@letscooee/web-sdk 0.0.4 → 0.0.8
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/CHANGELOG.md +20 -1
- package/README.md +6 -4
- package/dist/constants.js +11 -2
- package/dist/index-preview.js +3 -0
- package/dist/init/visibility-listener.js +2 -2
- package/dist/models/event/event-response.js +1 -0
- package/dist/models/trigger/action/click-action-executor.js +260 -0
- package/dist/models/trigger/blocks/background.js +33 -0
- package/dist/models/trigger/blocks/border.js +49 -0
- package/dist/models/trigger/blocks/click-action.js +9 -0
- package/dist/models/trigger/blocks/color.js +48 -0
- package/dist/models/trigger/blocks/colour.js +1 -0
- package/dist/models/trigger/blocks/flex.js +1 -0
- package/dist/models/trigger/blocks/font.js +1 -0
- package/dist/models/trigger/blocks/glossy.js +25 -0
- package/dist/models/trigger/blocks/gradient.js +1 -0
- package/dist/models/trigger/blocks/image.js +1 -0
- package/dist/models/trigger/blocks/index.js +5 -0
- package/dist/models/trigger/blocks/position.js +1 -0
- package/dist/models/trigger/blocks/shadow.js +1 -0
- package/dist/models/trigger/blocks/spacing.js +1 -0
- package/dist/models/trigger/blocks/transform.js +13 -0
- package/dist/models/trigger/elements/base-element.js +50 -0
- package/dist/models/trigger/elements/base-text-element.js +1 -0
- package/dist/models/trigger/elements/group-element.js +1 -0
- package/dist/models/trigger/elements/image-element.js +26 -0
- package/dist/models/trigger/elements/index.js +4 -0
- package/dist/models/trigger/elements/shape-element.js +24 -0
- package/dist/models/trigger/elements/text-element.js +81 -0
- package/dist/models/trigger/embedded-trigger.js +26 -0
- package/dist/models/trigger/inapp/container.js +104 -0
- package/dist/models/trigger/inapp/in-app-trigger.js +32 -0
- package/dist/models/trigger/inapp/layer.js +1 -0
- package/dist/models/trigger/trigger-data.js +9 -3
- package/dist/models/trigger/trigger-helper.js +52 -0
- package/dist/renderer/base-text-renderer.js +77 -0
- package/dist/renderer/block-processor.js +233 -0
- package/dist/renderer/block-renderer.js +44 -0
- package/dist/renderer/container-renderer.js +46 -0
- package/dist/renderer/group-renderer.js +44 -0
- package/dist/renderer/iFrame-renderer.js +82 -0
- package/dist/renderer/image-renderer.js +44 -0
- package/dist/renderer/in-app-renderer.js +84 -0
- package/dist/renderer/index.js +26 -0
- package/dist/renderer/renderer.js +97 -0
- package/dist/renderer/root-container-renderer.js +54 -0
- package/dist/renderer/shape-renderer.js +39 -0
- package/dist/renderer/text-renderer.js +48 -0
- package/dist/sdk-preview.min.js +2 -0
- package/dist/sdk-preview.min.js.LICENSE.txt +8 -0
- package/dist/sdk.min.js +1 -1
- package/dist/services/http-api.service.js +33 -9
- package/dist/services/user-auth.service.js +7 -7
- package/dist/session/new-session-executor.js +2 -2
- package/dist/session/session-manager.js +1 -0
- package/dist/utils/local-storage-helper.js +22 -0
- package/dist/utils/log.js +17 -13
- package/package.json +10 -7
- package/webpack-preview.config.js +10 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { Renderer } from './renderer';
|
|
2
|
+
import UAParser from 'ua-parser-js';
|
|
3
|
+
import { ClickActionExecutor } from '../models/trigger/action/click-action-executor';
|
|
4
|
+
import { getScalingFactor } from './index';
|
|
5
|
+
import { Container } from '../models/trigger/inapp/container';
|
|
6
|
+
/**
|
|
7
|
+
* Process all the block of in-app
|
|
8
|
+
*
|
|
9
|
+
* @author Abhishek Taparia
|
|
10
|
+
* @version 0.0.5
|
|
11
|
+
*/
|
|
12
|
+
var BlockProcessor = /** @class */ (function () {
|
|
13
|
+
function BlockProcessor(parentHTMLEl, inappElement) {
|
|
14
|
+
this.renderer = Renderer.get();
|
|
15
|
+
this.screenWidth = 0;
|
|
16
|
+
this.screenHeight = 0;
|
|
17
|
+
this.scalingFactor = getScalingFactor();
|
|
18
|
+
this.parentHTMLEl = parentHTMLEl;
|
|
19
|
+
this.inappElement = inappElement;
|
|
20
|
+
this.screenWidth = this.renderer.getWidth();
|
|
21
|
+
this.screenHeight = this.renderer.getHeight();
|
|
22
|
+
}
|
|
23
|
+
BlockProcessor.prototype.getHTMLElement = function () {
|
|
24
|
+
return this.inappHTMLEl;
|
|
25
|
+
};
|
|
26
|
+
BlockProcessor.prototype.insertElement = function () {
|
|
27
|
+
this.renderer.appendChild(this.parentHTMLEl, this.inappHTMLEl);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Process all the common blocks that can be placed in layer and container
|
|
31
|
+
*/
|
|
32
|
+
BlockProcessor.prototype.processCommonBlocks = function () {
|
|
33
|
+
this.processWidthAndHeight();
|
|
34
|
+
this.processPositionBlock();
|
|
35
|
+
this.processBorderBlock();
|
|
36
|
+
this.processBackgroundBlock();
|
|
37
|
+
this.processSpaceBlock();
|
|
38
|
+
this.processTransformBlock();
|
|
39
|
+
this.registerAction();
|
|
40
|
+
this.renderer.setStyle(this.inappHTMLEl, 'outline', 'none');
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Process width and height
|
|
44
|
+
*/
|
|
45
|
+
BlockProcessor.prototype.processWidthAndHeight = function () {
|
|
46
|
+
this.renderer.setStyle(this.inappHTMLEl, 'box-sizing', 'border-box');
|
|
47
|
+
if (this.inappElement.w) {
|
|
48
|
+
this.renderer.setStyle(this.inappHTMLEl, 'width', this.getSizePx(this.inappElement.w));
|
|
49
|
+
}
|
|
50
|
+
if (this.inappElement.h) {
|
|
51
|
+
this.renderer.setStyle(this.inappHTMLEl, 'height', this.getSizePx(this.inappElement.h));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get calculated size according to the device by multiplying it with scaling factor.
|
|
56
|
+
* @param {number} value size passed in payload
|
|
57
|
+
* @return number calculated size
|
|
58
|
+
*/
|
|
59
|
+
BlockProcessor.prototype.getSizePx = function (value) {
|
|
60
|
+
return (value * this.scalingFactor) + 'px';
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Process position block of the element
|
|
64
|
+
*/
|
|
65
|
+
BlockProcessor.prototype.processPositionBlock = function () {
|
|
66
|
+
if (!this.inappElement.x) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.renderer.setStyle(this.inappHTMLEl, 'position', 'absolute');
|
|
70
|
+
if (this.inappElement.x)
|
|
71
|
+
this.renderer.setStyle(this.inappHTMLEl, 'top', this.getSizePx(this.inappElement.y));
|
|
72
|
+
if (this.inappElement.y)
|
|
73
|
+
this.renderer.setStyle(this.inappHTMLEl, 'left', this.getSizePx(this.inappElement.x));
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Process border block of the element
|
|
77
|
+
*/
|
|
78
|
+
BlockProcessor.prototype.processBorderBlock = function () {
|
|
79
|
+
var _a;
|
|
80
|
+
var border = this.inappElement.br;
|
|
81
|
+
if (!border) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Just to make sure radius is not a negative number
|
|
85
|
+
if (border.radius && border.radius > 0) {
|
|
86
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-radius', this.getSizePx(border.radius));
|
|
87
|
+
}
|
|
88
|
+
// Just to make sure width is not a negative number
|
|
89
|
+
if (border.width && border.width > 0) {
|
|
90
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-width', this.getSizePx(border.width));
|
|
91
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-style', (_a = border.style) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
92
|
+
if (border.color) {
|
|
93
|
+
this.processColourBlock(border.color, 'border-color');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-color', 'black');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Process space block of the element which include margin and padding.
|
|
102
|
+
*/
|
|
103
|
+
BlockProcessor.prototype.processSpaceBlock = function () {
|
|
104
|
+
var space = this.inappElement.spc;
|
|
105
|
+
if (!space) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (space.p)
|
|
109
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding', this.getSizePx(space.p));
|
|
110
|
+
if (space.pt)
|
|
111
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-top', this.getSizePx(space.pt));
|
|
112
|
+
if (space.pb)
|
|
113
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-bottom', this.getSizePx(space.pb));
|
|
114
|
+
if (space.pl)
|
|
115
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-left', this.getSizePx(space.pl));
|
|
116
|
+
if (space.pr)
|
|
117
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-right', this.getSizePx(space.pr));
|
|
118
|
+
this.renderer.setStyle(this.inappHTMLEl, 'margin', '0 !important');
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Process transform block of the element
|
|
122
|
+
*/
|
|
123
|
+
BlockProcessor.prototype.processTransformBlock = function () {
|
|
124
|
+
var transform = this.inappElement.trf;
|
|
125
|
+
if (!transform) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (transform.rotate) {
|
|
129
|
+
this.renderer.setStyle(this.inappHTMLEl, 'transform', "rotate(" + transform.rotate + "deg)");
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Register click-to-action(CTA) block of the element
|
|
134
|
+
*/
|
|
135
|
+
BlockProcessor.prototype.registerAction = function () {
|
|
136
|
+
var action = this.inappElement.clc;
|
|
137
|
+
if (!action) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.inappHTMLEl.addEventListener('click', function () {
|
|
141
|
+
new ClickActionExecutor(action).execute();
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Process background block of the element
|
|
146
|
+
*/
|
|
147
|
+
BlockProcessor.prototype.processBackgroundBlock = function () {
|
|
148
|
+
var _a;
|
|
149
|
+
var bg = this.inappElement.bg;
|
|
150
|
+
if (!bg) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
var htmlElement = this.inappHTMLEl;
|
|
154
|
+
// For container, the background must be applied to its parent i.e. root container
|
|
155
|
+
if (this.inappElement instanceof Container) {
|
|
156
|
+
htmlElement = htmlElement.parentElement;
|
|
157
|
+
}
|
|
158
|
+
var prefix = '';
|
|
159
|
+
if ((_a = new UAParser().getBrowser().name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('safari')) {
|
|
160
|
+
prefix = '-webkit-';
|
|
161
|
+
}
|
|
162
|
+
if (bg.glossy) {
|
|
163
|
+
this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "blur(" + bg.glossy.radius + "px)");
|
|
164
|
+
if (bg.glossy.color) {
|
|
165
|
+
this.processColourBlock(bg.glossy.color, 'background', htmlElement);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (bg.solid) {
|
|
169
|
+
if (bg.solid.grad) {
|
|
170
|
+
this.processGradient(bg.solid.grad, 'background');
|
|
171
|
+
}
|
|
172
|
+
else if (bg.solid.hex) {
|
|
173
|
+
this.renderer.setStyle(htmlElement, 'background', bg.solid.rgba);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (bg.img) {
|
|
177
|
+
if (!bg.img.src) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
var value = "url(\"" + bg.img.src + "\") no-repeat center";
|
|
181
|
+
this.renderer.setStyle(htmlElement, 'background', value);
|
|
182
|
+
this.renderer.setStyle(htmlElement, 'background-size', 'cover');
|
|
183
|
+
if (bg.img.a) {
|
|
184
|
+
this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "opacity(" + bg.img.a + ")");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Process linear gradient and add to the element
|
|
190
|
+
* @param {Gradient} grad gradient value
|
|
191
|
+
* @param {string} attribute attribute on which gradient needs to be applied
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
BlockProcessor.prototype.processGradient = function (grad, attribute) {
|
|
195
|
+
if (grad.type === 'LINEAR') {
|
|
196
|
+
var linearFunctionString = "linear-gradient(" + grad.ang + "deg, " + grad.c1 + ", " + grad.c2;
|
|
197
|
+
if (grad.c3) {
|
|
198
|
+
linearFunctionString += ", " + grad.c3;
|
|
199
|
+
}
|
|
200
|
+
if (grad.c4) {
|
|
201
|
+
linearFunctionString += ", " + grad.c4;
|
|
202
|
+
}
|
|
203
|
+
if (grad.c5) {
|
|
204
|
+
linearFunctionString += ", " + grad.c5;
|
|
205
|
+
}
|
|
206
|
+
linearFunctionString += ")";
|
|
207
|
+
var gradient = linearFunctionString;
|
|
208
|
+
this.renderer.setStyle(this.inappHTMLEl, attribute, gradient);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Process colour block of the element
|
|
213
|
+
* @param {Color} colour colour data of the element
|
|
214
|
+
* @param {string} attribute attribute on which colour data need to be applied
|
|
215
|
+
* @param {HTMLElement} element Any other element to apply the color apart from {@link inappHTMLEl}
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
BlockProcessor.prototype.processColourBlock = function (colour, attribute, element) {
|
|
219
|
+
if (attribute === void 0) { attribute = 'color'; }
|
|
220
|
+
if (element === void 0) { element = this.inappHTMLEl; }
|
|
221
|
+
if (!colour) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (colour.grad) {
|
|
225
|
+
this.processGradient(colour.grad, attribute);
|
|
226
|
+
}
|
|
227
|
+
else if (colour.hex) {
|
|
228
|
+
this.renderer.setStyle(element, attribute, colour.rgba);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return BlockProcessor;
|
|
232
|
+
}());
|
|
233
|
+
export { BlockProcessor };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BlockProcessor } from './block-processor';
|
|
17
|
+
/**
|
|
18
|
+
* Base class for rendering any block from in-app.
|
|
19
|
+
*
|
|
20
|
+
* @author Abhishek Taparia
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var BlockRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(BlockRenderer, _super);
|
|
25
|
+
/**
|
|
26
|
+
* Public constructor
|
|
27
|
+
*/
|
|
28
|
+
function BlockRenderer() {
|
|
29
|
+
return _super.call(this) || this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Process all the common block in in-app.
|
|
33
|
+
* @param {HTMLElement} element element to be processed
|
|
34
|
+
* @param {BaseElement} baseElement style and attributes data of the element
|
|
35
|
+
*/
|
|
36
|
+
BlockRenderer.prototype.commonRenderingFunction = function (element, baseElement) {
|
|
37
|
+
this.processCommonBlocks(element, baseElement);
|
|
38
|
+
if (baseElement.type) {
|
|
39
|
+
element.classList.add(baseElement.type);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return BlockRenderer;
|
|
43
|
+
}(BlockProcessor));
|
|
44
|
+
export { BlockRenderer };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BlockProcessor } from './block-processor';
|
|
17
|
+
/**
|
|
18
|
+
* Renders container element.
|
|
19
|
+
*
|
|
20
|
+
* @author Shashank Agrawal
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var ContainerRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(ContainerRenderer, _super);
|
|
25
|
+
function ContainerRenderer(parentElement, inappElement) {
|
|
26
|
+
var _this = _super.call(this, parentElement, inappElement) || this;
|
|
27
|
+
_this.inappHTMLEl = _this.renderer.createElement('div');
|
|
28
|
+
_this.insertElement();
|
|
29
|
+
// Need to figure out the best way of doing this
|
|
30
|
+
_this.inappElement.w = 1080;
|
|
31
|
+
_this.inappElement.h = 1920;
|
|
32
|
+
return _this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Render group element from layers list in {@link InAppTrigger} block.
|
|
36
|
+
* @return The instance of this renderer.
|
|
37
|
+
*/
|
|
38
|
+
ContainerRenderer.prototype.render = function () {
|
|
39
|
+
this.processCommonBlocks();
|
|
40
|
+
this.renderer.setStyle(this.inappHTMLEl, 'position', 'relative');
|
|
41
|
+
Object.assign(this.inappHTMLEl.style, this.inappElement.getStyles());
|
|
42
|
+
return this;
|
|
43
|
+
};
|
|
44
|
+
return ContainerRenderer;
|
|
45
|
+
}(BlockProcessor));
|
|
46
|
+
export { ContainerRenderer };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BlockRenderer } from './block-renderer';
|
|
17
|
+
/**
|
|
18
|
+
* Renders group element present in in-app layer block.
|
|
19
|
+
*
|
|
20
|
+
* @author Abhishek Taparia
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var GroupRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(GroupRenderer, _super);
|
|
25
|
+
function GroupRenderer() {
|
|
26
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Render group element from layers list in {@link InAppTrigger} block.
|
|
30
|
+
* @param {HTMLElement} parent
|
|
31
|
+
* @param {GroupElement} elementData style and attributes data of the group element
|
|
32
|
+
* @return {HTMLElement} rendered group element
|
|
33
|
+
*/
|
|
34
|
+
GroupRenderer.prototype.render = function (parent, elementData) {
|
|
35
|
+
var newElement = this.renderer.createElement('div');
|
|
36
|
+
// By default the parents will be relative
|
|
37
|
+
this.renderer.setStyle(newElement, 'position', 'relative');
|
|
38
|
+
this.commonRenderingFunction(newElement, elementData);
|
|
39
|
+
this.renderer.appendChild(parent, newElement);
|
|
40
|
+
return newElement;
|
|
41
|
+
};
|
|
42
|
+
return GroupRenderer;
|
|
43
|
+
}(BlockRenderer));
|
|
44
|
+
export { GroupRenderer };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Renderer } from './renderer';
|
|
2
|
+
import { Constants } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Renders iFrame element on CTAs.
|
|
5
|
+
*
|
|
6
|
+
* @author Abhishek Taparia
|
|
7
|
+
* @version 0.0.5
|
|
8
|
+
*/
|
|
9
|
+
var IFrameRenderer = /** @class */ (function () {
|
|
10
|
+
function IFrameRenderer() {
|
|
11
|
+
this.renderer = Renderer.get();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render iFrame element on CTAs.
|
|
15
|
+
* @param {string} url URL for the iFrame.
|
|
16
|
+
* @return {HTMLElement} rendered iFrame
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
IFrameRenderer.prototype.render = function (url) {
|
|
20
|
+
var root = this.renderer.getElementById(Constants.IN_APP_CONTAINER_NAME);
|
|
21
|
+
var iFrameDiv = this.createIFrameContainer();
|
|
22
|
+
this.createIFrameElement(iFrameDiv, url);
|
|
23
|
+
// Create and render close button for iFrame with anchor tag
|
|
24
|
+
this.createAnchorElement(root, iFrameDiv);
|
|
25
|
+
this.renderer.appendChild(root, iFrameDiv);
|
|
26
|
+
return iFrameDiv;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Create and return iFrame container for iab CTA.
|
|
30
|
+
* @return {HTMLDivElement} iFrame container.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
IFrameRenderer.prototype.createIFrameContainer = function () {
|
|
34
|
+
var iFrameDiv = this.renderer.createElement('div');
|
|
35
|
+
this.renderer.setAttribute(iFrameDiv, 'class', 'iframe-container');
|
|
36
|
+
this.renderer.setAttribute(iFrameDiv, 'id', 'iframe-container');
|
|
37
|
+
this.renderer.setStyle(iFrameDiv, 'width', '100%');
|
|
38
|
+
this.renderer.setStyle(iFrameDiv, 'height', '100%');
|
|
39
|
+
this.renderer.setStyle(iFrameDiv, 'position', 'absolute');
|
|
40
|
+
this.renderer.setStyle(iFrameDiv, 'top', '0px');
|
|
41
|
+
this.renderer.setStyle(iFrameDiv, 'left', '0px');
|
|
42
|
+
return iFrameDiv;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Create and return iFrame element for iab CTA.
|
|
46
|
+
* @param {HTMLDivElement} iFrameDiv iframe container
|
|
47
|
+
* @param {string} src source url to redirect
|
|
48
|
+
* @return {HTMLIFrameElement} iFrame element
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
IFrameRenderer.prototype.createIFrameElement = function (iFrameDiv, src) {
|
|
52
|
+
var iFrameElement = this.renderer.createElement('iframe');
|
|
53
|
+
this.renderer.setStyle(iFrameElement, 'width', '100%');
|
|
54
|
+
this.renderer.setStyle(iFrameElement, 'height', '100%');
|
|
55
|
+
this.renderer.setAttribute(iFrameElement, 'src', src);
|
|
56
|
+
this.renderer.setAttribute(iFrameElement, 'frameBorder', '0');
|
|
57
|
+
this.renderer.appendChild(iFrameDiv, iFrameElement);
|
|
58
|
+
return iFrameElement;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Create and return close button for iFrame element
|
|
62
|
+
* @param {HTMLDivElement} root root container of in-app
|
|
63
|
+
* @param {HTMLDivElement} iframeDiv iframe container
|
|
64
|
+
* @return {HTMLAnchorElement} close button
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
IFrameRenderer.prototype.createAnchorElement = function (root, iframeDiv) {
|
|
68
|
+
var iFrameClose = this.renderer.createElement('a');
|
|
69
|
+
this.renderer.setStyle(iFrameClose, 'position', 'absolute');
|
|
70
|
+
this.renderer.setStyle(iFrameClose, 'top', '0px');
|
|
71
|
+
this.renderer.setStyle(iFrameClose, 'right', '0px');
|
|
72
|
+
iFrameClose.href = '#';
|
|
73
|
+
iFrameClose.innerHTML = 'Close';
|
|
74
|
+
iFrameClose.onclick = function () {
|
|
75
|
+
root.removeChild(iframeDiv);
|
|
76
|
+
};
|
|
77
|
+
this.renderer.appendChild(iframeDiv, iFrameClose);
|
|
78
|
+
return iFrameClose;
|
|
79
|
+
};
|
|
80
|
+
return IFrameRenderer;
|
|
81
|
+
}());
|
|
82
|
+
export { IFrameRenderer };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BlockProcessor } from './block-processor';
|
|
17
|
+
/**
|
|
18
|
+
* Renders image element present in in-app layer block.
|
|
19
|
+
*
|
|
20
|
+
* @author Abhishek Taparia
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var ImageRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(ImageRenderer, _super);
|
|
25
|
+
function ImageRenderer(parentElement, inappElement) {
|
|
26
|
+
var _this = _super.call(this, parentElement, inappElement) || this;
|
|
27
|
+
_this.inappHTMLEl = _this.renderer.createElement('img');
|
|
28
|
+
_this.insertElement();
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Render image element from layers list in {@link ian} block.
|
|
33
|
+
*/
|
|
34
|
+
ImageRenderer.prototype.render = function () {
|
|
35
|
+
this.renderer.setAttribute(this.inappHTMLEl, 'src', this.inappElement.src);
|
|
36
|
+
this.renderer.setStyle(this.inappHTMLEl, 'max-width', '100%');
|
|
37
|
+
this.renderer.setStyle(this.inappHTMLEl, 'max-height', '100%');
|
|
38
|
+
this.renderer.setStyle(this.inappHTMLEl, 'display', 'block');
|
|
39
|
+
this.renderer.setStyle(this.inappHTMLEl, 'margin', '0 auto');
|
|
40
|
+
this.processCommonBlocks();
|
|
41
|
+
};
|
|
42
|
+
return ImageRenderer;
|
|
43
|
+
}(BlockProcessor));
|
|
44
|
+
export { ImageRenderer };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Log } from '../utils/log';
|
|
2
|
+
import { ImageElement, ShapeElement, TextElement } from '../models/trigger/elements/';
|
|
3
|
+
import { TriggerData } from '../models/trigger/trigger-data';
|
|
4
|
+
import { LocalStorageHelper } from '../utils/local-storage-helper';
|
|
5
|
+
import { Constants } from '../constants';
|
|
6
|
+
import { ImageRenderer, RootContainerRenderer, ShapeRenderer, TextRenderer } from './';
|
|
7
|
+
import { ContainerRenderer } from './container-renderer';
|
|
8
|
+
import { TriggerHelper } from '../models/trigger/trigger-helper';
|
|
9
|
+
import { SafeHttpService } from '../services/safe-http-service';
|
|
10
|
+
import { Event } from '../models/event/event';
|
|
11
|
+
/**
|
|
12
|
+
* Renders In App trigger
|
|
13
|
+
*
|
|
14
|
+
* @author Abhishek Taparia
|
|
15
|
+
* @version 0.0.5
|
|
16
|
+
*/
|
|
17
|
+
var InAppRenderer = /** @class */ (function () {
|
|
18
|
+
/**
|
|
19
|
+
* Public constructor.
|
|
20
|
+
*
|
|
21
|
+
* @param parent Place the in-app in the given parent instead of the document.body.
|
|
22
|
+
*/
|
|
23
|
+
function InAppRenderer(parent) {
|
|
24
|
+
this.parent = parent;
|
|
25
|
+
this.rootContainer = new RootContainerRenderer(parent).render();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders in-app trigger from payload received
|
|
29
|
+
* @param {TriggerData} triggerData {@link TriggerData}
|
|
30
|
+
*/
|
|
31
|
+
InAppRenderer.prototype.render = function (triggerData) {
|
|
32
|
+
triggerData = new TriggerData(triggerData);
|
|
33
|
+
this.ian = triggerData.ian;
|
|
34
|
+
try {
|
|
35
|
+
this.renderContainer();
|
|
36
|
+
var event_1 = new Event('CE Trigger Displayed', { 'triggerID': triggerData.id });
|
|
37
|
+
SafeHttpService.getInstance().sendEvent(event_1);
|
|
38
|
+
LocalStorageHelper.setNumber(Constants.STORAGE_TRIGGER_START_TIME, new Date().getTime());
|
|
39
|
+
TriggerHelper.storeActiveTrigger(triggerData);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
Log.error(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Render elements.
|
|
47
|
+
* @param {HTMLElement} parentEl element to be rendered
|
|
48
|
+
* @param {BaseElement} inappElement style and attributes data of the element
|
|
49
|
+
*/
|
|
50
|
+
InAppRenderer.prototype.renderElement = function (parentEl, inappElement) {
|
|
51
|
+
if (inappElement instanceof TextElement) {
|
|
52
|
+
new TextRenderer(parentEl, inappElement).render();
|
|
53
|
+
}
|
|
54
|
+
else if (inappElement instanceof ImageElement) {
|
|
55
|
+
new ImageRenderer(parentEl, inappElement).render();
|
|
56
|
+
}
|
|
57
|
+
else if (inappElement instanceof ShapeElement) {
|
|
58
|
+
new ShapeRenderer(parentEl, inappElement).render();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
Log.error('Unsupported element type- ' + inappElement.type);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Render container from {@link ian} block.
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
InAppRenderer.prototype.renderContainer = function () {
|
|
69
|
+
var _this = this;
|
|
70
|
+
var _a, _b;
|
|
71
|
+
var container = (_a = this.ian) === null || _a === void 0 ? void 0 : _a.cont;
|
|
72
|
+
if (!container) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var containerHTMLElement = new ContainerRenderer(this.rootContainer, container)
|
|
76
|
+
.render()
|
|
77
|
+
.getHTMLElement();
|
|
78
|
+
(_b = this.ian.elems) === null || _b === void 0 ? void 0 : _b.forEach(function (element) {
|
|
79
|
+
_this.renderElement(containerHTMLElement, element);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return InAppRenderer;
|
|
83
|
+
}());
|
|
84
|
+
export { InAppRenderer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Constants } from '../constants';
|
|
2
|
+
import { Renderer } from './renderer';
|
|
3
|
+
export { TextRenderer } from './text-renderer';
|
|
4
|
+
export { ShapeRenderer } from './shape-renderer';
|
|
5
|
+
export { ImageRenderer } from './image-renderer';
|
|
6
|
+
export { RootContainerRenderer } from './root-container-renderer';
|
|
7
|
+
export { IFrameRenderer } from './iFrame-renderer';
|
|
8
|
+
/**
|
|
9
|
+
* Calculate scaling factor according to parent most container where the in-app's root container will be rendered.
|
|
10
|
+
* @return number scaling factor
|
|
11
|
+
*/
|
|
12
|
+
export function getScalingFactor() {
|
|
13
|
+
var screenWidth = Renderer.get().getWidth();
|
|
14
|
+
var screenHeight = Renderer.get().getHeight();
|
|
15
|
+
var scalingFactor;
|
|
16
|
+
if (screenWidth < screenHeight) {
|
|
17
|
+
var shortEdge = Math.min(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
|
|
18
|
+
scalingFactor = screenWidth / shortEdge;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
var longEdge = Math.max(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
|
|
22
|
+
scalingFactor = screenHeight / longEdge;
|
|
23
|
+
}
|
|
24
|
+
// The in-app should not scale beyond 100%
|
|
25
|
+
return Math.min(scalingFactor, 1);
|
|
26
|
+
}
|