@contrail/document-generation 2.0.37 → 2.0.38

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.
Files changed (43) hide show
  1. package/README.md +2 -2
  2. package/lib/board-document-generator.d.ts +23 -0
  3. package/lib/board-document-generator.js +223 -0
  4. package/lib/components/component-generator.d.ts +6 -0
  5. package/lib/components/component-generator.js +55 -0
  6. package/lib/components/component-grid-generator.d.ts +7 -0
  7. package/lib/components/component-grid-generator.js +84 -0
  8. package/lib/components/component-util.d.ts +5 -0
  9. package/lib/components/component-util.js +43 -0
  10. package/lib/document-generator.d.ts +6 -0
  11. package/lib/document-generator.js +11 -0
  12. package/lib/frames/frame-generator.d.ts +12 -0
  13. package/lib/frames/frame-generator.js +131 -0
  14. package/lib/frames/frame.d.ts +16 -0
  15. package/lib/frames/frame.js +67 -0
  16. package/lib/frames/index.d.ts +2 -0
  17. package/lib/frames/index.js +18 -0
  18. package/lib/index.d.ts +6 -0
  19. package/lib/index.js +22 -0
  20. package/lib/info-panel/info-panel-generator.d.ts +6 -0
  21. package/lib/info-panel/info-panel-generator.js +52 -0
  22. package/lib/interfaces.d.ts +72 -0
  23. package/lib/interfaces.js +8 -0
  24. package/lib/scripts/test-board.d.ts +1 -0
  25. package/lib/scripts/test-board.js +230 -0
  26. package/lib/scripts/test-showcase.d.ts +1 -0
  27. package/lib/scripts/test-showcase.js +257 -0
  28. package/lib/showcase-frame-generator.d.ts +8 -0
  29. package/lib/showcase-frame-generator.js +44 -0
  30. package/lib/test-data.d.ts +72 -0
  31. package/lib/test-data.js +187 -0
  32. package/lib/util/document-property-util.d.ts +9 -0
  33. package/lib/util/document-property-util.js +101 -0
  34. package/lib/util/document-text-element-util.d.ts +10 -0
  35. package/lib/util/document-text-element-util.js +124 -0
  36. package/lib/util/document-util.d.ts +8 -0
  37. package/lib/util/document-util.js +22 -0
  38. package/lib/util/index.d.ts +2 -0
  39. package/lib/util/index.js +18 -0
  40. package/lib/util/text-util.d.ts +4 -0
  41. package/lib/util/text-util.js +28 -0
  42. package/package.json +1 -1
  43. package/testdocument.json +25972 -25972
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const interfaces_1 = require("../interfaces");
13
+ const sdk_1 = require("@contrail/sdk");
14
+ const fs = require('fs');
15
+ const data_grouping_1 = require("@contrail/data-grouping");
16
+ const showcase_frame_generator_1 = require("../showcase-frame-generator");
17
+ function run() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const orgSlug = 'converse-prod';
20
+ yield loginSDK(orgSlug);
21
+ const assortmentId = 'Z7nTOauGtuuiU9UC';
22
+ const itemType = yield new sdk_1.Types().getType({ path: 'item' });
23
+ const projectItemType = yield new sdk_1.Types().getType({ path: 'project-item' });
24
+ const PROPERTY_COMPONENT_TEMPLATE = {
25
+ imageDimension: { width: 600 },
26
+ imageLocation: 'top',
27
+ textHorizontalAlignment: 'center',
28
+ properties: [
29
+ {
30
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
31
+ typeRootSlug: 'item',
32
+ slug: 'name',
33
+ style: {
34
+ font: {
35
+ size: 14,
36
+ weight: 'bold',
37
+ },
38
+ color: 'rgba(0,0,0,.5)',
39
+ },
40
+ },
41
+ {
42
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'optionName'),
43
+ typeRootSlug: 'item',
44
+ slug: 'optionName',
45
+ style: {
46
+ font: {
47
+ size: 10,
48
+ weight: 'bold',
49
+ },
50
+ color: 'green',
51
+ },
52
+ },
53
+ {
54
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'category'),
55
+ typeRootSlug: 'item',
56
+ slug: 'category',
57
+ includeLabel: true,
58
+ },
59
+ {
60
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'designTheme'),
61
+ typeRootSlug: 'item',
62
+ slug: 'designTheme',
63
+ includeLabel: true,
64
+ },
65
+ {
66
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'baseStyleNumber'),
67
+ typeRootSlug: 'item',
68
+ slug: 'baseStyleNumber',
69
+ },
70
+ {
71
+ propertyDefinition: projectItemType.typeProperties.find((p) => p.slug === 'colorwayStatus'),
72
+ slug: 'colorwayStatus',
73
+ typeRootSlug: 'project-item',
74
+ includeLabel: true,
75
+ },
76
+ ],
77
+ };
78
+ const PANEL_PROPERTY_TEMPLATE = {
79
+ properties: [
80
+ {
81
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
82
+ typeRootSlug: 'item',
83
+ slug: 'name',
84
+ includeLabel: false,
85
+ style: {
86
+ font: {
87
+ size: 25,
88
+ weight: 'bold',
89
+ },
90
+ color: 'white',
91
+ },
92
+ },
93
+ {
94
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'segment'),
95
+ typeRootSlug: 'item',
96
+ slug: 'segment',
97
+ includeLabel: true,
98
+ style: {
99
+ font: {
100
+ size: 14,
101
+ },
102
+ color: 'white',
103
+ },
104
+ },
105
+ {
106
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'familyName'),
107
+ typeRootSlug: 'item',
108
+ slug: 'familyName',
109
+ includeLabel: true,
110
+ style: {
111
+ font: {
112
+ size: 14,
113
+ },
114
+ color: 'white',
115
+ },
116
+ },
117
+ {
118
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'ageGroup'),
119
+ typeRootSlug: 'item',
120
+ slug: 'ageGroup',
121
+ includeLabel: true,
122
+ style: {
123
+ font: {
124
+ size: 14,
125
+ },
126
+ color: 'white',
127
+ },
128
+ },
129
+ {
130
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'planningLevel1'),
131
+ typeRootSlug: 'item',
132
+ slug: 'planningLevel1',
133
+ includeLabel: true,
134
+ style: {
135
+ font: {
136
+ size: 14,
137
+ },
138
+ color: 'white',
139
+ },
140
+ },
141
+ ],
142
+ };
143
+ const documentTemplateDefinition = {
144
+ frameOrientation: interfaces_1.Orientation.HORIZONTAL,
145
+ frameSize: { width: 1200, height: 675 },
146
+ framePadding: 30,
147
+ frameGroupHeaderTemplate: {
148
+ style: {
149
+ color: '#ffffff',
150
+ font: {
151
+ size: 20,
152
+ },
153
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
154
+ },
155
+ size: {
156
+ height: 60,
157
+ },
158
+ },
159
+ frameInfoPanelTemplate: {
160
+ panelDocumentTemplate: {
161
+ style: {
162
+ color: '#ffffff',
163
+ font: {
164
+ size: 20,
165
+ },
166
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
167
+ border: {
168
+ radius: 4,
169
+ },
170
+ },
171
+ size: {
172
+ width: 250,
173
+ height: 400,
174
+ },
175
+ },
176
+ propertyTemplate: PANEL_PROPERTY_TEMPLATE,
177
+ },
178
+ componentGridTemplate: {
179
+ gridDimensions: { cols: 3, rows: 1 },
180
+ componentPadding: 5,
181
+ componentTemplate: {
182
+ propertyTemplate: PROPERTY_COMPONENT_TEMPLATE,
183
+ },
184
+ },
185
+ };
186
+ const groupingProperties = [
187
+ {
188
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'category'),
189
+ typeRootSlug: 'item',
190
+ sort: sdk_1.SortOrderOptions.ASC,
191
+ values: null,
192
+ },
193
+ {
194
+ propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
195
+ typeRootSlug: 'item',
196
+ sort: sdk_1.SortOrderOptions.ASC,
197
+ values: null,
198
+ },
199
+ ];
200
+ documentTemplateDefinition.componentGridTemplate.componentTemplate.propertyTemplate = PROPERTY_COMPONENT_TEMPLATE;
201
+ const dataGroup = yield getDataGroupStructure(assortmentId, groupingProperties, documentTemplateDefinition);
202
+ const params = {
203
+ startingCoordinates: { x: 500, y: 500 },
204
+ data: {
205
+ dataGroup,
206
+ },
207
+ documentTemplateDefinition,
208
+ };
209
+ const frames = showcase_frame_generator_1.ShowcaseFrameGenerator.generateFrames(params);
210
+ });
211
+ }
212
+ function loginSDK(orgSlug) {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ const config = {
215
+ email: 'brian@vibeiq.com',
216
+ password: process.env.CONTRAIL_PW,
217
+ orgSlug: orgSlug,
218
+ };
219
+ yield (0, sdk_1.login)(config);
220
+ });
221
+ }
222
+ function getAssortmentItems(assortmentId) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ const assortment = yield new sdk_1.Entities().get({
225
+ entityName: 'assortment',
226
+ id: assortmentId,
227
+ relations: ['assortmentItems', 'assortmentItems.item', 'assortmentItems.projectItem'],
228
+ });
229
+ let assortmentItems = assortment.assortmentItems;
230
+ if (assortment.itemsDownloadURL) {
231
+ const response = yield fetch(assortment.itemsDownloadURL);
232
+ assortmentItems = yield response.json();
233
+ }
234
+ return assortmentItems;
235
+ });
236
+ }
237
+ function getDataGroupStructure(assortmentId, groupingProperties, template) {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ const assortmentItems = yield getAssortmentItems(assortmentId);
240
+ const data = fromAssortmentModelToItemModel(assortmentItems);
241
+ const leafNodeDataCount = template.componentGridTemplate.gridDimensions.cols * template.componentGridTemplate.gridDimensions.rows;
242
+ return data_grouping_1.DataGroupGenerator.buildDataGroupStructure(data, groupingProperties, leafNodeDataCount);
243
+ });
244
+ }
245
+ function fromAssortmentModelToItemModel(data) {
246
+ const results = [];
247
+ data.forEach((ai) => {
248
+ results.push({
249
+ item: ai.item,
250
+ projectItem: ai.projectItem,
251
+ viewable: ai.item,
252
+ assortmentItem: ai,
253
+ });
254
+ });
255
+ return results;
256
+ }
257
+ run();
@@ -0,0 +1,8 @@
1
+ import { DocumentGenerationOptions } from './interfaces';
2
+ import { DocumentFrame } from './frames/frame';
3
+ export declare class ShowcaseFrameGenerator {
4
+ constructor();
5
+ static generateFrames(options: DocumentGenerationOptions): Array<DocumentFrame>;
6
+ private static getFrameGroups;
7
+ private static getLeafGroupsFromGroups;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShowcaseFrameGenerator = void 0;
4
+ const frame_1 = require("./frames/frame");
5
+ const frame_generator_1 = require("./frames/frame-generator");
6
+ class ShowcaseFrameGenerator {
7
+ constructor() { }
8
+ static generateFrames(options) {
9
+ const frames = [];
10
+ const structure = options.data.dataGroup;
11
+ const template = options.documentTemplateDefinition;
12
+ const frameTemplate = options.frameTemplate;
13
+ const groups = this.getFrameGroups(structure);
14
+ for (let group of groups) {
15
+ const showcaseFrame = frame_generator_1.FrameGenerator.generateFrameContentForGroup(new frame_1.ShowcaseFrame(), group, template, frameTemplate);
16
+ console.log('showcaseFrame: ', showcaseFrame);
17
+ frames.push(showcaseFrame);
18
+ }
19
+ return frames;
20
+ }
21
+ static getFrameGroups(groupStructure) {
22
+ return this.getLeafGroupsFromGroups(groupStructure.rootGroup.subGroups, groupStructure.depth, 0);
23
+ }
24
+ static getLeafGroupsFromGroups(groups, totalDepth, currentDepth, groupName = null) {
25
+ const currentGroupName = groupName;
26
+ const leafGroups = [];
27
+ for (let group of groups) {
28
+ if (currentDepth === 0) {
29
+ groupName = null;
30
+ }
31
+ if (currentDepth === totalDepth) {
32
+ group.name = !groupName ? group.name : groupName + ' / ' + group.name;
33
+ leafGroups.push(group);
34
+ }
35
+ else {
36
+ if (currentDepth < totalDepth - 1)
37
+ groupName = !currentGroupName ? group.name : currentGroupName + ' / ' + group.name;
38
+ leafGroups.push(...this.getLeafGroupsFromGroups(group.subGroups, totalDepth, currentDepth + 1, groupName));
39
+ }
40
+ }
41
+ return leafGroups;
42
+ }
43
+ }
44
+ exports.ShowcaseFrameGenerator = ShowcaseFrameGenerator;
@@ -0,0 +1,72 @@
1
+ import { DataGroupStructure } from '@contrail/data-grouping';
2
+ import { ComponentGridTemplate, DocumentTemplate } from './interfaces';
3
+ export declare const TEST_ITEM_MODEL: {
4
+ item: {
5
+ id: string;
6
+ name: string;
7
+ optionName: string;
8
+ gender: string;
9
+ mediumViewableDownloadUrl: string;
10
+ };
11
+ projectItem: {
12
+ id: string;
13
+ retailPrice: number;
14
+ };
15
+ assortmentItem: {
16
+ id: string;
17
+ targetVolume: number;
18
+ };
19
+ };
20
+ export declare const TEST_GROUP: {
21
+ name: string;
22
+ data: {
23
+ item: {
24
+ id: string;
25
+ name: string;
26
+ optionName: string;
27
+ gender: string;
28
+ mediumViewableDownloadUrl: string;
29
+ };
30
+ projectItem: {
31
+ id: string;
32
+ retailPrice: number;
33
+ };
34
+ assortmentItem: {
35
+ id: string;
36
+ targetVolume: number;
37
+ };
38
+ }[];
39
+ propertyValues: {
40
+ gender: string;
41
+ };
42
+ subGroups: any[];
43
+ };
44
+ export declare const TEST_GROUP_2: {
45
+ name: string;
46
+ data: {
47
+ item: {
48
+ id: string;
49
+ name: string;
50
+ optionName: string;
51
+ gender: string;
52
+ mediumViewableDownloadUrl: string;
53
+ };
54
+ projectItem: {
55
+ id: string;
56
+ retailPrice: number;
57
+ };
58
+ assortmentItem: {
59
+ id: string;
60
+ targetVolume: number;
61
+ };
62
+ }[];
63
+ propertyValues: {
64
+ gender: string;
65
+ };
66
+ subGroups: any[];
67
+ };
68
+ export declare const TEST_ROOT_GROUP: DataGroupStructure;
69
+ export declare const TEST_TWO_LEVEL_ROOT_GROUP: DataGroupStructure;
70
+ export declare const COMPONENT_GRID_TEMPLATE: ComponentGridTemplate;
71
+ export declare const HORIZONTAL_DOCUMENT_TEMPLATE: DocumentTemplate;
72
+ export declare const VERTICAL_DOCUMENT_TEMPLATE: DocumentTemplate;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERTICAL_DOCUMENT_TEMPLATE = exports.HORIZONTAL_DOCUMENT_TEMPLATE = exports.COMPONENT_GRID_TEMPLATE = exports.TEST_TWO_LEVEL_ROOT_GROUP = exports.TEST_ROOT_GROUP = exports.TEST_GROUP_2 = exports.TEST_GROUP = exports.TEST_ITEM_MODEL = void 0;
4
+ const types_1 = require("@contrail/types");
5
+ const interfaces_1 = require("./interfaces");
6
+ const sdk_1 = require("@contrail/sdk");
7
+ exports.TEST_ITEM_MODEL = {
8
+ item: {
9
+ id: 'item-1001',
10
+ name: 'Shirt 1',
11
+ optionName: 'Red',
12
+ gender: 'mens',
13
+ mediumViewableDownloadUrl: 'https://api.vibeiq.com/dev/api/files/downloadUrl/-VMrLJrt3clDKPi0%2Fcontent:m3Bd4u-QLci1XiOl%2F2b72d48a-6b19-4ba8-9d54-813745fb8dd4.png',
14
+ },
15
+ projectItem: {
16
+ id: 'projectItem-1001',
17
+ retailPrice: 45.0,
18
+ },
19
+ assortmentItem: {
20
+ id: 'assortmentItem-1001',
21
+ targetVolume: 1000,
22
+ },
23
+ };
24
+ exports.TEST_GROUP = {
25
+ name: 'Mens',
26
+ data: [
27
+ exports.TEST_ITEM_MODEL,
28
+ exports.TEST_ITEM_MODEL,
29
+ exports.TEST_ITEM_MODEL,
30
+ exports.TEST_ITEM_MODEL,
31
+ exports.TEST_ITEM_MODEL,
32
+ exports.TEST_ITEM_MODEL,
33
+ exports.TEST_ITEM_MODEL,
34
+ exports.TEST_ITEM_MODEL,
35
+ exports.TEST_ITEM_MODEL,
36
+ exports.TEST_ITEM_MODEL,
37
+ ],
38
+ propertyValues: {
39
+ gender: 'mens',
40
+ },
41
+ subGroups: [],
42
+ };
43
+ exports.TEST_GROUP_2 = {
44
+ name: 'Womens',
45
+ data: [
46
+ exports.TEST_ITEM_MODEL,
47
+ exports.TEST_ITEM_MODEL,
48
+ exports.TEST_ITEM_MODEL,
49
+ exports.TEST_ITEM_MODEL,
50
+ exports.TEST_ITEM_MODEL,
51
+ exports.TEST_ITEM_MODEL,
52
+ exports.TEST_ITEM_MODEL,
53
+ ],
54
+ propertyValues: {
55
+ gender: 'womens',
56
+ },
57
+ subGroups: [],
58
+ };
59
+ exports.TEST_ROOT_GROUP = {
60
+ depth: 1,
61
+ groupingProperties: [
62
+ {
63
+ propertyDefinition: {
64
+ slug: 'gender',
65
+ propertyType: types_1.PropertyType.SingleSelect,
66
+ label: 'Gender',
67
+ },
68
+ sort: sdk_1.SortOrderOptions.ASC,
69
+ typeRootSlug: 'item',
70
+ values: null,
71
+ },
72
+ ],
73
+ rootGroup: {
74
+ data: [],
75
+ subGroups: [exports.TEST_GROUP, exports.TEST_GROUP, exports.TEST_GROUP],
76
+ name: 'Root',
77
+ propertyValues: {},
78
+ },
79
+ };
80
+ exports.TEST_TWO_LEVEL_ROOT_GROUP = {
81
+ depth: 2,
82
+ groupingProperties: [
83
+ {
84
+ propertyDefinition: {
85
+ slug: 'gender',
86
+ propertyType: types_1.PropertyType.SingleSelect,
87
+ label: 'Gender',
88
+ },
89
+ sort: sdk_1.SortOrderOptions.ASC,
90
+ typeRootSlug: 'item',
91
+ values: null,
92
+ },
93
+ ],
94
+ rootGroup: {
95
+ data: [],
96
+ subGroups: [
97
+ {
98
+ name: 'Mens',
99
+ subGroups: [exports.TEST_GROUP, exports.TEST_GROUP],
100
+ propertyValues: {
101
+ gender: 'mens',
102
+ },
103
+ data: [],
104
+ },
105
+ {
106
+ name: 'Womens',
107
+ subGroups: [exports.TEST_GROUP_2, exports.TEST_GROUP_2, exports.TEST_GROUP_2, exports.TEST_GROUP_2],
108
+ propertyValues: {
109
+ gender: 'mens',
110
+ },
111
+ data: [],
112
+ },
113
+ ],
114
+ name: 'Root',
115
+ propertyValues: {},
116
+ },
117
+ };
118
+ exports.COMPONENT_GRID_TEMPLATE = {
119
+ gridDimensions: { cols: 7, rows: 3 },
120
+ componentTemplate: {
121
+ propertyTemplate: {
122
+ properties: [],
123
+ imageLocation: 'top',
124
+ },
125
+ },
126
+ componentPadding: 20,
127
+ };
128
+ exports.HORIZONTAL_DOCUMENT_TEMPLATE = {
129
+ frameOrientation: interfaces_1.Orientation.HORIZONTAL,
130
+ frameSize: { width: 1200, height: 675 },
131
+ framePadding: 30,
132
+ frameHeaderTemplate: {
133
+ style: {
134
+ color: '#000000',
135
+ font: {
136
+ size: 20,
137
+ },
138
+ backgroundColor: '#FFFFFF',
139
+ },
140
+ size: {
141
+ height: 60,
142
+ },
143
+ },
144
+ frameGroupHeaderTemplate: {
145
+ style: {
146
+ color: '#ffffff',
147
+ font: {
148
+ size: 20,
149
+ },
150
+ backgroundColor: 'black',
151
+ },
152
+ size: {
153
+ height: 60,
154
+ },
155
+ },
156
+ componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
157
+ };
158
+ exports.VERTICAL_DOCUMENT_TEMPLATE = {
159
+ frameOrientation: interfaces_1.Orientation.VERTICAL,
160
+ frameSize: { width: 1200, height: 675 },
161
+ framePadding: 30,
162
+ frameHeaderTemplate: {
163
+ style: {
164
+ color: '#000000',
165
+ font: {
166
+ size: 20,
167
+ },
168
+ backgroundColor: '#FFFFFF',
169
+ },
170
+ size: {
171
+ height: 60,
172
+ },
173
+ },
174
+ frameGroupHeaderTemplate: {
175
+ style: {
176
+ color: '#ffffff',
177
+ font: {
178
+ size: 20,
179
+ },
180
+ backgroundColor: 'black',
181
+ },
182
+ size: {
183
+ height: 60,
184
+ },
185
+ },
186
+ componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
187
+ };
@@ -0,0 +1,9 @@
1
+ import { DocumentPropertyDefinition } from '../interfaces';
2
+ import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
3
+ import { PropertyValueFormatter } from '@contrail/types';
4
+ export declare class DocumentPropertyUtil {
5
+ static generatePropertyElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, imageDimension: SizeDefinition, isComponent?: boolean): Array<DocumentElement>;
6
+ static generatePropertyTextElement(model: any, property: DocumentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, position: PositionDefinition, isComponent?: boolean): DocumentElement;
7
+ static generatePropertyAnnotationElement(data: any, property: DocumentPropertyDefinition, size: SizeDefinition, position: PositionDefinition): DocumentElement;
8
+ static generatePropertyImageElement(data: any, property: DocumentPropertyDefinition, imageDimension: SizeDefinition, position: PositionDefinition): DocumentElement;
9
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentPropertyUtil = void 0;
4
+ const util_1 = require("@contrail/util");
5
+ const documents_1 = require("@contrail/documents");
6
+ const types_1 = require("@contrail/types");
7
+ const document_text_element_util_1 = require("./document-text-element-util");
8
+ const text_util_1 = require("./text-util");
9
+ class DocumentPropertyUtil {
10
+ static generatePropertyElements(data, properties, options, startingPosition, imageDimension, isComponent = false) {
11
+ var _a, _b;
12
+ let yPosition = startingPosition.y || 0;
13
+ const xPosition = startingPosition.x || 0;
14
+ const elements = [];
15
+ const formatter = new types_1.PropertyValueFormatter();
16
+ let index = 0;
17
+ for (let property of properties) {
18
+ let element;
19
+ if (index === 0 && property.slug === 'annotation') {
20
+ yPosition = -15;
21
+ }
22
+ if (property.propertyDefinition) {
23
+ const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
24
+ const PT_TO_PX = 1.3;
25
+ const LINE_HEIGHT = 1.4;
26
+ const PADDING = 1.6;
27
+ let height = fontSize * PT_TO_PX * LINE_HEIGHT * PADDING;
28
+ options.size = options.size || {};
29
+ options.size.height = height;
30
+ element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
31
+ yPosition += element.size.height - 10;
32
+ }
33
+ else if (property.slug === 'annotation') {
34
+ element = DocumentPropertyUtil.generatePropertyAnnotationElement(data, property, property.size, {
35
+ x: xPosition,
36
+ y: yPosition,
37
+ });
38
+ yPosition += element.size.height - 10;
39
+ }
40
+ else {
41
+ const imageHeight = imageDimension.height || imageDimension.width || 125;
42
+ const imageWidth = imageDimension.width || 125;
43
+ element = DocumentPropertyUtil.generatePropertyImageElement(data, property, { width: imageWidth, height: imageHeight }, { x: xPosition, y: yPosition });
44
+ yPosition += imageHeight;
45
+ }
46
+ elements.push(element);
47
+ index++;
48
+ }
49
+ return elements;
50
+ }
51
+ static generatePropertyTextElement(model, property, options, formatter, position, isComponent = false) {
52
+ var _a;
53
+ const modelKey = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
54
+ const value = util_1.ObjectUtil.getByPath(model, modelKey);
55
+ let display = formatter.formatValueForProperty(value, property.propertyDefinition);
56
+ if (!isComponent) {
57
+ const height = text_util_1.TextUtil.getHeightByTextWidth(display, property, options.size.width);
58
+ options.size.height = height;
59
+ }
60
+ if (!isComponent && property.includeLabel) {
61
+ display = property.propertyDefinition.label + ': ' + display;
62
+ }
63
+ const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
64
+ mergedOptions.position = position;
65
+ const useInlineFormatting = isComponent === false;
66
+ let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, useInlineFormatting, !isComponent);
67
+ if (property.includeLabel) {
68
+ element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
69
+ }
70
+ element.propertyBindings = { text: modelKey };
71
+ return element;
72
+ }
73
+ static generatePropertyAnnotationElement(data, property, size, position) {
74
+ const element = {
75
+ type: 'annotation',
76
+ size: size,
77
+ propertyBindings: { annotation: 'annotation' },
78
+ position,
79
+ };
80
+ if (property.isHidden) {
81
+ element.isHidden = property.isHidden;
82
+ }
83
+ return element;
84
+ }
85
+ static generatePropertyImageElement(data, property, imageDimension, position) {
86
+ const imageUrl = util_1.ObjectUtil.getByPath(data, `viewable.mediumViewableDownloadUrl`);
87
+ const element = {
88
+ type: 'image',
89
+ size: imageDimension,
90
+ propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
91
+ url: imageUrl,
92
+ position,
93
+ };
94
+ if (property.isHidden) {
95
+ element.isHidden = property.isHidden;
96
+ }
97
+ documents_1.DocumentElementPropertyBindingHandler.bindPropertiesToElement(element, data);
98
+ return element;
99
+ }
100
+ }
101
+ exports.DocumentPropertyUtil = DocumentPropertyUtil;
@@ -0,0 +1,10 @@
1
+ import { DocumentElement, StyleDefinition } from '@contrail/documents';
2
+ export declare class DocumentTextElementUtil {
3
+ static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean, sanitizeHTML?: boolean): DocumentElement;
4
+ static applyInLineStyling(text: any, style: StyleDefinition): any;
5
+ static extractStyleFromInline(text: string): StyleDefinition;
6
+ static extractFontSizeFromHTML(text: any): number;
7
+ static extractColorFromHTML(text: any): string;
8
+ static extractTextDecorationFromHTML(text: any): string;
9
+ static extractFontFromHTML(text: any): any;
10
+ }