@contrail/documents 1.0.98 → 1.0.100
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 -6
- package/lib/index.js +24 -22
- package/lib/types/common.d.ts +75 -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 -43
- 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 -0
- package/lib/util/dynamic-text/dynamic-text-util.js +55 -0
- package/lib/util/measure-text/measure-text.d.ts +5 -0
- package/lib/util/measure-text/measure-text.js +53 -0
- package/lib/util/measure-text/widths-map.d.ts +1651 -0
- package/lib/util/measure-text/widths-map.js +1654 -0
- package/package.json +2 -1
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);
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
const formatter = new types_1.PropertyValueFormatter();
|
|
20
|
+
let text = '';
|
|
21
|
+
if (displayFunction === DynamicTextDisplayFunction.AVERAGE) {
|
|
22
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined && !isNaN(e));
|
|
23
|
+
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
|
|
24
|
+
}
|
|
25
|
+
else if (displayFunction === DynamicTextDisplayFunction.SUM) {
|
|
26
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined && !isNaN(e));
|
|
27
|
+
text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
|
|
28
|
+
}
|
|
29
|
+
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
30
|
+
text = Array.from(new Set(memberValues
|
|
31
|
+
.filter((e) => e !== null && e !== undefined)
|
|
32
|
+
.flat()
|
|
33
|
+
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
34
|
+
.sort()
|
|
35
|
+
.join(', ');
|
|
36
|
+
}
|
|
37
|
+
else if (!displayFunction ||
|
|
38
|
+
[DynamicTextDisplayFunction.FIRST, DynamicTextDisplayFunction.VALUE].includes(displayFunction)) {
|
|
39
|
+
text = formatter.formatValueForProperty(memberValues[0], property);
|
|
40
|
+
}
|
|
41
|
+
else if (displayFunction === DynamicTextDisplayFunction.LAST) {
|
|
42
|
+
text = formatter.formatValueForProperty([memberValues.length - 1], property);
|
|
43
|
+
}
|
|
44
|
+
else if (displayFunction === DynamicTextDisplayFunction.MIN) {
|
|
45
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
46
|
+
text = formatter.formatValueForProperty(Math.min(...memberValues), property);
|
|
47
|
+
}
|
|
48
|
+
else if (displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
49
|
+
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|
|
50
|
+
text = formatter.formatValueForProperty(Math.max(...memberValues), property);
|
|
51
|
+
}
|
|
52
|
+
return text;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.DynamicTextUtil = DynamicTextUtil;
|
|
@@ -0,0 +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;
|