schematic-symbols 0.0.112 → 0.0.113
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 +88 -13
- package/dist/index.js.map +1 -1
- package/drawing/defineSymbol.ts +13 -2
- package/drawing/getSvg.ts +29 -1
- package/drawing/modify-symbol/modify-symbol.ts +11 -5
- package/drawing/rotateSymbol.ts +5 -8
- package/drawing/utils/getBoundsOfPrimitives.ts +51 -0
- package/package.json +1 -1
- package/symbols/boxresistor_down.ts +0 -1
- package/symbols/boxresistor_left.ts +0 -1
- package/symbols/boxresistor_right.ts +0 -1
- package/symbols/boxresistor_up.ts +0 -1
package/dist/index.js
CHANGED
@@ -1,6 +1,56 @@
|
|
1
|
+
// drawing/utils/getBoundsOfPrimitives.ts
|
2
|
+
function getBoundsOfPrimitives(primitives) {
|
3
|
+
if (primitives.length === 0) {
|
4
|
+
return { minX: 0, maxX: 0, minY: 0, maxY: 0 };
|
5
|
+
}
|
6
|
+
let minX = Infinity;
|
7
|
+
let maxX = -Infinity;
|
8
|
+
let minY = Infinity;
|
9
|
+
let maxY = -Infinity;
|
10
|
+
const updateBounds = (point) => {
|
11
|
+
minX = Math.min(minX, point.x);
|
12
|
+
maxX = Math.max(maxX, point.x);
|
13
|
+
minY = Math.min(minY, point.y);
|
14
|
+
maxY = Math.max(maxY, point.y);
|
15
|
+
};
|
16
|
+
primitives.forEach((primitive) => {
|
17
|
+
switch (primitive.type) {
|
18
|
+
case "path":
|
19
|
+
primitive.points.forEach(updateBounds);
|
20
|
+
break;
|
21
|
+
case "text":
|
22
|
+
updateBounds({ x: primitive.x, y: primitive.y });
|
23
|
+
break;
|
24
|
+
case "circle": {
|
25
|
+
const { x, y, radius } = primitive;
|
26
|
+
updateBounds({ x: x - radius, y: y - radius });
|
27
|
+
updateBounds({ x: x + radius, y: y + radius });
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
case "box": {
|
31
|
+
const { x, y, width, height } = primitive;
|
32
|
+
const halfWidth = width / 2;
|
33
|
+
const halfHeight = height / 2;
|
34
|
+
updateBounds({ x: x - halfWidth, y: y - halfHeight });
|
35
|
+
updateBounds({ x: x + halfWidth, y: y + halfHeight });
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
return { minX, maxX, minY, maxY };
|
41
|
+
}
|
42
|
+
|
1
43
|
// drawing/defineSymbol.ts
|
2
44
|
function defineSymbol(symbol) {
|
3
|
-
|
45
|
+
let size = symbol.size;
|
46
|
+
if (!size) {
|
47
|
+
const bounds54 = getBoundsOfPrimitives(symbol.primitives);
|
48
|
+
size = {
|
49
|
+
width: bounds54.maxX - bounds54.minX,
|
50
|
+
height: bounds54.maxY - bounds54.minY
|
51
|
+
};
|
52
|
+
}
|
53
|
+
return { ...symbol, size };
|
4
54
|
}
|
5
55
|
|
6
56
|
// assets/generated/ac_voltmeter.json
|
@@ -444,13 +494,14 @@ var rotateRightFacingSymbol = (symbol, opts) => {
|
|
444
494
|
...applyToPoint(transform2, port)
|
445
495
|
})
|
446
496
|
);
|
497
|
+
const bounds54 = getBoundsOfPrimitives(rotatedPrimitives);
|
447
498
|
return {
|
448
499
|
primitives: rotatedPrimitives,
|
449
500
|
center,
|
450
501
|
ports: rotatedPorts,
|
451
502
|
size: {
|
452
|
-
width:
|
453
|
-
height:
|
503
|
+
width: bounds54.maxX - bounds54.minX,
|
504
|
+
height: bounds54.maxY - bounds54.minY
|
454
505
|
},
|
455
506
|
...overrides
|
456
507
|
};
|
@@ -884,6 +935,7 @@ var SymbolModifier = class {
|
|
884
935
|
symbol;
|
885
936
|
constructor(symbol) {
|
886
937
|
this.symbol = JSON.parse(JSON.stringify(symbol));
|
938
|
+
this.symbol.size = this.computeSize();
|
887
939
|
}
|
888
940
|
changeTextAnchor(text, newAnchor) {
|
889
941
|
this.symbol = {
|
@@ -915,8 +967,15 @@ var SymbolModifier = class {
|
|
915
967
|
});
|
916
968
|
return this;
|
917
969
|
}
|
970
|
+
computeSize() {
|
971
|
+
const bounds54 = getBoundsOfPrimitives(this.symbol.primitives);
|
972
|
+
return {
|
973
|
+
width: bounds54.maxX - bounds54.minX,
|
974
|
+
height: bounds54.maxY - bounds54.minY
|
975
|
+
};
|
976
|
+
}
|
918
977
|
build() {
|
919
|
-
return this.symbol;
|
978
|
+
return { ...this.symbol, size: this.computeSize() };
|
920
979
|
}
|
921
980
|
};
|
922
981
|
var modifySymbol = (symbol) => {
|
@@ -934,10 +993,6 @@ var modifySymbol = (symbol) => {
|
|
934
993
|
center: symbol.center ?? {
|
935
994
|
x: symbol.bounds.centerX,
|
936
995
|
y: symbol.bounds.centerY
|
937
|
-
},
|
938
|
-
size: symbol.size ?? {
|
939
|
-
width: symbol.bounds.width,
|
940
|
-
height: symbol.bounds.height
|
941
996
|
}
|
942
997
|
});
|
943
998
|
};
|
@@ -967,7 +1022,6 @@ var boxresistor_down_default = modifySymbol({
|
|
967
1022
|
{ ...refblocks4.right1, labels: ["2"] }
|
968
1023
|
// TODO add more "standard" labels
|
969
1024
|
],
|
970
|
-
size: { width: bounds4.width, height: bounds4.height },
|
971
1025
|
center: { x: bounds4.centerX, y: bounds4.centerY }
|
972
1026
|
}).changeTextAnchor("{VAL}", "middle_bottom").rotateRightFacingSymbol("down").labelPort("left1", ["1"]).labelPort("right1", ["2"]).changeTextAnchor("{REF}", "middle_left").build();
|
973
1027
|
|
@@ -996,7 +1050,6 @@ var boxresistor_left_default = modifySymbol({
|
|
996
1050
|
{ ...refblocks5.right1, labels: ["2"] }
|
997
1051
|
// TODO add more "standard" labels
|
998
1052
|
],
|
999
|
-
size: { width: bounds5.width, height: bounds5.height },
|
1000
1053
|
center: { x: bounds5.centerX, y: bounds5.centerY }
|
1001
1054
|
}).changeTextAnchor("{VAL}", "middle_top").rotateRightFacingSymbol("right").labelPort("left1", ["1"]).labelPort("right1", ["2"]).changeTextAnchor("{REF}", "middle_bottom").build();
|
1002
1055
|
|
@@ -1025,7 +1078,6 @@ var boxresistor_right_default = modifySymbol({
|
|
1025
1078
|
{ ...refblocks6.right1, labels: ["2"] }
|
1026
1079
|
// TODO add more "standard" labels
|
1027
1080
|
],
|
1028
|
-
size: { width: bounds6.width, height: bounds6.height },
|
1029
1081
|
center: { x: bounds6.centerX, y: bounds6.centerY }
|
1030
1082
|
}).changeTextAnchor("{VAL}", "middle_top").rotateRightFacingSymbol("right").labelPort("left1", ["1"]).labelPort("right1", ["2"]).changeTextAnchor("{REF}", "middle_bottom").build();
|
1031
1083
|
|
@@ -1054,7 +1106,6 @@ var boxresistor_up_default = modifySymbol({
|
|
1054
1106
|
{ ...refblocks7.right1, labels: ["2"] }
|
1055
1107
|
// TODO add more "standard" labels
|
1056
1108
|
],
|
1057
|
-
size: { width: bounds7.width, height: bounds7.height },
|
1058
1109
|
center: { x: bounds7.centerX, y: bounds7.centerY }
|
1059
1110
|
}).changeTextAnchor("{VAL}", "middle_bottom").rotateRightFacingSymbol("down").labelPort("left1", ["1"]).labelPort("right1", ["2"]).changeTextAnchor("{REF}", "middle_left").build();
|
1060
1111
|
|
@@ -16314,7 +16365,31 @@ function getInnerSvg(symbol, options = {}) {
|
|
16314
16365
|
});
|
16315
16366
|
const portElements = ports.map((p) => createPortElement(p, { yUpPositive: true })).join("\n ");
|
16316
16367
|
const centerDiamond = createDiamondElement(symbol.center);
|
16317
|
-
|
16368
|
+
const debugElements = [];
|
16369
|
+
if (debug) {
|
16370
|
+
const topLeft = {
|
16371
|
+
x: symbol.center.x - size.width / 2,
|
16372
|
+
y: symbol.center.y - size.height / 2
|
16373
|
+
};
|
16374
|
+
debugElements.push(
|
16375
|
+
`<text x="${topLeft.x}" y="${topLeft.y}" style="font: 0.05px monospace; fill: #833;">${size.width.toFixed(2)} x ${size.height.toFixed(2)}</text>`
|
16376
|
+
);
|
16377
|
+
ports.forEach((port, i) => {
|
16378
|
+
if (port.labels.length > 1) {
|
16379
|
+
const alternateLabels = port.labels.slice(1).join(", ");
|
16380
|
+
debugElements.push(
|
16381
|
+
`<text x="${topLeft.x}" y="${topLeft.y - (i + 1) * 0.05}" dy="-0.15" style="font: 0.05px monospace; fill: #833;">${port.labels[0]} [${alternateLabels}]</text>`
|
16382
|
+
);
|
16383
|
+
}
|
16384
|
+
});
|
16385
|
+
debugElements.push(...debugElements);
|
16386
|
+
}
|
16387
|
+
return [
|
16388
|
+
svgElements.join("\n "),
|
16389
|
+
portElements,
|
16390
|
+
centerDiamond,
|
16391
|
+
...debugElements
|
16392
|
+
].join("\n");
|
16318
16393
|
}
|
16319
16394
|
function getSvg(symbol, options = {}) {
|
16320
16395
|
const { size } = symbol;
|