ducjs 4.0.4 → 4.2.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 (122) hide show
  1. package/dist/duc_locator_wasm.d.ts +48 -0
  2. package/dist/duc_locator_wasm.js +296 -0
  3. package/dist/duc_locator_wasm_bg.wasm +0 -0
  4. package/dist/duc_locator_wasm_bg.wasm.d.ts +13 -0
  5. package/dist/ducjs_wasi.wasm +0 -0
  6. package/dist/ducjs_wasm.d.ts +14 -2
  7. package/dist/ducjs_wasm.js +96 -8
  8. package/dist/ducjs_wasm_bg.wasm +0 -0
  9. package/dist/ducjs_wasm_bg.wasm.d.ts +6 -2
  10. package/dist/index.d.ts +4 -1
  11. package/dist/index.js +4 -1
  12. package/dist/locator-runtime.d.ts +4 -0
  13. package/dist/locator-runtime.js +7 -0
  14. package/dist/restore/index.d.ts +1 -0
  15. package/dist/restore/index.js +1 -0
  16. package/dist/restore/restoreDataState.d.ts +13 -24
  17. package/dist/restore/restoreDataState.js +49 -83
  18. package/dist/restore/restoreElements.d.ts +10 -15
  19. package/dist/restore/restoreElements.js +128 -125
  20. package/dist/restore/updateModelCode.d.ts +11 -0
  21. package/dist/restore/updateModelCode.js +63 -0
  22. package/dist/thumbnails/bounds.d.ts +21 -0
  23. package/dist/thumbnails/bounds.js +84 -0
  24. package/dist/thumbnails/browserRunner.d.ts +60 -0
  25. package/dist/thumbnails/browserRunner.js +446 -0
  26. package/dist/thumbnails/cameraPresets.d.ts +47 -0
  27. package/dist/thumbnails/cameraPresets.js +222 -0
  28. package/dist/thumbnails/cli.d.ts +2 -0
  29. package/dist/thumbnails/cli.js +102 -0
  30. package/dist/thumbnails/index.d.ts +11 -0
  31. package/dist/thumbnails/index.js +11 -0
  32. package/dist/thumbnails/lib/clientBundle.min.js +10427 -0
  33. package/dist/thumbnails/lib/clientEntry.d.ts +3 -0
  34. package/dist/thumbnails/lib/clientEntry.js +8 -0
  35. package/dist/thumbnails/lib/clippingUtils.d.ts +10 -0
  36. package/dist/thumbnails/lib/clippingUtils.js +3 -0
  37. package/dist/thumbnails/lib/defaultModelColor.d.ts +3 -0
  38. package/dist/thumbnails/lib/defaultModelColor.js +22 -0
  39. package/dist/thumbnails/lib/index.d.ts +12 -0
  40. package/dist/thumbnails/lib/index.js +12 -0
  41. package/dist/thumbnails/lib/mapViewerStateToOptions.d.ts +34 -0
  42. package/dist/thumbnails/lib/mapViewerStateToOptions.js +69 -0
  43. package/dist/thumbnails/lib/offscreen-dxf-thumbnail.d.ts +16 -0
  44. package/dist/thumbnails/lib/offscreen-dxf-thumbnail.js +173 -0
  45. package/dist/thumbnails/lib/offscreen-model-thumbnail.d.ts +16 -0
  46. package/dist/thumbnails/lib/offscreen-model-thumbnail.js +209 -0
  47. package/dist/thumbnails/lib/parametricClip.d.ts +18 -0
  48. package/dist/thumbnails/lib/parametricClip.js +177 -0
  49. package/dist/thumbnails/lib/parametricShapes.d.ts +1 -0
  50. package/dist/thumbnails/lib/parametricShapes.js +75 -0
  51. package/dist/thumbnails/lib/parametricViewerState.d.ts +26 -0
  52. package/dist/thumbnails/lib/parametricViewerState.js +198 -0
  53. package/dist/thumbnails/lib/thumbnail-camera-fit.d.ts +6 -0
  54. package/dist/thumbnails/lib/thumbnail-camera-fit.js +292 -0
  55. package/dist/thumbnails/lib/thumbnail-capture.d.ts +23 -0
  56. package/dist/thumbnails/lib/thumbnail-capture.js +161 -0
  57. package/dist/thumbnails/lib/thumbnail-visibility.d.ts +12 -0
  58. package/dist/thumbnails/lib/thumbnail-visibility.js +97 -0
  59. package/dist/thumbnails/lib/viewerGrid.d.ts +13 -0
  60. package/dist/thumbnails/lib/viewerGrid.js +57 -0
  61. package/dist/thumbnails/modelCache.d.ts +56 -0
  62. package/dist/thumbnails/modelCache.js +165 -0
  63. package/dist/thumbnails/modelOutputArtifact.d.ts +19 -0
  64. package/dist/thumbnails/modelOutputArtifact.js +87 -0
  65. package/dist/thumbnails/render.d.ts +45 -0
  66. package/dist/thumbnails/render.js +162 -0
  67. package/dist/thumbnails/templates.d.ts +16 -0
  68. package/dist/thumbnails/templates.js +786 -0
  69. package/dist/thumbnails/tessellator.d.ts +33 -0
  70. package/dist/thumbnails/tessellator.js +349 -0
  71. package/dist/thumbnails/types.d.ts +233 -0
  72. package/dist/thumbnails/types.js +1 -0
  73. package/dist/thumbnails/worker.d.ts +10 -0
  74. package/dist/thumbnails/worker.js +119 -0
  75. package/dist/transform.d.ts +1 -1
  76. package/dist/transform.js +20 -22
  77. package/dist/types/elements/index.d.ts +22 -28
  78. package/dist/types/elements/index.js +0 -1
  79. package/dist/types/geometry.types.d.ts +5 -5
  80. package/dist/types/index.d.ts +13 -59
  81. package/dist/types/index.js +0 -1
  82. package/dist/types/issues.types.d.ts +1 -2
  83. package/dist/utils/bounds.d.ts +10 -11
  84. package/dist/utils/bounds.js +105 -84
  85. package/dist/utils/constants.d.ts +5 -7
  86. package/dist/utils/constants.js +10 -15
  87. package/dist/utils/elements/freedrawElement.js +6 -3
  88. package/dist/utils/elements/index.d.ts +2 -6
  89. package/dist/utils/elements/index.js +4 -9
  90. package/dist/utils/elements/linearElement.d.ts +12 -14
  91. package/dist/utils/elements/linearElement.js +81 -66
  92. package/dist/utils/elements/newElement.d.ts +37 -22
  93. package/dist/utils/elements/newElement.js +70 -64
  94. package/dist/utils/elements/textElement.d.ts +34 -35
  95. package/dist/utils/elements/textElement.js +79 -83
  96. package/dist/utils/index.d.ts +1 -1
  97. package/dist/utils/index.js +1 -1
  98. package/dist/utils/locator.d.ts +43 -0
  99. package/dist/utils/locator.js +112 -0
  100. package/dist/utils/math/bbox.d.ts +1 -2
  101. package/dist/utils/math/geometry.js +5 -4
  102. package/dist/utils/math/index.d.ts +13 -17
  103. package/dist/utils/math/index.js +53 -41
  104. package/dist/utils/math/random.js +7 -2
  105. package/dist/utils/normalize.d.ts +5 -5
  106. package/dist/utils/normalize.js +15 -10
  107. package/dist/utils/shape.d.ts +3 -4
  108. package/dist/utils/shape.js +64 -48
  109. package/dist/utils/state/index.d.ts +3 -4
  110. package/dist/utils/state/index.js +8 -23
  111. package/dist/wasi.js +38 -12
  112. package/package.json +23 -9
  113. package/dist/technical/index.d.ts +0 -2
  114. package/dist/technical/index.js +0 -2
  115. package/dist/technical/measurements.d.ts +0 -31
  116. package/dist/technical/measurements.js +0 -64
  117. package/dist/technical/scopes.d.ts +0 -261
  118. package/dist/technical/scopes.js +0 -676
  119. package/dist/types/typeChecks.d.ts +0 -5
  120. package/dist/types/typeChecks.js +0 -10
  121. package/dist/utils/traverse.d.ts +0 -30
  122. package/dist/utils/traverse.js +0 -124
@@ -1,5 +1,4 @@
1
1
  import { BEZIER_MIRRORING } from "../enums";
2
- import { getPrecisionValueFromRaw, getPrecisionValueFromScoped } from "../technical/scopes";
3
2
  import { isArrowElement, isEllipseElement, isFreeDrawElement, isLinearElement, isPolygonElement } from "../types/elements/typeChecks";
4
3
  import { calculateShapeBounds } from "./bounds";
5
4
  import { getBaseElementProps } from "./elements";
@@ -9,26 +8,26 @@ import { rotatePoint } from "./math";
9
8
  /**
10
9
  * Converts a shape (rectangle, polygon, ellipse) to a linear element
11
10
  */
12
- export const convertShapeToLinearElement = (currentScope, element) => {
11
+ export const convertShapeToLinearElement = (element) => {
13
12
  if (!element)
14
13
  return null;
15
- const { points, lines, pathOverrides } = getElementRelativePoints(element, currentScope);
14
+ const { points, lines, pathOverrides } = getElementRelativePoints(element);
16
15
  // Create a new linear element based on the shape's points
17
- const linearElement = newLinearElement(currentScope, Object.assign(Object.assign({}, getBaseElementProps(element)), { type: "line", points,
16
+ const linearElement = newLinearElement(Object.assign(Object.assign({}, getBaseElementProps(element)), { type: "line", points,
18
17
  lines,
19
18
  pathOverrides }));
20
- const normalizedLinearElement = getNormalizedPoints(linearElement, currentScope);
19
+ const normalizedLinearElement = getNormalizedPoints(linearElement);
21
20
  return Object.assign(Object.assign({}, linearElement), normalizedLinearElement);
22
21
  };
23
22
  /**
24
23
  * @returns vertices relative to element's top-left {x: 0, y: 0} position
25
24
  * */
26
- const getNonLinearElementRelativePoints = (element, currentScope) => {
27
- var _a;
25
+ const getNonLinearElementRelativePoints = (element) => {
26
+ var _a, _b, _c, _d, _e, _f, _g, _h;
28
27
  if (isPolygonElement(element)) {
29
28
  const numSides = element.sides;
30
- const width = element.width.scoped;
31
- const height = element.height.scoped;
29
+ const width = typeof element.width === "number" ? element.width : ((_b = (_a = element.width) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
30
+ const height = typeof element.height === "number" ? element.height : ((_d = (_c = element.height) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
32
31
  const centerX = width / 2;
33
32
  const centerY = height / 2;
34
33
  const radiusX = width / 2;
@@ -44,8 +43,8 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
44
43
  const x = centerX + radiusX * Math.cos(baseAngle);
45
44
  const y = centerY + radiusY * Math.sin(baseAngle);
46
45
  points.push({
47
- x: getPrecisionValueFromScoped(x, element.scope, currentScope),
48
- y: getPrecisionValueFromScoped(y, element.scope, currentScope),
46
+ x,
47
+ y,
49
48
  });
50
49
  }
51
50
  // Create lines connecting consecutive vertices (closed polygon)
@@ -58,19 +57,21 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
58
57
  ]);
59
58
  }
60
59
  // Apply the correction for polygon points after generation
61
- const corrected = getCorrectedOrthodoxElementPoints(element, points, lines, currentScope);
60
+ const corrected = getCorrectedOrthodoxElementPoints(element, points, lines);
62
61
  return { points: corrected.points, lines: corrected.lines, pathOverrides };
63
62
  }
64
63
  if (isEllipseElement(element)) {
65
- const { width, ratio, startAngle, endAngle } = element;
66
- const height = (_a = element.height) !== null && _a !== void 0 ? _a : width;
67
- if (width.scoped <= 0 || height.scoped <= 0) {
64
+ const { ratio, startAngle, endAngle } = element;
65
+ const toNum = (v) => { var _a; return typeof v === "number" ? v : ((_a = v === null || v === void 0 ? void 0 : v.value) !== null && _a !== void 0 ? _a : 0); };
66
+ const w = toNum(element.width);
67
+ const h = element.height !== undefined ? toNum(element.height) : w;
68
+ if (w <= 0 || h <= 0) {
68
69
  return { points: [], lines: [] };
69
70
  }
70
- const rx = width.scoped / 2;
71
- const ry = height.scoped / 2;
72
- const cx = width.scoped / 2;
73
- const cy = height.scoped / 2;
71
+ const rx = w / 2;
72
+ const ry = h / 2;
73
+ const cx = w / 2;
74
+ const cy = h / 2;
74
75
  const epsilon = 1e-6;
75
76
  const sweepAngle = endAngle - startAngle;
76
77
  const isFullShape = Math.abs(sweepAngle) >= 2 * Math.PI - epsilon;
@@ -92,15 +93,15 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
92
93
  const p0 = { x: cx + radiusX * Math.cos(angle0), y: cy + radiusY * Math.sin(angle0) };
93
94
  if (i === 0) {
94
95
  arcPoints.push({
95
- x: getPrecisionValueFromScoped(p0.x, element.scope, currentScope),
96
- y: getPrecisionValueFromScoped(p0.y, element.scope, currentScope),
96
+ x: p0.x,
97
+ y: p0.y,
97
98
  mirroring: BEZIER_MIRRORING.ANGLE_LENGTH,
98
99
  });
99
100
  }
100
101
  const p3 = { x: cx + radiusX * Math.cos(angle1), y: cy + radiusY * Math.sin(angle1) };
101
102
  arcPoints.push({
102
- x: getPrecisionValueFromScoped(p3.x, element.scope, currentScope),
103
- y: getPrecisionValueFromScoped(p3.y, element.scope, currentScope),
103
+ x: p3.x,
104
+ y: p3.y,
104
105
  mirroring: BEZIER_MIRRORING.ANGLE_LENGTH,
105
106
  });
106
107
  const k = (4 / 3) * Math.tan(segmentSweep / 4);
@@ -112,15 +113,15 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
112
113
  {
113
114
  index: i,
114
115
  handle: {
115
- x: getPrecisionValueFromScoped(cp1.x, element.scope, currentScope),
116
- y: getPrecisionValueFromScoped(cp1.y, element.scope, currentScope),
116
+ x: cp1.x,
117
+ y: cp1.y,
117
118
  },
118
119
  },
119
120
  {
120
121
  index: i + 1,
121
122
  handle: {
122
- x: getPrecisionValueFromScoped(cp2.x, element.scope, currentScope),
123
- y: getPrecisionValueFromScoped(cp2.y, element.scope, currentScope),
123
+ x: cp2.x,
124
+ y: cp2.y,
124
125
  },
125
126
  },
126
127
  ]);
@@ -171,8 +172,8 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
171
172
  }
172
173
  else if (!isFullShape) { // Pie slice (no hole)
173
174
  const centerPoint = {
174
- x: getPrecisionValueFromScoped(cx, element.scope, currentScope),
175
- y: getPrecisionValueFromScoped(cy, element.scope, currentScope),
175
+ x: cx,
176
+ y: cy,
176
177
  mirroring: BEZIER_MIRRORING.NONE,
177
178
  };
178
179
  const centerIndex = allPoints.length;
@@ -186,26 +187,28 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
186
187
  }
187
188
  // Merge any overlapping points that may have been introduced
188
189
  const merged = mergeOverlappingPoints(allPoints, allLines);
189
- const corrected = getCorrectedOrthodoxElementPoints(element, merged.points, merged.lines, currentScope);
190
+ const corrected = getCorrectedOrthodoxElementPoints(element, merged.points, merged.lines);
190
191
  return { points: corrected.points, lines: corrected.lines, pathOverrides };
191
192
  }
192
193
  // Default case: rectangle/square
194
+ const elWidth = typeof element.width === "number" ? element.width : ((_f = (_e = element.width) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0);
195
+ const elHeight = typeof element.height === "number" ? element.height : ((_h = (_g = element.height) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0);
193
196
  const points = [
194
197
  {
195
- x: getPrecisionValueFromRaw(0, element.scope, currentScope),
196
- y: getPrecisionValueFromRaw(0, element.scope, currentScope),
198
+ x: 0,
199
+ y: 0,
197
200
  },
198
201
  {
199
- x: getPrecisionValueFromScoped(element.width.scoped, element.scope, currentScope),
200
- y: getPrecisionValueFromRaw(0, element.scope, currentScope),
202
+ x: elWidth,
203
+ y: 0,
201
204
  },
202
205
  {
203
- x: getPrecisionValueFromScoped(element.width.scoped, element.scope, currentScope),
204
- y: getPrecisionValueFromScoped(element.height.scoped, element.scope, currentScope),
206
+ x: elWidth,
207
+ y: elHeight,
205
208
  },
206
209
  {
207
- x: getPrecisionValueFromRaw(0, element.scope, currentScope),
208
- y: getPrecisionValueFromScoped(element.height.scoped, element.scope, currentScope),
210
+ x: 0,
211
+ y: elHeight,
209
212
  },
210
213
  ];
211
214
  // Create lines for rectangle: top, right, bottom, left
@@ -217,11 +220,14 @@ const getNonLinearElementRelativePoints = (element, currentScope) => {
217
220
  ];
218
221
  return { points, lines };
219
222
  };
220
- export const getCorrectedOrthodoxElementPoints = (element, points, lines, currentScope) => {
223
+ export const getCorrectedOrthodoxElementPoints = (element, points, lines) => {
224
+ var _a, _b, _c, _d;
221
225
  const { minX, minY, maxX, maxY } = calculateShapeBounds(points, lines);
226
+ const elWidth = typeof element.width === "number" ? element.width : ((_b = (_a = element.width) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
227
+ const elHeight = typeof element.height === "number" ? element.height : ((_d = (_c = element.height) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
222
228
  const polygonCenter = {
223
- x: element.width.scoped / 2,
224
- y: element.height.scoped / 2,
229
+ x: elWidth / 2,
230
+ y: elHeight / 2,
225
231
  };
226
232
  const bboxCenter = {
227
233
  x: minX + (maxX - minX) / 2,
@@ -236,19 +242,29 @@ export const getCorrectedOrthodoxElementPoints = (element, points, lines, curren
236
242
  x: offset.x - rotatedOffset.x,
237
243
  y: offset.y - rotatedOffset.y,
238
244
  };
239
- const correctedPoints = points.map((p) => (Object.assign(Object.assign({}, p), { x: getPrecisionValueFromScoped((p.x.scoped + correction.x), element.scope, currentScope), y: getPrecisionValueFromScoped((p.y.scoped + correction.y), element.scope, currentScope) })));
240
- const correctedLines = lines.map((line) => [
241
- Object.assign(Object.assign({}, line[0]), { handle: line[0].handle ? Object.assign(Object.assign({}, line[0].handle), { x: getPrecisionValueFromScoped(line[0].handle.x.scoped + correction.x, element.scope, currentScope), y: getPrecisionValueFromScoped(line[0].handle.y.scoped + correction.y, element.scope, currentScope) }) : null }),
242
- Object.assign(Object.assign({}, line[1]), { handle: line[1].handle ? Object.assign(Object.assign({}, line[1].handle), { x: getPrecisionValueFromScoped(line[1].handle.x.scoped + correction.x, element.scope, currentScope), y: getPrecisionValueFromScoped(line[1].handle.y.scoped + correction.y, element.scope, currentScope) }) : null }),
243
- ]);
245
+ const correctedPoints = points.map((p) => {
246
+ var _a, _b, _c, _d;
247
+ const px = typeof p.x === "number" ? p.x : ((_b = (_a = p.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
248
+ const py = typeof p.y === "number" ? p.y : ((_d = (_c = p.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
249
+ return Object.assign(Object.assign({}, p), { x: px + correction.x, y: py + correction.y });
250
+ });
251
+ const correctedLines = lines.map((line) => {
252
+ var _a, _b, _c, _d, _e, _f, _g, _h;
253
+ return [
254
+ Object.assign(Object.assign({}, line[0]), { handle: line[0].handle
255
+ ? Object.assign(Object.assign({}, line[0].handle), { x: (typeof line[0].handle.x === "number" ? line[0].handle.x : ((_b = (_a = line[0].handle.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0)) + correction.x, y: (typeof line[0].handle.y === "number" ? line[0].handle.y : ((_d = (_c = line[0].handle.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0)) + correction.y }) : null }),
256
+ Object.assign(Object.assign({}, line[1]), { handle: line[1].handle
257
+ ? Object.assign(Object.assign({}, line[1].handle), { x: (typeof line[1].handle.x === "number" ? line[1].handle.x : ((_f = (_e = line[1].handle.x) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0)) + correction.x, y: (typeof line[1].handle.y === "number" ? line[1].handle.y : ((_h = (_g = line[1].handle.y) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0)) + correction.y }) : null }),
258
+ ];
259
+ });
244
260
  return { points: correctedPoints, lines: correctedLines };
245
261
  };
246
- export const getElementRelativePoints = (element, currentScope) => {
262
+ export const getElementRelativePoints = (element) => {
247
263
  if (isLinearElement(element)) {
248
264
  return { points: element.points, lines: element.lines };
249
265
  }
250
266
  if (isFreeDrawElement(element) || isArrowElement(element)) {
251
267
  return { points: element.points, lines: [] };
252
268
  }
253
- return getNonLinearElementRelativePoints(element, currentScope);
269
+ return getNonLinearElementRelativePoints(element);
254
270
  };
@@ -1,9 +1,8 @@
1
- import { DucCharter, DucGlobalState, DucIssue, DucLocalState, Scope, Zoom } from "../../types";
1
+ import { DucCharter, DucGlobalState, DucIssue, DucLocalState, Zoom } from "../../types";
2
2
  /**
3
- * Returns the zoom object with value, scoped, and scaled properties,
4
- * using importedState, restoredGlobalState, and defaults.
3
+ * Returns the normalized zoom object using default fallback.
5
4
  */
6
- export declare const getZoom: (value: number, mainScope: Scope, scopeExponentThreshold: number) => Zoom;
5
+ export declare const getZoom: (value: number) => Zoom;
7
6
  export declare const getDefaultGlobalState: () => DucGlobalState;
8
7
  export declare const getDefaultCharter: () => DucCharter;
9
8
  export declare const getDefaultIssues: () => DucIssue[];
@@ -1,30 +1,22 @@
1
1
  import { isFiniteNumber } from "..";
2
2
  import { TEXT_ALIGN } from "../../enums";
3
- import { isValidPrecisionScopeValue } from "../../restore/restoreDataState";
4
- import { getPrecisionValueFromRaw, getScaledZoomValueForScope, getScopedZoomValue, NEUTRAL_SCOPE, } from "../../technical/scopes";
5
3
  import { COLOR_PALETTE, DEFAULT_ELEMENT_PROPS, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, } from "../constants";
6
4
  import { getNormalizedZoom } from "../normalize";
7
5
  /**
8
- * Returns the zoom object with value, scoped, and scaled properties,
9
- * using importedState, restoredGlobalState, and defaults.
6
+ * Returns the normalized zoom object using default fallback.
10
7
  */
11
- export const getZoom = (value, mainScope, scopeExponentThreshold) => {
8
+ export const getZoom = (value) => {
12
9
  const zoomValue = getNormalizedZoom(isFiniteNumber(value)
13
10
  ? value
14
11
  : 1);
15
- const scope = isValidPrecisionScopeValue(value, mainScope, scopeExponentThreshold);
16
- const scopedZoom = getScopedZoomValue(value, scope);
17
12
  return {
18
13
  value: zoomValue,
19
- scoped: scopedZoom,
20
- scaled: getScaledZoomValueForScope(scopedZoom, scope),
14
+ scaled: zoomValue === 0 || !isFinite(zoomValue) ? 1 : 1 / zoomValue,
21
15
  };
22
16
  };
23
17
  export const getDefaultGlobalState = () => {
24
18
  return {
25
19
  viewBackgroundColor: COLOR_PALETTE.white,
26
- scopeExponentThreshold: 3,
27
- mainScope: NEUTRAL_SCOPE,
28
20
  };
29
21
  };
30
22
  export const getDefaultCharter = () => ({
@@ -41,27 +33,20 @@ export const getDefaultLocalState = () => {
41
33
  const scrollX = typeof window !== "undefined" ? window.innerWidth / 2 : 0;
42
34
  const scrollY = typeof window !== "undefined" ? window.innerHeight / 2 : 0;
43
35
  const zoom = getNormalizedZoom(1);
44
- const scope = NEUTRAL_SCOPE;
45
- const scopedZoom = getScopedZoomValue(zoom, scope);
46
36
  return {
47
- scope,
48
37
  isBindingEnabled: true,
49
- scrollX: getPrecisionValueFromRaw(scrollX, NEUTRAL_SCOPE, scope),
50
- scrollY: getPrecisionValueFromRaw(scrollY, NEUTRAL_SCOPE, scope),
51
- zoom: {
52
- value: zoom,
53
- scoped: scopedZoom,
54
- scaled: getScaledZoomValueForScope(scopedZoom, scope),
55
- },
38
+ scrollX,
39
+ scrollY,
40
+ zoom: getZoom(1),
56
41
  currentItemBackground: DEFAULT_ELEMENT_PROPS.background,
57
42
  currentItemStroke: DEFAULT_ELEMENT_PROPS.stroke,
58
43
  currentItemStartLineHead: null,
59
44
  currentItemEndLineHead: null,
60
45
  currentItemFontFamily: DEFAULT_FONT_FAMILY,
61
46
  currentItemTextAlign: TEXT_ALIGN.LEFT,
62
- currentItemFontSize: getPrecisionValueFromRaw(DEFAULT_FONT_SIZE, scope, scope),
47
+ currentItemFontSize: DEFAULT_FONT_SIZE,
63
48
  currentItemOpacity: DEFAULT_ELEMENT_PROPS.opacity,
64
- currentItemRoundness: getPrecisionValueFromRaw(0, scope, scope),
49
+ currentItemRoundness: 0,
65
50
  penMode: false,
66
51
  viewModeEnabled: false,
67
52
  objectsSnapModeEnabled: true,
package/dist/wasi.js CHANGED
@@ -18,8 +18,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  });
19
19
  };
20
20
  import { WASI } from "node:wasi";
21
+ import { spawn } from "node:child_process";
21
22
  import { readFileSync, existsSync, writeFileSync, unlinkSync, mkdirSync, statSync, rmdirSync, rmSync, mkdtempSync } from "node:fs";
22
- import { join, dirname, resolve, relative } from "node:path";
23
+ import { join, dirname, resolve } from "node:path";
23
24
  import { fileURLToPath } from "node:url";
24
25
  import os from "node:os";
25
26
  import { prepareStateForSerialization } from "./serialize";
@@ -27,12 +28,7 @@ const _dirname = typeof import.meta !== "undefined"
27
28
  ? dirname(fileURLToPath(import.meta.url))
28
29
  : "";
29
30
  const isBunRuntime = () => { var _a; return typeof process !== "undefined" && typeof ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.bun) === "string"; };
30
- const getDefaultTempDir = () => isBunRuntime()
31
- ? join(process.cwd(), ".duc-wasi-tmp")
32
- : os.tmpdir();
33
- const toBunWasiPath = (path) => isBunRuntime()
34
- ? relative(process.cwd(), path) || "."
35
- : path;
31
+ const getDefaultTempDir = () => os.tmpdir();
36
32
  const isSuccessfulWasiExit = (error) => {
37
33
  const candidate = error;
38
34
  return (candidate === null || candidate === void 0 ? void 0 : candidate.code) === 0
@@ -67,6 +63,7 @@ function loadWasiBinary() {
67
63
  resolve(_dirname, "..", "node_modules", "ducjs", "dist", "ducjs_wasi.wasm"),
68
64
  resolve(_dirname, "..", "ducjs", "dist", "ducjs_wasi.wasm"),
69
65
  resolve(_dirname, "ducjs_wasi.wasm"),
66
+ resolve(_dirname, "..", "dist", "ducjs_wasi.wasm"),
70
67
  ];
71
68
  for (const candidate of candidates) {
72
69
  if (existsSync(candidate))
@@ -102,7 +99,7 @@ export function streamToDucFile(entries, outputPath, tempDir) {
102
99
  }
103
100
  const outputDir = dirname(outputPath);
104
101
  try {
105
- yield runWasi(["ducjs-wasi", isBunRuntime() ? toBunWasiPath(outputPath) : `/output/${outputPath.split("/").pop()}`, isBunRuntime() ? toBunWasiPath(manifestPath) : "/tmp/manifest.jsonl"], {
102
+ yield runWasi(["ducjs-wasi", `/output/${outputPath.split("/").pop()}`, "/tmp/manifest.jsonl"], {
106
103
  "/": "/",
107
104
  ".": process.cwd(),
108
105
  "/tmp": manifestDir,
@@ -187,7 +184,7 @@ const writeExternalFileSidecars = (state, manifestDir) => {
187
184
  const filename = `external-${index}.bin`;
188
185
  const sourcePath = join(manifestDir, filename);
189
186
  writeFileSync(sourcePath, data);
190
- entries.push(Object.assign(Object.assign({}, revision), { sourcePath: isBunRuntime() ? toBunWasiPath(sourcePath) : `/tmp/${filename}`, sizeBytes: revision.sizeBytes || data.byteLength }));
187
+ entries.push(Object.assign(Object.assign({}, revision), { sourcePath: `/tmp/${filename}`, sizeBytes: revision.sizeBytes || data.byteLength }));
191
188
  index += 1;
192
189
  }
193
190
  const manifestPath = join(manifestDir, "external-files.jsonl");
@@ -196,6 +193,35 @@ const writeExternalFileSidecars = (state, manifestDir) => {
196
193
  };
197
194
  const runWasi = (args, preopens) => __awaiter(void 0, void 0, void 0, function* () {
198
195
  const wasmBinary = yield loadWasiBinary();
196
+ if (isBunRuntime()) {
197
+ // Run SQLite WASI with Node's implementation; Bun can trap in call_indirect.
198
+ const directory = mkdtempSync(join(os.tmpdir(), "duc-wasi-node-"));
199
+ const binaryPath = join(directory, "serializer.wasm");
200
+ const configPath = join(directory, "config.json");
201
+ writeFileSync(binaryPath, wasmBinary);
202
+ writeFileSync(configPath, JSON.stringify({ args, preopens, binaryPath }));
203
+ const script = `
204
+ const { WASI } = require('node:wasi');
205
+ const { readFileSync } = require('node:fs');
206
+ const config = JSON.parse(readFileSync(process.argv[1], 'utf8'));
207
+ const wasi = new WASI({ version: 'preview1', args: config.args, preopens: config.preopens, env: {} });
208
+ WebAssembly.compile(readFileSync(config.binaryPath)).then(module => WebAssembly.instantiate(module, wasi.getImportObject())).then(instance => wasi.start(instance)).catch(error => { console.error(error); process.exitCode = 1; });
209
+ `;
210
+ try {
211
+ yield new Promise((resolve, reject) => {
212
+ const child = spawn(process.env.DUCJS_NODE_PATH || 'node', ['--no-warnings', '-e', script, configPath], { stdio: ['ignore', 'ignore', 'pipe'] });
213
+ let errors = '';
214
+ child.stderr.on('data', chunk => { if (errors.length < 16384)
215
+ errors += chunk.toString().slice(0, 16384 - errors.length); });
216
+ child.once('error', error => reject(new Error(`Cannot launch Node.js WASI runtime: ${error.message}`)));
217
+ child.once('close', code => code === 0 ? resolve() : reject(new Error(`WASI serialization failed (${code}): ${errors.trim()}`)));
218
+ });
219
+ }
220
+ finally {
221
+ rmSync(directory, { recursive: true, force: true });
222
+ }
223
+ return;
224
+ }
199
225
  const wasi = new WASI({
200
226
  version: "preview1",
201
227
  args,
@@ -231,10 +257,10 @@ export function serializeStateToDucFile(state, outputPath, tempDir) {
231
257
  yield runWasi([
232
258
  "ducjs-wasi",
233
259
  "--state-json",
234
- isBunRuntime() ? toBunWasiPath(statePath) : "/tmp/state.json",
235
- isBunRuntime() ? toBunWasiPath(outputPath) : `/output/${outputPath.split("/").pop()}`,
260
+ "/tmp/state.json",
261
+ `/output/${outputPath.split("/").pop()}`,
236
262
  ...(externalManifestPath
237
- ? [isBunRuntime() ? toBunWasiPath(externalManifestPath) : "/tmp/external-files.jsonl"]
263
+ ? ["/tmp/external-files.jsonl"]
238
264
  : []),
239
265
  ], {
240
266
  "/": "/",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "4.0.4",
3
+ "version": "4.2.0",
4
4
  "description": "SQLite-backed project-state format for physical-engineering work before execution.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,6 +12,16 @@
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.js"
14
14
  },
15
+ "./thumbnails": {
16
+ "types": "./dist/thumbnails/index.d.ts",
17
+ "import": "./dist/thumbnails/index.js",
18
+ "require": "./dist/thumbnails/index.js"
19
+ },
20
+ "./thumbnails/*": {
21
+ "types": "./dist/thumbnails/*.d.ts",
22
+ "import": "./dist/thumbnails/*.js",
23
+ "require": "./dist/thumbnails/*.js"
24
+ },
15
25
  "./*": {
16
26
  "types": [
17
27
  "./dist/*.d.ts",
@@ -40,20 +50,24 @@
40
50
  "license": "MIT",
41
51
  "devDependencies": {
42
52
  "@types/bun": "latest",
43
- "@types/node": "^22.10.0",
44
- "@types/react": "^19.0.0",
53
+ "@types/node": "^22.20.5",
54
+ "@types/react": "^19.3.0",
55
+ "@types/three": "^0.186.0",
45
56
  "@types/tinycolor2": "^1.4.6",
46
- "semantic-release": "^24.1.2",
57
+ "dxf-renderer": "^1.1.1",
58
+ "semantic-release": "^25.0.9",
59
+ "three": "^0.186.1",
60
+ "three-cad-viewer": "^5.1.3",
61
+ "turbo": "^2.11.10",
47
62
  "typedoc": "^0.27.9",
48
- "turbo": "^2.1.3",
49
- "typescript": "^5.8.3",
50
- "undici-types": "^6.21.0"
63
+ "typescript": "^5.9.3",
64
+ "undici-types": "^6.29.1"
51
65
  },
52
66
  "dependencies": {
53
- "@braintree/sanitize-url": "^7.1.1",
67
+ "@braintree/sanitize-url": "^7.1.2",
54
68
  "browser-fs-access": "^0.38.0",
55
69
  "fflate": "^0.8.3",
56
- "nanoid": "^5.1.6",
70
+ "nanoid": "^5.1.16",
57
71
  "perfect-freehand": "1.2.2",
58
72
  "tinycolor2": "1.6.0"
59
73
  },
@@ -1,2 +0,0 @@
1
- export * from "./measurements";
2
- export * from "./scopes";
@@ -1,2 +0,0 @@
1
- export * from "./measurements";
2
- export * from "./scopes";
@@ -1,31 +0,0 @@
1
- import { DucElement } from "../types/elements";
2
- import { CombinedMeasure, SupportedMeasures } from "./scopes";
3
- /**
4
- * Gets translation factor between current scope and element scope
5
- */
6
- export declare function getElementTranslationFactor(currentScope: CombinedMeasure, elementScope: CombinedMeasure): number;
7
- /**
8
- * Gets the appropriate unit for the current zoom level
9
- *
10
- * @param zoom - Current zoom level
11
- * @param mainMeasure - Main/base measurement unit
12
- * @param scopeExpThreshold - Controls the sensitivity of precision scope changes
13
- * @returns The most appropriate measurement unit for the current zoom
14
- */
15
- export declare function getPrecisionScope(zoom: number, mainMeasure: SupportedMeasures, scopeExpThreshold: number): SupportedMeasures;
16
- export declare const coordinateToRealMeasure: (coordinate: number, currentScope: CombinedMeasure, elementScope: CombinedMeasure) => number;
17
- export declare const realMeasureToCoordinate: (realMeasure: number, gridUnit: number) => number;
18
- export declare function filterElementsByScope<T extends DucElement>(elements: readonly T[], currentScope: CombinedMeasure): T[];
19
- /**
20
- * Calculates the approximate size of a single physical device pixel in millimeters.
21
- *
22
- * This calculation is based on the standard CSS definition of a reference pixel
23
- * (1/96th of an inch) and the current devicePixelRatio of the window.
24
- *
25
- * It reflects the effective size of the smallest addressable pixel by the browser,
26
- * considering screen density and browser/OS zoom levels.
27
- *
28
- * @returns {number} The approximate size of a physical pixel in millimeters.
29
- * Returns NaN if window or window.devicePixelRatio is not available (e.g., in a Node.js environment).
30
- */
31
- export declare const getPhysicalDevicePixelSizeInMm: () => number;
@@ -1,64 +0,0 @@
1
- import { calculateScope, getTranslationFactor } from "./scopes";
2
- /**
3
- * Gets translation factor between current scope and element scope
4
- */
5
- export function getElementTranslationFactor(currentScope, elementScope) {
6
- return getTranslationFactor(elementScope, currentScope);
7
- }
8
- /**
9
- * Gets the appropriate unit for the current zoom level
10
- *
11
- * @param zoom - Current zoom level
12
- * @param mainMeasure - Main/base measurement unit
13
- * @param scopeExpThreshold - Controls the sensitivity of precision scope changes
14
- * @returns The most appropriate measurement unit for the current zoom
15
- */
16
- export function getPrecisionScope(zoom, mainMeasure, scopeExpThreshold) {
17
- return calculateScope(zoom, scopeExpThreshold, mainMeasure);
18
- }
19
- export const coordinateToRealMeasure = (coordinate, currentScope, elementScope) => {
20
- const translationFactor = getElementTranslationFactor(currentScope, elementScope);
21
- // 100 grid units is 1,00 real unit
22
- return coordinate * translationFactor / 100;
23
- };
24
- export const realMeasureToCoordinate = (realMeasure, gridUnit) => {
25
- // x grid units * 100 = 1,00 real unit
26
- return realMeasure * 10 * gridUnit;
27
- };
28
- export function filterElementsByScope(elements, currentScope) {
29
- return elements.filter((element) => element.scope === currentScope);
30
- }
31
- /**
32
- * Calculates the approximate size of a single physical device pixel in millimeters.
33
- *
34
- * This calculation is based on the standard CSS definition of a reference pixel
35
- * (1/96th of an inch) and the current devicePixelRatio of the window.
36
- *
37
- * It reflects the effective size of the smallest addressable pixel by the browser,
38
- * considering screen density and browser/OS zoom levels.
39
- *
40
- * @returns {number} The approximate size of a physical pixel in millimeters.
41
- * Returns NaN if window or window.devicePixelRatio is not available (e.g., in a Node.js environment).
42
- */
43
- export const getPhysicalDevicePixelSizeInMm = () => {
44
- // Check if running in a browser environment where window and devicePixelRatio are available
45
- if (typeof window === 'undefined' || typeof window.devicePixelRatio === 'undefined') {
46
- console.warn('window.devicePixelRatio is not available. This function should be run in a browser environment.');
47
- return NaN; // Not applicable or calculable outside a browser context
48
- }
49
- // Standard conversion: 1 inch = 25.4 millimeters
50
- const mmPerInch = 25.4;
51
- // Standard CSS pixels per inch (W3C reference pixel definition)
52
- const cssPixelsPerInch = 96;
53
- // Calculate the conceptual size of one CSS pixel in millimeters.
54
- // This is the physical size a CSS pixel would ideally occupy if devicePixelRatio were 1.
55
- const cssPixelSizeInMm = mmPerInch / cssPixelsPerInch;
56
- // Get the current device pixel ratio from the window.
57
- // This value accounts for the screen's native density and any browser or OS zoom applied.
58
- const currentDevicePixelRatio = window.devicePixelRatio;
59
- // The size of a single physical pixel is the conceptual size of a CSS pixel
60
- // divided by the devicePixelRatio. This is because devicePixelRatio indicates
61
- // how many physical pixels are used to render one CSS pixel in each dimension.
62
- const physicalPixelSizeInMm = cssPixelSizeInMm / currentDevicePixelRatio;
63
- return physicalPixelSizeInMm;
64
- };