circuit-json-to-tscircuit 0.0.7 → 0.0.8
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-X7PFGT53.js +93 -0
- package/dist/cli/main.js +8 -3327
- package/dist/lib/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-VMXWQPSP.js +0 -5744
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// lib/generate-footprint-tsx.tsx
|
|
2
|
+
import { mmStr } from "@tscircuit/mm";
|
|
3
|
+
import { su } from "@tscircuit/soup-util";
|
|
4
|
+
var generateFootprintTsx = (circuitJson) => {
|
|
5
|
+
const holes = su(circuitJson).pcb_hole.list();
|
|
6
|
+
const platedHoles = su(circuitJson).pcb_plated_hole.list();
|
|
7
|
+
const smtPads = su(circuitJson).pcb_smtpad.list();
|
|
8
|
+
const silkscreenPaths = su(circuitJson).pcb_silkscreen_path.list();
|
|
9
|
+
const elementStrings = [];
|
|
10
|
+
for (const hole of holes) {
|
|
11
|
+
if (hole.hole_shape === "circle") {
|
|
12
|
+
elementStrings.push(
|
|
13
|
+
`<hole pcbX="${mmStr(hole.x)}" pcbY="${mmStr(hole.y)}" diameter="${mmStr(hole.hole_diameter)}" />`
|
|
14
|
+
);
|
|
15
|
+
} else if (hole.hole_shape === "oval") {
|
|
16
|
+
console.warn("Unhandled oval hole in conversion (needs implementation)");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const platedHole of platedHoles) {
|
|
20
|
+
if (platedHole.shape === "oval" || platedHole.shape === "pill") {
|
|
21
|
+
elementStrings.push(
|
|
22
|
+
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerHeight="${mmStr(platedHole.outer_height)}" outerWidth="${mmStr(platedHole.outer_width)}" holeHeight="${mmStr(platedHole.hole_height)}" holeWidth="${mmStr(platedHole.hole_width)}" height="${mmStr(platedHole.hole_height)}" shape="${platedHole.shape}" />`
|
|
23
|
+
);
|
|
24
|
+
} else if (platedHole.shape === "circle") {
|
|
25
|
+
elementStrings.push(
|
|
26
|
+
`<platedhole portHints={${JSON.stringify(platedHole.port_hints)}} pcbX="${mmStr(platedHole.x)}" pcbY="${mmStr(platedHole.y)}" outerDiameter="${mmStr(platedHole.outer_diameter)}" holeDiameter="${mmStr(platedHole.hole_diameter)}" shape="circle" />`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const smtPad of smtPads) {
|
|
31
|
+
if (smtPad.shape === "circle") {
|
|
32
|
+
elementStrings.push(
|
|
33
|
+
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" radius="${mmStr(smtPad.radius)}" shape="circle" />`
|
|
34
|
+
);
|
|
35
|
+
} else if (smtPad.shape === "rect") {
|
|
36
|
+
elementStrings.push(
|
|
37
|
+
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" shape="rect" />`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const silkscreenPath of silkscreenPaths) {
|
|
42
|
+
elementStrings.push(
|
|
43
|
+
`<silkscreenpath route={${JSON.stringify(silkscreenPath.route)}} />`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return `
|
|
47
|
+
<footprint>
|
|
48
|
+
${elementStrings.join("\n")}
|
|
49
|
+
</footprint>
|
|
50
|
+
`.trim();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// lib/get-component-using-template.ts
|
|
54
|
+
var getComponentUsingTemplate = ({
|
|
55
|
+
pinLabels,
|
|
56
|
+
componentName,
|
|
57
|
+
objUrl,
|
|
58
|
+
circuitJson,
|
|
59
|
+
supplierPartNumbers,
|
|
60
|
+
manufacturerPartNumber
|
|
61
|
+
}) => {
|
|
62
|
+
const footprintTsx = generateFootprintTsx(circuitJson);
|
|
63
|
+
return `
|
|
64
|
+
import { type ChipProps } from "tscircuit"
|
|
65
|
+
${pinLabels ? `const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as const
|
|
66
|
+
` : ""}export const ${componentName} = (props: ChipProps${pinLabels ? `<typeof pinLabels>` : ""}) => (
|
|
67
|
+
<chip
|
|
68
|
+
footprint={${footprintTsx}}
|
|
69
|
+
${pinLabels ? "pinLabels={pinLabels}" : ""}
|
|
70
|
+
${objUrl ? `cadModel={{
|
|
71
|
+
objUrl: "${objUrl}",
|
|
72
|
+
rotationOffset: { x: 0, y: 0, z: 0 },
|
|
73
|
+
positionOffset: { x: 0, y: 0, z: 0 },
|
|
74
|
+
}}` : ""}
|
|
75
|
+
${supplierPartNumbers ? `supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}` : ""}
|
|
76
|
+
${manufacturerPartNumber ? `manufacturerPartNumber="${manufacturerPartNumber}"` : ""}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
)
|
|
80
|
+
`.replace(/\n\s*\n/g, "\n").trim();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// lib/index.ts
|
|
84
|
+
var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
85
|
+
return getComponentUsingTemplate({
|
|
86
|
+
circuitJson,
|
|
87
|
+
...opts
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
convertCircuitJsonToTscircuit
|
|
93
|
+
};
|