circuit-to-svg 0.0.90 → 0.0.91
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 +97 -27
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1281,6 +1281,8 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
} else if (item.type === "schematic_text") {
|
|
1283
1283
|
updateBounds(item.position, { width: 0.1, height: 0.1 }, 0);
|
|
1284
|
+
} else if (item.type === "schematic_voltage_probe") {
|
|
1285
|
+
updateBounds(item.position, { width: 0.2, height: 0.4 }, 0);
|
|
1284
1286
|
}
|
|
1285
1287
|
}
|
|
1286
1288
|
minX -= padding;
|
|
@@ -1927,15 +1929,77 @@ function createSvgObjectsFromSchematicComponent(params) {
|
|
|
1927
1929
|
];
|
|
1928
1930
|
}
|
|
1929
1931
|
|
|
1930
|
-
// lib/sch/svg-object-fns/create-svg-objects-from-sch-
|
|
1932
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
|
|
1931
1933
|
import { applyToPoint as applyToPoint23 } from "transformation-matrix";
|
|
1934
|
+
function createSvgObjectsFromSchVoltageProbe(probe, transform) {
|
|
1935
|
+
const [screenX, screenY] = applyToPoint23(transform, [
|
|
1936
|
+
probe.position.x,
|
|
1937
|
+
probe.position.y
|
|
1938
|
+
]);
|
|
1939
|
+
const arrowLength = Math.abs(transform.a) * 0.6;
|
|
1940
|
+
const arrowWidth = Math.abs(transform.a) * 0.28;
|
|
1941
|
+
const baseX = screenX + arrowLength * Math.cos(-50 * Math.PI / 180);
|
|
1942
|
+
const baseY = screenY + arrowLength * Math.sin(-50 * Math.PI / 180);
|
|
1943
|
+
const tipX = screenX;
|
|
1944
|
+
const tipY = screenY;
|
|
1945
|
+
const arrowPath = [
|
|
1946
|
+
`M ${baseX},${baseY}`,
|
|
1947
|
+
`L ${tipX},${tipY}`,
|
|
1948
|
+
`M ${tipX},${tipY}`,
|
|
1949
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 150) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 150) * Math.PI / 180)}`,
|
|
1950
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 210) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 210) * Math.PI / 180)}`,
|
|
1951
|
+
"Z"
|
|
1952
|
+
].join(" ");
|
|
1953
|
+
return [
|
|
1954
|
+
{
|
|
1955
|
+
name: "path",
|
|
1956
|
+
type: "element",
|
|
1957
|
+
attributes: {
|
|
1958
|
+
d: arrowPath,
|
|
1959
|
+
stroke: colorMap.schematic.reference,
|
|
1960
|
+
fill: colorMap.schematic.reference,
|
|
1961
|
+
"stroke-width": `${getSchStrokeSize(transform)}px`
|
|
1962
|
+
},
|
|
1963
|
+
value: "",
|
|
1964
|
+
children: []
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
type: "element",
|
|
1968
|
+
name: "text",
|
|
1969
|
+
value: "",
|
|
1970
|
+
attributes: {
|
|
1971
|
+
x: (baseX + 8 - (baseX - baseX)).toString(),
|
|
1972
|
+
y: (baseY - 10 + (baseY - baseY)).toString(),
|
|
1973
|
+
fill: colorMap.schematic.reference,
|
|
1974
|
+
"text-anchor": "middle",
|
|
1975
|
+
"dominant-baseline": "middle",
|
|
1976
|
+
"font-family": "sans-serif",
|
|
1977
|
+
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|
|
1978
|
+
"font-weight": "bold",
|
|
1979
|
+
"data-schematic-voltage-probe-id": probe.schematic_voltage_probe_id
|
|
1980
|
+
},
|
|
1981
|
+
children: [
|
|
1982
|
+
{
|
|
1983
|
+
type: "text",
|
|
1984
|
+
value: probe.voltage ? `${probe.voltage}V` : "",
|
|
1985
|
+
name: "",
|
|
1986
|
+
attributes: {},
|
|
1987
|
+
children: []
|
|
1988
|
+
}
|
|
1989
|
+
]
|
|
1990
|
+
}
|
|
1991
|
+
];
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
|
|
1995
|
+
import { applyToPoint as applyToPoint24 } from "transformation-matrix";
|
|
1932
1996
|
function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
1933
1997
|
if (debugObject.shape === "rect") {
|
|
1934
|
-
let [screenLeft, screenTop] =
|
|
1998
|
+
let [screenLeft, screenTop] = applyToPoint24(transform, [
|
|
1935
1999
|
debugObject.center.x - debugObject.size.width / 2,
|
|
1936
2000
|
debugObject.center.y - debugObject.size.height / 2
|
|
1937
2001
|
]);
|
|
1938
|
-
let [screenRight, screenBottom] =
|
|
2002
|
+
let [screenRight, screenBottom] = applyToPoint24(transform, [
|
|
1939
2003
|
debugObject.center.x + debugObject.size.width / 2,
|
|
1940
2004
|
debugObject.center.y + debugObject.size.height / 2
|
|
1941
2005
|
]);
|
|
@@ -1945,7 +2009,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1945
2009
|
];
|
|
1946
2010
|
const width = Math.abs(screenRight - screenLeft);
|
|
1947
2011
|
const height = Math.abs(screenBottom - screenTop);
|
|
1948
|
-
const [screenCenterX, screenCenterY] =
|
|
2012
|
+
const [screenCenterX, screenCenterY] = applyToPoint24(transform, [
|
|
1949
2013
|
debugObject.center.x,
|
|
1950
2014
|
debugObject.center.y
|
|
1951
2015
|
]);
|
|
@@ -1991,11 +2055,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1991
2055
|
];
|
|
1992
2056
|
}
|
|
1993
2057
|
if (debugObject.shape === "line") {
|
|
1994
|
-
const [screenStartX, screenStartY] =
|
|
2058
|
+
const [screenStartX, screenStartY] = applyToPoint24(transform, [
|
|
1995
2059
|
debugObject.start.x,
|
|
1996
2060
|
debugObject.start.y
|
|
1997
2061
|
]);
|
|
1998
|
-
const [screenEndX, screenEndY] =
|
|
2062
|
+
const [screenEndX, screenEndY] = applyToPoint24(transform, [
|
|
1999
2063
|
debugObject.end.x,
|
|
2000
2064
|
debugObject.end.y
|
|
2001
2065
|
]);
|
|
@@ -2045,7 +2109,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
2045
2109
|
}
|
|
2046
2110
|
|
|
2047
2111
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
|
|
2048
|
-
import { applyToPoint as
|
|
2112
|
+
import { applyToPoint as applyToPoint25 } from "transformation-matrix";
|
|
2049
2113
|
function createSchematicTrace(trace, transform) {
|
|
2050
2114
|
const edges = trace.edges;
|
|
2051
2115
|
if (edges.length === 0) return [];
|
|
@@ -2054,11 +2118,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2054
2118
|
for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
|
2055
2119
|
const edge = edges[edgeIndex];
|
|
2056
2120
|
if (edge.is_crossing) continue;
|
|
2057
|
-
const [screenFromX, screenFromY] =
|
|
2121
|
+
const [screenFromX, screenFromY] = applyToPoint25(transform, [
|
|
2058
2122
|
edge.from.x,
|
|
2059
2123
|
edge.from.y
|
|
2060
2124
|
]);
|
|
2061
|
-
const [screenToX, screenToY] =
|
|
2125
|
+
const [screenToX, screenToY] = applyToPoint25(transform, [
|
|
2062
2126
|
edge.to.x,
|
|
2063
2127
|
edge.to.y
|
|
2064
2128
|
]);
|
|
@@ -2070,11 +2134,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2070
2134
|
}
|
|
2071
2135
|
for (const edge of edges) {
|
|
2072
2136
|
if (!edge.is_crossing) continue;
|
|
2073
|
-
const [screenFromX, screenFromY] =
|
|
2137
|
+
const [screenFromX, screenFromY] = applyToPoint25(transform, [
|
|
2074
2138
|
edge.from.x,
|
|
2075
2139
|
edge.from.y
|
|
2076
2140
|
]);
|
|
2077
|
-
const [screenToX, screenToY] =
|
|
2141
|
+
const [screenToX, screenToY] = applyToPoint25(transform, [
|
|
2078
2142
|
edge.to.x,
|
|
2079
2143
|
edge.to.y
|
|
2080
2144
|
]);
|
|
@@ -2150,7 +2214,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
2150
2214
|
}
|
|
2151
2215
|
if (trace.junctions) {
|
|
2152
2216
|
for (const junction of trace.junctions) {
|
|
2153
|
-
const [screenX, screenY] =
|
|
2217
|
+
const [screenX, screenY] = applyToPoint25(transform, [
|
|
2154
2218
|
junction.x,
|
|
2155
2219
|
junction.y
|
|
2156
2220
|
]);
|
|
@@ -2183,7 +2247,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
2183
2247
|
|
|
2184
2248
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
2185
2249
|
import {
|
|
2186
|
-
applyToPoint as
|
|
2250
|
+
applyToPoint as applyToPoint26,
|
|
2187
2251
|
compose as compose6,
|
|
2188
2252
|
rotate as rotate3,
|
|
2189
2253
|
scale as scale3,
|
|
@@ -2979,14 +3043,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
2979
3043
|
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
2980
3044
|
const fontSizeMm = getSchMmFontSize("net_label");
|
|
2981
3045
|
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
2982
|
-
const screenCenter =
|
|
3046
|
+
const screenCenter = applyToPoint26(realToScreenTransform, schNetLabel.center);
|
|
2983
3047
|
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
2984
3048
|
schNetLabel.anchor_side
|
|
2985
3049
|
);
|
|
2986
3050
|
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
2987
3051
|
screenTextGrowthVec.y *= -1;
|
|
2988
3052
|
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
2989
|
-
const screenAnchorPosition = schNetLabel.anchor_position ?
|
|
3053
|
+
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint26(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
2990
3054
|
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
2991
3055
|
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
2992
3056
|
};
|
|
@@ -3027,7 +3091,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3027
3091
|
y: -0.6
|
|
3028
3092
|
}
|
|
3029
3093
|
].map(
|
|
3030
|
-
(fontRelativePoint) =>
|
|
3094
|
+
(fontRelativePoint) => applyToPoint26(
|
|
3031
3095
|
compose6(
|
|
3032
3096
|
realToScreenTransform,
|
|
3033
3097
|
translate6(realAnchorPosition.x, realAnchorPosition.y),
|
|
@@ -3104,9 +3168,9 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3104
3168
|
};
|
|
3105
3169
|
|
|
3106
3170
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
|
|
3107
|
-
import { applyToPoint as
|
|
3171
|
+
import { applyToPoint as applyToPoint27 } from "transformation-matrix";
|
|
3108
3172
|
var createSvgSchText = (elm, transform) => {
|
|
3109
|
-
const center =
|
|
3173
|
+
const center = applyToPoint27(transform, elm.position);
|
|
3110
3174
|
const textAnchorMap = {
|
|
3111
3175
|
center: "middle",
|
|
3112
3176
|
left: "start",
|
|
@@ -3149,7 +3213,7 @@ var createSvgSchText = (elm, transform) => {
|
|
|
3149
3213
|
|
|
3150
3214
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-symbol.ts
|
|
3151
3215
|
import {
|
|
3152
|
-
applyToPoint as
|
|
3216
|
+
applyToPoint as applyToPoint28,
|
|
3153
3217
|
compose as compose7,
|
|
3154
3218
|
rotate as rotate4,
|
|
3155
3219
|
scale as scale4,
|
|
@@ -3248,7 +3312,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3248
3312
|
x: symbolBounds.minX,
|
|
3249
3313
|
y: (symbolBounds.minY + symbolBounds.maxY) / 2
|
|
3250
3314
|
};
|
|
3251
|
-
const rotatedSymbolEnd =
|
|
3315
|
+
const rotatedSymbolEnd = applyToPoint28(rotationMatrix, symbolEndPoint);
|
|
3252
3316
|
const symbolToRealTransform = compose7(
|
|
3253
3317
|
translate7(
|
|
3254
3318
|
realAnchorPosition.x - rotatedSymbolEnd.x,
|
|
@@ -3258,11 +3322,11 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3258
3322
|
scale4(1)
|
|
3259
3323
|
// Use full symbol size
|
|
3260
3324
|
);
|
|
3261
|
-
const [screenMinX, screenMinY] =
|
|
3325
|
+
const [screenMinX, screenMinY] = applyToPoint28(
|
|
3262
3326
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3263
3327
|
[bounds.minX, bounds.minY]
|
|
3264
3328
|
);
|
|
3265
|
-
const [screenMaxX, screenMaxY] =
|
|
3329
|
+
const [screenMaxX, screenMaxY] = applyToPoint28(
|
|
3266
3330
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3267
3331
|
[bounds.maxX, bounds.maxY]
|
|
3268
3332
|
);
|
|
@@ -3286,7 +3350,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3286
3350
|
});
|
|
3287
3351
|
for (const path of symbolPaths) {
|
|
3288
3352
|
const symbolPath = path.points.map((p, i) => {
|
|
3289
|
-
const [x, y] =
|
|
3353
|
+
const [x, y] = applyToPoint28(
|
|
3290
3354
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3291
3355
|
[p.x, p.y]
|
|
3292
3356
|
);
|
|
@@ -3306,7 +3370,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3306
3370
|
});
|
|
3307
3371
|
}
|
|
3308
3372
|
for (const text of symbolTexts) {
|
|
3309
|
-
const screenTextPos =
|
|
3373
|
+
const screenTextPos = applyToPoint28(
|
|
3310
3374
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3311
3375
|
text
|
|
3312
3376
|
);
|
|
@@ -3357,7 +3421,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3357
3421
|
});
|
|
3358
3422
|
}
|
|
3359
3423
|
for (const box of symbolBoxes) {
|
|
3360
|
-
const screenBoxPos =
|
|
3424
|
+
const screenBoxPos = applyToPoint28(
|
|
3361
3425
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3362
3426
|
box
|
|
3363
3427
|
);
|
|
@@ -3380,7 +3444,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3380
3444
|
});
|
|
3381
3445
|
}
|
|
3382
3446
|
for (const circle of symbolCircles) {
|
|
3383
|
-
const screenCirclePos =
|
|
3447
|
+
const screenCirclePos = applyToPoint28(
|
|
3384
3448
|
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3385
3449
|
circle
|
|
3386
3450
|
);
|
|
@@ -3466,6 +3530,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3466
3530
|
const schTraceSvgs = [];
|
|
3467
3531
|
const schNetLabel = [];
|
|
3468
3532
|
const schText = [];
|
|
3533
|
+
const voltageProbeSvgs = [];
|
|
3469
3534
|
for (const elm of circuitJson) {
|
|
3470
3535
|
if (elm.type === "schematic_debug_object") {
|
|
3471
3536
|
schDebugObjectSvgs.push(
|
|
@@ -3485,6 +3550,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3485
3550
|
elm.symbol_name ? schNetLabel.push(...createSvgObjectsForSchNetSymbol(elm, transform)) : schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
|
|
3486
3551
|
} else if (elm.type === "schematic_text") {
|
|
3487
3552
|
schText.push(createSvgSchText(elm, transform));
|
|
3553
|
+
} else if (elm.type === "schematic_voltage_probe") {
|
|
3554
|
+
voltageProbeSvgs.push(
|
|
3555
|
+
...createSvgObjectsFromSchVoltageProbe(elm, transform)
|
|
3556
|
+
);
|
|
3488
3557
|
}
|
|
3489
3558
|
}
|
|
3490
3559
|
svgChildren.push(
|
|
@@ -3492,7 +3561,8 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3492
3561
|
...schComponentSvgs,
|
|
3493
3562
|
...schTraceSvgs,
|
|
3494
3563
|
...schNetLabel,
|
|
3495
|
-
...schText
|
|
3564
|
+
...schText,
|
|
3565
|
+
...voltageProbeSvgs
|
|
3496
3566
|
);
|
|
3497
3567
|
if (options?.labeledPoints) {
|
|
3498
3568
|
svgChildren.push(
|