@tscircuit/core 0.0.1298 → 0.0.1299
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 +112 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10230,6 +10230,117 @@ var getAllDimensionsForSchematicBox = (params) => {
|
|
|
10230
10230
|
sideLengths.right + DEFAULT_SCHEMATIC_BOX_PADDING_MM
|
|
10231
10231
|
);
|
|
10232
10232
|
}
|
|
10233
|
+
if (params.pinLabels) {
|
|
10234
|
+
const CHAR_WIDTH = 0.13;
|
|
10235
|
+
const LABEL_EDGE_OFFSET = 0.1;
|
|
10236
|
+
const HALF_TEXT = 0.075;
|
|
10237
|
+
const getLabelLen = (pinNumber) => {
|
|
10238
|
+
const label = params.pinLabels[`pin${pinNumber}`] ?? params.pinLabels[`${pinNumber}`];
|
|
10239
|
+
return label ? label.length * CHAR_WIDTH : 0;
|
|
10240
|
+
};
|
|
10241
|
+
const leftLabels = orderedTruePorts.filter((p) => p.side === "left").map((p) => ({
|
|
10242
|
+
y: sideLengths.left / 2 - p.distanceFromOrthogonalEdge,
|
|
10243
|
+
len: getLabelLen(p.pinNumber)
|
|
10244
|
+
})).filter((p) => p.len > 0);
|
|
10245
|
+
const rightLabels = orderedTruePorts.filter((p) => p.side === "right").map((p) => ({
|
|
10246
|
+
y: -sideLengths.right / 2 + p.distanceFromOrthogonalEdge,
|
|
10247
|
+
len: getLabelLen(p.pinNumber)
|
|
10248
|
+
})).filter((p) => p.len > 0);
|
|
10249
|
+
const topLabels = orderedTruePorts.filter((p) => p.side === "top").map((p) => ({
|
|
10250
|
+
x: sideLengths.top / 2 - p.distanceFromOrthogonalEdge,
|
|
10251
|
+
len: getLabelLen(p.pinNumber)
|
|
10252
|
+
})).filter((p) => p.len > 0);
|
|
10253
|
+
const bottomLabels = orderedTruePorts.filter((p) => p.side === "bottom").map((p) => ({
|
|
10254
|
+
x: -sideLengths.bottom / 2 + p.distanceFromOrthogonalEdge,
|
|
10255
|
+
len: getLabelLen(p.pinNumber)
|
|
10256
|
+
})).filter((p) => p.len > 0);
|
|
10257
|
+
const rectsOverlap = (a, b) => Math.min(a.maxX, b.maxX) > Math.max(a.minX, b.minX) && Math.min(a.maxY, b.maxY) > Math.max(a.minY, b.minY);
|
|
10258
|
+
const getLeftRect = (label, width) => ({
|
|
10259
|
+
minX: -width / 2 + LABEL_EDGE_OFFSET,
|
|
10260
|
+
maxX: -width / 2 + LABEL_EDGE_OFFSET + label.len,
|
|
10261
|
+
minY: label.y - HALF_TEXT,
|
|
10262
|
+
maxY: label.y + HALF_TEXT
|
|
10263
|
+
});
|
|
10264
|
+
const getRightRect = (label, width) => ({
|
|
10265
|
+
minX: width / 2 - LABEL_EDGE_OFFSET - label.len,
|
|
10266
|
+
maxX: width / 2 - LABEL_EDGE_OFFSET,
|
|
10267
|
+
minY: label.y - HALF_TEXT,
|
|
10268
|
+
maxY: label.y + HALF_TEXT
|
|
10269
|
+
});
|
|
10270
|
+
const getTopRect = (label, height) => ({
|
|
10271
|
+
minX: label.x - HALF_TEXT,
|
|
10272
|
+
maxX: label.x + HALF_TEXT,
|
|
10273
|
+
minY: height / 2 - LABEL_EDGE_OFFSET - label.len,
|
|
10274
|
+
maxY: height / 2 - LABEL_EDGE_OFFSET
|
|
10275
|
+
});
|
|
10276
|
+
const getBottomRect = (label, height) => ({
|
|
10277
|
+
minX: label.x - HALF_TEXT,
|
|
10278
|
+
maxX: label.x + HALF_TEXT,
|
|
10279
|
+
minY: -height / 2 + LABEL_EDGE_OFFSET,
|
|
10280
|
+
maxY: -height / 2 + LABEL_EDGE_OFFSET + label.len
|
|
10281
|
+
});
|
|
10282
|
+
if (!params.schHeight) {
|
|
10283
|
+
let hasTopBottomLabelCollision = false;
|
|
10284
|
+
for (const topLabel of topLabels) {
|
|
10285
|
+
for (const bottomLabel of bottomLabels) {
|
|
10286
|
+
if (rectsOverlap(
|
|
10287
|
+
getTopRect(topLabel, schHeight),
|
|
10288
|
+
getBottomRect(bottomLabel, schHeight)
|
|
10289
|
+
)) {
|
|
10290
|
+
hasTopBottomLabelCollision = true;
|
|
10291
|
+
schHeight = Math.max(
|
|
10292
|
+
schHeight,
|
|
10293
|
+
topLabel.len + bottomLabel.len + 2 * LABEL_EDGE_OFFSET
|
|
10294
|
+
);
|
|
10295
|
+
}
|
|
10296
|
+
}
|
|
10297
|
+
}
|
|
10298
|
+
if (hasTopBottomLabelCollision) {
|
|
10299
|
+
for (const topLabel of topLabels) {
|
|
10300
|
+
const topRect = getTopRect(topLabel, schHeight);
|
|
10301
|
+
for (const leftLabel of leftLabels) {
|
|
10302
|
+
const leftRect = getLeftRect(leftLabel, resolvedSchWidth);
|
|
10303
|
+
if (rectsOverlap(topRect, leftRect)) {
|
|
10304
|
+
schHeight = Math.max(
|
|
10305
|
+
schHeight,
|
|
10306
|
+
2 * (leftRect.maxY + LABEL_EDGE_OFFSET + topLabel.len)
|
|
10307
|
+
);
|
|
10308
|
+
}
|
|
10309
|
+
}
|
|
10310
|
+
for (const rightLabel of rightLabels) {
|
|
10311
|
+
const rightRect = getRightRect(rightLabel, resolvedSchWidth);
|
|
10312
|
+
if (rectsOverlap(topRect, rightRect)) {
|
|
10313
|
+
schHeight = Math.max(
|
|
10314
|
+
schHeight,
|
|
10315
|
+
2 * (rightRect.maxY + LABEL_EDGE_OFFSET + topLabel.len)
|
|
10316
|
+
);
|
|
10317
|
+
}
|
|
10318
|
+
}
|
|
10319
|
+
}
|
|
10320
|
+
for (const bottomLabel of bottomLabels) {
|
|
10321
|
+
const bottomRect = getBottomRect(bottomLabel, schHeight);
|
|
10322
|
+
for (const leftLabel of leftLabels) {
|
|
10323
|
+
const leftRect = getLeftRect(leftLabel, resolvedSchWidth);
|
|
10324
|
+
if (rectsOverlap(bottomRect, leftRect)) {
|
|
10325
|
+
schHeight = Math.max(
|
|
10326
|
+
schHeight,
|
|
10327
|
+
2 * (LABEL_EDGE_OFFSET + bottomLabel.len - leftRect.minY)
|
|
10328
|
+
);
|
|
10329
|
+
}
|
|
10330
|
+
}
|
|
10331
|
+
for (const rightLabel of rightLabels) {
|
|
10332
|
+
const rightRect = getRightRect(rightLabel, resolvedSchWidth);
|
|
10333
|
+
if (rectsOverlap(bottomRect, rightRect)) {
|
|
10334
|
+
schHeight = Math.max(
|
|
10335
|
+
schHeight,
|
|
10336
|
+
2 * (LABEL_EDGE_OFFSET + bottomLabel.len - rightRect.minY)
|
|
10337
|
+
);
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
10340
|
+
}
|
|
10341
|
+
}
|
|
10342
|
+
}
|
|
10343
|
+
}
|
|
10233
10344
|
const trueEdgePositions = {
|
|
10234
10345
|
// Top left corner
|
|
10235
10346
|
left: {
|
|
@@ -22501,7 +22612,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
22501
22612
|
var package_default = {
|
|
22502
22613
|
name: "@tscircuit/core",
|
|
22503
22614
|
type: "module",
|
|
22504
|
-
version: "0.0.
|
|
22615
|
+
version: "0.0.1298",
|
|
22505
22616
|
types: "dist/index.d.ts",
|
|
22506
22617
|
main: "dist/index.js",
|
|
22507
22618
|
module: "dist/index.js",
|