@contrail/documents 2.4.0-alpha.c01727c → 2.4.0-alpha.cb23d8e
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/container-kind.d.ts +0 -1
- package/lib/containers/container-kind.js +2 -2
- package/lib/containers/document-container-index.d.ts +1 -1
- package/lib/containers/document-container-index.js +15 -5
- package/lib/containers/document-container.d.ts +2 -4
- package/lib/containers/document-container.js +19 -19
- package/lib/containers/document-container.service.d.ts +1 -3
- package/lib/containers/document-container.service.js +23 -80
- package/lib/util/dynamic-text/dynamic-text-util.js +3 -2
- package/package.json +1 -1
|
@@ -3,7 +3,6 @@ export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_EL
|
|
|
3
3
|
export interface ContainerKind {
|
|
4
4
|
elementType: ContainerElementType;
|
|
5
5
|
nests: boolean;
|
|
6
|
-
layer: number;
|
|
7
6
|
}
|
|
8
7
|
export declare const SECTION_KIND: ContainerKind;
|
|
9
8
|
export declare const FRAME_KIND: ContainerKind;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CONTAINER_KINDS = exports.FRAME_KIND = exports.SECTION_KIND = void 0;
|
|
4
4
|
const document_element_constants_1 = require("../document-element-constants");
|
|
5
|
-
exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true
|
|
6
|
-
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false
|
|
5
|
+
exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true };
|
|
6
|
+
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false };
|
|
7
7
|
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -10,6 +10,7 @@ export declare class DocumentContainerIndex {
|
|
|
10
10
|
memberIdsByContainerId: Map<string, string[]>;
|
|
11
11
|
containerIdsByElementType: Map<string, string[]>;
|
|
12
12
|
});
|
|
13
|
+
static empty(): DocumentContainerIndex;
|
|
13
14
|
getContainer(containerId: string): DocumentContainer | null;
|
|
14
15
|
containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
|
|
15
16
|
containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
|
|
@@ -17,7 +18,6 @@ export declare class DocumentContainerIndex {
|
|
|
17
18
|
memberIdsOf(containerId: string): readonly string[];
|
|
18
19
|
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
19
20
|
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
|
|
20
|
-
maxDepth(elementType: ContainerElementType): number;
|
|
21
21
|
private containersOfType;
|
|
22
22
|
private resolveAll;
|
|
23
23
|
private containerPath;
|
|
@@ -6,6 +6,15 @@ class DocumentContainerIndex {
|
|
|
6
6
|
constructor(data) {
|
|
7
7
|
this.data = data;
|
|
8
8
|
}
|
|
9
|
+
static empty() {
|
|
10
|
+
return new DocumentContainerIndex({
|
|
11
|
+
documentElementsById: new Map(),
|
|
12
|
+
containersById: new Map(),
|
|
13
|
+
containerPathsByDocumentElementId: new Map(),
|
|
14
|
+
memberIdsByContainerId: new Map(),
|
|
15
|
+
containerIdsByElementType: new Map(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
9
18
|
getContainer(containerId) {
|
|
10
19
|
var _a;
|
|
11
20
|
return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
|
|
@@ -35,11 +44,12 @@ class DocumentContainerIndex {
|
|
|
35
44
|
return members;
|
|
36
45
|
}
|
|
37
46
|
containerPathAtPoint(point, elementType) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const containers = this.containersOfType(elementType);
|
|
49
|
+
const covering = containers.filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
|
|
50
|
+
const nests = (_b = (_a = containers[0]) === null || _a === void 0 ? void 0 : _a.kind.nests) !== null && _b !== void 0 ? _b : true;
|
|
51
|
+
const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
|
|
52
|
+
return path.map((container) => container.id);
|
|
43
53
|
}
|
|
44
54
|
containersOfType(elementType) {
|
|
45
55
|
var _a;
|
|
@@ -3,10 +3,8 @@ import { ContainerKind } from './container-kind';
|
|
|
3
3
|
export interface DocumentContainer {
|
|
4
4
|
id: string;
|
|
5
5
|
kind: ContainerKind;
|
|
6
|
-
name: string;
|
|
7
6
|
documentElement: DocumentElement;
|
|
8
7
|
box: CoordinateBox;
|
|
9
|
-
depth: number;
|
|
10
8
|
drawOrder: number;
|
|
11
9
|
}
|
|
12
10
|
export interface MeasuredDocumentElement {
|
|
@@ -22,6 +20,6 @@ export declare class DocumentContainerUtil {
|
|
|
22
20
|
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
|
|
23
21
|
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
24
22
|
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
25
|
-
static
|
|
26
|
-
static
|
|
23
|
+
static chain(candidates: DocumentContainer[]): DocumentContainer[];
|
|
24
|
+
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
27
25
|
}
|
|
@@ -39,19 +39,12 @@ 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;
|
|
43
42
|
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
44
43
|
if (!at) {
|
|
45
44
|
return null;
|
|
46
45
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
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
|
-
}
|
|
46
|
+
const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
|
|
47
|
+
const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
|
|
55
48
|
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
56
49
|
}
|
|
57
50
|
static containsPoint(box, point) {
|
|
@@ -65,18 +58,25 @@ class DocumentContainerUtil {
|
|
|
65
58
|
outer.bottom === inner.bottom;
|
|
66
59
|
return covers && !identical;
|
|
67
60
|
}
|
|
68
|
-
static
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
static chain(candidates) {
|
|
62
|
+
if (!candidates.length) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
66
|
+
const path = [topmostOf(candidates)];
|
|
67
|
+
for (;;) {
|
|
68
|
+
const current = path[0];
|
|
69
|
+
const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
|
|
70
|
+
if (!enclosing.length) {
|
|
71
|
+
return path;
|
|
77
72
|
}
|
|
73
|
+
path.unshift(topmostOf(enclosing));
|
|
78
74
|
}
|
|
79
|
-
|
|
75
|
+
}
|
|
76
|
+
static topmost(containers) {
|
|
77
|
+
return containers.length
|
|
78
|
+
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
79
|
+
: [];
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
exports.DocumentContainerUtil = DocumentContainerUtil;
|
|
@@ -4,12 +4,10 @@ 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;
|
|
8
7
|
private static measureDocumentElements;
|
|
9
8
|
private static measure;
|
|
10
9
|
private static collectContainers;
|
|
11
|
-
private static
|
|
10
|
+
private static resolvePath;
|
|
12
11
|
private static enclosersOf;
|
|
13
|
-
private static chain;
|
|
14
12
|
private static candidateContainers;
|
|
15
13
|
}
|
|
@@ -2,48 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentContainerService = void 0;
|
|
4
4
|
const document_element_factory_1 = require("../document-element-factory");
|
|
5
|
-
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
6
|
-
const document_element_constants_1 = require("../document-element-constants");
|
|
7
5
|
const container_kind_1 = require("./container-kind");
|
|
8
6
|
const document_container_index_1 = require("./document-container-index");
|
|
9
7
|
const document_container_1 = require("./document-container");
|
|
10
8
|
class DocumentContainerService {
|
|
11
9
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
12
|
-
var _a, _b
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const elements = documentElements !== null && documentElements !== void 0 ? documentElements : [];
|
|
12
|
+
const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
|
|
13
|
+
if (!elements.some((element) => containerElementTypes.has(element === null || element === void 0 ? void 0 : element.type))) {
|
|
14
|
+
return document_container_index_1.DocumentContainerIndex.empty();
|
|
15
|
+
}
|
|
16
|
+
const documentElementsById = new Map(elements.map((element) => [element.id, element]));
|
|
17
|
+
const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
|
|
18
|
+
const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
16
19
|
const containersById = new Map();
|
|
17
20
|
const containerIdsByElementType = new Map();
|
|
18
21
|
containersByElementType.forEach((containers, elementType) => {
|
|
19
22
|
containerIdsByElementType.set(elementType, containers.map((container) => container.id));
|
|
20
23
|
containers.forEach((container) => containersById.set(container.id, container));
|
|
21
24
|
});
|
|
22
|
-
const
|
|
25
|
+
const pathsByMeasured = new Map();
|
|
23
26
|
for (const measured of measuredDocumentElements) {
|
|
24
27
|
const byElementType = new Map();
|
|
25
|
-
for (const kind of
|
|
26
|
-
byElementType.set(kind.elementType, this.
|
|
27
|
-
}
|
|
28
|
-
directPaths.set(measured, byElementType);
|
|
29
|
-
}
|
|
30
|
-
for (const measured of measuredDocumentElements) {
|
|
31
|
-
const container = containersById.get(measured.documentElement.id);
|
|
32
|
-
if (container && container.documentElement === measured.documentElement) {
|
|
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
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const measuredById = new Map();
|
|
37
|
-
for (const measured of measuredDocumentElements) {
|
|
38
|
-
if (!measuredById.has(measured.documentElement.id)) {
|
|
39
|
-
measuredById.set(measured.documentElement.id, measured);
|
|
28
|
+
for (const kind of kinds) {
|
|
29
|
+
byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
40
30
|
}
|
|
31
|
+
pathsByMeasured.set(measured, byElementType);
|
|
41
32
|
}
|
|
42
33
|
const containerPathsByDocumentElementId = new Map();
|
|
43
34
|
const memberIdsByContainerId = new Map();
|
|
44
35
|
for (const measured of measuredDocumentElements) {
|
|
45
36
|
const documentElementId = measured.documentElement.id;
|
|
46
|
-
const pathsByElementType =
|
|
37
|
+
const pathsByElementType = new Map();
|
|
38
|
+
((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
47
39
|
for (const path of pathsByElementType.values()) {
|
|
48
40
|
for (const containerId of path) {
|
|
49
41
|
const members = memberIdsByContainerId.get(containerId);
|
|
@@ -58,7 +50,7 @@ class DocumentContainerService {
|
|
|
58
50
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
59
51
|
}
|
|
60
52
|
return new document_container_index_1.DocumentContainerIndex({
|
|
61
|
-
documentElementsById
|
|
53
|
+
documentElementsById,
|
|
62
54
|
containersById,
|
|
63
55
|
containerPathsByDocumentElementId,
|
|
64
56
|
memberIdsByContainerId,
|
|
@@ -68,30 +60,7 @@ class DocumentContainerService {
|
|
|
68
60
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
69
61
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
70
62
|
}
|
|
71
|
-
static
|
|
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
|
-
}
|
|
93
|
-
static measureDocumentElements(documentElements) {
|
|
94
|
-
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
63
|
+
static measureDocumentElements(documentElements, documentElementsById) {
|
|
95
64
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
96
65
|
documentElement,
|
|
97
66
|
drawOrder,
|
|
@@ -119,27 +88,20 @@ class DocumentContainerService {
|
|
|
119
88
|
.map((measured) => ({
|
|
120
89
|
id: measured.documentElement.id,
|
|
121
90
|
kind,
|
|
122
|
-
name: measured.documentElement.name,
|
|
123
91
|
documentElement: measured.documentElement,
|
|
124
92
|
box: measured.box,
|
|
125
|
-
depth: 0,
|
|
126
93
|
drawOrder: measured.drawOrder,
|
|
127
94
|
}));
|
|
128
95
|
}
|
|
129
|
-
static
|
|
96
|
+
static resolvePath(measured, kind, containers) {
|
|
130
97
|
if (!containers.length || !measured.box) {
|
|
131
98
|
return [];
|
|
132
99
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (ownKind.elementType === kind.elementType) {
|
|
136
|
-
return kind.nests ? this.chain(this.enclosersOf(measured, containers)) : [];
|
|
137
|
-
}
|
|
138
|
-
if (kind.layer > ownKind.layer) {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
100
|
+
if (measured.documentElement.type === kind.elementType) {
|
|
101
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
141
102
|
}
|
|
142
|
-
|
|
103
|
+
const candidates = this.candidateContainers(measured, containers);
|
|
104
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
143
105
|
}
|
|
144
106
|
static enclosersOf(measured, containers) {
|
|
145
107
|
return containers.filter((container) => {
|
|
@@ -150,27 +112,8 @@ class DocumentContainerService {
|
|
|
150
112
|
!((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
151
113
|
});
|
|
152
114
|
}
|
|
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
|
-
}
|
|
170
115
|
static candidateContainers(measured, containers) {
|
|
171
116
|
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
172
|
-
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
|
|
173
|
-
!dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
|
|
174
117
|
return containers.filter((container) => {
|
|
175
118
|
var _a;
|
|
176
119
|
if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
|
|
@@ -179,7 +122,7 @@ class DocumentContainerService {
|
|
|
179
122
|
if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
|
|
180
123
|
return false;
|
|
181
124
|
}
|
|
182
|
-
if (
|
|
125
|
+
if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
|
|
183
126
|
return false;
|
|
184
127
|
}
|
|
185
128
|
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
@@ -56,8 +56,9 @@ function isContainerBinding(bindingProperty) {
|
|
|
56
56
|
}
|
|
57
57
|
class DynamicTextUtil {
|
|
58
58
|
static isDynamicText(documentElement) {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
60
|
+
!!documentElement.propertyBindings &&
|
|
61
|
+
!!documentElement.propertyBindingsMetaData);
|
|
61
62
|
}
|
|
62
63
|
static takesValueFromContainer(bindingProperty) {
|
|
63
64
|
if (!bindingProperty) {
|