circuit-to-svg 0.0.95 → 0.0.96

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
@@ -1981,7 +1981,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
1981
1981
  import { su as su5 } from "@tscircuit/soup-util";
1982
1982
  import "schematic-symbols";
1983
1983
  import "svgson";
1984
- import { applyToPoint as applyToPoint25 } from "transformation-matrix";
1984
+ import { applyToPoint as applyToPoint26 } from "transformation-matrix";
1985
1985
 
1986
1986
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
1987
1987
  import "transformation-matrix";
@@ -2185,6 +2185,50 @@ var createSvgObjectsFromSchPortOnBox = (params) => {
2185
2185
  return svgObjects;
2186
2186
  };
2187
2187
 
2188
+ // lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
2189
+ import { applyToPoint as applyToPoint25 } from "transformation-matrix";
2190
+ var createSvgSchText = (elm, transform) => {
2191
+ const center = applyToPoint25(transform, elm.position);
2192
+ const textAnchorMap = {
2193
+ center: "middle",
2194
+ left: "start",
2195
+ right: "end",
2196
+ top: "middle",
2197
+ bottom: "middle"
2198
+ };
2199
+ const dominantBaselineMap = {
2200
+ center: "middle",
2201
+ left: "middle",
2202
+ right: "middle",
2203
+ top: "hanging",
2204
+ bottom: "ideographic"
2205
+ };
2206
+ return {
2207
+ type: "element",
2208
+ name: "text",
2209
+ value: "",
2210
+ attributes: {
2211
+ x: center.x.toString(),
2212
+ y: center.y.toString(),
2213
+ fill: elm.color ?? colorMap.schematic.sheet_label,
2214
+ "text-anchor": textAnchorMap[elm.anchor],
2215
+ "dominant-baseline": dominantBaselineMap[elm.anchor],
2216
+ "font-family": "sans-serif",
2217
+ "font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
2218
+ transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
2219
+ },
2220
+ children: [
2221
+ {
2222
+ type: "text",
2223
+ value: elm.text,
2224
+ name: elm.schematic_text_id,
2225
+ attributes: {},
2226
+ children: []
2227
+ }
2228
+ ]
2229
+ };
2230
+ };
2231
+
2188
2232
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-box.ts
2189
2233
  var createSvgObjectsFromSchematicComponentWithBox = ({
2190
2234
  component: schComponent,
@@ -2192,11 +2236,11 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2192
2236
  circuitJson
2193
2237
  }) => {
2194
2238
  const svgObjects = [];
2195
- const componentScreenTopLeft = applyToPoint25(transform, {
2239
+ const componentScreenTopLeft = applyToPoint26(transform, {
2196
2240
  x: schComponent.center.x - schComponent.size.width / 2,
2197
2241
  y: schComponent.center.y + schComponent.size.height / 2
2198
2242
  });
2199
- const componentScreenBottomRight = applyToPoint25(transform, {
2243
+ const componentScreenBottomRight = applyToPoint26(transform, {
2200
2244
  x: schComponent.center.x + schComponent.size.width / 2,
2201
2245
  y: schComponent.center.y - schComponent.size.height / 2
2202
2246
  });
@@ -2232,6 +2276,12 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2232
2276
  },
2233
2277
  children: []
2234
2278
  });
2279
+ const schTexts = su5(circuitJson).schematic_text.list();
2280
+ for (const schText of schTexts) {
2281
+ if (schText.schematic_component_id === schComponent.schematic_component_id) {
2282
+ svgObjects.push(createSvgSchText(schText, transform));
2283
+ }
2284
+ }
2235
2285
  const schematicPorts = su5(circuitJson).schematic_port.list({
2236
2286
  schematic_component_id: schComponent.schematic_component_id
2237
2287
  });
@@ -2267,9 +2317,9 @@ function createSvgObjectsFromSchematicComponent(params) {
2267
2317
  }
2268
2318
 
2269
2319
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
2270
- import { applyToPoint as applyToPoint26 } from "transformation-matrix";
2320
+ import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2271
2321
  function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2272
- const [screenX, screenY] = applyToPoint26(transform, [
2322
+ const [screenX, screenY] = applyToPoint27(transform, [
2273
2323
  probe.position.x,
2274
2324
  probe.position.y
2275
2325
  ]);
@@ -2329,14 +2379,14 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2329
2379
  }
2330
2380
 
2331
2381
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
2332
- import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2382
+ import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2333
2383
  function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2334
2384
  if (debugObject.shape === "rect") {
2335
- let [screenLeft, screenTop] = applyToPoint27(transform, [
2385
+ let [screenLeft, screenTop] = applyToPoint28(transform, [
2336
2386
  debugObject.center.x - debugObject.size.width / 2,
2337
2387
  debugObject.center.y - debugObject.size.height / 2
2338
2388
  ]);
2339
- let [screenRight, screenBottom] = applyToPoint27(transform, [
2389
+ let [screenRight, screenBottom] = applyToPoint28(transform, [
2340
2390
  debugObject.center.x + debugObject.size.width / 2,
2341
2391
  debugObject.center.y + debugObject.size.height / 2
2342
2392
  ]);
@@ -2346,7 +2396,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2346
2396
  ];
2347
2397
  const width = Math.abs(screenRight - screenLeft);
2348
2398
  const height = Math.abs(screenBottom - screenTop);
2349
- const [screenCenterX, screenCenterY] = applyToPoint27(transform, [
2399
+ const [screenCenterX, screenCenterY] = applyToPoint28(transform, [
2350
2400
  debugObject.center.x,
2351
2401
  debugObject.center.y
2352
2402
  ]);
@@ -2392,11 +2442,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2392
2442
  ];
2393
2443
  }
2394
2444
  if (debugObject.shape === "line") {
2395
- const [screenStartX, screenStartY] = applyToPoint27(transform, [
2445
+ const [screenStartX, screenStartY] = applyToPoint28(transform, [
2396
2446
  debugObject.start.x,
2397
2447
  debugObject.start.y
2398
2448
  ]);
2399
- const [screenEndX, screenEndY] = applyToPoint27(transform, [
2449
+ const [screenEndX, screenEndY] = applyToPoint28(transform, [
2400
2450
  debugObject.end.x,
2401
2451
  debugObject.end.y
2402
2452
  ]);
@@ -2446,7 +2496,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2446
2496
  }
2447
2497
 
2448
2498
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
2449
- import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2499
+ import { applyToPoint as applyToPoint29 } from "transformation-matrix";
2450
2500
  function createSchematicTrace(trace, transform) {
2451
2501
  const edges = trace.edges;
2452
2502
  if (edges.length === 0) return [];
@@ -2455,11 +2505,11 @@ function createSchematicTrace(trace, transform) {
2455
2505
  for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
2456
2506
  const edge = edges[edgeIndex];
2457
2507
  if (edge.is_crossing) continue;
2458
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2508
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2459
2509
  edge.from.x,
2460
2510
  edge.from.y
2461
2511
  ]);
2462
- const [screenToX, screenToY] = applyToPoint28(transform, [
2512
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2463
2513
  edge.to.x,
2464
2514
  edge.to.y
2465
2515
  ]);
@@ -2471,11 +2521,11 @@ function createSchematicTrace(trace, transform) {
2471
2521
  }
2472
2522
  for (const edge of edges) {
2473
2523
  if (!edge.is_crossing) continue;
2474
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2524
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2475
2525
  edge.from.x,
2476
2526
  edge.from.y
2477
2527
  ]);
2478
- const [screenToX, screenToY] = applyToPoint28(transform, [
2528
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2479
2529
  edge.to.x,
2480
2530
  edge.to.y
2481
2531
  ]);
@@ -2551,7 +2601,7 @@ function createSchematicTrace(trace, transform) {
2551
2601
  }
2552
2602
  if (trace.junctions) {
2553
2603
  for (const junction of trace.junctions) {
2554
- const [screenX, screenY] = applyToPoint28(transform, [
2604
+ const [screenX, screenY] = applyToPoint29(transform, [
2555
2605
  junction.x,
2556
2606
  junction.y
2557
2607
  ]);
@@ -2586,7 +2636,7 @@ function createSchematicTrace(trace, transform) {
2586
2636
 
2587
2637
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
2588
2638
  import {
2589
- applyToPoint as applyToPoint30,
2639
+ applyToPoint as applyToPoint31,
2590
2640
  compose as compose8,
2591
2641
  rotate as rotate4,
2592
2642
  scale as scale5,
@@ -3374,7 +3424,7 @@ var estimateTextWidth = (text) => {
3374
3424
 
3375
3425
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
3376
3426
  import {
3377
- applyToPoint as applyToPoint29,
3427
+ applyToPoint as applyToPoint30,
3378
3428
  compose as compose7,
3379
3429
  rotate as rotate3,
3380
3430
  scale as scale4,
@@ -3494,7 +3544,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3494
3544
  x: symbolBounds.minX,
3495
3545
  y: (symbolBounds.minY + symbolBounds.maxY) / 2
3496
3546
  };
3497
- const rotatedSymbolEnd = applyToPoint29(rotationMatrix, symbolEndPoint);
3547
+ const rotatedSymbolEnd = applyToPoint30(rotationMatrix, symbolEndPoint);
3498
3548
  const symbolToRealTransform = compose7(
3499
3549
  translate7(
3500
3550
  realAnchorPosition.x - rotatedSymbolEnd.x,
@@ -3504,11 +3554,11 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3504
3554
  scale4(1)
3505
3555
  // Use full symbol size
3506
3556
  );
3507
- const [screenMinX, screenMinY] = applyToPoint29(
3557
+ const [screenMinX, screenMinY] = applyToPoint30(
3508
3558
  compose7(realToScreenTransform, symbolToRealTransform),
3509
3559
  [bounds.minX, bounds.minY]
3510
3560
  );
3511
- const [screenMaxX, screenMaxY] = applyToPoint29(
3561
+ const [screenMaxX, screenMaxY] = applyToPoint30(
3512
3562
  compose7(realToScreenTransform, symbolToRealTransform),
3513
3563
  [bounds.maxX, bounds.maxY]
3514
3564
  );
@@ -3532,7 +3582,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3532
3582
  });
3533
3583
  for (const path of symbolPaths) {
3534
3584
  const symbolPath = path.points.map((p, i) => {
3535
- const [x, y] = applyToPoint29(
3585
+ const [x, y] = applyToPoint30(
3536
3586
  compose7(realToScreenTransform, symbolToRealTransform),
3537
3587
  [p.x, p.y]
3538
3588
  );
@@ -3552,7 +3602,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3552
3602
  });
3553
3603
  }
3554
3604
  for (const text of symbolTexts) {
3555
- const screenTextPos = applyToPoint29(
3605
+ const screenTextPos = applyToPoint30(
3556
3606
  compose7(realToScreenTransform, symbolToRealTransform),
3557
3607
  text
3558
3608
  );
@@ -3594,7 +3644,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3594
3644
  });
3595
3645
  }
3596
3646
  for (const box of symbolBoxes) {
3597
- const screenBoxPos = applyToPoint29(
3647
+ const screenBoxPos = applyToPoint30(
3598
3648
  compose7(realToScreenTransform, symbolToRealTransform),
3599
3649
  box
3600
3650
  );
@@ -3617,7 +3667,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3617
3667
  });
3618
3668
  }
3619
3669
  for (const circle of symbolCircles) {
3620
- const screenCirclePos = applyToPoint29(
3670
+ const screenCirclePos = applyToPoint30(
3621
3671
  compose7(realToScreenTransform, symbolToRealTransform),
3622
3672
  circle
3623
3673
  );
@@ -3656,14 +3706,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3656
3706
  const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
3657
3707
  const fontSizeMm = getSchMmFontSize("net_label");
3658
3708
  const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
3659
- const screenCenter = applyToPoint30(realToScreenTransform, schNetLabel.center);
3709
+ const screenCenter = applyToPoint31(realToScreenTransform, schNetLabel.center);
3660
3710
  const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
3661
3711
  schNetLabel.anchor_side
3662
3712
  );
3663
3713
  const screenTextGrowthVec = { ...realTextGrowthVec };
3664
3714
  screenTextGrowthVec.y *= -1;
3665
3715
  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) : {
3716
+ const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint31(realToScreenTransform, schNetLabel.anchor_position) : {
3667
3717
  x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
3668
3718
  y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
3669
3719
  };
@@ -3704,7 +3754,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3704
3754
  y: -0.6
3705
3755
  }
3706
3756
  ].map(
3707
- (fontRelativePoint) => applyToPoint30(
3757
+ (fontRelativePoint) => applyToPoint31(
3708
3758
  compose8(
3709
3759
  realToScreenTransform,
3710
3760
  translate8(realAnchorPosition.x, realAnchorPosition.y),
@@ -3780,50 +3830,6 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3780
3830
  return svgObjects;
3781
3831
  };
3782
3832
 
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
3833
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
3828
3834
  function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3829
3835
  const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
@@ -3902,7 +3908,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3902
3908
  schTraceSvgs.push(...createSchematicTrace(elm, transform));
3903
3909
  } else if (elm.type === "schematic_net_label") {
3904
3910
  schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
3905
- } else if (elm.type === "schematic_text") {
3911
+ } else if (elm.type === "schematic_text" && !elm.schematic_component_id) {
3906
3912
  schText.push(createSvgSchText(elm, transform));
3907
3913
  } else if (elm.type === "schematic_voltage_probe") {
3908
3914
  voltageProbeSvgs.push(