@bitbybit-dev/create-app 1.3.2 → 1.4.0-rc.0
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 +47 -124
- package/dist/index.js +253 -21
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +107 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +4 -3
- package/src/index.test.ts +309 -8
- package/src/index.ts +285 -24
- package/src/scaffold.test.ts +177 -0
- package/src/scaffold.ts +99 -0
- package/templates/_agent/AGENTS.md +39 -0
- package/templates/_agent/CLAUDE.md +1 -0
- package/templates/_agent/_dot-cursor/mcp.json +5 -0
- package/templates/_agent/_dot-gitignore +7 -0
- package/templates/_agent/_dot-mcp.json +5 -0
- package/templates/_agent/_dot-vscode/mcp.json +5 -0
- package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
- package/templates/apps/drone-assembly/README.md +35 -0
- package/templates/apps/drone-assembly/eslint.config.js +47 -0
- package/templates/apps/drone-assembly/index.html +17 -0
- package/templates/apps/drone-assembly/package.json +31 -0
- package/templates/apps/drone-assembly/public/favicon.ico +0 -0
- package/templates/apps/drone-assembly/public/logo.png +0 -0
- package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
- package/templates/apps/drone-assembly/src/assembly.ts +99 -0
- package/templates/apps/drone-assembly/src/exports.ts +10 -0
- package/templates/apps/drone-assembly/src/kernel.ts +14 -0
- package/templates/apps/drone-assembly/src/main.ts +298 -0
- package/templates/apps/drone-assembly/src/materials.ts +58 -0
- package/templates/apps/drone-assembly/src/model.ts +280 -0
- package/templates/apps/drone-assembly/src/parts.ts +343 -0
- package/templates/apps/drone-assembly/src/style.css +219 -0
- package/templates/apps/drone-assembly/src/ui.ts +180 -0
- package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
- package/templates/apps/drone-assembly/tsconfig.json +29 -0
- package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
- package/templates/apps/laser-cut-box/README.md +34 -0
- package/templates/apps/laser-cut-box/eslint.config.js +47 -0
- package/templates/apps/laser-cut-box/index.html +17 -0
- package/templates/apps/laser-cut-box/package.json +30 -0
- package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
- package/templates/apps/laser-cut-box/public/logo.png +0 -0
- package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
- package/templates/apps/laser-cut-box/src/exports.ts +28 -0
- package/templates/apps/laser-cut-box/src/main.ts +176 -0
- package/templates/apps/laser-cut-box/src/model.ts +92 -0
- package/templates/apps/laser-cut-box/src/panels.ts +229 -0
- package/templates/apps/laser-cut-box/src/style.css +223 -0
- package/templates/apps/laser-cut-box/src/ui.ts +136 -0
- package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
- package/templates/apps/laser-cut-box/tsconfig.json +29 -0
- package/templates/apps/product-configurator/AGENTS.section.md +19 -0
- package/templates/apps/product-configurator/README.md +33 -0
- package/templates/apps/product-configurator/eslint.config.js +47 -0
- package/templates/apps/product-configurator/index.html +17 -0
- package/templates/apps/product-configurator/package.json +30 -0
- package/templates/apps/product-configurator/public/favicon.ico +0 -0
- package/templates/apps/product-configurator/public/logo.png +0 -0
- package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
- package/templates/apps/product-configurator/src/catalog.ts +56 -0
- package/templates/apps/product-configurator/src/exports.ts +19 -0
- package/templates/apps/product-configurator/src/main.ts +134 -0
- package/templates/apps/product-configurator/src/model.ts +153 -0
- package/templates/apps/product-configurator/src/style.css +177 -0
- package/templates/apps/product-configurator/src/ui.ts +150 -0
- package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
- package/templates/apps/product-configurator/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
- package/templates/apps/sheet-metal-unfold/README.md +41 -0
- package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
- package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
- package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
- package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
- package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
- package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
- package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
- package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
- package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
- package/templates/apps/sheet-metal-unfold/package.json +18 -0
- package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
- package/templates/apps/step-to-gltf-cli/README.md +34 -0
- package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
- package/templates/apps/step-to-gltf-cli/package.json +26 -0
- package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
- package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
- package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
- package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
- package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
- package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
- package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
- package/templates/cloud/AGENTS.section.md +22 -0
- package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
- package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
- package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
- package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-rest/package.json +11 -4
- package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
- package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
- package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
- package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-sdk/package.json +12 -5
- package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
- package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
- package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
- package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-rest/package.json +12 -5
- package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
- package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
- package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
- package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
- package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
- package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
- package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
- package/templates/cloud/frontend/eslint.config.js +50 -0
- package/templates/cloud/frontend/index.html +3 -1
- package/templates/cloud/frontend/package.json +13 -4
- package/templates/cloud/frontend/public/favicon.ico +0 -0
- package/templates/cloud/frontend/public/logo.png +0 -0
- package/templates/cloud/frontend/src/App.tsx +11 -9
- package/templates/cloud/frontend/src/api.ts +31 -0
- package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
- package/templates/cloud/frontend/src/components/Header.tsx +4 -2
- package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
- package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
- package/templates/cloud/frontend/src/main.tsx +6 -1
- package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
- package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
- package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
- package/templates/cloud/frontend/tsconfig.json +19 -7
- package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
- package/templates/vite/babylonjs/typescript/index.html +4 -2
- package/templates/vite/babylonjs/typescript/package.json +14 -4
- package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
- package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
- package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
- package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
- package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
- package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
- package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
- package/templates/vite/playcanvas/typescript/index.html +4 -2
- package/templates/vite/playcanvas/typescript/package.json +14 -4
- package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
- package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
- package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
- package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
- package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
- package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/threejs/typescript/eslint.config.js +47 -0
- package/templates/vite/threejs/typescript/index.html +4 -2
- package/templates/vite/threejs/typescript/package.json +16 -6
- package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
- package/templates/vite/threejs/typescript/public/logo.png +0 -0
- package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/threejs/typescript/src/main.ts +11 -22
- package/templates/vite/threejs/typescript/src/model.ts +24 -0
- package/templates/vite/threejs/typescript/tsconfig.json +16 -12
- package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
- package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
- package/templates/vite/threejs/typescript/public/vite.svg +0 -1
- /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { Bom } from "./assembly";
|
|
2
|
+
import { FINISHES, type FinishId } from "./materials";
|
|
3
|
+
import { ARM_COUNTS, LIMITS, UNITS, maxPropDiameter, type ArmCount, type DroneParams } from "./model";
|
|
4
|
+
|
|
5
|
+
type SliderKey = keyof typeof LIMITS;
|
|
6
|
+
|
|
7
|
+
const SLIDERS: { key: SliderKey; label: string }[] = [
|
|
8
|
+
{ key: "armLength", label: `Arm length (${UNITS})` },
|
|
9
|
+
{ key: "propDiameter", label: `Propeller diameter (${UNITS})` },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export type ExportFormat = "step" | "glb";
|
|
13
|
+
|
|
14
|
+
export const ROTOR_RPM = { min: 0, max: 360, step: 10, initial: 240 } as const;
|
|
15
|
+
|
|
16
|
+
export interface UiHandlers {
|
|
17
|
+
onChange: (params: DroneParams) => void;
|
|
18
|
+
onSpeed: (rpm: number) => void;
|
|
19
|
+
onEdges: (visible: boolean) => void;
|
|
20
|
+
onExport: (format: ExportFormat) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface UiHandle {
|
|
24
|
+
setParams: (params: DroneParams) => void;
|
|
25
|
+
setBom: (bom: Bom, bolts: number) => void;
|
|
26
|
+
setStatus: (text: string) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function mountPoint(id: string): HTMLElement {
|
|
30
|
+
const element = document.getElementById(id);
|
|
31
|
+
if (!element) throw new Error(`index.html has no #${id} element to mount the panel in`);
|
|
32
|
+
return element;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function query<T extends Element>(root: ParentNode, selector: string, kind: new () => T): T {
|
|
36
|
+
const found = root.querySelector(selector);
|
|
37
|
+
if (!(found instanceof kind)) throw new Error(`the panel markup has no ${selector} element of the expected kind`);
|
|
38
|
+
return found;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function mountUi(root: HTMLElement, initial: DroneParams, handlers: UiHandlers): UiHandle {
|
|
42
|
+
let params = { ...initial };
|
|
43
|
+
const outputs = new Map<SliderKey, HTMLOutputElement>();
|
|
44
|
+
const sliders = new Map<SliderKey, HTMLInputElement>();
|
|
45
|
+
|
|
46
|
+
root.innerHTML = `
|
|
47
|
+
<header class="brand"><img src="/logo.png" alt="bitbybit.dev" /><h1>Drone assembly</h1></header>
|
|
48
|
+
<p class="lead">Twenty-seven parts, placed as instances through sub-assemblies. Change the arms and only the placements change.</p>
|
|
49
|
+
<div class="field"><label>Arms</label><span></span><div class="segments"></div></div>
|
|
50
|
+
<form class="fields"></form>
|
|
51
|
+
<p class="note"></p>
|
|
52
|
+
<div class="field speed">
|
|
53
|
+
<label for="speed">Rotor speed (rpm, 0 lands)</label>
|
|
54
|
+
<output>${ROTOR_RPM.initial}</output>
|
|
55
|
+
<input type="range" id="speed" name="speed" min="${ROTOR_RPM.min}" max="${ROTOR_RPM.max}" step="${ROTOR_RPM.step}" value="${ROTOR_RPM.initial}" />
|
|
56
|
+
</div>
|
|
57
|
+
<div class="toggles">
|
|
58
|
+
<label><input type="checkbox" name="edges" checked /> Edges</label>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="bom">
|
|
61
|
+
<div class="bom-title"><span>Bill of materials</span><span class="bom-totals">-</span></div>
|
|
62
|
+
<table><tbody></tbody></table>
|
|
63
|
+
</div>
|
|
64
|
+
<div class="exports">
|
|
65
|
+
<button type="button" data-format="step">STEP assembly</button>
|
|
66
|
+
<button type="button" data-format="glb">GLB</button>
|
|
67
|
+
</div>
|
|
68
|
+
<p class="status"></p>
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const segments = query(root, ".segments", HTMLElement);
|
|
72
|
+
const armButtons = new Map<ArmCount, HTMLButtonElement>();
|
|
73
|
+
for (const count of ARM_COUNTS) {
|
|
74
|
+
const button = document.createElement("button");
|
|
75
|
+
button.type = "button";
|
|
76
|
+
button.textContent = String(count);
|
|
77
|
+
button.addEventListener("click", () => {
|
|
78
|
+
params = { ...params, arms: count };
|
|
79
|
+
syncInputs();
|
|
80
|
+
handlers.onChange(params);
|
|
81
|
+
});
|
|
82
|
+
segments.appendChild(button);
|
|
83
|
+
armButtons.set(count, button);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const form = query(root, ".fields", HTMLFormElement);
|
|
87
|
+
form.addEventListener("submit", (event) => { event.preventDefault(); });
|
|
88
|
+
for (const field of SLIDERS) {
|
|
89
|
+
const limit = LIMITS[field.key];
|
|
90
|
+
const wrapper = document.createElement("div");
|
|
91
|
+
wrapper.className = "field";
|
|
92
|
+
const label = document.createElement("label");
|
|
93
|
+
label.textContent = field.label;
|
|
94
|
+
label.htmlFor = field.key;
|
|
95
|
+
const output = document.createElement("output");
|
|
96
|
+
const input = document.createElement("input");
|
|
97
|
+
input.type = "range";
|
|
98
|
+
input.id = field.key;
|
|
99
|
+
input.min = String(limit.min);
|
|
100
|
+
input.max = String(limit.max);
|
|
101
|
+
input.step = String(limit.step);
|
|
102
|
+
input.addEventListener("input", () => {
|
|
103
|
+
params = { ...params, [field.key]: Number(input.value) };
|
|
104
|
+
output.value = input.value;
|
|
105
|
+
handlers.onChange(params);
|
|
106
|
+
});
|
|
107
|
+
wrapper.append(label, output, input);
|
|
108
|
+
form.appendChild(wrapper);
|
|
109
|
+
outputs.set(field.key, output);
|
|
110
|
+
sliders.set(field.key, input);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const finishWrapper = document.createElement("div");
|
|
114
|
+
finishWrapper.className = "field";
|
|
115
|
+
const finishLabel = document.createElement("label");
|
|
116
|
+
finishLabel.textContent = "Finish";
|
|
117
|
+
finishLabel.htmlFor = "finish";
|
|
118
|
+
const finishSelect = document.createElement("select");
|
|
119
|
+
finishSelect.id = "finish";
|
|
120
|
+
for (const [id, finish] of Object.entries(FINISHES)) {
|
|
121
|
+
const option = document.createElement("option");
|
|
122
|
+
option.value = id;
|
|
123
|
+
option.textContent = finish.label;
|
|
124
|
+
finishSelect.appendChild(option);
|
|
125
|
+
}
|
|
126
|
+
finishSelect.addEventListener("change", () => {
|
|
127
|
+
params = { ...params, finish: finishSelect.value as FinishId };
|
|
128
|
+
handlers.onChange(params);
|
|
129
|
+
});
|
|
130
|
+
finishWrapper.append(finishLabel, document.createElement("span"), finishSelect);
|
|
131
|
+
form.appendChild(finishWrapper);
|
|
132
|
+
|
|
133
|
+
const speed = query(root, "input[name=speed]", HTMLInputElement);
|
|
134
|
+
const speedOutput = query(root, ".speed output", HTMLOutputElement);
|
|
135
|
+
speed.addEventListener("input", () => {
|
|
136
|
+
speedOutput.value = speed.value;
|
|
137
|
+
handlers.onSpeed(Number(speed.value));
|
|
138
|
+
});
|
|
139
|
+
const edges = query(root, "input[name=edges]", HTMLInputElement);
|
|
140
|
+
edges.addEventListener("change", () => { handlers.onEdges(edges.checked); });
|
|
141
|
+
|
|
142
|
+
for (const button of root.querySelectorAll<HTMLButtonElement>(".exports button")) {
|
|
143
|
+
button.addEventListener("click", () => { handlers.onExport(button.dataset["format"] as ExportFormat); });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const note = query(root, ".note", HTMLElement);
|
|
147
|
+
const totals = query(root, ".bom-totals", HTMLElement);
|
|
148
|
+
const rows = query(root, ".bom tbody", HTMLElement);
|
|
149
|
+
const status = query(root, ".status", HTMLElement);
|
|
150
|
+
|
|
151
|
+
function syncInputs(): void {
|
|
152
|
+
for (const [key, slider] of sliders) slider.value = String(params[key]);
|
|
153
|
+
for (const [key, output] of outputs) output.value = String(params[key]);
|
|
154
|
+
for (const [count, button] of armButtons) button.classList.toggle("active", count === params.arms);
|
|
155
|
+
finishSelect.value = params.finish;
|
|
156
|
+
const largest = maxPropDiameter(params.arms, params.armLength);
|
|
157
|
+
note.textContent = params.propDiameter >= largest
|
|
158
|
+
? `Propellers are limited to ${largest} ${UNITS} here so their tips clear each other and the canopy.`
|
|
159
|
+
: "";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
syncInputs();
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
setParams: (next) => { params = { ...next }; syncInputs(); },
|
|
166
|
+
setBom: (bom, bolts) => {
|
|
167
|
+
totals.textContent = `${bom.parts} parts, ${bom.instances} placed, ${bolts} bolts`;
|
|
168
|
+
rows.replaceChildren(...bom.rows.map((row) => {
|
|
169
|
+
const tr = document.createElement("tr");
|
|
170
|
+
const name = document.createElement("td");
|
|
171
|
+
name.textContent = row.name;
|
|
172
|
+
const count = document.createElement("td");
|
|
173
|
+
count.textContent = `x${row.count}`;
|
|
174
|
+
tr.append(name, count);
|
|
175
|
+
return tr;
|
|
176
|
+
}));
|
|
177
|
+
},
|
|
178
|
+
setStatus: (text) => { status.textContent = text; },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"moduleDetection": "force",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"exactOptionalPropertyTypes": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noImplicitOverride": true,
|
|
16
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"useUnknownInCatchVariables": true,
|
|
21
|
+
"forceConsistentCasingInFileNames": true,
|
|
22
|
+
"isolatedModules": true,
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
24
|
+
"erasableSyntaxOnly": true,
|
|
25
|
+
"noUncheckedSideEffectImports": true,
|
|
26
|
+
"skipLibCheck": true
|
|
27
|
+
},
|
|
28
|
+
"include": ["src", "scripts"]
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## This template: laser-cut box
|
|
2
|
+
|
|
3
|
+
A finger-jointed box or enclosure cut from one sheet: the customer sets the outer dimensions, the sheet thickness, the laser's kerf and the finger width, toggles the lid, and gets the assembled box in 3D, the cutting layout on the sheet, and the layout as DXF or SVG plus the box as STEP.
|
|
4
|
+
|
|
5
|
+
- `src/panels.ts` is the geometry that needs no kernel: which panels the box has and the joint on each edge (`panelSpecs`), the outline of a panel as a closed polygon with the fingers, the slots and the kerf compensation worked in (`outlineFor`; `tidy` then removes repeated points and zero-width spikes cyclically, a spike being where the walk goes to a point and straight back, as happens where an edge ends flush and the next starts with a slot), the lid's finger-hole handle where the lid has room for it with its clearance to the fingers (`handleFor`, `HANDLE`, `slotArea`), the parts with their sizes (`partsFor`), and the row packing onto the sheet (`layoutParts`, `partsOverlap`). It is pure, so a change to the joint logic is testable by reading the points.
|
|
6
|
+
- `src/model.ts` is the kernel side. `buildModel(occt, params)` turns every outline into a planar face on the ground plane (the lid's handle as a hole in it, a rectangle rounded to a stadium, turned to run against the outline with `faceWithHole` because the kernel cuts only from an inner wire running the other way), translates a copy onto the sheet for the layout (the DXF is written from that face), extrudes that copy into a slab lifted one millimetre above the ground for the layout view (`LAYOUT_LIFT`, so the parts and the sheet outline never fight the ground plane for pixels), and extrudes another and rotates and moves it into its place in the assembled box. Faces are made on the ground plane (X and Z) because that is the plane `occt.io.shapeToDxfPaths` flattens into a drawing.
|
|
7
|
+
- `src/exports.ts` writes the layout SVG straight from the outlines, the handle as a rounded rectangle. DXF and STEP come from the kernel in `src/main.ts` (`shapeToDxfPaths`, `dxfPathsWithLayer`, `dxfCreate`; `makeCompound`, `saveShapeSTEP` converted to Z-up).
|
|
8
|
+
- `src/ui.ts` renders the panel with plain DOM; `src/main.ts` is the wiring: scene, kernel, debounced rebuilds, the two views, the downloads, one birch plywood material per panel under a room environment with the laser's brown on the cut edges. `cameraOptions` gives the orbit camera explicit distance limits from the scene size and leaves its sensitivities at their base values: the engine's defaults scale zoom and pan by the scene size although both already follow the camera's distance, so a scene this large would jump a third of the way in per wheel notch.
|
|
9
|
+
- `scripts/smoke.ts` builds the default box and three variants (no kerf, no lid, tall) on the in-process kernel and prints one JSON line with `template`, `params` and, per case, `parts`, `fingers` per panel, `dxfPaths` per panel, `layout` (fits, used width and height), `handle`, `materialVolume` and `jointsClosed`. It exits 1 when the part count is not five or six, a part is not one planar face, a part yields no DXF path, two parts overlap on the sheet, the assembled box does not span the declared length by height by width, or, with the kerf at zero, the panels do not tile the hollow box: their volumes must add up to the outer block minus the cavity and minus the handle (`hollowBox` in the output) and no two panels may share any volume, which together mean every finger fills its slot and nothing is doubled. The kernel is loaded in-process from `node_modules`, the same WebAssembly the browser runs inside a worker; its content-hashed `.wasm` is found beside the loader rather than spelled out.
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
|
|
13
|
+
- `npm run dev` serves the app at http://localhost:5173
|
|
14
|
+
- `npm run build` typechecks and bundles for production; `npm run typecheck` and `npm run lint` run alone as well
|
|
15
|
+
- `npm run smoke` typechecks, lints, then builds the cases headlessly and prints the summary line. The smoke script types the in-process kernel as the same `Occt` the browser code sees, through one `inProcess` cast, and awaits every call, so `buildModel` runs exactly as it does in the browser and `scripts/` is typechecked with the rest.
|
|
16
|
+
|
|
17
|
+
The joint rule: a `fingers` edge grows fingers one thickness beyond the panel's nominal edge, the `slots` edge it meets is cut one thickness deep at the same positions, and each edge has an odd number of segments (at least three) near the finger width, so both ends of an edge are the same kind and the pattern reads the same from either panel. The bottom and the lid have fingers on all four edges; the front and back have fingers on their vertical edges; the sides have slots everywhere. Kerf compensation moves every outline outward by half the kerf, widening fingers and narrowing slots by that much, so the cut part comes out at the nominal size. Change the rule in `panelSpecs` and `outlineFor` only, then run the smoke: the tiling check is what proves the joints still close.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
A finger-jointed box generator for laser cutting, built on the open-source [Bitbybit](https://bitbybit.dev) CAD packages and Three.js. Set the outer dimensions, the sheet thickness, your laser's kerf and the finger width, toggle the lid (it gets a finger-hole handle when it has room), and download the cutting layout as DXF or SVG or the assembled box as STEP. Everything runs in the browser; no account, key or server is involved.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install
|
|
7
|
+
npm run dev # http://localhost:5173
|
|
8
|
+
npm run smoke # typecheck, lint, then four boxes built headlessly in Node with the joints checked
|
|
9
|
+
npm run lint # the lint rules, at error
|
|
10
|
+
npm run build # typecheck and bundle for production
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## How it is put together
|
|
14
|
+
|
|
15
|
+
| File | Role |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `src/panels.ts` | the panels, their joints, the finger outlines with kerf compensation, and the sheet layout; pure functions, no kernel |
|
|
18
|
+
| `src/model.ts` | `buildModel(occt, params)`: every outline as a planar face, laid out on the sheet, and as a solid in the assembled box |
|
|
19
|
+
| `src/exports.ts` | the layout as SVG, written from the outlines |
|
|
20
|
+
| `src/ui.ts` | the panel: sliders, the lid toggle, the two views, the facts, the export buttons |
|
|
21
|
+
| `src/main.ts` | the wiring: scene, kernel, debounced rebuilds, DXF and STEP through the kernel |
|
|
22
|
+
| `scripts/smoke.ts` | the headless check: part counts, planar parts, DXF paths, no overlaps on the sheet, the box's extents, and that the panels tile the hollow box exactly, so every finger fills its slot |
|
|
23
|
+
|
|
24
|
+
The outline of a panel is computed once, in plain TypeScript, and used three times: as the face the laser cuts, positioned on the sheet for the layout, and extruded and placed for the 3D preview. The smoke's tiling check is the proof that the joint arithmetic is right: with the kerf at zero, panels that interlock perfectly add up to exactly the hollow box's volume and share none of it.
|
|
25
|
+
|
|
26
|
+
## Make it your product
|
|
27
|
+
|
|
28
|
+
Change the joint rule in `src/panels.ts` (`panelSpecs` decides which edges get fingers and which get slots; `outlineFor` draws them), add dividers or holes as further panels or as cuts in `src/model.ts`, and adjust the fields in `src/ui.ts`. Keep the smoke green while you do: it fails the moment the joints stop closing.
|
|
29
|
+
|
|
30
|
+
## Working with an AI agent
|
|
31
|
+
|
|
32
|
+
`AGENTS.md` explains the project to a coding agent, and the free Bitbybit CAD MCP server is configured for Claude Code, Cursor and VS Code, so the agent looks the API up instead of guessing it. Ask it for a divider or a hinge slot, then let it run `npm run smoke`.
|
|
33
|
+
|
|
34
|
+
Scaffolded by `@bitbybit-dev/create-app` {{CLI_VERSION}}. [Documentation](https://learn.bitbybit.dev), [the packages](https://github.com/bitbybit-dev/bitbybit), [Discord](https://discord.gg/GSe3VMe).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import eslint from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
import noComments from "eslint-plugin-no-comments";
|
|
5
|
+
|
|
6
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
10
|
+
{
|
|
11
|
+
files: ["**/*.ts"],
|
|
12
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
|
|
13
|
+
plugins: { "no-comments": noComments },
|
|
14
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
15
|
+
rules: {
|
|
16
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
17
|
+
semi: ["error", "always"],
|
|
18
|
+
eqeqeq: ["error", "always"],
|
|
19
|
+
curly: ["error", "multi-line"],
|
|
20
|
+
"prefer-const": "error",
|
|
21
|
+
"no-var": "error",
|
|
22
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
23
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
24
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
25
|
+
"no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
|
|
26
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
28
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
29
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
30
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
31
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
32
|
+
"@typescript-eslint/naming-convention": [
|
|
33
|
+
"error",
|
|
34
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
35
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
|
|
36
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
38
|
+
{ selector: "property", format: null },
|
|
39
|
+
{ selector: "method", format: ["camelCase"] },
|
|
40
|
+
{ selector: "import", format: null },
|
|
41
|
+
],
|
|
42
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
43
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
44
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
|
7
|
+
<link rel="icon" type="image/png" href="/logo.png" sizes="150x150" />
|
|
8
|
+
<link rel="apple-touch-icon" href="/logo.png" />
|
|
9
|
+
<title>Laser-cut box</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<canvas id="three-canvas"></canvas>
|
|
13
|
+
<aside id="panel" aria-label="Configure the box"></aside>
|
|
14
|
+
<a class="credit" href="https://bitbybit.dev" target="_blank" rel="noopener noreferrer"><img src="/logo.png" alt="" />geometry by bitbybit.dev</a>
|
|
15
|
+
<script type="module" src="/src/main.ts"></script>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bitbybit-laser-cut-box",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "npm run typecheck && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"smoke": "npm run typecheck && npm run lint && tsx scripts/smoke.ts",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint . --max-warnings 0"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@bitbybit-dev/threejs": "1.4.0-rc.0",
|
|
16
|
+
"three": "0.186.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@bitbybit-dev/occt": "1.4.0-rc.0",
|
|
20
|
+
"@eslint/js": "10.0.1",
|
|
21
|
+
"@types/node": "22.20.1",
|
|
22
|
+
"@types/three": "0.186.0",
|
|
23
|
+
"eslint": "10.10.0",
|
|
24
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
25
|
+
"tsx": "^4.19.0",
|
|
26
|
+
"typescript": "5.9.3",
|
|
27
|
+
"typescript-eslint": "8.70.0",
|
|
28
|
+
"vite": "^6.3.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readdirSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js";
|
|
5
|
+
import { Inputs, OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt";
|
|
6
|
+
import { buildModel, clampParams, defaultParams, type BoxParams, type Occt } from "../src/model.ts";
|
|
7
|
+
import { partsOverlap, slotArea } from "../src/panels.ts";
|
|
8
|
+
|
|
9
|
+
interface BoxCheck {
|
|
10
|
+
parts: number;
|
|
11
|
+
fingers: Record<string, number>;
|
|
12
|
+
dxfPaths: Record<string, number>;
|
|
13
|
+
layout: { fits: boolean; usedWidth: number; usedHeight: number };
|
|
14
|
+
handle: boolean;
|
|
15
|
+
materialVolume: number;
|
|
16
|
+
hollowBox: number;
|
|
17
|
+
jointsClosed: boolean | string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function inProcess(service: object): Occt {
|
|
21
|
+
return service as Occt;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function pairs<T>(items: T[]): [T, T][] {
|
|
25
|
+
return items.flatMap((a, i) => items.slice(i + 1).map((b): [T, T] => [a, b]));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
const kernelDir = dirname(require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/index.js"));
|
|
30
|
+
const wasmFile = readdirSync(kernelDir).find((file) => file.endsWith(".wasm"));
|
|
31
|
+
if (!wasmFile) throw new Error(`no OCCT kernel (.wasm) found in ${kernelDir}`);
|
|
32
|
+
const occ = await initOpenCascade({ locateFile: (file: string) => (file.endsWith(".wasm") ? join(kernelDir, wasmFile) : file) });
|
|
33
|
+
const occt = inProcess(new OCCTService(occ, new OccHelper(new VectorHelperService(), new ShapesHelperService(), occ)));
|
|
34
|
+
|
|
35
|
+
const round = (n: number): number => Math.round(n * 1000) / 1000;
|
|
36
|
+
const spans = (box: number[], expected: [number, number, number], slack: number): boolean => expected.every((value, i) => Math.abs((box[i] ?? Number.NaN) - value) <= slack);
|
|
37
|
+
const problems: string[] = [];
|
|
38
|
+
|
|
39
|
+
async function check(name: string, params: BoxParams): Promise<BoxCheck> {
|
|
40
|
+
const p = clampParams(params);
|
|
41
|
+
const model = await buildModel(occt, params);
|
|
42
|
+
const expectedParts = p.lid ? 6 : 5;
|
|
43
|
+
if (model.parts.length !== expectedParts) problems.push(`${name}: ${model.parts.length} parts, expected ${expectedParts}`);
|
|
44
|
+
|
|
45
|
+
const dxfPaths: Record<string, number> = {};
|
|
46
|
+
for (const part of model.parts) {
|
|
47
|
+
if (await occt.shapes.shape.getShapeType({ shape: part.face }) !== Inputs.OCCT.shapeTypeEnum.face) problems.push(`${name}: part ${part.id} is not one planar face`);
|
|
48
|
+
const paths = await occt.io.shapeToDxfPaths({ shape: part.flat, angularDeflection: 0.1, curvatureDeflection: 0.1, minimumOfPoints: 2, uTolerance: 1e-9, minimumLength: 1e-7 });
|
|
49
|
+
dxfPaths[part.id] = paths.length;
|
|
50
|
+
if (paths.length === 0) problems.push(`${name}: part ${part.id} produced no DXF path`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const [a, b] of pairs(model.layout.parts)) {
|
|
54
|
+
if (partsOverlap(a, b)) problems.push(`${name}: parts ${a.id} and ${b.id} overlap in the layout`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const assembled = await occt.shapes.compound.makeCompound({ shapes: model.parts.map((part) => part.assembled) });
|
|
58
|
+
const bbox = await occt.operations.boundingBoxOfShape({ shape: assembled });
|
|
59
|
+
const expectedMin: [number, number, number] = [-p.length / 2, 0, -p.width / 2];
|
|
60
|
+
const expectedMax: [number, number, number] = [p.length / 2, p.height, p.width / 2];
|
|
61
|
+
const slack = p.kerf / 2 + 0.001;
|
|
62
|
+
const within = spans(bbox.min, expectedMin, slack) && spans(bbox.max, expectedMax, slack);
|
|
63
|
+
if (!within) problems.push(`${name}: the assembled box spans ${JSON.stringify([bbox.min.map(round), bbox.max.map(round)])}, expected ${JSON.stringify([expectedMin, expectedMax])}`);
|
|
64
|
+
|
|
65
|
+
const volumes = await Promise.all(model.parts.map((part) => occt.shapes.solid.getSolidVolume({ shape: part.assembled })));
|
|
66
|
+
const sum = volumes.reduce((a, b) => a + b, 0);
|
|
67
|
+
const t = p.thickness;
|
|
68
|
+
const handle = model.parts.reduce((total, part) => total + (part.slot ? slotArea(part.slot) * t : 0), 0);
|
|
69
|
+
const hollowBox = p.length * p.width * p.height - (p.length - 2 * t) * (p.width - 2 * t) * (p.height - (p.lid ? 2 * t : t)) - handle;
|
|
70
|
+
let jointsClosed: boolean | string = "not checked with a kerf";
|
|
71
|
+
if (p.kerf === 0) {
|
|
72
|
+
jointsClosed = Math.abs(sum - hollowBox) <= hollowBox * 1e-6;
|
|
73
|
+
if (!jointsClosed) problems.push(`${name}: the panels do not tile the box: their volumes sum to ${round(sum)}, the hollow box less the handle is ${round(hollowBox)}`);
|
|
74
|
+
for (const [a, b] of pairs(model.parts)) {
|
|
75
|
+
const overlap = await occt.booleans.intersection({ shapes: [a.assembled, b.assembled], keepEdges: false });
|
|
76
|
+
const shared = await occt.shapes.solid.getSolidVolume({ shape: overlap });
|
|
77
|
+
if (shared > hollowBox * 1e-6) { jointsClosed = false; problems.push(`${name}: panels ${a.id} and ${b.id} share ${round(shared)} of volume`); }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
parts: model.parts.length,
|
|
83
|
+
fingers: Object.fromEntries(model.parts.map((part) => [part.id, part.fingers])),
|
|
84
|
+
dxfPaths,
|
|
85
|
+
layout: { fits: model.layout.fits, usedWidth: round(model.layout.usedWidth), usedHeight: round(model.layout.usedHeight) },
|
|
86
|
+
handle: model.parts.some((part) => part.slot),
|
|
87
|
+
materialVolume: round(sum),
|
|
88
|
+
hollowBox: round(hollowBox),
|
|
89
|
+
jointsClosed,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const summary = {
|
|
94
|
+
template: "laser-cut-box",
|
|
95
|
+
params: defaultParams,
|
|
96
|
+
default: await check("default", defaultParams),
|
|
97
|
+
noKerf: await check("noKerf", { ...defaultParams, kerf: 0 }),
|
|
98
|
+
noLid: await check("noLid", { ...defaultParams, lid: false, kerf: 0 }),
|
|
99
|
+
tall: await check("tall", { ...defaultParams, length: 60, width: 60, height: 200, thickness: 4, kerf: 0 }),
|
|
100
|
+
};
|
|
101
|
+
console.log(JSON.stringify(summary));
|
|
102
|
+
|
|
103
|
+
if (problems.length) {
|
|
104
|
+
console.error(`smoke: ${problems.join("; ")}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Layout, Point2 } from "./panels";
|
|
2
|
+
|
|
3
|
+
export function downloadBlob(blob: Blob, fileName: string): void {
|
|
4
|
+
const url = URL.createObjectURL(blob);
|
|
5
|
+
const link = document.createElement("a");
|
|
6
|
+
link.href = url;
|
|
7
|
+
link.download = fileName;
|
|
8
|
+
document.body.appendChild(link);
|
|
9
|
+
link.click();
|
|
10
|
+
link.remove();
|
|
11
|
+
setTimeout(() => { URL.revokeObjectURL(url); }, 1000);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function layoutSvg(layout: Layout, sheetWidth: number, sheetHeight: number): string {
|
|
15
|
+
const polygon = (outline: Point2[], x: number, y: number): string =>
|
|
16
|
+
outline.map(([u, v]) => `${(x + u).toFixed(3)},${(sheetHeight - (y + v)).toFixed(3)}`).join(" ");
|
|
17
|
+
const parts = layout.parts.flatMap((part) => [
|
|
18
|
+
` <polygon id="${part.id}" points="${polygon(part.outline, part.x, part.y)}" fill="none" stroke="#000" stroke-width="0.1" />`,
|
|
19
|
+
...(part.slot ? [` <rect id="${part.id}-handle" x="${(part.x - part.slot.length / 2).toFixed(3)}" y="${(sheetHeight - part.y - part.slot.radius).toFixed(3)}" width="${part.slot.length}" height="${2 * part.slot.radius}" rx="${part.slot.radius}" ry="${part.slot.radius}" fill="none" stroke="#000" stroke-width="0.1" />`] : []),
|
|
20
|
+
]);
|
|
21
|
+
return [
|
|
22
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${sheetWidth}mm" height="${sheetHeight}mm" viewBox="0 0 ${sheetWidth} ${sheetHeight}" style="max-width: 100%; height: auto; display: block">`,
|
|
23
|
+
` <rect x="0" y="0" width="${sheetWidth}" height="${sheetHeight}" fill="none" stroke="#999" stroke-width="0.1" stroke-dasharray="2 2" />`,
|
|
24
|
+
...parts,
|
|
25
|
+
"</svg>",
|
|
26
|
+
"",
|
|
27
|
+
].join("\n");
|
|
28
|
+
}
|