@contrail/documents 2.4.0-alpha.7e4b381 → 2.4.0-alpha.9ac43de

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,7 +5,9 @@ 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-24
8
+ ## [2.4.0] - 2026-09-26
9
+
10
+ Also shipped on the 1.x line as 1.21.0.
9
11
 
10
12
  ### Added
11
13
 
@@ -62,8 +64,16 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
62
64
  ### Changed
63
65
 
64
66
  - Container membership measures a scaled element from its scaled box, through the new
65
- `getBoundingClientRectScaled` above. A scaled element previously measured at its unscaled size
66
- and could resolve to the wrong container.
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.
67
77
 
68
78
  ## [2.3.0] - 2026-09-21
69
79
 
@@ -3,7 +3,7 @@ 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;
6
+ canBeContentOf: readonly ContainerElementType[];
7
7
  }
8
8
  export declare const SECTION_KIND: ContainerKind;
9
9
  export declare const FRAME_KIND: ContainerKind;
@@ -2,6 +2,14 @@
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, layer: 0 };
6
- exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false, layer: 1 };
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
+ };
7
15
  exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
@@ -17,7 +17,6 @@ export declare class DocumentContainerIndex {
17
17
  memberIdsOf(containerId: string): readonly string[];
18
18
  memberDocumentElementsOf(containerId: string): DocumentElement[];
19
19
  containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
20
- maxDepth(elementType: ContainerElementType): number;
21
20
  private containersOfType;
22
21
  private resolveAll;
23
22
  private containerPath;
@@ -35,11 +35,12 @@ class DocumentContainerIndex {
35
35
  return members;
36
36
  }
37
37
  containerPathAtPoint(point, elementType) {
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);
40
- }
41
- maxDepth(elementType) {
42
- return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
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);
43
44
  }
44
45
  containersOfType(elementType) {
45
46
  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 {
@@ -19,9 +17,9 @@ export declare class DocumentContainerUtil {
19
17
  static centerOf(box: CoordinateBox): PositionDefinition;
20
18
  static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
21
19
  static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
22
- static anchorFor(documentElement: DocumentElement, position?: PositionDefinition): PositionDefinition;
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 isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
26
- static topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
23
+ static chain(candidates: DocumentContainer[]): DocumentContainer[];
24
+ static topmost(containers: DocumentContainer[]): DocumentContainer[];
27
25
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentContainerUtil = void 0;
4
4
  const rotation_math_1 = require("../util/mask/rotation-math");
5
5
  const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
6
+ const document_element_factory_1 = require("../document-element-factory");
6
7
  class DocumentContainerUtil {
7
8
  static toCoordinateBox(x, y, width, height) {
8
9
  return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
@@ -37,14 +38,13 @@ class DocumentContainerUtil {
37
38
  const after = cornerOffset(newSize);
38
39
  return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
39
40
  }
40
- static anchorFor(documentElement, position) {
41
- var _a, _b, _c, _d, _e;
41
+ static anchorFor(documentElement, position, startElement, endElement) {
42
42
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
43
43
  if (!at) {
44
44
  return null;
45
45
  }
46
- const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
47
- const 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));
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
48
  return DocumentContainerUtil.anchorOf(documentElement, box);
49
49
  }
50
50
  static containsPoint(box, point) {
@@ -58,18 +58,25 @@ class DocumentContainerUtil {
58
58
  outer.bottom === inner.bottom;
59
59
  return covers && !identical;
60
60
  }
61
- static isWiderAndTallerThan(box, other) {
62
- return box.width > other.width && box.height > other.height;
63
- }
64
- static topmostPerDepth(containers) {
65
- const byDepth = [];
66
- for (const container of containers) {
67
- const existing = byDepth[container.depth];
68
- if (!existing || container.drawOrder > existing.drawOrder) {
69
- byDepth[container.depth] = container;
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;
70
72
  }
73
+ path.unshift(topmostOf(enclosing));
71
74
  }
72
- return byDepth.filter(Boolean);
75
+ }
76
+ static topmost(containers) {
77
+ return containers.length
78
+ ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
79
+ : [];
73
80
  }
74
81
  }
75
82
  exports.DocumentContainerUtil = DocumentContainerUtil;
@@ -6,9 +6,8 @@ export declare class DocumentContainerService {
6
6
  static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
7
7
  private static measureDocumentElements;
8
8
  private static measure;
9
- private static buildNesting;
10
- private static resolveContainerPath;
11
- private static resolveInnermostOnTop;
12
- private static toContainerPath;
9
+ private static collectContainers;
10
+ private static resolvePath;
11
+ private static enclosersOf;
13
12
  private static candidateContainers;
14
13
  }
@@ -2,29 +2,41 @@
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) {
10
+ var _a, _b;
12
11
  const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
13
- const nestingByElementType = new Map(kinds.map((kind) => [kind.elementType, this.buildNesting(measuredDocumentElements, kind)]));
12
+ const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
14
13
  const containersById = new Map();
15
14
  const containerIdsByElementType = new Map();
16
- nestingByElementType.forEach((nesting, elementType) => {
17
- containerIdsByElementType.set(elementType, nesting.containers.map((container) => container.id));
18
- nesting.containers.forEach((container) => containersById.set(container.id, container));
15
+ containersByElementType.forEach((containers, elementType) => {
16
+ containerIdsByElementType.set(elementType, containers.map((container) => container.id));
17
+ containers.forEach((container) => containersById.set(container.id, container));
19
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
+ }
20
33
  const containerPathsByDocumentElementId = new Map();
21
34
  const memberIdsByContainerId = new Map();
22
35
  for (const measured of measuredDocumentElements) {
23
36
  const documentElementId = measured.documentElement.id;
24
37
  const pathsByElementType = new Map();
25
- for (const kind of kinds) {
26
- const path = this.resolveContainerPath(measured, kind, kinds, nestingByElementType.get(kind.elementType));
27
- pathsByElementType.set(kind.elementType, path);
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()) {
28
40
  for (const containerId of path) {
29
41
  const members = memberIdsByContainerId.get(containerId);
30
42
  if (members) {
@@ -38,7 +50,7 @@ class DocumentContainerService {
38
50
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
39
51
  }
40
52
  return new document_container_index_1.DocumentContainerIndex({
41
- documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
53
+ documentElementsById: new Map([...measuredById].map(([id, measured]) => [id, measured.documentElement])),
42
54
  containersById,
43
55
  containerPathsByDocumentElementId,
44
56
  memberIdsByContainerId,
@@ -71,73 +83,53 @@ class DocumentContainerService {
71
83
  return null;
72
84
  }
73
85
  }
74
- static buildNesting(measuredDocumentElements, kind) {
75
- const containers = measuredDocumentElements
86
+ static collectContainers(measuredDocumentElements, kind) {
87
+ return measuredDocumentElements
76
88
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
77
89
  .map((measured) => ({
78
90
  id: measured.documentElement.id,
79
91
  kind,
80
- name: measured.documentElement.name,
81
92
  documentElement: measured.documentElement,
82
93
  box: measured.box,
83
- depth: 0,
84
94
  drawOrder: measured.drawOrder,
85
95
  }));
86
- const ancestorsById = new Map();
87
- for (const container of containers) {
88
- const ancestors = kind.nests
89
- ? containers.filter((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(other.box, container.box))
90
- : [];
91
- ancestorsById.set(container.id, ancestors);
92
- container.depth = ancestors.length;
93
- }
94
- return { containers, ancestorsById };
95
96
  }
96
- static resolveContainerPath(measured, kind, kinds, nesting) {
97
- var _a, _b;
98
- if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
97
+ static resolvePath(measured, kind, containers) {
98
+ if (!containers.length || !measured.box) {
99
99
  return [];
100
100
  }
101
- const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
101
+ const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
102
102
  if (ownKind) {
103
103
  if (ownKind.elementType === kind.elementType) {
104
- return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
104
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
105
105
  }
106
- if (kind.layer > ownKind.layer) {
106
+ if (!ownKind.canBeContentOf.includes(kind.elementType)) {
107
107
  return [];
108
108
  }
109
109
  }
110
- const candidates = this.candidateContainers(measured, nesting.containers);
111
- if (!candidates.length) {
112
- return [];
113
- }
114
- const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
115
- const candidateIds = new Set(candidates.map((container) => container.id));
116
- const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
117
- return this.toContainerPath([...ancestors, innermostOnTop]);
110
+ const candidates = this.candidateContainers(measured, containers);
111
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
118
112
  }
119
- static resolveInnermostOnTop(candidates, nesting) {
120
- const enclosingIds = new Set(candidates.flatMap((container) => { var _a; return (_a = nesting.ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : []; }).map((ancestor) => ancestor.id));
121
- return candidates
122
- .filter((container) => !enclosingIds.has(container.id))
123
- .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
124
- }
125
- static toContainerPath(containers) {
126
- return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
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
+ });
127
121
  }
128
122
  static candidateContainers(measured, containers) {
129
123
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
130
- const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
131
- !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
132
124
  return containers.filter((container) => {
133
125
  var _a;
134
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
126
+ if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
135
127
  return false;
136
128
  }
137
129
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
138
130
  return false;
139
131
  }
140
- if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
132
+ if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
141
133
  return false;
142
134
  }
143
135
  return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
@@ -48,6 +48,7 @@ export declare const HARD_CODED_TEXT: {
48
48
  'section.itemOptionCount': string;
49
49
  'section.colorCount': string;
50
50
  };
51
+ export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
51
52
  export declare class DynamicTextUtil {
52
53
  static isDynamicText(documentElement: DocumentElement): boolean;
53
54
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DynamicTextUtil = exports.HARD_CODED_TEXT = exports.CLICK_TO_CONFIGURE = exports.MOVE_TO_SECTION_TEXT = exports.MOVE_TO_FRAME_TEXT = exports.DynamicTextDisplayFunction = exports.DYNAMIC_TEXT_DATA_SOURCE = void 0;
4
+ exports.isContainerBinding = isContainerBinding;
4
5
  const types_1 = require("@contrail/types");
5
6
  const util_1 = require("@contrail/util");
6
7
  const document_util_1 = require("@contrail/document-util");
@@ -50,6 +51,9 @@ exports.HARD_CODED_TEXT = {
50
51
  };
51
52
  const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
52
53
  const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
54
+ function isContainerBinding(bindingProperty) {
55
+ return DynamicTextUtil.takesValueFromContainer(bindingProperty);
56
+ }
53
57
  class DynamicTextUtil {
54
58
  static isDynamicText(documentElement) {
55
59
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
@@ -172,8 +176,9 @@ class DynamicTextUtil {
172
176
  bold,
173
177
  italic,
174
178
  };
175
- if (!dynamicTextElement.isTextTool) {
176
- measureTextSettings.width = size.width - padding * 2;
179
+ const fixedWidth = size.width - padding * 2;
180
+ if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
181
+ measureTextSettings.width = fixedWidth;
177
182
  }
178
183
  try {
179
184
  const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
@@ -218,7 +223,10 @@ class DynamicTextUtil {
218
223
  }
219
224
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
220
225
  displayFunction === DynamicTextDisplayFunction.MAX) {
221
- const present = memberValues.filter((e) => e !== null && e !== undefined);
226
+ const present = memberValues
227
+ .filter((e) => e !== null && e !== undefined && e !== '')
228
+ .map(Number)
229
+ .filter((e) => !Number.isNaN(e));
222
230
  if (!present.length) {
223
231
  return '';
224
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.7e4b381",
3
+ "version": "2.4.0-alpha.9ac43de",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",