@contrail/documents 2.1.0-alpha.afeb3fa → 2.1.0-alpha.c922865
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
CHANGED
|
@@ -20,6 +20,11 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
20
20
|
- `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
|
|
21
21
|
`document-element-constants`, so the rule above has one definition rather than one per app.
|
|
22
22
|
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
|
|
26
|
+
the server failed the read for the whole document. It now measures from a zero size instead.
|
|
27
|
+
|
|
23
28
|
### Changed
|
|
24
29
|
|
|
25
30
|
- `DocumentElementFactory.getBoundingClientRect` multiplies the measured size by the element's
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { PositionDefinition } from '../types';
|
|
1
|
+
import { DocumentElement, PositionDefinition } from '../types';
|
|
2
2
|
import { ContainerElementType } from './container-kind';
|
|
3
3
|
import { DocumentContainer } from './document-container';
|
|
4
4
|
export declare class DocumentContainerIndex {
|
|
5
5
|
private readonly data;
|
|
6
6
|
constructor(data: {
|
|
7
|
+
documentElementsById: Map<string, DocumentElement>;
|
|
7
8
|
containersById: Map<string, DocumentContainer>;
|
|
8
9
|
containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
|
|
9
10
|
memberIdsByContainerId: Map<string, string[]>;
|
|
@@ -14,6 +15,7 @@ export declare class DocumentContainerIndex {
|
|
|
14
15
|
containerIdsOf(documentElementId: string, elementType: ContainerElementType): string[];
|
|
15
16
|
innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
|
|
16
17
|
memberIdsOf(containerId: string): string[];
|
|
18
|
+
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
17
19
|
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): string[];
|
|
18
20
|
maxDepth(elementType: ContainerElementType): number;
|
|
19
21
|
private containersOfType;
|
|
@@ -26,6 +26,11 @@ class DocumentContainerIndex {
|
|
|
26
26
|
var _a;
|
|
27
27
|
return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
|
|
28
28
|
}
|
|
29
|
+
memberDocumentElementsOf(containerId) {
|
|
30
|
+
return this.memberIdsOf(containerId)
|
|
31
|
+
.map((memberId) => this.data.documentElementsById.get(memberId))
|
|
32
|
+
.filter(Boolean);
|
|
33
|
+
}
|
|
29
34
|
containerPathAtPoint(point, elementType) {
|
|
30
35
|
const covering = this.containersOfType(elementType).filter((container) => (0, document_container_1.containsPoint)(container.box, point));
|
|
31
36
|
return (0, document_container_1.topmostPerDepth)(covering).map((container) => container.id);
|
|
@@ -37,6 +37,7 @@ class DocumentContainerService {
|
|
|
37
37
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
38
38
|
}
|
|
39
39
|
return new document_container_index_1.DocumentContainerIndex({
|
|
40
|
+
documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
|
|
40
41
|
containersById,
|
|
41
42
|
containerPathsByDocumentElementId,
|
|
42
43
|
memberIdsByContainerId,
|
|
@@ -150,12 +150,12 @@ class DynamicTextUtil {
|
|
|
150
150
|
return text;
|
|
151
151
|
}
|
|
152
152
|
static calculateSize(dynamicTextElement, entityType, text) {
|
|
153
|
-
var _a, _b, _c, _d;
|
|
154
|
-
let size = dynamicTextElement.size;
|
|
155
|
-
const fontFamily = (
|
|
156
|
-
const fontSize = (
|
|
157
|
-
? (
|
|
158
|
-
: document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null &&
|
|
153
|
+
var _a, _b, _c, _d, _e;
|
|
154
|
+
let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
|
|
155
|
+
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;
|
|
156
|
+
const fontSize = (_e = (dynamicTextElement.isTextTool
|
|
157
|
+
? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
|
|
158
|
+
: 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;
|
|
159
159
|
const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
|
|
160
160
|
const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
|
|
161
161
|
const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
|
|
@@ -169,7 +169,7 @@ class DynamicTextUtil {
|
|
|
169
169
|
italic,
|
|
170
170
|
};
|
|
171
171
|
if (!dynamicTextElement.isTextTool) {
|
|
172
|
-
measureTextSettings.width =
|
|
172
|
+
measureTextSettings.width = size.width - padding * 2;
|
|
173
173
|
}
|
|
174
174
|
try {
|
|
175
175
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|