@everymatrix/gamification-dropdown 1.40.0

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.
Files changed (80) hide show
  1. package/dist/cjs/gamification-dropdown.cjs.js +19 -0
  2. package/dist/cjs/gamification-dropdown_4.cjs.entry.js +751 -0
  3. package/dist/cjs/index-afa95f63.js +1704 -0
  4. package/dist/cjs/index.cjs.js +2 -0
  5. package/dist/cjs/loader.cjs.js +21 -0
  6. package/dist/cjs/player-elevate-card-items-37501652.js +2376 -0
  7. package/dist/cjs/player-elevate-card.cjs.entry.js +85 -0
  8. package/dist/cjs/player-elevate-pointcard.cjs.entry.js +92 -0
  9. package/dist/collection/collection-manifest.json +28 -0
  10. package/dist/collection/components/gamification-dropdown/gamification-dropdown.css +47 -0
  11. package/dist/collection/components/gamification-dropdown/gamification-dropdown.js +259 -0
  12. package/dist/collection/index.js +1 -0
  13. package/dist/collection/utils/locale.utils.js +48 -0
  14. package/dist/collection/utils/utils.js +3 -0
  15. package/dist/components/gamification-dropdown.d.ts +11 -0
  16. package/dist/components/gamification-dropdown.js +229 -0
  17. package/dist/components/general-styling-wrapper.js +6 -0
  18. package/dist/components/general-styling-wrapper2.js +103 -0
  19. package/dist/components/index.d.ts +26 -0
  20. package/dist/components/index.js +1 -0
  21. package/dist/components/player-elevate-card-data.js +6 -0
  22. package/dist/components/player-elevate-card-data2.js +632 -0
  23. package/dist/components/player-elevate-card-items.js +2149 -0
  24. package/dist/components/player-elevate-card.js +126 -0
  25. package/dist/components/player-elevate-loyaltycard.js +6 -0
  26. package/dist/components/player-elevate-loyaltycard2.js +129 -0
  27. package/dist/components/player-elevate-pointcard.js +135 -0
  28. package/dist/esm/gamification-dropdown.js +17 -0
  29. package/dist/esm/gamification-dropdown_4.entry.js +744 -0
  30. package/dist/esm/index-76ec399c.js +1675 -0
  31. package/dist/esm/index.js +1 -0
  32. package/dist/esm/loader.js +17 -0
  33. package/dist/esm/player-elevate-card-items-5d6e44ca.js +2363 -0
  34. package/dist/esm/player-elevate-card.entry.js +81 -0
  35. package/dist/esm/player-elevate-pointcard.entry.js +88 -0
  36. package/dist/esm/polyfills/core-js.js +11 -0
  37. package/dist/esm/polyfills/css-shim.js +1 -0
  38. package/dist/esm/polyfills/dom.js +79 -0
  39. package/dist/esm/polyfills/es5-html-element.js +1 -0
  40. package/dist/esm/polyfills/index.js +34 -0
  41. package/dist/esm/polyfills/system.js +6 -0
  42. package/dist/gamification-dropdown/gamification-dropdown.esm.js +1 -0
  43. package/dist/gamification-dropdown/index.esm.js +0 -0
  44. package/dist/gamification-dropdown/p-2d5bddc0.js +1 -0
  45. package/dist/gamification-dropdown/p-4eba8e43.entry.js +1 -0
  46. package/dist/gamification-dropdown/p-5e3064ce.js +1 -0
  47. package/dist/gamification-dropdown/p-62327671.entry.js +1 -0
  48. package/dist/gamification-dropdown/p-bbd6d5a3.entry.js +1 -0
  49. package/dist/index.cjs.js +1 -0
  50. package/dist/index.js +1 -0
  51. package/dist/static/button-default.svg +42 -0
  52. package/dist/static/button-disabled.svg +4 -0
  53. package/dist/static/button-hover.svg +4 -0
  54. package/dist/static/button-level.svg +27 -0
  55. package/dist/static/button-pressed.svg +18 -0
  56. package/dist/static/button-redeem.svg +36 -0
  57. package/dist/static/card-ground-over.png +0 -0
  58. package/dist/static/card-ground-over.svg +903 -0
  59. package/dist/static/card-ground.png +0 -0
  60. package/dist/static/card-ground.svg +34 -0
  61. package/dist/static/info.svg +4 -0
  62. package/dist/static/level-badge.png +0 -0
  63. package/dist/static/level-percent.svg +80 -0
  64. package/dist/static/tips-info.svg +21 -0
  65. package/dist/static/user.svg +3 -0
  66. package/dist/stencil.config.js +22 -0
  67. package/dist/types/Users/sebastian.strulea/Documents/work/widgets-stencil/packages/gamification-dropdown/.stencil/packages/gamification-dropdown/stencil.config.d.ts +2 -0
  68. package/dist/types/components/gamification-dropdown/gamification-dropdown.d.ts +41 -0
  69. package/dist/types/components.d.ts +85 -0
  70. package/dist/types/index.d.ts +1 -0
  71. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  72. package/dist/types/utils/locale.utils.d.ts +2 -0
  73. package/dist/types/utils/utils.d.ts +1 -0
  74. package/loader/cdn.js +3 -0
  75. package/loader/index.cjs.js +3 -0
  76. package/loader/index.d.ts +12 -0
  77. package/loader/index.es2017.js +3 -0
  78. package/loader/index.js +4 -0
  79. package/loader/package.json +10 -0
  80. package/package.json +22 -0
@@ -0,0 +1,751 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-afa95f63.js');
6
+ const playerElevateCardItems = require('./player-elevate-card-items-37501652.js');
7
+
8
+ const DEFAULT_LANGUAGE = 'en';
9
+ const SUPPORTED_LANGUAGES = ['de', 'en', 'hr'];
10
+ let TRANSLATIONS = {
11
+ en: {
12
+ gamificationNoPoints: "No points"
13
+ },
14
+ de: {
15
+ gamificationNoPoints: "No points"
16
+ },
17
+ ro: {
18
+ gamificationNoPoints: "No points"
19
+ },
20
+ fr: {
21
+ gamificationNoPoints: "No points"
22
+ },
23
+ ar: {
24
+ gamificationNoPoints: "No points"
25
+ },
26
+ hr: {
27
+ gamificationNoPoints: "No points"
28
+ }
29
+ };
30
+ const getTranslations = (url) => {
31
+ // fetch url, get the data, replace the TRANSLATIONS content
32
+ return new Promise((resolve) => {
33
+ fetch(url)
34
+ .then((res) => res.json())
35
+ .then((data) => {
36
+ Object.keys(data).forEach((item) => {
37
+ for (let key in data[item]) {
38
+ TRANSLATIONS[item][key] = data[item][key];
39
+ }
40
+ });
41
+ resolve(true);
42
+ });
43
+ });
44
+ };
45
+ const translate = (key, customLang, values) => {
46
+ const lang = customLang;
47
+ let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
48
+ if (values !== undefined) {
49
+ for (const [key, value] of Object.entries(values.values)) {
50
+ const regex = new RegExp(`{${key}}`, 'g');
51
+ translation = translation.replace(regex, value);
52
+ }
53
+ }
54
+ return translation;
55
+ };
56
+
57
+ const gamificationDropdownCss = ":host{display:block}.GamificationDropdownContainer{position:relative}.GamificationDropdownContainer .GamificationDropdown{position:absolute;left:0;z-index:999;overflow:hidden}.GamificationDropdownButton{cursor:pointer;font-size:14px;height:20px;background-color:unset;color:var(--emw--color-typography, #FFFFFF);padding:0;border:none;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;display:flex;align-items:center;justify-content:center;line-height:0}.GamificationDropdownButton:hover{color:var(--emw--color-primary, #52d004)}.GamificationDropdownButton:hover svg{fill:var(--emw--color-primary, #52d004)}.GamificationDropdownButton.IsOpen{color:var(--emw--color-primary, #52d004)}.GamificationDropdownButton.IsOpen svg{fill:var(--emw--color-primary, #52d004)}.GamificationDropdownButton svg{fill:var(--emw--color-typography, #FFFFFF);margin-left:8px;width:16px}";
58
+
59
+ const GamificationDropdown = class {
60
+ constructor(hostRef) {
61
+ index.registerInstance(this, hostRef);
62
+ /**
63
+ * Language of the widget
64
+ */
65
+ this.language = 'en';
66
+ /**
67
+ * Session of the user
68
+ */
69
+ this.session = '';
70
+ /**
71
+ * Client custom styling via string
72
+ */
73
+ this.clientStyling = '';
74
+ /**
75
+ * Client custom styling via url
76
+ */
77
+ this.clientStylingUrl = '';
78
+ /**
79
+ * Translations via URL
80
+ */
81
+ this.translationUrl = '';
82
+ this.isLoading = false;
83
+ this.stylingAppends = false;
84
+ this.setClientStyling = () => {
85
+ let sheet = document.createElement('style');
86
+ sheet.innerHTML = this.clientStyling;
87
+ this.stylingContainer.prepend(sheet);
88
+ };
89
+ this.setClientStylingURL = () => {
90
+ let url = new URL(this.clientStylingUrl);
91
+ let cssFile = document.createElement('style');
92
+ fetch(url.href)
93
+ .then((res) => res.text())
94
+ .then((data) => {
95
+ cssFile.innerHTML = data;
96
+ setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
97
+ })
98
+ .catch((err) => {
99
+ console.log('error ', err);
100
+ });
101
+ };
102
+ this.handleOutsideClick = (event) => {
103
+ const dropdownElement = document.querySelector('gamification-dropdown');
104
+ if (dropdownElement && !dropdownElement.contains(event.target)) {
105
+ this.isOpen = false;
106
+ document.removeEventListener('click', this.handleOutsideClick);
107
+ }
108
+ };
109
+ this.handleDropdownClick = () => {
110
+ this.isOpen = !this.isOpen;
111
+ if (this.isOpen) {
112
+ document.addEventListener('click', this.handleOutsideClick);
113
+ }
114
+ else {
115
+ document.removeEventListener('click', this.handleOutsideClick);
116
+ }
117
+ };
118
+ }
119
+ handleNewTranslations() {
120
+ this.isLoading = true;
121
+ getTranslations(this.translationUrl).then(() => {
122
+ this.isLoading = false;
123
+ });
124
+ }
125
+ async componentWillLoad() {
126
+ if (this.translationUrl.length > 2) {
127
+ await getTranslations(this.translationUrl);
128
+ }
129
+ if (this.endpoint && this.language) {
130
+ return this.fetchPointsData();
131
+ }
132
+ }
133
+ componentDidRender() {
134
+ // start custom styling area
135
+ if (!this.stylingAppends && this.stylingContainer) {
136
+ if (this.clientStyling)
137
+ this.setClientStyling();
138
+ if (this.clientStylingUrl)
139
+ this.setClientStylingURL();
140
+ this.stylingAppends = true;
141
+ }
142
+ // end custom styling area
143
+ }
144
+ fetchPointsData() {
145
+ let url = new URL(`${this.endpoint}/v1/elevate/playerInfo`);
146
+ url.searchParams.append('language', this.language);
147
+ const headers = new Headers();
148
+ headers.append('X-SessionId', this.session);
149
+ const options = {
150
+ method: 'GET',
151
+ headers
152
+ };
153
+ return new Promise((resolve, reject) => {
154
+ this.isLoading = true;
155
+ fetch(url.href, options)
156
+ .then((res) => res.json())
157
+ .then((data) => {
158
+ var _a, _b;
159
+ this.loyaltyPoints = (_b = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.level) === null || _b === void 0 ? void 0 : _b.loyaltyPoints;
160
+ resolve(true);
161
+ }).catch((err) => {
162
+ console.error(err);
163
+ reject(err);
164
+ }).finally(() => {
165
+ this.isLoading = false;
166
+ });
167
+ });
168
+ }
169
+ render() {
170
+ if (this.isLoading) {
171
+ return null;
172
+ }
173
+ else {
174
+ return (index.h("div", { class: "GamificationDropdownContainer" }, index.h("button", { class: `GamificationDropdownButton ${this.isOpen ? 'IsOpen' : ''}`, type: "button", onClick: this.handleDropdownClick, title: typeof this.loyaltyPoints === 'number'
175
+ ? String(this.loyaltyPoints)
176
+ : translate('gamificationNoPoints', this.language) }, typeof this.loyaltyPoints === 'number'
177
+ ? `${Math.floor(this.loyaltyPoints)} XP`
178
+ : '...', index.h("span", null, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "14", height: "6.835", viewBox: "0 0 14 6.835" }, index.h("path", { id: "arrow", d: "M281.541,447.921a.488.488,0,0,0,.295-.122l6.5-5.851a.488.488,0,1,0-.65-.726l-6.176,5.556-6.176-5.556h0a.488.488,0,1,0-.65.726l6.5,5.851a.488.488,0,0,0,.355.122Z", transform: "translate(-274.511 -441.088)" })))), this.isOpen && (index.h("div", { class: "GamificationDropdown" }, index.h("player-elevate-loyaltycard", { endpoint: this.endpoint, session: this.session, language: this.language, "client-styling-url": this.clientStylingUrl, "client-styling": this.clientStyling })))));
179
+ }
180
+ }
181
+ static get watchers() { return {
182
+ "translationUrl": ["handleNewTranslations"]
183
+ }; }
184
+ };
185
+ GamificationDropdown.style = gamificationDropdownCss;
186
+
187
+ const mergeTranslations = (url, target) => {
188
+ return new Promise((resolve) => {
189
+ fetch(url)
190
+ .then((res) => res.json())
191
+ .then((data) => {
192
+ Object.keys(data).forEach((item) => {
193
+ target[item] = target[item] ? target[item] : {};
194
+ for (let key in data[item]) {
195
+ target[item][key] = data[item][key];
196
+ }
197
+ });
198
+ resolve(true);
199
+ });
200
+ });
201
+ };
202
+
203
+ const generalStylingWrapperCss = ":host{display:block}";
204
+
205
+ const GeneralStylingWrapper = class {
206
+ constructor(hostRef) {
207
+ index.registerInstance(this, hostRef);
208
+ /**
209
+ * Client custom styling via inline styles
210
+ */
211
+ this.clientStyling = '';
212
+ /**
213
+ * Client custom styling via url
214
+ */
215
+ this.clientStylingUrl = '';
216
+ /**
217
+ * Translation via url
218
+ */
219
+ this.translationUrl = '';
220
+ this.stylingAppends = false;
221
+ this.setClientStyling = () => {
222
+ let sheet = document.createElement('style');
223
+ sheet.innerHTML = this.clientStyling;
224
+ this.el.prepend(sheet);
225
+ };
226
+ this.setClientStylingURL = () => {
227
+ let url = new URL(this.clientStylingUrl);
228
+ let cssFile = document.createElement('style');
229
+ fetch(url.href)
230
+ .then((res) => res.text())
231
+ .then((data) => {
232
+ cssFile.innerHTML = data;
233
+ setTimeout(() => {
234
+ this.el.prepend(cssFile);
235
+ }, 1);
236
+ })
237
+ .catch((err) => {
238
+ console.log('error ', err);
239
+ });
240
+ };
241
+ }
242
+ componentDidRender() {
243
+ // start custom styling area
244
+ if (!this.stylingAppends) {
245
+ if (this.clientStyling)
246
+ this.setClientStyling();
247
+ if (this.clientStylingUrl)
248
+ this.setClientStylingURL();
249
+ this.stylingAppends = true;
250
+ }
251
+ // end custom styling area
252
+ }
253
+ async componentWillLoad() {
254
+ const promises = [];
255
+ if (this.translationUrl) {
256
+ const translationPromise = mergeTranslations(this.translationUrl, this.targetTranslations);
257
+ promises.push(translationPromise);
258
+ }
259
+ return await Promise.all(promises);
260
+ }
261
+ render() {
262
+ return (index.h("div", { class: "StyleShell" }, index.h("slot", { name: "mainContent" })));
263
+ }
264
+ get el() { return index.getElement(this); }
265
+ };
266
+ GeneralStylingWrapper.style = generalStylingWrapperCss;
267
+
268
+ /**
269
+ * @name startOfDay
270
+ * @category Day Helpers
271
+ * @summary Return the start of a day for the given date.
272
+ *
273
+ * @description
274
+ * Return the start of a day for the given date.
275
+ * The result will be in the local timezone.
276
+ *
277
+ * @param {Date|Number} date - the original date
278
+ * @returns {Date} the start of a day
279
+ * @throws {TypeError} 1 argument required
280
+ *
281
+ * @example
282
+ * // The start of a day for 2 September 2014 11:55:00:
283
+ * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
284
+ * //=> Tue Sep 02 2014 00:00:00
285
+ */
286
+ function startOfDay(dirtyDate) {
287
+ playerElevateCardItems.requiredArgs(1, arguments);
288
+ var date = playerElevateCardItems.toDate(dirtyDate);
289
+ date.setHours(0, 0, 0, 0);
290
+ return date;
291
+ }
292
+
293
+ var MILLISECONDS_IN_DAY = 86400000;
294
+
295
+ /**
296
+ * @name differenceInCalendarDays
297
+ * @category Day Helpers
298
+ * @summary Get the number of calendar days between the given dates.
299
+ *
300
+ * @description
301
+ * Get the number of calendar days between the given dates. This means that the times are removed
302
+ * from the dates and then the difference in days is calculated.
303
+ *
304
+ * @param {Date|Number} dateLeft - the later date
305
+ * @param {Date|Number} dateRight - the earlier date
306
+ * @returns {Number} the number of calendar days
307
+ * @throws {TypeError} 2 arguments required
308
+ *
309
+ * @example
310
+ * // How many calendar days are between
311
+ * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
312
+ * const result = differenceInCalendarDays(
313
+ * new Date(2012, 6, 2, 0, 0),
314
+ * new Date(2011, 6, 2, 23, 0)
315
+ * )
316
+ * //=> 366
317
+ * // How many calendar days are between
318
+ * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
319
+ * const result = differenceInCalendarDays(
320
+ * new Date(2011, 6, 3, 0, 1),
321
+ * new Date(2011, 6, 2, 23, 59)
322
+ * )
323
+ * //=> 1
324
+ */
325
+ function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {
326
+ playerElevateCardItems.requiredArgs(2, arguments);
327
+ var startOfDayLeft = startOfDay(dirtyDateLeft);
328
+ var startOfDayRight = startOfDay(dirtyDateRight);
329
+ var timestampLeft = startOfDayLeft.getTime() - playerElevateCardItems.getTimezoneOffsetInMilliseconds(startOfDayLeft);
330
+ var timestampRight = startOfDayRight.getTime() - playerElevateCardItems.getTimezoneOffsetInMilliseconds(startOfDayRight);
331
+
332
+ // Round the number of days to the nearest integer
333
+ // because the number of milliseconds in a day is not constant
334
+ // (e.g. it's different in the day of the daylight saving time clock shift)
335
+ return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY);
336
+ }
337
+
338
+ /**
339
+ * Days in 1 week.
340
+ *
341
+ * @name daysInWeek
342
+ * @constant
343
+ * @type {number}
344
+ * @default
345
+ */
346
+
347
+ /**
348
+ * Milliseconds in 1 hour
349
+ *
350
+ * @name millisecondsInHour
351
+ * @constant
352
+ * @type {number}
353
+ * @default
354
+ */
355
+ var millisecondsInHour = 3600000;
356
+
357
+ /**
358
+ * @name differenceInMilliseconds
359
+ * @category Millisecond Helpers
360
+ * @summary Get the number of milliseconds between the given dates.
361
+ *
362
+ * @description
363
+ * Get the number of milliseconds between the given dates.
364
+ *
365
+ * @param {Date|Number} dateLeft - the later date
366
+ * @param {Date|Number} dateRight - the earlier date
367
+ * @returns {Number} the number of milliseconds
368
+ * @throws {TypeError} 2 arguments required
369
+ *
370
+ * @example
371
+ * // How many milliseconds are between
372
+ * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
373
+ * const result = differenceInMilliseconds(
374
+ * new Date(2014, 6, 2, 12, 30, 21, 700),
375
+ * new Date(2014, 6, 2, 12, 30, 20, 600)
376
+ * )
377
+ * //=> 1100
378
+ */
379
+ function differenceInMilliseconds(dateLeft, dateRight) {
380
+ playerElevateCardItems.requiredArgs(2, arguments);
381
+ return playerElevateCardItems.toDate(dateLeft).getTime() - playerElevateCardItems.toDate(dateRight).getTime();
382
+ }
383
+
384
+ var roundingMap = {
385
+ ceil: Math.ceil,
386
+ round: Math.round,
387
+ floor: Math.floor,
388
+ trunc: function trunc(value) {
389
+ return value < 0 ? Math.ceil(value) : Math.floor(value);
390
+ } // Math.trunc is not supported by IE
391
+ };
392
+
393
+ var defaultRoundingMethod = 'trunc';
394
+ function getRoundingMethod(method) {
395
+ return method ? roundingMap[method] : roundingMap[defaultRoundingMethod];
396
+ }
397
+
398
+ /**
399
+ * @name differenceInHours
400
+ * @category Hour Helpers
401
+ * @summary Get the number of hours between the given dates.
402
+ *
403
+ * @description
404
+ * Get the number of hours between the given dates.
405
+ *
406
+ * @param {Date|Number} dateLeft - the later date
407
+ * @param {Date|Number} dateRight - the earlier date
408
+ * @param {Object} [options] - an object with options.
409
+ * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
410
+ * @returns {Number} the number of hours
411
+ * @throws {TypeError} 2 arguments required
412
+ *
413
+ * @example
414
+ * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
415
+ * const result = differenceInHours(
416
+ * new Date(2014, 6, 2, 19, 0),
417
+ * new Date(2014, 6, 2, 6, 50)
418
+ * )
419
+ * //=> 12
420
+ */
421
+ function differenceInHours(dateLeft, dateRight, options) {
422
+ playerElevateCardItems.requiredArgs(2, arguments);
423
+ var diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInHour;
424
+ return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
425
+ }
426
+
427
+ /**
428
+ * @name isBefore
429
+ * @category Common Helpers
430
+ * @summary Is the first date before the second one?
431
+ *
432
+ * @description
433
+ * Is the first date before the second one?
434
+ *
435
+ * @param {Date|Number} date - the date that should be before the other one to return true
436
+ * @param {Date|Number} dateToCompare - the date to compare with
437
+ * @returns {Boolean} the first date is before the second date
438
+ * @throws {TypeError} 2 arguments required
439
+ *
440
+ * @example
441
+ * // Is 10 July 1989 before 11 February 1987?
442
+ * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
443
+ * //=> false
444
+ */
445
+ function isBefore(dirtyDate, dirtyDateToCompare) {
446
+ playerElevateCardItems.requiredArgs(2, arguments);
447
+ var date = playerElevateCardItems.toDate(dirtyDate);
448
+ var dateToCompare = playerElevateCardItems.toDate(dirtyDateToCompare);
449
+ return date.getTime() < dateToCompare.getTime();
450
+ }
451
+
452
+ function updateProgressSvg(progressElementRef, percent) {
453
+ const svgElement = progressElementRef.querySelector('#total_level');
454
+ const endLockWidth = 17, pointR = 6.5;
455
+ //Total Widget of the progress
456
+ const barWidth = svgElement.getBBox().width;
457
+ //The filled width according to current progress
458
+ const levelPercent = percent > 1 ? 1 : percent;
459
+ const widthOnBar = (levelPercent * barWidth - endLockWidth) < 0 ? 0 : levelPercent * barWidth - endLockWidth;
460
+ //update bar's width, widthOnBar
461
+ const levelBar = progressElementRef.querySelector('#current_level');
462
+ //update filters, x = widthOnBar
463
+ const levelFilter = progressElementRef.querySelector('#filter_current_level');
464
+ //update circle, widthOnBar+10
465
+ const levelCircle = progressElementRef.querySelector('#circle_current_level');
466
+ svgElement.setAttribute('viewbox', `0 0 ${widthOnBar} 28`);
467
+ levelBar.setAttribute('width', `${widthOnBar}`);
468
+ levelCircle.setAttribute('cx', `${(widthOnBar < pointR ? pointR : widthOnBar)}`);
469
+ levelFilter.setAttribute('x', `${widthOnBar - 8}`);
470
+ //update lock location
471
+ const endLockElement = progressElementRef.querySelector('#lock');
472
+ // wrapper of endLock, include ball and heatfilter1_d_305_23
473
+ const filter1 = progressElementRef.querySelector('#filter_heart_ball');
474
+ // ball in endlockfilter2_i_305_23
475
+ const filter2 = progressElementRef.querySelector('#filter_ball');
476
+ // heart in endlockfilter3_d_305_23
477
+ const filter3 = progressElementRef.querySelector('#filter_heart');
478
+ //wrapper of lockfilter4_d_305_23
479
+ const filterLock = progressElementRef.querySelector('#filter_lock');
480
+ // shadow of ball paint0_linear_305_23
481
+ const paint0 = progressElementRef.querySelector('#paint0_linear_ball');
482
+ //paint in lockpaint1_linear_305_23
483
+ const paint1 = progressElementRef.querySelector('#paint1_linear_lock');
484
+ // box of lock and heart, for move position dynamically
485
+ const lockBox = progressElementRef.querySelector('#lock_box');
486
+ const heartBox = progressElementRef.querySelector('#heart_box');
487
+ const rightPaddingOfLockWidth = 10, cxOfEndLockEle = barWidth - rightPaddingOfLockWidth;
488
+ //set cx of lockElement
489
+ endLockElement.setAttribute('cx', `${cxOfEndLockEle}`);
490
+ //set cx of sub Elements
491
+ paint1.setAttribute('x1', `${cxOfEndLockEle}`);
492
+ paint1.setAttribute('x2', `${cxOfEndLockEle}`);
493
+ paint0.setAttribute('x1', `${cxOfEndLockEle - 6}`);
494
+ paint0.setAttribute('x2', `${cxOfEndLockEle - 6 + 11.2}`);
495
+ filterLock.setAttribute('x', `${cxOfEndLockEle - 6}`);
496
+ filter3.setAttribute('x', `${cxOfEndLockEle - 6 - 2}`);
497
+ filter2.setAttribute('x', `${cxOfEndLockEle - 6 - 2 - 2}`);
498
+ filter1.setAttribute('x', `${cxOfEndLockEle - 6 - 2 - 2 - 4}`);
499
+ lockBox.setAttribute('x', `${cxOfEndLockEle - 6}`);
500
+ heartBox.setAttribute('x', `${cxOfEndLockEle - 6}`);
501
+ svgElement.parentElement.style.opacity = '1';
502
+ }
503
+
504
+ const playerElevateCardDataCss = ":host {\n display: block;\n width: 360px;\n height: 230px;\n}\n\n.ElevateCardWrapper {\n contain: layout inline-size;\n width: 100%;\n height: fit-content;\n min-height: 218px;\n}\n\n.Outer {\n container-type: inline-size;\n font-size: 12px;\n background-size: cover;\n background-repeat: no-repeat;\n line-height: initial;\n width: 100%;\n height: 100%;\n}\n\n.Dark {\n color: var(--emfe-w-color-gray150, #efefef);\n}\n\n.Light {\n color: var(--emfe-w-color-black, #0e0e0e);\n}\n\n@container (min-width: 381px) {\n .Outer {\n background-size: cover;\n }\n .Outer .OuterCover {\n min-height: 190px;\n }\n}\n@container (min-width: 260px) {\n .Outer {\n background-size: contain;\n }\n}\n.OuterCover {\n width: 100%;\n height: 100%;\n content: \"\";\n background-repeat: no-repeat;\n background-size: cover;\n border-radius: 15px;\n}\n\n.Inner {\n display: flex;\n flex-direction: column;\n min-height: 158px;\n}\n.Inner .Content {\n padding: 15px;\n flex-wrap: wrap;\n gap: 8px;\n}\n.Inner .Row {\n display: flex;\n flex-direction: row;\n}\n.Inner .CardCell {\n display: flex;\n}\n.Inner .LevelProgress svg {\n transition: opacity 0.4s;\n}\n.Inner .LevelInfo {\n display: flex;\n flex-direction: column;\n}\n.Inner .LevelInfo .ElevateLevel .LevelName {\n height: 28px;\n border-radius: 5px;\n line-height: 28px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.Inner .LevelInfo.Level0 .ElevateLevel .LevelName {\n box-shadow: -2px -2px 7px 0px var(--emfe-w-elevate-color-level0button-shadow, rgba(191, 84, 6, 0.75));\n background: linear-gradient(180deg, var(--emfe-w-elevate-color-level0-bg0, #E2792C) 0%, var(--emfe-w-elevate-color-level0-bg1, rgba(242, 151, 99, 0)) 100%);\n}\n.Inner .LevelInfo.Level1 .ElevateLevel .LevelName {\n box-shadow: -2px -2px 7px 0px var(--emfe-w-elevate-color-level1button-shadow, rgba(151, 151, 151, 0.75));\n background: linear-gradient(180deg, var(--emfe-w-elevate-color-level1-bg0, #BEBFED) 0%, var(--emfe-w-elevate-color-level1-bg1, rgba(216, 217, 233, 0)) 100%);\n}\n.Inner .LevelInfo.Level2 .ElevateLevel .LevelName {\n box-shadow: -2px -2px 7px 0px var(--emfe-w-elevate-color-level2button-shadow, rgba(191, 120, 6, 0.75));\n background: linear-gradient(180deg, var(--emfe-w-elevate-color-level2-bg0, #FCC410) 0%, var(--emfe-w-elevate-color-level2-bg1, rgba(255, 189, 43, 0)) 100%);\n}\n.Inner .LevelInfo.Level3 .ElevateLevel .LevelName {\n box-shadow: -2px -2px 7px 0px var(--emfe-w-elevate-color-level3button-shadow, rgba(65, 6, 191, 0.75));\n background: linear-gradient(180deg, var(--emfe-w-elevate-color-level3-bg0, #B1A2DB) 0%, var(--emfe-w-elevate-color-level3-bg1, rgba(203, 202, 245, 0)) 100%);\n}\n.Inner .LevelInfo.Level4 .ElevateLevel .LevelName {\n box-shadow: -2px -2px 7px 0px var(--emfe-w-elevate-color-level4button-shadow, rgba(65, 6, 191, 0.75));\n background: linear-gradient(180deg, var(--emfe-w-elevate-color-level4-bg0, #B1A2DB) 0%, var(--emfe-w-elevate-color-level4-bg1, rgba(203, 202, 245, 0)) 100%);\n}\n.Inner .LevelInfo .ElevateLevel {\n display: flex;\n}\n.Inner .LevelInfo {\n flex: 1;\n flex-grow: 1;\n min-width: 150px;\n}\n.Inner .PlayerImg {\n width: 29%;\n margin: auto;\n max-width: 100px;\n min-width: 30px;\n order: 0;\n}\n.Inner .PlayerAvatar {\n max-width: 100px;\n flex-basis: 100px;\n height: auto;\n margin: auto;\n padding-top: 10px;\n}\n.Inner .PlayerAvatar .Avatar, .Inner .PlayerAvatar .Badge {\n width: 100%;\n height: 100%;\n}\n.Inner .PlayerAvatar .Avatar {\n border-radius: 50%;\n background-size: contain;\n background-repeat: no-repeat;\n}\n.Inner .ElevateLevel .ExpirationDate {\n max-width: 138px;\n min-width: 118px;\n}\n.Inner .PlayerName, .Inner .RedeemButton, .Inner .ElevateLevel {\n text-transform: capitalize;\n width: 100%;\n}\n.Inner .PlayerName {\n font-size: 16px;\n}\n.Inner .Row .PointsInfo {\n display: table;\n font-weight: 600;\n}\n.Inner .Row .Redeem {\n justify-content: flex-end;\n margin-left: auto;\n}\n.Inner .Row .Redeem:hover {\n color: var(--emfe-w-elevate-color-redeem-hover, #00ABA4);\n cursor: pointer;\n}\n.Inner .Row .RedeemButton:hover span {\n color: var(emfe-w-elevate-color-redeem-text-hover, #f1f1f1);\n font-weight: bold;\n}\n.Inner .Row .RedeemButton {\n width: 95px;\n height: 35px;\n display: flex;\n align-items: center;\n border-radius: 10px;\n background: var(--emfe-w-elevate-color-redeem-bg, linear-gradient(0deg, #26CC37, #26CC37)), linear-gradient(117.99deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 33.89%), linear-gradient(283.85deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 33.47%), linear-gradient(268.18deg, rgba(255, 255, 255, 0.6) -17.36%, rgba(239, 239, 239, 0) 15.78%);\n box-shadow: 0px 4px 4px 0px #00000040;\n}\n.Inner .Row .RedeemButton span {\n color: var(--emfe-w-color-white, #fff);\n line-height: 18px;\n font-size: 15px;\n text-align: center;\n width: 100%;\n}\n.Inner .Row .Points {\n font-size: large;\n vertical-align: middle;\n}\n.Inner .Row .Points .XP {\n font-size: x-small;\n}\n.Inner .Row .ExpirationPoints {\n font-size: small;\n text-align: right;\n font-weight: bold;\n color: var(--emfe-w-color-red, #9e595f);\n}";
505
+
506
+ const PlayerElevateCardData = class {
507
+ constructor(hostRef) {
508
+ index.registerInstance(this, hostRef);
509
+ this.playerElevateLeveLoaded = index.createEvent(this, "playerElevateLeveLoaded", 7);
510
+ }
511
+ handleWindowResizs() {
512
+ this.initLevelProgressbar();
513
+ }
514
+ onParamsChanged() {
515
+ this.loadElevateInfo();
516
+ }
517
+ onRedeemClick() {
518
+ window.postMessage({ type: 'BEERedeemClicked' }, window.location.href);
519
+ }
520
+ loadLevels() {
521
+ let url = new URL(`${this.params.endpoint}/v1/elevate/levels?language=${this.params.language}`);
522
+ return new Promise((resolve, reject) => {
523
+ return fetch(url.href, {
524
+ method: 'GET',
525
+ })
526
+ .then((res) => res.json())
527
+ .then((res) => {
528
+ this.levels = res.data;
529
+ resolve(true);
530
+ })
531
+ .catch((err) => {
532
+ reject(err);
533
+ });
534
+ });
535
+ }
536
+ calcuatePointsToBeExpired(walletTotalInfo) {
537
+ let pointExpireInfoAsString = '';
538
+ if (!walletTotalInfo || !walletTotalInfo.aboutToExpire ||
539
+ walletTotalInfo.aboutToExpire.length == 0 ||
540
+ walletTotalInfo.aboutToExpire[0].points <= 0) {
541
+ return pointExpireInfoAsString;
542
+ }
543
+ walletTotalInfo.aboutToExpire.sort((expire1, expire2) => {
544
+ return isBefore(new Date(expire1.expireTime), new Date(expire2.expireTime))
545
+ ? -1
546
+ : 1;
547
+ });
548
+ const aboutToExpire = walletTotalInfo.aboutToExpire[0];
549
+ const daysToExpried = differenceInCalendarDays(new Date(aboutToExpire.expireTime), new Date());
550
+ let hoursToExpired = 0, expiredTranslationKey = daysToExpried === 0 ? 'pointsToBeExpiredDay' : 'pointsToBeExpired';
551
+ if (daysToExpried == 0) {
552
+ hoursToExpired = differenceInHours(new Date(aboutToExpire.expireTime), new Date());
553
+ expiredTranslationKey = hoursToExpired > 1 ? 'pointsToBeExpiredHours' : 'pointsToBeExpiredHour';
554
+ }
555
+ pointExpireInfoAsString = playerElevateCardItems.translateWithParams(expiredTranslationKey, {
556
+ expirationPoints: aboutToExpire.points,
557
+ expireDay: daysToExpried,
558
+ });
559
+ return pointExpireInfoAsString;
560
+ }
561
+ loadPlayerLevelInfo() {
562
+ let url = new URL(`${this.params.endpoint}/v1/elevate/playerInfo?language=${this.params.language}`);
563
+ return new Promise((resolve, reject) => {
564
+ return fetch(url.href, {
565
+ method: 'GET',
566
+ headers: {
567
+ 'X-Sessionid': this.params.session,
568
+ 'Content-Type': 'application/json',
569
+ },
570
+ })
571
+ .then((res) => res.json())
572
+ .then((res) => {
573
+ var _a, _b, _c;
574
+ if (!res.success) {
575
+ console.error('Exception when fetch user elevateinfo, ', res.errorCode, res.errorMessage);
576
+ reject(true);
577
+ return;
578
+ }
579
+ let playerElevateInfo = res.data;
580
+ this.playerElevateLevel = playerElevateInfo.level;
581
+ this.playerElevateLevel.name = this.playerElevateLevel.presentation.displayName || this.playerElevateLevel.name;
582
+ this.playerElevateLevel.spendablePoints = ((_a = playerElevateInfo.spendableWallet) === null || _a === void 0 ? void 0 : _a.total.points) || 0;
583
+ this.playerElevateLeveLoaded.emit({ elevateLevel: this.playerElevateLevel });
584
+ const spendableTotal = (_b = res.data.spendableWallet) === null || _b === void 0 ? void 0 : _b.total;
585
+ const loyaltyWalletTotal = (_c = res.data.loyaltyWallet) === null || _c === void 0 ? void 0 : _c.total;
586
+ this.playerElevateLeveLoaded.emit({
587
+ elevateLevelWalletTotal: spendableTotal,
588
+ loyaltyWalletTotal
589
+ });
590
+ let spExpireInfoAsString = this.calcuatePointsToBeExpired(spendableTotal);
591
+ let xpExpireInfoAsString = this.calcuatePointsToBeExpired(loyaltyWalletTotal);
592
+ if (spExpireInfoAsString || xpExpireInfoAsString) {
593
+ this.playerElevateLeveLoaded.emit({
594
+ pointExpireString: spExpireInfoAsString,
595
+ xpExpireString: xpExpireInfoAsString
596
+ });
597
+ }
598
+ resolve(this.playerElevateLevel);
599
+ })
600
+ .catch((err) => {
601
+ console.log('error ', err);
602
+ reject(true);
603
+ });
604
+ });
605
+ }
606
+ setLoyaltyProgress(percent) {
607
+ updateProgressSvg(this.loyaltyProgressEle, percent);
608
+ }
609
+ initLevelProgressbar() {
610
+ setTimeout(() => {
611
+ this.loyaltyProgressEle =
612
+ this.elevateCardRef.parentElement.querySelector('#LevelProgress');
613
+ if (!this.loyaltyProgressEle) {
614
+ return;
615
+ }
616
+ this.setLoyaltyProgress(!this.playerElevateLevel.nextLevel
617
+ ? 1 : (this.playerElevateLevel.loyaltyPoints / this.playerElevateLevel.nextLevel.entryPoints));
618
+ this.params['playerElevateLevel'] = this.playerElevateLevel;
619
+ }, 80);
620
+ }
621
+ componentDidRender() {
622
+ this.initLevelProgressbar();
623
+ }
624
+ loadElevateInfo() {
625
+ if (!this.params.endpoint || !this.params.session) {
626
+ return;
627
+ }
628
+ const promises = [];
629
+ promises.push(this.loadPlayerLevelInfo());
630
+ if (this.params.calculateLevelFlag) {
631
+ promises.push(this.loadLevels());
632
+ }
633
+ Promise.all(promises).then((res) => {
634
+ console.log('elevate-init', res);
635
+ this.initLevelProgressbar();
636
+ if (!this.levels) {
637
+ return;
638
+ }
639
+ this.levels.sort((level1, level2) => {
640
+ return level1.firstEntryPoints > level2.firstEntryPoints ? 1 : -1;
641
+ });
642
+ const playerPoints = this.playerElevateLevel.loyaltyPoints;
643
+ let playerLevelNumber = 0;
644
+ this.levels.forEach((elevateLevel, idx) => {
645
+ if (playerPoints > elevateLevel.firstEntryPoints) {
646
+ playerLevelNumber = idx;
647
+ }
648
+ });
649
+ this.playerElevateLeveLoaded.emit({
650
+ calculatedLevelFlag: playerLevelNumber,
651
+ });
652
+ });
653
+ }
654
+ componentWillLoad() {
655
+ this.loadElevateInfo();
656
+ }
657
+ get elevateCardRef() { return index.getElement(this); }
658
+ static get watchers() { return {
659
+ "params": ["onParamsChanged"]
660
+ }; }
661
+ };
662
+ PlayerElevateCardData.style = playerElevateCardDataCss;
663
+
664
+ const playerElevateLoyaltycardCss = ":host{display:block}@media screen and (min-width: 501px){.LoyaltyCard .Inner .LevelInfo .ElevateLevel{flex-wrap:nowrap}.LoyaltyCard .Inner .LevelInfo .ElevateLevel .ExpirationDate{padding-top:11px;margin-left:5px}}@media screen and (max-width: 500px){.LoyaltyCard .Inner .LevelInfo .ElevateLevel{flex-wrap:wrap}.LoyaltyCard .Inner .LevelInfo .ElevateLevel .ExpirationDate{padding-top:0px;margin-left:0px}}.LoyaltyCard .Inner .LevelProgress{margin-left:0px}.LoyaltyCard .Inner .Row .PointsInfo{width:100%}.LoyaltyCard .Inner .Row .PointsInfo.ExpirationPoints{text-align:left;color:var(--emfe-w-color-red-50, red)}.LoyaltyCard .Inner .PlayerAvatar .Avatar{display:none}.LoyaltyCard .Inner .PlayerAvatar .Badge{border-radius:50%;background-size:contain;width:100%;height:100%}.LoyaltyCard .Inner .LevelInfo .ElevateLevel{display:flex;flex:1;align-items:center}.LoyaltyCard .Inner .LevelInfo .ElevateLevel .ExpirationDate{position:relative;padding-left:5px}.LoyaltyCard .Inner .LevelInfo .ElevateLevel .ExpirationDate .ExpireTime{margin-left:5px}.LoyaltyCard .Inner .LevelInfo .ElevateLevel .LevelName{padding-left:0;font-size:var(--emfe-w-elevate-fontsize-2xlarge, 21px);position:relative;width:auto;color:var(--emfe-w-elevate-color-levelname, #FFBD2B);font-weight:bold}.LoyaltyCard .NextLevelTip{text-align:right;font-size:11px;color:var(--emfe-w-color-black, #000);opacity:0.8;font-weight:bold}";
665
+
666
+ const PlayerElevateLoyaltycard = class {
667
+ constructor(hostRef) {
668
+ index.registerInstance(this, hostRef);
669
+ /**
670
+ * The style that widget shows,available value: Dark, Light
671
+ * Default: Dark
672
+ */
673
+ this.theme = 'Dark';
674
+ /**
675
+ * Widget Language to show
676
+ */
677
+ this.language = 'en';
678
+ /**
679
+ * datePattern
680
+ */
681
+ this.dateFormat = 'yyyy-MM-dd';
682
+ /**
683
+ * Client custom styling via inline styles
684
+ */
685
+ this.clientStyling = '';
686
+ /**
687
+ * Client custom styling via url
688
+ */
689
+ this.clientStylingUrl = '';
690
+ /**
691
+ * Translation via url
692
+ */
693
+ this.translationUrl = '';
694
+ }
695
+ onSessionOrEndpointChange() {
696
+ this.paramProxy = Object.assign(Object.assign({}, this.paramProxy), { session: this.session, endpoint: this.endpoint, language: this.language });
697
+ }
698
+ playerElevateLeveLoadedHandler(event) {
699
+ if (!event.detail) {
700
+ return;
701
+ }
702
+ if (event.detail['elevateLevelWalletTotal']) {
703
+ this.elevateWalletTotal = event.detail['elevateLevelWalletTotal'];
704
+ }
705
+ if (event.detail['elevateLevel']) {
706
+ this.playerElevateLevel = event.detail['elevateLevel'];
707
+ }
708
+ if (event.detail['pointExpireString']) {
709
+ this.pointExpireString = event.detail.xpExpireString;
710
+ }
711
+ }
712
+ onRedeemClick() {
713
+ window.postMessage({ type: 'BEERedeemClicked' }, window.location.href);
714
+ }
715
+ componentWillLoad() {
716
+ this.paramProxy = {
717
+ endpoint: this.endpoint,
718
+ session: this.session,
719
+ language: this.language,
720
+ };
721
+ }
722
+ getNextLevelTips() {
723
+ var _a;
724
+ //need xx to reach Diamond
725
+ let nextLevel = (_a = this.playerElevateLevel) === null || _a === void 0 ? void 0 : _a.nextLevel;
726
+ if (this.playerElevateLevel && nextLevel) {
727
+ const pointsToReach = (nextLevel.entryPoints - this.playerElevateLevel.loyaltyPoints).toFixed(2);
728
+ return playerElevateCardItems.translateWithParams('tipsForNextLevel', {
729
+ pointsToReach,
730
+ levelName: nextLevel.name,
731
+ });
732
+ }
733
+ return '';
734
+ }
735
+ render() {
736
+ const backgroundOuterImagePath = index.getAssetPath('../static/card-ground.svg');
737
+ const backgroundInnerImagePath = index.getAssetPath('../static/card-ground-over.svg');
738
+ return (index.h("div", { class: `ElevateCardWrapper ${this.theme}` }, index.h("div", { class: "LoyaltyCard Outer", style: { 'backgroundImage': `url(${backgroundOuterImagePath}` } }, index.h("general-styling-wrapper", { clientStyling: this.clientStyling, clientStylingUrl: this.clientStylingUrl, targetTranslations: playerElevateCardItems.TRANSLATIONS, translationUrl: this.translationUrl }), index.h("player-elevate-card-data", { params: this.paramProxy }), index.h("div", { class: 'OuterCover Inner', style: { 'backgroundImage': `url(${backgroundInnerImagePath}` } }, index.h("div", { class: 'Content Row' }, this.playerElevateLevel && (index.h(index.Fragment, null, index.h("div", { class: "PlayerImg" }, index.h(playerElevateCardItems.PlayerAvatar, { onlyBadge: true, loyaltyIconUrl: this.playerElevateLevel.presentation.asset })), index.h("div", { class: `LevelInfo ${this.playerElevateLevel.name}` }, index.h(playerElevateCardItems.PlayerElevateLoyaltyLevel, { hideInfo: true, level: this.playerElevateLevel.name, expireTime: this.playerElevateLevel.expireTime, dateFormat: this.dateFormat }), index.h(playerElevateCardItems.PlayerPoints, { loyaltyPoints: this.playerElevateLevel.loyaltyPoints, language: this.language }), this.pointExpireString && (index.h("div", { class: 'PointsInfo ExpirationPoints' }, this.pointExpireString, " ")), index.h(playerElevateCardItems.PlayerLoyaltyProcess, null), index.h("div", { class: "NextLevelTip" }, this.getNextLevelTips())))))))));
739
+ }
740
+ static get watchers() { return {
741
+ "session": ["onSessionOrEndpointChange"],
742
+ "endpoint": ["onSessionOrEndpointChange"],
743
+ "language": ["onSessionOrEndpointChange"]
744
+ }; }
745
+ };
746
+ PlayerElevateLoyaltycard.style = playerElevateLoyaltycardCss;
747
+
748
+ exports.gamification_dropdown = GamificationDropdown;
749
+ exports.general_styling_wrapper = GeneralStylingWrapper;
750
+ exports.player_elevate_card_data = PlayerElevateCardData;
751
+ exports.player_elevate_loyaltycard = PlayerElevateLoyaltycard;