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,28 +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";
5
+ import { updateModelCodeElementIds } from "./updateModelCode";
6
6
  import { LINE_SPACING_TYPE, } from "../enums";
7
7
  const PARAMETRIC_SOURCE_TYPE = { CODE: 10, FILE: 11 };
8
8
  import tinycolor from "tinycolor2";
9
9
  const restoreElementWithProperties = (element, extra, localState, globalState) => {
10
- 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;
11
11
  const _element = Object.assign(Object.assign({}, element), extra);
12
- const elementScope = isValidElementScopeValue(_element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
13
- const currentScope = isValidElementScopeValue(localState === null || localState === void 0 ? void 0 : localState.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
14
12
  // Handle legacy stroke properties first
15
13
  let stroke = [DEFAULT_ELEMENT_PROPS.stroke];
16
14
  if (_element.strokeColor) {
17
15
  // Legacy strokeColor property
18
16
  stroke = [
19
- Object.assign(Object.assign({}, DEFAULT_ELEMENT_PROPS.stroke), { content: validateDeprecatedElementContent(_element.strokeColor, DEFAULT_ELEMENT_PROPS.stroke.content), width: restorePrecisionValue(_element.strokeWidth ||
20
- 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) }),
21
18
  ];
22
19
  }
23
20
  else if (_element.stroke) {
24
21
  // New stroke array property
25
- stroke = _element.stroke.map((s) => validateStroke(s, elementScope, currentScope));
22
+ stroke = _element.stroke.map((s) => validateStroke(s));
26
23
  }
27
24
  // Handle legacy background properties
28
25
  let background = [DEFAULT_ELEMENT_PROPS.background];
@@ -39,54 +36,57 @@ const restoreElementWithProperties = (element, extra, localState, globalState) =
39
36
  const base = {
40
37
  id: _element.id || randomId(),
41
38
  version: _element.version || 1,
42
- versionNonce: (_a = _element.versionNonce) !== null && _a !== void 0 ? _a : 0,
43
- 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,
44
41
  isDeleted: isValidBooleanValue(_element.isDeleted, false),
45
42
  blending: isValidBlendingValue(_element.blending),
46
43
  stroke,
47
44
  background,
48
45
  opacity: isValidPercentageValue(_element.opacity, DEFAULT_ELEMENT_PROPS.opacity),
49
46
  angle: isValidRadianValue(_element.angle, DEFAULT_ELEMENT_PROPS.angle),
50
- x: restorePrecisionValue(_element.x, elementScope, currentScope, 0),
51
- y: restorePrecisionValue(_element.y, elementScope, currentScope, 0),
52
- scope: elementScope,
53
- 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",
54
50
  isVisible: isValidBoolean(_element.isVisible, DEFAULT_ELEMENT_PROPS.isVisible),
55
51
  isPlot: isValidBoolean(_element.isPlot, DEFAULT_ELEMENT_PROPS.isPlot),
56
- layerId: (_d = _element.layerId) !== null && _d !== void 0 ? _d : null,
52
+ layerId: (_e = _element.layerId) !== null && _e !== void 0 ? _e : null,
57
53
  regionIds: Array.isArray(_element.regionIds) ? _element.regionIds : [],
58
- width: restorePrecisionValue(_element.width, elementScope, currentScope, 0),
59
- height: restorePrecisionValue(_element.height, elementScope, currentScope, 0),
60
- seed: (_e = _element.seed) !== null && _e !== void 0 ? _e : 1,
61
- 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 : [],
62
62
  blockIds: Array.isArray(_element.blockIds) ? _element.blockIds : [],
63
- instanceId: (_g = _element.instanceId) !== null && _g !== void 0 ? _g : null,
64
- frameId: (_h = _element.frameId) !== null && _h !== void 0 ? _h : null,
65
- roundness: restorePrecisionValue(_element.roundness, elementScope, currentScope, DEFAULT_ELEMENT_PROPS.roundness.value),
66
- boundElements: (_j = _element.boundElements) !== null && _j !== void 0 ? _j : undefined,
67
- 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(),
68
68
  link: _element.link ? normalizeLink(_element.link) : undefined,
69
69
  locked: isValidBooleanValue(_element.locked, false),
70
- description: (_l = _element.description) !== null && _l !== void 0 ? _l : undefined,
70
+ description: (_m = _element.description) !== null && _m !== void 0 ? _m : undefined,
71
71
  };
72
72
  if ("customData" in element || "customData" in extra) {
73
73
  base.customData = _element.customData;
74
74
  }
75
75
  const normalizedRaw = getNormalizedDimensions(base);
76
76
  const normalized = {
77
- x: restorePrecisionValue(normalizedRaw.x, elementScope, currentScope, 0, true),
78
- y: restorePrecisionValue(normalizedRaw.y, elementScope, currentScope, 0, true),
79
- width: restorePrecisionValue(normalizedRaw.width, elementScope, currentScope, 0, true),
80
- height: restorePrecisionValue(normalizedRaw.height, elementScope, currentScope, 0, true),
77
+ x: normalizedRaw.x,
78
+ y: normalizedRaw.y,
79
+ width: normalizedRaw.width,
80
+ height: normalizedRaw.height,
81
81
  };
82
82
  return Object.assign(Object.assign(Object.assign(Object.assign({}, _element), base), normalized), { type: _element.type });
83
83
  };
84
- const restoreElement = (element, currentScope, restoredBlocks, localState, globalState) => {
84
+ const restoreElement = (element, restoredBlocks, localState, globalState) => {
85
85
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
86
86
  // Migration: convert deprecated 'diamond' to 'polygon' with 4 sides
87
87
  if (element.type === "diamond") {
88
88
  const migrated = Object.assign(Object.assign({}, element), { type: "polygon", sides: 4 });
89
- return restoreElement(migrated, currentScope, restoredBlocks, localState);
89
+ return restoreElement(migrated, restoredBlocks, localState);
90
90
  }
91
91
  switch (element.type) {
92
92
  case "text": {
@@ -118,9 +118,8 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
118
118
  const lineHeight = (element.lineHeight && Number.isFinite(element.lineHeight)
119
119
  ? element.lineHeight
120
120
  : detectLineHeight(element));
121
- const restoredLineSpacing = restoreLineSpacing(element.lineSpacing, lineHeight, currentScope);
122
- const textElementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
123
- const finalFontSize = restorePrecisionValue(fontSize, textElementScope, currentScope, DEFAULT_FONT_SIZE);
121
+ const restoredLineSpacing = restoreLineSpacing(element.lineSpacing, lineHeight);
122
+ const finalFontSize = restoreNumber(fontSize, DEFAULT_FONT_SIZE);
124
123
  const restoredTextElement = restoreElementWithProperties(element, {
125
124
  // DucTextElement specific
126
125
  text,
@@ -152,21 +151,18 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
152
151
  return restoredTextElement;
153
152
  }
154
153
  case "freedraw": {
155
- const elementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
156
154
  const points = restoreElementPoints({
157
155
  points: element.points,
158
156
  x: element.x,
159
157
  y: element.y,
160
158
  width: element.width,
161
159
  height: element.height,
162
- elementScope,
163
- currentScope,
164
160
  });
165
161
  return restoreElementWithProperties(element, {
166
162
  points,
167
- size: restorePrecisionValue(element.size, elementScope, currentScope, DEFAULT_FREEDRAW_ELEMENT.size),
163
+ size: restoreNumber(element.size, DEFAULT_FREEDRAW_ELEMENT.size),
168
164
  lastCommittedPoint: element.lastCommittedPoint
169
- ? restorePoint(element.lastCommittedPoint, elementScope, currentScope)
165
+ ? restorePoint(element.lastCommittedPoint)
170
166
  : null,
171
167
  simulatePressure: isValidBoolean(element.simulatePressure, false),
172
168
  pressures: Array.isArray(element.pressures) ? element.pressures : [],
@@ -190,7 +186,6 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
190
186
  case "line": {
191
187
  // Don't normalize points if there are bindings
192
188
  const hasBindings = !!(element.startBinding || element.endBinding);
193
- const elementScope = isValidElementScopeValue(element.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
194
189
  const { points, lines } = restoreLinearElementPointsAndLines({
195
190
  points: element.points,
196
191
  lines: element.lines,
@@ -198,20 +193,18 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
198
193
  y: element.y,
199
194
  width: element.width,
200
195
  height: element.height,
201
- elementScope,
202
- currentScope,
203
196
  skipNormalization: hasBindings,
204
197
  });
205
198
  const isEditing = false; // TODO: Handle editingLinearElement properly
206
199
  let finalPoints = points;
207
200
  // Ensure we have at least 2 points for visibility check
208
201
  if (finalPoints.length < 2 && !isEditing) {
209
- const elementWidth = restorePrecisionValue(element.width, elementScope, currentScope, 0);
210
- const elementHeight = restorePrecisionValue(element.height, elementScope, currentScope, 0);
202
+ const elementWidth = restoreNumber(element.width, 0);
203
+ const elementHeight = restoreNumber(element.height, 0);
211
204
  finalPoints = [
212
205
  {
213
- x: getPrecisionValueFromRaw(0, elementScope, currentScope),
214
- y: getPrecisionValueFromRaw(0, elementScope, currentScope),
206
+ x: 0,
207
+ y: 0,
215
208
  mirroring: undefined,
216
209
  },
217
210
  {
@@ -228,16 +221,16 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
228
221
  const processedStartBinding = startBinding &&
229
222
  startBinding.head !== undefined &&
230
223
  (!startBinding.elementId || startBinding.elementId === "")
231
- ? createHeadOnlyBinding(startBinding.head, restoredBlocks, currentScope)
224
+ ? createHeadOnlyBinding(startBinding.head, restoredBlocks)
232
225
  : startBinding
233
- ? repairBinding(element, startBinding, currentScope, restoredBlocks)
226
+ ? repairBinding(element, startBinding, restoredBlocks)
234
227
  : null;
235
228
  const processedEndBinding = endBinding &&
236
229
  endBinding.head !== undefined &&
237
230
  (!endBinding.elementId || endBinding.elementId === "")
238
- ? createHeadOnlyBinding(endBinding.head, restoredBlocks, currentScope)
231
+ ? createHeadOnlyBinding(endBinding.head, restoredBlocks)
239
232
  : endBinding
240
- ? repairBinding(element, endBinding, currentScope, restoredBlocks)
233
+ ? repairBinding(element, endBinding, restoredBlocks)
241
234
  : null;
242
235
  // Create the base restored element
243
236
  // Skip sizeFromPoints override for block instance elements: their stored
@@ -245,24 +238,24 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
245
238
  const isBlockInstanceElement = !!element.instanceId;
246
239
  const sizeFromPoints = !hasBindings &&
247
240
  !isBlockInstanceElement &&
248
- getSizeFromPoints(finalPoints.map(getScopedBezierPointFromDucPoint));
241
+ getSizeFromPoints(finalPoints.map((p) => ({ x: p.x, y: p.y })));
249
242
  let restoredElement = restoreElementWithProperties(element, Object.assign({ points: finalPoints, lines, lastCommittedPoint: element.lastCommittedPoint
250
- ? restorePoint(element.lastCommittedPoint, element.scope, currentScope)
243
+ ? restorePoint(element.lastCommittedPoint)
251
244
  : null, startBinding: processedStartBinding, wipeoutBelow: isValidBooleanValue(element.wipeoutBelow, false), endBinding: processedEndBinding, x: element.x, y: element.y }, (!sizeFromPoints
252
245
  ? {}
253
246
  : {
254
- width: getPrecisionValueFromScoped(sizeFromPoints.width, element.scope, currentScope),
255
- height: getPrecisionValueFromScoped(sizeFromPoints.height, element.scope, currentScope),
247
+ width: sizeFromPoints.width,
248
+ height: sizeFromPoints.height,
256
249
  })), localState);
257
250
  const { points: updatedPoints, lines: updatedLines } = mergeOverlappingPoints(finalPoints, lines, LINE_CONFIRM_THRESHOLD);
258
251
  restoredElement = Object.assign(Object.assign({}, restoredElement), { points: updatedPoints, lines: updatedLines });
259
252
  // Validate path overrides after we have the final points and lines
260
- const validatedPathOverrides = validatePathOverrides(element.pathOverrides, restoredElement, elementScope, currentScope);
253
+ const validatedPathOverrides = validatePathOverrides(element.pathOverrides, restoredElement);
261
254
  return Object.assign(Object.assign({}, restoredElement), { pathOverrides: validatedPathOverrides });
262
255
  }
263
256
  case "arrow": {
264
257
  // since arrow is deprecated, we convert it to line
265
- 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);
266
259
  }
267
260
  case "ellipse": {
268
261
  const ratio = isValidPercentageValue(element.ratio, DEFAULT_ELLIPSE_ELEMENT.ratio);
@@ -286,20 +279,19 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
286
279
  // Stack-like elements
287
280
  case "frame": {
288
281
  const frameElement = element;
289
- return restoreElementWithProperties(frameElement, Object.assign({}, restoreStackElementProperties(frameElement, currentScope)), localState);
282
+ return restoreElementWithProperties(frameElement, Object.assign({}, restoreStackElementProperties(frameElement)), localState);
290
283
  }
291
284
  case "plot": {
292
285
  const plotElement = element;
293
- const elementScope = isValidElementScopeValue(plotElement.scope, globalState === null || globalState === void 0 ? void 0 : globalState.mainScope);
294
286
  // Restore base stack element properties (label, visibility, etc.)
295
- const stackProperties = restoreStackElementProperties(plotElement, currentScope);
287
+ const stackProperties = restoreStackElementProperties(plotElement);
296
288
  // Restore layout-specific properties
297
289
  const layout = {
298
290
  margins: {
299
- 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),
300
- 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),
301
- 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),
302
- 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),
303
295
  },
304
296
  };
305
297
  return restoreElementWithProperties(plotElement, Object.assign(Object.assign({}, stackProperties), { layout }), localState, globalState);
@@ -313,7 +305,7 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
313
305
  // Complex elements requiring specific restore logic
314
306
  case "table": {
315
307
  const tableElement = element;
316
- const defaultData = getDefaultTableData(currentScope);
308
+ const defaultData = getDefaultTableData();
317
309
  return restoreElementWithProperties(tableElement, {
318
310
  fileId: isValidString(tableElement.fileId) ||
319
311
  defaultData.fileId,
@@ -363,19 +355,15 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
363
355
  /**
364
356
  * Restores a point that might have legacy format (x,y as numbers)
365
357
  * @param point - The point to restore
366
- * @param elementScope - The scope to use for the precision values
367
358
  * @returns A properly formatted DucPoint
368
359
  */
369
- export const restorePoint = (point, elementScope, currentScope) => {
360
+ export const restorePoint = (point) => {
370
361
  if (!point) {
371
362
  return null;
372
363
  }
373
364
  // Handle x and y conversion
374
- const xValue = restorePrecisionValue(point.x, elementScope, currentScope);
375
- const yValue = restorePrecisionValue(point.y, elementScope, currentScope);
376
- if (!xValue || !yValue) {
377
- return null;
378
- }
365
+ const xValue = restoreNumber(point.x, 0);
366
+ const yValue = restoreNumber(point.y, 0);
379
367
  // Only keep the new DucPoint structure, ignore legacy properties
380
368
  return {
381
369
  x: xValue,
@@ -383,17 +371,17 @@ export const restorePoint = (point, elementScope, currentScope) => {
383
371
  mirroring: isValidBezierMirroringValue(point.mirroring),
384
372
  };
385
373
  };
386
- const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementScope, currentScope, }) => {
387
- // Convert input parameters to plain numbers if they're precision values
388
- const validatedWidth = restorePrecisionValue(width, elementScope, currentScope, 0);
389
- 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);
390
378
  // Process the points array with proper conversion
391
379
  let points = [];
392
380
  if (typeof oldPoints === "object" && Array.isArray(oldPoints)) {
393
381
  const migratedPoints = migratePoints(oldPoints);
394
382
  points = migratedPoints
395
383
  .map((point) => {
396
- const restoredPoint = restorePoint(point, elementScope, currentScope);
384
+ const restoredPoint = restorePoint(point);
397
385
  if (!restoredPoint) {
398
386
  return null;
399
387
  }
@@ -413,8 +401,8 @@ const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementS
413
401
  // Default two points
414
402
  points = [
415
403
  {
416
- x: getPrecisionValueFromRaw(0, elementScope, currentScope),
417
- y: getPrecisionValueFromRaw(0, elementScope, currentScope),
404
+ x: 0,
405
+ y: 0,
418
406
  mirroring: undefined,
419
407
  },
420
408
  {
@@ -425,27 +413,25 @@ const restoreElementPoints = ({ points: oldPoints, x, y, width, height, elementS
425
413
  ];
426
414
  }
427
415
  if (points.length === 2 &&
428
- points[1] && // Should always be true if points.length === 2
429
- points[1].x.value === 0 &&
430
- points[1].y.value === 0 &&
431
- (validatedWidth.value !== 0 || validatedHeight.value !== 0)) {
416
+ points[1] &&
417
+ points[1].x === 0 &&
418
+ points[1].y === 0 &&
419
+ (validatedWidth !== 0 || validatedHeight !== 0)) {
432
420
  points[1] = Object.assign(Object.assign({}, points[1]), { x: validatedWidth, y: validatedHeight });
433
421
  }
434
422
  return points;
435
423
  };
436
- const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines, x, y, width, height, elementScope, currentScope, skipNormalization, }) => {
437
- const validatedX = restorePrecisionValue(x, elementScope, currentScope, 0);
438
- const validatedY = restorePrecisionValue(y, elementScope, currentScope, 0);
439
- const validatedWidth = restorePrecisionValue(width, elementScope, currentScope, 0);
440
- 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);
441
429
  let points = restoreElementPoints({
442
430
  points: oldPoints,
443
431
  x,
444
432
  y,
445
433
  width,
446
434
  height,
447
- elementScope,
448
- currentScope,
449
435
  });
450
436
  let lines = oldLines;
451
437
  if (lines === undefined || lines === null) {
@@ -463,13 +449,13 @@ const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines
463
449
  {
464
450
  index: line[0].index,
465
451
  handle: line[0].handle
466
- ? restorePoint(line[0].handle, elementScope, currentScope)
452
+ ? restorePoint(line[0].handle)
467
453
  : null,
468
454
  },
469
455
  {
470
456
  index: line[1].index,
471
457
  handle: line[1].handle
472
- ? restorePoint(line[1].handle, elementScope, currentScope)
458
+ ? restorePoint(line[1].handle)
473
459
  : null,
474
460
  },
475
461
  ];
@@ -477,24 +463,23 @@ const restoreLinearElementPointsAndLines = ({ points: oldPoints, lines: oldLines
477
463
  }
478
464
  if (!skipNormalization &&
479
465
  points.length >= 2 &&
480
- (points[0].x.value !== 0 || points[0].y.value !== 0)) {
466
+ (points[0].x !== 0 || points[0].y !== 0)) {
481
467
  const normalizedResult = getNormalizedPoints({
482
468
  points,
483
469
  lines,
484
470
  x: validatedX,
485
471
  y: validatedY,
486
- scope: elementScope,
487
- }, currentScope);
472
+ });
488
473
  const firstPoint = points[0];
489
474
  const lastPoint = points[points.length - 1];
490
475
  points = normalizedResult.points;
491
476
  lines = normalizedResult.lines;
492
477
  if (oldPoints && oldPoints.length === points.length) {
493
- if (firstPoint.x.value !== 0 || firstPoint.y.value !== 0) {
478
+ if (firstPoint.x !== 0 || firstPoint.y !== 0) {
494
479
  points[0] = Object.assign({}, points[0]);
495
480
  }
496
- if (lastPoint.x.value !== validatedWidth.value ||
497
- lastPoint.y.value !== validatedHeight.value) {
481
+ if (lastPoint.x !== validatedWidth ||
482
+ lastPoint.y !== validatedHeight) {
498
483
  points[points.length - 1] = Object.assign({}, points[points.length - 1]);
499
484
  }
500
485
  }
@@ -586,12 +571,29 @@ export const migrateArrayOrderToZIndex = (elements) => {
586
571
  return element;
587
572
  });
588
573
  };
589
- 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
+ }
590
591
  const existingIds = new Set();
592
+ const idMap = new Map();
591
593
  // First restore all elements with their original properties
592
594
  const restored = (elements || []).reduce((elements, element) => {
593
595
  if (element.type !== "selection") {
594
- 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);
595
597
  if (!migratedElement) {
596
598
  // element failed to restore — skip
597
599
  }
@@ -606,7 +608,10 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
606
608
  if (migratedElement &&
607
609
  (isPassThrough || !isInvisiblySmallElement(migratedElement))) {
608
610
  if (existingIds.has(migratedElement.id)) {
609
- migratedElement = Object.assign(Object.assign({}, migratedElement), { id: randomId() });
611
+ const oldId = migratedElement.id;
612
+ const newId = randomId();
613
+ migratedElement = Object.assign(Object.assign({}, migratedElement), { id: newId });
614
+ idMap.set(oldId, newId);
610
615
  }
611
616
  existingIds.add(migratedElement.id);
612
617
  elements.push(migratedElement);
@@ -614,8 +619,15 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
614
619
  }
615
620
  return elements;
616
621
  }, []);
622
+ if (idMap.size > 0) {
623
+ for (const el of restored) {
624
+ if (el.type === "model" && typeof el.code === "string" && el.code) {
625
+ el.code = updateModelCodeElementIds(el.code, idMap);
626
+ }
627
+ }
628
+ }
617
629
  let restoredElements = (opts === null || opts === void 0 ? void 0 : opts.syncInvalidIndices)
618
- ? opts.syncInvalidIndices(restored, currentScope)
630
+ ? opts.syncInvalidIndices(restored)
619
631
  : restored;
620
632
  // Migrate array ordering to explicit z-index values if needed
621
633
  restoredElements = migrateArrayOrderToZIndex(restoredElements);
@@ -634,7 +646,7 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
634
646
  repairContainerElement(element, restoredElementsMap);
635
647
  }
636
648
  if (opts.refreshDimensions && isTextElement(element)) {
637
- Object.assign(element, refreshTextDimensions(element, getContainerElement(element, restoredElementsMap), restoredElementsMap, currentScope));
649
+ Object.assign(element, refreshTextDimensions(element, getContainerElement(element, restoredElementsMap), restoredElementsMap));
638
650
  }
639
651
  if (isLinearElement(element)) {
640
652
  // Helper function to check if we should keep a binding
@@ -698,18 +710,11 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
698
710
  }
699
711
  return restoredElements;
700
712
  };
701
- export const isValidElementScopeValue = (value, mainScope = NEUTRAL_SCOPE) => {
702
- // Only check if the provided value is valid
703
- if (value !== undefined && Object.keys(ScaleFactors).includes(value)) {
704
- return value;
705
- }
706
- return mainScope;
707
- };
708
- const restoreLineSpacing = (lineSpacing, legacyLineHeight, currentScope) => {
713
+ const restoreLineSpacing = (lineSpacing, legacyLineHeight) => {
709
714
  if (lineSpacing && lineSpacing.type && lineSpacing.value) {
710
715
  return {
711
716
  type: isValidLineSpacingTypeValue(lineSpacing.type),
712
- value: restorePrecisionValue(lineSpacing.value, currentScope, currentScope, 1.15, true),
717
+ value: restoreNumber(lineSpacing.value, 1.15),
713
718
  };
714
719
  }
715
720
  // Fallback to legacy lineHeight
@@ -733,7 +738,7 @@ const restoreDocumentGridConfig = (gridConfig) => {
733
738
  gapX: typeof gridConfig.gapX === "number" ? gridConfig.gapX : 0,
734
739
  gapY: typeof gridConfig.gapY === "number" ? gridConfig.gapY : 0,
735
740
  firstPageAlone: typeof gridConfig.firstPageAlone === "boolean" ? gridConfig.firstPageAlone : false,
736
- scale: typeof gridConfig.scale === "number" ? gridConfig.scale : 1,
741
+ scale: typeof gridConfig.scale === "number" && gridConfig.scale > 0 && gridConfig.scale <= 50 ? gridConfig.scale : 1,
737
742
  };
738
743
  };
739
744
  const getFontFamilyByName = (fontFamilyName) => {
@@ -742,7 +747,7 @@ const getFontFamilyByName = (fontFamilyName) => {
742
747
  }
743
748
  return DEFAULT_FONT_FAMILY;
744
749
  };
745
- const repairBinding = (element, binding, currentScope, restoredBlocks) => {
750
+ const repairBinding = (element, binding, restoredBlocks) => {
746
751
  var _a;
747
752
  if (!binding) {
748
753
  return null;
@@ -750,10 +755,8 @@ const repairBinding = (element, binding, currentScope, restoredBlocks) => {
750
755
  // If this is a head-only binding, normalize it
751
756
  if (binding.head !== undefined &&
752
757
  (!binding.elementId || binding.elementId === "")) {
753
- return createHeadOnlyBinding(binding.head, restoredBlocks, currentScope);
758
+ return createHeadOnlyBinding(binding.head, restoredBlocks);
754
759
  }
755
- // Get the element's scope for conversion
756
- const elementScope = element ? element.scope : NEUTRAL_SCOPE;
757
760
  // Ensure we preserve the point attribute for linear-to-linear bindings
758
761
  const pointData = binding.point
759
762
  ? {
@@ -766,14 +769,14 @@ const repairBinding = (element, binding, currentScope, restoredBlocks) => {
766
769
  },
767
770
  }
768
771
  : { point: null };
769
- 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)
770
773
  ? normalizeFixedPoint((_a = binding.fixedPoint) !== null && _a !== void 0 ? _a : { x: 0.5, y: 0.5 })
771
774
  : null }, pointData);
772
775
  };
773
776
  /**
774
777
  * Validates a DucPath object and ensures its line indices form a valid closed path
775
778
  */
776
- const validateDucPath = (path, element, elementScope, currentScope) => {
779
+ const validateDucPath = (path, element) => {
777
780
  if (!path || !path.lineIndices || !Array.isArray(path.lineIndices)) {
778
781
  return null;
779
782
  }
@@ -794,21 +797,21 @@ const validateDucPath = (path, element, elementScope, currentScope) => {
794
797
  lineIndices: validLineIndices,
795
798
  background: path.background ? validateBackground(path.background) : null,
796
799
  stroke: path.stroke
797
- ? validateStroke(path.stroke, elementScope, currentScope)
800
+ ? validateStroke(path.stroke)
798
801
  : null,
799
802
  };
800
803
  };
801
804
  /**
802
805
  * Validates and filters path overrides for a linear element
803
806
  */
804
- const validatePathOverrides = (pathOverrides, element, elementScope, currentScope) => {
807
+ const validatePathOverrides = (pathOverrides, element) => {
805
808
  if (!pathOverrides || !Array.isArray(pathOverrides)) {
806
809
  return [];
807
810
  }
808
811
  const validPaths = [];
809
812
  const usedLineIndices = new Set();
810
813
  for (const pathOverride of pathOverrides) {
811
- const validatedPath = validateDucPath(pathOverride, element, elementScope, currentScope);
814
+ const validatedPath = validateDucPath(pathOverride, element);
812
815
  if (validatedPath) {
813
816
  // Check for overlapping line indices with previously validated paths
814
817
  const hasOverlap = validatedPath.lineIndices.some((index) => usedLineIndices.has(index));
@@ -843,14 +846,14 @@ const isValidCutAngleValue = (value, defaultValue) => {
843
846
  }
844
847
  return radian;
845
848
  };
846
- const createHeadOnlyBinding = (head, restoredBlocks, currentScope) => {
849
+ const createHeadOnlyBinding = (head, restoredBlocks) => {
847
850
  return {
848
851
  elementId: "",
849
852
  focus: 0,
850
- gap: getPrecisionValueFromRaw(0, currentScope, currentScope),
853
+ gap: 0,
851
854
  fixedPoint: null,
852
855
  point: null,
853
- head: isValidDucHead(head, restoredBlocks),
856
+ head: isValidDucHead(head, restoredBlocks || []),
854
857
  };
855
858
  };
856
859
  const validateDeprecatedElementContent = (color, defaultContent) => {
@@ -864,6 +867,6 @@ const isValidLineSpacingTypeValue = (value) => {
864
867
  /**
865
868
  * Restore properties specific to Stack-like elements (_DucStackElementBase)
866
869
  */
867
- const restoreStackElementProperties = (element, currentScope) => {
870
+ const restoreStackElementProperties = (element) => {
868
871
  return Object.assign(Object.assign({}, restoreDucStackProperties(element)), { clip: isValidBooleanValue(element.clip, false), labelVisible: isValidBooleanValue(element.labelVisible, true) });
869
872
  };
@@ -0,0 +1,11 @@
1
+ export declare const getEncodedPythonModelModuleName: (elementId: string) => string;
2
+ export declare const getPythonModelModuleName: (elementId: string) => string;
3
+ /**
4
+ * Updates Python code referencing model element IDs when IDs are restored or duplicated.
5
+ * Replaces references in:
6
+ * - `from duc_model.<id_or_module> import ...`
7
+ * - `import duc_model.<id_or_module>`
8
+ * - `duc_model.<id_or_module>`
9
+ * - `from duc_model import <id_or_module>`
10
+ */
11
+ export declare const updateModelCodeElementIds: (code: string, idMap: Map<string, string> | Record<string, string>) => string;