@contrail/documents 2.4.0-alpha.a01d866 → 2.4.0-alpha.c01727c

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.
@@ -45,16 +45,13 @@ class DocumentContainerUtil {
45
45
  return null;
46
46
  }
47
47
  const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
48
- let width = 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);
49
- let height = 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);
48
+ let 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));
50
49
  try {
51
50
  const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
52
- width = measured.width;
53
- height = measured.height;
51
+ box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
54
52
  }
55
53
  catch (_f) {
56
54
  }
57
- const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, width, height);
58
55
  return DocumentContainerUtil.anchorOf(documentElement, box);
59
56
  }
60
57
  static containsPoint(box, point) {
@@ -4,11 +4,12 @@ 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;
7
8
  private static measureDocumentElements;
8
9
  private static measure;
9
- private static buildNesting;
10
- private static resolveContainerPath;
11
- private static resolveInnermostOnTop;
12
- private static toContainerPath;
10
+ private static collectContainers;
11
+ private static resolveDirectPath;
12
+ private static enclosersOf;
13
+ private static chain;
13
14
  private static candidateContainers;
14
15
  }
@@ -9,22 +9,42 @@ const document_container_index_1 = require("./document-container-index");
9
9
  const document_container_1 = require("./document-container");
10
10
  class DocumentContainerService {
11
11
  static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
12
+ var _a, _b, _c;
12
13
  const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
13
- const nestingByElementType = new Map(kinds.map((kind) => [kind.elementType, this.buildNesting(measuredDocumentElements, kind)]));
14
+ const kindsByLayer = [...kinds].sort((first, second) => second.layer - first.layer);
15
+ const containersByElementType = new Map(kindsByLayer.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
14
16
  const containersById = new Map();
15
17
  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));
18
+ containersByElementType.forEach((containers, elementType) => {
19
+ containerIdsByElementType.set(elementType, containers.map((container) => container.id));
20
+ containers.forEach((container) => containersById.set(container.id, container));
19
21
  });
22
+ const directPaths = new Map();
23
+ for (const measured of measuredDocumentElements) {
24
+ const byElementType = new Map();
25
+ for (const kind of kindsByLayer) {
26
+ byElementType.set(kind.elementType, this.resolveDirectPath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
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);
40
+ }
41
+ }
20
42
  const containerPathsByDocumentElementId = new Map();
21
43
  const memberIdsByContainerId = new Map();
22
44
  for (const measured of measuredDocumentElements) {
23
45
  const documentElementId = measured.documentElement.id;
24
- 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);
46
+ const pathsByElementType = this.inherit(measured, kindsByLayer, directPaths, measuredById, new Set());
47
+ for (const path of pathsByElementType.values()) {
28
48
  for (const containerId of path) {
29
49
  const members = memberIdsByContainerId.get(containerId);
30
50
  if (members) {
@@ -38,7 +58,7 @@ class DocumentContainerService {
38
58
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
39
59
  }
40
60
  return new document_container_index_1.DocumentContainerIndex({
41
- documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
61
+ documentElementsById: new Map([...measuredById].map(([id, measured]) => [id, measured.documentElement])),
42
62
  containersById,
43
63
  containerPathsByDocumentElementId,
44
64
  memberIdsByContainerId,
@@ -48,6 +68,28 @@ class DocumentContainerService {
48
68
  static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
49
69
  return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
50
70
  }
71
+ static inherit(measured, kindsByLayer, directPaths, measuredById, resolving) {
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
+ }
51
93
  static measureDocumentElements(documentElements) {
52
94
  const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
53
95
  return documentElements.map((documentElement, drawOrder) => ({
@@ -71,8 +113,8 @@ class DocumentContainerService {
71
113
  return null;
72
114
  }
73
115
  }
74
- static buildNesting(measuredDocumentElements, kind) {
75
- const containers = measuredDocumentElements
116
+ static collectContainers(measuredDocumentElements, kind) {
117
+ return measuredDocumentElements
76
118
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
77
119
  .map((measured) => ({
78
120
  id: measured.documentElement.id,
@@ -83,61 +125,47 @@ class DocumentContainerService {
83
125
  depth: 0,
84
126
  drawOrder: measured.drawOrder,
85
127
  }));
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
- }
93
- const depths = new Map();
94
- const depthOf = (container) => {
95
- var _a;
96
- const cached = depths.get(container.id);
97
- if (cached !== undefined) {
98
- return cached;
99
- }
100
- const ancestors = (_a = ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : [];
101
- const depth = ancestors.length ? 1 + Math.max(...ancestors.map(depthOf)) : 0;
102
- depths.set(container.id, depth);
103
- return depth;
104
- };
105
- for (const container of containers) {
106
- container.depth = depthOf(container);
107
- }
108
- return { containers, ancestorsById };
109
128
  }
110
- static resolveContainerPath(measured, kind, kinds, nesting) {
111
- var _a, _b;
112
- if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
129
+ static resolveDirectPath(measured, kind, containers) {
130
+ if (!containers.length || !measured.box) {
113
131
  return [];
114
132
  }
115
- const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
133
+ const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
116
134
  if (ownKind) {
117
135
  if (ownKind.elementType === kind.elementType) {
118
- return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
136
+ return kind.nests ? this.chain(this.enclosersOf(measured, containers)) : [];
119
137
  }
120
138
  if (kind.layer > ownKind.layer) {
121
139
  return [];
122
140
  }
123
141
  }
124
- const candidates = this.candidateContainers(measured, nesting.containers);
142
+ return this.chain(this.candidateContainers(measured, containers));
143
+ }
144
+ static enclosersOf(measured, containers) {
145
+ return containers.filter((container) => {
146
+ var _a;
147
+ return container.documentElement !== measured.documentElement &&
148
+ document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
149
+ measured.drawOrder > container.drawOrder &&
150
+ !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
151
+ });
152
+ }
153
+ static chain(candidates) {
125
154
  if (!candidates.length) {
126
155
  return [];
127
156
  }
128
- const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
129
- const candidateIds = new Set(candidates.map((container) => container.id));
130
- const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
131
- return this.toContainerPath([...ancestors, innermostOnTop]);
132
- }
133
- static resolveInnermostOnTop(candidates, nesting) {
134
- 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));
135
- return candidates
136
- .filter((container) => !enclosingIds.has(container.id))
157
+ const innermostOf = (of) => of
158
+ .filter((container) => !of.some((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(container.box, other.box)))
137
159
  .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
138
- }
139
- static toContainerPath(containers) {
140
- return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
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
+ }
141
169
  }
142
170
  static candidateContainers(measured, containers) {
143
171
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
@@ -145,7 +173,7 @@ class DocumentContainerService {
145
173
  !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
146
174
  return containers.filter((container) => {
147
175
  var _a;
148
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
176
+ if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
149
177
  return false;
150
178
  }
151
179
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
@@ -56,9 +56,8 @@ function isContainerBinding(bindingProperty) {
56
56
  }
57
57
  class DynamicTextUtil {
58
58
  static isDynamicText(documentElement) {
59
- return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
60
- !!documentElement.propertyBindings &&
61
- !!documentElement.propertyBindingsMetaData);
59
+ var _a;
60
+ return (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' && !!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text);
62
61
  }
63
62
  static takesValueFromContainer(bindingProperty) {
64
63
  if (!bindingProperty) {
@@ -176,8 +175,9 @@ class DynamicTextUtil {
176
175
  bold,
177
176
  italic,
178
177
  };
179
- if (!dynamicTextElement.isTextTool) {
180
- measureTextSettings.width = size.width - padding * 2;
178
+ const fixedWidth = size.width - padding * 2;
179
+ if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
180
+ measureTextSettings.width = fixedWidth;
181
181
  }
182
182
  try {
183
183
  const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
@@ -222,7 +222,10 @@ class DynamicTextUtil {
222
222
  }
223
223
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
224
224
  displayFunction === DynamicTextDisplayFunction.MAX) {
225
- const present = memberValues.filter((e) => e !== null && e !== undefined);
225
+ const present = memberValues
226
+ .filter((e) => e !== null && e !== undefined && e !== '')
227
+ .map(Number)
228
+ .filter((e) => !Number.isNaN(e));
226
229
  if (!present.length) {
227
230
  return '';
228
231
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.a01d866",
3
+ "version": "2.4.0-alpha.c01727c",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",