@contrail/document-generation 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ComponentGenerator = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
5
|
const nanoid_1 = require("nanoid");
|
|
6
|
-
const util_1 = require("@contrail/util");
|
|
7
6
|
const document_property_util_1 = require("../util/document-property-util");
|
|
8
7
|
const component_util_1 = require("./component-util");
|
|
9
8
|
class ComponentGenerator {
|
|
@@ -25,16 +24,8 @@ class ComponentGenerator {
|
|
|
25
24
|
}
|
|
26
25
|
let yPosition = 0;
|
|
27
26
|
const imageDimension = template.imageDimension || {};
|
|
28
|
-
const imageHeight = imageDimension.height || imageDimension.width || 125;
|
|
29
27
|
const imageWidth = imageDimension.width || 125;
|
|
30
|
-
const
|
|
31
|
-
const elements = [{
|
|
32
|
-
type: "image",
|
|
33
|
-
size: { width: imageWidth, height: imageHeight },
|
|
34
|
-
propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
|
|
35
|
-
url: imageUrl,
|
|
36
|
-
}];
|
|
37
|
-
yPosition += imageHeight;
|
|
28
|
+
const elements = [];
|
|
38
29
|
const textOptions = {
|
|
39
30
|
style: {
|
|
40
31
|
text: {
|
|
@@ -45,7 +36,7 @@ class ComponentGenerator {
|
|
|
45
36
|
width: imageWidth
|
|
46
37
|
}
|
|
47
38
|
};
|
|
48
|
-
elements.push(...document_property_util_1.DocumentPropertyUtil.
|
|
39
|
+
elements.push(...document_property_util_1.DocumentPropertyUtil.generatePropertyElements(data, template.properties, textOptions, { y: yPosition }, imageDimension, true));
|
|
49
40
|
const modelBindings = component_util_1.ComponentUtil.generatedModelBindings(data);
|
|
50
41
|
componentElement.elements = elements;
|
|
51
42
|
componentElement.modelBindings = modelBindings;
|
|
@@ -44,7 +44,7 @@ class InfoPanelGenerator {
|
|
|
44
44
|
},
|
|
45
45
|
modelBindings,
|
|
46
46
|
};
|
|
47
|
-
const textElements = document_property_util_1.DocumentPropertyUtil.
|
|
47
|
+
const textElements = document_property_util_1.DocumentPropertyUtil.generatePropertyElements(data, template.propertyTemplate.properties, textOptions, { x: panel.position.x, y: panel.position.y }, {}, false);
|
|
48
48
|
elements.push(...textElements);
|
|
49
49
|
return elements;
|
|
50
50
|
}
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DocumentPropertyDefinition } from "../interfaces";
|
|
2
|
-
import { DocumentElement, PositionDefinition } from "@contrail/documents";
|
|
2
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from "@contrail/documents";
|
|
3
3
|
import { PropertyValueFormatter } from "@contrail/types";
|
|
4
4
|
export declare class DocumentPropertyUtil {
|
|
5
|
-
static
|
|
5
|
+
static generatePropertyElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, imageDimension: SizeDefinition, isComponent?: boolean): Array<DocumentElement>;
|
|
6
6
|
static generatePropertyTextElement(model: any, property: DocumentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, position: PositionDefinition, isComponent?: boolean): DocumentElement;
|
|
7
|
+
static generatePropertyImageElement(data: any, property: DocumentPropertyDefinition, imageDimension: SizeDefinition, position: PositionDefinition): DocumentElement;
|
|
7
8
|
}
|
|
@@ -5,22 +5,31 @@ const util_1 = require("@contrail/util");
|
|
|
5
5
|
const types_1 = require("@contrail/types");
|
|
6
6
|
const document_text_element_util_1 = require("./document-text-element-util");
|
|
7
7
|
class DocumentPropertyUtil {
|
|
8
|
-
static
|
|
8
|
+
static generatePropertyElements(data, properties, options, startingPosition, imageDimension, isComponent = false) {
|
|
9
9
|
var _a, _b;
|
|
10
10
|
let yPosition = startingPosition.y || 0;
|
|
11
11
|
const xPosition = startingPosition.x || 0;
|
|
12
12
|
const elements = [];
|
|
13
13
|
const formatter = new types_1.PropertyValueFormatter();
|
|
14
14
|
for (let property of properties) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
let element;
|
|
16
|
+
if (property.propertyDefinition) {
|
|
17
|
+
const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
|
|
18
|
+
const PT_TO_PX = 1.3;
|
|
19
|
+
const LINE_HEIGHT = 1.4;
|
|
20
|
+
const PADDING = 1.6;
|
|
21
|
+
let height = fontSize * PT_TO_PX * LINE_HEIGHT * PADDING;
|
|
22
|
+
options.size = options.size || {};
|
|
23
|
+
options.size.height = height;
|
|
24
|
+
element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
|
|
25
|
+
yPosition += height;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const imageHeight = imageDimension.height || imageDimension.width || 125;
|
|
29
|
+
const imageWidth = imageDimension.width || 125;
|
|
30
|
+
element = DocumentPropertyUtil.generatePropertyImageElement(data, property, { width: imageWidth, height: imageHeight }, { x: xPosition, y: yPosition });
|
|
31
|
+
yPosition += imageHeight;
|
|
32
|
+
}
|
|
24
33
|
elements.push(element);
|
|
25
34
|
}
|
|
26
35
|
return elements;
|
|
@@ -43,5 +52,19 @@ class DocumentPropertyUtil {
|
|
|
43
52
|
element.propertyBindings = { text: modelKey };
|
|
44
53
|
return element;
|
|
45
54
|
}
|
|
55
|
+
static generatePropertyImageElement(data, property, imageDimension, position) {
|
|
56
|
+
const imageUrl = util_1.ObjectUtil.getByPath(data, `viewable.mediumViewableDownloadUrl`);
|
|
57
|
+
const element = {
|
|
58
|
+
type: "image",
|
|
59
|
+
size: imageDimension,
|
|
60
|
+
propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
|
|
61
|
+
url: imageUrl,
|
|
62
|
+
position
|
|
63
|
+
};
|
|
64
|
+
if (property.isHidden) {
|
|
65
|
+
element.isHidden = property.isHidden;
|
|
66
|
+
}
|
|
67
|
+
return element;
|
|
68
|
+
}
|
|
46
69
|
}
|
|
47
70
|
exports.DocumentPropertyUtil = DocumentPropertyUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-generation",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Utilities for automatic generation of documents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@contrail/data-grouping": "^1.0.20",
|
|
46
|
-
"@contrail/documents": "^1.0.
|
|
46
|
+
"@contrail/documents": "^1.0.59",
|
|
47
47
|
"@contrail/types": "^3.0.27",
|
|
48
48
|
"@contrail/util": "^1.0.27"
|
|
49
49
|
}
|