@contrail/documents 1.20.0-alpha.d734088 → 1.20.0
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 +6 -64
- package/lib/document-element-constants.d.ts +0 -3
- package/lib/document-element-constants.js +1 -22
- package/lib/document-element-factory.d.ts +0 -6
- package/lib/document-element-factory.js +0 -10
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -4
- package/lib/sort-index.d.ts +1 -0
- package/lib/sort-index.js +15 -2
- package/lib/sort-order-errors.d.ts +1 -1
- package/lib/sort-order-errors.js +1 -1
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +1 -2
- package/lib/util/dynamic-text/dynamic-text-util.js +22 -27
- package/package.json +1 -1
- package/lib/containers/container-kind.d.ts +0 -10
- package/lib/containers/container-kind.js +0 -7
- package/lib/containers/document-container-index.d.ts +0 -24
- package/lib/containers/document-container-index.js +0 -63
- package/lib/containers/document-container.d.ts +0 -23
- package/lib/containers/document-container.js +0 -43
- package/lib/containers/document-container.service.d.ts +0 -14
- package/lib/containers/document-container.service.js +0 -147
package/CHANGELOG.md
CHANGED
|
@@ -5,76 +5,18 @@ 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
|
-
## [1.20.0] - 2026-09-
|
|
8
|
+
## [1.20.0] - 2026-09-25
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- `DocumentContainerService.buildIndex` and `DocumentContainerIndex` — which containers hold which
|
|
13
|
-
elements, for one document, resolved once and read back by lookup. A container is a frame or a
|
|
14
|
-
section, described by a `ContainerKind` carrying `elementType`, `nests` and `layer`. An element
|
|
15
|
-
belongs to the container whose box covers its measured centre and which is drawn below it.
|
|
16
|
-
Nesting gives a path with one container per depth, the later-drawn one winning where two cross.
|
|
17
|
-
A container is only ever content of a kind layered behind it, so a frame belongs to a section and
|
|
18
|
-
a section never to a frame. Shapes wider and taller than the container, and groups holding it,
|
|
19
|
-
are excluded.
|
|
20
|
-
- `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
|
|
21
|
-
`document-element-constants`, so the rule above has one definition rather than one per app.
|
|
22
|
-
- `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
|
|
23
|
-
with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
|
|
24
|
-
which is what layout works in: `@contrail/document-table` places table members from it, and
|
|
25
|
-
scaling it moves a scaled member into a different cell. Anything deciding what an element overlaps
|
|
26
|
-
or sits on wants the scaled one.
|
|
27
|
-
|
|
28
|
-
### Deprecated
|
|
29
|
-
|
|
30
|
-
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
31
|
-
for what it decides: whether the binding's value comes from the container rather than a type
|
|
32
|
-
property. The old name still works and delegates to the new one.
|
|
33
|
-
|
|
34
|
-
### Fixed
|
|
35
|
-
|
|
36
|
-
- A dynamic text is now anchored at its position rather than its centre when deciding which
|
|
37
|
-
container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its size
|
|
38
|
-
comes from the value it resolves to, and that value depends on the container, so letting its width
|
|
39
|
-
feed membership meant its own text could choose its container: near an edge the two answers
|
|
40
|
-
disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
|
|
41
|
-
else still resolves on its centre.
|
|
42
|
-
- A dynamic text is also exempt from the oversized-shape exclusion, which keeps a shape wider and
|
|
43
|
-
taller than a container off it. That rule reads size too, so a dynamic text larger than its frame
|
|
44
|
-
in both directions had two self-consistent answers and kept whichever it started from. The rule
|
|
45
|
-
exists to keep a backdrop shape off a frame it covers, which is not what a dynamic text is doing.
|
|
46
|
-
- `min` and `max` rendered an infinity sign when every member value was empty. The early return
|
|
47
|
-
checked the list length before the empty values were filtered out, so `Math.min` of nothing
|
|
48
|
-
reached the formatter. Both now fall through to `n/a`.
|
|
49
|
-
- `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
|
|
50
|
-
the server failed the read for the whole document. It now measures from a zero size instead.
|
|
51
|
-
|
|
52
|
-
### Changed
|
|
53
|
-
|
|
54
|
-
- Container membership measures a scaled element from its scaled box, through the new
|
|
55
|
-
`getBoundingClientRectScaled` above. A scaled element previously measured at its unscaled size
|
|
56
|
-
and could resolve to the wrong container.
|
|
57
|
-
|
|
58
|
-
## [2.2.1] - 2026-09-15
|
|
59
|
-
|
|
60
|
-
### Changed
|
|
61
|
-
|
|
62
|
-
- The DESIGN-150 annotation-row collapse is reverted, to go out in a later release alongside the rest of the change. `calculateAnnotationHeight` returns its flat `fontSize + ANNOTATION_PADDING_Y` minimum again whether or not the row draws anything, and `getComponentSize` reserves a flat 18px row in every item card's height.
|
|
63
|
-
|
|
64
|
-
### Removed
|
|
65
|
-
|
|
66
|
-
- `ItemComponentService.isAnnotationRowEmpty` and `ItemComponentService.getAnnotationRowHeight`, both added in 2.2.0, and the optional `annotations` parameter they were reached through on `DocumentElementFactory.getBoundingClientRect` and `getSize`. Removed under a patch because 2.2.0 published hours earlier and nothing had consumed them: the canvas renderer mirrors the predicate privately rather than importing it, and every `contrail-apps` app pins this package on its 1.x range.
|
|
67
|
-
|
|
68
|
-
## [2.2.0] - 2026-09-15
|
|
10
|
+
Maintenance release on the 1.x line; the same change ships on 2.x as 2.3.0.
|
|
69
11
|
|
|
70
12
|
### Added
|
|
71
13
|
|
|
72
|
-
- `
|
|
73
|
-
- `ItemComponentService.getAnnotationRowHeight(annotationElement, annotations, width)` — the row's reserved height, wrapping onto further rows when the badges do not fit `width`, and `0` when the row is empty. Every creation path must size the row through here so a card laid out by the Item Chooser and one laid out by board generation agree.
|
|
14
|
+
- `isValidSortIndex(sortIndex)` — whether a value is a key `fractional-indexing` could have produced, so every client writing a sort index is held to one definition of valid rather than each caller inventing its own. `fractional-indexing` keeps its `validateOrderKey` private, so the check asks the generator to mint a key after the candidate: that path validates its bound first and cannot fail for any other reason. The generator's own grammar check ignores the digit alphabet, and accepts `a0!` or `a0 `, so the candidate is screened against the exported `BASE_62_DIGITS` first. Costs ~130ns for a short key and ~350ns for a 387-character one.
|
|
74
15
|
|
|
75
|
-
###
|
|
16
|
+
### Changed
|
|
76
17
|
|
|
77
|
-
- `
|
|
18
|
+
- `allElementsHaveSortIndex` now requires each element's key to be valid, not merely a non-empty string. Callers that treat an unkeyed collection as needing fresh keys — board snapshot restore is the one today — now also re-key a collection whose keys are present but malformed, instead of restoring ordering that cannot sort.
|
|
19
|
+
- `SortOrderErrorMessage.SORT_INDEX_NOT_USABLE` describes the real rule ("sortIndex must be a valid fractional index") rather than "must be a non-empty string". The `SORT_INDEX_NOT_USABLE` code is unchanged.
|
|
78
20
|
|
|
79
21
|
## [1.19.0] - 2026-09-11
|
|
80
22
|
|
|
@@ -3,6 +3,3 @@ 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,29 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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,12 +22,6 @@ 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
|
-
};
|
|
31
25
|
private static getPosition;
|
|
32
26
|
private static getSize;
|
|
33
27
|
private static getComponentSize;
|
|
@@ -216,16 +216,6 @@ 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
|
-
}
|
|
229
219
|
static getPosition(documentElement, startElement, endElement) {
|
|
230
220
|
var _a, _b;
|
|
231
221
|
if (documentElement.type === 'line' || documentElement.type === 'callout') {
|
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,3 @@ 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,7 +30,3 @@ __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);
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentElement } from './types';
|
|
2
|
+
export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
|
|
2
3
|
export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
|
|
3
4
|
export declare function buildKeyBetween(a: string | null, b: string | null): string;
|
|
4
5
|
export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
|
package/lib/sort-index.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSortIndex = isValidSortIndex;
|
|
3
4
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
5
|
exports.buildKeyBetween = buildKeyBetween;
|
|
5
6
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
6
7
|
exports.compareSortIndex = compareSortIndex;
|
|
7
8
|
const fractional_indexing_1 = require("fractional-indexing");
|
|
9
|
+
const SORT_INDEX_DIGITS = new RegExp(`^[${fractional_indexing_1.BASE_62_DIGITS.replace(/[\\\]^-]/g, (digit) => `\\${digit}`)}]+$`);
|
|
10
|
+
function isValidSortIndex(sortIndex) {
|
|
11
|
+
if (typeof sortIndex !== 'string' || !SORT_INDEX_DIGITS.test(sortIndex)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
(0, fractional_indexing_1.generateKeyBetween)(sortIndex, null);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
8
22
|
function allElementsHaveSortIndex(elements) {
|
|
9
|
-
return elements.every((element) =>
|
|
10
|
-
element.sortIndex.length > 0);
|
|
23
|
+
return elements.every((element) => isValidSortIndex(element.sortIndex));
|
|
11
24
|
}
|
|
12
25
|
function buildKeyBetween(a, b) {
|
|
13
26
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
@@ -6,5 +6,5 @@ export declare enum SortOrderErrorCode {
|
|
|
6
6
|
export declare enum SortOrderErrorMessage {
|
|
7
7
|
SORT_MIGRATION_IN_PROGRESS = "Sort order is being migrated for this document; editing is briefly locked",
|
|
8
8
|
SORT_MODE_MISMATCH = "Ordering write does not match the document's sort mode",
|
|
9
|
-
SORT_INDEX_NOT_USABLE = "sortIndex must be a
|
|
9
|
+
SORT_INDEX_NOT_USABLE = "sortIndex must be a valid fractional index"
|
|
10
10
|
}
|
package/lib/sort-order-errors.js
CHANGED
|
@@ -11,5 +11,5 @@ var SortOrderErrorMessage;
|
|
|
11
11
|
(function (SortOrderErrorMessage) {
|
|
12
12
|
SortOrderErrorMessage["SORT_MIGRATION_IN_PROGRESS"] = "Sort order is being migrated for this document; editing is briefly locked";
|
|
13
13
|
SortOrderErrorMessage["SORT_MODE_MISMATCH"] = "Ordering write does not match the document's sort mode";
|
|
14
|
-
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a
|
|
14
|
+
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a valid fractional index";
|
|
15
15
|
})(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
|
|
@@ -48,9 +48,8 @@ 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
|
-
static isDynamicText(documentElement: DocumentElement): boolean;
|
|
53
|
-
static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
|
|
54
53
|
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
|
|
55
54
|
static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
|
|
56
55
|
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
@@ -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,19 +51,14 @@ 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];
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
!!documentElement.propertyBindings &&
|
|
57
|
-
!!documentElement.propertyBindingsMetaData);
|
|
58
|
-
}
|
|
59
|
-
static takesValueFromContainer(bindingProperty) {
|
|
60
|
-
if (!bindingProperty) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
64
|
-
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
54
|
+
function isContainerBinding(bindingProperty) {
|
|
55
|
+
if (!bindingProperty) {
|
|
56
|
+
return false;
|
|
65
57
|
}
|
|
58
|
+
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
59
|
+
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
60
|
+
}
|
|
61
|
+
class DynamicTextUtil {
|
|
66
62
|
static getDynamicTextValue(dynamicTextElement, property, propertyLevel, container, componentModels, ownerReferenceModel = null) {
|
|
67
63
|
var _a, _b, _c, _d;
|
|
68
64
|
if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
|
|
@@ -154,12 +150,12 @@ class DynamicTextUtil {
|
|
|
154
150
|
return text;
|
|
155
151
|
}
|
|
156
152
|
static calculateSize(dynamicTextElement, entityType, text) {
|
|
157
|
-
var _a, _b, _c, _d
|
|
158
|
-
let size =
|
|
159
|
-
const fontFamily = (
|
|
160
|
-
const fontSize = (
|
|
161
|
-
? (
|
|
162
|
-
: document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null &&
|
|
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;
|
|
163
159
|
const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
|
|
164
160
|
const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
|
|
165
161
|
const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
|
|
@@ -173,7 +169,7 @@ class DynamicTextUtil {
|
|
|
173
169
|
italic,
|
|
174
170
|
};
|
|
175
171
|
if (!dynamicTextElement.isTextTool) {
|
|
176
|
-
measureTextSettings.width = size.width - padding * 2;
|
|
172
|
+
measureTextSettings.width = dynamicTextElement.size.width - padding * 2;
|
|
177
173
|
}
|
|
178
174
|
try {
|
|
179
175
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|
|
@@ -216,14 +212,13 @@ class DynamicTextUtil {
|
|
|
216
212
|
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
217
213
|
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
218
214
|
}
|
|
219
|
-
else if (displayFunction === DynamicTextDisplayFunction.MIN
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
text = formatter.formatValueForProperty(extreme, property);
|
|
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);
|
|
227
222
|
}
|
|
228
223
|
return text;
|
|
229
224
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
layer: number;
|
|
7
|
-
}
|
|
8
|
-
export declare const SECTION_KIND: ContainerKind;
|
|
9
|
-
export declare const FRAME_KIND: ContainerKind;
|
|
10
|
-
export declare const CONTAINER_KINDS: ContainerKind[];
|
|
@@ -1,7 +0,0 @@
|
|
|
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 = { 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 };
|
|
7
|
-
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
maxDepth(elementType: ContainerElementType): number;
|
|
21
|
-
private containersOfType;
|
|
22
|
-
private resolveAll;
|
|
23
|
-
private containerPath;
|
|
24
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
const covering = this.containersOfType(elementType).filter((container) => (0, document_container_1.containsPoint)(container.box, point));
|
|
39
|
-
return (0, document_container_1.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);
|
|
43
|
-
}
|
|
44
|
-
containersOfType(elementType) {
|
|
45
|
-
var _a;
|
|
46
|
-
return this.resolveAll((_a = this.data.containerIdsByElementType.get(elementType)) !== null && _a !== void 0 ? _a : []);
|
|
47
|
-
}
|
|
48
|
-
resolveAll(containerIds) {
|
|
49
|
-
const containers = [];
|
|
50
|
-
for (const containerId of containerIds) {
|
|
51
|
-
const container = this.data.containersById.get(containerId);
|
|
52
|
-
if (container) {
|
|
53
|
-
containers.push(container);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return containers;
|
|
57
|
-
}
|
|
58
|
-
containerPath(documentElementId, elementType) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.DocumentContainerIndex = DocumentContainerIndex;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CoordinateBox, DocumentElement, PositionDefinition } from '../types';
|
|
2
|
-
import { ContainerKind } from './container-kind';
|
|
3
|
-
export interface DocumentContainer {
|
|
4
|
-
id: string;
|
|
5
|
-
kind: ContainerKind;
|
|
6
|
-
name: string;
|
|
7
|
-
documentElement: DocumentElement;
|
|
8
|
-
box: CoordinateBox;
|
|
9
|
-
depth: number;
|
|
10
|
-
drawOrder: number;
|
|
11
|
-
}
|
|
12
|
-
export interface MeasuredDocumentElement {
|
|
13
|
-
documentElement: DocumentElement;
|
|
14
|
-
box: CoordinateBox | null;
|
|
15
|
-
drawOrder: number;
|
|
16
|
-
}
|
|
17
|
-
export declare function toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
|
|
18
|
-
export declare function centerOf(box: CoordinateBox): PositionDefinition;
|
|
19
|
-
export declare function anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
20
|
-
export declare function containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
21
|
-
export declare function encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
22
|
-
export declare function isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
|
|
23
|
-
export declare function topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCoordinateBox = toCoordinateBox;
|
|
4
|
-
exports.centerOf = centerOf;
|
|
5
|
-
exports.anchorOf = anchorOf;
|
|
6
|
-
exports.containsPoint = containsPoint;
|
|
7
|
-
exports.encloses = encloses;
|
|
8
|
-
exports.isWiderAndTallerThan = isWiderAndTallerThan;
|
|
9
|
-
exports.topmostPerDepth = topmostPerDepth;
|
|
10
|
-
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
11
|
-
function toCoordinateBox(x, y, width, height) {
|
|
12
|
-
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
13
|
-
}
|
|
14
|
-
function centerOf(box) {
|
|
15
|
-
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
16
|
-
}
|
|
17
|
-
function anchorOf(documentElement, box) {
|
|
18
|
-
return dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement) ? { x: box.left, y: box.top } : centerOf(box);
|
|
19
|
-
}
|
|
20
|
-
function containsPoint(box, point) {
|
|
21
|
-
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
22
|
-
}
|
|
23
|
-
function encloses(outer, inner) {
|
|
24
|
-
const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
|
|
25
|
-
const identical = outer.left === inner.left &&
|
|
26
|
-
outer.right === inner.right &&
|
|
27
|
-
outer.top === inner.top &&
|
|
28
|
-
outer.bottom === inner.bottom;
|
|
29
|
-
return covers && !identical;
|
|
30
|
-
}
|
|
31
|
-
function isWiderAndTallerThan(box, other) {
|
|
32
|
-
return box.width > other.width && box.height > other.height;
|
|
33
|
-
}
|
|
34
|
-
function topmostPerDepth(containers) {
|
|
35
|
-
const byDepth = [];
|
|
36
|
-
for (const container of containers) {
|
|
37
|
-
const existing = byDepth[container.depth];
|
|
38
|
-
if (!existing || container.drawOrder > existing.drawOrder) {
|
|
39
|
-
byDepth[container.depth] = container;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return byDepth.filter(Boolean);
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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 buildNesting;
|
|
10
|
-
private static resolveContainerPath;
|
|
11
|
-
private static resolveInnermostOnTop;
|
|
12
|
-
private static toContainerPath;
|
|
13
|
-
private static candidateContainers;
|
|
14
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
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 dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
6
|
-
const document_element_constants_1 = require("../document-element-constants");
|
|
7
|
-
const container_kind_1 = require("./container-kind");
|
|
8
|
-
const document_container_index_1 = require("./document-container-index");
|
|
9
|
-
const document_container_1 = require("./document-container");
|
|
10
|
-
class DocumentContainerService {
|
|
11
|
-
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
12
|
-
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 containersById = new Map();
|
|
15
|
-
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));
|
|
19
|
-
});
|
|
20
|
-
const containerPathsByDocumentElementId = new Map();
|
|
21
|
-
const memberIdsByContainerId = new Map();
|
|
22
|
-
for (const measured of measuredDocumentElements) {
|
|
23
|
-
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);
|
|
28
|
-
for (const containerId of path) {
|
|
29
|
-
const members = memberIdsByContainerId.get(containerId);
|
|
30
|
-
if (members) {
|
|
31
|
-
members.push(documentElementId);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
memberIdsByContainerId.set(containerId, [documentElementId]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
39
|
-
}
|
|
40
|
-
return new document_container_index_1.DocumentContainerIndex({
|
|
41
|
-
documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
|
|
42
|
-
containersById,
|
|
43
|
-
containerPathsByDocumentElementId,
|
|
44
|
-
memberIdsByContainerId,
|
|
45
|
-
containerIdsByElementType,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
49
|
-
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
50
|
-
}
|
|
51
|
-
static measureDocumentElements(documentElements) {
|
|
52
|
-
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
53
|
-
return documentElements.map((documentElement, drawOrder) => ({
|
|
54
|
-
documentElement,
|
|
55
|
-
drawOrder,
|
|
56
|
-
box: this.measure(documentElement, documentElementsById),
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
static measure(documentElement, documentElementsById) {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
66
|
-
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
67
|
-
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
|
|
68
|
-
return (0, document_container_1.toCoordinateBox)(x, y, width, height);
|
|
69
|
-
}
|
|
70
|
-
catch (_c) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
static buildNesting(measuredDocumentElements, kind) {
|
|
75
|
-
const containers = measuredDocumentElements
|
|
76
|
-
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
77
|
-
.map((measured) => ({
|
|
78
|
-
id: measured.documentElement.id,
|
|
79
|
-
kind,
|
|
80
|
-
name: measured.documentElement.name,
|
|
81
|
-
documentElement: measured.documentElement,
|
|
82
|
-
box: measured.box,
|
|
83
|
-
depth: 0,
|
|
84
|
-
drawOrder: measured.drawOrder,
|
|
85
|
-
}));
|
|
86
|
-
const ancestorsById = new Map();
|
|
87
|
-
for (const container of containers) {
|
|
88
|
-
const ancestors = kind.nests
|
|
89
|
-
? containers.filter((other) => other !== container && (0, document_container_1.encloses)(other.box, container.box))
|
|
90
|
-
: [];
|
|
91
|
-
ancestorsById.set(container.id, ancestors);
|
|
92
|
-
container.depth = ancestors.length;
|
|
93
|
-
}
|
|
94
|
-
return { containers, ancestorsById };
|
|
95
|
-
}
|
|
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) {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
|
|
102
|
-
if (ownKind) {
|
|
103
|
-
if (ownKind.elementType === kind.elementType) {
|
|
104
|
-
return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
|
|
105
|
-
}
|
|
106
|
-
if (kind.layer > ownKind.layer) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
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]);
|
|
118
|
-
}
|
|
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 (0, document_container_1.topmostPerDepth)(containers).map((container) => container.id);
|
|
127
|
-
}
|
|
128
|
-
static candidateContainers(measured, containers) {
|
|
129
|
-
const anchor = (0, document_container_1.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
|
-
return containers.filter((container) => {
|
|
133
|
-
var _a;
|
|
134
|
-
if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
if (!(0, document_container_1.containsPoint)(container.box, anchor)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
if (isShape && (0, document_container_1.isWiderAndTallerThan)(measured.box, container.box)) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.DocumentContainerService = DocumentContainerService;
|