ducjs 4.1.0 → 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.
- package/dist/duc_locator_wasm.d.ts +48 -0
- package/dist/duc_locator_wasm.js +296 -0
- package/dist/duc_locator_wasm_bg.wasm +0 -0
- package/dist/duc_locator_wasm_bg.wasm.d.ts +13 -0
- package/dist/ducjs_wasi.wasm +0 -0
- package/dist/ducjs_wasm.d.ts +14 -2
- package/dist/ducjs_wasm.js +96 -8
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/ducjs_wasm_bg.wasm.d.ts +6 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/locator-runtime.d.ts +4 -0
- package/dist/locator-runtime.js +7 -0
- package/dist/restore/restoreDataState.d.ts +13 -24
- package/dist/restore/restoreDataState.js +47 -81
- package/dist/restore/restoreElements.d.ts +10 -15
- package/dist/restore/restoreElements.js +115 -124
- package/dist/thumbnails/bounds.d.ts +21 -0
- package/dist/thumbnails/bounds.js +84 -0
- package/dist/thumbnails/browserRunner.d.ts +60 -0
- package/dist/thumbnails/browserRunner.js +446 -0
- package/dist/thumbnails/cameraPresets.d.ts +47 -0
- package/dist/thumbnails/cameraPresets.js +222 -0
- package/dist/thumbnails/cli.d.ts +2 -0
- package/dist/thumbnails/cli.js +102 -0
- package/dist/thumbnails/index.d.ts +11 -0
- package/dist/thumbnails/index.js +11 -0
- package/dist/thumbnails/lib/clientBundle.min.js +10427 -0
- package/dist/thumbnails/lib/clientEntry.d.ts +3 -0
- package/dist/thumbnails/lib/clientEntry.js +8 -0
- package/dist/thumbnails/lib/clippingUtils.d.ts +10 -0
- package/dist/thumbnails/lib/clippingUtils.js +3 -0
- package/dist/thumbnails/lib/defaultModelColor.d.ts +3 -0
- package/dist/thumbnails/lib/defaultModelColor.js +22 -0
- package/dist/thumbnails/lib/index.d.ts +12 -0
- package/dist/thumbnails/lib/index.js +12 -0
- package/dist/thumbnails/lib/mapViewerStateToOptions.d.ts +34 -0
- package/dist/thumbnails/lib/mapViewerStateToOptions.js +69 -0
- package/dist/thumbnails/lib/offscreen-dxf-thumbnail.d.ts +16 -0
- package/dist/thumbnails/lib/offscreen-dxf-thumbnail.js +173 -0
- package/dist/thumbnails/lib/offscreen-model-thumbnail.d.ts +16 -0
- package/dist/thumbnails/lib/offscreen-model-thumbnail.js +209 -0
- package/dist/thumbnails/lib/parametricClip.d.ts +18 -0
- package/dist/thumbnails/lib/parametricClip.js +177 -0
- package/dist/thumbnails/lib/parametricShapes.d.ts +1 -0
- package/dist/thumbnails/lib/parametricShapes.js +75 -0
- package/dist/thumbnails/lib/parametricViewerState.d.ts +26 -0
- package/dist/thumbnails/lib/parametricViewerState.js +198 -0
- package/dist/thumbnails/lib/thumbnail-camera-fit.d.ts +6 -0
- package/dist/thumbnails/lib/thumbnail-camera-fit.js +292 -0
- package/dist/thumbnails/lib/thumbnail-capture.d.ts +23 -0
- package/dist/thumbnails/lib/thumbnail-capture.js +161 -0
- package/dist/thumbnails/lib/thumbnail-visibility.d.ts +12 -0
- package/dist/thumbnails/lib/thumbnail-visibility.js +97 -0
- package/dist/thumbnails/lib/viewerGrid.d.ts +13 -0
- package/dist/thumbnails/lib/viewerGrid.js +57 -0
- package/dist/thumbnails/modelCache.d.ts +56 -0
- package/dist/thumbnails/modelCache.js +165 -0
- package/dist/thumbnails/modelOutputArtifact.d.ts +19 -0
- package/dist/thumbnails/modelOutputArtifact.js +87 -0
- package/dist/thumbnails/render.d.ts +45 -0
- package/dist/thumbnails/render.js +162 -0
- package/dist/thumbnails/templates.d.ts +16 -0
- package/dist/thumbnails/templates.js +786 -0
- package/dist/thumbnails/tessellator.d.ts +33 -0
- package/dist/thumbnails/tessellator.js +349 -0
- package/dist/thumbnails/types.d.ts +233 -0
- package/dist/thumbnails/types.js +1 -0
- package/dist/thumbnails/worker.d.ts +10 -0
- package/dist/thumbnails/worker.js +119 -0
- package/dist/transform.d.ts +1 -1
- package/dist/transform.js +20 -22
- package/dist/types/elements/index.d.ts +22 -28
- package/dist/types/elements/index.js +0 -1
- package/dist/types/geometry.types.d.ts +5 -5
- package/dist/types/index.d.ts +13 -59
- package/dist/types/index.js +0 -1
- package/dist/types/issues.types.d.ts +1 -2
- package/dist/utils/bounds.d.ts +10 -11
- package/dist/utils/bounds.js +105 -84
- package/dist/utils/constants.d.ts +5 -7
- package/dist/utils/constants.js +10 -15
- package/dist/utils/elements/freedrawElement.js +6 -3
- package/dist/utils/elements/index.d.ts +2 -6
- package/dist/utils/elements/index.js +4 -9
- package/dist/utils/elements/linearElement.d.ts +12 -14
- package/dist/utils/elements/linearElement.js +81 -66
- package/dist/utils/elements/newElement.d.ts +37 -22
- package/dist/utils/elements/newElement.js +70 -64
- package/dist/utils/elements/textElement.d.ts +34 -35
- package/dist/utils/elements/textElement.js +79 -83
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/locator.d.ts +43 -0
- package/dist/utils/locator.js +112 -0
- package/dist/utils/math/bbox.d.ts +1 -2
- package/dist/utils/math/geometry.js +5 -4
- package/dist/utils/math/index.d.ts +13 -17
- package/dist/utils/math/index.js +53 -41
- package/dist/utils/normalize.d.ts +5 -5
- package/dist/utils/normalize.js +15 -10
- package/dist/utils/shape.d.ts +3 -4
- package/dist/utils/shape.js +64 -48
- package/dist/utils/state/index.d.ts +3 -4
- package/dist/utils/state/index.js +8 -23
- package/dist/wasi.js +38 -12
- package/package.json +23 -9
- package/dist/technical/index.d.ts +0 -2
- package/dist/technical/index.js +0 -2
- package/dist/technical/measurements.d.ts +0 -31
- package/dist/technical/measurements.js +0 -64
- package/dist/technical/scopes.d.ts +0 -261
- package/dist/technical/scopes.js +0 -676
- package/dist/types/typeChecks.d.ts +0 -5
- package/dist/types/typeChecks.js +0 -10
- package/dist/utils/traverse.d.ts +0 -30
- 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,
|
|
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:
|
|
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
|
|
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: (
|
|
44
|
-
index: (
|
|
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:
|
|
52
|
-
y:
|
|
53
|
-
|
|
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: (
|
|
52
|
+
layerId: (_e = _element.layerId) !== null && _e !== void 0 ? _e : null,
|
|
58
53
|
regionIds: Array.isArray(_element.regionIds) ? _element.regionIds : [],
|
|
59
|
-
width:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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: (
|
|
65
|
-
frameId: (
|
|
66
|
-
roundness:
|
|
67
|
-
boundElements: (
|
|
68
|
-
updated: (
|
|
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: (
|
|
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:
|
|
79
|
-
y:
|
|
80
|
-
width:
|
|
81
|
-
height:
|
|
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,
|
|
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,
|
|
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
|
|
123
|
-
const
|
|
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:
|
|
163
|
+
size: restoreNumber(element.size, DEFAULT_FREEDRAW_ELEMENT.size),
|
|
169
164
|
lastCommittedPoint: element.lastCommittedPoint
|
|
170
|
-
? restorePoint(element.lastCommittedPoint
|
|
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 =
|
|
211
|
-
const elementHeight =
|
|
202
|
+
const elementWidth = restoreNumber(element.width, 0);
|
|
203
|
+
const elementHeight = restoreNumber(element.height, 0);
|
|
212
204
|
finalPoints = [
|
|
213
205
|
{
|
|
214
|
-
x:
|
|
215
|
-
y:
|
|
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
|
|
224
|
+
? createHeadOnlyBinding(startBinding.head, restoredBlocks)
|
|
233
225
|
: startBinding
|
|
234
|
-
? repairBinding(element, startBinding,
|
|
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
|
|
231
|
+
? createHeadOnlyBinding(endBinding.head, restoredBlocks)
|
|
240
232
|
: endBinding
|
|
241
|
-
? repairBinding(element, endBinding,
|
|
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(
|
|
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
|
|
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:
|
|
256
|
-
height:
|
|
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
|
|
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 }),
|
|
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
|
|
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
|
|
287
|
+
const stackProperties = restoreStackElementProperties(plotElement);
|
|
297
288
|
// Restore layout-specific properties
|
|
298
289
|
const layout = {
|
|
299
290
|
margins: {
|
|
300
|
-
top:
|
|
301
|
-
right:
|
|
302
|
-
bottom:
|
|
303
|
-
left:
|
|
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(
|
|
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
|
|
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 =
|
|
376
|
-
const yValue =
|
|
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,
|
|
388
|
-
// Convert input parameters to plain numbers
|
|
389
|
-
const validatedWidth =
|
|
390
|
-
const validatedHeight =
|
|
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
|
|
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:
|
|
418
|
-
y:
|
|
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] &&
|
|
430
|
-
points[1].x
|
|
431
|
-
points[1].y
|
|
432
|
-
(validatedWidth
|
|
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,
|
|
438
|
-
const validatedX =
|
|
439
|
-
const validatedY =
|
|
440
|
-
const validatedWidth =
|
|
441
|
-
const validatedHeight =
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
478
|
+
if (firstPoint.x !== 0 || firstPoint.y !== 0) {
|
|
495
479
|
points[0] = Object.assign({}, points[0]);
|
|
496
480
|
}
|
|
497
|
-
if (lastPoint.x
|
|
498
|
-
lastPoint.y
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
849
|
+
const createHeadOnlyBinding = (head, restoredBlocks) => {
|
|
859
850
|
return {
|
|
860
851
|
elementId: "",
|
|
861
852
|
focus: 0,
|
|
862
|
-
gap:
|
|
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
|
|
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;
|