circuit-to-svg 0.0.113 → 0.0.115

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.d.ts CHANGED
@@ -19,6 +19,7 @@ interface Options$1 {
19
19
  declare function convertCircuitJsonToAssemblySvg(soup: AnyCircuitElement[], options?: Options$1): string;
20
20
 
21
21
  interface Options {
22
+ colorOverrides?: ColorOverrides;
22
23
  width?: number;
23
24
  height?: number;
24
25
  grid?: boolean | {
@@ -31,10 +32,16 @@ interface Options {
31
32
  label: string;
32
33
  }>;
33
34
  }
35
+ interface ColorOverrides {
36
+ schematic?: {
37
+ background?: string;
38
+ component_body?: string;
39
+ };
40
+ }
34
41
  declare function convertCircuitJsonToSchematicSvg(circuitJson: AnyCircuitElement[], options?: Options): string;
35
42
  /**
36
43
  * @deprecated use `convertCircuitJsonToSchematicSvg` instead
37
44
  */
38
45
  declare const circuitJsonToSchematicSvg: typeof convertCircuitJsonToSchematicSvg;
39
46
 
40
- export { circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg };
47
+ export { type ColorOverrides, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg };
package/dist/index.js CHANGED
@@ -417,6 +417,8 @@ function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, transform) {
417
417
  fill: "none",
418
418
  stroke: color,
419
419
  "stroke-width": (silkscreenPath.stroke_width * Math.abs(transform.a)).toString(),
420
+ "stroke-linecap": "round",
421
+ "stroke-linejoin": "round",
420
422
  "data-pcb-component-id": silkscreenPath.pcb_component_id,
421
423
  "data-pcb-silkscreen-path-id": silkscreenPath.pcb_silkscreen_path_id
422
424
  },
@@ -1822,6 +1824,7 @@ var colorMap = {
1822
1824
  hidden: "rgb(194, 194, 194)",
1823
1825
  junction: "rgb(0, 150, 0)",
1824
1826
  label_global: "rgb(132, 0, 0)",
1827
+ label_background: "rgba(255, 255, 255, 0.6)",
1825
1828
  label_hier: "rgb(114, 86, 0)",
1826
1829
  label_local: "rgb(15, 15, 15)",
1827
1830
  net_name: "rgb(132, 132, 132)",
@@ -2195,7 +2198,8 @@ var ninePointAnchorToTextAnchor = {
2195
2198
  var createSvgObjectsFromSchematicComponentWithSymbol = ({
2196
2199
  component: schComponent,
2197
2200
  transform: realToScreenTransform,
2198
- circuitJson
2201
+ circuitJson,
2202
+ colorMap: colorMap2
2199
2203
  }) => {
2200
2204
  const svgObjects = [];
2201
2205
  const symbol = symbols[schComponent.symbol_name];
@@ -2283,7 +2287,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
2283
2287
  );
2284
2288
  return `${i === 0 ? "M" : "L"} ${x} ${y}`;
2285
2289
  }).join(" ") + (closed ? " Z" : ""),
2286
- stroke: colorMap.schematic.component_outline,
2290
+ stroke: colorMap2.schematic.component_outline,
2287
2291
  fill: "none",
2288
2292
  "stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
2289
2293
  },
@@ -2319,7 +2323,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
2319
2323
  attributes: {
2320
2324
  x: screenTextPos.x.toString(),
2321
2325
  y: (screenTextPos.y + verticalOffset).toString(),
2322
- fill: colorMap.schematic.label_local,
2326
+ fill: colorMap2.schematic.label_local,
2323
2327
  "font-family": "sans-serif",
2324
2328
  "text-anchor": ninePointAnchorToTextAnchor[text.anchor],
2325
2329
  "dominant-baseline": dominantBaseline,
@@ -2374,7 +2378,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
2374
2378
  r: `${Math.abs(realToScreenTransform.a) * 0.02}px`,
2375
2379
  "stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`,
2376
2380
  fill: "none",
2377
- stroke: colorMap.schematic.component_outline
2381
+ stroke: colorMap2.schematic.component_outline
2378
2382
  },
2379
2383
  value: "",
2380
2384
  children: []
@@ -2593,7 +2597,11 @@ var createSvgObjectsFromSchPortOnBox = (params) => {
2593
2597
 
2594
2598
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
2595
2599
  import { applyToPoint as applyToPoint29 } from "transformation-matrix";
2596
- var createSvgSchText = (elm, transform) => {
2600
+ var createSvgSchText = ({
2601
+ elm,
2602
+ transform,
2603
+ colorMap: colorMap2
2604
+ }) => {
2597
2605
  const center = applyToPoint29(transform, elm.position);
2598
2606
  const textAnchorMap = {
2599
2607
  center: "middle",
@@ -2616,7 +2624,7 @@ var createSvgSchText = (elm, transform) => {
2616
2624
  attributes: {
2617
2625
  x: center.x.toString(),
2618
2626
  y: center.y.toString(),
2619
- fill: elm.color ?? colorMap.schematic.sheet_label,
2627
+ fill: elm.color ?? colorMap2.schematic.sheet_label,
2620
2628
  "text-anchor": textAnchorMap[elm.anchor],
2621
2629
  "dominant-baseline": dominantBaselineMap[elm.anchor],
2622
2630
  "font-family": "sans-serif",
@@ -2639,7 +2647,8 @@ var createSvgSchText = (elm, transform) => {
2639
2647
  var createSvgObjectsFromSchematicComponentWithBox = ({
2640
2648
  component: schComponent,
2641
2649
  transform,
2642
- circuitJson
2650
+ circuitJson,
2651
+ colorMap: colorMap2
2643
2652
  }) => {
2644
2653
  const svgObjects = [];
2645
2654
  const componentScreenTopLeft = applyToPoint30(transform, {
@@ -2663,8 +2672,8 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2663
2672
  width: componentScreenWidth.toString(),
2664
2673
  height: componentScreenHeight.toString(),
2665
2674
  "stroke-width": `${getSchStrokeSize(transform)}px`,
2666
- fill: colorMap.schematic.component_body,
2667
- stroke: colorMap.schematic.component_outline
2675
+ fill: colorMap2.schematic.component_body,
2676
+ stroke: colorMap2.schematic.component_outline
2668
2677
  },
2669
2678
  children: []
2670
2679
  });
@@ -2685,7 +2694,13 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
2685
2694
  const schTexts = su7(circuitJson).schematic_text.list();
2686
2695
  for (const schText of schTexts) {
2687
2696
  if (schText.schematic_component_id === schComponent.schematic_component_id) {
2688
- svgObjects.push(createSvgSchText(schText, transform));
2697
+ svgObjects.push(
2698
+ createSvgSchText({
2699
+ elm: schText,
2700
+ transform,
2701
+ colorMap: colorMap2
2702
+ })
2703
+ );
2689
2704
  }
2690
2705
  }
2691
2706
  const schematicPorts = su7(circuitJson).schematic_port.list({
@@ -2724,7 +2739,11 @@ function createSvgObjectsFromSchematicComponent(params) {
2724
2739
 
2725
2740
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
2726
2741
  import { applyToPoint as applyToPoint31 } from "transformation-matrix";
2727
- function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2742
+ function createSvgObjectsFromSchVoltageProbe({
2743
+ probe,
2744
+ transform,
2745
+ colorMap: colorMap2
2746
+ }) {
2728
2747
  const [screenX, screenY] = applyToPoint31(transform, [
2729
2748
  probe.position.x,
2730
2749
  probe.position.y
@@ -2749,8 +2768,8 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2749
2768
  type: "element",
2750
2769
  attributes: {
2751
2770
  d: arrowPath,
2752
- stroke: colorMap.schematic.reference,
2753
- fill: colorMap.schematic.reference,
2771
+ stroke: colorMap2.schematic.reference,
2772
+ fill: colorMap2.schematic.reference,
2754
2773
  "stroke-width": `${getSchStrokeSize(transform)}px`
2755
2774
  },
2756
2775
  value: "",
@@ -2763,7 +2782,7 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2763
2782
  attributes: {
2764
2783
  x: (baseX + 8 - (baseX - baseX)).toString(),
2765
2784
  y: (baseY - 10 + (baseY - baseY)).toString(),
2766
- fill: colorMap.schematic.reference,
2785
+ fill: colorMap2.schematic.reference,
2767
2786
  "text-anchor": "middle",
2768
2787
  "dominant-baseline": "middle",
2769
2788
  "font-family": "sans-serif",
@@ -2786,7 +2805,10 @@ function createSvgObjectsFromSchVoltageProbe(probe, transform) {
2786
2805
 
2787
2806
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
2788
2807
  import { applyToPoint as applyToPoint32 } from "transformation-matrix";
2789
- function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2808
+ function createSvgObjectsFromSchDebugObject({
2809
+ debugObject,
2810
+ transform
2811
+ }) {
2790
2812
  if (debugObject.shape === "rect") {
2791
2813
  let [screenLeft, screenTop] = applyToPoint32(transform, [
2792
2814
  debugObject.center.x - debugObject.size.width / 2,
@@ -2903,7 +2925,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
2903
2925
 
2904
2926
  // lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
2905
2927
  import { applyToPoint as applyToPoint33 } from "transformation-matrix";
2906
- function createSchematicTrace(trace, transform) {
2928
+ function createSchematicTrace({
2929
+ trace,
2930
+ transform,
2931
+ colorMap: colorMap2
2932
+ }) {
2907
2933
  const edges = trace.edges;
2908
2934
  if (edges.length === 0) return [];
2909
2935
  const svgObjects = [];
@@ -2951,7 +2977,7 @@ function createSchematicTrace(trace, transform) {
2951
2977
  attributes: {
2952
2978
  class: "trace-crossing-outline",
2953
2979
  d: `M ${screenFromX} ${screenFromY} Q ${controlX} ${controlY} ${screenToX} ${screenToY}`,
2954
- stroke: colorMap.schematic.background,
2980
+ stroke: colorMap2.schematic.background,
2955
2981
  fill: "none",
2956
2982
  "stroke-width": `${getSchStrokeSize(transform) * 1.5}px`,
2957
2983
  "stroke-linecap": "round"
@@ -2964,7 +2990,7 @@ function createSchematicTrace(trace, transform) {
2964
2990
  type: "element",
2965
2991
  attributes: {
2966
2992
  d: `M ${screenFromX} ${screenFromY} Q ${controlX} ${controlY} ${screenToX} ${screenToY}`,
2967
- stroke: colorMap.schematic.wire,
2993
+ stroke: colorMap2.schematic.wire,
2968
2994
  fill: "none",
2969
2995
  "stroke-width": `${getSchStrokeSize(transform)}px`,
2970
2996
  "stroke-linecap": "round"
@@ -2980,7 +3006,7 @@ function createSchematicTrace(trace, transform) {
2980
3006
  attributes: {
2981
3007
  d: path,
2982
3008
  class: "trace-invisible-hover-outline",
2983
- stroke: colorMap.schematic.wire,
3009
+ stroke: colorMap2.schematic.wire,
2984
3010
  fill: "none",
2985
3011
  "stroke-width": `${getSchStrokeSize(transform) * 8}px`,
2986
3012
  "stroke-linecap": "round",
@@ -2995,7 +3021,7 @@ function createSchematicTrace(trace, transform) {
2995
3021
  type: "element",
2996
3022
  attributes: {
2997
3023
  d: path,
2998
- stroke: colorMap.schematic.wire,
3024
+ stroke: colorMap2.schematic.wire,
2999
3025
  fill: "none",
3000
3026
  "stroke-width": `${getSchStrokeSize(transform)}px`,
3001
3027
  "stroke-linecap": "round",
@@ -3018,7 +3044,7 @@ function createSchematicTrace(trace, transform) {
3018
3044
  cx: screenX.toString(),
3019
3045
  cy: screenY.toString(),
3020
3046
  r: (Math.abs(transform.a) * 0.03).toString(),
3021
- fill: colorMap.schematic.junction
3047
+ fill: colorMap2.schematic.junction
3022
3048
  },
3023
3049
  value: "",
3024
3050
  children: []
@@ -3883,7 +3909,11 @@ function getTextOffsets(pathRotation, transform) {
3883
3909
  }
3884
3910
 
3885
3911
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
3886
- var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransform) => {
3912
+ var createSvgObjectsForSchNetLabelWithSymbol = ({
3913
+ schNetLabel,
3914
+ realToScreenTransform,
3915
+ colorMap: colorMap2
3916
+ }) => {
3887
3917
  if (!schNetLabel.text) return [];
3888
3918
  const svgObjects = [];
3889
3919
  const symbol = symbols3[schNetLabel.symbol_name];
@@ -3999,7 +4029,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
3999
4029
  type: "element",
4000
4030
  attributes: {
4001
4031
  d: symbolPath + (path.closed ? " Z" : ""),
4002
- stroke: colorMap.schematic.component_outline,
4032
+ stroke: colorMap2.schematic.component_outline,
4003
4033
  fill: "none",
4004
4034
  "stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
4005
4035
  },
@@ -4031,7 +4061,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
4031
4061
  attributes: {
4032
4062
  x: offsetScreenPos.x.toString(),
4033
4063
  y: offsetScreenPos.y.toString(),
4034
- fill: colorMap.schematic.label_local,
4064
+ fill: colorMap2.schematic.label_local,
4035
4065
  "font-family": "sans-serif",
4036
4066
  "text-anchor": ninePointAnchorToTextAnchor2[text.anchor],
4037
4067
  "dominant-baseline": ninePointAnchorToDominantBaseline[text.anchor],
@@ -4089,7 +4119,7 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
4089
4119
  cy: screenCirclePos.y.toString(),
4090
4120
  r: (circle.radius * symbolToScreenScale).toString(),
4091
4121
  fill: "none",
4092
- stroke: colorMap.schematic.component_outline,
4122
+ stroke: colorMap2.schematic.component_outline,
4093
4123
  "stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
4094
4124
  },
4095
4125
  value: "",
@@ -4100,13 +4130,18 @@ var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransfo
4100
4130
  };
4101
4131
 
4102
4132
  // lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
4103
- var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
4133
+ var createSvgObjectsForSchNetLabel = ({
4134
+ schNetLabel,
4135
+ realToScreenTransform,
4136
+ colorMap: colorMap2
4137
+ }) => {
4104
4138
  if (!schNetLabel.text) return [];
4105
4139
  if (schNetLabel.symbol_name) {
4106
- return createSvgObjectsForSchNetLabelWithSymbol(
4140
+ return createSvgObjectsForSchNetLabelWithSymbol({
4107
4141
  schNetLabel,
4108
- realToScreenTransform
4109
- );
4142
+ realToScreenTransform,
4143
+ colorMap: colorMap2
4144
+ });
4110
4145
  }
4111
4146
  const svgObjects = [];
4112
4147
  const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
@@ -4184,8 +4219,8 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
4184
4219
  attributes: {
4185
4220
  class: "net-label",
4186
4221
  d: pathD,
4187
- fill: "#FFFFFF99",
4188
- stroke: colorMap.schematic.label_global,
4222
+ fill: colorMap2.schematic.label_background,
4223
+ stroke: colorMap2.schematic.label_global,
4189
4224
  "stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
4190
4225
  },
4191
4226
  value: "",
@@ -4214,7 +4249,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
4214
4249
  class: "net-label-text",
4215
4250
  x: screenTextPos.x.toString(),
4216
4251
  y: screenTextPos.y.toString(),
4217
- fill: colorMap.schematic.label_global,
4252
+ fill: colorMap2.schematic.label_global,
4218
4253
  "text-anchor": textAnchor,
4219
4254
  "dominant-baseline": "central",
4220
4255
  "font-family": "sans-serif",
@@ -4243,6 +4278,14 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4243
4278
  const realHeight = realBounds.maxY - realBounds.minY;
4244
4279
  const svgWidth = options?.width ?? 1200;
4245
4280
  const svgHeight = options?.height ?? 600;
4281
+ const colorOverrides = options?.colorOverrides;
4282
+ const colorMap2 = {
4283
+ ...colorMap,
4284
+ schematic: {
4285
+ ...colorMap.schematic,
4286
+ ...colorOverrides?.schematic ?? {}
4287
+ }
4288
+ };
4246
4289
  const circuitAspectRatio = realWidth / realHeight;
4247
4290
  const containerAspectRatio = svgWidth / svgHeight;
4248
4291
  let screenPaddingPx;
@@ -4300,25 +4343,51 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4300
4343
  for (const elm of circuitJson) {
4301
4344
  if (elm.type === "schematic_debug_object") {
4302
4345
  schDebugObjectSvgs.push(
4303
- ...createSvgObjectsFromSchDebugObject(elm, transform)
4346
+ ...createSvgObjectsFromSchDebugObject({
4347
+ debugObject: elm,
4348
+ transform
4349
+ })
4304
4350
  );
4305
4351
  } else if (elm.type === "schematic_component") {
4306
4352
  schComponentSvgs.push(
4307
4353
  ...createSvgObjectsFromSchematicComponent({
4308
4354
  component: elm,
4309
4355
  transform,
4310
- circuitJson
4356
+ circuitJson,
4357
+ colorMap: colorMap2
4311
4358
  })
4312
4359
  );
4313
4360
  } else if (elm.type === "schematic_trace") {
4314
- schTraceSvgs.push(...createSchematicTrace(elm, transform));
4361
+ schTraceSvgs.push(
4362
+ ...createSchematicTrace({
4363
+ trace: elm,
4364
+ transform,
4365
+ colorMap: colorMap2
4366
+ })
4367
+ );
4315
4368
  } else if (elm.type === "schematic_net_label") {
4316
- schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
4369
+ schNetLabel.push(
4370
+ ...createSvgObjectsForSchNetLabel({
4371
+ schNetLabel: elm,
4372
+ realToScreenTransform: transform,
4373
+ colorMap: colorMap2
4374
+ })
4375
+ );
4317
4376
  } else if (elm.type === "schematic_text" && !elm.schematic_component_id) {
4318
- schText.push(createSvgSchText(elm, transform));
4377
+ schText.push(
4378
+ createSvgSchText({
4379
+ elm,
4380
+ transform,
4381
+ colorMap: colorMap2
4382
+ })
4383
+ );
4319
4384
  } else if (elm.type === "schematic_voltage_probe") {
4320
4385
  voltageProbeSvgs.push(
4321
- ...createSvgObjectsFromSchVoltageProbe(elm, transform)
4386
+ ...createSvgObjectsFromSchVoltageProbe({
4387
+ probe: elm,
4388
+ transform,
4389
+ colorMap: colorMap2
4390
+ })
4322
4391
  );
4323
4392
  }
4324
4393
  }
@@ -4345,7 +4414,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4345
4414
  xmlns: "http://www.w3.org/2000/svg",
4346
4415
  width: svgWidth.toString(),
4347
4416
  height: svgHeight.toString(),
4348
- style: `background-color: ${colorMap.schematic.background}`,
4417
+ style: `background-color: ${colorMap2.schematic.background}`,
4349
4418
  "data-real-to-screen-transform": toSVG(transform)
4350
4419
  },
4351
4420
  children: [
@@ -4359,21 +4428,21 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
4359
4428
  // DO NOT USE THESE CLASSES!!!!
4360
4429
  // PUT STYLES IN THE SVG OBJECTS THEMSELVES
4361
4430
  value: `
4362
- .boundary { fill: ${colorMap.schematic.background}; }
4431
+ .boundary { fill: ${colorMap2.schematic.background}; }
4363
4432
  .schematic-boundary { fill: none; stroke: #fff; }
4364
- .component { fill: none; stroke: ${colorMap.schematic.component_outline}; }
4365
- .chip { fill: ${colorMap.schematic.component_body}; stroke: ${colorMap.schematic.component_outline}; }
4366
- .component-pin { fill: none; stroke: ${colorMap.schematic.component_outline}; }
4433
+ .component { fill: none; stroke: ${colorMap2.schematic.component_outline}; }
4434
+ .chip { fill: ${colorMap2.schematic.component_body}; stroke: ${colorMap2.schematic.component_outline}; }
4435
+ .component-pin { fill: none; stroke: ${colorMap2.schematic.component_outline}; }
4367
4436
  .trace:hover {
4368
4437
  filter: invert(1);
4369
4438
  }
4370
4439
  .trace:hover .trace-crossing-outline {
4371
4440
  opacity: 0;
4372
4441
  }
4373
- .text { font-family: sans-serif; fill: ${colorMap.schematic.wire}; }
4374
- .pin-number { fill: ${colorMap.schematic.pin_number}; }
4375
- .port-label { fill: ${colorMap.schematic.reference}; }
4376
- .component-name { fill: ${colorMap.schematic.reference}; }
4442
+ .text { font-family: sans-serif; fill: ${colorMap2.schematic.wire}; }
4443
+ .pin-number { fill: ${colorMap2.schematic.pin_number}; }
4444
+ .port-label { fill: ${colorMap2.schematic.reference}; }
4445
+ .component-name { fill: ${colorMap2.schematic.reference}; }
4377
4446
  `,
4378
4447
  name: "",
4379
4448
  attributes: {},