circuit-to-svg 0.0.95 → 0.0.97

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
@@ -1787,17 +1787,6 @@ var ninePointAnchorToTextAnchor = {
1787
1787
  middle_top: "middle",
1788
1788
  middle_bottom: "middle"
1789
1789
  };
1790
- var ninePointAnchorToDominantBaseline = {
1791
- top_left: "auto",
1792
- top_right: "auto",
1793
- bottom_left: "hanging",
1794
- bottom_right: "hanging",
1795
- center: "auto",
1796
- middle_left: "middle",
1797
- middle_right: "middle",
1798
- middle_top: "auto",
1799
- middle_bottom: "hanging"
1800
- };
1801
1790
  var createSvgObjectsFromSchematicComponentWithSymbol = ({
1802
1791
  component: schComponent,
1803
1792
  transform: realToScreenTransform,
@@ -1908,15 +1897,27 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
1908
1897
  } else if (text.text === "{VAL}") {
1909
1898
  textValue = schComponent.symbol_display_value ?? "";
1910
1899
  }
1900
+ const symbolHeight = Math.abs(bounds.maxY - bounds.minY);
1901
+ const offsetFactor = 0.1;
1902
+ const baseOffset = symbolHeight * offsetFactor;
1903
+ const transformScale = Math.abs(transformFromSymbolToReal.a);
1904
+ let verticalOffset = 0;
1905
+ if (text.anchor.includes("bottom")) {
1906
+ verticalOffset = baseOffset * transformScale;
1907
+ } else if (text.anchor.includes("top")) {
1908
+ verticalOffset = -baseOffset * transformScale;
1909
+ }
1910
+ const dominantBaseline = text.anchor.includes("bottom") ? "auto" : text.anchor.includes("top") ? "hanging" : "middle";
1911
1911
  svgObjects.push({
1912
1912
  name: "text",
1913
1913
  type: "element",
1914
1914
  attributes: {
1915
1915
  x: screenTextPos.x.toString(),
1916
- y: screenTextPos.y.toString(),
1917
- "dominant-baseline": ninePointAnchorToDominantBaseline[text.anchor],
1918
- "text-anchor": ninePointAnchorToTextAnchor[text.anchor],
1916
+ y: (screenTextPos.y + verticalOffset).toString(),
1917
+ fill: colorMap.schematic.label_local,
1919
1918
  "font-family": "sans-serif",
1919
+ "text-anchor": ninePointAnchorToTextAnchor[text.anchor],
1920
+ "dominant-baseline": dominantBaseline,
1920
1921
  "font-size": `${getSchScreenFontSize(realToScreenTransform, "reference_designator")}px`
1921
1922
  },
1922
1923
  value: "",
@@ -1981,7 +1982,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
1981
1982
  import { su as su5 } from "@tscircuit/soup-util";
1982
1983
  import "schematic-symbols";
1983
1984
  import "svgson";
1984
- import { applyToPoint as applyToPoint25 } from "transformation-matrix";
1985
+ import { applyToPoint as applyToPoint26 } from "transformation-matrix";
1985
1986
 
1986
1987
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
1987
1988
  import "transformation-matrix";
@@ -2185,6 +2186,50 @@ var createSvgObjectsFromSchPortOnBox = (params) => {
2185
2186
  return svgObjects;
2186
2187
  };
2187
2188
 
2189
+ // lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
2190
+ import { applyToPoint as applyToPoint25 } from "transformation-matrix";
2191
+ var createSvgSchText = (elm, transform) => {
2192
+ const center = applyToPoint25(transform, elm.position);
2193
+ const textAnchorMap = {
2194
+ center: "middle",
2195
+ left: "start",
2196
+ right: "end",
2197
+ top: "middle",
2198
+ bottom: "middle"
2199
+ };
2200
+ const dominantBaselineMap = {
2201
+ center: "middle",
2202
+ left: "middle",
2203
+ right: "middle",
2204
+ top: "hanging",
2205
+ bottom: "ideographic"
2206
+ };
2207
+ return {
2208
+ type: "element",
2209
+ name: "text",
2210
+ value: "",
2211
+ attributes: {
2212
+ x: center.x.toString(),
2213
+ y: center.y.toString(),
2214
+ fill: elm.color ?? colorMap.schematic.sheet_label,
2215
+ "text-anchor": textAnchorMap[elm.anchor],
2216
+ "dominant-baseline": dominantBaselineMap[elm.anchor],
2217
+ "font-family": "sans-serif",
2218
+ "font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
2219
+ transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
2220
+ },
2221
+ children: [
2222
+ {
2223
+ type: "text",
2224
+ value: elm.text,
2225
+ name: elm.schematic_text_id,
2226
+ attributes: {},
2227
+ children: []
2228
+ }
2229
+ ]
2230
+ };
2231
+ };
2232
+
2188
2233
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-box.ts
2189
2234
  var createSvgObjectsFromSchematicComponentWithBox = ({
2190
2235
  component: schComponent,
@@ -2192,11 +2237,11 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2192
2237
  circuitJson
2193
2238
  }) => {
2194
2239
  const svgObjects = [];
2195
- const componentScreenTopLeft = applyToPoint25(transform, {
2240
+ const componentScreenTopLeft = applyToPoint26(transform, {
2196
2241
  x: schComponent.center.x - schComponent.size.width / 2,
2197
2242
  y: schComponent.center.y + schComponent.size.height / 2
2198
2243
  });
2199
- const componentScreenBottomRight = applyToPoint25(transform, {
2244
+ const componentScreenBottomRight = applyToPoint26(transform, {
2200
2245
  x: schComponent.center.x + schComponent.size.width / 2,
2201
2246
  y: schComponent.center.y - schComponent.size.height / 2
2202
2247
  });
@@ -2232,6 +2277,12 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2232
2277
  },
2233
2278
  children: []
2234
2279
  });
2280
+ const schTexts = su5(circuitJson).schematic_text.list();
2281
+ for (const schText of schTexts) {
2282
+ if (schText.schematic_component_id === schComponent.schematic_component_id) {
2283
+ svgObjects.push(createSvgSchText(schText, transform));
2284
+ }
2285
+ }
2235
2286
  const schematicPorts = su5(circuitJson).schematic_port.list({
2236
2287
  schematic_component_id: schComponent.schematic_component_id
2237
2288
  });
@@ -2267,9 +2318,9 @@ function createSvgObjectsFromSchematicComponent(params) {
2267
2318
  }
2268
2319
 
2269
2320
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
2270
- import { applyToPoint as applyToPoint26 } from "transformation-matrix";
2321
+ import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2271
2322
  function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2272
- const [screenX, screenY] = applyToPoint26(transform, [
2323
+ const [screenX, screenY] = applyToPoint27(transform, [
2273
2324
  probe.position.x,
2274
2325
  probe.position.y
2275
2326
  ]);
@@ -2329,14 +2380,14 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2329
2380
  }
2330
2381
 
2331
2382
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
2332
- import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2383
+ import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2333
2384
  function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2334
2385
  if (debugObject.shape === "rect") {
2335
- let [screenLeft, screenTop] = applyToPoint27(transform, [
2386
+ let [screenLeft, screenTop] = applyToPoint28(transform, [
2336
2387
  debugObject.center.x - debugObject.size.width / 2,
2337
2388
  debugObject.center.y - debugObject.size.height / 2
2338
2389
  ]);
2339
- let [screenRight, screenBottom] = applyToPoint27(transform, [
2390
+ let [screenRight, screenBottom] = applyToPoint28(transform, [
2340
2391
  debugObject.center.x + debugObject.size.width / 2,
2341
2392
  debugObject.center.y + debugObject.size.height / 2
2342
2393
  ]);
@@ -2346,7 +2397,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2346
2397
  ];
2347
2398
  const width = Math.abs(screenRight - screenLeft);
2348
2399
  const height = Math.abs(screenBottom - screenTop);
2349
- const [screenCenterX, screenCenterY] = applyToPoint27(transform, [
2400
+ const [screenCenterX, screenCenterY] = applyToPoint28(transform, [
2350
2401
  debugObject.center.x,
2351
2402
  debugObject.center.y
2352
2403
  ]);
@@ -2392,11 +2443,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2392
2443
  ];
2393
2444
  }
2394
2445
  if (debugObject.shape === "line") {
2395
- const [screenStartX, screenStartY] = applyToPoint27(transform, [
2446
+ const [screenStartX, screenStartY] = applyToPoint28(transform, [
2396
2447
  debugObject.start.x,
2397
2448
  debugObject.start.y
2398
2449
  ]);
2399
- const [screenEndX, screenEndY] = applyToPoint27(transform, [
2450
+ const [screenEndX, screenEndY] = applyToPoint28(transform, [
2400
2451
  debugObject.end.x,
2401
2452
  debugObject.end.y
2402
2453
  ]);
@@ -2446,7 +2497,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2446
2497
  }
2447
2498
 
2448
2499
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
2449
- import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2500
+ import { applyToPoint as applyToPoint29 } from "transformation-matrix";
2450
2501
  function createSchematicTrace(trace, transform) {
2451
2502
  const edges = trace.edges;
2452
2503
  if (edges.length === 0) return [];
@@ -2455,11 +2506,11 @@ function createSchematicTrace(trace, transform) {
2455
2506
  for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
2456
2507
  const edge = edges[edgeIndex];
2457
2508
  if (edge.is_crossing) continue;
2458
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2509
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2459
2510
  edge.from.x,
2460
2511
  edge.from.y
2461
2512
  ]);
2462
- const [screenToX, screenToY] = applyToPoint28(transform, [
2513
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2463
2514
  edge.to.x,
2464
2515
  edge.to.y
2465
2516
  ]);
@@ -2471,11 +2522,11 @@ function createSchematicTrace(trace, transform) {
2471
2522
  }
2472
2523
  for (const edge of edges) {
2473
2524
  if (!edge.is_crossing) continue;
2474
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2525
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2475
2526
  edge.from.x,
2476
2527
  edge.from.y
2477
2528
  ]);
2478
- const [screenToX, screenToY] = applyToPoint28(transform, [
2529
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2479
2530
  edge.to.x,
2480
2531
  edge.to.y
2481
2532
  ]);
@@ -2551,7 +2602,7 @@ function createSchematicTrace(trace, transform) {
2551
2602
  }
2552
2603
  if (trace.junctions) {
2553
2604
  for (const junction of trace.junctions) {
2554
- const [screenX, screenY] = applyToPoint28(transform, [
2605
+ const [screenX, screenY] = applyToPoint29(transform, [
2555
2606
  junction.x,
2556
2607
  junction.y
2557
2608
  ]);
@@ -2586,7 +2637,7 @@ function createSchematicTrace(trace, transform) {
2586
2637
 
2587
2638
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
2588
2639
  import {
2589
- applyToPoint as applyToPoint30,
2640
+ applyToPoint as applyToPoint31,
2590
2641
  compose as compose8,
2591
2642
  rotate as rotate4,
2592
2643
  scale as scale5,
@@ -3374,7 +3425,7 @@ var estimateTextWidth = (text) => {
3374
3425
 
3375
3426
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
3376
3427
  import {
3377
- applyToPoint as applyToPoint29,
3428
+ applyToPoint as applyToPoint30,
3378
3429
  compose as compose7,
3379
3430
  rotate as rotate3,
3380
3431
  scale as scale4,
@@ -3399,7 +3450,7 @@ var ninePointAnchorToTextAnchor2 = {
3399
3450
  middle_top: "middle",
3400
3451
  middle_bottom: "middle"
3401
3452
  };
3402
- var ninePointAnchorToDominantBaseline2 = {
3453
+ var ninePointAnchorToDominantBaseline = {
3403
3454
  top_left: "auto",
3404
3455
  top_right: "auto",
3405
3456
  bottom_left: "hanging",
@@ -3494,7 +3545,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3494
3545
  x: symbolBounds.minX,
3495
3546
  y: (symbolBounds.minY + symbolBounds.maxY) / 2
3496
3547
  };
3497
- const rotatedSymbolEnd = applyToPoint29(rotationMatrix, symbolEndPoint);
3548
+ const rotatedSymbolEnd = applyToPoint30(rotationMatrix, symbolEndPoint);
3498
3549
  const symbolToRealTransform = compose7(
3499
3550
  translate7(
3500
3551
  realAnchorPosition.x - rotatedSymbolEnd.x,
@@ -3504,11 +3555,11 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3504
3555
  scale4(1)
3505
3556
  // Use full symbol size
3506
3557
  );
3507
- const [screenMinX, screenMinY] = applyToPoint29(
3558
+ const [screenMinX, screenMinY] = applyToPoint30(
3508
3559
  compose7(realToScreenTransform, symbolToRealTransform),
3509
3560
  [bounds.minX, bounds.minY]
3510
3561
  );
3511
- const [screenMaxX, screenMaxY] = applyToPoint29(
3562
+ const [screenMaxX, screenMaxY] = applyToPoint30(
3512
3563
  compose7(realToScreenTransform, symbolToRealTransform),
3513
3564
  [bounds.maxX, bounds.maxY]
3514
3565
  );
@@ -3532,7 +3583,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3532
3583
  });
3533
3584
  for (const path of symbolPaths) {
3534
3585
  const symbolPath = path.points.map((p, i) => {
3535
- const [x, y] = applyToPoint29(
3586
+ const [x, y] = applyToPoint30(
3536
3587
  compose7(realToScreenTransform, symbolToRealTransform),
3537
3588
  [p.x, p.y]
3538
3589
  );
@@ -3552,7 +3603,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3552
3603
  });
3553
3604
  }
3554
3605
  for (const text of symbolTexts) {
3555
- const screenTextPos = applyToPoint29(
3606
+ const screenTextPos = applyToPoint30(
3556
3607
  compose7(realToScreenTransform, symbolToRealTransform),
3557
3608
  text
3558
3609
  );
@@ -3578,7 +3629,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3578
3629
  fill: colorMap.schematic.label_local,
3579
3630
  "font-family": "sans-serif",
3580
3631
  "text-anchor": ninePointAnchorToTextAnchor2[text.anchor],
3581
- "dominant-baseline": ninePointAnchorToDominantBaseline2[text.anchor],
3632
+ "dominant-baseline": ninePointAnchorToDominantBaseline[text.anchor],
3582
3633
  "font-size": `${getSchScreenFontSize(realToScreenTransform, "reference_designator")}px`
3583
3634
  },
3584
3635
  children: [
@@ -3594,7 +3645,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3594
3645
  });
3595
3646
  }
3596
3647
  for (const box of symbolBoxes) {
3597
- const screenBoxPos = applyToPoint29(
3648
+ const screenBoxPos = applyToPoint30(
3598
3649
  compose7(realToScreenTransform, symbolToRealTransform),
3599
3650
  box
3600
3651
  );
@@ -3617,7 +3668,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3617
3668
  });
3618
3669
  }
3619
3670
  for (const circle of symbolCircles) {
3620
- const screenCirclePos = applyToPoint29(
3671
+ const screenCirclePos = applyToPoint30(
3621
3672
  compose7(realToScreenTransform, symbolToRealTransform),
3622
3673
  circle
3623
3674
  );
@@ -3656,14 +3707,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3656
3707
  const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
3657
3708
  const fontSizeMm = getSchMmFontSize("net_label");
3658
3709
  const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
3659
- const screenCenter = applyToPoint30(realToScreenTransform, schNetLabel.center);
3710
+ const screenCenter = applyToPoint31(realToScreenTransform, schNetLabel.center);
3660
3711
  const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
3661
3712
  schNetLabel.anchor_side
3662
3713
  );
3663
3714
  const screenTextGrowthVec = { ...realTextGrowthVec };
3664
3715
  screenTextGrowthVec.y *= -1;
3665
3716
  const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
3666
- const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint30(realToScreenTransform, schNetLabel.anchor_position) : {
3717
+ const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint31(realToScreenTransform, schNetLabel.anchor_position) : {
3667
3718
  x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
3668
3719
  y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
3669
3720
  };
@@ -3704,7 +3755,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3704
3755
  y: -0.6
3705
3756
  }
3706
3757
  ].map(
3707
- (fontRelativePoint) => applyToPoint30(
3758
+ (fontRelativePoint) => applyToPoint31(
3708
3759
  compose8(
3709
3760
  realToScreenTransform,
3710
3761
  translate8(realAnchorPosition.x, realAnchorPosition.y),
@@ -3780,50 +3831,6 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3780
3831
  return svgObjects;
3781
3832
  };
3782
3833
 
3783
- // lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
3784
- import { applyToPoint as applyToPoint31 } from "transformation-matrix";
3785
- var createSvgSchText = (elm, transform) => {
3786
- const center = applyToPoint31(transform, elm.position);
3787
- const textAnchorMap = {
3788
- center: "middle",
3789
- left: "start",
3790
- right: "end",
3791
- top: "middle",
3792
- bottom: "middle"
3793
- };
3794
- const dominantBaselineMap = {
3795
- center: "middle",
3796
- left: "middle",
3797
- right: "middle",
3798
- top: "hanging",
3799
- bottom: "ideographic"
3800
- };
3801
- return {
3802
- type: "element",
3803
- name: "text",
3804
- value: "",
3805
- attributes: {
3806
- x: center.x.toString(),
3807
- y: center.y.toString(),
3808
- fill: elm.color ?? colorMap.schematic.sheet_label,
3809
- "text-anchor": textAnchorMap[elm.anchor],
3810
- "dominant-baseline": dominantBaselineMap[elm.anchor],
3811
- "font-family": "sans-serif",
3812
- "font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
3813
- transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
3814
- },
3815
- children: [
3816
- {
3817
- type: "text",
3818
- value: elm.text,
3819
- name: elm.schematic_text_id,
3820
- attributes: {},
3821
- children: []
3822
- }
3823
- ]
3824
- };
3825
- };
3826
-
3827
3834
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
3828
3835
  function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3829
3836
  const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
@@ -3902,7 +3909,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3902
3909
  schTraceSvgs.push(...createSchematicTrace(elm, transform));
3903
3910
  } else if (elm.type === "schematic_net_label") {
3904
3911
  schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
3905
- } else if (elm.type === "schematic_text") {
3912
+ } else if (elm.type === "schematic_text" && !elm.schematic_component_id) {
3906
3913
  schText.push(createSvgSchText(elm, transform));
3907
3914
  } else if (elm.type === "schematic_voltage_probe") {
3908
3915
  voltageProbeSvgs.push(