@tscircuit/fabricator-drc 0.0.1

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/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @tscircuit/fabricator-drc
2
+
3
+ Fabricator-specific DRC checks for tscircuit. Install the provider through the
4
+ optional `platform.fabricatorEngine` interface:
5
+
6
+ ```tsx
7
+ import { RootCircuit } from "@tscircuit/core"
8
+ import { fabricatorEngine } from "@tscircuit/fabricator-drc"
9
+
10
+ const circuit = new RootCircuit({ platform: { fabricatorEngine } })
11
+ circuit.add(
12
+ <board width="10mm" height="10mm" fabricatorPreset="jlcpcb_economy">
13
+ <via name="V1" pcbX={0} pcbY={0} holeDiameter="0.25mm"
14
+ outerDiameter="0.6mm" fromLayer="top" toLayer="bottom" />
15
+ </board>,
16
+ )
17
+ await circuit.renderUntilSettled()
18
+ ```
19
+
20
+ Requires the fabricator engine integration in core and props. The package is
21
+ not yet published to npm.
22
+
23
+ ## Initial check
24
+
25
+ For `jlcpcb_economy`, `jlcpcb_standard`, `jlcpcb_economy_20260912`, and
26
+ `jlcpcb_standard_20260912`, via **hole diameters strictly below 0.3 mm** produce
27
+ one `pcb_fabricator_extra_charge_warning` per board with all affected via IDs.
28
+ Exactly 0.3 mm is allowed without this warning. Outer copper diameter does not
29
+ control this check. This records a surcharge warning, not a fabrication error,
30
+ and does not change via geometry or calculate a fee.
31
+
32
+ The spelling is `jlcpcb_economy`, matching the board prop. Unversioned presets
33
+ resolve to the 20260912 rules. Dated presets remain fixed; add a new dated
34
+ preset before changing rules. Unknown presets currently return no diagnostics.
35
+
36
+ ## Provider contract
37
+
38
+ `runDrcChecks({ circuitJson, fabricatorPreset, pcbBoardId })`
39
+ returns Circuit JSON diagnostic records. Core supplies the selected board's
40
+ subtree after routing; callers using the function directly must supply that
41
+ same scope. Circuit JSON positions and distances use millimeters in board world
42
+ coordinates (+X right, +Y up, +Z above). The function does not mutate its input.
43
+
44
+ Core inserts the returned records into the circuit. Omitted engines or presets,
45
+ `drcChecksDisabled`, and `pcbDisabled` prevent execution. Disabling autorouting
46
+ does not disable the check for manually placed vias.
47
+
48
+ ## Development
49
+
50
+ ```sh
51
+ bun install
52
+ bun test
53
+ bun run typecheck
54
+ bun run build
55
+ bun run format:check
56
+ ```
57
+
58
+ Preset rule data and diagnostic generation live in `lib/index.ts`. Add checks
59
+ with boundary tests and preserve dated preset behavior. CI validates tests,
60
+ types, build output, and formatting; npm publishing is not configured yet.
@@ -0,0 +1,25 @@
1
+ import { AnyCircuitElement, PcbBoard, PcbFabricatorExtraChargeWarning } from 'circuit-json';
2
+
3
+ interface FabricatorDrcParams {
4
+ /** Board subtree in Circuit JSON world coordinates: +X right, +Y up, +Z above; positions and distances in mm. */
5
+ circuitJson: AnyCircuitElement[];
6
+ fabricatorPreset: string;
7
+ pcbBoardId: PcbBoard["pcb_board_id"];
8
+ }
9
+ /** Dated presets keep fixed rules; unversioned names select the current rules. */
10
+ declare const fabricatorPresets: {
11
+ readonly jlcpcb_economy_20260912: {
12
+ readonly minimumViaHoleDiameterWithoutExtraCharge: 0.3;
13
+ };
14
+ readonly jlcpcb_standard_20260912: {
15
+ readonly minimumViaHoleDiameterWithoutExtraCharge: 0.3;
16
+ };
17
+ };
18
+ /** Generate surcharge diagnostics without modifying geometry or input records. */
19
+ declare function runDrcChecks({ circuitJson, fabricatorPreset, pcbBoardId, }: FabricatorDrcParams): PcbFabricatorExtraChargeWarning[];
20
+ /** Install as platform.fabricatorEngine in @tscircuit/core. */
21
+ declare const fabricatorEngine: {
22
+ runDrcChecks: typeof runDrcChecks;
23
+ };
24
+
25
+ export { type FabricatorDrcParams, fabricatorEngine, fabricatorPresets, runDrcChecks };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // lib/index.ts
2
+ import {
3
+ pcb_fabricator_extra_charge_warning
4
+ } from "circuit-json";
5
+ var fabricatorPresets = {
6
+ jlcpcb_economy_20260912: { minimumViaHoleDiameterWithoutExtraCharge: 0.3 },
7
+ jlcpcb_standard_20260912: { minimumViaHoleDiameterWithoutExtraCharge: 0.3 }
8
+ };
9
+ var presetAliases = {
10
+ jlcpcb_economy: "jlcpcb_economy_20260912",
11
+ jlcpcb_standard: "jlcpcb_standard_20260912"
12
+ };
13
+ function resolvePreset(name) {
14
+ const resolved = Object.hasOwn(presetAliases, name) ? presetAliases[name] : name;
15
+ return Object.hasOwn(fabricatorPresets, resolved) ? fabricatorPresets[resolved] : void 0;
16
+ }
17
+ function runDrcChecks({
18
+ circuitJson,
19
+ fabricatorPreset,
20
+ pcbBoardId
21
+ }) {
22
+ const preset = resolvePreset(fabricatorPreset);
23
+ if (!preset) return [];
24
+ const threshold = preset.minimumViaHoleDiameterWithoutExtraCharge;
25
+ const smallVias = circuitJson.filter((element) => element.type === "pcb_via").filter((via) => via.hole_diameter < threshold);
26
+ if (smallVias.length === 0) return [];
27
+ return [
28
+ pcb_fabricator_extra_charge_warning.parse({
29
+ type: "pcb_fabricator_extra_charge_warning",
30
+ fabricator_preset: fabricatorPreset,
31
+ pcb_board_id: pcbBoardId,
32
+ pcb_via_ids: smallVias.map((via) => via.pcb_via_id),
33
+ message: `${fabricatorPreset}: ${smallVias.length} via(s) have a hole diameter below ${threshold} mm and incur an extra fabrication charge. Use a hole diameter of at least ${threshold} mm to avoid this charge.`
34
+ })
35
+ ];
36
+ }
37
+ var fabricatorEngine = { runDrcChecks };
38
+ export {
39
+ fabricatorEngine,
40
+ fabricatorPresets,
41
+ runDrcChecks
42
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@tscircuit/fabricator-drc",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "Fabricator-specific Circuit JSON design rule checks",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/tscircuit/fabricator-drc"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "files": ["dist"],
14
+ "scripts": {
15
+ "test": "bun test",
16
+ "typecheck": "tsc --noEmit",
17
+ "build": "tsup lib/index.ts --format esm --dts",
18
+ "format:check": "biome format .",
19
+ "prepare": "bun run build",
20
+ "prepack": "bun run build"
21
+ },
22
+ "dependencies": {
23
+ "circuit-json": "^0.0.489",
24
+ "zod": "^3.25.76"
25
+ },
26
+ "devDependencies": {
27
+ "@biomejs/biome": "^1.9.4",
28
+ "@types/bun": "^1.2.16",
29
+ "tsup": "^8.5.0",
30
+ "typescript": "^5.9.3"
31
+ },
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }