copperflow 0.3.4 → 0.4.1

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.
Files changed (411) hide show
  1. package/README.md +117 -14
  2. package/dist/app/THIRD_PARTY_LICENSES.txt +5 -0
  3. package/dist/app/assets/NewPartDialog-ZQ4Y3m45.js +1 -0
  4. package/dist/app/assets/PackagesDialog-C8ZyWl-g.css +1 -0
  5. package/dist/app/assets/PackagesDialog-vEzilmpR.js +2 -0
  6. package/dist/app/assets/VerifyPartDialog-BHLqD_WJ.css +1 -0
  7. package/dist/app/assets/VerifyPartDialog-DYr1UIds.js +2 -0
  8. package/dist/app/assets/footprint-preview-Nyk2poiN.js +160 -0
  9. package/dist/app/assets/index-BUjGdMvr.js +20 -0
  10. package/dist/app/assets/index-CF7-tL4t.css +1 -0
  11. package/dist/app/assets/texture-worker-CyI_g_XZ.js +1 -0
  12. package/dist/app/index.html +2 -2
  13. package/dist/cli-commands.js +141 -16
  14. package/dist/cli-commands.js.map +1 -1
  15. package/dist/cli-impedance.d.ts +4 -0
  16. package/dist/cli-impedance.js +56 -0
  17. package/dist/cli-impedance.js.map +1 -0
  18. package/dist/cli-simulate.d.ts +3 -0
  19. package/dist/cli-simulate.js +54 -0
  20. package/dist/cli-simulate.js.map +1 -0
  21. package/dist/core/analyze.js +5 -2
  22. package/dist/core/analyze.js.map +1 -1
  23. package/dist/core/bom.d.ts +6 -1
  24. package/dist/core/bom.js +23 -4
  25. package/dist/core/bom.js.map +1 -1
  26. package/dist/core/case-results.d.ts +4 -0
  27. package/dist/core/case-results.js +9 -0
  28. package/dist/core/case-results.js.map +1 -0
  29. package/dist/core/change-files.d.ts +31 -0
  30. package/dist/core/change-files.js +67 -0
  31. package/dist/core/change-files.js.map +1 -0
  32. package/dist/core/change-render.d.ts +18 -0
  33. package/dist/core/change-render.js +48 -0
  34. package/dist/core/change-render.js.map +1 -0
  35. package/dist/core/change-view.d.ts +33 -0
  36. package/dist/core/change-view.js +73 -0
  37. package/dist/core/change-view.js.map +1 -0
  38. package/dist/core/change-words.d.ts +39 -0
  39. package/dist/core/change-words.js +214 -0
  40. package/dist/core/change-words.js.map +1 -0
  41. package/dist/core/checklist-text.d.ts +21 -0
  42. package/dist/core/checklist-text.js +59 -0
  43. package/dist/core/checklist-text.js.map +1 -0
  44. package/dist/core/edit.js +5 -2
  45. package/dist/core/edit.js.map +1 -1
  46. package/dist/core/fabrication.d.ts +9 -2
  47. package/dist/core/fabrication.js +29 -10
  48. package/dist/core/fabrication.js.map +1 -1
  49. package/dist/core/library.d.ts +46 -0
  50. package/dist/core/library.js +54 -16
  51. package/dist/core/library.js.map +1 -1
  52. package/dist/core/model-export.d.ts +33 -0
  53. package/dist/core/model-export.js +33 -0
  54. package/dist/core/model-export.js.map +1 -0
  55. package/dist/core/modules.d.ts +1 -0
  56. package/dist/core/modules.js +17 -0
  57. package/dist/core/modules.js.map +1 -1
  58. package/dist/core/order-report.d.ts +10 -0
  59. package/dist/core/order-report.js +93 -0
  60. package/dist/core/order-report.js.map +1 -0
  61. package/dist/core/packages.d.ts +18 -0
  62. package/dist/core/packages.js +49 -0
  63. package/dist/core/packages.js.map +1 -0
  64. package/dist/core/pin-header.d.ts +5 -0
  65. package/dist/core/pin-header.js +77 -0
  66. package/dist/core/pin-header.js.map +1 -0
  67. package/dist/core/pin-map.d.ts +46 -0
  68. package/dist/core/pin-map.js +101 -0
  69. package/dist/core/pin-map.js.map +1 -0
  70. package/dist/core/render.d.ts +26 -5
  71. package/dist/core/render.js +16 -6
  72. package/dist/core/render.js.map +1 -1
  73. package/dist/core/sheet-card.d.ts +4 -0
  74. package/dist/core/sheet-card.js +46 -1
  75. package/dist/core/sheet-card.js.map +1 -1
  76. package/dist/core/sheet-files.js +10 -3
  77. package/dist/core/sheet-files.js.map +1 -1
  78. package/dist/core/simulate.d.ts +19 -0
  79. package/dist/core/simulate.js +72 -0
  80. package/dist/core/simulate.js.map +1 -0
  81. package/dist/core/step-export.d.ts +17 -0
  82. package/dist/core/step-export.js +35 -0
  83. package/dist/core/step-export.js.map +1 -0
  84. package/dist/core/supplier-prop.d.ts +6 -0
  85. package/dist/core/supplier-prop.js +21 -0
  86. package/dist/core/supplier-prop.js.map +1 -0
  87. package/dist/core/workspace.d.ts +2 -1
  88. package/dist/core/workspace.js +2 -1
  89. package/dist/core/workspace.js.map +1 -1
  90. package/dist/engine/board.js +3 -1
  91. package/dist/engine/board.js.map +1 -1
  92. package/dist/engine/checks/fast-lines.d.ts +60 -0
  93. package/dist/engine/checks/fast-lines.js +209 -0
  94. package/dist/engine/checks/fast-lines.js.map +1 -0
  95. package/dist/engine/checks/index.js +2 -0
  96. package/dist/engine/checks/index.js.map +1 -1
  97. package/dist/engine/design-diff.d.ts +120 -0
  98. package/dist/engine/design-diff.js +249 -0
  99. package/dist/engine/design-diff.js.map +1 -0
  100. package/dist/engine/design.d.ts +3 -0
  101. package/dist/engine/design.js +7 -2
  102. package/dist/engine/design.js.map +1 -1
  103. package/dist/engine/fab/export.d.ts +17 -1
  104. package/dist/engine/fab/export.js +26 -4
  105. package/dist/engine/fab/export.js.map +1 -1
  106. package/dist/engine/fab/names.d.ts +2 -2
  107. package/dist/engine/fab/names.js +4 -2
  108. package/dist/engine/fab/names.js.map +1 -1
  109. package/dist/engine/fab/picture/board-picture.d.ts +52 -0
  110. package/dist/engine/fab/picture/board-picture.js +102 -0
  111. package/dist/engine/fab/picture/board-picture.js.map +1 -0
  112. package/dist/engine/fab/picture/board-view.d.ts +20 -0
  113. package/dist/engine/fab/picture/board-view.js +50 -0
  114. package/dist/engine/fab/picture/board-view.js.map +1 -0
  115. package/dist/engine/fab/picture/compose.d.ts +50 -0
  116. package/dist/engine/fab/picture/compose.js +208 -0
  117. package/dist/engine/fab/picture/compose.js.map +1 -0
  118. package/dist/engine/fab/picture/layer-images.d.ts +9 -0
  119. package/dist/engine/fab/picture/layer-images.js +67 -0
  120. package/dist/engine/fab/picture/layer-images.js.map +1 -0
  121. package/dist/engine/fab/picture/looks.d.ts +152 -0
  122. package/dist/engine/fab/picture/looks.js +53 -0
  123. package/dist/engine/fab/picture/looks.js.map +1 -0
  124. package/dist/engine/fab/picture/png.d.ts +31 -0
  125. package/dist/engine/fab/picture/png.js +47 -0
  126. package/dist/engine/fab/picture/png.js.map +1 -0
  127. package/dist/engine/fab/picture/raster.d.ts +46 -0
  128. package/dist/engine/fab/picture/raster.js +170 -0
  129. package/dist/engine/fab/picture/raster.js.map +1 -0
  130. package/dist/engine/fab/zip.d.ts +2 -1
  131. package/dist/engine/fab/zip.js +1 -1
  132. package/dist/engine/fab/zip.js.map +1 -1
  133. package/dist/engine/footprints/array.d.ts +4 -0
  134. package/dist/engine/footprints/array.js +51 -0
  135. package/dist/engine/footprints/array.js.map +1 -0
  136. package/dist/engine/footprints/axial.d.ts +6 -0
  137. package/dist/engine/footprints/axial.js +115 -0
  138. package/dist/engine/footprints/axial.js.map +1 -0
  139. package/dist/engine/footprints/catalogue.d.ts +39 -0
  140. package/dist/engine/footprints/catalogue.js +284 -0
  141. package/dist/engine/footprints/catalogue.js.map +1 -0
  142. package/dist/engine/footprints/chip.js +10 -1
  143. package/dist/engine/footprints/chip.js.map +1 -1
  144. package/dist/engine/footprints/connector.d.ts +16 -0
  145. package/dist/engine/footprints/connector.js +31 -0
  146. package/dist/engine/footprints/connector.js.map +1 -0
  147. package/dist/engine/footprints/dcjack.d.ts +3 -0
  148. package/dist/engine/footprints/dcjack.js +46 -0
  149. package/dist/engine/footprints/dcjack.js.map +1 -0
  150. package/dist/engine/footprints/dpak.d.ts +7 -0
  151. package/dist/engine/footprints/dpak.js +172 -0
  152. package/dist/engine/footprints/dpak.js.map +1 -0
  153. package/dist/engine/footprints/dual.d.ts +11 -2
  154. package/dist/engine/footprints/dual.js +113 -12
  155. package/dist/engine/footprints/dual.js.map +1 -1
  156. package/dist/engine/footprints/index.js +46 -3
  157. package/dist/engine/footprints/index.js.map +1 -1
  158. package/dist/engine/footprints/inductor.d.ts +3 -0
  159. package/dist/engine/footprints/inductor.js +32 -0
  160. package/dist/engine/footprints/inductor.js.map +1 -0
  161. package/dist/engine/footprints/known.js +114 -14
  162. package/dist/engine/footprints/known.js.map +1 -1
  163. package/dist/engine/footprints/ledsmd.d.ts +3 -0
  164. package/dist/engine/footprints/ledsmd.js +52 -0
  165. package/dist/engine/footprints/ledsmd.js.map +1 -0
  166. package/dist/engine/footprints/ledth.d.ts +4 -0
  167. package/dist/engine/footprints/ledth.js +45 -0
  168. package/dist/engine/footprints/ledth.js.map +1 -0
  169. package/dist/engine/footprints/melf.d.ts +8 -0
  170. package/dist/engine/footprints/melf.js +56 -0
  171. package/dist/engine/footprints/melf.js.map +1 -0
  172. package/dist/engine/footprints/plcc.d.ts +4 -0
  173. package/dist/engine/footprints/plcc.js +117 -0
  174. package/dist/engine/footprints/plcc.js.map +1 -0
  175. package/dist/engine/footprints/resonator.d.ts +3 -0
  176. package/dist/engine/footprints/resonator.js +33 -0
  177. package/dist/engine/footprints/resonator.js.map +1 -0
  178. package/dist/engine/footprints/screw.d.ts +3 -0
  179. package/dist/engine/footprints/screw.js +51 -0
  180. package/dist/engine/footprints/screw.js.map +1 -0
  181. package/dist/engine/footprints/smallsot.d.ts +8 -0
  182. package/dist/engine/footprints/smallsot.js +143 -0
  183. package/dist/engine/footprints/smallsot.js.map +1 -0
  184. package/dist/engine/footprints/smdbox.d.ts +33 -0
  185. package/dist/engine/footprints/smdbox.js +76 -0
  186. package/dist/engine/footprints/smdbox.js.map +1 -0
  187. package/dist/engine/footprints/smdcan.d.ts +3 -0
  188. package/dist/engine/footprints/smdcan.js +61 -0
  189. package/dist/engine/footprints/smdcan.js.map +1 -0
  190. package/dist/engine/footprints/smdip.d.ts +4 -0
  191. package/dist/engine/footprints/smdip.js +58 -0
  192. package/dist/engine/footprints/smdip.js.map +1 -0
  193. package/dist/engine/footprints/socket.d.ts +8 -0
  194. package/dist/engine/footprints/socket.js +21 -0
  195. package/dist/engine/footprints/socket.js.map +1 -0
  196. package/dist/engine/footprints/sod.d.ts +6 -0
  197. package/dist/engine/footprints/sod.js +63 -6
  198. package/dist/engine/footprints/sod.js.map +1 -1
  199. package/dist/engine/footprints/sot.d.ts +1 -1
  200. package/dist/engine/footprints/sot.js +17 -2
  201. package/dist/engine/footprints/sot.js.map +1 -1
  202. package/dist/engine/footprints/tact.d.ts +3 -0
  203. package/dist/engine/footprints/tact.js +65 -0
  204. package/dist/engine/footprints/tact.js.map +1 -0
  205. package/dist/engine/footprints/tantalum.d.ts +7 -0
  206. package/dist/engine/footprints/tantalum.js +91 -0
  207. package/dist/engine/footprints/tantalum.js.map +1 -0
  208. package/dist/engine/footprints/to92inline.d.ts +14 -0
  209. package/dist/engine/footprints/to92inline.js +21 -0
  210. package/dist/engine/footprints/to92inline.js.map +1 -0
  211. package/dist/engine/footprints/topower.d.ts +7 -0
  212. package/dist/engine/footprints/topower.js +119 -0
  213. package/dist/engine/footprints/topower.js.map +1 -0
  214. package/dist/engine/footprints/usb.d.ts +32 -0
  215. package/dist/engine/footprints/usb.js +109 -0
  216. package/dist/engine/footprints/usb.js.map +1 -0
  217. package/dist/engine/footprints/xtal.d.ts +4 -0
  218. package/dist/engine/footprints/xtal.js +61 -0
  219. package/dist/engine/footprints/xtal.js.map +1 -0
  220. package/dist/engine/impedance.d.ts +72 -0
  221. package/dist/engine/impedance.js +133 -0
  222. package/dist/engine/impedance.js.map +1 -0
  223. package/dist/engine/line-length.d.ts +15 -0
  224. package/dist/engine/line-length.js +116 -0
  225. package/dist/engine/line-length.js.map +1 -0
  226. package/dist/engine/model.d.ts +2 -0
  227. package/dist/engine/model.js.map +1 -1
  228. package/dist/engine/pcb-place/roles.d.ts +3 -1
  229. package/dist/engine/pcb-place/roles.js +5 -0
  230. package/dist/engine/pcb-place/roles.js.map +1 -1
  231. package/dist/engine/rules/impedance-widths.d.ts +20 -0
  232. package/dist/engine/rules/impedance-widths.js +57 -0
  233. package/dist/engine/rules/impedance-widths.js.map +1 -0
  234. package/dist/engine/rules/load.js +11 -2
  235. package/dist/engine/rules/load.js.map +1 -1
  236. package/dist/engine/rules/pairs.d.ts +27 -0
  237. package/dist/engine/rules/pairs.js +86 -0
  238. package/dist/engine/rules/pairs.js.map +1 -0
  239. package/dist/engine/rules/profiles.js +16 -0
  240. package/dist/engine/rules/profiles.js.map +1 -1
  241. package/dist/engine/rules/rotations.d.ts +12 -3
  242. package/dist/engine/rules/rotations.js +77 -2
  243. package/dist/engine/rules/rotations.js.map +1 -1
  244. package/dist/engine/rules/schema.d.ts +44 -0
  245. package/dist/engine/rules/schema.js +16 -1
  246. package/dist/engine/rules/schema.js.map +1 -1
  247. package/dist/engine/sim/answer.d.ts +13 -0
  248. package/dist/engine/sim/answer.js +101 -0
  249. package/dist/engine/sim/answer.js.map +1 -0
  250. package/dist/engine/sim/cases.d.ts +29 -0
  251. package/dist/engine/sim/cases.js +63 -0
  252. package/dist/engine/sim/cases.js.map +1 -0
  253. package/dist/engine/sim/devices.d.ts +109 -0
  254. package/dist/engine/sim/devices.js +137 -0
  255. package/dist/engine/sim/devices.js.map +1 -0
  256. package/dist/engine/sim/elements.d.ts +49 -0
  257. package/dist/engine/sim/elements.js +2 -0
  258. package/dist/engine/sim/elements.js.map +1 -0
  259. package/dist/engine/sim/from-circuit.d.ts +52 -0
  260. package/dist/engine/sim/from-circuit.js +354 -0
  261. package/dist/engine/sim/from-circuit.js.map +1 -0
  262. package/dist/engine/sim/limits.d.ts +12 -0
  263. package/dist/engine/sim/limits.js +79 -0
  264. package/dist/engine/sim/limits.js.map +1 -0
  265. package/dist/engine/sim/linear.d.ts +2 -0
  266. package/dist/engine/sim/linear.js +49 -0
  267. package/dist/engine/sim/linear.js.map +1 -0
  268. package/dist/engine/sim/model-schema.d.ts +246 -0
  269. package/dist/engine/sim/model-schema.js +115 -0
  270. package/dist/engine/sim/model-schema.js.map +1 -0
  271. package/dist/engine/sim/part-models.d.ts +47 -0
  272. package/dist/engine/sim/part-models.js +102 -0
  273. package/dist/engine/sim/part-models.js.map +1 -0
  274. package/dist/engine/sim/run.d.ts +14 -0
  275. package/dist/engine/sim/run.js +13 -0
  276. package/dist/engine/sim/run.js.map +1 -0
  277. package/dist/engine/sim/solve.d.ts +42 -0
  278. package/dist/engine/sim/solve.js +294 -0
  279. package/dist/engine/sim/solve.js.map +1 -0
  280. package/dist/engine/sim/spice.d.ts +5 -0
  281. package/dist/engine/sim/spice.js +66 -0
  282. package/dist/engine/sim/spice.js.map +1 -0
  283. package/dist/engine/sim/values.d.ts +4 -0
  284. package/dist/engine/sim/values.js +40 -0
  285. package/dist/engine/sim/values.js.map +1 -0
  286. package/dist/engine/solid/heights-smd.d.ts +3 -0
  287. package/dist/engine/solid/heights-smd.js +81 -0
  288. package/dist/engine/solid/heights-smd.js.map +1 -0
  289. package/dist/engine/solid/heights-through.d.ts +7 -0
  290. package/dist/engine/solid/heights-through.js +93 -0
  291. package/dist/engine/solid/heights-through.js.map +1 -0
  292. package/dist/engine/solid/heights-uno.d.ts +2 -0
  293. package/dist/engine/solid/heights-uno.js +15 -0
  294. package/dist/engine/solid/heights-uno.js.map +1 -0
  295. package/dist/engine/solid/heights.d.ts +31 -0
  296. package/dist/engine/solid/heights.js +112 -0
  297. package/dist/engine/solid/heights.js.map +1 -0
  298. package/dist/engine/solid/limits.d.ts +7 -0
  299. package/dist/engine/solid/limits.js +20 -0
  300. package/dist/engine/solid/limits.js.map +1 -0
  301. package/dist/engine/solid/model.d.ts +54 -0
  302. package/dist/engine/solid/model.js +147 -0
  303. package/dist/engine/solid/model.js.map +1 -0
  304. package/dist/engine/solid/step.d.ts +5 -0
  305. package/dist/engine/solid/step.js +164 -0
  306. package/dist/engine/solid/step.js.map +1 -0
  307. package/dist/engine/solid/thickness.d.ts +11 -0
  308. package/dist/engine/solid/thickness.js +10 -0
  309. package/dist/engine/solid/thickness.js.map +1 -0
  310. package/dist/library/kicad/board.d.ts +26 -0
  311. package/dist/library/kicad/board.js +96 -0
  312. package/dist/library/kicad/board.js.map +1 -0
  313. package/dist/library/kicad/copper.d.ts +44 -0
  314. package/dist/library/kicad/copper.js +106 -0
  315. package/dist/library/kicad/copper.js.map +1 -0
  316. package/dist/library/kicad/footprints.d.ts +62 -0
  317. package/dist/library/kicad/footprints.js +184 -0
  318. package/dist/library/kicad/footprints.js.map +1 -0
  319. package/dist/library/kicad/geometry.d.ts +36 -0
  320. package/dist/library/kicad/geometry.js +84 -0
  321. package/dist/library/kicad/geometry.js.map +1 -0
  322. package/dist/library/kicad/import.d.ts +58 -0
  323. package/dist/library/kicad/import.js +240 -0
  324. package/dist/library/kicad/import.js.map +1 -0
  325. package/dist/library/kicad/plan.d.ts +40 -0
  326. package/dist/library/kicad/plan.js +139 -0
  327. package/dist/library/kicad/plan.js.map +1 -0
  328. package/dist/library/kicad/read.d.ts +30 -0
  329. package/dist/library/kicad/read.js +105 -0
  330. package/dist/library/kicad/read.js.map +1 -0
  331. package/dist/library/kicad/sexpr.d.ts +36 -0
  332. package/dist/library/kicad/sexpr.js +153 -0
  333. package/dist/library/kicad/sexpr.js.map +1 -0
  334. package/dist/library/kicad/tally.d.ts +32 -0
  335. package/dist/library/kicad/tally.js +55 -0
  336. package/dist/library/kicad/tally.js.map +1 -0
  337. package/dist/library/kicad/write.d.ts +37 -0
  338. package/dist/library/kicad/write.js +146 -0
  339. package/dist/library/kicad/write.js.map +1 -0
  340. package/dist/library/new-part.d.ts +2 -0
  341. package/dist/library/new-part.js +1 -0
  342. package/dist/library/new-part.js.map +1 -1
  343. package/dist/mcp/board-import-tool.d.ts +1 -1
  344. package/dist/mcp/board-import-tool.js +14 -4
  345. package/dist/mcp/board-import-tool.js.map +1 -1
  346. package/dist/mcp/copper-summary.d.ts +2 -0
  347. package/dist/mcp/copper-summary.js +4 -2
  348. package/dist/mcp/copper-summary.js.map +1 -1
  349. package/dist/mcp/create-part.d.ts +23 -0
  350. package/dist/mcp/create-part.js +1 -0
  351. package/dist/mcp/create-part.js.map +1 -1
  352. package/dist/mcp/fast-summary.d.ts +3 -0
  353. package/dist/mcp/fast-summary.js +46 -0
  354. package/dist/mcp/fast-summary.js.map +1 -0
  355. package/dist/mcp/guide.d.ts +3 -1
  356. package/dist/mcp/guide.js +15 -4
  357. package/dist/mcp/guide.js.map +1 -1
  358. package/dist/mcp/model-tool.d.ts +31 -0
  359. package/dist/mcp/model-tool.js +27 -0
  360. package/dist/mcp/model-tool.js.map +1 -0
  361. package/dist/mcp/render-tool.d.ts +33 -2
  362. package/dist/mcp/render-tool.js +21 -5
  363. package/dist/mcp/render-tool.js.map +1 -1
  364. package/dist/mcp/server.js +20 -8
  365. package/dist/mcp/server.js.map +1 -1
  366. package/dist/mcp/sheet-card-tools.d.ts +3 -1
  367. package/dist/mcp/sheet-card-tools.js +3 -1
  368. package/dist/mcp/sheet-card-tools.js.map +1 -1
  369. package/dist/mcp/simulate-tool.d.ts +10 -0
  370. package/dist/mcp/simulate-tool.js +12 -0
  371. package/dist/mcp/simulate-tool.js.map +1 -0
  372. package/dist/render/render.js +11327 -1645
  373. package/dist/studio/change-route.d.ts +18 -0
  374. package/dist/studio/change-route.js +24 -0
  375. package/dist/studio/change-route.js.map +1 -0
  376. package/dist/studio/http-error.d.ts +5 -0
  377. package/dist/studio/http-error.js +9 -0
  378. package/dist/studio/http-error.js.map +1 -0
  379. package/dist/studio/live.d.ts +2 -0
  380. package/dist/studio/live.js.map +1 -1
  381. package/dist/studio/server.js +43 -15
  382. package/dist/studio/server.js.map +1 -1
  383. package/dist/studio/verify-routes.d.ts +42 -0
  384. package/dist/studio/verify-routes.js +110 -0
  385. package/dist/studio/verify-routes.js.map +1 -0
  386. package/dist/version.d.ts +1 -1
  387. package/dist/version.js +1 -1
  388. package/library/modules/CanNode/CanNode.sheet.tsx +1 -1
  389. package/library/modules/CanNode/parts/MCP2515-I-SO/MCP2515_I_SO.tsx +1 -0
  390. package/library/modules/CanNode/parts/MCP2515-I-SO/part.yaml +2 -0
  391. package/library/modules/CanNode/parts/MCP2515-I-SO/verification.md +2 -1
  392. package/library/modules/CanNode/parts/TJA1051T-3/TJA1051T_3.tsx +1 -0
  393. package/library/modules/CanNode/parts/TJA1051T-3/part.yaml +2 -0
  394. package/library/modules/CanNode/parts/TJA1051T-3/verification.md +2 -1
  395. package/library/modules/DigitalInput24V/DigitalInput24V.sheet.tsx +7 -7
  396. package/library/modules/RelayDriver/RelayDriver.sheet.tsx +3 -3
  397. package/library/modules/RelayDriver/parts/AO3400A/part.yaml +34 -0
  398. package/library/modules/RelayDriver/parts/AO3400A/verification.md +11 -1
  399. package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/SRD_12VDC_SL_C.tsx +1 -0
  400. package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/part.yaml +14 -0
  401. package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/verification.md +4 -1
  402. package/package.json +2 -1
  403. package/skills/copperflow/references/copper.md +8 -0
  404. package/skills/copperflow/references/design-rules.md +57 -6
  405. package/skills/copperflow/references/editable-subset.md +18 -8
  406. package/skills/copperflow/references/modules.md +26 -0
  407. package/skills/copperflow/references/parts-library.md +2 -1
  408. package/skills/copperflow/references/writing-circuits.md +9 -0
  409. package/dist/app/assets/NewPartDialog-C4sKWnGI.js +0 -160
  410. package/dist/app/assets/index-BgzJedaB.css +0 -1
  411. package/dist/app/assets/index-C_U9me2P.js +0 -19
@@ -0,0 +1,20 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./NewPartDialog-ZQ4Y3m45.js","./footprint-preview-Nyk2poiN.js","./PackagesDialog-vEzilmpR.js","./PackagesDialog-C8ZyWl-g.css","./VerifyPartDialog-DYr1UIds.js","./VerifyPartDialog-BHLqD_WJ.css"])))=>i.map(i=>d[i]);
2
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var l=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.iterator;function p(e){return typeof e!=`object`||!e?null:(e=f&&e[f]||e[`@@iterator`],typeof e==`function`?e:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},h=Object.assign,g={};function _(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}_.prototype.isReactComponent={},_.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},_.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function v(){}v.prototype=_.prototype;function y(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}var b=y.prototype=new v;b.constructor=y,h(b,_.prototype),b.isPureReactComponent=!0;var x=Array.isArray,S={H:null,A:null,T:null,S:null,V:null},C=Object.prototype.hasOwnProperty;function w(e,n,r,i,a,o){return r=o.ref,{$$typeof:t,type:e,key:n,ref:r===void 0?null:r,props:o}}function T(e,t){return w(e.type,t,void 0,void 0,void 0,e.props)}function E(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function ee(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var D=/\/+/g;function O(e,t){return typeof e==`object`&&e&&e.key!=null?ee(``+e.key):t.toString(36)}function k(){}function A(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(k,k):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function j(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,j(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+O(e,0):a,x(o)?(i=``,c!=null&&(i=c.replace(D,`$&/`)+`/`),j(o,r,i,``,function(e){return e})):o!=null&&(E(o)&&(o=T(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(D,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(x(e))for(var u=0;u<e.length;u++)a=e[u],s=l+O(a,u),c+=j(a,r,i,s,o);else if(u=p(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+O(a,u++),c+=j(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return j(A(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function te(e,t,n){if(e==null)return e;var r=[],i=0;return j(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ne(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var re=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function M(){}e.Children={map:te,forEach:function(e,t,n){te(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return te(e,function(){t++}),t},toArray:function(e){return te(e,function(e){return e})||[]},only:function(e){if(!E(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}},e.Component=_,e.Fragment=r,e.Profiler=a,e.PureComponent=y,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=S,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return S.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=h({},e.props),i=e.key,a=void 0;if(t!=null)for(o in t.ref!==void 0&&(a=void 0),t.key!==void 0&&(i=``+t.key),t)!C.call(t,o)||o===`key`||o===`__self`||o===`__source`||o===`ref`&&t.ref===void 0||(r[o]=t[o]);var o=arguments.length-2;if(o===1)r.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];r.children=s}return w(e.type,i,void 0,void 0,a,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)C.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return w(e,a,void 0,void 0,null,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=E,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:ne}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=S.T,n={};S.T=n;try{var r=e(),i=S.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(M,re)}catch(e){re(e)}finally{S.T=t}},e.unstable_useCacheRefresh=function(){return S.H.useCacheRefresh()},e.use=function(e){return S.H.use(e)},e.useActionState=function(e,t,n){return S.H.useActionState(e,t,n)},e.useCallback=function(e,t){return S.H.useCallback(e,t)},e.useContext=function(e){return S.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return S.H.useDeferredValue(e,t)},e.useEffect=function(e,t,n){var r=S.H;if(typeof n==`function`)throw Error(`useEffect CRUD overload is not enabled in this build of React.`);return r.useEffect(e,t)},e.useId=function(){return S.H.useId()},e.useImperativeHandle=function(e,t,n){return S.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return S.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return S.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return S.H.useMemo(e,t)},e.useOptimistic=function(e,t){return S.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return S.H.useReducer(e,t,n)},e.useRef=function(e){return S.H.useRef(e)},e.useState=function(e){return S.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return S.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return S.H.useTransition()},e.version=`19.1.0`})),u=o(((e,t)=>{t.exports=l()})),d=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,D());else{var t=n(l);t!==null&&A(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function ee(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&A(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?D():S=!1}}}var D;if(typeof y==`function`)D=function(){y(ee)};else if(typeof MessageChannel<`u`){var O=new MessageChannel,k=O.port2;O.port1.onmessage=ee,D=function(){k.postMessage(null)}}else D=function(){_(ee,0)};function A(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,A(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,D()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),f=o(((e,t)=>{t.exports=d()})),p=o((e=>{var t=u();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.1.0`})),m=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=p()})),h=o((e=>{var t=f(),n=u(),r=m();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(o(e)!==e)throw Error(i(188))}function l(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return c(a),e;if(s===r)return c(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var l=!1,u=a.child;u;){if(u===n){l=!0,n=a,r=s;break}if(u===r){l=!0,r=a,n=s;break}u=u.sibling}if(!l){for(u=s.child;u;){if(u===n){l=!0,n=s,r=a;break}if(u===r){l=!0,r=s,n=a;break}u=u.sibling}if(!l)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var p=Object.assign,h=Symbol.for(`react.element`),g=Symbol.for(`react.transitional.element`),_=Symbol.for(`react.portal`),v=Symbol.for(`react.fragment`),y=Symbol.for(`react.strict_mode`),b=Symbol.for(`react.profiler`),x=Symbol.for(`react.provider`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),ee=Symbol.for(`react.memo`),D=Symbol.for(`react.lazy`),O=Symbol.for(`react.activity`),k=Symbol.for(`react.memo_cache_sentinel`),A=Symbol.iterator;function j(e){return typeof e!=`object`||!e?null:(e=A&&e[A]||e[`@@iterator`],typeof e==`function`?e:null)}var te=Symbol.for(`react.client.reference`);function ne(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===te?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case v:return`Fragment`;case b:return`Profiler`;case y:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case O:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case _:return`Portal`;case C:return(e.displayName||`Context`)+`.Provider`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case ee:return t=e.displayName||null,t===null?ne(e.type)||`Memo`:t;case D:t=e._payload,e=e._init;try{return ne(e(t))}catch{}}return null}var re=Array.isArray,M=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,N=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P={pending:!1,data:null,method:null,action:null},ie=[],F=-1;function I(e){return{current:e}}function L(e){0>F||(e.current=ie[F],ie[F]=null,F--)}function R(e,t){F++,ie[F]=e.current,e.current=t}var ae=I(null),oe=I(null),se=I(null),ce=I(null);function le(e,t){switch(R(se,t),R(oe,e),R(ae,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?jd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=jd(t),e=Md(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}L(ae),R(ae,e)}function ue(){L(ae),L(oe),L(se)}function de(e){e.memoizedState!==null&&R(ce,e);var t=ae.current,n=Md(t,e.type);t!==n&&(R(oe,e),R(ae,n))}function fe(e){oe.current===e&&(L(ae),L(oe)),ce.current===e&&(L(ce),zf._currentValue=P)}var pe=Object.prototype.hasOwnProperty,me=t.unstable_scheduleCallback,z=t.unstable_cancelCallback,he=t.unstable_shouldYield,ge=t.unstable_requestPaint,_e=t.unstable_now,ve=t.unstable_getCurrentPriorityLevel,ye=t.unstable_ImmediatePriority,B=t.unstable_UserBlockingPriority,be=t.unstable_NormalPriority,xe=t.unstable_LowPriority,Se=t.unstable_IdlePriority,Ce=t.log,we=t.unstable_setDisableYieldValue,V=null,Te=null;function Ee(e){if(typeof Ce==`function`&&we(e),Te&&typeof Te.setStrictMode==`function`)try{Te.setStrictMode(V,e)}catch{}}var De=Math.clz32?Math.clz32:Ae,Oe=Math.log,ke=Math.LN2;function Ae(e){return e>>>=0,e===0?32:31-(Oe(e)/ke|0)|0}var je=256,Me=4194304;function Ne(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194048;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Pe(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Ne(n))):i=Ne(o):i=Ne(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Ne(n))):i=Ne(o)):i=Ne(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Fe(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Ie(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Le(){var e=je;return je<<=1,!(je&4194048)&&(je=256),e}function Re(){var e=Me;return Me<<=1,!(Me&62914560)&&(Me=4194304),e}function ze(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Be(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Ve(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0<n;){var u=31-De(n),d=1<<u;s[u]=0,c[u]=-1;var f=l[u];if(f!==null)for(l[u]=null,u=0;u<f.length;u++){var p=f[u];p!==null&&(p.lane&=-536870913)}n&=~d}r!==0&&He(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function He(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-De(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&4194090}function Ue(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-De(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function We(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function Ge(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function Ke(){var e=N.p;return e===0?(e=window.event,e===void 0?32:ep(e.type)):e}function qe(e,t){var n=N.p;try{return N.p=e,t()}finally{N.p=n}}var Je=Math.random().toString(36).slice(2),Ye=`__reactFiber$`+Je,Xe=`__reactProps$`+Je,Ze=`__reactContainer$`+Je,Qe=`__reactEvents$`+Je,$e=`__reactListeners$`+Je,et=`__reactHandles$`+Je,tt=`__reactResources$`+Je,nt=`__reactMarker$`+Je;function rt(e){delete e[Ye],delete e[Xe],delete e[Qe],delete e[$e],delete e[et]}function it(e){var t=e[Ye];if(t)return t;for(var n=e.parentNode;n;){if(t=n[Ze]||n[Ye]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=Xd(e);e!==null;){if(n=e[Ye])return n;e=Xd(e)}return t}e=n,n=e.parentNode}return null}function at(e){if(e=e[Ye]||e[Ze]){var t=e.tag;if(t===5||t===6||t===13||t===26||t===27||t===3)return e}return null}function ot(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(i(33))}function st(e){var t=e[tt];return t||=e[tt]={hoistableStyles:new Map,hoistableScripts:new Map},t}function H(e){e[nt]=!0}var ct=new Set,lt={};function ut(e,t){dt(e,t),dt(e+`Capture`,t)}function dt(e,t){for(lt[e]=t,e=0;e<t.length;e++)ct.add(t[e])}var ft=RegExp(`^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`),pt={},mt={};function ht(e){return pe.call(mt,e)?!0:pe.call(pt,e)?!1:ft.test(e)?mt[e]=!0:(pt[e]=!0,!1)}function gt(e,t,n){if(ht(t)){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:e.removeAttribute(t);return;case`boolean`:var r=t.toLowerCase().slice(0,5);if(r!==`data-`&&r!==`aria-`){e.removeAttribute(t);return}}e.setAttribute(t,``+n)}}}function _t(e,t,n){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(t);return}e.setAttribute(t,``+n)}}function vt(e,t,n,r){if(r===null)e.removeAttribute(n);else{switch(typeof r){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(n);return}e.setAttributeNS(t,n,``+r)}}var yt,bt;function xt(e){if(yt===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);yt=t&&t[1]||``,bt=-1<e.stack.indexOf(`
3
+ at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
+ `+yt+e+bt}var St=!1;function Ct(e,t){if(!e||St)return``;St=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
5
+ `),l=s.split(`
6
+ `);for(i=r=0;r<c.length&&!c[r].includes(`DetermineComponentFrameRoot`);)r++;for(;i<l.length&&!l[i].includes(`DetermineComponentFrameRoot`);)i++;if(r===c.length||i===l.length)for(r=c.length-1,i=l.length-1;1<=r&&0<=i&&c[r]!==l[i];)i--;for(;1<=r&&0<=i;r--,i--)if(c[r]!==l[i]){if(r!==1||i!==1)do if(r--,i--,0>i||c[r]!==l[i]){var u=`
7
+ `+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{St=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?xt(n):``}function U(e){switch(e.tag){case 26:case 27:case 5:return xt(e.type);case 16:return xt(`Lazy`);case 13:return xt(`Suspense`);case 19:return xt(`SuspenseList`);case 0:case 15:return Ct(e.type,!1);case 11:return Ct(e.type.render,!1);case 1:return Ct(e.type,!0);case 31:return xt(`Activity`);default:return``}}function wt(e){try{var t=``;do t+=U(e),e=e.return;while(e);return t}catch(e){return`
8
+ Error generating stack: `+e.message+`
9
+ `+e.stack}}function Tt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function Et(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function Dt(e){var t=Et(e)?`checked`:`value`,n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=``+e[t];if(!e.hasOwnProperty(t)&&n!==void 0&&typeof n.get==`function`&&typeof n.set==`function`){var i=n.get,a=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(e){r=``+e,a.call(this,e)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(e){r=``+e},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Ot(e){e._valueTracker||=Dt(e)}function kt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=Et(e)?e.checked?`true`:`false`:e.value),e=r,e!==n&&(t.setValue(e),!0)}function At(e){if(e||=typeof document<`u`?document:void 0,e===void 0)return null;try{return e.activeElement||e.body}catch{return e.body}}var jt=/[\n"\\]/g;function Mt(e){return e.replace(jt,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function Nt(e,t,n,r,i,a,o,s){e.name=``,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`?e.type=o:e.removeAttribute(`type`),t==null?o!==`submit`&&o!==`reset`||e.removeAttribute(`value`):o===`number`?(t===0&&e.value===``||e.value!=t)&&(e.value=``+Tt(t)):e.value!==``+Tt(t)&&(e.value=``+Tt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):Ft(e,o,Tt(n)):Ft(e,o,Tt(t)),i==null&&a!=null&&(e.defaultChecked=!!a),i!=null&&(e.checked=i&&typeof i!=`function`&&typeof i!=`symbol`),s!=null&&typeof s!=`function`&&typeof s!=`symbol`&&typeof s!=`boolean`?e.name=``+Tt(s):e.removeAttribute(`name`)}function Pt(e,t,n,r,i,a,o,s){if(a!=null&&typeof a!=`function`&&typeof a!=`symbol`&&typeof a!=`boolean`&&(e.type=a),t!=null||n!=null){if(!(a!==`submit`&&a!==`reset`||t!=null))return;n=n==null?``:``+Tt(n),t=t==null?n:``+Tt(t),s||t===e.value||(e.value=t),e.defaultValue=t}r??=i,r=typeof r!=`function`&&typeof r!=`symbol`&&!!r,e.checked=s?e.checked:!!r,e.defaultChecked=!!r,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`&&(e.name=o)}function Ft(e,t,n){t===`number`&&At(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function It(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i<n.length;i++)t[`$`+n[i]]=!0;for(n=0;n<e.length;n++)i=t.hasOwnProperty(`$`+e[n].value),e[n].selected!==i&&(e[n].selected=i),i&&r&&(e[n].defaultSelected=!0)}else{for(n=``+Tt(n),t=null,i=0;i<e.length;i++){if(e[i].value===n){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Lt(e,t,n){t!=null&&(t=``+Tt(t),t!==e.value&&(e.value=t),n==null)?e.defaultValue!==t&&(e.defaultValue=t):e.defaultValue=n==null?``:``+Tt(n)}function Rt(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(i(92));if(re(r)){if(1<r.length)throw Error(i(93));r=r[0]}n=r}n??=``,t=n}n=Tt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r)}function zt(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Bt=new Set(`animationIterationCount aspectRatio borderImageOutset borderImageSlice borderImageWidth boxFlex boxFlexGroup boxOrdinalGroup columnCount columns flex flexGrow flexPositive flexShrink flexNegative flexOrder gridArea gridRow gridRowEnd gridRowSpan gridRowStart gridColumn gridColumnEnd gridColumnSpan gridColumnStart fontWeight lineClamp lineHeight opacity order orphans scale tabSize widows zIndex zoom fillOpacity floodOpacity stopOpacity strokeDasharray strokeDashoffset strokeMiterlimit strokeOpacity strokeWidth MozAnimationIterationCount MozBoxFlex MozBoxFlexGroup MozLineClamp msAnimationIterationCount msFlex msZoom msFlexGrow msFlexNegative msFlexOrder msFlexPositive msFlexShrink msGridColumn msGridColumnSpan msGridRow msGridRowSpan WebkitAnimationIterationCount WebkitBoxFlex WebKitBoxFlexGroup WebkitBoxOrdinalGroup WebkitColumnCount WebkitColumns WebkitFlex WebkitFlexGrow WebkitFlexPositive WebkitFlexShrink WebkitLineClamp`.split(` `));function Vt(e,t,n){var r=t.indexOf(`--`)===0;n==null||typeof n==`boolean`||n===``?r?e.setProperty(t,``):t===`float`?e.cssFloat=``:e[t]=``:r?e.setProperty(t,n):typeof n!=`number`||n===0||Bt.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Ht(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(i(62));if(e=e.style,n!=null){for(var r in n)!n.hasOwnProperty(r)||t!=null&&t.hasOwnProperty(r)||(r.indexOf(`--`)===0?e.setProperty(r,``):r===`float`?e.cssFloat=``:e[r]=``);for(var a in t)r=t[a],t.hasOwnProperty(a)&&n[a]!==r&&Vt(e,a,r)}else for(var o in t)t.hasOwnProperty(o)&&Vt(e,o,t[o])}function Ut(e){if(e.indexOf(`-`)===-1)return!1;switch(e){case`annotation-xml`:case`color-profile`:case`font-face`:case`font-face-src`:case`font-face-uri`:case`font-face-format`:case`font-face-name`:case`missing-glyph`:return!1;default:return!0}}var Wt=new Map([[`acceptCharset`,`accept-charset`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`],[`crossOrigin`,`crossorigin`],[`accentHeight`,`accent-height`],[`alignmentBaseline`,`alignment-baseline`],[`arabicForm`,`arabic-form`],[`baselineShift`,`baseline-shift`],[`capHeight`,`cap-height`],[`clipPath`,`clip-path`],[`clipRule`,`clip-rule`],[`colorInterpolation`,`color-interpolation`],[`colorInterpolationFilters`,`color-interpolation-filters`],[`colorProfile`,`color-profile`],[`colorRendering`,`color-rendering`],[`dominantBaseline`,`dominant-baseline`],[`enableBackground`,`enable-background`],[`fillOpacity`,`fill-opacity`],[`fillRule`,`fill-rule`],[`floodColor`,`flood-color`],[`floodOpacity`,`flood-opacity`],[`fontFamily`,`font-family`],[`fontSize`,`font-size`],[`fontSizeAdjust`,`font-size-adjust`],[`fontStretch`,`font-stretch`],[`fontStyle`,`font-style`],[`fontVariant`,`font-variant`],[`fontWeight`,`font-weight`],[`glyphName`,`glyph-name`],[`glyphOrientationHorizontal`,`glyph-orientation-horizontal`],[`glyphOrientationVertical`,`glyph-orientation-vertical`],[`horizAdvX`,`horiz-adv-x`],[`horizOriginX`,`horiz-origin-x`],[`imageRendering`,`image-rendering`],[`letterSpacing`,`letter-spacing`],[`lightingColor`,`lighting-color`],[`markerEnd`,`marker-end`],[`markerMid`,`marker-mid`],[`markerStart`,`marker-start`],[`overlinePosition`,`overline-position`],[`overlineThickness`,`overline-thickness`],[`paintOrder`,`paint-order`],[`panose-1`,`panose-1`],[`pointerEvents`,`pointer-events`],[`renderingIntent`,`rendering-intent`],[`shapeRendering`,`shape-rendering`],[`stopColor`,`stop-color`],[`stopOpacity`,`stop-opacity`],[`strikethroughPosition`,`strikethrough-position`],[`strikethroughThickness`,`strikethrough-thickness`],[`strokeDasharray`,`stroke-dasharray`],[`strokeDashoffset`,`stroke-dashoffset`],[`strokeLinecap`,`stroke-linecap`],[`strokeLinejoin`,`stroke-linejoin`],[`strokeMiterlimit`,`stroke-miterlimit`],[`strokeOpacity`,`stroke-opacity`],[`strokeWidth`,`stroke-width`],[`textAnchor`,`text-anchor`],[`textDecoration`,`text-decoration`],[`textRendering`,`text-rendering`],[`transformOrigin`,`transform-origin`],[`underlinePosition`,`underline-position`],[`underlineThickness`,`underline-thickness`],[`unicodeBidi`,`unicode-bidi`],[`unicodeRange`,`unicode-range`],[`unitsPerEm`,`units-per-em`],[`vAlphabetic`,`v-alphabetic`],[`vHanging`,`v-hanging`],[`vIdeographic`,`v-ideographic`],[`vMathematical`,`v-mathematical`],[`vectorEffect`,`vector-effect`],[`vertAdvY`,`vert-adv-y`],[`vertOriginX`,`vert-origin-x`],[`vertOriginY`,`vert-origin-y`],[`wordSpacing`,`word-spacing`],[`writingMode`,`writing-mode`],[`xmlnsXlink`,`xmlns:xlink`],[`xHeight`,`x-height`]]),Gt=/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;function Kt(e){return Gt.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}var qt=null;function Jt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Yt=null,Xt=null;function Zt(e){var t=at(e);if(t&&(e=t.stateNode)){var n=e[Xe]||null;a:switch(e=t.stateNode,t.type){case`input`:if(Nt(e,n.value,n.defaultValue,n.defaultValue,n.checked,n.defaultChecked,n.type,n.name),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name="`+Mt(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var a=r[Xe]||null;if(!a)throw Error(i(90));Nt(r,a.value,a.defaultValue,a.defaultValue,a.checked,a.defaultChecked,a.type,a.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&kt(r)}break a;case`textarea`:Lt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&It(e,!!n.multiple,t,!1)}}}var Qt=!1;function $t(e,t,n){if(Qt)return e(t,n);Qt=!0;try{return e(t)}finally{if(Qt=!1,(Yt!==null||Xt!==null)&&(du(),Yt&&(t=Yt,e=Xt,Xt=Yt=null,Zt(t),e)))for(t=0;t<e.length;t++)Zt(e[t])}}function en(e,t){var n=e.stateNode;if(n===null)return null;var r=n[Xe]||null;if(r===null)return null;n=r[t];a:switch(t){case`onClick`:case`onClickCapture`:case`onDoubleClick`:case`onDoubleClickCapture`:case`onMouseDown`:case`onMouseDownCapture`:case`onMouseMove`:case`onMouseMoveCapture`:case`onMouseUp`:case`onMouseUpCapture`:case`onMouseEnter`:(r=!r.disabled)||(e=e.type,r=e!==`button`&&e!==`input`&&e!==`select`&&e!==`textarea`),e=!r;break a;default:e=!1}if(e)return null;if(n&&typeof n!=`function`)throw Error(i(231,t,typeof n));return n}var tn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,nn=!1;if(tn)try{var rn={};Object.defineProperty(rn,"passive",{get:function(){nn=!0}}),window.addEventListener(`test`,rn,rn),window.removeEventListener(`test`,rn,rn)}catch{nn=!1}var an=null,on=null,sn=null;function cn(){if(sn)return sn;var e,t=on,n=t.length,r,i=`value`in an?an.value:an.textContent,a=i.length;for(e=0;e<n&&t[e]===i[e];e++);var o=n-e;for(r=1;r<=o&&t[n-r]===i[a-r];r++);return sn=i.slice(e,1<r?1-r:void 0)}function ln(e){var t=e.keyCode;return`charCode`in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function un(){return!0}function dn(){return!1}function fn(e){function t(t,n,r,i,a){for(var o in this._reactName=t,this._targetInst=r,this.type=n,this.nativeEvent=i,this.target=a,this.currentTarget=null,e)e.hasOwnProperty(o)&&(t=e[o],this[o]=t?t(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented==null?!1===i.returnValue:i.defaultPrevented)?un:dn,this.isPropagationStopped=dn,this}return p(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():typeof e.returnValue!=`unknown`&&(e.returnValue=!1),this.isDefaultPrevented=un)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=un)},persist:function(){},isPersistent:un}),t}var pn={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},mn=fn(pn),hn=p({},pn,{view:0,detail:0}),gn=fn(hn),_n,vn,yn,bn=p({},hn,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:jn,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return`movementX`in e?e.movementX:(e!==yn&&(yn&&e.type===`mousemove`?(_n=e.screenX-yn.screenX,vn=e.screenY-yn.screenY):vn=_n=0,yn=e),_n)},movementY:function(e){return`movementY`in e?e.movementY:vn}}),xn=fn(bn),Sn=fn(p({},bn,{dataTransfer:0})),Cn=fn(p({},hn,{relatedTarget:0})),wn=fn(p({},pn,{animationName:0,elapsedTime:0,pseudoElement:0})),Tn=fn(p({},pn,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),En=fn(p({},pn,{data:0})),Dn={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},On={8:`Backspace`,9:`Tab`,12:`Clear`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,224:`Meta`},kn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function An(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=kn[e])?!!t[e]:!1}function jn(){return An}var Mn=fn(p({},hn,{key:function(e){if(e.key){var t=Dn[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=ln(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?On[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:jn,charCode:function(e){return e.type===`keypress`?ln(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?ln(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),Nn=fn(p({},bn,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),Pn=fn(p({},hn,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:jn})),Fn=fn(p({},pn,{propertyName:0,elapsedTime:0,pseudoElement:0})),In=fn(p({},bn,{deltaX:function(e){return`deltaX`in e?e.deltaX:`wheelDeltaX`in e?-e.wheelDeltaX:0},deltaY:function(e){return`deltaY`in e?e.deltaY:`wheelDeltaY`in e?-e.wheelDeltaY:`wheelDelta`in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0})),Ln=fn(p({},pn,{newState:0,oldState:0})),Rn=[9,13,27,32],zn=tn&&`CompositionEvent`in window,Bn=null;tn&&`documentMode`in document&&(Bn=document.documentMode);var Vn=tn&&`TextEvent`in window&&!Bn,Hn=tn&&(!zn||Bn&&8<Bn&&11>=Bn),Un=` `,Wn=!1;function Gn(e,t){switch(e){case`keyup`:return Rn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Kn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var qn=!1;function Jn(e,t){switch(e){case`compositionend`:return Kn(t);case`keypress`:return t.which===32?(Wn=!0,Un):null;case`textInput`:return e=t.data,e===Un&&Wn?null:e;default:return null}}function Yn(e,t){if(qn)return e===`compositionend`||!zn&&Gn(e,t)?(e=cn(),sn=on=an=null,qn=!1,e):null;switch(e){case`paste`:return null;case`keypress`:if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case`compositionend`:return Hn&&t.locale!==`ko`?null:t.data;default:return null}}var Xn={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function Zn(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!Xn[e.type]:t===`textarea`}function Qn(e,t,n,r){Yt?Xt?Xt.push(r):Xt=[r]:Yt=r,t=_d(t,`onChange`),0<t.length&&(n=new mn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var $n=null,er=null;function tr(e){ud(e,0)}function nr(e){if(kt(ot(e)))return e}function rr(e,t){if(e===`change`)return t}var ir=!1;if(tn){var ar;if(tn){var or=`oninput`in document;if(!or){var sr=document.createElement(`div`);sr.setAttribute(`oninput`,`return;`),or=typeof sr.oninput==`function`}ar=or}else ar=!1;ir=ar&&(!document.documentMode||9<document.documentMode)}function cr(){$n&&($n.detachEvent(`onpropertychange`,lr),er=$n=null)}function lr(e){if(e.propertyName===`value`&&nr(er)){var t=[];Qn(t,er,e,Jt(e)),$t(tr,t)}}function ur(e,t,n){e===`focusin`?(cr(),$n=t,er=n,$n.attachEvent(`onpropertychange`,lr)):e===`focusout`&&cr()}function dr(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return nr(er)}function fr(e,t){if(e===`click`)return nr(t)}function pr(e,t){if(e===`input`||e===`change`)return nr(t)}function mr(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var hr=typeof Object.is==`function`?Object.is:mr;function gr(e,t){if(hr(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var i=n[r];if(!pe.call(t,i)||!hr(e[i],t[i]))return!1}return!0}function _r(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function vr(e,t){var n=_r(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}a:{for(;n;){if(n.nextSibling){n=n.nextSibling;break a}n=n.parentNode}n=void 0}n=_r(n)}}function yr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?yr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function br(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=At(e.document);t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href==`string`}catch{n=!1}if(n)e=t.contentWindow;else break;t=At(e.document)}return t}function xr(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t===`input`&&(e.type===`text`||e.type===`search`||e.type===`tel`||e.type===`url`||e.type===`password`)||t===`textarea`||e.contentEditable===`true`)}var Sr=tn&&`documentMode`in document&&11>=document.documentMode,Cr=null,wr=null,Tr=null,Er=!1;function Dr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Er||Cr==null||Cr!==At(r)||(r=Cr,`selectionStart`in r&&xr(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Tr&&gr(Tr,r)||(Tr=r,r=_d(wr,`onSelect`),0<r.length&&(t=new mn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=Cr)))}function Or(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var kr={animationend:Or(`Animation`,`AnimationEnd`),animationiteration:Or(`Animation`,`AnimationIteration`),animationstart:Or(`Animation`,`AnimationStart`),transitionrun:Or(`Transition`,`TransitionRun`),transitionstart:Or(`Transition`,`TransitionStart`),transitioncancel:Or(`Transition`,`TransitionCancel`),transitionend:Or(`Transition`,`TransitionEnd`)},Ar={},jr={};tn&&(jr=document.createElement(`div`).style,`AnimationEvent`in window||(delete kr.animationend.animation,delete kr.animationiteration.animation,delete kr.animationstart.animation),`TransitionEvent`in window||delete kr.transitionend.transition);function Mr(e){if(Ar[e])return Ar[e];if(!kr[e])return e;var t=kr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in jr)return Ar[e]=t[n];return e}var Nr=Mr(`animationend`),Pr=Mr(`animationiteration`),Fr=Mr(`animationstart`),Ir=Mr(`transitionrun`),Lr=Mr(`transitionstart`),Rr=Mr(`transitioncancel`),zr=Mr(`transitionend`),Br=new Map,Vr=`abort auxClick beforeToggle cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel`.split(` `);Vr.push(`scrollEnd`);function Hr(e,t){Br.set(e,t),ut(t,[e])}var Ur=new WeakMap;function Wr(e,t){if(typeof e==`object`&&e){var n=Ur.get(e);return n===void 0?(t={value:e,source:t,stack:wt(t)},Ur.set(e,t),t):n}return{value:e,source:t,stack:wt(t)}}var Gr=[],Kr=0,qr=0;function Jr(){for(var e=Kr,t=qr=Kr=0;t<e;){var n=Gr[t];Gr[t++]=null;var r=Gr[t];Gr[t++]=null;var i=Gr[t];Gr[t++]=null;var a=Gr[t];if(Gr[t++]=null,r!==null&&i!==null){var o=r.pending;o===null?i.next=i:(i.next=o.next,o.next=i),r.pending=i}a!==0&&Qr(n,i,a)}}function Yr(e,t,n,r){Gr[Kr++]=e,Gr[Kr++]=t,Gr[Kr++]=n,Gr[Kr++]=r,qr|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function Xr(e,t,n,r){return Yr(e,t,n,r),$r(e)}function Zr(e,t){return Yr(e,null,null,t),$r(e)}function Qr(e,t,n){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n);for(var i=!1,a=e.return;a!==null;)a.childLanes|=n,r=a.alternate,r!==null&&(r.childLanes|=n),a.tag===22&&(e=a.stateNode,e===null||e._visibility&1||(i=!0)),e=a,a=a.return;return e.tag===3?(a=e.stateNode,i&&t!==null&&(i=31-De(n),e=a.hiddenUpdates,r=e[i],r===null?e[i]=[t]:r.push(t),t.lane=n|536870912),a):null}function $r(e){if(50<nu)throw nu=0,ru=null,Error(i(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var ei={};function ti(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ni(e,t,n,r){return new ti(e,t,n,r)}function ri(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ii(e,t){var n=e.alternate;return n===null?(n=ni(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&65011712,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n.refCleanup=e.refCleanup,n}function ai(e,t){e.flags&=65011714;var n=e.alternate;return n===null?(e.childLanes=0,e.lanes=t,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=n.childLanes,e.lanes=n.lanes,e.child=n.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=n.memoizedProps,e.memoizedState=n.memoizedState,e.updateQueue=n.updateQueue,e.type=n.type,t=n.dependencies,e.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),e}function oi(e,t,n,r,a,o){var s=0;if(r=e,typeof e==`function`)ri(e)&&(s=1);else if(typeof e==`string`)s=kf(e,n,ae.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case O:return e=ni(31,n,t,a),e.elementType=O,e.lanes=o,e;case v:return si(n.children,a,o,t);case y:s=8,a|=24;break;case b:return e=ni(12,n,t,a|2),e.elementType=b,e.lanes=o,e;case T:return e=ni(13,n,t,a),e.elementType=T,e.lanes=o,e;case E:return e=ni(19,n,t,a),e.elementType=E,e.lanes=o,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case x:case C:s=10;break a;case S:s=9;break a;case w:s=11;break a;case ee:s=14;break a;case D:s=16,r=null;break a}s=29,n=Error(i(130,e===null?`null`:typeof e,``)),r=null}return t=ni(s,n,t,a),t.elementType=e,t.type=r,t.lanes=o,t}function si(e,t,n,r){return e=ni(7,e,r,t),e.lanes=n,e}function ci(e,t,n){return e=ni(6,e,null,t),e.lanes=n,e}function li(e,t,n){return t=ni(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var ui=[],di=0,fi=null,pi=0,mi=[],hi=0,gi=null,_i=1,vi=``;function yi(e,t){ui[di++]=pi,ui[di++]=fi,fi=e,pi=t}function bi(e,t,n){mi[hi++]=_i,mi[hi++]=vi,mi[hi++]=gi,gi=e;var r=_i;e=vi;var i=32-De(r)-1;r&=~(1<<i),n+=1;var a=32-De(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,_i=1<<32-De(t)+i|n<<i|r,vi=a+e}else _i=1<<a|n<<i|r,vi=e}function xi(e){e.return!==null&&(yi(e,1),bi(e,1,0))}function Si(e){for(;e===fi;)fi=ui[--di],ui[di]=null,pi=ui[--di],ui[di]=null;for(;e===gi;)gi=mi[--hi],mi[hi]=null,vi=mi[--hi],mi[hi]=null,_i=mi[--hi],mi[hi]=null}var Ci=null,wi=null,Ti=!1,Ei=null,Di=!1,Oi=Error(i(519));function ki(e){throw Fi(Wr(Error(i(418,``)),e)),Oi}function Ai(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[Ye]=e,t[Xe]=r,n){case`dialog`:J(`cancel`,t),J(`close`,t);break;case`iframe`:case`object`:case`embed`:J(`load`,t);break;case`video`:case`audio`:for(n=0;n<cd.length;n++)J(cd[n],t);break;case`source`:J(`error`,t);break;case`img`:case`image`:case`link`:J(`error`,t),J(`load`,t);break;case`details`:J(`toggle`,t);break;case`input`:J(`invalid`,t),Pt(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0),Ot(t);break;case`select`:J(`invalid`,t);break;case`textarea`:J(`invalid`,t),Rt(t,r.value,r.defaultValue,r.children),Ot(t)}n=r.children,typeof n!=`string`&&typeof n!=`number`&&typeof n!=`bigint`||t.textContent===``+n||!0===r.suppressHydrationWarning||Cd(t.textContent,n)?(r.popover!=null&&(J(`beforetoggle`,t),J(`toggle`,t)),r.onScroll!=null&&J(`scroll`,t),r.onScrollEnd!=null&&J(`scrollend`,t),r.onClick!=null&&(t.onclick=wd),t=!0):t=!1,t||ki(e)}function ji(e){for(Ci=e.return;Ci;)switch(Ci.tag){case 5:case 13:Di=!1;return;case 27:case 3:Di=!0;return;default:Ci=Ci.return}}function Mi(e){if(e!==Ci)return!1;if(!Ti)return ji(e),Ti=!0,!1;var t=e.tag,n;if((n=t!==3&&t!==27)&&((n=t===5)&&(n=e.type,n=n===`form`||n===`button`||Nd(e.type,e.memoizedProps)),n=!n),n&&wi&&ki(e),ji(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));a:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){if(n=e.data,n===`/$`){if(t===0){wi=Jd(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}wi=null}}else t===27?(t=wi,Vd(e.type)?(e=Yd,Yd=null,wi=e):wi=t):wi=Ci?Jd(e.stateNode.nextSibling):null;return!0}function Ni(){wi=Ci=null,Ti=!1}function Pi(){var e=Ei;return e!==null&&(Ul===null?Ul=e:Ul.push.apply(Ul,e),Ei=null),e}function Fi(e){Ei===null?Ei=[e]:Ei.push(e)}var Ii=I(null),Li=null,Ri=null;function zi(e,t,n){R(Ii,t._currentValue),t._currentValue=n}function Bi(e){e._currentValue=Ii.current,L(Ii)}function Vi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)===t?r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t):(e.childLanes|=t,r!==null&&(r.childLanes|=t)),e===n)break;e=e.return}}function Hi(e,t,n,r){var a=e.child;for(a!==null&&(a.return=e);a!==null;){var o=a.dependencies;if(o!==null){var s=a.child;o=o.firstContext;a:for(;o!==null;){var c=o;o=a;for(var l=0;l<t.length;l++)if(c.context===t[l]){o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),Vi(o.return,n,e),r||(s=null);break a}o=c.next}}else if(a.tag===18){if(s=a.return,s===null)throw Error(i(341));s.lanes|=n,o=s.alternate,o!==null&&(o.lanes|=n),Vi(s,n,e),s=null}else s=a.child;if(s!==null)s.return=a;else for(s=a;s!==null;){if(s===e){s=null;break}if(a=s.sibling,a!==null){a.return=s.return,s=a;break}s=s.return}a=s}}function Ui(e,t,n,r){e=null;for(var a=t,o=!1;a!==null;){if(!o){if(a.flags&524288)o=!0;else if(a.flags&262144)break}if(a.tag===10){var s=a.alternate;if(s===null)throw Error(i(387));if(s=s.memoizedProps,s!==null){var c=a.type;hr(a.pendingProps.value,s.value)||(e===null?e=[c]:e.push(c))}}else if(a===ce.current){if(s=a.alternate,s===null)throw Error(i(387));s.memoizedState.memoizedState!==a.memoizedState.memoizedState&&(e===null?e=[zf]:e.push(zf))}a=a.return}e!==null&&Hi(t,e,n,r),t.flags|=262144}function Wi(e){for(e=e.firstContext;e!==null;){if(!hr(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function Gi(e){Li=e,Ri=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function Ki(e){return Ji(Li,e)}function qi(e,t){return Li===null&&Gi(e),Ji(e,t)}function Ji(e,t){var n=t._currentValue;if(t={context:t,memoizedValue:n,next:null},Ri===null){if(e===null)throw Error(i(308));Ri=t,e.dependencies={lanes:0,firstContext:t},e.flags|=524288}else Ri=Ri.next=t;return n}var Yi=typeof AbortController<`u`?AbortController:function(){var e=[],t=this.signal={aborted:!1,addEventListener:function(t,n){e.push(n)}};this.abort=function(){t.aborted=!0,e.forEach(function(e){return e()})}},Xi=t.unstable_scheduleCallback,Zi=t.unstable_NormalPriority,Qi={$$typeof:C,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function $i(){return{controller:new Yi,data:new Map,refCount:0}}function ea(e){e.refCount--,e.refCount===0&&Xi(Zi,function(){e.controller.abort()})}var ta=null,na=0,ra=0,ia=null;function aa(e,t){if(ta===null){var n=ta=[];na=0,ra=nd(),ia={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return na++,t.then(oa,oa),t}function oa(){if(--na===0&&ta!==null){ia!==null&&(ia.status=`fulfilled`);var e=ta;ta=null,ra=0,ia=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function sa(e,t){var n=[],r={status:`pending`,value:null,reason:null,then:function(e){n.push(e)}};return e.then(function(){r.status=`fulfilled`,r.value=t;for(var e=0;e<n.length;e++)(0,n[e])(t)},function(e){for(r.status=`rejected`,r.reason=e,e=0;e<n.length;e++)(0,n[e])(void 0)}),r}var ca=M.S;M.S=function(e,t){typeof t==`object`&&t&&typeof t.then==`function`&&aa(e,t),ca!==null&&ca(e,t)};var la=I(null);function ua(){var e=la.current;return e===null?kl.pooledCache:e}function da(e,t){t===null?R(la,la.current):R(la,t.pool)}function fa(){var e=ua();return e===null?null:{parent:Qi._currentValue,pool:e}}var pa=Error(i(460)),ma=Error(i(474)),ha=Error(i(542)),ga={then:function(){}};function _a(e){return e=e.status,e===`fulfilled`||e===`rejected`}function va(){}function ya(e,t,n){switch(n=e[n],n===void 0?e.push(t):n!==t&&(t.then(va,va),t=n),t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Sa(e),e;default:if(typeof t.status==`string`)t.then(va,va);else{if(e=kl,e!==null&&100<e.shellSuspendCounter)throw Error(i(482));e=t,e.status=`pending`,e.then(function(e){if(t.status===`pending`){var n=t;n.status=`fulfilled`,n.value=e}},function(e){if(t.status===`pending`){var n=t;n.status=`rejected`,n.reason=e}})}switch(t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Sa(e),e}throw ba=t,pa}}var ba=null;function xa(){if(ba===null)throw Error(i(459));var e=ba;return ba=null,e}function Sa(e){if(e===pa||e===ha)throw Error(i(483))}var W=!1;function Ca(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function wa(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ta(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ea(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ol&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=$r(e),Qr(e,null,n),t}return Yr(e,r,t,n),$r(e)}function Da(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194048)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ue(e,n)}}function Oa(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={lane:n.lane,tag:n.tag,payload:n.payload,callback:null,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,callbacks:r.callbacks},e.updateQueue=n}else e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}var ka=!1;function Aa(){if(ka){var e=ia;if(e!==null)throw e}}function ja(e,t,n,r){ka=!1;var i=e.updateQueue;W=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane&-536870913,m=f!==s.lane;if(m?(q&f)===f:(r&f)===f){f!==0&&f===ra&&(ka=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var h=e,g=s;f=t;var _=n;switch(g.tag){case 1:if(h=g.payload,typeof h==`function`){d=h.call(_,d,f);break a}d=h;break a;case 3:h.flags=h.flags&-65537|128;case 0:if(h=g.payload,f=typeof h==`function`?h.call(_,d,f):h,f==null)break a;d=p({},d,f);break a;case 2:W=!0}}f=s.callback,f!==null&&(e.flags|=64,m&&(e.flags|=8192),m=i.callbacks,m===null?i.callbacks=[f]:m.push(f))}else m={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=m,c=d):u=u.next=m,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;m=s,s=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),Ll|=o,e.lanes=o,e.memoizedState=d}}function Ma(e,t){if(typeof e!=`function`)throw Error(i(191,e));e.call(t)}function Na(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Ma(n[e],t)}var Pa=I(null),Fa=I(0);function Ia(e,t){e=Fl,R(Fa,e),R(Pa,t),Fl=e|t.baseLanes}function La(){R(Fa,Fl),R(Pa,Pa.current)}function Ra(){Fl=Fa.current,L(Pa),L(Fa)}var za=0,G=null,Ba=null,Va=null,Ha=!1,Ua=!1,Wa=!1,Ga=0,Ka=0,qa=null,Ja=0;function Ya(){throw Error(i(321))}function Xa(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!hr(e[n],t[n]))return!1;return!0}function Za(e,t,n,r,i,a){return za=a,G=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,M.H=e===null||e.memoizedState===null?ms:hs,Wa=!1,a=n(r,i),Wa=!1,Ua&&(a=$a(t,n,r,i)),Qa(e),a}function Qa(e){M.H=ps;var t=Ba!==null&&Ba.next!==null;if(za=0,Va=Ba=G=null,Ha=!1,Ka=0,qa=null,t)throw Error(i(300));e===null||Xs||(e=e.dependencies,e!==null&&Wi(e)&&(Xs=!0))}function $a(e,t,n,r){G=e;var a=0;do{if(Ua&&(qa=null),Ka=0,Ua=!1,25<=a)throw Error(i(301));if(a+=1,Va=Ba=null,e.updateQueue!=null){var o=e.updateQueue;o.lastEffect=null,o.events=null,o.stores=null,o.memoCache!=null&&(o.memoCache.index=0)}M.H=gs,o=t(n,r)}while(Ua);return o}function eo(){var e=M.H,t=e.useState()[0];return t=typeof t.then==`function`?so(t):t,e=e.useState()[0],(Ba===null?null:Ba.memoizedState)!==e&&(G.flags|=1024),t}function to(){var e=Ga!==0;return Ga=0,e}function no(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function ro(e){if(Ha){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}Ha=!1}za=0,Va=Ba=G=null,Ua=!1,Ka=Ga=0,qa=null}function io(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Va===null?G.memoizedState=Va=e:Va=Va.next=e,Va}function ao(){if(Ba===null){var e=G.alternate;e=e===null?null:e.memoizedState}else e=Ba.next;var t=Va===null?G.memoizedState:Va.next;if(t!==null)Va=t,Ba=e;else{if(e===null)throw G.alternate===null?Error(i(467)):Error(i(310));Ba=e,e={memoizedState:Ba.memoizedState,baseState:Ba.baseState,baseQueue:Ba.baseQueue,queue:Ba.queue,next:null},Va===null?G.memoizedState=Va=e:Va=Va.next=e}return Va}function oo(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function so(e){var t=Ka;return Ka+=1,qa===null&&(qa=[]),e=ya(qa,e,t),t=G,(Va===null?t.memoizedState:Va.next)===null&&(t=t.alternate,M.H=t===null||t.memoizedState===null?ms:hs),e}function co(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return so(e);if(e.$$typeof===C)return Ki(e)}throw Error(i(438,String(e)))}function lo(e){var t=null,n=G.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=G.alternate;r!==null&&(r=r.updateQueue,r!==null&&(r=r.memoCache,r!=null&&(t={data:r.data.map(function(e){return e.slice()}),index:0})))}if(t??={data:[],index:0},n===null&&(n=oo(),G.updateQueue=n),n.memoCache=t,n=t.data[t.index],n===void 0)for(n=t.data[t.index]=Array(e),r=0;r<e;r++)n[r]=k;return t.index++,n}function uo(e,t){return typeof t==`function`?t(e):t}function fo(e){return po(ao(),Ba,e)}function po(e,t,n){var r=e.queue;if(r===null)throw Error(i(311));r.lastRenderedReducer=n;var a=e.baseQueue,o=r.pending;if(o!==null){if(a!==null){var s=a.next;a.next=o.next,o.next=s}t.baseQueue=a=o,r.pending=null}if(o=e.baseState,a===null)e.memoizedState=o;else{t=a.next;var c=s=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(za&f)===f:(q&f)===f){var p=u.revertLane;if(p===0)l!==null&&(l=l.next={lane:0,revertLane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),f===ra&&(d=!0);else if((za&p)===p){u=u.next,p===ra&&(d=!0);continue}else f={lane:0,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=f,s=o):l=l.next=f,G.lanes|=p,Ll|=p;f=u.action,Wa&&n(o,f),o=u.hasEagerState?u.eagerState:n(o,f)}else p={lane:f,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,s=o):l=l.next=p,G.lanes|=f,Ll|=f;u=u.next}while(u!==null&&u!==t);if(l===null?s=o:l.next=c,!hr(o,e.memoizedState)&&(Xs=!0,d&&(n=ia,n!==null)))throw n;e.memoizedState=o,e.baseState=s,e.baseQueue=l,r.lastRenderedState=o}return a===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function mo(e){var t=ao(),n=t.queue;if(n===null)throw Error(i(311));n.lastRenderedReducer=e;var r=n.dispatch,a=n.pending,o=t.memoizedState;if(a!==null){n.pending=null;var s=a=a.next;do o=e(o,s.action),s=s.next;while(s!==a);hr(o,t.memoizedState)||(Xs=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,r]}function ho(e,t,n){var r=G,a=ao(),o=Ti;if(o){if(n===void 0)throw Error(i(407));n=n()}else n=t();var s=!hr((Ba||a).memoizedState,n);if(s&&(a.memoizedState=n,Xs=!0),a=a.queue,zo(2048,8,vo.bind(null,r,a,e),[e]),a.getSnapshot!==t||s||Va!==null&&Va.memoizedState.tag&1){if(r.flags|=2048,Fo(9,Io(),_o.bind(null,r,a,n,t),null),kl===null)throw Error(i(349));o||za&124||go(r,t,n)}return n}function go(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=G.updateQueue,t===null?(t=oo(),G.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function _o(e,t,n,r){t.value=n,t.getSnapshot=r,yo(t)&&bo(e)}function vo(e,t,n){return n(function(){yo(t)&&bo(e)})}function yo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!hr(e,n)}catch{return!0}}function bo(e){var t=Zr(e,2);t!==null&&ou(t,e,2)}function xo(e){var t=io();if(typeof e==`function`){var n=e;if(e=n(),Wa){Ee(!0);try{n()}finally{Ee(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:e},t}function So(e,t,n,r){return e.baseState=n,po(e,Ba,typeof r==`function`?r:uo)}function Co(e,t,n,r,a){if(us(e))throw Error(i(485));if(e=t.action,e!==null){var o={payload:a,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){o.listeners.push(e)}};M.T===null?o.isTransition=!1:n(!0),r(o),n=t.pending,n===null?(o.next=t.pending=o,wo(t,o)):(o.next=n.next,t.pending=n.next=o)}}function wo(e,t){var n=t.action,r=t.payload,i=e.state;if(t.isTransition){var a=M.T,o={};M.T=o;try{var s=n(i,r),c=M.S;c!==null&&c(o,s),To(e,t,s)}catch(n){Do(e,t,n)}finally{M.T=a}}else try{a=n(i,r),To(e,t,a)}catch(n){Do(e,t,n)}}function To(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){Eo(e,t,n)},function(n){return Do(e,t,n)}):Eo(e,t,n)}function Eo(e,t,n){t.status=`fulfilled`,t.value=n,Oo(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,wo(e,n)))}function Do(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,Oo(t),t=t.next;while(t!==r)}e.action=null}function Oo(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function ko(e,t){return t}function Ao(e,t){if(Ti){var n=kl.formState;if(n!==null){a:{var r=G;if(Ti){if(wi){b:{for(var i=wi,a=Di;i.nodeType!==8;)if(!a||(i=Jd(i.nextSibling),i===null)){i=null;break b}a=i.data,i=a===`F!`||a===`F`?i:null}if(i){wi=Jd(i.nextSibling),r=i.data===`F!`;break a}}ki(r)}r=!1}r&&(t=n[0])}}return n=io(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:ko,lastRenderedState:t},n.queue=r,n=ss.bind(null,G,r),r.dispatch=n,r=xo(!1),a=ls.bind(null,G,!1,r.queue),r=io(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=Co.bind(null,G,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function jo(e){return Mo(ao(),Ba,e)}function Mo(e,t,n){if(t=po(e,t,ko)[0],e=fo(uo)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=so(t)}catch(e){throw e===pa?ha:e}else r=t;t=ao();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(G.flags|=2048,Fo(9,Io(),No.bind(null,i,n),null)),[r,a,e]}function No(e,t){e.action=t}function Po(e){var t=ao(),n=Ba;if(n!==null)return Mo(t,n,e);ao(),t=t.memoizedState,n=ao();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function Fo(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=G.updateQueue,t===null&&(t=oo(),G.updateQueue=t),n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e),e}function Io(){return{destroy:void 0,resource:void 0}}function Lo(){return ao().memoizedState}function Ro(e,t,n,r){var i=io();r=r===void 0?null:r,G.flags|=e,i.memoizedState=Fo(1|t,Io(),n,r)}function zo(e,t,n,r){var i=ao();r=r===void 0?null:r;var a=i.memoizedState.inst;Ba!==null&&r!==null&&Xa(r,Ba.memoizedState.deps)?i.memoizedState=Fo(t,a,n,r):(G.flags|=e,i.memoizedState=Fo(1|t,a,n,r))}function Bo(e,t){Ro(8390656,8,e,t)}function Vo(e,t){zo(2048,8,e,t)}function Ho(e,t){return zo(4,2,e,t)}function Uo(e,t){return zo(4,4,e,t)}function Wo(e,t){if(typeof t==`function`){e=e();var n=t(e);return function(){typeof n==`function`?n():t(null)}}if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function Go(e,t,n){n=n==null?null:n.concat([e]),zo(4,4,Wo.bind(null,t,e),n)}function Ko(){}function qo(e,t){var n=ao();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&Xa(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function Jo(e,t){var n=ao();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&Xa(t,r[1]))return r[0];if(r=e(),Wa){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r}function Yo(e,t,n){return n===void 0||za&1073741824?e.memoizedState=t:(e.memoizedState=n,e=au(),G.lanes|=e,Ll|=e,n)}function Xo(e,t,n,r){return hr(n,t)?n:Pa.current===null?za&42?(e=au(),G.lanes|=e,Ll|=e,t):(Xs=!0,e.memoizedState=n):(e=Yo(e,n,r),hr(e,t)||(Xs=!0),e)}function Zo(e,t,n,r,i){var a=N.p;N.p=a!==0&&8>a?a:8;var o=M.T,s={};M.T=s,ls(e,!1,t,n);try{var c=i(),l=M.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?cs(e,t,sa(c,r),iu(e)):cs(e,t,r,iu(e))}catch(n){cs(e,t,{then:function(){},status:`rejected`,reason:n},iu())}finally{N.p=a,M.T=o}}function Qo(){}function $o(e,t,n,r){if(e.tag!==5)throw Error(i(476));var a=es(e).queue;Zo(e,a,t,P,n===null?Qo:function(){return ts(e),n(r)})}function es(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:P,baseState:P,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:P},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function ts(e){var t=es(e).next.queue;cs(e,t,{},iu())}function ns(){return Ki(zf)}function rs(){return ao().memoizedState}function is(){return ao().memoizedState}function as(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=iu();e=Ta(n);var r=Ea(t,e,n);r!==null&&(ou(r,t,n),Da(r,t,n)),t={cache:$i()},e.payload=t;return}t=t.return}}function os(e,t,n){var r=iu();n={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null},us(e)?ds(t,n):(n=Xr(e,t,n,r),n!==null&&(ou(n,e,r),fs(n,t,r)))}function ss(e,t,n){cs(e,t,n,iu())}function cs(e,t,n,r){var i={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null};if(us(e))ds(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,hr(s,o))return Yr(e,t,i,0),kl===null&&Jr(),!1}catch{}if(n=Xr(e,t,i,r),n!==null)return ou(n,e,r),fs(n,t,r),!0}return!1}function ls(e,t,n,r){if(r={lane:2,revertLane:nd(),action:r,hasEagerState:!1,eagerState:null,next:null},us(e)){if(t)throw Error(i(479))}else t=Xr(e,n,r,2),t!==null&&ou(t,e,2)}function us(e){var t=e.alternate;return e===G||t!==null&&t===G}function ds(e,t){Ua=Ha=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function fs(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ue(e,n)}}var ps={readContext:Ki,use:co,useCallback:Ya,useContext:Ya,useEffect:Ya,useImperativeHandle:Ya,useLayoutEffect:Ya,useInsertionEffect:Ya,useMemo:Ya,useReducer:Ya,useRef:Ya,useState:Ya,useDebugValue:Ya,useDeferredValue:Ya,useTransition:Ya,useSyncExternalStore:Ya,useId:Ya,useHostTransitionStatus:Ya,useFormState:Ya,useActionState:Ya,useOptimistic:Ya,useMemoCache:Ya,useCacheRefresh:Ya},ms={readContext:Ki,use:co,useCallback:function(e,t){return io().memoizedState=[e,t===void 0?null:t],e},useContext:Ki,useEffect:Bo,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),Ro(4194308,4,Wo.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Ro(4194308,4,e,t)},useInsertionEffect:function(e,t){Ro(4,2,e,t)},useMemo:function(e,t){var n=io();t=t===void 0?null:t;var r=e();if(Wa){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=io();if(n!==void 0){var i=n(t);if(Wa){Ee(!0);try{n(t)}finally{Ee(!1)}}}else i=t;return r.memoizedState=r.baseState=i,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:i},r.queue=e,e=e.dispatch=os.bind(null,G,e),[r.memoizedState,e]},useRef:function(e){var t=io();return e={current:e},t.memoizedState=e},useState:function(e){e=xo(e);var t=e.queue,n=ss.bind(null,G,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:Ko,useDeferredValue:function(e,t){return Yo(io(),e,t)},useTransition:function(){var e=xo(!1);return e=Zo.bind(null,G,e.queue,!0,!1),io().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=G,a=io();if(Ti){if(n===void 0)throw Error(i(407));n=n()}else{if(n=t(),kl===null)throw Error(i(349));q&124||go(r,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,Bo(vo.bind(null,r,o,e),[e]),r.flags|=2048,Fo(9,Io(),_o.bind(null,r,o,n,t),null),n},useId:function(){var e=io(),t=kl.identifierPrefix;if(Ti){var n=vi,r=_i;n=(r&~(1<<32-De(r)-1)).toString(32)+n,t=`«`+t+`R`+n,n=Ga++,0<n&&(t+=`H`+n.toString(32)),t+=`»`}else n=Ja++,t=`«`+t+`r`+n.toString(32)+`»`;return e.memoizedState=t},useHostTransitionStatus:ns,useFormState:Ao,useActionState:Ao,useOptimistic:function(e){var t=io();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=ls.bind(null,G,!0,n),n.dispatch=t,[e,t]},useMemoCache:lo,useCacheRefresh:function(){return io().memoizedState=as.bind(null,G)}},hs={readContext:Ki,use:co,useCallback:qo,useContext:Ki,useEffect:Vo,useImperativeHandle:Go,useInsertionEffect:Ho,useLayoutEffect:Uo,useMemo:Jo,useReducer:fo,useRef:Lo,useState:function(){return fo(uo)},useDebugValue:Ko,useDeferredValue:function(e,t){return Xo(ao(),Ba.memoizedState,e,t)},useTransition:function(){var e=fo(uo)[0],t=ao().memoizedState;return[typeof e==`boolean`?e:so(e),t]},useSyncExternalStore:ho,useId:rs,useHostTransitionStatus:ns,useFormState:jo,useActionState:jo,useOptimistic:function(e,t){return So(ao(),Ba,e,t)},useMemoCache:lo,useCacheRefresh:is},gs={readContext:Ki,use:co,useCallback:qo,useContext:Ki,useEffect:Vo,useImperativeHandle:Go,useInsertionEffect:Ho,useLayoutEffect:Uo,useMemo:Jo,useReducer:mo,useRef:Lo,useState:function(){return mo(uo)},useDebugValue:Ko,useDeferredValue:function(e,t){var n=ao();return Ba===null?Yo(n,e,t):Xo(n,Ba.memoizedState,e,t)},useTransition:function(){var e=mo(uo)[0],t=ao().memoizedState;return[typeof e==`boolean`?e:so(e),t]},useSyncExternalStore:ho,useId:rs,useHostTransitionStatus:ns,useFormState:Po,useActionState:Po,useOptimistic:function(e,t){var n=ao();return Ba===null?(n.baseState=e,[e,n.queue.dispatch]):So(n,Ba,e,t)},useMemoCache:lo,useCacheRefresh:is},_s=null,vs=0;function ys(e){var t=vs;return vs+=1,_s===null&&(_s=[]),ya(_s,e,t)}function bs(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function xs(e,t){throw t.$$typeof===h?Error(i(525)):(e=Object.prototype.toString.call(t),Error(i(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function Ss(e){var t=e._init;return t(e._payload)}function Cs(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function r(e){for(var t=new Map;e!==null;)e.key===null?t.set(e.index,e):t.set(e.key,e),e=e.sibling;return t}function a(e,t){return e=ii(e,t),e.index=0,e.sibling=null,e}function o(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=67108866,n):(r=r.index,r<n?(t.flags|=67108866,n):r)):(t.flags|=1048576,n)}function s(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=ci(n,e.mode,r),t.return=e,t):(t=a(t,n),t.return=e,t)}function l(e,t,n,r){var i=n.type;return i===v?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===i||typeof i==`object`&&i&&i.$$typeof===D&&Ss(i)===t.type)?(t=a(t,n.props),bs(t,n),t.return=e,t):(t=oi(n.type,n.key,n.props,null,e.mode,r),bs(t,n),t.return=e,t)}function u(e,t,n,r){return t===null||t.tag!==4||t.stateNode.containerInfo!==n.containerInfo||t.stateNode.implementation!==n.implementation?(t=li(n,e.mode,r),t.return=e,t):(t=a(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,i){return t===null||t.tag!==7?(t=si(n,e.mode,r,i),t.return=e,t):(t=a(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=ci(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case g:return n=oi(t.type,t.key,t.props,null,e.mode,n),bs(n,t),n.return=e,n;case _:return t=li(t,e.mode,n),t.return=e,t;case D:var r=t._init;return t=r(t._payload),f(e,t,n)}if(re(t)||j(t))return t=si(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,ys(t),n);if(t.$$typeof===C)return f(e,qi(e,t),n);xs(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`||typeof n==`bigint`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case g:return n.key===i?l(e,t,n,r):null;case _:return n.key===i?u(e,t,n,r):null;case D:return i=n._init,n=i(n._payload),p(e,t,n,r)}if(re(n)||j(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,ys(n),r);if(n.$$typeof===C)return p(e,t,qi(e,n),r);xs(e,n)}return null}function m(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`||typeof r==`bigint`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case g:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case _:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case D:var a=r._init;return r=a(r._payload),m(e,t,n,r,i)}if(re(r)||j(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return m(e,t,n,ys(r),i);if(r.$$typeof===C)return m(e,t,n,qi(t,r),i);xs(t,r)}return null}function h(i,a,s,c){for(var l=null,u=null,d=a,h=a=0,g=null;d!==null&&h<s.length;h++){d.index>h?(g=d,d=null):g=d.sibling;var _=p(i,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(i,d),a=o(_,a,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),Ti&&yi(i,h),l;if(d===null){for(;h<s.length;h++)d=f(i,s[h],c),d!==null&&(a=o(d,a,h),u===null?l=d:u.sibling=d,u=d);return Ti&&yi(i,h),l}for(d=r(d);h<s.length;h++)g=m(d,i,h,s[h],c),g!==null&&(e&&g.alternate!==null&&d.delete(g.key===null?h:g.key),a=o(g,a,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(i,e)}),Ti&&yi(i,h),l}function y(a,s,c,l){if(c==null)throw Error(i(151));for(var u=null,d=null,h=s,g=s=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(a,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(a,h),s=o(y,s,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(a,h),Ti&&yi(a,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return Ti&&yi(a,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,a,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(a,e)}),Ti&&yi(a,g),u}function b(e,r,o,c){if(typeof o==`object`&&o&&o.type===v&&o.key===null&&(o=o.props.children),typeof o==`object`&&o){switch(o.$$typeof){case g:a:{for(var l=o.key;r!==null;){if(r.key===l){if(l=o.type,l===v){if(r.tag===7){n(e,r.sibling),c=a(r,o.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===D&&Ss(l)===r.type){n(e,r.sibling),c=a(r,o.props),bs(c,o),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}o.type===v?(c=si(o.props.children,e.mode,c,o.key),c.return=e,e=c):(c=oi(o.type,o.key,o.props,null,e.mode,c),bs(c,o),c.return=e,e=c)}return s(e);case _:a:{for(l=o.key;r!==null;){if(r.key===l){if(r.tag===4&&r.stateNode.containerInfo===o.containerInfo&&r.stateNode.implementation===o.implementation){n(e,r.sibling),c=a(r,o.children||[]),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}c=li(o,e.mode,c),c.return=e,e=c}return s(e);case D:return l=o._init,o=l(o._payload),b(e,r,o,c)}if(re(o))return h(e,r,o,c);if(j(o)){if(l=j(o),typeof l!=`function`)throw Error(i(150));return o=l.call(o),y(e,r,o,c)}if(typeof o.then==`function`)return b(e,r,ys(o),c);if(o.$$typeof===C)return b(e,r,qi(e,o),c);xs(e,o)}return typeof o==`string`&&o!==``||typeof o==`number`||typeof o==`bigint`?(o=``+o,r!==null&&r.tag===6?(n(e,r.sibling),c=a(r,o),c.return=e,e=c):(n(e,r),c=ci(o,e.mode,c),c.return=e,e=c),s(e)):n(e,r)}return function(e,t,n,r){try{vs=0;var i=b(e,t,n,r);return _s=null,i}catch(t){if(t===pa||t===ha)throw t;var a=ni(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var ws=Cs(!0),Ts=Cs(!1),Es=I(null),Ds=null;function Os(e){var t=e.alternate;R(Ms,Ms.current&1),R(Es,e),Ds===null&&(t===null||Pa.current!==null||t.memoizedState!==null)&&(Ds=e)}function ks(e){if(e.tag===22){if(R(Ms,Ms.current),R(Es,e),Ds===null){var t=e.alternate;t!==null&&t.memoizedState!==null&&(Ds=e)}}else As(e)}function As(){R(Ms,Ms.current),R(Es,Es.current)}function js(e){L(Es),Ds===e&&(Ds=null),L(Ms)}var Ms=I(0);function Ns(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data===`$?`||Kd(n)))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}function Ps(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:p({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Fs={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=iu(),i=Ta(r);i.payload=t,n!=null&&(i.callback=n),t=Ea(e,i,r),t!==null&&(ou(t,e,r),Da(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=iu(),i=Ta(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Ea(e,i,r),t!==null&&(ou(t,e,r),Da(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=iu(),r=Ta(n);r.tag=2,t!=null&&(r.callback=t),t=Ea(e,r,n),t!==null&&(ou(t,e,n),Da(t,e,n))}};function Is(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!gr(n,r)||!gr(i,a):!0}function Ls(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&Fs.enqueueReplaceState(t,t.state,null)}function Rs(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=p({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}var zs=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function Bs(e){zs(e)}function Vs(e){console.error(e)}function Hs(e){zs(e)}function Us(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Ws(e,t,n){try{var r=e.onCaughtError;r(n.value,{componentStack:n.stack,errorBoundary:t.tag===1?t.stateNode:null})}catch(e){setTimeout(function(){throw e})}}function Gs(e,t,n){return n=Ta(n),n.tag=3,n.payload={element:null},n.callback=function(){Us(e,t)},n}function Ks(e){return e=Ta(e),e.tag=3,e}function qs(e,t,n,r){var i=n.type.getDerivedStateFromError;if(typeof i==`function`){var a=r.value;e.payload=function(){return i(a)},e.callback=function(){Ws(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Ws(t,n,r),typeof i!=`function`&&(Jl===null?Jl=new Set([this]):Jl.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function Js(e,t,n,r,a){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Ui(t,n,a,!0),n=Es.current,n!==null){switch(n.tag){case 13:return Ds===null?_u():n.alternate===null&&Il===0&&(Il=3),n.flags&=-257,n.flags|=65536,n.lanes=a,r===ga?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),Iu(e,r,a)),!1;case 22:return n.flags|=65536,r===ga?n.flags|=16384:(t=n.updateQueue,t===null?(t={transitions:null,markerInstances:null,retryQueue:new Set([r])},n.updateQueue=t):(n=t.retryQueue,n===null?t.retryQueue=new Set([r]):n.add(r)),Iu(e,r,a)),!1}throw Error(i(435,n.tag))}return Iu(e,r,a),_u(),!1}if(Ti)return t=Es.current,t===null?(r!==Oi&&(t=Error(i(423),{cause:r}),Fi(Wr(t,n))),e=e.current.alternate,e.flags|=65536,a&=-a,e.lanes|=a,r=Wr(r,n),a=Gs(e.stateNode,r,a),Oa(e,a),Il!==4&&(Il=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=a,r!==Oi&&(e=Error(i(422),{cause:r}),Fi(Wr(e,n)))),!1;var o=Error(i(520),{cause:r});if(o=Wr(o,n),Hl===null?Hl=[o]:Hl.push(o),Il!==4&&(Il=2),t===null)return!0;r=Wr(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=a&-a,n.lanes|=e,e=Gs(n.stateNode,r,e),Oa(n,e),!1;case 1:if(t=n.type,o=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||o!==null&&typeof o.componentDidCatch==`function`&&(Jl===null||!Jl.has(o))))return n.flags|=65536,a&=-a,n.lanes|=a,a=Ks(a),qs(a,e,n,r),Oa(n,a),!1}n=n.return}while(n!==null);return!1}var Ys=Error(i(461)),Xs=!1;function Zs(e,t,n,r){t.child=e===null?Ts(t,null,n,r):ws(t,e.child,n,r)}function Qs(e,t,n,r,i){n=n.render;var a=t.ref;if(`ref`in r){var o={};for(var s in r)s!==`ref`&&(o[s]=r[s])}else o=r;return Gi(t),r=Za(e,t,n,o,a,i),s=to(),e!==null&&!Xs?(no(e,t,i),vc(e,t,i)):(Ti&&s&&xi(t),t.flags|=1,Zs(e,t,r,i),t.child)}function $s(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!ri(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,ec(e,t,a,r,i)):(e=oi(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!yc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?gr:n,n(o,r)&&e.ref===t.ref)return vc(e,t,i)}return t.flags|=1,e=ii(a,r),e.ref=t.ref,e.return=t,t.child=e}function ec(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(gr(a,r)&&e.ref===t.ref){if(Xs=!1,t.pendingProps=r=a,yc(e,i))e.flags&131072&&(Xs=!0);else return t.lanes=e.lanes,vc(e,t,i)}}return ic(e,t,n,r,i)}function tc(e,t,n){var r=t.pendingProps,i=r.children,a=e===null?null:e.memoizedState;if(r.mode===`hidden`){if(t.flags&128){if(r=a===null?n:a.baseLanes|n,e!==null){for(i=t.child=e.child,a=0;i!==null;)a=a|i.lanes|i.childLanes,i=i.sibling;t.childLanes=a&~r}else t.childLanes=0,t.child=null;return nc(e,t,r,n)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&da(t,a===null?null:a.cachePool),a===null?La():Ia(t,a),ks(t);else return t.lanes=t.childLanes=536870912,nc(e,t,a===null?n:a.baseLanes|n,n)}else a===null?(e!==null&&da(t,null),La(),As(t)):(da(t,a.cachePool),Ia(t,a),As(t),t.memoizedState=null);return Zs(e,t,i,n),t.child}function nc(e,t,n,r){var i=ua();return i=i===null?null:{parent:Qi._currentValue,pool:i},t.memoizedState={baseLanes:n,cachePool:i},e!==null&&da(t,null),La(),ks(t),e!==null&&Ui(e,t,r,!0),null}function rc(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(i(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function ic(e,t,n,r,i){return Gi(t),n=Za(e,t,n,r,void 0,i),r=to(),e!==null&&!Xs?(no(e,t,i),vc(e,t,i)):(Ti&&r&&xi(t),t.flags|=1,Zs(e,t,n,i),t.child)}function ac(e,t,n,r,i,a){return Gi(t),t.updateQueue=null,n=$a(t,r,n,i),Qa(e),r=to(),e!==null&&!Xs?(no(e,t,a),vc(e,t,a)):(Ti&&r&&xi(t),t.flags|=1,Zs(e,t,n,a),t.child)}function oc(e,t,n,r,i){if(Gi(t),t.stateNode===null){var a=ei,o=n.contextType;typeof o==`object`&&o&&(a=Ki(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=Fs,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},Ca(t),o=n.contextType,a.context=typeof o==`object`&&o?Ki(o):ei,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Ps(t,n,o,r),a.state=t.memoizedState),typeof n.getDerivedStateFromProps==`function`||typeof a.getSnapshotBeforeUpdate==`function`||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(o=a.state,typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount(),o!==a.state&&Fs.enqueueReplaceState(a,a.state,null),ja(t,r,a,i),Aa(),a.state=t.memoizedState),typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!0}else if(e===null){a=t.stateNode;var s=t.memoizedProps,c=Rs(n,s);a.props=c;var l=a.context,u=n.contextType;o=ei,typeof u==`object`&&u&&(o=Ki(u));var d=n.getDerivedStateFromProps;u=typeof d==`function`||typeof a.getSnapshotBeforeUpdate==`function`,s=t.pendingProps!==s,u||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(s||l!==o)&&Ls(t,a,r,o),W=!1;var f=t.memoizedState;a.state=f,ja(t,r,a,i),Aa(),l=t.memoizedState,s||f!==l||W?(typeof d==`function`&&(Ps(t,n,d,r),l=t.memoizedState),(c=W||Is(t,n,c,r,f,l,o))?(u||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount==`function`&&(t.flags|=4194308)):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),a.props=r,a.state=l,a.context=o,r=c):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,wa(e,t),o=t.memoizedProps,u=Rs(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=ei,typeof l==`object`&&l&&(c=Ki(l)),s=n.getDerivedStateFromProps,(l=typeof s==`function`||typeof a.getSnapshotBeforeUpdate==`function`)||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(o!==d||f!==c)&&Ls(t,a,r,c),W=!1,f=t.memoizedState,a.state=f,ja(t,r,a,i),Aa();var p=t.memoizedState;o!==d||f!==p||W||e!==null&&e.dependencies!==null&&Wi(e.dependencies)?(typeof s==`function`&&(Ps(t,n,s,r),p=t.memoizedState),(u=W||Is(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&Wi(e.dependencies))?(l||typeof a.UNSAFE_componentWillUpdate!=`function`&&typeof a.componentWillUpdate!=`function`||(typeof a.componentWillUpdate==`function`&&a.componentWillUpdate(r,p,c),typeof a.UNSAFE_componentWillUpdate==`function`&&a.UNSAFE_componentWillUpdate(r,p,c)),typeof a.componentDidUpdate==`function`&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=c,r=u):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return a=r,rc(e,t),r=!!(t.flags&128),a||r?(a=t.stateNode,n=r&&typeof n.getDerivedStateFromError!=`function`?null:a.render(),t.flags|=1,e!==null&&r?(t.child=ws(t,e.child,null,i),t.child=ws(t,null,n,i)):Zs(e,t,n,i),t.memoizedState=a.state,e=t.child):e=vc(e,t,i),e}function sc(e,t,n,r){return Ni(),t.flags|=256,Zs(e,t,n,r),t.child}var cc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function lc(e){return{baseLanes:e,cachePool:fa()}}function uc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=Bl),e}function dc(e,t,n){var r=t.pendingProps,a=!1,o=!!(t.flags&128),s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:!!(Ms.current&2)),s&&(a=!0,t.flags&=-129),s=!!(t.flags&32),t.flags&=-33,e===null){if(Ti){if(a?Os(t):As(t),Ti){var c=wi,l;if(l=c){c:{for(l=c,c=Di;l.nodeType!==8;)if(!c||(l=Jd(l.nextSibling),l===null)){c=null;break c}c=l}c===null?l=!1:(t.memoizedState={dehydrated:c,treeContext:gi===null?null:{id:_i,overflow:vi},retryLane:536870912,hydrationErrors:null},l=ni(18,null,null,0),l.stateNode=c,l.return=t,t.child=l,Ci=t,wi=null,l=!0)}l||ki(t)}if(c=t.memoizedState,c!==null&&(c=c.dehydrated,c!==null))return Kd(c)?t.lanes=32:t.lanes=536870912,null;js(t)}return c=r.children,r=r.fallback,a?(As(t),a=t.mode,c=pc({mode:`hidden`,children:c},a),r=si(r,a,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,a=t.child,a.memoizedState=lc(n),a.childLanes=uc(e,s,n),t.memoizedState=cc,r):(Os(t),fc(t,c))}if(l=e.memoizedState,l!==null&&(c=l.dehydrated,c!==null)){if(o)t.flags&256?(Os(t),t.flags&=-257,t=mc(e,t,n)):t.memoizedState===null?(As(t),a=r.fallback,c=t.mode,r=pc({mode:`visible`,children:r.children},c),a=si(a,c,n,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,ws(t,e.child,null,n),r=t.child,r.memoizedState=lc(n),r.childLanes=uc(e,s,n),t.memoizedState=cc,t=a):(As(t),t.child=e.child,t.flags|=128,t=null);else if(Os(t),Kd(c)){if(s=c.nextSibling&&c.nextSibling.dataset,s)var u=s.dgst;s=u,r=Error(i(419)),r.stack=``,r.digest=s,Fi({value:r,source:null,stack:null}),t=mc(e,t,n)}else if(Xs||Ui(e,t,n,!1),s=(n&e.childLanes)!==0,Xs||s){if(s=kl,s!==null&&(r=n&-n,r=r&42?1:We(r),r=(r&(s.suspendedLanes|n))===0?r:0,r!==0&&r!==l.retryLane))throw l.retryLane=r,Zr(e,r),ou(s,e,r),Ys;c.data===`$?`||_u(),t=mc(e,t,n)}else c.data===`$?`?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,wi=Jd(c.nextSibling),Ci=t,Ti=!0,Ei=null,Di=!1,e!==null&&(mi[hi++]=_i,mi[hi++]=vi,mi[hi++]=gi,_i=e.id,vi=e.overflow,gi=t),t=fc(t,r.children),t.flags|=4096);return t}return a?(As(t),a=r.fallback,c=t.mode,l=e.child,u=l.sibling,r=ii(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(a=si(a,c,n,null),a.flags|=2):a=ii(u,a),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,c=e.child.memoizedState,c===null?c=lc(n):(l=c.cachePool,l===null?l=fa():(u=Qi._currentValue,l=l.parent===u?l:{parent:u,pool:u}),c={baseLanes:c.baseLanes|n,cachePool:l}),a.memoizedState=c,a.childLanes=uc(e,s,n),t.memoizedState=cc,r):(Os(t),n=e.child,e=n.sibling,n=ii(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=n,t.memoizedState=null,n)}function fc(e,t){return t=pc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function pc(e,t){return e=ni(22,e,null,t),e.lanes=0,e.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null},e}function mc(e,t,n){return ws(t,e.child,null,n),e=fc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function hc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Vi(e.return,t,n)}function gc(e,t,n,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=n,a.tailMode=i)}function _c(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Zs(e,t,r.children,n),r=Ms.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&hc(e,n,t);else if(e.tag===19)hc(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}switch(R(Ms,r),i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&Ns(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),gc(t,!1,i,n,a);break;case`backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&Ns(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}gc(t,!0,n,null,a);break;case`together`:gc(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function vc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ll|=t.lanes,(n&t.childLanes)===0){if(e!==null){if(Ui(e,t,n,!1),(n&t.childLanes)===0)return null}else return null}if(e!==null&&t.child!==e.child)throw Error(i(153));if(t.child!==null){for(e=t.child,n=ii(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=ii(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function yc(e,t){return(e.lanes&t)!==0||(e=e.dependencies,!!(e!==null&&Wi(e)))}function bc(e,t,n){switch(t.tag){case 3:le(t,t.stateNode.containerInfo),zi(t,Qi,e.memoizedState.cache),Ni();break;case 27:case 5:de(t);break;case 4:le(t,t.stateNode.containerInfo);break;case 10:zi(t,t.type,t.memoizedProps.value);break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(Os(t),e=vc(e,t,n),e===null?null:e.sibling):dc(e,t,n):(Os(t),t.flags|=128,null);Os(t);break;case 19:var i=!!(e.flags&128);if(r=(n&t.childLanes)!==0,r||=(Ui(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return _c(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),R(Ms,Ms.current),r)break;return null;case 22:case 23:return t.lanes=0,tc(e,t,n);case 24:zi(t,Qi,e.memoizedState.cache)}return vc(e,t,n)}function xc(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps)Xs=!0;else{if(!yc(e,n)&&!(t.flags&128))return Xs=!1,bc(e,t,n);Xs=!!(e.flags&131072)}}else Xs=!1,Ti&&t.flags&1048576&&bi(t,pi,t.index);switch(t.lanes=0,t.tag){case 16:a:{e=t.pendingProps;var r=t.elementType,a=r._init;if(r=a(r._payload),t.type=r,typeof r==`function`)ri(r)?(e=Rs(r,e),t.tag=1,t=oc(null,t,r,e,n)):(t.tag=0,t=ic(null,t,r,e,n));else{if(r!=null){if(a=r.$$typeof,a===w){t.tag=11,t=Qs(null,t,r,e,n);break a}if(a===ee){t.tag=14,t=$s(null,t,r,e,n);break a}}throw t=ne(r)||r,Error(i(306,t,``))}}return t;case 0:return ic(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,a=Rs(r,t.pendingProps),oc(e,t,r,a,n);case 3:a:{if(le(t,t.stateNode.containerInfo),e===null)throw Error(i(387));r=t.pendingProps;var o=t.memoizedState;a=o.element,wa(e,t),ja(t,r,null,n);var s=t.memoizedState;if(r=s.cache,zi(t,Qi,r),r!==o.cache&&Hi(t,[Qi],n,!0),Aa(),r=s.element,o.isDehydrated){if(o={element:r,isDehydrated:!1,cache:s.cache},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){t=sc(e,t,r,n);break a}if(r!==a){a=Wr(Error(i(424)),t),Fi(a),t=sc(e,t,r,n);break a}switch(e=t.stateNode.containerInfo,e.nodeType){case 9:e=e.body;break;default:e=e.nodeName===`HTML`?e.ownerDocument.body:e}for(wi=Jd(e.firstChild),Ci=t,Ti=!0,Ei=null,Di=!0,n=Ts(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Ni(),r===a){t=vc(e,t,n);break a}Zs(e,t,r,n)}t=t.child}return t;case 26:return rc(e,t),e===null?(n=hf(t.type,null,t.pendingProps,null))?t.memoizedState=n:Ti||(n=t.type,e=t.pendingProps,r=Ad(se.current).createElement(n),r[Ye]=t,r[Xe]=e,Y(r,n,e),H(r),t.stateNode=r):t.memoizedState=hf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return de(t),e===null&&Ti&&(r=t.stateNode=Zd(t.type,t.pendingProps,se.current),Ci=t,Di=!0,a=wi,Vd(t.type)?(Yd=a,wi=Jd(r.firstChild)):wi=a),Zs(e,t,t.pendingProps.children,n),rc(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&Ti&&((a=r=wi)&&(r=Wd(r,t.type,t.pendingProps,Di),r===null?a=!1:(t.stateNode=r,Ci=t,wi=Jd(r.firstChild),Di=!1,a=!0)),a||ki(t)),de(t),a=t.type,o=t.pendingProps,s=e===null?null:e.memoizedProps,r=o.children,Nd(a,o)?r=null:s!==null&&Nd(a,s)&&(t.flags|=32),t.memoizedState!==null&&(a=Za(e,t,eo,null,null,n),zf._currentValue=a),rc(e,t),Zs(e,t,r,n),t.child;case 6:return e===null&&Ti&&((e=n=wi)&&(n=Gd(n,t.pendingProps,Di),n===null?e=!1:(t.stateNode=n,Ci=t,wi=null,e=!0)),e||ki(t)),null;case 13:return dc(e,t,n);case 4:return le(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ws(t,null,r,n):Zs(e,t,r,n),t.child;case 11:return Qs(e,t,t.type,t.pendingProps,n);case 7:return Zs(e,t,t.pendingProps,n),t.child;case 8:return Zs(e,t,t.pendingProps.children,n),t.child;case 12:return Zs(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,zi(t,t.type,r.value),Zs(e,t,r.children,n),t.child;case 9:return a=t.type._context,r=t.pendingProps.children,Gi(t),a=Ki(a),r=r(a),t.flags|=1,Zs(e,t,r,n),t.child;case 14:return $s(e,t,t.type,t.pendingProps,n);case 15:return ec(e,t,t.type,t.pendingProps,n);case 19:return _c(e,t,n);case 31:return r=t.pendingProps,n=t.mode,r={mode:r.mode,children:r.children},e===null?(n=pc(r,n),n.ref=t.ref,t.child=n,n.return=t,t=n):(n=ii(e.child,r),n.ref=t.ref,t.child=n,n.return=t,t=n),t;case 22:return tc(e,t,n);case 24:return Gi(t),r=Ki(Qi),e===null?(a=ua(),a===null&&(a=kl,o=$i(),a.pooledCache=o,o.refCount++,o!==null&&(a.pooledCacheLanes|=n),a=o),t.memoizedState={parent:r,cache:a},Ca(t),zi(t,Qi,a)):((e.lanes&n)!==0&&(wa(e,t),ja(t,null,null,n),Aa()),a=e.memoizedState,o=t.memoizedState,a.parent===r?(r=o.cache,zi(t,Qi,r),r!==a.cache&&Hi(t,[Qi],n,!0)):(a={parent:r,cache:r},t.memoizedState=a,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=a),zi(t,Qi,r))),Zs(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(i(156,t.tag))}function Sc(e){e.flags|=4}function Cc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!Af(t)){if(t=Es.current,t!==null&&((q&4194048)===q?Ds!==null:(q&62914560)!==q&&!(q&536870912)||t!==Ds))throw ba=ga,ma;e.flags|=8192}}function wc(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Re(),e.lanes|=t,Vl|=t)}function Tc(e,t){if(!Ti)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Ec(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&65011712,r|=i.flags&65011712,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Dc(e,t,n){var r=t.pendingProps;switch(Si(t),t.tag){case 31:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Ec(t),null;case 1:return Ec(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Bi(Qi),ue(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Mi(t)?Sc(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Pi())),Ec(t),null;case 26:return n=t.memoizedState,e===null?(Sc(t),n===null?(Ec(t),t.flags&=-16777217):(Ec(t),Cc(t,n))):n?n===e.memoizedState?(Ec(t),t.flags&=-16777217):(Sc(t),Ec(t),Cc(t,n)):(e.memoizedProps!==r&&Sc(t),Ec(t),t.flags&=-16777217),null;case 27:fe(t),n=se.current;var a=t.type;if(e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ec(t),null}e=ae.current,Mi(t)?Ai(t,e):(e=Zd(a,r,n),t.stateNode=e,Sc(t))}return Ec(t),null;case 5:if(fe(t),n=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ec(t),null}if(e=ae.current,Mi(t))Ai(t,e);else{switch(a=Ad(se.current),e){case 1:e=a.createElementNS(`http://www.w3.org/2000/svg`,n);break;case 2:e=a.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;default:switch(n){case`svg`:e=a.createElementNS(`http://www.w3.org/2000/svg`,n);break;case`math`:e=a.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;case`script`:e=a.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild);break;case`select`:e=typeof r.is==`string`?a.createElement(`select`,{is:r.is}):a.createElement(`select`),r.multiple?e.multiple=!0:r.size&&(e.size=r.size);break;default:e=typeof r.is==`string`?a.createElement(n,{is:r.is}):a.createElement(n)}}e[Ye]=t,e[Xe]=r;a:for(a=t.child;a!==null;){if(a.tag===5||a.tag===6)e.appendChild(a.stateNode);else if(a.tag!==4&&a.tag!==27&&a.child!==null){a.child.return=a,a=a.child;continue}if(a===t)break a;for(;a.sibling===null;){if(a.return===null||a.return===t)break a;a=a.return}a.sibling.return=a.return,a=a.sibling}t.stateNode=e;a:switch(Y(e,n,r),n){case`button`:case`input`:case`select`:case`textarea`:e=!!r.autoFocus;break a;case`img`:e=!0;break a;default:e=!1}e&&Sc(t)}}return Ec(t),t.flags&=-16777217,null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(i(166));if(e=se.current,Mi(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,a=Ci,a!==null)switch(a.tag){case 27:case 5:r=a.memoizedProps}e[Ye]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Cd(e.nodeValue,n)),e||ki(t)}else e=Ad(e).createTextNode(r),e[Ye]=t,t.stateNode=e}return Ec(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Mi(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(i(318));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(i(317));a[Ye]=t}else Ni(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Ec(t),a=!1}else a=Pi(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(js(t),t):(js(t),null)}if(js(t),t.flags&128)return t.lanes=n,t;if(n=r!==null,e=e!==null&&e.memoizedState!==null,n){r=t.child,a=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(a=r.alternate.memoizedState.cachePool.pool);var o=null;r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(o=r.memoizedState.cachePool.pool),o!==a&&(r.flags|=2048)}return n!==e&&n&&(t.child.flags|=8192),wc(t,t.updateQueue),Ec(t),null;case 4:return ue(),e===null&&pd(t.stateNode.containerInfo),Ec(t),null;case 10:return Bi(t.type),Ec(t),null;case 19:if(L(Ms),a=t.memoizedState,a===null)return Ec(t),null;if(r=!!(t.flags&128),o=a.rendering,o===null){if(r)Tc(a,!1);else{if(Il!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=Ns(e),o!==null){for(t.flags|=128,Tc(a,!1),e=o.updateQueue,t.updateQueue=e,wc(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)ai(n,e),n=n.sibling;return R(Ms,Ms.current&1|2),t.child}e=e.sibling}a.tail!==null&&_e()>Kl&&(t.flags|=128,r=!0,Tc(a,!1),t.lanes=4194304)}}else{if(!r){if(e=Ns(o),e!==null){if(t.flags|=128,r=!0,e=e.updateQueue,t.updateQueue=e,wc(t,e),Tc(a,!0),a.tail===null&&a.tailMode===`hidden`&&!o.alternate&&!Ti)return Ec(t),null}else 2*_e()-a.renderingStartTime>Kl&&n!==536870912&&(t.flags|=128,r=!0,Tc(a,!1),t.lanes=4194304)}a.isBackwards?(o.sibling=t.child,t.child=o):(e=a.last,e===null?t.child=o:e.sibling=o,a.last=o)}return a.tail===null?(Ec(t),null):(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=_e(),t.sibling=null,e=Ms.current,R(Ms,r?e&1|2:e&1),t);case 22:case 23:return js(t),Ra(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Ec(t),t.subtreeFlags&6&&(t.flags|=8192)):Ec(t),n=t.updateQueue,n!==null&&wc(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==n&&(t.flags|=2048),e!==null&&L(la),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),Bi(Qi),Ec(t),null;case 25:return null;case 30:return null}throw Error(i(156,t.tag))}function Oc(e,t){switch(Si(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Bi(Qi),ue(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return fe(t),null;case 13:if(js(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(i(340));Ni()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return L(Ms),null;case 4:return ue(),null;case 10:return Bi(t.type),null;case 22:case 23:return js(t),Ra(),e!==null&&L(la),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Bi(Qi),null;case 25:return null;default:return null}}function kc(e,t){switch(Si(t),t.tag){case 3:Bi(Qi),ue();break;case 26:case 27:case 5:fe(t);break;case 4:ue();break;case 13:js(t);break;case 19:L(Ms);break;case 10:Bi(t.type);break;case 22:case 23:js(t),Ra(),e!==null&&L(la);break;case 24:Bi(Qi)}}function Ac(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){Fu(t,t.return,e)}}function jc(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){Fu(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Fu(t,t.return,e)}}function Mc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Na(t,n)}catch(t){Fu(e,e.return,t)}}}function Nc(e,t,n){n.props=Rs(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Fu(e,t,n)}}function Pc(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=e.stateNode;break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){Fu(e,t,n)}}function Fc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null){if(typeof r==`function`)try{r()}catch(n){Fu(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){Fu(e,t,n)}else n.current=null}}function Ic(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{a:switch(t){case`button`:case`input`:case`select`:case`textarea`:n.autoFocus&&r.focus();break a;case`img`:n.src?r.src=n.src:n.srcSet&&(r.srcset=n.srcSet)}}catch(t){Fu(e,e.return,t)}}function Lc(e,t,n){try{var r=e.stateNode;Dd(r,e.type,n,t),r[Xe]=t}catch(t){Fu(e,e.return,t)}}function Rc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Vd(e.type)||e.tag===4}function zc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Rc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Vd(e.type)||e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Bc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?(n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n).insertBefore(e,t):(t=n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n,t.appendChild(e),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=wd));else if(r!==4&&(r===27&&Vd(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(Bc(e,t,n),e=e.sibling;e!==null;)Bc(e,t,n),e=e.sibling}function Vc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(r===27&&Vd(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(Vc(e,t,n),e=e.sibling;e!==null;)Vc(e,t,n),e=e.sibling}function Hc(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Y(t,r,n),t[Ye]=e,t[Xe]=n}catch(t){Fu(e,e.return,t)}}var Uc=!1,Wc=!1,Gc=!1,Kc=typeof WeakSet==`function`?WeakSet:Set,qc=null;function Jc(e,t){if(e=e.containerInfo,Od=qf,e=br(e),xr(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var a=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||r!==0&&f.nodeType!==3||(l=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===r&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(kd={focusedElem:e,selectionRange:n},qf=!1,qc=t;qc!==null;)if(t=qc,e=t.child,t.subtreeFlags&1024&&e!==null)e.return=t,qc=e;else for(;qc!==null;){switch(t=qc,o=t.alternate,e=t.flags,t.tag){case 0:break;case 11:case 15:break;case 1:if(e&1024&&o!==null){e=void 0,n=t,a=o.memoizedProps,o=o.memoizedState,r=n.stateNode;try{var h=Rs(n.type,a,n.elementType===n.type);e=r.getSnapshotBeforeUpdate(h,o),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){Fu(n,n.return,e)}}break;case 3:if(e&1024){if(e=t.stateNode.containerInfo,n=e.nodeType,n===9)Ud(e);else if(n===1)switch(e.nodeName){case`HEAD`:case`HTML`:case`BODY`:Ud(e);break;default:e.textContent=``}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;default:if(e&1024)throw Error(i(163))}if(e=t.sibling,e!==null){e.return=t.return,qc=e;break}qc=t.return}}function Yc(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:ll(e,n),r&4&&Ac(5,n);break;case 1:if(ll(e,n),r&4){if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){Fu(n,n.return,e)}else{var i=Rs(n.type,t.memoizedProps);t=t.memoizedState;try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){Fu(n,n.return,e)}}}r&64&&Mc(n),r&512&&Pc(n,n.return);break;case 3:if(ll(e,n),r&64&&(e=n.updateQueue,e!==null)){if(t=null,n.child!==null)switch(n.child.tag){case 27:case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}try{Na(e,t)}catch(e){Fu(n,n.return,e)}}break;case 27:t===null&&r&4&&Hc(n);case 26:case 5:ll(e,n),t===null&&r&4&&Ic(n),r&512&&Pc(n,n.return);break;case 12:ll(e,n);break;case 13:ll(e,n),r&4&&tl(e,n),r&64&&(e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(n=zu.bind(null,n),qd(e,n))));break;case 22:if(r=n.memoizedState!==null||Uc,!r){t=t!==null&&t.memoizedState!==null||Wc,i=Uc;var a=Wc;Uc=r,(Wc=t)&&!a?dl(e,n,!!(n.subtreeFlags&8772)):ll(e,n),Uc=i,Wc=a}break;case 30:break;default:ll(e,n)}}function Xc(e){var t=e.alternate;t!==null&&(e.alternate=null,Xc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&rt(t)),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}var Zc=null,Qc=!1;function $c(e,t,n){for(n=n.child;n!==null;)el(e,t,n),n=n.sibling}function el(e,t,n){if(Te&&typeof Te.onCommitFiberUnmount==`function`)try{Te.onCommitFiberUnmount(V,n)}catch{}switch(n.tag){case 26:Wc||Fc(n,t),$c(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:Wc||Fc(n,t);var r=Zc,i=Qc;Vd(n.type)&&(Zc=n.stateNode,Qc=!1),$c(e,t,n),Qd(n.stateNode),Zc=r,Qc=i;break;case 5:Wc||Fc(n,t);case 6:if(r=Zc,i=Qc,Zc=null,$c(e,t,n),Zc=r,Qc=i,Zc!==null){if(Qc)try{(Zc.nodeType===9?Zc.body:Zc.nodeName===`HTML`?Zc.ownerDocument.body:Zc).removeChild(n.stateNode)}catch(e){Fu(n,t,e)}else try{Zc.removeChild(n.stateNode)}catch(e){Fu(n,t,e)}}break;case 18:Zc!==null&&(Qc?(e=Zc,Hd(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),yp(e)):Hd(Zc,n.stateNode));break;case 4:r=Zc,i=Qc,Zc=n.stateNode.containerInfo,Qc=!0,$c(e,t,n),Zc=r,Qc=i;break;case 0:case 11:case 14:case 15:Wc||jc(2,n,t),Wc||jc(4,n,t),$c(e,t,n);break;case 1:Wc||(Fc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Nc(n,t,r)),$c(e,t,n);break;case 21:$c(e,t,n);break;case 22:Wc=(r=Wc)||n.memoizedState!==null,$c(e,t,n),Wc=r;break;default:$c(e,t,n)}}function tl(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{yp(e)}catch(e){Fu(t,t.return,e)}}function nl(e){switch(e.tag){case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new Kc),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new Kc),t;default:throw Error(i(435,e.tag))}}function rl(e,t){var n=nl(e);t.forEach(function(t){var r=Bu.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}function il(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var a=n[r],o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 27:if(Vd(c.type)){Zc=c.stateNode,Qc=!1;break a}break;case 5:Zc=c.stateNode,Qc=!1;break a;case 3:case 4:Zc=c.stateNode.containerInfo,Qc=!0;break a}c=c.return}if(Zc===null)throw Error(i(160));el(o,s,a),Zc=null,Qc=!1,o=a.alternate,o!==null&&(o.return=null),a.return=null}if(t.subtreeFlags&13878)for(t=t.child;t!==null;)ol(t,e),t=t.sibling}var al=null;function ol(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:il(t,e),sl(e),r&4&&(jc(3,e,e.return),Ac(3,e),jc(5,e,e.return));break;case 1:il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),r&64&&Uc&&(e=e.updateQueue,e!==null&&(r=e.callbacks,r!==null&&(n=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=n===null?r:n.concat(r))));break;case 26:var a=al;if(il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),r&4){var o=n===null?null:n.memoizedState;if(r=e.memoizedState,n===null){if(r===null){if(e.stateNode===null){a:{r=e.type,n=e.memoizedProps,a=a.ownerDocument||a;b:switch(r){case`title`:o=a.getElementsByTagName(`title`)[0],(!o||o[nt]||o[Ye]||o.namespaceURI===`http://www.w3.org/2000/svg`||o.hasAttribute(`itemprop`))&&(o=a.createElement(r),a.head.insertBefore(o,a.querySelector(`head > title`))),Y(o,r,n),o[Ye]=e,H(o),r=o;break a;case`link`:var s=Df(`link`,`href`,a).get(r+(n.href||``));if(s){for(var c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&o.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&o.getAttribute(`title`)===(n.title==null?null:n.title)&&o.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){s.splice(c,1);break b}}o=a.createElement(r),Y(o,r,n),a.head.appendChild(o);break;case`meta`:if(s=Df(`meta`,`content`,a).get(r+(n.content||``))){for(c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`content`)===(n.content==null?null:``+n.content)&&o.getAttribute(`name`)===(n.name==null?null:n.name)&&o.getAttribute(`property`)===(n.property==null?null:n.property)&&o.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&o.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){s.splice(c,1);break b}}o=a.createElement(r),Y(o,r,n),a.head.appendChild(o);break;default:throw Error(i(468,r))}o[Ye]=e,H(o),r=o}e.stateNode=r}else Of(a,e.type,e.stateNode)}else e.stateNode=Sf(a,r,e.memoizedProps)}else o===r?r===null&&e.stateNode!==null&&Lc(e,e.memoizedProps,n.memoizedProps):(o===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):o.count--,r===null?Of(a,e.type,e.stateNode):Sf(a,r,e.memoizedProps))}break;case 27:il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),n!==null&&r&4&&Lc(e,e.memoizedProps,n.memoizedProps);break;case 5:if(il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),e.flags&32){a=e.stateNode;try{zt(a,``)}catch(t){Fu(e,e.return,t)}}r&4&&e.stateNode!=null&&(a=e.memoizedProps,Lc(e,a,n===null?a:n.memoizedProps)),r&1024&&(Gc=!0);break;case 6:if(il(t,e),sl(e),r&4){if(e.stateNode===null)throw Error(i(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){Fu(e,e.return,t)}}break;case 3:if(Ef=null,a=al,al=tf(t.containerInfo),il(t,e),al=a,sl(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{yp(t.containerInfo)}catch(t){Fu(e,e.return,t)}Gc&&(Gc=!1,cl(e));break;case 4:r=al,al=tf(e.stateNode.containerInfo),il(t,e),sl(e),al=r;break;case 12:il(t,e),sl(e);break;case 13:il(t,e),sl(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(Gl=_e()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,rl(e,r)));break;case 22:a=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=Uc,d=Wc;if(Uc=u||a,Wc=d||l,il(t,e),Wc=d,Uc=u,sl(e),r&8192)a:for(t=e.stateNode,t._visibility=a?t._visibility&-2:t._visibility|1,a&&(n===null||l||Uc||Wc||ul(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(o=l.stateNode,a)s=o.style,typeof s.setProperty==`function`?s.setProperty(`display`,`none`,`important`):s.display=`none`;else{c=l.stateNode;var f=l.memoizedProps.style,p=f!=null&&f.hasOwnProperty(`display`)?f.display:null;c.style.display=p==null||typeof p==`boolean`?``:(``+p).trim()}}catch(e){Fu(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=a?``:l.memoizedProps}catch(e){Fu(l,l.return,e)}}}else if((t.tag!==22&&t.tag!==23||t.memoizedState===null||t===e)&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break a;for(;t.sibling===null;){if(t.return===null||t.return===e)break a;n===t&&(n=null),t=t.return}n===t&&(n=null),t.sibling.return=t.return,t=t.sibling}r&4&&(r=e.updateQueue,r!==null&&(n=r.retryQueue,n!==null&&(r.retryQueue=null,rl(e,n))));break;case 19:il(t,e),sl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,rl(e,r)));break;case 30:break;case 21:break;default:il(t,e),sl(e)}}function sl(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if(Rc(r)){n=r;break}r=r.return}if(n==null)throw Error(i(160));switch(n.tag){case 27:var a=n.stateNode;Vc(e,zc(e),a);break;case 5:var o=n.stateNode;n.flags&32&&(zt(o,``),n.flags&=-33),Vc(e,zc(e),o);break;case 3:case 4:var s=n.stateNode.containerInfo;Bc(e,zc(e),s);break;default:throw Error(i(161))}}catch(t){Fu(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function cl(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;cl(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function ll(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)Yc(e,t.alternate,t),t=t.sibling}function ul(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:jc(4,t,t.return),ul(t);break;case 1:Fc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Nc(t,t.return,n),ul(t);break;case 27:Qd(t.stateNode);case 26:case 5:Fc(t,t.return),ul(t);break;case 22:t.memoizedState===null&&ul(t);break;case 30:ul(t);break;default:ul(t)}e=e.sibling}}function dl(e,t,n){for(n&&=!!(t.subtreeFlags&8772),t=t.child;t!==null;){var r=t.alternate,i=e,a=t,o=a.flags;switch(a.tag){case 0:case 11:case 15:dl(i,a,n),Ac(4,a);break;case 1:if(dl(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){Fu(r,r.return,e)}if(r=a,i=r.updateQueue,i!==null){var s=r.stateNode;try{var c=i.shared.hiddenCallbacks;if(c!==null)for(i.shared.hiddenCallbacks=null,i=0;i<c.length;i++)Ma(c[i],s)}catch(e){Fu(r,r.return,e)}}n&&o&64&&Mc(a),Pc(a,a.return);break;case 27:Hc(a);case 26:case 5:dl(i,a,n),n&&r===null&&o&4&&Ic(a),Pc(a,a.return);break;case 12:dl(i,a,n);break;case 13:dl(i,a,n),n&&o&4&&tl(i,a);break;case 22:a.memoizedState===null&&dl(i,a,n),Pc(a,a.return);break;case 30:break;default:dl(i,a,n)}t=t.sibling}}function fl(e,t){var n=null;e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),e=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(e=t.memoizedState.cachePool.pool),e!==n&&(e!=null&&e.refCount++,n!=null&&ea(n))}function pl(e,t){e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&ea(e))}function ml(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)hl(e,t,n,r),t=t.sibling}function hl(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:ml(e,t,n,r),i&2048&&Ac(9,t);break;case 1:ml(e,t,n,r);break;case 3:ml(e,t,n,r),i&2048&&(e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&ea(e)));break;case 12:if(i&2048){ml(e,t,n,r),e=t.stateNode;try{var a=t.memoizedProps,o=a.id,s=a.onPostCommit;typeof s==`function`&&s(o,t.alternate===null?`mount`:`update`,e.passiveEffectDuration,-0)}catch(e){Fu(t,t.return,e)}}else ml(e,t,n,r);break;case 13:ml(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?ml(e,t,n,r):(a._visibility|=2,gl(e,t,n,r,!!(t.subtreeFlags&10256))):a._visibility&2?ml(e,t,n,r):_l(e,t),i&2048&&fl(o,t);break;case 24:ml(e,t,n,r),i&2048&&pl(t.alternate,t);break;default:ml(e,t,n,r)}}function gl(e,t,n,r,i){for(i&&=!!(t.subtreeFlags&10256),t=t.child;t!==null;){var a=e,o=t,s=n,c=r,l=o.flags;switch(o.tag){case 0:case 11:case 15:gl(a,o,s,c,i),Ac(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,gl(a,o,s,c,i)):u._visibility&2?gl(a,o,s,c,i):_l(a,o),i&&l&2048&&fl(o.alternate,o);break;case 24:gl(a,o,s,c,i),i&&l&2048&&pl(o.alternate,o);break;default:gl(a,o,s,c,i)}t=t.sibling}}function _l(e,t){if(t.subtreeFlags&10256)for(t=t.child;t!==null;){var n=e,r=t,i=r.flags;switch(r.tag){case 22:_l(n,r),i&2048&&fl(r.alternate,r);break;case 24:_l(n,r),i&2048&&pl(r.alternate,r);break;default:_l(n,r)}t=t.sibling}}var vl=8192;function yl(e){if(e.subtreeFlags&vl)for(e=e.child;e!==null;)bl(e),e=e.sibling}function bl(e){switch(e.tag){case 26:yl(e),e.flags&vl&&e.memoizedState!==null&&Nf(al,e.memoizedState,e.memoizedProps);break;case 5:yl(e);break;case 3:case 4:var t=al;al=tf(e.stateNode.containerInfo),yl(e),al=t;break;case 22:e.memoizedState===null&&(t=e.alternate,t!==null&&t.memoizedState!==null?(t=vl,vl=16777216,yl(e),vl=t):yl(e));break;default:yl(e)}}function xl(e){var t=e.alternate;if(t!==null&&(e=t.child,e!==null)){t.child=null;do t=e.sibling,e.sibling=null,e=t;while(e!==null)}}function Sl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];qc=r,Tl(r,e)}xl(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)Cl(e),e=e.sibling}function Cl(e){switch(e.tag){case 0:case 11:case 15:Sl(e),e.flags&2048&&jc(9,e,e.return);break;case 3:Sl(e);break;case 12:Sl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,wl(e)):Sl(e);break;default:Sl(e)}}function wl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];qc=r,Tl(r,e)}xl(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:jc(8,t,t.return),wl(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,wl(t));break;default:wl(t)}e=e.sibling}}function Tl(e,t){for(;qc!==null;){var n=qc;switch(n.tag){case 0:case 11:case 15:jc(8,n,t);break;case 23:case 22:if(n.memoizedState!==null&&n.memoizedState.cachePool!==null){var r=n.memoizedState.cachePool.pool;r!=null&&r.refCount++}break;case 24:ea(n.memoizedState.cache)}if(r=n.child,r!==null)r.return=n,qc=r;else a:for(n=e;qc!==null;){r=qc;var i=r.sibling,a=r.return;if(Xc(r),r===n){qc=null;break a}if(i!==null){i.return=a,qc=i;break a}qc=a}}}var El={getCacheForType:function(e){var t=Ki(Qi),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n}},Dl=typeof WeakMap==`function`?WeakMap:Map,Ol=0,kl=null,K=null,q=0,Al=0,jl=null,Ml=!1,Nl=!1,Pl=!1,Fl=0,Il=0,Ll=0,Rl=0,zl=0,Bl=0,Vl=0,Hl=null,Ul=null,Wl=!1,Gl=0,Kl=1/0,ql=null,Jl=null,Yl=0,Xl=null,Zl=null,Ql=0,$l=0,eu=null,tu=null,nu=0,ru=null;function iu(){if(Ol&2&&q!==0)return q&-q;if(M.T!==null){var e=ra;return e===0?nd():e}return Ke()}function au(){Bl===0&&(Bl=!(q&536870912)||Ti?Le():536870912);var e=Es.current;return e!==null&&(e.flags|=32),Bl}function ou(e,t,n){(e===kl&&(Al===2||Al===9)||e.cancelPendingCommit!==null)&&(pu(e,0),uu(e,q,Bl,!1)),Be(e,n),Ol&2&&e===kl||(e===kl&&(!(Ol&2)&&(Rl|=n),Il===4&&uu(e,q,Bl,!1)),Ju(e))}function su(e,t,n){if(Ol&6)throw Error(i(327));var r=!n&&!(t&124)&&(t&e.expiredLanes)===0||Fe(e,t),a=r?bu(e,t):vu(e,t,!0),o=r;do{if(a===0){Nl&&!r&&uu(e,t,0,!1);break}if(n=e.current.alternate,o&&!lu(n))a=vu(e,t,!1),o=!1;else{if(a===2){if(o=t,e.errorRecoveryDisabledLanes&o)var s=0;else s=e.pendingLanes&-536870913,s=s===0?s&536870912?536870912:0:s;if(s!==0){t=s;a:{var c=e;a=Hl;var l=c.current.memoizedState.isDehydrated;if(l&&(pu(c,s).flags|=256),s=vu(c,s,!1),s!==2){if(Pl&&!l){c.errorRecoveryDisabledLanes|=o,Rl|=o,a=4;break a}o=Ul,Ul=a,o!==null&&(Ul===null?Ul=o:Ul.push.apply(Ul,o))}a=s}if(o=!1,a!==2)continue}}if(a===1){pu(e,0),uu(e,t,0,!0);break}a:{switch(r=e,o=a,o){case 0:case 1:throw Error(i(345));case 4:if((t&4194048)!==t)break;case 6:uu(r,t,Bl,!Ml);break a;case 2:Ul=null;break;case 3:case 5:break;default:throw Error(i(329))}if((t&62914560)===t&&(a=Gl+300-_e(),10<a)){if(uu(r,t,Bl,!Ml),Pe(r,0,!0)!==0)break a;r.timeoutHandle=Id(cu.bind(null,r,n,Ul,ql,Wl,t,Bl,Rl,Vl,Ml,o,2,-0,0),a);break a}cu(r,n,Ul,ql,Wl,t,Bl,Rl,Vl,Ml,o,0,-0,0)}break}}while(1);Ju(e)}function cu(e,t,n,r,i,a,o,s,c,l,u,d,f,p){e.timeoutHandle=-1,d=t.subtreeFlags,(d&8192||(d&16785408)==16785408)&&(jf={stylesheets:null,count:0,unsuspend:Mf},bl(t),d=Pf(),d!==null)?(e.cancelPendingCommit=d(Du.bind(null,e,t,a,n,r,i,o,s,c,u,1,f,p)),uu(e,a,o,!l)):Du(e,t,a,n,r,i,o,s,c)}function lu(e){for(var t=e;;){var n=t.tag;if((n===0||n===11||n===15)&&t.flags&16384&&(n=t.updateQueue,n!==null&&(n=n.stores,n!==null)))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!hr(a(),i))return!1}catch{return!1}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function uu(e,t,n,r){t&=~zl,t&=~Rl,e.suspendedLanes|=t,e.pingedLanes&=~t,r&&(e.warmLanes|=t),r=e.expirationTimes;for(var i=t;0<i;){var a=31-De(i),o=1<<a;r[a]=-1,i&=~o}n!==0&&He(e,n,t)}function du(){return Ol&6?!0:(Yu(0,!1),!1)}function fu(){if(K!==null){if(Al===0)var e=K.return;else e=K,Ri=Li=null,ro(e),_s=null,vs=0,e=K;for(;e!==null;)kc(e.alternate,e),e=e.return;K=null}}function pu(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,Ld(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),fu(),kl=e,K=n=ii(e.current,null),q=t,Al=0,jl=null,Ml=!1,Nl=Fe(e,t),Pl=!1,Vl=Bl=zl=Rl=Ll=Il=0,Ul=Hl=null,Wl=!1,t&8&&(t|=t&32);var r=e.entangledLanes;if(r!==0)for(e=e.entanglements,r&=t;0<r;){var i=31-De(r),a=1<<i;t|=e[i],r&=~a}return Fl=t,Jr(),n}function mu(e,t){G=null,M.H=ps,t===pa||t===ha?(t=xa(),Al=3):t===ma?(t=xa(),Al=4):Al=t===Ys?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,jl=t,K===null&&(Il=1,Us(e,Wr(t,e.current)))}function hu(){var e=M.H;return M.H=ps,e===null?ps:e}function gu(){var e=M.A;return M.A=El,e}function _u(){Il=4,Ml||(q&4194048)!==q&&Es.current!==null||(Nl=!0),!(Ll&134217727)&&!(Rl&134217727)||kl===null||uu(kl,q,Bl,!1)}function vu(e,t,n){var r=Ol;Ol|=2;var i=hu(),a=gu();(kl!==e||q!==t)&&(ql=null,pu(e,t)),t=!1;var o=Il;a:do try{if(Al!==0&&K!==null){var s=K,c=jl;switch(Al){case 8:fu(),o=6;break a;case 3:case 2:case 9:case 6:Es.current===null&&(t=!0);var l=Al;if(Al=0,jl=null,wu(e,s,c,l),n&&Nl){o=0;break a}break;default:l=Al,Al=0,jl=null,wu(e,s,c,l)}}yu(),o=Il;break}catch(t){mu(e,t)}while(1);return t&&e.shellSuspendCounter++,Ri=Li=null,Ol=r,M.H=i,M.A=a,K===null&&(kl=null,q=0,Jr()),o}function yu(){for(;K!==null;)Su(K)}function bu(e,t){var n=Ol;Ol|=2;var r=hu(),a=gu();kl!==e||q!==t?(ql=null,Kl=_e()+500,pu(e,t)):Nl=Fe(e,t);a:do try{if(Al!==0&&K!==null){t=K;var o=jl;b:switch(Al){case 1:Al=0,jl=null,wu(e,t,o,1);break;case 2:case 9:if(_a(o)){Al=0,jl=null,Cu(t);break}t=function(){Al!==2&&Al!==9||kl!==e||(Al=7),Ju(e)},o.then(t,t);break a;case 3:Al=7;break a;case 4:Al=5;break a;case 7:_a(o)?(Al=0,jl=null,Cu(t)):(Al=0,jl=null,wu(e,t,o,7));break;case 5:var s=null;switch(K.tag){case 26:s=K.memoizedState;case 5:case 27:var c=K;if(!s||Af(s)){Al=0,jl=null;var l=c.sibling;if(l!==null)K=l;else{var u=c.return;u===null?K=null:(K=u,Tu(u))}break b}}Al=0,jl=null,wu(e,t,o,5);break;case 6:Al=0,jl=null,wu(e,t,o,6);break;case 8:fu(),Il=6;break a;default:throw Error(i(462))}}xu();break}catch(t){mu(e,t)}while(1);return Ri=Li=null,M.H=r,M.A=a,Ol=n,K===null?(kl=null,q=0,Jr(),Il):0}function xu(){for(;K!==null&&!he();)Su(K)}function Su(e){var t=xc(e.alternate,e,Fl);e.memoizedProps=e.pendingProps,t===null?Tu(e):K=t}function Cu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=ac(n,t,t.pendingProps,t.type,void 0,q);break;case 11:t=ac(n,t,t.pendingProps,t.type.render,t.ref,q);break;case 5:ro(t);default:kc(n,t),t=K=ai(t,Fl),t=xc(n,t,Fl)}e.memoizedProps=e.pendingProps,t===null?Tu(e):K=t}function wu(e,t,n,r){Ri=Li=null,ro(t),_s=null,vs=0;var i=t.return;try{if(Js(e,i,t,n,q)){Il=1,Us(e,Wr(n,e.current)),K=null;return}}catch(t){if(i!==null)throw K=i,t;Il=1,Us(e,Wr(n,e.current)),K=null;return}t.flags&32768?(Ti||r===1?e=!0:Nl||q&536870912?e=!1:(Ml=e=!0,(r===2||r===9||r===3||r===6)&&(r=Es.current,r!==null&&r.tag===13&&(r.flags|=16384))),Eu(t,e)):Tu(t)}function Tu(e){var t=e;do{if(t.flags&32768){Eu(t,Ml);return}e=t.return;var n=Dc(t.alternate,t,Fl);if(n!==null){K=n;return}if(t=t.sibling,t!==null){K=t;return}K=t=e}while(t!==null);Il===0&&(Il=5)}function Eu(e,t){do{var n=Oc(e.alternate,e);if(n!==null){n.flags&=32767,K=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){K=e;return}K=e=n}while(e!==null);Il=6,K=null}function Du(e,t,n,r,a,o,s,c,l){e.cancelPendingCommit=null;do Mu();while(Yl!==0);if(Ol&6)throw Error(i(327));if(t!==null){if(t===e.current)throw Error(i(177));if(o=t.lanes|t.childLanes,o|=qr,Ve(e,n,o,s,c,l),e===kl&&(K=kl=null,q=0),Zl=t,Xl=e,Ql=n,$l=o,eu=a,tu=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,Vu(be,function(){return Nu(!0),null})):(e.callbackNode=null,e.callbackPriority=0),r=!!(t.flags&13878),t.subtreeFlags&13878||r){r=M.T,M.T=null,a=N.p,N.p=2,s=Ol,Ol|=4;try{Jc(e,t,n)}finally{Ol=s,N.p=a,M.T=r}}Yl=1,Ou(),ku(),Au()}}function Ou(){if(Yl===1){Yl=0;var e=Xl,t=Zl,n=!!(t.flags&13878);if(t.subtreeFlags&13878||n){n=M.T,M.T=null;var r=N.p;N.p=2;var i=Ol;Ol|=4;try{ol(t,e);var a=kd,o=br(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&yr(s.ownerDocument.documentElement,s)){if(c!==null&&xr(s)){var l=c.start,u=c.end;if(u===void 0&&(u=l),`selectionStart`in s)s.selectionStart=l,s.selectionEnd=Math.min(u,s.value.length);else{var d=s.ownerDocument||document,f=d&&d.defaultView||window;if(f.getSelection){var p=f.getSelection(),m=s.textContent.length,h=Math.min(c.start,m),g=c.end===void 0?h:Math.min(c.end,m);!p.extend&&h>g&&(o=g,g=h,h=o);var _=vr(s,h),v=vr(s,g);if(_&&v&&(p.rangeCount!==1||p.anchorNode!==_.node||p.anchorOffset!==_.offset||p.focusNode!==v.node||p.focusOffset!==v.offset)){var y=d.createRange();y.setStart(_.node,_.offset),p.removeAllRanges(),h>g?(p.addRange(y),p.extend(v.node,v.offset)):(y.setEnd(v.node,v.offset),p.addRange(y))}}}}for(d=[],p=s;p=p.parentNode;)p.nodeType===1&&d.push({element:p,left:p.scrollLeft,top:p.scrollTop});for(typeof s.focus==`function`&&s.focus(),s=0;s<d.length;s++){var b=d[s];b.element.scrollLeft=b.left,b.element.scrollTop=b.top}}qf=!!Od,kd=Od=null}finally{Ol=i,N.p=r,M.T=n}}e.current=t,Yl=2}}function ku(){if(Yl===2){Yl=0;var e=Xl,t=Zl,n=!!(t.flags&8772);if(t.subtreeFlags&8772||n){n=M.T,M.T=null;var r=N.p;N.p=2;var i=Ol;Ol|=4;try{Yc(e,t.alternate,t)}finally{Ol=i,N.p=r,M.T=n}}Yl=3}}function Au(){if(Yl===4||Yl===3){Yl=0,ge();var e=Xl,t=Zl,n=Ql,r=tu;t.subtreeFlags&10256||t.flags&10256?Yl=5:(Yl=0,Zl=Xl=null,ju(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(Jl=null),Ge(n),t=t.stateNode,Te&&typeof Te.onCommitFiberRoot==`function`)try{Te.onCommitFiberRoot(V,t,void 0,(t.current.flags&128)==128)}catch{}if(r!==null){t=M.T,i=N.p,N.p=2,M.T=null;try{for(var a=e.onRecoverableError,o=0;o<r.length;o++){var s=r[o];a(s.value,{componentStack:s.stack})}}finally{M.T=t,N.p=i}}Ql&3&&Mu(),Ju(e),i=e.pendingLanes,n&4194090&&i&42?e===ru?nu++:(nu=0,ru=e):nu=0,Yu(0,!1)}}function ju(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,ea(t)))}function Mu(e){return Ou(),ku(),Au(),Nu(e)}function Nu(){if(Yl!==5)return!1;var e=Xl,t=$l;$l=0;var n=Ge(Ql),r=M.T,a=N.p;try{N.p=32>n?32:n,M.T=null,n=eu,eu=null;var o=Xl,s=Ql;if(Yl=0,Zl=Xl=null,Ql=0,Ol&6)throw Error(i(331));var c=Ol;if(Ol|=4,Cl(o.current),hl(o,o.current,s,n),Ol=c,Yu(0,!1),Te&&typeof Te.onPostCommitFiberRoot==`function`)try{Te.onPostCommitFiberRoot(V,o)}catch{}return!0}finally{N.p=a,M.T=r,ju(e,t)}}function Pu(e,t,n){t=Wr(n,t),t=Gs(e.stateNode,t,2),e=Ea(e,t,2),e!==null&&(Be(e,2),Ju(e))}function Fu(e,t,n){if(e.tag===3)Pu(e,e,n);else for(;t!==null;){if(t.tag===3){Pu(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(Jl===null||!Jl.has(r))){e=Wr(n,e),n=Ks(2),r=Ea(t,n,2),r!==null&&(qs(n,r,t,e),Be(r,2),Ju(r));break}}t=t.return}}function Iu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Dl;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Pl=!0,i.add(n),e=Lu.bind(null,e,t,n),t.then(e,e))}function Lu(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,kl===e&&(q&n)===n&&(Il===4||Il===3&&(q&62914560)===q&&300>_e()-Gl?!(Ol&2)&&pu(e,0):zl|=n,Vl===q&&(Vl=0)),Ju(e)}function Ru(e,t){t===0&&(t=Re()),e=Zr(e,t),e!==null&&(Be(e,t),Ju(e))}function zu(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Ru(e,n)}function Bu(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(i(314))}r!==null&&r.delete(t),Ru(e,n)}function Vu(e,t){return me(e,t)}var Hu=null,Uu=null,Wu=!1,Gu=!1,Ku=!1,qu=0;function Ju(e){e!==Uu&&e.next===null&&(Uu===null?Hu=Uu=e:Uu=Uu.next=e),Gu=!0,Wu||(Wu=!0,td())}function Yu(e,t){if(!Ku&&Gu){Ku=!0;do for(var n=!1,r=Hu;r!==null;){if(!t){if(e!==0){var i=r.pendingLanes;if(i===0)var a=0;else{var o=r.suspendedLanes,s=r.pingedLanes;a=(1<<31-De(42|e)+1)-1,a&=i&~(o&~s),a=a&201326741?a&201326741|1:a?a|2:0}a!==0&&(n=!0,ed(r,a))}else a=q,a=Pe(r,r===kl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Fe(r,a)||(n=!0,ed(r,a))}r=r.next}while(n);Ku=!1}}function Xu(){Zu()}function Zu(){Gu=Wu=!1;var e=0;qu!==0&&(Fd()&&(e=qu),qu=0);for(var t=_e(),n=null,r=Hu;r!==null;){var i=r.next,a=Qu(r,t);a===0?(r.next=null,n===null?Hu=i:n.next=i,i===null&&(Uu=n)):(n=r,(e!==0||a&3)&&(Gu=!0)),r=i}Yu(e,!1)}function Qu(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes&-62914561;0<a;){var o=31-De(a),s=1<<o,c=i[o];c===-1?((s&n)===0||(s&r)!==0)&&(i[o]=Ie(s,t)):c<=t&&(e.expiredLanes|=s),a&=~s}if(t=kl,n=q,n=Pe(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Al===2||Al===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&z(r),e.callbackNode=null,e.callbackPriority=0;if(!(n&3)||Fe(e,n)){if(t=n&-n,t===e.callbackPriority)return t;switch(r!==null&&z(r),Ge(n)){case 2:case 8:n=B;break;case 32:n=be;break;case 268435456:n=Se;break;default:n=be}return r=$u.bind(null,e),n=me(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&z(r),e.callbackPriority=2,e.callbackNode=null,2}function $u(e,t){if(Yl!==0&&Yl!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Mu(!0)&&e.callbackNode!==n)return null;var r=q;return r=Pe(e,e===kl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(su(e,r,t),Qu(e,_e()),e.callbackNode!=null&&e.callbackNode===n?$u.bind(null,e):null)}function ed(e,t){if(Mu())return null;su(e,t,!0)}function td(){zd(function(){Ol&6?me(ye,Xu):Zu()})}function nd(){return qu===0&&(qu=Le()),qu}function rd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Kt(``+e)}function id(e,t){var n=t.ownerDocument.createElement(`input`);return n.name=t.name,n.value=t.value,e.id&&n.setAttribute(`form`,e.id),t.parentNode.insertBefore(n,t),e=new FormData(e),n.parentNode.removeChild(n),e}function ad(e,t,n,r,i){if(t===`submit`&&n&&n.stateNode===i){var a=rd((i[Xe]||null).action),o=r.submitter;o&&(t=(t=o[Xe]||null)?rd(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new mn(`action`,`action`,null,r,i);e.push({event:s,listeners:[{instance:null,listener:function(){if(r.defaultPrevented){if(qu!==0){var e=o?id(i,o):new FormData(i);$o(n,{pending:!0,data:e,method:i.method,action:a},null,e)}}else typeof a==`function`&&(s.preventDefault(),e=o?id(i,o):new FormData(i),$o(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var od=0;od<Vr.length;od++){var sd=Vr[od];Hr(sd.toLowerCase(),`on`+(sd[0].toUpperCase()+sd.slice(1)))}Hr(Nr,`onAnimationEnd`),Hr(Pr,`onAnimationIteration`),Hr(Fr,`onAnimationStart`),Hr(`dblclick`,`onDoubleClick`),Hr(`focusin`,`onFocus`),Hr(`focusout`,`onBlur`),Hr(Ir,`onTransitionRun`),Hr(Lr,`onTransitionStart`),Hr(Rr,`onTransitionCancel`),Hr(zr,`onTransitionEnd`),dt(`onMouseEnter`,[`mouseout`,`mouseover`]),dt(`onMouseLeave`,[`mouseout`,`mouseover`]),dt(`onPointerEnter`,[`pointerout`,`pointerover`]),dt(`onPointerLeave`,[`pointerout`,`pointerover`]),ut(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),ut(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),ut(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),ut(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),ut(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),ut(`onCompositionUpdate`,`compositionupdate focusout keydown keypress keyup mousedown`.split(` `));var cd=`abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting`.split(` `),ld=new Set(`beforetoggle cancel close invalid load scroll scrollend toggle`.split(` `).concat(cd));function ud(e,t){t=!!(t&4);for(var n=0;n<e.length;n++){var r=e[n],i=r.event;r=r.listeners;a:{var a=void 0;if(t)for(var o=r.length-1;0<=o;o--){var s=r[o],c=s.instance,l=s.currentTarget;if(s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){zs(e)}i.currentTarget=null,a=c}else for(o=0;o<r.length;o++){if(s=r[o],c=s.instance,l=s.currentTarget,s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){zs(e)}i.currentTarget=null,a=c}}}}function J(e,t){var n=t[Qe];n===void 0&&(n=t[Qe]=new Set);var r=e+`__bubble`;n.has(r)||(md(t,e,2,!1),n.add(r))}function dd(e,t,n){var r=0;t&&(r|=4),md(n,e,r,t)}var fd=`_reactListening`+Math.random().toString(36).slice(2);function pd(e){if(!e[fd]){e[fd]=!0,ct.forEach(function(t){t!==`selectionchange`&&(ld.has(t)||dd(t,!1,e),dd(t,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[fd]||(t[fd]=!0,dd(`selectionchange`,!1,t))}}function md(e,t,n,r){switch(ep(t)){case 2:var i=Jf;break;case 8:i=Yf;break;default:i=Xf}n=i.bind(null,t,n,e),i=void 0,!nn||t!==`touchstart`&&t!==`touchmove`&&t!==`wheel`||(i=!0),r?i===void 0?e.addEventListener(t,n,!0):e.addEventListener(t,n,{capture:!0,passive:i}):i===void 0?e.addEventListener(t,n,!1):e.addEventListener(t,n,{passive:i})}function hd(e,t,n,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)a:for(;;){if(r===null)return;var s=r.tag;if(s===3||s===4){var c=r.stateNode.containerInfo;if(c===i)break;if(s===4)for(s=r.return;s!==null;){var l=s.tag;if((l===3||l===4)&&s.stateNode.containerInfo===i)return;s=s.return}for(;c!==null;){if(s=it(c),s===null)return;if(l=s.tag,l===5||l===6||l===26||l===27){r=a=s;continue a}c=c.parentNode}}r=r.return}$t(function(){var r=a,i=Jt(n),s=[];a:{var c=Br.get(e);if(c!==void 0){var l=mn,u=e;switch(e){case`keypress`:if(ln(n)===0)break a;case`keydown`:case`keyup`:l=Mn;break;case`focusin`:u=`focus`,l=Cn;break;case`focusout`:u=`blur`,l=Cn;break;case`beforeblur`:case`afterblur`:l=Cn;break;case`click`:if(n.button===2)break a;case`auxclick`:case`dblclick`:case`mousedown`:case`mousemove`:case`mouseup`:case`mouseout`:case`mouseover`:case`contextmenu`:l=xn;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:l=Sn;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:l=Pn;break;case Nr:case Pr:case Fr:l=wn;break;case zr:l=Fn;break;case`scroll`:case`scrollend`:l=gn;break;case`wheel`:l=In;break;case`copy`:case`cut`:case`paste`:l=Tn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:l=Nn;break;case`toggle`:case`beforetoggle`:l=Ln}var d=!!(t&4),f=!d&&(e===`scroll`||e===`scrollend`),p=d?c===null?null:c+`Capture`:c;d=[];for(var m=r,h;m!==null;){var g=m;if(h=g.stateNode,g=g.tag,g!==5&&g!==26&&g!==27||h===null||p===null||(g=en(m,p),g!=null&&d.push(gd(m,g,h))),f)break;m=m.return}0<d.length&&(c=new l(c,u,null,n,i),s.push({event:c,listeners:d}))}}if(!(t&7)){a:{if(c=e===`mouseover`||e===`pointerover`,l=e===`mouseout`||e===`pointerout`,c&&n!==qt&&(u=n.relatedTarget||n.fromElement)&&(it(u)||u[Ze]))break a;if((l||c)&&(c=i.window===i?i:(c=i.ownerDocument)?c.defaultView||c.parentWindow:window,l?(u=n.relatedTarget||n.toElement,l=r,u=u?it(u):null,u!==null&&(f=o(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(l=null,u=r),l!==u)){if(d=xn,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=Nn,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=l==null?c:ot(l),h=u==null?c:ot(u),c=new d(g,m+`leave`,l,n,i),c.target=f,c.relatedTarget=h,g=null,it(i)===r&&(d=new d(p,m+`enter`,u,n,i),d.target=h,d.relatedTarget=f,g=d),f=g,l&&u)b:{for(d=l,p=u,m=0,h=d;h;h=vd(h))m++;for(h=0,g=p;g;g=vd(g))h++;for(;0<m-h;)d=vd(d),m--;for(;0<h-m;)p=vd(p),h--;for(;m--;){if(d===p||p!==null&&d===p.alternate)break b;d=vd(d),p=vd(p)}d=null}else d=null;l!==null&&yd(s,c,l,d,!1),u!==null&&f!==null&&yd(s,f,u,d,!0)}}a:{if(c=r?ot(r):window,l=c.nodeName&&c.nodeName.toLowerCase(),l===`select`||l===`input`&&c.type===`file`)var _=rr;else if(Zn(c)){if(ir)_=pr;else{_=dr;var v=ur}}else l=c.nodeName,!l||l.toLowerCase()!==`input`||c.type!==`checkbox`&&c.type!==`radio`?r&&Ut(r.elementType)&&(_=rr):_=fr;if(_&&=_(e,r)){Qn(s,_,n,i);break a}v&&v(e,c,r),e===`focusout`&&r&&c.type===`number`&&r.memoizedProps.value!=null&&Ft(c,`number`,c.value)}switch(v=r?ot(r):window,e){case`focusin`:(Zn(v)||v.contentEditable===`true`)&&(Cr=v,wr=r,Tr=null);break;case`focusout`:Tr=wr=Cr=null;break;case`mousedown`:Er=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Er=!1,Dr(s,n,i);break;case`selectionchange`:if(Sr)break;case`keydown`:case`keyup`:Dr(s,n,i)}var y;if(zn)b:{switch(e){case`compositionstart`:var b=`onCompositionStart`;break b;case`compositionend`:b=`onCompositionEnd`;break b;case`compositionupdate`:b=`onCompositionUpdate`;break b}b=void 0}else qn?Gn(e,n)&&(b=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(b=`onCompositionStart`);b&&(Hn&&n.locale!==`ko`&&(qn||b!==`onCompositionStart`?b===`onCompositionEnd`&&qn&&(y=cn()):(an=i,on=`value`in an?an.value:an.textContent,qn=!0)),v=_d(r,b),0<v.length&&(b=new En(b,e,null,n,i),s.push({event:b,listeners:v}),y?b.data=y:(y=Kn(n),y!==null&&(b.data=y)))),(y=Vn?Jn(e,n):Yn(e,n))&&(b=_d(r,`onBeforeInput`),0<b.length&&(v=new En(`onBeforeInput`,`beforeinput`,null,n,i),s.push({event:v,listeners:b}),v.data=y)),ad(s,e,r,n,i)}ud(s,t)})}function gd(e,t,n){return{instance:e,listener:t,currentTarget:n}}function _d(e,t){for(var n=t+`Capture`,r=[];e!==null;){var i=e,a=i.stateNode;if(i=i.tag,i!==5&&i!==26&&i!==27||a===null||(i=en(e,n),i!=null&&r.unshift(gd(e,i,a)),i=en(e,t),i!=null&&r.push(gd(e,i,a))),e.tag===3)return r;e=e.return}return[]}function vd(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function yd(e,t,n,r,i){for(var a=t._reactName,o=[];n!==null&&n!==r;){var s=n,c=s.alternate,l=s.stateNode;if(s=s.tag,c!==null&&c===r)break;s!==5&&s!==26&&s!==27||l===null||(c=l,i?(l=en(n,a),l!=null&&o.unshift(gd(n,l,c))):i||(l=en(n,a),l!=null&&o.push(gd(n,l,c)))),n=n.return}o.length!==0&&e.push({event:t,listeners:o})}var bd=/\r\n?/g,xd=/\u0000|\uFFFD/g;function Sd(e){return(typeof e==`string`?e:``+e).replace(bd,`
10
+ `).replace(xd,``)}function Cd(e,t){return t=Sd(t),Sd(e)===t}function wd(){}function Td(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||zt(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&zt(e,``+r);break;case`className`:_t(e,`class`,r);break;case`tabIndex`:_t(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:_t(e,n,r);break;case`style`:Ht(e,r,o);break;case`data`:if(t!==`object`){_t(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)||r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Kt(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}if(typeof o==`function`&&(n===`formAction`?(t!==`input`&&Td(e,t,`name`,a.name,a,null),Td(e,t,`formEncType`,a.formEncType,a,null),Td(e,t,`formMethod`,a.formMethod,a,null),Td(e,t,`formTarget`,a.formTarget,a,null)):(Td(e,t,`encType`,a.encType,a,null),Td(e,t,`method`,a.method,a,null),Td(e,t,`target`,a.target,a,null))),r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Kt(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=wd);break;case`onScroll`:r!=null&&J(`scroll`,e);break;case`onScrollEnd`:r!=null&&J(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=Kt(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:J(`beforetoggle`,e),J(`toggle`,e),gt(e,`popover`,r);break;case`xlinkActuate`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:gt(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=Wt.get(n)||n,gt(e,n,r))}}function Ed(e,t,n,r,a,o){switch(n){case`style`:Ht(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?zt(e,r):(typeof r==`number`||typeof r==`bigint`)&&zt(e,``+r);break;case`onScroll`:r!=null&&J(`scroll`,e);break;case`onScrollEnd`:r!=null&&J(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=wd);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!lt.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(a=n.endsWith(`Capture`),t=n.slice(2,a?n.length-7:void 0),o=e[Xe]||null,o=o==null?null:o[n],typeof o==`function`&&e.removeEventListener(t,o,a),typeof r==`function`)){typeof o!=`function`&&o!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,a);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):gt(e,n,r)}}}function Y(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:J(`error`,e),J(`load`,e);var r=!1,a=!1,o;for(o in n)if(n.hasOwnProperty(o)){var s=n[o];if(s!=null)switch(o){case`src`:r=!0;break;case`srcSet`:a=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Td(e,t,o,s,n,null)}}a&&Td(e,t,`srcSet`,n.srcSet,n,null),r&&Td(e,t,`src`,n.src,n,null);return;case`input`:J(`invalid`,e);var c=o=s=a=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:a=d;break;case`type`:s=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:o=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(i(137,t));break;default:Td(e,t,r,d,n,null)}}Pt(e,o,c,l,u,s,a,!1),Ot(e);return;case`select`:for(a in J(`invalid`,e),r=s=o=null,n)if(n.hasOwnProperty(a)&&(c=n[a],c!=null))switch(a){case`value`:o=c;break;case`defaultValue`:s=c;break;case`multiple`:r=c;default:Td(e,t,a,c,n,null)}t=o,n=s,e.multiple=!!r,t==null?n!=null&&It(e,!!r,n,!0):It(e,!!r,t,!1);return;case`textarea`:for(s in J(`invalid`,e),o=a=r=null,n)if(n.hasOwnProperty(s)&&(c=n[s],c!=null))switch(s){case`value`:r=c;break;case`defaultValue`:a=c;break;case`children`:o=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(i(91));break;default:Td(e,t,s,c,n,null)}Rt(e,r,a,o),Ot(e);return;case`option`:for(l in n)if(n.hasOwnProperty(l)&&(r=n[l],r!=null))switch(l){case`selected`:e.selected=r&&typeof r!=`function`&&typeof r!=`symbol`;break;default:Td(e,t,l,r,n,null)}return;case`dialog`:J(`beforetoggle`,e),J(`toggle`,e),J(`cancel`,e),J(`close`,e);break;case`iframe`:case`object`:J(`load`,e);break;case`video`:case`audio`:for(r=0;r<cd.length;r++)J(cd[r],e);break;case`image`:J(`error`,e),J(`load`,e);break;case`details`:J(`toggle`,e);break;case`embed`:case`source`:case`link`:J(`error`,e),J(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Td(e,t,u,r,n,null)}return;default:if(Ut(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Ed(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Td(e,t,c,r,n,null))}function Dd(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var a=null,o=null,s=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Td(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:o=m;break;case`name`:a=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:s=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(i(137,t));break;default:m!==f&&Td(e,t,p,m,r,f)}}Nt(e,s,c,l,u,d,o,a);return;case`select`:for(o in m=s=c=p=null,n)if(l=n[o],n.hasOwnProperty(o)&&l!=null)switch(o){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(o)||Td(e,t,o,null,r,l)}for(a in r)if(o=r[a],l=n[a],r.hasOwnProperty(a)&&(o!=null||l!=null))switch(a){case`value`:p=o;break;case`defaultValue`:c=o;break;case`multiple`:s=o;default:o!==l&&Td(e,t,a,o,r,l)}t=c,n=s,r=m,p==null?!!r!=!!n&&(t==null?It(e,!!n,n?[]:``,!1):It(e,!!n,t,!0)):It(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(a=n[c],n.hasOwnProperty(c)&&a!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Td(e,t,c,null,r,a)}for(s in r)if(a=r[s],o=n[s],r.hasOwnProperty(s)&&(a!=null||o!=null))switch(s){case`value`:p=a;break;case`defaultValue`:m=a;break;case`children`:break;case`dangerouslySetInnerHTML`:if(a!=null)throw Error(i(91));break;default:a!==o&&Td(e,t,s,a,r,o)}Lt(e,p,m);return;case`option`:for(var h in n)if(p=n[h],n.hasOwnProperty(h)&&p!=null&&!r.hasOwnProperty(h))switch(h){case`selected`:e.selected=!1;break;default:Td(e,t,h,null,r,p)}for(l in r)if(p=r[l],m=n[l],r.hasOwnProperty(l)&&p!==m&&(p!=null||m!=null))switch(l){case`selected`:e.selected=p&&typeof p!=`function`&&typeof p!=`symbol`;break;default:Td(e,t,l,p,r,m)}return;case`img`:case`link`:case`area`:case`base`:case`br`:case`col`:case`embed`:case`hr`:case`keygen`:case`meta`:case`param`:case`source`:case`track`:case`wbr`:case`menuitem`:for(var g in n)p=n[g],n.hasOwnProperty(g)&&p!=null&&!r.hasOwnProperty(g)&&Td(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(i(137,t));break;default:Td(e,t,u,p,r,m)}return;default:if(Ut(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Ed(e,t,_,void 0,r,p);for(d in r)p=r[d],m=n[d],!r.hasOwnProperty(d)||p===m||p===void 0&&m===void 0||Ed(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Td(e,t,v,null,r,p);for(f in r)p=r[f],m=n[f],!r.hasOwnProperty(f)||p===m||p==null&&m==null||Td(e,t,f,p,r,m)}var Od=null,kd=null;function Ad(e){return e.nodeType===9?e:e.ownerDocument}function jd(e){switch(e){case`http://www.w3.org/2000/svg`:return 1;case`http://www.w3.org/1998/Math/MathML`:return 2;default:return 0}}function Md(e,t){if(e===0)switch(t){case`svg`:return 1;case`math`:return 2;default:return 0}return e===1&&t===`foreignObject`?0:e}function Nd(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.children==`bigint`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Pd=null;function Fd(){var e=window.event;return e&&e.type===`popstate`?e!==Pd&&(Pd=e,!0):(Pd=null,!1)}var Id=typeof setTimeout==`function`?setTimeout:void 0,Ld=typeof clearTimeout==`function`?clearTimeout:void 0,Rd=typeof Promise==`function`?Promise:void 0,zd=typeof queueMicrotask==`function`?queueMicrotask:Rd===void 0?Id:function(e){return Rd.resolve(null).then(e).catch(Bd)};function Bd(e){setTimeout(function(){throw e})}function Vd(e){return e===`head`}function Hd(e,t){var n=t,r=0,i=0;do{var a=n.nextSibling;if(e.removeChild(n),a&&a.nodeType===8){if(n=a.data,n===`/$`){if(0<r&&8>r){n=r;var o=e.ownerDocument;if(n&1&&Qd(o.documentElement),n&2&&Qd(o.body),n&4)for(n=o.head,Qd(n),o=n.firstChild;o;){var s=o.nextSibling,c=o.nodeName;o[nt]||c===`SCRIPT`||c===`STYLE`||c===`LINK`&&o.rel.toLowerCase()===`stylesheet`||n.removeChild(o),o=s}}if(i===0){e.removeChild(a),yp(t);return}i--}else n===`$`||n===`$?`||n===`$!`?i++:r=n.charCodeAt(0)-48}else r=0;n=a}while(n);yp(t)}function Ud(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var n=t;switch(t=t.nextSibling,n.nodeName){case`HTML`:case`HEAD`:case`BODY`:Ud(n),rt(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function Wd(e,t,n,r){for(;e.nodeType===1;){var i=n;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!r&&(e.nodeName!==`INPUT`||e.type!==`hidden`))break}else if(!r){if(t===`input`&&e.type===`hidden`){var a=i.name==null?null:``+i.name;if(i.type===`hidden`&&e.getAttribute(`name`)===a)return e}else return e}else if(!e[nt])switch(t){case`meta`:if(!e.hasAttribute(`itemprop`))break;return e;case`link`:if(a=e.getAttribute(`rel`),a===`stylesheet`&&e.hasAttribute(`data-precedence`)||a!==i.rel||e.getAttribute(`href`)!==(i.href==null||i.href===``?null:i.href)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute(`title`)!==(i.title==null?null:i.title))break;return e;case`style`:if(e.hasAttribute(`data-precedence`))break;return e;case`script`:if(a=e.getAttribute(`src`),(a!==(i.src==null?null:i.src)||e.getAttribute(`type`)!==(i.type==null?null:i.type)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin))&&a&&e.hasAttribute(`async`)&&!e.hasAttribute(`itemprop`))break;return e;default:return e}if(e=Jd(e.nextSibling),e===null)break}return null}function Gd(e,t,n){if(t===``)return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=Jd(e.nextSibling),e===null))return null;return e}function Kd(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState===`complete`}function qd(e,t){var n=e.ownerDocument;if(e.data!==`$?`||n.readyState===`complete`)t();else{var r=function(){t(),n.removeEventListener(`DOMContentLoaded`,r)};n.addEventListener(`DOMContentLoaded`,r),e._reactRetry=r}}function Jd(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`||t===`F!`||t===`F`)break;if(t===`/$`)return null}}return e}var Yd=null;function Xd(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`){if(t===0)return e;t--}else n===`/$`&&t++}e=e.previousSibling}return null}function Zd(e,t,n){switch(t=Ad(n),e){case`html`:if(e=t.documentElement,!e)throw Error(i(452));return e;case`head`:if(e=t.head,!e)throw Error(i(453));return e;case`body`:if(e=t.body,!e)throw Error(i(454));return e;default:throw Error(i(451))}}function Qd(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);rt(e)}var $d=new Map,ef=new Set;function tf(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var nf=N.d;N.d={f:rf,r:af,D:cf,C:lf,L:uf,m:df,X:pf,S:ff,M:mf};function rf(){var e=nf.f(),t=du();return e||t}function af(e){var t=at(e);t!==null&&t.tag===5&&t.type===`form`?ts(t):nf.r(e)}var of=typeof document>`u`?null:document;function sf(e,t,n){var r=of;if(r&&typeof t==`string`&&t){var i=Mt(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),ef.has(i)||(ef.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Y(t,`link`,e),H(t),r.head.appendChild(t)))}}function cf(e){nf.D(e),sf(`dns-prefetch`,e,null)}function lf(e,t){nf.C(e,t),sf(`preconnect`,e,t)}function uf(e,t,n){nf.L(e,t,n);var r=of;if(r&&e&&t){var i=`link[rel="preload"][as="`+Mt(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Mt(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Mt(n.imageSizes)+`"]`)):i+=`[href="`+Mt(e)+`"]`;var a=i;switch(t){case`style`:a=gf(e);break;case`script`:a=bf(e)}$d.has(a)||(e=p({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),$d.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(_f(a))||t===`script`&&r.querySelector(xf(a))||(t=r.createElement(`link`),Y(t,`link`,e),H(t),r.head.appendChild(t)))}}function df(e,t){nf.m(e,t);var n=of;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Mt(r)+`"][href="`+Mt(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=bf(e)}if(!$d.has(a)&&(e=p({rel:`modulepreload`,href:e},t),$d.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(xf(a)))return}r=n.createElement(`link`),Y(r,`link`,e),H(r),n.head.appendChild(r)}}}function ff(e,t,n){nf.S(e,t,n);var r=of;if(r&&e){var i=st(r).hoistableStyles,a=gf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(_f(a)))s.loading=5;else{e=p({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=$d.get(a))&&wf(e,n);var c=o=r.createElement(`link`);H(c),Y(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,Cf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function pf(e,t){nf.X(e,t);var n=of;if(n&&e){var r=st(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=p({src:e,async:!0},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),H(a),Y(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function mf(e,t){nf.M(e,t);var n=of;if(n&&e){var r=st(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=p({src:e,async:!0,type:`module`},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),H(a),Y(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function hf(e,t,n,r){var a=(a=se.current)?tf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=gf(n.href),n=st(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=gf(n.href);var o=st(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(_f(e)))&&!o._p&&(s.instance=o,s.state.loading=5),$d.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},$d.set(e,n),o||yf(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=bf(n),n=st(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function gf(e){return`href="`+Mt(e)+`"`}function _f(e){return`link[rel="stylesheet"][`+e+`]`}function vf(e){return p({},e,{"data-precedence":e.precedence,precedence:null})}function yf(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),Y(t,`link`,n),H(t),e.head.appendChild(t))}function bf(e){return`[src="`+Mt(e)+`"]`}function xf(e){return`script[async]`+e}function Sf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Mt(n.href)+`"]`);if(r)return t.instance=r,H(r),r;var a=p({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),H(r),Y(r,`style`,a),Cf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=gf(n.href);var o=e.querySelector(_f(a));if(o)return t.state.loading|=4,t.instance=o,H(o),o;r=vf(n),(a=$d.get(a))&&wf(r,a),o=(e.ownerDocument||e).createElement(`link`),H(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Y(o,`link`,r),t.state.loading|=4,Cf(o,n.precedence,e),t.instance=o;case`script`:return o=bf(n.src),(a=e.querySelector(xf(o)))?(t.instance=a,H(a),a):(r=n,(a=$d.get(o))&&(r=p({},n),Tf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),H(a),Y(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,Cf(r,n.precedence,e));return t.instance}function Cf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o<r.length;o++){var s=r[o];if(s.dataset.precedence===t)a=s;else if(a!==i)break}a?a.parentNode.insertBefore(e,a.nextSibling):(t=n.nodeType===9?n.head:n,t.insertBefore(e,t.firstChild))}function wf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function Tf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var Ef=null;function Df(e,t,n){if(Ef===null){var r=new Map,i=Ef=new Map;i.set(n,r)}else i=Ef,r=i.get(n),r||(r=new Map,i.set(n,r));if(r.has(e))return r;for(r.set(e,null),n=n.getElementsByTagName(e),i=0;i<n.length;i++){var a=n[i];if(!(a[nt]||a[Ye]||e===`link`&&a.getAttribute(`rel`)===`stylesheet`)&&a.namespaceURI!==`http://www.w3.org/2000/svg`){var o=a.getAttribute(t)||``;o=e+o;var s=r.get(o);s?s.push(a):r.set(o,[a])}}return r}function Of(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function kf(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function Af(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}var jf=null;function Mf(){}function Nf(e,t,n){if(jf===null)throw Error(i(475));var r=jf;if(t.type===`stylesheet`&&(typeof n.media!=`string`||!1!==matchMedia(n.media).matches)&&!(t.state.loading&4)){if(t.instance===null){var a=gf(n.href),o=e.querySelector(_f(a));if(o){e=o._p,typeof e==`object`&&e&&typeof e.then==`function`&&(r.count++,r=Ff.bind(r),e.then(r,r)),t.state.loading|=4,t.instance=o,H(o);return}o=e.ownerDocument||e,n=vf(n),(a=$d.get(a))&&wf(n,a),o=o.createElement(`link`),H(o);var s=o;s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Y(o,`link`,n),t.instance=o}r.stylesheets===null&&(r.stylesheets=new Map),r.stylesheets.set(t,e),(e=t.state.preload)&&!(t.state.loading&3)&&(r.count++,t=Ff.bind(r),e.addEventListener(`load`,t),e.addEventListener(`error`,t))}}function Pf(){if(jf===null)throw Error(i(475));var e=jf;return e.stylesheets&&e.count===0&&Lf(e,e.stylesheets),0<e.count?function(t){var n=setTimeout(function(){if(e.stylesheets&&Lf(e,e.stylesheets),e.unsuspend){var t=e.unsuspend;e.unsuspend=null,t()}},6e4);return e.unsuspend=t,function(){e.unsuspend=null,clearTimeout(n)}}:null}function Ff(){if(this.count--,this.count===0){if(this.stylesheets)Lf(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var If=null;function Lf(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,If=new Map,t.forEach(Rf,e),If=null,Ff.call(e))}function Rf(e,t){if(!(t.state.loading&4)){var n=If.get(e);if(n)var r=n.get(null);else{n=new Map,If.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a<i.length;a++){var o=i[a];(o.nodeName===`LINK`||o.getAttribute(`media`)!==`not all`)&&(n.set(o.dataset.precedence,o),r=o)}r&&n.set(null,r)}i=t.instance,o=i.getAttribute(`data-precedence`),a=n.get(o)||r,a===r&&n.set(null,i),n.set(o,i),this.count++,r=Ff.bind(this),i.addEventListener(`load`,r),i.addEventListener(`error`,r),a?a.parentNode.insertBefore(i,a.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var zf={$$typeof:C,Provider:null,Consumer:null,_currentValue:P,_currentValue2:P,_threadCount:0};function Bf(e,t,n,r,i,a,o,s){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=ze(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ze(0),this.hiddenUpdates=ze(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=s,this.incompleteTransitions=new Map}function Vf(e,t,n,r,i,a,o,s,c,l,u,d){return e=new Bf(e,t,n,o,s,c,l,d),t=1,!0===a&&(t|=24),a=ni(3,null,null,t),e.current=a,a.stateNode=e,t=$i(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},Ca(a),e}function Hf(e){return e?(e=ei,e):ei}function Uf(e,t,n,r,i,a){i=Hf(i),r.context===null?r.context=i:r.pendingContext=i,r=Ta(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Ea(e,r,t),n!==null&&(ou(n,e,t),Da(n,e,t))}function Wf(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function Gf(e,t){Wf(e,t),(e=e.alternate)&&Wf(e,t)}function Kf(e){if(e.tag===13){var t=Zr(e,67108864);t!==null&&ou(t,e,67108864),Gf(e,67108864)}}var qf=!0;function Jf(e,t,n,r){var i=M.T;M.T=null;var a=N.p;try{N.p=2,Xf(e,t,n,r)}finally{N.p=a,M.T=i}}function Yf(e,t,n,r){var i=M.T;M.T=null;var a=N.p;try{N.p=8,Xf(e,t,n,r)}finally{N.p=a,M.T=i}}function Xf(e,t,n,r){if(qf){var i=Zf(r);if(i===null)hd(e,t,r,Qf,n),lp(e,r);else if(dp(i,e,t,n,r))r.stopPropagation();else if(lp(e,r),t&4&&-1<cp.indexOf(e)){for(;i!==null;){var a=at(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Ne(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-De(o);s.entanglements[1]|=c,o&=~c}Ju(a),!(Ol&6)&&(Kl=_e()+500,Yu(0,!1))}}break;case 13:s=Zr(a,2),s!==null&&ou(s,a,2),du(),Gf(a,2)}if(a=Zf(r),a===null&&hd(e,t,r,Qf,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else hd(e,t,r,null,n)}}function Zf(e){return e=Jt(e),$f(e)}var Qf=null;function $f(e){if(Qf=null,e=it(e),e!==null){var t=o(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=s(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return Qf=e,null}function ep(e){switch(e){case`beforetoggle`:case`cancel`:case`click`:case`close`:case`contextmenu`:case`copy`:case`cut`:case`auxclick`:case`dblclick`:case`dragend`:case`dragstart`:case`drop`:case`focusin`:case`focusout`:case`input`:case`invalid`:case`keydown`:case`keypress`:case`keyup`:case`mousedown`:case`mouseup`:case`paste`:case`pause`:case`play`:case`pointercancel`:case`pointerdown`:case`pointerup`:case`ratechange`:case`reset`:case`resize`:case`seeked`:case`submit`:case`toggle`:case`touchcancel`:case`touchend`:case`touchstart`:case`volumechange`:case`change`:case`selectionchange`:case`textInput`:case`compositionstart`:case`compositionend`:case`compositionupdate`:case`beforeblur`:case`afterblur`:case`beforeinput`:case`blur`:case`fullscreenchange`:case`focus`:case`hashchange`:case`popstate`:case`select`:case`selectstart`:return 2;case`drag`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`mousemove`:case`mouseout`:case`mouseover`:case`pointermove`:case`pointerout`:case`pointerover`:case`scroll`:case`touchmove`:case`wheel`:case`mouseenter`:case`mouseleave`:case`pointerenter`:case`pointerleave`:return 8;case`message`:switch(ve()){case ye:return 2;case B:return 8;case be:case xe:return 32;case Se:return 268435456;default:return 32}default:return 32}}var tp=!1,np=null,rp=null,ip=null,ap=new Map,op=new Map,sp=[],cp=`mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset`.split(` `);function lp(e,t){switch(e){case`focusin`:case`focusout`:np=null;break;case`dragenter`:case`dragleave`:rp=null;break;case`mouseover`:case`mouseout`:ip=null;break;case`pointerover`:case`pointerout`:ap.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:op.delete(t.pointerId)}}function up(e,t,n,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=at(t),t!==null&&Kf(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function dp(e,t,n,r,i){switch(t){case`focusin`:return np=up(np,e,t,n,r,i),!0;case`dragenter`:return rp=up(rp,e,t,n,r,i),!0;case`mouseover`:return ip=up(ip,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return ap.set(a,up(ap.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,op.set(a,up(op.get(a)||null,e,t,n,r,i)),!0}return!1}function fp(e){var t=it(e.target);if(t!==null){var n=o(t);if(n!==null){if(t=n.tag,t===13){if(t=s(n),t!==null){e.blockedOn=t,qe(e.priority,function(){if(n.tag===13){var e=iu();e=We(e);var t=Zr(n,e);t!==null&&ou(t,n,e),Gf(n,e)}});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function pp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=Zf(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);qt=r,n.target.dispatchEvent(r),qt=null}else return t=at(n),t!==null&&Kf(t),e.blockedOn=n,!1;t.shift()}return!0}function mp(e,t,n){pp(e)&&n.delete(t)}function hp(){tp=!1,np!==null&&pp(np)&&(np=null),rp!==null&&pp(rp)&&(rp=null),ip!==null&&pp(ip)&&(ip=null),ap.forEach(mp),op.forEach(mp)}function gp(e,n){e.blockedOn===n&&(e.blockedOn=null,tp||(tp=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,hp)))}var _p=null;function vp(e){_p!==e&&(_p=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){_p===e&&(_p=null);for(var t=0;t<e.length;t+=3){var n=e[t],r=e[t+1],i=e[t+2];if(typeof r!=`function`){if($f(r||n)===null)continue;break}var a=at(n);a!==null&&(e.splice(t,3),t-=3,$o(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function yp(e){function t(t){return gp(t,e)}np!==null&&gp(np,e),rp!==null&&gp(rp,e),ip!==null&&gp(ip,e),ap.forEach(t),op.forEach(t);for(var n=0;n<sp.length;n++){var r=sp[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<sp.length&&(n=sp[0],n.blockedOn===null);)fp(n),n.blockedOn===null&&sp.shift();if(n=(e.ownerDocument||e).$$reactFormReplay,n!=null)for(r=0;r<n.length;r+=3){var i=n[r],a=n[r+1],o=i[Xe]||null;if(typeof a==`function`)o||vp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Xe]||null)s=o.formAction;else if($f(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),vp(n)}}}function bp(e){this._internalRoot=e}xp.prototype.render=bp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(i(409));var n=t.current;Uf(n,iu(),e,t,null,null)},xp.prototype.unmount=bp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Uf(e.current,2,null,e,null,null),du(),t[Ze]=null}};function xp(e){this._internalRoot=e}xp.prototype.unstable_scheduleHydration=function(e){if(e){var t=Ke();e={blockedOn:null,target:e,priority:t};for(var n=0;n<sp.length&&t!==0&&t<sp[n].priority;n++);sp.splice(n,0,e),n===0&&fp(e)}};var Sp=n.version;if(Sp!==`19.1.0`)throw Error(i(527,Sp,`19.1.0`));N.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(i(188)):(e=Object.keys(e).join(`,`),Error(i(268,e)));return e=l(t),e=e===null?null:d(e),e=e===null?null:e.stateNode,e};var Cp={bundleType:0,version:`19.1.0`,rendererPackageName:`react-dom`,currentDispatcherRef:M,reconcilerVersion:`19.1.0`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var wp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!wp.isDisabled&&wp.supportsFiber)try{V=wp.inject(Cp),Te=wp}catch{}}e.createRoot=function(e,t){if(!a(e))throw Error(i(299));var n=!1,r=``,o=Bs,s=Vs,c=Hs,l=null;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(o=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(c=t.onRecoverableError),t.unstable_transitionCallbacks!==void 0&&(l=t.unstable_transitionCallbacks)),t=Vf(e,1,!1,null,null,n,r,o,s,c,l,null),e[Ze]=t.current,pd(e),new bp(t)}})),g=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=h()})),_=u(),v=g(),y="This tab's key is out of date. Open the address printed by `copperflow studio` again.";function b(e,t){return e===403&&/session token/i.test(t??``)?y:t??`Request failed (${e})`}function x(e){return e===y}var S=`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`;function C(e){return e instanceof TypeError?S:e instanceof Error?e.message:String(e)}var w=[`alignLeft`,`alignRight`,`alignTop`,`alignBottom`,`alignHCentres`,`alignVCentres`,`distributeH`,`distributeV`],T=new Set([`distributeH`,`distributeV`]),E=e=>w.includes(e),ee=e=>T.has(e)?3:2;function D(e,t){return t>=ee(e)?null:ee(e)===2?`Select two or more parts`:`Select three or more parts`}var O=[`drawBus`,`drawPolyline`,`drawArc`,`drawCircle`,`drawRectangle`,`drawText`],k={bus:`drawBus`,polyline:`drawPolyline`,arc:`drawArc`,circle:`drawCircle`,rectangle:`drawRectangle`,text:`drawText`},A={drawBus:`bus`,drawPolyline:`polyline`,drawArc:`arc`,drawCircle:`circle`,drawRectangle:`rectangle`,drawText:`text`},j=e=>O.includes(e),te=`The AI lock is on. Open it to edit.`;function ne(e){return{closed:e===`ai`,editedSinceOpen:!1}}function re(e){return{closed:!e.closed,editedSinceOpen:!1}}function M(e,t){return e.closed?e:t===`human`?e.editedSinceOpen?e:{...e,editedSinceOpen:!0}:e.editedSinceOpen?e:{...e,closed:!0}}var N=[`undo`,`redo`,`delete`,`replicateLayout`,`makeSheet`,`placeComponent`,`wire`,`netLabel`,`groundFlag`,`powerFlag`,...O,`singleRouting`,`placeVia`,`placePour`,`placePourBoard`,`placeHole`,`autoplace`,`autoplaceSelection`,`autoplaceInstance`,`fitBoard`,`importBoardDxf`,`autoroute`,`autorouteSelection`,`autorouteNet`,`unroute`,`rotate`,`rotateRight`,`removeCorners`,`filletTracks`,`straightenTracks`,`designRules`,`tidySheet`,`addPage`,`renamePage`,`deletePage`,...w,`newCircuit`,`paste`,`noConnect`,`junction`,`annotate`,`placementTransfer`,`routingCorner`,`flip`,`footprintManager`];function P(e){return e?Object.fromEntries(N.map(e=>[e,te])):{}}var ie=new Set([`wire`,`route`,`placeVia`,`armNetLabel`,...O,`rotate`,`openLibrary`,`undo`,`redo`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`delete`,`removeCorner`,`flipBend`,`alignLeft`,`distributeH`,`filletTracks`,`straightenTracks`,`routingCorner`,`flip`,`paste`,`junction`,`placementTransfer`]);function F(e){return ie.has(e)}var I=new Set([`move`,`moveGroup`,`label`,`text`,`wireSegment`,`wireCorner`]);function L(e){return I.has(e)}var R=new Set([`/api/edit`,`/api/layout`,`/api/undo`,`/api/redo`,`/api/rename-parts`,`/api/make-sheet`,`/api/route`,`/api/autoplace`,`/api/fit-board`,`/api/import-board`,`/api/unroute`,`/api/rules`,`/api/place`,`/api/new-circuit`]);function ae(e,t){return t===void 0||typeof t==`object`&&t&&t.preview===!0?!1:R.has(e.split(`?`)[0]??e)}function oe(e){return e?{title:`AI is driving`,hint:`Unlock to edit`}:{title:`You are editing`,hint:`Lock for the agent`}}function se(e){return N.includes(e)}function ce(e){let t=!1,n=!1,r=e;return{set(e){e&&!t&&(n=!1),t=e},closed:()=>t,listen(e){r=e},refuses(){return t?(n||(n=!0,r(te)),!0):!1}}}var le=ce(()=>void 0),ue=`copperflow-token`,de=2e3;function fe(){let e=/[#&]token=([^&]+)/.exec(window.location.hash);if(e?.[1]){let t=decodeURIComponent(e[1]);try{sessionStorage.setItem(ue,t)}catch{}return window.history.replaceState(null,``,window.location.pathname+window.location.search),t}try{return sessionStorage.getItem(ue)??``}catch{return``}}var pe=fe(),me=pe!==``;window.addEventListener(`hashchange`,()=>{/[#&]token=/.test(window.location.hash)&&window.location.reload()});async function z(e,t){if(le.closed()&&ae(e,t))throw Error(te);let n;try{n=await fetch(e,{method:t===void 0?`GET`:`POST`,headers:{"x-copperflow-token":pe,"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}})}catch(e){throw Error(C(e))}let r=await n.json();if(!r.ok)throw Object.assign(Error(b(n.status,r.error)),{status:n.status,data:r.data});return r.data}async function he(e){let t;try{t=await fetch(e,{headers:{"x-copperflow-token":pe}})}catch(e){throw Error(C(e))}if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(b(t.status,e.error))}return t.blob()}var ge=[`change`,`build`,`library`,`route`,`place`];function _e(e,t){let n=new AbortController,r=t=>{let n=/^event: (.+)$/m.exec(t)?.[1],r=/^data: (.+)$/m.exec(t)?.[1];if(n!==void 0&&ge.includes(n)&&r){let t=JSON.parse(r);e(n,typeof t.file==`string`?t.file:``,t)}};return(async()=>{for(;!n.signal.aborted;){try{let e=await fetch(`/api/events`,{headers:{"x-copperflow-token":pe},signal:n.signal});if(!e.ok||!e.body)throw Error(`Event stream failed (${e.status})`);t?.(!0);let i=e.body.pipeThrough(new TextDecoderStream).getReader(),a=``;for(;;){let{value:e,done:t}=await i.read();if(t)break;a+=e;for(let e=a.indexOf(`
11
+
12
+ `);e>=0;e=a.indexOf(`
13
+
14
+ `))r(a.slice(0,e)),a=a.slice(e+2)}}catch(e){if(n.signal.aborted)return;e instanceof TypeError&&t?.(!1)}await new Promise(e=>setTimeout(e,de))}})(),()=>n.abort()}var ve=.5,ye=2e3;function B(e,t,n){return{x:(n.x-e.cx)*e.scale+t.width/2,y:-(n.y-e.cy)*e.scale+t.height/2}}function be(e,t,n){return{x:(n.x-t.width/2)/e.scale+e.cx,y:-(n.y-t.height/2)/e.scale+e.cy}}function xe(e,t,n=.12){let r=Math.max(e.maxX-e.minX,1),i=Math.max(e.maxY-e.minY,1),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:Me(a)}}function Se(e,t,n){return{...e,cx:e.cx-(n.x-t.x)/e.scale,cy:e.cy+(n.y-t.y)/e.scale}}function Ce(e,t){return{...e,cx:t.x,cy:t.y}}function we(e,t,n,r){let i=be(e,t,n),a=Me(e.scale*r);return{scale:a,cx:i.x-(n.x-t.width/2)/a,cy:i.y+(n.y-t.height/2)/a}}var V=e=>Math.round(e*1e4)/1e4;function Te(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var Ee=(e,t,n=!0)=>V(n?Te(e,t):e),De=(e,t,n=!0)=>({x:Ee(e.x,t,n),y:Ee(e.y,t,n)});function Oe(e,t){let n=e=>(e.maxX-e.minX)*(e.maxY-e.minY);return e.filter(({box:e})=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY).sort((e,t)=>n(e.box)-n(t.box))}function ke(e){if(e.length===0)return;let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Ae(e){return ke(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function je(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),e&&e.x===n.x&&e.y===n.y||t.push(n)}return t}function Me(e){return Math.min(ye,Math.max(ve,e))}var Ne={pcb:{position:[`pcbX`,`pcbY`],rotation:`pcbRotation`,where:``,notePrompt:`Note for the agent, e.g. route ground here`},schematic:{position:[`schX`,`schY`],rotation:`schRotation`,where:` in the schematic`,notePrompt:`Note for the agent, e.g. add a pull-up here`}},Pe={x:0,y:0};function Fe(e,t){let n=new Map(e.circuit.components.map(e=>[e.id,t===`pcb`?e.groupOffset.pcb:e.groupOffset.sch])),r=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(r.map(e=>[e.component,{origin:{x:e.x,y:e.y},group:n.get(e.component)??Pe,autoPlaced:e.autoPlaced}]))}function Ie(e,t,n,r){let i=e.model.parts.find(e=>e.name===n);if(!i)return`This part has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason})`;let a=Ne[r].position.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}function Le(e,t,n,r=90){let i=Ne[n].rotation,a=e.model.parts.find(e=>e.name===t)?.props[i]?.literal;return a!==void 0&&typeof a!=`number`?`${t}.${i} is not a number`:(((a??0)+r)%360+360)%360}function Re(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Ne[n].position,s=(e,t,n)=>{let r=i?.[e]?.literal;return typeof r==`number`?r:t-n};return{x:s(a,r.origin.x,r.group.x),y:s(o,r.origin.y,r.group.y)}}function ze(e,t,n,r,i){let a=Re(e,t,n,r);return[V(a.x+i.x),V(a.y+i.y)]}var Be=`Keep auto-placed positions`,Ve=`a repeated name cannot be addressed from the Studio`,He=e=>Math.round(e*100)/100;function Ue(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var We=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Ne[n].rotation]!==void 0;function Ge(e,t,n=()=>null,r){let[i,a]=Ne[t].position,o=Ue(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of Fe(e,t)){if(!f)continue;let e=l.includes(`~`)?Ve:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:He(u.x-d.x),[a]:He(u.y-d.y),...p!==0||We(r,l,t)?{[Ne[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Ke(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function qe(e){let t=e.edits.length;return Ke(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function Je(e,t,n,r){if(e.edits.length===0)return r.notify(n(e));r.edit(e.edits,t).then(t=>{t&&r.notify(n(e))})}function Ye(e,t,n,r,i){Je(Ge(e,t,n,i),Be,qe,r)}var Xe=`Tidy sheet`,Ze=`Every part on the sheet has a position of its own`,Qe=`The schematic is not built yet`;function $e(e,t){if(!e)return new Set;let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Set(n.flatMap(e=>e.autoPlaced?[e.component]:[]))}function et(e){return e?$e(e,`schematic`).size>0?null:Ze:Qe}var tt=(e,t=()=>null,n)=>Ge(e,`schematic`,t,n);function nt(e){let t=e.edits.length;return Ke(t===0?`Tidied the sheet: no part Studio placed could be written.`:`Tidied the sheet: wrote the positions of ${t} ${t===1?`part`:`parts`} Studio placed.`,e)}function rt(e,t,n,r){let i=et(e);if(i!==null)return n.notify(i);Je(tt(e,t,r),Xe,nt,n)}var it=/\.sheet\.tsx$/,at=e=>e!==void 0&&it.test(e),ot=e=>(e.split(`/`).pop()??e).replace(it,``),st=3;function H(e){return e.length<=1?e[0]??``:e.length>st?`${e.slice(0,st).join(`, `)} and ${e.length-st} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var ct=e=>e.length>1?[`${e.length} wires`]:[...e],lt=e=>`by ${e}°`;function ut(e,t,n,r,i=90){let{rotation:a,where:o}=Ne[n],s=[],c=[];for(let a of t){let t=r(a)??Le(e,a,n,i);typeof t==`string`?c.push(t):s.push({name:a,to:t})}let l=s.map(e=>e.name),[u]=s,d=s.length===1&&u?`rotate ${u.name}${o} to ${u.to}°`:`rotate ${H(l)}${o} ${lt(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function dt(e,t,n,r,i,a){let[o,s]=Ne[n].position,{where:c}=Ne[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:ze(e,t,n,r(t),i)})),[f]=d,p=d.length===1&&f?`move ${f.name}${c} to (${f.to[0]}, ${f.to[1]})`:`move ${H(u)}${c} by (${V(i.x)}, ${V(i.y)})`;return{edits:d.map(({name:e,to:t})=>({kind:`setProps`,part:e,props:{[o]:t[0],[s]:t[1]}})),summary:p,parts:u,skipped:l,done:`moved`}}function ft(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??Pe,group:Pe}}function pt(e,t,n,r=!0){let i=r?t:t/10;return{x:V(e.dx*i*n),y:V(e.dy*i*n)}}function mt(e,t){let n=Ae(e);return n?{x:Te((n.minX+n.maxX)/2,t),y:Te((n.minY+n.maxY)/2,t)}:void 0}function ht(e,t,n=90){let r=n>0?1:-1;return{x:t.x-r*(e.y-t.y),y:t.y+r*(e.x-t.x)}}function gt(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return ut(e,t,n,a,s);let{rotation:c,position:l,where:u}=Ne[n],d=[],f=[],p=[];for(let u of t){if(!o(u)){p.push(`${u} is not in this view`);continue}let t=a(u)??Le(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ht(h,i,s),[_,v]=ze(e,u,n,m,{x:g.x-h.x,y:g.y-h.y});d.push({kind:`setProps`,part:u,props:{[l[0]]:_,[l[1]]:v,[c]:t}}),f.push(u)}return{edits:d,summary:`rotate ${H(f)}${u} ${lt(s)}`,parts:f,skipped:p,done:`rotated`}}function _t(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function vt(e,t,n,r,i,a=90){if(t.length===1)return ut(e,t,n,i,a);let o=mt(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?gt(e,t,n,ft(r.anchors,r.boxes),o,i,_t(r),a):{message:`None of the selected parts is in this view.`}}function yt(e,t,n,r,i,a){let o=_t(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=dt(e,t.filter(o),n,ft(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function bt(e,t){let n=e.flatMap(e=>t(e)??[]),r=e.filter(e=>t(e)===null);return{edits:r.map(e=>({kind:`removePart`,part:e})),summary:`remove ${H(r)}`,parts:r,skipped:n,done:`removed`}}function xt(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${H(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function St(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function Ct(e,t,n,r=new Set){if(e.length===0)return{message:`Select a part first.`};let i=e.filter(e=>n?!t.has(e)||r.has(e):t.has(e));if(i.length>0)return{parts:i};let a=e.length===1?`is`:`are`;return{message:`${H(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function U(e,t){return(await wt(e,t)).ok}async function wt(e,t){let n=St(e);if(e.edits.length===0)return n&&t.notify(n),{ok:!1};let r=t.editMarked?await t.editMarked(e.edits,e.summary):{ok:await t.edit(e.edits,e.summary)};return r.ok&&n&&t.notify(n),r}var Tt={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},Et=.6,Dt=e=>Math.round(e*1e6)/1e6,Ot=(e,t)=>({x:Dt(e),y:Dt(t)}),kt=(...e)=>({type:`polyline`,points:e.map(([e,t])=>Ot(e,t))});function At(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:Tt[r],role:r}}function jt(e){let t=Et*e.size*e.text.length,n=e.anchor===`left`?e.at.x:e.anchor===`right`?e.at.x-t:e.at.x-t/2;return{minX:n,maxX:n+t,minY:e.at.y-e.size/2,maxY:e.at.y+e.size/2}}function Mt(e){if(e.type===`text`)return jt(e);if(e.type===`polyline`){let t=e.points.map(e=>e.x),n=e.points.map(e=>e.y);return{minX:Math.min(...t),maxX:Math.max(...t),minY:Math.min(...n),maxY:Math.max(...n)}}let{center:t,radius:n}=e;return{minX:t.x-n,maxX:t.x+n,minY:t.y-n,maxY:t.y+n}}function Nt(e,t){let n=[...e.map(Mt),...t.map(e=>({minX:e.end.x,maxX:e.end.x,minY:e.end.y,maxY:e.end.y}))];return n.length===0?{minX:0,minY:0,maxX:0,maxY:0}:{minX:Dt(Math.min(...n.map(e=>e.minX))),minY:Dt(Math.min(...n.map(e=>e.minY))),maxX:Dt(Math.max(...n.map(e=>e.maxX))),maxY:Dt(Math.max(...n.map(e=>e.maxY)))}}var Pt=(e,t,n)=>({end:Ot(e,t),side:n});Pt(-.5,0,`left`),Pt(.5,0,`right`),Pt(-.5,0,`left`),Pt(.5,0,`right`),Pt(-.5,0,`left`),Pt(.3,-.5,`bottom`),Pt(.3,.5,`top`);function Ft(){return[kt([0,0],[0,-.1]),kt([-.15,-.1],[.15,-.1]),kt([-.1,-.15],[.1,-.15]),kt([-.05,-.2],[.05,-.2])]}function It(e){return[kt([0,0],[0,.1]),kt([-.1,.1],[.1,.1]),At(e,Ot(0,.2),`center`,`value`)]}var Lt=.16,Rt=Lt*1.5,zt=.66,Bt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Vt(e){let t=Bt[e.side],n=e.text.length*Lt*zt+Rt,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[Rt,n]:[n,Rt];return{middle:i,upright:r,box:{minX:i.x-a/2,minY:i.y-o/2,maxX:i.x+a/2,maxY:i.y+o/2}}}var Ht=/[\w-]+/,Ut=new RegExp(String.raw`^net\.(${Ht.source})$`),Wt=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Gt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Kt(e){let t=e.trim(),n=Ut.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=Gt.exec(t)??Wt.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var qt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Jt(e){let t=qt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Yt(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Xt={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Zt=.04,Qt=[`solid`,`dashed`,`dotted`],$t=[`left`,`center`,`right`];function en(e){return Object.hasOwn(Xt,e)?Xt[e]:void 0}var tn=new RegExp(String.raw`^${Ht.source}$`),nn=new RegExp(String.raw`^(${Ht.source})\[(\d+):(\d+)\]$`);function rn(e){if(tn.test(e))return[e];let t=nn.exec(e);if(!t)return;let[n,r,i]=[t[1],Number(t[2]),Number(t[3])],a=Math.abs(i-r)+1;if(a>1024)return;let o=i>=r?1:-1;return Array.from({length:a},(e,t)=>`${n}${r+t*o}`)}function an(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function on(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function sn(e,t,n,r,i){let a=on(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return an(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function cn(e,t,n,r,i){let a=Et*r*n.length,o=i===`left`?e:i===`right`?e-a:e-a/2;return{minX:o,minY:t-r/2,maxX:o+a,maxY:t+r/2}}function ln(e){switch(e.kind){case`path`:case`bus`:return an(e.points);case`rect`:return{minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height};case`circle`:return{minX:e.x-e.radius,minY:e.y-e.radius,maxX:e.x+e.radius,maxY:e.y+e.radius};case`arc`:return sn(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return cn(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Zt,minY:e.y-Zt,maxX:e.x+Zt,maxY:e.y+Zt}}}var un=e=>Dt(e)+0;function dn(e){let t=ln(e);return{minX:un(t.minX),minY:un(t.minY),maxX:un(t.maxX),maxY:un(t.maxY)}}var fn=/^[A-Za-z_][\w-]*$/;function pn(e,t,n,r){let i=Jt(n);if(i)return Yt(i,void 0);let a=n.replace(/^net\./,``);return r?rn(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:fn.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function mn(e,t){let n=new Set(e);for(let r of t??[]){let t=r.path.split(`/`)[0]??r.path;if(e.has(r.path)||e.has(t))for(let e of r.parts)n.add(e)}return n}var hn=e=>e?.circuit.instances??[];function gn(e,t){return hn(e).find(e=>e.path===t&&!e.path.includes(`/`))}function _n(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=hn(e).find(e=>e.path===n.instance);if(!r)return;let i=n.instance.split(`/`)[0]??n.instance;return{part:t,localId:n.localId??t,instance:r.path,outer:i,sheet:r.sheet,file:r.file}}function vn(e,t){return[...hn(e).find(e=>e.path===t)?.parts??[]]}function yn(e,t){return hn(e).filter(e=>e.file===t).length}function bn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function xn(e,t){let n=t.flatMap(t=>{let n=gn(e,t);if(n)return[n.path];let r=_n(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>vn(e,t))}function Sn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function Cn(e,t){return mn(e,t?.circuit.instances)}function wn(e,t,n){let r=_n(e,n);if(r)return t.has(r.outer)?`${n} is in ${r.outer}, which is locked`:`${n} is ${r.localId} of ${r.instance}; it is placed in ${r.file}, where every instance of ${ot(r.file)} shares it`}var Tn=e=>Math.round(e*1e4)/1e4||0,En=(e,t)=>e.x===t.x&&e.y===t.y;function Dn(e,t,n){return e.x===t.x||e.y===t.y?[t]:[n?{x:e.x,y:t.y}:{x:t.x,y:e.y},t]}function On(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...Dn(e[n-1],e[n],t[n-1]===!0));return r}function kn(e){let t=e.map(e=>({x:Tn(e.x),y:Tn(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&En(t,e)||n.push(e)}return n.filter((e,t)=>{let[r,i]=[n[t-1],n[t+1]];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function An(e,t=[]){return kn(On(e,t))}var jn=.2,Mn=/^[\w-]+$/,Nn=/^[A-Za-z_][\w-]*$/,Pn=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Fn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function In(e,t){let n=e.pinLabels;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n)){if(!RegExp(`^(?:pin)?${t}$`).test(e))continue;let n=(Array.isArray(r)?r:[r]).find(e=>typeof e==`string`&&e!==``);if(n!==void 0)return n}}function Ln(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=In(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&Mn.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function Rn(e,t){let n=t.trim(),r=Pn.exec(n)??Fn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var zn=e=>e.circuit.components.flatMap(e=>e.pins),Bn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Vn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function Hn(e,t,n){let r=Bn(e,t.id)?.names[0],i=Ln(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Un(e,t){let n=Bn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function Wn(e,t,n){for(let r of e.circuit.instances??[]){if(r.path.includes(`/`))continue;let e=r.ports.find(e=>`${r.path}.${e.name}`===t);if(!e)continue;let i=`${r.path}.${e.name}`,a=e.members?{members:e.members}:{};return{selector:`port:${i}`,at:n,label:i,port:{instance:r.path,name:e.name,bus:e.bus===!0,...a}}}}function Gn(e,t,n){let[r,i]=t.port?[t,n]:n.port?[n,t]:[];if(!r?.port||!i)return;let{port:a}=r;if(i.port)return{notice:`Connect ${r.label} and ${i.label} through a named net: wire each to a net label`};let o=(e.circuit.instances??[]).find(e=>e.path===a.instance);if(!o)return{notice:`${a.instance} is gone; wait for the build`};let s=a.bus?qn(a,i):Kn(i);if(s===void 0){let e=a.bus?`a bus with the members ${(a.members??[]).join(`, `)}`:`the net a name first (a net label)`;return{notice:a.bus?`${r.label} is a bus pin; wire it to ${e}`:`Give ${e}, then wire ${r.label} to it`}}let c=pn(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:Sn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Kn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function qn(e,t){let n=e.members??[],r=t.members??[];return r.length===n.length&&n.every(e=>r.includes(e))?t.label:void 0}function Jn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Vn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Yn(e,t,n,r={}){let i=Jn(e,t,n),a=i&&zn(e).find(e=>e.id===i.pin);return i&&a?Hn(e,a,i.at):i&&Wn(e,i.pin,i.at)||(nr(e,t,n)??er(e,t,n,r)??ir(e,t,n,r))}function Xn(e,t){let n;for(let r=1;r<e.length;r++){let[i,a]=[e[r-1],e[r]];if(!i||!a)continue;let o=or(t,i,a),s=Vn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Zn=e=>Math.round(e*1e4)/1e4||0;function Qn(e,t,n,r,i,a){let o=e=>e>=n[0]&&e<=n[1];if(i!==void 0&&Math.abs(t-i)<=r&&o(i))return i;if(!a.snap||!a.step)return e;let s=Zn(Math.round(e/a.step)*a.step);return o(s)?s:e}function $n(e,t,n,r){let{a:i,b:a,at:o}=e,s=i.y===a.y&&i.x!==a.x?`x`:i.x===a.x&&i.y!==a.y?`y`:void 0;if(!s)return o;let c=Qn(o[s],t[s],[Math.min(i[s],a[s]),Math.max(i[s],a[s])],n,r.from?.[s],r);return s===`x`?{x:c,y:i.y}:{x:i.x,y:c}}function er(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Xn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={id:r.id,name:r.name,members:r.members,near:e})}let a=i&&$n(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Zn(a.x),y:Zn(a.y)},label:i.name,members:i.members}}function tr(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function nr(e,t,n){let r;for(let i of e.schematic.labels){let a=e.circuit.nets.find(e=>e.id===i.net),o=a?.names.includes(i.text)?i.text:a?.names[0],s=rr(i,t);o!==void 0&&s<=n&&(!r||s<r.d)&&(r={name:o,at:i.at,d:s})}return r&&{selector:`net.${r.name}`,at:r.at,label:r.name,net:r.name}}function rr(e,t){if(e.style!==`label`)return Math.max(Vn(e.at,t)-jn,0);let{box:n}=Vt(e);return Math.hypot(Math.max(n.minX-t.x,0,t.x-n.maxX),Math.max(n.minY-t.y,0,t.y-n.maxY))}function ir(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Xn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&ar(e,i.net,$n(i.near,t,n,r))}function ar(e,t,n){let r=e.circuit.nets.find(e=>e.id===t),i=r?.names[0];if(i!==void 0)return{selector:`net.${i}`,at:n,label:i,net:i};let a=r?.pins[0]??(t.startsWith(`net:`)?t.slice(4):void 0),o=zn(e).find(e=>e.id===a);return o?{selector:Ln(e,o),at:n,label:Ln(e,o),pin:o.id}:void 0}function or(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function sr(e,t){if(t.pin!==void 0)return Bn(e,t.pin);let{selector:n}=t;if(n.startsWith(`net.`))return e.circuit.nets.find(e=>e.names.includes(n.slice(4)));let r=zn(e).find(t=>Ln(e,t)===n);return r&&Bn(e,r.id)}function cr(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function lr(e,t,n){let[r,i]=[sr(e,t),sr(e,n)],[a,o]=[ur(t,r),ur(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var ur=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function dr(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Nn.test(t)&&!t.includes(`~`)}var fr=e=>e.selector.startsWith(`net.`);function pr(e,t,n,r=[]){let i=An([e.at,...n,t.at],r);return i.slice(+!fr(e),fr(t)?i.length:i.length-1)}function mr(e,t,n,r,i=[]){if(t.members||n.members||!dr(t.selector)||!dr(n.selector))return[];let[a,o]=[sr(e,t),sr(e,n)];if(cr(t,n)||a!==void 0&&a.id===o?.id)return[];let s=pr(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var hr=/^net\.([\w-]+)$/,gr=new Set;function _r(e,t,n){return`pin`in n?t!==void 0&&Rn(e,t)?.id===n.pin:n.net.includes(hr.exec(t?.trim()??``)?.[1]??``)}function vr(e,t,n,r){return t.model.traces.filter(t=>_r(e,t.from,n)&&_r(e,t.to,r)||_r(e,t.from,r)&&_r(e,t.to,n))}function yr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function br(e){if(!e.editable)return`This wire is read-only (${e.readonlyReason}); change it in the code`;if(e.props.schematicRouteHints&&!e.schematicRouteHints)return`The corners of this wire are an expression; change them in the code`}function xr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[Rn(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function Sr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function Cr(e,t){let n=e.model.traces.find(e=>e.from===t.from&&e.to===t.to||e.from===t.to&&e.to===t.from);return n!==void 0&&n.start!==t.start?`This wire repeats another between the same ends; change its corners in the code`:void 0}var wr=.1,Tr=e=>Math.round(e*1e3)/1e3||0;function Er(e){if(e.style===`label`)return Vt(e).box;let t=Nt(e.style===`ground`?Ft():It(e.text),[]);return{minX:e.at.x+t.minX,minY:e.at.y+t.minY,maxX:e.at.x+t.maxX,maxY:e.at.y+t.maxY}}function Dr(e){let t=Er(e);return e.style===`label`?t:{minX:t.minX-wr,minY:t.minY-wr,maxX:t.maxX+wr,maxY:t.maxY+wr}}var Or=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,kr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Ar(e,t){return e.schematic.labels.map(e=>({label:e,box:Dr(e)})).filter(({box:e})=>Or(e,t)).sort((e,t)=>kr(e.box)-kr(t.box))[0]?.label}function jr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function Mr(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=e.circuit.connections.find(e=>`label:${e.id}`===n.id),i=`label:${n.net}:`,a=r?[r.from,r.to].find(e=>!e.startsWith(`net.`)):n.id.startsWith(i)?n.id.slice(i.length):void 0,o=e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===a),s=o&&jr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Nr(e,t){let n=Mr(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Pr(e,t){let n=Mr(e,t);return n&&`${n.label.net}|${n.pin.id}`}function Fr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Ir(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function Lr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Ir(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...je([r,t]).slice(1)]}var Rr=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),zr=e=>({x:Tr(e.x),y:Tr(e.y)});function Br(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Vr(e,t,n){let r=Mr(e,t);if(!r)return;let i=zr(n),a=[r.end,...Lr(r,i)];return{at:i,side:Br(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Hr(e,t,n){return yr(vr(e,t,{pin:n.pin.id},{net:Sr(e,n.label.net)}),n.connection?.id)}function Ur(e,t,n,r){let i=Mr(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Hr(e,t,i),o=xr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?Cr(t,a)??br(a):void 0;return s?{blocked:s}:!a&&i.connection?{blocked:`The wire of this label is not written in a trace the Studio can find`}:!a&&!dr(Ln(e,i.pin))?{blocked:`${i.pin.id} has a repeated name and cannot be wired from the Studio`}:a?{anchor:i,trace:a}:{anchor:i}}function Wr(e,t,n,r=gr){let i=Ur(e,t,n,r);return`blocked`in i?i.blocked:null}function Gr(e,t){let n=Sr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Kr(e,t,n,r,i=gr){let a=Ur(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=Lr(o,zr(r)).map(zr);if(Rr(c,o.connection?Ir(o):[]))return[];if(!s)return[{kind:`addTrace`,from:Ln(e,o.pin),to:Gr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&Rn(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var qr=new Intl.Collator(`en`,{numeric:!0});function Jr(e,t){let n=Array.from(e,e=>e.codePointAt(0)),r=Array.from(t,e=>e.codePointAt(0));for(let e=0;e<Math.min(n.length,r.length);e++){let t=n[e]-r[e];if(t!==0)return t}return n.length-r.length}function Yr(e,t){return qr.compare(e,t)||Jr(e,t)}function Xr(e){return[...e].sort(Yr)}function Zr(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Xr(r)};return i?{...a,source:i}:a}var Qr=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,$r={mm:1,in:25.4,mil:.0254};function ei(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Qr.exec(e.trim());if(!t)return;let n=Number(t[1])*($r[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}function ti(e){return e!==void 0&&e.outline.length>=3}var ni=Math.PI/180,ri=1e-12;function ii(e,t){let n=Math.cos(t.rotation*ni),r=Math.sin(t.rotation*ni);return{x:t.x+e.x*n-e.y*r,y:t.y+e.x*r+e.y*n}}function ai(e,t,n){return t<=ri&&n<=ri?[ii({x:0,y:0},e)]:n<=ri?[ii({x:-t,y:0},e),ii({x:t,y:0},e)]:t<=ri?[ii({x:0,y:-n},e),ii({x:0,y:n},e)]:[{x:-t,y:-n},{x:t,y:-n},{x:t,y:n},{x:-t,y:n}].map(t=>ii(t,e))}function oi(e,t,n){let r=Math.min(t,n),i=(Math.max(t,n)-r)/2;return{core:t>=n?ai(e,i,0):ai(e,0,i),radius:r/2}}function si(e){switch(e.shape){case`rect`:return{core:ai(e,e.width/2,e.height/2),radius:0};case`roundrect`:{let t=Math.min(Math.max(e.cornerRadius??0,0),e.width/2,e.height/2);return{core:ai(e,e.width/2-t,e.height/2-t),radius:t}}case`circle`:return{core:[ii({x:0,y:0},e)],radius:e.width/2};case`oval`:return oi(e,e.width,e.height);default:return}}function ci(e,t){return{x:e.x-t.x,y:e.y-t.y}}function li(e,t){return e.x*t.y-e.y*t.x}function ui(e,t,n){let r=ci(n,t),i=r.x*r.x+r.y*r.y,a=i===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r.x+(e.y-t.y)*r.y)/i)),o={x:t.x+r.x*a,y:t.y+r.y*a};return{distance:Math.hypot(e.x-o.x,e.y-o.y),at:o}}function di(e,t,n,r){let i=ci(t,e),a=ci(r,n),o=li(i,a);if(o===0)return;let s=li(ci(n,e),a)/o,c=li(ci(n,e),i)/o;if(!(s<0||s>1||c<0||c>1))return{x:e.x+i.x*s,y:e.y+i.y*s}}function fi(e,t,n,r){let i=di(e,t,n,r);if(i!==void 0)return{distance:0,from:i,to:i};let a=[];for(let i of[e,t]){let e=ui(i,n,r);a.push({distance:e.distance,from:i,to:e.at})}for(let i of[n,r]){let n=ui(i,e,t);a.push({distance:n.distance,from:n.at,to:i})}return a.reduce((e,t)=>t.distance<e.distance?t:e)}function pi(e){return e.length===1?[[e[0],e[0]]]:e.length===2?[[e[0],e[1]]]:e.map((t,n)=>[t,e[(n+1)%e.length]])}function mi(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function hi(e,t){if(!(e.length<3))return t.find(t=>mi(t,e))}function gi(e,t){let n=hi(e,t)??hi(t,e);if(n!==void 0)return{distance:0,from:n,to:n};let r;for(let[n,i]of pi(e))for(let[e,a]of pi(t)){let t=fi(n,i,e,a);(r===void 0||t.distance<r.distance)&&(r=t)}return r}function _i(e,t){return gi(e.core,t.core).distance-e.radius-t.radius}function vi(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?e:{x:e.x+(t.x-e.x)/r*n,y:e.y+(t.y-e.y)/r*n}}function yi(e,t){let{from:n,to:r}=gi(e.core,t.core);return[vi(n,r,e.radius),vi(r,n,t.radius)]}function bi(e){let t=e.core.map(e=>e.x),n=e.core.map(e=>e.y);return{minX:Math.min(...t)-e.radius,minY:Math.min(...n)-e.radius,maxX:Math.max(...t)+e.radius,maxY:Math.max(...n)+e.radius}}var xi={A:`0,0 0,4 2,6 4,4 4,0;0,3 4,3`,B:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;3,3 4,2 4,1 3,0 0,0`,C:`4,1 3,0 1,0 0,1 0,5 1,6 3,6 4,5`,D:`0,0 0,6 3,6 4,5 4,1 3,0 0,0`,E:`4,0 0,0 0,6 4,6;0,3 3,3`,F:`0,0 0,6 4,6;0,3 3,3`,G:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,3 2,3`,H:`0,0 0,6;4,0 4,6;0,3 4,3`,I:`1,0 3,0;2,0 2,6;1,6 3,6`,J:`0,1 1,0 2,0 3,1 3,6;2,6 4,6`,K:`0,0 0,6;4,6 0,2;1,3 4,0`,L:`0,6 0,0 4,0`,M:`0,0 0,6 2,3 4,6 4,0`,N:`0,0 0,6 4,0 4,6`,O:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0`,P:`0,0 0,6 3,6 4,5 4,4 3,3 0,3`,Q:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;2,2 4,0`,R:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;2,3 4,0`,S:`4,5 3,6 1,6 0,5 0,4 1,3 3,3 4,2 4,1 3,0 1,0 0,1`,T:`0,6 4,6;2,6 2,0`,U:`0,6 0,1 1,0 3,0 4,1 4,6`,V:`0,6 2,0 4,6`,W:`0,6 1,0 2,3 3,0 4,6`,X:`0,0 4,6;0,6 4,0`,Y:`0,6 2,3 4,6;2,3 2,0`,Z:`0,6 4,6 0,0 4,0`,0:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;0,1 4,5`,1:`1,5 2,6 2,0;1,0 3,0`,2:`0,5 1,6 3,6 4,5 4,4 0,0 4,0`,3:`0,5 1,6 3,6 4,5 4,4 3,3 4,2 4,1 3,0 1,0 0,1;1,3 3,3`,4:`3,0 3,6 0,2 4,2`,5:`4,6 0,6 0,3 3,3 4,2 4,1 3,0 1,0 0,1`,6:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,2 3,3 0,3`,7:`0,6 4,6 1,0`,8:`1,3 0,4 0,5 1,6 3,6 4,5 4,4 3,3 1,3 0,2 0,1 1,0 3,0 4,1 4,2 3,3`,9:`0,1 1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,4 1,3 4,3`,"-":`1,3 3,3`,_:`0,0 4,0`,"+":`2,1 2,5;0,3 4,3`,".":`2,0 2,0`,"/":`0,0 4,6`,"~":`0,3 1,4 3,2 4,3`,"(":`3,6 2,5 2,1 3,0`,")":`1,6 2,5 2,1 1,0`,"#":`1,0 1,6;3,0 3,6;0,2 4,2;0,4 4,4`," ":``},Si=`0,0 4,0 4,6 0,6 0,0`,Ci=4,wi=6,Ti=6;function Ei(e){let t=xi[e.toUpperCase()]??Si;return t===``?[]:t.split(`;`).map(e=>e.split(` `).map(e=>{let[t,n]=e.split(`,`).map(Number);return{x:t??0,y:n??0}}))}function Di(e,t){let n=[...e].length;return n===0?0:((n-1)*Ti+Ci)*t/wi}function Oi(e,t,n,r=!1,i=!1){let a=n/wi,o=[...e],s=Di(e,wi),c=r?-1:1;return o.flatMap((e,n)=>Ei(e).map(e=>e.map(e=>{let r=c*(n*Ti+e.x-s/2)*a,o=(e.y-wi/2)*a;return i?{x:t.x-o,y:t.y+r}:{x:t.x+r,y:t.y+o}})))}var ki=.15,Ai=[0,.4,.8,1.2,1.6],ji=.5,Mi=4,Ni=2,Pi={pad:100,hole:100,via:50,designator:100,courtyard:2,edge:1e3},Fi=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY,Ii=(e,t)=>Math.max(0,Math.min(e.maxX,t.maxX)-Math.max(e.minX,t.minX))*Math.max(0,Math.min(e.maxY,t.maxY)-Math.max(e.minY,t.minY)),Li=(e,t)=>({minX:Math.min(e.minX,t.minX),minY:Math.min(e.minY,t.minY),maxX:Math.max(e.maxX,t.maxX),maxY:Math.max(e.maxY,t.maxY)}),Ri=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function zi(e,t,n=0){let r=Di(e,1)/2+ki/2,i=.575,[a,o]=n===90?[i,r]:[r,i];return{minX:t.x-a,minY:t.y-o,maxX:t.x+a,maxY:t.y+o}}function Bi(e,t){let n=e.rotation*Math.PI/180,[r,i]=[Math.abs(Math.cos(n)),Math.abs(Math.sin(n))],[a,o]=[e.width/2+t,e.height/2+t],[s,c]=e.shape===`circle`?[a,a]:[a*r+o*i,a*i+o*r];return{minX:e.x-s,minY:e.y-c,maxX:e.x+s,maxY:e.y+c}}function Vi(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Hi(e,t){let n=Math.abs(e-t),r=Math.max(e,n),i=Math.max(ji,r/Mi),a=[0,n,e,...Array.from({length:Math.floor(r/i)},(e,t)=>(t+1)*i)].flatMap(e=>[-e,e]).map(e=>Math.round(e*1e6)/1e6+0);return[...new Set(a)]}function Ui(e,t,n){return n===void 0?[...Wi(e,t,e=>e?0:90),...Wi(e,t,e=>e?90:0)]:Wi(e,t,()=>n)}function Wi(e,t,n){if(e.courtyard.length===0)return[{at:{x:e.x,y:e.y},rotation:n(!0)}];let r=Vi(e.courtyard),[i,a]=[(r.minX+r.maxX)/2,(r.minY+r.maxY)/2],[o,s]=[(r.maxX-r.minX)/2,(r.maxY-r.minY)/2],c=Di(e.component,1)/2+ki/2,l=.575,u=[],d={flat:Hi(o,n(!0)===0?c:l),upright:Hi(s,n(!1)===0?l:c)};for(let e of Ai){let o=t+e;for(let e of[`top`,`bottom`,`left`,`right`]){let t=e===`top`||e===`bottom`,s=n(t),[f,p]=s===0===t?[c,l]:[l,c];if(t){let t=e===`top`,n=t?r.maxY+o+p:r.minY-o-p,[a,c]=t?[r.maxY,n+p]:[n-p,r.minY];for(let e of d.flat)u.push({at:{x:i+e,y:n},rotation:s,reach:{minX:i+e-f,maxX:i+e+f,minY:a,maxY:c}})}else{let t=e===`right`,n=t?r.maxX+o+p:r.minX-o-p,[i,c]=t?[r.maxX,n+p]:[n-p,r.minX];for(let e of d.upright)u.push({at:{x:n,y:a+e},rotation:s,reach:{minX:i,maxX:c,minY:a+e-f,maxY:a+e+f}})}}}let f=e=>Math.round(Math.hypot(e.at.x-i,e.at.y-a)*1e3);return u.map((e,t)=>({place:e,i:t,d:f(e)})).sort((e,t)=>e.d-t.d||e.i-t.i).map(e=>e.place)}var Gi=class{outline;clearance;fixedIndex=new Ki;textIndex=new Ki;designators=new Map;keptOf=new WeakMap;constructor(e,t){this.outline=e,this.clearance=t}add(e,t,n,r){let i={kind:e,component:t,side:n,box:r};e===`designator`?(this.remove(t),this.designators.set(t,i),this.textIndex.insert(i,r)):this.fixedIndex.insert(i,r)}remove(e){let t=this.designators.get(e);t&&(t.gone=!0),this.designators.delete(e)}covered(e,t,n=!0){let{near:r,fixed:i}=n?this.kept(e,t):this.measured(e,t,!1);if(this.designators.size===0)return i;let a;for(let t of this.textIndex.query(r))!t.gone&&t.side===e.side&&t.component!==e.component&&Fi(r,t.box)&&(a??={...i,designators:[]},a.score+=Pi.designator*(1+Ii(r,t.box)),a.designators.push(t.component));return a??i}kept(e,t){let n=this.keptOf.get(t);if(n)return n;let r=this.measured(e,t,!0);return this.keptOf.set(t,r),r}measured(e,t,n){let r=zi(e.component,t.at,t.rotation);return{near:n?Ri(r,this.clearance):r,fixed:this.fixedCovered(e,t,r,n)}}fixedCovered(e,t,n,r){let i=t.reach??n,a={pads:[],designators:[],courtyards:[],vias:!1,holes:!1,edge:!1,score:0,fixed:0,between:0};for(let t of this.fixedIndex.query(r?Li(n,i):n)){if(t.side!==`both`&&t.side!==e.side||t.component===e.component&&t.kind!==`pad`)continue;let o=t.kind===`courtyard`&&r&&!Fi(n,t.box)&&Fi(i,t.box);if(!o&&!Fi(n,t.box))continue;let s=Ii(n,t.box),c=o?1:Pi[t.kind]*(t.kind===`courtyard`?Math.max(s,.001):1+s);a.score+=c,o?a.between+=1:a.fixed+=c,o||(t.kind===`pad`?a.pads.push(t.component):t.kind===`courtyard`?a.courtyards.push(t.component):t.kind===`via`?a.vias=!0:a.holes=!0)}return this.outline&&!qi(n,this.outline)&&(a.edge=!0,a.score+=Pi.edge,a.fixed+=Pi.edge),a}},Ki=class e{cells=new Map;stamp=0;static key(e,t){return(e+32768)*65536+(t+32768)}insert(t,n){for(let r=Math.floor(n.minX/Ni);r<=Math.floor(n.maxX/Ni);r++)for(let i=Math.floor(n.minY/Ni);i<=Math.floor(n.maxY/Ni);i++){let n=e.key(r,i),a=this.cells.get(n);a?a.push(t):this.cells.set(n,[t])}}query(t){let n=++this.stamp,r=[];for(let i=Math.floor(t.minX/Ni);i<=Math.floor(t.maxX/Ni);i++)for(let a=Math.floor(t.minY/Ni);a<=Math.floor(t.maxY/Ni);a++)for(let t of this.cells.get(e.key(i,a))??[])t.seen!==n&&(t.seen=n,r.push(t));return r}};function qi(e,t){return[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].every(e=>mi(e,t))?!t.some(t=>t.x>e.minX&&t.x<e.maxX&&t.y>e.minY&&t.y<e.maxY):!1}var Ji=.15,Yi=e=>[...new Set(e)].sort(Yr),Xi=e=>(Math.round(e)%360+360)%360;function Zi(e,t,n){let r=new Gi(ti(e.board)?e.board?.outline:void 0,n);for(let n of e.parts){for(let e of n.pads)r.add(`pad`,n.component,e.layers===`through`?`both`:e.layers,Bi(e,t));n.courtyard.length>0&&r.add(`courtyard`,n.component,n.side,Vi(n.courtyard))}for(let t of e.vias??[]){let e=t.diameter/2;r.add(`via`,``,`both`,{minX:t.at.x-e,minY:t.at.y-e,maxX:t.at.x+e,maxY:t.at.y+e})}for(let t of e.holes??[]){let e=t.diameter/2;r.add(`hole`,``,`both`,{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e})}return r}function Qi(e){let t=new Map;for(let n of e){if(n.copyOf===void 0)continue;let e=`${n.copyOf}@${Xi(n.rotation)}${n.side}`;t.set(e,[...t.get(e)??[],n])}return t}function $i(e,t,n=Ji){let r=`${t}/${n}`,i=ta(e,r);if(i)return i;let a=aa(e,t,n);return na(e,r,a),a}var ea=new WeakMap;function ta(e,t){let n=e.parts[0],r=n&&ea.get(n);if(r&&r.key===t&&r.vias===e.vias&&r.holes===e.holes&&r.board===e.board&&r.parts.length===e.parts.length){for(let t=0;t<r.parts.length;t++)if(r.parts[t]!==e.parts[t])return;return r.placements}}function na(e,t,n){let r=e.parts[0];r&&ea.set(r,{key:t,parts:e.parts,vias:e.vias,holes:e.holes,board:e.board,placements:n})}function ra(e,t){let n;for(let r of e){let e=t(r);if(e.score===0)return r;n===void 0&&e.score===e.between*1&&(n=r)}return n}function ia(e,t,n){let[r,i]=[0,0];for(let e of t){let t=n(e);if(t.score===0&&r++,t.score===t.between*1&&i++,r>=ca)break}return{clear:r,fair:i}}function aa(e,t,n){let r=e.parts.filter(e=>e.component!==``),i=Zi(e,t,n),a=new Map,o=(e,t)=>{a.set(e.component,t),i.add(`designator`,e.component,e.side,zi(e.component,t.at,t.rotation))},s=new Map,c=e=>{let t=s.get(e.component);if(t)return t;let r=Ui(e,n,e.nameRotation);return s.set(e.component,r),r},l=(e,t)=>i.covered(e,t).score===0,u=(e,t)=>{let n=i.covered(e,t);return n.score===n.between*1},d=e=>{let t=c(e),n=ra(t,t=>i.covered(e,t));if(n)return n;let r={place:t[0],score:1/0};for(let n of t){let t=i.covered(e,n).score;t<r.score&&(r={place:n,score:t})}return r.place};for(let e of r)e.nameAt&&o(e,{at:e.nameAt,rotation:e.nameRotation??0});let f=new Map(r.filter(e=>!e.nameAt).map(e=>[e.component,ia(e,c(e),t=>i.covered(e,t))])),p=oa(r.filter(e=>!e.nameAt),e=>f.get(e.component)??{clear:0,fair:0});for(let e of p)e.length>1?fa(e,c,l,d,o):o(e[0],d(e[0]));return ua(r,a,{tries:c,clear:l,fair:u,settle:o,covered:(e,t)=>i.covered(e,t),remove:e=>i.remove(e.component)}),r.map(e=>{let t=a.get(e.component),n=i.covered(e,t,!1);return{component:e.component,side:e.side,at:t.at,rotation:t.rotation,coversPads:Yi(n.pads),coversDesignators:Yi(n.designators),coversParts:Yi(n.courtyards),offBoard:n.edge}})}function oa(e,t){let n=e=>t(e).clear>0?0:t(e).fair>0?1:2,r=e=>[t(e).clear,t(e).fair,0][n(e)],i=new Map([...Qi(e).values()].flatMap(e=>e.map(t=>[t.component,e]))),a=[],o=new Set;for(let t of e){if(o.has(t.component))continue;let e=i.get(t.component)??[t];e.forEach(e=>o.add(e.component));let r=e.filter(e=>n(e)===0);r.length>0&&a.push(r),a.push(...e.filter(e=>n(e)>0).map(e=>[e]))}let s=e=>({tier:Math.max(...e.map(n)),size:Math.min(...e.map(r))});return a.map((e,t)=>({members:e,i:t,...s(e)})).sort((e,t)=>e.tier-t.tier||e.size-t.size||e.i-t.i).map(e=>e.members)}var sa=4,ca=12,la=2;function ua(e,t,n){let r=new Map(e.map(e=>[e.component,e])),i=new Set(e.filter(e=>e.nameAt).map(e=>e.component));for(let a=0;a<la;a++){let a=!1;for(let o of e){let e=t.get(o.component);if(i.has(o.component)||n.clear(o,e))continue;let s=n.fair(o,e);n.remove(o);let c=ra(n.tries(o),e=>n.covered(o,e)),l=c&&(n.clear(o,c)||!s)?c:void 0,u=[];for(let e of l?[]:n.tries(o)){let t=n.covered(o,e);if(t.fixed!==0||t.between!==0&&s||t.designators.some(e=>i.has(e))||u.push(e),u.length>=sa)break}l&&n.settle(o,l);let d=l!==void 0||u.some(e=>da(o,e,r,t,n));d||n.settle(o,e),a||=d}if(!a)return}}function da(e,t,n,r,i){let a=Yi(i.covered(e,t).designators).map(e=>n.get(e)),o=a.map(e=>[e,r.get(e.component)]);a.forEach(i.remove),i.settle(e,t);let s=[];for(let e of a){let t=ra(i.tries(e),t=>i.covered(e,t));if(!t)break;i.settle(e,t),s.push(e)}return s.length===a.length||(s.forEach(i.remove),i.remove(e),o.forEach(([e,t])=>i.settle(e,t)),!1)}function fa(e,t,n,r,i){let a=e.map(t),o=Math.min(...a.map(e=>e.length)),s=t=>e.every((e,r)=>n(e,a[r]?.[t]))&&pa(e,a,t);for(let t=0;t<o;t++)if(s(t)){e.forEach((e,n)=>i(e,a[n]?.[t]));return}let c={index:-1,clear:0};for(let t=0;t<o;t++){let r=e.filter((e,r)=>n(e,a[r]?.[t])).length;r>c.clear&&(c={index:t,clear:r})}let l=[];e.forEach((e,t)=>{let r=c.index>=0?a[t]?.[c.index]:void 0;r&&n(e,r)?i(e,r):l.push(e)}),l.forEach(e=>i(e,r(e)))}function pa(e,t,n){let r=e.map((e,r)=>{let i=t[r]?.[n];return zi(e.component,i.at,i.rotation)});return r.every((e,t)=>r.every((n,r)=>r<=t||!(e.minX<n.maxX&&n.minX<e.maxX&&e.minY<n.maxY&&n.minY<e.maxY)))}var ma=e=>e.minSilkToPad??.15,ha=e=>e.nameAt??e.designatorAt??Ui(e,.15,0).find(t=>t.at.y>e.y)?.at??{x:e.x,y:e.y},ga=e=>(e.nameAt?e.nameRotation:void 0)??e.designatorRotation??e.nameRotation??0,_a=.3,va=.5,ya=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ba=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,xa={strong:600,regular:400},Sa=(e,t,n=ya)=>`${e} ${t}px ${n}`,W={background:`#000000`,boardEdge:`#ff00ff`,topCopper:`#ff0000`,bottomCopper:`#0000ff`,inner1Copper:`#cc9933`,inner2Copper:`#9966cc`,multiLayer:`#c0c0c0`,viaRing:`#c0c0c0`,highlight:`#ffffff`,drill:`#222222`,topSilk:`#ffcc00`,bottomSilk:`#66cc33`,topAssembly:`#33cc99`,bottomAssembly:`#5555ff`,ratsnest:`#6464ff`,keepout:`#f022f0`,document:`#ffffff`,grid:`rgb(255 255 255 / 30%)`,gridFifth:`rgb(255 255 255 / 50%)`,selection:`#ffffff`,selectionFill:`rgb(255 255 255 / 50%)`,hover:`rgb(255 255 255 / 60%)`,selectionBox:`#00ffff`,selectionBoxFill:`rgb(0 255 255 / 10%)`,notePanel:`rgb(0 0 0 / 80%)`,error:`#e5534b`,warning:`#e0a63a`,ringHaloOuter:`#ffffff`,ringHaloInner:`#000000`};function Ca(e){let t=e.split(`_`);return[t.includes(`top`)?`top`:t.includes(`bottom`)?`bottom`:`middle`,t.includes(`left`)?`left`:t.includes(`right`)?`right`:`center`]}var wa=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],Ta=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],Ea=[{id:`top`,name:`Top Layer`,group:`copper`,color:W.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:W.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:W.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:W.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:W.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:W.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:W.topAssembly,bottomColor:W.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:W.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:W.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:W.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:W.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:W.keepout}];function Da(e,t){return Ea.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function Oa(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var ka={...Object.fromEntries(wa.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function Aa(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function ja(e,t,n){let r={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`};return Object.keys(r).flatMap(i=>{let a=e.filter(e=>e.layer===i).map(e=>({id:e.id,net:t(e.net),layer:i,shown:!n.has(e.id)}));return a.length>0?[{layer:i,name:r[i],pours:a}]:[]})}function Ma(e,t){return{...e,[t]:!e[t]}}function Na(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function Pa(e){let t=e.side===`top`,n=new Set([`courtyard`]);e.fabrication.length>0&&n.add(t?`topAssembly`:`bottomAssembly`),e.silkscreen.length>0&&n.add(t?`topSilk`:`bottomSilk`);for(let t of e.pads)n.add(Na(t)),t.drill&&n.add(`hole`);return[...n]}function Fa(e,t){return e.some(e=>t[e])}function Ia(e,t){let n=new Map(e.map(e=>[e.component,Pa(e)]));return{visible:t,of:e=>n.get(e)}}var La={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function Ra(e,t){return{...e,[t]:!e[t]}}function za(e,t){return e===void 0||e[t]}function G(e){let t={kind:`parts`,label:`Parts`};return e===`schematic`?[t,{kind:`wires`,label:`Wires`},{kind:`labels`,label:`Net labels and flags`},{kind:`drawings`,label:`Drawings`},{kind:`texts`,label:`Names and values`}]:[t,{kind:`tracks`,label:`Tracks`},{kind:`vias`,label:`Vias`},{kind:`pours`,label:`Copper pours and holes`},{kind:`texts`,label:`Designators`}]}var Ba={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Va(e,t){if(!Ha(Ba[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||Fa(r,n.visible)}function Ha(e,t){return t.armed===`note`||t.armed===`zoom`?!1:za(t.filter,e)}function Ua(e,t){return e.filter(e=>Va(e,t))}function Wa(e,t){return Ua(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function Ga(e,t){return Ua(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function Ka(e,t){return Ha(`labels`,t)?[...e]:[]}function qa(e,t){return Ha(`drawings`,t)?[...e]:[]}function Ja(e,t){return Ua(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function Ya(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(Wa(e,c),Ga(r,c),Ka(i,c),qa(a,c),Ja(o,c))}}function Xa(e,t){return t.x>=e.x?`inside`:`touching`}var Za=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,Qa=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function $a(e,t,n,r){let i=ke([t,n]);if(!i)return[];let a=r===`inside`?e=>Za(i,e):e=>Qa(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function eo(e,t,n,r){return $a(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function to(e,t,n,r){return $a(e,t,n,r)}var no=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function ro(e,t,n){if(no(e,t)||no(e,n))return!0;let r=ke([t,n]);if(!r||!Qa(e,r))return!1;let i=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}].map(e=>(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x));return i.some(e=>e>=0)&&i.some(e=>e<=0)}function io(e,t,n,r){let i=ke([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>no(i,e)):e=>e.some((t,n)=>ro(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function ao(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[Wa(e.parts,o),Ga(e.wires??[],o),Ka(e.labels??[],o)],u=qa(e.drawings??[],o),d=Ja(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var oo=e=>[...new Set(e)],so=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),co=(e,t)=>e.filter(e=>!t.includes(e)),lo=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},uo=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,fo=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&uo(e.from,t.from)&&uo(e.to,t.to);function po(e,t){let[n,r]=[e.points[t],e.points[t+1]];return Number.isInteger(t)&&t>=0&&n&&r?{id:e.id,index:t,from:{x:n.x,y:n.y},to:{x:r.x,y:r.y}}:void 0}function mo(e,t){return uo(t[e.index],e.from)&&uo(t[e.index+1],e.to)}var ho={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},go=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],_o=class e{static none=new e(ho);names;wires;labels;drawings;copper;texts;board;segment;constructor(e,t){this.names=Object.freeze([...e.names]),this.wires=Object.freeze([...e.wires]),this.labels=Object.freeze([...e.labels]),this.drawings=Object.freeze([...e.drawings]),this.copper=Object.freeze([...e.copper]),this.texts=Object.freeze([...e.texts]),this.board=Object.freeze([...e.board]),this.segment=t&&Object.freeze({id:t.id,index:t.index,from:Object.freeze({...t.from}),to:Object.freeze({...t.to})}),Object.freeze(this)}static from(t){return go.every(e=>t[e].length===0)?e.none:new e(t)}get lists(){return{names:this.names,wires:this.wires,labels:this.labels,drawings:this.drawings,copper:this.copper,texts:this.texts,board:this.board}}with(t){let n={...this.lists,...t};return go.every(e=>n[e].length===this[e].length)?this:e.from(n)}grown(t){return new e({...this.lists,...t})}get primary(){return this.names.at(-1)}get size(){return this.names.length}get wireCount(){return this.wires.length}get labelCount(){return this.labels.length}get drawingCount(){return this.drawings.length}get copperCount(){return this.copper.length}get textCount(){return this.texts.length}get boardCount(){return this.board.length}get total(){return this.names.length+this.wires.length+this.labels.length+this.drawings.length+this.copper.length+this.texts.length+this.board.length}get soleBoard(){return this.total===1?this.board[0]:void 0}get soleText(){return this.total===1?this.texts[0]:void 0}get soleCopper(){return this.total===1?this.copper[0]:void 0}get soleWire(){return this.total===1?this.wires[0]:void 0}get soleLabel(){return this.total===1?this.labels[0]:void 0}get soleDrawing(){return this.total===1?this.drawings[0]:void 0}has(e){return this.names.includes(e)}hasWire(e){return this.wires.includes(e)}hasLabel(e){return this.labels.includes(e)}hasDrawing(e){return this.drawings.includes(e)}hasCopper(e){return this.copper.includes(e)}hasText(e){return this.texts.includes(e)}hasBoard(e){return this.board.includes(e)}onlyBoard(t){return this.soleBoard===t?this:new e({...ho,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=oo(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:co(this.board,e)})}keepBoard(e){return this.with({board:lo(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...ho,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...ho,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...ho,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...ho,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...ho,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...ho,copper:[t]})}onlySegment(t){return fo(this.segment,t)?this:new e({...ho,copper:[t.id]},t)}toggle(e){return this.has(e)?this.without([e]):this.grown({names:[...this.names,e]})}toggleWire(e){return this.hasWire(e)?this.withoutWires([e]):this.grown({wires:[...this.wires,e]})}toggleLabel(e){return this.hasLabel(e)?this.withoutLabels([e]):this.grown({labels:[...this.labels,e]})}toggleDrawing(e){return this.hasDrawing(e)?this.withoutDrawings([e]):this.grown({drawings:[...this.drawings,e]})}toggleCopper(e){return this.hasCopper(e)?this.withoutCopper([e]):this.grown({copper:[...this.copper,e]})}toggleText(e){return this.hasText(e)?this.with({texts:co(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=oo(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=oo(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=oo(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=oo(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=oo(e).filter(e=>!this.hasCopper(e));return t.length===0?this:this.grown({copper:[...this.copper,...t]})}clear(){return e.none}all(t,n=[],r=[],i=[],a=[]){let o={names:oo(t),wires:oo(n),labels:oo(r),drawings:oo(i),copper:oo(a),texts:[],board:[]};return go.every(e=>so(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:co(this.names,e)})}withoutWires(e){return this.with({wires:co(this.wires,e)})}withoutLabels(e){return this.with({labels:co(this.labels,e)})}withoutDrawings(e){return this.with({drawings:co(this.drawings,e)})}withoutCopper(e){return this.with({copper:co(this.copper,e)})}keep(e){return this.with({names:lo(this.names,e)})}keepWires(e){return this.with({wires:lo(this.wires,e)})}keepLabels(e){return this.with({labels:lo(this.labels,e)})}keepDrawings(e){return this.with({drawings:lo(this.drawings,e)})}withoutTexts(e){return this.with({texts:co(this.texts,e)})}keepTexts(e){return this.with({texts:lo(this.texts,e)})}keepCopper(e){return this.with({copper:lo(this.copper,e)})}};function vo(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!mo(n,r.points)?e.onlyCopper(n.id):e}function yo(e){return e.shiftKey||e.ctrlKey||e.metaKey}function bo(e,t){let n=yo(t);return t=>n?t.toggle(e):t.only(e)}function xo(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var So={error:W.error,warning:W.warning},Co=6,wo=1.5,To=3,Eo=1;function Do(e,t,n,r,i,a=So){if(n.length!==0){e.globalAlpha=1,e.setLineDash([]);for(let o of n){let n=B(t.camera,t.size,o.at),s=o.id===r?To:wo;i&&ko(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,Oo(e,n,Co,s)}}}function Oo(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function ko(e,t,n){let r=(n+Eo)/2;e.strokeStyle=W.ringHaloOuter,Oo(e,t,Co+r,Eo),e.strokeStyle=W.ringHaloInner,Oo(e,t,Co-r,Eo)}var Ao={background:`#FFFCF8`,grid:`#F0F0EB`,wire:`#008800`,bus:`#008800`,drawing:`#000080`,junction:`#CC0000`,symbolOutline:`#A00000`,pin:`#880000`,pinName:`#000000`,pinNumber:`#000000`,designator:`#0000FF`,netName:`#0000FF`,value:`#000080`,noConnect:`#33CC33`,selection:`#FF0000`,highlight:`#FF9933`,border:`#A00000`,titleText:`#000080`,gridDot:`#D9D9D2`,flag:`#A00000`,markerError:W.error,markerWarning:W.warning,selectionGlow:0,hover:`rgb(255 0 0 / 45%)`,handleFill:`#FFFFFF`,selectionFill:`rgb(255 0 0 / 8%)`,selectionBox:`#0000FF`,selectionBoxFill:`rgb(0 0 255 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},jo={background:`#141619`,grid:`#2B3038`,gridDot:`#2B3038`,gridFifth:`#3A4049`,wire:`#5BD3C7`,bus:`#8AB4FF`,drawing:`#9AA1A9`,junction:`#5BD3C7`,symbolOutline:`#D9DEE5`,pin:`#D9DEE5`,pinName:`#AEB6C0`,pinNumber:`#7E8792`,designator:`#E6E8EB`,netName:`#F2C66D`,value:`#AEB6C0`,noConnect:`#5BD3C7`,selection:`#4CC9F0`,highlight:`#E89A4F`,border:`#9AA1A9`,titleText:`#9AA1A9`,flag:`#FF9E80`,markerError:`#FF6B6B`,markerWarning:`#FFC857`,selectionGlow:8,hover:`#8BE0F5`,handleFill:`#141619`,selectionFill:`rgb(76 201 240 / 10%)`,selectionBox:`#4CC9F0`,selectionBoxFill:`rgb(76 201 240 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},Mo=e=>e===`dark`?jo:Ao,No=Ao,Po=()=>No;function Fo(e){No=e}function Io(e,t,n=No){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var Lo=.02,Ro=3*Lo;function zo(e){return e.kind===`bus`?Ro:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var Bo=(e,t)=>Math.max(e,t);function Vo(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function Ho(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function Uo(e){return e.kind===`bus`?Po().bus:e.kind===`junction`?e.color??Po().junction:e.color??Po().drawing}var Wo=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Go=e=>`${e}33`,Ko=e=>1/e,qo=(e,t)=>(Math.floor(e*t)+.5)/t,Jo=(e,t)=>Math.round(e*t)/t,Yo=(e,t)=>Math.max(1,Math.round(e*t))/t,Xo=(e,t)=>Math.round(e*t)/t,Zo=(e,t)=>e/t,Qo=(e,t)=>Math.max(1,Math.round(e*t)),$o=(e,t,n)=>n%2==1?qo(e,t):Jo(e,t);function es(e,t,n,r=1){let i=e=>$o(e,n,r),a=i(Math.min(e.x,t.x)),o=i(Math.min(e.y,t.y));return{x:a,y:o,width:i(Math.max(e.x,t.x))-a,height:i(Math.max(e.y,t.y))-o}}var ts=.16;function ns(e){return e<7?`none`:e<9?`names`:`all`}function rs(e,t,n){if(n<5)return!1;let r=ns(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var is=(e,t,n)=>Math.max(1,Math.round(e*t*n)),as=(e,t)=>is(ts,e,t),os=(e,t,n)=>is(e,t,n)/n,ss=(e,t)=>({x:Jo(e.x,t),y:Xo(e.y,t)});function cs(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var ls=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),us=e=>e*Math.PI/180;function ds(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)}function fs(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function ps(e,t){if(e.beginPath(),t.kind===`path`||t.kind===`bus`){t.points.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y));return}if(t.kind===`rect`){let{x:n,y:r,width:i,height:a}=t;e.moveTo(n,r),e.lineTo(n+i,r),e.lineTo(n+i,r+a),e.lineTo(n,r+a),e.closePath();return}if(t.kind===`circle`)return e.arc(t.x,t.y,t.radius,0,2*Math.PI);let n=us(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+us(fs(t.startAngle,t.endAngle)))}function ms(e,t){return t.selected?.includes(e.id)?{color:Po().selection,alpha:1}:{color:Uo(e),alpha:t.dim?_a:1}}function hs(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Zt,0,2*Math.PI),Io(e,i),e.fill(),Io(e,!1)}function gs(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=ms(i,r);if(i.kind===`junction`){hs(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=Bo(zo(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(Vo(r.pending?`dashed`:Ho(i),o)),ps(e,i),Wo(i)&&(e.fillStyle=Go(t),e.fill()),Io(e,r.selected?.includes(i.id)??!1),e.stroke(),Io(e,!1),e.setLineDash([])}e.globalAlpha=1}function _s(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=is(o.fontSize,n.scale,a);if(!rs(`detail`,as(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=ms(o,i),u=ss(B(n,r,o),a),[,d]=Ca(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${ya}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var vs=.7,ys=`…`,bs=2;function xs(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=bs;r--){let i=e.slice(0,r)+ys;if(n(i)<=t)return i}return null}function Ss(e,t,n){let r=t(e);if(r>=1)return{text:e,scale:1};if(r>=n)return{text:e,scale:r};for(let r=e.length-1;r>=bs;r--){let i=e.slice(0,r)+ys;if(t(i)>=n)return{text:i,scale:n}}return null}function Cs(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var ws=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),Ts=e=>e.side===`left`||e.side===`right`,Es=e=>Ts(e)?`x`:`y`,Ds=e=>Ts(e)?`y`:`x`,Os=e=>Ts(e)?1:.5,ks={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function As(e,t,n,r){let[i,a]=[Es(e),Ds(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>ws(e,i,e.text,n)*Os(e),c=t=>Math.abs(t.local[a]-e.local[a])<(ws(e,a,e.text,n)+ws(t,a,t.text,n))/2,l=t.filter(t=>t.side===ks[e.side]&&c(t)&&(t.local[i]-e.local[i])*o>0).sort((t,n)=>Math.abs(t.local[i]-e.local[i])-Math.abs(n.local[i]-e.local[i]))[0];return Cs(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/Os(e)}function js(e,t,n){let r=Ds(e),i=t.filter(t=>t!==e&&t.side===e.side).map(t=>Math.abs(t.local[r]-e.local[r]));return i.length===0?1/0:Math.min(...i)-n}function Ms(e,t,n,r,i){let a=As(e,t,n,r),o=js(e,t,r);return Ss(e.text,t=>Math.min(a/ws(e,Es(e),t,n),o/ws(e,Ds(e),t,n)),i)}function Ns(e,t,n){let r=n(t.text)*t.scale,i=e.align===`left`?e.x:e.align===`right`?e.x-r:e.x-r/2;return{x0:i,x1:i+r,y0:e.y-e.ascent*t.scale,y1:e.y+e.descent*t.scale}}var Ps=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function Fs(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&Ps(r,e)&&n.add(i).add(a)})}),n}function Is(e,t,n,r=vs){let i=e.map(i=>Ms(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:Ns(e[r],n,t)),o=Fs(a,(t,n)=>e[t]?.side===e[n]?.side),s=Fs(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var Ls=.25,Rs=.8,zs=.2,Bs={top:Rs,middle:.6000000000000001/2,bottom:-.2},Vs=(e,t,n)=>Sa(e.strong?xa.strong:xa.regular,t/n,e.mono?ba:void 0);function Hs(e,t,{camera:n,ratio:r}){let i=is(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=Vs(t,i,r),ls(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function Us(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(Bs[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??Rs*r-a,descent:i.actualBoundingBoxDescent??zs*r+a}}function Ws(e,{label:t,devicePx:n},r){let i=t.pinOf;if(!i)return null;let a=n/r.ratio,o=B(r.camera,r.size,t.at),[s,c]=Ca(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=Us(e,t.text,s,a);return{text:t.text,x:o.x,y:o.y,align:c,size:a,...u,local:l,side:i.side,quarter:i.quarter}}function Gs(e,t,n){let r=t[0];if(!r)return t;e.font=Vs(r.label,r.devicePx,n.ratio);let i=t.map(t=>Ws(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*vs)/r.devicePx,o=Is(i,t=>e.measureText(t).width,r.devicePx/n.ratio*Ls,a);return t.flatMap((e,t)=>{let n=o[t];if(!n)return[];let r=n.scale<1?Math.floor(e.devicePx*n.scale+1e-9):e.devicePx;return[{label:{...e.label,text:n.text},devicePx:r}]})}function Ks(e,t,n){let r=as(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>rs(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:Hs(e,t,n)})).filter(i),o=new Map;for(let e of a){let t=e.label.pinOf?.symbol;t!==void 0&&o.set(t,[...o.get(t)??[],e])}let s=[...o.values()].flatMap(t=>Gs(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function qs(e,{label:t,devicePx:n},r){let i=ss(B(r.camera,r.size,t.at),r.ratio),[a,o]=Ca(t.anchor);e.save(),e.translate(i.x,i.y),t.rotation&&e.rotate(-t.rotation*Math.PI/180),e.globalAlpha=t.alpha??1,e.fillStyle=t.color,e.font=Vs(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function Js(e,t,n,r,i){let a={camera:n,size:r,ratio:i};cs(e);for(let n of Ks(e,t,a))qs(e,n,a)}var Ys=.05,Xs=.015;function Zs(e){let t=Ys;return[[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y+t}],[{x:e.x-t,y:e.y+t},{x:e.x+t,y:e.y-t}]]}function Qs(e,t,n,r){if(t.length!==0){e.strokeStyle=Po().noConnect,e.lineWidth=n(Xs),e.globalAlpha=r?_a:1;for(let n of t)for(let[t,r]of Zs(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var $s={x:0,y:0},ec=.02,tc=1.2,nc=3.5,rc=.06,ic=1.5,ac=1.6,oc=.04,sc=3,cc=[.1,.06],lc=.1,uc=.07,dc=2.5,fc={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},pc={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},mc={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},hc=e=>e*Math.PI/180,gc=e=>Math.max(Lo*e,tc);function _c(e,t,n,r){let{camera:i,size:a}=n,o=1/i.scale,s=e=>Math.max(e,o/r.ratio),c=[],l=e=>r.moving?.components.includes(e.component)?r.moving.by:$s;e.save();let u=i.scale*r.ratio;e.setTransform(u,0,0,-u,(a.width/2-i.cx*i.scale)*r.ratio,(a.height/2+i.cy*i.scale)*r.ratio),e.lineCap=`round`,e.lineJoin=`round`,kc(e,t,r,o,s);let d=ds(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};gs(e,d,o/r.ratio,m),gs(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)Ac(e,n,l(n),{line:s,px:o,fade:Tc(n,r.highlight)},c);for(let n of t.labels){let t=r.movingLabels?.some(e=>e.id===n.id)??!1,i=r.selectedLabels?.includes(n.id)??!1,a=i?{color:Po().selection,alpha:1}:wc(n.net,r.highlight);Io(e,i),zc(e,Rc(n,r),s,c,t,a),Io(e,!1)}for(let t of r.ghostLabels??[])zc(e,t,s,c,!0,wc(t.net,void 0));Hc(e,t,r,o,l),Qs(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),Js(e,c,i,a,r.ratio),_s(e,p,i,a,m,r.ratio),Do(e,n,r.violations??[],r.activeViolation,!1,{error:Po().markerError,warning:Po().markerWarning}),e.restore()}function vc(e){return e.symbols.map(e=>{let t=bc(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var yc=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function bc(e){let{minX:t,minY:n,maxX:r,maxY:i}=Nt(e.symbol.shapes.filter(e=>!yc(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>xc(t,e)),o=a.map(e=>e.x),s=a.map(e=>e.y);return{minX:Math.min(...o),minY:Math.min(...s),maxX:Math.max(...o),maxY:Math.max(...s)}}function xc(e,t){let n=hc(t.rotation),r=Math.cos(n),i=Math.sin(n);return{x:t.x+e.x*r-e.y*i,y:t.y+e.x*i+e.y*r}}function Sc(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function Cc(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function wc(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:Po().highlight,alpha:1}:{color:void 0,alpha:_a}:{color:void 0,alpha:1}}function Tc(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:_a:1}var Ec=1e-9;function Dc(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<Ec,i=(e,t,n)=>e>=Math.min(t,n)-Ec&&e<=Math.max(t,n)+Ec;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function Oc(e,t,n){return e.wires.some(e=>wc(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&Dc(t,e.points[r-1]??n,n)))}function kc(e,t,n,r,i){e.lineWidth=i(Lo);for(let r of t.wires){if(n.movingLabels?.some(e=>e.hideWire===r.id))continue;let t=n.selectedWires?.includes(r.id)??!1,i=t?{color:Po().selection,alpha:1}:wc(r.net,n.highlight);e.strokeStyle=i.color??Po().wire,e.globalAlpha=i.alpha,Io(e,t),Sc(e,r.points),e.stroke()}Io(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&Oc(t,i,n.highlight);e.fillStyle=a?Po().highlight:Po().junction,e.globalAlpha=n.highlight&&!a?_a:1,Cc(e,i,Math.max(oc,sc*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=Po().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(cc);for(let t of a)Sc(e,t),e.stroke();e.setLineDash([])}}function Ac(e,t,n,r,i){let a={x:t.x+n.x,y:t.y+n.y,rotation:t.rotation},o=r.fade,s=[];e.globalAlpha=o,e.lineWidth=r.line(ec),Nc(e,t.symbol.shapes,a,Po().symbolOutline,s),e.globalAlpha=1;let c=t.symbol.shapes.some(e=>e.type===`text`&&e.role===`pin-number`);t.symbol.kind!==`sheet`&&!c&&s.push(...Mc(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...jc(e,t)})))}function jc(e,t){if(e.pinOf)return{pinOf:{...e.pinOf,symbol:t.component}};if(e.role!==`reference`&&e.role!==`value`||t.symbol.pins.length!==2)return{};let[n,r]=t.symbol.pins;return n&&r?{maxWidth:dc*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function Mc(e,t){return e.pins.map(e=>{let n=mc[e.side],r={x:e.end.x-n.x*lc,y:e.end.y-n.y*lc},i=n.x===0?{x:r.x+uc,y:r.y}:{x:r.x,y:r.y+uc};return{text:String(e.number),at:xc(i,t),size:.1,anchor:`center`,color:Po().pinNumber,mono:!0,kind:`pin-number`}})}function Nc(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(hc(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(Ic(a,n,r)):a.type===`polyline`&&a.bus?Pc(e,a):Fc(e,a);e.restore()}function Pc(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=Po().bus,e.fillStyle=Po().bus,Sc(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function Fc(e,t){if(t.type===`polyline`)Sc(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)Cc(e,t.center,t.radius),t.fill&&e.fill(),e.stroke();else{let n=t.end<t.start?t.end+360:t.end;e.beginPath(),e.arc(t.center.x,t.center.y,t.radius,hc(t.start),hc(n)),e.stroke()}}function Ic(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=hc(t.rotation),a=r*Math.cos(i),o=r*Math.sin(i),s=Math.abs(a)>.5?a>0?`left`:`right`:Math.abs(o)>.5?o>0?`bottom`:`top`:`center`,c={role:e.role,kind:fc[e.role],...e.role===`pin-name`?{pinOf:Lc(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:xc(e.at,t),size:e.size,anchor:s,color:Po()[pc[e.role]]??n,...c}}function Lc(e,t){let n=e.anchor===`left`?`left`:e.anchor===`right`?`right`:e.at.y>0?`top`:`bottom`;return{symbol:``,local:e.at,side:n,quarter:Math.abs(Math.sin(hc(t.rotation)))>.5}}function Rc(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function zc(e,t,n,r,i,a){e.setLineDash(i?cc:[]),e.globalAlpha=a.alpha,Bc(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function Bc(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?Ft():It(t.text);e.lineWidth=n(ec);let o=r.length;Nc(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??Po().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??Po().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Vt(t);r.push({text:t.text,at:a,size:Lt,anchor:`center`,strong:!0,kind:`name`,color:i.color??Po().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&Vc(e,t,s,n,i)}function Vc(e,t,n,r,i){e.strokeStyle=i.color??Po().netName,e.lineWidth=r(t.bus?ec*3:ec),e.beginPath(),e.moveTo(n.minX,n.minY),e.lineTo(n.maxX,n.minY),e.lineTo(n.maxX,n.maxY),e.lineTo(n.minX,n.maxY),e.closePath(),e.stroke()}function Hc(e,t,n,r,i){for(let a of t.symbols){let t=i(a);for(let[i,o]of Object.entries(a.pinEnds)){let a=n.highlight?.pins?.includes(i)??!1,s=(n.activePins?.includes(i)??!1)||a;if(!s&&!n.showPins)continue;e.fillStyle=s?Po().highlight:Po().pin;let c=a?Math.min(nc*r,Math.max(rc,ic*r)):(s?ac:1)*nc*r;Cc(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var Uc=2;function Wc(e,t){return Math.max(e,gc(t)/2+Uc)}var Gc=e=>Wc(6,e);function Kc(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function qc(e,t){let n;for(let r=1;r<e.length;r++){let i=Kc(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function Jc(e,t,n){let r=qc(e,t);return r&&r.distance<=n?r.index:void 0}function Yc(e,t,n){let r;for(let i of e){let e=qc(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function Xc(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function Zc(e,t,n){let r=e.findIndex((r,i)=>i>0&&i<e.length-1&&Math.abs(r.x-t.x)<=n&&Math.abs(r.y-t.y)<=n);return r<0?void 0:r}var Qc=1e-9,$c={x:0,y:0},el=(e,t)=>Math.abs(e-t)<Qc;function tl(e,t){return el(e.y,t.y)?`horizontal`:el(e.x,t.x)?`vertical`:`slanted`}function nl(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function rl(e,t){return e===`horizontal`?el(t.y,0):e!==`vertical`||el(t.x,0)}function il(e,t){return e.map((e,n)=>{let r=[t.get(n-1),t.get(n)].filter(e=>e!==void 0);return{x:r.find(e=>!el(e.x,0))?.x??0,y:r.find(e=>!el(e.y,0))?.y??0}})}function al(e,t,n,r){if(t===0||t===e.length-1)return!0;let i=r.has(t)?t-1:t,[a,o]=[e[i],e[i+1]];return a!==void 0&&o!==void 0&&!rl(tl(a,o),n)}function ol(e,t){let n=il(e,t);return kn(e.flatMap((r,i)=>{let a=n[i]??$c,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!al(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function sl(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?kn(e):ol(e,new Map([[t,nl(tl(r,i),n)]]))}function cl(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return kn(e);let o={x:n.x-i.x,y:n.y-i.y};return ol(e,new Map([[t-1,nl(tl(r,i),o)],[t,nl(tl(i,a),o)]]))}var ll=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function ul(e,t,n){let[r,i,a,o]=[e[0],e[1],e[e.length-2],e[e.length-1]];if(!r||!i||!a||!o)return kn(e);let s=n.start?[ll(r,t)]:[r,ll(r,nl(tl(r,i),t))],c=n.end?[ll(o,t)]:[ll(o,nl(tl(a,o),t)),o];return kn([...s,...e.slice(1,-1).map(e=>ll(e,t)),...c])}function dl(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return kn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=tl(n,r)===`horizontal`,kn(On(e.filter((e,n)=>n!==t),i))}var fl=kn,pl=`The pin of this wire has several traces to its net; change its corners in the code`,ml=1e-6;function hl(e,t){return e.slice(1).some((n,r)=>{let i=e[r],a=(n.x-i.x)*(t.y-i.y)-(n.y-i.y)*(t.x-i.x),o=Math.min(i.x,n.x)-ml<=t.x&&t.x<=Math.max(i.x,n.x)+ml&&Math.min(i.y,n.y)-ml<=t.y&&t.y<=Math.max(i.y,n.y)+ml;return Math.abs(a)<=ml&&o})}function gl(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&hl(e.points,r))}function _l(e,t,n,r){let i=vr(e,t,{pin:n.id},{net:Sr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:pl};let o=br(a)??Cr(t,a);return o===void 0?{trace:a}:{blocked:o}}function vl(e,t,n,r){let i=(e.pinLast?[...r].reverse():[...r]).slice(1),{trace:a}=e;if(!a)return[{kind:`addTrace`,from:t,to:n,schematicRouteHints:i}];let o=(a.from??``).startsWith(`net.`);return[{kind:`setTraceHints`,from:a.from??``,to:a.to??``,schematicRouteHints:o?[...i].reverse():i}]}var yl=/^wire:.+:\d+$/,bl=e=>e.startsWith(`net.`),xl=(e,t)=>e.x===t.x&&e.y===t.y,Sl=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function Cl(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function wl(e,t,n){let r=t=>bl(t)?{net:Sr(e,t)}:{pin:t};return yr(vr(e,t,r(n.from),r(n.to)).filter(t=>_r(e,t.from,r(n.from))),n.id)}function Tl(e,t,n,r,i){let a=wl(e,t,i);if(!a)return Cl(n,r,{kind:`none`,reason:`The wire is not written in a trace the Studio can find`});let o=[i.from,i.to].filter(e=>!bl(e)),s=o.map(t=>Sl(e,t)?.component??``),c=o.length===1,l=Cr(t,a);return Cl(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&bl(i.from),components:s,...l?{repeat:l}:{}})}function El(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&xl(e.pinEnds[t],n)));return r===void 0?void 0:Sl(e,r)}var Dl=(e,t)=>{let n=t.find(t=>!dr(Ln(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function Ol(e,t,n,r,i,a,o){let s=e.circuit.nets.find(e=>e.id===o)?.names[0],c=a?r[0]:r[r.length-1];if(s===void 0||!c||!gl(e,n,o,c))return;let l={pinLast:a,..._l(e,t,i,o)};return Cl(n,r,{kind:`engine`,from:Ln(e,i),to:`net.${s}`,components:[i.component],...Dl(e,[i]),onWire:l})}function kl(e,t,n,r,i){let a=e.circuit.nets.find(e=>e.id===i),[o,s]=[r[0],r[r.length-1]],[c,l]=o&&s&&a?[El(e,a.pins,o),El(e,a.pins,s)]:[];return(c&&!l?Ol(e,t,n,r,c,!1,i):!c&&l?Ol(e,t,n,r,l,!0,i):void 0)||(!c||!l?Cl(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):Cl(n,r,{kind:`engine`,from:Ln(e,c),to:Ln(e,l),components:[c.component,l.component],...Dl(e,[c,l])}))}function K(e,t,n){let r=e.schematic.wires.find(e=>e.id===n);if(!r)return;let i=r.points.map(e=>({x:e.x,y:e.y})),a=e.circuit.connections.find(e=>e.id===r.connection);return a?Tl(e,t,r.id,i,a):yl.test(r.id)?kl(e,t,r.id,i,r.net):Cl(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function q(e,t,n=gr){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=xr(e,r.components,r.kind===`trace`?r.trace:void 0,n);return i===void 0?r.kind===`engine`?r.unaddressable??r.onWire?.blocked??null:r.repeat??br(r.trace)??null:`${i} is locked`}function Al(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function jl(e,t){let[n,r]=[e[0],e[e.length-1]],[i,a]=[t.points[0],t.points[t.points.length-1]];return n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0&&xl(n,i)&&xl(r,a)}var Ml=(e,t)=>e.length===t.length&&e.every((e,n)=>xl(e,t[n]));function Nl(e,t,n,r=gr,i=t.points){let a=q(e,t,r);if(a!==null)return{blocked:a};let o=fl(n);if(!jl(o,t))return{blocked:`The ends of a wire stay on their pins`};if(Ml(o,fl(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:Al(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return vl(s.onWire,s.from,s.to,o);let c=o.slice(1,-1);return[{kind:`addTrace`,from:s.from,to:s.to,...c.length>0?{schematicRouteHints:c}:{}}]}var Pl=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});Pl(Ao);var Fl=3,Il=e=>Wc(Fl,e),Ll=[4,3],Rl=(e,t)=>{let n=Math.hypot(t.x-e.x,t.y-e.y);return{x:(t.x-e.x)/n,y:(t.y-e.y)/n}},zl=e=>({x:-e.y,y:e.x}),Bl=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function Vl(e,t,n,r,i){let a=e[n];if(n===0)return Bl(Bl(a,t[0],-r),zl(t[0]),r*i);if(n===e.length-1)return Bl(Bl(a,t[n-1],r),zl(t[n-1]),r*i);let[o,s]=[zl(t[n-1]),zl(t[n])],c=o.x*s.x+o.y*s.y;return Bl(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Hl(e,t){let n=e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y);if(n.length<2)return[];let r=n.slice(1).map((e,t)=>Rl(n[t],e)),i=e=>n.map((i,a)=>Vl(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Ul(e,t,n,r,i,a){let o=Hl(r.map(e=>B(t,n,e)),Il(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=Ko(a),e.setLineDash(Ll),e.beginPath(),o.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath(),e.stroke(),e.restore())}function Wl(e,t,n,r,i,a){let{corners:o,ends:s}=Xc(r),c=Yo(6,a),l=Ko(a),u=(r,i)=>{let o=B(t,n,r),[s,u]=[Jo(o.x-c/2,a),Jo(o.y-c/2,a)];i&&e.fillRect(s,u,c,c),e.strokeRect(s+l/2,u+l/2,c-l,c-l)};e.save(),e.fillStyle=i.handleFill,e.strokeStyle=i.selected,e.lineWidth=l,e.setLineDash([]);for(let e of o)u(e,!0);for(let e of s)u(e,!1);e.restore()}var Gl=e=>3/e,Kl=e=>Gc(e)/e;function ql(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?Zc(i,n,Gl(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function Jl(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Va({kind:`wire`,id:i},t))return ql(e,i,n,r)}function Yl(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=Jc(e,t,Kl(n));return i===void 0?void 0:{kind:`segment`,index:i}}function Xl(e,t,n,r){let i=e[t.index];if(!i)return fl(e);let a={x:Ee(i.x+n.x,r.step,r.snap),y:Ee(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?cl(e,t.index,a):sl(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function Zl(e,t,n,r){let i=e?.points(t);if(e&&i)return{kind:`reshape`,wire:t,grip:n,points:i,path:i,start:r,moved:!1,blocker:e.blocker(t)}}function Ql(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:Xl(e.points,e.grip,t,n)}}var $l=`The wire changed while you dragged it; try again`;function eu(e,t,n){if(!e||!t.moved||t.blocker||Ml(t.path,fl(t.points)))return;let r=e.points(t.wire);if(!r||!Ml(r,t.points))return n($l);e.commit(t.wire,t.path)}function tu(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function nu(e,t){return t.length===0?e:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,points:[...n.points]}:e})}var ru=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function iu(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var au=2,ou=(e,t)=>Math.max(6,e*t/2+au)/t;function su(e,t,n,r,i){let a=e.find(e=>iu({kind:`via`,...ru(e)},r)&&Va({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=ou(e.diameter,n));return a&&{kind:`via`,id:a.id}}function cu(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,Kc(t,e[r-1],e[r]));return n}function lu(e,t,n,r,i){let a;for(let o of e){if(!iu({kind:`track`,layer:o.layer,...ru(o)},r)||!Va({kind:`track`,id:o.id},i))continue;let e=cu(o.points,t);e<=ou(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function uu(e,t,n,r,i){return su(e.vias,t,n,r,i)??lu(e.tracks,t,n,r,i)}function du(e,t,n,r,i){let a=uu(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&Jc(o.points,t,ou(o.width,n));return o&&s!==void 0?po(o,s):void 0}function fu(e,t,n,r,i=0){let a=r?Zc(e,t,Gl(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=Jc(e,t,ou(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var pu=(e,t)=>{let n=e.map(e=>e.x),r=e.map(e=>e.y),i=e=>V(e);return{minX:i(Math.min(...n)-t),minY:i(Math.min(...r)-t),maxX:i(Math.max(...n)+t),maxY:i(Math.max(...r)+t)}};function mu(e,t){let n=e.tracks.filter(e=>iu({kind:`track`,layer:e.layer,...ru(e)},t)),r=e.vias.filter(e=>iu({kind:`via`,...ru(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:pu(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:pu([e.at],e.diameter/2)}))]}function hu(e,t,n,r){let i=new Set($a(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var gu=.4,_u=.7,vu=1.5,yu={top:W.topCopper,bottom:W.bottomCopper,inner1:W.topCopper,inner2:W.topCopper},bu=e=>e.missingLayer===void 0?yu[e.layer]:W.keepout,xu=e=>e.missingLayer===void 0?W.viaRing:W.keepout,Su=(e,t)=>iu({kind:`track`,layer:e.layer,...ru(e)},t),Cu=(e,t)=>iu({kind:`via`,...ru(e)},t),wu=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?va:1;function Tu(e,t,n,r){e.strokeStyle=n,e.lineWidth=r,e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke()}function Eu(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2),e.fill()}function Du(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>Su(e,n)),o=e=>e.layer===i||e.missingLayer!==void 0,s=[...a.filter(e=>!o(e)),...a.filter(o)];for(let t of s)e.globalAlpha=(o(t)?1:gu)*wu(r,t.net),Tu(e,t.points,bu(t),t.width);e.globalAlpha=1}function Ou(e,t,n,r){for(let i of t.vias.filter(e=>Cu(e,n)))e.globalAlpha=wu(r,i.net),Eu(e,i.at,i.diameter/2,xu(i)),n.hole&&Eu(e,i.at,i.drill/2,W.drill);e.globalAlpha=1}function ku(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)iu({kind:`track`,layer:t.layer},n)&&Tu(e,t.points,yu[t.layer],t.width);if(iu({kind:`via`},n))for(let t of r.vias)Eu(e,t.at,t.diameter/2,W.viaRing),n.hole&&Eu(e,t.at,t.drill/2,W.drill)}e.globalAlpha=1}function Au(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&mo(r,t.points)?[r.from,r.to]:t.points}function ju(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&Su(s,n)){let n=Au(t,s,a);Tu(e,n,i,s.width+2*vu*o),Tu(e,n,bu(s),s.width),a&&Tu(e,n,W.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&Cu(c,n)&&(Eu(e,c.at,c.diameter/2+vu*o,i),Eu(e,c.at,c.diameter/2,xu(c)),a&&Eu(e,c.at,c.diameter/2,W.selectionFill),n.hole&&Eu(e,c.at,c.drill/2,W.drill))}function Mu(e,t,n,r,i){Du(e,t,n,r),Ou(e,t,n,r),ku(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&ju(e,t,n,t.hover,W.hover,!1,i);for(let r of t.selected)ju(e,t,n,r,W.selection,!0,i)}var Nu=e=>e.pcb.board?.pours??[];function Pu(e,t){return e.outline??t?.outline??[]}function Fu(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var Iu=(e,t)=>`pour ${Fu(e,t.net)} · ${t.layer}`,Lu=e=>`${Number(e.toFixed(4))} mm`,Ru=e=>`hole ${Lu(e.diameter)}`;function zu(e,t,n){return n.has(e.id)?!1:e.layer===`top`||e.layer===`bottom`?t[e.layer]:e.layer===`inner1`||e.layer===`inner2`}function Bu(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function Vu(e,t,n,r,i){let a=6/n,o;for(let n of Nu(e))if(zu(n,r,i))for(let[r,i]of Bu(Pu(n,e.pcb.board))){let e=Kc(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Hu(e,t,n){let r=7/n,i=e.findIndex(e=>Math.hypot(e.x-t.x,e.y-t.y)<=r);return i===-1?void 0:i}function Uu(e,t,n,r){if(!r.hole)return;let i=3/n;return e.find(e=>Math.hypot(e.x-t.x,e.y-t.y)<=e.diameter/2+i)?.id}function Wu(e,t){let n=!1;for(let[r,i]of Bu(t))r.y>e.y!=i.y>e.y&&e.x<(i.x-r.x)*(e.y-r.y)/(i.y-r.y)+r.x&&(n=!n);return n}function Gu(e,t){return e.polygons.some(e=>Wu(t,e.outer)&&!e.holes.some(e=>Wu(t,e)))}function Ku(e,t,n,r,i){let a=e.pcb.pours.filter(e=>zu(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Gu(e,t))?.id}function qu(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=Nu(e).find(e=>e.id===t),i=r?Pu(r,e.pcb.board):[];if(i.length===0)return;let a=i.map(e=>e.x),o=i.map(e=>e.y);return{x:(Math.min(...a)+Math.max(...a))/2,y:(Math.min(...o)+Math.max(...o))/2}}var Ju=[`solid`,`hatched`,`outline`],Yu=`solid`,Xu=`copperflow.pourFill`,Zu=.35,Qu=e=>Ju.includes(e);function $u(e){try{let t=e()?.getItem(Xu);return Qu(t)?t:Yu}catch{return Yu}}function ed(e,t){try{let n=e();return n?(n.setItem(Xu,t),!0):!1}catch{return!1}}function td(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var nd={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},rd={top:W.topCopper,bottom:W.bottomCopper,inner1:W.inner1Copper,inner2:W.inner2Copper},id=rd,ad=.5,od=6,sd=1,cd=1.5;function ld(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function ud(e,t){fd()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){ld(e,n.outer);for(let t of n.holes)ld(e,t)}}function J(e,t=0){let n=e.polygons.flatMap(e=>e.outer);if(n.length===0)return[];let r=n.map(e=>e.x),i=n.map(e=>e.y),[a,o,s,c]=[Math.min(...r),Math.max(...r),Math.min(...i),Math.max(...i)],l=c-s,u=a-l,d=o-u,f=Math.max(ad,6*t,d/399),p=Math.floor(d/f+1e-9)+1;return Array.from({length:p},(e,t)=>[{x:u+t*f,y:s},{x:u+t*f+l,y:c}])}var dd=new WeakMap,fd=()=>typeof Path2D==`function`;function pd(e){let t=dd.get(e);if(t)return t;let n={};return dd.set(e,n),n}function md(e){if(!fd())return;let t=pd(e);return t.rings||(t.rings=new Path2D,ud(t.rings,e)),t.rings}function hd(e,t){if(!fd())return;let n=pd(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of J(e,t))r.moveTo(n.x,n.y),r.lineTo(i.x,i.y);n.hatch={px:t,path:r}}return n.hatch.path}function gd(e,t,n){e.lineWidth=n;let r=md(t);if(r)return e.stroke(r);ud(e,t),e.stroke()}function _d(e,t,n){let r=md(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);ud(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function vd(e,t,n){let r=hd(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of J(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function yd(e,t,n,r){let i=id[t.layer]??W.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,gd(e,t,sd*r);else{if(e.globalAlpha=Zu,n===`solid`)return _d(e,t,`fill`);e.save(),_d(e,t,`clip`),e.lineWidth=sd*r,e.globalAlpha=1,vd(e,t,r),e.restore(),e.globalAlpha=1,gd(e,t,sd*r)}}function bd(e,t,n,r,i){let a=(t.pours??[]).filter(e=>zu(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)yd(e,t,n.mode,i);e.globalAlpha=1}function xd(e,t,n){let r=n/2;e.beginPath(),e.moveTo(t.x-r,t.y-r),e.lineTo(t.x+r,t.y-r),e.lineTo(t.x+r,t.y+r),e.lineTo(t.x-r,t.y+r),e.closePath()}function Sd(e,t,n,r){if(e.strokeStyle=W.selection,e.lineWidth=cd*r,e.beginPath(),ld(e,t),e.stroke(),n){e.fillStyle=W.selection;for(let n of t)xd(e,n,od*r),e.fill()}}function Cd(e,t,n,r,i,a){if(r.selected.has(t.id))return Sd(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?W.hover:id[t.layer]??W.topCopper,e.lineWidth=Math.max(a,sd*i),e.setLineDash([4*i,3*i]),e.beginPath(),ld(e,n),e.stroke(),e.setLineDash([]))}function wd(e,t,n){t.length<2||(e.strokeStyle=W.selection,e.lineWidth=sd*n,e.setLineDash([4*n,3*n]),e.beginPath(),ld(e,t),e.stroke(),e.setLineDash([]))}function Td(e,t,n,r,i,a){for(let o of t.board?.pours??[])zu(o,r,n.hidden)&&Cd(e,o,n.outlines?.get(o.id)??Pu(o,t.board),n,i,a);n.preview&&wd(e,n.preview,i)}function Ed(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=W.drill,e.beginPath(),e.arc(r.x,r.y,t,0,Math.PI*2),e.fill();let o=n.selected.has(r.id);e.strokeStyle=o?W.selection:n.hover===r.id?W.hover:W.multiLayer,e.lineWidth=o?cd*i:a,e.stroke()}}var Y=(e,t=!1)=>({action:e,preventDefault:t}),Dd=new Map([[`ArrowLeft`,{action:`nudgeLeft`,dx:-1,dy:0}],[`ArrowRight`,{action:`nudgeRight`,dx:1,dy:0}],[`ArrowUp`,{action:`nudgeUp`,dx:0,dy:1}],[`ArrowDown`,{action:`nudgeDown`,dx:0,dy:-1}]]);function Od(e){for(let t of Dd.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function kd(e){let t=Dd.get(e.key);return!t||e.onButton||e.ctrlKey||e.metaKey||e.altKey?null:{action:t.action,preventDefault:!0,steps:e.shiftKey?10:1}}var Ad=`tr, [role='row'], [role='gridcell'], [role='grid'], [role='listbox'], [role='option'], [role='tree'], [role='treeitem'], [role='tablist'], [role='tab'], [role='radiogroup'], [role='menu'], [role='menubar'], [role='menuitem'], [role='menuitemcheckbox'], [data-keys='own']`,jd=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,Md=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,Nd=`[data-keys='parts']`;function Pd(e){let t=e.target instanceof HTMLElement?e.target:null;return{key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,altGraph:e.getModifierState?.(`AltGraph`)??!1,typing:t?.closest(jd)!=null,onButton:t?.closest(Md)!=null,ownsKeys:t?.closest(Ad)!=null,partRows:t?.closest(Nd)!=null,handled:e.defaultPrevented}}var Fd=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),Id=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),Ld=new Map([[`w`,`route`],[`v`,`placeVia`]]);function Rd(e,t){if(e.shiftKey)return null;let n=Fd(e);if(n===`s`)return Y(`toggleSnap`,!0);let r=(t.view===`schematic`?Id:Ld).get(n);return r?Y(r,!0):null}function zd(e,t,n){switch(e){case`w`:return Y(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?Y(`switchLayer`,!0):null;case`r`:return Y(`rotate`);case`k`:return Y(`fit`);case`f`:return t.shiftKey?Y(`openLibrary`,!0):Y(`fit`);case`h`:return t.shiftKey?Y(`clearHighlight`):Y(`highlight`);case`q`:return n.view===`pcb`?Y(`toggleUnit`):null;case`u`:return n.view===`pcb`?Y(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?Y(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?Y(`flip`,!0):null;default:return null}}var Bd=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),Vd=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),Hd=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Ud=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Wd(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Ud:Hd).get(e.key.toLowerCase());return t?Y(t,t!==`copy`):null}function Gd(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?Y(`removeCorner`,!0):null:Y(`delete`)}var Kd=e=>e.key===`Delete`||e.key===`Backspace`,qd=e=>e.ownsKeys===!0&&!(e.partRows===!0&&Kd(e)),Jd=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function Yd(e,t){if(e.typing)return null;if(Jd(e))return Y(`contextMenu`,!0);let n=Bd.get(e.key);return n&&Vd(e)?Y(n):e.ctrlKey||e.metaKey?Wd(e):e.altKey?Rd(e,t):e.handled||qd(e)?null:kd(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?Y(`finishShape`,!0):null:Kd(e)?Gd(e,t):e.key===` `?e.onButton?null:Y(t.drawing?`flipBend`:`rotate`,!0):zd(e.key.toLowerCase(),e,t))}function Xd(e){return e.key===`Escape`&&!e.typing}var Zd=e=>Dt(e)+0,Qd=e=>Math.round((e%360+360)%360/90)%4;function $d(e,t){switch(Qd(t)){case 1:return{x:Zd(-e.y),y:Zd(e.x)};case 2:return{x:Zd(-e.x),y:Zd(-e.y)};case 3:return{x:Zd(e.y),y:Zd(-e.x)};default:return{x:Zd(e.x),y:Zd(e.y)}}}function ef(e,t){let n=$d(e,t.rotation);return{x:Zd(t.x+n.x),y:Zd(t.y+n.y)}}var tf={reference:`schNameAt`,value:`schValueAt`},nf=(e,t)=>`${e}:${t}`;function rf(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function af(e,t,n){let r=Et*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function of(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=ef(t.at,e),r=tf[t.role],i={x:Zd(n.x-e.x),y:Zd(n.y-e.y)};return[{id:nf(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:af(n,t.size,t.text.length)}]})}var sf=.8,cf={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},lf={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function uf(e){let t=rf(e)?.prop;if(t!==void 0)return cf.schematic.includes(t)?`schematic`:cf.pcb.includes(t)?`pcb`:void 0}function df(e){return e.symbols.flatMap(e=>of(e))}function ff(e){let t=ha(e),n={x:t.x-e.x,y:t.y-e.y},r=ga(e),i=af(t,sf,e.component.length),[a,o]=[(i.maxX-i.minX)/2,(i.maxY-i.minY)/2],s=r===90?{minX:t.x-o,maxX:t.x+o,minY:t.y-a,maxY:t.y+a}:i;return{id:nf(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:s,rotation:r}}function pf(e){return e.parts.map(ff)}function mf(e,t){return e===`pcb`?pf(t.pcb):df(t.schematic)}var hf=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,gf=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function _f(e,t){return e.filter(e=>hf(e.box,t)).sort((e,t)=>gf(e.box)-gf(t.box))[0]}function vf(e,t){let n=t.x-e.at.x,r=t.y-e.at.y,{box:i}=e;return{...e,at:t,offset:{x:e.offset.x+n,y:e.offset.y+r},box:{minX:i.minX+n,maxX:i.maxX+n,minY:i.minY+r,maxY:i.maxY+r}}}function yf(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?vf(e,n.at):e})}function bf(e,t){let n={x:e.at.x-e.offset.x,y:e.at.y-e.offset.y},r={x:V(t.x-n.x),y:V(t.y-n.y)};return V(e.offset.x)===r.x&&V(e.offset.y)===r.y?[]:[{kind:`setProps`,part:e.part,props:{[e.prop]:r}}]}function xf(e){let t=rf(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function Sf(e,t){let n=rf(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}var Cf=(e,t)=>e.model.parts.find(e=>e.name===t)?.props.pcbNameRotation!==void 0;function wf(e,t,n){let r=rf(n),i=r&&e.model.parts.find(e=>e.name===r.part);if(!r||!i)return`This part has no editable source element`;if(t.has(i.name))return`${i.name} is locked`;if(!i.editable)return`${i.name} is read-only (${i.readonlyReason})`;let a=i.props[r.prop];return a&&!a.editable?`${i.name}.${r.prop} is an expression; change it in the code`:null}function Tf(e,t,n,r){let i=Af(e,t,n,r);return i?i.blocker??(i.moved?null:`It is where the layout puts it`):`It is not on this sheet`}function Ef(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=$d({x:n.x-e.x,y:n.y-e.y},-e.rotation),a=e.symbol.shapes.map(e=>e.type===`text`&&e.role===r?{...e,at:i,anchor:`center`}:e);return{...e,symbol:{...e.symbol,shapes:a}}}function Df(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=rf(n.id);return r?.part===e.component?Ef(t,r.prop,n.at):t},e));return{...e,symbols:n}}function Of(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===nf(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var kf=e=>String(V(e));function Af(e,t,n,r){let i=uf(n),a=i&&mf(i,e).find(e=>e.id===n);if(!i||!a)return;let o=Sf(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${kf(a.offset.x)}${s}`},{label:`Offset Y`,value:`${kf(a.offset.y)}${s}`},{label:`Position`,value:o?`Moved (${a.prop})`:`Where the layout puts it`},...a.rotation===void 0?[]:[{label:`Turn`,value:`${a.rotation}°${Cf(t,a.part)?` (pcbNameRotation)`:``}`}]];return{title:lf[a.prop]??a.prop,rows:c,moved:o,blocker:wf(t,r,n)}}function jf(e,t,n){let r=e.soleText,i=Od(t.action);if(r!==void 0&&i)return{id:r,by:pt(i,n.step,t.steps??1,n.snap!==!1)}}var Mf={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},Nf={x:0,y:0},Pf=1.5,Ff=.35,If=1.5,Lf=.6,Rf=.12,zf=1.5,Bf=.7,Vf=.5,Hf=1e-9,Uf=.25,Wf=.6,Gf=e=>e*Math.PI/180,Kf=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],qf=e=>e.autoPlaced?Wf:1,Jf=e=>e.side===`top`?W.topAssembly:W.bottomAssembly;function Yf(e,t,n,r){let i={...ka,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=Zo(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:Nf,u=n=>{for(let r of t.parts)ep(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=qf(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...Qf(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&op(e,t,s,c);let d=r.pours??Mf;bd(e,t,d,i,s),up(e,i,r.highlight,u,s),r.copper&&Mu(e,r.copper,i,r.highlight,s),i.hole&&fp(e,u),Ed(e,t.holes??[],d,i,s,c),Td(e,t,d,i,s,c),u(t=>{Kf(i,t,`Silk`)&&pp(e,t.silkscreen,t.side===`top`?W.topSilk:W.bottomSilk,Math.max(Rf,c),!1)}),i.courtyard&&mp(e,u,s,c),u(t=>{Kf(i,t,`Assembly`)&&pp(e,t.fabrication,Jf(t),c,!1)}),i.boardOutline&&ap(e,t,()=>{e.strokeStyle=W.boardEdge,e.lineWidth=zf*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&hp(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),cs(e);for(let n of t.parts)Kf(i,n,`Silk`)&&_p(e,n,a,o,l(n),r.ratio);Do(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function Xf(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[Na(e)])&&yp(e,t));if(e)return e}}function Zf(e){return e.parts.map(e=>{let t=$f(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function Qf({camera:e,size:t},n){let r=e.scale*n;return[r,0,0,-r,(t.width/2-e.cx*e.scale)*n,(t.height/2+e.cy*e.scale)*n]}function $f(e){let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function ep(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(Gf(r)),i(),e.restore()}function tp(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function np(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function rp(e,t,n,r){let i=Math.max(0,Math.min(r,t/2,n/2)),a=-t/2,o=-n/2;e.beginPath(),e.moveTo(a+i,o),e.arcTo(a+t,o,a+t,o+n,i),e.arcTo(a+t,o+n,a,o+n,i),e.arcTo(a,o+n,a,o,i),e.arcTo(a,o,a+t,o,i),e.closePath()}var ip=(e,t,n)=>rp(e,t,n,Math.min(t,n)/2);function ap(e,t,n){let r=t.board?.outline;!r||r.length<3||(tp(e,r),n())}function op(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=W.keepout,e.globalAlpha=Bf;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),tp(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),tp(e,t.outline),e.clip();for(let[n,r]of sp(t.outline))gp(e,n,r);e.restore()}e.globalAlpha=1}}function sp(e){let t=e.map(e=>e.x),n=e.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)];if(![r,i,a,o].every(Number.isFinite))return[];let s=o-a,c=r-s,l=i-c,u=Math.max(Vf,l/399),d=Math.floor(l/u+Hf)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function cp(e,t){ep(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?np(e,0,0,t.width/2):t.shape===`oval`?ip(e,t.width,t.height):rp(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??Uf*Math.min(t.width,t.height):0)})}function lp(e){return e.layers===`through`?W.multiLayer:e.layers===`bottom`?W.bottomCopper:W.topCopper}function up(e,t,n,r,i){let a=[[t.bottom,e=>e.layers===`bottom`],[t.top,e=>e.layers===`top`],[t.multiLayer,e=>e.layers===`through`]];for(let[t,o]of a)t&&r(t=>{for(let r of t.pads.filter(o)){let a=n!==void 0&&r.net!==void 0&&n.nets.includes(r.net);e.globalAlpha=(n&&!a?va:1)*qf(t),e.fillStyle=lp(r),cp(e,r),e.fill(),a&&dp(e,r,i,qf(t))}});e.globalAlpha=1}function dp(e,t,n,r){e.globalAlpha=Ff*r,e.fillStyle=W.highlight,cp(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=W.highlight,e.lineWidth=If*n,e.stroke()}function fp(e,t){e.fillStyle=W.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?np(e,n.x,n.y,t.width/2):ep(e,n.x,n.y,n.rotation,()=>ip(e,t.width,t.height)),e.fill())}})}function pp(e,t,n,r,i){e.strokeStyle=n,e.lineWidth=r;for(let n of t)n.length<2||(e.beginPath(),n.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),i&&e.closePath(),e.stroke())}function mp(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,pp(e,[t.courtyard],Jf(t),t.autoPlaced?Pf*n:r,!0)}),e.setLineDash([])}function hp(e,t,n,r){let i=n.moving,a=new Set(t.parts.filter(e=>i?.components.includes(e.component)).flatMap(e=>e.pads.map(e=>e.id))),o=(e,t)=>i&&a.has(t)?{x:e.x+i.by.x,y:e.y+i.by.y}:e;e.lineWidth=r;for(let r of t.ratsnest){let t=n.highlight?.nets.includes(r.net)??!1;e.strokeStyle=t?W.highlight:W.ratsnest,e.globalAlpha=t?1:n.highlight?Lf*va:Lf,gp(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function gp(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function _p(e,t,n,r,i,a){let o=is(sf,n.scale,a);if(!rs(`name`,o,o))return;let s=ha(t),c=ss(B(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?W.topSilk:W.bottomSilk,e.globalAlpha=qf(t),e.font=Sa(xa.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,ga(t)===90?(e.save(),e.translate(c.x,c.y),e.rotate(-Math.PI/2),e.fillText(t.component,0,0),e.restore()):e.fillText(t.component,c.x,c.y),e.globalAlpha=1}function vp(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[Na(e)])continue;let a=xp(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var yp=(e,t)=>xp(e,t)<=0;function bp(e,t){let n=Gf(-e.rotation),r=t.x-e.x,i=t.y-e.y;return{x:r*Math.cos(n)-i*Math.sin(n),y:r*Math.sin(n)+i*Math.cos(n)}}function xp(e,t){let{x:n,y:r}=bp(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?Sp(n,r,e.width,e.height):Math.hypot(Math.max(0,Math.abs(n)-e.width/2),Math.max(0,Math.abs(r)-e.height/2))}function Sp(e,t,n,r){let i=Math.min(n,r)/2,a=Math.max(n,r)/2-i,[o,s]=n>=r?[Math.max(-a,Math.min(a,e)),0]:[0,Math.max(-a,Math.min(a,t))];return Math.max(0,Math.hypot(e-o,t-s)-i)}function Cp(e,t,n){let r=Yc(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function wp(e,t,n){let r=Jn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=Ar(e,t)?.net??Cp(e,t,n);return i===void 0?void 0:Tp(e.circuit.nets,i)}function Tp(e,t){if(e.some(e=>e.id===t))return t;let n=t.startsWith(`net.`)?t.slice(4):void 0;return e.find(e=>n!==void 0&&e.names.includes(n))?.id??t}var Ep=[];function Dp(e,t){let n=t.flatMap(t=>e.circuit.nets.filter(e=>e.id===t)),r=n[0];if(!r)return;let i=[...new Set(n.flatMap(e=>e.pins))],a=[...new Set(n.flatMap(e=>[e.id,...e.names.map(e=>`net.${e}`)]))];return{net:r.id,pins:i,aliases:a}}function Op(e,t){let n=(e.circuit.components.find(e=>e.id===t)?.pins??[]).flatMap(t=>e.circuit.nets.filter(e=>e.pins.includes(t.id)).map(e=>e.id));return[...new Set(n)]}function kp(e,t){if(e.length===0)return{message:`Point at a net and press H.`};let n=[...new Set(e.flatMap(t))];return n.length>0?{nets:n}:{message:`${H(e)} ${e.length===1?`is`:`are`} on no net.`}}function Ap(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=kp(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function jp(e,t,n){if(n.circuit.nets.some(t=>t.id===e))return e;let r=t?.circuit.nets.find(t=>t.id===e)?.pins[0];return r!==void 0&&n.circuit.nets.find(e=>e.pins.includes(r))?.id||void 0}function Mp(e,t,n){let r=[...new Set(e.flatMap(e=>jp(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?Ep:r}function Np(e,t,n){return Xf(e,t,n)?.net??void 0}var Pp=e=>e.startsWith(`drawing:`)||e.includes(`~`),Fp=e=>JSON.stringify({...e,source:void 0}),Ip=(e,t)=>e.filter(e=>e.kind===t).length,Lp=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function Rp(e,t,n,r){return!Pp(t.id)&&!Lp(t.id,n)&&!Lp(t.id,r)?!0:e.kind===t.kind?Ip(n,t.kind)===Ip(r,t.kind)||Fp(e)===Fp(t):!1}function zp(e,t){let n=new Map((e??[]).map(e=>[e.id,e]));return t.flatMap(r=>{let i=n.get(r.id);return!e||!i||Rp(i,r,e,t)?[r.id]:[]})}function Bp(e,t,n){let r=e=>n.some(t=>t.id===e.to);return{selection:t.filter(r).reduce((e,{from:t,to:n})=>e.hasDrawing(t)?e.withoutDrawings([t]).addDrawings([n]):e,e),waiting:t.filter(e=>!r(e))}}function Vp(e,t,n){return e.drawingCount===0?e:e.keepDrawings(zp(t,n))}var Hp=/^[ADPF]?GND\w*$|^VSS\w*$/i,Up=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,Wp=new Intl.Collator(`en`,{numeric:!0});function Gp(e){return Hp.test(e)?`ground`:Up.test(e)?`power`:void 0}function Kp(e){for(let t of e){let e=Gp(t);if(e)return e}}var qp=e=>e.find(e=>Gp(e))??e[0];function Jp(e){return qp(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function Yp(e){if(e.length===void 0)return``;let t=e.partner===void 0?``:`, pair ${e.partner}${e.skew===void 0?``:`, skew ${e.skew.toFixed(1)} mm`}`;return`${e.length.toFixed(1)} mm${t}`}function Xp(e){let t=new Map((e.lines??[]).map(e=>[e.net,e])),n=new Map(e.circuit.nets.map(e=>[e.id,e]));return e.circuit.nets.map(e=>{let r=qp(e.names),i=Kp(e.names),a=t.get(e.id),o=a?.partner===void 0?void 0:n.get(a.partner);return{id:e.id,label:Jp(e),pins:e.pins.length,named:r!==void 0,...i?{badge:i}:{},...a?{length:a.length}:{},...o?{partner:Jp(o)}:{},...a?.skew===void 0?{}:{skew:a.skew}}}).sort((e,t)=>Number(t.named)-Number(e.named)||Wp.compare(e.label,t.label))}function Zp(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Nr(e,s);t?.wire!==void 0&&(r.includes(t.wire)||n(t.part))?i.set(t.wire,s):t&&t.wire===void 0&&n(t.part)?a.push(s):o.push(s)}return{riding:i,onPins:a,alone:o}}var Qp=(e,t)=>e.schematic.labels.find(e=>e.id===t);function $p(e,t){let n=e?Fr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function em(e,t,n,r,i,a){let o=Qp(e,n),s={edits:[],shown:[],names:[],notes:[]};if(!o)return s;let c={x:V(o.at.x+r.x),y:V(o.at.y+r.y)},l=Kr(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[$p(o,l.blocked)]};let u=l.length>0?Vr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[Fr(o)],notes:[]}:s}function tm(e,t,n,r,i,a){let o=n.map(n=>em(e,t,n,r,i,a));return{edits:o.flatMap(e=>e.edits),shown:o.flatMap(e=>e.shown),names:o.flatMap(e=>e.names),notes:o.flatMap(e=>e.notes)}}function nm(e,t){return t.flatMap(t=>{let n=Qp(e,t);return n?[Fr(n)]:[]})}var rm=e=>e.length>1?[`${e.length} labels`]:[...e];function im(e,t,n,r){if(r.has(e))return e;let i=t&&Pr(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Pr(n,e.id)===i)?.id}function am(e,t,n){if(e.labelCount===0)return e;let r=new Set(n.schematic.labels.map(e=>e.id)),i=e.labels.flatMap(e=>im(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var om=(e,t)=>e.slice(`label:${t}:`.length);function sm(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Nr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:$p(r,`Studio places it on ${om(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function cm(e,t,n){let r=t.map(t=>sm(e,t,n));return{withWires:r.flatMap(e=>e.kind===`wire`?[{label:e.label,wire:e.wire}]:[]),withParts:r.flatMap(e=>e.kind===`part`?[e.label]:[]),skipped:r.flatMap(e=>e.kind===`skipped`?[e.reason]:[])}}function lm(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=Tp(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Nr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?Jp(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var um=e=>`${e.x},${e.y}`;function dm(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[um(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(um(n)),t.get(um(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var fm=(e,t)=>e.x===t.x&&e.y===t.y;function pm(e,t){if(e.ends&&t.ends)return e.ends.length===t.ends.length&&e.ends.every(e=>t.ends?.includes(e));let[n,r,i,a]=[e.points[0],e.points[e.points.length-1],t.points[0],t.points[t.points.length-1]];return!n||!r||!i||!a?!1:fm(n,i)&&fm(r,a)||fm(n,a)&&fm(r,i)}function mm(e,t,n){let r=n.find(t=>t.id===e),i=t?.find(t=>t.id===e);return!r||r.connection===void 0&&i!==void 0&&!pm(i,r)}function hm(e,t,n){return e.withoutWires(e.wires.filter(e=>mm(e,t,n)))}function gm(e,t){let n=t.parts?e.keep(t.parts):e,r=t.view===`schematic`,i=e=>r?e??[]:[],a=r?[]:t.copper??[],o=r?[]:t.board??[];return n.keepWires(i(t.wires)).keepLabels(i(t.labels)).keepDrawings(i(t.drawings)).keepCopper(a).keepTexts(t.texts??[]).keepBoard(o)}var _m=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],vm=`bottom-panel`,ym=e=>`bottom-tab-${e}`,bm={open:!1,tab:`drc`};function xm(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Sm(e){return{...e,open:!e.open}}function Cm(e,t){return{open:!0,tab:t}}function wm(e){return e.detail>0}var Tm=`button, input[type='checkbox']`;function Em(e){e.target instanceof HTMLElement&&e.target.closest(Tm)?.blur()}function Dm(e,t,n){return t>0||e===`checkbox`&&!n}function Om(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function km(e){let t=e.target instanceof HTMLElement?e.target.closest(Tm):null;t&&Dm(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var Am=new Set([`ArrowLeft`,`ArrowUp`]),jm=new Set([`ArrowRight`,`ArrowDown`]);function Mm(e,t,n){if(e.length===0)return null;if(n===`Home`)return e[0]??null;if(n===`End`)return e[e.length-1]??null;let r=Am.has(n)?-1:+!!jm.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function Nm({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=Mm(e,t,r.key);i!==null&&(r.preventDefault(),r.stopPropagation(),n(i),r.currentTarget.querySelector(`[data-tab="${i}"]`)?.focus())},tab:e=>({"data-tab":e,tabIndex:e===t?0:-1,onClick:t=>{if(!wm(t))return n(e);Em(t),(r??n)(e)}})}}var Pm=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Fm=o(((e,t)=>{t.exports=Pm()})),X=Fm(),Im=_m.map(e=>e.id);function Lm({state:e,onClick:t,onOpen:n}){let r=Nm({ids:Im,current:e.tab,onSelect:n,onPointerClick:t});return(0,X.jsx)(`nav`,{className:`bottom-strip hairline-t`,role:`tablist`,"aria-label":`Bottom panel`,onKeyDown:r.onKeyDown,children:_m.map(t=>{let n=e.open&&e.tab===t.id;return(0,X.jsx)(`button`,{role:`tab`,id:ym(t.id),"aria-controls":vm,className:`bottom-tab${n?` on`:``}`,"aria-selected":n,...r.tab(t.id),children:(0,X.jsx)(`span`,{className:`bottom-tab-label`,children:t.label})},t.id)})})}function Rm(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function zm(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(Rm(e.devicePixelRatio)))t.style.setProperty(n,r);n?.removeEventListener(`change`,r),n=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),n.addEventListener(`change`,r)};return r(),e.addEventListener(`resize`,r),()=>{e.removeEventListener(`resize`,r),n?.removeEventListener(`change`,r)}}var Z=(e,t)=>t?{tag:`path`,d:e,dash:t}:{tag:`path`,d:e},Bm=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},Vm=(e,t,n,r,i=1,a)=>a?{tag:`rect`,x:e,y:t,width:n,height:r,rx:i,fill:a}:{tag:`rect`,x:e,y:t,width:n,height:r,rx:i},Hm=Z(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),Um=[Vm(3,7,10,7,1.5),Z(`M8 10v1.5`)],Wm=[4,8,12].flatMap(e=>[4,8,12].map(t=>Bm(t,e,1,!0))),Gm={lock:[...Um,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[...Um,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[Vm(2.5,7,11,7.5,1.5),Z(`M5 7V5a3 3 0 0 1 6 0v2`),Z(`M8 10v2`)],padlockOpen:[Vm(2.5,7,11,7.5,1.5),Z(`M11 7V4a3 3 0 0 0-6 0v.5`),Z(`M8 10v2`)],trash:[Z(`M2.5 4.5h11M6 4.5V2.5h4v2`),Z(`M4 4.5l.5 9h7l.5-9`),Z(`M6.5 7v4M9.5 7v4`)],close:[Z(`M4 4l8 8M12 4l-8 8`)],chevron:[Z(`M6 4l4 4-4 4`)],eye:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),Bm(8,8,2)],eyeOff:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),Bm(8,8,2),Z(`M2.5 2.5l11 11`)],undo:[Z(`M5.5 3 3 5.5 5.5 8`),Z(`M3 5.5h6.5a3.5 3.5 0 0 1 0 7h-3`)],redo:[Z(`M10.5 3 13 5.5 10.5 8`),Z(`M13 5.5H6.5a3.5 3.5 0 0 0 0 7h3`)],zoomIn:[Bm(7,7,4.5),Z(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[Bm(7,7,4.5),Z(`M10.5 10.5 14 14M5 7h4`)],fit:[Hm,Vm(6,6,4,4,.5)],fitSelection:[Hm,Vm(5.5,5.5,5,5,1,!0)],fitArea:[Vm(2.5,2.5,8,8,1),Z(`M7 7l6.5 6.5M13.5 9.5v4h-4`)].map(e=>e.tag===`rect`?{...e,dash:`2 2`}:e),grid:Wm,snap:[Z(`M3.5 2.5V8a4.5 4.5 0 0 0 9 0V2.5h-3V8a1.5 1.5 0 0 1-3 0V2.5z`),Z(`M3.5 5h3M9.5 5h3`)],component:[Vm(4.5,3,7,10,1),Z(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[Bm(3.5,12.5,1.5),Bm(12.5,3.5,1.5),Z(`M5 12.5h3.5v-9H11`)],netLabel:[Z(`M1.5 8h2`),Z(`M5.5 4.5h8v7h-8L3.5 8z`),Z(`M8 8h3`)],bus:[Z(`M2 10.5h12`,void 0),Z(`M5.5 10.5l2-4.5M9.5 10.5l2-4.5`)],polyline:[Z(`M2 13l3.5-7 4 4 4.5-7`)],arc:[Z(`M3 12a5 5 0 0 1 10 0`)],circle:[Bm(8,8,5.5)],rectangle:[Vm(2.5,4.5,11,7,0)],text:[Z(`M3.5 4.5V3h9v1.5M8 3v10M6 13h4`)],ground:[Z(`M8 2.5v6M3 8.5h10M5 11h6M7 13.5h2`)],power:[Z(`M8 14V5.5M3.5 5.5h9`),Z(`M3.5 5.5 8 2l4.5 3.5`)],noConnect:[Z(`M2 8h5`),Z(`M9 5.5l5 5M14 5.5l-5 5`)],via:[Bm(8,8,5.5),Bm(8,8,2)],boardOutline:[Z(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[Vm(2.5,2.5,11,11,1),Z(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[Bm(3.5,12.5,1.5),Z(`M5 12.5h3.5L12 9V3.5`)],gerber:[Z(`M8 2.5 2.5 5 8 7.5 13.5 5z`),Z(`M2.5 8 8 10.5 13.5 8`),Z(`M2.5 11 8 13.5 13.5 11`)],rotate:[Z(`M3 8a5 5 0 1 0 5-5`),Z(`M9.5 1.5 8 3l1.5 1.5`)],rotateRight:[Z(`M13 8a5 5 0 1 1-5-5`),Z(`M6.5 1.5 8 3 6.5 4.5`)],alignLeft:[Z(`M2.5 2v12`),Vm(5,3.5,8.5,3.5,1),Vm(5,9,5,3.5,1)],distributeH:[Z(`M2.5 2v12M13.5 2v12`),Vm(6,4,4,8,1)],check:[Z(`M8 1.5 3 3.5v4c0 3 2 5.5 5 6.5 3-1 5-3.5 5-6.5v-4z`),Z(`M5.5 8l2 2 3-3.5`)]},Km={width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,shapeRendering:`geometricPrecision`,"aria-hidden":!0};function qm(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function Jm(e,t={}){let n=Gm[e];return(0,_.createElement)(`svg`,{...Km,...t},...n.map((e,t)=>(0,_.createElement)(e.tag,qm(e,t))))}var Ym=e=>Jm(`lock`,e),Xm=e=>Jm(`unlock`,e),Zm=e=>Jm(`padlock`,e),Qm=e=>Jm(`padlockOpen`,e),$m=e=>Jm(`rotate`,e),eh=e=>Jm(`trash`,e),th=e=>Jm(`undo`,e),nh=e=>Jm(`close`,e),rh=e=>Jm(`chevron`,e),ih=({off:e,...t})=>Jm(e?`eyeOff`:`eye`,t),ah=e=>t=>Jm(e,t),oh={undo:ah(`undo`),redo:ah(`redo`),zoomIn:ah(`zoomIn`),zoomOut:ah(`zoomOut`),fit:ah(`fit`),fitSelection:ah(`fitSelection`),fitArea:ah(`fitArea`),component:ah(`component`),wire:ah(`wire`),netLabel:ah(`netLabel`),ground:ah(`ground`),power:ah(`power`),rotate:ah(`rotate`),rotateRight:ah(`rotateRight`),snap:ah(`snap`),check:ah(`check`),grid:ah(`grid`),alignLeft:ah(`alignLeft`),distributeH:ah(`distributeH`),polyline:ah(`polyline`),arc:ah(`arc`),circle:ah(`circle`),rectangle:ah(`rectangle`),text:ah(`text`),bus:ah(`bus`),noConnect:ah(`noConnect`),via:ah(`via`),boardOutline:ah(`boardOutline`),copperArea:ah(`copperArea`),singleRouting:ah(`singleRouting`),gerber:ah(`gerber`)};function sh(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function ch(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function lh(){let e=[];return{hold(t){return e=[...e,t],()=>{e=e.filter(e=>e!==t)}},held(){return e.length>0},dispatch(t){let n=e.at(-1);return n?(n(t),t.stopImmediatePropagation(),!0):!1}}}var uh=lh();function dh(e){let t=e=>void uh.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function fh(e,t){let n=(0,_.useRef)(t);(0,_.useLayoutEffect)(()=>{n.current=t}),(0,_.useEffect)(()=>e?uh.hold(e=>n.current(e)):void 0,[e])}var ph=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],mh=`Select a part first`,hh=e=>ph.includes(e);function gh(e,t){return E(e)?D(e,t):hh(e)&&t<1?mh:null}var _h=`Comes with hand routing (engine stage 4)`,Q=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},vh=[{title:`File`,entries:[Q(`Open circuit file`,`openFile`,`Ctrl+O`),Q(`New circuit…`,`newCircuit`),Q(`Import board (DXF or KiCad)…`,`importBoardDxf`),`separator`,Q(`Export BOM`,`exportBom`),Q(`Export package`,`exportPackage`),Q(`Export Gerber`,`exportFabrication`),Q(`Print…`,`print`)]},{title:`Edit`,entries:[Q(`Undo`,`undo`,`Ctrl+Z`),Q(`Redo`,`redo`,`Ctrl+Y`),`separator`,Q(`Copy`,`copy`,`Ctrl+C`),Q(`Paste`,`paste`,`Ctrl+V`),Q(`Delete`,`delete`,`Delete`),`separator`,Q(`Select all`,`selectAll`,`Ctrl+A`),Q(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},Q(`Find`,`find`,`Ctrl+F`),Q(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,Q(`Fillet tracks`,`filletTracks`,`U`),Q(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[Q(`Fit all`,`fit`,`K`),Q(`Fit selection`,`fitSelection`),Q(`Fit area`,`fitArea`),Q(`Zoom in`,`zoomIn`),Q(`Zoom out`,`zoomOut`),`separator`,{...Q(`Unit`,`toggleUnit`,`Q`),only:`pcb`},Q(`Grid style`,`gridStyle`),{...Q(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...Q(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...Q(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...Q(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...Q(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,Q(`Left panel`,`toggleLeftPanel`,`[`),Q(`Right panel`,`toggleRightPanel`,`]`),Q(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...Q(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...Q(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[Q(`Component`,`placeComponent`,`Shift+F`),Q(`Wire`,`wire`,`Alt+W`),Q(`Net label`,`netLabel`,`Alt+N`),Q(`Ground flag`,`groundFlag`),Q(`Power flag`,`powerFlag`),`separator`,Q(`Note box`,`noteBox`),`separator`,Q(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,Q(`Copper pour`,`placePour`),Q(`Copper pour: Whole board`,`placePourBoard`),Q(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,Q(`Polyline`,`drawPolyline`,`Alt+L`),Q(`Arc`,`drawArc`,`Alt+A`),Q(`Circle`,`drawCircle`,`Alt+C`),Q(`Rectangle`,`drawRectangle`,`Alt+R`),Q(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[Q(`Check DRC`,`checkDrc`),Q(`Design rules`,`designRules`),`separator`,Q(`Highlight net`,`highlight`,`H`),Q(`Clear highlight`,`clearHighlight`,`Shift+H`),`separator`,{label:`Add page`,command:`addPage`,only:`schematic`},{label:`Rename page`,command:`renamePage`,only:`schematic`},{label:`Delete page`,command:`deletePage`,only:`schematic`},`separator`,{label:`Replicate layout`,command:`replicateLayout`,only:`pcb`},Q(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[Q(`Single routing`,`singleRouting`,`Alt+W`),Q(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,Q(`Autoroute`,`autoroute`),Q(`Autoroute selection`,`autorouteSelection`),Q(`Autoroute net`,`autorouteNet`),Q(`Unroute`,`unroute`)]},{title:`Layout`,entries:[Q(`Rotate`,`rotate`,`Space`),Q(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,Q(`Lock`,`lock`),Q(`Unlock`,`unlock`),`separator`,Q(`Align left`,`alignLeft`,`Ctrl+Shift+L`),Q(`Align right`,`alignRight`),Q(`Align top`,`alignTop`),Q(`Align bottom`,`alignBottom`),Q(`Align horizontal centres`,`alignHCentres`),Q(`Align vertical centres`,`alignVCentres`),`separator`,Q(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),Q(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[Q(`History`,`history`),Q(`Footprint manager…`,`footprintManager`),Q(`Packages…`,`packages`)]},{title:`Export`,entries:[Q(`BOM`,`exportBom`),Q(`Package`,`exportPackage`),Q(`Fabrication files (JLCPCB)`,`exportFabrication`),Q(`Gerber`,`exportFabrication`),Q(`Pick and place (CPL)`,`exportFabrication`),Q(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[Q(`System…`,`systemSettings`),Q(`Hotkeys`,`keys`)]},{title:`Help`,entries:[Q(`Keys`,`keys`),Q(`About`,`about`)]}];vh.map(e=>e.title);var yh={pcb:`PCB only`,schematic:`Schematic only`};function bh(e,t,n,r={}){if(!e.command)return e.pending?{enabled:!1,reason:e.pending}:{enabled:!1};if(e.only&&e.only!==t)return{enabled:!1,reason:yh[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:gh(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function xh(e){return e.entries.filter(e=>e!==`separator`)}var Sh=[{keys:`Ctrl+Shift+Z`,label:`Redo`},{keys:`W`,label:`Wire (schematic), Single routing (PCB)`},{keys:`V (PCB)`,label:`Change the active layer; while routing, a via at the last corner`},{keys:`Space (while routing)`,label:`Step the corner mode: 45°, 45° reversed, 90°, arc`},{keys:`Enter (while routing)`,label:`End the track open at its last corner (or click that corner again)`},{keys:`R`,label:`Rotate`},{keys:`Space (while drawing a wire)`,label:`Flip the bend of the leg to the pointer`},{keys:`Shift (while drawing a polyline)`,label:`Keep the leg horizontal or vertical; Space flips its bend`},{keys:`Enter (while drawing a polyline)`,label:`Finish the polyline (or double click)`},{keys:`Backspace (while drawing)`,label:`Remove the last corner`},{keys:`F`,label:`Fit all`},{keys:`Esc`,label:`Clear the selection, put tools away`},{keys:`Arrow keys`,label:`Move the selection one grid step (a tenth with Snap off)`},{keys:`Shift+Arrow keys`,label:`Move the selection ten grid steps (ten tenths with Snap off)`},{keys:`Shift+F10`,label:`Open the context menu (also the menu key)`}];function Ch(){let e=new Set,t=[];for(let n of vh.flatMap(xh))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Sh.filter(t=>!e.has(t.keys))]}function wh(e,t){switch(t.type){case`click`:return{open:e.open===t.title?null:t.title};case`hover`:return e.open===null||e.open===t.title?e:{open:t.title};case`set`:return e.open===t.title?e:{open:t.title};default:return e.open===null?e:{open:null}}}function Th(e,t,n={}){return vh.map(r=>r.entries.map(r=>r===`separator`?`separator`:bh(r,e,t,n).enabled?`item`:`disabled`))}var Eh=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function Dh(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:Eh};if(!/^C[1-9][0-9]{0,9}$/.test(r))return{message:`"${e.trim()}" is not an LCSC part number: it looks like C7950 (C and digits).`};let i=t.trim();return{lcsc:r,replace:n,...i?{id:i}:{}}}function Oh(e){let t=(e,t)=>`${e} ${t}${e===1?``:`s`}`;return`Imported ${e.lcsc} as ${e.id}: ${e.title}, ${t(e.pins,`pin`)}, ${t(e.pads,`pad`)}.`}function kh(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function Ah(e){if(!e)return;let t=/^lcsc (C\d+), imported (\S+)$/.exec(e);if(t)return`Imported from LCSC ${t[1]} on ${t[2]}`;let n=/^written (\S+)$/.exec(e);return n?`Written on ${n[1]}`:e}function jh({result:e}){return(0,X.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,X.jsx)(`p`,{children:(0,X.jsx)(`strong`,{children:Oh(e)})}),(0,X.jsx)(`p`,{children:kh(e)}),e.notes.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Check these too`}),(0,X.jsx)(`ul`,{children:e.notes.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),(0,X.jsx)(`h3`,{children:`Written`}),(0,X.jsx)(`ul`,{children:e.files.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`code`,{children:e})},e))}),(0,X.jsx)(`p`,{children:e.terms})]})}function Mh({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(),m=(0,_.useId)(),h=async r=>{if(r.preventDefault(),c)return;if(f)return t();let a=Dh(n,i,o);if(`message`in a)return d(a.message);l(!0),d(void 0);try{p(await e.import(a))}catch(e){d(e.message)}finally{l(!1)}};return(0,X.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void h(e),children:[(0,X.jsx)(`label`,{htmlFor:m,children:`LCSC part number`}),(0,X.jsx)(`input`,{id:m,value:n,placeholder:`C7950`,disabled:c||f!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${m}-note`,"aria-invalid":u!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${m}-id`,children:`Part id`}),(0,X.jsx)(`input`,{id:`${m}-id`,value:i,placeholder:`the MPN`,disabled:c||f!==void 0,onChange:e=>a(e.target.value)}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,disabled:c||f!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,X.jsx)(`p`,{id:`${m}-note`,role:u?`alert`:void 0,children:c?`Fetching from EasyEDA…`:u??(f?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),f&&(0,X.jsx)(jh,{result:f}),(0,X.jsx)(`button`,{type:`submit`,disabled:c,children:f?`Close`:`Import`})]})}var Nh=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,Ph=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function Fh(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=Ph.exec(e)??Nh.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function Ih(e,t){if(t.includes(`/`))return;let n=e.parts.find(e=>e.name===t)?.tag,r=e.imports.find(e=>e.local===n)?.source;if(r===void 0||!/\.sheet(\.tsx)?$/.test(r))return;let i=r.replace(/^\.\//,``);return i.endsWith(`.tsx`)?i:`${i}.tsx`}var Lh=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function Rh(e,t){if(t.length===0)return`Select the parts to move into the sub-sheet first.`;let n=[];for(let r of new Set(t)){let t=e.parts.find(e=>e.name===r);if(!t)return`There is no part ${r} in the circuit.`;if(Ih(e,r)!==void 0)return`${r} is a sub-sheet instance; a sub-sheet is made of parts only, so leave instances out of the selection.`;if(!t.editable)return`${r} cannot be moved (${t.readonlyReason??`read-only`}).`;if(t.parent===`group`)return`${r} is inside a <group>, whose offset its position adds to; ungroup it first.`;n.push(t)}if(new Set(n.map(e=>e.page??``)).size>1)return`The selected parts are on different pages; select parts of one page.`}function zh(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=Rh(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function Bh(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function Vh(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var Hh=e=>`${e.trim()||`PowerStage`}1`,Uh=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function Wh(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var Gh=200;function Kh(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,_.useState)({problem:Uh});return(0,_.useEffect)(()=>{if(n.trim()===``){o({problem:Uh});return}let t=!0,a=window.setTimeout(()=>{e.preview({name:n.trim(),rename:i,...r?{instance:r}:{}}).then(e=>t&&o({preview:e}),e=>t&&o({problem:e.message}))},Gh);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function qh({preview:e}){let t=Bh(e);return t.length===0?(0,X.jsx)(`p`,{children:`No net crosses the selection, so the sheet has no ports.`}):(0,X.jsx)(`table`,{"aria-label":`Ports`,children:(0,X.jsx)(`tbody`,{children:t.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.port}),(0,X.jsx)(`td`,{children:e.joins})]},e.port))})})}function Jh({preview:e}){return(0,X.jsxs)(`table`,{"aria-label":`Designators`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:`Now`}),(0,X.jsx)(`td`,{children:`In the sheet`}),(0,X.jsx)(`td`,{children:`On the board`})]})}),(0,X.jsx)(`tbody`,{children:Vh(e).map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.now}),(0,X.jsx)(`td`,{children:e.sheet}),(0,X.jsx)(`td`,{children:e.board})]},e.now))})]})}function Yh({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),c=i.trim(),l={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:u,problem:d}=Kh(e,l),f=(0,_.useId)(),p=async n=>{n.preventDefault(),u&&await e.make(l)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void p(e),children:[(0,X.jsx)(`label`,{htmlFor:f,children:`Sheet name`}),(0,X.jsx)(`input`,{id:f,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${f}-note`,"aria-invalid":d!==void 0&&n!==``}),(0,X.jsx)(`label`,{htmlFor:`${f}-instance`,children:`Instance name`}),(0,X.jsx)(`input`,{id:`${f}-instance`,value:i,placeholder:Hh(n),onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{id:`${f}-note`,children:u?`Writes ${u.file}; ${u.instance} (base ${u.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:d}),u&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Ports`}),(0,X.jsx)(qh,{preview:u}),(0,X.jsx)(`h3`,{children:`Designators`}),(0,X.jsx)(Jh,{preview:u})]}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Rename the parts to local designators (R1, C1, …)`]}),(0,X.jsx)(`button`,{type:`submit`,disabled:!u,children:`Make sub-sheet`})]})}function Xh(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function Zh(e){let t=Xh(e),n=()=>(0,_.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function Qh({what:e,message:t,onRetry:n}){return(0,_.createElement)(`div`,{role:`alert`},(0,_.createElement)(`p`,null,`The ${e} dialog could not open (${t}). Check that the Studio is still running, then try again; if it fails again, reload the Studio.`),(0,_.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var $h=class extends _.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,_.createElement)(Qh,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,_.createElement)(_.Suspense,{fallback:(0,_.createElement)(`p`,null,`Loading…`)},this.props.render())}},eg=.0254,tg=e=>e===`mm`?`mil`:`mm`,ng=(e,t)=>t===`mil`?e/eg:e;function rg(e,t){let n=ng(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function ig(e,t){return`${Number(ng(e,t).toFixed(t===`mm`?4:2))} ${t}`}var ag=(e,t)=>Math.round(e/t*100),og=.0254,sg=[2*og,.1,5*og,10*og,.5,20*og,25*og,1,50*og,100*og].map(e=>Number(e.toFixed(4))),cg=.5,lg=[.05,.1,.2],ug=.1,dg=(e,t,n)=>({...e,[t]:n});function fg(e,t){if(e===`schematic`)return lg.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return sg.map(e=>({value:e,label:ig(e,t)}))}var pg={schematic:`lines`,pcb:`lines`},mg=e=>e===`lines`?`dots`:`lines`,hg=(e,t)=>({...e,[t]:mg(e[t])}),gg=5,_g=2;function vg(e,t,n=1){let r=e;for(let e=0;e<=_g;e++,r*=gg)if(r*t*n>=3)return r;return null}function yg(e,t,n,r=1){let i=vg(n,e.scale,r);if(i===null)return null;let a=be(e,t,{x:0,y:0}),o=be(e,t,{x:t.width,y:t.height}),s=(e,t)=>{let n=[];for(let r=Math.floor(Math.min(e,t)/i);r<=Math.ceil(Math.max(e,t)/i);r++)n.push(r);return n};return{spacing:i,columns:s(a.x,o.x),rows:s(a.y,o.y),minor:i*e.scale*r>=6}}var bg=e=>e%5==0,xg=e=>({...e,columns:e.columns.filter(bg),rows:e.rows.filter(bg)});function Sg(e,t,n,r,i,a){let{spacing:o}=r,s=(t,n)=>{for(let[r,a]of[[i.minor,!1],[i.fifth??i.minor,!0]]){e.strokeStyle=r,e.beginPath();for(let r of t.filter(e=>!i.fifth||bg(e)===a)){let[t,i,a,o]=n(r);e.moveTo(t,i),e.lineTo(a,o)}if(e.stroke(),!i.fifth)return}};e.lineWidth=Ko(a),s(r.columns,e=>{let r=qo(B(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=qo(B(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function Cg(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:Jo(t(e),r)-i,fifth:bg(e)}))}function wg(e,t,n,r){e.fillStyle=n,e.beginPath();for(let n=0;n+1<t.length;n+=2)e.rect(t[n],t[n+1],r,r);e.fill()}function Tg(e,t,n,r,i,a){let{spacing:o}=r,s=Yo(i.px,a),c=Cg(r.columns,e=>B(t,n,{x:e*o,y:0}).x,s,a),l=Cg(r.rows,e=>B(t,n,{x:0,y:e*o}).y,s,a),u=[];e.fillStyle=i.minor,e.beginPath();for(let t of c)for(let n of l)i.fifth&&t.fifth&&n.fifth?u.push(t.at,n.at):e.rect(t.at,n.at,s,s);e.fill(),i.fifth&&wg(e,u,i.fifth,s)}function Eg(e,t,n,r,i,a){let o=yg(t,n,r.step,a);if(!o)return;let s=o.minor?o:xg(o);e.save(),r.style===`dots`?Tg(e,t,n,s,i.dots,a):Sg(e,t,n,s,i.lines,a),e.restore()}function Dg({panel:e,onClose:t}){let[n,r]=(0,_.useState)(e.settings),i=(0,_.useId)(),a=(e,t)=>r(n=>({...n,[e]:t}));return(0,X.jsxs)(`form`,{className:`rules-form system-form`,onSubmit:r=>{r.preventDefault(),e.apply(n),t()},children:[(0,X.jsx)(`label`,{htmlFor:`${i}-theme`,children:`Theme`}),(0,X.jsxs)(`select`,{id:`${i}-theme`,value:n.theme,onChange:e=>a(`theme`,e.target.value),children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`dark`,children:`Dark`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-unit`,children:`PCB unit`}),(0,X.jsxs)(`select`,{id:`${i}-unit`,value:n.unit,onChange:e=>a(`unit`,e.target.value),children:[(0,X.jsx)(`option`,{value:`mm`,children:`mm`}),(0,X.jsx)(`option`,{value:`mil`,children:`mil`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-sheet`,children:`Schematic grid`}),(0,X.jsx)(`select`,{id:`${i}-sheet`,value:n.grid.schematic,onChange:e=>a(`grid`,{...n.grid,schematic:Number(e.target.value)}),children:fg(`schematic`).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsx)(`label`,{htmlFor:`${i}-pcb`,children:`PCB grid`}),(0,X.jsx)(`select`,{id:`${i}-pcb`,value:n.grid.pcb,onChange:e=>a(`grid`,{...n.grid,pcb:Number(e.target.value)}),children:fg(`pcb`,n.unit).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n.hoverLabels,onChange:e=>a(`hoverLabels`,e.target.checked)}),` Hover labels`]}),(0,X.jsx)(`p`,{children:`Kept in this browser. The grid steps are where each document starts; the Grid select still changes them.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var Og={width:30,height:20},kg=1e3,Ag=/^[\w\- ]+(\/[\w\- ]+)*$/;function jg(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!Ag.test(r))return{message:`Use letters, digits, spaces, - and _ in the name, and / between folders`};let i=[Number(t),Number(n)];return i.some(e=>!Number.isFinite(e)||e<=0||e>kg)?{message:`The board's width and height are mm above 0 and at most ${kg}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function Mg({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(String(Og.width)),[o,s]=(0,_.useState)(String(Og.height)),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(!1),f=(0,_.useId)(),p=async r=>{r.preventDefault();let a=jg(n,i,o);if(`message`in a)return l(a.message);d(!0);let s=await e.create(a);d(!1),s&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void p(e),children:[(0,X.jsx)(`label`,{htmlFor:`${f}-name`,children:`Name`}),(0,X.jsx)(`input`,{id:`${f}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${f}-w`,children:`Board width (mm)`}),(0,X.jsx)(`input`,{id:`${f}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,X.jsx)(`label`,{htmlFor:`${f}-h`,children:`Board height (mm)`}),(0,X.jsx)(`input`,{id:`${f}-h`,inputMode:`decimal`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(`p`,{role:c?`alert`:void 0,children:c??`Written as <name>.circuit.tsx in the project folder; Undo removes it again.`}),(0,X.jsx)(`button`,{type:`submit`,disabled:u,children:`Create`})]})}function Ng(e,t,n){if(!t)return`Not written in this file`;if(e.library)return`From library part ${e.library}; change it in the library`;if(n.has(t.name))return`Locked`;if(!t.editable)return`Read-only`;let r=t.props.footprint;return r&&r.literal===void 0?`Written as ${r.source}`:void 0}function Pg({components:e,parts:t,locked:n}){return e.map(e=>{let r=Ng(e,t.find(t=>t.name===e.id),n);return{name:e.id,kind:e.kind,value:e.value??``,footprint:e.footprint??``,...r?{fixed:r}:{}}})}var Fg=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),Ig=/^[\w.\-+:,=()]+$/;function Lg(e,t){let n=e.filter(e=>t[e.name]!==void 0&&t[e.name]?.trim()!==e.footprint);if(n.length===0)return{message:`No footprint was changed.`};let r=n.find(e=>e.fixed);if(r)return{message:`${r.name}: ${r.fixed}`};let i=n.find(e=>!Ig.test((t[e.name]??``).trim()));return i?{message:`${i.name}: a footprint is a name such as 0603 or soic8, without spaces`}:{edits:n.map(e=>({kind:`setProps`,part:e.name,props:{footprint:(t[e.name]??``).trim()}})),summary:`change footprints: ${n.slice(0,3).map(e=>`${e.name} → ${(t[e.name]??``).trim()}`).join(`, `)}${n.length>3?` and ${n.length-3} more`:``}`}}var Rg=`.insp-body:not([hidden]) .insp-value input:not([disabled]):not([type="checkbox"])`;function zg(e,t,n){return{edits:[{kind:`setProps`,part:e,props:{[t]:n}}],summary:`set ${e} ${t}=${JSON.stringify(n)}`}}var Bg={resistor:[[`resistance`,`10k`],[`footprint`,`0402`]],capacitor:[[`capacitance`,`100nF`],[`footprint`,`0402`]],inductor:[[`inductance`,`10uH`],[`footprint`,`0805`]],led:[[`color`,`green`],[`footprint`,`0603`]],diode:[[`footprint`,`sod123`]],fuse:[[`currentRating`,`500mA`],[`footprint`,`1206`]],crystal:[[`frequency`,`16MHz`],[`footprint`,`hc49`]],pinheader:[[`pinCount`,`4`],[`pitch`,`2.54mm`]],port:[[`side`,`left`],[`order`,`1`]]},Vg=[`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`side`,`layer`],Hg=[`schNameAt`,`schValueAt`,`pcbNameAt`],Ug=`footprint`;function Wg(e,t){return Ug in e.props?[`prop:${Ug}`]:t.includes(Ug)?[`suggest:${Ug}`]:[]}var Gg={label:`Placement`,value:`Placed by Studio`};function Kg(e,t){let n=Object.keys(e.props).filter(e=>!Vg.includes(e)&&!Hg.includes(e)&&e!==Ug),r=(Bg[e.tag]??[]).map(([e])=>e).filter(t=>!(t in e.props)),i=r.filter(e=>e!==Ug),a=Vg.filter(t=>t in e.props),o=Hg.filter(t=>t in e.props),s=Wg(e,r);return[{title:`Basic`,rows:[`name`,`kind`,...n.map(e=>`prop:${e}`),...i.map(e=>`suggest:${e}`)]},...s.length>0?[{title:`Footprint`,rows:s}]:[],{title:`Position`,rows:[...t.autoPlaced?[`placed`]:[],...a.map(e=>`prop:${e}`),...o.map(e=>`textAt:${e}`),`lock`]},{title:`Connections`,rows:[`connections`]},...t.library?[{title:`Library`,rows:[`library`]}]:[],{title:`Notes`,rows:[`notes`]}]}function qg(){return[{title:`Build`,rows:[`build`]},{title:`Notes for the agent`,rows:[`notes`]}]}function Jg(e,t,n=0,r=0,i=0,a=0,o=0){let s=e+t+n+r+i+a+o;return s===0?`board`:s>1?`group`:e===1?`part`:t===1?`wire`:i===1?`copper`:a===1?`text`:o===1?`pour`:n===1?`label`:`drawing`}var Yg={parts:`Parts`,wires:`Wires`,labels:`Net labels and flags`,drawings:`Drawings`,copper:`Tracks and vias`,texts:`Names and values`,pours:`Copper pours and holes`},Xg=/^kind:(parts|wires|labels|drawings|copper|texts|pours):(\d+)$/;function Zg(e){let t=Xg.exec(e);return t?{kind:t[1],count:Number(t[2])}:void 0}function Qg(e,t,n=0,r=0,i=0,a=0,o=0,s=0){let c=`Selected objects: ${e.length+n+r+i+a+o+s}`,[l]=e,u=e.map(e=>`part:${e.name}`),d=[[`parts`,e.length],[`wires`,n],[`labels`,r],[`drawings`,i],[`copper`,a],[`texts`,o],[`pours`,s]].flatMap(([e,t])=>t>0?[`kind:${e}:${t}`]:[]);return n+r+i+a+o+s>0?{header:c,sections:[{title:`Selection`,rows:[...d,...u]}]}:l?e.length===1?{header:c,sections:Kg(l,t)}:{header:c,sections:[{title:`Selection`,rows:u}]}:{header:c,sections:qg()}}var $g=[{label:`Rotate`,command:`rotate`},{label:`Lock`,command:`lock`},{label:`Unlock`,command:`unlock`},{label:`Delete`,command:`delete`}];function e_(e,t,n,r=0){let i=t.map(e=>e.name);return e===`lock`||e===`unlock`?`parts`in Ct(i,n.locked,e===`lock`,n.violated):e===`delete`&&r>0||t.some(e=>e.editable&&!n.locked.has(e.name))}function t_(e,t){return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this part`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this part, so the agent cannot move or change it`}}var n_=`Use this footprint`,r_=e=>e.kind===`look`?void 0:n_,i_=e=>e.kind===`look`?`copy`:`use`,a_=e=>e.kind===`look`;function o_(e,t){return i_(e)===`copy`?`copy`:t?`use`:`nothing`}var s_=(e,t,n)=>({...e,[t]:n}),c_=(e,t)=>zg(e,`footprint`,t),l_,u_=new Set;function d_(e){l_=e;for(let e of u_)e()}var f_={open(e){d_(e)},close(){d_(void 0)},current:()=>l_,subscribe(e){return u_.add(e),()=>{u_.delete(e)}}},p_=()=>f_.open({purpose:{kind:`look`}}),m_={display:`flex`,gap:4};function h_({panel:e,onClose:t}){let n=(0,_.useMemo)(()=>e.source?Pg(e.source):[],[e.source]),[r,i]=(0,_.useState)({}),[a,o]=(0,_.useState)(),s=(0,_.useId)();if(n.length===0)return(0,X.jsx)(`p`,{children:`The open circuit has no parts yet.`});let c=async i=>{i.preventDefault();let a=Lg(n,r);if(`message`in a)return o(a.message);await e.write(a.edits,a.summary)&&t()};return(0,X.jsxs)(`form`,{className:`footprint-manager`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`datalist`,{id:s,children:Fg(n).map(e=>(0,X.jsx)(`option`,{value:e},e))}),(0,X.jsxs)(`table`,{children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Designator`}),(0,X.jsx)(`th`,{scope:`col`,children:`Kind`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Footprint`})]})}),(0,X.jsx)(`tbody`,{children:n.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.name}),(0,X.jsx)(`td`,{children:e.kind}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:(0,X.jsxs)(`div`,{style:m_,children:[(0,X.jsx)(`input`,{"aria-label":`Footprint of ${e.name}`,list:s,value:r[e.name]??e.footprint,disabled:e.fixed!==void 0,title:e.fixed,onChange:t=>i(n=>({...n,[e.name]:t.target.value}))}),(0,X.jsx)(`button`,{type:`button`,"aria-label":`Choose a package for ${e.name}`,title:`Choose from the standard packages`,disabled:e.fixed!==void 0,onClick:()=>f_.open({purpose:{kind:`manager`,part:e.name},kind:e.kind,initial:r[e.name]??e.footprint,choose:t=>i(n=>s_(n,e.name,t))}),children:`…`})]})})]},e.name))})]}),(0,X.jsx)(`p`,{role:a?`alert`:void 0,children:a??`Changed footprints are written to the circuit file as one change; Undo takes them all back.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var g_={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function __(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function v_(e,t){if(e===`*`)return!0;let n=__(e);return t.names.some(e=>n.test(e))}var y_=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>v_(e,t))).map(e=>e.name);function b_(e,t){return y_(e,t)[0]??g_.name}function x_(e,t){let n=new Map,r=[];for(let i of t){let t=y_(e,i);if(n.set(i.id,t[0]??g_.name),t.length<2)continue;let a=`Net ${i.id.replace(/^net\./,``)} matches the net classes ${t.join(` and `)}; it uses ${t[0]}`;r.push(Zr(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...S_(e,t)]}}function S_(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>v_(e,t))).map(t=>Zr(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var C_=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??g_.clearance;function w_(e,t,n){let r=e.classClearance.filter(e=>e.a===t&&e.b===n||e.a===n&&e.b===t).map(e=>e.clearance);return Math.max(C_(e,t),C_(e,n),e.fabrication.minClearance,...r)}var T_=(e,t)=>e.classes.find(n=>n.name===b_(e,t))??g_,E_=(e,t)=>Math.max(T_(e,t).trackWidth,e.fabrication.minTrackWidth),D_=e=>Math.round(e*1e6)/1e6;function O_(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,D_(n+2*e.fabrication.minAnnularRing))}}var k_=(e,t)=>O_(e,T_(e,t).via),A_=e=>O_(e,g_.via),j_=e=>e.fabrication.filletRadius??1,M_=`Fillet radius`,N_=`Edit → Fillet tracks rounds corners with this radius. Empty is the default, 1 mm. A track's width is the floor: a smaller radius is raised to the width.`;function P_(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function F_(e){if(e.trim()===``)return{radius:null};let t=ei(e);return t===void 0||t<=0||t>50?{message:`Type a length above 0 and at most 50 mm, such as 1, 0.5mm or 40mil, or leave it empty for the default.`}:{radius:Math.round(t*1e6)/1e6}}var I_=`modulepreload`,L_=function(e,t){return new URL(e,t).href},R_={},z_=function(e){return e.pathname.endsWith(`.css`)},B_=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},V_=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=L_(t,n);let r=s(t),i=z_(r);return B_(R_,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:I_,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},H_=Zh(()=>V_(()=>import(`./NewPartDialog-ZQ4Y3m45.js`).then(e=>e.NewPartForm),__vite__mapDeps([0,1]),import.meta.url)),U_=Zh(()=>V_(()=>import(`./PackagesDialog-vEzilmpR.js`).then(e=>e.PackagesForm),__vite__mapDeps([2,1,3]),import.meta.url)),W_=Zh(()=>V_(()=>import(`./VerifyPartDialog-DYr1UIds.js`).then(e=>e.VerifyPartForm),__vite__mapDeps([4,5]),import.meta.url)),G_=`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex='-1'])`;function K_(e,t,n){fh(!0,r=>{let i=sh(r.key);if(i===`hold`)return n?.(r);if(r.preventDefault(),i===`close`)return t();let a=[...e.current?.querySelectorAll(G_)??[]];(a[ch(a.indexOf(document.activeElement),a.length,r.shiftKey)]??e.current)?.focus()})}function q_({title:e,onClose:t,children:n,wide:r=!1,large:i=!1,className:a,onKey:o}){let s=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=document.activeElement;return(s.current?.querySelector(`[data-default]`)??s.current?.querySelector(G_)??s.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),K_(s,t,o);let c=i?`dialog large`:r?`dialog wide`:`dialog`;return(0,X.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,X.jsxs)(`section`,{ref:s,tabIndex:-1,className:a?`${c} ${a}`:c,role:`dialog`,"aria-modal":`true`,"aria-label":e,children:[(0,X.jsxs)(`header`,{className:`hairline-b`,children:[(0,X.jsx)(`h2`,{children:e}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:t,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function J_(){return(0,X.jsx)(`table`,{children:(0,X.jsx)(`tbody`,{children:Ch().map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:(0,X.jsx)(`kbd`,{children:e.keys})}),(0,X.jsx)(`td`,{children:e.label})]},e.keys))})})}function Y_({rules:e,onClose:t}){let n=P_(e.fabrication),[r,i]=(0,_.useState)(n.value),[a,o]=(0,_.useState)(),s=(0,_.useId)(),c=async i=>{i.preventDefault();let a=F_(r);if(`message`in a)return o(a.message);if(r.trim()===n.value)return t();await e.save(a.radius)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`label`,{htmlFor:s,children:M_}),(0,X.jsx)(`input`,{id:s,value:r,placeholder:n.placeholder,onChange:e=>i(e.target.value),"aria-describedby":`${s}-note`,"aria-invalid":a!==void 0}),(0,X.jsx)(`p`,{id:`${s}-note`,children:a??N_}),(0,X.jsx)(`p`,{children:`The rest of the design rules are in rules.yaml in the project.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function X_({panel:e,onClose:t}){let n=e=>()=>{t(),e()};return(0,X.jsxs)(`div`,{className:`rules-form`,children:[(0,X.jsx)(`p`,{children:e.question}),(0,X.jsx)(`button`,{type:`button`,"data-default":!0,onClick:n(e.showChecks),children:`Show checks`}),(0,X.jsx)(`button`,{type:`button`,onClick:n(e.exportAnyway),children:`Export anyway`})]})}function Z_({name:e,onClose:t,rules:n,makeSheet:r,importPart:i,newPart:a,system:o,newCircuit:s,footprints:c,exportChecks:l}){return e===`exportChecks`?(0,X.jsx)(q_,{title:`Fabrication files`,onClose:t,children:(0,X.jsx)(X_,{panel:l,onClose:t})}):e===`footprints`?(0,X.jsx)(q_,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,X.jsx)(h_,{panel:c,onClose:t})}):e===`newCircuit`?(0,X.jsx)(q_,{title:`New circuit`,onClose:t,children:(0,X.jsx)(Mg,{panel:s,onClose:t})}):e===`system`?(0,X.jsx)(q_,{title:`System settings`,onClose:t,children:(0,X.jsx)(Dg,{panel:o,onClose:t})}):e===`newPart`?(0,X.jsx)(q_,{title:`New part`,onClose:t,wide:!0,children:(0,X.jsx)($h,{what:`New part`,onRetry:H_.retry,render:()=>{let e=H_.component();return(0,X.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,X.jsx)(q_,{title:`Import by LCSC number`,onClose:t,children:(0,X.jsx)(Mh,{panel:i,onClose:t})}):e===`makeSheet`?(0,X.jsx)(q_,{title:`Make sub-sheet`,onClose:t,children:(0,X.jsx)(Yh,{panel:r,onClose:t})}):e===`rules`?(0,X.jsx)(q_,{title:`Design rules`,onClose:t,children:(0,X.jsx)(Y_,{rules:n,onClose:t})}):e===`keys`?(0,X.jsx)(q_,{title:`Keys`,onClose:t,children:(0,X.jsx)(J_,{})}):(0,X.jsxs)(q_,{title:`About copperflow`,onClose:t,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`copperflow`}),` Studio`]}),(0,X.jsx)(`p`,{children:`Design circuits in code with a human and an AI agent editing the same files.`}),(0,X.jsx)(`p`,{children:`Apache License 2.0`})]})}function Q_({target:e,panel:t,onClose:n}){return(0,X.jsx)(q_,{title:`Verify ${e.title}`,onClose:n,large:!0,children:(0,X.jsx)($h,{what:`Verify`,onRetry:W_.retry,render:()=>{let n=W_.component();return(0,X.jsx)(n,{panel:t,id:e.id})}})})}function $_({request:e,onClose:t}){let n=(0,_.useRef)(void 0);return(0,X.jsx)(q_,{title:`Packages`,onClose:t,className:`packages-dialog`,onKey:e=>n.current?.(e),children:(0,X.jsx)($h,{what:`Packages`,onRetry:U_.retry,render:()=>{let r=U_.component();return(0,X.jsx)(r,{request:e,onClose:t,keys:n})}})})}var ev=.001;function tv(e){let t=Number(e.toFixed(3));return String(t===0?0:t)}var nv=e=>`${tv(e)} mm`,rv=(e,t)=>`${tv(e)} × ${tv(t)} mm`;function iv(e){let t=[...new Set(e)].sort(av),n=[];for(let e=0;e<t.length;){let r=e;for(;r+1<t.length&&Number(t[r+1])===Number(t[r])+1;)r++;n.push(r-e>=2?`${t[e]}–${t[r]}`:t.slice(e,r+1).join(`, `)),e=r+1}return n.join(`, `)}function av(e,t){let[n,r]=[Number(e),Number(t)];return Number.isFinite(n)&&Number.isFinite(r)?n-r:e.localeCompare(t)}function ov(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.abs(Math.cos(t)),Math.abs(Math.sin(t))];return{width:e.width*n+e.height*r,height:e.width*r+e.height*n}}function sv(e){return e.length===0?[{label:`Pads`,value:`0`}]:[{label:`Pads`,value:String(e.length)},...cv(e),...mv(e),...lv(e)]}function cv(e){let t=Tv(e,e=>{let t=ov(e);return rv(t.width,t.height)});return t.size===1?[{label:`Pad width × height`,value:[...t.keys()][0]??``}]:[...t].map(([e,t])=>{let n=[...new Set(t.map(e=>e.number))];return{label:`Pad width × height, pad${n.length===1?``:`s`} ${iv(n)}`,value:e}})}function lv(e){let t=e.filter(e=>e.drill!==void 0);if(t.length===0)return[];let n=Tv(t,e=>{let t=e.drill??{width:0,height:0};return t.width===t.height?nv(t.width):`${rv(t.width,t.height)} (slot)`}),r=(e,t)=>n.size===1?e:`${e}, pads ${iv(t.map(e=>e.number))}`;return[...n].flatMap(([e,t])=>[{label:r(`Drill`,t),value:e},{label:r(`Annular ring`,t),value:nv(Math.min(...t.map(uv)))}])}function uv(e){let t=e.drill??{width:0,height:0};return Math.min(e.width-t.width,e.height-t.height)/2}var dv=e=>e===`x`?`y`:`x`,fv=(e,t)=>(t===`x`?ov(e).width:ov(e).height)/2;function pv(e,t){return Math.max(...e.map(e=>e[t]+fv(e,t)))-Math.min(...e.map(e=>e[t]-fv(e,t)))}function mv(e){if(e.length===1)return[];if(e.length===2)return hv(e[0],e[1]);let t=t=>vv(e,dv(t)),[n,r]=[t(`x`),t(`y`)];for(let n of[`x`,`y`])if(t(n).length===1)return[{label:`Pitch along`,value:yv(e,n)},{label:`Span outside the pads`,value:nv(pv(e,n))}];let i=(r.length===2?[`y`]:[]).concat(n.length===2?[`x`]:[]);if(i.length>0){let n=i.sort((e,n)=>Math.max(...t(n).map(e=>e.length))-Math.max(...t(e).map(e=>e.length)))[0],[r,a]=t(n),o=dv(n);return[{label:`Pitch along`,value:yv(e,n)},{label:`Rows centre to centre`,value:nv(Math.abs(a[0][o]-r[0][o]))},{label:`Span outside the pads`,value:nv(pv(e,o))}]}return gv(e,n,r)||(_v(e)??[{label:`Pitch along`,value:yv(Cv(e),Sv(e))},{label:`Span outside the pads`,value:rv(pv(e,`x`),pv(e,`y`))}])}function hv(e,t){let n=Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?`x`:`y`;return[{label:`Pads centre to centre`,value:nv(Math.hypot(t.x-e.x,t.y-e.y))},{label:`Gap between the pads`,value:nv(wv(e,t))},{label:`Span outside the pads`,value:nv(pv([e,t],n))}]}function gv(e,t,n){let r=e=>e.every(t=>t.length===e[0]?.length);if(r(t)&&r(n)&&t.length*n.length===e.length)return[{label:`Pitch along`,value:yv(e,`x`)},{label:`Pitch across`,value:yv(e,`y`)},{label:`Span outside the pads`,value:rv(pv(e,`x`),pv(e,`y`))}]}function _v(e){let t=(t,n)=>e.filter(e=>Math.abs(e[t]-n)<ev),n=e.map(e=>e.x),r=e.map(e=>e.y),[i,a,o,s]=[t(`x`,Math.min(...n)),t(`x`,Math.max(...n)),t(`y`,Math.min(...r)),t(`y`,Math.max(...r))];if([i,a,o,s].some(e=>e.length<2))return;let c=new Set([...i,...a,...o,...s]);if(c.size!==i.length+a.length+o.length+s.length)return;let l=e=>e.x>Math.min(...n)+ev&&e.x<Math.max(...n)-ev&&e.y>Math.min(...r)+ev&&e.y<Math.max(...r)-ev;if(!e.some(e=>!c.has(e)&&!l(e)))return[{label:`Pitch along`,value:xv([...bv(i,`y`),...bv(a,`y`),...bv(o,`x`),...bv(s,`x`)])},{label:`Rows centre to centre`,value:rv(Math.max(...n)-Math.min(...n),Math.max(...r)-Math.min(...r))},{label:`Span outside the pads`,value:rv(pv(e,`x`),pv(e,`y`))}]}function vv(e,t){let n=[];for(let r of[...e].sort((e,n)=>e[t]-n[t])){let e=n.at(-1);e&&Math.abs(e[0][t]-r[t])<ev?e.push(r):n.push([r])}return n}function yv(e,t){return xv(vv(e,dv(t)).flatMap(e=>bv(e,t)))}function bv(e,t){let n=e.map(e=>e[t]).sort((e,t)=>e-t);return n.slice(1).map((e,t)=>e-n[t]).filter(e=>e>ev)}function xv(e){let t=[...new Set(e.map(tv))].sort((e,t)=>Number(e)-Number(t));return t.length===0?`–`:`${t.join(`, `)} mm`}function Sv(e){let t=t=>Math.max(...vv(e,dv(t)).map(e=>e.length));return t(`x`)>=t(`y`)?`x`:`y`}function Cv(e){return vv(e,dv(Sv(e))).reduce((e,t)=>t.length>e.length?t:e,[])}function wv(e,t){let n=e=>e.shape===`circle`&&e.width===e.height;if(n(e)&&n(t))return Math.max(0,Math.hypot(t.x-e.x,t.y-e.y)-e.width/2-t.width/2);let r=Math.max(0,Math.abs(t.x-e.x)-fv(e,`x`)-fv(t,`x`)),i=Math.max(0,Math.abs(t.y-e.y)-fv(e,`y`)-fv(t,`y`));return Math.hypot(r,i)}function Tv(e,t){let n=new Map;for(let r of e)n.set(t(r),[...n.get(t(r))??[],r]);return n}var Ev=()=>Mo(`light`).background,Dv={width:297,height:210,margin:10};function Ov(){return{width:(Dv.width-2*Dv.margin)*8,height:(Dv.height-2*Dv.margin-kv)*8}}var kv=8;function Av(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function jv(e){let t={width:Dv.width-2*Dv.margin,height:Dv.height-2*Dv.margin},n={width:t.width,height:t.height-kv};return[`<svg xmlns="http://www.w3.org/2000/svg" width="${t.width}mm" height="${t.height}mm" viewBox="0 0 ${t.width} ${t.height}">`,`<text x="0" y="5" font-size="4" font-family="Arial, sans-serif">${Av(e.title)}</text>`,`<image x="0" y="${kv}" width="${n.width}" height="${n.height}" preserveAspectRatio="xMidYMid meet" href="${Av(e.image)}" />`,`<rect x="0" y="${kv}" width="${n.width}" height="${n.height}" fill="none" stroke="currentColor" stroke-width="0.2" />`,`</svg>`].join(``)}function Mv(e,t){let n=t.map(e=>`<section class="sheet">${jv(e)}</section>`).join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${Av(e)}</title>`,`<style>`,`@page { size: A4 landscape; margin: ${Dv.margin}mm }`,`html, body { margin: 0; background: Canvas; color: CanvasText; color-scheme: light }`,`.sheet { break-after: page; page-break-after: always }`,`.sheet:last-child { break-after: auto; page-break-after: auto }`,`</style></head><body>`,n,`</body></html>`].join(``)}var Nv=5,Pv=10,Fv=`Print at 100 % (actual size), not fit to page; the bar must measure 10 mm.`;function Iv(e){let t=e.shape===`circle`||e.shape===`oval`?`<ellipse cx="0" cy="0" rx="${tv(e.width/2)}" ry="${tv(e.height/2)}" />`:`<rect x="${tv(-e.width/2)}" y="${tv(-e.height/2)}" width="${tv(e.width)}" height="${tv(e.height)}" />`,n=e.drill===void 0?``:`<ellipse class="drill" cx="0" cy="0" rx="${tv(e.drill.width/2)}" ry="${tv(e.drill.height/2)}" />`,r=Math.max(.3,Math.min(e.width,e.height)*.5);return`<g transform="translate(${tv(e.x)} ${tv(-e.y)}) rotate(${tv(-e.rotation)})">${t}${n}</g><text x="${tv(e.x)}" y="${tv(-e.y+r/3)}" font-size="${tv(r)}">${Av(e.number)}</text>`}function Lv(e,t){let n=[...t.pads.flatMap(e=>{let t=ov(e);return[{x:e.x-t.width/2,y:e.y-t.height/2},{x:e.x+t.width/2,y:e.y+t.height/2}]}),...t.courtyard,{x:0,y:0}],[r,i]=[Math.min(...n.map(e=>e.x)),Math.max(...n.map(e=>e.x))],[a,o]=[Math.min(...n.map(e=>-e.y)),Math.max(...n.map(e=>-e.y))],s=r-Nv,c=a-Nv-4,l=i-r+15+Pv,u=Math.max(o-a,6)+10+4,d=i+Nv,f=t.courtyard.map(e=>`${tv(e.x)},${tv(-e.y)}`).join(` `),p=[`<svg xmlns="http://www.w3.org/2000/svg" width="${tv(l)}mm" height="${tv(u)}mm" viewBox="${tv(s)} ${tv(c)} ${tv(l)} ${tv(u)}">`,`<text x="${tv(s+1)}" y="${tv(c+3)}" font-size="2.5">${Av(e)}</text>`,f===``?``:`<polygon class="courtyard" points="${f}" />`,`<path class="origin" d="M -1 0 H 1 M 0 -1 V 1" />`,...t.pads.map(Iv),`<rect class="scale" x="${tv(d)}" y="${tv(a)}" width="${Pv}" height="0.4" />`,`<text x="${tv(d)}" y="${tv(a+3)}" font-size="2">${Pv} mm</text>`,`</svg>`].join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${Av(e)} at 1:1</title>`,`<style>`,`@page { margin: 10mm }`,`html, body { margin: 0; background: #fff; color: #000; color-scheme: light; font-family: Arial, sans-serif }`,`p { font-size: 10pt; margin: 0 0 4mm }`,`svg { display: block }`,`svg g { fill: #999; stroke: #000; stroke-width: 0.05 }`,`svg .drill { fill: #fff }`,`svg text { fill: #000; text-anchor: start }`,`svg g + text { text-anchor: middle }`,`svg .courtyard, svg .origin { fill: none; stroke: #000; stroke-width: 0.05; stroke-dasharray: 0.3 0.3 }`,`svg .scale { fill: #000 }`,`</style></head><body>`,`<p>${Av(Fv)}</p>`,p,`</body></html>`].join(``)}function Rv(e){let t=window.open(``,`_blank`);return t?(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.setTimeout(()=>t.print(),0),!0):!1}function zv(e){return(0,_.useMemo)(()=>({load:e=>z(`/api/part?id=${encodeURIComponent(e)}`),tick:async(e,t,n,r)=>{try{return await z(`/api/tick`,{id:e,items:t,ticked:n,shown:r})}catch(e){let t=e;if(t.status===409&&typeof t.data?.checklist==`string`)return{changed:t.data.checklist};throw e}},mark:async(t,n)=>{await z(`/api/verify`,{id:t,...n}),await e()},frame:async(e,t)=>URL.createObjectURL(await he(`/api/part-datasheet?id=${encodeURIComponent(e)}&file=${encodeURIComponent(t)}`)),release:e=>URL.revokeObjectURL(e),print:(e,t)=>Rv(Lv(e,t))}),[e])}function Bv(e){return`Created ${e.id}: ${e.title}, ${e.pins} pin${e.pins===1?``:`s`}, footprint ${e.footprint}. Not verified: check it in ${e.verification}.`}function Vv({label:e,shortcut:t,menu:n,index:r,enabled:i,checked:a,reason:o,onActivate:s}){return(0,X.jsxs)(`button`,{role:a===void 0?`menuitem`:`menuitemcheckbox`,"aria-checked":a,className:a?`menu-item checked`:`menu-item`,...n===void 0?{}:{"data-menu":n},"data-item":r,tabIndex:-1,"aria-disabled":!i||void 0,title:o,onClick:e=>{let t=!wm(e);t||Em(e),i&&s(t)},children:[(0,X.jsx)(`span`,{children:e}),t&&(0,X.jsx)(`kbd`,{children:t})]})}function Hv(e,t,n){(0,_.useEffect)(()=>{if(!e)return;let r=e=>{e.target instanceof Node&&t.current?.contains(e.target)||n()};return window.addEventListener(`pointerdown`,r,!0),()=>window.removeEventListener(`pointerdown`,r,!0)},[e,t,n])}var Uv=(e,t)=>(e+t)%t,Wv=e=>e===`item`||e===`disabled`;function Gv(e,t,n,r=Wv){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=Uv(a+n,i),r(e[a]))return a;return null}var Kv=e=>e?Gv(e,null,1):null,qv=e=>e?Gv(e,null,-1):null,Jv=(e,t)=>e?Gv(e,null,t,e=>e===`item`)??Gv(e,null,t):null,Yv=e=>Jv(e,1),Xv=e=>Jv(e,-1),Zv=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),Qv=(e,t)=>Zv(e,{menu:e,item:t});function $v(e,t,n,r){let i=r.length,a={ArrowLeft:Uv(t-1,i),ArrowRight:Uv(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?Qv(t,Yv(r[t])):e===`ArrowUp`?Qv(t,Xv(r[t])):n===null?null:e===`Escape`?Zv(null,{menu:t,item:null}):e===`Tab`?Zv(null,`keep`,!1):null:Zv(n===null?null:a,{menu:a,item:null})}function ey(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:Gv(r,t.item,1),ArrowUp:Gv(r,t.item,-1),Home:Kv(r),End:qv(r)};if(e in a)return Qv(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=Uv(t.menu+(e===`ArrowLeft`?-1:1),i);return Qv(r,Yv(n[r]))}return e===`Escape`?Zv(null,{menu:t.menu,item:null}):e===`Tab`?Zv(null,{menu:t.menu,item:null},!1):null}function ty(e,t,n){return e===`Escape`?Zv(null,`keep`):e===`Tab`?Zv(null,`keep`,!1):e===`ArrowDown`||e===`Home`?Qv(t,Yv(n[t])):e===`ArrowUp`||e===`End`?Qv(t,Xv(n[t])):e===`ArrowLeft`||e===`ArrowRight`?Zv(Uv(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function ny(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:ty(e,n,r):t.item===null?$v(e,t.menu,n,r):ey(e,{menu:t.menu,item:t.item},r)}function ry(e){return Yv(e)}var iy=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function ay(e,t){let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-menu]`):null;if(!n)return null;let r=n.dataset.item;return{menu:Number(n.dataset.menu),item:r===void 0?null:Number(r)}}function oy(e){let t=(0,_.useRef)(null);return(0,_.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(iy(n))?.focus())}),(0,_.useCallback)(n=>{let r=e.current?.querySelector(iy(n));r?r.focus():t.current=n},[e])}function sy({entry:e,menu:t,index:n,view:r,selected:i,off:a,toggles:o,onRun:s}){if(e===`separator`)return(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`});let{label:c,shortcut:l,command:u,toggle:d}=e,{enabled:f,reason:p}=bh(e,r,i,a);return(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(Vv,{label:c,...l?{shortcut:l}:{},...d?{checked:o[d]}:{},menu:t,index:n,enabled:f,...p?{reason:p}:{},onActivate:e=>u&&s(u,t,e)})})}function cy({menu:e,index:t,view:n,selected:r,off:i,toggles:a,onRun:o}){return(0,X.jsx)(`ul`,{className:`menu-dropdown`,role:`menu`,"aria-label":e.title,children:e.entries.map((e,s)=>(0,X.jsx)(sy,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function ly({menu:e,index:t,open:n,current:r,onPointer:i,onHover:a,onKeyboard:o,view:s,selected:c,off:l,toggles:u,onRun:d}){return(0,X.jsxs)(`div`,{className:`menu`,children:[(0,X.jsx)(`button`,{role:`menuitem`,"data-menu":t,"aria-haspopup":`menu`,"aria-expanded":n,tabIndex:r?0:-1,className:`menu-title${n?` open`:``}`,onClick:e=>{if(!wm(e))return o({open:t,focus:{menu:t,item:ry(Th(s,c,l)[t])},preventDefault:!0});Em(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,X.jsx)(cy,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function uy({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,_.useReducer)(wh,{open:null}),[c,l]=(0,_.useState)(0),u=(0,_.useRef)(null),d=oy(u),f=o.open===null?null:vh.findIndex(e=>e.title===o.open),p=(0,_.useMemo)(()=>Th(t,n,i),[t,n,i]),m=e=>{s({type:`set`,title:e.open===null?null:vh[e.open]?.title??null}),e.focus!==`keep`&&(l(e.focus.menu),d(e.focus))},h=e=>{let t=ny(e.key,ay(u.current,document.activeElement),f,p,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),m(t),!0):!1};fh(f!==null,e=>void h(e)),Hv(f!==null,u,(0,_.useCallback)(()=>s({type:`outside`}),[]));let g=(t,n,r)=>{r&&m({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{l(e),s({type:`click`,title:vh[e]?.title??``})},y=e=>s({type:`hover`,title:vh[e]?.title??``});return(0,X.jsxs)(`header`,{className:`menubar hairline-b`,ref:u,children:[(0,X.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,X.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>h(e)&&e.stopPropagation(),children:vh.map((e,a)=>(0,X.jsx)(ly,{menu:e,index:a,open:f===a,current:c===a,onPointer:v,onHover:y,onKeyboard:m,view:t,selected:n,off:i,toggles:r,onRun:g},e.title))}),(0,X.jsx)(`div`,{className:`menubar-end`,children:a})]})}var dy=`Main`;function fy(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[dy]}function py(e,t){let n=fy(e);return n.includes(t)?t:n[0]??`Main`}function my(e,t){let n=e.schematic.pages??[],r=n.find(e=>e.name===t);if(n.length<=1||!r)return e;let i=(e,t,n)=>{let r=new Set(t);return e.filter(e=>r.has(n(e)))},{schematic:a}=e;return{...e,schematic:{...a,symbols:i(a.symbols,r.parts,e=>e.component),wires:i(a.wires,r.wires,e=>e.id),labels:i(a.labels,r.labels,e=>e.id),drawings:i(a.drawings,r.drawings,e=>e.id),junctions:r.junctions,...a.noConnects?{noConnects:i(a.noConnects,r.parts,e=>e.component)}:{}}}}function hy(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function gy(e,t){if(t===`Main`)return`${dy} is the first page and cannot be deleted`;let n=e?.schematic.pages?.find(e=>e.name===t)?.parts??[];if(n.length>0)return`Page ${t} still has parts (${n.join(`, `)}); move or delete them first`;let r=e?.circuit.connections.filter(e=>e.page===t)??[];if(r.length===0)return;let i=r.map(e=>`${e.from.replace(/^net\./,``)} to ${e.to.replace(/^net\./,``)}`).join(`, `);return`${t} still has ${r.length===1?`1 trace`:`${r.length} traces`}: ${i}; move or remove ${r.length===1?`it`:`them`} first`}function _y(e){return e===`Main`?`${dy} is the first page and keeps its name`:void 0}function vy(e,t){return e.status===`building`?`Building`:e.status===`failed`?`Build failed`:e.status!==`done`||!e.design?`Not built`:t===0?`Build OK`:`${t} ${t===1?`error`:`errors`}`}function yy(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function by({build:e,errors:t,onOpen:n}){return(0,X.jsxs)(`button`,{className:`build ${yy(e,t)}`,onClick:e=>{km(e),n()},title:`Show DRC`,children:[(0,X.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{role:`status`,children:vy(e,t)})]})}var xy=`light`,Sy=`copperflow.theme`,Cy=()=>typeof window>`u`?void 0:window.localStorage,wy=e=>e===`dark`||e===`light`?e:xy;function Ty(e){try{return wy(e()?.getItem(Sy))}catch{return xy}}function Ey(e,t){try{let n=e();return n?(n.setItem(Sy,t),!0):!1}catch{return!1}}function Dy(e,t){e.setAttribute(`data-theme`,t)}var Oy=e=>({themeLight:e===`light`,themeDark:e===`dark`}),ky=e=>e===`dark`?`dots`:`lines`,Ay=(e,t,n)=>t===n?e:jy(e,n),jy=(e,t)=>({...e,schematic:ky(t)}),My=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),Ny=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),Py=[My(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),My(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],Fy=[My(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),My(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),My(`fit`,`Fit all (K)`,`fit`,`fit`,1),My(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),My(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],Iy=e=>[My(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),My(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],Ly=e=>[My(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),My(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],Ry=e=>[My(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),My(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],zy=e=>My(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),By={schematic:[...Py,...Fy,...Ly(2),My(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),My(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),My(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),My(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),My(`ground`,`Ground flag`,`ground`,`groundFlag`,3),My(`power`,`Power flag`,`power`,`powerFlag`,3),My(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),My(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),My(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),My(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),My(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),My(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...Iy(5),...Ry(6),zy(7)],pcb:[...Py,...Fy,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...Ly(2),My(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),Ny(`boardOutline`,`Board outline`,`boardOutline`,_h,3),Ny(`copperArea`,`Copper area`,`copperArea`,_h,3),zy(4),My(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...Ry(6),...Iy(7),My(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function Vy(e,t,n={}){if(e.pending!==void 0)return{enabled:!1,title:`${e.title}: ${e.pending}`};let r=n[e.command];if(r!==void 0)return{enabled:!1,title:`${e.title}: ${r}`};let i=gh(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function Hy(e){let t=[];for(let n of By[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var Uy=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...O]);function Wy(e){return Uy.has(e)}var Gy={snap:`snap`};function Ky(e,t,n){let r=Gy[e];return r?n[r]:t===e}function qy(e){return Wy(e)||e in Gy}function Jy(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function Yy(e){return e?k[e]:null}var Xy={active:null,stop:null},Zy=Xy,Qy=new Set;function $y(e){if(e.active!==Zy.active||e.stop!==Zy.stop){Zy=e;for(let e of Qy)e()}}function eb(){return Zy}function tb(){$y(Xy)}function nb(e){return Qy.add(e),()=>{Qy.delete(e)}}function rb(){return(0,_.useSyncExternalStore)(nb,eb)}function ib(e,t){return t.active===e&&t.stop?`stop`:`run`}var ab=m(),ob=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function sb(){let e=e=>e.stopPropagation();return Object.fromEntries(ob.map(t=>[t,e]))}var cb=`toolbar-view-slot`,lb=sb();function ub({children:e}){let[t,n]=(0,_.useState)(null);return(0,_.useLayoutEffect)(()=>n(document.getElementById(cb)),[]),t?(0,ab.createPortal)((0,X.jsx)(`div`,{className:`canvas-tools`,...lb,onClick:km,children:e}),t):null}function db({item:e,unit:t}){if(e.text===`unit`)return(0,X.jsx)(X.Fragment,{children:t});let n=oh[e.icon];return(0,X.jsx)(n,{})}function fb({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=rb();return(0,X.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[Hy(e).map((e,s)=>(0,X.jsxs)(_.Fragment,{children:[s>0&&(0,X.jsx)(`span`,{className:`toolbar-separator`,role:`separator`,"aria-orientation":`vertical`}),e.map(e=>{let s=e.command!==void 0&&Ky(e.command,o.active,r),c=Vy(e,n,i);return(0,X.jsx)(`button`,{className:e.text?`toolbar-button text`:`toolbar-button`,title:c.title,"aria-label":e.text===`unit`?`${e.title}, now ${t}`:c.title,"aria-disabled":!c.enabled||void 0,"aria-pressed":e.command!==void 0&&qy(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{km(t),c.enabled&&e.command!==void 0&&(ib(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,X.jsx)(db,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,X.jsx)(`div`,{className:`toolbar-view-slot`,id:cb})]})}var pb=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function mb(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function hb(e){return[pb,...e.map(e=>[e.designators.join(` `),String(e.quantity),e.value||e.kind,e.footprint,e.manufacturer,e.mpn,e.supplier,e.libraryPart?e.verified?`yes`:`no`:``])].map(e=>e.map(mb).join(`,`)).join(`\r
15
+ `)+`\r
16
+ `}function gb(e){return`${(e.split(/[\\/]/).at(-1)??e).replace(/\.circuit\.tsx$|\.tsx$/,``)}-bom.csv`}var _b=[`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`,`F_Mask`,`B_Mask`,`F_Paste`,`B_Paste`,`F_Silkscreen`,`B_Silkscreen`,`Edge_Cuts`];function vb(e,t,n){let r=(e,t)=>n.find(t=>t.endsWith(e))??t;return`upload ${e.split(`/`).pop()??e} to JLCPCB's PCB order, and ${r(`-bom.csv`,`the BOM`)} and ${r(`-pick-and-place.csv`,`the pick-and-place file`)} from ${t}/ at its assembly step (the zip holds them too)`}var yb=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function bb(e){let t=`Checks: ${yb(e.errors,`error`)}, ${yb(e.warnings,`warning`)}.`;return e.errors>0?`${t} Run check_circuit (or copperflow check <file>) and fix the errors before anyone orders this board.`:t}var xb=3;function Sb(e){let t=e.slice(0,xb).map(e=>`Warning: ${e}.`),n=e.length-xb;return n>0?[...t,`And ${n} more ${n===1?`warning`:`warnings`}.`]:t}function Cb(e){if(!e.written)return`No fabrication files written: ${e.errors.join(`; `)}`;let t=vb(e.zip,e.folder,e.files),n=e.model===void 0?[]:[e.model];return[`Wrote ${e.files.length} fabrication files to ${e.folder}/ and ${e.zip}.`,`U${t.slice(1)}.`,...n,...Sb(e.warnings),bb(e.checks)].join(` `)}function wb(e){return e.errors>0}var Tb=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Eb(e){return`The design rule check reports ${Tb(e.errors,`error`)} and ${Tb(e.warnings,`warning`)}. Look at them before you order this board.`}var Db=1e-9,Ob=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),kb=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Ab=(e,t)=>({x:e.x*t,y:e.y*t}),jb=(e,t)=>e.x*t.y-e.y*t.x,Mb=(e,t)=>e.x===t.x&&e.y===t.y;function Nb(e){return e.every((t,n)=>n===0||tl(e[n-1],t)!==`slanted`)}function Pb(e){let t=e.map(e=>({x:V(e.x),y:V(e.y)})),n=t.filter((e,n)=>n===0||!Mb(t[n-1],e)),r=[];for(let[e,t]of n.entries()){let[i,a]=[r[r.length-1],n[e+1]];i&&a&&Math.abs(jb(Ob(t,i),Ob(a,t)))<Db||r.push(t)}return r}function Fb(e,t,n,r){let i=jb(t,r);if(!(Math.abs(i)<Db))return kb(e,Ab(t,jb(Ob(n,e),r)/i))}function Ib(e,t,n){let[r,i]=[e[t],e[t+1]],a=Ob(i,r),o=kb(r,n),s=(r,i)=>{let s=e[r],c=e[i],l=c&&Fb(c,Ob(s,c),o,a);return l?[l]:r===t?[s,kb(s,n)]:[kb(s,n),s]},c=t===0?[r,o]:s(t,t-1),l=t+1===e.length-1?[kb(i,n),i]:s(t+1,t+2);return[...e.slice(0,t),...c,...l,...e.slice(t+2)]}function Lb(e,t,n,r){let i={x:Ee(e.x+n.x,r.step,r.snap),y:Ee(e.y+n.y,r.step,r.snap)},a=Ob(t,e),o=Math.hypot(a.x,a.y);if(o<Db)return{x:0,y:0};let s={x:-a.y/o,y:a.x/o};return Ab(s,(i.x-e.x)*s.x+(i.y-e.y)*s.y)}function Rb(e,t,n,r){let i=e[t],a={x:Ee(i.x+n.x,r.step,r.snap),y:Ee(i.y+n.y,r.step,r.snap)};return e.map((e,n)=>n===t?a:e)}function zb(e,t,n,r){let i=e[t.index],a=e[t.index+1];if(!i||t.kind===`segment`&&!a)return[...e];let o;o=Nb(e)?Xl(e,t,n,r):t.kind===`corner`?Rb(e,t.index,n,r):Ib(e,t.index,Lb(i,a,n,r));let s=Pb(o);return s.length>=2?s:[...e]}var Bb=e=>Math.max(e.length-1,0),Vb=(e,t)=>Number.isInteger(t)&&t>=0&&t<Bb(e),Hb=e=>e.map(e=>({x:e.x,y:e.y}));function Ub(e,t){let n=Bb(e.points);if(!Vb(e.points,t))return{message:`${e.id} has no segment ${t}; it has ${n} (0 to ${n-1})`};if(e.locked)return{message:`${e.id} is locked`};let[r,i]=[e.points.slice(0,t+1),e.points.slice(t+1)].filter(e=>e.length>=2);if(!r)return{edits:[{kind:`removeTrack`,id:e.id}]};let a=e.net??e.carried,o=a===void 0?{}:{net:a},s={kind:`setTrack`,id:e.id,...e.net===void 0?o:{},points:Hb(r)};return i?{edits:[s,{kind:`addTrack`,...o,layer:e.layer,width:e.width,points:Hb(i)}]}:{edits:[s]}}var Wb={tracks:new Map,vias:new Map},Gb=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Kb=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),qb=(e,t)=>Math.hypot(t.x-e.at.x,t.y-e.at.y)<=e.diameter/2;function Jb(e,t,n){return e.vias.filter(r=>{if(!t.has(r.id))return!1;if(r.locked)return void n.push(`${r.id} is locked`);let i=e=>[e.points[0],e.points.at(-1)].some(e=>e!==void 0&&qb(r,e)),a=e.tracks.find(e=>e.locked&&i(e));return!a||void n.push(`${r.id} has the locked track ${a.id} on it`)})}function Yb(e,t,n,r,i){let a=t=>r.some(e=>qb(e,t))||!i(t,e.layer)&&!n.some(e=>qb(e,t)),[o,s]=[e.points[0],e.points.at(-1)];return Pb(ul(e.points,t,{start:a(o),end:a(s)}))}function Xb(e,t,n){let r=e.points.length-1,i=(e,t)=>(t===0||t===r)&&n.some(t=>qb(t,e));return e.points.some(i)?Pb(e.points.map((e,n)=>i(e,n)?Gb(e,t):e)):e.points}function Zb(e,t,n,r){let i=[];if(n.x===0&&n.y===0)return{edits:[],shapes:Wb,skipped:i};let a=new Set(t),o=Jb(e,a,i),s=new Map;for(let t of e.tracks){a.has(t.id)&&t.locked&&i.push(`${t.id} is locked`);let c=a.has(t.id)&&!t.locked?Yb(t,n,e.vias,o,r):Xb(t,n,o);!Kb(c,t.points)&&c.length>=2&&s.set(t.id,c)}let c=new Map(o.map(e=>[e.id,Gb(e.at,n)]));return{edits:[...[...c].map(([e,t])=>({kind:`setVia`,id:e,at:t})),...[...s].map(([e,t])=>({kind:`setTrack`,id:e,points:[...t]}))],shapes:{tracks:s,vias:c},skipped:i}}function Qb(e,t){if(!Kb(t,e.points))return e.locked?{message:`${e.id} is locked`}:{kind:`setTrack`,id:e.id,points:[...t]}}function $b(e,t){let n=new Set(t),r=[...e.tracks.map(e=>({...e,kind:`removeTrack`})),...e.vias.map(e=>({...e,kind:`removeVia`}))].filter(e=>n.has(e.id)),i=r.filter(e=>!e.locked);return{edits:i.map(e=>({kind:e.kind,id:e.id})),removed:i.map(e=>e.id),skipped:r.filter(e=>e.locked).map(e=>`${e.id} is locked`)}}function ex(e,t){if(!e)return{message:`${t.id} is gone`};if(!mo(t,e.points))return{message:`the track changed; select the segment again`};let n={...e.named===void 0?{}:{net:e.named},...e.net===void 0?{}:{carried:e.net}},r=Ub({id:e.id,...n,layer:e.layer,width:e.width,points:e.points,locked:e.locked},t.index);return`message`in r?r:{edits:r.edits,summary:`Delete segment ${t.index} of ${e.id}`}}function tx(e,t){return{tracks:new Map([...e.tracks,...t.tracks]),vias:new Map([...e.vias,...t.vias])}}function nx(e,t){return{tracks:e.tracks.map(e=>{let n=t.tracks.get(e.id);return n?{...e,points:[...n]}:e}),vias:e.vias.map(e=>{let n=t.vias.get(e.id);return n?{...e,at:n}:e})}}function rx(e,t,n){let r=new Set(t),i=e.tracks.filter(e=>r.has(e.id)&&e.locked!==n),a=e.vias.filter(e=>r.has(e.id)&&e.locked!==n),o=[...i.map(e=>({kind:`setTrack`,id:e.id,locked:n})),...a.map(e=>({kind:`setVia`,id:e.id,locked:n}))];return o.length===0?{message:`The selected copper is already ${n?`locked`:`unlocked`}.`}:{edits:o,summary:`${n?`Lock`:`Unlock`} ${H([...i,...a].map(e=>e.id))}`}}function ix(e,t){return!t&&e.copper.length>0&&e.total===e.copper.length}function ax(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):void 0}var ox=e=>/(^|\/)hole:\d+$/.test(e);function sx(e,t,n){return`${e} is a ${ox(e)?`hole`:`copper pour`} inside the sub-sheet instance ${t}; edit ${n??`its sheet file`} instead`}var cx=(e,t)=>e.x===t.x&&e.y===t.y,lx=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);function ux(e,t,n,r){let[i,a,o,s]=[lx(n,r,e),lx(n,r,t),lx(e,t,n),lx(e,t,r)];if((i>0&&a<0||i<0&&a>0)&&(o>0&&s<0||o<0&&s>0))return!0;let c=(e,t,n)=>Math.min(e.x,t.x)<=n.x&&n.x<=Math.max(e.x,t.x)&&Math.min(e.y,t.y)<=n.y&&n.y<=Math.max(e.y,t.y);return i===0&&c(n,r,e)||a===0&&c(n,r,t)||o===0&&c(e,t,n)||s===0&&c(e,t,r)}function dx(e){let t=e.length;if(t<3)return`an outline needs at least 3 corners`;if(e.some((n,r)=>cx(n,e[(r+1)%t])))return`two corners in a row are at the same place`;for(let n=0;n<t;n++)for(let r=n+1;r<t;r++){if(r===n+1||n===0&&r===t-1)continue;let[i,a,o,s]=[e[n],e[(n+1)%t],e[r],e[(r+1)%t]];if(ux(i,a,o,s))return`two of its edges cross`}let n=e.reduce((n,r,i)=>n+lx({x:0,y:0},r,e[(i+1)%t]),0);return Math.abs(n)<1e-9?`its corners are all on one line, so it has no area`:void 0}function fx(e,t){return`${t}:${e.filter(e=>e.tag===t).length+1}`}var px=3.2,mx=100,hx=e=>({tool:e,points:[]}),gx=(e,t)=>e.x===t.x&&e.y===t.y,_x=e=>({state:e});function vx(e){return e.filter((t,n)=>n===0||!gx(t,e[n-1]))}function yx(e){let t=vx(e.points);if(t.length>=3&&t.at(-1)&&gx(t[0],t.at(-1))&&t.pop(),t.length<3)return _x(e);let n=dx(t);return n?{state:e,refused:`Not closed: ${n}`}:{state:hx(e.tool),outline:t}}function bx(e,t,n){if(e.tool===`hole`)return{state:e,hole:t};if(n&&e.points.length>0)return yx(e);let r=e.points[0];return r&&e.points.length>=3&&gx(r,t)?yx(e):_x({...e,points:vx([...e.points,t])})}function xx(e,t){switch(t.type){case`press`:return bx(e,t.at,t.double);case`finish`:return e.tool===`pour`?yx(e):_x(e);case`removeCorner`:return _x({...e,points:e.points.slice(0,-1)});case`cancel`:return{state:e.points.length>0?hx(e.tool):null}}}function Sx(e,t){return!e||e.tool!==`pour`||e.points.length===0?[]:t?vx([...e.points,t]):[...e.points]}function Cx(e){let t=e.circuit.nets.flatMap(e=>e.names);return t.includes(`GND`)?`GND`:t[0]}function wx(e,t,n){return{kind:`addPour`,net:e,layer:t,...n?{outline:[...n]}:{}}}var Tx=(e,t,n)=>`add a ${e} copper pour on the ${t} layer${n?` over the whole board`:``}`;function Ex(e,t){return{kind:`addHole`,x:e.x,y:e.y,diameter:t}}var Dx=e=>`add a ${e} mm hole`;function Ox(e){let t=Number(e.trim().replace(/\s*mm$/i,``));return e.trim()===``||!Number.isFinite(t)||t<=0||t>mx?{message:`The diameter must be a number of mm above 0 and at most ${mx}`}:Math.round(t*1e3)/1e3}function kx(e,t,n,r){let i=t.map((e,t)=>t===n?{x:r.x,y:r.y}:{x:e.x,y:e.y}),a=dx(i);return a?{message:`Not moved: the outline would not be a simple polygon (${a})`}:{edit:{kind:`setPour`,id:e,props:{outline:i}},summary:`move a corner of ${e}`}}function Ax(e,t,n){let r=ax(n);if(r!==void 0)return sx(n,r,Ih({parts:e.parts??[],imports:e.imports??[]},r));let i=e.boardItems?.find(e=>e.id===n);return i?t.has(n)?`${n} is locked`:i.editable?null:`${n} is read-only (${i.readonlyReason})`:`${n} is not in the code yet`}var jx=e=>Number(e.slice(e.indexOf(`:`)+1)),Mx=e=>e.tag===`hole`?`hole ${jx(e.id)}`:`copper pour ${jx(e.id)}`;function Nx(e,t){return n=>{let r=n.map(n=>({id:n,blocker:Ax(e,t,n)})),i=r.flatMap(e=>e.blocker===null?[e.id]:[]);return{edits:[...i].sort((e,t)=>jx(t)-jx(e)).map(e=>ox(e)?{kind:`removeHole`,id:e}:{kind:`removePour`,id:e}),names:i.flatMap(t=>e.boardItems?.find(e=>e.id===t)??[]).map(Mx),skipped:r.flatMap(e=>e.blocker??[]),removed:i}}}var Px=`Esc or a right click stops.`;function Fx(e){if(e)return e.tool===`hole`?`Click where the hole goes; set its diameter in the field. ${Px}`:e.points.length===0?`Click the first corner of the copper pour. ${Px}`:`Click for each corner; double click, Enter or a click on the first corner closes the pour. Backspace removes a corner, Esc cancels.`}var Ix=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}],Lx=[{value:`inner1`,label:`Inner Layer 1`},{value:`inner2`,label:`Inner Layer 2`}],Rx=[{value:`relief`,label:`Relief (spokes)`},{value:`solid`,label:`Solid`}],zx=e=>String(Number(e.toFixed(4))),Bx=e=>e===void 0?`Not filled`:`${e.toFixed(2)} mm²`;function Vx(e,t){let n=e.circuit.nets.flatMap(e=>e.names[0]?[{value:e.names[0],label:e.names[0]}]:[]),r=e.pcb.pours.find(e=>e.id===t.id);return[{label:`Net`,value:Fu(e,t.net),field:`net`,choices:n},{label:`Layer`,value:t.layer,field:`layer`,choices:e.pcb.board?.layers===4?[...Ix,...Lx]:Ix},{label:`Priority`,value:String(t.priority),field:`priority`},{label:`Clearance (mm)`,value:t.clearance===void 0?``:zx(t.clearance),field:`clearance`},{label:`Min width (mm)`,value:zx(t.minWidth),field:`minWidth`},{label:`Thermal`,value:t.thermal,field:`thermal`,choices:Rx},{label:`Outline`,value:t.outline?`${t.outline.length} corners`:`Whole board`},{label:`Fill area`,value:Bx(r?.area)}]}function Hx(e){return[{label:`X (mm)`,value:zx(e.x),field:`x`},{label:`Y (mm)`,value:zx(e.y),field:`y`},{label:`Diameter (mm)`,value:zx(e.diameter),field:`diameter`}]}function Ux(e,t){let n=Nu(e).find(e=>e.id===t);if(n)return{kind:`pour`,title:`Copper pour`,rows:Vx(e,n)};let r=e.pcb.holes.find(e=>e.id===t);return r&&{kind:`hole`,title:`Hole`,rows:Hx(r)}}function Wx(e,t,n){let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)?{message:`${t} must be a number`}:n===`whole`&&!Number.isInteger(r)?{message:`${t} must be a whole number`}:n===`positive`&&r<=0?{message:`${t} must be above 0`}:r}function Gx(e,t){return e===`net`||e===`layer`||e===`thermal`?t:e===`clearance`&&t.trim()===``?null:Wx(t,e,e===`priority`?`whole`:`positive`)}function Kx(e,t){return e===`diameter`?Ox(t):Wx(t,e,`any`)}function qx(e,t,n,r){let i=Ux(e,t)?.rows.find(e=>e.field===n);if(!i||i.value===r.trim())return;let a=ox(t),o=a?Kx(n,r):Gx(n,r);if(typeof o==`object`&&o)return o;let s=`set ${t} ${n}=${o===null?`the net class's`:o}`;return a?{edit:{kind:`setHole`,id:t,props:{[n]:o}},summary:s}:{edit:{kind:`setPour`,id:t,props:{[n]:o}},summary:s}}function Jx(e,t){let n=ox(e)?`hole`:`copper pour`;return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this ${n}`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this ${n}, so the agent cannot change or remove it`}}function Yx(e,t,n,r=new Set){return Ct([...e.names,...e.board],t,n,r)}var Xx=.5,Zx=e=>Math.round(e*1e3)/1e3||0,Qx=e=>e.pcb??{x:0,y:0,rotation:0};function $x(e,t,n){let r=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].map(e=>iS(rS(e,t),n)),i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i),maxX:Math.max(...i),minY:Math.min(...a),maxY:Math.max(...a)}}var eS=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function tS(e,t,n,r){let i=[t,...n].filter(e=>!r(e.name)).map(e=>e.name);if(i.length>0)return`Place ${i.join(`, `)} on the board first (pcbX and pcbY on the instance), then replicate the layout.`;let a=sS(e,t);if(!a)return;let o=[t,...n].map(e=>({name:e.name,box:$x(a,Qx(t),Qx(e))}));for(let[e,t]of o.entries()){let n=o.slice(e+1).find(e=>eS(t.box,e.box));if(n)return`${t.name} and ${n.name} would overlap; place the instances apart first, then replicate the layout.`}}function nS(e,t){let n=t*Math.PI/180,[r,i]=Number.isInteger(t/90)?[[1,0],[0,1],[-1,0],[0,-1]][(t/90%4+4)%4]:[Math.cos(n),Math.sin(n)];return{x:e.x*r-e.y*i,y:e.x*i+e.y*r}}var rS=(e,t)=>nS({x:e.x-t.x,y:e.y-t.y},-t.rotation),iS=(e,t)=>{let n=nS(e,t.rotation);return{x:Zx(n.x+t.x),y:Zx(n.y+t.y)}};function aS(e,t){let n=gn(e,t)?.pcb;return n!==void 0&&(n.x!==0||n.y!==0)}function oS(e,t){for(let n of t){let t=gn(e,n)??gn(e,_n(e,n)?.outer??``);if(t)return t}}function sS(e,t){let n=new Set(t.parts),r=e.pcb.parts.filter(e=>n.has(e.component)).flatMap(e=>e.courtyard);if(r.length===0)return;let i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i)-Xx,maxX:Math.max(...i)+Xx,minY:Math.min(...a)-Xx,maxY:Math.max(...a)+Xx}}function cS(e,t,n=[]){if(t?.startsWith(`net.${e.path}/`))return!0;let r=new Set(e.parts);return n.length>0&&n.every(e=>r.has(e.split(`#`)[0]??``))}function lS(e,t,n,r,i=[]){if(n?.startsWith(`net.${t.path}/`))return!0;let a=new Set(t.parts);if(i.length>0&&i.every(e=>a.has(e.split(`#`)[0]??``)))return!0;let o=sS(e,t);return o!==void 0&&r.every(e=>e.x>=o.minX&&e.x<=o.maxX&&e.y>=o.minY&&e.y<=o.maxY)}function uS(e,t,n){let r=_n(e,t)?.localId;return e.circuit.components.find(e=>e.instance===n.path&&e.localId===r)?.id}function dS(e,t,n,r){if(t===void 0)return;if(t.startsWith(`net.${n.path}/`))return`net.${r.path}/${t.slice(`net.${n.path}/`.length)}`;if(t.startsWith(`net:`)){let[n,i]=t.slice(4).split(`.`),a=n===void 0?void 0:uS(e,n,r);return a&&i?`net:${a}.${i}`:void 0}let i=t.replace(/^net\./,``),a=n.ports.find(e=>!e.bus&&e.net===i),o=a&&r.ports.find(e=>e.name===a.name);return o?`net.${o.net}`:t}function fS(e,t){let n=Qx(t);return e.circuit.components.flatMap(r=>{if(r.instance!==t.path||r.localId===void 0||typeof r.props.pcbX==`number`&&typeof r.props.pcbY==`number`)return[];let i=e.pcb.parts.find(e=>e.component===r.id);if(!i)return[];let a=rS(i,n),o=((i.rotation-n.rotation)%360+360)%360,s={pcbX:Zx(a.x),pcbY:Zx(a.y),...o===0?{}:{pcbRotation:Zx(o)}};return[{kind:`setProps`,part:r.localId,props:s}]})}function pS(e,t,n,r){let i=t.tracks.filter(t=>lS(e,n,t.net,t.points,t.pads)),a=t.vias.filter(t=>lS(e,n,t.net,[t.at])),o=Qx(n);return r.flatMap(r=>{let s=Qx(r),c=e=>iS(rS(e,o),s),l=t=>{let i=dS(e,t,n,r);return i===void 0?{}:{net:i}},u=[...t.tracks.filter(e=>cS(r,e.net,e.pads)).map(e=>({kind:`removeTrack`,id:e.id})),...t.vias.filter(e=>cS(r,e.net)).map(e=>({kind:`removeVia`,id:e.id}))],d=[...i.map(e=>({kind:`addTrack`,...l(e.net),layer:e.layer,width:e.width,points:e.points.map(c)})),...a.map(e=>({kind:`addVia`,...l(e.net),at:c(e.at),drill:e.drill,diameter:e.diameter,layers:[...e.layers]}))];return[...u,...d]})}function mS(e,t,n){let r=t.filter(e=>n.has(e.name)||n.has(e.path)).map(e=>e.name);if(r.length===0)return;let[i,a]=r.length===1?[`is`,`it`]:[`are`,`them`];return`${r.join(`, `)} ${i} locked; unlock ${a} to replicate the layout of ${e.name} to ${a}.`}function hS(e,t,n,r=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let i=oS(e,t);if(!i)return{message:`Select a part of the instance whose layout to copy, or its symbol on the schematic.`};let a=(e.circuit.instances??[]).filter(e=>e.file===i.file&&e.path!==i.path&&!e.path.includes(`/`));if(a.length===0)return{message:`${i.name} is the only instance of ${i.sheet}; there is nothing to copy its layout to.`};let o=mS(i,a,r);if(o)return{message:o};let s=tS(e,i,a,n??(t=>aS(e,t)));if(s)return{message:s};let c=a.map(e=>e.name).join(`, `),l={file:i.file,edits:fS(e,i),summary:`Replicate the placement of ${i.name} in ${i.sheet}`},u={edits:pS(e,e.pcb,i,a),summary:`Replicate the copper of ${i.name} to ${c}`};return l.edits.length===0&&u.edits.length===0?{message:`${i.name} has no placement or copper the other instances lack.`}:{source:i.name,targets:a.map(e=>e.name),sheet:l,layout:u}}var gS={toggleUnit:`toggleUnit`,gridStyle:`toggleGridStyle`,snap:`toggleSnap`,toggleLeftPanel:`toggleLeftPanel`,toggleRightPanel:`toggleRightPanel`,toggleBottomPanel:`toggleBottomPanel`,clearHighlight:`clearHighlight`,placeComponent:`openLibrary`};[...w];var _S=[`wire`,`netLabel`,`groundFlag`,`powerFlag`,...O],vS=[`noConnect`,`junction`],yS=[`singleRouting`,`placeVia`,`routingCorner`],bS=[`placePour`,`placePourBoard`,`placeHole`],xS=[`filletTracks`,`straightenTracks`],SS=new Set;function CS(e){return SS.add(e),()=>{SS.delete(e)}}function wS(e){for(let t of SS)if(t(e))return!0;return!1}function TS(e){let t=(0,_.useRef)(e);t.current=e,(0,_.useEffect)(()=>CS(e=>{let n=t.current[e];return n?(n(),!0):!1}),[])}var ES=(e,t)=>e.by===`router`&&!e.locked&&(t===void 0||t.has(e.id)),DS=1e-6;function OS(e,t,n){let[r,i]=[n.x-t.x,n.y-t.y],a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function kS(e,t){if(t.at===void 0||t.diameter===void 0)return!1;let n=t.diameter/2+(e.width??0)/2+DS,r=t.at;return e.points.length===1?Math.hypot(e.points[0].x-r.x,e.points[0].y-r.y)<=n:e.points.some((t,i)=>i>0&&OS(r,e.points[i-1],t)<=n)}function AS(e,t={}){let n=t.ids===void 0?void 0:new Set(t.ids),r=[],i=e.tracks.filter(e=>{if(!ES(e,n))return!1;let i=t.lockedPart?.(e);return i!==void 0&&r.push(`${e.id} starts on the locked part ${i}`),i===void 0}),a=e.tracks.filter(e=>e.by!==`router`),o=[],s=e.vias.filter(e=>{if(!ES(e,n))return!1;let t=a.some(t=>kS(t,e));return t&&o.push(e.id),!t});return{edits:[...i.map(e=>({kind:`removeTrack`,id:e.id})),...s.map(e=>({kind:`removeVia`,id:e.id}))],skipped:r,kept:o}}var jS=[`top`,`bottom`,`inner1`,`inner2`],MS=e=>e===4?jS:[`top`,`bottom`],NS=({x0:e,x1:t,y0:n,y1:r})=>Math.max(0,t-e+1)*Math.max(0,r-n+1),PS=class{cell;cells=new Map;wide=[];constructor(e){if(this.cell=e,!(e>0))throw Error(`Grid cell size must be positive, got ${e}`)}insert(e,t){let n=this.rangeOf(t);NS(n)>4096?this.wide.push(e):FS(n,t=>{let n=this.cells.get(t);n===void 0?this.cells.set(t,[e]):n.push(e)})}query(e){let t=this.rangeOf(e),n=new Set(this.wide),r=e=>e?.forEach(e=>n.add(e));return NS(t)>4096?this.cells.forEach(r):FS(t,e=>r(this.cells.get(e))),[...n]}rangeOf(e){if(![e.minX,e.minY,e.maxX,e.maxY].every(Number.isFinite))throw Error(`Grid box must have finite bounds, got ${JSON.stringify(e)}`);let t=e=>Math.floor(e/this.cell);return{x0:t(e.minX),x1:t(e.maxX),y0:t(e.minY),y1:t(e.maxY)}}};function FS({x0:e,x1:t,y0:n,y1:r},i){for(let a=e;a<=t;a++)for(let e=n;e<=r;e++)i(`${a},${e}`)}var IS=[`top`,`inner1`,`inner2`,`bottom`],LS=1e-9,RS=(e,t)=>e.layers===`through`||e.layers===t,zS=e=>({core:[e],radius:0});function BS(e){return e.reduce((t,n,r)=>r===0?0:t+Math.hypot(n.x-(e[r-1]?.x??n.x),n.y-(e[r-1]?.y??n.y)),0)}function VS(e){let t=e.layers.map(e=>IS.indexOf(e));return new Set(IS.slice(Math.min(...t),Math.max(...t)+1))}function HS(e,t,n){return t!==void 0&&_i(t,zS(n))<=LS}function US(e,t,n){return e.flatMap(e=>e.pads.filter(e=>RS(e,n)&&HS(e,si(e),t)))}function WS(e,t){return _i(e,t)<=LS}function GS(e,t){if(t.length===0)return{message:`Select parts, or a sub-sheet instance, to route their connections.`};let n=t.length===1?gn(e,t[0]):void 0;if(n)return{kind:`instance`,instance:n.path};let r=new Set(t.map(t=>_n(e,t)?.outer)),[i]=r;if(r.size===1&&i!==void 0){let n=vn(e,i);if(n.length===t.length&&n.every(e=>t.includes(e)))return{kind:`instance`,instance:i}}return{kind:`parts`,parts:[...t]}}function KS(e){return e.length===0?{message:`Click a net in the Nets panel to highlight it, then Autoroute net.`}:{kind:`nets`,nets:[...e]}}function qS(e,t,n=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let r=Cn(n,e),i=t=>{let n=t.points[0];return n===void 0?void 0:US(e.pcb.parts,n,t.layer).find(e=>r.has(e.component))?.component},a=t.length===0?void 0:t,{edits:o,skipped:s}=AS(e.pcb,{...a?{ids:a}:{},lockedPart:i});if(o.length>0)return a?{ids:[...a]}:{};let c=a?`None of the selected copper was made by the router and unlocked; Unroute removes only that`:`The board has no unlocked router copper to remove`;return{message:s.length===0?`${c}.`:`${c}: ${s.join(`; `)}.`}}function JS(e,t){if(t.length===0)return{message:`Select the parts to place first.`};let n=t.flatMap(t=>gn(e,t)?.parts??[t]);return{kind:`parts`,parts:[...new Set(n)]}}function YS(e,t){for(let n of t){let t=gn(e,n)?.path??_n(e,n)?.outer;if(t!==void 0)return{kind:`instance`,instance:t}}return{message:`Select a part of a sub-sheet instance, or its symbol on the schematic, to place that instance.`}}function XS(e,t,n){let r=e.ask(t,n)?.trim();return r===void 0||r===``?void 0:r}async function ZS(e){let t=XS(e,`Name of the new page`,hy(fy(e.design)));t!==void 0&&await e.edit([{kind:`addPage`,name:t}],`add page ${t}`)&&e.openPage(t)}async function QS(e){let t=_y(e.page);if(t)return e.notify(t);let n=XS(e,`New name for page ${e.page}`,e.page);n!==void 0&&n!==e.page&&await e.edit([{kind:`renamePage`,from:e.page,to:n}],`rename page ${e.page} to ${n}`)&&e.openPage(n)}async function $S(e){let t=gy(e.design,e.page);if(t)return e.notify(t);let n=fy(e.design).indexOf(e.page),r=fy(e.design)[Math.max(0,n-1)]??`Main`;await e.edit([{kind:`removePage`,name:e.page}],`delete page ${e.page}`)&&e.openPage(r)}function eC(e,t){return e===`addPage`?ZS(t):e===`renamePage`?QS(t):$S(t)}function tC(e,t){return t===`Main`?[...e]:e.map(e=>(e.kind===`addPart`||e.kind===`addDrawing`||e.kind===`addTrace`)&&e.page===void 0?{...e,page:t}:e)}function nC(e){let t=dn(e),n=`strokeWidth`in e?e.strokeWidth/2:0;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function rC(e){let t=[...vc(e).map(e=>e.box),...df(e).map(e=>e.box)];t.push(...e.labels.map(Dr),...e.drawings.map(nC));let n=ke([...e.wires.flatMap(e=>e.points),...e.junctions]);return n&&t.push(n),Ae(t)}var iC=.04;function aC(e,t){let n=document.createElement(`canvas`);n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(r)return r.fillStyle=t,r.fillRect(0,0,e.width,e.height),{canvas:n,ctx:r}}function oC(e,t,n){let r=my(e,t).schematic,i=rC(r),a=Mo(`light`),o=i&&aC(n,a.background);if(i&&o)return Fo(a),_c(o.ctx,r,{camera:xe(i,n,iC),size:n},{ratio:1}),o.canvas.toDataURL(`image/png`)}function sC(e,t){let n=e.pcb,r=ke(n.board?.outline??[])??Ae(n.parts.map(e=>({minX:e.x-1,minY:e.y-1,maxX:e.x+1,maxY:e.y+1}))),i=r&&aC(t,Ev());if(!r||!i)return;let a=xe(r,t,iC);return Yf(i.ctx,n,{camera:a,size:t},{ratio:1,copper:{tracks:n.tracks,vias:n.vias,selected:new Set}}),i.canvas.toDataURL(`image/png`)}function cC(e,t,n=wy(document.documentElement.getAttribute(`data-theme`))){let r=Ov(),i=[];try{for(let n of fy(e)){let a=oC(e,n,r);a&&i.push({title:`${t} · Schematic · ${n}`,image:a,...r})}}finally{Fo(Mo(n))}let a=sC(e,r);return a&&i.push({title:`${t} · PCB`,image:a,...r}),i}function lC(e,t){let n=window.open(``,`_blank`);return n?(n.document.open(),n.document.write(Mv(e,t)),n.document.close(),n.focus(),n.setTimeout(()=>n.print(),0),!0):!1}var uC=12.7,dC=e=>Math.round(e*1e3)/1e3+0;function fC(e,t,n){let r=t.find(t=>t.name===e);return r?n.has(e)?`locked`:r.editable?void 0:`read-only`:`inside a sub-sheet; change it in its sheet`}function pC(e,t,n){let r=[],i=[];for(let a of e){let e=fC(a,t,n);e===void 0?r.push(a):i.push(`${a} (${e})`)}return{ok:r,skipped:i}}var mC=e=>e.length===0?``:`; left ${e.join(`, `)}`;function hC(e,t,n,r){let i=e.filter(e=>t.some(t=>t.component===e));if(i.length===0)return{message:`Select a part on the PCB to flip.`};let{ok:a,skipped:o}=pC(i,n,r);if(a.length===0)return{message:`Cannot flip ${o.join(`, `)}.`};let s=a.map(e=>{let r=t.find(t=>t.component===e),i=n.find(t=>t.name===e)?.props??{},a=i.pcbX||i.pcbY?{}:{pcbX:dC(r.x),pcbY:dC(r.y)};return{kind:`setProps`,part:e,props:{layer:r.side===`bottom`?`top`:`bottom`,...a}}}),c=new Set(a.map(e=>t.find(t=>t.component===e)?.side)),l=c.size===1?c.has(`bottom`)?` to the top`:` to the bottom`:``;return{edits:s,summary:`flip ${a.join(`, `)}${l}${mC(o)}`,skipped:o}}var gC=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length});function _C(e){let t=[...new Set(e.map(e=>e.page??0))].sort((e,t)=>e-t),n=new Map,r=0;for(let i of t){let t=e.filter(e=>(e.page??0)===i),a=Math.min(...t.map(e=>e.x)),o=Math.max(...t.map(e=>e.x)),s=gC(t).y;for(let e of t)n.set(e.component,{x:r+(e.x-a)*uC,y:(e.y-s)*uC});r+=(o-a)*uC+10}let i=gC([...n.values()]);return new Map([...n].map(([e,t])=>[e,{x:t.x-i.x,y:t.y-i.y}]))}function vC(e,t,n,r,i){let a=e.filter(e=>t.some(t=>t.component===e)&&n.some(t=>t.component===e));if(a.length===0)return{message:`No part is on both the schematic and the PCB.`};let{ok:o,skipped:s}=pC(a,r,i);if(o.length===0)return{message:`${s.join(`, `)} cannot move: locked or read-only.`};let c=o.map(e=>t.find(t=>t.component===e)),l=_C(c),u=gC(o.map(e=>n.find(t=>t.component===e)));return{edits:c.map(e=>{let t=l.get(e.component),n=e.rotation===void 0?{}:{pcbRotation:e.rotation};return{kind:`setProps`,part:e.component,props:{pcbX:dC(u.x+t.x),pcbY:dC(u.y+t.y),...n}}}),summary:`place ${o.length===1?o[0]:`${o.length} parts`} as on the schematic${mC(s)}`,skipped:s}}var yC=(e,t)=>e.kind===t.kind&&e.footprint===t.footprint&&e.value===t.value;function bC(e,t,n,r){let i=t.find(t=>t.id===e.parts[0]);if(i){let e=t.filter(e=>yC(e,i)).map(e=>e.id),n=[i.kind,i.value,i.footprint].filter(e=>e!==void 0&&e!==``).join(`, `);return{parts:e,drawings:[],note:`Selected ${e.length} ${e.length===1?`part`:`parts`} like ${i.id} (${n})`}}let a=n.find(t=>t.id===e.drawings[0]);if(a){let e=n.filter(e=>e.kind===a.kind).map(e=>e.id);return{parts:[],drawings:e,note:`Selected ${e.length} ${a.kind} ${e.length===1?`drawing`:`drawings`}`}}let o=e.board?.[0];if(o!==void 0){let e=o.split(`:`)[0]??o,t=(r??[]).filter(t=>t.split(`:`)[0]===e);return{parts:[],drawings:[],board:t,note:`Selected ${t.length} ${e===`copperpour`?`copper pour`:e}${t.length===1?``:`s`}`}}return{message:`Select a part, a drawing, a pour or a hole first; Find similar objects selects the ones like it.`}}var xC=/^([A-Za-z_]+)(\d+)$/;function SC(e,t){return!e.at||!t.at?e.at?-1:t.at?1:e.name.localeCompare(t.name):e.at.page-t.at.page||t.at.y-e.at.y||e.at.x-t.at.x||e.name.localeCompare(t.name)}function CC(e,t){let n=new Set(t.filter(e=>!e.renamable).map(e=>Number(xC.exec(e.name)?.[2]))),r=1;return[...t].filter(e=>e.renamable).sort(SC).map(t=>{for(;n.has(r);)r++;return{from:t.name,to:`${e}${r++}`}})}function wC(e){let t=new Map;for(let n of e){let e=xC.exec(n.name)?.[1];e!==void 0&&t.set(e,[...t.get(e)??[],n])}let n=[...t].flatMap(([e,t])=>CC(e,t)).filter(e=>e.from!==e.to);if(n.length===0)return{message:`Every designator is already numbered in order.`};let r=n.slice(0,4).map(e=>`${e.from} → ${e.to}`).join(`, `);return{edit:{kind:`renameParts`,mapping:n},summary:`annotate designators: ${r}${n.length>4?` and ${n.length-4} more`:``}`}}var TC={sch:.5,pcb:2.54},EC=new Set([`name`,`pinLabels`]),DC=new Set([`from`,`to`,`schematicRouteHints`]),OC=/(pin\d+)\s*:\s*["']([A-Za-z_][\w]*)["']/g;function kC(e){if(!e)return;let t=Object.fromEntries([...e.matchAll(OC)].map(e=>[e[1],e[2]]));return Object.keys(t).length>0?t:void 0}function AC(e){let t=e===void 0?void 0:Kt(e);return t?t.kind===`net`?void 0:t.part:null}var jC=e=>e.slice(0,e.lastIndexOf(`/`)+1);function MC(e,t,n=``){let r=e.parts.filter(e=>t.includes(e.name)),i=r.filter(t=>e.imports.some(e=>e.local===t.tag&&/\.sheet(\.tsx)?$/.test(e.source))),a=r.filter(e=>!i.includes(e));if(a.length===0)return{message:i.length>0?`Sub-sheet instances are not copied; make another instance from the sheet instead.`:`Select the parts to copy first.`};let o=[],s=a.map(t=>{let n={};for(let[e,r]of Object.entries(t.props))EC.has(e)||(r.literal===void 0?o.push(`${t.name}.${e}`):n[e]=r.literal);let r=kC(t.props.pinLabels?.source);t.props.pinLabels&&!r&&o.push(`${t.name}.pinLabels`);let i=e.imports.find(e=>e.local===t.tag)?.source;return{tag:t.tag,name:t.name,props:n,...r?{pinLabels:r}:{},...i?{importFrom:i}:{}}});o.push(...i.map(e=>`${e.name} (a sub-sheet instance)`));let c=new Set(a.map(e=>e.name));return{parts:s,traces:e.traces.flatMap(e=>{let t=[AC(e.from),AC(e.to)];if(t.some(e=>e===null))return[];let n=t.filter(e=>typeof e==`string`);if(n.length===0||n.some(e=>!c.has(e)))return[];let r=Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>DC.has(e)||t.literal===void 0?[]:[[e,t.literal]]));return[{from:e.from,to:e.to,props:r,...e.schematicRouteHints?{hints:e.schematicRouteHints}:{}}]}),left:o,folder:jC(n),anchor:PC(s)}}var NC=(e,t)=>t===void 0?void 0:e.startsWith(`pcb`)?ei(t):typeof t==`number`?t:void 0;function PC(e){let t=(t,n)=>{let r=e.flatMap(e=>{let[r,i]=[NC(t,e.props[t]),NC(n,e.props[n])];return r===void 0||i===void 0?[]:[{x:r,y:i}]});return r.length===0?void 0:{x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length}},n=t(`schX`,`schY`),r=t(`pcbX`,`pcbY`);return{...n?{sch:n}:{},...r?{pcb:r}:{}}}var FC=/^([A-Za-z_]+?)(\d+)$/;function IC(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=FC.exec(t)?.[1]??`${t}_`,i=1;for(;n.has(`${e}${i}`);)i++;let a=`${e}${i}`;n.add(a),r.set(t,a)}return r}var LC=e=>Math.round(e*1e4)/1e4+0;function RC(e,t,n){let r=e=>({x:e*n,y:-e*n}),i={sch:r(TC.sch),pcb:r(TC.pcb)},a=t?e.anchor[t.view]:void 0;return!t||!a?i:{...i,[t.view]:{x:LC(t.at.x-a.x),y:LC(t.at.y-a.y)}}}function zC(e,t,n){let r=e===`schX`?n.sch.x:e===`schY`?n.sch.y:e===`pcbX`?n.pcb.x:e===`pcbY`?n.pcb.y:void 0;if(r===void 0)return t;let i=NC(e,t);return i===void 0?t:LC(i+r)}function BC(e,t){let n=Kt(e);return n?.kind===`pin`?`${t.get(n.part)??n.part}.${n.pin}`:e}function VC(e,t,n,r){if(!e.importFrom)return;let i=r.imports.find(t=>t.local===e.tag);return i?i.source===e.importFrom?void 0:{message:`${e.tag} is imported from "${i.source}" here, not "${e.importFrom}"; paste into a file that imports it the same way`}:jC(n.file??``)===t.folder?e.importFrom:{message:`${e.name} needs "${e.importFrom}", which is relative to another folder; paste it into a circuit in that folder, or add the import first`}}function HC(e,t,n={}){let r=[...t.parts.map(e=>e.name),...t.drawings.flatMap(e=>[e.id,e.name??``]),...n.taken??[]],i=IC(e.parts.map(e=>e.name),r),a=n.page,o=a===void 0||a===`Main`?{}:{page:a},s=n.shift??RC(e,void 0,1),c=[];for(let r of e.parts){let a=VC(r,e,n,t);if(typeof a==`object`)return a;c.push({kind:`addPart`,tag:r.tag,name:i.get(r.name),props:Object.fromEntries(Object.entries(r.props).map(([e,t])=>[e,zC(e,t,s)])),...r.pinLabels?{pinLabels:r.pinLabels}:{},...a?{importFrom:a}:{},...o})}let l=e.traces.map(e=>({kind:`addTrace`,from:BC(e.from,i),to:BC(e.to,i),...Object.keys(e.props).length>0?{props:e.props}:{},...e.hints?{schematicRouteHints:e.hints.map(e=>({x:LC(e.x+s.sch.x),y:LC(e.y+s.sch.y)}))}:{},...o})),u=[...i.values()];return{edits:[...c,...l],summary:`paste ${u.length===1?u[0]:`${u.length} parts (${u.join(`, `)})`}`,names:u}}var UC={};function WC(e,t){t?UC[e]=t:delete UC[e]}function GC(e){return UC[e]}var KC=e=>new Set(e?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));function qC(e,t){if(`message`in t)return e.notify(t.message);e.edit(t.edits,t.summary)}function JC({design:e,circuit:t,selection:n,actions:r}){e&&t&&qC(r,hC(n.names,e.pcb.parts,t.model.parts,KC(t)))}function YC({design:e,circuit:t,selection:n,actions:r}){if(!e||!t)return;let i=n.names.length>0?n.names:e.pcb.parts.map(e=>e.component),a=e.schematic.pages??[],o=e=>Math.max(0,a.findIndex(t=>t.parts.includes(e)));qC(r,vC(i,e.schematic.symbols.map(e=>({component:e.component,x:e.x,y:e.y,page:o(e.component),rotation:e.rotation})),e.pcb.parts,t.model.parts,KC(t)))}function XC({design:e,circuit:t,actions:n}){if(!e||!t)return;let r=KC(t),i=e.schematic.pages??[],a=new Set(e.circuit.components.filter(e=>e.kind===`sheet`).map(e=>e.id)),o=t.model.parts.filter(e=>!a.has(e.name)).map(t=>{let n=e.schematic.symbols.find(e=>e.component===t.name),a=Math.max(0,i.findIndex(e=>e.parts.includes(t.name)));return{name:t.name,renamable:t.editable&&!r.has(t.name),...n?{at:{page:a,x:n.x,y:n.y}}:{}}}),s=new Set(t.model.parts.map(e=>e.name)),c=e.circuit.components.filter(e=>!s.has(e.id)&&e.kind!==`sheet`).map(e=>({name:e.id,renamable:!1})),l=wC([...o,...c]);if(`message`in l)return n.notify(l.message);n.renameParts(l.edit.mapping,l.summary).then(e=>e.ok&&n.notify(`Annotated ${l.edit.mapping.length} designators`))}var ZC,QC=0;function $C({circuit:e,selection:t,actions:n}){if(!e)return;let r=MC(e.model,t.names,e.file);if(`message`in r)return n.notify(r.message);ZC=r,QC=0;let i=r.parts.length===1?r.parts[0]?.name??``:`${r.parts.length} parts`,a=r.traces.length>0?` and ${r.traces.length} ${r.traces.length===1?`trace`:`traces`}`:``,o=r.left.length>0?`; left out ${r.left.join(`, `)}`:``;n.notify(`Copied ${i}${a}${o}`)}function ew({design:e,circuit:t,select:n,actions:r},i,a){if(!t)return;if(!ZC)return r.notify(`Copy some parts first (Ctrl+C).`);let o=GC(a),s=RC(ZC,o?{view:a,at:o}:void 0,QC+1),c=new Set(t.model.parts.map(e=>e.name)),l=(e?.circuit.components??[]).map(e=>e.id).filter(e=>!c.has(e)),u=HC(ZC,t.model,{file:t.file,...i?{page:i}:{},taken:l,shift:s});if(`message`in u)return r.notify(u.message);QC+=1;let{edits:d,summary:f,names:p}=u;r.edit(d,f).then(e=>{e&&(n(()=>_o.none.all(p)),r.notify(`Pasted ${p.join(`, `)}`))})}function tw({design:e,circuit:t,selection:n,select:r,actions:i}){if(!e)return;let a=e.circuit.components.map(e=>({id:e.id,kind:e.kind,...e.footprint?{footprint:e.footprint}:{},...e.value?{value:e.value}:{}})),o=(t?.model.boardItems??[]).map(e=>e.id),s=bC({parts:n.names,drawings:n.drawings,board:n.board},a,e.schematic.drawings,o);if(`message`in s)return i.notify(s.message);r(()=>_o.none.all(s.parts).addDrawings(s.drawings).addBoard(s.board??[])),i.notify(s.note)}var nw=new Set([..._S,...vS]),rw=new Set([...yS,...xS,...bS]),iw=e=>nw.has(e)?`schematic`:rw.has(e)?`pcb`:void 0,aw=gS;function ow(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.route(t)}function sw(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.autoplace(t)}function cw(e){let t=new Set(e.circuit?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part)),n=qS(e.design,e.selection.copper,t);if(`message`in n)return e.actions.notify(n.message);e.actions.unroute(n.ids)}function lw(e,t){let{design:n,page:r,actions:i,openPage:a}=e;eC(t,{design:n,page:r,edit:i.edit,notify:i.notify,ask:(e,t)=>window.prompt(e,t),openPage:a})}function uw(e,t){e&&(t.notify(`Exporting the BOM and datasheets…`),z(`/api/package`,{file:e}).then(e=>t.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>t.notify(e.message)))}function dw(e,t){let{design:n,file:r,actions:i}=e;if(!n||!r)return i.notify(`Wait for the build to finish, then try again.`);let a=cC(n,r);if(a.length===0)return i.notify(`Nothing to print yet: the circuit has no parts.`);let o=r.replace(/\.circuit\.tsx$/,``);if(!lC(o,a))return i.notify(`The browser blocked the print window; allow pop-ups for Studio and try again.`);i.notify(t?`Choose "Save as PDF" in the print dialog to save ${o}.pdf (${a.length} sheets)`:`Printing ${a.length} sheets`)}function fw(e){if(e.file){if(wb(e.checkCounts))return e.openDialog(`exportChecks`);pw(e.file,e.actions)}}function pw(e,t){e&&(t.notify(`Writing the fabrication files…`),z(`/api/export`,{file:e}).then(e=>t.notify(Cb(e))).catch(e=>t.notify(e.message)))}var mw=1e6;function hw(e,t){let n=Object.assign(document.createElement(`input`),{type:`file`,accept:`.dxf,.kicad_pcb`});n.addEventListener(`change`,()=>{let r=n.files?.[0];if(!r)return;let i=/\.kicad_pcb$/i.test(r.name);if(r.size>mw)return e.notify(`${r.name} is larger than 1 MB; import it with the agent's import_board or ${i?`copperflow import kicad`:`copperflow board --dxf`}`);r.text().then(async n=>{if(!i)return void await e.importBoard(r.name,n);let a=await e.importKicad(r.name,n);a!==void 0&&t(a)}).catch(t=>e.notify(t.message))}),n.click()}function gw(e,t){e&&z(`/api/bom?file=${encodeURIComponent(e)}`).then(({lines:n})=>{let r=URL.createObjectURL(new Blob([hb(n)],{type:`text/csv`}));Object.assign(document.createElement(`a`),{href:r,download:gb(e)}).click(),URL.revokeObjectURL(r),t.notify(`Saved ${gb(e)}`)}).catch(e=>t.notify(e.message))}function _w(e,t){let{copper:n}=e.selection;if(n.length>0&&e.copperRecords){let r=rx(e.copperRecords,n,t);if(`message`in r?e.actions.notify(r.message):e.actions.editLayout(r.edits,r.summary),e.selection.size+e.selection.boardCount===0)return}vw(e,t)}function vw(e,t){let n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=new Set(e.circuit?.violations.map(e=>e.part)),i=Yx(e.selection,n,t,r);if(`message`in i)return e.actions.notify(i.message);e.actions.lock(i.parts,t)}function yw(e){let t=xn(e.design,e.selection.names);if(!t)return e.actions.notify(`Select a part of a sub-sheet instance, or its symbol on the schematic, first.`);let n=e.view===`schematic`?e.selection.names.flatMap(t=>gn(e.design,t)?.path??_n(e.design,t)?.outer??[]):t;e.select(e=>e.all([...new Set(n)]))}async function bw(e){let t=t=>{let n=e.circuit?.model.parts.find(e=>e.name===t)?.props;return n?.pcbX!==void 0&&n.pcbY!==void 0},n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=hS(e.design,e.selection.names,t,n);if(`message`in r)return e.actions.notify(r.message);let{sheet:i,layout:a}=r;(a.edits.length===0?await e.actions.editFile(i.file,i.edits,i.summary):await e.actions.editLayout(a.edits,i.edits.length===0?a.summary:`${a.summary} and its placement`,i.edits.length===0?void 0:{file:i.file,edits:i.edits})).ok&&e.actions.notify(`Copied the layout of ${r.source} to ${r.targets.join(`, `)}`)}function xw(e){let t=zh(e.circuit?.model,e.selection.names);if(`message`in t)return e.actions.notify(t.message);e.openDialog(`makeSheet`)}function Sw(e,t){let n=aw[t];return n?()=>e.workspace.run(n):{openFile:e.workspace.openPageTree,exportBom:()=>gw(e.file,e.actions),exportPackage:()=>uw(e.file,e.actions),exportFabrication:()=>fw(e),undo:()=>void e.actions.undo(),redo:()=>void e.actions.redo(),selectAll:()=>e.select(Ya(e.circuit?.model.parts.map(e=>e.name)??[],e.pickLayers,e.pickFilter,e.sheetWires,e.sheetLabels,e.sheetDrawings,e.pcbCopper)),selectInstance:()=>yw(e),replicateLayout:()=>void bw(e),makeSheet:()=>xw(e),find:e.openFind,checkDrc:e.openChecks,designRules:()=>e.openDialog(`rules`),autoplace:()=>sw(e,{kind:`all`}),autoplaceSelection:()=>sw(e,JS(e.design,e.selection.names)),autoplaceInstance:()=>sw(e,YS(e.design,e.selection.names)),fitBoard:()=>void e.actions.fitBoard(),importBoardDxf:()=>hw(e.actions,e.openImported),autoroute:()=>ow(e,{kind:`all`}),autorouteSelection:()=>ow(e,GS(e.design,e.selection.names)),autorouteNet:()=>ow(e,KS(e.highlight)),unroute:()=>cw(e),lock:()=>_w(e,!0),unlock:()=>_w(e,!1),history:()=>e.workspace.openBottom(`log`),keys:()=>e.openDialog(`keys`),about:()=>e.openDialog(`about`),addPage:()=>lw(e,`addPage`),renamePage:()=>lw(e,`renamePage`),deletePage:()=>lw(e,`deletePage`),themeLight:()=>e.workspace.setTheme(`light`),themeDark:()=>e.workspace.setTheme(`dark`),hoverLabels:e.workspace.toggleHoverLabels,pourSolid:()=>e.workspace.setPourFill(nd.pourSolid),pourHatched:()=>e.workspace.setPourFill(nd.pourHatched),pourOutline:()=>e.workspace.setPourFill(nd.pourOutline),findSimilar:()=>tw(e),placementTransfer:()=>YC(e),flip:()=>JC(e),annotate:()=>XC(e),systemSettings:()=>e.openDialog(`system`),newCircuit:()=>e.openDialog(`newCircuit`),footprintManager:()=>e.openDialog(`footprints`),packages:p_,print:()=>dw(e,!1),exportPdf:()=>dw(e,!0),copy:()=>$C(e),paste:()=>ew(e,e.view===`schematic`?e.page:void 0,e.view===`schematic`?`sch`:`pcb`)}[t]}var Cw=[`undo`,`redo`,`openFile`,`selectAll`,`find`,`findSimilar`,`placementTransfer`,`flip`,`copy`,`paste`],ww=e=>Cw.includes(e??``);function Tw(e,t){(0,_.useEffect)(()=>{let n=n=>{let r=Yd(Pd(n),{view:t})?.action;ww(r)&&(r!==`copy`||(window.getSelection()?.toString()??``)===``)&&(n.preventDefault(),e(r))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function Ew(e){let[t,n]=(0,_.useState)(null),{file:r,openImported:i,view:a,setView:o,selection:s,select:c,circuit:l,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:v,openChecks:y,checkCounts:b,openFind:x,openDialog:S,design:C,page:w,openPage:T,highlight:E}=e,{run:ee,openBottom:D,openPageTree:O,setTheme:k,toggleHoverLabels:A,setPourFill:j}=e.workspace;(0,_.useEffect)(()=>{if(!t||a!==t.view)return;let e=window.setTimeout(()=>{n(null),wS(t.command)||u.notify(`The ${t.view===`pcb`?`PCB`:`schematic`} is still building; try again in a moment.`)},0);return()=>window.clearTimeout(e)},[t,a,u]);let te=(0,_.useCallback)(e=>{let t=Sw({file:r,openImported:i,view:a,setView:o,selection:s,select:c,circuit:l,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:v,workspace:{run:ee,openBottom:D,openPageTree:O,setTheme:k,toggleHoverLabels:A,setPourFill:j},openChecks:y,checkCounts:b,openFind:x,openDialog:S,design:C,page:w,openPage:T,highlight:E},e);if(t)return t();let _=iw(e);_&&a!==_?(o(_),n({command:e,view:_})):wS(e)||u.notify(`Wait for the build to finish, then try again.`)},[r,i,a,o,s,c,l,u,d,f,p,m,h,g,v,ee,D,O,k,A,j,y,b,x,S,C,w,T,E]);return Tw(te,a),te}function Dw({file:e,buildId:t,actions:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1);(0,_.useEffect)(()=>{z(`/api/bom?file=${encodeURIComponent(e)}`).then(e=>{i(e.lines),o(e.report)}).catch(e=>n.notify(e.message))},[e,t,n]);let l=r.reduce((e,t)=>e+t.quantity,0);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`h3`,{children:[`Bill of materials `,(0,X.jsxs)(`span`,{className:`count`,children:[l,` parts`]})]}),a&&(0,X.jsx)(`pre`,{className:`order-report`,children:a}),(0,X.jsxs)(`table`,{className:`bom`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Parts`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Supplier`})]})}),(0,X.jsx)(`tbody`,{children:r.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsxs)(`td`,{children:[e.designators.join(`, `),e.libraryPart&&!e.verified&&(0,X.jsx)(`span`,{className:`badge unverified`,children:`Unverified`})]}),(0,X.jsx)(`td`,{title:e.footprint,children:e.value||e.kind}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`code`,{children:e.supplier.replace(/^\w+ /,``)})})]},e.designators.join(` `)))})]}),(0,X.jsx)(`button`,{disabled:s,onClick:()=>{c(!0),z(`/api/package`,{file:e}).then(e=>n.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>n.notify(e.message)).finally(()=>c(!1))},children:s?`Exporting`:`Export BOM and datasheets`})]})}var Ow=`No problems found.`,kw=e=>e===`error`?0:1,Aw=e=>e.startsWith(`net.`)||e.includes(`:`);function jw(e){return e.items.find(e=>!Aw(e))?.split(/[#.]/,1)[0]||void 0}function Mw(e,t){let n=jw(e);return n!==void 0&&t.has(n)?n:void 0}function Nw(e,t,n,r){let i=e.items.filter(e=>n.has(e)),a=e.items.filter(e=>Pw(r).has(e)),o=e.at??(e.view===`pcb`?a.map(e=>qu(r,e)).find(e=>e!==void 0):void 0);if(i.length>0||a.length>0)return{...e,...i.length>0?{copper:i}:{},...a.length>0?{board:a}:{},...o?{at:o}:{}};let s=Mw(e,t);return s===void 0?e:{...e,part:s}}function Pw(e){let t=e.pcb;return new Set([...t?.board?.pours??[],...t?.holes??[]].map(e=>e.id))}function Fw(e){let t=e.pcb;return new Set([...t?.tracks??[],...t?.vias??[]].map(e=>e.id))}function Iw(e){let t={id:e.id,severity:e.severity,code:e.code,message:e.message,items:e.items,view:e.view};return e.at?{...t,at:e.at}:t}var Lw=(e,t)=>({id:`diagnostic:${t}`,severity:e.severity,code:e.code,message:e.message,items:e.items,view:`code`}),Rw=(e,t)=>e<t?`${e} ${t}`:`${t} ${e}`;function zw(e,t){if(t?.state!==`done`)return[];let n=new Map(e.pcb.ratsnest.map(e=>[Rw(e.from,e.to),e]));return t.unrouted.flatMap(e=>{let t=n.get(Rw(e.from,e.to));if(t===void 0)return[];let r={x:(t.a.x+t.b.x)/2,y:(t.a.y+t.b.y)/2};return[{id:`route:${e.from}:${e.to}`,severity:`warning`,code:`unrouted`,message:e.reason,items:[e.from,e.to,...e.blockers],view:`pcb`,at:r}]})}function Bw(e,t){let n=new Set(e.circuit.components.map(e=>e.id)),r=Fw(e);return[...e.violations.map(Iw),...zw(e,t),...e.diagnostics.map(Lw)].map(t=>Nw(t,n,r,e)).sort((e,t)=>kw(e.severity)-kw(t.severity))}function Vw(e){return[...new Set(e.map(e=>e.code))].map(t=>{let n=e.filter(e=>e.code===t);return{code:t,severity:n.some(e=>e.severity===`error`)?`error`:`warning`,rows:n}})}function Hw(e,t){return e.flatMap(e=>e.view===t&&e.at?[{id:e.id,at:e.at,severity:e.severity}]:[])}function Uw(e){let t=e.filter(e=>e.severity===`error`).length;return{errors:t,warnings:e.length-t}}var Ww=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Gw({errors:e,warnings:t}){let n=[...e>0?[Ww(e,`error`)]:[],...t>0?[Ww(t,`warning`)]:[]];return n.length===0?Ow:n.join(`, `)}function Kw({label:e,htmlFor:t,children:n}){return(0,X.jsxs)(`div`,{className:`insp-row`,children:[(0,X.jsx)(`label`,{className:`insp-label`,htmlFor:t,title:e,children:(0,X.jsx)(`span`,{children:e})}),(0,X.jsx)(`div`,{className:`insp-value`,children:n})]})}function qw({title:e,open:t,onToggle:n,children:r}){return(0,X.jsxs)(`section`,{className:t?`insp-section`:`insp-section collapsed`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`insp-head hairline-t`,"aria-expanded":t,onClick:n,children:[(0,X.jsx)(rh,{className:`insp-chevron`}),(0,X.jsx)(`span`,{className:`insp-title`,children:e})]}),(0,X.jsx)(`div`,{className:`insp-body`,hidden:!t,children:r})]})}function Jw({name:e,prop:t,disabled:n,onCommit:r,notify:i}){let a=t.literal===void 0?t.source:String(t.literal),[o,s]=(0,_.useState)(a);return(0,_.useEffect)(()=>s(a),[a]),t.editable?(0,X.jsx)(Kw,{label:e,htmlFor:`prop-${e}`,children:(0,X.jsx)(`input`,{id:`prop-${e}`,value:o,disabled:n,spellCheck:!1,onChange:e=>s(e.target.value),onBlur:()=>{if(o===a)return;let n=Zw(t.literal,o);n===void 0?(i(`${e} needs ${typeof t.literal==`number`?`a number`:`true or false`}`),s(a)):r(n).then(e=>e||s(a))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&s(a)}})}):(0,X.jsx)(Kw,{label:e,children:(0,X.jsx)(`code`,{className:`expr`,title:`An expression; change it in the code`,children:t.source.replace(/\s+/g,` `)})})}var Yw=new Set([`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`pinCount`,`order`,`base`]);function Xw({name:e,example:t,disabled:n,onCommit:r}){let[i,a]=(0,_.useState)(``);return(0,X.jsx)(Kw,{label:e,htmlFor:`new-prop-${e}`,children:(0,X.jsx)(`input`,{id:`new-prop-${e}`,className:`new-prop`,placeholder:t,value:i,disabled:n,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{let t=i.trim();t&&r(Yw.has(e)&&Number.isFinite(Number(t))?Number(t):t).then(e=>e&&a(``))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})})}function Zw(e,t){if(typeof e==`number`){let e=Number(t);return t.trim()!==``&&Number.isFinite(e)?e:void 0}return typeof e==`boolean`?t===`true`||t!==`false`&&void 0:t}function Qw({label:e,onAdd:t}){let[n,r]=(0,_.useState)(``),i=(0,_.useId)();return(0,X.jsxs)(`form`,{className:`mark-form`,onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim()).then(e=>e&&r(``))},children:[(0,X.jsx)(`label`,{htmlFor:i,children:e}),(0,X.jsxs)(`div`,{className:`inline`,children:[(0,X.jsx)(`input`,{id:i,value:n,onChange:e=>r(e.target.value),placeholder:`Route ground under this part`}),(0,X.jsx)(`button`,{type:`submit`,children:`Add`})]})]})}function $w({part:e,kind:t,footprint:n,disabled:r,onEdit:i}){return(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>f_.open({purpose:{kind:`inspector`,part:e},kind:t,initial:n,choose:t=>{if(t===n)return;let{edits:r,summary:a}=c_(e,t);i(r,a)}}),title:`Search the standard packages and see their pads and shape`,children:`Choose a package…`})})}var eT={rotate:$m,lock:Ym,unlock:Xm,delete:eh};function tT({view:e,parts:t,others:n,locks:r,run:i,onClear:a,collapsed:o,toggle:s}){let{locked:c}=r,l=new Map(t.map(e=>[e.name,e])),u=e=>{let t=Zg(e);if(t)return(0,X.jsx)(Kw,{label:Yg[t.kind],children:(0,X.jsx)(`span`,{className:`static`,children:t.count})},e);let n=e.slice(5),r=l.get(n);return(0,X.jsx)(Kw,{label:n,children:(0,X.jsxs)(`span`,{className:`static`,children:[r?.tag,c.has(n)?`, locked`:``]})},e)};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:e.header}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:$g.map(({label:e,command:a})=>{let o=eT[a];return(0,X.jsxs)(`button`,{className:a===`delete`?`danger`:void 0,disabled:!e_(a,t,r,n),onClick:()=>i(a),children:[(0,X.jsx)(o,{}),` `,e]},a)})}),e.sections.map(e=>(0,X.jsx)(qw,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(u)},e.title))]})}function nT(){let e=null;return{answer(t){return e=t,()=>{e===t&&(e=null)}},send(t){return e?(e(t),!0):!1}}}var rT=nT();function iT(e){let t=e;return{set(e){t=e},call:e=>t(e)}}var aT=`Label`;function oT({design:e,label:t,run:n,notify:r,onClear:i,collapsed:a,toggle:o}){let s=lm(e,t);return s?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:i,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{title:`Rename this label's net`,onClick:()=>{rT.send({kind:`renameLabel`,labelId:t})||r(`Open the schematic to rename this label.`)},children:`Rename`}),(0,X.jsx)(`button`,{title:`Light this label's net in both views`,onClick:()=>n(`highlight`),children:`Highlight net`})]}),(0,X.jsx)(qw,{title:aT,open:!a.has(aT),onToggle:()=>o(aT),children:s.rows.map(e=>(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}var sT={path:`line`,rect:`rectangle`,circle:`circle`,arc:`arc`,text:`text`,bus:`bus`,junction:`junction`},cT=(e,t)=>({x:V(e.x+t.x),y:V(e.y+t.y)}),lT=e=>e.kind===`path`||e.kind===`bus`,uT=e=>lT(e)?[`points`]:[`x`,`y`],dT=(e,t)=>e.drawings.find(e=>e.id===t);function fT(e,t,n,r=[]){let i=dT(e,n);if(!i)return`${n} has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason??`not a literal element`})`;let a=r.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}var pT=(e,t,n)=>fT(e,t,n.id,uT(n));function mT(e){return e.kind===`path`||e.kind===`bus`?e.points[0]??{x:0,y:0}:{x:e.x,y:e.y}}function hT(e,t,n){let r=e.props[t]?.literal;return typeof r==`number`?r:V(n)}function gT(e,t,n){if(lT(t))return{points:(e.points??[]).map(e=>cT(e,n))};let{groupOffset:r}=t,i=mT(t);return{x:V(hT(e,`x`,i.x-r.x)+n.x),y:V(hT(e,`y`,i.y-r.y)+n.y)}}function _T(e,t){let{groupOffset:n}=e;return e.kind===`path`||e.kind===`bus`?`points`in t?{...e,points:t.points.map(e=>cT(e,n))}:e:`x`in t?{...e,x:V(t.x+n.x),y:V(t.y+n.y)}:e}function vT(e){return e.length>1?[`${e.length} drawings`]:e.map(e=>e.name??`the ${sT[e.kind]}`)}function yT(e,t,n,r,i){let a=t.find(e=>e.id===n),o=dT(e,n);if(!a)return{id:n,blocker:`${n} is not on the sheet`};let s=pT(e,i,a);return s||!o?{id:n,blocker:s??`${n} has no editable source element`}:{id:n,drawing:a,placed:gT(o,a,r)}}function bT(e,t,n,r,i){let a=n.map(n=>yT(e,t,n,r,i)),o=a.flatMap(e=>`placed`in e?[e]:[]);return{edits:o.map(({id:e,placed:t})=>({kind:`setDrawingProps`,id:e,props:{...t}})),names:vT(o.map(e=>e.drawing)),skipped:a.flatMap(e=>`blocker`in e?[e.blocker]:[]),shown:o.map(({drawing:e,placed:t})=>_T(e,t))}}function xT(e,t,n){return r=>{let i=r.map(t=>({id:t,blocker:fT(e,n,t)})),a=i.flatMap(e=>e.blocker??[]),o=i.flatMap(e=>e.blocker===null?[e.id]:[]),s=t=>dT(e,t)?.start??0,c=[...o].sort((e,t)=>s(t)-s(e)),l=o.flatMap(e=>t.find(t=>t.id===e)??[]);return{edits:c.map(e=>({kind:`removeDrawing`,id:e})),names:vT(l),skipped:a,removed:o}}}var ST=/^[A-Za-z_][A-Za-z0-9_]*$/,CT=/^G(\d+)$/;function wT(e){let t=[...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``])];return`G${Math.max(0,...t.map(e=>Number(CT.exec(e)?.[1]??0)))+1}`}function TT(e,t,n,r){if(t===`bus`?rn(n)===void 0:!ST.test(n))throw new Lh(`invalid`,`"${n}" is not a valid ${t===`bus`?`bus`:`drawing`} name; use ${t===`bus`?`a net name such as "CLK" or a range such as "D[0:7]"`:`letters, digits and _`}`);if(e.parts.some(e=>e.name===n))throw new Lh(`invalid`,`A part named ${n} already exists`);let i=(e,r)=>t===`bus`&&e===`bus`&&r===n;if(e.drawings.some(e=>e.id!==r&&(e.name===n||e.id===n)&&!i(e.tag,e.name)))throw new Lh(`invalid`,`A drawing named ${n} already exists`)}function ET(e,t){if(typeof t==`string`&&t!==``)return e!==`bus`||rn(t)!==void 0?t:void 0}function DT(e,t){return`drawing:${e}:${t}`}function OT(e,t){let n=2;for(;e.has(`${t}~${n}`);)n++;return`${t}~${n}`}function kT(e,t){let n=new Set(t),r=new Set,i=new Map;return e.map(({kind:e,name:t})=>{let a=(i.get(e)??0)+1;i.set(e,a);let o=t??DT(e,a);if(!n.has(o))return n.add(o),e===`bus`&&r.add(o),{id:o,base:o};let s=OT(n,o);return n.add(s),{id:s,base:o,repeat:e===`bus`&&r.has(o)?`piece`:`duplicate`}})}var AT=`Name the bus, such as D[0:7] or CLK`;function jT(e,t){return new Set([...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``]),...t])}function MT(e,t=[]){let n=jT(e,t),r=1;for(;n.has(`BUS${r}`);)r++;return`BUS${r}`}function NT(e,t,n){let r=t.trim();if(r===``)return AT;try{TT(e,`bus`,r,n);return}catch(e){return e instanceof Error?e.message:String(e)}}function PT(e,t){return e.drawings.map(e=>{let n=en(e.tag)??`path`;return{kind:n,name:e.id===t?.id?t.name:ET(n,e.name)}})}var FT=(e,t,n)=>kT(t,e.parts.map(e=>e.name))[n]?.id??``;function IT(e,t,n=[]){let r=n.filter(e=>e===t).map(e=>({kind:`bus`,name:e})),i=[...PT(e),...r,{kind:`bus`,name:t}];return FT(e,i,i.length-1)}function LT(e,t,n){let r=e.drawings.findIndex(e=>e.id===t);return r<0?n:FT(e,PT(e,{id:t,name:n}),r)}function RT(e){let t=`${e.length} member${e.length===1?``:`s`}`;return`${e.length>2?`${e[0]} … ${e.at(-1)}`:e.join(`, `)}, ${t}`}var zT={x:{label:`X`,field:`number`},y:{label:`Y`,field:`number`},points:{label:`Points`,field:`points`},width:{label:`Width`,field:`number`,rule:`positive`},height:{label:`Height`,field:`number`,rule:`positive`},radius:{label:`Radius`,field:`number`,rule:`positive`},startAngle:{label:`Start angle`,field:`number`},endAngle:{label:`End angle`,field:`number`},text:{label:`Text`,field:`text`},fontSize:{label:`Font size`,field:`number`,rule:`positive`},anchor:{label:`Anchor`,field:`choice`,options:$t},strokeWidth:{label:`Stroke width`,field:`number`,rule:`nonNegative`},lineStyle:{label:`Line style`,field:`choice`,options:Qt},color:{label:`Colour`,field:`color`},filled:{label:`Filled`,field:`check`}},BT=[`strokeWidth`,`lineStyle`,`color`],VT={path:[`points`,...BT],rect:[`x`,`y`,`width`,`height`,...BT,`filled`],circle:[`x`,`y`,`radius`,...BT,`filled`],arc:[`x`,`y`,`radius`,`startAngle`,`endAngle`,...BT],text:[`x`,`y`,`text`,`fontSize`,`anchor`,`color`],bus:[`points`],junction:[`x`,`y`,`color`]},HT={path:`Line`,rect:`Rectangle`,circle:`Circle`,arc:`Arc`,text:`Text`,bus:`Bus`,junction:`Junction`},UT=e=>e.map(e=>`${e.x}, ${e.y}`).join(`; `);function WT(e,t){let{groupOffset:n}=e;if((e.kind===`path`||e.kind===`bus`)&&t===`points`)return UT(e.points.map(e=>({x:V(e.x-n.x),y:V(e.y-n.y)})));let r=e[t];return t===`x`||t===`y`?String(V(r-n[t])):r===void 0?``:String(r)}function GT(e,t,n,r){let i=zT[n],a=t?.props[n],o=a!==void 0&&!a.editable,s=n===`color`?{placeholder:Po().drawing}:{},c=i.options?{options:i.options}:{},l=o?a.source:WT(e,n);return{key:n,label:i.label,value:l,field:i.field,...c,...s,editable:r&&t!==void 0&&!o}}var KT=`Renames this piece of the bus only; its wires keep their nets`;function qT(e,t,n){return e.kind===`bus`?[{key:`name`,label:`Name`,value:e.name,field:`text`,editable:n&&t?.name!==void 0,hint:KT},{key:`members`,label:`Members`,value:RT(e.members),field:`static`,editable:!1}]:[{key:`name`,label:`Name`,value:e.name??`(none)`,field:`static`,editable:!1}]}function JT(e,t,n){let r=t?.line??e.source.line;return[{key:`kind`,label:`Kind`,value:`${HT[e.kind]}, line ${r}`,field:`static`,editable:!1},...qT(e,t,n),...VT[e.kind].map(r=>GT(e,t,r,n))]}var YT=/^#[0-9A-Fa-f]{6}$/,XT={any:{ok:()=>!0,says:`must be a number`},positive:{ok:e=>e>0,says:`must be a number greater than 0`},nonNegative:{ok:e=>e>=0,says:`must be a number of 0 or more`}};function ZT(e){let t=e.split(`;`).map(e=>e.split(`,`).map(e=>e.trim())).map(e=>e.length===2&&e.every(e=>e!==``&&Number.isFinite(Number(e)))?{x:V(Number(e[0])),y:V(Number(e[1]))}:void 0);return t.length>=2&&t.every(e=>e!==void 0)?t:void 0}function QT(e,t){let n=t.trim();if(e.field===`number`){let t=XT[e.rule??`any`],r=Number(n);return n!==``&&Number.isFinite(r)&&t.ok(r)?r:{message:`${e.label} ${t.says}`}}return e.field===`points`?ZT(n)??{message:`${e.label} needs two or more x, y pairs, such as 0, 0; 1, 0`}:e.field===`choice`?e.options?.includes(n)?n:{message:`${e.label} must be one of ${e.options?.join(`, `)}`}:e.field===`check`?n===`true`||n===`false`?n===`true`:{message:`${e.label} must be true or false`}:e.field===`color`?YT.test(n)?n:{message:`${e.label} must be a colour such as "#000080"`}:t===``?{message:`${e.label} cannot be empty`}:t}function $T(e,t,n){let r=t.trim(),i=NT(n,r,e.id);return i?{message:i}:{edit:{kind:`setDrawingProps`,id:e.id,props:{name:r}},summary:`rename the bus ${e.name} to ${r}`}}function eE(e,t,n,r){if(t===`name`&&e.kind===`bus`&&r)return $T(e,n,r);let i=zT[t];if(!i)return{message:`${t} cannot be set here`};let a=QT(i,n);if(typeof a==`object`&&!Array.isArray(a))return a;let o=e.name??`the ${sT[e.kind]}`,s=Array.isArray(a)?`set ${o} ${t}`:`set ${o} ${t}=${JSON.stringify(a)}`;return{edit:{kind:`setDrawingProps`,id:e.id,props:{[t]:a}},summary:s}}var tE=`Drawing`;function nE({design:e,circuit:t,drawing:n,locked:r,actions:i,onRename:a,run:o,onClear:s,collapsed:c,toggle:l}){let u=e.schematic.drawings.find(e=>e.id===n);if(!u)return null;let d=fT(t.model,r,n),f=JT(u,dT(t.model,n),d===null),p=(e,r)=>{let o=eE(u,e,r,t.model);if(`message`in o)return i.notify(o.message),Promise.resolve(!1);let{edit:s}=o,c=s.kind===`setDrawingProps`?s.props.name:void 0,l=typeof c==`string`?a({from:n,to:LT(t.model,n,c)}):void 0;return i.edit([s],o.summary).catch(()=>!1).then(e=>(e||l?.(),e))};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:s,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:d!==null,title:d??`Delete this drawing (Delete)`,onClick:()=>o(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})}),d&&(0,X.jsxs)(`p`,{className:`note`,children:[d,`.`]}),(0,X.jsx)(qw,{title:tE,open:!c.has(tE),onToggle:()=>l(tE),children:f.map(e=>(0,X.jsx)(rE,{row:e,onCommit:t=>p(e.key,t)},`${u.id}:${e.key}`))})]})}function rE({row:e,onCommit:t}){let n=(0,_.useId)();return e.field===`static`||!e.editable?(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:e.field===`static`?`static`:`expr`,title:e.value,children:e.value})}):e.field===`check`?(0,X.jsx)(Kw,{label:e.label,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e.value===`true`,onChange:e=>void t(String(e.target.checked))})}):e.field===`choice`?(0,X.jsx)(Kw,{label:e.label,htmlFor:n,children:(0,X.jsx)(`select`,{id:n,value:e.value,onChange:e=>void t(e.target.value),children:e.options?.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})}):(0,X.jsx)(iE,{id:n,row:e,onCommit:t})}function iE({id:e,row:t,onCommit:n}){let[r,i]=(0,_.useState)(t.value);return(0,_.useEffect)(()=>i(t.value),[t.value]),(0,X.jsx)(Kw,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:r,placeholder:t.placeholder,title:t.hint,spellCheck:!1,onChange:e=>i(e.target.value),onBlur:()=>{r!==t.value&&n(r).then(e=>e||i(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&i(t.value)}})})}var aE={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},oE={human:`You`,agent:`The agent`,router:`The router`},sE=e=>`${Math.round(e*1e3)/1e3} mm`;function cE(e,t){return t===void 0?`No net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function lE(e,t){return[{label:`Net`,value:cE(e,t.net)},{label:`Layer`,value:t.layer,field:`layer`},{label:`Width`,value:String(t.width),field:`width`},{label:`Length`,value:sE(BS(t.points))},{label:`Drawn by`,value:oE[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function uE(e,t){let[n=`top`,r=`bottom`]=[t.layers[0],t.layers.at(-1)];return[{label:`Net`,value:cE(e,t.net)},{label:`Layers`,value:`${aE[n]} to ${aE[r]}`},{label:`Drill`,value:sE(t.drill)},{label:`Diameter`,value:sE(t.diameter)},{label:`Drawn by`,value:oE[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function dE(e,t){let n=e.pcb.tracks.find(e=>e.id===t);if(n)return{kind:`track`,title:`Track`,locked:n.locked,rows:lE(e,n)};let r=e.pcb.vias.find(e=>e.id===t);return r&&{kind:`via`,title:`Via`,locked:r.locked,rows:uE(e,r)}}var fE=e=>`(${Math.round(e.x*1e3)/1e3}, ${Math.round(e.y*1e3)/1e3}) mm`;function pE(e,t){let n=e.pcb.tracks.find(e=>e.id===t.id);if(!n||!Vb(n.points,t.index)||!mo(t,n.points))return;let[r,i]=[n.points[t.index],n.points[t.index+1]];return{kind:`segment`,title:`Segment`,locked:n.locked,rows:[{label:`Net`,value:cE(e,n.net)},{label:`Track`,value:n.id},{label:`Length`,value:sE(BS([r,i]))},{label:`Start`,value:fE(r)},{label:`End`,value:fE(i)}]}}function mE(e,t){let n=t===`true`;if(n!==e.locked)return{edit:{kind:e.points?`setTrack`:`setVia`,id:e.id,locked:n},summary:`${n?`Lock`:`Unlock`} ${e.id}`}}function hE(e,t,n){if(t===`lock`)return mE(e,n);if(e.locked)return{message:`${e.id} is locked`};if(t===`width`){let t=Number(n.trim());return n.trim()===``||!Number.isFinite(t)||t<=0?{message:`The width must be a number of mm above 0`}:t===e.width?void 0:{edit:{kind:`setTrack`,id:e.id,width:t},summary:`Set the width of ${e.id} to ${t} mm`}}return n!==`top`&&n!==`bottom`?{message:`The layer must be top or bottom`}:n===e.layer?void 0:{edit:{kind:`setTrack`,id:e.id,layer:n},summary:`Move ${e.id} to the ${n} layer`}}var gE=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}];function _E({design:e,id:t,segment:n,actions:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=n?.id===t?pE(e,n):void 0;if(c)return(0,X.jsx)(vE,{shown:c,id:t,run:i,onClear:a,collapsed:o,toggle:s});let l=dE(e,t),u=e.pcb.tracks.find(e=>e.id===t)??e.pcb.vias.find(e=>e.id===t);if(!l||!u)return null;let d=async(e,t)=>{let n=hE(u,e,t);return n?`message`in n?(r.notify(n.message),!1):(await r.editLayout([n.edit],n.summary)).ok:!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:l.locked,title:l.locked?`${t} is locked`:`Delete this ${l.kind} (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})}),(0,X.jsx)(qw,{title:l.title,open:!o.has(l.title),onToggle:()=>s(l.title),children:l.rows.map(e=>(0,X.jsx)(yE,{row:e,locked:l.locked,onCommit:d},e.label))})]})}function vE({shown:e,id:t,run:n,onClear:r,collapsed:i,toggle:a}){return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:r,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:e.locked,title:e.locked?`${t} is locked`:`Delete this segment of the track (Delete)`,onClick:()=>n(`delete`),children:[(0,X.jsx)(eh,{}),` Delete segment`]})}),(0,X.jsx)(qw,{title:e.title,open:!i.has(e.title),onToggle:()=>a(e.title),children:e.rows.map(e=>(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function yE({row:e,locked:t,onCommit:n}){let r=(0,_.useId)();return e.field===`lock`?(0,X.jsx)(Kw,{label:e.label,htmlFor:r,children:(0,X.jsx)(`input`,{id:r,type:`checkbox`,checked:e.value===`true`,onChange:e=>void n(`lock`,String(e.target.checked))})}):e.field===`layer`?(0,X.jsx)(Kw,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,disabled:t,onChange:e=>void n(`layer`,e.target.value),children:[gE.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!gE.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value===`inner1`?`Inner Layer 1`:`Inner Layer 2`})]})}):e.field===`width`?(0,X.jsx)(bE,{id:r,value:e.value,locked:t,onCommit:e=>n(`width`,e)}):(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})})}function bE({id:e,value:t,locked:n,onCommit:r}){let[i,a]=(0,_.useState)(t);return(0,_.useEffect)(()=>a(t),[t]),(0,X.jsx)(Kw,{label:`Width (mm)`,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,disabled:n,inputMode:`decimal`,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{i!==t&&r(i).then(e=>e||a(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t)}})})}function xE({design:e,circuit:t,id:n,locks:r,actions:i,run:a,onClear:o,collapsed:s,toggle:c}){let l=Ux(e,n);if(!l)return null;let u=Ax(t.model,r.locked,n),d=Jx(n,r),f=async(t,r)=>{let a=qx(e,n,t,r);return a?`message`in a?(i.notify(a.message),!1):i.edit([a.edit],a.summary):!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:o,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsxs)(`button`,{className:d.pressed?`toggle on`:`toggle`,"aria-pressed":d.pressed,title:d.title,onClick:()=>a(d.command),children:[d.pressed?(0,X.jsx)(Ym,{}):(0,X.jsx)(Xm,{}),d.label]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:u!==null,title:u??`Delete this ${l.kind===`hole`?`hole`:`copper pour`} (Delete)`,onClick:()=>a(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})]}),(0,X.jsx)(qw,{title:l.title,open:!s.has(l.title),onToggle:()=>c(l.title),children:l.rows.map(e=>(0,X.jsx)(SE,{row:e,disabled:u!==null,onCommit:f},e.label))})]})}function SE({row:e,disabled:t,onCommit:n}){let r=(0,_.useId)(),{field:i,choices:a}=e;return!i||t?(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value===``?`Net class`:e.value})}):a?(0,X.jsx)(Kw,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,onChange:e=>void n(i,e.target.value),children:[a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!a.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value})]})}):(0,X.jsx)(CE,{id:r,row:e,field:i,onCommit:n})}function CE({id:e,row:t,field:n,onCommit:r}){let[i,a]=(0,_.useState)(t.value);return(0,_.useEffect)(()=>a(t.value),[t.value]),(0,X.jsx)(Kw,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,inputMode:`decimal`,spellCheck:!1,placeholder:n===`clearance`?`Net class`:void 0,onChange:e=>a(e.target.value),onBlur:()=>{i!==t.value&&r(n,i).then(e=>e||a(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t.value)}})})}var wE=.001,TE=e=>e.flatMap(e=>e.kind===`junction`&&e.x!==void 0&&e.y!==void 0?[{id:e.id,x:e.x,y:e.y}]:[]);function EE(e,t){for(let n=1;n<t.length;n++){let[r,i]=[t[n-1],t[n]],[a,o]=[i.x-r.x,i.y-r.y],s=a*a+o*o,c=s===0?0:Math.max(0,Math.min(1,((e.x-r.x)*a+(e.y-r.y)*o)/s));if(Math.hypot(r.x+c*a-e.x,r.y+c*o-e.y)<=wE)return{segment:n-1,t:c}}}var DE=(e,t)=>t.some(t=>EE(e,t)!==void 0);function OE(e,t){let n=t[0];for(let r=1;r<t.length;r++){let[i,a]=[t[r-1],t[r]],[o,s]=[a.x-i.x,a.y-i.y],c=o*o+s*s,l=c===0?0:Math.max(0,Math.min(1,((e.x-i.x)*o+(e.y-i.y)*s)/c)),u={x:i.x+l*o,y:i.y+l*s};Math.hypot(u.x-e.x,u.y-e.y)<Math.hypot(n.x-e.x,n.y-e.y)&&(n=u)}return n}var kE=e=>Math.round(e*1e3)/1e3;function AE(e,t,n,r){return n.length<2?[]:e.flatMap(e=>{let i=EE(e,t);if(i===void 0||DE(e,r))return[];let a=n.length===t.length,[o,s]=[n[i.segment],n[i.segment+1]],c=a?{x:o.x+i.t*(s.x-o.x),y:o.y+i.t*(s.y-o.y)}:OE(e,n),l={x:kE(c.x),y:kE(c.y)};return Math.abs(l.x-e.x)<wE&&Math.abs(l.y-e.y)<wE?[]:[{kind:`setDrawingProps`,id:e.id,props:l}]})}function jE(e,t,n){return e.filter(e=>DE(e,t)&&!DE(e,n)).map(e=>e.id)}var ME=`This wire is no longer on the sheet`,NE=`This wire has no corners`,PE=`Studio draws this wire's corner; the code has none to remove`,FE=`This wire repeats another between the same ends; delete it in the code`;function IE(e,t){let n=e.schematic.wires.find(e=>e.id===t);return n&&Tp(e.circuit.nets,n.net)}function LE(e,t){let n=IE(e,t),r=e.circuit.nets.find(e=>e.id===n);return r?Jp(r):(n??``).replace(/^net\./,``)}var RE=(e,t)=>`This wire has no trace of its own: Studio draws it for net ${LE(e,t)}`,zE=e=>e.startsWith(`net.`)?`net ${e.slice(4)}`:e;function BE(e,t){let{writer:n}=t;if(n.kind===`engine`)return[Rn(e,n.from)?.id??zE(n.from),Rn(e,n.to)?.id??zE(n.to)];let r=e.schematic.wires.find(e=>e.id===t.id),i=e.circuit.connections.find(e=>e.id===r?.connection);return i?[zE(i.from),zE(i.to)]:void 0}function VE(e,t){let n=BE(e,t);return n?`the wire from ${n[0]} to ${n[1]}`:`the wire`}function HE(e,t,n){let{writer:r}=t;if(r.kind===`none`)return r.reason;if(r.kind===`engine`)return RE(e,t.id);let i=xr(e,r.components,r.trace,n);return i===void 0?r.repeat?FE:r.trace.editable?null:`This wire is read-only (${r.trace.readonlyReason}); delete it in the code`:`${i} is locked`}function UE(e,t,n){if(t.writer.kind!==`trace`)return HE(e,t,n);if(t.points.length<=2)return NE;let r=q(e,t,n);return r===null?(t.writer.trace.schematicRouteHints?.length??0)>0?null:PE:r}function WE(e){let t=e.writer.kind===`trace`?e.writer.trace:void 0;return{from:t?.from??``,to:t?.to??``}}function GE(e,t,n){let r=HE(e,t,n);return r===null?{edits:[{kind:`removeTrace`,...WE(t)}],summary:`remove ${VE(e,t)}`}:{blocked:r}}function KE(e,t,n){let r=UE(e,t,n);return r===null?{edits:[{kind:`setTraceHints`,...WE(t),schematicRouteHints:[]}],summary:`remove the corners of ${VE(e,t)}`}:{blocked:r}}var qE=e=>`blocked`in e?e.blocked:null;function JE(e,t,n){return{remove:qE(GE(e,t,n)),removeCorners:qE(KE(e,t,n))}}function YE(e,t,n){let r=t?VE(e,t):`the wire`,i=r.charAt(0).toUpperCase()+r.slice(1);return n.startsWith(`This wire`)?`${i}${n.slice(9)}`:`${i}: ${n}`}function XE(e,t){if(t.writer.kind!==`none`)return t.writer.components;let n=e.circuit.connections.find(n=>n.id===e.schematic.wires.find(e=>e.id===t.id)?.connection),r=n?[n.from,n.to]:[];return e.circuit.components.filter(e=>e.pins.some(e=>r.includes(e.id))).map(e=>e.id)}function ZE(e,t,n,r,i){let a=K(e,t,n);if(a&&XE(e,a).some(e=>r.has(e)))return{id:n,kind:`withParts`};let o=a?GE(e,a,i):{blocked:ME};return`blocked`in o?{id:n,kind:`skipped`,reason:o.blocked,named:YE(e,a,o.blocked),studio:a?.writer.kind===`engine`}:{id:n,kind:`removed`,edits:o.edits,name:a?VE(e,a):`the wire`}}var QE=e=>`${e} wires have no trace of their own: Studio draws them for their nets`;function $E(e,t){let n=e.flatMap(e=>e.kind===`skipped`&&!t.has(e.reason)?[e]:[]),r=n.filter(e=>e.studio);return[...n.filter(e=>!e.studio).map(e=>e.named),...r.length>1?[QE(r.length)]:r.map(e=>e.named)]}function eD(e,t,n,r,i=gr,a=new Set){let o=n.map(n=>ZE(e,t,n,r,i)),s=o.flatMap(e=>e.kind===`removed`?[e]:[]),c=o.flatMap(e=>e.kind===`withParts`?[e.id]:[]),l=new Set([...s.map(e=>e.id),...c]),u=t=>e.schematic.wires.filter(e=>l.has(e.id)!==t).map(e=>e.points);return{edits:s.flatMap(e=>e.edits),removed:s.map(e=>e.id),names:s.map(e=>e.name),withParts:c,skipped:$E(o,a),junctions:jE(TE(e.schematic.drawings),u(!1),u(!0))}}function tD(e,t,n,r=gr){let i=K(e,t,n);return i?KE(e,i,r):{blocked:ME}}function nD(e,t,n,r=gr){let i=K(e,t,n);return i?JE(e,i,r):{remove:ME,removeCorners:ME}}function rD(e){return e.writer.kind===`trace`?`Trace, line ${e.writer.trace.line}`:e.writer.kind===`engine`?`Routed by Studio`:`Not found in the code`}function iD(e,t,n,r=gr){let i=K(e,t,n);if(!i)return;let[a,o]=BE(e,i)??[`unknown`,`unknown`],s=[{label:`Net`,value:LE(e,n)},{label:`From`,value:a},{label:`To`,value:o},{label:`Corners`,value:String(Math.max(0,i.points.length-2))},{label:`Kind`,value:rD(i)}];return{net:IE(e,n),rows:s,...JE(e,i,r)}}var aD=`Wire`;function oD({design:e,circuit:t,wire:n,locked:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=iD(e,t,n,r);return c?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{disabled:c.net===void 0,title:`Light this wire's net in both views`,onClick:()=>i(`highlight`),children:`Highlight net`}),(0,X.jsx)(`button`,{disabled:c.removeCorners!==null,title:c.removeCorners??`Let Studio draw this wire on its own, with at most one elbow`,onClick:()=>i(`removeCorners`),children:`Remove corners`}),(0,X.jsxs)(`button`,{className:`danger`,disabled:c.remove!==null,title:c.remove??`Delete this wire's trace (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})]}),c.remove&&(0,X.jsxs)(`p`,{className:`note`,children:[c.remove,`.`]}),(0,X.jsx)(qw,{title:aD,open:!o.has(aD),onToggle:()=>s(aD),children:c.rows.map(e=>(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}function sD({design:e,circuit:t,text:n,locked:r,actions:i,onClear:a,collapsed:o,toggle:s}){let c=Af(e,t,n,r);if(!c)return null;let l=Tf(e,t,n,r);return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsx)(`button`,{disabled:l!==null,title:l??`Put it back where the layout puts it`,onClick:()=>void i.edit(xf(n),`Reset ${c.rows[0]?.value??``} ${c.title.toLowerCase()} position`),children:`Reset position`})}),c.blocker&&(0,X.jsxs)(`p`,{className:`note`,children:[c.blocker,`.`]}),(0,X.jsx)(qw,{title:c.title,open:!o.has(c.title),onToggle:()=>s(c.title),children:c.rows.map(e=>(0,X.jsx)(Kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function cD({id:e,verified:t,actions:n}){let[r,i]=(0,_.useState)();if((0,_.useEffect)(()=>{z(`/api/part?id=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]),!r)return(0,X.jsx)(`p`,{className:`note`,children:`Loading…`});let{part:a}=r,o=r.checklist.split(`
17
+ `).filter(e=>e.startsWith(`- [`));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`dl`,{className:`facts`,children:[(0,X.jsx)(`dt`,{children:`Part`}),(0,X.jsx)(`dd`,{children:a.title}),a.manufacturer&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Maker`}),(0,X.jsx)(`dd`,{children:a.manufacturer})]}),a.mpn&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`MPN`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.mpn})})]}),(0,X.jsx)(`dt`,{children:`Footprint`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.footprint})}),Object.entries(a.suppliers??{}).map(([e,t])=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`dt`,{children:e}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:t})})]},e)),a.datasheet?.url&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Datasheet`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`a`,{href:a.datasheet.url,target:`_blank`,rel:`noreferrer noopener`,children:`Open`})})]})]}),(0,X.jsxs)(`p`,{className:`hint`,children:[`These come from parts/`,e,`/part.yaml and are the same for every copy of the part.`]}),t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`note ok`,children:[`Verified by `,a.verified?.by,` against `,a.verified?.against,`.`]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>n.openVerify(e,a.title),"aria-label":`Look again at ${a.title}`,children:`Look again`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`note warn`,children:[`Not verified: `,o.length,` item`,o.length===1?``:`s`,` in parts/`,e,`/verification.md to check against the datasheet.`]}),(0,X.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>n.openVerify(e,a.title),"aria-label":`Verify ${a.title}`,children:`Verify…`})]})]})}var lD=/^https?:\/\//,uD=e=>[e.type,e.carries].filter(Boolean).join(`, `);function dD({instance:e}){let t=e.sources??[];return!e.does&&t.length===0?null:(0,_.createElement)(`div`,{className:`instance-card`},e.does?(0,_.createElement)(`p`,{className:`note`},e.does):null,t.length>0?(0,_.createElement)(`ul`,{className:`instance-sources`},t.map(e=>(0,_.createElement)(`li`,{key:e},lD.test(e)?(0,_.createElement)(`a`,{href:e,target:`_blank`,rel:`noreferrer`},e):e))):null)}function fD({id:e,value:t,disabled:n,placeholder:r,onCommit:i}){let[a,o]=(0,_.useState)(t);return(0,_.useEffect)(()=>o(t),[t]),(0,X.jsx)(`input`,{id:e,value:a,disabled:n,placeholder:r,spellCheck:!1,onChange:e=>o(e.target.value),onBlur:()=>{a.trim()!==t&&i(a.trim()).then(e=>e||o(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&o(t)}})}function pD({design:e,name:t,editable:n,actions:r,onOpenSheet:i,collapsed:a,toggle:o}){let s=gn(e,t),c=(0,_.useId)();if(!s)return null;let l=(e,n)=>{let i=n===``?void 0:pn(s.sheet,e,n,s.ports.find(t=>t.name===e)?.bus===!0);return i===void 0?r.edit([{kind:`setConnections`,part:t,connections:Sn(s,e,n)}],`Connect ${t}.${e} to ${n===``?`nothing`:n}`):(r.notify(i),Promise.resolve(!1))};return(0,X.jsxs)(qw,{title:`Sub-sheet`,open:!a.has(`Sub-sheet`),onToggle:()=>o(`Sub-sheet`),children:[(0,X.jsx)(Kw,{label:`Sheet`,children:(0,X.jsx)(`span`,{className:`static`,children:bn(s.sheet,yn(e,s.file))})}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>i(s.file),title:`Open ${s.file}`,children:[`Open `,s.sheet]})}),(0,X.jsx)(dD,{instance:s}),s.ports.map(e=>(0,X.jsxs)(Kw,{label:`${e.name}${e.bus?` (bus)`:``}`,htmlFor:`${c}-${e.name}`,children:[(0,X.jsx)(fD,{id:`${c}-${e.name}`,value:s.connections[e.name]??``,placeholder:`not connected`,disabled:!n,onCommit:t=>l(e.name,t)}),uD(e)?(0,X.jsx)(`span`,{className:`port-about`,children:uD(e)}):null]},e.name)),(0,X.jsx)(Kw,{label:`base`,htmlFor:`${c}-base`,children:(0,X.jsx)(fD,{id:`${c}-base`,value:String(s.base),disabled:!n,onCommit:e=>{let n=Number(e);return!Number.isInteger(n)||n<=0?(r.notify(`The base is a whole number above 0, such as 300`),Promise.resolve(!1)):r.edit([{kind:`setProps`,part:t,props:{base:n}}],`Set ${t} base=${n}`)}})})]})}function mD({design:e,part:t,onSelect:n,onOpenSheet:r}){let i=_n(e,t);return i?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsx)(`header`,{className:`insp-header`,children:(0,X.jsx)(`span`,{children:t})}),(0,X.jsxs)(`p`,{className:`note`,children:[i.localId,` of instance `,i.instance,` (`,i.sheet,`). `,bn(i.sheet,yn(e,i.file)),`: change it in its sheet, and every instance changes with it.`]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>n(t=>t.all(vn(e,i.outer))),children:`Select the instance`}),(0,X.jsxs)(`button`,{onClick:()=>r(i.file),title:`Open ${i.file}`,children:[`Open `,i.sheet]})]})]}):null}function hD({file:e,parentDesign:t}){let n=t?yn(t,e):void 0;return(0,X.jsxs)(`p`,{className:`note`,children:[bn(ot(e),n),`.`]})}function gD({part:e,editable:t,actions:n,collapsed:r,toggle:i}){let a=(0,_.useId)(),o=e.props.bus?.literal===!0,s=t=>n.edit([{kind:`renamePort`,from:e.name,to:t}],`Rename port ${e.name} to ${t}`),c=t=>n.edit([{kind:`setProps`,part:e.name,props:{bus:t}}],`${t?`Make`:`Unmake`} ${e.name} a bus port`);return(0,X.jsxs)(qw,{title:`Port`,open:!r.has(`Port`),onToggle:()=>i(`Port`),children:[(0,X.jsx)(Kw,{label:`Name`,htmlFor:`${a}-name`,children:(0,X.jsx)(fD,{id:`${a}-name`,value:e.name,disabled:!t,onCommit:s})}),(0,X.jsx)(Kw,{label:`Bus`,htmlFor:`${a}-bus`,children:(0,X.jsx)(`input`,{id:`${a}-bus`,type:`checkbox`,checked:o,disabled:!t,onChange:e=>void c(e.target.checked)})}),(0,X.jsx)(`p`,{className:`hint`,children:`Drag its pin on a symbol of this sheet to move it along the box or to another side.`})]})}function _D({parts:e,onPlace:t,onImport:n,onNewPart:r,focus:i,onFocused:a}){let[o,s]=(0,_.useState)(``),c=(0,_.useRef)(null);(0,_.useEffect)(()=>{i&&(c.current?.focus(),a())},[i,a]);let l=o.trim().toLowerCase(),u=(...e)=>l===``||e.some(e=>e?.toLowerCase().includes(l)),d=e.library.filter(e=>u(e.id,e.title,e.mpn,e.footprint)),f=e.builtin.filter(e=>u(e));return(0,X.jsxs)(`div`,{className:`library`,children:[(0,X.jsx)(`input`,{ref:c,className:`search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsxs)(`h3`,{children:[`Project library `,(0,X.jsx)(`span`,{className:`count`,children:e.library.length})]}),(0,X.jsx)(`button`,{className:`library-import`,onClick:r,children:`New part…`}),(0,X.jsx)(`button`,{className:`library-import`,onClick:n,children:`Import by LCSC number…`}),(0,X.jsx)(`button`,{className:`library-import`,onClick:p_,title:`Search the standard packages, see their pads and shape, and copy a footprint string`,children:`Packages…`}),e.library.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No parts yet. Write one from its datasheet with New part…, import one by its LCSC number, or ask the agent to create one.`}),(0,X.jsx)(`ul`,{children:d.map(e=>(0,X.jsxs)(`li`,{className:`library-item`,children:[(0,X.jsxs)(`div`,{className:`text`,children:[(0,X.jsx)(`span`,{className:`title`,children:e.title}),(0,X.jsxs)(`span`,{className:`meta`,children:[e.mpn??e.id,`, `,e.footprint]}),e.origin&&(0,X.jsx)(`span`,{className:`meta`,children:Ah(e.origin)})]}),(0,X.jsx)(`span`,{className:`badge ${e.verified?`verified`:`unverified`}`,title:e.verified?`Checked by ${e.verifiedBy}`:`Not checked against the datasheet yet`,children:e.verified?`Verified`:`Unverified`}),(0,X.jsx)(`button`,{onClick:()=>t(e.id),"aria-label":`Place ${e.title}`,children:`Place`})]},e.id))}),(0,X.jsx)(`h3`,{children:`Built-in parts`}),(0,X.jsx)(`ul`,{className:`builtin`,children:f.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{className:`chip-button`,onClick:()=>t(e),"aria-label":`Place a ${e}`,children:e})},e))}),(0,X.jsx)(`p`,{className:`hint`,children:`Placed parts start at the board centre; drag them into position on the PCB.`})]})}function vD({design:e,highlight:t,onHighlight:n}){let r=(0,_.useMemo)(()=>e?Xp(e):[],[e]);if(r.length===0)return(0,X.jsx)(`p`,{className:`note`,children:`No nets yet.`});let i=e=>t.length===1&&t[0]===e;return(0,X.jsx)(`ul`,{className:`nets`,children:r.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`row${t.includes(e.id)?` selected`:``}`,"aria-pressed":t.includes(e.id),onClick:()=>n(i(e.id)?Ep:[e.id]),title:i(e.id)?`Click to clear the highlight`:`Click to highlight this net`,children:[(0,X.jsx)(`span`,{className:`name`,children:e.label}),e.badge&&(0,X.jsx)(`span`,{className:`badge ${e.badge}`,children:e.badge}),e.length!==void 0&&(0,X.jsx)(`span`,{className:`value`,children:Yp(e)}),(0,X.jsx)(`span`,{className:`value`,children:e.pins===1?`1 pin`:`${e.pins} pins`})]})},e.id))})}var yD=`No PROJECT.md yet. The agent writes it with set_project and note_decision; you can also write it by hand at the project root.`,bD=e=>e.map(e=>e.trim()).filter(e=>e!==``).map(e=>e.replace(/^[-*]\s+/,``));function xD(e){if(e==null)return{kind:`missing`,note:yD};let t=e.replace(/\r\n/g,`
18
+ `).split(`
19
+ `),n=t.find(e=>/^# /.test(e))?.slice(2).trim()||`Project`,r=[],i;for(let e of t){let t=/^## (.*)$/.exec(e);t?(i&&r.push({title:i.title,lines:bD(i.body)}),i={title:(t[1]??``).trim(),body:[]}):i&&i.body.push(e)}return i&&r.push({title:i.title,lines:bD(i.body)}),{kind:`file`,title:n,sections:r}}function SD(){let[e,t]=(0,_.useState)(void 0),[n,r]=(0,_.useState)(),i=(0,_.useCallback)(()=>{z(`/api/project-memory`).then(e=>{t(e.text),r(void 0)}).catch(e=>r(e.message))},[]);if((0,_.useEffect)(i,[i]),n)return(0,X.jsxs)(`p`,{className:`note project-memory`,children:[`PROJECT.md could not be read: `,n]});if(e===void 0)return(0,X.jsx)(`p`,{className:`note project-memory`,children:`Reading PROJECT.md…`});let a=xD(e);return(0,X.jsxs)(`div`,{className:`project-memory`,children:[(0,X.jsxs)(`div`,{className:`project-memory-head`,children:[(0,X.jsx)(`h3`,{children:a.kind===`file`?a.title:`PROJECT.md`}),(0,X.jsx)(`button`,{type:`button`,onClick:i,children:`Reload`})]}),a.kind===`missing`&&(0,X.jsx)(`p`,{className:`note`,children:a.note}),a.kind===`file`&&a.sections.map((e,t)=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h4`,{children:e.title}),e.lines.length===0?(0,X.jsx)(`p`,{className:`empty`,children:`(empty)`}):(0,X.jsx)(`ul`,{children:e.lines.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]},`${e.title}-${t}`))]})}function CD({tree:e,onOpen:t,focus:n,onFocused:r}){let i=(0,_.useRef)(null);return(0,_.useEffect)(()=>{n&&(i.current?.querySelector(`.tree-row.file`)?.focus(),r())},[n,r]),(0,X.jsxs)(`nav`,{className:`page-tree`,"aria-label":`Pages`,children:[(0,X.jsx)(`div`,{className:`tree-row project`,children:e.project}),(0,X.jsx)(`ul`,{ref:i,children:e.files.map(n=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`button`,{className:`tree-row file`,title:`Open ${n.file}`,onClick:()=>t(n.file,e.view),children:n.file}),(0,X.jsx)(`ul`,{children:n.documents.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{className:`tree-row doc${e.active?` active`:``}`,"aria-current":e.active?`page`:void 0,onClick:()=>t(n.file,e.view,e.page),children:e.label})},e.page??e.view))})]},n.file))})]})}var wD=e=>`${e}-panel`,TD=e=>`side-tab-${e}`;function ED({side:e,tabs:t,active:n,open:r,onClick:i,onSelect:a}){let o=Nm({ids:t.map(e=>e.id),current:n,onSelect:a,onPointerClick:i});return(0,X.jsx)(`div`,{className:`side-strip ${e} hairline-${e===`left`?`r`:`l`}`,role:`tablist`,"aria-orientation":`vertical`,"aria-label":e===`left`?`Left panel`:`Right panel`,onKeyDown:o.onKeyDown,children:t.map(t=>{let i=r&&t.id===n;return(0,X.jsx)(`button`,{role:`tab`,id:TD(t.id),"aria-controls":wD(e),"aria-selected":i,className:`side-tab${i?` on`:``}`,...o.tab(t.id),children:t.label},t.id)})})}var DD={page:`Page`,net:`Net`,component:`Component`,object:`Object`,project:`Project`},OD=Object.keys(DD),kD=`design-panel`;function AD({sub:e,onSub:t}){let n=Nm({ids:OD,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`sub-tabs hairline-b`,role:`tablist`,"aria-label":`Project Design`,onKeyDown:n.onKeyDown,children:OD.map(t=>(0,X.jsx)(`button`,{role:`tab`,id:`sub-tab-${t}`,"aria-controls":kD,"aria-selected":e===t,className:`sub-tab${e===t?` on`:``}`,...n.tab(t),children:DD[t]},t))})}function jD(e){let{left:t,onSub:n}=e,r=t.strip===`design`;return(0,X.jsxs)(`aside`,{className:`panel left hairline-r`,id:wD(`left`),role:`tabpanel`,"aria-labelledby":TD(t.strip),hidden:e.hidden,onClick:km,children:[r&&(0,X.jsx)(AD,{sub:t.sub,onSub:n}),(0,X.jsxs)(`div`,{className:`panel-body`,...r?{id:kD,role:`tabpanel`,"aria-labelledby":`sub-tab-${t.sub}`}:{},children:[!r&&(0,X.jsx)(_D,{parts:e.parts,onPlace:e.onPlace,onImport:e.onImport,onNewPart:e.onNewPart,focus:e.focusSearch,onFocused:e.onSearchFocused}),r&&(0,X.jsx)(MD,{...e})]})]})}function MD(e){switch(e.left.sub){case`page`:return(0,X.jsx)(CD,{tree:e.pageTree,onOpen:e.onOpenDocument,focus:e.focusPage,onFocused:e.onPageFocused});case`net`:return(0,X.jsx)(vD,{design:e.design,highlight:e.highlight,onHighlight:e.onHighlight});case`component`:return(0,X.jsx)(ND,{...e});case`object`:return(0,X.jsx)(FD,{...e});case`project`:return(0,X.jsx)(SD,{})}}function ND({circuit:e,parts:t,selection:n,onSelect:r,autoPlaced:i}){let a=new Set(e.annotations.locks.map(e=>e.part)),o=e=>t.library.find(t=>t.component===e)?.title??e,s=new Map;for(let t of e.model.parts)s.set(t.tag,[...s.get(t.tag)??[],t]);return(0,X.jsxs)(`div`,{className:`tree`,children:[[...s].map(([e,t])=>(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`h3`,{title:e,children:[o(e),` `,(0,X.jsx)(`span`,{className:`count`,children:t.length})]}),(0,X.jsx)(`ul`,{role:`listbox`,"aria-multiselectable":`true`,"aria-label":o(e),"data-keys":`parts`,children:t.map(e=>(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsxs)(`button`,{role:`option`,"aria-selected":n.has(e.name),className:`row${n.has(e.name)?` selected`:``}${e.editable?``:` readonly`}`,onClick:t=>r(bo(e.name,t)),title:e.readonlyReason?`Read-only: ${e.readonlyReason}`:void 0,children:[(0,X.jsx)(`span`,{className:`name`,children:e.name}),(0,X.jsx)(`span`,{className:`value`,children:PD(e.props)}),i.has(e.name)&&(0,X.jsx)(`span`,{className:`placed-dot`,role:`img`,"aria-label":Gg.value,title:Gg.value}),a.has(e.name)&&(0,X.jsx)(Ym,{className:`locked-icon`,"aria-label":`Locked`})]})},e.name))})]},e)),e.model.skipped.length>0&&(0,X.jsxs)(`p`,{className:`note`,children:[e.model.skipped.length,` element(s) cannot be edited here; see the code.`]})]})}function PD(e){for(let t of[`resistance`,`capacitance`,`inductance`,`color`,`footprint`,`standard`]){let n=e[t]?.literal;if(n!==void 0)return String(n)}return``}function FD({circuit:e,selection:t,actions:n}){return(0,X.jsxs)(`div`,{className:`connections`,children:[(0,X.jsx)(`ul`,{children:e.model.traces.map((e,r)=>(0,X.jsxs)(`li`,{className:t.names.some(t=>LD(e,t))?`selected`:``,children:[(0,X.jsx)(`code`,{children:e.editable?e.from:`line ${e.line}`}),(0,X.jsx)(`span`,{className:`arrow`,"aria-hidden":`true`,children:`—`}),(0,X.jsx)(`code`,{children:e.editable?e.to:`read-only`}),(0,X.jsx)(`button`,{className:`icon`,disabled:!e.editable,"aria-label":`Remove connection ${e.from} to ${e.to}`,onClick:()=>{e.from&&e.to&&n.edit([{kind:`removeTrace`,from:e.from,to:e.to}],`remove trace ${e.from} -> ${e.to}`)},children:(0,X.jsx)(nh,{})})]},`${e.from}-${e.to}-${r}`))}),(0,X.jsx)(ID,{actions:n})]})}function ID({actions:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(``);return(0,X.jsxs)(`form`,{className:`add-connection hairline-t`,onSubmit:a=>{a.preventDefault(),t&&r&&e.edit([{kind:`addTrace`,from:t,to:r}],`add trace ${t} -> ${r}`).then(e=>{e&&(n(``),i(``))})},children:[(0,X.jsxs)(`label`,{children:[`From`,(0,X.jsx)(`input`,{placeholder:`.R1 > .pin1`,value:t,onChange:e=>n(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`To`,(0,X.jsx)(`input`,{placeholder:`net.GND`,value:r,onChange:e=>i(e.target.value)})]}),(0,X.jsx)(`button`,{type:`submit`,className:`primary`,children:`Connect`})]})}function LD(e,t){return t?[e.from,e.to].some(e=>e!==void 0&&Fh(e).includes(t)):!1}function RD(e,t){let n=t.size===0&&t.soleLabel?.startsWith(`port:`)?t.soleLabel.slice(5):void 0;return(n===void 0?t.names:[n]).flatMap(t=>e.model.parts.find(e=>e.name===t)??[])}function zD(e,t,n){(0,_.useEffect)(()=>{t&&(e.current?.querySelector(Rg)?.focus(),n())},[e,t,n])}function BD(e){let t=(0,_.useRef)(null);zD(t,e.focusField,e.onFieldFocused);let n=RD(e.circuit,e.selection),[r]=n,i=n.length===1&&e.selection.size===0,{wireCount:a,labelCount:o,drawingCount:s,copperCount:c,soleWire:l,soleLabel:u,soleDrawing:d,soleCopper:f,soleText:p,textCount:m,boardCount:h,soleBoard:g}=e.selection,[v,y]=i?[0,0]:[a,o],b=Jg(n.length,v,y,s,c,m,h),x=n.length===0&&e.selection.size===1&&e.selection.primary!==void 0?_n(e.build.design,e.selection.primary):void 0,S=b===`part`&&r?e.parts.library.find(e=>e.component===r.tag):void 0,C=b===`part`&&r!==void 0&&$e(e.build.design,e.openView).has(r.name),w=Qg(n,{library:S!==void 0,autoPlaced:C},v,y,s,c,m,h),T={locked:new Set(e.circuit.annotations.locks.map(e=>e.part)),violated:new Set(e.circuit.violations.map(e=>e.part))},[E,ee]=(0,_.useState)(new Set),D=e=>ee(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),O=()=>e.onSelect(e=>e.clear()),k=e.build.design;return(0,X.jsxs)(`aside`,{ref:t,className:`panel right`,id:e.hidden?void 0:wD(`right`),role:`tabpanel`,"aria-labelledby":TD(`properties`),hidden:e.hidden,children:[b===`wire`&&l!==void 0&&k&&(0,X.jsx)(oD,{design:k,circuit:e.circuit,wire:l,locked:T.locked,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`label`&&u!==void 0&&k&&(0,X.jsx)(oT,{design:k,label:u,run:e.run,notify:e.actions.notify,onClear:O,collapsed:E,toggle:D}),b===`drawing`&&d!==void 0&&k&&(0,X.jsx)(nE,{design:k,circuit:e.circuit,drawing:d,locked:T.locked,actions:e.actions,onRename:e.onRenameDrawing,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`text`&&p!==void 0&&k&&(0,X.jsx)(sD,{design:k,circuit:e.circuit,text:p,locked:T.locked,actions:e.actions,onClear:O,collapsed:E,toggle:D}),b===`copper`&&f!==void 0&&k&&(0,X.jsx)(_E,{design:k,id:f,segment:e.selection.segment,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`pour`&&g!==void 0&&k&&(0,X.jsx)(xE,{design:k,circuit:e.circuit,id:g,locks:T,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`group`&&(0,X.jsx)(tT,{view:w,parts:n,others:v+y+s+c+h,locks:T,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`part`&&r&&(0,X.jsx)(HD,{...e,view:w,collapsed:E,toggle:D,part:r,locks:T}),x&&k&&(0,X.jsx)(mD,{design:k,part:x.part,onSelect:e.onSelect,onOpenSheet:e.onOpenSheet}),b===`board`&&!x&&(0,X.jsx)(KD,{...e,view:w,collapsed:E,toggle:D})]})}function VD(e,t){let n=e&&Zf(e.pcb).find(e=>e.name===t);return n&&{x:Math.round(n.center.x*1e3)/1e3,y:Math.round(n.center.y*1e3)/1e3}}function HD({circuit:e,build:t,parts:n,part:r,locks:i,actions:a,onSelect:o,run:s,view:c,collapsed:l,toggle:u,onOpenSheet:d,parentDesign:f}){let p=i.locked.has(r.name),m=n.library.find(e=>e.component===r.tag),h=(e,t)=>{let{edits:n,summary:i}=zg(r.name,e,t);return a.edit(n,i)},g=r.editable&&!p,v=e.model.traces.filter(e=>LD(e,r.name)),y=e=>{let[t,n=``]=e.split(`:`);if(n===`footprint`&&(t===`prop`||t===`suggest`)){let t=r.props[n],i=!g||t!==void 0&&!t.editable;return(0,X.jsxs)(_.Fragment,{children:[b(e),(0,X.jsx)($w,{part:r.name,kind:r.tag,footprint:t?.literal===void 0?``:String(t.literal),disabled:i,onEdit:a.edit})]},e)}return b(e)},b=e=>{let[n,i=``]=e.split(`:`),o=r.props[i];if(n===`name`)return(0,X.jsx)(Kw,{label:`Name`,children:(0,X.jsx)(`span`,{className:`static`,children:r.name})},e);if(n===`kind`)return(0,X.jsx)(Kw,{label:`Kind`,children:(0,X.jsxs)(`span`,{className:`static`,children:[r.tag,`, line `,r.line]})},e);if(n===`placed`)return(0,X.jsx)(Kw,{label:Gg.label,children:(0,X.jsx)(`span`,{className:`static`,children:Gg.value})},e);if(n===`prop`&&o)return(0,X.jsx)(Jw,{name:i,prop:o,disabled:!g,onCommit:e=>h(i,e),notify:a.notify},e);if(n===`suggest`){let t=Bg[r.tag]?.find(([e])=>e===i)?.[1]??``;return(0,X.jsx)(Xw,{name:i,example:t,disabled:!g,onCommit:e=>h(i,e)},e)}return n===`textAt`&&o?(0,X.jsx)(Kw,{label:`${lf[i]??i} offset`,children:(0,X.jsx)(`span`,{className:`static`,title:`Drag it on the canvas, or select it for Reset position`,children:o.source.replace(/[{}]/g,``).trim()})},e):n===`lock`?(0,X.jsx)(WD,{locked:p,onChange:e=>s(e?`lock`:`unlock`)},e):n===`connections`?(0,X.jsx)(GD,{traces:v},e):n===`library`?m&&(0,X.jsx)(cD,{id:m.id,verified:m.verified,actions:a},e):(0,X.jsx)(Qw,{label:`Note for the agent about ${r.name}`,onAdd:e=>{let n=VD(t.design,r.name);return a.mark(n?e:`${r.name}: ${e}`,n?{view:`pcb`,...n}:void 0)}},e)};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:c.header}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:()=>o(e=>e.clear()),children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(UD,{part:r,locks:i,run:s}),p&&(0,X.jsx)(`p`,{className:`note locked`,children:`Locked. The agent cannot move or change this part.`}),r.readonlyReason&&(0,X.jsxs)(`p`,{className:`note`,children:[`Read-only here: `,r.readonlyReason,`. Change it in the code.`]}),at(e.file)&&(0,X.jsx)(hD,{file:e.file,parentDesign:f}),r.tag===`port`&&at(e.file)&&(0,X.jsx)(gD,{part:r,editable:g,actions:a,collapsed:l,toggle:u}),t.design&&gn(t.design,r.name)&&(0,X.jsx)(pD,{design:t.design,name:r.name,editable:g,actions:a,onOpenSheet:d,collapsed:l,toggle:u}),c.sections.map(e=>(0,X.jsx)(qw,{title:e.title,open:!l.has(e.title),onToggle:()=>u(e.title),children:e.rows.map(y)},e.title))]})}function UD({part:e,locks:t,run:n}){let r=t_(e.name,t),i=n=>e_(n,[e],t);return(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsxs)(`button`,{className:r.pressed?`toggle on`:`toggle`,"aria-pressed":r.pressed,title:r.title,onClick:()=>n(r.command),children:[r.pressed?(0,X.jsx)(Ym,{}):(0,X.jsx)(Xm,{}),r.label]}),(0,X.jsxs)(`button`,{disabled:!i(`rotate`),onClick:()=>n(`rotate`),children:[(0,X.jsx)($m,{}),` Rotate`]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:!i(`delete`),onClick:()=>n(`delete`),children:[(0,X.jsx)(eh,{}),` Remove`]})]})}function WD({locked:e,onChange:t}){let n=(0,_.useId)();return(0,X.jsx)(Kw,{label:`Locked`,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)})})}function GD({traces:e}){return e.length===0?(0,X.jsx)(`p`,{className:`note`,children:`Not connected.`}):(0,X.jsx)(`ul`,{className:`part-traces`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.from}),` — `,(0,X.jsx)(`code`,{children:e.to})]},`${e.from}-${e.to}-${t}`))})}function KD({circuit:e,build:t,actions:n,counts:r,onShowChecks:i,view:a,collapsed:o,toggle:s}){let c=a=>a===`build`?(0,X.jsxs)(`div`,{children:[t.status===`failed`&&(0,X.jsx)(`p`,{className:`note error`,children:t.error}),t.status===`building`&&(0,X.jsx)(`p`,{className:`note`,children:`Building…`}),t.design&&(0,X.jsx)(qD,{counts:r,onShowChecks:i})]},a):(0,X.jsxs)(`div`,{children:[e.annotations.marks.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`Select a part to leave a note at it, or use Place → Note box to draw one on the canvas.`}),(0,X.jsx)(`ul`,{className:`marks`,children:e.annotations.marks.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{children:e.text}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Remove note ${e.id}`,onClick:()=>void n.unmark(e.id),children:(0,X.jsx)(nh,{})})]},e.id))}),(0,X.jsx)(Qw,{label:`Note for the agent`,onAdd:e=>n.mark(e)})]},a);return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:a.header}),(0,X.jsxs)(`span`,{className:`insp-file`,children:[e.file,`: `,e.model.parts.length,` parts, `,e.model.traces.length,` connections`]})]}),a.sections.map(e=>(0,X.jsx)(qw,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(c)},e.title)),(0,X.jsx)(Dw,{file:e.file,buildId:t.finishedAt,actions:n}),(0,X.jsx)(`p`,{className:`hint`,children:`Select a part to see and change its properties.`})]})}function qD({counts:e,onShowChecks:t}){let n=e.errors>0?`error`:e.warnings>0?`warn`:`ok`;return(0,X.jsxs)(`div`,{className:`check-counts`,children:[(0,X.jsx)(`p`,{className:`note ${n}`,children:Gw(e)}),e.errors+e.warnings>0&&(0,X.jsx)(`button`,{onClick:t,title:`DRC (\\)`,children:`Show checks`})]})}var JD=12,YD=32,XD={minor:W.grid,fifth:W.gridFifth},ZD={lines:XD,dots:{...XD,px:1}};function QD(e,t,n,r,i){Eg(e,t,n,r,ZD,i)}var $D={selected:W.selection,selectedFill:W.selectionFill,hover:W.hover,noteStroke:W.selectionBox,noteFill:W.selectionBoxFill,noteDash:[1,3],boxStroke:W.selectionBox,boxFill:W.selectionBoxFill,boxDash:[1,3],lockFill:W.document,lockGlyph:W.background,markPin:W.document,markPanel:W.notePanel,markText:W.document};function eO(e){return{selected:e.selection,hover:e.hover,noteStroke:e.selection,noteFill:e.selectionFill,noteDash:[5,4],boxStroke:e.selectionBox,boxFill:e.selectionBoxFill,boxDash:[5,4],lockFill:e.lockBadge,lockGlyph:e.lockGlyph,markPin:e.notePin,markPanel:e.notePanel,markText:e.noteText,...e.selectionGlow>0?{glow:e.selectionGlow}:{}}}eO(Ao);function tO(e,t,n,r,i,a,o,s){let c=B(t,n,{x:r.minX+i.x,y:r.maxY+i.y}),l=B(t,n,{x:r.maxX+i.x,y:r.minY+i.y}),u=a===`selected`?Qo(1.5,s):1,d=es({x:c.x-3,y:c.y-3},{x:l.x+3,y:l.y+3},s,u);e.save(),e.lineWidth=u/s,e.strokeStyle=a===`selected`?o.selected:o.hover,e.setLineDash(a===`selected`?[]:[4,3]),a===`selected`&&o.selectedFill&&(e.fillStyle=o.selectedFill,e.fillRect(d.x,d.y,d.width,d.height)),e.shadowBlur=a===`selected`?o.glow??0:0,e.shadowBlur>0&&(e.shadowColor=o.selected),e.strokeRect(d.x,d.y,d.width,d.height),e.restore()}function nO(e,t,n,r,i,a){let o=B(t,n,{x:r.maxX,y:r.maxY}),s=Jo(o.x-4,a),c=Jo(o.y-12,a),l=Yo(14,a);e.save(),e.fillStyle=i.lockFill,sO(e,s,c,l,l,3),e.fill(),e.strokeStyle=i.lockGlyph,e.fillStyle=i.lockGlyph,e.lineWidth=1.3,e.beginPath(),e.arc(s+7,c+6,2.4,Math.PI,0),e.stroke(),e.fillRect(s+3.5,c+6,7,5),e.restore()}function rO(e,t,n,r,i,a){let{at:o,id:s,text:c}=r,l=B(t,n,o),u=`${s} ${c.length>YD?`${c.slice(0,31)}…`:c}`;e.save(),cs(e),e.font=`${os(JD,1,a)}px ${ya}`;let d=e.measureText(u).width+12;e.fillStyle=i.markPanel,sO(e,l.x+10,l.y-22,d,20,4),e.fill(),e.fillStyle=i.markText;let f=ss({x:l.x+16,y:l.y-8},a);e.fillText(u,f.x,f.y),e.strokeStyle=i.markPin,e.lineWidth=Qo(1.5,a)/a,e.beginPath(),e.moveTo(l.x,l.y),e.lineTo(l.x+10,l.y-12),e.stroke(),e.fillStyle=i.markPin,e.beginPath(),e.arc(l.x,l.y,4,0,Math.PI*2),e.fill(),e.restore()}function iO(e,t,n,r,i,a){oO(e,t,n,{stroke:r.boxStroke,fill:r.boxFill,dash:i===`inside`?[]:r.boxDash},a)}function aO(e,t,n,r,i){oO(e,t,n,{stroke:r.noteStroke,fill:r.noteFill,dash:r.noteDash},i)}function oO(e,t,n,r,i){let a=es(t,n,i);e.save(),e.lineWidth=Ko(i),e.fillStyle=r.fill,e.strokeStyle=r.stroke,e.setLineDash(r.dash),e.fillRect(a.x,a.y,a.width,a.height),e.strokeRect(a.x,a.y,a.width,a.height),e.restore()}function sO(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function cO(e,t,n,r,i,a,o){let s=r.map(e=>B(t,n,e)),c=s[s.length-1];c&&(e.save(),e.strokeStyle=a,e.lineWidth=Qo(2,o)/o,e.lineCap=`round`,e.lineJoin=`round`,e.globalAlpha=i===`pending`?.75:1,e.setLineDash(i===`pending`?[6,5]:[]),e.beginPath(),s.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),i===`drawing`&&(e.setLineDash([]),e.beginPath(),e.arc(c.x,c.y,5,0,Math.PI*2),e.stroke()),e.restore())}function lO(e,t,n,r,i,a){for(let o of n){let n=r.selected.includes(o.id)?`selected`:o.id===r.hover?`hover`:void 0;n&&tO(e,t.camera,t.size,o.box,{x:0,y:0},n,i,a)}}var uO=(e,t,n)=>Math.min(Math.max(e,t),n);function dO(e){let t=Math.max(0,Math.floor((e.length-2)/2)),[n,r]=[e[t],e[t+1]];return n&&r?{x:(n.x+r.x)/2,y:(n.y+r.y)/2}:void 0}function fO(e,t,n){let r=e[0];if(r===void 0||t!==e.length)return;let i=n.tracks.find(e=>e.id===r);if(i)return{id:r,points:i.points};let a=n.vias.find(e=>e.id===r);return a&&{id:r,points:[a.at]}}var pO=e=>e.points.length===1?e.points[0]:dO(e.points);function mO(e,t,n,r){let i=n&&dO(n.points);if(n&&i)return{target:{kind:`wire`,id:n.id},middle:i};let a=r&&pO(r);if(r&&a)return{target:{kind:`copper`,id:r.id},middle:a};let o=e===void 0?void 0:t.find(t=>t.name===e);return o&&{target:{kind:`part`,name:o.name},middle:{x:(o.box.minX+o.box.maxX)/2,y:(o.box.minY+o.box.maxY)/2}}}function hO(e,t,n,r,i,a,o){let s=n?mO(e,t,a,o):void 0,c=s&&n?B(n,r,s.middle):{x:r.width/2,y:r.height/2},l=r.width>0?i.width/r.width:1,u=r.height>0?i.height/r.height:1,d={x:i.left+uO(c.x,0,r.width)*l,y:i.top+uO(c.y,0,r.height)*u};return{target:s?.target??{kind:`canvas`},at:d}}function gO(e,t){return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function _O(e,t,n){let r=gO(t,n);return e.width===r.width&&e.height===r.height?!1:(e.width=r.width,e.height=r.height,!0)}function vO(e){typeof e.reset==`function`?e.reset():(e.setTransform(1,0,0,1,0,0),e.globalAlpha=1,e.globalCompositeOperation=`source-over`,e.setLineDash([]))}var yO=.0015,bO=1.25;function xO(e,t,n){let r=(0,_.useMemo)(()=>t===`pcb`?Zf(e.pcb):vc(e.schematic),[e,t]),i=(0,_.useMemo)(()=>Fe(e,t),[e,t]),a=(0,_.useMemo)(()=>[...i.values()].some(e=>e.autoPlaced),[i]),o=(0,_.useMemo)(()=>Cn(new Set(n.annotations.locks.map(e=>e.part)),e),[n,e]);return{boxes:r,anchors:i,autoPlaced:a,locked:o,blockerFor:(0,_.useCallback)(r=>wn(e,o,r)??Ie(n,o,r,t),[e,n,o,t])}}function SO(e,t,n){let{anchors:r,boxes:i}=e;return(0,_.useMemo)(()=>({anchors:r,boxes:i,step:t,snap:n}),[r,i,t,n])}function CO(e,t,n,r,i,a,o){return(0,_.useCallback)(()=>hO(t,n,r,i,e.current?.getBoundingClientRect()??{left:0,top:0,width:i.width,height:i.height},a,o),[e,t,n,r,i,a,o])}function wO(e){let[t,n]=(0,_.useState)({width:0,height:0});return(0,_.useEffect)(()=>{let t=e.current;if(!t)return;let r=new ResizeObserver(([e])=>{e&&n({width:Math.floor(e.contentRect.width),height:Math.floor(e.contentRect.height)})});return r.observe(t),()=>r.disconnect()},[e]),t}function TO(e,t,n){let r=e?.getBoundingClientRect();return!r||r.width===0||r.height===0?{x:0,y:0}:{x:(n.clientX-r.left)*t.width/r.width,y:(n.clientY-r.top)*t.height/r.height}}function EO(e,t,n,r){let[i,a]=(0,_.useState)();OO(e,t,a);let o=(0,_.useCallback)(()=>{n&&t.width>0&&a(xe(n,t,r))},[n,t,r]);(0,_.useEffect)(()=>{i||o()},[i,o]);let s=e=>()=>a(n=>n&&we(n,t,{x:t.width/2,y:t.height/2},e));return TS({zoomIn:s(bO),zoomOut:s(1/bO)}),{camera:i,setCamera:a,fit:o}}function DO(e,t,n,r,i){(0,_.useEffect)(()=>{t&&t.view===e&&n&&(r(Ce(n,t.at)),i())},[e,t,n,r,i])}function OO(e,t,n){let r=(0,_.useCallback)(r=>{r.preventDefault();let i=TO(e.current,t,r);n(e=>e&&we(e,t,i,Math.exp(-r.deltaY*yO)))},[e,t,n]);(0,_.useEffect)(()=>{let t=e.current;if(t)return t.addEventListener(`wheel`,r,{passive:!1}),()=>t.removeEventListener(`wheel`,r)},[e,r])}function kO(e,t,n,r,i){if(!e||t.width===0)return null;let a=window.devicePixelRatio||1;_O(e,t,a);let o=e.getContext(`2d`);return o?(vO(o),o.fillStyle=r,o.fillRect(0,0,e.width,e.height),o.setTransform(a,0,0,a,0,0),i(o,n,t,a),{ctx:o,ratio:a}):null}function AO(e,t,n,r){let{look:i,gesture:a,ratio:o}=r;for(let a of r.boxes){let s=r.moving?.names.includes(a.name)?r.moving.offset:{x:0,y:0},c=r.selection.has(a.name);a.name===r.hover&&!c&&tO(e,t,n,a.box,s,`hover`,i,o),c&&tO(e,t,n,a.box,s,`selected`,i,o),r.locked.has(a.name)&&nO(e,t,n,a.box,i,o)}for(let a of r.marks)a.view===r.view&&a.x!==void 0&&a.y!==void 0&&rO(e,t,n,{at:{x:a.x,y:a.y},id:a.id,text:a.text},i,o);a?.kind===`box`&&iO(e,a.start,a.current,i,Xa(a.start,a.current),o),a?.kind===`zoom`&&iO(e,a.start,a.current,i,Xa(a.start,a.current),o),a?.kind===`note`&&aO(e,a.start,a.current,i,o)}function jO(e){return e.target instanceof HTMLElement&&e.target.closest(`input, textarea, select`)?!1:!(e.ctrlKey||e.metaKey||e.altKey)}var MO=`Waiting for the build…`,NO=`Snap off`;function PO(e){if(e?.kind===`drag`&&e.moved&&!e.blocker)return e.offset;if(e?.kind===`label`&&e.moved&&!e.blocker)return{x:e.at.x-e.label.at.x,y:e.at.y-e.label.at.y};if(e?.kind===`text`&&e.moved&&!e.blocker)return{x:e.at.x-e.from.x,y:e.at.y-e.from.y}}var FO=(e,t)=>rg(e,t??`mm`);function IO(e){let{cursor:t,zoom:n,unit:r}=e,i=PO(e.gesture);return{position:[n===void 0?``:`Zoom ${ag(n,r?10:60)}%`,t?`X ${FO(t.x,r)} Y ${FO(t.y,r)}`:``].filter(e=>e!==``).join(` `),drag:i?`dX ${FO(i.x,r)} dY ${FO(i.y,r)}`:``,notice:e.rotateHeld?MO:``,snap:e.snap===!1?NO:``}}function LO(e,t,n,r){return`Routing ${e} on ${t}, ${n} mm, ${r} — Space corner, V layer+via, Enter ends open, Esc`}function RO({step:e,options:t,onChange:n}){return(0,X.jsxs)(`label`,{children:[`Grid`,(0,X.jsx)(`select`,{value:e,onChange:e=>n(Number(e.target.value)),children:t.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function zO({show:e,onKeep:t,title:n}){return e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`tool-divider`,"aria-hidden":`true`}),(0,X.jsx)(`button`,{onClick:t,title:n,children:`Keep these positions`})]}):null}function BO({cursor:e,zoom:t,unit:n,onToggleUnit:r,detail:i,gesture:a,rotateHeld:o,snap:s}){let{position:c,drag:l,notice:u,snap:d}=IO({cursor:e,zoom:t,unit:n,gesture:a,rotateHeld:o,snap:s});return(0,X.jsxs)(`div`,{className:`canvas-status`,"aria-live":`off`,children:[(0,X.jsx)(`span`,{children:c}),n&&(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{r?.(),km(e)},onPointerDown:e=>e.stopPropagation(),title:`Switch between mm and mil (Q)`,children:n}),l&&(0,X.jsx)(`span`,{children:` ${l}`}),i&&(0,X.jsx)(`span`,{children:` ${i}`}),d&&(0,X.jsx)(`span`,{children:` ${d}`}),u&&(0,X.jsx)(`span`,{children:` ${u}`})]})}var VO=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),HO=(e,t,n)=>({...e.length>0?{wires:e}:{},...t.length>0?{labels:t}:{},...n.length>0?{drawings:n}:{}}),UO=(e,t,n,r,i)=>so(e.names,t)&&so(e.wires??[],n)&&so(e.labels??[],r)&&so(e.drawings??[],i);function WO(e,t,n,r,i=[],a=[],o=[]){let s=e!==void 0&&UO(e,n,i,a,o);if(e&&s&&e.inFlight)return{burst:{...e,total:VO(e.total,r),dirty:!0},send:null,fresh:!1};if(e&&s&&e.base===t){let t=VO(e.total,r);return{burst:{...e,total:t,inFlight:!0,dirty:!1},send:t,fresh:!1}}return{burst:{base:t,names:n,...HO(i,a,o),total:r,inFlight:!0,dirty:!1},send:r,fresh:!0}}function GO(e,t){if(t)return e.dirty?{burst:{...e,dirty:!1,inFlight:!0},send:e.total,fresh:!1}:{burst:{...e,inFlight:!1},send:null,fresh:!1}}var KO={inFlight:0,seq:0,waiting:void 0,written:0,held:void 0,history:void 0};function qO(e,t){return e.inFlight>0||t.moveWaiting?!1:e.waiting===void 0||t.buildStatus===`done`&&t.builtMark!==void 0&&t.builtMark>e.written}var JO=(e,t)=>e.waiting&&qO(e,t)?{...e,waiting:void 0,history:void 0}:e;function YO(e,t,n,r){if(n)return{gate:e,send:!1};if(qO(e,r)&&!e.held)return{gate:JO(e,r),send:!0};let i=e.held&&so(e.held.names,t)?e.held.count+1:1;return{gate:{...e,held:{names:t,count:i}},send:!1}}function XO(e,t,n){let{held:r}=e;if(!r||!qO(e,n))return{gate:r?e:JO(e,n),send:!1};let i=JO(e,n);return so(r.names,t)?{gate:{...i,held:r.count>1?{...r,count:r.count-1}:void 0},send:!0}:{gate:{...i,held:void 0},send:!1}}function ZO(e){let t=e.seq+1;return{...e,inFlight:e.inFlight+1,seq:t,waiting:{seq:t}}}function QO(e,t,n,r,i){let a=Math.max(0,e.inFlight-1);return t?{...e,inFlight:a,written:Math.max(e.written,i??0)}:{...e,inFlight:a,waiting:e.waiting?.seq===n?r:e.waiting,held:void 0}}function $O(e){let t=ZO(e);return{...t,history:{seq:t.seq}}}function ek(e,t,n,r,i){if(t)return QO(e,!0,n,r.waiting,i);let a=e=>e?.seq===n,o=Math.max(0,e.inFlight-1),s=a(e.waiting)?r.waiting:e.waiting;return{...e,inFlight:o,waiting:s,history:a(e.history)?r.history:e.history}}function tk(e,t){return e.history===void 0?{gate:e,send:!0}:qO(e,t)?{gate:JO(e,t),send:!0}:{gate:e,send:!1}}function nk(e,t,n,r=[],i=[],a=[]){let o=e!==void 0&&UO(e,t,r,i,a);return{names:t,...HO(r,i,a),total:e&&o?VO(e.total,n):n}}function rk(e,t,n,r,i=[],a=[],o=[]){if(!t)return{gate:e,held:t,send:null};let s=tk(e,r);return s.send?{gate:s.gate,held:void 0,send:UO(t,n,i,a,o)?t.total:null}:{gate:e,held:t,send:null}}var ik=new Set([`fit`,`highlight`,`contextMenu`,`delete`,`rotate`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`alignLeft`,`distributeH`]);function ak(e,t,n,r,i=t){return!r||!ik.has(e)?!1:e.startsWith(`nudge`)?i>0&&!n:e===`rotate`?t>0&&!n:e===`alignLeft`||e===`distributeH`?!n:!0}function ok(e){let t={},n=(e,t)=>({x:e.at.x+t.x,y:e.at.y+t.y}),r=(i,a)=>{let{text:o}=t;o&&e(o,n(o,a)).then(e=>{if(t.burst!==i&&t.burst?.base!==i.base)return;let n=t.burst?GO(t.burst,e):void 0;t.burst=n?.burst,n?.burst&&n.send&&r(n.burst,n.send)})};return{press(e,i,a,o){let s=WO(t.burst,e,[a],o);if(s.fresh&&(t.text=i(a)),t.burst=s.burst,!t.text)t.burst=void 0;else return s.send&&r(s.burst,s.send),n(t.text,s.burst.total)}}}function sk(e){return e?.kind===`text`&&e.moved&&!e.blocker?{id:e.id,at:e.at}:void 0}function ck({view:e,design:t,circuit:n,actions:r,locked:i,builtFrom:a,drawn:o}){let[s,c]=(0,_.useState)([]);(0,_.useEffect)(()=>c(e=>e.every(e=>e.sentAt>a)?e:e.filter(e=>e.sentAt>a)),[a]);let l=(0,_.useMemo)(()=>mf(e,t),[e,t]),u=(0,_.useMemo)(()=>s.filter(e=>e.sentAt>a),[s,a]),d=(0,_.useMemo)(()=>yf(l,u),[l,u]),f=(e,t)=>{let n={id:e,at:t,sentAt:Date.now()};return c(t=>[...t.filter(t=>t.id!==e),n]),n},p=async(e,t)=>{let a=wf(n,i,e.id);if(a)return r.notify(a),!1;let o=bf(e,t);if(o.length===0)return!0;let s=f(e.id,t),l=await r.edit(o,`Move ${e.part} ${lf[e.prop]?.toLowerCase()??e.prop}`);return l||c(e=>e.filter(e=>e!==s)),l},m=(e,t)=>{let n=d.find(t=>t.id===e);n&&p(n,t)},h=(0,_.useRef)(p);h.current=p;let[g]=(0,_.useState)(()=>ok((e,t)=>h.current(e,t)));return{tools:{at:e=>_f(o?d.filter(e=>o(e.part)):d,e)?.id,position:e=>d.find(t=>t.id===e)?.at,blocker:e=>wf(n,i,e),commit:m},placed:d,pending:u,nudge:(e,r)=>{let a=g.press(t,e=>d.find(t=>t.id===e),e,r);a&&wf(n,i,e)===null&&f(e,a)}}}function lk(e,t){let{placed:n,pending:r}=e;return(0,_.useMemo)(()=>{let e=sk(t);return{moves:e?[e,...r.filter(t=>t.id!==e.id)]:r,shown:e?yf(n,[e]):n}},[t,n,r])}var uk=e=>e*Math.PI/180;function dk(e,t,n=!1){let r=n&&e.length>2?[...e,e[0]]:e,i=1/0;for(let e=1;e<r.length;e++)i=Math.min(i,Kc(t,r[e-1],r[e]));return i}function fk(e,t,n,r){let i=r-n;if(Math.abs(i)>=360)return!0;let a=(i%360+360)%360;return((Math.atan2(e.y-t.y,e.x-t.x)*180/Math.PI-n)%360+360)%360<=a}function pk(e,t){let n={x:e.x,y:e.y};if(fk(t,n,e.startAngle,e.endAngle))return Math.abs(Math.hypot(t.x-n.x,t.y-n.y)-e.radius);let r=t=>({x:n.x+e.radius*Math.cos(uk(t)),y:n.y+e.radius*Math.sin(uk(t))}),[i,a]=[r(e.startAngle),r(e.endAngle)];return Math.min(Math.hypot(t.x-i.x,t.y-i.y),Math.hypot(t.x-a.x,t.y-a.y))}var mk=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,hk=(e,t)=>Math.hypot(Math.max(e.minX-t.x,0,t.x-e.maxX),Math.max(e.minY-t.y,0,t.y-e.maxY));function gk(e,t){switch(e.kind){case`path`:case`bus`:return dk(e.points,t);case`rect`:{let{x:n,y:r,width:i,height:a}=e;return dk([{x:n,y:r},{x:n+i,y:r},{x:n+i,y:r+a},{x:n,y:r+a}],t,!0)}case`circle`:return Math.abs(Math.hypot(t.x-e.x,t.y-e.y)-e.radius);case`arc`:return pk(e,t);case`text`:case`junction`:return hk(dn(e),t)}}function _k(e,t){return Wo(e)?e.kind===`circle`?Math.hypot(t.x-e.x,t.y-e.y)<=e.radius:mk(dn(e),t):!1}function vk(e,t,n){return gk(e,t)<=n+zo(e)/2?`line`:_k(e,t)?`inside`:void 0}var yk=(e,t)=>e.kind!==`text`||t===void 0||e.fontSize*t>=3;function bk(e,t,n,r){let i;for(let a=e.length-1;a>=0;a--){let o=e[a];if(!yk(o,r))continue;let s=vk(o,t,n);if(s===`line`)return{id:o.id,place:s};s===`inside`&&!i&&(i={id:o.id,place:s})}return i}function xk(e){let t=dn(e),n=zo(e)/2;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function Sk(e){return e.map(e=>({id:e.id,box:xk(e)}))}function Ck(e,t,n,r){return $a(e,t,n,r)}var wk=.1,Tk=`None of the selected parts is in this view.`,Ek=1e-6;function Dk(e,t,n){let r=Math.max(e.maxX-e.minX,Ek),i=Math.max(e.maxY-e.minY,Ek),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:Me(a)}}function Ok(e,t,n,r){let i=new Set(t),a=Ae(e.filter(e=>i.has(e.name)).map(e=>e.box));return!a||n.width<=0||n.height<=0?{message:Tk}:{camera:Dk(a,n,r)}}function kk(e,t,n){return Dk({minX:Math.min(e.x,t.x),minY:Math.min(e.y,t.y),maxX:Math.max(e.x,t.x),maxY:Math.max(e.y,t.y)},n,0)}var Ak=new Set([`part`,`selectedPart`,`label`,`selectedLabel`,`wire`,`selectedWire`,`wireCorner`,`drawing`,`selectedDrawing`,`text`]),jk=new Set([`selectedPart`,`selectedWire`,`selectedLabel`,`selectedDrawing`]),Mk=0,Nk=1,Pk=2,Fk={wire:`wireSegment`,wireCorner:`wireCorner`};function Ik(e,t,n){return e.button===Nk?`pan`:e.button===Pk?`rightPress`:e.button===Mk?n===`note`?`note`:n===`zoom`?`zoom`:n===`place`&&t===`empty`?`pan`:yo(e)?Ak.has(t)?`toggle`:`addBox`:t===`part`||t===`drawing`?`move`:jk.has(t)?`moveGroup`:t===`wire`||t===`wireCorner`?n===null?Fk[t]:`wire`:t===`text`?`text`:t===`label`?`label`:`box`:`none`}var Lk=2;function Rk(e){return(e&Lk)!==0}function zk(e,t){return e===`rightPress`?t?`disarm`:`menu`:e===`moveGroup`?`selectAlone`:e===`box`?`clear`:`none`}function Bk(e,t){return Math.hypot(t.x-e.x,t.y-e.y)>=3}var Vk=`input, textarea, select, form, button`;function Hk(e){if(e.button!==Mk)return!1;let t=e.target;return typeof t?.closest!=`function`||!t.closest(Vk)}var Uk=(e,t)=>({x:V(e.x+t.x),y:V(e.y+t.y)}),Wk=(e,t)=>e.x===t.x&&e.y===t.y,Gk=e=>Uk(e.at,e.by);function Kk(e,t,n){let r=e.schematic.symbols.find(e=>e.component===n);if(!r)return;let i=e.circuit.components.find(e=>e.id===n)?.groupOffset.sch??Pe,a=Re(t,n,`schematic`,{origin:r,group:i}),o={x:V(a.x),y:V(a.y)};return{props:o,ahead:{x:V(o.x+i.x-r.x),y:V(o.y+i.y-r.y)}}}var qk=(e,t)=>typeof e==`number`?V(e-t):0;function Jk(e,t,n){let r=new Map;for(let i of n){if(i.kind!==`setProps`)continue;let{schX:n,schY:a}=i.props,o=typeof n==`number`||typeof a==`number`?Kk(e,t,i.part):void 0;o&&r.set(i.part,{x:qk(n,o.props.x),y:qk(a,o.props.y)})}return r}function Yk(e){let t=e.trace.schematicRouteHints??[];return e.reversed?[...t].reverse():[...t]}function Xk(e,t,n,r,i){let a=(n,r)=>{if(n===void 0||r===void 0)return;let a=Kk(e,t,r);return a&&{at:Uk(n,a.ahead),by:i.get(r)??Pe}},o=a(n.points[0],r.components[0]);if(!o||r.toNet)return o&&[o,void 0];let s=a(n.points[n.points.length-1],r.components[1]);return s&&[o,s]}function Zk(e,t,n){let r=tl(e,t);return r===`horizontal`?{x:0,y:n.y}:r===`vertical`?{x:n.x,y:0}:Pe}function Qk(e,t,n){if(n&&Wk(e.by,n.by))return t.map(t=>Uk(t,e.by));let r=t.length-1,[i,a]=[t[0],t[r]],o=i?Zk(e.at,i,e.by):Pe,s=n&&a?Zk(n.at,a,n.by):Pe;return t.map((e,t)=>Uk(Uk(e,t===0?o:Pe),t===r?s:Pe))}function $k(e,t,n,r,i){let a=Yk(r),o=a.length>0?Xk(e,t,n,r,i):void 0;if(!o)return;let[s,c]=o;return{start:s,end:c,corners:a,path:fl([s.at,...a,...c?[c.at]:[]])}}function eA(e,t,n,r,i){let a=n.length<2?[]:Nl(e,{...t,points:n},n,r,i);return Array.isArray(a)&&a.length>0?{line:{id:t.id,points:n},edits:a}:void 0}function tA(e,t,n,r,i){let{writer:a}=n;if(a.kind!==`trace`||!a.components.some(e=>r.has(e)))return;let o=$k(e,t,n,a,r);if(!o)return;let{start:s,end:c}=o,l=c?[Gk(c)]:[],u=o.path.slice(1,c?-1:void 0);return eA(e,n,fl([Gk(s),...Qk(s,u,c),...l]),i,[Gk(s),...o.corners,...l])}function nA(e,t,n,r,i){if(n.size===0)return[];let a=new Set(e.circuit.components.filter(e=>n.has(e.id)).flatMap(e=>e.pins.map(e=>e.id))),o=new Set(e.circuit.connections.filter(e=>a.has(e.from)||a.has(e.to)).map(e=>e.id));return e.schematic.wires.flatMap(a=>{let s=a.connection!==void 0&&o.has(a.connection)&&!i.has(a.id)?K(e,t,a.id):void 0,c=s&&tA(e,t,s,n,r);return c?[c]:[]})}function rA(e,t,n,r,i,a,o){let s=$k(e,t,n,r,a);if(!s)return;let[c,l]=r.components,u=s.end?l!==void 0&&a.has(l):i.labelEnd,d={start:c!==void 0&&a.has(c),end:u};return eA(e,n,ul(s.path,i.offset,d),o,s.path)}function iA(e,t,n,r,i){let{design:a,locked:o}=e,s=K(a,t,n),c=s?.writer;if(!s||c?.kind!==`trace`||Yk(c).length===0)return{kind:`leave`};let l=q(a,s,o);if(l!==null)return{kind:`blocked`,reason:l,named:YE(a,s,l)};let u=VE(a,s);return!c.toNet&&c.components.every(e=>i.has(e))?{kind:`follow`,id:n,name:u}:{kind:`carry`,id:n,name:u,move:rA(a,t,s,c,r,i,o)}}var aA=`Studio draws this wire's shape between its pins; drag one of its segments to give it corners first`,oA=`Studio draws these wires' shapes between their pins; drag one of their segments to give them corners first`;function sA(e,t,n){let r=e.flatMap(e=>e.kind===`blocked`&&!t.includes(e.reason)?[e.named]:[]),i=e.filter(e=>e.kind===`leave`).length,a=n&&i>0?[i===1?aA:oA]:[];return[...r,...a]}function cA(e,t){return e.flatMap(e=>e.kind===`carry`&&e.move||e.kind===`follow`&&t.has(e.id)?[e.name]:[])}var lA=(e,t,n,r,i)=>`move ${H([...e,...ct(t),...rm(n),...r])}${Ne.schematic.where} by (${V(i.x)}, ${V(i.y)})`;function uA(e,t,n,r){let i=n?.wires??[],a=Zp(e.design,n?.labels??[],e=>r.has(e),i),o=i=>iA(e,t,i,{offset:n?.offset??Pe,labelEnd:a.riding.has(i)},r),s=[...a.riding.keys()].filter(e=>!i.includes(e));return{outcomes:i.map(o),riding:s.map(o),ridingIds:s,sort:a}}function dA(e,t,n,r){return n.riding.flatMap((i,a)=>{if(i.kind===`carry`||i.kind===`follow`)return[];let o=n.ridingIds[a]??``,s=K(e.design,t,o),c=i.kind===`blocked`?i.reason:s&&q(e.design,s,e.locked),l=e.design.schematic.labels.find(e=>e.id===n.sort.riding.get(o));return c&&!r.includes(c)?[$p(l,c)]:[]})}function fA(e){let t=new Set([...e.outcomes,...e.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.id]:[]));return[...e.sort.onPins,...[...e.sort.riding].flatMap(([e,n])=>t.has(e)?[n]:[])]}function pA(e,t,n,r){if(!n)return{plan:e,lines:[],labels:[],drawings:[]};let i=Jk(n.design,t,e.edits),a=uA(n,t,r,i),o=[...a.outcomes,...a.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.move]:[]),s=nA(n.design,t,i,n.locked,new Set(o.map(e=>e.line.id))),c=[...o,...s],l=r?.offset??Pe,u=tm(n.design,t,a.sort.alone,l,n.locked,e.skipped),d=bT(t.model,n.design.schematic.drawings,r?.drawings??[],l,n.locked),f=cA(a.outcomes,new Set(s.map(e=>e.line.id))),p=[...nm(n.design,fA(a)),...u.names],m=[...u.edits,...d.edits],h=e.edits.length===0&&c.length===0&&m.length===0,g=[...sA(a.outcomes,e.skipped,h),...dA(n,t,a,e.skipped),...u.notes,...d.skipped],_={lines:c.map(e=>e.line),labels:u.shown,drawings:d.shown};if(c.length===0&&m.length===0&&f.length+p.length+g.length===0)return{plan:e,..._};let v=r&&f.length+p.length+d.names.length>0?lA(e.parts,f,p,d.names,l):e.summary,y=[...e.edits,...c.flatMap(e=>e.edits),...m];return{plan:{...e,edits:y,summary:v,skipped:[...e.skipped,...g]},..._}}function mA(e,t,n,r){return pA(e,t,n,r).plan}function hA(e,t,n,r=[],i=[],a=[]){return pA(dt(e.circuit,t,e.view,ft(e.anchors,e.boxes),n,e.blockerFor),e.circuit,e.follow,{wires:r,labels:i,drawings:a,offset:n})}var gA=6,_A=V;function vA(e,t,n,r,i,a,o){let s=t?.at(n),c=i?.at(n),l=a?.at(n),u=o?.at(n),d=e=>l?.place===e?[{kind:`drawing`,id:l.id}]:[],[f]=Ua([...s?[{kind:`label`,label:s}]:[],...c===void 0?[]:[{kind:`wire`,id:c}],...d(`line`),...Oe(e,n).map(e=>({kind:`part`,name:e.name})),...u===void 0?[]:[{kind:`text`,id:u}],...d(`inside`)],r);return f??{kind:`canvas`}}function yA(e,t,n,r){return vA(e,void 0,t,n,void 0,void 0,r).kind===`text`}function bA({busy:e,handle:t,target:n,selectedBefore:r}){return e?{kind:`none`}:t?t.id===r?{kind:`removeCorner`,...t}:{kind:`properties`,target:{kind:`wire`,id:t.id}}:n.kind===`part`||n.kind===`wire`||n.kind===`drawing`?{kind:`properties`,target:n}:n.kind===`label`?{kind:`rename`,label:n.label}:{kind:`none`}}var xA=e=>({selection:e.selection,armed:e.tool.armed,layers:e.layers,filter:e.filter});function SA(e,t){return e.kind===`part`?t.has(e.name)?`selectedPart`:`part`:e.kind===`wire`?t.hasWire(e.id)&&t.total>1?`selectedWire`:`wire`:e.kind===`label`?t.hasLabel(e.label.id)&&t.total>1?`selectedLabel`:`label`:e.kind===`drawing`?t.hasDrawing(e.id)?`selectedDrawing`:`drawing`:e.kind===`text`?`text`:`empty`}function CA(e,t,n){let r=Jl(e.wires?.drag,xA(e),t,n.scale);if(r)return{target:{kind:`wire`,id:r.id},under:`wireCorner`,corner:r.index};let i=vA(e.boxes,e.labels,t,xA(e),e.wires,e.drawings,e.texts),a=i.kind===`text`?void 0:e.copperAt?.(t);return a===void 0?{target:i,under:SA(i,e.selection)}:{target:{kind:`copper`,id:a},under:`empty`}}var wA=new Set([`wire`,`wireSegment`,`wireCorner`]);function TA(e,t,n,r,i){if(e.onSelect(e=>e.onlyWire(t)),n===`wire`)return;let a=e.wires?.drag,o=a?.points(t),s=o&&Yl(o,r.world,i.scale,n===`wireCorner`?r.corner:void 0);return s&&Zl(a,t,s,r.point)}function EA(e,t,n){let{camera:r}=e;if(!r)return;let i=be(r,e.size,n),{target:a,under:o,corner:s}=CA(e,i,r),c=Ik(t,o,e.tool.armed);if(L(c)&&le.refuses())return DA(e,a,c);let l=zk(c,e.tool.armed);if(c===`pan`||c===`rightPress`)return{kind:`pan`,start:n,camera:r,moved:!1,still:l,target:a};if(c===`note`||c===`zoom`)return{kind:c,start:n,current:n};if(c===`box`||c===`addBox`)return{kind:`box`,start:n,current:n,adds:c===`addBox`,still:l};if(a.kind===`label`)return OA(e,a.label,c,n,l);if(a.kind===`wire`)return jA(e,a.id,c,{world:i,point:n,still:l,...s===void 0?{}:{corner:s}},r);if(a.kind===`drawing`)return AA(e,a.id,c,n,l);if(a.kind===`text`)return kA(e,a.id,c,n);let u=a.kind===`part`?e.boxes.find(e=>e.name===a.name):void 0;if(u){if(c===`toggle`)e.onSelect(e=>e.toggle(u.name));else return c===`move`||c===`moveGroup`?PA(e,{part:u},c,n,l):void 0}}function DA(e,t,n){n!==`moveGroup`&&(t.kind===`part`?e.onSelect(e=>e.only(t.name)):t.kind===`label`?e.onSelect(e=>e.onlyLabel(t.label.id)):t.kind===`wire`?e.onSelect(e=>e.onlyWire(t.id)):t.kind===`drawing`?e.onSelect(e=>e.onlyDrawing(t.id)):t.kind===`text`&&e.onSelect(e=>e.onlyText(t.id)))}function OA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleLabel(t.id));else{if(n===`moveGroup`)return PA(e,{label:t.id},n,r,i);if(n===`label`)return e.onSelect(e=>e.onlyLabel(t.id)),{kind:`label`,label:t,start:r,at:t.at,moved:!1,blocker:e.labels?.blocker(t.id)??null}}}function kA(e,t,n,r){if(n===`toggle`){e.onSelect(e=>e.toggleText(t));return}let i=e.texts?.position(t);if(n===`text`&&i)return e.onSelect(e=>e.onlyText(t)),{kind:`text`,id:t,start:r,from:i,at:i,moved:!1,blocker:e.texts?.blocker(t)??null}}function AA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleDrawing(t));else return n===`move`||n===`moveGroup`?PA(e,{drawing:t},n,r,i):void 0}function jA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleWire(t));else return n===`moveGroup`?PA(e,{wire:t},n,r.point,r.still):wA.has(n)?TA(e,t,n,r,i):void 0}var MA={names:[],wires:[],labels:[],drawings:[]};function NA(e,t,n){if(n){let t=new Set(e.boxes.map(e=>e.name)),{names:n,wires:r,labels:i,drawings:a}=e.selection;return{names:n.filter(e=>t.has(e)),wires:r,labels:i,drawings:a}}if(`part`in t){let{name:n}=t.part;return e.onSelect(e=>e.only(n)),{...MA,names:[n]}}if(!(`drawing`in t))return MA;let{drawing:r}=t;return e.onSelect(e=>e.onlyDrawing(r)),{...MA,drawings:[r]}}function PA(e,t,n,r,i){let a=NA(e,t,n===`moveGroup`),o=a.names.filter(t=>e.blockerFor(t)===null),s=`part`in t?e.blockerFor(t.part.name):`drawing`in t?e.drawings?.blocker?.(t.drawing)??null:null,c=`drawing`in t?e.drawings?.origin?.(t.drawing):void 0;return{kind:`drag`,...t,...c?{origin:c}:{},...a,movable:o,start:r,offset:Pe,moved:!1,blocker:s,still:i}}function FA(e,t,n,r){if(t.kind===`pan`)return e.setCamera(Se(t.camera,t.start,n)),!t.moved&&Bk(t.start,n)?{...t,moved:!0}:void 0;if(t.kind===`box`||t.kind===`note`||t.kind===`zoom`)return{...t,current:n};if(!t.moved&&!Bk(t.start,n))return;let i=be(r,e.size,n),a=be(r,e.size,t.start),o={x:i.x-a.x,y:i.y-a.y};if(t.kind===`reshape`)return Ql(t,o,{step:e.step,snap:e.snap!==!1},t=>e.actions.notify(t));if(t.kind===`drag`&&t.drawing!==void 0&&t.blocker)return t.moved||e.actions.notify(t.blocker),t.moved?void 0:{...t,moved:!0};let s=t=>Ee(t,e.step,e.snap!==!1);if(t.kind===`label`){let{at:e}=t.label;return{...t,moved:!0,at:{x:s(e.x+o.x),y:s(e.y+o.y)}}}if(t.kind===`text`)return{...t,moved:!0,at:{x:s(t.from.x+o.x),y:s(t.from.y+o.y)}};let{part:c}=t,l=c?e.anchors.get(c.name)?.origin??c.center:t.origin??Pe;return{...t,moved:!0,offset:{x:_A(s(l.x+o.x)-l.x),y:_A(s(l.y+o.y)-l.y)}}}function IA(e,t,n,r,i){if(t.kind===`label`)return t.moved?t.blocker?e.actions.notify(t.blocker):e.labels?.commit(t.label,t.at):void 0;if(t.kind===`text`)return t.moved?t.blocker?e.actions.notify(t.blocker):e.texts?.commit(t.id,t.at):void 0;if(t.kind===`drag`)return LA(e,t,r);if(t.kind===`reshape`)return eu(e.wires?.drag,t,t=>e.actions.notify(t));if(t.kind===`pan`){if(t.moved)return;t.still===`menu`&&e.onContextMenu(t.target,i),t.still===`disarm`&&e.tool.disarm()}else{if(t.kind===`box`)return BA(e,t,n);if(t.kind===`zoom`)return VA(e,t,n);HA(e,t,n)}}function LA(e,t,n){if(!t.moved)t.still===`selectAlone`&&e.onSelect(RA(t));else{if(t.blocker)return t.drawing===void 0?e.actions.notify(t.blocker):void 0;n(t.names,t.offset,t.wires,t.labels,t.drawings)}}function RA({part:e,wire:t,label:n,drawing:r}){return i=>e?i.only(e.name):t===void 0?r===void 0?n===void 0?i:i.onlyLabel(n):i.onlyDrawing(r):i.onlyWire(t)}function zA(e,t,n){return Math.abs(t.start.x-t.current.x)<gA&&Math.abs(t.start.y-t.current.y)<gA?void 0:[be(n,e.size,t.start),be(n,e.size,t.current)]}function BA(e,t,n){let r=zA(e,t,n);if(!r){t.still===`clear`&&e.onSelect(e=>e.clear());return}let i=Xa(t.start,t.current),a={parts:eo(e.boxes,r[0],r[1],i),wires:io(e.wires?.lines??[],r[0],r[1],i),labels:to(e.labels?.boxes??[],r[0],r[1],i),drawings:Ck(e.drawings?.boxes??[],r[0],r[1],i),copper:hu(e.copper??[],r[0],r[1],i)};e.onSelect(ao(a,t.adds,e.tool.armed,e.layers,e.filter))}function VA(e,t,n){let r=zA(e,t,n);r&&(e.tool.disarm(),e.setCamera(kk(r[0],r[1],e.size)))}function HA(e,t,n){let r=zA(e,t,n);if(!r)return;let[i,a]=r;e.tool.disarm();let o=window.prompt(Ne[e.view].notePrompt);o&&e.actions.mark(o,{view:e.view,x:_A((i.x+a.x)/2),y:_A((i.y+a.y)/2)})}function UA(e,t){return e.kind===`reshape`&&!t?.drag}var WA=new Set([`label`,`text`,`reshape`]),GA=e=>e!==void 0&&WA.has(e);function KA(e,t,n){return UA(e,n)?!0:t!==void 0&&(t===0||e.kind===`reshape`&&Rk(t))}function qA(e,t){let n,r=[],i=e=>{n=e,t(e)};return{press(t,n){let{input:a}=e();r=[...r,a.selection.soleWire].slice(-2);let o=EA(a,t,n);o&&i(o)},wireBeforeDoubleClick:()=>r.length===2?r[0]:void 0,move(t,r){let{input:a}=e();if(!n||!a.camera)return!1;if(KA(n,r,a.wires))return i(void 0),!1;let o=FA(a,n,t,a.camera);return o&&i(o),!0},release(t){let r=n;i(void 0);let{input:a,commit:o}=e();r&&a.camera&&IA(a,r,a.camera,o,t)},cancel(){i(void 0)}}}function JA(e){let{actions:t,builtFrom:n}=e,[r,i]=(0,_.useState)();return(0,_.useEffect)(()=>i(e=>e&&e.sentAt>n?e:void 0),[n]),{pending:(0,_.useMemo)(()=>r&&r.sentAt>n?r:void 0,[r,n]),commit:(n,r,a=[],o=[],s=[])=>{if(r.x===0&&r.y===0)return;let{plan:c,lines:l,labels:u,drawings:d}=hA(e,n,r,a,o,s),f=c.edits.length>0?{names:c.parts,offset:r,wires:l,labels:u,drawings:d,sentAt:Date.now()}:void 0;f&&i(f),U(c,t).then(e=>e||i(e=>e===f?void 0:e))}}}function YA(e,t){(0,_.useEffect)(()=>{if(!GA(e))return;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function XA(e,t){let n=t?.kind===`drag`&&t.moved&&!t.blocker?t:void 0,{follow:r,circuit:i}=e;return(0,_.useMemo)(()=>{if(!n)return;if(!r)return{names:n.movable,offset:n.offset,wires:[]};let{lines:t,labels:i,drawings:a}=hA(e,n.names,n.offset,n.wires,n.labels,n.drawings);return{names:n.movable,offset:n.offset,wires:t,labels:i,drawings:a}},[n,r,i])}function ZA(e){let[t,n]=(0,_.useState)(),{pending:r,commit:i}=JA(e),a=(0,_.useRef)({input:e,commit:i});a.current={input:e,commit:i};let[o]=(0,_.useState)(()=>qA(()=>a.current,n)),s=XA(e,t)??r;YA(t?.kind,o.cancel),(0,_.useEffect)(()=>{t&&UA(t,e.wires)&&o.cancel()},[t,e.wires,o]);let{press:c,move:l,release:u,cancel:d,wireBeforeDoubleClick:f}=o;return{gesture:t,moving:s,pending:r,press:c,move:l,release:u,cancel:d,wireBeforeDoubleClick:f}}function QA(e,t,n){return e?.kind===`pan`&&(e.moved||e.still===`none`)?`grabbing`:e?.kind===`drag`||e?.kind===`label`||e?.kind===`text`||e?.kind===`reshape`?e.blocker?`not-allowed`:`move`:t||e?.kind===`note`||e?.kind===`zoom`?`crosshair`:n?`pointer`:`default`}function $A(e){let t=t=>TO(e.element.current,e.size,t);return{onPointerDown:n=>{if(!e.camera)return;n.currentTarget.setPointerCapture(n.pointerId);let r=t(n);e.tool?.(n,be(e.camera,e.size,r))||e.gestures.press(n,r)},onPointerMove:n=>{if(!e.camera)return;let r=t(n),i=be(e.camera,e.size,r);e.setCursor(i),e.gestures.move(r,n.buttons)||e.hover(i)},onPointerUp:n=>{e.camera&&e.toolRelease&&e.toolRelease(be(e.camera,e.size,t(n))),e.gestures.release({x:n.clientX,y:n.clientY})},onPointerCancel:()=>e.gestures.cancel(),onLostPointerCapture:()=>e.gestures.cancel(),onDoubleClick:n=>{e.camera&&Hk(n)&&e.open?.(be(e.camera,e.size,t(n)))}}}function ej({selection:e,boxes:t,size:n,setCamera:r,notify:i}){TS({fitSelection:()=>{let a=Ok(t,e.names,n,wk);`camera`in a?r(a.camera):i(a.message)}})}var tj=`Drag a box where the note for the agent goes. Esc or a right click stops.`,nj=`Drag a box to zoom to it. Esc or a right click stops.`,rj=e=>e,ij=e=>e===`note`?tj:e===`zoom`?nj:void 0,aj=e=>e===`zoom`?`fitArea`:null;function oj(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e=>{Xd(Pd(e))&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function sj(e){let[t,n]=(0,_.useState)(null),r=(0,_.useCallback)(()=>n(null),[]),i=(0,_.useCallback)(t=>{e?.(),n(rj(t))},[e]);return TS({noteBox:()=>i(`note`),fitArea:()=>i(`zoom`)}),oj(t!==null,r),{armed:t!==null,which:t,tool:t,arm:i,disarm:r,hint:ij(t)}}function cj(e,t){return t===void 0?`no net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function lj(e,t){let n=e.circuit.nets.find(e=>e.id===t);if(n)return{id:t,name:n.names[0]??t,width:E_(e.rules,n),via:k_(e.rules,n)}}function uj(e,t){let n=e.circuit.components.find(e=>e.id===t.component)?.pins.find(e=>e.id===t.pin),r=n?.names.find(e=>!/^pin\d+$/.test(e))??n?.names[0];return r?`${t.component}.${r}`:t.id}var dj=(e,t)=>t===void 0?{}:{net:t,netName:cj(e,t)};function fj(e,t,n){if(!iu({kind:`via`},e.visible))return;let r=e.copper.vias.find(e=>e.missingLayer===void 0&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=Math.max(e.diameter/2,n));return r&&{kind:`via`,id:r.id,at:r.at,...dj(e.design,r.net)}}function pj(e,t,n){let r=vp(e.design.pcb,t,n,e.visible);return r&&{kind:`pad`,id:r.id,label:uj(e.design,r),part:r.component,at:{x:r.x,y:r.y},...dj(e.design,r.net),layer:r.layers}}function mj(e,t,n,r){let[i,a]=[t.x-e.x,t.y-e.y],o=i*i+a*a,s=o===0?0:Math.max(0,Math.min(1,((n.x-e.x)*i+(n.y-e.y)*a)/o)),c={x:V(e.x+s*i),y:V(e.y+s*a)},l=a===0&&i!==0?`x`:i===0&&a!==0?`y`:void 0;if(!l||!r?.snap)return c;let u=Ee(c[l],r.step);return u>=Math.min(e[l],t[l])&&u<=Math.max(e[l],t[l])?{...c,[l]:u}:c}function hj(e,t,n,r,i){let a;for(let o of e.copper.tracks)if(!(r!==void 0&&o.layer!==r||!iu({kind:`track`,layer:o.layer},e.visible)))for(let e=1;e<o.points.length;e++){let r=mj(o.points[e-1],o.points[e],t,void 0),s=Math.hypot(r.x-t.x,r.y-t.y);s<=Math.max(o.width/2,n)&&(!a||s<a.d)&&(a={track:o,at:mj(o.points[e-1],o.points[e],t,i),d:s})}return a&&{kind:`track`,id:a.track.id,at:a.at,...dj(e.design,a.track.net),layer:a.track.layer}}function gj(e,t,n,r,i){return fj(e,t,n)??pj(e,t,n)??hj(e,t,n,r,i)}var _j=(e,t)=>e.mark===void 0||t===void 0||t<=e.mark,vj=(e,t,n)=>[...e,{...n,id:t}],yj=(e,t,n)=>e.map(e=>e.id===t?{...e,mark:n}:e),bj=(e,t)=>e.filter(e=>e.id!==t),xj=(e,t)=>e.filter(e=>_j(e,t)),Sj=e=>e.some(e=>e.mark===void 0);function Cj(e,t){return xj(e,t).reduce((e,t)=>tx(e,t.shapes),Wb)}function wj(e,t){return[...xj(e,t)].reverse().find(e=>e.parts!==void 0)?.parts}var Tj=Math.PI/12,Ej=.005,Dj=.01,Oj=.001,kj=2*Oj,Aj=1e-4,jj=.01,Mj=1e6,Nj=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Pj=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Fj=(e,t)=>({x:e.x*t,y:e.y*t}),Ij=e=>Math.hypot(e.x,e.y),Lj=e=>Fj(e,1/Ij(e)),Rj=(e,t)=>e.x*t.y-e.y*t.x,zj=(e,t)=>e.x*t.x+e.y*t.y,Bj=e=>({x:Math.round(e.x*Mj)/Mj,y:Math.round(e.y*Mj)/Mj}),Vj=(e,t)=>Math.abs(e-t)<=Aj+jj*Math.max(e,t),Hj=(e,t)=>Math.abs(e-t)<=Oj;function Uj(e){let t=e<=.005/2?Math.PI:2*Math.acos(1-Ej/e);return Math.min(Tj,t)}function Wj(e){return e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y)}function Gj(e){return e.map((t,n)=>{let[r,i]=[e[n-1],e[n+1]];if(r===void 0||i===void 0)return 0;let[a,o]=[Nj(t,r),Nj(i,t)];return Math.atan2(Rj(a,o),zj(a,o))})}function Kj(e,t,n,r){let[i,a]=[Nj(t,e),Nj(r,n)],o=Rj(i,a);if(!(Math.abs(o)<1e-12))return Pj(e,Fj(i,Rj(Nj(n,e),a)/o))}function qj(e,t,n){let r=t[n];if(Math.abs(r)<=Oj||Math.abs(r)>Tj/2+Oj)return;let i=n+1;for(;i<e.length-1&&Hj(t[i],2*r);)i++;if(i>=e.length-1||!Hj(t[i],r))return;let a=Ij(Nj(e[n+1],e[n]));for(let t=n+1;t<i;t++)if(!Vj(Ij(Nj(e[t+1],e[t])),a))return;let[o,s]=[e[n],e[i]],c=Kj(e[n-1],o,s,e[i+1]);if(c===void 0)return;let[l,u]=[Nj(c,o),Nj(s,c)];return zj(l,Nj(o,e[n-1]))>0&&zj(u,Nj(e[i+1],s))>0&&Vj(Ij(l),Ij(u))?{first:n,last:i,corner:c}:void 0}function Jj(e){let t=Gj(e),n=[];for(let r=1;r<e.length-1;r++){let i=qj(e,t,r);i&&(n.push(i),r=i.last)}return n}var Yj=(e,t)=>Math.max(1,Math.ceil(e/Uj(t)-1e-9));function Xj(e,t,n,r,i){let a=Math.abs(i),o=r*Math.tan(a/2),[s,c]=[Nj(e,Fj(t,o)),Pj(e,Fj(n,o))],l=Math.sign(i),u=Pj(s,Fj({x:-t.y*l,y:t.x*l},r)),d=Yj(a,r),f=Nj(s,u);return[s,...Array.from({length:d-1},(e,t)=>{let n=l*a*(t+1)/d;return Pj(u,{x:f.x*Math.cos(n)-f.y*Math.sin(n),y:f.x*Math.sin(n)+f.y*Math.cos(n)})}),c].map(Bj)}function Zj(e,t,n,r){let i=Wj(e),a=Math.max(t,n),o=Gj(i),s=new Set(Jj(i).flatMap(e=>Array.from({length:e.last-e.first+1},(t,n)=>e.first+n))),c=[i[0]],l=[],u=0;for(let t=1;t<i.length-1;t++){let[n,d,f]=[i[t],c.at(-1),i[t+1]],p=Math.abs(o[t]);if(s.has(t)||p/Yj(p,a)/2<=kj){c.push(n);continue}let m=a*Math.tan(p/2),h=p<Math.PI-Oj&&m+Dj<=Ij(Nj(n,d))&&m+Dj<=Ij(Nj(f,n))?Xj(n,Lj(Nj(n,i[t-1])),Lj(Nj(f,n)),a,o[t]):void 0,g=h?r?.(n,h):`too short`;h&&g===void 0?(c.push(...h),u++):(l.push({index:e.indexOf(n),at:n,reason:g??`too short`}),c.push(n))}return i.length>1&&c.push(i.at(-1)),{points:u===0?[...e]:c,rounded:u,square:l}}function Qj(e,t){let n=Wj(e),r=[],i=Jj(n).filter(e=>{let i=Bj(e.corner),a=t?.(i,n.slice(e.first,e.last+1));return a===void 0||void r.push({at:i,reason:a})});if(i.length===0)return{points:[...e],straightened:0,round:r};let a=[],o=0;for(let e of i)a.push(...n.slice(o,e.first),Bj(e.corner)),o=e.last+1;return a.push(...n.slice(o)),{points:a,straightened:i.length,round:r}}var $j=[`45`,`45r`,`90`,`arc`],eM={45:`45°`,"45r":`45° reversed`,90:`90°`,arc:`Arc`},tM=e=>eM[e];function nM(e){return $j[($j.indexOf(e)+1)%$j.length]}var rM=(e,t)=>({x:V(e),y:V(t)});function iM(e,t,n){let[r,i]=[t.x-e.x,t.y-e.y],a=Math.min(Math.abs(r),Math.abs(i)),[o,s]=[Math.sign(r),Math.sign(i)];return n?Math.abs(r)>Math.abs(i)?rM(e.x+o*(Math.abs(r)-a),e.y):rM(e.x,e.y+s*(Math.abs(i)-a)):rM(e.x+o*a,e.y+s*a)}function aM(e,t,n,r=0){let[i,a]=[Math.abs(t.x-e.x),Math.abs(t.y-e.y)];return i===0||a===0||i===a?[t]:n===`90`?On([e,t]).slice(1):n===`arc`?sM(e,t,r):[iM(e,t,n===`45`),t]}var oM=.98;function sM(e,t,n){let r=On([e,t]),i=oM*Math.min(Math.abs(t.x-e.x),Math.abs(t.y-e.y));return i<n/2?r.slice(1):Zj([e,...r.slice(1)],i,n).points.slice(1)}function cM(e,t,n=0){let r=[e],i=e;for(let e of t)r.push(...aM(i,e.to,e.mode,n)),i=e.to;return Pb(r)}var lM={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},uM=e=>lM[e],dM=e=>e===`top`?`bottom`:`top`;function fM(e,t){if(e.kind===`pad`){if(t.locked.has(e.part))return{message:`${e.part} is locked: a track may not start on its pads. Unlock it first.`};let n=e.layer===`through`;return{start:{label:e.label,at:e.at,through:n},layer:e.layer===`through`?t.activeLayer:e.layer}}let n=`${e.kind} ${e.id}`;return e.kind===`via`?{start:{label:n,at:e.at,through:!0},layer:t.activeLayer}:e.layer!==`top`&&e.layer!==`bottom`?{message:`${n} is on ${uM(e.layer)}, which cannot be routed yet`}:{start:{label:n,at:e.at,through:!1},layer:e.layer}}function pM(e,t){let n=e.net===void 0?void 0:t.netOf(e.net),r=e.kind===`pad`?e.label:`${e.kind} ${e.id}`;if(!n)return{message:`${r} is on no net; connect it in the schematic first`};let i=fM(e,t);return`message`in i?i:{route:{net:n,start:i.start,layer:i.layer,mode:t.mode??`45`,corners:[]}}}function mM(e,t,n){if(!n.snap)return t;let r=r=>Math.abs(t[r]-e[r])<n.step/2?e[r]:Ee(t[r],n.step);return{x:r(`x`),y:r(`y`)}}var hM=e=>e.corners.at(-1)?.at??e.start.at,gM=(e,t)=>e.x===t.x&&e.y===t.y;function _M(e,t){return gM(t,hM(e))?e:{...e,corners:[...e.corners,{at:t,mode:e.mode,layer:e.layer}]}}var vM=e=>({...e,mode:nM(e.mode)});function yM(e,t=dM(e.layer)){return t===e.layer?e:e.corners.length===0&&!e.start.through?{message:`${e.start.label} is on the ${uM(e.layer)} only; click a corner before changing layer`}:{...e,layer:t}}function bM(e){let t=e.corners.at(-1);return t?{...e,corners:e.corners.slice(0,-1),layer:t.layer}:e}function xM(e,t){let n=[...e.corners,{at:t,mode:e.mode,layer:e.layer}],{width:r,via:i}=e.net,a={tracks:[],vias:[]},o={layer:n[0]?.layer??e.layer,from:e.start.at,legs:[]},s=e.start.at,c=()=>{let e=cM(o.from,o.legs.map(e=>({to:e.at,mode:e.mode})),r);e.length>=2&&a.tracks.push({layer:o.layer,width:r,points:e})};for(let e of n)e.layer!==o.layer&&(c(),a.vias.push({at:s,...i}),o={layer:e.layer,from:s,legs:[]}),o.legs.push(e),s=e.at;return c(),a}function SM(e,t){let n=t===void 0?{}:{net:t},r=t=>{let[r,i]=[e.tracks[t],e.vias[t]];return[...r?[{kind:`addTrack`,...n,layer:r.layer,width:r.width,points:r.points}]:[],...i?[{kind:`addVia`,...n,at:i.at,drill:i.drill,diameter:i.diameter,layers:[`top`,`bottom`]}]:[]]};return Array.from({length:Math.max(e.tracks.length,e.vias.length)},(e,t)=>r(t)).flat()}function CM(e,t){let n=t.kind===`pad`?t.label:t.kind===`track`?`Track ${t.id}`:`Via ${t.id}`;if(t.net!==e.net.id)return`${n} is on ${t.netName??`no net`}, but the track is on ${e.net.name}`;let r=t.kind===`via`?`through`:t.layer;if(r!==`through`&&r!==e.layer)return`${n} is on the ${uM(r)}; press V to change layer first`}var wM=e=>e.kind===`pad`?e.label:`${e.kind} ${e.id}`;function TM(e,t){if(e.corners.length===0&&gM(t.at,e.start.at))return;let n=CM(e,t);if(n)return{message:n};let r=xM(e,t.at);return{edits:SM(r,e.net.name),summary:`Route ${e.net.name} from ${e.start.label} to ${wM(t)}`,drawing:r}}function EM(e){let t=e.corners.at(-1);if(!t)return{message:`Click a corner first: a track needs two points. Esc drops it.`};let n=xM({...e,layer:t.layer},t.at);return{edits:SM(n,e.net.name),summary:`Route ${e.net.name} from ${e.start.label}, open at (${t.at.x}, ${t.at.y})`,drawing:n}}function DM(e,t,n,r=g_.via){if(e?.kind===`via`)return{message:`Via ${e.id} is already there`};let i=e?.net===void 0?void 0:n(e.net);return OM(e?e.at:t,i,r)}function OM(e,t,n=g_.via){let r=t?.via??n,i={tracks:[],vias:[{at:e,drill:r.drill,diameter:r.diameter}]},a=`at (${e.x}, ${e.y})`;return{edits:SM(i,t?.name),summary:t?`Add via on ${t.name} ${a}`:`Add via ${a}`,drawing:i}}var kM={route:`singleRouting`,via:`placeVia`},AM=12;function jM(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`45`);return{armed:e,setArmed:t,disarm:(0,_.useCallback)(()=>t(null),[]),route:n,setRoute:r,mode:i,setMode:a}}var MM=`new`;function NM(e){let t=e=>e.net===void 0?{}:{net:e.net};return{tracks:e.flatMap(e=>e.drawing.tracks.map(n=>({id:MM,...t(e),...n}))),vias:e.flatMap(e=>e.drawing.vias.map(n=>({id:MM,...t(e),at:n.at,diameter:n.diameter})))}}function PM(e,t){let[n,r]=(0,_.useState)([]),i=(0,_.useRef)(0);(0,_.useEffect)(()=>r(t=>xj(t,e)),[e]);let a=(0,_.useMemo)(()=>xj(n,e),[n,e]);return{drawings:(0,_.useMemo)(()=>a.map(e=>({drawing:e.drawing,alpha:_u})),[a]),copper:(0,_.useMemo)(()=>NM(a),[a]),send:(0,_.useCallback)((e,n)=>{i.current+=1;let a=i.current;r(t=>[...t,{id:a,drawing:e.drawing,...n===void 0?{}:{net:n}}]),t.editLayout(e.edits,e.summary).then(e=>r(t=>e.ok&&e.mark!==void 0?yj(t,a,e.mark):bj(t,a)))},[t])}}function FM(e,t){let n={tracks:[...e.copper.tracks,...t.tracks],vias:[...e.copper.vias,...t.vias]};return{design:e.design,copper:n,visible:e.layers}}function IM(e,t,n){let{design:r,actions:i,onActiveLayer:a,arm:o,onArm:s}=e,{route:c,setRoute:l}=o,u=(n,r=c===null)=>{if(!e.camera)return;let i=r?void 0:c?.layer??e.activeLayer;return gj(FM(e,t),n,AM/e.camera.scale,i,{step:e.step,snap:e.snap})},d=t=>{l(t),t.layer!==e.activeLayer&&a(t.layer)};return{input:e,route:c,setRoute:l,put:d,targetAt:u,start:t=>{let n=pM(t,{activeLayer:e.activeLayer,locked:e.locked,netOf:e=>lj(r,e),mode:o.mode});if(`message`in n)return i.notify(n.message);d(n.route)},changeLayer:e=>{if(!c)return a(e);let t=yM(c,e);`message`in t&&i.notify(t.message),d(`message`in t?c:t)},arm:e=>{s(),l(null),o.setArmed(e)},cancel:()=>c?l(null):o.disarm(),send:n,stepCorner:()=>{let e=nM(c?.mode??o.mode);o.setMode(e),c?d({...c,mode:e}):i.notify(`Routing corner: ${tM(e)}`)}}}function LM(e){let{input:t,route:n}=e;if(!n)return;let r=EM(n);if(`message`in r)return t.actions.notify(r.message);e.setRoute(null),e.send(r,n.net.id)}function RM(e,t){let{input:n,route:r}=e,i=Pd(t),a=()=>{t.preventDefault(),t.stopPropagation()};if(Xd(i)&&(r||n.arm.armed))return a(),e.cancel();let o=Yd(i,{view:`pcb`,drawing:r!==null});if(o){if(o.action===`route`||o.action===`placeVia`){if(o.preventDefault&&t.preventDefault(),r)return;e.arm(o.action===`route`?`route`:`via`);let i=o.action===`route`&&n.cursor?e.targetAt(n.cursor):void 0;i&&e.start(i)}else{if(o.action===`switchLayer`)return a(),e.changeLayer(dM(r?.layer??n.activeLayer));if(o.action===`routingCorner`)return a(),e.stepCorner();if(o.action===`finishShape`)return r?(a(),LM(e)):void 0;!r||o.action!==`flipBend`&&o.action!==`removeCorner`||(a(),o.action===`flipBend`&&n.arm.setMode(vM(r).mode),e.put(o.action===`flipBend`?vM(r):bM(r)))}}}function zM(e){(0,_.useEffect)(()=>{let t=t=>RM(e.current,t);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function BM(e,t,n){let{input:r}=e,i=e.targetAt(t,!0),a=DM(i,De(t,r.step,r.snap),e=>lj(r.design,e),A_(r.design.rules));if(`message`in a)return r.actions.notify(a.message);n(a,i?.net)}function VM(e,t,n){let{input:r,route:i}=e,a=e.targetAt(t);if(!i){a&&e.start(a);return}if(!a){let n=_M(i,mM(hM(i),t,r));return n===i&&i.corners.length>0?LM(e):e.put(n)}let o=TM(i,a);if(o){if(`message`in o)return r.actions.notify(o.message);e.setRoute(null),n(o,i.net.id)}}function HM(e,t,n,r){let{input:i}=e;return!i.arm.armed||t.button!==0?!1:(i.arm.armed===`via`?BM(e,n,r):VM(e,n,r),!0)}function UM(e,t){let{route:n,input:r}=e;if(n&&t)return xM(n,e.targetAt(t)?.at??mM(hM(n),t,r))}var WM=(e,t,n)=>e===`via`?`Via: click to place one; it takes the net of the pad or track under it. Esc to stop.`:e===`route`&&!t?`Single routing: click a pad, a track or a via to start a track on the ${uM(n)}. Esc to stop.`:void 0;function GM(e){let{route:t,setRoute:n}=e.arm,r=PM(e.builtMark,e.actions),i=IM(e,r.copper,r.send),a=(0,_.useRef)(i);a.current=i,zM(a),TS({singleRouting:()=>a.current.arm(`route`),placeVia:()=>a.current.arm(`via`),routingCorner:()=>a.current.stepCorner()});let{armed:o}=e.arm;(0,_.useEffect)(()=>{o!==`route`&&n(null)},[o,n]),(0,_.useEffect)(()=>{t&&t.layer!==e.activeLayer&&a.current.changeLayer(e.activeLayer)},[t,e.activeLayer]);let s=UM(i,e.cursor),c=s?[...r.drawings,{drawing:s,alpha:1}]:r.drawings,l=o?kM[o]:null;return{armed:o!==null,routing:t!==null,command:l,routes:c,status:t?LO(t.net.name,uM(t.layer),t.net.width,tM(t.mode)):void 0,hint:WM(o,t,e.activeLayer),press:(e,t)=>HM(a.current,e,t,r.send),cancel:()=>a.current.cancel()}}var KM;function qM(e){KM=e}function JM(){return KM}function YM(e,t,n){if(!t||n!==void 0&&n>t.mark)return e;let{filletRadius:r,...i}=e.rules.fabrication;return{...e,rules:{...e.rules,fabrication:t.radius===null?i:{...i,filletRadius:t.radius}}}}var XM=1e-6;function ZM(e,t){return!(e>=t-XM)}function QM(e,t,n,r,i,a){let o=Xr(r),s={id:`${e}:${o.join(`,`)}`,code:e,severity:t,message:n,items:o,view:i};return a===void 0?s:{...s,at:a}}var $M=e=>e.toFixed(3),eN=e=>e>0?`${$M(e)} mm apart`:`touching or overlapping`;function tN(e,t,n,r,i){return{...QM(e,`error`,t,r,`pcb`,i),id:`${e}:${n.join(`|`)}`}}var nN=2,rN=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),iN=([e,t])=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2}),aN=(e,t)=>e.net!==void 0&&e.net===t.net;function oN(e,t){return e.flatMap(e=>e.shapes.map(n=>({piece:e,shape:n,box:bi(n),rank:t(e)})))}function sN(e,t){let n=[...new Set(e.map(e=>e.className))].sort(Yr);return n.flatMap(e=>n.map(n=>w_(t,e,n))).reduce((e,t)=>Math.max(e,t),t.fabrication.minClearance)}function cN(e,t){return t.piece===e.piece||aN(e.piece,t.piece)?!1:t.rank===-1||t.rank>e.rank}function lN(e,t){return Yr(e.piece.id,t.piece.id)<=0?[e,t]:[t,e]}function uN(e,t,n){let[r,i]=lN(t,n),a=`${r.piece.id}|${i.piece.id}`,o=_i(r.shape,i.shape),s=e.get(a);(s===void 0||o<s.distance)&&e.set(a,{a:r,b:i,distance:o})}function dN(e,t,n,r){let i=new PS(n);for(let t of e)i.insert(t,t.box);for(let n of e)if(n.rank!==-1)for(let e of i.query(rN(n.box,t)))cN(n,e)&&uN(r,n,e)}function fN({a:e,b:t}){if(e.piece.kind!==`pad`&&t.piece.kind!==`pad`)return WS(e.shape,t.shape);let[n,r]=e.piece.kind===`pad`?[e,t]:[t,e];return n.piece.net===void 0?!1:r.piece.kind===`track`?r.piece.pads?.includes(n.piece.id)??!1:r.shape.core.some(e=>WS(n.shape,{core:[e],radius:0}))}function pN(e,t,n){if(t===n)return t;let r=e.classClearance.find(e=>e.a===t&&e.b===n||e.a===n&&e.b===t);return r===void 0?`${t}–${n}`:`${r.a}–${r.b}`}function mN(e,t,n,r){return w_({...e,fabrication:{...e.fabrication,minClearance:0}},t,n)<r?`the fabrication minimum is ${$M(r)} mm`:`${pN(e,t,n)} needs ${$M(r)} mm`}var hN=({a:e,b:t})=>e.piece.net!==void 0&&t.piece.net!==void 0&&e.piece.net!==t.piece.net;function gN(e,t){if(fN(e)&&!hN(e))return;let{a:n,b:r,distance:i}=e,a=w_(t,n.piece.className,r.piece.className);return ZM(i,a)?tN(`copper-clearance`,`${n.piece.id} and ${r.piece.id} are ${eN(i)}; ${mN(t,n.piece.className,r.piece.className,a)}`,[n.piece.id,r.piece.id],[n.piece.id,r.piece.id],iN(yi(n.shape,r.shape))):void 0}var _N=e=>t=>t.piece.layers.includes(e);function vN(e,t,n){if(e.length===0)return[];let r=new Map(e.map((e,t)=>[e,t])),i=[...oN(e,e=>r.get(e)??-1),...oN(t,()=>-1)],a=sN([...e,...t],n),o=Math.max(nN,a),s=new Map;for(let e of jS){let t=i.filter(_N(e));t.some(e=>e.rank!==-1)&&dN(t,a,o,s)}return[...s.keys()].sort(Yr).flatMap(e=>gN(s.get(e),n)??[])}var yN=e=>e===void 0?{}:{net:e};function bN(e){return e.layers===`through`?jS:[e.layers]}function xN(e,t){let n=si(e);if(n===void 0)return;let r=e.net===void 0?g_.name:t(e.net);return{id:e.id,kind:`pad`,...yN(e.net),className:r,layers:bN(e),shapes:[n],at:{x:e.x,y:e.y}}}function SN(e){let t=e.width/2;return e.points.length===1?[{core:[e.points[0]],radius:t}]:e.points.slice(1).map((n,r)=>({core:[e.points[r],n],radius:t}))}function CN(e,t){let n=e.points[0]??{x:0,y:0};return{id:e.id,kind:`track`,...yN(e.net),className:t(e.net),layers:[e.layer],shapes:SN(e),at:n,pads:e.pads}}function wN(e,t){let n={core:[e.at],radius:e.diameter/2};return{id:e.id,kind:`via`,...yN(e.net),className:t(e.net),layers:[...VS(e)],shapes:[n],at:e.at}}function TN(e,t){return e.parts.flatMap(e=>e.pads).flatMap(e=>xN(e,t)??[])}function EN(e,t){let n=e=>e.missingLayer===void 0;return[...e.tracks.filter(n).map(e=>CN(e,t)),...e.vias.filter(n).map(e=>wN(e,t))].filter(e=>e.shapes.length>0).sort((e,t)=>Yr(e.id,t.id))}function DN(e,t){let n={distance:1/0,at:t[0]};for(let r of e)t.forEach((e,i)=>{let a={core:[e,t[(i+1)%t.length]],radius:0},o=_i(r,a);o<n.distance&&(n={distance:o,at:yi(r,a)[1]})});return n}function ON(e,t){return!mi(e,t)&&DN([{core:[e],radius:0}],t).distance>1e-6}function kN(e,t,n){let r=n.fabrication.boardEdgeClearance,i=(t,n)=>tN(`copper-edge`,t,[e.id],[e.id],n),a=e.shapes.flatMap(e=>e.core).find(e=>ON(e,t));if(a!==void 0)return i(`${e.id} ${e.kind===`track`?`runs`:`is`} outside the board`,a);let{distance:o,at:s}=DN(e.shapes,t);if(ZM(o,r))return i(o>0?`${e.id} is ${$M(o)} mm from the board edge; the minimum is ${$M(r)} mm`:`${e.id} crosses the board edge; the minimum gap to it is ${$M(r)} mm`,s)}var AN=(e,t)=>e.layers===`all`||t.layers.includes(e.layers);function jN(e,t){let n=e.core.find(e=>mi(e,t));if(n!==void 0)return n;let r={core:[...t],radius:0};return _i(e,r)<-1e-6?yi(e,r)[1]:void 0}function MN(e,t){if(!AN(t,e))return;let n=e.shapes.map(e=>jN(e,t.outline)).find(e=>e!==void 0);if(n!==void 0)return tN(`copper-keepout`,`${e.id} lies inside ${t.id}`,[e.id,t.id],[e.id,t.id],n)}var NN=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY,PN=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function FN(e){return e.map(bi).reduce((e,t)=>({minX:Math.min(e.minX,t.minX),minY:Math.min(e.minY,t.minY),maxX:Math.max(e.maxX,t.maxX),maxY:Math.max(e.maxY,t.maxY)}))}function IN({layout:e,rules:t,classOf:n}){let r=[t.fabrication.minClearance,g_.clearance,...t.classes.map(e=>e.clearance),...t.classClearance.map(e=>e.clearance)];return{copper:EN(e,n),pads:TN(e,n),reach:Math.max(...r)}}var LN=(e,t)=>t.slice(1).map((n,r)=>({core:[t[r],n],radius:e.width/2}));function RN(e,t,n){let r=e.net===void 0?{}:{net:e.net};return{id:e.id,kind:`track`,...r,className:n(e.net),layers:[e.layer],shapes:LN(e,t),at:t[0],pads:e.pads}}var zN=(e,t)=>e.shapes.some(e=>t.some(t=>WS(e,t)));function BN(e,t,n,r){return e.some(e=>e.net===t.net&&zN(e,n)&&!zN(e,r.shapes))}function VN(e,t,n,r){let i=e.find(e=>e!==t.id)??``,a=n.find(e=>e.id===i);return a?.net===void 0?i:r.netName(a.net)}function HN(e,t){let n=t.layout.board;if(n===void 0)return;if(ti(n)&&kN(e,n.outline,t.rules))return`too close to the board edge`;let r={...e,shapes:e.shapes.map(e=>({...e,radius:e.radius+t.rules.fabrication.minClearance}))},i=n.keepouts.find(e=>e.outline.length>=3&&MN(r,e));return i?`too close to ${i.id}`:void 0}function UN(e,t,n){let r=e=>e.id!==n.id&&e.layers.includes(n.layer),[i,a]=[t.copper.filter(r),t.pads.filter(r)];return(r,o,s)=>{let c=RN(n,r,e.classOf),l=LN(n,o),u=PN(FN([...c.shapes,...l]),t.reach+n.width),d=e=>NN(FN(e.shapes),u),[f,p]=[i.filter(d),a.filter(d)];if(BN([...f,...p],n,l,c))return s;let m=vN([c,...f],p,e.rules).find(e=>e.items.includes(n.id));return m?`too close to ${VN(m.items,n,[...f,...p],e)}`:HN(c,e)}}var WN=(e,t)=>[t[0],e,t.at(-1)];function GN(e,t,n){let r=UN(e,t,n);return(e,t)=>r(t,WN(e,t),`joined on the corner's legs`)}function KN(e,t,n){let r=UN(e,t,n);return(e,t)=>r(WN(e,t),t,`joined on the arc`)}var qN=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function JN(e,t){let n=t.ids===void 0?void 0:new Set(t.ids),r=e.pcb.tracks.filter(e=>e.missingLayer===void 0&&(n===void 0||n.has(e.id))),i=[],a=t.lockedParts?.size?mn(t.lockedParts,e.circuit.instances):void 0;return{tracks:r.filter(t=>{if(t.locked)return void i.push(`${t.id} is locked`);let n=t.points[0],r=n&&a?US(e.pcb.parts,n,t.layer).find(e=>a.has(e.component))?.component:void 0;return r===void 0||void i.push(`${t.id} starts on the locked part ${r}`)}),skipped:i}}var YN=(e,t)=>[e,...t].join(`; `);function XN(e){let t=x_(e.rules,e.circuit.nets).byNet,n=new Map(e.circuit.nets.map(e=>[e.id,e.names[0]??e.id]));return{layout:e.pcb,rules:e.rules,classOf:e=>e===void 0?g_.name:t.get(e)??g_.name,netName:e=>n.get(e)??e}}function ZN(e,t={}){let{tracks:n,skipped:r}=JN(e,t);if(n.length===0)return{changes:[],summary:YN(`No tracks to round`,r)};let i=t.radius??j_(e.rules),a=XN(e),o=IN(a),s=[],c=[],[l,u]=[0,0];for(let e of n){let t=Zj(e.points,i,e.width,GN(a,o,e));t.rounded>0&&s.push({id:e.id,points:t.points}),l+=t.rounded,u+=t.square.length;for(let e of t.square)c.includes(e.reason)||c.push(e.reason)}return l===0&&u===0?{changes:s,summary:YN(`No square corners to round`,r)}:{changes:s,summary:YN(l===0?`No corner was rounded`:`Rounded ${qN(l,`corner`)} on ${qN(s.length,`track`)}`,[...u===0?[]:[`${u} left square: ${c.join(`, `)}`],...r])}}function QN(e,t={}){let{tracks:n,skipped:r}=JN(e,t),i=XN(e),a=IN(i),o=[],s=[],[c,l]=[0,0];for(let e of n){let t=Qj(e.points,KN(i,a,e));t.straightened>0&&o.push({id:e.id,points:t.points}),c+=t.straightened,l+=t.round.length;for(let e of t.round)s.includes(e.reason)||s.push(e.reason)}return c===0&&l===0?{changes:o,summary:YN(`No rounded corners to straighten`,r)}:{changes:o,summary:YN(c===0?`No corner was straightened`:`Straightened ${qN(c,`corner`)} on ${qN(o.length,`track`)}`,[...l===0?[]:[`${l} kept round: ${s.join(`, `)}`],...r])}}var $N={filletTracks:`Fillet`,straightenTracks:`Straighten`};function eP(e,t,n){let r=new Set(t.map(e=>e.id));if(n.total>0){let t=n.copper.filter(e=>r.has(e));return t.length>0?{ids:t}:{message:`Select tracks to ${$N[e].toLowerCase()}, or nothing for every track of the board.`}}if(t.length===0)return{message:`The board has no tracks.`};let i=t.length===1?`the board's one track`:`all ${t.length} tracks of the board`;return{confirm:`${$N[e]} ${i}?`}}function tP(e,t,n,r){let i={...n?{ids:n}:{},lockedParts:r},a=e===`filletTracks`?ZN(t,i):QN(t,i);if(a.changes.length===0)return{message:a.summary};let o=a.changes.map(e=>({kind:`setTrack`,id:e.id,points:e.points})),s=new Map(a.changes.map(e=>[e.id,e.points]));return{edits:o,summary:a.summary,shapes:{tracks:s,vias:new Map}}}function nP(e,t){if(e.busy())return e.notify(`Wait for the last copper change to land, then try again.`);let n=YM(e.design,JM(),e.builtMark),r=eP(t,n.pcb.tracks.filter(e=>e.missingLayer===void 0),e.selection);if(`message`in r)return e.notify(r.message);if(r.confirm!==void 0&&!window.confirm(r.confirm))return;let i=tP(t,n,r.ids,e.lockedParts);if(`message`in i)return e.notify(i.message);e.send(i),e.notify(i.summary)}function rP(e){let t=(0,_.useRef)(e);t.current=e,TS({filletTracks:()=>nP(t.current,`filletTracks`),straightenTracks:()=>nP(t.current,`straightenTracks`)}),(0,_.useEffect)(()=>{let e=e=>{if(t.current.routing||e.repeat)return;let n=Yd(Pd(e),{view:`pcb`})?.action;(n===`filletTracks`||n===`straightenTracks`)&&(e.preventDefault(),nP(t.current,n))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[])}function iP(e){let t=e.withoutTexts(e.texts);return t.total===0&&e.total>0?void 0:t}var aP=`Deleted in two changes: the copper in the layout file, the rest in the circuit file.`;function oP(e,t){if(!t)return{copper:[],rest:e};let n=e.withoutCopper(e.copper);return{copper:e.copper,rest:n.total===0?void 0:n}}function sP(e,t,n){return e>0?{removeCopper:!0,notice:t}:n?{removeCopper:!1}:{removeCopper:!1,notice:t}}var cP=`Select a part or a wire first.`,lP=e=>[...new Set(e)];function uP(e,t){let n=e?.withWires.filter(e=>t.has(e.wire)).map(e=>e.label)??[];return new Set([...e?.withParts??[],...n])}function dP(e,t,n,r,i,a){if(e.total===0)return{message:cP};let o=bt(e.names,t),s=new Set(o.parts),c=r&&e.labelCount>0?r(e.labels,s):void 0,l=lP([...e.wires,...c?.withWires.map(e=>e.wire)??[]]),u=n&&l.length>0?n(l,s,new Set(o.skipped)):void 0,d=lP([...e.drawings,...u?.junctions??[]]),f=i&&d.length>0?i(d):void 0,p=a&&e.boardCount>0?a(e.board):void 0,m={edits:[...u?.edits??[],...f?.edits??[],...p?.edits??[],...o.edits],summary:`remove ${H([...o.parts,...ct(u?.names??[]),...f?.names??[],...p?.names??[]])}`,parts:o.parts,skipped:[...o.skipped,...u?.skipped??[],...c?.skipped??[],...f?.skipped??[],...p?.skipped??[]],done:`removed`},h=new Set([...u?.removed??[],...u?.withParts??[]]),g=uP(c,h);return{plan:m,wires:e.wires.filter(e=>h.has(e)),labels:e.labels.filter(e=>g.has(e)),drawings:f?.removed??[],board:p?.removed??[],...o.parts.length>0?{question:xt(o.parts,(u?.removed??[]).filter(t=>e.hasWire(t)).length)}:{}}}var fP=new Set;function pP(e){return fP.add(e),()=>{fP.delete(e)}}function mP(e){for(let t of fP)t(e);return e}var hP=e=>(e.minX+e.maxX)/2,gP=e=>(e.minY+e.maxY)/2,_P=e=>e.maxX-e.minX,vP=e=>e.maxY-e.minY;function yP(e,t,n,r){let i=new Map;for(let{name:a,box:o}of e){let e=V(n(o)-r(o));e!==0&&i.set(a,t===`x`?{x:e,y:0}:{x:0,y:e})}return i}function bP(e,t){let[n,r,i]=t===`x`?[`minX`,`maxX`,_P]:[`minY`,`maxY`,vP],a=[...e].sort((e,t)=>e.box[n]-t.box[n]||e.name.localeCompare(t.name)),o=a[0],s=a.slice(1).reduce((e,t)=>!e||t.box[r]>e.box[r]?t:e,void 0);if(!o||!s||a.length<3)return new Map;let c=(s.box[r]-o.box[n]-a.reduce((e,{box:t})=>e+i(t),0))/(a.length-1),l=new Map,u=o.box[r];for(let{name:e,box:r}of a.slice(1).filter(e=>e!==s)){let a=V(u+c-r[n]);a!==0&&l.set(e,t===`x`?{x:a,y:0}:{x:0,y:a}),u+=c+i(r)}return l}function xP(e,t){let n=Ae(t.map(e=>e.box));if(!n)return new Map;switch(e){case`alignLeft`:return yP(t,`x`,()=>n.minX,e=>e.minX);case`alignRight`:return yP(t,`x`,()=>n.maxX,e=>e.maxX);case`alignTop`:return yP(t,`y`,()=>n.maxY,e=>e.maxY);case`alignBottom`:return yP(t,`y`,()=>n.minY,e=>e.minY);case`alignHCentres`:return yP(t,`y`,()=>gP(n),gP);case`alignVCentres`:return yP(t,`x`,()=>hP(n),hP);case`distributeH`:return bP(t,`x`);case`distributeV`:return bP(t,`y`)}}var SP={alignLeft:`align {} left`,alignRight:`align {} right`,alignTop:`align {} top`,alignBottom:`align {} bottom`,alignHCentres:`align {} horizontal centres`,alignVCentres:`align {} vertical centres`,distributeH:`distribute {} horizontally`,distributeV:`distribute {} vertically`};function CP(e,t,n){return SP[e].replace(`{}`,H(t))+Ne[n].where}function wP(e,t,n,r,i){let[a,o]=Ne[n].position,[s,c]=ze(e,t,n,ft(r.anchors,r.boxes)(t),i);return{[a]:s,[o]:c}}function TP(e,t,n,r,i,a){let o=_t(r),s=r.boxes.filter(e=>t.includes(e.name)),c=new Set(s.map(e=>e.name)),l=t.filter(e=>!c.has(e)).map(e=>`${e} ${o(e)?`has no box in`:`is not in`} this view`),u=ee(i);if(s.length<u){let e=l.length>0?` (${l.join(`; `)})`:``;return{message:`${u===2?`Align`:`Distribute`} needs ${u} or more parts in this view${e}.`}}let d=xP(i,s),f=i.startsWith(`distribute`)?` and kept its place; others may overlap it`:``,p=[...d.keys()].flatMap(e=>{let t=a(e);return t===null?[]:`${t}${f}`}),m=s.map(e=>e.name).filter(e=>d.has(e)&&a(e)===null),h=[...l,...p];return m.length===0?{message:h.length>0?`Nothing moves. ${h.join(`; `)}.`:`The parts are already there.`}:{edits:m.map(t=>({kind:`setProps`,part:t,props:wP(e,t,n,r,d.get(t))})),summary:CP(i,m,n),parts:m,skipped:h,done:`moved`}}function EP(e,t,n,r=[],i=[]){return{parts:t.edits.flatMap(t=>{if(t.kind!==`setProps`)return[];let{schX:n,schY:r}=t.props;if(typeof n!=`number`||typeof r!=`number`)return[];let i=e.circuit.components.find(e=>e.id===t.part)?.groupOffset.sch??Pe;return[{name:t.part,to:{x:V(n+i.x),y:V(r+i.y)}}]}),wires:n,...r.length>0?{labels:r}:{},...i.length>0?{drawings:i}:{}}}function DP(e,t){let n=e.parts.find(e=>t.has(e.name)),r=n&&t.get(n.name)?.origin,i=n&&r?{x:V(n.to.x-r.x),y:V(n.to.y-r.y)}:Pe,{labels:a,drawings:o}=e;return{names:e.parts.map(e=>e.name),offset:i,wires:e.wires,...a?{labels:a}:{},...o?{drawings:o}:{}}}var OP=e=>`${e.x},${e.y}`;function kP(e,t,n,r){let i=t.get(e.id),a=i?.[i.length-1];return i&&a?a.x===e.at.x&&a.y===e.at.y?void 0:{at:a,side:Br(i[i.length-2],a)}:n.has(OP(e.at))&&(r.x!==0||r.y!==0)?{at:{x:V(e.at.x+r.x),y:V(e.at.y+r.y)},side:e.side}:void 0}function AP(e,t){if(!t)return e.labels;let n=new Set(e.symbols.filter(e=>t.names.includes(e.component)).flatMap(e=>Object.values(e.pinEnds).map(OP))),r=new Map((t.wires??[]).map(e=>[`label:${e.id.slice(5)}`,e.points])),i=e.labels.map(e=>kP(e,r,n,t.offset));return i.every(e=>e===void 0)?e.labels:e.labels.map((e,t)=>({...e,...i[t]}))}function jP(e,t){e.gate.held||(e.queue=[]);let n=e.gate.held!==void 0||e.arrows!==void 0;n!==e.told&&(e.told=n,t.holding(n))}function MP(e,t,n,r){let i=e.gate.waiting;n.edits.length>0&&(e.gate=ZO(e.gate));let{seq:a}=e.gate;return wt(n,r.actions).then(({ok:r,mark:o})=>(n.edits.length>0&&(e.gate=QO(e.gate,r,a,i,o)),jP(e,t),t.resolved(),r))}function NP(e,t,n,r){let i=vt(n.circuit,n.selection.names,n.view,n.layout,n.blockerFor,r);if(`message`in i)return n.actions.notify(i.message);MP(e,t,i,n)}function PP(e,t,n,r){let i=TP(n.circuit,n.selection.names,n.view,n.layout,r,n.blockerFor);if(`message`in i)return n.actions.notify(i.message);MP(e,t,mA(i,n.circuit,n.follow),n)}function FP(e,t,n,r){r===`rotate`?NP(e,t,n,90):r===`rotateRight`?NP(e,t,n,-90):PP(e,t,n,r)}function IP(e,t,n,r,i){let a=YO(e.gate,n.selection.names,i,n);e.gate=a.gate,a.send?FP(e,t,n,r):i||(e.queue=(e.gate.held?.count??0)>1?[...e.queue,r]:[r]),jP(e,t)}function LP(e,t,n,r){let{burst:i,layout:a}=e;if(!i||!a)return;let o=yt(i.base,i.names,n.view,a,r,n.blockerFor),s={wires:i.wires??[],labels:i.labels??[],drawings:i.drawings??[],offset:r},{plan:c,lines:l,labels:u,drawings:d}=pA(o,i.base,n.follow,s),f=MP(e,t,c,n);n.follow&&c.edits.length>0&&t.moved?.(EP(n.follow.design,c,l,u,d),f),f.then(r=>{if(e.burst!==i&&e.burst?.base!==i.base)return;let a=e.burst?GO(e.burst,r):void 0;e.burst=a?.burst,a?.send&&LP(e,t,n,a.send)})}function RP(e,t,n,r){let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=WO(e.burst,n.circuit,i,r,a,o,s);e.burst=c.burst,c.fresh&&(e.layout=n.layout),c.send&&LP(e,t,n,c.send)}function zP(e,t,n){let r={waiting:e.gate.waiting,history:e.gate.history};e.gate=$O(e.gate),e.burst=void 0;let{seq:i}=e.gate;n.catch(()=>({ok:!1})).then(({ok:n,mark:a})=>{e.gate=ek(e.gate,n,i,r,a),jP(e,t),t.resolved()})}function BP(e){let t={gate:KO,told:!1,queue:[]};return{nudge(n,r){let i=Od(r.action);if(!i||n.selection.total===0)return;let a=pt(i,n.layout.step,r.steps??1,n.layout.snap!==!1),o=tk(t.gate,n);t.gate=o.gate,o.send?RP(t,e,n,a):t.arrows=nk(t.arrows,n.selection.names,a,n.selection.wires,n.selection.labels,n.selection.drawings),jP(t,e)},rotate(n,r){IP(t,e,n,`rotate`,r)},rotateRight(n){IP(t,e,n,`rotateRight`,!1)},align(n,r){IP(t,e,n,r,!1)},settle(n){let r=XO(t.gate,n.selection.names,n);t.gate=r.gate,r.send&&FP(t,e,n,t.queue.shift()??`rotate`);let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=rk(t.gate,t.arrows,i,n,a,o,s);t.gate=c.gate,t.arrows=c.held,c.send&&RP(t,e,n,c.send),jP(t,e)},historyWrite:n=>zP(t,e,n)}}function VP(e){let[t,n]=(0,_.useState)(0),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(),[s]=(0,_.useState)(()=>BP({resolved:()=>n(e=>e+1),holding:i,moved:(e,t)=>{let n={...e,sentAt:Date.now()};o(n),t.then(e=>e||o(e=>e===n?void 0:e))}})),{builtMark:c,buildStatus:l,moveWaiting:u,circuit:d}=e;return(0,_.useEffect)(()=>pP(e=>s.historyWrite(e)),[s]),(0,_.useEffect)(()=>s.settle(e),[s,c,l,u,d,t]),{edits:s,held:r,moved:a}}function HP(e,t){let n=iP(e.selection);if(e.paused||!n)return;let{copper:r,rest:i}=oP(n,e.copper!==void 0),a=()=>r.length>0?e.copper?.remove(r):void 0;if(!i)return a();let o=dP(i,e.blockerFor,e.wire?.removal,e.wire?.labelRemoval,e.drawings,e.board);if(`message`in o){let n=sP(r.length,o.message,t);return n.removeCopper&&a(),n.notice===void 0?void 0:e.actions.notify(n.notice)}let{plan:s,wires:c,labels:l,drawings:u,board:d,question:f}=o;if(f&&!window.confirm(f))return;a();let p=e=>e.without(s.parts).withoutWires(c).withoutLabels(l).withoutDrawings(u).withoutBoard(d);U(s,e.actions).then(t=>{t&&(e.onSelect(p),r.length>0&&e.actions.notify(aP))})}function UP(e,t,n){let r=e.texts&&jf(e.selection,t,e.layout);if(!r)return n.nudge(e,t);e.texts?.nudge(r.id,r.by)}function WP(e,t,n,r){let{action:i}=t;if(E(i))return e.paused||r?void 0:n.align(e,i);if(i.startsWith(`nudge`))return e.paused?void 0:UP(e,t,n);if(i===`fit`)return e.fit();if(i===`delete`)return HP(e,!0);if(i===`contextMenu`){if(e.paused)return;let{target:t,at:n}=e.menuPlace();return e.onContextMenu(t,n)}if(i===`highlight`){let t=e.netUnderPointer();t!==void 0&&e.onHighlight([t])}else i===`rotate`&&e.selection.size>0&&!e.paused&&n.rotate(e,r)}function GP(e){let t=Ap(e.selection,t=>e.wire?.net(t),e.netsOf,t=>e.wire?.labelNet(t));`nets`in t?e.onHighlight(t.nets):e.actions.notify(t.message)}function KP(e,t){let n=t=>()=>{e.paused||(e.selection.size>0?t(e):e.actions.notify(`Select a part first.`))};TS({...Object.fromEntries(w.map(n=>[n,()=>e.paused?void 0:t.align(e,n)])),fit:e.fit,rotate:n(e=>t.rotate(e,!1)),rotateRight:n(e=>t.rotateRight(e)),delete:()=>HP(e,!1),highlight:()=>GP(e)})}function qP(e){let{edits:t,held:n,moved:r}=VP(e);KP(e,t);let{view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:l,blockerFor:u,layout:d,builtMark:f,buildStatus:p,moveWaiting:m,fit:h,netUnderPointer:g,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee}=e;return(0,_.useEffect)(()=>{let e={view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:l,blockerFor:u,layout:d,builtMark:f,buildStatus:p,moveWaiting:m,fit:h,netUnderPointer:g,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee},n=n=>{let r=Yd(Pd(n),{view:i,drawing:o});r&&(ak(r.action,a.size,o,r.preventDefault,a.total)&&n.preventDefault(),WP(e,r,t,n.repeat))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,i,a,o,s,c,l,u,d,f,p,m,h,g,v,y,b,x,S,C,w,T,E,ee]),{rotateHeld:n,keyMove:r}}var JP={x:0,y:0};function YP(e,t,n){let r={id:e.id,start:n.point,moved:!1,offset:JP};if(e.kind===`via`){let n=t.vias.find(t=>t.id===e.id);return n&&{...r,kind:`via`,at:n.at,blocker:n.locked?`${n.id} is locked`:null}}let i=t.tracks.find(t=>t.id===e.id),a=i&&fu(i.points,n.world,n.scale,n.sole,n.width);if(i&&a)return{...r,kind:`track`,grip:a,points:i.points,world:n.world,blocker:i.locked?`${i.id} is locked`:null}}function XP(e,t){return e.kind===`track`&&e.grip?.kind===`segment`&&t?.id===e.id&&t.index===e.grip.index?{...e,segment:t.index}:e}function ZP(e){if(e.kind!==`track`||e.segment===void 0)return;let{id:t}=e;if(!e.moved)return e=>e.onlyCopper(t);if(!e.path||!e.world||!e.last)return;let n=qc(e.path,{x:e.world.x+e.last.x,y:e.world.y+e.last.y})?.index,r=n===void 0?void 0:po({id:t,points:e.path},n);return r&&(e=>e.onlySegment(r))}function QP(e){let{id:t=``,part:n,names:r,copper:i,start:a,origin:o}=e;return{kind:`group`,id:t,start:a,moved:!1,blocker:null,offset:JP,names:r,copper:i,...n===void 0?{}:{part:n},...o?{origin:o}:{}}}function $P(e,t,n){let r=e=>Ee(e,n.step,n.snap);return{x:V(r(e.x+t.x)-e.x),y:V(r(e.y+t.y)-e.y)}}function eF(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):e.kind===`track`&&e.points&&e.grip?{...e,moved:!0,last:t,path:zb(e.points,e.grip,t,n)}:{...e,moved:!0,offset:$P(e.at??e.origin??JP,t,n)}}var tF=e=>e.kind===`group`?e.copper??[]:[e.id];function nF(e,t,n){return!e.moved||e.blocker?Wb:e.kind===`track`?e.path?{tracks:new Map([[e.id,e.path]]),vias:new Map}:Wb:Zb(t,tF(e),e.offset,n).shapes}function rF(e){let t=e.offset.x!==0||e.offset.y!==0;return e.kind===`group`&&e.moved&&t&&(e.names?.length??0)>0?{names:e.names??[],offset:e.offset}:void 0}function iF(e,t,n){if(!e.moved||e.blocker)return;if(e.kind===`track`){let r=t.tracks.find(t=>t.id===e.id),i=r&&e.path?Qb(r,e.path):void 0;return!i||`message`in i?i:{edits:[i],summary:`Reshape track ${e.id}`,shapes:nF(e,t,n)}}let r=tF(e),i=Zb(t,r,e.offset,n);if(i.edits.length===0)return i.skipped.length>0?{message:i.skipped.join(`; `)}:void 0;let a=i.shapes.vias.get(e.id)??JP,o=e.kind===`group`?`Move ${H(r)} by (${e.offset.x}, ${e.offset.y})`:`Move via ${e.id} to (${a.x}, ${a.y})`;return{edits:i.edits,summary:o,shapes:i.shapes}}function aF(e,t){let[n,r]=(0,_.useState)([]),i=(0,_.useRef)(0);(0,_.useEffect)(()=>r(t=>xj(t,e)),[e]);let a=(0,_.useMemo)(()=>Cj(n,e),[n,e]),o=(0,_.useMemo)(()=>wj(n,e),[n,e]),s=(0,_.useCallback)((e,t)=>{i.current+=1;let n=i.current;r(t=>vj(t,n,e)),t.then(e=>r(t=>e.ok&&e.mark!==void 0?yj(t,n,e.mark):bj(t,n)))},[]);return{shapes:a,moving:o,send:(0,_.useCallback)(e=>s({shapes:e.shapes},t.editLayout(e.edits,e.summary)),[s,t]),sendParts:(0,_.useCallback)((e,t)=>s({shapes:Wb,parts:e},t),[s]),inFlight:Sj(n)}}function oF(e){return(t,n)=>{let r=Xf(e.pcb,t);return r!==void 0&&(r.layers===`through`||r.layers===n)}}function sF(e){(0,_.useEffect)(()=>{let t=t=>{let{input:n,shown:r,onPad:i,send:a,cancel:o,inFlight:s}=e.current;if(t.key===`Escape`&&o())return t.stopPropagation();let{copper:c}=n.selection;if(!ix(n.selection,n.routing===!0))return;let l=Yd(Pd(t),{view:`pcb`}),u=l&&Od(l.action);if(!l||!u||(t.preventDefault(),t.stopPropagation(),t.repeat&&s))return;let d=pt(u,n.step,l.steps??1,n.snap),f=Zb(r,c,d,i);f.skipped.length>0&&n.actions.notify(`Not moved: ${f.skipped.join(`; `)}`),f.edits.length>0&&a({edits:f.edits,summary:`Move ${H(c)} by (${d.x}, ${d.y})`,shapes:f.shapes})};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function cF(e,t,n,r){let{camera:i,selection:a}=e;if(!i||r.button!==0||e.armed===`note`||e.armed===`zoom`)return;let o=uu(t,n,i.scale,e.layers,{selection:a,armed:e.armed,filter:e.filter});if(!o)return lF(e,n,r);if(yo(r))return e.onSelect(e=>e.toggleCopper(o.id)),`toggled`;if(a.hasCopper(o.id)&&a.total>1)return QP({id:o.id,names:a.names,copper:a.copper,start:n});let s=a.soleCopper===o.id,c=t.tracks.find(e=>e.id===o.id)?.width??0,l=YP(o,t,{world:n,point:n,scale:i.scale,sole:s,width:c}),u=l&&XP(l,a.segment);return u?.segment===void 0&&e.onSelect(e=>e.onlyCopper(o.id)),u??`toggled`}function lF(e,t,n){let{selection:r,parts:i}=e;if(r.copper.length===0||yo(n))return;let a=i.selectedAt(t);if(a!==void 0&&i.blockerFor(a)===null)return QP({part:a,names:r.names,copper:r.copper,start:t,origin:i.originOf(a)})}function uF(e,t,n){let r=ex(t.tracks.find(e=>e.id===n.id),n);if(`message`in r)return e.actions.notify(`Not removed: ${r.message}`);e.actions.editLayout(r.edits,r.summary).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper([n.id])))}function dF(e,t,n){let{segment:r}=e.selection;if(r&&n.length===1&&n[0]===r.id)return uF(e,t,r);let{edits:i,removed:a,skipped:o}=$b(t,n);o.length>0&&e.actions.notify(`Not removed: ${o.join(`; `)}`),i.length!==0&&e.actions.editLayout(i,`Remove ${H(a)}`).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper(a)))}function fF(e){let{design:t,builtMark:n,actions:r,selection:i}=e,a=aF(n,r),o=(0,_.useMemo)(()=>nx(t.pcb,a.shapes),[t,a.shapes]),s=(0,_.useMemo)(()=>oF(t),[t]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(),f=(0,_.useRef)(void 0),p=e=>{f.current=e,l(e)},m={input:e,shown:o,onPad:s,send:a.send,sendParts:a.sendParts,cancel:()=>f.current?(p(void 0),!0):!1,inFlight:a.inFlight},h=(0,_.useRef)(m);h.current=m,sF(h),pF(o.tracks,i,e.onSelect);let g=(0,_.useMemo)(()=>c?nx(o,nF(c,o,s)):o,[c,o,s]);return{scene:{tracks:g.tracks,vias:g.vias,selected:new Set(i.copper),...i.segment?{segment:i.segment}:{},...u===void 0?{}:{hover:u}},shown:o,drag:c,hover:u,setHover:d,put:p,dragRef:f,latest:h,keys:(0,_.useMemo)(()=>({remove:e=>dF(h.current.input,h.current.shown,e)}),[]),moving:(0,_.useMemo)(()=>mF(c,e.parts)??a.moving,[c,e.parts,a.moving])}}function pF(e,t,n){let r=vo(t,e)!==t;(0,_.useEffect)(()=>{r&&n(t=>vo(t,e))},[r,e,n])}function mF(e,t){let n=e&&rF(e);return n&&{names:n.names.filter(e=>t.blockerFor(e)===null),offset:n.offset}}function hF(e,t){let{input:n,shown:r}=e.latest.current,i=n.camera&&uu(r,t,n.camera.scale,n.layers,{selection:_o.none,armed:n.armed,filter:n.filter});return i?i.id:void 0}function gF(e,t){let{input:n,shown:r}=e.latest.current;return n.camera&&du(r,t,n.camera.scale,n.layers,{selection:n.selection,armed:n.armed,filter:n.filter})}function _F(e,t){let n=hF(e,t);return e.setHover(n),n!==void 0}function vF(e){return(t,n)=>{let{input:r,shown:i}=e.latest.current,a=cF(r,i,n,t);return a&&a!==`toggled`&&e.put(a),a!==void 0}}function yF(e,t,n){let{input:r}=e.latest.current,i={x:n.x-t.start.x,y:n.y-t.start.y};!t.moved&&Math.hypot(i.x,i.y)*(r.camera?.scale??1)<3||e.put(eF(t,i,{step:r.step,snap:r.snap},e=>r.actions.notify(e)))}function bF(e,t){e.put(void 0);let{input:n,shown:r,onPad:i,send:a,sendParts:o}=e.latest.current;if(t.kind===`group`&&!t.moved)return n.onSelect(xF(t));let s=ZP(t);s&&n.onSelect(s);let c=rF(t);c&&o(c,n.parts.move(c.names,c.offset));let l=iF(t,r,i);l&&(`message`in l?n.actions.notify(l.message):a(l))}function xF(e){return t=>e.part===void 0?e.id?t.onlyCopper(e.id):t:t.only(e.part)}function SF(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?be(n.camera,n.size,TO(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);le.refuses()||yF(e,a,o)},onPointerUp:n=>{let r=e.dragRef.current;r?bF(e,r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function CF(e){return e.drag?e.drag.blocker?`not-allowed`:`move`:e.hover===void 0?void 0:`pointer`}var wF={phase:`idle`};function TF(e,t,n,r){return e.phase===`shown`&&r?{...e,at:t}:e.phase===`dismissed`&&r?e:{phase:`waiting`,at:t,since:n}}function EF(e,t){switch(t.kind){case`move`:return TF(e,t.at,t.now,t.still);case`tick`:return e.phase!==`waiting`||t.now-e.since<250?e:t.target?{phase:`shown`,target:t.target,at:e.at}:wF;case`key`:case`press`:return e.phase===`shown`||e.phase===`dismissed`?{phase:`dismissed`,target:e.target}:wF;case`leave`:case`stale`:case`busy`:return wF}}function DF(e,t){return e.phase===`waiting`?Math.max(0,e.since+250-t):void 0}var OF=e=>e.phase===`shown`||e.phase===`dismissed`;function kF(e){if(e.phase===`shown`)return{text:e.target.text,left:e.at.x+12,top:e.at.y+12}}function AF(e,t,n){let r=(e,t,n)=>e+t>n?Math.max(0,e-24-t):e;return{left:r(e.left,t.width,n.width),top:r(e.top,t.height,n.height)}}var jF=1;function MF(e,t,n){let r=wF,i,a,o=!1,s=!1,c=()=>{a!==void 0&&e.clearTimer(a),a=void 0},l=()=>{c();let t=DF(r,e.now());t!==void 0&&(a=e.setTimer(d,t+jF))},u=e=>{let n=EF(r,e);n!==r&&(r=n,t(r)),l()};function d(){a=void 0,u({kind:`tick`,now:e.now(),target:i&&n()?.pick(i)})}let f=e.listenKeys(()=>u({kind:`key`}));return{move(t,a){if(o||s)return;i=t;let c=n(),l=OF(r)&&c!==void 0&&c.still(r.target,t);u({kind:`move`,at:a,now:e.now(),still:l})},leave:()=>u({kind:`leave`}),press:()=>u({kind:`press`}),stale:()=>u({kind:`stale`}),quiet(e){o=e,e&&u({kind:`busy`})},over(e){!e&&!s&&u({kind:`leave`}),s=!e},dispose(){c(),f()}}}function NF(e,t,n){let{onPointerDown:r,onPointerMove:i}=e,a=(...e)=>{t.press(),r(...e)},o=(...e)=>{let r=e[0];n&&t.over(r?.target===n.current),i(...e)};return{...e,onPointerDown:a,onPointerMove:o,onWheel:()=>t.stale()}}var PF={now:()=>performance.now(),setTimer:(e,t)=>window.setTimeout(e,t),clearTimer:e=>window.clearTimeout(e),listenKeys:e=>(window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0))};function FF({enabled:e,busy:t,probe:n,camera:r,design:i}){let[a,o]=(0,_.useState)(wF),s=(0,_.useRef)(n);s.current=n;let c=(0,_.useRef)(void 0);return(0,_.useEffect)(()=>{let e=MF(PF,o,()=>s.current);return c.current=e,()=>{e.dispose(),c.current=void 0}},[]),(0,_.useEffect)(()=>c.current?.quiet(!e||t),[e,t]),(0,_.useEffect)(()=>c.current?.stale(),[r,i]),{state:a,...(0,_.useMemo)(()=>({move:(e,t)=>c.current?.move(e,t),leave:()=>c.current?.leave(),press:()=>c.current?.press(),stale:()=>c.current?.stale(),over:e=>c.current?.over(e)}),[])}}function IF({state:e}){let t=kF(e),n=(0,_.useRef)(null);return(0,_.useLayoutEffect)(()=>{let e=n.current,r=e?.parentElement;if(!e||!r||!t)return;let i=AF(t,{width:e.offsetWidth,height:e.offsetHeight},{width:r.clientWidth,height:r.clientHeight});e.style.left=`${i.left}px`,e.style.top=`${i.top}px`}),t?(0,X.jsx)(`div`,{ref:n,className:`hover-label`,role:`tooltip`,style:{left:t.left,top:t.top},children:t.text}):null}var LF=` · `;function RF(e,t){if(t===void 0)return`no net`;let n=e.circuit.nets.find(e=>e.id===t);return n?n.names[0]??t:t.startsWith(`net.`)?t.slice(4):t}var zF=e=>`${Number(e.toFixed(4))} mm`,BF=(e,t)=>e.circuit.components.find(e=>e.id===t);function VF(e,t){let n=BF(e,t.component),r=n?.pins.find(e=>e.id===t.pin),i=r&&In(n?.props??{},r.number),a=n?.instance===void 0?``:` [${n.instance}]`;return`${t.component}.${t.number}${i?` ${i}`:``}${LF}${RF(e,t.net)}${a}`}var HF=(e,t)=>`via ${t.id}${LF}${RF(e,t.net)}${LF}${t.layers[0]}–${t.layers.at(-1)}`;function UF(e,t){return`track ${t.id}${LF}${RF(e,t.net)}${LF}${zF(t.width)}${LF}${t.layer}${t.by===`router`?`${LF}routed`:``}`}var WF=new Set;function GF(e,t){let{design:n,scale:r,layers:i,context:a}=t;if(!Va({kind:`pour`,id:``},a))return;let o=n.pcb.holes?.find(t=>t.id===Uu(n.pcb.holes??[],e,r,i.visible));return o?{kind:`hole`,id:o.id,text:Ru(o)}:KF(n,Vu(n,e,r,i.visible,t.pours?.hidden??WF))}function KF(e,t){let n=t===void 0?void 0:Nu(e).find(e=>e.id===t);return n&&{kind:`pour`,id:n.id,text:Iu(e,n)}}function qF(e,t){let{design:n,layers:r,context:i}=t;if(n.pcb.pours&&Va({kind:`pour`,id:``},i))return KF(n,Ku(n,e,r.visible,t.pours?.hidden??WF,t.pours?.activeLayer))}function JF(e,t){let{design:n,copper:r,scale:i,layers:a,context:o}=t;if(yA(t.boxes,e,o,t.texts))return;let s=uu(r,e,i,a.visible,o),c=s?.kind===`via`?r.vias.find(e=>e.id===s.id):void 0;if(c)return{kind:`via`,id:c.id,text:HF(n,c)};let l=s?.kind===`track`?r.tracks.find(e=>e.id===s.id):void 0;if(l)return{kind:`track`,id:l.id,text:UF(n,l)};let u=GF(e,t);if(u)return u;let d=Xf(n.pcb,e,a.visible,e=>Va({kind:`part`,name:e},o));return d?{kind:`pad`,id:d.id,text:VF(n,d)}:qF(e,t)}function YF(e,t){let n=e.circuit.nets.find(e=>e.id===t.net);return n?.names.includes(t.text)?t.text:n?.names[0]??t.text}var XF=(e,t)=>`${t.component}.${In(BF(e,t.component)?.props??{},t.number)??`pin${t.number}`}`;function ZF(e,t){let n=e.circuit.nets.find(e=>e.pins.includes(t.id));return`${XF(e,t)}${LF}${RF(e,n?.id)}`}function QF(e,t){for(let n of e.circuit.instances??[]){let e=n.ports.find(e=>`${n.path}.${e.name}`===t);if(e)return{kind:`port`,id:t,text:`${t}${LF}${e.bus?`bus ${e.net}`:e.net}`}}}function $F(e,t){let{design:n}=t,r=Jn(n,e,12/t.scale),i=r&&n.schematic.symbols.find(e=>r.pin in e.pinEnds);if(!r||!i||!Va({kind:`part`,name:i.component},t.context))return;let a=BF(n,i.component)?.pins.find(e=>e.id===r.pin);return a?{kind:`pin`,id:a.id,text:ZF(n,a)}:QF(n,r.pin)}function eI(e,t,n){let r=$F(t,n);if(!r)return e;let i=r.text.slice(0,r.text.indexOf(LF));return{...e,text:`${e.text}${LF}pin ${i}`,pin:r.id}}function tI(e,t){let{design:n}=t,r=vA(t.boxes,t.labels,e,t.context,t.wires,t.drawings,t.texts);if(r.kind===`label`)return eI({kind:`label`,id:r.label.id,text:YF(n,r.label)},e,t);if(r.kind===`wire`){let i=n.schematic.wires.find(e=>e.id===r.id);return eI({kind:`wire`,id:r.id,text:`wire${LF}${RF(n,i?.net)}`},e,t)}return r.kind===`drawing`?void 0:$F(e,t)}function nI(e,t){return t.view===`pcb`?JF(e,t):tI(e,t)}function rI(e,t,n){let{copper:r,scale:i}=n;if(e.kind===`via`){let n=r.vias.find(t=>t.id===e.id);return n!==void 0&&Math.hypot(t.x-n.at.x,t.y-n.at.y)<=ou(n.diameter,i)}if(e.kind===`track`){let n=r.tracks.find(t=>t.id===e.id);return n!==void 0&&Jc(n.points,t,ou(n.width,i))!==void 0}if(e.kind===`hole`)return Uu(n.design.pcb.holes??[],t,i,n.layers.visible)===e.id;if(e.kind===`pour`){let r=n.design.pcb.pours?.find(t=>t.id===e.id);return Vu(n.design,t,i,n.layers.visible,n.pours?.hidden??WF)===e.id||r!==void 0&&Gu(r,t)}let a=e.id.slice(0,e.id.indexOf(`#`)),o=n.design.pcb.parts.find(e=>e.component===a)?.pads.find(t=>t.id===e.id);return e.kind===`pad`&&o!==void 0&&xp(o,t)<=0}function iI(e,t,n){let r=12/n.scale,i=e=>{let i=n.design.schematic.symbols.find(t=>e in t.pinEnds)?.pinEnds[e];return i!==void 0&&Math.hypot(t.x-i.x,t.y-i.y)<=r},a=e.pin===void 0||i(e.pin);return e.kind===`label`?n.labels?.at(t)?.id===e.id&&a:e.kind===`wire`?n.wires?.at(t)===e.id&&a:i(e.id)}function aI(e,t,n){return n.view===`pcb`?rI(e,t,n):iI(e,t,n)}function oI({value:e,onChange:t}){let n=(0,_.useId)();return(0,X.jsxs)(`div`,{className:`hole-field`,onPointerDown:e=>e.stopPropagation(),children:[(0,X.jsx)(`label`,{htmlFor:n,children:`Hole diameter (mm)`}),(0,X.jsx)(`input`,{id:n,value:e,inputMode:`decimal`,spellCheck:!1,onChange:e=>t(e.target.value)})]})}var sI=.1,cI=e=>Math.round(e*1e4)/1e4||0,lI=(e,t)=>e.x===t.x&&e.y===t.y,uI=(e,t)=>cI(Math.hypot(t.x-e.x,t.y-e.y));function dI(e,t){return cI((Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI%360+360)%360)%360}var fI=e=>({tool:e,points:[],flip:!1,dragging:!1});function pI(e,t,n){let r=De(e,t,n);return{x:cI(r.x),y:cI(r.y)}}function mI(e,t){return e?t.time-e.time<=400&&Math.hypot(t.at.x-e.at.x,t.at.y-e.at.y)<=4:!1}function hI(e,t){return(e?.tool===`text`||e?.naming===!0)&&t===0}function gI(e,t,n){let r=e.points.at(-1);if(!r)return[t];let i=n?On([r,t],[e.flip]).slice(1):[t];return[...e.points,...i.map(e=>({x:cI(e.x),y:cI(e.y)}))].filter((e,t,n)=>t===0||!lI(e,n[t-1]))}function _I(e,t){let[n,r]=[cI(Math.abs(t.x-e.x)),cI(Math.abs(t.y-e.y))];if(n!==0&&r!==0)return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),width:n,height:r}}function vI(e,t,n){let[r,i]=[dI(e,t),dI(e,n)];if(!(lI(n,e)||r===i))return{x:e.x,y:e.y,radius:uI(e,t),startAngle:r,endAngle:i}}var yI=(e,t)=>({state:fI(e),drawing:t}),bI=e=>({state:e});function xI(e){return e.points.length<2?bI(fI(e.tool)):e.tool===`bus`?bI({...e,naming:!0}):yI(`polyline`,{tag:`schematicpath`,props:{points:[...e.points]}})}function SI(e,t){return e.naming?bI(e):t.double&&e.points.length>0?xI(e):bI({...e,points:gI(e,t.at,t.shift)})}function CI(e,t){let[n]=e.points;if(!n)return bI({...e,points:[t],dragging:!0});let r=_I(n,t);return r?yI(`rectangle`,{tag:`schematicrect`,props:r}):bI(e)}function wI(e,t){let[n]=e.points;if(!n)return bI({...e,points:[t]});let r=uI(n,t);return r>0?yI(`circle`,{tag:`schematiccircle`,props:{x:n.x,y:n.y,radius:r}}):bI(e)}function TI(e,t){let[n,r]=e.points;if(!n)return bI({...e,points:[t]});if(!r)return lI(t,n)?bI(e):bI({...e,points:[n,t]});let i=vI(n,r,t);return i?yI(`arc`,{tag:`schematicarc`,props:i}):bI(e)}function EI(e,t){switch(e.tool){case`bus`:case`polyline`:return SI(e,t);case`rectangle`:return CI(e,t.at);case`circle`:return wI(e,t.at);case`arc`:return TI(e,t.at);case`text`:return bI({...e,points:[t.at]})}}function DI(e,t){let[n]=e.points;if(e.tool!==`rectangle`||!e.dragging||!n)return bI(e);let r=_I(n,t);return r?yI(`rectangle`,{tag:`schematicrect`,props:r}):bI({...e,dragging:!1})}function OI(e,t){let n=t.trim();return!e.naming||rn(n)===void 0?bI(e):yI(`bus`,{tag:`bus`,name:n,props:{points:[...e.points]}})}function kI(e,t){if(e.tool===`bus`)return OI(e,t);let[n]=e.points,r=t.trim();return e.tool!==`text`||!n||r===``?bI(fI(e.tool)):yI(`text`,{tag:`schematictext`,props:{x:n.x,y:n.y,text:r,fontSize:sI,anchor:`left`}})}function AI(e,t){switch(t.type){case`press`:return EI(e,t);case`release`:return DI(e,t.at);case`finish`:return(e.tool===`polyline`||e.tool===`bus`)&&!e.naming?xI(e):bI(e);case`removeCorner`:return e.naming?bI(e):bI(e.points.length<=1?fI(e.tool):{...e,points:e.points.slice(0,-1)});case`flip`:return bI(e.naming?e:{...e,flip:!e.flip});case`cancel`:return{state:e.points.length>0?fI(e.tool):null};case`text`:return kI(e,t.text)}}var jI={file:``,line:0,column:0,offset:0},MI={strokeWidth:.01,lineStyle:`dashed`,groupOffset:{x:0,y:0},source:jI};function NI(e,t,n){let[r,i]=e.points;if(!r)return;let a=`drawing:preview`;if(e.tool===`bus`)return{id:a,kind:`bus`,name:``,members:[],points:e.naming?[...e.points]:gI(e,t,n),groupOffset:MI.groupOffset,source:jI};if(e.tool===`polyline`)return{id:a,kind:`path`,points:gI(e,t,n),...MI};if(e.tool===`rectangle`){let e=_I(r,t);return e&&{id:a,kind:`rect`,x:e.x??0,y:e.y??0,width:e.width??0,height:e.height??0,filled:!1,...MI}}if(e.tool===`circle`)return{id:a,kind:`circle`,x:r.x,y:r.y,radius:uI(r,t),filled:!1,...MI};if(e.tool!==`arc`)return;if(!i)return{id:a,kind:`path`,points:[r,t],...MI};let o=vI(r,i,t);return o&&{id:a,kind:`arc`,x:r.x,y:r.y,radius:o.radius??0,startAngle:o.startAngle??0,endAngle:o.endAngle??0,...MI}}function PI(e,t){let{props:n}=e,r=e=>Number(n[e]??0),i={id:t,x:r(`x`),y:r(`y`)};switch(e.tag){case`bus`:return{id:t,kind:`bus`,name:e.name??``,members:rn(e.name??``)??[],points:n.points??[],groupOffset:MI.groupOffset,source:jI};case`schematicpath`:return{id:t,kind:`path`,points:n.points??[],...MI};case`schematicrect`:return{...i,kind:`rect`,width:r(`width`),height:r(`height`),filled:!1,...MI};case`schematiccircle`:return{...i,kind:`circle`,radius:r(`radius`),filled:!1,...MI};case`schematicarc`:return{...i,kind:`arc`,radius:r(`radius`),startAngle:r(`startAngle`),endAngle:r(`endAngle`),...MI};case`schematictext`:return{...i,kind:`text`,text:String(n.text??``),fontSize:sI,anchor:`left`,groupOffset:MI.groupOffset,source:jI}}}var FI=/^G(\d+)$/;function II(e,t,n=[]){if(e.name!==void 0)return{kind:`addDrawing`,tag:e.tag,name:e.name,props:e.props};let r=Number(FI.exec(wT(t))?.[1]??1),i=Math.max(r-1,...n.map(e=>Number(FI.exec(e)?.[1]??0)));return{kind:`addDrawing`,tag:e.tag,name:`G${i+1}`,props:e.props}}var LI={bus:`bus`,polyline:`line`,rectangle:`rectangle`,circle:`circle`,arc:`arc`,text:`text`},RI=(e,t)=>`add the ${LI[e]} ${t}`,zI=`Esc or a right click stops.`,BI=`Esc cancels.`,VI={bus:`Click to start a bus, Enter to finish, then name it. ${zI}`,polyline:`Click to start a polyline, Enter to finish. ${zI}`,rectangle:`Drag, or click two opposite corners, to draw a rectangle. ${zI}`,circle:`Click the centre of a circle. ${zI}`,arc:`Click the centre of an arc. ${zI}`,text:`Click where the text goes. ${zI}`},HI=`Click for each corner, double click or Enter to finish. Shift keeps a leg square and Space flips its bend; Backspace removes a corner, ${BI}`;function UI(e){if(!e)return;let t=e.points.length;return t===0?VI[e.tool]:e.naming?`Name the bus, such as D[0:7] or CLK; Enter writes it, ${BI}`:e.tool===`polyline`||e.tool===`bus`?HI:e.tool===`rectangle`?`Click the opposite corner. ${BI}`:e.tool===`circle`?`Click to set the radius. ${BI}`:e.tool===`text`?`Type the text; Enter writes it, ${BI}`:t===1?`Click where the arc starts. Backspace steps back, ${BI}`:`Click where the arc ends. Backspace steps back, ${BI}`}var WI=e=>new Set(e.annotations.locks.map(e=>e.part));function GI(e,t){let[n,r]=(0,_.useState)(null),i=Nu(e);return(0,_.useEffect)(()=>{n!==null&&i.some(e=>e.id===n)&&(t(e=>e.clear().onlyBoard(n)),r(null))},[i,n,t]),(0,_.useCallback)(e=>r(e),[])}var KI=e=>t=>(e.notify(`Not written: ${t instanceof Error?t.message:String(t)}`),!1);function qI(e,t){let[n,r]=(0,_.useState)(null),i=(0,_.useRef)(n);return i.current=n,{state:n,send:(0,_.useCallback)(e=>{let n=i.current;if(!n)return;let a=xx(n,e);i.current=a.state,r(a.state),(a.outline||a.hole||a.refused)&&t(a)},[t]),arm:(0,_.useCallback)(t=>{e(),i.current=hx(t),r(i.current)},[e]),disarm:(0,_.useCallback)(()=>{i.current=null,r(null)},[])}}function JI(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{e.key!==`Escape`||Pd(e).typing||(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Yd(Pd(e),{view:`pcb`,drawing:!0})?.action:void 0,i=r===`finishShape`?{type:`finish`}:r===`removeCorner`?{type:`removeCorner`}:void 0;i&&(e.preventDefault(),t(i))};return window.addEventListener(`keydown`,r,!0),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`keydown`,r,!0),window.removeEventListener(`keydown`,i)}},[e,t])}function YI(e,t){let n=(0,_.useRef)(t);n.current=t,(0,_.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),n.current())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function XI(e,t){let{input:n}=e,r=Cx(n.design);if(r===void 0)return n.actions.notify(`The circuit has no net for a copper pour yet.`);let i=fx(n.circuit.model.boardItems??[],`copperpour`);n.actions.edit([wx(r,n.activeLayer,t)],Tx(r,n.activeLayer,t===void 0)).catch(KI(n.actions)).then(t=>t&&e.waitForPour(i))}function ZI(e,t){let n=Ox(e.diameter);if(typeof n!=`number`)return e.input.actions.notify(n.message);e.input.actions.edit([Ex(t,n)],Dx(n)).catch(KI(e.input.actions))}function QI(e,t,n){let{input:r}=e,{camera:i,design:a,selection:o}=r;if(!i||t.button!==0||r.armed===`note`||r.armed===`zoom`||!Va({kind:`pour`,id:``},{selection:o,armed:r.armed,filter:r.filter}))return!1;let s=Uu(a.pcb.holes,n,i.scale,r.layers)??Vu(a,n,i.scale,r.layers,r.hidden);return s!==void 0&&(r.onSelect(e=>yo(t)?e.toggleBoard(s):e.onlyBoard(s)),!0)}function $I(e,t,n,r){let{input:i}=e,a=i.selection.soleBoard,o=a===void 0?void 0:Nu(i.design).find(e=>e.id===a);if(!o?.outline||!i.camera||t.button!==0||yo(t))return!1;let s=Hu(o.outline,n,i.camera.scale);if(s===void 0)return!1;let c=Ax(i.circuit.model,WI(i.circuit),o.id);return c?(i.actions.notify(`Not moved: ${c}`),!0):(r({id:o.id,index:s,outline:o.outline,start:n,to:o.outline[s],moved:!1}),!0)}var eL=e=>e.outline.map((t,n)=>n===e.index?e.to:t);function tL(e){let{design:t,circuit:n,onSelect:r}=e,[i,a]=(0,_.useState)(String(px)),o=GI(t,r),[s,c]=(0,_.useState)(),l=(0,_.useRef)(void 0),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)();(0,_.useEffect)(()=>p(void 0),[t]);let m=e=>{l.current=e,c(e)},h={input:e,diameter:i,drag:s,waitForPour:o},g=(0,_.useRef)(h);g.current=h;let v=(0,_.useCallback)(e=>{e.refused&&g.current.input.actions.notify(e.refused),e.outline&&XI(g.current,e.outline),e.hole&&ZI(g.current,e.hole)},[]),y=qI(e.onArm,v);JI(y.state,y.send);let{disarm:b}=y;(0,_.useEffect)(()=>{e.othersArmed&&b()},[e.othersArmed,b]),YI(s!==void 0,()=>m(void 0)),TS({placePour:()=>y.arm(`pour`),placeHole:()=>y.arm(`hole`),placePourBoard:()=>XI(g.current,void 0)});let x=(0,_.useRef)(void 0),S=t=>De(t,e.step,e.snap),C=(t,n)=>{if(!y.state||!e.camera||t.button===1)return!1;if(t.button===2)return y.send({type:`cancel`}),!0;let r={at:{x:n.x*e.camera.scale,y:n.y*e.camera.scale},time:Date.now()},i=mI(x.current,r);return x.current=i?void 0:r,y.send({type:`press`,at:S(n),double:i}),!0},w=(0,_.useMemo)(()=>{let e=new Map;return f&&e.set(f.id,f.outline),s?.moved&&e.set(s.id,eL(s)),e},[f,s]),T=Sx(y.state,e.cursor&&S(e.cursor)),E={mode:e.mode,hidden:e.hidden,selected:new Set(e.selection.board),...u===void 0?{}:{hover:u},activeLayer:e.activeLayer,outlines:w,...T.length>0?{preview:T}:{}},ee=(0,_.useMemo)(()=>Nx(n.model,WI(n)),[n]);return{state:y.state,armed:y.state!==null,busy:y.state!==null&&y.state.points.length>0,disarm:y.disarm,hint:Fx(y.state),diameter:i,setDiameter:a,toolPress:C,cornerPress:(e,t)=>$I(g.current,e,t,m),pickPress:(e,t)=>QI(g.current,e,t),hoverAt:n=>{let{camera:r}=e,i={selection:e.selection,armed:e.armed,filter:e.filter},a=r&&Va({kind:`pour`,id:``},i)?Uu(t.pcb.holes,n,r.scale,e.layers)??Vu(t,n,r.scale,e.layers,e.hidden):void 0;return d(a),a!==void 0},clearHover:()=>d(void 0),hover:u,drag:s,dragRef:l,put:m,release:t=>{if(m(void 0),!t.moved)return;let n=kx(t.id,t.outline,t.index,t.to);if(`message`in n)return e.actions.notify(n.message);p({id:t.id,outline:eL(t)}),e.actions.edit([n.edit],n.summary).catch(KI(e.actions)).then(e=>e||p(void 0))},latest:g,scene:E,removal:ee,cursor:s?`move`:y.state?`crosshair`:u===void 0?void 0:`pointer`}}function nL(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?be(n.camera,n.size,TO(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);let{input:s}=e.latest.current,c=Math.hypot(o.x-a.start.x,o.y-a.start.y)*(s.camera?.scale??1)>=3;(a.moved||c)&&(le.refuses()||e.put({...a,moved:!0,to:De(o,s.step,s.snap)}))},onPointerUp:n=>{let r=e.dragRef.current;r?e.release(r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function rL(e){return(t,n)=>e.pourTool(t,n)||e.route(t,n)||e.pourCorner(t,n)||!e.text(n)&&(e.copper(t,n)||e.pour(t,n))}var iL=W.background;function aL(e,t){let n=e.circuit.nets.find(e=>e.id===t.net)?.names[0];return`${uj(e,t)}${n?` on ${n}`:``}`}function oL(e,t,n){(0,_.useEffect)(()=>{$y({active:e,stop:()=>{t(),n()}})},[e,t,n]),(0,_.useEffect)(()=>tb,[])}function sL(e,t){let{design:n,camera:r,size:i,layers:a,hoverPad:o,moving:s,boxes:c,hover:l,selection:u,locked:d,circuit:f,gesture:p,highlightNets:m,markers:h,activeViolation:g,grid:v,copper:y,texts:b,pours:x}=t,S=(0,_.useMemo)(()=>Of(n.pcb,b.moves),[n.pcb,b.moves]),C=(0,_.useMemo)(()=>m.length>0?m:o?.net?[o.net]:Ep,[m,o]);(0,_.useEffect)(()=>{if(!r)return;let t=kO(e.current,i,r,iL,(e,t,n,r)=>QD(e,t,n,v,r));if(!t)return;let{ctx:n,ratio:o}=t;Yf(n,S,{camera:r,size:i},{ratio:o,layers:a,...C.length>0?{highlight:{nets:C}}:{},...s?{moving:{components:s.names,by:s.offset}}:{},violations:h,...g?{activeViolation:g}:{},copper:y,pours:x}),n.setTransform(o,0,0,o,0,0),AO(n,r,i,{view:`pcb`,boxes:c,moving:s,hover:l,selection:u,locked:d,marks:f.annotations.marks,gesture:p,look:$D,ratio:o}),lO(n,{camera:r,size:i},b.shown,{selected:u.texts,hover:p?void 0:b.hover},$D,o)},[e,S,r,i,a,C,s,c,l,u,d,f,p,h,g,v,y,b,x])}function cL({unit:e,step:t,setStep:n,keep:r}){return(0,X.jsxs)(ub,{children:[(0,X.jsx)(RO,{step:t,options:fg(`pcb`,e),onChange:n}),(0,X.jsx)(zO,{...r,title:`Write the faded parts' positions into the code as pcbX and pcbY`})]})}function lL(e,t,n,r,i){let[a,o]=(0,_.useState)(),[s,c]=(0,_.useState)(),[l,u]=(0,_.useState)();return{part:a,text:s,pad:l,at:a=>{let s={selection:_o.none,armed:null,layers:n,filter:r},l=vA(t,void 0,a,s,void 0,void 0,i);o(l.kind===`part`?l.name:void 0),c(l.kind===`text`?l.id:void 0),u(Xf(e.pcb,a,n.visible,e=>Va({kind:`part`,name:e},s)))},leave:()=>{o(void 0),c(void 0),u(void 0)}}}function uL(e,t,n,r){let i=(0,_.useRef)(void 0);i.current=t;let a=(0,_.useCallback)(()=>i.current?Np(e.pcb,i.current,n):void 0,[e,n]),o=(0,_.useCallback)(t=>Op(e,t),[e]);return qP({...r,netUnderPointer:a,netsOf:o})}function dL({canvasRef:e,size:t,cursorStyle:n,pointer:r,onLeave:i,hint:a}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`canvas`,{ref:e,style:{width:t.width,height:t.height,cursor:n},...r,onPointerLeave:i,onContextMenu:e=>e.preventDefault(),"aria-label":`PCB layout. Drag parts to move them, drag the background to select, drag with the right button to pan, scroll to zoom.`,role:`img`}),a&&(0,X.jsx)(`div`,{className:`canvas-top`,children:(0,X.jsx)(`div`,{className:`canvas-hint`,children:a})})]})}function fL({parts:e,circuit:t,actions:n,selection:r,armed:i,pick:a,pickFilter:o}){return(0,_.useMemo)(()=>({selectedAt:t=>{let n=vA(e.boxes,void 0,t,{selection:r,armed:i,layers:a,filter:o});return n.kind===`part`&&r.has(n.name)?n.name:void 0},originOf:t=>e.anchors.get(t)?.origin??e.boxes.find(e=>e.name===t)?.center??{x:0,y:0},blockerFor:e.blockerFor,move:(r,i)=>wt(dt(t,r,`pcb`,ft(e.anchors,e.boxes),i,e.blockerFor),n)}),[e,t,n,r,i,a,o])}function pL(e,t){return(0,_.useMemo)(()=>ke(e.pcb.board?.outline??[])??Ae(t.map(e=>e.box)),[e,t])}function mL({copper:e,pours:t,track:n,hover:r,boxes:i,context:a,texts:o,camera:s,size:c,canvasRef:l,gestures:u,setCursor:d,onOpenProperties:f,onSelect:p,label:m}){let h=e=>yA(i,e,a,o),g=r=>{if(n.armed||t.armed)return;let o=h(r)?void 0:gF(e,r);if(o)return p(e=>e.onlySegment(o));if(!h(r)&&hF(e,r)!==void 0)return;let s=vA(i,void 0,r,a);s.kind===`part`&&f(s)},_=n=>{if(WC(`pcb`,n),m.at(n),h(n))return e.setHover(void 0),t.clearHover(),r.at(n);if(_F(e,n))return t.clearHover(),r.leave();r.at(n),t.hoverAt(n)},v=vF(e);return{pointer:NF(nL(t,SF(e,$A({camera:s,size:c,element:l,gestures:u,setCursor:d,hover:_,open:g,tool:rL({pourTool:t.toolPress,route:n.press,pourCorner:t.cornerPress,text:h,copper:v,pour:t.pickPress})}),d),d),m),onLeave:()=>{m.leave(),r.leave(),e.setHover(void 0),t.clearHover(),d(void 0)}}}function hL(e){let{design:t,builtFrom:n,builtMark:r,buildStatus:i,circuit:a,actions:o,selection:s,onSelect:c,highlight:l,onHighlight:u,unit:d,onToggleUnit:f,gridStyle:p,gridStep:m,snap:h,onGridStep:g,markers:v,activeViolation:y,focus:b,onFocused:x,layers:S,pickFilter:C}=e,w=(0,_.useRef)(null),T=(0,_.useRef)(null),E=wO(w),[ee,D]=(0,_.useState)(),O=(0,_.useMemo)(()=>({step:m,style:p}),[m,p]),k=(0,_.useMemo)(()=>Ia(t.pcb.parts,S),[t,S]),A=xO(t,`pcb`,a),{camera:j,setCamera:te,fit:ne}=EO(w,E,pL(t,A.boxes));DO(`pcb`,b,j,te,x),ej({selection:s,boxes:A.boxes,size:E,setCamera:te,notify:o.notify});let re={view:`pcb`,circuit:a,actions:o,onSelect:c,blockerFor:A.blockerFor},M=jM(),N=(0,_.useRef)(()=>void 0),P=sj((0,_.useCallback)(()=>{M.disarm(),N.current()},[M])),ie=(0,_.useCallback)(()=>{P.disarm(),M.disarm()},[P,M]),F=tL({design:t,circuit:a,actions:o,camera:j,size:E,canvas:T,cursor:ee,layers:S,hidden:e.hiddenPours,filter:C,armed:P.tool,othersArmed:P.armed||M.armed!==null,selection:s,onSelect:c,step:m,snap:h,activeLayer:e.activeLayer,mode:e.pourFill,onArm:ie});N.current=F.disarm;let I=fF({design:t,builtMark:r,parts:fL({parts:A,circuit:a,actions:o,selection:s,armed:P.tool,pick:k,pickFilter:C}),camera:j,size:E,canvas:T,layers:S,filter:C,armed:P.tool,selection:s,onSelect:c,actions:o,step:m,snap:h,routing:M.route!==null}),L=(0,_.useMemo)(()=>mu(I.shown,S),[I.shown,S]);rP({design:t,builtMark:r,selection:s,lockedParts:A.locked,routing:M.route!==null,send:e=>I.latest.current.send(e),busy:()=>I.latest.current.inFlight,notify:o.notify});let R=GM({design:t,builtMark:r,copper:I.shown,camera:j,cursor:ee,step:m,snap:h,layers:S,activeLayer:e.activeLayer,onActiveLayer:e.onActiveLayer,locked:A.locked,actions:o,arm:M,onArm:P.disarm});oL(R.command??aj(P.which),P.disarm,M.disarm);let ae=(0,_.useCallback)(e=>{let n=t.pcb.parts.find(t=>t.component===e);return n!==void 0&&S[n.side===`top`?`topSilk`:`bottomSilk`]},[t,S]),oe=ck({view:`pcb`,design:t,circuit:a,actions:o,locked:A.locked,builtFrom:n,drawn:ae}),se=ZA({...re,camera:j,setCamera:te,size:E,boxes:A.boxes,anchors:A.anchors,step:m,snap:h,builtFrom:n,selection:s,tool:{armed:P.tool,disarm:P.disarm},layers:k,copper:L,copperAt:e=>hF(I,e),texts:oe.tools,filter:C,onContextMenu:R.armed?R.cancel:e.onContextMenu}),ce=SO(A,m,h),le=(0,_.useMemo)(()=>fO(s.copper,s.total,I.shown),[s,I.shown]),ue=CO(T,s.primary,A.boxes,j,E,void 0,le),{rotateHeld:de}=uL(t,ee,S,{...re,paused:R.routing||F.busy,board:F.removal,selection:s,layout:ce,builtMark:r,buildStatus:i,moveWaiting:se.pending!==void 0,fit:ne,onHighlight:u,menuPlace:ue,onContextMenu:e.onContextMenu,copper:I.keys,texts:oe}),fe=lL(t,A.boxes,k,C,oe.tools),{gesture:pe}=se,me=lk(oe,pe),z=(0,_.useMemo)(()=>({...me,hover:fe.text}),[me,fe.text]),he=I.moving?{names:I.moving.names,offset:I.moving.offset}:se.moving,ge={...I.scene,activeLayer:e.activeLayer,routes:R.routes};sL(T,{design:t,camera:j,size:E,layers:S,hoverPad:fe.pad,moving:he,boxes:A.boxes,hover:fe.part,selection:s,locked:A.locked,circuit:a,gesture:pe,highlightNets:l,markers:v,activeViolation:y,grid:O,copper:ge,texts:z,pours:F.scene});let _e={selection:s,armed:P.tool,layers:k,filter:C},ve=j&&{view:`pcb`,design:t,copper:I.shown,scale:j.scale,layers:k,context:_e,boxes:A.boxes,texts:oe.tools,pours:{hidden:e.hiddenPours,activeLayer:e.activeLayer}},ye=ve&&{pick:e=>nI(e,ve),still:(e,t)=>aI(e,t,ve)},be=FF({enabled:e.hoverLabels,busy:R.routing,probe:ye,camera:j,design:t}),xe={...be,at:e=>j&&be.move(e,B(j,E,e))},{pointer:Se,onLeave:Ce}=mL({copper:I,pours:F,track:R,hover:fe,boxes:A.boxes,context:_e,texts:oe.tools,camera:j,size:E,canvasRef:T,gestures:se,setCursor:D,onOpenProperties:e.onOpenProperties,onSelect:c,label:xe}),we=R.armed?`crosshair`:F.cursor??CF(I)??QA(pe,P.armed,fe.part!==void 0||fe.text!==void 0);return(0,X.jsxs)(`div`,{className:`pcb-canvas`,ref:w,children:[(0,X.jsx)(dL,{canvasRef:T,size:E,cursorStyle:we,pointer:Se,onLeave:Ce,hint:P.hint??F.hint??R.hint}),F.state?.tool===`hole`&&(0,X.jsx)(oI,{value:F.diameter,onChange:F.setDiameter}),(0,X.jsx)(IF,{state:be.state}),(0,X.jsx)(cL,{unit:d,step:m,setStep:g,keep:{show:A.autoPlaced,onKeep:()=>Ye(t,`pcb`,A.blockerFor,o,a)}}),(0,X.jsx)(BO,{cursor:ee,zoom:j?.scale,unit:d,onToggleUnit:f,detail:R.status??(fe.pad&&aL(t,fe.pad)),gesture:pe,rotateHeld:de,snap:h})]})}function gL(e){if(e.tool)return`Click a pin to place ${e.tool===`gnd`?`GND`:e.tool===`vcc`?e.typed||`VCC`:e.typed||`a net label`}.${e.tool===`gnd`?``:` Tab changes the name.`} Esc or a right click stops.`}function _L({palette:e,camera:t,size:n}){let{editing:r}=e;if(!r||!t)return null;let i=B(t,n,r.at);return(0,X.jsx)(vL,{at:i,initial:r.initial,palette:e},`${r.pin??r.rename?.id??`tab`}:${r.at.x}:${r.at.y}`)}function vL({at:e,initial:t,palette:n}){let[r,i]=(0,_.useState)(t),[a,o]=(0,_.useState)();return(0,X.jsxs)(`form`,{className:`label-name`,style:{left:e.x+12,top:e.y+12},onPointerDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),o(n.submitName(r))},children:[(0,X.jsx)(`input`,{autoFocus:!0,"aria-label":`Net name`,placeholder:`Net name`,value:r,onFocus:e=>e.currentTarget.select(),onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Tab`&&e.preventDefault(),e.key===`Escape`&&(e.stopPropagation(),n.cancelName())}}),a&&(0,X.jsx)(`span`,{role:`alert`,children:a})]})}function yL(e){let t=e.gridFifth?{fifth:e.gridFifth}:{};return{lines:{minor:e.grid,...t},dots:{minor:e.gridDot,...t,px:2}}}function bL(e,t,n,r,i,a=Po()){Eg(e,t,n,r,yL(a),i)}var xL=.12,SL=.09,CL=.14,wL=.06,TL=2,EL=[[`label`,SL],[`value`,CL]];function DL(e,t){return rs(`detail`,as(e,t),is(xL,e,t))}function OL(e,t,n,r,i,a=1){let o=B(t,n,{x:r.minX,y:r.minY}),s=B(t,n,{x:r.maxX,y:r.maxY});e.lineWidth=a/i;let c=es(o,s,i,a);e.strokeRect(c.x,c.y,c.width,c.height)}function kL(e,t,n,r,i,a){let o=B(t,n,r),s=B(t,n,i),c=o.x===s.x,l=e=>c?{x:qo(e.x,a),y:e.y}:{x:e.x,y:qo(e.y,a)},[u,d]=[l(o),l(s)];e.moveTo(u.x,u.y),e.lineTo(d.x,d.y)}function AL(e,t,n,r){let i=is(n,t.scale,r);return rs(`detail`,as(t.scale,r),i)?(e.font=Sa(xa.regular,i/r),!0):!1}function jL(e,t,n,r,i,a,o){if(!i)return;let s=o===void 0?i:xs(i,o*t.scale,t=>e.measureText(t).width);if(s===null)return;let c=ss(B(t,n,r),a);e.fillText(s,c.x,c.y)}function ML(e,t,n,r,i){let{sheet:a,dividers:{xs:o,ys:s}}=r;e.lineWidth=Ko(i),e.beginPath();for(let r of o)kL(e,t,n,{x:r,y:a.outer.minY},{x:r,y:a.inner.minY},i),kL(e,t,n,{x:r,y:a.inner.maxY},{x:r,y:a.outer.maxY},i);for(let r of s)kL(e,t,n,{x:a.outer.minX,y:r},{x:a.inner.minX,y:r},i),kL(e,t,n,{x:a.inner.maxX,y:r},{x:a.outer.maxX,y:r},i);if(e.stroke(),DL(t.scale,i)&&AL(e,t,.12,i)){e.fillStyle=Po().titleText,e.textBaseline=`middle`,e.textAlign=`center`;for(let a of r.labels)jL(e,t,n,a,a.text,i)}}function NL(e,t,n,r,i){let a=r.block;OL(e,t,n,a.box,i);for(let r of a.cells)OL(e,t,n,r.box,i);e.fillStyle=Po().titleText,e.textBaseline=`middle`,e.textAlign=`left`;for(let[r,o]of EL)if(AL(e,t,o,i))for(let o of a.cells)o.kind===r&&jL(e,t,n,{x:o.box.minX+wL,y:(o.box.minY+o.box.maxY)/2},o.text,i,o.box.maxX-o.box.minX-2*wL)}function PL(e,t,n,r,i){let{sheet:a}=r;e.save(),cs(e),e.strokeStyle=Po().border,OL(e,t,n,a.outer,i,Qo(TL,i)),OL(e,t,n,a.inner,i),ML(e,t,n,r,i),NL(e,t,n,r,i),e.restore()}var FL=[{name:`A4`,width:11.69,height:8.27,zonesX:6,zonesY:4},{name:`A3`,width:16.54,height:11.69,zonesX:8,zonesY:6},{name:`A2`,width:23.39,height:16.54,zonesX:12,zonesY:8},{name:`A1`,width:33.11,height:23.39,zonesX:16,zonesY:12},{name:`A0`,width:46.81,height:33.11,zonesX:24,zonesY:16}],IL=.2,LL=1.2,RL=.8,zL=10,BL=1e-6;function VL(e){return Math.round(e*zL)/zL}function HL(e,t){let n=t??{minX:0,minY:0,maxX:0,maxY:0},r=VL((n.minX+n.maxX)/2-e.width/2),i=VL((n.minY+n.maxY)/2-e.height/2),a={minX:r,minY:i,maxX:r+e.width,maxY:i+e.height};return{size:e,outer:a,inner:{minX:a.minX+IL,minY:a.minY+IL,maxX:a.maxX-IL,maxY:a.maxY-IL},empty:t===void 0}}function UL(e){let{inner:t}=e;return{minX:t.maxX-4,minY:t.minY,maxX:t.maxX,maxY:t.minY+LL}}var WL=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function GL(e,t){let{outer:n}=e;return t.minX-.5>=n.minX-BL&&t.minY-.5>=n.minY-BL&&t.maxX+.5<=n.maxX+BL&&t.maxY+.5<=n.maxY+BL&&!WL(t,UL(e))}function KL(e,t){let n=Math.max(0,t?FL.indexOf(t):0),r=FL.slice(n);if(!e)return HL(r[0],void 0);let i=r.map(t=>HL(t,e));return i.find(t=>GL(t,e))??i[i.length-1]}function qL(e,t){return t?e&&!e.empty&&GL(e,t)?e:KL(t,e&&!e.empty?e.size:void 0):e??KL(void 0)}function JL(e,t){return(e?.empty??!1)&&!t.empty}function YL(e){let{size:t,inner:n,outer:r}=e,i=[],a=(n.maxX-n.minX)/t.zonesX,o=(n.maxY-n.minY)/t.zonesY;for(let e=0;e<t.zonesX;e++){let t=n.minX+(e+.5)*a;i.push({text:String(e+1),x:t,y:(r.maxY+n.maxY)/2},{text:String(e+1),x:t,y:(r.minY+n.minY)/2})}for(let e=0;e<t.zonesY;e++){let t=n.maxY-(e+.5)*o,a=String.fromCharCode(65+e);i.push({text:a,x:(r.minX+n.minX)/2,y:t},{text:a,x:(r.maxX+n.maxX)/2,y:t})}return i}function XL(e){let{size:t,inner:n}=e,r=(e,t,n)=>Array.from({length:n-1},(r,i)=>e+(i+1)*(t-e)/n);return{xs:r(n.minX,n.maxX,t.zonesX),ys:r(n.minY,n.maxY,t.zonesY)}}var ZL=[[`Project`,`project`],[`Page`,`page`],[`File`,`file`],[`Date`,`date`],[`Rev`,`rev`]];function QL(e,t){let n=UL(e),r=LL/ZL.length,i=n.minX+RL;return{box:n,cells:ZL.flatMap(([e,a],o)=>{let s=n.maxY-o*r,c=s-r;return[{box:{minX:n.minX,minY:c,maxX:i,maxY:s},text:e,kind:`label`},{box:{minX:i,minY:c,maxX:n.maxX,maxY:s},text:t[a],kind:`value`}]})}}function $L(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function eR(e,t){return{sheet:e,dividers:XL(e),labels:YL(e),block:QL(e,t)}}function tR({design:e,circuit:t,actions:n,builtFrom:r}){let[i,a]=(0,_.useState)([]);(0,_.useEffect)(()=>a(e=>e.every(e=>e.sentAt>r)?e:e.filter(e=>e.sentAt>r)),[r]);let o=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return{tools:{boxes:(0,_.useMemo)(()=>e.schematic.labels.map(e=>({id:e.id,box:Er(e)})),[e.schematic.labels]),at:t=>Ar(e,t),blocker:n=>Wr(e,t,n,o),commit:(r,i)=>{let s=Kr(e,t,r.id,i,o);if(!Array.isArray(s))return n.notify(s.blocked);let c=Vr(e,r.id,i);if(s.length===0||!c)return;let l={id:r.id,...c,sentAt:Date.now()};a(e=>[...e.filter(e=>e.id!==r.id),l]),n.edit(s,`Move ${r.text} label`).then(e=>e||a(e=>e.filter(e=>e!==l)))}},pending:(0,_.useMemo)(()=>i.filter(e=>e.sentAt>r),[i,r])}}function nR(e,t){return(0,_.useMemo)(()=>{let n=t&&Vr(e,t.id,t.at);return t&&n?{id:t.id,...n}:void 0},[e,t])}function rR(e){let t=(0,_.useRef)(iT(e));t.current.set(e),(0,_.useEffect)(()=>rT.answer(e=>t.current.call(e)),[])}var iR=.5,aR=.1,oR=/^[A-Za-z_][A-Za-z0-9_]*$/,sR=`Use letters, digits and _, starting with a letter or _`,cR=[`right`,`top`,`left`,`bottom`],lR={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},uR=e=>Math.round(e*1e3)/1e3||0,dR=e=>uR(Math.round(e/aR)*aR);function fR(e,t){if(e===`gnd`)return`GND`;let n=t.trim();return e===`vcc`&&n===``?`VCC`:n}function pR(e,t){let n=e.schematic.symbols.find(e=>e.pinEnds[t.id]),r=n?.pinEnds[t.id],i=n?.symbol.pins.find(e=>e.number===t.number)?.side;if(!n||!r||!i)return;let a=Math.round((n.rotation%360+360)%360/90)%4,o=cR[(cR.indexOf(i)+a)%4]??i,s=lR[o];return{end:r,side:o,corner:{x:dR(r.x+s.x*iR),y:dR(r.y+s.y*iR)}}}var mR=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t),hR=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t));function gR(e){return e===``?`Name the net label`:oR.test(e)?void 0:sR}function _R(e,t,n,r){let i=Ln(e,t),a=gR(n);if(a)return a;if(!dr(i))return`${i} has a repeated name and cannot be wired from the Studio`;if(r.has(t.component))return`${t.component} is locked`;if(hR(e,t.id)?.names.includes(n))return`${i} is already on ${n}`}function vR(e,t,n,r,i,a){let o=mR(e,i),s=o&&pR(e,o);if(!o||!s)return{blocked:`No pin there`};let c=fR(n,r),l=_R(e,o,c,a);return l?{blocked:l}:[{kind:`addTrace`,from:Ln(e,o),to:`net.${c}`,schematicRouteHints:[s.corner]}]}function yR(e,t,n){return e===`label`?`Add ${t} label at ${n}`:`Add ${t} at ${n}`}function bR(e,t,n,r){let i=mR(e,r),a=i&&pR(e,i);if(!i||!a)return;let o=fR(t,n),s=Kp([o])??`label`;return{wire:[a.end,a.corner],label:{id:`label:pending:${r}:${o}`,net:`net.${o}`,text:o,at:a.corner,side:a.side,style:s}}}function xR(e,t,n){let r=hR(e,t);return r&&!r.names.includes(n)?r.names[0]:void 0}var SR=/^net\.([\w-]+)$/,CR=`schematicRouteHints`,wR=(e,t)=>SR.exec(e?.trim()??``)?.[1]===t,TR=(e,t)=>e.model.traces.filter(e=>wR(e.from,t)||wR(e.to,t));function ER(e,t,n,r){if(t.trim().startsWith(`net.`))return;let i=Rn(e,t)?.component;return i===void 0?`${t} is not a pin the Studio can find; rename ${n} in the code`:r.has(i)?`${i} is locked`:void 0}function DR(e,t,n,r){let i=`rename ${n} in the code`;return t.editable?t.parent!==void 0&&t.parent!==`board`?`The trace on line ${t.line} is inside <${t.parent}>; ${i}`:Object.entries(t.props).some(([e,n])=>n.literal===void 0&&!(e===CR&&t.schematicRouteHints))?`The trace on line ${t.line} has an expression; ${i}`:[t.from,t.to].map(t=>t===void 0?void 0:ER(e,t,n,r)).find(e=>e!==void 0):`The trace on line ${t.line} is read-only (${t.readonlyReason}); ${i}`}function OR(e,t,n){let r=e=>wR(e,t)?`net.${n}`:e??``,i=Object.entries(e.props).filter(([e])=>e!==CR),a=Object.fromEntries(i.map(([e,t])=>[e,t.literal]));return{kind:`addTrace`,from:r(e.from),to:r(e.to),...i.length>0?{props:a}:{},...e.schematicRouteHints?{schematicRouteHints:e.schematicRouteHints}:{}}}var kR=(e,t)=>e.circuit.nets.filter(e=>e.id!==t.net).flatMap(e=>e.names);function AR(e,t,n,r,i){let a=r.trim(),o=n.text,s=gR(a);if(s)return{blocked:s};let c=`Rename net ${o} to ${a}`;if(a===o)return{edits:[],summary:c};if(e.circuit.nets.find(e=>e.id===n.net)?.names.includes(a))return{blocked:`${o} and ${a} already name this net`};let l=TR(t,o);if(l.length===0)return{blocked:`${o} is not written on a trace the Studio can change; rename it in the code`};let u=l.map(t=>DR(e,t,o,i)).find(e=>e!==void 0);if(u)return{blocked:u};let d=l.map(e=>({kind:`removeTrace`,from:e.from??``,to:e.to??``})),f=l.map(e=>OR(e,o,a)),p=kR(e,n).includes(a)?{joins:a}:{};return{edits:[...d,...f],summary:c,...p}}function jR(e,t){if(t.style===`label`)return;let n=TR(e,t.text).length;return`Rename the ${t.text} net everywhere (${n} ${n===1?`connection`:`connections`})?`}var MR=12;function NR(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e),[t,e]),add:e=>{let t={...e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function PR(e){(0,_.useEffect)(()=>{let t=t=>{Yd(Pd(t),{view:`schematic`})?.action===`armNetLabel`&&(t.preventDefault(),e(`label`))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function FR(e,t,n,r){(0,_.useEffect)(()=>{if(e!==`label`&&e!==`vcc`)return;let i=i=>{i.key!==`Tab`||i.shiftKey||Pd(i).typing||(i.preventDefault(),r({at:n,initial:t||(e===`vcc`?`VCC`:``)}))};return window.addEventListener(`keydown`,i),()=>window.removeEventListener(`keydown`,i)},[e,t,n,r])}function IR({design:e,circuit:t,actions:n,pending:r,setTyped:i}){let a=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(o,s,c)=>{let l=vR(e,t,o,c,s,a);if(!Array.isArray(l))return n.notify(l.blocked);let u=fR(o,c),d=xR(e,s,u);if(d&&!window.confirm(`This joins ${d} and ${u} into one net, a short circuit if they carry different voltages. Connect them anyway?`))return;let f=bR(e,o,c,s),p=f&&r.add(f),m=l[0]?.kind===`addTrace`?l[0].from:s;n.edit(l,yR(o,u,m)).then(e=>e||p&&r.drop(p)),o===`label`&&i(``)}}function LR({design:e,circuit:t,actions:n}){let r=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(i,a)=>{let o=AR(e,t,i,a,r);if(`blocked`in o)return n.notify(o.blocked);if(o.edits.length===0)return;let s=`This joins ${i.text} and ${o.joins} into one net, a short circuit if they carry different voltages. Rename anyway?`;(!o.joins||window.confirm(s))&&n.edit(o.edits,o.summary)}}function RR(e){let{tool:t,typed:n,camera:r,design:i,setTyped:a,setEditing:o}=e,s=IR(e),c=LR(e),l=o;return{press:(e,a,o)=>{if(!t||!r)return!1;if(e.button===2)return o(),!0;if(e.button!==0||e.shiftKey)return!1;let c=Jn(i,a,MR/r.scale);return c?(t===`label`&&n===``?l({pin:c.pin,at:c.at,initial:``}):s(t,c.pin,n),!0):!1},submitName:(e,n)=>{let r=e.trim(),i=gR(r);if(i||!n)return i;n.rename?(l(null),c(n.rename,r)):t&&(l(null),n.pin?s(t,n.pin,r):a(r))},open:l}}function zR(e){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=(0,_.useCallback)(()=>{n(null),i(``),o(null)},[]);return{tool:t,typed:r,setTyped:i,editing:a,setEditing:o,arm:(0,_.useCallback)(t=>{e(),n(t),i(``),o(null)},[e]),disarm:s}}function BR(e){let{camera:t,cursor:n}=e,{tool:r,typed:i,setTyped:a,editing:o,setEditing:s,arm:c,disarm:l}=zR(e.onArm),u=NR(e.builtFrom),d=RR({...e,tool:r,typed:i,setTyped:a,setEditing:s,pending:u});FR(r,i,(0,_.useMemo)(()=>n??{x:t?.cx??0,y:t?.cy??0},[n,t]),d.open),oj(r!==null,l),PR(c);let f=u.visible.map(e=>e.label);return{tool:r,armed:r!==null,arm:c,disarm:l,press:(e,t)=>(o?.rename&&s(null),d.press(e,t,l)),rename:t=>{let n=jR(e.circuit,t);(!n||window.confirm(n))&&s({at:t.at,initial:t.text,rename:t})},editing:o,cancelName:()=>d.open(null),submitName:e=>d.submitName(e,o),typed:i,ghosts:f,ghostWires:u.visible.map(e=>e.wire)}}var VR=(e,t,n=!1)=>({start:e,...t?{pin:t}:{},corners:[],bends:[],flip:n}),HR=e=>[...e.bends,e.flip],UR=(e,t)=>An([e.start.at,...e.corners,t],HR(e)),WR=12,GR=(e,t)=>e.pin===t.pin&&e.end?.selector===t.end?.selector&&e.end?.at.x===t.end?.at.x&&e.end?.at.y===t.end?.at.y;function KR(e,t,n){let{start:r,corners:i}=t;if(cr(n,r))return{};let a=Gn(e,r,n);if(a)return`edits`in a?{...a,points:[]}:a;let o=[r,n].find(e=>e.selector.split(`.`)[0]?.includes(`~`));if(o)return{notice:`${o.label} has a repeated name and cannot be wired from the Studio`};let s=mr(e,r,n,i,HR(t));if(s.length===0)return{notice:`${r.label} and ${n.label} are already connected`};let c=lr(e,r,n);return c&&!window.confirm(`This wire joins ${c[0]} and ${c[1]} into one net, a short circuit if they carry different voltages. Connect them anyway?`)?{}:{edits:s,points:UR(t,n.at),summary:`connect ${r.label} to ${n.label}`}}function qR(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)({}),i=(0,_.useCallback)(e=>{r.current=e,n(t=>GR(t,e)?t:e)},[]);return(0,_.useEffect)(()=>i({}),[e,i]),{under:t,setUnder:i,underRef:r}}function JR(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.points),[t,e]),add:e=>{let t={points:e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function YR({drawing:e,setDrawing:t,setWiring:n,underRef:r,start:i,escape:a}){(0,_.useEffect)(()=>{let o=o=>{let s=Yd(Pd(o),{view:`schematic`,drawing:e!==null});if(s?.action===`wire`){if(s.preventDefault&&o.preventDefault(),e)return;let{end:t,pin:a}=r.current;return t?i(t,a):n(e=>!e)}if(s?.action===`removeCorner`&&e)return o.preventDefault(),t({...e,corners:e.corners.slice(0,-1),bends:e.bends.slice(0,-1)});if(s?.action===`flipBend`&&e)return o.preventDefault(),t({...e,flip:!e.flip});o.key===`Escape`&&jO(o)&&a()};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[e,t,n,r,i,a])}function XR(e,t,n,r,i){return(0,_.useMemo)(()=>{let a=t.end?.at??(n&&De(n,r,i));return e&&a?UR(e,a):void 0},[e,t,n,r,i])}var ZR=(e,t,n)=>({step:t,snap:n,...e?{from:e.corners.at(-1)??e.start.at}:{}});function QR(e,t,n,r,i){if(!t)return{};let a=WR/t.scale,o=Jn(e,r,a)?.pin;if(!n&&!o)return{};let s=Yn(e,r,a,i);return{...s?{end:s}:{},...o?{pin:o}:{}}}function $R(e,t,n,r){let[i,a]=(0,_.useState)(null);(0,_.useEffect)(()=>{i&&!e.schematic.drawings.some(e=>`bus:${e.id}`===i.bus.selector)&&a(null)},[e,i]);let o=(e,i,a)=>{let o=tr(e,a);i===`start`?n(VR(o,void 0)):t&&r(t,o)},s=(e,t)=>{let[n,...r]=e.members??[];if(n!==void 0&&r.length===0)return o(e,t,n);a({bus:e,role:t})};return{picking:i,open:s,pick:e=>{i&&(a(null),o(i.bus,i.role,e))},cancelPick:(0,_.useCallback)(()=>a(null),[]),start:(e,t)=>e.members?s(e,`start`):n(VR(e,t))}}function ez(e,t,n,r){return(i,a)=>{r(null);let o=KR(e,i,a);if(!(`edits`in o))return o.notice&&t.notify(o.notice);let s=n.add(o.points);t.edit(o.edits,o.summary).then(e=>e||n.drop(s))}}function tz(e){let{design:t,camera:n,step:r,snap:i}=e,[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),{under:l,setUnder:u,underRef:d}=qR(e.buildId),f=JR(e.builtFrom),p=ez(t,e.actions,f,c),m=$R(t,s,c,p);YR({drawing:s,setDrawing:c,setWiring:o,underRef:d,start:m.start,escape:()=>m.picking?m.cancelPick():s?c(null):o(!1)});let h=XR(s,(0,_.useMemo)(()=>m.picking?.role===`end`?{end:m.picking.bus}:l,[m.picking,l]),e.cursor,r,i),g=(0,_.useMemo)(()=>[s?.pin,l.pin].filter(e=>e!==void 0),[s,l]),v=e=>QR(t,n,a||s!==null,e,ZR(s,r,i)),y=(e,o)=>nz({design:t,camera:n,wiring:a,drawing:s,setDrawing:c,step:r,snap:i,finish:p,underAt:v,picks:m},e,o),b=(0,_.useCallback)(()=>{o(!1),c(null),m.cancelPick()},[m.cancelPick]),x=l.end!==void 0&&(a||s!==null||l.pin!==void 0&&Un(t,l.pin));return{wiring:a,toggleWiring:()=>{b(),o(!a)},cancel:b,drawing:s,under:l,pendingWires:f.visible,preview:h,activePins:g,overPin:x,press:y,hover:e=>u(v(e)),leave:()=>u({}),picking:m.picking,pick:m.pick,cancelPick:m.cancelPick}}function nz(e,t,n){if(!e.camera)return!1;if(e.picks.picking)return e.picks.cancelPick(),!0;if(t.button===2&&e.drawing)return e.setDrawing(null),!0;if(t.button===1||t.button===2||t.shiftKey)return!1;if(e.drawing){let t=Yn(e.design,n,WR/e.camera.scale,ZR(e.drawing,e.step,e.snap));return t?.members&&!e.drawing.start.port?.bus?e.picks.open(t,`end`):t?e.finish(e.drawing,t):rz(e.drawing,n,e,e.setDrawing),!0}let{end:r,pin:i}=e.underAt(n);return!r||!e.wiring&&!(i&&Un(e.design,i))?!1:(e.picks.start(r,i),!0)}function rz(e,t,n,r){let i=De(t,n.step,n.snap),a=e.corners[e.corners.length-1]??e.start.at;(i.x!==a.x||i.y!==a.y)&&r({...e,corners:[...e.corners,i],bends:[...e.bends,e.flip]})}var iz=`This wire's new trace is still being built; reshape it again when the build is done`;function az(e,t,n){let r=e.filter(e=>e.from===t&&e.to===n).length;return r===0?`wire:${t}|${n}`:`wire:${t}|${n}#${r+1}`}var oz=(e,t)=>t.startsWith(`net.`)?t:Rn(e,t)?.id,sz=(e,t)=>{let[n,r]=[oz(e,t.from??``),oz(e,t.to??``)];return n&&r?`wire:${n}|${r}`:void 0};function cz(e,t){let{writer:n}=t;if(n.kind!==`engine`)return{newTrace:!1,wire:t.id};if(n.onWire?.trace){let t=sz(e,n.onWire.trace);return t?{newTrace:!0,wire:t}:{newTrace:!0}}let[r,i]=[oz(e,n.from),oz(e,n.to)];return r&&i?{newTrace:!0,wire:az(e.circuit.connections,r,i)}:{newTrace:!0}}function lz(e,t){return e.some(e=>e.id===t&&e.newTrace)?iz:null}function uz(e,t,n){let r=e.filter(e=>e.sentAt<=t),i=r.length===0?e:e.filter(e=>e.sentAt>t),a=r.filter(e=>e.newTrace&&e.wire!==void 0&&n.has(e.wire));return{waiting:i,follow:e=>{let t=e.wires.map(e=>a.find(t=>t.id===e)?.wire??e);return e.all(e.names,t,e.labels,e.drawings)}}}function dz(e,t,n,r=gr){let i=K(e,t,n);return i?q(e,i,r):ME}function fz(e,t,n,r,i,a){let o=e.schematic.wires.filter(e=>e.id!==n.id).map(e=>e.points);return AE(TE(e.schematic.drawings).filter(e=>fT(t.model,i,e.id,[`x`,`y`])===null),a??n.points,fl(r),o)}function pz(e,t,n,r,i,a,o){let s=Nl(e,n,r,a,o);return Array.isArray(s)?{edits:s.length===0?s:[...s,...fz(e,t,n,r,a,o)],summary:`${i} ${VE(e,n)}`,points:fl(r),...cz(e,n)}:s}function mz(e,t,n,r,i=gr,a){let o=K(e,t,n);return o?pz(e,t,o,r,`reshape`,i,a):{blocked:ME}}function hz(e,t,n,r,i=gr,a){let o=K(e,t,n);if(!o)return{blocked:ME};let s=a!==void 0&&!Ml(a,o.points)?null:UE(e,o,i);return s===null?pz(e,t,o,dl(a??o.points,r),`remove a corner of`,i,a):{blocked:s}}function gz(e,t,{design:n,builtFrom:r,onSelect:i}){(0,_.useEffect)(()=>{let{waiting:a,follow:o}=uz(e,r,new Set(n.schematic.wires.map(e=>e.id)));a!==e&&(t(e=>e.filter(e=>e.sentAt>r)),i(o))},[e,t,n,r,i])}function _z(e){let{design:t,circuit:n,actions:r,locked:i,builtFrom:a}=e,[o,s]=(0,_.useState)([]);gz(o,s,e);let c=(0,_.useMemo)(()=>o.filter(e=>e.sentAt>a).map(({id:e,points:t})=>({id:e,points:t})),[o,a]),l=(0,_.useCallback)(e=>lz(o,e)??dz(t,n,e,i),[o,t,n,i]),u=(0,_.useCallback)((e,t)=>{if(`blocked`in t)return r.notify(t.blocked);if(t.edits.length===0)return;let{edits:n,summary:i,...a}=t,o={id:e,...a,sentAt:Date.now()};s(t=>[...t.filter(t=>t.id!==e),o]),r.edit(n,i).then(e=>e||s(e=>e.filter(e=>e!==o)))},[r]),d=(0,_.useCallback)(e=>c.find(t=>t.id===e)?.points,[c]);return{pending:c,blocker:l,commit:(0,_.useCallback)((e,r)=>u(e,mz(t,n,e,r,i,d(e))),[u,t,n,i,d]),dropCorner:(0,_.useCallback)((e,r)=>{let a=lz(o,e);u(e,a?{blocked:a}:hz(t,n,e,r,i,d(e)))},[u,o,t,n,i,d])}}async function vz(e,t){return`blocked`in e?(t.notify(e.blocked),!1):t.edit(e.edits,e.summary)}function yz({design:e,circuit:t,actions:n,locked:r,selection:i}){let a=(0,_.useCallback)((n,i,a)=>eD(e,t,n,i,r,a),[e,t,r]),o=(0,_.useCallback)((t,n)=>cm(e,t,n),[e]),s=(0,_.useCallback)(t=>IE(e,t),[e]),c=(0,_.useCallback)(t=>{let n=e.schematic.labels.find(e=>e.id===t);return n&&Tp(e.circuit.nets,n.net)},[e]);return TS({removeCorners:()=>{let a=i.soleWire;if(a===void 0)return n.notify(`Select one wire first.`);vz(tD(e,t,a,r),n)}}),(0,_.useMemo)(()=>({net:s,removal:a,labelRemoval:o,labelNet:c}),[s,a,o,c])}function bz(e){let{design:t,camera:n,selection:r,wiring:i}=e,{pending:a,blocker:o,commit:s,dropCorner:c}=_z(e),l=(0,_.useMemo)(()=>nu(t.schematic.wires,a),[t.schematic.wires,a]),u=(0,_.useCallback)(e=>e===void 0?void 0:l.find(t=>t.id===e),[l]),d=(0,_.useMemo)(()=>{let e=e=>n?Yc(l,e,Gc(n.scale)/n.scale):void 0;return i?{at:e,lines:l}:{at:e,lines:l,drag:{points:e=>u(e)?.points,blocker:o,commit:s}}},[l,n,u,o,s,i]),f={at:(e,t)=>n?Jl(d.drag,t,e,n.scale):void 0,drop:c};return{hits:d,selected:(0,_.useMemo)(()=>u(r.soleWire),[u,r.soleWire]),menuWire:(0,_.useMemo)(()=>r.size===0?u(r.wires.at(-1)):void 0,[u,r]),lineOf:u,keys:yz(e),pending:a,corners:f}}function xz({design:e,circuit:t,camera:n,locked:r}){let{drawings:i}=e.schematic,a=(0,_.useCallback)(e=>e===void 0?void 0:i.find(t=>t.id===e),[i]);return{hits:(0,_.useMemo)(()=>({at:e=>n?bk(i,e,6/n.scale,n.scale):void 0,boxes:Sk(i),origin:e=>{let t=a(e);return t&&mT(t)},blocker:e=>{let n=a(e);return n?pT(t.model,r,n):null}}),[i,n,a,t.model,r]),removal:(0,_.useCallback)(e=>xT(t.model,i,r)(e),[t.model,i,r]),drawingOf:a}}var Sz=7,Cz=20;function wz(e){let{state:t}=e;if(t?.tool===`text`&&t.points[0])return{label:`Text`,initial:``,at:t.points[0]};let n=t?.points.at(-1);if(t?.tool===`bus`&&t.naming&&n)return{label:`Bus name`,initial:e.busName(),at:n}}function Tz({draw:e,camera:t,size:n}){let r=wz(e);if(!r||!t)return null;let i=B(t,n,r.at);return(0,X.jsx)(Ez,{left:i.x-Sz,top:i.y-Cz,field:r,draw:e},r.label)}function Ez({left:e,top:t,field:n,draw:r}){let[i,a]=(0,_.useState)(n.initial),[o,s]=(0,_.useState)(),c=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let e=requestAnimationFrame(()=>c.current?.focus());return()=>cancelAnimationFrame(e)},[e,t]),(0,X.jsxs)(`form`,{className:`label-name`,style:{left:e,top:t},onPointerDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),s(r.submitText(i))},children:[(0,X.jsx)(`input`,{ref:c,autoFocus:!0,"aria-label":n.label,placeholder:n.label,value:i,style:{fontFamily:ya},onFocus:e=>n.initial!==``&&e.currentTarget.select(),onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r.cancelText())}}),o&&(0,X.jsx)(`span`,{role:`alert`,children:o})]})}function Dz(e,t,n){switch(n){case`ArrowDown`:return{index:(e+1)%t};case`ArrowUp`:return{index:(e-1+t)%t};case`Home`:return{index:0};case`End`:return{index:t-1};case`Enter`:return{pick:e};case`Escape`:return{cancel:!0};default:return}}var Oz=21,kz=6,Az=12,jz=e=>Math.min(e*Oz+kz,220);function Mz(e,t,n){let r=Math.min(e.x+Az,t.width-100),i=Math.min(e.y+Az,t.height-jz(n));return{left:Math.max(r,0),top:Math.max(i,0)}}function Nz({wire:e,camera:t,size:n}){let{picking:r}=e;if(!r||!t)return null;let i=r.bus.members??[],{left:a,top:o}=Mz(B(t,n,r.bus.at),n,i.length),s=`${r.bus.selector}:${r.bus.at.x}:${r.bus.at.y}`;return(0,X.jsx)(Pz,{left:a,top:o,name:r.bus.label,members:i,wire:e},s)}function Pz({left:e,top:t,name:n,members:r,wire:i}){let[a,o]=(0,_.useState)(0),s=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let e=requestAnimationFrame(()=>s.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,_.useEffect)(()=>s.current?.children[a]?.scrollIntoView({block:`nearest`}),[a]),(0,X.jsx)(`ul`,{ref:s,className:`bus-members`,role:`listbox`,"aria-label":`Members of ${n}`,"aria-activedescendant":`bus-member-${a}`,tabIndex:0,style:{left:e,top:t},onPointerDown:e=>e.stopPropagation(),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||i.cancelPick()},onKeyDown:e=>{let t=Dz(a,r.length,e.key);if(!t)return;if(e.preventDefault(),e.stopPropagation(),`index`in t)return o(t.index);if(`cancel`in t)return i.cancelPick();let n=r[t.pick];n!==void 0&&i.pick(n)},children:r.map((e,t)=>(0,X.jsx)(`li`,{id:`bus-member-${t}`,role:`option`,"aria-selected":t===a,onPointerEnter:()=>o(t),onClick:()=>i.pick(e),children:e},e))})}var Fz={finishShape:{type:`finish`},removeCorner:{type:`removeCorner`},flipBend:{type:`flip`}};function Iz(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.drawing),[t,e]),add:(0,_.useCallback)(e=>{let t={drawing:e,sentAt:Date.now()};return n(e=>[...e,t]),t},[]),drop:(0,_.useCallback)(e=>n(t=>t.filter(t=>t!==e)),[])}}function Lz(e,t){let[n,r]=(0,_.useState)([]);return(0,_.useEffect)(()=>{let i=n.filter(t=>e.schematic.drawings.some(e=>e.id===t));i.length!==0&&(t(()=>_o.none.addDrawings(i)),r(e=>e.filter(e=>!i.includes(e))))},[e,n,t]),{wait:(0,_.useCallback)(e=>r(t=>[...t,e]),[]),forget:(0,_.useCallback)(e=>r(t=>t.filter(t=>t!==e)),[])}}function Rz(e){let[t,n]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{if(!e){n(!1);return}let t=e=>n(e.shiftKey),r=()=>n(!1);return window.addEventListener(`keydown`,t),window.addEventListener(`keyup`,t),window.addEventListener(`blur`,r),()=>{window.removeEventListener(`keydown`,t),window.removeEventListener(`keyup`,t),window.removeEventListener(`blur`,r)}},[e]),t}function zz(e){(0,_.useEffect)(()=>{let t=t=>{let n=Yd(Pd(t),{view:`schematic`})?.action;n&&j(n)&&(t.preventDefault(),e(A[n]))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),TS(Object.fromEntries(O.map(t=>[t,()=>e(A[t])])))}function Bz(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{Xd(Pd(e))&&(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Yd(Pd(e),{view:`schematic`,drawing:!0})?.action:void 0,i=r===void 0?void 0:Fz[r];i&&(e.preventDefault(),t(i))};return window.addEventListener(`keydown`,r,!0),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`keydown`,r,!0),window.removeEventListener(`keydown`,i)}},[e,t])}function Vz(e,t){let[n,r]=(0,_.useState)(null),i=(0,_.useRef)(n);return i.current=n,{state:n,send:(0,_.useCallback)(e=>{let n=i.current;if(!n)return;let a=AI(n,e);i.current=a.state,r(a.state),a.drawing&&t(n.tool,a.drawing)},[t]),arm:(0,_.useCallback)(t=>{e(),i.current=fI(t),r(i.current)},[e]),disarm:(0,_.useCallback)(()=>{i.current=null,r(null)},[])}}function Hz(e,t){let{circuit:n,actions:r}=e,{add:i,drop:a,visible:o}=t,{wait:s,forget:c}=Lz(e.design,e.onSelect),l=(0,_.useRef)([]);return{write:(0,_.useCallback)((e,t)=>{let{model:u}=n;l.current=l.current.filter(e=>!u.drawings.some(t=>t.name===e||t.id===e));let d=II(t,u,l.current),f=d.name??``,p=IT(u,f,o.flatMap(e=>e.kind===`bus`?[e.name]:[]));l.current=[...l.current,f];let m=i(PI(t,p));s(p),r.edit([d],RI(e,f)).catch(()=>!1).then(e=>{e||(l.current=l.current.filter(e=>e!==f),a(m),c(p))})},[n,r,s,c,i,a,o]),taken:l}}function Uz(e,t,n,r){return{submitText:r=>{let i=e?.tool===`bus`?NT(n,r):void 0;return i||t({type:`text`,text:r}),i},busName:()=>MT(n,r.current)}}function Wz(e){let{camera:t,cursor:n,step:r,snap:i}=e,a=Iz(e.builtFrom),{write:o,taken:s}=Hz(e,a),{state:c,send:l,arm:u,disarm:d}=Vz(e.onArm,o),f=Rz(c!==null),p=(0,_.useRef)(void 0);zz(u),Bz(c,l);let m=(0,_.useMemo)(()=>c&&n?NI(c,pI(n,r,i),f):void 0,[c,n,r,i,f]),h=(e,n)=>{if(!c||!t||e.button===1)return!1;if(hI(c,e.button)&&e.preventDefault?.(),e.button===2)return l({type:`cancel`}),!0;let a={at:{x:n.x*t.scale,y:n.y*t.scale},time:Date.now()},o=mI(p.current,a);return p.current=o?void 0:a,l({type:`press`,at:pI(n,r,i),shift:e.shiftKey,double:o}),!0},g=(0,_.useMemo)(()=>m?[...a.visible,m]:a.visible,[a.visible,m]);return{state:c,tool:c?.tool??null,armed:c!==null,busy:c!==null&&c.points.length>0,arm:u,disarm:d,press:h,release:e=>{c&&l({type:`release`,at:pI(e,r,i)})},...Uz(c,l,e.circuit.model,s),cancelText:()=>l({type:`cancel`}),pending:g}}var Gz=.2,Kz=.2,qz=1.2,Jz=.6,Yz=.4,Xz=e=>Dt(Math.ceil(e/Gz-1e-9)*Gz),Zz=e=>Math.max(0,...e.map(e=>e.name.length))*Et*Tt[`pin-name`];function Qz(e){let t=t=>e.filter(e=>e.side===t),n=t=>Math.max(0,...e.filter(e=>t.includes(e.side)).map(e=>e.order)),r=(n([`top`,`bottom`])+1)*Gz,i=(n([`left`,`right`])+1)*Gz,a=Zz(t(`left`))+Zz(t(`right`))+Yz;return{width:Xz(Math.max(qz,r,a)),height:Xz(Math.max(Jz,i))}}function $z(e,t,n,r){let i=Dt(t*Gz);return e===`left`?{edge:Ot(0,-i),end:Ot(-.2,-i)}:e===`right`?{edge:Ot(n,-i),end:Ot(n+Kz,-i)}:e===`top`?{edge:Ot(i,0),end:Ot(i,Kz)}:{edge:Ot(i,-r),end:Ot(i,-r-Kz)}}function eB(e,t={}){let n=Qz(e),r=Math.max(n.width,Xz(t.width??0)),i=Math.max(n.height,Xz(t.height??0));return{width:r,height:i,needed:n,pins:e.map(e=>({name:e.name,side:e.side,order:e.order,bus:e.bus===!0,...$z(e.side,e.order,r,i)}))}}function tB(e,t,n,r){let i=e===`left`||e===`right`?-t.y:t.x,a=Math.max(1,Math.round((e===`left`||e===`right`?r:n)/Gz)-1);return Math.min(a,Math.max(1,Math.round(i/Gz)))}function nB(e,t,n){let[r]=[[`left`,Math.abs(e.x)],[`right`,Math.abs(e.x-t)],[`top`,Math.abs(e.y)],[`bottom`,Math.abs(e.y+n)]].reduce((e,t)=>t[1]<e[1]?t:e);return{side:r,order:tB(r,e,t,n)}}function rB(e,t){let n=gn(e,t),r=e.schematic.symbols.find(e=>e.component===t);if(n&&r)return{instance:n,placed:r,layout:eB(n.ports,n.size)}}var iB=(e,t)=>ef(t,e.placed),aB=(e,t)=>$d({x:t.x-e.placed.x,y:t.y-e.placed.y},-e.placed.rotation);function oB(e,t){return t.flatMap(t=>{let n=rB(e,t);if(!n)return[];let{instance:r,layout:i}=n;return[...i.pins.map(e=>({kind:`pin`,instance:t,file:r.file,port:e.name,at:iB(n,e.edge)})),{kind:`corner`,instance:t,file:r.file,at:iB(n,{x:i.width,y:-i.height})}]})}function sB(e,t,n){let r;for(let i of e){let e=Math.hypot(i.at.x-t.x,i.at.y-t.y);e<=n&&(!r||e<r.distance)&&(r={handle:i,distance:e})}return r?.handle}function cB(e,t,n){let r=rB(e,t.instance),i=r?.instance.ports.find(e=>e.name===t.port);if(!r||!i)return{message:`${t.instance} has no port ${t.port} any more`};let a=nB(aB(r,n),r.layout.width,r.layout.height);if(a.side===i.side&&a.order===i.order)return{message:`${i.name} stays where it is`};let o=r.instance.ports.find(e=>e!==i&&e.side===a.side&&e.order===a.order),s=[{kind:`setProps`,part:i.name,props:{side:a.side,order:a.order}}];o&&s.push({kind:`setProps`,part:o.name,props:{side:i.side,order:i.order}});let c=o?`, ${o.name} to ${i.side} ${i.order}`:``;return{file:r.instance.file,edits:s,summary:`Move port ${i.name} of ${r.instance.sheet} to ${a.side} ${a.order}${c}`}}var lB=e=>Math.round(Math.ceil(e/Gz-1e-9)*Gz*1e3)/1e3;function uB(e,t,n){let r=rB(e,t.instance);if(!r)return{message:`${t.instance} is gone`};let i=aB(r,n),a=Math.max(r.layout.needed.width,lB(i.x)),o=Math.max(r.layout.needed.height,lB(-i.y));return a===r.layout.width&&o===r.layout.height?{message:`${r.instance.sheet} keeps its size`}:{file:r.instance.file,edits:[{kind:`setSheetSize`,width:a,height:o}],summary:`Size the ${r.instance.sheet} symbol to ${a} × ${o}`}}var dB=6;function fB({design:e,selection:t,camera:n,actions:r}){let i=(0,_.useMemo)(()=>oB(e,t.names),[e,t.names]),[a,o]=(0,_.useState)(),s=(0,_.useRef)(void 0),c=e=>{s.current=e,o(e)};return{press:(e,t)=>{if(e.button!==0||e.shiftKey||e.ctrlKey||e.metaKey||!n||i.length===0)return!1;let r=sB(i,t,dB/n.scale);return c(r),r!==void 0},release:t=>{let n=s.current;if(!n)return;c(void 0);let i=n.kind===`pin`?cB(e,n,t):uB(e,n,t);if(`message`in i)return r.notify(i.message);r.editFile(i.file,i.edits,i.summary)},hint:a===void 0?void 0:a.kind===`pin`?`Drop ${a.port} on any side of ${a.instance}'s box; the release writes its side and order in ${a.file}.`:`Drop the corner to size ${a.instance}'s box; the release writes width and height in ${a.file}.`,holding:a!==void 0}}var pB=`noConnect`;function mB(e){return typeof e==`string`?[...new Set(e.split(`,`).map(e=>e.trim()).filter(e=>e!==``))]:[]}var hB=(e,t)=>e.names.includes(t)||`pin${e.number}`===t;function gB(e,t){let n=mB(e);return(n.some(e=>hB(t,e))?n.filter(e=>!hB(t,e)):[...n,`pin${t.number}`]).join(`,`)}function _B(e,t,n){let r;for(let i of e.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let o=Math.hypot(a.x-t.x,a.y-t.y);o<=n&&(!r||o<r.distance)&&(r={component:i.component,pin:e,end:a,distance:o})}return r&&{component:r.component,pin:r.pin,end:r.end}}function vB(e,t,n){let r=_B(e.sheet,t,n);if(!r)return{message:`Click the end of a pin to put a no connect flag on it.`};let i=e.components.find(e=>e.id===r.component)?.pins.find(e=>e.id===r.pin),a=e.parts.find(e=>e.name===r.component);if(!i||!a)return{message:`${r.pin} belongs to a part this file does not write; flag it in its own file.`};if(e.locked.has(a.name))return{message:`${a.name} is locked; unlock it to change its no connect flags.`};if(!a.editable)return{message:`${a.name} is read-only (${a.readonlyReason??`written as an expression`}).`};let o=a.props[pB];if(o&&o.literal===void 0)return{message:`${a.name}.${pB} is an expression (${o.source}); change it in the code.`};let s=gB(o?.literal,i),c=`${mB(s).length<mB(o?.literal).length?`remove the no connect flag from`:`flag no connect on`} ${r.pin}`;return{edit:{kind:`setProps`,part:a.name,props:{[pB]:s===``?null:s}},summary:c}}function yB(e,t,n){let[r,i]=[n.x-t.x,n.y-t.y],a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function bB(e,t,n){let r;for(let i of e.wires)for(let e=1;e<i.points.length;e++){let a=yB(t,i.points[e-1],i.points[e]),o=Math.hypot(a.x-t.x,a.y-t.y);o<=n&&(!r||o<r.distance)&&(r={wire:i.id,point:a,distance:o})}return r&&{wire:r.wire,point:{x:V(r.point.x),y:V(r.point.y)}}}function xB(e,t,n){let r=bB(e,t,n);if(!r)return{message:`Click a wire to put a junction on it.`};let i=e.pages?.find(e=>e.wires.includes(r.wire))?.name;return{edit:{kind:`addDrawing`,tag:`junction`,props:{x:r.point.x,y:r.point.y},...i&&i!==`Main`?{page:i}:{}},summary:`add a junction at ${r.point.x}, ${r.point.y}`}}var SB=12,CB={noConnect:`No connect flag: click the end of a pin to flag it (again to take the flag off). Esc to stop.`,junction:`Junction: click a wire to put a junction on it. Esc to stop.`};function wB(e){let[t,n]=(0,_.useState)(null),r=(0,_.useRef)(e);r.current=e;let i=(0,_.useCallback)(e=>{r.current.onArm(),n(e)},[]),a=(0,_.useCallback)(()=>n(null),[]);return TS({noConnect:()=>i(`noConnect`),junction:()=>i(`junction`)}),(0,_.useEffect)(()=>{let e=e=>{let r=Pd(e);if(Xd(r)&&t)return e.stopPropagation(),n(null);Yd(r,{view:`schematic`})?.action===`junction`&&(e.preventDefault(),i(`junction`))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t,i]),{tool:t,armed:t!==null,arm:i,disarm:a,press:(e,i)=>{let{design:a,circuit:o,actions:s,camera:c,locked:l}=r.current;if(!t||!c||e.button===1)return!1;if(e.button===2)return n(null),!0;let u=SB/c.scale,d=t===`junction`?xB(a.schematic,i,u):vB({sheet:a.schematic,components:a.circuit.components,parts:o.model.parts,locked:l},i,u);return`message`in d?s.notify(d.message):s.edit([d.edit],d.summary),!0},hint:t?CB[t]:void 0}}var TB={cx:0,cy:0,scale:60},EB=.06,DB=12;function OB(e,t,n,r){return{sheet:(0,_.useMemo)(()=>{let t=AP(e.schematic,r);return n.length===0&&t===e.schematic.labels?e.schematic:{...e.schematic,wires:[...nu(e.schematic.wires,n)],labels:[...t]}},[e.schematic,n,r]),selected:(0,_.useMemo)(()=>t&&nu([t],n)[0],[t,n])}}function kB(e,t){let{design:n,border:r,camera:i,size:a,moving:o,boxes:s,hover:c,selection:l,locked:u,circuit:d,gesture:f,movingLabels:p,hoverLabel:m,hoverDrawing:h,hoverWire:g,palette:v,highlight:y,markers:b,activeViolation:x,grid:S,texts:C,theme:w}=t,{wiring:T,drawing:E,activePins:ee,pendingWires:D,preview:O}=t.wire,{ghosts:k,ghostWires:A,armed:j}=v,te=t.draw.pending,ne=OB(n,t.selectedWire,t.wireShapes,o),re=ne.selected,M=(0,_.useMemo)(()=>Df(ne.sheet,C.moves),[ne.sheet,C.moves]);(0,_.useEffect)(()=>{let t=i??TB,n=Mo(w);Fo(n);let _=eO(n),v=Pl(n),ne=kO(e.current,a,t,n.background,(e,t,r,i)=>bL(e,t,r,S,i,n));if(!ne)return;let{ctx:N,ratio:P}=ne;PL(N,t,a,r,P),_c(N,M,{camera:t,size:a},{ratio:P,showPins:T||E!==null||j,activePins:ee,pending:[...D,...A,...p.map(e=>e.wire)],movingLabels:p,ghostLabels:k,selectedWires:l.wires,selectedLabels:l.labels,selectedDrawings:l.drawings,...o?.drawings?{movingDrawings:o.drawings}:{},pendingDrawings:te,...y?{highlight:y}:{},...o?{moving:{components:o.names,by:o.offset}}:{},violations:b,...x?{activeViolation:x}:{}}),N.setTransform(P,0,0,P,0,0),O&&cO(N,t,a,O,`drawing`,n.wire,P),AO(N,t,a,{view:`schematic`,boxes:s,moving:o,hover:E?void 0:c,selection:l,locked:u,marks:d.annotations.marks,gesture:f,look:_,ratio:P}),m&&!E&&!f&&tO(N,t,a,Dr(m),{x:0,y:0},`hover`,_,P),lO(N,{camera:t,size:a},C.shown,{selected:l.texts,hover:E||f?void 0:C.hover},_,P),h&&!l.hasDrawing(h.id)&&!E&&!f&&tO(N,t,a,xk(h),{x:0,y:0},`hover`,_,P),!g||l.hasWire(g.id)||T||E||f||Ul(N,t,a,g.points,v,P),re&&!p.some(e=>e.hideWire===re.id)&&Wl(N,t,a,re.points,v,P)},[e,M,r,i,a,T,E,ee,D,O,o,p,m,h,g,re,s,c,l,u,d,f,k,A,j,te,y,b,x,S,C,w])}function AB({step:e,setStep:t,keep:n}){return(0,X.jsxs)(ub,{children:[(0,X.jsx)(RO,{step:e,options:fg(`schematic`),onChange:t}),(0,X.jsx)(zO,{...n,title:`Write the faded symbols' positions into the code as schX and schY`})]})}function jB({boxes:e,wire:t,labels:n,filter:r,wires:i,drawings:a,texts:o,setCursor:s}){let[c,l]=(0,_.useState)({kind:`canvas`});return{part:c.kind===`part`?c.name:void 0,label:c.kind===`label`?c.label:void 0,wire:c.kind===`wire`?c.id:void 0,drawing:c.kind===`drawing`?c.id:void 0,text:c.kind===`text`?c.id:void 0,over:c.kind!==`canvas`,at:s=>{t.hover(s),l(vA(e,n,s,{selection:_o.none,armed:null,filter:r},i,a,o))},leave:()=>{l({kind:`canvas`}),s(void 0),t.leave()}}}function MB({wrapRef:e,canvasRef:t,size:n,camera:r,cursor:i,pointer:a,onLeave:o,cursorStyle:s,wire:c,palette:l,note:u,draw:d,gesture:f,rotateHeld:p,snap:m,empty:h,symbolHint:g,label:_,markHint:v}){let y=g??v??IB(c)??gL(l)??UI(d.state)??u.hint;return(0,X.jsxs)(`div`,{className:`schematic-canvas`,ref:e,style:{cursor:s},...a,onPointerLeave:o,onContextMenu:e=>e.preventDefault(),children:[(0,X.jsx)(`canvas`,{ref:t,style:{width:n.width,height:n.height},role:`img`,"aria-label":`Schematic. Drag symbols, net labels and drawings to move them, click a wire to select it, Shift or Ctrl click parts, wires, net labels and drawings to add them, drag a wire or its corner handles to reshape it, drag the background to select, drag with the right button to pan, scroll to zoom. Double click a net label to rename its net. Click a free pin or press W over a pin to draw a wire. Place → Bus draws a bus, and a wire that ends on a bus picks one of its members. Place → Polyline, Arc, Circle, Rectangle and Text draw on the sheet.`}),y&&(0,X.jsx)(`div`,{className:`canvas-top`,children:(0,X.jsx)(`div`,{className:`canvas-hint`,children:y})}),(0,X.jsx)(_L,{palette:l,camera:r,size:n}),(0,X.jsx)(Tz,{draw:d,camera:r,size:n}),(0,X.jsx)(Nz,{wire:c,camera:r,size:n}),(0,X.jsx)(IF,{state:_}),(0,X.jsx)(BO,{cursor:i,zoom:(r??TB).scale,detail:c.under.end?.label,gesture:f,rotateHeld:p,snap:m}),h&&(0,X.jsx)(`p`,{className:`empty`,children:`This schematic has no parts yet.`})]})}function NB(e,t,n){rR(r=>{let i=e.schematic.labels.find(e=>e.id===r.labelId);i?t.rename(i):n.notify(`That label is gone; right click it again.`)})}function PB(e){let t=(0,_.useRef)(void 0),n=(0,_.useMemo)(()=>rC(e.schematic),[e.schematic]);return(0,_.useMemo)(()=>{let e=qL(t.current,n);return t.current=e,e},[n])}function FB(e,t){let n=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{JL(n.current,e)&&t(),n.current=e},[e,t])}function IB(e){return e.picking?`Pick the member of ${e.picking.bus.label} to connect: arrow keys and Enter, or a click. Esc closes the list.`:e.drawing?`From ${e.drawing.start.label}: click the sheet for a corner, then a pin, a wire, a bus or a net label to finish. Backspace removes a corner, Esc cancels.`:e.wiring?`Click a pin or a bus to start a wire. Esc stops wiring.`:void 0}function LB(e,t){return(0,_.useMemo)(()=>Dp(e,t),[e,t])}function RB(e,t,n){return(0,_.useMemo)(()=>{let r=tu(e?.kind===`reshape`?e:void 0,t);return n&&n.length>0?[...n,...r]:r},[e,t,n])}function zB(e,t,n){return(0,_.useMemo)(()=>e&&e.sentAt>t?DP(e,n):void 0,[e,t,n])}function BB(e,t,n,r){let i=nR(e,(0,_.useMemo)(()=>t?.kind===`label`&&t.moved&&!t.blocker?{id:t.label.id,at:t.at}:void 0,[t]));return(0,_.useMemo)(()=>{let e=[...i?[i]:[],...r??[]];return e.length===0?n:[...e,...n.filter(t=>!e.some(e=>e.id===t.id))]},[i,n,r])}function VB({design:e,builtFrom:t,camera:n,cursor:r,fit:i,wire:a,palette:o,drawBusy:s,highlightNets:c,onHighlight:l,keys:u,texts:d}){let f=(0,_.useRef)(void 0);f.current=r;let p=(0,_.useCallback)(()=>n&&f.current?wp(e,f.current,DB/n.scale):void 0,[e,n]),m=(0,_.useCallback)(t=>Op(e,t),[e]),{rotateHeld:h,keyMove:g}=qP({...u,paused:a.drawing!==null||s,fit:i,netUnderPointer:p,netsOf:m,onHighlight:l,texts:d}),{wiring:v,drawing:y}=a,{disarm:b}=o;return(0,_.useEffect)(()=>{(v||y)&&b()},[v,y,b]),TS({wire:()=>{b(),v||a.toggleWiring()},netLabel:()=>o.arm(`label`),groundFlag:()=>o.arm(`gnd`),powerFlag:()=>o.arm(`vcc`)}),TS({tidySheet:()=>rt(e,u.blockerFor,u.actions,u.circuit)}),{highlight:LB(e,c),rotateHeld:h,keyMoving:zB(g,t,u.layout.anchors)}}function HB(e,t,n,r,i){let{wiring:a,cancel:o}=e,{tool:s,disarm:c}=t,{which:l,disarm:u}=n,{disarm:d}=r,{disarm:f}=i,p=Jy(a,s)??Yy(r.tool)??i.tool??aj(l);(0,_.useEffect)(()=>{$y({active:p,stop:()=>{c(),o(),u(),d(),f()}})},[p,c,o,u,d,f]),(0,_.useEffect)(()=>tb,[])}function UB(e,t,n,r,i){let{cancel:a,wiring:o,drawing:s}=t,{disarm:c,armed:l}=n,{disarm:u,armed:d}=r,{disarm:f,armed:p}=i,m=(0,_.useCallback)(()=>{c(),a(),u(),f()},[c,a,u,f]),h=wB({...e,onArm:m}),g=h.disarm;return(0,_.useEffect)(()=>{(o||s||l||d||p)&&g()},[o,s,l,d,p,g]),h}function WB(e,t){let{cancel:n,wiring:r,drawing:i}=e,{disarm:a,armed:o}=t,s=sj((0,_.useCallback)(()=>{a(),n()},[a,n])),c=s.disarm;return(0,_.useEffect)(()=>{(r||i||o)&&c()},[r,i,o,c]),s}function GB(e,t,n,r){let{cancel:i,wiring:a,drawing:o}=t,{disarm:s,armed:c}=n,{disarm:l,armed:u}=r,d=(0,_.useCallback)(()=>{s(),i(),l()},[s,i,l]),f=Wz({...e,onArm:d}),p=f.disarm;return(0,_.useEffect)(()=>{(a||o||c||u)&&p()},[a,o,c,u,p]),f}function KB(e,t,n,r){let{disarm:i}=e,{disarm:a}=t,{disarm:o}=n,{disarm:s}=r,c=(0,_.useCallback)(()=>{i(),a(),o(),s()},[i,a,o,s]);return{armed:e.tool??(t.armed||n.armed||r.armed?`place`:null),disarm:c}}function qB({boxes:e,labels:t,wires:n,drawings:r,corners:i,wire:a,palette:o,note:s,draw:c,marks:l,picking:u,onOpenProperties:d,symbolEdit:f,sheetOf:p,onOpenSheet:m,...h}){let g=()=>!s.armed&&!o.armed&&!c.armed&&!l.armed&&!a.wiring&&a.drawing===null,_=(e,t)=>g()&&f.press(e,t)||!s.armed&&(l.press(e,t)||c.press(e,t)||o.press(e,t)||a.press(e,t)),v=e=>{c.release(e),f.release(e)},y=f=>{let g=s.armed||o.armed||c.armed||l.armed||a.wiring||a.drawing!==null,_=vA(e,t,f,u,n,r),v=bA({busy:g,handle:i.at(f,u),target:_,selectedBefore:h.gestures.wireBeforeDoubleClick()});v.kind===`removeCorner`&&i.drop(v.id,v.index);let y=v.kind===`properties`&&v.target.kind===`part`?p(v.target.name):void 0;y===void 0?v.kind===`properties`&&d(v.target):m(y),v.kind===`rename`&&o.rename(v.label)};return $A({...h,tool:_,toolRelease:v,open:y})}function JB(e){let{design:t,buildId:n,builtMark:r,buildStatus:i,project:a,builtFrom:o,circuit:s,actions:c,selection:l,onSelect:u,highlight:d,onHighlight:f,gridStyle:p,gridStep:m,snap:h,onGridStep:g,markers:v,activeViolation:y,focus:b,onFocused:x}=e,S=(0,_.useRef)(null),C=(0,_.useRef)(null),w=wO(S),[T,E]=(0,_.useState)(),ee=(0,_.useMemo)(()=>({step:m,style:p}),[m,p]),D=xO(t,`schematic`,s),O=PB(t),{camera:k,setCamera:A,fit:j}=EO(S,w,O.outer,EB);FB(O,j);let te=(0,_.useMemo)(()=>eR(O,{project:a??``,page:`Schematic`,file:s.file,date:$L(n),rev:``}),[O,a,s.file,n]);DO(`schematic`,b,k,A,x),ej({selection:l,boxes:D.boxes,size:w,setCamera:A,notify:c.notify});let ne=tz({design:t,actions:c,camera:k,cursor:T,step:m,snap:h,buildId:n,builtFrom:o}),re=fB({design:t,selection:l,camera:k,actions:c}),M=BR({design:t,circuit:s,actions:c,camera:k,cursor:T,builtFrom:o,onArm:ne.cancel}),N=WB(ne,M),P=GB({design:t,circuit:s,actions:c,camera:k,cursor:T,step:m,snap:h,builtFrom:o,onSelect:u},ne,M,N),ie=(0,_.useMemo)(()=>({design:t,locked:D.locked}),[t,D.locked]),F={view:`schematic`,circuit:s,actions:c,onSelect:u,blockerFor:D.blockerFor,follow:ie},I=tR({design:t,circuit:s,actions:c,builtFrom:o}),L=bz({design:t,circuit:s,actions:c,locked:D.locked,camera:k,selection:l,onSelect:u,builtFrom:o,wiring:ne.wiring||ne.drawing!==null}),R=xz({design:t,circuit:s,camera:k,locked:D.locked}),ae=ck({view:`schematic`,design:t,circuit:s,actions:c,locked:D.locked,builtFrom:o}),oe=UB({design:t,circuit:s,actions:c,camera:k,locked:D.locked},ne,M,N,P),se=KB(N,M,P,oe);HB(ne,M,N,P,oe);let ce=ZA({...F,camera:k,setCamera:A,size:w,boxes:D.boxes,anchors:D.anchors,step:m,snap:h,builtFrom:o,labels:I.tools,wires:L.hits,drawings:R.hits,texts:ae.tools,selection:l,tool:se,filter:e.pickFilter,onContextMenu:e.onContextMenu});NB(t,M,c);let le=SO(D,m,h),ue=CO(S,l.primary,D.boxes,k,w,L.menuWire),de={...F,selection:l,layout:le,builtMark:r,buildStatus:i,moveWaiting:ce.pending!==void 0,menuPlace:ue,onContextMenu:e.onContextMenu,wire:L.keys,drawings:R.removal},{highlight:fe,rotateHeld:pe,keyMoving:me}=VB({design:t,builtFrom:o,camera:k,cursor:T,fit:j,wire:ne,palette:M,drawBusy:P.busy,highlightNets:d,onHighlight:f,keys:de,texts:ae}),z=jB({boxes:D.boxes,wire:ne,labels:I.tools,filter:e.pickFilter,wires:L.hits,drawings:R.hits,texts:ae.tools,setCursor:E}),{gesture:he}=ce,ge=lk(ae,he),_e=(0,_.useMemo)(()=>({...ge,hover:z.text}),[ge,z.text]),ve=ce.moving??me,ye=BB(t,he,I.pending,ve?.labels),be=(0,_.useMemo)(()=>L.lineOf(z.wire),[L.lineOf,z.wire]),xe=RB(he,L.pending,ve?.wires);kB(C,{design:t,border:te,camera:k,size:w,wire:ne,moving:ve,boxes:D.boxes,hover:z.part,selection:l,locked:D.locked,circuit:s,gesture:he,movingLabels:ye,hoverLabel:z.label,hoverDrawing:R.drawingOf(z.drawing),hoverWire:be,selectedWire:L.selected,wireShapes:xe,palette:M,draw:P,highlight:fe,markers:v,activeViolation:y,grid:ee,texts:_e,theme:e.theme});let Se={selection:l,armed:se.armed,filter:e.pickFilter},Ce=e=>gn(t,e)?.file,we=k??TB,V={view:`schematic`,design:t,scale:we.scale,context:Se,boxes:D.boxes,labels:I.tools,wires:L.hits,drawings:R.hits,texts:ae.tools},Te=FF({enabled:e.hoverLabels,busy:ne.drawing!==null||P.busy,probe:{pick:e=>nI(e,V),still:(e,t)=>aI(e,t,V)},camera:k,design:t}),Ee=e=>{WC(`sch`,e),z.at(e),Te.move(e,B(we,w,e))},De=()=>{Te.leave(),z.leave()},Oe=NF(qB({symbolEdit:re,sheetOf:Ce,onOpenSheet:e.onOpenSheet,camera:k,size:w,element:S,gestures:ce,setCursor:E,hover:Ee,boxes:D.boxes,labels:I.tools,wires:L.hits,drawings:R.hits,corners:L.corners,wire:ne,palette:M,note:N,draw:P,marks:oe,picking:Se,onOpenProperties:e.onOpenProperties}),Te,C),ke=QA(he,ne.drawing!==null||ne.overPin||M.armed||N.armed||P.armed||oe.armed,z.over);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(AB,{step:m,setStep:g,keep:{show:D.autoPlaced,onKeep:()=>Ye(t,`schematic`,D.blockerFor,c,s)}}),(0,X.jsx)(MB,{wrapRef:S,canvasRef:C,size:w,camera:k,cursor:T,pointer:Oe,onLeave:De,cursorStyle:ke,wire:ne,palette:M,note:N,draw:P,gesture:he,rotateHeld:pe,snap:h,empty:D.boxes.length===0,symbolHint:re.hint,label:Te.state,markHint:oe.hint})]})}function YB(){document.getElementById(`doc-panel`)?.focus()}function XB({text:e,seq:t,onText:n,onSearch:r,onClose:i,status:a}){let o=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=()=>{o.current?.focus(),o.current?.select()};e();let t=window.setTimeout(e,0);return()=>window.clearTimeout(t)},[t]);let s=()=>{i(),YB()};return(0,X.jsxs)(`div`,{className:`find-box`,role:`search`,children:[(0,X.jsx)(`input`,{ref:o,type:`text`,value:e,placeholder:`Find a part or a net`,"aria-label":`Find a part or a net`,spellCheck:!1,autoComplete:`off`,onChange:e=>n(e.target.value),onKeyDown:t=>{if(t.key===`Enter`)r(e);else if(t.key===`Escape`)s();else if((t.ctrlKey||t.metaKey)&&t.key.toLowerCase()===`f`)o.current?.select();else return;t.preventDefault(),t.stopPropagation()}}),(0,X.jsx)(`button`,{type:`button`,className:`find-close`,title:`Close (Esc)`,"aria-label":`Close the find box`,onClick:s,children:(0,X.jsx)(nh,{})}),(0,X.jsx)(`span`,{className:`find-status`,role:`status`,"aria-live":`polite`,children:a})]})}var ZB=new Set([`name`,`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`layer`,`side`]),QB=`Press Ctrl+F to find a part or a net.`,$B=e=>`Nothing matches "${e}".`;function eV(e,t){return e===null?``:t===0?`No results`:t===1?`1 result`:`${t} results`}var tV=new Intl.Collator(`en`,{numeric:!0});function nV(e){let t=new Map(Xp(e).map(e=>[e.id,e.label]));return e.circuit.nets.map(e=>({id:e.id,label:t.get(e.id)??e.id,names:e.names}))}var rV=e=>typeof e==`string`||typeof e==`number`?String(e):void 0;function iV(e,t){return t.find(t=>t.component===e.tag)}function aV(e,t){let n=[{field:`name`,text:e.name},{field:`kind`,text:e.tag}];for(let[t,r]of Object.entries(e.props)){let e=ZB.has(t)?void 0:rV(r.literal);e!==void 0&&n.push({field:t,text:e})}let r=iV(e,t);return r?.mpn&&n.push({field:`mpn`,text:r.mpn}),r&&n.push({field:`title`,text:r.title}),n}function oV(e,t,n){let r=aV(e,t).filter(e=>e.text.toLowerCase().includes(n));return r.filter((e,t)=>r.findIndex(t=>t.field===e.field)===t)}function sV(e,t){return e.names.filter(e=>e.toLowerCase().includes(t)).map(e=>({field:`net name`,text:e}))}var cV=(e,t)=>tV.compare(e.name,t.name);function lV(e,t,n,r=[]){let i=e.trim().toLowerCase();if(i===``)return[];let a=t.map(e=>({id:`part:${e.name}`,kind:`part`,name:e.name,matches:oV(e,r,i)})).filter(e=>e.matches.length>0).sort(cV),o=n.map(e=>({id:`net:${e.id}`,kind:`net`,name:e.label,net:e.id,matches:sV(e,i)})).filter(e=>e.matches.length>0).sort(cV);return[...a,...o]}function uV(e){return e.matches.map(e=>e.field===`name`||e.field===`net name`?e.field:`${e.field} ${e.text}`).join(`, `)}function dV(e,t,n){if(e.kind===`net`)return e.net?{highlight:[e.net]}:{};let r=t?Fe(t,n).get(e.name)?.origin:void 0;return{select:e.name,...r?{focus:{view:n,at:r}}:{}}}var fV={pcb:`Show on the PCB`,schematic:`Show on the schematic`,code:`From the code`};function pV({rows:e,counts:t,active:n,onPick:r}){let i=(0,_.useMemo)(()=>Vw(e),[e]);return(0,X.jsxs)(`section`,{className:`checks`,"aria-label":`Checks`,onClick:km,children:[(0,X.jsxs)(`header`,{className:`checks-head hairline-b`,children:[(0,X.jsx)(`h2`,{children:`Checks`}),e.length>0&&(0,X.jsx)(`span`,{className:`count`,children:Gw(t)})]}),(0,X.jsx)(`div`,{className:`checks-body`,children:i.length===0?(0,X.jsx)(`p`,{className:`note ok`,children:Ow}):i.map(e=>(0,X.jsx)(mV,{group:e,active:n,onPick:r},e.code))})]})}function mV({group:e,active:t,onPick:n}){return(0,X.jsxs)(`section`,{className:`check-group ${e.severity}`,children:[(0,X.jsxs)(`h3`,{children:[(0,X.jsx)(`span`,{className:`dot`,role:`img`,"aria-label":e.severity===`error`?`Error`:`Warning`}),(0,X.jsx)(`span`,{className:`code`,children:e.code}),(0,X.jsx)(`span`,{className:`count`,children:e.rows.length})]}),(0,X.jsx)(`ul`,{children:e.rows.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(hV,{row:e,active:e.id===t,onPick:n})},e.id))})]})}function hV({row:e,active:t,onPick:n}){return(0,X.jsxs)(`button`,{className:`check-row ${e.severity}${t?` active`:``}`,"aria-current":t||void 0,title:fV[e.view],onClick:()=>n(e),children:[(0,X.jsx)(`span`,{className:`message`,children:e.message}),e.items.length>0&&(0,X.jsx)(`span`,{className:`items`,children:e.items.join(`, `)})]})}var gV={part:`Select the part`,net:`Highlight the net`};function _V({query:e,rows:t,active:n,pick:r}){return e===null?(0,X.jsx)(`p`,{className:`note bottom-note`,children:QB}):t.length===0?(0,X.jsx)(`p`,{className:`note bottom-note`,children:$B(e)}):(0,X.jsxs)(`section`,{className:`find-results`,"aria-label":`Find results`,onClick:km,children:[(0,X.jsxs)(`header`,{className:`find-head hairline-b`,children:[(0,X.jsx)(`h2`,{children:`Find results`}),(0,X.jsx)(`span`,{className:`count`,children:`${t.length} found for "${e}"`})]}),(0,X.jsx)(`ul`,{children:t.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`find-row${e.id===n?` active`:``}`,"aria-current":e.id===n||void 0,title:gV[e.kind],onClick:()=>r(e),children:[(0,X.jsx)(`span`,{className:`kind ${e.kind}`,children:e.kind===`part`?`Part`:`Net`}),(0,X.jsx)(`span`,{className:`name`,children:e.name}),(0,X.jsx)(`span`,{className:`matched`,children:uV(e)})]})},e.id))})]})}var vV=.04,yV=`A change is shown: the board cannot be edited. Close it to edit.`;function bV(e){if(e[0]?.author!==`ai`)return;let t=e.find(e=>e.author===`human`)?.id;return t?{since:t,label:`Since my last change`}:{since:`c0000`,label:`Everything the agent did`}}function xV(e,t){let n=e.pcb,r=ke(n.board?.outline??[])??Ae(n.parts.flatMap(e=>ke(e.courtyard)??[]));return r&&t.width>0&&t.height>0?xe(r,t,vV):void 0}function SV(e){return e===`Escape`?`close`:void 0}function CV(e){return e?Object.fromEntries(N.map(e=>[e,yV])):{}}function wV(e,t){return t===`before`?e.before:e.after}function TV(e){return`id`in e?`/api/change?id=${encodeURIComponent(e.id)}`:`/api/change?since=${encodeURIComponent(e.since)}`}function EV({entry:e,onShow:t}){return(0,_.createElement)(`button`,{type:`button`,"aria-label":`Show change ${e.id}: ${e.summary}`,onClick:()=>t({id:e.id})},`Show`)}function DV({history:e,onShow:t}){let n=bV(e);return n===void 0?null:(0,_.createElement)(`p`,{className:`history-since`},(0,_.createElement)(`button`,{type:`button`,onClick:()=>t({since:n.since})},n.label))}function OV(e){return e.undone?{className:`undone`,undoable:!1}:e.redoneAs?{className:e.undoOf?`redone`:``,note:`redone as ${e.redoneAs}`,undoable:!1}:{className:``,undoable:e.undoOf===void 0}}function kV({history:e,problems:t,actions:n,onShow:r=()=>void 0}){let i=t.map(e=>(0,X.jsxs)(`p`,{className:`note`,role:`alert`,children:[`Skipped `,e.file,`: `,e.reason]},e.file));return e.length===0?(0,X.jsxs)(X.Fragment,{children:[t.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`Changes from you and the agent appear here.`}),i]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(DV,{history:e,onShow:r}),(0,X.jsx)(`ul`,{className:`history`,children:e.map(e=>{let t=OV(e);return(0,X.jsxs)(`li`,{className:t.className,children:[(0,X.jsx)(`span`,{className:`who ${e.author}`,children:e.author===`ai`?`Agent`:`You`}),(0,X.jsx)(`span`,{className:`what`,title:e.file,children:e.summary}),t.note&&(0,X.jsx)(`span`,{className:`history-note`,children:t.note}),(0,X.jsx)(EV,{entry:e,onShow:r}),t.undoable&&(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Undo ${e.summary}`,onClick:()=>void n.undo(e.id),children:(0,X.jsx)(th,{})})]},e.id)})}),i]})}var AV,jV=0,MV=new Set;function NV(e){AV=e;for(let e of MV)e()}var PV={async show(e){let t=++jV;NV({request:e,mode:`both`,status:`loading`});try{let n=await z(TV(e));t===jV&&AV&&NV({...AV,status:`ready`,data:n})}catch(e){t===jV&&AV&&NV({...AV,status:`failed`,error:e.message})}},setMode(e){AV&&NV({...AV,mode:e})},close(){jV+=1,NV(void 0)},shown:()=>AV!==void 0,subscribe(e){return MV.add(e),()=>MV.delete(e)},get:()=>AV};function FV(){return(0,_.useSyncExternalStore)(PV.subscribe,PV.get,PV.get)}var IV={resistor:{resistance:`10k`,footprint:`0402`},capacitor:{capacitance:`100nF`,footprint:`0402`},inductor:{inductance:`10uH`,footprint:`0805`},led:{color:`red`,footprint:`0603`},crystal:{frequency:`16MHz`},fuse:{currentRating:`500mA`,footprint:`1206`}};function LV(e){let t=IV[e]??{},n=Object.keys(t).find(e=>e!==`footprint`);return n?t[n]??``:``}function RV(e){let t=e.library.map(e=>({part:e.id,name:e.mpn??e.id,value:``,footprint:e.footprint,description:e.title,verified:e.verified?`Verified`:`Unverified`,tooltip:`${e.title} (${e.component})`,verifiedTip:e.verified?`Checked by ${e.verifiedBy}${e.verifiedAgainst?` against ${e.verifiedAgainst}`:``}`:`Not checked against the datasheet yet`,extra:`${e.id} ${e.mpn??``} ${e.component}`})),n=e.builtin.map(e=>({part:e,name:e,value:LV(e),footprint:IV[e]?.footprint??``,description:``,verified:``,tooltip:e,verifiedTip:``,extra:e}));return[...t,...n]}function zV(e,t){let n=t.trim().toLowerCase();return n===``?[...e]:e.filter(e=>[e.name,e.value,e.footprint,e.description,e.verified,e.extra].some(e=>e.toLowerCase().includes(n)))}function BV(e,t,n,r=!1){if(n===0||e===`Enter`&&r)return null;let i=n-1;switch(e){case`ArrowDown`:return{move:Math.min(t+1,i)};case`ArrowUp`:return{move:Math.max(t-1,0)};case`Home`:return{move:0};case`End`:return{move:i};case`Enter`:return{place:!0};default:return null}}var VV=(e,t)=>e===null||t-e>=500,HV=e=>e<=1,UV=(e,t)=>Math.max(0,Math.min(e,t-1));function WV(e){let t=(0,_.useRef)(null);return n=>{let r=Date.now();VV(t.current,r)&&(t.current=r,e(n))}}function GV(){return(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`wide`,children:`Name`}),(0,X.jsx)(`th`,{children:`Value`}),(0,X.jsx)(`th`,{children:`Footprint`}),(0,X.jsx)(`th`,{className:`wide`,children:`Description`}),(0,X.jsx)(`th`,{children:`Verified`}),(0,X.jsx)(`th`,{className:`action`,"aria-label":`Verify`}),(0,X.jsx)(`th`,{className:`action`,"aria-label":`Place`})]})})}function KV({row:e,tabStop:t,onFocus:n,onPlace:r,onVerify:i,onKey:a}){return(0,X.jsxs)(`tr`,{tabIndex:t?0:-1,title:e.tooltip,onFocus:n,onDoubleClick:r,onKeyDown:a,children:[(0,X.jsx)(`td`,{className:`wide`,children:e.name}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:e.footprint}),(0,X.jsx)(`td`,{className:`wide`,children:e.description}),(0,X.jsx)(`td`,{children:e.verified&&(0,X.jsx)(`span`,{className:`badge ${e.verified===`Verified`?`verified`:`unverified`}`,title:e.verifiedTip,children:e.verified})}),(0,X.jsx)(`td`,{className:`action`,children:e.verified&&(0,X.jsx)(`button`,{className:`lib-place`,tabIndex:t?0:-1,onClick:i,onDoubleClick:e=>e.stopPropagation(),"aria-label":e.verified===`Verified`?`Look again at ${e.description}`:`Verify ${e.description}`,children:e.verified===`Verified`?`Look again`:`Verify…`})}),(0,X.jsx)(`td`,{className:`action`,children:(0,X.jsx)(`button`,{className:`lib-place`,tabIndex:-1,onClick:e=>HV(e.detail)&&r(),onDoubleClick:e=>e.stopPropagation(),"aria-label":`Place ${e.name}`,children:`Place`})})]})}function qV({parts:e,onPlace:t,onVerify:n}){let[r,i]=(0,_.useState)(``),a=(0,_.useRef)(null),[o,s]=(0,_.useState)(0),c=(0,_.useId)(),l=WV(t),u=(0,_.useMemo)(()=>zV(RV(e),r),[e,r]),d=UV(o,u.length),f=(e,t,n)=>{if(e.target!==e.currentTarget)return;let r=BV(e.key,t,u.length,e.repeat);r&&(e.preventDefault(),`place`in r?l(n):(a.current?.rows[r.move])?.focus())};return(0,X.jsxs)(`div`,{className:`lib-table`,children:[(0,X.jsx)(`input`,{className:`lib-table-search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:r,onChange:e=>i(e.target.value)}),(0,X.jsx)(`p`,{id:c,className:`lib-table-hint`,children:`Enter places the focused part; so does a double click on a row.`}),(0,X.jsxs)(`div`,{className:`lib-table-scroll hairline-t`,children:[(0,X.jsxs)(`table`,{"aria-label":`Library parts`,"aria-describedby":c,children:[(0,X.jsx)(GV,{}),(0,X.jsx)(`tbody`,{ref:a,children:u.map((e,t)=>(0,X.jsx)(KV,{row:e,tabStop:t===d,onFocus:()=>s(t),onPlace:()=>l(e.part),onVerify:()=>n(e.part,e.description),onKey:n=>f(n,t,e.part)},e.part))})]}),u.length===0&&(0,X.jsx)(`p`,{className:`note lib-table-empty`,children:`No parts match.`})]})]})}function JV(e){return(0,X.jsx)(`div`,{className:`bottom-panel hairline-t`,id:vm,role:`tabpanel`,"aria-labelledby":ym(e.tab),onClick:km,children:(0,X.jsx)(YV,{...e})})}function YV(e){switch(e.tab){case`library`:return(0,X.jsx)(qV,{parts:e.parts,onPlace:e.onPlace,onVerify:e.actions.openVerify});case`log`:return(0,X.jsx)(`div`,{className:`bottom-scroll`,children:(0,X.jsx)(kV,{history:e.history,problems:e.historyProblems,actions:e.actions,onShow:e=>void PV.show(e)})});case`drc`:return e.built?(0,X.jsx)(pV,{rows:e.rows,counts:e.counts,active:e.active,onPick:e.onPick}):(0,X.jsx)(`p`,{className:`note bottom-note`,children:e.buildError??`Building the circuit…`});case`find`:return(0,X.jsx)(_V,{...e.find})}}var XV={added:{colour:W.selectionBox,dash:[],label:`Added`},removed:{colour:W.warning,dash:[7,4],label:`Removed`},moved:{colour:W.document,dash:[2,3],label:`Moved`},dim:`rgb(0 0 0 / 55%)`,legendPanel:W.notePanel},ZV=3,QV=10,$V=4,eH={pad:8,row:18,sample:26,font:12,margin:10};function tH(e,t){e.save(),e.fillStyle=XV.dim,nH(e,0,0,t.width,t.height),e.fill(),e.restore()}function nH(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.lineTo(t+r,n+i),e.lineTo(t,n+i),e.closePath()}function rH(e,t,n,r){e.save(),e.strokeStyle=t.colour,e.lineWidth=n,e.lineCap=`butt`,e.lineJoin=`round`,e.setLineDash([...t.dash]),e.beginPath(),r(),e.stroke(),e.restore()}function iH(e,t,n,r){n.forEach((n,r)=>{let i=B(t.camera,t.size,n);r===0?e.moveTo(i.x,i.y):e.lineTo(i.x,i.y)}),r&&n.length>2&&e.closePath()}function aH(e){if(e.courtyard.length>2)return e.courtyard;let t=.5;return[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y-t},{x:e.x+t,y:e.y+t},{x:e.x-t,y:e.y+t}]}function oH(e,t,n,r){let i=XV[r];for(let a of n.parts[r])rH(e,i,ZV,()=>iH(e,t,aH(a),!0));for(let a of n.tracks[r])rH(e,i,Math.max(ZV,a.width*t.camera.scale),()=>iH(e,t,a.points,!1));for(let a of n.vias[r]){let n=B(t.camera,t.size,a.at);rH(e,i,ZV,()=>e.arc(n.x,n.y,Math.max($V,a.diameter/2*t.camera.scale),0,Math.PI*2))}for(let a of n.pours[r])a.outline&&rH(e,i,ZV,()=>iH(e,t,a.outline,!0));for(let a of n.board.holes[r]){let n=B(t.camera,t.size,a);rH(e,i,ZV,()=>e.arc(n.x,n.y,Math.max($V,a.diameter/2*t.camera.scale),0,Math.PI*2))}}function sH(e,t,n,r){let i=Math.atan2(n.y-t.y,n.x-t.x),a=e=>({x:n.x-QV*Math.cos(i+e),y:n.y-QV*Math.sin(i+e)});e.save(),e.strokeStyle=r,e.fillStyle=r,e.lineWidth=2,e.setLineDash([]),e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke();let[o,s]=[a(.45),a(-.45)];e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.lineTo(s.x,s.y),e.closePath(),e.fill(),e.restore()}function cH(e,t,n,r){let i=XV.moved;for(let a of n.parts.moved){if(rH(e,i,ZV,()=>iH(e,t,aH(a.from),!0)),r===`before`)continue;let n=B(t.camera,t.size,a.from),o=B(t.camera,t.size,a.to);Math.hypot(o.x-n.x,o.y-n.y)>QV&&sH(e,n,o,i.colour)}}function lH(e,t,n,r){r!==`after`&&oH(e,t,n,`removed`),r!==`before`&&oH(e,t,n,`added`),cH(e,t,n,r)}function uH(e,t,n=`both`){let r=[XV.added,XV.removed,XV.moved].filter(e=>n===`both`||e!==(n===`before`?XV.added:XV.removed));e.save(),e.font=Sa(xa.regular,eH.font),e.textAlign=`left`,e.textBaseline=`middle`;let i=Math.max(...r.map(t=>e.measureText(t.label).width)),a=eH.pad*3+eH.sample+i,o=eH.pad*2+eH.row*r.length,s=eH.margin,c=t.height-eH.margin-o;e.fillStyle=XV.legendPanel,nH(e,s,c,a,o),e.fill(),r.forEach((t,n)=>{let r=c+eH.pad+eH.row*n+eH.row/2,i=s+eH.pad;t===XV.moved?sH(e,{x:i,y:r},{x:i+eH.sample,y:r},t.colour):rH(e,t,ZV,()=>{e.moveTo(i,r),e.lineTo(i+eH.sample,r)}),e.fillStyle=t.colour,e.fillText(t.label,i+eH.sample+eH.pad,r)}),e.restore()}function dH({design:e,diff:t,mode:n,focus:r}){let i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=wO(i),{camera:s,setCamera:c}=EO(i,o,void 0),l=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{let t=xV(e,o);t&&c(t)},[e,n,o,c]),(0,_.useEffect)(()=>{r&&c(e=>e&&Ce(e,r.at))},[r,c]),(0,_.useEffect)(()=>{if(!s)return;let r=kO(a.current,o,s,W.background,()=>void 0);if(!r)return;let i=r.ctx,c={camera:s,size:o};Yf(i,e.pcb,c,{ratio:r.ratio,copper:{tracks:e.pcb.tracks,vias:e.pcb.vias,selected:new Set}}),tH(i,o),lH(i,c,t,n),uH(i,o,n)},[s,o,e,t,n]);let u=e=>TO(i.current,o,e);return(0,X.jsx)(`div`,{className:`change-canvas`,ref:i,onPointerDown:e=>{s&&(e.currentTarget.setPointerCapture(e.pointerId),l.current={start:u(e),camera:s})},onPointerMove:e=>{l.current&&c(Se(l.current.camera,l.current.start,u(e)))},onPointerUp:()=>l.current=void 0,onPointerCancel:()=>l.current=void 0,children:(0,X.jsx)(`canvas`,{ref:a,role:`img`,"aria-label":`The board with the change marked; it cannot be edited here`})})}var fH=[{mode:`before`,label:`Before`},{mode:`after`,label:`After`},{mode:`both`,label:`Both`}];function pH(e,t,n){let{at:r,items:i}=e;return i?(0,_.createElement)(`li`,{key:t},(0,_.createElement)(`details`,null,(0,_.createElement)(`summary`,null,e.text),(0,_.createElement)(`ul`,null,i.map((e,t)=>pH(e,t,n))))):r?(0,_.createElement)(`li`,{key:t},(0,_.createElement)(`button`,{type:`button`,className:`change-line`,title:`Centre the view on it`,onClick:()=>n(r)},e.text)):(0,_.createElement)(`li`,{key:t},e.text)}function mH({state:e,onMode:t,onLine:n,onClose:r}){let i=e.status===`ready`?e.data:void 0,a=`id`in e.request?`Change ${e.request.id}`:e.request.since===`c0000`?`Everything the agent did`:`Since ${e.request.since}`,o=i?.onBoard?(0,_.createElement)(`span`,{className:`change-modes`,role:`group`,"aria-label":`Show`},fH.map(({mode:n,label:r})=>(0,_.createElement)(`button`,{key:n,type:`button`,"aria-pressed":e.mode===n,onClick:()=>t(n)},r))):null;return(0,_.createElement)(`div`,{className:`change-bar`,role:`region`,"aria-label":`Change view`},(0,_.createElement)(`div`,{className:`change-head`},(0,_.createElement)(`strong`,{className:`change-title`},i?.title??a),o,(0,_.createElement)(`button`,{type:`button`,className:`change-close`,"aria-label":`Close the change view`,onClick:r},`Close`)),(0,_.createElement)(`p`,{className:`change-note`},yV),e.status===`loading`?(0,_.createElement)(`p`,{className:`change-note`},`Building the change…`):null,e.status===`failed`?(0,_.createElement)(`p`,{className:`change-error`,role:`alert`},e.error):null,i?(0,_.createElement)(`ul`,{className:`change-lines`},i.lines.map((e,t)=>pH(e,t,n))):null)}function hH({state:e}){let[t,n]=(0,_.useState)(void 0);(0,_.useEffect)(()=>{let e=e=>{SV(e.key)===`close`&&(e.preventDefault(),PV.close())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,_.useEffect)(()=>n(void 0),[e.request]);let r=e.status===`ready`?e.data:void 0,i=r?wV(r,e.mode):void 0;return(0,X.jsxs)(`div`,{className:`change-view`,children:[(0,X.jsx)(mH,{state:e,onMode:PV.setMode,onClose:PV.close,onLine:e=>n(t=>({at:e,seq:(t?.seq??0)+1}))}),r?.onBoard&&i&&r.diff&&(0,X.jsx)(dH,{design:i,diff:r.diff,mode:e.mode,...t?{focus:t}:{}}),r?.onBoard&&!i&&(0,X.jsx)(`p`,{className:`empty`,children:`The circuit does not build on this side of the change, so there is no board to draw.`})]})}var gH=String.raw`\d+(?:\.\d+)?`,_H=new RegExp(String.raw`^([a-z]*)(${gH})?(?:x(${gH}))?([a-z]*)$`),vH=/^\d+$/,yH=/^([a-z]+)(.*)$/,bH=new RegExp(String.raw`^(${gH})(?:mm)?x(${gH})(?:mm)?$`);function xH(e){let[t=``,...n]=e.trim().toLowerCase().split(`_`),r=_H.exec(t);if(!r||t===``)return;let[,i=``,a=``,o,s=``]=r,c=vH.test(n[0]??``)?n[0]:void 0,l=c===void 0?n:n.slice(1),u=l.filter(e=>bH.test(e));if(u.length>1)return;let d=wH(l.filter(e=>!bH.test(e)));if(!d)return;let f=u[0]===void 0?void 0:CH(u[0]);return{kind:i,code:a,...o===void 0?{}:{cross:o},...s===``?{}:{suffix:s},...c===void 0?{}:{variant:c},...f===void 0?{}:{size:f},params:d.params,...Object.keys(d.pairs).length===0?{}:{pairs:d.pairs}}}function SH(e){return e.cross===void 0&&e.suffix===void 0&&e.size===void 0&&e.pairs===void 0}function CH(e){let t=bH.exec(e);return t?[Number(t[1]),Number(t[2])]:void 0}function wH(e){let t={},n={};for(let r of e){let e=yH.exec(r);if(!e)return;let i=e[1]??``,a=e[2]??``;if(Object.hasOwn(t,i)||Object.hasOwn(n,i))return;let o=CH(a);if(o){n[i]=o;continue}let s=a===``||ei(a);if(s===void 0)return;t[i]=s}return{params:t,pairs:n}}var TH=(e,t,n,r)=>({packages:e,height:t,source:n,matches:r}),EH=e=>e.variant===void 0&&e.cross===void 0&&e.size===void 0,DH=(e,t)=>n=>n.kind===e&&n.code===t&&EH(n),OH=(...e)=>t=>e.some(e=>e(t)),kH=[TH(`chip 01005`,.2,`makers' 01005 chip resistor and capacitor series: about 0.2 mm thick`,e=>e.kind===``&&e.code===`01005`&&e.variant===void 0),TH(`chip 2220`,3.2,`makers' chip capacitor series: the thickest part commonly made in this size`,e=>e.kind===``&&e.code===`2220`&&e.variant===void 0)],AH=(e,t,n)=>TH(e,n,`makers' ${e} drawings: a flat-lead body up to about ${n} mm`,e=>e.kind===`sod`&&e.code===t&&e.suffix===void 0&&EH(e)),jH=[AH(`SOD-523`,`523`,.7),AH(`SOD-923`,`923`,.4),TH(`SOD-123F`,1.1,`makers' SOD-123F drawings: a flat-lead body up to about 1.1 mm`,e=>e.kind===`sod`&&e.code===`123`&&e.suffix===`f`&&EH(e)),AH(`SOD-128`,`128`,1.1)],MH=(e,t,n)=>TH(e,t,`a MELF cylinder lies on the board: as high as the body is wide, the largest diameter of the footprint outline (${t} mm), which is written from general knowledge of makers' drawings`,e=>EH(e)&&n.includes(`${e.kind}${e.code}${e.suffix??``}`)),NH=[MH(`MiniMELF (SOD-80, DO-213AA)`,1.6,[`minimelf`,`sod80`,`do213aa`]),MH(`MELF (DO-213AB)`,2.6,[`melf`,`do213ab`])],PH=`makers' small SOT drawings`,FH=[TH(`SOT-323, SOT-353, SOT-363 (SC-70)`,1.1,`${PH} (SC-70 family): A max about 1.1 mm`,OH(e=>e.kind===`sot`&&[`323`,`353`,`363`].includes(e.code)&&EH(e),e=>e.kind===`sc`&&e.code===`70`)),TH(`SOT-523, SC-89`,.8,`${PH}: A max about 0.8 mm`,DH(`sot`,`523`)),TH(`SOT-563`,.6,`${PH}: A max about 0.6 mm`,DH(`sot`,`563`)),TH(`SOT-723`,.55,`${PH}: A max about 0.55 mm`,DH(`sot`,`723`)),TH(`SOT-143`,1.1,`${PH}: A max about 1.1 mm`,DH(`sot`,`143`)),TH(`SOT-23-8`,1.45,`typical, as the five and six lead SOT-23 packages in this table (JEDEC MO-178 outline), not read for eight leads`,e=>e.kind===`sot`&&e.code===`23`&&e.variant===`8`)],IH=[TH(`MSOP (3 mm)`,1.1,`JEDEC MO-187 (MSOP), A max about 1.1 mm, typical`,e=>e.kind===`msop`),TH(`QSOP (150 mil)`,1.75,`JEDEC MO-137 (QSOP), A max about 1.75 mm, typical`,e=>e.kind===`qsop`),TH(`surface-mount DIP`,4.5,`makers' drawings of the gull-wing option of a 300 mil DIP: about 4.5 mm above the board, typical`,e=>e.kind===`smdip`),TH(`PLCC (MS-018)`,4.57,`JEDEC MS-018 (square PLCC), A max about 4.57 mm, typical`,e=>e.kind===`plcc`&&e.code!==`32`),TH(`PLCC-32 (MS-016)`,3.55,`JEDEC MS-016 (rectangular PLCC-32), A max about 3.55 mm, typical`,e=>e.kind===`plcc`&&e.code===`32`)],LH=`makers' drawings, A max about`,RH=[TH(`DPAK (TO-252)`,2.4,`${LH} 2.4 mm for DPAK (TO-252), typical`,OH(e=>e.kind===`dpak`&&e.code===``,e=>e.kind===`to`&&e.code===`252`)),TH(`D2PAK (TO-263), 3, 5 or 7 leads`,4.8,`${LH} 4.8 mm for D2PAK (TO-263), typical`,OH(e=>e.kind===`d`&&e.code===`2`&&e.suffix===`pak`,e=>e.kind===`to`&&e.code===`263`))],zH=`EIA case name: the last two digits of the case code are its height in tenths of a mm; the maker's tolerance was not read`,BH=(e,t,n)=>TH(`tantalum case ${e.toUpperCase()}`,n,`${zH} (${n} mm)`,n=>n.kind===`tant`&&(t===void 0?n.params[e]===!0:n.code===t)),VH=[BH(`a`,void 0,1.8),BH(`b`,void 0,2.1),BH(`c`,void 0,2.8),BH(`d`,void 0,3.1),BH(`e`,void 0,4.3),BH(`a`,`3216`,1.8),BH(`b`,`3528`,2.1),BH(`c`,`6032`,2.8),BH(`d`,`7343`,3.1)],HH=(e,t)=>TH(`chip resistor array ${e}`,t,`makers' chip resistor array series: about ${t} mm thick, typical`,t=>t.kind===`array`&&`${t.code}x${t.cross}`===e),UH=[HH(`4x0603`,.5),HH(`4x0402`,.35),HH(`2x0402`,.35)],WH=[{packages:`surface-mount aluminium can`,height:0,source:`the can height written in the footprint name (smdcan8x10.2 is 10.2 mm), the whole part above the board`,heightOf:e=>Number(e.cross),matches:e=>e.kind===`smdcan`&&e.cross!==void 0}],GH=(e,t)=>TH(`crystal ${e}`,t,`makers' surface-mount crystal and oscillator drawings of this size: about ${t} mm, typical`,t=>`${t.kind}${t.code}${t.variant===void 0?``:`_${t.variant}`}`===e&&t.suffix===void 0),KH=[GH(`xtal2016`,.5),GH(`xtal2520`,.6),GH(`xtal3225`,.8),GH(`xtal5032`,1.2),GH(`xtal5032_2`,1.2),GH(`xtal3215`,.9),GH(`xtal7050`,1.4),TH(`HC-49/US SMD crystal`,4.5,`crystal makers' HC-49/US SMD drawings: a can about 3.5 mm on a seat about 1 mm, typical`,e=>e.kind===`hc`&&e.code===`49`&&e.suffix===`smd`)],qH=(e,t)=>TH(`PLCC LED ${e}`,t,`LED makers' PLCC drawings of this size: about ${t} mm, typical`,t=>t.kind===`led`&&`${t.code}${t.variant===void 0?``:`_${t.variant}`}`===e),JH=[qH(`3528`,1.9),qH(`5050`,1.6),qH(`5050_6`,1.6)],YH=[...kH,...jH,...NH,...FH,...IH,...RH,...VH,...UH,...WH,...KH,...JH],XH=.3,ZH=[{upTo:3.7,diameter:1.8},{upTo:6.6,diameter:2.5},{upTo:9.1,diameter:3.5},{upTo:12.1,diameter:4.5},{upTo:1/0,diameter:5.5}];function QH(e){let t=e.params.d;if(typeof t==`number`&&t>0)return t;let n=Number(e.code);return(ZH.find(e=>n<=e.upTo)??ZH[ZH.length-1]).diameter}var $H=`makers' drawings of axial resistors and diodes lying on the board: the body's diameter (from the string, or by body length) and about ${XH} mm of gap under it`,eU=(e,t)=>`makers' ${e} drawings: maximum body diameter ${t} mm and about ${XH} mm of gap under it`,tU=(e,t,n,r)=>({packages:e,height:r+XH,source:eU(e,r),matches:e=>e.kind===`do`&&e.code===t&&e.suffix===n&&e.variant===void 0}),nU=(e,t,n)=>({packages:e,height:t,source:`makers' PCB screw terminal block drawings: about ${t} mm above the board at these pitches`,matches:e=>e.kind===`screw`&&n.includes(typeof e.params.p==`number`?e.params.p:rU)}),rU=5.08,iU=[[4,7],[5,11],[6.3,11],[8,11.5],[10,16],[12.5,20],[16,25],[18,35.5]],aU=`makers' drawings of general-purpose radial aluminium electrolytic series: the common can length for the diameter`,oU=`makers' drawings of general-purpose radial aluminium electrolytic series: this diameter is not listed, so the common can length of the nearest listed diameter`,sU=e=>Number(e.code),cU=e=>e.kind===`radial`&&Number.isFinite(sU(e))&&sU(e)>0,lU=e=>iU.some(([t])=>t===e);function uU(e){return iU.reduce((t,n)=>Math.abs(n[0]-e)<Math.abs(t[0]-e)?n:t)[1]}var dU=(e,t)=>`makers' ${e} mm pitch pin header drawings: about ${t} mm overall above the board`,fU=e=>{let t=e.params.p;return e.kind===`pinrow`&&typeof t==`number`&&t<2.54?t:void 0},pU=1.5,mU=[{packages:`radial can, a listed diameter`,height:0,heightOf:e=>uU(sU(e)),source:aU,matches:e=>cU(e)&&lU(sU(e))},{packages:`radial can, any other diameter`,height:0,heightOf:e=>uU(sU(e)),source:oU,matches:e=>cU(e)&&!lU(sU(e))},{packages:`pin header, 1.27 mm pitch`,height:4.6,source:dU(`1.27`,4.6),matches:e=>(fU(e)??1/0)<=pU},{packages:`pin header, 2 mm pitch`,height:6,source:dU(`2`,6),matches:e=>(fU(e)??0)>pU},{packages:`axial resistor or diode`,height:0,heightOf:e=>QH(e)+XH,source:$H,matches:e=>e.kind===`axial`&&e.code!==``},tU(`DO-35`,`35`,void 0,2),tU(`DO-41`,`41`,void 0,2.7),tU(`DO-15`,`15`,void 0,3.6),tU(`DO-201AD`,`201`,`ad`,5.3),{packages:`3 mm round LED`,height:5.5,source:`makers' 3 mm (T-1) round LED drawings: flange and lens seated on the board, about 5.5 mm`,matches:e=>e.kind===`led`&&e.suffix===`mm`&&e.code===`3`},{packages:`5 mm round LED`,height:8.7,source:`makers' 5 mm (T-1 3/4) round LED drawings: flange and lens seated on the board, about 8.7 mm`,matches:e=>e.kind===`led`&&e.suffix===`mm`&&e.code===`5`},nU(`screw terminal block, 5 and 5.08 mm pitch`,10,[5,5.08]),nU(`screw terminal block, 3.5 and 3.81 mm pitch`,8.5,[3.5,3.81]),{packages:`pin socket, 2.54 mm pitch`,height:8.5,source:`makers' drawings of 2.54 mm female headers: the common 8.5 mm height above the board`,matches:e=>e.kind===`socket`},{packages:`TO-247`,height:25.5,source:`makers' TO-247 drawings: about 4.5 mm of lead above the board under about 21 mm of body and tab`,matches:e=>e.kind===`to`&&e.code===`247`},{packages:`TO-126`,height:13.3,source:`makers' TO-126 (SOT-32) drawings: about 2.5 mm of lead above the board under about 10.8 mm of plastic body`,matches:e=>e.kind===`to`&&e.code===`126`}],hU=(e,t,n,r)=>({packages:e,height:t,source:n,matches:r}),gU=e=>e.variant===void 0&&e.suffix===void 0&&e.size===void 0,_U=[[4,2],[5,2.5],[6,3],[8,4],[10,5],[12,6]],vU=(e,t)=>hU(`shielded power inductor ${e}x${e}`,t,`makers' shielded power inductor ranges of ${e} × ${e} mm: about ${t} mm, typical`,t=>t.kind===`ind`&&t.code===String(e)&&t.cross===String(e)&&gU(t)),yU=[hU(`USB Type-B receptacle`,11,`makers' right-angle USB Type-B receptacle drawings: a shell about 11 mm high, typical`,e=>e.kind===`usb`&&e.params.b===!0),hU(`USB Type-C receptacle, 16 pins`,3.2,`makers' horizontal USB Type-C receptacle drawings: a shell about 3.2 mm high, typical`,e=>e.kind===`usb`&&e.params.c===16),hU(`DC barrel jack, 5.5 mm`,11,`makers' right-angle barrel jack drawings for a 5.5 mm plug: a body about 11 mm high, typical`,e=>e.kind===`dcjack`),hU(`tact switch 6 x 6, through-hole`,4.3,`makers' 6 × 6 mm tact switch drawings with the usual short button: about 4.3 mm, typical`,e=>e.kind===`tact`&&e.params.smd===void 0),hU(`tact switch 6 x 6, surface-mount`,4.3,`makers' 6 × 6 mm surface-mount tact switch drawings with the usual short button: about 4.3 mm, typical`,e=>e.kind===`tact`&&e.params.smd===!0),hU(`ceramic resonator 3.2 x 1.3`,.9,`makers' 3.2 × 1.3 mm three-terminal ceramic resonator drawings: about 0.9 mm, typical`,e=>e.kind===`resonator`&&e.code===`3213`),..._U.map(([e,t])=>vU(e,t))],bU=`EIA/IEC 60384-21 chip capacitor sizes: thickness up to the body width plus its tolerance (resistors are thinner)`,xU=(e,t)=>({packages:`chip ${e}`,height:t,source:bU,matches:t=>t.kind===``&&t.code===e&&t.variant===void 0}),SU=`makers' chip capacitor series: the thickest part commonly made in this size`,CU=`makers' power chip resistor series: thickness up to 0.7 mm in this size`,wU=(e,t,n)=>({packages:`chip ${e}`,height:t,source:n,matches:t=>t.kind===``&&t.code===e&&t.variant===void 0}),TU=(e,t,n)=>({packages:`${e.toUpperCase()} (DO-214${t.toUpperCase()})`,height:n,source:`makers' ${e.toUpperCase()} (DO-214${t.toUpperCase()}) drawings: body thickness up to ${n} mm`,matches:n=>n.variant===void 0&&(n.kind===e&&n.code===``||n.kind===`do`&&n.code===`214`&&n.suffix===t)}),EU=e=>e.params.p===void 0||e.params.p===2.54,DU=[xU(`0402`,.55),xU(`0603`,.9),xU(`0805`,1.45),xU(`1206`,1.8),xU(`0201`,.33),wU(`1210`,2.5,SU),wU(`1812`,3.2,SU),wU(`2010`,.7,CU),wU(`2512`,.7,CU),{packages:`SOIC (narrow)`,height:1.75,source:`JEDEC MS-012, A max 1.75 mm`,document:`NXP TJA1051 data sheet Rev. 9, p15, Fig 9, SOT96-1 (SO8, JEDEC MS-012): A max 1.75 mm`,matches:e=>e.kind===`soic`&&e.suffix===void 0},{packages:`SOIC (wide)`,height:2.65,source:`JEDEC MS-013, A max 2.65 mm`,document:`Microchip MCP2515 data sheet DS20001801J, p82, 18-lead SOIC 7.50 mm body (drawing C04-051C): A max 2.65 mm`,matches:e=>e.kind===`soic`&&e.suffix===`w`},{packages:`SOT-23 (3 leads)`,height:1.12,source:`JEDEC TO-236 AB, A max 1.12 mm`,matches:e=>e.kind===`sot`&&e.code===`23`&&e.variant===void 0},{packages:`SOT-23-5, SOT-23-6`,height:1.45,source:`JEDEC MO-178, A max 1.45 mm`,matches:e=>e.kind===`sot`&&e.code===`23`&&(e.variant===`5`||e.variant===`6`)},{packages:`SOT-223`,height:1.8,source:`makers' SOT-223 (TO-261AA) drawings, A max 1.8 mm`,matches:e=>e.kind===`sot`&&e.code===`223`&&e.variant===void 0},{packages:`SOT-89`,height:1.6,source:`makers' SOT-89 (TO-243AA) drawings, A max about 1.6 mm`,matches:e=>e.kind===`sot`&&e.code===`89`&&e.variant===void 0},{packages:`SOP (208 mil)`,height:2.2,source:`makers' 208 mil SOP drawings, A max about 2.2 mm`,matches:e=>e.kind===`sop`},{packages:`SSOP`,height:2,source:`JEDEC MO-150 (SSOP), A max 2.0 mm`,matches:e=>e.kind===`ssop`},{packages:`TSSOP`,height:1.2,source:`JEDEC MO-153 (TSSOP), A max 1.2 mm`,matches:e=>e.kind===`tssop`},{packages:`ball grid array`,height:1.4,source:`makers' fine-pitch BGA drawings: balls and body together, 1.0 to 1.6 mm`,matches:e=>e.kind===`bga`},{packages:`QFN`,height:1,source:`JEDEC MO-220, A max 1.00 mm`,matches:e=>e.kind===`qfn`},{packages:`DFN`,height:1,source:`JEDEC MO-229, A max 1.00 mm`,matches:e=>e.kind===`dfn`},{packages:`LQFP, QFP`,height:1.6,source:`JEDEC MS-026 (LQFP), A max 1.60 mm`,matches:e=>e.kind===`lqfp`||e.kind===`qfp`},{packages:`TQFP`,height:1.2,source:`JEDEC MS-026 (TQFP), A max 1.20 mm`,matches:e=>e.kind===`tqfp`},{packages:`SOD-123`,height:1.35,source:`makers' SOD-123 drawings (for example onsemi case 425), A max 1.35 mm`,matches:e=>e.kind===`sod`&&e.code===`123`&&e.suffix===void 0},{packages:`SOD-323`,height:1.1,source:`makers' SOD-323 drawings, A max about 1.1 mm`,matches:e=>e.kind===`sod`&&e.code===`323`&&(e.suffix===void 0||e.suffix===`f`)},TU(`sma`,`ac`,2.4),TU(`smb`,`aa`,2.4),TU(`smc`,`ab`,2.7),{packages:`plastic DIP`,height:5.1,source:`makers' plastic DIP drawings: the body seated about 0.5 mm off the board, up to 5.1 mm high`,matches:e=>e.kind===`dip`},{packages:`TO-220, upright`,height:20.5,source:`makers' TO-220AB drawings, seated against the leads' shoulders: about 4.5 mm of lead above the board under about 16 mm of body and tab`,matches:e=>e.kind===`to`&&e.code===`220`},{packages:`TO-92`,height:5.2,source:`makers' TO-92 drawings: the body up to 5.2 mm above the board`,matches:e=>e.kind===`to`&&e.code===`92`},{packages:`pin header, 2.54 mm pitch`,height:8.5,source:`makers' drawings of straight 2.54 mm headers: 2.5 mm insulator and 6 mm of pin above it`,matches:e=>e.kind===`pinrow`&&EU(e)},{packages:`HC-49/U crystal`,height:13.46,source:`crystal makers' HC-49/U drawings, height max 13.46 mm`,matches:e=>e.kind===`hc`&&e.code===`49`&&e.suffix===void 0},{packages:`HC-49/S crystal`,height:3.5,source:`crystal makers' HC-49/S (HC-49/US) drawings, height max 3.5 mm`,matches:e=>e.kind===`hc`&&e.code===`49`&&e.suffix===`s`},...mU,...YH,...yU];function OU(e){let t=ei(e.height);return t!==void 0&&t>0?t:void 0}function kU(e){let t=OU(e.props);if(t!==void 0)return{height:t,source:`given`,state:`given`,assumed:!1};let n=e.footprint===void 0||e.footprint.includes(`/`)?void 0:xH(e.footprint),r=n===void 0?void 0:DU.find(e=>e.matches(n));if(r===void 0)return{height:1,source:`assumed`,state:`assumed`,assumed:!0};let i=r.heightOf?.(n)??r.height;return r.document===void 0?{height:i,source:r.source,state:`typical`,assumed:!1}:{height:i,source:r.document,state:`read`,assumed:!1}}function AU(e){let t=e.pcb.board;return t?.thicknessGiven?t.thickness:e.rules?.fabrication?.boardThickness??1.6}var jU=.5;function MU(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=r.x*i.y-i.x*r.y}return t}function NU(e){let{from:t,to:n,centre:r,ccw:i}=e,a=Math.atan2(t.y-r.y,t.x-r.x),o=Math.atan2(n.y-r.y,n.x-r.x),s=i?o-a:a-o;for(;s<=1e-12;)s+=2*Math.PI;for(;s>2*Math.PI+1e-12;)s-=2*Math.PI;return i?s:-s}var PU=e=>e.map((t,n)=>({kind:`line`,from:t,to:e[(n+1)%e.length]}));function FU(e,t){let n={x:e.x+t,y:e.y},r={x:e.x-t,y:e.y};return[{kind:`arc`,from:n,to:r,centre:e,radius:t,ccw:!1},{kind:`arc`,from:r,to:n,centre:e,radius:t,ccw:!1}]}function IU(e,t){let n=Math.min(t.width,t.height)/2,r=Math.abs(t.width-t.height)/2,i=(e.rotation+(t.width>=t.height?0:90))*Math.PI/180,[a,o]=[Math.cos(i),Math.sin(i)],s=(t,n)=>({x:e.x+a*t-o*n,y:e.y+o*t+a*n}),[c,l]=[s(r,0),s(-r,0)];return[{kind:`line`,from:s(r,-n),to:s(-r,-n)},{kind:`arc`,from:s(-r,-n),to:s(-r,n),centre:l,radius:n,ccw:!1},{kind:`line`,from:s(-r,n),to:s(r,n)},{kind:`arc`,from:s(r,n),to:s(r,-n),centre:c,radius:n,ccw:!1}]}function LU(e){let t=e.drill;if(e.layers===`through`&&t!==void 0&&t.width>0&&t.height>0)return t.width===t.height?FU(e,t.width/2):IU(e,t)}function RU(e,t){let n=e.pcb.board;if(n===void 0||n.outline.length<3)return;let r=MU(n.outline)<0?[...n.outline].reverse():n.outline,i=e.pcb.parts.flatMap(e=>e.pads.flatMap(e=>{let t=LU(e);return t===void 0?[]:[t]})),a=e.pcb.holes.map(e=>FU(e,e.diameter/2));return{outline:PU(r),holes:[...a,...i],thickness:t}}function zU(e){if(e===void 0)return{minX:-.5,minY:-.5,maxX:jU,maxY:jU};let t=e.courtyard.length>=3?e.courtyard:e.pads.flatMap(BU);if(t.length===0)return zU(void 0);let n=t.map(e=>e.x),r=t.map(e=>e.y);return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}}function BU(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.cos(t),Math.sin(t)];return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([t,i])=>{let[a,o]=[t*e.width/2,i*e.height/2];return{x:e.x+a*n-o*r,y:e.y+a*r+o*n}})}function VU(e,t){let n=t.rotation*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],[a,o]=[e.x*r-e.y*i,e.x*i+e.y*r];return{x:t.x+(t.side===`bottom`?-a:a),y:t.y+o}}function HU(e,t,n,r){let{minX:i,minY:a,maxX:o,maxY:s}=zU(e.footprint),c=[{x:i,y:a},{x:o,y:a},{x:o,y:s},{x:i,y:s}].map(t=>VU(t,e)),l=MU(c)<0?[c[0],c[3],c[2],c[1]]:c,{height:u,source:d,state:f,assumed:p}=kU({...n===void 0?{}:{footprint:n},props:t}),[m,h]=e.side===`top`?[r,r+u]:[-u,0];return{name:e.component,side:e.side,corners:l,bottom:m,top:h,height:u,source:d,state:f,assumed:p}}function UU(e){let t=AU(e),n=RU(e,t),r=new Map(e.circuit.components.map(e=>[e.id,e])),i=e.pcb.parts.map(e=>{let n=r.get(e.component);return HU(e,n?.props??{},n?.footprint,t)});return{...n?{board:n}:{},parts:i}}var WU={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}},GU={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]}},KU={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]}},qU={lit:[184,180,156],shaded:[138,132,106]},JU=[70,62,46],YU=Object.keys(WU),XU=Object.keys(GU),ZU=Object.keys(KU),QU=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function $U(e={}){let t=e.mask??`green`;if(!(t in WU))throw Error(`mask must be one of ${YU.join(`, `)}`);let n=e.silk??(t===`white`?`black`:`white`);if(!(n in GU))throw Error(`silk must be one of ${XU.join(`, `)}`);let r=e.finish??`enig`;if(!(r in KU))throw Error(`finish must be one of ${ZU.join(`, `)}`);if(e.background===void 0)return{mask:t,silk:n,finish:r};let i=QU.exec(e.background);if(!i)throw Error(`background must be a colour written "#rrggbb"`);return{mask:t,silk:n,finish:r,background:[1,2,3].map(e=>parseInt(i[e],16))}}var eW=`Parts are simple shapes, not their real models; heights marked typical come from a package table, assumed ones are guesses.`,tW=e=>String(Math.round(e*100)/100),nW=(e,t)=>e.filter(e=>e.side===t).reduce((e,t)=>e===void 0||t.height>e.height?t:e,void 0);function rW(e){let t=e.board;if(!t)return`No board outline`;let n=t.outline.map(e=>e.from.x),r=t.outline.map(e=>e.from.y);return`Board ${tW(Math.max(...n)-Math.min(...n))} × ${tW(Math.max(...r)-Math.min(...r))} mm, ${tW(t.thickness)} mm thick`}function iW(e){let[t,n]=[nW(e.parts,`top`),nW(e.parts,`bottom`)],r=(e,t)=>`Tallest on ${e}: ${t?`${t.name}, ${tW(t.height)} mm${aW(t)}`:`none`}`,i=e.board?.thickness??0;return{board:rW(e),top:r(`top`,t),bottom:r(`bottom`,n),total:`Total height: ${tW(i+(t?.height??0)+(n?.height??0))} mm`,limits:eW}}var aW=e=>e.state===`typical`||e.state===`assumed`?`, ${e.state}`:``,oW=e=>`${e.name}, ${tW(e.height)} mm high${aW(e)} (${e.side})`;function sW({model:e}){let t=iW(e);return(0,_.createElement)(`ul`,{className:`look-readout`,"aria-label":`Sizes`},(0,_.createElement)(`li`,null,t.board),(0,_.createElement)(`li`,null,t.top),(0,_.createElement)(`li`,null,t.bottom),(0,_.createElement)(`li`,null,t.total),(0,_.createElement)(`li`,{className:`look-limits`},t.limits))}function cW({model:e,active:t,onActive:n}){return(0,_.createElement)(`ul`,{className:`look-parts`,"aria-label":`Parts`},e.parts.map((e,r)=>(0,_.createElement)(`li`,{key:e.name},(0,_.createElement)(`button`,{type:`button`,"aria-pressed":t===r,onFocus:()=>n(r),onBlur:()=>n(void 0),onMouseEnter:()=>n(r),onMouseLeave:()=>n(void 0)},oW(e)))))}function lW({look:e,onLook:t,ready:n}){let r=(e,n,r,i,a)=>(0,_.createElement)(`label`,null,e,` `,(0,_.createElement)(`select`,{value:n,onChange:e=>t(a(e.target.value))},r.map(e=>(0,_.createElement)(`option`,{key:e,value:e},i(e)))));return(0,_.createElement)(`div`,{className:`look-chooser`,role:`group`,"aria-label":`How the board is made`},r(`Mask`,e.mask??`green`,YU,e=>WU[e].name,t=>({...e,mask:t})),r(`Finish`,e.finish??`enig`,ZU,e=>KU[e].name,t=>({...e,finish:t})),r(`Print`,e.silk??(e.mask===`white`?`black`:`white`),XU,e=>GU[e].name,t=>({...e,silk:t})),(0,_.createElement)(`p`,{className:`look-note`,"aria-live":`polite`},n?`The board as made, drawn from its fabrication layers.`:`Drawing the board as made…`))}var uW={yaw:-30,pitch:35,zoom:1},dW={yaw:0,pitch:90,zoom:1},fW={yaw:0,pitch:-90,zoom:1},pW=.4,mW=.2,hW=20,gW=.85,_W=e=>Math.max(-90,Math.min(90,e)),vW=e=>Math.max(mW,Math.min(hW,e)),yW=e=>((e+180)%360+360)%360-180,bW=(e,t,n)=>({...e,yaw:yW(e.yaw+t),pitch:_W(e.pitch+n)}),xW=(e,t,n)=>bW(e,-t*pW,n*pW),SW=(e,t)=>({...e,zoom:vW(e.zoom*Math.exp(-t*.0015))});function CW(e,t){switch(t){case`ArrowLeft`:return bW(e,15,0);case`ArrowRight`:return bW(e,-15,0);case`ArrowUp`:return bW(e,0,15);case`ArrowDown`:return bW(e,0,-15);case`+`:case`=`:return SW(e,-200);case`-`:return SW(e,200);case`Home`:case`0`:return uW;case`t`:case`T`:return dW;case`b`:case`B`:return fW;default:return}}var wW=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],TW=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];function EW(e,t,n,r){let[i,a]=[e.yaw*Math.PI/180,e.pitch*Math.PI/180],o=[Math.cos(a)*Math.sin(i),-Math.cos(a)*Math.cos(i),Math.sin(a)],s=[Math.cos(i),Math.sin(i),0],c=TW(o,s),[l,u]=t.bounds,d=e.target??[(l[0]+u[0])/2,(l[1]+u[1])/2,(l[2]+u[2])/2],f=Math.hypot(u[0]-l[0],u[1]-l[1],u[2]-l[2])||1;return{eye:o,right:s,up:c,target:d,scale:Math.min(n,r)*gW/f*e.zoom,width:n,height:r}}var DW=e=>`top`in e?e:{top:e,side:e};function OW(e,t,n,r,i,a,o){if(!(n>t)||e.length<3)return[];let{top:s,side:c}=DW(r);return[{loops:[e.map(e=>[e.x,e.y,n])],normal:[0,0,1],color:s,material:i,role:a},...e.map((r,s)=>{let l=e[(s+1)%e.length],u=Math.hypot(l.x-r.x,l.y-r.y)||1;return{loops:[[[r.x,r.y,t],[l.x,l.y,t],[l.x,l.y,n],[r.x,r.y,n]]],normal:[(l.y-r.y)/u,-(l.x-r.x)/u,0],color:o?.(s)??c,material:i,role:a}})]}function kW(e,t,n,r,i){let a=PW(e),o=a[0]*t[0]+a[1]*t[1]+a[2]*t[2]<0;return{loops:[o?[...e].reverse():[...e]],normal:o?[-a[0],-a[1],-a[2]]:a,color:n,material:r,role:i}}function AW(e,t,n,r,i,a){return t>n?[{loops:[[...e].reverse().map(e=>[e.x,e.y,n])],normal:[0,0,-1],color:r,material:i,role:a},...OW(e,n,t,r,i,a).slice(1)]:[]}function jW(e,t,n,r,i,a){if(!(n>t)||e.length<3)return[];let{top:o,side:s}=DW(r),c=(e,t)=>[e,t.x,t.y];return[{loops:[e.map(e=>c(n,e))],normal:[1,0,0],color:o,material:i,role:a},{loops:[[...e].reverse().map(e=>c(t,e))],normal:[-1,0,0],color:o,material:i,role:a},...e.map((r,o)=>{let l=e[(o+1)%e.length],u=Math.hypot(l.x-r.x,l.y-r.y)||1;return{loops:[[c(t,r),c(t,l),c(n,l),c(n,r)]],normal:[0,(l.y-r.y)/u,-(l.x-r.x)/u],color:s,material:i,role:a}})]}var MW=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],NW=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]];function PW(e){let t=MW(NW(e[1],e[0]),NW(e[2],e[1])),n=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/n,t[1]/n,t[2]/n]}function FW(e,t,n,r,i,a,o){if(e.length<2||r<3)return[];let{top:s,side:c}=DW(i),l=(e,i,a)=>{let o=2*Math.PI*a/r;return[t+e*Math.cos(o),n+e*Math.sin(o),i]},u=e.slice(1).flatMap(([t,n],i)=>{let[s,u]=e[i];return Array.from({length:r},(e,r)=>{let i=[l(s,u,r),l(s,u,r+1),l(t,n,r+1),l(t,n,r)],d=i.filter((e,t)=>t===0||Math.hypot(e[0]-i[t-1][0],e[1]-i[t-1][1])>1e-12||e[2]!==i[t-1][2]);return d.length<3?[]:[{loops:[d],normal:PW(d),color:c,material:a,role:o}]}).flat()}),[d,f]=e[e.length-1];return[...d>0?[{loops:[Array.from({length:r},(e,t)=>l(d,f,t))],normal:[0,0,1],color:s,material:a,role:o}]:[],...u]}var IW=e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}],$=(e,t,n,r,i,a)=>e.maxX>e.minX&&e.maxY>e.minY?OW(IW(e),t,n,r,i,a):[],LW=(e,t,n,r=20)=>Array.from({length:r},(i,a)=>({x:e+n*Math.cos(2*Math.PI*a/r),y:t+n*Math.sin(2*Math.PI*a/r)}));function RW(e,t,n,r,i=10){let a=r/2,o=Math.max(0,n/2-a),s=(n,r)=>Array.from({length:i+1},(o,s)=>{let c=r+Math.PI*s/i;return{x:e+n+a*Math.cos(c),y:t+a*Math.sin(c)}});return[...s(o,-Math.PI/2),...s(-o,Math.PI/2)]}function zW(e,t){if(t===0)return[...e];let n=t*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],a=e=>[e[0]*r-e[1]*i,e[0]*i+e[1]*r,e[2]];return e.map(e=>({...e,loops:e.loops.map(e=>e.map(a)),normal:a(e.normal)}))}var BW=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),VW=(e,t)=>({minX:Math.max(e.minX,t.minX),minY:Math.max(e.minY,t.minY),maxX:Math.min(e.maxX,t.maxX),maxY:Math.min(e.maxY,t.maxY)}),HW=e=>e.length===0?void 0:{minX:Math.min(...e.map(e=>e.x)),minY:Math.min(...e.map(e=>e.y)),maxX:Math.max(...e.map(e=>e.x)),maxY:Math.max(...e.map(e=>e.y))};function UW(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.abs(Math.cos(t)),Math.abs(Math.sin(t))],[i,a]=[(e.width*n+e.height*r)/2,(e.width*r+e.height*n)/2];return{minX:e.x-i,minY:e.y-a,maxX:e.x+i,maxY:e.y+a}}var WW=e=>HW(e.flatMap(e=>{let t=UW(e);return[{x:t.minX,y:t.minY},{x:t.maxX,y:t.maxY}]})),GW=1.6;function KW(e,t=e.look.metal,n){return e.pads.flatMap(r=>{if(r.layers!==`through`||r.drill===void 0)return[];let i=Math.min(r.drill.width,r.drill.height)*.32;return AW(n?IW({minX:r.x-n.x,maxX:r.x+n.x,minY:r.y-n.y,maxY:r.y+n.y}):LW(r.x,r.y,i,8),0,-(e.thickness+GW),t,`metal`,`lead`)})}var qW=e=>e.find(e=>e.number===`1`)??e[0],JW=.94,YW=16,XW=5,ZW=[[122,66,30],[24,24,26],[190,40,36],[204,168,62]],QW=.09,$W=.3,eG=.17,tG=.8,nG=.14,rG=.4,iG=.06,aG=.4,oG=.6,sG=.9,cG=.9,lG=e=>e.body??e.limit,uG=.78,dG=.15,fG=e=>(e-1)*1.9+1+(e===4?tG:0);function pG(e,t,n,r,i){let a=t>=XW?4:3,o=Math.max($W,t*QW),s=[a,3,2,1].filter(e=>e<=a).find(e=>Math.min(o,t*uG/fG(e))>=dG);if(s===void 0)return[];let c=Math.min(o,t*uG/fG(s)),l=c*1.9,u=e+t*eG;return ZW.slice(0,s).flatMap((e,t)=>{let a=u+t*l+(t===3?c*tG:0);return jW(LW(n,r,i,YW),a,a+c,e,`matt`,`body`)})}function mG(e,t,n,r,i,a){let o=Math.min(Math.max(rG,t*nG),t*aG),s=e-t*iG;return jW(LW(n,r,i,YW),s-o,s,a,`matt`,`cathode`)}function hG(e,t,n,r,i,a){let[o,s]=[Math.min(r,t-a),Math.max(r,t+a)],{look:c}=e,l=$({minX:o,maxX:s,minY:n-a,maxY:n+a},i-a,i+a,c.metal,`metal`,`leg`),u=$({minX:t-a,maxX:t+a,minY:n-a,maxY:n+a},0,i+a,c.metal,`metal`,`leg`);return[...l,...u]}function gG(e){let t=lG(e),{look:n,lookName:r}=e,i=t.maxX-t.minX,a=(t.maxY-t.minY)/2,o=e.height-a,s=(t.minY+t.maxY)/2,c=[...jW(LW(s,o,a*JW,YW),t.minX,t.maxX,n.body,`matt`,`body`)];r===`axialResistor`&&c.push(...pG(t.minX,i,s,o,a)),(r===`axialDiode`||r===`axialGlass`)&&c.push(...mG(t.maxX,i,s,o,a,n.mark));for(let n of e.pads){if(n.layers!==`through`)continue;let r=Math.min(sG,(n.drill?.width??1)*oG,a*2*cG)/2;c.push(...hG(e,n.x,n.y,n.x<(t.minX+t.maxX)/2?t.minX:t.maxX,o,r))}return[...c,...KW(e)]}var _G=24,vG=5,yG=1,bG=.14,xG=.4,SG=.7,CG=.5,wG={x:.25,y:.25},TG=.4,EG=new Map([[`red`,[[214,48,44],[236,96,88]]],[`green`,[[46,184,84],[110,220,134]]],[`blue`,[[48,96,214],[110,150,240]]],[`yellow`,[[236,200,40],[250,226,100]]],[`white`,[[232,232,226],[248,248,244]]]]);function DG(e,t){let n=t?.color,r=typeof n==`string`?EG.get(n.trim().toLowerCase()):void 0;return r===void 0?e:{...e,body:r[0],top:r[1]}}var OG=e=>[0,1,2].map(t=>Math.round(e[t]+(255-e[t])*CG));function kG(e,t,n){return LW(0,0,e,_G).map(e=>({x:n===1?Math.min(e.x,t):Math.max(e.x,t),y:e.y}))}function AG(e){let t=e.body??e.limit,{look:n}=e,[r,i]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]],a=r!==void 0&&i!==void 0&&i.x<r.x?-1:1,o=(t.maxY-t.minY)/2,s=a===1?Math.min(t.maxX,o-TG):Math.max(t.minX,TG-o),c=e.height,l=Math.min(yG,c*bG),u=Math.max(o-xG,o*SG),d=c-u,f=kG(o,s,a),p=OW(f,0,l,OG(n.body),`matt`,`body`,e=>f[e]?.x===s&&f[(e+1)%f.length]?.x===s?n.mark:void 0).map(e=>Math.abs(e.normal[0])>.99&&e.normal[0]*a>0?{...e,role:`cathode`}:e),m=Array.from({length:vG},(e,t)=>{let n=Math.PI/2*((t+1)/vG);return t===4?[0,c]:[u*Math.cos(n),d+u*Math.sin(n)]}),h=FW([[u,l],[u,d],...m],0,0,_G,{top:n.top??n.body,side:n.body},`matt`,`body`);return[...p,...h,...KW(e,n.metal,wG)]}var jG=.6,MG=.04,NG=12,PG=.32,FG=.8,IG=.2,LG=.6,RG=.18,zG=.62,BG=.03,VG={x:.45,y:.45},HG=5.08,UG=.5;function WG(e){let t=[...e].sort((e,t)=>e-t),n=t.slice(1).map((e,n)=>e-t[n]).filter(e=>e>UG);return n.length===0?HG:Math.min(...n)}function GG(e,t,n,r,i,a){return kW([[e-n/2,t,r],[e+n/2,t,r],[e+n/2,t,i],[e-n/2,t,i]],[0,-1,0],a,`matt`,`body`)}function KG(e){let t=VW(e.body??BW(e.limit,-.15),e.limit),{look:n}=e,r=e.height,i=r-Math.min(jG,r*.1),a=WG(e.pads.map(e=>e.x)),o=a*PG,s=[...$({...t,minY:t.minY+BG},0,i,n.body,`matt`,`body`)];for(let c of e.pads){s.push(...FW([[o,i],[o,r-MG]],c.x,c.y,NG,n.metal,`metal`,`cap`));let e={minX:c.x-o*FG,maxX:c.x+o*FG,minY:c.y-IG,maxY:c.y+IG};s.push(...$(e,r-MG,r,n.mark,`matt`,`cap`)),s.push(GG(c.x,t.minY,a*LG,i*RG,i*zG,n.mark))}return[...s,...KW(e,n.metal,VG)]}var qG=2.54,JG=.75,YG=1.2,XG=.3,ZG=6,QG=(e,t,n,r)=>kW([[e[0],e[1],n],[t[0],e[1],n],[t[0],t[1],n],[e[0],t[1],n]],[0,0,1],r,`matt`,`body`);function $G(e,t,n,r,i){let a=JG,{look:o}=i,s=VW({minX:e-qG/2,maxX:e+qG/2,minY:t-qG/2,maxY:t+qG/2},i.limit),c=n-r,l=o.mark.map(e=>e+ZG),u=(e,t,r)=>kW([[e[0],e[1],c],[t[0],t[1],c],[t[0],t[1],n],[e[0],e[1],n]],r,l,`matt`,`body`);return[QG([s.minX,s.minY],[e-a,s.maxY],n,o.body),QG([e+a,s.minY],[s.maxX,s.maxY],n,o.body),QG([e-a,s.minY],[e+a,t-a],n,o.body),QG([e-a,t+a],[e+a,s.maxY],n,o.body),u([e-a,t-a],[e+a,t-a],[0,1,0]),u([e-a,t+a],[e+a,t+a],[0,-1,0]),u([e-a,t-a],[e-a,t+a],[1,0,0]),u([e+a,t-a],[e+a,t+a],[-1,0,0]),QG([e-a,t-a],[e+a,t+a],c,o.mark)]}function eK(e){if(WW(e.pads)===void 0)return[];let t=e.pads.map(e=>e.x),n=e.pads.map(e=>e.y),r=qG/2,i=VW({minX:Math.min(...t)-r,maxX:Math.max(...t)+r,minY:Math.min(...n)-r,maxY:Math.max(...n)+r},e.limit),a=e.height,o=Math.min(YG,a*XG),s=OW(IW(i),0,a,e.look.body,`matt`,`body`).slice(1),c=e.pads.flatMap(t=>$G(t.x,t.y,a,o,e));return[...s,...c,...KW(e)]}var tK=.22;function nK(e){let[t,n]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]];if(t===void 0||n===void 0)return[];let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i=-r*Math.PI/180,a=(e,t)=>e*Math.cos(i)-t*Math.sin(i),o=(e,t)=>e*Math.sin(i)+t*Math.cos(i),s={x:(t.x+n.x)/2,y:(t.y+n.y)/2},c=Math.hypot(n.x-t.x,n.y-t.y),l=UW(n),u=[[l.minX,l.minY],[l.maxX,l.maxY],[l.minX,l.maxY],[l.maxX,l.minY]].map(([e,t])=>({u:a(e-s.x,t-s.y),v:o(e-s.x,t-s.y)})),d=Math.max(...u.map(e=>e.u))-Math.min(...u.map(e=>e.u)),f=Math.max(...u.map(e=>e.v))-Math.min(...u.map(e=>e.v)),p=c+d*.3,m=Math.min(f*.92,p*.62),h=Math.max(p*tK,.1),g=e.height,_=p/2,v=(e,t,n)=>({minX:e,maxX:t,minY:-n/2,maxY:n/2}),{look:y}=e,b=g*.97,x=[...$(v(-_,-_+h,m*1.02),0,g,y.metal,`metal`,`cap`),...$(v(_-h,_,m*1.02),0,g,y.metal,`metal`,`cap`),...$(v(-_+h,_-h,m),.02,b,{top:y.top??y.body,side:y.body},`matt`,`body`)],S=(e,t)=>e!==void 0&&e.join()===t.join();return!S(y.body,y.mark)&&!S(y.top,y.mark)&&x.push(...$(v(_-h-m*.32,_-h-m*.12,m*.7),b-.01,g,y.mark,`matt`,`cathode`)),rK(zW(x,r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+s.x,e[1]+s.y,e[2]]))})),e.limit)}function rK(e,t){let n=VW({minX:-1/0,minY:-1/0,maxX:1/0,maxY:1/0},t),r=(e,t,n)=>Math.min(n,Math.max(t,e));return e.map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[r(e[0],n.minX,n.maxX),r(e[1],n.minY,n.maxY),e[2]]))}))}var iK=.15,aK=.08,oK=1.05;function sK(e){return{bottom:Math.min(aK,e*.3),top:e-Math.min(.02,e*.2)}}var cK=.1,lK=.04;function uK(e){let t=UW(e),[n,r]=[t.maxX-t.minX,t.maxY-t.minY];return(Math.abs(n-r)<=cK*Math.max(n,r)?Math.abs(e.x)>Math.abs(e.y):n>=r)?e.x>=0?`right`:`left`:e.y>=0?`top`:`bottom`}function dK(e){let t=e.body;if(t===void 0)return e.pads;let n=e=>e.x>t.minX&&e.x<t.maxX&&e.y>t.minY&&e.y<t.maxY;return e.pads.filter(e=>!n(e))}function fK(e,t=.02){let n=dK(e).map(e=>({pad:e,side:uK(e),r:UW(e)})),r=e=>n.filter(t=>t.side===e),i=WW(dK(e))??e.limit,a=(e,n)=>{let i=r(e);return i.length===0?n:e===`right`?Math.min(...i.map(e=>e.r.minX))-t:e===`left`?Math.max(...i.map(e=>e.r.maxX))+t:e===`top`?Math.min(...i.map(e=>e.r.minY))-t:Math.max(...i.map(e=>e.r.maxY))+t},o=.45,s={minX:a(`left`,i.minX-o),maxX:a(`right`,i.maxX+o),minY:a(`bottom`,i.minY-o),maxY:a(`top`,i.maxY+o)},c={minX:r(`left`).length===0?Math.max(s.minX,i.minX-o):s.minX,maxX:r(`right`).length===0?Math.min(s.maxX,i.maxX+o):s.maxX,minY:r(`bottom`).length===0?Math.max(s.minY,i.minY-o):s.minY,maxY:r(`top`).length===0?Math.min(s.maxY,i.maxY+o):s.maxY};return VW(e.body?VW(e.body,c):c,e.limit)}function pK(e,t,n,r,i,a){let o=UW(e),s=t===`left`||t===`right`,c=t===`right`||t===`top`?1:-1,l=t===`right`?n.maxX:t===`left`?n.minX:t===`top`?n.maxY:n.minY,u=s?e.x:e.y,d=s?o.maxX-o.minX:o.maxY-o.minY,f=s?o.maxY-o.minY:o.maxX-o.minX,p=a??Math.min(f*.72,.5),m=s?e.y:e.x,h=c*(u-l);if(h<=.05)return[];let g=l+c*Math.min(h*.38,.6),_=u+c*Math.min(d*.3,Math.abs(d/2)-.02),v=Math.min(iK,r/3),y=Math.min(Math.max(r*.38,v*1.5),r-v*1.5,oK),b=(e,t,n,r)=>{let[a,o]=[Math.min(e,t),Math.max(e,t)];return $(s?{minX:a,maxX:o,minY:m-p/2,maxY:m+p/2}:{minY:a,maxY:o,minX:m-p/2,maxX:m+p/2},n,r,i,`metal`,`leg`)};return[...b(l,g+c*v,y,y+v),...b(g,g+c*v,v,y),...b(g,_,0,v)]}function mK(e,t,n,r=1/0){let i=qW(e.pads);if(i===void 0)return[];let a=Math.min(t.maxX-t.minX,t.maxY-t.minY),o=Math.min(a*.12,.4),s=o+Math.min(a*.08,r);return OW(LW(i.x<(t.minX+t.maxX)/2?t.minX+s:t.maxX-s,i.y<(t.minY+t.maxY)/2?t.minY+s:t.maxY-s,o,12),n-.01,e.height,e.look.mark,`matt`,`pin1`)}function hK(e){let t=fK(e),n=e.height,{bottom:r,top:i}=sK(n),{look:a}=e,o=[...$(t,r,i,a.body,`matt`,`body`)],s=dK(e);for(let e of s)o.push(...pK(e,uK(e),t,n,a.metal));for(let n of e.pads.filter(e=>!s.includes(e)))o.push(...$(VW(UW(n),t),0,Math.min(lK,r),a.metal,`metal`,`cap`));return o.push(...mK(e,t,i)),rK(o,e.limit)}var gK=1.3,_K=.8,vK=.3,yK=.25,bK=.3,xK=.4,SK=.06,CK=64,wK=400,TK=.1,EK=e=>Math.min(UW(e).maxX-UW(e).minX,UW(e).maxY-UW(e).minY);function DK(e,t,n,r,i){let a=t/2;return r<=CK?FW([[a*.55,0],[a,n*.5],[a*.6,n]],e.x,e.y,8,i,`metal`,`pin`):OW(LW(e.x,e.y,a*.85,r<=wK?6:4),0,n,i,`metal`,`pin`)}function OK(e){let t=WW(e.pads),n=VW(e.body??BW(t??e.limit,.3),e.limit),{look:r}=e,i=e.height,a=Math.min(...e.pads.map(EK),1/0),o=Number.isFinite(a)?a*gK:.4,s=Math.min(o*_K,i*vK),c=Math.min(yK,(i-s)*bK),l=Math.min(n.maxX-n.minX,n.maxY-n.minY),u=BW(n,-Math.min(xK,l*SK)),d=i-.02,f=r.top??r.body;return[...e.pads.flatMap(t=>DK(t,o,s,e.pads.length,r.metal)),...$(n,s,s+c,f,`matt`,`body`),...$(u,s+c,d,r.body,`matt`,`body`),...mK(e,u,d,TK)]}function kK(e){let t=VW(e.body??BW(e.limit,-.15),e.limit),{look:n}=e;return[...rK($(t,0,e.height,{top:n.top??n.body,side:n.body},`matt`,`body`),e.limit),...KW(e)]}function AK(e){return $(e.limit,0,e.height,e.look.body,`matt`,`body`)}var jK=.15;function MK(e){let[t,n]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]];if(t===void 0||n===void 0)return KW(e);let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i={x:(t.x+n.x)/2,y:(t.y+n.y)/2},a=Math.abs(Math.sin(r*Math.PI/180))>.7,o=e.body??e.limit,s=(a?o.maxY-o.minY:o.maxX-o.minX)-2*jK,c=(a?o.maxX-o.minX:o.maxY-o.minY)-2*jK,l=Math.min(c,s*.6),u=e.height,{look:d}=e,f=Math.min(.5,u*.1);return[...rK(zW([...OW(RW(0,0,s,l),0,f,d.body,`metal`,`body`),...OW(RW(0,0,s-.3,l-.3),f,u,d.body,`metal`,`body`)],r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+i.x,e[1]+i.y,e[2]]))})),e.limit),...KW(e)]}var NK=24;function PK(e){let t=e.limit,n=Math.min(t.maxX-t.minX,t.maxY-t.minY)/2-jK,r=(t.minX+t.maxX)/2,i=(t.minY+t.maxY)/2,a=e.pads.find(e=>e.number===`2`),o=a===void 0?0:Math.atan2(a.y-i,a.x-r),s=e.height,{look:c}=e,l=Math.min(.4,s*.05);return[...rK([...OW(LW(r,i,n,NK),0,s-l,{top:c.top??c.body,side:c.body},`matt`,`body`,e=>{let t=2*Math.PI*(e+.5)/NK;return Math.abs(Math.atan2(Math.sin(t-o),Math.cos(t-o)))<Math.PI/6?c.mark:void 0}),...OW(LW(r,i,n*.9,NK),s-l,s,c.top??c.metal,`metal`,`body`)],e.limit),...KW(e)]}var FK=[196,198,200],IK={melf:{sentence:`MELF diode: a dark glass cylinder lying on the board between two tinned end caps, a pale band at the cathode.`,body:[54,42,40],metal:FK,mark:[214,208,190]},tantalum:{sentence:`Tantalum capacitor: an amber moulded block with a darker stripe across the top at the plus end, tinned terminals wrapped over its ends.`,body:[204,140,56],metal:FK,mark:[112,70,28]},array:{sentence:`Resistor array: one pale ceramic body under a near-black coat with a small tinned terminal over each pad.`,body:[206,202,190],top:[34,34,38],metal:FK,mark:[34,34,38]},smdcan:{sentence:`Surface-mount aluminium capacitor: a black plastic base with two clipped corners under a round aluminium can, a dark segment on the lid at the minus side.`,body:[28,28,32],top:[200,204,210],metal:[186,190,196],mark:[34,36,42]},xtal:{sentence:`Surface-mount crystal: a ceramic base under a smaller metal lid with a dot at pin 1, tinned terminals at the pads.`,body:[212,196,162],top:[186,190,196],metal:FK,mark:[60,60,66]},xtalCan:{sentence:`HC-49 SMD crystal: a metal can with rounded ends on a low dark seat, a flat tinned lead to each pad.`,body:[188,190,194],top:[204,206,210],metal:FK,mark:[38,38,42]},ledsmd:{sentence:`Surface-mount LED: a white body with a round pale lens on top and a clipped corner at pad 1 (the two-pad one a green bar at the cathode), tinned terminals.`,body:[238,238,230],top:[250,240,196],metal:FK,mark:[64,168,92]},plcc:{sentence:`PLCC chip: a near-black body with a clipped corner and a dot at pin 1 and a tinned J-lead on every pad.`,body:[34,34,38],metal:FK,mark:[150,150,156]}};function LK(e){return e.kind===`minimelf`||e.kind===`melf`||e.kind===`sod`&&e.code===`80`||e.kind===`do`&&e.code===`213`?{family:`melf`,look:`melf`}:e.kind===`tant`?{family:`tantalum`,look:`tantalum`}:e.kind===`array`?{family:`array`,look:`array`}:e.kind===`smdcan`?{family:`smdcan`,look:`smdcan`}:e.kind===`xtal`?{family:`xtal`,look:`xtal`}:e.kind===`hc`&&e.code===`49`&&e.suffix===`smd`?{family:`xtal`,look:`xtalCan`}:e.kind===`led`&&(e.code===`3528`||e.code===`5050`)?{family:`ledsmd`,look:`ledsmd`}:e.kind===`plcc`?{family:`plcc`,look:`plcc`}:e.kind===`dpak`&&e.code===``||e.kind===`to`&&(e.code===`252`||e.code===`263`)||e.kind===`d`&&e.code===`2`&&e.suffix===`pak`?{family:`tab`,look:`tab`}:void 0}var RK=[196,198,200],zK={usbb:{sentence:`USB Type-B receptacle: a tinned metal shell open at the mating face with a dark opening and a pale plastic tongue inside, two shell legs and four pins through their holes.`,body:[226,222,204],metal:RK,mark:[14,14,18]},usbc:{sentence:`USB Type-C receptacle: a low tinned metal shell with rounded ends, a dark stadium opening at the mating face with a thin pale tongue, shell legs through their slots and a row of terminals on the pads at the back.`,body:[226,222,204],metal:RK,mark:[18,18,22]},dcjack:{sentence:`Barrel jack: a black plastic body with a round opening on the mating face and a metal pin in its middle, flat terminals through the slots.`,body:[32,32,35],metal:RK,mark:[8,8,10]},tact:{sentence:`Tact switch, 6 × 6 mm: a low black base under a tinned metal cover plate with a round black button standing out of its middle, pins through the holes or gull-wing terminals on the pads.`,body:[30,30,34],top:[62,62,68],metal:RK,mark:[30,30,34]},resonator:{sentence:`Ceramic resonator: a small pale ceramic body under a tinned metal cap over most of its top, a terminal on each of its three pads.`,body:[226,212,172],metal:RK,mark:[226,212,172]},inductor:{sentence:`Shielded power inductor: a dark grey ferrite block with clipped corners and a slightly lighter top with a small mark, a tinned terminal at each pad.`,body:[58,60,64],top:[86,88,94],metal:RK,mark:[178,180,184]}};function BK(e){if(e.kind===`usb`)return e.params.b===!0?`usbb`:e.params.c===16?`usbc`:void 0;if(e.kind===`dcjack`)return`dcjack`;if(e.kind===`tact`)return`tact`;if(e.kind===`resonator`)return`resonator`;if(e.kind===`ind`)return`inductor`}var VK=[196,198,200],HK=[214,176,86],UK={resistor:{sentence:`Chip resistor: a pale ceramic body under a near-black coat, between two tinned end caps.`,body:[216,214,204],top:[34,34,36],metal:VK,mark:[34,34,36]},capacitor:{sentence:`Chip capacitor: a tan ceramic body between two tinned end caps.`,body:[176,138,92],metal:VK,mark:[176,138,92]},led:{sentence:`Chip LED: a white body under a pale yellow lens, a green mark at the cathode.`,body:[234,234,226],top:[244,232,168],metal:VK,mark:[64,168,92]},chip:{sentence:`Any other chip part: a grey-brown body between two tinned end caps.`,body:[120,112,100],metal:VK,mark:[120,112,100]},molded:{sentence:`Moulded diode: a near-black body, a light grey band at the cathode, flat tinned leads.`,body:[44,44,46],metal:VK,mark:[200,200,194]},gullwing:{sentence:`Gull-wing chip: a near-black moulded body with a pin 1 dot, tinned legs bent down to the pads.`,body:[40,40,43],metal:VK,mark:[96,96,100]},leadless:{sentence:`Leadless chip: a near-black body with a pin 1 dot, tinned terminals at its edges.`,body:[40,40,43],metal:VK,mark:[96,96,100]},bga:{sentence:`Ball grid array: a tan substrate on a ball of tin under every pad, a dark mould cap on it and a pin 1 dot.`,body:[36,36,40],top:[150,128,78],metal:VK,mark:[196,196,190]},dip:{sentence:`Dual in-line package: a near-black body raised off the board with a notch and dot at pin 1, flat tinned legs down through the holes.`,body:[34,34,38],metal:VK,mark:[150,150,156]},to220:{sentence:`TO-220: a metal tab with its hole at the back of a near-black plastic body, flat tinned leads (two, three or five) down into the board; the TO-247 is bigger, the TO-126 all plastic with a hole.`,body:[30,30,33],metal:[176,180,186],mark:[30,30,33]},to92:{sentence:`TO-92: a near-black body with a flat front and a round back, raised on three tinned leads.`,body:[34,34,36],metal:VK,mark:[34,34,36]},tab:{sentence:`Power SOT with a tab: a near-black body with a pin 1 dot, tinned legs on the narrow pads and one wide flat tab on the wide pad.`,body:[40,40,43],metal:VK,mark:[96,96,100]},axialResistor:{sentence:`Axial resistor: a beige body lying above the board with three or four coloured bands (fixed colours, not the value's code), a wire from each end bent down through its hole.`,body:[214,188,142],metal:VK,mark:[214,188,142]},axialDiode:{sentence:`Axial diode: a near-black body with a pale band at the cathode end, a wire from each end bent down through its hole.`,body:[38,38,40],metal:VK,mark:[208,208,200]},axialGlass:{sentence:`Glass diode: an orange glass body with a dark band at the cathode end, a wire from each end bent down through its hole.`,body:[214,122,44],metal:VK,mark:[34,30,28]},axialPlain:{sentence:`Any other axial part: a plain grey body lying above the board, a wire from each end bent down through its hole.`,body:[122,126,132],metal:VK,mark:[122,126,132]},ledlens:{sentence:`Round LED: a flange ring on the board with a flat at the cathode, a translucent-looking lens (red unless the part says another colour) with a domed top, two tinned leads.`,body:[214,48,44],top:[236,96,88],metal:VK,mark:[244,240,232]},screw:{sentence:`Screw terminal block: a green block with a slotted round screw head on top and a dark wire opening on the front of every pole, a tinned pin through each hole.`,body:[44,128,78],metal:VK,mark:[16,18,18]},socket:{sentence:`Pin socket: a black body with a dark square opening over every pin and a gold pin through each hole.`,body:[26,26,28],metal:HK,mark:[8,8,10]},header:{sentence:`Pin header: a black plastic base with a gold pin on every pad.`,body:[28,28,30],metal:HK,mark:[28,28,30]},crystal:{sentence:`Crystal: a plain metal can with rounded ends.`,body:[188,190,194],metal:VK,mark:[188,190,194]},electrolytic:{sentence:`Electrolytic capacitor: a dark blue sleeve with a pale stripe at the minus lead, a metal lid.`,body:[38,52,98],top:[182,186,192],metal:VK,mark:[198,204,214]},relay:{sentence:`Relay: a mid-blue box with its leads.`,body:[46,86,156],top:[58,100,170],metal:VK,mark:[46,86,156]},terminal:{sentence:`Connector at another pitch, such as a terminal block: a green box with its leads.`,body:[44,128,78],metal:VK,mark:[44,128,78]},block:{sentence:`Any other through-hole part: a dark grey box with its leads.`,body:[72,74,78],metal:VK,mark:[72,74,78]},...IK,...zK,box:{sentence:`Anything else: a plain box, as before shapes were drawn.`,body:[96,138,118],metal:VK,mark:[96,138,118]}},WK=new Set([`0201`,`0402`,`0603`,`0805`,`1206`,`1210`,`1812`,`2010`,`2512`,`01005`,`2220`]),GK=new Set([`soic`,`sot`,`sop`,`ssop`,`tssop`,`msop`,`qsop`,`smdip`,`qfp`,`lqfp`,`tqfp`,`sc`]),KK=new Set([`qfn`,`dfn`,`son`,`wson`,`vson`]),qK=new Set([`223`,`89`]),JK=new Set([`sod`,`sma`,`smb`,`smc`,`do`]),YK=e=>e===void 0||e.includes(`/`)||e.endsWith(`.yaml`)?void 0:xH(e);function XK(e){return e===`resistor`?`resistor`:e===`capacitor`?`capacitor`:e===`led`?`led`:`chip`}var ZK=new Set([`220`,`247`,`126`]),QK=new Set([`35`,`41`,`15`,`201`]);function $K(e,t){return t.kind===`do`?t.code===`35`?`axialGlass`:`axialDiode`:e===`resistor`?`axialResistor`:e===`diode`?`axialDiode`:`axialPlain`}function eq(e){let t=/^[A-Za-z]+/.exec(e)?.[0]?.toUpperCase()??``;return t===`K`?`relay`:t===`J`||t===`P`||t===`X`||t===`CN`?`terminal`:`block`}function tq(e,t,n=!1,r=``){let i=YK(t),a=(e,t)=>({family:e,look:t,...i?{parsed:i}:{}});if(i!==void 0){if(i.kind===``&&WK.has(i.code))return a(`chip`,XK(e));if(i.kind===`bga`)return a(`bga`,`bga`);if(i.kind===`dip`)return a(`dip`,`dip`);if(i.kind===`to`&&ZK.has(i.code))return a(`to220`,`to220`);if(i.kind===`axial`||i.kind===`do`&&QK.has(i.code))return a(`axial`,$K(e,i));if(i.kind===`led`&&i.suffix===`mm`)return a(`ledth`,`ledlens`);if(i.kind===`screw`)return a(`screw`,`screw`);if(i.kind===`socket`)return a(`socket`,`socket`);if(i.kind===`to`&&i.code===`92`)return a(`to92`,`to92`);let t=BK(i);if(t!==void 0)return a(t,t);let n=LK(i);if(n!==void 0)return a(n.family,n.look);if(i.kind===`sot`&&qK.has(i.code)&&i.variant===void 0)return a(`tab`,`tab`);if(JK.has(i.kind))return a(`molded`,`molded`);if(GK.has(i.kind))return a(`gullwing`,`gullwing`);if(KK.has(i.kind))return a(`leadless`,`leadless`);if(i.kind===`pinrow`&&(i.params.p===void 0||i.params.p===2.54||typeof i.params.p==`number`&&i.params.p<2.54))return a(`header`,`header`);if(i.kind===`hc`&&i.code===`49`)return a(`crystal`,`crystal`);if(i.kind===`radial`)return a(`electrolytic`,`electrolytic`);if(i.kind===`pinrow`)return a(`block`,eq(r||`J`))}return n?a(`block`,eq(r)):a(`box`,`box`)}var nq=.5,rq=.25,iq=.5,aq=.3,oq=.9,sq=.18,cq=8;function lq(e,t,n){let r=(e.minX+e.maxX)/2,i=t===1?e.maxY:e.minY;return Array.from({length:9},(e,a)=>{let o=a/cq*Math.PI+(t===1?Math.PI:0);return{x:r+n*Math.cos(o),y:i+n*Math.sin(o)}})}function uq(e,t,n,r){let i=e.x>=(t.minX+t.maxX)/2?1:-1,a=i===1?t.maxX:t.minX,o={minY:e.y-iq/2,maxY:e.y+iq/2},s=e.x+rq/2*i,[c,l]=[Math.min(a,s),Math.max(a,s)],u=$({minX:c,maxX:l,...o},n,n+rq,r,`metal`,`leg`),d=$({minX:e.x-rq/2,maxX:e.x+rq/2,...o},0,n+rq,r,`metal`,`leg`);return[...u,...d]}function dq(e){let t=VW(e.body??BW(e.limit,-.3),e.limit),{look:n}=e,r=e.height,i=r-.02,a=nq+(i-nq)*aq,o=[...$(t,nq,i,n.body,`matt`,`body`)];for(let r of e.pads)r.layers===`through`&&o.push(...uq(r,t,a,n.metal));let s=qW(e.pads),c=s!==void 0&&s.y<(t.minY+t.maxY)/2?-1:1,l=Math.min(oq,(t.maxX-t.minX)*sq);return o.push(...OW(lq(t,c,l),i-.01,r,n.mark,`matt`,`pin1`)),o.push(...mK(e,t,i)),[...o,...KW(e,n.metal,{x:rq/2,y:iq/2})]}var fq=2.54,pq=2.5,mq=.64,hq=e=>{let t=e.parsed?.params.p;return typeof t==`number`&&t>0?t:fq};function gq(e){if(WW(e.pads)===void 0)return[];let t=e.pads.map(e=>e.x),n=e.pads.map(e=>e.y),r=hq(e),i=Math.min(1,r/fq),[a,o]=[pq*i,mq*i],s=r/2,c=VW({minX:Math.min(...t)-s,maxX:Math.max(...t)+s,minY:Math.min(...n)-s,maxY:Math.max(...n)+s},e.limit),l=e.height,{look:u}=e,d=Math.min(a,l*.4),f=[...$(c,0,d,u.body,`matt`,`body`)];for(let t of e.pads){let n={minX:t.x-o/2,maxX:t.x+o/2,minY:t.y-o/2,maxY:t.y+o/2};f.push(...$(n,d,l,u.metal,`metal`,`pin`)),f.push(...AW(IW(n),0,-(e.thickness+GW),u.metal,`metal`,`lead`))}return rK(f.filter(e=>e.role!==`lead`),e.limit).concat(f.filter(e=>e.role===`lead`))}var _q=.2;function vq(e){let t=e.pads.reduce((e,t)=>{let n=UW(t);return{minX:Math.min(e.minX,n.minX),minY:Math.min(e.minY,n.minY),maxX:Math.max(e.maxX,n.maxX),maxY:Math.max(e.maxY,n.maxY)}},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}),n=VW(e.body??(Number.isFinite(t.minX)?BW(t,-.05):fK(e)),e.limit),r=e.height,i=r-.02,{look:a}=e,o=[...$(n,_q*.5,i,a.body,`matt`,`body`)];for(let t of e.pads)o.push(...$(VW(UW(t),BW(n,.01)),0,_q,a.metal,`metal`,`leg`));let s=qW(e.pads);if(s!==void 0){let e=Math.min(n.maxX-n.minX,n.maxY-n.minY),t=Math.min(e*.1,.35),c=t+e*.1,l=s.x<(n.minX+n.maxX)/2?n.minX+c:n.maxX-c,u=s.y<(n.minY+n.maxY)/2?n.minY+c:n.maxY-c;o.push(...OW(LW(l,u,t,12),i-.01,r,a.mark,`matt`,`pin1`))}return rK(o,e.limit)}var yq=.12;function bq(e){let t=e.pads.find(e=>e.number===`1`)??e.pads[0],n=e.pads.find(e=>e.number===`2`)??e.pads[1];if(t===void 0||n===void 0)return[];let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i={x:(t.x+n.x)/2,y:(t.y+n.y)/2},a=Math.hypot(n.x-t.x,n.y-t.y),o=UW(n),s=Math.abs(Math.sin(r*Math.PI/180))>.7,c=s?o.maxX-o.minX:o.maxY-o.minY,l=s?o.maxY-o.minY:o.maxX-o.minX,u=e.body?s?e.body.maxY-e.body.minY:e.body.maxX-e.body.minX:a-l*.2,d=e.body?s?e.body.maxX-e.body.minX:e.body.maxY-e.body.minY:c*1.4,f=Math.min(u,a+l*.6),p=d,m=e.height,h=m*.97,g=(e,t,n)=>({minX:e,maxX:t,minY:-n/2,maxY:n/2}),{look:_}=e,v=Math.min(c*.6,p*.6),y=Math.max(f*.16,.2);return rK(zW([...$(g(-a/2-l*.3,-f/2+.05,v),0,yq,_.metal,`metal`,`leg`),...$(g(f/2-.05,a/2+l*.3,v),0,yq,_.metal,`metal`,`leg`),...$(g(-f/2,f/2,p),.04,h,_.body,`matt`,`body`),...$(g(f/2-y*1.9,f/2-y*.9,p*.96),h-.01,m,_.mark,`matt`,`cathode`)],r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+i.x,e[1]+i.y,e[2]]))})),e.limit)}function xq(e){let[t,n]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]];if(t===void 0||n===void 0)return;let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i=Math.abs(Math.sin(r*Math.PI/180))>.7,a=UW(n),o=Math.hypot(n.x-t.x,n.y-t.y),s=i?a.maxY-a.minY:a.maxX-a.minX,c=i?a.maxX-a.minX:a.maxY-a.minY,l=e.body?i?e.body.maxY-e.body.minY:e.body.maxX-e.body.minX:o+s*.3,u=e.body?i?e.body.maxX-e.body.minX:e.body.maxY-e.body.minY:c;return{angle:r,mid:{x:(t.x+n.x)/2,y:(t.y+n.y)/2},gap:o,padAlong:s,padAcross:c,bodyAlong:l,bodyAcross:u}}function Sq(e,t,n){return rK(zW(e,t.angle).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+t.mid.x,e[1]+t.mid.y,e[2]]))})),n.limit)}function Cq(e,t){let[n,r]=[(e.x-(t.minX+t.maxX)/2)/((t.maxX-t.minX)/2||1),(e.y-(t.minY+t.maxY)/2)/((t.maxY-t.minY)/2||1)];return Math.abs(r)>=Math.abs(n)?r>=0?`top`:`bottom`:n>=0?`right`:`left`}function wq(e,t,n,r,i){let a={minX:t.minX-i,maxX:t.maxX+i,minY:t.minY-i,maxY:t.maxY+i},o={left:{...a,minX:t.minX-i,maxX:t.minX+r},right:{...a,minX:t.maxX-r,maxX:t.maxX+i},bottom:{...a,minY:t.minY-i,maxY:t.minY+r},top:{...a,minY:t.maxY-r,maxY:t.maxY+i}}[n];return VW(UW(e),o)}function Tq(e,t,n,r){let i=Cq(e,t),a=wq(e,t,i,n.inside,n.outside),o=n.across===void 0?a:Eq(a,i,n.across);return $(o.maxX>o.minX&&o.maxY>o.minY?o:UW(e),0,n.height,r,`metal`,n.role??`cap`)}function Eq(e,t,n){let r=t===`left`||t===`right`,[i,a]=r?[(e.minY+e.maxY)/2,e.maxY-e.minY]:[(e.minX+e.maxX)/2,e.maxX-e.minX],o=Math.min(a,n)/2;return r?{...e,minY:i-o,maxY:i+o}:{...e,minX:i-o,maxX:i+o}}function Dq(e,t,n,r,i){let a=UW(e),o=t===`left`||t===`right`,s=t===`right`||t===`top`?1:-1,c=t===`right`?n.maxX:t===`left`?n.minX:t===`top`?n.maxY:n.minY,[l,u,d,f]=o?[a.minX,a.maxX,a.maxY-a.minY,e.y]:[a.minY,a.maxY,a.maxX-a.minX,e.x],p=s>0?u-c:c-l,m=s>0?l-c:c-u,h=Math.min(r.reach,p-r.toe);if(h<r.thick)return[];let g=Math.min(d,r.across)/2,_=(e,t,n,r)=>{let[a,l]=[Math.min(c+s*e,c+s*t),Math.max(c+s*e,c+s*t)];return $(o?{minX:a,maxX:l,minY:f-g,maxY:f+g}:{minY:a,maxY:l,minX:f-g,maxX:f+g},n,r,i,`metal`,`leg`)},v=r.thick;return[..._(Math.max(-r.tuck,m),h,0,v),..._(h-r.thick,h,v,r.rise-v),..._(0,h,r.rise-v,r.rise)]}function Oq(e,t,n,r){let i=[{x:e.minX,y:e.minY,sx:-1,sy:-1},{x:e.maxX,y:e.minY,sx:1,sy:-1},{x:e.maxX,y:e.maxY,sx:1,sy:1},{x:e.minX,y:e.maxY,sx:-1,sy:1}];return i.flatMap((e,a)=>{if(e.sx!==t||e.sy!==n)return[{x:e.x,y:e.y}];let[o,s]=[i[(a+3)%4],i[(a+1)%4]],c=t=>({x:e.x+Math.sign(t.x-e.x)*r,y:e.y+Math.sign(t.y-e.y)*r});return[c(o),c(s)]})}var kq=.03,Aq=.12,jq=.1,Mq=.7;function Nq(e){let t=WW(e.pads),n=VW(e.body??(t?BW(t,-.1):e.limit),e.limit),r=e.height,{look:i}=e,a=sK(r),o=[...$(n,Math.min(kq,a.bottom),a.top,{top:i.top??i.body,side:i.body},`matt`,`body`)];for(let t of e.pads)o.push(...Tq(t,n,{inside:Aq,outside:jq,height:r*Mq},i.metal));return rK(o,e.limit)}var Pq=.04,Fq=.78,Iq=.36,Lq=16,Rq=4,zq=Math.PI/3,Bq=.12,Vq=.25,Hq=.2,Uq=.3;function Wq(e,t,n,r,i,a){return FW(Array.from({length:5},(e,t)=>{let a=zq*t/Rq;return[n*Math.cos(a),r+(i-r)*Math.sin(a)/Math.sin(zq)]}),e,t,Lq,a,`matt`,`body`)}function Gq(e){let t=WW(e.pads),n=VW(e.body??(t?BW(t,-.1):e.limit),e.limit),[r,i]=[n.maxX-n.minX,n.maxY-n.minY],a=e.height,o=a*Fq,{look:s}=e,c=qW(e.pads),l=e.pads.length>=4&&c!==void 0?Oq(n,c.x<0?-1:1,c.y<0?-1:1,Math.min(r,i)*Bq):void 0,u=[...OW(l??[{x:n.minX,y:n.minY},{x:n.maxX,y:n.minY},{x:n.maxX,y:n.maxY},{x:n.minX,y:n.maxY}],Math.min(Pq,o/3),o,s.body,`matt`,`body`),...Wq((n.minX+n.maxX)/2,(n.minY+n.maxY)/2,Math.min(r,i)*Iq,o,a,s.top??s.body)];if(l===void 0){let t=e.pads.find(e=>e.number===`2`);if(t!==void 0){let e=t.x>=(n.minX+n.maxX)/2?1:-1,c=e>0?n.maxX:n.minX;u.push(...$({minX:Math.min(c-e*r*.06,c-e*r*.16),maxX:Math.max(c-e*r*.06,c-e*r*.16),minY:n.minY+i*.15,maxY:n.maxY-i*.15},o,Math.min(o+.02,a),s.mark,`matt`,`cathode`))}}for(let t of e.pads)u.push(...Tq(t,n,{inside:Vq,outside:Hq,height:Math.min(Uq,o/2)},s.metal));return rK(u,e.limit)}var Kq=16,qq=.14,Jq=.3,Yq=.93,Xq=.96,Zq=.95;function Qq(e,t){return Array.from({length:Kq},(n,r)=>({x:e*Math.cos(2*Math.PI*r/Kq),y:t+e*Math.sin(2*Math.PI*r/Kq)}))}function $q(e){let t=xq(e);if(t===void 0)return[];let n=Math.abs(Math.sin(t.angle*Math.PI/180))>.7?Math.min(e.limit.maxX-t.mid.x,t.mid.x-e.limit.minX):Math.min(e.limit.maxY-t.mid.y,t.mid.y-e.limit.minY),r=Math.min(e.height/2,n*Zq),i=t.bodyAlong/2,a=Math.max(t.bodyAlong*qq,Jq),o=Math.max(t.bodyAlong*.14,.3),{look:s}=e;return Sq([...jW(Qq(r,r),-i,-i+a,s.metal,`metal`,`cap`),...jW(Qq(r,r),i-a,i,s.metal,`metal`,`cap`),...jW(Qq(r*Yq,r),-i+a,i-a,s.body,`matt`,`body`),...jW(Qq(r*Xq,r),i-a-o,i-a,s.mark,`matt`,`cathode`)],t,e)}var eJ=.5,tJ=.2,nJ=.3,rJ=1.5,iJ=.9,aJ=.3,oJ=1.2,sJ=.5,cJ=1.3;function lJ(e){let t=e.body??fK(e),n=e.height,{top:r}=sK(n),i=Math.min(eJ,n*.2),a=Math.min(tJ,n*.1),{look:o}=e,s=Math.min(n*nJ,rJ),c=[...OW(Oq(t,-1,1,oJ),i,r,o.body,`matt`,`body`)];for(let n of e.pads)c.push(...Dq(n,Cq(n,t),t,{reach:.6,toe:aJ,thick:a,rise:s,tuck:iJ,across:.5},o.metal));let l=qW(e.pads);return l!==void 0&&c.push(...OW(LW(l.x,t.maxY-cJ,sJ,14),r-.01,n,o.mark,`matt`,`pin1`)),rK(c,e.limit)}var uJ=.12,dJ=.15,fJ=.8,pJ=1.2,mJ=.4,hJ=.35,gJ=3,_J=.02,vJ=28,yJ=.45,bJ=.92,xJ=.12,SJ=.6,CJ=.8;function wJ(e,t){let n=e.outlines?.[0];if(n===void 0||n.length<4)return[{x:t.minX,y:t.minY},{x:t.maxX,y:t.minY},{x:t.maxX,y:t.maxY},{x:t.minX,y:t.maxY}];let[r,i]=[n[0],n[n.length-1]];return r.x===i.x&&r.y===i.y?n.slice(0,-1):n}function TJ(e,t){let n=e.outlines?.find((e,t)=>t>0&&e.length>16),r=n===void 0?void 0:HW(n);return r===void 0?Math.min(t.maxX-t.minX,t.maxY-t.minY)/2-.15:(r.maxX-r.minX)/2}function EJ(e,t){let n=Math.acos(Math.min(1,t/e));return Array.from({length:9},(t,r)=>({x:e*Math.cos(-n+2*n*r/8),y:e*Math.sin(-n+2*n*r/8)}))}function DJ(e){let t=VW(e.body??BW(WW(e.pads)??e.limit,-.1),e.limit),n=e.height,{look:r}=e,i=Math.min(pJ,Math.max(fJ,n*dJ),n*mJ),a=Math.min(uJ,i/3),o=TJ(e,t),s=n-Math.min(_J,n*.1),c=Math.min(hJ,(s-i)/2,o/2),l=o-c,u=Array.from({length:4},(e,t)=>{let n=Math.PI/2*(t/gJ);return[l+c*Math.cos(n),s-c+c*Math.sin(n)]}),d=[[o,i],...u],f=EJ(l*bJ,l*bJ*yJ),p=[...OW(wJ(e,t),a,i,r.body,`matt`,`body`),...FW(d,0,0,vJ,{top:r.top??r.metal,side:r.metal},`metal`,`body`),...OW(f,s,n,r.mark,`matt`,`cathode`)],m=Math.min(xJ,a),h=(a+i)/2+m/2;for(let n of e.pads)p.push(...Dq(n,Cq(n,t),t,{reach:SJ,toe:.1,thick:m,rise:h,tuck:CJ,across:1.4},r.metal));return rK(p,e.limit)}var OJ=.62,kJ=.12,AJ=.8,jJ=.16,MJ=.3;function NJ(e){let t=xq(e);if(t===void 0)return[];let[n,r]=[t.bodyAlong/2,t.bodyAcross/2],i=e.height,{bottom:a,top:o}=sK(i),{look:s}=e,c=(e,t,n)=>({minX:e,maxX:t,minY:-n,maxY:n}),l=Math.max(t.bodyAlong*jJ,MJ),u=Math.min(r,t.padAcross/2)*.9;return Sq([...$(c(-n,n,r),a,o,s.body,`matt`,`body`),...$(c(-n+l*.5,-n+l*1.5,r),o,i,s.mark,`matt`,`pin1`),...$(c(-n-kJ,-n+AJ,u),0,i*OJ,s.metal,`metal`,`cap`),...$(c(n-AJ,n+kJ,u),0,i*OJ,s.metal,`metal`,`cap`)],t,e)}var PJ=.04,FJ=.3,IJ=.08,LJ=.24,RJ=.15,zJ=.25;function BJ(e,t){let n=e.height,{look:r}=e,i=Math.min(t.maxX-t.minX,t.maxY-t.minY),a=BW(t,-Math.min(i*IJ,.2)),o=n*.6,s=[...$(t,Math.min(PJ,o/2),o,r.body,`matt`,`body`),...$(a,o,sK(n).top,r.top??r.metal,`metal`,`body`),...mK(e,a,sK(n).top)];for(let n of e.pads)s.push(...Tq(n,t,{inside:.3,outside:.1,height:Math.min(FJ,o*.8)},r.metal));return s}function VJ(e,t){let n=e.height,{look:r}=e,[i,a]=[t.maxX-t.minX,t.maxY-t.minY],o=Math.min(Math.max(n*LJ,.6),n/2),s=Math.min(RJ,o/3),c=[...$(BW(t,-.15),s,o,r.mark,`matt`,`body`),...OW(RW((t.minX+t.maxX)/2,(t.minY+t.maxY)/2,i-2*zJ,a-2*zJ),o,n,{top:r.top??r.body,side:r.body},`metal`,`body`)];for(let t of e.pads)c.push(...$(VW(BW(UW(t),-.1),e.limit),0,s,r.metal,`metal`,`leg`));return c}function HJ(e){let t=VW(e.body??BW(e.limit,-.25),e.limit);return rK(e.parsed?.kind===`hc`?VJ(e,t):BJ(e,t),e.limit)}var UJ={melf:$q,tantalum:NJ,array:Nq,smdcan:DJ,xtal:HJ,ledsmd:Gq,plcc:lJ},WJ=e=>e.reduce((e,t)=>e+t,0)/(e.length||1);function GJ(e,t,n,r,i,a,o=`out`){if(!(n>t)||e.length<3)return[];let[s,c]=[WJ(e.map(e=>e.x)),WJ(e.map(e=>e.y))],l=o===`out`?1:-1;return e.map((o,u)=>{let d=e[(u+1)%e.length],f=[l*((o.x+d.x)/2-s),0,l*((o.y+d.y)/2-c)];return kW([[o.x,t,o.y],[d.x,t,d.y],[d.x,n,d.y],[o.x,n,o.y]],f,r,i,a)})}var KJ=(e,t,n,r,i,a)=>kW(e.map(e=>[e.x,t,e.y]),[0,n,0],r,i,a);function qJ(e,t,n,r,i,a,o){return e.length===t.length?e.map((s,c)=>{let l=(c+1)%e.length,[u,d,f]=[e[l],t[c],t[l]];return kW([[s.x,n,s.y],[u.x,n,u.y],[f.x,n,f.y],[d.x,n,d.y]],[0,r,0],i,a,o)}):[]}var JJ=(e,t,n,r,i,a,o,s,c)=>t>e&&r>n?[kW([[e,i,n],[t,i,n],[t,i,r],[e,i,r]],[0,a,0],o,s,c)]:[];function YJ(e,t,n,r,i,a,o,s){if(!(n>t)||!(e.maxX>e.minX)||!(i>r))return[];let c=(e,t,n,r,i,c)=>kW([[e,n,i],[t,n,i],[t,r,i],[e,r,i]],[0,0,c],a,o,s),l=(e,c)=>kW([[e,t,r],[e,n,r],[e,n,i],[e,t,i]],[c,0,0],a,o,s);return[c(e.minX,e.maxX,t,n,i,1),c(e.minX,e.maxX,t,n,r,-1),l(e.minX,-1),l(e.maxX,1),...JJ(e.minX,e.maxX,r,i,t,-1,a,o,s)]}var XJ=.8;function ZJ(e,t,n,r){return e.pads.filter(t).flatMap(t=>{let i=r??{x:(t.drill?.width??.6)*XJ/2,y:(t.drill?.height??.6)*XJ/2};return KW({...e,pads:[t]},n,i)})}var QJ=.12;function $J(e,t,n,r,i=`leg`){let a=UW(e),o=e.x>=(t.minX+t.maxX)/2?1:-1,s=o>0?t.maxX:t.minX,c=o>0?a.maxX:a.minX,l=Math.min(n.reach,Math.abs(c-s));if(l<n.thick)return[];let u=Math.min(a.maxY-a.minY,n.across)/2,[d,f]=[s-o*QJ,s+o*l],p=(t,n)=>({minX:Math.min(t,n),maxX:Math.max(t,n),minY:e.y-u,maxY:e.y+u}),m=$(p(d,f),0,n.thick,r,`metal`,i),h=$(p(s,s+o*n.thick),n.thick,n.rise,r,`metal`,i);return[...m,...h]}var eY=16,tY=12,nY=3.2,rY=.36,iY=.3,aY=9,oY=.62,sY=.31,cY=6.5,lY=.72,uY=3,dY=.3;function fY(e,t,n,r,i,a,o,s){let c=Array.from({length:eY},(e,t)=>[i+o*Math.cos(2*Math.PI*t/eY),n,a+o*Math.sin(2*Math.PI*t/eY)]);return{loops:[[[e,n,0],[t,n,0],[t,n,r],[e,n,r]],[...c].reverse()],normal:[0,-1,0],color:s,material:`matt`,role:`body`}}function pY(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,i=(t.minX+t.maxX)/2,a=Math.min(nY,(t.maxX-t.minX)*rY,r*iY),o=t.minY+Math.min(aY,(t.maxY-t.minY)*oY),s=LW(i,r/2,a,eY),c=LW(i,r/2,a*sY,tY),l=o-Math.min(cY,(o-t.minY)*lY),u=[...OW(IW(t),0,r,n.body,`matt`,`body`).filter(e=>e.normal[1]>-.99),fY(t.minX,t.maxX,t.minY,r,i,r/2,a,n.body),...GJ(s,t.minY,o,n.mark,`matt`,`body`,`in`),KJ(s,o,-1,n.mark,`matt`,`body`),...GJ(c,l,o,n.metal,`metal`,`pin`),KJ(c,l,-1,n.metal,`metal`,`pin`)];for(let i of e.pads){let e={x:(i.drill?.width??.6)*.8/2,y:(i.drill?.height??.6)*.8/2},[a,o]=[i.x-e.x,i.x+e.x];o>t.maxX&&u.push(...$({minX:t.maxX,maxX:o,minY:i.y-e.y,maxY:i.y+e.y},0,Math.min(uY,r*dY),n.metal,`metal`,`leg`)),a<t.minX&&u.push(...$({minX:a,maxX:t.minX,minY:i.y-e.y,maxY:i.y+e.y},0,Math.min(uY,r*dY),n.metal,`metal`,`leg`))}return[...u,...ZJ(e,()=>!0,n.metal)]}var mY=.08,hY=.05,gY=.04,_Y=.03,vY=.1,yY=.8,bY=.05,xY=.18,SY=.22,CY=12,wY=.15,TY=.2,EY=.9,DY=.5,OY=.8,kY=3;function AY(e,t){return[{x:e.minX+t,y:e.minY},{x:e.maxX-t,y:e.minY},{x:e.maxX,y:e.minY+t},{x:e.maxX,y:e.maxY-t},{x:e.maxX-t,y:e.maxY},{x:e.minX+t,y:e.maxY},{x:e.minX,y:e.maxY-t},{x:e.minX,y:e.minY+t}]}function jY(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,i=Math.min(t.maxX-t.minX,t.maxY-t.minY),a=Math.min(gY,r*_Y),o=qW(e.pads),s=o===void 0||o.x<=(t.minX+t.maxX)/2,c=i*SY,l=LW(s?t.minX+c:t.maxX-c,t.maxY-c,Math.max(i*bY,xY),CY),u={reach:kY,thick:Math.min(wY,r*TY),rise:Math.min(EY,r*DY),across:i*OY},d=[...OW(AY(t,Math.min(i*vY,yY)),Math.min(mY,r*hY),r-a,{top:n.top??n.body,side:n.body},`matt`,`body`),...OW(l,r-a,r,n.mark,`matt`,`pin1`)];for(let r of e.pads)d.push(...$J(r,t,u,n.metal));return d}var MY=.04,NY=.05,PY=.62,FY=.1,IY=.1,LY=.18,RY=.05,zY=.12,BY=.45,VY=.8;function HY(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,i=Math.min(t.maxX-t.minX,t.maxY-t.minY),a=r*PY,o=BW(t,-Math.min(FY,i*IY)),s=[...$(t,Math.min(MY,r*NY),a,n.body,`matt`,`body`),...$(o,a,r,n.metal,`metal`,`cap`)];for(let r of e.pads){let e=UW(r),i={minX:Math.max(e.minX,r.x-LY),maxX:Math.min(e.maxX,r.x+LY)},o=Math.min(BY,a*VY),c={...i,minY:Math.max(e.minY,t.maxY-RY),maxY:Math.min(e.maxY,t.maxY+zY)},l={...i,minY:Math.max(e.minY,t.minY-zY),maxY:Math.min(e.maxY,t.minY+RY)};s.push(...$(c,0,o,n.metal,`metal`,`leg`),...$(l,0,o,n.metal,`metal`,`leg`))}return s}var UY=.7,WY=.3,GY=.07,KY=.25,qY=.04,JY=1.7,YY=.28,XY=16,ZY={x:.25,y:.25},QY={reach:.5,thick:.15,rise:.6,across:.9},$Y={reach:1.2,thick:.15,rise:1,across:.9},eX=.1,tX=.6;function nX(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,i=Math.min(t.maxX-t.minX,t.maxY-t.minY),a=r*UY,o=a+Math.min(WY,r*GY),s=BW(t,-Math.min(KY,i*qY)),[c,l]=[(t.minX+t.maxX)/2,(t.minY+t.maxY)/2],u=OW(LW(c,l,Math.min(JY,i*YY),XY),o,r,{top:n.top??n.body,side:n.body},`matt`,`pin`),d=e.parsed?.params.smd===!0,f=d?$Y:QY,p={...f,thick:Math.min(f.thick,r*eX),rise:Math.min(f.rise,a*tX)},m=[...$(t,0,a,n.body,`matt`,`body`),...$(s,a,o,n.metal,`metal`,`cap`),...u];for(let r of e.pads)m.push(...$J(r,t,p,n.metal));return d?m:[...m,...KW(e,n.metal,ZY)]}var rX={across:8.4,up:7.8},iX=.7,aX=.72,oX=9,sX=.55,cX={across:6.2,length:6,thick:1.5},lX=.74,uX=.7,dX=.2,fX=1.5,pX={x:.2,y:.9};function mX(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,i=(t.minX+t.maxX)/2,[a,o]=[Math.min(rX.across,(t.maxX-t.minX)*iX),Math.min(rX.up,r*aX)],[s,c,l,u]=[i-a/2,i+a/2,(r-o)/2,(r+o)/2],d=t.minY+Math.min(oX,(t.maxY-t.minY)*sX),f=[{x:s,y:l},{x:c,y:l},{x:c,y:u},{x:s,y:u}],p={minX:i-Math.min(cX.across,a*lX)/2,maxX:i+Math.min(cX.across,a*lX)/2},m=Math.min(cX.thick,o*dX),h=OW(IW(t),0,r,n.metal,`metal`,`body`).filter(e=>e.normal[1]>-.99),g=[...JJ(t.minX,s,0,r,t.minY,-1,n.metal,`metal`,`body`),...JJ(c,t.maxX,0,r,t.minY,-1,n.metal,`metal`,`body`),...JJ(s,c,0,l,t.minY,-1,n.metal,`metal`,`body`),...JJ(s,c,u,r,t.minY,-1,n.metal,`metal`,`body`)],_=[...GJ(f,t.minY,d,n.mark,`matt`,`body`,`in`),KJ(f,d,-1,n.mark,`matt`,`body`)],v=YJ(p,d-Math.min(cX.length,(d-t.minY)*uX),d,(r-m)/2,(r+m)/2,n.body,`matt`,`body`),y=KW({...e,pads:e.pads.filter(e=>(e.drill?.width??0)<=fX)},n.metal);return[...h,...g,..._,...v,...y,...ZJ(e,e=>(e.drill?.width??0)>fX,n.metal,pX)]}var hX=8,gX=.9,_X=.35,vX=.12,yX=.15,bX=.1,xX=1.6,SX=.22,CX=5,wX=.4,TX={length:4.6,shorter:.6,thick:.6},EX=.28,DX=.45,OX=.5,kX=1.6,AX=.5;function jX(e){let t=VW(e.body??BW(e.limit,-.25),e.limit),{look:n}=e,r=e.height,[i,a]=[(t.minX+t.maxX)/2,t.maxX-t.minX],o=Math.min(_X,r*vX),s=Math.min(yX,r*bX),c=t.maxY-Math.min(xX,(t.maxY-t.minY)*SX),l=Math.min(t.minY+CX,c-wX),u=Math.min(r,a*gX),d=RW(i,r/2,a,u,hX),f=RW(i,r/2,a-2*o,u-2*o,hX),p=RW(i,r/2,a-2*s,u-2*s,hX),m={minX:i-Math.min(a/2-o-.6,3.4),maxX:i+Math.min(a/2-o-.6,3.4)},h=(u-2*o)*EX,g=[...GJ(d,t.minY,c,n.metal,`metal`,`body`),KJ(d,c,1,n.metal,`metal`,`body`),...qJ(d,f,t.minY,-1,n.metal,`metal`,`body`),...GJ(f,t.minY,l,n.mark,`matt`,`body`,`in`),KJ(f,l,-1,n.mark,`matt`,`body`),...YJ(m,l-Math.min(TX.length,l-t.minY-TX.shorter),l,(r-Math.min(TX.thick,h))/2,(r+Math.min(TX.thick,h))/2,n.body,`matt`,`body`),...GJ(p,c,t.maxY,n.mark,`matt`,`body`),KJ(p,t.maxY,1,n.mark,`matt`,`body`)],_=e=>e.layers===`through`;for(let t of e.pads.filter(e=>!_(e)))g.push(...$(UW(t),0,Math.min(DX,r*OX),n.metal,`metal`,`leg`));for(let i of e.pads.filter(_)){let e={x:(i.drill?.width??.6)*.8/2,y:(i.drill?.height??.6)*.8/2};g.push(...$(VW({minX:i.x-e.x,maxX:i.x+e.x,minY:i.y-e.y,maxY:i.y+e.y},t),0,Math.min(kX,r*AX),n.metal,`metal`,`leg`))}return[...g,...ZJ(e,_,n.metal)]}var MX={usbb:mX,usbc:jX,dcjack:pY,tact:nX,resonator:HY,inductor:jY},NX=.15,PX=.15,FX=e=>e.width*e.height;function IX(e,t){let[n,r]=[(t.minX+t.maxX)/2,(t.minY+t.maxY)/2],[i,a]=[(e.x-n)/((t.maxX-t.minX)/2),(e.y-r)/((t.maxY-t.minY)/2)];return Math.abs(a)>=Math.abs(i)?a>=0?`top`:`bottom`:i>=0?`right`:`left`}function LX(e,t,n,r){let i=UW(e),a=IX(e,t),o=a===`top`||a===`bottom`,s=o?i.maxX-i.minX:i.maxY-i.minY,c={minX:a===`right`?Math.max(i.minX,t.maxX):i.minX,maxX:a===`left`?Math.min(i.maxX,t.minX):i.maxX,minY:a===`top`?Math.max(i.minY,t.maxY):i.minY,maxY:a===`bottom`?Math.min(i.maxY,t.minY):i.maxY};return(o?c.maxY-c.minY:c.maxX-c.minX)<NX?$(i,0,Math.min(PX,n/3),r,`metal`,`leg`):pK({...e,x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2,width:c.maxX-c.minX,height:c.maxY-c.minY,rotation:0},a,t,n,r,s)}function RX(e){let t=e.pads.reduce((e,t)=>e===void 0||FX(t)>FX(e)?t:e,void 0),n=e.pads.filter(e=>e!==t),r=e.outlines!==void 0&&e.outlines.length>1?HW(e.outlines[0]):e.body,i=r?VW(r,e.limit):fK({...e,pads:n}),a=e.height,{bottom:o,top:s}=sK(a),{look:c}=e,l=[...$(i,o,s,c.body,`matt`,`body`)];for(let e of n)l.push(...pK(e,uK(e),i,a,c.metal));return t!==void 0&&l.push(...LX(t,i,a,c.metal)),l.push(...mK(e,i,s)),rK(l,e.limit)}var zX=.85,BX=.62,VX=.28,HX=.3,UX=14,WX=.55,GX={220:{rise:16,hole:1.9,plastic:!1,lead:{x:.4,y:.25}},247:{rise:21,hole:2.2,plastic:!1,lead:{x:.6,y:.3}},126:{rise:10.8,hole:1.5,plastic:!0,lead:{x:.4,y:.25}}},KX=(e,t,n)=>Array.from({length:UX},(r,i)=>[e+t.radius*Math.cos(2*Math.PI*i/UX),n,t.z+t.radius*Math.sin(2*Math.PI*i/UX)]);function qX(e,t,n,r,i,a){let[o,s]=[KX(e,t,n),KX(e,t,r)];return o.map((n,r)=>{let c=(r+1)%UX,[l,u,d]=[o[c],s[r],s[c]],f=[-((n[0]+l[0])/2-e),0,-((n[2]+l[2])/2-t.z)];return kW([n,u,d,l],f,i,a,`body`)})}function JX(e,t,n,r,i,a,o=`metal`){let s=(e.minX+e.maxX)/2,[c,l]=[e.minY,e.maxY],u={loops:[[[e.minX,c,n],[e.maxX,c,n],[e.maxX,c,r],[e.minX,c,r]],[...KX(s,i,c)].reverse()],normal:[0,-1,0],color:a,material:o,role:`body`},d=KX(s,i,l).map(e=>[2*s-e[0],e[1],e[2]]);return[u,{loops:[[[e.maxX,l,t],[e.minX,l,t],[e.minX,l,r],[e.maxX,l,r]],[...d].reverse()],normal:[0,1,0],color:a,material:o,role:`body`},...qX(s,i,c,l,a,o)]}function YX(e,t,n,r,i){let a=t+(n-t)*WX,o=Math.min(r.hole,(n-a)*HX,(e.maxX-e.minX)/2-.2),s=(a+n)/2,c=$(e,t,a,i,`matt`,`body`).filter(e=>e.normal[1]<-.5),l=OW(IW(e),t,n,i,`matt`,`body`).filter(e=>Math.abs(e.normal[1])<.5);return[...c,...l,...JX(e,t,a,n,{z:s,radius:o},i,`matt`)]}function XX(e){let t=VW(e.body??BW(e.limit,-.2),e.limit),{look:n}=e,r=GX[e.parsed?.code??`220`]??GX[220],i=e.height,a=Math.min(r.rise,i*zX),o=i-a,s=r.plastic?YX(t,o,i,r,n.body):ZX(t,o,i,a,r,n);for(let t of e.pads){let e={minX:t.x-r.lead.x,maxX:t.x+r.lead.x,minY:t.y-r.lead.y,maxY:t.y+r.lead.y};s.push(...$(e,0,o,n.metal,`metal`,`leg`))}return[...s,...KW(e,n.metal,r.lead)]}function ZX(e,t,n,r,i,a){let o=t+r*BX,s=e.maxY-(e.maxY-e.minY)*VX,c=Math.min(i.hole,(n-o)*HX,(e.maxX-e.minX)/2-.2),l={minX:e.minX,maxX:e.maxX,minY:s,maxY:e.maxY},u=OW(IW(l),t,n,a.metal,`metal`,`body`).filter(e=>Math.abs(e.normal[1])<.5);return[...$({...e,maxY:s},t,o,a.body,`matt`,`body`),...u,...JX(l,t,o,n,{z:(o+n)/2,radius:c},a.metal)]}var QX=.7,$X=.2,eZ=.6,tZ=14,nZ={x:.22,y:.2};function rZ(e){let t=(e.maxX-e.minX)/2,[n,r]=[(e.minX+e.maxX)/2,e.maxY-t],i=e=>({x:n+t*Math.cos(e),y:r+t*Math.sin(e)});if(e.minY<r-t)return[...Array.from({length:15},(e,t)=>i(Math.PI*t/tZ)),{x:n-t,y:e.minY},{x:n+t,y:e.minY}];let a=Math.asin(Math.max(-1,Math.min(1,(e.minY-r)/t))),o=Math.PI-2*a,s=o>=2*Math.PI-1e-9;return Array.from({length:s?tZ:15},(e,t)=>i(a+o*t/tZ))}function iZ(e){let t=VW(e.body??BW(e.limit,-.2),e.limit),{look:n}=e,r=e.height,i=Math.min(QX,r*$X),a=Math.max(i+.1,r-eZ),o=[...OW(rZ(t),i,a,n.body,`matt`,`body`),...OW(rZ(BW(t,-.35)),a,r,n.body,`matt`,`body`)];for(let t of e.pads){let e={minX:t.x-nZ.x,maxX:t.x+nZ.x,minY:t.y-nZ.y,maxY:t.y+nZ.y};o.push(...$(e,0,i+.3,n.metal,`metal`,`leg`))}return[...o,...KW(e,n.metal,nZ)]}var aZ={chip:nK,molded:bq,gullwing:hK,leadless:vq,header:gq,crystal:MK,electrolytic:PK,block:kK,box:AK,bga:OK,dip:dq,to220:XX,to92:iZ,tab:RX,axial:gG,ledth:AG,screw:KG,socket:eK,...UJ,...MX},oZ={minX:-.5,minY:-.5,maxX:.5,maxY:.5};function sZ(e,t){let n=e.rotation*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],a=e.side===`bottom`;return{point:n=>{let[o,s]=[n[0]*r-n[1]*i,n[0]*i+n[1]*r];return[e.x+(a?-o:o),e.y+s,a?-n[2]:t+n[2]]},normal:e=>{let[t,n]=[e[0]*r-e[1]*i,e[0]*i+e[1]*r];return[a?-t:t,n,a?-e[2]:e[2]]}}}function cZ(e,t,n,r,i,a){let o=e.footprint,s=HW(o?.courtyard??[])??HW((o?.pads??[]).map(e=>({x:e.x,y:e.y})))??oZ,c=HW((o?.fabrication??[]).flat());return{pads:o?.pads??[],height:t,limit:s,...c?{body:c}:{},...o?.fabrication.length?{outlines:o.fabrication}:{},look:n,...a?{lookName:a}:{},...r?{parsed:r}:{},thickness:i}}function lZ(e,t){let n=t.board?.thickness??t.parts.find(e=>e.side===`top`)?.bottom??1.6,r=new Map(e.circuit.components.map(e=>[e.id,e]));return e.pcb.parts.flatMap((e,i)=>{let a=t.parts[i];if(a===void 0)return[];let o=r.get(e.component),s=e.pads.some(e=>e.layers===`through`),{family:c,look:l,parsed:u}=tq(o?.kind??``,o?.footprint,s,e.component),d=c===`ledth`?DG(UK[l],o?.props):UK[l],f=cZ(e,a.height,d,u,n,l),p=e.footprint===void 0?[]:aZ[c](f),m=p.length===0?AK(f):p,h=sZ(e,n);return m.map(e=>({loops:e.loops.map(e=>e.map(h.point)),normal:h.normal(e.normal),color:e.color,alpha:1,part:i,material:e.material,role:e.role}))})}var uZ=e=>{let t=Math.hypot(e[0],e[1],e[2]);return[e[0]/t,e[1]/t,e[2]/t]},dZ=uZ([-.55,.5,.78]),fZ=.36,pZ=.2,mZ=.44/dZ[2],hZ=.55,gZ=18,_Z=e=>e[2]>=0?dZ:[dZ[0],dZ[1],-dZ[2]],vZ=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function yZ(e,t,n,r=`matt`){let i=vZ(e,t),a=i<0?[-e[0],-e[1],-e[2]]:e,o=Math.max(0,vZ(a,n)),s=fZ+pZ*Math.abs(i)+mZ*o*(r===`metal`?.8:1);if(r!==`metal`)return{scale:s,add:0};let c=uZ([n[0]+t[0],n[1]+t[1],n[2]+t[2]]);return{scale:s,add:255*hZ*Math.max(0,vZ(a,c))**gZ}}var bZ=.35,xZ=.45,SZ=1e-6;function CZ(e,t,n){if(n&&n.width===e&&n.height===t)return n;let r=e*t;return{width:e,height:t,color:new Uint8ClampedArray(r*4),ids:new Int32Array(r),depth:new Float32Array(r),faces:new Int32Array(r)}}function wZ(e,t){let n=wW(e.normal,t.eye);if(Math.abs(n)<SZ)return;let r=e.loops[0]?.[0];if(r===void 0)return;let[i,a]=[wW(e.normal,t.right),wW(e.normal,t.up)],o=wW(e.normal,t.target)-wW(e.normal,r),s=i/t.scale/n,c=-a/t.scale/n,l=(o-i*t.width/2/t.scale+a*t.height/2/t.scale)/n;return{loops:e.loops.map(e=>e.map(e=>{let n=[e[0]-t.target[0],e[1]-t.target[1],e[2]-t.target[2]];return{x:t.width/2+t.scale*wW(n,t.right),y:t.height/2-t.scale*wW(n,t.up)}})),a:s,b:c,c:l}}function TZ(e,t,n,r){let[i,a]=[1/0,-1/0];for(let t of e.loops)for(let e of t)[i,a]=[Math.min(i,e.y),Math.max(a,e.y)];let o=Math.max(0,Math.ceil(i-.5)),s=Math.min(n-1,Math.floor(a-.5)),c=[];for(let n=o;n<=s;n++){let i=n+.5;c.length=0;for(let t of e.loops)for(let e=0;e<t.length;e++){let n=t[e],r=t[(e+1)%t.length];(n.y<=i&&r.y>i||r.y<=i&&n.y>i)&&c.push(n.x+(i-n.y)/(r.y-n.y)*(r.x-n.x))}c.sort((e,t)=>e-t);for(let a=0;a+1<c.length;a+=2){let o=Math.max(0,Math.ceil(c[a]-.5)),s=Math.min(t-1,Math.floor(c[a+1]-.5));for(let a=o;a<=s;a++)r(n*t+a,e.a*(a+.5)+e.b*i+e.c)}}}function EZ(e,t,n){let r=bZ+.65*Math.abs(wW(e.normal,t.eye)),i=e.part>=0&&e.part===n?xZ:0;return e.color.map(e=>Math.round(e*r+(255-e*r)*i))}function DZ(e,t,n,r,i){let a=CZ(n,r,i.reuse),o=EW(t,e,n,r),[s,c,l]=i.background;a.color.subarray(0,4).set([s,c,l,255]);for(let e=4;e<a.color.length;e*=2)a.color.copyWithin(e,0,Math.min(e,a.color.length-e));if(a.ids.fill(-1),a.depth.fill(1/0),a.faces.fill(-1),i.lit)return AZ(e,o,a,i),a;let u=e.faces.filter(e=>e.alpha>=1),d=e.faces.filter(e=>e.alpha<1);for(let e of u){let t=wZ(e,o);if(!t)continue;let[s,c,l]=EZ(e,o,i.highlight);TZ(t,n,r,(t,n)=>{n>=a.depth[t]||(a.depth[t]=n,a.ids[t]=e.part,a.color[t*4]=s,a.color[t*4+1]=c,a.color[t*4+2]=l)})}for(let e of d){let t=wZ(e,o);if(!t)continue;let[i,s,c]=EZ(e,o,void 0),l=1-e.alpha;TZ(t,n,r,(t,n)=>{n>=a.depth[t]||(a.color[t*4]=a.color[t*4]*l+i*e.alpha,a.color[t*4+1]=a.color[t*4+1]*l+s*e.alpha,a.color[t*4+2]=a.color[t*4+2]*l+c*e.alpha)})}return a}var OZ=.78,kZ=.94;function AZ(e,t,n,r){let i=_Z(t.eye),a=new Float32Array(3),{width:o,height:s}=n;e.faces.forEach((e,c)=>{if(wW(e.normal,t.eye)<=0)return;let l=wZ(e,t);if(!l)return;let{scale:u,add:d}=yZ(e.normal,t.eye,i,e.material),f=e.part>=0&&e.part===r.highlight?xZ:0,p=e=>Math.min(255,e*u+d)*(1-f)+255*f,m=e.paint;if(!m){let[t,r,i]=[p(e.color[0]),p(e.color[1]),p(e.color[2])];TZ(l,o,s,(a,o)=>{o>=n.depth[a]||(n.depth[a]=o,n.ids[a]=e.part,n.faces[a]=c,n.color[a*4]=t,n.color[a*4+1]=r,n.color[a*4+2]=i)});return}let h=t.scale,{a:g,b:_,c:v}=l,y=e=>({A:t.right[e]/h-g*t.eye[e],B:-t.up[e]/h-_*t.eye[e],C:t.target[e]+(.5-o/2)*t.right[e]/h+(s/2-.5)*t.up[e]/h-(.5*g+.5*_+v)*t.eye[e]}),[b,x,S]=[y(0),y(1),y(2)],C=r.fine??!1,w=m.texture;if(w&&!C){let e=w.mirrored?-1:1,t=w.pxPerMm,[r,i,a]=[e*t*b.A,e*t*b.B,w.origin.x+e*t*b.C],[u,d,f]=[-t*x.A,-t*x.B,w.origin.y-t*x.C],{rgba:m,width:h,height:g}=w;TZ(l,o,s,(e,t)=>{if(t>=n.depth[e])return;let s=e/o|0,l=e-s*o,_=Math.floor(r*l+i*s+a),v=Math.floor(u*l+d*s+f);if(_<0||v<0||_>=h||v>=g)return;let y=(v*h+_)*4;m[y+3]<128||(n.depth[e]=t,n.ids[e]=-1,n.faces[e]=c,n.color[e*4]=p(m[y]),n.color[e*4+1]=p(m[y+1]),n.color[e*4+2]=p(m[y+2]))})}else TZ(l,o,s,(t,r)=>{if(r>=n.depth[t])return;let i=t/o|0,s=t-i*o,l=b.A*s+b.B*i+b.C,u=x.A*s+x.B*i+x.C,d=S.A*s+S.B*i+S.C;m.at(l,u,d,a,C)<.5||(n.depth[t]=r,n.ids[t]=e.part,n.faces[t]=c,n.color[t*4]=p(a[0]),n.color[t*4+1]=p(a[1]),n.color[t*4+2]=p(a[2]))})}),jZ(e,n,t.scale)}function jZ(e,t,n){let{width:r,height:i,faces:a,depth:o,color:s}=t,c=2/n,l=new Uint8Array(r*i),u=(t,n)=>{let[r,i]=[a[t],a[n]];if(r===i)return!1;if(r<0||i<0)return r!==i&&(r>=0||i>=0);let[s,l]=[e.faces[r],e.faces[i]];return s.part!==l.part||Math.abs(o[t]-o[n])>c||wW(s.normal,l.normal)<kZ};for(let e=0;e<i;e++)for(let t=0;t<r;t++){let n=e*r+t,s=a[n];t+1<r&&a[n+1]!==s&&u(n,n+1)&&(l[o[n]>o[n+1]?n+1:n]=1),e+1<i&&a[n+r]!==s&&u(n,n+r)&&(l[o[n]>o[n+r]?n+r:n]=1)}for(let e=0;e<l.length;e++)!l[e]||a[e]<0||(s[e*4]=s[e*4]*OZ,s[e*4+1]=s[e*4+1]*OZ,s[e*4+2]=s[e*4+2]*OZ)}function MZ(e,t,n,r,i,a=2){let o=DZ(e,t,n*a,r*a,{...i,reuse:void 0,fine:!0}),s=CZ(n,r,i.reuse),c=a*a;for(let e=0;e<r;e++)for(let t=0;t<n;t++){let[r,i,l]=[0,0,0];for(let n=0;n<a;n++)for(let s=0;s<a;s++){let c=((e*a+n)*o.width+t*a+s)*4;r+=o.color[c],i+=o.color[c+1],l+=o.color[c+2]}let u=e*n+t,d=(e*a+(a>>1))*o.width+t*a+(a>>1);s.color[u*4]=r/c,s.color[u*4+1]=i/c,s.color[u*4+2]=l/c,s.color[u*4+3]=255,s.ids[u]=o.ids[d],s.depth[u]=o.depth[d],s.faces[u]=o.faces[d]}return s}function NZ(e){let{rgba:t,width:n,height:r,origin:i,pxPerMm:a,mirrored:o}=e,s=o?-1:1;return{texture:e,at(e,o,c,l,u){let d=i.x+s*e*a,f=i.y-o*a;if(!u){let[e,i]=[Math.floor(d),Math.floor(f)];if(e<0||i<0||e>=n||i>=r)return 0;let a=(i*n+e)*4;return l[0]=t[a],l[1]=t[a+1],l[2]=t[a+2],t[a+3]/255}let[p,m]=[d-.5,f-.5],[h,g]=[Math.floor(p),Math.floor(m)],[_,v]=[p-h,m-g],y=0;l[0]=l[1]=l[2]=0;for(let[e,i,a]of[[0,0,(1-_)*(1-v)],[1,0,_*(1-v)],[0,1,(1-_)*v],[1,1,_*v]]){let[o,s]=[Math.min(n-1,Math.max(0,h+e)),Math.min(r-1,Math.max(0,g+i))],c=(s*n+o)*4,u=a*t[c+3]/255;l[0]+=t[c]*u,l[1]+=t[c+1]*u,l[2]+=t[c+2]*u,y+=u}return y>0&&(l[0]/=y,l[1]/=y,l[2]/=y),y}}}var PZ=[176,112,58],FZ=.0175;function IZ(e,t,n){let r=t===4?[0,e/3,2*e/3,e]:[0,e],i=qU.lit;return{at(t,a,o,s){let c=o<.02||o>e-.02,l=r.some(t=>Math.abs(o-(t===0?.027500000000000004:t===e?e-FZ-.01:t))<=FZ),u=c?n:l?PZ:i;return s[0]=u[0],s[1]=u[1],s[2]=u[2],1}}}function LZ(e){return{mask:WU[$U({...e,background:void 0}).mask].over,laminate:qU.lit,barrel:JU}}var RZ=.45,zZ=[40,120,70];function BZ(e){let t=Number.parseInt(e.slice(1),16);return[t>>16&255,t>>8&255,t&255]}var VZ=e=>BZ(e===`top`?W.topAssembly:W.bottomAssembly),HZ=Math.PI/12;function UZ(e){return e.flatMap(e=>{if(e.kind===`line`)return[e.from];let t=NU(e),n=Math.max(2,Math.ceil(Math.abs(t)/HZ)),r=Math.atan2(e.from.y-e.centre.y,e.from.x-e.centre.x);return Array.from({length:n},(i,a)=>{let o=r+t*a/n;return a===0?e.from:{x:e.centre.x+e.radius*Math.cos(o),y:e.centre.y+e.radius*Math.sin(o)}})})}function WZ(e,t,n,r,i,a){let o=e=>t=>[t.x,t.y,e];return[{loops:e.map(e=>e.map(o(n))),normal:[0,0,1],color:r,alpha:i,part:a},{loops:e.map(e=>[...e].reverse().map(o(t))),normal:[0,0,-1],color:r,alpha:i,part:a},...e.flatMap(e=>e.map((s,c)=>{let l=e[(c+1)%e.length],u=Math.hypot(l.x-s.x,l.y-s.y)||1;return{loops:[[o(t)(s),o(t)(l),o(n)(l),o(n)(s)]],normal:[(l.y-s.y)/u,-(l.x-s.x)/u,0],color:r,alpha:i,part:a}}))]}function GZ(e,t){let n=LZ(t.look??{}),r=[e.outline,...e.holes].map(UZ),i=e.thickness,a=e=>t=>[t.x,t.y,e],o=e=>e?r.slice(0,1):r,s={loops:o(t.textures?.top).map(e=>e.map(a(i))),normal:[0,0,1],color:n.mask,alpha:1,part:-1,material:`matt`,role:`board`,...t.textures?.top?{paint:NZ(t.textures.top)}:{}},c={loops:o(t.textures?.bottom).map(e=>[...e].reverse().map(a(0))),normal:[0,0,-1],color:n.mask,alpha:1,part:-1,material:`matt`,role:`board`,...t.textures?.bottom?{paint:NZ(t.textures.bottom)}:{}},l=IZ(i,t.layers??2,n.mask),u=t.mounting??0;return[s,c,...r.flatMap((e,t)=>e.map((r,o)=>{let s=e[(o+1)%e.length],c=Math.hypot(s.x-r.x,s.y-r.y)||1,d=t===0,f=!d&&t-1>=u;return{loops:[[a(0)(r),a(0)(s),a(i)(s),a(i)(r)]],normal:[(s.y-r.y)/c,-(s.x-r.x)/c,0],color:f?n.barrel:n.laminate,alpha:1,part:-1,material:f?`metal`:`matt`,role:`board`,...d?{paint:l}:{}}}))]}function KZ(e,t){let n=e.board,r=n?t?GZ(n,t):WZ([n.outline,...n.holes].map(UZ),0,n.thickness,zZ,RZ,-1):[],i=[...t?.parts??e.parts.flatMap((e,t)=>WZ([e.corners],e.bottom,e.top,VZ(e.side),1,t)),...r],a=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(let e of i.flatMap(e=>e.loops.flat()))for(let t=0;t<3;t++)a[t]=Math.min(a[t],e[t]),o[t]=Math.max(o[t],e[t]);return{faces:i,bounds:i.length===0?[[0,0,0],[0,0,0]]:[a,o]}}function qZ(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 JZ(e){let t=e.parts.flatMap(e=>e.pads).filter(e=>e.layers===`through`&&e.drill!==void 0).map(qZ),n=e.vias.filter(e=>e.missingLayer===void 0).map(e=>({diameter:e.drill,at:e.at,function:`ViaDrill`})),r=e.holes.map(e=>({diameter:e.diameter,at:{x:e.x,y:e.y},function:`MechanicalDrill`}));return{plated:[...t,...n],nonPlated:r}}var YZ=c(o(((e,t)=>{(function(){var e={};e.version=`6.4.2.2`,e.use_lines=!0,e.use_xyz=!1;var n=!1;t!==void 0&&t.exports?(t.exports=e,n=!0):(typeof define==`function`&&define.amd&&define(e),typeof document<`u`?window.ClipperLib=e:self.ClipperLib=e);var r;if(n){var i=`chrome`;r=`Netscape`}else{var i=navigator.userAgent.toString().toLowerCase();r=navigator.appName}var a={};a.chrome=+(i.indexOf(`chrome`)!=-1&&i.indexOf(`chromium`)==-1),a.chromium=i.indexOf(`chromium`)==-1?0:1,a.safari=+(i.indexOf(`safari`)!=-1&&i.indexOf(`chrome`)==-1&&i.indexOf(`chromium`)==-1),a.firefox=i.indexOf(`firefox`)==-1?0:1,a.firefox17=i.indexOf(`firefox/17`)==-1?0:1,a.firefox15=i.indexOf(`firefox/15`)==-1?0:1,a.firefox3=i.indexOf(`firefox/3`)==-1?0:1,a.opera=i.indexOf(`opera`)==-1?0:1,a.msie10=i.indexOf(`msie 10`)==-1?0:1,a.msie9=i.indexOf(`msie 9`)==-1?0:1,a.msie8=i.indexOf(`msie 8`)==-1?0:1,a.msie7=i.indexOf(`msie 7`)==-1?0:1,a.msie=i.indexOf(`msie `)==-1?0:1,e.biginteger_used=null;var o,s=!0;function c(t,n,r){e.biginteger_used=1,t!=null&&(typeof t==`number`&&n===void 0?this.fromInt(t):typeof t==`number`?this.fromNumber(t,n,r):n==null&&typeof t!=`string`?this.fromString(t,256):this.fromString(t,n))}function l(){return new c(null,void 0,void 0)}function u(e,t,n,r,i,a){for(;--a>=0;){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864),n[r++]=o&67108863}return i}function d(e,t,n,r,i,a){for(var o=t&32767,s=t>>15;--a>=0;){var c=this[e]&32767,l=this[e++]>>15,u=s*c+l*o;c=o*c+((u&32767)<<15)+n[r]+(i&1073741823),i=(c>>>30)+(u>>>15)+s*l+(i>>>30),n[r++]=c&1073741823}return i}function f(e,t,n,r,i,a){for(var o=t&16383,s=t>>14;--a>=0;){var c=this[e]&16383,l=this[e++]>>14,u=s*c+l*o;c=o*c+((u&16383)<<14)+n[r]+i,i=(c>>28)+(u>>14)+s*l,n[r++]=c&268435455}return i}s&&r==`Microsoft Internet Explorer`?(c.prototype.am=d,o=30):s&&r!=`Netscape`?(c.prototype.am=u,o=26):(c.prototype.am=f,o=28),c.prototype.DB=o,c.prototype.DM=(1<<o)-1,c.prototype.DV=1<<o;var p=52;c.prototype.FV=2**p,c.prototype.F1=p-o,c.prototype.F2=2*o-p;for(var m=`0123456789abcdefghijklmnopqrstuvwxyz`,h=[],g=48,_=0;_<=9;++_)h[g++]=_;for(g=97,_=10;_<36;++_)h[g++]=_;for(g=65,_=10;_<36;++_)h[g++]=_;function v(e){return m.charAt(e)}function y(e,t){return h[e.charCodeAt(t)]??-1}function b(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function x(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0}function S(e){var t=l();return t.fromInt(e),t}function C(e,t){var n;if(t==16)n=4;else if(t==8)n=3;else if(t==256)n=8;else if(t==2)n=1;else if(t==32)n=5;else if(t==4)n=2;else{this.fromRadix(e,t);return}this.t=0,this.s=0;for(var r=e.length,i=!1,a=0;--r>=0;){var o=n==8?e[r]&255:y(e,r);o<0?e.charAt(r)==`-`&&(i=!0):(i=!1,a==0?this[this.t++]=o:a+n>this.DB?(this[this.t-1]|=(o&(1<<this.DB-a)-1)<<a,this[this.t++]=o>>this.DB-a):this[this.t-1]|=o<<a,a+=n,a>=this.DB&&(a-=this.DB))}n==8&&e[0]&128&&(this.s=-1,a>0&&(this[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),i&&c.ZERO.subTo(this,this)}function w(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function T(e){if(this.s<0)return`-`+this.negate().toString(e);var t;if(e==16)t=4;else if(e==8)t=3;else if(e==2)t=1;else if(e==32)t=5;else if(e==4)t=2;else return this.toRadix(e);var n=(1<<t)-1,r,i=!1,a=``,o=this.t,s=this.DB-o*this.DB%t;if(o-->0)for(s<this.DB&&(r=this[o]>>s)>0&&(i=!0,a=v(r));o>=0;)s<t?(r=(this[o]&(1<<s)-1)<<t-s,r|=this[--o]>>(s+=this.DB-t)):(r=this[o]>>(s-=t)&n,s<=0&&(s+=this.DB,--o)),r>0&&(i=!0),i&&(a+=v(r));return i?a:`0`}function E(){var e=l();return c.ZERO.subTo(this,e),e}function ee(){return this.s<0?this.negate():this}function D(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 O(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 k(){return this.t<=0?0:this.DB*(this.t-1)+O(this[this.t-1]^this.s&this.DM)}function A(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 j(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 te(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 ne(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 re(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 M(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 N(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 P(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-O(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 ie(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 F(e){this.m=e}function I(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function L(e){return e}function R(e){e.divRemTo(this.m,null,e)}function ae(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function oe(e,t){e.squareTo(t),this.reduce(t)}F.prototype.convert=I,F.prototype.revert=L,F.prototype.reduce=R,F.prototype.mulTo=ae,F.prototype.sqrTo=oe;function se(){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 ce(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 le(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 ue(e){var t=l();return e.copyTo(t),this.reduce(t),t}function de(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 fe(e,t){e.squareTo(t),this.reduce(t)}function pe(e,t,n){e.multiplyTo(t,n),this.reduce(n)}ce.prototype.convert=le,ce.prototype.revert=ue,ce.prototype.reduce=de,ce.prototype.mulTo=pe,ce.prototype.sqrTo=fe;function me(){return(this.t>0?this[0]&1:this.s)==0}function z(e,t){if(e>4294967295||e<1)return c.ONE;var n=l(),r=l(),i=t.convert(this),a=O(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 he(e,t){var n=e<256||t.isEven()?new F(t):new ce(t);return this.exp(e,n)}c.prototype.copyTo=b,c.prototype.fromInt=x,c.prototype.fromString=C,c.prototype.clamp=w,c.prototype.dlShiftTo=A,c.prototype.drShiftTo=j,c.prototype.lShiftTo=te,c.prototype.rShiftTo=ne,c.prototype.subTo=re,c.prototype.multiplyTo=M,c.prototype.squareTo=N,c.prototype.divRemTo=P,c.prototype.invDigit=se,c.prototype.isEven=me,c.prototype.exp=z,c.prototype.toString=T,c.prototype.negate=E,c.prototype.abs=ee,c.prototype.compareTo=D,c.prototype.bitLength=k,c.prototype.mod=ie,c.prototype.modPowInt=he,c.ZERO=S(0),c.ONE=S(1);function ge(){var e=l();return this.copyTo(e),e}function _e(){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 ve(){return this.t==0?this.s:this[0]<<24>>24}function ye(){return this.t==0?this.s:this[0]<<16>>16}function B(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function be(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function xe(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 Se(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 Ce(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),Ae,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 we(){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 V(e){return this.compareTo(e)==0}function Te(e){return this.compareTo(e)<0?this:e}function Ee(e){return this.compareTo(e)>0?this:e}function De(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 Oe(e,t){return e&t}function ke(e){var t=l();return this.bitwiseTo(e,Oe,t),t}function Ae(e,t){return e|t}function je(e){var t=l();return this.bitwiseTo(e,Ae,t),t}function Me(e,t){return e^t}function Ne(e){var t=l();return this.bitwiseTo(e,Me,t),t}function Pe(e,t){return e&~t}function Fe(e){var t=l();return this.bitwiseTo(e,Pe,t),t}function Ie(){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 Le(e){var t=l();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function Re(e){var t=l();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function ze(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 Be(){for(var e=0;e<this.t;++e)if(this[e]!=0)return e*this.DB+ze(this[e]);return this.s<0?this.t*this.DB:-1}function Ve(e){for(var t=0;e!=0;)e&=e-1,++t;return t}function He(){for(var e=0,t=this.s&this.DM,n=0;n<this.t;++n)e+=Ve(this[n]^t);return e}function Ue(e){var t=Math.floor(e/this.DB);return t>=this.t?this.s!=0:!!(this[t]&1<<e%this.DB)}function We(e,t){var n=c.ONE.shiftLeft(e);return this.bitwiseTo(n,t,n),n}function Ge(e){return this.changeBit(e,Ae)}function Ke(e){return this.changeBit(e,Pe)}function qe(e){return this.changeBit(e,Me)}function Je(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 Ye(e){var t=l();return this.addTo(e,t),t}function Xe(e){var t=l();return this.subTo(e,t),t}function Ze(e){var t=l();return this.multiplyTo(e,t),t}function Qe(){var e=l();return this.squareTo(e),e}function $e(e){var t=l();return this.divRemTo(e,t,null),t}function et(e){var t=l();return this.divRemTo(e,null,t),t}function tt(e){var t=l(),n=l();return this.divRemTo(e,t,n),[t,n]}function nt(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function rt(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 it(){}function at(e){return e}function ot(e,t,n){e.multiplyTo(t,n)}function st(e,t){e.squareTo(t)}it.prototype.convert=at,it.prototype.revert=at,it.prototype.mulTo=ot,it.prototype.sqrTo=st;function H(e){return this.exp(e,new it)}function ct(e,t,n){var r=Math.min(this.t+e.t,t);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(var i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,e[r],n,r,0,this.t);for(i=Math.min(e.t,t);r<i;++r)this.am(0,e[r],n,r,0,t-r);n.clamp()}function lt(e,t,n){--t;var r=n.t=this.t+e.t-t;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n[this.t+r-t]=this.am(t-r,e[r],n,0,0,this.t+r-t);n.clamp(),n.drShiftTo(1,n)}function ut(e){this.r2=l(),this.q3=l(),c.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function dt(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=l();return e.copyTo(t),this.reduce(t),t}function ft(e){return e}function pt(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function mt(e,t){e.squareTo(t),this.reduce(t)}function ht(e,t,n){e.multiplyTo(t,n),this.reduce(n)}ut.prototype.convert=dt,ut.prototype.revert=ft,ut.prototype.reduce=pt,ut.prototype.mulTo=ht,ut.prototype.sqrTo=mt;function gt(e,t){var n=e.bitLength(),r,i=S(1),a;if(n<=0)return i;r=n<18?1:n<48?3:n<144?4:n<768?5:6,a=n<8?new F(t):t.isEven()?new ut(t):new ce(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=O(e[f])-1;f>=0;){for(n>=c?p=e[f]>>n-c&u:(p=(e[f]&(1<<n+1)-1)<<c-n,f>0&&(p|=e[f-1]>>this.DB+n-c)),s=r;!(p&1);)p>>=1,--s;if((n-=s)<0&&(n+=this.DB,--f),m)o[p].copyTo(i),m=!1;else{for(;s>1;)a.sqrTo(i,h),a.sqrTo(h,i),s-=2;s>0?a.sqrTo(i,h):(g=i,i=h,h=g),a.mulTo(h,o[p],i)}for(;f>=0&&!(e[f]&1<<n);)a.sqrTo(i,h),g=i,i=h,h=g,--n<0&&(n=this.DB-1,--f)}return a.revert(i)}function _t(e){var t=this.s<0?this.negate():this.clone(),n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n,n=r}var i=t.getLowestSetBit(),a=n.getLowestSetBit();if(a<0)return t;for(i<a&&(a=i),a>0&&(t.rShiftTo(a,t),n.rShiftTo(a,n));t.signum()>0;)(i=t.getLowestSetBit())>0&&t.rShiftTo(i,t),(i=n.getLowestSetBit())>0&&n.rShiftTo(i,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return a>0&&n.lShiftTo(a,n),n}function vt(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0){if(t==0)n=this[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this[r])%e}return n}function yt(e){var t=e.isEven();if(this.isEven()&&t||e.signum()==0)return c.ZERO;for(var n=e.clone(),r=this.clone(),i=S(1),a=S(0),o=S(0),s=S(1);n.signum()!=0;){for(;n.isEven();)n.rShiftTo(1,n),t?(i.isEven()&&a.isEven()||(i.addTo(this,i),a.subTo(e,a)),i.rShiftTo(1,i)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;r.isEven();)r.rShiftTo(1,r),t?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(e,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(r)>=0?(n.subTo(r,n),t&&i.subTo(o,i),a.subTo(s,a)):(r.subTo(n,r),t&&o.subTo(i,o),s.subTo(a,s))}if(r.compareTo(c.ONE)!=0)return c.ZERO;if(s.compareTo(e)>=0)return s.subtract(e);if(s.signum()<0)s.addTo(e,s);else return s;return s.signum()<0?s.add(e):s}var bt=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],xt=(1<<26)/bt[bt.length-1];function St(e){var t,n=this.abs();if(n.t==1&&n[0]<=bt[bt.length-1]){for(t=0;t<bt.length;++t)if(n[0]==bt[t])return!0;return!1}if(n.isEven())return!1;for(t=1;t<bt.length;){for(var r=bt[t],i=t+1;i<bt.length&&r<xt;)r*=bt[i++];for(r=n.modInt(r);t<i;)if(r%bt[t++]==0)return!1}return n.millerRabin(e)}function Ct(e){var t=this.subtract(c.ONE),n=t.getLowestSetBit();if(n<=0)return!1;var r=t.shiftRight(n);e=e+1>>1,e>bt.length&&(e=bt.length);for(var i=l(),a=0;a<e;++a){i.fromInt(bt[Math.floor(Math.random()*bt.length)]);var o=i.modPow(r,this);if(o.compareTo(c.ONE)!=0&&o.compareTo(t)!=0){for(var s=1;s++<n&&o.compareTo(t)!=0;)if(o=o.modPowInt(2,this),o.compareTo(c.ONE)==0)return!1;if(o.compareTo(t)!=0)return!1}}return!0}c.prototype.chunkSize=B,c.prototype.toRadix=xe,c.prototype.fromRadix=Se,c.prototype.fromNumber=Ce,c.prototype.bitwiseTo=De,c.prototype.changeBit=We,c.prototype.addTo=Je,c.prototype.dMultiply=nt,c.prototype.dAddOffset=rt,c.prototype.multiplyLowerTo=ct,c.prototype.multiplyUpperTo=lt,c.prototype.modInt=vt,c.prototype.millerRabin=Ct,c.prototype.clone=ge,c.prototype.intValue=_e,c.prototype.byteValue=ve,c.prototype.shortValue=ye,c.prototype.signum=be,c.prototype.toByteArray=we,c.prototype.equals=V,c.prototype.min=Te,c.prototype.max=Ee,c.prototype.and=ke,c.prototype.or=je,c.prototype.xor=Ne,c.prototype.andNot=Fe,c.prototype.not=Ie,c.prototype.shiftLeft=Le,c.prototype.shiftRight=Re,c.prototype.getLowestSetBit=Be,c.prototype.bitCount=He,c.prototype.testBit=Ue,c.prototype.setBit=Ge,c.prototype.clearBit=Ke,c.prototype.flipBit=qe,c.prototype.add=Ye,c.prototype.subtract=Xe,c.prototype.multiply=Ze,c.prototype.divide=$e,c.prototype.remainder=et,c.prototype.divideAndRemainder=tt,c.prototype.modPow=gt,c.prototype.modInverse=yt,c.prototype.pow=H,c.prototype.gcd=_t,c.prototype.isProbablePrime=St,c.prototype.square=Qe;var U=c;U.prototype.IsNegative=function(){return this.compareTo(U.ZERO)==-1},U.op_Equality=function(e,t){return e.compareTo(t)==0},U.op_Inequality=function(e,t){return e.compareTo(t)!=0},U.op_GreaterThan=function(e,t){return e.compareTo(t)>0},U.op_LessThan=function(e,t){return e.compareTo(t)<0},U.op_Addition=function(e,t){return new U(e,void 0,void 0).add(new U(t,void 0,void 0))},U.op_Subtraction=function(e,t){return new U(e,void 0,void 0).subtract(new U(t,void 0,void 0))},U.Int128Mul=function(e,t){return new U(e,void 0,void 0).multiply(new U(t,void 0,void 0))},U.op_Division=function(e,t){return e.divide(t)},U.prototype.ToDouble=function(){return parseFloat(this.toString())};var wt=function(e,t){var n;if(Object.getOwnPropertyNames===void 0){for(n in t.prototype)(e.prototype[n]===void 0||e.prototype[n]===Object.prototype[n])&&(e.prototype[n]=t.prototype[n]);for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}else{for(var r=Object.getOwnPropertyNames(t.prototype),i=0;i<r.length;i++)Object.getOwnPropertyDescriptor(e.prototype,r[i])===void 0&&Object.defineProperty(e.prototype,r[i],Object.getOwnPropertyDescriptor(t.prototype,r[i]));for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}};e.Path=function(){return[]},e.Path.prototype.push=Array.prototype.push,e.Paths=function(){return[]},e.Paths.prototype.push=Array.prototype.push,e.DoublePoint=function(){var e=arguments;this.X=0,this.Y=0,e.length===1?(this.X=e[0].X,this.Y=e[0].Y):e.length===2&&(this.X=e[0],this.Y=e[1])},e.DoublePoint0=function(){this.X=0,this.Y=0},e.DoublePoint0.prototype=e.DoublePoint.prototype,e.DoublePoint1=function(e){this.X=e.X,this.Y=e.Y},e.DoublePoint1.prototype=e.DoublePoint.prototype,e.DoublePoint2=function(e,t){this.X=e,this.Y=t},e.DoublePoint2.prototype=e.DoublePoint.prototype,e.PolyNode=function(){this.m_Parent=null,this.m_polygon=new e.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},e.PolyNode.prototype.IsHoleNode=function(){for(var e=!0,t=this.m_Parent;t!==null;)e=!e,t=t.m_Parent;return e},e.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},e.PolyNode.prototype.Contour=function(){return this.m_polygon},e.PolyNode.prototype.AddChild=function(e){var t=this.m_Childs.length;this.m_Childs.push(e),e.m_Parent=this,e.m_Index=t},e.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},e.PolyNode.prototype.GetNextSiblingUp=function(){return this.m_Parent===null?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},e.PolyNode.prototype.Childs=function(){return this.m_Childs},e.PolyNode.prototype.Parent=function(){return this.m_Parent},e.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},e.PolyTree=function(){this.m_AllPolys=[],e.PolyNode.call(this)},e.PolyTree.prototype.Clear=function(){for(var e=0,t=this.m_AllPolys.length;e<t;e++)this.m_AllPolys[e]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},e.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},e.PolyTree.prototype.Total=function(){var e=this.m_AllPolys.length;return e>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&e--,e},wt(e.PolyTree,e.PolyNode),e.Math_Abs_Int64=e.Math_Abs_Int32=e.Math_Abs_Double=function(e){return Math.abs(e)},e.Math_Max_Int32_Int32=function(e,t){return Math.max(e,t)},e.Cast_Int32=a.msie||a.opera||a.safari?function(e){return e|0}:function(e){return~~e},Number.toInteger===void 0&&(Number.toInteger=null),e.Cast_Int64=a.chrome?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):~~e}:a.firefox&&typeof Number.toInteger==`function`?function(e){return Number.toInteger(e)}:a.msie7||a.msie8?function(e){return parseInt(e,10)}:a.msie?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):e|0}:function(e){return e<0?Math.ceil(e):Math.floor(e)},e.Clear=function(e){e.length=0},e.PI=3.141592653589793,e.PI2=6.283185307179586,e.IntPoint=function(){var t=arguments,n=t.length;if(this.X=0,this.Y=0,e.use_xyz){if(this.Z=0,n===3)this.X=t[0],this.Y=t[1],this.Z=t[2];else if(n===2)this.X=t[0],this.Y=t[1],this.Z=0;else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y),this.Z=0}else{var i=t[0];i.Z===void 0&&(i.Z=0),this.X=i.X,this.Y=i.Y,this.Z=i.Z}}else this.X=0,this.Y=0,this.Z=0}else if(n===2)this.X=t[0],this.Y=t[1];else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y)}else{var i=t[0];this.X=i.X,this.Y=i.Y}}else this.X=0,this.Y=0},e.IntPoint.op_Equality=function(e,t){return e.X===t.X&&e.Y===t.Y},e.IntPoint.op_Inequality=function(e,t){return e.X!==t.X||e.Y!==t.Y},e.IntPoint0=function(){this.X=0,this.Y=0,e.use_xyz&&(this.Z=0)},e.IntPoint0.prototype=e.IntPoint.prototype,e.IntPoint1=function(t){this.X=t.X,this.Y=t.Y,e.use_xyz&&(this.Z=t.Z===void 0?0:t.Z)},e.IntPoint1.prototype=e.IntPoint.prototype,e.IntPoint1dp=function(t){this.X=e.Clipper.Round(t.X),this.Y=e.Clipper.Round(t.Y),e.use_xyz&&(this.Z=0)},e.IntPoint1dp.prototype=e.IntPoint.prototype,e.IntPoint2=function(t,n,r){this.X=t,this.Y=n,e.use_xyz&&(this.Z=r===void 0?0:r)},e.IntPoint2.prototype=e.IntPoint.prototype,e.IntRect=function(){var e=arguments,t=e.length;if(t===4)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(t===1){var n=e[0];this.left=n.left,this.top=n.top,this.right=n.right,this.bottom=n.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0.prototype=e.IntRect.prototype,e.IntRect1=function(e){this.left=e.left,this.top=e.top,this.right=e.right,this.bottom=e.bottom},e.IntRect1.prototype=e.IntRect.prototype,e.IntRect4=function(e,t,n,r){this.left=e,this.top=t,this.right=n,this.bottom=r},e.IntRect4.prototype=e.IntRect.prototype,e.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},e.PolyType={ptSubject:0,ptClip:1},e.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},e.JoinType={jtSquare:0,jtRound:1,jtMiter:2},e.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},e.EdgeSide={esLeft:0,esRight:1},e.Direction={dRightToLeft:0,dLeftToRight:1},e.TEdge=function(){this.Bot=new e.IntPoint0,this.Curr=new e.IntPoint0,this.Top=new e.IntPoint0,this.Delta=new e.IntPoint0,this.Dx=0,this.PolyTyp=e.PolyType.ptSubject,this.Side=e.EdgeSide.esLeft,this.WindDelta=0,this.WindCnt=0,this.WindCnt2=0,this.OutIdx=0,this.Next=null,this.Prev=null,this.NextInLML=null,this.NextInAEL=null,this.PrevInAEL=null,this.NextInSEL=null,this.PrevInSEL=null},e.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new e.IntPoint0},e.MyIntersectNodeSort=function(){},e.MyIntersectNodeSort.Compare=function(e,t){var n=t.Pt.Y-e.Pt.Y;return n>0?1:n<0?-1:0},e.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},e.Scanbeam=function(){this.Y=0,this.Next=null},e.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},e.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},e.OutPt=function(){this.Idx=0,this.Pt=new e.IntPoint0,this.Next=null,this.Prev=null},e.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new e.IntPoint0},e.ClipperBase=function(){this.m_MinimaList=null,this.m_CurrentLM=null,this.m_edges=[],this.m_UseFullRange=!1,this.m_HasOpenPaths=!1,this.PreserveCollinear=!1,this.m_Scanbeam=null,this.m_PolyOuts=null,this.m_ActiveEdges=null},e.ClipperBase.horizontal=-9007199254740992,e.ClipperBase.Skip=-2,e.ClipperBase.Unassigned=-1,e.ClipperBase.tolerance=1e-20,e.ClipperBase.loRange=47453132,e.ClipperBase.hiRange=0xfffffffffffff,e.ClipperBase.near_zero=function(t){return t>-e.ClipperBase.tolerance&&t<e.ClipperBase.tolerance},e.ClipperBase.IsHorizontal=function(e){return e.Delta.Y===0},e.ClipperBase.prototype.PointIsVertex=function(t,n){var r=n;do{if(e.IntPoint.op_Equality(r.Pt,t))return!0;r=r.Next}while(r!==n);return!1},e.ClipperBase.prototype.PointOnLineSegment=function(e,t,n,r){return r?e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&U.op_Equality(U.Int128Mul(e.X-t.X,n.Y-t.Y),U.Int128Mul(n.X-t.X,e.Y-t.Y)):e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&(e.X-t.X)*(n.Y-t.Y)===(n.X-t.X)*(e.Y-t.Y)},e.ClipperBase.prototype.PointOnPolygon=function(e,t,n){for(var r=t;;){if(this.PointOnLineSegment(e,r.Pt,r.Next.Pt,n))return!0;if(r=r.Next,r===t)break}return!1},e.ClipperBase.prototype.SlopesEqual=e.ClipperBase.SlopesEqual=function(){var t=arguments,n=t.length,r,i,a,o,s,c,l;return n===3?(r=t[0],i=t[1],l=t[2],l?U.op_Equality(U.Int128Mul(r.Delta.Y,i.Delta.X),U.Int128Mul(r.Delta.X,i.Delta.Y)):e.Cast_Int64(r.Delta.Y*i.Delta.X)===e.Cast_Int64(r.Delta.X*i.Delta.Y)):n===4?(a=t[0],o=t[1],s=t[2],l=t[3],l?U.op_Equality(U.Int128Mul(a.Y-o.Y,o.X-s.X),U.Int128Mul(a.X-o.X,o.Y-s.Y)):e.Cast_Int64((a.Y-o.Y)*(o.X-s.X))-e.Cast_Int64((a.X-o.X)*(o.Y-s.Y))===0):(a=t[0],o=t[1],s=t[2],c=t[3],l=t[4],l?U.op_Equality(U.Int128Mul(a.Y-o.Y,s.X-c.X),U.Int128Mul(a.X-o.X,s.Y-c.Y)):e.Cast_Int64((a.Y-o.Y)*(s.X-c.X))-e.Cast_Int64((a.X-o.X)*(s.Y-c.Y))===0)},e.ClipperBase.SlopesEqual3=function(t,n,r){return r?U.op_Equality(U.Int128Mul(t.Delta.Y,n.Delta.X),U.Int128Mul(t.Delta.X,n.Delta.Y)):e.Cast_Int64(t.Delta.Y*n.Delta.X)===e.Cast_Int64(t.Delta.X*n.Delta.Y)},e.ClipperBase.SlopesEqual4=function(t,n,r,i){return i?U.op_Equality(U.Int128Mul(t.Y-n.Y,n.X-r.X),U.Int128Mul(t.X-n.X,n.Y-r.Y)):e.Cast_Int64((t.Y-n.Y)*(n.X-r.X))-e.Cast_Int64((t.X-n.X)*(n.Y-r.Y))===0},e.ClipperBase.SlopesEqual5=function(t,n,r,i,a){return a?U.op_Equality(U.Int128Mul(t.Y-n.Y,r.X-i.X),U.Int128Mul(t.X-n.X,r.Y-i.Y)):e.Cast_Int64((t.Y-n.Y)*(r.X-i.X))-e.Cast_Int64((t.X-n.X)*(r.Y-i.Y))===0},e.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var t=0,n=this.m_edges.length;t<n;++t){for(var r=0,i=this.m_edges[t].length;r<i;++r)this.m_edges[t][r]=null;e.Clear(this.m_edges[t])}e.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},e.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;this.m_MinimaList!==null;){var e=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=e}this.m_CurrentLM=null},e.ClipperBase.prototype.RangeTest=function(t,n){n.Value?(t.X>e.ClipperBase.hiRange||t.Y>e.ClipperBase.hiRange||-t.X>e.ClipperBase.hiRange||-t.Y>e.ClipperBase.hiRange)&&e.Error(`Coordinate outside allowed range in RangeTest().`):(t.X>e.ClipperBase.loRange||t.Y>e.ClipperBase.loRange||-t.X>e.ClipperBase.loRange||-t.Y>e.ClipperBase.loRange)&&(n.Value=!0,this.RangeTest(t,n))},e.ClipperBase.prototype.InitEdge=function(t,n,r,i){t.Next=n,t.Prev=r,t.Curr.X=i.X,t.Curr.Y=i.Y,e.use_xyz&&(t.Curr.Z=i.Z),t.OutIdx=-1},e.ClipperBase.prototype.InitEdge2=function(t,n){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Curr.Z),t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y,e.use_xyz&&(t.Top.Z=t.Next.Curr.Z)):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,e.use_xyz&&(t.Top.Z=t.Curr.Z),t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Next.Curr.Z)),this.SetDx(t),t.PolyTyp=n},e.ClipperBase.prototype.FindNextLocMin=function(t){for(var n;;){for(;e.IntPoint.op_Inequality(t.Bot,t.Prev.Bot)||e.IntPoint.op_Equality(t.Curr,t.Top);)t=t.Next;if(t.Dx!==e.ClipperBase.horizontal&&t.Prev.Dx!==e.ClipperBase.horizontal)break;for(;t.Prev.Dx===e.ClipperBase.horizontal;)t=t.Prev;for(n=t;t.Dx===e.ClipperBase.horizontal;)t=t.Next;if(t.Top.Y!==t.Prev.Bot.Y){n.Prev.Bot.X<t.Bot.X&&(t=n);break}}return t},e.ClipperBase.prototype.ProcessBound=function(t,n){var r,i=t,a;if(i.OutIdx===e.ClipperBase.Skip){if(t=i,n){for(;t.Top.Y===t.Next.Bot.Y;)t=t.Next;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Prev}else{for(;t.Top.Y===t.Prev.Bot.Y;)t=t.Prev;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Next}if(t===i)i=n?t.Next:t.Prev;else{t=n?i.Next:i.Prev;var o=new e.LocalMinima;o.Next=null,o.Y=t.Bot.Y,o.LeftBound=null,o.RightBound=t,t.WindDelta=0,i=this.ProcessBound(t,n),this.InsertLocalMinima(o)}return i}if(t.Dx===e.ClipperBase.horizontal&&(r=n?t.Prev:t.Next,r.Dx===e.ClipperBase.horizontal?r.Bot.X!==t.Bot.X&&r.Top.X!==t.Bot.X&&this.ReverseHorizontal(t):r.Bot.X!==t.Bot.X&&this.ReverseHorizontal(t)),r=t,n){for(;i.Top.Y===i.Next.Bot.Y&&i.Next.OutIdx!==e.ClipperBase.Skip;)i=i.Next;if(i.Dx===e.ClipperBase.horizontal&&i.Next.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Prev.Dx===e.ClipperBase.horizontal;)a=a.Prev;a.Prev.Top.X>i.Next.Top.X&&(i=a.Prev)}for(;t!==i;)t.NextInLML=t.Next,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),t=t.Next;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),i=i.Next}else{for(;i.Top.Y===i.Prev.Bot.Y&&i.Prev.OutIdx!==e.ClipperBase.Skip;)i=i.Prev;if(i.Dx===e.ClipperBase.horizontal&&i.Prev.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Next.Dx===e.ClipperBase.horizontal;)a=a.Next;(a.Next.Top.X===i.Prev.Top.X||a.Next.Top.X>i.Prev.Top.X)&&(i=a.Next)}for(;t!==i;)t.NextInLML=t.Prev,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),t=t.Prev;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),i=i.Prev}return i},e.ClipperBase.prototype.AddPath=function(t,n,r){e.use_lines?!r&&n===e.PolyType.ptClip&&e.Error(`AddPath: Open paths must be subject.`):r||e.Error(`AddPath: Open paths have been disabled.`);var i=t.length-1;if(r)for(;i>0&&e.IntPoint.op_Equality(t[i],t[0]);)--i;for(;i>0&&e.IntPoint.op_Equality(t[i],t[i-1]);)--i;if(r&&i<2||!r&&i<1)return!1;for(var a=[],o=0;o<=i;o++)a.push(new e.TEdge);var s=!0;a[1].Curr.X=t[1].X,a[1].Curr.Y=t[1].Y,e.use_xyz&&(a[1].Curr.Z=t[1].Z);var c={Value:this.m_UseFullRange};this.RangeTest(t[0],c),this.m_UseFullRange=c.Value,c.Value=this.m_UseFullRange,this.RangeTest(t[i],c),this.m_UseFullRange=c.Value,this.InitEdge(a[0],a[1],a[i],t[0]),this.InitEdge(a[i],a[0],a[i-1],t[i]);for(var o=i-1;o>=1;--o)c.Value=this.m_UseFullRange,this.RangeTest(t[o],c),this.m_UseFullRange=c.Value,this.InitEdge(a[o],a[o+1],a[o-1],t[o]);for(var l=a[0],u=l,d=l;;)if(u.Curr===u.Next.Curr&&(r||u.Next!==l)){if(u===u.Next)break;u===l&&(l=u.Next),u=this.RemoveEdge(u),d=u}else{if(u.Prev===u.Next)break;if(r&&e.ClipperBase.SlopesEqual4(u.Prev.Curr,u.Curr,u.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(u.Prev.Curr,u.Curr,u.Next.Curr)))u===l&&(l=u.Next),u=this.RemoveEdge(u),u=u.Prev,d=u;else if(u=u.Next,u===d||!r&&u.Next===l)break}if(!r&&u===u.Next||r&&u.Prev===u.Next)return!1;r||(this.m_HasOpenPaths=!0,l.Prev.OutIdx=e.ClipperBase.Skip),u=l;do this.InitEdge2(u,n),u=u.Next,s&&u.Curr.Y!==l.Curr.Y&&(s=!1);while(u!==l);if(s){if(r)return!1;u.Prev.OutIdx=e.ClipperBase.Skip;var f=new e.LocalMinima;for(f.Next=null,f.Y=u.Bot.Y,f.LeftBound=null,f.RightBound=u,f.RightBound.Side=e.EdgeSide.esRight,f.RightBound.WindDelta=0;u.Bot.X!==u.Prev.Top.X&&this.ReverseHorizontal(u),u.Next.OutIdx!==e.ClipperBase.Skip;)u.NextInLML=u.Next,u=u.Next;return this.InsertLocalMinima(f),this.m_edges.push(a),!0}this.m_edges.push(a);var p,m=null;for(e.IntPoint.op_Equality(u.Prev.Bot,u.Prev.Top)&&(u=u.Next);u=this.FindNextLocMin(u),u!==m;){m===null&&(m=u);var f=new e.LocalMinima;f.Next=null,f.Y=u.Bot.Y,u.Dx<u.Prev.Dx?(f.LeftBound=u.Prev,f.RightBound=u,p=!1):(f.LeftBound=u,f.RightBound=u.Prev,p=!0),f.LeftBound.Side=e.EdgeSide.esLeft,f.RightBound.Side=e.EdgeSide.esRight,r?f.LeftBound.Next===f.RightBound?f.LeftBound.WindDelta=-1:f.LeftBound.WindDelta=1:f.LeftBound.WindDelta=0,f.RightBound.WindDelta=-f.LeftBound.WindDelta,u=this.ProcessBound(f.LeftBound,p),u.OutIdx===e.ClipperBase.Skip&&(u=this.ProcessBound(u,p));var h=this.ProcessBound(f.RightBound,!p);h.OutIdx===e.ClipperBase.Skip&&(h=this.ProcessBound(h,!p)),f.LeftBound.OutIdx===e.ClipperBase.Skip?f.LeftBound=null:f.RightBound.OutIdx===e.ClipperBase.Skip&&(f.RightBound=null),this.InsertLocalMinima(f),p||(u=h)}return!0},e.ClipperBase.prototype.AddPaths=function(e,t,n){for(var r=!1,i=0,a=e.length;i<a;++i)this.AddPath(e[i],t,n)&&(r=!0);return r},e.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(t,n,r){return e.IntPoint.op_Equality(t,r)||e.IntPoint.op_Equality(t,n)||e.IntPoint.op_Equality(r,n)?!1:t.X===r.X?n.Y>t.Y==n.Y<r.Y:n.X>t.X==n.X<r.X},e.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var t=e.Next;return e.Prev=null,t},e.ClipperBase.prototype.SetDx=function(t){t.Delta.X=t.Top.X-t.Bot.X,t.Delta.Y=t.Top.Y-t.Bot.Y,t.Dx=t.Delta.Y===0?e.ClipperBase.horizontal:t.Delta.X/t.Delta.Y},e.ClipperBase.prototype.InsertLocalMinima=function(e){if(this.m_MinimaList===null)this.m_MinimaList=e;else if(e.Y>=this.m_MinimaList.Y)e.Next=this.m_MinimaList,this.m_MinimaList=e;else{for(var t=this.m_MinimaList;t.Next!==null&&e.Y<t.Next.Y;)t=t.Next;e.Next=t.Next,t.Next=e}},e.ClipperBase.prototype.PopLocalMinima=function(e,t){return t.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===e&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)},e.ClipperBase.prototype.ReverseHorizontal=function(t){var n=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=n,e.use_xyz&&(n=t.Top.Z,t.Top.Z=t.Bot.Z,t.Bot.Z=n)},e.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,this.m_CurrentLM!==null){this.m_Scanbeam=null;for(var t=this.m_MinimaList;t!==null;){this.InsertScanbeam(t.Y);var n=t.LeftBound;n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),n=t.RightBound,n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),t=t.Next}this.m_ActiveEdges=null}},e.ClipperBase.prototype.InsertScanbeam=function(t){if(this.m_Scanbeam===null)this.m_Scanbeam=new e.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=t;else if(t>this.m_Scanbeam.Y){var n=new e.Scanbeam;n.Y=t,n.Next=this.m_Scanbeam,this.m_Scanbeam=n}else{for(var r=this.m_Scanbeam;r.Next!==null&&t<=r.Next.Y;)r=r.Next;if(t===r.Y)return;var i=new e.Scanbeam;i.Y=t,i.Next=r.Next,r.Next=i}},e.ClipperBase.prototype.PopScanbeam=function(e){return this.m_Scanbeam===null?(e.v=0,!1):(e.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},e.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},e.ClipperBase.prototype.CreateOutRec=function(){var t=new e.OutRec;return t.Idx=e.ClipperBase.Unassigned,t.IsHole=!1,t.IsOpen=!1,t.FirstLeft=null,t.Pts=null,t.BottomPt=null,t.PolyNode=null,this.m_PolyOuts.push(t),t.Idx=this.m_PolyOuts.length-1,t},e.ClipperBase.prototype.DisposeOutRec=function(e){var t=this.m_PolyOuts[e];t.Pts=null,t=null,this.m_PolyOuts[e]=null},e.ClipperBase.prototype.UpdateEdgeIntoAEL=function(t){t.NextInLML===null&&e.Error(`UpdateEdgeIntoAEL: invalid call`);var n=t.PrevInAEL,r=t.NextInAEL;return t.NextInLML.OutIdx=t.OutIdx,n===null?this.m_ActiveEdges=t.NextInLML:n.NextInAEL=t.NextInLML,r!==null&&(r.PrevInAEL=t.NextInLML),t.NextInLML.Side=t.Side,t.NextInLML.WindDelta=t.WindDelta,t.NextInLML.WindCnt=t.WindCnt,t.NextInLML.WindCnt2=t.WindCnt2,t=t.NextInLML,t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,t.PrevInAEL=n,t.NextInAEL=r,e.ClipperBase.IsHorizontal(t)||this.InsertScanbeam(t.Top.Y),t},e.ClipperBase.prototype.SwapPositionsInAEL=function(e,t){if(e.NextInAEL!==e.PrevInAEL&&t.NextInAEL!==t.PrevInAEL){if(e.NextInAEL===t){var n=t.NextInAEL;n!==null&&(n.PrevInAEL=e);var r=e.PrevInAEL;r!==null&&(r.NextInAEL=t),t.PrevInAEL=r,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=n}else if(t.NextInAEL===e){var i=e.NextInAEL;i!==null&&(i.PrevInAEL=t);var a=t.PrevInAEL;a!==null&&(a.NextInAEL=e),e.PrevInAEL=a,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else{var o=e.NextInAEL,s=e.PrevInAEL;e.NextInAEL=t.NextInAEL,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=t.PrevInAEL,e.PrevInAEL!==null&&(e.PrevInAEL.NextInAEL=e),t.NextInAEL=o,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=s,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t)}e.PrevInAEL===null?this.m_ActiveEdges=e:t.PrevInAEL===null&&(this.m_ActiveEdges=t)}},e.ClipperBase.prototype.DeleteFromAEL=function(e){var t=e.PrevInAEL,n=e.NextInAEL;(t!==null||n!==null||e===this.m_ActiveEdges)&&(t===null?this.m_ActiveEdges=n:t.NextInAEL=n,n!==null&&(n.PrevInAEL=t),e.NextInAEL=null,e.PrevInAEL=null)},e.Clipper=function(t){t===void 0&&(t=0),this.m_PolyOuts=null,this.m_ClipType=e.ClipType.ctIntersection,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=null,this.m_IntersectNodeComparer=null,this.m_ExecuteLocked=!1,this.m_ClipFillType=e.PolyFillType.pftEvenOdd,this.m_SubjFillType=e.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,e.ClipperBase.call(this),this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=[],this.m_IntersectNodeComparer=e.MyIntersectNodeSort.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=[],this.m_Joins=[],this.m_GhostJoins=[],this.ReverseSolution=!!(1&t),this.StrictlySimple=!!(2&t),this.PreserveCollinear=!!(4&t),e.use_xyz&&(this.ZFillFunction=null)},e.Clipper.ioReverseSolution=1,e.Clipper.ioStrictlySimple=2,e.Clipper.ioPreserveCollinear=4,e.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),e.ClipperBase.prototype.Clear.call(this))},e.Clipper.prototype.InsertMaxima=function(t){var n=new e.Maxima;if(n.X=t,this.m_Maxima===null)this.m_Maxima=n,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(t<this.m_Maxima.X)n.Next=this.m_Maxima,n.Prev=null,this.m_Maxima=n;else{for(var r=this.m_Maxima;r.Next!==null&&t>=r.Next.X;)r=r.Next;if(t===r.X)return;n.Next=r.Next,n.Prev=r,r.Next!==null&&(r.Next.Prev=n),r.Next=n}},e.Clipper.prototype.Execute=function(){var t=arguments,n=t.length,r=t[1]instanceof e.PolyTree;if(n===4&&!r){var i=t[0],a=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&e.Error(`Error: PolyTree struct is needed for open path clipping.`),this.m_ExecuteLocked=!0,e.Clear(a),this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!1;try{var c=this.ExecuteInternal();c&&this.BuildResult(a)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===4&&r){var i=t[0],l=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!0;try{var c=this.ExecuteInternal();c&&this.BuildResult2(l)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===2&&!r){var i=t[0],a=t[1];return this.Execute(i,a,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}if(n===2&&r){var i=t[0],l=t[1];return this.Execute(i,l,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}},e.Clipper.prototype.FixHoleLinkage=function(e){if(!(e.FirstLeft===null||e.IsHole!==e.FirstLeft.IsHole&&e.FirstLeft.Pts!==null)){for(var t=e.FirstLeft;t!==null&&(t.IsHole===e.IsHole||t.Pts===null);)t=t.FirstLeft;e.FirstLeft=t}},e.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var e={},t={};if(!this.PopScanbeam(e))return!1;for(this.InsertLocalMinimaIntoAEL(e.v);this.PopScanbeam(t)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(t.v))return!1;this.ProcessEdgesAtTopOfScanbeam(t.v),e.v=t.v,this.InsertLocalMinimaIntoAEL(e.v)}for(var n,r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts===null||n.IsOpen||(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts);for(this.JoinCommonEdges(),r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts!==null&&(n.IsOpen?this.FixupOutPolyline(n):this.FixupOutPolygon(n));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},e.Clipper.prototype.DisposeAllPolyPts=function(){for(var t=0,n=this.m_PolyOuts.length;t<n;++t)this.DisposeOutRec(t);e.Clear(this.m_PolyOuts)},e.Clipper.prototype.AddJoin=function(t,n,r){var i=new e.Join;i.OutPt1=t,i.OutPt2=n,i.OffPt.X=r.X,i.OffPt.Y=r.Y,e.use_xyz&&(i.OffPt.Z=r.Z),this.m_Joins.push(i)},e.Clipper.prototype.AddGhostJoin=function(t,n){var r=new e.Join;r.OutPt1=t,r.OffPt.X=n.X,r.OffPt.Y=n.Y,e.use_xyz&&(r.OffPt.Z=n.Z),this.m_GhostJoins.push(r)},e.Clipper.prototype.SetZ=function(t,n,r){if(this.ZFillFunction!==null){if(t.Z!==0||this.ZFillFunction===null)return;e.IntPoint.op_Equality(t,n.Bot)?t.Z=n.Bot.Z:e.IntPoint.op_Equality(t,n.Top)?t.Z=n.Top.Z:e.IntPoint.op_Equality(t,r.Bot)?t.Z=r.Bot.Z:e.IntPoint.op_Equality(t,r.Top)?t.Z=r.Top.Z:this.ZFillFunction(n.Bot,n.Top,r.Bot,r.Top,t)}},e.Clipper.prototype.InsertLocalMinimaIntoAEL=function(t){for(var n={},r,i;this.PopLocalMinima(t,n);){r=n.v.LeftBound,i=n.v.RightBound;var a=null;if(r===null?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(a=this.AddOutPt(i,i.Bot))):i===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(a=this.AddOutPt(r,r.Bot)),this.InsertScanbeam(r.Top.Y)):(this.InsertEdgeIntoAEL(r,null),this.InsertEdgeIntoAEL(i,r),this.SetWindingCount(r),i.WindCnt=r.WindCnt,i.WindCnt2=r.WindCnt2,this.IsContributing(r)&&(a=this.AddLocalMinPoly(r,i,r.Bot)),this.InsertScanbeam(r.Top.Y)),i!==null&&(e.ClipperBase.IsHorizontal(i)?(i.NextInLML!==null&&this.InsertScanbeam(i.NextInLML.Top.Y),this.AddEdgeToSEL(i)):this.InsertScanbeam(i.Top.Y)),r!==null&&i!==null){if(a!==null&&e.ClipperBase.IsHorizontal(i)&&this.m_GhostJoins.length>0&&i.WindDelta!==0)for(var o=0,s=this.m_GhostJoins.length;o<s;o++){var c=this.m_GhostJoins[o];this.HorzSegmentsOverlap(c.OutPt1.Pt.X,c.OffPt.X,i.Bot.X,i.Top.X)&&this.AddJoin(c.OutPt1,a,c.OffPt)}if(r.OutIdx>=0&&r.PrevInAEL!==null&&r.PrevInAEL.Curr.X===r.Bot.X&&r.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(r.PrevInAEL.Curr,r.PrevInAEL.Top,r.Curr,r.Top,this.m_UseFullRange)&&r.WindDelta!==0&&r.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(a,l,r.Top)}if(r.NextInAEL!==i){if(i.OutIdx>=0&&i.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top,this.m_UseFullRange)&&i.WindDelta!==0&&i.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(a,l,i.Top)}var u=r.NextInAEL;if(u!==null)for(;u!==i;)this.IntersectEdges(i,u,r.Curr),u=u.NextInAEL}}}},e.Clipper.prototype.InsertEdgeIntoAEL=function(e,t){if(this.m_ActiveEdges===null)e.PrevInAEL=null,e.NextInAEL=null,this.m_ActiveEdges=e;else if(t===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,e))e.PrevInAEL=null,e.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=e,this.m_ActiveEdges=e;else{for(t===null&&(t=this.m_ActiveEdges);t.NextInAEL!==null&&!this.E2InsertsBeforeE1(t.NextInAEL,e);)t=t.NextInAEL;e.NextInAEL=t.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=e),e.PrevInAEL=t,t.NextInAEL=e}},e.Clipper.prototype.E2InsertsBeforeE1=function(t,n){return n.Curr.X===t.Curr.X?n.Top.Y>t.Top.Y?n.Top.X<e.Clipper.TopX(t,n.Top.Y):t.Top.X>e.Clipper.TopX(n,t.Top.Y):n.Curr.X<t.Curr.X},e.Clipper.prototype.IsEvenOddFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType===e.PolyFillType.pftEvenOdd:this.m_ClipFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsEvenOddAltFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_ClipFillType===e.PolyFillType.pftEvenOdd:this.m_SubjFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsContributing=function(t){var n,r;switch(t.PolyTyp===e.PolyType.ptSubject?(n=this.m_SubjFillType,r=this.m_ClipFillType):(n=this.m_ClipFillType,r=this.m_SubjFillType),n){case e.PolyFillType.pftEvenOdd:if(t.WindDelta===0&&t.WindCnt!==1)return!1;break;case e.PolyFillType.pftNonZero:if(Math.abs(t.WindCnt)!==1)return!1;break;case e.PolyFillType.pftPositive:if(t.WindCnt!==1)return!1;break;default:if(t.WindCnt!==-1)return!1}switch(this.m_ClipType){case e.ClipType.ctIntersection:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctUnion:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case e.ClipType.ctDifference:if(t.PolyTyp===e.PolyType.ptSubject)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctXor:if(t.WindDelta===0)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else return!0}return!0},e.Clipper.prototype.SetWindingCount=function(t){for(var n=t.PrevInAEL;n!==null&&(n.PolyTyp!==t.PolyTyp||n.WindDelta===0);)n=n.PrevInAEL;if(n===null){var r=t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;t.WindCnt=t.WindDelta===0?r===e.PolyFillType.pftNegative?-1:1:t.WindDelta,t.WindCnt2=0,n=this.m_ActiveEdges}else if(t.WindDelta===0&&this.m_ClipType!==e.ClipType.ctUnion)t.WindCnt=1,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;else if(this.IsEvenOddFillType(t)){if(t.WindDelta===0){for(var i=!0,a=n.PrevInAEL;a!==null;)a.PolyTyp===n.PolyTyp&&a.WindDelta!==0&&(i=!i),a=a.PrevInAEL;t.WindCnt=+!i}else t.WindCnt=t.WindDelta;t.WindCnt2=n.WindCnt2,n=n.NextInAEL}else t.WindCnt=n.WindCnt*n.WindDelta<0?Math.abs(n.WindCnt)>1?n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta:t.WindDelta===0?1:t.WindDelta:t.WindDelta===0?n.WindCnt<0?n.WindCnt-1:n.WindCnt+1:n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;n!==t;)n.WindDelta!==0&&(t.WindCnt2=+(t.WindCnt2===0)),n=n.NextInAEL;else for(;n!==t;)t.WindCnt2+=n.WindDelta,n=n.NextInAEL},e.Clipper.prototype.AddEdgeToSEL=function(e){this.m_SortedEdges===null?(this.m_SortedEdges=e,e.PrevInSEL=null,e.NextInSEL=null):(e.NextInSEL=this.m_SortedEdges,e.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=e,this.m_SortedEdges=e)},e.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,e.v===null)return!1;var t=e.v;return this.m_SortedEdges=e.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),t.NextInSEL=null,t.PrevInSEL=null,!0},e.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;e!==null;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},e.Clipper.prototype.SwapPositionsInSEL=function(e,t){if((e.NextInSEL!==null||e.PrevInSEL!==null)&&(t.NextInSEL!==null||t.PrevInSEL!==null)){if(e.NextInSEL===t){var n=t.NextInSEL;n!==null&&(n.PrevInSEL=e);var r=e.PrevInSEL;r!==null&&(r.NextInSEL=t),t.PrevInSEL=r,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=n}else if(t.NextInSEL===e){var n=e.NextInSEL;n!==null&&(n.PrevInSEL=t);var r=t.PrevInSEL;r!==null&&(r.NextInSEL=e),e.PrevInSEL=r,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=n}else{var n=e.NextInSEL,r=e.PrevInSEL;e.NextInSEL=t.NextInSEL,e.NextInSEL!==null&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=t.PrevInSEL,e.PrevInSEL!==null&&(e.PrevInSEL.NextInSEL=e),t.NextInSEL=n,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=r,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t)}e.PrevInSEL===null?this.m_SortedEdges=e:t.PrevInSEL===null&&(this.m_SortedEdges=t)}},e.Clipper.prototype.AddLocalMaxPoly=function(e,t,n){this.AddOutPt(e,n),t.WindDelta===0&&this.AddOutPt(t,n),e.OutIdx===t.OutIdx?(e.OutIdx=-1,t.OutIdx=-1):e.OutIdx<t.OutIdx?this.AppendPolygon(e,t):this.AppendPolygon(t,e)},e.Clipper.prototype.AddLocalMinPoly=function(t,n,r){var i,a,o;if(e.ClipperBase.IsHorizontal(n)||t.Dx>n.Dx?(i=this.AddOutPt(t,r),n.OutIdx=t.OutIdx,t.Side=e.EdgeSide.esLeft,n.Side=e.EdgeSide.esRight,a=t,o=a.PrevInAEL===n?n.PrevInAEL:a.PrevInAEL):(i=this.AddOutPt(n,r),t.OutIdx=n.OutIdx,t.Side=e.EdgeSide.esRight,n.Side=e.EdgeSide.esLeft,a=n,o=a.PrevInAEL===t?t.PrevInAEL:a.PrevInAEL),o!==null&&o.OutIdx>=0&&o.Top.Y<r.Y&&a.Top.Y<r.Y){var s=e.Clipper.TopX(o,r.Y),c=e.Clipper.TopX(a,r.Y);if(s===c&&a.WindDelta!==0&&o.WindDelta!==0&&e.ClipperBase.SlopesEqual5(new e.IntPoint2(s,r.Y),o.Top,new e.IntPoint2(c,r.Y),a.Top,this.m_UseFullRange)){var l=this.AddOutPt(o,r);this.AddJoin(i,l,a.Top)}}return i},e.Clipper.prototype.AddOutPt=function(t,n){if(t.OutIdx<0){var r=this.CreateOutRec();r.IsOpen=t.WindDelta===0;var i=new e.OutPt;return r.Pts=i,i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=i,i.Prev=i,r.IsOpen||this.SetHoleState(t,r),t.OutIdx=r.Idx,i}var r=this.m_PolyOuts[t.OutIdx],a=r.Pts,o=t.Side===e.EdgeSide.esLeft;if(o&&e.IntPoint.op_Equality(n,a.Pt))return a;if(!o&&e.IntPoint.op_Equality(n,a.Prev.Pt))return a.Prev;var i=new e.OutPt;return i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=a,i.Prev=a.Prev,i.Prev.Next=i,a.Prev=i,o&&(r.Pts=i),i},e.Clipper.prototype.GetLastOutPt=function(t){var n=this.m_PolyOuts[t.OutIdx];return t.Side===e.EdgeSide.esLeft?n.Pts:n.Pts.Prev},e.Clipper.prototype.SwapPoints=function(t,n){var r=new e.IntPoint1(t.Value);t.Value.X=n.Value.X,t.Value.Y=n.Value.Y,e.use_xyz&&(t.Value.Z=n.Value.Z),n.Value.X=r.X,n.Value.Y=r.Y,e.use_xyz&&(n.Value.Z=r.Z)},e.Clipper.prototype.HorzSegmentsOverlap=function(e,t,n,r){var i;return e>t&&(i=e,e=t,t=i),n>r&&(i=n,n=r,r=i),e<r&&n<t},e.Clipper.prototype.SetHoleState=function(e,t){for(var n=e.PrevInAEL,r=null;n!==null;)n.OutIdx>=0&&n.WindDelta!==0&&(r===null?r=n:r.OutIdx===n.OutIdx&&(r=null)),n=n.PrevInAEL;r===null?(t.FirstLeft=null,t.IsHole=!1):(t.FirstLeft=this.m_PolyOuts[r.OutIdx],t.IsHole=!t.FirstLeft.IsHole)},e.Clipper.prototype.GetDx=function(t,n){return t.Y===n.Y?e.ClipperBase.horizontal:(n.X-t.X)/(n.Y-t.Y)},e.Clipper.prototype.FirstIsBottomPt=function(t,n){for(var r=t.Prev;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Prev;var i=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=t.Next;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Next;var a=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=n.Prev;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Prev;var o=Math.abs(this.GetDx(n.Pt,r.Pt));for(r=n.Next;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Next;var s=Math.abs(this.GetDx(n.Pt,r.Pt));return Math.max(i,a)===Math.max(o,s)&&Math.min(i,a)===Math.min(o,s)?this.Area(t)>0:i>=o&&i>=s||a>=o&&a>=s},e.Clipper.prototype.GetBottomPt=function(t){for(var n=null,r=t.Next;r!==t;)r.Pt.Y>t.Pt.Y?(t=r,n=null):r.Pt.Y===t.Pt.Y&&r.Pt.X<=t.Pt.X&&(r.Pt.X<t.Pt.X?(n=null,t=r):r.Next!==t&&r.Prev!==t&&(n=r)),r=r.Next;if(n!==null)for(;n!==r;)for(this.FirstIsBottomPt(r,n)||(t=n),n=n.Next;e.IntPoint.op_Inequality(n.Pt,t.Pt);)n=n.Next;return t},e.Clipper.prototype.GetLowermostRec=function(e,t){e.BottomPt===null&&(e.BottomPt=this.GetBottomPt(e.Pts)),t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts));var n=e.BottomPt,r=t.BottomPt;return n.Pt.Y>r.Pt.Y?e:n.Pt.Y<r.Pt.Y?t:n.Pt.X<r.Pt.X?e:n.Pt.X>r.Pt.X||n.Next===n?t:r.Next===r||this.FirstIsBottomPt(n,r)?e:t},e.Clipper.prototype.OutRec1RightOfOutRec2=function(e,t){do if(e=e.FirstLeft,e===t)return!0;while(e!==null);return!1},e.Clipper.prototype.GetOutRec=function(e){for(var t=this.m_PolyOuts[e];t!==this.m_PolyOuts[t.Idx];)t=this.m_PolyOuts[t.Idx];return t},e.Clipper.prototype.AppendPolygon=function(t,n){var r=this.m_PolyOuts[t.OutIdx],i=this.m_PolyOuts[n.OutIdx],a=this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i),o=r.Pts,s=o.Prev,c=i.Pts,l=c.Prev;t.Side===e.EdgeSide.esLeft?n.Side===e.EdgeSide.esLeft?(this.ReversePolyPtLinks(c),c.Next=o,o.Prev=c,s.Next=l,l.Prev=s,r.Pts=l):(l.Next=o,o.Prev=l,c.Prev=s,s.Next=c,r.Pts=c):n.Side===e.EdgeSide.esRight?(this.ReversePolyPtLinks(c),s.Next=l,l.Prev=s,c.Next=o,o.Prev=c):(s.Next=c,c.Prev=s,o.Prev=l,l.Next=o),r.BottomPt=null,a===i&&(i.FirstLeft!==r&&(r.FirstLeft=i.FirstLeft),r.IsHole=i.IsHole),i.Pts=null,i.BottomPt=null,i.FirstLeft=r;var u=t.OutIdx,d=n.OutIdx;t.OutIdx=-1,n.OutIdx=-1;for(var f=this.m_ActiveEdges;f!==null;){if(f.OutIdx===d){f.OutIdx=u,f.Side=t.Side;break}f=f.NextInAEL}i.Idx=r.Idx},e.Clipper.prototype.ReversePolyPtLinks=function(e){if(e!==null){var t=e,n;do n=t.Next,t.Next=t.Prev,t.Prev=n,t=n;while(t!==e)}},e.Clipper.SwapSides=function(e,t){var n=e.Side;e.Side=t.Side,t.Side=n},e.Clipper.SwapPolyIndexes=function(e,t){var n=e.OutIdx;e.OutIdx=t.OutIdx,t.OutIdx=n},e.Clipper.prototype.IntersectEdges=function(t,n,r){var i=t.OutIdx>=0,a=n.OutIdx>=0;if(e.use_xyz&&this.SetZ(r,t,n),e.use_lines&&(t.WindDelta===0||n.WindDelta===0)){if(t.WindDelta===0&&n.WindDelta===0)return;t.PolyTyp===n.PolyTyp&&t.WindDelta!==n.WindDelta&&this.m_ClipType===e.ClipType.ctUnion?t.WindDelta===0?a&&(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):i&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)):t.PolyTyp!==n.PolyTyp&&(t.WindDelta===0&&Math.abs(n.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||n.WindCnt2===0)?(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):n.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||t.WindCnt2===0)&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)))}else{if(t.PolyTyp===n.PolyTyp){if(this.IsEvenOddFillType(t)){var o=t.WindCnt;t.WindCnt=n.WindCnt,n.WindCnt=o}else t.WindCnt+n.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt+=n.WindDelta,n.WindCnt-t.WindDelta===0?n.WindCnt=-n.WindCnt:n.WindCnt-=t.WindDelta}else this.IsEvenOddFillType(n)?t.WindCnt2=+(t.WindCnt2===0):t.WindCnt2+=n.WindDelta,this.IsEvenOddFillType(t)?n.WindCnt2=+(n.WindCnt2===0):n.WindCnt2-=t.WindDelta;var s,c,l,u;t.PolyTyp===e.PolyType.ptSubject?(s=this.m_SubjFillType,l=this.m_ClipFillType):(s=this.m_ClipFillType,l=this.m_SubjFillType),n.PolyTyp===e.PolyType.ptSubject?(c=this.m_SubjFillType,u=this.m_ClipFillType):(c=this.m_ClipFillType,u=this.m_SubjFillType);var d,f;switch(s){case e.PolyFillType.pftPositive:d=t.WindCnt;break;case e.PolyFillType.pftNegative:d=-t.WindCnt;break;default:d=Math.abs(t.WindCnt)}switch(c){case e.PolyFillType.pftPositive:f=n.WindCnt;break;case e.PolyFillType.pftNegative:f=-n.WindCnt;break;default:f=Math.abs(n.WindCnt)}if(i&&a)d!==0&&d!==1||f!==0&&f!==1||t.PolyTyp!==n.PolyTyp&&this.m_ClipType!==e.ClipType.ctXor?this.AddLocalMaxPoly(t,n,r):(this.AddOutPt(t,r),this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(i)(f===0||f===1)&&(this.AddOutPt(t,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(a)(d===0||d===1)&&(this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if((d===0||d===1)&&(f===0||f===1)){var p,m;switch(l){case e.PolyFillType.pftPositive:p=t.WindCnt2;break;case e.PolyFillType.pftNegative:p=-t.WindCnt2;break;default:p=Math.abs(t.WindCnt2)}switch(u){case e.PolyFillType.pftPositive:m=n.WindCnt2;break;case e.PolyFillType.pftNegative:m=-n.WindCnt2;break;default:m=Math.abs(n.WindCnt2)}if(t.PolyTyp!==n.PolyTyp)this.AddLocalMinPoly(t,n,r);else if(d===1&&f===1)switch(this.m_ClipType){case e.ClipType.ctIntersection:p>0&&m>0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctUnion:p<=0&&m<=0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctDifference:(t.PolyTyp===e.PolyType.ptClip&&p>0&&m>0||t.PolyTyp===e.PolyType.ptSubject&&p<=0&&m<=0)&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctXor:this.AddLocalMinPoly(t,n,r)}else e.Clipper.SwapSides(t,n)}}},e.Clipper.prototype.DeleteFromSEL=function(e){var t=e.PrevInSEL,n=e.NextInSEL;(t!==null||n!==null||e===this.m_SortedEdges)&&(t===null?this.m_SortedEdges=n:t.NextInSEL=n,n!==null&&(n.PrevInSEL=t),e.NextInSEL=null,e.PrevInSEL=null)},e.Clipper.prototype.ProcessHorizontals=function(){for(var e={};this.PopEdgeFromSEL(e);)this.ProcessHorizontal(e.v)},e.Clipper.prototype.GetHorzDirection=function(t,n){t.Bot.X<t.Top.X?(n.Left=t.Bot.X,n.Right=t.Top.X,n.Dir=e.Direction.dLeftToRight):(n.Left=t.Top.X,n.Right=t.Bot.X,n.Dir=e.Direction.dRightToLeft)},e.Clipper.prototype.ProcessHorizontal=function(t){var n={Dir:null,Left:null,Right:null};this.GetHorzDirection(t,n);for(var r=n.Dir,i=n.Left,a=n.Right,o=t.WindDelta===0,s=t,c=null;s.NextInLML!==null&&e.ClipperBase.IsHorizontal(s.NextInLML);)s=s.NextInLML;s.NextInLML===null&&(c=this.GetMaximaPair(s));var l=this.m_Maxima;if(l!==null){if(r===e.Direction.dLeftToRight){for(;l!==null&&l.X<=t.Bot.X;)l=l.Next;l!==null&&l.X>=s.Top.X&&(l=null)}else{for(;l.Next!==null&&l.Next.X<t.Bot.X;)l=l.Next;l.X<=s.Top.X&&(l=null)}}for(var u=null;;){for(var d=t===s,f=this.GetNextInAEL(t,r);f!==null;){if(l!==null){if(r===e.Direction.dLeftToRight)for(;l!==null&&l.X<f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Next;else for(;l!==null&&l.X>f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Prev}if(r===e.Direction.dLeftToRight&&f.Curr.X>a||r===e.Direction.dRightToLeft&&f.Curr.X<i||f.Curr.X===t.Top.X&&t.NextInLML!==null&&f.Dx<t.NextInLML.Dx)break;if(t.OutIdx>=0&&!o){e.use_xyz&&(r===e.Direction.dLeftToRight?this.SetZ(f.Curr,t,f):this.SetZ(f.Curr,f,t)),u=this.AddOutPt(t,f.Curr);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Bot)}if(f===c&&d){t.OutIdx>=0&&this.AddLocalMaxPoly(t,c,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(c);return}if(r===e.Direction.dLeftToRight){var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(t,f,h)}else{var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(f,t,h)}var g=this.GetNextInAEL(f,r);this.SwapPositionsInAEL(t,f),f=g}if(t.NextInLML===null||!e.ClipperBase.IsHorizontal(t.NextInLML))break;t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),n={Dir:r,Left:i,Right:a},this.GetHorzDirection(t,n),r=n.Dir,i=n.Left,a=n.Right}if(t.OutIdx>=0&&u===null){u=this.GetLastOutPt(t);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Top)}if(t.NextInLML!==null){if(t.OutIdx>=0){if(u=this.AddOutPt(t,t.Top),t=this.UpdateEdgeIntoAEL(t),t.WindDelta===0)return;var _=t.PrevInAEL,g=t.NextInAEL;if(_!==null&&_.Curr.X===t.Bot.X&&_.Curr.Y===t.Bot.Y&&_.WindDelta===0&&_.OutIdx>=0&&_.Curr.Y>_.Top.Y&&e.ClipperBase.SlopesEqual3(t,_,this.m_UseFullRange)){var m=this.AddOutPt(_,t.Bot);this.AddJoin(u,m,t.Top)}else if(g!==null&&g.Curr.X===t.Bot.X&&g.Curr.Y===t.Bot.Y&&g.WindDelta!==0&&g.OutIdx>=0&&g.Curr.Y>g.Top.Y&&e.ClipperBase.SlopesEqual3(t,g,this.m_UseFullRange)){var m=this.AddOutPt(g,t.Bot);this.AddJoin(u,m,t.Top)}}else t=this.UpdateEdgeIntoAEL(t)}else t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t)},e.Clipper.prototype.GetNextInAEL=function(t,n){return n===e.Direction.dLeftToRight?t.NextInAEL:t.PrevInAEL},e.Clipper.prototype.IsMinima=function(e){return e!==null&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},e.Clipper.prototype.IsMaxima=function(e,t){return e!==null&&e.Top.Y===t&&e.NextInLML===null},e.Clipper.prototype.IsIntermediate=function(e,t){return e.Top.Y===t&&e.NextInLML!==null},e.Clipper.prototype.GetMaximaPair=function(t){return e.IntPoint.op_Equality(t.Next.Top,t.Top)&&t.Next.NextInLML===null?t.Next:e.IntPoint.op_Equality(t.Prev.Top,t.Top)&&t.Prev.NextInLML===null?t.Prev:null},e.Clipper.prototype.GetMaximaPairEx=function(t){var n=this.GetMaximaPair(t);return n===null||n.OutIdx===e.ClipperBase.Skip||n.NextInAEL===n.PrevInAEL&&!e.ClipperBase.IsHorizontal(n)?null:n},e.Clipper.prototype.ProcessIntersections=function(t){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(t),this.m_IntersectList.length===0)return!0;if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,e.Error(`ProcessIntersections error`)}return this.m_SortedEdges=null,!0},e.Clipper.prototype.BuildIntersectList=function(t){if(this.m_ActiveEdges!==null){var n=this.m_ActiveEdges;for(this.m_SortedEdges=n;n!==null;)n.PrevInSEL=n.PrevInAEL,n.NextInSEL=n.NextInAEL,n.Curr.X=e.Clipper.TopX(n,t),n=n.NextInAEL;for(var r=!0;r&&this.m_SortedEdges!==null;){for(r=!1,n=this.m_SortedEdges;n.NextInSEL!==null;){var i=n.NextInSEL,a=new e.IntPoint0;if(n.Curr.X>i.Curr.X){this.IntersectPoint(n,i,a),a.Y<t&&(a=new e.IntPoint2(e.Clipper.TopX(n,t),t));var o=new e.IntersectNode;o.Edge1=n,o.Edge2=i,o.Pt.X=a.X,o.Pt.Y=a.Y,e.use_xyz&&(o.Pt.Z=a.Z),this.m_IntersectList.push(o),this.SwapPositionsInSEL(n,i),r=!0}else n=i}if(n.PrevInSEL!==null)n.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},e.Clipper.prototype.EdgesAdjacent=function(e){return e.Edge1.NextInSEL===e.Edge2||e.Edge1.PrevInSEL===e.Edge2},e.Clipper.IntersectNodeSort=function(e,t){return t.Pt.Y-e.Pt.Y},e.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var e=this.m_IntersectList.length,t=0;t<e;t++){if(!this.EdgesAdjacent(this.m_IntersectList[t])){for(var n=t+1;n<e&&!this.EdgesAdjacent(this.m_IntersectList[n]);)n++;if(n===e)return!1;var r=this.m_IntersectList[t];this.m_IntersectList[t]=this.m_IntersectList[n],this.m_IntersectList[n]=r}this.SwapPositionsInSEL(this.m_IntersectList[t].Edge1,this.m_IntersectList[t].Edge2)}return!0},e.Clipper.prototype.ProcessIntersectList=function(){for(var e=0,t=this.m_IntersectList.length;e<t;e++){var n=this.m_IntersectList[e];this.IntersectEdges(n.Edge1,n.Edge2,n.Pt),this.SwapPositionsInAEL(n.Edge1,n.Edge2)}this.m_IntersectList.length=0};var Tt=function(e){return e<0?Math.ceil(e-.5):Math.round(e)},Et=function(e){return e<0?Math.ceil(e-.5):Math.floor(e+.5)},Dt=function(e){return e<0?-Math.round(Math.abs(e)):Math.round(e)},Ot=function(e){return e<0?(e-=.5,e<-2147483648?Math.ceil(e):e|0):(e+=.5,e>2147483647?Math.floor(e):e|0)};a.msie?e.Clipper.Round=Tt:a.chromium?e.Clipper.Round=Dt:a.safari?e.Clipper.Round=Ot:e.Clipper.Round=Et,e.Clipper.TopX=function(t,n){return n===t.Top.Y?t.Top.X:t.Bot.X+e.Clipper.Round(t.Dx*(n-t.Bot.Y))},e.Clipper.prototype.IntersectPoint=function(t,n,r){r.X=0,r.Y=0;var i,a;if(t.Dx===n.Dx)r.Y=t.Curr.Y,r.X=e.Clipper.TopX(t,r.Y);else{if(t.Delta.X===0)r.X=t.Bot.X,e.ClipperBase.IsHorizontal(n)?r.Y=n.Bot.Y:(a=n.Bot.Y-n.Bot.X/n.Dx,r.Y=e.Clipper.Round(r.X/n.Dx+a));else if(n.Delta.X===0)r.X=n.Bot.X,e.ClipperBase.IsHorizontal(t)?r.Y=t.Bot.Y:(i=t.Bot.Y-t.Bot.X/t.Dx,r.Y=e.Clipper.Round(r.X/t.Dx+i));else{i=t.Bot.X-t.Bot.Y*t.Dx,a=n.Bot.X-n.Bot.Y*n.Dx;var o=(a-i)/(t.Dx-n.Dx);r.Y=e.Clipper.Round(o),r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.Round(t.Dx*o+i):e.Clipper.Round(n.Dx*o+a)}if(r.Y<t.Top.Y||r.Y<n.Top.Y){if(t.Top.Y>n.Top.Y)return r.Y=t.Top.Y,r.X=e.Clipper.TopX(n,t.Top.Y),r.X<t.Top.X;r.Y=n.Top.Y,r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.TopX(t,r.Y):e.Clipper.TopX(n,r.Y)}r.Y>t.Curr.Y&&(r.Y=t.Curr.Y,r.X=Math.abs(t.Dx)>Math.abs(n.Dx)?e.Clipper.TopX(n,r.Y):e.Clipper.TopX(t,r.Y))}},e.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(t){for(var n=this.m_ActiveEdges;n!==null;){var r=this.IsMaxima(n,t);if(r){var i=this.GetMaximaPairEx(n);r=i===null||!e.ClipperBase.IsHorizontal(i)}if(r){this.StrictlySimple&&this.InsertMaxima(n.Top.X);var a=n.PrevInAEL;this.DoMaxima(n),n=a===null?this.m_ActiveEdges:a.NextInAEL}else{if(this.IsIntermediate(n,t)&&e.ClipperBase.IsHorizontal(n.NextInLML)?(n=this.UpdateEdgeIntoAEL(n),n.OutIdx>=0&&this.AddOutPt(n,n.Bot),this.AddEdgeToSEL(n)):(n.Curr.X=e.Clipper.TopX(n,t),n.Curr.Y=t),e.use_xyz&&(n.Top.Y===t?n.Curr.Z=n.Top.Z:n.Bot.Y===t?n.Curr.Z=n.Bot.Z:n.Curr.Z=0),this.StrictlySimple){var a=n.PrevInAEL;if(n.OutIdx>=0&&n.WindDelta!==0&&a!==null&&a.OutIdx>=0&&a.Curr.X===n.Curr.X&&a.WindDelta!==0){var o=new e.IntPoint1(n.Curr);e.use_xyz&&this.SetZ(o,a,n);var s=this.AddOutPt(a,o),c=this.AddOutPt(n,o);this.AddJoin(s,c,o)}}n=n.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,n=this.m_ActiveEdges;n!==null;){if(this.IsIntermediate(n,t)){var s=null;n.OutIdx>=0&&(s=this.AddOutPt(n,n.Top)),n=this.UpdateEdgeIntoAEL(n);var a=n.PrevInAEL,l=n.NextInAEL;if(a!==null&&a.Curr.X===n.Bot.X&&a.Curr.Y===n.Bot.Y&&s!==null&&a.OutIdx>=0&&a.Curr.Y===a.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,a.Curr,a.Top,this.m_UseFullRange)&&n.WindDelta!==0&&a.WindDelta!==0){var c=this.AddOutPt(ePrev2,n.Bot);this.AddJoin(s,c,n.Top)}else if(l!==null&&l.Curr.X===n.Bot.X&&l.Curr.Y===n.Bot.Y&&s!==null&&l.OutIdx>=0&&l.Curr.Y===l.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,l.Curr,l.Top,this.m_UseFullRange)&&n.WindDelta!==0&&l.WindDelta!==0){var c=this.AddOutPt(l,n.Bot);this.AddJoin(s,c,n.Top)}}n=n.NextInAEL}},e.Clipper.prototype.DoMaxima=function(t){var n=this.GetMaximaPairEx(t);if(n===null)t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t);else{for(var r=t.NextInAEL;r!==null&&r!==n;)this.IntersectEdges(t,r,t.Top),this.SwapPositionsInAEL(t,r),r=t.NextInAEL;t.OutIdx===-1&&n.OutIdx===-1?(this.DeleteFromAEL(t),this.DeleteFromAEL(n)):t.OutIdx>=0&&n.OutIdx>=0?(t.OutIdx>=0&&this.AddLocalMaxPoly(t,n,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(n)):e.use_lines&&t.WindDelta===0?(t.OutIdx>=0&&(this.AddOutPt(t,t.Top),t.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(t),n.OutIdx>=0&&(this.AddOutPt(n,t.Top),n.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(n)):e.Error(`DoMaxima error`)}},e.Clipper.ReversePaths=function(e){for(var t=0,n=e.length;t<n;t++)e[t].reverse()},e.Clipper.Orientation=function(t){return e.Clipper.Area(t)>=0},e.Clipper.prototype.PointCount=function(e){if(e===null)return 0;var t=0,n=e;do t++,n=n.Next;while(n!==e);return t},e.Clipper.prototype.BuildResult=function(t){e.Clear(t);for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];if(i.Pts!==null){var a=i.Pts.Prev,o=this.PointCount(a);if(!(o<2)){for(var s=Array(o),c=0;c<o;c++)s[c]=a.Pt,a=a.Prev;t.push(s)}}}},e.Clipper.prototype.BuildResult2=function(t){t.Clear();for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n],a=this.PointCount(i.Pts);if(!(i.IsOpen&&a<2||!i.IsOpen&&a<3)){this.FixHoleLinkage(i);var o=new e.PolyNode;t.m_AllPolys.push(o),i.PolyNode=o,o.m_polygon.length=a;for(var s=i.Pts.Prev,c=0;c<a;c++)o.m_polygon[c]=s.Pt,s=s.Prev}}for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];i.PolyNode!==null&&(i.IsOpen?(i.PolyNode.IsOpen=!0,t.AddChild(i.PolyNode)):i.FirstLeft!==null&&i.FirstLeft.PolyNode!==null?i.FirstLeft.PolyNode.AddChild(i.PolyNode):t.AddChild(i.PolyNode))}},e.Clipper.prototype.FixupOutPolyline=function(t){for(var n=t.Pts,r=n.Prev;n!==r;)if(n=n.Next,e.IntPoint.op_Equality(n.Pt,n.Prev.Pt)){n===r&&(r=n.Prev);var i=n.Prev;i.Next=n.Next,n.Next.Prev=i,n=i}n===n.Prev&&(t.Pts=null)},e.Clipper.prototype.FixupOutPolygon=function(t){var n=null;t.BottomPt=null;for(var r=t.Pts,i=this.PreserveCollinear||this.StrictlySimple;;){if(r.Prev===r||r.Prev===r.Next){t.Pts=null;return}if(e.IntPoint.op_Equality(r.Pt,r.Next.Pt)||e.IntPoint.op_Equality(r.Pt,r.Prev.Pt)||e.ClipperBase.SlopesEqual4(r.Prev.Pt,r.Pt,r.Next.Pt,this.m_UseFullRange)&&(!i||!this.Pt2IsBetweenPt1AndPt3(r.Prev.Pt,r.Pt,r.Next.Pt)))n=null,r.Prev.Next=r.Next,r.Next.Prev=r.Prev,r=r.Prev;else if(r===n)break;else n===null&&(n=r),r=r.Next}t.Pts=r},e.Clipper.prototype.DupOutPt=function(t,n){var r=new e.OutPt;return r.Pt.X=t.Pt.X,r.Pt.Y=t.Pt.Y,e.use_xyz&&(r.Pt.Z=t.Pt.Z),r.Idx=t.Idx,n?(r.Next=t.Next,r.Prev=t,t.Next.Prev=r,t.Next=r):(r.Prev=t.Prev,r.Next=t,t.Prev.Next=r,t.Prev=r),r},e.Clipper.prototype.GetOverlap=function(e,t,n,r,i){return e<t?n<r?(i.Left=Math.max(e,n),i.Right=Math.min(t,r)):(i.Left=Math.max(e,r),i.Right=Math.min(t,n)):n<r?(i.Left=Math.max(t,n),i.Right=Math.min(e,r)):(i.Left=Math.max(t,r),i.Right=Math.min(e,n)),i.Left<i.Right},e.Clipper.prototype.JoinHorz=function(t,n,r,i,a,o){var s=t.Pt.X>n.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight,c=r.Pt.X>i.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight;if(s===c)return!1;if(s===e.Direction.dLeftToRight){for(;t.Next.Pt.X<=a.X&&t.Next.Pt.X>=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,!o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,!o))}else{for(;t.Next.Pt.X>=a.X&&t.Next.Pt.X<=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;!o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,o))}if(c===e.Direction.dLeftToRight){for(;r.Next.Pt.X<=a.X&&r.Next.Pt.X>=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,!o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,!o))}else{for(;r.Next.Pt.X>=a.X&&r.Next.Pt.X<=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;!o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,o))}return s===e.Direction.dLeftToRight===o?(t.Prev=r,r.Next=t,n.Next=i,i.Prev=n):(t.Next=r,r.Prev=t,n.Prev=i,i.Next=n),!0},e.Clipper.prototype.JoinPoints=function(t,n,r){var i=t.OutPt1,a=new e.OutPt,o=t.OutPt2,s=new e.OutPt,c=t.OutPt1.Pt.Y===t.OffPt.Y;if(c&&e.IntPoint.op_Equality(t.OffPt,t.OutPt1.Pt)&&e.IntPoint.op_Equality(t.OffPt,t.OutPt2.Pt)){if(n!==r)return!1;for(a=t.OutPt1.Next;a!==i&&e.IntPoint.op_Equality(a.Pt,t.OffPt);)a=a.Next;var l=a.Pt.Y>t.OffPt.Y;for(s=t.OutPt2.Next;s!==o&&e.IntPoint.op_Equality(s.Pt,t.OffPt);)s=s.Next;return l===s.Pt.Y>t.OffPt.Y?!1:l?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)}if(c){for(a=i;i.Prev.Pt.Y===i.Pt.Y&&i.Prev!==a&&i.Prev!==o;)i=i.Prev;for(;a.Next.Pt.Y===a.Pt.Y&&a.Next!==i&&a.Next!==o;)a=a.Next;if(a.Next===i||a.Next===o)return!1;for(s=o;o.Prev.Pt.Y===o.Pt.Y&&o.Prev!==s&&o.Prev!==a;)o=o.Prev;for(;s.Next.Pt.Y===s.Pt.Y&&s.Next!==o&&s.Next!==i;)s=s.Next;if(s.Next===o||s.Next===i)return!1;var u={Left:null,Right:null};if(!this.GetOverlap(i.Pt.X,a.Pt.X,o.Pt.X,s.Pt.X,u))return!1;var d=u.Left,f=u.Right,p=new e.IntPoint0,m;return i.Pt.X>=d&&i.Pt.X<=f?(p.X=i.Pt.X,p.Y=i.Pt.Y,e.use_xyz&&(p.Z=i.Pt.Z),m=i.Pt.X>a.Pt.X):o.Pt.X>=d&&o.Pt.X<=f?(p.X=o.Pt.X,p.Y=o.Pt.Y,e.use_xyz&&(p.Z=o.Pt.Z),m=o.Pt.X>s.Pt.X):a.Pt.X>=d&&a.Pt.X<=f?(p.X=a.Pt.X,p.Y=a.Pt.Y,e.use_xyz&&(p.Z=a.Pt.Z),m=a.Pt.X>i.Pt.X):(p.X=s.Pt.X,p.Y=s.Pt.Y,e.use_xyz&&(p.Z=s.Pt.Z),m=s.Pt.X>o.Pt.X),t.OutPt1=i,t.OutPt2=o,this.JoinHorz(i,a,o,s,p,m)}for(a=i.Next;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Next;var h=a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange);if(h){for(a=i.Prev;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Prev;if(a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange))return!1}for(s=o.Next;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Next;var g=s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange);if(g){for(s=o.Prev;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Prev;if(s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange))return!1}return a===i||s===o||a===s||n===r&&h===g?!1:h?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)},e.Clipper.GetBounds=function(t){for(var n=0,r=t.length;n<r&&t[n].length===0;)n++;if(n===r)return new e.IntRect(0,0,0,0);var i=new e.IntRect;for(i.left=t[n][0].X,i.right=i.left,i.top=t[n][0].Y,i.bottom=i.top;n<r;n++)for(var a=0,o=t[n].length;a<o;a++)t[n][a].X<i.left?i.left=t[n][a].X:t[n][a].X>i.right&&(i.right=t[n][a].X),t[n][a].Y<i.top?i.top=t[n][a].Y:t[n][a].Y>i.bottom&&(i.bottom=t[n][a].Y);return i},e.Clipper.prototype.GetBounds2=function(t){var n=t,r=new e.IntRect;for(r.left=t.Pt.X,r.right=t.Pt.X,r.top=t.Pt.Y,r.bottom=t.Pt.Y,t=t.Next;t!==n;)t.Pt.X<r.left&&(r.left=t.Pt.X),t.Pt.X>r.right&&(r.right=t.Pt.X),t.Pt.Y<r.top&&(r.top=t.Pt.Y),t.Pt.Y>r.bottom&&(r.bottom=t.Pt.Y),t=t.Next;return r},e.Clipper.PointInPolygon=function(e,t){var n=0,r=t.length;if(r<3)return 0;for(var i=t[0],a=1;a<=r;++a){var o=a===r?t[0]:t[a];if(o.Y===e.Y&&(o.X===e.X||i.Y===e.Y&&o.X>e.X==i.X<e.X))return-1;if(i.Y<e.Y!=o.Y<e.Y){if(i.X>=e.X){if(o.X>e.X)n=1-n;else{var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}else if(o.X>e.X){var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}i=o}return n},e.Clipper.prototype.PointInPolygon=function(e,t){var n=0,r=t,i=e.X,a=e.Y,o=t.Pt.X,s=t.Pt.Y;do{t=t.Next;var c=t.Pt.X,l=t.Pt.Y;if(l===a&&(c===i||s===a&&c>i==o<i))return-1;if(s<a!=l<a){if(o>=i){if(c>i)n=1-n;else{var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}else if(c>i){var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}o=c,s=l}while(r!==t);return n},e.Clipper.prototype.Poly2ContainsPoly1=function(e,t){var n=e;do{var r=this.PointInPolygon(n.Pt,t);if(r>=0)return r>0;n=n.Next}while(n!==e);return!0},e.Clipper.prototype.FixupFirstLefts1=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&this.Poly2ContainsPoly1(r.Pts,n.Pts)&&(r.FirstLeft=n)},e.Clipper.prototype.FixupFirstLefts2=function(t,n){for(var r=n.FirstLeft,i,a,o=0,s=this.m_PolyOuts.length;o<s;o++)i=this.m_PolyOuts[o],i.Pts!==null&&i!==n&&i!==t&&(a=e.Clipper.ParseFirstLeft(i.FirstLeft),(a===r||a===t||a===n)&&(this.Poly2ContainsPoly1(i.Pts,t.Pts)?i.FirstLeft=t:this.Poly2ContainsPoly1(i.Pts,n.Pts)?i.FirstLeft=n:(i.FirstLeft===t||i.FirstLeft===n)&&(i.FirstLeft=r)))},e.Clipper.prototype.FixupFirstLefts3=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&(r.FirstLeft=n)},e.Clipper.ParseFirstLeft=function(e){for(;e!==null&&e.Pts===null;)e=e.FirstLeft;return e},e.Clipper.prototype.JoinCommonEdges=function(){for(var e=0,t=this.m_Joins.length;e<t;e++){var n=this.m_Joins[e],r=this.GetOutRec(n.OutPt1.Idx),i=this.GetOutRec(n.OutPt2.Idx);if(r.Pts!==null&&i.Pts!==null&&!(r.IsOpen||i.IsOpen)){var a=r===i?r:this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i);this.JoinPoints(n,r,i)&&(r===i?(r.Pts=n.OutPt1,r.BottomPt=null,i=this.CreateOutRec(),i.Pts=n.OutPt2,this.UpdateOutPtIdxs(i),this.Poly2ContainsPoly1(i.Pts,r.Pts)?(i.IsHole=!r.IsHole,i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,r),(i.IsHole^this.ReverseSolution)==this.Area$1(i)>0&&this.ReversePolyPtLinks(i.Pts)):this.Poly2ContainsPoly1(r.Pts,i.Pts)?(i.IsHole=r.IsHole,r.IsHole=!i.IsHole,i.FirstLeft=r.FirstLeft,r.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,i),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(i.IsHole=r.IsHole,i.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,i))):(i.Pts=null,i.BottomPt=null,i.Idx=r.Idx,r.IsHole=a.IsHole,a===i&&(r.FirstLeft=i.FirstLeft),i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(i,r)))}}},e.Clipper.prototype.UpdateOutPtIdxs=function(e){var t=e.Pts;do t.Idx=e.Idx,t=t.Prev;while(t!==e.Pts)},e.Clipper.prototype.DoSimplePolygons=function(){for(var t=0;t<this.m_PolyOuts.length;){var n=this.m_PolyOuts[t++],r=n.Pts;if(!(r===null||n.IsOpen))do{for(var i=r.Next;i!==n.Pts;){if(e.IntPoint.op_Equality(r.Pt,i.Pt)&&i.Next!==r&&i.Prev!==r){var a=r.Prev,o=i.Prev;r.Prev=o,o.Next=r,i.Prev=a,a.Next=i,n.Pts=r;var s=this.CreateOutRec();s.Pts=i,this.UpdateOutPtIdxs(s),this.Poly2ContainsPoly1(s.Pts,n.Pts)?(s.IsHole=!n.IsHole,s.FirstLeft=n,this.m_UsingPolyTree&&this.FixupFirstLefts2(s,n)):this.Poly2ContainsPoly1(n.Pts,s.Pts)?(s.IsHole=n.IsHole,n.IsHole=!s.IsHole,s.FirstLeft=n.FirstLeft,n.FirstLeft=s,this.m_UsingPolyTree&&this.FixupFirstLefts2(n,s)):(s.IsHole=n.IsHole,s.FirstLeft=n.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(n,s)),i=r}i=i.Next}r=r.Next}while(r!==n.Pts)}},e.Clipper.Area=function(e){if(!Array.isArray(e))return 0;var t=e.length;if(t<3)return 0;for(var n=0,r=0,i=t-1;r<t;++r)n+=(e[i].X+e[r].X)*(e[i].Y-e[r].Y),i=r;return-n*.5},e.Clipper.prototype.Area=function(e){var t=e;if(e===null)return 0;var n=0;do n+=(e.Prev.Pt.X+e.Pt.X)*(e.Prev.Pt.Y-e.Pt.Y),e=e.Next;while(e!==t);return n*.5},e.Clipper.prototype.Area$1=function(e){return this.Area(e.Pts)},e.Clipper.SimplifyPolygon=function(t,n){var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPath(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.SimplifyPolygons=function(t,n){n===void 0&&(n=e.PolyFillType.pftEvenOdd);var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPaths(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.DistanceSqrd=function(e,t){var n=e.X-t.X,r=e.Y-t.Y;return n*n+r*r},e.Clipper.DistanceFromLineSqrd=function(e,t,n){var r=t.Y-n.Y,i=n.X-t.X,a=r*t.X+i*t.Y;return a=r*e.X+i*e.Y-a,a*a/(r*r+i*i)},e.Clipper.SlopesNearCollinear=function(t,n,r,i){return Math.abs(t.X-n.X)>Math.abs(t.Y-n.Y)?t.X>n.X==t.X<r.X?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.X>t.X==n.X<r.X?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i:t.Y>n.Y==t.Y<r.Y?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.Y>t.Y==n.Y<r.Y?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i},e.Clipper.PointsAreClose=function(e,t,n){var r=e.X-t.X,i=e.Y-t.Y;return r*r+i*i<=n},e.Clipper.ExcludeOp=function(e){var t=e.Prev;return t.Next=e.Next,e.Next.Prev=t,t.Idx=0,t},e.Clipper.CleanPolygon=function(t,n){n===void 0&&(n=1.415);var r=t.length;if(r===0)return[];for(var i=Array(r),a=0;a<r;++a)i[a]=new e.OutPt;for(var a=0;a<r;++a)i[a].Pt=t[a],i[a].Next=i[(a+1)%r],i[a].Next.Prev=i[a],i[a].Idx=0;for(var o=n*n,s=i[0];s.Idx===0&&s.Next!==s.Prev;)e.Clipper.PointsAreClose(s.Pt,s.Prev.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):e.Clipper.PointsAreClose(s.Prev.Pt,s.Next.Pt,o)?(e.Clipper.ExcludeOp(s.Next),s=e.Clipper.ExcludeOp(s),r-=2):e.Clipper.SlopesNearCollinear(s.Prev.Pt,s.Pt,s.Next.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):(s.Idx=1,s=s.Next);r<3&&(r=0);for(var c=Array(r),a=0;a<r;++a)c[a]=new e.IntPoint1(s.Pt),s=s.Next;return i=null,c},e.Clipper.CleanPolygons=function(t,n){for(var r=Array(t.length),i=0,a=t.length;i<a;i++)r[i]=e.Clipper.CleanPolygon(t[i],n);return r},e.Clipper.Minkowski=function(t,n,r,i){var a=+!!i,o=t.length,s=n.length,c=[];if(r)for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X+p.X,n[l].Y+p.Y);c.push(u)}else for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X-p.X,n[l].Y-p.Y);c.push(u)}for(var m=[],l=0;l<s-1+a;l++)for(var d=0;d<o;d++){var h=[];h.push(c[l%s][d%o]),h.push(c[(l+1)%s][d%o]),h.push(c[(l+1)%s][(d+1)%o]),h.push(c[l%s][(d+1)%o]),e.Clipper.Orientation(h)||h.reverse(),m.push(h)}return m},e.Clipper.MinkowskiSum=function(t,n,r){if(n[0]instanceof Array){for(var i=n,a=new e.Paths,o=new e.Clipper,s=0;s<i.length;++s){var c=e.Clipper.Minkowski(t,i[s],!0,r);if(o.AddPaths(c,e.PolyType.ptSubject,!0),r){var l=e.Clipper.TranslatePath(i[s],t[0]);o.AddPath(l,e.PolyType.ptClip,!0)}}return o.Execute(e.ClipType.ctUnion,a,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),a}var l=n,i=e.Clipper.Minkowski(t,l,!0,r),o=new e.Clipper;return o.AddPaths(i,e.PolyType.ptSubject,!0),o.Execute(e.ClipType.ctUnion,i,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),i},e.Clipper.TranslatePath=function(t,n){for(var r=new e.Path,i=0;i<t.length;i++)r.push(new e.IntPoint2(t[i].X+n.X,t[i].Y+n.Y));return r},e.Clipper.MinkowskiDiff=function(t,n){var r=e.Clipper.Minkowski(t,n,!1,!0),i=new e.Clipper;return i.AddPaths(r,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),r},e.Clipper.PolyTreeToPaths=function(t){var n=[];return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntAny,n),n},e.Clipper.AddPolyNodeToPaths=function(t,n,r){var i=!0;switch(n){case e.Clipper.NodeType.ntOpen:return;case e.Clipper.NodeType.ntClosed:i=!t.IsOpen}t.m_polygon.length>0&&i&&r.push(t.m_polygon);for(var a=0,o=t.Childs(),s=o.length,c=o[a];a<s;a++,c=o[a])e.Clipper.AddPolyNodeToPaths(c,n,r)},e.Clipper.OpenPathsFromPolyTree=function(t){for(var n=new e.Paths,r=0,i=t.ChildCount();r<i;r++)t.Childs()[r].IsOpen&&n.push(t.Childs()[r].m_polygon);return n},e.Clipper.ClosedPathsFromPolyTree=function(t){var n=new e.Paths;return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntClosed,n),n},wt(e.Clipper,e.ClipperBase),e.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},e.ClipperOffset=function(t,n){t===void 0&&(t=2),n===void 0&&(n=e.ClipperOffset.def_arc_tolerance),this.m_destPolys=new e.Paths,this.m_srcPoly=new e.Path,this.m_destPoly=new e.Path,this.m_normals=[],this.m_delta=0,this.m_sinA=0,this.m_sin=0,this.m_cos=0,this.m_miterLim=0,this.m_StepsPerRad=0,this.m_lowest=new e.IntPoint0,this.m_polyNodes=new e.PolyNode,this.MiterLimit=t,this.ArcTolerance=n,this.m_lowest.X=-1},e.ClipperOffset.two_pi=6.28318530717959,e.ClipperOffset.def_arc_tolerance=.25,e.ClipperOffset.prototype.Clear=function(){e.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},e.ClipperOffset.Round=e.Clipper.Round,e.ClipperOffset.prototype.AddPath=function(t,n,r){var i=t.length-1;if(!(i<0)){var a=new e.PolyNode;if(a.m_jointype=n,a.m_endtype=r,r===e.EndType.etClosedLine||r===e.EndType.etClosedPolygon)for(;i>0&&e.IntPoint.op_Equality(t[0],t[i]);)i--;a.m_polygon.push(t[0]);for(var o=0,s=0,c=1;c<=i;c++)e.IntPoint.op_Inequality(a.m_polygon[o],t[c])&&(o++,a.m_polygon.push(t[c]),(t[c].Y>a.m_polygon[s].Y||t[c].Y===a.m_polygon[s].Y&&t[c].X<a.m_polygon[s].X)&&(s=o));if(!(r===e.EndType.etClosedPolygon&&o<2)&&(this.m_polyNodes.AddChild(a),r===e.EndType.etClosedPolygon)){if(this.m_lowest.X<0)this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s);else{var l=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(a.m_polygon[s].Y>l.Y||a.m_polygon[s].Y===l.Y&&a.m_polygon[s].X<l.X)&&(this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s))}}}},e.ClipperOffset.prototype.AddPaths=function(e,t,n){for(var r=0,i=e.length;r<i;r++)this.AddPath(e[r],t,n)},e.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!e.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];(n.m_endtype===e.EndType.etClosedPolygon||n.m_endtype===e.EndType.etClosedLine&&e.Clipper.Orientation(n.m_polygon))&&n.m_polygon.reverse()}else for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];n.m_endtype===e.EndType.etClosedLine&&!e.Clipper.Orientation(n.m_polygon)&&n.m_polygon.reverse()}},e.ClipperOffset.GetUnitNormal=function(t,n){var r=n.X-t.X,i=n.Y-t.Y;if(r===0&&i===0)return new e.DoublePoint2(0,0);var a=1/Math.sqrt(r*r+i*i);return r*=a,i*=a,new e.DoublePoint2(i,-r)},e.ClipperOffset.prototype.DoOffset=function(t){if(this.m_destPolys=[],this.m_delta=t,e.ClipperBase.near_zero(t))for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];r.m_endtype===e.EndType.etClosedPolygon&&this.m_destPolys.push(r.m_polygon)}else{this.m_miterLim=this.MiterLimit>2?2/(this.MiterLimit*this.MiterLimit):.5;var i=this.ArcTolerance<=0?e.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(t)*e.ClipperOffset.def_arc_tolerance?Math.abs(t)*e.ClipperOffset.def_arc_tolerance:this.ArcTolerance,a=3.14159265358979/Math.acos(1-i/Math.abs(t));this.m_sin=Math.sin(e.ClipperOffset.two_pi/a),this.m_cos=Math.cos(e.ClipperOffset.two_pi/a),this.m_StepsPerRad=a/e.ClipperOffset.two_pi,t<0&&(this.m_sin=-this.m_sin);for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];this.m_srcPoly=r.m_polygon;var o=this.m_srcPoly.length;if(!(o===0||t<=0&&(o<3||r.m_endtype!==e.EndType.etClosedPolygon))){if(this.m_destPoly=[],o===1){if(r.m_jointype===e.JoinType.jtRound)for(var s=1,c=0,l=1;l<=a;l++){this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t)));var u=s;s=s*this.m_cos-this.m_sin*c,c=u*this.m_sin+c*this.m_cos}else for(var s=-1,c=-1,l=0;l<4;++l)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t))),s<0?s=1:c<0?c=1:s=-1;this.m_destPolys.push(this.m_destPoly)}else{this.m_normals.length=0;for(var l=0;l<o-1;l++)this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[l],this.m_srcPoly[l+1]));if(r.m_endtype===e.EndType.etClosedLine||r.m_endtype===e.EndType.etClosedPolygon?this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[o-1],this.m_srcPoly[0])):this.m_normals.push(new e.DoublePoint1(this.m_normals[o-2])),r.m_endtype===e.EndType.etClosedPolygon){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(r.m_endtype===e.EndType.etClosedLine){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=[];for(var f=this.m_normals[o-1],l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-f.X,-f.Y),d=0;for(var l=o-1;l>=0;l--)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var d=0,l=1;l<o-1;++l)d=this.OffsetPoint(l,d,r.m_jointype);var p;if(r.m_endtype===e.EndType.etOpenButt){var l=o-1;p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X+this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y+this.m_normals[l].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X-this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y-this.m_normals[l].Y*t)),this.m_destPoly.push(p)}else{var l=o-1;d=o-2,this.m_sinA=0,this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l].X,-this.m_normals[l].Y),r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(l,d):this.DoRound(l,d)}for(var l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),d=o-1;for(var l=d-1;l>0;--l)d=this.OffsetPoint(l,d,r.m_jointype);r.m_endtype===e.EndType.etOpenButt?(p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*t)),this.m_destPoly.push(p)):(d=1,this.m_sinA=0,r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}}}},e.ClipperOffset.prototype.Execute=function(){var t=arguments;if(t[0]instanceof e.PolyTree){var n=t[0],r=t[1];n.Clear(),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;if(o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.ChildCount()===1&&n.Childs()[0].ChildCount()>0){var s=n.Childs()[0];n.Childs()[0]=s.Childs()[0],n.Childs()[0].m_Parent=n;for(var c=1;c<s.ChildCount();c++)n.AddChild(s.Childs()[c])}else n.Clear()}}else{var n=t[0],r=t[1];e.Clear(n),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.length>0&&n.splice(0,1)}}},e.ClipperOffset.prototype.OffsetPoint=function(t,n,r){if(this.m_sinA=this.m_normals[n].X*this.m_normals[t].Y-this.m_normals[t].X*this.m_normals[n].Y,Math.abs(this.m_sinA*this.m_delta)<1){if(this.m_normals[n].X*this.m_normals[t].X+this.m_normals[t].Y*this.m_normals[n].Y>0)return this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),n}else this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1);if(this.m_sinA*this.m_delta<0)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),this.m_destPoly.push(new e.IntPoint1(this.m_srcPoly[t])),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)));else switch(r){case e.JoinType.jtMiter:var i=1+(this.m_normals[t].X*this.m_normals[n].X+this.m_normals[t].Y*this.m_normals[n].Y);i>=this.m_miterLim?this.DoMiter(t,n,i):this.DoSquare(t,n);break;case e.JoinType.jtSquare:this.DoSquare(t,n);break;case e.JoinType.jtRound:this.DoRound(t,n)}return n=t,n},e.ClipperOffset.prototype.DoSquare=function(t,n){var r=Math.tan(Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y)/4);this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[n].X-this.m_normals[n].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[n].Y+this.m_normals[n].X*r)))),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[t].X+this.m_normals[t].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[t].Y-this.m_normals[t].X*r))))},e.ClipperOffset.prototype.DoMiter=function(t,n,r){var i=this.m_delta/r;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+(this.m_normals[n].X+this.m_normals[t].X)*i),e.ClipperOffset.Round(this.m_srcPoly[t].Y+(this.m_normals[n].Y+this.m_normals[t].Y)*i)))},e.ClipperOffset.prototype.DoRound=function(t,n){for(var r=Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y),i=Math.max(e.Cast_Int32(e.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(r))),1),a=this.m_normals[n].X,o=this.m_normals[n].Y,s,c=0;c<i;++c)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+a*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+o*this.m_delta))),s=a,a=a*this.m_cos-this.m_sin*o,o=s*this.m_sin+o*this.m_cos;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)))},e.Error=function(e){try{throw Error(e)}catch(e){alert(e.message)}},e.JS={},e.JS.AreaOfPolygon=function(t,n){return n||=1,e.Clipper.Area(t)/(n*n)},e.JS.AreaOfPolygons=function(t,n){n||=1;for(var r=0,i=0;i<t.length;i++)r+=e.Clipper.Area(t[i]);return r/(n*n)},e.JS.BoundsOfPath=function(t,n){return e.JS.BoundsOfPaths([t],n)},e.JS.BoundsOfPaths=function(t,n){n||=1;var r=e.Clipper.GetBounds(t);return r.left/=n,r.bottom/=n,r.right/=n,r.top/=n,r},e.JS.Clean=function(t,n){if(!(t instanceof Array))return[];var r=t[0]instanceof Array,t=e.JS.Clone(t);if(typeof n!=`number`||n===null)return e.Error(`Delta is not a number in Clean().`),t;if(t.length===0||t.length===1&&t[0].length===0||n<0)return t;r||(t=[t]);for(var i=t.length,a,o,s,c,l,u,d,f=[],p=0;p<i;p++)if(o=t[p],a=o.length,a!==0){if(a<3)s=o,f.push(s);else{for(s=o,c=n*n,l=o[0],u=1,d=1;d<a;d++)(o[d].X-l.X)*(o[d].X-l.X)+(o[d].Y-l.Y)*(o[d].Y-l.Y)<=c||(s[u]=o[d],l=o[d],u++);l=o[u-1],(o[0].X-l.X)*(o[0].X-l.X)+(o[0].Y-l.Y)*(o[0].Y-l.Y)<=c&&u--,u<a&&s.splice(u,a-u),s.length&&f.push(s)}}return!r&&f.length?f=f[0]:!r&&f.length===0?f=[]:r&&f.length===0&&(f=[[]]),f},e.JS.Clone=function(e){if(!(e instanceof Array)||e.length===0)return[];if(e.length===1&&e[0].length===0)return[[]];var t=e[0]instanceof Array;t||(e=[e]);var n=e.length,r,i,a,o,s=Array(n);for(i=0;i<n;i++){for(r=e[i].length,o=Array(r),a=0;a<r;a++)o[a]={X:e[i][a].X,Y:e[i][a].Y};s[i]=o}return t||(s=s[0]),s},e.JS.Lighten=function(t,n){if(!(t instanceof Array))return[];if(typeof n!=`number`||n===null)return e.Error(`Tolerance is not a number in Lighten().`),e.JS.Clone(t);if(t.length===0||t.length===1&&t[0].length===0||n<0)return e.JS.Clone(t);var r=t[0]instanceof Array;r||(t=[t]);var i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x=t.length,S=n*n,C=[];for(i=0;i<x;i++)if(o=t[i],l=o.length,l!==0){for(s=0;s<1e6;s++){for(c=[],l=o.length,o[l-1].X!==o[0].X||o[l-1].Y!==o[0].Y?(h=1,o.push({X:o[0].X,Y:o[0].Y}),l=o.length):h=0,m=[],a=0;a<l-2;a++)u=o[a],f=o[a+1],d=o[a+2],y=u.X,b=u.Y,g=d.X-y,_=d.Y-b,(g!==0||_!==0)&&(v=((f.X-y)*g+(f.Y-b)*_)/(g*g+_*_),v>1?(y=d.X,b=d.Y):v>0&&(y+=g*v,b+=_*v)),g=f.X-y,_=f.Y-b,p=g*g+_*_,p<=S&&(m[a+1]=1,a++);for(c.push({X:o[0].X,Y:o[0].Y}),a=1;a<l-1;a++)m[a]||c.push({X:o[a].X,Y:o[a].Y});if(c.push({X:o[l-1].X,Y:o[l-1].Y}),h&&o.pop(),m.length)o=c;else break}l=c.length,c[l-1].X===c[0].X&&c[l-1].Y===c[0].Y&&c.pop(),c.length>2&&C.push(c)}return r||(C=C[0]),C===void 0&&(C=[]),C},e.JS.PerimeterOfPath=function(e,t,n){if(e===void 0)return 0;var r=Math.sqrt,i=0,a,o,s=0,c=0,l=0,u=0,d=e.length;if(d<2)return 0;for(t&&(e[d]=e[0],d++);--d;)a=e[d],s=a.X,c=a.Y,o=e[d-1],l=o.X,u=o.Y,i+=r((s-l)*(s-l)+(c-u)*(c-u));return t&&e.pop(),i/n},e.JS.PerimeterOfPaths=function(t,n,r){r||=1;for(var i=0,a=0;a<t.length;a++)i+=e.JS.PerimeterOfPath(t[a],n,r);return i},e.JS.ScaleDownPath=function(e,t){var n,r;for(t||=1,n=e.length;n--;)r=e[n],r.X/=t,r.Y/=t},e.JS.ScaleDownPaths=function(e,t){var n,r,i;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X/=t,i.Y/=t},e.JS.ScaleUpPath=function(e,t){var n,r,i=Math.round;for(t||=1,n=e.length;n--;)r=e[n],r.X=i(r.X*t),r.Y=i(r.Y*t)},e.JS.ScaleUpPaths=function(e,t){var n,r,i,a=Math.round;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X=a(i.X*t),i.Y=a(i.Y*t)},e.ExPolygons=function(){return[]},e.ExPolygon=function(){this.outer=null,this.holes=null},e.JS.AddOuterPolyNodeToExPolygons=function(t,n){var r=new e.ExPolygon;r.outer=t.Contour();var i=t.Childs(),a=i.length;r.holes=Array(a);for(var o,s,c=0,l,u,d;c<a;c++)for(o=i[c],r.holes[c]=o.Contour(),l=0,u=o.Childs(),d=u.length;l<d;l++)s=u[l],e.JS.AddOuterPolyNodeToExPolygons(s,n);n.push(r)},e.JS.ExPolygonsToPaths=function(t){var n,r,i,a,o=new e.Paths;for(n=0,i=t.length;n<i;n++)for(o.push(t[n].outer),r=0,a=t[n].holes.length;r<a;r++)o.push(t[n].holes[r]);return o},e.JS.PolyTreeToExPolygons=function(t){for(var n=new e.ExPolygons,r,i=0,a=t.Childs(),o=a.length;i<o;i++)r=a[i],e.JS.AddOuterPolyNodeToExPolygons(r,n);return n}})()}))(),1),XZ=1e3,ZZ=e=>Math.round(e*XZ),QZ=e=>e.map(e=>({X:ZZ(e.x),Y:ZZ(e.y)})),$Z=e=>e.map(e=>({x:e.X/XZ,y:e.Y/XZ}));function eQ(e,t){let n=new YZ.default.Clipper;return n.StrictlySimple=!0,n.AddPaths(e.filter(e=>e.length>=3),YZ.default.PolyType.ptSubject,!0),n.AddPaths(t.filter(e=>e.length>=3),YZ.default.PolyType.ptClip,!0),n}function tQ(e){let t=new YZ.default.PolyTree,n=YZ.default.PolyFillType.pftNonZero;return eQ(e,[]).Execute(YZ.default.ClipType.ctUnion,t,n,n),YZ.default.JS.PolyTreeToExPolygons(t).map(e=>({outer:e.outer,holes:e.holes}))}var nQ=e=>YZ.default.Clipper.Area(e),rQ=.1,iQ=[`top`,`bottom`],aQ=1e-9,oQ={top:`F_Cu`,inner1:`In1_Cu`,inner2:`In2_Cu`,bottom:`B_Cu`},sQ={top:`F`,bottom:`B`},cQ={top:`Top`,bottom:`Bot`},lQ=e=>e.drill===void 0&&e.layers!==`through`,uQ=(e,t)=>e.layers===`through`||e.layers===t;function dQ(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)<aQ||Math.abs(o%90-90)<aQ,c=Math.abs(o-90)<aQ?{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:mQ(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:pQ(a,r,i,e.rotation),...l};case`roundrect`:{let n=Math.min(Math.max((e.cornerRadius??0)+t,0),r/2,i/2);return n<=0?u():{kind:`flash`,at:a,aperture:{shape:`roundrect`,radius:n,...s?{...c,rotation:0}:{width:r,height:i,rotation:o}},...l}}}}var fQ=11;function pQ(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:fQ},(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 mQ(e,t,n,r){let i=r*Math.PI/180,[a,o]=[Math.cos(i),Math.sin(i)];return[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]].map(([t,n])=>({x:e.x+t*a-n*o,y:e.y+t*o+n*a}))}var hQ=e=>e.flatMap(e=>e.pads),gQ=e=>lQ(e)?`SMDPad,CuDef`:`ComponentPad`,_Q=`Other,Legend`,vQ=e=>e!==void 0;function yQ(e,t){let n=e.pours.filter(e=>e.layer===t).flatMap(e=>e.polygons.flatMap(e=>[QZ(e.outer),...e.holes.map(QZ)]));return n.length===0?[]:tQ(n).sort((e,t)=>Math.abs(nQ(t.outer))-Math.abs(nQ(e.outer))).flatMap(e=>[{kind:`region`,points:$Z(e.outer),function:`Conductor`},...e.holes.map(e=>({kind:`region`,points:$Z(e),polarity:`clear`}))])}function bQ(e,t){let n=hQ(e.parts).filter(e=>e.layers===`through`||e.layers===t).map(e=>dQ(e,0,gQ(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&&VS(e).has(t)).map(e=>({kind:`flash`,at:e.at,aperture:{shape:`circle`,diameter:e.diameter},function:`ViaPad`}));return[...yQ(e,t),...n.filter(vQ),...r,...i]}function xQ(e,t,n,r){let i=$i(e,n,r).filter(e=>e.side===t);return[...e.parts.filter(e=>e.side===t).flatMap(e=>e.silkscreen),...i.flatMap(e=>Oi(e.component,e.at,1,t===`bottom`,e.rotation===90))].filter(e=>e.length>0).map(e=>({kind:`draw`,points:e,width:ki,function:_Q}))}function SQ(e){let t=e.board?.outline??[],n=t[0];return n===void 0?[]:[{kind:`draw`,points:[...t,n],width:rQ,function:`Profile`}]}function CQ(e,t){let n=MS(e.board?.layers??2),r=t.maskExpansion??.05,i=t.pasteReduction??0,a=new Map;[`top`,`inner1`,`inner2`,`bottom`].filter(e=>n.includes(e)).forEach((t,n)=>{let r=t===`top`?`Top`:t===`bottom`?`Bot`:`Inr`;a.set(oQ[t],{fileFunction:`Copper,L${n+1},${r}`,polarity:`Positive`,objects:bQ(e,t)})});for(let n of iQ){let o=hQ(e.parts).filter(e=>uQ(e,n)),s=o.map(e=>dQ(e,r,gQ(e))).filter(vQ),c=o.filter(lQ).map(e=>dQ(e,-i,gQ(e))).filter(vQ);a.set(`${sQ[n]}_Mask`,{fileFunction:`Soldermask,${cQ[n]}`,polarity:`Negative`,objects:s}),a.set(`${sQ[n]}_Paste`,{fileFunction:`Paste,${cQ[n]}`,polarity:`Positive`,objects:c}),a.set(`${sQ[n]}_Silkscreen`,{fileFunction:`Legend,${cQ[n]}`,polarity:`Positive`,objects:xQ(e,n,r,ma(t))})}return a.set(`Edge_Cuts`,{fileFunction:`Profile,NP`,polarity:`Positive`,objects:SQ(e)}),_b.flatMap(e=>{let t=a.get(e);return t===void 0?[]:[{name:e,layer:t}]})}var wQ=.06,TQ=.035,EQ=.08,DQ=34,OQ=14,kQ=.42,AQ=.97,jQ=e=>e<0?0:e>1?1:e,MQ=(e,t,n)=>{let r=jQ((n-e)/(t-e));return r*r*(3-2*r)},NQ=(e,t)=>e.data[t],PQ=(e,t)=>Math.max(1,Math.round(e*t));function FQ(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 IQ(e,t){let n=e.data;for(let r=0;r<2;r+=1)n=FQ(FQ(n,e.width,e.height,t,!0),e.width,e.height,t,!1);return{width:e.width,height:e.height,data:n}}function LQ(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 RQ(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 zQ(e){let t=e.body.data.length,n=new Float32Array(t*3),r=qU.shaded,i=[0,1,2].map(e=>qU.lit[e]-r[e]);for(let a=0;a<t;a+=1){let t=(1-NQ(e.copper,a))*(1-NQ(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 BQ(e,t,n,r){let i=WU[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*OQ*.5;for(let u=0;u<a;u+=1){let d=n*a+u,f=NQ(t.body,d)*(1-NQ(t.openings,d)),p=NQ(r.soft,d),m=r.slope[d]*DQ*(.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]-qU.shaded[t])*i.see+m+h}RQ(s,d*3,e,d*3,c,f)}}return s}function VQ(e,t,n,r){let i=KU[n.finish],a=new Float32Array(e),o=[0,0,0];for(let n=0;n<t.body.data.length;n+=1){let s=NQ(t.copper,n)*NQ(t.openings,n)*NQ(t.body,n);if(s<=0)continue;let c=MQ(.1,.9,NQ(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}RQ(a,n*3,e,n*3,o,s)}return a}function HQ(e,t,n){let r=GU[n.silk].colour,i=new Float32Array(e);for(let n=0;n<t.body.data.length;n+=1){let a=NQ(t.silk,n)*NQ(t.body,n)*(1-NQ(t.openings,n))*(1-Math.max(NQ(t.plated,n),NQ(t.nonPlated,n)));a>0&&RQ(i,n*3,e,n*3,r,a*AQ)}return i}var UQ=(e,t)=>Math.max(NQ(e.bore,t),NQ(e.nonPlated,t));function WQ(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,NQ(t.plated,i)-NQ(t.bore,i));n>0?RQ(r,i*4,e,i*3,JU,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]=NQ(t.body,i)*(1-UQ(t,i))}return r}function GQ(e,t){let n=new Float32Array(e);for(let r=0;r<t.data.length;r+=1){let i=jQ((1-NQ(t,r))*2.5);if(!(i<=0))for(let t=0;t<3;t+=1)n[r*4+t]=e[r*4+t]*(1-kQ*i)}return n}function KQ(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 qQ(e,t,n){let r=(e,t)=>{let r=PQ(t,n),i=IQ(e,r);return{soft:i,slope:LQ(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]=NQ(e.copper,t)*NQ(e.openings,t),o.data[t]=NQ(e.body,t)*(1-UQ(e,t));return KQ(GQ(WQ(HQ(VQ(BQ(zQ(e),e,t,r(e.copper,wQ)),e,t,r(a,TQ)),e,t),e),IQ(o,PQ(EQ,n))),t.background)}var JQ=16;function YQ(e,t,n){let r=Math.max(1,Math.ceil((e.maxX-e.minX)*t-1e-9));return{width:r,height:Math.max(1,Math.ceil((e.maxY-e.minY)*t-1e-9)),pxPerMm:t,minX:e.minX,maxX:e.minX+r/t,maxY:e.maxY,mirrored:n}}var XQ=e=>({width:e.width,height:e.height,data:new Float32Array(e.width*e.height)});function ZQ(e,t){return{x:(e.mirrored?e.maxX-t.x:t.x-e.minX)*e.pxPerMm,y:(e.maxY-t.y)*e.pxPerMm}}function QQ(e,t){let n=Math.max(e-.5,-t),r=Math.min(e+.5,t);return r>n?Math.min(r-n,1):0}var $Q=(e,t)=>Math.sqrt(e*e+t*t),e$=e=>e<0?0:e>1?1:e;function t$(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 n$(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)t$(e.data,n+r,i(r+.5,t+.5),a)}}function r$(e,t,n,r=`dark`){n$(e,t,t,n+1,(e,r)=>QQ($Q(e-t.x,r-t.y),n),r)}function i$(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 r$(e,t,r,i);n$(e,t,n,r+1,(e,n)=>{let i=e$(((e-t.x)*a+(n-t.y)*o)/s);return QQ($Q(e-t.x-i*a,n-t.y-i*o),r)},i)}function a$(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);n$(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 QQ(a,n)*QQ(o,r);let l=Math.abs(a)-(n-u),d=Math.abs(o)-(r-u);return e$(.5-($Q(Math.max(l,0),Math.max(d,0))+Math.min(Math.max(l,d),0)-u))},o)}function o$(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 s$(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 c$(e,t,n,r=`dark`){let i=o$(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/JQ;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<JQ;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);s$(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],t$(e.data,m+t,Math.min(p+s[t],1),r),s[t]=0,c[t]=0;o>a&&(c[o]=0)}}function l$(e,t){let n=t*Math.PI/180;return Math.atan2(-Math.sin(n),(e.mirrored?-1:1)*Math.cos(n))}function u$(e,t,n,r,i){let a=t.pxPerMm,o=ZQ(t,n);switch(r.shape){case`circle`:return r$(e,o,r.diameter/2*a,i);case`rect`:return a$(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 i$(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 a$(e,o,r.width/2*a,r.height/2*a,l$(t,r.rotation),r.radius*a,i)}}function d$(e,t,n){let r=t.pxPerMm;if(n.kind===`flash`)return u$(e,t,n.at,n.aperture,`dark`);if(n.kind===`region`)return c$(e,[n.points.map(e=>ZQ(t,e))],`nonzero`,n.polarity===`clear`?`clear`:`dark`);let i=n.points.map(e=>ZQ(t,e)),a=n.width/2*r;if(i.length===1)return r$(e,i[0],a);for(let t=1;t<i.length;t+=1)i$(e,i[t-1],i[t],a)}function f$(e,t){let n=XQ(e);for(let r of t.objects)d$(n,e,r);return n}function p$(e,t){let n=XQ(e);return c$(n,t.objects.flatMap(t=>t.kind===`draw`&&t.points.length>=3?[t.points.map(t=>ZQ(e,t))]:[]),`evenodd`),n}function m$(e,t,n=0){let r=XQ(e);for(let i of t){let t=(i.diameter/2-n)*e.pxPerMm;if(t<=0)continue;let a=ZQ(e,i.at);i.to===void 0?r$(r,a,t):i$(r,a,ZQ(e,i.to),t)}return r}var h$=4e3,g$=.05,_$={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`}},v$=new Set([`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`]);function y$(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 b$(e,t){let n=YQ(t.box??y$(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 ${h$} on its long side`);return n}function x$(e,t,n){y$(e.pcb);let r=new Map(CQ(e.pcb,e.rules.fabrication).map(({name:e,layer:t})=>[e,t])),i=_$[n],a=e=>{let n=r.get(e);return n===void 0?XQ(t):f$(t,n)},o=XQ(t);for(let e of v$){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=JZ(e.pcb);return{body:s===void 0?XQ(t):p$(t,s),copper:a(i.copper),otherCopper:o,openings:a(i.mask),paste:a(i.paste),silk:a(i.silk),plated:m$(t,c.plated),bore:m$(t,c.plated,Math.max(g$,1/t.pxPerMm)),nonPlated:m$(t,c.nonPlated)}}function S$(e,t={}){let n=t.side??`top`,r=$U(t.look),i=b$(e,t),a=qQ(x$(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:ZQ(i,{x:0,y:0}),mirrored:i.mirrored,side:n,look:r}}var C$=4e3,w$=4e6;function T$(e){let[t,n]=[e.maxX-e.minX,e.maxY-e.minY];return Math.min(40,C$/Math.max(t,n,1e-9),Math.sqrt(w$/Math.max(t*n,1e-9)))}var E$=4,D$=.45,O$=2.6,k$=.45;function A$(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 j$(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 M$(e,t,n){let[r,i]=[Math.ceil(e.width/E$),Math.ceil(e.height/E$)],a=new Float32Array(r*i),o=(t,n)=>({x:(e.origin.x+(e.mirrored?-t:t)*e.pxPerMm)/E$,y:(e.origin.y-n*e.pxPerMm)/E$}),[s,c]=[-dZ[0]/dZ[2],-dZ[1]/dZ[2]];for(let e of t.filter(e=>e.side===n)){let t=Math.min(e.height,O$),n=A$(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=j$(a,r,i,Math.max(1,Math.round(k$*e.pxPerMm/E$/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/E$-.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/E$-.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-D$*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 N$(e,t,n,r=S$){let i;try{i=y$(e.pcb)}catch{return{}}let a=T$(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:M$(s,t.parts,i)}};return{top:o(`top`),bottom:o(`bottom`)}}var P$=e=>`${e.mask??``}/${e.silk??``}/${e.finish??``}`,F$=0;function I$(e,t,n){return new Promise((r,i)=>{let a=new Worker(new URL(new URL(`texture-worker-CyI_g_XZ.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),o=++F$;a.onmessage=e=>{a.terminate(),e.data.id===o&&(e.data.error?i(Error(e.data.error)):r(e.data.textures))},a.onerror=e=>{a.terminate(),i(Error(e.message))},a.postMessage({id:o,design:e,model:t,look:n})})}var L$=e=>new Promise(t=>setTimeout(()=>t(e()),50));function R$(e,t,n){let r=P$(n),[i,a]=(0,_.useState)(void 0);(0,_.useEffect)(()=>{let i=!0,o=performance.now(),s=t=>i&&a({design:e,key:r,textures:t,ms:performance.now()-o}),c=()=>L$(()=>N$(e,t,n)).then(s);return typeof Worker>`u`?c():I$(e,t,n).then(s,c),()=>{i=!1}},[e,r]);let o=i&&i.design===e&&i.key===r?i:void 0;return{textures:o?.textures,ms:o?.ms}}var z$=160,B$=`Drag to turn, wheel to zoom. Keys: arrows turn, + and − zoom, T top, B bottom, Home resets.`;function V$({design:e}){let t=(0,_.useMemo)(()=>UU(e),[e]),[n,r]=(0,_.useState)({}),{textures:i}=R$(e,t,n),a=(0,_.useMemo)(()=>lZ(e,t),[e,t]),o=(0,_.useMemo)(()=>KZ(t,{parts:a,...i?{textures:i}:{},look:n,mounting:e.pcb.holes.length,layers:e.pcb.board?.layers??2}),[t,a,i,n,e]),[s,c]=(0,_.useState)(!0),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(void 0),f=(0,_.useRef)(void 0),p=wO(l),[m,h]=(0,_.useState)(uW),[g,v]=(0,_.useState)(void 0),[y,b]=(0,_.useState)(void 0),[x,S]=(0,_.useState)(void 0),C=g??y;(0,_.useEffect)(()=>{let e=u.current,{width:t,height:n}=p;if(!e||t===0||n===0)return;let r=performance.now(),i={background:BZ(W.background),highlight:C,reuse:d.current,lit:!0};d.current=s?MZ(o,m,t,n,i):DZ(o,m,t,n,i),e.width!==t&&(e.width=t),e.height!==n&&(e.height=n),e.getContext(`2d`)?.putImageData(new ImageData(d.current.color,t,n),0,0),s||S(performance.now()-r)},[o,m,p,C,s]),(0,_.useEffect)(()=>{c(!1);let e=setTimeout(()=>c(!0),z$);return()=>clearTimeout(e)},[m,p]),(0,_.useEffect)(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),h(t=>SW(t,e.deltaY))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]);let w=e=>{let t=l.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},T=e=>{let{x:t,y:n}=w(e),r=d.current;if(!r||t<0||n<0||t>=r.width||n>=r.height)return;let i=r.ids[Math.floor(n)*r.width+Math.floor(t)]??-1;return i>=0?i:void 0},E=C===void 0?void 0:t.parts[C];return(0,X.jsxs)(`div`,{className:`look`,children:[(0,X.jsxs)(`div`,{className:`look-view`,ref:l,tabIndex:0,role:`group`,"aria-label":`3D view of the board and its parts; it cannot be edited here`,"aria-describedby":`look-help`,"data-frame-ms":x===void 0?void 0:x.toFixed(1),onKeyDown:e=>{let t=CW(m,e.key);t!==void 0&&(e.preventDefault(),h(t))},onPointerDown:e=>{e.target.closest(`button`)||(e.currentTarget.setPointerCapture(e.pointerId),f.current={...w(e),orbit:m})},onPointerMove:e=>{if(f.current){let{x:t,y:n}=w(e);h(xW(f.current.orbit,t-f.current.x,n-f.current.y))}else v(T(e))},onPointerUp:()=>f.current=void 0,onPointerCancel:()=>f.current=void 0,onPointerLeave:()=>v(void 0),children:[(0,X.jsx)(`canvas`,{ref:u}),(0,X.jsxs)(`div`,{className:`look-tools`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(dW),children:`Top`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(fW),children:`Bottom`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(uW),title:`Home`,children:`Reset view`})]}),(0,X.jsx)(`p`,{className:`look-status`,"aria-live":`polite`,children:E?oW(E):(0,X.jsx)(`span`,{id:`look-help`,children:B$})})]}),(0,X.jsxs)(`aside`,{className:`look-side`,children:[(0,X.jsx)(sW,{model:t}),(0,X.jsx)(lW,{look:n,onLook:r,ready:i!==void 0}),(0,X.jsx)(cW,{model:t,active:C,onActive:b})]})]})}var H$=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},U$={alignLeft:`Align left`,alignRight:`Align right`,alignTop:`Align top`,alignBottom:`Align bottom`,alignHCentres:`Align horizontal centres`,alignVCentres:`Align vertical centres`,distributeH:`Distribute horizontally`,distributeV:`Distribute vertically`},W$={alignLeft:`Ctrl+Shift+L`,distributeH:`Ctrl+Shift+H`};function G$(e){if(e<2)return[];let t=t=>{let n=D(t,e),r=W$[t];return{label:U$[t],command:t,...r?{shortcut:r}:{},...n?{pending:n}:{}}};return[`separator`,...w.slice(0,6).map(t),`separator`,...w.slice(6).map(t)]}function K$({allLocked:e,selected:t}){return[{label:`Properties`,special:`properties`},`separator`,H$(`Rotate`,`rotate`,`Space`),e?H$(`Unlock`,`unlock`):H$(`Lock`,`lock`),H$(`Highlight its nets`,`highlight`,`H`),H$(`Copy`,`copy`,`Ctrl+C`),...G$(t),`separator`,H$(`Delete`,`delete`,`Delete`)]}var q$=[H$(`Fit all`,`fit`,`K`),H$(`Grid style`,`gridStyle`),`separator`,H$(`Zoom in`,`zoomIn`),H$(`Zoom out`,`zoomOut`),`separator`,H$(`Paste`,`paste`,`Ctrl+V`)],J$={remove:null,removeCorners:`Select this wire alone to remove its corners`},Y$=(e,t)=>t?{...e,pending:t}:e;function X$(e){return[{label:`Properties`,special:`properties`},`separator`,H$(`Highlight net`,`highlight`,`H`),Y$(H$(`Remove corners`,`removeCorners`),e?.removeCorners),`separator`,Y$(H$(`Delete`,`delete`,`Delete`),e?.remove)]}var Z$=[{label:`Properties`,special:`properties`},`separator`,H$(`Delete`,`delete`,`Delete`)],Q$=[{label:`Rename`,special:`rename`},{label:`Highlight net`,special:`highlightNet`}],$$=[H$(`Fillet tracks`,`filletTracks`,`U`),H$(`Straighten tracks`,`straightenTracks`,`Shift+U`),`separator`];function e1(e,t,n){let r=e.startsWith(`t`)?$$:[],i=H$(n?`Delete segment`:`Delete`,`delete`,`Delete`);return[{label:`Properties`,special:`properties`},`separator`,...r,t?H$(`Unlock`,`unlock`):H$(`Lock`,`lock`),`separator`,i]}function t1(e){let t={label:`Reset position`,special:`resetText`};return[e?{...t,pending:e}:t,`separator`,{label:`Properties`,special:`properties`}]}function n1(e,t){return e.kind===`part`?K$(t):e.kind===`copper`?e1(e.id,t.copperLocked,t.segment):e.kind===`wire`?X$(t.wire):e.kind===`drawing`?[...Z$]:e.kind===`text`?t1(t.textReset):[...e.kind===`label`?Q$:q$]}function r1(e){return e.map(e=>e===`separator`?`separator`:e.pending?`disabled`:`item`)}function i1(e,t){return e.length>0&&e.every(e=>t.has(e))}function a1(e,t){return t.kind===`drawing`?e.hasDrawing(t.id)?e:e.onlyDrawing(t.id):t.kind===`wire`?e.hasWire(t.id)?e:e.onlyWire(t.id):t.kind===`label`?e.hasLabel(t.label.id)?e:e.onlyLabel(t.label.id):t.kind===`copper`?e.hasCopper(t.id)?e:e.onlyCopper(t.id):t.kind===`text`?e.hasText(t.id)?e:e.onlyText(t.id):t.kind===`part`&&!e.has(t.name)?e.only(t.name):e}var o1=28,s1=9,c1=10;function l1(e){return{width:240,height:e.reduce((e,t)=>e+(t===`separator`?s1:o1),0)+c1}}function u1(e,t,n){let r=(e,t,n)=>Math.max(0,e+t>n?e-t:e);return{x:r(e.x,t.width,n.width),y:r(e.y,t.height,n.height)}}function d1(e){(0,_.useEffect)(()=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),[e])}function f1(e,t){let n=(0,_.useRef)(ry(t));(0,_.useLayoutEffect)(()=>{let t=e.current,r=document.activeElement;return n.current!==null&&t?.querySelector(`[data-item="${n.current}"]`)?.focus(),()=>{r instanceof HTMLElement&&r.isConnected&&Om(document.activeElement,document.body,t)&&r.focus()}},[e])}var p1=(e,t)=>{let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-item]`):null;return n?Number(n.dataset.item):null};function m1({entries:e,at:t,onRun:n,onClose:r}){let i=(0,_.useRef)(null),a=(0,_.useMemo)(()=>r1(e),[e]),[o,s]=(0,_.useState)(null);(0,_.useLayoutEffect)(()=>{let e=i.current?.getBoundingClientRect();e&&s({width:e.width,height:e.height})},[e]);let c=(0,_.useMemo)(()=>u1(t,o??l1(e),{width:window.innerWidth,height:window.innerHeight}),[t,e,o]);return fh(!0,e=>{let t=p1(i.current,document.activeElement),n=ny(e.key,t===null?null:{menu:0,item:t},0,[a],{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});if(n){if(n.preventDefault&&e.preventDefault(),n.open===null)return r();n.focus!==`keep`&&n.focus.item!==null&&i.current?.querySelector(`[data-item="${n.focus.item}"]`)?.focus()}}),f1(i,a),Hv(!0,i,r),d1(r),(0,X.jsx)(`ul`,{className:`menu-dropdown context-menu`,role:`menu`,"aria-label":`Context menu`,ref:i,onContextMenu:e=>e.preventDefault(),style:{left:c.x,top:c.y},children:e.map((e,t)=>e===`separator`?(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`},`sep${t}`):(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(Vv,{label:e.label,...e.shortcut?{shortcut:e.shortcut}:{},index:t,enabled:!e.pending,...e.pending?{reason:e.pending}:{},onActivate:()=>{r(),n(e)}})},e.label))})}var h1=[{view:`schematic`,label:`Schematic`},{view:`pcb`,label:`PCB`}];function g1(e,t,n,r){let i=e===t;return at(e)?[{view:`schematic`,label:`Schematic`,active:i}]:h1.flatMap(({view:e,label:t})=>e===`pcb`||!i||!r||r.names.length<=1?[{view:e,label:t,active:i&&e===n}]:r.names.map(t=>({view:e,label:t,page:t,active:n===`schematic`&&t===r.open})))}function _1(e,t,n,r,i){return{project:e||`Project`,view:r,files:t.map(e=>({file:e,documents:g1(e,n,r,i)}))}}h1.map(e=>e.view);var v1=`schematic:`,y1=`parent:`;function b1(e){return e===`3d`?{view:`pcb`,look:!0}:e.startsWith(y1)?{...b1(e.slice(7)),parent:!0}:e.startsWith(v1)?{view:`schematic`,page:e.slice(10)}:{view:e===`pcb`?`pcb`:`schematic`}}function x1(e,t){return[...t===void 0?[]:S1(t,`pcb`).map(e=>({...e,id:`${y1}${e.id}`,active:!1,parent:!0})),{id:`schematic`,view:`schematic`,title:`${ot(e)} (sheet)`,active:!0}]}function S1(e,t,n=[dy],r=dy,i){if(e!==void 0&&at(e))return x1(e,i);let a=(e??``).replace(/\.circuit\.tsx$/,``),o=(e,t)=>a?`${a}${t}${e}`:e;return h1.flatMap(({view:e,label:i})=>e===`pcb`||n.length<=1?[{id:e,view:e,title:o(i,` `),active:e===t}]:n.map(n=>({id:`${v1}${n}`,view:e,page:n,title:o(n,` — `),active:t===`schematic`&&n===r})))}function C1(e,t,n){if(t!==void 0&&at(t))return[...e];let r=(t??``).replace(/\.circuit\.tsx$/,``);return[...e.map(e=>n&&e.active?{...e,active:!1}:e),{id:`3d`,view:`pcb`,title:r?`${r} 3D`:`3D`,active:n,look:!0}]}function w1({file:e,view:t,pages:n,page:r,onView:i,onPage:a,parent:o,onParent:s,look:c=!1,onLook:l}){let u=C1(S1(e,t,n,r,o),e,c),d=u.find(e=>e.active)?.id??t,f=Nm({ids:u.map(e=>e.id),current:d,onSelect:e=>{let t=b1(e);l?.(t.look===!0),t.look?i(t.view):t.parent?s?.(t.view):t.page===void 0?i(t.view):a(t.page)}});return(0,X.jsx)(`div`,{className:`doc-tabs hairline-b`,role:`tablist`,"aria-label":`Documents`,onKeyDown:f.onKeyDown,children:u.map((e,t)=>(0,X.jsx)(`button`,{role:`tab`,id:e.look?`doc-tab-3d`:e.active||e.page===void 0&&!e.parent?`doc-tab-${e.view}`:`doc-tab-${e.view}-${t}`,"aria-controls":`doc-panel`,"aria-selected":e.active,className:`doc-tab${e.active?` on`:``}`,title:e.title,...f.tab(e.id),children:(0,X.jsx)(`span`,{className:`doc-tab-label`,children:e.title})},e.id))})}function T1({view:e,filter:t,onToggle:n}){return(0,X.jsxs)(`aside`,{className:`panel right filter-panel`,id:wD(`right`),role:`tabpanel`,"aria-labelledby":TD(`filter`),onClick:km,children:[(0,X.jsx)(`h3`,{className:`filter-head hairline-b`,children:`Pick`}),(0,X.jsx)(`ul`,{className:`filter-list`,children:G(e).map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`label`,{className:`filter-row`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:t[e.kind],onChange:()=>n(e.kind)}),(0,X.jsx)(`span`,{children:e.label})]})},e.kind))}),(0,X.jsx)(`p`,{className:`filter-note`,children:`A kind that is off still draws and stays in the Component tree and the Net list.`})]})}var E1=e=>e?.state===`started`||e?.state===`running`||e?.state===`cleanup`,D1=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,O1=`cleanup stopped at its pass cap`,k1=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function A1(e){switch(e.state){case`started`:return e.inProcess?`Autorouting in the server process (worker threads are unavailable)…`:`Autorouting…`;case`running`:return`Autorouting: pass ${e.pass}, ${e.done} of ${k1(e.total,`connection`)}`;case`cleanup`:return e.capped?`Autorouting: ${O1}`:`Autorouting: cleaning up`;case`done`:{if(e.total===0)return`Nothing to route: the scope has no connection left to route`;let t=e.unrouted.length===0?``:`; ${e.unrouted.length} not routed, see Checks`,n=e.cleanupCapped?`; ${O1}`:``;return`Routed ${e.routed} of ${k1(e.total,`connection`)} in ${k1(e.passes,`pass`,`passes`)}${t}${n}`}case`discarded`:return e.reason;case`cancelled`:return`Autorouting cancelled; nothing was written`;case`failed`:return`Autorouting failed: ${e.error}`}}function j1({route:e,onCancel:t}){return!e||!E1(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:A1(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{km(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop routing; nothing is written`,children:`Cancel`})]})}var M1=e=>e?.state===`started`||e?.state===`running`,N1=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,P1=(e,t)=>`${e} ${t}${e===1?``:`s`}`,F1=e=>String(Math.round(e));function I1(e){switch(e.state){case`started`:return e.inProcess?`Autoplacing in the server process (worker threads are unavailable)…`:`Autoplacing…`;case`running`:return e.stage===`construct`?`Autoplacing: ${e.done} of ${P1(e.total,`part`)}`:`Autoplacing: refining, ${Math.round(100*e.done/Math.max(1,e.total))}%`;case`done`:{if(e.placed===0&&e.unplaced.length===0)return`Nothing to place: every part in the scope is placed or locked`;let t=e.unplaced.length===0?``:`; ${e.unplaced.length} not placed (${e.unplaced.map(e=>e.name).join(`, `)})`,n=e.board&&`width`in e.board?`; board ${e.board.width} × ${e.board.height} mm`:``;return`Placed ${P1(e.placed,`part`)}; wire length ${F1(e.wireLength)} mm (was ${F1(e.before)})${n}${t}`}case`discarded`:return e.reason;case`cancelled`:return`Autoplacing cancelled; nothing was written`;case`failed`:return`Autoplacing failed: ${e.error}`}}function L1({place:e,onCancel:t}){return!e||!M1(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:I1(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{km(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop placing; nothing is written`,children:`Cancel`})]})}var R1=[{id:`all`,label:`All`},{id:`copper`,label:`Copper`},{id:`non-copper`,label:`Non-copper`}],z1=R1.map(e=>e.id);function B1({pours:e,onTogglePour:t}){return e.length===0?null:(0,X.jsx)(`ul`,{className:`layer-list layer-pours hairline-t`,"aria-label":`Copper pours`,children:e.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`div`,{className:`layer-pours-title`,children:[`Copper pours · `,e.name]}),(0,X.jsx)(`ul`,{className:`layer-list`,children:e.pours.map(n=>(0,X.jsxs)(`li`,{className:`layer-row${n.shown?``:` off`}`,children:[(0,X.jsx)(`span`,{className:`layer-swatch`,style:{background:rd[n.layer]??W.topCopper,opacity:.6},"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`layer-name`,title:n.id,children:n.net}),(0,X.jsx)(`button`,{className:`layer-eye`,"aria-pressed":n.shown,"aria-label":`${n.net} pour on the ${e.name}`,title:`${n.shown?`Hide`:`Show`} the ${n.net} pour`,onClick:()=>t(n.id),children:(0,X.jsx)(ih,{off:!n.shown})})]},n.id))})]},e.layer))})}function V1({active:e,onActive:t}){return(0,X.jsxs)(`label`,{className:`layer-active hairline-b`,title:`The layer tracks are drawn on (V)`,children:[`Active layer`,(0,X.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),children:Ta.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})}function H1({filter:e,onFilter:t}){let n=Nm({ids:z1,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`layer-filters hairline-b`,role:`radiogroup`,"aria-label":`Show layers`,onKeyDown:n.onKeyDown,children:R1.map(({id:t,label:r})=>(0,X.jsx)(`button`,{className:`layer-filter${e===t?` on`:``}`,role:`radio`,"aria-checked":e===t,...n.tab(t),children:r},t))})}function U1({visibility:e,filter:t,hasKeepouts:n,onFilter:r,onToggle:i,active:a,onActive:o,pours:s,onTogglePour:c}){return(0,X.jsxs)(`aside`,{className:`panel right layer-panel`,id:wD(`right`),role:`tabpanel`,"aria-labelledby":TD(`layer`),onClick:km,children:[(0,X.jsx)(H1,{filter:t,onFilter:r}),(0,X.jsx)(V1,{active:a,onActive:o}),(0,X.jsx)(`ul`,{className:`layer-list`,children:Da(n,t).map(t=>{let n=e[t.id];return(0,X.jsxs)(`li`,{className:`layer-row${n?``:` off`}`,children:[(0,X.jsx)(`span`,{className:`layer-swatch`,style:{background:Oa(t)},"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`layer-name`,children:t.name}),(0,X.jsx)(`button`,{className:`layer-eye`,"aria-pressed":n,"aria-label":t.name,title:`${n?`Hide`:`Show`} ${t.name}`,onClick:()=>i(t.id),children:(0,X.jsx)(ih,{off:!n})})]},t.id)})}),t!==`non-copper`&&(0,X.jsx)(B1,{pours:s,onTogglePour:c})]})}function W1(e,t,n,r,i){return t.total>1?J$:n&&r?nD(n,r,e,i):void 0}function G1(e,t){let n=[...e?.pcb.tracks??[],...e?.pcb.vias??[]].filter(e=>t.includes(e.id));return n.length>0&&n.every(e=>e.locked)}function K1(e){let{circuit:t,design:n,selection:r,onSelect:i,run:a,openProperties:o,onHighlight:s,edit:c}=e,[l,u]=(0,_.useState)(null),d=(0,_.useCallback)((e,t)=>{i(t=>a1(t,e)),u({target:e,at:t})},[i]),f=(0,_.useCallback)(()=>u(null),[]);return{open:(0,_.useMemo)(()=>{if(!l)return null;let e=new Set(t?.annotations.locks.map(e=>e.part)),i=a1(r,l.target),{target:a}=l,o=a.kind===`wire`?W1(a.id,i,n,t,e):void 0,s=a.kind===`copper`&&G1(n,i.copper),c=a.kind===`copper`&&i.segment?.id===a.id,u=a.kind===`text`?n&&t?Tf(n,t,a.id,e):`It is not on this sheet`:void 0;return{entries:n1(a,{allLocked:i1(i.names,e),selected:i.size,wire:o,copperLocked:s,segment:c,textReset:u}),at:l.at}},[l,t,n,r]),close:f,show:d,runItem:(0,_.useCallback)(e=>{if(e.command)return a(e.command);if(e.special===`properties`)return o();if(e.special===`resetText`&&l?.target.kind===`text`)return void c(xf(l.target.id),`Reset text position`);if(e.special===`rename`&&l?.target.kind===`label`)return void rT.send({kind:`renameLabel`,labelId:l.target.label.id});e.special===`highlightNet`&&l?.target.kind===`label`&&n&&s([Tp(n.circuit.nets,l.target.label.net)])},[a,o,s,c,l,n])}}function q1(e){return e===`pcb`?[`properties`,`layer`,`filter`]:[`properties`,`filter`]}function J1(e,t){return e.active!==`layer`||t===`pcb`?e:{...e,active:`properties`}}var Y1={active:`properties`,open:!0},X1={strip:`design`,sub:`page`,open:!0};function Z1(e,t){return e.open&&e.active===t?{...e,open:!1}:{active:t,open:!0}}function Q1(e){return{...e,open:!e.open}}function $1(e,t){return{active:t,open:!0}}function e0(e,t){let n=Z1({active:e.strip,open:e.open},t);return{...e,strip:n.active,open:n.open}}function t0(e,t){return{...e,strip:t,open:!0}}function n0(e){return{strip:`design`,sub:e,open:!0}}function r0(e){return{...e,strip:`library`,open:!0}}function i0(e){return{...e,open:!e.open}}var a0=[{id:`design`,label:`Project Design`},{id:`library`,label:`Common Library`}],o0={properties:`Properties`,layer:`Layer`,filter:`Filter`},s0=e=>q1(e).map(e=>({id:e,label:o0[e]}));function c0({data:e,workspace:t,checks:n,selection:r,onSelect:i,actions:a,onOpenSheet:o},s){let{build:c,circuit:l}=e;if(c.design&&l)return{design:c.design,buildId:c.finishedAt,buildStatus:c.status,builtMark:c.startMark,project:e.project,builtFrom:c.startedAt?Date.parse(c.startedAt):-1/0,circuit:l,actions:a,selection:r,onSelect:i,highlight:t.highlight,onHighlight:t.setHighlight,unit:t.unit,onToggleUnit:t.toggleUnit,activeViolation:n.active,focus:n.focus,onFocused:n.focused,layers:t.layerVisibility,pickFilter:t.pickFilter,onContextMenu:s,onOpenSheet:o,onOpenProperties:e=>{i(t=>e.kind===`wire`?t.onlyWire(e.id):e.kind===`drawing`?t.onlyDrawing(e.id):t.only(e.name)),t.openProperties()}}}function l0(e,t){return{gridStyle:e.gridStyles[t],gridStep:e.gridSteps[t],snap:e.snap,onGridStep:n=>e.changeGridStep(t,n),theme:e.theme,hoverLabels:e.hoverLabels}}function u0(e,t){let n=e?.design,r=e?.actions,i=(0,_.useMemo)(()=>n?my(n,t):void 0,[n,t]),a=(0,_.useMemo)(()=>r?{...r,edit:(e,n)=>r.edit(tC(e,t),n),editMarked:(e,n)=>r.editMarked(tC(e,t),n)}:void 0,[r,t]);return e&&i&&a?{...e,design:i,actions:a}:void 0}function d0({sheetParent:e,onOpenDocument:t}){return e?{parent:e.file,onParent:n=>t(e.file,n)}:{}}function f0(e){let{data:t,workspace:n,checks:r,find:i,view:a,page:o}=e,{build:s}=t,c=c0(e,e.onContextMenu),l=u0(c,o),u=(0,_.useMemo)(()=>fy(s.design),[s.design]),d=FV(),[f,p]=(0,_.useState)(!1),m=f&&a===`pcb`;return(0,X.jsxs)(`div`,{className:`center`,children:[(0,X.jsx)(w1,{file:t.file,view:a,pages:u,page:o,onView:e.onView,onPage:e.onPage,look:m,onLook:p,...d0(e)}),(0,X.jsx)(`div`,{className:`ai-lock-band`,children:e.lockControl}),(0,X.jsxs)(`section`,{className:e.aiLocked?`canvas ai-locked`:`canvas`,id:`doc-panel`,role:`tabpanel`,"aria-labelledby":m?`doc-tab-3d`:`doc-tab-${a}`,tabIndex:-1,children:[!s.design&&(0,X.jsx)(`p`,{className:`empty`,children:s.status===`failed`?s.error:`Building the circuit…`}),d&&(0,X.jsx)(hH,{state:d}),!d&&m&&s.design&&(0,X.jsx)(V$,{design:s.design}),!d&&!m&&c&&a===`pcb`&&(0,X.jsx)(hL,{...c,...l0(n,`pcb`),markers:r.markers.pcb,activeLayer:n.activeLayer,onActiveLayer:n.setActiveLayer,pourFill:n.pourFill,hiddenPours:n.hiddenPours},t.file),!d&&l&&a===`schematic`&&(0,X.jsx)(JB,{...l,...l0(n,`schematic`),markers:r.markers.schematic},`${t.file}
20
+ ${o}`),(0,X.jsx)(j1,{route:t.route,onCancel:()=>void e.actions.cancelRoute()}),(0,X.jsx)(L1,{place:t.place,onCancel:()=>void e.actions.cancelAutoplace()}),i.box.open&&(0,X.jsx)(XB,{text:i.box.text,seq:i.box.seq,onText:i.setText,onSearch:i.search,onClose:i.close,status:eV(i.results.query,i.results.rows.length)})]}),n.bottom.open&&(0,X.jsx)(JV,{tab:n.bottom.tab,parts:t.parts,onPlace:e.onPlace,history:t.history,historyProblems:t.historyProblems,actions:e.actions,built:s.design!==void 0,buildError:s.status===`failed`?s.error??`The build failed.`:void 0,rows:r.rows,counts:r.counts,active:r.active,onPick:r.pick,find:i.results})]})}function p0({data:e,workspace:t,view:n,page:r,selection:i,onSelect:a,actions:o,onPlace:s,onImportPart:c,onNewPart:l,onOpenDocument:u}){let{circuit:d,build:f,project:p,files:m,sheets:h,file:g}=e,v=(0,_.useMemo)(()=>_1(p,[...m,...h],g,n,{names:fy(f.design),open:r}),[p,m,h,g,n,f.design,r]),y=(0,_.useMemo)(()=>$e(f.design,n),[f.design,n]);return d?(0,X.jsx)(jD,{circuit:d,parts:e.parts,onPlace:s,onImport:c,onNewPart:l,selection:i,onSelect:a,actions:o,design:f.design,autoPlaced:y,left:t.left,onSub:t.showSub,pageTree:v,onOpenDocument:u,focusSearch:t.focusSearch,onSearchFocused:t.searchFocused,focusPage:t.focusPage,onPageFocused:t.pageFocused,highlight:t.highlight,onHighlight:t.setHighlight,hidden:!t.leftOpen}):null}function m0({data:e,workspace:t,checks:n,selection:r,onSelect:i,onRenameDrawing:a,actions:o,run:s,openChecks:c,view:l,onOpenSheet:u,sheetParent:d}){if(!e.circuit)return null;let{right:f}=t,p=f.open&&f.active===`layer`,m=f.open&&f.active===`filter`,h=e.build.design?.pcb.board?.keepouts??[],g=e.build.design,_=g?ja(g.pcb.board?.pours??[],e=>Fu(g,e),t.hiddenPours):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(BD,{circuit:e.circuit,build:e.build,parts:e.parts,openView:l,selection:r,onSelect:i,onRenameDrawing:a,actions:o,run:s,counts:n.counts,onShowChecks:c,hidden:!f.open||f.active!==`properties`,focusField:t.focusField,onFieldFocused:t.fieldFocused,onOpenSheet:u,parentDesign:d?.design}),p&&(0,X.jsx)(U1,{visibility:t.layerVisibility,filter:t.layerFilter,hasKeepouts:h.length>0,onFilter:t.setLayerFilter,onToggle:t.toggleLayerShown,active:t.activeLayer,onActive:t.setActiveLayer,pours:_,onTogglePour:t.togglePourShown}),m&&(0,X.jsx)(T1,{view:l,filter:t.pickFilter,onToggle:t.togglePickable})]})}function h0(e){let{data:t,workspace:n,selection:r,onSelect:i}=e,a=K1({circuit:t.circuit,design:t.build.design,selection:r,onSelect:i,run:e.run,openProperties:n.openProperties,edit:e.actions.edit,onHighlight:n.setHighlight});return(0,X.jsxs)(`main`,{className:`workspace`,children:[(0,X.jsx)(ED,{side:`left`,tabs:a0,active:n.left.strip,open:n.left.open,onClick:n.clickLeft,onSelect:n.selectLeft}),(0,X.jsx)(p0,{...e}),(0,X.jsx)(f0,{...e,onContextMenu:a.show}),(0,X.jsx)(m0,{...e}),(0,X.jsx)(ED,{side:`right`,tabs:s0(e.view),active:n.right.active,open:n.right.open,onClick:n.clickRight,onSelect:n.selectRight}),a.open&&(0,X.jsx)(m1,{entries:a.open.entries,at:a.open.at,onRun:a.runItem,onClose:a.close})]})}function g0({file:e,refresh:t,notify:n,openVerify:r}){let i=(0,_.useCallback)(async r=>{try{return await r(),!0}catch(e){return n(e.message),!1}finally{e&&await t(e).catch(()=>void 0)}},[e,t,n]),a=(0,_.useCallback)(async(e,t)=>{let n;return{ok:await i(async()=>{n=(await z(e,t)).writeMark}),mark:n}},[i]),o=(0,_.useCallback)((t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),[e,a]),s=(0,_.useCallback)((t,n,r)=>a(`/api/layout`,{file:e,edits:t,summary:n,...r?{sheet:r}:{}}),[e,a]);return(0,_.useMemo)(()=>({edit:async(e,t)=>(await o(e,t)).ok,editMarked:o,editFile:(e,t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),editLayout:s,renameParts:(t,n)=>mP(a(`/api/rename-parts`,{file:e,mapping:t,summary:n})),lock:(t,n)=>i(()=>z(`/api/lock`,{file:e,parts:t,locked:n})),mark:(t,n)=>i(()=>z(`/api/mark`,{file:e,text:t,...n})),unmark:t=>i(()=>z(`/api/unmark`,{file:e,id:t})),undo:e=>mP(a(`/api/undo`,e?{id:e}:{})),redo:e=>mP(a(`/api/redo`,e?{id:e}:{})),openVerify:r,makeSheet:t=>i(async()=>{n(Wh((await z(`/api/make-sheet`,{file:e,...t})).preview,t.parts.length))}),route:async t=>{try{return await z(`/api/route`,{file:e,scope:t}),!0}catch(e){return n(e.message),!1}},cancelRoute:async()=>{try{return(await z(`/api/route/cancel`,{})).cancelled}catch(e){return n(e.message),!1}},autoplace:async t=>{try{return await z(`/api/autoplace`,{file:e,scope:t}),!0}catch(e){return n(e.message),!1}},cancelAutoplace:async()=>{try{return(await z(`/api/autoplace/cancel`,{})).cancelled}catch(e){return n(e.message),!1}},fitBoard:()=>mP((async()=>{let t;return{ok:await i(async()=>{let r=await z(`/api/fit-board`,{file:e});t=r.writeMark,n(r.summary)}),mark:t}})()),importBoard:(t,r)=>mP((async()=>{let a;return{ok:await i(async()=>{let i=await z(`/api/import-board`,{file:e,name:t,text:r});a=i.writeMark,n(i.summary)}),mark:a}})()),importKicad:async(t,r)=>{let a;return await i(async()=>{let i=await z(`/api/import-board`,{file:e??``,name:t,text:r});a=i.file,n(i.summary)}),a},unroute:t=>mP((async()=>{let r;return{ok:await i(async()=>{let i=await z(`/api/unroute`,{file:e,...t?{ids:t}:{}});r=i.writeMark,n(i.summary)}),mark:r}})()),setFilletRadius:t=>i(async()=>{let r=await z(`/api/rules`,{filletRadius:t,...e?{file:e}:{}});r.writeMark!==void 0&&qM({radius:t,mark:r.writeMark}),n(r.summary)}),notify:n}),[e,i,n,o,s,a,r])}function _0({file:e,refresh:t,notify:n},r,i=`Main`){return(0,_.useCallback)(a=>{let o=IV[a];z(`/api/place`,{file:e,part:a,...o?{props:o}:{},...i===`Main`?{}:{page:i}}).then(e=>{r(e.name),n(`Placed ${e.name}${o?` with a starting value; change it on the right`:``}. Drag it into position on the PCB.`)}).catch(e=>n(e.message)).finally(()=>{e&&t(e).catch(()=>void 0)})},[e,t,n,r,i])}function v0(e,t){return e===0&&t>0}function y0(e){let t=e.view===`code`?void 0:e.view;return{...t?{tab:t}:{},...t&&e.at?{focus:{view:t,at:e.at}}:{},...e.copper?.length||e.board?.length?{selectCopper:e.copper??[],...e.board?.length?{selectBoard:e.board}:{}}:e.part?{select:e.part}:{}}}function b0({file:e,build:t,route:n,onTab:r,onSelect:i,onSelectCopper:a,onOpen:o}){let s=t.design,c=(0,_.useMemo)(()=>s?Bw(s,n):[],[s,n]),l=(0,_.useMemo)(()=>Uw(c),[c]),u=(0,_.useMemo)(()=>({pcb:Hw(c,`pcb`),schematic:Hw(c,`schematic`)}),[c]),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null);return x0(e,t,l.errors,o),{rows:c,counts:l,markers:u,active:d,focus:p,pick:(0,_.useCallback)(e=>{let t=y0(e);f(e.id),t.tab&&r(t.tab),t.focus&&m(t.focus),t.select&&i(t.select),t.selectCopper&&a(t.selectCopper,t.selectBoard??[])},[r,i,a]),focused:(0,_.useCallback)(()=>m(null),[]),requestFocus:m}}function x0(e,t,n,r){let i=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{i.current=void 0},[e]);let a=t.status===`done`?t.finishedAt:void 0;(0,_.useEffect)(()=>{a!==void 0&&(v0(i.current,n)&&r(),i.current=n)},[a,n,r])}var S0={open:!1,text:``,seq:0};function C0({file:e,circuit:t,library:n,design:r,view:i,onSelect:a,onHighlight:o,requestFocus:s,openResults:c}){let[l,u]=(0,_.useState)(S0),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),h=t?.model.parts,g=(0,_.useMemo)(()=>d===null?[]:lV(d,h??[],r?nV(r):[],n),[d,h,r,n]);return(0,_.useEffect)(()=>{f(null),m(null)},[e]),{box:l,open:(0,_.useCallback)(()=>u(e=>({...e,open:!0,seq:e.seq+1})),[]),close:(0,_.useCallback)(()=>u(e=>({...e,open:!1})),[]),setText:(0,_.useCallback)(e=>u(t=>({...t,text:e})),[]),search:(0,_.useCallback)(e=>{let t=e.trim();t!==``&&(f(t),m(null),c())},[c]),results:{query:d,rows:g,active:p,pick:(0,_.useCallback)(e=>{let t=dV(e,r,i);if(m(e.id),t.select){let e=t.select;a(t=>t.only(e))}t.focus&&s(t.focus),t.highlight&&o(t.highlight)},[r,i,a,o,s])}}}function w0(e,t,n){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)();return(0,_.useEffect)(()=>{z(`/api/circuits`).then(e=>{i(e),t(t=>t??e[0])}).catch(t=>e(t.message)),z(`/api/sheets`).then(o).catch(t=>e(t.message)),z(`/api/project`).then(e=>c(e.name)).catch(t=>e(t.message)),n().catch(t=>e(t.message))},[e,t,n]),{files:r,sheets:a,project:s,refreshFiles:(0,_.useCallback)(()=>z(`/api/circuits`).then(i),[])}}function T0(e,t){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(),[o,s]=(0,_.useState)({status:`idle`}),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)({library:[],builtin:[]}),[m,h]=(0,_.useState)(),[g,v]=(0,_.useState)(),[y,b]=(0,_.useState)(!1),S=(0,_.useCallback)(e=>b(!e),[]),C=(0,_.useCallback)(t=>{x(t)&&s({status:`failed`,error:t}),e(t)},[e]),w=(0,_.useCallback)(async e=>{let[t,n]=await Promise.all([z(`/api/circuit?file=${encodeURIComponent(e)}`),z(`/api/history?limit=30`).catch(e=>({entries:[],problems:[{file:`history`,reason:e.message}]}))]);a(t),l(n.entries),d(n.problems)},[]),T=(0,_.useCallback)(async()=>{p(await z(`/api/parts`))},[]),E=(0,_.useCallback)(async e=>{let t=await z(`/api/build?file=${encodeURIComponent(e)}`);s(e=>t.status===`building`&&e.design?{...t,design:e.design}:t)},[]),{files:ee,sheets:D,project:O,refreshFiles:k}=w0(C,r,T),A=(0,_.useCallback)(t=>{if(h(t),E1(t))return;e(A1(t));let n=D1(t);n!==void 0&&(mP(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]),j=(0,_.useCallback)(t=>{if(v(t),M1(t))return;e(I1(t));let n=N1(t);n!==void 0&&(mP(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]);return(0,_.useEffect)(()=>{if(n)return t(),h(void 0),v(void 0),w(n).catch(e=>C(e.message)),z(`/api/build`,{file:n}).then(()=>E(n)).catch(e=>C(e.message)),_e((e,t,r)=>{if(e===`library`)T().catch(e=>C(e.message));else if(t===n){if(e===`route`)return A(r);if(e===`place`)return j(r);(e===`change`?w(n):E(n)).catch(e=>C(e.message))}},S)},[n,w,E,T,C,t,A,j,S]),{files:ee,sheets:D,project:O,file:n,setFile:r,circuit:i,build:o,history:c,historyProblems:u,parts:f,route:m,place:g,serverGone:y,refresh:w,refreshParts:T,refreshFiles:k}}function E0(e,t,n,r){let[i,a]=(0,_.useState)(),o=(0,_.useRef)(void 0);(0,_.useEffect)(()=>le.listen(r),[r]),(0,_.useEffect)(()=>{if(!t)return;let n=e[0];(n?.id!==o.current||i===void 0)&&(o.current=n?.id,a(e=>e===void 0?ne(n?.author):n?M(e,n.author):e))},[e,t,i]);let s=i?.closed??!1;return(0,_.useLayoutEffect)(()=>le.set(s),[s]),D0(s,n),{closed:s,toggle:(0,_.useCallback)(()=>a(e=>re(e??ne(void 0))),[])}}function D0(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e=>{let n=Yd(Pd(e),{view:t})?.action;n!==void 0&&F(n)&&(e.preventDefault(),e.stopImmediatePropagation(),le.refuses())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function O0({closed:e,onToggle:t}){let{title:n,hint:r}=oe(e),i=e?Zm:Qm,a=e?34:16;return(0,X.jsxs)(`button`,{type:`button`,className:e?`ai-lock closed`:`ai-lock`,"aria-pressed":e,"aria-label":`AI lock: ${n}. ${r}`,title:r,onClick:t,children:[(0,X.jsx)(i,{className:`ai-lock-icon`,width:a,height:a}),(0,X.jsxs)(`span`,{className:`ai-lock-words`,children:[(0,X.jsx)(`span`,{className:`ai-lock-title`,children:n}),(0,X.jsx)(`span`,{className:`ai-lock-hint`,children:r})]})]})}var k0=`copperflow.hoverLabels`,A0=`off`,j0=`on`;function M0(e){try{return e()?.getItem(k0)!==A0}catch{return!0}}function N0(e,t){try{let n=e();return n?(n.setItem(k0,t?j0:A0),!0):!1}catch{return!1}}var P0=`copperflow.system`,F0={unit:`mm`,grid:{schematic:ug,pcb:cg}},I0=(e,t,n)=>typeof e==`number`&&t.includes(e)?e:n;function L0(e){let t={};try{t=e?JSON.parse(e):{}}catch{t={}}let n=typeof t.grid==`object`&&t.grid!==null?t.grid:{};return{unit:t.unit===`mil`?`mil`:`mm`,grid:{schematic:I0(n.schematic,lg,ug),pcb:I0(n.pcb,sg,cg)}}}function R0(e){try{return L0(e()?.getItem(P0))}catch{return F0}}function z0(e,t){try{let n=e();return n?(n.setItem(P0,JSON.stringify({unit:t.unit,grid:t.grid})),!0):!1}catch{return!1}}function B0(){let[e,t]=(0,_.useState)(ka),[n,r]=(0,_.useState)(`all`),[i,a]=(0,_.useState)(`top`),o=(0,_.useCallback)(e=>t(t=>Ma(t,e)),[]),[s,c]=(0,_.useState)(()=>new Set);return{layerVisibility:e,layerFilter:n,setLayerFilter:r,toggleLayerShown:o,activeLayer:i,setActiveLayer:a,hiddenPours:s,togglePourShown:(0,_.useCallback)(e=>c(t=>Aa(t,e)),[])}}function V0(){let[e,t]=(0,_.useState)(La);return{pickFilter:e,togglePickable:(0,_.useCallback)(e=>t(t=>Ra(t,e)),[])}}var H0=new Set([`toggleLeftPanel`,`toggleRightPanel`,`toggleBottomPanel`,`toggleUnit`,`clearHighlight`,`openLibrary`,`toggleSnap`]);function U0(e){let[t,n]=(0,_.useState)(X1),[r,i]=(0,_.useState)(Y1),a=J1(r,e),[o,s]=(0,_.useState)(bm);return{left:t,setLeft:n,right:a,setRight:i,bottom:o,setBottom:s,clickLeft:(0,_.useCallback)(e=>n(t=>e0(t,e)),[]),selectLeft:(0,_.useCallback)(e=>n(t=>t0(t,e)),[]),clickRight:(0,_.useCallback)(t=>i(n=>Z1(J1(n,e),t)),[e]),selectRight:(0,_.useCallback)(e=>i(t=>$1(t,e)),[]),clickBottomTab:(0,_.useCallback)(e=>s(t=>xm(t,e)),[]),openBottom:(0,_.useCallback)(e=>s(t=>Cm(t,e)),[]),showSub:(0,_.useCallback)(e=>n(n0(e)),[])}}function W0(){let[e,t]=(0,_.useState)(!1);return[e,(0,_.useCallback)(()=>t(!0),[]),(0,_.useCallback)(()=>t(!1),[])]}function G0(e){let[t,n]=(0,_.useState)(()=>jy(pg,e)),[r,i]=(0,_.useState)(()=>R0(Cy).grid);return{gridStyles:t,gridSteps:r,setGridSteps:i,changeGridStep:(0,_.useCallback)((e,t)=>i(n=>dg(n,e,t)),[]),toggleGridStyleOf:(0,_.useCallback)(e=>n(t=>hg(t,e)),[]),gridFollowsTheme:(0,_.useCallback)((e,t)=>n(n=>Ay(n,e,t)),[])}}function K0(){let[e,t]=(0,_.useState)(()=>Ty(Cy));(0,_.useEffect)(()=>Dy(document.documentElement,e),[e]);let{gridFollowsTheme:n,...r}=G0(e),i=(0,_.useRef)(e);return{theme:e,setTheme:(0,_.useCallback)(e=>{n(i.current,e),i.current=e,t(e),Ey(Cy,e)},[n]),grid:r}}function q0(){let[e,t]=(0,_.useState)(!0);return{snap:e,toggleSnap:(0,_.useCallback)(()=>t(e=>!e),[])}}function J0(){let[e,t]=(0,_.useState)(()=>M0(Cy)),n=(0,_.useRef)(!0);return(0,_.useEffect)(()=>{n.current?n.current=!1:N0(Cy,e)},[e]),{hoverLabels:e,setHoverLabels:t,toggleHoverLabels:(0,_.useCallback)(()=>t(e=>!e),[])}}function Y0(){let[e,t]=(0,_.useState)(()=>$u(Cy));return{pourFill:e,setPourFill:(0,_.useCallback)(e=>{t(e),ed(Cy,e)},[])}}function X0(e,t){(0,_.useEffect)(()=>{let n=n=>{let r=Yd(Pd(n),{view:e});r&&H0.has(r.action)&&(r.preventDefault&&n.preventDefault(),t(r.action))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function Z0(e,t){let[n,r,i]=W0(),[a,o,s]=W0(),[c,l,u]=W0();return{focusSearch:n,requestSearch:r,searchFocused:i,focusPage:a,pageFocused:s,openPageTree:(0,_.useCallback)(()=>{e(n0(`page`)),o()},[e,o]),focusField:c,fieldFocused:u,openProperties:(0,_.useCallback)(()=>{t(e=>$1(e,`properties`)),l()},[t,l])}}function Q0(e,{strips:t,setUnit:n,setHighlight:r,toggleGridStyleOf:i,toggleSnap:a,requestSearch:o}){let{setLeft:s,setRight:c,setBottom:l}=t,u=(0,_.useRef)(e);return u.current=e,(0,_.useCallback)(e=>{e===`toggleLeftPanel`&&s(i0),e===`toggleRightPanel`&&c(Q1),e===`toggleBottomPanel`&&l(Sm),e===`toggleUnit`&&n(tg),e===`toggleGridStyle`&&i(u.current),e===`toggleSnap`&&a(),e===`clearHighlight`&&r(Ep),e===`openLibrary`&&(s(r0),o())},[s,c,l,n,r,o,i,a])}function $0(e){let{setLeft:t,setRight:n,setBottom:r,...i}=U0(e),{requestSearch:a,...o}=Z0(t,n),[s,c]=(0,_.useState)(()=>R0(Cy).unit),[l,u]=(0,_.useState)(Ep),{theme:d,setTheme:f,grid:p}=K0(),{toggleGridStyleOf:m,setGridSteps:h,...g}=p,{snap:v,toggleSnap:y}=q0(),{hoverLabels:b,setHoverLabels:x,toggleHoverLabels:S}=J0(),{pourFill:C,setPourFill:w}=Y0(),T=B0(),E=V0(),ee=Q0(e,{strips:{setLeft:t,setRight:n,setBottom:r},setUnit:c,setHighlight:u,toggleGridStyleOf:m,toggleSnap:y,requestSearch:a});X0(e,ee);let D=(0,_.useCallback)(()=>c(tg),[]),O=(0,_.useCallback)(e=>{f(e.theme),c(e.unit),h(e.grid),x(e.hoverLabels),z0(Cy,e)},[f,h,x]);return{...i,...g,theme:d,setTheme:f,applySystem:O,snap:v,hoverLabels:b,toggleHoverLabels:S,pourFill:C,setPourFill:w,...T,...E,...o,leftOpen:i.left.open,unit:s,toggleUnit:D,highlight:l,setHighlight:u,run:ee}}function e2(){let[e,t]=(0,_.useState)(null);return{message:e,notify:(0,_.useCallback)(e=>{t(e),window.setTimeout(()=>t(t=>t===e?null:t),6e3)},[]),dismiss:(0,_.useCallback)(()=>t(null),[])}}function t2(e){(0,_.useEffect)(()=>{let t=t=>{let n=t.target instanceof HTMLElement&&t.target.closest(`input, textarea, select`);t.key===`Escape`&&!n&&e(e=>e.clear())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function n2(e,t){let n=(0,_.useRef)([]);(0,_.useEffect)(()=>{if(!e)return;let r=e.model.parts.map(e=>e.name),i=xo(n.current,r);n.current=r,i.length>0&&t(e=>e.without(i))},[e,t])}function r2(e,t){let n=(0,_.useRef)(void 0),r=(0,_.useRef)([]);return(0,_.useEffect)(()=>{if(!e||e===n.current)return;let i=n.current;n.current=e;let a=e.schematic.drawings,o=r.current;r.current=Bp(_o.none,o,a).waiting,t(t=>{let n=Bp(am(t.wireCount===0?t:hm(t,i&&dm(i.schematic),dm(e.schematic)),i,e),o,a).selection;return Vp(n,i?.schematic.drawings,a)})},[e,t]),{seen:n,onRenameDrawing:(0,_.useCallback)(e=>(r.current=[...r.current,e],()=>{r.current=r.current.filter(t=>t!==e)}),[])}}function i2(e,t,n,r,i){return(0,_.useMemo)(()=>{let a=r===`pcb`?n?.circuit.components.filter(e=>e.instance!==void 0).map(e=>e.id)??[]:[],o=t&&[...t.model.parts.map(e=>e.name),...a],s=n?.schematic,c=e=>e?.map(e=>e.id),l=s&&zp(i?.schematic.drawings,s.drawings),u=n&&[...n.pcb.tracks,...n.pcb.vias].map(e=>e.id),d=n&&[...n.pcb.board?.pours??[],...n.pcb.holes??[]].map(e=>e.id),f=n&&c(r===`pcb`?pf(n.pcb):r===`schematic`?df(n.schematic):[]);return gm(e,{view:r,parts:o,wires:c(s?.wires),labels:c(s?.labels),drawings:l,copper:u,texts:f,board:d})},[e,t,n,r,i])}function a2(e,t){let n=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{let r=n.current;n.current=e,e&&e!==r&&t(t=>Mp(t,r,e))},[e,t])}function o2(){return(0,X.jsxs)(`p`,{className:`empty`,children:[`Open the address that `,(0,X.jsx)(`code`,{children:`copperflow studio`}),` printed in the terminal. It contains a key for this session.`]})}function s2(e,t,n){return T0(e,(0,_.useCallback)(()=>{t(_o.none),n(Ep)},[t,n]))}function c2({data:e,tab:t,setTab:n,select:r,selectOnly:i,workspace:a}){let{file:o,build:s}=e,{setHighlight:c,openBottom:l}=a,u=(0,_.useCallback)(()=>l(`drc`),[l]),d=(0,_.useCallback)((e,t)=>r(()=>_o.none.all([],[],[],[],e).addBoard(t)),[r]),f=b0({file:o,build:s,route:e.route,onTab:n,onSelect:i,onSelectCopper:d,onOpen:u}),p=(0,_.useCallback)(()=>l(`find`),[l]);return{checks:f,find:C0({file:o,circuit:e.circuit,library:e.parts.library,design:s.design,view:t,onSelect:r,onHighlight:c,requestFocus:f.requestFocus,openResults:p}),openChecks:u}}function l2(){let e=e2(),[t,n]=(0,_.useState)(_o.none),r=(0,_.useCallback)(e=>n(t=>t.only(e)),[]),[i,a]=(0,_.useState)(`pcb`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(),u=(0,_.useCallback)((e,t)=>l({id:e,title:t}),[]),d=(0,_.useCallback)(()=>l(void 0),[]),f=$0(i),p=s2(e.notify,n,f.setHighlight),{file:m,setFile:h,build:g,circuit:v}=p;n2(v,n);let{seen:y,onRenameDrawing:b}=r2(g.design,n),x=i2(t,v,g.design,i,y.current),S=g0({file:m,refresh:p.refresh,notify:e.notify,openVerify:u}),[C,w]=(0,_.useState)(dy),T=py(g.design,C),E=_0({file:m,refresh:p.refresh,notify:e.notify},r,i===`schematic`?T:dy),{checks:ee,find:D,openChecks:O}=c2({data:p,tab:i,setTab:a,select:n,selectOnly:r,workspace:f});t2(n),a2(g.design,f.setHighlight);let k=(0,_.useCallback)(()=>s(null),[]),A=(0,_.useCallback)(()=>s(`importPart`),[]),j=(0,_.useCallback)(()=>s(`newPart`),[]),[te,ne]=(0,_.useState)(),re=(0,_.useCallback)((e,t,n)=>{n===void 0?e!==m&&w(dy):w(n),at(e)?ne(e=>m&&!at(m)?{file:m,design:g.design}:e):ne(void 0),h(e),a(at(e)?`schematic`:t)},[h,m,g.design]),M=(0,_.useCallback)(e=>re(e,`schematic`),[re]),N=(0,_.useCallback)(e=>{w(e),a(`schematic`)},[]),P=g.design?.pcb,ie=(0,_.useMemo)(()=>i===`pcb`&&P?Ia(P.parts,f.layerVisibility):void 0,[i,P,f.layerVisibility]),F=(0,_.useMemo)(()=>g.design?my(g.design,T).schematic:void 0,[g.design,T]),I={sheetWires:(0,_.useMemo)(()=>i===`schematic`&&F?F.wires.map(e=>e.id):[],[i,F]),sheetLabels:(0,_.useMemo)(()=>i===`schematic`&&F?F.labels.map(e=>e.id):[],[i,F]),sheetDrawings:(0,_.useMemo)(()=>i===`schematic`&&F?F.drawings.map(e=>e.id):[],[i,F]),pcbCopper:(0,_.useMemo)(()=>i===`pcb`&&P?mu(P,f.layerVisibility).map(({kind:e,id:t})=>({kind:e,id:t})):[],[i,P,f.layerVisibility]),copperRecords:i===`pcb`?P:void 0},L=E0(p.history,v!==void 0,i,e.notify),R=Ew({file:m,openImported:(0,_.useCallback)(e=>void p.refreshFiles().then(()=>re(e,`pcb`)),[p,re]),view:i,setView:a,selection:x,select:n,circuit:v,actions:S,pickLayers:ie,pickFilter:f.pickFilter,...I,workspace:f,openChecks:O,checkCounts:ee.counts,openFind:D.open,openDialog:s,design:g.design,page:T,openPage:N,highlight:f.highlight}),ae=FV()!==void 0;return{verifying:c,closeVerify:d,aiLock:L,toast:e,tab:i,setTab:a,dialog:o,closeDialog:k,openImportPart:A,openNewPart:j,workspace:f,data:p,selection:x,select:n,onRenameDrawing:b,actions:S,place:E,checks:ee,find:D,openChecks:O,openDocument:re,openSheet:M,sheetParent:te,runCommand:(0,_.useCallback)(t=>ae&&se(t)?e.notify(yV):L.closed&&se(t)?void le.refuses():R(t),[L.closed,ae,R,e.notify]),page:T,openPage:N}}function u2(e){return(0,_.useMemo)(()=>{let t=et(e);return t===null?{}:{tidySheet:t}},[e])}function d2(e,t){return(0,_.useMemo)(()=>({import:async n=>{let r=await z(`/api/import-part`,n);return await e(),t(Oh(r)),r}}),[e,t])}function f2(e,t){return(0,_.useMemo)(()=>({create:async n=>{let r=await z(`/api/create-part`,n);return await e(),t(Bv(r)),r}}),[e,t])}function p2(e,t,n){return(0,_.useMemo)(()=>({create:async r=>{try{let i=await z(`/api/new-circuit`,r);return await e(),t(i.file,`schematic`),n(`Created ${i.file}; Undo removes it again`),!0}catch(e){return n(e.message),!1}}}),[e,t,n])}function m2(e,t,n){return(0,_.useMemo)(()=>{let r=new Set(t?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));return{source:e&&t?{components:e.circuit.components,parts:t.model.parts,locked:r}:void 0,write:n.edit}},[e,t,n])}function h2(e,t,n,r){return(0,_.useMemo)(()=>({question:Eb(t),showChecks:n,exportAnyway:()=>pw(e,r)}),[e,t,n,r])}function g2(e,t,n){return(0,_.useMemo)(()=>({parts:t,preview:n=>z(`/api/make-sheet`,{file:e,parts:t,...n,preview:!0}),make:e=>n.makeSheet({parts:t,...e})}),[e,t,n])}function _2(){let{verifying:e,closeVerify:t,aiLock:n,toast:r,tab:i,setTab:a,dialog:o,closeDialog:s,openImportPart:c,openNewPart:l,workspace:u,data:d,selection:f,select:p,onRenameDrawing:m,actions:h,place:g,checks:v,find:y,openChecks:b,openDocument:x,openSheet:S,sheetParent:C,runCommand:w,page:T,openPage:E}=l2(),{build:ee,circuit:D}=d,{message:O,dismiss:k}=r,A={snap:u.snap,hoverLabels:u.hoverLabels,...Oy(u.theme),...td(u.pourFill)},j=u2(ee.design),te=FV()!==void 0,ne=(0,_.useMemo)(()=>({...j,...P(n.closed),...CV(te)}),[j,n.closed,te]),re=g2(d.file,f.names,h),M=d2(d.refreshParts,r.notify),N=f2(d.refreshParts,r.notify),ie=zv(d.refreshParts),F=p2(d.refreshFiles,x,r.notify),I=m2(ee.design,D,h),L=h2(d.file,v.counts,b,h),R=(0,_.useSyncExternalStore)(f_.subscribe,f_.current),ae={settings:{theme:u.theme,unit:u.unit,grid:u.gridSteps,hoverLabels:u.hoverLabels},apply:u.applySystem};return(0,_.useEffect)(()=>zm(window),[]),me?(0,X.jsxs)(`div`,{className:`app`,children:[(0,X.jsx)(uy,{run:w,view:i,selected:f.size,toggles:A,off:ne,children:(0,X.jsx)(by,{build:ee,errors:v.counts.errors,onOpen:b})}),(0,X.jsx)(fb,{view:i,unit:u.unit,selected:f.size,toggles:A,off:ne,run:w}),o&&(0,X.jsx)(Z_,{name:o,onClose:s,rules:{fabrication:ee.design?.rules.fabrication,save:h.setFilletRadius},makeSheet:re,importPart:M,newPart:N,system:ae,newCircuit:F,footprints:I,exportChecks:L}),R&&(0,X.jsx)($_,{request:R,onClose:f_.close}),e&&(0,X.jsx)(Q_,{target:e,panel:ie,onClose:t}),d.serverGone&&(0,X.jsx)(`div`,{className:`banner`,role:`alert`,children:`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`}),D&&D.violations.length>0&&(0,X.jsxs)(`div`,{className:`banner`,role:`alert`,children:[`Locked parts changed outside the editor: `,D.violations.map(e=>`${e.part} (${e.detail})`).join(`, `),`. Lock them again to accept the change, or undo it in the code.`]}),(0,X.jsx)(h0,{data:d,workspace:u,checks:v,find:y,view:i,onView:a,page:T,onPage:E,selection:f,onSelect:p,onRenameDrawing:m,actions:h,run:w,onPlace:g,onImportPart:c,onNewPart:l,onOpenDocument:x,onOpenSheet:S,sheetParent:C,openChecks:b,aiLocked:n.closed,lockControl:(0,X.jsx)(O0,{closed:n.closed,onToggle:n.toggle})}),(0,X.jsx)(Lm,{state:u.bottom,onClick:u.clickBottomTab,onOpen:u.openBottom}),O&&(0,X.jsx)(`div`,{className:`toast`,role:`status`,onClick:k,children:O})]}):(0,X.jsx)(o2,{})}dh(window),Dy(document.documentElement,Ty(Cy)),(0,v.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(_.StrictMode,{children:(0,X.jsx)(_2,{})}));export{u as A,ov as C,a_ as D,o_ as E,Fm as O,tv as S,r_ as T,xH as _,aZ as a,wv as b,tq as c,HW as d,uW as f,SH as g,kU as h,MZ as i,W as k,DG as l,CW as m,LZ as n,cZ as o,xW as p,DZ as r,UK as s,BZ as t,OW as u,Bv as v,f_ as w,sv as x,av as y};