@contrail/documents 2.1.0-alpha.a738b01 → 2.1.0-alpha.afeb3fa
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.
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { DocumentElement } from '../types';
|
|
2
2
|
import { ContainerKind } from './container-kind';
|
|
3
3
|
import { DocumentContainerIndex } from './document-container-index';
|
|
4
|
-
export type MeasureDocumentElement = (documentElement: DocumentElement, startElement?: DocumentElement, endElement?: DocumentElement) => {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
} | null;
|
|
10
4
|
export declare class DocumentContainerService {
|
|
11
|
-
static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]
|
|
5
|
+
static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
|
|
12
6
|
static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
|
|
13
7
|
private static measureDocumentElements;
|
|
14
8
|
private static measure;
|
|
@@ -7,8 +7,8 @@ const container_kind_1 = require("./container-kind");
|
|
|
7
7
|
const document_container_index_1 = require("./document-container-index");
|
|
8
8
|
const document_container_1 = require("./document-container");
|
|
9
9
|
class DocumentContainerService {
|
|
10
|
-
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS
|
|
11
|
-
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []
|
|
10
|
+
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
11
|
+
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
|
|
12
12
|
const nestingByElementType = new Map(kinds.map((kind) => [kind.elementType, this.buildNesting(measuredDocumentElements, kind)]));
|
|
13
13
|
const containersById = new Map();
|
|
14
14
|
const containerIdsByElementType = new Map();
|
|
@@ -46,15 +46,15 @@ class DocumentContainerService {
|
|
|
46
46
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
47
47
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
48
48
|
}
|
|
49
|
-
static measureDocumentElements(documentElements
|
|
49
|
+
static measureDocumentElements(documentElements) {
|
|
50
50
|
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
51
51
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
52
52
|
documentElement,
|
|
53
53
|
drawOrder,
|
|
54
|
-
box: this.measure(documentElement, documentElementsById
|
|
54
|
+
box: this.measure(documentElement, documentElementsById),
|
|
55
55
|
}));
|
|
56
56
|
}
|
|
57
|
-
static measure(documentElement, documentElementsById
|
|
57
|
+
static measure(documentElement, documentElementsById) {
|
|
58
58
|
var _a, _b;
|
|
59
59
|
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
60
60
|
return null;
|
|
@@ -62,10 +62,8 @@ class DocumentContainerService {
|
|
|
62
62
|
try {
|
|
63
63
|
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
64
64
|
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
: document_element_factory_1.DocumentElementFactory.getBoundingClientRect(documentElement, start, end);
|
|
68
|
-
return rect ? (0, document_container_1.toCoordinateBox)(rect.x, rect.y, rect.width, rect.height) : null;
|
|
65
|
+
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRect(documentElement, start, end);
|
|
66
|
+
return (0, document_container_1.toCoordinateBox)(x, y, width, height);
|
|
69
67
|
}
|
|
70
68
|
catch (_c) {
|
|
71
69
|
return null;
|