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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import * as paths from "../../dist/locator-runtime.js";
|
|
11
|
+
// Pure path rules run in the shared Rust module. Filesystem probes remain host callbacks.
|
|
12
|
+
export const normalizeHostPath = (path) => paths.normalizeHostPath(path || "");
|
|
13
|
+
export const normalizePathSegments = (path) => paths.normalizePathSegments(path);
|
|
14
|
+
export const getOwningDucDirectory = (path) => paths.getOwningDucDirectory(path);
|
|
15
|
+
/**
|
|
16
|
+
* Creates an ExternalFileLocator with explicit kind.
|
|
17
|
+
*/
|
|
18
|
+
export function createExternalFileLocator(kind, path, originalPath) {
|
|
19
|
+
const normalized = normalizeHostPath(path);
|
|
20
|
+
return Object.assign({ kind, path: normalized }, (originalPath !== undefined ? { originalPath } : path !== normalized ? { originalPath: path } : {}));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the target filesystem path for an ExternalFileLocator without performing I/O.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveExternalFileLocatorPath(locator, owningDucPath) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
try {
|
|
28
|
+
return { resolvedPath: paths.resolveLocatorPath((_a = locator === null || locator === void 0 ? void 0 : locator.kind) !== null && _a !== void 0 ? _a : "", (_b = locator === null || locator === void 0 ? void 0 : locator.path) !== null && _b !== void 0 ? _b : "", owningDucPath) };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolves an external file locator synchronously against the owning .duc path,
|
|
36
|
+
* optionally verifying filesystem accessibility.
|
|
37
|
+
* Preserves the original locator object intact regardless of whether resolution succeeds.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveExternalFileLocator(locator, options) {
|
|
40
|
+
const { resolvedPath, error } = resolveExternalFileLocatorPath(locator, options === null || options === void 0 ? void 0 : options.owningDucPath);
|
|
41
|
+
if (error || !resolvedPath) {
|
|
42
|
+
return {
|
|
43
|
+
status: "unresolved",
|
|
44
|
+
error: error !== null && error !== void 0 ? error : "Unable to resolve locator path",
|
|
45
|
+
locator,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if ((options === null || options === void 0 ? void 0 : options.checkExists) && !options.checkExists(resolvedPath)) {
|
|
49
|
+
return {
|
|
50
|
+
status: "missing",
|
|
51
|
+
resolvedPath,
|
|
52
|
+
error: `External file not found at ${resolvedPath}`,
|
|
53
|
+
locator,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if ((options === null || options === void 0 ? void 0 : options.checkReadable) && !options.checkReadable(resolvedPath)) {
|
|
57
|
+
return {
|
|
58
|
+
status: "inaccessible",
|
|
59
|
+
resolvedPath,
|
|
60
|
+
error: `External file at ${resolvedPath} is not accessible`,
|
|
61
|
+
locator,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
status: "resolved",
|
|
66
|
+
resolvedPath,
|
|
67
|
+
locator,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolves an external file locator asynchronously against the owning .duc path.
|
|
72
|
+
* Preserves the original locator object intact regardless of resolution status.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveExternalFileLocatorAsync(locator, options) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const { resolvedPath, error } = resolveExternalFileLocatorPath(locator, options === null || options === void 0 ? void 0 : options.owningDucPath);
|
|
77
|
+
if (error || !resolvedPath) {
|
|
78
|
+
return {
|
|
79
|
+
status: "unresolved",
|
|
80
|
+
error: error !== null && error !== void 0 ? error : "Unable to resolve locator path",
|
|
81
|
+
locator,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (options === null || options === void 0 ? void 0 : options.checkExists) {
|
|
85
|
+
const exists = yield options.checkExists(resolvedPath);
|
|
86
|
+
if (!exists) {
|
|
87
|
+
return {
|
|
88
|
+
status: "missing",
|
|
89
|
+
resolvedPath,
|
|
90
|
+
error: `External file not found at ${resolvedPath}`,
|
|
91
|
+
locator,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (options === null || options === void 0 ? void 0 : options.checkReadable) {
|
|
96
|
+
const readable = yield options.checkReadable(resolvedPath);
|
|
97
|
+
if (!readable) {
|
|
98
|
+
return {
|
|
99
|
+
status: "inaccessible",
|
|
100
|
+
resolvedPath,
|
|
101
|
+
error: `External file at ${resolvedPath} is not accessible`,
|
|
102
|
+
locator,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: "resolved",
|
|
108
|
+
resolvedPath,
|
|
109
|
+
locator,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Bounds, LineSegment } from "../../types/geometry.types";
|
|
2
|
-
import { GeometricPoint } from "../../types/geometry.types";
|
|
1
|
+
import { Bounds, GeometricPoint, LineSegment } from "../../types/geometry.types";
|
|
3
2
|
export declare function getBBox(line: LineSegment): Bounds;
|
|
4
3
|
export declare function crossProduct(a: GeometricPoint, b: GeometricPoint): number;
|
|
5
4
|
export declare function doBBoxesIntersect(a: Bounds, b: Bounds): boolean;
|
|
@@ -753,11 +753,12 @@ export const segmentsIntersectAt = (a, b) => {
|
|
|
753
753
|
*/
|
|
754
754
|
// TODO: Replace with final rounded rectangle code
|
|
755
755
|
export const segmentIntersectRectangleElement = (element, segment, gap = 0) => {
|
|
756
|
+
const toNum = (v) => { var _a; return typeof v === "number" ? v : ((_a = v === null || v === void 0 ? void 0 : v.value) !== null && _a !== void 0 ? _a : 0); };
|
|
756
757
|
const bounds = [
|
|
757
|
-
element.x
|
|
758
|
-
element.y
|
|
759
|
-
element.x
|
|
760
|
-
element.y
|
|
758
|
+
toNum(element.x) - gap,
|
|
759
|
+
toNum(element.y) - gap,
|
|
760
|
+
toNum(element.x) + toNum(element.width) + gap,
|
|
761
|
+
toNum(element.y) + toNum(element.height) + gap,
|
|
761
762
|
];
|
|
762
763
|
const center = {
|
|
763
764
|
x: (bounds[0] + bounds[2]) / 2,
|
|
@@ -2,9 +2,6 @@ export * from "./algebra";
|
|
|
2
2
|
export * from "./bbox";
|
|
3
3
|
export * from "./geometry";
|
|
4
4
|
export * from "./random";
|
|
5
|
-
import { SupportedMeasures } from "../../technical/scopes";
|
|
6
|
-
import type { Zoom } from "../../types";
|
|
7
|
-
import { Scope, ScopedValue } from "../../types";
|
|
8
5
|
import type { DucElement, DucLine, DucLinearElement, DucLinearLikeElement, DucPoint, NonDeleted } from "../../types/elements";
|
|
9
6
|
import type { Bounds, GeometricPoint, GeometricVector, Percentage, Radian } from "../../types/geometry.types";
|
|
10
7
|
import { Heading } from "../../types/geometry.types";
|
|
@@ -25,12 +22,11 @@ export declare const rotate: (x: number, y: number, cx: number, cy: number, angl
|
|
|
25
22
|
*/
|
|
26
23
|
export declare const rotatePoint: (point: GeometricPoint, center: GeometricPoint, angle: number) => GeometricPoint;
|
|
27
24
|
export declare const getSizeFromPoints: (points: readonly GeometricPoint[]) => {
|
|
28
|
-
width:
|
|
29
|
-
height:
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const rescaleLines: (dimension: "x" | "y", newSize: ScopedValue, lines: readonly DucLine[], points: readonly DucPoint[], normalize: boolean, elementScope: SupportedMeasures, currentScope: Scope) => DucLine[];
|
|
28
|
+
export declare const rescalePoints: (dimension: "x" | "y", newSize: number, points: readonly DucPoint[], normalize: boolean) => DucPoint[];
|
|
29
|
+
export declare const rescaleLines: (dimension: "x" | "y", newSize: number, lines: readonly DucLine[], points: readonly DucPoint[], normalize: boolean) => DucLine[];
|
|
34
30
|
/**
|
|
35
31
|
* Calculates the distance from a point to a line segment
|
|
36
32
|
* @param point The point to check distance from
|
|
@@ -85,20 +81,20 @@ export declare function getBezierPoint(start: GeometricPoint, cp1: GeometricPoin
|
|
|
85
81
|
* Enhanced version that handles edge cases better
|
|
86
82
|
*/
|
|
87
83
|
export declare function getQuadraticBezierBoundingBox(p0: GeometricPoint, p1: GeometricPoint, p2: GeometricPoint): {
|
|
88
|
-
minX:
|
|
89
|
-
minY:
|
|
90
|
-
maxX:
|
|
91
|
-
maxY:
|
|
84
|
+
minX: number;
|
|
85
|
+
minY: number;
|
|
86
|
+
maxX: number;
|
|
87
|
+
maxY: number;
|
|
92
88
|
};
|
|
93
89
|
/**
|
|
94
90
|
* Cubic bezier bounding box (from bounds.ts)
|
|
95
91
|
* Enhanced version that handles edge cases better
|
|
96
92
|
*/
|
|
97
93
|
export declare function getCubicBezierBoundingBox(p0: GeometricPoint, p1: GeometricPoint, p2: GeometricPoint, p3: GeometricPoint): {
|
|
98
|
-
minX:
|
|
99
|
-
minY:
|
|
100
|
-
maxX:
|
|
101
|
-
maxY:
|
|
94
|
+
minX: number;
|
|
95
|
+
minY: number;
|
|
96
|
+
maxX: number;
|
|
97
|
+
maxY: number;
|
|
102
98
|
};
|
|
103
99
|
/**
|
|
104
100
|
* Cubic bezier curve bound (returns Bounds tuple, from bounds.ts)
|
|
@@ -157,7 +153,7 @@ export declare const centerPoint: (a: GeometricPoint, b: GeometricPoint) => Geom
|
|
|
157
153
|
*/
|
|
158
154
|
export declare const isPathALoop: (points: DucLinearElement["points"],
|
|
159
155
|
/** Supply if you want the loop detection to account for current zoom */
|
|
160
|
-
zoomValue
|
|
156
|
+
zoomValue?: number) => boolean;
|
|
161
157
|
/**
|
|
162
158
|
* Determines if a Point is inside a Polygon defined by an array of Points.
|
|
163
159
|
*/
|
package/dist/utils/math/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from "./algebra";
|
|
|
2
2
|
export * from "./bbox";
|
|
3
3
|
export * from "./geometry";
|
|
4
4
|
export * from "./random";
|
|
5
|
-
import { getPrecisionValueFromRaw, getPrecisionValueFromScoped, getScopedBezierPointFromDucPoint } from "../../technical/scopes";
|
|
6
5
|
import { LINE_CONFIRM_THRESHOLD } from "../constants";
|
|
7
6
|
import { pointFrom } from "./geometry";
|
|
8
7
|
export const getRadianFromDegrees = (degrees) => {
|
|
@@ -49,47 +48,45 @@ export const getSizeFromPoints = (points) => {
|
|
|
49
48
|
};
|
|
50
49
|
};
|
|
51
50
|
/** @param dimension 0 for rescaling only x, 1 for y */
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const getCoord = (p, dim) => { var _a, _b; return typeof p[dim] === "number" ? p[dim] : ((_b = (_a = p[dim]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); };
|
|
52
|
+
export const rescalePoints = (dimension, newSize, points, normalize) => {
|
|
53
|
+
const coordinates = points.map((point) => getCoord(point, dimension));
|
|
54
54
|
const maxCoordinate = Math.max(...coordinates);
|
|
55
55
|
const minCoordinate = Math.min(...coordinates);
|
|
56
56
|
const size = maxCoordinate - minCoordinate;
|
|
57
57
|
const scale = size === 0 ? 1 : newSize / size;
|
|
58
58
|
const scaledPoints = points.map((point) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
return newPoint;
|
|
59
|
+
const val = getCoord(point, dimension);
|
|
60
|
+
return Object.assign(Object.assign({}, point), { [dimension]: val * scale });
|
|
62
61
|
});
|
|
63
62
|
if (!normalize || points.length === 0) {
|
|
64
63
|
return scaledPoints;
|
|
65
64
|
}
|
|
66
65
|
// With normalization, we move the points so that the first point
|
|
67
66
|
// is at the same position as original.
|
|
68
|
-
const translation = (points[0][
|
|
69
|
-
scaledPoints[0][dimension].scoped);
|
|
67
|
+
const translation = getCoord(points[0], dimension) - getCoord(scaledPoints[0], dimension);
|
|
70
68
|
const nextPoints = scaledPoints.map((scaledPoint) => {
|
|
71
|
-
const
|
|
72
|
-
return
|
|
69
|
+
const val = getCoord(scaledPoint, dimension);
|
|
70
|
+
return Object.assign(Object.assign({}, scaledPoint), { [dimension]: val + translation });
|
|
73
71
|
});
|
|
74
72
|
return nextPoints;
|
|
75
73
|
};
|
|
76
74
|
// Helper function to rescale DucLine handles
|
|
77
|
-
export const rescaleLines = (dimension, newSize, lines, points, normalize
|
|
78
|
-
const coordinates = points.map((point) => point
|
|
75
|
+
export const rescaleLines = (dimension, newSize, lines, points, normalize) => {
|
|
76
|
+
const coordinates = points.map((point) => getCoord(point, dimension));
|
|
79
77
|
const maxCoordinate = Math.max(...coordinates);
|
|
80
78
|
const minCoordinate = Math.min(...coordinates);
|
|
81
79
|
const size = maxCoordinate - minCoordinate;
|
|
82
80
|
const scale = size === 0 ? 1 : newSize / size;
|
|
83
81
|
let translation = 0;
|
|
84
82
|
if (normalize && points.length > 0) {
|
|
85
|
-
const scaledFirstPointCoordinate = points[0]
|
|
86
|
-
translation = (points[0]
|
|
87
|
-
scaledFirstPointCoordinate);
|
|
83
|
+
const scaledFirstPointCoordinate = getCoord(points[0], dimension) * scale;
|
|
84
|
+
translation = getCoord(points[0], dimension) - scaledFirstPointCoordinate;
|
|
88
85
|
}
|
|
89
86
|
const scaledLines = lines.map((line) => {
|
|
90
87
|
const [start, end] = line;
|
|
91
|
-
const scaledStart = Object.assign(Object.assign({}, start), { handle: start.handle ? Object.assign(Object.assign({}, start.handle), { [dimension]:
|
|
92
|
-
const scaledEnd = Object.assign(Object.assign({}, end), { handle: end.handle ? Object.assign(Object.assign({}, end.handle), { [dimension]:
|
|
88
|
+
const scaledStart = Object.assign(Object.assign({}, start), { handle: start.handle ? Object.assign(Object.assign({}, start.handle), { [dimension]: getCoord(start.handle, dimension) * scale + translation }) : null });
|
|
89
|
+
const scaledEnd = Object.assign(Object.assign({}, end), { handle: end.handle ? Object.assign(Object.assign({}, end.handle), { [dimension]: getCoord(end.handle, dimension) * scale + translation }) : null });
|
|
93
90
|
return [scaledStart, scaledEnd];
|
|
94
91
|
});
|
|
95
92
|
return scaledLines;
|
|
@@ -438,6 +435,7 @@ export const isPointCurved = (element, pointIndex) => {
|
|
|
438
435
|
* Gets the bezier handles for a point from the lines array
|
|
439
436
|
*/
|
|
440
437
|
export const getPointHandles = (element, pointIndex) => {
|
|
438
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
441
439
|
const handles = {};
|
|
442
440
|
// Find lines that connect to this point
|
|
443
441
|
for (const line of element.lines) {
|
|
@@ -445,15 +443,15 @@ export const getPointHandles = (element, pointIndex) => {
|
|
|
445
443
|
// Check if this point is the start of the line
|
|
446
444
|
if (start.index === pointIndex && start.handle) {
|
|
447
445
|
handles.handleOut = {
|
|
448
|
-
x: start.handle.x.
|
|
449
|
-
y: start.handle.y.
|
|
446
|
+
x: (_b = (_a = start.handle.x) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : start.handle.x,
|
|
447
|
+
y: (_d = (_c = start.handle.y) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : start.handle.y,
|
|
450
448
|
};
|
|
451
449
|
}
|
|
452
450
|
// Check if this point is the end of the line
|
|
453
451
|
if (end.index === pointIndex && end.handle) {
|
|
454
452
|
handles.handleIn = {
|
|
455
|
-
x: end.handle.x.
|
|
456
|
-
y: end.handle.y.
|
|
453
|
+
x: (_f = (_e = end.handle.x) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : end.handle.x,
|
|
454
|
+
y: (_h = (_g = end.handle.y) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : end.handle.y,
|
|
457
455
|
};
|
|
458
456
|
}
|
|
459
457
|
}
|
|
@@ -658,14 +656,17 @@ export const centerPoint = (a, b) => ({
|
|
|
658
656
|
*/
|
|
659
657
|
export const isPathALoop = (points,
|
|
660
658
|
/** Supply if you want the loop detection to account for current zoom */
|
|
661
|
-
zoomValue = 1
|
|
659
|
+
zoomValue = 1) => {
|
|
662
660
|
if (points.length >= 3) {
|
|
663
661
|
const [first, last] = [points[0], points[points.length - 1]];
|
|
664
|
-
const
|
|
665
|
-
const
|
|
662
|
+
const fx = getCoord(first, 'x');
|
|
663
|
+
const fy = getCoord(first, 'y');
|
|
664
|
+
const lx = getCoord(last, 'x');
|
|
665
|
+
const ly = getCoord(last, 'y');
|
|
666
|
+
const distance = distance2d(fx, fy, lx, ly);
|
|
666
667
|
// Adjusting LINE_CONFIRM_THRESHOLD to current zoom so that when zoomed in
|
|
667
668
|
// really close we make the threshold smaller, and vice versa.
|
|
668
|
-
return distance <=
|
|
669
|
+
return distance <= LINE_CONFIRM_THRESHOLD / zoomValue;
|
|
669
670
|
}
|
|
670
671
|
return false;
|
|
671
672
|
};
|
|
@@ -920,13 +921,18 @@ export const pointInsideBounds = (p, bounds) => p.x > bounds[0] && p.x < bounds[
|
|
|
920
921
|
* Get the axis-aligned bounding box for a given element.
|
|
921
922
|
*/
|
|
922
923
|
export const aabbForElement = (element, offset) => {
|
|
924
|
+
const toNum = (v) => { var _a; return typeof v === "number" ? v : ((_a = v === null || v === void 0 ? void 0 : v.value) !== null && _a !== void 0 ? _a : 0); };
|
|
925
|
+
const ex = toNum(element.x);
|
|
926
|
+
const ey = toNum(element.y);
|
|
927
|
+
const ew = toNum(element.width);
|
|
928
|
+
const eh = toNum(element.height);
|
|
923
929
|
const bbox = {
|
|
924
|
-
minX:
|
|
925
|
-
minY:
|
|
926
|
-
maxX:
|
|
927
|
-
maxY:
|
|
928
|
-
midX:
|
|
929
|
-
midY:
|
|
930
|
+
minX: ex,
|
|
931
|
+
minY: ey,
|
|
932
|
+
maxX: ex + ew,
|
|
933
|
+
maxY: ey + eh,
|
|
934
|
+
midX: ex + ew / 2,
|
|
935
|
+
midY: ey + eh / 2,
|
|
930
936
|
};
|
|
931
937
|
const center = { x: bbox.midX, y: bbox.midY };
|
|
932
938
|
const topLeft = rotatePoint({ x: bbox.minX, y: bbox.minY }, center, element.angle);
|
|
@@ -981,10 +987,13 @@ export const getCenterForBounds = (bounds) => ({
|
|
|
981
987
|
/**
|
|
982
988
|
* Gets the center point for a DucElement.
|
|
983
989
|
*/
|
|
984
|
-
export const getCenterForElement = (element) =>
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
990
|
+
export const getCenterForElement = (element) => {
|
|
991
|
+
const toNum = (v) => { var _a; return typeof v === "number" ? v : ((_a = v === null || v === void 0 ? void 0 : v.value) !== null && _a !== void 0 ? _a : 0); };
|
|
992
|
+
return {
|
|
993
|
+
x: toNum(element.x) + toNum(element.width) / 2,
|
|
994
|
+
y: toNum(element.y) + toNum(element.height) / 2,
|
|
995
|
+
};
|
|
996
|
+
};
|
|
988
997
|
/**
|
|
989
998
|
* Determines if two axis-aligned bounding boxes overlap.
|
|
990
999
|
*/
|
|
@@ -1048,7 +1057,7 @@ export const reverseExponent = (num) => {
|
|
|
1048
1057
|
* Retrieves control points for a Bezier curve.
|
|
1049
1058
|
*/
|
|
1050
1059
|
export const getControlPointsForBezierCurve = (element, endPoint) => {
|
|
1051
|
-
const endPointIndex = element.points.findIndex((p) => arePointsEqual(
|
|
1060
|
+
const endPointIndex = element.points.findIndex((p) => arePointsEqual({ x: p.x, y: p.y }, endPoint));
|
|
1052
1061
|
if (endPointIndex < 1) {
|
|
1053
1062
|
return null;
|
|
1054
1063
|
}
|
|
@@ -1060,15 +1069,18 @@ export const getControlPointsForBezierCurve = (element, endPoint) => {
|
|
|
1060
1069
|
}
|
|
1061
1070
|
const startRef = line[0].index === startPointIndex ? line[0] : line[1];
|
|
1062
1071
|
const endRef = line[1].index === startPointIndex ? line[1] : line[0];
|
|
1063
|
-
const p0 =
|
|
1064
|
-
const p3 =
|
|
1072
|
+
const p0 = { x: element.points[startRef.index].x, y: element.points[startRef.index].y };
|
|
1073
|
+
const p3 = { x: element.points[endRef.index].x, y: element.points[endRef.index].y };
|
|
1065
1074
|
if (startRef.handle && endRef.handle) {
|
|
1066
|
-
const p1 =
|
|
1067
|
-
const p2 =
|
|
1075
|
+
const p1 = { x: startRef.handle.x, y: startRef.handle.y };
|
|
1076
|
+
const p2 = { x: endRef.handle.x, y: endRef.handle.y };
|
|
1068
1077
|
return [p0, p1, p2, p3];
|
|
1069
1078
|
}
|
|
1070
1079
|
// Quadratic bezier, we need to convert to cubic
|
|
1071
|
-
const
|
|
1080
|
+
const h = startRef.handle || endRef.handle;
|
|
1081
|
+
if (!h)
|
|
1082
|
+
return null;
|
|
1083
|
+
const p1 = { x: h.x, y: h.y };
|
|
1072
1084
|
return [
|
|
1073
1085
|
p0,
|
|
1074
1086
|
{ x: p0.x + 2 / 3 * (p1.x - p0.x), y: p0.y + 2 / 3 * (p1.y - p0.y) },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { customAlphabet } from "nanoid";
|
|
2
2
|
export function randomSeed() {
|
|
3
3
|
return Math.floor(Math.random() * Math.pow(2, 31));
|
|
4
4
|
}
|
|
@@ -22,4 +22,9 @@ export const reseed = (seed) => {
|
|
|
22
22
|
random = new Random(seed);
|
|
23
23
|
testIdBase = 0;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
// Python-identifier-safe alphabet: letters, digits, underscore (no hyphens)
|
|
26
|
+
const ID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
|
27
|
+
const ID_INITIAL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
28
|
+
const generateBody = customAlphabet(ID_ALPHABET, 20);
|
|
29
|
+
const generateInitial = customAlphabet(ID_INITIAL_ALPHABET, 1);
|
|
30
|
+
export const randomId = () => `${generateInitial()}${generateBody()}`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { NormalizedZoomValue
|
|
1
|
+
import type { NormalizedZoomValue } from "../types";
|
|
2
2
|
import { DucElement, FixedPoint } from "../types/elements";
|
|
3
3
|
export declare const getNormalizedZoom: (zoom: number) => NormalizedZoomValue;
|
|
4
4
|
export declare const normalizeFixedPoint: <T extends FixedPoint | null>(fixedPoint: T) => T extends null ? null : FixedPoint;
|
|
5
5
|
export declare const getNormalizedDimensions: (element: Pick<DucElement, "width" | "height" | "x" | "y">) => {
|
|
6
|
-
width:
|
|
7
|
-
height:
|
|
8
|
-
x:
|
|
9
|
-
y:
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
10
|
};
|
|
11
11
|
export declare const normalizeEOL: (str: string) => string;
|
|
12
12
|
export declare const normalizeText: (text: string) => string;
|
package/dist/utils/normalize.js
CHANGED
|
@@ -15,21 +15,26 @@ export const normalizeFixedPoint = (fixedPoint) => {
|
|
|
15
15
|
return fixedPoint;
|
|
16
16
|
};
|
|
17
17
|
export const getNormalizedDimensions = (element) => {
|
|
18
|
+
const toNum = (v) => { var _a; return (typeof v === "number" ? v : ((_a = v === null || v === void 0 ? void 0 : v.value) !== null && _a !== void 0 ? _a : 0)); };
|
|
19
|
+
const elWidth = toNum(element.width);
|
|
20
|
+
const elHeight = toNum(element.height);
|
|
21
|
+
const elX = toNum(element.x);
|
|
22
|
+
const elY = toNum(element.y);
|
|
18
23
|
const ret = {
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
21
|
-
x:
|
|
22
|
-
y:
|
|
24
|
+
width: elWidth,
|
|
25
|
+
height: elHeight,
|
|
26
|
+
x: elX,
|
|
27
|
+
y: elY,
|
|
23
28
|
};
|
|
24
|
-
if (
|
|
25
|
-
const nextWidth = Math.abs(
|
|
29
|
+
if (elWidth < 0) {
|
|
30
|
+
const nextWidth = Math.abs(elWidth);
|
|
26
31
|
ret.width = nextWidth;
|
|
27
|
-
ret.x =
|
|
32
|
+
ret.x = elX - nextWidth;
|
|
28
33
|
}
|
|
29
|
-
if (
|
|
30
|
-
const nextHeight = Math.abs(
|
|
34
|
+
if (elHeight < 0) {
|
|
35
|
+
const nextHeight = Math.abs(elHeight);
|
|
31
36
|
ret.height = nextHeight;
|
|
32
|
-
ret.y =
|
|
37
|
+
ret.y = elY - nextHeight;
|
|
33
38
|
}
|
|
34
39
|
return ret;
|
|
35
40
|
};
|
package/dist/utils/shape.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Scope } from "../types";
|
|
2
1
|
import { DucElement, DucLine, DucLinearElement, DucNonSelectionElement, DucPath, DucPoint } from "../types/elements";
|
|
3
2
|
/**
|
|
4
3
|
* Converts a shape (rectangle, polygon, ellipse) to a linear element
|
|
5
4
|
*/
|
|
6
|
-
export declare const convertShapeToLinearElement: (
|
|
7
|
-
export declare const getCorrectedOrthodoxElementPoints: (element: DucElement, points: readonly DucPoint[], lines: readonly DucLine[]
|
|
5
|
+
export declare const convertShapeToLinearElement: (element: DucNonSelectionElement) => DucLinearElement | null;
|
|
6
|
+
export declare const getCorrectedOrthodoxElementPoints: (element: DucElement, points: readonly DucPoint[], lines: readonly DucLine[]) => {
|
|
8
7
|
points: DucPoint[];
|
|
9
8
|
lines: DucLine[];
|
|
10
9
|
};
|
|
11
|
-
export declare const getElementRelativePoints: (element: DucElement
|
|
10
|
+
export declare const getElementRelativePoints: (element: DucElement) => {
|
|
12
11
|
points: DucLinearElement["points"];
|
|
13
12
|
lines: DucLinearElement["lines"];
|
|
14
13
|
pathOverrides?: DucPath[];
|