copperflow 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +21 -4
  2. package/dist/app/assets/NewPartDialog-PSXlbLR2.js +1 -0
  3. package/dist/app/assets/PackagesDialog-C8ZyWl-g.css +1 -0
  4. package/dist/app/assets/PackagesDialog-DmIT8b2D.js +2 -0
  5. package/dist/app/assets/{VerifyPartDialog-Ey6xpQ_U.js → VerifyPartDialog-KiW1nDnZ.js} +2 -2
  6. package/dist/app/assets/footprint-preview-oJ27yBAB.js +160 -0
  7. package/dist/app/assets/index-CArKmuM_.css +1 -0
  8. package/dist/app/assets/index-Yj6ATP2T.js +20 -0
  9. package/dist/app/assets/texture-worker-e8zKC6dv.js +1 -0
  10. package/dist/app/index.html +2 -2
  11. package/dist/cli-commands.d.ts +2 -0
  12. package/dist/cli-commands.js +45 -0
  13. package/dist/cli-commands.js.map +1 -1
  14. package/dist/cli-graphic.d.ts +9 -0
  15. package/dist/cli-graphic.js +62 -0
  16. package/dist/cli-graphic.js.map +1 -0
  17. package/dist/core/annotations.js +2 -2
  18. package/dist/core/annotations.js.map +1 -1
  19. package/dist/core/board-edits.d.ts +2 -0
  20. package/dist/core/board-edits.js +14 -0
  21. package/dist/core/board-edits.js.map +1 -1
  22. package/dist/core/board-graphic-edits.d.ts +8 -0
  23. package/dist/core/board-graphic-edits.js +88 -0
  24. package/dist/core/board-graphic-edits.js.map +1 -0
  25. package/dist/core/board-items.d.ts +6 -0
  26. package/dist/core/board-items.js +8 -3
  27. package/dist/core/board-items.js.map +1 -1
  28. package/dist/core/board-shape-edit.js +4 -2
  29. package/dist/core/board-shape-edit.js.map +1 -1
  30. package/dist/core/edit.js +17 -1
  31. package/dist/core/edit.js.map +1 -1
  32. package/dist/core/graphic-import.d.ts +43 -0
  33. package/dist/core/graphic-import.js +142 -0
  34. package/dist/core/graphic-import.js.map +1 -0
  35. package/dist/core/html-export.d.ts +37 -0
  36. package/dist/core/html-export.js +139 -0
  37. package/dist/core/html-export.js.map +1 -0
  38. package/dist/core/html-page.d.ts +39 -0
  39. package/dist/core/html-page.js +114 -0
  40. package/dist/core/html-page.js.map +1 -0
  41. package/dist/core/html-style.d.ts +3 -0
  42. package/dist/core/html-style.js +117 -0
  43. package/dist/core/html-style.js.map +1 -0
  44. package/dist/core/model-export.d.ts +33 -0
  45. package/dist/core/model-export.js +36 -0
  46. package/dist/core/model-export.js.map +1 -0
  47. package/dist/core/out-name.d.ts +5 -0
  48. package/dist/core/out-name.js +10 -0
  49. package/dist/core/out-name.js.map +1 -0
  50. package/dist/core/packages.d.ts +22 -0
  51. package/dist/core/packages.js +64 -0
  52. package/dist/core/packages.js.map +1 -0
  53. package/dist/core/pad-lines.d.ts +7 -0
  54. package/dist/core/pad-lines.js +15 -0
  55. package/dist/core/pad-lines.js.map +1 -0
  56. package/dist/core/pour-edits.d.ts +12 -1
  57. package/dist/core/pour-edits.js +6 -6
  58. package/dist/core/pour-edits.js.map +1 -1
  59. package/dist/core/render.d.ts +2 -1
  60. package/dist/core/render.js.map +1 -1
  61. package/dist/core/rules-patch.d.ts +17 -0
  62. package/dist/core/rules-patch.js +102 -0
  63. package/dist/core/rules-patch.js.map +1 -0
  64. package/dist/core/silk-text-edits.d.ts +8 -0
  65. package/dist/core/silk-text-edits.js +72 -0
  66. package/dist/core/silk-text-edits.js.map +1 -0
  67. package/dist/core/step-export.js +3 -0
  68. package/dist/core/step-export.js.map +1 -1
  69. package/dist/core/types.d.ts +55 -3
  70. package/dist/engine/board-graphic.d.ts +49 -0
  71. package/dist/engine/board-graphic.js +175 -0
  72. package/dist/engine/board-graphic.js.map +1 -0
  73. package/dist/engine/checks/copper-clearance.d.ts +1 -1
  74. package/dist/engine/checks/copper-clearance.js +19 -1
  75. package/dist/engine/checks/copper-clearance.js.map +1 -1
  76. package/dist/engine/checks/copper-pieces.d.ts +8 -2
  77. package/dist/engine/checks/copper-pieces.js +23 -2
  78. package/dist/engine/checks/copper-pieces.js.map +1 -1
  79. package/dist/engine/checks/drc-board-graphic.d.ts +10 -0
  80. package/dist/engine/checks/drc-board-graphic.js +95 -0
  81. package/dist/engine/checks/drc-board-graphic.js.map +1 -0
  82. package/dist/engine/checks/drc-parts.js +3 -1
  83. package/dist/engine/checks/drc-parts.js.map +1 -1
  84. package/dist/engine/checks/drc-pours.js +3 -3
  85. package/dist/engine/checks/drc-pours.js.map +1 -1
  86. package/dist/engine/checks/drc-silk-text.d.ts +15 -0
  87. package/dist/engine/checks/drc-silk-text.js +65 -0
  88. package/dist/engine/checks/drc-silk-text.js.map +1 -0
  89. package/dist/engine/checks/fill-point.d.ts +7 -0
  90. package/dist/engine/checks/fill-point.js +58 -0
  91. package/dist/engine/checks/fill-point.js.map +1 -0
  92. package/dist/engine/checks/stranded-copper.d.ts +14 -0
  93. package/dist/engine/checks/stranded-copper.js +43 -0
  94. package/dist/engine/checks/stranded-copper.js.map +1 -0
  95. package/dist/engine/design.js +1 -1
  96. package/dist/engine/design.js.map +1 -1
  97. package/dist/engine/elaborate.d.ts +2 -0
  98. package/dist/engine/elaborate.js +30 -1
  99. package/dist/engine/elaborate.js.map +1 -1
  100. package/dist/engine/engine.d.ts +4 -1
  101. package/dist/engine/engine.js +5 -2
  102. package/dist/engine/engine.js.map +1 -1
  103. package/dist/engine/fab/graphic-objects.d.ts +7 -0
  104. package/dist/engine/fab/graphic-objects.js +24 -0
  105. package/dist/engine/fab/graphic-objects.js.map +1 -0
  106. package/dist/engine/fab/layers.d.ts +9 -0
  107. package/dist/engine/fab/layers.js +60 -8
  108. package/dist/engine/fab/layers.js.map +1 -1
  109. package/dist/engine/fab/silk-text-strokes.d.ts +16 -0
  110. package/dist/engine/fab/silk-text-strokes.js +28 -0
  111. package/dist/engine/fab/silk-text-strokes.js.map +1 -0
  112. package/dist/engine/fab/stroke-font.d.ts +4 -0
  113. package/dist/engine/fab/stroke-font.js +38 -1
  114. package/dist/engine/fab/stroke-font.js.map +1 -1
  115. package/dist/engine/footprints/array.d.ts +4 -0
  116. package/dist/engine/footprints/array.js +51 -0
  117. package/dist/engine/footprints/array.js.map +1 -0
  118. package/dist/engine/footprints/axial.d.ts +6 -0
  119. package/dist/engine/footprints/axial.js +115 -0
  120. package/dist/engine/footprints/axial.js.map +1 -0
  121. package/dist/engine/footprints/catalogue.d.ts +39 -0
  122. package/dist/engine/footprints/catalogue.js +284 -0
  123. package/dist/engine/footprints/catalogue.js.map +1 -0
  124. package/dist/engine/footprints/chip.js +10 -1
  125. package/dist/engine/footprints/chip.js.map +1 -1
  126. package/dist/engine/footprints/connector.d.ts +16 -0
  127. package/dist/engine/footprints/connector.js +31 -0
  128. package/dist/engine/footprints/connector.js.map +1 -0
  129. package/dist/engine/footprints/dcjack.d.ts +3 -0
  130. package/dist/engine/footprints/dcjack.js +46 -0
  131. package/dist/engine/footprints/dcjack.js.map +1 -0
  132. package/dist/engine/footprints/dpak.d.ts +7 -0
  133. package/dist/engine/footprints/dpak.js +172 -0
  134. package/dist/engine/footprints/dpak.js.map +1 -0
  135. package/dist/engine/footprints/dual.d.ts +11 -2
  136. package/dist/engine/footprints/dual.js +113 -12
  137. package/dist/engine/footprints/dual.js.map +1 -1
  138. package/dist/engine/footprints/index.js +46 -3
  139. package/dist/engine/footprints/index.js.map +1 -1
  140. package/dist/engine/footprints/inductor.d.ts +3 -0
  141. package/dist/engine/footprints/inductor.js +32 -0
  142. package/dist/engine/footprints/inductor.js.map +1 -0
  143. package/dist/engine/footprints/known.js +114 -14
  144. package/dist/engine/footprints/known.js.map +1 -1
  145. package/dist/engine/footprints/ledsmd.d.ts +3 -0
  146. package/dist/engine/footprints/ledsmd.js +52 -0
  147. package/dist/engine/footprints/ledsmd.js.map +1 -0
  148. package/dist/engine/footprints/ledth.d.ts +4 -0
  149. package/dist/engine/footprints/ledth.js +45 -0
  150. package/dist/engine/footprints/ledth.js.map +1 -0
  151. package/dist/engine/footprints/melf.d.ts +8 -0
  152. package/dist/engine/footprints/melf.js +56 -0
  153. package/dist/engine/footprints/melf.js.map +1 -0
  154. package/dist/engine/footprints/pad-roles.d.ts +4 -0
  155. package/dist/engine/footprints/pad-roles.js +32 -0
  156. package/dist/engine/footprints/pad-roles.js.map +1 -0
  157. package/dist/engine/footprints/plcc.d.ts +4 -0
  158. package/dist/engine/footprints/plcc.js +117 -0
  159. package/dist/engine/footprints/plcc.js.map +1 -0
  160. package/dist/engine/footprints/resonator.d.ts +3 -0
  161. package/dist/engine/footprints/resonator.js +33 -0
  162. package/dist/engine/footprints/resonator.js.map +1 -0
  163. package/dist/engine/footprints/screw.d.ts +3 -0
  164. package/dist/engine/footprints/screw.js +51 -0
  165. package/dist/engine/footprints/screw.js.map +1 -0
  166. package/dist/engine/footprints/smallsot.d.ts +8 -0
  167. package/dist/engine/footprints/smallsot.js +143 -0
  168. package/dist/engine/footprints/smallsot.js.map +1 -0
  169. package/dist/engine/footprints/smdbox.d.ts +33 -0
  170. package/dist/engine/footprints/smdbox.js +76 -0
  171. package/dist/engine/footprints/smdbox.js.map +1 -0
  172. package/dist/engine/footprints/smdcan.d.ts +3 -0
  173. package/dist/engine/footprints/smdcan.js +61 -0
  174. package/dist/engine/footprints/smdcan.js.map +1 -0
  175. package/dist/engine/footprints/smdip.d.ts +4 -0
  176. package/dist/engine/footprints/smdip.js +58 -0
  177. package/dist/engine/footprints/smdip.js.map +1 -0
  178. package/dist/engine/footprints/socket.d.ts +8 -0
  179. package/dist/engine/footprints/socket.js +21 -0
  180. package/dist/engine/footprints/socket.js.map +1 -0
  181. package/dist/engine/footprints/sod.d.ts +6 -0
  182. package/dist/engine/footprints/sod.js +63 -6
  183. package/dist/engine/footprints/sod.js.map +1 -1
  184. package/dist/engine/footprints/sot.d.ts +1 -1
  185. package/dist/engine/footprints/sot.js +17 -2
  186. package/dist/engine/footprints/sot.js.map +1 -1
  187. package/dist/engine/footprints/tact.d.ts +3 -0
  188. package/dist/engine/footprints/tact.js +65 -0
  189. package/dist/engine/footprints/tact.js.map +1 -0
  190. package/dist/engine/footprints/tantalum.d.ts +7 -0
  191. package/dist/engine/footprints/tantalum.js +91 -0
  192. package/dist/engine/footprints/tantalum.js.map +1 -0
  193. package/dist/engine/footprints/to92inline.d.ts +14 -0
  194. package/dist/engine/footprints/to92inline.js +21 -0
  195. package/dist/engine/footprints/to92inline.js.map +1 -0
  196. package/dist/engine/footprints/topower.d.ts +7 -0
  197. package/dist/engine/footprints/topower.js +119 -0
  198. package/dist/engine/footprints/topower.js.map +1 -0
  199. package/dist/engine/footprints/usb.d.ts +32 -0
  200. package/dist/engine/footprints/usb.js +109 -0
  201. package/dist/engine/footprints/usb.js.map +1 -0
  202. package/dist/engine/footprints/xtal.d.ts +4 -0
  203. package/dist/engine/footprints/xtal.js +61 -0
  204. package/dist/engine/footprints/xtal.js.map +1 -0
  205. package/dist/engine/graphic-place.d.ts +34 -0
  206. package/dist/engine/graphic-place.js +132 -0
  207. package/dist/engine/graphic-place.js.map +1 -0
  208. package/dist/engine/graphics/curves.d.ts +18 -0
  209. package/dist/engine/graphics/curves.js +75 -0
  210. package/dist/engine/graphics/curves.js.map +1 -0
  211. package/dist/engine/graphics/dxf-entities.d.ts +20 -0
  212. package/dist/engine/graphics/dxf-entities.js +184 -0
  213. package/dist/engine/graphics/dxf-entities.js.map +1 -0
  214. package/dist/engine/graphics/dxf-pairs.d.ts +22 -0
  215. package/dist/engine/graphics/dxf-pairs.js +77 -0
  216. package/dist/engine/graphics/dxf-pairs.js.map +1 -0
  217. package/dist/engine/graphics/dxf.d.ts +5 -0
  218. package/dist/engine/graphics/dxf.js +110 -0
  219. package/dist/engine/graphics/dxf.js.map +1 -0
  220. package/dist/engine/graphics/index.d.ts +9 -0
  221. package/dist/engine/graphics/index.js +30 -0
  222. package/dist/engine/graphics/index.js.map +1 -0
  223. package/dist/engine/graphics/path-data.d.ts +12 -0
  224. package/dist/engine/graphics/path-data.js +162 -0
  225. package/dist/engine/graphics/path-data.js.map +1 -0
  226. package/dist/engine/graphics/rings.d.ts +7 -0
  227. package/dist/engine/graphics/rings.js +93 -0
  228. package/dist/engine/graphics/rings.js.map +1 -0
  229. package/dist/engine/graphics/shapes.d.ts +47 -0
  230. package/dist/engine/graphics/shapes.js +85 -0
  231. package/dist/engine/graphics/shapes.js.map +1 -0
  232. package/dist/engine/graphics/svg-attributes.d.ts +26 -0
  233. package/dist/engine/graphics/svg-attributes.js +116 -0
  234. package/dist/engine/graphics/svg-attributes.js.map +1 -0
  235. package/dist/engine/graphics/svg.d.ts +5 -0
  236. package/dist/engine/graphics/svg.js +118 -0
  237. package/dist/engine/graphics/svg.js.map +1 -0
  238. package/dist/engine/graphics/transform.d.ts +21 -0
  239. package/dist/engine/graphics/transform.js +88 -0
  240. package/dist/engine/graphics/transform.js.map +1 -0
  241. package/dist/engine/graphics/xml.d.ts +10 -0
  242. package/dist/engine/graphics/xml.js +130 -0
  243. package/dist/engine/graphics/xml.js.map +1 -0
  244. package/dist/engine/model.d.ts +55 -0
  245. package/dist/engine/model.js.map +1 -1
  246. package/dist/engine/pcb-place/grow.d.ts +12 -0
  247. package/dist/engine/pcb-place/grow.js +100 -0
  248. package/dist/engine/pcb-place/grow.js.map +1 -0
  249. package/dist/engine/pcb.d.ts +5 -1
  250. package/dist/engine/pcb.js +2 -0
  251. package/dist/engine/pcb.js.map +1 -1
  252. package/dist/engine/pour/cache.js +1 -0
  253. package/dist/engine/pour/cache.js.map +1 -1
  254. package/dist/engine/pour/obstacles.js +18 -1
  255. package/dist/engine/pour/obstacles.js.map +1 -1
  256. package/dist/engine/router/route-board.d.ts +2 -0
  257. package/dist/engine/router/route-board.js +7 -2
  258. package/dist/engine/router/route-board.js.map +1 -1
  259. package/dist/engine/router/unplaced.d.ts +18 -0
  260. package/dist/engine/router/unplaced.js +27 -0
  261. package/dist/engine/router/unplaced.js.map +1 -0
  262. package/dist/engine/rules/rotations.d.ts +12 -3
  263. package/dist/engine/rules/rotations.js +77 -2
  264. package/dist/engine/rules/rotations.js.map +1 -1
  265. package/dist/engine/silk-text.d.ts +40 -0
  266. package/dist/engine/silk-text.js +85 -0
  267. package/dist/engine/silk-text.js.map +1 -0
  268. package/dist/engine/solid/heights-smd.d.ts +3 -0
  269. package/dist/engine/solid/heights-smd.js +81 -0
  270. package/dist/engine/solid/heights-smd.js.map +1 -0
  271. package/dist/engine/solid/heights-through.d.ts +7 -0
  272. package/dist/engine/solid/heights-through.js +93 -0
  273. package/dist/engine/solid/heights-through.js.map +1 -0
  274. package/dist/engine/solid/heights-uno.d.ts +2 -0
  275. package/dist/engine/solid/heights-uno.js +15 -0
  276. package/dist/engine/solid/heights-uno.js.map +1 -0
  277. package/dist/engine/solid/heights.d.ts +2 -0
  278. package/dist/engine/solid/heights.js +43 -18
  279. package/dist/engine/solid/heights.js.map +1 -1
  280. package/dist/library/attach-datasheet.d.ts +2 -0
  281. package/dist/library/attach-datasheet.js +1 -1
  282. package/dist/library/attach-datasheet.js.map +1 -1
  283. package/dist/library/part-fields.d.ts +23 -0
  284. package/dist/library/part-fields.js +55 -0
  285. package/dist/library/part-fields.js.map +1 -0
  286. package/dist/mcp/batch-steps.d.ts +33 -0
  287. package/dist/mcp/batch-steps.js +211 -0
  288. package/dist/mcp/batch-steps.js.map +1 -0
  289. package/dist/mcp/batch.d.ts +16 -0
  290. package/dist/mcp/batch.js +18 -5
  291. package/dist/mcp/batch.js.map +1 -1
  292. package/dist/mcp/board-import-tool.d.ts +1 -1
  293. package/dist/mcp/board-import-tool.js +1 -1
  294. package/dist/mcp/board-import-tool.js.map +1 -1
  295. package/dist/mcp/board-summary.d.ts +1 -1
  296. package/dist/mcp/board-summary.js +32 -1
  297. package/dist/mcp/board-summary.js.map +1 -1
  298. package/dist/mcp/board-tool.d.ts +36 -0
  299. package/dist/mcp/board-tool.js +109 -0
  300. package/dist/mcp/board-tool.js.map +1 -0
  301. package/dist/mcp/copper-summary.d.ts +2 -0
  302. package/dist/mcp/copper-summary.js +10 -2
  303. package/dist/mcp/copper-summary.js.map +1 -1
  304. package/dist/mcp/copper-tools.d.ts +1 -1
  305. package/dist/mcp/copper-tools.js +1 -1
  306. package/dist/mcp/copper-tools.js.map +1 -1
  307. package/dist/mcp/create-part.js +2 -2
  308. package/dist/mcp/create-part.js.map +1 -1
  309. package/dist/mcp/graphic-tool.d.ts +34 -0
  310. package/dist/mcp/graphic-tool.js +29 -0
  311. package/dist/mcp/graphic-tool.js.map +1 -0
  312. package/dist/mcp/guide.d.ts +3 -1
  313. package/dist/mcp/guide.js +15 -4
  314. package/dist/mcp/guide.js.map +1 -1
  315. package/dist/mcp/html-tool.d.ts +28 -0
  316. package/dist/mcp/html-tool.js +21 -0
  317. package/dist/mcp/html-tool.js.map +1 -0
  318. package/dist/mcp/model-tool.d.ts +31 -0
  319. package/dist/mcp/model-tool.js +27 -0
  320. package/dist/mcp/model-tool.js.map +1 -0
  321. package/dist/mcp/new-circuit.d.ts +1 -1
  322. package/dist/mcp/new-circuit.js +10 -11
  323. package/dist/mcp/new-circuit.js.map +1 -1
  324. package/dist/mcp/part-tools.d.ts +20 -0
  325. package/dist/mcp/part-tools.js +40 -0
  326. package/dist/mcp/part-tools.js.map +1 -0
  327. package/dist/mcp/place-tools.d.ts +1 -1
  328. package/dist/mcp/place-tools.js +11 -5
  329. package/dist/mcp/place-tools.js.map +1 -1
  330. package/dist/mcp/project-tools.js +2 -0
  331. package/dist/mcp/project-tools.js.map +1 -1
  332. package/dist/mcp/render-tool.d.ts +2 -0
  333. package/dist/mcp/render-tool.js +32 -1
  334. package/dist/mcp/render-tool.js.map +1 -1
  335. package/dist/mcp/route-tools.d.ts +1 -1
  336. package/dist/mcp/route-tools.js +3 -1
  337. package/dist/mcp/route-tools.js.map +1 -1
  338. package/dist/mcp/rules-tool.d.ts +19 -0
  339. package/dist/mcp/rules-tool.js +73 -0
  340. package/dist/mcp/rules-tool.js.map +1 -0
  341. package/dist/mcp/server.js +53 -17
  342. package/dist/mcp/server.js.map +1 -1
  343. package/dist/mcp/text-tool.d.ts +34 -0
  344. package/dist/mcp/text-tool.js +37 -0
  345. package/dist/mcp/text-tool.js.map +1 -0
  346. package/dist/render/render.js +2335 -389
  347. package/dist/studio/server.js +32 -0
  348. package/dist/studio/server.js.map +1 -1
  349. package/dist/version.d.ts +1 -1
  350. package/dist/version.js +1 -1
  351. package/package.json +2 -1
  352. package/skills/copperflow/SKILL.md +8 -8
  353. package/skills/copperflow/references/copper.md +9 -1
  354. package/skills/copperflow/references/design-rules.md +36 -7
  355. package/skills/copperflow/references/editable-subset.md +18 -8
  356. package/skills/copperflow/references/parts-library.md +19 -1
  357. package/skills/copperflow/references/writing-circuits.md +71 -0
  358. package/dist/app/assets/NewPartDialog-BBJaZFCo.js +0 -160
  359. package/dist/app/assets/index-BKoIKo22.css +0 -1
  360. package/dist/app/assets/index-DPmr2dR1.js +0 -20
  361. package/dist/app/assets/texture-worker-CyI_g_XZ.js +0 -1
@@ -5114,11 +5114,11 @@ var require_clipper = __commonJS({
5114
5114
  };
5115
5115
  ClipperLib2.JS.AreaOfPolygons = function(poly, scale) {
5116
5116
  if (!scale) scale = 1;
5117
- var area = 0;
5117
+ var area2 = 0;
5118
5118
  for (var i = 0; i < poly.length; i++) {
5119
- area += ClipperLib2.Clipper.Area(poly[i]);
5119
+ area2 += ClipperLib2.Clipper.Area(poly[i]);
5120
5120
  }
5121
- return area / (scale * scale);
5121
+ return area2 / (scale * scale);
5122
5122
  };
5123
5123
  ClipperLib2.JS.BoundsOfPath = function(path2, scale) {
5124
5124
  return ClipperLib2.JS.BoundsOfPaths([path2], scale);
@@ -5356,25 +5356,25 @@ var require_clipper = __commonJS({
5356
5356
  }
5357
5357
  };
5358
5358
  ClipperLib2.JS.ScaleUpPath = function(path2, scale) {
5359
- var i, p, round = Math.round;
5359
+ var i, p, round2 = Math.round;
5360
5360
  if (!scale) scale = 1;
5361
5361
  i = path2.length;
5362
5362
  while (i--) {
5363
5363
  p = path2[i];
5364
- p.X = round(p.X * scale);
5365
- p.Y = round(p.Y * scale);
5364
+ p.X = round2(p.X * scale);
5365
+ p.Y = round2(p.Y * scale);
5366
5366
  }
5367
5367
  };
5368
5368
  ClipperLib2.JS.ScaleUpPaths = function(paths, scale) {
5369
- var i, j, p, round = Math.round;
5369
+ var i, j, p, round2 = Math.round;
5370
5370
  if (!scale) scale = 1;
5371
5371
  i = paths.length;
5372
5372
  while (i--) {
5373
5373
  j = paths[i].length;
5374
5374
  while (j--) {
5375
5375
  p = paths[i][j];
5376
- p.X = round(p.X * scale);
5377
- p.Y = round(p.Y * scale);
5376
+ p.X = round2(p.X * scale);
5377
+ p.Y = round2(p.Y * scale);
5378
5378
  }
5379
5379
  }
5380
5380
  };
@@ -5576,6 +5576,37 @@ var GLYPHS = {
5576
5576
  "(": "3,6 2,5 2,1 3,0",
5577
5577
  ")": "1,6 2,5 2,1 1,0",
5578
5578
  "#": "1,0 1,6;3,0 3,6;0,2 4,2;0,4 4,4",
5579
+ ":": "2,1 2,1;2,4 2,4",
5580
+ "%": "0,6 1,6 1,5 0,5 0,6;3,1 4,1 4,0 3,0 3,1;0,0 4,6",
5581
+ "=": "0,2 4,2;0,4 4,4",
5582
+ ",": "2,0 1,-1",
5583
+ "!": "2,6 2,2;2,0 2,0",
5584
+ a: "4,4 4,0;4,3 3,4 1,4 0,3 0,1 1,0 3,0 4,1",
5585
+ b: "0,6 0,0;0,1 1,0 3,0 4,1 4,3 3,4 1,4 0,3",
5586
+ c: "4,3 3,4 1,4 0,3 0,1 1,0 3,0 4,1",
5587
+ d: "4,6 4,0;4,1 3,0 1,0 0,1 0,3 1,4 3,4 4,3",
5588
+ e: "0,2 4,2 4,3 3,4 1,4 0,3 0,1 1,0 3,0 4,1",
5589
+ f: "3,6 2,6 1,5 1,0;0,4 3,4",
5590
+ g: "4,4 4,-1 3,-2 1,-2 0,-1;4,3 3,4 1,4 0,3 0,1 1,0 3,0 4,1",
5591
+ h: "0,6 0,0;0,3 1,4 3,4 4,3 4,0",
5592
+ i: "2,4 2,0;2,5.5 2,5.5",
5593
+ j: "3,4 3,-1 2,-2 1,-2 0,-1;3,5.5 3,5.5",
5594
+ k: "0,6 0,0;0,1 3,4;1,2 4,0",
5595
+ l: "1,6 2,6 2,1 3,0",
5596
+ m: "0,4 0,0;0,3 1,4 2,3 2,0;2,3 3,4 4,3 4,0",
5597
+ n: "0,4 0,0;0,3 1,4 3,4 4,3 4,0",
5598
+ o: "1,0 0,1 0,3 1,4 3,4 4,3 4,1 3,0 1,0",
5599
+ p: "0,4 0,-2;0,3 1,4 3,4 4,3 4,1 3,0 1,0 0,1",
5600
+ q: "4,4 4,-2;4,3 3,4 1,4 0,3 0,1 1,0 3,0 4,1",
5601
+ r: "0,4 0,0;0,2 2,4 4,4",
5602
+ s: "4,4 1,4 0,3 1,2 3,2 4,1 3,0 0,0",
5603
+ t: "1,6 1,1 2,0 3,0;0,4 3,4",
5604
+ u: "0,4 0,1 1,0 3,0 4,1;4,4 4,0",
5605
+ v: "0,4 2,0 4,4",
5606
+ w: "0,4 1,0 2,2 3,0 4,4",
5607
+ x: "0,0 4,4;0,4 4,0",
5608
+ y: "0,4 2,0;4,4 1,-2",
5609
+ z: "0,4 4,4 0,0 4,0",
5579
5610
  " ": ""
5580
5611
  };
5581
5612
  var MISSING = "0,0 4,0 4,6 0,6 0,0";
@@ -5583,7 +5614,7 @@ var GLYPH_WIDTH = 4;
5583
5614
  var GLYPH_HEIGHT = 6;
5584
5615
  var ADVANCE = 6;
5585
5616
  function strokesOf(char) {
5586
- const glyph = GLYPHS[char.toUpperCase()] ?? MISSING;
5617
+ const glyph = (Object.hasOwn(GLYPHS, char) ? GLYPHS[char] : void 0) ?? MISSING;
5587
5618
  if (glyph === "") return [];
5588
5619
  return glyph.split(";").map(
5589
5620
  (line2) => line2.split(" ").map((pair2) => {
@@ -5664,8 +5695,8 @@ function sidePlaces(part, clearance, turnFor) {
5664
5695
  const short = DESIGNATOR_HEIGHT / 2 + SILK_WIDTH / 2;
5665
5696
  const found = [];
5666
5697
  const along = { flat: slides(halfW, turnFor(true) === 0 ? long : short), upright: slides(halfH, turnFor(false) === 0 ? short : long) };
5667
- for (const ring2 of RINGS) {
5668
- const gap = clearance + ring2;
5698
+ for (const ring4 of RINGS) {
5699
+ const gap = clearance + ring4;
5669
5700
  for (const side of ["top", "bottom", "left", "right"]) {
5670
5701
  const flat = side === "top" || side === "bottom";
5671
5702
  const rotation = turnFor(flat);
@@ -5753,8 +5784,8 @@ var SilkObstacles = class {
5753
5784
  if (obstacle.component === part.component && obstacle.kind !== "pad") continue;
5754
5785
  const between = obstacle.kind === "courtyard" && spaced && !overlap(box3, obstacle.box) && overlap(reach, obstacle.box);
5755
5786
  if (!between && !overlap(box3, obstacle.box)) continue;
5756
- const area = overlapArea(box3, obstacle.box);
5757
- const weight = between ? BETWEEN : WEIGHT[obstacle.kind] * (obstacle.kind === "courtyard" ? Math.max(area, 1e-3) : 1 + area);
5787
+ const area2 = overlapArea(box3, obstacle.box);
5788
+ const weight = between ? BETWEEN : WEIGHT[obstacle.kind] * (obstacle.kind === "courtyard" ? Math.max(area2, 1e-3) : 1 + area2);
5758
5789
  found.score += weight;
5759
5790
  if (between) found.between += 1;
5760
5791
  else found.fixed += weight;
@@ -5889,7 +5920,7 @@ function placeDesignators(pcb, expansion, clearance) {
5889
5920
  const parts = pcb.parts.filter((part) => part.component !== "");
5890
5921
  const obstacles = obstaclesOf(pcb, expansion, clearance);
5891
5922
  const chosen = /* @__PURE__ */ new Map();
5892
- const settle = (part, place3) => {
5923
+ const settle2 = (part, place3) => {
5893
5924
  chosen.set(part.component, place3);
5894
5925
  obstacles.add("designator", part.component, part.side, textBox(part.component, place3.at, place3.rotation));
5895
5926
  };
@@ -5917,14 +5948,14 @@ function placeDesignators(pcb, expansion, clearance) {
5917
5948
  }
5918
5949
  return least.place;
5919
5950
  };
5920
- for (const part of parts) if (part.nameAt) settle(part, { at: part.nameAt, rotation: part.nameRotation ?? 0 });
5951
+ for (const part of parts) if (part.nameAt) settle2(part, { at: part.nameAt, rotation: part.nameRotation ?? 0 });
5921
5952
  const room = new Map(parts.filter((part) => !part.nameAt).map((part) => [part.component, roomAround(part, tries(part), (place3) => obstacles.covered(part, place3))]));
5922
5953
  const ordered = placingOrder(parts.filter((part) => !part.nameAt), (part) => room.get(part.component) ?? { clear: 0, fair: 0 });
5923
5954
  for (const members of ordered) {
5924
- if (members.length > 1) placeCopies(members, tries, clear, best, settle);
5925
- else settle(members[0], best(members[0]));
5955
+ if (members.length > 1) placeCopies(members, tries, clear, best, settle2);
5956
+ else settle2(members[0], best(members[0]));
5926
5957
  }
5927
- makeRoom(parts, chosen, { tries, clear, fair, settle, covered: (part, place3) => obstacles.covered(part, place3), remove: (part) => obstacles.remove(part.component) });
5958
+ makeRoom(parts, chosen, { tries, clear, fair, settle: settle2, covered: (part, place3) => obstacles.covered(part, place3), remove: (part) => obstacles.remove(part.component) });
5928
5959
  return parts.map((part) => {
5929
5960
  const place3 = chosen.get(part.component);
5930
5961
  const covered = obstacles.covered(part, place3, false);
@@ -6004,13 +6035,13 @@ function tryMoving(part, place3, byName, chosen, placer2) {
6004
6035
  before.forEach(([blocker, was]) => placer2.settle(blocker, was));
6005
6036
  return false;
6006
6037
  }
6007
- function placeCopies(members, tries, clear, best, settle) {
6038
+ function placeCopies(members, tries, clear, best, settle2) {
6008
6039
  const lists = members.map(tries);
6009
6040
  const count = Math.min(...lists.map((list) => list.length));
6010
6041
  const fitsAll = (i) => members.every((member, m) => clear(member, lists[m]?.[i])) && copiesApart(members, lists, i);
6011
6042
  for (let i = 0; i < count; i++) {
6012
6043
  if (!fitsAll(i)) continue;
6013
- members.forEach((member, m) => settle(member, lists[m]?.[i]));
6044
+ members.forEach((member, m) => settle2(member, lists[m]?.[i]));
6014
6045
  return;
6015
6046
  }
6016
6047
  let most = { index: -1, clear: 0 };
@@ -6021,10 +6052,10 @@ function placeCopies(members, tries, clear, best, settle) {
6021
6052
  const rest = [];
6022
6053
  members.forEach((member, m) => {
6023
6054
  const same = most.index >= 0 ? lists[m]?.[most.index] : void 0;
6024
- if (same && clear(member, same)) settle(member, same);
6055
+ if (same && clear(member, same)) settle2(member, same);
6025
6056
  else rest.push(member);
6026
6057
  });
6027
- rest.forEach((member) => settle(member, best(member)));
6058
+ rest.forEach((member) => settle2(member, best(member)));
6028
6059
  }
6029
6060
  function copiesApart(members, lists, i) {
6030
6061
  const boxes = members.map((member, m) => {
@@ -6094,8 +6125,8 @@ var among = (items, kept) => {
6094
6125
  };
6095
6126
  var sameEnd = (a, b) => a !== void 0 && a.x === b.x && a.y === b.y;
6096
6127
  var sameSegment = (a, b) => a !== void 0 && a.id === b.id && a.index === b.index && sameEnd(a.from, b.from) && sameEnd(a.to, b.to);
6097
- function segmentFits(segment, points) {
6098
- return sameEnd(points[segment.index], segment.from) && sameEnd(points[segment.index + 1], segment.to);
6128
+ function segmentFits(segment2, points) {
6129
+ return sameEnd(points[segment2.index], segment2.from) && sameEnd(points[segment2.index + 1], segment2.to);
6099
6130
  }
6100
6131
  var EMPTY = { names: [], wires: [], labels: [], drawings: [], copper: [], texts: [], board: [] };
6101
6132
  var KEYS = ["names", "wires", "labels", "drawings", "copper", "texts", "board"];
@@ -6118,7 +6149,7 @@ var Selection = class _Selection {
6118
6149
  board;
6119
6150
  /** The segment of the track selected alone that a double click picked; undefined when the whole track (or anything else) is. */
6120
6151
  segment;
6121
- constructor(lists, segment) {
6152
+ constructor(lists, segment2) {
6122
6153
  this.names = Object.freeze([...lists.names]);
6123
6154
  this.wires = Object.freeze([...lists.wires]);
6124
6155
  this.labels = Object.freeze([...lists.labels]);
@@ -6126,7 +6157,7 @@ var Selection = class _Selection {
6126
6157
  this.copper = Object.freeze([...lists.copper]);
6127
6158
  this.texts = Object.freeze([...lists.texts]);
6128
6159
  this.board = Object.freeze([...lists.board]);
6129
- this.segment = segment && Object.freeze({ id: segment.id, index: segment.index, from: Object.freeze({ ...segment.from }), to: Object.freeze({ ...segment.to }) });
6160
+ this.segment = segment2 && Object.freeze({ id: segment2.id, index: segment2.index, from: Object.freeze({ ...segment2.from }), to: Object.freeze({ ...segment2.to }) });
6130
6161
  Object.freeze(this);
6131
6162
  }
6132
6163
  static from(lists) {
@@ -6266,8 +6297,8 @@ var Selection = class _Selection {
6266
6297
  return this.soleCopper === id && !this.segment ? this : new _Selection({ ...EMPTY, copper: [id] });
6267
6298
  }
6268
6299
  /** Just this segment of its track. */
6269
- onlySegment(segment) {
6270
- return sameSegment(this.segment, segment) ? this : new _Selection({ ...EMPTY, copper: [segment.id] }, segment);
6300
+ onlySegment(segment2) {
6301
+ return sameSegment(this.segment, segment2) ? this : new _Selection({ ...EMPTY, copper: [segment2.id] }, segment2);
6271
6302
  }
6272
6303
  /** The part taken out when it is in, else added as the primary; the other kinds stay. */
6273
6304
  toggle(name) {
@@ -6709,9 +6740,9 @@ function outline(ctx, drawing) {
6709
6740
  const start = rad(drawing.startAngle);
6710
6741
  ctx.arc(drawing.x, drawing.y, drawing.radius, start, start + rad(sweepOf2(drawing.startAngle, drawing.endAngle)));
6711
6742
  }
6712
- function toneOf(drawing, paint) {
6713
- if (paint.selected?.includes(drawing.id)) return { color: sheetPalette().selection, alpha: 1 };
6714
- return { color: colorOf(drawing), alpha: paint.dim ? HIGHLIGHT_DIM : 1 };
6743
+ function toneOf(drawing, paint2) {
6744
+ if (paint2.selected?.includes(drawing.id)) return { color: sheetPalette().selection, alpha: 1 };
6745
+ return { color: colorOf(drawing), alpha: paint2.dim ? HIGHLIGHT_DIM : 1 };
6715
6746
  }
6716
6747
  function drawJunction(ctx, drawing, color, alpha, selected) {
6717
6748
  ctx.globalAlpha = alpha;
@@ -6722,38 +6753,38 @@ function drawJunction(ctx, drawing, color, alpha, selected) {
6722
6753
  ctx.fill();
6723
6754
  glow(ctx, false);
6724
6755
  }
6725
- function drawDrawings(ctx, drawings, devicePx, paint) {
6756
+ function drawDrawings(ctx, drawings, devicePx, paint2) {
6726
6757
  for (const drawing of drawings) {
6727
6758
  if (drawing.kind === "text") continue;
6728
- const { color, alpha } = toneOf(drawing, paint);
6759
+ const { color, alpha } = toneOf(drawing, paint2);
6729
6760
  if (drawing.kind === "junction") {
6730
- drawJunction(ctx, drawing, color, alpha, paint.selected?.includes(drawing.id) ?? false);
6761
+ drawJunction(ctx, drawing, color, alpha, paint2.selected?.includes(drawing.id) ?? false);
6731
6762
  continue;
6732
6763
  }
6733
6764
  const width = drawnWidth(strokeWidthOf(drawing), devicePx);
6734
6765
  ctx.globalAlpha = alpha;
6735
6766
  ctx.lineWidth = width;
6736
6767
  ctx.strokeStyle = color;
6737
- ctx.setLineDash(dashOf(paint.pending ? "dashed" : lineStyleOf(drawing), width));
6768
+ ctx.setLineDash(dashOf(paint2.pending ? "dashed" : lineStyleOf(drawing), width));
6738
6769
  outline(ctx, drawing);
6739
6770
  if (isFilled(drawing)) {
6740
6771
  ctx.fillStyle = fillOf(color);
6741
6772
  ctx.fill();
6742
6773
  }
6743
- glow(ctx, paint.selected?.includes(drawing.id) ?? false);
6774
+ glow(ctx, paint2.selected?.includes(drawing.id) ?? false);
6744
6775
  ctx.stroke();
6745
6776
  glow(ctx, false);
6746
6777
  ctx.setLineDash([]);
6747
6778
  }
6748
6779
  ctx.globalAlpha = 1;
6749
6780
  }
6750
- function drawDrawingTexts(ctx, drawings, camera, size, paint, ratio) {
6781
+ function drawDrawingTexts(ctx, drawings, camera, size, paint2, ratio) {
6751
6782
  for (const drawing of drawings) {
6752
6783
  if (drawing.kind !== "text" || drawing.text === "") continue;
6753
6784
  const devicePx = devicePxFor(drawing.fontSize, camera.scale, ratio);
6754
6785
  if (!textShown("detail", sheetLevelPx(camera.scale, ratio), devicePx)) continue;
6755
6786
  const fontPx = devicePx / ratio;
6756
- const { color, alpha } = toneOf(drawing, paint);
6787
+ const { color, alpha } = toneOf(drawing, paint2);
6757
6788
  const at2 = textAnchorAt(worldToScreen(camera, size, drawing), ratio);
6758
6789
  const [, horizontal] = anchorAlignment(drawing.anchor);
6759
6790
  ctx.globalAlpha = alpha;
@@ -6858,24 +6889,24 @@ function inkOf(ctx, text2, baseline, size) {
6858
6889
  descent: metrics.actualBoundingBoxDescent ?? FALLBACK_DESCENT * size + drop
6859
6890
  };
6860
6891
  }
6861
- function pinName(ctx, { label, devicePx }, paint) {
6892
+ function pinName(ctx, { label, devicePx }, paint2) {
6862
6893
  const pin = label.pinOf;
6863
6894
  if (!pin) return null;
6864
- const size = devicePx / paint.ratio;
6865
- const p = worldToScreen(paint.camera, paint.size, label.at);
6895
+ const size = devicePx / paint2.ratio;
6896
+ const p = worldToScreen(paint2.camera, paint2.size, label.at);
6866
6897
  const [vertical, horizontal] = anchorAlignment(label.anchor);
6867
- const local = { x: pin.local.x * paint.camera.scale, y: pin.local.y * paint.camera.scale };
6898
+ const local = { x: pin.local.x * paint2.camera.scale, y: pin.local.y * paint2.camera.scale };
6868
6899
  const ink = inkOf(ctx, label.text, vertical, size);
6869
6900
  return { text: label.text, x: p.x, y: p.y, align: horizontal, size, ...ink, local, side: pin.side, quarter: pin.quarter };
6870
6901
  }
6871
- function fitSymbol(ctx, names, paint) {
6902
+ function fitSymbol(ctx, names, paint2) {
6872
6903
  const first = names[0];
6873
6904
  if (!first) return names;
6874
- ctx.font = fontOf(first.label, first.devicePx, paint.ratio);
6875
- const onScreen = names.map((sized) => pinName(ctx, sized, paint)).filter((name) => name !== null);
6905
+ ctx.font = fontOf(first.label, first.devicePx, paint2.ratio);
6906
+ const onScreen = names.map((sized) => pinName(ctx, sized, paint2)).filter((name) => name !== null);
6876
6907
  if (onScreen.length !== names.length) return names;
6877
6908
  const least = Math.ceil(first.devicePx * MIN_NAME_SCALE) / first.devicePx;
6878
- const fits = fitPinNames(onScreen, (text2) => ctx.measureText(text2).width, first.devicePx / paint.ratio * NAME_GAP, least);
6909
+ const fits = fitPinNames(onScreen, (text2) => ctx.measureText(text2).width, first.devicePx / paint2.ratio * NAME_GAP, least);
6879
6910
  return names.flatMap((sized, i) => {
6880
6911
  const fit = fits[i];
6881
6912
  if (!fit) return [];
@@ -6883,36 +6914,36 @@ function fitSymbol(ctx, names, paint) {
6883
6914
  return [{ label: { ...sized.label, text: fit.text }, devicePx }];
6884
6915
  });
6885
6916
  }
6886
- function arrange(ctx, labels, paint) {
6887
- const levelPx = sheetLevelPx(paint.camera.scale, paint.ratio);
6917
+ function arrange(ctx, labels, paint2) {
6918
+ const levelPx = sheetLevelPx(paint2.camera.scale, paint2.ratio);
6888
6919
  const allowed = ({ label, devicePx }) => textShown(label.kind, levelPx, devicePx);
6889
- const shown = labels.filter((label) => label.text !== "").map((label) => ({ label, devicePx: sizeOf(ctx, label, paint) })).filter(allowed);
6920
+ const shown2 = labels.filter((label) => label.text !== "").map((label) => ({ label, devicePx: sizeOf(ctx, label, paint2) })).filter(allowed);
6890
6921
  const bySymbol = /* @__PURE__ */ new Map();
6891
- for (const sized of shown) {
6922
+ for (const sized of shown2) {
6892
6923
  const symbol = sized.label.pinOf?.symbol;
6893
6924
  if (symbol !== void 0) bySymbol.set(symbol, [...bySymbol.get(symbol) ?? [], sized]);
6894
6925
  }
6895
- const fitted = [...bySymbol.values()].flatMap((names) => fitSymbol(ctx, names, paint));
6896
- return [...shown.filter(({ label }) => !label.pinOf), ...fitted.filter(allowed)];
6926
+ const fitted = [...bySymbol.values()].flatMap((names) => fitSymbol(ctx, names, paint2));
6927
+ return [...shown2.filter(({ label }) => !label.pinOf), ...fitted.filter(allowed)];
6897
6928
  }
6898
- function write(ctx, { label, devicePx }, paint) {
6899
- const p = textAnchorAt(worldToScreen(paint.camera, paint.size, label.at), paint.ratio);
6929
+ function write(ctx, { label, devicePx }, paint2) {
6930
+ const p = textAnchorAt(worldToScreen(paint2.camera, paint2.size, label.at), paint2.ratio);
6900
6931
  const [vertical, horizontal] = anchorAlignment(label.anchor);
6901
6932
  ctx.save();
6902
6933
  ctx.translate(p.x, p.y);
6903
6934
  if (label.rotation) ctx.rotate(-label.rotation * Math.PI / 180);
6904
6935
  ctx.globalAlpha = label.alpha ?? 1;
6905
6936
  ctx.fillStyle = label.color;
6906
- ctx.font = fontOf(label, devicePx, paint.ratio);
6937
+ ctx.font = fontOf(label, devicePx, paint2.ratio);
6907
6938
  ctx.textAlign = horizontal;
6908
6939
  ctx.textBaseline = vertical;
6909
6940
  ctx.fillText(label.text, 0, 0);
6910
6941
  ctx.restore();
6911
6942
  }
6912
6943
  function drawSheetTexts(ctx, labels, camera, size, ratio) {
6913
- const paint = { camera, size, ratio };
6944
+ const paint2 = { camera, size, ratio };
6914
6945
  sharpenText(ctx);
6915
- for (const sized of arrange(ctx, labels, paint)) write(ctx, sized, paint);
6946
+ for (const sized of arrange(ctx, labels, paint2)) write(ctx, sized, paint2);
6916
6947
  }
6917
6948
 
6918
6949
  // studio/src/pcb/no-connect-draw.ts
@@ -6975,12 +7006,12 @@ function drawSchematic(ctx, layout, view, options) {
6975
7006
  ctx.lineCap = "round";
6976
7007
  ctx.lineJoin = "round";
6977
7008
  drawWires(ctx, layout, options, px, line2);
6978
- const shown = shownDrawings(layout.drawings, options.movingDrawings);
7009
+ const shown2 = shownDrawings(layout.drawings, options.movingDrawings);
6979
7010
  const pending = options.pendingDrawings ?? [];
6980
- const drawings = [...shown, ...pending];
6981
- const paint = { ...options.selectedDrawings ? { selected: options.selectedDrawings } : {}, dim: options.highlight !== void 0 };
6982
- drawDrawings(ctx, shown, px / options.ratio, paint);
6983
- drawDrawings(ctx, pending, px / options.ratio, { pending: true, dim: paint.dim });
7011
+ const drawings = [...shown2, ...pending];
7012
+ const paint2 = { ...options.selectedDrawings ? { selected: options.selectedDrawings } : {}, dim: options.highlight !== void 0 };
7013
+ drawDrawings(ctx, shown2, px / options.ratio, paint2);
7014
+ drawDrawings(ctx, pending, px / options.ratio, { pending: true, dim: paint2.dim });
6984
7015
  for (const symbol of layout.symbols) drawSymbol(ctx, symbol, shiftOf(symbol), { line: line2, px, fade: symbolFade(symbol, options.highlight) }, texts);
6985
7016
  for (const label of layout.labels) {
6986
7017
  const moving = options.movingLabels?.some((m) => m.id === label.id) ?? false;
@@ -6995,7 +7026,7 @@ function drawSchematic(ctx, layout, view, options) {
6995
7026
  drawNoConnects(ctx, layout.noConnects ?? [], line2, options.highlight !== void 0);
6996
7027
  ctx.setTransform(options.ratio, 0, 0, options.ratio, 0, 0);
6997
7028
  drawSheetTexts(ctx, texts, camera, size, options.ratio);
6998
- drawDrawingTexts(ctx, drawings, camera, size, paint, options.ratio);
7029
+ drawDrawingTexts(ctx, drawings, camera, size, paint2, options.ratio);
6999
7030
  drawViolationMarkers(ctx, view, options.violations ?? [], options.activeViolation, false, { error: sheetPalette().markerError, warning: sheetPalette().markerWarning });
7000
7031
  ctx.restore();
7001
7032
  }
@@ -7047,18 +7078,18 @@ function onSegment(p, a, b) {
7047
7078
  return straight && within(p.x, a.x, b.x) && within(p.y, a.y, b.y);
7048
7079
  }
7049
7080
  function junctionLit(layout, junction, highlight) {
7050
- return layout.wires.some((wire) => toneOf2(wire.net, highlight).color !== void 0 && wire.points.some((b, i) => i > 0 && onSegment(junction, wire.points[i - 1] ?? b, b)));
7081
+ return layout.wires.some((wire2) => toneOf2(wire2.net, highlight).color !== void 0 && wire2.points.some((b, i) => i > 0 && onSegment(junction, wire2.points[i - 1] ?? b, b)));
7051
7082
  }
7052
7083
  function drawWires(ctx, layout, options, px, line2) {
7053
7084
  ctx.lineWidth = line2(WIRE_WIDTH);
7054
- for (const wire of layout.wires) {
7055
- if (options.movingLabels?.some((m) => m.hideWire === wire.id)) continue;
7056
- const selected = options.selectedWires?.includes(wire.id) ?? false;
7057
- const tone = selected ? { color: sheetPalette().selection, alpha: 1 } : toneOf2(wire.net, options.highlight);
7085
+ for (const wire2 of layout.wires) {
7086
+ if (options.movingLabels?.some((m) => m.hideWire === wire2.id)) continue;
7087
+ const selected = options.selectedWires?.includes(wire2.id) ?? false;
7088
+ const tone = selected ? { color: sheetPalette().selection, alpha: 1 } : toneOf2(wire2.net, options.highlight);
7058
7089
  ctx.strokeStyle = tone.color ?? sheetPalette().wire;
7059
7090
  ctx.globalAlpha = tone.alpha;
7060
7091
  glow(ctx, selected);
7061
- path(ctx, wire.points);
7092
+ path(ctx, wire2.points);
7062
7093
  ctx.stroke();
7063
7094
  }
7064
7095
  glow(ctx, false);
@@ -7148,14 +7179,14 @@ function paintShape(ctx, shape) {
7148
7179
  ctx.stroke();
7149
7180
  }
7150
7181
  }
7151
- function textLabel(shape, frame, fallback) {
7182
+ function textLabel(shape, frame, fallback2) {
7152
7183
  const along = shape.anchor === "left" ? 1 : shape.anchor === "right" ? -1 : 0;
7153
7184
  const angle = rad2(frame.rotation);
7154
7185
  const dx = along * Math.cos(angle);
7155
7186
  const dy = along * Math.sin(angle);
7156
7187
  const anchor = Math.abs(dx) > 0.5 ? dx > 0 ? "left" : "right" : Math.abs(dy) > 0.5 ? dy > 0 ? "bottom" : "top" : "center";
7157
7188
  const role = { role: shape.role, kind: TEXT_KINDS[shape.role], ...shape.role === "pin-name" ? { pinOf: pinFrame(shape, frame) } : {}, ...shape.role === "reference" ? { strong: true } : {}, ...shape.role === "pin-number" ? { mono: true } : {} };
7158
- return { text: shape.text, at: place2(shape.at, frame), size: shape.size, anchor, color: sheetPalette()[TEXT_COLORS[shape.role]] ?? fallback, ...role };
7189
+ return { text: shape.text, at: place2(shape.at, frame), size: shape.size, anchor, color: sheetPalette()[TEXT_COLORS[shape.role]] ?? fallback2, ...role };
7159
7190
  }
7160
7191
  function pinFrame(shape, frame) {
7161
7192
  const side = shape.anchor === "left" ? "left" : shape.anchor === "right" ? "right" : shape.at.y > 0 ? "top" : "bottom";
@@ -7247,9 +7278,9 @@ function disc(ctx, at2, radius, color) {
7247
7278
  }
7248
7279
  function drawTracks(ctx, scene, layers, highlight) {
7249
7280
  const active = scene.activeLayer ?? "top";
7250
- const shown = scene.tracks.filter((track) => trackShown(track, layers));
7281
+ const shown2 = scene.tracks.filter((track) => trackShown(track, layers));
7251
7282
  const isActive = (track) => track.layer === active || track.missingLayer !== void 0;
7252
- const ordered = [...shown.filter((track) => !isActive(track)), ...shown.filter(isActive)];
7283
+ const ordered = [...shown2.filter((track) => !isActive(track)), ...shown2.filter(isActive)];
7253
7284
  for (const track of ordered) {
7254
7285
  ctx.globalAlpha = (isActive(track) ? 1 : INACTIVE_COPPER_ALPHA) * litAlpha(highlight, track.net);
7255
7286
  strokePath(ctx, track.points, trackColor(track), track.width);
@@ -7276,24 +7307,24 @@ function drawRoutes(ctx, scene, layers) {
7276
7307
  }
7277
7308
  ctx.globalAlpha = 1;
7278
7309
  }
7279
- function markedPoints(scene, track, wash) {
7280
- const { segment } = scene;
7281
- return wash && segment?.id === track.id && segmentFits(segment, track.points) ? [segment.from, segment.to] : track.points;
7310
+ function markedPoints(scene, track, wash2) {
7311
+ const { segment: segment2 } = scene;
7312
+ return wash2 && segment2?.id === track.id && segmentFits(segment2, track.points) ? [segment2.from, segment2.to] : track.points;
7282
7313
  }
7283
- function mark(ctx, scene, layers, id, color, wash, px) {
7314
+ function mark(ctx, scene, layers, id, color, wash2, px) {
7284
7315
  const track = scene.tracks.find((one) => one.id === id);
7285
7316
  if (track && trackShown(track, layers)) {
7286
- const points = markedPoints(scene, track, wash);
7317
+ const points = markedPoints(scene, track, wash2);
7287
7318
  strokePath(ctx, points, color, track.width + 2 * OUTLINE_PX * px);
7288
7319
  strokePath(ctx, points, trackColor(track), track.width);
7289
- if (wash) strokePath(ctx, points, PALETTE.selectionFill, track.width);
7320
+ if (wash2) strokePath(ctx, points, PALETTE.selectionFill, track.width);
7290
7321
  return;
7291
7322
  }
7292
7323
  const via = scene.vias.find((one) => one.id === id);
7293
7324
  if (!via || !viaShown(via, layers)) return;
7294
7325
  disc(ctx, via.at, via.diameter / 2 + OUTLINE_PX * px, color);
7295
7326
  disc(ctx, via.at, via.diameter / 2, ringColor(via));
7296
- if (wash) disc(ctx, via.at, via.diameter / 2, PALETTE.selectionFill);
7327
+ if (wash2) disc(ctx, via.at, via.diameter / 2, PALETTE.selectionFill);
7297
7328
  if (layers.hole) disc(ctx, via.at, via.drill / 2, PALETTE.drill);
7298
7329
  }
7299
7330
  function drawCopperItems(ctx, scene, layers, highlight, px) {
@@ -7324,8 +7355,8 @@ var MAX_HATCH = 400;
7324
7355
  var HANDLE_PX = 6;
7325
7356
  var OUTLINE_PX2 = 1;
7326
7357
  var SELECTED_PX = 1.5;
7327
- function ringPath(ctx, ring2) {
7328
- ring2.forEach((p, i) => i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y));
7358
+ function ringPath(ctx, ring4) {
7359
+ ring4.forEach((p, i) => i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y));
7329
7360
  ctx.closePath();
7330
7361
  }
7331
7362
  function fillPath(ctx, fill) {
@@ -7407,7 +7438,7 @@ function strokeHatch(ctx, fill, px) {
7407
7438
  }
7408
7439
  ctx.stroke();
7409
7440
  }
7410
- function drawFill(ctx, fill, mode, px) {
7441
+ function drawFill(ctx, fill, mode, px, dim) {
7411
7442
  const color = LAYER_COLOR[fill.layer] ?? PALETTE.topCopper;
7412
7443
  ctx.fillStyle = color;
7413
7444
  ctx.strokeStyle = color;
@@ -7416,21 +7447,21 @@ function drawFill(ctx, fill, mode, px) {
7416
7447
  strokeRings(ctx, fill, OUTLINE_PX2 * px);
7417
7448
  return;
7418
7449
  }
7419
- ctx.globalAlpha = POUR_FILL_ALPHA;
7450
+ ctx.globalAlpha = POUR_FILL_ALPHA * dim;
7420
7451
  if (mode === "solid") return fillRings(ctx, fill, "fill");
7421
7452
  ctx.save();
7422
7453
  fillRings(ctx, fill, "clip");
7423
7454
  ctx.lineWidth = OUTLINE_PX2 * px;
7424
- ctx.globalAlpha = 1;
7455
+ ctx.globalAlpha = dim;
7425
7456
  strokeHatch(ctx, fill, px);
7426
7457
  ctx.restore();
7427
7458
  ctx.globalAlpha = 1;
7428
7459
  strokeRings(ctx, fill, OUTLINE_PX2 * px);
7429
7460
  }
7430
7461
  function drawPourFills(ctx, layout, scene, layers, px) {
7431
- const shown = (layout.pours ?? []).filter((fill) => pourShown(fill, layers, scene.hidden));
7432
- const ordered = [...shown.filter((fill) => fill.layer !== scene.activeLayer), ...shown.filter((fill) => fill.layer === scene.activeLayer)];
7433
- for (const fill of ordered) drawFill(ctx, fill, scene.mode, px);
7462
+ const shown2 = (layout.pours ?? []).filter((fill) => pourShown(fill, layers, scene.hidden));
7463
+ const ordered = [...shown2.filter((fill) => fill.layer !== scene.activeLayer), ...shown2.filter((fill) => fill.layer === scene.activeLayer)];
7464
+ for (const fill of ordered) drawFill(ctx, fill, scene.mode, px, fill.layer === scene.activeLayer ? 1 : INACTIVE_COPPER_ALPHA);
7434
7465
  ctx.globalAlpha = 1;
7435
7466
  }
7436
7467
  function square(ctx, at2, size) {
@@ -7499,6 +7530,201 @@ function drawHoles(ctx, holes, scene, layers, px, hair) {
7499
7530
  }
7500
7531
  }
7501
7532
 
7533
+ // src/engine/fab/silk-text-strokes.ts
7534
+ var LINE_SHARE = 0.1;
7535
+ var silkTextLineWidth = (height) => Math.max(SILK_WIDTH, height * LINE_SHARE);
7536
+ function silkTextStrokes(text2) {
7537
+ const radians = text2.rotation * Math.PI / 180;
7538
+ const [cos, sin] = [Math.cos(radians), Math.sin(radians)];
7539
+ const side = text2.layer === "bottom" ? -1 : 1;
7540
+ return textStrokes(text2.text, { x: 0, y: 0 }, text2.height).map(
7541
+ (line2) => line2.map((p) => ({ x: text2.x + side * (p.x * cos - p.y * sin), y: text2.y + p.x * sin + p.y * cos }))
7542
+ );
7543
+ }
7544
+ function silkTextBox(text2) {
7545
+ const points = silkTextStrokes(text2).flat();
7546
+ const half = silkTextLineWidth(text2.height) / 2;
7547
+ if (points.length === 0) return { minX: text2.x, minY: text2.y, maxX: text2.x, maxY: text2.y };
7548
+ const xs = points.map((p) => p.x);
7549
+ const ys = points.map((p) => p.y);
7550
+ return { minX: Math.min(...xs) - half, minY: Math.min(...ys) - half, maxX: Math.max(...xs) + half, maxY: Math.max(...ys) + half };
7551
+ }
7552
+
7553
+ // studio/src/pcb/silk-text-draw.ts
7554
+ var RING_GAP_PX = 3;
7555
+ var RING_PX2 = 1.5;
7556
+ var HOVER_ALPHA = 0.5;
7557
+ var shown = (layers, text2) => layers[text2.layer === "top" ? "topSilk" : "bottomSilk"];
7558
+ function shownText(text2, scene) {
7559
+ const moving = scene?.moving;
7560
+ return moving && moving.id === text2.id ? { ...text2, x: text2.x + moving.by.x, y: text2.y + moving.by.y } : text2;
7561
+ }
7562
+ function drawSilkTexts(ctx, texts, layers, scene, px) {
7563
+ for (const original of texts) {
7564
+ if (!shown(layers, original)) continue;
7565
+ const text2 = shownText(original, scene);
7566
+ const colour = text2.layer === "top" ? PALETTE.topSilk : PALETTE.bottomSilk;
7567
+ ctx.strokeStyle = colour;
7568
+ ctx.fillStyle = colour;
7569
+ ctx.lineWidth = silkTextLineWidth(text2.height);
7570
+ for (const line2 of silkTextStrokes(text2)) strokeLine(ctx, line2);
7571
+ if (scene?.selected.has(text2.id) || scene?.hovered === text2.id) ring2(ctx, text2, scene.selected.has(text2.id), px);
7572
+ }
7573
+ }
7574
+ function strokeLine(ctx, line2) {
7575
+ const first = line2[0];
7576
+ if (!first || line2.length < 2) return;
7577
+ ctx.beginPath();
7578
+ if (line2.every((p) => p.x === first.x && p.y === first.y)) {
7579
+ ctx.arc(first.x, first.y, ctx.lineWidth / 2, 0, 2 * Math.PI);
7580
+ ctx.fill();
7581
+ return;
7582
+ }
7583
+ line2.forEach((p, i) => i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y));
7584
+ ctx.stroke();
7585
+ }
7586
+ function ring2(ctx, text2, selected, px) {
7587
+ const box3 = silkTextBox(text2);
7588
+ const gap = RING_GAP_PX * px;
7589
+ ctx.save();
7590
+ ctx.strokeStyle = PALETTE.selection;
7591
+ ctx.globalAlpha = selected ? 1 : HOVER_ALPHA;
7592
+ ctx.lineWidth = RING_PX2 * px;
7593
+ const [left, right, bottom2, top] = [box3.minX - gap, box3.maxX + gap, box3.minY - gap, box3.maxY + gap];
7594
+ ctx.beginPath();
7595
+ ctx.moveTo(left, bottom2);
7596
+ ctx.lineTo(right, bottom2);
7597
+ ctx.lineTo(right, top);
7598
+ ctx.lineTo(left, top);
7599
+ ctx.closePath();
7600
+ ctx.stroke();
7601
+ ctx.restore();
7602
+ }
7603
+
7604
+ // src/engine/graphic-place.ts
7605
+ import earcut from "earcut";
7606
+
7607
+ // src/engine/pour/clip.ts
7608
+ var import_clipper_lib = __toESM(require_clipper(), 1);
7609
+ var UNITS_PER_MM = 1e3;
7610
+ var toUnits = (mm) => Math.round(mm * UNITS_PER_MM);
7611
+ var toPath = (points) => points.map((p) => ({ X: toUnits(p.x), Y: toUnits(p.y) }));
7612
+ var toPoints = (path2) => path2.map((p) => ({ x: p.X / UNITS_PER_MM, y: p.Y / UNITS_PER_MM }));
7613
+ function clipper(subject, clip) {
7614
+ const engine = new import_clipper_lib.default.Clipper();
7615
+ engine.StrictlySimple = true;
7616
+ engine.AddPaths(subject.filter((path2) => path2.length >= 3), import_clipper_lib.default.PolyType.ptSubject, true);
7617
+ engine.AddPaths(clip.filter((path2) => path2.length >= 3), import_clipper_lib.default.PolyType.ptClip, true);
7618
+ return engine;
7619
+ }
7620
+ function regions(paths) {
7621
+ const tree = new import_clipper_lib.default.PolyTree();
7622
+ const fill = import_clipper_lib.default.PolyFillType.pftNonZero;
7623
+ clipper(paths, []).Execute(import_clipper_lib.default.ClipType.ctUnion, tree, fill, fill);
7624
+ return import_clipper_lib.default.JS.PolyTreeToExPolygons(tree).map((piece) => ({ outer: piece.outer, holes: piece.holes }));
7625
+ }
7626
+ var pathArea = (path2) => import_clipper_lib.default.Clipper.Area(path2);
7627
+
7628
+ // src/engine/graphic-place.ts
7629
+ function graphicBox(graphic) {
7630
+ const box3 = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
7631
+ const grow = (p, half) => {
7632
+ box3.minX = Math.min(box3.minX, p.x - half);
7633
+ box3.minY = Math.min(box3.minY, p.y - half);
7634
+ box3.maxX = Math.max(box3.maxX, p.x + half);
7635
+ box3.maxY = Math.max(box3.maxY, p.y + half);
7636
+ };
7637
+ for (const area2 of graphic.areas) for (const p of area2.outer) grow(p, 0);
7638
+ for (const line2 of graphic.lines) for (const p of line2.points) grow(p, line2.width / 2);
7639
+ return Number.isFinite(box3.minX) ? box3 : { minX: graphic.x, minY: graphic.y, maxX: graphic.x, maxY: graphic.y };
7640
+ }
7641
+
7642
+ // studio/src/pcb/graphic-draw.ts
7643
+ var RING_GAP_PX2 = 3;
7644
+ var RING_PX3 = 1.5;
7645
+ var HOVER_ALPHA2 = 0.5;
7646
+ var MASK_ALPHA = 0.35;
7647
+ var INACTIVE_COPPER_ALPHA2 = 0.4;
7648
+ var COPPER_COLOURS = { top: PALETTE.topCopper, bottom: PALETTE.bottomCopper, inner1: PALETTE.inner1Copper, inner2: PALETTE.inner2Copper };
7649
+ var bottom = (graphic) => graphic.layer.startsWith("bottom");
7650
+ var isMask = (graphic) => graphic.layer.endsWith("mask");
7651
+ var isCopper = (graphic) => COPPER_COLOURS[graphic.layer] !== void 0;
7652
+ function graphicShown(layers, graphic) {
7653
+ if (graphic.layer === "inner1" || graphic.layer === "inner2") return true;
7654
+ if (isMask(graphic) || isCopper(graphic)) return layers[bottom(graphic) ? "bottom" : "top"];
7655
+ return layers[bottom(graphic) ? "bottomSilk" : "topSilk"];
7656
+ }
7657
+ var colourOf = (graphic) => COPPER_COLOURS[graphic.layer] ?? (isMask(graphic) ? bottom(graphic) ? PALETTE.bottomCopper : PALETTE.topCopper : bottom(graphic) ? PALETTE.bottomSilk : PALETTE.topSilk);
7658
+ function shownGraphic(graphic, scene) {
7659
+ const moving = scene?.moving;
7660
+ if (!moving || moving.id !== graphic.id) return graphic;
7661
+ const by = (p) => ({ x: p.x + moving.by.x, y: p.y + moving.by.y });
7662
+ return {
7663
+ ...graphic,
7664
+ x: graphic.x + moving.by.x,
7665
+ y: graphic.y + moving.by.y,
7666
+ areas: graphic.areas.map((area2) => ({ outer: area2.outer.map(by), holes: area2.holes.map((hole) => hole.map(by)) })),
7667
+ lines: graphic.lines.map((line2) => ({ ...line2, points: line2.points.map(by) }))
7668
+ };
7669
+ }
7670
+ function ringPath2(ctx, ring4) {
7671
+ ring4.forEach((p, i) => i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y));
7672
+ ctx.closePath();
7673
+ }
7674
+ function paint(ctx, graphic) {
7675
+ ctx.fillStyle = colourOf(graphic);
7676
+ ctx.strokeStyle = colourOf(graphic);
7677
+ ctx.lineCap = "round";
7678
+ ctx.lineJoin = "round";
7679
+ if (graphic.areas.length > 0) {
7680
+ ctx.beginPath();
7681
+ for (const area2 of graphic.areas) for (const ring4 of [area2.outer, ...area2.holes]) ringPath2(ctx, ring4);
7682
+ ctx.fill("evenodd");
7683
+ }
7684
+ for (const line2 of graphic.lines) {
7685
+ const first = line2.points[0];
7686
+ if (!first) continue;
7687
+ ctx.lineWidth = line2.width;
7688
+ ctx.beginPath();
7689
+ if (line2.points.length === 1) {
7690
+ ctx.arc(first.x, first.y, line2.width / 2, 0, 2 * Math.PI);
7691
+ ctx.fill();
7692
+ continue;
7693
+ }
7694
+ line2.points.forEach((p, i) => i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y));
7695
+ ctx.stroke();
7696
+ }
7697
+ }
7698
+ function ring3(ctx, graphic, selected, px) {
7699
+ const box3 = graphicBox(graphic);
7700
+ const gap = RING_GAP_PX2 * px;
7701
+ ctx.save();
7702
+ ctx.strokeStyle = PALETTE.selection;
7703
+ ctx.globalAlpha = selected ? 1 : HOVER_ALPHA2;
7704
+ ctx.lineWidth = RING_PX3 * px;
7705
+ ctx.beginPath();
7706
+ ringPath2(ctx, [
7707
+ { x: box3.minX - gap, y: box3.minY - gap },
7708
+ { x: box3.maxX + gap, y: box3.minY - gap },
7709
+ { x: box3.maxX + gap, y: box3.maxY + gap },
7710
+ { x: box3.minX - gap, y: box3.maxY + gap }
7711
+ ]);
7712
+ ctx.stroke();
7713
+ ctx.restore();
7714
+ }
7715
+ function drawGraphics(ctx, graphics, layers, scene, px, activeLayer = "top") {
7716
+ for (const original of graphics) {
7717
+ if (!graphicShown(layers, original)) continue;
7718
+ const graphic = shownGraphic(original, scene);
7719
+ ctx.save();
7720
+ if (isMask(graphic)) ctx.globalAlpha = MASK_ALPHA;
7721
+ if (isCopper(graphic) && graphic.layer !== activeLayer) ctx.globalAlpha = INACTIVE_COPPER_ALPHA2;
7722
+ paint(ctx, graphic);
7723
+ ctx.restore();
7724
+ if (scene?.selected.has(graphic.id) || scene?.hovered === graphic.id) ring3(ctx, graphic, scene.selected.has(graphic.id), px);
7725
+ }
7726
+ }
7727
+
7502
7728
  // src/engine/schematic-geometry.ts
7503
7729
  var tidy3 = (value) => clean(value) + 0;
7504
7730
  var turnsOf = (rotation) => Math.round((rotation % 360 + 360) % 360 / 90) % 4;
@@ -7567,11 +7793,11 @@ function drawPcb(ctx, layout, view, options) {
7567
7793
  const px = 1 / camera.scale;
7568
7794
  const hair = devicePixelIn(px, options.ratio);
7569
7795
  const shiftOf = (part) => options.moving?.components.includes(part.component) ? options.moving.by : NO_SHIFT2;
7570
- const each = (paint) => {
7796
+ const each = (paint2) => {
7571
7797
  for (const part of layout.parts) {
7572
7798
  framed(ctx, shiftOf(part).x, shiftOf(part).y, 0, () => {
7573
7799
  ctx.globalAlpha = alphaOf(part);
7574
- paint(part);
7800
+ paint2(part);
7575
7801
  });
7576
7802
  }
7577
7803
  ctx.globalAlpha = 1;
@@ -7591,6 +7817,8 @@ function drawPcb(ctx, layout, view, options) {
7591
7817
  each((part) => {
7592
7818
  if (shownOn(layers, part, "Silk")) drawPolylines(ctx, part.silkscreen, part.side === "top" ? PALETTE.topSilk : PALETTE.bottomSilk, Math.max(SILK_WIDTH_MM, hair), false);
7593
7819
  });
7820
+ drawGraphics(ctx, layout.graphics ?? [], layers, options.silkTexts, px, options.copper?.activeLayer);
7821
+ drawSilkTexts(ctx, layout.silkTexts ?? [], layers, options.silkTexts, px);
7594
7822
  if (layers.courtyard) drawCourtyards(ctx, each, px, hair);
7595
7823
  each((part) => {
7596
7824
  if (shownOn(layers, part, "Assembly")) drawPolylines(ctx, part.fabrication, assemblyColor(part), hair, false);
@@ -7642,11 +7870,11 @@ function roundRect(ctx, w, h, r) {
7642
7870
  ctx.closePath();
7643
7871
  }
7644
7872
  var stadium = (ctx, w, h) => roundRect(ctx, w, h, Math.min(w, h) / 2);
7645
- function drawBoard(ctx, layout, paint) {
7873
+ function drawBoard(ctx, layout, paint2) {
7646
7874
  const outline2 = layout.board?.outline;
7647
7875
  if (!outline2 || outline2.length < 3) return;
7648
7876
  polygon2(ctx, outline2);
7649
- paint();
7877
+ paint2();
7650
7878
  }
7651
7879
  function drawKeepouts(ctx, layout, px, hair) {
7652
7880
  const keepouts = layout.board?.keepouts ?? [];
@@ -7952,7 +8180,7 @@ function drawingBox(drawing) {
7952
8180
  function drawingExtents(layout) {
7953
8181
  const boxes = [...sheetBoxes(layout).map((part) => part.box), ...sheetTexts(layout).map((text2) => text2.box)];
7954
8182
  boxes.push(...layout.labels.map(labelHitBox), ...layout.drawings.map(drawingBox));
7955
- const points = [...layout.wires.flatMap((wire) => wire.points), ...layout.junctions];
8183
+ const points = [...layout.wires.flatMap((wire2) => wire2.points), ...layout.junctions];
7956
8184
  const pointBox = pointBounds(points);
7957
8185
  if (pointBox) boxes.push(pointBox);
7958
8186
  return unionBoxes(boxes);
@@ -8031,18 +8259,18 @@ function pcbFrame(design, parts) {
8031
8259
  }
8032
8260
  function schematicFrame(design, page, parts) {
8033
8261
  const pages = pageNames(design);
8034
- const shown = page ?? pages[0] ?? "Main";
8035
- if (!pages.includes(shown)) throw new Error(`No schematic page "${shown}"; the pages are ${pages.map((name) => `"${name}"`).join(", ")}`);
8036
- const onPage = designOnPage(design, shown);
8262
+ const shown2 = page ?? pages[0] ?? "Main";
8263
+ if (!pages.includes(shown2)) throw new Error(`No schematic page "${shown2}"; the pages are ${pages.map((name) => `"${name}"`).join(", ")}`);
8264
+ const onPage = designOnPage(design, shown2);
8037
8265
  const layout = onPage.schematic;
8038
- const title = `Schematic page "${shown}"`;
8266
+ const title = `Schematic page "${shown2}"`;
8039
8267
  if (parts && parts.length > 0) {
8040
8268
  const boxes = new Map(sheetBoxes(layout).map((part) => [part.name, part.box]));
8041
- return { box: grown2(partBoxes(parts, boxes, `on page "${shown}"`), PART_MARGIN, MIN_PART_MARGIN), what: `${title}, around ${parts.join(", ")}`, page: shown, design: onPage };
8269
+ return { box: grown2(partBoxes(parts, boxes, `on page "${shown2}"`), PART_MARGIN, MIN_PART_MARGIN), what: `${title}, around ${parts.join(", ")}`, page: shown2, design: onPage };
8042
8270
  }
8043
8271
  const box3 = drawingExtents(layout);
8044
8272
  if (!box3) throw new Error(`${title} is empty`);
8045
- return { box: grown2(box3, WHOLE_MARGIN, 0), what: title, page: shown, design: onPage };
8273
+ return { box: grown2(box3, WHOLE_MARGIN, 0), what: title, page: shown2, design: onPage };
8046
8274
  }
8047
8275
  function frameFor(design, request) {
8048
8276
  if (request.view === "pcb") {
@@ -8138,18 +8366,18 @@ function parseFootprint(text2) {
8138
8366
  const [head = "", ...segments] = text2.trim().toLowerCase().split("_");
8139
8367
  const match = HEAD.exec(head);
8140
8368
  if (!match || head === "") return void 0;
8141
- const [, kind = "", code = "", cross2, suffix = ""] = match;
8369
+ const [, kind = "", code = "", cross3, suffix = ""] = match;
8142
8370
  const variant = VARIANT.test(segments[0] ?? "") ? segments[0] : void 0;
8143
8371
  const rest = variant === void 0 ? segments : segments.slice(1);
8144
- const sizes = rest.filter((segment) => PAIR.test(segment));
8372
+ const sizes = rest.filter((segment2) => PAIR.test(segment2));
8145
8373
  if (sizes.length > 1) return void 0;
8146
- const fields = parseParams(rest.filter((segment) => !PAIR.test(segment)));
8374
+ const fields = parseParams(rest.filter((segment2) => !PAIR.test(segment2)));
8147
8375
  if (!fields) return void 0;
8148
8376
  const size = sizes[0] === void 0 ? void 0 : pair(sizes[0]);
8149
8377
  return {
8150
8378
  kind,
8151
8379
  code,
8152
- ...cross2 === void 0 ? {} : { cross: cross2 },
8380
+ ...cross3 === void 0 ? {} : { cross: cross3 },
8153
8381
  ...suffix === "" ? {} : { suffix },
8154
8382
  ...variant === void 0 ? {} : { variant },
8155
8383
  ...size === void 0 ? {} : { size },
@@ -8164,8 +8392,8 @@ function pair(text2) {
8164
8392
  function parseParams(segments) {
8165
8393
  const params = {};
8166
8394
  const pairs = {};
8167
- for (const segment of segments) {
8168
- const match = PARAM.exec(segment);
8395
+ for (const segment2 of segments) {
8396
+ const match = PARAM.exec(segment2);
8169
8397
  if (!match) return void 0;
8170
8398
  const key = match[1] ?? "";
8171
8399
  const value = match[2] ?? "";
@@ -8182,6 +8410,182 @@ function parseParams(segments) {
8182
8410
  return { params, pairs };
8183
8411
  }
8184
8412
 
8413
+ // src/engine/solid/heights-smd.ts
8414
+ var row = (packages, height, source, matches) => ({ packages, height, source, matches });
8415
+ var bare = (p) => p.variant === void 0 && p.cross === void 0 && p.size === void 0;
8416
+ var named = (kind, code) => (p) => p.kind === kind && p.code === code && bare(p);
8417
+ var anyOf = (...tests) => (p) => tests.some((test) => test(p));
8418
+ var CHIPS = [
8419
+ row("chip 01005", 0.2, "makers' 01005 chip resistor and capacitor series: about 0.2 mm thick", (p) => p.kind === "" && p.code === "01005" && p.variant === void 0),
8420
+ row("chip 2220", 3.2, "makers' chip capacitor series: the thickest part commonly made in this size", (p) => p.kind === "" && p.code === "2220" && p.variant === void 0)
8421
+ ];
8422
+ var flatLead = (name, code, height) => row(name, height, `makers' ${name} drawings: a flat-lead body up to about ${height} mm`, (p) => p.kind === "sod" && p.code === code && p.suffix === void 0 && bare(p));
8423
+ var DIODES = [
8424
+ flatLead("SOD-523", "523", 0.7),
8425
+ flatLead("SOD-923", "923", 0.4),
8426
+ row("SOD-123F", 1.1, "makers' SOD-123F drawings: a flat-lead body up to about 1.1 mm", (p) => p.kind === "sod" && p.code === "123" && p.suffix === "f" && bare(p)),
8427
+ flatLead("SOD-128", "128", 1.1)
8428
+ ];
8429
+ var melf = (name, height, keys) => row(name, height, `a MELF cylinder lies on the board: as high as the body is wide, the largest diameter of the footprint outline (${height} mm), which is written from general knowledge of makers' drawings`, (p) => bare(p) && keys.includes(`${p.kind}${p.code}${p.suffix ?? ""}`));
8430
+ var MELFS = [melf("MiniMELF (SOD-80, DO-213AA)", 1.6, ["minimelf", "sod80", "do213aa"]), melf("MELF (DO-213AB)", 2.6, ["melf", "do213ab"])];
8431
+ var SMALL_SOT = "makers' small SOT drawings";
8432
+ var SMALL_SOTS = [
8433
+ row("SOT-323, SOT-353, SOT-363 (SC-70)", 1.1, `${SMALL_SOT} (SC-70 family): A max about 1.1 mm`, anyOf((p) => p.kind === "sot" && ["323", "353", "363"].includes(p.code) && bare(p), (p) => p.kind === "sc" && p.code === "70")),
8434
+ row("SOT-523, SC-89", 0.8, `${SMALL_SOT}: A max about 0.8 mm`, named("sot", "523")),
8435
+ row("SOT-563", 0.6, `${SMALL_SOT}: A max about 0.6 mm`, named("sot", "563")),
8436
+ row("SOT-723", 0.55, `${SMALL_SOT}: A max about 0.55 mm`, named("sot", "723")),
8437
+ row("SOT-143", 1.1, `${SMALL_SOT}: A max about 1.1 mm`, named("sot", "143")),
8438
+ row("SOT-23-8", 1.45, "typical, as the five and six lead SOT-23 packages in this table (JEDEC MO-178 outline), not read for eight leads", (p) => p.kind === "sot" && p.code === "23" && p.variant === "8")
8439
+ ];
8440
+ var SMALL_ICS = [
8441
+ row("MSOP (3 mm)", 1.1, "JEDEC MO-187 (MSOP), A max about 1.1 mm, typical", (p) => p.kind === "msop"),
8442
+ row("QSOP (150 mil)", 1.75, "JEDEC MO-137 (QSOP), A max about 1.75 mm, typical", (p) => p.kind === "qsop"),
8443
+ row("surface-mount DIP", 4.5, "makers' drawings of the gull-wing option of a 300 mil DIP: about 4.5 mm above the board, typical", (p) => p.kind === "smdip"),
8444
+ row("PLCC (MS-018)", 4.57, "JEDEC MS-018 (square PLCC), A max about 4.57 mm, typical", (p) => p.kind === "plcc" && p.code !== "32"),
8445
+ row("PLCC-32 (MS-016)", 3.55, "JEDEC MS-016 (rectangular PLCC-32), A max about 3.55 mm, typical", (p) => p.kind === "plcc" && p.code === "32")
8446
+ ];
8447
+ var POWER = "makers' drawings, A max about";
8448
+ var POWERS = [
8449
+ row("DPAK (TO-252)", 2.4, `${POWER} 2.4 mm for DPAK (TO-252), typical`, anyOf((p) => p.kind === "dpak" && p.code === "", (p) => p.kind === "to" && p.code === "252")),
8450
+ row("D2PAK (TO-263), 3, 5 or 7 leads", 4.8, `${POWER} 4.8 mm for D2PAK (TO-263), typical`, anyOf((p) => p.kind === "d" && p.code === "2" && p.suffix === "pak", (p) => p.kind === "to" && p.code === "263"))
8451
+ ];
8452
+ var CASE_NAME = "EIA case name: the last two digits of the case code are its height in tenths of a mm; the maker's tolerance was not read";
8453
+ var tantalum = (letter, size, height) => row(`tantalum case ${letter.toUpperCase()}`, height, `${CASE_NAME} (${height} mm)`, (p) => p.kind === "tant" && (size === void 0 ? p.params[letter] === true : p.code === size));
8454
+ var TANTALUMS = [
8455
+ tantalum("a", void 0, 1.8),
8456
+ tantalum("b", void 0, 2.1),
8457
+ tantalum("c", void 0, 2.8),
8458
+ tantalum("d", void 0, 3.1),
8459
+ tantalum("e", void 0, 4.3),
8460
+ tantalum("a", "3216", 1.8),
8461
+ tantalum("b", "3528", 2.1),
8462
+ tantalum("c", "6032", 2.8),
8463
+ tantalum("d", "7343", 3.1)
8464
+ ];
8465
+ var array = (name, height) => row(`chip resistor array ${name}`, height, `makers' chip resistor array series: about ${height} mm thick, typical`, (p) => p.kind === "array" && `${p.code}x${p.cross}` === name);
8466
+ var ARRAYS = [array("4x0603", 0.5), array("4x0402", 0.35), array("2x0402", 0.35)];
8467
+ var CANS = [
8468
+ {
8469
+ packages: "surface-mount aluminium can",
8470
+ height: 0,
8471
+ source: "the can height written in the footprint name (smdcan8x10.2 is 10.2 mm), the whole part above the board",
8472
+ heightOf: (p) => Number(p.cross),
8473
+ matches: (p) => p.kind === "smdcan" && p.cross !== void 0
8474
+ }
8475
+ ];
8476
+ var xtal = (key, height) => row(`crystal ${key}`, height, `makers' surface-mount crystal and oscillator drawings of this size: about ${height} mm, typical`, (p) => `${p.kind}${p.code}${p.variant === void 0 ? "" : `_${p.variant}`}` === key && p.suffix === void 0);
8477
+ var CRYSTALS = [
8478
+ xtal("xtal2016", 0.5),
8479
+ xtal("xtal2520", 0.6),
8480
+ xtal("xtal3225", 0.8),
8481
+ xtal("xtal5032", 1.2),
8482
+ xtal("xtal5032_2", 1.2),
8483
+ xtal("xtal3215", 0.9),
8484
+ xtal("xtal7050", 1.4),
8485
+ row("HC-49/US SMD crystal", 4.5, "crystal makers' HC-49/US SMD drawings: a can about 3.5 mm on a seat about 1 mm, typical", (p) => p.kind === "hc" && p.code === "49" && p.suffix === "smd")
8486
+ ];
8487
+ var led2 = (key, height) => row(`PLCC LED ${key}`, height, `LED makers' PLCC drawings of this size: about ${height} mm, typical`, (p) => p.kind === "led" && `${p.code}${p.variant === void 0 ? "" : `_${p.variant}`}` === key);
8488
+ var LEDS = [led2("3528", 1.9), led2("5050", 1.6), led2("5050_6", 1.6)];
8489
+ var SMD_ROWS = [...CHIPS, ...DIODES, ...MELFS, ...SMALL_SOTS, ...SMALL_ICS, ...POWERS, ...TANTALUMS, ...ARRAYS, ...CANS, ...CRYSTALS, ...LEDS];
8490
+
8491
+ // src/engine/solid/heights-through.ts
8492
+ var AXIAL_GAP = 0.3;
8493
+ var AXIAL_DIAMETERS = [
8494
+ { upTo: 3.7, diameter: 1.8 },
8495
+ { upTo: 6.6, diameter: 2.5 },
8496
+ { upTo: 9.1, diameter: 3.5 },
8497
+ { upTo: 12.1, diameter: 4.5 },
8498
+ { upTo: Infinity, diameter: 5.5 }
8499
+ ];
8500
+ function axialDiameter(parsed2) {
8501
+ const given = parsed2.params["d"];
8502
+ if (typeof given === "number" && given > 0) return given;
8503
+ const length2 = Number(parsed2.code);
8504
+ return (AXIAL_DIAMETERS.find((row3) => length2 <= row3.upTo) ?? AXIAL_DIAMETERS[AXIAL_DIAMETERS.length - 1]).diameter;
8505
+ }
8506
+ var AXIAL_SOURCE = `makers' drawings of axial resistors and diodes lying on the board: the body's diameter (from the string, or by body length) and about ${AXIAL_GAP} mm of gap under it`;
8507
+ var DIODE_SOURCE = (name, diameter) => `makers' ${name} drawings: maximum body diameter ${diameter} mm and about ${AXIAL_GAP} mm of gap under it`;
8508
+ var diode2 = (name, code, suffix, diameter) => ({
8509
+ packages: name,
8510
+ height: diameter + AXIAL_GAP,
8511
+ source: DIODE_SOURCE(name, diameter),
8512
+ matches: (p) => p.kind === "do" && p.code === code && p.suffix === suffix && p.variant === void 0
8513
+ });
8514
+ var screw = (packages, height, pitches) => ({
8515
+ packages,
8516
+ height,
8517
+ source: `makers' PCB screw terminal block drawings: about ${height} mm above the board at these pitches`,
8518
+ matches: (p) => p.kind === "screw" && pitches.includes(typeof p.params["p"] === "number" ? p.params["p"] : DEFAULT_SCREW_PITCH)
8519
+ });
8520
+ var DEFAULT_SCREW_PITCH = 5.08;
8521
+ var RADIAL_CANS = [[4, 7], [5, 11], [6.3, 11], [8, 11.5], [10, 16], [12.5, 20], [16, 25], [18, 35.5]];
8522
+ var RADIAL_SOURCE = "makers' drawings of general-purpose radial aluminium electrolytic series: the common can length for the diameter";
8523
+ var RADIAL_NEAREST_SOURCE = "makers' drawings of general-purpose radial aluminium electrolytic series: this diameter is not listed, so the common can length of the nearest listed diameter";
8524
+ var radialDiameter = (p) => Number(p.code);
8525
+ var isRadial = (p) => p.kind === "radial" && Number.isFinite(radialDiameter(p)) && radialDiameter(p) > 0;
8526
+ var listed = (diameter) => RADIAL_CANS.some(([d]) => d === diameter);
8527
+ function nearestCan(diameter) {
8528
+ const best = RADIAL_CANS.reduce((a, b) => Math.abs(b[0] - diameter) < Math.abs(a[0] - diameter) ? b : a);
8529
+ return best[1];
8530
+ }
8531
+ var FINE_HEADER_SOURCE = (pitch, height) => `makers' ${pitch} mm pitch pin header drawings: about ${height} mm overall above the board`;
8532
+ var finePitch = (p) => {
8533
+ const pitch = p.params["p"];
8534
+ return p.kind === "pinrow" && typeof pitch === "number" && pitch < 2.54 ? pitch : void 0;
8535
+ };
8536
+ var FINE_HEADER_LIMIT = 1.5;
8537
+ var THROUGH_HOLE_ROWS = [
8538
+ {
8539
+ packages: "radial can, a listed diameter",
8540
+ height: 0,
8541
+ heightOf: (p) => nearestCan(radialDiameter(p)),
8542
+ source: RADIAL_SOURCE,
8543
+ matches: (p) => isRadial(p) && listed(radialDiameter(p))
8544
+ },
8545
+ {
8546
+ packages: "radial can, any other diameter",
8547
+ height: 0,
8548
+ heightOf: (p) => nearestCan(radialDiameter(p)),
8549
+ source: RADIAL_NEAREST_SOURCE,
8550
+ matches: (p) => isRadial(p) && !listed(radialDiameter(p))
8551
+ },
8552
+ { packages: "pin header, 1.27 mm pitch", height: 4.6, source: FINE_HEADER_SOURCE("1.27", 4.6), matches: (p) => (finePitch(p) ?? Infinity) <= FINE_HEADER_LIMIT },
8553
+ { packages: "pin header, 2 mm pitch", height: 6, source: FINE_HEADER_SOURCE("2", 6), matches: (p) => (finePitch(p) ?? 0) > FINE_HEADER_LIMIT },
8554
+ {
8555
+ packages: "axial resistor or diode",
8556
+ height: 0,
8557
+ heightOf: (p) => axialDiameter(p) + AXIAL_GAP,
8558
+ source: AXIAL_SOURCE,
8559
+ matches: (p) => p.kind === "axial" && p.code !== ""
8560
+ },
8561
+ diode2("DO-35", "35", void 0, 2),
8562
+ diode2("DO-41", "41", void 0, 2.7),
8563
+ diode2("DO-15", "15", void 0, 3.6),
8564
+ diode2("DO-201AD", "201", "ad", 5.3),
8565
+ { packages: "3 mm round LED", height: 5.5, source: "makers' 3 mm (T-1) round LED drawings: flange and lens seated on the board, about 5.5 mm", matches: (p) => p.kind === "led" && p.suffix === "mm" && p.code === "3" },
8566
+ { packages: "5 mm round LED", height: 8.7, source: "makers' 5 mm (T-1 3/4) round LED drawings: flange and lens seated on the board, about 8.7 mm", matches: (p) => p.kind === "led" && p.suffix === "mm" && p.code === "5" },
8567
+ screw("screw terminal block, 5 and 5.08 mm pitch", 10, [5, 5.08]),
8568
+ screw("screw terminal block, 3.5 and 3.81 mm pitch", 8.5, [3.5, 3.81]),
8569
+ { packages: "pin socket, 2.54 mm pitch", height: 8.5, source: "makers' drawings of 2.54 mm female headers: the common 8.5 mm height above the board", matches: (p) => p.kind === "socket" },
8570
+ { packages: "TO-247", height: 25.5, source: "makers' TO-247 drawings: about 4.5 mm of lead above the board under about 21 mm of body and tab", matches: (p) => p.kind === "to" && p.code === "247" },
8571
+ { packages: "TO-126", height: 13.3, source: "makers' TO-126 (SOT-32) drawings: about 2.5 mm of lead above the board under about 10.8 mm of plastic body", matches: (p) => p.kind === "to" && p.code === "126" }
8572
+ ];
8573
+
8574
+ // src/engine/solid/heights-uno.ts
8575
+ var row2 = (packages, height, source, matches) => ({ packages, height, source, matches });
8576
+ var isPlain = (p) => p.variant === void 0 && p.suffix === void 0 && p.size === void 0;
8577
+ var INDUCTOR_HEIGHTS = [[4, 2], [5, 2.5], [6, 3], [8, 4], [10, 5], [12, 6]];
8578
+ var inductor2 = (side, height) => row2(`shielded power inductor ${side}x${side}`, height, `makers' shielded power inductor ranges of ${side} \xD7 ${side} mm: about ${height} mm, typical`, (p) => p.kind === "ind" && p.code === String(side) && p.cross === String(side) && isPlain(p));
8579
+ var UNO_ROWS = [
8580
+ row2("USB Type-B receptacle", 11, "makers' right-angle USB Type-B receptacle drawings: a shell about 11 mm high, typical", (p) => p.kind === "usb" && p.params["b"] === true),
8581
+ row2("USB Type-C receptacle, 16 pins", 3.2, "makers' horizontal USB Type-C receptacle drawings: a shell about 3.2 mm high, typical", (p) => p.kind === "usb" && p.params["c"] === 16),
8582
+ row2("DC barrel jack, 5.5 mm", 11, "makers' right-angle barrel jack drawings for a 5.5 mm plug: a body about 11 mm high, typical", (p) => p.kind === "dcjack"),
8583
+ row2("tact switch 6 x 6, through-hole", 4.3, "makers' 6 \xD7 6 mm tact switch drawings with the usual short button: about 4.3 mm, typical", (p) => p.kind === "tact" && p.params["smd"] === void 0),
8584
+ row2("tact switch 6 x 6, surface-mount", 4.3, "makers' 6 \xD7 6 mm surface-mount tact switch drawings with the usual short button: about 4.3 mm, typical", (p) => p.kind === "tact" && p.params["smd"] === true),
8585
+ row2("ceramic resonator 3.2 x 1.3", 0.9, "makers' 3.2 \xD7 1.3 mm three-terminal ceramic resonator drawings: about 0.9 mm, typical", (p) => p.kind === "resonator" && p.code === "3213"),
8586
+ ...INDUCTOR_HEIGHTS.map(([side, height]) => inductor2(side, height))
8587
+ ];
8588
+
8185
8589
  // src/engine/solid/heights.ts
8186
8590
  var ASSUMED_HEIGHT = 1;
8187
8591
  var CHIP_SOURCE = "EIA/IEC 60384-21 chip capacitor sizes: thickness up to the body width plus its tolerance (resistors are thinner)";
@@ -8191,19 +8595,31 @@ var chip = (code, height) => ({
8191
8595
  source: CHIP_SOURCE,
8192
8596
  matches: (p) => p.kind === "" && p.code === code && p.variant === void 0
8193
8597
  });
8194
- var isHeaderPitch = (p) => p.params["p"] === void 0 || p.params["p"] === 2.54;
8195
- var RADIAL_SOURCE = "makers' drawings of general-purpose radial aluminium electrolytic series: the common can length for the diameter";
8196
- var radial = (diameter, height) => ({
8197
- packages: `radial can ${diameter} mm across`,
8598
+ var BIG_CHIP_CAPACITOR_SOURCE = "makers' chip capacitor series: the thickest part commonly made in this size";
8599
+ var POWER_CHIP_SOURCE = "makers' power chip resistor series: thickness up to 0.7 mm in this size";
8600
+ var chipOf = (code, height, source) => ({
8601
+ packages: `chip ${code}`,
8198
8602
  height,
8199
- source: RADIAL_SOURCE,
8200
- matches: (p) => p.kind === "radial" && p.code === diameter
8603
+ source,
8604
+ matches: (p) => p.kind === "" && p.code === code && p.variant === void 0
8605
+ });
8606
+ var moulded = (name, jedec, height) => ({
8607
+ packages: `${name.toUpperCase()} (DO-214${jedec.toUpperCase()})`,
8608
+ height,
8609
+ source: `makers' ${name.toUpperCase()} (DO-214${jedec.toUpperCase()}) drawings: body thickness up to ${height} mm`,
8610
+ matches: (p) => p.variant === void 0 && (p.kind === name && p.code === "" || p.kind === "do" && p.code === "214" && p.suffix === jedec)
8201
8611
  });
8612
+ var isHeaderPitch = (p) => p.params["p"] === void 0 || p.params["p"] === 2.54;
8202
8613
  var HEIGHT_TABLE = [
8203
8614
  chip("0402", 0.55),
8204
8615
  chip("0603", 0.9),
8205
8616
  chip("0805", 1.45),
8206
8617
  chip("1206", 1.8),
8618
+ chip("0201", 0.33),
8619
+ chipOf("1210", 2.5, BIG_CHIP_CAPACITOR_SOURCE),
8620
+ chipOf("1812", 3.2, BIG_CHIP_CAPACITOR_SOURCE),
8621
+ chipOf("2010", 0.7, POWER_CHIP_SOURCE),
8622
+ chipOf("2512", 0.7, POWER_CHIP_SOURCE),
8207
8623
  {
8208
8624
  packages: "SOIC (narrow)",
8209
8625
  height: 1.75,
@@ -8220,11 +8636,24 @@ var HEIGHT_TABLE = [
8220
8636
  },
8221
8637
  { packages: "SOT-23 (3 leads)", height: 1.12, source: "JEDEC TO-236 AB, A max 1.12 mm", matches: (p) => p.kind === "sot" && p.code === "23" && p.variant === void 0 },
8222
8638
  { packages: "SOT-23-5, SOT-23-6", height: 1.45, source: "JEDEC MO-178, A max 1.45 mm", matches: (p) => p.kind === "sot" && p.code === "23" && (p.variant === "5" || p.variant === "6") },
8639
+ { packages: "SOT-223", height: 1.8, source: "makers' SOT-223 (TO-261AA) drawings, A max 1.8 mm", matches: (p) => p.kind === "sot" && p.code === "223" && p.variant === void 0 },
8640
+ { packages: "SOT-89", height: 1.6, source: "makers' SOT-89 (TO-243AA) drawings, A max about 1.6 mm", matches: (p) => p.kind === "sot" && p.code === "89" && p.variant === void 0 },
8641
+ { packages: "SOP (208 mil)", height: 2.2, source: "makers' 208 mil SOP drawings, A max about 2.2 mm", matches: (p) => p.kind === "sop" },
8642
+ { packages: "SSOP", height: 2, source: "JEDEC MO-150 (SSOP), A max 2.0 mm", matches: (p) => p.kind === "ssop" },
8643
+ { packages: "TSSOP", height: 1.2, source: "JEDEC MO-153 (TSSOP), A max 1.2 mm", matches: (p) => p.kind === "tssop" },
8644
+ { packages: "ball grid array", height: 1.4, source: "makers' fine-pitch BGA drawings: balls and body together, 1.0 to 1.6 mm", matches: (p) => p.kind === "bga" },
8223
8645
  { packages: "QFN", height: 1, source: "JEDEC MO-220, A max 1.00 mm", matches: (p) => p.kind === "qfn" },
8224
8646
  { packages: "DFN", height: 1, source: "JEDEC MO-229, A max 1.00 mm", matches: (p) => p.kind === "dfn" },
8225
8647
  { packages: "LQFP, QFP", height: 1.6, source: "JEDEC MS-026 (LQFP), A max 1.60 mm", matches: (p) => p.kind === "lqfp" || p.kind === "qfp" },
8226
8648
  { packages: "TQFP", height: 1.2, source: "JEDEC MS-026 (TQFP), A max 1.20 mm", matches: (p) => p.kind === "tqfp" },
8227
- { packages: "SOD-123", height: 1.35, source: "makers' SOD-123 drawings (for example onsemi case 425), A max 1.35 mm", matches: (p) => p.kind === "sod" && p.code === "123" },
8649
+ { packages: "SOD-123", height: 1.35, source: "makers' SOD-123 drawings (for example onsemi case 425), A max 1.35 mm", matches: (p) => p.kind === "sod" && p.code === "123" && p.suffix === void 0 },
8650
+ { packages: "SOD-323", height: 1.1, source: "makers' SOD-323 drawings, A max about 1.1 mm", matches: (p) => p.kind === "sod" && p.code === "323" && (p.suffix === void 0 || p.suffix === "f") },
8651
+ moulded("sma", "ac", 2.4),
8652
+ moulded("smb", "aa", 2.4),
8653
+ moulded("smc", "ab", 2.7),
8654
+ { packages: "plastic DIP", height: 5.1, source: "makers' plastic DIP drawings: the body seated about 0.5 mm off the board, up to 5.1 mm high", matches: (p) => p.kind === "dip" },
8655
+ { packages: "TO-220, upright", height: 20.5, source: "makers' TO-220AB drawings, seated against the leads' shoulders: about 4.5 mm of lead above the board under about 16 mm of body and tab", matches: (p) => p.kind === "to" && p.code === "220" },
8656
+ { packages: "TO-92", height: 5.2, source: "makers' TO-92 drawings: the body up to 5.2 mm above the board", matches: (p) => p.kind === "to" && p.code === "92" },
8228
8657
  {
8229
8658
  packages: "pin header, 2.54 mm pitch",
8230
8659
  height: 8.5,
@@ -8233,14 +8662,9 @@ var HEIGHT_TABLE = [
8233
8662
  },
8234
8663
  { packages: "HC-49/U crystal", height: 13.46, source: "crystal makers' HC-49/U drawings, height max 13.46 mm", matches: (p) => p.kind === "hc" && p.code === "49" && p.suffix === void 0 },
8235
8664
  { packages: "HC-49/S crystal", height: 3.5, source: "crystal makers' HC-49/S (HC-49/US) drawings, height max 3.5 mm", matches: (p) => p.kind === "hc" && p.code === "49" && p.suffix === "s" },
8236
- radial("4", 7),
8237
- radial("5", 11),
8238
- radial("6.3", 11),
8239
- radial("8", 11.5),
8240
- radial("10", 16),
8241
- radial("12.5", 20),
8242
- radial("16", 25),
8243
- radial("18", 35.5)
8665
+ ...THROUGH_HOLE_ROWS,
8666
+ ...SMD_ROWS,
8667
+ ...UNO_ROWS
8244
8668
  ];
8245
8669
  function givenHeight(props) {
8246
8670
  const height = parseLength(props["height"]);
@@ -8250,9 +8674,10 @@ function partHeight(part) {
8250
8674
  const given = givenHeight(part.props);
8251
8675
  if (given !== void 0) return { height: given, source: "given", state: "given", assumed: false };
8252
8676
  const parsed2 = part.footprint === void 0 || part.footprint.includes("/") ? void 0 : parseFootprint(part.footprint);
8253
- const row = parsed2 === void 0 ? void 0 : HEIGHT_TABLE.find((candidate) => candidate.matches(parsed2));
8254
- if (row === void 0) return { height: ASSUMED_HEIGHT, source: "assumed", state: "assumed", assumed: true };
8255
- return row.document === void 0 ? { height: row.height, source: row.source, state: "typical", assumed: false } : { height: row.height, source: row.document, state: "read", assumed: false };
8677
+ const row3 = parsed2 === void 0 ? void 0 : HEIGHT_TABLE.find((candidate) => candidate.matches(parsed2));
8678
+ if (row3 === void 0) return { height: ASSUMED_HEIGHT, source: "assumed", state: "assumed", assumed: true };
8679
+ const height = row3.heightOf?.(parsed2) ?? row3.height;
8680
+ return row3.document === void 0 ? { height, source: row3.source, state: "typical", assumed: false } : { height, source: row3.document, state: "read", assumed: false };
8256
8681
  }
8257
8682
 
8258
8683
  // src/engine/solid/thickness.ts
@@ -8273,8 +8698,8 @@ function doubledArea(points) {
8273
8698
  }
8274
8699
  return sum;
8275
8700
  }
8276
- function arcSweep(segment) {
8277
- const { from, to, centre, ccw } = segment;
8701
+ function arcSweep(segment2) {
8702
+ const { from, to, centre, ccw } = segment2;
8278
8703
  const start = Math.atan2(from.y - centre.y, from.x - centre.x);
8279
8704
  const end = Math.atan2(to.y - centre.y, to.x - centre.x);
8280
8705
  let sweep = ccw ? end - start : start - end;
@@ -8359,8 +8784,8 @@ function partSolid(part, props, footprintText, thickness) {
8359
8784
  const world = local.map((p) => placed(p, part));
8360
8785
  const corners = doubledArea(world) < 0 ? [world[0], world[3], world[2], world[1]] : world;
8361
8786
  const { height, source, state, assumed } = partHeight({ ...footprintText === void 0 ? {} : { footprint: footprintText }, props });
8362
- const [bottom, top] = part.side === "top" ? [thickness, thickness + height] : [-height, 0];
8363
- return { name: part.component, side: part.side, corners, bottom, top, height, source, state, assumed };
8787
+ const [bottom2, top] = part.side === "top" ? [thickness, thickness + height] : [-height, 0];
8788
+ return { name: part.component, side: part.side, corners, bottom: bottom2, top, height, source, state, assumed };
8364
8789
  }
8365
8790
  function solidModel(design) {
8366
8791
  const thickness = boardThickness(design);
@@ -8410,12 +8835,63 @@ function prism(polygon3, z0, z1, colors, material, role, sideColor2) {
8410
8835
  });
8411
8836
  return [cap, ...sides];
8412
8837
  }
8838
+ function facet(loop, outward, color, material, role) {
8839
+ const wound3 = windNormal(loop);
8840
+ const flip = wound3[0] * outward[0] + wound3[1] * outward[1] + wound3[2] * outward[2] < 0;
8841
+ const turned = flip ? [...loop].reverse() : [...loop];
8842
+ return { loops: [turned], normal: flip ? [-wound3[0], -wound3[1], -wound3[2]] : wound3, color, material, role };
8843
+ }
8413
8844
  function hanging(polygon3, z0, z1, color, material, role) {
8414
8845
  if (!(z0 > z1)) return [];
8415
8846
  const end = { loops: [[...polygon3].reverse().map((p) => [p.x, p.y, z1])], normal: [0, 0, -1], color, material, role };
8416
8847
  const sides = prism(polygon3, z1, z0, color, material, role).slice(1);
8417
8848
  return [end, ...sides];
8418
8849
  }
8850
+ function lying(polygon3, x0, x1, colors, material, role) {
8851
+ if (!(x1 > x0) || polygon3.length < 3) return [];
8852
+ const { top, side } = colorsOf(colors);
8853
+ const at2 = (x, p) => [x, p.x, p.y];
8854
+ const far = { loops: [polygon3.map((p) => at2(x1, p))], normal: [1, 0, 0], color: top, material, role };
8855
+ const near = { loops: [[...polygon3].reverse().map((p) => at2(x0, p))], normal: [-1, 0, 0], color: top, material, role };
8856
+ const sides = polygon3.map((p, i) => {
8857
+ const q = polygon3[(i + 1) % polygon3.length];
8858
+ const length2 = Math.hypot(q.x - p.x, q.y - p.y) || 1;
8859
+ return {
8860
+ loops: [[at2(x0, p), at2(x0, q), at2(x1, q), at2(x1, p)]],
8861
+ normal: [0, (q.y - p.y) / length2, -(q.x - p.x) / length2],
8862
+ color: side,
8863
+ material,
8864
+ role
8865
+ };
8866
+ });
8867
+ return [far, near, ...sides];
8868
+ }
8869
+ var cross2 = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
8870
+ var minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
8871
+ function windNormal(loop) {
8872
+ const n = cross2(minus(loop[1], loop[0]), minus(loop[2], loop[1]));
8873
+ const length2 = Math.hypot(n[0], n[1], n[2]) || 1;
8874
+ return [n[0] / length2, n[1] / length2, n[2] / length2];
8875
+ }
8876
+ function lathe(profile, cx, cy, sides, colors, material, role) {
8877
+ if (profile.length < 2 || sides < 3) return [];
8878
+ const { top, side } = colorsOf(colors);
8879
+ const ring4 = (radius, z, i) => {
8880
+ const angle = 2 * Math.PI * i / sides;
8881
+ return [cx + radius * Math.cos(angle), cy + radius * Math.sin(angle), z];
8882
+ };
8883
+ const bands = profile.slice(1).flatMap(([r1, z1], k) => {
8884
+ const [r0, z0] = profile[k];
8885
+ return Array.from({ length: sides }, (_, i) => {
8886
+ const corners = [ring4(r0, z0, i), ring4(r0, z0, i + 1), ring4(r1, z1, i + 1), ring4(r1, z1, i)];
8887
+ const loop = corners.filter((p, j) => j === 0 || Math.hypot(p[0] - corners[j - 1][0], p[1] - corners[j - 1][1]) > 1e-12 || p[2] !== corners[j - 1][2]);
8888
+ return loop.length < 3 ? [] : [{ loops: [loop], normal: windNormal(loop), color: side, material, role }];
8889
+ }).flat();
8890
+ });
8891
+ const [lastR, lastZ] = profile[profile.length - 1];
8892
+ const lid2 = lastR > 0 ? [{ loops: [Array.from({ length: sides }, (_, i) => ring4(lastR, lastZ, i))], normal: [0, 0, 1], color: top, material, role }] : [];
8893
+ return [...lid2, ...bands];
8894
+ }
8419
8895
  var rectPolygon = (r) => [
8420
8896
  { x: r.minX, y: r.minY },
8421
8897
  { x: r.maxX, y: r.minY },
@@ -8461,16 +8937,209 @@ var padsRect = (pads2) => rectOf(pads2.flatMap((pad) => {
8461
8937
  return [{ x: r.minX, y: r.minY }, { x: r.maxX, y: r.maxY }];
8462
8938
  }));
8463
8939
  var LEAD_TAIL = 1.6;
8464
- function leads(input, color = input.look.metal) {
8940
+ function leads(input, color = input.look.metal, half) {
8465
8941
  return input.pads.flatMap((pad) => {
8466
8942
  if (pad.layers !== "through" || pad.drill === void 0) return [];
8467
8943
  const radius = Math.min(pad.drill.width, pad.drill.height) * 0.32;
8468
- const wire = circle3(pad.x, pad.y, radius, 8);
8469
- return hanging(wire, 0, -(input.thickness + LEAD_TAIL), color, "metal", "lead");
8944
+ const wire2 = half ? rectPolygon({ minX: pad.x - half.x, maxX: pad.x + half.x, minY: pad.y - half.y, maxY: pad.y + half.y }) : circle3(pad.x, pad.y, radius, 8);
8945
+ return hanging(wire2, 0, -(input.thickness + LEAD_TAIL), color, "metal", "lead");
8470
8946
  });
8471
8947
  }
8472
8948
  var firstPad = (pads2) => pads2.find((pad) => pad.number === "1") ?? pads2[0];
8473
8949
 
8950
+ // studio/src/look/parts/axial.ts
8951
+ var BODY_SHARE = 0.94;
8952
+ var SIDES = 16;
8953
+ var FOUR_BANDS_FROM = 5;
8954
+ var BAND_COLORS = [[122, 66, 30], [24, 24, 26], [190, 40, 36], [204, 168, 62]];
8955
+ var BAND_SHARE = 0.09;
8956
+ var BAND_MIN = 0.3;
8957
+ var FIRST_BAND_SHARE = 0.17;
8958
+ var LAST_BAND_GAP = 0.8;
8959
+ var CATHODE_SHARE = 0.14;
8960
+ var CATHODE_MIN = 0.4;
8961
+ var CATHODE_INSET_SHARE = 0.06;
8962
+ var CATHODE_MAX_SHARE = 0.4;
8963
+ var WIRE_SHARE = 0.6;
8964
+ var WIRE_MAX = 0.9;
8965
+ var WIRE_BODY_SHARE = 0.9;
8966
+ var fallback = (input) => input.body ?? input.limit;
8967
+ var BAND_SPAN_SHARE = 0.78;
8968
+ var BAND_VISIBLE = 0.15;
8969
+ var bandSpan = (count) => (count - 1) * 1.9 + 1 + (count === 4 ? LAST_BAND_GAP : 0);
8970
+ function resistorBands(x0, length2, mid, axis, radius) {
8971
+ const wanted = length2 >= FOUR_BANDS_FROM ? 4 : 3;
8972
+ const preferred = Math.max(BAND_MIN, length2 * BAND_SHARE);
8973
+ const count = [wanted, 3, 2, 1].filter((n) => n <= wanted).find((n) => Math.min(preferred, length2 * BAND_SPAN_SHARE / bandSpan(n)) >= BAND_VISIBLE);
8974
+ if (count === void 0) return [];
8975
+ const width = Math.min(preferred, length2 * BAND_SPAN_SHARE / bandSpan(count));
8976
+ const step = width * 1.9;
8977
+ const start = x0 + length2 * FIRST_BAND_SHARE;
8978
+ return BAND_COLORS.slice(0, count).flatMap((color, i) => {
8979
+ const from = start + i * step + (i === 3 ? width * LAST_BAND_GAP : 0);
8980
+ return lying(circle3(mid, axis, radius, SIDES), from, from + width, color, "matt", "body");
8981
+ });
8982
+ }
8983
+ function cathodeBand(x1, length2, mid, axis, radius, color) {
8984
+ const width = Math.min(Math.max(CATHODE_MIN, length2 * CATHODE_SHARE), length2 * CATHODE_MAX_SHARE);
8985
+ const end = x1 - length2 * CATHODE_INSET_SHARE;
8986
+ return lying(circle3(mid, axis, radius, SIDES), end - width, end, color, "matt", "cathode");
8987
+ }
8988
+ function wire(input, padX, padY, endX, axis, half) {
8989
+ const [lo, hi] = [Math.min(endX, padX - half), Math.max(endX, padX + half)];
8990
+ const { look } = input;
8991
+ const along = box({ minX: lo, maxX: hi, minY: padY - half, maxY: padY + half }, axis - half, axis + half, look.metal, "metal", "leg");
8992
+ const down = box({ minX: padX - half, maxX: padX + half, minY: padY - half, maxY: padY + half }, 0, axis + half, look.metal, "metal", "leg");
8993
+ return [...along, ...down];
8994
+ }
8995
+ function axialShape(input) {
8996
+ const body = fallback(input);
8997
+ const { look, lookName } = input;
8998
+ const length2 = body.maxX - body.minX;
8999
+ const radius = (body.maxY - body.minY) / 2;
9000
+ const axis = input.height - radius;
9001
+ const mid = (body.minY + body.maxY) / 2;
9002
+ const pieces = [...lying(circle3(mid, axis, radius * BODY_SHARE, SIDES), body.minX, body.maxX, look.body, "matt", "body")];
9003
+ if (lookName === "axialResistor") pieces.push(...resistorBands(body.minX, length2, mid, axis, radius));
9004
+ if (lookName === "axialDiode" || lookName === "axialGlass") pieces.push(...cathodeBand(body.maxX, length2, mid, axis, radius, look.mark));
9005
+ for (const pad of input.pads) {
9006
+ if (pad.layers !== "through") continue;
9007
+ const half = Math.min(WIRE_MAX, (pad.drill?.width ?? 1) * WIRE_SHARE, radius * 2 * WIRE_BODY_SHARE) / 2;
9008
+ pieces.push(...wire(input, pad.x, pad.y, pad.x < (body.minX + body.maxX) / 2 ? body.minX : body.maxX, axis, half));
9009
+ }
9010
+ return [...pieces, ...leads(input)];
9011
+ }
9012
+
9013
+ // studio/src/look/parts/ledth.ts
9014
+ var SIDES2 = 24;
9015
+ var DOME_STEPS = 5;
9016
+ var FLANGE = 1;
9017
+ var FLANGE_SHARE = 0.14;
9018
+ var LENS_MARGIN = 0.4;
9019
+ var LENS_MIN_SHARE = 0.7;
9020
+ var FLANGE_WASH = 0.5;
9021
+ var LEAD_HALF = { x: 0.25, y: 0.25 };
9022
+ var FALLBACK_FLAT = 0.4;
9023
+ var LENS_COLORS = /* @__PURE__ */ new Map([
9024
+ ["red", [[214, 48, 44], [236, 96, 88]]],
9025
+ ["green", [[46, 184, 84], [110, 220, 134]]],
9026
+ ["blue", [[48, 96, 214], [110, 150, 240]]],
9027
+ ["yellow", [[236, 200, 40], [250, 226, 100]]],
9028
+ ["white", [[232, 232, 226], [248, 248, 244]]]
9029
+ ]);
9030
+ function ledLook(base, props) {
9031
+ const named2 = props?.["color"];
9032
+ const pair2 = typeof named2 === "string" ? LENS_COLORS.get(named2.trim().toLowerCase()) : void 0;
9033
+ return pair2 === void 0 ? base : { ...base, body: pair2[0], top: pair2[1] };
9034
+ }
9035
+ var wash = (color) => [0, 1, 2].map((i) => Math.round(color[i] + (255 - color[i]) * FLANGE_WASH));
9036
+ function flangeOutline(radius, cut, sign) {
9037
+ return circle3(0, 0, radius, SIDES2).map((p) => ({ x: sign === 1 ? Math.min(p.x, cut) : Math.max(p.x, cut), y: p.y }));
9038
+ }
9039
+ function ledShape(input) {
9040
+ const body = input.body ?? input.limit;
9041
+ const { look } = input;
9042
+ const [one, two] = [input.pads.find((p) => p.number === "1") ?? input.pads[0], input.pads.find((p) => p.number === "2") ?? input.pads[1]];
9043
+ const sign = one !== void 0 && two !== void 0 && two.x < one.x ? -1 : 1;
9044
+ const radius = (body.maxY - body.minY) / 2;
9045
+ const cut = sign === 1 ? Math.min(body.maxX, radius - FALLBACK_FLAT) : Math.max(body.minX, FALLBACK_FLAT - radius);
9046
+ const h = input.height;
9047
+ const flange = Math.min(FLANGE, h * FLANGE_SHARE);
9048
+ const lens2 = Math.max(radius - LENS_MARGIN, radius * LENS_MIN_SHARE);
9049
+ const axis = h - lens2;
9050
+ const outline2 = flangeOutline(radius, cut, sign);
9051
+ const onFlat = (i) => outline2[i]?.x === cut && outline2[(i + 1) % outline2.length]?.x === cut ? look.mark : void 0;
9052
+ const flangeColor = wash(look.body);
9053
+ const ring4 = prism(outline2, 0, flange, flangeColor, "matt", "body", onFlat).map((piece) => Math.abs(piece.normal[0]) > 0.99 && piece.normal[0] * sign > 0 ? { ...piece, role: "cathode" } : piece);
9054
+ const dome = Array.from({ length: DOME_STEPS }, (_, k) => {
9055
+ const angle = Math.PI / 2 * ((k + 1) / DOME_STEPS);
9056
+ return k === DOME_STEPS - 1 ? [0, h] : [lens2 * Math.cos(angle), axis + lens2 * Math.sin(angle)];
9057
+ });
9058
+ const profile = [[lens2, flange], [lens2, axis], ...dome];
9059
+ const lensPieces = lathe(profile, 0, 0, SIDES2, { top: look.top ?? look.body, side: look.body }, "matt", "body");
9060
+ return [...ring4, ...lensPieces, ...leads(input, look.metal, LEAD_HALF)];
9061
+ }
9062
+
9063
+ // studio/src/look/parts/screw.ts
9064
+ var HEAD_HEIGHT = 0.6;
9065
+ var SLOT_RISE = 0.04;
9066
+ var HEAD_SIDES = 12;
9067
+ var HEAD_SHARE = 0.32;
9068
+ var SLOT_LENGTH = 0.8;
9069
+ var SLOT_HALF = 0.2;
9070
+ var OPENING_SHARE = 0.6;
9071
+ var OPENING_FROM = 0.18;
9072
+ var OPENING_TO = 0.62;
9073
+ var SET_BACK = 0.03;
9074
+ var INSET = 0.15;
9075
+ var PIN_HALF = { x: 0.45, y: 0.45 };
9076
+ var DEFAULT_PITCH = 5.08;
9077
+ var MIN_PITCH = 0.5;
9078
+ function pitchOf2(xs) {
9079
+ const sorted = [...xs].sort((a, b) => a - b);
9080
+ const gaps = sorted.slice(1).map((x, i) => x - sorted[i]).filter((gap) => gap > MIN_PITCH);
9081
+ return gaps.length === 0 ? DEFAULT_PITCH : Math.min(...gaps);
9082
+ }
9083
+ function opening(x, y, width, z0, z1, color) {
9084
+ return facet([[x - width / 2, y, z0], [x + width / 2, y, z0], [x + width / 2, y, z1], [x - width / 2, y, z1]], [0, -1, 0], color, "matt", "body");
9085
+ }
9086
+ function screwShape(input) {
9087
+ const outline2 = clipped(input.body ?? grown3(input.limit, -INSET), input.limit);
9088
+ const { look } = input;
9089
+ const h = input.height;
9090
+ const top = h - Math.min(HEAD_HEIGHT, h * 0.1);
9091
+ const pitch = pitchOf2(input.pads.map((pad) => pad.x));
9092
+ const radius = pitch * HEAD_SHARE;
9093
+ const pieces = [...box({ ...outline2, minY: outline2.minY + SET_BACK }, 0, top, look.body, "matt", "body")];
9094
+ for (const pad of input.pads) {
9095
+ pieces.push(...lathe([[radius, top], [radius, h - SLOT_RISE]], pad.x, pad.y, HEAD_SIDES, look.metal, "metal", "cap"));
9096
+ const slot = { minX: pad.x - radius * SLOT_LENGTH, maxX: pad.x + radius * SLOT_LENGTH, minY: pad.y - SLOT_HALF, maxY: pad.y + SLOT_HALF };
9097
+ pieces.push(...box(slot, h - SLOT_RISE, h, look.mark, "matt", "cap"));
9098
+ pieces.push(opening(pad.x, outline2.minY, pitch * OPENING_SHARE, top * OPENING_FROM, top * OPENING_TO, look.mark));
9099
+ }
9100
+ return [...pieces, ...leads(input, look.metal, PIN_HALF)];
9101
+ }
9102
+
9103
+ // studio/src/look/parts/socket.ts
9104
+ var PITCH = 2.54;
9105
+ var OPENING_HALF = 0.75;
9106
+ var OPENING_DEPTH = 1.2;
9107
+ var DEPTH_SHARE = 0.3;
9108
+ var WALL_LIFT = 6;
9109
+ var lid = (a, b, z, color) => facet([[a[0], a[1], z], [b[0], a[1], z], [b[0], b[1], z], [a[0], b[1], z]], [0, 0, 1], color, "matt", "body");
9110
+ function cell(x, y, h, depth, input) {
9111
+ const o = OPENING_HALF;
9112
+ const { look } = input;
9113
+ const r = clipped({ minX: x - PITCH / 2, maxX: x + PITCH / 2, minY: y - PITCH / 2, maxY: y + PITCH / 2 }, input.limit);
9114
+ const floor = h - depth;
9115
+ const wallColor = look.mark.map((c) => c + WALL_LIFT);
9116
+ const wall = (from, to, outward) => facet([[from[0], from[1], floor], [to[0], to[1], floor], [to[0], to[1], h], [from[0], from[1], h]], outward, wallColor, "matt", "body");
9117
+ return [
9118
+ lid([r.minX, r.minY], [x - o, r.maxY], h, look.body),
9119
+ lid([x + o, r.minY], [r.maxX, r.maxY], h, look.body),
9120
+ lid([x - o, r.minY], [x + o, y - o], h, look.body),
9121
+ lid([x - o, y + o], [x + o, r.maxY], h, look.body),
9122
+ wall([x - o, y - o], [x + o, y - o], [0, 1, 0]),
9123
+ wall([x - o, y + o], [x + o, y + o], [0, -1, 0]),
9124
+ wall([x - o, y - o], [x - o, y + o], [1, 0, 0]),
9125
+ wall([x + o, y - o], [x + o, y + o], [-1, 0, 0]),
9126
+ lid([x - o, y - o], [x + o, y + o], floor, look.mark)
9127
+ ];
9128
+ }
9129
+ function socketShape(input) {
9130
+ const pads2 = padsRect(input.pads);
9131
+ if (pads2 === void 0) return [];
9132
+ const xs = input.pads.map((p) => p.x);
9133
+ const ys = input.pads.map((p) => p.y);
9134
+ const half = PITCH / 2;
9135
+ const base = clipped({ minX: Math.min(...xs) - half, maxX: Math.max(...xs) + half, minY: Math.min(...ys) - half, maxY: Math.max(...ys) + half }, input.limit);
9136
+ const h = input.height;
9137
+ const depth = Math.min(OPENING_DEPTH, h * DEPTH_SHARE);
9138
+ const sides = prism(rectPolygon(base), 0, h, input.look.body, "matt", "body").slice(1);
9139
+ const cells = input.pads.flatMap((pad) => cell(pad.x, pad.y, h, depth, input));
9140
+ return [...sides, ...cells, ...leads(input)];
9141
+ }
9142
+
8474
9143
  // studio/src/look/parts/chip.ts
8475
9144
  var CAP_SHARE = 0.22;
8476
9145
  function chipShape(input) {
@@ -8517,10 +9186,145 @@ function clipPieces(pieces, limit) {
8517
9186
  return pieces.map((piece) => ({ ...piece, loops: piece.loops.map((loop) => loop.map((p) => [pull(p[0], inside.minX, inside.maxX), pull(p[1], inside.minY, inside.maxY), p[2]])) }));
8518
9187
  }
8519
9188
 
9189
+ // studio/src/look/parts/gullwing.ts
9190
+ var LEAD = 0.15;
9191
+ var STANDOFF = 0.08;
9192
+ var SHOULDER_MOST = 1.05;
9193
+ function bodyBand(height) {
9194
+ return { bottom: Math.min(STANDOFF, height * 0.3), top: height - Math.min(0.02, height * 0.2) };
9195
+ }
9196
+ var SQUARISH = 0.1;
9197
+ var PLATE = 0.04;
9198
+ function padSide(pad) {
9199
+ const r = padRect(pad);
9200
+ const [w, h] = [r.maxX - r.minX, r.maxY - r.minY];
9201
+ const wide = Math.abs(w - h) <= SQUARISH * Math.max(w, h) ? Math.abs(pad.x) > Math.abs(pad.y) : w >= h;
9202
+ if (wide) return pad.x >= 0 ? "right" : "left";
9203
+ return pad.y >= 0 ? "top" : "bottom";
9204
+ }
9205
+ function legPads(input) {
9206
+ const body = input.body;
9207
+ if (body === void 0) return input.pads;
9208
+ const under = (pad) => pad.x > body.minX && pad.x < body.maxX && pad.y > body.minY && pad.y < body.maxY;
9209
+ return input.pads.filter((pad) => !under(pad));
9210
+ }
9211
+ function bodyRect(input, inset = 0.02) {
9212
+ const sides = legPads(input).map((pad) => ({ pad, side: padSide(pad), r: padRect(pad) }));
9213
+ const inner = (side) => sides.filter((s) => s.side === side);
9214
+ const all = padsRect(legPads(input)) ?? input.limit;
9215
+ const reach = (side, fallback2) => {
9216
+ const row3 = inner(side);
9217
+ if (row3.length === 0) return fallback2;
9218
+ if (side === "right") return Math.min(...row3.map((s) => s.r.minX)) - inset;
9219
+ if (side === "left") return Math.max(...row3.map((s) => s.r.maxX)) + inset;
9220
+ if (side === "top") return Math.min(...row3.map((s) => s.r.minY)) - inset;
9221
+ return Math.max(...row3.map((s) => s.r.maxY)) + inset;
9222
+ };
9223
+ const spare = 0.45;
9224
+ const estimate = {
9225
+ minX: reach("left", all.minX - spare),
9226
+ maxX: reach("right", all.maxX + spare),
9227
+ minY: reach("bottom", all.minY - spare),
9228
+ maxY: reach("top", all.maxY + spare)
9229
+ };
9230
+ const rowless = {
9231
+ minX: inner("left").length === 0 ? Math.max(estimate.minX, all.minX - spare) : estimate.minX,
9232
+ maxX: inner("right").length === 0 ? Math.min(estimate.maxX, all.maxX + spare) : estimate.maxX,
9233
+ minY: inner("bottom").length === 0 ? Math.max(estimate.minY, all.minY - spare) : estimate.minY,
9234
+ maxY: inner("top").length === 0 ? Math.min(estimate.maxY, all.maxY + spare) : estimate.maxY
9235
+ };
9236
+ const outline2 = input.body ? clipped(input.body, rowless) : rowless;
9237
+ return clipped(outline2, input.limit);
9238
+ }
9239
+ function leg(pad, side, body, height, color, across) {
9240
+ const r = padRect(pad);
9241
+ const horizontal = side === "left" || side === "right";
9242
+ const sign = side === "right" || side === "top" ? 1 : -1;
9243
+ const edge = side === "right" ? body.maxX : side === "left" ? body.minX : side === "top" ? body.maxY : body.minY;
9244
+ const centre = horizontal ? pad.x : pad.y;
9245
+ const length2 = horizontal ? r.maxX - r.minX : r.maxY - r.minY;
9246
+ const padAcross = horizontal ? r.maxY - r.minY : r.maxX - r.minX;
9247
+ const width = across ?? Math.min(padAcross * 0.72, 0.5);
9248
+ const mid = horizontal ? pad.y : pad.x;
9249
+ const reach = sign * (centre - edge);
9250
+ if (reach <= 0.05) return [];
9251
+ const bend = edge + sign * Math.min(reach * 0.38, 0.6);
9252
+ const toe = centre + sign * Math.min(length2 * 0.3, Math.abs(length2 / 2) - 0.02);
9253
+ const lead = Math.min(LEAD, height / 3);
9254
+ const shoulder = Math.min(Math.max(height * 0.38, lead * 1.5), height - lead * 1.5, SHOULDER_MOST);
9255
+ const span = (a, b, z0, z1) => {
9256
+ const [lo, hi] = [Math.min(a, b), Math.max(a, b)];
9257
+ const rect2 = horizontal ? { minX: lo, maxX: hi, minY: mid - width / 2, maxY: mid + width / 2 } : { minY: lo, maxY: hi, minX: mid - width / 2, maxX: mid + width / 2 };
9258
+ return box(rect2, z0, z1, color, "metal", "leg");
9259
+ };
9260
+ return [...span(edge, bend + sign * lead, shoulder, shoulder + lead), ...span(bend, bend + sign * lead, lead, shoulder), ...span(bend, toe, 0, lead)];
9261
+ }
9262
+ function pin1Dot(input, body, top, roomy = Infinity) {
9263
+ const one = firstPad(input.pads);
9264
+ if (one === void 0) return [];
9265
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9266
+ const radius = Math.min(small * 0.12, 0.4);
9267
+ const inset = radius + Math.min(small * 0.08, roomy);
9268
+ const x = one.x < (body.minX + body.maxX) / 2 ? body.minX + inset : body.maxX - inset;
9269
+ const y = one.y < (body.minY + body.maxY) / 2 ? body.minY + inset : body.maxY - inset;
9270
+ return prism(circle3(x, y, radius, 12), top - 0.01, input.height, input.look.mark, "matt", "pin1");
9271
+ }
9272
+ function gullwingShape(input) {
9273
+ const body = bodyRect(input);
9274
+ const h = input.height;
9275
+ const { bottom: bottom2, top } = bodyBand(h);
9276
+ const { look } = input;
9277
+ const pieces = [...box(body, bottom2, top, look.body, "matt", "body")];
9278
+ const legged = legPads(input);
9279
+ for (const pad of legged) pieces.push(...leg(pad, padSide(pad), body, h, look.metal));
9280
+ for (const pad of input.pads.filter((one) => !legged.includes(one))) pieces.push(...box(clipped(padRect(pad), body), 0, Math.min(PLATE, bottom2), look.metal, "metal", "cap"));
9281
+ pieces.push(...pin1Dot(input, body, top));
9282
+ return clipPieces(pieces, input.limit);
9283
+ }
9284
+
9285
+ // studio/src/look/parts/bga.ts
9286
+ var BALL_OVER_LAND = 1.3;
9287
+ var BALL_SQUASH = 0.8;
9288
+ var BALL_HEIGHT_SHARE = 0.3;
9289
+ var SUBSTRATE = 0.25;
9290
+ var SUBSTRATE_SHARE = 0.3;
9291
+ var CAP_INSET = 0.4;
9292
+ var CAP_INSET_SHARE = 0.06;
9293
+ var DOMED_LIMIT = 64;
9294
+ var MANY = 400;
9295
+ var DOT_ROOM = 0.1;
9296
+ var landOf = (pad) => Math.min(padRect(pad).maxX - padRect(pad).minX, padRect(pad).maxY - padRect(pad).minY);
9297
+ function ball(pad, width, height, count, color) {
9298
+ const radius = width / 2;
9299
+ if (count <= DOMED_LIMIT) return lathe([[radius * 0.55, 0], [radius, height * 0.5], [radius * 0.6, height]], pad.x, pad.y, 8, color, "metal", "pin");
9300
+ return prism(circle3(pad.x, pad.y, radius * 0.85, count <= MANY ? 6 : 4), 0, height, color, "metal", "pin");
9301
+ }
9302
+ function bgaShape(input) {
9303
+ const extent = padsRect(input.pads);
9304
+ const outline2 = clipped(input.body ?? grown3(extent ?? input.limit, 0.3), input.limit);
9305
+ const { look } = input;
9306
+ const h = input.height;
9307
+ const land = Math.min(...input.pads.map(landOf), Infinity);
9308
+ const width = Number.isFinite(land) ? land * BALL_OVER_LAND : 0.4;
9309
+ const ballHeight = Math.min(width * BALL_SQUASH, h * BALL_HEIGHT_SHARE);
9310
+ const substrate = Math.min(SUBSTRATE, (h - ballHeight) * SUBSTRATE_SHARE);
9311
+ const small = Math.min(outline2.maxX - outline2.minX, outline2.maxY - outline2.minY);
9312
+ const cap = grown3(outline2, -Math.min(CAP_INSET, small * CAP_INSET_SHARE));
9313
+ const top = h - 0.02;
9314
+ const colorOfSubstrate = look.top ?? look.body;
9315
+ const pieces = [
9316
+ ...input.pads.flatMap((pad) => ball(pad, width, ballHeight, input.pads.length, look.metal)),
9317
+ ...box(outline2, ballHeight, ballHeight + substrate, colorOfSubstrate, "matt", "body"),
9318
+ ...box(cap, ballHeight + substrate, top, look.body, "matt", "body"),
9319
+ ...pin1Dot(input, cap, top, DOT_ROOM)
9320
+ ];
9321
+ return pieces;
9322
+ }
9323
+
8520
9324
  // studio/src/look/parts/block.ts
8521
- var INSET = 0.15;
9325
+ var INSET2 = 0.15;
8522
9326
  function blockShape(input) {
8523
- const body = clipped(input.body ?? grown3(input.limit, -INSET), input.limit);
9327
+ const body = clipped(input.body ?? grown3(input.limit, -INSET2), input.limit);
8524
9328
  const { look } = input;
8525
9329
  return [...clipPieces(box(body, 0, input.height, { top: look.top ?? look.body, side: look.body }, "matt", "body"), input.limit), ...leads(input)];
8526
9330
  }
@@ -8550,52 +9354,111 @@ function crystalShape(input) {
8550
9354
  const moved = turnPieces(pieces, angle).map((piece) => ({ ...piece, loops: piece.loops.map((loop) => loop.map((p) => [p[0] + mid.x, p[1] + mid.y, p[2]])) }));
8551
9355
  return [...clipPieces(moved, input.limit), ...leads(input)];
8552
9356
  }
8553
- var SIDES = 24;
9357
+ var SIDES3 = 24;
8554
9358
  function electrolyticShape(input) {
8555
9359
  const limit = input.limit;
8556
9360
  const radius = Math.min(limit.maxX - limit.minX, limit.maxY - limit.minY) / 2 - MARGIN;
8557
9361
  const cx = (limit.minX + limit.maxX) / 2;
8558
9362
  const cy = (limit.minY + limit.maxY) / 2;
8559
- const minus = input.pads.find((p) => p.number === "2");
8560
- const towards = minus === void 0 ? 0 : Math.atan2(minus.y - cy, minus.x - cx);
9363
+ const minus2 = input.pads.find((p) => p.number === "2");
9364
+ const towards = minus2 === void 0 ? 0 : Math.atan2(minus2.y - cy, minus2.x - cx);
8561
9365
  const h = input.height;
8562
9366
  const { look } = input;
8563
- const lid = Math.min(0.4, h * 0.05);
9367
+ const lid2 = Math.min(0.4, h * 0.05);
8564
9368
  const stripe = (i) => {
8565
- const a = 2 * Math.PI * (i + 0.5) / SIDES;
9369
+ const a = 2 * Math.PI * (i + 0.5) / SIDES3;
8566
9370
  const off = Math.abs(Math.atan2(Math.sin(a - towards), Math.cos(a - towards)));
8567
9371
  return off < Math.PI / 6 ? look.mark : void 0;
8568
9372
  };
8569
9373
  const pieces = [
8570
- ...prism(circle3(cx, cy, radius, SIDES), 0, h - lid, { top: look.top ?? look.body, side: look.body }, "matt", "body", stripe),
8571
- ...prism(circle3(cx, cy, radius * 0.9, SIDES), h - lid, h, look.top ?? look.metal, "metal", "body")
9374
+ ...prism(circle3(cx, cy, radius, SIDES3), 0, h - lid2, { top: look.top ?? look.body, side: look.body }, "matt", "body", stripe),
9375
+ ...prism(circle3(cx, cy, radius * 0.9, SIDES3), h - lid2, h, look.top ?? look.metal, "metal", "body")
8572
9376
  ];
8573
9377
  return [...clipPieces(pieces, input.limit), ...leads(input)];
8574
9378
  }
8575
9379
 
8576
- // studio/src/look/parts/family.ts
9380
+ // studio/src/look/parts/smd-family.ts
8577
9381
  var TIN = [196, 198, 200];
9382
+ var SMD_LOOKS = {
9383
+ melf: { sentence: "MELF diode: a dark glass cylinder lying on the board between two tinned end caps, a pale band at the cathode.", body: [54, 42, 40], metal: TIN, mark: [214, 208, 190] },
9384
+ tantalum: { sentence: "Tantalum capacitor: an amber moulded block with a darker stripe across the top at the plus end, tinned terminals wrapped over its ends.", body: [204, 140, 56], metal: TIN, mark: [112, 70, 28] },
9385
+ array: { sentence: "Resistor array: one pale ceramic body under a near-black coat with a small tinned terminal over each pad.", body: [206, 202, 190], top: [34, 34, 38], metal: TIN, mark: [34, 34, 38] },
9386
+ smdcan: { sentence: "Surface-mount aluminium capacitor: a black plastic base with two clipped corners under a round aluminium can, a dark segment on the lid at the minus side.", body: [28, 28, 32], top: [200, 204, 210], metal: [186, 190, 196], mark: [34, 36, 42] },
9387
+ xtal: { sentence: "Surface-mount crystal: a ceramic base under a smaller metal lid with a dot at pin 1, tinned terminals at the pads.", body: [212, 196, 162], top: [186, 190, 196], metal: TIN, mark: [60, 60, 66] },
9388
+ xtalCan: { sentence: "HC-49 SMD crystal: a metal can with rounded ends on a low dark seat, a flat tinned lead to each pad.", body: [188, 190, 194], top: [204, 206, 210], metal: TIN, mark: [38, 38, 42] },
9389
+ ledsmd: { sentence: "Surface-mount LED: a white body with a round pale lens on top and a clipped corner at pad 1 (the two-pad one a green bar at the cathode), tinned terminals.", body: [238, 238, 230], top: [250, 240, 196], metal: TIN, mark: [64, 168, 92] },
9390
+ plcc: { sentence: "PLCC chip: a near-black body with a clipped corner and a dot at pin 1 and a tinned J-lead on every pad.", body: [34, 34, 38], metal: TIN, mark: [150, 150, 156] }
9391
+ };
9392
+ function smdFamilyOf(p) {
9393
+ if (p.kind === "minimelf" || p.kind === "melf" || p.kind === "sod" && p.code === "80" || p.kind === "do" && p.code === "213") return { family: "melf", look: "melf" };
9394
+ if (p.kind === "tant") return { family: "tantalum", look: "tantalum" };
9395
+ if (p.kind === "array") return { family: "array", look: "array" };
9396
+ if (p.kind === "smdcan") return { family: "smdcan", look: "smdcan" };
9397
+ if (p.kind === "xtal") return { family: "xtal", look: "xtal" };
9398
+ if (p.kind === "hc" && p.code === "49" && p.suffix === "smd") return { family: "xtal", look: "xtalCan" };
9399
+ if (p.kind === "led" && (p.code === "3528" || p.code === "5050")) return { family: "ledsmd", look: "ledsmd" };
9400
+ if (p.kind === "plcc") return { family: "plcc", look: "plcc" };
9401
+ const power = p.kind === "dpak" && p.code === "" || p.kind === "to" && (p.code === "252" || p.code === "263") || p.kind === "d" && p.code === "2" && p.suffix === "pak";
9402
+ return power ? { family: "tab", look: "tab" } : void 0;
9403
+ }
9404
+
9405
+ // studio/src/look/parts/uno-family.ts
9406
+ var TIN2 = [196, 198, 200];
9407
+ var UNO_LOOKS = {
9408
+ usbb: { sentence: "USB Type-B receptacle: a tinned metal shell open at the mating face with a dark opening and a pale plastic tongue inside, two shell legs and four pins through their holes.", body: [226, 222, 204], metal: TIN2, mark: [14, 14, 18] },
9409
+ usbc: { sentence: "USB Type-C receptacle: a low tinned metal shell with rounded ends, a dark stadium opening at the mating face with a thin pale tongue, shell legs through their slots and a row of terminals on the pads at the back.", body: [226, 222, 204], metal: TIN2, mark: [18, 18, 22] },
9410
+ dcjack: { sentence: "Barrel jack: a black plastic body with a round opening on the mating face and a metal pin in its middle, flat terminals through the slots.", body: [32, 32, 35], metal: TIN2, mark: [8, 8, 10] },
9411
+ tact: { sentence: "Tact switch, 6 \xD7 6 mm: a low black base under a tinned metal cover plate with a round black button standing out of its middle, pins through the holes or gull-wing terminals on the pads.", body: [30, 30, 34], top: [62, 62, 68], metal: TIN2, mark: [30, 30, 34] },
9412
+ resonator: { sentence: "Ceramic resonator: a small pale ceramic body under a tinned metal cap over most of its top, a terminal on each of its three pads.", body: [226, 212, 172], metal: TIN2, mark: [226, 212, 172] },
9413
+ inductor: { sentence: "Shielded power inductor: a dark grey ferrite block with clipped corners and a slightly lighter top with a small mark, a tinned terminal at each pad.", body: [58, 60, 64], top: [86, 88, 94], metal: TIN2, mark: [178, 180, 184] }
9414
+ };
9415
+ function unoFamilyOf(p) {
9416
+ if (p.kind === "usb") return p.params["b"] === true ? "usbb" : p.params["c"] === 16 ? "usbc" : void 0;
9417
+ if (p.kind === "dcjack") return "dcjack";
9418
+ if (p.kind === "tact") return "tact";
9419
+ if (p.kind === "resonator") return "resonator";
9420
+ if (p.kind === "ind") return "inductor";
9421
+ return void 0;
9422
+ }
9423
+
9424
+ // studio/src/look/parts/family.ts
9425
+ var TIN3 = [196, 198, 200];
8578
9426
  var GOLD = [214, 176, 86];
8579
9427
  var FAMILY_LOOKS = {
8580
- resistor: { sentence: "Chip resistor: a pale ceramic body under a near-black coat, between two tinned end caps.", body: [216, 214, 204], top: [34, 34, 36], metal: TIN, mark: [34, 34, 36] },
8581
- capacitor: { sentence: "Chip capacitor: a tan ceramic body between two tinned end caps.", body: [176, 138, 92], metal: TIN, mark: [176, 138, 92] },
8582
- led: { sentence: "Chip LED: a white body under a pale yellow lens, a green mark at the cathode.", body: [234, 234, 226], top: [244, 232, 168], metal: TIN, mark: [64, 168, 92] },
8583
- chip: { sentence: "Any other chip part: a grey-brown body between two tinned end caps.", body: [120, 112, 100], metal: TIN, mark: [120, 112, 100] },
8584
- molded: { sentence: "Moulded diode: a near-black body, a light grey band at the cathode, flat tinned leads.", body: [44, 44, 46], metal: TIN, mark: [200, 200, 194] },
8585
- gullwing: { sentence: "Gull-wing chip: a near-black moulded body with a pin 1 dot, tinned legs bent down to the pads.", body: [40, 40, 43], metal: TIN, mark: [96, 96, 100] },
8586
- leadless: { sentence: "Leadless chip: a near-black body with a pin 1 dot, tinned terminals at its edges.", body: [40, 40, 43], metal: TIN, mark: [96, 96, 100] },
9428
+ resistor: { sentence: "Chip resistor: a pale ceramic body under a near-black coat, between two tinned end caps.", body: [216, 214, 204], top: [34, 34, 36], metal: TIN3, mark: [34, 34, 36] },
9429
+ capacitor: { sentence: "Chip capacitor: a tan ceramic body between two tinned end caps.", body: [176, 138, 92], metal: TIN3, mark: [176, 138, 92] },
9430
+ led: { sentence: "Chip LED: a white body under a pale yellow lens, a green mark at the cathode.", body: [234, 234, 226], top: [244, 232, 168], metal: TIN3, mark: [64, 168, 92] },
9431
+ chip: { sentence: "Any other chip part: a grey-brown body between two tinned end caps.", body: [120, 112, 100], metal: TIN3, mark: [120, 112, 100] },
9432
+ molded: { sentence: "Moulded diode: a near-black body, a light grey band at the cathode, flat tinned leads.", body: [44, 44, 46], metal: TIN3, mark: [200, 200, 194] },
9433
+ gullwing: { sentence: "Gull-wing chip: a near-black moulded body with a pin 1 dot, tinned legs bent down to the pads.", body: [40, 40, 43], metal: TIN3, mark: [96, 96, 100] },
9434
+ leadless: { sentence: "Leadless chip: a near-black body with a pin 1 dot, tinned terminals at its edges.", body: [40, 40, 43], metal: TIN3, mark: [96, 96, 100] },
9435
+ bga: { sentence: "Ball grid array: a tan substrate on a ball of tin under every pad, a dark mould cap on it and a pin 1 dot.", body: [36, 36, 40], top: [150, 128, 78], metal: TIN3, mark: [196, 196, 190] },
9436
+ dip: { sentence: "Dual in-line package: a near-black body raised off the board with a notch and dot at pin 1, flat tinned legs down through the holes.", body: [34, 34, 38], metal: TIN3, mark: [150, 150, 156] },
9437
+ to220: { sentence: "TO-220: a metal tab with its hole at the back of a near-black plastic body, flat tinned leads (two, three or five) down into the board; the TO-247 is bigger, the TO-126 all plastic with a hole.", body: [30, 30, 33], metal: [176, 180, 186], mark: [30, 30, 33] },
9438
+ to92: { sentence: "TO-92: a near-black body with a flat front and a round back, raised on three tinned leads.", body: [34, 34, 36], metal: TIN3, mark: [34, 34, 36] },
9439
+ tab: { sentence: "Power SOT with a tab: a near-black body with a pin 1 dot, tinned legs on the narrow pads and one wide flat tab on the wide pad.", body: [40, 40, 43], metal: TIN3, mark: [96, 96, 100] },
9440
+ axialResistor: { sentence: "Axial resistor: a beige body lying above the board with three or four coloured bands (fixed colours, not the value's code), a wire from each end bent down through its hole.", body: [214, 188, 142], metal: TIN3, mark: [214, 188, 142] },
9441
+ axialDiode: { sentence: "Axial diode: a near-black body with a pale band at the cathode end, a wire from each end bent down through its hole.", body: [38, 38, 40], metal: TIN3, mark: [208, 208, 200] },
9442
+ axialGlass: { sentence: "Glass diode: an orange glass body with a dark band at the cathode end, a wire from each end bent down through its hole.", body: [214, 122, 44], metal: TIN3, mark: [34, 30, 28] },
9443
+ axialPlain: { sentence: "Any other axial part: a plain grey body lying above the board, a wire from each end bent down through its hole.", body: [122, 126, 132], metal: TIN3, mark: [122, 126, 132] },
9444
+ ledlens: { sentence: "Round LED: a flange ring on the board with a flat at the cathode, a translucent-looking lens (red unless the part says another colour) with a domed top, two tinned leads.", body: [214, 48, 44], top: [236, 96, 88], metal: TIN3, mark: [244, 240, 232] },
9445
+ screw: { sentence: "Screw terminal block: a green block with a slotted round screw head on top and a dark wire opening on the front of every pole, a tinned pin through each hole.", body: [44, 128, 78], metal: TIN3, mark: [16, 18, 18] },
9446
+ socket: { sentence: "Pin socket: a black body with a dark square opening over every pin and a gold pin through each hole.", body: [26, 26, 28], metal: GOLD, mark: [8, 8, 10] },
8587
9447
  header: { sentence: "Pin header: a black plastic base with a gold pin on every pad.", body: [28, 28, 30], metal: GOLD, mark: [28, 28, 30] },
8588
- crystal: { sentence: "Crystal: a plain metal can with rounded ends.", body: [188, 190, 194], metal: TIN, mark: [188, 190, 194] },
8589
- electrolytic: { sentence: "Electrolytic capacitor: a dark blue sleeve with a pale stripe at the minus lead, a metal lid.", body: [38, 52, 98], top: [182, 186, 192], metal: TIN, mark: [198, 204, 214] },
8590
- relay: { sentence: "Relay: a mid-blue box with its leads.", body: [46, 86, 156], top: [58, 100, 170], metal: TIN, mark: [46, 86, 156] },
8591
- terminal: { sentence: "Connector at another pitch, such as a terminal block: a green box with its leads.", body: [44, 128, 78], metal: TIN, mark: [44, 128, 78] },
8592
- block: { sentence: "Any other through-hole part: a dark grey box with its leads.", body: [72, 74, 78], metal: TIN, mark: [72, 74, 78] },
8593
- box: { sentence: "Anything else: a plain box, as before shapes were drawn.", body: [96, 138, 118], metal: TIN, mark: [96, 138, 118] }
9448
+ crystal: { sentence: "Crystal: a plain metal can with rounded ends.", body: [188, 190, 194], metal: TIN3, mark: [188, 190, 194] },
9449
+ electrolytic: { sentence: "Electrolytic capacitor: a dark blue sleeve with a pale stripe at the minus lead, a metal lid.", body: [38, 52, 98], top: [182, 186, 192], metal: TIN3, mark: [198, 204, 214] },
9450
+ relay: { sentence: "Relay: a mid-blue box with its leads.", body: [46, 86, 156], top: [58, 100, 170], metal: TIN3, mark: [46, 86, 156] },
9451
+ terminal: { sentence: "Connector at another pitch, such as a terminal block: a green box with its leads.", body: [44, 128, 78], metal: TIN3, mark: [44, 128, 78] },
9452
+ block: { sentence: "Any other through-hole part: a dark grey box with its leads.", body: [72, 74, 78], metal: TIN3, mark: [72, 74, 78] },
9453
+ ...SMD_LOOKS,
9454
+ ...UNO_LOOKS,
9455
+ box: { sentence: "Anything else: a plain box, as before shapes were drawn.", body: [96, 138, 118], metal: TIN3, mark: [96, 138, 118] }
8594
9456
  };
8595
- var CHIP_CODES = /* @__PURE__ */ new Set(["0201", "0402", "0603", "0805", "1206", "1210", "1812", "2010", "2512"]);
8596
- var GULLWING = /* @__PURE__ */ new Set(["soic", "sot", "sop", "ssop", "tssop", "msop", "qfp", "lqfp", "tqfp", "sc", "sod323f"]);
9457
+ var CHIP_CODES = /* @__PURE__ */ new Set(["0201", "0402", "0603", "0805", "1206", "1210", "1812", "2010", "2512", "01005", "2220"]);
9458
+ var GULLWING = /* @__PURE__ */ new Set(["soic", "sot", "sop", "ssop", "tssop", "msop", "qsop", "smdip", "qfp", "lqfp", "tqfp", "sc"]);
8597
9459
  var LEADLESS = /* @__PURE__ */ new Set(["qfn", "dfn", "son", "wson", "vson"]);
8598
- var MOLDED = /* @__PURE__ */ new Set(["sod", "sma", "smb", "smc", "do", "minimelf", "melf"]);
9460
+ var TABBED = /* @__PURE__ */ new Set(["223", "89"]);
9461
+ var MOLDED = /* @__PURE__ */ new Set(["sod", "sma", "smb", "smc", "do"]);
8599
9462
  var parsed = (footprint) => footprint === void 0 || footprint.includes("/") || footprint.endsWith(".yaml") ? void 0 : parseFootprint(footprint);
8600
9463
  function chipLook(kind) {
8601
9464
  if (kind === "resistor") return "resistor";
@@ -8603,6 +9466,14 @@ function chipLook(kind) {
8603
9466
  if (kind === "led") return "led";
8604
9467
  return "chip";
8605
9468
  }
9469
+ var TO220_FAMILY = /* @__PURE__ */ new Set(["220", "247", "126"]);
9470
+ var AXIAL_DIODE_CODES = /* @__PURE__ */ new Set(["35", "41", "15", "201"]);
9471
+ function axialLook(kind, p) {
9472
+ if (p.kind === "do") return p.code === "35" ? "axialGlass" : "axialDiode";
9473
+ if (kind === "resistor") return "axialResistor";
9474
+ if (kind === "diode") return "axialDiode";
9475
+ return "axialPlain";
9476
+ }
8606
9477
  function blockLook(name) {
8607
9478
  const letter = /^[A-Za-z]+/.exec(name)?.[0]?.toUpperCase() ?? "";
8608
9479
  if (letter === "K") return "relay";
@@ -8610,117 +9481,102 @@ function blockLook(name) {
8610
9481
  return "block";
8611
9482
  }
8612
9483
  function familyOf(kind, footprint, through2 = false, name = "") {
8613
- const p = parsed(footprint);
8614
- const withParsed = (family, look) => ({ family, look, ...p ? { parsed: p } : {} });
8615
- if (p !== void 0) {
8616
- if (p.kind === "" && CHIP_CODES.has(p.code)) return withParsed("chip", chipLook(kind));
8617
- if (MOLDED.has(p.kind)) return withParsed("molded", "molded");
8618
- if (GULLWING.has(p.kind)) return withParsed("gullwing", "gullwing");
8619
- if (LEADLESS.has(p.kind)) return withParsed("leadless", "leadless");
8620
- if (p.kind === "pinrow" && (p.params["p"] === void 0 || p.params["p"] === 2.54)) return withParsed("header", "header");
8621
- if (p.kind === "hc" && p.code === "49") return withParsed("crystal", "crystal");
8622
- if (p.kind === "radial") return withParsed("electrolytic", "electrolytic");
8623
- if (p.kind === "pinrow") return withParsed("block", blockLook(name || "J"));
8624
- }
8625
- if (through2) return withParsed("block", blockLook(name));
8626
- return withParsed("box", "box");
8627
- }
8628
-
8629
- // studio/src/look/parts/gullwing.ts
8630
- var LEAD = 0.15;
8631
- var STANDOFF = 0.08;
8632
- function padSide(pad) {
8633
- const r = padRect(pad);
8634
- const wide = r.maxX - r.minX >= r.maxY - r.minY;
8635
- if (wide) return pad.x >= 0 ? "right" : "left";
8636
- return pad.y >= 0 ? "top" : "bottom";
8637
- }
8638
- function bodyRect(input, inset = 0.02) {
8639
- const sides = input.pads.map((pad) => ({ pad, side: padSide(pad), r: padRect(pad) }));
8640
- const inner = (side) => sides.filter((s) => s.side === side);
8641
- const all = padsRect(input.pads) ?? input.limit;
8642
- const reach = (side, fallback) => {
8643
- const row = inner(side);
8644
- if (row.length === 0) return fallback;
8645
- if (side === "right") return Math.min(...row.map((s) => s.r.minX)) - inset;
8646
- if (side === "left") return Math.max(...row.map((s) => s.r.maxX)) + inset;
8647
- if (side === "top") return Math.min(...row.map((s) => s.r.minY)) - inset;
8648
- return Math.max(...row.map((s) => s.r.maxY)) + inset;
8649
- };
8650
- const spare = 0.45;
8651
- const estimate = {
8652
- minX: reach("left", all.minX - (inner("top").length + inner("bottom").length > 0 ? 0 : 0) + (inner("left").length === 0 && inner("right").length === 0 ? 0 : 0) - spare),
8653
- maxX: reach("right", all.maxX + spare),
8654
- minY: reach("bottom", all.minY - spare),
8655
- maxY: reach("top", all.maxY + spare)
8656
- };
8657
- const rowless = {
8658
- minX: inner("left").length === 0 ? Math.max(estimate.minX, all.minX - spare) : estimate.minX,
8659
- maxX: inner("right").length === 0 ? Math.min(estimate.maxX, all.maxX + spare) : estimate.maxX,
8660
- minY: inner("bottom").length === 0 ? Math.max(estimate.minY, all.minY - spare) : estimate.minY,
8661
- maxY: inner("top").length === 0 ? Math.min(estimate.maxY, all.maxY + spare) : estimate.maxY
8662
- };
8663
- const outline2 = input.body ? clipped(input.body, rowless) : rowless;
8664
- return clipped(outline2, input.limit);
8665
- }
8666
- function leg(pad, side, body, height, color) {
8667
- const r = padRect(pad);
8668
- const horizontal = side === "left" || side === "right";
8669
- const sign = side === "right" || side === "top" ? 1 : -1;
8670
- const edge = side === "right" ? body.maxX : side === "left" ? body.minX : side === "top" ? body.maxY : body.minY;
8671
- const centre = horizontal ? pad.x : pad.y;
8672
- const length2 = horizontal ? r.maxX - r.minX : r.maxY - r.minY;
8673
- const across = horizontal ? r.maxY - r.minY : r.maxX - r.minX;
8674
- const width = Math.min(across * 0.72, 0.5);
8675
- const mid = horizontal ? pad.y : pad.x;
8676
- const reach = sign * (centre - edge);
8677
- if (reach <= 0.05) return [];
8678
- const bend = edge + sign * Math.min(reach * 0.38, 0.6);
8679
- const toe = centre + sign * Math.min(length2 * 0.3, Math.abs(length2 / 2) - 0.02);
8680
- const shoulder = Math.min(Math.max(height * 0.38, LEAD * 1.5), height - LEAD * 1.5);
8681
- const span = (a, b, z0, z1) => {
8682
- const [lo, hi] = [Math.min(a, b), Math.max(a, b)];
8683
- const rect2 = horizontal ? { minX: lo, maxX: hi, minY: mid - width / 2, maxY: mid + width / 2 } : { minY: lo, maxY: hi, minX: mid - width / 2, maxX: mid + width / 2 };
8684
- return box(rect2, z0, z1, color, "metal", "leg");
8685
- };
8686
- return [...span(edge, bend + sign * LEAD, shoulder, shoulder + LEAD), ...span(bend, bend + sign * LEAD, LEAD, shoulder), ...span(bend, toe, 0, LEAD)];
9484
+ const p = parsed(footprint);
9485
+ const withParsed = (family, look) => ({ family, look, ...p ? { parsed: p } : {} });
9486
+ if (p !== void 0) {
9487
+ if (p.kind === "" && CHIP_CODES.has(p.code)) return withParsed("chip", chipLook(kind));
9488
+ if (p.kind === "bga") return withParsed("bga", "bga");
9489
+ if (p.kind === "dip") return withParsed("dip", "dip");
9490
+ if (p.kind === "to" && TO220_FAMILY.has(p.code)) return withParsed("to220", "to220");
9491
+ if (p.kind === "axial" || p.kind === "do" && AXIAL_DIODE_CODES.has(p.code)) return withParsed("axial", axialLook(kind, p));
9492
+ if (p.kind === "led" && p.suffix === "mm") return withParsed("ledth", "ledlens");
9493
+ if (p.kind === "screw") return withParsed("screw", "screw");
9494
+ if (p.kind === "socket") return withParsed("socket", "socket");
9495
+ if (p.kind === "to" && p.code === "92") return withParsed("to92", "to92");
9496
+ const uno = unoFamilyOf(p);
9497
+ if (uno !== void 0) return withParsed(uno, uno);
9498
+ const smd = smdFamilyOf(p);
9499
+ if (smd !== void 0) return withParsed(smd.family, smd.look);
9500
+ if (p.kind === "sot" && TABBED.has(p.code) && p.variant === void 0) return withParsed("tab", "tab");
9501
+ if (MOLDED.has(p.kind)) return withParsed("molded", "molded");
9502
+ if (GULLWING.has(p.kind)) return withParsed("gullwing", "gullwing");
9503
+ if (LEADLESS.has(p.kind)) return withParsed("leadless", "leadless");
9504
+ if (p.kind === "pinrow" && (p.params["p"] === void 0 || p.params["p"] === 2.54 || typeof p.params["p"] === "number" && p.params["p"] < 2.54)) return withParsed("header", "header");
9505
+ if (p.kind === "hc" && p.code === "49") return withParsed("crystal", "crystal");
9506
+ if (p.kind === "radial") return withParsed("electrolytic", "electrolytic");
9507
+ if (p.kind === "pinrow") return withParsed("block", blockLook(name || "J"));
9508
+ }
9509
+ if (through2) return withParsed("block", blockLook(name));
9510
+ return withParsed("box", "box");
8687
9511
  }
8688
- function gullwingShape(input) {
8689
- const body = bodyRect(input);
9512
+
9513
+ // studio/src/look/parts/dip.ts
9514
+ var STANDOFF2 = 0.5;
9515
+ var LEG_THICKNESS = 0.25;
9516
+ var LEG_WIDTH = 0.5;
9517
+ var SHOULDER_SHARE = 0.3;
9518
+ var NOTCH_RADIUS = 0.9;
9519
+ var NOTCH_SHARE = 0.18;
9520
+ var NOTCH_STEPS = 8;
9521
+ function notch(body, end, radius) {
9522
+ const cx = (body.minX + body.maxX) / 2;
9523
+ const y = end === 1 ? body.maxY : body.minY;
9524
+ const arc = Array.from({ length: NOTCH_STEPS + 1 }, (_, i) => {
9525
+ const angle = Math.PI * (i / NOTCH_STEPS) + (end === 1 ? Math.PI : 0);
9526
+ return { x: cx + radius * Math.cos(angle), y: y + radius * Math.sin(angle) };
9527
+ });
9528
+ return arc;
9529
+ }
9530
+ function leg2(pad, body, shoulder, color) {
9531
+ const sign = pad.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
9532
+ const edge = sign === 1 ? body.maxX : body.minX;
9533
+ const across = { minY: pad.y - LEG_WIDTH / 2, maxY: pad.y + LEG_WIDTH / 2 };
9534
+ const outer = pad.x + sign * (LEG_THICKNESS / 2);
9535
+ const [lo, hi] = [Math.min(edge, outer), Math.max(edge, outer)];
9536
+ const stub = box({ minX: lo, maxX: hi, ...across }, shoulder, shoulder + LEG_THICKNESS, color, "metal", "leg");
9537
+ const down = box({ minX: pad.x - LEG_THICKNESS / 2, maxX: pad.x + LEG_THICKNESS / 2, ...across }, 0, shoulder + LEG_THICKNESS, color, "metal", "leg");
9538
+ return [...stub, ...down];
9539
+ }
9540
+ function dipShape(input) {
9541
+ const body = clipped(input.body ?? grown3(input.limit, -0.3), input.limit);
9542
+ const { look } = input;
8690
9543
  const h = input.height;
8691
9544
  const top = h - 0.02;
8692
- const { look } = input;
8693
- const pieces = [...box(body, STANDOFF, top, look.body, "matt", "body")];
8694
- for (const pad of input.pads) pieces.push(...leg(pad, padSide(pad), body, h, look.metal));
9545
+ const shoulder = STANDOFF2 + (top - STANDOFF2) * SHOULDER_SHARE;
9546
+ const pieces = [...box(body, STANDOFF2, top, look.body, "matt", "body")];
9547
+ for (const pad of input.pads) if (pad.layers === "through") pieces.push(...leg2(pad, body, shoulder, look.metal));
8695
9548
  const one = firstPad(input.pads);
8696
- if (one !== void 0) {
8697
- const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
8698
- const radius = Math.min(small * 0.12, 0.4);
8699
- const inset = radius + small * 0.08;
8700
- const x = one.x < (body.minX + body.maxX) / 2 ? body.minX + inset : body.maxX - inset;
8701
- const y = one.y < (body.minY + body.maxY) / 2 ? body.minY + inset : body.maxY - inset;
8702
- pieces.push(...prism(circle3(x, y, radius, 12), top - 0.01, h, look.mark, "matt", "pin1"));
8703
- }
8704
- return clipPieces(pieces, input.limit);
9549
+ const end = one !== void 0 && one.y < (body.minY + body.maxY) / 2 ? -1 : 1;
9550
+ const radius = Math.min(NOTCH_RADIUS, (body.maxX - body.minX) * NOTCH_SHARE);
9551
+ pieces.push(...prism(notch(body, end, radius), top - 0.01, h, look.mark, "matt", "pin1"));
9552
+ pieces.push(...pin1Dot(input, body, top));
9553
+ return [...pieces, ...leads(input, look.metal, { x: LEG_THICKNESS / 2, y: LEG_WIDTH / 2 })];
8705
9554
  }
8706
9555
 
8707
9556
  // studio/src/look/parts/header.ts
8708
- var PITCH = 2.54;
9557
+ var PITCH2 = 2.54;
8709
9558
  var BASE = 2.5;
8710
9559
  var PIN = 0.64;
9560
+ var pitchOf3 = (input) => {
9561
+ const given = input.parsed?.params["p"];
9562
+ return typeof given === "number" && given > 0 ? given : PITCH2;
9563
+ };
8711
9564
  function headerShape(input) {
8712
9565
  const pads2 = padsRect(input.pads);
8713
9566
  if (pads2 === void 0) return [];
8714
9567
  const xs = input.pads.map((p) => p.x);
8715
9568
  const ys = input.pads.map((p) => p.y);
8716
- const half = PITCH / 2;
9569
+ const pitch = pitchOf3(input);
9570
+ const scale = Math.min(1, pitch / PITCH2);
9571
+ const [baseHeight, pinSize] = [BASE * scale, PIN * scale];
9572
+ const half = pitch / 2;
8717
9573
  const base = clipped({ minX: Math.min(...xs) - half, maxX: Math.max(...xs) + half, minY: Math.min(...ys) - half, maxY: Math.max(...ys) + half }, input.limit);
8718
9574
  const h = input.height;
8719
9575
  const { look } = input;
8720
- const baseTop = Math.min(BASE, h * 0.4);
9576
+ const baseTop = Math.min(baseHeight, h * 0.4);
8721
9577
  const pieces = [...box(base, 0, baseTop, look.body, "matt", "body")];
8722
9578
  for (const pad of input.pads) {
8723
- const pin = { minX: pad.x - PIN / 2, maxX: pad.x + PIN / 2, minY: pad.y - PIN / 2, maxY: pad.y + PIN / 2 };
9579
+ const pin = { minX: pad.x - pinSize / 2, maxX: pad.x + pinSize / 2, minY: pad.y - pinSize / 2, maxY: pad.y + pinSize / 2 };
8724
9580
  pieces.push(...box(pin, baseTop, h, look.metal, "metal", "pin"));
8725
9581
  pieces.push(...hanging(rectPolygon(pin), 0, -(input.thickness + LEAD_TAIL), look.metal, "metal", "lead"));
8726
9582
  }
@@ -8774,17 +9630,812 @@ function moldedShape(input) {
8774
9630
  const at2 = (minX, maxX, w) => ({ minX, maxX, minY: -w / 2, maxY: w / 2 });
8775
9631
  const { look } = input;
8776
9632
  const leadWidth = Math.min(padAcross * 0.6, width * 0.6);
8777
- const band2 = Math.max(length2 * 0.16, 0.2);
9633
+ const band3 = Math.max(length2 * 0.16, 0.2);
8778
9634
  const pieces = [
8779
9635
  ...box(at2(-gap / 2 - padAlong * 0.3, -length2 / 2 + 0.05, leadWidth), 0, LEAD2, look.metal, "metal", "leg"),
8780
9636
  ...box(at2(length2 / 2 - 0.05, gap / 2 + padAlong * 0.3, leadWidth), 0, LEAD2, look.metal, "metal", "leg"),
8781
9637
  ...box(at2(-length2 / 2, length2 / 2, width), 0.04, top, look.body, "matt", "body"),
8782
- ...box(at2(length2 / 2 - band2 * 1.9, length2 / 2 - band2 * 0.9, width * 0.96), top - 0.01, h, look.mark, "matt", "cathode")
9638
+ ...box(at2(length2 / 2 - band3 * 1.9, length2 / 2 - band3 * 0.9, width * 0.96), top - 0.01, h, look.mark, "matt", "cathode")
8783
9639
  ];
8784
9640
  const moved = turnPieces(pieces, angle).map((piece) => ({ ...piece, loops: piece.loops.map((loop) => loop.map((p) => [p[0] + mid.x, p[1] + mid.y, p[2]])) }));
8785
9641
  return clipPieces(moved, input.limit);
8786
9642
  }
8787
9643
 
9644
+ // studio/src/look/parts/smd.ts
9645
+ function twoPads(input) {
9646
+ const [one, two] = [input.pads.find((pad) => pad.number === "1") ?? input.pads[0], input.pads.find((pad) => pad.number === "2") ?? input.pads[1]];
9647
+ if (one === void 0 || two === void 0) return void 0;
9648
+ const angle = Math.atan2(two.y - one.y, two.x - one.x) * 180 / Math.PI;
9649
+ const flat = Math.abs(Math.sin(angle * Math.PI / 180)) > 0.7;
9650
+ const rect2 = padRect(two);
9651
+ const gap = Math.hypot(two.x - one.x, two.y - one.y);
9652
+ const padAlong = flat ? rect2.maxY - rect2.minY : rect2.maxX - rect2.minX;
9653
+ const padAcross = flat ? rect2.maxX - rect2.minX : rect2.maxY - rect2.minY;
9654
+ const bodyAlong = input.body ? flat ? input.body.maxY - input.body.minY : input.body.maxX - input.body.minX : gap + padAlong * 0.3;
9655
+ const bodyAcross = input.body ? flat ? input.body.maxX - input.body.minX : input.body.maxY - input.body.minY : padAcross;
9656
+ return { angle, mid: { x: (one.x + two.x) / 2, y: (one.y + two.y) / 2 }, gap, padAlong, padAcross, bodyAlong, bodyAcross };
9657
+ }
9658
+ function settle(pieces, axis, input) {
9659
+ const moved = turnPieces(pieces, axis.angle).map((piece) => ({ ...piece, loops: piece.loops.map((loop) => loop.map((p) => [p[0] + axis.mid.x, p[1] + axis.mid.y, p[2]])) }));
9660
+ return clipPieces(moved, input.limit);
9661
+ }
9662
+ function sideOf(pad, body) {
9663
+ const [dx, dy] = [(pad.x - (body.minX + body.maxX) / 2) / ((body.maxX - body.minX) / 2 || 1), (pad.y - (body.minY + body.maxY) / 2) / ((body.maxY - body.minY) / 2 || 1)];
9664
+ if (Math.abs(dy) >= Math.abs(dx)) return dy >= 0 ? "top" : "bottom";
9665
+ return dx >= 0 ? "right" : "left";
9666
+ }
9667
+ function band(pad, body, side, inside, outside) {
9668
+ const grownBody = { minX: body.minX - outside, maxX: body.maxX + outside, minY: body.minY - outside, maxY: body.maxY + outside };
9669
+ const strip = {
9670
+ left: { ...grownBody, minX: body.minX - outside, maxX: body.minX + inside },
9671
+ right: { ...grownBody, minX: body.maxX - inside, maxX: body.maxX + outside },
9672
+ bottom: { ...grownBody, minY: body.minY - outside, maxY: body.minY + inside },
9673
+ top: { ...grownBody, minY: body.maxY - inside, maxY: body.maxY + outside }
9674
+ }[side];
9675
+ return clipped(padRect(pad), strip);
9676
+ }
9677
+ function terminal(pad, body, spec, color) {
9678
+ const side = sideOf(pad, body);
9679
+ const region = band(pad, body, side, spec.inside, spec.outside);
9680
+ const narrow = spec.across === void 0 ? region : narrowed(region, side, spec.across);
9681
+ return box(narrow.maxX > narrow.minX && narrow.maxY > narrow.minY ? narrow : padRect(pad), 0, spec.height, color, "metal", spec.role ?? "cap");
9682
+ }
9683
+ function narrowed(r, side, across) {
9684
+ const vertical = side === "left" || side === "right";
9685
+ const [mid, size] = vertical ? [(r.minY + r.maxY) / 2, r.maxY - r.minY] : [(r.minX + r.maxX) / 2, r.maxX - r.minX];
9686
+ const half = Math.min(size, across) / 2;
9687
+ return vertical ? { ...r, minY: mid - half, maxY: mid + half } : { ...r, minX: mid - half, maxX: mid + half };
9688
+ }
9689
+ function jLead(pad, side, body, spec, color) {
9690
+ const r = padRect(pad);
9691
+ const vertical = side === "left" || side === "right";
9692
+ const sign = side === "right" || side === "top" ? 1 : -1;
9693
+ const edge = side === "right" ? body.maxX : side === "left" ? body.minX : side === "top" ? body.maxY : body.minY;
9694
+ const [near, far, across, mid] = vertical ? [r.minX, r.maxX, r.maxY - r.minY, pad.y] : [r.minY, r.maxY, r.maxX - r.minX, pad.x];
9695
+ const padOut = sign > 0 ? far - edge : edge - near;
9696
+ const padIn = sign > 0 ? near - edge : edge - far;
9697
+ const outer = Math.min(spec.reach, padOut - spec.toe);
9698
+ if (outer < spec.thick) return [];
9699
+ const half = Math.min(across, spec.across) / 2;
9700
+ const strip = (a, b, z0, z1) => {
9701
+ const [lo, hi] = [Math.min(edge + sign * a, edge + sign * b), Math.max(edge + sign * a, edge + sign * b)];
9702
+ const rect2 = vertical ? { minX: lo, maxX: hi, minY: mid - half, maxY: mid + half } : { minY: lo, maxY: hi, minX: mid - half, maxX: mid + half };
9703
+ return box(rect2, z0, z1, color, "metal", "leg");
9704
+ };
9705
+ const foot = spec.thick;
9706
+ return [...strip(Math.max(-spec.tuck, padIn), outer, 0, foot), ...strip(outer - spec.thick, outer, foot, spec.rise - foot), ...strip(0, outer, spec.rise - foot, spec.rise)];
9707
+ }
9708
+ function clippedCorner(r, sx, sy, cut) {
9709
+ const corners = [
9710
+ { x: r.minX, y: r.minY, sx: -1, sy: -1 },
9711
+ { x: r.maxX, y: r.minY, sx: 1, sy: -1 },
9712
+ { x: r.maxX, y: r.maxY, sx: 1, sy: 1 },
9713
+ { x: r.minX, y: r.maxY, sx: -1, sy: 1 }
9714
+ ];
9715
+ return corners.flatMap((c, i) => {
9716
+ if (c.sx !== sx || c.sy !== sy) return [{ x: c.x, y: c.y }];
9717
+ const [before, after] = [corners[(i + 3) % 4], corners[(i + 1) % 4]];
9718
+ const toward = (to) => ({ x: c.x + Math.sign(to.x - c.x) * cut, y: c.y + Math.sign(to.y - c.y) * cut });
9719
+ return [toward(before), toward(after)];
9720
+ });
9721
+ }
9722
+
9723
+ // studio/src/look/parts/array.ts
9724
+ var STANDOFF3 = 0.03;
9725
+ var INSIDE = 0.12;
9726
+ var OUTSIDE = 0.1;
9727
+ var TERMINAL_SHARE = 0.7;
9728
+ function arrayShape(input) {
9729
+ const reach = padsRect(input.pads);
9730
+ const body = clipped(input.body ?? (reach ? grown3(reach, -0.1) : input.limit), input.limit);
9731
+ const h = input.height;
9732
+ const { look } = input;
9733
+ const band3 = bodyBand(h);
9734
+ const pieces = [...box(body, Math.min(STANDOFF3, band3.bottom), band3.top, { top: look.top ?? look.body, side: look.body }, "matt", "body")];
9735
+ for (const pad of input.pads) pieces.push(...terminal(pad, body, { inside: INSIDE, outside: OUTSIDE, height: h * TERMINAL_SHARE }, look.metal));
9736
+ return clipPieces(pieces, input.limit);
9737
+ }
9738
+
9739
+ // studio/src/look/parts/ledsmd.ts
9740
+ var STANDOFF4 = 0.04;
9741
+ var BODY_SHARE2 = 0.78;
9742
+ var LENS_SHARE = 0.36;
9743
+ var SIDES4 = 16;
9744
+ var DOME_STEPS2 = 4;
9745
+ var DOME_ANGLE = Math.PI / 3;
9746
+ var CLIP_SHARE = 0.12;
9747
+ var INSIDE2 = 0.25;
9748
+ var OUTSIDE2 = 0.2;
9749
+ var TERMINAL_HEIGHT = 0.3;
9750
+ function lens(cx, cy, radius, from, to, color) {
9751
+ const profile = Array.from({ length: DOME_STEPS2 + 1 }, (_, i) => {
9752
+ const angle = DOME_ANGLE * i / DOME_STEPS2;
9753
+ return [radius * Math.cos(angle), from + (to - from) * Math.sin(angle) / Math.sin(DOME_ANGLE)];
9754
+ });
9755
+ return lathe(profile, cx, cy, SIDES4, color, "matt", "body");
9756
+ }
9757
+ function ledSmdShape(input) {
9758
+ const reach = padsRect(input.pads);
9759
+ const body = clipped(input.body ?? (reach ? grown3(reach, -0.1) : input.limit), input.limit);
9760
+ const [width, depth] = [body.maxX - body.minX, body.maxY - body.minY];
9761
+ const h = input.height;
9762
+ const shoulder = h * BODY_SHARE2;
9763
+ const { look } = input;
9764
+ const one = firstPad(input.pads);
9765
+ const corner = input.pads.length >= 4 && one !== void 0 ? clippedCorner(body, one.x < 0 ? -1 : 1, one.y < 0 ? -1 : 1, Math.min(width, depth) * CLIP_SHARE) : void 0;
9766
+ const outline2 = corner ?? [{ x: body.minX, y: body.minY }, { x: body.maxX, y: body.minY }, { x: body.maxX, y: body.maxY }, { x: body.minX, y: body.maxY }];
9767
+ const pieces = [
9768
+ ...prism(outline2, Math.min(STANDOFF4, shoulder / 3), shoulder, look.body, "matt", "body"),
9769
+ ...lens((body.minX + body.maxX) / 2, (body.minY + body.maxY) / 2, Math.min(width, depth) * LENS_SHARE, shoulder, h, look.top ?? look.body)
9770
+ ];
9771
+ if (corner === void 0) {
9772
+ const cathode = input.pads.find((pad) => pad.number === "2");
9773
+ if (cathode !== void 0) {
9774
+ const side = cathode.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
9775
+ const edge = side > 0 ? body.maxX : body.minX;
9776
+ pieces.push(...box({ minX: Math.min(edge - side * width * 0.06, edge - side * width * 0.16), maxX: Math.max(edge - side * width * 0.06, edge - side * width * 0.16), minY: body.minY + depth * 0.15, maxY: body.maxY - depth * 0.15 }, shoulder, Math.min(shoulder + 0.02, h), look.mark, "matt", "cathode"));
9777
+ }
9778
+ }
9779
+ for (const pad of input.pads) pieces.push(...terminal(pad, body, { inside: INSIDE2, outside: OUTSIDE2, height: Math.min(TERMINAL_HEIGHT, shoulder / 2) }, look.metal));
9780
+ return clipPieces(pieces, input.limit);
9781
+ }
9782
+
9783
+ // studio/src/look/parts/melf.ts
9784
+ var SIDES5 = 16;
9785
+ var CAP_SHARE2 = 0.14;
9786
+ var CAP_LEAST = 0.3;
9787
+ var GLASS_SHARE = 0.93;
9788
+ var BAND_SHARE2 = 0.96;
9789
+ var ROOM_SHARE = 0.95;
9790
+ function round(radius, axisHeight) {
9791
+ return Array.from({ length: SIDES5 }, (_, i) => ({ x: radius * Math.cos(2 * Math.PI * i / SIDES5), y: axisHeight + radius * Math.sin(2 * Math.PI * i / SIDES5) }));
9792
+ }
9793
+ function melfShape(input) {
9794
+ const axis = twoPads(input);
9795
+ if (axis === void 0) return [];
9796
+ const flat = Math.abs(Math.sin(axis.angle * Math.PI / 180)) > 0.7;
9797
+ const room = flat ? Math.min(input.limit.maxX - axis.mid.x, axis.mid.x - input.limit.minX) : Math.min(input.limit.maxY - axis.mid.y, axis.mid.y - input.limit.minY);
9798
+ const radius = Math.min(input.height / 2, room * ROOM_SHARE);
9799
+ const half = axis.bodyAlong / 2;
9800
+ const cap = Math.max(axis.bodyAlong * CAP_SHARE2, CAP_LEAST);
9801
+ const band3 = Math.max(axis.bodyAlong * 0.14, 0.3);
9802
+ const { look } = input;
9803
+ const pieces = [
9804
+ ...lying(round(radius, radius), -half, -half + cap, look.metal, "metal", "cap"),
9805
+ ...lying(round(radius, radius), half - cap, half, look.metal, "metal", "cap"),
9806
+ ...lying(round(radius * GLASS_SHARE, radius), -half + cap, half - cap, look.body, "matt", "body"),
9807
+ ...lying(round(radius * BAND_SHARE2, radius), half - cap - band3, half - cap, look.mark, "matt", "cathode")
9808
+ ];
9809
+ return settle(pieces, axis, input);
9810
+ }
9811
+
9812
+ // studio/src/look/parts/plcc.ts
9813
+ var STANDOFF5 = 0.5;
9814
+ var STRIP = 0.2;
9815
+ var RISE_SHARE = 0.3;
9816
+ var RISE_MOST = 1.5;
9817
+ var TUCK = 0.9;
9818
+ var TOE = 0.3;
9819
+ var CLIP = 1.2;
9820
+ var DOT_RADIUS = 0.5;
9821
+ var DOT_INSET = 1.3;
9822
+ function plccShape(input) {
9823
+ const body = input.body ?? bodyRect(input);
9824
+ const h = input.height;
9825
+ const { top } = bodyBand(h);
9826
+ const standoff = Math.min(STANDOFF5, h * 0.2);
9827
+ const strip = Math.min(STRIP, h * 0.1);
9828
+ const { look } = input;
9829
+ const rise = Math.min(h * RISE_SHARE, RISE_MOST);
9830
+ const pieces = [...prism(clippedCorner(body, -1, 1, CLIP), standoff, top, look.body, "matt", "body")];
9831
+ for (const pad of input.pads) pieces.push(...jLead(pad, sideOf(pad, body), body, { reach: 0.6, toe: TOE, thick: strip, rise, tuck: TUCK, across: 0.5 }, look.metal));
9832
+ const one = firstPad(input.pads);
9833
+ if (one !== void 0) pieces.push(...prism(circle3(one.x, body.maxY - DOT_INSET, DOT_RADIUS, 14), top - 0.01, h, look.mark, "matt", "pin1"));
9834
+ return clipPieces(pieces, input.limit);
9835
+ }
9836
+
9837
+ // studio/src/look/parts/smdcan.ts
9838
+ var STANDOFF6 = 0.12;
9839
+ var BASE_SHARE = 0.15;
9840
+ var BASE_LEAST = 0.8;
9841
+ var BASE_MOST = 1.2;
9842
+ var BASE_CEILING = 0.4;
9843
+ var ROUND = 0.35;
9844
+ var ROUND_STEPS = 3;
9845
+ var LID_DROP = 0.02;
9846
+ var SIDES6 = 28;
9847
+ var SEGMENT_FROM = 0.45;
9848
+ var SEGMENT_SHARE = 0.92;
9849
+ var STRIP2 = 0.12;
9850
+ var REACH = 0.6;
9851
+ var TUCK2 = 0.8;
9852
+ function baseOutline(input, body) {
9853
+ const first = input.outlines?.[0];
9854
+ if (first === void 0 || first.length < 4) return [{ x: body.minX, y: body.minY }, { x: body.maxX, y: body.minY }, { x: body.maxX, y: body.maxY }, { x: body.minX, y: body.maxY }];
9855
+ const [a, z] = [first[0], first[first.length - 1]];
9856
+ return a.x === z.x && a.y === z.y ? first.slice(0, -1) : first;
9857
+ }
9858
+ function canRadius(input, body) {
9859
+ const circle4 = input.outlines?.find((line2, i) => i > 0 && line2.length > 16);
9860
+ const found = circle4 === void 0 ? void 0 : rectOf(circle4);
9861
+ return found === void 0 ? Math.min(body.maxX - body.minX, body.maxY - body.minY) / 2 - 0.15 : (found.maxX - found.minX) / 2;
9862
+ }
9863
+ function segment(radius, from) {
9864
+ const reach = Math.acos(Math.min(1, from / radius));
9865
+ const arc = Array.from({ length: 9 }, (_, i) => ({ x: radius * Math.cos(-reach + 2 * reach * i / 8), y: radius * Math.sin(-reach + 2 * reach * i / 8) }));
9866
+ return arc;
9867
+ }
9868
+ function smdCanShape(input) {
9869
+ const body = clipped(input.body ?? grown3(padsRect(input.pads) ?? input.limit, -0.1), input.limit);
9870
+ const h = input.height;
9871
+ const { look } = input;
9872
+ const baseTop = Math.min(BASE_MOST, Math.max(BASE_LEAST, h * BASE_SHARE), h * BASE_CEILING);
9873
+ const standoff = Math.min(STANDOFF6, baseTop / 3);
9874
+ const radius = canRadius(input, body);
9875
+ const lidZ = h - Math.min(LID_DROP, h * 0.1);
9876
+ const round2 = Math.min(ROUND, (lidZ - baseTop) / 2, radius / 2);
9877
+ const lidRadius = radius - round2;
9878
+ const edge = Array.from({ length: ROUND_STEPS + 1 }, (_, i) => {
9879
+ const angle = Math.PI / 2 * (i / ROUND_STEPS);
9880
+ return [lidRadius + round2 * Math.cos(angle), lidZ - round2 + round2 * Math.sin(angle)];
9881
+ });
9882
+ const profile = [[radius, baseTop], ...edge];
9883
+ const dark = segment(lidRadius * SEGMENT_SHARE, lidRadius * SEGMENT_SHARE * SEGMENT_FROM);
9884
+ const pieces = [
9885
+ ...prism(baseOutline(input, body), standoff, baseTop, look.body, "matt", "body"),
9886
+ ...lathe(profile, 0, 0, SIDES6, { top: look.top ?? look.metal, side: look.metal }, "metal", "body"),
9887
+ ...prism(dark, lidZ, h, look.mark, "matt", "cathode")
9888
+ ];
9889
+ const strip = Math.min(STRIP2, standoff);
9890
+ const rise = (standoff + baseTop) / 2 + strip / 2;
9891
+ for (const pad of input.pads) pieces.push(...jLead(pad, sideOf(pad, body), body, { reach: REACH, toe: 0.1, thick: strip, rise, tuck: TUCK2, across: 1.4 }, look.metal));
9892
+ return clipPieces(pieces, input.limit);
9893
+ }
9894
+
9895
+ // studio/src/look/parts/tantalum.ts
9896
+ var WRAP = 0.62;
9897
+ var THICK = 0.12;
9898
+ var TUCK3 = 0.8;
9899
+ var STRIPE_SHARE = 0.16;
9900
+ var STRIPE_LEAST = 0.3;
9901
+ function tantalumShape(input) {
9902
+ const axis = twoPads(input);
9903
+ if (axis === void 0) return [];
9904
+ const [half, across] = [axis.bodyAlong / 2, axis.bodyAcross / 2];
9905
+ const h = input.height;
9906
+ const { bottom: bottom2, top } = bodyBand(h);
9907
+ const { look } = input;
9908
+ const local = (minX, maxX, y) => ({ minX, maxX, minY: -y, maxY: y });
9909
+ const stripe = Math.max(axis.bodyAlong * STRIPE_SHARE, STRIPE_LEAST);
9910
+ const wide = Math.min(across, axis.padAcross / 2) * 0.9;
9911
+ const pieces = [
9912
+ ...box(local(-half, half, across), bottom2, top, look.body, "matt", "body"),
9913
+ ...box(local(-half + stripe * 0.5, -half + stripe * 1.5, across), top, h, look.mark, "matt", "pin1"),
9914
+ ...box(local(-half - THICK, -half + TUCK3, wide), 0, h * WRAP, look.metal, "metal", "cap"),
9915
+ ...box(local(half - TUCK3, half + THICK, wide), 0, h * WRAP, look.metal, "metal", "cap")
9916
+ ];
9917
+ return settle(pieces, axis, input);
9918
+ }
9919
+
9920
+ // studio/src/look/parts/xtal.ts
9921
+ var STANDOFF7 = 0.04;
9922
+ var TERMINAL_HEIGHT2 = 0.3;
9923
+ var LID_SHARE = 0.4;
9924
+ var LID_INSET = 0.08;
9925
+ var SEAT_SHARE = 0.24;
9926
+ var FOOT = 0.15;
9927
+ var CAN_MARGIN = 0.25;
9928
+ function ceramicShape(input, body) {
9929
+ const h = input.height;
9930
+ const { look } = input;
9931
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9932
+ const lid2 = grown3(body, -Math.min(small * LID_INSET, 0.2));
9933
+ const split = h * (1 - LID_SHARE);
9934
+ const pieces = [
9935
+ ...box(body, Math.min(STANDOFF7, split / 2), split, look.body, "matt", "body"),
9936
+ ...box(lid2, split, bodyBand(h).top, look.top ?? look.metal, "metal", "body"),
9937
+ ...pin1Dot(input, lid2, bodyBand(h).top)
9938
+ ];
9939
+ for (const pad of input.pads) pieces.push(...terminal(pad, body, { inside: 0.3, outside: 0.1, height: Math.min(TERMINAL_HEIGHT2, split * 0.8) }, look.metal));
9940
+ return pieces;
9941
+ }
9942
+ function canShape(input, body) {
9943
+ const h = input.height;
9944
+ const { look } = input;
9945
+ const [length2, width] = [body.maxX - body.minX, body.maxY - body.minY];
9946
+ const seatTop = Math.min(Math.max(h * SEAT_SHARE, 0.6), h / 2);
9947
+ const foot = Math.min(FOOT, seatTop / 3);
9948
+ const seat = grown3(body, -0.15);
9949
+ const pieces = [
9950
+ ...box(seat, foot, seatTop, look.mark, "matt", "body"),
9951
+ ...prism(stadium2((body.minX + body.maxX) / 2, (body.minY + body.maxY) / 2, length2 - 2 * CAN_MARGIN, width - 2 * CAN_MARGIN), seatTop, h, { top: look.top ?? look.body, side: look.body }, "metal", "body")
9952
+ ];
9953
+ for (const pad of input.pads) pieces.push(...box(clipped(grown3(padRect(pad), -0.1), input.limit), 0, foot, look.metal, "metal", "leg"));
9954
+ return pieces;
9955
+ }
9956
+ function xtalShape(input) {
9957
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9958
+ const pieces = input.parsed?.kind === "hc" ? canShape(input, body) : ceramicShape(input, body);
9959
+ return clipPieces(pieces, input.limit);
9960
+ }
9961
+
9962
+ // studio/src/look/parts/smd-shapes.ts
9963
+ var SMD_SHAPES = {
9964
+ melf: melfShape,
9965
+ tantalum: tantalumShape,
9966
+ array: arrayShape,
9967
+ smdcan: smdCanShape,
9968
+ xtal: xtalShape,
9969
+ ledsmd: ledSmdShape,
9970
+ plcc: plccShape
9971
+ };
9972
+
9973
+ // studio/src/look/parts/uno-kit.ts
9974
+ var mean = (values) => values.reduce((sum, v) => sum + v, 0) / (values.length || 1);
9975
+ function wallY(profile, y0, y1, color, material, role, facing = "out") {
9976
+ if (!(y1 > y0) || profile.length < 3) return [];
9977
+ const [cx, cz] = [mean(profile.map((p) => p.x)), mean(profile.map((p) => p.y))];
9978
+ const sign = facing === "out" ? 1 : -1;
9979
+ return profile.map((p, i) => {
9980
+ const q = profile[(i + 1) % profile.length];
9981
+ const outward = [sign * ((p.x + q.x) / 2 - cx), 0, sign * ((p.y + q.y) / 2 - cz)];
9982
+ return facet([[p.x, y0, p.y], [q.x, y0, q.y], [q.x, y1, q.y], [p.x, y1, p.y]], outward, color, material, role);
9983
+ });
9984
+ }
9985
+ var capY = (profile, y, toward, color, material, role) => facet(profile.map((p) => [p.x, y, p.y]), [0, toward, 0], color, material, role);
9986
+ function ringY(outer, inner, y, toward, color, material, role) {
9987
+ if (outer.length !== inner.length) return [];
9988
+ return outer.map((p, i) => {
9989
+ const j = (i + 1) % outer.length;
9990
+ const [q, a, b] = [outer[j], inner[i], inner[j]];
9991
+ return facet([[p.x, y, p.y], [q.x, y, q.y], [b.x, y, b.y], [a.x, y, a.y]], [0, toward, 0], color, material, role);
9992
+ });
9993
+ }
9994
+ var frontRect = (x0, x1, z0, z1, y, toward, color, material, role) => x1 > x0 && z1 > z0 ? [facet([[x0, y, z0], [x1, y, z0], [x1, y, z1], [x0, y, z1]], [0, toward, 0], color, material, role)] : [];
9995
+ function openBox(rect2, y0, y1, z0, z1, color, material, role) {
9996
+ if (!(y1 > y0) || !(rect2.maxX > rect2.minX) || !(z1 > z0)) return [];
9997
+ const plate = (xa, xb, ya, yb, z, up) => facet([[xa, ya, z], [xb, ya, z], [xb, yb, z], [xa, yb, z]], [0, 0, up], color, material, role);
9998
+ const side = (x, out) => facet([[x, y0, z0], [x, y1, z0], [x, y1, z1], [x, y0, z1]], [out, 0, 0], color, material, role);
9999
+ return [plate(rect2.minX, rect2.maxX, y0, y1, z1, 1), plate(rect2.minX, rect2.maxX, y0, y1, z0, -1), side(rect2.minX, -1), side(rect2.maxX, 1), ...frontRect(rect2.minX, rect2.maxX, z0, z1, y0, -1, color, material, role)];
10000
+ }
10001
+ var SLOT_FILL = 0.8;
10002
+ function stripLeads(input, pick, color, half) {
10003
+ const chosen = input.pads.filter(pick);
10004
+ return chosen.flatMap((pad) => {
10005
+ const size = half ?? { x: (pad.drill?.width ?? 0.6) * SLOT_FILL / 2, y: (pad.drill?.height ?? 0.6) * SLOT_FILL / 2 };
10006
+ return leads({ ...input, pads: [pad] }, color, size);
10007
+ });
10008
+ }
10009
+ var TUCK4 = 0.12;
10010
+ function foldedTerminal(pad, body, spec, color, role = "leg") {
10011
+ const r = padRect(pad);
10012
+ const sign = pad.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
10013
+ const edge = sign > 0 ? body.maxX : body.minX;
10014
+ const outer = sign > 0 ? r.maxX : r.minX;
10015
+ const reach = Math.min(spec.reach, Math.abs(outer - edge));
10016
+ if (reach < spec.thick) return [];
10017
+ const half = Math.min(r.maxY - r.minY, spec.across) / 2;
10018
+ const [near, far] = [edge - sign * TUCK4, edge + sign * reach];
10019
+ const span = (a, b) => ({ minX: Math.min(a, b), maxX: Math.max(a, b), minY: pad.y - half, maxY: pad.y + half });
10020
+ const foot = box(span(near, far), 0, spec.thick, color, "metal", role);
10021
+ const riser = box(span(edge, edge + sign * spec.thick), spec.thick, spec.rise, color, "metal", role);
10022
+ return [...foot, ...riser];
10023
+ }
10024
+
10025
+ // studio/src/look/parts/dcjack.ts
10026
+ var SIDES7 = 16;
10027
+ var PIN_SIDES = 12;
10028
+ var RADIUS = 3.2;
10029
+ var RADIUS_WIDTH_SHARE = 0.36;
10030
+ var RADIUS_HEIGHT_SHARE = 0.3;
10031
+ var CAVITY_DEPTH = 9;
10032
+ var DEPTH_SHARE2 = 0.62;
10033
+ var PIN_SHARE = 0.31;
10034
+ var PIN_LENGTH = 6.5;
10035
+ var PIN_LENGTH_SHARE = 0.72;
10036
+ var FOLD = 3;
10037
+ var FOLD_SHARE = 0.3;
10038
+ function face(x0, x1, y, h, cx, cz, radius, color) {
10039
+ const ring4 = Array.from({ length: SIDES7 }, (_, i) => [cx + radius * Math.cos(2 * Math.PI * i / SIDES7), y, cz + radius * Math.sin(2 * Math.PI * i / SIDES7)]);
10040
+ return { loops: [[[x0, y, 0], [x1, y, 0], [x1, y, h], [x0, y, h]], [...ring4].reverse()], normal: [0, -1, 0], color, material: "matt", role: "body" };
10041
+ }
10042
+ function dcJackShape(input) {
10043
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10044
+ const { look } = input;
10045
+ const h = input.height;
10046
+ const cx = (body.minX + body.maxX) / 2;
10047
+ const radius = Math.min(RADIUS, (body.maxX - body.minX) * RADIUS_WIDTH_SHARE, h * RADIUS_HEIGHT_SHARE);
10048
+ const back = body.minY + Math.min(CAVITY_DEPTH, (body.maxY - body.minY) * DEPTH_SHARE2);
10049
+ const opening2 = circle3(cx, h / 2, radius, SIDES7);
10050
+ const pin = circle3(cx, h / 2, radius * PIN_SHARE, PIN_SIDES);
10051
+ const tip = back - Math.min(PIN_LENGTH, (back - body.minY) * PIN_LENGTH_SHARE);
10052
+ const sides = prism(rectPolygon(body), 0, h, look.body, "matt", "body").filter((piece) => piece.normal[1] > -0.99);
10053
+ const pieces = [
10054
+ ...sides,
10055
+ face(body.minX, body.maxX, body.minY, h, cx, h / 2, radius, look.body),
10056
+ ...wallY(opening2, body.minY, back, look.mark, "matt", "body", "in"),
10057
+ capY(opening2, back, -1, look.mark, "matt", "body"),
10058
+ ...wallY(pin, tip, back, look.metal, "metal", "pin"),
10059
+ capY(pin, tip, -1, look.metal, "metal", "pin")
10060
+ ];
10061
+ for (const pad of input.pads) {
10062
+ const half = { x: (pad.drill?.width ?? 0.6) * 0.8 / 2, y: (pad.drill?.height ?? 0.6) * 0.8 / 2 };
10063
+ const [lo, hi] = [pad.x - half.x, pad.x + half.x];
10064
+ if (hi > body.maxX) pieces.push(...box({ minX: body.maxX, maxX: hi, minY: pad.y - half.y, maxY: pad.y + half.y }, 0, Math.min(FOLD, h * FOLD_SHARE), look.metal, "metal", "leg"));
10065
+ if (lo < body.minX) pieces.push(...box({ minX: lo, maxX: body.minX, minY: pad.y - half.y, maxY: pad.y + half.y }, 0, Math.min(FOLD, h * FOLD_SHARE), look.metal, "metal", "leg"));
10066
+ }
10067
+ return [...pieces, ...stripLeads(input, () => true, look.metal)];
10068
+ }
10069
+
10070
+ // studio/src/look/parts/inductor.ts
10071
+ var STANDOFF8 = 0.08;
10072
+ var STANDOFF_SHARE = 0.05;
10073
+ var MARK_RISE = 0.04;
10074
+ var MARK_SHARE = 0.03;
10075
+ var CLIP_SHARE2 = 0.1;
10076
+ var CLIP_MOST = 0.8;
10077
+ var MARK_RADIUS_SHARE = 0.05;
10078
+ var MARK_RADIUS_LEAST = 0.18;
10079
+ var MARK_INSET_SHARE = 0.22;
10080
+ var MARK_SIDES = 12;
10081
+ var FOOT2 = 0.15;
10082
+ var FOOT_SHARE = 0.2;
10083
+ var RISE = 0.9;
10084
+ var RISE_SHARE2 = 0.5;
10085
+ var ACROSS_SHARE = 0.8;
10086
+ var TERMINAL_REACH = 3;
10087
+ function clippedRect(r, cut) {
10088
+ return [
10089
+ { x: r.minX + cut, y: r.minY },
10090
+ { x: r.maxX - cut, y: r.minY },
10091
+ { x: r.maxX, y: r.minY + cut },
10092
+ { x: r.maxX, y: r.maxY - cut },
10093
+ { x: r.maxX - cut, y: r.maxY },
10094
+ { x: r.minX + cut, y: r.maxY },
10095
+ { x: r.minX, y: r.maxY - cut },
10096
+ { x: r.minX, y: r.minY + cut }
10097
+ ];
10098
+ }
10099
+ function inductorShape(input) {
10100
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10101
+ const { look } = input;
10102
+ const h = input.height;
10103
+ const side = Math.min(body.maxX - body.minX, body.maxY - body.minY);
10104
+ const rise = Math.min(MARK_RISE, h * MARK_SHARE);
10105
+ const one = firstPad(input.pads);
10106
+ const left = one === void 0 || one.x <= (body.minX + body.maxX) / 2;
10107
+ const inset = side * MARK_INSET_SHARE;
10108
+ const mark2 = circle3(left ? body.minX + inset : body.maxX - inset, body.maxY - inset, Math.max(side * MARK_RADIUS_SHARE, MARK_RADIUS_LEAST), MARK_SIDES);
10109
+ const fold = { reach: TERMINAL_REACH, thick: Math.min(FOOT2, h * FOOT_SHARE), rise: Math.min(RISE, h * RISE_SHARE2), across: side * ACROSS_SHARE };
10110
+ const pieces = [
10111
+ ...prism(clippedRect(body, Math.min(side * CLIP_SHARE2, CLIP_MOST)), Math.min(STANDOFF8, h * STANDOFF_SHARE), h - rise, { top: look.top ?? look.body, side: look.body }, "matt", "body"),
10112
+ ...prism(mark2, h - rise, h, look.mark, "matt", "pin1")
10113
+ ];
10114
+ for (const pad of input.pads) pieces.push(...foldedTerminal(pad, body, fold, look.metal));
10115
+ return pieces;
10116
+ }
10117
+
10118
+ // studio/src/look/parts/resonator.ts
10119
+ var STANDOFF9 = 0.04;
10120
+ var STANDOFF_SHARE2 = 0.05;
10121
+ var CERAMIC_SHARE = 0.62;
10122
+ var CAP_INSET2 = 0.1;
10123
+ var CAP_INSET_SHARE2 = 0.1;
10124
+ var TERMINAL_HALF = 0.18;
10125
+ var TUCK5 = 0.05;
10126
+ var OUT = 0.12;
10127
+ var TERMINAL_HEIGHT3 = 0.45;
10128
+ var TERMINAL_SHARE2 = 0.8;
10129
+ function resonatorShape(input) {
10130
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10131
+ const { look } = input;
10132
+ const h = input.height;
10133
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
10134
+ const split = h * CERAMIC_SHARE;
10135
+ const cap = grown3(body, -Math.min(CAP_INSET2, small * CAP_INSET_SHARE2));
10136
+ const pieces = [
10137
+ ...box(body, Math.min(STANDOFF9, h * STANDOFF_SHARE2), split, look.body, "matt", "body"),
10138
+ ...box(cap, split, h, look.metal, "metal", "cap")
10139
+ ];
10140
+ for (const pad of input.pads) {
10141
+ const r = padRect(pad);
10142
+ const x = { minX: Math.max(r.minX, pad.x - TERMINAL_HALF), maxX: Math.min(r.maxX, pad.x + TERMINAL_HALF) };
10143
+ const height = Math.min(TERMINAL_HEIGHT3, split * TERMINAL_SHARE2);
10144
+ const top = { ...x, minY: Math.max(r.minY, body.maxY - TUCK5), maxY: Math.min(r.maxY, body.maxY + OUT) };
10145
+ const bottom2 = { ...x, minY: Math.max(r.minY, body.minY - OUT), maxY: Math.min(r.maxY, body.minY + TUCK5) };
10146
+ pieces.push(...box(top, 0, height, look.metal, "metal", "leg"), ...box(bottom2, 0, height, look.metal, "metal", "leg"));
10147
+ }
10148
+ return pieces;
10149
+ }
10150
+
10151
+ // studio/src/look/parts/tact.ts
10152
+ var BASE_SHARE2 = 0.7;
10153
+ var COVER = 0.3;
10154
+ var COVER_SHARE = 0.07;
10155
+ var COVER_INSET = 0.25;
10156
+ var COVER_INSET_SHARE = 0.04;
10157
+ var BUTTON = 1.7;
10158
+ var BUTTON_SHARE = 0.28;
10159
+ var BUTTON_SIDES = 16;
10160
+ var PIN_HALF2 = { x: 0.25, y: 0.25 };
10161
+ var STRIP3 = { reach: 0.5, thick: 0.15, rise: 0.6, across: 0.9 };
10162
+ var WING = { reach: 1.2, thick: 0.15, rise: 1, across: 0.9 };
10163
+ var THICK_SHARE = 0.1;
10164
+ var RISE_SHARE3 = 0.6;
10165
+ function tactShape(input) {
10166
+ const base = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10167
+ const { look } = input;
10168
+ const h = input.height;
10169
+ const small = Math.min(base.maxX - base.minX, base.maxY - base.minY);
10170
+ const baseTop = h * BASE_SHARE2;
10171
+ const coverTop = baseTop + Math.min(COVER, h * COVER_SHARE);
10172
+ const cover = grown3(base, -Math.min(COVER_INSET, small * COVER_INSET_SHARE));
10173
+ const [cx, cy] = [(base.minX + base.maxX) / 2, (base.minY + base.maxY) / 2];
10174
+ const button = prism(circle3(cx, cy, Math.min(BUTTON, small * BUTTON_SHARE), BUTTON_SIDES), coverTop, h, { top: look.top ?? look.body, side: look.body }, "matt", "pin");
10175
+ const surface = input.parsed?.params["smd"] === true;
10176
+ const spec = surface ? WING : STRIP3;
10177
+ const fold = { ...spec, thick: Math.min(spec.thick, h * THICK_SHARE), rise: Math.min(spec.rise, baseTop * RISE_SHARE3) };
10178
+ const pieces = [
10179
+ ...box(base, 0, baseTop, look.body, "matt", "body"),
10180
+ ...box(cover, baseTop, coverTop, look.metal, "metal", "cap"),
10181
+ ...button
10182
+ ];
10183
+ for (const pad of input.pads) pieces.push(...foldedTerminal(pad, base, fold, look.metal));
10184
+ return surface ? pieces : [...pieces, ...leads(input, look.metal, PIN_HALF2)];
10185
+ }
10186
+
10187
+ // studio/src/look/parts/usbb.ts
10188
+ var OPENING = { across: 8.4, up: 7.8 };
10189
+ var ACROSS_SHARE2 = 0.7;
10190
+ var UP_SHARE = 0.72;
10191
+ var CAVITY_DEPTH2 = 9;
10192
+ var DEPTH_SHARE3 = 0.55;
10193
+ var TONGUE = { across: 6.2, length: 6, thick: 1.5 };
10194
+ var TONGUE_ACROSS_SHARE = 0.74;
10195
+ var TONGUE_LENGTH_SHARE = 0.7;
10196
+ var TONGUE_THICK_SHARE = 0.2;
10197
+ var SHELL_HOLE = 1.5;
10198
+ var LEG_HALF = { x: 0.2, y: 0.9 };
10199
+ function usbBShape(input) {
10200
+ const shell = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10201
+ const { look } = input;
10202
+ const h = input.height;
10203
+ const mid = (shell.minX + shell.maxX) / 2;
10204
+ const [across, up] = [Math.min(OPENING.across, (shell.maxX - shell.minX) * ACROSS_SHARE2), Math.min(OPENING.up, h * UP_SHARE)];
10205
+ const [x0, x1, z0, z1] = [mid - across / 2, mid + across / 2, (h - up) / 2, (h + up) / 2];
10206
+ const back = shell.minY + Math.min(CAVITY_DEPTH2, (shell.maxY - shell.minY) * DEPTH_SHARE3);
10207
+ const room = [{ x: x0, y: z0 }, { x: x1, y: z0 }, { x: x1, y: z1 }, { x: x0, y: z1 }];
10208
+ const tongue = { minX: mid - Math.min(TONGUE.across, across * TONGUE_ACROSS_SHARE) / 2, maxX: mid + Math.min(TONGUE.across, across * TONGUE_ACROSS_SHARE) / 2 };
10209
+ const thick = Math.min(TONGUE.thick, up * TONGUE_THICK_SHARE);
10210
+ const sides = prism(rectPolygon(shell), 0, h, look.metal, "metal", "body").filter((piece) => piece.normal[1] > -0.99);
10211
+ const front = [
10212
+ ...frontRect(shell.minX, x0, 0, h, shell.minY, -1, look.metal, "metal", "body"),
10213
+ ...frontRect(x1, shell.maxX, 0, h, shell.minY, -1, look.metal, "metal", "body"),
10214
+ ...frontRect(x0, x1, 0, z0, shell.minY, -1, look.metal, "metal", "body"),
10215
+ ...frontRect(x0, x1, z1, h, shell.minY, -1, look.metal, "metal", "body")
10216
+ ];
10217
+ const cavity = [...wallY(room, shell.minY, back, look.mark, "matt", "body", "in"), capY(room, back, -1, look.mark, "matt", "body")];
10218
+ const plate = openBox(tongue, back - Math.min(TONGUE.length, (back - shell.minY) * TONGUE_LENGTH_SHARE), back, (h - thick) / 2, (h + thick) / 2, look.body, "matt", "body");
10219
+ const signal = leads({ ...input, pads: input.pads.filter((pad) => (pad.drill?.width ?? 0) <= SHELL_HOLE) }, look.metal);
10220
+ return [...sides, ...front, ...cavity, ...plate, ...signal, ...stripLeads(input, (pad) => (pad.drill?.width ?? 0) > SHELL_HOLE, look.metal, LEG_HALF)];
10221
+ }
10222
+
10223
+ // studio/src/look/parts/usbc.ts
10224
+ var STEPS = 8;
10225
+ var ROUND_LIMIT = 0.9;
10226
+ var WALL = 0.35;
10227
+ var WALL_SHARE = 0.12;
10228
+ var REAR_INSET = 0.15;
10229
+ var REAR_INSET_SHARE = 0.1;
10230
+ var REAR_DEPTH = 1.6;
10231
+ var REAR_SHARE = 0.22;
10232
+ var CAVITY_DEPTH3 = 5;
10233
+ var CAVITY_STOP = 0.4;
10234
+ var TONGUE2 = { length: 4.6, shorter: 0.6, thick: 0.6 };
10235
+ var TONGUE_THICK_SHARE2 = 0.28;
10236
+ var TERMINAL2 = 0.45;
10237
+ var TERMINAL_SHARE3 = 0.5;
10238
+ var TAB = 1.6;
10239
+ var TAB_SHARE = 0.5;
10240
+ function usbCShape(input) {
10241
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10242
+ const { look } = input;
10243
+ const h = input.height;
10244
+ const [mid, length2] = [(body.minX + body.maxX) / 2, body.maxX - body.minX];
10245
+ const wall = Math.min(WALL, h * WALL_SHARE);
10246
+ const inset = Math.min(REAR_INSET, h * REAR_INSET_SHARE);
10247
+ const rear = body.maxY - Math.min(REAR_DEPTH, (body.maxY - body.minY) * REAR_SHARE);
10248
+ const back = Math.min(body.minY + CAVITY_DEPTH3, rear - CAVITY_STOP);
10249
+ const tall = Math.min(h, length2 * ROUND_LIMIT);
10250
+ const outer = stadium2(mid, h / 2, length2, tall, STEPS);
10251
+ const opening2 = stadium2(mid, h / 2, length2 - 2 * wall, tall - 2 * wall, STEPS);
10252
+ const block = stadium2(mid, h / 2, length2 - 2 * inset, tall - 2 * inset, STEPS);
10253
+ const room = { minX: mid - Math.min(length2 / 2 - wall - 0.6, 3.4), maxX: mid + Math.min(length2 / 2 - wall - 0.6, 3.4) };
10254
+ const thick = (tall - 2 * wall) * TONGUE_THICK_SHARE2;
10255
+ const pieces = [
10256
+ ...wallY(outer, body.minY, rear, look.metal, "metal", "body"),
10257
+ capY(outer, rear, 1, look.metal, "metal", "body"),
10258
+ ...ringY(outer, opening2, body.minY, -1, look.metal, "metal", "body"),
10259
+ ...wallY(opening2, body.minY, back, look.mark, "matt", "body", "in"),
10260
+ capY(opening2, back, -1, look.mark, "matt", "body"),
10261
+ ...openBox(room, back - Math.min(TONGUE2.length, back - body.minY - TONGUE2.shorter), back, (h - Math.min(TONGUE2.thick, thick)) / 2, (h + Math.min(TONGUE2.thick, thick)) / 2, look.body, "matt", "body"),
10262
+ ...wallY(block, rear, body.maxY, look.mark, "matt", "body"),
10263
+ capY(block, body.maxY, 1, look.mark, "matt", "body")
10264
+ ];
10265
+ const through2 = (pad) => pad.layers === "through";
10266
+ for (const pad of input.pads.filter((one) => !through2(one))) pieces.push(...box(padRect(pad), 0, Math.min(TERMINAL2, h * TERMINAL_SHARE3), look.metal, "metal", "leg"));
10267
+ for (const pad of input.pads.filter(through2)) {
10268
+ const half = { x: (pad.drill?.width ?? 0.6) * 0.8 / 2, y: (pad.drill?.height ?? 0.6) * 0.8 / 2 };
10269
+ pieces.push(...box(clipped({ minX: pad.x - half.x, maxX: pad.x + half.x, minY: pad.y - half.y, maxY: pad.y + half.y }, body), 0, Math.min(TAB, h * TAB_SHARE), look.metal, "metal", "leg"));
10270
+ }
10271
+ return [...pieces, ...stripLeads(input, through2, look.metal)];
10272
+ }
10273
+
10274
+ // studio/src/look/parts/uno-shapes.ts
10275
+ var UNO_SHAPES = {
10276
+ usbb: usbBShape,
10277
+ usbc: usbCShape,
10278
+ dcjack: dcJackShape,
10279
+ tact: tactShape,
10280
+ resonator: resonatorShape,
10281
+ inductor: inductorShape
10282
+ };
10283
+
10284
+ // studio/src/look/parts/tab.ts
10285
+ var MIN_REACH = 0.15;
10286
+ var FOOT3 = 0.15;
10287
+ var area = (pad) => pad.width * pad.height;
10288
+ function tabSide(pad, body) {
10289
+ const [cx, cy] = [(body.minX + body.maxX) / 2, (body.minY + body.maxY) / 2];
10290
+ const [dx, dy] = [(pad.x - cx) / ((body.maxX - body.minX) / 2), (pad.y - cy) / ((body.maxY - body.minY) / 2)];
10291
+ if (Math.abs(dy) >= Math.abs(dx)) return dy >= 0 ? "top" : "bottom";
10292
+ return dx >= 0 ? "right" : "left";
10293
+ }
10294
+ function tab(pad, body, height, color) {
10295
+ const r = padRect(pad);
10296
+ const side = tabSide(pad, body);
10297
+ const vertical = side === "top" || side === "bottom";
10298
+ const across = vertical ? r.maxX - r.minX : r.maxY - r.minY;
10299
+ const outside = {
10300
+ minX: side === "right" ? Math.max(r.minX, body.maxX) : r.minX,
10301
+ maxX: side === "left" ? Math.min(r.maxX, body.minX) : r.maxX,
10302
+ minY: side === "top" ? Math.max(r.minY, body.maxY) : r.minY,
10303
+ maxY: side === "bottom" ? Math.min(r.maxY, body.minY) : r.maxY
10304
+ };
10305
+ const reach = vertical ? outside.maxY - outside.minY : outside.maxX - outside.minX;
10306
+ if (reach < MIN_REACH) return box(r, 0, Math.min(FOOT3, height / 3), color, "metal", "leg");
10307
+ const outer = { ...pad, x: (outside.minX + outside.maxX) / 2, y: (outside.minY + outside.maxY) / 2, width: outside.maxX - outside.minX, height: outside.maxY - outside.minY, rotation: 0 };
10308
+ return leg(outer, side, body, height, color, across);
10309
+ }
10310
+ function tabShape(input) {
10311
+ const wide = input.pads.reduce((best, pad) => best === void 0 || area(pad) > area(best) ? pad : best, void 0);
10312
+ const narrow = input.pads.filter((pad) => pad !== wide);
10313
+ const outline2 = input.outlines !== void 0 && input.outlines.length > 1 ? rectOf(input.outlines[0]) : input.body;
10314
+ const body = outline2 ? clipped(outline2, input.limit) : bodyRect({ ...input, pads: narrow });
10315
+ const h = input.height;
10316
+ const { bottom: bottom2, top } = bodyBand(h);
10317
+ const { look } = input;
10318
+ const pieces = [...box(body, bottom2, top, look.body, "matt", "body")];
10319
+ for (const pad of narrow) pieces.push(...leg(pad, padSide(pad), body, h, look.metal));
10320
+ if (wide !== void 0) pieces.push(...tab(wide, body, h, look.metal));
10321
+ pieces.push(...pin1Dot(input, body, top));
10322
+ return clipPieces(pieces, input.limit);
10323
+ }
10324
+
10325
+ // studio/src/look/parts/to220.ts
10326
+ var BODY_SHARE3 = 0.85;
10327
+ var PLASTIC_SHARE = 0.62;
10328
+ var TAB_SHARE2 = 0.28;
10329
+ var HOLE_SHARE = 0.3;
10330
+ var HOLE_SIDES = 14;
10331
+ var PLASTIC_HOLE_FROM = 0.55;
10332
+ var SPECS = {
10333
+ "220": { rise: 16, hole: 1.9, plastic: false, lead: { x: 0.4, y: 0.25 } },
10334
+ "247": { rise: 21, hole: 2.2, plastic: false, lead: { x: 0.6, y: 0.3 } },
10335
+ "126": { rise: 10.8, hole: 1.5, plastic: true, lead: { x: 0.4, y: 0.25 } }
10336
+ };
10337
+ var holeRing = (cx, hole, y) => Array.from({ length: HOLE_SIDES }, (_, i) => [cx + hole.radius * Math.cos(2 * Math.PI * i / HOLE_SIDES), y, hole.z + hole.radius * Math.sin(2 * Math.PI * i / HOLE_SIDES)]);
10338
+ function holeWall(cx, hole, frontY, backY, color, material) {
10339
+ const [front, back] = [holeRing(cx, hole, frontY), holeRing(cx, hole, backY)];
10340
+ return front.map((f0, i) => {
10341
+ const j = (i + 1) % HOLE_SIDES;
10342
+ const [f1, b0, b1] = [front[j], back[i], back[j]];
10343
+ const towards = [-((f0[0] + f1[0]) / 2 - cx), 0, -((f0[2] + f1[2]) / 2 - hole.z)];
10344
+ return facet([f0, b0, b1, f1], towards, color, material, "body");
10345
+ });
10346
+ }
10347
+ function tabFaces(slab, zFoot, zPlastic, top, hole, color, material = "metal") {
10348
+ const cx = (slab.minX + slab.maxX) / 2;
10349
+ const [frontY, backY] = [slab.minY, slab.maxY];
10350
+ const front = {
10351
+ loops: [[[slab.minX, frontY, zPlastic], [slab.maxX, frontY, zPlastic], [slab.maxX, frontY, top], [slab.minX, frontY, top]], [...holeRing(cx, hole, frontY)].reverse()],
10352
+ normal: [0, -1, 0],
10353
+ color,
10354
+ material,
10355
+ role: "body"
10356
+ };
10357
+ const mirrored = holeRing(cx, hole, backY).map((p) => [2 * cx - p[0], p[1], p[2]]);
10358
+ const back = {
10359
+ loops: [[[slab.maxX, backY, zFoot], [slab.minX, backY, zFoot], [slab.minX, backY, top], [slab.maxX, backY, top]], [...mirrored].reverse()],
10360
+ normal: [0, 1, 0],
10361
+ color,
10362
+ material,
10363
+ role: "body"
10364
+ };
10365
+ return [front, back, ...holeWall(cx, hole, frontY, backY, color, material)];
10366
+ }
10367
+ function plasticBody(outline2, foot, h, spec, color) {
10368
+ const below = foot + (h - foot) * PLASTIC_HOLE_FROM;
10369
+ const hole = Math.min(spec.hole, (h - below) * HOLE_SHARE, (outline2.maxX - outline2.minX) / 2 - 0.2);
10370
+ const upper = (below + h) / 2;
10371
+ const front = box(outline2, foot, below, color, "matt", "body").filter((piece) => piece.normal[1] < -0.5);
10372
+ const sides = prism(rectPolygon(outline2), foot, h, color, "matt", "body").filter((piece) => Math.abs(piece.normal[1]) < 0.5);
10373
+ return [...front, ...sides, ...tabFaces(outline2, foot, below, h, { z: upper, radius: hole }, color, "matt")];
10374
+ }
10375
+ function to220Shape(input) {
10376
+ const outline2 = clipped(input.body ?? grown3(input.limit, -0.2), input.limit);
10377
+ const { look } = input;
10378
+ const spec = SPECS[input.parsed?.code ?? "220"] ?? SPECS["220"];
10379
+ const h = input.height;
10380
+ const rise = Math.min(spec.rise, h * BODY_SHARE3);
10381
+ const foot = h - rise;
10382
+ const pieces = spec.plastic ? plasticBody(outline2, foot, h, spec, look.body) : tabbedBody(outline2, foot, h, rise, spec, look);
10383
+ for (const pad of input.pads) {
10384
+ const strip = { minX: pad.x - spec.lead.x, maxX: pad.x + spec.lead.x, minY: pad.y - spec.lead.y, maxY: pad.y + spec.lead.y };
10385
+ pieces.push(...box(strip, 0, foot, look.metal, "metal", "leg"));
10386
+ }
10387
+ return [...pieces, ...leads(input, look.metal, spec.lead)];
10388
+ }
10389
+ function tabbedBody(outline2, foot, h, rise, spec, look) {
10390
+ const plasticTop = foot + rise * PLASTIC_SHARE;
10391
+ const frontY = outline2.maxY - (outline2.maxY - outline2.minY) * TAB_SHARE2;
10392
+ const radius = Math.min(spec.hole, (h - plasticTop) * HOLE_SHARE, (outline2.maxX - outline2.minX) / 2 - 0.2);
10393
+ const slab = { minX: outline2.minX, maxX: outline2.maxX, minY: frontY, maxY: outline2.maxY };
10394
+ const sides = prism(rectPolygon(slab), foot, h, look.metal, "metal", "body").filter((piece) => Math.abs(piece.normal[1]) < 0.5);
10395
+ return [
10396
+ ...box({ ...outline2, maxY: frontY }, foot, plasticTop, look.body, "matt", "body"),
10397
+ ...sides,
10398
+ ...tabFaces(slab, foot, plasticTop, h, { z: (plasticTop + h) / 2, radius }, look.metal)
10399
+ ];
10400
+ }
10401
+
10402
+ // studio/src/look/parts/to92.ts
10403
+ var STANDOFF10 = 0.7;
10404
+ var STANDOFF_SHARE3 = 0.2;
10405
+ var SHOULDER = 0.35;
10406
+ var SHOULDER_HEIGHT = 0.6;
10407
+ var ARC_STEPS = 14;
10408
+ var LEAD_HALF2 = { x: 0.22, y: 0.2 };
10409
+ function dShape(r) {
10410
+ const radius = (r.maxX - r.minX) / 2;
10411
+ const [cx, cy] = [(r.minX + r.maxX) / 2, r.maxY - radius];
10412
+ const point = (angle) => ({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });
10413
+ if (r.minY < cy - radius) {
10414
+ const back = Array.from({ length: ARC_STEPS + 1 }, (_, i) => point(Math.PI * i / ARC_STEPS));
10415
+ return [...back, { x: cx - radius, y: r.minY }, { x: cx + radius, y: r.minY }];
10416
+ }
10417
+ const start = Math.asin(Math.max(-1, Math.min(1, (r.minY - cy) / radius)));
10418
+ const sweep = Math.PI - 2 * start;
10419
+ const closed = sweep >= 2 * Math.PI - 1e-9;
10420
+ return Array.from({ length: closed ? ARC_STEPS : ARC_STEPS + 1 }, (_, i) => point(start + sweep * i / ARC_STEPS));
10421
+ }
10422
+ function to92Shape(input) {
10423
+ const outline2 = clipped(input.body ?? grown3(input.limit, -0.2), input.limit);
10424
+ const { look } = input;
10425
+ const h = input.height;
10426
+ const foot = Math.min(STANDOFF10, h * STANDOFF_SHARE3);
10427
+ const shoulder = Math.max(foot + 0.1, h - SHOULDER_HEIGHT);
10428
+ const pieces = [
10429
+ ...prism(dShape(outline2), foot, shoulder, look.body, "matt", "body"),
10430
+ ...prism(dShape(grown3(outline2, -SHOULDER)), shoulder, h, look.body, "matt", "body")
10431
+ ];
10432
+ for (const pad of input.pads) {
10433
+ const strip = { minX: pad.x - LEAD_HALF2.x, maxX: pad.x + LEAD_HALF2.x, minY: pad.y - LEAD_HALF2.y, maxY: pad.y + LEAD_HALF2.y };
10434
+ pieces.push(...box(strip, 0, foot + 0.3, look.metal, "metal", "leg"));
10435
+ }
10436
+ return [...pieces, ...leads(input, look.metal, LEAD_HALF2)];
10437
+ }
10438
+
8788
10439
  // studio/src/look/parts/index.ts
8789
10440
  var SHAPES = {
8790
10441
  chip: chipShape,
@@ -8795,28 +10446,39 @@ var SHAPES = {
8795
10446
  crystal: crystalShape,
8796
10447
  electrolytic: electrolyticShape,
8797
10448
  block: blockShape,
8798
- box: plainBox
10449
+ box: plainBox,
10450
+ bga: bgaShape,
10451
+ dip: dipShape,
10452
+ to220: to220Shape,
10453
+ to92: to92Shape,
10454
+ tab: tabShape,
10455
+ axial: axialShape,
10456
+ ledth: ledShape,
10457
+ screw: screwShape,
10458
+ socket: socketShape,
10459
+ ...SMD_SHAPES,
10460
+ ...UNO_SHAPES
8799
10461
  };
8800
10462
  var FALLBACK = { minX: -0.5, minY: -0.5, maxX: 0.5, maxY: 0.5 };
8801
10463
  function placer(part, thickness) {
8802
10464
  const r = part.rotation * Math.PI / 180;
8803
10465
  const [c, s] = [Math.cos(r), Math.sin(r)];
8804
- const bottom = part.side === "bottom";
10466
+ const bottom2 = part.side === "bottom";
8805
10467
  const point = (p) => {
8806
10468
  const [x, y] = [p[0] * c - p[1] * s, p[0] * s + p[1] * c];
8807
- return [part.x + (bottom ? -x : x), part.y + y, bottom ? -p[2] : thickness + p[2]];
10469
+ return [part.x + (bottom2 ? -x : x), part.y + y, bottom2 ? -p[2] : thickness + p[2]];
8808
10470
  };
8809
10471
  const normal = (n) => {
8810
10472
  const [x, y] = [n[0] * c - n[1] * s, n[0] * s + n[1] * c];
8811
- return [bottom ? -x : x, y, bottom ? -n[2] : n[2]];
10473
+ return [bottom2 ? -x : x, y, bottom2 ? -n[2] : n[2]];
8812
10474
  };
8813
10475
  return { point, normal };
8814
10476
  }
8815
- function shapeInput(part, height, look, parsed2, thickness) {
10477
+ function shapeInput(part, height, look, parsed2, thickness, lookName) {
8816
10478
  const footprint = part.footprint;
8817
10479
  const limit = rectOf(footprint?.courtyard ?? []) ?? rectOf((footprint?.pads ?? []).map((p) => ({ x: p.x, y: p.y }))) ?? FALLBACK;
8818
10480
  const body = rectOf((footprint?.fabrication ?? []).flat());
8819
- return { pads: footprint?.pads ?? [], height, limit, ...body ? { body } : {}, look, ...parsed2 ? { parsed: parsed2 } : {}, thickness };
10481
+ return { pads: footprint?.pads ?? [], height, limit, ...body ? { body } : {}, ...footprint?.fabrication.length ? { outlines: footprint.fabrication } : {}, look, ...lookName ? { lookName } : {}, ...parsed2 ? { parsed: parsed2 } : {}, thickness };
8820
10482
  }
8821
10483
  function partFaces(design, model) {
8822
10484
  const thickness = model.board?.thickness ?? model.parts.find((p) => p.side === "top")?.bottom ?? 1.6;
@@ -8827,8 +10489,10 @@ function partFaces(design, model) {
8827
10489
  const component = components.get(part.component);
8828
10490
  const through2 = part.pads.some((pad) => pad.layers === "through");
8829
10491
  const { family, look, parsed: parsed2 } = familyOf(component?.kind ?? "", component?.footprint, through2, part.component);
8830
- const input = shapeInput(part, solid.height, FAMILY_LOOKS[look], parsed2, thickness);
8831
- const pieces = part.footprint === void 0 ? plainBox(input) : SHAPES[family](input);
10492
+ const paint2 = family === "ledth" ? ledLook(FAMILY_LOOKS[look], component?.props) : FAMILY_LOOKS[look];
10493
+ const input = shapeInput(part, solid.height, paint2, parsed2, thickness, look);
10494
+ const shaped = part.footprint === void 0 ? [] : SHAPES[family](input);
10495
+ const pieces = shaped.length === 0 ? plainBox(input) : shaped;
8832
10496
  const place3 = placer(part, thickness);
8833
10497
  return pieces.map((piece) => ({
8834
10498
  loops: piece.loops.map((loop) => loop.map(place3.point)),
@@ -8874,17 +10538,17 @@ function frameOf(width, height, reuse) {
8874
10538
  const size = width * height;
8875
10539
  return { width, height, color: new Uint8ClampedArray(size * 4), ids: new Int32Array(size), depth: new Float32Array(size), faces: new Int32Array(size) };
8876
10540
  }
8877
- function projectFace(face, view) {
8878
- const facing = dot2(face.normal, view.eye);
10541
+ function projectFace(face2, view) {
10542
+ const facing = dot2(face2.normal, view.eye);
8879
10543
  if (Math.abs(facing) < EDGE_ON) return void 0;
8880
- const first = face.loops[0]?.[0];
10544
+ const first = face2.loops[0]?.[0];
8881
10545
  if (first === void 0) return void 0;
8882
- const [nr, nu] = [dot2(face.normal, view.right), dot2(face.normal, view.up)];
8883
- const offset = dot2(face.normal, view.target) - dot2(face.normal, first);
10546
+ const [nr, nu] = [dot2(face2.normal, view.right), dot2(face2.normal, view.up)];
10547
+ const offset = dot2(face2.normal, view.target) - dot2(face2.normal, first);
8884
10548
  const a = nr / view.scale / facing;
8885
10549
  const b = -nu / view.scale / facing;
8886
10550
  const c = (offset - nr * view.width / 2 / view.scale + nu * view.height / 2 / view.scale) / facing;
8887
- const loops = face.loops.map(
10551
+ const loops = face2.loops.map(
8888
10552
  (loop) => loop.map((p) => {
8889
10553
  const d = [p[0] - view.target[0], p[1] - view.target[1], p[2] - view.target[2]];
8890
10554
  return { x: view.width / 2 + view.scale * dot2(d, view.right), y: view.height / 2 - view.scale * dot2(d, view.up) };
@@ -8892,16 +10556,16 @@ function projectFace(face, view) {
8892
10556
  );
8893
10557
  return { loops, a, b, c };
8894
10558
  }
8895
- function scan(face, width, height, fill) {
8896
- let [top, bottom] = [Infinity, -Infinity];
8897
- for (const loop of face.loops) for (const p of loop) [top, bottom] = [Math.min(top, p.y), Math.max(bottom, p.y)];
10559
+ function scan(face2, width, height, fill) {
10560
+ let [top, bottom2] = [Infinity, -Infinity];
10561
+ for (const loop of face2.loops) for (const p of loop) [top, bottom2] = [Math.min(top, p.y), Math.max(bottom2, p.y)];
8898
10562
  const first = Math.max(0, Math.ceil(top - 0.5));
8899
- const last = Math.min(height - 1, Math.floor(bottom - 0.5));
10563
+ const last = Math.min(height - 1, Math.floor(bottom2 - 0.5));
8900
10564
  const crossings = [];
8901
- for (let row = first; row <= last; row++) {
8902
- const y = row + 0.5;
10565
+ for (let row3 = first; row3 <= last; row3++) {
10566
+ const y = row3 + 0.5;
8903
10567
  crossings.length = 0;
8904
- for (const loop of face.loops) {
10568
+ for (const loop of face2.loops) {
8905
10569
  for (let i = 0; i < loop.length; i++) {
8906
10570
  const p = loop[i];
8907
10571
  const q = loop[(i + 1) % loop.length];
@@ -8912,14 +10576,14 @@ function scan(face, width, height, fill) {
8912
10576
  for (let k = 0; k + 1 < crossings.length; k += 2) {
8913
10577
  const from = Math.max(0, Math.ceil(crossings[k] - 0.5));
8914
10578
  const to = Math.min(width - 1, Math.floor(crossings[k + 1] - 0.5));
8915
- for (let col = from; col <= to; col++) fill(row * width + col, face.a * (col + 0.5) + face.b * y + face.c);
10579
+ for (let col = from; col <= to; col++) fill(row3 * width + col, face2.a * (col + 0.5) + face2.b * y + face2.c);
8916
10580
  }
8917
10581
  }
8918
10582
  }
8919
- function shade(face, view, highlight) {
8920
- const light = AMBIENT2 + (1 - AMBIENT2) * Math.abs(dot2(face.normal, view.eye));
8921
- const lift = face.part >= 0 && face.part === highlight ? HIGHLIGHT : 0;
8922
- return face.color.map((channel) => Math.round(channel * light + (255 - channel * light) * lift));
10583
+ function shade(face2, view, highlight) {
10584
+ const light = AMBIENT2 + (1 - AMBIENT2) * Math.abs(dot2(face2.normal, view.eye));
10585
+ const lift = face2.part >= 0 && face2.part === highlight ? HIGHLIGHT : 0;
10586
+ return face2.color.map((channel) => Math.round(channel * light + (255 - channel * light) * lift));
8923
10587
  }
8924
10588
  function renderScene(scene, orbit, width, height, options) {
8925
10589
  const frame = frameOf(width, height, options.reuse);
@@ -8934,31 +10598,31 @@ function renderScene(scene, orbit, width, height, options) {
8934
10598
  drawLit(scene, view, frame, options);
8935
10599
  return frame;
8936
10600
  }
8937
- const opaque = scene.faces.filter((face) => face.alpha >= 1);
8938
- const clear = scene.faces.filter((face) => face.alpha < 1);
8939
- for (const face of opaque) {
8940
- const projected = projectFace(face, view);
10601
+ const opaque = scene.faces.filter((face2) => face2.alpha >= 1);
10602
+ const clear = scene.faces.filter((face2) => face2.alpha < 1);
10603
+ for (const face2 of opaque) {
10604
+ const projected = projectFace(face2, view);
8941
10605
  if (!projected) continue;
8942
- const [r, g, b] = shade(face, view, options.highlight);
10606
+ const [r, g, b] = shade(face2, view, options.highlight);
8943
10607
  scan(projected, width, height, (index, depth) => {
8944
10608
  if (depth >= frame.depth[index]) return;
8945
10609
  frame.depth[index] = depth;
8946
- frame.ids[index] = face.part;
10610
+ frame.ids[index] = face2.part;
8947
10611
  frame.color[index * 4] = r;
8948
10612
  frame.color[index * 4 + 1] = g;
8949
10613
  frame.color[index * 4 + 2] = b;
8950
10614
  });
8951
10615
  }
8952
- for (const face of clear) {
8953
- const projected = projectFace(face, view);
10616
+ for (const face2 of clear) {
10617
+ const projected = projectFace(face2, view);
8954
10618
  if (!projected) continue;
8955
- const [r, g, b] = shade(face, view, void 0);
8956
- const keep = 1 - face.alpha;
10619
+ const [r, g, b] = shade(face2, view, void 0);
10620
+ const keep = 1 - face2.alpha;
8957
10621
  scan(projected, width, height, (index, depth) => {
8958
10622
  if (depth >= frame.depth[index]) return;
8959
- frame.color[index * 4] = frame.color[index * 4] * keep + r * face.alpha;
8960
- frame.color[index * 4 + 1] = frame.color[index * 4 + 1] * keep + g * face.alpha;
8961
- frame.color[index * 4 + 2] = frame.color[index * 4 + 2] * keep + b * face.alpha;
10623
+ frame.color[index * 4] = frame.color[index * 4] * keep + r * face2.alpha;
10624
+ frame.color[index * 4 + 1] = frame.color[index * 4 + 1] * keep + g * face2.alpha;
10625
+ frame.color[index * 4 + 2] = frame.color[index * 4 + 2] * keep + b * face2.alpha;
8962
10626
  });
8963
10627
  }
8964
10628
  return frame;
@@ -8969,20 +10633,20 @@ function drawLit(scene, view, frame, options) {
8969
10633
  const key = keyFor(view.eye);
8970
10634
  const sample = new Float32Array(3);
8971
10635
  const { width, height } = frame;
8972
- scene.faces.forEach((face, index) => {
8973
- if (dot2(face.normal, view.eye) <= 0) return;
8974
- const projected = projectFace(face, view);
10636
+ scene.faces.forEach((face2, index) => {
10637
+ if (dot2(face2.normal, view.eye) <= 0) return;
10638
+ const projected = projectFace(face2, view);
8975
10639
  if (!projected) return;
8976
- const { scale, add } = lightFace(face.normal, view.eye, key, face.material);
8977
- const lift = face.part >= 0 && face.part === options.highlight ? HIGHLIGHT : 0;
10640
+ const { scale, add } = lightFace(face2.normal, view.eye, key, face2.material);
10641
+ const lift = face2.part >= 0 && face2.part === options.highlight ? HIGHLIGHT : 0;
8978
10642
  const tone = (c2) => Math.min(255, c2 * scale + add) * (1 - lift) + 255 * lift;
8979
- const paint = face.paint;
8980
- if (!paint) {
8981
- const [r, g, b2] = [tone(face.color[0]), tone(face.color[1]), tone(face.color[2])];
10643
+ const paint2 = face2.paint;
10644
+ if (!paint2) {
10645
+ const [r, g, b2] = [tone(face2.color[0]), tone(face2.color[1]), tone(face2.color[2])];
8982
10646
  scan(projected, width, height, (i, depth) => {
8983
10647
  if (depth >= frame.depth[i]) return;
8984
10648
  frame.depth[i] = depth;
8985
- frame.ids[i] = face.part;
10649
+ frame.ids[i] = face2.part;
8986
10650
  frame.faces[i] = index;
8987
10651
  frame.color[i * 4] = r;
8988
10652
  frame.color[i * 4 + 1] = g;
@@ -8999,7 +10663,7 @@ function drawLit(scene, view, frame, options) {
8999
10663
  });
9000
10664
  const [X, Y, Z] = [axis(0), axis(1), axis(2)];
9001
10665
  const fine = options.fine ?? false;
9002
- const texture = paint.texture;
10666
+ const texture = paint2.texture;
9003
10667
  if (texture && !fine) {
9004
10668
  const sign = texture.mirrored ? -1 : 1;
9005
10669
  const p = texture.pxPerMm;
@@ -9008,10 +10672,10 @@ function drawLit(scene, view, frame, options) {
9008
10672
  const { rgba, width: tw, height: th } = texture;
9009
10673
  scan(projected, width, height, (i, depth) => {
9010
10674
  if (depth >= frame.depth[i]) return;
9011
- const row = i / width | 0;
9012
- const col = i - row * width;
9013
- const u = Math.floor(Au * col + Bu * row + Cu);
9014
- const v = Math.floor(Av * col + Bv * row + Cv);
10675
+ const row3 = i / width | 0;
10676
+ const col = i - row3 * width;
10677
+ const u = Math.floor(Au * col + Bu * row3 + Cu);
10678
+ const v = Math.floor(Av * col + Bv * row3 + Cv);
9015
10679
  if (u < 0 || v < 0 || u >= tw || v >= th) return;
9016
10680
  const k = (v * tw + u) * 4;
9017
10681
  if (rgba[k + 3] < 128) return;
@@ -9026,14 +10690,14 @@ function drawLit(scene, view, frame, options) {
9026
10690
  }
9027
10691
  scan(projected, width, height, (i, depth) => {
9028
10692
  if (depth >= frame.depth[i]) return;
9029
- const row = i / width | 0;
9030
- const col = i - row * width;
9031
- const x = X.A * col + X.B * row + X.C;
9032
- const y = Y.A * col + Y.B * row + Y.C;
9033
- const z = Z.A * col + Z.B * row + Z.C;
9034
- if (paint.at(x, y, z, sample, fine) < 0.5) return;
10693
+ const row3 = i / width | 0;
10694
+ const col = i - row3 * width;
10695
+ const x = X.A * col + X.B * row3 + X.C;
10696
+ const y = Y.A * col + Y.B * row3 + Y.C;
10697
+ const z = Z.A * col + Z.B * row3 + Z.C;
10698
+ if (paint2.at(x, y, z, sample, fine) < 0.5) return;
9035
10699
  frame.depth[i] = depth;
9036
- frame.ids[i] = face.part;
10700
+ frame.ids[i] = face2.part;
9037
10701
  frame.faces[i] = index;
9038
10702
  frame.color[i * 4] = tone(sample[0]);
9039
10703
  frame.color[i * 4 + 1] = tone(sample[1]);
@@ -9172,21 +10836,21 @@ function rgb(hex) {
9172
10836
  var sideColor = (side) => rgb(side === "top" ? PALETTE.topAssembly : PALETTE.bottomAssembly);
9173
10837
  var ARC_STEP = Math.PI / 12;
9174
10838
  function loopPoints(loop) {
9175
- return loop.flatMap((segment) => {
9176
- if (segment.kind === "line") return [segment.from];
9177
- const sweep = arcSweep(segment);
10839
+ return loop.flatMap((segment2) => {
10840
+ if (segment2.kind === "line") return [segment2.from];
10841
+ const sweep = arcSweep(segment2);
9178
10842
  const pieces = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
9179
- const start = Math.atan2(segment.from.y - segment.centre.y, segment.from.x - segment.centre.x);
10843
+ const start = Math.atan2(segment2.from.y - segment2.centre.y, segment2.from.x - segment2.centre.x);
9180
10844
  return Array.from({ length: pieces }, (_, i) => {
9181
10845
  const angle = start + sweep * i / pieces;
9182
- return i === 0 ? segment.from : { x: segment.centre.x + segment.radius * Math.cos(angle), y: segment.centre.y + segment.radius * Math.sin(angle) };
10846
+ return i === 0 ? segment2.from : { x: segment2.centre.x + segment2.radius * Math.cos(angle), y: segment2.centre.y + segment2.radius * Math.sin(angle) };
9183
10847
  });
9184
10848
  });
9185
10849
  }
9186
10850
  function prismFaces(loops, z0, z1, color, alpha, part) {
9187
10851
  const at2 = (z) => (p) => [p.x, p.y, z];
9188
10852
  const top = { loops: loops.map((loop) => loop.map(at2(z1))), normal: [0, 0, 1], color, alpha, part };
9189
- const bottom = { loops: loops.map((loop) => [...loop].reverse().map(at2(z0))), normal: [0, 0, -1], color, alpha, part };
10853
+ const bottom2 = { loops: loops.map((loop) => [...loop].reverse().map(at2(z0))), normal: [0, 0, -1], color, alpha, part };
9190
10854
  const sides = loops.flatMap(
9191
10855
  (loop) => loop.map((p, i) => {
9192
10856
  const q = loop[(i + 1) % loop.length];
@@ -9194,7 +10858,7 @@ function prismFaces(loops, z0, z1, color, alpha, part) {
9194
10858
  return { loops: [[at2(z0)(p), at2(z0)(q), at2(z1)(q), at2(z1)(p)]], normal: [(q.y - p.y) / length2, -(q.x - p.x) / length2, 0], color, alpha, part };
9195
10859
  })
9196
10860
  );
9197
- return [top, bottom, ...sides];
10861
+ return [top, bottom2, ...sides];
9198
10862
  }
9199
10863
  function litBoard(board, options) {
9200
10864
  const colours = plainBoardColours(options.look ?? {});
@@ -9203,7 +10867,7 @@ function litBoard(board, options) {
9203
10867
  const at2 = (z) => (p) => [p.x, p.y, z];
9204
10868
  const faceLoops = (texture) => texture ? loops.slice(0, 1) : loops;
9205
10869
  const top = { loops: faceLoops(options.textures?.top).map((loop) => loop.map(at2(t))), normal: [0, 0, 1], color: colours.mask, alpha: 1, part: -1, material: "matt", role: "board", ...options.textures?.top ? { paint: texturePaint(options.textures.top) } : {} };
9206
- const bottom = { loops: faceLoops(options.textures?.bottom).map((loop) => [...loop].reverse().map(at2(0))), normal: [0, 0, -1], color: colours.mask, alpha: 1, part: -1, material: "matt", role: "board", ...options.textures?.bottom ? { paint: texturePaint(options.textures.bottom) } : {} };
10870
+ const bottom2 = { loops: faceLoops(options.textures?.bottom).map((loop) => [...loop].reverse().map(at2(0))), normal: [0, 0, -1], color: colours.mask, alpha: 1, part: -1, material: "matt", role: "board", ...options.textures?.bottom ? { paint: texturePaint(options.textures.bottom) } : {} };
9207
10871
  const edge = edgePaint(t, options.layers ?? 2, colours.mask);
9208
10872
  const mounting = options.mounting ?? 0;
9209
10873
  const walls = loops.flatMap(
@@ -9224,7 +10888,7 @@ function litBoard(board, options) {
9224
10888
  };
9225
10889
  })
9226
10890
  );
9227
- return [top, bottom, ...walls];
10891
+ return [top, bottom2, ...walls];
9228
10892
  }
9229
10893
  function buildScene(model, options) {
9230
10894
  const board = model.board;
@@ -9233,7 +10897,7 @@ function buildScene(model, options) {
9233
10897
  const faces = [...partFaces2, ...boardFaces];
9234
10898
  const min = [Infinity, Infinity, Infinity];
9235
10899
  const max = [-Infinity, -Infinity, -Infinity];
9236
- for (const point of faces.flatMap((face) => face.loops.flat())) {
10900
+ for (const point of faces.flatMap((face2) => face2.loops.flat())) {
9237
10901
  for (let axis = 0; axis < 3; axis++) {
9238
10902
  min[axis] = Math.min(min[axis], point[axis]);
9239
10903
  max[axis] = Math.max(max[axis], point[axis]);
@@ -9278,31 +10942,32 @@ function viaSpan(via) {
9278
10942
  return new Set(STACK.slice(Math.min(...indices), Math.max(...indices) + 1));
9279
10943
  }
9280
10944
 
9281
- // src/engine/pour/clip.ts
9282
- var import_clipper_lib = __toESM(require_clipper(), 1);
9283
- var UNITS_PER_MM = 1e3;
9284
- var toUnits = (mm) => Math.round(mm * UNITS_PER_MM);
9285
- var toPath = (points) => points.map((p) => ({ X: toUnits(p.x), Y: toUnits(p.y) }));
9286
- var toPoints = (path2) => path2.map((p) => ({ x: p.X / UNITS_PER_MM, y: p.Y / UNITS_PER_MM }));
9287
- function clipper(subject, clip) {
9288
- const engine = new import_clipper_lib.default.Clipper();
9289
- engine.StrictlySimple = true;
9290
- engine.AddPaths(subject.filter((path2) => path2.length >= 3), import_clipper_lib.default.PolyType.ptSubject, true);
9291
- engine.AddPaths(clip.filter((path2) => path2.length >= 3), import_clipper_lib.default.PolyType.ptClip, true);
9292
- return engine;
9293
- }
9294
- function regions(paths) {
9295
- const tree = new import_clipper_lib.default.PolyTree();
9296
- const fill = import_clipper_lib.default.PolyFillType.pftNonZero;
9297
- clipper(paths, []).Execute(import_clipper_lib.default.ClipType.ctUnion, tree, fill, fill);
9298
- return import_clipper_lib.default.JS.PolyTreeToExPolygons(tree).map((piece) => ({ outer: piece.outer, holes: piece.holes }));
10945
+ // src/engine/fab/graphic-objects.ts
10946
+ var wound = (ring4, counterClockwise) => {
10947
+ const area2 = ring4.reduce((sum, a, i) => {
10948
+ const b = ring4[(i + 1) % ring4.length];
10949
+ return sum + a.x * b.y - b.x * a.y;
10950
+ }, 0);
10951
+ return area2 > 0 === counterClockwise ? [...ring4] : [...ring4].reverse();
10952
+ };
10953
+ function graphicObjects(graphics, layer, fn) {
10954
+ const here = (graphics ?? []).filter((graphic) => graphic.layer === layer);
10955
+ if (here.length === 0) return { areas: [], lines: [] };
10956
+ const extra = fn === void 0 ? {} : { function: fn };
10957
+ const paths = here.flatMap((graphic) => graphic.areas.flatMap((area2) => [toPath(wound(area2.outer, true)), ...area2.holes.map((hole) => toPath(wound(hole, false)))]));
10958
+ const pieces = paths.length === 0 ? [] : regions(paths).sort((a, b) => Math.abs(pathArea(b.outer)) - Math.abs(pathArea(a.outer)));
10959
+ const areas = pieces.flatMap((piece) => [
10960
+ { kind: "region", points: toPoints(piece.outer), ...extra },
10961
+ ...piece.holes.map((hole) => ({ kind: "region", points: toPoints(hole), polarity: "clear" }))
10962
+ ]);
10963
+ const lines2 = here.flatMap((graphic) => graphic.lines.filter((line2) => line2.points.length > 0).map((line2) => ({ kind: "draw", points: line2.points, width: line2.width, ...extra })));
10964
+ return { areas, lines: lines2 };
9299
10965
  }
9300
- var pathArea = (path2) => import_clipper_lib.default.Clipper.Area(path2);
9301
10966
 
9302
10967
  // src/engine/fab/layers.ts
9303
10968
  var DEFAULT_PASTE_REDUCTION = 0;
9304
10969
  var OUTLINE_WIDTH = 0.1;
9305
- var SIDES2 = ["top", "bottom"];
10970
+ var SIDES8 = ["top", "bottom"];
9306
10971
  var ANGLE_TOLERANCE = 1e-9;
9307
10972
  var COPPER_NAME = { top: "F_Cu", inner1: "In1_Cu", inner2: "In2_Cu", bottom: "B_Cu" };
9308
10973
  var SIDE_KEY = { top: "F", bottom: "B" };
@@ -9371,18 +11036,58 @@ function pourObjects(pcb, layer) {
9371
11036
  ...piece.holes.map((hole) => ({ kind: "region", points: toPoints(hole), polarity: "clear" }))
9372
11037
  ]);
9373
11038
  }
11039
+ function drawingCopper(pcb, layer) {
11040
+ const here = (pcb.graphics ?? []).filter((graphic) => graphic.layer === layer);
11041
+ return here.flatMap((graphic) => [
11042
+ ...graphic.areas.map((area2) => ({ kind: "region", points: withCutIns(area2), function: "Conductor" })),
11043
+ ...graphic.lines.filter((line2) => line2.points.length > 0).map((line2) => ({ kind: "draw", points: line2.points, width: line2.width, function: "Conductor" }))
11044
+ ]);
11045
+ }
11046
+ var wound2 = (ring4, counterClockwise) => {
11047
+ const twice = ring4.reduce((sum, a, i) => {
11048
+ const b = ring4[(i + 1) % ring4.length];
11049
+ return sum + a.x * b.y - b.x * a.y;
11050
+ }, 0);
11051
+ return twice > 0 === counterClockwise ? [...ring4] : [...ring4].reverse();
11052
+ };
11053
+ function withCutIns(area2) {
11054
+ return area2.holes.reduce((ring4, raw) => {
11055
+ const hole = wound2(raw, false);
11056
+ let [best, at2, from] = [Infinity, 0, 0];
11057
+ hole.forEach(
11058
+ (h, j) => ring4.forEach((o, i) => {
11059
+ const d = (o.x - h.x) ** 2 + (o.y - h.y) ** 2;
11060
+ if (d < best) [best, at2, from] = [d, i, j];
11061
+ })
11062
+ );
11063
+ const loop = [...hole.slice(from), ...hole.slice(0, from), hole[from]];
11064
+ return [...ring4.slice(0, at2 + 1), ...loop, ...ring4.slice(at2)];
11065
+ }, wound2(area2.outer, true));
11066
+ }
9374
11067
  function copperObjects(pcb, layer) {
9375
11068
  const padCopper = pads(pcb.parts).filter((pad) => pad.layers === "through" || pad.layers === layer).map((pad) => padObject(pad, 0, padFunction(pad)));
9376
11069
  const tracks = pcb.tracks.filter((track) => track.layer === layer && track.missingLayer === void 0).map((track) => ({ kind: "draw", points: track.points, width: track.width, function: "Conductor" }));
9377
11070
  const vias = pcb.vias.filter((via) => via.missingLayer === void 0 && viaSpan(via).has(layer)).map((via) => ({ kind: "flash", at: via.at, aperture: { shape: "circle", diameter: via.diameter }, function: "ViaPad" }));
9378
- return [...pourObjects(pcb, layer), ...padCopper.filter(present), ...tracks, ...vias];
11071
+ return [...pourObjects(pcb, layer), ...drawingCopper(pcb, layer), ...padCopper.filter(present), ...tracks, ...vias];
9379
11072
  }
9380
11073
  function silkObjects(pcb, side, expansion, clearance) {
9381
11074
  const designators = designatorPlacements(pcb, expansion, clearance).filter((placed2) => placed2.side === side);
11075
+ const draw2 = (width) => (points) => ({ kind: "draw", points, width, function: LEGEND_FUNCTION });
11076
+ const texts = (pcb.silkTexts ?? []).filter((text2) => text2.layer === side).flatMap((text2) => silkTextStrokes(text2).map(draw2(silkTextLineWidth(text2.height))));
11077
+ const drawings = graphicObjects(pcb.graphics, `${side}-silkscreen`, LEGEND_FUNCTION);
9382
11078
  return [
9383
- ...pcb.parts.filter((part) => part.side === side).flatMap((part) => part.silkscreen),
9384
- ...designators.flatMap((placed2) => textStrokes(placed2.component, placed2.at, DESIGNATOR_HEIGHT, side === "bottom", placed2.rotation === 90))
9385
- ].filter((line2) => line2.length > 0).map((points) => ({ kind: "draw", points, width: SILK_WIDTH, function: LEGEND_FUNCTION }));
11079
+ ...drawings.areas,
11080
+ ...[
11081
+ ...pcb.parts.filter((part) => part.side === side).flatMap((part) => part.silkscreen),
11082
+ ...designators.flatMap((placed2) => textStrokes(placed2.component, placed2.at, DESIGNATOR_HEIGHT, side === "bottom", placed2.rotation === 90))
11083
+ ].filter((line2) => line2.length > 0).map(draw2(SILK_WIDTH)),
11084
+ ...texts,
11085
+ ...drawings.lines
11086
+ ];
11087
+ }
11088
+ function maskObjects(pcb, side, onSide, expansion) {
11089
+ const drawings = graphicObjects(pcb.graphics, `${side}-mask`);
11090
+ return [...drawings.areas, ...onSide.map((pad) => padObject(pad, expansion, padFunction(pad))).filter(present), ...drawings.lines];
9386
11091
  }
9387
11092
  function outlineObjects(pcb) {
9388
11093
  const outline2 = pcb.board?.outline ?? [];
@@ -9400,9 +11105,9 @@ function gerberLayers(pcb, fabrication) {
9400
11105
  const position = layer === "top" ? "Top" : layer === "bottom" ? "Bot" : "Inr";
9401
11106
  layers.set(COPPER_NAME[layer], { fileFunction: `Copper,L${i + 1},${position}`, polarity: "Positive", objects: copperObjects(pcb, layer) });
9402
11107
  });
9403
- for (const side of SIDES2) {
11108
+ for (const side of SIDES8) {
9404
11109
  const onSide = pads(pcb.parts).filter((pad) => padOnSide(pad, side));
9405
- const mask = onSide.map((pad) => padObject(pad, expansion, padFunction(pad))).filter(present);
11110
+ const mask = maskObjects(pcb, side, onSide, expansion);
9406
11111
  const paste = onSide.filter(isSmd).map((pad) => padObject(pad, -reduction, padFunction(pad))).filter(present);
9407
11112
  layers.set(`${SIDE_KEY[side]}_Mask`, { fileFunction: `Soldermask,${SIDE_X2[side]}`, polarity: "Negative", objects: mask });
9408
11113
  layers.set(`${SIDE_KEY[side]}_Paste`, { fileFunction: `Paste,${SIDE_X2[side]}`, polarity: "Positive", objects: paste });
@@ -9511,15 +11216,15 @@ function finishStep(below, images, look, relief) {
9511
11216
  const out = new Float32Array(below);
9512
11217
  const colour = [0, 0, 0];
9513
11218
  for (let i = 0; i < images.body.data.length; i += 1) {
9514
- const bare = at(images.copper, i) * at(images.openings, i) * at(images.body, i);
9515
- if (bare <= 0) continue;
11219
+ const bare2 = at(images.copper, i) * at(images.openings, i) * at(images.body, i);
11220
+ if (bare2 <= 0) continue;
9516
11221
  const inner = smooth(0.1, 0.9, at(relief.soft, i));
9517
11222
  const glint = relief.slope[i];
9518
11223
  for (let c = 0; c < 3; c += 1) {
9519
- const face = finish.rim[c] + (finish.face[c] - finish.rim[c]) * inner;
9520
- colour[c] = glint >= 0 ? face + (finish.shine[c] - face) * glint * 0.8 : face + (finish.rim[c] - face) * -glint * 0.6;
11224
+ const face2 = finish.rim[c] + (finish.face[c] - finish.rim[c]) * inner;
11225
+ colour[c] = glint >= 0 ? face2 + (finish.shine[c] - face2) * glint * 0.8 : face2 + (finish.rim[c] - face2) * -glint * 0.6;
9521
11226
  }
9522
- mixInto(out, i * 3, below, i * 3, colour, bare);
11227
+ mixInto(out, i * 3, below, i * 3, colour, bare2);
9523
11228
  }
9524
11229
  return out;
9525
11230
  }
@@ -9578,15 +11283,15 @@ function compose(images, look, pxPerMm) {
9578
11283
  return { soft, slope: slope(soft, r) };
9579
11284
  };
9580
11285
  const n = images.body.data.length;
9581
- const bare = { ...images.copper, data: new Float32Array(n) };
11286
+ const bare2 = { ...images.copper, data: new Float32Array(n) };
9582
11287
  const solid = { ...images.body, data: new Float32Array(n) };
9583
11288
  for (let i = 0; i < n; i += 1) {
9584
- bare.data[i] = at(images.copper, i) * at(images.openings, i);
11289
+ bare2.data[i] = at(images.copper, i) * at(images.openings, i);
9585
11290
  solid.data[i] = at(images.body, i) * (1 - through(images, i));
9586
11291
  }
9587
11292
  const body = bodyStep(images);
9588
11293
  const masked = maskStep(body, images, look, relief(images.copper, MASK_SOFTNESS));
9589
- const plated = finishStep(masked, images, look, relief(bare, FINISH_SOFTNESS));
11294
+ const plated = finishStep(masked, images, look, relief(bare2, FINISH_SOFTNESS));
9590
11295
  const printed = silkStep(plated, images, look);
9591
11296
  const holed = holesStep(printed, images);
9592
11297
  const edged = edgeStep(holed, soften(solid, radiusOf(EDGE_SOFTNESS, pxPerMm)));
@@ -9605,39 +11310,39 @@ function toPixel(grid, p) {
9605
11310
  const x = grid.mirrored ? grid.maxX - p.x : p.x - grid.minX;
9606
11311
  return { x: x * grid.pxPerMm, y: (grid.maxY - p.y) * grid.pxPerMm };
9607
11312
  }
9608
- function band(d, half) {
11313
+ function band2(d, half) {
9609
11314
  const a = Math.max(d - 0.5, -half);
9610
11315
  const b = Math.min(d + 0.5, half);
9611
11316
  return b > a ? Math.min(b - a, 1) : 0;
9612
11317
  }
9613
11318
  var length = (x, y) => Math.sqrt(x * x + y * y);
9614
11319
  var clamp012 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
9615
- function put(data, i, c, paint) {
11320
+ function put(data, i, c, paint2) {
9616
11321
  if (c <= 0) return;
9617
- if (paint === "dark") {
11322
+ if (paint2 === "dark") {
9618
11323
  if (c > data[i]) data[i] = c;
9619
11324
  } else {
9620
11325
  const left = 1 - c;
9621
11326
  if (left < data[i]) data[i] = left;
9622
11327
  }
9623
11328
  }
9624
- function eachPixel(layer, a, b, reach, cover, paint) {
11329
+ function eachPixel(layer, a, b, reach, cover, paint2) {
9625
11330
  const x0 = Math.max(0, Math.floor(Math.min(a.x, b.x) - reach));
9626
11331
  const x1 = Math.min(layer.width, Math.ceil(Math.max(a.x, b.x) + reach));
9627
11332
  const y0 = Math.max(0, Math.floor(Math.min(a.y, b.y) - reach));
9628
11333
  const y1 = Math.min(layer.height, Math.ceil(Math.max(a.y, b.y) + reach));
9629
11334
  for (let y = y0; y < y1; y += 1) {
9630
- const row = y * layer.width;
9631
- for (let x = x0; x < x1; x += 1) put(layer.data, row + x, cover(x + 0.5, y + 0.5), paint);
11335
+ const row3 = y * layer.width;
11336
+ for (let x = x0; x < x1; x += 1) put(layer.data, row3 + x, cover(x + 0.5, y + 0.5), paint2);
9632
11337
  }
9633
11338
  }
9634
- function disc2(layer, c, r, paint = "dark") {
9635
- eachPixel(layer, c, c, r + 1, (x, y) => band(length(x - c.x, y - c.y), r), paint);
11339
+ function disc2(layer, c, r, paint2 = "dark") {
11340
+ eachPixel(layer, c, c, r + 1, (x, y) => band2(length(x - c.x, y - c.y), r), paint2);
9636
11341
  }
9637
- function capsule(layer, a, b, r, paint = "dark") {
11342
+ function capsule(layer, a, b, r, paint2 = "dark") {
9638
11343
  const [dx, dy] = [b.x - a.x, b.y - a.y];
9639
11344
  const length2 = dx * dx + dy * dy;
9640
- if (length2 === 0) return disc2(layer, a, r, paint);
11345
+ if (length2 === 0) return disc2(layer, a, r, paint2);
9641
11346
  eachPixel(
9642
11347
  layer,
9643
11348
  a,
@@ -9645,12 +11350,12 @@ function capsule(layer, a, b, r, paint = "dark") {
9645
11350
  r + 1,
9646
11351
  (x, y) => {
9647
11352
  const t = clamp012(((x - a.x) * dx + (y - a.y) * dy) / length2);
9648
- return band(length(x - a.x - t * dx, y - a.y - t * dy), r);
11353
+ return band2(length(x - a.x - t * dx, y - a.y - t * dy), r);
9649
11354
  },
9650
- paint
11355
+ paint2
9651
11356
  );
9652
11357
  }
9653
- function box2(layer, c, hw, hh, angle, radius, paint = "dark") {
11358
+ function box2(layer, c, hw, hh, angle, radius, paint2 = "dark") {
9654
11359
  const [cos, sin] = [Math.cos(angle), Math.sin(angle)];
9655
11360
  const reach = Math.hypot(hw, hh) + 1;
9656
11361
  const rounded = Math.min(radius, hw, hh);
@@ -9662,14 +11367,14 @@ function box2(layer, c, hw, hh, angle, radius, paint = "dark") {
9662
11367
  (x, y) => {
9663
11368
  const u = (x - c.x) * cos + (y - c.y) * sin;
9664
11369
  const v = -(x - c.x) * sin + (y - c.y) * cos;
9665
- if (rounded <= 0) return band(u, hw) * band(v, hh);
11370
+ if (rounded <= 0) return band2(u, hw) * band2(v, hh);
9666
11371
  const qx = Math.abs(u) - (hw - rounded);
9667
11372
  const qy = Math.abs(v) - (hh - rounded);
9668
11373
  const outside = length(Math.max(qx, 0), Math.max(qy, 0));
9669
11374
  const distance = outside + Math.min(Math.max(qx, qy), 0) - rounded;
9670
11375
  return clamp012(0.5 - distance);
9671
11376
  },
9672
- paint
11377
+ paint2
9673
11378
  );
9674
11379
  }
9675
11380
  function edgesOf(paths) {
@@ -9679,8 +11384,8 @@ function edgesOf(paths) {
9679
11384
  const a = path2[i];
9680
11385
  const b = path2[(i + 1) % path2.length];
9681
11386
  if (a.y === b.y) continue;
9682
- const [top, bottom, dir] = a.y < b.y ? [a, b, 1] : [b, a, -1];
9683
- edges.push({ x0: top.x, y0: top.y, y1: bottom.y, slope: (bottom.x - top.x) / (bottom.y - top.y), dir });
11387
+ const [top, bottom2, dir] = a.y < b.y ? [a, b, 1] : [b, a, -1];
11388
+ edges.push({ x0: top.x, y0: top.y, y1: bottom2.y, slope: (bottom2.x - top.x) / (bottom2.y - top.y), dir });
9684
11389
  }
9685
11390
  }
9686
11391
  return edges.sort((a, b) => a.y0 - b.y0);
@@ -9697,18 +11402,18 @@ function addSpan(parts, steps, a, b, weight) {
9697
11402
  steps[ib] = steps[ib] - weight;
9698
11403
  parts[ib] = parts[ib] + (b - ib) * weight;
9699
11404
  }
9700
- function polygons(layer, paths, rule, paint = "dark") {
11405
+ function polygons(layer, paths, rule, paint2 = "dark") {
9701
11406
  const edges = edgesOf(paths);
9702
11407
  if (edges.length === 0) return;
9703
11408
  const top = Math.max(0, Math.floor(edges[0]?.y0 ?? 0));
9704
- const bottom = Math.min(layer.height, Math.ceil(Math.max(...edges.map((edge) => edge.y1))));
11409
+ const bottom2 = Math.min(layer.height, Math.ceil(Math.max(...edges.map((edge) => edge.y1))));
9705
11410
  const parts = new Float32Array(layer.width + 2);
9706
11411
  const steps = new Float32Array(layer.width + 2);
9707
11412
  const crossings = [];
9708
11413
  let next = 0;
9709
11414
  let active = [];
9710
11415
  const weight = 1 / SUBROWS;
9711
- for (let y = top; y < bottom; y += 1) {
11416
+ for (let y = top; y < bottom2; y += 1) {
9712
11417
  while (next < edges.length && edges[next].y0 < y + 1) active.push(edges[next++]);
9713
11418
  active = active.filter((edge) => edge.y1 > y);
9714
11419
  if (active.length === 0) continue;
@@ -9734,10 +11439,10 @@ function polygons(layer, paths, rule, paint = "dark") {
9734
11439
  }
9735
11440
  }
9736
11441
  let run = 0;
9737
- const row = y * layer.width;
11442
+ const row3 = y * layer.width;
9738
11443
  for (let x = from; x < to; x += 1) {
9739
11444
  run += steps[x];
9740
- put(layer.data, row + x, Math.min(run + parts[x], 1), paint);
11445
+ put(layer.data, row3 + x, Math.min(run + parts[x], 1), paint2);
9741
11446
  parts[x] = 0;
9742
11447
  steps[x] = 0;
9743
11448
  }
@@ -9750,22 +11455,22 @@ function pictureAngle(grid, degrees) {
9750
11455
  const radians = degrees * Math.PI / 180;
9751
11456
  return Math.atan2(-Math.sin(radians), (grid.mirrored ? -1 : 1) * Math.cos(radians));
9752
11457
  }
9753
- function flash(layer, grid, at2, aperture, paint) {
11458
+ function flash(layer, grid, at2, aperture, paint2) {
9754
11459
  const s = grid.pxPerMm;
9755
11460
  const c = toPixel(grid, at2);
9756
11461
  switch (aperture.shape) {
9757
11462
  case "circle":
9758
- return disc2(layer, c, aperture.diameter / 2 * s, paint);
11463
+ return disc2(layer, c, aperture.diameter / 2 * s, paint2);
9759
11464
  case "rect":
9760
- return box2(layer, c, aperture.width / 2 * s, aperture.height / 2 * s, 0, 0, paint);
11465
+ return box2(layer, c, aperture.width / 2 * s, aperture.height / 2 * s, 0, 0, paint2);
9761
11466
  case "obround": {
9762
11467
  const along = aperture.width >= aperture.height;
9763
11468
  const half = Math.abs(aperture.width - aperture.height) / 2 * s;
9764
11469
  const [dx, dy] = along ? [half, 0] : [0, half];
9765
- return capsule(layer, { x: c.x - dx, y: c.y - dy }, { x: c.x + dx, y: c.y + dy }, Math.min(aperture.width, aperture.height) / 2 * s, paint);
11470
+ return capsule(layer, { x: c.x - dx, y: c.y - dy }, { x: c.x + dx, y: c.y + dy }, Math.min(aperture.width, aperture.height) / 2 * s, paint2);
9766
11471
  }
9767
11472
  case "roundrect":
9768
- return box2(layer, c, aperture.width / 2 * s, aperture.height / 2 * s, pictureAngle(grid, aperture.rotation), aperture.radius * s, paint);
11473
+ return box2(layer, c, aperture.width / 2 * s, aperture.height / 2 * s, pictureAngle(grid, aperture.rotation), aperture.radius * s, paint2);
9769
11474
  }
9770
11475
  }
9771
11476
  function draw(layer, grid, object) {
@@ -9885,11 +11590,11 @@ var SHADOW_HEIGHT = 2.6;
9885
11590
  var SOFT = 0.45;
9886
11591
  function hull2(points) {
9887
11592
  const sorted = [...points].sort((a, b) => a.x - b.x || a.y - b.y);
9888
- const cross2 = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
11593
+ const cross3 = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
9889
11594
  const half = (list) => {
9890
11595
  const out = [];
9891
11596
  for (const p of list) {
9892
- while (out.length >= 2 && cross2(out[out.length - 2], out[out.length - 1], p) <= 0) out.pop();
11597
+ while (out.length >= 2 && cross3(out[out.length - 2], out[out.length - 1], p) <= 0) out.pop();
9893
11598
  out.push(p);
9894
11599
  }
9895
11600
  out.pop();
@@ -9999,18 +11704,26 @@ function heightWords(model) {
9999
11704
  const part = (list, word) => list.length === 0 ? `none ${word}` : list.length <= NAMED ? `${word}: ${list.join(", ")}` : `${list.length} ${word}`;
10000
11705
  return `heights ${part(typical, "typical")}; ${part(assumed, "assumed")}`;
10001
11706
  }
11707
+ function lookScene(design, look) {
11708
+ const model = solidModel(design);
11709
+ const textures = boardTextures(design, model, look);
11710
+ const scene = buildScene(model, { parts: partFaces(design, model), textures, look, mounting: design.pcb.holes.length, layers: design.pcb.board?.layers ?? 2 });
11711
+ return { model, scene };
11712
+ }
11713
+ function shapesWords(model, look) {
11714
+ return `the board as made (${lookWords(resolveLook(look))}) and ${partsWords(model)}`;
11715
+ }
11716
+ var partsWords = (model) => `${model.parts.length} parts as simple shapes, not their real models; ${heightWords(model)}`;
10002
11717
  function lookPicture(design, request) {
10003
11718
  const width = request.width ?? DEFAULT_WIDTH2;
10004
11719
  if (!Number.isInteger(width) || width < LOOK_MIN_WIDTH || width > LOOK_MAX_WIDTH) throw new Error(`width must be a whole number of pixels from ${LOOK_MIN_WIDTH} to ${LOOK_MAX_WIDTH} for view 3d`);
10005
11720
  const height = Math.round(width * ASPECT);
10006
11721
  const angle = request.angle ?? "iso";
10007
11722
  const look = request.look ?? {};
10008
- const resolved = resolveLook(look);
10009
- const model = solidModel(design);
10010
- const textures = boardTextures(design, model, look);
10011
- const scene = buildScene(model, { parts: partFaces(design, model), textures, look, mounting: design.pcb.holes.length, layers: design.pcb.board?.layers ?? 2 });
11723
+ resolveLook(look);
11724
+ const { model, scene } = lookScene(design, look);
11725
+ const what = `3D from ${angle}, ${shapesWords(model, look)}`;
10012
11726
  const frame = renderSmooth(scene, ANGLES[angle], width, height, { background: [...LOOK_BACKGROUND], lit: true });
10013
- const what = `3D from ${angle}, the board as made (${lookWords(resolved)}) and ${model.parts.length} parts as simple shapes, not their real models; ${heightWords(model)}`;
10014
11727
  return { rgba: frame.color, width, height, what, label: designName(design.file) };
10015
11728
  }
10016
11729
  async function renderLook(design, request) {
@@ -10025,6 +11738,238 @@ async function renderLook(design, request) {
10025
11738
  return { png: new Uint8Array(png), width: picture.width, height: picture.height, what: picture.what, label: picture.label };
10026
11739
  }
10027
11740
 
11741
+ // studio/src/look/glb.ts
11742
+ import earcut2 from "earcut";
11743
+ var FLOAT = 5126;
11744
+ var UINT = 5125;
11745
+ var ARRAY_BUFFER = 34962;
11746
+ var ELEMENT_ARRAY_BUFFER = 34963;
11747
+ var LINEAR = 9729;
11748
+ var LINEAR_MIPMAP_LINEAR = 9987;
11749
+ var CLAMP_TO_EDGE = 33071;
11750
+ var TO_METRES_Y_UP = [1e-3, 0, 0, 0, 0, 0, -1e-3, 0, 0, 1e-3, 0, 0, 0, 0, 0, 1];
11751
+ var SURFACE = {
11752
+ matt: { metallicFactor: 0, roughnessFactor: 0.8 },
11753
+ metal: { metallicFactor: 0.75, roughnessFactor: 0.35 }
11754
+ };
11755
+ var BOARD_SURFACE = { metallicFactor: 0, roughnessFactor: 0.55 };
11756
+ var STRIP_HEIGHT = 128;
11757
+ var STRIP_WIDTH = 4;
11758
+ var round4 = (value) => Math.round(value * 1e4) / 1e4;
11759
+ var linear = (channel) => {
11760
+ const c = channel / 255;
11761
+ return round4(c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
11762
+ };
11763
+ function triangles(face2) {
11764
+ const corners = face2.loops.flat();
11765
+ const [nx, ny, nz] = face2.normal.map(Math.abs);
11766
+ const drop = nx >= ny && nx >= nz ? 0 : ny >= nz ? 1 : 2;
11767
+ const [a, b] = [(drop + 1) % 3, (drop + 2) % 3];
11768
+ const flat = corners.flatMap((corner) => [corner[a], corner[b]]);
11769
+ const holes = [];
11770
+ face2.loops.slice(0, -1).reduce((count, loop) => (holes.push(count + loop.length), count + loop.length), 0);
11771
+ const cut = earcut2(flat, holes, 2);
11772
+ const indices = [];
11773
+ for (let i = 0; i < cut.length; i += 3) {
11774
+ const [p, q, r] = [cut[i], cut[i + 1], cut[i + 2]];
11775
+ const [P, Q, R] = [corners[p], corners[q], corners[r]];
11776
+ const [ux, uy, uz] = [Q[0] - P[0], Q[1] - P[1], Q[2] - P[2]];
11777
+ const [vx, vy, vz] = [R[0] - P[0], R[1] - P[1], R[2] - P[2]];
11778
+ const along = (uy * vz - uz * vy) * face2.normal[0] + (uz * vx - ux * vz) * face2.normal[1] + (ux * vy - uy * vx) * face2.normal[2];
11779
+ if (along === 0) continue;
11780
+ indices.push(p, ...along > 0 ? [q, r] : [r, q]);
11781
+ }
11782
+ return { corners, indices };
11783
+ }
11784
+ function pack(json, bin) {
11785
+ const text2 = new TextEncoder().encode(JSON.stringify(json));
11786
+ const jsonLength = Math.ceil(text2.length / 4) * 4;
11787
+ const out = new Uint8Array(12 + 8 + jsonLength + 8 + bin.length);
11788
+ const view = new DataView(out.buffer);
11789
+ view.setUint32(0, 1179937895, true);
11790
+ view.setUint32(4, 2, true);
11791
+ view.setUint32(8, out.length, true);
11792
+ view.setUint32(12, jsonLength, true);
11793
+ view.setUint32(16, 1313821514, true);
11794
+ out.fill(32, 20, 20 + jsonLength);
11795
+ out.set(text2, 20);
11796
+ view.setUint32(20 + jsonLength, bin.length, true);
11797
+ view.setUint32(24 + jsonLength, 5130562, true);
11798
+ out.set(bin, 28 + jsonLength);
11799
+ return out;
11800
+ }
11801
+ function sceneGlb(scene, options) {
11802
+ const chunks = [];
11803
+ let length2 = 0;
11804
+ const bufferViews = [];
11805
+ const addView = (bytes, target) => {
11806
+ bufferViews.push({ buffer: 0, byteOffset: length2, byteLength: bytes.length, ...target !== void 0 ? { target } : {} });
11807
+ const padded = Math.ceil(bytes.length / 4) * 4;
11808
+ const chunk2 = new Uint8Array(padded);
11809
+ chunk2.set(bytes);
11810
+ chunks.push(chunk2);
11811
+ length2 += padded;
11812
+ return bufferViews.length - 1;
11813
+ };
11814
+ const bytesOf = (array2) => new Uint8Array(array2.buffer, array2.byteOffset, array2.byteLength);
11815
+ const images = [];
11816
+ const pictures = /* @__PURE__ */ new Map();
11817
+ const painted = scene.faces.filter((face2) => face2.paint !== void 0);
11818
+ for (const paint2 of new Set(painted.map((face2) => face2.paint))) {
11819
+ const texture = paint2.texture;
11820
+ if (texture) {
11821
+ const sign = texture.mirrored ? -1 : 1;
11822
+ images.push({ bufferView: addView(options.png(texture)), mimeType: "image/png", name: texture.mirrored ? "board bottom" : "board top" });
11823
+ pictures.set(paint2, { image: images.length - 1, map: (p) => [(texture.origin.x + sign * p[0] * texture.pxPerMm) / texture.width, (texture.origin.y - p[1] * texture.pxPerMm) / texture.height] });
11824
+ continue;
11825
+ }
11826
+ let [low, high] = [Infinity, -Infinity];
11827
+ for (const face2 of painted) {
11828
+ if (face2.paint !== paint2) continue;
11829
+ for (const point of face2.loops.flat()) [low, high] = [Math.min(low, point[2]), Math.max(high, point[2])];
11830
+ }
11831
+ const span = high - low || 1;
11832
+ const [x, y] = painted.find((face2) => face2.paint === paint2).loops[0]?.[0] ?? [0, 0];
11833
+ const rgba = new Uint8ClampedArray(STRIP_WIDTH * STRIP_HEIGHT * 4);
11834
+ const colour = new Float32Array(3);
11835
+ for (let row3 = 0; row3 < STRIP_HEIGHT; row3++) {
11836
+ const alpha = paint2.at(x, y, high - (row3 + 0.5) / STRIP_HEIGHT * span, colour, true);
11837
+ for (let column = 0; column < STRIP_WIDTH; column++) rgba.set([colour[0], colour[1], colour[2], alpha * 255], (row3 * STRIP_WIDTH + column) * 4);
11838
+ }
11839
+ images.push({ bufferView: addView(options.png({ rgba, width: STRIP_WIDTH, height: STRIP_HEIGHT })), mimeType: "image/png", name: "board edge" });
11840
+ pictures.set(paint2, { image: images.length - 1, map: (p) => [0.5, (high - p[2]) / span] });
11841
+ }
11842
+ const materials = [];
11843
+ const materialOf = /* @__PURE__ */ new Map();
11844
+ const material = (face2) => {
11845
+ const picture = face2.paint ? pictures.get(face2.paint) : void 0;
11846
+ const key = picture ? `picture ${picture.image}` : `${face2.color.join(",")} ${face2.alpha} ${face2.material ?? "matt"}`;
11847
+ const known = materialOf.get(key);
11848
+ if (known !== void 0) return known;
11849
+ const made = picture ? { name: images[picture.image]?.name, pbrMetallicRoughness: { baseColorTexture: { index: picture.image }, ...BOARD_SURFACE }, ...face2.paint?.texture ? { alphaMode: "MASK", alphaCutoff: 0.5 } : {} } : {
11850
+ pbrMetallicRoughness: { baseColorFactor: [linear(face2.color[0]), linear(face2.color[1]), linear(face2.color[2]), face2.alpha], ...SURFACE[face2.material ?? "matt"] },
11851
+ ...face2.alpha < 1 ? { alphaMode: "BLEND" } : {}
11852
+ };
11853
+ materials.push(made);
11854
+ materialOf.set(key, materials.length - 1);
11855
+ return materials.length - 1;
11856
+ };
11857
+ const owners = [...new Set(scene.faces.map((face2) => face2.part))].sort((a, b) => a - b);
11858
+ const accessors = [];
11859
+ const meshes = [];
11860
+ const children = [];
11861
+ const nodes = [{ name: options.name, matrix: TO_METRES_Y_UP, children }];
11862
+ for (const owner of owners) {
11863
+ const gathered = /* @__PURE__ */ new Map();
11864
+ for (const face2 of scene.faces) {
11865
+ if (face2.part !== owner) continue;
11866
+ const { corners, indices } = triangles(face2);
11867
+ if (indices.length === 0) continue;
11868
+ const number = material(face2);
11869
+ const map = face2.paint ? pictures.get(face2.paint)?.map : void 0;
11870
+ const into = gathered.get(number) ?? { material: number, positions: [], normals: [], uvs: map ? [] : void 0, indices: [] };
11871
+ gathered.set(number, into);
11872
+ const first = into.positions.length / 3;
11873
+ for (const corner of corners) {
11874
+ into.positions.push(...corner);
11875
+ into.normals.push(...face2.normal);
11876
+ if (map) into.uvs?.push(...map(corner));
11877
+ }
11878
+ for (const index of indices) into.indices.push(first + index);
11879
+ }
11880
+ if (gathered.size === 0) continue;
11881
+ const primitives = [...gathered.values()].map((one) => {
11882
+ const positions = new Float32Array(one.positions);
11883
+ const min = [Infinity, Infinity, Infinity];
11884
+ const max = [-Infinity, -Infinity, -Infinity];
11885
+ positions.forEach((value, i) => {
11886
+ min[i % 3] = Math.min(min[i % 3], value);
11887
+ max[i % 3] = Math.max(max[i % 3], value);
11888
+ });
11889
+ const accessor = (array2, type, target, more = {}) => {
11890
+ const width = type === "VEC3" ? 3 : type === "VEC2" ? 2 : 1;
11891
+ accessors.push({ bufferView: addView(bytesOf(array2), target), componentType: array2 instanceof Float32Array ? FLOAT : UINT, count: array2.length / width, type, ...more });
11892
+ return accessors.length - 1;
11893
+ };
11894
+ const attributes = {
11895
+ POSITION: accessor(positions, "VEC3", ARRAY_BUFFER, { min, max }),
11896
+ NORMAL: accessor(new Float32Array(one.normals), "VEC3", ARRAY_BUFFER),
11897
+ ...one.uvs ? { TEXCOORD_0: accessor(new Float32Array(one.uvs), "VEC2", ARRAY_BUFFER) } : {}
11898
+ };
11899
+ return { attributes, indices: accessor(new Uint32Array(one.indices), "SCALAR", ELEMENT_ARRAY_BUFFER), material: one.material };
11900
+ });
11901
+ const name = owner < 0 ? "board" : options.names[owner] ?? `part ${owner + 1}`;
11902
+ meshes.push({ name, primitives });
11903
+ nodes.push({ name, mesh: meshes.length - 1 });
11904
+ children.push(nodes.length - 1);
11905
+ }
11906
+ if (meshes.length === 0) throw new Error("Nothing to write: the scene has no faces");
11907
+ const bin = new Uint8Array(length2);
11908
+ chunks.reduce((offset, chunk2) => (bin.set(chunk2, offset), offset + chunk2.length), 0);
11909
+ const json = {
11910
+ asset: { version: "2.0", generator: "copperflow" },
11911
+ scene: 0,
11912
+ scenes: [{ name: options.name, nodes: [0] }],
11913
+ nodes,
11914
+ meshes,
11915
+ materials,
11916
+ accessors,
11917
+ bufferViews,
11918
+ buffers: [{ byteLength: bin.length }],
11919
+ ...images.length > 0 ? { images, textures: images.map((_, source) => ({ source, sampler: 0 })), samplers: [{ magFilter: LINEAR, minFilter: LINEAR_MIPMAP_LINEAR, wrapS: CLAMP_TO_EDGE, wrapT: CLAMP_TO_EDGE }] } : {}
11920
+ };
11921
+ return pack(json, bin);
11922
+ }
11923
+
11924
+ // studio/src/render/png-bytes.ts
11925
+ import { deflateSync } from "node:zlib";
11926
+ var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
11927
+ var CRC_TABLE = Uint32Array.from({ length: 256 }, (_, n) => {
11928
+ let c = n;
11929
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
11930
+ return c >>> 0;
11931
+ });
11932
+ function crc(bytes) {
11933
+ let c = 4294967295;
11934
+ for (const byte of bytes) c = CRC_TABLE[(c ^ byte) & 255] ^ c >>> 8;
11935
+ return (c ^ 4294967295) >>> 0;
11936
+ }
11937
+ function chunk(kind, data) {
11938
+ const out = new Uint8Array(12 + data.length);
11939
+ const view = new DataView(out.buffer);
11940
+ view.setUint32(0, data.length);
11941
+ out.set(new TextEncoder().encode(kind), 4);
11942
+ out.set(data, 8);
11943
+ view.setUint32(8 + data.length, crc(out.subarray(4, 8 + data.length)));
11944
+ return out;
11945
+ }
11946
+ function pngBytes(image) {
11947
+ const { rgba, width, height } = image;
11948
+ const header = new Uint8Array(13);
11949
+ const view = new DataView(header.buffer);
11950
+ view.setUint32(0, width);
11951
+ view.setUint32(4, height);
11952
+ header.set([8, 6, 0, 0, 0], 8);
11953
+ const row3 = width * 4;
11954
+ const raw = new Uint8Array((row3 + 1) * height);
11955
+ for (let y = 0; y < height; y++) raw.set(rgba.subarray(y * row3, (y + 1) * row3), y * (row3 + 1) + 1);
11956
+ const parts = [Uint8Array.from(SIGNATURE), chunk("IHDR", header), chunk("IDAT", deflateSync(raw)), chunk("IEND", new Uint8Array(0))];
11957
+ const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
11958
+ parts.reduce((offset, part) => (out.set(part, offset), offset + part.length), 0);
11959
+ return out;
11960
+ }
11961
+
11962
+ // studio/src/render/model-render.ts
11963
+ function modelGlb(design, request = {}) {
11964
+ const look = request.look ?? {};
11965
+ if (look.background !== void 0) throw new Error("a model has no background: that is for pictures");
11966
+ resolveLook(look);
11967
+ const { model, scene } = lookScene(design, look);
11968
+ if (scene.faces.length === 0) throw new Error("Nothing to write: the design has no board outline and no parts");
11969
+ const glb = sceneGlb(scene, { name: designName(design.file), names: model.parts.map((part) => part.name), png: pngBytes });
11970
+ return { glb, what: model.board ? shapesWords(model, look) : `${partsWords(model)} (no board outline)`, parts: model.parts.length };
11971
+ }
11972
+
10028
11973
  // studio/src/render/node-render.ts
10029
11974
  async function renderDesign(design, request) {
10030
11975
  if (request.view === "3d") return renderLook(design, { ...request.angle ? { angle: request.angle } : {}, ...request.look ? { look: request.look } : {}, ...request.width !== void 0 ? { width: request.width } : {} });
@@ -10061,5 +12006,6 @@ async function renderDesign(design, request) {
10061
12006
  return { png: new Uint8Array(png), width: size.width, height: size.height, what, ...frame.page !== void 0 ? { page: frame.page } : {} };
10062
12007
  }
10063
12008
  export {
12009
+ modelGlb,
10064
12010
  renderDesign
10065
12011
  };