@contrail/document-util 1.0.1 → 1.0.3

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,3 +1,10 @@
1
+ export declare const DEFAULT_TEXT_FONT_FAMILY = "Roboto";
2
+ export declare const DEFAULT_TEXT_FONT_SIZE = 11;
3
+ export declare const DEFAULT_LINE_HEIGHT = 1.2;
4
+ export declare const DEFAULT_LETTER_SPACING = 0.25;
5
+ export declare const DEFAULT_TEXT_VALIGN = "top";
6
+ export declare const DEFAULT_TEXT_ALIGN = "left";
7
+ export declare const DEFAULT_TEXT_FONT_COLOR = "#000000";
1
8
  export declare class DocumentStyleUtil {
2
9
  static getFirstInlineStyleValue(text: string, pattern: string): string;
3
10
  static getFirstFontSize(text: string, toPt?: boolean): string;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentStyleUtil = void 0;
3
+ exports.DocumentStyleUtil = exports.DEFAULT_TEXT_FONT_COLOR = exports.DEFAULT_TEXT_ALIGN = exports.DEFAULT_TEXT_VALIGN = exports.DEFAULT_LETTER_SPACING = exports.DEFAULT_LINE_HEIGHT = exports.DEFAULT_TEXT_FONT_SIZE = exports.DEFAULT_TEXT_FONT_FAMILY = void 0;
4
+ exports.DEFAULT_TEXT_FONT_FAMILY = 'Roboto';
5
+ exports.DEFAULT_TEXT_FONT_SIZE = 11;
6
+ exports.DEFAULT_LINE_HEIGHT = 1.2;
7
+ exports.DEFAULT_LETTER_SPACING = 0.25;
8
+ exports.DEFAULT_TEXT_VALIGN = 'top';
9
+ exports.DEFAULT_TEXT_ALIGN = 'left';
10
+ exports.DEFAULT_TEXT_FONT_COLOR = '#000000';
4
11
  class DocumentStyleUtil {
5
12
  static getFirstInlineStyleValue(text, pattern) {
6
13
  if (!text)
@@ -6,6 +6,7 @@ export declare class MeasureTextSettings {
6
6
  scale?: number;
7
7
  italic?: boolean;
8
8
  bold?: boolean;
9
+ letterSpacing?: number;
9
10
  map?: any;
10
11
  }
11
12
  export declare class DocumentTextUtil {
@@ -28,6 +28,7 @@ class DocumentTextUtil {
28
28
  let totalWidth = 0;
29
29
  let lines = 1;
30
30
  let lineWidth = 0;
31
+ let charLength = 0;
31
32
  const str = string.toString().normalize('NFD');
32
33
  const words = str.split(/(\s|-)/);
33
34
  const fixedWidth = settings.width ? (settings.width * 100) / fontSize : null;
@@ -41,6 +42,7 @@ class DocumentTextUtil {
41
42
  const width = widths[variant];
42
43
  totalWidth += width;
43
44
  wordWidth += width;
45
+ charLength++;
44
46
  return true;
45
47
  });
46
48
  if (fixedWidth != null) {
@@ -51,7 +53,8 @@ class DocumentTextUtil {
51
53
  }
52
54
  }
53
55
  });
54
- let width = Math.ceil(totalWidth * (fontSize / 100));
56
+ let letterSpacingWidth = sett.letterSpacing ? charLength * sett.letterSpacing : 0;
57
+ let width = Math.ceil(totalWidth * (fontSize / 100) + letterSpacingWidth);
55
58
  let height = Math.ceil(fontSize * 1.16);
56
59
  if ((settings === null || settings === void 0 ? void 0 : settings.width) != null) {
57
60
  width = settings.width;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-util",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Documents util library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",