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
@@ -1,19 +0,0 @@
1
- var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var t=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.iterator;function p(e){return typeof e!=`object`||!e?null:(e=f&&e[f]||e[`@@iterator`],typeof e==`function`?e:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},h=Object.assign,g={};function _(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}_.prototype.isReactComponent={},_.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},_.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function v(){}v.prototype=_.prototype;function y(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}var b=y.prototype=new v;b.constructor=y,h(b,_.prototype),b.isPureReactComponent=!0;var x=Array.isArray,S={H:null,A:null,T:null,S:null,V:null},C=Object.prototype.hasOwnProperty;function w(e,n,r,i,a,o){return r=o.ref,{$$typeof:t,type:e,key:n,ref:r===void 0?null:r,props:o}}function T(e,t){return w(e.type,t,void 0,void 0,void 0,e.props)}function E(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function ee(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var D=/\/+/g;function O(e,t){return typeof e==`object`&&e&&e.key!=null?ee(``+e.key):t.toString(36)}function k(){}function A(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(k,k):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function j(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,j(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+O(e,0):a,x(o)?(i=``,c!=null&&(i=c.replace(D,`$&/`)+`/`),j(o,r,i,``,function(e){return e})):o!=null&&(E(o)&&(o=T(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(D,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(x(e))for(var u=0;u<e.length;u++)a=e[u],s=l+O(a,u),c+=j(a,r,i,s,o);else if(u=p(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+O(a,u++),c+=j(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return j(A(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function te(e,t,n){if(e==null)return e;var r=[],i=0;return j(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function M(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var ne=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function N(){}e.Children={map:te,forEach:function(e,t,n){te(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return te(e,function(){t++}),t},toArray:function(e){return te(e,function(e){return e})||[]},only:function(e){if(!E(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}},e.Component=_,e.Fragment=r,e.Profiler=a,e.PureComponent=y,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=S,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return S.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=h({},e.props),i=e.key,a=void 0;if(t!=null)for(o in t.ref!==void 0&&(a=void 0),t.key!==void 0&&(i=``+t.key),t)!C.call(t,o)||o===`key`||o===`__self`||o===`__source`||o===`ref`&&t.ref===void 0||(r[o]=t[o]);var o=arguments.length-2;if(o===1)r.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];r.children=s}return w(e.type,i,void 0,void 0,a,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)C.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return w(e,a,void 0,void 0,null,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=E,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:M}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=S.T,n={};S.T=n;try{var r=e(),i=S.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(N,ne)}catch(e){ne(e)}finally{S.T=t}},e.unstable_useCacheRefresh=function(){return S.H.useCacheRefresh()},e.use=function(e){return S.H.use(e)},e.useActionState=function(e,t,n){return S.H.useActionState(e,t,n)},e.useCallback=function(e,t){return S.H.useCallback(e,t)},e.useContext=function(e){return S.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return S.H.useDeferredValue(e,t)},e.useEffect=function(e,t,n){var r=S.H;if(typeof n==`function`)throw Error(`useEffect CRUD overload is not enabled in this build of React.`);return r.useEffect(e,t)},e.useId=function(){return S.H.useId()},e.useImperativeHandle=function(e,t,n){return S.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return S.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return S.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return S.H.useMemo(e,t)},e.useOptimistic=function(e,t){return S.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return S.H.useReducer(e,t,n)},e.useRef=function(e){return S.H.useRef(e)},e.useState=function(e){return S.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return S.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return S.H.useTransition()},e.version=`19.1.0`})),n=e(((e,n)=>{n.exports=t()})),r=e((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,D());else{var t=n(l);t!==null&&A(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function ee(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&A(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?D():S=!1}}}var D;if(typeof y==`function`)D=function(){y(ee)};else if(typeof MessageChannel<`u`){var O=new MessageChannel,k=O.port2;O.port1.onmessage=ee,D=function(){k.postMessage(null)}}else D=function(){_(ee,0)};function A(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,A(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,D()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),i=e(((e,t)=>{t.exports=r()})),a=e((e=>{var t=n();function r(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function i(){}var a={d:{f:i,r:function(){throw Error(r(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(r(299));return s(e,t,null,n)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)}},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.1.0`})),o=e(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=a()})),s=e((e=>{var t=i(),r=n(),a=o();function s(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function c(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function l(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function u(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function d(e){if(l(e)!==e)throw Error(s(188))}function f(e){var t=e.alternate;if(!t){if(t=l(e),t===null)throw Error(s(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===n)return d(i),e;if(a===r)return d(i),t;a=a.sibling}throw Error(s(188))}if(n.return!==r.return)n=i,r=a;else{for(var o=!1,c=i.child;c;){if(c===n){o=!0,n=i,r=a;break}if(c===r){o=!0,r=i,n=a;break}c=c.sibling}if(!o){for(c=a.child;c;){if(c===n){o=!0,n=a,r=i;break}if(c===r){o=!0,r=a,n=i;break}c=c.sibling}if(!o)throw Error(s(189))}}if(n.alternate!==r)throw Error(s(190))}if(n.tag!==3)throw Error(s(188));return n.stateNode.current===n?e:t}function p(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=p(e),t!==null)return t;e=e.sibling}return null}var m=Object.assign,h=Symbol.for(`react.element`),g=Symbol.for(`react.transitional.element`),_=Symbol.for(`react.portal`),v=Symbol.for(`react.fragment`),y=Symbol.for(`react.strict_mode`),b=Symbol.for(`react.profiler`),x=Symbol.for(`react.provider`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),ee=Symbol.for(`react.memo`),D=Symbol.for(`react.lazy`),O=Symbol.for(`react.activity`),k=Symbol.for(`react.memo_cache_sentinel`),A=Symbol.iterator;function j(e){return typeof e!=`object`||!e?null:(e=A&&e[A]||e[`@@iterator`],typeof e==`function`?e:null)}var te=Symbol.for(`react.client.reference`);function M(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===te?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case v:return`Fragment`;case b:return`Profiler`;case y:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case O:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case _:return`Portal`;case C:return(e.displayName||`Context`)+`.Provider`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case ee:return t=e.displayName||null,t===null?M(e.type)||`Memo`:t;case D:t=e._payload,e=e._init;try{return M(e(t))}catch{}}return null}var ne=Array.isArray,N=r.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=a.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},re=[],ie=-1;function I(e){return{current:e}}function L(e){0>ie||(e.current=re[ie],re[ie]=null,ie--)}function R(e,t){ie++,re[ie]=e.current,e.current=t}var ae=I(null),oe=I(null),z=I(null),se=I(null);function ce(e,t){switch(R(z,t),R(oe,e),R(ae,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ad(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ad(t),e=jd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}L(ae),R(ae,e)}function le(){L(ae),L(oe),L(z)}function ue(e){e.memoizedState!==null&&R(se,e);var t=ae.current,n=jd(t,e.type);t!==n&&(R(oe,e),R(ae,n))}function B(e){oe.current===e&&(L(ae),L(oe)),se.current===e&&(L(se),Rf._currentValue=F)}var de=Object.prototype.hasOwnProperty,fe=t.unstable_scheduleCallback,pe=t.unstable_cancelCallback,me=t.unstable_shouldYield,V=t.unstable_requestPaint,he=t.unstable_now,ge=t.unstable_getCurrentPriorityLevel,_e=t.unstable_ImmediatePriority,ve=t.unstable_UserBlockingPriority,ye=t.unstable_NormalPriority,be=t.unstable_LowPriority,xe=t.unstable_IdlePriority,Se=t.log,Ce=t.unstable_setDisableYieldValue,we=null,Te=null;function Ee(e){if(typeof Se==`function`&&Ce(e),Te&&typeof Te.setStrictMode==`function`)try{Te.setStrictMode(we,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=P.p;return e===0?(e=window.event,e===void 0?32:$f(e.type)):e}function qe(e,t){var n=P.p;try{return P.p=e,t()}finally{P.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=Yd(e);e!==null;){if(n=e[Ye])return n;e=Yd(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(s(33))}function st(e){var t=e[tt];return t||=e[tt]={hoistableStyles:new Map,hoistableScripts:new Map},t}function ct(e){e[nt]=!0}var lt=new Set,ut={};function dt(e,t){ft(e,t),ft(e+`Capture`,t)}function ft(e,t){for(ut[e]=t,e=0;e<t.length;e++)lt.add(t[e])}var pt=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]*$`),mt={},ht={};function gt(e){return de.call(ht,e)?!0:de.call(mt,e)?!1:pt.test(e)?ht[e]=!0:(mt[e]=!0,!1)}function _t(e,t,n){if(gt(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 vt(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 yt(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 bt,xt;function St(e){if(bt===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);bt=t&&t[1]||``,xt=-1<e.stack.indexOf(`
2
- at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
3
- `+bt+e+xt}var Ct=!1;function wt(e,t){if(!e||Ct)return``;Ct=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
4
- `),l=s.split(`
5
- `);for(i=r=0;r<c.length&&!c[r].includes(`DetermineComponentFrameRoot`);)r++;for(;i<l.length&&!l[i].includes(`DetermineComponentFrameRoot`);)i++;if(r===c.length||i===l.length)for(r=c.length-1,i=l.length-1;1<=r&&0<=i&&c[r]!==l[i];)i--;for(;1<=r&&0<=i;r--,i--)if(c[r]!==l[i]){if(r!==1||i!==1)do if(r--,i--,0>i||c[r]!==l[i]){var u=`
6
- `+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{Ct=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?St(n):``}function Tt(e){switch(e.tag){case 26:case 27:case 5:return St(e.type);case 16:return St(`Lazy`);case 13:return St(`Suspense`);case 19:return St(`SuspenseList`);case 0:case 15:return wt(e.type,!1);case 11:return wt(e.type.render,!1);case 1:return wt(e.type,!0);case 31:return St(`Activity`);default:return``}}function Et(e){try{var t=``;do t+=Tt(e),e=e.return;while(e);return t}catch(e){return`
7
- Error generating stack: `+e.message+`
8
- `+e.stack}}function Dt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function Ot(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function kt(e){var t=Ot(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 At(e){e._valueTracker||=kt(e)}function jt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=Ot(e)?e.checked?`true`:`false`:e.value),e=r,e!==n&&(t.setValue(e),!0)}function Mt(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 Nt=/[\n"\\]/g;function Pt(e){return e.replace(Nt,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function Ft(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=``+Dt(t)):e.value!==``+Dt(t)&&(e.value=``+Dt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):Lt(e,o,Dt(n)):Lt(e,o,Dt(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=``+Dt(s):e.removeAttribute(`name`)}function It(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?``:``+Dt(n),t=t==null?n:``+Dt(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 Lt(e,t,n){t===`number`&&Mt(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function Rt(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=``+Dt(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 zt(e,t,n){t!=null&&(t=``+Dt(t),t!==e.value&&(e.value=t),n==null)?e.defaultValue!==t&&(e.defaultValue=t):e.defaultValue=n==null?``:``+Dt(n)}function Bt(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(s(92));if(ne(r)){if(1<r.length)throw Error(s(93));r=r[0]}n=r}n??=``,t=n}n=Dt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r)}function Vt(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Ht=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 Ut(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||Ht.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Wt(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(s(62));if(e=e.style,n!=null){for(var r in n)!n.hasOwnProperty(r)||t!=null&&t.hasOwnProperty(r)||(r.indexOf(`--`)===0?e.setProperty(r,``):r===`float`?e.cssFloat=``:e[r]=``);for(var i in t)r=t[i],t.hasOwnProperty(i)&&n[i]!==r&&Ut(e,i,r)}else for(var a in t)t.hasOwnProperty(a)&&Ut(e,a,t[a])}function Gt(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 Kt=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`]]),qt=/^[\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 Jt(e){return qt.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}var Yt=null;function Xt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Zt=null,Qt=null;function $t(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(Ft(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="`+Pt(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var i=r[Xe]||null;if(!i)throw Error(s(90));Ft(r,i.value,i.defaultValue,i.defaultValue,i.checked,i.defaultChecked,i.type,i.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&jt(r)}break a;case`textarea`:zt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&Rt(e,!!n.multiple,t,!1)}}}var en=!1;function tn(e,t,n){if(en)return e(t,n);en=!0;try{return e(t)}finally{if(en=!1,(Zt!==null||Qt!==null)&&(lu(),Zt&&(t=Zt,e=Qt,Qt=Zt=null,$t(t),e)))for(t=0;t<e.length;t++)$t(e[t])}}function nn(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(s(231,t,typeof n));return n}var rn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,an=!1;if(rn)try{var on={};Object.defineProperty(on,"passive",{get:function(){an=!0}}),window.addEventListener(`test`,on,on),window.removeEventListener(`test`,on,on)}catch{an=!1}var sn=null,cn=null,ln=null;function un(){if(ln)return ln;var e,t=cn,n=t.length,r,i=`value`in sn?sn.value:sn.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 ln=i.slice(e,1<r?1-r:void 0)}function dn(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 fn(){return!0}function pn(){return!1}function mn(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)?fn:pn,this.isPropagationStopped=pn,this}return m(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():typeof e.returnValue!=`unknown`&&(e.returnValue=!1),this.isDefaultPrevented=fn)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=fn)},persist:function(){},isPersistent:fn}),t}var hn={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},gn=mn(hn),_n=m({},hn,{view:0,detail:0}),vn=mn(_n),yn,bn,xn,Sn=m({},_n,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Nn,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!==xn&&(xn&&e.type===`mousemove`?(yn=e.screenX-xn.screenX,bn=e.screenY-xn.screenY):bn=yn=0,xn=e),yn)},movementY:function(e){return`movementY`in e?e.movementY:bn}}),Cn=mn(Sn),wn=mn(m({},Sn,{dataTransfer:0})),Tn=mn(m({},_n,{relatedTarget:0})),En=mn(m({},hn,{animationName:0,elapsedTime:0,pseudoElement:0})),Dn=mn(m({},hn,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),On=mn(m({},hn,{data:0})),kn={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},An={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`},jn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function Mn(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=jn[e])?!!t[e]:!1}function Nn(){return Mn}var Pn=mn(m({},_n,{key:function(e){if(e.key){var t=kn[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=dn(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?An[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Nn,charCode:function(e){return e.type===`keypress`?dn(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?dn(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),Fn=mn(m({},Sn,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),In=mn(m({},_n,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Nn})),Ln=mn(m({},hn,{propertyName:0,elapsedTime:0,pseudoElement:0})),Rn=mn(m({},Sn,{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})),zn=mn(m({},hn,{newState:0,oldState:0})),Bn=[9,13,27,32],Vn=rn&&`CompositionEvent`in window,Hn=null;rn&&`documentMode`in document&&(Hn=document.documentMode);var Un=rn&&`TextEvent`in window&&!Hn,Wn=rn&&(!Vn||Hn&&8<Hn&&11>=Hn),Gn=` `,Kn=!1;function qn(e,t){switch(e){case`keyup`:return Bn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Jn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var Yn=!1;function Xn(e,t){switch(e){case`compositionend`:return Jn(t);case`keypress`:return t.which===32?(Kn=!0,Gn):null;case`textInput`:return e=t.data,e===Gn&&Kn?null:e;default:return null}}function Zn(e,t){if(Yn)return e===`compositionend`||!Vn&&qn(e,t)?(e=un(),ln=cn=sn=null,Yn=!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 Wn&&t.locale!==`ko`?null:t.data;default:return null}}var Qn={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 $n(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!Qn[e.type]:t===`textarea`}function er(e,t,n,r){Zt?Qt?Qt.push(r):Qt=[r]:Zt=r,t=hd(t,`onChange`),0<t.length&&(n=new gn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var tr=null,nr=null;function rr(e){cd(e,0)}function ir(e){if(jt(ot(e)))return e}function ar(e,t){if(e===`change`)return t}var or=!1;if(rn){var sr;if(rn){var cr=`oninput`in document;if(!cr){var lr=document.createElement(`div`);lr.setAttribute(`oninput`,`return;`),cr=typeof lr.oninput==`function`}sr=cr}else sr=!1;or=sr&&(!document.documentMode||9<document.documentMode)}function ur(){tr&&(tr.detachEvent(`onpropertychange`,dr),nr=tr=null)}function dr(e){if(e.propertyName===`value`&&ir(nr)){var t=[];er(t,nr,e,Xt(e)),tn(rr,t)}}function fr(e,t,n){e===`focusin`?(ur(),tr=t,nr=n,tr.attachEvent(`onpropertychange`,dr)):e===`focusout`&&ur()}function pr(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return ir(nr)}function mr(e,t){if(e===`click`)return ir(t)}function hr(e,t){if(e===`input`||e===`change`)return ir(t)}function gr(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var _r=typeof Object.is==`function`?Object.is:gr;function vr(e,t){if(_r(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(!de.call(t,i)||!_r(e[i],t[i]))return!1}return!0}function yr(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function br(e,t){var n=yr(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=yr(n)}}function xr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?xr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Sr(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Mt(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=Mt(e.document)}return t}function Cr(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 wr=rn&&`documentMode`in document&&11>=document.documentMode,Tr=null,Er=null,Dr=null,Or=!1;function kr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Or||Tr==null||Tr!==Mt(r)||(r=Tr,`selectionStart`in r&&Cr(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}),Dr&&vr(Dr,r)||(Dr=r,r=hd(Er,`onSelect`),0<r.length&&(t=new gn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=Tr)))}function Ar(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var jr={animationend:Ar(`Animation`,`AnimationEnd`),animationiteration:Ar(`Animation`,`AnimationIteration`),animationstart:Ar(`Animation`,`AnimationStart`),transitionrun:Ar(`Transition`,`TransitionRun`),transitionstart:Ar(`Transition`,`TransitionStart`),transitioncancel:Ar(`Transition`,`TransitionCancel`),transitionend:Ar(`Transition`,`TransitionEnd`)},Mr={},Nr={};rn&&(Nr=document.createElement(`div`).style,`AnimationEvent`in window||(delete jr.animationend.animation,delete jr.animationiteration.animation,delete jr.animationstart.animation),`TransitionEvent`in window||delete jr.transitionend.transition);function Pr(e){if(Mr[e])return Mr[e];if(!jr[e])return e;var t=jr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in Nr)return Mr[e]=t[n];return e}var Fr=Pr(`animationend`),Ir=Pr(`animationiteration`),Lr=Pr(`animationstart`),Rr=Pr(`transitionrun`),zr=Pr(`transitionstart`),Br=Pr(`transitioncancel`),Vr=Pr(`transitionend`),Hr=new Map,Ur=`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(` `);Ur.push(`scrollEnd`);function Wr(e,t){Hr.set(e,t),dt(t,[e])}var Gr=new WeakMap;function Kr(e,t){if(typeof e==`object`&&e){var n=Gr.get(e);return n===void 0?(t={value:e,source:t,stack:Et(t)},Gr.set(e,t),t):n}return{value:e,source:t,stack:Et(t)}}var qr=[],Jr=0,Yr=0;function Xr(){for(var e=Jr,t=Yr=Jr=0;t<e;){var n=qr[t];qr[t++]=null;var r=qr[t];qr[t++]=null;var i=qr[t];qr[t++]=null;var a=qr[t];if(qr[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&&ei(n,i,a)}}function Zr(e,t,n,r){qr[Jr++]=e,qr[Jr++]=t,qr[Jr++]=n,qr[Jr++]=r,Yr|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function Qr(e,t,n,r){return Zr(e,t,n,r),ti(e)}function $r(e,t){return Zr(e,null,null,t),ti(e)}function ei(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 ti(e){if(50<eu)throw eu=0,tu=null,Error(s(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var ni={};function ri(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 ii(e,t,n,r){return new ri(e,t,n,r)}function ai(e){return e=e.prototype,!(!e||!e.isReactComponent)}function oi(e,t){var n=e.alternate;return n===null?(n=ii(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 si(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 ci(e,t,n,r,i,a){var o=0;if(r=e,typeof e==`function`)ai(e)&&(o=1);else if(typeof e==`string`)o=Of(e,n,ae.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case O:return e=ii(31,n,t,i),e.elementType=O,e.lanes=a,e;case v:return li(n.children,i,a,t);case y:o=8,i|=24;break;case b:return e=ii(12,n,t,i|2),e.elementType=b,e.lanes=a,e;case T:return e=ii(13,n,t,i),e.elementType=T,e.lanes=a,e;case E:return e=ii(19,n,t,i),e.elementType=E,e.lanes=a,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case x:case C:o=10;break a;case S:o=9;break a;case w:o=11;break a;case ee:o=14;break a;case D:o=16,r=null;break a}o=29,n=Error(s(130,e===null?`null`:typeof e,``)),r=null}return t=ii(o,n,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function li(e,t,n,r){return e=ii(7,e,r,t),e.lanes=n,e}function ui(e,t,n){return e=ii(6,e,null,t),e.lanes=n,e}function di(e,t,n){return t=ii(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var fi=[],pi=0,mi=null,hi=0,gi=[],_i=0,vi=null,yi=1,bi=``;function xi(e,t){fi[pi++]=hi,fi[pi++]=mi,mi=e,hi=t}function Si(e,t,n){gi[_i++]=yi,gi[_i++]=bi,gi[_i++]=vi,vi=e;var r=yi;e=bi;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,yi=1<<32-De(t)+i|n<<i|r,bi=a+e}else yi=1<<a|n<<i|r,bi=e}function Ci(e){e.return!==null&&(xi(e,1),Si(e,1,0))}function wi(e){for(;e===mi;)mi=fi[--pi],fi[pi]=null,hi=fi[--pi],fi[pi]=null;for(;e===vi;)vi=gi[--_i],gi[_i]=null,bi=gi[--_i],gi[_i]=null,yi=gi[--_i],gi[_i]=null}var Ti=null,Ei=null,H=!1,Di=null,Oi=!1,ki=Error(s(519));function Ai(e){throw Fi(Kr(Error(s(418,``)),e)),ki}function ji(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[Ye]=e,t[Xe]=r,n){case`dialog`:X(`cancel`,t),X(`close`,t);break;case`iframe`:case`object`:case`embed`:X(`load`,t);break;case`video`:case`audio`:for(n=0;n<od.length;n++)X(od[n],t);break;case`source`:X(`error`,t);break;case`img`:case`image`:case`link`:X(`error`,t),X(`load`,t);break;case`details`:X(`toggle`,t);break;case`input`:X(`invalid`,t),It(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0),At(t);break;case`select`:X(`invalid`,t);break;case`textarea`:X(`invalid`,t),Bt(t,r.value,r.defaultValue,r.children),At(t)}n=r.children,typeof n!=`string`&&typeof n!=`number`&&typeof n!=`bigint`||t.textContent===``+n||!0===r.suppressHydrationWarning||xd(t.textContent,n)?(r.popover!=null&&(X(`beforetoggle`,t),X(`toggle`,t)),r.onScroll!=null&&X(`scroll`,t),r.onScrollEnd!=null&&X(`scrollend`,t),r.onClick!=null&&(t.onclick=Sd),t=!0):t=!1,t||Ai(e)}function U(e){for(Ti=e.return;Ti;)switch(Ti.tag){case 5:case 13:Oi=!1;return;case 27:case 3:Oi=!0;return;default:Ti=Ti.return}}function Mi(e){if(e!==Ti)return!1;if(!H)return U(e),H=!0,!1;var t=e.tag,n;if((n=t!==3&&t!==27)&&((n=t===5)&&(n=e.type,n=n===`form`||n===`button`||Md(e.type,e.memoizedProps)),n=!n),n&&Ei&&Ai(e),U(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(s(317));a:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){if(n=e.data,n===`/$`){if(t===0){Ei=qd(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}Ei=null}}else t===27?(t=Ei,Bd(e.type)?(e=Jd,Jd=null,Ei=e):Ei=t):Ei=Ti?qd(e.stateNode.nextSibling):null;return!0}function Ni(){Ei=Ti=null,H=!1}function Pi(){var e=Di;return e!==null&&(Vl===null?Vl=e:Vl.push.apply(Vl,e),Di=null),e}function Fi(e){Di===null?Di=[e]:Di.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 i=e.child;for(i!==null&&(i.return=e);i!==null;){var a=i.dependencies;if(a!==null){var o=i.child;a=a.firstContext;a:for(;a!==null;){var c=a;a=i;for(var l=0;l<t.length;l++)if(c.context===t[l]){a.lanes|=n,c=a.alternate,c!==null&&(c.lanes|=n),Vi(a.return,n,e),r||(o=null);break a}a=c.next}}else if(i.tag===18){if(o=i.return,o===null)throw Error(s(341));o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),Vi(o,n,e),o=null}else o=i.child;if(o!==null)o.return=i;else for(o=i;o!==null;){if(o===e){o=null;break}if(i=o.sibling,i!==null){i.return=o.return,o=i;break}o=o.return}i=o}}function Ui(e,t,n,r){e=null;for(var i=t,a=!1;i!==null;){if(!a){if(i.flags&524288)a=!0;else if(i.flags&262144)break}if(i.tag===10){var o=i.alternate;if(o===null)throw Error(s(387));if(o=o.memoizedProps,o!==null){var c=i.type;_r(i.pendingProps.value,o.value)||(e===null?e=[c]:e.push(c))}}else if(i===se.current){if(o=i.alternate,o===null)throw Error(s(387));o.memoizedState.memoizedState!==i.memoizedState.memoizedState&&(e===null?e=[Rf]:e.push(Rf))}i=i.return}e!==null&&Hi(t,e,n,r),t.flags|=262144}function Wi(e){for(e=e.firstContext;e!==null;){if(!_r(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(s(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=ed(),ia={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return na++,t.then(oa,oa),t}function oa(){if(--na===0&&ta!==null){ia!==null&&(ia.status=`fulfilled`);var e=ta;ta=null,ra=0,ia=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function sa(e,t){var n=[],r={status:`pending`,value:null,reason:null,then:function(e){n.push(e)}};return e.then(function(){r.status=`fulfilled`,r.value=t;for(var e=0;e<n.length;e++)(0,n[e])(t)},function(e){for(r.status=`rejected`,r.reason=e,e=0;e<n.length;e++)(0,n[e])(void 0)}),r}var ca=N.S;N.S=function(e,t){typeof t==`object`&&t&&typeof t.then==`function`&&aa(e,t),ca!==null&&ca(e,t)};var la=I(null);function ua(){var e=la.current;return e===null?Dl.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(s(460)),ma=Error(s(474)),ha=Error(s(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=Dl,e!==null&&100<e.shellSuspendCounter)throw Error(s(482));e=t,e.status=`pending`,e.then(function(e){if(t.status===`pending`){var n=t;n.status=`fulfilled`,n.value=e}},function(e){if(t.status===`pending`){var n=t;n.status=`rejected`,n.reason=e}})}switch(t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Sa(e),e}throw ba=t,pa}}var ba=null;function xa(){if(ba===null)throw Error(s(459));var e=ba;return ba=null,e}function Sa(e){if(e===pa||e===ha)throw Error(s(483))}var Ca=!1;function wa(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Ta(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 Ea(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Da(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,q&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=ti(e),ei(e,null,n),t}return Zr(e,r,t,n),ti(e)}function Oa(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 ka(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 Aa=!1;function ja(){if(Aa){var e=ia;if(e!==null)throw e}}function Ma(e,t,n,r){Aa=!1;var i=e.updateQueue;Ca=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane&-536870913,p=f!==s.lane;if(p?(Y&f)===f:(r&f)===f){f!==0&&f===ra&&(Aa=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var h=e,g=s;f=t;var _=n;switch(g.tag){case 1:if(h=g.payload,typeof h==`function`){d=h.call(_,d,f);break a}d=h;break a;case 3:h.flags=h.flags&-65537|128;case 0:if(h=g.payload,f=typeof h==`function`?h.call(_,d,f):h,f==null)break a;d=m({},d,f);break a;case 2:Ca=!0}}f=s.callback,f!==null&&(e.flags|=64,p&&(e.flags|=8192),p=i.callbacks,p===null?i.callbacks=[f]:p.push(f))}else p={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;p=s,s=p.next,p.next=null,i.lastBaseUpdate=p,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),Fl|=o,e.lanes=o,e.memoizedState=d}}function Na(e,t){if(typeof e!=`function`)throw Error(s(191,e));e.call(t)}function Pa(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Na(n[e],t)}var Fa=I(null),Ia=I(0);function La(e,t){e=Nl,R(Ia,e),R(Fa,t),Nl=e|t.baseLanes}function Ra(){R(Ia,Nl),R(Fa,Fa.current)}function za(){Nl=Ia.current,L(Fa),L(Ia)}var Ba=0,W=null,G=null,K=null,Va=!1,Ha=!1,Ua=!1,Wa=0,Ga=0,Ka=null,qa=0;function Ja(){throw Error(s(321))}function Ya(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!_r(e[n],t[n]))return!1;return!0}function Xa(e,t,n,r,i,a){return Ba=a,W=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,N.H=e===null||e.memoizedState===null?ps:ms,Ua=!1,a=n(r,i),Ua=!1,Ha&&(a=Qa(t,n,r,i)),Za(e),a}function Za(e){N.H=fs;var t=G!==null&&G.next!==null;if(Ba=0,K=G=W=null,Va=!1,Ga=0,Ka=null,t)throw Error(s(300));e===null||Ys||(e=e.dependencies,e!==null&&Wi(e)&&(Ys=!0))}function Qa(e,t,n,r){W=e;var i=0;do{if(Ha&&(Ka=null),Ga=0,Ha=!1,25<=i)throw Error(s(301));if(i+=1,K=G=null,e.updateQueue!=null){var a=e.updateQueue;a.lastEffect=null,a.events=null,a.stores=null,a.memoCache!=null&&(a.memoCache.index=0)}N.H=hs,a=t(n,r)}while(Ha);return a}function $a(){var e=N.H,t=e.useState()[0];return t=typeof t.then==`function`?oo(t):t,e=e.useState()[0],(G===null?null:G.memoizedState)!==e&&(W.flags|=1024),t}function eo(){var e=Wa!==0;return Wa=0,e}function to(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function no(e){if(Va){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}Va=!1}Ba=0,K=G=W=null,Ha=!1,Ga=Wa=0,Ka=null}function ro(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return K===null?W.memoizedState=K=e:K=K.next=e,K}function io(){if(G===null){var e=W.alternate;e=e===null?null:e.memoizedState}else e=G.next;var t=K===null?W.memoizedState:K.next;if(t!==null)K=t,G=e;else{if(e===null)throw W.alternate===null?Error(s(467)):Error(s(310));G=e,e={memoizedState:G.memoizedState,baseState:G.baseState,baseQueue:G.baseQueue,queue:G.queue,next:null},K===null?W.memoizedState=K=e:K=K.next=e}return K}function ao(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function oo(e){var t=Ga;return Ga+=1,Ka===null&&(Ka=[]),e=ya(Ka,e,t),t=W,(K===null?t.memoizedState:K.next)===null&&(t=t.alternate,N.H=t===null||t.memoizedState===null?ps:ms),e}function so(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return oo(e);if(e.$$typeof===C)return Ki(e)}throw Error(s(438,String(e)))}function co(e){var t=null,n=W.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=W.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=ao(),W.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 lo(e,t){return typeof t==`function`?t(e):t}function uo(e){return fo(io(),G,e)}function fo(e,t,n){var r=e.queue;if(r===null)throw Error(s(311));r.lastRenderedReducer=n;var i=e.baseQueue,a=r.pending;if(a!==null){if(i!==null){var o=i.next;i.next=a.next,a.next=o}t.baseQueue=i=a,r.pending=null}if(a=e.baseState,i===null)e.memoizedState=a;else{t=i.next;var c=o=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(Ba&f)===f:(Y&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((Ba&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,o=a):l=l.next=f,W.lanes|=p,Fl|=p;f=u.action,Ua&&n(a,f),a=u.hasEagerState?u.eagerState:n(a,f)}else p={lane:f,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,o=a):l=l.next=p,W.lanes|=f,Fl|=f;u=u.next}while(u!==null&&u!==t);if(l===null?o=a:l.next=c,!_r(a,e.memoizedState)&&(Ys=!0,d&&(n=ia,n!==null)))throw n;e.memoizedState=a,e.baseState=o,e.baseQueue=l,r.lastRenderedState=a}return i===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function po(e){var t=io(),n=t.queue;if(n===null)throw Error(s(311));n.lastRenderedReducer=e;var r=n.dispatch,i=n.pending,a=t.memoizedState;if(i!==null){n.pending=null;var o=i=i.next;do a=e(a,o.action),o=o.next;while(o!==i);_r(a,t.memoizedState)||(Ys=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),n.lastRenderedState=a}return[a,r]}function mo(e,t,n){var r=W,i=io(),a=H;if(a){if(n===void 0)throw Error(s(407));n=n()}else n=t();var o=!_r((G||i).memoizedState,n);if(o&&(i.memoizedState=n,Ys=!0),i=i.queue,Ro(2048,8,_o.bind(null,r,i,e),[e]),i.getSnapshot!==t||o||K!==null&&K.memoizedState.tag&1){if(r.flags|=2048,Po(9,Fo(),go.bind(null,r,i,n,t),null),Dl===null)throw Error(s(349));a||Ba&124||ho(r,t,n)}return n}function ho(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=W.updateQueue,t===null?(t=ao(),W.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function go(e,t,n,r){t.value=n,t.getSnapshot=r,vo(t)&&yo(e)}function _o(e,t,n){return n(function(){vo(t)&&yo(e)})}function vo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!_r(e,n)}catch{return!0}}function yo(e){var t=$r(e,2);t!==null&&iu(t,e,2)}function bo(e){var t=ro();if(typeof e==`function`){var n=e;if(e=n(),Ua){Ee(!0);try{n()}finally{Ee(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:lo,lastRenderedState:e},t}function xo(e,t,n,r){return e.baseState=n,fo(e,G,typeof r==`function`?r:lo)}function So(e,t,n,r,i){if(ls(e))throw Error(s(485));if(e=t.action,e!==null){var a={payload:i,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){a.listeners.push(e)}};N.T===null?a.isTransition=!1:n(!0),r(a),n=t.pending,n===null?(a.next=t.pending=a,Co(t,a)):(a.next=n.next,t.pending=n.next=a)}}function Co(e,t){var n=t.action,r=t.payload,i=e.state;if(t.isTransition){var a=N.T,o={};N.T=o;try{var s=n(i,r),c=N.S;c!==null&&c(o,s),wo(e,t,s)}catch(n){Eo(e,t,n)}finally{N.T=a}}else try{a=n(i,r),wo(e,t,a)}catch(n){Eo(e,t,n)}}function wo(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){To(e,t,n)},function(n){return Eo(e,t,n)}):To(e,t,n)}function To(e,t,n){t.status=`fulfilled`,t.value=n,Do(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,Co(e,n)))}function Eo(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,Do(t),t=t.next;while(t!==r)}e.action=null}function Do(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function Oo(e,t){return t}function ko(e,t){if(H){var n=Dl.formState;if(n!==null){a:{var r=W;if(H){if(Ei){b:{for(var i=Ei,a=Oi;i.nodeType!==8;)if(!a||(i=qd(i.nextSibling),i===null)){i=null;break b}a=i.data,i=a===`F!`||a===`F`?i:null}if(i){Ei=qd(i.nextSibling),r=i.data===`F!`;break a}}Ai(r)}r=!1}r&&(t=n[0])}}return n=ro(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:Oo,lastRenderedState:t},n.queue=r,n=os.bind(null,W,r),r.dispatch=n,r=bo(!1),a=cs.bind(null,W,!1,r.queue),r=ro(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=So.bind(null,W,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function Ao(e){return jo(io(),G,e)}function jo(e,t,n){if(t=fo(e,t,Oo)[0],e=uo(lo)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=oo(t)}catch(e){throw e===pa?ha:e}else r=t;t=io();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(W.flags|=2048,Po(9,Fo(),Mo.bind(null,i,n),null)),[r,a,e]}function Mo(e,t){e.action=t}function No(e){var t=io(),n=G;if(n!==null)return jo(t,n,e);io(),t=t.memoizedState,n=io();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function Po(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=W.updateQueue,t===null&&(t=ao(),W.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 Fo(){return{destroy:void 0,resource:void 0}}function Io(){return io().memoizedState}function Lo(e,t,n,r){var i=ro();r=r===void 0?null:r,W.flags|=e,i.memoizedState=Po(1|t,Fo(),n,r)}function Ro(e,t,n,r){var i=io();r=r===void 0?null:r;var a=i.memoizedState.inst;G!==null&&r!==null&&Ya(r,G.memoizedState.deps)?i.memoizedState=Po(t,a,n,r):(W.flags|=e,i.memoizedState=Po(1|t,a,n,r))}function zo(e,t){Lo(8390656,8,e,t)}function Bo(e,t){Ro(2048,8,e,t)}function Vo(e,t){return Ro(4,2,e,t)}function Ho(e,t){return Ro(4,4,e,t)}function Uo(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 Wo(e,t,n){n=n==null?null:n.concat([e]),Ro(4,4,Uo.bind(null,t,e),n)}function Go(){}function Ko(e,t){var n=io();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&Ya(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function qo(e,t){var n=io();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&Ya(t,r[1]))return r[0];if(r=e(),Ua){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r}function Jo(e,t,n){return n===void 0||Ba&1073741824?e.memoizedState=t:(e.memoizedState=n,e=ru(),W.lanes|=e,Fl|=e,n)}function Yo(e,t,n,r){return _r(n,t)?n:Fa.current===null?Ba&42?(e=ru(),W.lanes|=e,Fl|=e,t):(Ys=!0,e.memoizedState=n):(e=Jo(e,n,r),_r(e,t)||(Ys=!0),e)}function Xo(e,t,n,r,i){var a=P.p;P.p=a!==0&&8>a?a:8;var o=N.T,s={};N.T=s,cs(e,!1,t,n);try{var c=i(),l=N.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?ss(e,t,sa(c,r),nu(e)):ss(e,t,r,nu(e))}catch(n){ss(e,t,{then:function(){},status:`rejected`,reason:n},nu())}finally{P.p=a,N.T=o}}function Zo(){}function Qo(e,t,n,r){if(e.tag!==5)throw Error(s(476));var i=$o(e).queue;Xo(e,i,t,F,n===null?Zo:function(){return es(e),n(r)})}function $o(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:F,baseState:F,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:lo,lastRenderedState:F},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:lo,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function es(e){var t=$o(e).next.queue;ss(e,t,{},nu())}function ts(){return Ki(Rf)}function ns(){return io().memoizedState}function rs(){return io().memoizedState}function is(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=nu();e=Ea(n);var r=Da(t,e,n);r!==null&&(iu(r,t,n),Oa(r,t,n)),t={cache:$i()},e.payload=t;return}t=t.return}}function as(e,t,n){var r=nu();n={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null},ls(e)?us(t,n):(n=Qr(e,t,n,r),n!==null&&(iu(n,e,r),ds(n,t,r)))}function os(e,t,n){ss(e,t,n,nu())}function ss(e,t,n,r){var i={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null};if(ls(e))us(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,_r(s,o))return Zr(e,t,i,0),Dl===null&&Xr(),!1}catch{}if(n=Qr(e,t,i,r),n!==null)return iu(n,e,r),ds(n,t,r),!0}return!1}function cs(e,t,n,r){if(r={lane:2,revertLane:ed(),action:r,hasEagerState:!1,eagerState:null,next:null},ls(e)){if(t)throw Error(s(479))}else t=Qr(e,n,r,2),t!==null&&iu(t,e,2)}function ls(e){var t=e.alternate;return e===W||t!==null&&t===W}function us(e,t){Ha=Va=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function ds(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ue(e,n)}}var fs={readContext:Ki,use:so,useCallback:Ja,useContext:Ja,useEffect:Ja,useImperativeHandle:Ja,useLayoutEffect:Ja,useInsertionEffect:Ja,useMemo:Ja,useReducer:Ja,useRef:Ja,useState:Ja,useDebugValue:Ja,useDeferredValue:Ja,useTransition:Ja,useSyncExternalStore:Ja,useId:Ja,useHostTransitionStatus:Ja,useFormState:Ja,useActionState:Ja,useOptimistic:Ja,useMemoCache:Ja,useCacheRefresh:Ja},ps={readContext:Ki,use:so,useCallback:function(e,t){return ro().memoizedState=[e,t===void 0?null:t],e},useContext:Ki,useEffect:zo,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),Lo(4194308,4,Uo.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Lo(4194308,4,e,t)},useInsertionEffect:function(e,t){Lo(4,2,e,t)},useMemo:function(e,t){var n=ro();t=t===void 0?null:t;var r=e();if(Ua){Ee(!0);try{e()}finally{Ee(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=ro();if(n!==void 0){var i=n(t);if(Ua){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=as.bind(null,W,e),[r.memoizedState,e]},useRef:function(e){var t=ro();return e={current:e},t.memoizedState=e},useState:function(e){e=bo(e);var t=e.queue,n=os.bind(null,W,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:Go,useDeferredValue:function(e,t){return Jo(ro(),e,t)},useTransition:function(){var e=bo(!1);return e=Xo.bind(null,W,e.queue,!0,!1),ro().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=W,i=ro();if(H){if(n===void 0)throw Error(s(407));n=n()}else{if(n=t(),Dl===null)throw Error(s(349));Y&124||ho(r,t,n)}i.memoizedState=n;var a={value:n,getSnapshot:t};return i.queue=a,zo(_o.bind(null,r,a,e),[e]),r.flags|=2048,Po(9,Fo(),go.bind(null,r,a,n,t),null),n},useId:function(){var e=ro(),t=Dl.identifierPrefix;if(H){var n=bi,r=yi;n=(r&~(1<<32-De(r)-1)).toString(32)+n,t=`«`+t+`R`+n,n=Wa++,0<n&&(t+=`H`+n.toString(32)),t+=`»`}else n=qa++,t=`«`+t+`r`+n.toString(32)+`»`;return e.memoizedState=t},useHostTransitionStatus:ts,useFormState:ko,useActionState:ko,useOptimistic:function(e){var t=ro();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=cs.bind(null,W,!0,n),n.dispatch=t,[e,t]},useMemoCache:co,useCacheRefresh:function(){return ro().memoizedState=is.bind(null,W)}},ms={readContext:Ki,use:so,useCallback:Ko,useContext:Ki,useEffect:Bo,useImperativeHandle:Wo,useInsertionEffect:Vo,useLayoutEffect:Ho,useMemo:qo,useReducer:uo,useRef:Io,useState:function(){return uo(lo)},useDebugValue:Go,useDeferredValue:function(e,t){return Yo(io(),G.memoizedState,e,t)},useTransition:function(){var e=uo(lo)[0],t=io().memoizedState;return[typeof e==`boolean`?e:oo(e),t]},useSyncExternalStore:mo,useId:ns,useHostTransitionStatus:ts,useFormState:Ao,useActionState:Ao,useOptimistic:function(e,t){return xo(io(),G,e,t)},useMemoCache:co,useCacheRefresh:rs},hs={readContext:Ki,use:so,useCallback:Ko,useContext:Ki,useEffect:Bo,useImperativeHandle:Wo,useInsertionEffect:Vo,useLayoutEffect:Ho,useMemo:qo,useReducer:po,useRef:Io,useState:function(){return po(lo)},useDebugValue:Go,useDeferredValue:function(e,t){var n=io();return G===null?Jo(n,e,t):Yo(n,G.memoizedState,e,t)},useTransition:function(){var e=po(lo)[0],t=io().memoizedState;return[typeof e==`boolean`?e:oo(e),t]},useSyncExternalStore:mo,useId:ns,useHostTransitionStatus:ts,useFormState:No,useActionState:No,useOptimistic:function(e,t){var n=io();return G===null?(n.baseState=e,[e,n.queue.dispatch]):xo(n,G,e,t)},useMemoCache:co,useCacheRefresh:rs},gs=null,_s=0;function vs(e){var t=_s;return _s+=1,gs===null&&(gs=[]),ya(gs,e,t)}function ys(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function bs(e,t){throw t.$$typeof===h?Error(s(525)):(e=Object.prototype.toString.call(t),Error(s(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function xs(e){var t=e._init;return t(e._payload)}function Ss(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function r(e){for(var t=new Map;e!==null;)e.key===null?t.set(e.index,e):t.set(e.key,e),e=e.sibling;return t}function i(e,t){return e=oi(e,t),e.index=0,e.sibling=null,e}function a(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=67108866,n):(r=r.index,r<n?(t.flags|=67108866,n):r)):(t.flags|=1048576,n)}function o(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=ui(n,e.mode,r),t.return=e,t):(t=i(t,n),t.return=e,t)}function l(e,t,n,r){var a=n.type;return a===v?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===a||typeof a==`object`&&a&&a.$$typeof===D&&xs(a)===t.type)?(t=i(t,n.props),ys(t,n),t.return=e,t):(t=ci(n.type,n.key,n.props,null,e.mode,r),ys(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=di(n,e.mode,r),t.return=e,t):(t=i(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,a){return t===null||t.tag!==7?(t=li(n,e.mode,r,a),t.return=e,t):(t=i(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=ui(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case g:return n=ci(t.type,t.key,t.props,null,e.mode,n),ys(n,t),n.return=e,n;case _:return t=di(t,e.mode,n),t.return=e,t;case D:var r=t._init;return t=r(t._payload),f(e,t,n)}if(ne(t)||j(t))return t=li(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,vs(t),n);if(t.$$typeof===C)return f(e,qi(e,t),n);bs(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`||typeof n==`bigint`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case g:return n.key===i?l(e,t,n,r):null;case _:return n.key===i?u(e,t,n,r):null;case D:return i=n._init,n=i(n._payload),p(e,t,n,r)}if(ne(n)||j(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,vs(n),r);if(n.$$typeof===C)return p(e,t,qi(e,n),r);bs(e,n)}return null}function m(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`||typeof r==`bigint`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case g:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case _:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case D:var a=r._init;return r=a(r._payload),m(e,t,n,r,i)}if(ne(r)||j(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return m(e,t,n,vs(r),i);if(r.$$typeof===C)return m(e,t,n,qi(t,r),i);bs(t,r)}return null}function h(i,o,s,c){for(var l=null,u=null,d=o,h=o=0,g=null;d!==null&&h<s.length;h++){d.index>h?(g=d,d=null):g=d.sibling;var _=p(i,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(i,d),o=a(_,o,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),H&&xi(i,h),l;if(d===null){for(;h<s.length;h++)d=f(i,s[h],c),d!==null&&(o=a(d,o,h),u===null?l=d:u.sibling=d,u=d);return H&&xi(i,h),l}for(d=r(d);h<s.length;h++)g=m(d,i,h,s[h],c),g!==null&&(e&&g.alternate!==null&&d.delete(g.key===null?h:g.key),o=a(g,o,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(i,e)}),H&&xi(i,h),l}function y(i,o,c,l){if(c==null)throw Error(s(151));for(var u=null,d=null,h=o,g=o=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(i,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(i,h),o=a(y,o,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(i,h),H&&xi(i,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(i,v.value,l),v!==null&&(o=a(v,o,g),d===null?u=v:d.sibling=v,d=v);return H&&xi(i,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,i,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),o=a(v,o,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(i,e)}),H&&xi(i,g),u}function b(e,r,a,c){if(typeof a==`object`&&a&&a.type===v&&a.key===null&&(a=a.props.children),typeof a==`object`&&a){switch(a.$$typeof){case g:a:{for(var l=a.key;r!==null;){if(r.key===l){if(l=a.type,l===v){if(r.tag===7){n(e,r.sibling),c=i(r,a.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===D&&xs(l)===r.type){n(e,r.sibling),c=i(r,a.props),ys(c,a),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}a.type===v?(c=li(a.props.children,e.mode,c,a.key),c.return=e,e=c):(c=ci(a.type,a.key,a.props,null,e.mode,c),ys(c,a),c.return=e,e=c)}return o(e);case _:a:{for(l=a.key;r!==null;){if(r.key===l){if(r.tag===4&&r.stateNode.containerInfo===a.containerInfo&&r.stateNode.implementation===a.implementation){n(e,r.sibling),c=i(r,a.children||[]),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}c=di(a,e.mode,c),c.return=e,e=c}return o(e);case D:return l=a._init,a=l(a._payload),b(e,r,a,c)}if(ne(a))return h(e,r,a,c);if(j(a)){if(l=j(a),typeof l!=`function`)throw Error(s(150));return a=l.call(a),y(e,r,a,c)}if(typeof a.then==`function`)return b(e,r,vs(a),c);if(a.$$typeof===C)return b(e,r,qi(e,a),c);bs(e,a)}return typeof a==`string`&&a!==``||typeof a==`number`||typeof a==`bigint`?(a=``+a,r!==null&&r.tag===6?(n(e,r.sibling),c=i(r,a),c.return=e,e=c):(n(e,r),c=ui(a,e.mode,c),c.return=e,e=c),o(e)):n(e,r)}return function(e,t,n,r){try{_s=0;var i=b(e,t,n,r);return gs=null,i}catch(t){if(t===pa||t===ha)throw t;var a=ii(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var Cs=Ss(!0),ws=Ss(!1),Ts=I(null),Es=null;function Ds(e){var t=e.alternate;R(js,js.current&1),R(Ts,e),Es===null&&(t===null||Fa.current!==null||t.memoizedState!==null)&&(Es=e)}function Os(e){if(e.tag===22){if(R(js,js.current),R(Ts,e),Es===null){var t=e.alternate;t!==null&&t.memoizedState!==null&&(Es=e)}}else ks(e)}function ks(){R(js,js.current),R(Ts,Ts.current)}function As(e){L(Ts),Es===e&&(Es=null),L(js)}var js=I(0);function Ms(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===`$?`||Gd(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 Ns(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:m({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Ps={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=nu(),i=Ea(r);i.payload=t,n!=null&&(i.callback=n),t=Da(e,i,r),t!==null&&(iu(t,e,r),Oa(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=nu(),i=Ea(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Da(e,i,r),t!==null&&(iu(t,e,r),Oa(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=nu(),r=Ea(n);r.tag=2,t!=null&&(r.callback=t),t=Da(e,r,n),t!==null&&(iu(t,e,n),Oa(t,e,n))}};function Fs(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?!vr(n,r)||!vr(i,a):!0}function Is(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&&Ps.enqueueReplaceState(t,t.state,null)}function Ls(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=m({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}var Rs=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 zs(e){Rs(e)}function Bs(e){console.error(e)}function Vs(e){Rs(e)}function Hs(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Us(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 Ws(e,t,n){return n=Ea(n),n.tag=3,n.payload={element:null},n.callback=function(){Hs(e,t)},n}function Gs(e){return e=Ea(e),e.tag=3,e}function Ks(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(){Us(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Us(t,n,r),typeof i!=`function`&&(Kl===null?Kl=new Set([this]):Kl.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function qs(e,t,n,r,i){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Ui(t,n,i,!0),n=Ts.current,n!==null){switch(n.tag){case 13:return Es===null?hu():n.alternate===null&&Pl===0&&(Pl=3),n.flags&=-257,n.flags|=65536,n.lanes=i,r===ga?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),Pu(e,r,i)),!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)),Pu(e,r,i)),!1}throw Error(s(435,n.tag))}return Pu(e,r,i),hu(),!1}if(H)return t=Ts.current,t===null?(r!==ki&&(t=Error(s(423),{cause:r}),Fi(Kr(t,n))),e=e.current.alternate,e.flags|=65536,i&=-i,e.lanes|=i,r=Kr(r,n),i=Ws(e.stateNode,r,i),ka(e,i),Pl!==4&&(Pl=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=i,r!==ki&&(e=Error(s(422),{cause:r}),Fi(Kr(e,n)))),!1;var a=Error(s(520),{cause:r});if(a=Kr(a,n),Bl===null?Bl=[a]:Bl.push(a),Pl!==4&&(Pl=2),t===null)return!0;r=Kr(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=i&-i,n.lanes|=e,e=Ws(n.stateNode,r,e),ka(n,e),!1;case 1:if(t=n.type,a=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||a!==null&&typeof a.componentDidCatch==`function`&&(Kl===null||!Kl.has(a))))return n.flags|=65536,i&=-i,n.lanes|=i,i=Gs(i),Ks(i,e,n,r),ka(n,i),!1}n=n.return}while(n!==null);return!1}var Js=Error(s(461)),Ys=!1;function Xs(e,t,n,r){t.child=e===null?ws(t,null,n,r):Cs(t,e.child,n,r)}function Zs(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=Xa(e,t,n,o,a,i),s=eo(),e!==null&&!Ys?(to(e,t,i),_c(e,t,i)):(H&&s&&Ci(t),t.flags|=1,Xs(e,t,r,i),t.child)}function Qs(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!ai(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,$s(e,t,a,r,i)):(e=ci(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!vc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?vr:n,n(o,r)&&e.ref===t.ref)return _c(e,t,i)}return t.flags|=1,e=oi(a,r),e.ref=t.ref,e.return=t,t.child=e}function $s(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(vr(a,r)&&e.ref===t.ref){if(Ys=!1,t.pendingProps=r=a,vc(e,i))e.flags&131072&&(Ys=!0);else return t.lanes=e.lanes,_c(e,t,i)}}return rc(e,t,n,r,i)}function ec(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 tc(e,t,r,n)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&da(t,a===null?null:a.cachePool),a===null?Ra():La(t,a),Os(t);else return t.lanes=t.childLanes=536870912,tc(e,t,a===null?n:a.baseLanes|n,n)}else a===null?(e!==null&&da(t,null),Ra(),ks(t)):(da(t,a.cachePool),La(t,a),ks(t),t.memoizedState=null);return Xs(e,t,i,n),t.child}function tc(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),Ra(),Os(t),e!==null&&Ui(e,t,r,!0),null}function nc(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(s(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function rc(e,t,n,r,i){return Gi(t),n=Xa(e,t,n,r,void 0,i),r=eo(),e!==null&&!Ys?(to(e,t,i),_c(e,t,i)):(H&&r&&Ci(t),t.flags|=1,Xs(e,t,n,i),t.child)}function ic(e,t,n,r,i,a){return Gi(t),t.updateQueue=null,n=Qa(t,r,n,i),Za(e),r=eo(),e!==null&&!Ys?(to(e,t,a),_c(e,t,a)):(H&&r&&Ci(t),t.flags|=1,Xs(e,t,n,a),t.child)}function ac(e,t,n,r,i){if(Gi(t),t.stateNode===null){var a=ni,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=Ps,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},wa(t),o=n.contextType,a.context=typeof o==`object`&&o?Ki(o):ni,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Ns(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&&Ps.enqueueReplaceState(a,a.state,null),Ma(t,r,a,i),ja(),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=Ls(n,s);a.props=c;var l=a.context,u=n.contextType;o=ni,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)&&Is(t,a,r,o),Ca=!1;var f=t.memoizedState;a.state=f,Ma(t,r,a,i),ja(),l=t.memoizedState,s||f!==l||Ca?(typeof d==`function`&&(Ns(t,n,d,r),l=t.memoizedState),(c=Ca||Fs(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,Ta(e,t),o=t.memoizedProps,u=Ls(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=ni,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)&&Is(t,a,r,c),Ca=!1,f=t.memoizedState,a.state=f,Ma(t,r,a,i),ja();var p=t.memoizedState;o!==d||f!==p||Ca||e!==null&&e.dependencies!==null&&Wi(e.dependencies)?(typeof s==`function`&&(Ns(t,n,s,r),p=t.memoizedState),(u=Ca||Fs(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,nc(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=Cs(t,e.child,null,i),t.child=Cs(t,null,n,i)):Xs(e,t,n,i),t.memoizedState=a.state,e=t.child):e=_c(e,t,i),e}function oc(e,t,n,r){return Ni(),t.flags|=256,Xs(e,t,n,r),t.child}var sc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function cc(e){return{baseLanes:e,cachePool:fa()}}function lc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=Rl),e}function uc(e,t,n){var r=t.pendingProps,i=!1,a=!!(t.flags&128),o;if((o=a)||(o=e!==null&&e.memoizedState===null?!1:!!(js.current&2)),o&&(i=!0,t.flags&=-129),o=!!(t.flags&32),t.flags&=-33,e===null){if(H){if(i?Ds(t):ks(t),H){var c=Ei,l;if(l=c){c:{for(l=c,c=Oi;l.nodeType!==8;)if(!c||(l=qd(l.nextSibling),l===null)){c=null;break c}c=l}c===null?l=!1:(t.memoizedState={dehydrated:c,treeContext:vi===null?null:{id:yi,overflow:bi},retryLane:536870912,hydrationErrors:null},l=ii(18,null,null,0),l.stateNode=c,l.return=t,t.child=l,Ti=t,Ei=null,l=!0)}l||Ai(t)}if(c=t.memoizedState,c!==null&&(c=c.dehydrated,c!==null))return Gd(c)?t.lanes=32:t.lanes=536870912,null;As(t)}return c=r.children,r=r.fallback,i?(ks(t),i=t.mode,c=fc({mode:`hidden`,children:c},i),r=li(r,i,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,i=t.child,i.memoizedState=cc(n),i.childLanes=lc(e,o,n),t.memoizedState=sc,r):(Ds(t),dc(t,c))}if(l=e.memoizedState,l!==null&&(c=l.dehydrated,c!==null)){if(a)t.flags&256?(Ds(t),t.flags&=-257,t=pc(e,t,n)):t.memoizedState===null?(ks(t),i=r.fallback,c=t.mode,r=fc({mode:`visible`,children:r.children},c),i=li(i,c,n,null),i.flags|=2,r.return=t,i.return=t,r.sibling=i,t.child=r,Cs(t,e.child,null,n),r=t.child,r.memoizedState=cc(n),r.childLanes=lc(e,o,n),t.memoizedState=sc,t=i):(ks(t),t.child=e.child,t.flags|=128,t=null);else if(Ds(t),Gd(c)){if(o=c.nextSibling&&c.nextSibling.dataset,o)var u=o.dgst;o=u,r=Error(s(419)),r.stack=``,r.digest=o,Fi({value:r,source:null,stack:null}),t=pc(e,t,n)}else if(Ys||Ui(e,t,n,!1),o=(n&e.childLanes)!==0,Ys||o){if(o=Dl,o!==null&&(r=n&-n,r=r&42?1:We(r),r=(r&(o.suspendedLanes|n))===0?r:0,r!==0&&r!==l.retryLane))throw l.retryLane=r,$r(e,r),iu(o,e,r),Js;c.data===`$?`||hu(),t=pc(e,t,n)}else c.data===`$?`?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,Ei=qd(c.nextSibling),Ti=t,H=!0,Di=null,Oi=!1,e!==null&&(gi[_i++]=yi,gi[_i++]=bi,gi[_i++]=vi,yi=e.id,bi=e.overflow,vi=t),t=dc(t,r.children),t.flags|=4096);return t}return i?(ks(t),i=r.fallback,c=t.mode,l=e.child,u=l.sibling,r=oi(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(i=li(i,c,n,null),i.flags|=2):i=oi(u,i),i.return=t,r.return=t,r.sibling=i,t.child=r,r=i,i=t.child,c=e.child.memoizedState,c===null?c=cc(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}),i.memoizedState=c,i.childLanes=lc(e,o,n),t.memoizedState=sc,r):(Ds(t),n=e.child,e=n.sibling,n=oi(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(o=t.deletions,o===null?(t.deletions=[e],t.flags|=16):o.push(e)),t.child=n,t.memoizedState=null,n)}function dc(e,t){return t=fc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function fc(e,t){return e=ii(22,e,null,t),e.lanes=0,e.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null},e}function pc(e,t,n){return Cs(t,e.child,null,n),e=dc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function mc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Vi(e.return,t,n)}function hc(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 gc(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Xs(e,t,r.children,n),r=js.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&&mc(e,n,t);else if(e.tag===19)mc(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(js,r),i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&Ms(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),hc(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&&Ms(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}hc(t,!0,n,null,a);break;case`together`:hc(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function _c(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Fl|=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(s(153));if(t.child!==null){for(e=t.child,n=oi(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=oi(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function vc(e,t){return(e.lanes&t)!==0||(e=e.dependencies,!!(e!==null&&Wi(e)))}function yc(e,t,n){switch(t.tag){case 3:ce(t,t.stateNode.containerInfo),zi(t,Qi,e.memoizedState.cache),Ni();break;case 27:case 5:ue(t);break;case 4:ce(t,t.stateNode.containerInfo);break;case 10:zi(t,t.type,t.memoizedProps.value);break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(Ds(t),e=_c(e,t,n),e===null?null:e.sibling):uc(e,t,n):(Ds(t),t.flags|=128,null);Ds(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 gc(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),R(js,js.current),r)break;return null;case 22:case 23:return t.lanes=0,ec(e,t,n);case 24:zi(t,Qi,e.memoizedState.cache)}return _c(e,t,n)}function bc(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps)Ys=!0;else{if(!vc(e,n)&&!(t.flags&128))return Ys=!1,yc(e,t,n);Ys=!!(e.flags&131072)}}else Ys=!1,H&&t.flags&1048576&&Si(t,hi,t.index);switch(t.lanes=0,t.tag){case 16:a:{e=t.pendingProps;var r=t.elementType,i=r._init;if(r=i(r._payload),t.type=r,typeof r==`function`)ai(r)?(e=Ls(r,e),t.tag=1,t=ac(null,t,r,e,n)):(t.tag=0,t=rc(null,t,r,e,n));else{if(r!=null){if(i=r.$$typeof,i===w){t.tag=11,t=Zs(null,t,r,e,n);break a}if(i===ee){t.tag=14,t=Qs(null,t,r,e,n);break a}}throw t=M(r)||r,Error(s(306,t,``))}}return t;case 0:return rc(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,i=Ls(r,t.pendingProps),ac(e,t,r,i,n);case 3:a:{if(ce(t,t.stateNode.containerInfo),e===null)throw Error(s(387));r=t.pendingProps;var a=t.memoizedState;i=a.element,Ta(e,t),Ma(t,r,null,n);var o=t.memoizedState;if(r=o.cache,zi(t,Qi,r),r!==a.cache&&Hi(t,[Qi],n,!0),ja(),r=o.element,a.isDehydrated){if(a={element:r,isDehydrated:!1,cache:o.cache},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){t=oc(e,t,r,n);break a}if(r!==i){i=Kr(Error(s(424)),t),Fi(i),t=oc(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(Ei=qd(e.firstChild),Ti=t,H=!0,Di=null,Oi=!0,n=ws(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Ni(),r===i){t=_c(e,t,n);break a}Xs(e,t,r,n)}t=t.child}return t;case 26:return nc(e,t),e===null?(n=mf(t.type,null,t.pendingProps,null))?t.memoizedState=n:H||(n=t.type,e=t.pendingProps,r=kd(z.current).createElement(n),r[Ye]=t,r[Xe]=e,Td(r,n,e),ct(r),t.stateNode=r):t.memoizedState=mf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return ue(t),e===null&&H&&(r=t.stateNode=Xd(t.type,t.pendingProps,z.current),Ti=t,Oi=!0,i=Ei,Bd(t.type)?(Jd=i,Ei=qd(r.firstChild)):Ei=i),Xs(e,t,t.pendingProps.children,n),nc(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&H&&((i=r=Ei)&&(r=Ud(r,t.type,t.pendingProps,Oi),r===null?i=!1:(t.stateNode=r,Ti=t,Ei=qd(r.firstChild),Oi=!1,i=!0)),i||Ai(t)),ue(t),i=t.type,a=t.pendingProps,o=e===null?null:e.memoizedProps,r=a.children,Md(i,a)?r=null:o!==null&&Md(i,o)&&(t.flags|=32),t.memoizedState!==null&&(i=Xa(e,t,$a,null,null,n),Rf._currentValue=i),nc(e,t),Xs(e,t,r,n),t.child;case 6:return e===null&&H&&((e=n=Ei)&&(n=Wd(n,t.pendingProps,Oi),n===null?e=!1:(t.stateNode=n,Ti=t,Ei=null,e=!0)),e||Ai(t)),null;case 13:return uc(e,t,n);case 4:return ce(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Cs(t,null,r,n):Xs(e,t,r,n),t.child;case 11:return Zs(e,t,t.type,t.pendingProps,n);case 7:return Xs(e,t,t.pendingProps,n),t.child;case 8:return Xs(e,t,t.pendingProps.children,n),t.child;case 12:return Xs(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,zi(t,t.type,r.value),Xs(e,t,r.children,n),t.child;case 9:return i=t.type._context,r=t.pendingProps.children,Gi(t),i=Ki(i),r=r(i),t.flags|=1,Xs(e,t,r,n),t.child;case 14:return Qs(e,t,t.type,t.pendingProps,n);case 15:return $s(e,t,t.type,t.pendingProps,n);case 19:return gc(e,t,n);case 31:return r=t.pendingProps,n=t.mode,r={mode:r.mode,children:r.children},e===null?(n=fc(r,n),n.ref=t.ref,t.child=n,n.return=t,t=n):(n=oi(e.child,r),n.ref=t.ref,t.child=n,n.return=t,t=n),t;case 22:return ec(e,t,n);case 24:return Gi(t),r=Ki(Qi),e===null?(i=ua(),i===null&&(i=Dl,a=$i(),i.pooledCache=a,a.refCount++,a!==null&&(i.pooledCacheLanes|=n),i=a),t.memoizedState={parent:r,cache:i},wa(t),zi(t,Qi,i)):((e.lanes&n)!==0&&(Ta(e,t),Ma(t,null,null,n),ja()),i=e.memoizedState,a=t.memoizedState,i.parent===r?(r=a.cache,zi(t,Qi,r),r!==i.cache&&Hi(t,[Qi],n,!0)):(i={parent:r,cache:r},t.memoizedState=i,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=i),zi(t,Qi,r))),Xs(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(s(156,t.tag))}function xc(e){e.flags|=4}function Sc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!kf(t)){if(t=Ts.current,t!==null&&((Y&4194048)===Y?Es!==null:(Y&62914560)!==Y&&!(Y&536870912)||t!==Es))throw ba=ga,ma;e.flags|=8192}}function Cc(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Re(),e.lanes|=t,zl|=t)}function wc(e,t){if(!H)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 Tc(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 Ec(e,t,n){var r=t.pendingProps;switch(wi(t),t.tag){case 31:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Tc(t),null;case 1:return Tc(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Bi(Qi),le(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Mi(t)?xc(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Pi())),Tc(t),null;case 26:return n=t.memoizedState,e===null?(xc(t),n===null?(Tc(t),t.flags&=-16777217):(Tc(t),Sc(t,n))):n?n===e.memoizedState?(Tc(t),t.flags&=-16777217):(xc(t),Tc(t),Sc(t,n)):(e.memoizedProps!==r&&xc(t),Tc(t),t.flags&=-16777217),null;case 27:B(t),n=z.current;var i=t.type;if(e!==null&&t.stateNode!=null)e.memoizedProps!==r&&xc(t);else{if(!r){if(t.stateNode===null)throw Error(s(166));return Tc(t),null}e=ae.current,Mi(t)?ji(t,e):(e=Xd(i,r,n),t.stateNode=e,xc(t))}return Tc(t),null;case 5:if(B(t),n=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&xc(t);else{if(!r){if(t.stateNode===null)throw Error(s(166));return Tc(t),null}if(e=ae.current,Mi(t))ji(t,e);else{switch(i=kd(z.current),e){case 1:e=i.createElementNS(`http://www.w3.org/2000/svg`,n);break;case 2:e=i.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;default:switch(n){case`svg`:e=i.createElementNS(`http://www.w3.org/2000/svg`,n);break;case`math`:e=i.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;case`script`:e=i.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild);break;case`select`:e=typeof r.is==`string`?i.createElement(`select`,{is:r.is}):i.createElement(`select`),r.multiple?e.multiple=!0:r.size&&(e.size=r.size);break;default:e=typeof r.is==`string`?i.createElement(n,{is:r.is}):i.createElement(n)}}e[Ye]=t,e[Xe]=r;a:for(i=t.child;i!==null;){if(i.tag===5||i.tag===6)e.appendChild(i.stateNode);else if(i.tag!==4&&i.tag!==27&&i.child!==null){i.child.return=i,i=i.child;continue}if(i===t)break a;for(;i.sibling===null;){if(i.return===null||i.return===t)break a;i=i.return}i.sibling.return=i.return,i=i.sibling}t.stateNode=e;a:switch(Td(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&&xc(t)}}return Tc(t),t.flags&=-16777217,null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&xc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(s(166));if(e=z.current,Mi(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,i=Ti,i!==null)switch(i.tag){case 27:case 5:r=i.memoizedProps}e[Ye]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||xd(e.nodeValue,n)),e||Ai(t)}else e=kd(e).createTextNode(r),e[Ye]=t,t.stateNode=e}return Tc(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(i=Mi(t),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(s(318));if(i=t.memoizedState,i=i===null?null:i.dehydrated,!i)throw Error(s(317));i[Ye]=t}else Ni(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Tc(t),i=!1}else i=Pi(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=i),i=!0;if(!i)return t.flags&256?(As(t),t):(As(t),null)}if(As(t),t.flags&128)return t.lanes=n,t;if(n=r!==null,e=e!==null&&e.memoizedState!==null,n){r=t.child,i=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(i=r.alternate.memoizedState.cachePool.pool);var a=null;r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(a=r.memoizedState.cachePool.pool),a!==i&&(r.flags|=2048)}return n!==e&&n&&(t.child.flags|=8192),Cc(t,t.updateQueue),Tc(t),null;case 4:return le(),e===null&&dd(t.stateNode.containerInfo),Tc(t),null;case 10:return Bi(t.type),Tc(t),null;case 19:if(L(js),i=t.memoizedState,i===null)return Tc(t),null;if(r=!!(t.flags&128),a=i.rendering,a===null){if(r)wc(i,!1);else{if(Pl!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(a=Ms(e),a!==null){for(t.flags|=128,wc(i,!1),e=a.updateQueue,t.updateQueue=e,Cc(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)si(n,e),n=n.sibling;return R(js,js.current&1|2),t.child}e=e.sibling}i.tail!==null&&he()>Wl&&(t.flags|=128,r=!0,wc(i,!1),t.lanes=4194304)}}else{if(!r){if(e=Ms(a),e!==null){if(t.flags|=128,r=!0,e=e.updateQueue,t.updateQueue=e,Cc(t,e),wc(i,!0),i.tail===null&&i.tailMode===`hidden`&&!a.alternate&&!H)return Tc(t),null}else 2*he()-i.renderingStartTime>Wl&&n!==536870912&&(t.flags|=128,r=!0,wc(i,!1),t.lanes=4194304)}i.isBackwards?(a.sibling=t.child,t.child=a):(e=i.last,e===null?t.child=a:e.sibling=a,i.last=a)}return i.tail===null?(Tc(t),null):(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=he(),t.sibling=null,e=js.current,R(js,r?e&1|2:e&1),t);case 22:case 23:return As(t),za(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Tc(t),t.subtreeFlags&6&&(t.flags|=8192)):Tc(t),n=t.updateQueue,n!==null&&Cc(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),Tc(t),null;case 25:return null;case 30:return null}throw Error(s(156,t.tag))}function Dc(e,t){switch(wi(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Bi(Qi),le(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return B(t),null;case 13:if(As(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(s(340));Ni()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return L(js),null;case 4:return le(),null;case 10:return Bi(t.type),null;case 22:case 23:return As(t),za(),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 Oc(e,t){switch(wi(t),t.tag){case 3:Bi(Qi),le();break;case 26:case 27:case 5:B(t);break;case 4:le();break;case 13:As(t);break;case 19:L(js);break;case 10:Bi(t.type);break;case 22:case 23:As(t),za(),e!==null&&L(la);break;case 24:Bi(Qi)}}function kc(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){Nu(t,t.return,e)}}function Ac(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){Nu(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Nu(t,t.return,e)}}function jc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Pa(t,n)}catch(t){Nu(e,e.return,t)}}}function Mc(e,t,n){n.props=Ls(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Nu(e,t,n)}}function Nc(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){Nu(e,t,n)}}function Pc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null){if(typeof r==`function`)try{r()}catch(n){Nu(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){Nu(e,t,n)}else n.current=null}}function Fc(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){Nu(e,e.return,t)}}function Ic(e,t,n){try{var r=e.stateNode;Ed(r,e.type,n,t),r[Xe]=t}catch(t){Nu(e,e.return,t)}}function Lc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Bd(e.type)||e.tag===4}function Rc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Lc(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&&Bd(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 zc(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=Sd));else if(r!==4&&(r===27&&Bd(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(zc(e,t,n),e=e.sibling;e!==null;)zc(e,t,n),e=e.sibling}function Bc(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&&Bd(e.type)&&(n=e.stateNode),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){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Td(t,r,n),t[Ye]=e,t[Xe]=n}catch(t){Nu(e,e.return,t)}}var Hc=!1,Uc=!1,Wc=!1,Gc=typeof WeakSet==`function`?WeakSet:Set,Kc=null;function qc(e,t){if(e=e.containerInfo,Dd=Kf,e=Sr(e),Cr(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{n.nodeType,a.nodeType}catch{n=null;break a}var o=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||i!==0&&f.nodeType!==3||(c=o+i),f!==a||r!==0&&f.nodeType!==3||(l=o+r),f.nodeType===3&&(o+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===i&&(c=o),p===a&&++d===r&&(l=o),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(Od={focusedElem:e,selectionRange:n},Kf=!1,Kc=t;Kc!==null;)if(t=Kc,e=t.child,t.subtreeFlags&1024&&e!==null)e.return=t,Kc=e;else for(;Kc!==null;){switch(t=Kc,a=t.alternate,e=t.flags,t.tag){case 0:break;case 11:case 15:break;case 1:if(e&1024&&a!==null){e=void 0,n=t,i=a.memoizedProps,a=a.memoizedState,r=n.stateNode;try{var h=Ls(n.type,i,n.elementType===n.type);e=r.getSnapshotBeforeUpdate(h,a),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){Nu(n,n.return,e)}}break;case 3:if(e&1024){if(e=t.stateNode.containerInfo,n=e.nodeType,n===9)Hd(e);else if(n===1)switch(e.nodeName){case`HEAD`:case`HTML`:case`BODY`:Hd(e);break;default:e.textContent=``}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;default:if(e&1024)throw Error(s(163))}if(e=t.sibling,e!==null){e.return=t.return,Kc=e;break}Kc=t.return}}function Jc(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:cl(e,n),r&4&&kc(5,n);break;case 1:if(cl(e,n),r&4){if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){Nu(n,n.return,e)}else{var i=Ls(n.type,t.memoizedProps);t=t.memoizedState;try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){Nu(n,n.return,e)}}}r&64&&jc(n),r&512&&Nc(n,n.return);break;case 3:if(cl(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{Pa(e,t)}catch(e){Nu(n,n.return,e)}}break;case 27:t===null&&r&4&&Vc(n);case 26:case 5:cl(e,n),t===null&&r&4&&Fc(n),r&512&&Nc(n,n.return);break;case 12:cl(e,n);break;case 13:cl(e,n),r&4&&el(e,n),r&64&&(e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(n=Lu.bind(null,n),Kd(e,n))));break;case 22:if(r=n.memoizedState!==null||Hc,!r){t=t!==null&&t.memoizedState!==null||Uc,i=Hc;var a=Uc;Hc=r,(Uc=t)&&!a?ul(e,n,!!(n.subtreeFlags&8772)):cl(e,n),Hc=i,Uc=a}break;case 30:break;default:cl(e,n)}}function Yc(e){var t=e.alternate;t!==null&&(e.alternate=null,Yc(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 Xc=null,Zc=!1;function Qc(e,t,n){for(n=n.child;n!==null;)$c(e,t,n),n=n.sibling}function $c(e,t,n){if(Te&&typeof Te.onCommitFiberUnmount==`function`)try{Te.onCommitFiberUnmount(we,n)}catch{}switch(n.tag){case 26:Uc||Pc(n,t),Qc(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:Uc||Pc(n,t);var r=Xc,i=Zc;Bd(n.type)&&(Xc=n.stateNode,Zc=!1),Qc(e,t,n),Zd(n.stateNode),Xc=r,Zc=i;break;case 5:Uc||Pc(n,t);case 6:if(r=Xc,i=Zc,Xc=null,Qc(e,t,n),Xc=r,Zc=i,Xc!==null){if(Zc)try{(Xc.nodeType===9?Xc.body:Xc.nodeName===`HTML`?Xc.ownerDocument.body:Xc).removeChild(n.stateNode)}catch(e){Nu(n,t,e)}else try{Xc.removeChild(n.stateNode)}catch(e){Nu(n,t,e)}}break;case 18:Xc!==null&&(Zc?(e=Xc,Vd(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),vp(e)):Vd(Xc,n.stateNode));break;case 4:r=Xc,i=Zc,Xc=n.stateNode.containerInfo,Zc=!0,Qc(e,t,n),Xc=r,Zc=i;break;case 0:case 11:case 14:case 15:Uc||Ac(2,n,t),Uc||Ac(4,n,t),Qc(e,t,n);break;case 1:Uc||(Pc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Mc(n,t,r)),Qc(e,t,n);break;case 21:Qc(e,t,n);break;case 22:Uc=(r=Uc)||n.memoizedState!==null,Qc(e,t,n),Uc=r;break;default:Qc(e,t,n)}}function el(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{vp(e)}catch(e){Nu(t,t.return,e)}}function tl(e){switch(e.tag){case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new Gc),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new Gc),t;default:throw Error(s(435,e.tag))}}function nl(e,t){var n=tl(e);t.forEach(function(t){var r=Ru.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}function rl(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var i=n[r],a=e,o=t,c=o;a:for(;c!==null;){switch(c.tag){case 27:if(Bd(c.type)){Xc=c.stateNode,Zc=!1;break a}break;case 5:Xc=c.stateNode,Zc=!1;break a;case 3:case 4:Xc=c.stateNode.containerInfo,Zc=!0;break a}c=c.return}if(Xc===null)throw Error(s(160));$c(a,o,i),Xc=null,Zc=!1,a=i.alternate,a!==null&&(a.return=null),i.return=null}if(t.subtreeFlags&13878)for(t=t.child;t!==null;)al(t,e),t=t.sibling}var il=null;function al(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:rl(t,e),ol(e),r&4&&(Ac(3,e,e.return),kc(3,e),Ac(5,e,e.return));break;case 1:rl(t,e),ol(e),r&512&&(Uc||n===null||Pc(n,n.return)),r&64&&Hc&&(e=e.updateQueue,e!==null&&(r=e.callbacks,r!==null&&(n=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=n===null?r:n.concat(r))));break;case 26:var i=il;if(rl(t,e),ol(e),r&512&&(Uc||n===null||Pc(n,n.return)),r&4){var a=n===null?null:n.memoizedState;if(r=e.memoizedState,n===null){if(r===null){if(e.stateNode===null){a:{r=e.type,n=e.memoizedProps,i=i.ownerDocument||i;b:switch(r){case`title`:a=i.getElementsByTagName(`title`)[0],(!a||a[nt]||a[Ye]||a.namespaceURI===`http://www.w3.org/2000/svg`||a.hasAttribute(`itemprop`))&&(a=i.createElement(r),i.head.insertBefore(a,i.querySelector(`head > title`))),Td(a,r,n),a[Ye]=e,ct(a),r=a;break a;case`link`:var o=Ef(`link`,`href`,i).get(r+(n.href||``));if(o){for(var c=0;c<o.length;c++)if(a=o[c],a.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&a.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&a.getAttribute(`title`)===(n.title==null?null:n.title)&&a.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){o.splice(c,1);break b}}a=i.createElement(r),Td(a,r,n),i.head.appendChild(a);break;case`meta`:if(o=Ef(`meta`,`content`,i).get(r+(n.content||``))){for(c=0;c<o.length;c++)if(a=o[c],a.getAttribute(`content`)===(n.content==null?null:``+n.content)&&a.getAttribute(`name`)===(n.name==null?null:n.name)&&a.getAttribute(`property`)===(n.property==null?null:n.property)&&a.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&a.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){o.splice(c,1);break b}}a=i.createElement(r),Td(a,r,n),i.head.appendChild(a);break;default:throw Error(s(468,r))}a[Ye]=e,ct(a),r=a}e.stateNode=r}else Df(i,e.type,e.stateNode)}else e.stateNode=xf(i,r,e.memoizedProps)}else a===r?r===null&&e.stateNode!==null&&Ic(e,e.memoizedProps,n.memoizedProps):(a===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):a.count--,r===null?Df(i,e.type,e.stateNode):xf(i,r,e.memoizedProps))}break;case 27:rl(t,e),ol(e),r&512&&(Uc||n===null||Pc(n,n.return)),n!==null&&r&4&&Ic(e,e.memoizedProps,n.memoizedProps);break;case 5:if(rl(t,e),ol(e),r&512&&(Uc||n===null||Pc(n,n.return)),e.flags&32){i=e.stateNode;try{Vt(i,``)}catch(t){Nu(e,e.return,t)}}r&4&&e.stateNode!=null&&(i=e.memoizedProps,Ic(e,i,n===null?i:n.memoizedProps)),r&1024&&(Wc=!0);break;case 6:if(rl(t,e),ol(e),r&4){if(e.stateNode===null)throw Error(s(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){Nu(e,e.return,t)}}break;case 3:if(Tf=null,i=il,il=ef(t.containerInfo),rl(t,e),il=i,ol(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{vp(t.containerInfo)}catch(t){Nu(e,e.return,t)}Wc&&(Wc=!1,sl(e));break;case 4:r=il,il=ef(e.stateNode.containerInfo),rl(t,e),ol(e),il=r;break;case 12:rl(t,e),ol(e);break;case 13:rl(t,e),ol(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(Ul=he()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,nl(e,r)));break;case 22:i=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=Hc,d=Uc;if(Hc=u||i,Uc=d||l,rl(t,e),Uc=d,Hc=u,ol(e),r&8192)a:for(t=e.stateNode,t._visibility=i?t._visibility&-2:t._visibility|1,i&&(n===null||l||Hc||Uc||ll(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(a=l.stateNode,i)o=a.style,typeof o.setProperty==`function`?o.setProperty(`display`,`none`,`important`):o.display=`none`;else{c=l.stateNode;var f=l.memoizedProps.style,p=f!=null&&f.hasOwnProperty(`display`)?f.display:null;c.style.display=p==null||typeof p==`boolean`?``:(``+p).trim()}}catch(e){Nu(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=i?``:l.memoizedProps}catch(e){Nu(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,nl(e,n))));break;case 19:rl(t,e),ol(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,nl(e,r)));break;case 30:break;case 21:break;default:rl(t,e),ol(e)}}function ol(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if(Lc(r)){n=r;break}r=r.return}if(n==null)throw Error(s(160));switch(n.tag){case 27:var i=n.stateNode;Bc(e,Rc(e),i);break;case 5:var a=n.stateNode;n.flags&32&&(Vt(a,``),n.flags&=-33),Bc(e,Rc(e),a);break;case 3:case 4:var o=n.stateNode.containerInfo;zc(e,Rc(e),o);break;default:throw Error(s(161))}}catch(t){Nu(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function sl(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;sl(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function cl(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)Jc(e,t.alternate,t),t=t.sibling}function ll(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:Ac(4,t,t.return),ll(t);break;case 1:Pc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Mc(t,t.return,n),ll(t);break;case 27:Zd(t.stateNode);case 26:case 5:Pc(t,t.return),ll(t);break;case 22:t.memoizedState===null&&ll(t);break;case 30:ll(t);break;default:ll(t)}e=e.sibling}}function ul(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:ul(i,a,n),kc(4,a);break;case 1:if(ul(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){Nu(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++)Na(c[i],s)}catch(e){Nu(r,r.return,e)}}n&&o&64&&jc(a),Nc(a,a.return);break;case 27:Vc(a);case 26:case 5:ul(i,a,n),n&&r===null&&o&4&&Fc(a),Nc(a,a.return);break;case 12:ul(i,a,n);break;case 13:ul(i,a,n),n&&o&4&&el(i,a);break;case 22:a.memoizedState===null&&ul(i,a,n),Nc(a,a.return);break;case 30:break;default:ul(i,a,n)}t=t.sibling}}function dl(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 fl(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 pl(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)ml(e,t,n,r),t=t.sibling}function ml(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:pl(e,t,n,r),i&2048&&kc(9,t);break;case 1:pl(e,t,n,r);break;case 3:pl(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){pl(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){Nu(t,t.return,e)}}else pl(e,t,n,r);break;case 13:pl(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?pl(e,t,n,r):(a._visibility|=2,hl(e,t,n,r,!!(t.subtreeFlags&10256))):a._visibility&2?pl(e,t,n,r):gl(e,t),i&2048&&dl(o,t);break;case 24:pl(e,t,n,r),i&2048&&fl(t.alternate,t);break;default:pl(e,t,n,r)}}function hl(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:hl(a,o,s,c,i),kc(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,hl(a,o,s,c,i)):u._visibility&2?hl(a,o,s,c,i):gl(a,o),i&&l&2048&&dl(o.alternate,o);break;case 24:hl(a,o,s,c,i),i&&l&2048&&fl(o.alternate,o);break;default:hl(a,o,s,c,i)}t=t.sibling}}function gl(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:gl(n,r),i&2048&&dl(r.alternate,r);break;case 24:gl(n,r),i&2048&&fl(r.alternate,r);break;default:gl(n,r)}t=t.sibling}}var _l=8192;function vl(e){if(e.subtreeFlags&_l)for(e=e.child;e!==null;)yl(e),e=e.sibling}function yl(e){switch(e.tag){case 26:vl(e),e.flags&_l&&e.memoizedState!==null&&Mf(il,e.memoizedState,e.memoizedProps);break;case 5:vl(e);break;case 3:case 4:var t=il;il=ef(e.stateNode.containerInfo),vl(e),il=t;break;case 22:e.memoizedState===null&&(t=e.alternate,t!==null&&t.memoizedState!==null?(t=_l,_l=16777216,vl(e),_l=t):vl(e));break;default:vl(e)}}function bl(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 xl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];Kc=r,wl(r,e)}bl(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)Sl(e),e=e.sibling}function Sl(e){switch(e.tag){case 0:case 11:case 15:xl(e),e.flags&2048&&Ac(9,e,e.return);break;case 3:xl(e);break;case 12:xl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,Cl(e)):xl(e);break;default:xl(e)}}function Cl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];Kc=r,wl(r,e)}bl(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:Ac(8,t,t.return),Cl(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,Cl(t));break;default:Cl(t)}e=e.sibling}}function wl(e,t){for(;Kc!==null;){var n=Kc;switch(n.tag){case 0:case 11:case 15:Ac(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,Kc=r;else a:for(n=e;Kc!==null;){r=Kc;var i=r.sibling,a=r.return;if(Yc(r),r===n){Kc=null;break a}if(i!==null){i.return=a,Kc=i;break a}Kc=a}}}var Tl={getCacheForType:function(e){var t=Ki(Qi),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n}},El=typeof WeakMap==`function`?WeakMap:Map,q=0,Dl=null,J=null,Y=0,Ol=0,kl=null,Al=!1,jl=!1,Ml=!1,Nl=0,Pl=0,Fl=0,Il=0,Ll=0,Rl=0,zl=0,Bl=null,Vl=null,Hl=!1,Ul=0,Wl=1/0,Gl=null,Kl=null,ql=0,Jl=null,Yl=null,Xl=0,Zl=0,Ql=null,$l=null,eu=0,tu=null;function nu(){if(q&2&&Y!==0)return Y&-Y;if(N.T!==null){var e=ra;return e===0?ed():e}return Ke()}function ru(){Rl===0&&(Rl=!(Y&536870912)||H?Le():536870912);var e=Ts.current;return e!==null&&(e.flags|=32),Rl}function iu(e,t,n){(e===Dl&&(Ol===2||Ol===9)||e.cancelPendingCommit!==null)&&(du(e,0),cu(e,Y,Rl,!1)),Be(e,n),q&2&&e===Dl||(e===Dl&&(!(q&2)&&(Il|=n),Pl===4&&cu(e,Y,Rl,!1)),Ku(e))}function au(e,t,n){if(q&6)throw Error(s(327));var r=!n&&!(t&124)&&(t&e.expiredLanes)===0||Fe(e,t),i=r?vu(e,t):gu(e,t,!0),a=r;do{if(i===0){jl&&!r&&cu(e,t,0,!1);break}if(n=e.current.alternate,a&&!su(n))i=gu(e,t,!1),a=!1;else{if(i===2){if(a=t,e.errorRecoveryDisabledLanes&a)var o=0;else o=e.pendingLanes&-536870913,o=o===0?o&536870912?536870912:0:o;if(o!==0){t=o;a:{var c=e;i=Bl;var l=c.current.memoizedState.isDehydrated;if(l&&(du(c,o).flags|=256),o=gu(c,o,!1),o!==2){if(Ml&&!l){c.errorRecoveryDisabledLanes|=a,Il|=a,i=4;break a}a=Vl,Vl=i,a!==null&&(Vl===null?Vl=a:Vl.push.apply(Vl,a))}i=o}if(a=!1,i!==2)continue}}if(i===1){du(e,0),cu(e,t,0,!0);break}a:{switch(r=e,a=i,a){case 0:case 1:throw Error(s(345));case 4:if((t&4194048)!==t)break;case 6:cu(r,t,Rl,!Al);break a;case 2:Vl=null;break;case 3:case 5:break;default:throw Error(s(329))}if((t&62914560)===t&&(i=Ul+300-he(),10<i)){if(cu(r,t,Rl,!Al),Pe(r,0,!0)!==0)break a;r.timeoutHandle=Fd(ou.bind(null,r,n,Vl,Gl,Hl,t,Rl,Il,zl,Al,a,2,-0,0),i);break a}ou(r,n,Vl,Gl,Hl,t,Rl,Il,zl,Al,a,0,-0,0)}break}}while(1);Ku(e)}function ou(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)&&(Af={stylesheets:null,count:0,unsuspend:jf},yl(t),d=Nf(),d!==null)?(e.cancelPendingCommit=d(Tu.bind(null,e,t,a,n,r,i,o,s,c,u,1,f,p)),cu(e,a,o,!l)):Tu(e,t,a,n,r,i,o,s,c)}function su(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(!_r(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 cu(e,t,n,r){t&=~Ll,t&=~Il,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 lu(){return q&6?!0:(qu(0,!1),!1)}function uu(){if(J!==null){if(Ol===0)var e=J.return;else e=J,Ri=Li=null,no(e),gs=null,_s=0,e=J;for(;e!==null;)Oc(e.alternate,e),e=e.return;J=null}}function du(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,Id(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),uu(),Dl=e,J=n=oi(e.current,null),Y=t,Ol=0,kl=null,Al=!1,jl=Fe(e,t),Ml=!1,zl=Rl=Ll=Il=Fl=Pl=0,Vl=Bl=null,Hl=!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 Nl=t,Xr(),n}function fu(e,t){W=null,N.H=fs,t===pa||t===ha?(t=xa(),Ol=3):t===ma?(t=xa(),Ol=4):Ol=t===Js?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,kl=t,J===null&&(Pl=1,Hs(e,Kr(t,e.current)))}function pu(){var e=N.H;return N.H=fs,e===null?fs:e}function mu(){var e=N.A;return N.A=Tl,e}function hu(){Pl=4,Al||(Y&4194048)!==Y&&Ts.current!==null||(jl=!0),!(Fl&134217727)&&!(Il&134217727)||Dl===null||cu(Dl,Y,Rl,!1)}function gu(e,t,n){var r=q;q|=2;var i=pu(),a=mu();(Dl!==e||Y!==t)&&(Gl=null,du(e,t)),t=!1;var o=Pl;a:do try{if(Ol!==0&&J!==null){var s=J,c=kl;switch(Ol){case 8:uu(),o=6;break a;case 3:case 2:case 9:case 6:Ts.current===null&&(t=!0);var l=Ol;if(Ol=0,kl=null,Su(e,s,c,l),n&&jl){o=0;break a}break;default:l=Ol,Ol=0,kl=null,Su(e,s,c,l)}}_u(),o=Pl;break}catch(t){fu(e,t)}while(1);return t&&e.shellSuspendCounter++,Ri=Li=null,q=r,N.H=i,N.A=a,J===null&&(Dl=null,Y=0,Xr()),o}function _u(){for(;J!==null;)bu(J)}function vu(e,t){var n=q;q|=2;var r=pu(),i=mu();Dl!==e||Y!==t?(Gl=null,Wl=he()+500,du(e,t)):jl=Fe(e,t);a:do try{if(Ol!==0&&J!==null){t=J;var a=kl;b:switch(Ol){case 1:Ol=0,kl=null,Su(e,t,a,1);break;case 2:case 9:if(_a(a)){Ol=0,kl=null,xu(t);break}t=function(){Ol!==2&&Ol!==9||Dl!==e||(Ol=7),Ku(e)},a.then(t,t);break a;case 3:Ol=7;break a;case 4:Ol=5;break a;case 7:_a(a)?(Ol=0,kl=null,xu(t)):(Ol=0,kl=null,Su(e,t,a,7));break;case 5:var o=null;switch(J.tag){case 26:o=J.memoizedState;case 5:case 27:var c=J;if(!o||kf(o)){Ol=0,kl=null;var l=c.sibling;if(l!==null)J=l;else{var u=c.return;u===null?J=null:(J=u,Cu(u))}break b}}Ol=0,kl=null,Su(e,t,a,5);break;case 6:Ol=0,kl=null,Su(e,t,a,6);break;case 8:uu(),Pl=6;break a;default:throw Error(s(462))}}yu();break}catch(t){fu(e,t)}while(1);return Ri=Li=null,N.H=r,N.A=i,q=n,J===null?(Dl=null,Y=0,Xr(),Pl):0}function yu(){for(;J!==null&&!me();)bu(J)}function bu(e){var t=bc(e.alternate,e,Nl);e.memoizedProps=e.pendingProps,t===null?Cu(e):J=t}function xu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=ic(n,t,t.pendingProps,t.type,void 0,Y);break;case 11:t=ic(n,t,t.pendingProps,t.type.render,t.ref,Y);break;case 5:no(t);default:Oc(n,t),t=J=si(t,Nl),t=bc(n,t,Nl)}e.memoizedProps=e.pendingProps,t===null?Cu(e):J=t}function Su(e,t,n,r){Ri=Li=null,no(t),gs=null,_s=0;var i=t.return;try{if(qs(e,i,t,n,Y)){Pl=1,Hs(e,Kr(n,e.current)),J=null;return}}catch(t){if(i!==null)throw J=i,t;Pl=1,Hs(e,Kr(n,e.current)),J=null;return}t.flags&32768?(H||r===1?e=!0:jl||Y&536870912?e=!1:(Al=e=!0,(r===2||r===9||r===3||r===6)&&(r=Ts.current,r!==null&&r.tag===13&&(r.flags|=16384))),wu(t,e)):Cu(t)}function Cu(e){var t=e;do{if(t.flags&32768){wu(t,Al);return}e=t.return;var n=Ec(t.alternate,t,Nl);if(n!==null){J=n;return}if(t=t.sibling,t!==null){J=t;return}J=t=e}while(t!==null);Pl===0&&(Pl=5)}function wu(e,t){do{var n=Dc(e.alternate,e);if(n!==null){n.flags&=32767,J=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){J=e;return}J=e=n}while(e!==null);Pl=6,J=null}function Tu(e,t,n,r,i,a,o,c,l){e.cancelPendingCommit=null;do Au();while(ql!==0);if(q&6)throw Error(s(327));if(t!==null){if(t===e.current)throw Error(s(177));if(a=t.lanes|t.childLanes,a|=Yr,Ve(e,n,a,o,c,l),e===Dl&&(J=Dl=null,Y=0),Yl=t,Jl=e,Xl=n,Zl=a,Ql=i,$l=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,zu(ye,function(){return ju(!0),null})):(e.callbackNode=null,e.callbackPriority=0),r=!!(t.flags&13878),t.subtreeFlags&13878||r){r=N.T,N.T=null,i=P.p,P.p=2,o=q,q|=4;try{qc(e,t,n)}finally{q=o,P.p=i,N.T=r}}ql=1,Eu(),Du(),Ou()}}function Eu(){if(ql===1){ql=0;var e=Jl,t=Yl,n=!!(t.flags&13878);if(t.subtreeFlags&13878||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=q;q|=4;try{al(t,e);var a=Od,o=Sr(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&xr(s.ownerDocument.documentElement,s)){if(c!==null&&Cr(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 _=br(s,h),v=br(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}}Kf=!!Dd,Od=Dd=null}finally{q=i,P.p=r,N.T=n}}e.current=t,ql=2}}function Du(){if(ql===2){ql=0;var e=Jl,t=Yl,n=!!(t.flags&8772);if(t.subtreeFlags&8772||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=q;q|=4;try{Jc(e,t.alternate,t)}finally{q=i,P.p=r,N.T=n}}ql=3}}function Ou(){if(ql===4||ql===3){ql=0,V();var e=Jl,t=Yl,n=Xl,r=$l;t.subtreeFlags&10256||t.flags&10256?ql=5:(ql=0,Yl=Jl=null,ku(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(Kl=null),Ge(n),t=t.stateNode,Te&&typeof Te.onCommitFiberRoot==`function`)try{Te.onCommitFiberRoot(we,t,void 0,(t.current.flags&128)==128)}catch{}if(r!==null){t=N.T,i=P.p,P.p=2,N.T=null;try{for(var a=e.onRecoverableError,o=0;o<r.length;o++){var s=r[o];a(s.value,{componentStack:s.stack})}}finally{N.T=t,P.p=i}}Xl&3&&Au(),Ku(e),i=e.pendingLanes,n&4194090&&i&42?e===tu?eu++:(eu=0,tu=e):eu=0,qu(0,!1)}}function ku(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,ea(t)))}function Au(e){return Eu(),Du(),Ou(),ju(e)}function ju(){if(ql!==5)return!1;var e=Jl,t=Zl;Zl=0;var n=Ge(Xl),r=N.T,i=P.p;try{P.p=32>n?32:n,N.T=null,n=Ql,Ql=null;var a=Jl,o=Xl;if(ql=0,Yl=Jl=null,Xl=0,q&6)throw Error(s(331));var c=q;if(q|=4,Sl(a.current),ml(a,a.current,o,n),q=c,qu(0,!1),Te&&typeof Te.onPostCommitFiberRoot==`function`)try{Te.onPostCommitFiberRoot(we,a)}catch{}return!0}finally{P.p=i,N.T=r,ku(e,t)}}function Mu(e,t,n){t=Kr(n,t),t=Ws(e.stateNode,t,2),e=Da(e,t,2),e!==null&&(Be(e,2),Ku(e))}function Nu(e,t,n){if(e.tag===3)Mu(e,e,n);else for(;t!==null;){if(t.tag===3){Mu(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(Kl===null||!Kl.has(r))){e=Kr(n,e),n=Gs(2),r=Da(t,n,2),r!==null&&(Ks(n,r,t,e),Be(r,2),Ku(r));break}}t=t.return}}function Pu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new El;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)||(Ml=!0,i.add(n),e=Fu.bind(null,e,t,n),t.then(e,e))}function Fu(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,Dl===e&&(Y&n)===n&&(Pl===4||Pl===3&&(Y&62914560)===Y&&300>he()-Ul?!(q&2)&&du(e,0):Ll|=n,zl===Y&&(zl=0)),Ku(e)}function Iu(e,t){t===0&&(t=Re()),e=$r(e,t),e!==null&&(Be(e,t),Ku(e))}function Lu(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Iu(e,n)}function Ru(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(s(314))}r!==null&&r.delete(t),Iu(e,n)}function zu(e,t){return fe(e,t)}var Bu=null,Vu=null,Hu=!1,Uu=!1,Wu=!1,Gu=0;function Ku(e){e!==Vu&&e.next===null&&(Vu===null?Bu=Vu=e:Vu=Vu.next=e),Uu=!0,Hu||(Hu=!0,$u())}function qu(e,t){if(!Wu&&Uu){Wu=!0;do for(var n=!1,r=Bu;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,Qu(r,a))}else a=Y,a=Pe(r,r===Dl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Fe(r,a)||(n=!0,Qu(r,a))}r=r.next}while(n);Wu=!1}}function Ju(){Yu()}function Yu(){Uu=Hu=!1;var e=0;Gu!==0&&(Pd()&&(e=Gu),Gu=0);for(var t=he(),n=null,r=Bu;r!==null;){var i=r.next,a=Xu(r,t);a===0?(r.next=null,n===null?Bu=i:n.next=i,i===null&&(Vu=n)):(n=r,(e!==0||a&3)&&(Uu=!0)),r=i}qu(e,!1)}function Xu(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=Dl,n=Y,n=Pe(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Ol===2||Ol===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&pe(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&&pe(r),Ge(n)){case 2:case 8:n=ve;break;case 32:n=ye;break;case 268435456:n=xe;break;default:n=ye}return r=Zu.bind(null,e),n=fe(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&pe(r),e.callbackPriority=2,e.callbackNode=null,2}function Zu(e,t){if(ql!==0&&ql!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Au(!0)&&e.callbackNode!==n)return null;var r=Y;return r=Pe(e,e===Dl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(au(e,r,t),Xu(e,he()),e.callbackNode!=null&&e.callbackNode===n?Zu.bind(null,e):null)}function Qu(e,t){if(Au())return null;au(e,t,!0)}function $u(){Rd(function(){q&6?fe(_e,Ju):Yu()})}function ed(){return Gu===0&&(Gu=Le()),Gu}function td(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Jt(``+e)}function nd(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 rd(e,t,n,r,i){if(t===`submit`&&n&&n.stateNode===i){var a=td((i[Xe]||null).action),o=r.submitter;o&&(t=(t=o[Xe]||null)?td(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new gn(`action`,`action`,null,r,i);e.push({event:s,listeners:[{instance:null,listener:function(){if(r.defaultPrevented){if(Gu!==0){var e=o?nd(i,o):new FormData(i);Qo(n,{pending:!0,data:e,method:i.method,action:a},null,e)}}else typeof a==`function`&&(s.preventDefault(),e=o?nd(i,o):new FormData(i),Qo(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var id=0;id<Ur.length;id++){var ad=Ur[id];Wr(ad.toLowerCase(),`on`+(ad[0].toUpperCase()+ad.slice(1)))}Wr(Fr,`onAnimationEnd`),Wr(Ir,`onAnimationIteration`),Wr(Lr,`onAnimationStart`),Wr(`dblclick`,`onDoubleClick`),Wr(`focusin`,`onFocus`),Wr(`focusout`,`onBlur`),Wr(Rr,`onTransitionRun`),Wr(zr,`onTransitionStart`),Wr(Br,`onTransitionCancel`),Wr(Vr,`onTransitionEnd`),ft(`onMouseEnter`,[`mouseout`,`mouseover`]),ft(`onMouseLeave`,[`mouseout`,`mouseover`]),ft(`onPointerEnter`,[`pointerout`,`pointerover`]),ft(`onPointerLeave`,[`pointerout`,`pointerover`]),dt(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),dt(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),dt(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),dt(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),dt(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),dt(`onCompositionUpdate`,`compositionupdate focusout keydown keypress keyup mousedown`.split(` `));var od=`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(` `),sd=new Set(`beforetoggle cancel close invalid load scroll scrollend toggle`.split(` `).concat(od));function cd(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){Rs(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){Rs(e)}i.currentTarget=null,a=c}}}}function X(e,t){var n=t[Qe];n===void 0&&(n=t[Qe]=new Set);var r=e+`__bubble`;n.has(r)||(fd(t,e,2,!1),n.add(r))}function ld(e,t,n){var r=0;t&&(r|=4),fd(n,e,r,t)}var ud=`_reactListening`+Math.random().toString(36).slice(2);function dd(e){if(!e[ud]){e[ud]=!0,lt.forEach(function(t){t!==`selectionchange`&&(sd.has(t)||ld(t,!1,e),ld(t,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[ud]||(t[ud]=!0,ld(`selectionchange`,!1,t))}}function fd(e,t,n,r){switch($f(t)){case 2:var i=qf;break;case 8:i=Jf;break;default:i=Yf}n=i.bind(null,t,n,e),i=void 0,!an||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 pd(e,t,n,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)a:for(;;){if(r===null)return;var o=r.tag;if(o===3||o===4){var s=r.stateNode.containerInfo;if(s===i)break;if(o===4)for(o=r.return;o!==null;){var c=o.tag;if((c===3||c===4)&&o.stateNode.containerInfo===i)return;o=o.return}for(;s!==null;){if(o=it(s),o===null)return;if(c=o.tag,c===5||c===6||c===26||c===27){r=a=o;continue a}s=s.parentNode}}r=r.return}tn(function(){var r=a,i=Xt(n),o=[];a:{var s=Hr.get(e);if(s!==void 0){var c=gn,u=e;switch(e){case`keypress`:if(dn(n)===0)break a;case`keydown`:case`keyup`:c=Pn;break;case`focusin`:u=`focus`,c=Tn;break;case`focusout`:u=`blur`,c=Tn;break;case`beforeblur`:case`afterblur`:c=Tn;break;case`click`:if(n.button===2)break a;case`auxclick`:case`dblclick`:case`mousedown`:case`mousemove`:case`mouseup`:case`mouseout`:case`mouseover`:case`contextmenu`:c=Cn;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:c=wn;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:c=In;break;case Fr:case Ir:case Lr:c=En;break;case Vr:c=Ln;break;case`scroll`:case`scrollend`:c=vn;break;case`wheel`:c=Rn;break;case`copy`:case`cut`:case`paste`:c=Dn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:c=Fn;break;case`toggle`:case`beforetoggle`:c=zn}var d=!!(t&4),f=!d&&(e===`scroll`||e===`scrollend`),p=d?s===null?null:s+`Capture`:s;d=[];for(var m=r,h;m!==null;){var g=m;if(h=g.stateNode,g=g.tag,g!==5&&g!==26&&g!==27||h===null||p===null||(g=nn(m,p),g!=null&&d.push(md(m,g,h))),f)break;m=m.return}0<d.length&&(s=new c(s,u,null,n,i),o.push({event:s,listeners:d}))}}if(!(t&7)){a:{if(s=e===`mouseover`||e===`pointerover`,c=e===`mouseout`||e===`pointerout`,s&&n!==Yt&&(u=n.relatedTarget||n.fromElement)&&(it(u)||u[Ze]))break a;if((c||s)&&(s=i.window===i?i:(s=i.ownerDocument)?s.defaultView||s.parentWindow:window,c?(u=n.relatedTarget||n.toElement,c=r,u=u?it(u):null,u!==null&&(f=l(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(c=null,u=r),c!==u)){if(d=Cn,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=Fn,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=c==null?s:ot(c),h=u==null?s:ot(u),s=new d(g,m+`leave`,c,n,i),s.target=f,s.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,c&&u)b:{for(d=c,p=u,m=0,h=d;h;h=gd(h))m++;for(h=0,g=p;g;g=gd(g))h++;for(;0<m-h;)d=gd(d),m--;for(;0<h-m;)p=gd(p),h--;for(;m--;){if(d===p||p!==null&&d===p.alternate)break b;d=gd(d),p=gd(p)}d=null}else d=null;c!==null&&_d(o,s,c,d,!1),u!==null&&f!==null&&_d(o,f,u,d,!0)}}a:{if(s=r?ot(r):window,c=s.nodeName&&s.nodeName.toLowerCase(),c===`select`||c===`input`&&s.type===`file`)var _=ar;else if($n(s)){if(or)_=hr;else{_=pr;var v=fr}}else c=s.nodeName,!c||c.toLowerCase()!==`input`||s.type!==`checkbox`&&s.type!==`radio`?r&&Gt(r.elementType)&&(_=ar):_=mr;if(_&&=_(e,r)){er(o,_,n,i);break a}v&&v(e,s,r),e===`focusout`&&r&&s.type===`number`&&r.memoizedProps.value!=null&&Lt(s,`number`,s.value)}switch(v=r?ot(r):window,e){case`focusin`:($n(v)||v.contentEditable===`true`)&&(Tr=v,Er=r,Dr=null);break;case`focusout`:Dr=Er=Tr=null;break;case`mousedown`:Or=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Or=!1,kr(o,n,i);break;case`selectionchange`:if(wr)break;case`keydown`:case`keyup`:kr(o,n,i)}var y;if(Vn)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 Yn?qn(e,n)&&(b=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(b=`onCompositionStart`);b&&(Wn&&n.locale!==`ko`&&(Yn||b!==`onCompositionStart`?b===`onCompositionEnd`&&Yn&&(y=un()):(sn=i,cn=`value`in sn?sn.value:sn.textContent,Yn=!0)),v=hd(r,b),0<v.length&&(b=new On(b,e,null,n,i),o.push({event:b,listeners:v}),y?b.data=y:(y=Jn(n),y!==null&&(b.data=y)))),(y=Un?Xn(e,n):Zn(e,n))&&(b=hd(r,`onBeforeInput`),0<b.length&&(v=new On(`onBeforeInput`,`beforeinput`,null,n,i),o.push({event:v,listeners:b}),v.data=y)),rd(o,e,r,n,i)}cd(o,t)})}function md(e,t,n){return{instance:e,listener:t,currentTarget:n}}function hd(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=nn(e,n),i!=null&&r.unshift(md(e,i,a)),i=nn(e,t),i!=null&&r.push(md(e,i,a))),e.tag===3)return r;e=e.return}return[]}function gd(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function _d(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=nn(n,a),l!=null&&o.unshift(md(n,l,c))):i||(l=nn(n,a),l!=null&&o.push(md(n,l,c)))),n=n.return}o.length!==0&&e.push({event:t,listeners:o})}var vd=/\r\n?/g,yd=/\u0000|\uFFFD/g;function bd(e){return(typeof e==`string`?e:``+e).replace(vd,`
9
- `).replace(yd,``)}function xd(e,t){return t=bd(t),bd(e)===t}function Sd(){}function Cd(e,t,n,r,i,a){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||Vt(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&Vt(e,``+r);break;case`className`:vt(e,`class`,r);break;case`tabIndex`:vt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:vt(e,n,r);break;case`style`:Wt(e,r,a);break;case`data`:if(t!==`object`){vt(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=Jt(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}if(typeof a==`function`&&(n===`formAction`?(t!==`input`&&Cd(e,t,`name`,i.name,i,null),Cd(e,t,`formEncType`,i.formEncType,i,null),Cd(e,t,`formMethod`,i.formMethod,i,null),Cd(e,t,`formTarget`,i.formTarget,i,null)):(Cd(e,t,`encType`,i.encType,i,null),Cd(e,t,`method`,i.method,i,null),Cd(e,t,`target`,i.target,i,null))),r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Jt(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=Sd);break;case`onScroll`:r!=null&&X(`scroll`,e);break;case`onScrollEnd`:r!=null&&X(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(s(61));if(n=r.__html,n!=null){if(i.children!=null)throw Error(s(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=Jt(``+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`:X(`beforetoggle`,e),X(`toggle`,e),_t(e,`popover`,r);break;case`xlinkActuate`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:yt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:yt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:yt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:yt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:_t(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=Kt.get(n)||n,_t(e,n,r))}}function wd(e,t,n,r,i,a){switch(n){case`style`:Wt(e,r,a);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(s(61));if(n=r.__html,n!=null){if(i.children!=null)throw Error(s(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?Vt(e,r):(typeof r==`number`||typeof r==`bigint`)&&Vt(e,``+r);break;case`onScroll`:r!=null&&X(`scroll`,e);break;case`onScrollEnd`:r!=null&&X(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=Sd);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!ut.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(i=n.endsWith(`Capture`),t=n.slice(2,i?n.length-7:void 0),a=e[Xe]||null,a=a==null?null:a[n],typeof a==`function`&&e.removeEventListener(t,a,i),typeof r==`function`)){typeof a!=`function`&&a!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,i);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):_t(e,n,r)}}}function Td(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:X(`error`,e),X(`load`,e);var r=!1,i=!1,a;for(a in n)if(n.hasOwnProperty(a)){var o=n[a];if(o!=null)switch(a){case`src`:r=!0;break;case`srcSet`:i=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(s(137,t));default:Cd(e,t,a,o,n,null)}}i&&Cd(e,t,`srcSet`,n.srcSet,n,null),r&&Cd(e,t,`src`,n.src,n,null);return;case`input`:X(`invalid`,e);var c=a=o=i=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:i=d;break;case`type`:o=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:a=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(s(137,t));break;default:Cd(e,t,r,d,n,null)}}It(e,a,c,l,u,o,i,!1),At(e);return;case`select`:for(i in X(`invalid`,e),r=o=a=null,n)if(n.hasOwnProperty(i)&&(c=n[i],c!=null))switch(i){case`value`:a=c;break;case`defaultValue`:o=c;break;case`multiple`:r=c;default:Cd(e,t,i,c,n,null)}t=a,n=o,e.multiple=!!r,t==null?n!=null&&Rt(e,!!r,n,!0):Rt(e,!!r,t,!1);return;case`textarea`:for(o in X(`invalid`,e),a=i=r=null,n)if(n.hasOwnProperty(o)&&(c=n[o],c!=null))switch(o){case`value`:r=c;break;case`defaultValue`:i=c;break;case`children`:a=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(s(91));break;default:Cd(e,t,o,c,n,null)}Bt(e,r,i,a),At(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:Cd(e,t,l,r,n,null)}return;case`dialog`:X(`beforetoggle`,e),X(`toggle`,e),X(`cancel`,e),X(`close`,e);break;case`iframe`:case`object`:X(`load`,e);break;case`video`:case`audio`:for(r=0;r<od.length;r++)X(od[r],e);break;case`image`:X(`error`,e),X(`load`,e);break;case`details`:X(`toggle`,e);break;case`embed`:case`source`:case`link`:X(`error`,e),X(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(s(137,t));default:Cd(e,t,u,r,n,null)}return;default:if(Gt(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&wd(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Cd(e,t,c,r,n,null))}function Ed(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var i=null,a=null,o=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Cd(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:a=m;break;case`name`:i=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:o=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(s(137,t));break;default:m!==f&&Cd(e,t,p,m,r,f)}}Ft(e,o,c,l,u,d,a,i);return;case`select`:for(a in m=o=c=p=null,n)if(l=n[a],n.hasOwnProperty(a)&&l!=null)switch(a){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(a)||Cd(e,t,a,null,r,l)}for(i in r)if(a=r[i],l=n[i],r.hasOwnProperty(i)&&(a!=null||l!=null))switch(i){case`value`:p=a;break;case`defaultValue`:c=a;break;case`multiple`:o=a;default:a!==l&&Cd(e,t,i,a,r,l)}t=c,n=o,r=m,p==null?!!r!=!!n&&(t==null?Rt(e,!!n,n?[]:``,!1):Rt(e,!!n,t,!0)):Rt(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(i=n[c],n.hasOwnProperty(c)&&i!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Cd(e,t,c,null,r,i)}for(o in r)if(i=r[o],a=n[o],r.hasOwnProperty(o)&&(i!=null||a!=null))switch(o){case`value`:p=i;break;case`defaultValue`:m=i;break;case`children`:break;case`dangerouslySetInnerHTML`:if(i!=null)throw Error(s(91));break;default:i!==a&&Cd(e,t,o,i,r,a)}zt(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:Cd(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:Cd(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)&&Cd(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(s(137,t));break;default:Cd(e,t,u,p,r,m)}return;default:if(Gt(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&wd(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||wd(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Cd(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||Cd(e,t,f,p,r,m)}var Dd=null,Od=null;function kd(e){return e.nodeType===9?e:e.ownerDocument}function Ad(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 jd(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 Md(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 Nd=null;function Pd(){var e=window.event;return e&&e.type===`popstate`?e!==Nd&&(Nd=e,!0):(Nd=null,!1)}var Fd=typeof setTimeout==`function`?setTimeout:void 0,Id=typeof clearTimeout==`function`?clearTimeout:void 0,Ld=typeof Promise==`function`?Promise:void 0,Rd=typeof queueMicrotask==`function`?queueMicrotask:Ld===void 0?Fd:function(e){return Ld.resolve(null).then(e).catch(zd)};function zd(e){setTimeout(function(){throw e})}function Bd(e){return e===`head`}function Vd(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&&Zd(o.documentElement),n&2&&Zd(o.body),n&4)for(n=o.head,Zd(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),vp(t);return}i--}else n===`$`||n===`$?`||n===`$!`?i++:r=n.charCodeAt(0)-48}else r=0;n=a}while(n);vp(t)}function Hd(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`:Hd(n),rt(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function Ud(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=qd(e.nextSibling),e===null)break}return null}function Wd(e,t,n){if(t===``)return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=qd(e.nextSibling),e===null))return null;return e}function Gd(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState===`complete`}function Kd(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 qd(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 Jd=null;function Yd(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 Xd(e,t,n){switch(t=kd(n),e){case`html`:if(e=t.documentElement,!e)throw Error(s(452));return e;case`head`:if(e=t.head,!e)throw Error(s(453));return e;case`body`:if(e=t.body,!e)throw Error(s(454));return e;default:throw Error(s(451))}}function Zd(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);rt(e)}var Qd=new Map,$d=new Set;function ef(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var tf=P.d;P.d={f:nf,r:rf,D:sf,C:cf,L:lf,m:uf,X:ff,S:df,M:pf};function nf(){var e=tf.f(),t=lu();return e||t}function rf(e){var t=at(e);t!==null&&t.tag===5&&t.type===`form`?es(t):tf.r(e)}var af=typeof document>`u`?null:document;function of(e,t,n){var r=af;if(r&&typeof t==`string`&&t){var i=Pt(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),$d.has(i)||($d.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Td(t,`link`,e),ct(t),r.head.appendChild(t)))}}function sf(e){tf.D(e),of(`dns-prefetch`,e,null)}function cf(e,t){tf.C(e,t),of(`preconnect`,e,t)}function lf(e,t,n){tf.L(e,t,n);var r=af;if(r&&e&&t){var i=`link[rel="preload"][as="`+Pt(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Pt(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Pt(n.imageSizes)+`"]`)):i+=`[href="`+Pt(e)+`"]`;var a=i;switch(t){case`style`:a=hf(e);break;case`script`:a=yf(e)}Qd.has(a)||(e=m({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),Qd.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(gf(a))||t===`script`&&r.querySelector(bf(a))||(t=r.createElement(`link`),Td(t,`link`,e),ct(t),r.head.appendChild(t)))}}function uf(e,t){tf.m(e,t);var n=af;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Pt(r)+`"][href="`+Pt(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=yf(e)}if(!Qd.has(a)&&(e=m({rel:`modulepreload`,href:e},t),Qd.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(bf(a)))return}r=n.createElement(`link`),Td(r,`link`,e),ct(r),n.head.appendChild(r)}}}function df(e,t,n){tf.S(e,t,n);var r=af;if(r&&e){var i=st(r).hoistableStyles,a=hf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(gf(a)))s.loading=5;else{e=m({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=Qd.get(a))&&Cf(e,n);var c=o=r.createElement(`link`);ct(c),Td(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,Sf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function ff(e,t){tf.X(e,t);var n=af;if(n&&e){var r=st(n).hoistableScripts,i=yf(e),a=r.get(i);a||(a=n.querySelector(bf(i)),a||(e=m({src:e,async:!0},t),(t=Qd.get(i))&&wf(e,t),a=n.createElement(`script`),ct(a),Td(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function pf(e,t){tf.M(e,t);var n=af;if(n&&e){var r=st(n).hoistableScripts,i=yf(e),a=r.get(i);a||(a=n.querySelector(bf(i)),a||(e=m({src:e,async:!0,type:`module`},t),(t=Qd.get(i))&&wf(e,t),a=n.createElement(`script`),ct(a),Td(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function mf(e,t,n,r){var i=(i=z.current)?ef(i):null;if(!i)throw Error(s(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=hf(n.href),n=st(i).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=hf(n.href);var a=st(i).hoistableStyles,o=a.get(e);if(o||(i=i.ownerDocument||i,o={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},a.set(e,o),(a=i.querySelector(gf(e)))&&!a._p&&(o.instance=a,o.state.loading=5),Qd.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},Qd.set(e,n),a||vf(i,e,n,o.state))),t&&r===null)throw Error(s(528,``));return o}if(t&&r!==null)throw Error(s(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=yf(n),n=st(i).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(s(444,e))}}function hf(e){return`href="`+Pt(e)+`"`}function gf(e){return`link[rel="stylesheet"][`+e+`]`}function _f(e){return m({},e,{"data-precedence":e.precedence,precedence:null})}function vf(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}),Td(t,`link`,n),ct(t),e.head.appendChild(t))}function yf(e){return`[src="`+Pt(e)+`"]`}function bf(e){return`script[async]`+e}function xf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Pt(n.href)+`"]`);if(r)return t.instance=r,ct(r),r;var i=m({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),ct(r),Td(r,`style`,i),Sf(r,n.precedence,e),t.instance=r;case`stylesheet`:i=hf(n.href);var a=e.querySelector(gf(i));if(a)return t.state.loading|=4,t.instance=a,ct(a),a;r=_f(n),(i=Qd.get(i))&&Cf(r,i),a=(e.ownerDocument||e).createElement(`link`),ct(a);var o=a;return o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Td(a,`link`,r),t.state.loading|=4,Sf(a,n.precedence,e),t.instance=a;case`script`:return a=yf(n.src),(i=e.querySelector(bf(a)))?(t.instance=i,ct(i),i):(r=n,(i=Qd.get(a))&&(r=m({},n),wf(r,i)),e=e.ownerDocument||e,i=e.createElement(`script`),ct(i),Td(i,`link`,r),e.head.appendChild(i),t.instance=i);case`void`:return null;default:throw Error(s(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,Sf(r,n.precedence,e));return t.instance}function Sf(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 Cf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function wf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var Tf=null;function Ef(e,t,n){if(Tf===null){var r=new Map,i=Tf=new Map;i.set(n,r)}else i=Tf,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 Df(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function Of(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 kf(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}var Af=null;function jf(){}function Mf(e,t,n){if(Af===null)throw Error(s(475));var r=Af;if(t.type===`stylesheet`&&(typeof n.media!=`string`||!1!==matchMedia(n.media).matches)&&!(t.state.loading&4)){if(t.instance===null){var i=hf(n.href),a=e.querySelector(gf(i));if(a){e=a._p,typeof e==`object`&&e&&typeof e.then==`function`&&(r.count++,r=Pf.bind(r),e.then(r,r)),t.state.loading|=4,t.instance=a,ct(a);return}a=e.ownerDocument||e,n=_f(n),(i=Qd.get(i))&&Cf(n,i),a=a.createElement(`link`),ct(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Td(a,`link`,n),t.instance=a}r.stylesheets===null&&(r.stylesheets=new Map),r.stylesheets.set(t,e),(e=t.state.preload)&&!(t.state.loading&3)&&(r.count++,t=Pf.bind(r),e.addEventListener(`load`,t),e.addEventListener(`error`,t))}}function Nf(){if(Af===null)throw Error(s(475));var e=Af;return e.stylesheets&&e.count===0&&If(e,e.stylesheets),0<e.count?function(t){var n=setTimeout(function(){if(e.stylesheets&&If(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 Pf(){if(this.count--,this.count===0){if(this.stylesheets)If(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var Ff=null;function If(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Ff=new Map,t.forEach(Lf,e),Ff=null,Pf.call(e))}function Lf(e,t){if(!(t.state.loading&4)){var n=Ff.get(e);if(n)var r=n.get(null);else{n=new Map,Ff.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=Pf.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 Rf={$$typeof:C,Provider:null,Consumer:null,_currentValue:F,_currentValue2:F,_threadCount:0};function zf(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 Bf(e,t,n,r,i,a,o,s,c,l,u,d){return e=new zf(e,t,n,o,s,c,l,d),t=1,!0===a&&(t|=24),a=ii(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},wa(a),e}function Vf(e){return e?(e=ni,e):ni}function Hf(e,t,n,r,i,a){i=Vf(i),r.context===null?r.context=i:r.pendingContext=i,r=Ea(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Da(e,r,t),n!==null&&(iu(n,e,t),Oa(n,e,t))}function Uf(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function Wf(e,t){Uf(e,t),(e=e.alternate)&&Uf(e,t)}function Gf(e){if(e.tag===13){var t=$r(e,67108864);t!==null&&iu(t,e,67108864),Wf(e,67108864)}}var Kf=!0;function qf(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=2,Yf(e,t,n,r)}finally{P.p=a,N.T=i}}function Jf(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=8,Yf(e,t,n,r)}finally{P.p=a,N.T=i}}function Yf(e,t,n,r){if(Kf){var i=Xf(r);if(i===null)pd(e,t,r,Zf,n),cp(e,r);else if(up(i,e,t,n,r))r.stopPropagation();else if(cp(e,r),t&4&&-1<sp.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}Ku(a),!(q&6)&&(Wl=he()+500,qu(0,!1))}}break;case 13:s=$r(a,2),s!==null&&iu(s,a,2),lu(),Wf(a,2)}if(a=Xf(r),a===null&&pd(e,t,r,Zf,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else pd(e,t,r,null,n)}}function Xf(e){return e=Xt(e),Qf(e)}var Zf=null;function Qf(e){if(Zf=null,e=it(e),e!==null){var t=l(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=u(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return Zf=e,null}function $f(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(ge()){case _e:return 2;case ve:return 8;case ye:case be:return 32;case xe:return 268435456;default:return 32}default:return 32}}var ep=!1,tp=null,np=null,rp=null,ip=new Map,ap=new Map,op=[],sp=`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 cp(e,t){switch(e){case`focusin`:case`focusout`:tp=null;break;case`dragenter`:case`dragleave`:np=null;break;case`mouseover`:case`mouseout`:rp=null;break;case`pointerover`:case`pointerout`:ip.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:ap.delete(t.pointerId)}}function lp(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&&Gf(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function up(e,t,n,r,i){switch(t){case`focusin`:return tp=lp(tp,e,t,n,r,i),!0;case`dragenter`:return np=lp(np,e,t,n,r,i),!0;case`mouseover`:return rp=lp(rp,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return ip.set(a,lp(ip.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,ap.set(a,lp(ap.get(a)||null,e,t,n,r,i)),!0}return!1}function dp(e){var t=it(e.target);if(t!==null){var n=l(t);if(n!==null){if(t=n.tag,t===13){if(t=u(n),t!==null){e.blockedOn=t,qe(e.priority,function(){if(n.tag===13){var e=nu();e=We(e);var t=$r(n,e);t!==null&&iu(t,n,e),Wf(n,e)}});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function fp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=Xf(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);Yt=r,n.target.dispatchEvent(r),Yt=null}else return t=at(n),t!==null&&Gf(t),e.blockedOn=n,!1;t.shift()}return!0}function pp(e,t,n){fp(e)&&n.delete(t)}function mp(){ep=!1,tp!==null&&fp(tp)&&(tp=null),np!==null&&fp(np)&&(np=null),rp!==null&&fp(rp)&&(rp=null),ip.forEach(pp),ap.forEach(pp)}function hp(e,n){e.blockedOn===n&&(e.blockedOn=null,ep||(ep=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,mp)))}var gp=null;function _p(e){gp!==e&&(gp=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){gp===e&&(gp=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(Qf(r||n)===null)continue;break}var a=at(n);a!==null&&(e.splice(t,3),t-=3,Qo(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function vp(e){function t(t){return hp(t,e)}tp!==null&&hp(tp,e),np!==null&&hp(np,e),rp!==null&&hp(rp,e),ip.forEach(t),ap.forEach(t);for(var n=0;n<op.length;n++){var r=op[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<op.length&&(n=op[0],n.blockedOn===null);)dp(n),n.blockedOn===null&&op.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||_p(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Xe]||null)s=o.formAction;else if(Qf(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),_p(n)}}}function yp(e){this._internalRoot=e}bp.prototype.render=yp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(s(409));var n=t.current;Hf(n,nu(),e,t,null,null)},bp.prototype.unmount=yp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Hf(e.current,2,null,e,null,null),lu(),t[Ze]=null}};function bp(e){this._internalRoot=e}bp.prototype.unstable_scheduleHydration=function(e){if(e){var t=Ke();e={blockedOn:null,target:e,priority:t};for(var n=0;n<op.length&&t!==0&&t<op[n].priority;n++);op.splice(n,0,e),n===0&&dp(e)}};var xp=r.version;if(xp!==`19.1.0`)throw Error(s(527,xp,`19.1.0`));P.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(s(188)):(e=Object.keys(e).join(`,`),Error(s(268,e)));return e=f(t),e=e===null?null:p(e),e=e===null?null:e.stateNode,e};var Sp={bundleType:0,version:`19.1.0`,rendererPackageName:`react-dom`,currentDispatcherRef:N,reconcilerVersion:`19.1.0`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Cp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Cp.isDisabled&&Cp.supportsFiber)try{we=Cp.inject(Sp),Te=Cp}catch{}}e.createRoot=function(e,t){if(!c(e))throw Error(s(299));var n=!1,r=``,i=zs,a=Bs,o=Vs,l=null;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(i=t.onUncaughtError),t.onCaughtError!==void 0&&(a=t.onCaughtError),t.onRecoverableError!==void 0&&(o=t.onRecoverableError),t.unstable_transitionCallbacks!==void 0&&(l=t.unstable_transitionCallbacks)),t=Bf(e,1,!1,null,null,n,r,i,a,o,l,null),e[Ze]=t.current,dd(e),new yp(t)}})),c=e(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=s()})),l=n(),u=c(),d="This tab's key is out of date. Open the address printed by `copperflow studio` again.";function f(e,t){return e===403&&/session token/i.test(t??``)?d:t??`Request failed (${e})`}function p(e){return e===d}var m=`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`;function h(e){return e instanceof TypeError?m:e instanceof Error?e.message:String(e)}var g=[`alignLeft`,`alignRight`,`alignTop`,`alignBottom`,`alignHCentres`,`alignVCentres`,`distributeH`,`distributeV`],_=new Set([`distributeH`,`distributeV`]),v=e=>g.includes(e),y=e=>_.has(e)?3:2;function b(e,t){return t>=y(e)?null:y(e)===2?`Select two or more parts`:`Select three or more parts`}var x=[`drawBus`,`drawPolyline`,`drawArc`,`drawCircle`,`drawRectangle`,`drawText`],S={bus:`drawBus`,polyline:`drawPolyline`,arc:`drawArc`,circle:`drawCircle`,rectangle:`drawRectangle`,text:`drawText`},C={drawBus:`bus`,drawPolyline:`polyline`,drawArc:`arc`,drawCircle:`circle`,drawRectangle:`rectangle`,drawText:`text`},w=e=>x.includes(e),T=`The AI lock is on. Open it to edit.`;function E(e){return{closed:e===`ai`,editedSinceOpen:!1}}function ee(e){return{closed:!e.closed,editedSinceOpen:!1}}function D(e,t){return e.closed?e:t===`human`?e.editedSinceOpen?e:{...e,editedSinceOpen:!0}:e.editedSinceOpen?e:{...e,closed:!0}}var O=[`undo`,`redo`,`delete`,`replicateLayout`,`makeSheet`,`placeComponent`,`wire`,`netLabel`,`groundFlag`,`powerFlag`,...x,`singleRouting`,`placeVia`,`placePour`,`placePourBoard`,`placeHole`,`autoplace`,`autoplaceSelection`,`autoplaceInstance`,`fitBoard`,`importBoardDxf`,`autoroute`,`autorouteSelection`,`autorouteNet`,`unroute`,`rotate`,`rotateRight`,`removeCorners`,`filletTracks`,`straightenTracks`,`designRules`,`tidySheet`,`addPage`,`renamePage`,`deletePage`,...g,`newCircuit`,`paste`,`noConnect`,`junction`,`annotate`,`placementTransfer`,`routingCorner`,`flip`,`footprintManager`];function k(e){return e?Object.fromEntries(O.map(e=>[e,T])):{}}var A=new Set([`wire`,`route`,`placeVia`,`armNetLabel`,...x,`rotate`,`openLibrary`,`undo`,`redo`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`delete`,`removeCorner`,`flipBend`,`alignLeft`,`distributeH`,`filletTracks`,`straightenTracks`,`routingCorner`,`flip`,`paste`,`junction`,`placementTransfer`]);function j(e){return A.has(e)}var te=new Set([`move`,`moveGroup`,`label`,`text`,`wireSegment`,`wireCorner`]);function M(e){return te.has(e)}var ne=new Set([`/api/edit`,`/api/layout`,`/api/undo`,`/api/redo`,`/api/rename-parts`,`/api/make-sheet`,`/api/route`,`/api/autoplace`,`/api/fit-board`,`/api/import-board`,`/api/unroute`,`/api/rules`,`/api/place`,`/api/new-circuit`]);function N(e,t){return t===void 0||typeof t==`object`&&t&&t.preview===!0?!1:ne.has(e.split(`?`)[0]??e)}function P(e){return e?{title:`AI is driving`,hint:`Unlock to edit`}:{title:`You are editing`,hint:`Lock for the agent`}}function F(e){return O.includes(e)}function re(e){let t=!1,n=!1,r=e;return{set(e){e&&!t&&(n=!1),t=e},closed:()=>t,listen(e){r=e},refuses(){return t?(n||(n=!0,r(T)),!0):!1}}}var ie=re(()=>void 0),I=`copperflow-token`,L=2e3;function R(){let e=/[#&]token=([^&]+)/.exec(window.location.hash);if(e?.[1]){let t=decodeURIComponent(e[1]);try{sessionStorage.setItem(I,t)}catch{}return window.history.replaceState(null,``,window.location.pathname+window.location.search),t}try{return sessionStorage.getItem(I)??``}catch{return``}}var ae=R(),oe=ae!==``;window.addEventListener(`hashchange`,()=>{/[#&]token=/.test(window.location.hash)&&window.location.reload()});async function z(e,t){if(ie.closed()&&N(e,t))throw Error(T);let n;try{n=await fetch(e,{method:t===void 0?`GET`:`POST`,headers:{"x-copperflow-token":ae,"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}})}catch(e){throw Error(h(e))}let r=await n.json();if(!r.ok)throw Error(f(n.status,r.error));return r.data}var se=[`change`,`build`,`library`,`route`,`place`];function ce(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&&se.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":ae},signal:n.signal});if(!e.ok||!e.body)throw Error(`Event stream failed (${e.status})`);t?.(!0);let i=e.body.pipeThrough(new TextDecoderStream).getReader(),a=``;for(;;){let{value:e,done:t}=await i.read();if(t)break;a+=e;for(let e=a.indexOf(`
10
-
11
- `);e>=0;e=a.indexOf(`
12
-
13
- `))r(a.slice(0,e)),a=a.slice(e+2)}}catch(e){if(n.signal.aborted)return;e instanceof TypeError&&t?.(!1)}await new Promise(e=>setTimeout(e,L))}})(),()=>n.abort()}var le=.5,ue=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 de(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 fe(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:Se(a)}}function pe(e,t){return{...e,cx:t.x,cy:t.y}}function me(e,t,n,r){let i=de(e,t,n),a=Se(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 he(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var ge=(e,t,n=!0)=>V(n?he(e,t):e),_e=(e,t,n=!0)=>({x:ge(e.x,t,n),y:ge(e.y,t,n)});function ve(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 ye(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 be(e){return ye(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function xe(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 Se(e){return Math.min(ue,Math.max(le,e))}var Ce={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`}},we={x:0,y:0};function Te(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)??we,autoPlaced:e.autoPlaced}]))}function Ee(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=Ce[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 De(e,t,n,r=90){let i=Ce[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 Oe(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Ce[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 ke(e,t,n,r,i){let a=Oe(e,t,n,r);return[V(a.x+i.x),V(a.y+i.y)]}var Ae=`Keep auto-placed positions`,je=`a repeated name cannot be addressed from the Studio`,Me=e=>Math.round(e*100)/100;function Ne(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var Pe=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Ce[n].rotation]!==void 0;function Fe(e,t,n=()=>null,r){let[i,a]=Ce[t].position,o=Ne(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of Te(e,t)){if(!f)continue;let e=l.includes(`~`)?je:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:Me(u.x-d.x),[a]:Me(u.y-d.y),...p!==0||Pe(r,l,t)?{[Ce[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Ie(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function Le(e){let t=e.edits.length;return Ie(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function Re(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 ze(e,t,n,r,i){Re(Fe(e,t,n,i),Ae,Le,r)}var Be=`Tidy sheet`,Ve=`Every part on the sheet has a position of its own`,He=`The schematic is not built yet`;function Ue(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 We(e){return e?Ue(e,`schematic`).size>0?null:Ve:He}var Ge=(e,t=()=>null,n)=>Fe(e,`schematic`,t,n);function Ke(e){let t=e.edits.length;return Ie(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 qe(e,t,n,r){let i=We(e);if(i!==null)return n.notify(i);Re(Ge(e,t,r),Be,Ke,n)}var Je=/\.sheet\.tsx$/,Ye=e=>e!==void 0&&Je.test(e),Xe=e=>(e.split(`/`).pop()??e).replace(Je,``),Ze=3;function Qe(e){return e.length<=1?e[0]??``:e.length>Ze?`${e.slice(0,Ze).join(`, `)} and ${e.length-Ze} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var $e=e=>e.length>1?[`${e.length} wires`]:[...e],et=e=>`by ${e}°`;function tt(e,t,n,r,i=90){let{rotation:a,where:o}=Ce[n],s=[],c=[];for(let a of t){let t=r(a)??De(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 ${Qe(l)}${o} ${et(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function nt(e,t,n,r,i,a){let[o,s]=Ce[n].position,{where:c}=Ce[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:ke(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 ${Qe(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 rt(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??we,group:we}}function it(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 at(e,t){let n=be(e);return n?{x:he((n.minX+n.maxX)/2,t),y:he((n.minY+n.maxY)/2,t)}:void 0}function ot(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 st(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return tt(e,t,n,a,s);let{rotation:c,position:l,where:u}=Ce[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)??De(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ot(h,i,s),[_,v]=ke(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 ${Qe(f)}${u} ${et(s)}`,parts:f,skipped:p,done:`rotated`}}function ct(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function lt(e,t,n,r,i,a=90){if(t.length===1)return tt(e,t,n,i,a);let o=at(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?st(e,t,n,rt(r.anchors,r.boxes),o,i,ct(r),a):{message:`None of the selected parts is in this view.`}}function ut(e,t,n,r,i,a){let o=ct(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=nt(e,t.filter(o),n,rt(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function dt(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 ${Qe(r)}`,parts:r,skipped:n,done:`removed`}}function ft(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${Qe(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function pt(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function mt(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:`${Qe(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function ht(e,t){return(await gt(e,t)).ok}async function gt(e,t){let n=pt(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 _t={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},vt=.6,yt=e=>Math.round(e*1e6)/1e6,bt=(e,t)=>({x:yt(e),y:yt(t)}),xt=(...e)=>({type:`polyline`,points:e.map(([e,t])=>bt(e,t))});function St(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:_t[r],role:r}}function Ct(e){let t=vt*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 wt(e){if(e.type===`text`)return Ct(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 Tt(e,t){let n=[...e.map(wt),...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:yt(Math.min(...n.map(e=>e.minX))),minY:yt(Math.min(...n.map(e=>e.minY))),maxX:yt(Math.max(...n.map(e=>e.maxX))),maxY:yt(Math.max(...n.map(e=>e.maxY)))}}var Et=(e,t,n)=>({end:bt(e,t),side:n});Et(-.5,0,`left`),Et(.5,0,`right`),Et(-.5,0,`left`),Et(.5,0,`right`),Et(-.5,0,`left`),Et(.3,-.5,`bottom`),Et(.3,.5,`top`);function Dt(){return[xt([0,0],[0,-.1]),xt([-.15,-.1],[.15,-.1]),xt([-.1,-.15],[.1,-.15]),xt([-.05,-.2],[.05,-.2])]}function Ot(e){return[xt([0,0],[0,.1]),xt([-.1,.1],[.1,.1]),St(e,bt(0,.2),`center`,`value`)]}var kt=.16,At=kt*1.5,jt=.66,Mt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Nt(e){let t=Mt[e.side],n=e.text.length*kt*jt+At,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[At,n]:[n,At];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 Pt=/[\w-]+/,Ft=new RegExp(String.raw`^net\.(${Pt.source})$`),It=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Lt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Rt(e){let t=e.trim(),n=Ft.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=Lt.exec(t)??It.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var zt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Bt(e){let t=zt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Vt(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Ht={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Ut=.04,Wt=[`solid`,`dashed`,`dotted`],Gt=[`left`,`center`,`right`];function Kt(e){return Object.hasOwn(Ht,e)?Ht[e]:void 0}var qt=new RegExp(String.raw`^${Pt.source}$`),Jt=new RegExp(String.raw`^(${Pt.source})\[(\d+):(\d+)\]$`);function Yt(e){if(qt.test(e))return[e];let t=Jt.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 Xt(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 Zt(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function Qt(e,t,n,r,i){let a=Zt(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return Xt(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function $t(e,t,n,r,i){let a=vt*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 en(e){switch(e.kind){case`path`:case`bus`:return Xt(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 Qt(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return $t(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Ut,minY:e.y-Ut,maxX:e.x+Ut,maxY:e.y+Ut}}}var tn=e=>yt(e)+0;function nn(e){let t=en(e);return{minX:tn(t.minX),minY:tn(t.minY),maxX:tn(t.maxX),maxY:tn(t.maxY)}}var rn=/^[A-Za-z_][\w-]*$/;function an(e,t,n,r){let i=Bt(n);if(i)return Vt(i,void 0);let a=n.replace(/^net\./,``);return r?Yt(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:rn.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function on(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 sn=e=>e?.circuit.instances??[];function cn(e,t){return sn(e).find(e=>e.path===t&&!e.path.includes(`/`))}function ln(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=sn(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 un(e,t){return[...sn(e).find(e=>e.path===t)?.parts??[]]}function dn(e,t){return sn(e).filter(e=>e.file===t).length}function fn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function pn(e,t){let n=t.flatMap(t=>{let n=cn(e,t);if(n)return[n.path];let r=ln(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>un(e,t))}function mn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function hn(e,t){return on(e,t?.circuit.instances)}function gn(e,t,n){let r=ln(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 ${Xe(r.file)} shares it`}var _n=e=>Math.round(e*1e4)/1e4||0,vn=(e,t)=>e.x===t.x&&e.y===t.y;function yn(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 bn(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...yn(e[n-1],e[n],t[n-1]===!0));return r}function xn(e){let t=e.map(e=>({x:_n(e.x),y:_n(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&vn(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 Sn(e,t=[]){return xn(bn(e,t))}var Cn=.2,wn=/^[\w-]+$/,Tn=/^[A-Za-z_][\w-]*$/,En=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Dn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function On(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 kn(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=On(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&wn.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function An(e,t){let n=t.trim(),r=En.exec(n)??Dn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var jn=e=>e.circuit.components.flatMap(e=>e.pins),Mn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Nn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function Pn(e,t,n){let r=Mn(e,t.id)?.names[0],i=kn(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Fn(e,t){let n=Mn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function In(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 Ln(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?zn(a,i):Rn(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=an(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:mn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Rn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function zn(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 Bn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Nn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Vn(e,t,n,r={}){let i=Bn(e,t,n),a=i&&jn(e).find(e=>e.id===i.pin);return i&&a?Pn(e,a,i.at):i&&In(e,i.pin,i.at)||(Jn(e,t,n)??Kn(e,t,n,r)??Xn(e,t,n,r))}function Hn(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=Qn(t,i,a),s=Nn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Un=e=>Math.round(e*1e4)/1e4||0;function Wn(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=Un(Math.round(e/a.step)*a.step);return o(s)?s:e}function Gn(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=Wn(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 Kn(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Hn(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&&Gn(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Un(a.x),y:Un(a.y)},label:i.name,members:i.members}}function qn(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function Jn(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=Yn(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 Yn(e,t){if(e.style!==`label`)return Math.max(Nn(e.at,t)-Cn,0);let{box:n}=Nt(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 Xn(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Hn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&Zn(e,i.net,Gn(i.near,t,n,r))}function Zn(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=jn(e).find(e=>e.id===a);return o?{selector:kn(e,o),at:n,label:kn(e,o),pin:o.id}:void 0}function Qn(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 $n(e,t){if(t.pin!==void 0)return Mn(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=jn(e).find(t=>kn(e,t)===n);return r&&Mn(e,r.id)}function er(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function tr(e,t,n){let[r,i]=[$n(e,t),$n(e,n)],[a,o]=[nr(t,r),nr(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var nr=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function rr(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Tn.test(t)&&!t.includes(`~`)}var ir=e=>e.selector.startsWith(`net.`);function ar(e,t,n,r=[]){let i=Sn([e.at,...n,t.at],r);return i.slice(+!ir(e),ir(t)?i.length:i.length-1)}function or(e,t,n,r,i=[]){if(t.members||n.members||!rr(t.selector)||!rr(n.selector))return[];let[a,o]=[$n(e,t),$n(e,n)];if(er(t,n)||a!==void 0&&a.id===o?.id)return[];let s=ar(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var sr=/^net\.([\w-]+)$/,cr=new Set;function lr(e,t,n){return`pin`in n?t!==void 0&&An(e,t)?.id===n.pin:n.net.includes(sr.exec(t?.trim()??``)?.[1]??``)}function ur(e,t,n,r){return t.model.traces.filter(t=>lr(e,t.from,n)&&lr(e,t.to,r)||lr(e,t.from,r)&&lr(e,t.to,n))}function dr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function fr(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 pr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[An(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function mr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function hr(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 gr=.1,_r=e=>Math.round(e*1e3)/1e3||0;function vr(e){if(e.style===`label`)return Nt(e).box;let t=Tt(e.style===`ground`?Dt():Ot(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 yr(e){let t=vr(e);return e.style===`label`?t:{minX:t.minX-gr,minY:t.minY-gr,maxX:t.maxX+gr,maxY:t.maxY+gr}}var br=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,xr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Sr(e,t){return e.schematic.labels.map(e=>({label:e,box:yr(e)})).filter(({box:e})=>br(e,t)).sort((e,t)=>xr(e.box)-xr(t.box))[0]?.label}function Cr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function wr(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&&Cr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Tr(e,t){let n=wr(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Er(e,t){let n=wr(e,t);return n&&`${n.label.net}|${n.pin.id}`}function Dr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Or(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function kr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Or(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...xe([r,t]).slice(1)]}var Ar=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),jr=e=>({x:_r(e.x),y:_r(e.y)});function Mr(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Nr(e,t,n){let r=wr(e,t);if(!r)return;let i=jr(n),a=[r.end,...kr(r,i)];return{at:i,side:Mr(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Pr(e,t,n){return dr(ur(e,t,{pin:n.pin.id},{net:mr(e,n.label.net)}),n.connection?.id)}function Fr(e,t,n,r){let i=wr(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Pr(e,t,i),o=pr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?hr(t,a)??fr(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&&!rr(kn(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 Ir(e,t,n,r=cr){let i=Fr(e,t,n,r);return`blocked`in i?i.blocked:null}function Lr(e,t){let n=mr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Rr(e,t,n,r,i=cr){let a=Fr(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=kr(o,jr(r)).map(jr);if(Ar(c,o.connection?Or(o):[]))return[];if(!s)return[{kind:`addTrace`,from:kn(e,o.pin),to:Lr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&An(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var zr=new Intl.Collator(`en`,{numeric:!0});function Br(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 Vr(e,t){return zr.compare(e,t)||Br(e,t)}function Hr(e){return[...e].sort(Vr)}function Ur(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Hr(r)};return i?{...a,source:i}:a}var Wr=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,Gr={mm:1,in:25.4,mil:.0254};function Kr(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Wr.exec(e.trim());if(!t)return;let n=Number(t[1])*(Gr[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}function qr(e){return e!==void 0&&e.outline.length>=3}var Jr=Math.PI/180,Yr=1e-12;function Xr(e,t){let n=Math.cos(t.rotation*Jr),r=Math.sin(t.rotation*Jr);return{x:t.x+e.x*n-e.y*r,y:t.y+e.x*r+e.y*n}}function Zr(e,t,n){return t<=Yr&&n<=Yr?[Xr({x:0,y:0},e)]:n<=Yr?[Xr({x:-t,y:0},e),Xr({x:t,y:0},e)]:t<=Yr?[Xr({x:0,y:-n},e),Xr({x:0,y:n},e)]:[{x:-t,y:-n},{x:t,y:-n},{x:t,y:n},{x:-t,y:n}].map(t=>Xr(t,e))}function Qr(e,t,n){let r=Math.min(t,n),i=(Math.max(t,n)-r)/2;return{core:t>=n?Zr(e,i,0):Zr(e,0,i),radius:r/2}}function $r(e){switch(e.shape){case`rect`:return{core:Zr(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:Zr(e,e.width/2-t,e.height/2-t),radius:t}}case`circle`:return{core:[Xr({x:0,y:0},e)],radius:e.width/2};case`oval`:return Qr(e,e.width,e.height);default:return}}function ei(e,t){return{x:e.x-t.x,y:e.y-t.y}}function ti(e,t){return e.x*t.y-e.y*t.x}function ni(e,t,n){let r=ei(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 ri(e,t,n,r){let i=ei(t,e),a=ei(r,n),o=ti(i,a);if(o===0)return;let s=ti(ei(n,e),a)/o,c=ti(ei(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 ii(e,t,n,r){let i=ri(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=ni(i,n,r);a.push({distance:e.distance,from:i,to:e.at})}for(let i of[n,r]){let n=ni(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 ai(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 oi(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 si(e,t){if(!(e.length<3))return t.find(t=>oi(t,e))}function ci(e,t){let n=si(e,t)??si(t,e);if(n!==void 0)return{distance:0,from:n,to:n};let r;for(let[n,i]of ai(e))for(let[e,a]of ai(t)){let t=ii(n,i,e,a);(r===void 0||t.distance<r.distance)&&(r=t)}return r}function li(e,t){return ci(e.core,t.core).distance-e.radius-t.radius}function ui(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 di(e,t){let{from:n,to:r}=ci(e.core,t.core);return[ui(n,r,e.radius),ui(r,n,t.radius)]}function fi(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 pi=4,mi=6,hi=6;function gi(e,t){let n=[...e].length;return n===0?0:((n-1)*hi+pi)*t/mi}var _i=.15,vi=[0,.4,.8,1.2,1.6],yi=.5,bi=4;function xi(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 Si(e,t){let n=Math.abs(e-t),r=Math.max(e,n),i=Math.max(yi,r/bi),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 Ci(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=xi(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=gi(e.component,1)/2+_i/2,l=.575,u=[],d={flat:Si(o,n(!0)===0?c:l),upright:Si(s,n(!1)===0?l:c)};for(let e of vi){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 Ti=e=>e.nameAt??e.designatorAt??Ci(e,.15,0).find(t=>t.at.y>e.y)?.at??{x:e.x,y:e.y},Ei=e=>(e.nameAt?e.nameRotation:void 0)??e.designatorRotation??e.nameRotation??0,H=.3,Di=.5,Oi=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ki=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,Ai={strong:600,regular:400},ji=(e,t,n=Oi)=>`${e} ${t}px ${n}`,U={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 Mi(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 Ni=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],Pi=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],Fi=[{id:`top`,name:`Top Layer`,group:`copper`,color:U.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:U.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:U.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:U.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:U.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:U.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:U.topAssembly,bottomColor:U.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:U.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:U.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:U.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:U.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:U.keepout}];function Ii(e,t){return Fi.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function Li(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var Ri={...Object.fromEntries(Ni.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function zi(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function Bi(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 Vi(e,t){return{...e,[t]:!e[t]}}function Hi(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function Ui(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(Hi(t)),t.drill&&n.add(`hole`);return[...n]}function Wi(e,t){return e.some(e=>t[e])}function Gi(e,t){let n=new Map(e.map(e=>[e.component,Ui(e)]));return{visible:t,of:e=>n.get(e)}}var Ki={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function qi(e,t){return{...e,[t]:!e[t]}}function Ji(e,t){return e===void 0||e[t]}function Yi(e){let t={kind:`parts`,label:`Parts`};return e===`schematic`?[t,{kind:`wires`,label:`Wires`},{kind:`labels`,label:`Net labels and flags`},{kind:`drawings`,label:`Drawings`},{kind:`texts`,label:`Names and values`}]:[t,{kind:`tracks`,label:`Tracks`},{kind:`vias`,label:`Vias`},{kind:`pours`,label:`Copper pours and holes`},{kind:`texts`,label:`Designators`}]}var Xi={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Zi(e,t){if(!Qi(Xi[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||Wi(r,n.visible)}function Qi(e,t){return t.armed===`note`||t.armed===`zoom`?!1:Ji(t.filter,e)}function $i(e,t){return e.filter(e=>Zi(e,t))}function ea(e,t){return $i(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function ta(e,t){return $i(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function na(e,t){return Qi(`labels`,t)?[...e]:[]}function ra(e,t){return Qi(`drawings`,t)?[...e]:[]}function ia(e,t){return $i(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function aa(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(ea(e,c),ta(r,c),na(i,c),ra(a,c),ia(o,c))}}function oa(e,t){return t.x>=e.x?`inside`:`touching`}var sa=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,ca=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function la(e,t,n,r){let i=ye([t,n]);if(!i)return[];let a=r===`inside`?e=>sa(i,e):e=>ca(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function ua(e,t,n,r){return la(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function da(e,t,n,r){return la(e,t,n,r)}var fa=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function pa(e,t,n){if(fa(e,t)||fa(e,n))return!0;let r=ye([t,n]);if(!r||!ca(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 ma(e,t,n,r){let i=ye([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>fa(i,e)):e=>e.some((t,n)=>pa(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function ha(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[ea(e.parts,o),ta(e.wires??[],o),na(e.labels??[],o)],u=ra(e.drawings??[],o),d=ia(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var ga=e=>[...new Set(e)],_a=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),va=(e,t)=>e.filter(e=>!t.includes(e)),ya=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},ba=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,xa=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&ba(e.from,t.from)&&ba(e.to,t.to);function Sa(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 Ca(e,t){return ba(t[e.index],e.from)&&ba(t[e.index+1],e.to)}var wa={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},Ta=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],Ea=class e{static none=new e(wa);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 Ta.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 Ta.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({...wa,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=ga(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:va(this.board,e)})}keepBoard(e){return this.with({board:ya(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...wa,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...wa,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...wa,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...wa,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...wa,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...wa,copper:[t]})}onlySegment(t){return xa(this.segment,t)?this:new e({...wa,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:va(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=ga(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=ga(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=ga(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=ga(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=ga(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:ga(t),wires:ga(n),labels:ga(r),drawings:ga(i),copper:ga(a),texts:[],board:[]};return Ta.every(e=>_a(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:va(this.names,e)})}withoutWires(e){return this.with({wires:va(this.wires,e)})}withoutLabels(e){return this.with({labels:va(this.labels,e)})}withoutDrawings(e){return this.with({drawings:va(this.drawings,e)})}withoutCopper(e){return this.with({copper:va(this.copper,e)})}keep(e){return this.with({names:ya(this.names,e)})}keepWires(e){return this.with({wires:ya(this.wires,e)})}keepLabels(e){return this.with({labels:ya(this.labels,e)})}keepDrawings(e){return this.with({drawings:ya(this.drawings,e)})}withoutTexts(e){return this.with({texts:va(this.texts,e)})}keepTexts(e){return this.with({texts:ya(this.texts,e)})}keepCopper(e){return this.with({copper:ya(this.copper,e)})}};function Da(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!Ca(n,r.points)?e.onlyCopper(n.id):e}function Oa(e){return e.shiftKey||e.ctrlKey||e.metaKey}function ka(e,t){let n=Oa(t);return t=>n?t.toggle(e):t.only(e)}function Aa(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var ja={error:U.error,warning:U.warning},Ma=6,Na=1.5,Pa=3,Fa=1;function Ia(e,t,n,r,i,a=ja){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?Pa:Na;i&&Ra(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,La(e,n,Ma,s)}}}function La(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function Ra(e,t,n){let r=(n+Fa)/2;e.strokeStyle=U.ringHaloOuter,La(e,t,Ma+r,Fa),e.strokeStyle=U.ringHaloInner,La(e,t,Ma-r,Fa)}var za={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:U.error,markerWarning:U.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`},Ba={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`},W=e=>e===`dark`?Ba:za,G=za,K=()=>G;function Va(e){G=e}function Ha(e,t,n=G){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var Ua=.02,Wa=3*Ua;function Ga(e){return e.kind===`bus`?Wa:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var Ka=(e,t)=>Math.max(e,t);function qa(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function Ja(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function Ya(e){return e.kind===`bus`?K().bus:e.kind===`junction`?e.color??K().junction:e.color??K().drawing}var Xa=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Za=e=>`${e}33`,Qa=e=>1/e,$a=(e,t)=>(Math.floor(e*t)+.5)/t,eo=(e,t)=>Math.round(e*t)/t,to=(e,t)=>Math.max(1,Math.round(e*t))/t,no=(e,t)=>Math.round(e*t)/t,ro=(e,t)=>e/t,io=(e,t)=>Math.max(1,Math.round(e*t)),ao=(e,t,n)=>n%2==1?$a(e,t):eo(e,t);function oo(e,t,n,r=1){let i=e=>ao(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 so=.16;function co(e){return e<7?`none`:e<9?`names`:`all`}function lo(e,t,n){if(n<5)return!1;let r=co(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var uo=(e,t,n)=>Math.max(1,Math.round(e*t*n)),fo=(e,t)=>uo(so,e,t),po=(e,t,n)=>uo(e,t,n)/n,mo=(e,t)=>({x:eo(e.x,t),y:no(e.y,t)});function ho(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var go=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),_o=e=>e*Math.PI/180;function vo(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 yo(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function bo(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=_o(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+_o(yo(t.startAngle,t.endAngle)))}function xo(e,t){return t.selected?.includes(e.id)?{color:K().selection,alpha:1}:{color:Ya(e),alpha:t.dim?H:1}}function So(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Ut,0,2*Math.PI),Ha(e,i),e.fill(),Ha(e,!1)}function Co(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=xo(i,r);if(i.kind===`junction`){So(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=Ka(Ga(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(qa(r.pending?`dashed`:Ja(i),o)),bo(e,i),Xa(i)&&(e.fillStyle=Za(t),e.fill()),Ha(e,r.selected?.includes(i.id)??!1),e.stroke(),Ha(e,!1),e.setLineDash([])}e.globalAlpha=1}function wo(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=uo(o.fontSize,n.scale,a);if(!lo(`detail`,fo(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=xo(o,i),u=mo(B(n,r,o),a),[,d]=Mi(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${Oi}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var To=.7,Eo=`…`,Do=2;function Oo(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=Do;r--){let i=e.slice(0,r)+Eo;if(n(i)<=t)return i}return null}function ko(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>=Do;r--){let i=e.slice(0,r)+Eo;if(t(i)>=n)return{text:i,scale:n}}return null}function Ao(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var jo=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),Mo=e=>e.side===`left`||e.side===`right`,No=e=>Mo(e)?`x`:`y`,Po=e=>Mo(e)?`y`:`x`,Fo=e=>Mo(e)?1:.5,Io={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function Lo(e,t,n,r){let[i,a]=[No(e),Po(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>jo(e,i,e.text,n)*Fo(e),c=t=>Math.abs(t.local[a]-e.local[a])<(jo(e,a,e.text,n)+jo(t,a,t.text,n))/2,l=t.filter(t=>t.side===Io[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 Ao(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/Fo(e)}function Ro(e,t,n){let r=Po(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 zo(e,t,n,r,i){let a=Lo(e,t,n,r),o=Ro(e,t,r);return ko(e.text,t=>Math.min(a/jo(e,No(e),t,n),o/jo(e,Po(e),t,n)),i)}function Bo(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 Vo=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function Ho(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&Vo(r,e)&&n.add(i).add(a)})}),n}function Uo(e,t,n,r=To){let i=e.map(i=>zo(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:Bo(e[r],n,t)),o=Ho(a,(t,n)=>e[t]?.side===e[n]?.side),s=Ho(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var Wo=.25,Go=.8,Ko=.2,qo={top:Go,middle:.6000000000000001/2,bottom:-.2},Jo=(e,t,n)=>ji(e.strong?Ai.strong:Ai.regular,t/n,e.mono?ki:void 0);function Yo(e,t,{camera:n,ratio:r}){let i=uo(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=Jo(t,i,r),go(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function Xo(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(qo[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??Go*r-a,descent:i.actualBoundingBoxDescent??Ko*r+a}}function Zo(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]=Mi(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=Xo(e,t.text,s,a);return{text:t.text,x:o.x,y:o.y,align:c,size:a,...u,local:l,side:i.side,quarter:i.quarter}}function Qo(e,t,n){let r=t[0];if(!r)return t;e.font=Jo(r.label,r.devicePx,n.ratio);let i=t.map(t=>Zo(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*To)/r.devicePx,o=Uo(i,t=>e.measureText(t).width,r.devicePx/n.ratio*Wo,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 $o(e,t,n){let r=fo(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>lo(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:Yo(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=>Qo(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function es(e,{label:t,devicePx:n},r){let i=mo(B(r.camera,r.size,t.at),r.ratio),[a,o]=Mi(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=Jo(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function ts(e,t,n,r,i){let a={camera:n,size:r,ratio:i};ho(e);for(let n of $o(e,t,a))es(e,n,a)}var ns=.05,rs=.015;function is(e){let t=ns;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 as(e,t,n,r){if(t.length!==0){e.strokeStyle=K().noConnect,e.lineWidth=n(rs),e.globalAlpha=r?H:1;for(let n of t)for(let[t,r]of is(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var os={x:0,y:0},ss=.02,cs=1.2,ls=3.5,us=.06,ds=1.5,fs=1.6,ps=.04,ms=3,hs=[.1,.06],gs=.1,_s=.07,vs=2.5,ys={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},bs={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},xs={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},Ss=e=>e*Math.PI/180,Cs=e=>Math.max(Ua*e,cs);function ws(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:os;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`,Is(e,t,r,o,s);let d=vo(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};Co(e,d,o/r.ratio,m),Co(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)Ls(e,n,l(n),{line:s,px:o,fade:Ms(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:K().selection,alpha:1}:js(n.net,r.highlight);Ha(e,i),Ks(e,Gs(n,r),s,c,t,a),Ha(e,!1)}for(let t of r.ghostLabels??[])Ks(e,t,s,c,!0,js(t.net,void 0));Ys(e,t,r,o,l),as(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),ts(e,c,i,a,r.ratio),wo(e,p,i,a,m,r.ratio),Ia(e,n,r.violations??[],r.activeViolation,!1,{error:K().markerError,warning:K().markerWarning}),e.restore()}function Ts(e){return e.symbols.map(e=>{let t=Ds(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var Es=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function Ds(e){let{minX:t,minY:n,maxX:r,maxY:i}=Tt(e.symbol.shapes.filter(e=>!Es(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>Os(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 Os(e,t){let n=Ss(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 ks(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function As(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function js(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:K().highlight,alpha:1}:{color:void 0,alpha:H}:{color:void 0,alpha:1}}function Ms(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:H:1}var Ns=1e-9;function Ps(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<Ns,i=(e,t,n)=>e>=Math.min(t,n)-Ns&&e<=Math.max(t,n)+Ns;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function Fs(e,t,n){return e.wires.some(e=>js(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&Ps(t,e.points[r-1]??n,n)))}function Is(e,t,n,r,i){e.lineWidth=i(Ua);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:K().selection,alpha:1}:js(r.net,n.highlight);e.strokeStyle=i.color??K().wire,e.globalAlpha=i.alpha,Ha(e,t),ks(e,r.points),e.stroke()}Ha(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&Fs(t,i,n.highlight);e.fillStyle=a?K().highlight:K().junction,e.globalAlpha=n.highlight&&!a?H:1,As(e,i,Math.max(ps,ms*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=K().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(hs);for(let t of a)ks(e,t),e.stroke();e.setLineDash([])}}function Ls(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(ss),Bs(e,t.symbol.shapes,a,K().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(...zs(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...Rs(e,t)})))}function Rs(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:vs*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function zs(e,t){return e.pins.map(e=>{let n=xs[e.side],r={x:e.end.x-n.x*gs,y:e.end.y-n.y*gs},i=n.x===0?{x:r.x+_s,y:r.y}:{x:r.x,y:r.y+_s};return{text:String(e.number),at:Os(i,t),size:.1,anchor:`center`,color:K().pinNumber,mono:!0,kind:`pin-number`}})}function Bs(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(Ss(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(Us(a,n,r)):a.type===`polyline`&&a.bus?Vs(e,a):Hs(e,a);e.restore()}function Vs(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=K().bus,e.fillStyle=K().bus,ks(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function Hs(e,t){if(t.type===`polyline`)ks(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)As(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,Ss(t.start),Ss(n)),e.stroke()}}function Us(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=Ss(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:ys[e.role],...e.role===`pin-name`?{pinOf:Ws(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:Os(e.at,t),size:e.size,anchor:s,color:K()[bs[e.role]]??n,...c}}function Ws(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(Ss(t.rotation)))>.5}}function Gs(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function Ks(e,t,n,r,i,a){e.setLineDash(i?hs:[]),e.globalAlpha=a.alpha,qs(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function qs(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?Dt():Ot(t.text);e.lineWidth=n(ss);let o=r.length;Bs(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??K().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??K().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Nt(t);r.push({text:t.text,at:a,size:kt,anchor:`center`,strong:!0,kind:`name`,color:i.color??K().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&Js(e,t,s,n,i)}function Js(e,t,n,r,i){e.strokeStyle=i.color??K().netName,e.lineWidth=r(t.bus?ss*3:ss),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 Ys(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?K().highlight:K().pin;let c=a?Math.min(ls*r,Math.max(us,ds*r)):(s?fs:1)*ls*r;As(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var Xs=2;function Zs(e,t){return Math.max(e,Cs(t)/2+Xs)}var Qs=e=>Zs(6,e);function $s(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 ec(e,t){let n;for(let r=1;r<e.length;r++){let i=$s(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function tc(e,t,n){let r=ec(e,t);return r&&r.distance<=n?r.index:void 0}function nc(e,t,n){let r;for(let i of e){let e=ec(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function rc(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function ic(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 ac=1e-9,oc={x:0,y:0},sc=(e,t)=>Math.abs(e-t)<ac;function cc(e,t){return sc(e.y,t.y)?`horizontal`:sc(e.x,t.x)?`vertical`:`slanted`}function lc(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function uc(e,t){return e===`horizontal`?sc(t.y,0):e!==`vertical`||sc(t.x,0)}function dc(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=>!sc(e.x,0))?.x??0,y:r.find(e=>!sc(e.y,0))?.y??0}})}function fc(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&&!uc(cc(a,o),n)}function pc(e,t){let n=dc(e,t);return xn(e.flatMap((r,i)=>{let a=n[i]??oc,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!fc(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function mc(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?xn(e):pc(e,new Map([[t,lc(cc(r,i),n)]]))}function hc(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return xn(e);let o={x:n.x-i.x,y:n.y-i.y};return pc(e,new Map([[t-1,lc(cc(r,i),o)],[t,lc(cc(i,a),o)]]))}var gc=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function _c(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 xn(e);let s=n.start?[gc(r,t)]:[r,gc(r,lc(cc(r,i),t))],c=n.end?[gc(o,t)]:[gc(o,lc(cc(a,o),t)),o];return xn([...s,...e.slice(1,-1).map(e=>gc(e,t)),...c])}function vc(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return xn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=cc(n,r)===`horizontal`,xn(bn(e.filter((e,n)=>n!==t),i))}var yc=xn,bc=`The pin of this wire has several traces to its net; change its corners in the code`,xc=1e-6;function Sc(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)-xc<=t.x&&t.x<=Math.max(i.x,n.x)+xc&&Math.min(i.y,n.y)-xc<=t.y&&t.y<=Math.max(i.y,n.y)+xc;return Math.abs(a)<=xc&&o})}function Cc(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&Sc(e.points,r))}function wc(e,t,n,r){let i=ur(e,t,{pin:n.id},{net:mr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:bc};let o=fr(a)??hr(t,a);return o===void 0?{trace:a}:{blocked:o}}function Tc(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 Ec=/^wire:.+:\d+$/,Dc=e=>e.startsWith(`net.`),Oc=(e,t)=>e.x===t.x&&e.y===t.y,kc=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function Ac(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function jc(e,t,n){let r=t=>Dc(t)?{net:mr(e,t)}:{pin:t};return dr(ur(e,t,r(n.from),r(n.to)).filter(t=>lr(e,t.from,r(n.from))),n.id)}function Mc(e,t,n,r,i){let a=jc(e,t,i);if(!a)return Ac(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=>!Dc(e)),s=o.map(t=>kc(e,t)?.component??``),c=o.length===1,l=hr(t,a);return Ac(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&Dc(i.from),components:s,...l?{repeat:l}:{}})}function Nc(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&Oc(e.pinEnds[t],n)));return r===void 0?void 0:kc(e,r)}var Pc=(e,t)=>{let n=t.find(t=>!rr(kn(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function Fc(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||!Cc(e,n,o,c))return;let l={pinLast:a,...wc(e,t,i,o)};return Ac(n,r,{kind:`engine`,from:kn(e,i),to:`net.${s}`,components:[i.component],...Pc(e,[i]),onWire:l})}function Ic(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?[Nc(e,a.pins,o),Nc(e,a.pins,s)]:[];return(c&&!l?Fc(e,t,n,r,c,!1,i):!c&&l?Fc(e,t,n,r,l,!0,i):void 0)||(!c||!l?Ac(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):Ac(n,r,{kind:`engine`,from:kn(e,c),to:kn(e,l),components:[c.component,l.component],...Pc(e,[c,l])}))}function Lc(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?Mc(e,t,r.id,i,a):Ec.test(r.id)?Ic(e,t,r.id,i,r.net):Ac(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function Rc(e,t,n=cr){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=pr(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??fr(r.trace)??null:`${i} is locked`}function zc(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function Bc(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&&Oc(n,i)&&Oc(r,a)}var Vc=(e,t)=>e.length===t.length&&e.every((e,n)=>Oc(e,t[n]));function Hc(e,t,n,r=cr,i=t.points){let a=Rc(e,t,r);if(a!==null)return{blocked:a};let o=yc(n);if(!Bc(o,t))return{blocked:`The ends of a wire stay on their pins`};if(Vc(o,yc(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:zc(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return Tc(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 Uc=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});Uc(za);var Wc=3,Gc=e=>Zs(Wc,e),Kc=[4,3],qc=(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}},Jc=e=>({x:-e.y,y:e.x}),Yc=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function Xc(e,t,n,r,i){let a=e[n];if(n===0)return Yc(Yc(a,t[0],-r),Jc(t[0]),r*i);if(n===e.length-1)return Yc(Yc(a,t[n-1],r),Jc(t[n-1]),r*i);let[o,s]=[Jc(t[n-1]),Jc(t[n])],c=o.x*s.x+o.y*s.y;return Yc(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Zc(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)=>qc(n[t],e)),i=e=>n.map((i,a)=>Xc(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Qc(e,t,n,r,i,a){let o=Zc(r.map(e=>B(t,n,e)),Gc(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=Qa(a),e.setLineDash(Kc),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 $c(e,t,n,r,i,a){let{corners:o,ends:s}=rc(r),c=to(6,a),l=Qa(a),u=(r,i)=>{let o=B(t,n,r),[s,u]=[eo(o.x-c/2,a),eo(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 el=e=>3/e,tl=e=>Qs(e)/e;function nl(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?ic(i,n,el(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function rl(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Zi({kind:`wire`,id:i},t))return nl(e,i,n,r)}function il(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=tc(e,t,tl(n));return i===void 0?void 0:{kind:`segment`,index:i}}function al(e,t,n,r){let i=e[t.index];if(!i)return yc(e);let a={x:ge(i.x+n.x,r.step,r.snap),y:ge(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?hc(e,t.index,a):mc(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function ol(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 sl(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:al(e.points,e.grip,t,n)}}var cl=`The wire changed while you dragged it; try again`;function ll(e,t,n){if(!e||!t.moved||t.blocker||Vc(t.path,yc(t.points)))return;let r=e.points(t.wire);if(!r||!Vc(r,t.points))return n(cl);e.commit(t.wire,t.path)}function ul(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function dl(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 fl=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function pl(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var ml=2,hl=(e,t)=>Math.max(6,e*t/2+ml)/t;function gl(e,t,n,r,i){let a=e.find(e=>pl({kind:`via`,...fl(e)},r)&&Zi({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=hl(e.diameter,n));return a&&{kind:`via`,id:a.id}}function _l(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,$s(t,e[r-1],e[r]));return n}function vl(e,t,n,r,i){let a;for(let o of e){if(!pl({kind:`track`,layer:o.layer,...fl(o)},r)||!Zi({kind:`track`,id:o.id},i))continue;let e=_l(o.points,t);e<=hl(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function yl(e,t,n,r,i){return gl(e.vias,t,n,r,i)??vl(e.tracks,t,n,r,i)}function bl(e,t,n,r,i){let a=yl(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&tc(o.points,t,hl(o.width,n));return o&&s!==void 0?Sa(o,s):void 0}function xl(e,t,n,r,i=0){let a=r?ic(e,t,el(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=tc(e,t,hl(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var Sl=(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 Cl(e,t){let n=e.tracks.filter(e=>pl({kind:`track`,layer:e.layer,...fl(e)},t)),r=e.vias.filter(e=>pl({kind:`via`,...fl(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:Sl(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:Sl([e.at],e.diameter/2)}))]}function wl(e,t,n,r){let i=new Set(la(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var Tl=.4,El=.7,q=1.5,Dl={top:U.topCopper,bottom:U.bottomCopper,inner1:U.topCopper,inner2:U.topCopper},J=e=>e.missingLayer===void 0?Dl[e.layer]:U.keepout,Y=e=>e.missingLayer===void 0?U.viaRing:U.keepout,Ol=(e,t)=>pl({kind:`track`,layer:e.layer,...fl(e)},t),kl=(e,t)=>pl({kind:`via`,...fl(e)},t),Al=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?Di:1;function jl(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 Ml(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 Nl(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>Ol(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:Tl)*Al(r,t.net),jl(e,t.points,J(t),t.width);e.globalAlpha=1}function Pl(e,t,n,r){for(let i of t.vias.filter(e=>kl(e,n)))e.globalAlpha=Al(r,i.net),Ml(e,i.at,i.diameter/2,Y(i)),n.hole&&Ml(e,i.at,i.drill/2,U.drill);e.globalAlpha=1}function Fl(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)pl({kind:`track`,layer:t.layer},n)&&jl(e,t.points,Dl[t.layer],t.width);if(pl({kind:`via`},n))for(let t of r.vias)Ml(e,t.at,t.diameter/2,U.viaRing),n.hole&&Ml(e,t.at,t.drill/2,U.drill)}e.globalAlpha=1}function Il(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&Ca(r,t.points)?[r.from,r.to]:t.points}function Ll(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&Ol(s,n)){let n=Il(t,s,a);jl(e,n,i,s.width+2*q*o),jl(e,n,J(s),s.width),a&&jl(e,n,U.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&kl(c,n)&&(Ml(e,c.at,c.diameter/2+q*o,i),Ml(e,c.at,c.diameter/2,Y(c)),a&&Ml(e,c.at,c.diameter/2,U.selectionFill),n.hole&&Ml(e,c.at,c.drill/2,U.drill))}function Rl(e,t,n,r,i){Nl(e,t,n,r),Pl(e,t,n,r),Fl(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&Ll(e,t,n,t.hover,U.hover,!1,i);for(let r of t.selected)Ll(e,t,n,r,U.selection,!0,i)}var zl=e=>e.pcb.board?.pours??[];function Bl(e,t){return e.outline??t?.outline??[]}function Vl(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var Hl=(e,t)=>`pour ${Vl(e,t.net)} · ${t.layer}`,Ul=e=>`${Number(e.toFixed(4))} mm`,Wl=e=>`hole ${Ul(e.diameter)}`;function Gl(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 Kl(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function ql(e,t,n,r,i){let a=6/n,o;for(let n of zl(e))if(Gl(n,r,i))for(let[r,i]of Kl(Bl(n,e.pcb.board))){let e=$s(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Jl(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 Yl(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 Xl(e,t){let n=!1;for(let[r,i]of Kl(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 Zl(e,t){return e.polygons.some(e=>Xl(t,e.outer)&&!e.holes.some(e=>Xl(t,e)))}function Ql(e,t,n,r,i){let a=e.pcb.pours.filter(e=>Gl(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Zl(e,t))?.id}function $l(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=zl(e).find(e=>e.id===t),i=r?Bl(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 eu=[`solid`,`hatched`,`outline`],tu=`solid`,nu=`copperflow.pourFill`,ru=.35,iu=e=>eu.includes(e);function au(e){try{let t=e()?.getItem(nu);return iu(t)?t:tu}catch{return tu}}function ou(e,t){try{let n=e();return n?(n.setItem(nu,t),!0):!1}catch{return!1}}function su(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var cu={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},lu={top:U.topCopper,bottom:U.bottomCopper,inner1:U.inner1Copper,inner2:U.inner2Copper},uu=lu,du=.5,fu=6,pu=1,mu=1.5;function hu(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function gu(e,t){yu()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){hu(e,n.outer);for(let t of n.holes)hu(e,t)}}function _u(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(du,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 vu=new WeakMap,yu=()=>typeof Path2D==`function`;function bu(e){let t=vu.get(e);if(t)return t;let n={};return vu.set(e,n),n}function xu(e){if(!yu())return;let t=bu(e);return t.rings||(t.rings=new Path2D,gu(t.rings,e)),t.rings}function Su(e,t){if(!yu())return;let n=bu(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of _u(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 Cu(e,t,n){e.lineWidth=n;let r=xu(t);if(r)return e.stroke(r);gu(e,t),e.stroke()}function wu(e,t,n){let r=xu(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);gu(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function Tu(e,t,n){let r=Su(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of _u(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function Eu(e,t,n,r){let i=uu[t.layer]??U.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,Cu(e,t,pu*r);else{if(e.globalAlpha=ru,n===`solid`)return wu(e,t,`fill`);e.save(),wu(e,t,`clip`),e.lineWidth=pu*r,e.globalAlpha=1,Tu(e,t,r),e.restore(),e.globalAlpha=1,Cu(e,t,pu*r)}}function Du(e,t,n,r,i){let a=(t.pours??[]).filter(e=>Gl(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)Eu(e,t,n.mode,i);e.globalAlpha=1}function Ou(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 ku(e,t,n,r){if(e.strokeStyle=U.selection,e.lineWidth=mu*r,e.beginPath(),hu(e,t),e.stroke(),n){e.fillStyle=U.selection;for(let n of t)Ou(e,n,fu*r),e.fill()}}function Au(e,t,n,r,i,a){if(r.selected.has(t.id))return ku(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?U.hover:uu[t.layer]??U.topCopper,e.lineWidth=Math.max(a,pu*i),e.setLineDash([4*i,3*i]),e.beginPath(),hu(e,n),e.stroke(),e.setLineDash([]))}function ju(e,t,n){t.length<2||(e.strokeStyle=U.selection,e.lineWidth=pu*n,e.setLineDash([4*n,3*n]),e.beginPath(),hu(e,t),e.stroke(),e.setLineDash([]))}function Mu(e,t,n,r,i,a){for(let o of t.board?.pours??[])Gl(o,r,n.hidden)&&Au(e,o,n.outlines?.get(o.id)??Bl(o,t.board),n,i,a);n.preview&&ju(e,n.preview,i)}function Nu(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=U.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?U.selection:n.hover===r.id?U.hover:U.multiLayer,e.lineWidth=o?mu*i:a,e.stroke()}}var Pu=(e,t=!1)=>({action:e,preventDefault:t}),Fu=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 Iu(e){for(let t of Fu.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function Lu(e){let t=Fu.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 Ru=`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']`,zu=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,Bu=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,Vu=`[data-keys='parts']`;function Hu(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(zu)!=null,onButton:t?.closest(Bu)!=null,ownsKeys:t?.closest(Ru)!=null,partRows:t?.closest(Vu)!=null,handled:e.defaultPrevented}}var Uu=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),Wu=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),Gu=new Map([[`w`,`route`],[`v`,`placeVia`]]);function Ku(e,t){if(e.shiftKey)return null;let n=Uu(e);if(n===`s`)return Pu(`toggleSnap`,!0);let r=(t.view===`schematic`?Wu:Gu).get(n);return r?Pu(r,!0):null}function qu(e,t,n){switch(e){case`w`:return Pu(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?Pu(`switchLayer`,!0):null;case`r`:return Pu(`rotate`);case`k`:return Pu(`fit`);case`f`:return t.shiftKey?Pu(`openLibrary`,!0):Pu(`fit`);case`h`:return t.shiftKey?Pu(`clearHighlight`):Pu(`highlight`);case`q`:return n.view===`pcb`?Pu(`toggleUnit`):null;case`u`:return n.view===`pcb`?Pu(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?Pu(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?Pu(`flip`,!0):null;default:return null}}var Ju=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),Yu=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),Xu=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Zu=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Qu(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Zu:Xu).get(e.key.toLowerCase());return t?Pu(t,t!==`copy`):null}function $u(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?Pu(`removeCorner`,!0):null:Pu(`delete`)}var ed=e=>e.key===`Delete`||e.key===`Backspace`,td=e=>e.ownsKeys===!0&&!(e.partRows===!0&&ed(e)),nd=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function rd(e,t){if(e.typing)return null;if(nd(e))return Pu(`contextMenu`,!0);let n=Ju.get(e.key);return n&&Yu(e)?Pu(n):e.ctrlKey||e.metaKey?Qu(e):e.altKey?Ku(e,t):e.handled||td(e)?null:Lu(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?Pu(`finishShape`,!0):null:ed(e)?$u(e,t):e.key===` `?e.onButton?null:Pu(t.drawing?`flipBend`:`rotate`,!0):qu(e.key.toLowerCase(),e,t))}function id(e){return e.key===`Escape`&&!e.typing}var ad=e=>yt(e)+0,od=e=>Math.round((e%360+360)%360/90)%4;function sd(e,t){switch(od(t)){case 1:return{x:ad(-e.y),y:ad(e.x)};case 2:return{x:ad(-e.x),y:ad(-e.y)};case 3:return{x:ad(e.y),y:ad(-e.x)};default:return{x:ad(e.x),y:ad(e.y)}}}function cd(e,t){let n=sd(e,t.rotation);return{x:ad(t.x+n.x),y:ad(t.y+n.y)}}var X={reference:`schNameAt`,value:`schValueAt`},ld=(e,t)=>`${e}:${t}`;function ud(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function dd(e,t,n){let r=vt*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function fd(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=cd(t.at,e),r=X[t.role],i={x:ad(n.x-e.x),y:ad(n.y-e.y)};return[{id:ld(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:dd(n,t.size,t.text.length)}]})}var pd=.8,md={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},hd={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function gd(e){let t=ud(e)?.prop;if(t!==void 0)return md.schematic.includes(t)?`schematic`:md.pcb.includes(t)?`pcb`:void 0}function _d(e){return e.symbols.flatMap(e=>fd(e))}function vd(e){let t=Ti(e),n={x:t.x-e.x,y:t.y-e.y},r=Ei(e),i=dd(t,pd,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:ld(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:s,rotation:r}}function yd(e){return e.parts.map(vd)}function bd(e,t){return e===`pcb`?yd(t.pcb):_d(t.schematic)}var xd=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,Sd=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Cd(e,t){return e.filter(e=>xd(e.box,t)).sort((e,t)=>Sd(e.box)-Sd(t.box))[0]}function wd(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 Td(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?wd(e,n.at):e})}function Ed(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 Dd(e){let t=ud(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function Od(e,t){let n=ud(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}var kd=(e,t)=>e.model.parts.find(e=>e.name===t)?.props.pcbNameRotation!==void 0;function Ad(e,t,n){let r=ud(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 jd(e,t,n,r){let i=Id(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 Md(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=sd({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 Nd(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=ud(n.id);return r?.part===e.component?Md(t,r.prop,n.at):t},e));return{...e,symbols:n}}function Pd(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===ld(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var Fd=e=>String(V(e));function Id(e,t,n,r){let i=gd(n),a=i&&bd(i,e).find(e=>e.id===n);if(!i||!a)return;let o=Od(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${Fd(a.offset.x)}${s}`},{label:`Offset Y`,value:`${Fd(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}°${kd(t,a.part)?` (pcbNameRotation)`:``}`}]];return{title:hd[a.prop]??a.prop,rows:c,moved:o,blocker:Ad(t,r,n)}}function Ld(e,t,n){let r=e.soleText,i=Iu(t.action);if(r!==void 0&&i)return{id:r,by:it(i,n.step,t.steps??1,n.snap!==!1)}}var Rd={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},zd={x:0,y:0},Bd=1.5,Vd=.35,Hd=1.5,Ud=.6,Wd=.12,Gd=1.5,Kd=.7,qd=.5,Jd=1e-9,Yd=.25,Xd=.6,Zd=e=>e*Math.PI/180,Qd=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],$d=e=>e.autoPlaced?Xd:1,ef=e=>e.side===`top`?U.topAssembly:U.bottomAssembly;function tf(e,t,n,r){let i={...Ri,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=ro(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:zd,u=n=>{for(let r of t.parts)sf(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=$d(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...af(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&pf(e,t,s,c);let d=r.pours??Rd;Du(e,t,d,i,s),_f(e,i,r.highlight,u,s),r.copper&&Rl(e,r.copper,i,r.highlight,s),i.hole&&yf(e,u),Nu(e,t.holes??[],d,i,s,c),Mu(e,t,d,i,s,c),u(t=>{Qd(i,t,`Silk`)&&bf(e,t.silkscreen,t.side===`top`?U.topSilk:U.bottomSilk,Math.max(Wd,c),!1)}),i.courtyard&&xf(e,u,s,c),u(t=>{Qd(i,t,`Assembly`)&&bf(e,t.fabrication,ef(t),c,!1)}),i.boardOutline&&ff(e,t,()=>{e.strokeStyle=U.boardEdge,e.lineWidth=Gd*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&Sf(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),ho(e);for(let n of t.parts)Qd(i,n,`Silk`)&&wf(e,n,a,o,l(n),r.ratio);Ia(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function nf(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[Hi(e)])&&Ef(e,t));if(e)return e}}function rf(e){return e.parts.map(e=>{let t=of(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function af({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 of(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 sf(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(Zd(r)),i(),e.restore()}function cf(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 lf(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function uf(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 df=(e,t,n)=>uf(e,t,n,Math.min(t,n)/2);function ff(e,t,n){let r=t.board?.outline;!r||r.length<3||(cf(e,r),n())}function pf(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=U.keepout,e.globalAlpha=Kd;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),cf(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),cf(e,t.outline),e.clip();for(let[n,r]of mf(t.outline))Cf(e,n,r);e.restore()}e.globalAlpha=1}}function mf(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(qd,l/399),d=Math.floor(l/u+Jd)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function hf(e,t){sf(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?lf(e,0,0,t.width/2):t.shape===`oval`?df(e,t.width,t.height):uf(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??Yd*Math.min(t.width,t.height):0)})}function gf(e){return e.layers===`through`?U.multiLayer:e.layers===`bottom`?U.bottomCopper:U.topCopper}function _f(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?Di:1)*$d(t),e.fillStyle=gf(r),hf(e,r),e.fill(),a&&vf(e,r,i,$d(t))}});e.globalAlpha=1}function vf(e,t,n,r){e.globalAlpha=Vd*r,e.fillStyle=U.highlight,hf(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=U.highlight,e.lineWidth=Hd*n,e.stroke()}function yf(e,t){e.fillStyle=U.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?lf(e,n.x,n.y,t.width/2):sf(e,n.x,n.y,n.rotation,()=>df(e,t.width,t.height)),e.fill())}})}function bf(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 xf(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,bf(e,[t.courtyard],ef(t),t.autoPlaced?Bd*n:r,!0)}),e.setLineDash([])}function Sf(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?U.highlight:U.ratsnest,e.globalAlpha=t?1:n.highlight?Ud*Di:Ud,Cf(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function Cf(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function wf(e,t,n,r,i,a){let o=uo(pd,n.scale,a);if(!lo(`name`,o,o))return;let s=Ti(t),c=mo(B(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?U.topSilk:U.bottomSilk,e.globalAlpha=$d(t),e.font=ji(Ai.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,Ei(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 Tf(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[Hi(e)])continue;let a=Of(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var Ef=(e,t)=>Of(e,t)<=0;function Df(e,t){let n=Zd(-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 Of(e,t){let{x:n,y:r}=Df(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?kf(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 kf(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 Af(e,t,n){let r=nc(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function jf(e,t,n){let r=Bn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=Sr(e,t)?.net??Af(e,t,n);return i===void 0?void 0:Mf(e.circuit.nets,i)}function Mf(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 Nf=[];function Pf(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 Ff(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 If(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:`${Qe(e)} ${e.length===1?`is`:`are`} on no net.`}}function Lf(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=If(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function Rf(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 zf(e,t,n){let r=[...new Set(e.flatMap(e=>Rf(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?Nf:r}function Bf(e,t,n){return nf(e,t,n)?.net??void 0}var Vf=e=>e.startsWith(`drawing:`)||e.includes(`~`),Hf=e=>JSON.stringify({...e,source:void 0}),Uf=(e,t)=>e.filter(e=>e.kind===t).length,Wf=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function Gf(e,t,n,r){return!Vf(t.id)&&!Wf(t.id,n)&&!Wf(t.id,r)?!0:e.kind===t.kind?Uf(n,t.kind)===Uf(r,t.kind)||Hf(e)===Hf(t):!1}function Kf(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||Gf(i,r,e,t)?[r.id]:[]})}function qf(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 Jf(e,t,n){return e.drawingCount===0?e:e.keepDrawings(Kf(t,n))}var Yf=/^[ADPF]?GND\w*$|^VSS\w*$/i,Xf=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,Zf=new Intl.Collator(`en`,{numeric:!0});function Qf(e){return Yf.test(e)?`ground`:Xf.test(e)?`power`:void 0}function $f(e){for(let t of e){let e=Qf(t);if(e)return e}}var ep=e=>e.find(e=>Qf(e))??e[0];function tp(e){return ep(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function np(e){return e.circuit.nets.map(e=>{let t=ep(e.names),n=$f(e.names);return{id:e.id,label:tp(e),pins:e.pins.length,named:t!==void 0,...n?{badge:n}:{}}}).sort((e,t)=>Number(t.named)-Number(e.named)||Zf.compare(e.label,t.label))}function rp(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Tr(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 ip=(e,t)=>e.schematic.labels.find(e=>e.id===t);function ap(e,t){let n=e?Dr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function op(e,t,n,r,i,a){let o=ip(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=Rr(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[ap(o,l.blocked)]};let u=l.length>0?Nr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[Dr(o)],notes:[]}:s}function sp(e,t,n,r,i,a){let o=n.map(n=>op(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 cp(e,t){return t.flatMap(t=>{let n=ip(e,t);return n?[Dr(n)]:[]})}var lp=e=>e.length>1?[`${e.length} labels`]:[...e];function up(e,t,n,r){if(r.has(e))return e;let i=t&&Er(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Er(n,e.id)===i)?.id}function dp(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=>up(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var fp=(e,t)=>e.slice(`label:${t}:`.length);function pp(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Tr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:ap(r,`Studio places it on ${fp(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function mp(e,t,n){let r=t.map(t=>pp(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 hp(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=Mf(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Tr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?tp(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var gp=e=>`${e.x},${e.y}`;function _p(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[gp(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(gp(n)),t.get(gp(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var vp=(e,t)=>e.x===t.x&&e.y===t.y;function yp(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:vp(n,i)&&vp(r,a)||vp(n,a)&&vp(r,i)}function bp(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&&!yp(i,r)}function xp(e,t,n){return e.withoutWires(e.wires.filter(e=>bp(e,t,n)))}function Sp(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 Cp=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],wp=`bottom-panel`,Tp=e=>`bottom-tab-${e}`,Ep={open:!1,tab:`drc`};function Dp(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Op(e){return{...e,open:!e.open}}function kp(e,t){return{open:!0,tab:t}}function Ap(e){return e.detail>0}var jp=`button, input[type='checkbox']`;function Mp(e){e.target instanceof HTMLElement&&e.target.closest(jp)?.blur()}function Np(e,t,n){return t>0||e===`checkbox`&&!n}function Pp(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function Fp(e){let t=e.target instanceof HTMLElement?e.target.closest(jp):null;t&&Np(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var Ip=new Set([`ArrowLeft`,`ArrowUp`]),Lp=new Set([`ArrowRight`,`ArrowDown`]);function Rp(e,t,n){if(e.length===0)return null;if(n===`Home`)return e[0]??null;if(n===`End`)return e[e.length-1]??null;let r=Ip.has(n)?-1:+!!Lp.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function zp({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=Rp(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(!Ap(t))return n(e);Mp(t),(r??n)(e)}})}}var Bp=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Vp=e(((e,t)=>{t.exports=Bp()})),Z=Vp(),Hp=Cp.map(e=>e.id);function Up({state:e,onClick:t,onOpen:n}){let r=zp({ids:Hp,current:e.tab,onSelect:n,onPointerClick:t});return(0,Z.jsx)(`nav`,{className:`bottom-strip hairline-t`,role:`tablist`,"aria-label":`Bottom panel`,onKeyDown:r.onKeyDown,children:Cp.map(t=>{let n=e.open&&e.tab===t.id;return(0,Z.jsx)(`button`,{role:`tab`,id:Tp(t.id),"aria-controls":wp,className:`bottom-tab${n?` on`:``}`,"aria-selected":n,...r.tab(t.id),children:(0,Z.jsx)(`span`,{className:`bottom-tab-label`,children:t.label})},t.id)})})}function Wp(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function Gp(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(Wp(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 Q=(e,t)=>t?{tag:`path`,d:e,dash:t}:{tag:`path`,d:e},Kp=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},qp=(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},Jp=Q(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),Yp=[qp(3,7,10,7,1.5),Q(`M8 10v1.5`)],Xp=[4,8,12].flatMap(e=>[4,8,12].map(t=>Kp(t,e,1,!0))),Zp={lock:[...Yp,Q(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[...Yp,Q(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[qp(2.5,7,11,7.5,1.5),Q(`M5 7V5a3 3 0 0 1 6 0v2`),Q(`M8 10v2`)],padlockOpen:[qp(2.5,7,11,7.5,1.5),Q(`M11 7V4a3 3 0 0 0-6 0v.5`),Q(`M8 10v2`)],trash:[Q(`M2.5 4.5h11M6 4.5V2.5h4v2`),Q(`M4 4.5l.5 9h7l.5-9`),Q(`M6.5 7v4M9.5 7v4`)],close:[Q(`M4 4l8 8M12 4l-8 8`)],chevron:[Q(`M6 4l4 4-4 4`)],eye:[Q(`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`),Kp(8,8,2)],eyeOff:[Q(`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`),Kp(8,8,2),Q(`M2.5 2.5l11 11`)],undo:[Q(`M5.5 3 3 5.5 5.5 8`),Q(`M3 5.5h6.5a3.5 3.5 0 0 1 0 7h-3`)],redo:[Q(`M10.5 3 13 5.5 10.5 8`),Q(`M13 5.5H6.5a3.5 3.5 0 0 0 0 7h3`)],zoomIn:[Kp(7,7,4.5),Q(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[Kp(7,7,4.5),Q(`M10.5 10.5 14 14M5 7h4`)],fit:[Jp,qp(6,6,4,4,.5)],fitSelection:[Jp,qp(5.5,5.5,5,5,1,!0)],fitArea:[qp(2.5,2.5,8,8,1),Q(`M7 7l6.5 6.5M13.5 9.5v4h-4`)].map(e=>e.tag===`rect`?{...e,dash:`2 2`}:e),grid:Xp,snap:[Q(`M3.5 2.5V8a4.5 4.5 0 0 0 9 0V2.5h-3V8a1.5 1.5 0 0 1-3 0V2.5z`),Q(`M3.5 5h3M9.5 5h3`)],component:[qp(4.5,3,7,10,1),Q(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[Kp(3.5,12.5,1.5),Kp(12.5,3.5,1.5),Q(`M5 12.5h3.5v-9H11`)],netLabel:[Q(`M1.5 8h2`),Q(`M5.5 4.5h8v7h-8L3.5 8z`),Q(`M8 8h3`)],bus:[Q(`M2 10.5h12`,void 0),Q(`M5.5 10.5l2-4.5M9.5 10.5l2-4.5`)],polyline:[Q(`M2 13l3.5-7 4 4 4.5-7`)],arc:[Q(`M3 12a5 5 0 0 1 10 0`)],circle:[Kp(8,8,5.5)],rectangle:[qp(2.5,4.5,11,7,0)],text:[Q(`M3.5 4.5V3h9v1.5M8 3v10M6 13h4`)],ground:[Q(`M8 2.5v6M3 8.5h10M5 11h6M7 13.5h2`)],power:[Q(`M8 14V5.5M3.5 5.5h9`),Q(`M3.5 5.5 8 2l4.5 3.5`)],noConnect:[Q(`M2 8h5`),Q(`M9 5.5l5 5M14 5.5l-5 5`)],via:[Kp(8,8,5.5),Kp(8,8,2)],boardOutline:[Q(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[qp(2.5,2.5,11,11,1),Q(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[Kp(3.5,12.5,1.5),Q(`M5 12.5h3.5L12 9V3.5`)],gerber:[Q(`M8 2.5 2.5 5 8 7.5 13.5 5z`),Q(`M2.5 8 8 10.5 13.5 8`),Q(`M2.5 11 8 13.5 13.5 11`)],rotate:[Q(`M3 8a5 5 0 1 0 5-5`),Q(`M9.5 1.5 8 3l1.5 1.5`)],rotateRight:[Q(`M13 8a5 5 0 1 1-5-5`),Q(`M6.5 1.5 8 3 6.5 4.5`)],alignLeft:[Q(`M2.5 2v12`),qp(5,3.5,8.5,3.5,1),qp(5,9,5,3.5,1)],distributeH:[Q(`M2.5 2v12M13.5 2v12`),qp(6,4,4,8,1)],check:[Q(`M8 1.5 3 3.5v4c0 3 2 5.5 5 6.5 3-1 5-3.5 5-6.5v-4z`),Q(`M5.5 8l2 2 3-3.5`)]},Qp={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 $p(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function em(e,t={}){let n=Zp[e];return(0,l.createElement)(`svg`,{...Qp,...t},...n.map((e,t)=>(0,l.createElement)(e.tag,$p(e,t))))}var tm=e=>em(`lock`,e),nm=e=>em(`unlock`,e),rm=e=>em(`padlock`,e),im=e=>em(`padlockOpen`,e),am=e=>em(`rotate`,e),om=e=>em(`trash`,e),sm=e=>em(`undo`,e),cm=e=>em(`close`,e),lm=e=>em(`chevron`,e),um=({off:e,...t})=>em(e?`eyeOff`:`eye`,t),dm=e=>t=>em(e,t),fm={undo:dm(`undo`),redo:dm(`redo`),zoomIn:dm(`zoomIn`),zoomOut:dm(`zoomOut`),fit:dm(`fit`),fitSelection:dm(`fitSelection`),fitArea:dm(`fitArea`),component:dm(`component`),wire:dm(`wire`),netLabel:dm(`netLabel`),ground:dm(`ground`),power:dm(`power`),rotate:dm(`rotate`),rotateRight:dm(`rotateRight`),snap:dm(`snap`),check:dm(`check`),grid:dm(`grid`),alignLeft:dm(`alignLeft`),distributeH:dm(`distributeH`),polyline:dm(`polyline`),arc:dm(`arc`),circle:dm(`circle`),rectangle:dm(`rectangle`),text:dm(`text`),bus:dm(`bus`),noConnect:dm(`noConnect`),via:dm(`via`),boardOutline:dm(`boardOutline`),copperArea:dm(`copperArea`),singleRouting:dm(`singleRouting`),gerber:dm(`gerber`)};function pm(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function mm(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function hm(){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 gm=hm();function _m(e){let t=e=>void gm.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function vm(e,t){let n=(0,l.useRef)(t);(0,l.useLayoutEffect)(()=>{n.current=t}),(0,l.useEffect)(()=>e?gm.hold(e=>n.current(e)):void 0,[e])}var ym=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],bm=`Select a part first`,xm=e=>ym.includes(e);function Sm(e,t){return v(e)?b(e,t):xm(e)&&t<1?bm:null}var Cm=`Comes with hand routing (engine stage 4)`,$=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},wm=[{title:`File`,entries:[$(`Open circuit file`,`openFile`,`Ctrl+O`),$(`New circuit…`,`newCircuit`),$(`Import board outline (DXF)…`,`importBoardDxf`),`separator`,$(`Export BOM`,`exportBom`),$(`Export package`,`exportPackage`),$(`Export Gerber`,`exportFabrication`),$(`Print…`,`print`)]},{title:`Edit`,entries:[$(`Undo`,`undo`,`Ctrl+Z`),$(`Redo`,`redo`,`Ctrl+Y`),`separator`,$(`Copy`,`copy`,`Ctrl+C`),$(`Paste`,`paste`,`Ctrl+V`),$(`Delete`,`delete`,`Delete`),`separator`,$(`Select all`,`selectAll`,`Ctrl+A`),$(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},$(`Find`,`find`,`Ctrl+F`),$(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,$(`Fillet tracks`,`filletTracks`,`U`),$(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[$(`Fit all`,`fit`,`K`),$(`Fit selection`,`fitSelection`),$(`Fit area`,`fitArea`),$(`Zoom in`,`zoomIn`),$(`Zoom out`,`zoomOut`),`separator`,{...$(`Unit`,`toggleUnit`,`Q`),only:`pcb`},$(`Grid style`,`gridStyle`),{...$(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...$(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...$(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...$(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...$(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,$(`Left panel`,`toggleLeftPanel`,`[`),$(`Right panel`,`toggleRightPanel`,`]`),$(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...$(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...$(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[$(`Component`,`placeComponent`,`Shift+F`),$(`Wire`,`wire`,`Alt+W`),$(`Net label`,`netLabel`,`Alt+N`),$(`Ground flag`,`groundFlag`),$(`Power flag`,`powerFlag`),`separator`,$(`Note box`,`noteBox`),`separator`,$(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,$(`Copper pour`,`placePour`),$(`Copper pour: Whole board`,`placePourBoard`),$(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,$(`Polyline`,`drawPolyline`,`Alt+L`),$(`Arc`,`drawArc`,`Alt+A`),$(`Circle`,`drawCircle`,`Alt+C`),$(`Rectangle`,`drawRectangle`,`Alt+R`),$(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[$(`Check DRC`,`checkDrc`),$(`Design rules`,`designRules`),`separator`,$(`Highlight net`,`highlight`,`H`),$(`Clear highlight`,`clearHighlight`,`Shift+H`),`separator`,{label:`Add page`,command:`addPage`,only:`schematic`},{label:`Rename page`,command:`renamePage`,only:`schematic`},{label:`Delete page`,command:`deletePage`,only:`schematic`},`separator`,{label:`Replicate layout`,command:`replicateLayout`,only:`pcb`},$(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[$(`Single routing`,`singleRouting`,`Alt+W`),$(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,$(`Autoroute`,`autoroute`),$(`Autoroute selection`,`autorouteSelection`),$(`Autoroute net`,`autorouteNet`),$(`Unroute`,`unroute`)]},{title:`Layout`,entries:[$(`Rotate`,`rotate`,`Space`),$(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,$(`Lock`,`lock`),$(`Unlock`,`unlock`),`separator`,$(`Align left`,`alignLeft`,`Ctrl+Shift+L`),$(`Align right`,`alignRight`),$(`Align top`,`alignTop`),$(`Align bottom`,`alignBottom`),$(`Align horizontal centres`,`alignHCentres`),$(`Align vertical centres`,`alignVCentres`),`separator`,$(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),$(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[$(`History`,`history`),$(`Footprint manager…`,`footprintManager`)]},{title:`Export`,entries:[$(`BOM`,`exportBom`),$(`Package`,`exportPackage`),$(`Fabrication files (JLCPCB)`,`exportFabrication`),$(`Gerber`,`exportFabrication`),$(`Pick and place (CPL)`,`exportFabrication`),$(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[$(`System…`,`systemSettings`),$(`Hotkeys`,`keys`)]},{title:`Help`,entries:[$(`Keys`,`keys`),$(`About`,`about`)]}];wm.map(e=>e.title);var Tm={pcb:`PCB only`,schematic:`Schematic only`};function Em(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:Tm[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:Sm(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function Dm(e){return e.entries.filter(e=>e!==`separator`)}var Om=[{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 km(){let e=new Set,t=[];for(let n of wm.flatMap(Dm))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Om.filter(t=>!e.has(t.keys))]}function Am(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 jm(e,t,n={}){return wm.map(r=>r.entries.map(r=>r===`separator`?`separator`:Em(r,e,t,n).enabled?`item`:`disabled`))}var Mm=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function Nm(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:Mm};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 Pm(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 Fm(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function Im(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 Lm({result:e}){return(0,Z.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,Z.jsx)(`p`,{children:(0,Z.jsx)(`strong`,{children:Pm(e)})}),(0,Z.jsx)(`p`,{children:Fm(e)}),e.notes.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h3`,{children:`Check these too`}),(0,Z.jsx)(`ul`,{children:e.notes.map(e=>(0,Z.jsx)(`li`,{children:e},e))})]}),(0,Z.jsx)(`h3`,{children:`Written`}),(0,Z.jsx)(`ul`,{children:e.files.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`code`,{children:e})},e))}),(0,Z.jsx)(`p`,{children:e.terms})]})}function Rm({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)(),h=(0,l.useId)(),g=async r=>{if(r.preventDefault(),c)return;if(p)return t();let a=Nm(n,i,o);if(`message`in a)return f(a.message);u(!0),f(void 0);try{m(await e.import(a))}catch(e){f(e.message)}finally{u(!1)}};return(0,Z.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void g(e),children:[(0,Z.jsx)(`label`,{htmlFor:h,children:`LCSC part number`}),(0,Z.jsx)(`input`,{id:h,value:n,placeholder:`C7950`,disabled:c||p!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${h}-note`,"aria-invalid":d!==void 0}),(0,Z.jsx)(`label`,{htmlFor:`${h}-id`,children:`Part id`}),(0,Z.jsx)(`input`,{id:`${h}-id`,value:i,placeholder:`the MPN`,disabled:c||p!==void 0,onChange:e=>a(e.target.value)}),(0,Z.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:o,disabled:c||p!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,Z.jsx)(`p`,{id:`${h}-note`,role:d?`alert`:void 0,children:c?`Fetching from EasyEDA…`:d??(p?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),p&&(0,Z.jsx)(Lm,{result:p}),(0,Z.jsx)(`button`,{type:`submit`,disabled:c,children:p?`Close`:`Import`})]})}var zm=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,Bm=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function Vm(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=Bm.exec(e)??zm.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function Hm(e,t){if(t.includes(`/`))return;let n=e.parts.find(e=>e.name===t)?.tag,r=e.imports.find(e=>e.local===n)?.source;if(r===void 0||!/\.sheet(\.tsx)?$/.test(r))return;let i=r.replace(/^\.\//,``);return i.endsWith(`.tsx`)?i:`${i}.tsx`}var Um=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function Wm(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(Hm(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 Gm(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=Wm(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function Km(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function qm(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var Jm=e=>`${e.trim()||`PowerStage`}1`,Ym=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function Xm(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var Zm=200;function Qm(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,l.useState)({problem:Ym});return(0,l.useEffect)(()=>{if(n.trim()===``){o({problem:Ym});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}))},Zm);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function $m({preview:e}){let t=Km(e);return t.length===0?(0,Z.jsx)(`p`,{children:`No net crosses the selection, so the sheet has no ports.`}):(0,Z.jsx)(`table`,{"aria-label":`Ports`,children:(0,Z.jsx)(`tbody`,{children:t.map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:e.port}),(0,Z.jsx)(`td`,{children:e.joins})]},e.port))})})}function eh({preview:e}){return(0,Z.jsxs)(`table`,{"aria-label":`Designators`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:`Now`}),(0,Z.jsx)(`td`,{children:`In the sheet`}),(0,Z.jsx)(`td`,{children:`On the board`})]})}),(0,Z.jsx)(`tbody`,{children:qm(e).map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:e.now}),(0,Z.jsx)(`td`,{children:e.sheet}),(0,Z.jsx)(`td`,{children:e.board})]},e.now))})]})}function th({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),c=i.trim(),u={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:d,problem:f}=Qm(e,u),p=(0,l.useId)(),m=async n=>{n.preventDefault(),d&&await e.make(u)&&t()};return(0,Z.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void m(e),children:[(0,Z.jsx)(`label`,{htmlFor:p,children:`Sheet name`}),(0,Z.jsx)(`input`,{id:p,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${p}-note`,"aria-invalid":f!==void 0&&n!==``}),(0,Z.jsx)(`label`,{htmlFor:`${p}-instance`,children:`Instance name`}),(0,Z.jsx)(`input`,{id:`${p}-instance`,value:i,placeholder:Jm(n),onChange:e=>a(e.target.value)}),(0,Z.jsx)(`p`,{id:`${p}-note`,children:d?`Writes ${d.file}; ${d.instance} (base ${d.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:f}),d&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h3`,{children:`Ports`}),(0,Z.jsx)($m,{preview:d}),(0,Z.jsx)(`h3`,{children:`Designators`}),(0,Z.jsx)(eh,{preview:d})]}),(0,Z.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Rename the parts to local designators (R1, C1, …)`]}),(0,Z.jsx)(`button`,{type:`submit`,disabled:!d,children:`Make sub-sheet`})]})}function nh(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function rh(e){let t=nh(e),n=()=>(0,l.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function ih({what:e,message:t,onRetry:n}){return(0,l.createElement)(`div`,{role:`alert`},(0,l.createElement)(`p`,null,`The ${e} dialog could not open (${t}). Check that the Studio is still running, then try again; if it fails again, reload the Studio.`),(0,l.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var ah=class extends l.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,l.createElement)(ih,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,l.createElement)(l.Suspense,{fallback:(0,l.createElement)(`p`,null,`Loading…`)},this.props.render())}},oh=.0254,sh=e=>e===`mm`?`mil`:`mm`,ch=(e,t)=>t===`mil`?e/oh:e;function lh(e,t){let n=ch(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function uh(e,t){return`${Number(ch(e,t).toFixed(t===`mm`?4:2))} ${t}`}var dh=(e,t)=>Math.round(e/t*100),fh=.0254,ph=[2*fh,.1,5*fh,10*fh,.5,20*fh,25*fh,1,50*fh,100*fh].map(e=>Number(e.toFixed(4))),mh=.5,hh=[.05,.1,.2],gh=.1,_h=(e,t,n)=>({...e,[t]:n});function vh(e,t){if(e===`schematic`)return hh.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return ph.map(e=>({value:e,label:uh(e,t)}))}var yh={schematic:`lines`,pcb:`lines`},bh=e=>e===`lines`?`dots`:`lines`,xh=(e,t)=>({...e,[t]:bh(e[t])}),Sh=5,Ch=2;function wh(e,t,n=1){let r=e;for(let e=0;e<=Ch;e++,r*=Sh)if(r*t*n>=3)return r;return null}function Th(e,t,n,r=1){let i=wh(n,e.scale,r);if(i===null)return null;let a=de(e,t,{x:0,y:0}),o=de(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 Eh=e=>e%5==0,Dh=e=>({...e,columns:e.columns.filter(Eh),rows:e.rows.filter(Eh)});function Oh(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||Eh(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=Qa(a),s(r.columns,e=>{let r=$a(B(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=$a(B(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function kh(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:eo(t(e),r)-i,fifth:Eh(e)}))}function Ah(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 jh(e,t,n,r,i,a){let{spacing:o}=r,s=to(i.px,a),c=kh(r.columns,e=>B(t,n,{x:e*o,y:0}).x,s,a),l=kh(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&&Ah(e,u,i.fifth,s)}function Mh(e,t,n,r,i,a){let o=Th(t,n,r.step,a);if(!o)return;let s=o.minor?o:Dh(o);e.save(),r.style===`dots`?jh(e,t,n,s,i.dots,a):Oh(e,t,n,s,i.lines,a),e.restore()}function Nh({panel:e,onClose:t}){let[n,r]=(0,l.useState)(e.settings),i=(0,l.useId)(),a=(e,t)=>r(n=>({...n,[e]:t}));return(0,Z.jsxs)(`form`,{className:`rules-form system-form`,onSubmit:r=>{r.preventDefault(),e.apply(n),t()},children:[(0,Z.jsx)(`label`,{htmlFor:`${i}-theme`,children:`Theme`}),(0,Z.jsxs)(`select`,{id:`${i}-theme`,value:n.theme,onChange:e=>a(`theme`,e.target.value),children:[(0,Z.jsx)(`option`,{value:`light`,children:`Light`}),(0,Z.jsx)(`option`,{value:`dark`,children:`Dark`})]}),(0,Z.jsx)(`label`,{htmlFor:`${i}-unit`,children:`PCB unit`}),(0,Z.jsxs)(`select`,{id:`${i}-unit`,value:n.unit,onChange:e=>a(`unit`,e.target.value),children:[(0,Z.jsx)(`option`,{value:`mm`,children:`mm`}),(0,Z.jsx)(`option`,{value:`mil`,children:`mil`})]}),(0,Z.jsx)(`label`,{htmlFor:`${i}-sheet`,children:`Schematic grid`}),(0,Z.jsx)(`select`,{id:`${i}-sheet`,value:n.grid.schematic,onChange:e=>a(`grid`,{...n.grid,schematic:Number(e.target.value)}),children:vh(`schematic`).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,Z.jsx)(`label`,{htmlFor:`${i}-pcb`,children:`PCB grid`}),(0,Z.jsx)(`select`,{id:`${i}-pcb`,value:n.grid.pcb,onChange:e=>a(`grid`,{...n.grid,pcb:Number(e.target.value)}),children:vh(`pcb`,n.unit).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,Z.jsxs)(`label`,{children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:n.hoverLabels,onChange:e=>a(`hoverLabels`,e.target.checked)}),` Hover labels`]}),(0,Z.jsx)(`p`,{children:`Kept in this browser. The grid steps are where each document starts; the Grid select still changes them.`}),(0,Z.jsx)(`button`,{type:`submit`,children:`Save`})]})}var Ph={width:30,height:20},Fh=1e3,Ih=/^[\w\- ]+(\/[\w\- ]+)*$/;function Lh(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!Ih.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>Fh)?{message:`The board's width and height are mm above 0 and at most ${Fh}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function Rh({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(String(Ph.width)),[o,s]=(0,l.useState)(String(Ph.height)),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(!1),p=(0,l.useId)(),m=async r=>{r.preventDefault();let a=Lh(n,i,o);if(`message`in a)return u(a.message);f(!0);let s=await e.create(a);f(!1),s&&t()};return(0,Z.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void m(e),children:[(0,Z.jsx)(`label`,{htmlFor:`${p}-name`,children:`Name`}),(0,Z.jsx)(`input`,{id:`${p}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,Z.jsx)(`label`,{htmlFor:`${p}-w`,children:`Board width (mm)`}),(0,Z.jsx)(`input`,{id:`${p}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,Z.jsx)(`label`,{htmlFor:`${p}-h`,children:`Board height (mm)`}),(0,Z.jsx)(`input`,{id:`${p}-h`,inputMode:`decimal`,value:o,onChange:e=>s(e.target.value)}),(0,Z.jsx)(`p`,{role:c?`alert`:void 0,children:c??`Written as <name>.circuit.tsx in the project folder; Undo removes it again.`}),(0,Z.jsx)(`button`,{type:`submit`,disabled:d,children:`Create`})]})}function zh(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 Bh({components:e,parts:t,locked:n}){return e.map(e=>{let r=zh(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 Vh=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),Hh=/^[\w.\-+:,=()]+$/;function Uh(e,t){let n=e.filter(e=>t[e.name]!==void 0&&t[e.name]?.trim()!==e.footprint);if(n.length===0)return{message:`No footprint was changed.`};let r=n.find(e=>e.fixed);if(r)return{message:`${r.name}: ${r.fixed}`};let i=n.find(e=>!Hh.test((t[e.name]??``).trim()));return i?{message:`${i.name}: a footprint is a name such as 0603 or soic8, without spaces`}:{edits:n.map(e=>({kind:`setProps`,part:e.name,props:{footprint:(t[e.name]??``).trim()}})),summary:`change footprints: ${n.slice(0,3).map(e=>`${e.name} → ${(t[e.name]??``).trim()}`).join(`, `)}${n.length>3?` and ${n.length-3} more`:``}`}}function Wh({panel:e,onClose:t}){let n=(0,l.useMemo)(()=>e.source?Bh(e.source):[],[e.source]),[r,i]=(0,l.useState)({}),[a,o]=(0,l.useState)(),s=(0,l.useId)();if(n.length===0)return(0,Z.jsx)(`p`,{children:`The open circuit has no parts yet.`});let c=async i=>{i.preventDefault();let a=Uh(n,r);if(`message`in a)return o(a.message);await e.write(a.edits,a.summary)&&t()};return(0,Z.jsxs)(`form`,{className:`footprint-manager`,onSubmit:e=>void c(e),children:[(0,Z.jsx)(`datalist`,{id:s,children:Vh(n).map(e=>(0,Z.jsx)(`option`,{value:e},e))}),(0,Z.jsxs)(`table`,{children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`col`,children:`Designator`}),(0,Z.jsx)(`th`,{scope:`col`,children:`Kind`}),(0,Z.jsx)(`th`,{scope:`col`,children:`Value`}),(0,Z.jsx)(`th`,{scope:`col`,children:`Footprint`})]})}),(0,Z.jsx)(`tbody`,{children:n.map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:e.name}),(0,Z.jsx)(`td`,{children:e.kind}),(0,Z.jsx)(`td`,{children:e.value}),(0,Z.jsx)(`td`,{children:(0,Z.jsx)(`input`,{"aria-label":`Footprint of ${e.name}`,list:s,value:r[e.name]??e.footprint,disabled:e.fixed!==void 0,title:e.fixed,onChange:t=>i(n=>({...n,[e.name]:t.target.value}))})})]},e.name))})]}),(0,Z.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,Z.jsx)(`button`,{type:`submit`,children:`Save`})]})}var Gh={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function Kh(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function qh(e,t){if(e===`*`)return!0;let n=Kh(e);return t.names.some(e=>n.test(e))}var Jh=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>qh(e,t))).map(e=>e.name);function Yh(e,t){return Jh(e,t)[0]??Gh.name}function Xh(e,t){let n=new Map,r=[];for(let i of t){let t=Jh(e,i);if(n.set(i.id,t[0]??Gh.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(Ur(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...Zh(e,t)]}}function Zh(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>qh(e,t))).map(t=>Ur(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var Qh=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??Gh.clearance;function $h(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(Qh(e,t),Qh(e,n),e.fabrication.minClearance,...r)}var eg=(e,t)=>e.classes.find(n=>n.name===Yh(e,t))??Gh,tg=(e,t)=>Math.max(eg(e,t).trackWidth,e.fabrication.minTrackWidth),ng=e=>Math.round(e*1e6)/1e6;function rg(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,ng(n+2*e.fabrication.minAnnularRing))}}var ig=(e,t)=>rg(e,eg(e,t).via),ag=e=>rg(e,Gh.via),og=e=>e.fabrication.filletRadius??1,sg=`Fillet radius`,cg=`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 lg(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function ug(e){if(e.trim()===``)return{radius:null};let t=Kr(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 dg=`modulepreload`,fg=function(e,t){return new URL(e,t).href},pg={},mg=function(e){return e.pathname.endsWith(`.css`)},hg=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},gg=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=fg(t,n);let r=s(t),i=mg(r);return hg(pg,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`:dg,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)})},_g=rh(()=>gg(()=>import(`./NewPartDialog-C4sKWnGI.js`).then(e=>e.NewPartForm),[],import.meta.url)),vg=`button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])`;function yg(e,t){vm(!0,n=>{let r=pm(n.key);if(r===`hold`)return;if(n.preventDefault(),r===`close`)return t();let i=[...e.current?.querySelectorAll(vg)??[]];(i[mm(i.indexOf(document.activeElement),i.length,n.shiftKey)]??e.current)?.focus()})}function bg({title:e,onClose:t,children:n,wide:r=!1}){let i=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=document.activeElement;return(i.current?.querySelector(`[data-default]`)??i.current?.querySelector(vg)??i.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),yg(i,t),(0,Z.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,Z.jsxs)(`section`,{ref:i,tabIndex:-1,className:r?`dialog wide`:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":e,children:[(0,Z.jsxs)(`header`,{className:`hairline-b`,children:[(0,Z.jsx)(`h2`,{children:e}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:t,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function xg(){return(0,Z.jsx)(`table`,{children:(0,Z.jsx)(`tbody`,{children:km().map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:(0,Z.jsx)(`kbd`,{children:e.keys})}),(0,Z.jsx)(`td`,{children:e.label})]},e.keys))})})}function Sg({rules:e,onClose:t}){let n=lg(e.fabrication),[r,i]=(0,l.useState)(n.value),[a,o]=(0,l.useState)(),s=(0,l.useId)(),c=async i=>{i.preventDefault();let a=ug(r);if(`message`in a)return o(a.message);if(r.trim()===n.value)return t();await e.save(a.radius)&&t()};return(0,Z.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void c(e),children:[(0,Z.jsx)(`label`,{htmlFor:s,children:sg}),(0,Z.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,Z.jsx)(`p`,{id:`${s}-note`,children:a??cg}),(0,Z.jsx)(`p`,{children:`The rest of the design rules are in rules.yaml in the project.`}),(0,Z.jsx)(`button`,{type:`submit`,children:`Save`})]})}function Cg({panel:e,onClose:t}){let n=e=>()=>{t(),e()};return(0,Z.jsxs)(`div`,{className:`rules-form`,children:[(0,Z.jsx)(`p`,{children:e.question}),(0,Z.jsx)(`button`,{type:`button`,"data-default":!0,onClick:n(e.showChecks),children:`Show checks`}),(0,Z.jsx)(`button`,{type:`button`,onClick:n(e.exportAnyway),children:`Export anyway`})]})}function wg({name:e,onClose:t,rules:n,makeSheet:r,importPart:i,newPart:a,system:o,newCircuit:s,footprints:c,exportChecks:l}){return e===`exportChecks`?(0,Z.jsx)(bg,{title:`Fabrication files`,onClose:t,children:(0,Z.jsx)(Cg,{panel:l,onClose:t})}):e===`footprints`?(0,Z.jsx)(bg,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,Z.jsx)(Wh,{panel:c,onClose:t})}):e===`newCircuit`?(0,Z.jsx)(bg,{title:`New circuit`,onClose:t,children:(0,Z.jsx)(Rh,{panel:s,onClose:t})}):e===`system`?(0,Z.jsx)(bg,{title:`System settings`,onClose:t,children:(0,Z.jsx)(Nh,{panel:o,onClose:t})}):e===`newPart`?(0,Z.jsx)(bg,{title:`New part`,onClose:t,wide:!0,children:(0,Z.jsx)(ah,{what:`New part`,onRetry:_g.retry,render:()=>{let e=_g.component();return(0,Z.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,Z.jsx)(bg,{title:`Import by LCSC number`,onClose:t,children:(0,Z.jsx)(Rm,{panel:i,onClose:t})}):e===`makeSheet`?(0,Z.jsx)(bg,{title:`Make sub-sheet`,onClose:t,children:(0,Z.jsx)(th,{panel:r,onClose:t})}):e===`rules`?(0,Z.jsx)(bg,{title:`Design rules`,onClose:t,children:(0,Z.jsx)(Sg,{rules:n,onClose:t})}):e===`keys`?(0,Z.jsx)(bg,{title:`Keys`,onClose:t,children:(0,Z.jsx)(xg,{})}):(0,Z.jsxs)(bg,{title:`About copperflow`,onClose:t,children:[(0,Z.jsxs)(`p`,{children:[(0,Z.jsx)(`strong`,{children:`copperflow`}),` Studio`]}),(0,Z.jsx)(`p`,{children:`Design circuits in code with a human and an AI agent editing the same files.`}),(0,Z.jsx)(`p`,{children:`Apache License 2.0`})]})}function Tg(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 Eg({label:e,shortcut:t,menu:n,index:r,enabled:i,checked:a,reason:o,onActivate:s}){return(0,Z.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=!Ap(e);t||Mp(e),i&&s(t)},children:[(0,Z.jsx)(`span`,{children:e}),t&&(0,Z.jsx)(`kbd`,{children:t})]})}function Dg(e,t,n){(0,l.useEffect)(()=>{if(!e)return;let r=e=>{e.target instanceof Node&&t.current?.contains(e.target)||n()};return window.addEventListener(`pointerdown`,r,!0),()=>window.removeEventListener(`pointerdown`,r,!0)},[e,t,n])}var Og=(e,t)=>(e+t)%t,kg=e=>e===`item`||e===`disabled`;function Ag(e,t,n,r=kg){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=Og(a+n,i),r(e[a]))return a;return null}var jg=e=>e?Ag(e,null,1):null,Mg=e=>e?Ag(e,null,-1):null,Ng=(e,t)=>e?Ag(e,null,t,e=>e===`item`)??Ag(e,null,t):null,Pg=e=>Ng(e,1),Fg=e=>Ng(e,-1),Ig=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),Lg=(e,t)=>Ig(e,{menu:e,item:t});function Rg(e,t,n,r){let i=r.length,a={ArrowLeft:Og(t-1,i),ArrowRight:Og(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?Lg(t,Pg(r[t])):e===`ArrowUp`?Lg(t,Fg(r[t])):n===null?null:e===`Escape`?Ig(null,{menu:t,item:null}):e===`Tab`?Ig(null,`keep`,!1):null:Ig(n===null?null:a,{menu:a,item:null})}function zg(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:Ag(r,t.item,1),ArrowUp:Ag(r,t.item,-1),Home:jg(r),End:Mg(r)};if(e in a)return Lg(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=Og(t.menu+(e===`ArrowLeft`?-1:1),i);return Lg(r,Pg(n[r]))}return e===`Escape`?Ig(null,{menu:t.menu,item:null}):e===`Tab`?Ig(null,{menu:t.menu,item:null},!1):null}function Bg(e,t,n){return e===`Escape`?Ig(null,`keep`):e===`Tab`?Ig(null,`keep`,!1):e===`ArrowDown`||e===`Home`?Lg(t,Pg(n[t])):e===`ArrowUp`||e===`End`?Lg(t,Fg(n[t])):e===`ArrowLeft`||e===`ArrowRight`?Ig(Og(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function Vg(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:Bg(e,n,r):t.item===null?Rg(e,t.menu,n,r):zg(e,{menu:t.menu,item:t.item},r)}function Hg(e){return Pg(e)}var Ug=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function Wg(e,t){let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-menu]`):null;if(!n)return null;let r=n.dataset.item;return{menu:Number(n.dataset.menu),item:r===void 0?null:Number(r)}}function Gg(e){let t=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(Ug(n))?.focus())}),(0,l.useCallback)(n=>{let r=e.current?.querySelector(Ug(n));r?r.focus():t.current=n},[e])}function Kg({entry:e,menu:t,index:n,view:r,selected:i,off:a,toggles:o,onRun:s}){if(e===`separator`)return(0,Z.jsx)(`li`,{className:`menu-separator`,role:`separator`});let{label:c,shortcut:l,command:u,toggle:d}=e,{enabled:f,reason:p}=Em(e,r,i,a);return(0,Z.jsx)(`li`,{role:`none`,children:(0,Z.jsx)(Eg,{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 qg({menu:e,index:t,view:n,selected:r,off:i,toggles:a,onRun:o}){return(0,Z.jsx)(`ul`,{className:`menu-dropdown`,role:`menu`,"aria-label":e.title,children:e.entries.map((e,s)=>(0,Z.jsx)(Kg,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function Jg({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,Z.jsxs)(`div`,{className:`menu`,children:[(0,Z.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(!Ap(e))return o({open:t,focus:{menu:t,item:Hg(jm(s,c,l)[t])},preventDefault:!0});Mp(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,Z.jsx)(qg,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function Yg({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,l.useReducer)(Am,{open:null}),[c,u]=(0,l.useState)(0),d=(0,l.useRef)(null),f=Gg(d),p=o.open===null?null:wm.findIndex(e=>e.title===o.open),m=(0,l.useMemo)(()=>jm(t,n,i),[t,n,i]),h=e=>{s({type:`set`,title:e.open===null?null:wm[e.open]?.title??null}),e.focus!==`keep`&&(u(e.focus.menu),f(e.focus))},g=e=>{let t=Vg(e.key,Wg(d.current,document.activeElement),p,m,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),h(t),!0):!1};vm(p!==null,e=>void g(e)),Dg(p!==null,d,(0,l.useCallback)(()=>s({type:`outside`}),[]));let _=(t,n,r)=>{r&&h({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{u(e),s({type:`click`,title:wm[e]?.title??``})},y=e=>s({type:`hover`,title:wm[e]?.title??``});return(0,Z.jsxs)(`header`,{className:`menubar hairline-b`,ref:d,children:[(0,Z.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,Z.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>g(e)&&e.stopPropagation(),children:wm.map((e,a)=>(0,Z.jsx)(Jg,{menu:e,index:a,open:p===a,current:c===a,onPointer:v,onHover:y,onKeyboard:h,view:t,selected:n,off:i,toggles:r,onRun:_},e.title))}),(0,Z.jsx)(`div`,{className:`menubar-end`,children:a})]})}var Xg=`Main`;function Zg(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[Xg]}function Qg(e,t){let n=Zg(e);return n.includes(t)?t:n[0]??`Main`}function $g(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 e_(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function t_(e,t){if(t===`Main`)return`${Xg} is the first page and cannot be deleted`;let n=e?.schematic.pages?.find(e=>e.name===t)?.parts??[];if(n.length>0)return`Page ${t} still has parts (${n.join(`, `)}); move or delete them first`;let r=e?.circuit.connections.filter(e=>e.page===t)??[];if(r.length===0)return;let i=r.map(e=>`${e.from.replace(/^net\./,``)} to ${e.to.replace(/^net\./,``)}`).join(`, `);return`${t} still has ${r.length===1?`1 trace`:`${r.length} traces`}: ${i}; move or remove ${r.length===1?`it`:`them`} first`}function n_(e){return e===`Main`?`${Xg} is the first page and keeps its name`:void 0}function r_(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 i_(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function a_({build:e,errors:t,onOpen:n}){return(0,Z.jsxs)(`button`,{className:`build ${i_(e,t)}`,onClick:e=>{Fp(e),n()},title:`Show DRC`,children:[(0,Z.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{role:`status`,children:r_(e,t)})]})}var o_=`light`,s_=`copperflow.theme`,c_=()=>typeof window>`u`?void 0:window.localStorage,l_=e=>e===`dark`||e===`light`?e:o_;function u_(e){try{return l_(e()?.getItem(s_))}catch{return o_}}function d_(e,t){try{let n=e();return n?(n.setItem(s_,t),!0):!1}catch{return!1}}function f_(e,t){e.setAttribute(`data-theme`,t)}var p_=e=>({themeLight:e===`light`,themeDark:e===`dark`}),m_=e=>e===`dark`?`dots`:`lines`,h_=(e,t,n)=>t===n?e:g_(e,n),g_=(e,t)=>({...e,schematic:m_(t)}),__=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),v_=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),y_=[__(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),__(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],b_=[__(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),__(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),__(`fit`,`Fit all (K)`,`fit`,`fit`,1),__(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),__(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],x_=e=>[__(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),__(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],S_=e=>[__(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),__(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],C_=e=>[__(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),__(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],w_=e=>__(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),T_={schematic:[...y_,...b_,...S_(2),__(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),__(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),__(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),__(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),__(`ground`,`Ground flag`,`ground`,`groundFlag`,3),__(`power`,`Power flag`,`power`,`powerFlag`,3),__(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),__(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),__(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),__(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),__(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),__(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...x_(5),...C_(6),w_(7)],pcb:[...y_,...b_,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...S_(2),__(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),v_(`boardOutline`,`Board outline`,`boardOutline`,Cm,3),v_(`copperArea`,`Copper area`,`copperArea`,Cm,3),w_(4),__(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...C_(6),...x_(7),__(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function E_(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=Sm(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function D_(e){let t=[];for(let n of T_[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var O_=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...x]);function k_(e){return O_.has(e)}var A_={snap:`snap`};function j_(e,t,n){let r=A_[e];return r?n[r]:t===e}function M_(e){return k_(e)||e in A_}function N_(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function P_(e){return e?S[e]:null}var F_={active:null,stop:null},I_=F_,L_=new Set;function R_(e){if(e.active!==I_.active||e.stop!==I_.stop){I_=e;for(let e of L_)e()}}function z_(){return I_}function B_(){R_(F_)}function V_(e){return L_.add(e),()=>{L_.delete(e)}}function H_(){return(0,l.useSyncExternalStore)(V_,z_)}function U_(e,t){return t.active===e&&t.stop?`stop`:`run`}var W_=o(),G_=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function K_(){let e=e=>e.stopPropagation();return Object.fromEntries(G_.map(t=>[t,e]))}var q_=`toolbar-view-slot`,J_=K_();function Y_({children:e}){let[t,n]=(0,l.useState)(null);return(0,l.useLayoutEffect)(()=>n(document.getElementById(q_)),[]),t?(0,W_.createPortal)((0,Z.jsx)(`div`,{className:`canvas-tools`,...J_,onClick:Fp,children:e}),t):null}function X_({item:e,unit:t}){if(e.text===`unit`)return(0,Z.jsx)(Z.Fragment,{children:t});let n=fm[e.icon];return(0,Z.jsx)(n,{})}function Z_({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=H_();return(0,Z.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[D_(e).map((e,s)=>(0,Z.jsxs)(l.Fragment,{children:[s>0&&(0,Z.jsx)(`span`,{className:`toolbar-separator`,role:`separator`,"aria-orientation":`vertical`}),e.map(e=>{let s=e.command!==void 0&&j_(e.command,o.active,r),c=E_(e,n,i);return(0,Z.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&&M_(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{Fp(t),c.enabled&&e.command!==void 0&&(U_(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,Z.jsx)(X_,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,Z.jsx)(`div`,{className:`toolbar-view-slot`,id:q_})]})}var Q_=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function $_(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function ev(e){return[Q_,...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($_).join(`,`)).join(`\r
14
- `)+`\r
15
- `}function tv(e){return`${(e.split(/[\\/]/).at(-1)??e).replace(/\.circuit\.tsx$|\.tsx$/,``)}-bom.csv`}function nv(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 rv=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function iv(e){let t=`Checks: ${rv(e.errors,`error`)}, ${rv(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 av=3;function ov(e){let t=e.slice(0,av).map(e=>`Warning: ${e}.`),n=e.length-av;return n>0?[...t,`And ${n} more ${n===1?`warning`:`warnings`}.`]:t}function sv(e){if(!e.written)return`No fabrication files written: ${e.errors.join(`; `)}`;let t=nv(e.zip,e.folder,e.files);return[`Wrote ${e.files.length} fabrication files to ${e.folder}/ and ${e.zip}.`,`U${t.slice(1)}.`,...ov(e.warnings),iv(e.checks)].join(` `)}function cv(e){return e.errors>0}var lv=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function uv(e){return`The design rule check reports ${lv(e.errors,`error`)} and ${lv(e.warnings,`warning`)}. Look at them before you order this board.`}var dv=1e-9,fv=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),pv=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),mv=(e,t)=>({x:e.x*t,y:e.y*t}),hv=(e,t)=>e.x*t.y-e.y*t.x,gv=(e,t)=>e.x===t.x&&e.y===t.y;function _v(e){return e.every((t,n)=>n===0||cc(e[n-1],t)!==`slanted`)}function vv(e){let t=e.map(e=>({x:V(e.x),y:V(e.y)})),n=t.filter((e,n)=>n===0||!gv(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(hv(fv(t,i),fv(a,t)))<dv||r.push(t)}return r}function yv(e,t,n,r){let i=hv(t,r);if(!(Math.abs(i)<dv))return pv(e,mv(t,hv(fv(n,e),r)/i))}function bv(e,t,n){let[r,i]=[e[t],e[t+1]],a=fv(i,r),o=pv(r,n),s=(r,i)=>{let s=e[r],c=e[i],l=c&&yv(c,fv(s,c),o,a);return l?[l]:r===t?[s,pv(s,n)]:[pv(s,n),s]},c=t===0?[r,o]:s(t,t-1),l=t+1===e.length-1?[pv(i,n),i]:s(t+1,t+2);return[...e.slice(0,t),...c,...l,...e.slice(t+2)]}function xv(e,t,n,r){let i={x:ge(e.x+n.x,r.step,r.snap),y:ge(e.y+n.y,r.step,r.snap)},a=fv(t,e),o=Math.hypot(a.x,a.y);if(o<dv)return{x:0,y:0};let s={x:-a.y/o,y:a.x/o};return mv(s,(i.x-e.x)*s.x+(i.y-e.y)*s.y)}function Sv(e,t,n,r){let i=e[t],a={x:ge(i.x+n.x,r.step,r.snap),y:ge(i.y+n.y,r.step,r.snap)};return e.map((e,n)=>n===t?a:e)}function Cv(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=_v(e)?al(e,t,n,r):t.kind===`corner`?Sv(e,t.index,n,r):bv(e,t.index,xv(i,a,n,r));let s=vv(o);return s.length>=2?s:[...e]}var wv=e=>Math.max(e.length-1,0),Tv=(e,t)=>Number.isInteger(t)&&t>=0&&t<wv(e),Ev=e=>e.map(e=>({x:e.x,y:e.y}));function Dv(e,t){let n=wv(e.points);if(!Tv(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:Ev(r)};return i?{edits:[s,{kind:`addTrack`,...o,layer:e.layer,width:e.width,points:Ev(i)}]}:{edits:[s]}}var Ov={tracks:new Map,vias:new Map},kv=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Av=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),jv=(e,t)=>Math.hypot(t.x-e.at.x,t.y-e.at.y)<=e.diameter/2;function Mv(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&&jv(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 Nv(e,t,n,r,i){let a=t=>r.some(e=>jv(e,t))||!i(t,e.layer)&&!n.some(e=>jv(e,t)),[o,s]=[e.points[0],e.points.at(-1)];return vv(_c(e.points,t,{start:a(o),end:a(s)}))}function Pv(e,t,n){let r=e.points.length-1,i=(e,t)=>(t===0||t===r)&&n.some(t=>jv(t,e));return e.points.some(i)?vv(e.points.map((e,n)=>i(e,n)?kv(e,t):e)):e.points}function Fv(e,t,n,r){let i=[];if(n.x===0&&n.y===0)return{edits:[],shapes:Ov,skipped:i};let a=new Set(t),o=Mv(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?Nv(t,n,e.vias,o,r):Pv(t,n,o);!Av(c,t.points)&&c.length>=2&&s.set(t.id,c)}let c=new Map(o.map(e=>[e.id,kv(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 Iv(e,t){if(!Av(t,e.points))return e.locked?{message:`${e.id} is locked`}:{kind:`setTrack`,id:e.id,points:[...t]}}function Lv(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 Rv(e,t){if(!e)return{message:`${t.id} is gone`};if(!Ca(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=Dv({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 zv(e,t){return{tracks:new Map([...e.tracks,...t.tracks]),vias:new Map([...e.vias,...t.vias])}}function Bv(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 Vv(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`} ${Qe([...i,...a].map(e=>e.id))}`}}function Hv(e,t){return!t&&e.copper.length>0&&e.total===e.copper.length}function Uv(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):void 0}var Wv=e=>/(^|\/)hole:\d+$/.test(e);function Gv(e,t,n){return`${e} is a ${Wv(e)?`hole`:`copper pour`} inside the sub-sheet instance ${t}; edit ${n??`its sheet file`} instead`}var Kv=(e,t)=>e.x===t.x&&e.y===t.y,qv=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);function Jv(e,t,n,r){let[i,a,o,s]=[qv(n,r,e),qv(n,r,t),qv(e,t,n),qv(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 Yv(e){let t=e.length;if(t<3)return`an outline needs at least 3 corners`;if(e.some((n,r)=>Kv(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(Jv(i,a,o,s))return`two of its edges cross`}let n=e.reduce((n,r,i)=>n+qv({x:0,y:0},r,e[(i+1)%t]),0);return Math.abs(n)<1e-9?`its corners are all on one line, so it has no area`:void 0}function Xv(e,t){return`${t}:${e.filter(e=>e.tag===t).length+1}`}var Zv=3.2,Qv=100,$v=e=>({tool:e,points:[]}),ey=(e,t)=>e.x===t.x&&e.y===t.y,ty=e=>({state:e});function ny(e){return e.filter((t,n)=>n===0||!ey(t,e[n-1]))}function ry(e){let t=ny(e.points);if(t.length>=3&&t.at(-1)&&ey(t[0],t.at(-1))&&t.pop(),t.length<3)return ty(e);let n=Yv(t);return n?{state:e,refused:`Not closed: ${n}`}:{state:$v(e.tool),outline:t}}function iy(e,t,n){if(e.tool===`hole`)return{state:e,hole:t};if(n&&e.points.length>0)return ry(e);let r=e.points[0];return r&&e.points.length>=3&&ey(r,t)?ry(e):ty({...e,points:ny([...e.points,t])})}function ay(e,t){switch(t.type){case`press`:return iy(e,t.at,t.double);case`finish`:return e.tool===`pour`?ry(e):ty(e);case`removeCorner`:return ty({...e,points:e.points.slice(0,-1)});case`cancel`:return{state:e.points.length>0?$v(e.tool):null}}}function oy(e,t){return!e||e.tool!==`pour`||e.points.length===0?[]:t?ny([...e.points,t]):[...e.points]}function sy(e){let t=e.circuit.nets.flatMap(e=>e.names);return t.includes(`GND`)?`GND`:t[0]}function cy(e,t,n){return{kind:`addPour`,net:e,layer:t,...n?{outline:[...n]}:{}}}var ly=(e,t,n)=>`add a ${e} copper pour on the ${t} layer${n?` over the whole board`:``}`;function uy(e,t){return{kind:`addHole`,x:e.x,y:e.y,diameter:t}}var dy=e=>`add a ${e} mm hole`;function fy(e){let t=Number(e.trim().replace(/\s*mm$/i,``));return e.trim()===``||!Number.isFinite(t)||t<=0||t>Qv?{message:`The diameter must be a number of mm above 0 and at most ${Qv}`}:Math.round(t*1e3)/1e3}function py(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=Yv(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 my(e,t,n){let r=Uv(n);if(r!==void 0)return Gv(n,r,Hm({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 hy=e=>Number(e.slice(e.indexOf(`:`)+1)),gy=e=>e.tag===`hole`?`hole ${hy(e.id)}`:`copper pour ${hy(e.id)}`;function _y(e,t){return n=>{let r=n.map(n=>({id:n,blocker:my(e,t,n)})),i=r.flatMap(e=>e.blocker===null?[e.id]:[]);return{edits:[...i].sort((e,t)=>hy(t)-hy(e)).map(e=>Wv(e)?{kind:`removeHole`,id:e}:{kind:`removePour`,id:e}),names:i.flatMap(t=>e.boardItems?.find(e=>e.id===t)??[]).map(gy),skipped:r.flatMap(e=>e.blocker??[]),removed:i}}}var vy=`Esc or a right click stops.`;function yy(e){if(e)return e.tool===`hole`?`Click where the hole goes; set its diameter in the field. ${vy}`:e.points.length===0?`Click the first corner of the copper pour. ${vy}`:`Click for each corner; double click, Enter or a click on the first corner closes the pour. Backspace removes a corner, Esc cancels.`}var by=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}],xy=[{value:`inner1`,label:`Inner Layer 1`},{value:`inner2`,label:`Inner Layer 2`}],Sy=[{value:`relief`,label:`Relief (spokes)`},{value:`solid`,label:`Solid`}],Cy=e=>String(Number(e.toFixed(4))),wy=e=>e===void 0?`Not filled`:`${e.toFixed(2)} mm²`;function Ty(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:Vl(e,t.net),field:`net`,choices:n},{label:`Layer`,value:t.layer,field:`layer`,choices:e.pcb.board?.layers===4?[...by,...xy]:by},{label:`Priority`,value:String(t.priority),field:`priority`},{label:`Clearance (mm)`,value:t.clearance===void 0?``:Cy(t.clearance),field:`clearance`},{label:`Min width (mm)`,value:Cy(t.minWidth),field:`minWidth`},{label:`Thermal`,value:t.thermal,field:`thermal`,choices:Sy},{label:`Outline`,value:t.outline?`${t.outline.length} corners`:`Whole board`},{label:`Fill area`,value:wy(r?.area)}]}function Ey(e){return[{label:`X (mm)`,value:Cy(e.x),field:`x`},{label:`Y (mm)`,value:Cy(e.y),field:`y`},{label:`Diameter (mm)`,value:Cy(e.diameter),field:`diameter`}]}function Dy(e,t){let n=zl(e).find(e=>e.id===t);if(n)return{kind:`pour`,title:`Copper pour`,rows:Ty(e,n)};let r=e.pcb.holes.find(e=>e.id===t);return r&&{kind:`hole`,title:`Hole`,rows:Ey(r)}}function Oy(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 ky(e,t){return e===`net`||e===`layer`||e===`thermal`?t:e===`clearance`&&t.trim()===``?null:Oy(t,e,e===`priority`?`whole`:`positive`)}function Ay(e,t){return e===`diameter`?fy(t):Oy(t,e,`any`)}function jy(e,t,n,r){let i=Dy(e,t)?.rows.find(e=>e.field===n);if(!i||i.value===r.trim())return;let a=Wv(t),o=a?Ay(n,r):ky(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 My(e,t){let n=Wv(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 Ny(e,t,n,r=new Set){return mt([...e.names,...e.board],t,n,r)}var Py=.5,Fy=e=>Math.round(e*1e3)/1e3||0,Iy=e=>e.pcb??{x:0,y:0,rotation:0};function Ly(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=>Hy(Vy(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 Ry=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function zy(e,t,n,r){let i=[t,...n].filter(e=>!r(e.name)).map(e=>e.name);if(i.length>0)return`Place ${i.join(`, `)} on the board first (pcbX and pcbY on the instance), then replicate the layout.`;let a=Gy(e,t);if(!a)return;let o=[t,...n].map(e=>({name:e.name,box:Ly(a,Iy(t),Iy(e))}));for(let[e,t]of o.entries()){let n=o.slice(e+1).find(e=>Ry(t.box,e.box));if(n)return`${t.name} and ${n.name} would overlap; place the instances apart first, then replicate the layout.`}}function By(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 Vy=(e,t)=>By({x:e.x-t.x,y:e.y-t.y},-t.rotation),Hy=(e,t)=>{let n=By(e,t.rotation);return{x:Fy(n.x+t.x),y:Fy(n.y+t.y)}};function Uy(e,t){let n=cn(e,t)?.pcb;return n!==void 0&&(n.x!==0||n.y!==0)}function Wy(e,t){for(let n of t){let t=cn(e,n)??cn(e,ln(e,n)?.outer??``);if(t)return t}}function Gy(e,t){let n=new Set(t.parts),r=e.pcb.parts.filter(e=>n.has(e.component)).flatMap(e=>e.courtyard);if(r.length===0)return;let i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i)-Py,maxX:Math.max(...i)+Py,minY:Math.min(...a)-Py,maxY:Math.max(...a)+Py}}function Ky(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 qy(e,t,n,r,i=[]){if(n?.startsWith(`net.${t.path}/`))return!0;let a=new Set(t.parts);if(i.length>0&&i.every(e=>a.has(e.split(`#`)[0]??``)))return!0;let o=Gy(e,t);return o!==void 0&&r.every(e=>e.x>=o.minX&&e.x<=o.maxX&&e.y>=o.minY&&e.y<=o.maxY)}function Jy(e,t,n){let r=ln(e,t)?.localId;return e.circuit.components.find(e=>e.instance===n.path&&e.localId===r)?.id}function Yy(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:Jy(e,n,r);return a&&i?`net:${a}.${i}`:void 0}let i=t.replace(/^net\./,``),a=n.ports.find(e=>!e.bus&&e.net===i),o=a&&r.ports.find(e=>e.name===a.name);return o?`net.${o.net}`:t}function Xy(e,t){let n=Iy(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=Vy(i,n),o=((i.rotation-n.rotation)%360+360)%360,s={pcbX:Fy(a.x),pcbY:Fy(a.y),...o===0?{}:{pcbRotation:Fy(o)}};return[{kind:`setProps`,part:r.localId,props:s}]})}function Zy(e,t,n,r){let i=t.tracks.filter(t=>qy(e,n,t.net,t.points,t.pads)),a=t.vias.filter(t=>qy(e,n,t.net,[t.at])),o=Iy(n);return r.flatMap(r=>{let s=Iy(r),c=e=>Hy(Vy(e,o),s),l=t=>{let i=Yy(e,t,n,r);return i===void 0?{}:{net:i}},u=[...t.tracks.filter(e=>Ky(r,e.net,e.pads)).map(e=>({kind:`removeTrack`,id:e.id})),...t.vias.filter(e=>Ky(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 Qy(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 $y(e,t,n,r=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let i=Wy(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=Qy(i,a,r);if(o)return{message:o};let s=zy(e,i,a,n??(t=>Uy(e,t)));if(s)return{message:s};let c=a.map(e=>e.name).join(`, `),l={file:i.file,edits:Xy(e,i),summary:`Replicate the placement of ${i.name} in ${i.sheet}`},u={edits:Zy(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 eb={toggleUnit:`toggleUnit`,gridStyle:`toggleGridStyle`,snap:`toggleSnap`,toggleLeftPanel:`toggleLeftPanel`,toggleRightPanel:`toggleRightPanel`,toggleBottomPanel:`toggleBottomPanel`,clearHighlight:`clearHighlight`,placeComponent:`openLibrary`};[...g];var tb=[`wire`,`netLabel`,`groundFlag`,`powerFlag`,...x],nb=[`noConnect`,`junction`],rb=[`singleRouting`,`placeVia`,`routingCorner`],ib=[`placePour`,`placePourBoard`,`placeHole`],ab=[`filletTracks`,`straightenTracks`],ob=new Set;function sb(e){return ob.add(e),()=>{ob.delete(e)}}function cb(e){for(let t of ob)if(t(e))return!0;return!1}function lb(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>sb(e=>{let n=t.current[e];return n?(n(),!0):!1}),[])}var ub=(e,t)=>e.by===`router`&&!e.locked&&(t===void 0||t.has(e.id)),db=1e-6;function fb(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 pb(e,t){if(t.at===void 0||t.diameter===void 0)return!1;let n=t.diameter/2+(e.width??0)/2+db,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&&fb(r,e.points[i-1],t)<=n)}function mb(e,t={}){let n=t.ids===void 0?void 0:new Set(t.ids),r=[],i=e.tracks.filter(e=>{if(!ub(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(!ub(e,n))return!1;let t=a.some(t=>pb(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 hb=[`top`,`bottom`,`inner1`,`inner2`],gb=({x0:e,x1:t,y0:n,y1:r})=>Math.max(0,t-e+1)*Math.max(0,r-n+1),_b=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);gb(n)>4096?this.wide.push(e):vb(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 gb(t)>4096?this.cells.forEach(r):vb(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 vb({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 yb=[`top`,`inner1`,`inner2`,`bottom`],bb=1e-9,xb=(e,t)=>e.layers===`through`||e.layers===t,Sb=e=>({core:[e],radius:0});function Cb(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 wb(e){let t=e.layers.map(e=>yb.indexOf(e));return new Set(yb.slice(Math.min(...t),Math.max(...t)+1))}function Tb(e,t,n){return t!==void 0&&li(t,Sb(n))<=bb}function Eb(e,t,n){return e.flatMap(e=>e.pads.filter(e=>xb(e,n)&&Tb(e,$r(e),t)))}function Db(e,t){return li(e,t)<=bb}function Ob(e,t){if(t.length===0)return{message:`Select parts, or a sub-sheet instance, to route their connections.`};let n=t.length===1?cn(e,t[0]):void 0;if(n)return{kind:`instance`,instance:n.path};let r=new Set(t.map(t=>ln(e,t)?.outer)),[i]=r;if(r.size===1&&i!==void 0){let n=un(e,i);if(n.length===t.length&&n.every(e=>t.includes(e)))return{kind:`instance`,instance:i}}return{kind:`parts`,parts:[...t]}}function kb(e){return e.length===0?{message:`Click a net in the Nets panel to highlight it, then Autoroute net.`}:{kind:`nets`,nets:[...e]}}function Ab(e,t,n=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let r=hn(n,e),i=t=>{let n=t.points[0];return n===void 0?void 0:Eb(e.pcb.parts,n,t.layer).find(e=>r.has(e.component))?.component},a=t.length===0?void 0:t,{edits:o,skipped:s}=mb(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 jb(e,t){if(t.length===0)return{message:`Select the parts to place first.`};let n=t.flatMap(t=>cn(e,t)?.parts??[t]);return{kind:`parts`,parts:[...new Set(n)]}}function Mb(e,t){for(let n of t){let t=cn(e,n)?.path??ln(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 Nb(e,t,n){let r=e.ask(t,n)?.trim();return r===void 0||r===``?void 0:r}async function Pb(e){let t=Nb(e,`Name of the new page`,e_(Zg(e.design)));t!==void 0&&await e.edit([{kind:`addPage`,name:t}],`add page ${t}`)&&e.openPage(t)}async function Fb(e){let t=n_(e.page);if(t)return e.notify(t);let n=Nb(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 Ib(e){let t=t_(e.design,e.page);if(t)return e.notify(t);let n=Zg(e.design).indexOf(e.page),r=Zg(e.design)[Math.max(0,n-1)]??`Main`;await e.edit([{kind:`removePage`,name:e.page}],`delete page ${e.page}`)&&e.openPage(r)}function Lb(e,t){return e===`addPage`?Pb(t):e===`renamePage`?Fb(t):Ib(t)}function Rb(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 zb(e){let t=nn(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 Bb(e){let t=[...Ts(e).map(e=>e.box),..._d(e).map(e=>e.box)];t.push(...e.labels.map(yr),...e.drawings.map(zb));let n=ye([...e.wires.flatMap(e=>e.points),...e.junctions]);return n&&t.push(n),be(t)}var Vb=()=>W(`light`).background,Hb={width:297,height:210,margin:10};function Ub(){return{width:(Hb.width-2*Hb.margin)*8,height:(Hb.height-2*Hb.margin-Wb)*8}}var Wb=8;function Gb(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function Kb(e){let t={width:Hb.width-2*Hb.margin,height:Hb.height-2*Hb.margin},n={width:t.width,height:t.height-Wb};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">${Gb(e.title)}</text>`,`<image x="0" y="${Wb}" width="${n.width}" height="${n.height}" preserveAspectRatio="xMidYMid meet" href="${Gb(e.image)}" />`,`<rect x="0" y="${Wb}" width="${n.width}" height="${n.height}" fill="none" stroke="currentColor" stroke-width="0.2" />`,`</svg>`].join(``)}function qb(e,t){let n=t.map(e=>`<section class="sheet">${Kb(e)}</section>`).join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${Gb(e)}</title>`,`<style>`,`@page { size: A4 landscape; margin: ${Hb.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 Jb=.04;function Yb(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 Xb(e,t,n){let r=$g(e,t).schematic,i=Bb(r),a=W(`light`),o=i&&Yb(n,a.background);if(i&&o)return Va(a),ws(o.ctx,r,{camera:fe(i,n,Jb),size:n},{ratio:1}),o.canvas.toDataURL(`image/png`)}function Zb(e,t){let n=e.pcb,r=ye(n.board?.outline??[])??be(n.parts.map(e=>({minX:e.x-1,minY:e.y-1,maxX:e.x+1,maxY:e.y+1}))),i=r&&Yb(t,Vb());if(!r||!i)return;let a=fe(r,t,Jb);return tf(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 Qb(e,t,n=l_(document.documentElement.getAttribute(`data-theme`))){let r=Ub(),i=[];try{for(let n of Zg(e)){let a=Xb(e,n,r);a&&i.push({title:`${t} · Schematic · ${n}`,image:a,...r})}}finally{Va(W(n))}let a=Zb(e,r);return a&&i.push({title:`${t} · PCB`,image:a,...r}),i}function $b(e,t){let n=window.open(``,`_blank`);return n?(n.document.open(),n.document.write(qb(e,t)),n.document.close(),n.focus(),n.setTimeout(()=>n.print(),0),!0):!1}var ex=12.7,tx=e=>Math.round(e*1e3)/1e3+0;function nx(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 rx(e,t,n){let r=[],i=[];for(let a of e){let e=nx(a,t,n);e===void 0?r.push(a):i.push(`${a} (${e})`)}return{ok:r,skipped:i}}var ix=e=>e.length===0?``:`; left ${e.join(`, `)}`;function ax(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}=rx(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:tx(r.x),pcbY:tx(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}${ix(o)}`,skipped:o}}var ox=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length});function sx(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=ox(t).y;for(let e of t)n.set(e.component,{x:r+(e.x-a)*ex,y:(e.y-s)*ex});r+=(o-a)*ex+10}let i=ox([...n.values()]);return new Map([...n].map(([e,t])=>[e,{x:t.x-i.x,y:t.y-i.y}]))}function cx(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}=rx(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=sx(c),u=ox(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:tx(u.x+t.x),pcbY:tx(u.y+t.y),...n}}}),summary:`place ${o.length===1?o[0]:`${o.length} parts`} as on the schematic${ix(s)}`,skipped:s}}var lx=(e,t)=>e.kind===t.kind&&e.footprint===t.footprint&&e.value===t.value;function ux(e,t,n,r){let i=t.find(t=>t.id===e.parts[0]);if(i){let e=t.filter(e=>lx(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 dx=/^([A-Za-z_]+)(\d+)$/;function fx(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 px(e,t){let n=new Set(t.filter(e=>!e.renamable).map(e=>Number(dx.exec(e.name)?.[2]))),r=1;return[...t].filter(e=>e.renamable).sort(fx).map(t=>{for(;n.has(r);)r++;return{from:t.name,to:`${e}${r++}`}})}function mx(e){let t=new Map;for(let n of e){let e=dx.exec(n.name)?.[1];e!==void 0&&t.set(e,[...t.get(e)??[],n])}let n=[...t].flatMap(([e,t])=>px(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 hx={sch:.5,pcb:2.54},gx=new Set([`name`,`pinLabels`]),_x=new Set([`from`,`to`,`schematicRouteHints`]),vx=/(pin\d+)\s*:\s*["']([A-Za-z_][\w]*)["']/g;function yx(e){if(!e)return;let t=Object.fromEntries([...e.matchAll(vx)].map(e=>[e[1],e[2]]));return Object.keys(t).length>0?t:void 0}function bx(e){let t=e===void 0?void 0:Rt(e);return t?t.kind===`net`?void 0:t.part:null}var xx=e=>e.slice(0,e.lastIndexOf(`/`)+1);function Sx(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))gx.has(e)||(r.literal===void 0?o.push(`${t.name}.${e}`):n[e]=r.literal);let r=yx(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=[bx(e.from),bx(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])=>_x.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:xx(n),anchor:wx(s)}}var Cx=(e,t)=>t===void 0?void 0:e.startsWith(`pcb`)?Kr(t):typeof t==`number`?t:void 0;function wx(e){let t=(t,n)=>{let r=e.flatMap(e=>{let[r,i]=[Cx(t,e.props[t]),Cx(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 Tx=/^([A-Za-z_]+?)(\d+)$/;function Ex(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=Tx.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 Dx=e=>Math.round(e*1e4)/1e4+0;function Ox(e,t,n){let r=e=>({x:e*n,y:-e*n}),i={sch:r(hx.sch),pcb:r(hx.pcb)},a=t?e.anchor[t.view]:void 0;return!t||!a?i:{...i,[t.view]:{x:Dx(t.at.x-a.x),y:Dx(t.at.y-a.y)}}}function kx(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=Cx(e,t);return i===void 0?t:Dx(i+r)}function Ax(e,t){let n=Rt(e);return n?.kind===`pin`?`${t.get(n.part)??n.part}.${n.pin}`:e}function jx(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`}:xx(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 Mx(e,t,n={}){let r=[...t.parts.map(e=>e.name),...t.drawings.flatMap(e=>[e.id,e.name??``]),...n.taken??[]],i=Ex(e.parts.map(e=>e.name),r),a=n.page,o=a===void 0||a===`Main`?{}:{page:a},s=n.shift??Ox(e,void 0,1),c=[];for(let r of e.parts){let a=jx(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,kx(e,t,s)])),...r.pinLabels?{pinLabels:r.pinLabels}:{},...a?{importFrom:a}:{},...o})}let l=e.traces.map(e=>({kind:`addTrace`,from:Ax(e.from,i),to:Ax(e.to,i),...Object.keys(e.props).length>0?{props:e.props}:{},...e.hints?{schematicRouteHints:e.hints.map(e=>({x:Dx(e.x+s.sch.x),y:Dx(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 Nx={};function Px(e,t){t?Nx[e]=t:delete Nx[e]}function Fx(e){return Nx[e]}var Ix=e=>new Set(e?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));function Lx(e,t){if(`message`in t)return e.notify(t.message);e.edit(t.edits,t.summary)}function Rx({design:e,circuit:t,selection:n,actions:r}){e&&t&&Lx(r,ax(n.names,e.pcb.parts,t.model.parts,Ix(t)))}function zx({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)));Lx(r,cx(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,Ix(t)))}function Bx({design:e,circuit:t,actions:n}){if(!e||!t)return;let r=Ix(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=mx([...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 Vx,Hx=0;function Ux({circuit:e,selection:t,actions:n}){if(!e)return;let r=Sx(e.model,t.names,e.file);if(`message`in r)return n.notify(r.message);Vx=r,Hx=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 Wx({design:e,circuit:t,select:n,actions:r},i,a){if(!t)return;if(!Vx)return r.notify(`Copy some parts first (Ctrl+C).`);let o=Fx(a),s=Ox(Vx,o?{view:a,at:o}:void 0,Hx+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=Mx(Vx,t.model,{file:t.file,...i?{page:i}:{},taken:l,shift:s});if(`message`in u)return r.notify(u.message);Hx+=1;let{edits:d,summary:f,names:p}=u;r.edit(d,f).then(e=>{e&&(n(()=>Ea.none.all(p)),r.notify(`Pasted ${p.join(`, `)}`))})}function Gx({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=ux({parts:n.names,drawings:n.drawings,board:n.board},a,e.schematic.drawings,o);if(`message`in s)return i.notify(s.message);r(()=>Ea.none.all(s.parts).addDrawings(s.drawings).addBoard(s.board??[])),i.notify(s.note)}var Kx=new Set([...tb,...nb]),qx=new Set([...rb,...ab,...ib]),Jx=e=>Kx.has(e)?`schematic`:qx.has(e)?`pcb`:void 0,Yx=eb;function Xx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.route(t)}function Zx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.autoplace(t)}function Qx(e){let t=new Set(e.circuit?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part)),n=Ab(e.design,e.selection.copper,t);if(`message`in n)return e.actions.notify(n.message);e.actions.unroute(n.ids)}function $x(e,t){let{design:n,page:r,actions:i,openPage:a}=e;Lb(t,{design:n,page:r,edit:i.edit,notify:i.notify,ask:(e,t)=>window.prompt(e,t),openPage:a})}function eS(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 tS(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=Qb(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(!$b(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 nS(e){if(e.file){if(cv(e.checkCounts))return e.openDialog(`exportChecks`);rS(e.file,e.actions)}}function rS(e,t){e&&(t.notify(`Writing the fabrication files…`),z(`/api/export`,{file:e}).then(e=>t.notify(sv(e))).catch(e=>t.notify(e.message)))}var iS=1e6;function aS(e){let t=Object.assign(document.createElement(`input`),{type:`file`,accept:`.dxf`});t.addEventListener(`change`,()=>{let n=t.files?.[0];if(n){if(n.size>iS)return e.notify(`${n.name} is larger than 1 MB; import it with the agent's import_board or copperflow board --dxf`);n.text().then(t=>e.importBoard(n.name,t)).catch(t=>e.notify(t.message))}}),t.click()}function oS(e,t){e&&z(`/api/bom?file=${encodeURIComponent(e)}`).then(n=>{let r=URL.createObjectURL(new Blob([ev(n)],{type:`text/csv`}));Object.assign(document.createElement(`a`),{href:r,download:tv(e)}).click(),URL.revokeObjectURL(r),t.notify(`Saved ${tv(e)}`)}).catch(e=>t.notify(e.message))}function sS(e,t){let{copper:n}=e.selection;if(n.length>0&&e.copperRecords){let r=Vv(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}cS(e,t)}function cS(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=Ny(e.selection,n,t,r);if(`message`in i)return e.actions.notify(i.message);e.actions.lock(i.parts,t)}function lS(e){let t=pn(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=>cn(e.design,t)?.path??ln(e.design,t)?.outer??[]):t;e.select(e=>e.all([...new Set(n)]))}async function uS(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=$y(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 dS(e){let t=Gm(e.circuit?.model,e.selection.names);if(`message`in t)return e.actions.notify(t.message);e.openDialog(`makeSheet`)}function fS(e,t){let n=Yx[t];return n?()=>e.workspace.run(n):{openFile:e.workspace.openPageTree,exportBom:()=>oS(e.file,e.actions),exportPackage:()=>eS(e.file,e.actions),exportFabrication:()=>nS(e),undo:()=>void e.actions.undo(),redo:()=>void e.actions.redo(),selectAll:()=>e.select(aa(e.circuit?.model.parts.map(e=>e.name)??[],e.pickLayers,e.pickFilter,e.sheetWires,e.sheetLabels,e.sheetDrawings,e.pcbCopper)),selectInstance:()=>lS(e),replicateLayout:()=>void uS(e),makeSheet:()=>dS(e),find:e.openFind,checkDrc:e.openChecks,designRules:()=>e.openDialog(`rules`),autoplace:()=>Zx(e,{kind:`all`}),autoplaceSelection:()=>Zx(e,jb(e.design,e.selection.names)),autoplaceInstance:()=>Zx(e,Mb(e.design,e.selection.names)),fitBoard:()=>void e.actions.fitBoard(),importBoardDxf:()=>aS(e.actions),autoroute:()=>Xx(e,{kind:`all`}),autorouteSelection:()=>Xx(e,Ob(e.design,e.selection.names)),autorouteNet:()=>Xx(e,kb(e.highlight)),unroute:()=>Qx(e),lock:()=>sS(e,!0),unlock:()=>sS(e,!1),history:()=>e.workspace.openBottom(`log`),keys:()=>e.openDialog(`keys`),about:()=>e.openDialog(`about`),addPage:()=>$x(e,`addPage`),renamePage:()=>$x(e,`renamePage`),deletePage:()=>$x(e,`deletePage`),themeLight:()=>e.workspace.setTheme(`light`),themeDark:()=>e.workspace.setTheme(`dark`),hoverLabels:e.workspace.toggleHoverLabels,pourSolid:()=>e.workspace.setPourFill(cu.pourSolid),pourHatched:()=>e.workspace.setPourFill(cu.pourHatched),pourOutline:()=>e.workspace.setPourFill(cu.pourOutline),findSimilar:()=>Gx(e),placementTransfer:()=>zx(e),flip:()=>Rx(e),annotate:()=>Bx(e),systemSettings:()=>e.openDialog(`system`),newCircuit:()=>e.openDialog(`newCircuit`),footprintManager:()=>e.openDialog(`footprints`),print:()=>tS(e,!1),exportPdf:()=>tS(e,!0),copy:()=>Ux(e),paste:()=>Wx(e,e.view===`schematic`?e.page:void 0,e.view===`schematic`?`sch`:`pcb`)}[t]}var pS=[`undo`,`redo`,`openFile`,`selectAll`,`find`,`findSimilar`,`placementTransfer`,`flip`,`copy`,`paste`],mS=e=>pS.includes(e??``);function hS(e,t){(0,l.useEffect)(()=>{let n=n=>{let r=rd(Hu(n),{view:t})?.action;mS(r)&&(r!==`copy`||(window.getSelection()?.toString()??``)===``)&&(n.preventDefault(),e(r))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function gS(e){let[t,n]=(0,l.useState)(null),{file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T}=e,{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A}=e.workspace;(0,l.useEffect)(()=>{if(!t||i!==t.view)return;let e=window.setTimeout(()=>{n(null),cb(t.command)||u.notify(`The ${t.view===`pcb`?`PCB`:`schematic`} is still building; try again in a moment.`)},0);return()=>window.clearTimeout(e)},[t,i,u]);let j=(0,l.useCallback)(e=>{let t=fS({file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,workspace:{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A},openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T},e);if(t)return t();let l=Jx(e);l&&i!==l?(a(l),n({command:e,view:l})):cb(e)||u.notify(`Wait for the build to finish, then try again.`)},[r,i,a,o,s,c,u,d,f,p,m,h,g,_,E,ee,D,O,k,A,v,y,b,x,S,C,w,T]);return hS(j,i),j}function _S({file:e,buildId:t,actions:n}){let[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(!1);(0,l.useEffect)(()=>{z(`/api/bom?file=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]);let s=r.reduce((e,t)=>e+t.quantity,0);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`h3`,{children:[`Bill of materials `,(0,Z.jsxs)(`span`,{className:`count`,children:[s,` parts`]})]}),(0,Z.jsxs)(`table`,{className:`bom`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`col`,children:`Parts`}),(0,Z.jsx)(`th`,{scope:`col`,children:`Value`}),(0,Z.jsx)(`th`,{scope:`col`,children:`Supplier`})]})}),(0,Z.jsx)(`tbody`,{children:r.map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsxs)(`td`,{children:[e.designators.join(`, `),e.libraryPart&&!e.verified&&(0,Z.jsx)(`span`,{className:`badge unverified`,children:`Unverified`})]}),(0,Z.jsx)(`td`,{title:e.footprint,children:e.value||e.kind}),(0,Z.jsx)(`td`,{children:(0,Z.jsx)(`code`,{children:e.supplier.replace(/^\w+ /,``)})})]},e.designators.join(` `)))})]}),(0,Z.jsx)(`button`,{disabled:a,onClick:()=>{o(!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(()=>o(!1))},children:a?`Exporting`:`Export BOM and datasheets`})]})}var vS=`No problems found.`,yS=e=>e===`error`?0:1,bS=e=>e.startsWith(`net.`)||e.includes(`:`);function xS(e){return e.items.find(e=>!bS(e))?.split(/[#.]/,1)[0]||void 0}function SS(e,t){let n=xS(e);return n!==void 0&&t.has(n)?n:void 0}function CS(e,t,n,r){let i=e.items.filter(e=>n.has(e)),a=e.items.filter(e=>wS(r).has(e)),o=e.at??(e.view===`pcb`?a.map(e=>$l(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=SS(e,t);return s===void 0?e:{...e,part:s}}function wS(e){let t=e.pcb;return new Set([...t?.board?.pours??[],...t?.holes??[]].map(e=>e.id))}function TS(e){let t=e.pcb;return new Set([...t?.tracks??[],...t?.vias??[]].map(e=>e.id))}function ES(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 DS=(e,t)=>({id:`diagnostic:${t}`,severity:e.severity,code:e.code,message:e.message,items:e.items,view:`code`}),OS=(e,t)=>e<t?`${e} ${t}`:`${t} ${e}`;function kS(e,t){if(t?.state!==`done`)return[];let n=new Map(e.pcb.ratsnest.map(e=>[OS(e.from,e.to),e]));return t.unrouted.flatMap(e=>{let t=n.get(OS(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 AS(e,t){let n=new Set(e.circuit.components.map(e=>e.id)),r=TS(e);return[...e.violations.map(ES),...kS(e,t),...e.diagnostics.map(DS)].map(t=>CS(t,n,r,e)).sort((e,t)=>yS(e.severity)-yS(t.severity))}function jS(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 MS(e,t){return e.flatMap(e=>e.view===t&&e.at?[{id:e.id,at:e.at,severity:e.severity}]:[])}function NS(e){let t=e.filter(e=>e.severity===`error`).length;return{errors:t,warnings:e.length-t}}var PS=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function FS({errors:e,warnings:t}){let n=[...e>0?[PS(e,`error`)]:[],...t>0?[PS(t,`warning`)]:[]];return n.length===0?vS:n.join(`, `)}var IS=`.insp-body:not([hidden]) .insp-value input:not([disabled]):not([type="checkbox"])`,LS={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`]]},RS=[`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`side`,`layer`],zS=[`schNameAt`,`schValueAt`,`pcbNameAt`],BS=`footprint`;function VS(e,t){return BS in e.props?[`prop:${BS}`]:t.includes(BS)?[`suggest:${BS}`]:[]}var HS={label:`Placement`,value:`Placed by Studio`};function US(e,t){let n=Object.keys(e.props).filter(e=>!RS.includes(e)&&!zS.includes(e)&&e!==BS),r=(LS[e.tag]??[]).map(([e])=>e).filter(t=>!(t in e.props)),i=r.filter(e=>e!==BS),a=RS.filter(t=>t in e.props),o=zS.filter(t=>t in e.props),s=VS(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 WS(){return[{title:`Build`,rows:[`build`]},{title:`Notes for the agent`,rows:[`notes`]}]}function GS(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 KS={parts:`Parts`,wires:`Wires`,labels:`Net labels and flags`,drawings:`Drawings`,copper:`Tracks and vias`,texts:`Names and values`,pours:`Copper pours and holes`},qS=/^kind:(parts|wires|labels|drawings|copper|texts|pours):(\d+)$/;function JS(e){let t=qS.exec(e);return t?{kind:t[1],count:Number(t[2])}:void 0}function YS(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:US(l,t)}:{header:c,sections:[{title:`Selection`,rows:u}]}:{header:c,sections:WS()}}var XS=[{label:`Rotate`,command:`rotate`},{label:`Lock`,command:`lock`},{label:`Unlock`,command:`unlock`},{label:`Delete`,command:`delete`}];function ZS(e,t,n,r=0){let i=t.map(e=>e.name);return e===`lock`||e===`unlock`?`parts`in mt(i,n.locked,e===`lock`,n.violated):e===`delete`&&r>0||t.some(e=>e.editable&&!n.locked.has(e.name))}function QS(e,t){return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this part`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this part, so the agent cannot move or change it`}}function $S({label:e,htmlFor:t,children:n}){return(0,Z.jsxs)(`div`,{className:`insp-row`,children:[(0,Z.jsx)(`label`,{className:`insp-label`,htmlFor:t,title:e,children:(0,Z.jsx)(`span`,{children:e})}),(0,Z.jsx)(`div`,{className:`insp-value`,children:n})]})}function eC({title:e,open:t,onToggle:n,children:r}){return(0,Z.jsxs)(`section`,{className:t?`insp-section`:`insp-section collapsed`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`insp-head hairline-t`,"aria-expanded":t,onClick:n,children:[(0,Z.jsx)(lm,{className:`insp-chevron`}),(0,Z.jsx)(`span`,{className:`insp-title`,children:e})]}),(0,Z.jsx)(`div`,{className:`insp-body`,hidden:!t,children:r})]})}function tC({name:e,prop:t,disabled:n,onCommit:r,notify:i}){let a=t.literal===void 0?t.source:String(t.literal),[o,s]=(0,l.useState)(a);return(0,l.useEffect)(()=>s(a),[a]),t.editable?(0,Z.jsx)($S,{label:e,htmlFor:`prop-${e}`,children:(0,Z.jsx)(`input`,{id:`prop-${e}`,value:o,disabled:n,spellCheck:!1,onChange:e=>s(e.target.value),onBlur:()=>{if(o===a)return;let n=iC(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,Z.jsx)($S,{label:e,children:(0,Z.jsx)(`code`,{className:`expr`,title:`An expression; change it in the code`,children:t.source.replace(/\s+/g,` `)})})}var nC=new Set([`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`pinCount`,`order`,`base`]);function rC({name:e,example:t,disabled:n,onCommit:r}){let[i,a]=(0,l.useState)(``);return(0,Z.jsx)($S,{label:e,htmlFor:`new-prop-${e}`,children:(0,Z.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(nC.has(e)&&Number.isFinite(Number(t))?Number(t):t).then(e=>e&&a(``))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})})}function iC(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 aC({label:e,onAdd:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useId)();return(0,Z.jsxs)(`form`,{className:`mark-form`,onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim()).then(e=>e&&r(``))},children:[(0,Z.jsx)(`label`,{htmlFor:i,children:e}),(0,Z.jsxs)(`div`,{className:`inline`,children:[(0,Z.jsx)(`input`,{id:i,value:n,onChange:e=>r(e.target.value),placeholder:`Route ground under this part`}),(0,Z.jsx)(`button`,{type:`submit`,children:`Add`})]})]})}var oC={rotate:am,lock:tm,unlock:nm,delete:om};function sC({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=JS(e);if(t)return(0,Z.jsx)($S,{label:KS[t.kind],children:(0,Z.jsx)(`span`,{className:`static`,children:t.count})},e);let n=e.slice(5),r=l.get(n);return(0,Z.jsx)($S,{label:n,children:(0,Z.jsxs)(`span`,{className:`static`,children:[r?.tag,c.has(n)?`, locked`:``]})},e)};return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:e.header}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:XS.map(({label:e,command:a})=>{let o=oC[a];return(0,Z.jsxs)(`button`,{className:a===`delete`?`danger`:void 0,disabled:!ZS(a,t,r,n),onClick:()=>i(a),children:[(0,Z.jsx)(o,{}),` `,e]},a)})}),e.sections.map(e=>(0,Z.jsx)(eC,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(u)},e.title))]})}function cC(){let e=null;return{answer(t){return e=t,()=>{e===t&&(e=null)}},send(t){return e?(e(t),!0):!1}}}var lC=cC();function uC(e){let t=e;return{set(e){t=e},call:e=>t(e)}}var dC=`Label`;function fC({design:e,label:t,run:n,notify:r,onClear:i,collapsed:a,toggle:o}){let s=hp(e,t);return s?(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:i,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsxs)(`div`,{className:`inspector-actions`,children:[(0,Z.jsx)(`button`,{title:`Rename this label's net`,onClick:()=>{lC.send({kind:`renameLabel`,labelId:t})||r(`Open the schematic to rename this label.`)},children:`Rename`}),(0,Z.jsx)(`button`,{title:`Light this label's net in both views`,onClick:()=>n(`highlight`),children:`Highlight net`})]}),(0,Z.jsx)(eC,{title:dC,open:!a.has(dC),onToggle:()=>o(dC),children:s.rows.map(e=>(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}var pC={path:`line`,rect:`rectangle`,circle:`circle`,arc:`arc`,text:`text`,bus:`bus`,junction:`junction`},mC=(e,t)=>({x:V(e.x+t.x),y:V(e.y+t.y)}),hC=e=>e.kind===`path`||e.kind===`bus`,gC=e=>hC(e)?[`points`]:[`x`,`y`],_C=(e,t)=>e.drawings.find(e=>e.id===t);function vC(e,t,n,r=[]){let i=_C(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 yC=(e,t,n)=>vC(e,t,n.id,gC(n));function bC(e){return e.kind===`path`||e.kind===`bus`?e.points[0]??{x:0,y:0}:{x:e.x,y:e.y}}function xC(e,t,n){let r=e.props[t]?.literal;return typeof r==`number`?r:V(n)}function SC(e,t,n){if(hC(t))return{points:(e.points??[]).map(e=>mC(e,n))};let{groupOffset:r}=t,i=bC(t);return{x:V(xC(e,`x`,i.x-r.x)+n.x),y:V(xC(e,`y`,i.y-r.y)+n.y)}}function CC(e,t){let{groupOffset:n}=e;return e.kind===`path`||e.kind===`bus`?`points`in t?{...e,points:t.points.map(e=>mC(e,n))}:e:`x`in t?{...e,x:V(t.x+n.x),y:V(t.y+n.y)}:e}function wC(e){return e.length>1?[`${e.length} drawings`]:e.map(e=>e.name??`the ${pC[e.kind]}`)}function TC(e,t,n,r,i){let a=t.find(e=>e.id===n),o=_C(e,n);if(!a)return{id:n,blocker:`${n} is not on the sheet`};let s=yC(e,i,a);return s||!o?{id:n,blocker:s??`${n} has no editable source element`}:{id:n,drawing:a,placed:SC(o,a,r)}}function EC(e,t,n,r,i){let a=n.map(n=>TC(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:wC(o.map(e=>e.drawing)),skipped:a.flatMap(e=>`blocker`in e?[e.blocker]:[]),shown:o.map(({drawing:e,placed:t})=>CC(e,t))}}function DC(e,t,n){return r=>{let i=r.map(t=>({id:t,blocker:vC(e,n,t)})),a=i.flatMap(e=>e.blocker??[]),o=i.flatMap(e=>e.blocker===null?[e.id]:[]),s=t=>_C(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:wC(l),skipped:a,removed:o}}}var OC=/^[A-Za-z_][A-Za-z0-9_]*$/,kC=/^G(\d+)$/;function AC(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(kC.exec(e)?.[1]??0)))+1}`}function jC(e,t,n,r){if(t===`bus`?Yt(n)===void 0:!OC.test(n))throw new Um(`invalid`,`"${n}" is not a valid ${t===`bus`?`bus`:`drawing`} name; use ${t===`bus`?`a net name such as "CLK" or a range such as "D[0:7]"`:`letters, digits and _`}`);if(e.parts.some(e=>e.name===n))throw new Um(`invalid`,`A part named ${n} already exists`);let i=(e,r)=>t===`bus`&&e===`bus`&&r===n;if(e.drawings.some(e=>e.id!==r&&(e.name===n||e.id===n)&&!i(e.tag,e.name)))throw new Um(`invalid`,`A drawing named ${n} already exists`)}function MC(e,t){if(typeof t==`string`&&t!==``)return e!==`bus`||Yt(t)!==void 0?t:void 0}function NC(e,t){return`drawing:${e}:${t}`}function PC(e,t){let n=2;for(;e.has(`${t}~${n}`);)n++;return`${t}~${n}`}function FC(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??NC(e,a);if(!n.has(o))return n.add(o),e===`bus`&&r.add(o),{id:o,base:o};let s=PC(n,o);return n.add(s),{id:s,base:o,repeat:e===`bus`&&r.has(o)?`piece`:`duplicate`}})}var IC=`Name the bus, such as D[0:7] or CLK`;function LC(e,t){return new Set([...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``]),...t])}function RC(e,t=[]){let n=LC(e,t),r=1;for(;n.has(`BUS${r}`);)r++;return`BUS${r}`}function zC(e,t,n){let r=t.trim();if(r===``)return IC;try{jC(e,`bus`,r,n);return}catch(e){return e instanceof Error?e.message:String(e)}}function BC(e,t){return e.drawings.map(e=>{let n=Kt(e.tag)??`path`;return{kind:n,name:e.id===t?.id?t.name:MC(n,e.name)}})}var VC=(e,t,n)=>FC(t,e.parts.map(e=>e.name))[n]?.id??``;function HC(e,t,n=[]){let r=n.filter(e=>e===t).map(e=>({kind:`bus`,name:e})),i=[...BC(e),...r,{kind:`bus`,name:t}];return VC(e,i,i.length-1)}function UC(e,t,n){let r=e.drawings.findIndex(e=>e.id===t);return r<0?n:VC(e,BC(e,{id:t,name:n}),r)}function WC(e){let t=`${e.length} member${e.length===1?``:`s`}`;return`${e.length>2?`${e[0]} … ${e.at(-1)}`:e.join(`, `)}, ${t}`}var GC={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:Gt},strokeWidth:{label:`Stroke width`,field:`number`,rule:`nonNegative`},lineStyle:{label:`Line style`,field:`choice`,options:Wt},color:{label:`Colour`,field:`color`},filled:{label:`Filled`,field:`check`}},KC=[`strokeWidth`,`lineStyle`,`color`],qC={path:[`points`,...KC],rect:[`x`,`y`,`width`,`height`,...KC,`filled`],circle:[`x`,`y`,`radius`,...KC,`filled`],arc:[`x`,`y`,`radius`,`startAngle`,`endAngle`,...KC],text:[`x`,`y`,`text`,`fontSize`,`anchor`,`color`],bus:[`points`],junction:[`x`,`y`,`color`]},JC={path:`Line`,rect:`Rectangle`,circle:`Circle`,arc:`Arc`,text:`Text`,bus:`Bus`,junction:`Junction`},YC=e=>e.map(e=>`${e.x}, ${e.y}`).join(`; `);function XC(e,t){let{groupOffset:n}=e;if((e.kind===`path`||e.kind===`bus`)&&t===`points`)return YC(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 ZC(e,t,n,r){let i=GC[n],a=t?.props[n],o=a!==void 0&&!a.editable,s=n===`color`?{placeholder:K().drawing}:{},c=i.options?{options:i.options}:{},l=o?a.source:XC(e,n);return{key:n,label:i.label,value:l,field:i.field,...c,...s,editable:r&&t!==void 0&&!o}}var QC=`Renames this piece of the bus only; its wires keep their nets`;function $C(e,t,n){return e.kind===`bus`?[{key:`name`,label:`Name`,value:e.name,field:`text`,editable:n&&t?.name!==void 0,hint:QC},{key:`members`,label:`Members`,value:WC(e.members),field:`static`,editable:!1}]:[{key:`name`,label:`Name`,value:e.name??`(none)`,field:`static`,editable:!1}]}function ew(e,t,n){let r=t?.line??e.source.line;return[{key:`kind`,label:`Kind`,value:`${JC[e.kind]}, line ${r}`,field:`static`,editable:!1},...$C(e,t,n),...qC[e.kind].map(r=>ZC(e,t,r,n))]}var tw=/^#[0-9A-Fa-f]{6}$/,nw={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 rw(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 iw(e,t){let n=t.trim();if(e.field===`number`){let t=nw[e.rule??`any`],r=Number(n);return n!==``&&Number.isFinite(r)&&t.ok(r)?r:{message:`${e.label} ${t.says}`}}return e.field===`points`?rw(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`?tw.test(n)?n:{message:`${e.label} must be a colour such as "#000080"`}:t===``?{message:`${e.label} cannot be empty`}:t}function aw(e,t,n){let r=t.trim(),i=zC(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 ow(e,t,n,r){if(t===`name`&&e.kind===`bus`&&r)return aw(e,n,r);let i=GC[t];if(!i)return{message:`${t} cannot be set here`};let a=iw(i,n);if(typeof a==`object`&&!Array.isArray(a))return a;let o=e.name??`the ${pC[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 sw=`Drawing`;function cw({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=vC(t.model,r,n),f=ew(u,_C(t.model,n),d===null),p=(e,r)=>{let o=ow(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:UC(t.model,n,c)}):void 0;return i.edit([s],o.summary).catch(()=>!1).then(e=>(e||l?.(),e))};return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:s,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:(0,Z.jsxs)(`button`,{className:`danger`,disabled:d!==null,title:d??`Delete this drawing (Delete)`,onClick:()=>o(`delete`),children:[(0,Z.jsx)(om,{}),` Delete`]})}),d&&(0,Z.jsxs)(`p`,{className:`note`,children:[d,`.`]}),(0,Z.jsx)(eC,{title:sw,open:!c.has(sw),onToggle:()=>l(sw),children:f.map(e=>(0,Z.jsx)(lw,{row:e,onCommit:t=>p(e.key,t)},`${u.id}:${e.key}`))})]})}function lw({row:e,onCommit:t}){let n=(0,l.useId)();return e.field===`static`||!e.editable?(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:e.field===`static`?`static`:`expr`,title:e.value,children:e.value})}):e.field===`check`?(0,Z.jsx)($S,{label:e.label,htmlFor:n,children:(0,Z.jsx)(`input`,{id:n,type:`checkbox`,checked:e.value===`true`,onChange:e=>void t(String(e.target.checked))})}):e.field===`choice`?(0,Z.jsx)($S,{label:e.label,htmlFor:n,children:(0,Z.jsx)(`select`,{id:n,value:e.value,onChange:e=>void t(e.target.value),children:e.options?.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})}):(0,Z.jsx)(uw,{id:n,row:e,onCommit:t})}function uw({id:e,row:t,onCommit:n}){let[r,i]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>i(t.value),[t.value]),(0,Z.jsx)($S,{label:t.label,htmlFor:e,children:(0,Z.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 dw={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},fw={human:`You`,agent:`The agent`,router:`The router`},pw=e=>`${Math.round(e*1e3)/1e3} mm`;function mw(e,t){return t===void 0?`No net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function hw(e,t){return[{label:`Net`,value:mw(e,t.net)},{label:`Layer`,value:t.layer,field:`layer`},{label:`Width`,value:String(t.width),field:`width`},{label:`Length`,value:pw(Cb(t.points))},{label:`Drawn by`,value:fw[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function gw(e,t){let[n=`top`,r=`bottom`]=[t.layers[0],t.layers.at(-1)];return[{label:`Net`,value:mw(e,t.net)},{label:`Layers`,value:`${dw[n]} to ${dw[r]}`},{label:`Drill`,value:pw(t.drill)},{label:`Diameter`,value:pw(t.diameter)},{label:`Drawn by`,value:fw[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function _w(e,t){let n=e.pcb.tracks.find(e=>e.id===t);if(n)return{kind:`track`,title:`Track`,locked:n.locked,rows:hw(e,n)};let r=e.pcb.vias.find(e=>e.id===t);return r&&{kind:`via`,title:`Via`,locked:r.locked,rows:gw(e,r)}}var vw=e=>`(${Math.round(e.x*1e3)/1e3}, ${Math.round(e.y*1e3)/1e3}) mm`;function yw(e,t){let n=e.pcb.tracks.find(e=>e.id===t.id);if(!n||!Tv(n.points,t.index)||!Ca(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:mw(e,n.net)},{label:`Track`,value:n.id},{label:`Length`,value:pw(Cb([r,i]))},{label:`Start`,value:vw(r)},{label:`End`,value:vw(i)}]}}function bw(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 xw(e,t,n){if(t===`lock`)return bw(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 Sw=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}];function Cw({design:e,id:t,segment:n,actions:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=n?.id===t?yw(e,n):void 0;if(c)return(0,Z.jsx)(ww,{shown:c,id:t,run:i,onClear:a,collapsed:o,toggle:s});let l=_w(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=xw(u,e,t);return n?`message`in n?(r.notify(n.message),!1):(await r.editLayout([n.edit],n.summary)).ok:!0};return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:(0,Z.jsxs)(`button`,{className:`danger`,disabled:l.locked,title:l.locked?`${t} is locked`:`Delete this ${l.kind} (Delete)`,onClick:()=>i(`delete`),children:[(0,Z.jsx)(om,{}),` Delete`]})}),(0,Z.jsx)(eC,{title:l.title,open:!o.has(l.title),onToggle:()=>s(l.title),children:l.rows.map(e=>(0,Z.jsx)(Tw,{row:e,locked:l.locked,onCommit:d},e.label))})]})}function ww({shown:e,id:t,run:n,onClear:r,collapsed:i,toggle:a}){return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:r,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:(0,Z.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,Z.jsx)(om,{}),` Delete segment`]})}),(0,Z.jsx)(eC,{title:e.title,open:!i.has(e.title),onToggle:()=>a(e.title),children:e.rows.map(e=>(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function Tw({row:e,locked:t,onCommit:n}){let r=(0,l.useId)();return e.field===`lock`?(0,Z.jsx)($S,{label:e.label,htmlFor:r,children:(0,Z.jsx)(`input`,{id:r,type:`checkbox`,checked:e.value===`true`,onChange:e=>void n(`lock`,String(e.target.checked))})}):e.field===`layer`?(0,Z.jsx)($S,{label:e.label,htmlFor:r,children:(0,Z.jsxs)(`select`,{id:r,value:e.value,disabled:t,onChange:e=>void n(`layer`,e.target.value),children:[Sw.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value)),!Sw.some(t=>t.value===e.value)&&(0,Z.jsx)(`option`,{value:e.value,disabled:!0,children:e.value===`inner1`?`Inner Layer 1`:`Inner Layer 2`})]})}):e.field===`width`?(0,Z.jsx)(Ew,{id:r,value:e.value,locked:t,onCommit:e=>n(`width`,e)}):(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value})})}function Ew({id:e,value:t,locked:n,onCommit:r}){let[i,a]=(0,l.useState)(t);return(0,l.useEffect)(()=>a(t),[t]),(0,Z.jsx)($S,{label:`Width (mm)`,htmlFor:e,children:(0,Z.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 Dw({design:e,circuit:t,id:n,locks:r,actions:i,run:a,onClear:o,collapsed:s,toggle:c}){let l=Dy(e,n);if(!l)return null;let u=my(t.model,r.locked,n),d=My(n,r),f=async(t,r)=>{let a=jy(e,n,t,r);return a?`message`in a?(i.notify(a.message),!1):i.edit([a.edit],a.summary):!0};return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:o,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsxs)(`div`,{className:`inspector-actions`,children:[(0,Z.jsxs)(`button`,{className:d.pressed?`toggle on`:`toggle`,"aria-pressed":d.pressed,title:d.title,onClick:()=>a(d.command),children:[d.pressed?(0,Z.jsx)(tm,{}):(0,Z.jsx)(nm,{}),d.label]}),(0,Z.jsxs)(`button`,{className:`danger`,disabled:u!==null,title:u??`Delete this ${l.kind===`hole`?`hole`:`copper pour`} (Delete)`,onClick:()=>a(`delete`),children:[(0,Z.jsx)(om,{}),` Delete`]})]}),(0,Z.jsx)(eC,{title:l.title,open:!s.has(l.title),onToggle:()=>c(l.title),children:l.rows.map(e=>(0,Z.jsx)(Ow,{row:e,disabled:u!==null,onCommit:f},e.label))})]})}function Ow({row:e,disabled:t,onCommit:n}){let r=(0,l.useId)(),{field:i,choices:a}=e;return!i||t?(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value===``?`Net class`:e.value})}):a?(0,Z.jsx)($S,{label:e.label,htmlFor:r,children:(0,Z.jsxs)(`select`,{id:r,value:e.value,onChange:e=>void n(i,e.target.value),children:[a.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value)),!a.some(t=>t.value===e.value)&&(0,Z.jsx)(`option`,{value:e.value,disabled:!0,children:e.value})]})}):(0,Z.jsx)(kw,{id:r,row:e,field:i,onCommit:n})}function kw({id:e,row:t,field:n,onCommit:r}){let[i,a]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>a(t.value),[t.value]),(0,Z.jsx)($S,{label:t.label,htmlFor:e,children:(0,Z.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 Aw=.001,jw=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 Mw(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)<=Aw)return{segment:n-1,t:c}}}var Nw=(e,t)=>t.some(t=>Mw(e,t)!==void 0);function Pw(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 Fw=e=>Math.round(e*1e3)/1e3;function Iw(e,t,n,r){return n.length<2?[]:e.flatMap(e=>{let i=Mw(e,t);if(i===void 0||Nw(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)}:Pw(e,n),l={x:Fw(c.x),y:Fw(c.y)};return Math.abs(l.x-e.x)<Aw&&Math.abs(l.y-e.y)<Aw?[]:[{kind:`setDrawingProps`,id:e.id,props:l}]})}function Lw(e,t,n){return e.filter(e=>Nw(e,t)&&!Nw(e,n)).map(e=>e.id)}var Rw=`This wire is no longer on the sheet`,zw=`This wire has no corners`,Bw=`Studio draws this wire's corner; the code has none to remove`,Vw=`This wire repeats another between the same ends; delete it in the code`;function Hw(e,t){let n=e.schematic.wires.find(e=>e.id===t);return n&&Mf(e.circuit.nets,n.net)}function Uw(e,t){let n=Hw(e,t),r=e.circuit.nets.find(e=>e.id===n);return r?tp(r):(n??``).replace(/^net\./,``)}var Ww=(e,t)=>`This wire has no trace of its own: Studio draws it for net ${Uw(e,t)}`,Gw=e=>e.startsWith(`net.`)?`net ${e.slice(4)}`:e;function Kw(e,t){let{writer:n}=t;if(n.kind===`engine`)return[An(e,n.from)?.id??Gw(n.from),An(e,n.to)?.id??Gw(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?[Gw(i.from),Gw(i.to)]:void 0}function qw(e,t){let n=Kw(e,t);return n?`the wire from ${n[0]} to ${n[1]}`:`the wire`}function Jw(e,t,n){let{writer:r}=t;if(r.kind===`none`)return r.reason;if(r.kind===`engine`)return Ww(e,t.id);let i=pr(e,r.components,r.trace,n);return i===void 0?r.repeat?Vw:r.trace.editable?null:`This wire is read-only (${r.trace.readonlyReason}); delete it in the code`:`${i} is locked`}function Yw(e,t,n){if(t.writer.kind!==`trace`)return Jw(e,t,n);if(t.points.length<=2)return zw;let r=Rc(e,t,n);return r===null?(t.writer.trace.schematicRouteHints?.length??0)>0?null:Bw:r}function Xw(e){let t=e.writer.kind===`trace`?e.writer.trace:void 0;return{from:t?.from??``,to:t?.to??``}}function Zw(e,t,n){let r=Jw(e,t,n);return r===null?{edits:[{kind:`removeTrace`,...Xw(t)}],summary:`remove ${qw(e,t)}`}:{blocked:r}}function Qw(e,t,n){let r=Yw(e,t,n);return r===null?{edits:[{kind:`setTraceHints`,...Xw(t),schematicRouteHints:[]}],summary:`remove the corners of ${qw(e,t)}`}:{blocked:r}}var $w=e=>`blocked`in e?e.blocked:null;function eT(e,t,n){return{remove:$w(Zw(e,t,n)),removeCorners:$w(Qw(e,t,n))}}function tT(e,t,n){let r=t?qw(e,t):`the wire`,i=r.charAt(0).toUpperCase()+r.slice(1);return n.startsWith(`This wire`)?`${i}${n.slice(9)}`:`${i}: ${n}`}function nT(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 rT(e,t,n,r,i){let a=Lc(e,t,n);if(a&&nT(e,a).some(e=>r.has(e)))return{id:n,kind:`withParts`};let o=a?Zw(e,a,i):{blocked:Rw};return`blocked`in o?{id:n,kind:`skipped`,reason:o.blocked,named:tT(e,a,o.blocked),studio:a?.writer.kind===`engine`}:{id:n,kind:`removed`,edits:o.edits,name:a?qw(e,a):`the wire`}}var iT=e=>`${e} wires have no trace of their own: Studio draws them for their nets`;function aT(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?[iT(r.length)]:r.map(e=>e.named)]}function oT(e,t,n,r,i=cr,a=new Set){let o=n.map(n=>rT(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:aT(o,a),junctions:Lw(jw(e.schematic.drawings),u(!1),u(!0))}}function sT(e,t,n,r=cr){let i=Lc(e,t,n);return i?Qw(e,i,r):{blocked:Rw}}function cT(e,t,n,r=cr){let i=Lc(e,t,n);return i?eT(e,i,r):{remove:Rw,removeCorners:Rw}}function lT(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 uT(e,t,n,r=cr){let i=Lc(e,t,n);if(!i)return;let[a,o]=Kw(e,i)??[`unknown`,`unknown`],s=[{label:`Net`,value:Uw(e,n)},{label:`From`,value:a},{label:`To`,value:o},{label:`Corners`,value:String(Math.max(0,i.points.length-2))},{label:`Kind`,value:lT(i)}];return{net:Hw(e,n),rows:s,...eT(e,i,r)}}var dT=`Wire`;function fT({design:e,circuit:t,wire:n,locked:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=uT(e,t,n,r);return c?(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsxs)(`div`,{className:`inspector-actions`,children:[(0,Z.jsx)(`button`,{disabled:c.net===void 0,title:`Light this wire's net in both views`,onClick:()=>i(`highlight`),children:`Highlight net`}),(0,Z.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,Z.jsxs)(`button`,{className:`danger`,disabled:c.remove!==null,title:c.remove??`Delete this wire's trace (Delete)`,onClick:()=>i(`delete`),children:[(0,Z.jsx)(om,{}),` Delete`]})]}),c.remove&&(0,Z.jsxs)(`p`,{className:`note`,children:[c.remove,`.`]}),(0,Z.jsx)(eC,{title:dT,open:!o.has(dT),onToggle:()=>s(dT),children:c.rows.map(e=>(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}function pT({design:e,circuit:t,text:n,locked:r,actions:i,onClear:a,collapsed:o,toggle:s}){let c=Id(e,t,n,r);if(!c)return null;let l=jd(e,t,n,r);return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:`Selected objects: 1`}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:(0,Z.jsx)(`button`,{disabled:l!==null,title:l??`Put it back where the layout puts it`,onClick:()=>void i.edit(Dd(n),`Reset ${c.rows[0]?.value??``} ${c.title.toLowerCase()} position`),children:`Reset position`})}),c.blocker&&(0,Z.jsxs)(`p`,{className:`note`,children:[c.blocker,`.`]}),(0,Z.jsx)(eC,{title:c.title,open:!o.has(c.title),onToggle:()=>s(c.title),children:c.rows.map(e=>(0,Z.jsx)($S,{label:e.label,children:(0,Z.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function mT({id:e,verified:t,actions:n}){let[r,i]=(0,l.useState)();if((0,l.useEffect)(()=>{z(`/api/part?id=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]),!r)return(0,Z.jsx)(`p`,{className:`note`,children:`Loading…`});let{part:a}=r,o=r.checklist.split(`
16
- `).filter(e=>e.startsWith(`- [`));return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`dl`,{className:`facts`,children:[(0,Z.jsx)(`dt`,{children:`Part`}),(0,Z.jsx)(`dd`,{children:a.title}),a.manufacturer&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{children:`Maker`}),(0,Z.jsx)(`dd`,{children:a.manufacturer})]}),a.mpn&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{children:`MPN`}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(`code`,{children:a.mpn})})]}),(0,Z.jsx)(`dt`,{children:`Footprint`}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(`code`,{children:a.footprint})}),Object.entries(a.suppliers??{}).map(([e,t])=>(0,Z.jsxs)(`span`,{className:`contents`,children:[(0,Z.jsx)(`dt`,{children:e}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(`code`,{children:t})})]},e)),a.datasheet?.url&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{children:`Datasheet`}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(`a`,{href:a.datasheet.url,target:`_blank`,rel:`noreferrer noopener`,children:`Open`})})]})]}),(0,Z.jsxs)(`p`,{className:`hint`,children:[`These come from parts/`,e,`/part.yaml and are the same for every copy of the part.`]}),t?(0,Z.jsxs)(`p`,{className:`note ok`,children:[`Verified by `,a.verified?.by,` against `,a.verified?.against,`.`]}):(0,Z.jsx)(hT,{id:e,checklist:o,actions:n})]})}function hT({id:e,checklist:t,actions:n}){let[r,i]=(0,l.useState)(``),[a,o]=(0,l.useState)(``),[s,c]=(0,l.useState)(``);return(0,Z.jsxs)(`form`,{className:`verify`,onSubmit:t=>{t.preventDefault(),n.verify(e,r.trim(),a.trim(),s)},children:[(0,Z.jsx)(`p`,{className:`note warn`,children:`Not verified. Check each item against the datasheet:`}),(0,Z.jsx)(`ul`,{className:`checklist`,children:t.map(e=>(0,Z.jsx)(`li`,{children:e.replace(/^- \[ \] /,``)},e))}),(0,Z.jsxs)(`label`,{children:[`Checked against`,(0,Z.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`Datasheet, revision, page`,required:!0})]}),(0,Z.jsxs)(`label`,{children:[`Your name`,(0,Z.jsx)(`input`,{"aria-label":`Your name`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,Z.jsxs)(`label`,{children:[`Type `,e,` to confirm`,(0,Z.jsx)(`input`,{"aria-label":`Type ${e} to confirm`,value:s,onChange:e=>c(e.target.value),spellCheck:!1,required:!0})]}),(0,Z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:s.trim()!==e||!r.trim()||!a.trim(),children:`Mark verified`})]})}var gT=/^https?:\/\//,_T=e=>[e.type,e.carries].filter(Boolean).join(`, `);function vT({instance:e}){let t=e.sources??[];return!e.does&&t.length===0?null:(0,l.createElement)(`div`,{className:`instance-card`},e.does?(0,l.createElement)(`p`,{className:`note`},e.does):null,t.length>0?(0,l.createElement)(`ul`,{className:`instance-sources`},t.map(e=>(0,l.createElement)(`li`,{key:e},gT.test(e)?(0,l.createElement)(`a`,{href:e,target:`_blank`,rel:`noreferrer`},e):e))):null)}function yT({id:e,value:t,disabled:n,placeholder:r,onCommit:i}){let[a,o]=(0,l.useState)(t);return(0,l.useEffect)(()=>o(t),[t]),(0,Z.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 bT({design:e,name:t,editable:n,actions:r,onOpenSheet:i,collapsed:a,toggle:o}){let s=cn(e,t),c=(0,l.useId)();if(!s)return null;let u=(e,n)=>{let i=n===``?void 0:an(s.sheet,e,n,s.ports.find(t=>t.name===e)?.bus===!0);return i===void 0?r.edit([{kind:`setConnections`,part:t,connections:mn(s,e,n)}],`Connect ${t}.${e} to ${n===``?`nothing`:n}`):(r.notify(i),Promise.resolve(!1))};return(0,Z.jsxs)(eC,{title:`Sub-sheet`,open:!a.has(`Sub-sheet`),onToggle:()=>o(`Sub-sheet`),children:[(0,Z.jsx)($S,{label:`Sheet`,children:(0,Z.jsx)(`span`,{className:`static`,children:fn(s.sheet,dn(e,s.file))})}),(0,Z.jsx)(`div`,{className:`inspector-actions`,children:(0,Z.jsxs)(`button`,{onClick:()=>i(s.file),title:`Open ${s.file}`,children:[`Open `,s.sheet]})}),(0,Z.jsx)(vT,{instance:s}),s.ports.map(e=>(0,Z.jsxs)($S,{label:`${e.name}${e.bus?` (bus)`:``}`,htmlFor:`${c}-${e.name}`,children:[(0,Z.jsx)(yT,{id:`${c}-${e.name}`,value:s.connections[e.name]??``,placeholder:`not connected`,disabled:!n,onCommit:t=>u(e.name,t)}),_T(e)?(0,Z.jsx)(`span`,{className:`port-about`,children:_T(e)}):null]},e.name)),(0,Z.jsx)($S,{label:`base`,htmlFor:`${c}-base`,children:(0,Z.jsx)(yT,{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 xT({design:e,part:t,onSelect:n,onOpenSheet:r}){let i=ln(e,t);return i?(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsx)(`header`,{className:`insp-header`,children:(0,Z.jsx)(`span`,{children:t})}),(0,Z.jsxs)(`p`,{className:`note`,children:[i.localId,` of instance `,i.instance,` (`,i.sheet,`). `,fn(i.sheet,dn(e,i.file)),`: change it in its sheet, and every instance changes with it.`]}),(0,Z.jsxs)(`div`,{className:`inspector-actions`,children:[(0,Z.jsx)(`button`,{onClick:()=>n(t=>t.all(un(e,i.outer))),children:`Select the instance`}),(0,Z.jsxs)(`button`,{onClick:()=>r(i.file),title:`Open ${i.file}`,children:[`Open `,i.sheet]})]})]}):null}function ST({file:e,parentDesign:t}){let n=t?dn(t,e):void 0;return(0,Z.jsxs)(`p`,{className:`note`,children:[fn(Xe(e),n),`.`]})}function CT({part:e,editable:t,actions:n,collapsed:r,toggle:i}){let a=(0,l.useId)(),o=e.props.bus?.literal===!0,s=t=>n.edit([{kind:`renamePort`,from:e.name,to:t}],`Rename port ${e.name} to ${t}`),c=t=>n.edit([{kind:`setProps`,part:e.name,props:{bus:t}}],`${t?`Make`:`Unmake`} ${e.name} a bus port`);return(0,Z.jsxs)(eC,{title:`Port`,open:!r.has(`Port`),onToggle:()=>i(`Port`),children:[(0,Z.jsx)($S,{label:`Name`,htmlFor:`${a}-name`,children:(0,Z.jsx)(yT,{id:`${a}-name`,value:e.name,disabled:!t,onCommit:s})}),(0,Z.jsx)($S,{label:`Bus`,htmlFor:`${a}-bus`,children:(0,Z.jsx)(`input`,{id:`${a}-bus`,type:`checkbox`,checked:o,disabled:!t,onChange:e=>void c(e.target.checked)})}),(0,Z.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 wT({parts:e,onPlace:t,onImport:n,onNewPart:r,focus:i,onFocused:a}){let[o,s]=(0,l.useState)(``),c=(0,l.useRef)(null);(0,l.useEffect)(()=>{i&&(c.current?.focus(),a())},[i,a]);let u=o.trim().toLowerCase(),d=(...e)=>u===``||e.some(e=>e?.toLowerCase().includes(u)),f=e.library.filter(e=>d(e.id,e.title,e.mpn,e.footprint)),p=e.builtin.filter(e=>d(e));return(0,Z.jsxs)(`div`,{className:`library`,children:[(0,Z.jsx)(`input`,{ref:c,className:`search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:o,onChange:e=>s(e.target.value)}),(0,Z.jsxs)(`h3`,{children:[`Project library `,(0,Z.jsx)(`span`,{className:`count`,children:e.library.length})]}),(0,Z.jsx)(`button`,{className:`library-import`,onClick:r,children:`New part…`}),(0,Z.jsx)(`button`,{className:`library-import`,onClick:n,children:`Import by LCSC number…`}),e.library.length===0&&(0,Z.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,Z.jsx)(`ul`,{children:f.map(e=>(0,Z.jsxs)(`li`,{className:`library-item`,children:[(0,Z.jsxs)(`div`,{className:`text`,children:[(0,Z.jsx)(`span`,{className:`title`,children:e.title}),(0,Z.jsxs)(`span`,{className:`meta`,children:[e.mpn??e.id,`, `,e.footprint]}),e.origin&&(0,Z.jsx)(`span`,{className:`meta`,children:Im(e.origin)})]}),(0,Z.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,Z.jsx)(`button`,{onClick:()=>t(e.id),"aria-label":`Place ${e.title}`,children:`Place`})]},e.id))}),(0,Z.jsx)(`h3`,{children:`Built-in parts`}),(0,Z.jsx)(`ul`,{className:`builtin`,children:p.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`button`,{className:`chip-button`,onClick:()=>t(e),"aria-label":`Place a ${e}`,children:e})},e))}),(0,Z.jsx)(`p`,{className:`hint`,children:`Placed parts start at the board centre; drag them into position on the PCB.`})]})}function TT({design:e,highlight:t,onHighlight:n}){let r=(0,l.useMemo)(()=>e?np(e):[],[e]);if(r.length===0)return(0,Z.jsx)(`p`,{className:`note`,children:`No nets yet.`});let i=e=>t.length===1&&t[0]===e;return(0,Z.jsx)(`ul`,{className:`nets`,children:r.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{className:`row${t.includes(e.id)?` selected`:``}`,"aria-pressed":t.includes(e.id),onClick:()=>n(i(e.id)?Nf:[e.id]),title:i(e.id)?`Click to clear the highlight`:`Click to highlight this net`,children:[(0,Z.jsx)(`span`,{className:`name`,children:e.label}),e.badge&&(0,Z.jsx)(`span`,{className:`badge ${e.badge}`,children:e.badge}),(0,Z.jsx)(`span`,{className:`value`,children:e.pins===1?`1 pin`:`${e.pins} pins`})]})},e.id))})}var ET=`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.`,DT=e=>e.map(e=>e.trim()).filter(e=>e!==``).map(e=>e.replace(/^[-*]\s+/,``));function OT(e){if(e==null)return{kind:`missing`,note:ET};let t=e.replace(/\r\n/g,`
17
- `).split(`
18
- `),n=t.find(e=>/^# /.test(e))?.slice(2).trim()||`Project`,r=[],i;for(let e of t){let t=/^## (.*)$/.exec(e);t?(i&&r.push({title:i.title,lines:DT(i.body)}),i={title:(t[1]??``).trim(),body:[]}):i&&i.body.push(e)}return i&&r.push({title:i.title,lines:DT(i.body)}),{kind:`file`,title:n,sections:r}}function kT(){let[e,t]=(0,l.useState)(void 0),[n,r]=(0,l.useState)(),i=(0,l.useCallback)(()=>{z(`/api/project-memory`).then(e=>{t(e.text),r(void 0)}).catch(e=>r(e.message))},[]);if((0,l.useEffect)(i,[i]),n)return(0,Z.jsxs)(`p`,{className:`note project-memory`,children:[`PROJECT.md could not be read: `,n]});if(e===void 0)return(0,Z.jsx)(`p`,{className:`note project-memory`,children:`Reading PROJECT.md…`});let a=OT(e);return(0,Z.jsxs)(`div`,{className:`project-memory`,children:[(0,Z.jsxs)(`div`,{className:`project-memory-head`,children:[(0,Z.jsx)(`h3`,{children:a.kind===`file`?a.title:`PROJECT.md`}),(0,Z.jsx)(`button`,{type:`button`,onClick:i,children:`Reload`})]}),a.kind===`missing`&&(0,Z.jsx)(`p`,{className:`note`,children:a.note}),a.kind===`file`&&a.sections.map((e,t)=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{children:e.title}),e.lines.length===0?(0,Z.jsx)(`p`,{className:`empty`,children:`(empty)`}):(0,Z.jsx)(`ul`,{children:e.lines.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]},`${e.title}-${t}`))]})}function AT({tree:e,onOpen:t,focus:n,onFocused:r}){let i=(0,l.useRef)(null);return(0,l.useEffect)(()=>{n&&(i.current?.querySelector(`.tree-row.file`)?.focus(),r())},[n,r]),(0,Z.jsxs)(`nav`,{className:`page-tree`,"aria-label":`Pages`,children:[(0,Z.jsx)(`div`,{className:`tree-row project`,children:e.project}),(0,Z.jsx)(`ul`,{ref:i,children:e.files.map(n=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`button`,{className:`tree-row file`,title:`Open ${n.file}`,onClick:()=>t(n.file,e.view),children:n.file}),(0,Z.jsx)(`ul`,{children:n.documents.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.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 jT=e=>`${e}-panel`,MT=e=>`side-tab-${e}`;function NT({side:e,tabs:t,active:n,open:r,onClick:i,onSelect:a}){let o=zp({ids:t.map(e=>e.id),current:n,onSelect:a,onPointerClick:i});return(0,Z.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,Z.jsx)(`button`,{role:`tab`,id:MT(t.id),"aria-controls":jT(e),"aria-selected":i,className:`side-tab${i?` on`:``}`,...o.tab(t.id),children:t.label},t.id)})})}var PT={page:`Page`,net:`Net`,component:`Component`,object:`Object`,project:`Project`},FT=Object.keys(PT),IT=`design-panel`;function LT({sub:e,onSub:t}){let n=zp({ids:FT,current:e,onSelect:t});return(0,Z.jsx)(`div`,{className:`sub-tabs hairline-b`,role:`tablist`,"aria-label":`Project Design`,onKeyDown:n.onKeyDown,children:FT.map(t=>(0,Z.jsx)(`button`,{role:`tab`,id:`sub-tab-${t}`,"aria-controls":IT,"aria-selected":e===t,className:`sub-tab${e===t?` on`:``}`,...n.tab(t),children:PT[t]},t))})}function RT(e){let{left:t,onSub:n}=e,r=t.strip===`design`;return(0,Z.jsxs)(`aside`,{className:`panel left hairline-r`,id:jT(`left`),role:`tabpanel`,"aria-labelledby":MT(t.strip),hidden:e.hidden,onClick:Fp,children:[r&&(0,Z.jsx)(LT,{sub:t.sub,onSub:n}),(0,Z.jsxs)(`div`,{className:`panel-body`,...r?{id:IT,role:`tabpanel`,"aria-labelledby":`sub-tab-${t.sub}`}:{},children:[!r&&(0,Z.jsx)(wT,{parts:e.parts,onPlace:e.onPlace,onImport:e.onImport,onNewPart:e.onNewPart,focus:e.focusSearch,onFocused:e.onSearchFocused}),r&&(0,Z.jsx)(zT,{...e})]})]})}function zT(e){switch(e.left.sub){case`page`:return(0,Z.jsx)(AT,{tree:e.pageTree,onOpen:e.onOpenDocument,focus:e.focusPage,onFocused:e.onPageFocused});case`net`:return(0,Z.jsx)(TT,{design:e.design,highlight:e.highlight,onHighlight:e.onHighlight});case`component`:return(0,Z.jsx)(BT,{...e});case`object`:return(0,Z.jsx)(HT,{...e});case`project`:return(0,Z.jsx)(kT,{})}}function BT({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,Z.jsxs)(`div`,{className:`tree`,children:[[...s].map(([e,t])=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`h3`,{title:e,children:[o(e),` `,(0,Z.jsx)(`span`,{className:`count`,children:t.length})]}),(0,Z.jsx)(`ul`,{role:`listbox`,"aria-multiselectable":`true`,"aria-label":o(e),"data-keys":`parts`,children:t.map(e=>(0,Z.jsx)(`li`,{role:`none`,children:(0,Z.jsxs)(`button`,{role:`option`,"aria-selected":n.has(e.name),className:`row${n.has(e.name)?` selected`:``}${e.editable?``:` readonly`}`,onClick:t=>r(ka(e.name,t)),title:e.readonlyReason?`Read-only: ${e.readonlyReason}`:void 0,children:[(0,Z.jsx)(`span`,{className:`name`,children:e.name}),(0,Z.jsx)(`span`,{className:`value`,children:VT(e.props)}),i.has(e.name)&&(0,Z.jsx)(`span`,{className:`placed-dot`,role:`img`,"aria-label":HS.value,title:HS.value}),a.has(e.name)&&(0,Z.jsx)(tm,{className:`locked-icon`,"aria-label":`Locked`})]})},e.name))})]},e)),e.model.skipped.length>0&&(0,Z.jsxs)(`p`,{className:`note`,children:[e.model.skipped.length,` element(s) cannot be edited here; see the code.`]})]})}function VT(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 HT({circuit:e,selection:t,actions:n}){return(0,Z.jsxs)(`div`,{className:`connections`,children:[(0,Z.jsx)(`ul`,{children:e.model.traces.map((e,r)=>(0,Z.jsxs)(`li`,{className:t.names.some(t=>WT(e,t))?`selected`:``,children:[(0,Z.jsx)(`code`,{children:e.editable?e.from:`line ${e.line}`}),(0,Z.jsx)(`span`,{className:`arrow`,"aria-hidden":`true`,children:`—`}),(0,Z.jsx)(`code`,{children:e.editable?e.to:`read-only`}),(0,Z.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,Z.jsx)(cm,{})})]},`${e.from}-${e.to}-${r}`))}),(0,Z.jsx)(UT,{actions:n})]})}function UT({actions:e}){let[t,n]=(0,l.useState)(``),[r,i]=(0,l.useState)(``);return(0,Z.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,Z.jsxs)(`label`,{children:[`From`,(0,Z.jsx)(`input`,{placeholder:`.R1 > .pin1`,value:t,onChange:e=>n(e.target.value)})]}),(0,Z.jsxs)(`label`,{children:[`To`,(0,Z.jsx)(`input`,{placeholder:`net.GND`,value:r,onChange:e=>i(e.target.value)})]}),(0,Z.jsx)(`button`,{type:`submit`,className:`primary`,children:`Connect`})]})}function WT(e,t){return t?[e.from,e.to].some(e=>e!==void 0&&Vm(e).includes(t)):!1}function GT(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 KT(e,t,n){(0,l.useEffect)(()=>{t&&(e.current?.querySelector(IS)?.focus(),n())},[e,t,n])}function qT(e){let t=(0,l.useRef)(null);KT(t,e.focusField,e.onFieldFocused);let n=GT(e.circuit,e.selection),[r]=n,i=n.length===1&&e.selection.size===0,{wireCount:a,labelCount:o,drawingCount:s,copperCount:c,soleWire:u,soleLabel:d,soleDrawing:f,soleCopper:p,soleText:m,textCount:h,boardCount:g,soleBoard:_}=e.selection,[v,y]=i?[0,0]:[a,o],b=GS(n.length,v,y,s,c,h,g),x=n.length===0&&e.selection.size===1&&e.selection.primary!==void 0?ln(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&&Ue(e.build.design,e.openView).has(r.name),w=YS(n,{library:S!==void 0,autoPlaced:C},v,y,s,c,h,g),T={locked:new Set(e.circuit.annotations.locks.map(e=>e.part)),violated:new Set(e.circuit.violations.map(e=>e.part))},[E,ee]=(0,l.useState)(new Set),D=e=>ee(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),O=()=>e.onSelect(e=>e.clear()),k=e.build.design;return(0,Z.jsxs)(`aside`,{ref:t,className:`panel right`,id:e.hidden?void 0:jT(`right`),role:`tabpanel`,"aria-labelledby":MT(`properties`),hidden:e.hidden,children:[b===`wire`&&u!==void 0&&k&&(0,Z.jsx)(fT,{design:k,circuit:e.circuit,wire:u,locked:T.locked,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`label`&&d!==void 0&&k&&(0,Z.jsx)(fC,{design:k,label:d,run:e.run,notify:e.actions.notify,onClear:O,collapsed:E,toggle:D}),b===`drawing`&&f!==void 0&&k&&(0,Z.jsx)(cw,{design:k,circuit:e.circuit,drawing:f,locked:T.locked,actions:e.actions,onRename:e.onRenameDrawing,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`text`&&m!==void 0&&k&&(0,Z.jsx)(pT,{design:k,circuit:e.circuit,text:m,locked:T.locked,actions:e.actions,onClear:O,collapsed:E,toggle:D}),b===`copper`&&p!==void 0&&k&&(0,Z.jsx)(Cw,{design:k,id:p,segment:e.selection.segment,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`pour`&&_!==void 0&&k&&(0,Z.jsx)(Dw,{design:k,circuit:e.circuit,id:_,locks:T,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`group`&&(0,Z.jsx)(sC,{view:w,parts:n,others:v+y+s+c+g,locks:T,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`part`&&r&&(0,Z.jsx)(YT,{...e,view:w,collapsed:E,toggle:D,part:r,locks:T}),x&&k&&(0,Z.jsx)(xT,{design:k,part:x.part,onSelect:e.onSelect,onOpenSheet:e.onOpenSheet}),b===`board`&&!x&&(0,Z.jsx)($T,{...e,view:w,collapsed:E,toggle:D})]})}function JT(e,t){let n=e&&rf(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 YT({circuit:e,build:t,parts:n,part:r,locks:i,actions:a,onSelect:o,run:s,view:c,collapsed:l,toggle:u,onOpenSheet:d,parentDesign:f}){let p=i.locked.has(r.name),m=n.library.find(e=>e.component===r.tag),h=(e,t)=>a.edit([{kind:`setProps`,part:r.name,props:{[e]:t}}],`set ${r.name} ${e}=${JSON.stringify(t)}`),g=r.editable&&!p,_=e.model.traces.filter(e=>WT(e,r.name)),v=e=>{let[n,i=``]=e.split(`:`),o=r.props[i];if(n===`name`)return(0,Z.jsx)($S,{label:`Name`,children:(0,Z.jsx)(`span`,{className:`static`,children:r.name})},e);if(n===`kind`)return(0,Z.jsx)($S,{label:`Kind`,children:(0,Z.jsxs)(`span`,{className:`static`,children:[r.tag,`, line `,r.line]})},e);if(n===`placed`)return(0,Z.jsx)($S,{label:HS.label,children:(0,Z.jsx)(`span`,{className:`static`,children:HS.value})},e);if(n===`prop`&&o)return(0,Z.jsx)(tC,{name:i,prop:o,disabled:!g,onCommit:e=>h(i,e),notify:a.notify},e);if(n===`suggest`){let t=LS[r.tag]?.find(([e])=>e===i)?.[1]??``;return(0,Z.jsx)(rC,{name:i,example:t,disabled:!g,onCommit:e=>h(i,e)},e)}return n===`textAt`&&o?(0,Z.jsx)($S,{label:`${hd[i]??i} offset`,children:(0,Z.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,Z.jsx)(ZT,{locked:p,onChange:e=>s(e?`lock`:`unlock`)},e):n===`connections`?(0,Z.jsx)(QT,{traces:_},e):n===`library`?m&&(0,Z.jsx)(mT,{id:m.id,verified:m.verified,actions:a},e):(0,Z.jsx)(aC,{label:`Note for the agent about ${r.name}`,onAdd:e=>{let n=JT(t.design,r.name);return a.mark(n?e:`${r.name}: ${e}`,n?{view:`pcb`,...n}:void 0)}},e)};return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:c.header}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:()=>o(e=>e.clear()),children:(0,Z.jsx)(cm,{})})]}),(0,Z.jsx)(XT,{part:r,locks:i,run:s}),p&&(0,Z.jsx)(`p`,{className:`note locked`,children:`Locked. The agent cannot move or change this part.`}),r.readonlyReason&&(0,Z.jsxs)(`p`,{className:`note`,children:[`Read-only here: `,r.readonlyReason,`. Change it in the code.`]}),Ye(e.file)&&(0,Z.jsx)(ST,{file:e.file,parentDesign:f}),r.tag===`port`&&Ye(e.file)&&(0,Z.jsx)(CT,{part:r,editable:g,actions:a,collapsed:l,toggle:u}),t.design&&cn(t.design,r.name)&&(0,Z.jsx)(bT,{design:t.design,name:r.name,editable:g,actions:a,onOpenSheet:d,collapsed:l,toggle:u}),c.sections.map(e=>(0,Z.jsx)(eC,{title:e.title,open:!l.has(e.title),onToggle:()=>u(e.title),children:e.rows.map(v)},e.title))]})}function XT({part:e,locks:t,run:n}){let r=QS(e.name,t),i=n=>ZS(n,[e],t);return(0,Z.jsxs)(`div`,{className:`inspector-actions`,children:[(0,Z.jsxs)(`button`,{className:r.pressed?`toggle on`:`toggle`,"aria-pressed":r.pressed,title:r.title,onClick:()=>n(r.command),children:[r.pressed?(0,Z.jsx)(tm,{}):(0,Z.jsx)(nm,{}),r.label]}),(0,Z.jsxs)(`button`,{disabled:!i(`rotate`),onClick:()=>n(`rotate`),children:[(0,Z.jsx)(am,{}),` Rotate`]}),(0,Z.jsxs)(`button`,{className:`danger`,disabled:!i(`delete`),onClick:()=>n(`delete`),children:[(0,Z.jsx)(om,{}),` Remove`]})]})}function ZT({locked:e,onChange:t}){let n=(0,l.useId)();return(0,Z.jsx)($S,{label:`Locked`,htmlFor:n,children:(0,Z.jsx)(`input`,{id:n,type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)})})}function QT({traces:e}){return e.length===0?(0,Z.jsx)(`p`,{className:`note`,children:`Not connected.`}):(0,Z.jsx)(`ul`,{className:`part-traces`,children:e.map((e,t)=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`code`,{children:e.from}),` — `,(0,Z.jsx)(`code`,{children:e.to})]},`${e.from}-${e.to}-${t}`))})}function $T({circuit:e,build:t,actions:n,counts:r,onShowChecks:i,view:a,collapsed:o,toggle:s}){let c=a=>a===`build`?(0,Z.jsxs)(`div`,{children:[t.status===`failed`&&(0,Z.jsx)(`p`,{className:`note error`,children:t.error}),t.status===`building`&&(0,Z.jsx)(`p`,{className:`note`,children:`Building…`}),t.design&&(0,Z.jsx)(eE,{counts:r,onShowChecks:i})]},a):(0,Z.jsxs)(`div`,{children:[e.annotations.marks.length===0&&(0,Z.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,Z.jsx)(`ul`,{className:`marks`,children:e.annotations.marks.map(e=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`span`,{children:e.text}),(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Remove note ${e.id}`,onClick:()=>void n.unmark(e.id),children:(0,Z.jsx)(cm,{})})]},e.id))}),(0,Z.jsx)(aC,{label:`Note for the agent`,onAdd:e=>n.mark(e)})]},a);return(0,Z.jsxs)(`div`,{className:`inspector`,children:[(0,Z.jsxs)(`header`,{className:`insp-header`,children:[(0,Z.jsx)(`span`,{children:a.header}),(0,Z.jsxs)(`span`,{className:`insp-file`,children:[e.file,`: `,e.model.parts.length,` parts, `,e.model.traces.length,` connections`]})]}),a.sections.map(e=>(0,Z.jsx)(eC,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(c)},e.title)),(0,Z.jsx)(_S,{file:e.file,buildId:t.finishedAt,actions:n}),(0,Z.jsx)(`p`,{className:`hint`,children:`Select a part to see and change its properties.`})]})}function eE({counts:e,onShowChecks:t}){let n=e.errors>0?`error`:e.warnings>0?`warn`:`ok`;return(0,Z.jsxs)(`div`,{className:`check-counts`,children:[(0,Z.jsx)(`p`,{className:`note ${n}`,children:FS(e)}),e.errors+e.warnings>0&&(0,Z.jsx)(`button`,{onClick:t,title:`DRC (\\)`,children:`Show checks`})]})}var tE=12,nE=32,rE={minor:U.grid,fifth:U.gridFifth},iE={lines:rE,dots:{...rE,px:1}};function aE(e,t,n,r,i){Mh(e,t,n,r,iE,i)}var oE={selected:U.selection,selectedFill:U.selectionFill,hover:U.hover,noteStroke:U.selectionBox,noteFill:U.selectionBoxFill,noteDash:[1,3],boxStroke:U.selectionBox,boxFill:U.selectionBoxFill,boxDash:[1,3],lockFill:U.document,lockGlyph:U.background,markPin:U.document,markPanel:U.notePanel,markText:U.document};function sE(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}:{}}}sE(za);function cE(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`?io(1.5,s):1,d=oo({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 lE(e,t,n,r,i,a){let o=B(t,n,{x:r.maxX,y:r.maxY}),s=eo(o.x-4,a),c=eo(o.y-12,a),l=to(14,a);e.save(),e.fillStyle=i.lockFill,mE(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 uE(e,t,n,r,i,a){let{at:o,id:s,text:c}=r,l=B(t,n,o),u=`${s} ${c.length>nE?`${c.slice(0,31)}…`:c}`;e.save(),ho(e),e.font=`${po(tE,1,a)}px ${Oi}`;let d=e.measureText(u).width+12;e.fillStyle=i.markPanel,mE(e,l.x+10,l.y-22,d,20,4),e.fill(),e.fillStyle=i.markText;let f=mo({x:l.x+16,y:l.y-8},a);e.fillText(u,f.x,f.y),e.strokeStyle=i.markPin,e.lineWidth=io(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 dE(e,t,n,r,i,a){pE(e,t,n,{stroke:r.boxStroke,fill:r.boxFill,dash:i===`inside`?[]:r.boxDash},a)}function fE(e,t,n,r,i){pE(e,t,n,{stroke:r.noteStroke,fill:r.noteFill,dash:r.noteDash},i)}function pE(e,t,n,r,i){let a=oo(t,n,i);e.save(),e.lineWidth=Qa(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 mE(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 hE(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=io(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 gE(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&&cE(e,t.camera,t.size,o.box,{x:0,y:0},n,i,a)}}var _E=(e,t,n)=>Math.min(Math.max(e,t),n);function vE(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 yE(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 bE=e=>e.points.length===1?e.points[0]:vE(e.points);function xE(e,t,n,r){let i=n&&vE(n.points);if(n&&i)return{target:{kind:`wire`,id:n.id},middle:i};let a=r&&bE(r);if(r&&a)return{target:{kind:`copper`,id:r.id},middle:a};let o=e===void 0?void 0:t.find(t=>t.name===e);return o&&{target:{kind:`part`,name:o.name},middle:{x:(o.box.minX+o.box.maxX)/2,y:(o.box.minY+o.box.maxY)/2}}}function SE(e,t,n,r,i,a,o){let s=n?xE(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+_E(c.x,0,r.width)*l,y:i.top+_E(c.y,0,r.height)*u};return{target:s?.target??{kind:`canvas`},at:d}}function CE(e,t){return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function wE(e,t,n){let r=CE(t,n);return e.width===r.width&&e.height===r.height?!1:(e.width=r.width,e.height=r.height,!0)}function TE(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 EE=.0015,DE=1.25;function OE(e,t,n){let r=(0,l.useMemo)(()=>t===`pcb`?rf(e.pcb):Ts(e.schematic),[e,t]),i=(0,l.useMemo)(()=>Te(e,t),[e,t]),a=(0,l.useMemo)(()=>[...i.values()].some(e=>e.autoPlaced),[i]),o=(0,l.useMemo)(()=>hn(new Set(n.annotations.locks.map(e=>e.part)),e),[n,e]);return{boxes:r,anchors:i,autoPlaced:a,locked:o,blockerFor:(0,l.useCallback)(r=>gn(e,o,r)??Ee(n,o,r,t),[e,n,o,t])}}function kE(e,t,n){let{anchors:r,boxes:i}=e;return(0,l.useMemo)(()=>({anchors:r,boxes:i,step:t,snap:n}),[r,i,t,n])}function AE(e,t,n,r,i,a,o){return(0,l.useCallback)(()=>SE(t,n,r,i,e.current?.getBoundingClientRect()??{left:0,top:0,width:i.width,height:i.height},a,o),[e,t,n,r,i,a,o])}function jE(e){let[t,n]=(0,l.useState)({width:0,height:0});return(0,l.useEffect)(()=>{let t=e.current;if(!t)return;let r=new ResizeObserver(([e])=>{e&&n({width:Math.floor(e.contentRect.width),height:Math.floor(e.contentRect.height)})});return r.observe(t),()=>r.disconnect()},[e]),t}function ME(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 NE(e,t,n,r){let[i,a]=(0,l.useState)();FE(e,t,a);let o=(0,l.useCallback)(()=>{n&&t.width>0&&a(fe(n,t,r))},[n,t,r]);(0,l.useEffect)(()=>{i||o()},[i,o]);let s=e=>()=>a(n=>n&&me(n,t,{x:t.width/2,y:t.height/2},e));return lb({zoomIn:s(DE),zoomOut:s(1/DE)}),{camera:i,setCamera:a,fit:o}}function PE(e,t,n,r,i){(0,l.useEffect)(()=>{t&&t.view===e&&n&&(r(pe(n,t.at)),i())},[e,t,n,r,i])}function FE(e,t,n){let r=(0,l.useCallback)(r=>{r.preventDefault();let i=ME(e.current,t,r);n(e=>e&&me(e,t,i,Math.exp(-r.deltaY*EE)))},[e,t,n]);(0,l.useEffect)(()=>{let t=e.current;if(t)return t.addEventListener(`wheel`,r,{passive:!1}),()=>t.removeEventListener(`wheel`,r)},[e,r])}function IE(e,t,n,r,i){if(!e||t.width===0)return null;let a=window.devicePixelRatio||1;wE(e,t,a);let o=e.getContext(`2d`);return o?(TE(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 LE(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&&cE(e,t,n,a.box,s,`hover`,i,o),c&&cE(e,t,n,a.box,s,`selected`,i,o),r.locked.has(a.name)&&lE(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&&uE(e,t,n,{at:{x:a.x,y:a.y},id:a.id,text:a.text},i,o);a?.kind===`box`&&dE(e,a.start,a.current,i,oa(a.start,a.current),o),a?.kind===`zoom`&&dE(e,a.start,a.current,i,oa(a.start,a.current),o),a?.kind===`note`&&fE(e,a.start,a.current,i,o)}function RE(e){return e.target instanceof HTMLElement&&e.target.closest(`input, textarea, select`)?!1:!(e.ctrlKey||e.metaKey||e.altKey)}var zE=`Waiting for the build…`,BE=`Snap off`;function VE(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 HE=(e,t)=>lh(e,t??`mm`);function UE(e){let{cursor:t,zoom:n,unit:r}=e,i=VE(e.gesture);return{position:[n===void 0?``:`Zoom ${dh(n,r?10:60)}%`,t?`X ${HE(t.x,r)} Y ${HE(t.y,r)}`:``].filter(e=>e!==``).join(` `),drag:i?`dX ${HE(i.x,r)} dY ${HE(i.y,r)}`:``,notice:e.rotateHeld?zE:``,snap:e.snap===!1?BE:``}}function WE(e,t,n,r){return`Routing ${e} on ${t}, ${n} mm, ${r} — Space corner, V layer+via, Enter ends open, Esc`}function GE({step:e,options:t,onChange:n}){return(0,Z.jsxs)(`label`,{children:[`Grid`,(0,Z.jsx)(`select`,{value:e,onChange:e=>n(Number(e.target.value)),children:t.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function KE({show:e,onKeep:t,title:n}){return e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`tool-divider`,"aria-hidden":`true`}),(0,Z.jsx)(`button`,{onClick:t,title:n,children:`Keep these positions`})]}):null}function qE({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}=UE({cursor:e,zoom:t,unit:n,gesture:a,rotateHeld:o,snap:s});return(0,Z.jsxs)(`div`,{className:`canvas-status`,"aria-live":`off`,children:[(0,Z.jsx)(`span`,{children:c}),n&&(0,Z.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{r?.(),Fp(e)},onPointerDown:e=>e.stopPropagation(),title:`Switch between mm and mil (Q)`,children:n}),l&&(0,Z.jsx)(`span`,{children:` ${l}`}),i&&(0,Z.jsx)(`span`,{children:` ${i}`}),d&&(0,Z.jsx)(`span`,{children:` ${d}`}),u&&(0,Z.jsx)(`span`,{children:` ${u}`})]})}var JE=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),YE=(e,t,n)=>({...e.length>0?{wires:e}:{},...t.length>0?{labels:t}:{},...n.length>0?{drawings:n}:{}}),XE=(e,t,n,r,i)=>_a(e.names,t)&&_a(e.wires??[],n)&&_a(e.labels??[],r)&&_a(e.drawings??[],i);function ZE(e,t,n,r,i=[],a=[],o=[]){let s=e!==void 0&&XE(e,n,i,a,o);if(e&&s&&e.inFlight)return{burst:{...e,total:JE(e.total,r),dirty:!0},send:null,fresh:!1};if(e&&s&&e.base===t){let t=JE(e.total,r);return{burst:{...e,total:t,inFlight:!0,dirty:!1},send:t,fresh:!1}}return{burst:{base:t,names:n,...YE(i,a,o),total:r,inFlight:!0,dirty:!1},send:r,fresh:!0}}function QE(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 $E={inFlight:0,seq:0,waiting:void 0,written:0,held:void 0,history:void 0};function eD(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 tD=(e,t)=>e.waiting&&eD(e,t)?{...e,waiting:void 0,history:void 0}:e;function nD(e,t,n,r){if(n)return{gate:e,send:!1};if(eD(e,r)&&!e.held)return{gate:tD(e,r),send:!0};let i=e.held&&_a(e.held.names,t)?e.held.count+1:1;return{gate:{...e,held:{names:t,count:i}},send:!1}}function rD(e,t,n){let{held:r}=e;if(!r||!eD(e,n))return{gate:r?e:tD(e,n),send:!1};let i=tD(e,n);return _a(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 iD(e){let t=e.seq+1;return{...e,inFlight:e.inFlight+1,seq:t,waiting:{seq:t}}}function aD(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 oD(e){let t=iD(e);return{...t,history:{seq:t.seq}}}function sD(e,t,n,r,i){if(t)return aD(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 cD(e,t){return e.history===void 0?{gate:e,send:!0}:eD(e,t)?{gate:tD(e,t),send:!0}:{gate:e,send:!1}}function lD(e,t,n,r=[],i=[],a=[]){let o=e!==void 0&&XE(e,t,r,i,a);return{names:t,...YE(r,i,a),total:e&&o?JE(e.total,n):n}}function uD(e,t,n,r,i=[],a=[],o=[]){if(!t)return{gate:e,held:t,send:null};let s=cD(e,r);return s.send?{gate:s.gate,held:void 0,send:XE(t,n,i,a,o)?t.total:null}:{gate:e,held:t,send:null}}var dD=new Set([`fit`,`highlight`,`contextMenu`,`delete`,`rotate`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`alignLeft`,`distributeH`]);function fD(e,t,n,r,i=t){return!r||!dD.has(e)?!1:e.startsWith(`nudge`)?i>0&&!n:e===`rotate`?t>0&&!n:e===`alignLeft`||e===`distributeH`?!n:!0}function pD(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?QE(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=ZE(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 mD(e){return e?.kind===`text`&&e.moved&&!e.blocker?{id:e.id,at:e.at}:void 0}function hD({view:e,design:t,circuit:n,actions:r,locked:i,builtFrom:a,drawn:o}){let[s,c]=(0,l.useState)([]);(0,l.useEffect)(()=>c(e=>e.every(e=>e.sentAt>a)?e:e.filter(e=>e.sentAt>a)),[a]);let u=(0,l.useMemo)(()=>bd(e,t),[e,t]),d=(0,l.useMemo)(()=>s.filter(e=>e.sentAt>a),[s,a]),f=(0,l.useMemo)(()=>Td(u,d),[u,d]),p=(e,t)=>{let n={id:e,at:t,sentAt:Date.now()};return c(t=>[...t.filter(t=>t.id!==e),n]),n},m=async(e,t)=>{let a=Ad(n,i,e.id);if(a)return r.notify(a),!1;let o=Ed(e,t);if(o.length===0)return!0;let s=p(e.id,t),l=await r.edit(o,`Move ${e.part} ${hd[e.prop]?.toLowerCase()??e.prop}`);return l||c(e=>e.filter(e=>e!==s)),l},h=(e,t)=>{let n=f.find(t=>t.id===e);n&&m(n,t)},g=(0,l.useRef)(m);g.current=m;let[_]=(0,l.useState)(()=>pD((e,t)=>g.current(e,t)));return{tools:{at:e=>Cd(o?f.filter(e=>o(e.part)):f,e)?.id,position:e=>f.find(t=>t.id===e)?.at,blocker:e=>Ad(n,i,e),commit:h},placed:f,pending:d,nudge:(e,r)=>{let a=_.press(t,e=>f.find(t=>t.id===e),e,r);a&&Ad(n,i,e)===null&&p(e,a)}}}function gD(e,t){let{placed:n,pending:r}=e;return(0,l.useMemo)(()=>{let e=mD(t);return{moves:e?[e,...r.filter(t=>t.id!==e.id)]:r,shown:e?Td(n,[e]):n}},[t,n,r])}var _D=e=>e*Math.PI/180;function vD(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,$s(t,r[e-1],r[e]));return i}function yD(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 bD(e,t){let n={x:e.x,y:e.y};if(yD(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(_D(t)),y:n.y+e.radius*Math.sin(_D(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 xD=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,SD=(e,t)=>Math.hypot(Math.max(e.minX-t.x,0,t.x-e.maxX),Math.max(e.minY-t.y,0,t.y-e.maxY));function CD(e,t){switch(e.kind){case`path`:case`bus`:return vD(e.points,t);case`rect`:{let{x:n,y:r,width:i,height:a}=e;return vD([{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 bD(e,t);case`text`:case`junction`:return SD(nn(e),t)}}function wD(e,t){return Xa(e)?e.kind===`circle`?Math.hypot(t.x-e.x,t.y-e.y)<=e.radius:xD(nn(e),t):!1}function TD(e,t,n){return CD(e,t)<=n+Ga(e)/2?`line`:wD(e,t)?`inside`:void 0}var ED=(e,t)=>e.kind!==`text`||t===void 0||e.fontSize*t>=3;function DD(e,t,n,r){let i;for(let a=e.length-1;a>=0;a--){let o=e[a];if(!ED(o,r))continue;let s=TD(o,t,n);if(s===`line`)return{id:o.id,place:s};s===`inside`&&!i&&(i={id:o.id,place:s})}return i}function OD(e){let t=nn(e),n=Ga(e)/2;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function kD(e){return e.map(e=>({id:e.id,box:OD(e)}))}function AD(e,t,n,r){return la(e,t,n,r)}var jD=.1,MD=`None of the selected parts is in this view.`,ND=1e-6;function PD(e,t,n){let r=Math.max(e.maxX-e.minX,ND),i=Math.max(e.maxY-e.minY,ND),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:Se(a)}}function FD(e,t,n,r){let i=new Set(t),a=be(e.filter(e=>i.has(e.name)).map(e=>e.box));return!a||n.width<=0||n.height<=0?{message:MD}:{camera:PD(a,n,r)}}function ID(e,t,n){return PD({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 LD=new Set([`part`,`selectedPart`,`label`,`selectedLabel`,`wire`,`selectedWire`,`wireCorner`,`drawing`,`selectedDrawing`,`text`]),RD=new Set([`selectedPart`,`selectedWire`,`selectedLabel`,`selectedDrawing`]),zD=0,BD=1,VD=2,HD={wire:`wireSegment`,wireCorner:`wireCorner`};function UD(e,t,n){return e.button===BD?`pan`:e.button===VD?`rightPress`:e.button===zD?n===`note`?`note`:n===`zoom`?`zoom`:n===`place`&&t===`empty`?`pan`:Oa(e)?LD.has(t)?`toggle`:`addBox`:t===`part`||t===`drawing`?`move`:RD.has(t)?`moveGroup`:t===`wire`||t===`wireCorner`?n===null?HD[t]:`wire`:t===`text`?`text`:t===`label`?`label`:`box`:`none`}var WD=2;function GD(e){return(e&WD)!==0}function KD(e,t){return e===`rightPress`?t?`disarm`:`menu`:e===`moveGroup`?`selectAlone`:e===`box`?`clear`:`none`}function qD(e,t){return Math.hypot(t.x-e.x,t.y-e.y)>=3}var JD=`input, textarea, select, form, button`;function YD(e){if(e.button!==zD)return!1;let t=e.target;return typeof t?.closest!=`function`||!t.closest(JD)}var XD=(e,t)=>({x:V(e.x+t.x),y:V(e.y+t.y)}),ZD=(e,t)=>e.x===t.x&&e.y===t.y,QD=e=>XD(e.at,e.by);function $D(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??we,a=Oe(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 eO=(e,t)=>typeof e==`number`?V(e-t):0;function tO(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`?$D(e,t,i.part):void 0;o&&r.set(i.part,{x:eO(n,o.props.x),y:eO(a,o.props.y)})}return r}function nO(e){let t=e.trace.schematicRouteHints??[];return e.reversed?[...t].reverse():[...t]}function rO(e,t,n,r,i){let a=(n,r)=>{if(n===void 0||r===void 0)return;let a=$D(e,t,r);return a&&{at:XD(n,a.ahead),by:i.get(r)??we}},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 iO(e,t,n){let r=cc(e,t);return r===`horizontal`?{x:0,y:n.y}:r===`vertical`?{x:n.x,y:0}:we}function aO(e,t,n){if(n&&ZD(e.by,n.by))return t.map(t=>XD(t,e.by));let r=t.length-1,[i,a]=[t[0],t[r]],o=i?iO(e.at,i,e.by):we,s=n&&a?iO(n.at,a,n.by):we;return t.map((e,t)=>XD(XD(e,t===0?o:we),t===r?s:we))}function oO(e,t,n,r,i){let a=nO(r),o=a.length>0?rO(e,t,n,r,i):void 0;if(!o)return;let[s,c]=o;return{start:s,end:c,corners:a,path:yc([s.at,...a,...c?[c.at]:[]])}}function sO(e,t,n,r,i){let a=n.length<2?[]:Hc(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 cO(e,t,n,r,i){let{writer:a}=n;if(a.kind!==`trace`||!a.components.some(e=>r.has(e)))return;let o=oO(e,t,n,a,r);if(!o)return;let{start:s,end:c}=o,l=c?[QD(c)]:[],u=o.path.slice(1,c?-1:void 0);return sO(e,n,yc([QD(s),...aO(s,u,c),...l]),i,[QD(s),...o.corners,...l])}function lO(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)?Lc(e,t,a.id):void 0,c=s&&cO(e,t,s,n,r);return c?[c]:[]})}function uO(e,t,n,r,i,a,o){let s=oO(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 sO(e,n,_c(s.path,i.offset,d),o,s.path)}function dO(e,t,n,r,i){let{design:a,locked:o}=e,s=Lc(a,t,n),c=s?.writer;if(!s||c?.kind!==`trace`||nO(c).length===0)return{kind:`leave`};let l=Rc(a,s,o);if(l!==null)return{kind:`blocked`,reason:l,named:tT(a,s,l)};let u=qw(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:uO(a,t,s,c,r,i,o)}}var fO=`Studio draws this wire's shape between its pins; drag one of its segments to give it corners first`,pO=`Studio draws these wires' shapes between their pins; drag one of their segments to give them corners first`;function mO(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?fO:pO]:[];return[...r,...a]}function hO(e,t){return e.flatMap(e=>e.kind===`carry`&&e.move||e.kind===`follow`&&t.has(e.id)?[e.name]:[])}var gO=(e,t,n,r,i)=>`move ${Qe([...e,...$e(t),...lp(n),...r])}${Ce.schematic.where} by (${V(i.x)}, ${V(i.y)})`;function _O(e,t,n,r){let i=n?.wires??[],a=rp(e.design,n?.labels??[],e=>r.has(e),i),o=i=>dO(e,t,i,{offset:n?.offset??we,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 vO(e,t,n,r){return n.riding.flatMap((i,a)=>{if(i.kind===`carry`||i.kind===`follow`)return[];let o=n.ridingIds[a]??``,s=Lc(e.design,t,o),c=i.kind===`blocked`?i.reason:s&&Rc(e.design,s,e.locked),l=e.design.schematic.labels.find(e=>e.id===n.sort.riding.get(o));return c&&!r.includes(c)?[ap(l,c)]:[]})}function yO(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 bO(e,t,n,r){if(!n)return{plan:e,lines:[],labels:[],drawings:[]};let i=tO(n.design,t,e.edits),a=_O(n,t,r,i),o=[...a.outcomes,...a.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.move]:[]),s=lO(n.design,t,i,n.locked,new Set(o.map(e=>e.line.id))),c=[...o,...s],l=r?.offset??we,u=sp(n.design,t,a.sort.alone,l,n.locked,e.skipped),d=EC(t.model,n.design.schematic.drawings,r?.drawings??[],l,n.locked),f=hO(a.outcomes,new Set(s.map(e=>e.line.id))),p=[...cp(n.design,yO(a)),...u.names],m=[...u.edits,...d.edits],h=e.edits.length===0&&c.length===0&&m.length===0,g=[...mO(a.outcomes,e.skipped,h),...vO(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?gO(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 xO(e,t,n,r){return bO(e,t,n,r).plan}function SO(e,t,n,r=[],i=[],a=[]){return bO(nt(e.circuit,t,e.view,rt(e.anchors,e.boxes),n,e.blockerFor),e.circuit,e.follow,{wires:r,labels:i,drawings:a,offset:n})}var CO=6,wO=V;function TO(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]=$i([...s?[{kind:`label`,label:s}]:[],...c===void 0?[]:[{kind:`wire`,id:c}],...d(`line`),...ve(e,n).map(e=>({kind:`part`,name:e.name})),...u===void 0?[]:[{kind:`text`,id:u}],...d(`inside`)],r);return f??{kind:`canvas`}}function EO(e,t,n,r){return TO(e,void 0,t,n,void 0,void 0,r).kind===`text`}function DO({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 OO=e=>({selection:e.selection,armed:e.tool.armed,layers:e.layers,filter:e.filter});function kO(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 AO(e,t,n){let r=rl(e.wires?.drag,OO(e),t,n.scale);if(r)return{target:{kind:`wire`,id:r.id},under:`wireCorner`,corner:r.index};let i=TO(e.boxes,e.labels,t,OO(e),e.wires,e.drawings,e.texts),a=i.kind===`text`?void 0:e.copperAt?.(t);return a===void 0?{target:i,under:kO(i,e.selection)}:{target:{kind:`copper`,id:a},under:`empty`}}var jO=new Set([`wire`,`wireSegment`,`wireCorner`]);function MO(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&&il(o,r.world,i.scale,n===`wireCorner`?r.corner:void 0);return s&&ol(a,t,s,r.point)}function NO(e,t,n){let{camera:r}=e;if(!r)return;let i=de(r,e.size,n),{target:a,under:o,corner:s}=AO(e,i,r),c=UD(t,o,e.tool.armed);if(M(c)&&ie.refuses())return PO(e,a,c);let l=KD(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 FO(e,a.label,c,n,l);if(a.kind===`wire`)return RO(e,a.id,c,{world:i,point:n,still:l,...s===void 0?{}:{corner:s}},r);if(a.kind===`drawing`)return LO(e,a.id,c,n,l);if(a.kind===`text`)return IO(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`?VO(e,{part:u},c,n,l):void 0}}function PO(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 FO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleLabel(t.id));else{if(n===`moveGroup`)return VO(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 IO(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 LO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleDrawing(t));else return n===`move`||n===`moveGroup`?VO(e,{drawing:t},n,r,i):void 0}function RO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleWire(t));else return n===`moveGroup`?VO(e,{wire:t},n,r.point,r.still):jO.has(n)?MO(e,t,n,r,i):void 0}var zO={names:[],wires:[],labels:[],drawings:[]};function BO(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)),{...zO,names:[n]}}if(!(`drawing`in t))return zO;let{drawing:r}=t;return e.onSelect(e=>e.onlyDrawing(r)),{...zO,drawings:[r]}}function VO(e,t,n,r,i){let a=BO(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:we,moved:!1,blocker:s,still:i}}function HO(e,t,n,r){if(t.kind===`pan`){let r=(n.x-t.start.x)/t.camera.scale,i=(n.y-t.start.y)/t.camera.scale;return e.setCamera({...t.camera,cx:t.camera.cx-r,cy:t.camera.cy+i}),!t.moved&&qD(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&&!qD(t.start,n))return;let i=de(r,e.size,n),a=de(r,e.size,t.start),o={x:i.x-a.x,y:i.y-a.y};if(t.kind===`reshape`)return sl(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=>ge(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??we;return{...t,moved:!0,offset:{x:wO(s(l.x+o.x)-l.x),y:wO(s(l.y+o.y)-l.y)}}}function UO(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 WO(e,t,r);if(t.kind===`reshape`)return ll(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 qO(e,t,n);if(t.kind===`zoom`)return JO(e,t,n);YO(e,t,n)}}function WO(e,t,n){if(!t.moved)t.still===`selectAlone`&&e.onSelect(GO(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 GO({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 KO(e,t,n){return Math.abs(t.start.x-t.current.x)<CO&&Math.abs(t.start.y-t.current.y)<CO?void 0:[de(n,e.size,t.start),de(n,e.size,t.current)]}function qO(e,t,n){let r=KO(e,t,n);if(!r){t.still===`clear`&&e.onSelect(e=>e.clear());return}let i=oa(t.start,t.current),a={parts:ua(e.boxes,r[0],r[1],i),wires:ma(e.wires?.lines??[],r[0],r[1],i),labels:da(e.labels?.boxes??[],r[0],r[1],i),drawings:AD(e.drawings?.boxes??[],r[0],r[1],i),copper:wl(e.copper??[],r[0],r[1],i)};e.onSelect(ha(a,t.adds,e.tool.armed,e.layers,e.filter))}function JO(e,t,n){let r=KO(e,t,n);r&&(e.tool.disarm(),e.setCamera(ID(r[0],r[1],e.size)))}function YO(e,t,n){let r=KO(e,t,n);if(!r)return;let[i,a]=r;e.tool.disarm();let o=window.prompt(Ce[e.view].notePrompt);o&&e.actions.mark(o,{view:e.view,x:wO((i.x+a.x)/2),y:wO((i.y+a.y)/2)})}function XO(e,t){return e.kind===`reshape`&&!t?.drag}var ZO=new Set([`label`,`text`,`reshape`]),QO=e=>e!==void 0&&ZO.has(e);function $O(e,t,n){return XO(e,n)?!0:t!==void 0&&(t===0||e.kind===`reshape`&&GD(t))}function ek(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=NO(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($O(n,r,a.wires))return i(void 0),!1;let o=HO(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&&UO(a,r,a.camera,o,t)},cancel(){i(void 0)}}}function tk(e){let{actions:t,builtFrom:n}=e,[r,i]=(0,l.useState)();return(0,l.useEffect)(()=>i(e=>e&&e.sentAt>n?e:void 0),[n]),{pending:(0,l.useMemo)(()=>r&&r.sentAt>n?r:void 0,[r,n]),commit:(n,r,a=[],o=[],s=[])=>{if(r.x===0&&r.y===0)return;let{plan:c,lines:l,labels:u,drawings:d}=SO(e,n,r,a,o,s),f=c.edits.length>0?{names:c.parts,offset:r,wires:l,labels:u,drawings:d,sentAt:Date.now()}:void 0;f&&i(f),ht(c,t).then(e=>e||i(e=>e===f?void 0:e))}}}function nk(e,t){(0,l.useEffect)(()=>{if(!QO(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 rk(e,t){let n=t?.kind===`drag`&&t.moved&&!t.blocker?t:void 0,{follow:r,circuit:i}=e;return(0,l.useMemo)(()=>{if(!n)return;if(!r)return{names:n.movable,offset:n.offset,wires:[]};let{lines:t,labels:i,drawings:a}=SO(e,n.names,n.offset,n.wires,n.labels,n.drawings);return{names:n.movable,offset:n.offset,wires:t,labels:i,drawings:a}},[n,r,i])}function ik(e){let[t,n]=(0,l.useState)(),{pending:r,commit:i}=tk(e),a=(0,l.useRef)({input:e,commit:i});a.current={input:e,commit:i};let[o]=(0,l.useState)(()=>ek(()=>a.current,n)),s=rk(e,t)??r;nk(t?.kind,o.cancel),(0,l.useEffect)(()=>{t&&XO(t,e.wires)&&o.cancel()},[t,e.wires,o]);let{press:c,move:u,release:d,cancel:f,wireBeforeDoubleClick:p}=o;return{gesture:t,moving:s,pending:r,press:c,move:u,release:d,cancel:f,wireBeforeDoubleClick:p}}function ak(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 ok(e){let t=t=>ME(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,de(e.camera,e.size,r))||e.gestures.press(n,r)},onPointerMove:n=>{if(!e.camera)return;let r=t(n),i=de(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(de(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&&YD(n)&&e.open?.(de(e.camera,e.size,t(n)))}}}function sk({selection:e,boxes:t,size:n,setCamera:r,notify:i}){lb({fitSelection:()=>{let a=FD(t,e.names,n,jD);`camera`in a?r(a.camera):i(a.message)}})}var ck=`Drag a box where the note for the agent goes. Esc or a right click stops.`,lk=`Drag a box to zoom to it. Esc or a right click stops.`,uk=e=>e,dk=e=>e===`note`?ck:e===`zoom`?lk:void 0,fk=e=>e===`zoom`?`fitArea`:null;function pk(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e=>{id(Hu(e))&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function mk(e){let[t,n]=(0,l.useState)(null),r=(0,l.useCallback)(()=>n(null),[]),i=(0,l.useCallback)(t=>{e?.(),n(uk(t))},[e]);return lb({noteBox:()=>i(`note`),fitArea:()=>i(`zoom`)}),pk(t!==null,r),{armed:t!==null,which:t,tool:t,arm:i,disarm:r,hint:dk(t)}}function hk(e,t){return t===void 0?`no net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function gk(e,t){let n=e.circuit.nets.find(e=>e.id===t);if(n)return{id:t,name:n.names[0]??t,width:tg(e.rules,n),via:ig(e.rules,n)}}function _k(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 vk=(e,t)=>t===void 0?{}:{net:t,netName:hk(e,t)};function yk(e,t,n){if(!pl({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,...vk(e.design,r.net)}}function bk(e,t,n){let r=Tf(e.design.pcb,t,n,e.visible);return r&&{kind:`pad`,id:r.id,label:_k(e.design,r),part:r.component,at:{x:r.x,y:r.y},...vk(e.design,r.net),layer:r.layers}}function xk(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=ge(c[l],r.step);return u>=Math.min(e[l],t[l])&&u<=Math.max(e[l],t[l])?{...c,[l]:u}:c}function Sk(e,t,n,r,i){let a;for(let o of e.copper.tracks)if(!(r!==void 0&&o.layer!==r||!pl({kind:`track`,layer:o.layer},e.visible)))for(let e=1;e<o.points.length;e++){let r=xk(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:xk(o.points[e-1],o.points[e],t,i),d:s})}return a&&{kind:`track`,id:a.track.id,at:a.at,...vk(e.design,a.track.net),layer:a.track.layer}}function Ck(e,t,n,r,i){return yk(e,t,n)??bk(e,t,n)??Sk(e,t,n,r,i)}var wk=(e,t)=>e.mark===void 0||t===void 0||t<=e.mark,Tk=(e,t,n)=>[...e,{...n,id:t}],Ek=(e,t,n)=>e.map(e=>e.id===t?{...e,mark:n}:e),Dk=(e,t)=>e.filter(e=>e.id!==t),Ok=(e,t)=>e.filter(e=>wk(e,t)),kk=e=>e.some(e=>e.mark===void 0);function Ak(e,t){return Ok(e,t).reduce((e,t)=>zv(e,t.shapes),Ov)}function jk(e,t){return[...Ok(e,t)].reverse().find(e=>e.parts!==void 0)?.parts}var Mk=Math.PI/12,Nk=.005,Pk=.01,Fk=.001,Ik=2*Fk,Lk=1e-4,Rk=.01,zk=1e6,Bk=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Vk=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Hk=(e,t)=>({x:e.x*t,y:e.y*t}),Uk=e=>Math.hypot(e.x,e.y),Wk=e=>Hk(e,1/Uk(e)),Gk=(e,t)=>e.x*t.y-e.y*t.x,Kk=(e,t)=>e.x*t.x+e.y*t.y,qk=e=>({x:Math.round(e.x*zk)/zk,y:Math.round(e.y*zk)/zk}),Jk=(e,t)=>Math.abs(e-t)<=Lk+Rk*Math.max(e,t),Yk=(e,t)=>Math.abs(e-t)<=Fk;function Xk(e){let t=e<=.005/2?Math.PI:2*Math.acos(1-Nk/e);return Math.min(Mk,t)}function Zk(e){return e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y)}function Qk(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]=[Bk(t,r),Bk(i,t)];return Math.atan2(Gk(a,o),Kk(a,o))})}function $k(e,t,n,r){let[i,a]=[Bk(t,e),Bk(r,n)],o=Gk(i,a);if(!(Math.abs(o)<1e-12))return Vk(e,Hk(i,Gk(Bk(n,e),a)/o))}function eA(e,t,n){let r=t[n];if(Math.abs(r)<=Fk||Math.abs(r)>Mk/2+Fk)return;let i=n+1;for(;i<e.length-1&&Yk(t[i],2*r);)i++;if(i>=e.length-1||!Yk(t[i],r))return;let a=Uk(Bk(e[n+1],e[n]));for(let t=n+1;t<i;t++)if(!Jk(Uk(Bk(e[t+1],e[t])),a))return;let[o,s]=[e[n],e[i]],c=$k(e[n-1],o,s,e[i+1]);if(c===void 0)return;let[l,u]=[Bk(c,o),Bk(s,c)];return Kk(l,Bk(o,e[n-1]))>0&&Kk(u,Bk(e[i+1],s))>0&&Jk(Uk(l),Uk(u))?{first:n,last:i,corner:c}:void 0}function tA(e){let t=Qk(e),n=[];for(let r=1;r<e.length-1;r++){let i=eA(e,t,r);i&&(n.push(i),r=i.last)}return n}var nA=(e,t)=>Math.max(1,Math.ceil(e/Xk(t)-1e-9));function rA(e,t,n,r,i){let a=Math.abs(i),o=r*Math.tan(a/2),[s,c]=[Bk(e,Hk(t,o)),Vk(e,Hk(n,o))],l=Math.sign(i),u=Vk(s,Hk({x:-t.y*l,y:t.x*l},r)),d=nA(a,r),f=Bk(s,u);return[s,...Array.from({length:d-1},(e,t)=>{let n=l*a*(t+1)/d;return Vk(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(qk)}function iA(e,t,n,r){let i=Zk(e),a=Math.max(t,n),o=Qk(i),s=new Set(tA(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/nA(p,a)/2<=Ik){c.push(n);continue}let m=a*Math.tan(p/2),h=p<Math.PI-Fk&&m+Pk<=Uk(Bk(n,d))&&m+Pk<=Uk(Bk(f,n))?rA(n,Wk(Bk(n,i[t-1])),Wk(Bk(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 aA(e,t){let n=Zk(e),r=[],i=tA(n).filter(e=>{let i=qk(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),qk(e.corner)),o=e.last+1;return a.push(...n.slice(o)),{points:a,straightened:i.length,round:r}}var oA=[`45`,`45r`,`90`,`arc`],sA={45:`45°`,"45r":`45° reversed`,90:`90°`,arc:`Arc`},cA=e=>sA[e];function lA(e){return oA[(oA.indexOf(e)+1)%oA.length]}var uA=(e,t)=>({x:V(e),y:V(t)});function dA(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)?uA(e.x+o*(Math.abs(r)-a),e.y):uA(e.x,e.y+s*(Math.abs(i)-a)):uA(e.x+o*a,e.y+s*a)}function fA(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`?bn([e,t]).slice(1):n===`arc`?mA(e,t,r):[dA(e,t,n===`45`),t]}var pA=.98;function mA(e,t,n){let r=bn([e,t]),i=pA*Math.min(Math.abs(t.x-e.x),Math.abs(t.y-e.y));return i<n/2?r.slice(1):iA([e,...r.slice(1)],i,n).points.slice(1)}function hA(e,t,n=0){let r=[e],i=e;for(let e of t)r.push(...fA(i,e.to,e.mode,n)),i=e.to;return vv(r)}var gA={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},_A=e=>gA[e],vA=e=>e===`top`?`bottom`:`top`;function yA(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 ${_A(e.layer)}, which cannot be routed yet`}:{start:{label:n,at:e.at,through:!1},layer:e.layer}}function bA(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=yA(e,t);return`message`in i?i:{route:{net:n,start:i.start,layer:i.layer,mode:t.mode??`45`,corners:[]}}}function xA(e,t,n){if(!n.snap)return t;let r=r=>Math.abs(t[r]-e[r])<n.step/2?e[r]:ge(t[r],n.step);return{x:r(`x`),y:r(`y`)}}var SA=e=>e.corners.at(-1)?.at??e.start.at,CA=(e,t)=>e.x===t.x&&e.y===t.y;function wA(e,t){return CA(t,SA(e))?e:{...e,corners:[...e.corners,{at:t,mode:e.mode,layer:e.layer}]}}var TA=e=>({...e,mode:lA(e.mode)});function EA(e,t=vA(e.layer)){return t===e.layer?e:e.corners.length===0&&!e.start.through?{message:`${e.start.label} is on the ${_A(e.layer)} only; click a corner before changing layer`}:{...e,layer:t}}function DA(e){let t=e.corners.at(-1);return t?{...e,corners:e.corners.slice(0,-1),layer:t.layer}:e}function OA(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=hA(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 kA(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 AA(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 ${_A(r)}; press V to change layer first`}var jA=e=>e.kind===`pad`?e.label:`${e.kind} ${e.id}`;function MA(e,t){if(e.corners.length===0&&CA(t.at,e.start.at))return;let n=AA(e,t);if(n)return{message:n};let r=OA(e,t.at);return{edits:kA(r,e.net.name),summary:`Route ${e.net.name} from ${e.start.label} to ${jA(t)}`,drawing:r}}function NA(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=OA({...e,layer:t.layer},t.at);return{edits:kA(n,e.net.name),summary:`Route ${e.net.name} from ${e.start.label}, open at (${t.at.x}, ${t.at.y})`,drawing:n}}function PA(e,t,n,r=Gh.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 FA(e?e.at:t,i,r)}function FA(e,t,n=Gh.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:kA(i,t?.name),summary:t?`Add via on ${t.name} ${a}`:`Add via ${a}`,drawing:i}}var IA={route:`singleRouting`,via:`placeVia`},LA=12;function RA(){let[e,t]=(0,l.useState)(null),[n,r]=(0,l.useState)(null),[i,a]=(0,l.useState)(`45`);return{armed:e,setArmed:t,disarm:(0,l.useCallback)(()=>t(null),[]),route:n,setRoute:r,mode:i,setMode:a}}var zA=`new`;function BA(e){let t=e=>e.net===void 0?{}:{net:e.net};return{tracks:e.flatMap(e=>e.drawing.tracks.map(n=>({id:zA,...t(e),...n}))),vias:e.flatMap(e=>e.drawing.vias.map(n=>({id:zA,...t(e),at:n.at,diameter:n.diameter})))}}function VA(e,t){let[n,r]=(0,l.useState)([]),i=(0,l.useRef)(0);(0,l.useEffect)(()=>r(t=>Ok(t,e)),[e]);let a=(0,l.useMemo)(()=>Ok(n,e),[n,e]);return{drawings:(0,l.useMemo)(()=>a.map(e=>({drawing:e.drawing,alpha:El})),[a]),copper:(0,l.useMemo)(()=>BA(a),[a]),send:(0,l.useCallback)((e,n)=>{i.current+=1;let a=i.current;r(t=>[...t,{id:a,drawing:e.drawing,...n===void 0?{}:{net:n}}]),t.editLayout(e.edits,e.summary).then(e=>r(t=>e.ok&&e.mark!==void 0?Ek(t,a,e.mark):Dk(t,a)))},[t])}}function HA(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 UA(e,t,n){let{design:r,actions:i,onActiveLayer:a,arm:o,onArm:s}=e,{route:c,setRoute:l}=o,u=(n,r=c===null)=>{if(!e.camera)return;let i=r?void 0:c?.layer??e.activeLayer;return Ck(HA(e,t),n,LA/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=bA(t,{activeLayer:e.activeLayer,locked:e.locked,netOf:e=>gk(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=EA(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=lA(c?.mode??o.mode);o.setMode(e),c?d({...c,mode:e}):i.notify(`Routing corner: ${cA(e)}`)}}}function WA(e){let{input:t,route:n}=e;if(!n)return;let r=NA(n);if(`message`in r)return t.actions.notify(r.message);e.setRoute(null),e.send(r,n.net.id)}function GA(e,t){let{input:n,route:r}=e,i=Hu(t),a=()=>{t.preventDefault(),t.stopPropagation()};if(id(i)&&(r||n.arm.armed))return a(),e.cancel();let o=rd(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(vA(r?.layer??n.activeLayer));if(o.action===`routingCorner`)return a(),e.stepCorner();if(o.action===`finishShape`)return r?(a(),WA(e)):void 0;!r||o.action!==`flipBend`&&o.action!==`removeCorner`||(a(),o.action===`flipBend`&&n.arm.setMode(TA(r).mode),e.put(o.action===`flipBend`?TA(r):DA(r)))}}}function KA(e){(0,l.useEffect)(()=>{let t=t=>GA(e.current,t);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function qA(e,t,n){let{input:r}=e,i=e.targetAt(t,!0),a=PA(i,_e(t,r.step,r.snap),e=>gk(r.design,e),ag(r.design.rules));if(`message`in a)return r.actions.notify(a.message);n(a,i?.net)}function JA(e,t,n){let{input:r,route:i}=e,a=e.targetAt(t);if(!i){a&&e.start(a);return}if(!a){let n=wA(i,xA(SA(i),t,r));return n===i&&i.corners.length>0?WA(e):e.put(n)}let o=MA(i,a);if(o){if(`message`in o)return r.actions.notify(o.message);e.setRoute(null),n(o,i.net.id)}}function YA(e,t,n,r){let{input:i}=e;return!i.arm.armed||t.button!==0?!1:(i.arm.armed===`via`?qA(e,n,r):JA(e,n,r),!0)}function XA(e,t){let{route:n,input:r}=e;if(n&&t)return OA(n,e.targetAt(t)?.at??xA(SA(n),t,r))}var ZA=(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 ${_A(n)}. Esc to stop.`:void 0;function QA(e){let{route:t,setRoute:n}=e.arm,r=VA(e.builtMark,e.actions),i=UA(e,r.copper,r.send),a=(0,l.useRef)(i);a.current=i,KA(a),lb({singleRouting:()=>a.current.arm(`route`),placeVia:()=>a.current.arm(`via`),routingCorner:()=>a.current.stepCorner()});let{armed:o}=e.arm;(0,l.useEffect)(()=>{o!==`route`&&n(null)},[o,n]),(0,l.useEffect)(()=>{t&&t.layer!==e.activeLayer&&a.current.changeLayer(e.activeLayer)},[t,e.activeLayer]);let s=XA(i,e.cursor),c=s?[...r.drawings,{drawing:s,alpha:1}]:r.drawings,u=o?IA[o]:null;return{armed:o!==null,routing:t!==null,command:u,routes:c,status:t?WE(t.net.name,_A(t.layer),t.net.width,cA(t.mode)):void 0,hint:ZA(o,t,e.activeLayer),press:(e,t)=>YA(a.current,e,t,r.send),cancel:()=>a.current.cancel()}}var $A;function ej(e){$A=e}function tj(){return $A}function nj(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 rj=1e-6;function ij(e,t){return!(e>=t-rj)}function aj(e,t,n,r,i,a){let o=Hr(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 oj=e=>e.toFixed(3),sj=e=>e>0?`${oj(e)} mm apart`:`touching or overlapping`;function cj(e,t,n,r,i){return{...aj(e,`error`,t,r,`pcb`,i),id:`${e}:${n.join(`|`)}`}}var lj=2,uj=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),dj=([e,t])=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2}),fj=(e,t)=>e.net!==void 0&&e.net===t.net;function pj(e,t){return e.flatMap(e=>e.shapes.map(n=>({piece:e,shape:n,box:fi(n),rank:t(e)})))}function mj(e,t){let n=[...new Set(e.map(e=>e.className))].sort(Vr);return n.flatMap(e=>n.map(n=>$h(t,e,n))).reduce((e,t)=>Math.max(e,t),t.fabrication.minClearance)}function hj(e,t){return t.piece===e.piece||fj(e.piece,t.piece)?!1:t.rank===-1||t.rank>e.rank}function gj(e,t){return Vr(e.piece.id,t.piece.id)<=0?[e,t]:[t,e]}function _j(e,t,n){let[r,i]=gj(t,n),a=`${r.piece.id}|${i.piece.id}`,o=li(r.shape,i.shape),s=e.get(a);(s===void 0||o<s.distance)&&e.set(a,{a:r,b:i,distance:o})}function vj(e,t,n,r){let i=new _b(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(uj(n.box,t)))hj(n,e)&&_j(r,n,e)}function yj({a:e,b:t}){if(e.piece.kind!==`pad`&&t.piece.kind!==`pad`)return Db(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=>Db(n.shape,{core:[e],radius:0}))}function bj(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 xj(e,t,n,r){return $h({...e,fabrication:{...e.fabrication,minClearance:0}},t,n)<r?`the fabrication minimum is ${oj(r)} mm`:`${bj(e,t,n)} needs ${oj(r)} mm`}var Sj=({a:e,b:t})=>e.piece.net!==void 0&&t.piece.net!==void 0&&e.piece.net!==t.piece.net;function Cj(e,t){if(yj(e)&&!Sj(e))return;let{a:n,b:r,distance:i}=e,a=$h(t,n.piece.className,r.piece.className);return ij(i,a)?cj(`copper-clearance`,`${n.piece.id} and ${r.piece.id} are ${sj(i)}; ${xj(t,n.piece.className,r.piece.className,a)}`,[n.piece.id,r.piece.id],[n.piece.id,r.piece.id],dj(di(n.shape,r.shape))):void 0}var wj=e=>t=>t.piece.layers.includes(e);function Tj(e,t,n){if(e.length===0)return[];let r=new Map(e.map((e,t)=>[e,t])),i=[...pj(e,e=>r.get(e)??-1),...pj(t,()=>-1)],a=mj([...e,...t],n),o=Math.max(lj,a),s=new Map;for(let e of hb){let t=i.filter(wj(e));t.some(e=>e.rank!==-1)&&vj(t,a,o,s)}return[...s.keys()].sort(Vr).flatMap(e=>Cj(s.get(e),n)??[])}var Ej=e=>e===void 0?{}:{net:e};function Dj(e){return e.layers===`through`?hb:[e.layers]}function Oj(e,t){let n=$r(e);if(n===void 0)return;let r=e.net===void 0?Gh.name:t(e.net);return{id:e.id,kind:`pad`,...Ej(e.net),className:r,layers:Dj(e),shapes:[n],at:{x:e.x,y:e.y}}}function kj(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 Aj(e,t){let n=e.points[0]??{x:0,y:0};return{id:e.id,kind:`track`,...Ej(e.net),className:t(e.net),layers:[e.layer],shapes:kj(e),at:n,pads:e.pads}}function jj(e,t){let n={core:[e.at],radius:e.diameter/2};return{id:e.id,kind:`via`,...Ej(e.net),className:t(e.net),layers:[...wb(e)],shapes:[n],at:e.at}}function Mj(e,t){return e.parts.flatMap(e=>e.pads).flatMap(e=>Oj(e,t)??[])}function Nj(e,t){let n=e=>e.missingLayer===void 0;return[...e.tracks.filter(n).map(e=>Aj(e,t)),...e.vias.filter(n).map(e=>jj(e,t))].filter(e=>e.shapes.length>0).sort((e,t)=>Vr(e.id,t.id))}function Pj(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=li(r,a);o<n.distance&&(n={distance:o,at:di(r,a)[1]})});return n}function Fj(e,t){return!oi(e,t)&&Pj([{core:[e],radius:0}],t).distance>1e-6}function Ij(e,t,n){let r=n.fabrication.boardEdgeClearance,i=(t,n)=>cj(`copper-edge`,t,[e.id],[e.id],n),a=e.shapes.flatMap(e=>e.core).find(e=>Fj(e,t));if(a!==void 0)return i(`${e.id} ${e.kind===`track`?`runs`:`is`} outside the board`,a);let{distance:o,at:s}=Pj(e.shapes,t);if(ij(o,r))return i(o>0?`${e.id} is ${oj(o)} mm from the board edge; the minimum is ${oj(r)} mm`:`${e.id} crosses the board edge; the minimum gap to it is ${oj(r)} mm`,s)}var Lj=(e,t)=>e.layers===`all`||t.layers.includes(e.layers);function Rj(e,t){let n=e.core.find(e=>oi(e,t));if(n!==void 0)return n;let r={core:[...t],radius:0};return li(e,r)<-1e-6?di(e,r)[1]:void 0}function zj(e,t){if(!Lj(t,e))return;let n=e.shapes.map(e=>Rj(e,t.outline)).find(e=>e!==void 0);if(n!==void 0)return cj(`copper-keepout`,`${e.id} lies inside ${t.id}`,[e.id,t.id],[e.id,t.id],n)}var Bj=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY,Vj=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function Hj(e){return e.map(fi).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 Uj({layout:e,rules:t,classOf:n}){let r=[t.fabrication.minClearance,Gh.clearance,...t.classes.map(e=>e.clearance),...t.classClearance.map(e=>e.clearance)];return{copper:Nj(e,n),pads:Mj(e,n),reach:Math.max(...r)}}var Wj=(e,t)=>t.slice(1).map((n,r)=>({core:[t[r],n],radius:e.width/2}));function Gj(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:Wj(e,t),at:t[0],pads:e.pads}}var Kj=(e,t)=>e.shapes.some(e=>t.some(t=>Db(e,t)));function qj(e,t,n,r){return e.some(e=>e.net===t.net&&Kj(e,n)&&!Kj(e,r.shapes))}function Jj(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 Yj(e,t){let n=t.layout.board;if(n===void 0)return;if(qr(n)&&Ij(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&&zj(r,e));return i?`too close to ${i.id}`:void 0}function Xj(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=Gj(n,r,e.classOf),l=Wj(n,o),u=Vj(Hj([...c.shapes,...l]),t.reach+n.width),d=e=>Bj(Hj(e.shapes),u),[f,p]=[i.filter(d),a.filter(d)];if(qj([...f,...p],n,l,c))return s;let m=Tj([c,...f],p,e.rules).find(e=>e.items.includes(n.id));return m?`too close to ${Jj(m.items,n,[...f,...p],e)}`:Yj(c,e)}}var Zj=(e,t)=>[t[0],e,t.at(-1)];function Qj(e,t,n){let r=Xj(e,t,n);return(e,t)=>r(t,Zj(e,t),`joined on the corner's legs`)}function $j(e,t,n){let r=Xj(e,t,n);return(e,t)=>r(Zj(e,t),t,`joined on the arc`)}var eM=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function tM(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?on(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?Eb(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 nM=(e,t)=>[e,...t].join(`; `);function rM(e){let t=Xh(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?Gh.name:t.get(e)??Gh.name,netName:e=>n.get(e)??e}}function iM(e,t={}){let{tracks:n,skipped:r}=tM(e,t);if(n.length===0)return{changes:[],summary:nM(`No tracks to round`,r)};let i=t.radius??og(e.rules),a=rM(e),o=Uj(a),s=[],c=[],[l,u]=[0,0];for(let e of n){let t=iA(e.points,i,e.width,Qj(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:nM(`No square corners to round`,r)}:{changes:s,summary:nM(l===0?`No corner was rounded`:`Rounded ${eM(l,`corner`)} on ${eM(s.length,`track`)}`,[...u===0?[]:[`${u} left square: ${c.join(`, `)}`],...r])}}function aM(e,t={}){let{tracks:n,skipped:r}=tM(e,t),i=rM(e),a=Uj(i),o=[],s=[],[c,l]=[0,0];for(let e of n){let t=aA(e.points,$j(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:nM(`No rounded corners to straighten`,r)}:{changes:o,summary:nM(c===0?`No corner was straightened`:`Straightened ${eM(c,`corner`)} on ${eM(o.length,`track`)}`,[...l===0?[]:[`${l} kept round: ${s.join(`, `)}`],...r])}}var oM={filletTracks:`Fillet`,straightenTracks:`Straighten`};function sM(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 ${oM[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:`${oM[e]} ${i}?`}}function cM(e,t,n,r){let i={...n?{ids:n}:{},lockedParts:r},a=e===`filletTracks`?iM(t,i):aM(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 lM(e,t){if(e.busy())return e.notify(`Wait for the last copper change to land, then try again.`);let n=nj(e.design,tj(),e.builtMark),r=sM(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=cM(t,n,r.ids,e.lockedParts);if(`message`in i)return e.notify(i.message);e.send(i),e.notify(i.summary)}function uM(e){let t=(0,l.useRef)(e);t.current=e,lb({filletTracks:()=>lM(t.current,`filletTracks`),straightenTracks:()=>lM(t.current,`straightenTracks`)}),(0,l.useEffect)(()=>{let e=e=>{if(t.current.routing||e.repeat)return;let n=rd(Hu(e),{view:`pcb`})?.action;(n===`filletTracks`||n===`straightenTracks`)&&(e.preventDefault(),lM(t.current,n))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[])}function dM(e){let t=e.withoutTexts(e.texts);return t.total===0&&e.total>0?void 0:t}var fM=`Deleted in two changes: the copper in the layout file, the rest in the circuit file.`;function pM(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 mM(e,t,n){return e>0?{removeCopper:!0,notice:t}:n?{removeCopper:!1}:{removeCopper:!1,notice:t}}var hM=`Select a part or a wire first.`,gM=e=>[...new Set(e)];function _M(e,t){let n=e?.withWires.filter(e=>t.has(e.wire)).map(e=>e.label)??[];return new Set([...e?.withParts??[],...n])}function vM(e,t,n,r,i,a){if(e.total===0)return{message:hM};let o=dt(e.names,t),s=new Set(o.parts),c=r&&e.labelCount>0?r(e.labels,s):void 0,l=gM([...e.wires,...c?.withWires.map(e=>e.wire)??[]]),u=n&&l.length>0?n(l,s,new Set(o.skipped)):void 0,d=gM([...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 ${Qe([...o.parts,...$e(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=_M(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:ft(o.parts,(u?.removed??[]).filter(t=>e.hasWire(t)).length)}:{}}}var yM=new Set;function bM(e){return yM.add(e),()=>{yM.delete(e)}}function xM(e){for(let t of yM)t(e);return e}var SM=e=>(e.minX+e.maxX)/2,CM=e=>(e.minY+e.maxY)/2,wM=e=>e.maxX-e.minX,TM=e=>e.maxY-e.minY;function EM(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 DM(e,t){let[n,r,i]=t===`x`?[`minX`,`maxX`,wM]:[`minY`,`maxY`,TM],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 OM(e,t){let n=be(t.map(e=>e.box));if(!n)return new Map;switch(e){case`alignLeft`:return EM(t,`x`,()=>n.minX,e=>e.minX);case`alignRight`:return EM(t,`x`,()=>n.maxX,e=>e.maxX);case`alignTop`:return EM(t,`y`,()=>n.maxY,e=>e.maxY);case`alignBottom`:return EM(t,`y`,()=>n.minY,e=>e.minY);case`alignHCentres`:return EM(t,`y`,()=>CM(n),CM);case`alignVCentres`:return EM(t,`x`,()=>SM(n),SM);case`distributeH`:return DM(t,`x`);case`distributeV`:return DM(t,`y`)}}var kM={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 AM(e,t,n){return kM[e].replace(`{}`,Qe(t))+Ce[n].where}function jM(e,t,n,r,i){let[a,o]=Ce[n].position,[s,c]=ke(e,t,n,rt(r.anchors,r.boxes)(t),i);return{[a]:s,[o]:c}}function MM(e,t,n,r,i,a){let o=ct(r),s=r.boxes.filter(e=>t.includes(e.name)),c=new Set(s.map(e=>e.name)),l=t.filter(e=>!c.has(e)).map(e=>`${e} ${o(e)?`has no box in`:`is not in`} this view`),u=y(i);if(s.length<u){let e=l.length>0?` (${l.join(`; `)})`:``;return{message:`${u===2?`Align`:`Distribute`} needs ${u} or more parts in this view${e}.`}}let d=OM(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:jM(e,t,n,r,d.get(t))})),summary:AM(i,m,n),parts:m,skipped:h,done:`moved`}}function NM(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??we;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 PM(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)}:we,{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 FM=e=>`${e.x},${e.y}`;function IM(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:Mr(i[i.length-2],a)}:n.has(FM(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 LM(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(FM))),r=new Map((t.wires??[]).map(e=>[`label:${e.id.slice(5)}`,e.points])),i=e.labels.map(e=>IM(e,r,n,t.offset));return i.every(e=>e===void 0)?e.labels:e.labels.map((e,t)=>({...e,...i[t]}))}function RM(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 zM(e,t,n,r){let i=e.gate.waiting;n.edits.length>0&&(e.gate=iD(e.gate));let{seq:a}=e.gate;return gt(n,r.actions).then(({ok:r,mark:o})=>(n.edits.length>0&&(e.gate=aD(e.gate,r,a,i,o)),RM(e,t),t.resolved(),r))}function BM(e,t,n,r){let i=lt(n.circuit,n.selection.names,n.view,n.layout,n.blockerFor,r);if(`message`in i)return n.actions.notify(i.message);zM(e,t,i,n)}function VM(e,t,n,r){let i=MM(n.circuit,n.selection.names,n.view,n.layout,r,n.blockerFor);if(`message`in i)return n.actions.notify(i.message);zM(e,t,xO(i,n.circuit,n.follow),n)}function HM(e,t,n,r){r===`rotate`?BM(e,t,n,90):r===`rotateRight`?BM(e,t,n,-90):VM(e,t,n,r)}function UM(e,t,n,r,i){let a=nD(e.gate,n.selection.names,i,n);e.gate=a.gate,a.send?HM(e,t,n,r):i||(e.queue=(e.gate.held?.count??0)>1?[...e.queue,r]:[r]),RM(e,t)}function WM(e,t,n,r){let{burst:i,layout:a}=e;if(!i||!a)return;let o=ut(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}=bO(o,i.base,n.follow,s),f=zM(e,t,c,n);n.follow&&c.edits.length>0&&t.moved?.(NM(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?QE(e.burst,r):void 0;e.burst=a?.burst,a?.send&&WM(e,t,n,a.send)})}function GM(e,t,n,r){let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=ZE(e.burst,n.circuit,i,r,a,o,s);e.burst=c.burst,c.fresh&&(e.layout=n.layout),c.send&&WM(e,t,n,c.send)}function KM(e,t,n){let r={waiting:e.gate.waiting,history:e.gate.history};e.gate=oD(e.gate),e.burst=void 0;let{seq:i}=e.gate;n.catch(()=>({ok:!1})).then(({ok:n,mark:a})=>{e.gate=sD(e.gate,n,i,r,a),RM(e,t),t.resolved()})}function qM(e){let t={gate:$E,told:!1,queue:[]};return{nudge(n,r){let i=Iu(r.action);if(!i||n.selection.total===0)return;let a=it(i,n.layout.step,r.steps??1,n.layout.snap!==!1),o=cD(t.gate,n);t.gate=o.gate,o.send?GM(t,e,n,a):t.arrows=lD(t.arrows,n.selection.names,a,n.selection.wires,n.selection.labels,n.selection.drawings),RM(t,e)},rotate(n,r){UM(t,e,n,`rotate`,r)},rotateRight(n){UM(t,e,n,`rotateRight`,!1)},align(n,r){UM(t,e,n,r,!1)},settle(n){let r=rD(t.gate,n.selection.names,n);t.gate=r.gate,r.send&&HM(t,e,n,t.queue.shift()??`rotate`);let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=uD(t.gate,t.arrows,i,n,a,o,s);t.gate=c.gate,t.arrows=c.held,c.send&&GM(t,e,n,c.send),RM(t,e)},historyWrite:n=>KM(t,e,n)}}function JM(e){let[t,n]=(0,l.useState)(0),[r,i]=(0,l.useState)(!1),[a,o]=(0,l.useState)(),[s]=(0,l.useState)(()=>qM({resolved:()=>n(e=>e+1),holding:i,moved:(e,t)=>{let n={...e,sentAt:Date.now()};o(n),t.then(e=>e||o(e=>e===n?void 0:e))}})),{builtMark:c,buildStatus:u,moveWaiting:d,circuit:f}=e;return(0,l.useEffect)(()=>bM(e=>s.historyWrite(e)),[s]),(0,l.useEffect)(()=>s.settle(e),[s,c,u,d,f,t]),{edits:s,held:r,moved:a}}function YM(e,t){let n=dM(e.selection);if(e.paused||!n)return;let{copper:r,rest:i}=pM(n,e.copper!==void 0),a=()=>r.length>0?e.copper?.remove(r):void 0;if(!i)return a();let o=vM(i,e.blockerFor,e.wire?.removal,e.wire?.labelRemoval,e.drawings,e.board);if(`message`in o){let n=mM(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);ht(s,e.actions).then(t=>{t&&(e.onSelect(p),r.length>0&&e.actions.notify(fM))})}function XM(e,t,n){let r=e.texts&&Ld(e.selection,t,e.layout);if(!r)return n.nudge(e,t);e.texts?.nudge(r.id,r.by)}function ZM(e,t,n,r){let{action:i}=t;if(v(i))return e.paused||r?void 0:n.align(e,i);if(i.startsWith(`nudge`))return e.paused?void 0:XM(e,t,n);if(i===`fit`)return e.fit();if(i===`delete`)return YM(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 QM(e){let t=Lf(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 $M(e,t){let n=t=>()=>{e.paused||(e.selection.size>0?t(e):e.actions.notify(`Select a part first.`))};lb({...Object.fromEntries(g.map(n=>[n,()=>e.paused?void 0:t.align(e,n)])),fit:e.fit,rotate:n(e=>t.rotate(e,!1)),rotateRight:n(e=>t.rotateRight(e)),delete:()=>YM(e,!1),highlight:()=>QM(e)})}function eN(e){let{edits:t,held:n,moved:r}=JM(e);$M(e,t);let{view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:u,blockerFor:d,layout:f,builtMark:p,buildStatus:m,moveWaiting:h,fit:g,netUnderPointer:_,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee}=e;return(0,l.useEffect)(()=>{let e={view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:u,blockerFor:d,layout:f,builtMark:p,buildStatus:m,moveWaiting:h,fit:g,netUnderPointer:_,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee},n=n=>{let r=rd(Hu(n),{view:i,drawing:o});r&&(fD(r.action,a.size,o,r.preventDefault,a.total)&&n.preventDefault(),ZM(e,r,t,n.repeat))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,i,a,o,s,c,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,ee]),{rotateHeld:n,keyMove:r}}var tN={x:0,y:0};function nN(e,t,n){let r={id:e.id,start:n.point,moved:!1,offset:tN};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&&xl(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 rN(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 iN(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=ec(e.path,{x:e.world.x+e.last.x,y:e.world.y+e.last.y})?.index,r=n===void 0?void 0:Sa({id:t,points:e.path},n);return r&&(e=>e.onlySegment(r))}function aN(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:tN,names:r,copper:i,...n===void 0?{}:{part:n},...o?{origin:o}:{}}}function oN(e,t,n){let r=e=>ge(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 sN(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:Cv(e.points,e.grip,t,n)}:{...e,moved:!0,offset:oN(e.at??e.origin??tN,t,n)}}var cN=e=>e.kind===`group`?e.copper??[]:[e.id];function lN(e,t,n){return!e.moved||e.blocker?Ov:e.kind===`track`?e.path?{tracks:new Map([[e.id,e.path]]),vias:new Map}:Ov:Fv(t,cN(e),e.offset,n).shapes}function uN(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 dN(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?Iv(r,e.path):void 0;return!i||`message`in i?i:{edits:[i],summary:`Reshape track ${e.id}`,shapes:lN(e,t,n)}}let r=cN(e),i=Fv(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)??tN,o=e.kind===`group`?`Move ${Qe(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 fN(e,t){let[n,r]=(0,l.useState)([]),i=(0,l.useRef)(0);(0,l.useEffect)(()=>r(t=>Ok(t,e)),[e]);let a=(0,l.useMemo)(()=>Ak(n,e),[n,e]),o=(0,l.useMemo)(()=>jk(n,e),[n,e]),s=(0,l.useCallback)((e,t)=>{i.current+=1;let n=i.current;r(t=>Tk(t,n,e)),t.then(e=>r(t=>e.ok&&e.mark!==void 0?Ek(t,n,e.mark):Dk(t,n)))},[]);return{shapes:a,moving:o,send:(0,l.useCallback)(e=>s({shapes:e.shapes},t.editLayout(e.edits,e.summary)),[s,t]),sendParts:(0,l.useCallback)((e,t)=>s({shapes:Ov,parts:e},t),[s]),inFlight:kk(n)}}function pN(e){return(t,n)=>{let r=nf(e.pcb,t);return r!==void 0&&(r.layers===`through`||r.layers===n)}}function mN(e){(0,l.useEffect)(()=>{let t=t=>{let{input:n,shown:r,onPad:i,send:a,cancel:o,inFlight:s}=e.current;if(t.key===`Escape`&&o())return t.stopPropagation();let{copper:c}=n.selection;if(!Hv(n.selection,n.routing===!0))return;let l=rd(Hu(t),{view:`pcb`}),u=l&&Iu(l.action);if(!l||!u||(t.preventDefault(),t.stopPropagation(),t.repeat&&s))return;let d=it(u,n.step,l.steps??1,n.snap),f=Fv(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 ${Qe(c)} by (${d.x}, ${d.y})`,shapes:f.shapes})};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function hN(e,t,n,r){let{camera:i,selection:a}=e;if(!i||r.button!==0||e.armed===`note`||e.armed===`zoom`)return;let o=yl(t,n,i.scale,e.layers,{selection:a,armed:e.armed,filter:e.filter});if(!o)return gN(e,n,r);if(Oa(r))return e.onSelect(e=>e.toggleCopper(o.id)),`toggled`;if(a.hasCopper(o.id)&&a.total>1)return aN({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=nN(o,t,{world:n,point:n,scale:i.scale,sole:s,width:c}),u=l&&rN(l,a.segment);return u?.segment===void 0&&e.onSelect(e=>e.onlyCopper(o.id)),u??`toggled`}function gN(e,t,n){let{selection:r,parts:i}=e;if(r.copper.length===0||Oa(n))return;let a=i.selectedAt(t);if(a!==void 0&&i.blockerFor(a)===null)return aN({part:a,names:r.names,copper:r.copper,start:t,origin:i.originOf(a)})}function _N(e,t,n){let r=Rv(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 vN(e,t,n){let{segment:r}=e.selection;if(r&&n.length===1&&n[0]===r.id)return _N(e,t,r);let{edits:i,removed:a,skipped:o}=Lv(t,n);o.length>0&&e.actions.notify(`Not removed: ${o.join(`; `)}`),i.length!==0&&e.actions.editLayout(i,`Remove ${Qe(a)}`).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper(a)))}function yN(e){let{design:t,builtMark:n,actions:r,selection:i}=e,a=fN(n,r),o=(0,l.useMemo)(()=>Bv(t.pcb,a.shapes),[t,a.shapes]),s=(0,l.useMemo)(()=>pN(t),[t]),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(),p=(0,l.useRef)(void 0),m=e=>{p.current=e,u(e)},h={input:e,shown:o,onPad:s,send:a.send,sendParts:a.sendParts,cancel:()=>p.current?(m(void 0),!0):!1,inFlight:a.inFlight},g=(0,l.useRef)(h);g.current=h,mN(g),bN(o.tracks,i,e.onSelect);let _=(0,l.useMemo)(()=>c?Bv(o,lN(c,o,s)):o,[c,o,s]);return{scene:{tracks:_.tracks,vias:_.vias,selected:new Set(i.copper),...i.segment?{segment:i.segment}:{},...d===void 0?{}:{hover:d}},shown:o,drag:c,hover:d,setHover:f,put:m,dragRef:p,latest:g,keys:(0,l.useMemo)(()=>({remove:e=>vN(g.current.input,g.current.shown,e)}),[]),moving:(0,l.useMemo)(()=>xN(c,e.parts)??a.moving,[c,e.parts,a.moving])}}function bN(e,t,n){let r=Da(t,e)!==t;(0,l.useEffect)(()=>{r&&n(t=>Da(t,e))},[r,e,n])}function xN(e,t){let n=e&&uN(e);return n&&{names:n.names.filter(e=>t.blockerFor(e)===null),offset:n.offset}}function SN(e,t){let{input:n,shown:r}=e.latest.current,i=n.camera&&yl(r,t,n.camera.scale,n.layers,{selection:Ea.none,armed:n.armed,filter:n.filter});return i?i.id:void 0}function CN(e,t){let{input:n,shown:r}=e.latest.current;return n.camera&&bl(r,t,n.camera.scale,n.layers,{selection:n.selection,armed:n.armed,filter:n.filter})}function wN(e,t){let n=SN(e,t);return e.setHover(n),n!==void 0}function TN(e){return(t,n)=>{let{input:r,shown:i}=e.latest.current,a=hN(r,i,n,t);return a&&a!==`toggled`&&e.put(a),a!==void 0}}function EN(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(sN(t,i,{step:r.step,snap:r.snap},e=>r.actions.notify(e)))}function DN(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(ON(t));let s=iN(t);s&&n.onSelect(s);let c=uN(t);c&&o(c,n.parts.move(c.names,c.offset));let l=dN(t,r,i);l&&(`message`in l?n.actions.notify(l.message):a(l))}function ON(e){return t=>e.part===void 0?e.id?t.onlyCopper(e.id):t:t.only(e.part)}function kN(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?de(n.camera,n.size,ME(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);ie.refuses()||EN(e,a,o)},onPointerUp:n=>{let r=e.dragRef.current;r?DN(e,r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function AN(e){return e.drag?e.drag.blocker?`not-allowed`:`move`:e.hover===void 0?void 0:`pointer`}var jN={phase:`idle`};function MN(e,t,n,r){return e.phase===`shown`&&r?{...e,at:t}:e.phase===`dismissed`&&r?e:{phase:`waiting`,at:t,since:n}}function NN(e,t){switch(t.kind){case`move`:return MN(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}:jN;case`key`:case`press`:return e.phase===`shown`||e.phase===`dismissed`?{phase:`dismissed`,target:e.target}:jN;case`leave`:case`stale`:case`busy`:return jN}}function PN(e,t){return e.phase===`waiting`?Math.max(0,e.since+250-t):void 0}var FN=e=>e.phase===`shown`||e.phase===`dismissed`;function IN(e){if(e.phase===`shown`)return{text:e.target.text,left:e.at.x+12,top:e.at.y+12}}function LN(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 RN=1;function zN(e,t,n){let r=jN,i,a,o=!1,s=!1,c=()=>{a!==void 0&&e.clearTimer(a),a=void 0},l=()=>{c();let t=PN(r,e.now());t!==void 0&&(a=e.setTimer(d,t+RN))},u=e=>{let n=NN(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=FN(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 BN(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 VN={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 HN({enabled:e,busy:t,probe:n,camera:r,design:i}){let[a,o]=(0,l.useState)(jN),s=(0,l.useRef)(n);s.current=n;let c=(0,l.useRef)(void 0);return(0,l.useEffect)(()=>{let e=zN(VN,o,()=>s.current);return c.current=e,()=>{e.dispose(),c.current=void 0}},[]),(0,l.useEffect)(()=>c.current?.quiet(!e||t),[e,t]),(0,l.useEffect)(()=>c.current?.stale(),[r,i]),{state:a,...(0,l.useMemo)(()=>({move:(e,t)=>c.current?.move(e,t),leave:()=>c.current?.leave(),press:()=>c.current?.press(),stale:()=>c.current?.stale(),over:e=>c.current?.over(e)}),[])}}function UN({state:e}){let t=IN(e),n=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let e=n.current,r=e?.parentElement;if(!e||!r||!t)return;let i=LN(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,Z.jsx)(`div`,{ref:n,className:`hover-label`,role:`tooltip`,style:{left:t.left,top:t.top},children:t.text}):null}var WN=` · `;function GN(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 KN=e=>`${Number(e.toFixed(4))} mm`,qN=(e,t)=>e.circuit.components.find(e=>e.id===t);function JN(e,t){let n=qN(e,t.component),r=n?.pins.find(e=>e.id===t.pin),i=r&&On(n?.props??{},r.number),a=n?.instance===void 0?``:` [${n.instance}]`;return`${t.component}.${t.number}${i?` ${i}`:``}${WN}${GN(e,t.net)}${a}`}var YN=(e,t)=>`via ${t.id}${WN}${GN(e,t.net)}${WN}${t.layers[0]}–${t.layers.at(-1)}`;function XN(e,t){return`track ${t.id}${WN}${GN(e,t.net)}${WN}${KN(t.width)}${WN}${t.layer}${t.by===`router`?`${WN}routed`:``}`}var ZN=new Set;function QN(e,t){let{design:n,scale:r,layers:i,context:a}=t;if(!Zi({kind:`pour`,id:``},a))return;let o=n.pcb.holes?.find(t=>t.id===Yl(n.pcb.holes??[],e,r,i.visible));return o?{kind:`hole`,id:o.id,text:Wl(o)}:$N(n,ql(n,e,r,i.visible,t.pours?.hidden??ZN))}function $N(e,t){let n=t===void 0?void 0:zl(e).find(e=>e.id===t);return n&&{kind:`pour`,id:n.id,text:Hl(e,n)}}function eP(e,t){let{design:n,layers:r,context:i}=t;if(n.pcb.pours&&Zi({kind:`pour`,id:``},i))return $N(n,Ql(n,e,r.visible,t.pours?.hidden??ZN,t.pours?.activeLayer))}function tP(e,t){let{design:n,copper:r,scale:i,layers:a,context:o}=t;if(EO(t.boxes,e,o,t.texts))return;let s=yl(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:YN(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:XN(n,l)};let u=QN(e,t);if(u)return u;let d=nf(n.pcb,e,a.visible,e=>Zi({kind:`part`,name:e},o));return d?{kind:`pad`,id:d.id,text:JN(n,d)}:eP(e,t)}function nP(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 rP=(e,t)=>`${t.component}.${On(qN(e,t.component)?.props??{},t.number)??`pin${t.number}`}`;function iP(e,t){let n=e.circuit.nets.find(e=>e.pins.includes(t.id));return`${rP(e,t)}${WN}${GN(e,n?.id)}`}function aP(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}${WN}${e.bus?`bus ${e.net}`:e.net}`}}}function oP(e,t){let{design:n}=t,r=Bn(n,e,12/t.scale),i=r&&n.schematic.symbols.find(e=>r.pin in e.pinEnds);if(!r||!i||!Zi({kind:`part`,name:i.component},t.context))return;let a=qN(n,i.component)?.pins.find(e=>e.id===r.pin);return a?{kind:`pin`,id:a.id,text:iP(n,a)}:aP(n,r.pin)}function sP(e,t,n){let r=oP(t,n);if(!r)return e;let i=r.text.slice(0,r.text.indexOf(WN));return{...e,text:`${e.text}${WN}pin ${i}`,pin:r.id}}function cP(e,t){let{design:n}=t,r=TO(t.boxes,t.labels,e,t.context,t.wires,t.drawings,t.texts);if(r.kind===`label`)return sP({kind:`label`,id:r.label.id,text:nP(n,r.label)},e,t);if(r.kind===`wire`){let i=n.schematic.wires.find(e=>e.id===r.id);return sP({kind:`wire`,id:r.id,text:`wire${WN}${GN(n,i?.net)}`},e,t)}return r.kind===`drawing`?void 0:oP(e,t)}function lP(e,t){return t.view===`pcb`?tP(e,t):cP(e,t)}function uP(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)<=hl(n.diameter,i)}if(e.kind===`track`){let n=r.tracks.find(t=>t.id===e.id);return n!==void 0&&tc(n.points,t,hl(n.width,i))!==void 0}if(e.kind===`hole`)return Yl(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 ql(n.design,t,i,n.layers.visible,n.pours?.hidden??ZN)===e.id||r!==void 0&&Zl(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&&Of(o,t)<=0}function dP(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 fP(e,t,n){return n.view===`pcb`?uP(e,t,n):dP(e,t,n)}function pP({value:e,onChange:t}){let n=(0,l.useId)();return(0,Z.jsxs)(`div`,{className:`hole-field`,onPointerDown:e=>e.stopPropagation(),children:[(0,Z.jsx)(`label`,{htmlFor:n,children:`Hole diameter (mm)`}),(0,Z.jsx)(`input`,{id:n,value:e,inputMode:`decimal`,spellCheck:!1,onChange:e=>t(e.target.value)})]})}var mP=.1,hP=e=>Math.round(e*1e4)/1e4||0,gP=(e,t)=>e.x===t.x&&e.y===t.y,_P=(e,t)=>hP(Math.hypot(t.x-e.x,t.y-e.y));function vP(e,t){return hP((Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI%360+360)%360)%360}var yP=e=>({tool:e,points:[],flip:!1,dragging:!1});function bP(e,t,n){let r=_e(e,t,n);return{x:hP(r.x),y:hP(r.y)}}function xP(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 SP(e,t){return(e?.tool===`text`||e?.naming===!0)&&t===0}function CP(e,t,n){let r=e.points.at(-1);if(!r)return[t];let i=n?bn([r,t],[e.flip]).slice(1):[t];return[...e.points,...i.map(e=>({x:hP(e.x),y:hP(e.y)}))].filter((e,t,n)=>t===0||!gP(e,n[t-1]))}function wP(e,t){let[n,r]=[hP(Math.abs(t.x-e.x)),hP(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 TP(e,t,n){let[r,i]=[vP(e,t),vP(e,n)];if(!(gP(n,e)||r===i))return{x:e.x,y:e.y,radius:_P(e,t),startAngle:r,endAngle:i}}var EP=(e,t)=>({state:yP(e),drawing:t}),DP=e=>({state:e});function OP(e){return e.points.length<2?DP(yP(e.tool)):e.tool===`bus`?DP({...e,naming:!0}):EP(`polyline`,{tag:`schematicpath`,props:{points:[...e.points]}})}function kP(e,t){return e.naming?DP(e):t.double&&e.points.length>0?OP(e):DP({...e,points:CP(e,t.at,t.shift)})}function AP(e,t){let[n]=e.points;if(!n)return DP({...e,points:[t],dragging:!0});let r=wP(n,t);return r?EP(`rectangle`,{tag:`schematicrect`,props:r}):DP(e)}function jP(e,t){let[n]=e.points;if(!n)return DP({...e,points:[t]});let r=_P(n,t);return r>0?EP(`circle`,{tag:`schematiccircle`,props:{x:n.x,y:n.y,radius:r}}):DP(e)}function MP(e,t){let[n,r]=e.points;if(!n)return DP({...e,points:[t]});if(!r)return gP(t,n)?DP(e):DP({...e,points:[n,t]});let i=TP(n,r,t);return i?EP(`arc`,{tag:`schematicarc`,props:i}):DP(e)}function NP(e,t){switch(e.tool){case`bus`:case`polyline`:return kP(e,t);case`rectangle`:return AP(e,t.at);case`circle`:return jP(e,t.at);case`arc`:return MP(e,t.at);case`text`:return DP({...e,points:[t.at]})}}function PP(e,t){let[n]=e.points;if(e.tool!==`rectangle`||!e.dragging||!n)return DP(e);let r=wP(n,t);return r?EP(`rectangle`,{tag:`schematicrect`,props:r}):DP({...e,dragging:!1})}function FP(e,t){let n=t.trim();return!e.naming||Yt(n)===void 0?DP(e):EP(`bus`,{tag:`bus`,name:n,props:{points:[...e.points]}})}function IP(e,t){if(e.tool===`bus`)return FP(e,t);let[n]=e.points,r=t.trim();return e.tool!==`text`||!n||r===``?DP(yP(e.tool)):EP(`text`,{tag:`schematictext`,props:{x:n.x,y:n.y,text:r,fontSize:mP,anchor:`left`}})}function LP(e,t){switch(t.type){case`press`:return NP(e,t);case`release`:return PP(e,t.at);case`finish`:return(e.tool===`polyline`||e.tool===`bus`)&&!e.naming?OP(e):DP(e);case`removeCorner`:return e.naming?DP(e):DP(e.points.length<=1?yP(e.tool):{...e,points:e.points.slice(0,-1)});case`flip`:return DP(e.naming?e:{...e,flip:!e.flip});case`cancel`:return{state:e.points.length>0?yP(e.tool):null};case`text`:return IP(e,t.text)}}var RP={file:``,line:0,column:0,offset:0},zP={strokeWidth:.01,lineStyle:`dashed`,groupOffset:{x:0,y:0},source:RP};function BP(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]:CP(e,t,n),groupOffset:zP.groupOffset,source:RP};if(e.tool===`polyline`)return{id:a,kind:`path`,points:CP(e,t,n),...zP};if(e.tool===`rectangle`){let e=wP(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,...zP}}if(e.tool===`circle`)return{id:a,kind:`circle`,x:r.x,y:r.y,radius:_P(r,t),filled:!1,...zP};if(e.tool!==`arc`)return;if(!i)return{id:a,kind:`path`,points:[r,t],...zP};let o=TP(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,...zP}}function VP(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:Yt(e.name??``)??[],points:n.points??[],groupOffset:zP.groupOffset,source:RP};case`schematicpath`:return{id:t,kind:`path`,points:n.points??[],...zP};case`schematicrect`:return{...i,kind:`rect`,width:r(`width`),height:r(`height`),filled:!1,...zP};case`schematiccircle`:return{...i,kind:`circle`,radius:r(`radius`),filled:!1,...zP};case`schematicarc`:return{...i,kind:`arc`,radius:r(`radius`),startAngle:r(`startAngle`),endAngle:r(`endAngle`),...zP};case`schematictext`:return{...i,kind:`text`,text:String(n.text??``),fontSize:mP,anchor:`left`,groupOffset:zP.groupOffset,source:RP}}}var HP=/^G(\d+)$/;function UP(e,t,n=[]){if(e.name!==void 0)return{kind:`addDrawing`,tag:e.tag,name:e.name,props:e.props};let r=Number(HP.exec(AC(t))?.[1]??1),i=Math.max(r-1,...n.map(e=>Number(HP.exec(e)?.[1]??0)));return{kind:`addDrawing`,tag:e.tag,name:`G${i+1}`,props:e.props}}var WP={bus:`bus`,polyline:`line`,rectangle:`rectangle`,circle:`circle`,arc:`arc`,text:`text`},GP=(e,t)=>`add the ${WP[e]} ${t}`,KP=`Esc or a right click stops.`,qP=`Esc cancels.`,JP={bus:`Click to start a bus, Enter to finish, then name it. ${KP}`,polyline:`Click to start a polyline, Enter to finish. ${KP}`,rectangle:`Drag, or click two opposite corners, to draw a rectangle. ${KP}`,circle:`Click the centre of a circle. ${KP}`,arc:`Click the centre of an arc. ${KP}`,text:`Click where the text goes. ${KP}`},YP=`Click for each corner, double click or Enter to finish. Shift keeps a leg square and Space flips its bend; Backspace removes a corner, ${qP}`;function XP(e){if(!e)return;let t=e.points.length;return t===0?JP[e.tool]:e.naming?`Name the bus, such as D[0:7] or CLK; Enter writes it, ${qP}`:e.tool===`polyline`||e.tool===`bus`?YP:e.tool===`rectangle`?`Click the opposite corner. ${qP}`:e.tool===`circle`?`Click to set the radius. ${qP}`:e.tool===`text`?`Type the text; Enter writes it, ${qP}`:t===1?`Click where the arc starts. Backspace steps back, ${qP}`:`Click where the arc ends. Backspace steps back, ${qP}`}var ZP=e=>new Set(e.annotations.locks.map(e=>e.part));function QP(e,t){let[n,r]=(0,l.useState)(null),i=zl(e);return(0,l.useEffect)(()=>{n!==null&&i.some(e=>e.id===n)&&(t(e=>e.clear().onlyBoard(n)),r(null))},[i,n,t]),(0,l.useCallback)(e=>r(e),[])}var $P=e=>t=>(e.notify(`Not written: ${t instanceof Error?t.message:String(t)}`),!1);function eF(e,t){let[n,r]=(0,l.useState)(null),i=(0,l.useRef)(n);return i.current=n,{state:n,send:(0,l.useCallback)(e=>{let n=i.current;if(!n)return;let a=ay(n,e);i.current=a.state,r(a.state),(a.outline||a.hole||a.refused)&&t(a)},[t]),arm:(0,l.useCallback)(t=>{e(),i.current=$v(t),r(i.current)},[e]),disarm:(0,l.useCallback)(()=>{i.current=null,r(null)},[])}}function tF(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{e.key!==`Escape`||Hu(e).typing||(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?rd(Hu(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 nF(e,t){let n=(0,l.useRef)(t);n.current=t,(0,l.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),n.current())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function rF(e,t){let{input:n}=e,r=sy(n.design);if(r===void 0)return n.actions.notify(`The circuit has no net for a copper pour yet.`);let i=Xv(n.circuit.model.boardItems??[],`copperpour`);n.actions.edit([cy(r,n.activeLayer,t)],ly(r,n.activeLayer,t===void 0)).catch($P(n.actions)).then(t=>t&&e.waitForPour(i))}function iF(e,t){let n=fy(e.diameter);if(typeof n!=`number`)return e.input.actions.notify(n.message);e.input.actions.edit([uy(t,n)],dy(n)).catch($P(e.input.actions))}function aF(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`||!Zi({kind:`pour`,id:``},{selection:o,armed:r.armed,filter:r.filter}))return!1;let s=Yl(a.pcb.holes,n,i.scale,r.layers)??ql(a,n,i.scale,r.layers,r.hidden);return s!==void 0&&(r.onSelect(e=>Oa(t)?e.toggleBoard(s):e.onlyBoard(s)),!0)}function oF(e,t,n,r){let{input:i}=e,a=i.selection.soleBoard,o=a===void 0?void 0:zl(i.design).find(e=>e.id===a);if(!o?.outline||!i.camera||t.button!==0||Oa(t))return!1;let s=Jl(o.outline,n,i.camera.scale);if(s===void 0)return!1;let c=my(i.circuit.model,ZP(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 sF=e=>e.outline.map((t,n)=>n===e.index?e.to:t);function cF(e){let{design:t,circuit:n,onSelect:r}=e,[i,a]=(0,l.useState)(String(Zv)),o=QP(t,r),[s,c]=(0,l.useState)(),u=(0,l.useRef)(void 0),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)();(0,l.useEffect)(()=>m(void 0),[t]);let h=e=>{u.current=e,c(e)},g={input:e,diameter:i,drag:s,waitForPour:o},_=(0,l.useRef)(g);_.current=g;let v=(0,l.useCallback)(e=>{e.refused&&_.current.input.actions.notify(e.refused),e.outline&&rF(_.current,e.outline),e.hole&&iF(_.current,e.hole)},[]),y=eF(e.onArm,v);tF(y.state,y.send);let{disarm:b}=y;(0,l.useEffect)(()=>{e.othersArmed&&b()},[e.othersArmed,b]),nF(s!==void 0,()=>h(void 0)),lb({placePour:()=>y.arm(`pour`),placeHole:()=>y.arm(`hole`),placePourBoard:()=>rF(_.current,void 0)});let x=(0,l.useRef)(void 0),S=t=>_e(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=xP(x.current,r);return x.current=i?void 0:r,y.send({type:`press`,at:S(n),double:i}),!0},w=(0,l.useMemo)(()=>{let e=new Map;return p&&e.set(p.id,p.outline),s?.moved&&e.set(s.id,sF(s)),e},[p,s]),T=oy(y.state,e.cursor&&S(e.cursor)),E={mode:e.mode,hidden:e.hidden,selected:new Set(e.selection.board),...d===void 0?{}:{hover:d},activeLayer:e.activeLayer,outlines:w,...T.length>0?{preview:T}:{}},ee=(0,l.useMemo)(()=>_y(n.model,ZP(n)),[n]);return{state:y.state,armed:y.state!==null,busy:y.state!==null&&y.state.points.length>0,disarm:y.disarm,hint:yy(y.state),diameter:i,setDiameter:a,toolPress:C,cornerPress:(e,t)=>oF(_.current,e,t,h),pickPress:(e,t)=>aF(_.current,e,t),hoverAt:n=>{let{camera:r}=e,i={selection:e.selection,armed:e.armed,filter:e.filter},a=r&&Zi({kind:`pour`,id:``},i)?Yl(t.pcb.holes,n,r.scale,e.layers)??ql(t,n,r.scale,e.layers,e.hidden):void 0;return f(a),a!==void 0},clearHover:()=>f(void 0),hover:d,drag:s,dragRef:u,put:h,release:t=>{if(h(void 0),!t.moved)return;let n=py(t.id,t.outline,t.index,t.to);if(`message`in n)return e.actions.notify(n.message);m({id:t.id,outline:sF(t)}),e.actions.edit([n.edit],n.summary).catch($P(e.actions)).then(e=>e||m(void 0))},latest:_,scene:E,removal:ee,cursor:s?`move`:y.state?`crosshair`:d===void 0?void 0:`pointer`}}function lF(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?de(n.camera,n.size,ME(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);let{input:s}=e.latest.current,c=Math.hypot(o.x-a.start.x,o.y-a.start.y)*(s.camera?.scale??1)>=3;(a.moved||c)&&(ie.refuses()||e.put({...a,moved:!0,to:_e(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 uF(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 dF=U.background;function fF(e,t){let n=e.circuit.nets.find(e=>e.id===t.net)?.names[0];return`${_k(e,t)}${n?` on ${n}`:``}`}function pF(e,t,n){(0,l.useEffect)(()=>{R_({active:e,stop:()=>{t(),n()}})},[e,t,n]),(0,l.useEffect)(()=>B_,[])}function mF(e,t){let{design:n,camera:r,size:i,layers:a,hoverPad:o,moving:s,boxes:c,hover:u,selection:d,locked:f,circuit:p,gesture:m,highlightNets:h,markers:g,activeViolation:_,grid:v,copper:y,texts:b,pours:x}=t,S=(0,l.useMemo)(()=>Pd(n.pcb,b.moves),[n.pcb,b.moves]),C=(0,l.useMemo)(()=>h.length>0?h:o?.net?[o.net]:Nf,[h,o]);(0,l.useEffect)(()=>{if(!r)return;let t=IE(e.current,i,r,dF,(e,t,n,r)=>aE(e,t,n,v,r));if(!t)return;let{ctx:n,ratio:o}=t;tf(n,S,{camera:r,size:i},{ratio:o,layers:a,...C.length>0?{highlight:{nets:C}}:{},...s?{moving:{components:s.names,by:s.offset}}:{},violations:g,..._?{activeViolation:_}:{},copper:y,pours:x}),n.setTransform(o,0,0,o,0,0),LE(n,r,i,{view:`pcb`,boxes:c,moving:s,hover:u,selection:d,locked:f,marks:p.annotations.marks,gesture:m,look:oE,ratio:o}),gE(n,{camera:r,size:i},b.shown,{selected:d.texts,hover:m?void 0:b.hover},oE,o)},[e,S,r,i,a,C,s,c,u,d,f,p,m,g,_,v,y,b,x])}function hF({unit:e,step:t,setStep:n,keep:r}){return(0,Z.jsxs)(Y_,{children:[(0,Z.jsx)(GE,{step:t,options:vh(`pcb`,e),onChange:n}),(0,Z.jsx)(KE,{...r,title:`Write the faded parts' positions into the code as pcbX and pcbY`})]})}function gF(e,t,n,r,i){let[a,o]=(0,l.useState)(),[s,c]=(0,l.useState)(),[u,d]=(0,l.useState)();return{part:a,text:s,pad:u,at:a=>{let s={selection:Ea.none,armed:null,layers:n,filter:r},l=TO(t,void 0,a,s,void 0,void 0,i);o(l.kind===`part`?l.name:void 0),c(l.kind===`text`?l.id:void 0),d(nf(e.pcb,a,n.visible,e=>Zi({kind:`part`,name:e},s)))},leave:()=>{o(void 0),c(void 0),d(void 0)}}}function _F(e,t,n,r){let i=(0,l.useRef)(void 0);i.current=t;let a=(0,l.useCallback)(()=>i.current?Bf(e.pcb,i.current,n):void 0,[e,n]),o=(0,l.useCallback)(t=>Ff(e,t),[e]);return eN({...r,netUnderPointer:a,netsOf:o})}function vF({canvasRef:e,size:t,cursorStyle:n,pointer:r,onLeave:i,hint:a}){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(`div`,{className:`canvas-top`,children:(0,Z.jsx)(`div`,{className:`canvas-hint`,children:a})})]})}function yF({parts:e,circuit:t,actions:n,selection:r,armed:i,pick:a,pickFilter:o}){return(0,l.useMemo)(()=>({selectedAt:t=>{let n=TO(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)=>gt(nt(t,r,`pcb`,rt(e.anchors,e.boxes),i,e.blockerFor),n)}),[e,t,n,r,i,a,o])}function bF(e,t){return(0,l.useMemo)(()=>ye(e.pcb.board?.outline??[])??be(t.map(e=>e.box)),[e,t])}function xF({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=>EO(i,e,a,o),g=r=>{if(n.armed||t.armed)return;let o=h(r)?void 0:CN(e,r);if(o)return p(e=>e.onlySegment(o));if(!h(r)&&SN(e,r)!==void 0)return;let s=TO(i,void 0,r,a);s.kind===`part`&&f(s)},_=n=>{if(Px(`pcb`,n),m.at(n),h(n))return e.setHover(void 0),t.clearHover(),r.at(n);if(wN(e,n))return t.clearHover(),r.leave();r.at(n),t.hoverAt(n)},v=TN(e);return{pointer:BN(lF(t,kN(e,ok({camera:s,size:c,element:l,gestures:u,setCursor:d,hover:_,open:g,tool:uF({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 SF(e){let{design:t,builtFrom:n,builtMark:r,buildStatus:i,circuit:a,actions:o,selection:s,onSelect:c,highlight:u,onHighlight:d,unit:f,onToggleUnit:p,gridStyle:m,gridStep:h,snap:g,onGridStep:_,markers:v,activeViolation:y,focus:b,onFocused:x,layers:S,pickFilter:C}=e,w=(0,l.useRef)(null),T=(0,l.useRef)(null),E=jE(w),[ee,D]=(0,l.useState)(),O=(0,l.useMemo)(()=>({step:h,style:m}),[h,m]),k=(0,l.useMemo)(()=>Gi(t.pcb.parts,S),[t,S]),A=OE(t,`pcb`,a),{camera:j,setCamera:te,fit:M}=NE(w,E,bF(t,A.boxes));PE(`pcb`,b,j,te,x),sk({selection:s,boxes:A.boxes,size:E,setCamera:te,notify:o.notify});let ne={view:`pcb`,circuit:a,actions:o,onSelect:c,blockerFor:A.blockerFor},N=RA(),P=(0,l.useRef)(()=>void 0),F=mk((0,l.useCallback)(()=>{N.disarm(),P.current()},[N])),re=(0,l.useCallback)(()=>{F.disarm(),N.disarm()},[F,N]),ie=cF({design:t,circuit:a,actions:o,camera:j,size:E,canvas:T,cursor:ee,layers:S,hidden:e.hiddenPours,filter:C,armed:F.tool,othersArmed:F.armed||N.armed!==null,selection:s,onSelect:c,step:h,snap:g,activeLayer:e.activeLayer,mode:e.pourFill,onArm:re});P.current=ie.disarm;let I=yN({design:t,builtMark:r,parts:yF({parts:A,circuit:a,actions:o,selection:s,armed:F.tool,pick:k,pickFilter:C}),camera:j,size:E,canvas:T,layers:S,filter:C,armed:F.tool,selection:s,onSelect:c,actions:o,step:h,snap:g,routing:N.route!==null}),L=(0,l.useMemo)(()=>Cl(I.shown,S),[I.shown,S]);uM({design:t,builtMark:r,selection:s,lockedParts:A.locked,routing:N.route!==null,send:e=>I.latest.current.send(e),busy:()=>I.latest.current.inFlight,notify:o.notify});let R=QA({design:t,builtMark:r,copper:I.shown,camera:j,cursor:ee,step:h,snap:g,layers:S,activeLayer:e.activeLayer,onActiveLayer:e.onActiveLayer,locked:A.locked,actions:o,arm:N,onArm:F.disarm});pF(R.command??fk(F.which),F.disarm,N.disarm);let ae=(0,l.useCallback)(e=>{let n=t.pcb.parts.find(t=>t.component===e);return n!==void 0&&S[n.side===`top`?`topSilk`:`bottomSilk`]},[t,S]),oe=hD({view:`pcb`,design:t,circuit:a,actions:o,locked:A.locked,builtFrom:n,drawn:ae}),z=ik({...ne,camera:j,setCamera:te,size:E,boxes:A.boxes,anchors:A.anchors,step:h,snap:g,builtFrom:n,selection:s,tool:{armed:F.tool,disarm:F.disarm},layers:k,copper:L,copperAt:e=>SN(I,e),texts:oe.tools,filter:C,onContextMenu:R.armed?R.cancel:e.onContextMenu}),se=kE(A,h,g),ce=(0,l.useMemo)(()=>yE(s.copper,s.total,I.shown),[s,I.shown]),le=AE(T,s.primary,A.boxes,j,E,void 0,ce),{rotateHeld:ue}=_F(t,ee,S,{...ne,paused:R.routing||ie.busy,board:ie.removal,selection:s,layout:se,builtMark:r,buildStatus:i,moveWaiting:z.pending!==void 0,fit:M,onHighlight:d,menuPlace:le,onContextMenu:e.onContextMenu,copper:I.keys,texts:oe}),de=gF(t,A.boxes,k,C,oe.tools),{gesture:fe}=z,pe=gD(oe,fe),me=(0,l.useMemo)(()=>({...pe,hover:de.text}),[pe,de.text]),V=I.moving?{names:I.moving.names,offset:I.moving.offset}:z.moving,he={...I.scene,activeLayer:e.activeLayer,routes:R.routes};mF(T,{design:t,camera:j,size:E,layers:S,hoverPad:de.pad,moving:V,boxes:A.boxes,hover:de.part,selection:s,locked:A.locked,circuit:a,gesture:fe,highlightNets:u,markers:v,activeViolation:y,grid:O,copper:he,texts:me,pours:ie.scene});let ge={selection:s,armed:F.tool,layers:k,filter:C},_e=j&&{view:`pcb`,design:t,copper:I.shown,scale:j.scale,layers:k,context:ge,boxes:A.boxes,texts:oe.tools,pours:{hidden:e.hiddenPours,activeLayer:e.activeLayer}},ve=_e&&{pick:e=>lP(e,_e),still:(e,t)=>fP(e,t,_e)},ye=HN({enabled:e.hoverLabels,busy:R.routing,probe:ve,camera:j,design:t}),be={...ye,at:e=>j&&ye.move(e,B(j,E,e))},{pointer:xe,onLeave:Se}=xF({copper:I,pours:ie,track:R,hover:de,boxes:A.boxes,context:ge,texts:oe.tools,camera:j,size:E,canvasRef:T,gestures:z,setCursor:D,onOpenProperties:e.onOpenProperties,onSelect:c,label:be}),Ce=R.armed?`crosshair`:ie.cursor??AN(I)??ak(fe,F.armed,de.part!==void 0||de.text!==void 0);return(0,Z.jsxs)(`div`,{className:`pcb-canvas`,ref:w,children:[(0,Z.jsx)(vF,{canvasRef:T,size:E,cursorStyle:Ce,pointer:xe,onLeave:Se,hint:F.hint??ie.hint??R.hint}),ie.state?.tool===`hole`&&(0,Z.jsx)(pP,{value:ie.diameter,onChange:ie.setDiameter}),(0,Z.jsx)(UN,{state:ye.state}),(0,Z.jsx)(hF,{unit:f,step:h,setStep:_,keep:{show:A.autoPlaced,onKeep:()=>ze(t,`pcb`,A.blockerFor,o,a)}}),(0,Z.jsx)(qE,{cursor:ee,zoom:j?.scale,unit:f,onToggleUnit:p,detail:R.status??(de.pad&&fF(t,de.pad)),gesture:fe,rotateHeld:ue,snap:g})]})}function CF(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 wF({palette:e,camera:t,size:n}){let{editing:r}=e;if(!r||!t)return null;let i=B(t,n,r.at);return(0,Z.jsx)(TF,{at:i,initial:r.initial,palette:e},`${r.pin??r.rename?.id??`tab`}:${r.at.x}:${r.at.y}`)}function TF({at:e,initial:t,palette:n}){let[r,i]=(0,l.useState)(t),[a,o]=(0,l.useState)();return(0,Z.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,Z.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,Z.jsx)(`span`,{role:`alert`,children:a})]})}function EF(e){let t=e.gridFifth?{fifth:e.gridFifth}:{};return{lines:{minor:e.grid,...t},dots:{minor:e.gridDot,...t,px:2}}}function DF(e,t,n,r,i,a=K()){Mh(e,t,n,r,EF(a),i)}var OF=.12,kF=.09,AF=.14,jF=.06,MF=2,NF=[[`label`,kF],[`value`,AF]];function PF(e,t){return lo(`detail`,fo(e,t),uo(OF,e,t))}function FF(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=oo(o,s,i,a);e.strokeRect(c.x,c.y,c.width,c.height)}function IF(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:$a(e.x,a),y:e.y}:{x:e.x,y:$a(e.y,a)},[u,d]=[l(o),l(s)];e.moveTo(u.x,u.y),e.lineTo(d.x,d.y)}function LF(e,t,n,r){let i=uo(n,t.scale,r);return lo(`detail`,fo(t.scale,r),i)?(e.font=ji(Ai.regular,i/r),!0):!1}function RF(e,t,n,r,i,a,o){if(!i)return;let s=o===void 0?i:Oo(i,o*t.scale,t=>e.measureText(t).width);if(s===null)return;let c=mo(B(t,n,r),a);e.fillText(s,c.x,c.y)}function zF(e,t,n,r,i){let{sheet:a,dividers:{xs:o,ys:s}}=r;e.lineWidth=Qa(i),e.beginPath();for(let r of o)IF(e,t,n,{x:r,y:a.outer.minY},{x:r,y:a.inner.minY},i),IF(e,t,n,{x:r,y:a.inner.maxY},{x:r,y:a.outer.maxY},i);for(let r of s)IF(e,t,n,{x:a.outer.minX,y:r},{x:a.inner.minX,y:r},i),IF(e,t,n,{x:a.inner.maxX,y:r},{x:a.outer.maxX,y:r},i);if(e.stroke(),PF(t.scale,i)&&LF(e,t,.12,i)){e.fillStyle=K().titleText,e.textBaseline=`middle`,e.textAlign=`center`;for(let a of r.labels)RF(e,t,n,a,a.text,i)}}function BF(e,t,n,r,i){let a=r.block;FF(e,t,n,a.box,i);for(let r of a.cells)FF(e,t,n,r.box,i);e.fillStyle=K().titleText,e.textBaseline=`middle`,e.textAlign=`left`;for(let[r,o]of NF)if(LF(e,t,o,i))for(let o of a.cells)o.kind===r&&RF(e,t,n,{x:o.box.minX+jF,y:(o.box.minY+o.box.maxY)/2},o.text,i,o.box.maxX-o.box.minX-2*jF)}function VF(e,t,n,r,i){let{sheet:a}=r;e.save(),ho(e),e.strokeStyle=K().border,FF(e,t,n,a.outer,i,io(MF,i)),FF(e,t,n,a.inner,i),zF(e,t,n,r,i),BF(e,t,n,r,i),e.restore()}var HF=[{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}],UF=.2,WF=1.2,GF=.8,KF=10,qF=1e-6;function JF(e){return Math.round(e*KF)/KF}function YF(e,t){let n=t??{minX:0,minY:0,maxX:0,maxY:0},r=JF((n.minX+n.maxX)/2-e.width/2),i=JF((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+UF,minY:a.minY+UF,maxX:a.maxX-UF,maxY:a.maxY-UF},empty:t===void 0}}function XF(e){let{inner:t}=e;return{minX:t.maxX-4,minY:t.minY,maxX:t.maxX,maxY:t.minY+WF}}var ZF=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function QF(e,t){let{outer:n}=e;return t.minX-.5>=n.minX-qF&&t.minY-.5>=n.minY-qF&&t.maxX+.5<=n.maxX+qF&&t.maxY+.5<=n.maxY+qF&&!ZF(t,XF(e))}function $F(e,t){let n=Math.max(0,t?HF.indexOf(t):0),r=HF.slice(n);if(!e)return YF(r[0],void 0);let i=r.map(t=>YF(t,e));return i.find(t=>QF(t,e))??i[i.length-1]}function eI(e,t){return t?e&&!e.empty&&QF(e,t)?e:$F(t,e&&!e.empty?e.size:void 0):e??$F(void 0)}function tI(e,t){return(e?.empty??!1)&&!t.empty}function nI(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 rI(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 iI=[[`Project`,`project`],[`Page`,`page`],[`File`,`file`],[`Date`,`date`],[`Rev`,`rev`]];function aI(e,t){let n=XF(e),r=WF/iI.length,i=n.minX+GF;return{box:n,cells:iI.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 oI(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function sI(e,t){return{sheet:e,dividers:rI(e),labels:nI(e),block:aI(e,t)}}function cI({design:e,circuit:t,actions:n,builtFrom:r}){let[i,a]=(0,l.useState)([]);(0,l.useEffect)(()=>a(e=>e.every(e=>e.sentAt>r)?e:e.filter(e=>e.sentAt>r)),[r]);let o=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return{tools:{boxes:(0,l.useMemo)(()=>e.schematic.labels.map(e=>({id:e.id,box:vr(e)})),[e.schematic.labels]),at:t=>Sr(e,t),blocker:n=>Ir(e,t,n,o),commit:(r,i)=>{let s=Rr(e,t,r.id,i,o);if(!Array.isArray(s))return n.notify(s.blocked);let c=Nr(e,r.id,i);if(s.length===0||!c)return;let l={id:r.id,...c,sentAt:Date.now()};a(e=>[...e.filter(e=>e.id!==r.id),l]),n.edit(s,`Move ${r.text} label`).then(e=>e||a(e=>e.filter(e=>e!==l)))}},pending:(0,l.useMemo)(()=>i.filter(e=>e.sentAt>r),[i,r])}}function lI(e,t){return(0,l.useMemo)(()=>{let n=t&&Nr(e,t.id,t.at);return t&&n?{id:t.id,...n}:void 0},[e,t])}function uI(e){let t=(0,l.useRef)(uC(e));t.current.set(e),(0,l.useEffect)(()=>lC.answer(e=>t.current.call(e)),[])}var dI=.5,fI=.1,pI=/^[A-Za-z_][A-Za-z0-9_]*$/,mI=`Use letters, digits and _, starting with a letter or _`,hI=[`right`,`top`,`left`,`bottom`],gI={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},_I=e=>Math.round(e*1e3)/1e3||0,vI=e=>_I(Math.round(e/fI)*fI);function yI(e,t){if(e===`gnd`)return`GND`;let n=t.trim();return e===`vcc`&&n===``?`VCC`:n}function bI(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=hI[(hI.indexOf(i)+a)%4]??i,s=gI[o];return{end:r,side:o,corner:{x:vI(r.x+s.x*dI),y:vI(r.y+s.y*dI)}}}var xI=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t),SI=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t));function CI(e){return e===``?`Name the net label`:pI.test(e)?void 0:mI}function wI(e,t,n,r){let i=kn(e,t),a=CI(n);if(a)return a;if(!rr(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(SI(e,t.id)?.names.includes(n))return`${i} is already on ${n}`}function TI(e,t,n,r,i,a){let o=xI(e,i),s=o&&bI(e,o);if(!o||!s)return{blocked:`No pin there`};let c=yI(n,r),l=wI(e,o,c,a);return l?{blocked:l}:[{kind:`addTrace`,from:kn(e,o),to:`net.${c}`,schematicRouteHints:[s.corner]}]}function EI(e,t,n){return e===`label`?`Add ${t} label at ${n}`:`Add ${t} at ${n}`}function DI(e,t,n,r){let i=xI(e,r),a=i&&bI(e,i);if(!i||!a)return;let o=yI(t,n),s=$f([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 OI(e,t,n){let r=SI(e,t);return r&&!r.names.includes(n)?r.names[0]:void 0}var kI=/^net\.([\w-]+)$/,AI=`schematicRouteHints`,jI=(e,t)=>kI.exec(e?.trim()??``)?.[1]===t,MI=(e,t)=>e.model.traces.filter(e=>jI(e.from,t)||jI(e.to,t));function NI(e,t,n,r){if(t.trim().startsWith(`net.`))return;let i=An(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 PI(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===AI&&t.schematicRouteHints))?`The trace on line ${t.line} has an expression; ${i}`:[t.from,t.to].map(t=>t===void 0?void 0:NI(e,t,n,r)).find(e=>e!==void 0):`The trace on line ${t.line} is read-only (${t.readonlyReason}); ${i}`}function FI(e,t,n){let r=e=>jI(e,t)?`net.${n}`:e??``,i=Object.entries(e.props).filter(([e])=>e!==AI),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 II=(e,t)=>e.circuit.nets.filter(e=>e.id!==t.net).flatMap(e=>e.names);function LI(e,t,n,r,i){let a=r.trim(),o=n.text,s=CI(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=MI(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=>PI(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=>FI(e,o,a)),p=II(e,n).includes(a)?{joins:a}:{};return{edits:[...d,...f],summary:c,...p}}function RI(e,t){if(t.style===`label`)return;let n=MI(e,t.text).length;return`Rename the ${t.text} net everywhere (${n} ${n===1?`connection`:`connections`})?`}var zI=12;function BI(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.useMemo)(()=>t.filter(t=>t.sentAt>e),[t,e]),add:e=>{let t={...e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function VI(e){(0,l.useEffect)(()=>{let t=t=>{rd(Hu(t),{view:`schematic`})?.action===`armNetLabel`&&(t.preventDefault(),e(`label`))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function HI(e,t,n,r){(0,l.useEffect)(()=>{if(e!==`label`&&e!==`vcc`)return;let i=i=>{i.key!==`Tab`||i.shiftKey||Hu(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 UI({design:e,circuit:t,actions:n,pending:r,setTyped:i}){let a=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(o,s,c)=>{let l=TI(e,t,o,c,s,a);if(!Array.isArray(l))return n.notify(l.blocked);let u=yI(o,c),d=OI(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=DI(e,o,c,s),p=f&&r.add(f),m=l[0]?.kind===`addTrace`?l[0].from:s;n.edit(l,EI(o,u,m)).then(e=>e||p&&r.drop(p)),o===`label`&&i(``)}}function WI({design:e,circuit:t,actions:n}){let r=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(i,a)=>{let o=LI(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 GI(e){let{tool:t,typed:n,camera:r,design:i,setTyped:a,setEditing:o}=e,s=UI(e),c=WI(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=Bn(i,a,zI/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=CI(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 KI(e){let[t,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(``),[a,o]=(0,l.useState)(null),s=(0,l.useCallback)(()=>{n(null),i(``),o(null)},[]);return{tool:t,typed:r,setTyped:i,editing:a,setEditing:o,arm:(0,l.useCallback)(t=>{e(),n(t),i(``),o(null)},[e]),disarm:s}}function qI(e){let{camera:t,cursor:n}=e,{tool:r,typed:i,setTyped:a,editing:o,setEditing:s,arm:c,disarm:u}=KI(e.onArm),d=BI(e.builtFrom),f=GI({...e,tool:r,typed:i,setTyped:a,setEditing:s,pending:d});HI(r,i,(0,l.useMemo)(()=>n??{x:t?.cx??0,y:t?.cy??0},[n,t]),f.open),pk(r!==null,u),VI(c);let p=d.visible.map(e=>e.label);return{tool:r,armed:r!==null,arm:c,disarm:u,press:(e,t)=>(o?.rename&&s(null),f.press(e,t,u)),rename:t=>{let n=RI(e.circuit,t);(!n||window.confirm(n))&&s({at:t.at,initial:t.text,rename:t})},editing:o,cancelName:()=>f.open(null),submitName:e=>f.submitName(e,o),typed:i,ghosts:p,ghostWires:d.visible.map(e=>e.wire)}}var JI=(e,t,n=!1)=>({start:e,...t?{pin:t}:{},corners:[],bends:[],flip:n}),YI=e=>[...e.bends,e.flip],XI=(e,t)=>Sn([e.start.at,...e.corners,t],YI(e)),ZI=12,QI=(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 $I(e,t,n){let{start:r,corners:i}=t;if(er(n,r))return{};let a=Ln(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=or(e,r,n,i,YI(t));if(s.length===0)return{notice:`${r.label} and ${n.label} are already connected`};let c=tr(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:XI(t,n.at),summary:`connect ${r.label} to ${n.label}`}}function eL(e){let[t,n]=(0,l.useState)({}),r=(0,l.useRef)({}),i=(0,l.useCallback)(e=>{r.current=e,n(t=>QI(t,e)?t:e)},[]);return(0,l.useEffect)(()=>i({}),[e,i]),{under:t,setUnder:i,underRef:r}}function tL(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.points),[t,e]),add:e=>{let t={points:e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function nL({drawing:e,setDrawing:t,setWiring:n,underRef:r,start:i,escape:a}){(0,l.useEffect)(()=>{let o=o=>{let s=rd(Hu(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`&&RE(o)&&a()};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[e,t,n,r,i,a])}function rL(e,t,n,r,i){return(0,l.useMemo)(()=>{let a=t.end?.at??(n&&_e(n,r,i));return e&&a?XI(e,a):void 0},[e,t,n,r,i])}var iL=(e,t,n)=>({step:t,snap:n,...e?{from:e.corners.at(-1)??e.start.at}:{}});function aL(e,t,n,r,i){if(!t)return{};let a=ZI/t.scale,o=Bn(e,r,a)?.pin;if(!n&&!o)return{};let s=Vn(e,r,a,i);return{...s?{end:s}:{},...o?{pin:o}:{}}}function oL(e,t,n,r){let[i,a]=(0,l.useState)(null);(0,l.useEffect)(()=>{i&&!e.schematic.drawings.some(e=>`bus:${e.id}`===i.bus.selector)&&a(null)},[e,i]);let o=(e,i,a)=>{let o=qn(e,a);i===`start`?n(JI(o,void 0)):t&&r(t,o)},s=(e,t)=>{let[n,...r]=e.members??[];if(n!==void 0&&r.length===0)return o(e,t,n);a({bus:e,role:t})};return{picking:i,open:s,pick:e=>{i&&(a(null),o(i.bus,i.role,e))},cancelPick:(0,l.useCallback)(()=>a(null),[]),start:(e,t)=>e.members?s(e,`start`):n(JI(e,t))}}function sL(e,t,n,r){return(i,a)=>{r(null);let o=$I(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 cL(e){let{design:t,camera:n,step:r,snap:i}=e,[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(null),{under:u,setUnder:d,underRef:f}=eL(e.buildId),p=tL(e.builtFrom),m=sL(t,e.actions,p,c),h=oL(t,s,c,m);nL({drawing:s,setDrawing:c,setWiring:o,underRef:f,start:h.start,escape:()=>h.picking?h.cancelPick():s?c(null):o(!1)});let g=rL(s,(0,l.useMemo)(()=>h.picking?.role===`end`?{end:h.picking.bus}:u,[h.picking,u]),e.cursor,r,i),_=(0,l.useMemo)(()=>[s?.pin,u.pin].filter(e=>e!==void 0),[s,u]),v=e=>aL(t,n,a||s!==null,e,iL(s,r,i)),y=(e,o)=>lL({design:t,camera:n,wiring:a,drawing:s,setDrawing:c,step:r,snap:i,finish:m,underAt:v,picks:h},e,o),b=(0,l.useCallback)(()=>{o(!1),c(null),h.cancelPick()},[h.cancelPick]),x=u.end!==void 0&&(a||s!==null||u.pin!==void 0&&Fn(t,u.pin));return{wiring:a,toggleWiring:()=>{b(),o(!a)},cancel:b,drawing:s,under:u,pendingWires:p.visible,preview:g,activePins:_,overPin:x,press:y,hover:e=>d(v(e)),leave:()=>d({}),picking:h.picking,pick:h.pick,cancelPick:h.cancelPick}}function lL(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=Vn(e.design,n,ZI/e.camera.scale,iL(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):uL(e.drawing,n,e,e.setDrawing),!0}let{end:r,pin:i}=e.underAt(n);return!r||!e.wiring&&!(i&&Fn(e.design,i))?!1:(e.picks.start(r,i),!0)}function uL(e,t,n,r){let i=_e(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 dL=`This wire's new trace is still being built; reshape it again when the build is done`;function fL(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 pL=(e,t)=>t.startsWith(`net.`)?t:An(e,t)?.id,mL=(e,t)=>{let[n,r]=[pL(e,t.from??``),pL(e,t.to??``)];return n&&r?`wire:${n}|${r}`:void 0};function hL(e,t){let{writer:n}=t;if(n.kind!==`engine`)return{newTrace:!1,wire:t.id};if(n.onWire?.trace){let t=mL(e,n.onWire.trace);return t?{newTrace:!0,wire:t}:{newTrace:!0}}let[r,i]=[pL(e,n.from),pL(e,n.to)];return r&&i?{newTrace:!0,wire:fL(e.circuit.connections,r,i)}:{newTrace:!0}}function gL(e,t){return e.some(e=>e.id===t&&e.newTrace)?dL:null}function _L(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 vL(e,t,n,r=cr){let i=Lc(e,t,n);return i?Rc(e,i,r):Rw}function yL(e,t,n,r,i,a){let o=e.schematic.wires.filter(e=>e.id!==n.id).map(e=>e.points);return Iw(jw(e.schematic.drawings).filter(e=>vC(t.model,i,e.id,[`x`,`y`])===null),a??n.points,yc(r),o)}function bL(e,t,n,r,i,a,o){let s=Hc(e,n,r,a,o);return Array.isArray(s)?{edits:s.length===0?s:[...s,...yL(e,t,n,r,a,o)],summary:`${i} ${qw(e,n)}`,points:yc(r),...hL(e,n)}:s}function xL(e,t,n,r,i=cr,a){let o=Lc(e,t,n);return o?bL(e,t,o,r,`reshape`,i,a):{blocked:Rw}}function SL(e,t,n,r,i=cr,a){let o=Lc(e,t,n);if(!o)return{blocked:Rw};let s=a!==void 0&&!Vc(a,o.points)?null:Yw(e,o,i);return s===null?bL(e,t,o,vc(a??o.points,r),`remove a corner of`,i,a):{blocked:s}}function CL(e,t,{design:n,builtFrom:r,onSelect:i}){(0,l.useEffect)(()=>{let{waiting:a,follow:o}=_L(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 wL(e){let{design:t,circuit:n,actions:r,locked:i,builtFrom:a}=e,[o,s]=(0,l.useState)([]);CL(o,s,e);let c=(0,l.useMemo)(()=>o.filter(e=>e.sentAt>a).map(({id:e,points:t})=>({id:e,points:t})),[o,a]),u=(0,l.useCallback)(e=>gL(o,e)??vL(t,n,e,i),[o,t,n,i]),d=(0,l.useCallback)((e,t)=>{if(`blocked`in t)return r.notify(t.blocked);if(t.edits.length===0)return;let{edits:n,summary:i,...a}=t,o={id:e,...a,sentAt:Date.now()};s(t=>[...t.filter(t=>t.id!==e),o]),r.edit(n,i).then(e=>e||s(e=>e.filter(e=>e!==o)))},[r]),f=(0,l.useCallback)(e=>c.find(t=>t.id===e)?.points,[c]);return{pending:c,blocker:u,commit:(0,l.useCallback)((e,r)=>d(e,xL(t,n,e,r,i,f(e))),[d,t,n,i,f]),dropCorner:(0,l.useCallback)((e,r)=>{let a=gL(o,e);d(e,a?{blocked:a}:SL(t,n,e,r,i,f(e)))},[d,o,t,n,i,f])}}async function TL(e,t){return`blocked`in e?(t.notify(e.blocked),!1):t.edit(e.edits,e.summary)}function EL({design:e,circuit:t,actions:n,locked:r,selection:i}){let a=(0,l.useCallback)((n,i,a)=>oT(e,t,n,i,r,a),[e,t,r]),o=(0,l.useCallback)((t,n)=>mp(e,t,n),[e]),s=(0,l.useCallback)(t=>Hw(e,t),[e]),c=(0,l.useCallback)(t=>{let n=e.schematic.labels.find(e=>e.id===t);return n&&Mf(e.circuit.nets,n.net)},[e]);return lb({removeCorners:()=>{let a=i.soleWire;if(a===void 0)return n.notify(`Select one wire first.`);TL(sT(e,t,a,r),n)}}),(0,l.useMemo)(()=>({net:s,removal:a,labelRemoval:o,labelNet:c}),[s,a,o,c])}function DL(e){let{design:t,camera:n,selection:r,wiring:i}=e,{pending:a,blocker:o,commit:s,dropCorner:c}=wL(e),u=(0,l.useMemo)(()=>dl(t.schematic.wires,a),[t.schematic.wires,a]),d=(0,l.useCallback)(e=>e===void 0?void 0:u.find(t=>t.id===e),[u]),f=(0,l.useMemo)(()=>{let e=e=>n?nc(u,e,Qs(n.scale)/n.scale):void 0;return i?{at:e,lines:u}:{at:e,lines:u,drag:{points:e=>d(e)?.points,blocker:o,commit:s}}},[u,n,d,o,s,i]),p={at:(e,t)=>n?rl(f.drag,t,e,n.scale):void 0,drop:c};return{hits:f,selected:(0,l.useMemo)(()=>d(r.soleWire),[d,r.soleWire]),menuWire:(0,l.useMemo)(()=>r.size===0?d(r.wires.at(-1)):void 0,[d,r]),lineOf:d,keys:EL(e),pending:a,corners:p}}function OL({design:e,circuit:t,camera:n,locked:r}){let{drawings:i}=e.schematic,a=(0,l.useCallback)(e=>e===void 0?void 0:i.find(t=>t.id===e),[i]);return{hits:(0,l.useMemo)(()=>({at:e=>n?DD(i,e,6/n.scale,n.scale):void 0,boxes:kD(i),origin:e=>{let t=a(e);return t&&bC(t)},blocker:e=>{let n=a(e);return n?yC(t.model,r,n):null}}),[i,n,a,t.model,r]),removal:(0,l.useCallback)(e=>DC(t.model,i,r)(e),[t.model,i,r]),drawingOf:a}}var kL=7,AL=20;function jL(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 ML({draw:e,camera:t,size:n}){let r=jL(e);if(!r||!t)return null;let i=B(t,n,r.at);return(0,Z.jsx)(NL,{left:i.x-kL,top:i.y-AL,field:r,draw:e},r.label)}function NL({left:e,top:t,field:n,draw:r}){let[i,a]=(0,l.useState)(n.initial),[o,s]=(0,l.useState)(),c=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>c.current?.focus());return()=>cancelAnimationFrame(e)},[e,t]),(0,Z.jsxs)(`form`,{className:`label-name`,style:{left:e,top:t},onPointerDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),s(r.submitText(i))},children:[(0,Z.jsx)(`input`,{ref:c,autoFocus:!0,"aria-label":n.label,placeholder:n.label,value:i,style:{fontFamily:Oi},onFocus:e=>n.initial!==``&&e.currentTarget.select(),onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r.cancelText())}}),o&&(0,Z.jsx)(`span`,{role:`alert`,children:o})]})}function PL(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 FL=21,IL=6,LL=12,RL=e=>Math.min(e*FL+IL,220);function zL(e,t,n){let r=Math.min(e.x+LL,t.width-100),i=Math.min(e.y+LL,t.height-RL(n));return{left:Math.max(r,0),top:Math.max(i,0)}}function BL({wire:e,camera:t,size:n}){let{picking:r}=e;if(!r||!t)return null;let i=r.bus.members??[],{left:a,top:o}=zL(B(t,n,r.bus.at),n,i.length),s=`${r.bus.selector}:${r.bus.at.x}:${r.bus.at.y}`;return(0,Z.jsx)(VL,{left:a,top:o,name:r.bus.label,members:i,wire:e},s)}function VL({left:e,top:t,name:n,members:r,wire:i}){let[a,o]=(0,l.useState)(0),s=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>s.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,l.useEffect)(()=>s.current?.children[a]?.scrollIntoView({block:`nearest`}),[a]),(0,Z.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=PL(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,Z.jsx)(`li`,{id:`bus-member-${t}`,role:`option`,"aria-selected":t===a,onPointerEnter:()=>o(t),onClick:()=>i.pick(e),children:e},e))})}var HL={finishShape:{type:`finish`},removeCorner:{type:`removeCorner`},flipBend:{type:`flip`}};function UL(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.drawing),[t,e]),add:(0,l.useCallback)(e=>{let t={drawing:e,sentAt:Date.now()};return n(e=>[...e,t]),t},[]),drop:(0,l.useCallback)(e=>n(t=>t.filter(t=>t!==e)),[])}}function WL(e,t){let[n,r]=(0,l.useState)([]);return(0,l.useEffect)(()=>{let i=n.filter(t=>e.schematic.drawings.some(e=>e.id===t));i.length!==0&&(t(()=>Ea.none.addDrawings(i)),r(e=>e.filter(e=>!i.includes(e))))},[e,n,t]),{wait:(0,l.useCallback)(e=>r(t=>[...t,e]),[]),forget:(0,l.useCallback)(e=>r(t=>t.filter(t=>t!==e)),[])}}function GL(e){let[t,n]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(!e){n(!1);return}let t=e=>n(e.shiftKey),r=()=>n(!1);return window.addEventListener(`keydown`,t),window.addEventListener(`keyup`,t),window.addEventListener(`blur`,r),()=>{window.removeEventListener(`keydown`,t),window.removeEventListener(`keyup`,t),window.removeEventListener(`blur`,r)}},[e]),t}function KL(e){(0,l.useEffect)(()=>{let t=t=>{let n=rd(Hu(t),{view:`schematic`})?.action;n&&w(n)&&(t.preventDefault(),e(C[n]))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),lb(Object.fromEntries(x.map(t=>[t,()=>e(C[t])])))}function qL(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{id(Hu(e))&&(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?rd(Hu(e),{view:`schematic`,drawing:!0})?.action:void 0,i=r===void 0?void 0:HL[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 JL(e,t){let[n,r]=(0,l.useState)(null),i=(0,l.useRef)(n);return i.current=n,{state:n,send:(0,l.useCallback)(e=>{let n=i.current;if(!n)return;let a=LP(n,e);i.current=a.state,r(a.state),a.drawing&&t(n.tool,a.drawing)},[t]),arm:(0,l.useCallback)(t=>{e(),i.current=yP(t),r(i.current)},[e]),disarm:(0,l.useCallback)(()=>{i.current=null,r(null)},[])}}function YL(e,t){let{circuit:n,actions:r}=e,{add:i,drop:a,visible:o}=t,{wait:s,forget:c}=WL(e.design,e.onSelect),u=(0,l.useRef)([]);return{write:(0,l.useCallback)((e,t)=>{let{model:l}=n;u.current=u.current.filter(e=>!l.drawings.some(t=>t.name===e||t.id===e));let d=UP(t,l,u.current),f=d.name??``,p=HC(l,f,o.flatMap(e=>e.kind===`bus`?[e.name]:[]));u.current=[...u.current,f];let m=i(VP(t,p));s(p),r.edit([d],GP(e,f)).catch(()=>!1).then(e=>{e||(u.current=u.current.filter(e=>e!==f),a(m),c(p))})},[n,r,s,c,i,a,o]),taken:u}}function XL(e,t,n,r){return{submitText:r=>{let i=e?.tool===`bus`?zC(n,r):void 0;return i||t({type:`text`,text:r}),i},busName:()=>RC(n,r.current)}}function ZL(e){let{camera:t,cursor:n,step:r,snap:i}=e,a=UL(e.builtFrom),{write:o,taken:s}=YL(e,a),{state:c,send:u,arm:d,disarm:f}=JL(e.onArm,o),p=GL(c!==null),m=(0,l.useRef)(void 0);KL(d),qL(c,u);let h=(0,l.useMemo)(()=>c&&n?BP(c,bP(n,r,i),p):void 0,[c,n,r,i,p]),g=(e,n)=>{if(!c||!t||e.button===1)return!1;if(SP(c,e.button)&&e.preventDefault?.(),e.button===2)return u({type:`cancel`}),!0;let a={at:{x:n.x*t.scale,y:n.y*t.scale},time:Date.now()},o=xP(m.current,a);return m.current=o?void 0:a,u({type:`press`,at:bP(n,r,i),shift:e.shiftKey,double:o}),!0},_=(0,l.useMemo)(()=>h?[...a.visible,h]:a.visible,[a.visible,h]);return{state:c,tool:c?.tool??null,armed:c!==null,busy:c!==null&&c.points.length>0,arm:d,disarm:f,press:g,release:e=>{c&&u({type:`release`,at:bP(e,r,i)})},...XL(c,u,e.circuit.model,s),cancelText:()=>u({type:`cancel`}),pending:_}}var QL=.2,$L=.2,eR=1.2,tR=.6,nR=.4,rR=e=>yt(Math.ceil(e/QL-1e-9)*QL),iR=e=>Math.max(0,...e.map(e=>e.name.length))*vt*_t[`pin-name`];function aR(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)*QL,i=(n([`left`,`right`])+1)*QL,a=iR(t(`left`))+iR(t(`right`))+nR;return{width:rR(Math.max(eR,r,a)),height:rR(Math.max(tR,i))}}function oR(e,t,n,r){let i=yt(t*QL);return e===`left`?{edge:bt(0,-i),end:bt(-.2,-i)}:e===`right`?{edge:bt(n,-i),end:bt(n+$L,-i)}:e===`top`?{edge:bt(i,0),end:bt(i,$L)}:{edge:bt(i,-r),end:bt(i,-r-$L)}}function sR(e,t={}){let n=aR(e),r=Math.max(n.width,rR(t.width??0)),i=Math.max(n.height,rR(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,...oR(e.side,e.order,r,i)}))}}function cR(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)/QL)-1);return Math.min(a,Math.max(1,Math.round(i/QL)))}function lR(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:cR(r,e,t,n)}}function uR(e,t){let n=cn(e,t),r=e.schematic.symbols.find(e=>e.component===t);if(n&&r)return{instance:n,placed:r,layout:sR(n.ports,n.size)}}var dR=(e,t)=>cd(t,e.placed),fR=(e,t)=>sd({x:t.x-e.placed.x,y:t.y-e.placed.y},-e.placed.rotation);function pR(e,t){return t.flatMap(t=>{let n=uR(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:dR(n,e.edge)})),{kind:`corner`,instance:t,file:r.file,at:dR(n,{x:i.width,y:-i.height})}]})}function mR(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 hR(e,t,n){let r=uR(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=lR(fR(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 gR=e=>Math.round(Math.ceil(e/QL-1e-9)*QL*1e3)/1e3;function _R(e,t,n){let r=uR(e,t.instance);if(!r)return{message:`${t.instance} is gone`};let i=fR(r,n),a=Math.max(r.layout.needed.width,gR(i.x)),o=Math.max(r.layout.needed.height,gR(-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 vR=6;function yR({design:e,selection:t,camera:n,actions:r}){let i=(0,l.useMemo)(()=>pR(e,t.names),[e,t.names]),[a,o]=(0,l.useState)(),s=(0,l.useRef)(void 0),c=e=>{s.current=e,o(e)};return{press:(e,t)=>{if(e.button!==0||e.shiftKey||e.ctrlKey||e.metaKey||!n||i.length===0)return!1;let r=mR(i,t,vR/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`?hR(e,n,t):_R(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 bR=`noConnect`;function xR(e){return typeof e==`string`?[...new Set(e.split(`,`).map(e=>e.trim()).filter(e=>e!==``))]:[]}var SR=(e,t)=>e.names.includes(t)||`pin${e.number}`===t;function CR(e,t){let n=xR(e);return(n.some(e=>SR(t,e))?n.filter(e=>!SR(t,e)):[...n,`pin${t.number}`]).join(`,`)}function wR(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 TR(e,t,n){let r=wR(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[bR];if(o&&o.literal===void 0)return{message:`${a.name}.${bR} is an expression (${o.source}); change it in the code.`};let s=CR(o?.literal,i),c=`${xR(s).length<xR(o?.literal).length?`remove the no connect flag from`:`flag no connect on`} ${r.pin}`;return{edit:{kind:`setProps`,part:a.name,props:{[bR]:s===``?null:s}},summary:c}}function ER(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 DR(e,t,n){let r;for(let i of e.wires)for(let e=1;e<i.points.length;e++){let a=ER(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 OR(e,t,n){let r=DR(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 kR=12,AR={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 jR(e){let[t,n]=(0,l.useState)(null),r=(0,l.useRef)(e);r.current=e;let i=(0,l.useCallback)(e=>{r.current.onArm(),n(e)},[]),a=(0,l.useCallback)(()=>n(null),[]);return lb({noConnect:()=>i(`noConnect`),junction:()=>i(`junction`)}),(0,l.useEffect)(()=>{let e=e=>{let r=Hu(e);if(id(r)&&t)return e.stopPropagation(),n(null);rd(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=kR/c.scale,d=t===`junction`?OR(a.schematic,i,u):TR({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?AR[t]:void 0}}var MR={cx:0,cy:0,scale:60},NR=.06,PR=12;function FR(e,t,n,r){return{sheet:(0,l.useMemo)(()=>{let t=LM(e.schematic,r);return n.length===0&&t===e.schematic.labels?e.schematic:{...e.schematic,wires:[...dl(e.schematic.wires,n)],labels:[...t]}},[e.schematic,n,r]),selected:(0,l.useMemo)(()=>t&&dl([t],n)[0],[t,n])}}function IR(e,t){let{design:n,border:r,camera:i,size:a,moving:o,boxes:s,hover:c,selection:u,locked:d,circuit:f,gesture:p,movingLabels:m,hoverLabel:h,hoverDrawing:g,hoverWire:_,palette:v,highlight:y,markers:b,activeViolation:x,grid:S,texts:C,theme:w}=t,{wiring:T,drawing:E,activePins:ee,pendingWires:D,preview:O}=t.wire,{ghosts:k,ghostWires:A,armed:j}=v,te=t.draw.pending,M=FR(n,t.selectedWire,t.wireShapes,o),ne=M.selected,N=(0,l.useMemo)(()=>Nd(M.sheet,C.moves),[M.sheet,C.moves]);(0,l.useEffect)(()=>{let t=i??MR,n=W(w);Va(n);let l=sE(n),v=Uc(n),M=IE(e.current,a,t,n.background,(e,t,r,i)=>DF(e,t,r,S,i,n));if(!M)return;let{ctx:P,ratio:F}=M;VF(P,t,a,r,F),ws(P,N,{camera:t,size:a},{ratio:F,showPins:T||E!==null||j,activePins:ee,pending:[...D,...A,...m.map(e=>e.wire)],movingLabels:m,ghostLabels:k,selectedWires:u.wires,selectedLabels:u.labels,selectedDrawings:u.drawings,...o?.drawings?{movingDrawings:o.drawings}:{},pendingDrawings:te,...y?{highlight:y}:{},...o?{moving:{components:o.names,by:o.offset}}:{},violations:b,...x?{activeViolation:x}:{}}),P.setTransform(F,0,0,F,0,0),O&&hE(P,t,a,O,`drawing`,n.wire,F),LE(P,t,a,{view:`schematic`,boxes:s,moving:o,hover:E?void 0:c,selection:u,locked:d,marks:f.annotations.marks,gesture:p,look:l,ratio:F}),h&&!E&&!p&&cE(P,t,a,yr(h),{x:0,y:0},`hover`,l,F),gE(P,{camera:t,size:a},C.shown,{selected:u.texts,hover:E||p?void 0:C.hover},l,F),g&&!u.hasDrawing(g.id)&&!E&&!p&&cE(P,t,a,OD(g),{x:0,y:0},`hover`,l,F),!_||u.hasWire(_.id)||T||E||p||Qc(P,t,a,_.points,v,F),ne&&!m.some(e=>e.hideWire===ne.id)&&$c(P,t,a,ne.points,v,F)},[e,N,r,i,a,T,E,ee,D,O,o,m,h,g,_,ne,s,c,u,d,f,p,k,A,j,te,y,b,x,S,C,w])}function LR({step:e,setStep:t,keep:n}){return(0,Z.jsxs)(Y_,{children:[(0,Z.jsx)(GE,{step:e,options:vh(`schematic`),onChange:t}),(0,Z.jsx)(KE,{...n,title:`Write the faded symbols' positions into the code as schX and schY`})]})}function RR({boxes:e,wire:t,labels:n,filter:r,wires:i,drawings:a,texts:o,setCursor:s}){let[c,u]=(0,l.useState)({kind:`canvas`});return{part:c.kind===`part`?c.name:void 0,label:c.kind===`label`?c.label:void 0,wire:c.kind===`wire`?c.id:void 0,drawing:c.kind===`drawing`?c.id:void 0,text:c.kind===`text`?c.id:void 0,over:c.kind!==`canvas`,at:s=>{t.hover(s),u(TO(e,n,s,{selection:Ea.none,armed:null,filter:r},i,a,o))},leave:()=>{u({kind:`canvas`}),s(void 0),t.leave()}}}function zR({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??UR(c)??CF(l)??XP(d.state)??u.hint;return(0,Z.jsxs)(`div`,{className:`schematic-canvas`,ref:e,style:{cursor:s},...a,onPointerLeave:o,onContextMenu:e=>e.preventDefault(),children:[(0,Z.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,Z.jsx)(`div`,{className:`canvas-top`,children:(0,Z.jsx)(`div`,{className:`canvas-hint`,children:y})}),(0,Z.jsx)(wF,{palette:l,camera:r,size:n}),(0,Z.jsx)(ML,{draw:d,camera:r,size:n}),(0,Z.jsx)(BL,{wire:c,camera:r,size:n}),(0,Z.jsx)(UN,{state:_}),(0,Z.jsx)(qE,{cursor:i,zoom:(r??MR).scale,detail:c.under.end?.label,gesture:f,rotateHeld:p,snap:m}),h&&(0,Z.jsx)(`p`,{className:`empty`,children:`This schematic has no parts yet.`})]})}function BR(e,t,n){uI(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 VR(e){let t=(0,l.useRef)(void 0),n=(0,l.useMemo)(()=>Bb(e.schematic),[e.schematic]);return(0,l.useMemo)(()=>{let e=eI(t.current,n);return t.current=e,e},[n])}function HR(e,t){let n=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{tI(n.current,e)&&t(),n.current=e},[e,t])}function UR(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 WR(e,t){return(0,l.useMemo)(()=>Pf(e,t),[e,t])}function GR(e,t,n){return(0,l.useMemo)(()=>{let r=ul(e?.kind===`reshape`?e:void 0,t);return n&&n.length>0?[...n,...r]:r},[e,t,n])}function KR(e,t,n){return(0,l.useMemo)(()=>e&&e.sentAt>t?PM(e,n):void 0,[e,t,n])}function qR(e,t,n,r){let i=lI(e,(0,l.useMemo)(()=>t?.kind===`label`&&t.moved&&!t.blocker?{id:t.label.id,at:t.at}:void 0,[t]));return(0,l.useMemo)(()=>{let e=[...i?[i]:[],...r??[]];return e.length===0?n:[...e,...n.filter(t=>!e.some(e=>e.id===t.id))]},[i,n,r])}function JR({design:e,builtFrom:t,camera:n,cursor:r,fit:i,wire:a,palette:o,drawBusy:s,highlightNets:c,onHighlight:u,keys:d,texts:f}){let p=(0,l.useRef)(void 0);p.current=r;let m=(0,l.useCallback)(()=>n&&p.current?jf(e,p.current,PR/n.scale):void 0,[e,n]),h=(0,l.useCallback)(t=>Ff(e,t),[e]),{rotateHeld:g,keyMove:_}=eN({...d,paused:a.drawing!==null||s,fit:i,netUnderPointer:m,netsOf:h,onHighlight:u,texts:f}),{wiring:v,drawing:y}=a,{disarm:b}=o;return(0,l.useEffect)(()=>{(v||y)&&b()},[v,y,b]),lb({wire:()=>{b(),v||a.toggleWiring()},netLabel:()=>o.arm(`label`),groundFlag:()=>o.arm(`gnd`),powerFlag:()=>o.arm(`vcc`)}),lb({tidySheet:()=>qe(e,d.blockerFor,d.actions,d.circuit)}),{highlight:WR(e,c),rotateHeld:g,keyMoving:KR(_,t,d.layout.anchors)}}function YR(e,t,n,r,i){let{wiring:a,cancel:o}=e,{tool:s,disarm:c}=t,{which:u,disarm:d}=n,{disarm:f}=r,{disarm:p}=i,m=N_(a,s)??P_(r.tool)??i.tool??fk(u);(0,l.useEffect)(()=>{R_({active:m,stop:()=>{c(),o(),d(),f(),p()}})},[m,c,o,d,f,p]),(0,l.useEffect)(()=>B_,[])}function XR(e,t,n,r,i){let{cancel:a,wiring:o,drawing:s}=t,{disarm:c,armed:u}=n,{disarm:d,armed:f}=r,{disarm:p,armed:m}=i,h=(0,l.useCallback)(()=>{c(),a(),d(),p()},[c,a,d,p]),g=jR({...e,onArm:h}),_=g.disarm;return(0,l.useEffect)(()=>{(o||s||u||f||m)&&_()},[o,s,u,f,m,_]),g}function ZR(e,t){let{cancel:n,wiring:r,drawing:i}=e,{disarm:a,armed:o}=t,s=mk((0,l.useCallback)(()=>{a(),n()},[a,n])),c=s.disarm;return(0,l.useEffect)(()=>{(r||i||o)&&c()},[r,i,o,c]),s}function QR(e,t,n,r){let{cancel:i,wiring:a,drawing:o}=t,{disarm:s,armed:c}=n,{disarm:u,armed:d}=r,f=(0,l.useCallback)(()=>{s(),i(),u()},[s,i,u]),p=ZL({...e,onArm:f}),m=p.disarm;return(0,l.useEffect)(()=>{(a||o||c||d)&&m()},[a,o,c,d,m]),p}function $R(e,t,n,r){let{disarm:i}=e,{disarm:a}=t,{disarm:o}=n,{disarm:s}=r,c=(0,l.useCallback)(()=>{i(),a(),o(),s()},[i,a,o,s]);return{armed:e.tool??(t.armed||n.armed||r.armed?`place`:null),disarm:c}}function ez({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,_=TO(e,t,f,u,n,r),v=DO({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 ok({...h,tool:_,toolRelease:v,open:y})}function tz(e){let{design:t,buildId:n,builtMark:r,buildStatus:i,project:a,builtFrom:o,circuit:s,actions:c,selection:u,onSelect:d,highlight:f,onHighlight:p,gridStyle:m,gridStep:h,snap:g,onGridStep:_,markers:v,activeViolation:y,focus:b,onFocused:x}=e,S=(0,l.useRef)(null),C=(0,l.useRef)(null),w=jE(S),[T,E]=(0,l.useState)(),ee=(0,l.useMemo)(()=>({step:h,style:m}),[h,m]),D=OE(t,`schematic`,s),O=VR(t),{camera:k,setCamera:A,fit:j}=NE(S,w,O.outer,NR);HR(O,j);let te=(0,l.useMemo)(()=>sI(O,{project:a??``,page:`Schematic`,file:s.file,date:oI(n),rev:``}),[O,a,s.file,n]);PE(`schematic`,b,k,A,x),sk({selection:u,boxes:D.boxes,size:w,setCamera:A,notify:c.notify});let M=cL({design:t,actions:c,camera:k,cursor:T,step:h,snap:g,buildId:n,builtFrom:o}),ne=yR({design:t,selection:u,camera:k,actions:c}),N=qI({design:t,circuit:s,actions:c,camera:k,cursor:T,builtFrom:o,onArm:M.cancel}),P=ZR(M,N),F=QR({design:t,circuit:s,actions:c,camera:k,cursor:T,step:h,snap:g,builtFrom:o,onSelect:d},M,N,P),re=(0,l.useMemo)(()=>({design:t,locked:D.locked}),[t,D.locked]),ie={view:`schematic`,circuit:s,actions:c,onSelect:d,blockerFor:D.blockerFor,follow:re},I=cI({design:t,circuit:s,actions:c,builtFrom:o}),L=DL({design:t,circuit:s,actions:c,locked:D.locked,camera:k,selection:u,onSelect:d,builtFrom:o,wiring:M.wiring||M.drawing!==null}),R=OL({design:t,circuit:s,camera:k,locked:D.locked}),ae=hD({view:`schematic`,design:t,circuit:s,actions:c,locked:D.locked,builtFrom:o}),oe=XR({design:t,circuit:s,actions:c,camera:k,locked:D.locked},M,N,P,F),z=$R(P,N,F,oe);YR(M,N,P,F,oe);let se=ik({...ie,camera:k,setCamera:A,size:w,boxes:D.boxes,anchors:D.anchors,step:h,snap:g,builtFrom:o,labels:I.tools,wires:L.hits,drawings:R.hits,texts:ae.tools,selection:u,tool:z,filter:e.pickFilter,onContextMenu:e.onContextMenu});BR(t,N,c);let ce=kE(D,h,g),le=AE(S,u.primary,D.boxes,k,w,L.menuWire),ue={...ie,selection:u,layout:ce,builtMark:r,buildStatus:i,moveWaiting:se.pending!==void 0,menuPlace:le,onContextMenu:e.onContextMenu,wire:L.keys,drawings:R.removal},{highlight:de,rotateHeld:fe,keyMoving:pe}=JR({design:t,builtFrom:o,camera:k,cursor:T,fit:j,wire:M,palette:N,drawBusy:F.busy,highlightNets:f,onHighlight:p,keys:ue,texts:ae}),me=RR({boxes:D.boxes,wire:M,labels:I.tools,filter:e.pickFilter,wires:L.hits,drawings:R.hits,texts:ae.tools,setCursor:E}),{gesture:V}=se,he=gD(ae,V),ge=(0,l.useMemo)(()=>({...he,hover:me.text}),[he,me.text]),_e=se.moving??pe,ve=qR(t,V,I.pending,_e?.labels),ye=(0,l.useMemo)(()=>L.lineOf(me.wire),[L.lineOf,me.wire]),be=GR(V,L.pending,_e?.wires);IR(C,{design:t,border:te,camera:k,size:w,wire:M,moving:_e,boxes:D.boxes,hover:me.part,selection:u,locked:D.locked,circuit:s,gesture:V,movingLabels:ve,hoverLabel:me.label,hoverDrawing:R.drawingOf(me.drawing),hoverWire:ye,selectedWire:L.selected,wireShapes:be,palette:N,draw:F,highlight:de,markers:v,activeViolation:y,grid:ee,texts:ge,theme:e.theme});let xe={selection:u,armed:z.armed,filter:e.pickFilter},Se=e=>cn(t,e)?.file,Ce=k??MR,we={view:`schematic`,design:t,scale:Ce.scale,context:xe,boxes:D.boxes,labels:I.tools,wires:L.hits,drawings:R.hits,texts:ae.tools},Te=HN({enabled:e.hoverLabels,busy:M.drawing!==null||F.busy,probe:{pick:e=>lP(e,we),still:(e,t)=>fP(e,t,we)},camera:k,design:t}),Ee=e=>{Px(`sch`,e),me.at(e),Te.move(e,B(Ce,w,e))},De=()=>{Te.leave(),me.leave()},Oe=BN(ez({symbolEdit:ne,sheetOf:Se,onOpenSheet:e.onOpenSheet,camera:k,size:w,element:S,gestures:se,setCursor:E,hover:Ee,boxes:D.boxes,labels:I.tools,wires:L.hits,drawings:R.hits,corners:L.corners,wire:M,palette:N,note:P,draw:F,marks:oe,picking:xe,onOpenProperties:e.onOpenProperties}),Te,C),ke=ak(V,M.drawing!==null||M.overPin||N.armed||P.armed||F.armed||oe.armed,me.over);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(LR,{step:h,setStep:_,keep:{show:D.autoPlaced,onKeep:()=>ze(t,`schematic`,D.blockerFor,c,s)}}),(0,Z.jsx)(zR,{wrapRef:S,canvasRef:C,size:w,camera:k,cursor:T,pointer:Oe,onLeave:De,cursorStyle:ke,wire:M,palette:N,note:P,draw:F,gesture:V,rotateHeld:fe,snap:g,empty:D.boxes.length===0,symbolHint:ne.hint,label:Te.state,markHint:oe.hint})]})}function nz(){document.getElementById(`doc-panel`)?.focus()}function rz({text:e,seq:t,onText:n,onSearch:r,onClose:i,status:a}){let o=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=()=>{o.current?.focus(),o.current?.select()};e();let t=window.setTimeout(e,0);return()=>window.clearTimeout(t)},[t]);let s=()=>{i(),nz()};return(0,Z.jsxs)(`div`,{className:`find-box`,role:`search`,children:[(0,Z.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,Z.jsx)(`button`,{type:`button`,className:`find-close`,title:`Close (Esc)`,"aria-label":`Close the find box`,onClick:s,children:(0,Z.jsx)(cm,{})}),(0,Z.jsx)(`span`,{className:`find-status`,role:`status`,"aria-live":`polite`,children:a})]})}var iz=new Set([`name`,`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`layer`,`side`]),az=`Press Ctrl+F to find a part or a net.`,oz=e=>`Nothing matches "${e}".`;function sz(e,t){return e===null?``:t===0?`No results`:t===1?`1 result`:`${t} results`}var cz=new Intl.Collator(`en`,{numeric:!0});function lz(e){let t=new Map(np(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 uz=e=>typeof e==`string`||typeof e==`number`?String(e):void 0;function dz(e,t){return t.find(t=>t.component===e.tag)}function fz(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=iz.has(t)?void 0:uz(r.literal);e!==void 0&&n.push({field:t,text:e})}let r=dz(e,t);return r?.mpn&&n.push({field:`mpn`,text:r.mpn}),r&&n.push({field:`title`,text:r.title}),n}function pz(e,t,n){let r=fz(e,t).filter(e=>e.text.toLowerCase().includes(n));return r.filter((e,t)=>r.findIndex(t=>t.field===e.field)===t)}function mz(e,t){return e.names.filter(e=>e.toLowerCase().includes(t)).map(e=>({field:`net name`,text:e}))}var hz=(e,t)=>cz.compare(e.name,t.name);function gz(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:pz(e,r,i)})).filter(e=>e.matches.length>0).sort(hz),o=n.map(e=>({id:`net:${e.id}`,kind:`net`,name:e.label,net:e.id,matches:mz(e,i)})).filter(e=>e.matches.length>0).sort(hz);return[...a,...o]}function _z(e){return e.matches.map(e=>e.field===`name`||e.field===`net name`?e.field:`${e.field} ${e.text}`).join(`, `)}function vz(e,t,n){if(e.kind===`net`)return e.net?{highlight:[e.net]}:{};let r=t?Te(t,n).get(e.name)?.origin:void 0;return{select:e.name,...r?{focus:{view:n,at:r}}:{}}}var yz={pcb:`Show on the PCB`,schematic:`Show on the schematic`,code:`From the code`};function bz({rows:e,counts:t,active:n,onPick:r}){let i=(0,l.useMemo)(()=>jS(e),[e]);return(0,Z.jsxs)(`section`,{className:`checks`,"aria-label":`Checks`,onClick:Fp,children:[(0,Z.jsxs)(`header`,{className:`checks-head hairline-b`,children:[(0,Z.jsx)(`h2`,{children:`Checks`}),e.length>0&&(0,Z.jsx)(`span`,{className:`count`,children:FS(t)})]}),(0,Z.jsx)(`div`,{className:`checks-body`,children:i.length===0?(0,Z.jsx)(`p`,{className:`note ok`,children:vS}):i.map(e=>(0,Z.jsx)(xz,{group:e,active:n,onPick:r},e.code))})]})}function xz({group:e,active:t,onPick:n}){return(0,Z.jsxs)(`section`,{className:`check-group ${e.severity}`,children:[(0,Z.jsxs)(`h3`,{children:[(0,Z.jsx)(`span`,{className:`dot`,role:`img`,"aria-label":e.severity===`error`?`Error`:`Warning`}),(0,Z.jsx)(`span`,{className:`code`,children:e.code}),(0,Z.jsx)(`span`,{className:`count`,children:e.rows.length})]}),(0,Z.jsx)(`ul`,{children:e.rows.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(Sz,{row:e,active:e.id===t,onPick:n})},e.id))})]})}function Sz({row:e,active:t,onPick:n}){return(0,Z.jsxs)(`button`,{className:`check-row ${e.severity}${t?` active`:``}`,"aria-current":t||void 0,title:yz[e.view],onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`message`,children:e.message}),e.items.length>0&&(0,Z.jsx)(`span`,{className:`items`,children:e.items.join(`, `)})]})}var Cz={part:`Select the part`,net:`Highlight the net`};function wz({query:e,rows:t,active:n,pick:r}){return e===null?(0,Z.jsx)(`p`,{className:`note bottom-note`,children:az}):t.length===0?(0,Z.jsx)(`p`,{className:`note bottom-note`,children:oz(e)}):(0,Z.jsxs)(`section`,{className:`find-results`,"aria-label":`Find results`,onClick:Fp,children:[(0,Z.jsxs)(`header`,{className:`find-head hairline-b`,children:[(0,Z.jsx)(`h2`,{children:`Find results`}),(0,Z.jsx)(`span`,{className:`count`,children:`${t.length} found for "${e}"`})]}),(0,Z.jsx)(`ul`,{children:t.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{className:`find-row${e.id===n?` active`:``}`,"aria-current":e.id===n||void 0,title:Cz[e.kind],onClick:()=>r(e),children:[(0,Z.jsx)(`span`,{className:`kind ${e.kind}`,children:e.kind===`part`?`Part`:`Net`}),(0,Z.jsx)(`span`,{className:`name`,children:e.name}),(0,Z.jsx)(`span`,{className:`matched`,children:_z(e)})]})},e.id))})]})}function Tz(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 Ez({history:e,problems:t,actions:n}){let r=t.map(e=>(0,Z.jsxs)(`p`,{className:`note`,role:`alert`,children:[`Skipped `,e.file,`: `,e.reason]},e.file));return e.length===0?(0,Z.jsxs)(Z.Fragment,{children:[t.length===0&&(0,Z.jsx)(`p`,{className:`note`,children:`Changes from you and the agent appear here.`}),r]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`ul`,{className:`history`,children:e.map(e=>{let t=Tz(e);return(0,Z.jsxs)(`li`,{className:t.className,children:[(0,Z.jsx)(`span`,{className:`who ${e.author}`,children:e.author===`ai`?`Agent`:`You`}),(0,Z.jsx)(`span`,{className:`what`,title:e.file,children:e.summary}),t.note&&(0,Z.jsx)(`span`,{className:`history-note`,children:t.note}),t.undoable&&(0,Z.jsx)(`button`,{className:`icon`,"aria-label":`Undo ${e.summary}`,onClick:()=>void n.undo(e.id),children:(0,Z.jsx)(sm,{})})]},e.id)})}),r]})}var Dz={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 Oz(e){let t=Dz[e]??{},n=Object.keys(t).find(e=>e!==`footprint`);return n?t[n]??``:``}function kz(e){let t=e.library.map(e=>({part:e.id,name:e.mpn??e.id,value:``,footprint:e.footprint,description:e.title,verified:e.verified?`Verified`:`Unverified`,tooltip:`${e.title} (${e.component})`,verifiedTip:e.verified?`Checked by ${e.verifiedBy}`:`Not checked against the datasheet yet`,extra:`${e.id} ${e.mpn??``} ${e.component}`})),n=e.builtin.map(e=>({part:e,name:e,value:Oz(e),footprint:Dz[e]?.footprint??``,description:``,verified:``,tooltip:e,verifiedTip:``,extra:e}));return[...t,...n]}function Az(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 jz(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 Mz=(e,t)=>e===null||t-e>=500,Nz=e=>e<=1,Pz=(e,t)=>Math.max(0,Math.min(e,t-1));function Fz(e){let t=(0,l.useRef)(null);return n=>{let r=Date.now();Mz(t.current,r)&&(t.current=r,e(n))}}function Iz(){return(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`wide`,children:`Name`}),(0,Z.jsx)(`th`,{children:`Value`}),(0,Z.jsx)(`th`,{children:`Footprint`}),(0,Z.jsx)(`th`,{className:`wide`,children:`Description`}),(0,Z.jsx)(`th`,{children:`Verified`}),(0,Z.jsx)(`th`,{className:`action`,"aria-label":`Place`})]})})}function Lz({row:e,tabStop:t,onFocus:n,onPlace:r,onKey:i}){return(0,Z.jsxs)(`tr`,{tabIndex:t?0:-1,title:e.tooltip,onFocus:n,onDoubleClick:r,onKeyDown:i,children:[(0,Z.jsx)(`td`,{className:`wide`,children:e.name}),(0,Z.jsx)(`td`,{children:e.value}),(0,Z.jsx)(`td`,{children:e.footprint}),(0,Z.jsx)(`td`,{className:`wide`,children:e.description}),(0,Z.jsx)(`td`,{children:e.verified&&(0,Z.jsx)(`span`,{className:`badge ${e.verified===`Verified`?`verified`:`unverified`}`,title:e.verifiedTip,children:e.verified})}),(0,Z.jsx)(`td`,{className:`action`,children:(0,Z.jsx)(`button`,{className:`lib-place`,tabIndex:-1,onClick:e=>Nz(e.detail)&&r(),onDoubleClick:e=>e.stopPropagation(),"aria-label":`Place ${e.name}`,children:`Place`})})]})}function Rz({parts:e,onPlace:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useRef)(null),[a,o]=(0,l.useState)(0),s=(0,l.useId)(),c=Fz(t),u=(0,l.useMemo)(()=>Az(kz(e),n),[e,n]),d=Pz(a,u.length),f=(e,t,n)=>{if(e.target!==e.currentTarget)return;let r=jz(e.key,t,u.length,e.repeat);r&&(e.preventDefault(),`place`in r?c(n):(i.current?.rows[r.move])?.focus())};return(0,Z.jsxs)(`div`,{className:`lib-table`,children:[(0,Z.jsx)(`input`,{className:`lib-table-search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:n,onChange:e=>r(e.target.value)}),(0,Z.jsx)(`p`,{id:s,className:`lib-table-hint`,children:`Enter places the focused part; so does a double click on a row.`}),(0,Z.jsxs)(`div`,{className:`lib-table-scroll hairline-t`,children:[(0,Z.jsxs)(`table`,{"aria-label":`Library parts`,"aria-describedby":s,children:[(0,Z.jsx)(Iz,{}),(0,Z.jsx)(`tbody`,{ref:i,children:u.map((e,t)=>(0,Z.jsx)(Lz,{row:e,tabStop:t===d,onFocus:()=>o(t),onPlace:()=>c(e.part),onKey:n=>f(n,t,e.part)},e.part))})]}),u.length===0&&(0,Z.jsx)(`p`,{className:`note lib-table-empty`,children:`No parts match.`})]})]})}function zz(e){return(0,Z.jsx)(`div`,{className:`bottom-panel hairline-t`,id:wp,role:`tabpanel`,"aria-labelledby":Tp(e.tab),onClick:Fp,children:(0,Z.jsx)(Bz,{...e})})}function Bz(e){switch(e.tab){case`library`:return(0,Z.jsx)(Rz,{parts:e.parts,onPlace:e.onPlace});case`log`:return(0,Z.jsx)(`div`,{className:`bottom-scroll`,children:(0,Z.jsx)(Ez,{history:e.history,problems:e.historyProblems,actions:e.actions})});case`drc`:return e.built?(0,Z.jsx)(bz,{rows:e.rows,counts:e.counts,active:e.active,onPick:e.onPick}):(0,Z.jsx)(`p`,{className:`note bottom-note`,children:e.buildError??`Building the circuit…`});case`find`:return(0,Z.jsx)(wz,{...e.find})}}var Vz=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},Hz={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`},Uz={alignLeft:`Ctrl+Shift+L`,distributeH:`Ctrl+Shift+H`};function Wz(e){if(e<2)return[];let t=t=>{let n=b(t,e),r=Uz[t];return{label:Hz[t],command:t,...r?{shortcut:r}:{},...n?{pending:n}:{}}};return[`separator`,...g.slice(0,6).map(t),`separator`,...g.slice(6).map(t)]}function Gz({allLocked:e,selected:t}){return[{label:`Properties`,special:`properties`},`separator`,Vz(`Rotate`,`rotate`,`Space`),e?Vz(`Unlock`,`unlock`):Vz(`Lock`,`lock`),Vz(`Highlight its nets`,`highlight`,`H`),Vz(`Copy`,`copy`,`Ctrl+C`),...Wz(t),`separator`,Vz(`Delete`,`delete`,`Delete`)]}var Kz=[Vz(`Fit all`,`fit`,`K`),Vz(`Grid style`,`gridStyle`),`separator`,Vz(`Zoom in`,`zoomIn`),Vz(`Zoom out`,`zoomOut`),`separator`,Vz(`Paste`,`paste`,`Ctrl+V`)],qz={remove:null,removeCorners:`Select this wire alone to remove its corners`},Jz=(e,t)=>t?{...e,pending:t}:e;function Yz(e){return[{label:`Properties`,special:`properties`},`separator`,Vz(`Highlight net`,`highlight`,`H`),Jz(Vz(`Remove corners`,`removeCorners`),e?.removeCorners),`separator`,Jz(Vz(`Delete`,`delete`,`Delete`),e?.remove)]}var Xz=[{label:`Properties`,special:`properties`},`separator`,Vz(`Delete`,`delete`,`Delete`)],Zz=[{label:`Rename`,special:`rename`},{label:`Highlight net`,special:`highlightNet`}],Qz=[Vz(`Fillet tracks`,`filletTracks`,`U`),Vz(`Straighten tracks`,`straightenTracks`,`Shift+U`),`separator`];function $z(e,t,n){let r=e.startsWith(`t`)?Qz:[],i=Vz(n?`Delete segment`:`Delete`,`delete`,`Delete`);return[{label:`Properties`,special:`properties`},`separator`,...r,t?Vz(`Unlock`,`unlock`):Vz(`Lock`,`lock`),`separator`,i]}function eB(e){let t={label:`Reset position`,special:`resetText`};return[e?{...t,pending:e}:t,`separator`,{label:`Properties`,special:`properties`}]}function tB(e,t){return e.kind===`part`?Gz(t):e.kind===`copper`?$z(e.id,t.copperLocked,t.segment):e.kind===`wire`?Yz(t.wire):e.kind===`drawing`?[...Xz]:e.kind===`text`?eB(t.textReset):[...e.kind===`label`?Zz:Kz]}function nB(e){return e.map(e=>e===`separator`?`separator`:e.pending?`disabled`:`item`)}function rB(e,t){return e.length>0&&e.every(e=>t.has(e))}function iB(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 aB=28,oB=9,sB=10;function cB(e){return{width:240,height:e.reduce((e,t)=>e+(t===`separator`?oB:aB),0)+sB}}function lB(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 uB(e){(0,l.useEffect)(()=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),[e])}function dB(e,t){let n=(0,l.useRef)(Hg(t));(0,l.useLayoutEffect)(()=>{let t=e.current,r=document.activeElement;return n.current!==null&&t?.querySelector(`[data-item="${n.current}"]`)?.focus(),()=>{r instanceof HTMLElement&&r.isConnected&&Pp(document.activeElement,document.body,t)&&r.focus()}},[e])}var fB=(e,t)=>{let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-item]`):null;return n?Number(n.dataset.item):null};function pB({entries:e,at:t,onRun:n,onClose:r}){let i=(0,l.useRef)(null),a=(0,l.useMemo)(()=>nB(e),[e]),[o,s]=(0,l.useState)(null);(0,l.useLayoutEffect)(()=>{let e=i.current?.getBoundingClientRect();e&&s({width:e.width,height:e.height})},[e]);let c=(0,l.useMemo)(()=>lB(t,o??cB(e),{width:window.innerWidth,height:window.innerHeight}),[t,e,o]);return vm(!0,e=>{let t=fB(i.current,document.activeElement),n=Vg(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()}}),dB(i,a),Dg(!0,i,r),uB(r),(0,Z.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,Z.jsx)(`li`,{className:`menu-separator`,role:`separator`},`sep${t}`):(0,Z.jsx)(`li`,{role:`none`,children:(0,Z.jsx)(Eg,{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 mB=[{view:`schematic`,label:`Schematic`},{view:`pcb`,label:`PCB`}];function hB(e,t,n,r){let i=e===t;return Ye(e)?[{view:`schematic`,label:`Schematic`,active:i}]:mB.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 gB(e,t,n,r,i){return{project:e||`Project`,view:r,files:t.map(e=>({file:e,documents:hB(e,n,r,i)}))}}mB.map(e=>e.view);var _B=`schematic:`,vB=`parent:`;function yB(e){return e.startsWith(vB)?{...yB(e.slice(7)),parent:!0}:e.startsWith(_B)?{view:`schematic`,page:e.slice(10)}:{view:e===`pcb`?`pcb`:`schematic`}}function bB(e,t){return[...t===void 0?[]:xB(t,`pcb`).map(e=>({...e,id:`${vB}${e.id}`,active:!1,parent:!0})),{id:`schematic`,view:`schematic`,title:`${Xe(e)} (sheet)`,active:!0}]}function xB(e,t,n=[Xg],r=Xg,i){if(e!==void 0&&Ye(e))return bB(e,i);let a=(e??``).replace(/\.circuit\.tsx$/,``),o=(e,t)=>a?`${a}${t}${e}`:e;return mB.flatMap(({view:e,label:i})=>e===`pcb`||n.length<=1?[{id:e,view:e,title:o(i,` `),active:e===t}]:n.map(n=>({id:`${_B}${n}`,view:e,page:n,title:o(n,` — `),active:t===`schematic`&&n===r})))}function SB({file:e,view:t,pages:n,page:r,onView:i,onPage:a,parent:o,onParent:s}){let c=xB(e,t,n,r,o),l=c.find(e=>e.active)?.id??t,u=zp({ids:c.map(e=>e.id),current:l,onSelect:e=>{let t=yB(e);t.parent?s?.(t.view):t.page===void 0?i(t.view):a(t.page)}});return(0,Z.jsx)(`div`,{className:`doc-tabs hairline-b`,role:`tablist`,"aria-label":`Documents`,onKeyDown:u.onKeyDown,children:c.map((e,t)=>(0,Z.jsx)(`button`,{role:`tab`,id:e.active||e.page===void 0&&!e.parent?`doc-tab-${e.view}`:`doc-tab-${e.view}-${t}`,"aria-controls":`doc-panel`,"aria-selected":e.active,className:`doc-tab${e.active?` on`:``}`,title:e.title,...u.tab(e.id),children:(0,Z.jsx)(`span`,{className:`doc-tab-label`,children:e.title})},e.id))})}function CB({view:e,filter:t,onToggle:n}){return(0,Z.jsxs)(`aside`,{className:`panel right filter-panel`,id:jT(`right`),role:`tabpanel`,"aria-labelledby":MT(`filter`),onClick:Fp,children:[(0,Z.jsx)(`h3`,{className:`filter-head hairline-b`,children:`Pick`}),(0,Z.jsx)(`ul`,{className:`filter-list`,children:Yi(e).map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`label`,{className:`filter-row`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:t[e.kind],onChange:()=>n(e.kind)}),(0,Z.jsx)(`span`,{children:e.label})]})},e.kind))}),(0,Z.jsx)(`p`,{className:`filter-note`,children:`A kind that is off still draws and stays in the Component tree and the Net list.`})]})}var wB=e=>e?.state===`started`||e?.state===`running`||e?.state===`cleanup`,TB=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,EB=`cleanup stopped at its pass cap`,DB=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function OB(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 ${DB(e.total,`connection`)}`;case`cleanup`:return e.capped?`Autorouting: ${EB}`:`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?`; ${EB}`:``;return`Routed ${e.routed} of ${DB(e.total,`connection`)} in ${DB(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 kB({route:e,onCancel:t}){return!e||!wB(e)?null:(0,Z.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,Z.jsx)(`span`,{children:OB(e)}),(0,Z.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{Fp(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop routing; nothing is written`,children:`Cancel`})]})}var AB=e=>e?.state===`started`||e?.state===`running`,jB=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,MB=(e,t)=>`${e} ${t}${e===1?``:`s`}`,NB=e=>String(Math.round(e));function PB(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 ${MB(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 ${MB(e.placed,`part`)}; wire length ${NB(e.wireLength)} mm (was ${NB(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 FB({place:e,onCancel:t}){return!e||!AB(e)?null:(0,Z.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,Z.jsx)(`span`,{children:PB(e)}),(0,Z.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{Fp(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop placing; nothing is written`,children:`Cancel`})]})}var IB=[{id:`all`,label:`All`},{id:`copper`,label:`Copper`},{id:`non-copper`,label:`Non-copper`}],LB=IB.map(e=>e.id);function RB({pours:e,onTogglePour:t}){return e.length===0?null:(0,Z.jsx)(`ul`,{className:`layer-list layer-pours hairline-t`,"aria-label":`Copper pours`,children:e.map(e=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsxs)(`div`,{className:`layer-pours-title`,children:[`Copper pours · `,e.name]}),(0,Z.jsx)(`ul`,{className:`layer-list`,children:e.pours.map(n=>(0,Z.jsxs)(`li`,{className:`layer-row${n.shown?``:` off`}`,children:[(0,Z.jsx)(`span`,{className:`layer-swatch`,style:{background:lu[n.layer]??U.topCopper,opacity:.6},"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`layer-name`,title:n.id,children:n.net}),(0,Z.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,Z.jsx)(um,{off:!n.shown})})]},n.id))})]},e.layer))})}function zB({active:e,onActive:t}){return(0,Z.jsxs)(`label`,{className:`layer-active hairline-b`,title:`The layer tracks are drawn on (V)`,children:[`Active layer`,(0,Z.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),children:Pi.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})}function BB({filter:e,onFilter:t}){let n=zp({ids:LB,current:e,onSelect:t});return(0,Z.jsx)(`div`,{className:`layer-filters hairline-b`,role:`radiogroup`,"aria-label":`Show layers`,onKeyDown:n.onKeyDown,children:IB.map(({id:t,label:r})=>(0,Z.jsx)(`button`,{className:`layer-filter${e===t?` on`:``}`,role:`radio`,"aria-checked":e===t,...n.tab(t),children:r},t))})}function VB({visibility:e,filter:t,hasKeepouts:n,onFilter:r,onToggle:i,active:a,onActive:o,pours:s,onTogglePour:c}){return(0,Z.jsxs)(`aside`,{className:`panel right layer-panel`,id:jT(`right`),role:`tabpanel`,"aria-labelledby":MT(`layer`),onClick:Fp,children:[(0,Z.jsx)(BB,{filter:t,onFilter:r}),(0,Z.jsx)(zB,{active:a,onActive:o}),(0,Z.jsx)(`ul`,{className:`layer-list`,children:Ii(n,t).map(t=>{let n=e[t.id];return(0,Z.jsxs)(`li`,{className:`layer-row${n?``:` off`}`,children:[(0,Z.jsx)(`span`,{className:`layer-swatch`,style:{background:Li(t)},"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`layer-name`,children:t.name}),(0,Z.jsx)(`button`,{className:`layer-eye`,"aria-pressed":n,"aria-label":t.name,title:`${n?`Hide`:`Show`} ${t.name}`,onClick:()=>i(t.id),children:(0,Z.jsx)(um,{off:!n})})]},t.id)})}),t!==`non-copper`&&(0,Z.jsx)(RB,{pours:s,onTogglePour:c})]})}function HB(e,t,n,r,i){return t.total>1?qz:n&&r?cT(n,r,e,i):void 0}function UB(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 WB(e){let{circuit:t,design:n,selection:r,onSelect:i,run:a,openProperties:o,onHighlight:s,edit:c}=e,[u,d]=(0,l.useState)(null),f=(0,l.useCallback)((e,t)=>{i(t=>iB(t,e)),d({target:e,at:t})},[i]),p=(0,l.useCallback)(()=>d(null),[]);return{open:(0,l.useMemo)(()=>{if(!u)return null;let e=new Set(t?.annotations.locks.map(e=>e.part)),i=iB(r,u.target),{target:a}=u,o=a.kind===`wire`?HB(a.id,i,n,t,e):void 0,s=a.kind===`copper`&&UB(n,i.copper),c=a.kind===`copper`&&i.segment?.id===a.id,l=a.kind===`text`?n&&t?jd(n,t,a.id,e):`It is not on this sheet`:void 0;return{entries:tB(a,{allLocked:rB(i.names,e),selected:i.size,wire:o,copperLocked:s,segment:c,textReset:l}),at:u.at}},[u,t,n,r]),close:p,show:f,runItem:(0,l.useCallback)(e=>{if(e.command)return a(e.command);if(e.special===`properties`)return o();if(e.special===`resetText`&&u?.target.kind===`text`)return void c(Dd(u.target.id),`Reset text position`);if(e.special===`rename`&&u?.target.kind===`label`)return void lC.send({kind:`renameLabel`,labelId:u.target.label.id});e.special===`highlightNet`&&u?.target.kind===`label`&&n&&s([Mf(n.circuit.nets,u.target.label.net)])},[a,o,s,c,u,n])}}function GB(e){return e===`pcb`?[`properties`,`layer`,`filter`]:[`properties`,`filter`]}function KB(e,t){return e.active!==`layer`||t===`pcb`?e:{...e,active:`properties`}}var qB={active:`properties`,open:!0},JB={strip:`design`,sub:`page`,open:!0};function YB(e,t){return e.open&&e.active===t?{...e,open:!1}:{active:t,open:!0}}function XB(e){return{...e,open:!e.open}}function ZB(e,t){return{active:t,open:!0}}function QB(e,t){let n=YB({active:e.strip,open:e.open},t);return{...e,strip:n.active,open:n.open}}function $B(e,t){return{...e,strip:t,open:!0}}function eV(e){return{strip:`design`,sub:e,open:!0}}function tV(e){return{...e,strip:`library`,open:!0}}function nV(e){return{...e,open:!e.open}}var rV=[{id:`design`,label:`Project Design`},{id:`library`,label:`Common Library`}],iV={properties:`Properties`,layer:`Layer`,filter:`Filter`},aV=e=>GB(e).map(e=>({id:e,label:iV[e]}));function oV({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 sV(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 cV(e,t){let n=e?.design,r=e?.actions,i=(0,l.useMemo)(()=>n?$g(n,t):void 0,[n,t]),a=(0,l.useMemo)(()=>r?{...r,edit:(e,n)=>r.edit(Rb(e,t),n),editMarked:(e,n)=>r.editMarked(Rb(e,t),n)}:void 0,[r,t]);return e&&i&&a?{...e,design:i,actions:a}:void 0}function lV({sheetParent:e,onOpenDocument:t}){return e?{parent:e.file,onParent:n=>t(e.file,n)}:{}}function uV(e){let{data:t,workspace:n,checks:r,find:i,view:a,page:o}=e,{build:s}=t,c=oV(e,e.onContextMenu),u=cV(c,o),d=(0,l.useMemo)(()=>Zg(s.design),[s.design]);return(0,Z.jsxs)(`div`,{className:`center`,children:[(0,Z.jsx)(SB,{file:t.file,view:a,pages:d,page:o,onView:e.onView,onPage:e.onPage,...lV(e)}),(0,Z.jsx)(`div`,{className:`ai-lock-band`,children:e.lockControl}),(0,Z.jsxs)(`section`,{className:e.aiLocked?`canvas ai-locked`:`canvas`,id:`doc-panel`,role:`tabpanel`,"aria-labelledby":`doc-tab-${a}`,tabIndex:-1,children:[!s.design&&(0,Z.jsx)(`p`,{className:`empty`,children:s.status===`failed`?s.error:`Building the circuit…`}),c&&a===`pcb`&&(0,Z.jsx)(SF,{...c,...sV(n,`pcb`),markers:r.markers.pcb,activeLayer:n.activeLayer,onActiveLayer:n.setActiveLayer,pourFill:n.pourFill,hiddenPours:n.hiddenPours},t.file),u&&a===`schematic`&&(0,Z.jsx)(tz,{...u,...sV(n,`schematic`),markers:r.markers.schematic},`${t.file}
19
- ${o}`),(0,Z.jsx)(kB,{route:t.route,onCancel:()=>void e.actions.cancelRoute()}),(0,Z.jsx)(FB,{place:t.place,onCancel:()=>void e.actions.cancelAutoplace()}),i.box.open&&(0,Z.jsx)(rz,{text:i.box.text,seq:i.box.seq,onText:i.setText,onSearch:i.search,onClose:i.close,status:sz(i.results.query,i.results.rows.length)})]}),n.bottom.open&&(0,Z.jsx)(zz,{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 dV({data:e,workspace:t,view:n,page:r,selection:i,onSelect:a,actions:o,onPlace:s,onImportPart:c,onNewPart:u,onOpenDocument:d}){let{circuit:f,build:p,project:m,files:h,sheets:g,file:_}=e,v=(0,l.useMemo)(()=>gB(m,[...h,...g],_,n,{names:Zg(p.design),open:r}),[m,h,g,_,n,p.design,r]),y=(0,l.useMemo)(()=>Ue(p.design,n),[p.design,n]);return f?(0,Z.jsx)(RT,{circuit:f,parts:e.parts,onPlace:s,onImport:c,onNewPart:u,selection:i,onSelect:a,actions:o,design:p.design,autoPlaced:y,left:t.left,onSub:t.showSub,pageTree:v,onOpenDocument:d,focusSearch:t.focusSearch,onSearchFocused:t.searchFocused,focusPage:t.focusPage,onPageFocused:t.pageFocused,highlight:t.highlight,onHighlight:t.setHighlight,hidden:!t.leftOpen}):null}function fV({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?Bi(g.pcb.board?.pours??[],e=>Vl(g,e),t.hiddenPours):[];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(qT,{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,Z.jsx)(VB,{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,Z.jsx)(CB,{view:l,filter:t.pickFilter,onToggle:t.togglePickable})]})}function pV(e){let{data:t,workspace:n,selection:r,onSelect:i}=e,a=WB({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,Z.jsxs)(`main`,{className:`workspace`,children:[(0,Z.jsx)(NT,{side:`left`,tabs:rV,active:n.left.strip,open:n.left.open,onClick:n.clickLeft,onSelect:n.selectLeft}),(0,Z.jsx)(dV,{...e}),(0,Z.jsx)(uV,{...e,onContextMenu:a.show}),(0,Z.jsx)(fV,{...e}),(0,Z.jsx)(NT,{side:`right`,tabs:aV(e.view),active:n.right.active,open:n.right.open,onClick:n.clickRight,onSelect:n.selectRight}),a.open&&(0,Z.jsx)(pB,{entries:a.open.entries,at:a.open.at,onRun:a.runItem,onClose:a.close})]})}function mV({file:e,refresh:t,refreshParts:n,notify:r}){let i=(0,l.useCallback)(async n=>{try{return await n(),!0}catch(e){return r(e.message),!1}finally{e&&await t(e).catch(()=>void 0)}},[e,t,r]),a=(0,l.useCallback)(async(e,t)=>{let n;return{ok:await i(async()=>{n=(await z(e,t)).writeMark}),mark:n}},[i]),o=(0,l.useCallback)((t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),[e,a]),s=(0,l.useCallback)((t,n,r)=>a(`/api/layout`,{file:e,edits:t,summary:n,...r?{sheet:r}:{}}),[e,a]);return(0,l.useMemo)(()=>({edit:async(e,t)=>(await o(e,t)).ok,editMarked:o,editFile:(e,t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),editLayout:s,renameParts:(t,n)=>xM(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=>xM(a(`/api/undo`,e?{id:e}:{})),redo:e=>xM(a(`/api/redo`,e?{id:e}:{})),verify:async(e,t,r,a)=>{let o=await i(()=>z(`/api/verify`,{id:e,by:t,against:r,confirm:a}));return o&&await n(),o},makeSheet:t=>i(async()=>{r(Xm((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 r(e.message),!1}},cancelRoute:async()=>{try{return(await z(`/api/route/cancel`,{})).cancelled}catch(e){return r(e.message),!1}},autoplace:async t=>{try{return await z(`/api/autoplace`,{file:e,scope:t}),!0}catch(e){return r(e.message),!1}},cancelAutoplace:async()=>{try{return(await z(`/api/autoplace/cancel`,{})).cancelled}catch(e){return r(e.message),!1}},fitBoard:()=>xM((async()=>{let t;return{ok:await i(async()=>{let n=await z(`/api/fit-board`,{file:e});t=n.writeMark,r(n.summary)}),mark:t}})()),importBoard:(t,n)=>xM((async()=>{let a;return{ok:await i(async()=>{let i=await z(`/api/import-board`,{file:e,name:t,text:n});a=i.writeMark,r(i.summary)}),mark:a}})()),unroute:t=>xM((async()=>{let n;return{ok:await i(async()=>{let i=await z(`/api/unroute`,{file:e,...t?{ids:t}:{}});n=i.writeMark,r(i.summary)}),mark:n}})()),setFilletRadius:t=>i(async()=>{let n=await z(`/api/rules`,{filletRadius:t,...e?{file:e}:{}});n.writeMark!==void 0&&ej({radius:t,mark:n.writeMark}),r(n.summary)}),notify:r}),[e,i,r,n,o,s,a])}function hV({file:e,refresh:t,notify:n},r,i=`Main`){return(0,l.useCallback)(a=>{let o=Dz[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 gV(e,t){return e===0&&t>0}function _V(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 vV({file:e,build:t,route:n,onTab:r,onSelect:i,onSelectCopper:a,onOpen:o}){let s=t.design,c=(0,l.useMemo)(()=>s?AS(s,n):[],[s,n]),u=(0,l.useMemo)(()=>NS(c),[c]),d=(0,l.useMemo)(()=>({pcb:MS(c,`pcb`),schematic:MS(c,`schematic`)}),[c]),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)(null);return yV(e,t,u.errors,o),{rows:c,counts:u,markers:d,active:f,focus:m,pick:(0,l.useCallback)(e=>{let t=_V(e);p(e.id),t.tab&&r(t.tab),t.focus&&h(t.focus),t.select&&i(t.select),t.selectCopper&&a(t.selectCopper,t.selectBoard??[])},[r,i,a]),focused:(0,l.useCallback)(()=>h(null),[]),requestFocus:h}}function yV(e,t,n,r){let i=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{i.current=void 0},[e]);let a=t.status===`done`?t.finishedAt:void 0;(0,l.useEffect)(()=>{a!==void 0&&(gV(i.current,n)&&r(),i.current=n)},[a,n,r])}var bV={open:!1,text:``,seq:0};function xV({file:e,circuit:t,library:n,design:r,view:i,onSelect:a,onHighlight:o,requestFocus:s,openResults:c}){let[u,d]=(0,l.useState)(bV),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)(null),g=t?.model.parts,_=(0,l.useMemo)(()=>f===null?[]:gz(f,g??[],r?lz(r):[],n),[f,g,r,n]);return(0,l.useEffect)(()=>{p(null),h(null)},[e]),{box:u,open:(0,l.useCallback)(()=>d(e=>({...e,open:!0,seq:e.seq+1})),[]),close:(0,l.useCallback)(()=>d(e=>({...e,open:!1})),[]),setText:(0,l.useCallback)(e=>d(t=>({...t,text:e})),[]),search:(0,l.useCallback)(e=>{let t=e.trim();t!==``&&(p(t),h(null),c())},[c]),results:{query:f,rows:_,active:m,pick:(0,l.useCallback)(e=>{let t=vz(e,r,i);if(h(e.id),t.select){let e=t.select;a(t=>t.only(e))}t.focus&&s(t.focus),t.highlight&&o(t.highlight)},[r,i,a,o,s])}}}function SV(e,t,n){let[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)([]),[s,c]=(0,l.useState)();return(0,l.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,l.useCallback)(()=>z(`/api/circuits`).then(i),[])}}function CV(e,t){let[n,r]=(0,l.useState)(),[i,a]=(0,l.useState)(),[o,s]=(0,l.useState)({status:`idle`}),[c,u]=(0,l.useState)([]),[d,f]=(0,l.useState)([]),[m,h]=(0,l.useState)({library:[],builtin:[]}),[g,_]=(0,l.useState)(),[v,y]=(0,l.useState)(),[b,x]=(0,l.useState)(!1),S=(0,l.useCallback)(e=>x(!e),[]),C=(0,l.useCallback)(t=>{p(t)&&s({status:`failed`,error:t}),e(t)},[e]),w=(0,l.useCallback)(async e=>{let[t,n]=await Promise.all([z(`/api/circuit?file=${encodeURIComponent(e)}`),z(`/api/history?limit=30`).catch(e=>({entries:[],problems:[{file:`history`,reason:e.message}]}))]);a(t),u(n.entries),f(n.problems)},[]),T=(0,l.useCallback)(async()=>{h(await z(`/api/parts`))},[]),E=(0,l.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}=SV(C,r,T),A=(0,l.useCallback)(t=>{if(_(t),wB(t))return;e(OB(t));let n=TB(t);n!==void 0&&(xM(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]),j=(0,l.useCallback)(t=>{if(y(t),AB(t))return;e(PB(t));let n=jB(t);n!==void 0&&(xM(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]);return(0,l.useEffect)(()=>{if(n)return t(),_(void 0),y(void 0),w(n).catch(e=>C(e.message)),z(`/api/build`,{file:n}).then(()=>E(n)).catch(e=>C(e.message)),ce((e,t,r)=>{if(e===`library`)T().catch(e=>C(e.message));else if(t===n){if(e===`route`)return A(r);if(e===`place`)return j(r);(e===`change`?w(n):E(n)).catch(e=>C(e.message))}},S)},[n,w,E,T,C,t,A,j,S]),{files:ee,sheets:D,project:O,file:n,setFile:r,circuit:i,build:o,history:c,historyProblems:d,parts:m,route:g,place:v,serverGone:b,refresh:w,refreshParts:T,refreshFiles:k}}function wV(e,t,n,r){let[i,a]=(0,l.useState)(),o=(0,l.useRef)(void 0);(0,l.useEffect)(()=>ie.listen(r),[r]),(0,l.useEffect)(()=>{if(!t)return;let n=e[0];(n?.id!==o.current||i===void 0)&&(o.current=n?.id,a(e=>e===void 0?E(n?.author):n?D(e,n.author):e))},[e,t,i]);let s=i?.closed??!1;return(0,l.useLayoutEffect)(()=>ie.set(s),[s]),TV(s,n),{closed:s,toggle:(0,l.useCallback)(()=>a(e=>ee(e??E(void 0))),[])}}function TV(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e=>{let n=rd(Hu(e),{view:t})?.action;n!==void 0&&j(n)&&(e.preventDefault(),e.stopImmediatePropagation(),ie.refuses())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function EV({closed:e,onToggle:t}){let{title:n,hint:r}=P(e),i=e?rm:im,a=e?34:16;return(0,Z.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,Z.jsx)(i,{className:`ai-lock-icon`,width:a,height:a}),(0,Z.jsxs)(`span`,{className:`ai-lock-words`,children:[(0,Z.jsx)(`span`,{className:`ai-lock-title`,children:n}),(0,Z.jsx)(`span`,{className:`ai-lock-hint`,children:r})]})]})}var DV=`copperflow.hoverLabels`,OV=`off`,kV=`on`;function AV(e){try{return e()?.getItem(DV)!==OV}catch{return!0}}function jV(e,t){try{let n=e();return n?(n.setItem(DV,t?kV:OV),!0):!1}catch{return!1}}var MV=`copperflow.system`,NV={unit:`mm`,grid:{schematic:gh,pcb:mh}},PV=(e,t,n)=>typeof e==`number`&&t.includes(e)?e:n;function FV(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:PV(n.schematic,hh,gh),pcb:PV(n.pcb,ph,mh)}}}function IV(e){try{return FV(e()?.getItem(MV))}catch{return NV}}function LV(e,t){try{let n=e();return n?(n.setItem(MV,JSON.stringify({unit:t.unit,grid:t.grid})),!0):!1}catch{return!1}}function RV(){let[e,t]=(0,l.useState)(Ri),[n,r]=(0,l.useState)(`all`),[i,a]=(0,l.useState)(`top`),o=(0,l.useCallback)(e=>t(t=>Vi(t,e)),[]),[s,c]=(0,l.useState)(()=>new Set);return{layerVisibility:e,layerFilter:n,setLayerFilter:r,toggleLayerShown:o,activeLayer:i,setActiveLayer:a,hiddenPours:s,togglePourShown:(0,l.useCallback)(e=>c(t=>zi(t,e)),[])}}function zV(){let[e,t]=(0,l.useState)(Ki);return{pickFilter:e,togglePickable:(0,l.useCallback)(e=>t(t=>qi(t,e)),[])}}var BV=new Set([`toggleLeftPanel`,`toggleRightPanel`,`toggleBottomPanel`,`toggleUnit`,`clearHighlight`,`openLibrary`,`toggleSnap`]);function VV(e){let[t,n]=(0,l.useState)(JB),[r,i]=(0,l.useState)(qB),a=KB(r,e),[o,s]=(0,l.useState)(Ep);return{left:t,setLeft:n,right:a,setRight:i,bottom:o,setBottom:s,clickLeft:(0,l.useCallback)(e=>n(t=>QB(t,e)),[]),selectLeft:(0,l.useCallback)(e=>n(t=>$B(t,e)),[]),clickRight:(0,l.useCallback)(t=>i(n=>YB(KB(n,e),t)),[e]),selectRight:(0,l.useCallback)(e=>i(t=>ZB(t,e)),[]),clickBottomTab:(0,l.useCallback)(e=>s(t=>Dp(t,e)),[]),openBottom:(0,l.useCallback)(e=>s(t=>kp(t,e)),[]),showSub:(0,l.useCallback)(e=>n(eV(e)),[])}}function HV(){let[e,t]=(0,l.useState)(!1);return[e,(0,l.useCallback)(()=>t(!0),[]),(0,l.useCallback)(()=>t(!1),[])]}function UV(e){let[t,n]=(0,l.useState)(()=>g_(yh,e)),[r,i]=(0,l.useState)(()=>IV(c_).grid);return{gridStyles:t,gridSteps:r,setGridSteps:i,changeGridStep:(0,l.useCallback)((e,t)=>i(n=>_h(n,e,t)),[]),toggleGridStyleOf:(0,l.useCallback)(e=>n(t=>xh(t,e)),[]),gridFollowsTheme:(0,l.useCallback)((e,t)=>n(n=>h_(n,e,t)),[])}}function WV(){let[e,t]=(0,l.useState)(()=>u_(c_));(0,l.useEffect)(()=>f_(document.documentElement,e),[e]);let{gridFollowsTheme:n,...r}=UV(e),i=(0,l.useRef)(e);return{theme:e,setTheme:(0,l.useCallback)(e=>{n(i.current,e),i.current=e,t(e),d_(c_,e)},[n]),grid:r}}function GV(){let[e,t]=(0,l.useState)(!0);return{snap:e,toggleSnap:(0,l.useCallback)(()=>t(e=>!e),[])}}function KV(){let[e,t]=(0,l.useState)(()=>AV(c_)),n=(0,l.useRef)(!0);return(0,l.useEffect)(()=>{n.current?n.current=!1:jV(c_,e)},[e]),{hoverLabels:e,setHoverLabels:t,toggleHoverLabels:(0,l.useCallback)(()=>t(e=>!e),[])}}function qV(){let[e,t]=(0,l.useState)(()=>au(c_));return{pourFill:e,setPourFill:(0,l.useCallback)(e=>{t(e),ou(c_,e)},[])}}function JV(e,t){(0,l.useEffect)(()=>{let n=n=>{let r=rd(Hu(n),{view:e});r&&BV.has(r.action)&&(r.preventDefault&&n.preventDefault(),t(r.action))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function YV(e,t){let[n,r,i]=HV(),[a,o,s]=HV(),[c,u,d]=HV();return{focusSearch:n,requestSearch:r,searchFocused:i,focusPage:a,pageFocused:s,openPageTree:(0,l.useCallback)(()=>{e(eV(`page`)),o()},[e,o]),focusField:c,fieldFocused:d,openProperties:(0,l.useCallback)(()=>{t(e=>ZB(e,`properties`)),u()},[t,u])}}function XV(e,{strips:t,setUnit:n,setHighlight:r,toggleGridStyleOf:i,toggleSnap:a,requestSearch:o}){let{setLeft:s,setRight:c,setBottom:u}=t,d=(0,l.useRef)(e);return d.current=e,(0,l.useCallback)(e=>{e===`toggleLeftPanel`&&s(nV),e===`toggleRightPanel`&&c(XB),e===`toggleBottomPanel`&&u(Op),e===`toggleUnit`&&n(sh),e===`toggleGridStyle`&&i(d.current),e===`toggleSnap`&&a(),e===`clearHighlight`&&r(Nf),e===`openLibrary`&&(s(tV),o())},[s,c,u,n,r,o,i,a])}function ZV(e){let{setLeft:t,setRight:n,setBottom:r,...i}=VV(e),{requestSearch:a,...o}=YV(t,n),[s,c]=(0,l.useState)(()=>IV(c_).unit),[u,d]=(0,l.useState)(Nf),{theme:f,setTheme:p,grid:m}=WV(),{toggleGridStyleOf:h,setGridSteps:g,..._}=m,{snap:v,toggleSnap:y}=GV(),{hoverLabels:b,setHoverLabels:x,toggleHoverLabels:S}=KV(),{pourFill:C,setPourFill:w}=qV(),T=RV(),E=zV(),ee=XV(e,{strips:{setLeft:t,setRight:n,setBottom:r},setUnit:c,setHighlight:d,toggleGridStyleOf:h,toggleSnap:y,requestSearch:a});JV(e,ee);let D=(0,l.useCallback)(()=>c(sh),[]),O=(0,l.useCallback)(e=>{p(e.theme),c(e.unit),g(e.grid),x(e.hoverLabels),LV(c_,e)},[p,g,x]);return{...i,..._,theme:f,setTheme:p,applySystem:O,snap:v,hoverLabels:b,toggleHoverLabels:S,pourFill:C,setPourFill:w,...T,...E,...o,leftOpen:i.left.open,unit:s,toggleUnit:D,highlight:u,setHighlight:d,run:ee}}function QV(){let[e,t]=(0,l.useState)(null);return{message:e,notify:(0,l.useCallback)(e=>{t(e),window.setTimeout(()=>t(t=>t===e?null:t),6e3)},[]),dismiss:(0,l.useCallback)(()=>t(null),[])}}function $V(e){(0,l.useEffect)(()=>{let t=t=>{let n=t.target instanceof HTMLElement&&t.target.closest(`input, textarea, select`);t.key===`Escape`&&!n&&e(e=>e.clear())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function eH(e,t){let n=(0,l.useRef)([]);(0,l.useEffect)(()=>{if(!e)return;let r=e.model.parts.map(e=>e.name),i=Aa(n.current,r);n.current=r,i.length>0&&t(e=>e.without(i))},[e,t])}function tH(e,t){let n=(0,l.useRef)(void 0),r=(0,l.useRef)([]);return(0,l.useEffect)(()=>{if(!e||e===n.current)return;let i=n.current;n.current=e;let a=e.schematic.drawings,o=r.current;r.current=qf(Ea.none,o,a).waiting,t(t=>{let n=qf(dp(t.wireCount===0?t:xp(t,i&&_p(i.schematic),_p(e.schematic)),i,e),o,a).selection;return Jf(n,i?.schematic.drawings,a)})},[e,t]),{seen:n,onRenameDrawing:(0,l.useCallback)(e=>(r.current=[...r.current,e],()=>{r.current=r.current.filter(t=>t!==e)}),[])}}function nH(e,t,n,r,i){return(0,l.useMemo)(()=>{let a=r===`pcb`?n?.circuit.components.filter(e=>e.instance!==void 0).map(e=>e.id)??[]:[],o=t&&[...t.model.parts.map(e=>e.name),...a],s=n?.schematic,c=e=>e?.map(e=>e.id),l=s&&Kf(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`?yd(n.pcb):r===`schematic`?_d(n.schematic):[]);return Sp(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 rH(e,t){let n=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{let r=n.current;n.current=e,e&&e!==r&&t(t=>zf(t,r,e))},[e,t])}function iH(){return(0,Z.jsxs)(`p`,{className:`empty`,children:[`Open the address that `,(0,Z.jsx)(`code`,{children:`copperflow studio`}),` printed in the terminal. It contains a key for this session.`]})}function aH(e,t,n){return CV(e,(0,l.useCallback)(()=>{t(Ea.none),n(Nf)},[t,n]))}function oH({data:e,tab:t,setTab:n,select:r,selectOnly:i,workspace:a}){let{file:o,build:s}=e,{setHighlight:c,openBottom:u}=a,d=(0,l.useCallback)(()=>u(`drc`),[u]),f=(0,l.useCallback)((e,t)=>r(()=>Ea.none.all([],[],[],[],e).addBoard(t)),[r]),p=vV({file:o,build:s,route:e.route,onTab:n,onSelect:i,onSelectCopper:f,onOpen:d}),m=(0,l.useCallback)(()=>u(`find`),[u]);return{checks:p,find:xV({file:o,circuit:e.circuit,library:e.parts.library,design:s.design,view:t,onSelect:r,onHighlight:c,requestFocus:p.requestFocus,openResults:m}),openChecks:d}}function sH(){let e=QV(),[t,n]=(0,l.useState)(Ea.none),r=(0,l.useCallback)(e=>n(t=>t.only(e)),[]),[i,a]=(0,l.useState)(`pcb`),[o,s]=(0,l.useState)(null),c=ZV(i),u=aH(e.notify,n,c.setHighlight),{file:d,setFile:f,build:p,circuit:m}=u;eH(m,n);let{seen:h,onRenameDrawing:g}=tH(p.design,n),_=nH(t,m,p.design,i,h.current),v=mV({file:d,refresh:u.refresh,refreshParts:u.refreshParts,notify:e.notify}),[y,b]=(0,l.useState)(Xg),x=Qg(p.design,y),S=hV({file:d,refresh:u.refresh,refreshParts:u.refreshParts,notify:e.notify},r,i===`schematic`?x:Xg),{checks:C,find:w,openChecks:T}=oH({data:u,tab:i,setTab:a,select:n,selectOnly:r,workspace:c});$V(n),rH(p.design,c.setHighlight);let E=(0,l.useCallback)(()=>s(null),[]),ee=(0,l.useCallback)(()=>s(`importPart`),[]),D=(0,l.useCallback)(()=>s(`newPart`),[]),[O,k]=(0,l.useState)(),A=(0,l.useCallback)((e,t,n)=>{n===void 0?e!==d&&b(Xg):b(n),Ye(e)?k(e=>d&&!Ye(d)?{file:d,design:p.design}:e):k(void 0),f(e),a(Ye(e)?`schematic`:t)},[f,d,p.design]),j=(0,l.useCallback)(e=>A(e,`schematic`),[A]),te=(0,l.useCallback)(e=>{b(e),a(`schematic`)},[]),M=p.design?.pcb,ne=(0,l.useMemo)(()=>i===`pcb`&&M?Gi(M.parts,c.layerVisibility):void 0,[i,M,c.layerVisibility]),N=(0,l.useMemo)(()=>p.design?$g(p.design,x).schematic:void 0,[p.design,x]),P={sheetWires:(0,l.useMemo)(()=>i===`schematic`&&N?N.wires.map(e=>e.id):[],[i,N]),sheetLabels:(0,l.useMemo)(()=>i===`schematic`&&N?N.labels.map(e=>e.id):[],[i,N]),sheetDrawings:(0,l.useMemo)(()=>i===`schematic`&&N?N.drawings.map(e=>e.id):[],[i,N]),pcbCopper:(0,l.useMemo)(()=>i===`pcb`&&M?Cl(M,c.layerVisibility).map(({kind:e,id:t})=>({kind:e,id:t})):[],[i,M,c.layerVisibility]),copperRecords:i===`pcb`?M:void 0},re=wV(u.history,m!==void 0,i,e.notify),I=gS({file:d,view:i,setView:a,selection:_,select:n,circuit:m,actions:v,pickLayers:ne,pickFilter:c.pickFilter,...P,workspace:c,openChecks:T,checkCounts:C.counts,openFind:w.open,openDialog:s,design:p.design,page:x,openPage:te,highlight:c.highlight});return{aiLock:re,toast:e,tab:i,setTab:a,dialog:o,closeDialog:E,openImportPart:ee,openNewPart:D,workspace:c,data:u,selection:_,select:n,onRenameDrawing:g,actions:v,place:S,checks:C,find:w,openChecks:T,openDocument:A,openSheet:j,sheetParent:O,runCommand:(0,l.useCallback)(e=>re.closed&&F(e)?void ie.refuses():I(e),[re.closed,I]),page:x,openPage:te}}function cH(e){return(0,l.useMemo)(()=>{let t=We(e);return t===null?{}:{tidySheet:t}},[e])}function lH(e,t){return(0,l.useMemo)(()=>({import:async n=>{let r=await z(`/api/import-part`,n);return await e(),t(Pm(r)),r}}),[e,t])}function uH(e,t){return(0,l.useMemo)(()=>({create:async n=>{let r=await z(`/api/create-part`,n);return await e(),t(Tg(r)),r}}),[e,t])}function dH(e,t,n){return(0,l.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 fH(e,t,n){return(0,l.useMemo)(()=>{let r=new Set(t?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));return{source:e&&t?{components:e.circuit.components,parts:t.model.parts,locked:r}:void 0,write:n.edit}},[e,t,n])}function pH(e,t,n,r){return(0,l.useMemo)(()=>({question:uv(t),showChecks:n,exportAnyway:()=>rS(e,r)}),[e,t,n,r])}function mH(e,t,n){return(0,l.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 hH(){let{aiLock:e,toast:t,tab:n,setTab:r,dialog:i,closeDialog:a,openImportPart:o,openNewPart:s,workspace:c,data:u,selection:d,select:f,onRenameDrawing:p,actions:m,place:h,checks:g,find:_,openChecks:v,openDocument:y,openSheet:b,sheetParent:x,runCommand:S,page:C,openPage:w}=sH(),{build:T,circuit:E}=u,{message:ee,dismiss:D}=t,O={snap:c.snap,hoverLabels:c.hoverLabels,...p_(c.theme),...su(c.pourFill)},A=cH(T.design),j=(0,l.useMemo)(()=>({...A,...k(e.closed)}),[A,e.closed]),te=mH(u.file,d.names,m),M=lH(u.refreshParts,t.notify),ne=uH(u.refreshParts,t.notify),N=dH(u.refreshFiles,y,t.notify),P=fH(T.design,E,m),F=pH(u.file,g.counts,v,m),re={settings:{theme:c.theme,unit:c.unit,grid:c.gridSteps,hoverLabels:c.hoverLabels},apply:c.applySystem};return(0,l.useEffect)(()=>Gp(window),[]),oe?(0,Z.jsxs)(`div`,{className:`app`,children:[(0,Z.jsx)(Yg,{run:S,view:n,selected:d.size,toggles:O,off:j,children:(0,Z.jsx)(a_,{build:T,errors:g.counts.errors,onOpen:v})}),(0,Z.jsx)(Z_,{view:n,unit:c.unit,selected:d.size,toggles:O,off:j,run:S}),i&&(0,Z.jsx)(wg,{name:i,onClose:a,rules:{fabrication:T.design?.rules.fabrication,save:m.setFilletRadius},makeSheet:te,importPart:M,newPart:ne,system:re,newCircuit:N,footprints:P,exportChecks:F}),u.serverGone&&(0,Z.jsx)(`div`,{className:`banner`,role:`alert`,children:`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`}),E&&E.violations.length>0&&(0,Z.jsxs)(`div`,{className:`banner`,role:`alert`,children:[`Locked parts changed outside the editor: `,E.violations.map(e=>`${e.part} (${e.detail})`).join(`, `),`. Lock them again to accept the change, or undo it in the code.`]}),(0,Z.jsx)(pV,{data:u,workspace:c,checks:g,find:_,view:n,onView:r,page:C,onPage:w,selection:d,onSelect:f,onRenameDrawing:p,actions:m,run:S,onPlace:h,onImportPart:o,onNewPart:s,onOpenDocument:y,onOpenSheet:b,sheetParent:x,openChecks:v,aiLocked:e.closed,lockControl:(0,Z.jsx)(EV,{closed:e.closed,onToggle:e.toggle})}),(0,Z.jsx)(Up,{state:c.bottom,onClick:c.clickBottomTab,onOpen:c.openBottom}),ee&&(0,Z.jsx)(`div`,{className:`toast`,role:`status`,onClick:D,children:ee})]}):(0,Z.jsx)(iH,{})}_m(window),f_(document.documentElement,u_(c_)),(0,u.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(l.StrictMode,{children:(0,Z.jsx)(hH,{})}));export{n as a,Kr as i,Vp as n,U as r,Tg as t};