@contrail/documents 1.21.0-alpha.fb2b49f → 1.21.0-alpha.fb70961

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,11 +1,10 @@
1
1
  import { DocumentElement, PositionDefinition } from '../types';
2
- import { ContainerElementType, ContainerKind } from './container-kind';
3
- import { DocumentContainer, MeasuredDocumentElement } from './document-container';
2
+ import { ContainerElementType } from './container-kind';
3
+ import { DocumentContainer } from './document-container';
4
4
  export declare class DocumentContainerIndex {
5
5
  private readonly data;
6
6
  constructor(data: {
7
7
  documentElementsById: Map<string, DocumentElement>;
8
- measuredById: Map<string, MeasuredDocumentElement>;
9
8
  containersById: Map<string, DocumentContainer>;
10
9
  containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
11
10
  memberIdsByContainerId: Map<string, string[]>;
@@ -18,7 +17,6 @@ export declare class DocumentContainerIndex {
18
17
  innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
19
18
  memberIdsOf(containerId: string): readonly string[];
20
19
  memberDocumentElementsOf(containerId: string): DocumentElement[];
21
- containerPathFor(documentElement: DocumentElement, kind: ContainerKind, at?: PositionDefinition): readonly string[];
22
20
  containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
23
21
  private containersOfType;
24
22
  private resolveAll;
@@ -9,7 +9,6 @@ class DocumentContainerIndex {
9
9
  static empty() {
10
10
  return new DocumentContainerIndex({
11
11
  documentElementsById: new Map(),
12
- measuredById: new Map(),
13
12
  containersById: new Map(),
14
13
  containerPathsByDocumentElementId: new Map(),
15
14
  memberIdsByContainerId: new Map(),
@@ -44,20 +43,6 @@ class DocumentContainerIndex {
44
43
  }
45
44
  return members;
46
45
  }
47
- containerPathFor(documentElement, kind, at) {
48
- var _a;
49
- if (!documentElement) {
50
- return [];
51
- }
52
- const known = this.data.measuredById.get(documentElement.id);
53
- const positioned = at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement;
54
- const measured = {
55
- documentElement: positioned,
56
- box: at || !known ? document_container_1.DocumentContainerUtil.measureBox(positioned, this.data.documentElementsById) : known.box,
57
- drawOrder: (_a = known === null || known === void 0 ? void 0 : known.drawOrder) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
58
- };
59
- return document_container_1.DocumentContainerUtil.pathFor(measured, kind, this.containersOfType(kind.elementType)).map((container) => container.id);
60
- }
61
46
  containerPathAtPoint(point, elementType) {
62
47
  var _a, _b;
63
48
  const containers = this.containersOfType(elementType);
@@ -25,9 +25,5 @@ export declare class DocumentContainerUtil {
25
25
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
26
26
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
27
27
  static chain(candidates: DocumentContainer[]): DocumentContainer[];
28
- static measureBox(documentElement: DocumentElement, documentElementsById: Map<string, DocumentElement>): CoordinateBox | null;
29
- static pathFor(measured: MeasuredDocumentElement, kind: ContainerKind, containers: DocumentContainer[]): DocumentContainer[];
30
- static enclosersOf(measured: MeasuredDocumentElement, containers: DocumentContainer[]): DocumentContainer[];
31
- static candidatesFor(measured: MeasuredDocumentElement, containers: DocumentContainer[]): DocumentContainer[];
32
28
  static topmost(containers: DocumentContainer[]): DocumentContainer[];
33
29
  }
@@ -24,12 +24,9 @@ class DocumentContainerUtil {
24
24
  var _a, _b, _c, _d, _e;
25
25
  const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
26
26
  const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
27
- if (!position) {
27
+ if (!position || !angle || !newSize || !documentElement.size) {
28
28
  return position;
29
29
  }
30
- if (!angle || !newSize || !documentElement.size) {
31
- return Object.assign({}, position);
32
- }
33
30
  const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
34
31
  const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
35
32
  const cornerOffset = (size) => {
@@ -39,8 +36,7 @@ class DocumentContainerUtil {
39
36
  };
40
37
  const before = cornerOffset(documentElement.size);
41
38
  const after = cornerOffset(newSize);
42
- const moved = { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
43
- return Number.isFinite(moved.x) && Number.isFinite(moved.y) ? moved : Object.assign({}, position);
39
+ return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
44
40
  }
45
41
  static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
46
42
  const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
@@ -83,56 +79,6 @@ class DocumentContainerUtil {
83
79
  path.unshift(topmostOf(enclosing));
84
80
  }
85
81
  }
86
- static measureBox(documentElement, documentElementsById) {
87
- var _a, _b;
88
- try {
89
- const start = ((_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
90
- const end = ((_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
91
- const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
92
- if (!width && !height && !documentElement.position) {
93
- return null;
94
- }
95
- return DocumentContainerUtil.toCoordinateBox(x, y, width, height);
96
- }
97
- catch (_c) {
98
- return null;
99
- }
100
- }
101
- static pathFor(measured, kind, containers) {
102
- if (!containers.length || !measured.box) {
103
- return [];
104
- }
105
- if (measured.documentElement.type === kind.elementType) {
106
- return kind.nests ? DocumentContainerUtil.chain(DocumentContainerUtil.enclosersOf(measured, containers)) : [];
107
- }
108
- const candidates = DocumentContainerUtil.candidatesFor(measured, containers);
109
- return kind.nests ? DocumentContainerUtil.chain(candidates) : DocumentContainerUtil.topmost(candidates);
110
- }
111
- static enclosersOf(measured, containers) {
112
- return containers.filter((container) => {
113
- var _a;
114
- return container.id !== measured.documentElement.id &&
115
- DocumentContainerUtil.encloses(container.box, measured.box) &&
116
- measured.drawOrder > container.drawOrder &&
117
- !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
118
- });
119
- }
120
- static candidatesFor(measured, containers) {
121
- const anchor = DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
122
- return containers.filter((container) => {
123
- var _a;
124
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
125
- return false;
126
- }
127
- if (!DocumentContainerUtil.containsPoint(container.box, anchor)) {
128
- return false;
129
- }
130
- if (DocumentContainerUtil.encloses(measured.box, container.box)) {
131
- return false;
132
- }
133
- return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
134
- });
135
- }
136
82
  static topmost(containers) {
137
83
  return containers.length
138
84
  ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
@@ -5,5 +5,9 @@ export declare class DocumentContainerService {
5
5
  static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
6
6
  static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
7
7
  private static measureDocumentElements;
8
+ private static measure;
8
9
  private static collectContainers;
10
+ private static resolvePath;
11
+ private static enclosersOf;
12
+ private static candidateContainers;
9
13
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentContainerService = void 0;
4
+ const document_element_factory_1 = require("../document-element-factory");
4
5
  const container_kind_1 = require("./container-kind");
5
6
  const document_container_index_1 = require("./document-container-index");
6
7
  const document_container_1 = require("./document-container");
@@ -25,7 +26,7 @@ class DocumentContainerService {
25
26
  for (const measured of measuredDocumentElements) {
26
27
  const byElementType = new Map();
27
28
  for (const kind of kinds) {
28
- byElementType.set(kind.elementType, document_container_1.DocumentContainerUtil.pathFor(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
29
+ byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
29
30
  }
30
31
  pathsByMeasured.set(measured, byElementType);
31
32
  }
@@ -51,13 +52,8 @@ class DocumentContainerService {
51
52
  }
52
53
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
53
54
  }
54
- const measuredById = new Map();
55
- for (const measured of measuredDocumentElements) {
56
- measuredById.set(measured.documentElement.id, measured);
57
- }
58
55
  return new document_container_index_1.DocumentContainerIndex({
59
56
  documentElementsById,
60
- measuredById,
61
57
  containersById,
62
58
  containerPathsByDocumentElementId,
63
59
  memberIdsByContainerId,
@@ -71,9 +67,21 @@ class DocumentContainerService {
71
67
  return documentElements.map((documentElement, drawOrder) => ({
72
68
  documentElement,
73
69
  drawOrder,
74
- box: document_container_1.DocumentContainerUtil.measureBox(documentElement, documentElementsById),
70
+ box: this.measure(documentElement, documentElementsById),
75
71
  }));
76
72
  }
73
+ static measure(documentElement, documentElementsById) {
74
+ var _a, _b;
75
+ try {
76
+ const start = ((_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
77
+ const end = ((_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
78
+ const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
79
+ return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
80
+ }
81
+ catch (_c) {
82
+ return null;
83
+ }
84
+ }
77
85
  static collectContainers(measuredDocumentElements, kind) {
78
86
  return measuredDocumentElements
79
87
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
@@ -85,5 +93,40 @@ class DocumentContainerService {
85
93
  drawOrder: measured.drawOrder,
86
94
  }));
87
95
  }
96
+ static resolvePath(measured, kind, containers) {
97
+ if (!containers.length || !measured.box) {
98
+ return [];
99
+ }
100
+ if (measured.documentElement.type === kind.elementType) {
101
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
102
+ }
103
+ const candidates = this.candidateContainers(measured, containers);
104
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
105
+ }
106
+ static enclosersOf(measured, containers) {
107
+ return containers.filter((container) => {
108
+ var _a;
109
+ return container.id !== measured.documentElement.id &&
110
+ document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
111
+ measured.drawOrder > container.drawOrder &&
112
+ !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
113
+ });
114
+ }
115
+ static candidateContainers(measured, containers) {
116
+ const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
117
+ return containers.filter((container) => {
118
+ var _a;
119
+ if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
120
+ return false;
121
+ }
122
+ if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
123
+ return false;
124
+ }
125
+ if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
126
+ return false;
127
+ }
128
+ return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
129
+ });
130
+ }
88
131
  }
89
132
  exports.DocumentContainerService = DocumentContainerService;
@@ -55,10 +55,7 @@ export declare class DynamicTextUtil {
55
55
  static isDynamicText(documentElement: DocumentElement): boolean;
56
56
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
57
57
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
58
- static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): {
59
- width: number;
60
- height: number;
61
- };
58
+ static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
62
59
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
63
60
  private static getItemCount;
64
61
  }
@@ -167,19 +167,16 @@ class DynamicTextUtil {
167
167
  return text;
168
168
  }
169
169
  static calculateSize(dynamicTextElement, entityType, text) {
170
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
171
- let size = {
172
- width: (_b = (_a = dynamicTextElement.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0,
173
- height: (_d = (_c = dynamicTextElement.size) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0,
174
- };
175
- const fontFamily = (_f = document_util_1.DocumentStyleUtil.getFirstFontFamily((_e = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _e !== void 0 ? _e : '')) !== null && _f !== void 0 ? _f : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
176
- const fontSize = (_j = (dynamicTextElement.isTextTool
177
- ? (_h = (_g = dynamicTextElement.style) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.size
178
- : document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _j !== void 0 ? _j : document_util_1.DEFAULT_TEXT_FONT_SIZE;
170
+ var _a, _b, _c, _d, _e;
171
+ let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
172
+ 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;
173
+ const fontSize = (_e = (dynamicTextElement.isTextTool
174
+ ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
175
+ : 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;
179
176
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
180
177
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
181
- const bold = document_util_1.DocumentStyleUtil.isBold((_k = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _k !== void 0 ? _k : '', fontFamily);
182
- const italic = document_util_1.DocumentStyleUtil.isItalic((_l = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _l !== void 0 ? _l : '');
178
+ const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
179
+ const italic = document_util_1.DocumentStyleUtil.isItalic(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text);
183
180
  const measureTextSettings = {
184
181
  fontFamily,
185
182
  fontSize: fontSizePx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.21.0-alpha.fb2b49f",
3
+ "version": "1.21.0-alpha.fb70961",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",