@contrail/document-generation 1.0.13 → 1.0.14

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.
@@ -4,5 +4,4 @@ import { PropertyValueFormatter } from "@contrail/types";
4
4
  export declare class DocumentPropertyUtil {
5
5
  static generatePropertyTextElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, isComponent: boolean): Array<DocumentElement>;
6
6
  static generatePropertyTextElement(model: any, property: DocumentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, position: PositionDefinition, isComponent: boolean): DocumentElement;
7
- private static generateTextElement;
8
7
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentPropertyUtil = void 0;
4
4
  const util_1 = require("@contrail/util");
5
- const documents_1 = require("@contrail/documents");
6
5
  const types_1 = require("@contrail/types");
6
+ const document_text_element_util_1 = require("./document-text-element-util");
7
7
  class DocumentPropertyUtil {
8
8
  static generatePropertyTextElements(data, properties, options, startingPosition, isComponent) {
9
9
  var _a, _b;
@@ -28,7 +28,8 @@ class DocumentPropertyUtil {
28
28
  const value = util_1.ObjectUtil.getByPath(model, modelKey);
29
29
  let display = formatter.formatValueForProperty(value, property.propertyDefinition);
30
30
  const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
31
- let element = this.generateTextElement(display, mergedOptions, position);
31
+ mergedOptions.position = position;
32
+ let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, !isComponent);
32
33
  if (isComponent && property.includeLabel) {
33
34
  element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
34
35
  }
@@ -39,29 +40,5 @@ class DocumentPropertyUtil {
39
40
  element.propertyBindings = { text: modelKey };
40
41
  return element;
41
42
  }
42
- static generateTextElement(textValue, options, position) {
43
- var _a, _b, _c;
44
- const yPosition = position.y || 0;
45
- const xPosition = position.x || 0;
46
- const defaultStyle = {
47
- font: {
48
- size: 8,
49
- },
50
- color: 'rgba(0,0,0,.5)',
51
- };
52
- let style = options.style || defaultStyle;
53
- if ((_a = options === null || options === void 0 ? void 0 : options.style) === null || _a === void 0 ? void 0 : _a.text) {
54
- style.text = options.style.text;
55
- }
56
- let element = documents_1.DocumentElementFactory.createTextElement(textValue);
57
- const height = ((_b = options.size) === null || _b === void 0 ? void 0 : _b.height) || 25;
58
- const width = ((_c = options === null || options === void 0 ? void 0 : options.size) === null || _c === void 0 ? void 0 : _c.width) || 125;
59
- element = Object.assign(element, {
60
- position: { x: xPosition, y: yPosition },
61
- size: { height, width },
62
- style,
63
- });
64
- return element;
65
- }
66
43
  }
67
44
  exports.DocumentPropertyUtil = DocumentPropertyUtil;
@@ -0,0 +1,6 @@
1
+ import { DocumentElement, StyleDefinition } from "@contrail/documents";
2
+ export declare class DocumentTextElementUtil {
3
+ static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean): DocumentElement;
4
+ static applyInLineStyling(text: any, style: StyleDefinition): any;
5
+ static applyBold(text: any): void;
6
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentTextElementUtil = void 0;
4
+ const documents_1 = require("@contrail/documents");
5
+ const util_1 = require("@contrail/util");
6
+ class DocumentTextElementUtil {
7
+ static generateTextElement(textValue, options, applyInlineFormatting = true) {
8
+ var _a;
9
+ const defaultStyle = {
10
+ font: {
11
+ size: 8,
12
+ },
13
+ color: 'rgba(0,0,0,.5)',
14
+ };
15
+ let style = util_1.ObjectUtil.mergeDeep(defaultStyle, options.style || {});
16
+ if ((_a = options === null || options === void 0 ? void 0 : options.style) === null || _a === void 0 ? void 0 : _a.text) {
17
+ style.text = options.style.text;
18
+ }
19
+ let position = options.position || { y: 0, x: 0 };
20
+ position.x = position.x || 0;
21
+ position.y = position.y || 0;
22
+ let size = options.size || { height: 25, width: 125 };
23
+ size.height = size.height || 25;
24
+ size.width = size.width || 125;
25
+ const defaultedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { position, size, style });
26
+ let element = documents_1.DocumentElementFactory.createTextElement(textValue);
27
+ element = Object.assign(element, defaultedOptions);
28
+ if (applyInlineFormatting) {
29
+ element.text = this.applyInLineStyling(element.text, element.style);
30
+ }
31
+ return element;
32
+ }
33
+ static applyInLineStyling(text, style) {
34
+ var _a, _b;
35
+ let formattedText = text;
36
+ if ((style === null || style === void 0 ? void 0 : style.font.weight) === 'bold') {
37
+ formattedText = `<strong>${formattedText}</strong>`;
38
+ }
39
+ if (((_a = style === null || style === void 0 ? void 0 : style.text) === null || _a === void 0 ? void 0 : _a.decoration) === 'underline') {
40
+ formattedText = `<span style="text-decoration: underline;">${formattedText}</span>`;
41
+ }
42
+ if ((_b = style === null || style === void 0 ? void 0 : style.font) === null || _b === void 0 ? void 0 : _b.size) {
43
+ formattedText = `<span style="font-size: ${style.font.size}pt;">${formattedText}</span>`;
44
+ }
45
+ formattedText = `<p>${formattedText}</p>`;
46
+ return formattedText;
47
+ }
48
+ static applyBold(text) {
49
+ return;
50
+ }
51
+ }
52
+ exports.DocumentTextElementUtil = DocumentTextElementUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",