@contrail/documents 1.0.123 → 1.1.1
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/lib/components/color-component.service.d.ts +9 -0
- package/lib/components/color-component.service.js +73 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +2 -0
- package/lib/components/item-component.service.d.ts +7 -0
- package/lib/{document-element-component-size-handler.js → components/item-component.service.js} +9 -57
- package/lib/document-element-property-binding-handler.d.ts +1 -0
- package/lib/document-element-property-binding-handler.js +29 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +1 -1
- package/lib/document-element-component-size-handler.d.ts +0 -10
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DocumentElement, SizeDefinition } from '../types';
|
|
2
|
+
export declare class ColorComponentService {
|
|
3
|
+
static isColorComponent(element: DocumentElement): boolean;
|
|
4
|
+
static isColorHexComponent(element: DocumentElement): boolean;
|
|
5
|
+
static isColorImageComponent(element: DocumentElement): boolean;
|
|
6
|
+
static getColorRectangle(elements: DocumentElement[]): DocumentElement;
|
|
7
|
+
static getColorContainer(elements: DocumentElement[]): DocumentElement;
|
|
8
|
+
static updateSizeAndPosition(elements: any, size?: SizeDefinition): any;
|
|
9
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColorComponentService = void 0;
|
|
4
|
+
const document_element_constants_1 = require("../document-element-constants");
|
|
5
|
+
class ColorComponentService {
|
|
6
|
+
static isColorComponent(element) {
|
|
7
|
+
var _a;
|
|
8
|
+
return element && element.type === 'component' && ((_a = element.modelBindings) === null || _a === void 0 ? void 0 : _a.color);
|
|
9
|
+
}
|
|
10
|
+
static isColorHexComponent(element) {
|
|
11
|
+
var _a;
|
|
12
|
+
return (ColorComponentService.isColorComponent(element) &&
|
|
13
|
+
((_a = ColorComponentService.getColorRectangle(element.elements)) === null || _a === void 0 ? void 0 : _a.type) === 'rectangle');
|
|
14
|
+
}
|
|
15
|
+
static isColorImageComponent(element) {
|
|
16
|
+
var _a;
|
|
17
|
+
return (ColorComponentService.isColorComponent(element) &&
|
|
18
|
+
((_a = ColorComponentService.getColorRectangle(element.elements)) === null || _a === void 0 ? void 0 : _a.type) === 'image');
|
|
19
|
+
}
|
|
20
|
+
static getColorRectangle(elements) {
|
|
21
|
+
return elements === null || elements === void 0 ? void 0 : elements.find((e) => ['rectangle', 'image'].indexOf(e.type) !== -1 && e.propertyBindings);
|
|
22
|
+
}
|
|
23
|
+
static getColorContainer(elements) {
|
|
24
|
+
return elements === null || elements === void 0 ? void 0 : elements.find((e) => ['rectangle'].indexOf(e.type) !== -1 && !e.propertyBindings);
|
|
25
|
+
}
|
|
26
|
+
static updateSizeAndPosition(elements, size) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
const padding = document_element_constants_1.COLOR_PADDING;
|
|
29
|
+
const container = ColorComponentService.getColorContainer(elements);
|
|
30
|
+
const colorRect = ColorComponentService.getColorRectangle(elements);
|
|
31
|
+
if (!container || !colorRect)
|
|
32
|
+
throw new Error('Invalid color element');
|
|
33
|
+
const width = (_a = size === null || size === void 0 ? void 0 : size.width) !== null && _a !== void 0 ? _a : (_b = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _b === void 0 ? void 0 : _b.width;
|
|
34
|
+
const height = (_c = size === null || size === void 0 ? void 0 : size.height) !== null && _c !== void 0 ? _c : (_d = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _d === void 0 ? void 0 : _d.height;
|
|
35
|
+
const newElements = [];
|
|
36
|
+
let lastYPosition = 0;
|
|
37
|
+
elements.forEach((element) => {
|
|
38
|
+
var _a;
|
|
39
|
+
if ((element === null || element === void 0 ? void 0 : element.enabled) === false) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
element.position = { x: padding, y: lastYPosition };
|
|
43
|
+
if (element.type === 'rectangle' || element.type === 'image') {
|
|
44
|
+
if (!(element === null || element === void 0 ? void 0 : element.propertyBindings)) {
|
|
45
|
+
lastYPosition = lastYPosition + padding;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
element.size = { width, height };
|
|
49
|
+
lastYPosition = lastYPosition + height + padding;
|
|
50
|
+
}
|
|
51
|
+
else if (element.type === 'text') {
|
|
52
|
+
if (!((_a = element.style) === null || _a === void 0 ? void 0 : _a.font)) {
|
|
53
|
+
element.style = Object.assign(Object.assign({}, element.style), { font: { size: document_element_constants_1.COLOR_FONT_SIZE } });
|
|
54
|
+
}
|
|
55
|
+
if (!(element === null || element === void 0 ? void 0 : element.size)) {
|
|
56
|
+
element.size = {};
|
|
57
|
+
}
|
|
58
|
+
element.size.height = element.style.font.size + padding;
|
|
59
|
+
element.size.width = width;
|
|
60
|
+
lastYPosition = lastYPosition + element.size.height;
|
|
61
|
+
}
|
|
62
|
+
newElements.push(element);
|
|
63
|
+
});
|
|
64
|
+
container.size = {
|
|
65
|
+
width: width + padding * 2,
|
|
66
|
+
height: lastYPosition + padding,
|
|
67
|
+
};
|
|
68
|
+
container.position = { x: 0, y: 0 };
|
|
69
|
+
newElements.unshift(container);
|
|
70
|
+
return newElements;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.ColorComponentService = ColorComponentService;
|
package/lib/components/index.js
CHANGED
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./components"), exports);
|
|
18
|
+
__exportStar(require("./color-component.service"), exports);
|
|
19
|
+
__exportStar(require("./item-component.service"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentElement } from '../types';
|
|
2
|
+
export declare class ItemComponentService {
|
|
3
|
+
static isItemComponent(element: DocumentElement): boolean;
|
|
4
|
+
static updateSizeAndPosition(propertyElements: any[], componentElement: DocumentElement, annotatedElements?: any[]): any;
|
|
5
|
+
private static getYMargin;
|
|
6
|
+
private static calculateAnnotationHeight;
|
|
7
|
+
}
|
package/lib/{document-element-component-size-handler.js → components/item-component.service.js}
RENAMED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const document_element_constants_1 = require("
|
|
5
|
-
class
|
|
6
|
-
static
|
|
3
|
+
exports.ItemComponentService = void 0;
|
|
4
|
+
const document_element_constants_1 = require("../document-element-constants");
|
|
5
|
+
class ItemComponentService {
|
|
6
|
+
static isItemComponent(element) {
|
|
7
|
+
var _a;
|
|
8
|
+
return element && element.type === 'component' && ((_a = element.modelBindings) === null || _a === void 0 ? void 0 : _a.item);
|
|
9
|
+
}
|
|
10
|
+
static updateSizeAndPosition(propertyElements, componentElement, annotatedElements = []) {
|
|
7
11
|
const newElements = [];
|
|
8
12
|
let lastYPosition = 0;
|
|
9
13
|
let width = 200;
|
|
@@ -98,57 +102,5 @@ class DocumentElementComponentSizeHandler {
|
|
|
98
102
|
}
|
|
99
103
|
return height;
|
|
100
104
|
}
|
|
101
|
-
static getColorRectangle(elements) {
|
|
102
|
-
return elements === null || elements === void 0 ? void 0 : elements.find((e) => ['rectangle', 'image'].indexOf(e.type) !== -1 && e.propertyBindings);
|
|
103
|
-
}
|
|
104
|
-
static getColorContainer(elements) {
|
|
105
|
-
return elements === null || elements === void 0 ? void 0 : elements.find((e) => ['rectangle'].indexOf(e.type) !== -1 && !e.propertyBindings);
|
|
106
|
-
}
|
|
107
|
-
static updateSizeAndPositionForColorElements(elements, size) {
|
|
108
|
-
var _a, _b, _c, _d;
|
|
109
|
-
const padding = document_element_constants_1.COLOR_PADDING;
|
|
110
|
-
const container = this.getColorContainer(elements);
|
|
111
|
-
const colorRect = this.getColorRectangle(elements);
|
|
112
|
-
if (!container || !colorRect)
|
|
113
|
-
throw new Error('Invalid color element');
|
|
114
|
-
const width = (_a = size === null || size === void 0 ? void 0 : size.width) !== null && _a !== void 0 ? _a : (_b = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _b === void 0 ? void 0 : _b.width;
|
|
115
|
-
const height = (_c = size === null || size === void 0 ? void 0 : size.height) !== null && _c !== void 0 ? _c : (_d = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _d === void 0 ? void 0 : _d.height;
|
|
116
|
-
const newElements = [];
|
|
117
|
-
let lastYPosition = 0;
|
|
118
|
-
elements.forEach((element) => {
|
|
119
|
-
var _a;
|
|
120
|
-
if ((element === null || element === void 0 ? void 0 : element.enabled) === false) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
element.position = { x: padding, y: lastYPosition };
|
|
124
|
-
if (element.type === 'rectangle' || element.type === 'image') {
|
|
125
|
-
if (!(element === null || element === void 0 ? void 0 : element.propertyBindings)) {
|
|
126
|
-
lastYPosition = lastYPosition + padding;
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
element.size = { width, height };
|
|
130
|
-
lastYPosition = lastYPosition + height + padding;
|
|
131
|
-
}
|
|
132
|
-
else if (element.type === 'text') {
|
|
133
|
-
if (!((_a = element.style) === null || _a === void 0 ? void 0 : _a.font)) {
|
|
134
|
-
element.style = Object.assign(Object.assign({}, element.style), { font: { size: document_element_constants_1.COLOR_FONT_SIZE } });
|
|
135
|
-
}
|
|
136
|
-
if (!(element === null || element === void 0 ? void 0 : element.size)) {
|
|
137
|
-
element.size = {};
|
|
138
|
-
}
|
|
139
|
-
element.size.height = element.style.font.size + padding;
|
|
140
|
-
element.size.width = width;
|
|
141
|
-
lastYPosition = lastYPosition + element.size.height;
|
|
142
|
-
}
|
|
143
|
-
newElements.push(element);
|
|
144
|
-
});
|
|
145
|
-
container.size = {
|
|
146
|
-
width: width + padding * 2,
|
|
147
|
-
height: lastYPosition + padding,
|
|
148
|
-
};
|
|
149
|
-
container.position = { x: 0, y: 0 };
|
|
150
|
-
newElements.unshift(container);
|
|
151
|
-
return newElements;
|
|
152
|
-
}
|
|
153
105
|
}
|
|
154
|
-
exports.
|
|
106
|
+
exports.ItemComponentService = ItemComponentService;
|
|
@@ -3,4 +3,5 @@ export declare class DocumentElementPropertyBindingHandler {
|
|
|
3
3
|
static bindPropertiesToElements(elements: Array<DocumentElement>, model: any): void;
|
|
4
4
|
static bindPropertiesToElement(element: DocumentElement, model: any): void;
|
|
5
5
|
static isContentTypeWebViewable(contentType: string): boolean;
|
|
6
|
+
static adjustPropertyElements(element: DocumentElement, elements: DocumentElement[], model: any): void;
|
|
6
7
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentElementPropertyBindingHandler = void 0;
|
|
4
|
+
const color_component_service_1 = require("./components/color-component.service");
|
|
5
|
+
const common_1 = require("./types/common");
|
|
4
6
|
const util_1 = require("@contrail/util");
|
|
5
7
|
class DocumentElementPropertyBindingHandler {
|
|
6
8
|
static bindPropertiesToElements(elements, model) {
|
|
7
|
-
elements.map(
|
|
9
|
+
elements.map(el => {
|
|
8
10
|
this.bindPropertiesToElement(el, model);
|
|
9
11
|
});
|
|
10
12
|
}
|
|
@@ -32,7 +34,7 @@ class DocumentElementPropertyBindingHandler {
|
|
|
32
34
|
let viewableObject;
|
|
33
35
|
const content = (_e = model === null || model === void 0 ? void 0 : model.viewable) === null || _e === void 0 ? void 0 : _e.content;
|
|
34
36
|
if ((content === null || content === void 0 ? void 0 : content.length) > 0) {
|
|
35
|
-
const primaryContent = content.find(
|
|
37
|
+
const primaryContent = content.find(c => { var _a; return (c === null || c === void 0 ? void 0 : c.id) === ((_a = model === null || model === void 0 ? void 0 : model.viewable) === null || _a === void 0 ? void 0 : _a.primaryViewableId); });
|
|
36
38
|
viewableObject = primaryContent;
|
|
37
39
|
}
|
|
38
40
|
else {
|
|
@@ -67,5 +69,30 @@ class DocumentElementPropertyBindingHandler {
|
|
|
67
69
|
}
|
|
68
70
|
return (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf('image')) > -1 && (contentType === null || contentType === void 0 ? void 0 : contentType.toLowerCase().indexOf('tiff')) < 0;
|
|
69
71
|
}
|
|
72
|
+
static adjustPropertyElements(element, elements, model) {
|
|
73
|
+
if (color_component_service_1.ColorComponentService.isColorComponent(element) && (elements === null || elements === void 0 ? void 0 : elements.length) > 0 && (model === null || model === void 0 ? void 0 : model.color)) {
|
|
74
|
+
const colorRect = color_component_service_1.ColorComponentService.getColorRectangle(elements);
|
|
75
|
+
if (model.color.primaryViewableId && colorRect.type === 'rectangle') {
|
|
76
|
+
element.modelBindings.viewable = element.modelBindings.color;
|
|
77
|
+
model.viewable = model.color;
|
|
78
|
+
colorRect.type = 'image';
|
|
79
|
+
colorRect.style = { background: { size: common_1.BackgroundSizeType.CONTAIN } };
|
|
80
|
+
colorRect.propertyBindings = { url: 'viewable.mediumViewableDownloadUrl' };
|
|
81
|
+
}
|
|
82
|
+
else if (!model.color.primaryViewableId && colorRect.type === 'image') {
|
|
83
|
+
colorRect.type = 'rectangle';
|
|
84
|
+
colorRect.size.height = colorRect.size.width;
|
|
85
|
+
colorRect.style = {
|
|
86
|
+
border: {
|
|
87
|
+
width: 0,
|
|
88
|
+
color: '#FFFFFF',
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
colorRect.propertyBindings = { 'style.backgroundColor': 'color.hexCode' };
|
|
92
|
+
delete colorRect.url;
|
|
93
|
+
delete colorRect.alternateUrls;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
70
97
|
}
|
|
71
98
|
exports.DocumentElementPropertyBindingHandler = DocumentElementPropertyBindingHandler;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './types';
|
|
|
2
2
|
export * from './components';
|
|
3
3
|
export * from './document-element-factory';
|
|
4
4
|
export * from './document-element-property-binding-handler';
|
|
5
|
-
export * from './document-element-component-size-handler';
|
|
6
5
|
export * from './document-action';
|
|
7
6
|
export * from './util/measure-text/measure-text';
|
|
8
7
|
export * from './util/dynamic-text/dynamic-text-util';
|
package/lib/index.js
CHANGED
|
@@ -18,7 +18,6 @@ __exportStar(require("./types"), exports);
|
|
|
18
18
|
__exportStar(require("./components"), exports);
|
|
19
19
|
__exportStar(require("./document-element-factory"), exports);
|
|
20
20
|
__exportStar(require("./document-element-property-binding-handler"), exports);
|
|
21
|
-
__exportStar(require("./document-element-component-size-handler"), exports);
|
|
22
21
|
__exportStar(require("./document-action"), exports);
|
|
23
22
|
__exportStar(require("./util/measure-text/measure-text"), exports);
|
|
24
23
|
__exportStar(require("./util/dynamic-text/dynamic-text-util"), exports);
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SizeDefinition } from './types';
|
|
2
|
-
import { DocumentElement } from './types/document-element';
|
|
3
|
-
export declare class DocumentElementComponentSizeHandler {
|
|
4
|
-
static updateSizeAndPositionForPropertyElements(propertyElements: any[], componentElement: DocumentElement, annotatedElements?: any[]): any;
|
|
5
|
-
private static getYMargin;
|
|
6
|
-
private static calculateAnnotationHeight;
|
|
7
|
-
static getColorRectangle(elements: DocumentElement[]): DocumentElement;
|
|
8
|
-
static getColorContainer(elements: DocumentElement[]): DocumentElement;
|
|
9
|
-
static updateSizeAndPositionForColorElements(elements: any, size?: SizeDefinition): any;
|
|
10
|
-
}
|