@contrail/documents 1.20.0 → 1.21.0-alpha.0c990fd
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 +57 -0
- package/lib/containers/container-kind.d.ts +9 -0
- package/lib/containers/container-kind.js +7 -0
- package/lib/containers/document-container-index.d.ts +24 -0
- package/lib/containers/document-container-index.js +73 -0
- package/lib/containers/document-container.d.ts +29 -0
- package/lib/containers/document-container.js +92 -0
- package/lib/containers/document-container.service.d.ts +13 -0
- package/lib/containers/document-container.service.js +135 -0
- package/lib/document-element-constants.d.ts +3 -0
- package/lib/document-element-constants.js +22 -1
- package/lib/document-element-factory.d.ts +6 -0
- package/lib/document-element-factory.js +10 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +8 -1
- package/lib/util/dynamic-text/dynamic-text-util.js +51 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,63 @@ 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.21.0] - 2026-09-26
|
|
9
|
+
|
|
10
|
+
Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `DocumentContainerService.buildIndex` and `DocumentContainerIndex` — which containers hold which
|
|
15
|
+
elements, for one document, resolved once and read back by lookup. A container is a frame or a
|
|
16
|
+
section; membership is geometry, draw order and kind, with nothing inherited and nothing stored.
|
|
17
|
+
The rule is written out in `src/containers/DOCUMENT_CONTAINERS_SPEC.md`, which the code is
|
|
18
|
+
measured against.
|
|
19
|
+
- `DocumentContainerUtil` — the container geometry as statics. `anchorFor` answers "which point is
|
|
20
|
+
this element placed by" for a caller holding an element rather than a measured box, and
|
|
21
|
+
`resizeKeepingAnchor` returns the size a new value needs with the position that keeps that point
|
|
22
|
+
still. Applying one without the other drags the corner membership reads.
|
|
23
|
+
- `SECTION_ELEMENT_TYPE` and `FRAME_ELEMENT_TYPE` in `document-element-constants`, alongside
|
|
24
|
+
`SHAPE_ELEMENT_TYPES`, which moved here for the board's shape handling.
|
|
25
|
+
- `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
|
|
26
|
+
with `scale` applied. `getBoundingClientRect` still returns the unscaled box, which is what layout
|
|
27
|
+
works in: `@contrail/document-table` places table members from it, and scaling it moves a scaled
|
|
28
|
+
member into a different cell. Anything deciding what an element overlaps or sits on wants the
|
|
29
|
+
scaled one.
|
|
30
|
+
|
|
31
|
+
### Deprecated
|
|
32
|
+
|
|
33
|
+
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
34
|
+
for what it decides. The old name still works and delegates to the new one.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- A dynamic text is anchored at its drawn top-left corner rather than its centre. Its size comes
|
|
39
|
+
from the value it resolves to and that value comes from its container, so an anchor that moved
|
|
40
|
+
with the size let the two choose each other: near an edge they never settled, flipping between a
|
|
41
|
+
value and "Move to a frame" on every read. The corner is the rotated one, so a text turned on its
|
|
42
|
+
side anchors where it appears (VIBE-9567).
|
|
43
|
+
- `isDynamicText` requires a `propertyBindings.text` binding, the one the value is read from. The
|
|
44
|
+
text tool creates an element with empty bindings and empty metadata, both truthy, so an
|
|
45
|
+
unconfigured text was anchored at its corner while the canvas centred it.
|
|
46
|
+
- An element covering a container is not inside it, whatever its type. The rule it replaces looked
|
|
47
|
+
only at shapes wider and taller than the container, so a background image joined the frame it
|
|
48
|
+
covered.
|
|
49
|
+
- A line or callout is measured from the elements it connects even with no stored `position`, where
|
|
50
|
+
it was previously left out of the index entirely.
|
|
51
|
+
- `min` and `max` rendered an infinity sign when every member value was empty; both fall through to
|
|
52
|
+
`n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
|
|
53
|
+
the server failed the read for the whole document.
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- `anchorFor` and the index measure through the same factory call, so a caller holding an element
|
|
58
|
+
gets the answer the index would give it. Reading `size` directly disagreed for the types whose box
|
|
59
|
+
is not position plus size.
|
|
60
|
+
- A container path is a containment chain, walked outward from the container the element sits on, so
|
|
61
|
+
two containers that merely cross no longer both claim it.
|
|
62
|
+
- `buildIndex` scans element types before measuring, so a document with no containers of the kinds
|
|
63
|
+
asked for returns an empty index without a geometry pass.
|
|
64
|
+
|
|
8
65
|
## [1.20.0] - 2026-09-25
|
|
9
66
|
|
|
10
67
|
Maintenance release on the 1.x line; the same change ships on 2.x as 2.3.0.
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
7
|
+
export declare const SECTION_KIND: ContainerKind;
|
|
8
|
+
export declare const FRAME_KIND: ContainerKind;
|
|
9
|
+
export declare const CONTAINER_KINDS: ContainerKind[];
|
|
@@ -0,0 +1,7 @@
|
|
|
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 };
|
|
6
|
+
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false };
|
|
7
|
+
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
static empty(): DocumentContainerIndex;
|
|
14
|
+
getContainer(containerId: string): DocumentContainer | null;
|
|
15
|
+
containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
|
|
16
|
+
containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
|
|
17
|
+
innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
|
|
18
|
+
memberIdsOf(containerId: string): readonly string[];
|
|
19
|
+
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
20
|
+
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
|
|
21
|
+
private containersOfType;
|
|
22
|
+
private resolveAll;
|
|
23
|
+
private containerPath;
|
|
24
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
static empty() {
|
|
10
|
+
return new DocumentContainerIndex({
|
|
11
|
+
documentElementsById: new Map(),
|
|
12
|
+
containersById: new Map(),
|
|
13
|
+
containerPathsByDocumentElementId: new Map(),
|
|
14
|
+
memberIdsByContainerId: new Map(),
|
|
15
|
+
containerIdsByElementType: new Map(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
getContainer(containerId) {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
|
|
21
|
+
}
|
|
22
|
+
containersOf(documentElementId, elementType) {
|
|
23
|
+
return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
|
|
24
|
+
}
|
|
25
|
+
containerIdsOf(documentElementId, elementType) {
|
|
26
|
+
return [...this.containerPath(documentElementId, elementType)];
|
|
27
|
+
}
|
|
28
|
+
innermostContainerIdOf(documentElementId, elementType) {
|
|
29
|
+
const path = this.containerPath(documentElementId, elementType);
|
|
30
|
+
return path.length ? path[path.length - 1] : null;
|
|
31
|
+
}
|
|
32
|
+
memberIdsOf(containerId) {
|
|
33
|
+
var _a;
|
|
34
|
+
return [...((_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [])];
|
|
35
|
+
}
|
|
36
|
+
memberDocumentElementsOf(containerId) {
|
|
37
|
+
const members = [];
|
|
38
|
+
for (const memberId of this.memberIdsOf(containerId)) {
|
|
39
|
+
const member = this.data.documentElementsById.get(memberId);
|
|
40
|
+
if (member) {
|
|
41
|
+
members.push(member);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return members;
|
|
45
|
+
}
|
|
46
|
+
containerPathAtPoint(point, elementType) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const containers = this.containersOfType(elementType);
|
|
49
|
+
const covering = containers.filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
|
|
50
|
+
const nests = (_b = (_a = containers[0]) === null || _a === void 0 ? void 0 : _a.kind.nests) !== null && _b !== void 0 ? _b : true;
|
|
51
|
+
const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
|
|
52
|
+
return path.map((container) => container.id);
|
|
53
|
+
}
|
|
54
|
+
containersOfType(elementType) {
|
|
55
|
+
var _a;
|
|
56
|
+
return this.resolveAll((_a = this.data.containerIdsByElementType.get(elementType)) !== null && _a !== void 0 ? _a : []);
|
|
57
|
+
}
|
|
58
|
+
resolveAll(containerIds) {
|
|
59
|
+
const containers = [];
|
|
60
|
+
for (const containerId of containerIds) {
|
|
61
|
+
const container = this.data.containersById.get(containerId);
|
|
62
|
+
if (container) {
|
|
63
|
+
containers.push(container);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return containers;
|
|
67
|
+
}
|
|
68
|
+
containerPath(documentElementId, elementType) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.DocumentContainerIndex = DocumentContainerIndex;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CoordinateBox, DocumentElement, PositionDefinition, SizeDefinition } from '../types';
|
|
2
|
+
import { ContainerKind } from './container-kind';
|
|
3
|
+
export interface DocumentContainer {
|
|
4
|
+
id: string;
|
|
5
|
+
kind: ContainerKind;
|
|
6
|
+
documentElement: DocumentElement;
|
|
7
|
+
box: CoordinateBox;
|
|
8
|
+
drawOrder: number;
|
|
9
|
+
}
|
|
10
|
+
export interface MeasuredDocumentElement {
|
|
11
|
+
documentElement: DocumentElement;
|
|
12
|
+
box: CoordinateBox | null;
|
|
13
|
+
drawOrder: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class DocumentContainerUtil {
|
|
16
|
+
static toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
|
|
17
|
+
static centerOf(box: CoordinateBox): PositionDefinition;
|
|
18
|
+
static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
19
|
+
static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
|
|
20
|
+
static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
|
|
21
|
+
size: SizeDefinition;
|
|
22
|
+
position: PositionDefinition;
|
|
23
|
+
};
|
|
24
|
+
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
|
|
25
|
+
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
26
|
+
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
27
|
+
static chain(candidates: DocumentContainer[]): DocumentContainer[];
|
|
28
|
+
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentContainerUtil = void 0;
|
|
4
|
+
const rotation_math_1 = require("../util/mask/rotation-math");
|
|
5
|
+
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
6
|
+
const document_element_factory_1 = require("../document-element-factory");
|
|
7
|
+
class DocumentContainerUtil {
|
|
8
|
+
static toCoordinateBox(x, y, width, height) {
|
|
9
|
+
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
10
|
+
}
|
|
11
|
+
static centerOf(box) {
|
|
12
|
+
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
13
|
+
}
|
|
14
|
+
static anchorOf(documentElement, box) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
|
|
17
|
+
return DocumentContainerUtil.centerOf(box);
|
|
18
|
+
}
|
|
19
|
+
const angle = (_a = documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
20
|
+
const corner = { x: box.left, y: box.top };
|
|
21
|
+
return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, DocumentContainerUtil.centerOf(box)) : corner;
|
|
22
|
+
}
|
|
23
|
+
static positionKeepingAnchor(documentElement, newSize) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
26
|
+
const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
27
|
+
if (!position) {
|
|
28
|
+
return position;
|
|
29
|
+
}
|
|
30
|
+
if (!angle || !newSize || !documentElement.size) {
|
|
31
|
+
return Object.assign({}, position);
|
|
32
|
+
}
|
|
33
|
+
const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
|
|
34
|
+
const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
|
|
35
|
+
const cornerOffset = (size) => {
|
|
36
|
+
const half = { x: (size.width * scaleX) / 2, y: (size.height * scaleY) / 2 };
|
|
37
|
+
const turned = (0, rotation_math_1.rotatePoint)(half, angle);
|
|
38
|
+
return { x: half.x - turned.x, y: half.y - turned.y };
|
|
39
|
+
};
|
|
40
|
+
const before = cornerOffset(documentElement.size);
|
|
41
|
+
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);
|
|
44
|
+
}
|
|
45
|
+
static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
|
|
46
|
+
const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
|
|
47
|
+
return { size, position: DocumentContainerUtil.positionKeepingAnchor(dynamicTextElement, size) };
|
|
48
|
+
}
|
|
49
|
+
static anchorFor(documentElement, position, startElement, endElement) {
|
|
50
|
+
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
51
|
+
try {
|
|
52
|
+
const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
|
|
53
|
+
const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
|
|
54
|
+
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
55
|
+
}
|
|
56
|
+
catch (_a) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static containsPoint(box, point) {
|
|
61
|
+
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
62
|
+
}
|
|
63
|
+
static encloses(outer, inner) {
|
|
64
|
+
const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
|
|
65
|
+
const identical = outer.left === inner.left &&
|
|
66
|
+
outer.right === inner.right &&
|
|
67
|
+
outer.top === inner.top &&
|
|
68
|
+
outer.bottom === inner.bottom;
|
|
69
|
+
return covers && !identical;
|
|
70
|
+
}
|
|
71
|
+
static chain(candidates) {
|
|
72
|
+
if (!candidates.length) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
76
|
+
const path = [topmostOf(candidates)];
|
|
77
|
+
for (;;) {
|
|
78
|
+
const current = path[0];
|
|
79
|
+
const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
|
|
80
|
+
if (!enclosing.length) {
|
|
81
|
+
return path;
|
|
82
|
+
}
|
|
83
|
+
path.unshift(topmostOf(enclosing));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
static topmost(containers) {
|
|
87
|
+
return containers.length
|
|
88
|
+
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
89
|
+
: [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.DocumentContainerUtil = DocumentContainerUtil;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 collectContainers;
|
|
10
|
+
private static resolvePath;
|
|
11
|
+
private static enclosersOf;
|
|
12
|
+
private static candidateContainers;
|
|
13
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 container_kind_1 = require("./container-kind");
|
|
6
|
+
const document_container_index_1 = require("./document-container-index");
|
|
7
|
+
const document_container_1 = require("./document-container");
|
|
8
|
+
class DocumentContainerService {
|
|
9
|
+
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
|
|
12
|
+
const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
|
|
13
|
+
if (!elements.some((element) => containerElementTypes.has(element.type))) {
|
|
14
|
+
return document_container_index_1.DocumentContainerIndex.empty();
|
|
15
|
+
}
|
|
16
|
+
const documentElementsById = new Map(elements.map((element) => [element.id, element]));
|
|
17
|
+
const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
|
|
18
|
+
const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
19
|
+
const containersById = new Map();
|
|
20
|
+
const containerIdsByElementType = new Map();
|
|
21
|
+
containersByElementType.forEach((containers, elementType) => {
|
|
22
|
+
containerIdsByElementType.set(elementType, containers.map((container) => container.id));
|
|
23
|
+
containers.forEach((container) => containersById.set(container.id, container));
|
|
24
|
+
});
|
|
25
|
+
const pathsByMeasured = new Map();
|
|
26
|
+
for (const measured of measuredDocumentElements) {
|
|
27
|
+
const byElementType = new Map();
|
|
28
|
+
for (const kind of kinds) {
|
|
29
|
+
byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
30
|
+
}
|
|
31
|
+
pathsByMeasured.set(measured, byElementType);
|
|
32
|
+
}
|
|
33
|
+
const containerPathsByDocumentElementId = new Map();
|
|
34
|
+
const memberIdsByContainerId = new Map();
|
|
35
|
+
const memberIdsSeen = new Map();
|
|
36
|
+
for (const measured of measuredDocumentElements) {
|
|
37
|
+
const documentElementId = measured.documentElement.id;
|
|
38
|
+
const pathsByElementType = new Map();
|
|
39
|
+
((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
40
|
+
for (const path of pathsByElementType.values()) {
|
|
41
|
+
for (const containerId of path) {
|
|
42
|
+
const seen = memberIdsSeen.get(containerId);
|
|
43
|
+
if (!seen) {
|
|
44
|
+
memberIdsSeen.set(containerId, new Set([documentElementId]));
|
|
45
|
+
memberIdsByContainerId.set(containerId, [documentElementId]);
|
|
46
|
+
}
|
|
47
|
+
else if (!seen.has(documentElementId)) {
|
|
48
|
+
seen.add(documentElementId);
|
|
49
|
+
memberIdsByContainerId.get(containerId).push(documentElementId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
54
|
+
}
|
|
55
|
+
return new document_container_index_1.DocumentContainerIndex({
|
|
56
|
+
documentElementsById,
|
|
57
|
+
containersById,
|
|
58
|
+
containerPathsByDocumentElementId,
|
|
59
|
+
memberIdsByContainerId,
|
|
60
|
+
containerIdsByElementType,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
64
|
+
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
65
|
+
}
|
|
66
|
+
static measureDocumentElements(documentElements, documentElementsById) {
|
|
67
|
+
return documentElements.map((documentElement, drawOrder) => ({
|
|
68
|
+
documentElement,
|
|
69
|
+
drawOrder,
|
|
70
|
+
box: this.measure(documentElement, documentElementsById),
|
|
71
|
+
}));
|
|
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
|
+
if (!width && !height && !documentElement.position) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
|
|
83
|
+
}
|
|
84
|
+
catch (_c) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
static collectContainers(measuredDocumentElements, kind) {
|
|
89
|
+
return measuredDocumentElements
|
|
90
|
+
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
91
|
+
.map((measured) => ({
|
|
92
|
+
id: measured.documentElement.id,
|
|
93
|
+
kind,
|
|
94
|
+
documentElement: measured.documentElement,
|
|
95
|
+
box: measured.box,
|
|
96
|
+
drawOrder: measured.drawOrder,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
static resolvePath(measured, kind, containers) {
|
|
100
|
+
if (!containers.length || !measured.box) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
if (measured.documentElement.type === kind.elementType) {
|
|
104
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
105
|
+
}
|
|
106
|
+
const candidates = this.candidateContainers(measured, containers);
|
|
107
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
108
|
+
}
|
|
109
|
+
static enclosersOf(measured, containers) {
|
|
110
|
+
return containers.filter((container) => {
|
|
111
|
+
var _a;
|
|
112
|
+
return container.id !== measured.documentElement.id &&
|
|
113
|
+
document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
|
|
114
|
+
measured.drawOrder > container.drawOrder &&
|
|
115
|
+
!((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
static candidateContainers(measured, containers) {
|
|
119
|
+
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
120
|
+
return containers.filter((container) => {
|
|
121
|
+
var _a;
|
|
122
|
+
if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.DocumentContainerService = DocumentContainerService;
|
|
@@ -3,3 +3,6 @@ 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,8 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ANNOTATION_PADDING_Y = exports.ANNOTATION_IMG_SIZE = void 0;
|
|
3
|
+
exports.SHAPE_ELEMENT_TYPES = exports.FRAME_ELEMENT_TYPE = exports.SECTION_ELEMENT_TYPE = 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,6 +22,12 @@ 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
|
+
};
|
|
25
31
|
private static getPosition;
|
|
26
32
|
private static getSize;
|
|
27
33
|
private static getComponentSize;
|
|
@@ -216,6 +216,16 @@ 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
|
+
}
|
|
219
229
|
static getPosition(documentElement, startElement, endElement) {
|
|
220
230
|
var _a, _b;
|
|
221
231
|
if (documentElement.type === 'line' || documentElement.type === 'callout') {
|
package/lib/index.d.ts
CHANGED
|
@@ -14,3 +14,7 @@ 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,3 +30,7 @@ __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);
|
|
@@ -27,6 +27,8 @@ export declare enum DynamicTextDisplayFunction {
|
|
|
27
27
|
export declare const MOVE_TO_FRAME_TEXT = "Move to a frame";
|
|
28
28
|
export declare const MOVE_TO_SECTION_TEXT = "Move to a section";
|
|
29
29
|
export declare const CLICK_TO_CONFIGURE = "Click to configure";
|
|
30
|
+
export declare function placeholderForMissingContainer(entityType: string): string;
|
|
31
|
+
export declare function isPlaceholderText(text: string): boolean;
|
|
30
32
|
export declare const HARD_CODED_TEXT: {
|
|
31
33
|
'project.name': string;
|
|
32
34
|
'project.createdBy.email': string;
|
|
@@ -50,8 +52,13 @@ export declare const HARD_CODED_TEXT: {
|
|
|
50
52
|
};
|
|
51
53
|
export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
|
|
52
54
|
export declare class DynamicTextUtil {
|
|
55
|
+
static isDynamicText(documentElement: DocumentElement): boolean;
|
|
56
|
+
static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
|
|
53
57
|
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
|
|
54
|
-
static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string):
|
|
58
|
+
static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
55
62
|
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
56
63
|
private static getItemCount;
|
|
57
64
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
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.placeholderForMissingContainer = placeholderForMissingContainer;
|
|
5
|
+
exports.isPlaceholderText = isPlaceholderText;
|
|
4
6
|
exports.isContainerBinding = isContainerBinding;
|
|
5
7
|
const types_1 = require("@contrail/types");
|
|
6
8
|
const util_1 = require("@contrail/util");
|
|
@@ -28,6 +30,12 @@ var DynamicTextDisplayFunction;
|
|
|
28
30
|
exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
|
|
29
31
|
exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
|
|
30
32
|
exports.CLICK_TO_CONFIGURE = 'Click to configure';
|
|
33
|
+
function placeholderForMissingContainer(entityType) {
|
|
34
|
+
return entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
|
|
35
|
+
}
|
|
36
|
+
function isPlaceholderText(text) {
|
|
37
|
+
return text === exports.MOVE_TO_FRAME_TEXT || text === exports.MOVE_TO_SECTION_TEXT || text === exports.CLICK_TO_CONFIGURE;
|
|
38
|
+
}
|
|
31
39
|
exports.HARD_CODED_TEXT = {
|
|
32
40
|
'project.name': 'Project name',
|
|
33
41
|
'project.createdBy.email': 'Project created by',
|
|
@@ -52,13 +60,22 @@ exports.HARD_CODED_TEXT = {
|
|
|
52
60
|
const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
|
|
53
61
|
const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
|
|
54
62
|
function isContainerBinding(bindingProperty) {
|
|
55
|
-
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
59
|
-
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
63
|
+
return DynamicTextUtil.takesValueFromContainer(bindingProperty);
|
|
60
64
|
}
|
|
61
65
|
class DynamicTextUtil {
|
|
66
|
+
static isDynamicText(documentElement) {
|
|
67
|
+
var _a;
|
|
68
|
+
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
69
|
+
!!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text) &&
|
|
70
|
+
!!documentElement.propertyBindingsMetaData);
|
|
71
|
+
}
|
|
72
|
+
static takesValueFromContainer(bindingProperty) {
|
|
73
|
+
if (!bindingProperty) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const [entityType, propertySlug] = bindingProperty.split('.');
|
|
77
|
+
return CONTAINER_SOURCES.includes(entityType) && CONTAINER_PROPERTY_SLUGS.includes(propertySlug);
|
|
78
|
+
}
|
|
62
79
|
static getDynamicTextValue(dynamicTextElement, property, propertyLevel, container, componentModels, ownerReferenceModel = null) {
|
|
63
80
|
var _a, _b, _c, _d;
|
|
64
81
|
if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
|
|
@@ -89,7 +106,7 @@ class DynamicTextUtil {
|
|
|
89
106
|
}
|
|
90
107
|
else {
|
|
91
108
|
if (!container && !isSpecRelated) {
|
|
92
|
-
text = entityType
|
|
109
|
+
text = placeholderForMissingContainer(entityType);
|
|
93
110
|
}
|
|
94
111
|
else {
|
|
95
112
|
if (CONTAINER_SOURCES.includes(entityType)) {
|
|
@@ -132,7 +149,7 @@ class DynamicTextUtil {
|
|
|
132
149
|
text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
|
|
133
150
|
}
|
|
134
151
|
else if (!container) {
|
|
135
|
-
text =
|
|
152
|
+
text = placeholderForMissingContainer(entityType);
|
|
136
153
|
}
|
|
137
154
|
else {
|
|
138
155
|
text = property === null || property === void 0 ? void 0 : property.label;
|
|
@@ -142,7 +159,7 @@ class DynamicTextUtil {
|
|
|
142
159
|
text = 'n/a';
|
|
143
160
|
}
|
|
144
161
|
if (displayLabel &&
|
|
145
|
-
!
|
|
162
|
+
!isPlaceholderText(text) &&
|
|
146
163
|
displayFunction !== DynamicTextDisplayFunction.LABEL &&
|
|
147
164
|
text !== bindingProperty) {
|
|
148
165
|
text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
|
|
@@ -150,16 +167,19 @@ class DynamicTextUtil {
|
|
|
150
167
|
return text;
|
|
151
168
|
}
|
|
152
169
|
static calculateSize(dynamicTextElement, entityType, text) {
|
|
153
|
-
var _a, _b, _c, _d;
|
|
154
|
-
let size =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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;
|
|
159
179
|
const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
|
|
160
180
|
const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
|
|
161
|
-
const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
|
|
162
|
-
const italic = document_util_1.DocumentStyleUtil.isItalic(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text);
|
|
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 : '');
|
|
163
183
|
const measureTextSettings = {
|
|
164
184
|
fontFamily,
|
|
165
185
|
fontSize: fontSizePx,
|
|
@@ -168,8 +188,9 @@ class DynamicTextUtil {
|
|
|
168
188
|
bold,
|
|
169
189
|
italic,
|
|
170
190
|
};
|
|
171
|
-
|
|
172
|
-
|
|
191
|
+
const fixedWidth = size.width - padding * 2;
|
|
192
|
+
if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
|
|
193
|
+
measureTextSettings.width = fixedWidth;
|
|
173
194
|
}
|
|
174
195
|
try {
|
|
175
196
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|
|
@@ -199,7 +220,7 @@ class DynamicTextUtil {
|
|
|
199
220
|
}
|
|
200
221
|
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
201
222
|
text = Array.from(new Set(memberValues
|
|
202
|
-
.filter((e) => e !== null && e !== undefined)
|
|
223
|
+
.filter((e) => e !== null && e !== undefined && e !== '')
|
|
203
224
|
.flat()
|
|
204
225
|
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
205
226
|
.sort()
|
|
@@ -212,13 +233,17 @@ class DynamicTextUtil {
|
|
|
212
233
|
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
213
234
|
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
214
235
|
}
|
|
215
|
-
else if (displayFunction === DynamicTextDisplayFunction.MIN
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
236
|
+
else if (displayFunction === DynamicTextDisplayFunction.MIN ||
|
|
237
|
+
displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
238
|
+
const present = memberValues
|
|
239
|
+
.filter((e) => e !== null && e !== undefined && e !== '')
|
|
240
|
+
.map(Number)
|
|
241
|
+
.filter((e) => !Number.isNaN(e));
|
|
242
|
+
if (!present.length) {
|
|
243
|
+
return '';
|
|
244
|
+
}
|
|
245
|
+
const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
|
|
246
|
+
text = formatter.formatValueForProperty(extreme, property);
|
|
222
247
|
}
|
|
223
248
|
return text;
|
|
224
249
|
}
|