@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.
Files changed (190) hide show
  1. package/README.md +47 -124
  2. package/dist/index.js +253 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/scaffold.d.ts +30 -0
  5. package/dist/scaffold.d.ts.map +1 -0
  6. package/dist/scaffold.js +107 -0
  7. package/dist/scaffold.js.map +1 -0
  8. package/package.json +4 -3
  9. package/src/index.test.ts +309 -8
  10. package/src/index.ts +285 -24
  11. package/src/scaffold.test.ts +177 -0
  12. package/src/scaffold.ts +99 -0
  13. package/templates/_agent/AGENTS.md +39 -0
  14. package/templates/_agent/CLAUDE.md +1 -0
  15. package/templates/_agent/_dot-cursor/mcp.json +5 -0
  16. package/templates/_agent/_dot-gitignore +7 -0
  17. package/templates/_agent/_dot-mcp.json +5 -0
  18. package/templates/_agent/_dot-vscode/mcp.json +5 -0
  19. package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
  20. package/templates/apps/drone-assembly/README.md +35 -0
  21. package/templates/apps/drone-assembly/eslint.config.js +47 -0
  22. package/templates/apps/drone-assembly/index.html +17 -0
  23. package/templates/apps/drone-assembly/package.json +31 -0
  24. package/templates/apps/drone-assembly/public/favicon.ico +0 -0
  25. package/templates/apps/drone-assembly/public/logo.png +0 -0
  26. package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
  27. package/templates/apps/drone-assembly/src/assembly.ts +99 -0
  28. package/templates/apps/drone-assembly/src/exports.ts +10 -0
  29. package/templates/apps/drone-assembly/src/kernel.ts +14 -0
  30. package/templates/apps/drone-assembly/src/main.ts +298 -0
  31. package/templates/apps/drone-assembly/src/materials.ts +58 -0
  32. package/templates/apps/drone-assembly/src/model.ts +280 -0
  33. package/templates/apps/drone-assembly/src/parts.ts +343 -0
  34. package/templates/apps/drone-assembly/src/style.css +219 -0
  35. package/templates/apps/drone-assembly/src/ui.ts +180 -0
  36. package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
  37. package/templates/apps/drone-assembly/tsconfig.json +29 -0
  38. package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
  39. package/templates/apps/laser-cut-box/README.md +34 -0
  40. package/templates/apps/laser-cut-box/eslint.config.js +47 -0
  41. package/templates/apps/laser-cut-box/index.html +17 -0
  42. package/templates/apps/laser-cut-box/package.json +30 -0
  43. package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
  44. package/templates/apps/laser-cut-box/public/logo.png +0 -0
  45. package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
  46. package/templates/apps/laser-cut-box/src/exports.ts +28 -0
  47. package/templates/apps/laser-cut-box/src/main.ts +176 -0
  48. package/templates/apps/laser-cut-box/src/model.ts +92 -0
  49. package/templates/apps/laser-cut-box/src/panels.ts +229 -0
  50. package/templates/apps/laser-cut-box/src/style.css +223 -0
  51. package/templates/apps/laser-cut-box/src/ui.ts +136 -0
  52. package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
  53. package/templates/apps/laser-cut-box/tsconfig.json +29 -0
  54. package/templates/apps/product-configurator/AGENTS.section.md +19 -0
  55. package/templates/apps/product-configurator/README.md +33 -0
  56. package/templates/apps/product-configurator/eslint.config.js +47 -0
  57. package/templates/apps/product-configurator/index.html +17 -0
  58. package/templates/apps/product-configurator/package.json +30 -0
  59. package/templates/apps/product-configurator/public/favicon.ico +0 -0
  60. package/templates/apps/product-configurator/public/logo.png +0 -0
  61. package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
  62. package/templates/apps/product-configurator/src/catalog.ts +56 -0
  63. package/templates/apps/product-configurator/src/exports.ts +19 -0
  64. package/templates/apps/product-configurator/src/main.ts +134 -0
  65. package/templates/apps/product-configurator/src/model.ts +153 -0
  66. package/templates/apps/product-configurator/src/style.css +177 -0
  67. package/templates/apps/product-configurator/src/ui.ts +150 -0
  68. package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
  69. package/templates/apps/product-configurator/tsconfig.json +29 -0
  70. package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
  71. package/templates/apps/sheet-metal-unfold/README.md +41 -0
  72. package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
  73. package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
  74. package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
  75. package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
  76. package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
  77. package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
  78. package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
  79. package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
  80. package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
  81. package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
  82. package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
  83. package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
  84. package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
  85. package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
  86. package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
  87. package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
  88. package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
  89. package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
  90. package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
  91. package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
  92. package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
  93. package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
  94. package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
  95. package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
  96. package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
  97. package/templates/apps/sheet-metal-unfold/package.json +18 -0
  98. package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
  99. package/templates/apps/step-to-gltf-cli/README.md +34 -0
  100. package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
  101. package/templates/apps/step-to-gltf-cli/package.json +26 -0
  102. package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
  103. package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
  104. package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
  105. package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
  106. package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
  107. package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
  108. package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
  109. package/templates/cloud/AGENTS.section.md +22 -0
  110. package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
  111. package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
  112. package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
  113. package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
  114. package/templates/cloud/backends/hono-rest/package.json +11 -4
  115. package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
  116. package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
  117. package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
  118. package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
  119. package/templates/cloud/backends/hono-sdk/package.json +12 -5
  120. package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
  121. package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
  122. package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
  123. package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
  124. package/templates/cloud/backends/nodejs-rest/package.json +12 -5
  125. package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
  126. package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
  127. package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
  128. package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
  129. package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
  130. package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
  131. package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
  132. package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
  133. package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
  134. package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
  135. package/templates/cloud/frontend/eslint.config.js +50 -0
  136. package/templates/cloud/frontend/index.html +3 -1
  137. package/templates/cloud/frontend/package.json +13 -4
  138. package/templates/cloud/frontend/public/favicon.ico +0 -0
  139. package/templates/cloud/frontend/public/logo.png +0 -0
  140. package/templates/cloud/frontend/src/App.tsx +11 -9
  141. package/templates/cloud/frontend/src/api.ts +31 -0
  142. package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
  143. package/templates/cloud/frontend/src/components/Header.tsx +4 -2
  144. package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
  145. package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
  146. package/templates/cloud/frontend/src/main.tsx +6 -1
  147. package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
  148. package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
  149. package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
  150. package/templates/cloud/frontend/tsconfig.json +19 -7
  151. package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
  152. package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
  153. package/templates/vite/babylonjs/typescript/index.html +4 -2
  154. package/templates/vite/babylonjs/typescript/package.json +14 -4
  155. package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
  156. package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
  157. package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
  158. package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
  159. package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
  160. package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
  161. package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
  162. package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
  163. package/templates/vite/playcanvas/typescript/index.html +4 -2
  164. package/templates/vite/playcanvas/typescript/package.json +14 -4
  165. package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
  166. package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
  167. package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
  168. package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
  169. package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
  170. package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
  171. package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
  172. package/templates/vite/threejs/typescript/eslint.config.js +47 -0
  173. package/templates/vite/threejs/typescript/index.html +4 -2
  174. package/templates/vite/threejs/typescript/package.json +16 -6
  175. package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
  176. package/templates/vite/threejs/typescript/public/logo.png +0 -0
  177. package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
  178. package/templates/vite/threejs/typescript/src/main.ts +11 -22
  179. package/templates/vite/threejs/typescript/src/model.ts +24 -0
  180. package/templates/vite/threejs/typescript/tsconfig.json +16 -12
  181. package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
  182. package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
  183. package/templates/vite/threejs/typescript/public/vite.svg +0 -1
  184. /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
  185. /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
  186. /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
  187. /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
  188. /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
  189. /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
  190. /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
@@ -0,0 +1,291 @@
1
+ :root {
2
+ --panel: rgba(24, 26, 30, 0.92);
3
+ --line: rgba(255, 255, 255, 0.12);
4
+ --text: #f2f2f2;
5
+ --muted: #a5a8ad;
6
+ --accent: #f0cebb;
7
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
8
+ color: var(--text);
9
+ }
10
+
11
+ body {
12
+ margin: 0;
13
+ overflow: hidden;
14
+ background: #1a1c1f;
15
+ }
16
+
17
+ #three-canvas {
18
+ position: fixed;
19
+ inset: 0;
20
+ width: 100%;
21
+ height: 100%;
22
+ display: block;
23
+ }
24
+
25
+ #panel {
26
+ position: fixed;
27
+ top: 16px;
28
+ left: 16px;
29
+ width: 300px;
30
+ max-height: calc(100vh - 32px);
31
+ overflow-y: auto;
32
+ padding: 18px;
33
+ box-sizing: border-box;
34
+ background: var(--panel);
35
+ border: 1px solid var(--line);
36
+ border-radius: 12px;
37
+ backdrop-filter: blur(12px);
38
+ }
39
+
40
+ .brand {
41
+ display: flex;
42
+ align-items: center;
43
+ gap: 10px;
44
+ margin: 0 0 4px;
45
+ }
46
+
47
+ .brand img {
48
+ width: 28px;
49
+ height: 28px;
50
+ }
51
+
52
+ #panel h1 {
53
+ font-size: 18px;
54
+ margin: 0;
55
+ }
56
+
57
+ #panel .lead {
58
+ color: var(--muted);
59
+ font-size: 13px;
60
+ margin: 0 0 14px;
61
+ }
62
+
63
+ .presets {
64
+ display: flex;
65
+ gap: 6px;
66
+ margin-bottom: 14px;
67
+ }
68
+
69
+ .presets button, .exports button {
70
+ flex: 1;
71
+ padding: 7px 8px;
72
+ background: transparent;
73
+ color: var(--text);
74
+ border: 1px solid var(--line);
75
+ border-radius: 8px;
76
+ cursor: pointer;
77
+ font-size: 13px;
78
+ }
79
+
80
+ .presets button:hover, .exports button:hover {
81
+ border-color: var(--accent);
82
+ }
83
+
84
+ .field {
85
+ display: grid;
86
+ grid-template-columns: 1fr auto;
87
+ gap: 2px 8px;
88
+ align-items: center;
89
+ margin-bottom: 10px;
90
+ font-size: 13px;
91
+ }
92
+
93
+ .field label {
94
+ color: var(--muted);
95
+ }
96
+
97
+ .field output {
98
+ text-align: right;
99
+ font-variant-numeric: tabular-nums;
100
+ }
101
+
102
+ .field input[type="range"] {
103
+ grid-column: 1 / 3;
104
+ width: 100%;
105
+ accent-color: var(--accent);
106
+ }
107
+
108
+ .field select {
109
+ grid-column: 1 / 3;
110
+ padding: 6px;
111
+ background: #101114;
112
+ color: var(--text);
113
+ border: 1px solid var(--line);
114
+ border-radius: 6px;
115
+ }
116
+
117
+ .quote {
118
+ margin: 14px 0;
119
+ padding: 12px;
120
+ border: 1px solid var(--line);
121
+ border-radius: 8px;
122
+ font-size: 13px;
123
+ }
124
+
125
+ .quote .total {
126
+ display: flex;
127
+ justify-content: space-between;
128
+ font-size: 18px;
129
+ font-weight: 600;
130
+ margin-bottom: 6px;
131
+ }
132
+
133
+ .quote .line {
134
+ display: flex;
135
+ justify-content: space-between;
136
+ color: var(--muted);
137
+ }
138
+
139
+ .exports {
140
+ display: flex;
141
+ gap: 6px;
142
+ }
143
+
144
+ .status {
145
+ min-height: 18px;
146
+ margin-top: 10px;
147
+ font-size: 12px;
148
+ color: var(--muted);
149
+ }
150
+
151
+ .credit {
152
+ position: fixed;
153
+ right: 16px;
154
+ bottom: 12px;
155
+ display: flex;
156
+ align-items: center;
157
+ gap: 6px;
158
+ color: var(--muted);
159
+ font-size: 12px;
160
+ text-decoration: none;
161
+ }
162
+
163
+ .credit img {
164
+ width: 16px;
165
+ height: 16px;
166
+ }
167
+
168
+ @media (max-width: 640px) {
169
+ #panel {
170
+ top: auto;
171
+ bottom: 0;
172
+ left: 0;
173
+ width: 100%;
174
+ max-height: 55vh;
175
+ border-radius: 12px 12px 0 0;
176
+ }
177
+ }
178
+
179
+ .field input[type="checkbox"] {
180
+ justify-self: end;
181
+ accent-color: var(--accent);
182
+ }
183
+
184
+ .views {
185
+ display: flex;
186
+ gap: 6px;
187
+ margin-bottom: 14px;
188
+ }
189
+
190
+ .views button {
191
+ flex: 1;
192
+ padding: 7px 8px;
193
+ background: transparent;
194
+ color: var(--text);
195
+ border: 1px solid var(--line);
196
+ border-radius: 8px;
197
+ cursor: pointer;
198
+ font-size: 13px;
199
+ }
200
+
201
+ .views button.active {
202
+ border-color: var(--accent);
203
+ color: var(--accent);
204
+ }
205
+
206
+ .facts {
207
+ margin: 14px 0;
208
+ padding: 12px;
209
+ border: 1px solid var(--line);
210
+ border-radius: 8px;
211
+ font-size: 13px;
212
+ }
213
+
214
+ .facts .line {
215
+ display: flex;
216
+ justify-content: space-between;
217
+ color: var(--muted);
218
+ }
219
+
220
+ .facts .line strong {
221
+ color: var(--text);
222
+ font-weight: 500;
223
+ }
224
+
225
+ .access {
226
+ margin: 14px 0;
227
+ padding: 12px;
228
+ border: 1px solid rgba(255, 160, 60, 0.5);
229
+ background: rgba(180, 80, 20, 0.18);
230
+ border-radius: 8px;
231
+ font-size: 13px;
232
+ line-height: 1.5;
233
+ }
234
+
235
+ .access.hidden {
236
+ display: none;
237
+ }
238
+
239
+ .access strong {
240
+ display: block;
241
+ margin-bottom: 4px;
242
+ }
243
+
244
+ .access a {
245
+ color: var(--accent);
246
+ }
247
+
248
+ .access code {
249
+ display: block;
250
+ margin-top: 6px;
251
+ padding: 6px;
252
+ background: #101114;
253
+ border-radius: 6px;
254
+ font-size: 12px;
255
+ }
256
+
257
+ .primary {
258
+ width: 100%;
259
+ margin: 10px 0 4px;
260
+ padding: 9px 8px;
261
+ background: var(--accent);
262
+ color: #1a1c1f;
263
+ border: 0;
264
+ border-radius: 8px;
265
+ cursor: pointer;
266
+ font-size: 13px;
267
+ font-weight: 600;
268
+ }
269
+
270
+ .primary:disabled {
271
+ opacity: 0.5;
272
+ cursor: default;
273
+ }
274
+
275
+ .bends {
276
+ width: 100%;
277
+ border-collapse: collapse;
278
+ font-size: 12px;
279
+ margin-top: 8px;
280
+ }
281
+
282
+ .bends th, .bends td {
283
+ text-align: right;
284
+ padding: 3px 4px;
285
+ border-bottom: 1px solid var(--line);
286
+ color: var(--muted);
287
+ }
288
+
289
+ .bends th:first-child, .bends td:first-child {
290
+ text-align: left;
291
+ }
@@ -0,0 +1,150 @@
1
+ import type { FlatSummary } from "./flat";
2
+ import { LIMITS, UNITS, type FlatEstimate, type PartParams } from "./model";
3
+
4
+ type NumericKey = keyof typeof LIMITS;
5
+
6
+ const FIELDS: { key: NumericKey; label: string }[] = [
7
+ { key: "baseWidth", label: `Base width (${UNITS})` },
8
+ { key: "flangeHeight", label: `Flange height (${UNITS})` },
9
+ { key: "lipHeight", label: `Lip height (${UNITS}, 0 for none)` },
10
+ { key: "depth", label: `Depth (${UNITS})` },
11
+ { key: "thickness", label: `Sheet thickness (${UNITS})` },
12
+ { key: "bendRadius", label: `Inner bend radius (${UNITS})` },
13
+ { key: "kFactor", label: "K-factor" },
14
+ ];
15
+
16
+ export type View = "part" | "flat";
17
+ export type ExportFormat = "part-step" | "flat-step" | "flat-dxf";
18
+
19
+ export interface UiHandlers {
20
+ onChange: (params: PartParams) => void;
21
+ onView: (view: View) => void;
22
+ onUnfold: () => void;
23
+ onExport: (format: ExportFormat) => void;
24
+ }
25
+
26
+ export interface UiHandle {
27
+ accessRoot: HTMLElement;
28
+ setEstimate: (estimate: FlatEstimate, volume: number) => void;
29
+ setFlat: (summary: FlatSummary | null) => void;
30
+ setStatus: (text: string) => void;
31
+ setBusy: (busy: boolean) => void;
32
+ }
33
+
34
+ export function mountPoint(id: string): HTMLElement {
35
+ const element = document.getElementById(id);
36
+ if (!element) throw new Error(`index.html has no #${id} element to mount the panel in`);
37
+ return element;
38
+ }
39
+
40
+ function query<T extends Element>(root: ParentNode, selector: string, kind: new () => T): T {
41
+ const found = root.querySelector(selector);
42
+ if (!(found instanceof kind)) throw new Error(`the panel markup has no ${selector} element of the expected kind`);
43
+ return found;
44
+ }
45
+
46
+ export function mountUi(root: HTMLElement, initial: PartParams, handlers: UiHandlers): UiHandle {
47
+ let params = { ...initial };
48
+
49
+ root.innerHTML = `
50
+ <header class="brand"><img src="/logo.png" alt="bitbybit.dev" /><h1>Sheet-metal unfold</h1></header>
51
+ <p class="lead">The channel is built here, in your browser. The flat pattern comes from CAD Cloud's unfold, a Pro algorithm.</p>
52
+ <div class="views">
53
+ <button type="button" data-view="part" class="active">Part</button>
54
+ <button type="button" data-view="flat" disabled>Flat pattern</button>
55
+ </div>
56
+ <form class="fields"></form>
57
+ <div class="facts">
58
+ <div class="line"><span>Material</span><strong class="volume">-</strong></div>
59
+ <div class="line"><span>Bends</span><strong class="bends">-</strong></div>
60
+ <div class="line"><span>Flat length, K-factor estimate</span><strong class="estimate">-</strong></div>
61
+ <div class="line"><span>Flat pattern, CAD Cloud</span><strong class="cloud">not unfolded yet</strong></div>
62
+ <table class="bends hidden"></table>
63
+ </div>
64
+ <button type="button" class="primary unfold">Unfold on CAD Cloud</button>
65
+ <div class="access hidden"></div>
66
+ <div class="exports">
67
+ <button type="button" data-format="part-step">STEP part</button>
68
+ <button type="button" data-format="flat-dxf" disabled>DXF flat</button>
69
+ <button type="button" data-format="flat-step" disabled>STEP flat</button>
70
+ </div>
71
+ <p class="status"></p>
72
+ `;
73
+
74
+ const viewButtons = root.querySelectorAll<HTMLButtonElement>(".views button");
75
+ for (const button of viewButtons) {
76
+ button.addEventListener("click", () => {
77
+ for (const other of viewButtons) other.classList.toggle("active", other === button);
78
+ handlers.onView(button.dataset["view"] as View);
79
+ });
80
+ }
81
+
82
+ const form = query(root, ".fields", HTMLFormElement);
83
+ form.addEventListener("submit", (event) => { event.preventDefault(); });
84
+ for (const field of FIELDS) {
85
+ const limit = LIMITS[field.key];
86
+ const wrapper = document.createElement("div");
87
+ wrapper.className = "field";
88
+ const label = document.createElement("label");
89
+ label.textContent = field.label;
90
+ label.htmlFor = field.key;
91
+ const output = document.createElement("output");
92
+ output.value = String(params[field.key]);
93
+ const input = document.createElement("input");
94
+ input.type = "range";
95
+ input.id = field.key;
96
+ input.min = String(limit.min);
97
+ input.max = String(limit.max);
98
+ input.step = String(limit.step);
99
+ input.value = String(params[field.key]);
100
+ input.addEventListener("input", () => {
101
+ params = { ...params, [field.key]: Number(input.value) };
102
+ output.value = input.value;
103
+ handlers.onChange(params);
104
+ });
105
+ wrapper.append(label, output, input);
106
+ form.appendChild(wrapper);
107
+ }
108
+
109
+ const unfold = query(root, ".unfold", HTMLButtonElement);
110
+ unfold.addEventListener("click", () => { handlers.onUnfold(); });
111
+
112
+ const exportButtons = root.querySelectorAll<HTMLButtonElement>(".exports button");
113
+ for (const button of exportButtons) {
114
+ button.addEventListener("click", () => { handlers.onExport(button.dataset["format"] as ExportFormat); });
115
+ }
116
+
117
+ const volume = query(root, ".volume", HTMLElement);
118
+ const bends = query(root, ".bends:not(table)", HTMLElement);
119
+ const estimate = query(root, ".estimate", HTMLElement);
120
+ const cloud = query(root, ".cloud", HTMLElement);
121
+ const table = query(root, "table.bends", HTMLTableElement);
122
+ const status = query(root, ".status", HTMLElement);
123
+ const flatView = query(root, '[data-view="flat"]', HTMLButtonElement);
124
+ const flatExports = [...exportButtons].filter((button) => button.dataset["format"]?.startsWith("flat"));
125
+
126
+ return {
127
+ accessRoot: query(root, ".access", HTMLElement),
128
+ setEstimate: (flat, cubic) => {
129
+ volume.textContent = `${(cubic / 1000).toFixed(1)} cm³`;
130
+ bends.textContent = String(flat.bends);
131
+ estimate.textContent = `${flat.total.toFixed(2)} ${UNITS}`;
132
+ },
133
+ setFlat: (summary) => {
134
+ const ready = summary !== null && summary.unfolded > 0;
135
+ flatView.disabled = !ready;
136
+ for (const button of flatExports) button.disabled = !ready;
137
+ table.classList.toggle("hidden", !ready);
138
+ if (!summary) { cloud.textContent = "not unfolded yet"; table.innerHTML = ""; return; }
139
+ cloud.textContent = ready
140
+ ? `${summary.developedLength?.toFixed(2) ?? "?"} ${UNITS} developed, ${summary.bends} bends, ${summary.thickness?.toFixed(2) ?? "?"} ${UNITS} thick`
141
+ : summary.problems.join("; ");
142
+ table.innerHTML = ready
143
+ ? `<tr><th>Bend</th><th>Angle</th><th>Inner r</th><th>Allowance</th></tr>` +
144
+ summary.problems.map((problem) => `<tr><td colspan="4">${problem}</td></tr>`).join("")
145
+ : "";
146
+ },
147
+ setStatus: (text) => { status.textContent = text; },
148
+ setBusy: (busy) => { unfold.disabled = busy; unfold.textContent = busy ? "Unfolding..." : "Unfold on CAD Cloud"; },
149
+ };
150
+ }
@@ -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", "vite.config.ts"]
29
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "vite";
2
+
3
+ export default defineConfig({
4
+ server: {
5
+ proxy: {
6
+ "/api": "http://localhost:3000",
7
+ },
8
+ },
9
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "bitbybit-sheet-metal-unfold",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "workspaces": [
7
+ "frontend",
8
+ "backend"
9
+ ],
10
+ "scripts": {
11
+ "dev:backend": "npm run dev -w backend",
12
+ "dev:frontend": "npm run dev -w frontend",
13
+ "build": "npm run build --workspaces",
14
+ "smoke": "npm run smoke --workspaces",
15
+ "typecheck": "npm run typecheck --workspaces",
16
+ "lint": "npm run lint --workspaces"
17
+ }
18
+ }
@@ -0,0 +1,20 @@
1
+ ## This template: STEP to glTF command line
2
+
3
+ A batch converter: STEP and IGES files in, GLB and STL files and a JSON of facts out, in this process, on the open-source OpenCascade kernel. It is the honesty rule as a program: a machine that can run the kernel needs no service to convert a file. The `--cloud` flag exists for the two cases that cannot, and says so.
4
+
5
+ - `src/kernel.ts` loads the kernel once per run.
6
+ - `src/convert.ts` is the conversion: `convertFile(occt, name, text, options)` reads the file through the kernel, counts its solids, faces and edges, measures its volume and extents, writes the GLB with the kernel's converter and the STL from the loaded shape. It is a pure function over the kernel, so the smoke calls it directly.
7
+ - `src/cloud.ts` is the same conversion as one CAD Cloud task through the SDK: upload, convert, wait, download. It reads the key from `BITBYBIT_API_KEY` and nothing else. Without the key it throws the message the CLI prints, which names the free in-process answer first.
8
+ - `src/cli.ts` parses the arguments, expands directories, runs every file, writes `<name>.glb`, `<name>.stl` and `<name>.json` into `--out`, prints one line per file and a JSON summary, and exits 0, 1 on a failed file, or 2 when `--cloud` was asked without a key.
9
+ - `samples/bracket.step` is a plate with a boss, three holes and filleted edges, made with this kernel; the smoke knows its counts.
10
+ - `scripts/smoke.ts` converts the sample directly and checks the GLB magic, the STL header and the exact solid, face and edge counts, the volume and the extents; parses arguments and expands a directory; runs the CLI as a child on the sample and checks the three files; runs it with `--cloud` and no key and checks the exit code and that the message carries the CAD Cloud page and the Studio keys page. No key and no network.
11
+
12
+ Commands:
13
+
14
+ - `npm run convert -- samples/bracket.step --out out` converts one file; a directory converts every CAD file in it
15
+ - `npm run convert -- --help` prints the options
16
+ - `npm run smoke` typechecks, lints and runs the checks above; `npm run typecheck` and `npm run lint` run alone as well
17
+
18
+ ## What needs CAD Cloud and where to get it
19
+
20
+ Nothing, by default: the conversion runs here, free, on the MIT packages, and gives the same result for any file this machine can hold. `--cloud` sends each file to CAD Cloud as one metered conversion task instead, for exactly two situations: a runtime without the memory for the kernel (a serverless or edge function), or a volume of files worth handing to a queue rather than a laptop. If neither applies, do not use it, and do not add cloud calls to this tool to improve it. Any [CAD Cloud plan](https://bitbybit.dev/cad-cloud) includes conversion; the key needs the `convert`, `files` and `tasks` scopes and is created in [Bitbybit Studio](https://studio.bitbybit.dev/keys/billing). It travels in the `BITBYBIT_API_KEY` environment variable only: never in a file in this project, a prompt or a log.
@@ -0,0 +1,34 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A command-line converter from STEP and IGES to GLB and STL, built on the open-source [Bitbybit](https://bitbybit.dev) OpenCascade kernel. Files are converted in this process, on this machine; nothing is uploaded and no account is needed. Beside each result it writes a JSON with what the file contained: solids, faces, edges, volume, extents, sizes and timing.
4
+
5
+ ```bash
6
+ npm install
7
+ npm run convert -- samples/bracket.step --out out # one file
8
+ npm run convert -- ./incoming --out out # every .step, .stp, .iges, .igs in a directory
9
+ npm run convert -- --help # the options
10
+ npm run smoke # typecheck, lint, then the checks on the sample
11
+ npm run lint # the lint rules, at error
12
+ ```
13
+
14
+ ## When to use `--cloud`, and when not to
15
+
16
+ By default the kernel runs here, and that is the right answer for a laptop, a build server or a Node service with a few hundred megabytes to spare: it is free, it is the same algorithm CAD Cloud runs, and the file never leaves the machine.
17
+
18
+ `--cloud` converts each file as one task on [CAD Cloud](https://bitbybit.dev/cad-cloud) instead. It exists for two cases: a serverless or edge function that cannot load a 35 MB kernel, and a volume of files you would rather hand to a queue than to a laptop. It needs `BITBYBIT_API_KEY` in the environment (any plan; keys live in [Bitbybit Studio](https://studio.bitbybit.dev/keys/billing)), and without it the tool explains this and exits with code 2. Every cloud conversion is metered on the key's account.
19
+
20
+ ## How it is put together
21
+
22
+ | File | Role |
23
+ |---|---|
24
+ | `src/convert.ts` | one file through the kernel: load, count, measure, GLB, STL |
25
+ | `src/cli.ts` | arguments, directories, outputs, exit codes |
26
+ | `src/cloud.ts` | the same conversion as a CAD Cloud task, key from the environment |
27
+ | `samples/bracket.step` | a part made with this kernel, whose counts the smoke knows |
28
+ | `scripts/smoke.ts` | the checks: exact counts on the sample, the CLI end to end, the no-key path |
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 to add an option, 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,26 @@
1
+ {
2
+ "name": "bitbybit-step-to-gltf-cli",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "convert": "tsx src/cli.ts",
8
+ "build": "npm run typecheck",
9
+ "smoke": "npm run typecheck && npm run lint && tsx scripts/smoke.ts",
10
+ "typecheck": "tsc --noEmit",
11
+ "lint": "eslint . --max-warnings 0"
12
+ },
13
+ "dependencies": {
14
+ "@bitbybit-dev/cad-cloud-sdk": "1.4.0-rc.0",
15
+ "@bitbybit-dev/occt": "1.4.0-rc.0"
16
+ },
17
+ "devDependencies": {
18
+ "@eslint/js": "10.0.1",
19
+ "@types/node": "22.20.1",
20
+ "eslint": "10.10.0",
21
+ "eslint-plugin-no-comments": "1.2.1",
22
+ "tsx": "^4.19.0",
23
+ "typescript": "5.9.3",
24
+ "typescript-eslint": "8.70.0"
25
+ }
26
+ }