@letscooee/web-sdk 0.0.12 → 0.0.13

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Features
6
+
7
+ 1. Support dynamic canvas size.
8
+ 2. Ability to set colors on in-app and container separately.
9
+
10
+ ### Improvements
11
+
12
+ 1. Add hand pointer for CTAs.
13
+ 2. Add push prompt CTA.
14
+
3
15
  ## 0.0.11, 0.0.12
4
16
 
5
17
  ### Fixes
@@ -35,11 +35,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import { Constants } from '../../../constants';
38
- import { IFrameRenderer, RootContainerRenderer } from '../../../renderer';
38
+ import { IFrameRenderer } from '../../../renderer';
39
+ import { Renderer } from '../../../renderer/renderer';
39
40
  import { SafeHttpService } from '../../../services/safe-http-service';
41
+ import { LocalStorageHelper } from '../../../utils/local-storage-helper';
40
42
  import { Log } from '../../../utils/log';
41
43
  import { Event } from '../../event/event';
42
- import { LocalStorageHelper } from '../../../utils/local-storage-helper';
43
44
  import { Permission } from '../blocks/click-action';
44
45
  /**
45
46
  * Performs click to action on in-app elements
@@ -128,7 +129,7 @@ var ClickActionExecutor = /** @class */ (function () {
128
129
  if (!this.action.close) {
129
130
  return;
130
131
  }
131
- new RootContainerRenderer().removeInApp();
132
+ Renderer.get().removeInApp();
132
133
  var startTime = LocalStorageHelper.getNumber(Constants.STORAGE_TRIGGER_START_TIME, new Date().getTime());
133
134
  var triggerID = (_a = LocalStorageHelper.getObject(Constants.STORAGE_ACTIVE_TRIGGER)) === null || _a === void 0 ? void 0 : _a.triggerID;
134
135
  var diffInSeconds = (new Date().getTime() - startTime) / 1000;
@@ -5,5 +5,5 @@ export var Permission;
5
5
  // eslint-disable-next-line no-unused-vars
6
6
  Permission[Permission["LOCATION"] = 2] = "LOCATION";
7
7
  // eslint-disable-next-line no-unused-vars
8
- Permission[Permission["PUSH"] = 6] = "PUSH";
8
+ Permission[Permission["PUSH"] = 3] = "PUSH";
9
9
  })(Permission || (Permission = {}));
@@ -17,9 +17,12 @@ import { BaseElement } from '../elements';
17
17
  var Container = /** @class */ (function (_super) {
18
18
  __extends(Container, _super);
19
19
  function Container(data) {
20
- var _a;
20
+ var _a, _b, _c;
21
21
  var _this = _super.call(this, data) || this;
22
22
  _this.o = (_a = data.o) !== null && _a !== void 0 ? _a : ContainerOrigin.C;
23
+ // For backward compatibility
24
+ _this.w = (_b = _this.w) !== null && _b !== void 0 ? _b : 1080;
25
+ _this.h = (_c = _this.h) !== null && _c !== void 0 ? _c : 1920;
23
26
  return _this;
24
27
  }
25
28
  Container.prototype.getOrigin = function () {
@@ -1,18 +1,41 @@
1
- import { Container } from './container';
2
- import { ImageElement, ShapeElement, TextElement } from '../elements';
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, ImageElement, ShapeElement, TextElement } from '../elements';
3
17
  import { ElementType } from '../elements/base-element';
18
+ import { Container } from './container';
4
19
  /**
5
20
  * Stores data present in ian (In App) block in {@link TriggerData}
6
21
  *
7
22
  * @author Abhishek Taparia
8
23
  * @version 0.0.5
9
24
  */
10
- var InAppTrigger = /** @class */ (function () {
25
+ var InAppTrigger = /** @class */ (function (_super) {
26
+ __extends(InAppTrigger, _super);
11
27
  function InAppTrigger(data) {
12
- var _this = this;
13
- this.elems = [];
14
- this.cont = new Container(data.cont);
15
- this.gvt = data.gvt;
28
+ var _this =
29
+ // Only background is supported for in-apps
30
+ _super.call(this, { bg: data.bg }) || this;
31
+ _this.elems = [];
32
+ _this.cont = new Container(data.cont);
33
+ _this.gvt = data.gvt;
34
+ // Backward compatibility
35
+ if (!_this.bg) {
36
+ _this.bg = _this.cont.bg;
37
+ delete _this.cont.bg;
38
+ }
16
39
  data.elems.forEach(function (rawElement) {
17
40
  if (rawElement.t === ElementType.IMAGE) {
18
41
  _this.elems.push(new ImageElement(rawElement));
@@ -27,6 +50,7 @@ var InAppTrigger = /** @class */ (function () {
27
50
  _this.elems.push(new ShapeElement(rawElement));
28
51
  }
29
52
  });
53
+ return _this;
30
54
  }
31
55
  InAppTrigger.prototype.getStyles = function () {
32
56
  var styles;
@@ -94,7 +118,7 @@ var InAppTrigger = /** @class */ (function () {
94
118
  return styles;
95
119
  };
96
120
  return InAppTrigger;
97
- }());
121
+ }(BaseElement));
98
122
  export { InAppTrigger };
99
123
  export var ContainerOrigin;
100
124
  (function (ContainerOrigin) {
@@ -1,8 +1,7 @@
1
- import { Renderer } from './renderer';
2
1
  import { ClickActionExecutor } from '../models/trigger/action/click-action-executor';
3
2
  import { Transform } from '../models/trigger/blocks';
4
- import { getScalingFactor } from './index';
5
3
  import { Container } from '../models/trigger/inapp/container';
4
+ import { Renderer } from './renderer';
6
5
  /**
7
6
  * Process all the block of in-app
8
7
  *
@@ -14,9 +13,9 @@ var BlockProcessor = /** @class */ (function () {
14
13
  this.renderer = Renderer.get();
15
14
  this.screenWidth = 0;
16
15
  this.screenHeight = 0;
17
- this.scalingFactor = getScalingFactor();
18
16
  this.parentHTMLEl = parentHTMLEl;
19
17
  this.inappElement = inappElement;
18
+ this.scalingFactor = this.renderer.getScalingFactor();
20
19
  this.screenWidth = this.renderer.getWidth();
21
20
  this.screenHeight = this.renderer.getHeight();
22
21
  }
@@ -131,13 +130,19 @@ var BlockProcessor = /** @class */ (function () {
131
130
  */
132
131
  BlockProcessor.prototype.registerAction = function () {
133
132
  var action = this.inappElement.clc;
134
- if (!action) {
133
+ if (!action || Object.keys(action).length === 0) {
135
134
  return;
136
135
  }
137
136
  this.inappHTMLEl.addEventListener('click', function (event) {
138
137
  event.stopPropagation();
139
138
  new ClickActionExecutor(action).execute();
140
139
  });
140
+ if (!(this.inappElement instanceof Container)) {
141
+ this.renderer.setStyle(this.inappHTMLEl, 'cursor', "pointer");
142
+ }
143
+ else if (!(Object.keys(action).length === 1 && action.close !== undefined && action.close !== null)) {
144
+ this.renderer.setStyle(this.inappHTMLEl, 'cursor', "pointer");
145
+ }
141
146
  };
142
147
  /**
143
148
  * Process background block of the element
@@ -148,10 +153,6 @@ var BlockProcessor = /** @class */ (function () {
148
153
  return;
149
154
  }
150
155
  var htmlElement = this.inappHTMLEl;
151
- // For container, the background must be applied to its parent i.e. root container
152
- if (this.inappElement instanceof Container) {
153
- htmlElement = htmlElement.parentElement;
154
- }
155
156
  if (bg.glossy) {
156
157
  // Style for Apple devices
157
158
  this.renderer.setStyle(htmlElement, '-webkit-backdrop-filter', "blur(" + bg.glossy.radius + "px)");
@@ -26,9 +26,6 @@ var ContainerRenderer = /** @class */ (function (_super) {
26
26
  var _this = _super.call(this, parentElement, inappElement) || this;
27
27
  _this.inappHTMLEl = _this.renderer.createElement('div');
28
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
29
  return _this;
33
30
  }
34
31
  /**
@@ -1,13 +1,14 @@
1
- import { Log } from '../utils/log';
1
+ import { Constants } from '../constants';
2
+ import { Event } from '../models/event/event';
2
3
  import { ImageElement, ShapeElement, TextElement } from '../models/trigger/elements/';
3
4
  import { TriggerData } from '../models/trigger/trigger-data';
5
+ import { TriggerHelper } from '../models/trigger/trigger-helper';
6
+ import { SafeHttpService } from '../services/safe-http-service';
4
7
  import { LocalStorageHelper } from '../utils/local-storage-helper';
5
- import { Constants } from '../constants';
8
+ import { Log } from '../utils/log';
6
9
  import { ImageRenderer, RootContainerRenderer, ShapeRenderer, TextRenderer } from './';
7
10
  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
+ import { Renderer } from './renderer';
11
12
  /**
12
13
  * Renders In App trigger
13
14
  *
@@ -21,8 +22,9 @@ var InAppRenderer = /** @class */ (function () {
21
22
  * @param parent Place the in-app in the given parent instead of the document.body.
22
23
  */
23
24
  function InAppRenderer(parent) {
24
- this.parent = parent;
25
- this.rootContainer = new RootContainerRenderer(parent).render();
25
+ this.renderer = Renderer.get();
26
+ this.parent = parent !== null && parent !== void 0 ? parent : document.body;
27
+ this.renderer.setParentContainer(this.parent);
26
28
  }
27
29
  /**
28
30
  * Renders in-app trigger from payload received
@@ -31,6 +33,8 @@ var InAppRenderer = /** @class */ (function () {
31
33
  InAppRenderer.prototype.render = function (triggerData) {
32
34
  triggerData = new TriggerData(triggerData);
33
35
  this.ian = triggerData.ian;
36
+ this.rootContainer = new RootContainerRenderer(this.parent, this.ian)
37
+ .render();
34
38
  try {
35
39
  this.renderContainer();
36
40
  var event_1 = new Event('CE Trigger Displayed', { 'triggerID': triggerData.id });
@@ -72,10 +76,11 @@ var InAppRenderer = /** @class */ (function () {
72
76
  if (!container) {
73
77
  return;
74
78
  }
79
+ this.renderer.calculateScalingFactor(container.w, container.h);
75
80
  var containerHTMLElement = new ContainerRenderer(this.rootContainer, container)
76
81
  .render()
77
82
  .getHTMLElement();
78
- // Forward compatibility
83
+ // Backward compatibility
79
84
  if (!this.ian.gvt) {
80
85
  this.ian.gvt = this.ian.cont.getOrigin();
81
86
  }
@@ -1,26 +1,5 @@
1
- import { Constants } from '../constants';
2
- import { Renderer } from './renderer';
3
1
  export { TextRenderer } from './text-renderer';
4
2
  export { ShapeRenderer } from './shape-renderer';
5
3
  export { ImageRenderer } from './image-renderer';
6
4
  export { RootContainerRenderer } from './root-container-renderer';
7
5
  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
- }
@@ -1,3 +1,4 @@
1
+ import { Constants } from '../constants';
1
2
  /**
2
3
  * Utility class for creating and rendering elements.
3
4
  *
@@ -35,6 +36,24 @@ var Renderer = /** @class */ (function () {
35
36
  }
36
37
  return document.documentElement.clientHeight;
37
38
  };
39
+ /**
40
+ * Calculate scaling factor according to parent most container where the in-app's root container will be rendered.
41
+ *
42
+ * @param canvasWidth The width of the canvas to render.
43
+ * @param canvasHeight The height of the canvas to render.
44
+ */
45
+ Renderer.prototype.calculateScalingFactor = function (canvasWidth, canvasHeight) {
46
+ var screenWidth = Renderer.get().getWidth();
47
+ var screenHeight = Renderer.get().getHeight();
48
+ var longEdgeOfCanvas = Math.max(canvasWidth, canvasHeight);
49
+ var shortEdgeOfScreen = Math.min(screenWidth, screenHeight);
50
+ var scalingFactor = shortEdgeOfScreen / longEdgeOfCanvas;
51
+ // The in-app should not scale beyond 100%
52
+ this.scalingFactor = Math.min(scalingFactor, 1);
53
+ };
54
+ Renderer.prototype.getScalingFactor = function () {
55
+ return this.scalingFactor;
56
+ };
38
57
  /**
39
58
  * Creates an element
40
59
  * @param {string} elementType element type to be created
@@ -77,6 +96,15 @@ var Renderer = /** @class */ (function () {
77
96
  Renderer.prototype.setAttribute = function (element, attrName, value) {
78
97
  element.setAttribute(attrName, value);
79
98
  };
99
+ /**
100
+ * Remove InApp trigger.
101
+ */
102
+ Renderer.prototype.removeInApp = function () {
103
+ var rootDiv = document.querySelector("." + Constants.IN_APP_CONTAINER_NAME);
104
+ if (rootDiv) {
105
+ rootDiv.parentElement.removeChild(rootDiv);
106
+ }
107
+ };
80
108
  /**
81
109
  * Set the parent most container where the Cooee's In-App's root div will render.
82
110
  * @param container The HTML holder element.
@@ -1,17 +1,34 @@
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
+ })();
1
16
  import { Constants } from '../constants';
2
- import { Renderer } from './renderer';
3
17
  import { ClickActionExecutor } from '../models/trigger/action/click-action-executor';
18
+ import { BlockProcessor } from './block-processor';
4
19
  /**
5
20
  * Renders root container.
6
21
  *
7
22
  * @author Abhishek Taparia
8
23
  * @version 0.0.5
9
24
  */
10
- var RootContainerRenderer = /** @class */ (function () {
11
- function RootContainerRenderer(parent) {
12
- this.parent = parent;
13
- this.renderer = Renderer.get();
14
- this.renderer.setParentContainer(parent);
25
+ var RootContainerRenderer = /** @class */ (function (_super) {
26
+ __extends(RootContainerRenderer, _super);
27
+ function RootContainerRenderer(parent, inappElement) {
28
+ var _this = _super.call(this, parent, inappElement) || this;
29
+ _this.parent = parent;
30
+ _this.inappHTMLEl = _this.renderer.createElement('div');
31
+ return _this;
15
32
  }
16
33
  /**
17
34
  * Render root container.
@@ -19,37 +36,27 @@ var RootContainerRenderer = /** @class */ (function () {
19
36
  */
20
37
  RootContainerRenderer.prototype.render = function () {
21
38
  if (!this.parent) {
22
- this.removeInApp();
39
+ this.renderer.removeInApp();
23
40
  }
24
- var rootDiv = this.renderer.createElement('div');
25
- rootDiv.classList.add(Constants.IN_APP_CONTAINER_NAME);
26
- if (this.parent) {
27
- this.renderer.setStyle(rootDiv, 'position', 'absolute');
41
+ this.processBackgroundBlock();
42
+ this.inappHTMLEl.classList.add(Constants.IN_APP_CONTAINER_NAME);
43
+ if (this.parent !== document.body) {
44
+ this.renderer.setStyle(this.inappHTMLEl, 'position', 'absolute');
28
45
  }
29
46
  else {
30
- this.renderer.setStyle(rootDiv, 'position', 'fixed');
47
+ this.renderer.setStyle(this.inappHTMLEl, 'position', 'fixed');
31
48
  }
32
- this.renderer.setStyle(rootDiv, 'z-index', '10000000');
33
- this.renderer.setStyle(rootDiv, 'top', '0');
34
- this.renderer.setStyle(rootDiv, 'left', '0');
35
- this.renderer.setStyle(rootDiv, 'width', '100%');
36
- this.renderer.setStyle(rootDiv, 'height', '100%');
37
- this.renderer.appendChild(this.parent || document.body, rootDiv);
38
- rootDiv.addEventListener('click', function () {
49
+ this.renderer.setStyle(this.inappHTMLEl, 'z-index', '10000000');
50
+ this.renderer.setStyle(this.inappHTMLEl, 'top', '0');
51
+ this.renderer.setStyle(this.inappHTMLEl, 'left', '0');
52
+ this.renderer.setStyle(this.inappHTMLEl, 'width', '100%');
53
+ this.renderer.setStyle(this.inappHTMLEl, 'height', '100%');
54
+ this.insertElement();
55
+ this.inappHTMLEl.addEventListener('click', function () {
39
56
  new ClickActionExecutor({ close: true }).execute();
40
57
  });
41
- return rootDiv;
42
- };
43
- // noinspection JSMethodCanBeStatic
44
- /**
45
- * Remove InApp trigger.
46
- */
47
- RootContainerRenderer.prototype.removeInApp = function () {
48
- var rootDiv = document.querySelector("." + Constants.IN_APP_CONTAINER_NAME);
49
- if (rootDiv) {
50
- rootDiv.parentElement.removeChild(rootDiv);
51
- }
58
+ return this.inappHTMLEl;
52
59
  };
53
60
  return RootContainerRenderer;
54
- }());
61
+ }(BlockProcessor));
55
62
  export { RootContainerRenderer };