@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,24 @@
|
|
|
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 { BaseElement } from './base-element';
|
|
17
|
+
var ShapeElement = /** @class */ (function (_super) {
|
|
18
|
+
__extends(ShapeElement, _super);
|
|
19
|
+
function ShapeElement(data) {
|
|
20
|
+
return _super.call(this, data) || this;
|
|
21
|
+
}
|
|
22
|
+
return ShapeElement;
|
|
23
|
+
}(BaseElement));
|
|
24
|
+
export { ShapeElement };
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { Color } from '../blocks';
|
|
17
|
+
import { BaseElement } from './base-element';
|
|
18
|
+
var TextElement = /** @class */ (function (_super) {
|
|
19
|
+
__extends(TextElement, _super);
|
|
20
|
+
function TextElement(data) {
|
|
21
|
+
var _this = _super.call(this, data) || this;
|
|
22
|
+
_this.alg = TextAlign.START;
|
|
23
|
+
_this.prs = data.prs;
|
|
24
|
+
_this.alg = data.alg;
|
|
25
|
+
if (data.f)
|
|
26
|
+
_this.f = data.f;
|
|
27
|
+
if (data.c)
|
|
28
|
+
_this.c = new Color(data.c);
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperty(TextElement.prototype, "parts", {
|
|
32
|
+
get: function () {
|
|
33
|
+
return this.prs;
|
|
34
|
+
},
|
|
35
|
+
enumerable: false,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(TextElement.prototype, "color", {
|
|
39
|
+
get: function () {
|
|
40
|
+
return this.c;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(TextElement.prototype, "font", {
|
|
46
|
+
get: function () {
|
|
47
|
+
return this.f;
|
|
48
|
+
},
|
|
49
|
+
enumerable: false,
|
|
50
|
+
configurable: true
|
|
51
|
+
});
|
|
52
|
+
return TextElement;
|
|
53
|
+
}(BaseElement));
|
|
54
|
+
export { TextElement };
|
|
55
|
+
var TextPart = /** @class */ (function () {
|
|
56
|
+
function TextPart(data) {
|
|
57
|
+
this.txt = data.text;
|
|
58
|
+
this.b = data.b;
|
|
59
|
+
this.i = data.i;
|
|
60
|
+
this.u = data.u;
|
|
61
|
+
this.st = data.st;
|
|
62
|
+
this.sc = data.sc;
|
|
63
|
+
}
|
|
64
|
+
return TextPart;
|
|
65
|
+
}());
|
|
66
|
+
export { TextPart };
|
|
67
|
+
/* eslint-disable no-unused-vars */
|
|
68
|
+
export var TextAlign;
|
|
69
|
+
(function (TextAlign) {
|
|
70
|
+
TextAlign[TextAlign["START"] = 0] = "START";
|
|
71
|
+
TextAlign[TextAlign["CENTER"] = 1] = "CENTER";
|
|
72
|
+
TextAlign[TextAlign["END"] = 2] = "END";
|
|
73
|
+
TextAlign[TextAlign["JUSTIFY"] = 3] = "JUSTIFY";
|
|
74
|
+
})(TextAlign || (TextAlign = {}));
|
|
75
|
+
export var TextScript;
|
|
76
|
+
(function (TextScript) {
|
|
77
|
+
TextScript[TextScript["NORMAL"] = 0] = "NORMAL";
|
|
78
|
+
TextScript[TextScript["SUPER"] = 1] = "SUPER";
|
|
79
|
+
TextScript[TextScript["SUB"] = 2] = "SUB";
|
|
80
|
+
})(TextScript || (TextScript = {}));
|
|
81
|
+
/* eslint-enable no-unused-vars */
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class store data related to triggers which are active/activated by clicking on the trigger notification or by
|
|
3
|
+
* looking an in-app trigger(in future). This would be commonly sent with events as <code>activeTrigger</code>.
|
|
4
|
+
*
|
|
5
|
+
* @author Abhishek Taparia
|
|
6
|
+
* @since 1.1.0
|
|
7
|
+
*/
|
|
8
|
+
var EmbeddedTrigger = /** @class */ (function () {
|
|
9
|
+
function EmbeddedTrigger(data) {
|
|
10
|
+
this.triggerID = data.id;
|
|
11
|
+
this.engagementID = data.engagementID;
|
|
12
|
+
this.expireAt = data.expireAt;
|
|
13
|
+
if (this.isExpired) {
|
|
14
|
+
this.expired = this.isExpired;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(EmbeddedTrigger.prototype, "isExpired", {
|
|
18
|
+
get: function () {
|
|
19
|
+
return this.expireAt < new Date().getTime();
|
|
20
|
+
},
|
|
21
|
+
enumerable: false,
|
|
22
|
+
configurable: true
|
|
23
|
+
});
|
|
24
|
+
return EmbeddedTrigger;
|
|
25
|
+
}());
|
|
26
|
+
export { EmbeddedTrigger };
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { BaseElement } from '../elements';
|
|
17
|
+
var Container = /** @class */ (function (_super) {
|
|
18
|
+
__extends(Container, _super);
|
|
19
|
+
function Container(data) {
|
|
20
|
+
var _a;
|
|
21
|
+
var _this = _super.call(this, data) || this;
|
|
22
|
+
_this.o = (_a = data.o) !== null && _a !== void 0 ? _a : ContainerOrigin.C;
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
Container.prototype.getStyles = function () {
|
|
26
|
+
var styles;
|
|
27
|
+
if (this.o === ContainerOrigin.NW) {
|
|
28
|
+
styles = {
|
|
29
|
+
top: 0,
|
|
30
|
+
left: 0,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (this.o === ContainerOrigin.N) {
|
|
34
|
+
styles = {
|
|
35
|
+
top: 0,
|
|
36
|
+
left: '50%',
|
|
37
|
+
transform: 'translateX(-50%)',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else if (this.o === ContainerOrigin.NE) {
|
|
41
|
+
styles = {
|
|
42
|
+
top: 0,
|
|
43
|
+
right: 0,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (this.o === ContainerOrigin.E) {
|
|
47
|
+
styles = {
|
|
48
|
+
top: '50%',
|
|
49
|
+
left: 0,
|
|
50
|
+
transform: 'translateY(-50%)',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (this.o === ContainerOrigin.SE) {
|
|
54
|
+
styles = {
|
|
55
|
+
bottom: 0,
|
|
56
|
+
right: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if (this.o === ContainerOrigin.S) {
|
|
60
|
+
styles = {
|
|
61
|
+
bottom: 0,
|
|
62
|
+
left: '50%',
|
|
63
|
+
transform: 'translateX(-50%)',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else if (this.o === ContainerOrigin.SW) {
|
|
67
|
+
styles = {
|
|
68
|
+
bottom: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else if (this.o === ContainerOrigin.W) {
|
|
73
|
+
styles = {
|
|
74
|
+
top: '50%',
|
|
75
|
+
left: 0,
|
|
76
|
+
transform: 'translateY(-50%)',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
styles = {
|
|
81
|
+
top: '50%',
|
|
82
|
+
left: '50%',
|
|
83
|
+
transform: 'translateX(-50%) translateY(-50%)',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
styles.position = 'absolute';
|
|
87
|
+
return styles;
|
|
88
|
+
};
|
|
89
|
+
return Container;
|
|
90
|
+
}(BaseElement));
|
|
91
|
+
export { Container };
|
|
92
|
+
export var ContainerOrigin;
|
|
93
|
+
(function (ContainerOrigin) {
|
|
94
|
+
ContainerOrigin[ContainerOrigin["NW"] = 1] = "NW";
|
|
95
|
+
ContainerOrigin[ContainerOrigin["N"] = 2] = "N";
|
|
96
|
+
ContainerOrigin[ContainerOrigin["NE"] = 3] = "NE";
|
|
97
|
+
ContainerOrigin[ContainerOrigin["W"] = 4] = "W";
|
|
98
|
+
ContainerOrigin[ContainerOrigin["C"] = 5] = "C";
|
|
99
|
+
ContainerOrigin[ContainerOrigin["E"] = 6] = "E";
|
|
100
|
+
ContainerOrigin[ContainerOrigin["SW"] = 7] = "SW";
|
|
101
|
+
ContainerOrigin[ContainerOrigin["S"] = 8] = "S";
|
|
102
|
+
ContainerOrigin[ContainerOrigin["SE"] = 9] = "SE";
|
|
103
|
+
})(ContainerOrigin || (ContainerOrigin = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Container } from './container';
|
|
2
|
+
import { ImageElement, ShapeElement, TextElement } from '../elements';
|
|
3
|
+
import { ElementType } from '../elements/base-element';
|
|
4
|
+
/**
|
|
5
|
+
* Stores data present in ian (In App) block in {@link TriggerData}
|
|
6
|
+
*
|
|
7
|
+
* @author Abhishek Taparia
|
|
8
|
+
* @version 0.0.5
|
|
9
|
+
*/
|
|
10
|
+
var InAppTrigger = /** @class */ (function () {
|
|
11
|
+
function InAppTrigger(data) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
this.elems = [];
|
|
14
|
+
this.cont = new Container(data.cont);
|
|
15
|
+
data.elems.forEach(function (rawElement) {
|
|
16
|
+
if (rawElement.t === ElementType.IMAGE) {
|
|
17
|
+
_this.elems.push(new ImageElement(rawElement));
|
|
18
|
+
}
|
|
19
|
+
else if (rawElement.t === ElementType.TEXT) {
|
|
20
|
+
_this.elems.push(new TextElement(rawElement));
|
|
21
|
+
}
|
|
22
|
+
else if (rawElement.t === ElementType.BUTTON) {
|
|
23
|
+
_this.elems.push(new TextElement(rawElement));
|
|
24
|
+
}
|
|
25
|
+
else if (rawElement.t === ElementType.SHAPE) {
|
|
26
|
+
_this.elems.push(new ShapeElement(rawElement));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return InAppTrigger;
|
|
31
|
+
}());
|
|
32
|
+
export { InAppTrigger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InAppTrigger } from './inapp/in-app-trigger';
|
|
1
2
|
/**
|
|
2
3
|
* This store the payload sent by server to render trigger.
|
|
3
4
|
*/
|
|
@@ -5,12 +6,17 @@ var TriggerData = /** @class */ (function () {
|
|
|
5
6
|
/**
|
|
6
7
|
* Public constructor
|
|
7
8
|
*
|
|
8
|
-
* @param {
|
|
9
|
+
* @param {Props} data payload
|
|
9
10
|
*/
|
|
10
11
|
function TriggerData(data) {
|
|
11
|
-
this.
|
|
12
|
+
this.expireAt = new Date().getTime();
|
|
12
13
|
this.id = data.id;
|
|
13
|
-
this.
|
|
14
|
+
this.expireAt = data.expireAt;
|
|
15
|
+
this.version = data.version;
|
|
16
|
+
this.engagementID = data.engagementID;
|
|
17
|
+
this.internal = data.internal;
|
|
18
|
+
this.pn = data.pn;
|
|
19
|
+
this.ian = new InAppTrigger(data.ian);
|
|
14
20
|
}
|
|
15
21
|
return TriggerData;
|
|
16
22
|
}());
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LocalStorageHelper } from '../../utils/local-storage-helper';
|
|
2
|
+
import { Constants } from '../../constants';
|
|
3
|
+
import { EmbeddedTrigger } from './embedded-trigger';
|
|
4
|
+
/**
|
|
5
|
+
* A small helper class for any kind of engagement trigger like caching or retrieving from local storage.
|
|
6
|
+
*
|
|
7
|
+
* @author Abhishek Taparia
|
|
8
|
+
* @since 0.0.7
|
|
9
|
+
*/
|
|
10
|
+
var TriggerHelper = /** @class */ (function () {
|
|
11
|
+
function TriggerHelper() {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Store the current active trigger details in local storage for "late engagement tracking".
|
|
15
|
+
* @param triggerData trigger data
|
|
16
|
+
*/
|
|
17
|
+
TriggerHelper.storeActiveTrigger = function (triggerData) {
|
|
18
|
+
var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
|
|
19
|
+
if (!activeTriggers) {
|
|
20
|
+
activeTriggers = [];
|
|
21
|
+
}
|
|
22
|
+
var embeddedTrigger = new EmbeddedTrigger(triggerData);
|
|
23
|
+
if (!embeddedTrigger.isExpired) {
|
|
24
|
+
activeTriggers.push(embeddedTrigger);
|
|
25
|
+
}
|
|
26
|
+
LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGER, embeddedTrigger);
|
|
27
|
+
LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Get the list of non-expired active triggers from local storage for "late engagement tracking".
|
|
31
|
+
*
|
|
32
|
+
* @return EmbeddedTrigger[] list of active triggers
|
|
33
|
+
*/
|
|
34
|
+
TriggerHelper.getActiveTriggers = function () {
|
|
35
|
+
var activeTriggers = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGERS);
|
|
36
|
+
if (!activeTriggers) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
activeTriggers.forEach(function (trigger, index, array) {
|
|
40
|
+
if (new EmbeddedTrigger(trigger).isExpired) {
|
|
41
|
+
array.splice(index, 1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
LocalStorageHelper.setObject(Constants.STORAGE_ACTIVE_TRIGGERS, activeTriggers);
|
|
45
|
+
return activeTriggers;
|
|
46
|
+
};
|
|
47
|
+
return TriggerHelper;
|
|
48
|
+
}());
|
|
49
|
+
export { TriggerHelper };
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
import { TextAlign } from '../models/trigger/elements/text-element';
|
|
18
|
+
/**
|
|
19
|
+
* Base class for rendering any text extending block from in-app.
|
|
20
|
+
*
|
|
21
|
+
* @author Abhishek Taparia
|
|
22
|
+
* @version 0.0.5
|
|
23
|
+
*/
|
|
24
|
+
var BaseTextRenderer = /** @class */ (function (_super) {
|
|
25
|
+
__extends(BaseTextRenderer, _super);
|
|
26
|
+
function BaseTextRenderer(parentElement, inappElement) {
|
|
27
|
+
return _super.call(this, parentElement, inappElement) || this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Process all the common block in in-app.
|
|
31
|
+
*/
|
|
32
|
+
BaseTextRenderer.prototype.processCommonBlocks = function () {
|
|
33
|
+
_super.prototype.processCommonBlocks.call(this);
|
|
34
|
+
this.processFontBlock();
|
|
35
|
+
this.processColourBlock(this.inappElement.color);
|
|
36
|
+
this.processAlignment();
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Process font block of the element
|
|
40
|
+
*/
|
|
41
|
+
BaseTextRenderer.prototype.processFontBlock = function () {
|
|
42
|
+
var font = this.inappElement.font;
|
|
43
|
+
if (!font) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.renderer.setStyle(this.inappHTMLEl, 'font-size', this.getSizePx(font.s));
|
|
47
|
+
this.renderer.setStyle(this.inappHTMLEl, 'font-family', font.ff);
|
|
48
|
+
this.renderer.setStyle(this.inappHTMLEl, 'line-height', font.lh);
|
|
49
|
+
};
|
|
50
|
+
BaseTextRenderer.prototype.processPart = function (partHTMLEl, part) {
|
|
51
|
+
var _a;
|
|
52
|
+
var decoration = [];
|
|
53
|
+
if (part.u)
|
|
54
|
+
decoration.push('underline');
|
|
55
|
+
if (part.st)
|
|
56
|
+
decoration.push('line-through');
|
|
57
|
+
if (!decoration.length)
|
|
58
|
+
decoration.push('normal');
|
|
59
|
+
this.renderer.setStyle(partHTMLEl, 'font-weight', part.b ? 'bold' : 'normal');
|
|
60
|
+
this.renderer.setStyle(partHTMLEl, 'font-style', part.i ? 'italic' : 'normal');
|
|
61
|
+
this.renderer.setStyle(partHTMLEl, 'text-decoration', decoration.join(' '));
|
|
62
|
+
this.renderer.setStyle(partHTMLEl, 'color', (_a = part.c) !== null && _a !== void 0 ? _a : 'inherit');
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Process text alignment block of the element
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
BaseTextRenderer.prototype.processAlignment = function () {
|
|
69
|
+
var _a;
|
|
70
|
+
var value = (_a = TextAlign[this.inappElement.alg]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
71
|
+
if (!value)
|
|
72
|
+
value = 'start';
|
|
73
|
+
this.renderer.setStyle(this.inappHTMLEl, 'text-align', value);
|
|
74
|
+
};
|
|
75
|
+
return BaseTextRenderer;
|
|
76
|
+
}(BlockProcessor));
|
|
77
|
+
export { BaseTextRenderer };
|
|
@@ -0,0 +1,234 @@
|
|
|
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.screenWidth = 0;
|
|
15
|
+
this.screenHeight = 0;
|
|
16
|
+
this.scalingFactor = getScalingFactor();
|
|
17
|
+
this.parentHTMLEl = parentHTMLEl;
|
|
18
|
+
this.inappElement = inappElement;
|
|
19
|
+
this.renderer = new Renderer();
|
|
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, 'overflow', 'visible');
|
|
41
|
+
this.renderer.setStyle(this.inappHTMLEl, 'outline', 'none');
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Process width and height
|
|
45
|
+
*/
|
|
46
|
+
BlockProcessor.prototype.processWidthAndHeight = function () {
|
|
47
|
+
this.renderer.setStyle(this.inappHTMLEl, 'box-sizing', 'border-box');
|
|
48
|
+
if (this.inappElement.w) {
|
|
49
|
+
this.renderer.setStyle(this.inappHTMLEl, 'width', this.getSizePx(this.inappElement.w));
|
|
50
|
+
}
|
|
51
|
+
if (this.inappElement.h) {
|
|
52
|
+
this.renderer.setStyle(this.inappHTMLEl, 'height', this.getSizePx(this.inappElement.h));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get calculated size according to the device by multiplying it with scaling factor.
|
|
57
|
+
* @param {number} value size passed in payload
|
|
58
|
+
* @return number calculated size
|
|
59
|
+
*/
|
|
60
|
+
BlockProcessor.prototype.getSizePx = function (value) {
|
|
61
|
+
return (value * this.scalingFactor) + 'px';
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Process position block of the element
|
|
65
|
+
*/
|
|
66
|
+
BlockProcessor.prototype.processPositionBlock = function () {
|
|
67
|
+
if (!this.inappElement.x) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.renderer.setStyle(this.inappHTMLEl, 'position', 'absolute');
|
|
71
|
+
if (this.inappElement.x)
|
|
72
|
+
this.renderer.setStyle(this.inappHTMLEl, 'top', this.getSizePx(this.inappElement.y));
|
|
73
|
+
if (this.inappElement.y)
|
|
74
|
+
this.renderer.setStyle(this.inappHTMLEl, 'left', this.getSizePx(this.inappElement.x));
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Process border block of the element
|
|
78
|
+
*/
|
|
79
|
+
BlockProcessor.prototype.processBorderBlock = function () {
|
|
80
|
+
var _a;
|
|
81
|
+
var border = this.inappElement.br;
|
|
82
|
+
if (!border) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Just to make sure radius is not a negative number
|
|
86
|
+
if (border.radius && border.radius > 0) {
|
|
87
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-radius', this.getSizePx(border.radius));
|
|
88
|
+
}
|
|
89
|
+
// Just to make sure width is not a negative number
|
|
90
|
+
if (border.width && border.width > 0) {
|
|
91
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-width', this.getSizePx(border.width));
|
|
92
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-style', (_a = border.style) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
93
|
+
if (border.color) {
|
|
94
|
+
this.processColourBlock(border.color, 'border-color');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.renderer.setStyle(this.inappHTMLEl, 'border-color', 'black');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Process space block of the element which include margin and padding.
|
|
103
|
+
*/
|
|
104
|
+
BlockProcessor.prototype.processSpaceBlock = function () {
|
|
105
|
+
var space = this.inappElement.spc;
|
|
106
|
+
if (!space) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (space.p)
|
|
110
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding', this.getSizePx(space.p));
|
|
111
|
+
if (space.pt)
|
|
112
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-top', this.getSizePx(space.pt));
|
|
113
|
+
if (space.pb)
|
|
114
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-bottom', this.getSizePx(space.pb));
|
|
115
|
+
if (space.pl)
|
|
116
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-left', this.getSizePx(space.pl));
|
|
117
|
+
if (space.pr)
|
|
118
|
+
this.renderer.setStyle(this.inappHTMLEl, 'padding-right', this.getSizePx(space.pr));
|
|
119
|
+
this.renderer.setStyle(this.inappHTMLEl, 'margin', '0 !important');
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Process transform block of the element
|
|
123
|
+
*/
|
|
124
|
+
BlockProcessor.prototype.processTransformBlock = function () {
|
|
125
|
+
var transform = this.inappElement.trf;
|
|
126
|
+
if (!transform) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (transform.rotate) {
|
|
130
|
+
this.renderer.setStyle(this.inappHTMLEl, 'transform', "rotate(" + transform.rotate + "deg)");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Register click-to-action(CTA) block of the element
|
|
135
|
+
*/
|
|
136
|
+
BlockProcessor.prototype.registerAction = function () {
|
|
137
|
+
var action = this.inappElement.clc;
|
|
138
|
+
if (!action) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.inappHTMLEl.addEventListener('click', function () {
|
|
142
|
+
new ClickActionExecutor(action).execute();
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Process background block of the element
|
|
147
|
+
*/
|
|
148
|
+
BlockProcessor.prototype.processBackgroundBlock = function () {
|
|
149
|
+
var _a;
|
|
150
|
+
var bg = this.inappElement.bg;
|
|
151
|
+
if (!bg) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var htmlElement = this.inappHTMLEl;
|
|
155
|
+
// For container, the background must be applied to its parent i.e. root container
|
|
156
|
+
if (this.inappElement instanceof Container) {
|
|
157
|
+
htmlElement = htmlElement.parentElement;
|
|
158
|
+
}
|
|
159
|
+
var prefix = '';
|
|
160
|
+
if ((_a = new UAParser().getBrowser().name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('safari')) {
|
|
161
|
+
prefix = '-webkit-';
|
|
162
|
+
}
|
|
163
|
+
if (bg.glossy) {
|
|
164
|
+
this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "blur(" + bg.glossy.radius + "px)");
|
|
165
|
+
if (bg.glossy.color) {
|
|
166
|
+
this.processColourBlock(bg.glossy.color, 'background', htmlElement);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (bg.solid) {
|
|
170
|
+
if (bg.solid.grad) {
|
|
171
|
+
this.processGradient(bg.solid.grad, 'background');
|
|
172
|
+
}
|
|
173
|
+
else if (bg.solid.hex) {
|
|
174
|
+
this.renderer.setStyle(htmlElement, 'background', bg.solid.rgba);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (bg.img) {
|
|
178
|
+
if (!bg.img.src) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
var value = "url(\"" + bg.img.src + "\") no-repeat center";
|
|
182
|
+
this.renderer.setStyle(htmlElement, 'background', value);
|
|
183
|
+
this.renderer.setStyle(htmlElement, 'background-size', 'cover');
|
|
184
|
+
if (bg.img.a) {
|
|
185
|
+
this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "opacity(" + bg.img.a + ")");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Process linear gradient and add to the element
|
|
191
|
+
* @param {Gradient} grad gradient value
|
|
192
|
+
* @param {string} attribute attribute on which gradient needs to be applied
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
BlockProcessor.prototype.processGradient = function (grad, attribute) {
|
|
196
|
+
if (grad.type === 'LINEAR') {
|
|
197
|
+
var linearFunctionString = "linear-gradient(" + grad.ang + "deg, " + grad.c1 + ", " + grad.c2;
|
|
198
|
+
if (grad.c3) {
|
|
199
|
+
linearFunctionString += ", " + grad.c3;
|
|
200
|
+
}
|
|
201
|
+
if (grad.c4) {
|
|
202
|
+
linearFunctionString += ", " + grad.c4;
|
|
203
|
+
}
|
|
204
|
+
if (grad.c5) {
|
|
205
|
+
linearFunctionString += ", " + grad.c5;
|
|
206
|
+
}
|
|
207
|
+
linearFunctionString += ")";
|
|
208
|
+
var gradient = linearFunctionString;
|
|
209
|
+
this.renderer.setStyle(this.inappHTMLEl, attribute, gradient);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Process colour block of the element
|
|
214
|
+
* @param {Color} colour colour data of the element
|
|
215
|
+
* @param {string} attribute attribute on which colour data need to be applied
|
|
216
|
+
* @param {HTMLElement} element Any other element to apply the color apart from {@link inappHTMLEl}
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
BlockProcessor.prototype.processColourBlock = function (colour, attribute, element) {
|
|
220
|
+
if (attribute === void 0) { attribute = 'color'; }
|
|
221
|
+
if (element === void 0) { element = this.inappHTMLEl; }
|
|
222
|
+
if (!colour) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (colour.grad) {
|
|
226
|
+
this.processGradient(colour.grad, attribute);
|
|
227
|
+
}
|
|
228
|
+
else if (colour.hex) {
|
|
229
|
+
this.renderer.setStyle(element, attribute, colour.rgba);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return BlockProcessor;
|
|
233
|
+
}());
|
|
234
|
+
export { BlockProcessor };
|