@contrail/documents 2.3.0 → 2.4.0-alpha.3107575

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/CHANGELOG.md CHANGED
@@ -5,6 +5,76 @@ All notable changes to `@contrail/documents` are documented here.
5
5
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
  Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.4.0] - 2026-09-26
9
+
10
+ Also shipped on the 1.x line as 1.21.0.
11
+
12
+ ### Added
13
+
14
+ - `DocumentContainerService.buildIndex` and `DocumentContainerIndex` — which containers hold which
15
+ elements, for one document, resolved once and read back by lookup. A container is a frame or a
16
+ section, described by a `ContainerKind` carrying `elementType`, `nests` and `layer`. An element
17
+ belongs to the container whose box covers its anchor point and which is drawn below it. Nesting
18
+ gives a path with one container per depth, the later-drawn one winning where two cross. A
19
+ container is only ever content of a kind layered behind it, so a frame belongs to a section and a
20
+ section never to a frame. Shapes wider and taller than the container, and groups holding it, are
21
+ excluded.
22
+ - `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
23
+ `document-element-constants`, so the rule above has one definition rather than one per app.
24
+ - `DocumentContainerUtil` — the container geometry as statics, with `anchorFor` for a caller
25
+ holding an element rather than a measured box.
26
+ - `positionKeepingAnchor` — where an element has to sit for its drawn corner to land where it did
27
+ before a resize. Rotation turns about the centre and the centre moves with the size, so a rotated
28
+ element resized about its stored position drags its corner along with it. The board already makes
29
+ this move; a server recomputing a dynamic text has to make the same one, or the corner is not the
30
+ fixed point the anchor rule needs.
31
+ - `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
32
+ with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
33
+ which is what layout works in: `@contrail/document-table` places table members from it, and
34
+ scaling it moves a scaled member into a different cell. Anything deciding what an element overlaps
35
+ or sits on wants the scaled one.
36
+
37
+ ### Deprecated
38
+
39
+ - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
40
+ for what it decides: whether the binding's value comes from the container rather than a type
41
+ property. The old name still works and delegates to the new one.
42
+
43
+ ### Fixed
44
+
45
+ - A dynamic text is now anchored at its drawn top-left corner rather than its centre when deciding
46
+ which container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its
47
+ size comes from the value it resolves to, and that value depends on the container, so letting its
48
+ width feed membership meant its own text could choose its container: near an edge the two answers
49
+ disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
50
+ else still resolves on its centre.
51
+ - The corner is the rotated one (VIBE-9567). A 200x20 text turned on its side draws as a 20x200
52
+ column, and its unrotated `position` can sit well clear of the frame it is visibly on, which
53
+ reported "Move to a frame" for a vertical text the user could see was placed correctly.
54
+ - A dynamic text is also exempt from the oversized-shape exclusion, which keeps a shape wider and
55
+ taller than a container off it. That rule reads size too, so a dynamic text larger than its frame
56
+ in both directions had two self-consistent answers and kept whichever it started from. The rule
57
+ exists to keep a backdrop shape off a frame it covers, which is not what a dynamic text is doing.
58
+ - `min` and `max` rendered an infinity sign when every member value was empty. The early return
59
+ checked the list length before the empty values were filtered out, so `Math.min` of nothing
60
+ reached the formatter. Both now fall through to `n/a`.
61
+ - `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
62
+ the server failed the read for the whole document. It now measures from a zero size instead.
63
+
64
+ ### Changed
65
+
66
+ - Container membership measures a scaled element from its scaled box, through the new
67
+ `getBoundingClientRectScaled` above. Only a sticky note, a regular iframe, a text-tool text or a
68
+ table carries `scale` at all; for this work the one that matters is a text-tool dynamic text,
69
+ which previously measured at its unscaled size and could resolve to the wrong container.
70
+ - `DocumentContainerUtil.anchorFor` measures through the same factory call the index uses, so a
71
+ caller holding an element gets the answer the index would give it. Reading `size` directly
72
+ disagreed for the types whose box is not position plus size: a component's box is built from the
73
+ rows it draws, and a line's comes from its `lineDefinition`.
74
+ - Container depth counts nesting levels rather than enclosing boxes. Two containers that merely
75
+ cross both enclose anything inside the overlap, so counting ancestors put that inner container a
76
+ level too deep and made `maxDepth` report a level no path could reach.
77
+
8
78
  ## [2.3.0] - 2026-09-21
9
79
 
10
80
  ### Added
@@ -0,0 +1,10 @@
1
+ import { FRAME_ELEMENT_TYPE, SECTION_ELEMENT_TYPE } from '../document-element-constants';
2
+ export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_ELEMENT_TYPE;
3
+ export interface ContainerKind {
4
+ elementType: ContainerElementType;
5
+ nests: boolean;
6
+ canBeContentOf: readonly ContainerElementType[];
7
+ }
8
+ export declare const SECTION_KIND: ContainerKind;
9
+ export declare const FRAME_KIND: ContainerKind;
10
+ export declare const CONTAINER_KINDS: ContainerKind[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTAINER_KINDS = exports.FRAME_KIND = exports.SECTION_KIND = void 0;
4
+ const document_element_constants_1 = require("../document-element-constants");
5
+ exports.SECTION_KIND = {
6
+ elementType: document_element_constants_1.SECTION_ELEMENT_TYPE,
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
+ };
15
+ exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
@@ -0,0 +1,23 @@
1
+ import { DocumentElement, PositionDefinition } from '../types';
2
+ import { ContainerElementType } from './container-kind';
3
+ import { DocumentContainer } from './document-container';
4
+ export declare class DocumentContainerIndex {
5
+ private readonly data;
6
+ constructor(data: {
7
+ documentElementsById: Map<string, DocumentElement>;
8
+ containersById: Map<string, DocumentContainer>;
9
+ containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
10
+ memberIdsByContainerId: Map<string, string[]>;
11
+ containerIdsByElementType: Map<string, string[]>;
12
+ });
13
+ getContainer(containerId: string): DocumentContainer | null;
14
+ containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
15
+ containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
16
+ innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
17
+ memberIdsOf(containerId: string): readonly string[];
18
+ memberDocumentElementsOf(containerId: string): DocumentElement[];
19
+ containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
20
+ private containersOfType;
21
+ private resolveAll;
22
+ private containerPath;
23
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentContainerIndex = void 0;
4
+ const document_container_1 = require("./document-container");
5
+ class DocumentContainerIndex {
6
+ constructor(data) {
7
+ this.data = data;
8
+ }
9
+ getContainer(containerId) {
10
+ var _a;
11
+ return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
12
+ }
13
+ containersOf(documentElementId, elementType) {
14
+ return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
15
+ }
16
+ containerIdsOf(documentElementId, elementType) {
17
+ return this.containerPath(documentElementId, elementType);
18
+ }
19
+ innermostContainerIdOf(documentElementId, elementType) {
20
+ const path = this.containerPath(documentElementId, elementType);
21
+ return path.length ? path[path.length - 1] : null;
22
+ }
23
+ memberIdsOf(containerId) {
24
+ var _a;
25
+ return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
26
+ }
27
+ memberDocumentElementsOf(containerId) {
28
+ const members = [];
29
+ for (const memberId of this.memberIdsOf(containerId)) {
30
+ const member = this.data.documentElementsById.get(memberId);
31
+ if (member) {
32
+ members.push(member);
33
+ }
34
+ }
35
+ return members;
36
+ }
37
+ containerPathAtPoint(point, elementType) {
38
+ var _a, _b;
39
+ const containers = this.containersOfType(elementType);
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);
44
+ }
45
+ containersOfType(elementType) {
46
+ var _a;
47
+ return this.resolveAll((_a = this.data.containerIdsByElementType.get(elementType)) !== null && _a !== void 0 ? _a : []);
48
+ }
49
+ resolveAll(containerIds) {
50
+ const containers = [];
51
+ for (const containerId of containerIds) {
52
+ const container = this.data.containersById.get(containerId);
53
+ if (container) {
54
+ containers.push(container);
55
+ }
56
+ }
57
+ return containers;
58
+ }
59
+ containerPath(documentElementId, elementType) {
60
+ var _a, _b;
61
+ return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
62
+ }
63
+ }
64
+ exports.DocumentContainerIndex = DocumentContainerIndex;
@@ -0,0 +1,25 @@
1
+ import { CoordinateBox, DocumentElement, PositionDefinition, SizeDefinition } from '../types';
2
+ import { ContainerKind } from './container-kind';
3
+ export interface DocumentContainer {
4
+ id: string;
5
+ kind: ContainerKind;
6
+ documentElement: DocumentElement;
7
+ box: CoordinateBox;
8
+ drawOrder: number;
9
+ }
10
+ export interface MeasuredDocumentElement {
11
+ documentElement: DocumentElement;
12
+ box: CoordinateBox | null;
13
+ drawOrder: number;
14
+ }
15
+ export declare class DocumentContainerUtil {
16
+ static toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
17
+ static centerOf(box: CoordinateBox): PositionDefinition;
18
+ static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
19
+ static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
20
+ static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
21
+ static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
22
+ static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
23
+ static chain(candidates: DocumentContainer[]): DocumentContainer[];
24
+ static topmost(containers: DocumentContainer[]): DocumentContainer[];
25
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentContainerUtil = void 0;
4
+ const rotation_math_1 = require("../util/mask/rotation-math");
5
+ const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
6
+ const document_element_factory_1 = require("../document-element-factory");
7
+ class DocumentContainerUtil {
8
+ static toCoordinateBox(x, y, width, height) {
9
+ return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
10
+ }
11
+ static centerOf(box) {
12
+ return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
13
+ }
14
+ static anchorOf(documentElement, box) {
15
+ var _a;
16
+ if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
17
+ return DocumentContainerUtil.centerOf(box);
18
+ }
19
+ const angle = (_a = documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
20
+ const corner = { x: box.left, y: box.top };
21
+ return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, DocumentContainerUtil.centerOf(box)) : corner;
22
+ }
23
+ static positionKeepingAnchor(documentElement, newSize) {
24
+ var _a, _b, _c, _d, _e;
25
+ const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
26
+ const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
27
+ if (!position || !angle || !newSize || !documentElement.size) {
28
+ return position;
29
+ }
30
+ const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
31
+ const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
32
+ const cornerOffset = (size) => {
33
+ const half = { x: (size.width * scaleX) / 2, y: (size.height * scaleY) / 2 };
34
+ const turned = (0, rotation_math_1.rotatePoint)(half, angle);
35
+ return { x: half.x - turned.x, y: half.y - turned.y };
36
+ };
37
+ const before = cornerOffset(documentElement.size);
38
+ const after = cornerOffset(newSize);
39
+ return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
40
+ }
41
+ static anchorFor(documentElement, position, startElement, endElement) {
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 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);
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 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;
72
+ }
73
+ path.unshift(topmostOf(enclosing));
74
+ }
75
+ }
76
+ static topmost(containers) {
77
+ return containers.length
78
+ ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
79
+ : [];
80
+ }
81
+ }
82
+ exports.DocumentContainerUtil = DocumentContainerUtil;
@@ -0,0 +1,13 @@
1
+ import { DocumentElement } from '../types';
2
+ import { ContainerKind } from './container-kind';
3
+ import { DocumentContainerIndex } from './document-container-index';
4
+ export declare class DocumentContainerService {
5
+ static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
6
+ static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
7
+ private static measureDocumentElements;
8
+ private static measure;
9
+ private static collectContainers;
10
+ private static resolvePath;
11
+ private static enclosersOf;
12
+ private static candidateContainers;
13
+ }
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentContainerService = void 0;
4
+ const document_element_factory_1 = require("../document-element-factory");
5
+ const container_kind_1 = require("./container-kind");
6
+ const document_container_index_1 = require("./document-container-index");
7
+ const document_container_1 = require("./document-container");
8
+ class DocumentContainerService {
9
+ static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
10
+ var _a, _b;
11
+ const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
12
+ const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
13
+ const containersById = new Map();
14
+ const containerIdsByElementType = new Map();
15
+ containersByElementType.forEach((containers, elementType) => {
16
+ containerIdsByElementType.set(elementType, containers.map((container) => container.id));
17
+ containers.forEach((container) => containersById.set(container.id, container));
18
+ });
19
+ const pathsByMeasured = new Map();
20
+ for (const measured of measuredDocumentElements) {
21
+ const byElementType = new Map();
22
+ for (const kind of kinds) {
23
+ byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
24
+ }
25
+ pathsByMeasured.set(measured, byElementType);
26
+ }
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
+ const containerPathsByDocumentElementId = new Map();
34
+ const memberIdsByContainerId = new Map();
35
+ for (const measured of measuredDocumentElements) {
36
+ const documentElementId = measured.documentElement.id;
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)));
39
+ for (const path of pathsByElementType.values()) {
40
+ for (const containerId of path) {
41
+ const members = memberIdsByContainerId.get(containerId);
42
+ if (members) {
43
+ members.push(documentElementId);
44
+ }
45
+ else {
46
+ memberIdsByContainerId.set(containerId, [documentElementId]);
47
+ }
48
+ }
49
+ }
50
+ containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
51
+ }
52
+ return new document_container_index_1.DocumentContainerIndex({
53
+ documentElementsById: new Map([...measuredById].map(([id, measured]) => [id, measured.documentElement])),
54
+ containersById,
55
+ containerPathsByDocumentElementId,
56
+ memberIdsByContainerId,
57
+ containerIdsByElementType,
58
+ });
59
+ }
60
+ static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
61
+ return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
62
+ }
63
+ static measureDocumentElements(documentElements) {
64
+ const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
65
+ return documentElements.map((documentElement, drawOrder) => ({
66
+ documentElement,
67
+ drawOrder,
68
+ box: this.measure(documentElement, documentElementsById),
69
+ }));
70
+ }
71
+ static measure(documentElement, documentElementsById) {
72
+ var _a, _b;
73
+ if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
74
+ return null;
75
+ }
76
+ try {
77
+ const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
78
+ const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
79
+ const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
80
+ return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
81
+ }
82
+ catch (_c) {
83
+ return null;
84
+ }
85
+ }
86
+ static collectContainers(measuredDocumentElements, kind) {
87
+ return measuredDocumentElements
88
+ .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
89
+ .map((measured) => ({
90
+ id: measured.documentElement.id,
91
+ kind,
92
+ documentElement: measured.documentElement,
93
+ box: measured.box,
94
+ drawOrder: measured.drawOrder,
95
+ }));
96
+ }
97
+ static resolvePath(measured, kind, containers) {
98
+ if (!containers.length || !measured.box) {
99
+ return [];
100
+ }
101
+ const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
102
+ if (ownKind) {
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
+ }
109
+ }
110
+ const candidates = this.candidateContainers(measured, containers);
111
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
112
+ }
113
+ static enclosersOf(measured, containers) {
114
+ return containers.filter((container) => {
115
+ var _a;
116
+ return container.documentElement !== measured.documentElement &&
117
+ document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
118
+ measured.drawOrder > container.drawOrder &&
119
+ !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
120
+ });
121
+ }
122
+ static candidateContainers(measured, containers) {
123
+ const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
124
+ return containers.filter((container) => {
125
+ var _a;
126
+ if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
127
+ return false;
128
+ }
129
+ if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
130
+ return false;
131
+ }
132
+ if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
133
+ return false;
134
+ }
135
+ return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
136
+ });
137
+ }
138
+ }
139
+ exports.DocumentContainerService = DocumentContainerService;
@@ -3,3 +3,6 @@ export declare const ANNOTATION_PADDING_Y = 8;
3
3
  export declare const COLOR_PADDING = 5;
4
4
  export declare const COLOR_FONT_SIZE = 8;
5
5
  export declare const COLOR_WIDTH = 140;
6
+ export declare const SECTION_ELEMENT_TYPE = "section";
7
+ export declare const FRAME_ELEMENT_TYPE = "frame";
8
+ export declare const SHAPE_ELEMENT_TYPES: string[];
@@ -1,8 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ANNOTATION_PADDING_Y = exports.ANNOTATION_IMG_SIZE = void 0;
3
+ exports.SHAPE_ELEMENT_TYPES = exports.FRAME_ELEMENT_TYPE = exports.SECTION_ELEMENT_TYPE = exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ANNOTATION_PADDING_Y = exports.ANNOTATION_IMG_SIZE = void 0;
4
4
  exports.ANNOTATION_IMG_SIZE = 15;
5
5
  exports.ANNOTATION_PADDING_Y = 8;
6
6
  exports.COLOR_PADDING = 5;
7
7
  exports.COLOR_FONT_SIZE = 8;
8
8
  exports.COLOR_WIDTH = 140;
9
+ exports.SECTION_ELEMENT_TYPE = 'section';
10
+ exports.FRAME_ELEMENT_TYPE = 'frame';
11
+ exports.SHAPE_ELEMENT_TYPES = [
12
+ 'text',
13
+ 'line',
14
+ 'arrow',
15
+ 'circle',
16
+ 'rectangle',
17
+ 'round_rectangle',
18
+ 'triangle',
19
+ 'diamond',
20
+ 'star',
21
+ 'heart',
22
+ 'double_arrow',
23
+ 'right_arrow',
24
+ 'rhombus',
25
+ 'cloud',
26
+ 'callout',
27
+ 'draw_frame',
28
+ 'draw_section',
29
+ ];
@@ -22,6 +22,12 @@ export declare class DocumentElementFactory {
22
22
  width: any;
23
23
  height: any;
24
24
  };
25
+ static getBoundingClientRectScaled(documentElement: DocumentElement, startElement?: DocumentElement, endElement?: DocumentElement): {
26
+ x: any;
27
+ y: any;
28
+ width: any;
29
+ height: any;
30
+ };
25
31
  private static getPosition;
26
32
  private static getSize;
27
33
  private static getComponentSize;
@@ -216,6 +216,16 @@ class DocumentElementFactory {
216
216
  height,
217
217
  };
218
218
  }
219
+ static getBoundingClientRectScaled(documentElement, startElement, endElement) {
220
+ var _a, _b, _c, _d;
221
+ const { x, y, width, height } = this.getBoundingClientRect(documentElement, startElement, endElement);
222
+ return {
223
+ x,
224
+ y,
225
+ width: width * ((_b = (_a = documentElement.scale) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 1),
226
+ height: height * ((_d = (_c = documentElement.scale) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : 1),
227
+ };
228
+ }
219
229
  static getPosition(documentElement, startElement, endElement) {
220
230
  var _a, _b;
221
231
  if (documentElement.type === 'line' || documentElement.type === 'callout') {
package/lib/index.d.ts CHANGED
@@ -14,3 +14,7 @@ export * from './util/curved-line/curved-line';
14
14
  export * from './util/callout/callout';
15
15
  export * from './util/mask';
16
16
  export * from './document-frame.service';
17
+ export * from './containers/container-kind';
18
+ export * from './containers/document-container';
19
+ export * from './containers/document-container-index';
20
+ export * from './containers/document-container.service';
package/lib/index.js CHANGED
@@ -30,3 +30,7 @@ __exportStar(require("./util/curved-line/curved-line"), exports);
30
30
  __exportStar(require("./util/callout/callout"), exports);
31
31
  __exportStar(require("./util/mask"), exports);
32
32
  __exportStar(require("./document-frame.service"), exports);
33
+ __exportStar(require("./containers/container-kind"), exports);
34
+ __exportStar(require("./containers/document-container"), exports);
35
+ __exportStar(require("./containers/document-container-index"), exports);
36
+ __exportStar(require("./containers/document-container.service"), exports);
@@ -50,6 +50,8 @@ export declare const HARD_CODED_TEXT: {
50
50
  };
51
51
  export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
52
52
  export declare class DynamicTextUtil {
53
+ static isDynamicText(documentElement: DocumentElement): boolean;
54
+ static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
53
55
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
54
56
  static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
55
57
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
@@ -52,13 +52,21 @@ exports.HARD_CODED_TEXT = {
52
52
  const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
53
53
  const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
54
54
  function isContainerBinding(bindingProperty) {
55
- if (!bindingProperty) {
56
- return false;
57
- }
58
- const [entityType, propertySlug] = bindingProperty.split('.');
59
- return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
55
+ return DynamicTextUtil.takesValueFromContainer(bindingProperty);
60
56
  }
61
57
  class DynamicTextUtil {
58
+ static isDynamicText(documentElement) {
59
+ return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
60
+ !!documentElement.propertyBindings &&
61
+ !!documentElement.propertyBindingsMetaData);
62
+ }
63
+ static takesValueFromContainer(bindingProperty) {
64
+ if (!bindingProperty) {
65
+ return false;
66
+ }
67
+ const [entityType, propertySlug] = bindingProperty.split('.');
68
+ return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
69
+ }
62
70
  static getDynamicTextValue(dynamicTextElement, property, propertyLevel, container, componentModels, ownerReferenceModel = null) {
63
71
  var _a, _b, _c, _d;
64
72
  if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
@@ -150,12 +158,12 @@ class DynamicTextUtil {
150
158
  return text;
151
159
  }
152
160
  static calculateSize(dynamicTextElement, entityType, text) {
153
- var _a, _b, _c, _d;
154
- let size = dynamicTextElement.size;
155
- const fontFamily = (_a = document_util_1.DocumentStyleUtil.getFirstFontFamily(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text)) !== null && _a !== void 0 ? _a : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
156
- const fontSize = (_d = (dynamicTextElement.isTextTool
157
- ? (_c = (_b = dynamicTextElement.style) === null || _b === void 0 ? void 0 : _b.font) === null || _c === void 0 ? void 0 : _c.size
158
- : document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _d !== void 0 ? _d : document_util_1.DEFAULT_TEXT_FONT_SIZE;
161
+ var _a, _b, _c, _d, _e;
162
+ let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
163
+ const fontFamily = (_b = document_util_1.DocumentStyleUtil.getFirstFontFamily(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text)) !== null && _b !== void 0 ? _b : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
164
+ const fontSize = (_e = (dynamicTextElement.isTextTool
165
+ ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
166
+ : document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _e !== void 0 ? _e : document_util_1.DEFAULT_TEXT_FONT_SIZE;
159
167
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
160
168
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
161
169
  const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
@@ -168,8 +176,9 @@ class DynamicTextUtil {
168
176
  bold,
169
177
  italic,
170
178
  };
171
- if (!dynamicTextElement.isTextTool) {
172
- measureTextSettings.width = dynamicTextElement.size.width - padding * 2;
179
+ const fixedWidth = size.width - padding * 2;
180
+ if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
181
+ measureTextSettings.width = fixedWidth;
173
182
  }
174
183
  try {
175
184
  const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
@@ -212,13 +221,17 @@ class DynamicTextUtil {
212
221
  else if (displayFunction === DynamicTextDisplayFunction.LAST) {
213
222
  text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
214
223
  }
215
- else if (displayFunction === DynamicTextDisplayFunction.MIN) {
216
- memberValues = memberValues.filter((e) => e !== null && e !== undefined);
217
- text = formatter.formatValueForProperty(Math.min(...memberValues), property);
218
- }
219
- else if (displayFunction === DynamicTextDisplayFunction.MAX) {
220
- memberValues = memberValues.filter((e) => e !== null && e !== undefined);
221
- text = formatter.formatValueForProperty(Math.max(...memberValues), property);
224
+ else if (displayFunction === DynamicTextDisplayFunction.MIN ||
225
+ displayFunction === DynamicTextDisplayFunction.MAX) {
226
+ const present = memberValues
227
+ .filter((e) => e !== null && e !== undefined && e !== '')
228
+ .map(Number)
229
+ .filter((e) => !Number.isNaN(e));
230
+ if (!present.length) {
231
+ return '';
232
+ }
233
+ const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
234
+ text = formatter.formatValueForProperty(extreme, property);
222
235
  }
223
236
  return text;
224
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.3.0",
3
+ "version": "2.4.0-alpha.3107575",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",