@letscooee/web-sdk 0.0.8 → 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,29 +1,64 @@
1
1
  # Change Log
2
2
 
3
- # 0.0.8
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
+
15
+ ## 0.0.11, 0.0.12
16
+
17
+ ### Fixes
18
+
19
+ 1. Rendering condition for x(left) and y(top) position.
20
+ 2. Rotation of the text.
21
+
22
+ ## 0.0.10 (unreleased)
23
+
24
+ ### Improvement:
25
+ 1. Get trigger direction(gravity) for InAppTrigger.
26
+
27
+ ### Fixes
28
+ 1. Rename `prompt` to `pmpt`.
29
+ 2. Use device api instead of user api to send device data.
30
+
31
+ ## 0.0.9
32
+
33
+ 1. Fix: glassmorphism on iOS.
34
+ 2. Fix: Fix rendering scaled images.
35
+ 3. Fix: Update in KPI for CTA.
36
+ 4. Fix: Do not remove in-app if being used inside an element.
37
+
38
+ ## 0.0.8
4
39
 
5
40
  1. Feature: Ability of InApp to be rendered inside an element.
6
41
  2. Fix: Overflowed content should not be rendered.
7
42
  3. Fix: Placing in-app on east direction.
8
43
 
9
- # 0.0.7
44
+ ## 0.0.7
10
45
 
11
46
  More feature support in the sdk.
12
47
 
13
- # 0.0.6
48
+ ## 0.0.6
14
49
 
15
50
  1. Build: Upgrade TypeScript to 4.4.
16
51
  2. Fix: Convert \n to `<br>` in texts.
17
52
 
18
- # 0.0.5
53
+ ## 0.0.5
19
54
 
20
55
  Supporting changes based on the in-app composer.
21
56
 
22
- # 0.0.3, 0.0.4
57
+ ## 0.0.3, 0.0.4
23
58
 
24
59
  1. Fix generating token because of missing app version.
25
60
  2. Handle scenario when `CooeeSDK` is not initialised.
26
61
 
27
- # 0.0.2
62
+ ## 0.0.2
28
63
 
29
64
  First functional release.
@@ -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
@@ -105,18 +106,18 @@ var ClickActionExecutor = /** @class */ (function () {
105
106
  * Performs prompt action i.e. ask for permission for location and notification.
106
107
  */
107
108
  ClickActionExecutor.prototype.prompt = function () {
108
- var permission = this.action.prompt;
109
+ var permission = this.action.pmpt;
109
110
  if (!permission) {
110
111
  return;
111
112
  }
112
113
  // TODO test in mobile browsers
113
- if (permission === Permission.Location) {
114
+ if (permission === Permission.LOCATION) {
114
115
  this.promptLocationPermission();
115
116
  }
116
- if (permission === Permission.Push) {
117
+ if (permission === Permission.PUSH) {
117
118
  this.promptPushNotificationPermission();
118
119
  }
119
- if (permission === Permission.Camera) {
120
+ if (permission === Permission.CAMERA) {
120
121
  this.promptCameraPermission();
121
122
  }
122
123
  };
@@ -128,14 +129,22 @@ 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;
136
+ var closeBehaviour;
137
+ if (this.action.ext || this.action.up || this.action.kv ||
138
+ this.action.iab || this.action.pmpt || this.action.share) {
139
+ closeBehaviour = 'CTA';
140
+ }
141
+ else {
142
+ closeBehaviour = 'Close';
143
+ }
135
144
  var eventProps = {
136
145
  'triggerID': triggerID,
137
- 'Close Behaviour': 'CTA',
138
- 'Duration': diffInSeconds,
146
+ 'closeBehaviour': closeBehaviour,
147
+ 'duration': diffInSeconds,
139
148
  };
140
149
  this.apiService.sendEvent(new Event('CE Trigger Closed', eventProps));
141
150
  LocalStorageHelper.remove(Constants.STORAGE_TRIGGER_START_TIME);
@@ -171,7 +180,7 @@ var ClickActionExecutor = /** @class */ (function () {
171
180
  }
172
181
  // TODO Need device endpoints to update this property
173
182
  navigator.geolocation.getCurrentPosition(function (position) {
174
- _this.apiService.updateProfile({ 'coords': [position.coords.latitude, position.coords.longitude] });
183
+ _this.apiService.updateDeviceProps({ 'coords': [position.coords.latitude, position.coords.longitude] });
175
184
  _this.sendPermissionData();
176
185
  });
177
186
  };
@@ -187,7 +196,7 @@ var ClickActionExecutor = /** @class */ (function () {
187
196
  }
188
197
  // TODO Need device endpoints to update this property
189
198
  if (Notification.permission !== 'default') {
190
- this.apiService.updateProfile({ 'pnPerm': Notification.permission });
199
+ this.apiService.updateDeviceProps({ 'pnPerm': Notification.permission });
191
200
  return;
192
201
  }
193
202
  Notification.requestPermission()
@@ -252,7 +261,7 @@ var ClickActionExecutor = /** @class */ (function () {
252
261
  ClickActionExecutor.prototype.sendPermissionData = function () {
253
262
  var _this = this;
254
263
  this.checkAllPermission().then(function (permissions) {
255
- _this.apiService.updateProfile({ 'perm': permissions });
264
+ _this.apiService.updateDeviceProps({ 'perm': permissions });
256
265
  });
257
266
  };
258
267
  return ClickActionExecutor;
@@ -1,9 +1,9 @@
1
1
  export var Permission;
2
2
  (function (Permission) {
3
3
  // eslint-disable-next-line no-unused-vars
4
- Permission["Location"] = "LOCATION";
4
+ Permission[Permission["CAMERA"] = 1] = "CAMERA";
5
5
  // eslint-disable-next-line no-unused-vars
6
- Permission["Push"] = "PUSH";
6
+ Permission[Permission["LOCATION"] = 2] = "LOCATION";
7
7
  // eslint-disable-next-line no-unused-vars
8
- Permission["Camera"] = "CAMERA";
8
+ Permission[Permission["PUSH"] = 3] = "PUSH";
9
9
  })(Permission || (Permission = {}));
@@ -1,5 +1,7 @@
1
1
  var Transform = /** @class */ (function () {
2
- function Transform() {
2
+ function Transform(data) {
3
+ if (data === null || data === void 0 ? void 0 : data.rot)
4
+ this.rot = data.rot;
3
5
  }
4
6
  Object.defineProperty(Transform.prototype, "rotate", {
5
7
  get: function () {
@@ -1,4 +1,4 @@
1
- import { Background, Border } from '../blocks';
1
+ import { Background, Border, Transform } from '../blocks';
2
2
  var BaseElement = /** @class */ (function () {
3
3
  function BaseElement(data) {
4
4
  this.t = data.t;
@@ -6,10 +6,10 @@ var BaseElement = /** @class */ (function () {
6
6
  this.bg = new Background(data.bg);
7
7
  if (data.br)
8
8
  this.br = new Border(data.br);
9
+ this.trf = new Transform(data.trf);
9
10
  this.clc = data.clc;
10
11
  this.shd = data.shd;
11
12
  this.spc = data.spc;
12
- this.trf = data.trf;
13
13
  this.w = data.w;
14
14
  this.h = data.h;
15
15
  this.x = data.x;
@@ -17,75 +17,16 @@ 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
- 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
- right: 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
- styles.overflow = 'hidden';
88
- return styles;
28
+ Container.prototype.getOrigin = function () {
29
+ return this.o;
89
30
  };
90
31
  return Container;
91
32
  }(BaseElement));
@@ -1,17 +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);
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
+ }
15
39
  data.elems.forEach(function (rawElement) {
16
40
  if (rawElement.t === ElementType.IMAGE) {
17
41
  _this.elems.push(new ImageElement(rawElement));
@@ -26,7 +50,85 @@ var InAppTrigger = /** @class */ (function () {
26
50
  _this.elems.push(new ShapeElement(rawElement));
27
51
  }
28
52
  });
53
+ return _this;
29
54
  }
55
+ InAppTrigger.prototype.getStyles = function () {
56
+ var styles;
57
+ if (this.gvt === ContainerOrigin.NW) {
58
+ styles = {
59
+ top: 0,
60
+ left: 0,
61
+ };
62
+ }
63
+ else if (this.gvt === ContainerOrigin.N) {
64
+ styles = {
65
+ top: 0,
66
+ left: '50%',
67
+ transform: 'translateX(-50%)',
68
+ };
69
+ }
70
+ else if (this.gvt === ContainerOrigin.NE) {
71
+ styles = {
72
+ top: 0,
73
+ right: 0,
74
+ };
75
+ }
76
+ else if (this.gvt === ContainerOrigin.E) {
77
+ styles = {
78
+ top: '50%',
79
+ right: 0,
80
+ transform: 'translateY(-50%)',
81
+ };
82
+ }
83
+ else if (this.gvt === ContainerOrigin.SE) {
84
+ styles = {
85
+ bottom: 0,
86
+ right: 0,
87
+ };
88
+ }
89
+ else if (this.gvt === ContainerOrigin.S) {
90
+ styles = {
91
+ bottom: 0,
92
+ left: '50%',
93
+ transform: 'translateX(-50%)',
94
+ };
95
+ }
96
+ else if (this.gvt === ContainerOrigin.SW) {
97
+ styles = {
98
+ bottom: 0,
99
+ left: 0,
100
+ };
101
+ }
102
+ else if (this.gvt === ContainerOrigin.W) {
103
+ styles = {
104
+ top: '50%',
105
+ left: 0,
106
+ transform: 'translateY(-50%)',
107
+ };
108
+ }
109
+ else {
110
+ styles = {
111
+ top: '50%',
112
+ left: '50%',
113
+ transform: 'translateX(-50%) translateY(-50%)',
114
+ };
115
+ }
116
+ styles.position = 'absolute';
117
+ styles.overflow = 'hidden';
118
+ return styles;
119
+ };
30
120
  return InAppTrigger;
31
- }());
121
+ }(BaseElement));
32
122
  export { InAppTrigger };
123
+ export var ContainerOrigin;
124
+ (function (ContainerOrigin) {
125
+ ContainerOrigin[ContainerOrigin["NW"] = 1] = "NW";
126
+ ContainerOrigin[ContainerOrigin["N"] = 2] = "N";
127
+ ContainerOrigin[ContainerOrigin["NE"] = 3] = "NE";
128
+ ContainerOrigin[ContainerOrigin["W"] = 4] = "W";
129
+ ContainerOrigin[ContainerOrigin["C"] = 5] = "C";
130
+ ContainerOrigin[ContainerOrigin["E"] = 6] = "E";
131
+ ContainerOrigin[ContainerOrigin["SW"] = 7] = "SW";
132
+ ContainerOrigin[ContainerOrigin["S"] = 8] = "S";
133
+ ContainerOrigin[ContainerOrigin["SE"] = 9] = "SE";
134
+ })(ContainerOrigin || (ContainerOrigin = {}));
@@ -1,8 +1,7 @@
1
- import { Renderer } from './renderer';
2
- import UAParser from 'ua-parser-js';
3
1
  import { ClickActionExecutor } from '../models/trigger/action/click-action-executor';
4
- import { getScalingFactor } from './index';
2
+ import { Transform } from '../models/trigger/blocks';
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
  }
@@ -63,14 +62,11 @@ var BlockProcessor = /** @class */ (function () {
63
62
  * Process position block of the element
64
63
  */
65
64
  BlockProcessor.prototype.processPositionBlock = function () {
66
- if (!this.inappElement.x) {
67
- return;
68
- }
69
65
  this.renderer.setStyle(this.inappHTMLEl, 'position', 'absolute');
70
66
  if (this.inappElement.x)
71
- this.renderer.setStyle(this.inappHTMLEl, 'top', this.getSizePx(this.inappElement.y));
72
- if (this.inappElement.y)
73
67
  this.renderer.setStyle(this.inappHTMLEl, 'left', this.getSizePx(this.inappElement.x));
68
+ if (this.inappElement.y)
69
+ this.renderer.setStyle(this.inappHTMLEl, 'top', this.getSizePx(this.inappElement.y));
74
70
  };
75
71
  /**
76
72
  * Process border block of the element
@@ -121,7 +117,7 @@ var BlockProcessor = /** @class */ (function () {
121
117
  * Process transform block of the element
122
118
  */
123
119
  BlockProcessor.prototype.processTransformBlock = function () {
124
- var transform = this.inappElement.trf;
120
+ var transform = new Transform(this.inappElement.trf);
125
121
  if (!transform) {
126
122
  return;
127
123
  }
@@ -134,33 +130,34 @@ var BlockProcessor = /** @class */ (function () {
134
130
  */
135
131
  BlockProcessor.prototype.registerAction = function () {
136
132
  var action = this.inappElement.clc;
137
- if (!action) {
133
+ if (!action || Object.keys(action).length === 0) {
138
134
  return;
139
135
  }
140
- this.inappHTMLEl.addEventListener('click', function () {
136
+ this.inappHTMLEl.addEventListener('click', function (event) {
137
+ event.stopPropagation();
141
138
  new ClickActionExecutor(action).execute();
142
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
+ }
143
146
  };
144
147
  /**
145
148
  * Process background block of the element
146
149
  */
147
150
  BlockProcessor.prototype.processBackgroundBlock = function () {
148
- var _a;
149
151
  var bg = this.inappElement.bg;
150
152
  if (!bg) {
151
153
  return;
152
154
  }
153
155
  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
156
  if (bg.glossy) {
163
- this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "blur(" + bg.glossy.radius + "px)");
157
+ // Style for Apple devices
158
+ this.renderer.setStyle(htmlElement, '-webkit-backdrop-filter', "blur(" + bg.glossy.radius + "px)");
159
+ // Style for other devices
160
+ this.renderer.setStyle(htmlElement, 'backdrop-filter', "blur(" + bg.glossy.radius + "px)");
164
161
  if (bg.glossy.color) {
165
162
  this.processColourBlock(bg.glossy.color, 'background', htmlElement);
166
163
  }
@@ -181,7 +178,10 @@ var BlockProcessor = /** @class */ (function () {
181
178
  this.renderer.setStyle(htmlElement, 'background', value);
182
179
  this.renderer.setStyle(htmlElement, 'background-size', 'cover');
183
180
  if (bg.img.a) {
184
- this.renderer.setStyle(htmlElement, prefix + 'backdrop-filter', "opacity(" + bg.img.a + ")");
181
+ // Style for Apple devices
182
+ this.renderer.setStyle(htmlElement, '-webkit-backdrop-filter', "opacity(" + bg.img.a + ")");
183
+ // Style for other devices
184
+ this.renderer.setStyle(htmlElement, 'backdrop-filter', "opacity(" + bg.img.a + ")");
185
185
  }
186
186
  }
187
187
  };
@@ -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
  /**
@@ -38,7 +35,6 @@ var ContainerRenderer = /** @class */ (function (_super) {
38
35
  ContainerRenderer.prototype.render = function () {
39
36
  this.processCommonBlocks();
40
37
  this.renderer.setStyle(this.inappHTMLEl, 'position', 'relative');
41
- Object.assign(this.inappHTMLEl.style, this.inappElement.getStyles());
42
38
  return this;
43
39
  };
44
40
  return ContainerRenderer;
@@ -17,7 +17,7 @@ var IFrameRenderer = /** @class */ (function () {
17
17
  * @private
18
18
  */
19
19
  IFrameRenderer.prototype.render = function (url) {
20
- var root = this.renderer.getElementById(Constants.IN_APP_CONTAINER_NAME);
20
+ var root = document.querySelector("." + Constants.IN_APP_CONTAINER_NAME);
21
21
  var iFrameDiv = this.createIFrameContainer();
22
22
  this.createIFrameElement(iFrameDiv, url);
23
23
  // Create and render close button for iFrame with anchor tag
@@ -33,8 +33,8 @@ var ImageRenderer = /** @class */ (function (_super) {
33
33
  */
34
34
  ImageRenderer.prototype.render = function () {
35
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%');
36
+ this.renderer.setStyle(this.inappHTMLEl, 'max-width', 'none');
37
+ this.renderer.setStyle(this.inappHTMLEl, 'max-height', 'none');
38
38
  this.renderer.setStyle(this.inappHTMLEl, 'display', 'block');
39
39
  this.renderer.setStyle(this.inappHTMLEl, 'margin', '0 auto');
40
40
  this.processCommonBlocks();
@@ -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,9 +76,15 @@ 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();
83
+ // Backward compatibility
84
+ if (!this.ian.gvt) {
85
+ this.ian.gvt = this.ian.cont.getOrigin();
86
+ }
87
+ Object.assign(containerHTMLElement.style, this.ian.getStyles());
78
88
  (_b = this.ian.elems) === null || _b === void 0 ? void 0 : _b.forEach(function (element) {
79
89
  _this.renderElement(containerHTMLElement, element);
80
90
  });
@@ -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
- }