@everymatrix/casino-engagement-suite-challenges-list 1.35.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.
- package/dist/casino-engagement-suite-challenges-list/casino-engagement-suite-challenges-list.esm.js +1 -0
- package/dist/casino-engagement-suite-challenges-list/index.esm.js +0 -0
- package/dist/casino-engagement-suite-challenges-list/p-7e171791.js +1 -0
- package/dist/casino-engagement-suite-challenges-list/p-eb36cbe7.entry.js +1 -0
- package/dist/cjs/casino-engagement-suite-challenges-list.cjs.entry.js +1147 -0
- package/dist/cjs/casino-engagement-suite-challenges-list.cjs.js +19 -0
- package/dist/cjs/index-79c88755.js +1299 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/loader.cjs.js +21 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/casino-engagement-suite-challenges-list/casino-engagement-suite-challenges-list.css +225 -0
- package/dist/collection/components/casino-engagement-suite-challenges-list/casino-engagement-suite-challenges-list.js +368 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/models/challenge.js +15 -0
- package/dist/collection/utils/locale.utils.js +16 -0
- package/dist/components/casino-engagement-suite-challenges-list.d.ts +11 -0
- package/dist/components/casino-engagement-suite-challenges-list.js +1170 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +1 -0
- package/dist/esm/casino-engagement-suite-challenges-list.entry.js +1143 -0
- package/dist/esm/casino-engagement-suite-challenges-list.js +17 -0
- package/dist/esm/index-70e47fe0.js +1272 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +17 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.js +22 -0
- package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/casino-engagement-suite-challenges-list/.stencil/packages/casino-engagement-suite-challenges-list/stencil.config.d.ts +2 -0
- package/dist/types/components/casino-engagement-suite-challenges-list/casino-engagement-suite-challenges-list.d.ts +60 -0
- package/dist/types/components.d.ts +79 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/challenge.d.ts +57 -0
- package/dist/types/stencil-public-runtime.d.ts +1565 -0
- package/dist/types/utils/locale.utils.d.ts +1 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +12 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +10 -0
- package/package.json +19 -0
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-70e47fe0.js';
|
|
2
|
+
import '@everymatrix/casino-engagement-suite-progress-bar';
|
|
3
|
+
|
|
4
|
+
var ChallengeLevelProgressStatus;
|
|
5
|
+
(function (ChallengeLevelProgressStatus) {
|
|
6
|
+
ChallengeLevelProgressStatus[ChallengeLevelProgressStatus["Closed"] = 0] = "Closed";
|
|
7
|
+
ChallengeLevelProgressStatus[ChallengeLevelProgressStatus["InProgress"] = 1] = "InProgress";
|
|
8
|
+
ChallengeLevelProgressStatus[ChallengeLevelProgressStatus["Fillup"] = 2] = "Fillup";
|
|
9
|
+
ChallengeLevelProgressStatus[ChallengeLevelProgressStatus["Completed"] = 3] = "Completed";
|
|
10
|
+
})(ChallengeLevelProgressStatus || (ChallengeLevelProgressStatus = {}));
|
|
11
|
+
var ChallengeProgressStatus;
|
|
12
|
+
(function (ChallengeProgressStatus) {
|
|
13
|
+
ChallengeProgressStatus[ChallengeProgressStatus["Started"] = 0] = "Started";
|
|
14
|
+
ChallengeProgressStatus[ChallengeProgressStatus["InProgress"] = 1] = "InProgress";
|
|
15
|
+
ChallengeProgressStatus[ChallengeProgressStatus["PendingLevelReward"] = 2] = "PendingLevelReward";
|
|
16
|
+
ChallengeProgressStatus[ChallengeProgressStatus["Completed"] = 3] = "Completed";
|
|
17
|
+
ChallengeProgressStatus[ChallengeProgressStatus["Expired"] = 4] = "Expired";
|
|
18
|
+
})(ChallengeProgressStatus || (ChallengeProgressStatus = {}));
|
|
19
|
+
|
|
20
|
+
const DEFAULT_LANGUAGE = 'en';
|
|
21
|
+
const SUPPORTED_LANGUAGES = ['en'];
|
|
22
|
+
const TRANSLATIONS = {
|
|
23
|
+
en: {
|
|
24
|
+
challenges: 'Challenges',
|
|
25
|
+
join: 'Join',
|
|
26
|
+
unjoin: 'Unjoin',
|
|
27
|
+
noChallenges: 'No Challenges yet',
|
|
28
|
+
tryOtherGames: 'Try winning Challenges as rewards or launching other booster games',
|
|
29
|
+
tooltip: 'Competition where your real money bets contribute towards the level progress to achieve the level reward'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const translate = (key, customLang) => {
|
|
33
|
+
const lang = customLang;
|
|
34
|
+
return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function _typeof(o) {
|
|
38
|
+
"@babel/helpers - typeof";
|
|
39
|
+
|
|
40
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
41
|
+
return typeof o;
|
|
42
|
+
} : function (o) {
|
|
43
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
44
|
+
}, _typeof(o);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function requiredArgs(required, args) {
|
|
48
|
+
if (args.length < required) {
|
|
49
|
+
throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @name toDate
|
|
55
|
+
* @category Common Helpers
|
|
56
|
+
* @summary Convert the given argument to an instance of Date.
|
|
57
|
+
*
|
|
58
|
+
* @description
|
|
59
|
+
* Convert the given argument to an instance of Date.
|
|
60
|
+
*
|
|
61
|
+
* If the argument is an instance of Date, the function returns its clone.
|
|
62
|
+
*
|
|
63
|
+
* If the argument is a number, it is treated as a timestamp.
|
|
64
|
+
*
|
|
65
|
+
* If the argument is none of the above, the function returns Invalid Date.
|
|
66
|
+
*
|
|
67
|
+
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
|
|
68
|
+
*
|
|
69
|
+
* @param {Date|Number} argument - the value to convert
|
|
70
|
+
* @returns {Date} the parsed date in the local time zone
|
|
71
|
+
* @throws {TypeError} 1 argument required
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Clone the date:
|
|
75
|
+
* const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
|
|
76
|
+
* //=> Tue Feb 11 2014 11:30:30
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Convert the timestamp to date:
|
|
80
|
+
* const result = toDate(1392098430000)
|
|
81
|
+
* //=> Tue Feb 11 2014 11:30:30
|
|
82
|
+
*/
|
|
83
|
+
function toDate(argument) {
|
|
84
|
+
requiredArgs(1, arguments);
|
|
85
|
+
var argStr = Object.prototype.toString.call(argument);
|
|
86
|
+
|
|
87
|
+
// Clone the date
|
|
88
|
+
if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {
|
|
89
|
+
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
|
|
90
|
+
return new Date(argument.getTime());
|
|
91
|
+
} else if (typeof argument === 'number' || argStr === '[object Number]') {
|
|
92
|
+
return new Date(argument);
|
|
93
|
+
} else {
|
|
94
|
+
if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments");
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.warn(new Error().stack);
|
|
99
|
+
}
|
|
100
|
+
return new Date(NaN);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @name compareAsc
|
|
106
|
+
* @category Common Helpers
|
|
107
|
+
* @summary Compare the two dates and return -1, 0 or 1.
|
|
108
|
+
*
|
|
109
|
+
* @description
|
|
110
|
+
* Compare the two dates and return 1 if the first date is after the second,
|
|
111
|
+
* -1 if the first date is before the second or 0 if dates are equal.
|
|
112
|
+
*
|
|
113
|
+
* @param {Date|Number} dateLeft - the first date to compare
|
|
114
|
+
* @param {Date|Number} dateRight - the second date to compare
|
|
115
|
+
* @returns {Number} the result of the comparison
|
|
116
|
+
* @throws {TypeError} 2 arguments required
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // Compare 11 February 1987 and 10 July 1989:
|
|
120
|
+
* const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
|
|
121
|
+
* //=> -1
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Sort the array of dates:
|
|
125
|
+
* const result = [
|
|
126
|
+
* new Date(1995, 6, 2),
|
|
127
|
+
* new Date(1987, 1, 11),
|
|
128
|
+
* new Date(1989, 6, 10)
|
|
129
|
+
* ].sort(compareAsc)
|
|
130
|
+
* //=> [
|
|
131
|
+
* // Wed Feb 11 1987 00:00:00,
|
|
132
|
+
* // Mon Jul 10 1989 00:00:00,
|
|
133
|
+
* // Sun Jul 02 1995 00:00:00
|
|
134
|
+
* // ]
|
|
135
|
+
*/
|
|
136
|
+
function compareAsc(dirtyDateLeft, dirtyDateRight) {
|
|
137
|
+
requiredArgs(2, arguments);
|
|
138
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
139
|
+
var dateRight = toDate(dirtyDateRight);
|
|
140
|
+
var diff = dateLeft.getTime() - dateRight.getTime();
|
|
141
|
+
if (diff < 0) {
|
|
142
|
+
return -1;
|
|
143
|
+
} else if (diff > 0) {
|
|
144
|
+
return 1;
|
|
145
|
+
// Return 0 if diff is 0; return NaN if diff is NaN
|
|
146
|
+
} else {
|
|
147
|
+
return diff;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function toInteger(dirtyNumber) {
|
|
152
|
+
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
153
|
+
return NaN;
|
|
154
|
+
}
|
|
155
|
+
var number = Number(dirtyNumber);
|
|
156
|
+
if (isNaN(number)) {
|
|
157
|
+
return number;
|
|
158
|
+
}
|
|
159
|
+
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @name addDays
|
|
164
|
+
* @category Day Helpers
|
|
165
|
+
* @summary Add the specified number of days to the given date.
|
|
166
|
+
*
|
|
167
|
+
* @description
|
|
168
|
+
* Add the specified number of days to the given date.
|
|
169
|
+
*
|
|
170
|
+
* @param {Date|Number} date - the date to be changed
|
|
171
|
+
* @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
172
|
+
* @returns {Date} - the new date with the days added
|
|
173
|
+
* @throws {TypeError} - 2 arguments required
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // Add 10 days to 1 September 2014:
|
|
177
|
+
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
178
|
+
* //=> Thu Sep 11 2014 00:00:00
|
|
179
|
+
*/
|
|
180
|
+
function addDays(dirtyDate, dirtyAmount) {
|
|
181
|
+
requiredArgs(2, arguments);
|
|
182
|
+
var date = toDate(dirtyDate);
|
|
183
|
+
var amount = toInteger(dirtyAmount);
|
|
184
|
+
if (isNaN(amount)) {
|
|
185
|
+
return new Date(NaN);
|
|
186
|
+
}
|
|
187
|
+
if (!amount) {
|
|
188
|
+
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
189
|
+
return date;
|
|
190
|
+
}
|
|
191
|
+
date.setDate(date.getDate() + amount);
|
|
192
|
+
return date;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @name addMonths
|
|
197
|
+
* @category Month Helpers
|
|
198
|
+
* @summary Add the specified number of months to the given date.
|
|
199
|
+
*
|
|
200
|
+
* @description
|
|
201
|
+
* Add the specified number of months to the given date.
|
|
202
|
+
*
|
|
203
|
+
* @param {Date|Number} date - the date to be changed
|
|
204
|
+
* @param {Number} amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
205
|
+
* @returns {Date} the new date with the months added
|
|
206
|
+
* @throws {TypeError} 2 arguments required
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* // Add 5 months to 1 September 2014:
|
|
210
|
+
* const result = addMonths(new Date(2014, 8, 1), 5)
|
|
211
|
+
* //=> Sun Feb 01 2015 00:00:00
|
|
212
|
+
*/
|
|
213
|
+
function addMonths(dirtyDate, dirtyAmount) {
|
|
214
|
+
requiredArgs(2, arguments);
|
|
215
|
+
var date = toDate(dirtyDate);
|
|
216
|
+
var amount = toInteger(dirtyAmount);
|
|
217
|
+
if (isNaN(amount)) {
|
|
218
|
+
return new Date(NaN);
|
|
219
|
+
}
|
|
220
|
+
if (!amount) {
|
|
221
|
+
// If 0 months, no-op to avoid changing times in the hour before end of DST
|
|
222
|
+
return date;
|
|
223
|
+
}
|
|
224
|
+
var dayOfMonth = date.getDate();
|
|
225
|
+
|
|
226
|
+
// The JS Date object supports date math by accepting out-of-bounds values for
|
|
227
|
+
// month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and
|
|
228
|
+
// new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we
|
|
229
|
+
// want except that dates will wrap around the end of a month, meaning that
|
|
230
|
+
// new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So
|
|
231
|
+
// we'll default to the end of the desired month by adding 1 to the desired
|
|
232
|
+
// month and using a date of 0 to back up one day to the end of the desired
|
|
233
|
+
// month.
|
|
234
|
+
var endOfDesiredMonth = new Date(date.getTime());
|
|
235
|
+
endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);
|
|
236
|
+
var daysInMonth = endOfDesiredMonth.getDate();
|
|
237
|
+
if (dayOfMonth >= daysInMonth) {
|
|
238
|
+
// If we're already at the end of the month, then this is the correct date
|
|
239
|
+
// and we're done.
|
|
240
|
+
return endOfDesiredMonth;
|
|
241
|
+
} else {
|
|
242
|
+
// Otherwise, we now know that setting the original day-of-month value won't
|
|
243
|
+
// cause an overflow, so set the desired day-of-month. Note that we can't
|
|
244
|
+
// just set the date of `endOfDesiredMonth` because that object may have had
|
|
245
|
+
// its time changed in the unusual case where where a DST transition was on
|
|
246
|
+
// the last day of the month and its local time was in the hour skipped or
|
|
247
|
+
// repeated next to a DST transition. So we use `date` instead which is
|
|
248
|
+
// guaranteed to still have the original time.
|
|
249
|
+
date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
|
|
250
|
+
return date;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @name add
|
|
256
|
+
* @category Common Helpers
|
|
257
|
+
* @summary Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
|
|
258
|
+
*
|
|
259
|
+
* @description
|
|
260
|
+
* Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
|
|
261
|
+
*
|
|
262
|
+
* @param {Date|Number} date - the date to be changed
|
|
263
|
+
* @param {Duration} duration - the object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
264
|
+
*
|
|
265
|
+
* | Key | Description |
|
|
266
|
+
* |----------------|------------------------------------|
|
|
267
|
+
* | years | Amount of years to be added |
|
|
268
|
+
* | months | Amount of months to be added |
|
|
269
|
+
* | weeks | Amount of weeks to be added |
|
|
270
|
+
* | days | Amount of days to be added |
|
|
271
|
+
* | hours | Amount of hours to be added |
|
|
272
|
+
* | minutes | Amount of minutes to be added |
|
|
273
|
+
* | seconds | Amount of seconds to be added |
|
|
274
|
+
*
|
|
275
|
+
* All values default to 0
|
|
276
|
+
*
|
|
277
|
+
* @returns {Date} the new date with the seconds added
|
|
278
|
+
* @throws {TypeError} 2 arguments required
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* // Add the following duration to 1 September 2014, 10:19:50
|
|
282
|
+
* const result = add(new Date(2014, 8, 1, 10, 19, 50), {
|
|
283
|
+
* years: 2,
|
|
284
|
+
* months: 9,
|
|
285
|
+
* weeks: 1,
|
|
286
|
+
* days: 7,
|
|
287
|
+
* hours: 5,
|
|
288
|
+
* minutes: 9,
|
|
289
|
+
* seconds: 30,
|
|
290
|
+
* })
|
|
291
|
+
* //=> Thu Jun 15 2017 15:29:20
|
|
292
|
+
*/
|
|
293
|
+
function add(dirtyDate, duration) {
|
|
294
|
+
requiredArgs(2, arguments);
|
|
295
|
+
if (!duration || _typeof(duration) !== 'object') return new Date(NaN);
|
|
296
|
+
var years = duration.years ? toInteger(duration.years) : 0;
|
|
297
|
+
var months = duration.months ? toInteger(duration.months) : 0;
|
|
298
|
+
var weeks = duration.weeks ? toInteger(duration.weeks) : 0;
|
|
299
|
+
var days = duration.days ? toInteger(duration.days) : 0;
|
|
300
|
+
var hours = duration.hours ? toInteger(duration.hours) : 0;
|
|
301
|
+
var minutes = duration.minutes ? toInteger(duration.minutes) : 0;
|
|
302
|
+
var seconds = duration.seconds ? toInteger(duration.seconds) : 0;
|
|
303
|
+
|
|
304
|
+
// Add years and months
|
|
305
|
+
var date = toDate(dirtyDate);
|
|
306
|
+
var dateWithMonths = months || years ? addMonths(date, months + years * 12) : date;
|
|
307
|
+
|
|
308
|
+
// Add weeks and days
|
|
309
|
+
var dateWithDays = days || weeks ? addDays(dateWithMonths, days + weeks * 7) : dateWithMonths;
|
|
310
|
+
|
|
311
|
+
// Add days, hours, minutes and seconds
|
|
312
|
+
var minutesToAdd = minutes + hours * 60;
|
|
313
|
+
var secondsToAdd = seconds + minutesToAdd * 60;
|
|
314
|
+
var msToAdd = secondsToAdd * 1000;
|
|
315
|
+
var finalDate = new Date(dateWithDays.getTime() + msToAdd);
|
|
316
|
+
return finalDate;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
|
|
321
|
+
* They usually appear for dates that denote time before the timezones were introduced
|
|
322
|
+
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
|
|
323
|
+
* and GMT+01:00:00 after that date)
|
|
324
|
+
*
|
|
325
|
+
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
|
|
326
|
+
* which would lead to incorrect calculations.
|
|
327
|
+
*
|
|
328
|
+
* This function returns the timezone offset in milliseconds that takes seconds in account.
|
|
329
|
+
*/
|
|
330
|
+
function getTimezoneOffsetInMilliseconds(date) {
|
|
331
|
+
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
|
|
332
|
+
utcDate.setUTCFullYear(date.getFullYear());
|
|
333
|
+
return date.getTime() - utcDate.getTime();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @name startOfDay
|
|
338
|
+
* @category Day Helpers
|
|
339
|
+
* @summary Return the start of a day for the given date.
|
|
340
|
+
*
|
|
341
|
+
* @description
|
|
342
|
+
* Return the start of a day for the given date.
|
|
343
|
+
* The result will be in the local timezone.
|
|
344
|
+
*
|
|
345
|
+
* @param {Date|Number} date - the original date
|
|
346
|
+
* @returns {Date} the start of a day
|
|
347
|
+
* @throws {TypeError} 1 argument required
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* // The start of a day for 2 September 2014 11:55:00:
|
|
351
|
+
* const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
|
|
352
|
+
* //=> Tue Sep 02 2014 00:00:00
|
|
353
|
+
*/
|
|
354
|
+
function startOfDay(dirtyDate) {
|
|
355
|
+
requiredArgs(1, arguments);
|
|
356
|
+
var date = toDate(dirtyDate);
|
|
357
|
+
date.setHours(0, 0, 0, 0);
|
|
358
|
+
return date;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
var MILLISECONDS_IN_DAY = 86400000;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* @name differenceInCalendarDays
|
|
365
|
+
* @category Day Helpers
|
|
366
|
+
* @summary Get the number of calendar days between the given dates.
|
|
367
|
+
*
|
|
368
|
+
* @description
|
|
369
|
+
* Get the number of calendar days between the given dates. This means that the times are removed
|
|
370
|
+
* from the dates and then the difference in days is calculated.
|
|
371
|
+
*
|
|
372
|
+
* @param {Date|Number} dateLeft - the later date
|
|
373
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
374
|
+
* @returns {Number} the number of calendar days
|
|
375
|
+
* @throws {TypeError} 2 arguments required
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* // How many calendar days are between
|
|
379
|
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
|
380
|
+
* const result = differenceInCalendarDays(
|
|
381
|
+
* new Date(2012, 6, 2, 0, 0),
|
|
382
|
+
* new Date(2011, 6, 2, 23, 0)
|
|
383
|
+
* )
|
|
384
|
+
* //=> 366
|
|
385
|
+
* // How many calendar days are between
|
|
386
|
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
|
387
|
+
* const result = differenceInCalendarDays(
|
|
388
|
+
* new Date(2011, 6, 3, 0, 1),
|
|
389
|
+
* new Date(2011, 6, 2, 23, 59)
|
|
390
|
+
* )
|
|
391
|
+
* //=> 1
|
|
392
|
+
*/
|
|
393
|
+
function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {
|
|
394
|
+
requiredArgs(2, arguments);
|
|
395
|
+
var startOfDayLeft = startOfDay(dirtyDateLeft);
|
|
396
|
+
var startOfDayRight = startOfDay(dirtyDateRight);
|
|
397
|
+
var timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft);
|
|
398
|
+
var timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(startOfDayRight);
|
|
399
|
+
|
|
400
|
+
// Round the number of days to the nearest integer
|
|
401
|
+
// because the number of milliseconds in a day is not constant
|
|
402
|
+
// (e.g. it's different in the day of the daylight saving time clock shift)
|
|
403
|
+
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// for accurate equality comparisons of UTC timestamps that end up
|
|
407
|
+
// having the same representation in local time, e.g. one hour before
|
|
408
|
+
// DST ends vs. the instant that DST ends.
|
|
409
|
+
function compareLocalAsc(dateLeft, dateRight) {
|
|
410
|
+
var diff = dateLeft.getFullYear() - dateRight.getFullYear() || dateLeft.getMonth() - dateRight.getMonth() || dateLeft.getDate() - dateRight.getDate() || dateLeft.getHours() - dateRight.getHours() || dateLeft.getMinutes() - dateRight.getMinutes() || dateLeft.getSeconds() - dateRight.getSeconds() || dateLeft.getMilliseconds() - dateRight.getMilliseconds();
|
|
411
|
+
if (diff < 0) {
|
|
412
|
+
return -1;
|
|
413
|
+
} else if (diff > 0) {
|
|
414
|
+
return 1;
|
|
415
|
+
// Return 0 if diff is 0; return NaN if diff is NaN
|
|
416
|
+
} else {
|
|
417
|
+
return diff;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @name differenceInDays
|
|
423
|
+
* @category Day Helpers
|
|
424
|
+
* @summary Get the number of full days between the given dates.
|
|
425
|
+
*
|
|
426
|
+
* @description
|
|
427
|
+
* Get the number of full day periods between two dates. Fractional days are
|
|
428
|
+
* truncated towards zero.
|
|
429
|
+
*
|
|
430
|
+
* One "full day" is the distance between a local time in one day to the same
|
|
431
|
+
* local time on the next or previous day. A full day can sometimes be less than
|
|
432
|
+
* or more than 24 hours if a daylight savings change happens between two dates.
|
|
433
|
+
*
|
|
434
|
+
* To ignore DST and only measure exact 24-hour periods, use this instead:
|
|
435
|
+
* `Math.floor(differenceInHours(dateLeft, dateRight)/24)|0`.
|
|
436
|
+
*
|
|
437
|
+
*
|
|
438
|
+
* @param {Date|Number} dateLeft - the later date
|
|
439
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
440
|
+
* @returns {Number} the number of full days according to the local timezone
|
|
441
|
+
* @throws {TypeError} 2 arguments required
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* // How many full days are between
|
|
445
|
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
|
446
|
+
* const result = differenceInDays(
|
|
447
|
+
* new Date(2012, 6, 2, 0, 0),
|
|
448
|
+
* new Date(2011, 6, 2, 23, 0)
|
|
449
|
+
* )
|
|
450
|
+
* //=> 365
|
|
451
|
+
* // How many full days are between
|
|
452
|
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
|
453
|
+
* const result = differenceInDays(
|
|
454
|
+
* new Date(2011, 6, 3, 0, 1),
|
|
455
|
+
* new Date(2011, 6, 2, 23, 59)
|
|
456
|
+
* )
|
|
457
|
+
* //=> 0
|
|
458
|
+
* // How many full days are between
|
|
459
|
+
* // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
|
460
|
+
* // Note: because local time is used, the
|
|
461
|
+
* // result will always be 92 days, even in
|
|
462
|
+
* // time zones where DST starts and the
|
|
463
|
+
* // period has only 92*24-1 hours.
|
|
464
|
+
* const result = differenceInDays(
|
|
465
|
+
* new Date(2020, 5, 1),
|
|
466
|
+
* new Date(2020, 2, 1)
|
|
467
|
+
* )
|
|
468
|
+
//=> 92
|
|
469
|
+
*/
|
|
470
|
+
function differenceInDays(dirtyDateLeft, dirtyDateRight) {
|
|
471
|
+
requiredArgs(2, arguments);
|
|
472
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
473
|
+
var dateRight = toDate(dirtyDateRight);
|
|
474
|
+
var sign = compareLocalAsc(dateLeft, dateRight);
|
|
475
|
+
var difference = Math.abs(differenceInCalendarDays(dateLeft, dateRight));
|
|
476
|
+
dateLeft.setDate(dateLeft.getDate() - sign * difference);
|
|
477
|
+
|
|
478
|
+
// Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full
|
|
479
|
+
// If so, result must be decreased by 1 in absolute value
|
|
480
|
+
var isLastDayNotFull = Number(compareLocalAsc(dateLeft, dateRight) === -sign);
|
|
481
|
+
var result = sign * (difference - isLastDayNotFull);
|
|
482
|
+
// Prevent negative zero
|
|
483
|
+
return result === 0 ? 0 : result;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Days in 1 week.
|
|
488
|
+
*
|
|
489
|
+
* @name daysInWeek
|
|
490
|
+
* @constant
|
|
491
|
+
* @type {number}
|
|
492
|
+
* @default
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Milliseconds in 1 minute
|
|
497
|
+
*
|
|
498
|
+
* @name millisecondsInMinute
|
|
499
|
+
* @constant
|
|
500
|
+
* @type {number}
|
|
501
|
+
* @default
|
|
502
|
+
*/
|
|
503
|
+
var millisecondsInMinute = 60000;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Milliseconds in 1 hour
|
|
507
|
+
*
|
|
508
|
+
* @name millisecondsInHour
|
|
509
|
+
* @constant
|
|
510
|
+
* @type {number}
|
|
511
|
+
* @default
|
|
512
|
+
*/
|
|
513
|
+
var millisecondsInHour = 3600000;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @name differenceInMilliseconds
|
|
517
|
+
* @category Millisecond Helpers
|
|
518
|
+
* @summary Get the number of milliseconds between the given dates.
|
|
519
|
+
*
|
|
520
|
+
* @description
|
|
521
|
+
* Get the number of milliseconds between the given dates.
|
|
522
|
+
*
|
|
523
|
+
* @param {Date|Number} dateLeft - the later date
|
|
524
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
525
|
+
* @returns {Number} the number of milliseconds
|
|
526
|
+
* @throws {TypeError} 2 arguments required
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* // How many milliseconds are between
|
|
530
|
+
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
|
531
|
+
* const result = differenceInMilliseconds(
|
|
532
|
+
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
|
533
|
+
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
|
534
|
+
* )
|
|
535
|
+
* //=> 1100
|
|
536
|
+
*/
|
|
537
|
+
function differenceInMilliseconds(dateLeft, dateRight) {
|
|
538
|
+
requiredArgs(2, arguments);
|
|
539
|
+
return toDate(dateLeft).getTime() - toDate(dateRight).getTime();
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
var roundingMap = {
|
|
543
|
+
ceil: Math.ceil,
|
|
544
|
+
round: Math.round,
|
|
545
|
+
floor: Math.floor,
|
|
546
|
+
trunc: function trunc(value) {
|
|
547
|
+
return value < 0 ? Math.ceil(value) : Math.floor(value);
|
|
548
|
+
} // Math.trunc is not supported by IE
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
var defaultRoundingMethod = 'trunc';
|
|
552
|
+
function getRoundingMethod(method) {
|
|
553
|
+
return method ? roundingMap[method] : roundingMap[defaultRoundingMethod];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* @name differenceInHours
|
|
558
|
+
* @category Hour Helpers
|
|
559
|
+
* @summary Get the number of hours between the given dates.
|
|
560
|
+
*
|
|
561
|
+
* @description
|
|
562
|
+
* Get the number of hours between the given dates.
|
|
563
|
+
*
|
|
564
|
+
* @param {Date|Number} dateLeft - the later date
|
|
565
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
566
|
+
* @param {Object} [options] - an object with options.
|
|
567
|
+
* @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
|
|
568
|
+
* @returns {Number} the number of hours
|
|
569
|
+
* @throws {TypeError} 2 arguments required
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
|
573
|
+
* const result = differenceInHours(
|
|
574
|
+
* new Date(2014, 6, 2, 19, 0),
|
|
575
|
+
* new Date(2014, 6, 2, 6, 50)
|
|
576
|
+
* )
|
|
577
|
+
* //=> 12
|
|
578
|
+
*/
|
|
579
|
+
function differenceInHours(dateLeft, dateRight, options) {
|
|
580
|
+
requiredArgs(2, arguments);
|
|
581
|
+
var diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInHour;
|
|
582
|
+
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* @name differenceInMinutes
|
|
587
|
+
* @category Minute Helpers
|
|
588
|
+
* @summary Get the number of minutes between the given dates.
|
|
589
|
+
*
|
|
590
|
+
* @description
|
|
591
|
+
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
|
592
|
+
*
|
|
593
|
+
* @param {Date|Number} dateLeft - the later date
|
|
594
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
595
|
+
* @param {Object} [options] - an object with options.
|
|
596
|
+
* @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
|
|
597
|
+
* @returns {Number} the number of minutes
|
|
598
|
+
* @throws {TypeError} 2 arguments required
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
|
602
|
+
* const result = differenceInMinutes(
|
|
603
|
+
* new Date(2014, 6, 2, 12, 20, 0),
|
|
604
|
+
* new Date(2014, 6, 2, 12, 7, 59)
|
|
605
|
+
* )
|
|
606
|
+
* //=> 12
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* // How many minutes are between 10:01:59 and 10:00:00
|
|
610
|
+
* const result = differenceInMinutes(
|
|
611
|
+
* new Date(2000, 0, 1, 10, 0, 0),
|
|
612
|
+
* new Date(2000, 0, 1, 10, 1, 59)
|
|
613
|
+
* )
|
|
614
|
+
* //=> -1
|
|
615
|
+
*/
|
|
616
|
+
function differenceInMinutes(dateLeft, dateRight, options) {
|
|
617
|
+
requiredArgs(2, arguments);
|
|
618
|
+
var diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
|
619
|
+
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* @name differenceInCalendarMonths
|
|
624
|
+
* @category Month Helpers
|
|
625
|
+
* @summary Get the number of calendar months between the given dates.
|
|
626
|
+
*
|
|
627
|
+
* @description
|
|
628
|
+
* Get the number of calendar months between the given dates.
|
|
629
|
+
*
|
|
630
|
+
* @param {Date|Number} dateLeft - the later date
|
|
631
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
632
|
+
* @returns {Number} the number of calendar months
|
|
633
|
+
* @throws {TypeError} 2 arguments required
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* // How many calendar months are between 31 January 2014 and 1 September 2014?
|
|
637
|
+
* const result = differenceInCalendarMonths(
|
|
638
|
+
* new Date(2014, 8, 1),
|
|
639
|
+
* new Date(2014, 0, 31)
|
|
640
|
+
* )
|
|
641
|
+
* //=> 8
|
|
642
|
+
*/
|
|
643
|
+
function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) {
|
|
644
|
+
requiredArgs(2, arguments);
|
|
645
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
646
|
+
var dateRight = toDate(dirtyDateRight);
|
|
647
|
+
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
|
648
|
+
var monthDiff = dateLeft.getMonth() - dateRight.getMonth();
|
|
649
|
+
return yearDiff * 12 + monthDiff;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* @name endOfDay
|
|
654
|
+
* @category Day Helpers
|
|
655
|
+
* @summary Return the end of a day for the given date.
|
|
656
|
+
*
|
|
657
|
+
* @description
|
|
658
|
+
* Return the end of a day for the given date.
|
|
659
|
+
* The result will be in the local timezone.
|
|
660
|
+
*
|
|
661
|
+
* @param {Date|Number} date - the original date
|
|
662
|
+
* @returns {Date} the end of a day
|
|
663
|
+
* @throws {TypeError} 1 argument required
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* // The end of a day for 2 September 2014 11:55:00:
|
|
667
|
+
* const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
|
|
668
|
+
* //=> Tue Sep 02 2014 23:59:59.999
|
|
669
|
+
*/
|
|
670
|
+
function endOfDay(dirtyDate) {
|
|
671
|
+
requiredArgs(1, arguments);
|
|
672
|
+
var date = toDate(dirtyDate);
|
|
673
|
+
date.setHours(23, 59, 59, 999);
|
|
674
|
+
return date;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* @name endOfMonth
|
|
679
|
+
* @category Month Helpers
|
|
680
|
+
* @summary Return the end of a month for the given date.
|
|
681
|
+
*
|
|
682
|
+
* @description
|
|
683
|
+
* Return the end of a month for the given date.
|
|
684
|
+
* The result will be in the local timezone.
|
|
685
|
+
*
|
|
686
|
+
* @param {Date|Number} date - the original date
|
|
687
|
+
* @returns {Date} the end of a month
|
|
688
|
+
* @throws {TypeError} 1 argument required
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* // The end of a month for 2 September 2014 11:55:00:
|
|
692
|
+
* const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0))
|
|
693
|
+
* //=> Tue Sep 30 2014 23:59:59.999
|
|
694
|
+
*/
|
|
695
|
+
function endOfMonth(dirtyDate) {
|
|
696
|
+
requiredArgs(1, arguments);
|
|
697
|
+
var date = toDate(dirtyDate);
|
|
698
|
+
var month = date.getMonth();
|
|
699
|
+
date.setFullYear(date.getFullYear(), month + 1, 0);
|
|
700
|
+
date.setHours(23, 59, 59, 999);
|
|
701
|
+
return date;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @name isLastDayOfMonth
|
|
706
|
+
* @category Month Helpers
|
|
707
|
+
* @summary Is the given date the last day of a month?
|
|
708
|
+
*
|
|
709
|
+
* @description
|
|
710
|
+
* Is the given date the last day of a month?
|
|
711
|
+
*
|
|
712
|
+
* @param {Date|Number} date - the date to check
|
|
713
|
+
* @returns {Boolean} the date is the last day of a month
|
|
714
|
+
* @throws {TypeError} 1 argument required
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* // Is 28 February 2014 the last day of a month?
|
|
718
|
+
* const result = isLastDayOfMonth(new Date(2014, 1, 28))
|
|
719
|
+
* //=> true
|
|
720
|
+
*/
|
|
721
|
+
function isLastDayOfMonth(dirtyDate) {
|
|
722
|
+
requiredArgs(1, arguments);
|
|
723
|
+
var date = toDate(dirtyDate);
|
|
724
|
+
return endOfDay(date).getTime() === endOfMonth(date).getTime();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* @name differenceInMonths
|
|
729
|
+
* @category Month Helpers
|
|
730
|
+
* @summary Get the number of full months between the given dates.
|
|
731
|
+
*
|
|
732
|
+
* @description
|
|
733
|
+
* Get the number of full months between the given dates using trunc as a default rounding method.
|
|
734
|
+
*
|
|
735
|
+
* @param {Date|Number} dateLeft - the later date
|
|
736
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
737
|
+
* @returns {Number} the number of full months
|
|
738
|
+
* @throws {TypeError} 2 arguments required
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* // How many full months are between 31 January 2014 and 1 September 2014?
|
|
742
|
+
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
|
743
|
+
* //=> 7
|
|
744
|
+
*/
|
|
745
|
+
function differenceInMonths(dirtyDateLeft, dirtyDateRight) {
|
|
746
|
+
requiredArgs(2, arguments);
|
|
747
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
748
|
+
var dateRight = toDate(dirtyDateRight);
|
|
749
|
+
var sign = compareAsc(dateLeft, dateRight);
|
|
750
|
+
var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight));
|
|
751
|
+
var result;
|
|
752
|
+
|
|
753
|
+
// Check for the difference of less than month
|
|
754
|
+
if (difference < 1) {
|
|
755
|
+
result = 0;
|
|
756
|
+
} else {
|
|
757
|
+
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) {
|
|
758
|
+
// This will check if the date is end of Feb and assign a higher end of month date
|
|
759
|
+
// to compare it with Jan
|
|
760
|
+
dateLeft.setDate(30);
|
|
761
|
+
}
|
|
762
|
+
dateLeft.setMonth(dateLeft.getMonth() - sign * difference);
|
|
763
|
+
|
|
764
|
+
// Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full
|
|
765
|
+
// If so, result must be decreased by 1 in absolute value
|
|
766
|
+
var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign;
|
|
767
|
+
|
|
768
|
+
// Check for cases of one full calendar month
|
|
769
|
+
if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) {
|
|
770
|
+
isLastMonthNotFull = false;
|
|
771
|
+
}
|
|
772
|
+
result = sign * (difference - Number(isLastMonthNotFull));
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Prevent negative zero
|
|
776
|
+
return result === 0 ? 0 : result;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* @name differenceInSeconds
|
|
781
|
+
* @category Second Helpers
|
|
782
|
+
* @summary Get the number of seconds between the given dates.
|
|
783
|
+
*
|
|
784
|
+
* @description
|
|
785
|
+
* Get the number of seconds between the given dates.
|
|
786
|
+
*
|
|
787
|
+
* @param {Date|Number} dateLeft - the later date
|
|
788
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
789
|
+
* @param {Object} [options] - an object with options.
|
|
790
|
+
* @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
|
|
791
|
+
* @returns {Number} the number of seconds
|
|
792
|
+
* @throws {TypeError} 2 arguments required
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* // How many seconds are between
|
|
796
|
+
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
|
797
|
+
* const result = differenceInSeconds(
|
|
798
|
+
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
|
799
|
+
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
|
800
|
+
* )
|
|
801
|
+
* //=> 12
|
|
802
|
+
*/
|
|
803
|
+
function differenceInSeconds(dateLeft, dateRight, options) {
|
|
804
|
+
requiredArgs(2, arguments);
|
|
805
|
+
var diff = differenceInMilliseconds(dateLeft, dateRight) / 1000;
|
|
806
|
+
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* @name differenceInCalendarYears
|
|
811
|
+
* @category Year Helpers
|
|
812
|
+
* @summary Get the number of calendar years between the given dates.
|
|
813
|
+
*
|
|
814
|
+
* @description
|
|
815
|
+
* Get the number of calendar years between the given dates.
|
|
816
|
+
*
|
|
817
|
+
* @param {Date|Number} dateLeft - the later date
|
|
818
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
819
|
+
* @returns {Number} the number of calendar years
|
|
820
|
+
* @throws {TypeError} 2 arguments required
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* // How many calendar years are between 31 December 2013 and 11 February 2015?
|
|
824
|
+
* const result = differenceInCalendarYears(
|
|
825
|
+
* new Date(2015, 1, 11),
|
|
826
|
+
* new Date(2013, 11, 31)
|
|
827
|
+
* )
|
|
828
|
+
* //=> 2
|
|
829
|
+
*/
|
|
830
|
+
function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) {
|
|
831
|
+
requiredArgs(2, arguments);
|
|
832
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
833
|
+
var dateRight = toDate(dirtyDateRight);
|
|
834
|
+
return dateLeft.getFullYear() - dateRight.getFullYear();
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* @name differenceInYears
|
|
839
|
+
* @category Year Helpers
|
|
840
|
+
* @summary Get the number of full years between the given dates.
|
|
841
|
+
*
|
|
842
|
+
* @description
|
|
843
|
+
* Get the number of full years between the given dates.
|
|
844
|
+
*
|
|
845
|
+
* @param {Date|Number} dateLeft - the later date
|
|
846
|
+
* @param {Date|Number} dateRight - the earlier date
|
|
847
|
+
* @returns {Number} the number of full years
|
|
848
|
+
* @throws {TypeError} 2 arguments required
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* // How many full years are between 31 December 2013 and 11 February 2015?
|
|
852
|
+
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
|
853
|
+
* //=> 1
|
|
854
|
+
*/
|
|
855
|
+
function differenceInYears(dirtyDateLeft, dirtyDateRight) {
|
|
856
|
+
requiredArgs(2, arguments);
|
|
857
|
+
var dateLeft = toDate(dirtyDateLeft);
|
|
858
|
+
var dateRight = toDate(dirtyDateRight);
|
|
859
|
+
var sign = compareAsc(dateLeft, dateRight);
|
|
860
|
+
var difference = Math.abs(differenceInCalendarYears(dateLeft, dateRight));
|
|
861
|
+
|
|
862
|
+
// Set both dates to a valid leap year for accurate comparison when dealing
|
|
863
|
+
// with leap days
|
|
864
|
+
dateLeft.setFullYear(1584);
|
|
865
|
+
dateRight.setFullYear(1584);
|
|
866
|
+
|
|
867
|
+
// Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full
|
|
868
|
+
// If so, result must be decreased by 1 in absolute value
|
|
869
|
+
var isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign;
|
|
870
|
+
var result = sign * (difference - Number(isLastYearNotFull));
|
|
871
|
+
// Prevent negative zero
|
|
872
|
+
return result === 0 ? 0 : result;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* @name intervalToDuration
|
|
877
|
+
* @category Common Helpers
|
|
878
|
+
* @summary Convert interval to duration
|
|
879
|
+
*
|
|
880
|
+
* @description
|
|
881
|
+
* Convert a interval object to a duration object.
|
|
882
|
+
*
|
|
883
|
+
* @param {Interval} interval - the interval to convert to duration
|
|
884
|
+
*
|
|
885
|
+
* @returns {Duration} The duration Object
|
|
886
|
+
* @throws {TypeError} Requires 2 arguments
|
|
887
|
+
* @throws {RangeError} `start` must not be Invalid Date
|
|
888
|
+
* @throws {RangeError} `end` must not be Invalid Date
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* // Get the duration between January 15, 1929 and April 4, 1968.
|
|
892
|
+
* intervalToDuration({
|
|
893
|
+
* start: new Date(1929, 0, 15, 12, 0, 0),
|
|
894
|
+
* end: new Date(1968, 3, 4, 19, 5, 0)
|
|
895
|
+
* })
|
|
896
|
+
* // => { years: 39, months: 2, days: 20, hours: 7, minutes: 5, seconds: 0 }
|
|
897
|
+
*/
|
|
898
|
+
function intervalToDuration(interval) {
|
|
899
|
+
requiredArgs(1, arguments);
|
|
900
|
+
var start = toDate(interval.start);
|
|
901
|
+
var end = toDate(interval.end);
|
|
902
|
+
if (isNaN(start.getTime())) throw new RangeError('Start Date is invalid');
|
|
903
|
+
if (isNaN(end.getTime())) throw new RangeError('End Date is invalid');
|
|
904
|
+
var duration = {};
|
|
905
|
+
duration.years = Math.abs(differenceInYears(end, start));
|
|
906
|
+
var sign = compareAsc(end, start);
|
|
907
|
+
var remainingMonths = add(start, {
|
|
908
|
+
years: sign * duration.years
|
|
909
|
+
});
|
|
910
|
+
duration.months = Math.abs(differenceInMonths(end, remainingMonths));
|
|
911
|
+
var remainingDays = add(remainingMonths, {
|
|
912
|
+
months: sign * duration.months
|
|
913
|
+
});
|
|
914
|
+
duration.days = Math.abs(differenceInDays(end, remainingDays));
|
|
915
|
+
var remainingHours = add(remainingDays, {
|
|
916
|
+
days: sign * duration.days
|
|
917
|
+
});
|
|
918
|
+
duration.hours = Math.abs(differenceInHours(end, remainingHours));
|
|
919
|
+
var remainingMinutes = add(remainingHours, {
|
|
920
|
+
hours: sign * duration.hours
|
|
921
|
+
});
|
|
922
|
+
duration.minutes = Math.abs(differenceInMinutes(end, remainingMinutes));
|
|
923
|
+
var remainingSeconds = add(remainingMinutes, {
|
|
924
|
+
minutes: sign * duration.minutes
|
|
925
|
+
});
|
|
926
|
+
duration.seconds = Math.abs(differenceInSeconds(end, remainingSeconds));
|
|
927
|
+
return duration;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const casinoEngagementSuiteChallengesListCss = "@import url(\"https://fonts.googleapis.com/css2?family=Montserrat:wght@600&display=swap\");:host{display:block;font-family:inherit}*{box-sizing:border-box;margin:0;padding:0}button{border:none;background:none;cursor:pointer}button:focus{outline:none}.ChallengesListPopup{display:flex;height:100%;background-color:var(--emw--color-background, #1E1638);border-radius:8px;overflow:hidden;flex-direction:column;position:relative}.ChallengesListPopupHeader{display:flex;justify-content:space-between;align-items:center;padding:12px 8px 8px}.ChallengesIconButton{width:16px;height:16px;cursor:pointer}.ChallengesListPopupHeaderName{color:var(--emw--color-gray-100, #BBB9C3);font-size:14px;font-weight:500;line-height:14px}.ChallengesListWrapper{overflow-y:auto;-ms-overflow-style:none;scrollbar-width:none}.ChallengesListWrapper::-webkit-scrollbar{display:none}.ChallengesList{display:flex;flex-direction:column;row-gap:12px;padding:8px 19px 0}.ChallengeCard{padding:15px 15px 19px;border:1px solid var(--emw--button-border-color, #403956);border-radius:6px;position:relative}.ChallengeJoinButton.Joined::before,.ChallengeCard.InProgress::before{content:\"\";position:absolute;inset:0;border-radius:var(--emw--button-border-radius, 4px);padding:1px;background:linear-gradient(98.25deg, #FF9400 22.48%, #FEF746 131.02%, #FFE24A 131.9%);-webkit-mask:linear-gradient(#FFF 0 0) content-box, linear-gradient(#FFF 0 0);-webkit-mask-composite:xor;mask-composite:exclude}.ChallengeCardHeader{display:flex;justify-content:space-between;gap:24px;margin-bottom:12px}.ChallengeName{color:var(--emw--color-typography, #FFFFFF);font-family:\"Montserrat\", sans-serif;line-height:22px;font-weight:700;font-size:18px;word-break:break-word}.ChallengeJoinButton{transition:all 0.5s ease-out;background:linear-gradient(98.25deg, #FF9400 22.48%, #FEF746 131.02%, #FFE24A 131.9%);color:var(--emw--color-typography, #1E1638);border-radius:99px;min-width:88px;height:32px;font-size:14px;font-weight:700;position:relative;font-family:\"Montserrat\", sans-serif}.ChallengeJoinButton.Joined{background:linear-gradient(98.25deg, #FF9400 22.48%, #FEF746 131.02%, #FFE24A 131.9%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent}.ChallengeJoinButton.Joined::before{border-radius:99px}.ChallengesListEmpty{padding:20px 32px}.ChallengesListEmpty h2{margin:0 0 16px 0;text-align:center;font-weight:600;font-size:20px;line-height:24px;font-family:\"Montserrat\", sans-serif;color:var(--emw--color-typography, #FFFFFF)}.ChallengesListEmpty p{font-size:14px;line-height:17px;color:var(--emw--color-gray-100, #BBB9C3)}.ChallengeCountdown{color:var(--emw--color-gray-100, #BBB9C3);font-size:12px;line-height:12px}.ChallengesTooltipBackdrop{padding:48px 30px 0;position:absolute;width:100%;height:100%;inset:0;background-color:rgba(0, 0, 0, 0.5)}.ChallengesTooltipBackdrop .ChallengesTooltip{border:1px solid var(--emw--button-border-color, #403956);background-color:var(--emw--color-background, #1E1638);border-radius:8px;padding:32px;font-size:14px;line-height:17px;color:var(--emw--color-gray-100, #BBB9C3);position:relative}.ChallengesTooltipBackdrop .ChallengesTooltip .ChallengesIconButton{top:12px;right:6px;position:absolute}.ChallengesListPopup.Tablet .ChallengesListPopupHeader,.ChallengesListPopup.Desktop .ChallengesListPopupHeader{padding-top:16px}.ChallengesListPopup.Tablet .ChallengesListPopupHeaderName,.ChallengesListPopup.Desktop .ChallengesListPopupHeaderName{font-size:16px;line-height:16px}.ChallengesListPopup.Tablet .ChallengesIconButton,.ChallengesListPopup.Desktop .ChallengesIconButton{width:24px;height:24px}.ChallengesListPopup.Tablet .ChallengesList,.ChallengesListPopup.Desktop .ChallengesList{padding:20px 24px 0;row-gap:20px}.ChallengesListPopup.Tablet .ChallengeCardHeader,.ChallengesListPopup.Desktop .ChallengeCardHeader{margin-bottom:16px}.ChallengesListPopup.Tablet .ChallengeName,.ChallengesListPopup.Desktop .ChallengeName{line-height:27px;font-size:22px}.ChallengesListPopup.Tablet .ChallengeJoinButton,.ChallengesListPopup.Desktop .ChallengeJoinButton{min-width:100px;height:36px;font-size:16px}.ChallengesListPopup.Tablet .ChallengeCountdown,.ChallengesListPopup.Desktop .ChallengeCountdown{font-size:14px;line-height:14px}.ChallengesListPopup.Tablet .ChallengesTooltip,.ChallengesListPopup.Desktop .ChallengesTooltip{padding:60px 65px;font-size:16px;line-height:20px}.ChallengesListPopup.Tablet .ChallengesTooltip .ChallengesIconButton,.ChallengesListPopup.Desktop .ChallengesTooltip .ChallengesIconButton{top:24px;right:24px}";
|
|
931
|
+
|
|
932
|
+
const CasinoEngagementSuiteChallengesList = class {
|
|
933
|
+
constructor(hostRef) {
|
|
934
|
+
registerInstance(this, hostRef);
|
|
935
|
+
this.close = createEvent(this, "close", 7);
|
|
936
|
+
/**
|
|
937
|
+
* Client custom styling via string
|
|
938
|
+
*/
|
|
939
|
+
this.clientStyling = '';
|
|
940
|
+
/**
|
|
941
|
+
* Client custom styling via url
|
|
942
|
+
*/
|
|
943
|
+
this.clientStylingUrl = '';
|
|
944
|
+
/**
|
|
945
|
+
* Language of the widget
|
|
946
|
+
*/
|
|
947
|
+
this.language = 'en';
|
|
948
|
+
/**
|
|
949
|
+
* User's device type
|
|
950
|
+
*/
|
|
951
|
+
this.device = 'Mobile';
|
|
952
|
+
/**
|
|
953
|
+
* List of challenges
|
|
954
|
+
*/
|
|
955
|
+
this.challenges = [];
|
|
956
|
+
this.tooltip = false;
|
|
957
|
+
this.timers = {};
|
|
958
|
+
this.limitStylingAppends = false;
|
|
959
|
+
this.setClientStyling = () => {
|
|
960
|
+
let sheet = document.createElement('style');
|
|
961
|
+
sheet.innerHTML = this.clientStyling;
|
|
962
|
+
this.host.prepend(sheet);
|
|
963
|
+
};
|
|
964
|
+
this.setClientStylingURL = () => {
|
|
965
|
+
let url = new URL(this.clientStylingUrl);
|
|
966
|
+
let cssFile = document.createElement('style');
|
|
967
|
+
fetch(url.href)
|
|
968
|
+
.then((res) => res.text())
|
|
969
|
+
.then((data) => {
|
|
970
|
+
cssFile.innerHTML = data;
|
|
971
|
+
setTimeout(() => { this.host.prepend(cssFile); }, 1);
|
|
972
|
+
})
|
|
973
|
+
.catch((err) => {
|
|
974
|
+
console.log('Error ', err);
|
|
975
|
+
});
|
|
976
|
+
};
|
|
977
|
+
this.handleCloseClick = () => {
|
|
978
|
+
this.close.emit();
|
|
979
|
+
this.tooltip = false;
|
|
980
|
+
};
|
|
981
|
+
this.handleChallengeClick = (ev) => {
|
|
982
|
+
const id = +ev.currentTarget.getAttribute('data-id');
|
|
983
|
+
window.postMessage({ type: `ChallengeClick`, id });
|
|
984
|
+
};
|
|
985
|
+
this.showTooltip = () => {
|
|
986
|
+
this.tooltip = true;
|
|
987
|
+
};
|
|
988
|
+
this.hideTooltip = () => {
|
|
989
|
+
this.tooltip = false;
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
challengesPropHandler(value) {
|
|
993
|
+
if (!this.interval && value.length) {
|
|
994
|
+
this.updateTimers();
|
|
995
|
+
this.startCountdown();
|
|
996
|
+
}
|
|
997
|
+
if (this.interval && !value.length) {
|
|
998
|
+
clearInterval(this.interval);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
handleEvent(e) {
|
|
1002
|
+
const newChallenge = e.data.data;
|
|
1003
|
+
if (e.data.type === 'ChallengeGrant') {
|
|
1004
|
+
const index = this.challenges.findIndex(challenge => differenceInSeconds(new Date(challenge.ExpirationTime), new Date(newChallenge.ExpirationTime)) > 0);
|
|
1005
|
+
if (index > -1) {
|
|
1006
|
+
this.challenges.splice(index, 0, newChallenge);
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
this.challenges.unshift(newChallenge);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
componentWillLoad() {
|
|
1014
|
+
this.challengesPropHandler(this.challenges);
|
|
1015
|
+
}
|
|
1016
|
+
componentDidRender() {
|
|
1017
|
+
if (!this.limitStylingAppends && this.host) {
|
|
1018
|
+
if (this.clientStyling)
|
|
1019
|
+
this.setClientStyling();
|
|
1020
|
+
if (this.clientStylingUrl)
|
|
1021
|
+
this.setClientStylingURL();
|
|
1022
|
+
this.limitStylingAppends = true;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
disconnectedCallback() {
|
|
1026
|
+
this.interval && clearInterval(this.interval);
|
|
1027
|
+
}
|
|
1028
|
+
startCountdown() {
|
|
1029
|
+
this.interval = setInterval(() => {
|
|
1030
|
+
this.updateTimers();
|
|
1031
|
+
}, 1000);
|
|
1032
|
+
}
|
|
1033
|
+
updateTimers() {
|
|
1034
|
+
const now = new Date();
|
|
1035
|
+
this.timers = this.challenges.filter(challenge => challenge.Status !== ChallengeProgressStatus.Expired).reduce((acc, challenge) => {
|
|
1036
|
+
const expirationDate = new Date(challenge.ExpirationTime);
|
|
1037
|
+
const diff = differenceInSeconds(expirationDate, now);
|
|
1038
|
+
const duration = intervalToDuration({
|
|
1039
|
+
start: now,
|
|
1040
|
+
end: expirationDate
|
|
1041
|
+
});
|
|
1042
|
+
let countdown = '00h:00m:00s';
|
|
1043
|
+
if (diff < 1) {
|
|
1044
|
+
this.removeChallenge(challenge.Id);
|
|
1045
|
+
}
|
|
1046
|
+
else {
|
|
1047
|
+
const days = duration.days.toString().padStart(2, '0');
|
|
1048
|
+
const hours = duration.hours.toString().padStart(2, '0');
|
|
1049
|
+
const minutes = duration.minutes.toString().padStart(2, '0');
|
|
1050
|
+
const seconds = duration.seconds.toString().padStart(2, '0');
|
|
1051
|
+
countdown = days === '00'
|
|
1052
|
+
? `${hours}h:${minutes}m:${seconds}s`
|
|
1053
|
+
: `${days}d:${hours}h:${minutes}m`;
|
|
1054
|
+
}
|
|
1055
|
+
return Object.assign(Object.assign({}, acc), { [challenge.Id]: countdown });
|
|
1056
|
+
}, {});
|
|
1057
|
+
}
|
|
1058
|
+
removeChallenge(id) {
|
|
1059
|
+
const index = this.challenges.findIndex(challenge => challenge.Id === id);
|
|
1060
|
+
if (index > -1) {
|
|
1061
|
+
this.challenges.splice(index, 1);
|
|
1062
|
+
window.postMessage({ type: 'ChallengeHasExpired', id });
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
getChallengeClasses(challenge) {
|
|
1066
|
+
return {
|
|
1067
|
+
ChallengeCard: true,
|
|
1068
|
+
InProgress: challenge.Status === ChallengeProgressStatus.InProgress,
|
|
1069
|
+
Completed: this.isChallengeCompleted(challenge),
|
|
1070
|
+
Paused: this.isChallengePaused(challenge)
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
isChallengePaused(challenge) {
|
|
1074
|
+
return challenge.Status === ChallengeProgressStatus.Started
|
|
1075
|
+
&& challenge.LevelProgresses[0].ProgressPercentage > 0;
|
|
1076
|
+
}
|
|
1077
|
+
isChallengeCompleted(challenge) {
|
|
1078
|
+
return challenge.Status === ChallengeProgressStatus.Completed
|
|
1079
|
+
|| (challenge.Status === ChallengeProgressStatus.PendingLevelReward
|
|
1080
|
+
&& challenge.LevelProgresses.every(progress => progress.ProgressPercentage === 100));
|
|
1081
|
+
}
|
|
1082
|
+
getChallengeProgress(challenge) {
|
|
1083
|
+
if (challenge.Status === ChallengeProgressStatus.Completed) {
|
|
1084
|
+
return 100;
|
|
1085
|
+
}
|
|
1086
|
+
if (this.isChallengePaused(challenge)
|
|
1087
|
+
|| challenge.Status === ChallengeProgressStatus.PendingLevelReward
|
|
1088
|
+
|| challenge.Status === ChallengeProgressStatus.InProgress) {
|
|
1089
|
+
const activeLevel = challenge.LevelProgresses
|
|
1090
|
+
.find(level => level.ProgressStatus === ChallengeLevelProgressStatus.InProgress);
|
|
1091
|
+
/**
|
|
1092
|
+
* It is possible that Paused/InProgress challenge
|
|
1093
|
+
* doesn't have InProgress level
|
|
1094
|
+
* because level becomes InProgress after user's bet.
|
|
1095
|
+
* In this case should be displayed progress of the next level (0%)
|
|
1096
|
+
*/
|
|
1097
|
+
return activeLevel ? activeLevel.ProgressPercentage : 0;
|
|
1098
|
+
}
|
|
1099
|
+
return -1;
|
|
1100
|
+
}
|
|
1101
|
+
getChallengeHeaderTemplate(challenge) {
|
|
1102
|
+
return h("div", { class: "ChallengeCardHeader" }, h("div", { class: "ChallengeName" }, challenge.ChallengePresentation.PresentationName), h("button", { class: challenge.Status === ChallengeProgressStatus.InProgress ? 'ChallengeJoinButton Joined' : 'ChallengeJoinButton' }, challenge.Status === ChallengeProgressStatus.InProgress
|
|
1103
|
+
? translate('unjoin', this.language)
|
|
1104
|
+
: translate('join', this.language)));
|
|
1105
|
+
}
|
|
1106
|
+
getChallengeTemplate(challenge) {
|
|
1107
|
+
const challengeProgress = this.getChallengeProgress(challenge);
|
|
1108
|
+
const countdown = this.timers[challenge.Id];
|
|
1109
|
+
const progressTemplate = challengeProgress > -1
|
|
1110
|
+
? h("casino-engagement-suite-progress-bar", { class: this.device, value: challengeProgress, disabled: this.isChallengePaused(challenge) }, h("span", { slot: "Title", class: "ChallengeCountdown" }, countdown))
|
|
1111
|
+
: h("span", { class: "ChallengeCountdown" }, countdown);
|
|
1112
|
+
return (h("div", { class: this.getChallengeClasses(challenge), onClick: this.handleChallengeClick, key: challenge.Id, "data-id": challenge.Id }, this.getChallengeHeaderTemplate(challenge), progressTemplate));
|
|
1113
|
+
}
|
|
1114
|
+
getHeaderTemplate() {
|
|
1115
|
+
return h("header", { class: "ChallengesListPopupHeader" }, h("button", { onClick: this.showTooltip, class: "ChallengesIconButton" }, h("img", { src: "https://static.everymatrix.com/gic/img/engagement-suite/help.svg", alt: "Show tooltip" })), h("div", { class: "ChallengesListPopupHeaderName" }, translate('challenges', this.language)), h("button", { class: "ChallengesIconButton", onClick: this.handleCloseClick }, h("img", { src: "https://static.everymatrix.com/gic/img/engagement-suite/close.svg", alt: "\u0421lose challenges list" })));
|
|
1116
|
+
}
|
|
1117
|
+
getListTemplate() {
|
|
1118
|
+
if (this.challenges.length) {
|
|
1119
|
+
return h("div", { class: "ChallengesListWrapper" }, h("div", { class: "ChallengesList" }, this.challenges.map(challenge => this.getChallengeTemplate(challenge))));
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
return h("div", { class: "ChallengesListEmpty" }, h("h2", null, translate('noChallenges', this.language)), h("p", null, translate('tryOtherGames', this.language)));
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
getTooltipTemplate() {
|
|
1126
|
+
if (this.tooltip) {
|
|
1127
|
+
return h("div", { class: "ChallengesTooltipBackdrop" }, h("div", { class: "ChallengesTooltip" }, h("button", { class: "ChallengesIconButton", onClick: this.hideTooltip }, h("img", { src: "https://static.everymatrix.com/gic/img/engagement-suite/close.svg", alt: "\u0421lose tooltip" })), translate('tooltip', this.language)));
|
|
1128
|
+
}
|
|
1129
|
+
else {
|
|
1130
|
+
return '';
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
render() {
|
|
1134
|
+
return h("div", { class: `ChallengesListPopup ${this.device}` }, this.getHeaderTemplate(), this.getListTemplate(), this.getTooltipTemplate());
|
|
1135
|
+
}
|
|
1136
|
+
get host() { return getElement(this); }
|
|
1137
|
+
static get watchers() { return {
|
|
1138
|
+
"challenges": ["challengesPropHandler"]
|
|
1139
|
+
}; }
|
|
1140
|
+
};
|
|
1141
|
+
CasinoEngagementSuiteChallengesList.style = casinoEngagementSuiteChallengesListCss;
|
|
1142
|
+
|
|
1143
|
+
export { CasinoEngagementSuiteChallengesList as casino_engagement_suite_challenges_list };
|