@contrail/documents 2.4.0-alpha.86639ad → 2.4.0-alpha.c01727c
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/lib/containers/document-container-index.js +2 -6
- package/lib/containers/document-container.d.ts +1 -2
- package/lib/containers/document-container.js +16 -21
- package/lib/containers/document-container.service.d.ts +3 -1
- package/lib/containers/document-container.service.js +48 -11
- package/lib/util/dynamic-text/dynamic-text-util.js +2 -3
- package/package.json +1 -1
|
@@ -35,12 +35,8 @@ class DocumentContainerIndex {
|
|
|
35
35
|
return members;
|
|
36
36
|
}
|
|
37
37
|
containerPathAtPoint(point, elementType) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const covering = containers.filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
|
|
41
|
-
const nests = (_b = (_a = containers[0]) === null || _a === void 0 ? void 0 : _a.kind.nests) !== null && _b !== void 0 ? _b : true;
|
|
42
|
-
const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
|
|
43
|
-
return path.map((container) => container.id);
|
|
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);
|
|
44
40
|
}
|
|
45
41
|
maxDepth(elementType) {
|
|
46
42
|
return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
|
|
@@ -23,6 +23,5 @@ export declare class DocumentContainerUtil {
|
|
|
23
23
|
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
24
24
|
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
25
25
|
static isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
|
|
26
|
-
static
|
|
27
|
-
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
26
|
+
static topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
|
|
28
27
|
}
|
|
@@ -39,12 +39,19 @@ class DocumentContainerUtil {
|
|
|
39
39
|
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
40
40
|
}
|
|
41
41
|
static anchorFor(documentElement, position, startElement, endElement) {
|
|
42
|
+
var _a, _b, _c, _d, _e;
|
|
42
43
|
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
43
44
|
if (!at) {
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
47
|
+
const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
|
|
48
|
+
let 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));
|
|
49
|
+
try {
|
|
50
|
+
const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
|
|
51
|
+
box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
|
|
52
|
+
}
|
|
53
|
+
catch (_f) {
|
|
54
|
+
}
|
|
48
55
|
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
49
56
|
}
|
|
50
57
|
static containsPoint(box, point) {
|
|
@@ -61,27 +68,15 @@ class DocumentContainerUtil {
|
|
|
61
68
|
static isWiderAndTallerThan(box, other) {
|
|
62
69
|
return box.width > other.width && box.height > other.height;
|
|
63
70
|
}
|
|
64
|
-
static
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
71
|
-
const path = [innermostOf(candidates)];
|
|
72
|
-
for (;;) {
|
|
73
|
-
const current = path[0];
|
|
74
|
-
const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
|
|
75
|
-
if (!enclosing.length) {
|
|
76
|
-
return path;
|
|
71
|
+
static topmostPerDepth(containers) {
|
|
72
|
+
const byDepth = [];
|
|
73
|
+
for (const container of containers) {
|
|
74
|
+
const existing = byDepth[container.depth];
|
|
75
|
+
if (!existing || container.drawOrder > existing.drawOrder) {
|
|
76
|
+
byDepth[container.depth] = container;
|
|
77
77
|
}
|
|
78
|
-
path.unshift(innermostOf(enclosing));
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
static topmost(containers) {
|
|
82
|
-
return containers.length
|
|
83
|
-
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
84
|
-
: [];
|
|
79
|
+
return byDepth.filter(Boolean);
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
82
|
exports.DocumentContainerUtil = DocumentContainerUtil;
|
|
@@ -4,10 +4,12 @@ import { DocumentContainerIndex } from './document-container-index';
|
|
|
4
4
|
export declare class DocumentContainerService {
|
|
5
5
|
static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
|
|
6
6
|
static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
|
|
7
|
+
private static inherit;
|
|
7
8
|
private static measureDocumentElements;
|
|
8
9
|
private static measure;
|
|
9
10
|
private static collectContainers;
|
|
10
|
-
private static
|
|
11
|
+
private static resolveDirectPath;
|
|
11
12
|
private static enclosersOf;
|
|
13
|
+
private static chain;
|
|
12
14
|
private static candidateContainers;
|
|
13
15
|
}
|
|
@@ -9,7 +9,7 @@ const document_container_index_1 = require("./document-container-index");
|
|
|
9
9
|
const document_container_1 = require("./document-container");
|
|
10
10
|
class DocumentContainerService {
|
|
11
11
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
12
|
-
var _a, _b, _c
|
|
12
|
+
var _a, _b, _c;
|
|
13
13
|
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
|
|
14
14
|
const kindsByLayer = [...kinds].sort((first, second) => second.layer - first.layer);
|
|
15
15
|
const containersByElementType = new Map(kindsByLayer.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
@@ -19,18 +19,18 @@ class DocumentContainerService {
|
|
|
19
19
|
containerIdsByElementType.set(elementType, containers.map((container) => container.id));
|
|
20
20
|
containers.forEach((container) => containersById.set(container.id, container));
|
|
21
21
|
});
|
|
22
|
-
const
|
|
22
|
+
const directPaths = new Map();
|
|
23
23
|
for (const measured of measuredDocumentElements) {
|
|
24
24
|
const byElementType = new Map();
|
|
25
25
|
for (const kind of kindsByLayer) {
|
|
26
|
-
byElementType.set(kind.elementType, this.
|
|
26
|
+
byElementType.set(kind.elementType, this.resolveDirectPath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
directPaths.set(measured, byElementType);
|
|
29
29
|
}
|
|
30
30
|
for (const measured of measuredDocumentElements) {
|
|
31
31
|
const container = containersById.get(measured.documentElement.id);
|
|
32
32
|
if (container && container.documentElement === measured.documentElement) {
|
|
33
|
-
container.depth = ((_c = (_b =
|
|
33
|
+
container.depth = ((_c = (_b = directPaths.get(measured)) === null || _b === void 0 ? void 0 : _b.get(container.kind.elementType)) !== null && _c !== void 0 ? _c : []).length;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
const measuredById = new Map();
|
|
@@ -43,8 +43,7 @@ class DocumentContainerService {
|
|
|
43
43
|
const memberIdsByContainerId = new Map();
|
|
44
44
|
for (const measured of measuredDocumentElements) {
|
|
45
45
|
const documentElementId = measured.documentElement.id;
|
|
46
|
-
const pathsByElementType = new
|
|
47
|
-
((_d = pathsByMeasured.get(measured)) !== null && _d !== void 0 ? _d : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
46
|
+
const pathsByElementType = this.inherit(measured, kindsByLayer, directPaths, measuredById, new Set());
|
|
48
47
|
for (const path of pathsByElementType.values()) {
|
|
49
48
|
for (const containerId of path) {
|
|
50
49
|
const members = memberIdsByContainerId.get(containerId);
|
|
@@ -69,6 +68,28 @@ class DocumentContainerService {
|
|
|
69
68
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
70
69
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
71
70
|
}
|
|
71
|
+
static inherit(measured, kindsByLayer, directPaths, measuredById, resolving) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
const direct = (_a = directPaths.get(measured)) !== null && _a !== void 0 ? _a : new Map();
|
|
74
|
+
const paths = new Map();
|
|
75
|
+
let inheritFromId = null;
|
|
76
|
+
for (const kind of kindsByLayer) {
|
|
77
|
+
if (inheritFromId && !resolving.has(inheritFromId)) {
|
|
78
|
+
const container = measuredById.get(inheritFromId);
|
|
79
|
+
const inherited = container
|
|
80
|
+
? this.inherit(container, kindsByLayer, directPaths, measuredById, new Set(resolving).add(inheritFromId))
|
|
81
|
+
: null;
|
|
82
|
+
paths.set(kind.elementType, (_b = inherited === null || inherited === void 0 ? void 0 : inherited.get(kind.elementType)) !== null && _b !== void 0 ? _b : []);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const path = (_c = direct.get(kind.elementType)) !== null && _c !== void 0 ? _c : [];
|
|
86
|
+
paths.set(kind.elementType, path.map((container) => container.id));
|
|
87
|
+
if (path.length) {
|
|
88
|
+
inheritFromId = path[path.length - 1].id;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return paths;
|
|
92
|
+
}
|
|
72
93
|
static measureDocumentElements(documentElements) {
|
|
73
94
|
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
74
95
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
@@ -105,21 +126,20 @@ class DocumentContainerService {
|
|
|
105
126
|
drawOrder: measured.drawOrder,
|
|
106
127
|
}));
|
|
107
128
|
}
|
|
108
|
-
static
|
|
129
|
+
static resolveDirectPath(measured, kind, containers) {
|
|
109
130
|
if (!containers.length || !measured.box) {
|
|
110
131
|
return [];
|
|
111
132
|
}
|
|
112
133
|
const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
|
|
113
134
|
if (ownKind) {
|
|
114
135
|
if (ownKind.elementType === kind.elementType) {
|
|
115
|
-
return kind.nests ?
|
|
136
|
+
return kind.nests ? this.chain(this.enclosersOf(measured, containers)) : [];
|
|
116
137
|
}
|
|
117
138
|
if (kind.layer > ownKind.layer) {
|
|
118
139
|
return [];
|
|
119
140
|
}
|
|
120
141
|
}
|
|
121
|
-
|
|
122
|
-
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
142
|
+
return this.chain(this.candidateContainers(measured, containers));
|
|
123
143
|
}
|
|
124
144
|
static enclosersOf(measured, containers) {
|
|
125
145
|
return containers.filter((container) => {
|
|
@@ -130,6 +150,23 @@ class DocumentContainerService {
|
|
|
130
150
|
!((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
131
151
|
});
|
|
132
152
|
}
|
|
153
|
+
static chain(candidates) {
|
|
154
|
+
if (!candidates.length) {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
const innermostOf = (of) => of
|
|
158
|
+
.filter((container) => !of.some((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(container.box, other.box)))
|
|
159
|
+
.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
160
|
+
const path = [innermostOf(candidates)];
|
|
161
|
+
for (;;) {
|
|
162
|
+
const current = path[0];
|
|
163
|
+
const enclosing = candidates.filter((container) => !path.includes(container) && document_container_1.DocumentContainerUtil.encloses(container.box, current.box));
|
|
164
|
+
if (!enclosing.length) {
|
|
165
|
+
return path;
|
|
166
|
+
}
|
|
167
|
+
path.unshift(innermostOf(enclosing));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
133
170
|
static candidateContainers(measured, containers) {
|
|
134
171
|
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
135
172
|
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
|
|
@@ -56,9 +56,8 @@ function isContainerBinding(bindingProperty) {
|
|
|
56
56
|
}
|
|
57
57
|
class DynamicTextUtil {
|
|
58
58
|
static isDynamicText(documentElement) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
!!documentElement.propertyBindingsMetaData);
|
|
59
|
+
var _a;
|
|
60
|
+
return (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' && !!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text);
|
|
62
61
|
}
|
|
63
62
|
static takesValueFromContainer(bindingProperty) {
|
|
64
63
|
if (!bindingProperty) {
|