circuit-to-svg 0.0.228 → 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 +8 -0
- package/dist/index.js +165 -17
- 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;
|
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 = {
|