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.
- 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/index.d.ts +1 -0
- package/dist/restore/index.js +1 -0
- package/dist/restore/restoreDataState.d.ts +13 -24
- package/dist/restore/restoreDataState.js +49 -83
- package/dist/restore/restoreElements.d.ts +10 -15
- package/dist/restore/restoreElements.js +128 -125
- package/dist/restore/updateModelCode.d.ts +11 -0
- package/dist/restore/updateModelCode.js +63 -0
- 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/math/random.js +7 -2
- 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,4 +1,3 @@
|
|
|
1
|
-
import { getPrecisionValueFromRaw, getPrecisionValueFromScoped, getScopedBezierPointFromDucPoint } from "../../technical/scopes";
|
|
2
1
|
import { getBoundTextElement, getElementAbsoluteCoords, getElementPointsCoords } from "../bounds";
|
|
3
2
|
import { LINE_CONFIRM_THRESHOLD } from "../constants";
|
|
4
3
|
import { centerPoint, getBezierXY, getControlPointsForBezierCurve, getCubicBezierBoundingBox, getQuadraticBezierBoundingBox, mapIntervalToBezierT, rotate, rotatePoint } from "../math";
|
|
@@ -45,9 +44,12 @@ export const mergeOverlappingPoints = (points, lines, threshold = LINE_CONFIRM_T
|
|
|
45
44
|
const findOverlappingPointGroups = (points, threshold) => {
|
|
46
45
|
const groups = {};
|
|
47
46
|
points.forEach((point, index) => {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
48
|
// Create a key based on rounded coordinates for threshold-based grouping
|
|
49
|
-
const
|
|
50
|
-
const
|
|
49
|
+
const px = typeof point.x === "number" ? point.x : ((_b = (_a = point.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
|
|
50
|
+
const py = typeof point.y === "number" ? point.y : ((_d = (_c = point.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
|
|
51
|
+
const roundedX = Math.round(px / threshold) * threshold;
|
|
52
|
+
const roundedY = Math.round(py / threshold) * threshold;
|
|
51
53
|
const key = `${roundedX},${roundedY}`;
|
|
52
54
|
if (!groups[key]) {
|
|
53
55
|
groups[key] = [];
|
|
@@ -194,35 +196,42 @@ const removeDuplicateLines = (lines) => {
|
|
|
194
196
|
* expected in various parts of the codebase. Also returns new x/y to account
|
|
195
197
|
* for the potential normalization.
|
|
196
198
|
*/
|
|
197
|
-
export const getNormalizedPoints = (element
|
|
199
|
+
export const getNormalizedPoints = (element) => {
|
|
200
|
+
var _a, _b, _c, _d, _e, _f;
|
|
198
201
|
const { points, x, y, lines } = element;
|
|
202
|
+
const numX = typeof x === "number" ? x : ((_a = x === null || x === void 0 ? void 0 : x.value) !== null && _a !== void 0 ? _a : 0);
|
|
203
|
+
const numY = typeof y === "number" ? y : ((_b = y === null || y === void 0 ? void 0 : y.value) !== null && _b !== void 0 ? _b : 0);
|
|
199
204
|
if (points.length === 0) {
|
|
200
205
|
// Handle empty points array: return element's current x/y and empty normalized points
|
|
201
206
|
return {
|
|
202
207
|
points: [],
|
|
203
|
-
x:
|
|
204
|
-
y:
|
|
208
|
+
x: numX,
|
|
209
|
+
y: numY,
|
|
205
210
|
lines: lines || [],
|
|
206
211
|
};
|
|
207
212
|
}
|
|
208
|
-
const offsetX = points[0].x.value;
|
|
209
|
-
const offsetY = points[0].y.value;
|
|
213
|
+
const offsetX = typeof points[0].x === "number" ? points[0].x : ((_d = (_c = points[0].x) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
|
|
214
|
+
const offsetY = typeof points[0].y === "number" ? points[0].y : ((_f = (_e = points[0].y) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0);
|
|
210
215
|
const normalizedPoints = points.map((point) => {
|
|
211
|
-
|
|
216
|
+
var _a, _b, _c, _d;
|
|
217
|
+
const px = typeof point.x === "number" ? point.x : ((_b = (_a = point.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
|
|
218
|
+
const py = typeof point.y === "number" ? point.y : ((_d = (_c = point.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
|
|
219
|
+
return Object.assign(Object.assign({}, point), { x: px - offsetX, y: py - offsetY });
|
|
212
220
|
});
|
|
213
221
|
const normalizedLines = (lines || []).map((line) => {
|
|
222
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
214
223
|
const [start, end] = line;
|
|
215
224
|
return [
|
|
216
225
|
Object.assign(Object.assign({}, start), { handle: start.handle
|
|
217
226
|
? {
|
|
218
|
-
x:
|
|
219
|
-
y:
|
|
227
|
+
x: (typeof start.handle.x === "number" ? start.handle.x : ((_b = (_a = start.handle.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0)) - offsetX,
|
|
228
|
+
y: (typeof start.handle.y === "number" ? start.handle.y : ((_d = (_c = start.handle.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0)) - offsetY,
|
|
220
229
|
}
|
|
221
230
|
: null }),
|
|
222
231
|
Object.assign(Object.assign({}, end), { handle: end.handle
|
|
223
232
|
? {
|
|
224
|
-
x:
|
|
225
|
-
y:
|
|
233
|
+
x: (typeof end.handle.x === "number" ? end.handle.x : ((_f = (_e = end.handle.x) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0)) - offsetX,
|
|
234
|
+
y: (typeof end.handle.y === "number" ? end.handle.y : ((_h = (_g = end.handle.y) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0)) - offsetY,
|
|
226
235
|
}
|
|
227
236
|
: null }),
|
|
228
237
|
];
|
|
@@ -230,44 +239,36 @@ export const getNormalizedPoints = (element, currentScope) => {
|
|
|
230
239
|
return {
|
|
231
240
|
points: normalizedPoints,
|
|
232
241
|
lines: normalizedLines,
|
|
233
|
-
x:
|
|
234
|
-
y:
|
|
242
|
+
x: numX + offsetX,
|
|
243
|
+
y: numY + offsetY,
|
|
235
244
|
};
|
|
236
245
|
};
|
|
237
246
|
/** scene coords */
|
|
238
|
-
export const getPointsGlobalCoordinates = (element, elementsMap
|
|
239
|
-
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap
|
|
247
|
+
export const getPointsGlobalCoordinates = (element, elementsMap) => {
|
|
248
|
+
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
|
240
249
|
const cx = (x1 + x2) / 2;
|
|
241
250
|
const cy = (y1 + y2) / 2;
|
|
251
|
+
const elX = typeof element.x === "number" ? element.x : 0;
|
|
252
|
+
const elY = typeof element.y === "number" ? element.y : 0;
|
|
242
253
|
return element.points.map((point) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const rotatePoint = rotate(x.scoped + point.x.scoped, y.scoped + point.y.scoped, cx, cy, element.angle);
|
|
248
|
-
// if (point.isCurve) {
|
|
249
|
-
// if(handleIn)
|
|
250
|
-
// handleIn = rotate(x + handleIn.x, y + handleIn.y, cx, cy, element.angle);
|
|
251
|
-
// if(handleOut)
|
|
252
|
-
// handleOut = rotate(x + handleOut.x, y + handleOut.y, cx, cy, element.angle);
|
|
253
|
-
// }
|
|
254
|
-
x = getPrecisionValueFromScoped(rotatePoint.x, element.scope, currentScope);
|
|
255
|
-
y = getPrecisionValueFromScoped(rotatePoint.y, element.scope, currentScope);
|
|
256
|
-
return Object.assign(Object.assign({}, point), { x, y });
|
|
254
|
+
const ptX = typeof point.x === "number" ? point.x : 0;
|
|
255
|
+
const ptY = typeof point.y === "number" ? point.y : 0;
|
|
256
|
+
const rotatePoint = rotate(elX + ptX, elY + ptY, cx, cy, element.angle);
|
|
257
|
+
return Object.assign(Object.assign({}, point), { x: rotatePoint.x, y: rotatePoint.y });
|
|
257
258
|
});
|
|
258
259
|
};
|
|
259
260
|
/** scene coords */
|
|
260
|
-
export const getPointGlobalCoordinates = (element, point, elementsMap
|
|
261
|
-
const [x1_sv, y1_sv, x2_sv, y2_sv] = getElementAbsoluteCoords(element, elementsMap
|
|
261
|
+
export const getPointGlobalCoordinates = (element, point, elementsMap) => {
|
|
262
|
+
const [x1_sv, y1_sv, x2_sv, y2_sv] = getElementAbsoluteCoords(element, elementsMap);
|
|
262
263
|
const cx = (x1_sv + x2_sv) / 2;
|
|
263
264
|
const cy = (y1_sv + y2_sv) / 2;
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
const elementX = typeof element.x === "number" ? element.x : 0;
|
|
266
|
+
const elementY = typeof element.y === "number" ? element.y : 0;
|
|
266
267
|
const rotatedPoint = rotate(elementX + point.x, elementY + point.y, cx, cy, element.angle);
|
|
267
268
|
return { x: rotatedPoint.x, y: rotatedPoint.y };
|
|
268
269
|
};
|
|
269
|
-
export const getBoundTextElementPosition = (element, boundTextElement, elementsMap
|
|
270
|
-
const points = getPointsGlobalCoordinates(element, elementsMap
|
|
270
|
+
export const getBoundTextElementPosition = (element, boundTextElement, elementsMap) => {
|
|
271
|
+
const points = getPointsGlobalCoordinates(element, elementsMap);
|
|
271
272
|
if (points.length < 2) {
|
|
272
273
|
return null;
|
|
273
274
|
}
|
|
@@ -275,27 +276,35 @@ export const getBoundTextElementPosition = (element, boundTextElement, elementsM
|
|
|
275
276
|
let y = 0;
|
|
276
277
|
if (element.points.length % 2 === 1) {
|
|
277
278
|
const index = Math.floor(element.points.length / 2);
|
|
278
|
-
const midPoint = getPointGlobalCoordinates(element,
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
const midPoint = getPointGlobalCoordinates(element, { x: element.points[index].x, y: element.points[index].y }, elementsMap);
|
|
280
|
+
const btw = typeof boundTextElement.width === "number" ? boundTextElement.width : 0;
|
|
281
|
+
const bth = typeof boundTextElement.height === "number" ? boundTextElement.height : 0;
|
|
282
|
+
x = midPoint.x - btw / 2;
|
|
283
|
+
y = midPoint.y - bth / 2;
|
|
281
284
|
}
|
|
282
285
|
else {
|
|
283
286
|
const index = element.points.length / 2 - 1;
|
|
284
287
|
let midSegmentMidpoint = null;
|
|
285
288
|
if (element.points.length === 2) {
|
|
286
|
-
|
|
289
|
+
const p0x = typeof points[0].x === "number" ? points[0].x : 0;
|
|
290
|
+
const p0y = typeof points[0].y === "number" ? points[0].y : 0;
|
|
291
|
+
const p1x = typeof points[1].x === "number" ? points[1].x : 0;
|
|
292
|
+
const p1y = typeof points[1].y === "number" ? points[1].y : 0;
|
|
293
|
+
midSegmentMidpoint = centerPoint({ x: p0x, y: p0y }, { x: p1x, y: p1y });
|
|
287
294
|
}
|
|
288
295
|
else {
|
|
289
|
-
midSegmentMidpoint = getSegmentMidPoint(element,
|
|
296
|
+
midSegmentMidpoint = getSegmentMidPoint(element, { x: points[index].x, y: points[index].y }, { x: points[index + 1].x, y: points[index + 1].y }, index + 1, elementsMap);
|
|
290
297
|
}
|
|
291
298
|
if (midSegmentMidpoint) {
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
const btw = typeof boundTextElement.width === "number" ? boundTextElement.width : 0;
|
|
300
|
+
const bth = typeof boundTextElement.height === "number" ? boundTextElement.height : 0;
|
|
301
|
+
x = midSegmentMidpoint.x - btw / 2;
|
|
302
|
+
y = midSegmentMidpoint.y - bth / 2;
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
305
|
return { x, y };
|
|
297
306
|
};
|
|
298
|
-
export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoundText = false,
|
|
307
|
+
export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoundText = false, returnUnrotatedBoundsOnly = true) => {
|
|
299
308
|
const { points, lines, angle, x: elX, y: elY } = element;
|
|
300
309
|
// Get unrotated bounding box to determine the center of rotation
|
|
301
310
|
const [unrotatedX1, unrotatedY1, unrotatedX2, unrotatedY2] = getElementPointsCoords(element, points);
|
|
@@ -307,6 +316,10 @@ export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoun
|
|
|
307
316
|
let minY = Infinity;
|
|
308
317
|
let maxX = -Infinity;
|
|
309
318
|
let maxY = -Infinity;
|
|
319
|
+
const ex = typeof elX === "number" ? elX : 0;
|
|
320
|
+
const ey = typeof elY === "number" ? elY : 0;
|
|
321
|
+
const getPtX = (p) => typeof p.x === "number" ? p.x : 0;
|
|
322
|
+
const getPtY = (p) => typeof p.y === "number" ? p.y : 0;
|
|
310
323
|
if (lines && lines.length > 0) {
|
|
311
324
|
for (const line of lines) {
|
|
312
325
|
const startPoint = points[line[0].index];
|
|
@@ -315,23 +328,23 @@ export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoun
|
|
|
315
328
|
continue;
|
|
316
329
|
}
|
|
317
330
|
const absoluteStartPoint = {
|
|
318
|
-
x:
|
|
319
|
-
y:
|
|
331
|
+
x: ex + getPtX(startPoint),
|
|
332
|
+
y: ey + getPtY(startPoint),
|
|
320
333
|
};
|
|
321
334
|
const absoluteEndPoint = {
|
|
322
|
-
x:
|
|
323
|
-
y:
|
|
335
|
+
x: ex + getPtX(endPoint),
|
|
336
|
+
y: ey + getPtY(endPoint),
|
|
324
337
|
};
|
|
325
338
|
const startHandle = line[0].handle;
|
|
326
339
|
const endHandle = line[1].handle;
|
|
327
340
|
if (startHandle && endHandle) {
|
|
328
341
|
const absoluteStartHandle = {
|
|
329
|
-
x:
|
|
330
|
-
y:
|
|
342
|
+
x: ex + getPtX(startHandle),
|
|
343
|
+
y: ey + getPtY(startHandle),
|
|
331
344
|
};
|
|
332
345
|
const absoluteEndHandle = {
|
|
333
|
-
x:
|
|
334
|
-
y:
|
|
346
|
+
x: ex + getPtX(endHandle),
|
|
347
|
+
y: ey + getPtY(endHandle),
|
|
335
348
|
};
|
|
336
349
|
const p0 = rotate(absoluteStartPoint.x, absoluteStartPoint.y, cx, cy, angle);
|
|
337
350
|
const p1 = rotate(absoluteStartHandle.x, absoluteStartHandle.y, cx, cy, angle);
|
|
@@ -346,8 +359,8 @@ export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoun
|
|
|
346
359
|
else if (startHandle || endHandle) {
|
|
347
360
|
const controlHandle = startHandle || endHandle;
|
|
348
361
|
const absoluteControlHandle = {
|
|
349
|
-
x:
|
|
350
|
-
y:
|
|
362
|
+
x: ex + getPtX(controlHandle),
|
|
363
|
+
y: ey + getPtY(controlHandle),
|
|
351
364
|
};
|
|
352
365
|
const p0 = rotate(absoluteStartPoint.x, absoluteStartPoint.y, cx, cy, angle);
|
|
353
366
|
const p1 = rotate(absoluteControlHandle.x, absoluteControlHandle.y, cx, cy, angle);
|
|
@@ -371,8 +384,8 @@ export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoun
|
|
|
371
384
|
else {
|
|
372
385
|
// Fallback for elements without lines
|
|
373
386
|
for (let i = 0; i < points.length - 1; i++) {
|
|
374
|
-
const p0 = rotate(
|
|
375
|
-
const p1 = rotate(
|
|
387
|
+
const p0 = rotate(ex + getPtX(points[i]), ey + getPtY(points[i]), cx, cy, angle);
|
|
388
|
+
const p1 = rotate(ex + getPtX(points[i + 1]), ey + getPtY(points[i + 1]), cx, cy, angle);
|
|
376
389
|
minX = Math.min(minX, p0.x, p1.x);
|
|
377
390
|
minY = Math.min(minY, p0.y, p1.y);
|
|
378
391
|
maxX = Math.max(maxX, p0.x, p1.x);
|
|
@@ -394,22 +407,24 @@ export const getLinearElementAbsoluteCoords = (element, elementsMap, includeBoun
|
|
|
394
407
|
if (includeBoundText) {
|
|
395
408
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
396
409
|
if (boundTextElement) {
|
|
397
|
-
coords = getMinMaxXYWithBoundText(element, elementsMap, [coords[0], coords[1], coords[2], coords[3]], boundTextElement
|
|
410
|
+
coords = getMinMaxXYWithBoundText(element, elementsMap, [coords[0], coords[1], coords[2], coords[3]], boundTextElement);
|
|
398
411
|
}
|
|
399
412
|
}
|
|
400
413
|
return coords;
|
|
401
414
|
};
|
|
402
|
-
export const getMinMaxXYWithBoundText = (element, elementsMap, elementBounds, boundTextElement
|
|
415
|
+
export const getMinMaxXYWithBoundText = (element, elementsMap, elementBounds, boundTextElement) => {
|
|
403
416
|
let [x1, y1, x2, y2] = elementBounds;
|
|
404
417
|
const cx = (x1 + x2) / 2;
|
|
405
418
|
const cy = (y1 + y2) / 2;
|
|
406
|
-
const boundTextCoords = getBoundTextElementPosition(element, boundTextElement, elementsMap
|
|
419
|
+
const boundTextCoords = getBoundTextElementPosition(element, boundTextElement, elementsMap);
|
|
407
420
|
if (boundTextCoords === null) {
|
|
408
421
|
return [x1, y1, x2, y2, cx, cy];
|
|
409
422
|
}
|
|
410
423
|
const { x: boundTextX1, y: boundTextY1 } = boundTextCoords;
|
|
411
|
-
const
|
|
412
|
-
const
|
|
424
|
+
const btw = typeof boundTextElement.width === "number" ? boundTextElement.width : 0;
|
|
425
|
+
const bth = typeof boundTextElement.height === "number" ? boundTextElement.height : 0;
|
|
426
|
+
const boundTextX2 = boundTextX1 + btw;
|
|
427
|
+
const boundTextY2 = boundTextY1 + bth;
|
|
413
428
|
const topLeftRotatedPoint = rotatePoint({ x: x1, y: y1 }, { x: cx, y: cy }, element.angle);
|
|
414
429
|
const topRightRotatedPoint = rotatePoint({ x: x2, y: y1 }, { x: cx, y: cy }, element.angle);
|
|
415
430
|
const counterRotateBoundTextTopLeft = rotatePoint({ x: boundTextX1, y: boundTextY1 }, { x: cx, y: cy }, -element.angle);
|
|
@@ -444,14 +459,14 @@ export const getMinMaxXYWithBoundText = (element, elementsMap, elementBounds, bo
|
|
|
444
459
|
}
|
|
445
460
|
return [x1, y1, x2, y2, cx, cy];
|
|
446
461
|
};
|
|
447
|
-
export const getSegmentMidPoint = (element, startPoint, endPoint, endPointIndex, elementsMap
|
|
462
|
+
export const getSegmentMidPoint = (element, startPoint, endPoint, endPointIndex, elementsMap) => {
|
|
448
463
|
let segmentMidPoint = centerPoint(startPoint, endPoint);
|
|
449
464
|
if (element.points.length > 2 && element.roundness) {
|
|
450
|
-
const controlPoints = getControlPointsForBezierCurve(element,
|
|
465
|
+
const controlPoints = getControlPointsForBezierCurve(element, { x: element.points[endPointIndex].x, y: element.points[endPointIndex].y });
|
|
451
466
|
if (controlPoints) {
|
|
452
|
-
const t = mapIntervalToBezierT(element,
|
|
467
|
+
const t = mapIntervalToBezierT(element, { x: element.points[endPointIndex].x, y: element.points[endPointIndex].y }, 0.5);
|
|
453
468
|
const { x: tx, y: ty } = getBezierXY(controlPoints[0], controlPoints[1], controlPoints[2], controlPoints[3], t);
|
|
454
|
-
segmentMidPoint = getPointGlobalCoordinates(element, { x: tx, y: ty }, elementsMap
|
|
469
|
+
segmentMidPoint = getPointGlobalCoordinates(element, { x: tx, y: ty }, elementsMap);
|
|
455
470
|
}
|
|
456
471
|
}
|
|
457
472
|
return segmentMidPoint;
|
|
@@ -1,42 +1,56 @@
|
|
|
1
|
-
import { Scope } from "../../types";
|
|
2
1
|
import { DucArrowElement, DucDocElement, DucElement, DucEllipseElement, DucEmbeddableElement, DucFrameElement, DucFreeDrawElement, DucGenericElement, DucImageElement, DucLinearElement, DucModelElement, DucPdfElement, DucPlotElement, DucPolygonElement, DucTableElement, DucTextElement, ElementConstructorOpts, ElementUpdate, NonDeleted } from "../../types/elements";
|
|
3
2
|
import { Mutable } from "../../types/utility.types";
|
|
4
3
|
export declare const newElementWith: <TElement extends DucElement>(element: TElement, updates: ElementUpdate<TElement>,
|
|
5
4
|
/** pass `true` to always regenerate */
|
|
6
5
|
force?: boolean) => TElement;
|
|
7
|
-
|
|
6
|
+
type NewGenericOpts = {
|
|
8
7
|
type: DucGenericElement["type"];
|
|
9
|
-
} & ElementConstructorOpts
|
|
10
|
-
export declare
|
|
8
|
+
} & ElementConstructorOpts;
|
|
9
|
+
export declare function newElement(opts: NewGenericOpts): NonDeleted<DucGenericElement>;
|
|
10
|
+
type NewEmbeddableOpts = {
|
|
11
11
|
type: "embeddable";
|
|
12
|
-
} & ElementConstructorOpts
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
export declare
|
|
12
|
+
} & ElementConstructorOpts;
|
|
13
|
+
export declare function newEmbeddableElement(opts: NewEmbeddableOpts): NonDeleted<DucEmbeddableElement>;
|
|
14
|
+
type NewFrameOpts = Partial<DucFrameElement> & ElementConstructorOpts;
|
|
15
|
+
export declare function newFrameElement(opts: NewFrameOpts): NonDeleted<DucFrameElement>;
|
|
16
|
+
type NewPlotOpts = Partial<DucPlotElement> & ElementConstructorOpts;
|
|
17
|
+
export declare function newPlotElement(opts: NewPlotOpts): NonDeleted<DucPlotElement>;
|
|
18
|
+
type NewEllipseOpts = {
|
|
16
19
|
type: "ellipse";
|
|
17
20
|
ratio?: DucEllipseElement["ratio"];
|
|
18
21
|
startAngle?: DucEllipseElement["startAngle"];
|
|
19
22
|
endAngle?: DucEllipseElement["endAngle"];
|
|
20
23
|
showAuxCrosshair?: DucEllipseElement["showAuxCrosshair"];
|
|
21
|
-
} & ElementConstructorOpts
|
|
22
|
-
export declare
|
|
24
|
+
} & ElementConstructorOpts;
|
|
25
|
+
export declare function newEllipseElement(opts: NewEllipseOpts): NonDeleted<DucEllipseElement>;
|
|
26
|
+
type NewPolygonOpts = {
|
|
23
27
|
type: "polygon";
|
|
24
28
|
sides?: DucPolygonElement["sides"];
|
|
25
|
-
} & ElementConstructorOpts
|
|
26
|
-
export declare
|
|
29
|
+
} & ElementConstructorOpts;
|
|
30
|
+
export declare function newPolygonElement(opts: NewPolygonOpts): NonDeleted<DucPolygonElement>;
|
|
31
|
+
type NewTextOpts = {
|
|
27
32
|
text: string;
|
|
28
33
|
originalText?: string;
|
|
29
|
-
} & Partial<DucTextElement> & ElementConstructorOpts
|
|
30
|
-
export declare
|
|
34
|
+
} & Partial<DucTextElement> & ElementConstructorOpts;
|
|
35
|
+
export declare function newTextElement(opts: NewTextOpts): NonDeleted<DucTextElement>;
|
|
36
|
+
type NewFreeDrawOpts = {
|
|
31
37
|
simulatePressure: boolean;
|
|
32
|
-
} & Partial<DucFreeDrawElement> & ElementConstructorOpts
|
|
33
|
-
export declare
|
|
34
|
-
|
|
35
|
-
export declare
|
|
36
|
-
|
|
37
|
-
export declare
|
|
38
|
-
|
|
39
|
-
export declare
|
|
38
|
+
} & Partial<DucFreeDrawElement> & ElementConstructorOpts;
|
|
39
|
+
export declare function newFreeDrawElement(opts: NewFreeDrawOpts): NonDeleted<DucFreeDrawElement>;
|
|
40
|
+
type NewLinearOpts = Partial<DucLinearElement> & ElementConstructorOpts;
|
|
41
|
+
export declare function newLinearElement(opts: NewLinearOpts): NonDeleted<DucLinearElement>;
|
|
42
|
+
type NewArrowOpts = Partial<DucArrowElement> & ElementConstructorOpts;
|
|
43
|
+
export declare function newArrowElement(opts: NewArrowOpts): NonDeleted<DucArrowElement>;
|
|
44
|
+
type NewImageOpts = Partial<DucImageElement> & ElementConstructorOpts;
|
|
45
|
+
export declare function newImageElement(opts: NewImageOpts): NonDeleted<DucImageElement>;
|
|
46
|
+
type NewTableOpts = Partial<DucTableElement> & ElementConstructorOpts;
|
|
47
|
+
export declare function newTableElement(opts: NewTableOpts): NonDeleted<DucTableElement>;
|
|
48
|
+
type NewDocOpts = Partial<DucDocElement> & ElementConstructorOpts;
|
|
49
|
+
export declare function newDocElement(opts: NewDocOpts): NonDeleted<DucDocElement>;
|
|
50
|
+
type NewPdfOpts = Partial<DucPdfElement> & ElementConstructorOpts;
|
|
51
|
+
export declare function newPdfElement(opts: NewPdfOpts): NonDeleted<DucPdfElement>;
|
|
52
|
+
type NewModelOpts = Partial<DucModelElement> & ElementConstructorOpts;
|
|
53
|
+
export declare function newModelElement(opts: NewModelOpts): NonDeleted<DucModelElement>;
|
|
40
54
|
/**
|
|
41
55
|
* Clones DucElement data structure. Does not regenerate id, nonce, or
|
|
42
56
|
* any value. The purpose is to to break object references for immutability
|
|
@@ -54,3 +68,4 @@ export declare const deepCopyElement: <T extends DucElement>(val: T) => Mutable<
|
|
|
54
68
|
export declare const regenerateId: (
|
|
55
69
|
/** supply null if no previous id exists */
|
|
56
70
|
previousId: string | null) => string;
|
|
71
|
+
export {};
|
|
@@ -11,7 +11,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { getUpdatedTimestamp } from "..";
|
|
13
13
|
import { IMAGE_STATUS, LINE_SPACING_TYPE, } from "../../enums";
|
|
14
|
-
import { getPrecisionValueFromRaw } from "../../technical/scopes";
|
|
15
14
|
import { DEFAULT_ELEMENT_PROPS, DEFAULT_ELLIPSE_ELEMENT, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, DEFAULT_FREEDRAW_ELEMENT, DEFAULT_POLYGON_SIDES, DEFAULT_TEXT_ALIGN, DEFAULT_VERTICAL_ALIGN } from "../constants";
|
|
16
15
|
import { randomId, randomInteger } from "../math/random";
|
|
17
16
|
import { normalizeText } from "../normalize";
|
|
@@ -37,9 +36,9 @@ force = false) => {
|
|
|
37
36
|
}
|
|
38
37
|
return Object.assign(Object.assign(Object.assign({}, element), updates), { updated: getUpdatedTimestamp(), version: element.version + 1, versionNonce: randomInteger() });
|
|
39
38
|
};
|
|
40
|
-
const _newElementBase = (type,
|
|
41
|
-
var
|
|
42
|
-
|
|
39
|
+
const _newElementBase = (type, opts) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const { x, y, zIndex, index = DEFAULT_ELEMENT_PROPS.index, label, isVisible = DEFAULT_ELEMENT_PROPS.isVisible, isPlot = DEFAULT_ELEMENT_PROPS.isPlot, stroke = [DEFAULT_ELEMENT_PROPS.stroke], background = [DEFAULT_ELEMENT_PROPS.background], opacity = DEFAULT_ELEMENT_PROPS.opacity, width = DEFAULT_ELEMENT_PROPS.width, height = DEFAULT_ELEMENT_PROPS.height, angle = DEFAULT_ELEMENT_PROPS.angle, groupIds = DEFAULT_ELEMENT_PROPS.groupIds, blockIds = [], instanceId = null, regionIds = [], frameId = DEFAULT_ELEMENT_PROPS.frameId, layerId = null, roundness = DEFAULT_ELEMENT_PROPS.roundness, boundElements = DEFAULT_ELEMENT_PROPS.boundElements, link = DEFAULT_ELEMENT_PROPS.link, locked = DEFAULT_ELEMENT_PROPS.locked, description = null } = opts, rest = __rest(opts, ["x", "y", "zIndex", "index", "label", "isVisible", "isPlot", "stroke", "background", "opacity", "width", "height", "angle", "groupIds", "blockIds", "instanceId", "regionIds", "frameId", "layerId", "roundness", "boundElements", "link", "locked", "description"]);
|
|
43
42
|
// assign type to guard against excess properties
|
|
44
43
|
const element = {
|
|
45
44
|
id: rest.id || randomId(),
|
|
@@ -60,10 +59,9 @@ const _newElementBase = (type, currentScope, _a) => {
|
|
|
60
59
|
frameId,
|
|
61
60
|
roundness,
|
|
62
61
|
label,
|
|
63
|
-
|
|
64
|
-
seed: (_b = rest.seed) !== null && _b !== void 0 ? _b : randomInteger(),
|
|
62
|
+
seed: (_a = rest.seed) !== null && _a !== void 0 ? _a : randomInteger(),
|
|
65
63
|
version: rest.version || 1,
|
|
66
|
-
versionNonce: (
|
|
64
|
+
versionNonce: (_b = rest.versionNonce) !== null && _b !== void 0 ? _b : 0,
|
|
67
65
|
isDeleted: false,
|
|
68
66
|
boundElements,
|
|
69
67
|
updated: getUpdatedTimestamp(),
|
|
@@ -78,38 +76,43 @@ const _newElementBase = (type, currentScope, _a) => {
|
|
|
78
76
|
};
|
|
79
77
|
return element;
|
|
80
78
|
};
|
|
81
|
-
export
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
79
|
+
export function newElement(opts) {
|
|
80
|
+
return _newElementBase(opts.type, opts);
|
|
81
|
+
}
|
|
82
|
+
export function newEmbeddableElement(opts) {
|
|
83
|
+
return Object.assign(Object.assign({}, opts), _newElementBase(opts.type, opts));
|
|
84
|
+
}
|
|
85
|
+
export function newFrameElement(opts) {
|
|
86
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, getDefaultStackProperties()), { clip: false, labelVisible: true }), _newElementBase("frame", opts)), { type: "frame" });
|
|
87
|
+
}
|
|
88
|
+
export function newPlotElement(opts) {
|
|
89
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, getDefaultStackProperties()), { clip: false, labelVisible: true, layout: {
|
|
90
|
+
margins: {
|
|
91
|
+
top: 0,
|
|
92
|
+
right: 0,
|
|
93
|
+
bottom: 0,
|
|
94
|
+
left: 0,
|
|
95
|
+
},
|
|
96
|
+
} }), _newElementBase("plot", opts)), { type: "plot" });
|
|
97
|
+
}
|
|
98
|
+
export function newEllipseElement(opts) {
|
|
99
|
+
return Object.assign(Object.assign({}, _newElementBase(opts.type, opts)), { ratio: opts.ratio || DEFAULT_ELLIPSE_ELEMENT.ratio, startAngle: opts.startAngle || DEFAULT_ELLIPSE_ELEMENT.startAngle, endAngle: opts.endAngle || DEFAULT_ELLIPSE_ELEMENT.endAngle, showAuxCrosshair: opts.showAuxCrosshair || DEFAULT_ELLIPSE_ELEMENT.showAuxCrosshair });
|
|
100
|
+
}
|
|
101
|
+
export function newPolygonElement(opts) {
|
|
102
|
+
return Object.assign(Object.assign({}, _newElementBase(opts.type, opts)), { sides: opts.sides || DEFAULT_POLYGON_SIDES });
|
|
103
|
+
}
|
|
104
|
+
export function newTextElement(opts) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
103
106
|
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
|
|
104
|
-
const fontSize = opts.fontSize
|
|
107
|
+
const fontSize = typeof opts.fontSize === "number" ? opts.fontSize : ((_b = (_a = opts.fontSize) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : DEFAULT_FONT_SIZE);
|
|
105
108
|
const lineHeight = opts.lineHeight || 1.2;
|
|
106
109
|
const text = normalizeText(opts.text);
|
|
107
|
-
const metrics = measureText(text, getFontString({ fontFamily, fontSize }), lineHeight
|
|
110
|
+
const metrics = measureText(text, getFontString({ fontFamily, fontSize }), lineHeight);
|
|
108
111
|
const textAlign = opts.textAlign || DEFAULT_TEXT_ALIGN;
|
|
109
112
|
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
|
|
110
113
|
const offsets = getTextElementPositionOffsets({ textAlign, verticalAlign }, metrics);
|
|
111
114
|
// Minimum dimensions: at least 1px wide, at least one line high (NaN-safe)
|
|
112
|
-
const rawMinLineHeight = fontSize
|
|
115
|
+
const rawMinLineHeight = fontSize * lineHeight;
|
|
113
116
|
const minLineHeight = (Number.isFinite(rawMinLineHeight) && rawMinLineHeight > 0)
|
|
114
117
|
? rawMinLineHeight
|
|
115
118
|
: DEFAULT_FONT_SIZE * lineHeight;
|
|
@@ -117,29 +120,30 @@ export const newTextElement = (currentScope, opts) => {
|
|
|
117
120
|
const finalHeight = (Number.isFinite(metrics.height) && metrics.height > 0)
|
|
118
121
|
? Math.max(metrics.height, minLineHeight)
|
|
119
122
|
: minLineHeight;
|
|
120
|
-
const x =
|
|
121
|
-
const y =
|
|
122
|
-
|
|
123
|
+
const rawX = typeof opts.x === "number" ? opts.x : ((_d = (_c = opts.x) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0);
|
|
124
|
+
const rawY = typeof opts.y === "number" ? opts.y : ((_f = (_e = opts.y) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0);
|
|
125
|
+
const x = rawX - offsets.x;
|
|
126
|
+
const y = rawY - offsets.y;
|
|
127
|
+
return Object.assign(Object.assign({}, _newElementBase("text", Object.assign(Object.assign({}, opts), { x, y }))), { type: "text", text,
|
|
123
128
|
fontSize,
|
|
124
129
|
fontFamily,
|
|
125
130
|
textAlign,
|
|
126
|
-
verticalAlign, width:
|
|
131
|
+
verticalAlign, width: finalWidth, height: finalHeight, containerId: opts.containerId || null, originalText: (_g = opts.originalText) !== null && _g !== void 0 ? _g : text, autoResize: (_h = opts.autoResize) !== null && _h !== void 0 ? _h : true, lineHeight,
|
|
127
132
|
// DucTextStyle properties
|
|
128
|
-
isLtr: (
|
|
129
|
-
}
|
|
130
|
-
export
|
|
131
|
-
var _a, _b, _c, _d;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
export const newLinearElement = (currentScope, opts) => {
|
|
133
|
+
isLtr: (_j = opts.isLtr) !== null && _j !== void 0 ? _j : true, bigFontFamily: opts.bigFontFamily || "sans-serif", lineSpacing: opts.lineSpacing || { type: LINE_SPACING_TYPE.MULTIPLE, value: lineHeight }, obliqueAngle: opts.obliqueAngle || 0, widthFactor: opts.widthFactor || 1, isUpsideDown: (_k = opts.isUpsideDown) !== null && _k !== void 0 ? _k : false, isBackwards: (_l = opts.isBackwards) !== null && _l !== void 0 ? _l : false });
|
|
134
|
+
}
|
|
135
|
+
export function newFreeDrawElement(opts) {
|
|
136
|
+
var _a, _b, _c, _d, _e;
|
|
137
|
+
return Object.assign(Object.assign({}, _newElementBase("freedraw", opts)), { type: "freedraw", points: opts.points || [], size: typeof opts.size === "number" ? opts.size : ((_b = (_a = opts.size) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : DEFAULT_FREEDRAW_ELEMENT.size), pressures: opts.pressures || [], simulatePressure: opts.simulatePressure, thinning: (_c = opts.thinning) !== null && _c !== void 0 ? _c : DEFAULT_FREEDRAW_ELEMENT.thinning, smoothing: (_d = opts.smoothing) !== null && _d !== void 0 ? _d : DEFAULT_FREEDRAW_ELEMENT.smoothing, streamline: (_e = opts.streamline) !== null && _e !== void 0 ? _e : DEFAULT_FREEDRAW_ELEMENT.streamline, easing: opts.easing || DEFAULT_FREEDRAW_ELEMENT.easing, lastCommittedPoint: null, start: opts.start || null, end: opts.end || null, svgPath: null });
|
|
138
|
+
}
|
|
139
|
+
export function newLinearElement(opts) {
|
|
136
140
|
var _a;
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
export
|
|
141
|
+
return Object.assign(Object.assign({}, _newElementBase("line", opts)), { type: "line", points: opts.points || [], lines: opts.lines || [], pathOverrides: opts.pathOverrides || [], lastCommittedPoint: null, startBinding: null, endBinding: null, wipeoutBelow: (_a = opts.wipeoutBelow) !== null && _a !== void 0 ? _a : false });
|
|
142
|
+
}
|
|
143
|
+
export function newArrowElement(opts) {
|
|
140
144
|
var _a;
|
|
141
|
-
return
|
|
142
|
-
}
|
|
145
|
+
return Object.assign(Object.assign({}, _newElementBase("arrow", opts)), { type: "arrow", points: opts.points || [], lines: opts.lines || [], pathOverrides: opts.pathOverrides || [], lastCommittedPoint: null, startBinding: null, endBinding: null, elbowed: (_a = opts.elbowed) !== null && _a !== void 0 ? _a : true });
|
|
146
|
+
}
|
|
143
147
|
const withDisabledContentVisibility = (items, fallback) => {
|
|
144
148
|
const source = (items === null || items === void 0 ? void 0 : items.length) ? items : [fallback];
|
|
145
149
|
return source.map((item) => (Object.assign(Object.assign({}, item), { content: Object.assign(Object.assign({}, item.content), { visible: false }) })));
|
|
@@ -153,32 +157,34 @@ const getDocumentElementStyle = (opts) => ({
|
|
|
153
157
|
stroke: withDisabledContentVisibility(opts.stroke, DEFAULT_ELEMENT_PROPS.stroke),
|
|
154
158
|
background: withDisabledContentVisibility(opts.background, DEFAULT_ELEMENT_PROPS.background),
|
|
155
159
|
});
|
|
156
|
-
export
|
|
160
|
+
export function newImageElement(opts) {
|
|
157
161
|
var _a, _b, _c;
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
export
|
|
162
|
+
return Object.assign(Object.assign({}, _newElementBase("image", Object.assign(Object.assign({}, opts), getMediaElementStyle(opts)))), { type: "image", status: (_a = opts.status) !== null && _a !== void 0 ? _a : IMAGE_STATUS.PENDING, fileId: (_b = opts.fileId) !== null && _b !== void 0 ? _b : null, scaleFlip: (_c = opts.scaleFlip) !== null && _c !== void 0 ? _c : [1, 1], crop: null, filter: null });
|
|
163
|
+
}
|
|
164
|
+
export function newTableElement(opts) {
|
|
161
165
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
162
|
-
return
|
|
166
|
+
return Object.assign(Object.assign({}, _newElementBase("table", opts)), { fileId: (_a = opts.fileId) !== null && _a !== void 0 ? _a : null, gridConfig: {
|
|
163
167
|
columns: (_c = (_b = opts.gridConfig) === null || _b === void 0 ? void 0 : _b.columns) !== null && _c !== void 0 ? _c : 1,
|
|
164
168
|
gapX: (_e = (_d = opts.gridConfig) === null || _d === void 0 ? void 0 : _d.gapX) !== null && _e !== void 0 ? _e : 0,
|
|
165
169
|
gapY: (_g = (_f = opts.gridConfig) === null || _f === void 0 ? void 0 : _f.gapY) !== null && _g !== void 0 ? _g : 0,
|
|
166
170
|
firstPageAlone: (_j = (_h = opts.gridConfig) === null || _h === void 0 ? void 0 : _h.firstPageAlone) !== null && _j !== void 0 ? _j : false,
|
|
167
171
|
scale: (_l = (_k = opts.gridConfig) === null || _k === void 0 ? void 0 : _k.scale) !== null && _l !== void 0 ? _l : 1,
|
|
168
|
-
}, type: "table" })
|
|
169
|
-
}
|
|
170
|
-
export
|
|
172
|
+
}, type: "table" });
|
|
173
|
+
}
|
|
174
|
+
export function newDocElement(opts) {
|
|
171
175
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
172
|
-
return
|
|
176
|
+
return Object.assign(Object.assign({}, _newElementBase("doc", Object.assign(Object.assign({}, opts), getDocumentElementStyle(opts)))), { type: "doc", text: opts.text || "", fileId: (_a = opts.fileId) !== null && _a !== void 0 ? _a : null, referencedFileIds: (_b = opts.referencedFileIds) !== null && _b !== void 0 ? _b : [], gridConfig: {
|
|
173
177
|
columns: (_d = (_c = opts.gridConfig) === null || _c === void 0 ? void 0 : _c.columns) !== null && _d !== void 0 ? _d : 1,
|
|
174
178
|
gapX: (_f = (_e = opts.gridConfig) === null || _e === void 0 ? void 0 : _e.gapX) !== null && _f !== void 0 ? _f : 0,
|
|
175
179
|
gapY: (_h = (_g = opts.gridConfig) === null || _g === void 0 ? void 0 : _g.gapY) !== null && _h !== void 0 ? _h : 0,
|
|
176
180
|
firstPageAlone: (_k = (_j = opts.gridConfig) === null || _j === void 0 ? void 0 : _j.firstPageAlone) !== null && _k !== void 0 ? _k : false,
|
|
177
181
|
scale: (_m = (_l = opts.gridConfig) === null || _l === void 0 ? void 0 : _l.scale) !== null && _m !== void 0 ? _m : 1,
|
|
178
|
-
} })
|
|
179
|
-
}
|
|
180
|
-
export
|
|
181
|
-
|
|
182
|
+
} });
|
|
183
|
+
}
|
|
184
|
+
export function newPdfElement(opts) {
|
|
185
|
+
return Object.assign(Object.assign({ fileId: null, gridConfig: { columns: 1, gapX: 0, gapY: 0, firstPageAlone: false, scale: 1 } }, _newElementBase("pdf", Object.assign(Object.assign({}, opts), getDocumentElementStyle(opts)))), { type: "pdf" });
|
|
186
|
+
}
|
|
187
|
+
export function newModelElement(opts) {
|
|
182
188
|
var _a;
|
|
183
189
|
const modelType = (_a = opts.modelType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
184
190
|
const backgroundFallback = modelType === "dxf" || modelType === "dwg"
|
|
@@ -188,8 +194,8 @@ export const newModelElement = (currentScope, opts) => {
|
|
|
188
194
|
stroke: withDisabledContentVisibility(opts.stroke, DEFAULT_ELEMENT_PROPS.stroke),
|
|
189
195
|
background: withDisabledContentVisibility(opts.background, backgroundFallback),
|
|
190
196
|
};
|
|
191
|
-
return Object.assign(Object.assign({ modelType: null, code: null, thumbnail: null, fileIds: [], viewerState: null }, _newElementBase("model",
|
|
192
|
-
}
|
|
197
|
+
return Object.assign(Object.assign({ modelType: null, code: null, thumbnail: null, fileIds: [], viewerState: null }, _newElementBase("model", Object.assign(Object.assign({}, opts), modelStyle))), { type: 'model' });
|
|
198
|
+
}
|
|
193
199
|
// Simplified deep clone for the purpose of cloning DucElement.
|
|
194
200
|
//
|
|
195
201
|
// Only clones plain objects and arrays. Doesn't clone Date, RegExp, Map, Set,
|