fluidcad 0.0.28 → 0.0.30

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 (145) hide show
  1. package/lib/dist/common/profiler.d.ts +12 -0
  2. package/lib/dist/common/profiler.js +35 -0
  3. package/lib/dist/common/scene-object.d.ts +3 -0
  4. package/lib/dist/common/scene-object.js +3 -0
  5. package/lib/dist/common/shape-history-tracker.d.ts +9 -1
  6. package/lib/dist/common/shape-history-tracker.js +37 -23
  7. package/lib/dist/core/2d/aline.d.ts +13 -13
  8. package/lib/dist/core/2d/aline.js +20 -11
  9. package/lib/dist/core/2d/arc.d.ts +6 -6
  10. package/lib/dist/core/2d/arc.js +19 -15
  11. package/lib/dist/core/2d/back.d.ts +12 -0
  12. package/lib/dist/core/2d/back.js +11 -0
  13. package/lib/dist/core/2d/circle.d.ts +2 -2
  14. package/lib/dist/core/2d/circle.js +14 -10
  15. package/lib/dist/core/2d/ellipse.d.ts +35 -0
  16. package/lib/dist/core/2d/ellipse.js +65 -0
  17. package/lib/dist/core/2d/hline.d.ts +20 -13
  18. package/lib/dist/core/2d/hline.js +33 -15
  19. package/lib/dist/core/2d/index.d.ts +2 -0
  20. package/lib/dist/core/2d/index.js +2 -0
  21. package/lib/dist/core/2d/intersect.d.ts +2 -2
  22. package/lib/dist/core/2d/intersect.js +7 -3
  23. package/lib/dist/core/2d/line.d.ts +2 -2
  24. package/lib/dist/core/2d/line.js +14 -10
  25. package/lib/dist/core/2d/offset.d.ts +4 -4
  26. package/lib/dist/core/2d/offset.js +9 -5
  27. package/lib/dist/core/2d/polygon.d.ts +4 -4
  28. package/lib/dist/core/2d/polygon.js +24 -20
  29. package/lib/dist/core/2d/project.d.ts +2 -2
  30. package/lib/dist/core/2d/project.js +7 -3
  31. package/lib/dist/core/2d/rect.d.ts +2 -2
  32. package/lib/dist/core/2d/rect.js +22 -21
  33. package/lib/dist/core/2d/slot.d.ts +6 -6
  34. package/lib/dist/core/2d/slot.js +29 -32
  35. package/lib/dist/core/2d/vline.d.ts +20 -13
  36. package/lib/dist/core/2d/vline.js +29 -15
  37. package/lib/dist/core/interfaces.d.ts +62 -0
  38. package/lib/dist/core/mirror.d.ts +7 -7
  39. package/lib/dist/core/mirror.js +17 -11
  40. package/lib/dist/core/part.d.ts +3 -1
  41. package/lib/dist/core/part.js +1 -1
  42. package/lib/dist/core/rotate.d.ts +5 -5
  43. package/lib/dist/core/rotate.js +4 -1
  44. package/lib/dist/core/sketch.d.ts +3 -1
  45. package/lib/dist/core/sketch.js +1 -1
  46. package/lib/dist/core/translate.d.ts +9 -9
  47. package/lib/dist/features/2d/aline.d.ts +8 -5
  48. package/lib/dist/features/2d/aline.js +70 -18
  49. package/lib/dist/features/2d/back.d.ts +14 -0
  50. package/lib/dist/features/2d/back.js +35 -0
  51. package/lib/dist/features/2d/ellipse.d.ts +23 -0
  52. package/lib/dist/features/2d/ellipse.js +75 -0
  53. package/lib/dist/features/2d/hline.d.ts +9 -4
  54. package/lib/dist/features/2d/hline.js +65 -14
  55. package/lib/dist/features/2d/offset.d.ts +3 -0
  56. package/lib/dist/features/2d/offset.js +27 -3
  57. package/lib/dist/features/2d/sketch.d.ts +1 -0
  58. package/lib/dist/features/2d/sketch.js +15 -0
  59. package/lib/dist/features/2d/vline.d.ts +9 -4
  60. package/lib/dist/features/2d/vline.js +67 -15
  61. package/lib/dist/features/common.js +2 -1
  62. package/lib/dist/features/extrude-base.d.ts +19 -1
  63. package/lib/dist/features/extrude-base.js +75 -12
  64. package/lib/dist/features/extrude-two-distances.js +32 -27
  65. package/lib/dist/features/extrude.d.ts +39 -0
  66. package/lib/dist/features/extrude.js +196 -156
  67. package/lib/dist/features/fuse.js +2 -1
  68. package/lib/dist/features/lazy-scene-object.d.ts +1 -0
  69. package/lib/dist/features/lazy-scene-object.js +3 -0
  70. package/lib/dist/features/lazy-vertex.d.ts +1 -0
  71. package/lib/dist/features/lazy-vertex.js +3 -0
  72. package/lib/dist/features/loft.js +11 -8
  73. package/lib/dist/features/mirror-shape.d.ts +2 -0
  74. package/lib/dist/features/mirror-shape.js +16 -0
  75. package/lib/dist/features/mirror-shape2d.d.ts +2 -0
  76. package/lib/dist/features/mirror-shape2d.js +22 -1
  77. package/lib/dist/features/revolve.d.ts +31 -0
  78. package/lib/dist/features/revolve.js +178 -95
  79. package/lib/dist/features/rotate.d.ts +2 -0
  80. package/lib/dist/features/rotate.js +16 -0
  81. package/lib/dist/features/rotate2d.d.ts +2 -0
  82. package/lib/dist/features/rotate2d.js +16 -0
  83. package/lib/dist/features/select.js +2 -1
  84. package/lib/dist/features/simple-extruder.d.ts +3 -1
  85. package/lib/dist/features/simple-extruder.js +13 -9
  86. package/lib/dist/features/subtract.d.ts +2 -2
  87. package/lib/dist/features/subtract.js +3 -3
  88. package/lib/dist/features/sweep.d.ts +14 -0
  89. package/lib/dist/features/sweep.js +93 -80
  90. package/lib/dist/features/translate.d.ts +2 -0
  91. package/lib/dist/features/translate.js +23 -2
  92. package/lib/dist/filters/edge/edge-filter.d.ts +6 -0
  93. package/lib/dist/filters/edge/edge-filter.js +11 -0
  94. package/lib/dist/filters/face/face-filter.d.ts +6 -0
  95. package/lib/dist/filters/face/face-filter.js +11 -0
  96. package/lib/dist/filters/filter-base.d.ts +7 -1
  97. package/lib/dist/filters/filter-base.js +8 -0
  98. package/lib/dist/filters/filter-builder-base.js +11 -0
  99. package/lib/dist/filters/from-object.d.ts +14 -0
  100. package/lib/dist/filters/from-object.js +40 -0
  101. package/lib/dist/helpers/scene-helpers.d.ts +2 -0
  102. package/lib/dist/helpers/scene-helpers.js +68 -48
  103. package/lib/dist/oc/color-transfer.js +6 -0
  104. package/lib/dist/oc/edge-ops.d.ts +1 -0
  105. package/lib/dist/oc/edge-ops.js +17 -0
  106. package/lib/dist/oc/extrude-ops.d.ts +18 -1
  107. package/lib/dist/oc/extrude-ops.js +34 -1
  108. package/lib/dist/oc/geometry.d.ts +1 -0
  109. package/lib/dist/oc/geometry.js +27 -0
  110. package/lib/dist/oc/mesh.js +11 -9
  111. package/lib/dist/oc/ray-intersect.d.ts +16 -0
  112. package/lib/dist/oc/ray-intersect.js +91 -0
  113. package/lib/dist/oc/thin-face-maker.d.ts +0 -1
  114. package/lib/dist/oc/thin-face-maker.js +2 -20
  115. package/lib/dist/rendering/render.d.ts +2 -1
  116. package/lib/dist/rendering/render.js +72 -33
  117. package/lib/dist/rendering/scene.d.ts +4 -0
  118. package/lib/dist/tests/features/2d/back.test.d.ts +1 -0
  119. package/lib/dist/tests/features/2d/back.test.js +60 -0
  120. package/lib/dist/tests/features/2d/circle.test.js +1 -1
  121. package/lib/dist/tests/features/2d/constrained.test.js +4 -4
  122. package/lib/dist/tests/features/2d/ellipse.test.d.ts +1 -0
  123. package/lib/dist/tests/features/2d/ellipse.test.js +100 -0
  124. package/lib/dist/tests/features/2d/line.test.js +89 -3
  125. package/lib/dist/tests/features/2d/offset.test.js +1 -1
  126. package/lib/dist/tests/features/2d/polygon.test.js +2 -2
  127. package/lib/dist/tests/features/2d/rect.test.js +1 -1
  128. package/lib/dist/tests/features/2d/slot-from-edge.test.js +1 -1
  129. package/lib/dist/tests/features/2d/slot.test.js +1 -1
  130. package/lib/dist/tests/features/mirror.test.js +58 -0
  131. package/lib/dist/tests/features/mirror2d.test.js +63 -0
  132. package/lib/dist/tests/features/rotate.test.js +62 -0
  133. package/lib/dist/tests/features/rotate2d.test.js +47 -0
  134. package/lib/dist/tests/features/thin-revolve.test.js +37 -1
  135. package/lib/dist/tests/features/translate.test.js +63 -0
  136. package/lib/dist/tests/perf/record-fusion-history.bench.test.d.ts +1 -0
  137. package/lib/dist/tests/perf/record-fusion-history.bench.test.js +77 -0
  138. package/lib/dist/tsconfig.tsbuildinfo +1 -1
  139. package/package.json +1 -1
  140. package/server/dist/index.js +77 -45
  141. package/server/dist/ws-protocol.d.ts +11 -0
  142. package/ui/dist/assets/{index-BrW_x4uc.js → index-6Ep4GPxf.js} +131 -77
  143. package/ui/dist/assets/index-DRKfe6N9.css +2 -0
  144. package/ui/dist/index.html +2 -2
  145. package/ui/dist/assets/index-gPoNOiIs.css +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluidcad",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "Parametric CAD modeling library using javascript",
5
5
  "author": "Marwan Aouida <contact@marwan.dev>",
6
6
  "homepage": "https://fluidcad.io",
@@ -10,6 +10,7 @@ import { createExportRouter } from "./routes/export.js";
10
10
  import { createScreenshotRouter } from "./routes/screenshot.js";
11
11
  import { createPreferencesRouter } from "./routes/preferences.js";
12
12
  import { normalizePath } from "./normalize-path.js";
13
+ import { extractSourceLocation } from '../../lib/dist/index.js';
13
14
  const PORT = parseInt(process.env.FLUIDCAD_SERVER_PORT || '3100', 10);
14
15
  const WORKSPACE_PATH = normalizePath(process.env.FLUIDCAD_WORKSPACE_PATH || '');
15
16
  const UI_DIST = path.resolve(import.meta.dirname, '../../ui/dist');
@@ -142,6 +143,62 @@ wss.on('connection', (ws) => {
142
143
  // ---------------------------------------------------------------------------
143
144
  let currentFile = null;
144
145
  let renderVersion = 0;
146
+ const lastSceneByFile = new Map();
147
+ function emitSuccess(absPath, result, rollbackStop, breakpointHit) {
148
+ lastSceneByFile.set(absPath, { result, rollbackStop });
149
+ sendToExtension({
150
+ type: 'scene-rendered',
151
+ absPath,
152
+ result,
153
+ rollbackStop,
154
+ });
155
+ broadcastToUI({
156
+ type: 'scene-rendered',
157
+ result,
158
+ absPath,
159
+ rollbackStop,
160
+ breakpointHit,
161
+ });
162
+ }
163
+ function buildCompileError(filePath, err) {
164
+ const message = err?.message || String(err);
165
+ const stack = typeof err?.stack === 'string' ? err.stack : '';
166
+ let sourceLocation = stack ? extractSourceLocation(stack) : null;
167
+ const normalized = normalizePath(filePath).replace('virtual:live-render:', '');
168
+ if (sourceLocation) {
169
+ sourceLocation = {
170
+ filePath: sourceLocation.filePath.replace('virtual:live-render:', ''),
171
+ line: sourceLocation.line,
172
+ column: sourceLocation.column,
173
+ };
174
+ }
175
+ return {
176
+ message,
177
+ filePath: normalized,
178
+ sourceLocation: sourceLocation ?? undefined,
179
+ };
180
+ }
181
+ function emitCompileError(filePath, err) {
182
+ const compileError = buildCompileError(filePath, err);
183
+ const key = compileError.filePath ?? normalizePath(filePath).replace('virtual:live-render:', '');
184
+ const prev = lastSceneByFile.get(key);
185
+ const result = prev?.result ?? [];
186
+ const rollbackStop = prev?.rollbackStop ?? -1;
187
+ sendToExtension({
188
+ type: 'scene-rendered',
189
+ absPath: key,
190
+ result,
191
+ rollbackStop,
192
+ compileError,
193
+ });
194
+ broadcastToUI({
195
+ type: 'scene-rendered',
196
+ result,
197
+ absPath: key,
198
+ rollbackStop,
199
+ compileError,
200
+ });
201
+ }
145
202
  async function handleExtensionMessage(msg) {
146
203
  try {
147
204
  switch (msg.type) {
@@ -149,23 +206,20 @@ async function handleExtensionMessage(msg) {
149
206
  const myVersion = ++renderVersion;
150
207
  broadcastToUI({ type: 'processing-file' });
151
208
  currentFile = msg.filePath;
152
- const data = await fluidCadServer.processFile(msg.filePath);
153
- if (myVersion !== renderVersion) {
154
- return;
209
+ try {
210
+ const data = await fluidCadServer.processFile(msg.filePath);
211
+ if (myVersion !== renderVersion) {
212
+ return;
213
+ }
214
+ if (data) {
215
+ emitSuccess(data.absPath, data.result, data.rollbackStop, data.breakpointHit);
216
+ }
155
217
  }
156
- if (data) {
157
- sendToExtension({
158
- type: 'scene-rendered',
159
- absPath: data.absPath,
160
- result: data.result,
161
- rollbackStop: data.rollbackStop,
162
- });
163
- broadcastToUI({
164
- type: 'scene-rendered',
165
- result: data.result,
166
- absPath: data.absPath,
167
- breakpointHit: data.breakpointHit,
168
- });
218
+ catch (err) {
219
+ if (myVersion !== renderVersion) {
220
+ return;
221
+ }
222
+ emitCompileError(msg.filePath, err);
169
223
  }
170
224
  break;
171
225
  }
@@ -181,25 +235,14 @@ async function handleExtensionMessage(msg) {
181
235
  return;
182
236
  }
183
237
  if (data) {
184
- sendToExtension({
185
- type: 'scene-rendered',
186
- absPath: data.absPath,
187
- result: data.result,
188
- rollbackStop: data.rollbackStop,
189
- });
190
- broadcastToUI({
191
- type: 'scene-rendered',
192
- result: data.result,
193
- absPath: data.absPath,
194
- breakpointHit: data.breakpointHit,
195
- });
238
+ emitSuccess(data.absPath, data.result, data.rollbackStop, data.breakpointHit);
196
239
  }
197
240
  }
198
- catch {
199
- // Silently ignore errors during live-update (syntax errors, incomplete
200
- // expressions, etc. while the user is typing). The last successful
201
- // render remains visible. Model-building errors are delivered separately
202
- // via scene-rendered object properties and are not affected.
241
+ catch (err) {
242
+ if (myVersion !== renderVersion) {
243
+ return;
244
+ }
245
+ emitCompileError(msg.fileName, err);
203
246
  }
204
247
  break;
205
248
  }
@@ -210,18 +253,7 @@ async function handleExtensionMessage(msg) {
210
253
  return;
211
254
  }
212
255
  if (data) {
213
- sendToExtension({
214
- type: 'scene-rendered',
215
- absPath: data.absPath,
216
- result: data.result,
217
- rollbackStop: data.rollbackStop,
218
- });
219
- broadcastToUI({
220
- type: 'scene-rendered',
221
- result: data.result,
222
- absPath: data.absPath,
223
- rollbackStop: data.rollbackStop,
224
- });
256
+ emitSuccess(data.absPath, data.result, data.rollbackStop);
225
257
  }
226
258
  break;
227
259
  }
@@ -51,11 +51,21 @@ export type InitCompleteMessage = {
51
51
  success: boolean;
52
52
  error?: string;
53
53
  };
54
+ export type CompileError = {
55
+ message: string;
56
+ filePath?: string;
57
+ sourceLocation?: {
58
+ filePath: string;
59
+ line: number;
60
+ column: number;
61
+ };
62
+ };
54
63
  export type SceneRenderedMessage = {
55
64
  type: 'scene-rendered';
56
65
  absPath: string;
57
66
  result: any[];
58
67
  rollbackStop: number;
68
+ compileError?: CompileError;
59
69
  };
60
70
  export type ErrorMessage = {
61
71
  type: 'error';
@@ -131,6 +141,7 @@ export type UISceneRenderedMessage = {
131
141
  absPath: string;
132
142
  rollbackStop?: number;
133
143
  breakpointHit?: boolean;
144
+ compileError?: CompileError;
134
145
  };
135
146
  export type UIHighlightShapeMessage = {
136
147
  type: 'highlight-shape';