@contrail/documents 1.20.0-alpha.5ed9686 → 1.20.0-alpha.8d925dc
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.
|
@@ -35,8 +35,8 @@ class DocumentContainerIndex {
|
|
|
35
35
|
return members;
|
|
36
36
|
}
|
|
37
37
|
containerPathAtPoint(point, elementType) {
|
|
38
|
-
const covering = this.containersOfType(elementType).filter((container) =>
|
|
39
|
-
return
|
|
38
|
+
const covering = this.containersOfType(elementType).filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
|
|
39
|
+
return document_container_1.DocumentContainerUtil.topmostPerDepth(covering).map((container) => container.id);
|
|
40
40
|
}
|
|
41
41
|
maxDepth(elementType) {
|
|
42
42
|
return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
|
|
@@ -14,11 +14,14 @@ export interface MeasuredDocumentElement {
|
|
|
14
14
|
box: CoordinateBox | null;
|
|
15
15
|
drawOrder: number;
|
|
16
16
|
}
|
|
17
|
-
export declare
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export declare class DocumentContainerUtil {
|
|
18
|
+
static toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
|
|
19
|
+
static centerOf(box: CoordinateBox): PositionDefinition;
|
|
20
|
+
static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
21
|
+
static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
|
|
22
|
+
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition): PositionDefinition;
|
|
23
|
+
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
24
|
+
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
25
|
+
static isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
|
|
26
|
+
static topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
|
|
27
|
+
}
|
|
@@ -1,69 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.centerOf = centerOf;
|
|
5
|
-
exports.anchorOf = anchorOf;
|
|
6
|
-
exports.positionKeepingAnchor = positionKeepingAnchor;
|
|
7
|
-
exports.containsPoint = containsPoint;
|
|
8
|
-
exports.encloses = encloses;
|
|
9
|
-
exports.isWiderAndTallerThan = isWiderAndTallerThan;
|
|
10
|
-
exports.topmostPerDepth = topmostPerDepth;
|
|
3
|
+
exports.DocumentContainerUtil = void 0;
|
|
11
4
|
const rotation_math_1 = require("../util/mask/rotation-math");
|
|
12
5
|
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function centerOf(box) {
|
|
17
|
-
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
18
|
-
}
|
|
19
|
-
function anchorOf(documentElement, box) {
|
|
20
|
-
var _a;
|
|
21
|
-
if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
|
|
22
|
-
return centerOf(box);
|
|
6
|
+
class DocumentContainerUtil {
|
|
7
|
+
static toCoordinateBox(x, y, width, height) {
|
|
8
|
+
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
23
9
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, centerOf(box)) : corner;
|
|
27
|
-
}
|
|
28
|
-
function positionKeepingAnchor(documentElement, newSize) {
|
|
29
|
-
var _a, _b, _c, _d, _e;
|
|
30
|
-
const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
31
|
-
const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
32
|
-
if (!position || !angle || !newSize || !documentElement.size) {
|
|
33
|
-
return position;
|
|
10
|
+
static centerOf(box) {
|
|
11
|
+
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
34
12
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
13
|
+
static anchorOf(documentElement, box) {
|
|
14
|
+
var _a;
|
|
15
|
+
if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
|
|
16
|
+
return DocumentContainerUtil.centerOf(box);
|
|
17
|
+
}
|
|
18
|
+
const angle = (_a = documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
19
|
+
const corner = { x: box.left, y: box.top };
|
|
20
|
+
return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, DocumentContainerUtil.centerOf(box)) : corner;
|
|
21
|
+
}
|
|
22
|
+
static positionKeepingAnchor(documentElement, newSize) {
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
24
|
+
const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
25
|
+
const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
26
|
+
if (!position || !angle || !newSize || !documentElement.size) {
|
|
27
|
+
return position;
|
|
28
|
+
}
|
|
29
|
+
const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
|
|
30
|
+
const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
|
|
31
|
+
const cornerOffset = (size) => {
|
|
32
|
+
const half = { x: (size.width * scaleX) / 2, y: (size.height * scaleY) / 2 };
|
|
33
|
+
const turned = (0, rotation_math_1.rotatePoint)(half, angle);
|
|
34
|
+
return { x: half.x - turned.x, y: half.y - turned.y };
|
|
35
|
+
};
|
|
36
|
+
const before = cornerOffset(documentElement.size);
|
|
37
|
+
const after = cornerOffset(newSize);
|
|
38
|
+
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
39
|
+
}
|
|
40
|
+
static anchorFor(documentElement, position) {
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
43
|
+
if (!at) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
|
|
47
|
+
const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, size.width * ((_c = (_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1), size.height * ((_e = (_d = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1));
|
|
48
|
+
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
49
|
+
}
|
|
50
|
+
static containsPoint(box, point) {
|
|
51
|
+
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
52
|
+
}
|
|
53
|
+
static encloses(outer, inner) {
|
|
54
|
+
const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
|
|
55
|
+
const identical = outer.left === inner.left &&
|
|
56
|
+
outer.right === inner.right &&
|
|
57
|
+
outer.top === inner.top &&
|
|
58
|
+
outer.bottom === inner.bottom;
|
|
59
|
+
return covers && !identical;
|
|
60
|
+
}
|
|
61
|
+
static isWiderAndTallerThan(box, other) {
|
|
62
|
+
return box.width > other.width && box.height > other.height;
|
|
63
|
+
}
|
|
64
|
+
static topmostPerDepth(containers) {
|
|
65
|
+
const byDepth = [];
|
|
66
|
+
for (const container of containers) {
|
|
67
|
+
const existing = byDepth[container.depth];
|
|
68
|
+
if (!existing || container.drawOrder > existing.drawOrder) {
|
|
69
|
+
byDepth[container.depth] = container;
|
|
70
|
+
}
|
|
66
71
|
}
|
|
72
|
+
return byDepth.filter(Boolean);
|
|
67
73
|
}
|
|
68
|
-
return byDepth.filter(Boolean);
|
|
69
74
|
}
|
|
75
|
+
exports.DocumentContainerUtil = DocumentContainerUtil;
|
|
@@ -65,7 +65,7 @@ class DocumentContainerService {
|
|
|
65
65
|
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
66
66
|
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
67
67
|
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
|
|
68
|
-
return
|
|
68
|
+
return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
|
|
69
69
|
}
|
|
70
70
|
catch (_c) {
|
|
71
71
|
return null;
|
|
@@ -86,7 +86,7 @@ class DocumentContainerService {
|
|
|
86
86
|
const ancestorsById = new Map();
|
|
87
87
|
for (const container of containers) {
|
|
88
88
|
const ancestors = kind.nests
|
|
89
|
-
? containers.filter((other) => other !== container &&
|
|
89
|
+
? containers.filter((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(other.box, container.box))
|
|
90
90
|
: [];
|
|
91
91
|
ancestorsById.set(container.id, ancestors);
|
|
92
92
|
container.depth = ancestors.length;
|
|
@@ -123,10 +123,10 @@ class DocumentContainerService {
|
|
|
123
123
|
.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
124
124
|
}
|
|
125
125
|
static toContainerPath(containers) {
|
|
126
|
-
return
|
|
126
|
+
return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
|
|
127
127
|
}
|
|
128
128
|
static candidateContainers(measured, containers) {
|
|
129
|
-
const anchor =
|
|
129
|
+
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
130
130
|
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
|
|
131
131
|
!dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
|
|
132
132
|
return containers.filter((container) => {
|
|
@@ -134,10 +134,10 @@ class DocumentContainerService {
|
|
|
134
134
|
if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
|
|
135
135
|
return false;
|
|
136
136
|
}
|
|
137
|
-
if (!
|
|
137
|
+
if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
|
-
if (isShape &&
|
|
140
|
+
if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|