circuit-json-to-tscircuit 0.0.81 → 0.0.82
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/{chunk-DD2WT5R6.js → chunk-QRKLAMFT.js} +39 -3
- package/dist/cli/main.js +2 -2
- package/dist/lib/index.js +1 -1
- package/lib/generate-board-schematic-tsx/convert-primitives.ts +1 -0
- package/lib/generate-board-schematic-tsx/convert-rect.ts +14 -1
- package/lib/get-schematic-using-template.ts +30 -0
- package/lib/index.ts +11 -0
- package/package.json +1 -1
- package/tests/__snapshots__/test29-standalone-ti-schematic-roundtrip-schematic-comparison.snap.svg +30 -0
- package/tests/standalone-schematic-dashed-rect.test.ts +46 -0
- package/tests/test29-standalone-ti-schematic-roundtrip.test.tsx +66 -0
|
@@ -166,6 +166,8 @@ var formatAttributes = (attributes) => Object.entries(attributes).filter(([, att
|
|
|
166
166
|
var formatElement = (tagName, attributes) => `<${tagName} ${formatAttributes(attributes)} />`;
|
|
167
167
|
|
|
168
168
|
// lib/generate-board-schematic-tsx/convert-rect.ts
|
|
169
|
+
var DEFAULT_SCHEMATIC_STROKE_WIDTH = 0.02;
|
|
170
|
+
var DASH_LENGTH_TO_STROKE_WIDTH_RATIO = 3;
|
|
169
171
|
var convertRect = ({
|
|
170
172
|
center,
|
|
171
173
|
width,
|
|
@@ -174,7 +176,8 @@ var convertRect = ({
|
|
|
174
176
|
strokeWidth,
|
|
175
177
|
color,
|
|
176
178
|
fillColor,
|
|
177
|
-
isFilled
|
|
179
|
+
isFilled,
|
|
180
|
+
isDashed
|
|
178
181
|
}) => {
|
|
179
182
|
const rectToSchematicTransform = compose(
|
|
180
183
|
translate(center.x, center.y),
|
|
@@ -187,12 +190,15 @@ var convertRect = ({
|
|
|
187
190
|
{ x: -width / 2, y: height / 2 },
|
|
188
191
|
{ x: -width / 2, y: -height / 2 }
|
|
189
192
|
].map((point) => applyToPoint(rectToSchematicTransform, point));
|
|
193
|
+
const dashLength = isDashed ? (strokeWidth ?? DEFAULT_SCHEMATIC_STROKE_WIDTH) * DASH_LENGTH_TO_STROKE_WIDTH_RATIO : void 0;
|
|
190
194
|
return formatElement("schematicpath", {
|
|
191
195
|
points,
|
|
192
196
|
strokeWidth,
|
|
193
197
|
strokeColor: color,
|
|
194
198
|
fillColor,
|
|
195
|
-
isFilled
|
|
199
|
+
isFilled,
|
|
200
|
+
dashLength,
|
|
201
|
+
dashGap: dashLength
|
|
196
202
|
});
|
|
197
203
|
};
|
|
198
204
|
|
|
@@ -458,7 +464,8 @@ var convertPrimitives = (circuitJson) => [
|
|
|
458
464
|
strokeWidth: element.stroke_width,
|
|
459
465
|
color: element.color,
|
|
460
466
|
fillColor: element.fill_color,
|
|
461
|
-
isFilled: element.is_filled
|
|
467
|
+
isFilled: element.is_filled,
|
|
468
|
+
isDashed: element.is_dashed
|
|
462
469
|
})
|
|
463
470
|
];
|
|
464
471
|
case "schematic_line":
|
|
@@ -2269,6 +2276,26 @@ ${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as con
|
|
|
2269
2276
|
`.replace(/\n\s*\n/g, "\n").trim();
|
|
2270
2277
|
};
|
|
2271
2278
|
|
|
2279
|
+
// lib/get-schematic-using-template.ts
|
|
2280
|
+
var getSchematicUsingTemplate = ({
|
|
2281
|
+
circuitJson,
|
|
2282
|
+
componentName
|
|
2283
|
+
}) => {
|
|
2284
|
+
const schematicElements = generateBoardSchematicElements(circuitJson);
|
|
2285
|
+
const schematicSheetTsx = generateBoardSchematicSheetTsx({
|
|
2286
|
+
circuitJson,
|
|
2287
|
+
schematicElements
|
|
2288
|
+
});
|
|
2289
|
+
return `
|
|
2290
|
+
${componentName ? `export const ${componentName} =` : "export default"} () => (
|
|
2291
|
+
<board routingDisabled>
|
|
2292
|
+
${schematicSheetTsx}
|
|
2293
|
+
</board>
|
|
2294
|
+
)
|
|
2295
|
+
${componentName ? `export default ${componentName}` : ""}
|
|
2296
|
+
`.replace(/\n\s*\n/g, "\n").trim();
|
|
2297
|
+
};
|
|
2298
|
+
|
|
2272
2299
|
// lib/index.ts
|
|
2273
2300
|
var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
2274
2301
|
const hasBoard = circuitJson.some((el) => el.type === "pcb_board");
|
|
@@ -2278,6 +2305,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
2278
2305
|
componentName: opts.componentName
|
|
2279
2306
|
});
|
|
2280
2307
|
}
|
|
2308
|
+
const hasSchematicSheet = circuitJson.some(
|
|
2309
|
+
(element) => element.type === "schematic_sheet"
|
|
2310
|
+
);
|
|
2311
|
+
if (hasSchematicSheet) {
|
|
2312
|
+
return getSchematicUsingTemplate({
|
|
2313
|
+
circuitJson,
|
|
2314
|
+
componentName: opts.componentName
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2281
2317
|
return getComponentUsingTemplate({
|
|
2282
2318
|
circuitJson,
|
|
2283
2319
|
...opts
|
package/dist/cli/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
convertCircuitJsonToTscircuit
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-QRKLAMFT.js";
|
|
5
5
|
|
|
6
6
|
// cli/main.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -16,7 +16,7 @@ var package_default = {
|
|
|
16
16
|
"./cli": "./dist/cli/main.js"
|
|
17
17
|
},
|
|
18
18
|
type: "module",
|
|
19
|
-
version: "0.0.
|
|
19
|
+
version: "0.0.81",
|
|
20
20
|
repository: {
|
|
21
21
|
type: "git",
|
|
22
22
|
url: "https://github.com/tscircuit/circuit-json-to-tscircuit.git"
|
package/dist/lib/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
} from "transformation-matrix"
|
|
7
7
|
import { formatElement } from "./format-attributes"
|
|
8
8
|
|
|
9
|
+
const DEFAULT_SCHEMATIC_STROKE_WIDTH = 0.02
|
|
10
|
+
const DASH_LENGTH_TO_STROKE_WIDTH_RATIO = 3
|
|
11
|
+
|
|
9
12
|
export const convertRect = ({
|
|
10
13
|
center,
|
|
11
14
|
width,
|
|
@@ -15,6 +18,7 @@ export const convertRect = ({
|
|
|
15
18
|
color,
|
|
16
19
|
fillColor,
|
|
17
20
|
isFilled,
|
|
21
|
+
isDashed,
|
|
18
22
|
}: {
|
|
19
23
|
center: { x: number; y: number }
|
|
20
24
|
width: number
|
|
@@ -24,6 +28,7 @@ export const convertRect = ({
|
|
|
24
28
|
color?: string
|
|
25
29
|
fillColor?: string
|
|
26
30
|
isFilled?: boolean
|
|
31
|
+
isDashed?: boolean
|
|
27
32
|
}) => {
|
|
28
33
|
const rectToSchematicTransform = compose(
|
|
29
34
|
translate(center.x, center.y),
|
|
@@ -36,12 +41,20 @@ export const convertRect = ({
|
|
|
36
41
|
{ x: -width / 2, y: height / 2 },
|
|
37
42
|
{ x: -width / 2, y: -height / 2 },
|
|
38
43
|
].map((point) => applyToPoint(rectToSchematicTransform, point))
|
|
39
|
-
|
|
44
|
+
const dashLength = isDashed
|
|
45
|
+
? (strokeWidth ?? DEFAULT_SCHEMATIC_STROKE_WIDTH) *
|
|
46
|
+
DASH_LENGTH_TO_STROKE_WIDTH_RATIO
|
|
47
|
+
: undefined
|
|
48
|
+
|
|
49
|
+
// Paths preserve the separate outline and fill colors used by imported
|
|
50
|
+
// rectangles. Explicit dash lengths retain the rectangle's dashed outline.
|
|
40
51
|
return formatElement("schematicpath", {
|
|
41
52
|
points,
|
|
42
53
|
strokeWidth,
|
|
43
54
|
strokeColor: color,
|
|
44
55
|
fillColor,
|
|
45
56
|
isFilled,
|
|
57
|
+
dashLength,
|
|
58
|
+
dashGap: dashLength,
|
|
46
59
|
})
|
|
47
60
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
2
|
+
import { generateBoardSchematicSheetTsx } from "./generate-board-schematic-sheet-tsx"
|
|
3
|
+
import { generateBoardSchematicElements } from "./generate-board-schematic-tsx"
|
|
4
|
+
|
|
5
|
+
export interface SchematicTemplateParams {
|
|
6
|
+
circuitJson: AnyCircuitElement[]
|
|
7
|
+
componentName?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getSchematicUsingTemplate = ({
|
|
11
|
+
circuitJson,
|
|
12
|
+
componentName,
|
|
13
|
+
}: SchematicTemplateParams): string => {
|
|
14
|
+
const schematicElements = generateBoardSchematicElements(circuitJson)
|
|
15
|
+
const schematicSheetTsx = generateBoardSchematicSheetTsx({
|
|
16
|
+
circuitJson,
|
|
17
|
+
schematicElements,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return `
|
|
21
|
+
${componentName ? `export const ${componentName} =` : "export default"} () => (
|
|
22
|
+
<board routingDisabled>
|
|
23
|
+
${schematicSheetTsx}
|
|
24
|
+
</board>
|
|
25
|
+
)
|
|
26
|
+
${componentName ? `export default ${componentName}` : ""}
|
|
27
|
+
`
|
|
28
|
+
.replace(/\n\s*\n/g, "\n")
|
|
29
|
+
.trim()
|
|
30
|
+
}
|
package/lib/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getComponentUsingTemplate,
|
|
5
5
|
type ComponentTemplateParams,
|
|
6
6
|
} from "./get-component-using-template"
|
|
7
|
+
import { getSchematicUsingTemplate } from "./get-schematic-using-template"
|
|
7
8
|
|
|
8
9
|
export const convertCircuitJsonToTscircuit = (
|
|
9
10
|
circuitJson: CircuitJson,
|
|
@@ -21,6 +22,16 @@ export const convertCircuitJsonToTscircuit = (
|
|
|
21
22
|
})
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
const hasSchematicSheet = circuitJson.some(
|
|
26
|
+
(element) => element.type === "schematic_sheet",
|
|
27
|
+
)
|
|
28
|
+
if (hasSchematicSheet) {
|
|
29
|
+
return getSchematicUsingTemplate({
|
|
30
|
+
circuitJson,
|
|
31
|
+
componentName: opts.componentName,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
return getComponentUsingTemplate({
|
|
25
36
|
circuitJson,
|
|
26
37
|
...opts,
|