copperflow 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +13 -4
  2. package/dist/app/assets/NewPartDialog-ZQ4Y3m45.js +1 -0
  3. package/dist/app/assets/PackagesDialog-C8ZyWl-g.css +1 -0
  4. package/dist/app/assets/PackagesDialog-vEzilmpR.js +2 -0
  5. package/dist/app/assets/{VerifyPartDialog-Ey6xpQ_U.js → VerifyPartDialog-DYr1UIds.js} +2 -2
  6. package/dist/app/assets/footprint-preview-Nyk2poiN.js +160 -0
  7. package/dist/app/assets/index-BUjGdMvr.js +20 -0
  8. package/dist/app/assets/index-CF7-tL4t.css +1 -0
  9. package/dist/app/index.html +2 -2
  10. package/dist/cli-commands.js +21 -0
  11. package/dist/cli-commands.js.map +1 -1
  12. package/dist/core/model-export.d.ts +33 -0
  13. package/dist/core/model-export.js +33 -0
  14. package/dist/core/model-export.js.map +1 -0
  15. package/dist/core/packages.d.ts +18 -0
  16. package/dist/core/packages.js +49 -0
  17. package/dist/core/packages.js.map +1 -0
  18. package/dist/core/render.d.ts +2 -1
  19. package/dist/core/render.js.map +1 -1
  20. package/dist/engine/footprints/array.d.ts +4 -0
  21. package/dist/engine/footprints/array.js +51 -0
  22. package/dist/engine/footprints/array.js.map +1 -0
  23. package/dist/engine/footprints/axial.d.ts +6 -0
  24. package/dist/engine/footprints/axial.js +115 -0
  25. package/dist/engine/footprints/axial.js.map +1 -0
  26. package/dist/engine/footprints/catalogue.d.ts +39 -0
  27. package/dist/engine/footprints/catalogue.js +284 -0
  28. package/dist/engine/footprints/catalogue.js.map +1 -0
  29. package/dist/engine/footprints/chip.js +10 -1
  30. package/dist/engine/footprints/chip.js.map +1 -1
  31. package/dist/engine/footprints/connector.d.ts +16 -0
  32. package/dist/engine/footprints/connector.js +31 -0
  33. package/dist/engine/footprints/connector.js.map +1 -0
  34. package/dist/engine/footprints/dcjack.d.ts +3 -0
  35. package/dist/engine/footprints/dcjack.js +46 -0
  36. package/dist/engine/footprints/dcjack.js.map +1 -0
  37. package/dist/engine/footprints/dpak.d.ts +7 -0
  38. package/dist/engine/footprints/dpak.js +172 -0
  39. package/dist/engine/footprints/dpak.js.map +1 -0
  40. package/dist/engine/footprints/dual.d.ts +11 -2
  41. package/dist/engine/footprints/dual.js +113 -12
  42. package/dist/engine/footprints/dual.js.map +1 -1
  43. package/dist/engine/footprints/index.js +46 -3
  44. package/dist/engine/footprints/index.js.map +1 -1
  45. package/dist/engine/footprints/inductor.d.ts +3 -0
  46. package/dist/engine/footprints/inductor.js +32 -0
  47. package/dist/engine/footprints/inductor.js.map +1 -0
  48. package/dist/engine/footprints/known.js +114 -14
  49. package/dist/engine/footprints/known.js.map +1 -1
  50. package/dist/engine/footprints/ledsmd.d.ts +3 -0
  51. package/dist/engine/footprints/ledsmd.js +52 -0
  52. package/dist/engine/footprints/ledsmd.js.map +1 -0
  53. package/dist/engine/footprints/ledth.d.ts +4 -0
  54. package/dist/engine/footprints/ledth.js +45 -0
  55. package/dist/engine/footprints/ledth.js.map +1 -0
  56. package/dist/engine/footprints/melf.d.ts +8 -0
  57. package/dist/engine/footprints/melf.js +56 -0
  58. package/dist/engine/footprints/melf.js.map +1 -0
  59. package/dist/engine/footprints/plcc.d.ts +4 -0
  60. package/dist/engine/footprints/plcc.js +117 -0
  61. package/dist/engine/footprints/plcc.js.map +1 -0
  62. package/dist/engine/footprints/resonator.d.ts +3 -0
  63. package/dist/engine/footprints/resonator.js +33 -0
  64. package/dist/engine/footprints/resonator.js.map +1 -0
  65. package/dist/engine/footprints/screw.d.ts +3 -0
  66. package/dist/engine/footprints/screw.js +51 -0
  67. package/dist/engine/footprints/screw.js.map +1 -0
  68. package/dist/engine/footprints/smallsot.d.ts +8 -0
  69. package/dist/engine/footprints/smallsot.js +143 -0
  70. package/dist/engine/footprints/smallsot.js.map +1 -0
  71. package/dist/engine/footprints/smdbox.d.ts +33 -0
  72. package/dist/engine/footprints/smdbox.js +76 -0
  73. package/dist/engine/footprints/smdbox.js.map +1 -0
  74. package/dist/engine/footprints/smdcan.d.ts +3 -0
  75. package/dist/engine/footprints/smdcan.js +61 -0
  76. package/dist/engine/footprints/smdcan.js.map +1 -0
  77. package/dist/engine/footprints/smdip.d.ts +4 -0
  78. package/dist/engine/footprints/smdip.js +58 -0
  79. package/dist/engine/footprints/smdip.js.map +1 -0
  80. package/dist/engine/footprints/socket.d.ts +8 -0
  81. package/dist/engine/footprints/socket.js +21 -0
  82. package/dist/engine/footprints/socket.js.map +1 -0
  83. package/dist/engine/footprints/sod.d.ts +6 -0
  84. package/dist/engine/footprints/sod.js +63 -6
  85. package/dist/engine/footprints/sod.js.map +1 -1
  86. package/dist/engine/footprints/sot.d.ts +1 -1
  87. package/dist/engine/footprints/sot.js +17 -2
  88. package/dist/engine/footprints/sot.js.map +1 -1
  89. package/dist/engine/footprints/tact.d.ts +3 -0
  90. package/dist/engine/footprints/tact.js +65 -0
  91. package/dist/engine/footprints/tact.js.map +1 -0
  92. package/dist/engine/footprints/tantalum.d.ts +7 -0
  93. package/dist/engine/footprints/tantalum.js +91 -0
  94. package/dist/engine/footprints/tantalum.js.map +1 -0
  95. package/dist/engine/footprints/to92inline.d.ts +14 -0
  96. package/dist/engine/footprints/to92inline.js +21 -0
  97. package/dist/engine/footprints/to92inline.js.map +1 -0
  98. package/dist/engine/footprints/topower.d.ts +7 -0
  99. package/dist/engine/footprints/topower.js +119 -0
  100. package/dist/engine/footprints/topower.js.map +1 -0
  101. package/dist/engine/footprints/usb.d.ts +32 -0
  102. package/dist/engine/footprints/usb.js +109 -0
  103. package/dist/engine/footprints/usb.js.map +1 -0
  104. package/dist/engine/footprints/xtal.d.ts +4 -0
  105. package/dist/engine/footprints/xtal.js +61 -0
  106. package/dist/engine/footprints/xtal.js.map +1 -0
  107. package/dist/engine/rules/rotations.d.ts +12 -3
  108. package/dist/engine/rules/rotations.js +77 -2
  109. package/dist/engine/rules/rotations.js.map +1 -1
  110. package/dist/engine/solid/heights-smd.d.ts +3 -0
  111. package/dist/engine/solid/heights-smd.js +81 -0
  112. package/dist/engine/solid/heights-smd.js.map +1 -0
  113. package/dist/engine/solid/heights-through.d.ts +7 -0
  114. package/dist/engine/solid/heights-through.js +93 -0
  115. package/dist/engine/solid/heights-through.js.map +1 -0
  116. package/dist/engine/solid/heights-uno.d.ts +2 -0
  117. package/dist/engine/solid/heights-uno.js +15 -0
  118. package/dist/engine/solid/heights-uno.js.map +1 -0
  119. package/dist/engine/solid/heights.d.ts +2 -0
  120. package/dist/engine/solid/heights.js +43 -18
  121. package/dist/engine/solid/heights.js.map +1 -1
  122. package/dist/mcp/guide.d.ts +3 -1
  123. package/dist/mcp/guide.js +15 -4
  124. package/dist/mcp/guide.js.map +1 -1
  125. package/dist/mcp/model-tool.d.ts +31 -0
  126. package/dist/mcp/model-tool.js +27 -0
  127. package/dist/mcp/model-tool.js.map +1 -0
  128. package/dist/mcp/server.js +2 -0
  129. package/dist/mcp/server.js.map +1 -1
  130. package/dist/render/render.js +1937 -260
  131. package/dist/version.d.ts +1 -1
  132. package/dist/version.js +1 -1
  133. package/package.json +2 -1
  134. package/skills/copperflow/references/design-rules.md +9 -6
  135. package/skills/copperflow/references/editable-subset.md +18 -8
  136. package/skills/copperflow/references/parts-library.md +2 -1
  137. package/skills/copperflow/references/writing-circuits.md +6 -0
  138. package/dist/app/assets/NewPartDialog-BBJaZFCo.js +0 -160
  139. package/dist/app/assets/index-BKoIKo22.css +0 -1
  140. package/dist/app/assets/index-DPmr2dR1.js +0 -20
@@ -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
  };
@@ -5753,8 +5753,8 @@ var SilkObstacles = class {
5753
5753
  if (obstacle.component === part.component && obstacle.kind !== "pad") continue;
5754
5754
  const between = obstacle.kind === "courtyard" && spaced && !overlap(box3, obstacle.box) && overlap(reach, obstacle.box);
5755
5755
  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);
5756
+ const area2 = overlapArea(box3, obstacle.box);
5757
+ const weight = between ? BETWEEN : WEIGHT[obstacle.kind] * (obstacle.kind === "courtyard" ? Math.max(area2, 1e-3) : 1 + area2);
5758
5758
  found.score += weight;
5759
5759
  if (between) found.between += 1;
5760
5760
  else found.fixed += weight;
@@ -5889,7 +5889,7 @@ function placeDesignators(pcb, expansion, clearance) {
5889
5889
  const parts = pcb.parts.filter((part) => part.component !== "");
5890
5890
  const obstacles = obstaclesOf(pcb, expansion, clearance);
5891
5891
  const chosen = /* @__PURE__ */ new Map();
5892
- const settle = (part, place3) => {
5892
+ const settle2 = (part, place3) => {
5893
5893
  chosen.set(part.component, place3);
5894
5894
  obstacles.add("designator", part.component, part.side, textBox(part.component, place3.at, place3.rotation));
5895
5895
  };
@@ -5917,14 +5917,14 @@ function placeDesignators(pcb, expansion, clearance) {
5917
5917
  }
5918
5918
  return least.place;
5919
5919
  };
5920
- for (const part of parts) if (part.nameAt) settle(part, { at: part.nameAt, rotation: part.nameRotation ?? 0 });
5920
+ for (const part of parts) if (part.nameAt) settle2(part, { at: part.nameAt, rotation: part.nameRotation ?? 0 });
5921
5921
  const room = new Map(parts.filter((part) => !part.nameAt).map((part) => [part.component, roomAround(part, tries(part), (place3) => obstacles.covered(part, place3))]));
5922
5922
  const ordered = placingOrder(parts.filter((part) => !part.nameAt), (part) => room.get(part.component) ?? { clear: 0, fair: 0 });
5923
5923
  for (const members of ordered) {
5924
- if (members.length > 1) placeCopies(members, tries, clear, best, settle);
5925
- else settle(members[0], best(members[0]));
5924
+ if (members.length > 1) placeCopies(members, tries, clear, best, settle2);
5925
+ else settle2(members[0], best(members[0]));
5926
5926
  }
5927
- makeRoom(parts, chosen, { tries, clear, fair, settle, covered: (part, place3) => obstacles.covered(part, place3), remove: (part) => obstacles.remove(part.component) });
5927
+ makeRoom(parts, chosen, { tries, clear, fair, settle: settle2, covered: (part, place3) => obstacles.covered(part, place3), remove: (part) => obstacles.remove(part.component) });
5928
5928
  return parts.map((part) => {
5929
5929
  const place3 = chosen.get(part.component);
5930
5930
  const covered = obstacles.covered(part, place3, false);
@@ -6004,13 +6004,13 @@ function tryMoving(part, place3, byName, chosen, placer2) {
6004
6004
  before.forEach(([blocker, was]) => placer2.settle(blocker, was));
6005
6005
  return false;
6006
6006
  }
6007
- function placeCopies(members, tries, clear, best, settle) {
6007
+ function placeCopies(members, tries, clear, best, settle2) {
6008
6008
  const lists = members.map(tries);
6009
6009
  const count = Math.min(...lists.map((list) => list.length));
6010
6010
  const fitsAll = (i) => members.every((member, m) => clear(member, lists[m]?.[i])) && copiesApart(members, lists, i);
6011
6011
  for (let i = 0; i < count; i++) {
6012
6012
  if (!fitsAll(i)) continue;
6013
- members.forEach((member, m) => settle(member, lists[m]?.[i]));
6013
+ members.forEach((member, m) => settle2(member, lists[m]?.[i]));
6014
6014
  return;
6015
6015
  }
6016
6016
  let most = { index: -1, clear: 0 };
@@ -6021,10 +6021,10 @@ function placeCopies(members, tries, clear, best, settle) {
6021
6021
  const rest = [];
6022
6022
  members.forEach((member, m) => {
6023
6023
  const same = most.index >= 0 ? lists[m]?.[most.index] : void 0;
6024
- if (same && clear(member, same)) settle(member, same);
6024
+ if (same && clear(member, same)) settle2(member, same);
6025
6025
  else rest.push(member);
6026
6026
  });
6027
- rest.forEach((member) => settle(member, best(member)));
6027
+ rest.forEach((member) => settle2(member, best(member)));
6028
6028
  }
6029
6029
  function copiesApart(members, lists, i) {
6030
6030
  const boxes = members.map((member, m) => {
@@ -6094,8 +6094,8 @@ var among = (items, kept) => {
6094
6094
  };
6095
6095
  var sameEnd = (a, b) => a !== void 0 && a.x === b.x && a.y === b.y;
6096
6096
  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);
6097
+ function segmentFits(segment2, points) {
6098
+ return sameEnd(points[segment2.index], segment2.from) && sameEnd(points[segment2.index + 1], segment2.to);
6099
6099
  }
6100
6100
  var EMPTY = { names: [], wires: [], labels: [], drawings: [], copper: [], texts: [], board: [] };
6101
6101
  var KEYS = ["names", "wires", "labels", "drawings", "copper", "texts", "board"];
@@ -6118,7 +6118,7 @@ var Selection = class _Selection {
6118
6118
  board;
6119
6119
  /** The segment of the track selected alone that a double click picked; undefined when the whole track (or anything else) is. */
6120
6120
  segment;
6121
- constructor(lists, segment) {
6121
+ constructor(lists, segment2) {
6122
6122
  this.names = Object.freeze([...lists.names]);
6123
6123
  this.wires = Object.freeze([...lists.wires]);
6124
6124
  this.labels = Object.freeze([...lists.labels]);
@@ -6126,7 +6126,7 @@ var Selection = class _Selection {
6126
6126
  this.copper = Object.freeze([...lists.copper]);
6127
6127
  this.texts = Object.freeze([...lists.texts]);
6128
6128
  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 }) });
6129
+ this.segment = segment2 && Object.freeze({ id: segment2.id, index: segment2.index, from: Object.freeze({ ...segment2.from }), to: Object.freeze({ ...segment2.to }) });
6130
6130
  Object.freeze(this);
6131
6131
  }
6132
6132
  static from(lists) {
@@ -6266,8 +6266,8 @@ var Selection = class _Selection {
6266
6266
  return this.soleCopper === id && !this.segment ? this : new _Selection({ ...EMPTY, copper: [id] });
6267
6267
  }
6268
6268
  /** Just this segment of its track. */
6269
- onlySegment(segment) {
6270
- return sameSegment(this.segment, segment) ? this : new _Selection({ ...EMPTY, copper: [segment.id] }, segment);
6269
+ onlySegment(segment2) {
6270
+ return sameSegment(this.segment, segment2) ? this : new _Selection({ ...EMPTY, copper: [segment2.id] }, segment2);
6271
6271
  }
6272
6272
  /** The part taken out when it is in, else added as the primary; the other kinds stay. */
6273
6273
  toggle(name) {
@@ -7047,18 +7047,18 @@ function onSegment(p, a, b) {
7047
7047
  return straight && within(p.x, a.x, b.x) && within(p.y, a.y, b.y);
7048
7048
  }
7049
7049
  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)));
7050
+ 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
7051
  }
7052
7052
  function drawWires(ctx, layout, options, px, line2) {
7053
7053
  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);
7054
+ for (const wire2 of layout.wires) {
7055
+ if (options.movingLabels?.some((m) => m.hideWire === wire2.id)) continue;
7056
+ const selected = options.selectedWires?.includes(wire2.id) ?? false;
7057
+ const tone = selected ? { color: sheetPalette().selection, alpha: 1 } : toneOf2(wire2.net, options.highlight);
7058
7058
  ctx.strokeStyle = tone.color ?? sheetPalette().wire;
7059
7059
  ctx.globalAlpha = tone.alpha;
7060
7060
  glow(ctx, selected);
7061
- path(ctx, wire.points);
7061
+ path(ctx, wire2.points);
7062
7062
  ctx.stroke();
7063
7063
  }
7064
7064
  glow(ctx, false);
@@ -7148,14 +7148,14 @@ function paintShape(ctx, shape) {
7148
7148
  ctx.stroke();
7149
7149
  }
7150
7150
  }
7151
- function textLabel(shape, frame, fallback) {
7151
+ function textLabel(shape, frame, fallback2) {
7152
7152
  const along = shape.anchor === "left" ? 1 : shape.anchor === "right" ? -1 : 0;
7153
7153
  const angle = rad2(frame.rotation);
7154
7154
  const dx = along * Math.cos(angle);
7155
7155
  const dy = along * Math.sin(angle);
7156
7156
  const anchor = Math.abs(dx) > 0.5 ? dx > 0 ? "left" : "right" : Math.abs(dy) > 0.5 ? dy > 0 ? "bottom" : "top" : "center";
7157
7157
  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 };
7158
+ return { text: shape.text, at: place2(shape.at, frame), size: shape.size, anchor, color: sheetPalette()[TEXT_COLORS[shape.role]] ?? fallback2, ...role };
7159
7159
  }
7160
7160
  function pinFrame(shape, frame) {
7161
7161
  const side = shape.anchor === "left" ? "left" : shape.anchor === "right" ? "right" : shape.at.y > 0 ? "top" : "bottom";
@@ -7276,24 +7276,24 @@ function drawRoutes(ctx, scene, layers) {
7276
7276
  }
7277
7277
  ctx.globalAlpha = 1;
7278
7278
  }
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;
7279
+ function markedPoints(scene, track, wash2) {
7280
+ const { segment: segment2 } = scene;
7281
+ return wash2 && segment2?.id === track.id && segmentFits(segment2, track.points) ? [segment2.from, segment2.to] : track.points;
7282
7282
  }
7283
- function mark(ctx, scene, layers, id, color, wash, px) {
7283
+ function mark(ctx, scene, layers, id, color, wash2, px) {
7284
7284
  const track = scene.tracks.find((one) => one.id === id);
7285
7285
  if (track && trackShown(track, layers)) {
7286
- const points = markedPoints(scene, track, wash);
7286
+ const points = markedPoints(scene, track, wash2);
7287
7287
  strokePath(ctx, points, color, track.width + 2 * OUTLINE_PX * px);
7288
7288
  strokePath(ctx, points, trackColor(track), track.width);
7289
- if (wash) strokePath(ctx, points, PALETTE.selectionFill, track.width);
7289
+ if (wash2) strokePath(ctx, points, PALETTE.selectionFill, track.width);
7290
7290
  return;
7291
7291
  }
7292
7292
  const via = scene.vias.find((one) => one.id === id);
7293
7293
  if (!via || !viaShown(via, layers)) return;
7294
7294
  disc(ctx, via.at, via.diameter / 2 + OUTLINE_PX * px, color);
7295
7295
  disc(ctx, via.at, via.diameter / 2, ringColor(via));
7296
- if (wash) disc(ctx, via.at, via.diameter / 2, PALETTE.selectionFill);
7296
+ if (wash2) disc(ctx, via.at, via.diameter / 2, PALETTE.selectionFill);
7297
7297
  if (layers.hole) disc(ctx, via.at, via.drill / 2, PALETTE.drill);
7298
7298
  }
7299
7299
  function drawCopperItems(ctx, scene, layers, highlight, px) {
@@ -7952,7 +7952,7 @@ function drawingBox(drawing) {
7952
7952
  function drawingExtents(layout) {
7953
7953
  const boxes = [...sheetBoxes(layout).map((part) => part.box), ...sheetTexts(layout).map((text2) => text2.box)];
7954
7954
  boxes.push(...layout.labels.map(labelHitBox), ...layout.drawings.map(drawingBox));
7955
- const points = [...layout.wires.flatMap((wire) => wire.points), ...layout.junctions];
7955
+ const points = [...layout.wires.flatMap((wire2) => wire2.points), ...layout.junctions];
7956
7956
  const pointBox = pointBounds(points);
7957
7957
  if (pointBox) boxes.push(pointBox);
7958
7958
  return unionBoxes(boxes);
@@ -8138,18 +8138,18 @@ function parseFootprint(text2) {
8138
8138
  const [head = "", ...segments] = text2.trim().toLowerCase().split("_");
8139
8139
  const match = HEAD.exec(head);
8140
8140
  if (!match || head === "") return void 0;
8141
- const [, kind = "", code = "", cross2, suffix = ""] = match;
8141
+ const [, kind = "", code = "", cross3, suffix = ""] = match;
8142
8142
  const variant = VARIANT.test(segments[0] ?? "") ? segments[0] : void 0;
8143
8143
  const rest = variant === void 0 ? segments : segments.slice(1);
8144
- const sizes = rest.filter((segment) => PAIR.test(segment));
8144
+ const sizes = rest.filter((segment2) => PAIR.test(segment2));
8145
8145
  if (sizes.length > 1) return void 0;
8146
- const fields = parseParams(rest.filter((segment) => !PAIR.test(segment)));
8146
+ const fields = parseParams(rest.filter((segment2) => !PAIR.test(segment2)));
8147
8147
  if (!fields) return void 0;
8148
8148
  const size = sizes[0] === void 0 ? void 0 : pair(sizes[0]);
8149
8149
  return {
8150
8150
  kind,
8151
8151
  code,
8152
- ...cross2 === void 0 ? {} : { cross: cross2 },
8152
+ ...cross3 === void 0 ? {} : { cross: cross3 },
8153
8153
  ...suffix === "" ? {} : { suffix },
8154
8154
  ...variant === void 0 ? {} : { variant },
8155
8155
  ...size === void 0 ? {} : { size },
@@ -8164,8 +8164,8 @@ function pair(text2) {
8164
8164
  function parseParams(segments) {
8165
8165
  const params = {};
8166
8166
  const pairs = {};
8167
- for (const segment of segments) {
8168
- const match = PARAM.exec(segment);
8167
+ for (const segment2 of segments) {
8168
+ const match = PARAM.exec(segment2);
8169
8169
  if (!match) return void 0;
8170
8170
  const key = match[1] ?? "";
8171
8171
  const value = match[2] ?? "";
@@ -8182,6 +8182,182 @@ function parseParams(segments) {
8182
8182
  return { params, pairs };
8183
8183
  }
8184
8184
 
8185
+ // src/engine/solid/heights-smd.ts
8186
+ var row = (packages, height, source, matches) => ({ packages, height, source, matches });
8187
+ var bare = (p) => p.variant === void 0 && p.cross === void 0 && p.size === void 0;
8188
+ var named = (kind, code) => (p) => p.kind === kind && p.code === code && bare(p);
8189
+ var anyOf = (...tests) => (p) => tests.some((test) => test(p));
8190
+ var CHIPS = [
8191
+ 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),
8192
+ 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)
8193
+ ];
8194
+ 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));
8195
+ var DIODES = [
8196
+ flatLead("SOD-523", "523", 0.7),
8197
+ flatLead("SOD-923", "923", 0.4),
8198
+ 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)),
8199
+ flatLead("SOD-128", "128", 1.1)
8200
+ ];
8201
+ 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 ?? ""}`));
8202
+ var MELFS = [melf("MiniMELF (SOD-80, DO-213AA)", 1.6, ["minimelf", "sod80", "do213aa"]), melf("MELF (DO-213AB)", 2.6, ["melf", "do213ab"])];
8203
+ var SMALL_SOT = "makers' small SOT drawings";
8204
+ var SMALL_SOTS = [
8205
+ 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")),
8206
+ row("SOT-523, SC-89", 0.8, `${SMALL_SOT}: A max about 0.8 mm`, named("sot", "523")),
8207
+ row("SOT-563", 0.6, `${SMALL_SOT}: A max about 0.6 mm`, named("sot", "563")),
8208
+ row("SOT-723", 0.55, `${SMALL_SOT}: A max about 0.55 mm`, named("sot", "723")),
8209
+ row("SOT-143", 1.1, `${SMALL_SOT}: A max about 1.1 mm`, named("sot", "143")),
8210
+ 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")
8211
+ ];
8212
+ var SMALL_ICS = [
8213
+ row("MSOP (3 mm)", 1.1, "JEDEC MO-187 (MSOP), A max about 1.1 mm, typical", (p) => p.kind === "msop"),
8214
+ row("QSOP (150 mil)", 1.75, "JEDEC MO-137 (QSOP), A max about 1.75 mm, typical", (p) => p.kind === "qsop"),
8215
+ 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"),
8216
+ 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"),
8217
+ 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")
8218
+ ];
8219
+ var POWER = "makers' drawings, A max about";
8220
+ var POWERS = [
8221
+ 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")),
8222
+ 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"))
8223
+ ];
8224
+ 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";
8225
+ 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));
8226
+ var TANTALUMS = [
8227
+ tantalum("a", void 0, 1.8),
8228
+ tantalum("b", void 0, 2.1),
8229
+ tantalum("c", void 0, 2.8),
8230
+ tantalum("d", void 0, 3.1),
8231
+ tantalum("e", void 0, 4.3),
8232
+ tantalum("a", "3216", 1.8),
8233
+ tantalum("b", "3528", 2.1),
8234
+ tantalum("c", "6032", 2.8),
8235
+ tantalum("d", "7343", 3.1)
8236
+ ];
8237
+ 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);
8238
+ var ARRAYS = [array("4x0603", 0.5), array("4x0402", 0.35), array("2x0402", 0.35)];
8239
+ var CANS = [
8240
+ {
8241
+ packages: "surface-mount aluminium can",
8242
+ height: 0,
8243
+ source: "the can height written in the footprint name (smdcan8x10.2 is 10.2 mm), the whole part above the board",
8244
+ heightOf: (p) => Number(p.cross),
8245
+ matches: (p) => p.kind === "smdcan" && p.cross !== void 0
8246
+ }
8247
+ ];
8248
+ 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);
8249
+ var CRYSTALS = [
8250
+ xtal("xtal2016", 0.5),
8251
+ xtal("xtal2520", 0.6),
8252
+ xtal("xtal3225", 0.8),
8253
+ xtal("xtal5032", 1.2),
8254
+ xtal("xtal5032_2", 1.2),
8255
+ xtal("xtal3215", 0.9),
8256
+ xtal("xtal7050", 1.4),
8257
+ 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")
8258
+ ];
8259
+ 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);
8260
+ var LEDS = [led2("3528", 1.9), led2("5050", 1.6), led2("5050_6", 1.6)];
8261
+ var SMD_ROWS = [...CHIPS, ...DIODES, ...MELFS, ...SMALL_SOTS, ...SMALL_ICS, ...POWERS, ...TANTALUMS, ...ARRAYS, ...CANS, ...CRYSTALS, ...LEDS];
8262
+
8263
+ // src/engine/solid/heights-through.ts
8264
+ var AXIAL_GAP = 0.3;
8265
+ var AXIAL_DIAMETERS = [
8266
+ { upTo: 3.7, diameter: 1.8 },
8267
+ { upTo: 6.6, diameter: 2.5 },
8268
+ { upTo: 9.1, diameter: 3.5 },
8269
+ { upTo: 12.1, diameter: 4.5 },
8270
+ { upTo: Infinity, diameter: 5.5 }
8271
+ ];
8272
+ function axialDiameter(parsed2) {
8273
+ const given = parsed2.params["d"];
8274
+ if (typeof given === "number" && given > 0) return given;
8275
+ const length2 = Number(parsed2.code);
8276
+ return (AXIAL_DIAMETERS.find((row3) => length2 <= row3.upTo) ?? AXIAL_DIAMETERS[AXIAL_DIAMETERS.length - 1]).diameter;
8277
+ }
8278
+ 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`;
8279
+ var DIODE_SOURCE = (name, diameter) => `makers' ${name} drawings: maximum body diameter ${diameter} mm and about ${AXIAL_GAP} mm of gap under it`;
8280
+ var diode2 = (name, code, suffix, diameter) => ({
8281
+ packages: name,
8282
+ height: diameter + AXIAL_GAP,
8283
+ source: DIODE_SOURCE(name, diameter),
8284
+ matches: (p) => p.kind === "do" && p.code === code && p.suffix === suffix && p.variant === void 0
8285
+ });
8286
+ var screw = (packages, height, pitches) => ({
8287
+ packages,
8288
+ height,
8289
+ source: `makers' PCB screw terminal block drawings: about ${height} mm above the board at these pitches`,
8290
+ matches: (p) => p.kind === "screw" && pitches.includes(typeof p.params["p"] === "number" ? p.params["p"] : DEFAULT_SCREW_PITCH)
8291
+ });
8292
+ var DEFAULT_SCREW_PITCH = 5.08;
8293
+ var RADIAL_CANS = [[4, 7], [5, 11], [6.3, 11], [8, 11.5], [10, 16], [12.5, 20], [16, 25], [18, 35.5]];
8294
+ var RADIAL_SOURCE = "makers' drawings of general-purpose radial aluminium electrolytic series: the common can length for the diameter";
8295
+ 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";
8296
+ var radialDiameter = (p) => Number(p.code);
8297
+ var isRadial = (p) => p.kind === "radial" && Number.isFinite(radialDiameter(p)) && radialDiameter(p) > 0;
8298
+ var listed = (diameter) => RADIAL_CANS.some(([d]) => d === diameter);
8299
+ function nearestCan(diameter) {
8300
+ const best = RADIAL_CANS.reduce((a, b) => Math.abs(b[0] - diameter) < Math.abs(a[0] - diameter) ? b : a);
8301
+ return best[1];
8302
+ }
8303
+ var FINE_HEADER_SOURCE = (pitch, height) => `makers' ${pitch} mm pitch pin header drawings: about ${height} mm overall above the board`;
8304
+ var finePitch = (p) => {
8305
+ const pitch = p.params["p"];
8306
+ return p.kind === "pinrow" && typeof pitch === "number" && pitch < 2.54 ? pitch : void 0;
8307
+ };
8308
+ var FINE_HEADER_LIMIT = 1.5;
8309
+ var THROUGH_HOLE_ROWS = [
8310
+ {
8311
+ packages: "radial can, a listed diameter",
8312
+ height: 0,
8313
+ heightOf: (p) => nearestCan(radialDiameter(p)),
8314
+ source: RADIAL_SOURCE,
8315
+ matches: (p) => isRadial(p) && listed(radialDiameter(p))
8316
+ },
8317
+ {
8318
+ packages: "radial can, any other diameter",
8319
+ height: 0,
8320
+ heightOf: (p) => nearestCan(radialDiameter(p)),
8321
+ source: RADIAL_NEAREST_SOURCE,
8322
+ matches: (p) => isRadial(p) && !listed(radialDiameter(p))
8323
+ },
8324
+ { 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 },
8325
+ { packages: "pin header, 2 mm pitch", height: 6, source: FINE_HEADER_SOURCE("2", 6), matches: (p) => (finePitch(p) ?? 0) > FINE_HEADER_LIMIT },
8326
+ {
8327
+ packages: "axial resistor or diode",
8328
+ height: 0,
8329
+ heightOf: (p) => axialDiameter(p) + AXIAL_GAP,
8330
+ source: AXIAL_SOURCE,
8331
+ matches: (p) => p.kind === "axial" && p.code !== ""
8332
+ },
8333
+ diode2("DO-35", "35", void 0, 2),
8334
+ diode2("DO-41", "41", void 0, 2.7),
8335
+ diode2("DO-15", "15", void 0, 3.6),
8336
+ diode2("DO-201AD", "201", "ad", 5.3),
8337
+ { 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" },
8338
+ { 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" },
8339
+ screw("screw terminal block, 5 and 5.08 mm pitch", 10, [5, 5.08]),
8340
+ screw("screw terminal block, 3.5 and 3.81 mm pitch", 8.5, [3.5, 3.81]),
8341
+ { 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" },
8342
+ { 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" },
8343
+ { 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" }
8344
+ ];
8345
+
8346
+ // src/engine/solid/heights-uno.ts
8347
+ var row2 = (packages, height, source, matches) => ({ packages, height, source, matches });
8348
+ var isPlain = (p) => p.variant === void 0 && p.suffix === void 0 && p.size === void 0;
8349
+ var INDUCTOR_HEIGHTS = [[4, 2], [5, 2.5], [6, 3], [8, 4], [10, 5], [12, 6]];
8350
+ 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));
8351
+ var UNO_ROWS = [
8352
+ 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),
8353
+ 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),
8354
+ 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"),
8355
+ 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),
8356
+ 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),
8357
+ 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"),
8358
+ ...INDUCTOR_HEIGHTS.map(([side, height]) => inductor2(side, height))
8359
+ ];
8360
+
8185
8361
  // src/engine/solid/heights.ts
8186
8362
  var ASSUMED_HEIGHT = 1;
8187
8363
  var CHIP_SOURCE = "EIA/IEC 60384-21 chip capacitor sizes: thickness up to the body width plus its tolerance (resistors are thinner)";
@@ -8191,19 +8367,31 @@ var chip = (code, height) => ({
8191
8367
  source: CHIP_SOURCE,
8192
8368
  matches: (p) => p.kind === "" && p.code === code && p.variant === void 0
8193
8369
  });
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`,
8370
+ var BIG_CHIP_CAPACITOR_SOURCE = "makers' chip capacitor series: the thickest part commonly made in this size";
8371
+ var POWER_CHIP_SOURCE = "makers' power chip resistor series: thickness up to 0.7 mm in this size";
8372
+ var chipOf = (code, height, source) => ({
8373
+ packages: `chip ${code}`,
8374
+ height,
8375
+ source,
8376
+ matches: (p) => p.kind === "" && p.code === code && p.variant === void 0
8377
+ });
8378
+ var moulded = (name, jedec, height) => ({
8379
+ packages: `${name.toUpperCase()} (DO-214${jedec.toUpperCase()})`,
8198
8380
  height,
8199
- source: RADIAL_SOURCE,
8200
- matches: (p) => p.kind === "radial" && p.code === diameter
8381
+ source: `makers' ${name.toUpperCase()} (DO-214${jedec.toUpperCase()}) drawings: body thickness up to ${height} mm`,
8382
+ matches: (p) => p.variant === void 0 && (p.kind === name && p.code === "" || p.kind === "do" && p.code === "214" && p.suffix === jedec)
8201
8383
  });
8384
+ var isHeaderPitch = (p) => p.params["p"] === void 0 || p.params["p"] === 2.54;
8202
8385
  var HEIGHT_TABLE = [
8203
8386
  chip("0402", 0.55),
8204
8387
  chip("0603", 0.9),
8205
8388
  chip("0805", 1.45),
8206
8389
  chip("1206", 1.8),
8390
+ chip("0201", 0.33),
8391
+ chipOf("1210", 2.5, BIG_CHIP_CAPACITOR_SOURCE),
8392
+ chipOf("1812", 3.2, BIG_CHIP_CAPACITOR_SOURCE),
8393
+ chipOf("2010", 0.7, POWER_CHIP_SOURCE),
8394
+ chipOf("2512", 0.7, POWER_CHIP_SOURCE),
8207
8395
  {
8208
8396
  packages: "SOIC (narrow)",
8209
8397
  height: 1.75,
@@ -8220,11 +8408,24 @@ var HEIGHT_TABLE = [
8220
8408
  },
8221
8409
  { 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
8410
  { 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") },
8411
+ { 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 },
8412
+ { 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 },
8413
+ { packages: "SOP (208 mil)", height: 2.2, source: "makers' 208 mil SOP drawings, A max about 2.2 mm", matches: (p) => p.kind === "sop" },
8414
+ { packages: "SSOP", height: 2, source: "JEDEC MO-150 (SSOP), A max 2.0 mm", matches: (p) => p.kind === "ssop" },
8415
+ { packages: "TSSOP", height: 1.2, source: "JEDEC MO-153 (TSSOP), A max 1.2 mm", matches: (p) => p.kind === "tssop" },
8416
+ { 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
8417
  { packages: "QFN", height: 1, source: "JEDEC MO-220, A max 1.00 mm", matches: (p) => p.kind === "qfn" },
8224
8418
  { packages: "DFN", height: 1, source: "JEDEC MO-229, A max 1.00 mm", matches: (p) => p.kind === "dfn" },
8225
8419
  { 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
8420
  { 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" },
8421
+ { 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 },
8422
+ { 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") },
8423
+ moulded("sma", "ac", 2.4),
8424
+ moulded("smb", "aa", 2.4),
8425
+ moulded("smc", "ab", 2.7),
8426
+ { 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" },
8427
+ { 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" },
8428
+ { 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
8429
  {
8229
8430
  packages: "pin header, 2.54 mm pitch",
8230
8431
  height: 8.5,
@@ -8233,14 +8434,9 @@ var HEIGHT_TABLE = [
8233
8434
  },
8234
8435
  { 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
8436
  { 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)
8437
+ ...THROUGH_HOLE_ROWS,
8438
+ ...SMD_ROWS,
8439
+ ...UNO_ROWS
8244
8440
  ];
8245
8441
  function givenHeight(props) {
8246
8442
  const height = parseLength(props["height"]);
@@ -8250,9 +8446,10 @@ function partHeight(part) {
8250
8446
  const given = givenHeight(part.props);
8251
8447
  if (given !== void 0) return { height: given, source: "given", state: "given", assumed: false };
8252
8448
  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 };
8449
+ const row3 = parsed2 === void 0 ? void 0 : HEIGHT_TABLE.find((candidate) => candidate.matches(parsed2));
8450
+ if (row3 === void 0) return { height: ASSUMED_HEIGHT, source: "assumed", state: "assumed", assumed: true };
8451
+ const height = row3.heightOf?.(parsed2) ?? row3.height;
8452
+ return row3.document === void 0 ? { height, source: row3.source, state: "typical", assumed: false } : { height, source: row3.document, state: "read", assumed: false };
8256
8453
  }
8257
8454
 
8258
8455
  // src/engine/solid/thickness.ts
@@ -8273,8 +8470,8 @@ function doubledArea(points) {
8273
8470
  }
8274
8471
  return sum;
8275
8472
  }
8276
- function arcSweep(segment) {
8277
- const { from, to, centre, ccw } = segment;
8473
+ function arcSweep(segment2) {
8474
+ const { from, to, centre, ccw } = segment2;
8278
8475
  const start = Math.atan2(from.y - centre.y, from.x - centre.x);
8279
8476
  const end = Math.atan2(to.y - centre.y, to.x - centre.x);
8280
8477
  let sweep = ccw ? end - start : start - end;
@@ -8410,12 +8607,63 @@ function prism(polygon3, z0, z1, colors, material, role, sideColor2) {
8410
8607
  });
8411
8608
  return [cap, ...sides];
8412
8609
  }
8610
+ function facet(loop, outward, color, material, role) {
8611
+ const wound = windNormal(loop);
8612
+ const flip = wound[0] * outward[0] + wound[1] * outward[1] + wound[2] * outward[2] < 0;
8613
+ const turned = flip ? [...loop].reverse() : [...loop];
8614
+ return { loops: [turned], normal: flip ? [-wound[0], -wound[1], -wound[2]] : wound, color, material, role };
8615
+ }
8413
8616
  function hanging(polygon3, z0, z1, color, material, role) {
8414
8617
  if (!(z0 > z1)) return [];
8415
8618
  const end = { loops: [[...polygon3].reverse().map((p) => [p.x, p.y, z1])], normal: [0, 0, -1], color, material, role };
8416
8619
  const sides = prism(polygon3, z1, z0, color, material, role).slice(1);
8417
8620
  return [end, ...sides];
8418
8621
  }
8622
+ function lying(polygon3, x0, x1, colors, material, role) {
8623
+ if (!(x1 > x0) || polygon3.length < 3) return [];
8624
+ const { top, side } = colorsOf(colors);
8625
+ const at2 = (x, p) => [x, p.x, p.y];
8626
+ const far = { loops: [polygon3.map((p) => at2(x1, p))], normal: [1, 0, 0], color: top, material, role };
8627
+ const near = { loops: [[...polygon3].reverse().map((p) => at2(x0, p))], normal: [-1, 0, 0], color: top, material, role };
8628
+ const sides = polygon3.map((p, i) => {
8629
+ const q = polygon3[(i + 1) % polygon3.length];
8630
+ const length2 = Math.hypot(q.x - p.x, q.y - p.y) || 1;
8631
+ return {
8632
+ loops: [[at2(x0, p), at2(x0, q), at2(x1, q), at2(x1, p)]],
8633
+ normal: [0, (q.y - p.y) / length2, -(q.x - p.x) / length2],
8634
+ color: side,
8635
+ material,
8636
+ role
8637
+ };
8638
+ });
8639
+ return [far, near, ...sides];
8640
+ }
8641
+ 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]];
8642
+ var minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
8643
+ function windNormal(loop) {
8644
+ const n = cross2(minus(loop[1], loop[0]), minus(loop[2], loop[1]));
8645
+ const length2 = Math.hypot(n[0], n[1], n[2]) || 1;
8646
+ return [n[0] / length2, n[1] / length2, n[2] / length2];
8647
+ }
8648
+ function lathe(profile, cx, cy, sides, colors, material, role) {
8649
+ if (profile.length < 2 || sides < 3) return [];
8650
+ const { top, side } = colorsOf(colors);
8651
+ const ring2 = (radius, z, i) => {
8652
+ const angle = 2 * Math.PI * i / sides;
8653
+ return [cx + radius * Math.cos(angle), cy + radius * Math.sin(angle), z];
8654
+ };
8655
+ const bands = profile.slice(1).flatMap(([r1, z1], k) => {
8656
+ const [r0, z0] = profile[k];
8657
+ return Array.from({ length: sides }, (_, i) => {
8658
+ const corners = [ring2(r0, z0, i), ring2(r0, z0, i + 1), ring2(r1, z1, i + 1), ring2(r1, z1, i)];
8659
+ 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]);
8660
+ return loop.length < 3 ? [] : [{ loops: [loop], normal: windNormal(loop), color: side, material, role }];
8661
+ }).flat();
8662
+ });
8663
+ const [lastR, lastZ] = profile[profile.length - 1];
8664
+ const lid2 = lastR > 0 ? [{ loops: [Array.from({ length: sides }, (_, i) => ring2(lastR, lastZ, i))], normal: [0, 0, 1], color: top, material, role }] : [];
8665
+ return [...lid2, ...bands];
8666
+ }
8419
8667
  var rectPolygon = (r) => [
8420
8668
  { x: r.minX, y: r.minY },
8421
8669
  { x: r.maxX, y: r.minY },
@@ -8461,16 +8709,209 @@ var padsRect = (pads2) => rectOf(pads2.flatMap((pad) => {
8461
8709
  return [{ x: r.minX, y: r.minY }, { x: r.maxX, y: r.maxY }];
8462
8710
  }));
8463
8711
  var LEAD_TAIL = 1.6;
8464
- function leads(input, color = input.look.metal) {
8712
+ function leads(input, color = input.look.metal, half) {
8465
8713
  return input.pads.flatMap((pad) => {
8466
8714
  if (pad.layers !== "through" || pad.drill === void 0) return [];
8467
8715
  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");
8716
+ 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);
8717
+ return hanging(wire2, 0, -(input.thickness + LEAD_TAIL), color, "metal", "lead");
8470
8718
  });
8471
8719
  }
8472
8720
  var firstPad = (pads2) => pads2.find((pad) => pad.number === "1") ?? pads2[0];
8473
8721
 
8722
+ // studio/src/look/parts/axial.ts
8723
+ var BODY_SHARE = 0.94;
8724
+ var SIDES = 16;
8725
+ var FOUR_BANDS_FROM = 5;
8726
+ var BAND_COLORS = [[122, 66, 30], [24, 24, 26], [190, 40, 36], [204, 168, 62]];
8727
+ var BAND_SHARE = 0.09;
8728
+ var BAND_MIN = 0.3;
8729
+ var FIRST_BAND_SHARE = 0.17;
8730
+ var LAST_BAND_GAP = 0.8;
8731
+ var CATHODE_SHARE = 0.14;
8732
+ var CATHODE_MIN = 0.4;
8733
+ var CATHODE_INSET_SHARE = 0.06;
8734
+ var CATHODE_MAX_SHARE = 0.4;
8735
+ var WIRE_SHARE = 0.6;
8736
+ var WIRE_MAX = 0.9;
8737
+ var WIRE_BODY_SHARE = 0.9;
8738
+ var fallback = (input) => input.body ?? input.limit;
8739
+ var BAND_SPAN_SHARE = 0.78;
8740
+ var BAND_VISIBLE = 0.15;
8741
+ var bandSpan = (count) => (count - 1) * 1.9 + 1 + (count === 4 ? LAST_BAND_GAP : 0);
8742
+ function resistorBands(x0, length2, mid, axis, radius) {
8743
+ const wanted = length2 >= FOUR_BANDS_FROM ? 4 : 3;
8744
+ const preferred = Math.max(BAND_MIN, length2 * BAND_SHARE);
8745
+ const count = [wanted, 3, 2, 1].filter((n) => n <= wanted).find((n) => Math.min(preferred, length2 * BAND_SPAN_SHARE / bandSpan(n)) >= BAND_VISIBLE);
8746
+ if (count === void 0) return [];
8747
+ const width = Math.min(preferred, length2 * BAND_SPAN_SHARE / bandSpan(count));
8748
+ const step = width * 1.9;
8749
+ const start = x0 + length2 * FIRST_BAND_SHARE;
8750
+ return BAND_COLORS.slice(0, count).flatMap((color, i) => {
8751
+ const from = start + i * step + (i === 3 ? width * LAST_BAND_GAP : 0);
8752
+ return lying(circle3(mid, axis, radius, SIDES), from, from + width, color, "matt", "body");
8753
+ });
8754
+ }
8755
+ function cathodeBand(x1, length2, mid, axis, radius, color) {
8756
+ const width = Math.min(Math.max(CATHODE_MIN, length2 * CATHODE_SHARE), length2 * CATHODE_MAX_SHARE);
8757
+ const end = x1 - length2 * CATHODE_INSET_SHARE;
8758
+ return lying(circle3(mid, axis, radius, SIDES), end - width, end, color, "matt", "cathode");
8759
+ }
8760
+ function wire(input, padX, padY, endX, axis, half) {
8761
+ const [lo, hi] = [Math.min(endX, padX - half), Math.max(endX, padX + half)];
8762
+ const { look } = input;
8763
+ const along = box({ minX: lo, maxX: hi, minY: padY - half, maxY: padY + half }, axis - half, axis + half, look.metal, "metal", "leg");
8764
+ const down = box({ minX: padX - half, maxX: padX + half, minY: padY - half, maxY: padY + half }, 0, axis + half, look.metal, "metal", "leg");
8765
+ return [...along, ...down];
8766
+ }
8767
+ function axialShape(input) {
8768
+ const body = fallback(input);
8769
+ const { look, lookName } = input;
8770
+ const length2 = body.maxX - body.minX;
8771
+ const radius = (body.maxY - body.minY) / 2;
8772
+ const axis = input.height - radius;
8773
+ const mid = (body.minY + body.maxY) / 2;
8774
+ const pieces = [...lying(circle3(mid, axis, radius * BODY_SHARE, SIDES), body.minX, body.maxX, look.body, "matt", "body")];
8775
+ if (lookName === "axialResistor") pieces.push(...resistorBands(body.minX, length2, mid, axis, radius));
8776
+ if (lookName === "axialDiode" || lookName === "axialGlass") pieces.push(...cathodeBand(body.maxX, length2, mid, axis, radius, look.mark));
8777
+ for (const pad of input.pads) {
8778
+ if (pad.layers !== "through") continue;
8779
+ const half = Math.min(WIRE_MAX, (pad.drill?.width ?? 1) * WIRE_SHARE, radius * 2 * WIRE_BODY_SHARE) / 2;
8780
+ pieces.push(...wire(input, pad.x, pad.y, pad.x < (body.minX + body.maxX) / 2 ? body.minX : body.maxX, axis, half));
8781
+ }
8782
+ return [...pieces, ...leads(input)];
8783
+ }
8784
+
8785
+ // studio/src/look/parts/ledth.ts
8786
+ var SIDES2 = 24;
8787
+ var DOME_STEPS = 5;
8788
+ var FLANGE = 1;
8789
+ var FLANGE_SHARE = 0.14;
8790
+ var LENS_MARGIN = 0.4;
8791
+ var LENS_MIN_SHARE = 0.7;
8792
+ var FLANGE_WASH = 0.5;
8793
+ var LEAD_HALF = { x: 0.25, y: 0.25 };
8794
+ var FALLBACK_FLAT = 0.4;
8795
+ var LENS_COLORS = /* @__PURE__ */ new Map([
8796
+ ["red", [[214, 48, 44], [236, 96, 88]]],
8797
+ ["green", [[46, 184, 84], [110, 220, 134]]],
8798
+ ["blue", [[48, 96, 214], [110, 150, 240]]],
8799
+ ["yellow", [[236, 200, 40], [250, 226, 100]]],
8800
+ ["white", [[232, 232, 226], [248, 248, 244]]]
8801
+ ]);
8802
+ function ledLook(base, props) {
8803
+ const named2 = props?.["color"];
8804
+ const pair2 = typeof named2 === "string" ? LENS_COLORS.get(named2.trim().toLowerCase()) : void 0;
8805
+ return pair2 === void 0 ? base : { ...base, body: pair2[0], top: pair2[1] };
8806
+ }
8807
+ var wash = (color) => [0, 1, 2].map((i) => Math.round(color[i] + (255 - color[i]) * FLANGE_WASH));
8808
+ function flangeOutline(radius, cut, sign) {
8809
+ return circle3(0, 0, radius, SIDES2).map((p) => ({ x: sign === 1 ? Math.min(p.x, cut) : Math.max(p.x, cut), y: p.y }));
8810
+ }
8811
+ function ledShape(input) {
8812
+ const body = input.body ?? input.limit;
8813
+ const { look } = input;
8814
+ const [one, two] = [input.pads.find((p) => p.number === "1") ?? input.pads[0], input.pads.find((p) => p.number === "2") ?? input.pads[1]];
8815
+ const sign = one !== void 0 && two !== void 0 && two.x < one.x ? -1 : 1;
8816
+ const radius = (body.maxY - body.minY) / 2;
8817
+ const cut = sign === 1 ? Math.min(body.maxX, radius - FALLBACK_FLAT) : Math.max(body.minX, FALLBACK_FLAT - radius);
8818
+ const h = input.height;
8819
+ const flange = Math.min(FLANGE, h * FLANGE_SHARE);
8820
+ const lens2 = Math.max(radius - LENS_MARGIN, radius * LENS_MIN_SHARE);
8821
+ const axis = h - lens2;
8822
+ const outline2 = flangeOutline(radius, cut, sign);
8823
+ const onFlat = (i) => outline2[i]?.x === cut && outline2[(i + 1) % outline2.length]?.x === cut ? look.mark : void 0;
8824
+ const flangeColor = wash(look.body);
8825
+ const ring2 = 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);
8826
+ const dome = Array.from({ length: DOME_STEPS }, (_, k) => {
8827
+ const angle = Math.PI / 2 * ((k + 1) / DOME_STEPS);
8828
+ return k === DOME_STEPS - 1 ? [0, h] : [lens2 * Math.cos(angle), axis + lens2 * Math.sin(angle)];
8829
+ });
8830
+ const profile = [[lens2, flange], [lens2, axis], ...dome];
8831
+ const lensPieces = lathe(profile, 0, 0, SIDES2, { top: look.top ?? look.body, side: look.body }, "matt", "body");
8832
+ return [...ring2, ...lensPieces, ...leads(input, look.metal, LEAD_HALF)];
8833
+ }
8834
+
8835
+ // studio/src/look/parts/screw.ts
8836
+ var HEAD_HEIGHT = 0.6;
8837
+ var SLOT_RISE = 0.04;
8838
+ var HEAD_SIDES = 12;
8839
+ var HEAD_SHARE = 0.32;
8840
+ var SLOT_LENGTH = 0.8;
8841
+ var SLOT_HALF = 0.2;
8842
+ var OPENING_SHARE = 0.6;
8843
+ var OPENING_FROM = 0.18;
8844
+ var OPENING_TO = 0.62;
8845
+ var SET_BACK = 0.03;
8846
+ var INSET = 0.15;
8847
+ var PIN_HALF = { x: 0.45, y: 0.45 };
8848
+ var DEFAULT_PITCH = 5.08;
8849
+ var MIN_PITCH = 0.5;
8850
+ function pitchOf2(xs) {
8851
+ const sorted = [...xs].sort((a, b) => a - b);
8852
+ const gaps = sorted.slice(1).map((x, i) => x - sorted[i]).filter((gap) => gap > MIN_PITCH);
8853
+ return gaps.length === 0 ? DEFAULT_PITCH : Math.min(...gaps);
8854
+ }
8855
+ function opening(x, y, width, z0, z1, color) {
8856
+ 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");
8857
+ }
8858
+ function screwShape(input) {
8859
+ const outline2 = clipped(input.body ?? grown3(input.limit, -INSET), input.limit);
8860
+ const { look } = input;
8861
+ const h = input.height;
8862
+ const top = h - Math.min(HEAD_HEIGHT, h * 0.1);
8863
+ const pitch = pitchOf2(input.pads.map((pad) => pad.x));
8864
+ const radius = pitch * HEAD_SHARE;
8865
+ const pieces = [...box({ ...outline2, minY: outline2.minY + SET_BACK }, 0, top, look.body, "matt", "body")];
8866
+ for (const pad of input.pads) {
8867
+ pieces.push(...lathe([[radius, top], [radius, h - SLOT_RISE]], pad.x, pad.y, HEAD_SIDES, look.metal, "metal", "cap"));
8868
+ const slot = { minX: pad.x - radius * SLOT_LENGTH, maxX: pad.x + radius * SLOT_LENGTH, minY: pad.y - SLOT_HALF, maxY: pad.y + SLOT_HALF };
8869
+ pieces.push(...box(slot, h - SLOT_RISE, h, look.mark, "matt", "cap"));
8870
+ pieces.push(opening(pad.x, outline2.minY, pitch * OPENING_SHARE, top * OPENING_FROM, top * OPENING_TO, look.mark));
8871
+ }
8872
+ return [...pieces, ...leads(input, look.metal, PIN_HALF)];
8873
+ }
8874
+
8875
+ // studio/src/look/parts/socket.ts
8876
+ var PITCH = 2.54;
8877
+ var OPENING_HALF = 0.75;
8878
+ var OPENING_DEPTH = 1.2;
8879
+ var DEPTH_SHARE = 0.3;
8880
+ var WALL_LIFT = 6;
8881
+ 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");
8882
+ function cell(x, y, h, depth, input) {
8883
+ const o = OPENING_HALF;
8884
+ const { look } = input;
8885
+ const r = clipped({ minX: x - PITCH / 2, maxX: x + PITCH / 2, minY: y - PITCH / 2, maxY: y + PITCH / 2 }, input.limit);
8886
+ const floor = h - depth;
8887
+ const wallColor = look.mark.map((c) => c + WALL_LIFT);
8888
+ 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");
8889
+ return [
8890
+ lid([r.minX, r.minY], [x - o, r.maxY], h, look.body),
8891
+ lid([x + o, r.minY], [r.maxX, r.maxY], h, look.body),
8892
+ lid([x - o, r.minY], [x + o, y - o], h, look.body),
8893
+ lid([x - o, y + o], [x + o, r.maxY], h, look.body),
8894
+ wall([x - o, y - o], [x + o, y - o], [0, 1, 0]),
8895
+ wall([x - o, y + o], [x + o, y + o], [0, -1, 0]),
8896
+ wall([x - o, y - o], [x - o, y + o], [1, 0, 0]),
8897
+ wall([x + o, y - o], [x + o, y + o], [-1, 0, 0]),
8898
+ lid([x - o, y - o], [x + o, y + o], floor, look.mark)
8899
+ ];
8900
+ }
8901
+ function socketShape(input) {
8902
+ const pads2 = padsRect(input.pads);
8903
+ if (pads2 === void 0) return [];
8904
+ const xs = input.pads.map((p) => p.x);
8905
+ const ys = input.pads.map((p) => p.y);
8906
+ const half = PITCH / 2;
8907
+ 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);
8908
+ const h = input.height;
8909
+ const depth = Math.min(OPENING_DEPTH, h * DEPTH_SHARE);
8910
+ const sides = prism(rectPolygon(base), 0, h, input.look.body, "matt", "body").slice(1);
8911
+ const cells = input.pads.flatMap((pad) => cell(pad.x, pad.y, h, depth, input));
8912
+ return [...sides, ...cells, ...leads(input)];
8913
+ }
8914
+
8474
8915
  // studio/src/look/parts/chip.ts
8475
8916
  var CAP_SHARE = 0.22;
8476
8917
  function chipShape(input) {
@@ -8517,10 +8958,145 @@ function clipPieces(pieces, limit) {
8517
8958
  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
8959
  }
8519
8960
 
8961
+ // studio/src/look/parts/gullwing.ts
8962
+ var LEAD = 0.15;
8963
+ var STANDOFF = 0.08;
8964
+ var SHOULDER_MOST = 1.05;
8965
+ function bodyBand(height) {
8966
+ return { bottom: Math.min(STANDOFF, height * 0.3), top: height - Math.min(0.02, height * 0.2) };
8967
+ }
8968
+ var SQUARISH = 0.1;
8969
+ var PLATE = 0.04;
8970
+ function padSide(pad) {
8971
+ const r = padRect(pad);
8972
+ const [w, h] = [r.maxX - r.minX, r.maxY - r.minY];
8973
+ const wide = Math.abs(w - h) <= SQUARISH * Math.max(w, h) ? Math.abs(pad.x) > Math.abs(pad.y) : w >= h;
8974
+ if (wide) return pad.x >= 0 ? "right" : "left";
8975
+ return pad.y >= 0 ? "top" : "bottom";
8976
+ }
8977
+ function legPads(input) {
8978
+ const body = input.body;
8979
+ if (body === void 0) return input.pads;
8980
+ const under = (pad) => pad.x > body.minX && pad.x < body.maxX && pad.y > body.minY && pad.y < body.maxY;
8981
+ return input.pads.filter((pad) => !under(pad));
8982
+ }
8983
+ function bodyRect(input, inset = 0.02) {
8984
+ const sides = legPads(input).map((pad) => ({ pad, side: padSide(pad), r: padRect(pad) }));
8985
+ const inner = (side) => sides.filter((s) => s.side === side);
8986
+ const all = padsRect(legPads(input)) ?? input.limit;
8987
+ const reach = (side, fallback2) => {
8988
+ const row3 = inner(side);
8989
+ if (row3.length === 0) return fallback2;
8990
+ if (side === "right") return Math.min(...row3.map((s) => s.r.minX)) - inset;
8991
+ if (side === "left") return Math.max(...row3.map((s) => s.r.maxX)) + inset;
8992
+ if (side === "top") return Math.min(...row3.map((s) => s.r.minY)) - inset;
8993
+ return Math.max(...row3.map((s) => s.r.maxY)) + inset;
8994
+ };
8995
+ const spare = 0.45;
8996
+ const estimate = {
8997
+ minX: reach("left", all.minX - spare),
8998
+ maxX: reach("right", all.maxX + spare),
8999
+ minY: reach("bottom", all.minY - spare),
9000
+ maxY: reach("top", all.maxY + spare)
9001
+ };
9002
+ const rowless = {
9003
+ minX: inner("left").length === 0 ? Math.max(estimate.minX, all.minX - spare) : estimate.minX,
9004
+ maxX: inner("right").length === 0 ? Math.min(estimate.maxX, all.maxX + spare) : estimate.maxX,
9005
+ minY: inner("bottom").length === 0 ? Math.max(estimate.minY, all.minY - spare) : estimate.minY,
9006
+ maxY: inner("top").length === 0 ? Math.min(estimate.maxY, all.maxY + spare) : estimate.maxY
9007
+ };
9008
+ const outline2 = input.body ? clipped(input.body, rowless) : rowless;
9009
+ return clipped(outline2, input.limit);
9010
+ }
9011
+ function leg(pad, side, body, height, color, across) {
9012
+ const r = padRect(pad);
9013
+ const horizontal = side === "left" || side === "right";
9014
+ const sign = side === "right" || side === "top" ? 1 : -1;
9015
+ const edge = side === "right" ? body.maxX : side === "left" ? body.minX : side === "top" ? body.maxY : body.minY;
9016
+ const centre = horizontal ? pad.x : pad.y;
9017
+ const length2 = horizontal ? r.maxX - r.minX : r.maxY - r.minY;
9018
+ const padAcross = horizontal ? r.maxY - r.minY : r.maxX - r.minX;
9019
+ const width = across ?? Math.min(padAcross * 0.72, 0.5);
9020
+ const mid = horizontal ? pad.y : pad.x;
9021
+ const reach = sign * (centre - edge);
9022
+ if (reach <= 0.05) return [];
9023
+ const bend = edge + sign * Math.min(reach * 0.38, 0.6);
9024
+ const toe = centre + sign * Math.min(length2 * 0.3, Math.abs(length2 / 2) - 0.02);
9025
+ const lead = Math.min(LEAD, height / 3);
9026
+ const shoulder = Math.min(Math.max(height * 0.38, lead * 1.5), height - lead * 1.5, SHOULDER_MOST);
9027
+ const span = (a, b, z0, z1) => {
9028
+ const [lo, hi] = [Math.min(a, b), Math.max(a, b)];
9029
+ 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 };
9030
+ return box(rect2, z0, z1, color, "metal", "leg");
9031
+ };
9032
+ return [...span(edge, bend + sign * lead, shoulder, shoulder + lead), ...span(bend, bend + sign * lead, lead, shoulder), ...span(bend, toe, 0, lead)];
9033
+ }
9034
+ function pin1Dot(input, body, top, roomy = Infinity) {
9035
+ const one = firstPad(input.pads);
9036
+ if (one === void 0) return [];
9037
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9038
+ const radius = Math.min(small * 0.12, 0.4);
9039
+ const inset = radius + Math.min(small * 0.08, roomy);
9040
+ const x = one.x < (body.minX + body.maxX) / 2 ? body.minX + inset : body.maxX - inset;
9041
+ const y = one.y < (body.minY + body.maxY) / 2 ? body.minY + inset : body.maxY - inset;
9042
+ return prism(circle3(x, y, radius, 12), top - 0.01, input.height, input.look.mark, "matt", "pin1");
9043
+ }
9044
+ function gullwingShape(input) {
9045
+ const body = bodyRect(input);
9046
+ const h = input.height;
9047
+ const { bottom, top } = bodyBand(h);
9048
+ const { look } = input;
9049
+ const pieces = [...box(body, bottom, top, look.body, "matt", "body")];
9050
+ const legged = legPads(input);
9051
+ for (const pad of legged) pieces.push(...leg(pad, padSide(pad), body, h, look.metal));
9052
+ for (const pad of input.pads.filter((one) => !legged.includes(one))) pieces.push(...box(clipped(padRect(pad), body), 0, Math.min(PLATE, bottom), look.metal, "metal", "cap"));
9053
+ pieces.push(...pin1Dot(input, body, top));
9054
+ return clipPieces(pieces, input.limit);
9055
+ }
9056
+
9057
+ // studio/src/look/parts/bga.ts
9058
+ var BALL_OVER_LAND = 1.3;
9059
+ var BALL_SQUASH = 0.8;
9060
+ var BALL_HEIGHT_SHARE = 0.3;
9061
+ var SUBSTRATE = 0.25;
9062
+ var SUBSTRATE_SHARE = 0.3;
9063
+ var CAP_INSET = 0.4;
9064
+ var CAP_INSET_SHARE = 0.06;
9065
+ var DOMED_LIMIT = 64;
9066
+ var MANY = 400;
9067
+ var DOT_ROOM = 0.1;
9068
+ var landOf = (pad) => Math.min(padRect(pad).maxX - padRect(pad).minX, padRect(pad).maxY - padRect(pad).minY);
9069
+ function ball(pad, width, height, count, color) {
9070
+ const radius = width / 2;
9071
+ 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");
9072
+ return prism(circle3(pad.x, pad.y, radius * 0.85, count <= MANY ? 6 : 4), 0, height, color, "metal", "pin");
9073
+ }
9074
+ function bgaShape(input) {
9075
+ const extent = padsRect(input.pads);
9076
+ const outline2 = clipped(input.body ?? grown3(extent ?? input.limit, 0.3), input.limit);
9077
+ const { look } = input;
9078
+ const h = input.height;
9079
+ const land = Math.min(...input.pads.map(landOf), Infinity);
9080
+ const width = Number.isFinite(land) ? land * BALL_OVER_LAND : 0.4;
9081
+ const ballHeight = Math.min(width * BALL_SQUASH, h * BALL_HEIGHT_SHARE);
9082
+ const substrate = Math.min(SUBSTRATE, (h - ballHeight) * SUBSTRATE_SHARE);
9083
+ const small = Math.min(outline2.maxX - outline2.minX, outline2.maxY - outline2.minY);
9084
+ const cap = grown3(outline2, -Math.min(CAP_INSET, small * CAP_INSET_SHARE));
9085
+ const top = h - 0.02;
9086
+ const colorOfSubstrate = look.top ?? look.body;
9087
+ const pieces = [
9088
+ ...input.pads.flatMap((pad) => ball(pad, width, ballHeight, input.pads.length, look.metal)),
9089
+ ...box(outline2, ballHeight, ballHeight + substrate, colorOfSubstrate, "matt", "body"),
9090
+ ...box(cap, ballHeight + substrate, top, look.body, "matt", "body"),
9091
+ ...pin1Dot(input, cap, top, DOT_ROOM)
9092
+ ];
9093
+ return pieces;
9094
+ }
9095
+
8520
9096
  // studio/src/look/parts/block.ts
8521
- var INSET = 0.15;
9097
+ var INSET2 = 0.15;
8522
9098
  function blockShape(input) {
8523
- const body = clipped(input.body ?? grown3(input.limit, -INSET), input.limit);
9099
+ const body = clipped(input.body ?? grown3(input.limit, -INSET2), input.limit);
8524
9100
  const { look } = input;
8525
9101
  return [...clipPieces(box(body, 0, input.height, { top: look.top ?? look.body, side: look.body }, "matt", "body"), input.limit), ...leads(input)];
8526
9102
  }
@@ -8550,52 +9126,111 @@ function crystalShape(input) {
8550
9126
  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
9127
  return [...clipPieces(moved, input.limit), ...leads(input)];
8552
9128
  }
8553
- var SIDES = 24;
9129
+ var SIDES3 = 24;
8554
9130
  function electrolyticShape(input) {
8555
9131
  const limit = input.limit;
8556
9132
  const radius = Math.min(limit.maxX - limit.minX, limit.maxY - limit.minY) / 2 - MARGIN;
8557
9133
  const cx = (limit.minX + limit.maxX) / 2;
8558
9134
  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);
9135
+ const minus2 = input.pads.find((p) => p.number === "2");
9136
+ const towards = minus2 === void 0 ? 0 : Math.atan2(minus2.y - cy, minus2.x - cx);
8561
9137
  const h = input.height;
8562
9138
  const { look } = input;
8563
- const lid = Math.min(0.4, h * 0.05);
9139
+ const lid2 = Math.min(0.4, h * 0.05);
8564
9140
  const stripe = (i) => {
8565
- const a = 2 * Math.PI * (i + 0.5) / SIDES;
9141
+ const a = 2 * Math.PI * (i + 0.5) / SIDES3;
8566
9142
  const off = Math.abs(Math.atan2(Math.sin(a - towards), Math.cos(a - towards)));
8567
9143
  return off < Math.PI / 6 ? look.mark : void 0;
8568
9144
  };
8569
9145
  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")
9146
+ ...prism(circle3(cx, cy, radius, SIDES3), 0, h - lid2, { top: look.top ?? look.body, side: look.body }, "matt", "body", stripe),
9147
+ ...prism(circle3(cx, cy, radius * 0.9, SIDES3), h - lid2, h, look.top ?? look.metal, "metal", "body")
8572
9148
  ];
8573
9149
  return [...clipPieces(pieces, input.limit), ...leads(input)];
8574
9150
  }
8575
9151
 
8576
- // studio/src/look/parts/family.ts
9152
+ // studio/src/look/parts/smd-family.ts
8577
9153
  var TIN = [196, 198, 200];
9154
+ var SMD_LOOKS = {
9155
+ 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] },
9156
+ 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] },
9157
+ 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] },
9158
+ 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] },
9159
+ 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] },
9160
+ 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] },
9161
+ 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] },
9162
+ 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] }
9163
+ };
9164
+ function smdFamilyOf(p) {
9165
+ if (p.kind === "minimelf" || p.kind === "melf" || p.kind === "sod" && p.code === "80" || p.kind === "do" && p.code === "213") return { family: "melf", look: "melf" };
9166
+ if (p.kind === "tant") return { family: "tantalum", look: "tantalum" };
9167
+ if (p.kind === "array") return { family: "array", look: "array" };
9168
+ if (p.kind === "smdcan") return { family: "smdcan", look: "smdcan" };
9169
+ if (p.kind === "xtal") return { family: "xtal", look: "xtal" };
9170
+ if (p.kind === "hc" && p.code === "49" && p.suffix === "smd") return { family: "xtal", look: "xtalCan" };
9171
+ if (p.kind === "led" && (p.code === "3528" || p.code === "5050")) return { family: "ledsmd", look: "ledsmd" };
9172
+ if (p.kind === "plcc") return { family: "plcc", look: "plcc" };
9173
+ 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";
9174
+ return power ? { family: "tab", look: "tab" } : void 0;
9175
+ }
9176
+
9177
+ // studio/src/look/parts/uno-family.ts
9178
+ var TIN2 = [196, 198, 200];
9179
+ var UNO_LOOKS = {
9180
+ 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] },
9181
+ 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] },
9182
+ 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] },
9183
+ 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] },
9184
+ 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] },
9185
+ 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] }
9186
+ };
9187
+ function unoFamilyOf(p) {
9188
+ if (p.kind === "usb") return p.params["b"] === true ? "usbb" : p.params["c"] === 16 ? "usbc" : void 0;
9189
+ if (p.kind === "dcjack") return "dcjack";
9190
+ if (p.kind === "tact") return "tact";
9191
+ if (p.kind === "resonator") return "resonator";
9192
+ if (p.kind === "ind") return "inductor";
9193
+ return void 0;
9194
+ }
9195
+
9196
+ // studio/src/look/parts/family.ts
9197
+ var TIN3 = [196, 198, 200];
8578
9198
  var GOLD = [214, 176, 86];
8579
9199
  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] },
9200
+ 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] },
9201
+ capacitor: { sentence: "Chip capacitor: a tan ceramic body between two tinned end caps.", body: [176, 138, 92], metal: TIN3, mark: [176, 138, 92] },
9202
+ 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] },
9203
+ 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] },
9204
+ 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] },
9205
+ 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] },
9206
+ 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] },
9207
+ 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] },
9208
+ 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] },
9209
+ 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] },
9210
+ 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] },
9211
+ 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] },
9212
+ 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] },
9213
+ 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] },
9214
+ 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] },
9215
+ 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] },
9216
+ 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] },
9217
+ 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] },
9218
+ 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
9219
  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] }
9220
+ crystal: { sentence: "Crystal: a plain metal can with rounded ends.", body: [188, 190, 194], metal: TIN3, mark: [188, 190, 194] },
9221
+ 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] },
9222
+ relay: { sentence: "Relay: a mid-blue box with its leads.", body: [46, 86, 156], top: [58, 100, 170], metal: TIN3, mark: [46, 86, 156] },
9223
+ 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] },
9224
+ block: { sentence: "Any other through-hole part: a dark grey box with its leads.", body: [72, 74, 78], metal: TIN3, mark: [72, 74, 78] },
9225
+ ...SMD_LOOKS,
9226
+ ...UNO_LOOKS,
9227
+ box: { sentence: "Anything else: a plain box, as before shapes were drawn.", body: [96, 138, 118], metal: TIN3, mark: [96, 138, 118] }
8594
9228
  };
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"]);
9229
+ var CHIP_CODES = /* @__PURE__ */ new Set(["0201", "0402", "0603", "0805", "1206", "1210", "1812", "2010", "2512", "01005", "2220"]);
9230
+ var GULLWING = /* @__PURE__ */ new Set(["soic", "sot", "sop", "ssop", "tssop", "msop", "qsop", "smdip", "qfp", "lqfp", "tqfp", "sc"]);
8597
9231
  var LEADLESS = /* @__PURE__ */ new Set(["qfn", "dfn", "son", "wson", "vson"]);
8598
- var MOLDED = /* @__PURE__ */ new Set(["sod", "sma", "smb", "smc", "do", "minimelf", "melf"]);
9232
+ var TABBED = /* @__PURE__ */ new Set(["223", "89"]);
9233
+ var MOLDED = /* @__PURE__ */ new Set(["sod", "sma", "smb", "smc", "do"]);
8599
9234
  var parsed = (footprint) => footprint === void 0 || footprint.includes("/") || footprint.endsWith(".yaml") ? void 0 : parseFootprint(footprint);
8600
9235
  function chipLook(kind) {
8601
9236
  if (kind === "resistor") return "resistor";
@@ -8603,6 +9238,14 @@ function chipLook(kind) {
8603
9238
  if (kind === "led") return "led";
8604
9239
  return "chip";
8605
9240
  }
9241
+ var TO220_FAMILY = /* @__PURE__ */ new Set(["220", "247", "126"]);
9242
+ var AXIAL_DIODE_CODES = /* @__PURE__ */ new Set(["35", "41", "15", "201"]);
9243
+ function axialLook(kind, p) {
9244
+ if (p.kind === "do") return p.code === "35" ? "axialGlass" : "axialDiode";
9245
+ if (kind === "resistor") return "axialResistor";
9246
+ if (kind === "diode") return "axialDiode";
9247
+ return "axialPlain";
9248
+ }
8606
9249
  function blockLook(name) {
8607
9250
  const letter = /^[A-Za-z]+/.exec(name)?.[0]?.toUpperCase() ?? "";
8608
9251
  if (letter === "K") return "relay";
@@ -8614,10 +9257,23 @@ function familyOf(kind, footprint, through2 = false, name = "") {
8614
9257
  const withParsed = (family, look) => ({ family, look, ...p ? { parsed: p } : {} });
8615
9258
  if (p !== void 0) {
8616
9259
  if (p.kind === "" && CHIP_CODES.has(p.code)) return withParsed("chip", chipLook(kind));
9260
+ if (p.kind === "bga") return withParsed("bga", "bga");
9261
+ if (p.kind === "dip") return withParsed("dip", "dip");
9262
+ if (p.kind === "to" && TO220_FAMILY.has(p.code)) return withParsed("to220", "to220");
9263
+ if (p.kind === "axial" || p.kind === "do" && AXIAL_DIODE_CODES.has(p.code)) return withParsed("axial", axialLook(kind, p));
9264
+ if (p.kind === "led" && p.suffix === "mm") return withParsed("ledth", "ledlens");
9265
+ if (p.kind === "screw") return withParsed("screw", "screw");
9266
+ if (p.kind === "socket") return withParsed("socket", "socket");
9267
+ if (p.kind === "to" && p.code === "92") return withParsed("to92", "to92");
9268
+ const uno = unoFamilyOf(p);
9269
+ if (uno !== void 0) return withParsed(uno, uno);
9270
+ const smd = smdFamilyOf(p);
9271
+ if (smd !== void 0) return withParsed(smd.family, smd.look);
9272
+ if (p.kind === "sot" && TABBED.has(p.code) && p.variant === void 0) return withParsed("tab", "tab");
8617
9273
  if (MOLDED.has(p.kind)) return withParsed("molded", "molded");
8618
9274
  if (GULLWING.has(p.kind)) return withParsed("gullwing", "gullwing");
8619
9275
  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");
9276
+ 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");
8621
9277
  if (p.kind === "hc" && p.code === "49") return withParsed("crystal", "crystal");
8622
9278
  if (p.kind === "radial") return withParsed("electrolytic", "electrolytic");
8623
9279
  if (p.kind === "pinrow") return withParsed("block", blockLook(name || "J"));
@@ -8626,101 +9282,73 @@ function familyOf(kind, footprint, through2 = false, name = "") {
8626
9282
  return withParsed("box", "box");
8627
9283
  }
8628
9284
 
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)];
8687
- }
8688
- function gullwingShape(input) {
8689
- const body = bodyRect(input);
9285
+ // studio/src/look/parts/dip.ts
9286
+ var STANDOFF2 = 0.5;
9287
+ var LEG_THICKNESS = 0.25;
9288
+ var LEG_WIDTH = 0.5;
9289
+ var SHOULDER_SHARE = 0.3;
9290
+ var NOTCH_RADIUS = 0.9;
9291
+ var NOTCH_SHARE = 0.18;
9292
+ var NOTCH_STEPS = 8;
9293
+ function notch(body, end, radius) {
9294
+ const cx = (body.minX + body.maxX) / 2;
9295
+ const y = end === 1 ? body.maxY : body.minY;
9296
+ const arc = Array.from({ length: NOTCH_STEPS + 1 }, (_, i) => {
9297
+ const angle = Math.PI * (i / NOTCH_STEPS) + (end === 1 ? Math.PI : 0);
9298
+ return { x: cx + radius * Math.cos(angle), y: y + radius * Math.sin(angle) };
9299
+ });
9300
+ return arc;
9301
+ }
9302
+ function leg2(pad, body, shoulder, color) {
9303
+ const sign = pad.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
9304
+ const edge = sign === 1 ? body.maxX : body.minX;
9305
+ const across = { minY: pad.y - LEG_WIDTH / 2, maxY: pad.y + LEG_WIDTH / 2 };
9306
+ const outer = pad.x + sign * (LEG_THICKNESS / 2);
9307
+ const [lo, hi] = [Math.min(edge, outer), Math.max(edge, outer)];
9308
+ const stub = box({ minX: lo, maxX: hi, ...across }, shoulder, shoulder + LEG_THICKNESS, color, "metal", "leg");
9309
+ const down = box({ minX: pad.x - LEG_THICKNESS / 2, maxX: pad.x + LEG_THICKNESS / 2, ...across }, 0, shoulder + LEG_THICKNESS, color, "metal", "leg");
9310
+ return [...stub, ...down];
9311
+ }
9312
+ function dipShape(input) {
9313
+ const body = clipped(input.body ?? grown3(input.limit, -0.3), input.limit);
9314
+ const { look } = input;
8690
9315
  const h = input.height;
8691
9316
  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));
9317
+ const shoulder = STANDOFF2 + (top - STANDOFF2) * SHOULDER_SHARE;
9318
+ const pieces = [...box(body, STANDOFF2, top, look.body, "matt", "body")];
9319
+ for (const pad of input.pads) if (pad.layers === "through") pieces.push(...leg2(pad, body, shoulder, look.metal));
8695
9320
  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);
9321
+ const end = one !== void 0 && one.y < (body.minY + body.maxY) / 2 ? -1 : 1;
9322
+ const radius = Math.min(NOTCH_RADIUS, (body.maxX - body.minX) * NOTCH_SHARE);
9323
+ pieces.push(...prism(notch(body, end, radius), top - 0.01, h, look.mark, "matt", "pin1"));
9324
+ pieces.push(...pin1Dot(input, body, top));
9325
+ return [...pieces, ...leads(input, look.metal, { x: LEG_THICKNESS / 2, y: LEG_WIDTH / 2 })];
8705
9326
  }
8706
9327
 
8707
9328
  // studio/src/look/parts/header.ts
8708
- var PITCH = 2.54;
9329
+ var PITCH2 = 2.54;
8709
9330
  var BASE = 2.5;
8710
9331
  var PIN = 0.64;
9332
+ var pitchOf3 = (input) => {
9333
+ const given = input.parsed?.params["p"];
9334
+ return typeof given === "number" && given > 0 ? given : PITCH2;
9335
+ };
8711
9336
  function headerShape(input) {
8712
9337
  const pads2 = padsRect(input.pads);
8713
9338
  if (pads2 === void 0) return [];
8714
9339
  const xs = input.pads.map((p) => p.x);
8715
9340
  const ys = input.pads.map((p) => p.y);
8716
- const half = PITCH / 2;
9341
+ const pitch = pitchOf3(input);
9342
+ const scale = Math.min(1, pitch / PITCH2);
9343
+ const [baseHeight, pinSize] = [BASE * scale, PIN * scale];
9344
+ const half = pitch / 2;
8717
9345
  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
9346
  const h = input.height;
8719
9347
  const { look } = input;
8720
- const baseTop = Math.min(BASE, h * 0.4);
9348
+ const baseTop = Math.min(baseHeight, h * 0.4);
8721
9349
  const pieces = [...box(base, 0, baseTop, look.body, "matt", "body")];
8722
9350
  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 };
9351
+ const pin = { minX: pad.x - pinSize / 2, maxX: pad.x + pinSize / 2, minY: pad.y - pinSize / 2, maxY: pad.y + pinSize / 2 };
8724
9352
  pieces.push(...box(pin, baseTop, h, look.metal, "metal", "pin"));
8725
9353
  pieces.push(...hanging(rectPolygon(pin), 0, -(input.thickness + LEAD_TAIL), look.metal, "metal", "lead"));
8726
9354
  }
@@ -8774,17 +9402,812 @@ function moldedShape(input) {
8774
9402
  const at2 = (minX, maxX, w) => ({ minX, maxX, minY: -w / 2, maxY: w / 2 });
8775
9403
  const { look } = input;
8776
9404
  const leadWidth = Math.min(padAcross * 0.6, width * 0.6);
8777
- const band2 = Math.max(length2 * 0.16, 0.2);
9405
+ const band3 = Math.max(length2 * 0.16, 0.2);
8778
9406
  const pieces = [
8779
9407
  ...box(at2(-gap / 2 - padAlong * 0.3, -length2 / 2 + 0.05, leadWidth), 0, LEAD2, look.metal, "metal", "leg"),
8780
9408
  ...box(at2(length2 / 2 - 0.05, gap / 2 + padAlong * 0.3, leadWidth), 0, LEAD2, look.metal, "metal", "leg"),
8781
9409
  ...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")
9410
+ ...box(at2(length2 / 2 - band3 * 1.9, length2 / 2 - band3 * 0.9, width * 0.96), top - 0.01, h, look.mark, "matt", "cathode")
8783
9411
  ];
8784
9412
  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
9413
  return clipPieces(moved, input.limit);
8786
9414
  }
8787
9415
 
9416
+ // studio/src/look/parts/smd.ts
9417
+ function twoPads(input) {
9418
+ const [one, two] = [input.pads.find((pad) => pad.number === "1") ?? input.pads[0], input.pads.find((pad) => pad.number === "2") ?? input.pads[1]];
9419
+ if (one === void 0 || two === void 0) return void 0;
9420
+ const angle = Math.atan2(two.y - one.y, two.x - one.x) * 180 / Math.PI;
9421
+ const flat = Math.abs(Math.sin(angle * Math.PI / 180)) > 0.7;
9422
+ const rect2 = padRect(two);
9423
+ const gap = Math.hypot(two.x - one.x, two.y - one.y);
9424
+ const padAlong = flat ? rect2.maxY - rect2.minY : rect2.maxX - rect2.minX;
9425
+ const padAcross = flat ? rect2.maxX - rect2.minX : rect2.maxY - rect2.minY;
9426
+ const bodyAlong = input.body ? flat ? input.body.maxY - input.body.minY : input.body.maxX - input.body.minX : gap + padAlong * 0.3;
9427
+ const bodyAcross = input.body ? flat ? input.body.maxX - input.body.minX : input.body.maxY - input.body.minY : padAcross;
9428
+ return { angle, mid: { x: (one.x + two.x) / 2, y: (one.y + two.y) / 2 }, gap, padAlong, padAcross, bodyAlong, bodyAcross };
9429
+ }
9430
+ function settle(pieces, axis, input) {
9431
+ 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]])) }));
9432
+ return clipPieces(moved, input.limit);
9433
+ }
9434
+ function sideOf(pad, body) {
9435
+ 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)];
9436
+ if (Math.abs(dy) >= Math.abs(dx)) return dy >= 0 ? "top" : "bottom";
9437
+ return dx >= 0 ? "right" : "left";
9438
+ }
9439
+ function band(pad, body, side, inside, outside) {
9440
+ const grownBody = { minX: body.minX - outside, maxX: body.maxX + outside, minY: body.minY - outside, maxY: body.maxY + outside };
9441
+ const strip = {
9442
+ left: { ...grownBody, minX: body.minX - outside, maxX: body.minX + inside },
9443
+ right: { ...grownBody, minX: body.maxX - inside, maxX: body.maxX + outside },
9444
+ bottom: { ...grownBody, minY: body.minY - outside, maxY: body.minY + inside },
9445
+ top: { ...grownBody, minY: body.maxY - inside, maxY: body.maxY + outside }
9446
+ }[side];
9447
+ return clipped(padRect(pad), strip);
9448
+ }
9449
+ function terminal(pad, body, spec, color) {
9450
+ const side = sideOf(pad, body);
9451
+ const region = band(pad, body, side, spec.inside, spec.outside);
9452
+ const narrow = spec.across === void 0 ? region : narrowed(region, side, spec.across);
9453
+ return box(narrow.maxX > narrow.minX && narrow.maxY > narrow.minY ? narrow : padRect(pad), 0, spec.height, color, "metal", spec.role ?? "cap");
9454
+ }
9455
+ function narrowed(r, side, across) {
9456
+ const vertical = side === "left" || side === "right";
9457
+ const [mid, size] = vertical ? [(r.minY + r.maxY) / 2, r.maxY - r.minY] : [(r.minX + r.maxX) / 2, r.maxX - r.minX];
9458
+ const half = Math.min(size, across) / 2;
9459
+ return vertical ? { ...r, minY: mid - half, maxY: mid + half } : { ...r, minX: mid - half, maxX: mid + half };
9460
+ }
9461
+ function jLead(pad, side, body, spec, color) {
9462
+ const r = padRect(pad);
9463
+ const vertical = side === "left" || side === "right";
9464
+ const sign = side === "right" || side === "top" ? 1 : -1;
9465
+ const edge = side === "right" ? body.maxX : side === "left" ? body.minX : side === "top" ? body.maxY : body.minY;
9466
+ 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];
9467
+ const padOut = sign > 0 ? far - edge : edge - near;
9468
+ const padIn = sign > 0 ? near - edge : edge - far;
9469
+ const outer = Math.min(spec.reach, padOut - spec.toe);
9470
+ if (outer < spec.thick) return [];
9471
+ const half = Math.min(across, spec.across) / 2;
9472
+ const strip = (a, b, z0, z1) => {
9473
+ const [lo, hi] = [Math.min(edge + sign * a, edge + sign * b), Math.max(edge + sign * a, edge + sign * b)];
9474
+ const rect2 = vertical ? { minX: lo, maxX: hi, minY: mid - half, maxY: mid + half } : { minY: lo, maxY: hi, minX: mid - half, maxX: mid + half };
9475
+ return box(rect2, z0, z1, color, "metal", "leg");
9476
+ };
9477
+ const foot = spec.thick;
9478
+ 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)];
9479
+ }
9480
+ function clippedCorner(r, sx, sy, cut) {
9481
+ const corners = [
9482
+ { x: r.minX, y: r.minY, sx: -1, sy: -1 },
9483
+ { x: r.maxX, y: r.minY, sx: 1, sy: -1 },
9484
+ { x: r.maxX, y: r.maxY, sx: 1, sy: 1 },
9485
+ { x: r.minX, y: r.maxY, sx: -1, sy: 1 }
9486
+ ];
9487
+ return corners.flatMap((c, i) => {
9488
+ if (c.sx !== sx || c.sy !== sy) return [{ x: c.x, y: c.y }];
9489
+ const [before, after] = [corners[(i + 3) % 4], corners[(i + 1) % 4]];
9490
+ const toward = (to) => ({ x: c.x + Math.sign(to.x - c.x) * cut, y: c.y + Math.sign(to.y - c.y) * cut });
9491
+ return [toward(before), toward(after)];
9492
+ });
9493
+ }
9494
+
9495
+ // studio/src/look/parts/array.ts
9496
+ var STANDOFF3 = 0.03;
9497
+ var INSIDE = 0.12;
9498
+ var OUTSIDE = 0.1;
9499
+ var TERMINAL_SHARE = 0.7;
9500
+ function arrayShape(input) {
9501
+ const reach = padsRect(input.pads);
9502
+ const body = clipped(input.body ?? (reach ? grown3(reach, -0.1) : input.limit), input.limit);
9503
+ const h = input.height;
9504
+ const { look } = input;
9505
+ const band3 = bodyBand(h);
9506
+ const pieces = [...box(body, Math.min(STANDOFF3, band3.bottom), band3.top, { top: look.top ?? look.body, side: look.body }, "matt", "body")];
9507
+ for (const pad of input.pads) pieces.push(...terminal(pad, body, { inside: INSIDE, outside: OUTSIDE, height: h * TERMINAL_SHARE }, look.metal));
9508
+ return clipPieces(pieces, input.limit);
9509
+ }
9510
+
9511
+ // studio/src/look/parts/ledsmd.ts
9512
+ var STANDOFF4 = 0.04;
9513
+ var BODY_SHARE2 = 0.78;
9514
+ var LENS_SHARE = 0.36;
9515
+ var SIDES4 = 16;
9516
+ var DOME_STEPS2 = 4;
9517
+ var DOME_ANGLE = Math.PI / 3;
9518
+ var CLIP_SHARE = 0.12;
9519
+ var INSIDE2 = 0.25;
9520
+ var OUTSIDE2 = 0.2;
9521
+ var TERMINAL_HEIGHT = 0.3;
9522
+ function lens(cx, cy, radius, from, to, color) {
9523
+ const profile = Array.from({ length: DOME_STEPS2 + 1 }, (_, i) => {
9524
+ const angle = DOME_ANGLE * i / DOME_STEPS2;
9525
+ return [radius * Math.cos(angle), from + (to - from) * Math.sin(angle) / Math.sin(DOME_ANGLE)];
9526
+ });
9527
+ return lathe(profile, cx, cy, SIDES4, color, "matt", "body");
9528
+ }
9529
+ function ledSmdShape(input) {
9530
+ const reach = padsRect(input.pads);
9531
+ const body = clipped(input.body ?? (reach ? grown3(reach, -0.1) : input.limit), input.limit);
9532
+ const [width, depth] = [body.maxX - body.minX, body.maxY - body.minY];
9533
+ const h = input.height;
9534
+ const shoulder = h * BODY_SHARE2;
9535
+ const { look } = input;
9536
+ const one = firstPad(input.pads);
9537
+ 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;
9538
+ 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 }];
9539
+ const pieces = [
9540
+ ...prism(outline2, Math.min(STANDOFF4, shoulder / 3), shoulder, look.body, "matt", "body"),
9541
+ ...lens((body.minX + body.maxX) / 2, (body.minY + body.maxY) / 2, Math.min(width, depth) * LENS_SHARE, shoulder, h, look.top ?? look.body)
9542
+ ];
9543
+ if (corner === void 0) {
9544
+ const cathode = input.pads.find((pad) => pad.number === "2");
9545
+ if (cathode !== void 0) {
9546
+ const side = cathode.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
9547
+ const edge = side > 0 ? body.maxX : body.minX;
9548
+ 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"));
9549
+ }
9550
+ }
9551
+ for (const pad of input.pads) pieces.push(...terminal(pad, body, { inside: INSIDE2, outside: OUTSIDE2, height: Math.min(TERMINAL_HEIGHT, shoulder / 2) }, look.metal));
9552
+ return clipPieces(pieces, input.limit);
9553
+ }
9554
+
9555
+ // studio/src/look/parts/melf.ts
9556
+ var SIDES5 = 16;
9557
+ var CAP_SHARE2 = 0.14;
9558
+ var CAP_LEAST = 0.3;
9559
+ var GLASS_SHARE = 0.93;
9560
+ var BAND_SHARE2 = 0.96;
9561
+ var ROOM_SHARE = 0.95;
9562
+ function round(radius, axisHeight) {
9563
+ 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) }));
9564
+ }
9565
+ function melfShape(input) {
9566
+ const axis = twoPads(input);
9567
+ if (axis === void 0) return [];
9568
+ const flat = Math.abs(Math.sin(axis.angle * Math.PI / 180)) > 0.7;
9569
+ 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);
9570
+ const radius = Math.min(input.height / 2, room * ROOM_SHARE);
9571
+ const half = axis.bodyAlong / 2;
9572
+ const cap = Math.max(axis.bodyAlong * CAP_SHARE2, CAP_LEAST);
9573
+ const band3 = Math.max(axis.bodyAlong * 0.14, 0.3);
9574
+ const { look } = input;
9575
+ const pieces = [
9576
+ ...lying(round(radius, radius), -half, -half + cap, look.metal, "metal", "cap"),
9577
+ ...lying(round(radius, radius), half - cap, half, look.metal, "metal", "cap"),
9578
+ ...lying(round(radius * GLASS_SHARE, radius), -half + cap, half - cap, look.body, "matt", "body"),
9579
+ ...lying(round(radius * BAND_SHARE2, radius), half - cap - band3, half - cap, look.mark, "matt", "cathode")
9580
+ ];
9581
+ return settle(pieces, axis, input);
9582
+ }
9583
+
9584
+ // studio/src/look/parts/plcc.ts
9585
+ var STANDOFF5 = 0.5;
9586
+ var STRIP = 0.2;
9587
+ var RISE_SHARE = 0.3;
9588
+ var RISE_MOST = 1.5;
9589
+ var TUCK = 0.9;
9590
+ var TOE = 0.3;
9591
+ var CLIP = 1.2;
9592
+ var DOT_RADIUS = 0.5;
9593
+ var DOT_INSET = 1.3;
9594
+ function plccShape(input) {
9595
+ const body = input.body ?? bodyRect(input);
9596
+ const h = input.height;
9597
+ const { top } = bodyBand(h);
9598
+ const standoff = Math.min(STANDOFF5, h * 0.2);
9599
+ const strip = Math.min(STRIP, h * 0.1);
9600
+ const { look } = input;
9601
+ const rise = Math.min(h * RISE_SHARE, RISE_MOST);
9602
+ const pieces = [...prism(clippedCorner(body, -1, 1, CLIP), standoff, top, look.body, "matt", "body")];
9603
+ 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));
9604
+ const one = firstPad(input.pads);
9605
+ 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"));
9606
+ return clipPieces(pieces, input.limit);
9607
+ }
9608
+
9609
+ // studio/src/look/parts/smdcan.ts
9610
+ var STANDOFF6 = 0.12;
9611
+ var BASE_SHARE = 0.15;
9612
+ var BASE_LEAST = 0.8;
9613
+ var BASE_MOST = 1.2;
9614
+ var BASE_CEILING = 0.4;
9615
+ var ROUND = 0.35;
9616
+ var ROUND_STEPS = 3;
9617
+ var LID_DROP = 0.02;
9618
+ var SIDES6 = 28;
9619
+ var SEGMENT_FROM = 0.45;
9620
+ var SEGMENT_SHARE = 0.92;
9621
+ var STRIP2 = 0.12;
9622
+ var REACH = 0.6;
9623
+ var TUCK2 = 0.8;
9624
+ function baseOutline(input, body) {
9625
+ const first = input.outlines?.[0];
9626
+ 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 }];
9627
+ const [a, z] = [first[0], first[first.length - 1]];
9628
+ return a.x === z.x && a.y === z.y ? first.slice(0, -1) : first;
9629
+ }
9630
+ function canRadius(input, body) {
9631
+ const circle4 = input.outlines?.find((line2, i) => i > 0 && line2.length > 16);
9632
+ const found = circle4 === void 0 ? void 0 : rectOf(circle4);
9633
+ return found === void 0 ? Math.min(body.maxX - body.minX, body.maxY - body.minY) / 2 - 0.15 : (found.maxX - found.minX) / 2;
9634
+ }
9635
+ function segment(radius, from) {
9636
+ const reach = Math.acos(Math.min(1, from / radius));
9637
+ 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) }));
9638
+ return arc;
9639
+ }
9640
+ function smdCanShape(input) {
9641
+ const body = clipped(input.body ?? grown3(padsRect(input.pads) ?? input.limit, -0.1), input.limit);
9642
+ const h = input.height;
9643
+ const { look } = input;
9644
+ const baseTop = Math.min(BASE_MOST, Math.max(BASE_LEAST, h * BASE_SHARE), h * BASE_CEILING);
9645
+ const standoff = Math.min(STANDOFF6, baseTop / 3);
9646
+ const radius = canRadius(input, body);
9647
+ const lidZ = h - Math.min(LID_DROP, h * 0.1);
9648
+ const round2 = Math.min(ROUND, (lidZ - baseTop) / 2, radius / 2);
9649
+ const lidRadius = radius - round2;
9650
+ const edge = Array.from({ length: ROUND_STEPS + 1 }, (_, i) => {
9651
+ const angle = Math.PI / 2 * (i / ROUND_STEPS);
9652
+ return [lidRadius + round2 * Math.cos(angle), lidZ - round2 + round2 * Math.sin(angle)];
9653
+ });
9654
+ const profile = [[radius, baseTop], ...edge];
9655
+ const dark = segment(lidRadius * SEGMENT_SHARE, lidRadius * SEGMENT_SHARE * SEGMENT_FROM);
9656
+ const pieces = [
9657
+ ...prism(baseOutline(input, body), standoff, baseTop, look.body, "matt", "body"),
9658
+ ...lathe(profile, 0, 0, SIDES6, { top: look.top ?? look.metal, side: look.metal }, "metal", "body"),
9659
+ ...prism(dark, lidZ, h, look.mark, "matt", "cathode")
9660
+ ];
9661
+ const strip = Math.min(STRIP2, standoff);
9662
+ const rise = (standoff + baseTop) / 2 + strip / 2;
9663
+ 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));
9664
+ return clipPieces(pieces, input.limit);
9665
+ }
9666
+
9667
+ // studio/src/look/parts/tantalum.ts
9668
+ var WRAP = 0.62;
9669
+ var THICK = 0.12;
9670
+ var TUCK3 = 0.8;
9671
+ var STRIPE_SHARE = 0.16;
9672
+ var STRIPE_LEAST = 0.3;
9673
+ function tantalumShape(input) {
9674
+ const axis = twoPads(input);
9675
+ if (axis === void 0) return [];
9676
+ const [half, across] = [axis.bodyAlong / 2, axis.bodyAcross / 2];
9677
+ const h = input.height;
9678
+ const { bottom, top } = bodyBand(h);
9679
+ const { look } = input;
9680
+ const local = (minX, maxX, y) => ({ minX, maxX, minY: -y, maxY: y });
9681
+ const stripe = Math.max(axis.bodyAlong * STRIPE_SHARE, STRIPE_LEAST);
9682
+ const wide = Math.min(across, axis.padAcross / 2) * 0.9;
9683
+ const pieces = [
9684
+ ...box(local(-half, half, across), bottom, top, look.body, "matt", "body"),
9685
+ ...box(local(-half + stripe * 0.5, -half + stripe * 1.5, across), top, h, look.mark, "matt", "pin1"),
9686
+ ...box(local(-half - THICK, -half + TUCK3, wide), 0, h * WRAP, look.metal, "metal", "cap"),
9687
+ ...box(local(half - TUCK3, half + THICK, wide), 0, h * WRAP, look.metal, "metal", "cap")
9688
+ ];
9689
+ return settle(pieces, axis, input);
9690
+ }
9691
+
9692
+ // studio/src/look/parts/xtal.ts
9693
+ var STANDOFF7 = 0.04;
9694
+ var TERMINAL_HEIGHT2 = 0.3;
9695
+ var LID_SHARE = 0.4;
9696
+ var LID_INSET = 0.08;
9697
+ var SEAT_SHARE = 0.24;
9698
+ var FOOT = 0.15;
9699
+ var CAN_MARGIN = 0.25;
9700
+ function ceramicShape(input, body) {
9701
+ const h = input.height;
9702
+ const { look } = input;
9703
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9704
+ const lid2 = grown3(body, -Math.min(small * LID_INSET, 0.2));
9705
+ const split = h * (1 - LID_SHARE);
9706
+ const pieces = [
9707
+ ...box(body, Math.min(STANDOFF7, split / 2), split, look.body, "matt", "body"),
9708
+ ...box(lid2, split, bodyBand(h).top, look.top ?? look.metal, "metal", "body"),
9709
+ ...pin1Dot(input, lid2, bodyBand(h).top)
9710
+ ];
9711
+ 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));
9712
+ return pieces;
9713
+ }
9714
+ function canShape(input, body) {
9715
+ const h = input.height;
9716
+ const { look } = input;
9717
+ const [length2, width] = [body.maxX - body.minX, body.maxY - body.minY];
9718
+ const seatTop = Math.min(Math.max(h * SEAT_SHARE, 0.6), h / 2);
9719
+ const foot = Math.min(FOOT, seatTop / 3);
9720
+ const seat = grown3(body, -0.15);
9721
+ const pieces = [
9722
+ ...box(seat, foot, seatTop, look.mark, "matt", "body"),
9723
+ ...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")
9724
+ ];
9725
+ for (const pad of input.pads) pieces.push(...box(clipped(grown3(padRect(pad), -0.1), input.limit), 0, foot, look.metal, "metal", "leg"));
9726
+ return pieces;
9727
+ }
9728
+ function xtalShape(input) {
9729
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9730
+ const pieces = input.parsed?.kind === "hc" ? canShape(input, body) : ceramicShape(input, body);
9731
+ return clipPieces(pieces, input.limit);
9732
+ }
9733
+
9734
+ // studio/src/look/parts/smd-shapes.ts
9735
+ var SMD_SHAPES = {
9736
+ melf: melfShape,
9737
+ tantalum: tantalumShape,
9738
+ array: arrayShape,
9739
+ smdcan: smdCanShape,
9740
+ xtal: xtalShape,
9741
+ ledsmd: ledSmdShape,
9742
+ plcc: plccShape
9743
+ };
9744
+
9745
+ // studio/src/look/parts/uno-kit.ts
9746
+ var mean = (values) => values.reduce((sum, v) => sum + v, 0) / (values.length || 1);
9747
+ function wallY(profile, y0, y1, color, material, role, facing = "out") {
9748
+ if (!(y1 > y0) || profile.length < 3) return [];
9749
+ const [cx, cz] = [mean(profile.map((p) => p.x)), mean(profile.map((p) => p.y))];
9750
+ const sign = facing === "out" ? 1 : -1;
9751
+ return profile.map((p, i) => {
9752
+ const q = profile[(i + 1) % profile.length];
9753
+ const outward = [sign * ((p.x + q.x) / 2 - cx), 0, sign * ((p.y + q.y) / 2 - cz)];
9754
+ 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);
9755
+ });
9756
+ }
9757
+ var capY = (profile, y, toward, color, material, role) => facet(profile.map((p) => [p.x, y, p.y]), [0, toward, 0], color, material, role);
9758
+ function ringY(outer, inner, y, toward, color, material, role) {
9759
+ if (outer.length !== inner.length) return [];
9760
+ return outer.map((p, i) => {
9761
+ const j = (i + 1) % outer.length;
9762
+ const [q, a, b] = [outer[j], inner[i], inner[j]];
9763
+ 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);
9764
+ });
9765
+ }
9766
+ 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)] : [];
9767
+ function openBox(rect2, y0, y1, z0, z1, color, material, role) {
9768
+ if (!(y1 > y0) || !(rect2.maxX > rect2.minX) || !(z1 > z0)) return [];
9769
+ 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);
9770
+ const side = (x, out) => facet([[x, y0, z0], [x, y1, z0], [x, y1, z1], [x, y0, z1]], [out, 0, 0], color, material, role);
9771
+ 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)];
9772
+ }
9773
+ var SLOT_FILL = 0.8;
9774
+ function stripLeads(input, pick, color, half) {
9775
+ const chosen = input.pads.filter(pick);
9776
+ return chosen.flatMap((pad) => {
9777
+ const size = half ?? { x: (pad.drill?.width ?? 0.6) * SLOT_FILL / 2, y: (pad.drill?.height ?? 0.6) * SLOT_FILL / 2 };
9778
+ return leads({ ...input, pads: [pad] }, color, size);
9779
+ });
9780
+ }
9781
+ var TUCK4 = 0.12;
9782
+ function foldedTerminal(pad, body, spec, color, role = "leg") {
9783
+ const r = padRect(pad);
9784
+ const sign = pad.x >= (body.minX + body.maxX) / 2 ? 1 : -1;
9785
+ const edge = sign > 0 ? body.maxX : body.minX;
9786
+ const outer = sign > 0 ? r.maxX : r.minX;
9787
+ const reach = Math.min(spec.reach, Math.abs(outer - edge));
9788
+ if (reach < spec.thick) return [];
9789
+ const half = Math.min(r.maxY - r.minY, spec.across) / 2;
9790
+ const [near, far] = [edge - sign * TUCK4, edge + sign * reach];
9791
+ const span = (a, b) => ({ minX: Math.min(a, b), maxX: Math.max(a, b), minY: pad.y - half, maxY: pad.y + half });
9792
+ const foot = box(span(near, far), 0, spec.thick, color, "metal", role);
9793
+ const riser = box(span(edge, edge + sign * spec.thick), spec.thick, spec.rise, color, "metal", role);
9794
+ return [...foot, ...riser];
9795
+ }
9796
+
9797
+ // studio/src/look/parts/dcjack.ts
9798
+ var SIDES7 = 16;
9799
+ var PIN_SIDES = 12;
9800
+ var RADIUS = 3.2;
9801
+ var RADIUS_WIDTH_SHARE = 0.36;
9802
+ var RADIUS_HEIGHT_SHARE = 0.3;
9803
+ var CAVITY_DEPTH = 9;
9804
+ var DEPTH_SHARE2 = 0.62;
9805
+ var PIN_SHARE = 0.31;
9806
+ var PIN_LENGTH = 6.5;
9807
+ var PIN_LENGTH_SHARE = 0.72;
9808
+ var FOLD = 3;
9809
+ var FOLD_SHARE = 0.3;
9810
+ function face(x0, x1, y, h, cx, cz, radius, color) {
9811
+ const ring2 = Array.from({ length: SIDES7 }, (_, i) => [cx + radius * Math.cos(2 * Math.PI * i / SIDES7), y, cz + radius * Math.sin(2 * Math.PI * i / SIDES7)]);
9812
+ return { loops: [[[x0, y, 0], [x1, y, 0], [x1, y, h], [x0, y, h]], [...ring2].reverse()], normal: [0, -1, 0], color, material: "matt", role: "body" };
9813
+ }
9814
+ function dcJackShape(input) {
9815
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9816
+ const { look } = input;
9817
+ const h = input.height;
9818
+ const cx = (body.minX + body.maxX) / 2;
9819
+ const radius = Math.min(RADIUS, (body.maxX - body.minX) * RADIUS_WIDTH_SHARE, h * RADIUS_HEIGHT_SHARE);
9820
+ const back = body.minY + Math.min(CAVITY_DEPTH, (body.maxY - body.minY) * DEPTH_SHARE2);
9821
+ const opening2 = circle3(cx, h / 2, radius, SIDES7);
9822
+ const pin = circle3(cx, h / 2, radius * PIN_SHARE, PIN_SIDES);
9823
+ const tip = back - Math.min(PIN_LENGTH, (back - body.minY) * PIN_LENGTH_SHARE);
9824
+ const sides = prism(rectPolygon(body), 0, h, look.body, "matt", "body").filter((piece) => piece.normal[1] > -0.99);
9825
+ const pieces = [
9826
+ ...sides,
9827
+ face(body.minX, body.maxX, body.minY, h, cx, h / 2, radius, look.body),
9828
+ ...wallY(opening2, body.minY, back, look.mark, "matt", "body", "in"),
9829
+ capY(opening2, back, -1, look.mark, "matt", "body"),
9830
+ ...wallY(pin, tip, back, look.metal, "metal", "pin"),
9831
+ capY(pin, tip, -1, look.metal, "metal", "pin")
9832
+ ];
9833
+ for (const pad of input.pads) {
9834
+ const half = { x: (pad.drill?.width ?? 0.6) * 0.8 / 2, y: (pad.drill?.height ?? 0.6) * 0.8 / 2 };
9835
+ const [lo, hi] = [pad.x - half.x, pad.x + half.x];
9836
+ 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"));
9837
+ 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"));
9838
+ }
9839
+ return [...pieces, ...stripLeads(input, () => true, look.metal)];
9840
+ }
9841
+
9842
+ // studio/src/look/parts/inductor.ts
9843
+ var STANDOFF8 = 0.08;
9844
+ var STANDOFF_SHARE = 0.05;
9845
+ var MARK_RISE = 0.04;
9846
+ var MARK_SHARE = 0.03;
9847
+ var CLIP_SHARE2 = 0.1;
9848
+ var CLIP_MOST = 0.8;
9849
+ var MARK_RADIUS_SHARE = 0.05;
9850
+ var MARK_RADIUS_LEAST = 0.18;
9851
+ var MARK_INSET_SHARE = 0.22;
9852
+ var MARK_SIDES = 12;
9853
+ var FOOT2 = 0.15;
9854
+ var FOOT_SHARE = 0.2;
9855
+ var RISE = 0.9;
9856
+ var RISE_SHARE2 = 0.5;
9857
+ var ACROSS_SHARE = 0.8;
9858
+ var TERMINAL_REACH = 3;
9859
+ function clippedRect(r, cut) {
9860
+ return [
9861
+ { x: r.minX + cut, y: r.minY },
9862
+ { x: r.maxX - cut, y: r.minY },
9863
+ { x: r.maxX, y: r.minY + cut },
9864
+ { x: r.maxX, y: r.maxY - cut },
9865
+ { x: r.maxX - cut, y: r.maxY },
9866
+ { x: r.minX + cut, y: r.maxY },
9867
+ { x: r.minX, y: r.maxY - cut },
9868
+ { x: r.minX, y: r.minY + cut }
9869
+ ];
9870
+ }
9871
+ function inductorShape(input) {
9872
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9873
+ const { look } = input;
9874
+ const h = input.height;
9875
+ const side = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9876
+ const rise = Math.min(MARK_RISE, h * MARK_SHARE);
9877
+ const one = firstPad(input.pads);
9878
+ const left = one === void 0 || one.x <= (body.minX + body.maxX) / 2;
9879
+ const inset = side * MARK_INSET_SHARE;
9880
+ const mark2 = circle3(left ? body.minX + inset : body.maxX - inset, body.maxY - inset, Math.max(side * MARK_RADIUS_SHARE, MARK_RADIUS_LEAST), MARK_SIDES);
9881
+ const fold = { reach: TERMINAL_REACH, thick: Math.min(FOOT2, h * FOOT_SHARE), rise: Math.min(RISE, h * RISE_SHARE2), across: side * ACROSS_SHARE };
9882
+ const pieces = [
9883
+ ...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"),
9884
+ ...prism(mark2, h - rise, h, look.mark, "matt", "pin1")
9885
+ ];
9886
+ for (const pad of input.pads) pieces.push(...foldedTerminal(pad, body, fold, look.metal));
9887
+ return pieces;
9888
+ }
9889
+
9890
+ // studio/src/look/parts/resonator.ts
9891
+ var STANDOFF9 = 0.04;
9892
+ var STANDOFF_SHARE2 = 0.05;
9893
+ var CERAMIC_SHARE = 0.62;
9894
+ var CAP_INSET2 = 0.1;
9895
+ var CAP_INSET_SHARE2 = 0.1;
9896
+ var TERMINAL_HALF = 0.18;
9897
+ var TUCK5 = 0.05;
9898
+ var OUT = 0.12;
9899
+ var TERMINAL_HEIGHT3 = 0.45;
9900
+ var TERMINAL_SHARE2 = 0.8;
9901
+ function resonatorShape(input) {
9902
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9903
+ const { look } = input;
9904
+ const h = input.height;
9905
+ const small = Math.min(body.maxX - body.minX, body.maxY - body.minY);
9906
+ const split = h * CERAMIC_SHARE;
9907
+ const cap = grown3(body, -Math.min(CAP_INSET2, small * CAP_INSET_SHARE2));
9908
+ const pieces = [
9909
+ ...box(body, Math.min(STANDOFF9, h * STANDOFF_SHARE2), split, look.body, "matt", "body"),
9910
+ ...box(cap, split, h, look.metal, "metal", "cap")
9911
+ ];
9912
+ for (const pad of input.pads) {
9913
+ const r = padRect(pad);
9914
+ const x = { minX: Math.max(r.minX, pad.x - TERMINAL_HALF), maxX: Math.min(r.maxX, pad.x + TERMINAL_HALF) };
9915
+ const height = Math.min(TERMINAL_HEIGHT3, split * TERMINAL_SHARE2);
9916
+ const top = { ...x, minY: Math.max(r.minY, body.maxY - TUCK5), maxY: Math.min(r.maxY, body.maxY + OUT) };
9917
+ const bottom = { ...x, minY: Math.max(r.minY, body.minY - OUT), maxY: Math.min(r.maxY, body.minY + TUCK5) };
9918
+ pieces.push(...box(top, 0, height, look.metal, "metal", "leg"), ...box(bottom, 0, height, look.metal, "metal", "leg"));
9919
+ }
9920
+ return pieces;
9921
+ }
9922
+
9923
+ // studio/src/look/parts/tact.ts
9924
+ var BASE_SHARE2 = 0.7;
9925
+ var COVER = 0.3;
9926
+ var COVER_SHARE = 0.07;
9927
+ var COVER_INSET = 0.25;
9928
+ var COVER_INSET_SHARE = 0.04;
9929
+ var BUTTON = 1.7;
9930
+ var BUTTON_SHARE = 0.28;
9931
+ var BUTTON_SIDES = 16;
9932
+ var PIN_HALF2 = { x: 0.25, y: 0.25 };
9933
+ var STRIP3 = { reach: 0.5, thick: 0.15, rise: 0.6, across: 0.9 };
9934
+ var WING = { reach: 1.2, thick: 0.15, rise: 1, across: 0.9 };
9935
+ var THICK_SHARE = 0.1;
9936
+ var RISE_SHARE3 = 0.6;
9937
+ function tactShape(input) {
9938
+ const base = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9939
+ const { look } = input;
9940
+ const h = input.height;
9941
+ const small = Math.min(base.maxX - base.minX, base.maxY - base.minY);
9942
+ const baseTop = h * BASE_SHARE2;
9943
+ const coverTop = baseTop + Math.min(COVER, h * COVER_SHARE);
9944
+ const cover = grown3(base, -Math.min(COVER_INSET, small * COVER_INSET_SHARE));
9945
+ const [cx, cy] = [(base.minX + base.maxX) / 2, (base.minY + base.maxY) / 2];
9946
+ 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");
9947
+ const surface = input.parsed?.params["smd"] === true;
9948
+ const spec = surface ? WING : STRIP3;
9949
+ const fold = { ...spec, thick: Math.min(spec.thick, h * THICK_SHARE), rise: Math.min(spec.rise, baseTop * RISE_SHARE3) };
9950
+ const pieces = [
9951
+ ...box(base, 0, baseTop, look.body, "matt", "body"),
9952
+ ...box(cover, baseTop, coverTop, look.metal, "metal", "cap"),
9953
+ ...button
9954
+ ];
9955
+ for (const pad of input.pads) pieces.push(...foldedTerminal(pad, base, fold, look.metal));
9956
+ return surface ? pieces : [...pieces, ...leads(input, look.metal, PIN_HALF2)];
9957
+ }
9958
+
9959
+ // studio/src/look/parts/usbb.ts
9960
+ var OPENING = { across: 8.4, up: 7.8 };
9961
+ var ACROSS_SHARE2 = 0.7;
9962
+ var UP_SHARE = 0.72;
9963
+ var CAVITY_DEPTH2 = 9;
9964
+ var DEPTH_SHARE3 = 0.55;
9965
+ var TONGUE = { across: 6.2, length: 6, thick: 1.5 };
9966
+ var TONGUE_ACROSS_SHARE = 0.74;
9967
+ var TONGUE_LENGTH_SHARE = 0.7;
9968
+ var TONGUE_THICK_SHARE = 0.2;
9969
+ var SHELL_HOLE = 1.5;
9970
+ var LEG_HALF = { x: 0.2, y: 0.9 };
9971
+ function usbBShape(input) {
9972
+ const shell = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
9973
+ const { look } = input;
9974
+ const h = input.height;
9975
+ const mid = (shell.minX + shell.maxX) / 2;
9976
+ const [across, up] = [Math.min(OPENING.across, (shell.maxX - shell.minX) * ACROSS_SHARE2), Math.min(OPENING.up, h * UP_SHARE)];
9977
+ const [x0, x1, z0, z1] = [mid - across / 2, mid + across / 2, (h - up) / 2, (h + up) / 2];
9978
+ const back = shell.minY + Math.min(CAVITY_DEPTH2, (shell.maxY - shell.minY) * DEPTH_SHARE3);
9979
+ const room = [{ x: x0, y: z0 }, { x: x1, y: z0 }, { x: x1, y: z1 }, { x: x0, y: z1 }];
9980
+ const tongue = { minX: mid - Math.min(TONGUE.across, across * TONGUE_ACROSS_SHARE) / 2, maxX: mid + Math.min(TONGUE.across, across * TONGUE_ACROSS_SHARE) / 2 };
9981
+ const thick = Math.min(TONGUE.thick, up * TONGUE_THICK_SHARE);
9982
+ const sides = prism(rectPolygon(shell), 0, h, look.metal, "metal", "body").filter((piece) => piece.normal[1] > -0.99);
9983
+ const front = [
9984
+ ...frontRect(shell.minX, x0, 0, h, shell.minY, -1, look.metal, "metal", "body"),
9985
+ ...frontRect(x1, shell.maxX, 0, h, shell.minY, -1, look.metal, "metal", "body"),
9986
+ ...frontRect(x0, x1, 0, z0, shell.minY, -1, look.metal, "metal", "body"),
9987
+ ...frontRect(x0, x1, z1, h, shell.minY, -1, look.metal, "metal", "body")
9988
+ ];
9989
+ const cavity = [...wallY(room, shell.minY, back, look.mark, "matt", "body", "in"), capY(room, back, -1, look.mark, "matt", "body")];
9990
+ 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");
9991
+ const signal = leads({ ...input, pads: input.pads.filter((pad) => (pad.drill?.width ?? 0) <= SHELL_HOLE) }, look.metal);
9992
+ return [...sides, ...front, ...cavity, ...plate, ...signal, ...stripLeads(input, (pad) => (pad.drill?.width ?? 0) > SHELL_HOLE, look.metal, LEG_HALF)];
9993
+ }
9994
+
9995
+ // studio/src/look/parts/usbc.ts
9996
+ var STEPS = 8;
9997
+ var ROUND_LIMIT = 0.9;
9998
+ var WALL = 0.35;
9999
+ var WALL_SHARE = 0.12;
10000
+ var REAR_INSET = 0.15;
10001
+ var REAR_INSET_SHARE = 0.1;
10002
+ var REAR_DEPTH = 1.6;
10003
+ var REAR_SHARE = 0.22;
10004
+ var CAVITY_DEPTH3 = 5;
10005
+ var CAVITY_STOP = 0.4;
10006
+ var TONGUE2 = { length: 4.6, shorter: 0.6, thick: 0.6 };
10007
+ var TONGUE_THICK_SHARE2 = 0.28;
10008
+ var TERMINAL2 = 0.45;
10009
+ var TERMINAL_SHARE3 = 0.5;
10010
+ var TAB = 1.6;
10011
+ var TAB_SHARE = 0.5;
10012
+ function usbCShape(input) {
10013
+ const body = clipped(input.body ?? grown3(input.limit, -0.25), input.limit);
10014
+ const { look } = input;
10015
+ const h = input.height;
10016
+ const [mid, length2] = [(body.minX + body.maxX) / 2, body.maxX - body.minX];
10017
+ const wall = Math.min(WALL, h * WALL_SHARE);
10018
+ const inset = Math.min(REAR_INSET, h * REAR_INSET_SHARE);
10019
+ const rear = body.maxY - Math.min(REAR_DEPTH, (body.maxY - body.minY) * REAR_SHARE);
10020
+ const back = Math.min(body.minY + CAVITY_DEPTH3, rear - CAVITY_STOP);
10021
+ const tall = Math.min(h, length2 * ROUND_LIMIT);
10022
+ const outer = stadium2(mid, h / 2, length2, tall, STEPS);
10023
+ const opening2 = stadium2(mid, h / 2, length2 - 2 * wall, tall - 2 * wall, STEPS);
10024
+ const block = stadium2(mid, h / 2, length2 - 2 * inset, tall - 2 * inset, STEPS);
10025
+ const room = { minX: mid - Math.min(length2 / 2 - wall - 0.6, 3.4), maxX: mid + Math.min(length2 / 2 - wall - 0.6, 3.4) };
10026
+ const thick = (tall - 2 * wall) * TONGUE_THICK_SHARE2;
10027
+ const pieces = [
10028
+ ...wallY(outer, body.minY, rear, look.metal, "metal", "body"),
10029
+ capY(outer, rear, 1, look.metal, "metal", "body"),
10030
+ ...ringY(outer, opening2, body.minY, -1, look.metal, "metal", "body"),
10031
+ ...wallY(opening2, body.minY, back, look.mark, "matt", "body", "in"),
10032
+ capY(opening2, back, -1, look.mark, "matt", "body"),
10033
+ ...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"),
10034
+ ...wallY(block, rear, body.maxY, look.mark, "matt", "body"),
10035
+ capY(block, body.maxY, 1, look.mark, "matt", "body")
10036
+ ];
10037
+ const through2 = (pad) => pad.layers === "through";
10038
+ 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"));
10039
+ for (const pad of input.pads.filter(through2)) {
10040
+ const half = { x: (pad.drill?.width ?? 0.6) * 0.8 / 2, y: (pad.drill?.height ?? 0.6) * 0.8 / 2 };
10041
+ 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"));
10042
+ }
10043
+ return [...pieces, ...stripLeads(input, through2, look.metal)];
10044
+ }
10045
+
10046
+ // studio/src/look/parts/uno-shapes.ts
10047
+ var UNO_SHAPES = {
10048
+ usbb: usbBShape,
10049
+ usbc: usbCShape,
10050
+ dcjack: dcJackShape,
10051
+ tact: tactShape,
10052
+ resonator: resonatorShape,
10053
+ inductor: inductorShape
10054
+ };
10055
+
10056
+ // studio/src/look/parts/tab.ts
10057
+ var MIN_REACH = 0.15;
10058
+ var FOOT3 = 0.15;
10059
+ var area = (pad) => pad.width * pad.height;
10060
+ function tabSide(pad, body) {
10061
+ const [cx, cy] = [(body.minX + body.maxX) / 2, (body.minY + body.maxY) / 2];
10062
+ const [dx, dy] = [(pad.x - cx) / ((body.maxX - body.minX) / 2), (pad.y - cy) / ((body.maxY - body.minY) / 2)];
10063
+ if (Math.abs(dy) >= Math.abs(dx)) return dy >= 0 ? "top" : "bottom";
10064
+ return dx >= 0 ? "right" : "left";
10065
+ }
10066
+ function tab(pad, body, height, color) {
10067
+ const r = padRect(pad);
10068
+ const side = tabSide(pad, body);
10069
+ const vertical = side === "top" || side === "bottom";
10070
+ const across = vertical ? r.maxX - r.minX : r.maxY - r.minY;
10071
+ const outside = {
10072
+ minX: side === "right" ? Math.max(r.minX, body.maxX) : r.minX,
10073
+ maxX: side === "left" ? Math.min(r.maxX, body.minX) : r.maxX,
10074
+ minY: side === "top" ? Math.max(r.minY, body.maxY) : r.minY,
10075
+ maxY: side === "bottom" ? Math.min(r.maxY, body.minY) : r.maxY
10076
+ };
10077
+ const reach = vertical ? outside.maxY - outside.minY : outside.maxX - outside.minX;
10078
+ if (reach < MIN_REACH) return box(r, 0, Math.min(FOOT3, height / 3), color, "metal", "leg");
10079
+ 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 };
10080
+ return leg(outer, side, body, height, color, across);
10081
+ }
10082
+ function tabShape(input) {
10083
+ const wide = input.pads.reduce((best, pad) => best === void 0 || area(pad) > area(best) ? pad : best, void 0);
10084
+ const narrow = input.pads.filter((pad) => pad !== wide);
10085
+ const outline2 = input.outlines !== void 0 && input.outlines.length > 1 ? rectOf(input.outlines[0]) : input.body;
10086
+ const body = outline2 ? clipped(outline2, input.limit) : bodyRect({ ...input, pads: narrow });
10087
+ const h = input.height;
10088
+ const { bottom, top } = bodyBand(h);
10089
+ const { look } = input;
10090
+ const pieces = [...box(body, bottom, top, look.body, "matt", "body")];
10091
+ for (const pad of narrow) pieces.push(...leg(pad, padSide(pad), body, h, look.metal));
10092
+ if (wide !== void 0) pieces.push(...tab(wide, body, h, look.metal));
10093
+ pieces.push(...pin1Dot(input, body, top));
10094
+ return clipPieces(pieces, input.limit);
10095
+ }
10096
+
10097
+ // studio/src/look/parts/to220.ts
10098
+ var BODY_SHARE3 = 0.85;
10099
+ var PLASTIC_SHARE = 0.62;
10100
+ var TAB_SHARE2 = 0.28;
10101
+ var HOLE_SHARE = 0.3;
10102
+ var HOLE_SIDES = 14;
10103
+ var PLASTIC_HOLE_FROM = 0.55;
10104
+ var SPECS = {
10105
+ "220": { rise: 16, hole: 1.9, plastic: false, lead: { x: 0.4, y: 0.25 } },
10106
+ "247": { rise: 21, hole: 2.2, plastic: false, lead: { x: 0.6, y: 0.3 } },
10107
+ "126": { rise: 10.8, hole: 1.5, plastic: true, lead: { x: 0.4, y: 0.25 } }
10108
+ };
10109
+ 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)]);
10110
+ function holeWall(cx, hole, frontY, backY, color, material) {
10111
+ const [front, back] = [holeRing(cx, hole, frontY), holeRing(cx, hole, backY)];
10112
+ return front.map((f0, i) => {
10113
+ const j = (i + 1) % HOLE_SIDES;
10114
+ const [f1, b0, b1] = [front[j], back[i], back[j]];
10115
+ const towards = [-((f0[0] + f1[0]) / 2 - cx), 0, -((f0[2] + f1[2]) / 2 - hole.z)];
10116
+ return facet([f0, b0, b1, f1], towards, color, material, "body");
10117
+ });
10118
+ }
10119
+ function tabFaces(slab, zFoot, zPlastic, top, hole, color, material = "metal") {
10120
+ const cx = (slab.minX + slab.maxX) / 2;
10121
+ const [frontY, backY] = [slab.minY, slab.maxY];
10122
+ const front = {
10123
+ loops: [[[slab.minX, frontY, zPlastic], [slab.maxX, frontY, zPlastic], [slab.maxX, frontY, top], [slab.minX, frontY, top]], [...holeRing(cx, hole, frontY)].reverse()],
10124
+ normal: [0, -1, 0],
10125
+ color,
10126
+ material,
10127
+ role: "body"
10128
+ };
10129
+ const mirrored = holeRing(cx, hole, backY).map((p) => [2 * cx - p[0], p[1], p[2]]);
10130
+ const back = {
10131
+ loops: [[[slab.maxX, backY, zFoot], [slab.minX, backY, zFoot], [slab.minX, backY, top], [slab.maxX, backY, top]], [...mirrored].reverse()],
10132
+ normal: [0, 1, 0],
10133
+ color,
10134
+ material,
10135
+ role: "body"
10136
+ };
10137
+ return [front, back, ...holeWall(cx, hole, frontY, backY, color, material)];
10138
+ }
10139
+ function plasticBody(outline2, foot, h, spec, color) {
10140
+ const below = foot + (h - foot) * PLASTIC_HOLE_FROM;
10141
+ const hole = Math.min(spec.hole, (h - below) * HOLE_SHARE, (outline2.maxX - outline2.minX) / 2 - 0.2);
10142
+ const upper = (below + h) / 2;
10143
+ const front = box(outline2, foot, below, color, "matt", "body").filter((piece) => piece.normal[1] < -0.5);
10144
+ const sides = prism(rectPolygon(outline2), foot, h, color, "matt", "body").filter((piece) => Math.abs(piece.normal[1]) < 0.5);
10145
+ return [...front, ...sides, ...tabFaces(outline2, foot, below, h, { z: upper, radius: hole }, color, "matt")];
10146
+ }
10147
+ function to220Shape(input) {
10148
+ const outline2 = clipped(input.body ?? grown3(input.limit, -0.2), input.limit);
10149
+ const { look } = input;
10150
+ const spec = SPECS[input.parsed?.code ?? "220"] ?? SPECS["220"];
10151
+ const h = input.height;
10152
+ const rise = Math.min(spec.rise, h * BODY_SHARE3);
10153
+ const foot = h - rise;
10154
+ const pieces = spec.plastic ? plasticBody(outline2, foot, h, spec, look.body) : tabbedBody(outline2, foot, h, rise, spec, look);
10155
+ for (const pad of input.pads) {
10156
+ 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 };
10157
+ pieces.push(...box(strip, 0, foot, look.metal, "metal", "leg"));
10158
+ }
10159
+ return [...pieces, ...leads(input, look.metal, spec.lead)];
10160
+ }
10161
+ function tabbedBody(outline2, foot, h, rise, spec, look) {
10162
+ const plasticTop = foot + rise * PLASTIC_SHARE;
10163
+ const frontY = outline2.maxY - (outline2.maxY - outline2.minY) * TAB_SHARE2;
10164
+ const radius = Math.min(spec.hole, (h - plasticTop) * HOLE_SHARE, (outline2.maxX - outline2.minX) / 2 - 0.2);
10165
+ const slab = { minX: outline2.minX, maxX: outline2.maxX, minY: frontY, maxY: outline2.maxY };
10166
+ const sides = prism(rectPolygon(slab), foot, h, look.metal, "metal", "body").filter((piece) => Math.abs(piece.normal[1]) < 0.5);
10167
+ return [
10168
+ ...box({ ...outline2, maxY: frontY }, foot, plasticTop, look.body, "matt", "body"),
10169
+ ...sides,
10170
+ ...tabFaces(slab, foot, plasticTop, h, { z: (plasticTop + h) / 2, radius }, look.metal)
10171
+ ];
10172
+ }
10173
+
10174
+ // studio/src/look/parts/to92.ts
10175
+ var STANDOFF10 = 0.7;
10176
+ var STANDOFF_SHARE3 = 0.2;
10177
+ var SHOULDER = 0.35;
10178
+ var SHOULDER_HEIGHT = 0.6;
10179
+ var ARC_STEPS = 14;
10180
+ var LEAD_HALF2 = { x: 0.22, y: 0.2 };
10181
+ function dShape(r) {
10182
+ const radius = (r.maxX - r.minX) / 2;
10183
+ const [cx, cy] = [(r.minX + r.maxX) / 2, r.maxY - radius];
10184
+ const point = (angle) => ({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });
10185
+ if (r.minY < cy - radius) {
10186
+ const back = Array.from({ length: ARC_STEPS + 1 }, (_, i) => point(Math.PI * i / ARC_STEPS));
10187
+ return [...back, { x: cx - radius, y: r.minY }, { x: cx + radius, y: r.minY }];
10188
+ }
10189
+ const start = Math.asin(Math.max(-1, Math.min(1, (r.minY - cy) / radius)));
10190
+ const sweep = Math.PI - 2 * start;
10191
+ const closed = sweep >= 2 * Math.PI - 1e-9;
10192
+ return Array.from({ length: closed ? ARC_STEPS : ARC_STEPS + 1 }, (_, i) => point(start + sweep * i / ARC_STEPS));
10193
+ }
10194
+ function to92Shape(input) {
10195
+ const outline2 = clipped(input.body ?? grown3(input.limit, -0.2), input.limit);
10196
+ const { look } = input;
10197
+ const h = input.height;
10198
+ const foot = Math.min(STANDOFF10, h * STANDOFF_SHARE3);
10199
+ const shoulder = Math.max(foot + 0.1, h - SHOULDER_HEIGHT);
10200
+ const pieces = [
10201
+ ...prism(dShape(outline2), foot, shoulder, look.body, "matt", "body"),
10202
+ ...prism(dShape(grown3(outline2, -SHOULDER)), shoulder, h, look.body, "matt", "body")
10203
+ ];
10204
+ for (const pad of input.pads) {
10205
+ 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 };
10206
+ pieces.push(...box(strip, 0, foot + 0.3, look.metal, "metal", "leg"));
10207
+ }
10208
+ return [...pieces, ...leads(input, look.metal, LEAD_HALF2)];
10209
+ }
10210
+
8788
10211
  // studio/src/look/parts/index.ts
8789
10212
  var SHAPES = {
8790
10213
  chip: chipShape,
@@ -8795,7 +10218,18 @@ var SHAPES = {
8795
10218
  crystal: crystalShape,
8796
10219
  electrolytic: electrolyticShape,
8797
10220
  block: blockShape,
8798
- box: plainBox
10221
+ box: plainBox,
10222
+ bga: bgaShape,
10223
+ dip: dipShape,
10224
+ to220: to220Shape,
10225
+ to92: to92Shape,
10226
+ tab: tabShape,
10227
+ axial: axialShape,
10228
+ ledth: ledShape,
10229
+ screw: screwShape,
10230
+ socket: socketShape,
10231
+ ...SMD_SHAPES,
10232
+ ...UNO_SHAPES
8799
10233
  };
8800
10234
  var FALLBACK = { minX: -0.5, minY: -0.5, maxX: 0.5, maxY: 0.5 };
8801
10235
  function placer(part, thickness) {
@@ -8812,11 +10246,11 @@ function placer(part, thickness) {
8812
10246
  };
8813
10247
  return { point, normal };
8814
10248
  }
8815
- function shapeInput(part, height, look, parsed2, thickness) {
10249
+ function shapeInput(part, height, look, parsed2, thickness, lookName) {
8816
10250
  const footprint = part.footprint;
8817
10251
  const limit = rectOf(footprint?.courtyard ?? []) ?? rectOf((footprint?.pads ?? []).map((p) => ({ x: p.x, y: p.y }))) ?? FALLBACK;
8818
10252
  const body = rectOf((footprint?.fabrication ?? []).flat());
8819
- return { pads: footprint?.pads ?? [], height, limit, ...body ? { body } : {}, look, ...parsed2 ? { parsed: parsed2 } : {}, thickness };
10253
+ return { pads: footprint?.pads ?? [], height, limit, ...body ? { body } : {}, ...footprint?.fabrication.length ? { outlines: footprint.fabrication } : {}, look, ...lookName ? { lookName } : {}, ...parsed2 ? { parsed: parsed2 } : {}, thickness };
8820
10254
  }
8821
10255
  function partFaces(design, model) {
8822
10256
  const thickness = model.board?.thickness ?? model.parts.find((p) => p.side === "top")?.bottom ?? 1.6;
@@ -8827,8 +10261,10 @@ function partFaces(design, model) {
8827
10261
  const component = components.get(part.component);
8828
10262
  const through2 = part.pads.some((pad) => pad.layers === "through");
8829
10263
  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);
10264
+ const paint = family === "ledth" ? ledLook(FAMILY_LOOKS[look], component?.props) : FAMILY_LOOKS[look];
10265
+ const input = shapeInput(part, solid.height, paint, parsed2, thickness, look);
10266
+ const shaped = part.footprint === void 0 ? [] : SHAPES[family](input);
10267
+ const pieces = shaped.length === 0 ? plainBox(input) : shaped;
8832
10268
  const place3 = placer(part, thickness);
8833
10269
  return pieces.map((piece) => ({
8834
10270
  loops: piece.loops.map((loop) => loop.map(place3.point)),
@@ -8874,17 +10310,17 @@ function frameOf(width, height, reuse) {
8874
10310
  const size = width * height;
8875
10311
  return { width, height, color: new Uint8ClampedArray(size * 4), ids: new Int32Array(size), depth: new Float32Array(size), faces: new Int32Array(size) };
8876
10312
  }
8877
- function projectFace(face, view) {
8878
- const facing = dot2(face.normal, view.eye);
10313
+ function projectFace(face2, view) {
10314
+ const facing = dot2(face2.normal, view.eye);
8879
10315
  if (Math.abs(facing) < EDGE_ON) return void 0;
8880
- const first = face.loops[0]?.[0];
10316
+ const first = face2.loops[0]?.[0];
8881
10317
  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);
10318
+ const [nr, nu] = [dot2(face2.normal, view.right), dot2(face2.normal, view.up)];
10319
+ const offset = dot2(face2.normal, view.target) - dot2(face2.normal, first);
8884
10320
  const a = nr / view.scale / facing;
8885
10321
  const b = -nu / view.scale / facing;
8886
10322
  const c = (offset - nr * view.width / 2 / view.scale + nu * view.height / 2 / view.scale) / facing;
8887
- const loops = face.loops.map(
10323
+ const loops = face2.loops.map(
8888
10324
  (loop) => loop.map((p) => {
8889
10325
  const d = [p[0] - view.target[0], p[1] - view.target[1], p[2] - view.target[2]];
8890
10326
  return { x: view.width / 2 + view.scale * dot2(d, view.right), y: view.height / 2 - view.scale * dot2(d, view.up) };
@@ -8892,16 +10328,16 @@ function projectFace(face, view) {
8892
10328
  );
8893
10329
  return { loops, a, b, c };
8894
10330
  }
8895
- function scan(face, width, height, fill) {
10331
+ function scan(face2, width, height, fill) {
8896
10332
  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)];
10333
+ for (const loop of face2.loops) for (const p of loop) [top, bottom] = [Math.min(top, p.y), Math.max(bottom, p.y)];
8898
10334
  const first = Math.max(0, Math.ceil(top - 0.5));
8899
10335
  const last = Math.min(height - 1, Math.floor(bottom - 0.5));
8900
10336
  const crossings = [];
8901
- for (let row = first; row <= last; row++) {
8902
- const y = row + 0.5;
10337
+ for (let row3 = first; row3 <= last; row3++) {
10338
+ const y = row3 + 0.5;
8903
10339
  crossings.length = 0;
8904
- for (const loop of face.loops) {
10340
+ for (const loop of face2.loops) {
8905
10341
  for (let i = 0; i < loop.length; i++) {
8906
10342
  const p = loop[i];
8907
10343
  const q = loop[(i + 1) % loop.length];
@@ -8912,14 +10348,14 @@ function scan(face, width, height, fill) {
8912
10348
  for (let k = 0; k + 1 < crossings.length; k += 2) {
8913
10349
  const from = Math.max(0, Math.ceil(crossings[k] - 0.5));
8914
10350
  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);
10351
+ for (let col = from; col <= to; col++) fill(row3 * width + col, face2.a * (col + 0.5) + face2.b * y + face2.c);
8916
10352
  }
8917
10353
  }
8918
10354
  }
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));
10355
+ function shade(face2, view, highlight) {
10356
+ const light = AMBIENT2 + (1 - AMBIENT2) * Math.abs(dot2(face2.normal, view.eye));
10357
+ const lift = face2.part >= 0 && face2.part === highlight ? HIGHLIGHT : 0;
10358
+ return face2.color.map((channel) => Math.round(channel * light + (255 - channel * light) * lift));
8923
10359
  }
8924
10360
  function renderScene(scene, orbit, width, height, options) {
8925
10361
  const frame = frameOf(width, height, options.reuse);
@@ -8934,31 +10370,31 @@ function renderScene(scene, orbit, width, height, options) {
8934
10370
  drawLit(scene, view, frame, options);
8935
10371
  return frame;
8936
10372
  }
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);
10373
+ const opaque = scene.faces.filter((face2) => face2.alpha >= 1);
10374
+ const clear = scene.faces.filter((face2) => face2.alpha < 1);
10375
+ for (const face2 of opaque) {
10376
+ const projected = projectFace(face2, view);
8941
10377
  if (!projected) continue;
8942
- const [r, g, b] = shade(face, view, options.highlight);
10378
+ const [r, g, b] = shade(face2, view, options.highlight);
8943
10379
  scan(projected, width, height, (index, depth) => {
8944
10380
  if (depth >= frame.depth[index]) return;
8945
10381
  frame.depth[index] = depth;
8946
- frame.ids[index] = face.part;
10382
+ frame.ids[index] = face2.part;
8947
10383
  frame.color[index * 4] = r;
8948
10384
  frame.color[index * 4 + 1] = g;
8949
10385
  frame.color[index * 4 + 2] = b;
8950
10386
  });
8951
10387
  }
8952
- for (const face of clear) {
8953
- const projected = projectFace(face, view);
10388
+ for (const face2 of clear) {
10389
+ const projected = projectFace(face2, view);
8954
10390
  if (!projected) continue;
8955
- const [r, g, b] = shade(face, view, void 0);
8956
- const keep = 1 - face.alpha;
10391
+ const [r, g, b] = shade(face2, view, void 0);
10392
+ const keep = 1 - face2.alpha;
8957
10393
  scan(projected, width, height, (index, depth) => {
8958
10394
  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;
10395
+ frame.color[index * 4] = frame.color[index * 4] * keep + r * face2.alpha;
10396
+ frame.color[index * 4 + 1] = frame.color[index * 4 + 1] * keep + g * face2.alpha;
10397
+ frame.color[index * 4 + 2] = frame.color[index * 4 + 2] * keep + b * face2.alpha;
8962
10398
  });
8963
10399
  }
8964
10400
  return frame;
@@ -8969,20 +10405,20 @@ function drawLit(scene, view, frame, options) {
8969
10405
  const key = keyFor(view.eye);
8970
10406
  const sample = new Float32Array(3);
8971
10407
  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);
10408
+ scene.faces.forEach((face2, index) => {
10409
+ if (dot2(face2.normal, view.eye) <= 0) return;
10410
+ const projected = projectFace(face2, view);
8975
10411
  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;
10412
+ const { scale, add } = lightFace(face2.normal, view.eye, key, face2.material);
10413
+ const lift = face2.part >= 0 && face2.part === options.highlight ? HIGHLIGHT : 0;
8978
10414
  const tone = (c2) => Math.min(255, c2 * scale + add) * (1 - lift) + 255 * lift;
8979
- const paint = face.paint;
10415
+ const paint = face2.paint;
8980
10416
  if (!paint) {
8981
- const [r, g, b2] = [tone(face.color[0]), tone(face.color[1]), tone(face.color[2])];
10417
+ const [r, g, b2] = [tone(face2.color[0]), tone(face2.color[1]), tone(face2.color[2])];
8982
10418
  scan(projected, width, height, (i, depth) => {
8983
10419
  if (depth >= frame.depth[i]) return;
8984
10420
  frame.depth[i] = depth;
8985
- frame.ids[i] = face.part;
10421
+ frame.ids[i] = face2.part;
8986
10422
  frame.faces[i] = index;
8987
10423
  frame.color[i * 4] = r;
8988
10424
  frame.color[i * 4 + 1] = g;
@@ -9008,10 +10444,10 @@ function drawLit(scene, view, frame, options) {
9008
10444
  const { rgba, width: tw, height: th } = texture;
9009
10445
  scan(projected, width, height, (i, depth) => {
9010
10446
  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);
10447
+ const row3 = i / width | 0;
10448
+ const col = i - row3 * width;
10449
+ const u = Math.floor(Au * col + Bu * row3 + Cu);
10450
+ const v = Math.floor(Av * col + Bv * row3 + Cv);
9015
10451
  if (u < 0 || v < 0 || u >= tw || v >= th) return;
9016
10452
  const k = (v * tw + u) * 4;
9017
10453
  if (rgba[k + 3] < 128) return;
@@ -9026,14 +10462,14 @@ function drawLit(scene, view, frame, options) {
9026
10462
  }
9027
10463
  scan(projected, width, height, (i, depth) => {
9028
10464
  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;
10465
+ const row3 = i / width | 0;
10466
+ const col = i - row3 * width;
10467
+ const x = X.A * col + X.B * row3 + X.C;
10468
+ const y = Y.A * col + Y.B * row3 + Y.C;
10469
+ const z = Z.A * col + Z.B * row3 + Z.C;
9034
10470
  if (paint.at(x, y, z, sample, fine) < 0.5) return;
9035
10471
  frame.depth[i] = depth;
9036
- frame.ids[i] = face.part;
10472
+ frame.ids[i] = face2.part;
9037
10473
  frame.faces[i] = index;
9038
10474
  frame.color[i * 4] = tone(sample[0]);
9039
10475
  frame.color[i * 4 + 1] = tone(sample[1]);
@@ -9172,14 +10608,14 @@ function rgb(hex) {
9172
10608
  var sideColor = (side) => rgb(side === "top" ? PALETTE.topAssembly : PALETTE.bottomAssembly);
9173
10609
  var ARC_STEP = Math.PI / 12;
9174
10610
  function loopPoints(loop) {
9175
- return loop.flatMap((segment) => {
9176
- if (segment.kind === "line") return [segment.from];
9177
- const sweep = arcSweep(segment);
10611
+ return loop.flatMap((segment2) => {
10612
+ if (segment2.kind === "line") return [segment2.from];
10613
+ const sweep = arcSweep(segment2);
9178
10614
  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);
10615
+ const start = Math.atan2(segment2.from.y - segment2.centre.y, segment2.from.x - segment2.centre.x);
9180
10616
  return Array.from({ length: pieces }, (_, i) => {
9181
10617
  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) };
10618
+ return i === 0 ? segment2.from : { x: segment2.centre.x + segment2.radius * Math.cos(angle), y: segment2.centre.y + segment2.radius * Math.sin(angle) };
9183
10619
  });
9184
10620
  });
9185
10621
  }
@@ -9233,7 +10669,7 @@ function buildScene(model, options) {
9233
10669
  const faces = [...partFaces2, ...boardFaces];
9234
10670
  const min = [Infinity, Infinity, Infinity];
9235
10671
  const max = [-Infinity, -Infinity, -Infinity];
9236
- for (const point of faces.flatMap((face) => face.loops.flat())) {
10672
+ for (const point of faces.flatMap((face2) => face2.loops.flat())) {
9237
10673
  for (let axis = 0; axis < 3; axis++) {
9238
10674
  min[axis] = Math.min(min[axis], point[axis]);
9239
10675
  max[axis] = Math.max(max[axis], point[axis]);
@@ -9302,7 +10738,7 @@ var pathArea = (path2) => import_clipper_lib.default.Clipper.Area(path2);
9302
10738
  // src/engine/fab/layers.ts
9303
10739
  var DEFAULT_PASTE_REDUCTION = 0;
9304
10740
  var OUTLINE_WIDTH = 0.1;
9305
- var SIDES2 = ["top", "bottom"];
10741
+ var SIDES8 = ["top", "bottom"];
9306
10742
  var ANGLE_TOLERANCE = 1e-9;
9307
10743
  var COPPER_NAME = { top: "F_Cu", inner1: "In1_Cu", inner2: "In2_Cu", bottom: "B_Cu" };
9308
10744
  var SIDE_KEY = { top: "F", bottom: "B" };
@@ -9400,7 +10836,7 @@ function gerberLayers(pcb, fabrication) {
9400
10836
  const position = layer === "top" ? "Top" : layer === "bottom" ? "Bot" : "Inr";
9401
10837
  layers.set(COPPER_NAME[layer], { fileFunction: `Copper,L${i + 1},${position}`, polarity: "Positive", objects: copperObjects(pcb, layer) });
9402
10838
  });
9403
- for (const side of SIDES2) {
10839
+ for (const side of SIDES8) {
9404
10840
  const onSide = pads(pcb.parts).filter((pad) => padOnSide(pad, side));
9405
10841
  const mask = onSide.map((pad) => padObject(pad, expansion, padFunction(pad))).filter(present);
9406
10842
  const paste = onSide.filter(isSmd).map((pad) => padObject(pad, -reduction, padFunction(pad))).filter(present);
@@ -9511,15 +10947,15 @@ function finishStep(below, images, look, relief) {
9511
10947
  const out = new Float32Array(below);
9512
10948
  const colour = [0, 0, 0];
9513
10949
  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;
10950
+ const bare2 = at(images.copper, i) * at(images.openings, i) * at(images.body, i);
10951
+ if (bare2 <= 0) continue;
9516
10952
  const inner = smooth(0.1, 0.9, at(relief.soft, i));
9517
10953
  const glint = relief.slope[i];
9518
10954
  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;
10955
+ const face2 = finish.rim[c] + (finish.face[c] - finish.rim[c]) * inner;
10956
+ colour[c] = glint >= 0 ? face2 + (finish.shine[c] - face2) * glint * 0.8 : face2 + (finish.rim[c] - face2) * -glint * 0.6;
9521
10957
  }
9522
- mixInto(out, i * 3, below, i * 3, colour, bare);
10958
+ mixInto(out, i * 3, below, i * 3, colour, bare2);
9523
10959
  }
9524
10960
  return out;
9525
10961
  }
@@ -9578,15 +11014,15 @@ function compose(images, look, pxPerMm) {
9578
11014
  return { soft, slope: slope(soft, r) };
9579
11015
  };
9580
11016
  const n = images.body.data.length;
9581
- const bare = { ...images.copper, data: new Float32Array(n) };
11017
+ const bare2 = { ...images.copper, data: new Float32Array(n) };
9582
11018
  const solid = { ...images.body, data: new Float32Array(n) };
9583
11019
  for (let i = 0; i < n; i += 1) {
9584
- bare.data[i] = at(images.copper, i) * at(images.openings, i);
11020
+ bare2.data[i] = at(images.copper, i) * at(images.openings, i);
9585
11021
  solid.data[i] = at(images.body, i) * (1 - through(images, i));
9586
11022
  }
9587
11023
  const body = bodyStep(images);
9588
11024
  const masked = maskStep(body, images, look, relief(images.copper, MASK_SOFTNESS));
9589
- const plated = finishStep(masked, images, look, relief(bare, FINISH_SOFTNESS));
11025
+ const plated = finishStep(masked, images, look, relief(bare2, FINISH_SOFTNESS));
9590
11026
  const printed = silkStep(plated, images, look);
9591
11027
  const holed = holesStep(printed, images);
9592
11028
  const edged = edgeStep(holed, soften(solid, radiusOf(EDGE_SOFTNESS, pxPerMm)));
@@ -9605,7 +11041,7 @@ function toPixel(grid, p) {
9605
11041
  const x = grid.mirrored ? grid.maxX - p.x : p.x - grid.minX;
9606
11042
  return { x: x * grid.pxPerMm, y: (grid.maxY - p.y) * grid.pxPerMm };
9607
11043
  }
9608
- function band(d, half) {
11044
+ function band2(d, half) {
9609
11045
  const a = Math.max(d - 0.5, -half);
9610
11046
  const b = Math.min(d + 0.5, half);
9611
11047
  return b > a ? Math.min(b - a, 1) : 0;
@@ -9627,12 +11063,12 @@ function eachPixel(layer, a, b, reach, cover, paint) {
9627
11063
  const y0 = Math.max(0, Math.floor(Math.min(a.y, b.y) - reach));
9628
11064
  const y1 = Math.min(layer.height, Math.ceil(Math.max(a.y, b.y) + reach));
9629
11065
  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);
11066
+ const row3 = y * layer.width;
11067
+ for (let x = x0; x < x1; x += 1) put(layer.data, row3 + x, cover(x + 0.5, y + 0.5), paint);
9632
11068
  }
9633
11069
  }
9634
11070
  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);
11071
+ eachPixel(layer, c, c, r + 1, (x, y) => band2(length(x - c.x, y - c.y), r), paint);
9636
11072
  }
9637
11073
  function capsule(layer, a, b, r, paint = "dark") {
9638
11074
  const [dx, dy] = [b.x - a.x, b.y - a.y];
@@ -9645,7 +11081,7 @@ function capsule(layer, a, b, r, paint = "dark") {
9645
11081
  r + 1,
9646
11082
  (x, y) => {
9647
11083
  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);
11084
+ return band2(length(x - a.x - t * dx, y - a.y - t * dy), r);
9649
11085
  },
9650
11086
  paint
9651
11087
  );
@@ -9662,7 +11098,7 @@ function box2(layer, c, hw, hh, angle, radius, paint = "dark") {
9662
11098
  (x, y) => {
9663
11099
  const u = (x - c.x) * cos + (y - c.y) * sin;
9664
11100
  const v = -(x - c.x) * sin + (y - c.y) * cos;
9665
- if (rounded <= 0) return band(u, hw) * band(v, hh);
11101
+ if (rounded <= 0) return band2(u, hw) * band2(v, hh);
9666
11102
  const qx = Math.abs(u) - (hw - rounded);
9667
11103
  const qy = Math.abs(v) - (hh - rounded);
9668
11104
  const outside = length(Math.max(qx, 0), Math.max(qy, 0));
@@ -9734,10 +11170,10 @@ function polygons(layer, paths, rule, paint = "dark") {
9734
11170
  }
9735
11171
  }
9736
11172
  let run = 0;
9737
- const row = y * layer.width;
11173
+ const row3 = y * layer.width;
9738
11174
  for (let x = from; x < to; x += 1) {
9739
11175
  run += steps[x];
9740
- put(layer.data, row + x, Math.min(run + parts[x], 1), paint);
11176
+ put(layer.data, row3 + x, Math.min(run + parts[x], 1), paint);
9741
11177
  parts[x] = 0;
9742
11178
  steps[x] = 0;
9743
11179
  }
@@ -9885,11 +11321,11 @@ var SHADOW_HEIGHT = 2.6;
9885
11321
  var SOFT = 0.45;
9886
11322
  function hull2(points) {
9887
11323
  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);
11324
+ const cross3 = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
9889
11325
  const half = (list) => {
9890
11326
  const out = [];
9891
11327
  for (const p of list) {
9892
- while (out.length >= 2 && cross2(out[out.length - 2], out[out.length - 1], p) <= 0) out.pop();
11328
+ while (out.length >= 2 && cross3(out[out.length - 2], out[out.length - 1], p) <= 0) out.pop();
9893
11329
  out.push(p);
9894
11330
  }
9895
11331
  out.pop();
@@ -9999,18 +11435,26 @@ function heightWords(model) {
9999
11435
  const part = (list, word) => list.length === 0 ? `none ${word}` : list.length <= NAMED ? `${word}: ${list.join(", ")}` : `${list.length} ${word}`;
10000
11436
  return `heights ${part(typical, "typical")}; ${part(assumed, "assumed")}`;
10001
11437
  }
11438
+ function lookScene(design, look) {
11439
+ const model = solidModel(design);
11440
+ const textures = boardTextures(design, model, look);
11441
+ const scene = buildScene(model, { parts: partFaces(design, model), textures, look, mounting: design.pcb.holes.length, layers: design.pcb.board?.layers ?? 2 });
11442
+ return { model, scene };
11443
+ }
11444
+ function shapesWords(model, look) {
11445
+ return `the board as made (${lookWords(resolveLook(look))}) and ${partsWords(model)}`;
11446
+ }
11447
+ var partsWords = (model) => `${model.parts.length} parts as simple shapes, not their real models; ${heightWords(model)}`;
10002
11448
  function lookPicture(design, request) {
10003
11449
  const width = request.width ?? DEFAULT_WIDTH2;
10004
11450
  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
11451
  const height = Math.round(width * ASPECT);
10006
11452
  const angle = request.angle ?? "iso";
10007
11453
  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 });
11454
+ resolveLook(look);
11455
+ const { model, scene } = lookScene(design, look);
11456
+ const what = `3D from ${angle}, ${shapesWords(model, look)}`;
10012
11457
  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
11458
  return { rgba: frame.color, width, height, what, label: designName(design.file) };
10015
11459
  }
10016
11460
  async function renderLook(design, request) {
@@ -10025,6 +11469,238 @@ async function renderLook(design, request) {
10025
11469
  return { png: new Uint8Array(png), width: picture.width, height: picture.height, what: picture.what, label: picture.label };
10026
11470
  }
10027
11471
 
11472
+ // studio/src/look/glb.ts
11473
+ import earcut from "earcut";
11474
+ var FLOAT = 5126;
11475
+ var UINT = 5125;
11476
+ var ARRAY_BUFFER = 34962;
11477
+ var ELEMENT_ARRAY_BUFFER = 34963;
11478
+ var LINEAR = 9729;
11479
+ var LINEAR_MIPMAP_LINEAR = 9987;
11480
+ var CLAMP_TO_EDGE = 33071;
11481
+ var TO_METRES_Y_UP = [1e-3, 0, 0, 0, 0, 0, -1e-3, 0, 0, 1e-3, 0, 0, 0, 0, 0, 1];
11482
+ var SURFACE = {
11483
+ matt: { metallicFactor: 0, roughnessFactor: 0.8 },
11484
+ metal: { metallicFactor: 0.75, roughnessFactor: 0.35 }
11485
+ };
11486
+ var BOARD_SURFACE = { metallicFactor: 0, roughnessFactor: 0.55 };
11487
+ var STRIP_HEIGHT = 128;
11488
+ var STRIP_WIDTH = 4;
11489
+ var round4 = (value) => Math.round(value * 1e4) / 1e4;
11490
+ var linear = (channel) => {
11491
+ const c = channel / 255;
11492
+ return round4(c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
11493
+ };
11494
+ function triangles(face2) {
11495
+ const corners = face2.loops.flat();
11496
+ const [nx, ny, nz] = face2.normal.map(Math.abs);
11497
+ const drop = nx >= ny && nx >= nz ? 0 : ny >= nz ? 1 : 2;
11498
+ const [a, b] = [(drop + 1) % 3, (drop + 2) % 3];
11499
+ const flat = corners.flatMap((corner) => [corner[a], corner[b]]);
11500
+ const holes = [];
11501
+ face2.loops.slice(0, -1).reduce((count, loop) => (holes.push(count + loop.length), count + loop.length), 0);
11502
+ const cut = earcut(flat, holes, 2);
11503
+ const indices = [];
11504
+ for (let i = 0; i < cut.length; i += 3) {
11505
+ const [p, q, r] = [cut[i], cut[i + 1], cut[i + 2]];
11506
+ const [P, Q, R] = [corners[p], corners[q], corners[r]];
11507
+ const [ux, uy, uz] = [Q[0] - P[0], Q[1] - P[1], Q[2] - P[2]];
11508
+ const [vx, vy, vz] = [R[0] - P[0], R[1] - P[1], R[2] - P[2]];
11509
+ const along = (uy * vz - uz * vy) * face2.normal[0] + (uz * vx - ux * vz) * face2.normal[1] + (ux * vy - uy * vx) * face2.normal[2];
11510
+ if (along === 0) continue;
11511
+ indices.push(p, ...along > 0 ? [q, r] : [r, q]);
11512
+ }
11513
+ return { corners, indices };
11514
+ }
11515
+ function pack(json, bin) {
11516
+ const text2 = new TextEncoder().encode(JSON.stringify(json));
11517
+ const jsonLength = Math.ceil(text2.length / 4) * 4;
11518
+ const out = new Uint8Array(12 + 8 + jsonLength + 8 + bin.length);
11519
+ const view = new DataView(out.buffer);
11520
+ view.setUint32(0, 1179937895, true);
11521
+ view.setUint32(4, 2, true);
11522
+ view.setUint32(8, out.length, true);
11523
+ view.setUint32(12, jsonLength, true);
11524
+ view.setUint32(16, 1313821514, true);
11525
+ out.fill(32, 20, 20 + jsonLength);
11526
+ out.set(text2, 20);
11527
+ view.setUint32(20 + jsonLength, bin.length, true);
11528
+ view.setUint32(24 + jsonLength, 5130562, true);
11529
+ out.set(bin, 28 + jsonLength);
11530
+ return out;
11531
+ }
11532
+ function sceneGlb(scene, options) {
11533
+ const chunks = [];
11534
+ let length2 = 0;
11535
+ const bufferViews = [];
11536
+ const addView = (bytes, target) => {
11537
+ bufferViews.push({ buffer: 0, byteOffset: length2, byteLength: bytes.length, ...target !== void 0 ? { target } : {} });
11538
+ const padded = Math.ceil(bytes.length / 4) * 4;
11539
+ const chunk2 = new Uint8Array(padded);
11540
+ chunk2.set(bytes);
11541
+ chunks.push(chunk2);
11542
+ length2 += padded;
11543
+ return bufferViews.length - 1;
11544
+ };
11545
+ const bytesOf = (array2) => new Uint8Array(array2.buffer, array2.byteOffset, array2.byteLength);
11546
+ const images = [];
11547
+ const pictures = /* @__PURE__ */ new Map();
11548
+ const painted = scene.faces.filter((face2) => face2.paint !== void 0);
11549
+ for (const paint of new Set(painted.map((face2) => face2.paint))) {
11550
+ const texture = paint.texture;
11551
+ if (texture) {
11552
+ const sign = texture.mirrored ? -1 : 1;
11553
+ images.push({ bufferView: addView(options.png(texture)), mimeType: "image/png", name: texture.mirrored ? "board bottom" : "board top" });
11554
+ pictures.set(paint, { 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] });
11555
+ continue;
11556
+ }
11557
+ let [low, high] = [Infinity, -Infinity];
11558
+ for (const face2 of painted) {
11559
+ if (face2.paint !== paint) continue;
11560
+ for (const point of face2.loops.flat()) [low, high] = [Math.min(low, point[2]), Math.max(high, point[2])];
11561
+ }
11562
+ const span = high - low || 1;
11563
+ const [x, y] = painted.find((face2) => face2.paint === paint).loops[0]?.[0] ?? [0, 0];
11564
+ const rgba = new Uint8ClampedArray(STRIP_WIDTH * STRIP_HEIGHT * 4);
11565
+ const colour = new Float32Array(3);
11566
+ for (let row3 = 0; row3 < STRIP_HEIGHT; row3++) {
11567
+ const alpha = paint.at(x, y, high - (row3 + 0.5) / STRIP_HEIGHT * span, colour, true);
11568
+ for (let column = 0; column < STRIP_WIDTH; column++) rgba.set([colour[0], colour[1], colour[2], alpha * 255], (row3 * STRIP_WIDTH + column) * 4);
11569
+ }
11570
+ images.push({ bufferView: addView(options.png({ rgba, width: STRIP_WIDTH, height: STRIP_HEIGHT })), mimeType: "image/png", name: "board edge" });
11571
+ pictures.set(paint, { image: images.length - 1, map: (p) => [0.5, (high - p[2]) / span] });
11572
+ }
11573
+ const materials = [];
11574
+ const materialOf = /* @__PURE__ */ new Map();
11575
+ const material = (face2) => {
11576
+ const picture = face2.paint ? pictures.get(face2.paint) : void 0;
11577
+ const key = picture ? `picture ${picture.image}` : `${face2.color.join(",")} ${face2.alpha} ${face2.material ?? "matt"}`;
11578
+ const known = materialOf.get(key);
11579
+ if (known !== void 0) return known;
11580
+ const made = picture ? { name: images[picture.image]?.name, pbrMetallicRoughness: { baseColorTexture: { index: picture.image }, ...BOARD_SURFACE }, ...face2.paint?.texture ? { alphaMode: "MASK", alphaCutoff: 0.5 } : {} } : {
11581
+ pbrMetallicRoughness: { baseColorFactor: [linear(face2.color[0]), linear(face2.color[1]), linear(face2.color[2]), face2.alpha], ...SURFACE[face2.material ?? "matt"] },
11582
+ ...face2.alpha < 1 ? { alphaMode: "BLEND" } : {}
11583
+ };
11584
+ materials.push(made);
11585
+ materialOf.set(key, materials.length - 1);
11586
+ return materials.length - 1;
11587
+ };
11588
+ const owners = [...new Set(scene.faces.map((face2) => face2.part))].sort((a, b) => a - b);
11589
+ const accessors = [];
11590
+ const meshes = [];
11591
+ const children = [];
11592
+ const nodes = [{ name: options.name, matrix: TO_METRES_Y_UP, children }];
11593
+ for (const owner of owners) {
11594
+ const gathered = /* @__PURE__ */ new Map();
11595
+ for (const face2 of scene.faces) {
11596
+ if (face2.part !== owner) continue;
11597
+ const { corners, indices } = triangles(face2);
11598
+ if (indices.length === 0) continue;
11599
+ const number = material(face2);
11600
+ const map = face2.paint ? pictures.get(face2.paint)?.map : void 0;
11601
+ const into = gathered.get(number) ?? { material: number, positions: [], normals: [], uvs: map ? [] : void 0, indices: [] };
11602
+ gathered.set(number, into);
11603
+ const first = into.positions.length / 3;
11604
+ for (const corner of corners) {
11605
+ into.positions.push(...corner);
11606
+ into.normals.push(...face2.normal);
11607
+ if (map) into.uvs?.push(...map(corner));
11608
+ }
11609
+ for (const index of indices) into.indices.push(first + index);
11610
+ }
11611
+ if (gathered.size === 0) continue;
11612
+ const primitives = [...gathered.values()].map((one) => {
11613
+ const positions = new Float32Array(one.positions);
11614
+ const min = [Infinity, Infinity, Infinity];
11615
+ const max = [-Infinity, -Infinity, -Infinity];
11616
+ positions.forEach((value, i) => {
11617
+ min[i % 3] = Math.min(min[i % 3], value);
11618
+ max[i % 3] = Math.max(max[i % 3], value);
11619
+ });
11620
+ const accessor = (array2, type, target, more = {}) => {
11621
+ const width = type === "VEC3" ? 3 : type === "VEC2" ? 2 : 1;
11622
+ accessors.push({ bufferView: addView(bytesOf(array2), target), componentType: array2 instanceof Float32Array ? FLOAT : UINT, count: array2.length / width, type, ...more });
11623
+ return accessors.length - 1;
11624
+ };
11625
+ const attributes = {
11626
+ POSITION: accessor(positions, "VEC3", ARRAY_BUFFER, { min, max }),
11627
+ NORMAL: accessor(new Float32Array(one.normals), "VEC3", ARRAY_BUFFER),
11628
+ ...one.uvs ? { TEXCOORD_0: accessor(new Float32Array(one.uvs), "VEC2", ARRAY_BUFFER) } : {}
11629
+ };
11630
+ return { attributes, indices: accessor(new Uint32Array(one.indices), "SCALAR", ELEMENT_ARRAY_BUFFER), material: one.material };
11631
+ });
11632
+ const name = owner < 0 ? "board" : options.names[owner] ?? `part ${owner + 1}`;
11633
+ meshes.push({ name, primitives });
11634
+ nodes.push({ name, mesh: meshes.length - 1 });
11635
+ children.push(nodes.length - 1);
11636
+ }
11637
+ if (meshes.length === 0) throw new Error("Nothing to write: the scene has no faces");
11638
+ const bin = new Uint8Array(length2);
11639
+ chunks.reduce((offset, chunk2) => (bin.set(chunk2, offset), offset + chunk2.length), 0);
11640
+ const json = {
11641
+ asset: { version: "2.0", generator: "copperflow" },
11642
+ scene: 0,
11643
+ scenes: [{ name: options.name, nodes: [0] }],
11644
+ nodes,
11645
+ meshes,
11646
+ materials,
11647
+ accessors,
11648
+ bufferViews,
11649
+ buffers: [{ byteLength: bin.length }],
11650
+ ...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 }] } : {}
11651
+ };
11652
+ return pack(json, bin);
11653
+ }
11654
+
11655
+ // studio/src/render/png-bytes.ts
11656
+ import { deflateSync } from "node:zlib";
11657
+ var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
11658
+ var CRC_TABLE = Uint32Array.from({ length: 256 }, (_, n) => {
11659
+ let c = n;
11660
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
11661
+ return c >>> 0;
11662
+ });
11663
+ function crc(bytes) {
11664
+ let c = 4294967295;
11665
+ for (const byte of bytes) c = CRC_TABLE[(c ^ byte) & 255] ^ c >>> 8;
11666
+ return (c ^ 4294967295) >>> 0;
11667
+ }
11668
+ function chunk(kind, data) {
11669
+ const out = new Uint8Array(12 + data.length);
11670
+ const view = new DataView(out.buffer);
11671
+ view.setUint32(0, data.length);
11672
+ out.set(new TextEncoder().encode(kind), 4);
11673
+ out.set(data, 8);
11674
+ view.setUint32(8 + data.length, crc(out.subarray(4, 8 + data.length)));
11675
+ return out;
11676
+ }
11677
+ function pngBytes(image) {
11678
+ const { rgba, width, height } = image;
11679
+ const header = new Uint8Array(13);
11680
+ const view = new DataView(header.buffer);
11681
+ view.setUint32(0, width);
11682
+ view.setUint32(4, height);
11683
+ header.set([8, 6, 0, 0, 0], 8);
11684
+ const row3 = width * 4;
11685
+ const raw = new Uint8Array((row3 + 1) * height);
11686
+ for (let y = 0; y < height; y++) raw.set(rgba.subarray(y * row3, (y + 1) * row3), y * (row3 + 1) + 1);
11687
+ const parts = [Uint8Array.from(SIGNATURE), chunk("IHDR", header), chunk("IDAT", deflateSync(raw)), chunk("IEND", new Uint8Array(0))];
11688
+ const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
11689
+ parts.reduce((offset, part) => (out.set(part, offset), offset + part.length), 0);
11690
+ return out;
11691
+ }
11692
+
11693
+ // studio/src/render/model-render.ts
11694
+ function modelGlb(design, request = {}) {
11695
+ const look = request.look ?? {};
11696
+ if (look.background !== void 0) throw new Error("a model has no background: that is for pictures");
11697
+ resolveLook(look);
11698
+ const { model, scene } = lookScene(design, look);
11699
+ if (scene.faces.length === 0) throw new Error("Nothing to write: the design has no board outline and no parts");
11700
+ const glb = sceneGlb(scene, { name: designName(design.file), names: model.parts.map((part) => part.name), png: pngBytes });
11701
+ return { glb, what: model.board ? shapesWords(model, look) : `${partsWords(model)} (no board outline)`, parts: model.parts.length };
11702
+ }
11703
+
10028
11704
  // studio/src/render/node-render.ts
10029
11705
  async function renderDesign(design, request) {
10030
11706
  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 +11737,6 @@ async function renderDesign(design, request) {
10061
11737
  return { png: new Uint8Array(png), width: size.width, height: size.height, what, ...frame.page !== void 0 ? { page: frame.page } : {} };
10062
11738
  }
10063
11739
  export {
11740
+ modelGlb,
10064
11741
  renderDesign
10065
11742
  };