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