@everymatrix/casino-tournament-list 1.20.5

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 (58) hide show
  1. package/dist/casino-tournament-list/casino-tournament-list.esm.js +1 -0
  2. package/dist/casino-tournament-list/index.esm.js +0 -0
  3. package/dist/casino-tournament-list/p-1368789d.js +1 -0
  4. package/dist/casino-tournament-list/p-908908a6.entry.js +15 -0
  5. package/dist/cjs/casino-tournament-banner_6.cjs.entry.js +8911 -0
  6. package/dist/cjs/casino-tournament-list.cjs.js +19 -0
  7. package/dist/cjs/index-c1b4bd7d.js +1284 -0
  8. package/dist/cjs/index.cjs.js +2 -0
  9. package/dist/cjs/loader.cjs.js +21 -0
  10. package/dist/collection/collection-manifest.json +43 -0
  11. package/dist/collection/components/casino-tournament-list/casino-tournament-list.css +97 -0
  12. package/dist/collection/components/casino-tournament-list/casino-tournament-list.js +578 -0
  13. package/dist/collection/index.js +1 -0
  14. package/dist/collection/utils/locale.utils.js +104 -0
  15. package/dist/collection/utils/utils.js +20 -0
  16. package/dist/components/casino-tournament-banner.js +6 -0
  17. package/dist/components/casino-tournament-banner2.js +598 -0
  18. package/dist/components/casino-tournament-buttons.js +6 -0
  19. package/dist/components/casino-tournament-buttons2.js +534 -0
  20. package/dist/components/casino-tournament-duration.js +6 -0
  21. package/dist/components/casino-tournament-duration2.js +220 -0
  22. package/dist/components/casino-tournament-info.js +6 -0
  23. package/dist/components/casino-tournament-info2.js +502 -0
  24. package/dist/components/casino-tournament-list.d.ts +11 -0
  25. package/dist/components/casino-tournament-list.js +1493 -0
  26. package/dist/components/casino-tournament-prizes.js +6 -0
  27. package/dist/components/casino-tournament-prizes2.js +190 -0
  28. package/dist/components/index.d.ts +26 -0
  29. package/dist/components/index.js +1 -0
  30. package/dist/components/moment.js +5677 -0
  31. package/dist/esm/casino-tournament-banner_6.entry.js +8902 -0
  32. package/dist/esm/casino-tournament-list.js +17 -0
  33. package/dist/esm/index-b57e0a6b.js +1258 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/loader.js +17 -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/index.cjs.js +1 -0
  43. package/dist/index.js +1 -0
  44. package/dist/stencil.config.js +22 -0
  45. package/dist/types/Users/sebastian.strulea/Documents/work/widgets-stencil/packages/casino-tournament-list/.stencil/packages/casino-tournament-list/stencil.config.d.ts +2 -0
  46. package/dist/types/components/casino-tournament-list/casino-tournament-list.d.ts +101 -0
  47. package/dist/types/components.d.ts +181 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  50. package/dist/types/utils/locale.utils.d.ts +2 -0
  51. package/dist/types/utils/utils.d.ts +2 -0
  52. package/loader/cdn.js +3 -0
  53. package/loader/index.cjs.js +3 -0
  54. package/loader/index.d.ts +12 -0
  55. package/loader/index.es2017.js +3 -0
  56. package/loader/index.js +4 -0
  57. package/loader/package.json +10 -0
  58. package/package.json +19 -0
@@ -0,0 +1,1493 @@
1
+ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
2
+ import { d as defineCustomElement$6 } from './casino-tournament-banner2.js';
3
+ import { d as defineCustomElement$5 } from './casino-tournament-buttons2.js';
4
+ import { d as defineCustomElement$4 } from './casino-tournament-duration2.js';
5
+ import { d as defineCustomElement$3 } from './casino-tournament-info2.js';
6
+ import { d as defineCustomElement$2 } from './casino-tournament-prizes2.js';
7
+
8
+ const getDevice = () => {
9
+ let userAgent = window.navigator.userAgent;
10
+ if (userAgent.toLowerCase().match(/android/i)) {
11
+ return 'Android';
12
+ }
13
+ if (userAgent.toLowerCase().match(/iphone/i)) {
14
+ return 'iPhone';
15
+ }
16
+ if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
17
+ return 'iPad';
18
+ }
19
+ return 'PC';
20
+ };
21
+ const isMobile = () => {
22
+ let userAgent = window.navigator.userAgent;
23
+ return !!(userAgent.toLowerCase().match(/android/i) ||
24
+ userAgent.toLowerCase().match(/blackberry|bb/i) ||
25
+ userAgent.toLowerCase().match(/iphone|ipad|ipod/i) ||
26
+ userAgent.toLowerCase().match(/windows phone|windows mobile|iemobile|wpdesktop/i));
27
+ };
28
+
29
+ const DEFAULT_LANGUAGE = 'en';
30
+ const SUPPORTED_LANGUAGES = ['ro', 'en', 'zh-hk', 'fr', 'hu', 'tr', 'el', 'es', 'pt'];
31
+ const TRANSLATIONS = {
32
+ en: {
33
+ 500: '500 - Internal server error',
34
+ showMore: 'Show more',
35
+ Scheduled: 'Scheduled',
36
+ Ongoing: 'Ongoing',
37
+ Finished: 'Finished',
38
+ loading: 'Loading, please wait ...',
39
+ noTournaments: 'No tournaments found'
40
+ },
41
+ 'zh-hk': {
42
+ 500: '500內部服務器錯誤',
43
+ showMore: '顯示更多',
44
+ Scheduled: '預定的',
45
+ Ongoing: '進行中',
46
+ Finished: '完成的',
47
+ loading: '加載請稍候 ...',
48
+ noTournaments: '沒有找到比賽'
49
+ },
50
+ fr: {
51
+ 500: '500 - erreur de serveur interne',
52
+ showMore: 'Afficher plus',
53
+ Scheduled: 'Programmé',
54
+ Ongoing: 'En cours',
55
+ Finished: 'Fini',
56
+ loading: 'Chargement , veuillez patienter ...',
57
+ noTournaments: 'Aucun tournoi trouvé'
58
+ },
59
+ ro: {
60
+ 500: '500 - Internal server error',
61
+ showMore: 'Mai mult',
62
+ Scheduled: 'Programate',
63
+ Ongoing: 'În curs',
64
+ Finished: 'Finalizat',
65
+ loading: 'Se încarcă, asteptati ...',
66
+ noTournaments: 'Niciun turneu gasit'
67
+ },
68
+ tr: {
69
+ 500: '500 - Dahili sunucu hatası',
70
+ showMore: 'Daha fazla',
71
+ Scheduled: 'Planlanmış',
72
+ Ongoing: 'Devam Eden',
73
+ Finished: 'Sona Ermiş',
74
+ loading: 'Yükleniyor, lütfen bekleyin ...',
75
+ noTournaments: 'Herhangi bir turnuva bulunamadı.'
76
+ },
77
+ el: {
78
+ 500: '500 - Σφάλμα Διακομιστή',
79
+ showMore: 'Περισσότερα',
80
+ Scheduled: 'Προγραμματισμένα',
81
+ Ongoing: 'Τρέχοντα',
82
+ Finished: 'Ολοκληρωμένα',
83
+ loading: 'Φορτώνει, παρακαλούμε περιμένετε ...',
84
+ noTournaments: 'Δεν βρέθηκαν τουρνουά'
85
+ },
86
+ es: {
87
+ 500: '500 - Error servidor interno',
88
+ showMore: 'Mostrar más',
89
+ Scheduled: 'Programado',
90
+ Ongoing: 'En vivo',
91
+ Finished: 'Finalizado',
92
+ loading: 'Cargando …',
93
+ noTournaments: 'No se encontraron Torneos',
94
+ },
95
+ hu: {
96
+ 500: '500 - Belső szerver hiba',
97
+ showMore: 'Mutass többet',
98
+ Scheduled: 'Ütemezés',
99
+ Ongoing: 'Folyamatban',
100
+ Finished: 'Befejezett',
101
+ loading: 'Betöltés, kérjük várjon...',
102
+ noTournaments: 'Verseny nem található',
103
+ },
104
+ pt: {
105
+ 500: 'Erro 500 - Erro interno do servidor',
106
+ showMore: 'Ver mais',
107
+ Scheduled: 'Agendado',
108
+ Ongoing: 'Em progresso',
109
+ Finished: 'Finalizado',
110
+ loading: 'Carregando, por favor espere ...',
111
+ noTournaments: 'Nenhum torneio encontrado'
112
+ }
113
+ };
114
+ const translate = (key, customLang) => {
115
+ const lang = customLang;
116
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
117
+ };
118
+ const getTranslations = (url) => {
119
+ // fetch url, get the data, replace the TRANSLATIONS content
120
+ return new Promise((resolve) => {
121
+ fetch(url)
122
+ .then((res) => res.json())
123
+ .then((data) => {
124
+ Object.keys(data).forEach((item) => {
125
+ for (let key in data[item]) {
126
+ TRANSLATIONS[item][key] = data[item][key];
127
+ }
128
+ });
129
+ resolve(true);
130
+ });
131
+ });
132
+ };
133
+
134
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
135
+
136
+ function createCommonjsModule(fn, basedir, module) {
137
+ return module = {
138
+ path: basedir,
139
+ exports: {},
140
+ require: function (path, base) {
141
+ return commonjsRequire();
142
+ }
143
+ }, fn(module, module.exports), module.exports;
144
+ }
145
+
146
+ function commonjsRequire () {
147
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
148
+ }
149
+
150
+ var eventsource = createCommonjsModule(function (module, exports) {
151
+ /** @license
152
+ * eventsource.js
153
+ * Available under MIT License (MIT)
154
+ * https://github.com/Yaffle/EventSource/
155
+ */
156
+
157
+ /*jslint indent: 2, vars: true, plusplus: true */
158
+ /*global setTimeout, clearTimeout */
159
+
160
+ (function (global) {
161
+
162
+ var setTimeout = global.setTimeout;
163
+ var clearTimeout = global.clearTimeout;
164
+ var XMLHttpRequest = global.XMLHttpRequest;
165
+ var XDomainRequest = global.XDomainRequest;
166
+ var ActiveXObject = global.ActiveXObject;
167
+ var NativeEventSource = global.EventSource;
168
+
169
+ var document = global.document;
170
+ var Promise = global.Promise;
171
+ var fetch = global.fetch;
172
+ var Response = global.Response;
173
+ var TextDecoder = global.TextDecoder;
174
+ var TextEncoder = global.TextEncoder;
175
+ var AbortController = global.AbortController;
176
+
177
+ if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
178
+ document.readyState = "loading";
179
+ window.addEventListener("load", function (event) {
180
+ document.readyState = "complete";
181
+ }, false);
182
+ }
183
+
184
+ if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
185
+ XMLHttpRequest = function () {
186
+ return new ActiveXObject("Microsoft.XMLHTTP");
187
+ };
188
+ }
189
+
190
+ if (Object.create == undefined) {
191
+ Object.create = function (C) {
192
+ function F(){}
193
+ F.prototype = C;
194
+ return new F();
195
+ };
196
+ }
197
+
198
+ if (!Date.now) {
199
+ Date.now = function now() {
200
+ return new Date().getTime();
201
+ };
202
+ }
203
+
204
+ // see #118 (Promise#finally with polyfilled Promise)
205
+ // see #123 (data URLs crash Edge)
206
+ // see #125 (CSP violations)
207
+ // see pull/#138
208
+ // => No way to polyfill Promise#finally
209
+
210
+ if (AbortController == undefined) {
211
+ var originalFetch2 = fetch;
212
+ fetch = function (url, options) {
213
+ var signal = options.signal;
214
+ return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
215
+ var reader = response.body.getReader();
216
+ signal._reader = reader;
217
+ if (signal._aborted) {
218
+ signal._reader.cancel();
219
+ }
220
+ return {
221
+ status: response.status,
222
+ statusText: response.statusText,
223
+ headers: response.headers,
224
+ body: {
225
+ getReader: function () {
226
+ return reader;
227
+ }
228
+ }
229
+ };
230
+ });
231
+ };
232
+ AbortController = function () {
233
+ this.signal = {
234
+ _reader: null,
235
+ _aborted: false
236
+ };
237
+ this.abort = function () {
238
+ if (this.signal._reader != null) {
239
+ this.signal._reader.cancel();
240
+ }
241
+ this.signal._aborted = true;
242
+ };
243
+ };
244
+ }
245
+
246
+ function TextDecoderPolyfill() {
247
+ this.bitsNeeded = 0;
248
+ this.codePoint = 0;
249
+ }
250
+
251
+ TextDecoderPolyfill.prototype.decode = function (octets) {
252
+ function valid(codePoint, shift, octetsCount) {
253
+ if (octetsCount === 1) {
254
+ return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
255
+ }
256
+ if (octetsCount === 2) {
257
+ return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
258
+ }
259
+ if (octetsCount === 3) {
260
+ return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
261
+ }
262
+ throw new Error();
263
+ }
264
+ function octetsCount(bitsNeeded, codePoint) {
265
+ if (bitsNeeded === 6 * 1) {
266
+ return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
267
+ }
268
+ if (bitsNeeded === 6 * 2) {
269
+ return codePoint > 15 ? 3 : 2;
270
+ }
271
+ if (bitsNeeded === 6 * 3) {
272
+ return 3;
273
+ }
274
+ throw new Error();
275
+ }
276
+ var REPLACER = 0xFFFD;
277
+ var string = "";
278
+ var bitsNeeded = this.bitsNeeded;
279
+ var codePoint = this.codePoint;
280
+ for (var i = 0; i < octets.length; i += 1) {
281
+ var octet = octets[i];
282
+ if (bitsNeeded !== 0) {
283
+ if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
284
+ bitsNeeded = 0;
285
+ codePoint = REPLACER;
286
+ string += String.fromCharCode(codePoint);
287
+ }
288
+ }
289
+ if (bitsNeeded === 0) {
290
+ if (octet >= 0 && octet <= 127) {
291
+ bitsNeeded = 0;
292
+ codePoint = octet;
293
+ } else if (octet >= 192 && octet <= 223) {
294
+ bitsNeeded = 6 * 1;
295
+ codePoint = octet & 31;
296
+ } else if (octet >= 224 && octet <= 239) {
297
+ bitsNeeded = 6 * 2;
298
+ codePoint = octet & 15;
299
+ } else if (octet >= 240 && octet <= 247) {
300
+ bitsNeeded = 6 * 3;
301
+ codePoint = octet & 7;
302
+ } else {
303
+ bitsNeeded = 0;
304
+ codePoint = REPLACER;
305
+ }
306
+ if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
307
+ bitsNeeded = 0;
308
+ codePoint = REPLACER;
309
+ }
310
+ } else {
311
+ bitsNeeded -= 6;
312
+ codePoint = codePoint << 6 | octet & 63;
313
+ }
314
+ if (bitsNeeded === 0) {
315
+ if (codePoint <= 0xFFFF) {
316
+ string += String.fromCharCode(codePoint);
317
+ } else {
318
+ string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
319
+ string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
320
+ }
321
+ }
322
+ }
323
+ this.bitsNeeded = bitsNeeded;
324
+ this.codePoint = codePoint;
325
+ return string;
326
+ };
327
+
328
+ // Firefox < 38 throws an error with stream option
329
+ var supportsStreamOption = function () {
330
+ try {
331
+ return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
332
+ } catch (error) {
333
+ console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
334
+ }
335
+ return false;
336
+ };
337
+
338
+ // IE, Edge
339
+ if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
340
+ TextDecoder = TextDecoderPolyfill;
341
+ }
342
+
343
+ var k = function () {
344
+ };
345
+
346
+ function XHRWrapper(xhr) {
347
+ this.withCredentials = false;
348
+ this.readyState = 0;
349
+ this.status = 0;
350
+ this.statusText = "";
351
+ this.responseText = "";
352
+ this.onprogress = k;
353
+ this.onload = k;
354
+ this.onerror = k;
355
+ this.onreadystatechange = k;
356
+ this._contentType = "";
357
+ this._xhr = xhr;
358
+ this._sendTimeout = 0;
359
+ this._abort = k;
360
+ }
361
+
362
+ XHRWrapper.prototype.open = function (method, url) {
363
+ this._abort(true);
364
+
365
+ var that = this;
366
+ var xhr = this._xhr;
367
+ var state = 1;
368
+ var timeout = 0;
369
+
370
+ this._abort = function (silent) {
371
+ if (that._sendTimeout !== 0) {
372
+ clearTimeout(that._sendTimeout);
373
+ that._sendTimeout = 0;
374
+ }
375
+ if (state === 1 || state === 2 || state === 3) {
376
+ state = 4;
377
+ xhr.onload = k;
378
+ xhr.onerror = k;
379
+ xhr.onabort = k;
380
+ xhr.onprogress = k;
381
+ xhr.onreadystatechange = k;
382
+ // IE 8 - 9: XDomainRequest#abort() does not fire any event
383
+ // Opera < 10: XMLHttpRequest#abort() does not fire any event
384
+ xhr.abort();
385
+ if (timeout !== 0) {
386
+ clearTimeout(timeout);
387
+ timeout = 0;
388
+ }
389
+ if (!silent) {
390
+ that.readyState = 4;
391
+ that.onabort(null);
392
+ that.onreadystatechange();
393
+ }
394
+ }
395
+ state = 0;
396
+ };
397
+
398
+ var onStart = function () {
399
+ if (state === 1) {
400
+ //state = 2;
401
+ var status = 0;
402
+ var statusText = "";
403
+ var contentType = undefined;
404
+ if (!("contentType" in xhr)) {
405
+ try {
406
+ status = xhr.status;
407
+ statusText = xhr.statusText;
408
+ contentType = xhr.getResponseHeader("Content-Type");
409
+ } catch (error) {
410
+ // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
411
+ // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
412
+ // https://bugs.webkit.org/show_bug.cgi?id=29121
413
+ status = 0;
414
+ statusText = "";
415
+ contentType = undefined;
416
+ // Firefox < 14, Chrome ?, Safari ?
417
+ // https://bugs.webkit.org/show_bug.cgi?id=29658
418
+ // https://bugs.webkit.org/show_bug.cgi?id=77854
419
+ }
420
+ } else {
421
+ status = 200;
422
+ statusText = "OK";
423
+ contentType = xhr.contentType;
424
+ }
425
+ if (status !== 0) {
426
+ state = 2;
427
+ that.readyState = 2;
428
+ that.status = status;
429
+ that.statusText = statusText;
430
+ that._contentType = contentType;
431
+ that.onreadystatechange();
432
+ }
433
+ }
434
+ };
435
+ var onProgress = function () {
436
+ onStart();
437
+ if (state === 2 || state === 3) {
438
+ state = 3;
439
+ var responseText = "";
440
+ try {
441
+ responseText = xhr.responseText;
442
+ } catch (error) {
443
+ // IE 8 - 9 with XMLHttpRequest
444
+ }
445
+ that.readyState = 3;
446
+ that.responseText = responseText;
447
+ that.onprogress();
448
+ }
449
+ };
450
+ var onFinish = function (type, event) {
451
+ if (event == null || event.preventDefault == null) {
452
+ event = {
453
+ preventDefault: k
454
+ };
455
+ }
456
+ // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
457
+ // IE 8 fires "onload" without "onprogress"
458
+ onProgress();
459
+ if (state === 1 || state === 2 || state === 3) {
460
+ state = 4;
461
+ if (timeout !== 0) {
462
+ clearTimeout(timeout);
463
+ timeout = 0;
464
+ }
465
+ that.readyState = 4;
466
+ if (type === "load") {
467
+ that.onload(event);
468
+ } else if (type === "error") {
469
+ that.onerror(event);
470
+ } else if (type === "abort") {
471
+ that.onabort(event);
472
+ } else {
473
+ throw new TypeError();
474
+ }
475
+ that.onreadystatechange();
476
+ }
477
+ };
478
+ var onReadyStateChange = function (event) {
479
+ if (xhr != undefined) { // Opera 12
480
+ if (xhr.readyState === 4) {
481
+ if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
482
+ onFinish(xhr.responseText === "" ? "error" : "load", event);
483
+ }
484
+ } else if (xhr.readyState === 3) {
485
+ if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
486
+ // and in Firefox 3.6
487
+ onProgress();
488
+ }
489
+ } else if (xhr.readyState === 2) {
490
+ onStart();
491
+ }
492
+ }
493
+ };
494
+ var onTimeout = function () {
495
+ timeout = setTimeout(function () {
496
+ onTimeout();
497
+ }, 500);
498
+ if (xhr.readyState === 3) {
499
+ onProgress();
500
+ }
501
+ };
502
+
503
+ // XDomainRequest#abort removes onprogress, onerror, onload
504
+ if ("onload" in xhr) {
505
+ xhr.onload = function (event) {
506
+ onFinish("load", event);
507
+ };
508
+ }
509
+ if ("onerror" in xhr) {
510
+ xhr.onerror = function (event) {
511
+ onFinish("error", event);
512
+ };
513
+ }
514
+ // improper fix to match Firefox behaviour, but it is better than just ignore abort
515
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
516
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
517
+ // https://code.google.com/p/chromium/issues/detail?id=153570
518
+ // IE 8 fires "onload" without "onprogress
519
+ if ("onabort" in xhr) {
520
+ xhr.onabort = function (event) {
521
+ onFinish("abort", event);
522
+ };
523
+ }
524
+
525
+ if ("onprogress" in xhr) {
526
+ xhr.onprogress = onProgress;
527
+ }
528
+
529
+ // IE 8 - 9 (XMLHTTPRequest)
530
+ // Opera < 12
531
+ // Firefox < 3.5
532
+ // Firefox 3.5 - 3.6 - ? < 9.0
533
+ // onprogress is not fired sometimes or delayed
534
+ // see also #64 (significant lag in IE 11)
535
+ if ("onreadystatechange" in xhr) {
536
+ xhr.onreadystatechange = function (event) {
537
+ onReadyStateChange(event);
538
+ };
539
+ }
540
+
541
+ if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
542
+ url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
543
+ }
544
+ xhr.open(method, url, true);
545
+
546
+ if ("readyState" in xhr) {
547
+ // workaround for Opera 12 issue with "progress" events
548
+ // #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
549
+ timeout = setTimeout(function () {
550
+ onTimeout();
551
+ }, 0);
552
+ }
553
+ };
554
+ XHRWrapper.prototype.abort = function () {
555
+ this._abort(false);
556
+ };
557
+ XHRWrapper.prototype.getResponseHeader = function (name) {
558
+ return this._contentType;
559
+ };
560
+ XHRWrapper.prototype.setRequestHeader = function (name, value) {
561
+ var xhr = this._xhr;
562
+ if ("setRequestHeader" in xhr) {
563
+ xhr.setRequestHeader(name, value);
564
+ }
565
+ };
566
+ XHRWrapper.prototype.getAllResponseHeaders = function () {
567
+ // XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
568
+ return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
569
+ };
570
+ XHRWrapper.prototype.send = function () {
571
+ // loading indicator in Safari < ? (6), Chrome < 14, Firefox
572
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
573
+ if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
574
+ document != undefined &&
575
+ document.readyState != undefined &&
576
+ document.readyState !== "complete") {
577
+ var that = this;
578
+ that._sendTimeout = setTimeout(function () {
579
+ that._sendTimeout = 0;
580
+ that.send();
581
+ }, 4);
582
+ return;
583
+ }
584
+
585
+ var xhr = this._xhr;
586
+ // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
587
+ if ("withCredentials" in xhr) {
588
+ xhr.withCredentials = this.withCredentials;
589
+ }
590
+ try {
591
+ // xhr.send(); throws "Not enough arguments" in Firefox 3.0
592
+ xhr.send(undefined);
593
+ } catch (error1) {
594
+ // Safari 5.1.7, Opera 12
595
+ throw error1;
596
+ }
597
+ };
598
+
599
+ function toLowerCase(name) {
600
+ return name.replace(/[A-Z]/g, function (c) {
601
+ return String.fromCharCode(c.charCodeAt(0) + 0x20);
602
+ });
603
+ }
604
+
605
+ function HeadersPolyfill(all) {
606
+ // Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
607
+ var map = Object.create(null);
608
+ var array = all.split("\r\n");
609
+ for (var i = 0; i < array.length; i += 1) {
610
+ var line = array[i];
611
+ var parts = line.split(": ");
612
+ var name = parts.shift();
613
+ var value = parts.join(": ");
614
+ map[toLowerCase(name)] = value;
615
+ }
616
+ this._map = map;
617
+ }
618
+ HeadersPolyfill.prototype.get = function (name) {
619
+ return this._map[toLowerCase(name)];
620
+ };
621
+
622
+ if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
623
+ XMLHttpRequest.HEADERS_RECEIVED = 2;
624
+ }
625
+
626
+ function XHRTransport() {
627
+ }
628
+
629
+ XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
630
+ xhr.open("GET", url);
631
+ var offset = 0;
632
+ xhr.onprogress = function () {
633
+ var responseText = xhr.responseText;
634
+ var chunk = responseText.slice(offset);
635
+ offset += chunk.length;
636
+ onProgressCallback(chunk);
637
+ };
638
+ xhr.onerror = function (event) {
639
+ event.preventDefault();
640
+ onFinishCallback(new Error("NetworkError"));
641
+ };
642
+ xhr.onload = function () {
643
+ onFinishCallback(null);
644
+ };
645
+ xhr.onabort = function () {
646
+ onFinishCallback(null);
647
+ };
648
+ xhr.onreadystatechange = function () {
649
+ if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
650
+ var status = xhr.status;
651
+ var statusText = xhr.statusText;
652
+ var contentType = xhr.getResponseHeader("Content-Type");
653
+ var headers = xhr.getAllResponseHeaders();
654
+ onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
655
+ }
656
+ };
657
+ xhr.withCredentials = withCredentials;
658
+ for (var name in headers) {
659
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
660
+ xhr.setRequestHeader(name, headers[name]);
661
+ }
662
+ }
663
+ xhr.send();
664
+ return xhr;
665
+ };
666
+
667
+ function HeadersWrapper(headers) {
668
+ this._headers = headers;
669
+ }
670
+ HeadersWrapper.prototype.get = function (name) {
671
+ return this._headers.get(name);
672
+ };
673
+
674
+ function FetchTransport() {
675
+ }
676
+
677
+ FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
678
+ var reader = null;
679
+ var controller = new AbortController();
680
+ var signal = controller.signal;
681
+ var textDecoder = new TextDecoder();
682
+ fetch(url, {
683
+ headers: headers,
684
+ credentials: withCredentials ? "include" : "same-origin",
685
+ signal: signal,
686
+ cache: "no-store"
687
+ }).then(function (response) {
688
+ reader = response.body.getReader();
689
+ onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
690
+ // see https://github.com/promises-aplus/promises-spec/issues/179
691
+ return new Promise(function (resolve, reject) {
692
+ var readNextChunk = function () {
693
+ reader.read().then(function (result) {
694
+ if (result.done) {
695
+ //Note: bytes in textDecoder are ignored
696
+ resolve(undefined);
697
+ } else {
698
+ var chunk = textDecoder.decode(result.value, {stream: true});
699
+ onProgressCallback(chunk);
700
+ readNextChunk();
701
+ }
702
+ })["catch"](function (error) {
703
+ reject(error);
704
+ });
705
+ };
706
+ readNextChunk();
707
+ });
708
+ })["catch"](function (error) {
709
+ if (error.name === "AbortError") {
710
+ return undefined;
711
+ } else {
712
+ return error;
713
+ }
714
+ }).then(function (error) {
715
+ onFinishCallback(error);
716
+ });
717
+ return {
718
+ abort: function () {
719
+ if (reader != null) {
720
+ reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
721
+ }
722
+ controller.abort();
723
+ }
724
+ };
725
+ };
726
+
727
+ function EventTarget() {
728
+ this._listeners = Object.create(null);
729
+ }
730
+
731
+ function throwError(e) {
732
+ setTimeout(function () {
733
+ throw e;
734
+ }, 0);
735
+ }
736
+
737
+ EventTarget.prototype.dispatchEvent = function (event) {
738
+ event.target = this;
739
+ var typeListeners = this._listeners[event.type];
740
+ if (typeListeners != undefined) {
741
+ var length = typeListeners.length;
742
+ for (var i = 0; i < length; i += 1) {
743
+ var listener = typeListeners[i];
744
+ try {
745
+ if (typeof listener.handleEvent === "function") {
746
+ listener.handleEvent(event);
747
+ } else {
748
+ listener.call(this, event);
749
+ }
750
+ } catch (e) {
751
+ throwError(e);
752
+ }
753
+ }
754
+ }
755
+ };
756
+ EventTarget.prototype.addEventListener = function (type, listener) {
757
+ type = String(type);
758
+ var listeners = this._listeners;
759
+ var typeListeners = listeners[type];
760
+ if (typeListeners == undefined) {
761
+ typeListeners = [];
762
+ listeners[type] = typeListeners;
763
+ }
764
+ var found = false;
765
+ for (var i = 0; i < typeListeners.length; i += 1) {
766
+ if (typeListeners[i] === listener) {
767
+ found = true;
768
+ }
769
+ }
770
+ if (!found) {
771
+ typeListeners.push(listener);
772
+ }
773
+ };
774
+ EventTarget.prototype.removeEventListener = function (type, listener) {
775
+ type = String(type);
776
+ var listeners = this._listeners;
777
+ var typeListeners = listeners[type];
778
+ if (typeListeners != undefined) {
779
+ var filtered = [];
780
+ for (var i = 0; i < typeListeners.length; i += 1) {
781
+ if (typeListeners[i] !== listener) {
782
+ filtered.push(typeListeners[i]);
783
+ }
784
+ }
785
+ if (filtered.length === 0) {
786
+ delete listeners[type];
787
+ } else {
788
+ listeners[type] = filtered;
789
+ }
790
+ }
791
+ };
792
+
793
+ function Event(type) {
794
+ this.type = type;
795
+ this.target = undefined;
796
+ }
797
+
798
+ function MessageEvent(type, options) {
799
+ Event.call(this, type);
800
+ this.data = options.data;
801
+ this.lastEventId = options.lastEventId;
802
+ }
803
+
804
+ MessageEvent.prototype = Object.create(Event.prototype);
805
+
806
+ function ConnectionEvent(type, options) {
807
+ Event.call(this, type);
808
+ this.status = options.status;
809
+ this.statusText = options.statusText;
810
+ this.headers = options.headers;
811
+ }
812
+
813
+ ConnectionEvent.prototype = Object.create(Event.prototype);
814
+
815
+ function ErrorEvent(type, options) {
816
+ Event.call(this, type);
817
+ this.error = options.error;
818
+ }
819
+
820
+ ErrorEvent.prototype = Object.create(Event.prototype);
821
+
822
+ var WAITING = -1;
823
+ var CONNECTING = 0;
824
+ var OPEN = 1;
825
+ var CLOSED = 2;
826
+
827
+ var AFTER_CR = -1;
828
+ var FIELD_START = 0;
829
+ var FIELD = 1;
830
+ var VALUE_START = 2;
831
+ var VALUE = 3;
832
+
833
+ var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
834
+
835
+ var MINIMUM_DURATION = 1000;
836
+ var MAXIMUM_DURATION = 18000000;
837
+
838
+ var parseDuration = function (value, def) {
839
+ var n = value == null ? def : parseInt(value, 10);
840
+ if (n !== n) {
841
+ n = def;
842
+ }
843
+ return clampDuration(n);
844
+ };
845
+ var clampDuration = function (n) {
846
+ return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
847
+ };
848
+
849
+ var fire = function (that, f, event) {
850
+ try {
851
+ if (typeof f === "function") {
852
+ f.call(that, event);
853
+ }
854
+ } catch (e) {
855
+ throwError(e);
856
+ }
857
+ };
858
+
859
+ function EventSourcePolyfill(url, options) {
860
+ EventTarget.call(this);
861
+ options = options || {};
862
+
863
+ this.onopen = undefined;
864
+ this.onmessage = undefined;
865
+ this.onerror = undefined;
866
+
867
+ this.url = undefined;
868
+ this.readyState = undefined;
869
+ this.withCredentials = undefined;
870
+ this.headers = undefined;
871
+
872
+ this._close = undefined;
873
+
874
+ start(this, url, options);
875
+ }
876
+
877
+ function getBestXHRTransport() {
878
+ return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
879
+ ? new XMLHttpRequest()
880
+ : new XDomainRequest();
881
+ }
882
+
883
+ var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
884
+
885
+ function start(es, url, options) {
886
+ url = String(url);
887
+ var withCredentials = Boolean(options.withCredentials);
888
+ var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
889
+
890
+ var initialRetry = clampDuration(1000);
891
+ var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
892
+
893
+ var lastEventId = "";
894
+ var retry = initialRetry;
895
+ var wasActivity = false;
896
+ var textLength = 0;
897
+ var headers = options.headers || {};
898
+ var TransportOption = options.Transport;
899
+ var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
900
+ var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
901
+ var abortController = undefined;
902
+ var timeout = 0;
903
+ var currentState = WAITING;
904
+ var dataBuffer = "";
905
+ var lastEventIdBuffer = "";
906
+ var eventTypeBuffer = "";
907
+
908
+ var textBuffer = "";
909
+ var state = FIELD_START;
910
+ var fieldStart = 0;
911
+ var valueStart = 0;
912
+
913
+ var onStart = function (status, statusText, contentType, headers) {
914
+ if (currentState === CONNECTING) {
915
+ if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
916
+ currentState = OPEN;
917
+ wasActivity = Date.now();
918
+ retry = initialRetry;
919
+ es.readyState = OPEN;
920
+ var event = new ConnectionEvent("open", {
921
+ status: status,
922
+ statusText: statusText,
923
+ headers: headers
924
+ });
925
+ es.dispatchEvent(event);
926
+ fire(es, es.onopen, event);
927
+ } else {
928
+ var message = "";
929
+ if (status !== 200) {
930
+ if (statusText) {
931
+ statusText = statusText.replace(/\s+/g, " ");
932
+ }
933
+ message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
934
+ } else {
935
+ message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
936
+ }
937
+ close();
938
+ var event = new ConnectionEvent("error", {
939
+ status: status,
940
+ statusText: statusText,
941
+ headers: headers
942
+ });
943
+ es.dispatchEvent(event);
944
+ fire(es, es.onerror, event);
945
+ console.error(message);
946
+ }
947
+ }
948
+ };
949
+
950
+ var onProgress = function (textChunk) {
951
+ if (currentState === OPEN) {
952
+ var n = -1;
953
+ for (var i = 0; i < textChunk.length; i += 1) {
954
+ var c = textChunk.charCodeAt(i);
955
+ if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
956
+ n = i;
957
+ }
958
+ }
959
+ var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
960
+ textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
961
+ if (textChunk !== "") {
962
+ wasActivity = Date.now();
963
+ textLength += textChunk.length;
964
+ }
965
+ for (var position = 0; position < chunk.length; position += 1) {
966
+ var c = chunk.charCodeAt(position);
967
+ if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
968
+ state = FIELD_START;
969
+ } else {
970
+ if (state === AFTER_CR) {
971
+ state = FIELD_START;
972
+ }
973
+ if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
974
+ if (state !== FIELD_START) {
975
+ if (state === FIELD) {
976
+ valueStart = position + 1;
977
+ }
978
+ var field = chunk.slice(fieldStart, valueStart - 1);
979
+ var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
980
+ if (field === "data") {
981
+ dataBuffer += "\n";
982
+ dataBuffer += value;
983
+ } else if (field === "id") {
984
+ lastEventIdBuffer = value;
985
+ } else if (field === "event") {
986
+ eventTypeBuffer = value;
987
+ } else if (field === "retry") {
988
+ initialRetry = parseDuration(value, initialRetry);
989
+ retry = initialRetry;
990
+ } else if (field === "heartbeatTimeout") {
991
+ heartbeatTimeout = parseDuration(value, heartbeatTimeout);
992
+ if (timeout !== 0) {
993
+ clearTimeout(timeout);
994
+ timeout = setTimeout(function () {
995
+ onTimeout();
996
+ }, heartbeatTimeout);
997
+ }
998
+ }
999
+ }
1000
+ if (state === FIELD_START) {
1001
+ if (dataBuffer !== "") {
1002
+ lastEventId = lastEventIdBuffer;
1003
+ if (eventTypeBuffer === "") {
1004
+ eventTypeBuffer = "message";
1005
+ }
1006
+ var event = new MessageEvent(eventTypeBuffer, {
1007
+ data: dataBuffer.slice(1),
1008
+ lastEventId: lastEventIdBuffer
1009
+ });
1010
+ es.dispatchEvent(event);
1011
+ if (eventTypeBuffer === "open") {
1012
+ fire(es, es.onopen, event);
1013
+ } else if (eventTypeBuffer === "message") {
1014
+ fire(es, es.onmessage, event);
1015
+ } else if (eventTypeBuffer === "error") {
1016
+ fire(es, es.onerror, event);
1017
+ }
1018
+ if (currentState === CLOSED) {
1019
+ return;
1020
+ }
1021
+ }
1022
+ dataBuffer = "";
1023
+ eventTypeBuffer = "";
1024
+ }
1025
+ state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
1026
+ } else {
1027
+ if (state === FIELD_START) {
1028
+ fieldStart = position;
1029
+ state = FIELD;
1030
+ }
1031
+ if (state === FIELD) {
1032
+ if (c === ":".charCodeAt(0)) {
1033
+ valueStart = position + 1;
1034
+ state = VALUE_START;
1035
+ }
1036
+ } else if (state === VALUE_START) {
1037
+ state = VALUE;
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ };
1044
+
1045
+ var onFinish = function (error) {
1046
+ if (currentState === OPEN || currentState === CONNECTING) {
1047
+ currentState = WAITING;
1048
+ if (timeout !== 0) {
1049
+ clearTimeout(timeout);
1050
+ timeout = 0;
1051
+ }
1052
+ timeout = setTimeout(function () {
1053
+ onTimeout();
1054
+ }, retry);
1055
+ retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
1056
+
1057
+ es.readyState = CONNECTING;
1058
+ var event = new ErrorEvent("error", {error: error});
1059
+ es.dispatchEvent(event);
1060
+ fire(es, es.onerror, event);
1061
+ if (error != undefined) {
1062
+ console.error(error);
1063
+ }
1064
+ }
1065
+ };
1066
+
1067
+ var close = function () {
1068
+ currentState = CLOSED;
1069
+ if (abortController != undefined) {
1070
+ abortController.abort();
1071
+ abortController = undefined;
1072
+ }
1073
+ if (timeout !== 0) {
1074
+ clearTimeout(timeout);
1075
+ timeout = 0;
1076
+ }
1077
+ es.readyState = CLOSED;
1078
+ };
1079
+
1080
+ var onTimeout = function () {
1081
+ timeout = 0;
1082
+
1083
+ if (currentState !== WAITING) {
1084
+ if (!wasActivity && abortController != undefined) {
1085
+ onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
1086
+ if (abortController != undefined) {
1087
+ abortController.abort();
1088
+ abortController = undefined;
1089
+ }
1090
+ } else {
1091
+ var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
1092
+ wasActivity = false;
1093
+ timeout = setTimeout(function () {
1094
+ onTimeout();
1095
+ }, nextHeartbeat);
1096
+ }
1097
+ return;
1098
+ }
1099
+
1100
+ wasActivity = false;
1101
+ textLength = 0;
1102
+ timeout = setTimeout(function () {
1103
+ onTimeout();
1104
+ }, heartbeatTimeout);
1105
+
1106
+ currentState = CONNECTING;
1107
+ dataBuffer = "";
1108
+ eventTypeBuffer = "";
1109
+ lastEventIdBuffer = lastEventId;
1110
+ textBuffer = "";
1111
+ fieldStart = 0;
1112
+ valueStart = 0;
1113
+ state = FIELD_START;
1114
+
1115
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
1116
+ // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
1117
+ var requestURL = url;
1118
+ if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
1119
+ if (lastEventId !== "") {
1120
+ // Remove the lastEventId parameter if it's already part of the request URL.
1121
+ var i = url.indexOf("?");
1122
+ requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
1123
+ return paramName === lastEventIdQueryParameterName ? '' : p;
1124
+ });
1125
+ // Append the current lastEventId to the request URL.
1126
+ requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
1127
+ }
1128
+ }
1129
+ var withCredentials = es.withCredentials;
1130
+ var requestHeaders = {};
1131
+ requestHeaders["Accept"] = "text/event-stream";
1132
+ var headers = es.headers;
1133
+ if (headers != undefined) {
1134
+ for (var name in headers) {
1135
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
1136
+ requestHeaders[name] = headers[name];
1137
+ }
1138
+ }
1139
+ }
1140
+ try {
1141
+ abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
1142
+ } catch (error) {
1143
+ close();
1144
+ throw error;
1145
+ }
1146
+ };
1147
+
1148
+ es.url = url;
1149
+ es.readyState = CONNECTING;
1150
+ es.withCredentials = withCredentials;
1151
+ es.headers = headers;
1152
+ es._close = close;
1153
+
1154
+ onTimeout();
1155
+ }
1156
+
1157
+ EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
1158
+ EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
1159
+ EventSourcePolyfill.prototype.OPEN = OPEN;
1160
+ EventSourcePolyfill.prototype.CLOSED = CLOSED;
1161
+ EventSourcePolyfill.prototype.close = function () {
1162
+ this._close();
1163
+ };
1164
+
1165
+ EventSourcePolyfill.CONNECTING = CONNECTING;
1166
+ EventSourcePolyfill.OPEN = OPEN;
1167
+ EventSourcePolyfill.CLOSED = CLOSED;
1168
+ EventSourcePolyfill.prototype.withCredentials = undefined;
1169
+
1170
+ var R = NativeEventSource;
1171
+ if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
1172
+ // Why replace a native EventSource ?
1173
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
1174
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
1175
+ // https://code.google.com/p/chromium/issues/detail?id=260144
1176
+ // https://code.google.com/p/chromium/issues/detail?id=225654
1177
+ // ...
1178
+ R = EventSourcePolyfill;
1179
+ }
1180
+
1181
+ (function (factory) {
1182
+ {
1183
+ var v = factory(exports);
1184
+ if (v !== undefined) module.exports = v;
1185
+ }
1186
+ })(function (exports) {
1187
+ exports.EventSourcePolyfill = EventSourcePolyfill;
1188
+ exports.NativeEventSource = NativeEventSource;
1189
+ exports.EventSource = R;
1190
+ });
1191
+ }(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
1192
+ });
1193
+
1194
+ const casinoTournamentListCss = ":host{display:block}.TournamentList{display:flex;flex-direction:column;width:1200px;margin:0 auto;background-color:#1a2c38;padding:12px}.TournamentList.CardMode{width:1040px}.TournamentList.Mobile{width:100%;padding:12px 0}.States{display:flex;gap:10px;justify-content:center;margin:16px}.State{padding:12px;font-size:12px;font-weight:800;color:var(--emfe-w-color-white, #FFFFFF);cursor:pointer}.State.active{border-bottom:2px solid var(--emfe-w-tournament-color-primary, #0072ed)}.Tournaments{display:flex;flex-wrap:wrap;gap:10px}.Tournaments.Mobile{width:100%;box-sizing:border-box;padding:12px}.TournamentCard{width:340px;height:180px}.TournamentCard.Mobile{width:100%}.TournamentCard casino-tournament-banner{height:180px}.TournamentCard casino-tournament-banner::part(TournamentBanner){border-radius:8px}.Tournament{width:390px}.Tournament casino-tournament-banner{height:150px}.Loading,.NoTournaments{color:var(--emfe-w-color-white, #FFFFFF)}.Loading.Mobile,.NoTournaments.Mobile{padding-left:12px}.CenterButton{padding-top:12px;width:100%;display:flex;justify-content:center}.ShowMoreButton{background:#1a2c38;display:flex;width:185px;justify-content:center;align-items:center;border-radius:2px;border:1px solid var(--emfe-w-color-white, #FFFFFF);color:var(--emfe-w-color-white, #FFFFFF);padding:7px;text-transform:uppercase;cursor:pointer}";
1195
+
1196
+ const CasinoTournamentList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
1197
+ constructor() {
1198
+ super();
1199
+ this.__registerHost();
1200
+ this.__attachShadow();
1201
+ /**
1202
+ * NWA parameter tournaments offet
1203
+ */
1204
+ this.offset = 0;
1205
+ /**
1206
+ * NWA parameter tournaments limit
1207
+ */
1208
+ this.limit = 6;
1209
+ /**
1210
+ * NWA parameter show anonymous tournament
1211
+ */
1212
+ this.showAnonymous = false;
1213
+ /**
1214
+ * Tournament states
1215
+ */
1216
+ this.state = 'All,Ongoing,Upcoming,Expired';
1217
+ /**
1218
+ * Real time update
1219
+ */
1220
+ this.updateTournaments = true;
1221
+ /**
1222
+ * Event for login button
1223
+ */
1224
+ this.loginEvent = 'OpenLoginRegisterModal';
1225
+ /**
1226
+ * Event for register button
1227
+ */
1228
+ this.registerEvent = 'OpenLoginRegisterModal';
1229
+ /**
1230
+ * Display as card
1231
+ */
1232
+ this.cardMode = false;
1233
+ /**
1234
+ * Show read more button
1235
+ */
1236
+ this.showReadMore = false;
1237
+ /**
1238
+ * Client custom styling via inline styles
1239
+ */
1240
+ this.clientStyling = '';
1241
+ /**
1242
+ * Client custom styling via url
1243
+ */
1244
+ this.clientStylingUrl = '';
1245
+ /**
1246
+ * Translations via URL
1247
+ */
1248
+ this.translationUrl = '';
1249
+ this.limitStylingAppends = false;
1250
+ this.tournaments = [];
1251
+ this.currentState = 'All';
1252
+ this.isLoading = false;
1253
+ this.tournamentsShown = 0;
1254
+ this.allTournamentsShown = false;
1255
+ }
1256
+ getTournamentInfo(offset, limit) {
1257
+ let url = new URL(this.endpoint + `/tournaments`);
1258
+ let reqHeaders = new Headers();
1259
+ if (this.session) {
1260
+ reqHeaders.append('X-SessionId', this.session);
1261
+ }
1262
+ const filterOptions = {
1263
+ StartTimeAfter: this.getStartTimeAfter(),
1264
+ };
1265
+ if (!this.session && this.showAnonymous == false) {
1266
+ filterOptions.tags = 'no-role-set';
1267
+ }
1268
+ if (this.currentState && this.currentState != 'All') {
1269
+ filterOptions.state = this.matchStatus(this.currentState);
1270
+ }
1271
+ const filter = Object.keys(filterOptions).map(k => `${k}=${filterOptions[k]}`).join(',');
1272
+ url.searchParams.append('filter', filter);
1273
+ url.searchParams.append('platform', getDevice());
1274
+ url.searchParams.append('language', this.language);
1275
+ url.searchParams.append('fields', 'id,nameOrTitle,termsUrl,thumbnail,startTime,endTime,closeTime,playerEnrolled');
1276
+ url.searchParams.append('pagination', `offset=${offset},limit=${limit}`);
1277
+ url.searchParams.append('sortField', 'StartTime');
1278
+ url.searchParams.append('sortOrder', this.sortOrder || 'desc');
1279
+ if (this.sortType) {
1280
+ url.searchParams.append('sortType', this.sortType);
1281
+ }
1282
+ let requestOptions = {
1283
+ method: 'GET',
1284
+ headers: reqHeaders,
1285
+ cache: 'no-cache'
1286
+ };
1287
+ this.isLoading = true;
1288
+ fetch(url.href, requestOptions).then((res) => res.json())
1289
+ .then((res) => {
1290
+ this.tournaments = this.tournaments.concat(res.items);
1291
+ this.tournamentsShown += res.items.length;
1292
+ if (this.tournamentsShown >= res.total) {
1293
+ this.allTournamentsShown = true;
1294
+ }
1295
+ if (this.updateTournaments) {
1296
+ url.searchParams.set('pagination', `offset=0,limit=${this.tournamentsShown}`);
1297
+ let endpointURL = `${this.endpoint}/tournaments/updates?${url.searchParams.toString()}`;
1298
+ this.startUpdate(endpointURL, { headers: { 'accept': 'text/event-stream', 'X-SessionId': this.session } });
1299
+ }
1300
+ }).catch((err) => {
1301
+ throw new Error(err);
1302
+ }).finally(() => {
1303
+ this.isLoading = false;
1304
+ });
1305
+ }
1306
+ createImagePlaceHolder(width, height) {
1307
+ const canvas = document.createElement('canvas');
1308
+ canvas.width = width;
1309
+ canvas.height = height;
1310
+ const ctx = canvas.getContext('2d');
1311
+ ctx.fillStyle = 'rgb(0, 0, 0)';
1312
+ ctx.fillRect(0, 0, width, height);
1313
+ const img = new Image(width, height);
1314
+ img.src = canvas.toDataURL();
1315
+ return img.src;
1316
+ }
1317
+ componentDidRender() {
1318
+ if (!this.limitStylingAppends && this.host) {
1319
+ if (this.clientStyling)
1320
+ this.setClientStyling();
1321
+ if (this.clientStylingUrl)
1322
+ this.setClientStylingURL();
1323
+ this.limitStylingAppends = true;
1324
+ }
1325
+ }
1326
+ componentWillLoad() {
1327
+ if (this.state) {
1328
+ this.states = this.state.split(',');
1329
+ }
1330
+ if (this.endpoint) {
1331
+ this.getTournamentInfo(this.offset, this.limit);
1332
+ }
1333
+ }
1334
+ setClientStyling() {
1335
+ let sheet = document.createElement('style');
1336
+ sheet.innerHTML = this.clientStyling;
1337
+ this.host.shadowRoot.prepend(sheet);
1338
+ }
1339
+ setClientStylingURL() {
1340
+ let url = new URL(this.clientStylingUrl);
1341
+ let cssFile = document.createElement('style');
1342
+ fetch(url.href)
1343
+ .then((res) => res.text())
1344
+ .then((data) => {
1345
+ cssFile.innerHTML = data;
1346
+ this.clientStyling = data;
1347
+ setTimeout(() => { this.host.shadowRoot.prepend(cssFile); }, 1);
1348
+ });
1349
+ }
1350
+ getStartTimeAfter() {
1351
+ const dateStartTimeAfter = new Date();
1352
+ if (this.startTimeAfter) {
1353
+ dateStartTimeAfter.setDate(dateStartTimeAfter.getDate() - Number(this.startTimeAfter));
1354
+ }
1355
+ else {
1356
+ dateStartTimeAfter.setMonth(dateStartTimeAfter.getMonth() - 12);
1357
+ }
1358
+ return dateStartTimeAfter.toISOString().substring(0, 10);
1359
+ }
1360
+ onStateChange(state) {
1361
+ if (this.isLoading == false) {
1362
+ this.tournaments = [];
1363
+ this.tournamentsShown = 0;
1364
+ this.allTournamentsShown = false;
1365
+ this.sseConnection.removeEventListener('message', this.updateHandler);
1366
+ this.currentState = state;
1367
+ this.getTournamentInfo(this.offset, this.limit);
1368
+ }
1369
+ }
1370
+ showMoreAction() {
1371
+ this.getTournamentInfo(this.offset + this.tournamentsShown, this.limit);
1372
+ }
1373
+ matchStatus(status) {
1374
+ if (status == 'Upcoming') {
1375
+ return 'Unstarted';
1376
+ }
1377
+ if (status == 'Ongoing') {
1378
+ return 'Running';
1379
+ }
1380
+ return 'Closing|Closed';
1381
+ }
1382
+ startUpdate(updateUrl, updateOptions) {
1383
+ if (this.sseConnection) {
1384
+ this.sseConnection.close();
1385
+ }
1386
+ this.sseConnection = new eventsource.EventSourcePolyfill(updateUrl, updateOptions);
1387
+ this.sseConnection.removeEventListener('message', this.updateHandler);
1388
+ this.sseConnection.addEventListener('message', this.updateHandler.bind(this));
1389
+ }
1390
+ updateHandler(message) {
1391
+ if (!message.data) {
1392
+ return;
1393
+ }
1394
+ let data = JSON.parse(message.data);
1395
+ if (data.messageType == 'LeaderBoardUpdate') {
1396
+ this.updateView(data);
1397
+ }
1398
+ }
1399
+ updateView(data) {
1400
+ this.tournaments = data.items;
1401
+ }
1402
+ connectedCallback() {
1403
+ if (this.translationUrl) {
1404
+ getTranslations(this.translationUrl);
1405
+ }
1406
+ }
1407
+ render() {
1408
+ return h("div", { class: `TournamentList ${this.cardMode ? 'CardMode' : ''} ${isMobile() ? 'Mobile' : ''}` }, this.states && h("div", { class: "States" }, this.states.map(state => {
1409
+ return h("div", { onClick: () => this.onStateChange.bind(this)(state), class: `State ${this.currentState == state ? 'active' : ''}` }, state);
1410
+ })), !this.isLoading && (!this.tournaments || this.tournaments.length == 0) && h("div", { class: `NoTournaments ${isMobile() ? 'Mobile' : ''}` }, translate('noTournaments', this.language)), this.tournaments && h("div", { class: `Tournaments ${isMobile() ? 'Mobile' : ''}` }, this.tournaments.map(item => {
1411
+ if (this.cardMode) {
1412
+ return h("div", { class: `TournamentCard ${isMobile() ? 'Mobile' : ''}` }, h("casino-tournament-banner", { "name-or-title": item.nameOrTitle, "tournament-id": item.id, state: item.state, enrolled: item.playerEnrolled, "start-time": item.startTime, "end-time": item.endTime, thumbnail: item.thumbnail ? item.thumbnail : this.createImagePlaceHolder(320, 180), "show-date": "false", "show-check": "true", "show-calendar": "true", "show-running-date": "true", "short-start": "true", "show-read-more": this.showReadMore, "card-mode": this.cardMode, language: this.language, endpoint: this.endpoint, loginEvent: this.loginEvent, session: this.session, registerEvent: this.registerEvent, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl }));
1413
+ }
1414
+ else {
1415
+ return h("div", { class: "Tournament" }, h("casino-tournament-banner", { "name-or-title": item.nameOrTitle, "tournament-id": item.id, state: item.state, enrolled: item.playerEnrolled, "start-time": item.startTime, thumbnail: item.thumbnail ? item.thumbnail : this.createImagePlaceHolder(320, 180), "show-date": "false", "show-check": "true", "show-calendar": "true", "short-start": "true", "card-mode": this.cardMode, language: this.language, endpoint: this.endpoint, session: this.session, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl }), h("casino-tournament-info", { "name-or-title": item.nameOrTitle, "tournament-id": item.id, "start-time": item.startTime, "end-time": item.endTime, "score-criteria": item.scoreCriteria, "min-bet-count": item.minBetCount, enrolled: item.playerEnrolled, align: "left", "see-games": "true", "show-button": "true", loginEvent: this.loginEvent, registerEvent: this.registerEvent, "show-read-more": this.showReadMore, language: this.language, endpoint: this.endpoint, session: this.session, "client-styling": this.clientStyling, "client-styling-url": this.clientStylingUrl }));
1416
+ }
1417
+ }), this.isLoading &&
1418
+ h("p", { class: "Loading" }, translate('loading', this.language)), !this.isLoading && !this.allTournamentsShown &&
1419
+ h("div", { class: "CenterButton", part: "CenterButton" }, h("button", { class: "ShowMoreButton", part: "ShowMoreButton", onClick: () => this.showMoreAction(), title: "Show More" }, translate('showMore', this.language)))));
1420
+ }
1421
+ get host() { return this; }
1422
+ static get style() { return casinoTournamentListCss; }
1423
+ }, [1, "casino-tournament-list", {
1424
+ "endpoint": [1],
1425
+ "language": [1],
1426
+ "session": [1],
1427
+ "sortType": [1, "sort-type"],
1428
+ "sortOrder": [1, "sort-order"],
1429
+ "offset": [2],
1430
+ "limit": [2],
1431
+ "showAnonymous": [4, "show-anonymous"],
1432
+ "state": [1],
1433
+ "startTimeAfter": [1, "start-time-after"],
1434
+ "updateTournaments": [4, "update-tournaments"],
1435
+ "loginEvent": [1, "login-event"],
1436
+ "registerEvent": [1, "register-event"],
1437
+ "cardMode": [4, "card-mode"],
1438
+ "showReadMore": [4, "show-read-more"],
1439
+ "clientStyling": [1, "client-styling"],
1440
+ "clientStylingUrl": [1, "client-styling-url"],
1441
+ "translationUrl": [1, "translation-url"],
1442
+ "limitStylingAppends": [32],
1443
+ "tournaments": [32],
1444
+ "states": [32],
1445
+ "currentState": [32],
1446
+ "isLoading": [32],
1447
+ "tournamentsShown": [32],
1448
+ "allTournamentsShown": [32],
1449
+ "sseConnection": [32]
1450
+ }]);
1451
+ function defineCustomElement$1() {
1452
+ if (typeof customElements === "undefined") {
1453
+ return;
1454
+ }
1455
+ const components = ["casino-tournament-list", "casino-tournament-banner", "casino-tournament-buttons", "casino-tournament-duration", "casino-tournament-info", "casino-tournament-prizes"];
1456
+ components.forEach(tagName => { switch (tagName) {
1457
+ case "casino-tournament-list":
1458
+ if (!customElements.get(tagName)) {
1459
+ customElements.define(tagName, CasinoTournamentList$1);
1460
+ }
1461
+ break;
1462
+ case "casino-tournament-banner":
1463
+ if (!customElements.get(tagName)) {
1464
+ defineCustomElement$6();
1465
+ }
1466
+ break;
1467
+ case "casino-tournament-buttons":
1468
+ if (!customElements.get(tagName)) {
1469
+ defineCustomElement$5();
1470
+ }
1471
+ break;
1472
+ case "casino-tournament-duration":
1473
+ if (!customElements.get(tagName)) {
1474
+ defineCustomElement$4();
1475
+ }
1476
+ break;
1477
+ case "casino-tournament-info":
1478
+ if (!customElements.get(tagName)) {
1479
+ defineCustomElement$3();
1480
+ }
1481
+ break;
1482
+ case "casino-tournament-prizes":
1483
+ if (!customElements.get(tagName)) {
1484
+ defineCustomElement$2();
1485
+ }
1486
+ break;
1487
+ } });
1488
+ }
1489
+
1490
+ const CasinoTournamentList = CasinoTournamentList$1;
1491
+ const defineCustomElement = defineCustomElement$1;
1492
+
1493
+ export { CasinoTournamentList, defineCustomElement };