circuit-json-to-tscircuit 0.0.2 → 0.0.3
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/.github/workflows/bun-pver-release.yml +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +104 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyCircuitElement, CircuitJson } from 'circuit-json';
|
|
2
|
+
|
|
3
|
+
interface ComponentTemplateParams {
|
|
4
|
+
pinLabels?: Record<string, string[]> | Record<string, string>;
|
|
5
|
+
componentName: string;
|
|
6
|
+
objUrl?: string;
|
|
7
|
+
circuitJson: AnyCircuitElement[];
|
|
8
|
+
supplierPartNumbers?: Record<string, string[]>;
|
|
9
|
+
manufacturerPartNumber?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare const convertCircuitJsonToTscircuit: (circuitJson: CircuitJson, opts: Omit<ComponentTemplateParams, "circuitJson">) => string;
|
|
13
|
+
|
|
14
|
+
export { convertCircuitJsonToTscircuit };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
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 { createUseComponent } from "@tscircuit/core"
|
|
65
|
+
import type { CommonLayoutProps } from "@tscircuit/props"
|
|
66
|
+
|
|
67
|
+
const pinLabels = ${JSON.stringify(pinLabels, null, " ")} as const
|
|
68
|
+
|
|
69
|
+
interface Props extends CommonLayoutProps {
|
|
70
|
+
name: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const ${componentName} = (props: Props) => {
|
|
74
|
+
return (
|
|
75
|
+
<chip
|
|
76
|
+
{...props}
|
|
77
|
+
${objUrl ? `cadModel={{
|
|
78
|
+
objUrl: "${objUrl}",
|
|
79
|
+
rotationOffset: { x: 0, y: 0, z: 0 },
|
|
80
|
+
positionOffset: { x: 0, y: 0, z: 0 },
|
|
81
|
+
}}` : ""}
|
|
82
|
+
${pinLabels ? `pinLabels={${JSON.stringify(pinLabels, null, " ")}}` : ""}
|
|
83
|
+
${supplierPartNumbers ? `supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}` : ""}
|
|
84
|
+
${manufacturerPartNumber ? `manufacturerPartNumber="${manufacturerPartNumber}"` : ""}
|
|
85
|
+
footprint={${footprintTsx}}
|
|
86
|
+
/>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const use${componentName} = createUseComponent(${componentName}, pinLabels)
|
|
91
|
+
|
|
92
|
+
`.trim();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// lib/index.ts
|
|
96
|
+
var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
97
|
+
return getComponentUsingTemplate({
|
|
98
|
+
circuitJson,
|
|
99
|
+
...opts
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
export {
|
|
103
|
+
convertCircuitJsonToTscircuit
|
|
104
|
+
};
|