@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,223 @@
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
+ }
@@ -0,0 +1,136 @@
1
+ import { LIMITS, UNITS, type BoxParams, type Layout } from "./panels";
2
+
3
+ type NumericKey = keyof typeof LIMITS;
4
+
5
+ const FIELDS: { key: NumericKey; label: string }[] = [
6
+ { key: "length", label: `Length (${UNITS})` },
7
+ { key: "width", label: `Width (${UNITS})` },
8
+ { key: "height", label: `Height (${UNITS})` },
9
+ { key: "thickness", label: `Sheet thickness (${UNITS})` },
10
+ { key: "kerf", label: `Kerf (${UNITS})` },
11
+ { key: "fingerWidth", label: `Finger width (${UNITS})` },
12
+ { key: "sheetWidth", label: `Sheet width (${UNITS})` },
13
+ { key: "sheetHeight", label: `Sheet height (${UNITS})` },
14
+ { key: "gap", label: `Gap between parts (${UNITS})` },
15
+ ];
16
+
17
+ export type View = "assembled" | "flat";
18
+ export type ExportFormat = "dxf" | "svg" | "step";
19
+
20
+ export interface UiHandlers {
21
+ onChange: (params: BoxParams) => void;
22
+ onView: (view: View) => void;
23
+ onExport: (format: ExportFormat) => void;
24
+ }
25
+
26
+ export interface UiHandle {
27
+ setFacts: (layout: Layout, params: BoxParams) => void;
28
+ setStatus: (text: string) => void;
29
+ }
30
+
31
+ export function mountPoint(id: string): HTMLElement {
32
+ const element = document.getElementById(id);
33
+ if (!element) throw new Error(`index.html has no #${id} element to mount the panel in`);
34
+ return element;
35
+ }
36
+
37
+ function query<T extends Element>(root: ParentNode, selector: string, kind: new () => T): T {
38
+ const found = root.querySelector(selector);
39
+ if (!(found instanceof kind)) throw new Error(`the panel markup has no ${selector} element of the expected kind`);
40
+ return found;
41
+ }
42
+
43
+ export function mountUi(root: HTMLElement, initial: BoxParams, handlers: UiHandlers): UiHandle {
44
+ let params = { ...initial };
45
+
46
+ root.innerHTML = `
47
+ <header class="brand"><img src="/logo.png" alt="bitbybit.dev" /><h1>Laser-cut box</h1></header>
48
+ <p class="lead">A finger-jointed box from one sheet. Every part is cut from the same outline the preview shows.</p>
49
+ <div class="views">
50
+ <button type="button" data-view="assembled" class="active">Assembled</button>
51
+ <button type="button" data-view="flat">Cutting layout</button>
52
+ </div>
53
+ <form class="fields"></form>
54
+ <div class="facts">
55
+ <div class="line"><span>Parts</span><strong class="parts">-</strong></div>
56
+ <div class="line"><span>Layout</span><strong class="layout">-</strong></div>
57
+ <div class="line"><span>Sheet used</span><strong class="used">-</strong></div>
58
+ </div>
59
+ <div class="exports">
60
+ <button type="button" data-format="dxf">DXF</button>
61
+ <button type="button" data-format="svg">SVG</button>
62
+ <button type="button" data-format="step">STEP</button>
63
+ </div>
64
+ <p class="status"></p>
65
+ `;
66
+
67
+ const viewButtons = root.querySelectorAll<HTMLButtonElement>(".views button");
68
+ for (const button of viewButtons) {
69
+ button.addEventListener("click", () => {
70
+ for (const other of viewButtons) other.classList.toggle("active", other === button);
71
+ handlers.onView(button.dataset["view"] as View);
72
+ });
73
+ }
74
+
75
+ const form = query(root, ".fields", HTMLFormElement);
76
+ form.addEventListener("submit", (event) => { event.preventDefault(); });
77
+ for (const field of FIELDS) {
78
+ const limit = LIMITS[field.key];
79
+ const wrapper = document.createElement("div");
80
+ wrapper.className = "field";
81
+ const label = document.createElement("label");
82
+ label.textContent = field.label;
83
+ label.htmlFor = field.key;
84
+ const output = document.createElement("output");
85
+ output.value = String(params[field.key]);
86
+ const input = document.createElement("input");
87
+ input.type = "range";
88
+ input.id = field.key;
89
+ input.min = String(limit.min);
90
+ input.max = String(limit.max);
91
+ input.step = String(limit.step);
92
+ input.value = String(params[field.key]);
93
+ input.addEventListener("input", () => {
94
+ params = { ...params, [field.key]: Number(input.value) };
95
+ output.value = input.value;
96
+ handlers.onChange(params);
97
+ });
98
+ wrapper.append(label, output, input);
99
+ form.appendChild(wrapper);
100
+ }
101
+
102
+ const lidWrapper = document.createElement("div");
103
+ lidWrapper.className = "field";
104
+ const lidLabel = document.createElement("label");
105
+ lidLabel.textContent = "Lid";
106
+ lidLabel.htmlFor = "lid";
107
+ const lid = document.createElement("input");
108
+ lid.type = "checkbox";
109
+ lid.id = "lid";
110
+ lid.checked = params.lid;
111
+ lid.addEventListener("change", () => {
112
+ params = { ...params, lid: lid.checked };
113
+ handlers.onChange(params);
114
+ });
115
+ lidWrapper.append(lidLabel, lid);
116
+ form.appendChild(lidWrapper);
117
+
118
+ for (const button of root.querySelectorAll<HTMLButtonElement>(".exports button")) {
119
+ button.addEventListener("click", () => { handlers.onExport(button.dataset["format"] as ExportFormat); });
120
+ }
121
+
122
+ const parts = query(root, ".parts", HTMLElement);
123
+ const layoutText = query(root, ".layout", HTMLElement);
124
+ const used = query(root, ".used", HTMLElement);
125
+ const status = query(root, ".status", HTMLElement);
126
+
127
+ return {
128
+ setFacts: (layout, p) => {
129
+ parts.textContent = String(layout.parts.length);
130
+ layoutText.textContent = layout.fits ? "fits the sheet" : `needs ${Math.ceil(layout.usedWidth)} by ${Math.ceil(layout.usedHeight)} ${UNITS}`;
131
+ const share = (layout.parts.reduce((sum, part) => sum + part.width * part.height, 0) / (p.sheetWidth * p.sheetHeight)) * 100;
132
+ used.textContent = `${share.toFixed(0)}% of ${p.sheetWidth} by ${p.sheetHeight} ${UNITS}`;
133
+ },
134
+ setStatus: (text) => { status.textContent = text; },
135
+ };
136
+ }
@@ -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,19 @@
1
+ ## This template: product configurator
2
+
3
+ A parametric planter with its own form, a live price and downloads, the way a storefront page would present a made-to-measure product. Everything the customer sees comes from the geometry: the price is computed from the solid's measured volume and surface area, so a change to the model changes the quote by itself.
4
+
5
+ - `src/model.ts` is the geometry. `buildModel(occt, params)` builds the planter and returns the shape with its volume and surface area: walls that lean inward by a draft angle (`occt.draft.draftAngle` on the side faces of a rounded block, the negative angle being the inward lean), a stepped lip at the rim, the cavity drafted the same way so the wall keeps one thickness, the rim's edges rounded (selected by their height with `getEdgesCentersOfMass`), a recess under the base so the pot stands on a rim, and the drainage holes, all with planes, cylinders and cones so the booleans stay quick. `STYLE` holds those fixed proportions; `taperAngle` eases the lean off on tall narrow pots so the base keeps at least half the top. One kernel limit is worked around on purpose: a drafted block whose corner arcs are under a millimetre makes the hollowing boolean return the outer solid untouched, so corners that small are cut sharp (`SMALLEST_DRAFTED_CORNER`). `PlanterParams` are the customer-facing parameters, `LIMITS` their ranges, `clampParams` the rule that keeps them buildable (a corner radius cannot exceed half the smallest side minus the wall). Every kernel call is awaited, so the same function runs in the browser through the OCCT worker and in Node in-process.
6
+ - `src/catalog.ts` is the shop side: materials with a colour, a roughness and a clearcoat for the physically based look, and a price per litre, three presets, and `quoteFor(params, model)`, the price formula. It reads the model's measurements and nothing else, so it is pure and the smoke checks it for every preset.
7
+ - `src/ui.ts` renders the panel (presets, sliders, material, quote, export buttons) with plain DOM and calls back on change. It knows the parameter names and limits, not the kernel.
8
+ - `src/main.ts` is the wiring: the Three.js scene, Bitbybit, debounced rebuilds that drop stale results, the draw with one physically based material per catalogue material under a room environment, and the STEP, STL and GLB downloads. `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. STEP and STL come from the OCCT kernel (`occt.io.saveShapeSTEP`, `occt.io.saveShapeStl`, converted to Z-up for CAD tools); GLB comes from Three.js's `GLTFExporter` over the drawn group.
9
+ - `scripts/smoke.ts` builds the default planter and every preset on the in-process kernel and prints one JSON line: `template`, `params`, then for `default` and each entry of `presets` the fields `valid`, `faces`, `edges`, `volume`, `surfaceArea` and `price`. It exits 1 when any planter is not a valid solid, has no volume, is not hollow (its volume must be below the block's less the cavity's least possible size), has a bounding box other than the declared width by height by depth (within the rim's radius, because OpenCascade's box around a fillet surface is loose by up to that), has a quote that is not a positive number, or places a different number of drainage holes than asked. 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 configurator 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 every preset 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
+ To add a parameter: add it to `PlanterParams` and `defaultParams`, give it a range in `LIMITS`, use it in `buildModel`, add a field in `ui.ts`, and if it costs money, price it in `quoteFor`. Then run the smoke and, if the change pins a new fact, assert it there.
18
+
19
+ Units are centimetres in the model and in the scene; prices are in `CURRENCY` from `src/catalog.ts`. The material and finish rates are illustrative numbers to replace with the shop's own; the formula's structure (base, material by volume, finish by surface, options) is the part worth keeping.
@@ -0,0 +1,33 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A parametric product configurator built on the open-source [Bitbybit](https://bitbybit.dev) CAD packages and Three.js. The product is a planter with leaning walls, a stepped lip, a rounded rim and a foot rim: the customer sets its dimensions, wall thickness, corner radius, drainage holes and material, sees it rebuilt live in a physically based material, gets a price computed from the measured solid, and downloads it as STEP, STL or GLB. Nothing runs on a server: the OpenCascade kernel runs in the browser as WebAssembly, and there is no account, key or service in the loop.
4
+
5
+ ```bash
6
+ npm install
7
+ npm run dev # http://localhost:5173
8
+ npm run smoke # typecheck, lint, then every preset built headlessly in Node with a JSON summary
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/model.ts` | the geometry: `buildModel(occt, params)` returns the planter with its volume and surface area; parameter ranges and the rule that keeps them buildable |
18
+ | `src/catalog.ts` | the shop side: materials, presets and the price formula over the model's measurements |
19
+ | `src/ui.ts` | the panel: presets, sliders, material, quote and export buttons, in plain DOM |
20
+ | `src/main.ts` | the wiring: scene, kernel, debounced rebuilds, drawing, downloads |
21
+ | `scripts/smoke.ts` | the headless check an agent or a CI job runs after every change |
22
+
23
+ The geometry function is written once and runs in two places: in the browser it receives Bitbybit's OCCT worker, whose calls return promises; in the smoke it receives the same kernel loaded in-process. That is what makes the price honest and the smoke cheap: both read the same solid.
24
+
25
+ ## Make it your product
26
+
27
+ Replace the planter in `src/model.ts` with your own part and its parameters, put your rates and presets in `src/catalog.ts`, and adjust the fields in `src/ui.ts`. The form is deliberately plain DOM so it drops into any page or framework; the price formula is deliberately pure so it can be tested and reused server-side. The downloads need no changes: STEP and STL come from the kernel, GLB from Three.js.
28
+
29
+ ## Working with an AI agent
30
+
31
+ `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 change the model, then let it run `npm run smoke`.
32
+
33
+ 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>Planter configurator</title>
10
+ </head>
11
+ <body>
12
+ <canvas id="three-canvas"></canvas>
13
+ <aside id="panel" aria-label="Configure the planter"></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-product-configurator",
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
+ }
@@ -0,0 +1,69 @@
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 { OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt";
6
+ import { bottomSize, buildModel, clampParams, defaultParams, drainageHoleCenters, STYLE, type Occt, type PlanterParams } from "../src/model.ts";
7
+ import { PRESETS, quoteFor } from "../src/catalog.ts";
8
+
9
+ interface PlanterCheck {
10
+ valid: boolean;
11
+ faces: number;
12
+ edges: number;
13
+ volume: number;
14
+ surfaceArea: number;
15
+ price: number;
16
+ }
17
+
18
+ function inProcess(service: object): Occt {
19
+ return service as Occt;
20
+ }
21
+
22
+ const require = createRequire(import.meta.url);
23
+ const kernelDir = dirname(require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/index.js"));
24
+ const wasmFile = readdirSync(kernelDir).find((file) => file.endsWith(".wasm"));
25
+ if (!wasmFile) throw new Error(`no OCCT kernel (.wasm) found in ${kernelDir}`);
26
+ const occ = await initOpenCascade({ locateFile: (file: string) => (file.endsWith(".wasm") ? join(kernelDir, wasmFile) : file) });
27
+ const occt = inProcess(new OCCTService(occ, new OccHelper(new VectorHelperService(), new ShapesHelperService(), occ)));
28
+
29
+ const round = (n: number): number => Math.round(n * 1000) / 1000;
30
+ const spans = (box: number[], expected: [number, number, number], tolerance: number): boolean => expected.every((value, i) => Math.abs((box[i] ?? Number.NaN) - value) < tolerance);
31
+
32
+ const TOLERANCE = STYLE.rimRadius;
33
+ const problems: string[] = [];
34
+
35
+ async function check(name: string, params: PlanterParams): Promise<PlanterCheck> {
36
+ const p = clampParams(params);
37
+ const model = await buildModel(occt, params);
38
+ const info = await occt.shapes.solid.debugInfo({ shape: model.shape });
39
+ const bbox = await occt.operations.boundingBoxOfShape({ shape: model.shape });
40
+ const quote = quoteFor(p, model);
41
+ const expectedMin: [number, number, number] = [-p.width / 2, 0, -p.depth / 2];
42
+ const expectedMax: [number, number, number] = [p.width / 2, p.height, p.depth / 2];
43
+ const within = spans(bbox.min, expectedMin, TOLERANCE) && spans(bbox.max, expectedMax, TOLERANCE);
44
+ const solidVolume = p.width * p.depth * p.height;
45
+
46
+ const bottom = bottomSize(p);
47
+ const inside = p.wallThickness + STYLE.lipStep;
48
+ const leastCavity = (bottom.width - 2 * inside) * (bottom.depth - 2 * inside) * (p.height - p.wallThickness);
49
+ if (!info.valid) problems.push(`${name}: the planter is not a valid solid`);
50
+ if (!(model.volume > 0)) problems.push(`${name}: the planter has no volume`);
51
+ if (!(model.volume < solidVolume - leastCavity)) problems.push(`${name}: the planter is not hollow (volume ${round(model.volume)} is not below the block's ${solidVolume} less the least cavity ${round(leastCavity)})`);
52
+ if (!within) problems.push(`${name}: the bounding box ${JSON.stringify([bbox.min, bbox.max])} is not the declared ${JSON.stringify([expectedMin, expectedMax])}`);
53
+ if (!(Number.isFinite(quote.total) && quote.total > 0)) problems.push(`${name}: the quote is ${quote.total}`);
54
+ if (drainageHoleCenters(p).length !== p.drainageHoles) problems.push(`${name}: ${drainageHoleCenters(p).length} hole centers for ${p.drainageHoles} holes`);
55
+ return { valid: info.valid, faces: info.nbFaces, edges: info.nbEdges, volume: round(model.volume), surfaceArea: round(model.surfaceArea), price: quote.total };
56
+ }
57
+
58
+ const summary = {
59
+ template: "product-configurator",
60
+ params: defaultParams,
61
+ default: await check("default", defaultParams),
62
+ presets: Object.fromEntries(await Promise.all(Object.entries(PRESETS).map(async ([id, preset]): Promise<[string, PlanterCheck]> => [id, await check(id, preset.params)]))),
63
+ };
64
+ console.log(JSON.stringify(summary));
65
+
66
+ if (problems.length) {
67
+ console.error(`smoke: ${problems.join("; ")}`);
68
+ process.exit(1);
69
+ }