@contrail/document-generation 2.0.10 → 2.0.12

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,6 +4,7 @@ exports.DocumentPropertyUtil = void 0;
4
4
  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
+ const text_util_1 = require("./text-util");
7
8
  class DocumentPropertyUtil {
8
9
  static generatePropertyElements(data, properties, options, startingPosition, imageDimension, isComponent = false) {
9
10
  var _a, _b;
@@ -22,7 +23,7 @@ class DocumentPropertyUtil {
22
23
  options.size = options.size || {};
23
24
  options.size.height = height;
24
25
  element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
25
- yPosition += height;
26
+ yPosition += element.size.height - 10;
26
27
  }
27
28
  else {
28
29
  const imageHeight = imageDimension.height || imageDimension.width || 125;
@@ -39,6 +40,10 @@ class DocumentPropertyUtil {
39
40
  const modelKey = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
40
41
  const value = util_1.ObjectUtil.getByPath(model, modelKey);
41
42
  let display = formatter.formatValueForProperty(value, property.propertyDefinition);
43
+ if (!isComponent) {
44
+ const height = text_util_1.TextUtil.getHeightByTextWidth(display, property, options.size.width);
45
+ options.size.height = height;
46
+ }
42
47
  if (!isComponent && property.includeLabel) {
43
48
  display = property.propertyDefinition.label + ': ' + display;
44
49
  }
@@ -0,0 +1,4 @@
1
+ import { DocumentPropertyDefinition } from "../interfaces";
2
+ export declare class TextUtil {
3
+ static getHeightByTextWidth(text: string, property: DocumentPropertyDefinition, width: number): number;
4
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextUtil = void 0;
4
+ class TextUtil {
5
+ static getHeightByTextWidth(text, property, width) {
6
+ var _a, _b, _c, _d;
7
+ let height = 0;
8
+ let div = document.createElement('DIV');
9
+ div.id = '__textMeasure';
10
+ div.innerHTML = text;
11
+ div.style.position = 'absolute';
12
+ div.style.top = '-500px';
13
+ div.style.left = '0';
14
+ div.style.width = width + 'px';
15
+ div.style.lineHeight = 'normal';
16
+ div.style.fontFamily = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.family) || 'Roboto';
17
+ div.style.fontWeight = property.style.font.weight ? 'bold' : 'normal';
18
+ div.style.fontSize = (((_d = (_c = property.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size) || 12) + 'pt';
19
+ div.style.padding = '11px';
20
+ document.body.appendChild(div);
21
+ height = div.offsetHeight + 5;
22
+ document.body.removeChild(div);
23
+ div = null;
24
+ return height;
25
+ }
26
+ }
27
+ exports.TextUtil = TextUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",