circuit-to-svg 0.0.94 → 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
@@ -1444,7 +1444,8 @@ var colorMap = {
1444
1444
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
1445
1445
  import { stringify as stringify3 } from "svgson";
1446
1446
  import {
1447
- fromTriangles
1447
+ fromTriangles,
1448
+ toSVG
1448
1449
  } from "transformation-matrix";
1449
1450
 
1450
1451
  // lib/sch/draw-schematic-grid.ts
@@ -1622,6 +1623,12 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
1622
1623
  updateBounds(item.position, { width: 0.1, height: 0.1 }, 0);
1623
1624
  } else if (item.type === "schematic_voltage_probe") {
1624
1625
  updateBounds(item.position, { width: 0.2, height: 0.4 }, 0);
1626
+ } else if (item.type === "schematic_box") {
1627
+ updateBounds(
1628
+ { x: item.x, y: item.y },
1629
+ { width: item.width, height: item.height },
1630
+ 0
1631
+ );
1625
1632
  }
1626
1633
  }
1627
1634
  minX -= padding;
@@ -1974,7 +1981,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
1974
1981
  import { su as su5 } from "@tscircuit/soup-util";
1975
1982
  import "schematic-symbols";
1976
1983
  import "svgson";
1977
- import { applyToPoint as applyToPoint25 } from "transformation-matrix";
1984
+ import { applyToPoint as applyToPoint26 } from "transformation-matrix";
1978
1985
 
1979
1986
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
1980
1987
  import "transformation-matrix";
@@ -2178,6 +2185,50 @@ var createSvgObjectsFromSchPortOnBox = (params) => {
2178
2185
  return svgObjects;
2179
2186
  };
2180
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
+
2181
2232
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-box.ts
2182
2233
  var createSvgObjectsFromSchematicComponentWithBox = ({
2183
2234
  component: schComponent,
@@ -2185,11 +2236,11 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2185
2236
  circuitJson
2186
2237
  }) => {
2187
2238
  const svgObjects = [];
2188
- const componentScreenTopLeft = applyToPoint25(transform, {
2239
+ const componentScreenTopLeft = applyToPoint26(transform, {
2189
2240
  x: schComponent.center.x - schComponent.size.width / 2,
2190
2241
  y: schComponent.center.y + schComponent.size.height / 2
2191
2242
  });
2192
- const componentScreenBottomRight = applyToPoint25(transform, {
2243
+ const componentScreenBottomRight = applyToPoint26(transform, {
2193
2244
  x: schComponent.center.x + schComponent.size.width / 2,
2194
2245
  y: schComponent.center.y - schComponent.size.height / 2
2195
2246
  });
@@ -2225,6 +2276,12 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2225
2276
  },
2226
2277
  children: []
2227
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
+ }
2228
2285
  const schematicPorts = su5(circuitJson).schematic_port.list({
2229
2286
  schematic_component_id: schComponent.schematic_component_id
2230
2287
  });
@@ -2260,9 +2317,9 @@ function createSvgObjectsFromSchematicComponent(params) {
2260
2317
  }
2261
2318
 
2262
2319
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
2263
- import { applyToPoint as applyToPoint26 } from "transformation-matrix";
2320
+ import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2264
2321
  function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2265
- const [screenX, screenY] = applyToPoint26(transform, [
2322
+ const [screenX, screenY] = applyToPoint27(transform, [
2266
2323
  probe.position.x,
2267
2324
  probe.position.y
2268
2325
  ]);
@@ -2322,14 +2379,14 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2322
2379
  }
2323
2380
 
2324
2381
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
2325
- import { applyToPoint as applyToPoint27 } from "transformation-matrix";
2382
+ import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2326
2383
  function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2327
2384
  if (debugObject.shape === "rect") {
2328
- let [screenLeft, screenTop] = applyToPoint27(transform, [
2385
+ let [screenLeft, screenTop] = applyToPoint28(transform, [
2329
2386
  debugObject.center.x - debugObject.size.width / 2,
2330
2387
  debugObject.center.y - debugObject.size.height / 2
2331
2388
  ]);
2332
- let [screenRight, screenBottom] = applyToPoint27(transform, [
2389
+ let [screenRight, screenBottom] = applyToPoint28(transform, [
2333
2390
  debugObject.center.x + debugObject.size.width / 2,
2334
2391
  debugObject.center.y + debugObject.size.height / 2
2335
2392
  ]);
@@ -2339,7 +2396,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2339
2396
  ];
2340
2397
  const width = Math.abs(screenRight - screenLeft);
2341
2398
  const height = Math.abs(screenBottom - screenTop);
2342
- const [screenCenterX, screenCenterY] = applyToPoint27(transform, [
2399
+ const [screenCenterX, screenCenterY] = applyToPoint28(transform, [
2343
2400
  debugObject.center.x,
2344
2401
  debugObject.center.y
2345
2402
  ]);
@@ -2385,11 +2442,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2385
2442
  ];
2386
2443
  }
2387
2444
  if (debugObject.shape === "line") {
2388
- const [screenStartX, screenStartY] = applyToPoint27(transform, [
2445
+ const [screenStartX, screenStartY] = applyToPoint28(transform, [
2389
2446
  debugObject.start.x,
2390
2447
  debugObject.start.y
2391
2448
  ]);
2392
- const [screenEndX, screenEndY] = applyToPoint27(transform, [
2449
+ const [screenEndX, screenEndY] = applyToPoint28(transform, [
2393
2450
  debugObject.end.x,
2394
2451
  debugObject.end.y
2395
2452
  ]);
@@ -2439,7 +2496,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2439
2496
  }
2440
2497
 
2441
2498
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
2442
- import { applyToPoint as applyToPoint28 } from "transformation-matrix";
2499
+ import { applyToPoint as applyToPoint29 } from "transformation-matrix";
2443
2500
  function createSchematicTrace(trace, transform) {
2444
2501
  const edges = trace.edges;
2445
2502
  if (edges.length === 0) return [];
@@ -2448,11 +2505,11 @@ function createSchematicTrace(trace, transform) {
2448
2505
  for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
2449
2506
  const edge = edges[edgeIndex];
2450
2507
  if (edge.is_crossing) continue;
2451
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2508
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2452
2509
  edge.from.x,
2453
2510
  edge.from.y
2454
2511
  ]);
2455
- const [screenToX, screenToY] = applyToPoint28(transform, [
2512
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2456
2513
  edge.to.x,
2457
2514
  edge.to.y
2458
2515
  ]);
@@ -2464,11 +2521,11 @@ function createSchematicTrace(trace, transform) {
2464
2521
  }
2465
2522
  for (const edge of edges) {
2466
2523
  if (!edge.is_crossing) continue;
2467
- const [screenFromX, screenFromY] = applyToPoint28(transform, [
2524
+ const [screenFromX, screenFromY] = applyToPoint29(transform, [
2468
2525
  edge.from.x,
2469
2526
  edge.from.y
2470
2527
  ]);
2471
- const [screenToX, screenToY] = applyToPoint28(transform, [
2528
+ const [screenToX, screenToY] = applyToPoint29(transform, [
2472
2529
  edge.to.x,
2473
2530
  edge.to.y
2474
2531
  ]);
@@ -2544,7 +2601,7 @@ function createSchematicTrace(trace, transform) {
2544
2601
  }
2545
2602
  if (trace.junctions) {
2546
2603
  for (const junction of trace.junctions) {
2547
- const [screenX, screenY] = applyToPoint28(transform, [
2604
+ const [screenX, screenY] = applyToPoint29(transform, [
2548
2605
  junction.x,
2549
2606
  junction.y
2550
2607
  ]);
@@ -2579,7 +2636,7 @@ function createSchematicTrace(trace, transform) {
2579
2636
 
2580
2637
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
2581
2638
  import {
2582
- applyToPoint as applyToPoint30,
2639
+ applyToPoint as applyToPoint31,
2583
2640
  compose as compose8,
2584
2641
  rotate as rotate4,
2585
2642
  scale as scale5,
@@ -3367,7 +3424,7 @@ var estimateTextWidth = (text) => {
3367
3424
 
3368
3425
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
3369
3426
  import {
3370
- applyToPoint as applyToPoint29,
3427
+ applyToPoint as applyToPoint30,
3371
3428
  compose as compose7,
3372
3429
  rotate as rotate3,
3373
3430
  scale as scale4,
@@ -3487,7 +3544,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3487
3544
  x: symbolBounds.minX,
3488
3545
  y: (symbolBounds.minY + symbolBounds.maxY) / 2
3489
3546
  };
3490
- const rotatedSymbolEnd = applyToPoint29(rotationMatrix, symbolEndPoint);
3547
+ const rotatedSymbolEnd = applyToPoint30(rotationMatrix, symbolEndPoint);
3491
3548
  const symbolToRealTransform = compose7(
3492
3549
  translate7(
3493
3550
  realAnchorPosition.x - rotatedSymbolEnd.x,
@@ -3497,11 +3554,11 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3497
3554
  scale4(1)
3498
3555
  // Use full symbol size
3499
3556
  );
3500
- const [screenMinX, screenMinY] = applyToPoint29(
3557
+ const [screenMinX, screenMinY] = applyToPoint30(
3501
3558
  compose7(realToScreenTransform, symbolToRealTransform),
3502
3559
  [bounds.minX, bounds.minY]
3503
3560
  );
3504
- const [screenMaxX, screenMaxY] = applyToPoint29(
3561
+ const [screenMaxX, screenMaxY] = applyToPoint30(
3505
3562
  compose7(realToScreenTransform, symbolToRealTransform),
3506
3563
  [bounds.maxX, bounds.maxY]
3507
3564
  );
@@ -3525,7 +3582,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3525
3582
  });
3526
3583
  for (const path of symbolPaths) {
3527
3584
  const symbolPath = path.points.map((p, i) => {
3528
- const [x, y] = applyToPoint29(
3585
+ const [x, y] = applyToPoint30(
3529
3586
  compose7(realToScreenTransform, symbolToRealTransform),
3530
3587
  [p.x, p.y]
3531
3588
  );
@@ -3545,7 +3602,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3545
3602
  });
3546
3603
  }
3547
3604
  for (const text of symbolTexts) {
3548
- const screenTextPos = applyToPoint29(
3605
+ const screenTextPos = applyToPoint30(
3549
3606
  compose7(realToScreenTransform, symbolToRealTransform),
3550
3607
  text
3551
3608
  );
@@ -3587,7 +3644,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3587
3644
  });
3588
3645
  }
3589
3646
  for (const box of symbolBoxes) {
3590
- const screenBoxPos = applyToPoint29(
3647
+ const screenBoxPos = applyToPoint30(
3591
3648
  compose7(realToScreenTransform, symbolToRealTransform),
3592
3649
  box
3593
3650
  );
@@ -3610,7 +3667,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3610
3667
  });
3611
3668
  }
3612
3669
  for (const circle of symbolCircles) {
3613
- const screenCirclePos = applyToPoint29(
3670
+ const screenCirclePos = applyToPoint30(
3614
3671
  compose7(realToScreenTransform, symbolToRealTransform),
3615
3672
  circle
3616
3673
  );
@@ -3649,14 +3706,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3649
3706
  const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
3650
3707
  const fontSizeMm = getSchMmFontSize("net_label");
3651
3708
  const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
3652
- const screenCenter = applyToPoint30(realToScreenTransform, schNetLabel.center);
3709
+ const screenCenter = applyToPoint31(realToScreenTransform, schNetLabel.center);
3653
3710
  const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
3654
3711
  schNetLabel.anchor_side
3655
3712
  );
3656
3713
  const screenTextGrowthVec = { ...realTextGrowthVec };
3657
3714
  screenTextGrowthVec.y *= -1;
3658
3715
  const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
3659
- const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint30(realToScreenTransform, schNetLabel.anchor_position) : {
3716
+ const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint31(realToScreenTransform, schNetLabel.anchor_position) : {
3660
3717
  x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
3661
3718
  y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
3662
3719
  };
@@ -3697,7 +3754,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3697
3754
  y: -0.6
3698
3755
  }
3699
3756
  ].map(
3700
- (fontRelativePoint) => applyToPoint30(
3757
+ (fontRelativePoint) => applyToPoint31(
3701
3758
  compose8(
3702
3759
  realToScreenTransform,
3703
3760
  translate8(realAnchorPosition.x, realAnchorPosition.y),
@@ -3773,50 +3830,6 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
3773
3830
  return svgObjects;
3774
3831
  };
3775
3832
 
3776
- // lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
3777
- import { applyToPoint as applyToPoint31 } from "transformation-matrix";
3778
- var createSvgSchText = (elm, transform) => {
3779
- const center = applyToPoint31(transform, elm.position);
3780
- const textAnchorMap = {
3781
- center: "middle",
3782
- left: "start",
3783
- right: "end",
3784
- top: "middle",
3785
- bottom: "middle"
3786
- };
3787
- const dominantBaselineMap = {
3788
- center: "middle",
3789
- left: "middle",
3790
- right: "middle",
3791
- top: "hanging",
3792
- bottom: "ideographic"
3793
- };
3794
- return {
3795
- type: "element",
3796
- name: "text",
3797
- value: "",
3798
- attributes: {
3799
- x: center.x.toString(),
3800
- y: center.y.toString(),
3801
- fill: elm.color ?? colorMap.schematic.sheet_label,
3802
- "text-anchor": textAnchorMap[elm.anchor],
3803
- "dominant-baseline": dominantBaselineMap[elm.anchor],
3804
- "font-family": "sans-serif",
3805
- "font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
3806
- transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
3807
- },
3808
- children: [
3809
- {
3810
- type: "text",
3811
- value: elm.text,
3812
- name: elm.schematic_text_id,
3813
- attributes: {},
3814
- children: []
3815
- }
3816
- ]
3817
- };
3818
- };
3819
-
3820
3833
  // lib/sch/convert-circuit-json-to-schematic-svg.ts
3821
3834
  function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3822
3835
  const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
@@ -3895,7 +3908,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3895
3908
  schTraceSvgs.push(...createSchematicTrace(elm, transform));
3896
3909
  } else if (elm.type === "schematic_net_label") {
3897
3910
  schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
3898
- } else if (elm.type === "schematic_text") {
3911
+ } else if (elm.type === "schematic_text" && !elm.schematic_component_id) {
3899
3912
  schText.push(createSvgSchText(elm, transform));
3900
3913
  } else if (elm.type === "schematic_voltage_probe") {
3901
3914
  voltageProbeSvgs.push(
@@ -3926,7 +3939,8 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
3926
3939
  xmlns: "http://www.w3.org/2000/svg",
3927
3940
  width: svgWidth.toString(),
3928
3941
  height: svgHeight.toString(),
3929
- style: `background-color: ${colorMap.schematic.background}`
3942
+ style: `background-color: ${colorMap.schematic.background}`,
3943
+ "data-real-to-screen-transform": toSVG(transform)
3930
3944
  },
3931
3945
  children: [
3932
3946
  // Add styles