circuit-to-svg 0.0.227 → 0.0.229
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 +18 -2
- package/dist/index.js +179 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { AnyCircuitElement, PcbPort, SchematicComponent } from 'circuit-json';
|
|
|
2
2
|
import { Matrix } from 'transformation-matrix';
|
|
3
3
|
import { INode } from 'svgson';
|
|
4
4
|
|
|
5
|
+
interface PcbGridOptions {
|
|
6
|
+
cellSize: number;
|
|
7
|
+
lineColor?: string;
|
|
8
|
+
majorCellSize?: number;
|
|
9
|
+
majorLineColor?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
type CopperLayerName = "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
|
|
6
13
|
type CopperColorMap = Record<CopperLayerName, string> & {
|
|
7
14
|
[layer: string]: string;
|
|
@@ -44,6 +51,7 @@ interface Options$4 {
|
|
|
44
51
|
drawPaddingOutsideBoard?: boolean;
|
|
45
52
|
includeVersion?: boolean;
|
|
46
53
|
renderSolderMask?: boolean;
|
|
54
|
+
grid?: PcbGridOptions;
|
|
47
55
|
}
|
|
48
56
|
interface PcbContext {
|
|
49
57
|
transform: Matrix;
|
|
@@ -312,9 +320,17 @@ interface SimulationTransientVoltageGraphElement {
|
|
|
312
320
|
end_time_ms: number;
|
|
313
321
|
name?: string;
|
|
314
322
|
}
|
|
315
|
-
|
|
323
|
+
interface SimulationVoltageProbeElement {
|
|
324
|
+
type: "simulation_voltage_probe";
|
|
325
|
+
simulation_voltage_probe_id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
source_port_id?: string;
|
|
328
|
+
source_net_id?: string;
|
|
329
|
+
}
|
|
330
|
+
type CircuitJsonWithSimulation = AnyCircuitElement | SimulationExperimentElement | SimulationTransientVoltageGraphElement | SimulationVoltageProbeElement;
|
|
316
331
|
declare function isSimulationTransientVoltageGraph(value: CircuitJsonWithSimulation): value is SimulationTransientVoltageGraphElement;
|
|
317
332
|
declare function isSimulationExperiment(value: CircuitJsonWithSimulation): value is SimulationExperimentElement;
|
|
333
|
+
declare function isSimulationVoltageProbe(value: CircuitJsonWithSimulation): value is SimulationVoltageProbeElement;
|
|
318
334
|
|
|
319
335
|
interface ConvertSchematicSimulationParams {
|
|
320
336
|
circuitJson: CircuitJsonWithSimulation[];
|
|
@@ -356,4 +372,4 @@ declare const createSvgObjectsForSchComponentPortHovers: ({ component, transform
|
|
|
356
372
|
circuitJson: AnyCircuitElement[];
|
|
357
373
|
}) => INode[];
|
|
358
374
|
|
|
359
|
-
export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type CircuitJsonWithSimulation, type ColorMap, type ColorOverrides, type ExperimentType, type PcbColorMap, type PcbColorOverrides, type PcbContext, type PinoutLabel, type PinoutSvgContext, type SimulationExperimentElement, type SimulationTransientVoltageGraphElement, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToPinoutSvg, convertCircuitJsonToSchematicSimulationSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSimulationGraphSvg, convertCircuitJsonToSolderPasteMask, createSvgObjectsForSchComponentPortHovers, getSoftwareUsedString, isSimulationExperiment, isSimulationTransientVoltageGraph };
|
|
375
|
+
export { type AssemblySvgContext, CIRCUIT_TO_SVG_VERSION, type CircuitJsonWithSimulation, type ColorMap, type ColorOverrides, type ExperimentType, type PcbColorMap, type PcbColorOverrides, type PcbContext, type PinoutLabel, type PinoutSvgContext, type SimulationExperimentElement, type SimulationTransientVoltageGraphElement, type SimulationVoltageProbeElement, circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToAssemblySvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToPinoutSvg, convertCircuitJsonToSchematicSimulationSvg, convertCircuitJsonToSchematicSvg, convertCircuitJsonToSimulationGraphSvg, convertCircuitJsonToSolderPasteMask, createSvgObjectsForSchComponentPortHovers, getSoftwareUsedString, isSimulationExperiment, isSimulationTransientVoltageGraph, isSimulationVoltageProbe };
|
package/dist/index.js
CHANGED
|
@@ -1842,6 +1842,143 @@ function createSvgObjectsFromPcbCopperPour(pour, ctx) {
|
|
|
1842
1842
|
return [];
|
|
1843
1843
|
}
|
|
1844
1844
|
|
|
1845
|
+
// lib/pcb/svg-object-fns/create-svg-objects-for-pcb-grid.ts
|
|
1846
|
+
import "svgson";
|
|
1847
|
+
var DEFAULT_GRID_LINE_COLOR = "rgba(255, 255, 255, 0.5)";
|
|
1848
|
+
var GRID_PATTERN_ID = "pcb-grid-pattern";
|
|
1849
|
+
function createSvgObjectsForPcbGrid({
|
|
1850
|
+
grid,
|
|
1851
|
+
svgWidth,
|
|
1852
|
+
svgHeight
|
|
1853
|
+
}) {
|
|
1854
|
+
if (!grid) {
|
|
1855
|
+
return {};
|
|
1856
|
+
}
|
|
1857
|
+
const gridLineColor = grid.lineColor ?? DEFAULT_GRID_LINE_COLOR;
|
|
1858
|
+
const gridCellSize = grid.cellSize;
|
|
1859
|
+
const majorCellSize = grid.majorCellSize;
|
|
1860
|
+
const majorLineColor = grid.majorLineColor ?? gridLineColor;
|
|
1861
|
+
if (majorCellSize !== void 0) {
|
|
1862
|
+
if (!gridCellSize || gridCellSize <= 0) {
|
|
1863
|
+
throw new Error("grid.majorCellSize requires a positive grid.cellSize");
|
|
1864
|
+
}
|
|
1865
|
+
if (majorCellSize <= 0) {
|
|
1866
|
+
throw new Error(
|
|
1867
|
+
"grid.majorCellSize must be a positive multiple of grid.cellSize"
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
const ratio = majorCellSize / gridCellSize;
|
|
1871
|
+
const nearestInteger = Math.round(ratio);
|
|
1872
|
+
if (!Number.isFinite(ratio) || Math.abs(ratio - nearestInteger) > 1e-6) {
|
|
1873
|
+
throw new Error(
|
|
1874
|
+
"grid.majorCellSize must be a positive multiple of grid.cellSize"
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (!gridCellSize || gridCellSize <= 0) {
|
|
1879
|
+
return {};
|
|
1880
|
+
}
|
|
1881
|
+
const hasMajorGrid = majorCellSize !== void 0;
|
|
1882
|
+
const patternChildren = hasMajorGrid ? createMajorGridPatternChildren(
|
|
1883
|
+
gridCellSize,
|
|
1884
|
+
majorCellSize,
|
|
1885
|
+
gridLineColor,
|
|
1886
|
+
majorLineColor
|
|
1887
|
+
) : [
|
|
1888
|
+
{
|
|
1889
|
+
name: "path",
|
|
1890
|
+
type: "element",
|
|
1891
|
+
value: "",
|
|
1892
|
+
attributes: {
|
|
1893
|
+
d: `M ${gridCellSize} 0 L 0 0 0 ${gridCellSize}`,
|
|
1894
|
+
fill: "none",
|
|
1895
|
+
stroke: gridLineColor,
|
|
1896
|
+
"stroke-width": "1",
|
|
1897
|
+
"shape-rendering": "crispEdges"
|
|
1898
|
+
},
|
|
1899
|
+
children: []
|
|
1900
|
+
}
|
|
1901
|
+
];
|
|
1902
|
+
const defs = {
|
|
1903
|
+
name: "defs",
|
|
1904
|
+
type: "element",
|
|
1905
|
+
value: "",
|
|
1906
|
+
attributes: {},
|
|
1907
|
+
children: [
|
|
1908
|
+
{
|
|
1909
|
+
name: "pattern",
|
|
1910
|
+
type: "element",
|
|
1911
|
+
value: "",
|
|
1912
|
+
attributes: {
|
|
1913
|
+
id: GRID_PATTERN_ID,
|
|
1914
|
+
width: hasMajorGrid ? majorCellSize.toString() : gridCellSize.toString(),
|
|
1915
|
+
height: hasMajorGrid ? majorCellSize.toString() : gridCellSize.toString(),
|
|
1916
|
+
patternUnits: "userSpaceOnUse"
|
|
1917
|
+
},
|
|
1918
|
+
children: patternChildren
|
|
1919
|
+
}
|
|
1920
|
+
]
|
|
1921
|
+
};
|
|
1922
|
+
const rect = {
|
|
1923
|
+
name: "rect",
|
|
1924
|
+
type: "element",
|
|
1925
|
+
value: "",
|
|
1926
|
+
attributes: {
|
|
1927
|
+
x: "0",
|
|
1928
|
+
y: "0",
|
|
1929
|
+
width: svgWidth.toString(),
|
|
1930
|
+
height: svgHeight.toString(),
|
|
1931
|
+
fill: `url(#${GRID_PATTERN_ID})`,
|
|
1932
|
+
"pointer-events": "none",
|
|
1933
|
+
"data-type": "pcb_grid",
|
|
1934
|
+
"data-pcb-layer": "global"
|
|
1935
|
+
},
|
|
1936
|
+
children: []
|
|
1937
|
+
};
|
|
1938
|
+
return { defs, rect };
|
|
1939
|
+
}
|
|
1940
|
+
function createMajorGridPatternChildren(cellSize, majorCellSize, lineColor, majorLineColor) {
|
|
1941
|
+
const children = [];
|
|
1942
|
+
const steps = Math.round(majorCellSize / cellSize);
|
|
1943
|
+
for (let step = 0; step < steps; step += 1) {
|
|
1944
|
+
const offset = Number((step * cellSize).toFixed(6));
|
|
1945
|
+
const offsetString = offset.toString();
|
|
1946
|
+
const color = step === 0 ? majorLineColor : lineColor;
|
|
1947
|
+
const majorSizeString = majorCellSize.toString();
|
|
1948
|
+
children.push({
|
|
1949
|
+
name: "line",
|
|
1950
|
+
type: "element",
|
|
1951
|
+
value: "",
|
|
1952
|
+
attributes: {
|
|
1953
|
+
x1: offsetString,
|
|
1954
|
+
y1: "0",
|
|
1955
|
+
x2: offsetString,
|
|
1956
|
+
y2: majorSizeString,
|
|
1957
|
+
stroke: color,
|
|
1958
|
+
"stroke-width": "1",
|
|
1959
|
+
"shape-rendering": "crispEdges"
|
|
1960
|
+
},
|
|
1961
|
+
children: []
|
|
1962
|
+
});
|
|
1963
|
+
children.push({
|
|
1964
|
+
name: "line",
|
|
1965
|
+
type: "element",
|
|
1966
|
+
value: "",
|
|
1967
|
+
attributes: {
|
|
1968
|
+
x1: "0",
|
|
1969
|
+
y1: offsetString,
|
|
1970
|
+
x2: majorSizeString,
|
|
1971
|
+
y2: offsetString,
|
|
1972
|
+
stroke: color,
|
|
1973
|
+
"stroke-width": "1",
|
|
1974
|
+
"shape-rendering": "crispEdges"
|
|
1975
|
+
},
|
|
1976
|
+
children: []
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
return children;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1845
1982
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-component.ts
|
|
1846
1983
|
import { applyToPoint as applyToPoint19 } from "transformation-matrix";
|
|
1847
1984
|
function createSvgObjectsFromPcbComponent(component, ctx) {
|
|
@@ -1897,7 +2034,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
1897
2034
|
var package_default = {
|
|
1898
2035
|
name: "circuit-to-svg",
|
|
1899
2036
|
type: "module",
|
|
1900
|
-
version: "0.0.
|
|
2037
|
+
version: "0.0.228",
|
|
1901
2038
|
description: "Convert Circuit JSON to SVG",
|
|
1902
2039
|
main: "dist/index.js",
|
|
1903
2040
|
files: [
|
|
@@ -2176,30 +2313,41 @@ function convertCircuitJsonToPcbSvg(circuitJson, options) {
|
|
|
2176
2313
|
children: []
|
|
2177
2314
|
}
|
|
2178
2315
|
]
|
|
2179
|
-
},
|
|
2180
|
-
{
|
|
2181
|
-
name: "rect",
|
|
2182
|
-
type: "element",
|
|
2183
|
-
value: "",
|
|
2184
|
-
attributes: {
|
|
2185
|
-
class: "boundary",
|
|
2186
|
-
x: "0",
|
|
2187
|
-
y: "0",
|
|
2188
|
-
fill: options?.backgroundColor ?? "#000",
|
|
2189
|
-
width: svgWidth.toString(),
|
|
2190
|
-
height: svgHeight.toString(),
|
|
2191
|
-
"data-type": "pcb_background",
|
|
2192
|
-
"data-pcb-layer": "global"
|
|
2193
|
-
},
|
|
2194
|
-
children: []
|
|
2195
2316
|
}
|
|
2196
2317
|
];
|
|
2318
|
+
const gridObjects = createSvgObjectsForPcbGrid({
|
|
2319
|
+
grid: options?.grid,
|
|
2320
|
+
svgWidth,
|
|
2321
|
+
svgHeight
|
|
2322
|
+
});
|
|
2323
|
+
if (gridObjects.defs) {
|
|
2324
|
+
children.push(gridObjects.defs);
|
|
2325
|
+
}
|
|
2326
|
+
children.push({
|
|
2327
|
+
name: "rect",
|
|
2328
|
+
type: "element",
|
|
2329
|
+
value: "",
|
|
2330
|
+
attributes: {
|
|
2331
|
+
class: "boundary",
|
|
2332
|
+
x: "0",
|
|
2333
|
+
y: "0",
|
|
2334
|
+
fill: options?.backgroundColor ?? "#000",
|
|
2335
|
+
width: svgWidth.toString(),
|
|
2336
|
+
height: svgHeight.toString(),
|
|
2337
|
+
"data-type": "pcb_background",
|
|
2338
|
+
"data-pcb-layer": "global"
|
|
2339
|
+
},
|
|
2340
|
+
children: []
|
|
2341
|
+
});
|
|
2197
2342
|
if (drawPaddingOutsideBoard) {
|
|
2198
2343
|
children.push(
|
|
2199
2344
|
createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY)
|
|
2200
2345
|
);
|
|
2201
2346
|
}
|
|
2202
2347
|
children.push(...svgObjects);
|
|
2348
|
+
if (gridObjects.rect) {
|
|
2349
|
+
children.push(gridObjects.rect);
|
|
2350
|
+
}
|
|
2203
2351
|
const softwareUsedString = getSoftwareUsedString(circuitJson);
|
|
2204
2352
|
const version = CIRCUIT_TO_SVG_VERSION;
|
|
2205
2353
|
const svgObject = {
|
|
@@ -8336,6 +8484,9 @@ function isSimulationTransientVoltageGraph(value) {
|
|
|
8336
8484
|
function isSimulationExperiment(value) {
|
|
8337
8485
|
return value?.type === "simulation_experiment";
|
|
8338
8486
|
}
|
|
8487
|
+
function isSimulationVoltageProbe(value) {
|
|
8488
|
+
return value?.type === "simulation_voltage_probe";
|
|
8489
|
+
}
|
|
8339
8490
|
|
|
8340
8491
|
// lib/sim/convert-circuit-json-to-simulation-graph-svg.ts
|
|
8341
8492
|
var DEFAULT_WIDTH = 1200;
|
|
@@ -8362,7 +8513,7 @@ function convertCircuitJsonToSimulationGraphSvg({
|
|
|
8362
8513
|
`No simulation_transient_voltage_graph elements found for simulation_experiment_id "${simulation_experiment_id}"`
|
|
8363
8514
|
);
|
|
8364
8515
|
}
|
|
8365
|
-
const preparedGraphs = prepareSimulationGraphs(graphs);
|
|
8516
|
+
const preparedGraphs = prepareSimulationGraphs(graphs, circuitJson);
|
|
8366
8517
|
const allPoints = preparedGraphs.flatMap((entry) => entry.points);
|
|
8367
8518
|
if (allPoints.length === 0) {
|
|
8368
8519
|
throw new Error(
|
|
@@ -8438,13 +8589,19 @@ function convertCircuitJsonToSimulationGraphSvg({
|
|
|
8438
8589
|
);
|
|
8439
8590
|
return stringify5(svgObject);
|
|
8440
8591
|
}
|
|
8441
|
-
function prepareSimulationGraphs(graphs) {
|
|
8592
|
+
function prepareSimulationGraphs(graphs, circuitJson) {
|
|
8442
8593
|
const palette = Array.isArray(colorMap.palette) ? colorMap.palette : [];
|
|
8594
|
+
const voltageProbes = circuitJson.filter(isSimulationVoltageProbe);
|
|
8595
|
+
const probeIdToName = /* @__PURE__ */ new Map();
|
|
8596
|
+
for (const probe of voltageProbes) {
|
|
8597
|
+
probeIdToName.set(probe.simulation_voltage_probe_id, probe.name);
|
|
8598
|
+
}
|
|
8443
8599
|
return graphs.map((graph, index) => {
|
|
8444
8600
|
const points = createGraphPoints(graph);
|
|
8445
8601
|
const paletteColor = palette.length > 0 ? palette[index % palette.length] : FALLBACK_LINE_COLOR;
|
|
8446
8602
|
const color = paletteColor ?? FALLBACK_LINE_COLOR;
|
|
8447
|
-
const
|
|
8603
|
+
const probeName = graph.schematic_voltage_probe_id ? probeIdToName.get(graph.schematic_voltage_probe_id) : void 0;
|
|
8604
|
+
const label = graph.name || probeName || (graph.schematic_voltage_probe_id ? `Probe ${graph.schematic_voltage_probe_id}` : graph.simulation_transient_voltage_graph_id);
|
|
8448
8605
|
return { graph, points, color, label };
|
|
8449
8606
|
}).filter((entry) => entry.points.length > 0);
|
|
8450
8607
|
}
|
|
@@ -9261,6 +9418,7 @@ export {
|
|
|
9261
9418
|
createSvgObjectsForSchComponentPortHovers,
|
|
9262
9419
|
getSoftwareUsedString,
|
|
9263
9420
|
isSimulationExperiment,
|
|
9264
|
-
isSimulationTransientVoltageGraph
|
|
9421
|
+
isSimulationTransientVoltageGraph,
|
|
9422
|
+
isSimulationVoltageProbe
|
|
9265
9423
|
};
|
|
9266
9424
|
//# sourceMappingURL=index.js.map
|