@contrail/documents 1.19.0-alpha.8326aa7 → 1.20.0-alpha.23f6f22
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/CHANGELOG.md +3 -40
- package/lib/document-element-constants.d.ts +0 -3
- package/lib/document-element-constants.js +1 -22
- package/lib/index.d.ts +1 -4
- package/lib/index.js +1 -4
- package/lib/types/common.d.ts +5 -0
- package/lib/types/document-element.d.ts +2 -1
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +1 -3
- package/lib/util/dynamic-text/dynamic-text-util.js +21 -30
- package/lib/util/mask/index.d.ts +4 -0
- package/lib/util/mask/index.js +20 -0
- package/lib/util/mask/mask-preset-geometry.d.ts +3 -0
- package/lib/util/mask/mask-preset-geometry.js +19 -0
- package/lib/util/mask/mask-shape-geometry.d.ts +26 -0
- package/lib/util/mask/mask-shape-geometry.js +154 -0
- package/lib/util/mask/rotation-math.d.ts +2 -0
- package/lib/util/mask/rotation-math.js +14 -0
- package/lib/util/mask/shape-mask-element.d.ts +16 -0
- package/lib/util/mask/shape-mask-element.js +61 -0
- package/package.json +1 -1
- package/lib/containers/container-kind.d.ts +0 -10
- package/lib/containers/container-kind.js +0 -7
- package/lib/containers/document-container-index.d.ts +0 -24
- package/lib/containers/document-container-index.js +0 -63
- package/lib/containers/document-container.d.ts +0 -23
- package/lib/containers/document-container.js +0 -43
- package/lib/containers/document-container.service.d.ts +0 -14
- package/lib/containers/document-container.service.js +0 -147
package/CHANGELOG.md
CHANGED
|
@@ -5,49 +5,12 @@ All notable changes to `@contrail/documents` are documented here.
|
|
|
5
5
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.
|
|
8
|
+
## [1.20.0] - 2026-09-10
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- `
|
|
13
|
-
|
|
14
|
-
section, described by a `ContainerKind` carrying `elementType`, `nests` and `layer`. An element
|
|
15
|
-
belongs to the container whose box covers its measured centre and which is drawn below it.
|
|
16
|
-
Nesting gives a path with one container per depth, the later-drawn one winning where two cross.
|
|
17
|
-
A container is only ever content of a kind layered behind it, so a frame belongs to a section and
|
|
18
|
-
a section never to a frame. Shapes wider and taller than the container, and groups holding it,
|
|
19
|
-
are excluded.
|
|
20
|
-
- `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
|
|
21
|
-
`document-element-constants`, so the rule above has one definition rather than one per app.
|
|
22
|
-
|
|
23
|
-
### Deprecated
|
|
24
|
-
|
|
25
|
-
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
26
|
-
for what it decides: whether the binding's value comes from the container rather than a type
|
|
27
|
-
property. The old name still works and delegates to the new one.
|
|
28
|
-
|
|
29
|
-
### Fixed
|
|
30
|
-
|
|
31
|
-
- A dynamic text is now anchored at its position rather than its centre when deciding which
|
|
32
|
-
container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its size
|
|
33
|
-
comes from the value it resolves to, and that value depends on the container, so letting its width
|
|
34
|
-
feed membership meant its own text could choose its container: near an edge the two answers
|
|
35
|
-
disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
|
|
36
|
-
else still resolves on its centre.
|
|
37
|
-
- `min` and `max` rendered an infinity sign when every member value was empty. The early return
|
|
38
|
-
checked the list length before the empty values were filtered out, so `Math.min` of nothing
|
|
39
|
-
reached the formatter. Both now fall through to `n/a`.
|
|
40
|
-
- `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
|
|
41
|
-
the server failed the read for the whole document. It now measures from a zero size instead.
|
|
42
|
-
|
|
43
|
-
### Changed
|
|
44
|
-
|
|
45
|
-
- Container membership measures a scaled element from its scaled box. Scale grows an element from
|
|
46
|
-
its top-left, so it widens the box and moves the centre; a scaled element previously measured at
|
|
47
|
-
its unscaled size and could resolve to the wrong container. Applied in
|
|
48
|
-
`DocumentContainerService`, not in `DocumentElementFactory.getBoundingClientRect`, which is
|
|
49
|
-
unchanged: `@contrail/document-table` sizes table members from that box, and scaling it there
|
|
50
|
-
moved scaled members into different cells.
|
|
12
|
+
- `MaskDefinition` and `MaskShapeKey` on `DocumentElement` — `maskDefinition` records that an image is masked into one of nine preset shapes, with an optional clockwise `rotation`. Its presence changes how `cropDefinition`'s percents are read: element-space (the mask window within the element) instead of the source-image crop they otherwise mean. Anything deriving image geometry must check `hasShapeMask` before treating a crop as a source crop — reading one as the other samples the wrong region of the bitmap.
|
|
13
|
+
- `@contrail/documents/util/mask` — the shared mask model, exported from the package root: the nine shapes as renderer-agnostic cubic path segments (`getMaskShapeSegments`), `rotatedRectAABB` for the bounds a tilted shape actually occupies, `rotatePoint`, the mask-rect/percent conversions, and `MASK_SHAPE_PRESET_GEOMETRY` mapping each shape to its OOXML preset so exporters and the canvas cannot drift apart. Segments are cubic-only because cubics survive affine maps exactly, letting each consumer render them however it draws — `Path2D` in a browser, preset geometry in pptx.
|
|
51
14
|
|
|
52
15
|
## [1.18.0] - 2026-09-10
|
|
53
16
|
|
|
@@ -3,6 +3,3 @@ export declare const ANNOTATION_PADDING_Y = 8;
|
|
|
3
3
|
export declare const COLOR_PADDING = 5;
|
|
4
4
|
export declare const COLOR_FONT_SIZE = 8;
|
|
5
5
|
export declare const COLOR_WIDTH = 140;
|
|
6
|
-
export declare const SECTION_ELEMENT_TYPE = "section";
|
|
7
|
-
export declare const FRAME_ELEMENT_TYPE = "frame";
|
|
8
|
-
export declare const SHAPE_ELEMENT_TYPES: string[];
|
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ANNOTATION_PADDING_Y = exports.ANNOTATION_IMG_SIZE = void 0;
|
|
4
4
|
exports.ANNOTATION_IMG_SIZE = 15;
|
|
5
5
|
exports.ANNOTATION_PADDING_Y = 8;
|
|
6
6
|
exports.COLOR_PADDING = 5;
|
|
7
7
|
exports.COLOR_FONT_SIZE = 8;
|
|
8
8
|
exports.COLOR_WIDTH = 140;
|
|
9
|
-
exports.SECTION_ELEMENT_TYPE = 'section';
|
|
10
|
-
exports.FRAME_ELEMENT_TYPE = 'frame';
|
|
11
|
-
exports.SHAPE_ELEMENT_TYPES = [
|
|
12
|
-
'text',
|
|
13
|
-
'line',
|
|
14
|
-
'arrow',
|
|
15
|
-
'circle',
|
|
16
|
-
'rectangle',
|
|
17
|
-
'round_rectangle',
|
|
18
|
-
'triangle',
|
|
19
|
-
'diamond',
|
|
20
|
-
'star',
|
|
21
|
-
'heart',
|
|
22
|
-
'double_arrow',
|
|
23
|
-
'right_arrow',
|
|
24
|
-
'rhombus',
|
|
25
|
-
'cloud',
|
|
26
|
-
'callout',
|
|
27
|
-
'draw_frame',
|
|
28
|
-
'draw_section',
|
|
29
|
-
];
|
package/lib/index.d.ts
CHANGED
|
@@ -12,8 +12,5 @@ export * from './document-element-constants';
|
|
|
12
12
|
export * from './util/curved-line/point';
|
|
13
13
|
export * from './util/curved-line/curved-line';
|
|
14
14
|
export * from './util/callout/callout';
|
|
15
|
+
export * from './util/mask';
|
|
15
16
|
export * from './document-frame.service';
|
|
16
|
-
export * from './containers/container-kind';
|
|
17
|
-
export * from './containers/document-container';
|
|
18
|
-
export * from './containers/document-container-index';
|
|
19
|
-
export * from './containers/document-container.service';
|
package/lib/index.js
CHANGED
|
@@ -28,8 +28,5 @@ __exportStar(require("./document-element-constants"), exports);
|
|
|
28
28
|
__exportStar(require("./util/curved-line/point"), exports);
|
|
29
29
|
__exportStar(require("./util/curved-line/curved-line"), exports);
|
|
30
30
|
__exportStar(require("./util/callout/callout"), exports);
|
|
31
|
+
__exportStar(require("./util/mask"), exports);
|
|
31
32
|
__exportStar(require("./document-frame.service"), exports);
|
|
32
|
-
__exportStar(require("./containers/container-kind"), exports);
|
|
33
|
-
__exportStar(require("./containers/document-container"), exports);
|
|
34
|
-
__exportStar(require("./containers/document-container-index"), exports);
|
|
35
|
-
__exportStar(require("./containers/document-container.service"), exports);
|
package/lib/types/common.d.ts
CHANGED
|
@@ -74,6 +74,11 @@ export interface LineDefinition {
|
|
|
74
74
|
markerEnd?: string;
|
|
75
75
|
lineType?: LineType;
|
|
76
76
|
}
|
|
77
|
+
export type MaskShapeKey = 'circle' | 'square' | 'rounded' | 'triangle' | 'diamond' | 'parallelogram' | 'star' | 'heart' | 'cloud';
|
|
78
|
+
export interface MaskDefinition {
|
|
79
|
+
shape: MaskShapeKey;
|
|
80
|
+
rotation?: number;
|
|
81
|
+
}
|
|
77
82
|
export interface CropDefinition {
|
|
78
83
|
x1?: number;
|
|
79
84
|
x2?: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropertyLevel } from '@contrail/types';
|
|
2
|
-
import { CropDefinition, LineDefinition, PositionDefinition, RotationDefinition, SizeDefinition } from './common';
|
|
2
|
+
import { CropDefinition, LineDefinition, MaskDefinition, PositionDefinition, RotationDefinition, SizeDefinition } from './common';
|
|
3
3
|
import { Document } from './document';
|
|
4
4
|
import { ScaleTransformation } from './element-transformation';
|
|
5
5
|
export interface AlternateUrls {
|
|
@@ -32,6 +32,7 @@ export interface DocumentElement extends Document {
|
|
|
32
32
|
annotations?: any;
|
|
33
33
|
isLocked?: boolean;
|
|
34
34
|
cropDefinition?: CropDefinition;
|
|
35
|
+
maskDefinition?: MaskDefinition;
|
|
35
36
|
embedInfo?: any;
|
|
36
37
|
isHidden?: boolean;
|
|
37
38
|
elementIds?: Array<string>;
|
|
@@ -48,12 +48,10 @@ export declare const HARD_CODED_TEXT: {
|
|
|
48
48
|
'section.itemOptionCount': string;
|
|
49
49
|
'section.colorCount': string;
|
|
50
50
|
};
|
|
51
|
+
export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
|
|
51
52
|
export declare class DynamicTextUtil {
|
|
52
|
-
static isDynamicText(documentElement: DocumentElement): boolean;
|
|
53
|
-
static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
|
|
54
53
|
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
|
|
55
54
|
static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
|
|
56
55
|
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
57
56
|
private static getItemCount;
|
|
58
57
|
}
|
|
59
|
-
export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
|
|
@@ -51,19 +51,14 @@ exports.HARD_CODED_TEXT = {
|
|
|
51
51
|
};
|
|
52
52
|
const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
|
|
53
53
|
const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
!!documentElement.propertyBindings &&
|
|
58
|
-
!!documentElement.propertyBindingsMetaData);
|
|
59
|
-
}
|
|
60
|
-
static takesValueFromContainer(bindingProperty) {
|
|
61
|
-
if (!bindingProperty) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
65
|
-
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
54
|
+
function isContainerBinding(bindingProperty) {
|
|
55
|
+
if (!bindingProperty) {
|
|
56
|
+
return false;
|
|
66
57
|
}
|
|
58
|
+
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
59
|
+
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
60
|
+
}
|
|
61
|
+
class DynamicTextUtil {
|
|
67
62
|
static getDynamicTextValue(dynamicTextElement, property, propertyLevel, container, componentModels, ownerReferenceModel = null) {
|
|
68
63
|
var _a, _b, _c, _d;
|
|
69
64
|
if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
|
|
@@ -155,12 +150,12 @@ class DynamicTextUtil {
|
|
|
155
150
|
return text;
|
|
156
151
|
}
|
|
157
152
|
static calculateSize(dynamicTextElement, entityType, text) {
|
|
158
|
-
var _a, _b, _c, _d
|
|
159
|
-
let size =
|
|
160
|
-
const fontFamily = (
|
|
161
|
-
const fontSize = (
|
|
162
|
-
? (
|
|
163
|
-
: document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null &&
|
|
153
|
+
var _a, _b, _c, _d;
|
|
154
|
+
let size = dynamicTextElement.size;
|
|
155
|
+
const fontFamily = (_a = document_util_1.DocumentStyleUtil.getFirstFontFamily(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text)) !== null && _a !== void 0 ? _a : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
|
|
156
|
+
const fontSize = (_d = (dynamicTextElement.isTextTool
|
|
157
|
+
? (_c = (_b = dynamicTextElement.style) === null || _b === void 0 ? void 0 : _b.font) === null || _c === void 0 ? void 0 : _c.size
|
|
158
|
+
: document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _d !== void 0 ? _d : document_util_1.DEFAULT_TEXT_FONT_SIZE;
|
|
164
159
|
const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
|
|
165
160
|
const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
|
|
166
161
|
const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
|
|
@@ -174,7 +169,7 @@ class DynamicTextUtil {
|
|
|
174
169
|
italic,
|
|
175
170
|
};
|
|
176
171
|
if (!dynamicTextElement.isTextTool) {
|
|
177
|
-
measureTextSettings.width = size.width - padding * 2;
|
|
172
|
+
measureTextSettings.width = dynamicTextElement.size.width - padding * 2;
|
|
178
173
|
}
|
|
179
174
|
try {
|
|
180
175
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|
|
@@ -217,14 +212,13 @@ class DynamicTextUtil {
|
|
|
217
212
|
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
218
213
|
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
219
214
|
}
|
|
220
|
-
else if (displayFunction === DynamicTextDisplayFunction.MIN
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
text = formatter.formatValueForProperty(extreme, property);
|
|
215
|
+
else if (displayFunction === DynamicTextDisplayFunction.MIN) {
|
|
216
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
217
|
+
text = formatter.formatValueForProperty(Math.min(...memberValues), property);
|
|
218
|
+
}
|
|
219
|
+
else if (displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
220
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
221
|
+
text = formatter.formatValueForProperty(Math.max(...memberValues), property);
|
|
228
222
|
}
|
|
229
223
|
return text;
|
|
230
224
|
}
|
|
@@ -251,6 +245,3 @@ class DynamicTextUtil {
|
|
|
251
245
|
}
|
|
252
246
|
}
|
|
253
247
|
exports.DynamicTextUtil = DynamicTextUtil;
|
|
254
|
-
function isContainerBinding(bindingProperty) {
|
|
255
|
-
return DynamicTextUtil.takesValueFromContainer(bindingProperty);
|
|
256
|
-
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./mask-shape-geometry"), exports);
|
|
18
|
+
__exportStar(require("./rotation-math"), exports);
|
|
19
|
+
__exportStar(require("./shape-mask-element"), exports);
|
|
20
|
+
__exportStar(require("./mask-preset-geometry"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MASK_SHAPE_PRESET_GEOMETRY = void 0;
|
|
4
|
+
exports.getMaskPresetGeometry = getMaskPresetGeometry;
|
|
5
|
+
exports.MASK_SHAPE_PRESET_GEOMETRY = {
|
|
6
|
+
circle: 'ellipse',
|
|
7
|
+
square: 'rect',
|
|
8
|
+
rounded: 'roundRect',
|
|
9
|
+
triangle: 'triangle',
|
|
10
|
+
diamond: 'diamond',
|
|
11
|
+
parallelogram: 'parallelogram',
|
|
12
|
+
star: 'star5',
|
|
13
|
+
heart: 'heart',
|
|
14
|
+
cloud: 'cloud',
|
|
15
|
+
};
|
|
16
|
+
function getMaskPresetGeometry(shape) {
|
|
17
|
+
var _a;
|
|
18
|
+
return shape ? (_a = exports.MASK_SHAPE_PRESET_GEOMETRY[shape]) !== null && _a !== void 0 ? _a : null : null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MaskShapeKey } from '../../types';
|
|
2
|
+
export { MaskShapeKey };
|
|
3
|
+
export declare const MASK_SHAPE_KEYS: readonly MaskShapeKey[];
|
|
4
|
+
export interface MaskRect {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
export type PathSegment = {
|
|
11
|
+
op: 'move' | 'line';
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
} | {
|
|
15
|
+
op: 'cubic';
|
|
16
|
+
c1x: number;
|
|
17
|
+
c1y: number;
|
|
18
|
+
c2x: number;
|
|
19
|
+
c2y: number;
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
} | {
|
|
23
|
+
op: 'close';
|
|
24
|
+
};
|
|
25
|
+
export declare function getMaskShapeSegments(shape: MaskShapeKey, rect: MaskRect, rotationDeg?: number): PathSegment[];
|
|
26
|
+
export declare function rotatedRectAABB(rect: MaskRect, rotationDeg: number): MaskRect;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MASK_SHAPE_KEYS = void 0;
|
|
4
|
+
exports.getMaskShapeSegments = getMaskShapeSegments;
|
|
5
|
+
exports.rotatedRectAABB = rotatedRectAABB;
|
|
6
|
+
const rotation_math_1 = require("./rotation-math");
|
|
7
|
+
exports.MASK_SHAPE_KEYS = [
|
|
8
|
+
'circle',
|
|
9
|
+
'square',
|
|
10
|
+
'rounded',
|
|
11
|
+
'triangle',
|
|
12
|
+
'diamond',
|
|
13
|
+
'parallelogram',
|
|
14
|
+
'star',
|
|
15
|
+
'heart',
|
|
16
|
+
'cloud',
|
|
17
|
+
];
|
|
18
|
+
const K = 0.5522847498;
|
|
19
|
+
function polygon(points) {
|
|
20
|
+
const [first, ...rest] = points;
|
|
21
|
+
return [
|
|
22
|
+
{ op: 'move', x: first[0], y: first[1] },
|
|
23
|
+
...rest.map(([x, y]) => ({ op: 'line', x, y })),
|
|
24
|
+
{ op: 'close' },
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function ellipse(cx, cy, rx, ry) {
|
|
28
|
+
return [
|
|
29
|
+
{ op: 'move', x: cx + rx, y: cy },
|
|
30
|
+
{ op: 'cubic', c1x: cx + rx, c1y: cy + K * ry, c2x: cx + K * rx, c2y: cy + ry, x: cx, y: cy + ry },
|
|
31
|
+
{ op: 'cubic', c1x: cx - K * rx, c1y: cy + ry, c2x: cx - rx, c2y: cy + K * ry, x: cx - rx, y: cy },
|
|
32
|
+
{ op: 'cubic', c1x: cx - rx, c1y: cy - K * ry, c2x: cx - K * rx, c2y: cy - ry, x: cx, y: cy - ry },
|
|
33
|
+
{ op: 'cubic', c1x: cx + K * rx, c1y: cy - ry, c2x: cx + rx, c2y: cy - K * ry, x: cx + rx, y: cy },
|
|
34
|
+
{ op: 'close' },
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function roundedRect(x, y, w, h, r) {
|
|
38
|
+
const x2 = x + w;
|
|
39
|
+
const y2 = y + h;
|
|
40
|
+
return [
|
|
41
|
+
{ op: 'move', x: x + r, y },
|
|
42
|
+
{ op: 'line', x: x2 - r, y },
|
|
43
|
+
{ op: 'cubic', c1x: x2 - r + K * r, c1y: y, c2x: x2, c2y: y + r - K * r, x: x2, y: y + r },
|
|
44
|
+
{ op: 'line', x: x2, y: y2 - r },
|
|
45
|
+
{ op: 'cubic', c1x: x2, c1y: y2 - r + K * r, c2x: x2 - r + K * r, c2y: y2, x: x2 - r, y: y2 },
|
|
46
|
+
{ op: 'line', x: x + r, y: y2 },
|
|
47
|
+
{ op: 'cubic', c1x: x + r - K * r, c1y: y2, c2x: x, c2y: y2 - r + K * r, x, y: y2 - r },
|
|
48
|
+
{ op: 'line', x, y: y + r },
|
|
49
|
+
{ op: 'cubic', c1x: x, c1y: y + r - K * r, c2x: x + r - K * r, c2y: y, x: x + r, y },
|
|
50
|
+
{ op: 'close' },
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
const UNIT_SEGMENTS = {
|
|
54
|
+
circle: ellipse(50, 50, 49, 49),
|
|
55
|
+
square: polygon([
|
|
56
|
+
[1, 1],
|
|
57
|
+
[99, 1],
|
|
58
|
+
[99, 99],
|
|
59
|
+
[1, 99],
|
|
60
|
+
]),
|
|
61
|
+
rounded: roundedRect(1, 1, 98, 98, 16),
|
|
62
|
+
triangle: polygon([
|
|
63
|
+
[50, 3],
|
|
64
|
+
[97, 96],
|
|
65
|
+
[3, 96],
|
|
66
|
+
]),
|
|
67
|
+
diamond: polygon([
|
|
68
|
+
[50, 2],
|
|
69
|
+
[98, 50],
|
|
70
|
+
[50, 98],
|
|
71
|
+
[2, 50],
|
|
72
|
+
]),
|
|
73
|
+
parallelogram: polygon([
|
|
74
|
+
[27, 12],
|
|
75
|
+
[98, 12],
|
|
76
|
+
[73, 88],
|
|
77
|
+
[2, 88],
|
|
78
|
+
]),
|
|
79
|
+
star: polygon([
|
|
80
|
+
[50, 3],
|
|
81
|
+
[61, 37],
|
|
82
|
+
[97, 37],
|
|
83
|
+
[68, 59],
|
|
84
|
+
[79, 95],
|
|
85
|
+
[50, 73],
|
|
86
|
+
[21, 95],
|
|
87
|
+
[32, 59],
|
|
88
|
+
[3, 37],
|
|
89
|
+
[39, 37],
|
|
90
|
+
]),
|
|
91
|
+
heart: [
|
|
92
|
+
{ op: 'move', x: 50, y: 90 },
|
|
93
|
+
{ op: 'cubic', c1x: 6, c1y: 58, c2x: 10, c2y: 20, x: 32, y: 18 },
|
|
94
|
+
{ op: 'cubic', c1x: 44, c1y: 17, c2x: 50, c2y: 27, x: 50, y: 34 },
|
|
95
|
+
{ op: 'cubic', c1x: 50, c1y: 27, c2x: 56, c2y: 17, x: 68, y: 18 },
|
|
96
|
+
{ op: 'cubic', c1x: 90, c1y: 20, c2x: 94, c2y: 58, x: 50, y: 90 },
|
|
97
|
+
{ op: 'close' },
|
|
98
|
+
],
|
|
99
|
+
cloud: [
|
|
100
|
+
{ op: 'move', x: 30, y: 80 },
|
|
101
|
+
{ op: 'cubic', c1x: 13, c1y: 80, c2x: 6, c2y: 66, x: 16, y: 56 },
|
|
102
|
+
{ op: 'cubic', c1x: 11, c1y: 42, c2x: 27, c2y: 34, x: 37, y: 42 },
|
|
103
|
+
{ op: 'cubic', c1x: 41, c1y: 24, c2x: 66, c2y: 24, x: 70, y: 42 },
|
|
104
|
+
{ op: 'cubic', c1x: 86, c1y: 38, c2x: 96, c2y: 56, x: 84, y: 68 },
|
|
105
|
+
{ op: 'cubic', c1x: 92, c1y: 78, c2x: 82, c2y: 88, x: 70, y: 84 },
|
|
106
|
+
{ op: 'close' },
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
function getMaskShapeSegments(shape, rect, rotationDeg = 0) {
|
|
110
|
+
const unit = UNIT_SEGMENTS[shape];
|
|
111
|
+
if (!unit) {
|
|
112
|
+
throw new Error(`Unknown mask shape: ${shape}`);
|
|
113
|
+
}
|
|
114
|
+
const sx = rect.width / 100;
|
|
115
|
+
const sy = rect.height / 100;
|
|
116
|
+
const tx = (x) => rect.x + x * sx;
|
|
117
|
+
const ty = (y) => rect.y + y * sy;
|
|
118
|
+
const cx = rect.x + rect.width * 0.5;
|
|
119
|
+
const cy = rect.y + rect.height * 0.5;
|
|
120
|
+
const rotate = (x, y) => rotationDeg ? (0, rotation_math_1.rotatePoint)({ x, y }, rotationDeg, { x: cx, y: cy }) : { x, y };
|
|
121
|
+
return unit.map((s) => {
|
|
122
|
+
if (s.op === 'close') {
|
|
123
|
+
return { op: 'close' };
|
|
124
|
+
}
|
|
125
|
+
if (s.op === 'cubic') {
|
|
126
|
+
const c1 = rotate(tx(s.c1x), ty(s.c1y));
|
|
127
|
+
const c2 = rotate(tx(s.c2x), ty(s.c2y));
|
|
128
|
+
const p = rotate(tx(s.x), ty(s.y));
|
|
129
|
+
return { op: 'cubic', c1x: c1.x, c1y: c1.y, c2x: c2.x, c2y: c2.y, x: p.x, y: p.y };
|
|
130
|
+
}
|
|
131
|
+
const p = rotate(tx(s.x), ty(s.y));
|
|
132
|
+
return { op: s.op, x: p.x, y: p.y };
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function rotatedRectAABB(rect, rotationDeg) {
|
|
136
|
+
if (!rotationDeg) {
|
|
137
|
+
return Object.assign({}, rect);
|
|
138
|
+
}
|
|
139
|
+
const cx = rect.x + rect.width * 0.5;
|
|
140
|
+
const cy = rect.y + rect.height * 0.5;
|
|
141
|
+
const corners = [
|
|
142
|
+
{ x: rect.x, y: rect.y },
|
|
143
|
+
{ x: rect.x + rect.width, y: rect.y },
|
|
144
|
+
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
|
145
|
+
{ x: rect.x, y: rect.y + rect.height },
|
|
146
|
+
].map(p => (0, rotation_math_1.rotatePoint)(p, rotationDeg, { x: cx, y: cy }));
|
|
147
|
+
const xs = corners.map(p => p.x);
|
|
148
|
+
const ys = corners.map(p => p.y);
|
|
149
|
+
const minX = Math.min(...xs);
|
|
150
|
+
const maxX = Math.max(...xs);
|
|
151
|
+
const minY = Math.min(...ys);
|
|
152
|
+
const maxY = Math.max(...ys);
|
|
153
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
154
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rotatePoint = rotatePoint;
|
|
4
|
+
function rotatePoint(point, angleDeg, pivot = { x: 0, y: 0 }) {
|
|
5
|
+
const theta = (angleDeg * Math.PI) / 180;
|
|
6
|
+
const cos = Math.cos(theta);
|
|
7
|
+
const sin = Math.sin(theta);
|
|
8
|
+
const dx = point.x - pivot.x;
|
|
9
|
+
const dy = point.y - pivot.y;
|
|
10
|
+
return {
|
|
11
|
+
x: dx * cos - dy * sin + pivot.x,
|
|
12
|
+
y: dx * sin + dy * cos + pivot.y,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CropDefinition, DocumentElement, SizeDefinition } from '../../types';
|
|
2
|
+
import { MaskRect, MaskShapeKey } from './mask-shape-geometry';
|
|
3
|
+
export declare function hasShapeMask(element: DocumentElement): boolean;
|
|
4
|
+
export declare function getShapeMaskKey(element: DocumentElement): MaskShapeKey | null;
|
|
5
|
+
export declare function getShapeMaskRotation(element: DocumentElement): number;
|
|
6
|
+
export declare function normalizeMaskRotation(rotation: number): number;
|
|
7
|
+
export declare function isShapeMaskable(element: DocumentElement): boolean;
|
|
8
|
+
export declare function getDefaultShapeMaskCrop(size: SizeDefinition): CropDefinition;
|
|
9
|
+
export declare function cropDefinitionToMaskRect(crop: CropDefinition, size: SizeDefinition): MaskRect;
|
|
10
|
+
export declare function maskRectToCropDefinition(rect: MaskRect, size: SizeDefinition): CropDefinition;
|
|
11
|
+
export declare const SHAPE_MASK_CLEAR_FIELDS: {
|
|
12
|
+
readonly maskDefinition: any;
|
|
13
|
+
readonly cropDefinition: any;
|
|
14
|
+
readonly imageSize: any;
|
|
15
|
+
readonly imagePosition: any;
|
|
16
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHAPE_MASK_CLEAR_FIELDS = void 0;
|
|
4
|
+
exports.hasShapeMask = hasShapeMask;
|
|
5
|
+
exports.getShapeMaskKey = getShapeMaskKey;
|
|
6
|
+
exports.getShapeMaskRotation = getShapeMaskRotation;
|
|
7
|
+
exports.normalizeMaskRotation = normalizeMaskRotation;
|
|
8
|
+
exports.isShapeMaskable = isShapeMaskable;
|
|
9
|
+
exports.getDefaultShapeMaskCrop = getDefaultShapeMaskCrop;
|
|
10
|
+
exports.cropDefinitionToMaskRect = cropDefinitionToMaskRect;
|
|
11
|
+
exports.maskRectToCropDefinition = maskRectToCropDefinition;
|
|
12
|
+
const DEFAULT_MASK_FRACTION = 0.72;
|
|
13
|
+
function hasShapeMask(element) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
return (!!getShapeMaskKey(element) && !!((_a = element === null || element === void 0 ? void 0 : element.cropDefinition) === null || _a === void 0 ? void 0 : _a.widthPercent) && !!((_b = element === null || element === void 0 ? void 0 : element.cropDefinition) === null || _b === void 0 ? void 0 : _b.heightPercent));
|
|
16
|
+
}
|
|
17
|
+
function getShapeMaskKey(element) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return (_b = (_a = element === null || element === void 0 ? void 0 : element.maskDefinition) === null || _a === void 0 ? void 0 : _a.shape) !== null && _b !== void 0 ? _b : null;
|
|
20
|
+
}
|
|
21
|
+
function getShapeMaskRotation(element) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (_b = (_a = element === null || element === void 0 ? void 0 : element.maskDefinition) === null || _a === void 0 ? void 0 : _a.rotation) !== null && _b !== void 0 ? _b : 0;
|
|
24
|
+
}
|
|
25
|
+
function normalizeMaskRotation(rotation) {
|
|
26
|
+
return ((rotation % 360) + 360) % 360;
|
|
27
|
+
}
|
|
28
|
+
function isShapeMaskable(element) {
|
|
29
|
+
return (element === null || element === void 0 ? void 0 : element.type) === 'image';
|
|
30
|
+
}
|
|
31
|
+
function getDefaultShapeMaskCrop(size) {
|
|
32
|
+
const side = Math.min(size.width, size.height) * DEFAULT_MASK_FRACTION;
|
|
33
|
+
return {
|
|
34
|
+
x1Percent: ((size.width - side) * 0.5) / size.width,
|
|
35
|
+
y1Percent: ((size.height - side) * 0.5) / size.height,
|
|
36
|
+
widthPercent: side / size.width,
|
|
37
|
+
heightPercent: side / size.height,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function cropDefinitionToMaskRect(crop, size) {
|
|
41
|
+
return {
|
|
42
|
+
x: crop.x1Percent * size.width,
|
|
43
|
+
y: crop.y1Percent * size.height,
|
|
44
|
+
width: crop.widthPercent * size.width,
|
|
45
|
+
height: crop.heightPercent * size.height,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function maskRectToCropDefinition(rect, size) {
|
|
49
|
+
return {
|
|
50
|
+
x1Percent: rect.x / size.width,
|
|
51
|
+
y1Percent: rect.y / size.height,
|
|
52
|
+
widthPercent: rect.width / size.width,
|
|
53
|
+
heightPercent: rect.height / size.height,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.SHAPE_MASK_CLEAR_FIELDS = {
|
|
57
|
+
maskDefinition: null,
|
|
58
|
+
cropDefinition: null,
|
|
59
|
+
imageSize: null,
|
|
60
|
+
imagePosition: null,
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FRAME_ELEMENT_TYPE, SECTION_ELEMENT_TYPE } from '../document-element-constants';
|
|
2
|
-
export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_ELEMENT_TYPE;
|
|
3
|
-
export interface ContainerKind {
|
|
4
|
-
elementType: ContainerElementType;
|
|
5
|
-
nests: boolean;
|
|
6
|
-
layer: number;
|
|
7
|
-
}
|
|
8
|
-
export declare const SECTION_KIND: ContainerKind;
|
|
9
|
-
export declare const FRAME_KIND: ContainerKind;
|
|
10
|
-
export declare const CONTAINER_KINDS: ContainerKind[];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONTAINER_KINDS = exports.FRAME_KIND = exports.SECTION_KIND = void 0;
|
|
4
|
-
const document_element_constants_1 = require("../document-element-constants");
|
|
5
|
-
exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true, layer: 0 };
|
|
6
|
-
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false, layer: 1 };
|
|
7
|
-
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { DocumentElement, PositionDefinition } from '../types';
|
|
2
|
-
import { ContainerElementType } from './container-kind';
|
|
3
|
-
import { DocumentContainer } from './document-container';
|
|
4
|
-
export declare class DocumentContainerIndex {
|
|
5
|
-
private readonly data;
|
|
6
|
-
constructor(data: {
|
|
7
|
-
documentElementsById: Map<string, DocumentElement>;
|
|
8
|
-
containersById: Map<string, DocumentContainer>;
|
|
9
|
-
containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
|
|
10
|
-
memberIdsByContainerId: Map<string, string[]>;
|
|
11
|
-
containerIdsByElementType: Map<string, string[]>;
|
|
12
|
-
});
|
|
13
|
-
getContainer(containerId: string): DocumentContainer | null;
|
|
14
|
-
containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
|
|
15
|
-
containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
|
|
16
|
-
innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
|
|
17
|
-
memberIdsOf(containerId: string): readonly string[];
|
|
18
|
-
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
19
|
-
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
|
|
20
|
-
maxDepth(elementType: ContainerElementType): number;
|
|
21
|
-
private containersOfType;
|
|
22
|
-
private resolveAll;
|
|
23
|
-
private containerPath;
|
|
24
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentContainerIndex = void 0;
|
|
4
|
-
const document_container_1 = require("./document-container");
|
|
5
|
-
class DocumentContainerIndex {
|
|
6
|
-
constructor(data) {
|
|
7
|
-
this.data = data;
|
|
8
|
-
}
|
|
9
|
-
getContainer(containerId) {
|
|
10
|
-
var _a;
|
|
11
|
-
return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
|
|
12
|
-
}
|
|
13
|
-
containersOf(documentElementId, elementType) {
|
|
14
|
-
return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
|
|
15
|
-
}
|
|
16
|
-
containerIdsOf(documentElementId, elementType) {
|
|
17
|
-
return this.containerPath(documentElementId, elementType);
|
|
18
|
-
}
|
|
19
|
-
innermostContainerIdOf(documentElementId, elementType) {
|
|
20
|
-
const path = this.containerPath(documentElementId, elementType);
|
|
21
|
-
return path.length ? path[path.length - 1] : null;
|
|
22
|
-
}
|
|
23
|
-
memberIdsOf(containerId) {
|
|
24
|
-
var _a;
|
|
25
|
-
return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
|
|
26
|
-
}
|
|
27
|
-
memberDocumentElementsOf(containerId) {
|
|
28
|
-
const members = [];
|
|
29
|
-
for (const memberId of this.memberIdsOf(containerId)) {
|
|
30
|
-
const member = this.data.documentElementsById.get(memberId);
|
|
31
|
-
if (member) {
|
|
32
|
-
members.push(member);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return members;
|
|
36
|
-
}
|
|
37
|
-
containerPathAtPoint(point, elementType) {
|
|
38
|
-
const covering = this.containersOfType(elementType).filter((container) => (0, document_container_1.containsPoint)(container.box, point));
|
|
39
|
-
return (0, document_container_1.topmostPerDepth)(covering).map((container) => container.id);
|
|
40
|
-
}
|
|
41
|
-
maxDepth(elementType) {
|
|
42
|
-
return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
|
|
43
|
-
}
|
|
44
|
-
containersOfType(elementType) {
|
|
45
|
-
var _a;
|
|
46
|
-
return this.resolveAll((_a = this.data.containerIdsByElementType.get(elementType)) !== null && _a !== void 0 ? _a : []);
|
|
47
|
-
}
|
|
48
|
-
resolveAll(containerIds) {
|
|
49
|
-
const containers = [];
|
|
50
|
-
for (const containerId of containerIds) {
|
|
51
|
-
const container = this.data.containersById.get(containerId);
|
|
52
|
-
if (container) {
|
|
53
|
-
containers.push(container);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return containers;
|
|
57
|
-
}
|
|
58
|
-
containerPath(documentElementId, elementType) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.DocumentContainerIndex = DocumentContainerIndex;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CoordinateBox, DocumentElement, PositionDefinition } from '../types';
|
|
2
|
-
import { ContainerKind } from './container-kind';
|
|
3
|
-
export interface DocumentContainer {
|
|
4
|
-
id: string;
|
|
5
|
-
kind: ContainerKind;
|
|
6
|
-
name: string;
|
|
7
|
-
documentElement: DocumentElement;
|
|
8
|
-
box: CoordinateBox;
|
|
9
|
-
depth: number;
|
|
10
|
-
drawOrder: number;
|
|
11
|
-
}
|
|
12
|
-
export interface MeasuredDocumentElement {
|
|
13
|
-
documentElement: DocumentElement;
|
|
14
|
-
box: CoordinateBox | null;
|
|
15
|
-
drawOrder: number;
|
|
16
|
-
}
|
|
17
|
-
export declare function toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
|
|
18
|
-
export declare function centerOf(box: CoordinateBox): PositionDefinition;
|
|
19
|
-
export declare function anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
20
|
-
export declare function containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
21
|
-
export declare function encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
22
|
-
export declare function isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
|
|
23
|
-
export declare function topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCoordinateBox = toCoordinateBox;
|
|
4
|
-
exports.centerOf = centerOf;
|
|
5
|
-
exports.anchorOf = anchorOf;
|
|
6
|
-
exports.containsPoint = containsPoint;
|
|
7
|
-
exports.encloses = encloses;
|
|
8
|
-
exports.isWiderAndTallerThan = isWiderAndTallerThan;
|
|
9
|
-
exports.topmostPerDepth = topmostPerDepth;
|
|
10
|
-
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
11
|
-
function toCoordinateBox(x, y, width, height) {
|
|
12
|
-
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
13
|
-
}
|
|
14
|
-
function centerOf(box) {
|
|
15
|
-
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
16
|
-
}
|
|
17
|
-
function anchorOf(documentElement, box) {
|
|
18
|
-
return dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement) ? { x: box.left, y: box.top } : centerOf(box);
|
|
19
|
-
}
|
|
20
|
-
function containsPoint(box, point) {
|
|
21
|
-
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
22
|
-
}
|
|
23
|
-
function encloses(outer, inner) {
|
|
24
|
-
const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
|
|
25
|
-
const identical = outer.left === inner.left &&
|
|
26
|
-
outer.right === inner.right &&
|
|
27
|
-
outer.top === inner.top &&
|
|
28
|
-
outer.bottom === inner.bottom;
|
|
29
|
-
return covers && !identical;
|
|
30
|
-
}
|
|
31
|
-
function isWiderAndTallerThan(box, other) {
|
|
32
|
-
return box.width > other.width && box.height > other.height;
|
|
33
|
-
}
|
|
34
|
-
function topmostPerDepth(containers) {
|
|
35
|
-
const byDepth = [];
|
|
36
|
-
for (const container of containers) {
|
|
37
|
-
const existing = byDepth[container.depth];
|
|
38
|
-
if (!existing || container.drawOrder > existing.drawOrder) {
|
|
39
|
-
byDepth[container.depth] = container;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return byDepth.filter(Boolean);
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DocumentElement } from '../types';
|
|
2
|
-
import { ContainerKind } from './container-kind';
|
|
3
|
-
import { DocumentContainerIndex } from './document-container-index';
|
|
4
|
-
export declare class DocumentContainerService {
|
|
5
|
-
static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
|
|
6
|
-
static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
|
|
7
|
-
private static measureDocumentElements;
|
|
8
|
-
private static measure;
|
|
9
|
-
private static buildNesting;
|
|
10
|
-
private static resolveContainerPath;
|
|
11
|
-
private static resolveInnermostOnTop;
|
|
12
|
-
private static toContainerPath;
|
|
13
|
-
private static candidateContainers;
|
|
14
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentContainerService = void 0;
|
|
4
|
-
const document_element_factory_1 = require("../document-element-factory");
|
|
5
|
-
const document_element_constants_1 = require("../document-element-constants");
|
|
6
|
-
const container_kind_1 = require("./container-kind");
|
|
7
|
-
const document_container_index_1 = require("./document-container-index");
|
|
8
|
-
const document_container_1 = require("./document-container");
|
|
9
|
-
class DocumentContainerService {
|
|
10
|
-
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
11
|
-
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
|
|
12
|
-
const nestingByElementType = new Map(kinds.map((kind) => [kind.elementType, this.buildNesting(measuredDocumentElements, kind)]));
|
|
13
|
-
const containersById = new Map();
|
|
14
|
-
const containerIdsByElementType = new Map();
|
|
15
|
-
nestingByElementType.forEach((nesting, elementType) => {
|
|
16
|
-
containerIdsByElementType.set(elementType, nesting.containers.map((container) => container.id));
|
|
17
|
-
nesting.containers.forEach((container) => containersById.set(container.id, container));
|
|
18
|
-
});
|
|
19
|
-
const containerPathsByDocumentElementId = new Map();
|
|
20
|
-
const memberIdsByContainerId = new Map();
|
|
21
|
-
for (const measured of measuredDocumentElements) {
|
|
22
|
-
const documentElementId = measured.documentElement.id;
|
|
23
|
-
const pathsByElementType = new Map();
|
|
24
|
-
for (const kind of kinds) {
|
|
25
|
-
const path = this.resolveContainerPath(measured, kind, kinds, nestingByElementType.get(kind.elementType));
|
|
26
|
-
pathsByElementType.set(kind.elementType, path);
|
|
27
|
-
for (const containerId of path) {
|
|
28
|
-
const members = memberIdsByContainerId.get(containerId);
|
|
29
|
-
if (members) {
|
|
30
|
-
members.push(documentElementId);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
memberIdsByContainerId.set(containerId, [documentElementId]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
38
|
-
}
|
|
39
|
-
return new document_container_index_1.DocumentContainerIndex({
|
|
40
|
-
documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
|
|
41
|
-
containersById,
|
|
42
|
-
containerPathsByDocumentElementId,
|
|
43
|
-
memberIdsByContainerId,
|
|
44
|
-
containerIdsByElementType,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
48
|
-
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
49
|
-
}
|
|
50
|
-
static measureDocumentElements(documentElements) {
|
|
51
|
-
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
52
|
-
return documentElements.map((documentElement, drawOrder) => ({
|
|
53
|
-
documentElement,
|
|
54
|
-
drawOrder,
|
|
55
|
-
box: this.measure(documentElement, documentElementsById),
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
static measure(documentElement, documentElementsById) {
|
|
59
|
-
var _a, _b, _c, _d, _e, _f;
|
|
60
|
-
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
65
|
-
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
66
|
-
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRect(documentElement, start, end);
|
|
67
|
-
const scaleX = (_d = (_c = documentElement.scale) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 1;
|
|
68
|
-
const scaleY = (_f = (_e = documentElement.scale) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 1;
|
|
69
|
-
return (0, document_container_1.toCoordinateBox)(x, y, width * scaleX, height * scaleY);
|
|
70
|
-
}
|
|
71
|
-
catch (_g) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
static buildNesting(measuredDocumentElements, kind) {
|
|
76
|
-
const containers = measuredDocumentElements
|
|
77
|
-
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
78
|
-
.map((measured) => ({
|
|
79
|
-
id: measured.documentElement.id,
|
|
80
|
-
kind,
|
|
81
|
-
name: measured.documentElement.name,
|
|
82
|
-
documentElement: measured.documentElement,
|
|
83
|
-
box: measured.box,
|
|
84
|
-
depth: 0,
|
|
85
|
-
drawOrder: measured.drawOrder,
|
|
86
|
-
}));
|
|
87
|
-
const ancestorsById = new Map();
|
|
88
|
-
for (const container of containers) {
|
|
89
|
-
const ancestors = kind.nests
|
|
90
|
-
? containers.filter((other) => other !== container && (0, document_container_1.encloses)(other.box, container.box))
|
|
91
|
-
: [];
|
|
92
|
-
ancestorsById.set(container.id, ancestors);
|
|
93
|
-
container.depth = ancestors.length;
|
|
94
|
-
}
|
|
95
|
-
return { containers, ancestorsById };
|
|
96
|
-
}
|
|
97
|
-
static resolveContainerPath(measured, kind, kinds, nesting) {
|
|
98
|
-
var _a, _b;
|
|
99
|
-
if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
|
|
103
|
-
if (ownKind) {
|
|
104
|
-
if (ownKind.elementType === kind.elementType) {
|
|
105
|
-
return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
|
|
106
|
-
}
|
|
107
|
-
if (kind.layer > ownKind.layer) {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const candidates = this.candidateContainers(measured, nesting.containers);
|
|
112
|
-
if (!candidates.length) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
|
|
116
|
-
const candidateIds = new Set(candidates.map((container) => container.id));
|
|
117
|
-
const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
|
|
118
|
-
return this.toContainerPath([...ancestors, innermostOnTop]);
|
|
119
|
-
}
|
|
120
|
-
static resolveInnermostOnTop(candidates, nesting) {
|
|
121
|
-
const enclosingIds = new Set(candidates.flatMap((container) => { var _a; return (_a = nesting.ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : []; }).map((ancestor) => ancestor.id));
|
|
122
|
-
return candidates
|
|
123
|
-
.filter((container) => !enclosingIds.has(container.id))
|
|
124
|
-
.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
125
|
-
}
|
|
126
|
-
static toContainerPath(containers) {
|
|
127
|
-
return (0, document_container_1.topmostPerDepth)(containers).map((container) => container.id);
|
|
128
|
-
}
|
|
129
|
-
static candidateContainers(measured, containers) {
|
|
130
|
-
const anchor = (0, document_container_1.anchorOf)(measured.documentElement, measured.box);
|
|
131
|
-
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type);
|
|
132
|
-
return containers.filter((container) => {
|
|
133
|
-
var _a;
|
|
134
|
-
if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
if (!(0, document_container_1.containsPoint)(container.box, anchor)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
if (isShape && (0, document_container_1.isWiderAndTallerThan)(measured.box, container.box)) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.DocumentContainerService = DocumentContainerService;
|