@letscooee/web-sdk 0.0.3 → 0.0.7
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 +15 -2
- package/README.md +4 -2
- 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 +103 -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 +49 -0
- package/dist/renderer/base-text-renderer.js +77 -0
- package/dist/renderer/block-processor.js +234 -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 +85 -0
- package/dist/renderer/image-renderer.js +44 -0
- package/dist/renderer/in-app-renderer.js +81 -0
- package/dist/renderer/index.js +25 -0
- package/dist/renderer/renderer.js +77 -0
- package/dist/renderer/root-container-renderer.js +43 -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 +30 -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 +8 -6
- package/webpack-preview.config.js +10 -0
|
@@ -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,85 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*/
|
|
13
|
+
function IFrameRenderer() {
|
|
14
|
+
this.renderer = new Renderer();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Render iFrame element on CTAs.
|
|
18
|
+
* @param {string} url URL for the iFrame.
|
|
19
|
+
* @return {HTMLElement} rendered iFrame
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
IFrameRenderer.prototype.render = function (url) {
|
|
23
|
+
var root = this.renderer.getElementById(Constants.IN_APP_CONTAINER_NAME);
|
|
24
|
+
var iFrameDiv = this.createIFrameContainer();
|
|
25
|
+
this.createIFrameElement(iFrameDiv, url);
|
|
26
|
+
// Create and render close button for iFrame with anchor tag
|
|
27
|
+
this.createAnchorElement(root, iFrameDiv);
|
|
28
|
+
this.renderer.appendChild(root, iFrameDiv);
|
|
29
|
+
return iFrameDiv;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create and return iFrame container for iab CTA.
|
|
33
|
+
* @return {HTMLDivElement} iFrame container.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
IFrameRenderer.prototype.createIFrameContainer = function () {
|
|
37
|
+
var iFrameDiv = this.renderer.createElement('div');
|
|
38
|
+
this.renderer.setAttribute(iFrameDiv, 'class', 'iframe-container');
|
|
39
|
+
this.renderer.setAttribute(iFrameDiv, 'id', 'iframe-container');
|
|
40
|
+
this.renderer.setStyle(iFrameDiv, 'width', '100%');
|
|
41
|
+
this.renderer.setStyle(iFrameDiv, 'height', '100%');
|
|
42
|
+
this.renderer.setStyle(iFrameDiv, 'position', 'absolute');
|
|
43
|
+
this.renderer.setStyle(iFrameDiv, 'top', '0px');
|
|
44
|
+
this.renderer.setStyle(iFrameDiv, 'left', '0px');
|
|
45
|
+
return iFrameDiv;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Create and return iFrame element for iab CTA.
|
|
49
|
+
* @param {HTMLDivElement} iFrameDiv iframe container
|
|
50
|
+
* @param {string} src source url to redirect
|
|
51
|
+
* @return {HTMLIFrameElement} iFrame element
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
IFrameRenderer.prototype.createIFrameElement = function (iFrameDiv, src) {
|
|
55
|
+
var iFrameElement = this.renderer.createElement('iframe');
|
|
56
|
+
this.renderer.setStyle(iFrameElement, 'width', '100%');
|
|
57
|
+
this.renderer.setStyle(iFrameElement, 'height', '100%');
|
|
58
|
+
this.renderer.setAttribute(iFrameElement, 'src', src);
|
|
59
|
+
this.renderer.setAttribute(iFrameElement, 'frameBorder', '0');
|
|
60
|
+
this.renderer.appendChild(iFrameDiv, iFrameElement);
|
|
61
|
+
return iFrameElement;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Create and return close button for iFrame element
|
|
65
|
+
* @param {HTMLDivElement} root root container of in-app
|
|
66
|
+
* @param {HTMLDivElement} iframeDiv iframe container
|
|
67
|
+
* @return {HTMLAnchorElement} close button
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
IFrameRenderer.prototype.createAnchorElement = function (root, iframeDiv) {
|
|
71
|
+
var iFrameClose = this.renderer.createElement('a');
|
|
72
|
+
this.renderer.setStyle(iFrameClose, 'position', 'absolute');
|
|
73
|
+
this.renderer.setStyle(iFrameClose, 'top', '0px');
|
|
74
|
+
this.renderer.setStyle(iFrameClose, 'right', '0px');
|
|
75
|
+
iFrameClose.href = '#';
|
|
76
|
+
iFrameClose.innerHTML = 'Close';
|
|
77
|
+
iFrameClose.onclick = function () {
|
|
78
|
+
root.removeChild(iframeDiv);
|
|
79
|
+
};
|
|
80
|
+
this.renderer.appendChild(iframeDiv, iFrameClose);
|
|
81
|
+
return iFrameClose;
|
|
82
|
+
};
|
|
83
|
+
return IFrameRenderer;
|
|
84
|
+
}());
|
|
85
|
+
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,81 @@
|
|
|
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
|
+
function InAppRenderer() {
|
|
22
|
+
this.rootContainer = new RootContainerRenderer().render();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Renders in-app trigger from payload received
|
|
26
|
+
* @param {TriggerData} triggerData {@link TriggerData}
|
|
27
|
+
*/
|
|
28
|
+
InAppRenderer.prototype.render = function (triggerData) {
|
|
29
|
+
triggerData = new TriggerData(triggerData);
|
|
30
|
+
this.ian = triggerData.ian;
|
|
31
|
+
try {
|
|
32
|
+
this.renderContainer();
|
|
33
|
+
var event_1 = new Event('CE Trigger Displayed', { 'triggerID': triggerData.id });
|
|
34
|
+
SafeHttpService.getInstance().sendEvent(event_1);
|
|
35
|
+
LocalStorageHelper.setNumber(Constants.STORAGE_TRIGGER_START_TIME, new Date().getTime());
|
|
36
|
+
TriggerHelper.storeActiveTrigger(triggerData);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
Log.error(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Render elements.
|
|
44
|
+
* @param {HTMLElement} parentEl element to be rendered
|
|
45
|
+
* @param {BaseElement} inappElement style and attributes data of the element
|
|
46
|
+
*/
|
|
47
|
+
InAppRenderer.prototype.renderElement = function (parentEl, inappElement) {
|
|
48
|
+
if (inappElement instanceof TextElement) {
|
|
49
|
+
new TextRenderer(parentEl, inappElement).render();
|
|
50
|
+
}
|
|
51
|
+
else if (inappElement instanceof ImageElement) {
|
|
52
|
+
new ImageRenderer(parentEl, inappElement).render();
|
|
53
|
+
}
|
|
54
|
+
else if (inappElement instanceof ShapeElement) {
|
|
55
|
+
new ShapeRenderer(parentEl, inappElement).render();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
Log.error('Unsupported element type- ' + inappElement.type);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Render container from {@link ian} block.
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
InAppRenderer.prototype.renderContainer = function () {
|
|
66
|
+
var _this = this;
|
|
67
|
+
var _a, _b;
|
|
68
|
+
var container = (_a = this.ian) === null || _a === void 0 ? void 0 : _a.cont;
|
|
69
|
+
if (!container) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
var containerHTMLElement = new ContainerRenderer(this.rootContainer, container)
|
|
73
|
+
.render()
|
|
74
|
+
.getHTMLElement();
|
|
75
|
+
(_b = this.ian.elems) === null || _b === void 0 ? void 0 : _b.forEach(function (element) {
|
|
76
|
+
_this.renderElement(containerHTMLElement, element);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return InAppRenderer;
|
|
80
|
+
}());
|
|
81
|
+
export { InAppRenderer };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Constants } from '../constants';
|
|
2
|
+
export { TextRenderer } from './text-renderer';
|
|
3
|
+
export { ShapeRenderer } from './shape-renderer';
|
|
4
|
+
export { ImageRenderer } from './image-renderer';
|
|
5
|
+
export { RootContainerRenderer } from './root-container-renderer';
|
|
6
|
+
export { IFrameRenderer } from './iFrame-renderer';
|
|
7
|
+
/**
|
|
8
|
+
* Calculate scaling factor according to screen sizes
|
|
9
|
+
* @return number scaling factor
|
|
10
|
+
*/
|
|
11
|
+
export function getScalingFactor() {
|
|
12
|
+
var screenWidth = document.documentElement.clientWidth;
|
|
13
|
+
var screenHeight = document.documentElement.clientHeight;
|
|
14
|
+
var scalingFactor;
|
|
15
|
+
if (screenWidth < screenHeight) {
|
|
16
|
+
var shortEdge = Math.min(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
|
|
17
|
+
scalingFactor = screenWidth / shortEdge;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
var longEdge = Math.max(Constants.CANVAS_WIDTH, Constants.CANVAS_HEIGHT);
|
|
21
|
+
scalingFactor = screenHeight / longEdge;
|
|
22
|
+
}
|
|
23
|
+
// The in-app should not scale beyond 100%
|
|
24
|
+
return Math.min(scalingFactor, 1);
|
|
25
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for creating and rendering elements.
|
|
3
|
+
*
|
|
4
|
+
* @author Abhishek Taparia
|
|
5
|
+
* @version 0.0.5
|
|
6
|
+
*/
|
|
7
|
+
var Renderer = /** @class */ (function () {
|
|
8
|
+
function Renderer() {
|
|
9
|
+
this.doc = document;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get width of the browser
|
|
13
|
+
* @return {number} inner width of the browser
|
|
14
|
+
*/
|
|
15
|
+
Renderer.prototype.getWidth = function () {
|
|
16
|
+
return document.documentElement.clientWidth;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get height of the browser
|
|
20
|
+
* @return {number} inner height of the browser
|
|
21
|
+
*/
|
|
22
|
+
Renderer.prototype.getHeight = function () {
|
|
23
|
+
return document.documentElement.clientHeight;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates an element
|
|
27
|
+
* @param {string} elementType element type to be created
|
|
28
|
+
* @return {HTMLElement} created element
|
|
29
|
+
*/
|
|
30
|
+
Renderer.prototype.createElement = function (elementType) {
|
|
31
|
+
return this.doc.createElement(elementType);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Append a child to parent element
|
|
35
|
+
* @param {HTMLElement} parentElement element on which child is to be appended
|
|
36
|
+
* @param {HTMLElement} childElement element to to appended
|
|
37
|
+
*/
|
|
38
|
+
Renderer.prototype.appendChild = function (parentElement, childElement) {
|
|
39
|
+
parentElement.appendChild(childElement);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Set style of the element
|
|
43
|
+
* @param {HTMLElement} element element on which styles is added
|
|
44
|
+
* @param {string} styleName style name
|
|
45
|
+
* @param {any} value style value
|
|
46
|
+
*/
|
|
47
|
+
Renderer.prototype.setStyle = function (element, styleName, value) {
|
|
48
|
+
// Return if style or value is null or undefined
|
|
49
|
+
if (!styleName) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!value) {
|
|
53
|
+
element.style.removeProperty(styleName);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
element.style.setProperty(styleName, value);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Set style of the element
|
|
60
|
+
* @param {HTMLElement} element element on which attribute is added
|
|
61
|
+
* @param {string} attrName attribute name
|
|
62
|
+
* @param {any} value attribute value
|
|
63
|
+
*/
|
|
64
|
+
Renderer.prototype.setAttribute = function (element, attrName, value) {
|
|
65
|
+
element.setAttribute(attrName, value);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Get element by tag id
|
|
69
|
+
* @param {string} id id of the element
|
|
70
|
+
* @return {HTMLElement | null} returns element if present, otherwise null
|
|
71
|
+
*/
|
|
72
|
+
Renderer.prototype.getElementById = function (id) {
|
|
73
|
+
return this.doc.getElementById(id);
|
|
74
|
+
};
|
|
75
|
+
return Renderer;
|
|
76
|
+
}());
|
|
77
|
+
export { Renderer };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Constants } from '../constants';
|
|
2
|
+
import { Renderer } from './renderer';
|
|
3
|
+
/**
|
|
4
|
+
* Renders root container.
|
|
5
|
+
*
|
|
6
|
+
* @author Abhishek Taparia
|
|
7
|
+
* @version 0.0.5
|
|
8
|
+
*/
|
|
9
|
+
var RootContainerRenderer = /** @class */ (function () {
|
|
10
|
+
function RootContainerRenderer() {
|
|
11
|
+
this.renderer = new Renderer();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render root container.
|
|
15
|
+
* @return {HTMLElement} rendered root container
|
|
16
|
+
*/
|
|
17
|
+
RootContainerRenderer.prototype.render = function () {
|
|
18
|
+
this.removeInApp();
|
|
19
|
+
var rootDiv = this.renderer.createElement('div');
|
|
20
|
+
rootDiv.id = Constants.IN_APP_CONTAINER_NAME;
|
|
21
|
+
rootDiv.classList.add(Constants.IN_APP_CONTAINER_NAME);
|
|
22
|
+
this.renderer.setStyle(rootDiv, 'z-index', '10000000');
|
|
23
|
+
this.renderer.setStyle(rootDiv, 'position', 'fixed');
|
|
24
|
+
this.renderer.setStyle(rootDiv, 'top', '0');
|
|
25
|
+
this.renderer.setStyle(rootDiv, 'left', '0');
|
|
26
|
+
this.renderer.setStyle(rootDiv, 'width', '100%');
|
|
27
|
+
this.renderer.setStyle(rootDiv, 'height', '100%');
|
|
28
|
+
this.renderer.appendChild(document.body, rootDiv);
|
|
29
|
+
return rootDiv;
|
|
30
|
+
};
|
|
31
|
+
// noinspection JSMethodCanBeStatic
|
|
32
|
+
/**
|
|
33
|
+
* Remove InApp trigger.
|
|
34
|
+
*/
|
|
35
|
+
RootContainerRenderer.prototype.removeInApp = function () {
|
|
36
|
+
var rootDiv = document.getElementById(Constants.IN_APP_CONTAINER_NAME);
|
|
37
|
+
if (rootDiv) {
|
|
38
|
+
rootDiv.parentElement.removeChild(rootDiv);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return RootContainerRenderer;
|
|
42
|
+
}());
|
|
43
|
+
export { RootContainerRenderer };
|
|
@@ -0,0 +1,39 @@
|
|
|
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 group element present in in-app layer block.
|
|
19
|
+
*
|
|
20
|
+
* @author Abhishek Taparia
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var ShapeRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(ShapeRenderer, _super);
|
|
25
|
+
function ShapeRenderer(parentElement, inappElement) {
|
|
26
|
+
var _this = _super.call(this, parentElement, inappElement) || this;
|
|
27
|
+
_this.inappHTMLEl = _this.renderer.createElement('div');
|
|
28
|
+
_this.insertElement();
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Render group element from layers list in {@link InAppTrigger} block.
|
|
33
|
+
*/
|
|
34
|
+
ShapeRenderer.prototype.render = function () {
|
|
35
|
+
this.processCommonBlocks();
|
|
36
|
+
};
|
|
37
|
+
return ShapeRenderer;
|
|
38
|
+
}(BlockProcessor));
|
|
39
|
+
export { ShapeRenderer };
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { BaseTextRenderer } from './base-text-renderer';
|
|
17
|
+
/**
|
|
18
|
+
* Renders text element present in in-app layer block.
|
|
19
|
+
*
|
|
20
|
+
* @author Abhishek Taparia
|
|
21
|
+
* @version 0.0.5
|
|
22
|
+
*/
|
|
23
|
+
var TextRenderer = /** @class */ (function (_super) {
|
|
24
|
+
__extends(TextRenderer, _super);
|
|
25
|
+
function TextRenderer(parentElement, inappElement) {
|
|
26
|
+
var _this = _super.call(this, parentElement, inappElement) || this;
|
|
27
|
+
_this.inappHTMLEl = _this.renderer.createElement('div');
|
|
28
|
+
_this.insertElement();
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Render text element from layers list in {@link ian} block.
|
|
33
|
+
*/
|
|
34
|
+
TextRenderer.prototype.render = function () {
|
|
35
|
+
var _this = this;
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = this.inappElement.parts) === null || _a === void 0 ? void 0 : _a.forEach(function (partData) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
var newPartElement = _this.renderer.createElement('span');
|
|
40
|
+
newPartElement.innerHTML = (_b = (_a = partData.txt) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.replace(/\n/g, '<br />');
|
|
41
|
+
_this.processPart(newPartElement, partData);
|
|
42
|
+
_this.renderer.appendChild(_this.inappHTMLEl, newPartElement);
|
|
43
|
+
});
|
|
44
|
+
this.processCommonBlocks();
|
|
45
|
+
};
|
|
46
|
+
return TextRenderer;
|
|
47
|
+
}(BaseTextRenderer));
|
|
48
|
+
export { TextRenderer };
|