@contrail/documents 2.4.0-alpha.86639ad → 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.
@@ -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;
@@ -42,9 +42,6 @@ class DocumentContainerIndex {
42
42
  const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
43
43
  return path.map((container) => container.id);
44
44
  }
45
- maxDepth(elementType) {
46
- return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
47
- }
48
45
  containersOfType(elementType) {
49
46
  var _a;
50
47
  return this.resolveAll((_a = this.data.containerIdsByElementType.get(elementType)) !== null && _a !== void 0 ? _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 {
@@ -22,7 +20,6 @@ export declare class DocumentContainerUtil {
22
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
23
  static chain(candidates: DocumentContainer[]): DocumentContainer[];
27
24
  static topmost(containers: DocumentContainer[]): DocumentContainer[];
28
25
  }
@@ -58,24 +58,19 @@ 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
61
  static chain(candidates) {
65
62
  if (!candidates.length) {
66
63
  return [];
67
64
  }
68
- const innermostOf = (of) => of
69
- .filter((container) => !of.some((other) => other !== container && this.encloses(container.box, other.box)))
70
- .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
71
- const path = [innermostOf(candidates)];
65
+ const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
66
+ const path = [topmostOf(candidates)];
72
67
  for (;;) {
73
68
  const current = path[0];
74
69
  const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
75
70
  if (!enclosing.length) {
76
71
  return path;
77
72
  }
78
- path.unshift(innermostOf(enclosing));
73
+ path.unshift(topmostOf(enclosing));
79
74
  }
80
75
  }
81
76
  static topmost(containers) {
@@ -2,17 +2,14 @@
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) {
12
- var _a, _b, _c, _d;
10
+ var _a, _b;
13
11
  const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
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)]));
12
+ const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
16
13
  const containersById = new Map();
17
14
  const containerIdsByElementType = new Map();
18
15
  containersByElementType.forEach((containers, elementType) => {
@@ -22,17 +19,11 @@ class DocumentContainerService {
22
19
  const pathsByMeasured = new Map();
23
20
  for (const measured of measuredDocumentElements) {
24
21
  const byElementType = new Map();
25
- for (const kind of kindsByLayer) {
22
+ for (const kind of kinds) {
26
23
  byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
27
24
  }
28
25
  pathsByMeasured.set(measured, byElementType);
29
26
  }
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 = pathsByMeasured.get(measured)) === null || _b === void 0 ? void 0 : _b.get(container.kind.elementType)) !== null && _c !== void 0 ? _c : []).length;
34
- }
35
- }
36
27
  const measuredById = new Map();
37
28
  for (const measured of measuredDocumentElements) {
38
29
  if (!measuredById.has(measured.documentElement.id)) {
@@ -44,7 +35,7 @@ class DocumentContainerService {
44
35
  for (const measured of measuredDocumentElements) {
45
36
  const documentElementId = measured.documentElement.id;
46
37
  const pathsByElementType = new Map();
47
- ((_d = pathsByMeasured.get(measured)) !== null && _d !== void 0 ? _d : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
38
+ ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
48
39
  for (const path of pathsByElementType.values()) {
49
40
  for (const containerId of path) {
50
41
  const members = memberIdsByContainerId.get(containerId);
@@ -98,10 +89,8 @@ class DocumentContainerService {
98
89
  .map((measured) => ({
99
90
  id: measured.documentElement.id,
100
91
  kind,
101
- name: measured.documentElement.name,
102
92
  documentElement: measured.documentElement,
103
93
  box: measured.box,
104
- depth: 0,
105
94
  drawOrder: measured.drawOrder,
106
95
  }));
107
96
  }
@@ -114,7 +103,7 @@ class DocumentContainerService {
114
103
  if (ownKind.elementType === kind.elementType) {
115
104
  return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
116
105
  }
117
- if (kind.layer > ownKind.layer) {
106
+ if (!ownKind.canBeContentOf.includes(kind.elementType)) {
118
107
  return [];
119
108
  }
120
109
  }
@@ -132,8 +121,6 @@ class DocumentContainerService {
132
121
  }
133
122
  static candidateContainers(measured, containers) {
134
123
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
135
- const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
136
- !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
137
124
  return containers.filter((container) => {
138
125
  var _a;
139
126
  if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
@@ -142,7 +129,7 @@ class DocumentContainerService {
142
129
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
143
130
  return false;
144
131
  }
145
- if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
132
+ if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
146
133
  return false;
147
134
  }
148
135
  return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.86639ad",
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",