ducjs 4.1.0 → 4.3.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 (117) 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/restoreDataState.d.ts +13 -24
  15. package/dist/restore/restoreDataState.js +46 -80
  16. package/dist/restore/restoreElements.d.ts +10 -15
  17. package/dist/restore/restoreElements.js +115 -124
  18. package/dist/thumbnails/bounds.d.ts +21 -0
  19. package/dist/thumbnails/bounds.js +84 -0
  20. package/dist/thumbnails/browserRunner.d.ts +60 -0
  21. package/dist/thumbnails/browserRunner.js +446 -0
  22. package/dist/thumbnails/cameraPresets.d.ts +47 -0
  23. package/dist/thumbnails/cameraPresets.js +222 -0
  24. package/dist/thumbnails/cli.d.ts +2 -0
  25. package/dist/thumbnails/cli.js +102 -0
  26. package/dist/thumbnails/index.d.ts +11 -0
  27. package/dist/thumbnails/index.js +11 -0
  28. package/dist/thumbnails/lib/clientBundle.min.js +10427 -0
  29. package/dist/thumbnails/lib/clientEntry.d.ts +3 -0
  30. package/dist/thumbnails/lib/clientEntry.js +8 -0
  31. package/dist/thumbnails/lib/clippingUtils.d.ts +10 -0
  32. package/dist/thumbnails/lib/clippingUtils.js +3 -0
  33. package/dist/thumbnails/lib/defaultModelColor.d.ts +3 -0
  34. package/dist/thumbnails/lib/defaultModelColor.js +22 -0
  35. package/dist/thumbnails/lib/index.d.ts +12 -0
  36. package/dist/thumbnails/lib/index.js +12 -0
  37. package/dist/thumbnails/lib/mapViewerStateToOptions.d.ts +34 -0
  38. package/dist/thumbnails/lib/mapViewerStateToOptions.js +69 -0
  39. package/dist/thumbnails/lib/offscreen-dxf-thumbnail.d.ts +16 -0
  40. package/dist/thumbnails/lib/offscreen-dxf-thumbnail.js +173 -0
  41. package/dist/thumbnails/lib/offscreen-model-thumbnail.d.ts +16 -0
  42. package/dist/thumbnails/lib/offscreen-model-thumbnail.js +209 -0
  43. package/dist/thumbnails/lib/parametricClip.d.ts +18 -0
  44. package/dist/thumbnails/lib/parametricClip.js +177 -0
  45. package/dist/thumbnails/lib/parametricShapes.d.ts +1 -0
  46. package/dist/thumbnails/lib/parametricShapes.js +75 -0
  47. package/dist/thumbnails/lib/parametricViewerState.d.ts +26 -0
  48. package/dist/thumbnails/lib/parametricViewerState.js +198 -0
  49. package/dist/thumbnails/lib/thumbnail-camera-fit.d.ts +6 -0
  50. package/dist/thumbnails/lib/thumbnail-camera-fit.js +292 -0
  51. package/dist/thumbnails/lib/thumbnail-capture.d.ts +23 -0
  52. package/dist/thumbnails/lib/thumbnail-capture.js +161 -0
  53. package/dist/thumbnails/lib/thumbnail-visibility.d.ts +12 -0
  54. package/dist/thumbnails/lib/thumbnail-visibility.js +97 -0
  55. package/dist/thumbnails/lib/viewerGrid.d.ts +13 -0
  56. package/dist/thumbnails/lib/viewerGrid.js +57 -0
  57. package/dist/thumbnails/modelCache.d.ts +56 -0
  58. package/dist/thumbnails/modelCache.js +165 -0
  59. package/dist/thumbnails/modelOutputArtifact.d.ts +19 -0
  60. package/dist/thumbnails/modelOutputArtifact.js +87 -0
  61. package/dist/thumbnails/render.d.ts +45 -0
  62. package/dist/thumbnails/render.js +162 -0
  63. package/dist/thumbnails/templates.d.ts +16 -0
  64. package/dist/thumbnails/templates.js +786 -0
  65. package/dist/thumbnails/tessellator.d.ts +33 -0
  66. package/dist/thumbnails/tessellator.js +349 -0
  67. package/dist/thumbnails/types.d.ts +233 -0
  68. package/dist/thumbnails/types.js +1 -0
  69. package/dist/thumbnails/worker.d.ts +10 -0
  70. package/dist/thumbnails/worker.js +119 -0
  71. package/dist/transform.d.ts +1 -1
  72. package/dist/transform.js +20 -22
  73. package/dist/types/elements/index.d.ts +22 -28
  74. package/dist/types/elements/index.js +0 -1
  75. package/dist/types/geometry.types.d.ts +5 -5
  76. package/dist/types/index.d.ts +15 -59
  77. package/dist/types/index.js +0 -1
  78. package/dist/types/issues.types.d.ts +1 -2
  79. package/dist/utils/bounds.d.ts +10 -11
  80. package/dist/utils/bounds.js +105 -84
  81. package/dist/utils/constants.d.ts +5 -7
  82. package/dist/utils/constants.js +10 -15
  83. package/dist/utils/elements/freedrawElement.js +6 -3
  84. package/dist/utils/elements/index.d.ts +2 -6
  85. package/dist/utils/elements/index.js +4 -9
  86. package/dist/utils/elements/linearElement.d.ts +12 -14
  87. package/dist/utils/elements/linearElement.js +81 -66
  88. package/dist/utils/elements/newElement.d.ts +37 -22
  89. package/dist/utils/elements/newElement.js +70 -64
  90. package/dist/utils/elements/textElement.d.ts +34 -35
  91. package/dist/utils/elements/textElement.js +79 -83
  92. package/dist/utils/index.d.ts +1 -1
  93. package/dist/utils/index.js +1 -1
  94. package/dist/utils/locator.d.ts +43 -0
  95. package/dist/utils/locator.js +112 -0
  96. package/dist/utils/math/bbox.d.ts +1 -2
  97. package/dist/utils/math/geometry.js +5 -4
  98. package/dist/utils/math/index.d.ts +13 -17
  99. package/dist/utils/math/index.js +53 -41
  100. package/dist/utils/normalize.d.ts +5 -5
  101. package/dist/utils/normalize.js +15 -10
  102. package/dist/utils/shape.d.ts +3 -4
  103. package/dist/utils/shape.js +64 -48
  104. package/dist/utils/state/index.d.ts +3 -4
  105. package/dist/utils/state/index.js +9 -23
  106. package/dist/wasi.js +38 -12
  107. package/package.json +23 -9
  108. package/dist/technical/index.d.ts +0 -2
  109. package/dist/technical/index.js +0 -2
  110. package/dist/technical/measurements.d.ts +0 -31
  111. package/dist/technical/measurements.js +0 -64
  112. package/dist/technical/scopes.d.ts +0 -261
  113. package/dist/technical/scopes.js +0 -676
  114. package/dist/types/typeChecks.d.ts +0 -5
  115. package/dist/types/typeChecks.js +0 -10
  116. package/dist/utils/traverse.d.ts +0 -30
  117. package/dist/utils/traverse.js +0 -124
@@ -1,29 +1,25 @@
1
- import { getPrecisionValueFromRaw, getPrecisionValueFromScoped, getScopedBezierPointFromDucPoint, NEUTRAL_SCOPE, ScaleFactors } from "../technical/scopes";
2
1
  import { isElbowArrow, isLinearElement, isTextElement, } from "../types";
3
2
  import { arrayToMap, bumpVersion, DEFAULT_ELEMENT_PROPS, DEFAULT_ELLIPSE_ELEMENT, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, DEFAULT_FREEDRAW_ELEMENT, detectLineHeight, FONT_FAMILY, getContainerElement, getDefaultTableData, getNormalizedDimensions, getNormalizedPoints, getSizeFromPoints, getUpdatedTimestamp, isInvisiblySmallElement, LINE_CONFIRM_THRESHOLD, mergeOverlappingPoints, migratePoints, normalizeFixedPoint, normalizeLink, randomId, refreshTextDimensions, validateClosedPath } from "../utils";
4
3
  import { isValidBezierMirroringValue, isValidBlendingValue, isValidBoolean, isValidBoolean as isValidBooleanValue, // Renaming to avoid conflict
5
- isValidColor, isValidDucHead, isValidFunction, isValidImageScaleValue, isValidImageStatusValue, isValidPercentageValue, isValidPolygonSides, isValidRadianValue, isValidString, isValidTextAlignValue, isValidVerticalAlignValue, restoreDucStackProperties, restorePrecisionValue, validateBackground, validateStroke } from "./restoreDataState";
4
+ isValidColor, isValidDucHead, isValidFunction, isValidImageScaleValue, isValidImageStatusValue, isValidPercentageValue, isValidPolygonSides, isValidRadianValue, isValidString, isValidTextAlignValue, isValidVerticalAlignValue, restoreDucStackProperties, restoreNumber, validateBackground, validateStroke } from "./restoreDataState";
6
5
  import { updateModelCodeElementIds } from "./updateModelCode";
7
6
  import { LINE_SPACING_TYPE, } from "../enums";
8
7
  const PARAMETRIC_SOURCE_TYPE = { CODE: 10, FILE: 11 };
9
8
  import tinycolor from "tinycolor2";
10
9
  const restoreElementWithProperties = (element, extra, localState, globalState) => {
11
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
12
11
  const _element = Object.assign(Object.assign({}, element), extra);
13
- const elementScope = isValidElementScopeValue(_element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
14
- const currentScope = isValidElementScopeValue(localState === null || localState === void 0 ? void 0 : localState.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
15
12
  // Handle legacy stroke properties first
16
13
  let stroke = [DEFAULT_ELEMENT_PROPS.stroke];
17
14
  if (_element.strokeColor) {
18
15
  // Legacy strokeColor property
19
16
  stroke = [
20
- Object.assign(Object.assign({}, DEFAULT_ELEMENT_PROPS.stroke), { content: validateDeprecatedElementContent(_element.strokeColor, DEFAULT_ELEMENT_PROPS.stroke.content), width: restorePrecisionValue(_element.strokeWidth ||
21
- DEFAULT_ELEMENT_PROPS.stroke.width.value, elementScope, currentScope, DEFAULT_ELEMENT_PROPS.stroke.width.value) }),
17
+ Object.assign(Object.assign({}, DEFAULT_ELEMENT_PROPS.stroke), { content: validateDeprecatedElementContent(_element.strokeColor, DEFAULT_ELEMENT_PROPS.stroke.content), width: restoreNumber((_a = _element.strokeWidth) !== null && _a !== void 0 ? _a : DEFAULT_ELEMENT_PROPS.stroke.width, DEFAULT_ELEMENT_PROPS.stroke.width) }),
22
18
  ];
23
19
  }
24
20
  else if (_element.stroke) {
25
21
  // New stroke array property
26
- stroke = _element.stroke.map((s) => validateStroke(s, elementScope, currentScope));
22
+ stroke = _element.stroke.map((s) => validateStroke(s));
27
23
  }
28
24
  // Handle legacy background properties
29
25
  let background = [DEFAULT_ELEMENT_PROPS.background];
@@ -40,54 +36,57 @@ const restoreElementWithProperties = (element, extra, localState, globalState) =
40
36
  const base = {
41
37
  id: _element.id || randomId(),
42
38
  version: _element.version || 1,
43
- versionNonce: (_a = _element.versionNonce) !== null && _a !== void 0 ? _a : 0,
44
- index: (_b = _element.index) !== null && _b !== void 0 ? _b : null,
39
+ versionNonce: (_b = _element.versionNonce) !== null && _b !== void 0 ? _b : 0,
40
+ index: (_c = _element.index) !== null && _c !== void 0 ? _c : null,
45
41
  isDeleted: isValidBooleanValue(_element.isDeleted, false),
46
42
  blending: isValidBlendingValue(_element.blending),
47
43
  stroke,
48
44
  background,
49
45
  opacity: isValidPercentageValue(_element.opacity, DEFAULT_ELEMENT_PROPS.opacity),
50
46
  angle: isValidRadianValue(_element.angle, DEFAULT_ELEMENT_PROPS.angle),
51
- x: restorePrecisionValue(_element.x, elementScope, currentScope, 0),
52
- y: restorePrecisionValue(_element.y, elementScope, currentScope, 0),
53
- scope: elementScope,
54
- label: (_c = _element.label) !== null && _c !== void 0 ? _c : "Lost Element Label",
47
+ x: restoreNumber(_element.x, 0),
48
+ y: restoreNumber(_element.y, 0),
49
+ label: (_d = _element.label) !== null && _d !== void 0 ? _d : "Lost Element Label",
55
50
  isVisible: isValidBoolean(_element.isVisible, DEFAULT_ELEMENT_PROPS.isVisible),
56
51
  isPlot: isValidBoolean(_element.isPlot, DEFAULT_ELEMENT_PROPS.isPlot),
57
- layerId: (_d = _element.layerId) !== null && _d !== void 0 ? _d : null,
52
+ layerId: (_e = _element.layerId) !== null && _e !== void 0 ? _e : null,
58
53
  regionIds: Array.isArray(_element.regionIds) ? _element.regionIds : [],
59
- width: restorePrecisionValue(_element.width, elementScope, currentScope, 0),
60
- height: restorePrecisionValue(_element.height, elementScope, currentScope, 0),
61
- seed: (_e = _element.seed) !== null && _e !== void 0 ? _e : 1,
62
- groupIds: (_f = _element.groupIds) !== null && _f !== void 0 ? _f : [],
54
+ width: ((_element.type === "doc" || _element.type === "pdf") && restoreNumber(_element.width, 0) > 50000)
55
+ ? restoreNumber(_element.width, 0) / 1000
56
+ : restoreNumber(_element.width, 0),
57
+ height: ((_element.type === "doc" || _element.type === "pdf") && restoreNumber(_element.height, 0) > 50000)
58
+ ? restoreNumber(_element.height, 0) / 1000
59
+ : restoreNumber(_element.height, 0),
60
+ seed: (_f = _element.seed) !== null && _f !== void 0 ? _f : 1,
61
+ groupIds: (_g = _element.groupIds) !== null && _g !== void 0 ? _g : [],
63
62
  blockIds: Array.isArray(_element.blockIds) ? _element.blockIds : [],
64
- instanceId: (_g = _element.instanceId) !== null && _g !== void 0 ? _g : null,
65
- frameId: (_h = _element.frameId) !== null && _h !== void 0 ? _h : null,
66
- roundness: restorePrecisionValue(_element.roundness, elementScope, currentScope, DEFAULT_ELEMENT_PROPS.roundness.value),
67
- boundElements: (_j = _element.boundElements) !== null && _j !== void 0 ? _j : undefined,
68
- updated: (_k = _element.updated) !== null && _k !== void 0 ? _k : getUpdatedTimestamp(),
63
+ instanceId: (_h = _element.instanceId) !== null && _h !== void 0 ? _h : null,
64
+ frameId: (_j = _element.frameId) !== null && _j !== void 0 ? _j : null,
65
+ roundness: restoreNumber(_element.roundness, DEFAULT_ELEMENT_PROPS.roundness),
66
+ boundElements: (_k = _element.boundElements) !== null && _k !== void 0 ? _k : undefined,
67
+ updated: (_l = _element.updated) !== null && _l !== void 0 ? _l : getUpdatedTimestamp(),
69
68
  link: _element.link ? normalizeLink(_element.link) : undefined,
70
69
  locked: isValidBooleanValue(_element.locked, false),
71
- description: (_l = _element.description) !== null && _l !== void 0 ? _l : undefined,
70
+ description: (_m = _element.description) !== null && _m !== void 0 ? _m : undefined,
72
71
  };
73
72
  if ("customData" in element || "customData" in extra) {
74
73
  base.customData = _element.customData;
75
74
  }
76
75
  const normalizedRaw = getNormalizedDimensions(base);
77
76
  const normalized = {
78
- x: restorePrecisionValue(normalizedRaw.x, elementScope, currentScope, 0, true),
79
- y: restorePrecisionValue(normalizedRaw.y, elementScope, currentScope, 0, true),
80
- width: restorePrecisionValue(normalizedRaw.width, elementScope, currentScope, 0, true),
81
- height: restorePrecisionValue(normalizedRaw.height, elementScope, currentScope, 0, true),
77
+ x: normalizedRaw.x,
78
+ y: normalizedRaw.y,
79
+ width: normalizedRaw.width,
80
+ height: normalizedRaw.height,
82
81
  };
83
82
  return Object.assign(Object.assign(Object.assign(Object.assign({}, _element), base), normalized), { type: _element.type });
84
83
  };
85
- const restoreElement = (element, currentScope, restoredBlocks, localState, globalState) => {
84
+ const restoreElement = (element, restoredBlocks, localState, globalState) => {
86
85
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
87
86
  // Migration: convert deprecated 'diamond' to 'polygon' with 4 sides
88
87
  if (element.type === "diamond") {
89
88
  const migrated = Object.assign(Object.assign({}, element), { type: "polygon", sides: 4 });
90
- return restoreElement(migrated, currentScope, restoredBlocks, localState);
89
+ return restoreElement(migrated, restoredBlocks, localState);
91
90
  }
92
91
  switch (element.type) {
93
92
  case "text": {
@@ -119,9 +118,8 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
119
118
  const lineHeight = (element.lineHeight && Number.isFinite(element.lineHeight)
120
119
  ? element.lineHeight
121
120
  : detectLineHeight(element));
122
- const restoredLineSpacing = restoreLineSpacing(element.lineSpacing, lineHeight, currentScope);
123
- const textElementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
124
- const finalFontSize = restorePrecisionValue(fontSize, textElementScope, currentScope, DEFAULT_FONT_SIZE);
121
+ const restoredLineSpacing = restoreLineSpacing(element.lineSpacing, lineHeight);
122
+ const finalFontSize = restoreNumber(fontSize, DEFAULT_FONT_SIZE);
125
123
  const restoredTextElement = restoreElementWithProperties(element, {
126
124
  // DucTextElement specific
127
125
  text,
@@ -153,21 +151,18 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
153
151
  return restoredTextElement;
154
152
  }
155
153
  case "freedraw": {
156
- const elementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
157
154
  const points = restoreElementPoints({
158
155
  points: element.points,
159
156
  x: element.x,
160
157
  y: element.y,
161
158
  width: element.width,
162
159
  height: element.height,
163
- elementScope,
164
- currentScope,
165
160
  });
166
161
  return restoreElementWithProperties(element, {
167
162
  points,
168
- size: restorePrecisionValue(element.size, elementScope, currentScope, DEFAULT_FREEDRAW_ELEMENT.size),
163
+ size: restoreNumber(element.size, DEFAULT_FREEDRAW_ELEMENT.size),
169
164
  lastCommittedPoint: element.lastCommittedPoint
170
- ? restorePoint(element.lastCommittedPoint, elementScope, currentScope)
165
+ ? restorePoint(element.lastCommittedPoint)
171
166
  : null,
172
167
  simulatePressure: isValidBoolean(element.simulatePressure, false),
173
168
  pressures: Array.isArray(element.pressures) ? element.pressures : [],
@@ -191,7 +186,6 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
191
186
  case "line": {
192
187
  // Don't normalize points if there are bindings
193
188
  const hasBindings = !!(element.startBinding || element.endBinding);
194
- const elementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
195
189
  const { points, lines } = restoreLinearElementPointsAndLines({
196
190
  points: element.points,
197
191
  lines: element.lines,
@@ -199,20 +193,18 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
199
193
  y: element.y,
200
194
  width: element.width,
201
195
  height: element.height,
202
- elementScope,
203
- currentScope,
204
196
  skipNormalization: hasBindings,
205
197
  });
206
198
  const isEditing = false; // TODO: Handle editingLinearElement properly
207
199
  let finalPoints = points;
208
200
  // Ensure we have at least 2 points for visibility check
209
201
  if (finalPoints.length < 2 && !isEditing) {
210
- const elementWidth = restorePrecisionValue(element.width, elementScope, currentScope, 0);
211
- const elementHeight = restorePrecisionValue(element.height, elementScope, currentScope, 0);
202
+ const elementWidth = restoreNumber(element.width, 0);
203
+ const elementHeight = restoreNumber(element.height, 0);
212
204
  finalPoints = [
213
205
  {
214
- x: getPrecisionValueFromRaw(0, elementScope, currentScope),
215
- y: getPrecisionValueFromRaw(0, elementScope, currentScope),
206
+ x: 0,
207
+ y: 0,
216
208
  mirroring: undefined,
217
209
  },
218
210
  {
@@ -229,16 +221,16 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
229
221
  const processedStartBinding = startBinding &&
230
222
  startBinding.head !== undefined &&
231
223
  (!startBinding.elementId || startBinding.elementId === "")
232
- ? createHeadOnlyBinding(startBinding.head, restoredBlocks, currentScope)
224
+ ? createHeadOnlyBinding(startBinding.head, restoredBlocks)
233
225
  : startBinding
234
- ? repairBinding(element, startBinding, currentScope, restoredBlocks)
226
+ ? repairBinding(element, startBinding, restoredBlocks)
235
227
  : null;
236
228
  const processedEndBinding = endBinding &&
237
229
  endBinding.head !== undefined &&
238
230
  (!endBinding.elementId || endBinding.elementId === "")
239
- ? createHeadOnlyBinding(endBinding.head, restoredBlocks, currentScope)
231
+ ? createHeadOnlyBinding(endBinding.head, restoredBlocks)
240
232
  : endBinding
241
- ? repairBinding(element, endBinding, currentScope, restoredBlocks)
233
+ ? repairBinding(element, endBinding, restoredBlocks)
242
234
  : null;
243
235
  // Create the base restored element
244
236
  // Skip sizeFromPoints override for block instance elements: their stored
@@ -246,24 +238,24 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
246
238
  const isBlockInstanceElement = !!element.instanceId;
247
239
  const sizeFromPoints = !hasBindings &&
248
240
  !isBlockInstanceElement &&
249
- getSizeFromPoints(finalPoints.map(getScopedBezierPointFromDucPoint));
241
+ getSizeFromPoints(finalPoints.map((p) => ({ x: p.x, y: p.y })));
250
242
  let restoredElement = restoreElementWithProperties(element, Object.assign({ points: finalPoints, lines, lastCommittedPoint: element.lastCommittedPoint
251
- ? restorePoint(element.lastCommittedPoint, element.scope, currentScope)
243
+ ? restorePoint(element.lastCommittedPoint)
252
244
  : null, startBinding: processedStartBinding, wipeoutBelow: isValidBooleanValue(element.wipeoutBelow, false), endBinding: processedEndBinding, x: element.x, y: element.y }, (!sizeFromPoints
253
245
  ? {}
254
246
  : {
255
- width: getPrecisionValueFromScoped(sizeFromPoints.width, element.scope, currentScope),
256
- height: getPrecisionValueFromScoped(sizeFromPoints.height, element.scope, currentScope),
247
+ width: sizeFromPoints.width,
248
+ height: sizeFromPoints.height,
257
249
  })), localState);
258
250
  const { points: updatedPoints, lines: updatedLines } = mergeOverlappingPoints(finalPoints, lines, LINE_CONFIRM_THRESHOLD);
259
251
  restoredElement = Object.assign(Object.assign({}, restoredElement), { points: updatedPoints, lines: updatedLines });
260
252
  // Validate path overrides after we have the final points and lines
261
- const validatedPathOverrides = validatePathOverrides(element.pathOverrides, restoredElement, elementScope, currentScope);
253
+ const validatedPathOverrides = validatePathOverrides(element.pathOverrides, restoredElement);
262
254
  return Object.assign(Object.assign({}, restoredElement), { pathOverrides: validatedPathOverrides });
263
255
  }
264
256
  case "arrow": {
265
257
  // since arrow is deprecated, we convert it to line
266
- return restoreElement(Object.assign(Object.assign({}, element), { type: "line", wipeoutBelow: false }), currentScope, restoredBlocks, localState);
258
+ return restoreElement(Object.assign(Object.assign({}, element), { type: "line", wipeoutBelow: false }), restoredBlocks, localState);
267
259
  }
268
260
  case "ellipse": {
269
261
  const ratio = isValidPercentageValue(element.ratio, DEFAULT_ELLIPSE_ELEMENT.ratio);
@@ -287,20 +279,19 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
287
279
  // Stack-like elements
288
280
  case "frame": {
289
281
  const frameElement = element;
290
- return restoreElementWithProperties(frameElement, Object.assign({}, restoreStackElementProperties(frameElement, currentScope)), localState);
282
+ return restoreElementWithProperties(frameElement, Object.assign({}, restoreStackElementProperties(frameElement)), localState);
291
283
  }
292
284
  case "plot": {
293
285
  const plotElement = element;
294
- const elementScope = isValidElementScopeValue(plotElement.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
295
286
  // Restore base stack element properties (label, visibility, etc.)
296
- const stackProperties = restoreStackElementProperties(plotElement, currentScope);
287
+ const stackProperties = restoreStackElementProperties(plotElement);
297
288
  // Restore layout-specific properties
298
289
  const layout = {
299
290
  margins: {
300
- top: restorePrecisionValue((_d = (_c = plotElement.layout) === null || _c === void 0 ? void 0 : _c.margins) === null || _d === void 0 ? void 0 : _d.top, elementScope, currentScope, 0),
301
- right: restorePrecisionValue((_f = (_e = plotElement.layout) === null || _e === void 0 ? void 0 : _e.margins) === null || _f === void 0 ? void 0 : _f.right, elementScope, currentScope, 0),
302
- bottom: restorePrecisionValue((_h = (_g = plotElement.layout) === null || _g === void 0 ? void 0 : _g.margins) === null || _h === void 0 ? void 0 : _h.bottom, elementScope, currentScope, 0),
303
- left: restorePrecisionValue((_k = (_j = plotElement.layout) === null || _j === void 0 ? void 0 : _j.margins) === null || _k === void 0 ? void 0 : _k.left, elementScope, currentScope, 0),
291
+ top: restoreNumber((_d = (_c = plotElement.layout) === null || _c === void 0 ? void 0 : _c.margins) === null || _d === void 0 ? void 0 : _d.top, 0),
292
+ right: restoreNumber((_f = (_e = plotElement.layout) === null || _e === void 0 ? void 0 : _e.margins) === null || _f === void 0 ? void 0 : _f.right, 0),
293
+ bottom: restoreNumber((_h = (_g = plotElement.layout) === null || _g === void 0 ? void 0 : _g.margins) === null || _h === void 0 ? void 0 : _h.bottom, 0),
294
+ left: restoreNumber((_k = (_j = plotElement.layout) === null || _j === void 0 ? void 0 : _j.margins) === null || _k === void 0 ? void 0 : _k.left, 0),
304
295
  },
305
296
  };
306
297
  return restoreElementWithProperties(plotElement, Object.assign(Object.assign({}, stackProperties), { layout }), localState, globalState);
@@ -314,7 +305,7 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
314
305
  // Complex elements requiring specific restore logic
315
306
  case "table": {
316
307
  const tableElement = element;
317
- const defaultData = getDefaultTableData(currentScope);
308
+ const defaultData = getDefaultTableData();
318
309
  return restoreElementWithProperties(tableElement, {
319
310
  fileId: isValidString(tableElement.fileId) ||
320
311
  defaultData.fileId,
@@ -364,19 +355,15 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
364
355
  /**
365
356
  * Restores a point that might have legacy format (x,y as numbers)
366
357
  * @param point - The point to restore
367
- * @param elementScope - The scope to use for the precision values
368
358
  * @returns A properly formatted DucPoint
369
359
  */
370
- export const restorePoint = (point, elementScope, currentScope) => {
360
+ export const restorePoint = (point) => {
371
361
  if (!point) {
372
362
  return null;
373
363
  }
374
364
  // Handle x and y conversion
375
- const xValue = restorePrecisionValue(point.x, elementScope, currentScope);
376
- const yValue = restorePrecisionValue(point.y, elementScope, currentScope);
377
- if (!xValue || !yValue) {
378
- return null;
379
- }
365
+ const xValue = restoreNumber(point.x, 0);
366
+ const yValue = restoreNumber(point.y, 0);
380
367
  // Only keep the new DucPoint structure, ignore legacy properties
381
368
  return {
382
369
  x: xValue,
@@ -384,17 +371,17 @@ export const restorePoint = (point, elementScope, currentScope) => {
384
371
  mirroring: isValidBezierMirroringValue(point.mirroring),
385
372
  };
386
373
  };
387
- const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementScope, currentScope, }) => {
388
- // Convert input parameters to plain numbers if they're precision values
389
- const validatedWidth = restorePrecisionValue(width, elementScope, currentScope, 0);
390
- const validatedHeight = restorePrecisionValue(height, elementScope, currentScope, 0);
374
+ const restoreElementPoints = ({ points: oldPoints, x, y, width, height, }) => {
375
+ // Convert input parameters to plain numbers
376
+ const validatedWidth = restoreNumber(width, 0);
377
+ const validatedHeight = restoreNumber(height, 0);
391
378
  // Process the points array with proper conversion
392
379
  let points = [];
393
380
  if (typeof oldPoints === "object" && Array.isArray(oldPoints)) {
394
381
  const migratedPoints = migratePoints(oldPoints);
395
382
  points = migratedPoints
396
383
  .map((point) => {
397
- const restoredPoint = restorePoint(point, elementScope, currentScope);
384
+ const restoredPoint = restorePoint(point);
398
385
  if (!restoredPoint) {
399
386
  return null;
400
387
  }
@@ -414,8 +401,8 @@ const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementS
414
401
  // Default two points
415
402
  points = [
416
403
  {
417
- x: getPrecisionValueFromRaw(0, elementScope, currentScope),
418
- y: getPrecisionValueFromRaw(0, elementScope, currentScope),
404
+ x: 0,
405
+ y: 0,
419
406
  mirroring: undefined,
420
407
  },
421
408
  {
@@ -426,27 +413,25 @@ const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementS
426
413
  ];
427
414
  }
428
415
  if (points.length === 2 &&
429
- points[1] && // Should always be true if points.length === 2
430
- points[1].x.value === 0 &&
431
- points[1].y.value === 0 &&
432
- (validatedWidth.value !== 0 || validatedHeight.value !== 0)) {
416
+ points[1] &&
417
+ points[1].x === 0 &&
418
+ points[1].y === 0 &&
419
+ (validatedWidth !== 0 || validatedHeight !== 0)) {
433
420
  points[1] = Object.assign(Object.assign({}, points[1]), { x: validatedWidth, y: validatedHeight });
434
421
  }
435
422
  return points;
436
423
  };
437
- const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines, x, y, width, height, elementScope, currentScope, skipNormalization, }) => {
438
- const validatedX = restorePrecisionValue(x, elementScope, currentScope, 0);
439
- const validatedY = restorePrecisionValue(y, elementScope, currentScope, 0);
440
- const validatedWidth = restorePrecisionValue(width, elementScope, currentScope, 0);
441
- const validatedHeight = restorePrecisionValue(height, elementScope, currentScope, 0);
424
+ const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines, x, y, width, height, skipNormalization, }) => {
425
+ const validatedX = restoreNumber(x, 0);
426
+ const validatedY = restoreNumber(y, 0);
427
+ const validatedWidth = restoreNumber(width, 0);
428
+ const validatedHeight = restoreNumber(height, 0);
442
429
  let points = restoreElementPoints({
443
430
  points: oldPoints,
444
431
  x,
445
432
  y,
446
433
  width,
447
434
  height,
448
- elementScope,
449
- currentScope,
450
435
  });
451
436
  let lines = oldLines;
452
437
  if (lines === undefined || lines === null) {
@@ -464,13 +449,13 @@ const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines
464
449
  {
465
450
  index: line[0].index,
466
451
  handle: line[0].handle
467
- ? restorePoint(line[0].handle, elementScope, currentScope)
452
+ ? restorePoint(line[0].handle)
468
453
  : null,
469
454
  },
470
455
  {
471
456
  index: line[1].index,
472
457
  handle: line[1].handle
473
- ? restorePoint(line[1].handle, elementScope, currentScope)
458
+ ? restorePoint(line[1].handle)
474
459
  : null,
475
460
  },
476
461
  ];
@@ -478,24 +463,23 @@ const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines
478
463
  }
479
464
  if (!skipNormalization &&
480
465
  points.length >= 2 &&
481
- (points[0].x.value !== 0 || points[0].y.value !== 0)) {
466
+ (points[0].x !== 0 || points[0].y !== 0)) {
482
467
  const normalizedResult = getNormalizedPoints({
483
468
  points,
484
469
  lines,
485
470
  x: validatedX,
486
471
  y: validatedY,
487
- scope: elementScope,
488
- }, currentScope);
472
+ });
489
473
  const firstPoint = points[0];
490
474
  const lastPoint = points[points.length - 1];
491
475
  points = normalizedResult.points;
492
476
  lines = normalizedResult.lines;
493
477
  if (oldPoints && oldPoints.length === points.length) {
494
- if (firstPoint.x.value !== 0 || firstPoint.y.value !== 0) {
478
+ if (firstPoint.x !== 0 || firstPoint.y !== 0) {
495
479
  points[0] = Object.assign({}, points[0]);
496
480
  }
497
- if (lastPoint.x.value !== validatedWidth.value ||
498
- lastPoint.y.value !== validatedHeight.value) {
481
+ if (lastPoint.x !== validatedWidth ||
482
+ lastPoint.y !== validatedHeight) {
499
483
  points[points.length - 1] = Object.assign({}, points[points.length - 1]);
500
484
  }
501
485
  }
@@ -587,13 +571,29 @@ export const migrateArrayOrderToZIndex = (elements) => {
587
571
  return element;
588
572
  });
589
573
  };
590
- export const restoreElements = (elements, currentScope, restoredBlocks, opts) => {
574
+ export const restoreElements = (elements, second, third, fourth) => {
575
+ let restoredBlocks = [];
576
+ let opts;
577
+ if (Array.isArray(second)) {
578
+ restoredBlocks = second;
579
+ opts = third;
580
+ }
581
+ else if (second && typeof second === "object" && ("syncInvalidIndices" in second || "localState" in second || "passThroughElementIds" in second)) {
582
+ opts = second;
583
+ }
584
+ else if (Array.isArray(third)) {
585
+ restoredBlocks = third;
586
+ opts = fourth;
587
+ }
588
+ else if (third && typeof third === "object") {
589
+ opts = third;
590
+ }
591
591
  const existingIds = new Set();
592
592
  const idMap = new Map();
593
593
  // First restore all elements with their original properties
594
594
  const restored = (elements || []).reduce((elements, element) => {
595
595
  if (element.type !== "selection") {
596
- let migratedElement = restoreElement(element, currentScope, restoredBlocks, opts === null || opts === void 0 ? void 0 : opts.localState);
596
+ let migratedElement = restoreElement(element, restoredBlocks, opts === null || opts === void 0 ? void 0 : opts.localState);
597
597
  if (!migratedElement) {
598
598
  // element failed to restore — skip
599
599
  }
@@ -627,7 +627,7 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
627
627
  }
628
628
  }
629
629
  let restoredElements = (opts === null || opts === void 0 ? void 0 : opts.syncInvalidIndices)
630
- ? opts.syncInvalidIndices(restored, currentScope)
630
+ ? opts.syncInvalidIndices(restored)
631
631
  : restored;
632
632
  // Migrate array ordering to explicit z-index values if needed
633
633
  restoredElements = migrateArrayOrderToZIndex(restoredElements);
@@ -646,7 +646,7 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
646
646
  repairContainerElement(element, restoredElementsMap);
647
647
  }
648
648
  if (opts.refreshDimensions && isTextElement(element)) {
649
- Object.assign(element, refreshTextDimensions(element, getContainerElement(element, restoredElementsMap), restoredElementsMap, currentScope));
649
+ Object.assign(element, refreshTextDimensions(element, getContainerElement(element, restoredElementsMap), restoredElementsMap));
650
650
  }
651
651
  if (isLinearElement(element)) {
652
652
  // Helper function to check if we should keep a binding
@@ -710,18 +710,11 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
710
710
  }
711
711
  return restoredElements;
712
712
  };
713
- export const isValidElementScopeValue = (value, mainScope = NEUTRAL_SCOPE) => {
714
- // Only check if the provided value is valid
715
- if (value !== undefined && Object.keys(ScaleFactors).includes(value)) {
716
- return value;
717
- }
718
- return mainScope;
719
- };
720
- const restoreLineSpacing = (lineSpacing, legacyLineHeight, currentScope) => {
713
+ const restoreLineSpacing = (lineSpacing, legacyLineHeight) => {
721
714
  if (lineSpacing && lineSpacing.type && lineSpacing.value) {
722
715
  return {
723
716
  type: isValidLineSpacingTypeValue(lineSpacing.type),
724
- value: restorePrecisionValue(lineSpacing.value, currentScope, currentScope, 1.15, true),
717
+ value: restoreNumber(lineSpacing.value, 1.15),
725
718
  };
726
719
  }
727
720
  // Fallback to legacy lineHeight
@@ -745,7 +738,7 @@ const restoreDocumentGridConfig = (gridConfig) => {
745
738
  gapX: typeof gridConfig.gapX === "number" ? gridConfig.gapX : 0,
746
739
  gapY: typeof gridConfig.gapY === "number" ? gridConfig.gapY : 0,
747
740
  firstPageAlone: typeof gridConfig.firstPageAlone === "boolean" ? gridConfig.firstPageAlone : false,
748
- scale: typeof gridConfig.scale === "number" ? gridConfig.scale : 1,
741
+ scale: typeof gridConfig.scale === "number" && gridConfig.scale > 0 && gridConfig.scale <= 50 ? gridConfig.scale : 1,
749
742
  };
750
743
  };
751
744
  const getFontFamilyByName = (fontFamilyName) => {
@@ -754,7 +747,7 @@ const getFontFamilyByName = (fontFamilyName) => {
754
747
  }
755
748
  return DEFAULT_FONT_FAMILY;
756
749
  };
757
- const repairBinding = (element, binding, currentScope, restoredBlocks) => {
750
+ const repairBinding = (element, binding, restoredBlocks) => {
758
751
  var _a;
759
752
  if (!binding) {
760
753
  return null;
@@ -762,10 +755,8 @@ const repairBinding = (element, binding, currentScope, restoredBlocks) => {
762
755
  // If this is a head-only binding, normalize it
763
756
  if (binding.head !== undefined &&
764
757
  (!binding.elementId || binding.elementId === "")) {
765
- return createHeadOnlyBinding(binding.head, restoredBlocks, currentScope);
758
+ return createHeadOnlyBinding(binding.head, restoredBlocks);
766
759
  }
767
- // Get the element's scope for conversion
768
- const elementScope = element ? element.scope : NEUTRAL_SCOPE;
769
760
  // Ensure we preserve the point attribute for linear-to-linear bindings
770
761
  const pointData = binding.point
771
762
  ? {
@@ -778,14 +769,14 @@ const repairBinding = (element, binding, currentScope, restoredBlocks) => {
778
769
  },
779
770
  }
780
771
  : { point: null };
781
- return Object.assign({ elementId: binding.elementId || "", focus: typeof binding.focus === "number" ? binding.focus : 0, gap: restorePrecisionValue(typeof binding.gap === "number" ? Math.max(0, binding.gap) : 0, elementScope, currentScope), head: isValidDucHead(binding.head, restoredBlocks), fixedPoint: element && isElbowArrow(element)
772
+ return Object.assign({ elementId: binding.elementId || "", focus: typeof binding.focus === "number" ? binding.focus : 0, gap: restoreNumber(binding.gap, 0), head: isValidDucHead(binding.head, restoredBlocks || []), fixedPoint: element && isElbowArrow(element)
782
773
  ? normalizeFixedPoint((_a = binding.fixedPoint) !== null && _a !== void 0 ? _a : { x: 0.5, y: 0.5 })
783
774
  : null }, pointData);
784
775
  };
785
776
  /**
786
777
  * Validates a DucPath object and ensures its line indices form a valid closed path
787
778
  */
788
- const validateDucPath = (path, element, elementScope, currentScope) => {
779
+ const validateDucPath = (path, element) => {
789
780
  if (!path || !path.lineIndices || !Array.isArray(path.lineIndices)) {
790
781
  return null;
791
782
  }
@@ -806,21 +797,21 @@ const validateDucPath = (path, element, elementScope, currentScope) => {
806
797
  lineIndices: validLineIndices,
807
798
  background: path.background ? validateBackground(path.background) : null,
808
799
  stroke: path.stroke
809
- ? validateStroke(path.stroke, elementScope, currentScope)
800
+ ? validateStroke(path.stroke)
810
801
  : null,
811
802
  };
812
803
  };
813
804
  /**
814
805
  * Validates and filters path overrides for a linear element
815
806
  */
816
- const validatePathOverrides = (pathOverrides, element, elementScope, currentScope) => {
807
+ const validatePathOverrides = (pathOverrides, element) => {
817
808
  if (!pathOverrides || !Array.isArray(pathOverrides)) {
818
809
  return [];
819
810
  }
820
811
  const validPaths = [];
821
812
  const usedLineIndices = new Set();
822
813
  for (const pathOverride of pathOverrides) {
823
- const validatedPath = validateDucPath(pathOverride, element, elementScope, currentScope);
814
+ const validatedPath = validateDucPath(pathOverride, element);
824
815
  if (validatedPath) {
825
816
  // Check for overlapping line indices with previously validated paths
826
817
  const hasOverlap = validatedPath.lineIndices.some((index) => usedLineIndices.has(index));
@@ -855,14 +846,14 @@ const isValidCutAngleValue = (value, defaultValue) => {
855
846
  }
856
847
  return radian;
857
848
  };
858
- const createHeadOnlyBinding = (head, restoredBlocks, currentScope) => {
849
+ const createHeadOnlyBinding = (head, restoredBlocks) => {
859
850
  return {
860
851
  elementId: "",
861
852
  focus: 0,
862
- gap: getPrecisionValueFromRaw(0, currentScope, currentScope),
853
+ gap: 0,
863
854
  fixedPoint: null,
864
855
  point: null,
865
- head: isValidDucHead(head, restoredBlocks),
856
+ head: isValidDucHead(head, restoredBlocks || []),
866
857
  };
867
858
  };
868
859
  const validateDeprecatedElementContent = (color, defaultContent) => {
@@ -876,6 +867,6 @@ const isValidLineSpacingTypeValue = (value) => {
876
867
  /**
877
868
  * Restore properties specific to Stack-like elements (_DucStackElementBase)
878
869
  */
879
- const restoreStackElementProperties = (element, currentScope) => {
870
+ const restoreStackElementProperties = (element) => {
880
871
  return Object.assign(Object.assign({}, restoreDucStackProperties(element)), { clip: isValidBooleanValue(element.clip, false), labelVisible: isValidBooleanValue(element.labelVisible, true) });
881
872
  };
@@ -0,0 +1,21 @@
1
+ import type { DucModelElement } from "../types/elements";
2
+ /**
3
+ * Check if a color is grayscale (neutral color from white to grey to black or transparent).
4
+ * Returns true if the color has no actual chromatic hue.
5
+ * Directly mirrors packages/core/canvas/utils/thumbnailGenerator.ts.
6
+ */
7
+ export declare const isGrayscaleColor: (color: string) => boolean;
8
+ /**
9
+ * Determines the effective background color for thumbnail generation.
10
+ * If none provided (or "transparent"), defaults to "transparent".
11
+ * If an explicit background color is provided, preserves that color.
12
+ */
13
+ export declare const resolveThumbnailBackground: (backgroundColor?: string) => string;
14
+ /**
15
+ * Calculates updated element dimensions preserving the aspect ratio of the generated thumbnail.
16
+ * Directly mirrors packages/client/ui/blocks/core/three/lib/model-thumbnail-bounds.ts.
17
+ */
18
+ export declare const getModelThumbnailBoundsUpdate: (element: DucModelElement, thumbnailWidth: number, thumbnailHeight: number) => {
19
+ width: number;
20
+ height: number;
21
+ } | null;