@contrail/document-generation 1.0.24 → 1.0.25

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.
@@ -1,59 +1,59 @@
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
- let fontStyles = '';
43
- if ((_b = style === null || style === void 0 ? void 0 : style.font) === null || _b === void 0 ? void 0 : _b.size) {
44
- fontStyles += `font-size: ${style.font.size}pt; `;
45
- }
46
- if (style === null || style === void 0 ? void 0 : style.color) {
47
- fontStyles += `color: ${style.color}; `;
48
- }
49
- if (fontStyles.length) {
50
- formattedText = `<span style="${fontStyles}">${formattedText}</span>`;
51
- }
52
- formattedText = `<p>${formattedText}</p>`;
53
- return formattedText;
54
- }
55
- static applyBold(text) {
56
- return;
57
- }
58
- }
59
- exports.DocumentTextElementUtil = DocumentTextElementUtil;
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
+ let fontStyles = '';
43
+ if ((_b = style === null || style === void 0 ? void 0 : style.font) === null || _b === void 0 ? void 0 : _b.size) {
44
+ fontStyles += `font-size: ${style.font.size}pt; `;
45
+ }
46
+ if (style === null || style === void 0 ? void 0 : style.color) {
47
+ fontStyles += `color: ${style.color}; `;
48
+ }
49
+ if (fontStyles.length) {
50
+ formattedText = `<span style="${fontStyles}">${formattedText}</span>`;
51
+ }
52
+ formattedText = `<p>${formattedText}</p>`;
53
+ return formattedText;
54
+ }
55
+ static applyBold(text) {
56
+ return;
57
+ }
58
+ }
59
+ exports.DocumentTextElementUtil = DocumentTextElementUtil;
@@ -1,7 +1,7 @@
1
- import { PositionDefinition } from "@contrail/documents";
2
- export declare class DocumentUtil {
3
- static getRelativePosition(position1: PositionDefinition, position2: PositionDefinition): {
4
- x: number;
5
- y: number;
6
- };
7
- }
1
+ import { PositionDefinition } from "@contrail/documents";
2
+ export declare class DocumentUtil {
3
+ static getRelativePosition(position1: PositionDefinition, position2: PositionDefinition): {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ }
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentUtil = void 0;
4
- class DocumentUtil {
5
- static getRelativePosition(position1, position2) {
6
- const relativePosition = {
7
- x: position2.x - position1.x,
8
- y: position2.y - position1.y,
9
- };
10
- return relativePosition;
11
- }
12
- }
13
- exports.DocumentUtil = DocumentUtil;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentUtil = void 0;
4
+ class DocumentUtil {
5
+ static getRelativePosition(position1, position2) {
6
+ const relativePosition = {
7
+ x: position2.x - position1.x,
8
+ y: position2.y - position1.y,
9
+ };
10
+ return relativePosition;
11
+ }
12
+ }
13
+ exports.DocumentUtil = DocumentUtil;
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@contrail/document-generation",
3
- "version": "1.0.24",
4
- "description": "Utilities for automatic generation of documents.",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "scripts": {
8
- "build": "tsc",
9
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
10
- "lint": "tslint -p tsconfig.json",
11
- "test": "jest"
12
- },
13
- "keywords": [],
14
- "author": "",
15
- "license": "ISC",
16
- "devDependencies": {
17
- "@contrail/aggregates": "^1.0.14",
18
- "@contrail/sdk": "^1.2.3",
19
- "@types/jest": "^23.3.14",
20
- "@types/node": "^18.16.0",
21
- "jest": "^23.6.0",
22
- "nanoid": "^3.3.6",
23
- "npm": "^9.6.5",
24
- "prettier": "^1.19.1",
25
- "ts-jest": "^23.10.5",
26
- "tslint": "^5.11.0",
27
- "tslint-config-prettier": "^1.18.0",
28
- "typescript": "^4.0.0"
29
- },
30
- "jest": {
31
- "moduleFileExtensions": [
32
- "js",
33
- "json",
34
- "ts"
35
- ],
36
- "rootDir": "src",
37
- "testRegex": ".spec.ts$",
38
- "transform": {
39
- "^.+\\.(t|j)s$": "ts-jest"
40
- },
41
- "coverageDirectory": "../coverage",
42
- "testEnvironment": "node"
43
- },
44
- "dependencies": {
45
- "@contrail/data-grouping": "^1.0.20",
46
- "@contrail/documents": "^1.0.44",
47
- "@contrail/types": "^3.0.27",
48
- "@contrail/util": "^1.0.27"
49
- }
50
- }
1
+ {
2
+ "name": "@contrail/document-generation",
3
+ "version": "1.0.25",
4
+ "description": "Utilities for automatic generation of documents.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
10
+ "lint": "tslint -p tsconfig.json",
11
+ "test": "jest"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "devDependencies": {
17
+ "@contrail/aggregates": "^1.0.14",
18
+ "@contrail/sdk": "^1.2.3",
19
+ "@types/jest": "^29.5.2",
20
+ "@types/node": "^18.16.0",
21
+ "jest": "^29.5.0",
22
+ "nanoid": "^3.3.6",
23
+ "npm": "^9.6.5",
24
+ "prettier": "^1.19.1",
25
+ "ts-jest": "^29.1.1",
26
+ "tslint": "^5.11.0",
27
+ "tslint-config-prettier": "^1.18.0",
28
+ "typescript": "^4.0.0"
29
+ },
30
+ "jest": {
31
+ "moduleFileExtensions": [
32
+ "js",
33
+ "json",
34
+ "ts"
35
+ ],
36
+ "rootDir": "src",
37
+ "testRegex": ".spec.ts$",
38
+ "transform": {
39
+ "^.+\\.(t|j)s$": "ts-jest"
40
+ },
41
+ "coverageDirectory": "../coverage",
42
+ "testEnvironment": "node"
43
+ },
44
+ "dependencies": {
45
+ "@contrail/data-grouping": "^1.0.20",
46
+ "@contrail/documents": "^1.0.44",
47
+ "@contrail/types": "^3.0.27",
48
+ "@contrail/util": "^1.0.27"
49
+ }
50
+ }