@tscircuit/footprinter 0.0.206 → 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 +123 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7063,6 +7063,42 @@ var m2host = (raw_params) => {
|
|
|
7063
7063
|
stroke_width: 0.05,
|
|
7064
7064
|
pcb_silkscreen_path_id: "pin_marker_1"
|
|
7065
7065
|
};
|
|
7066
|
+
let minX = Infinity;
|
|
7067
|
+
let maxX = -Infinity;
|
|
7068
|
+
let minY = Infinity;
|
|
7069
|
+
let maxY = -Infinity;
|
|
7070
|
+
const updateBounds = (x, y, w = 0, h = 0) => {
|
|
7071
|
+
minX = Math.min(minX, x - w / 2);
|
|
7072
|
+
maxX = Math.max(maxX, x + w / 2);
|
|
7073
|
+
minY = Math.min(minY, y - h / 2);
|
|
7074
|
+
maxY = Math.max(maxY, y + h / 2);
|
|
7075
|
+
};
|
|
7076
|
+
for (const pad2 of pads) {
|
|
7077
|
+
updateBounds(pad2.x, pad2.y, pad2.width, pad2.height);
|
|
7078
|
+
}
|
|
7079
|
+
updateBounds(cutout.center.x, cutout.center.y, cutout.width, cutout.height);
|
|
7080
|
+
for (const point of pin1Marker.route) {
|
|
7081
|
+
updateBounds(point.x, point.y);
|
|
7082
|
+
}
|
|
7083
|
+
const centerX = (minX + maxX) / 2;
|
|
7084
|
+
const centerY = (minY + maxY) / 2;
|
|
7085
|
+
const translate = (el) => {
|
|
7086
|
+
if (typeof el.x === "number") el.x -= centerX;
|
|
7087
|
+
if (typeof el.y === "number") el.y -= centerY;
|
|
7088
|
+
if (el.center) {
|
|
7089
|
+
el.center.x -= centerX;
|
|
7090
|
+
el.center.y -= centerY;
|
|
7091
|
+
}
|
|
7092
|
+
if (Array.isArray(el.route)) {
|
|
7093
|
+
el.route = el.route.map((p) => ({
|
|
7094
|
+
x: p.x - centerX,
|
|
7095
|
+
y: p.y - centerY
|
|
7096
|
+
}));
|
|
7097
|
+
}
|
|
7098
|
+
};
|
|
7099
|
+
for (const pad2 of pads) translate(pad2);
|
|
7100
|
+
translate(cutout);
|
|
7101
|
+
translate(pin1Marker);
|
|
7066
7102
|
return {
|
|
7067
7103
|
circuitJson: [
|
|
7068
7104
|
...pads,
|
|
@@ -7079,6 +7115,89 @@ function isNotNull(value) {
|
|
|
7079
7115
|
return value !== null;
|
|
7080
7116
|
}
|
|
7081
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
|
+
|
|
7082
7201
|
// src/footprinter.ts
|
|
7083
7202
|
var string2 = (def) => {
|
|
7084
7203
|
let fp2 = footprinter();
|
|
@@ -7121,7 +7240,10 @@ var footprinter = () => {
|
|
|
7121
7240
|
get: (target, prop) => {
|
|
7122
7241
|
if (prop === "soup" || prop === "circuitJson") {
|
|
7123
7242
|
if ("fn" in target && fn_exports[target.fn]) {
|
|
7124
|
-
return () =>
|
|
7243
|
+
return () => {
|
|
7244
|
+
const { circuitJson } = fn_exports[target.fn](target);
|
|
7245
|
+
return applyOrigin(circuitJson, target.origin);
|
|
7246
|
+
};
|
|
7125
7247
|
}
|
|
7126
7248
|
if (!fn_exports[target.fn]) {
|
|
7127
7249
|
throw new Error(
|