@tscircuit/footprinter 0.0.207 → 0.0.208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7115,6 +7115,89 @@ function isNotNull(value) {
7115
7115
  return value !== null;
7116
7116
  }
7117
7117
 
7118
+ // src/helpers/apply-origin.ts
7119
+ var applyOrigin = (elements, origin) => {
7120
+ if (!origin) return elements;
7121
+ const pads = elements.filter(
7122
+ (el) => el.type === "pcb_smtpad" || el.type === "pcb_plated_hole" || el.type === "pcb_thtpad"
7123
+ );
7124
+ if (pads.length === 0) return elements;
7125
+ let minX = Infinity;
7126
+ let maxX = -Infinity;
7127
+ let minY = Infinity;
7128
+ let maxY = -Infinity;
7129
+ const updateBounds = (x, y, w = 0, h = 0) => {
7130
+ const left = x - w / 2;
7131
+ const right = x + w / 2;
7132
+ const bottom = y - h / 2;
7133
+ const top = y + h / 2;
7134
+ minX = Math.min(minX, left);
7135
+ maxX = Math.max(maxX, right);
7136
+ minY = Math.min(minY, bottom);
7137
+ maxY = Math.max(maxY, top);
7138
+ };
7139
+ for (const pad2 of pads) {
7140
+ if (pad2.type === "pcb_smtpad") {
7141
+ const w = pad2.shape === "circle" ? pad2.radius * 2 : pad2.width;
7142
+ const h = pad2.shape === "circle" ? pad2.radius * 2 : pad2.height;
7143
+ updateBounds(pad2.x, pad2.y, w, h);
7144
+ } else if (pad2.type === "pcb_plated_hole") {
7145
+ const d = pad2.outer_diameter ?? pad2.hole_diameter;
7146
+ updateBounds(pad2.x, pad2.y, d, d);
7147
+ } else if (pad2.type === "pcb_thtpad") {
7148
+ const d = pad2.diameter;
7149
+ updateBounds(pad2.x, pad2.y, d, d);
7150
+ }
7151
+ }
7152
+ let dx = 0;
7153
+ let dy = 0;
7154
+ switch (origin) {
7155
+ case "center":
7156
+ dx = (minX + maxX) / 2;
7157
+ dy = (minY + maxY) / 2;
7158
+ break;
7159
+ case "bottomleft":
7160
+ dx = minX;
7161
+ dy = minY;
7162
+ break;
7163
+ case "bottomcenter":
7164
+ case "centerbottom":
7165
+ dx = (minX + maxX) / 2;
7166
+ dy = minY;
7167
+ break;
7168
+ case "topcenter":
7169
+ case "centertop":
7170
+ dx = (minX + maxX) / 2;
7171
+ dy = maxY;
7172
+ break;
7173
+ case "leftcenter":
7174
+ case "centerleft":
7175
+ dx = minX;
7176
+ dy = (minY + maxY) / 2;
7177
+ break;
7178
+ case "rightcenter":
7179
+ case "centerright":
7180
+ dx = maxX;
7181
+ dy = (minY + maxY) / 2;
7182
+ break;
7183
+ case "pin1":
7184
+ const pin1 = pads.find((p) => p.port_hints?.[0] === "1") || pads[0];
7185
+ dx = pin1.x;
7186
+ dy = pin1.y;
7187
+ break;
7188
+ }
7189
+ if (dx === 0 && dy === 0) return elements;
7190
+ for (const pad2 of pads) {
7191
+ pad2.x -= dx;
7192
+ pad2.y -= dy;
7193
+ if (pad2.center) {
7194
+ pad2.center.x -= dx;
7195
+ pad2.center.y -= dy;
7196
+ }
7197
+ }
7198
+ return elements;
7199
+ };
7200
+
7118
7201
  // src/footprinter.ts
7119
7202
  var string2 = (def) => {
7120
7203
  let fp2 = footprinter();
@@ -7157,7 +7240,10 @@ var footprinter = () => {
7157
7240
  get: (target, prop) => {
7158
7241
  if (prop === "soup" || prop === "circuitJson") {
7159
7242
  if ("fn" in target && fn_exports[target.fn]) {
7160
- return () => fn_exports[target.fn](target).circuitJson;
7243
+ return () => {
7244
+ const { circuitJson } = fn_exports[target.fn](target);
7245
+ return applyOrigin(circuitJson, target.origin);
7246
+ };
7161
7247
  }
7162
7248
  if (!fn_exports[target.fn]) {
7163
7249
  throw new Error(