@contrail/documents 1.0.102 → 1.0.104
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.
- package/README.md +1 -1
- package/lib/components/components.d.ts +269 -269
- package/lib/components/components.js +92 -92
- package/lib/components/index.d.ts +1 -1
- package/lib/components/index.js +17 -17
- package/lib/document-action.d.ts +7 -7
- package/lib/document-action.js +10 -10
- package/lib/document-element-component-size-handler.d.ts +4 -4
- package/lib/document-element-component-size-handler.js +55 -55
- package/lib/document-element-factory.d.ts +12 -12
- package/lib/document-element-factory.js +77 -77
- package/lib/document-element-property-binding-handler.d.ts +6 -6
- package/lib/document-element-property-binding-handler.js +71 -71
- package/lib/index.d.ts +8 -8
- package/lib/index.js +24 -24
- package/lib/types/common.d.ts +82 -75
- package/lib/types/common.js +8 -8
- package/lib/types/data-object.d.ts +6 -6
- package/lib/types/data-object.js +2 -2
- package/lib/types/document-change.d.ts +17 -17
- package/lib/types/document-change.js +12 -12
- package/lib/types/document-element-event.d.ts +24 -24
- package/lib/types/document-element-event.js +2 -2
- package/lib/types/document-element-holder.d.ts +8 -8
- package/lib/types/document-element-holder.js +2 -2
- package/lib/types/document-element.d.ts +44 -44
- package/lib/types/document-element.js +2 -2
- package/lib/types/document-navigation-event.d.ts +5 -5
- package/lib/types/document-navigation-event.js +2 -2
- package/lib/types/document.d.ts +24 -24
- package/lib/types/document.js +2 -2
- package/lib/types/element-transformation.d.ts +18 -18
- package/lib/types/element-transformation.js +2 -2
- package/lib/types/index.d.ts +9 -9
- package/lib/types/index.js +25 -25
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +14 -14
- package/lib/util/dynamic-text/dynamic-text-util.js +58 -58
- package/lib/util/measure-text/measure-text.d.ts +5 -5
- package/lib/util/measure-text/measure-text.js +53 -53
- package/lib/util/measure-text/widths-map.d.ts +1651 -1651
- package/lib/util/measure-text/widths-map.js +1654 -1654
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export interface DocumentNavigationEvent {
|
|
2
|
-
eventType?: string;
|
|
3
|
-
navigationType?: string;
|
|
4
|
-
data?: any;
|
|
5
|
-
}
|
|
1
|
+
export interface DocumentNavigationEvent {
|
|
2
|
+
eventType?: string;
|
|
3
|
+
navigationType?: string;
|
|
4
|
+
data?: any;
|
|
5
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/types/document.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { PositionDefinition, SizeDefinition, StyleDefinition, ViewBox } from './common';
|
|
2
|
-
import { DocumentElement } from './document-element';
|
|
3
|
-
export interface ImportReferenceDetail {
|
|
4
|
-
importedSlideReference?: string;
|
|
5
|
-
importedFileReference?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface Document {
|
|
8
|
-
id?: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
elements?: Array<DocumentElement>;
|
|
11
|
-
size?: SizeDefinition;
|
|
12
|
-
style?: StyleDefinition;
|
|
13
|
-
model?: any;
|
|
14
|
-
modelBindings?: any;
|
|
15
|
-
background?: Array<DocumentElement>;
|
|
16
|
-
importedFrom?: ImportReferenceDetail;
|
|
17
|
-
startingViewBox?: ViewBox;
|
|
18
|
-
startingLocation?: {
|
|
19
|
-
position: PositionDefinition;
|
|
20
|
-
zoom: number;
|
|
21
|
-
};
|
|
22
|
-
clipContent?: boolean;
|
|
23
|
-
ownedByReference?: string;
|
|
24
|
-
}
|
|
1
|
+
import { PositionDefinition, SizeDefinition, StyleDefinition, ViewBox } from './common';
|
|
2
|
+
import { DocumentElement } from './document-element';
|
|
3
|
+
export interface ImportReferenceDetail {
|
|
4
|
+
importedSlideReference?: string;
|
|
5
|
+
importedFileReference?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Document {
|
|
8
|
+
id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
elements?: Array<DocumentElement>;
|
|
11
|
+
size?: SizeDefinition;
|
|
12
|
+
style?: StyleDefinition;
|
|
13
|
+
model?: any;
|
|
14
|
+
modelBindings?: any;
|
|
15
|
+
background?: Array<DocumentElement>;
|
|
16
|
+
importedFrom?: ImportReferenceDetail;
|
|
17
|
+
startingViewBox?: ViewBox;
|
|
18
|
+
startingLocation?: {
|
|
19
|
+
position: PositionDefinition;
|
|
20
|
+
zoom: number;
|
|
21
|
+
};
|
|
22
|
+
clipContent?: boolean;
|
|
23
|
+
ownedByReference?: string;
|
|
24
|
+
}
|
package/lib/types/document.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export interface ScaleTransformation {
|
|
2
|
-
x?: number;
|
|
3
|
-
y?: number;
|
|
4
|
-
}
|
|
5
|
-
export interface TranslateTransformation {
|
|
6
|
-
x?: number;
|
|
7
|
-
y?: number;
|
|
8
|
-
}
|
|
9
|
-
export interface RotationTransformation {
|
|
10
|
-
angle?: number;
|
|
11
|
-
cx?: number;
|
|
12
|
-
cy?: number;
|
|
13
|
-
}
|
|
14
|
-
export interface ElementTransformation {
|
|
15
|
-
translate?: TranslateTransformation;
|
|
16
|
-
scale?: ScaleTransformation;
|
|
17
|
-
rotate?: RotationTransformation;
|
|
18
|
-
}
|
|
1
|
+
export interface ScaleTransformation {
|
|
2
|
+
x?: number;
|
|
3
|
+
y?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface TranslateTransformation {
|
|
6
|
+
x?: number;
|
|
7
|
+
y?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface RotationTransformation {
|
|
10
|
+
angle?: number;
|
|
11
|
+
cx?: number;
|
|
12
|
+
cy?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ElementTransformation {
|
|
15
|
+
translate?: TranslateTransformation;
|
|
16
|
+
scale?: ScaleTransformation;
|
|
17
|
+
rotate?: RotationTransformation;
|
|
18
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './common';
|
|
2
|
-
export * from './data-object';
|
|
3
|
-
export * from './document-change';
|
|
4
|
-
export * from './document-element-event';
|
|
5
|
-
export * from './document-element-holder';
|
|
6
|
-
export * from './document-element';
|
|
7
|
-
export * from './document-navigation-event';
|
|
8
|
-
export * from './document';
|
|
9
|
-
export * from './element-transformation';
|
|
1
|
+
export * from './common';
|
|
2
|
+
export * from './data-object';
|
|
3
|
+
export * from './document-change';
|
|
4
|
+
export * from './document-element-event';
|
|
5
|
+
export * from './document-element-holder';
|
|
6
|
+
export * from './document-element';
|
|
7
|
+
export * from './document-navigation-event';
|
|
8
|
+
export * from './document';
|
|
9
|
+
export * from './element-transformation';
|
package/lib/types/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./common"), exports);
|
|
18
|
-
__exportStar(require("./data-object"), exports);
|
|
19
|
-
__exportStar(require("./document-change"), exports);
|
|
20
|
-
__exportStar(require("./document-element-event"), exports);
|
|
21
|
-
__exportStar(require("./document-element-holder"), exports);
|
|
22
|
-
__exportStar(require("./document-element"), exports);
|
|
23
|
-
__exportStar(require("./document-navigation-event"), exports);
|
|
24
|
-
__exportStar(require("./document"), exports);
|
|
25
|
-
__exportStar(require("./element-transformation"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./data-object"), exports);
|
|
19
|
+
__exportStar(require("./document-change"), exports);
|
|
20
|
+
__exportStar(require("./document-element-event"), exports);
|
|
21
|
+
__exportStar(require("./document-element-holder"), exports);
|
|
22
|
+
__exportStar(require("./document-element"), exports);
|
|
23
|
+
__exportStar(require("./document-navigation-event"), exports);
|
|
24
|
+
__exportStar(require("./document"), exports);
|
|
25
|
+
__exportStar(require("./element-transformation"), exports);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export declare enum DynamicTextDisplayFunction {
|
|
2
|
-
VALUE = "value",
|
|
3
|
-
LABEL = "label",
|
|
4
|
-
UNIQUE_ARRAY = "uniqueArray",
|
|
5
|
-
FIRST = "first",
|
|
6
|
-
LAST = "last",
|
|
7
|
-
MIN = "min",
|
|
8
|
-
MAX = "max",
|
|
9
|
-
AVERAGE = "average",
|
|
10
|
-
SUM = "sum"
|
|
11
|
-
}
|
|
12
|
-
export declare class DynamicTextUtil {
|
|
13
|
-
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
14
|
-
}
|
|
1
|
+
export declare enum DynamicTextDisplayFunction {
|
|
2
|
+
VALUE = "value",
|
|
3
|
+
LABEL = "label",
|
|
4
|
+
UNIQUE_ARRAY = "uniqueArray",
|
|
5
|
+
FIRST = "first",
|
|
6
|
+
LAST = "last",
|
|
7
|
+
MIN = "min",
|
|
8
|
+
MAX = "max",
|
|
9
|
+
AVERAGE = "average",
|
|
10
|
+
SUM = "sum"
|
|
11
|
+
}
|
|
12
|
+
export declare class DynamicTextUtil {
|
|
13
|
+
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
14
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamicTextUtil = exports.DynamicTextDisplayFunction = void 0;
|
|
4
|
-
const types_1 = require("@contrail/types");
|
|
5
|
-
var DynamicTextDisplayFunction;
|
|
6
|
-
(function (DynamicTextDisplayFunction) {
|
|
7
|
-
DynamicTextDisplayFunction["VALUE"] = "value";
|
|
8
|
-
DynamicTextDisplayFunction["LABEL"] = "label";
|
|
9
|
-
DynamicTextDisplayFunction["UNIQUE_ARRAY"] = "uniqueArray";
|
|
10
|
-
DynamicTextDisplayFunction["FIRST"] = "first";
|
|
11
|
-
DynamicTextDisplayFunction["LAST"] = "last";
|
|
12
|
-
DynamicTextDisplayFunction["MIN"] = "min";
|
|
13
|
-
DynamicTextDisplayFunction["MAX"] = "max";
|
|
14
|
-
DynamicTextDisplayFunction["AVERAGE"] = "average";
|
|
15
|
-
DynamicTextDisplayFunction["SUM"] = "sum";
|
|
16
|
-
})(DynamicTextDisplayFunction = exports.DynamicTextDisplayFunction || (exports.DynamicTextDisplayFunction = {}));
|
|
17
|
-
class DynamicTextUtil {
|
|
18
|
-
static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
|
|
19
|
-
let text = '';
|
|
20
|
-
if (memberValues.length === 0) {
|
|
21
|
-
return text;
|
|
22
|
-
}
|
|
23
|
-
const formatter = new types_1.PropertyValueFormatter();
|
|
24
|
-
if (displayFunction === DynamicTextDisplayFunction.AVERAGE) {
|
|
25
|
-
memberValues = memberValues.filter(
|
|
26
|
-
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
|
|
27
|
-
}
|
|
28
|
-
else if (displayFunction === DynamicTextDisplayFunction.SUM) {
|
|
29
|
-
memberValues = memberValues.filter(
|
|
30
|
-
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
|
|
31
|
-
}
|
|
32
|
-
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
33
|
-
text = Array.from(new Set(memberValues
|
|
34
|
-
.filter(e => e !== null && e !== undefined)
|
|
35
|
-
.flat()
|
|
36
|
-
.map(e => formatter.formatValueForProperty(e, property))))
|
|
37
|
-
.sort()
|
|
38
|
-
.join(', ');
|
|
39
|
-
}
|
|
40
|
-
else if (!displayFunction ||
|
|
41
|
-
[DynamicTextDisplayFunction.FIRST, DynamicTextDisplayFunction.VALUE].includes(displayFunction)) {
|
|
42
|
-
text = formatter.formatValueForProperty(memberValues[0], property);
|
|
43
|
-
}
|
|
44
|
-
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
45
|
-
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
46
|
-
}
|
|
47
|
-
else if (displayFunction === DynamicTextDisplayFunction.MIN) {
|
|
48
|
-
memberValues = memberValues.filter(e => e !== null && e !== undefined);
|
|
49
|
-
text = formatter.formatValueForProperty(Math.min(...memberValues), property);
|
|
50
|
-
}
|
|
51
|
-
else if (displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
52
|
-
memberValues = memberValues.filter(e => e !== null && e !== undefined);
|
|
53
|
-
text = formatter.formatValueForProperty(Math.max(...memberValues), property);
|
|
54
|
-
}
|
|
55
|
-
return text;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.DynamicTextUtil = DynamicTextUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicTextUtil = exports.DynamicTextDisplayFunction = void 0;
|
|
4
|
+
const types_1 = require("@contrail/types");
|
|
5
|
+
var DynamicTextDisplayFunction;
|
|
6
|
+
(function (DynamicTextDisplayFunction) {
|
|
7
|
+
DynamicTextDisplayFunction["VALUE"] = "value";
|
|
8
|
+
DynamicTextDisplayFunction["LABEL"] = "label";
|
|
9
|
+
DynamicTextDisplayFunction["UNIQUE_ARRAY"] = "uniqueArray";
|
|
10
|
+
DynamicTextDisplayFunction["FIRST"] = "first";
|
|
11
|
+
DynamicTextDisplayFunction["LAST"] = "last";
|
|
12
|
+
DynamicTextDisplayFunction["MIN"] = "min";
|
|
13
|
+
DynamicTextDisplayFunction["MAX"] = "max";
|
|
14
|
+
DynamicTextDisplayFunction["AVERAGE"] = "average";
|
|
15
|
+
DynamicTextDisplayFunction["SUM"] = "sum";
|
|
16
|
+
})(DynamicTextDisplayFunction = exports.DynamicTextDisplayFunction || (exports.DynamicTextDisplayFunction = {}));
|
|
17
|
+
class DynamicTextUtil {
|
|
18
|
+
static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
|
|
19
|
+
let text = '';
|
|
20
|
+
if (memberValues.length === 0) {
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
const formatter = new types_1.PropertyValueFormatter();
|
|
24
|
+
if (displayFunction === DynamicTextDisplayFunction.AVERAGE) {
|
|
25
|
+
memberValues = memberValues.filter(Number);
|
|
26
|
+
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
|
|
27
|
+
}
|
|
28
|
+
else if (displayFunction === DynamicTextDisplayFunction.SUM) {
|
|
29
|
+
memberValues = memberValues.filter(Number);
|
|
30
|
+
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
|
|
31
|
+
}
|
|
32
|
+
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
33
|
+
text = Array.from(new Set(memberValues
|
|
34
|
+
.filter((e) => e !== null && e !== undefined)
|
|
35
|
+
.flat()
|
|
36
|
+
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
37
|
+
.sort()
|
|
38
|
+
.join(', ');
|
|
39
|
+
}
|
|
40
|
+
else if (!displayFunction ||
|
|
41
|
+
[DynamicTextDisplayFunction.FIRST, DynamicTextDisplayFunction.VALUE].includes(displayFunction)) {
|
|
42
|
+
text = formatter.formatValueForProperty(memberValues[0], property);
|
|
43
|
+
}
|
|
44
|
+
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
45
|
+
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
46
|
+
}
|
|
47
|
+
else if (displayFunction === DynamicTextDisplayFunction.MIN) {
|
|
48
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
49
|
+
text = formatter.formatValueForProperty(Math.min(...memberValues), property);
|
|
50
|
+
}
|
|
51
|
+
else if (displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
52
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
53
|
+
text = formatter.formatValueForProperty(Math.max(...memberValues), property);
|
|
54
|
+
}
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.DynamicTextUtil = DynamicTextUtil;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const measureText: (string: any, settings: any) => {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
};
|
|
5
|
-
export default measureText;
|
|
1
|
+
declare const measureText: (string: any, settings: any) => {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
};
|
|
5
|
+
export default measureText;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const widths_map_1 = require("./widths-map");
|
|
4
|
-
const settingsDefaults = { fontFamily: 'Arial', fontSize: 14 };
|
|
5
|
-
const measureText = (string, settings) => {
|
|
6
|
-
if (string === null || string === undefined) {
|
|
7
|
-
return { width: 0, height: 0 };
|
|
8
|
-
}
|
|
9
|
-
const sett = Object.assign(Object.assign({}, settingsDefaults), settings);
|
|
10
|
-
let font = sett.fontFamily.toLowerCase();
|
|
11
|
-
const fontSize = sett.fontSize;
|
|
12
|
-
const variant = 0 + (sett.bold ? 1 : 0) + (sett.italic ? 2 : 0);
|
|
13
|
-
const map = sett.map || widths_map_1.WIDTHS_MAP;
|
|
14
|
-
const available = Object.keys(map);
|
|
15
|
-
if (available.indexOf(font) === -1) {
|
|
16
|
-
font = 'arial';
|
|
17
|
-
}
|
|
18
|
-
let totalWidth = 0;
|
|
19
|
-
let lines = 1;
|
|
20
|
-
let lineWidth = 0;
|
|
21
|
-
const str = string.toString().normalize('NFD');
|
|
22
|
-
const words = str.split(/(\s|-)/);
|
|
23
|
-
const fixedWidth = settings.width ? (settings.width * 100) / fontSize : null;
|
|
24
|
-
words.forEach((word, index) => {
|
|
25
|
-
let wordWidth = 0;
|
|
26
|
-
word.split('').forEach((char) => {
|
|
27
|
-
if (/[\x00-\x1F]/.test(char)) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
const widths = map[font][char] || map[font].x;
|
|
31
|
-
const width = widths[variant];
|
|
32
|
-
totalWidth += width;
|
|
33
|
-
wordWidth += width;
|
|
34
|
-
return true;
|
|
35
|
-
});
|
|
36
|
-
if (fixedWidth != null) {
|
|
37
|
-
lineWidth = lineWidth + wordWidth;
|
|
38
|
-
if (lineWidth > fixedWidth) {
|
|
39
|
-
lineWidth = wordWidth % fixedWidth;
|
|
40
|
-
lines = (index === 0 ? 0 : lines) + Math.max(1, Math.ceil(wordWidth / fixedWidth));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
let width = Math.ceil(totalWidth * (fontSize / 100));
|
|
45
|
-
let height = Math.ceil(fontSize * 1.16);
|
|
46
|
-
if ((settings === null || settings === void 0 ? void 0 : settings.width) != null) {
|
|
47
|
-
width = settings.width;
|
|
48
|
-
height = height * lines;
|
|
49
|
-
}
|
|
50
|
-
height = height + 1 * ((settings === null || settings === void 0 ? void 0 : settings.scale) || 1);
|
|
51
|
-
return { width, height };
|
|
52
|
-
};
|
|
53
|
-
exports.default = measureText;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const widths_map_1 = require("./widths-map");
|
|
4
|
+
const settingsDefaults = { fontFamily: 'Arial', fontSize: 14 };
|
|
5
|
+
const measureText = (string, settings) => {
|
|
6
|
+
if (string === null || string === undefined) {
|
|
7
|
+
return { width: 0, height: 0 };
|
|
8
|
+
}
|
|
9
|
+
const sett = Object.assign(Object.assign({}, settingsDefaults), settings);
|
|
10
|
+
let font = sett.fontFamily.toLowerCase();
|
|
11
|
+
const fontSize = sett.fontSize;
|
|
12
|
+
const variant = 0 + (sett.bold ? 1 : 0) + (sett.italic ? 2 : 0);
|
|
13
|
+
const map = sett.map || widths_map_1.WIDTHS_MAP;
|
|
14
|
+
const available = Object.keys(map);
|
|
15
|
+
if (available.indexOf(font) === -1) {
|
|
16
|
+
font = 'arial';
|
|
17
|
+
}
|
|
18
|
+
let totalWidth = 0;
|
|
19
|
+
let lines = 1;
|
|
20
|
+
let lineWidth = 0;
|
|
21
|
+
const str = string.toString().normalize('NFD');
|
|
22
|
+
const words = str.split(/(\s|-)/);
|
|
23
|
+
const fixedWidth = settings.width ? (settings.width * 100) / fontSize : null;
|
|
24
|
+
words.forEach((word, index) => {
|
|
25
|
+
let wordWidth = 0;
|
|
26
|
+
word.split('').forEach((char) => {
|
|
27
|
+
if (/[\x00-\x1F]/.test(char)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const widths = map[font][char] || map[font].x;
|
|
31
|
+
const width = widths[variant];
|
|
32
|
+
totalWidth += width;
|
|
33
|
+
wordWidth += width;
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
if (fixedWidth != null) {
|
|
37
|
+
lineWidth = lineWidth + wordWidth;
|
|
38
|
+
if (lineWidth > fixedWidth) {
|
|
39
|
+
lineWidth = wordWidth % fixedWidth;
|
|
40
|
+
lines = (index === 0 ? 0 : lines) + Math.max(1, Math.ceil(wordWidth / fixedWidth));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let width = Math.ceil(totalWidth * (fontSize / 100));
|
|
45
|
+
let height = Math.ceil(fontSize * 1.16);
|
|
46
|
+
if ((settings === null || settings === void 0 ? void 0 : settings.width) != null) {
|
|
47
|
+
width = settings.width;
|
|
48
|
+
height = height * lines;
|
|
49
|
+
}
|
|
50
|
+
height = height + 1 * ((settings === null || settings === void 0 ? void 0 : settings.scale) || 1);
|
|
51
|
+
return { width, height };
|
|
52
|
+
};
|
|
53
|
+
exports.default = measureText;
|