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