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,38 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DucLocalState, RawValue, Scope, ScopedValue } from "../../types";
|
|
1
|
+
import { DucLocalState } from "../../types";
|
|
3
2
|
import { DucElement, DucElementType, DucTextContainer, DucTextElement, DucTextElementWithContainer, ElementsMap, FontFamilyValues, FontString, NonDeletedDucElement } from "../../types/elements";
|
|
4
3
|
import { GeometricPoint } from "../../types/geometry.types";
|
|
5
4
|
import { ExtractSetType } from "../../types/utility.types";
|
|
6
5
|
import { getBoundTextElementPosition } from "./linearElement";
|
|
7
|
-
export declare const computeBoundTextPosition: (container: DucElement, boundTextElement: DucTextElementWithContainer, elementsMap: ElementsMap
|
|
8
|
-
x:
|
|
9
|
-
y:
|
|
6
|
+
export declare const computeBoundTextPosition: (container: DucElement, boundTextElement: DucTextElementWithContainer, elementsMap: ElementsMap) => {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
10
9
|
};
|
|
11
|
-
export declare const measureText: (text: string, font: FontString, lineHeight: DucTextElement["lineHeight"]
|
|
12
|
-
width:
|
|
13
|
-
height:
|
|
10
|
+
export declare const measureText: (text: string, font: FontString, lineHeight: DucTextElement["lineHeight"]) => {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
16
15
|
* We calculate the line height from the font size and the unitless line height,
|
|
17
16
|
* aligning with the W3C spec.
|
|
18
17
|
*/
|
|
19
|
-
export declare const getLineHeightInPx: (fontSize: DucTextElement["fontSize"], lineHeight: DucTextElement["lineHeight"]) =>
|
|
20
|
-
export declare const getApproxMinLineHeight: (fontSize: DucTextElement["fontSize"], lineHeight: DucTextElement["lineHeight"]) =>
|
|
21
|
-
export declare const getTextWidth: (text: string, font: FontString, forceAdvanceWidth?: true) =>
|
|
22
|
-
export declare const getTextHeight: (text: DucTextElement["text"], fontSize: DucTextElement["fontSize"], lineHeight: DucTextElement["lineHeight"]) =>
|
|
18
|
+
export declare const getLineHeightInPx: (fontSize: DucTextElement["fontSize"] | number, lineHeight: DucTextElement["lineHeight"]) => number;
|
|
19
|
+
export declare const getApproxMinLineHeight: (fontSize: DucTextElement["fontSize"] | number, lineHeight: DucTextElement["lineHeight"]) => number;
|
|
20
|
+
export declare const getTextWidth: (text: string, font: FontString, forceAdvanceWidth?: true) => number;
|
|
21
|
+
export declare const getTextHeight: (text: DucTextElement["text"], fontSize: DucTextElement["fontSize"], lineHeight: DucTextElement["lineHeight"]) => number;
|
|
23
22
|
export declare const parseTokens: (text: string) => string[];
|
|
24
23
|
export declare const wrapText: (text: string, font: FontString, maxWidth: number) => string;
|
|
25
24
|
export declare const charWidth: {
|
|
26
25
|
calculate: (char: string, font: FontString) => number;
|
|
27
26
|
getCache: (font: FontString) => number[];
|
|
28
27
|
};
|
|
29
|
-
export declare const getApproxMinLineWidth: (font: FontString, lineHeight: DucTextElement["lineHeight"]
|
|
30
|
-
export declare const getMinCharWidth: (font: FontString) =>
|
|
31
|
-
export declare const getMaxCharWidth: (font: FontString) =>
|
|
32
|
-
export declare const getContainerCenter: (container: DucElement,
|
|
28
|
+
export declare const getApproxMinLineWidth: (font: FontString, lineHeight: DucTextElement["lineHeight"]) => number;
|
|
29
|
+
export declare const getMinCharWidth: (font: FontString) => number;
|
|
30
|
+
export declare const getMaxCharWidth: (font: FontString) => number;
|
|
31
|
+
export declare const getContainerCenter: (container: DucElement, _DucState: DucLocalState, elementsMap: ElementsMap) => GeometricPoint;
|
|
33
32
|
export declare const getContainerCoords: (container: NonDeletedDucElement) => {
|
|
34
|
-
x:
|
|
35
|
-
y:
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
36
35
|
};
|
|
37
36
|
export declare const getTextElementAngle: (textElement: DucTextElement, container: DucTextContainer | null) => import("../..").Radian;
|
|
38
37
|
export declare const shouldAllowVerticalAlign: (selectedElements: NonDeletedDucElement[], elementsMap: ElementsMap) => boolean;
|
|
@@ -41,11 +40,11 @@ declare const VALID_CONTAINER_TYPES: Set<string>;
|
|
|
41
40
|
export declare const isValidTextContainer: (element: {
|
|
42
41
|
type: DucElementType;
|
|
43
42
|
}) => boolean;
|
|
44
|
-
export declare const computeContainerDimensionForBoundText: (dimension:
|
|
45
|
-
export declare const getBoundTextMaxWidth: (container: DucElement, boundTextElement: DucTextElement | null) =>
|
|
46
|
-
export declare const getBoundTextMaxHeight: (container: DucElement, boundTextElement: DucTextElementWithContainer) =>
|
|
47
|
-
export declare const isMeasureTextSupported: (
|
|
48
|
-
export declare const getMinTextElementWidth: (font: FontString, lineHeight: DucTextElement["lineHeight"]
|
|
43
|
+
export declare const computeContainerDimensionForBoundText: (dimension: number, containerType: ExtractSetType<typeof VALID_CONTAINER_TYPES>) => number;
|
|
44
|
+
export declare const getBoundTextMaxWidth: (container: DucElement, boundTextElement: DucTextElement | null) => number;
|
|
45
|
+
export declare const getBoundTextMaxHeight: (container: DucElement, boundTextElement: DucTextElementWithContainer) => number;
|
|
46
|
+
export declare const isMeasureTextSupported: () => boolean;
|
|
47
|
+
export declare const getMinTextElementWidth: (font: FontString, lineHeight: DucTextElement["lineHeight"]) => number;
|
|
49
48
|
/** retrieves text from text elements and concatenates to a single string */
|
|
50
49
|
export declare const getTextFromElements: (elements: readonly DucElement[], separator?: string) => string;
|
|
51
50
|
export declare const getFontFamilyString: ({ fontFamily, }: {
|
|
@@ -61,17 +60,17 @@ export declare const getTextElementPositionOffsets: (opts: {
|
|
|
61
60
|
textAlign: DucTextElement["textAlign"];
|
|
62
61
|
verticalAlign: DucTextElement["verticalAlign"];
|
|
63
62
|
}, metrics: {
|
|
64
|
-
width:
|
|
65
|
-
height:
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
66
65
|
}) => {
|
|
67
66
|
x: number;
|
|
68
67
|
y: number;
|
|
69
68
|
};
|
|
70
|
-
export declare const refreshTextDimensions: (textElement: DucTextElement, container: DucTextContainer | null, elementsMap: ElementsMap,
|
|
71
|
-
x:
|
|
72
|
-
y:
|
|
73
|
-
width:
|
|
74
|
-
height:
|
|
69
|
+
export declare const refreshTextDimensions: (textElement: DucTextElement, container: DucTextContainer | null, elementsMap: ElementsMap, text?: string) => {
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
75
74
|
text: string;
|
|
76
75
|
} | undefined;
|
|
77
76
|
export declare const splitIntoLines: (text: string) => string[];
|
|
@@ -80,10 +79,10 @@ export declare const splitIntoLines: (text: string) => string[];
|
|
|
80
79
|
* height-per-line by fontSize.
|
|
81
80
|
*/
|
|
82
81
|
export declare const detectLineHeight: (textElement: DucTextElement) => DucTextElement["lineHeight"];
|
|
83
|
-
export declare const getAdjustedDimensions: (element: DucTextElement, elementsMap: ElementsMap, nextText: string
|
|
84
|
-
x:
|
|
85
|
-
y:
|
|
86
|
-
width:
|
|
87
|
-
height:
|
|
82
|
+
export declare const getAdjustedDimensions: (element: DucTextElement, elementsMap: ElementsMap, nextText: string) => {
|
|
83
|
+
x: number;
|
|
84
|
+
y: number;
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
88
87
|
};
|
|
89
88
|
export { getBoundTextElementPosition };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { TEXT_ALIGN, VERTICAL_ALIGN } from "../../enums";
|
|
2
|
-
import { getPrecisionValueFromRaw, getScopedBezierPointFromDucPoint } from "../../technical/scopes";
|
|
3
2
|
import { isArrowElement, isBoundToContainer, isTextElement } from "../../types/elements/typeChecks";
|
|
4
3
|
import { getContainerElement, getElementAbsoluteCoords, getResizedElementAbsoluteCoords } from "../bounds";
|
|
5
4
|
import { ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO, ARROW_LABEL_WIDTH_FRACTION, BOUND_TEXT_PADDING, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, LEGACY_FONT_ID_TO_NAME, WINDOWS_EMOJI_FALLBACK_FONT } from "../constants";
|
|
6
5
|
import { adjustXYWithRotation } from "../math";
|
|
7
6
|
import { normalizeText } from "../normalize";
|
|
8
7
|
import { getBoundTextElementPosition, getPointGlobalCoordinates, getPointsGlobalCoordinates, getSegmentMidPoint } from "./linearElement";
|
|
9
|
-
|
|
8
|
+
const toNum = (val, fallback = 0) => { var _a; return typeof val === "number" ? val : ((_a = val === null || val === void 0 ? void 0 : val.value) !== null && _a !== void 0 ? _a : fallback); };
|
|
9
|
+
export const computeBoundTextPosition = (container, boundTextElement, elementsMap) => {
|
|
10
10
|
if (isArrowElement(container)) {
|
|
11
|
-
const coords = getBoundTextElementPosition(container, boundTextElement, elementsMap
|
|
11
|
+
const coords = getBoundTextElementPosition(container, boundTextElement, elementsMap);
|
|
12
12
|
if (coords === null) {
|
|
13
13
|
return {
|
|
14
|
-
x:
|
|
15
|
-
y:
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
return { x: coords.x, y: coords.y };
|
|
@@ -20,34 +20,34 @@ export const computeBoundTextPosition = (container, boundTextElement, elementsMa
|
|
|
20
20
|
const containerCoords = getContainerCoords(container);
|
|
21
21
|
const maxContainerHeight = getBoundTextMaxHeight(container, boundTextElement);
|
|
22
22
|
const maxContainerWidth = getBoundTextMaxWidth(container, boundTextElement);
|
|
23
|
+
const bth = toNum(boundTextElement.height);
|
|
24
|
+
const btw = toNum(boundTextElement.width);
|
|
23
25
|
let x;
|
|
24
26
|
let y;
|
|
25
27
|
if (boundTextElement.verticalAlign === VERTICAL_ALIGN.TOP) {
|
|
26
28
|
y = containerCoords.y;
|
|
27
29
|
}
|
|
28
30
|
else if (boundTextElement.verticalAlign === VERTICAL_ALIGN.BOTTOM) {
|
|
29
|
-
y = containerCoords.y + (maxContainerHeight -
|
|
31
|
+
y = containerCoords.y + (maxContainerHeight - bth);
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
32
34
|
y =
|
|
33
35
|
containerCoords.y +
|
|
34
|
-
(maxContainerHeight / 2 -
|
|
36
|
+
(maxContainerHeight / 2 - bth / 2);
|
|
35
37
|
}
|
|
36
38
|
if (boundTextElement.textAlign === TEXT_ALIGN.LEFT) {
|
|
37
39
|
x = containerCoords.x;
|
|
38
40
|
}
|
|
39
41
|
else if (boundTextElement.textAlign === TEXT_ALIGN.RIGHT) {
|
|
40
|
-
x = containerCoords.x + (maxContainerWidth -
|
|
42
|
+
x = containerCoords.x + (maxContainerWidth - btw);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
45
|
x =
|
|
44
|
-
containerCoords.x + (maxContainerWidth / 2 -
|
|
46
|
+
containerCoords.x + (maxContainerWidth / 2 - btw / 2);
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
const yValue = getPrecisionValueFromRaw(y, boundTextElement.scope, currentScope);
|
|
48
|
-
return { x: xValue.scoped, y: yValue.scoped };
|
|
48
|
+
return { x, y };
|
|
49
49
|
};
|
|
50
|
-
export const measureText = (text, font, lineHeight
|
|
50
|
+
export const measureText = (text, font, lineHeight) => {
|
|
51
51
|
text = text
|
|
52
52
|
.split("\n")
|
|
53
53
|
// replace empty lines with single space because leading/trailing empty
|
|
@@ -60,8 +60,7 @@ export const measureText = (text, font, lineHeight, currentScope) => {
|
|
|
60
60
|
const safeFontSize = (Number.isFinite(parsedFontSize) && parsedFontSize > 0)
|
|
61
61
|
? parsedFontSize
|
|
62
62
|
: DEFAULT_FONT_SIZE;
|
|
63
|
-
const
|
|
64
|
-
const height = getTextHeight(text, fontSize, lineHeight);
|
|
63
|
+
const height = getTextHeight(text, safeFontSize, lineHeight);
|
|
65
64
|
const width = getTextWidth(text, font);
|
|
66
65
|
// Defensive: ensure we never return 0 or NaN dimensions
|
|
67
66
|
const safeWidth = (Number.isFinite(width) && width > 0) ? width : 1;
|
|
@@ -73,11 +72,11 @@ export const measureText = (text, font, lineHeight, currentScope) => {
|
|
|
73
72
|
* aligning with the W3C spec.
|
|
74
73
|
*/
|
|
75
74
|
export const getLineHeightInPx = (fontSize, lineHeight) => {
|
|
76
|
-
return fontSize
|
|
75
|
+
return toNum(fontSize, DEFAULT_FONT_SIZE) * lineHeight;
|
|
77
76
|
};
|
|
78
77
|
// FIXME rename to getApproxMinContainerHeight
|
|
79
78
|
export const getApproxMinLineHeight = (fontSize, lineHeight) => {
|
|
80
|
-
return getLineHeightInPx(fontSize, lineHeight) +
|
|
79
|
+
return getLineHeightInPx(fontSize, lineHeight) + BOUND_TEXT_PADDING * 2;
|
|
81
80
|
};
|
|
82
81
|
let canvas;
|
|
83
82
|
/**
|
|
@@ -292,13 +291,13 @@ export const charWidth = (() => {
|
|
|
292
291
|
})();
|
|
293
292
|
const DUMMY_TEXT = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase();
|
|
294
293
|
// FIXME rename to getApproxMinContainerWidth
|
|
295
|
-
export const getApproxMinLineWidth = (font, lineHeight
|
|
294
|
+
export const getApproxMinLineWidth = (font, lineHeight) => {
|
|
296
295
|
const maxCharWidth = getMaxCharWidth(font);
|
|
297
296
|
if (maxCharWidth === 0) {
|
|
298
|
-
return (measureText(DUMMY_TEXT.split("").join("\n"), font, lineHeight
|
|
297
|
+
return (measureText(DUMMY_TEXT.split("").join("\n"), font, lineHeight).width +
|
|
299
298
|
BOUND_TEXT_PADDING * 2);
|
|
300
299
|
}
|
|
301
|
-
return
|
|
300
|
+
return maxCharWidth + BOUND_TEXT_PADDING * 2;
|
|
302
301
|
};
|
|
303
302
|
export const getMinCharWidth = (font) => {
|
|
304
303
|
const cache = charWidth.getCache(font);
|
|
@@ -316,50 +315,48 @@ export const getMaxCharWidth = (font) => {
|
|
|
316
315
|
const cacheWithOutEmpty = cache.filter((val) => val !== undefined);
|
|
317
316
|
return Math.max(...cacheWithOutEmpty);
|
|
318
317
|
};
|
|
319
|
-
export const getContainerCenter = (container,
|
|
318
|
+
export const getContainerCenter = (container, _DucState, elementsMap) => {
|
|
320
319
|
if (!isArrowElement(container)) {
|
|
321
320
|
return {
|
|
322
|
-
x: container.x
|
|
323
|
-
y: container.y
|
|
321
|
+
x: toNum(container.x) + toNum(container.width) / 2,
|
|
322
|
+
y: toNum(container.y) + toNum(container.height) / 2,
|
|
324
323
|
};
|
|
325
324
|
}
|
|
326
|
-
const points = getPointsGlobalCoordinates(container, elementsMap
|
|
325
|
+
const points = getPointsGlobalCoordinates(container, elementsMap);
|
|
327
326
|
if (points.length % 2 === 1) {
|
|
328
327
|
const index = Math.floor(container.points.length / 2);
|
|
329
|
-
const midPoint = getPointGlobalCoordinates(container,
|
|
328
|
+
const midPoint = getPointGlobalCoordinates(container, { x: container.points[index].x, y: container.points[index].y }, elementsMap);
|
|
330
329
|
return { x: midPoint.x, y: midPoint.y };
|
|
331
330
|
}
|
|
332
331
|
const index = container.points.length / 2 - 1;
|
|
333
|
-
// const initialMidSegmentMidpoint = getEditorMidPoints(
|
|
334
|
-
// container,
|
|
335
|
-
// elementsMap,
|
|
336
|
-
// DucState,
|
|
337
|
-
// )[index];
|
|
338
332
|
let initialMidSegmentMidpoint; // FIXME: provide a better implementation for mid points handling
|
|
339
|
-
const initMidPoints = initialMidSegmentMidpoint &&
|
|
340
|
-
// Remove casting in the future
|
|
333
|
+
const initMidPoints = initialMidSegmentMidpoint && { x: initialMidSegmentMidpoint.x, y: initialMidSegmentMidpoint.y };
|
|
341
334
|
let midSegmentMidpoint = initMidPoints && { x: initMidPoints.x, y: initMidPoints.y };
|
|
342
335
|
if (!midSegmentMidpoint) {
|
|
343
|
-
midSegmentMidpoint = getSegmentMidPoint(container,
|
|
336
|
+
midSegmentMidpoint = getSegmentMidPoint(container, { x: points[index].x, y: points[index].y }, { x: points[index + 1].x, y: points[index + 1].y }, index + 1, elementsMap);
|
|
344
337
|
}
|
|
345
338
|
return { x: midSegmentMidpoint.x, y: midSegmentMidpoint.y };
|
|
346
339
|
};
|
|
347
340
|
export const getContainerCoords = (container) => {
|
|
348
341
|
let offsetX = BOUND_TEXT_PADDING;
|
|
349
342
|
let offsetY = BOUND_TEXT_PADDING;
|
|
343
|
+
const width = toNum(container.width);
|
|
344
|
+
const height = toNum(container.height);
|
|
345
|
+
const cx = toNum(container.x);
|
|
346
|
+
const cy = toNum(container.y);
|
|
350
347
|
if (container.type === "ellipse") {
|
|
351
348
|
// The derivation of coordinates is explained in https://github.com/excalidraw/excalidraw/pull/6172
|
|
352
|
-
offsetX += (
|
|
353
|
-
offsetY += (
|
|
349
|
+
offsetX += (width / 2) * (1 - Math.sqrt(2) / 2);
|
|
350
|
+
offsetY += (height / 2) * (1 - Math.sqrt(2) / 2);
|
|
354
351
|
}
|
|
355
352
|
// The derivation of coordinates is explained in https://github.com/excalidraw/excalidraw/pull/6265
|
|
356
353
|
if (container.type === "polygon") {
|
|
357
|
-
offsetX +=
|
|
358
|
-
offsetY +=
|
|
354
|
+
offsetX += width / 4;
|
|
355
|
+
offsetY += height / 4;
|
|
359
356
|
}
|
|
360
357
|
return {
|
|
361
|
-
x:
|
|
362
|
-
y:
|
|
358
|
+
x: cx + offsetX,
|
|
359
|
+
y: cy + offsetY,
|
|
363
360
|
};
|
|
364
361
|
};
|
|
365
362
|
export const getTextElementAngle = (textElement, container) => {
|
|
@@ -401,70 +398,69 @@ const VALID_CONTAINER_TYPES = new Set([
|
|
|
401
398
|
export const isValidTextContainer = (element) => VALID_CONTAINER_TYPES.has(element.type);
|
|
402
399
|
export const computeContainerDimensionForBoundText = (dimension, containerType) => {
|
|
403
400
|
dimension = Math.ceil(dimension);
|
|
404
|
-
const padding =
|
|
401
|
+
const padding = BOUND_TEXT_PADDING * 2;
|
|
405
402
|
if (containerType === "ellipse") {
|
|
406
403
|
return Math.round(((dimension + padding) / Math.sqrt(2)) * 2);
|
|
407
404
|
}
|
|
408
405
|
if (containerType === "arrow") {
|
|
409
|
-
return
|
|
406
|
+
return dimension + padding * 8;
|
|
410
407
|
}
|
|
411
408
|
if (containerType === "diamond") {
|
|
412
|
-
return
|
|
409
|
+
return 2 * (dimension + padding);
|
|
413
410
|
}
|
|
414
|
-
return
|
|
411
|
+
return dimension + padding;
|
|
415
412
|
};
|
|
416
413
|
export const getBoundTextMaxWidth = (container, boundTextElement) => {
|
|
417
|
-
|
|
418
|
-
const { width } = container;
|
|
414
|
+
const width = toNum(container.width);
|
|
419
415
|
if (isArrowElement(container)) {
|
|
420
|
-
const minWidth = (
|
|
416
|
+
const minWidth = toNum(boundTextElement === null || boundTextElement === void 0 ? void 0 : boundTextElement.fontSize, DEFAULT_FONT_SIZE) *
|
|
421
417
|
ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO;
|
|
422
|
-
return Math.max(ARROW_LABEL_WIDTH_FRACTION * width
|
|
418
|
+
return Math.max(ARROW_LABEL_WIDTH_FRACTION * width, minWidth);
|
|
423
419
|
}
|
|
424
420
|
if (container.type === "ellipse") {
|
|
425
421
|
// The width of the largest rectangle inscribed inside an ellipse is
|
|
426
422
|
// Math.round((ellipse.width / 2) * Math.sqrt(2)) which is derived from
|
|
427
423
|
// equation of an ellipse -https://github.com/excalidraw/excalidraw/pull/6172
|
|
428
|
-
return
|
|
424
|
+
return Math.round((width / 2) * Math.sqrt(2)) - BOUND_TEXT_PADDING * 2;
|
|
429
425
|
}
|
|
430
426
|
if (container.type === "polygon") {
|
|
431
427
|
// The width of the largest rectangle inscribed inside a rhombus is
|
|
432
428
|
// Math.round(width / 2) - https://github.com/excalidraw/excalidraw/pull/6265
|
|
433
|
-
return
|
|
429
|
+
return Math.round(width / 2) - BOUND_TEXT_PADDING * 2;
|
|
434
430
|
}
|
|
435
|
-
return
|
|
431
|
+
return width - BOUND_TEXT_PADDING * 2;
|
|
436
432
|
};
|
|
437
433
|
export const getBoundTextMaxHeight = (container, boundTextElement) => {
|
|
438
|
-
const
|
|
434
|
+
const height = toNum(container.height);
|
|
439
435
|
if (isArrowElement(container)) {
|
|
440
|
-
const containerHeight = height
|
|
436
|
+
const containerHeight = height - BOUND_TEXT_PADDING * 8 * 2;
|
|
441
437
|
if (containerHeight <= 0) {
|
|
442
|
-
return boundTextElement.height
|
|
438
|
+
return toNum(boundTextElement.height);
|
|
443
439
|
}
|
|
444
|
-
return height
|
|
440
|
+
return height;
|
|
445
441
|
}
|
|
446
442
|
if (container.type === "ellipse") {
|
|
447
443
|
// The height of the largest rectangle inscribed inside an ellipse is
|
|
448
444
|
// Math.round((ellipse.height / 2) * Math.sqrt(2)) which is derived from
|
|
449
445
|
// equation of an ellipse - https://github.com/excalidraw/excalidraw/pull/6172
|
|
450
|
-
return
|
|
446
|
+
return Math.round((height / 2) * Math.sqrt(2)) - BOUND_TEXT_PADDING * 2;
|
|
451
447
|
}
|
|
452
448
|
if (container.type === "polygon") {
|
|
453
449
|
// The height of the largest rectangle inscribed inside a rhombus is
|
|
454
450
|
// Math.round(height / 2) - https://github.com/excalidraw/excalidraw/pull/6265
|
|
455
|
-
return
|
|
451
|
+
return Math.round(height / 2) - BOUND_TEXT_PADDING * 2;
|
|
456
452
|
}
|
|
457
|
-
return
|
|
453
|
+
return height - BOUND_TEXT_PADDING * 2;
|
|
458
454
|
};
|
|
459
|
-
export const isMeasureTextSupported = (
|
|
455
|
+
export const isMeasureTextSupported = () => {
|
|
460
456
|
const width = getTextWidth(DUMMY_TEXT, getFontString({
|
|
461
|
-
fontSize:
|
|
457
|
+
fontSize: DEFAULT_FONT_SIZE,
|
|
462
458
|
fontFamily: DEFAULT_FONT_FAMILY,
|
|
463
459
|
}));
|
|
464
460
|
return width > 0;
|
|
465
461
|
};
|
|
466
|
-
export const getMinTextElementWidth = (font, lineHeight
|
|
467
|
-
return measureText("", font, lineHeight
|
|
462
|
+
export const getMinTextElementWidth = (font, lineHeight) => {
|
|
463
|
+
return measureText("", font, lineHeight).width + BOUND_TEXT_PADDING * 2;
|
|
468
464
|
};
|
|
469
465
|
/** retrieves text from text elements and concatenates to a single string */
|
|
470
466
|
export const getTextFromElements = (elements, separator = "\n\n") => {
|
|
@@ -496,7 +492,7 @@ export const getFontFamilyString = ({ fontFamily, }) => {
|
|
|
496
492
|
};
|
|
497
493
|
/** returns fontSize+fontFamily string for assignment to DOM elements */
|
|
498
494
|
export const getFontString = ({ fontSize, fontFamily, }) => {
|
|
499
|
-
return `${fontSize
|
|
495
|
+
return `${toNum(fontSize)}px ${getFontFamilyString({ fontFamily })}`;
|
|
500
496
|
};
|
|
501
497
|
/** computes element x/y offset based on textAlign/verticalAlign */
|
|
502
498
|
export const getTextElementPositionOffsets = (opts, metrics) => {
|
|
@@ -509,19 +505,19 @@ export const getTextElementPositionOffsets = (opts, metrics) => {
|
|
|
509
505
|
y: opts.verticalAlign === VERTICAL_ALIGN.MIDDLE ? metrics.height / 2 : 0,
|
|
510
506
|
};
|
|
511
507
|
};
|
|
512
|
-
export const refreshTextDimensions = (textElement, container, elementsMap,
|
|
508
|
+
export const refreshTextDimensions = (textElement, container, elementsMap, text = textElement.text) => {
|
|
513
509
|
if (textElement.isDeleted) {
|
|
514
510
|
return;
|
|
515
511
|
}
|
|
516
512
|
if (container || !textElement.autoResize) {
|
|
517
513
|
text = wrapText(text, getFontString({ fontFamily: textElement.fontFamily, fontSize: textElement.fontSize }), container
|
|
518
514
|
? getBoundTextMaxWidth(container, textElement)
|
|
519
|
-
: textElement.width
|
|
515
|
+
: toNum(textElement.width));
|
|
520
516
|
}
|
|
521
|
-
const dimensions = getAdjustedDimensions(textElement, elementsMap, text
|
|
517
|
+
const dimensions = getAdjustedDimensions(textElement, elementsMap, text);
|
|
522
518
|
// Defensive minimums — ensure height is always at least one line.
|
|
523
519
|
// Use negated >= to also catch NaN (NaN < x is always false).
|
|
524
|
-
const rawMinLineHeight = textElement.fontSize
|
|
520
|
+
const rawMinLineHeight = toNum(textElement.fontSize, DEFAULT_FONT_SIZE) * textElement.lineHeight;
|
|
525
521
|
const minLineHeight = (Number.isFinite(rawMinLineHeight) && rawMinLineHeight > 0)
|
|
526
522
|
? rawMinLineHeight
|
|
527
523
|
: DEFAULT_FONT_SIZE * textElement.lineHeight;
|
|
@@ -529,7 +525,7 @@ export const refreshTextDimensions = (textElement, container, elementsMap, curre
|
|
|
529
525
|
dimensions.height = minLineHeight;
|
|
530
526
|
}
|
|
531
527
|
if (!(dimensions.width > 0)) {
|
|
532
|
-
dimensions.width =
|
|
528
|
+
dimensions.width = textElement.autoResize ? 1 : toNum(textElement.width, 1);
|
|
533
529
|
}
|
|
534
530
|
return Object.assign({ text }, dimensions);
|
|
535
531
|
};
|
|
@@ -542,36 +538,36 @@ export const splitIntoLines = (text) => {
|
|
|
542
538
|
*/
|
|
543
539
|
export const detectLineHeight = (textElement) => {
|
|
544
540
|
const lineCount = splitIntoLines(textElement.text).length;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
541
|
+
const h = toNum(textElement.height);
|
|
542
|
+
const fs = toNum(textElement.fontSize, DEFAULT_FONT_SIZE);
|
|
543
|
+
return (h / lineCount / fs);
|
|
548
544
|
};
|
|
549
|
-
export const getAdjustedDimensions = (element, elementsMap, nextText
|
|
550
|
-
let { width: nextWidth, height: nextHeight } = measureText(nextText, getFontString({ fontFamily: element.fontFamily, fontSize: element.fontSize }), element.lineHeight
|
|
545
|
+
export const getAdjustedDimensions = (element, elementsMap, nextText) => {
|
|
546
|
+
let { width: nextWidth, height: nextHeight } = measureText(nextText, getFontString({ fontFamily: element.fontFamily, fontSize: element.fontSize }), element.lineHeight);
|
|
551
547
|
// wrapped text
|
|
552
548
|
if (!element.autoResize) {
|
|
553
|
-
nextWidth = element.width
|
|
549
|
+
nextWidth = toNum(element.width);
|
|
554
550
|
}
|
|
555
551
|
const { textAlign, verticalAlign } = element;
|
|
552
|
+
const elX = toNum(element.x);
|
|
553
|
+
const elY = toNum(element.y);
|
|
556
554
|
let x;
|
|
557
555
|
let y;
|
|
558
556
|
if (textAlign === TEXT_ALIGN.CENTER &&
|
|
559
557
|
verticalAlign === VERTICAL_ALIGN.MIDDLE &&
|
|
560
558
|
!element.containerId &&
|
|
561
559
|
element.autoResize) {
|
|
562
|
-
const prevMetrics = measureText(element.text, getFontString({ fontFamily: element.fontFamily, fontSize: element.fontSize }), element.lineHeight
|
|
560
|
+
const prevMetrics = measureText(element.text, getFontString({ fontFamily: element.fontFamily, fontSize: element.fontSize }), element.lineHeight);
|
|
563
561
|
const offsets = getTextElementPositionOffsets(element, {
|
|
564
562
|
width: nextWidth - prevMetrics.width,
|
|
565
563
|
height: nextHeight - prevMetrics.height,
|
|
566
564
|
});
|
|
567
|
-
x =
|
|
568
|
-
y =
|
|
565
|
+
x = elX - offsets.x;
|
|
566
|
+
y = elY - offsets.y;
|
|
569
567
|
}
|
|
570
568
|
else {
|
|
571
|
-
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap
|
|
572
|
-
const
|
|
573
|
-
const nextHeightValue = getPrecisionValueFromRaw(nextHeight, element.scope, currentScope);
|
|
574
|
-
const [nextX1, nextY1, nextX2, nextY2] = getResizedElementAbsoluteCoords(element, nextWidthValue.scoped, nextHeightValue.scoped, false, currentScope);
|
|
569
|
+
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
|
570
|
+
const [nextX1, nextY1, nextX2, nextY2] = getResizedElementAbsoluteCoords(element, nextWidth, nextHeight, false);
|
|
575
571
|
const deltaX1 = (x1 - nextX1) / 2;
|
|
576
572
|
const deltaY1 = (y1 - nextY1) / 2;
|
|
577
573
|
const deltaX2 = (x2 - nextX2) / 2;
|
|
@@ -580,15 +576,15 @@ export const getAdjustedDimensions = (element, elementsMap, nextText, currentSco
|
|
|
580
576
|
s: true,
|
|
581
577
|
e: textAlign === TEXT_ALIGN.CENTER || textAlign === TEXT_ALIGN.LEFT,
|
|
582
578
|
w: textAlign === TEXT_ALIGN.CENTER || textAlign === TEXT_ALIGN.RIGHT,
|
|
583
|
-
},
|
|
579
|
+
}, elX, elY, element.angle, deltaX1, deltaY1, deltaX2, deltaY2);
|
|
584
580
|
x = rotationPoint.x;
|
|
585
581
|
y = rotationPoint.y;
|
|
586
582
|
}
|
|
587
583
|
return {
|
|
588
584
|
width: nextWidth,
|
|
589
585
|
height: nextHeight,
|
|
590
|
-
x: Number.isFinite(x) ? x :
|
|
591
|
-
y: Number.isFinite(y) ? y :
|
|
586
|
+
x: Number.isFinite(x) ? x : elX,
|
|
587
|
+
y: Number.isFinite(y) ? y : elY,
|
|
592
588
|
};
|
|
593
589
|
};
|
|
594
590
|
export { getBoundTextElementPosition };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./url";
|
|
|
9
9
|
export * from "./version";
|
|
10
10
|
export * from "./filebyte";
|
|
11
11
|
export * from "./functionCodec";
|
|
12
|
-
export * from "./
|
|
12
|
+
export * from "./locator";
|
|
13
13
|
/**
|
|
14
14
|
* supply `null` as message if non-never value is valid, you just need to
|
|
15
15
|
* typecheck against it
|
package/dist/utils/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./url";
|
|
|
9
9
|
export * from "./version";
|
|
10
10
|
export * from "./filebyte";
|
|
11
11
|
export * from "./functionCodec";
|
|
12
|
-
export * from "./
|
|
12
|
+
export * from "./locator";
|
|
13
13
|
/**
|
|
14
14
|
* supply `null` as message if non-never value is valid, you just need to
|
|
15
15
|
* typecheck against it
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ExternalFileLocator, ExternalFileLocatorKind } from "../types";
|
|
2
|
+
export type ExternalFileResolutionStatus = "resolved" | "missing" | "inaccessible" | "unresolved";
|
|
3
|
+
export type ExternalFileResolutionResult = {
|
|
4
|
+
status: ExternalFileResolutionStatus;
|
|
5
|
+
resolvedPath?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
locator: ExternalFileLocator;
|
|
8
|
+
};
|
|
9
|
+
export type ResolveExternalFileOptions = {
|
|
10
|
+
owningDucPath?: string;
|
|
11
|
+
checkExists?: (resolvedPath: string) => boolean;
|
|
12
|
+
checkReadable?: (resolvedPath: string) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export type ResolveExternalFileAsyncOptions = {
|
|
15
|
+
owningDucPath?: string;
|
|
16
|
+
checkExists?: (resolvedPath: string) => Promise<boolean>;
|
|
17
|
+
checkReadable?: (resolvedPath: string) => Promise<boolean>;
|
|
18
|
+
};
|
|
19
|
+
export declare const normalizeHostPath: (path: string) => string;
|
|
20
|
+
export declare const normalizePathSegments: (path: string) => string;
|
|
21
|
+
export declare const getOwningDucDirectory: (path: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an ExternalFileLocator with explicit kind.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createExternalFileLocator(kind: ExternalFileLocatorKind, path: string, originalPath?: string): ExternalFileLocator;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the target filesystem path for an ExternalFileLocator without performing I/O.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveExternalFileLocatorPath(locator: ExternalFileLocator, owningDucPath?: string): {
|
|
30
|
+
resolvedPath?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Resolves an external file locator synchronously against the owning .duc path,
|
|
35
|
+
* optionally verifying filesystem accessibility.
|
|
36
|
+
* Preserves the original locator object intact regardless of whether resolution succeeds.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveExternalFileLocator(locator: ExternalFileLocator, options?: ResolveExternalFileOptions): ExternalFileResolutionResult;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves an external file locator asynchronously against the owning .duc path.
|
|
41
|
+
* Preserves the original locator object intact regardless of resolution status.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveExternalFileLocatorAsync(locator: ExternalFileLocator, options?: ResolveExternalFileAsyncOptions): Promise<ExternalFileResolutionResult>;
|