@contrail/documents 2.4.0-alpha.3107575 → 2.4.0-alpha.4805e08
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.
|
@@ -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
|
-
canBeContentOf: readonly ContainerElementType[];
|
|
7
6
|
}
|
|
8
7
|
export declare const SECTION_KIND: ContainerKind;
|
|
9
8
|
export declare const FRAME_KIND: ContainerKind;
|
|
@@ -2,14 +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 = {
|
|
6
|
-
|
|
7
|
-
nests: true,
|
|
8
|
-
canBeContentOf: [document_element_constants_1.SECTION_ELEMENT_TYPE],
|
|
9
|
-
};
|
|
10
|
-
exports.FRAME_KIND = {
|
|
11
|
-
elementType: document_element_constants_1.FRAME_ELEMENT_TYPE,
|
|
12
|
-
nests: false,
|
|
13
|
-
canBeContentOf: [document_element_constants_1.SECTION_ELEMENT_TYPE],
|
|
14
|
-
};
|
|
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 };
|
|
15
7
|
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -8,7 +8,9 @@ const document_container_1 = require("./document-container");
|
|
|
8
8
|
class DocumentContainerService {
|
|
9
9
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
10
10
|
var _a, _b;
|
|
11
|
-
const
|
|
11
|
+
const elements = documentElements !== null && documentElements !== void 0 ? documentElements : [];
|
|
12
|
+
const documentElementsById = new Map(elements.map((element) => [element.id, element]));
|
|
13
|
+
const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
|
|
12
14
|
const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
13
15
|
const containersById = new Map();
|
|
14
16
|
const containerIdsByElementType = new Map();
|
|
@@ -24,12 +26,6 @@ class DocumentContainerService {
|
|
|
24
26
|
}
|
|
25
27
|
pathsByMeasured.set(measured, byElementType);
|
|
26
28
|
}
|
|
27
|
-
const measuredById = new Map();
|
|
28
|
-
for (const measured of measuredDocumentElements) {
|
|
29
|
-
if (!measuredById.has(measured.documentElement.id)) {
|
|
30
|
-
measuredById.set(measured.documentElement.id, measured);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
29
|
const containerPathsByDocumentElementId = new Map();
|
|
34
30
|
const memberIdsByContainerId = new Map();
|
|
35
31
|
for (const measured of measuredDocumentElements) {
|
|
@@ -50,7 +46,7 @@ class DocumentContainerService {
|
|
|
50
46
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
51
47
|
}
|
|
52
48
|
return new document_container_index_1.DocumentContainerIndex({
|
|
53
|
-
documentElementsById
|
|
49
|
+
documentElementsById,
|
|
54
50
|
containersById,
|
|
55
51
|
containerPathsByDocumentElementId,
|
|
56
52
|
memberIdsByContainerId,
|
|
@@ -60,8 +56,7 @@ class DocumentContainerService {
|
|
|
60
56
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
61
57
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
62
58
|
}
|
|
63
|
-
static measureDocumentElements(documentElements) {
|
|
64
|
-
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
59
|
+
static measureDocumentElements(documentElements, documentElementsById) {
|
|
65
60
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
66
61
|
documentElement,
|
|
67
62
|
drawOrder,
|
|
@@ -98,14 +93,8 @@ class DocumentContainerService {
|
|
|
98
93
|
if (!containers.length || !measured.box) {
|
|
99
94
|
return [];
|
|
100
95
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (ownKind.elementType === kind.elementType) {
|
|
104
|
-
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
105
|
-
}
|
|
106
|
-
if (!ownKind.canBeContentOf.includes(kind.elementType)) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
96
|
+
if (measured.documentElement.type === kind.elementType) {
|
|
97
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
109
98
|
}
|
|
110
99
|
const candidates = this.candidateContainers(measured, containers);
|
|
111
100
|
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|