@everymatrix/casino-tournaments-ingame-table 0.0.1

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 (59) hide show
  1. package/dist/casino-tournaments-ingame-table/app-globals-0f993ce5.js +1 -0
  2. package/dist/casino-tournaments-ingame-table/casino-tournaments-ingame-table-cea9e05e.js +7 -0
  3. package/dist/casino-tournaments-ingame-table/casino-tournaments-ingame-table.entry.js +1 -0
  4. package/dist/casino-tournaments-ingame-table/casino-tournaments-ingame-table.esm.js +1 -0
  5. package/dist/casino-tournaments-ingame-table/index-7421f3cc.js +2 -0
  6. package/dist/casino-tournaments-ingame-table/index.esm.js +1 -0
  7. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  8. package/dist/cjs/casino-tournaments-ingame-table-58ce40fc.js +1667 -0
  9. package/dist/cjs/casino-tournaments-ingame-table.cjs.entry.js +10 -0
  10. package/dist/cjs/casino-tournaments-ingame-table.cjs.js +25 -0
  11. package/dist/cjs/index-3f69085c.js +1217 -0
  12. package/dist/cjs/index.cjs.js +10 -0
  13. package/dist/cjs/loader.cjs.js +15 -0
  14. package/dist/collection/collection-manifest.json +12 -0
  15. package/dist/collection/components/casino-tournaments-ingame-table/casino-tournaments-ingame-table.css +104 -0
  16. package/dist/collection/components/casino-tournaments-ingame-table/casino-tournaments-ingame-table.js +700 -0
  17. package/dist/collection/components/casino-tournaments-ingame-table/index.js +1 -0
  18. package/dist/collection/index.js +1 -0
  19. package/dist/collection/utils/leaderboard.js +1 -0
  20. package/dist/collection/utils/locale.utils.js +39 -0
  21. package/dist/collection/utils/utils.js +16 -0
  22. package/dist/esm/app-globals-0f993ce5.js +3 -0
  23. package/dist/esm/casino-tournaments-ingame-table-cea9e05e.js +1665 -0
  24. package/dist/esm/casino-tournaments-ingame-table.entry.js +2 -0
  25. package/dist/esm/casino-tournaments-ingame-table.js +20 -0
  26. package/dist/esm/index-7421f3cc.js +1190 -0
  27. package/dist/esm/index.js +2 -0
  28. package/dist/esm/loader.js +11 -0
  29. package/dist/index.cjs.js +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/stencil.config.dev.js +19 -0
  32. package/dist/stencil.config.js +19 -0
  33. package/dist/storybook/main.js +43 -0
  34. package/dist/storybook/preview.js +9 -0
  35. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/libs/common/src/storybook/storybook-utils.d.ts +39 -0
  36. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/packages/stencil/casino-tournaments-ingame-table/stencil.config.d.ts +2 -0
  37. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/packages/stencil/casino-tournaments-ingame-table/stencil.config.dev.d.ts +2 -0
  38. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/packages/stencil/casino-tournaments-ingame-table/storybook/main.d.ts +3 -0
  39. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/packages/stencil/casino-tournaments-ingame-table/storybook/preview.d.ts +70 -0
  40. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/tools/plugins/index.d.ts +4 -0
  41. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/tools/plugins/lazy-load-chunk-plugin.d.ts +12 -0
  42. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/tools/plugins/stencil-clean-deps-plugin.d.ts +5 -0
  43. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/tools/plugins/vite-chunk-plugin.d.ts +6 -0
  44. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/casino-tournaments-ingame-table/.stencil/tools/plugins/vite-clean-deps-plugin.d.ts +4 -0
  45. package/dist/types/components/casino-tournaments-ingame-table/casino-tournaments-ingame-table.d.ts +88 -0
  46. package/dist/types/components/casino-tournaments-ingame-table/index.d.ts +1 -0
  47. package/dist/types/components.d.ts +73 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/stencil-public-runtime.d.ts +1674 -0
  50. package/dist/types/utils/leaderboard.d.ts +15 -0
  51. package/dist/types/utils/locale.utils.d.ts +2 -0
  52. package/dist/types/utils/utils.d.ts +2 -0
  53. package/loader/cdn.js +1 -0
  54. package/loader/index.cjs.js +1 -0
  55. package/loader/index.d.ts +24 -0
  56. package/loader/index.es2017.js +1 -0
  57. package/loader/index.js +2 -0
  58. package/loader/package.json +11 -0
  59. package/package.json +27 -0
@@ -0,0 +1,1667 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index-3f69085c.js');
4
+
5
+ const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
6
+
7
+ /**
8
+ * @name setClientStyling
9
+ * @description Method used to create and append to the passed element of the widget a style element with the content received
10
+ * @param {HTMLElement} stylingContainer The reference element of the widget
11
+ * @param {string} clientStyling The style content
12
+ */
13
+ function setClientStyling(stylingContainer, clientStyling) {
14
+ if (stylingContainer) {
15
+ const sheet = document.createElement('style');
16
+ sheet.innerHTML = clientStyling;
17
+ stylingContainer.appendChild(sheet);
18
+ }
19
+ }
20
+
21
+ /**
22
+ * @name setClientStylingURL
23
+ * @description Method used to create and append to the passed element of the widget a style element with the content fetched from a given URL
24
+ * @param {HTMLElement} stylingContainer The reference element of the widget
25
+ * @param {string} clientStylingUrl The URL of the style content
26
+ */
27
+ function setClientStylingURL(stylingContainer, clientStylingUrl) {
28
+ if (!stylingContainer || !clientStylingUrl) return;
29
+
30
+ const url = new URL(clientStylingUrl);
31
+
32
+ fetch(url.href)
33
+ .then((res) => res.text())
34
+ .then((data) => {
35
+ const cssFile = document.createElement('style');
36
+ cssFile.innerHTML = data;
37
+ if (stylingContainer) {
38
+ stylingContainer.appendChild(cssFile);
39
+ }
40
+ })
41
+ .catch((err) => {
42
+ console.error('There was an error while trying to load client styling from URL', err);
43
+ });
44
+ }
45
+
46
+ /**
47
+ * @name setStreamLibrary
48
+ * @description Method used to create and append to the passed element of the widget a style element with content fetched from the MessageBus
49
+ * @param {HTMLElement} stylingContainer The highest element of the widget
50
+ * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
51
+ * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
52
+ * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
53
+ */
54
+ function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
55
+ if (!window.emMessageBus) return;
56
+
57
+ const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
58
+
59
+ if (!supportAdoptStyle || !useAdoptedStyleSheets) {
60
+ subscription = getStyleTagSubscription(stylingContainer, domain);
61
+
62
+ return subscription;
63
+ }
64
+
65
+ if (!window[StyleCacheKey]) {
66
+ window[StyleCacheKey] = {};
67
+ }
68
+ subscription = getAdoptStyleSubscription(stylingContainer, domain);
69
+
70
+ const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
71
+ const wrappedUnsubscribe = () => {
72
+ if (window[StyleCacheKey][domain]) {
73
+ const cachedObject = window[StyleCacheKey][domain];
74
+ cachedObject.refCount > 1
75
+ ? (cachedObject.refCount = cachedObject.refCount - 1)
76
+ : delete window[StyleCacheKey][domain];
77
+ }
78
+
79
+ originalUnsubscribe();
80
+ };
81
+ subscription.unsubscribe = wrappedUnsubscribe;
82
+
83
+ return subscription;
84
+ }
85
+
86
+ function getStyleTagSubscription(stylingContainer, domain) {
87
+ const sheet = document.createElement('style');
88
+
89
+ return window.emMessageBus.subscribe(domain, (data) => {
90
+ if (stylingContainer) {
91
+ sheet.innerHTML = data;
92
+ stylingContainer.appendChild(sheet);
93
+ }
94
+ });
95
+ }
96
+
97
+ function getAdoptStyleSubscription(stylingContainer, domain) {
98
+ return window.emMessageBus.subscribe(domain, (data) => {
99
+ if (!stylingContainer) return;
100
+
101
+ const shadowRoot = stylingContainer.getRootNode();
102
+ const cacheStyleObject = window[StyleCacheKey];
103
+ let cachedStyle = cacheStyleObject[domain] && cacheStyleObject[domain].sheet;
104
+
105
+ if (!cachedStyle) {
106
+ cachedStyle = new CSSStyleSheet();
107
+ cachedStyle.replaceSync(data);
108
+ cacheStyleObject[domain] = {
109
+ sheet: cachedStyle,
110
+ refCount: 1
111
+ };
112
+ } else {
113
+ cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
114
+ }
115
+
116
+ const currentSheets = shadowRoot.adoptedStyleSheets || [];
117
+ if (!currentSheets.includes(cachedStyle)) {
118
+ shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
119
+ }
120
+ });
121
+ }
122
+
123
+ const DEFAULT_LANGUAGE = 'en';
124
+ const TRANSLATIONS = {
125
+ en: {
126
+ you: 'You',
127
+ loading: 'Loading, please wait ...',
128
+ leaderboard: 'Leaderboard',
129
+ "nowinners": "No winners for the time being. Be one of them!",
130
+ noLeaderboard: 'No Leaderboard yet',
131
+ positionsWillShow: 'Player positions will appear here once scores are recorded.',
132
+ }
133
+ };
134
+ const translate = (key, customLang, values) => {
135
+ const lang = customLang;
136
+ let translation = TRANSLATIONS[(lang !== undefined) && (lang in TRANSLATIONS) ? lang : DEFAULT_LANGUAGE][key];
137
+ if (values !== undefined) {
138
+ for (const [key, value] of Object.entries(values.values)) {
139
+ const regex = new RegExp(`{${key}}`, 'g');
140
+ translation = translation.replace(regex, value);
141
+ }
142
+ }
143
+ return translation;
144
+ };
145
+
146
+ const getDevice = () => {
147
+ let userAgent = window.navigator.userAgent;
148
+ if (userAgent.toLowerCase().match(/android/i)) {
149
+ return 'Android';
150
+ }
151
+ if (userAgent.toLowerCase().match(/iphone/i)) {
152
+ return 'iPhone';
153
+ }
154
+ if (userAgent.toLowerCase().match(/ipad|ipod/i)) {
155
+ return 'iPad';
156
+ }
157
+ return 'PC';
158
+ };
159
+
160
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
161
+
162
+ var eventsource = {exports: {}};
163
+
164
+ /** @license
165
+ * eventsource.js
166
+ * Available under MIT License (MIT)
167
+ * https://github.com/Yaffle/EventSource/
168
+ */
169
+
170
+ (function (module, exports) {
171
+ /*jslint indent: 2, vars: true, plusplus: true */
172
+ /*global setTimeout, clearTimeout */
173
+
174
+ (function (global) {
175
+
176
+ var setTimeout = global.setTimeout;
177
+ var clearTimeout = global.clearTimeout;
178
+ var XMLHttpRequest = global.XMLHttpRequest;
179
+ var XDomainRequest = global.XDomainRequest;
180
+ var ActiveXObject = global.ActiveXObject;
181
+ var NativeEventSource = global.EventSource;
182
+
183
+ var document = global.document;
184
+ var Promise = global.Promise;
185
+ var fetch = global.fetch;
186
+ var Response = global.Response;
187
+ var TextDecoder = global.TextDecoder;
188
+ var TextEncoder = global.TextEncoder;
189
+ var AbortController = global.AbortController;
190
+
191
+ if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
192
+ document.readyState = "loading";
193
+ window.addEventListener("load", function (event) {
194
+ document.readyState = "complete";
195
+ }, false);
196
+ }
197
+
198
+ if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
199
+ XMLHttpRequest = function () {
200
+ return new ActiveXObject("Microsoft.XMLHTTP");
201
+ };
202
+ }
203
+
204
+ if (Object.create == undefined) {
205
+ Object.create = function (C) {
206
+ function F(){}
207
+ F.prototype = C;
208
+ return new F();
209
+ };
210
+ }
211
+
212
+ if (!Date.now) {
213
+ Date.now = function now() {
214
+ return new Date().getTime();
215
+ };
216
+ }
217
+
218
+ // see #118 (Promise#finally with polyfilled Promise)
219
+ // see #123 (data URLs crash Edge)
220
+ // see #125 (CSP violations)
221
+ // see pull/#138
222
+ // => No way to polyfill Promise#finally
223
+
224
+ if (AbortController == undefined) {
225
+ var originalFetch2 = fetch;
226
+ fetch = function (url, options) {
227
+ var signal = options.signal;
228
+ return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
229
+ var reader = response.body.getReader();
230
+ signal._reader = reader;
231
+ if (signal._aborted) {
232
+ signal._reader.cancel();
233
+ }
234
+ return {
235
+ status: response.status,
236
+ statusText: response.statusText,
237
+ headers: response.headers,
238
+ body: {
239
+ getReader: function () {
240
+ return reader;
241
+ }
242
+ }
243
+ };
244
+ });
245
+ };
246
+ AbortController = function () {
247
+ this.signal = {
248
+ _reader: null,
249
+ _aborted: false
250
+ };
251
+ this.abort = function () {
252
+ if (this.signal._reader != null) {
253
+ this.signal._reader.cancel();
254
+ }
255
+ this.signal._aborted = true;
256
+ };
257
+ };
258
+ }
259
+
260
+ function TextDecoderPolyfill() {
261
+ this.bitsNeeded = 0;
262
+ this.codePoint = 0;
263
+ }
264
+
265
+ TextDecoderPolyfill.prototype.decode = function (octets) {
266
+ function valid(codePoint, shift, octetsCount) {
267
+ if (octetsCount === 1) {
268
+ return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
269
+ }
270
+ if (octetsCount === 2) {
271
+ return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
272
+ }
273
+ if (octetsCount === 3) {
274
+ return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
275
+ }
276
+ throw new Error();
277
+ }
278
+ function octetsCount(bitsNeeded, codePoint) {
279
+ if (bitsNeeded === 6 * 1) {
280
+ return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
281
+ }
282
+ if (bitsNeeded === 6 * 2) {
283
+ return codePoint > 15 ? 3 : 2;
284
+ }
285
+ if (bitsNeeded === 6 * 3) {
286
+ return 3;
287
+ }
288
+ throw new Error();
289
+ }
290
+ var REPLACER = 0xFFFD;
291
+ var string = "";
292
+ var bitsNeeded = this.bitsNeeded;
293
+ var codePoint = this.codePoint;
294
+ for (var i = 0; i < octets.length; i += 1) {
295
+ var octet = octets[i];
296
+ if (bitsNeeded !== 0) {
297
+ if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
298
+ bitsNeeded = 0;
299
+ codePoint = REPLACER;
300
+ string += String.fromCharCode(codePoint);
301
+ }
302
+ }
303
+ if (bitsNeeded === 0) {
304
+ if (octet >= 0 && octet <= 127) {
305
+ bitsNeeded = 0;
306
+ codePoint = octet;
307
+ } else if (octet >= 192 && octet <= 223) {
308
+ bitsNeeded = 6 * 1;
309
+ codePoint = octet & 31;
310
+ } else if (octet >= 224 && octet <= 239) {
311
+ bitsNeeded = 6 * 2;
312
+ codePoint = octet & 15;
313
+ } else if (octet >= 240 && octet <= 247) {
314
+ bitsNeeded = 6 * 3;
315
+ codePoint = octet & 7;
316
+ } else {
317
+ bitsNeeded = 0;
318
+ codePoint = REPLACER;
319
+ }
320
+ if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
321
+ bitsNeeded = 0;
322
+ codePoint = REPLACER;
323
+ }
324
+ } else {
325
+ bitsNeeded -= 6;
326
+ codePoint = codePoint << 6 | octet & 63;
327
+ }
328
+ if (bitsNeeded === 0) {
329
+ if (codePoint <= 0xFFFF) {
330
+ string += String.fromCharCode(codePoint);
331
+ } else {
332
+ string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
333
+ string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
334
+ }
335
+ }
336
+ }
337
+ this.bitsNeeded = bitsNeeded;
338
+ this.codePoint = codePoint;
339
+ return string;
340
+ };
341
+
342
+ // Firefox < 38 throws an error with stream option
343
+ var supportsStreamOption = function () {
344
+ try {
345
+ return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
346
+ } catch (error) {
347
+ console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
348
+ }
349
+ return false;
350
+ };
351
+
352
+ // IE, Edge
353
+ if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
354
+ TextDecoder = TextDecoderPolyfill;
355
+ }
356
+
357
+ var k = function () {
358
+ };
359
+
360
+ function XHRWrapper(xhr) {
361
+ this.withCredentials = false;
362
+ this.readyState = 0;
363
+ this.status = 0;
364
+ this.statusText = "";
365
+ this.responseText = "";
366
+ this.onprogress = k;
367
+ this.onload = k;
368
+ this.onerror = k;
369
+ this.onreadystatechange = k;
370
+ this._contentType = "";
371
+ this._xhr = xhr;
372
+ this._sendTimeout = 0;
373
+ this._abort = k;
374
+ }
375
+
376
+ XHRWrapper.prototype.open = function (method, url) {
377
+ this._abort(true);
378
+
379
+ var that = this;
380
+ var xhr = this._xhr;
381
+ var state = 1;
382
+ var timeout = 0;
383
+
384
+ this._abort = function (silent) {
385
+ if (that._sendTimeout !== 0) {
386
+ clearTimeout(that._sendTimeout);
387
+ that._sendTimeout = 0;
388
+ }
389
+ if (state === 1 || state === 2 || state === 3) {
390
+ state = 4;
391
+ xhr.onload = k;
392
+ xhr.onerror = k;
393
+ xhr.onabort = k;
394
+ xhr.onprogress = k;
395
+ xhr.onreadystatechange = k;
396
+ // IE 8 - 9: XDomainRequest#abort() does not fire any event
397
+ // Opera < 10: XMLHttpRequest#abort() does not fire any event
398
+ xhr.abort();
399
+ if (timeout !== 0) {
400
+ clearTimeout(timeout);
401
+ timeout = 0;
402
+ }
403
+ if (!silent) {
404
+ that.readyState = 4;
405
+ that.onabort(null);
406
+ that.onreadystatechange();
407
+ }
408
+ }
409
+ state = 0;
410
+ };
411
+
412
+ var onStart = function () {
413
+ if (state === 1) {
414
+ //state = 2;
415
+ var status = 0;
416
+ var statusText = "";
417
+ var contentType = undefined;
418
+ if (!("contentType" in xhr)) {
419
+ try {
420
+ status = xhr.status;
421
+ statusText = xhr.statusText;
422
+ contentType = xhr.getResponseHeader("Content-Type");
423
+ } catch (error) {
424
+ // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
425
+ // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
426
+ // https://bugs.webkit.org/show_bug.cgi?id=29121
427
+ status = 0;
428
+ statusText = "";
429
+ contentType = undefined;
430
+ // Firefox < 14, Chrome ?, Safari ?
431
+ // https://bugs.webkit.org/show_bug.cgi?id=29658
432
+ // https://bugs.webkit.org/show_bug.cgi?id=77854
433
+ }
434
+ } else {
435
+ status = 200;
436
+ statusText = "OK";
437
+ contentType = xhr.contentType;
438
+ }
439
+ if (status !== 0) {
440
+ state = 2;
441
+ that.readyState = 2;
442
+ that.status = status;
443
+ that.statusText = statusText;
444
+ that._contentType = contentType;
445
+ that.onreadystatechange();
446
+ }
447
+ }
448
+ };
449
+ var onProgress = function () {
450
+ onStart();
451
+ if (state === 2 || state === 3) {
452
+ state = 3;
453
+ var responseText = "";
454
+ try {
455
+ responseText = xhr.responseText;
456
+ } catch (error) {
457
+ // IE 8 - 9 with XMLHttpRequest
458
+ }
459
+ that.readyState = 3;
460
+ that.responseText = responseText;
461
+ that.onprogress();
462
+ }
463
+ };
464
+ var onFinish = function (type, event) {
465
+ if (event == null || event.preventDefault == null) {
466
+ event = {
467
+ preventDefault: k
468
+ };
469
+ }
470
+ // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
471
+ // IE 8 fires "onload" without "onprogress"
472
+ onProgress();
473
+ if (state === 1 || state === 2 || state === 3) {
474
+ state = 4;
475
+ if (timeout !== 0) {
476
+ clearTimeout(timeout);
477
+ timeout = 0;
478
+ }
479
+ that.readyState = 4;
480
+ if (type === "load") {
481
+ that.onload(event);
482
+ } else if (type === "error") {
483
+ that.onerror(event);
484
+ } else if (type === "abort") {
485
+ that.onabort(event);
486
+ } else {
487
+ throw new TypeError();
488
+ }
489
+ that.onreadystatechange();
490
+ }
491
+ };
492
+ var onReadyStateChange = function (event) {
493
+ if (xhr != undefined) { // Opera 12
494
+ if (xhr.readyState === 4) {
495
+ if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
496
+ onFinish(xhr.responseText === "" ? "error" : "load", event);
497
+ }
498
+ } else if (xhr.readyState === 3) {
499
+ if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
500
+ // and in Firefox 3.6
501
+ onProgress();
502
+ }
503
+ } else if (xhr.readyState === 2) {
504
+ onStart();
505
+ }
506
+ }
507
+ };
508
+ var onTimeout = function () {
509
+ timeout = setTimeout(function () {
510
+ onTimeout();
511
+ }, 500);
512
+ if (xhr.readyState === 3) {
513
+ onProgress();
514
+ }
515
+ };
516
+
517
+ // XDomainRequest#abort removes onprogress, onerror, onload
518
+ if ("onload" in xhr) {
519
+ xhr.onload = function (event) {
520
+ onFinish("load", event);
521
+ };
522
+ }
523
+ if ("onerror" in xhr) {
524
+ xhr.onerror = function (event) {
525
+ onFinish("error", event);
526
+ };
527
+ }
528
+ // improper fix to match Firefox behaviour, but it is better than just ignore abort
529
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
530
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
531
+ // https://code.google.com/p/chromium/issues/detail?id=153570
532
+ // IE 8 fires "onload" without "onprogress
533
+ if ("onabort" in xhr) {
534
+ xhr.onabort = function (event) {
535
+ onFinish("abort", event);
536
+ };
537
+ }
538
+
539
+ if ("onprogress" in xhr) {
540
+ xhr.onprogress = onProgress;
541
+ }
542
+
543
+ // IE 8 - 9 (XMLHTTPRequest)
544
+ // Opera < 12
545
+ // Firefox < 3.5
546
+ // Firefox 3.5 - 3.6 - ? < 9.0
547
+ // onprogress is not fired sometimes or delayed
548
+ // see also #64 (significant lag in IE 11)
549
+ if ("onreadystatechange" in xhr) {
550
+ xhr.onreadystatechange = function (event) {
551
+ onReadyStateChange(event);
552
+ };
553
+ }
554
+
555
+ if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
556
+ url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
557
+ }
558
+ xhr.open(method, url, true);
559
+
560
+ if ("readyState" in xhr) {
561
+ // workaround for Opera 12 issue with "progress" events
562
+ // #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
563
+ timeout = setTimeout(function () {
564
+ onTimeout();
565
+ }, 0);
566
+ }
567
+ };
568
+ XHRWrapper.prototype.abort = function () {
569
+ this._abort(false);
570
+ };
571
+ XHRWrapper.prototype.getResponseHeader = function (name) {
572
+ return this._contentType;
573
+ };
574
+ XHRWrapper.prototype.setRequestHeader = function (name, value) {
575
+ var xhr = this._xhr;
576
+ if ("setRequestHeader" in xhr) {
577
+ xhr.setRequestHeader(name, value);
578
+ }
579
+ };
580
+ XHRWrapper.prototype.getAllResponseHeaders = function () {
581
+ // XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
582
+ return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
583
+ };
584
+ XHRWrapper.prototype.send = function () {
585
+ // loading indicator in Safari < ? (6), Chrome < 14, Firefox
586
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
587
+ if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
588
+ document != undefined &&
589
+ document.readyState != undefined &&
590
+ document.readyState !== "complete") {
591
+ var that = this;
592
+ that._sendTimeout = setTimeout(function () {
593
+ that._sendTimeout = 0;
594
+ that.send();
595
+ }, 4);
596
+ return;
597
+ }
598
+
599
+ var xhr = this._xhr;
600
+ // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
601
+ if ("withCredentials" in xhr) {
602
+ xhr.withCredentials = this.withCredentials;
603
+ }
604
+ try {
605
+ // xhr.send(); throws "Not enough arguments" in Firefox 3.0
606
+ xhr.send(undefined);
607
+ } catch (error1) {
608
+ // Safari 5.1.7, Opera 12
609
+ throw error1;
610
+ }
611
+ };
612
+
613
+ function toLowerCase(name) {
614
+ return name.replace(/[A-Z]/g, function (c) {
615
+ return String.fromCharCode(c.charCodeAt(0) + 0x20);
616
+ });
617
+ }
618
+
619
+ function HeadersPolyfill(all) {
620
+ // Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
621
+ var map = Object.create(null);
622
+ var array = all.split("\r\n");
623
+ for (var i = 0; i < array.length; i += 1) {
624
+ var line = array[i];
625
+ var parts = line.split(": ");
626
+ var name = parts.shift();
627
+ var value = parts.join(": ");
628
+ map[toLowerCase(name)] = value;
629
+ }
630
+ this._map = map;
631
+ }
632
+ HeadersPolyfill.prototype.get = function (name) {
633
+ return this._map[toLowerCase(name)];
634
+ };
635
+
636
+ if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
637
+ XMLHttpRequest.HEADERS_RECEIVED = 2;
638
+ }
639
+
640
+ function XHRTransport() {
641
+ }
642
+
643
+ XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
644
+ xhr.open("GET", url);
645
+ var offset = 0;
646
+ xhr.onprogress = function () {
647
+ var responseText = xhr.responseText;
648
+ var chunk = responseText.slice(offset);
649
+ offset += chunk.length;
650
+ onProgressCallback(chunk);
651
+ };
652
+ xhr.onerror = function (event) {
653
+ event.preventDefault();
654
+ onFinishCallback(new Error("NetworkError"));
655
+ };
656
+ xhr.onload = function () {
657
+ onFinishCallback(null);
658
+ };
659
+ xhr.onabort = function () {
660
+ onFinishCallback(null);
661
+ };
662
+ xhr.onreadystatechange = function () {
663
+ if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
664
+ var status = xhr.status;
665
+ var statusText = xhr.statusText;
666
+ var contentType = xhr.getResponseHeader("Content-Type");
667
+ var headers = xhr.getAllResponseHeaders();
668
+ onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
669
+ }
670
+ };
671
+ xhr.withCredentials = withCredentials;
672
+ for (var name in headers) {
673
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
674
+ xhr.setRequestHeader(name, headers[name]);
675
+ }
676
+ }
677
+ xhr.send();
678
+ return xhr;
679
+ };
680
+
681
+ function HeadersWrapper(headers) {
682
+ this._headers = headers;
683
+ }
684
+ HeadersWrapper.prototype.get = function (name) {
685
+ return this._headers.get(name);
686
+ };
687
+
688
+ function FetchTransport() {
689
+ }
690
+
691
+ FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
692
+ var reader = null;
693
+ var controller = new AbortController();
694
+ var signal = controller.signal;
695
+ var textDecoder = new TextDecoder();
696
+ fetch(url, {
697
+ headers: headers,
698
+ credentials: withCredentials ? "include" : "same-origin",
699
+ signal: signal,
700
+ cache: "no-store"
701
+ }).then(function (response) {
702
+ reader = response.body.getReader();
703
+ onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
704
+ // see https://github.com/promises-aplus/promises-spec/issues/179
705
+ return new Promise(function (resolve, reject) {
706
+ var readNextChunk = function () {
707
+ reader.read().then(function (result) {
708
+ if (result.done) {
709
+ //Note: bytes in textDecoder are ignored
710
+ resolve(undefined);
711
+ } else {
712
+ var chunk = textDecoder.decode(result.value, {stream: true});
713
+ onProgressCallback(chunk);
714
+ readNextChunk();
715
+ }
716
+ })["catch"](function (error) {
717
+ reject(error);
718
+ });
719
+ };
720
+ readNextChunk();
721
+ });
722
+ })["catch"](function (error) {
723
+ if (error.name === "AbortError") {
724
+ return undefined;
725
+ } else {
726
+ return error;
727
+ }
728
+ }).then(function (error) {
729
+ onFinishCallback(error);
730
+ });
731
+ return {
732
+ abort: function () {
733
+ if (reader != null) {
734
+ reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
735
+ }
736
+ controller.abort();
737
+ }
738
+ };
739
+ };
740
+
741
+ function EventTarget() {
742
+ this._listeners = Object.create(null);
743
+ }
744
+
745
+ function throwError(e) {
746
+ setTimeout(function () {
747
+ throw e;
748
+ }, 0);
749
+ }
750
+
751
+ EventTarget.prototype.dispatchEvent = function (event) {
752
+ event.target = this;
753
+ var typeListeners = this._listeners[event.type];
754
+ if (typeListeners != undefined) {
755
+ var length = typeListeners.length;
756
+ for (var i = 0; i < length; i += 1) {
757
+ var listener = typeListeners[i];
758
+ try {
759
+ if (typeof listener.handleEvent === "function") {
760
+ listener.handleEvent(event);
761
+ } else {
762
+ listener.call(this, event);
763
+ }
764
+ } catch (e) {
765
+ throwError(e);
766
+ }
767
+ }
768
+ }
769
+ };
770
+ EventTarget.prototype.addEventListener = function (type, listener) {
771
+ type = String(type);
772
+ var listeners = this._listeners;
773
+ var typeListeners = listeners[type];
774
+ if (typeListeners == undefined) {
775
+ typeListeners = [];
776
+ listeners[type] = typeListeners;
777
+ }
778
+ var found = false;
779
+ for (var i = 0; i < typeListeners.length; i += 1) {
780
+ if (typeListeners[i] === listener) {
781
+ found = true;
782
+ }
783
+ }
784
+ if (!found) {
785
+ typeListeners.push(listener);
786
+ }
787
+ };
788
+ EventTarget.prototype.removeEventListener = function (type, listener) {
789
+ type = String(type);
790
+ var listeners = this._listeners;
791
+ var typeListeners = listeners[type];
792
+ if (typeListeners != undefined) {
793
+ var filtered = [];
794
+ for (var i = 0; i < typeListeners.length; i += 1) {
795
+ if (typeListeners[i] !== listener) {
796
+ filtered.push(typeListeners[i]);
797
+ }
798
+ }
799
+ if (filtered.length === 0) {
800
+ delete listeners[type];
801
+ } else {
802
+ listeners[type] = filtered;
803
+ }
804
+ }
805
+ };
806
+
807
+ function Event(type) {
808
+ this.type = type;
809
+ this.target = undefined;
810
+ }
811
+
812
+ function MessageEvent(type, options) {
813
+ Event.call(this, type);
814
+ this.data = options.data;
815
+ this.lastEventId = options.lastEventId;
816
+ }
817
+
818
+ MessageEvent.prototype = Object.create(Event.prototype);
819
+
820
+ function ConnectionEvent(type, options) {
821
+ Event.call(this, type);
822
+ this.status = options.status;
823
+ this.statusText = options.statusText;
824
+ this.headers = options.headers;
825
+ }
826
+
827
+ ConnectionEvent.prototype = Object.create(Event.prototype);
828
+
829
+ function ErrorEvent(type, options) {
830
+ Event.call(this, type);
831
+ this.error = options.error;
832
+ }
833
+
834
+ ErrorEvent.prototype = Object.create(Event.prototype);
835
+
836
+ var WAITING = -1;
837
+ var CONNECTING = 0;
838
+ var OPEN = 1;
839
+ var CLOSED = 2;
840
+
841
+ var AFTER_CR = -1;
842
+ var FIELD_START = 0;
843
+ var FIELD = 1;
844
+ var VALUE_START = 2;
845
+ var VALUE = 3;
846
+
847
+ var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
848
+
849
+ var MINIMUM_DURATION = 1000;
850
+ var MAXIMUM_DURATION = 18000000;
851
+
852
+ var parseDuration = function (value, def) {
853
+ var n = value == null ? def : parseInt(value, 10);
854
+ if (n !== n) {
855
+ n = def;
856
+ }
857
+ return clampDuration(n);
858
+ };
859
+ var clampDuration = function (n) {
860
+ return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
861
+ };
862
+
863
+ var fire = function (that, f, event) {
864
+ try {
865
+ if (typeof f === "function") {
866
+ f.call(that, event);
867
+ }
868
+ } catch (e) {
869
+ throwError(e);
870
+ }
871
+ };
872
+
873
+ function EventSourcePolyfill(url, options) {
874
+ EventTarget.call(this);
875
+ options = options || {};
876
+
877
+ this.onopen = undefined;
878
+ this.onmessage = undefined;
879
+ this.onerror = undefined;
880
+
881
+ this.url = undefined;
882
+ this.readyState = undefined;
883
+ this.withCredentials = undefined;
884
+ this.headers = undefined;
885
+
886
+ this._close = undefined;
887
+
888
+ start(this, url, options);
889
+ }
890
+
891
+ function getBestXHRTransport() {
892
+ return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
893
+ ? new XMLHttpRequest()
894
+ : new XDomainRequest();
895
+ }
896
+
897
+ var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
898
+
899
+ function start(es, url, options) {
900
+ url = String(url);
901
+ var withCredentials = Boolean(options.withCredentials);
902
+ var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
903
+
904
+ var initialRetry = clampDuration(1000);
905
+ var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
906
+
907
+ var lastEventId = "";
908
+ var retry = initialRetry;
909
+ var wasActivity = false;
910
+ var textLength = 0;
911
+ var headers = options.headers || {};
912
+ var TransportOption = options.Transport;
913
+ var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
914
+ var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
915
+ var abortController = undefined;
916
+ var timeout = 0;
917
+ var currentState = WAITING;
918
+ var dataBuffer = "";
919
+ var lastEventIdBuffer = "";
920
+ var eventTypeBuffer = "";
921
+
922
+ var textBuffer = "";
923
+ var state = FIELD_START;
924
+ var fieldStart = 0;
925
+ var valueStart = 0;
926
+
927
+ var onStart = function (status, statusText, contentType, headers) {
928
+ if (currentState === CONNECTING) {
929
+ if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
930
+ currentState = OPEN;
931
+ wasActivity = Date.now();
932
+ retry = initialRetry;
933
+ es.readyState = OPEN;
934
+ var event = new ConnectionEvent("open", {
935
+ status: status,
936
+ statusText: statusText,
937
+ headers: headers
938
+ });
939
+ es.dispatchEvent(event);
940
+ fire(es, es.onopen, event);
941
+ } else {
942
+ var message = "";
943
+ if (status !== 200) {
944
+ if (statusText) {
945
+ statusText = statusText.replace(/\s+/g, " ");
946
+ }
947
+ message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
948
+ } else {
949
+ message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
950
+ }
951
+ close();
952
+ var event = new ConnectionEvent("error", {
953
+ status: status,
954
+ statusText: statusText,
955
+ headers: headers
956
+ });
957
+ es.dispatchEvent(event);
958
+ fire(es, es.onerror, event);
959
+ console.error(message);
960
+ }
961
+ }
962
+ };
963
+
964
+ var onProgress = function (textChunk) {
965
+ if (currentState === OPEN) {
966
+ var n = -1;
967
+ for (var i = 0; i < textChunk.length; i += 1) {
968
+ var c = textChunk.charCodeAt(i);
969
+ if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
970
+ n = i;
971
+ }
972
+ }
973
+ var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
974
+ textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
975
+ if (textChunk !== "") {
976
+ wasActivity = Date.now();
977
+ textLength += textChunk.length;
978
+ }
979
+ for (var position = 0; position < chunk.length; position += 1) {
980
+ var c = chunk.charCodeAt(position);
981
+ if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
982
+ state = FIELD_START;
983
+ } else {
984
+ if (state === AFTER_CR) {
985
+ state = FIELD_START;
986
+ }
987
+ if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
988
+ if (state !== FIELD_START) {
989
+ if (state === FIELD) {
990
+ valueStart = position + 1;
991
+ }
992
+ var field = chunk.slice(fieldStart, valueStart - 1);
993
+ var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
994
+ if (field === "data") {
995
+ dataBuffer += "\n";
996
+ dataBuffer += value;
997
+ } else if (field === "id") {
998
+ lastEventIdBuffer = value;
999
+ } else if (field === "event") {
1000
+ eventTypeBuffer = value;
1001
+ } else if (field === "retry") {
1002
+ initialRetry = parseDuration(value, initialRetry);
1003
+ retry = initialRetry;
1004
+ } else if (field === "heartbeatTimeout") {
1005
+ heartbeatTimeout = parseDuration(value, heartbeatTimeout);
1006
+ if (timeout !== 0) {
1007
+ clearTimeout(timeout);
1008
+ timeout = setTimeout(function () {
1009
+ onTimeout();
1010
+ }, heartbeatTimeout);
1011
+ }
1012
+ }
1013
+ }
1014
+ if (state === FIELD_START) {
1015
+ if (dataBuffer !== "") {
1016
+ lastEventId = lastEventIdBuffer;
1017
+ if (eventTypeBuffer === "") {
1018
+ eventTypeBuffer = "message";
1019
+ }
1020
+ var event = new MessageEvent(eventTypeBuffer, {
1021
+ data: dataBuffer.slice(1),
1022
+ lastEventId: lastEventIdBuffer
1023
+ });
1024
+ es.dispatchEvent(event);
1025
+ if (eventTypeBuffer === "open") {
1026
+ fire(es, es.onopen, event);
1027
+ } else if (eventTypeBuffer === "message") {
1028
+ fire(es, es.onmessage, event);
1029
+ } else if (eventTypeBuffer === "error") {
1030
+ fire(es, es.onerror, event);
1031
+ }
1032
+ if (currentState === CLOSED) {
1033
+ return;
1034
+ }
1035
+ }
1036
+ dataBuffer = "";
1037
+ eventTypeBuffer = "";
1038
+ }
1039
+ state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
1040
+ } else {
1041
+ if (state === FIELD_START) {
1042
+ fieldStart = position;
1043
+ state = FIELD;
1044
+ }
1045
+ if (state === FIELD) {
1046
+ if (c === ":".charCodeAt(0)) {
1047
+ valueStart = position + 1;
1048
+ state = VALUE_START;
1049
+ }
1050
+ } else if (state === VALUE_START) {
1051
+ state = VALUE;
1052
+ }
1053
+ }
1054
+ }
1055
+ }
1056
+ }
1057
+ };
1058
+
1059
+ var onFinish = function (error) {
1060
+ if (currentState === OPEN || currentState === CONNECTING) {
1061
+ currentState = WAITING;
1062
+ if (timeout !== 0) {
1063
+ clearTimeout(timeout);
1064
+ timeout = 0;
1065
+ }
1066
+ timeout = setTimeout(function () {
1067
+ onTimeout();
1068
+ }, retry);
1069
+ retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
1070
+
1071
+ es.readyState = CONNECTING;
1072
+ var event = new ErrorEvent("error", {error: error});
1073
+ es.dispatchEvent(event);
1074
+ fire(es, es.onerror, event);
1075
+ if (error != undefined) {
1076
+ console.error(error);
1077
+ }
1078
+ }
1079
+ };
1080
+
1081
+ var close = function () {
1082
+ currentState = CLOSED;
1083
+ if (abortController != undefined) {
1084
+ abortController.abort();
1085
+ abortController = undefined;
1086
+ }
1087
+ if (timeout !== 0) {
1088
+ clearTimeout(timeout);
1089
+ timeout = 0;
1090
+ }
1091
+ es.readyState = CLOSED;
1092
+ };
1093
+
1094
+ var onTimeout = function () {
1095
+ timeout = 0;
1096
+
1097
+ if (currentState !== WAITING) {
1098
+ if (!wasActivity && abortController != undefined) {
1099
+ onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
1100
+ if (abortController != undefined) {
1101
+ abortController.abort();
1102
+ abortController = undefined;
1103
+ }
1104
+ } else {
1105
+ var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
1106
+ wasActivity = false;
1107
+ timeout = setTimeout(function () {
1108
+ onTimeout();
1109
+ }, nextHeartbeat);
1110
+ }
1111
+ return;
1112
+ }
1113
+
1114
+ wasActivity = false;
1115
+ textLength = 0;
1116
+ timeout = setTimeout(function () {
1117
+ onTimeout();
1118
+ }, heartbeatTimeout);
1119
+
1120
+ currentState = CONNECTING;
1121
+ dataBuffer = "";
1122
+ eventTypeBuffer = "";
1123
+ lastEventIdBuffer = lastEventId;
1124
+ textBuffer = "";
1125
+ fieldStart = 0;
1126
+ valueStart = 0;
1127
+ state = FIELD_START;
1128
+
1129
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
1130
+ // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
1131
+ var requestURL = url;
1132
+ if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
1133
+ if (lastEventId !== "") {
1134
+ // Remove the lastEventId parameter if it's already part of the request URL.
1135
+ var i = url.indexOf("?");
1136
+ requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
1137
+ return paramName === lastEventIdQueryParameterName ? '' : p;
1138
+ });
1139
+ // Append the current lastEventId to the request URL.
1140
+ requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
1141
+ }
1142
+ }
1143
+ var withCredentials = es.withCredentials;
1144
+ var requestHeaders = {};
1145
+ requestHeaders["Accept"] = "text/event-stream";
1146
+ var headers = es.headers;
1147
+ if (headers != undefined) {
1148
+ for (var name in headers) {
1149
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
1150
+ requestHeaders[name] = headers[name];
1151
+ }
1152
+ }
1153
+ }
1154
+ try {
1155
+ abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
1156
+ } catch (error) {
1157
+ close();
1158
+ throw error;
1159
+ }
1160
+ };
1161
+
1162
+ es.url = url;
1163
+ es.readyState = CONNECTING;
1164
+ es.withCredentials = withCredentials;
1165
+ es.headers = headers;
1166
+ es._close = close;
1167
+
1168
+ onTimeout();
1169
+ }
1170
+
1171
+ EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
1172
+ EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
1173
+ EventSourcePolyfill.prototype.OPEN = OPEN;
1174
+ EventSourcePolyfill.prototype.CLOSED = CLOSED;
1175
+ EventSourcePolyfill.prototype.close = function () {
1176
+ this._close();
1177
+ };
1178
+
1179
+ EventSourcePolyfill.CONNECTING = CONNECTING;
1180
+ EventSourcePolyfill.OPEN = OPEN;
1181
+ EventSourcePolyfill.CLOSED = CLOSED;
1182
+ EventSourcePolyfill.prototype.withCredentials = undefined;
1183
+
1184
+ var R = NativeEventSource;
1185
+ if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
1186
+ // Why replace a native EventSource ?
1187
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
1188
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
1189
+ // https://code.google.com/p/chromium/issues/detail?id=260144
1190
+ // https://code.google.com/p/chromium/issues/detail?id=225654
1191
+ // ...
1192
+ R = EventSourcePolyfill;
1193
+ }
1194
+
1195
+ (function (factory) {
1196
+ {
1197
+ var v = factory(exports);
1198
+ if (v !== undefined) module.exports = v;
1199
+ }
1200
+ })(function (exports) {
1201
+ exports.EventSourcePolyfill = EventSourcePolyfill;
1202
+ exports.NativeEventSource = NativeEventSource;
1203
+ exports.EventSource = R;
1204
+ });
1205
+ }(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
1206
+ }(eventsource, eventsource.exports));
1207
+
1208
+ const casinoTournamentsIngameTableCss = ":host{display:block;height:100%}.Dark{color:var(--emw--ingame-color-text, #f5f8f6)}.Light{color:var(--emw--ingame-color-black, #0A0A17)}.Mobile.LeaderboardWrapper .Bottom .PlayerRank.Active{padding:2px 8px}.LeaderboardWrapper{height:100%;position:relative;overflow:hidden}.LeaderboardWrapper .Loading,.LeaderboardWrapper .Leaderboard,.LeaderboardWrapper .Bottom{width:calc(100% - 30px);padding:0 15px;scrollbar-width:thin}.LeaderboardWrapper .Loading,.LeaderboardWrapper .Leaderboard{padding-bottom:0}.LeaderboardWrapper .Bottom{position:absolute;bottom:0;background:linear-gradient(90deg, var(--emw--ingame-color-gray-purple50, rgba(35, 41, 119, 0.4980392157)) 0%, var(--emw--ingame-color-dark-purple50, rgba(59, 28, 117, 0.4980392157)) 100%);border-top:1px solid;border-image-source:linear-gradient(94.32deg, var(--emw--ingame-color-pth-primary1, #9500FF) 4.41%, var(--emw--ingame-color-pth-primary2, #232EC4) 113.86%);border-image-slice:1;backdrop-filter:blur(20px);opacity:0.91}.LeaderboardWrapper .Bottom .PlayerRank.Active{border-width:0;cursor:pointer;padding-right:18px;background:transparent}.LeaderboardWrapper .PlayerRank{overflow-anchor:auto;font-weight:bold;align-items:center;height:26px;gap:16px;padding:2px 8px;display:flex}.LeaderboardWrapper .PlayerRank.Hidden{display:none !important}.LeaderboardWrapper .PlayerRank.Active{background-clip:padding-box, border-box;background-origin:padding-box, border-box;border:1px solid transparent;border-radius:10px;background-image:linear-gradient(91deg, var(--emw--ingame-color-pth-primary4, #11153E) 4.41%, var(--emw--ingame-color-pth-primary4, #11153E) 113.86%), linear-gradient(91deg, var(--emw--ingame-color-pth-primary1, #9500FF) 4.41%, var(--emw--ingame-color-pth-primary2, #232EC4) 113.86%)}.LeaderboardWrapper .PlayerRank div{text-overflow:ellipsis;overflow:hidden;white-space:nowrap}.LeaderboardWrapper .PlayerRank .Rank{flex:1}.LeaderboardWrapper .PlayerRank .Name{flex:2;text-align:left}.LeaderboardWrapper .PlayerRank .Score{flex:1;font-weight:normal}.LeaderboardWrapper .PlayerRank .Prize{flex:4}.LeaderboardWrapper .Leaderboard{height:calc(99% - 25px) !important;overflow-y:auto;overflow-anchor:auto}.LeaderboardWrapper .Leaderboard .NoWinners{margin:30px auto;display:flex;flex-direction:column;gap:15px}.LeaderboardWrapper .Leaderboard .NoWinners .Title{font-weight:bold;font-size:medium}.LeaderboardWrapper .Leaderboard .NoWinners .Title,.LeaderboardWrapper .Leaderboard .NoWinners .Info{display:flex;align-items:center;flex-direction:column}";
1209
+ const CasinoTournamentsIngameTableStyle0 = casinoTournamentsIngameTableCss;
1210
+
1211
+ const CasinoTournamentsIngameTable = class {
1212
+ constructor(hostRef) {
1213
+ index.registerInstance(this, hostRef);
1214
+ this.leaderboardLoaded = index.createEvent(this, "leaderboardLoaded", 7);
1215
+ this.isCurrentOnTop = false;
1216
+ this.isCurrentPlayerRanked = false;
1217
+ this.timeOrder1 = 500;
1218
+ this.timeOrder2 = 1000;
1219
+ this.isMobile = false;
1220
+ this.abortController = null;
1221
+ //Will load again if current player is not in the 1st page when autoLocateCurrent=true;
1222
+ this.autoLocateCurrent = false;
1223
+ //Current player will not change the position when scroll current player up
1224
+ this.keepOnBottom = true;
1225
+ this.mbSource = undefined;
1226
+ this.clientStyling = undefined;
1227
+ this.clientStylingUrl = undefined;
1228
+ this.tournamentId = undefined;
1229
+ this.endpoint = undefined;
1230
+ this.session = undefined;
1231
+ this.language = 'en';
1232
+ this.limit = 40;
1233
+ this.theme = 'Dark';
1234
+ this.state = undefined;
1235
+ this.offset = 0;
1236
+ this.currentUserData = undefined;
1237
+ this.leaderboard = [];
1238
+ this.isLeaderboardLoading = true;
1239
+ this.isLoadingMore = false;
1240
+ this.isCurrentPlayerInview = true;
1241
+ this.isLoadingPrevious = false;
1242
+ }
1243
+ /**
1244
+ * oriArr:
1245
+ * [{rank: 15, playerName: xxx, prize: xxx},
1246
+ * {rank: 16, playerName: xxx, prize: xxx},
1247
+ * {rank: 17, playerName: xxx, prize: xxx},
1248
+ * {rank: 18, playerName: xxx, prize: xxx}]
1249
+ *==> oriMap{15: 0, 16: 1, 17: 2, 18: 3}
1250
+ * new: [
1251
+ * { rank: 5, playerName: xxx, prize: yyy},
1252
+ * { rank: 6, playerName: xxx, prize: xxx},
1253
+ * { rank: 7, playerName: xxx, prize: xxx}
1254
+ * ],
1255
+ * order: 'rank'
1256
+ * @param originalArray
1257
+ * @param newArray
1258
+ * @param order
1259
+ */
1260
+ mergeSortedArrays(originalArray, newArray, order) {
1261
+ if (!(originalArray === null || originalArray === void 0 ? void 0 : originalArray.length)) {
1262
+ return newArray;
1263
+ }
1264
+ if (!(newArray === null || newArray === void 0 ? void 0 : newArray.length)) {
1265
+ return originalArray;
1266
+ }
1267
+ // create a Map for locating elements in originalArray
1268
+ const originalMap = new Map();
1269
+ originalArray.forEach((item, index) => {
1270
+ originalMap.set(item[order], index);
1271
+ });
1272
+ // insert the news
1273
+ let result = [...originalArray];
1274
+ const newItems = [];
1275
+ newArray.forEach(item => {
1276
+ const key = item[order];
1277
+ if (!originalMap.has(key)) {
1278
+ newItems.push(item);
1279
+ }
1280
+ else {
1281
+ result[originalMap.get(key)] = item;
1282
+ }
1283
+ });
1284
+ if (!newItems.length) {
1285
+ return originalArray;
1286
+ }
1287
+ result = [];
1288
+ const maxOfNewItemsKey = newItems[newItems.length - 1][order];
1289
+ const minOfOriItemsKey = originalArray[0][order];
1290
+ if (maxOfNewItemsKey < minOfOriItemsKey) {
1291
+ result = [...newItems, ...originalArray];
1292
+ }
1293
+ else {
1294
+ result = [...originalArray, ...newItems];
1295
+ }
1296
+ return result;
1297
+ }
1298
+ onLeaderboardScroll(event) {
1299
+ if (this.isLoadingPrevious || this.isLoadingMore) {
1300
+ event.preventDefault();
1301
+ }
1302
+ }
1303
+ async loadLeaderboardById() {
1304
+ if (this.abortController) {
1305
+ this.abortController.abort();
1306
+ }
1307
+ if (this.isLoadingMore) {
1308
+ return;
1309
+ }
1310
+ this.abortController = new AbortController();
1311
+ this.isLoadingMore = true;
1312
+ let url = new URL(`${this.endpoint}/v1/tournaments/${this.tournamentId}/leaderboard?language=${this.language}`);
1313
+ url.searchParams.set('filter', 'includeUnqualifiedPlayer=true');
1314
+ url.searchParams.set('pagination', `offset=${this.offset},limit=${this.limit}`);
1315
+ url.searchParams.set('platform', getDevice());
1316
+ let options = {
1317
+ headers: {
1318
+ 'Content-Type': 'application/json',
1319
+ 'x-SessionId': this.session
1320
+ },
1321
+ method: 'GET',
1322
+ signal: this.abortController.signal
1323
+ };
1324
+ await fetch(url, options).then(res => res.json()).then(data => {
1325
+ const { item, items, total } = data;
1326
+ this.isCurrentPlayerRanked = !!item;
1327
+ if (this.isCurrentPlayerRanked) {
1328
+ this.currentUserData = item;
1329
+ if (this.isLeaderboardLoading) {
1330
+ if (this.offset > 0) { //First load for current player
1331
+ this.scrollCurrentPlayerToMiddle();
1332
+ }
1333
+ else if (this.offset === 0) {
1334
+ if (this.autoLocateCurrent && this.currentUserData.rank > this.limit) { //current player is not in the 1st page
1335
+ this.offset = (this.currentUserData.rank - this.limit / 2) || 0;
1336
+ this.leaderboardLoaded.emit({ item: this.currentUserData, leaderboardOffset: this.offset, isRanked: true, totalRank: total });
1337
+ this.loadLeaderboardById().catch(console.error);
1338
+ return;
1339
+ }
1340
+ }
1341
+ }
1342
+ else {
1343
+ this.isLoadingPrevious && this.resetScrollTop();
1344
+ }
1345
+ setTimeout(() => {
1346
+ if (this.tableListEle && this.tableListEle.querySelectorAll(`.Active`).length) {
1347
+ this.startActivePlayerObserver();
1348
+ }
1349
+ else {
1350
+ this.isCurrentPlayerInview = false;
1351
+ }
1352
+ }, this.timeOrder2);
1353
+ }
1354
+ this.total = total;
1355
+ this.leaderboardLoaded.emit({ item: this.currentUserData, leaderboardOffset: this.offset, isRanked: this.isCurrentPlayerRanked, totalRank: total });
1356
+ this.leaderboard = this.mergeSortedArrays(this.leaderboard, items, 'rank');
1357
+ //Setup the observer for loadMore when scroll to top or bottom
1358
+ this.startScrollObersever();
1359
+ this.reStartUpSSEUpdater(url);
1360
+ this.isLeaderboardLoading = false;
1361
+ }, err => {
1362
+ this.isLeaderboardLoading = false;
1363
+ if (err.name === 'AbortError') {
1364
+ console.log('Request aborted because a new one started or component unmounted.');
1365
+ }
1366
+ else {
1367
+ console.error('Network error', err);
1368
+ }
1369
+ }).finally(() => {
1370
+ this.isLoadingMore = false;
1371
+ });
1372
+ }
1373
+ startScrollObersever() {
1374
+ this.topLastTimer && clearTimeout(this.topLastTimer);
1375
+ this.topLastTimer = setTimeout(() => {
1376
+ if (this.total <= this.limit) {
1377
+ return;
1378
+ }
1379
+ if (this.leaderboard[0].rank !== 1) {
1380
+ this.startTopRankObserver();
1381
+ }
1382
+ if (this.leaderboard[this.leaderboard.length - 1].rank < this.total) {
1383
+ this.startLastRankObserver();
1384
+ }
1385
+ }, this.timeOrder2);
1386
+ }
1387
+ scrollCurrentPlayerToMiddle() {
1388
+ setTimeout(() => {
1389
+ if (!this.tableListEle || !this.tableListEle.querySelectorAll(`.Active`).length) {
1390
+ return;
1391
+ }
1392
+ const currentPlayerEle = this.tableListEle.querySelectorAll(`.Active`)[0];
1393
+ const rect = this.stylingContainer.getBoundingClientRect();
1394
+ //the height of the viewport
1395
+ const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
1396
+ //the distance between the top of the element and the top of the viewport
1397
+ const top = rect.top;
1398
+ const visibleHeight = viewportHeight - top; // 如果元素顶部在视口外,计算实际可见部分的高度
1399
+ let currentLineDistanceToTop = Math.min(visibleHeight / 2 - currentPlayerEle.clientHeight, currentPlayerEle.clientHeight * 4);
1400
+ currentLineDistanceToTop = Math.max(currentLineDistanceToTop, currentPlayerEle.clientHeight);
1401
+ this.tableListEle.scrollTo({ top: currentPlayerEle.offsetTop - currentLineDistanceToTop, behavior: 'smooth' });
1402
+ }, this.timeOrder1);
1403
+ }
1404
+ onStateChanged() {
1405
+ switch (this.state) {
1406
+ case 'Closed':
1407
+ case 'Closing':
1408
+ if (this.leaderboardUpdater) {
1409
+ this.leaderboardUpdater.close();
1410
+ this.leaderboardUpdater.removeEventListener('message', this.updateMessageHandler);
1411
+ this.leaderboardUpdater = null;
1412
+ }
1413
+ break;
1414
+ }
1415
+ }
1416
+ reStartUpSSEUpdater(url) {
1417
+ if (this.leaderboardUpdater) {
1418
+ this.leaderboardUpdater.close();
1419
+ this.leaderboardUpdater.removeEventListener('message', this.updateMessageHandler);
1420
+ }
1421
+ if (this.state !== 'Running') {
1422
+ return;
1423
+ }
1424
+ url.searchParams.set("pagination", `offset=${this.leaderboard.length ? this.leaderboard[0].rank - 1 : 0},limit=${this.leaderboard.length || this.limit}`);
1425
+ let endpointUrl = new URL(`${this.endpoint}/v1/tournaments/${this.tournamentId}/leaderboard/updates?${url.searchParams.toString()}`);
1426
+ const options = { headers: { 'accept': 'text/event-stream', 'X-SessionId': this.session } };
1427
+ this.leaderboardUpdater = new eventsource.exports.EventSourcePolyfill(endpointUrl, options);
1428
+ this.leaderboardUpdater.addEventListener('message', this.updateMessageHandler.bind(this));
1429
+ }
1430
+ updateMessageHandler(message) {
1431
+ if (!message.data) {
1432
+ return;
1433
+ }
1434
+ const data = JSON.parse(message.data);
1435
+ if (data.messageType === 'LeaderBoardUpdate') {
1436
+ const { item, items, total } = data;
1437
+ if (item || this.currentUserData) {
1438
+ this.currentUserData = item ? item : this.currentUserData;
1439
+ this.leaderboardLoaded.emit({ item, isRanked: !!item, totalRank: total });
1440
+ }
1441
+ items.forEach(e => {
1442
+ const rankIdx = this.leaderboard.findIndex(rank => rank.rank === e.rank);
1443
+ rankIdx >= 0 && (this.leaderboard[rankIdx] = e);
1444
+ if (rankIdx < 0) {
1445
+ this.leaderboard.push(e);
1446
+ }
1447
+ else {
1448
+ this.leaderboard[rankIdx] = e;
1449
+ }
1450
+ });
1451
+ this.leaderboard = [...this.leaderboard];
1452
+ }
1453
+ }
1454
+ startActivePlayerObserver() {
1455
+ if (this.activePlayerObserver && this.activePlayerEle) {
1456
+ this.activePlayerObserver.unobserve(this.activePlayerEle);
1457
+ }
1458
+ this.activePlayerObserver = new IntersectionObserver(entries => {
1459
+ entries.forEach(entry => {
1460
+ this.isCurrentPlayerInview = entry.isIntersecting;
1461
+ if (!entry.isIntersecting) {
1462
+ const rect = this.activePlayerEle.getBoundingClientRect();
1463
+ if (!this.keepOnBottom) {
1464
+ this.isCurrentOnTop = rect.top < this.stylingContainer.offsetTop;
1465
+ }
1466
+ }
1467
+ });
1468
+ });
1469
+ this.activePlayerEle = this.tableListEle.querySelectorAll(`.Active`)[0];
1470
+ this.activePlayerObserver.observe(this.activePlayerEle);
1471
+ }
1472
+ startTopRankObserver() {
1473
+ if (this.topRankToObserved) {
1474
+ this.topMoreObserver.unobserve(this.topRankToObserved);
1475
+ this.topRankToObserved = null;
1476
+ }
1477
+ if (!this.topMoreObserver) {
1478
+ this.topMoreObserver = new IntersectionObserver((entries) => {
1479
+ entries.forEach((entry) => {
1480
+ if (entry.isIntersecting) {
1481
+ this.loadPreMore();
1482
+ this.topMoreObserver.unobserve(entry.target);
1483
+ }
1484
+ });
1485
+ });
1486
+ }
1487
+ setTimeout(() => {
1488
+ var _a;
1489
+ this.topRankToObserved = (_a = this.tableListEle) === null || _a === void 0 ? void 0 : _a.querySelector(`#Rank_0`);
1490
+ this.topRankToObserved && this.topMoreObserver.observe(this.topRankToObserved);
1491
+ }, this.timeOrder2); //2000
1492
+ }
1493
+ startLastRankObserver() {
1494
+ var _a;
1495
+ if (this.lastRankToObserved) {
1496
+ this.loadMoreObserver.unobserve(this.lastRankToObserved);
1497
+ this.lastRankToObserved = null;
1498
+ }
1499
+ if (!this.loadMoreObserver) {
1500
+ this.loadMoreObserver = new IntersectionObserver((entries) => {
1501
+ entries.forEach((entry) => {
1502
+ if (entry.isIntersecting) {
1503
+ this.loadMore();
1504
+ this.loadMoreObserver.unobserve(entry.target);
1505
+ }
1506
+ });
1507
+ });
1508
+ }
1509
+ this.lastRankToObserved = (_a = this.tableListEle) === null || _a === void 0 ? void 0 : _a.querySelector(`#Rank_${this.leaderboard.length - 1}`);
1510
+ this.lastRankToObserved && this.loadMoreObserver.observe(this.lastRankToObserved);
1511
+ }
1512
+ resetScrollTop() {
1513
+ this.isLoadingPrevious = false;
1514
+ setTimeout(() => {
1515
+ const scrollContainer = this.tableListEle;
1516
+ const currentScrollHeight = scrollContainer.scrollHeight;
1517
+ const heightDifference = currentScrollHeight - this.previousScrollHeight;
1518
+ scrollContainer.scrollTop = this.previousScrollTop + heightDifference;
1519
+ }, 100);
1520
+ }
1521
+ loadPreMore() {
1522
+ var _a;
1523
+ if (((_a = this.leaderboard) === null || _a === void 0 ? void 0 : _a.length) && this.leaderboard[0].rank === 1 || this.isLoadingPrevious) {
1524
+ return;
1525
+ }
1526
+ this.offset = (this.leaderboard[0].rank - 1 - this.limit) || 0;
1527
+ const scrollContainer = this.tableListEle;
1528
+ this.previousScrollHeight = scrollContainer.scrollHeight;
1529
+ this.previousScrollTop = scrollContainer.scrollTop;
1530
+ this.isLoadingPrevious = true;
1531
+ this.preTopRank = this.leaderboard[0].rank;
1532
+ this.loadLeaderboardById().catch(console.error);
1533
+ }
1534
+ goToCurrentPlayerPage() {
1535
+ if (this.leaderboard.findIndex(item => item.id === this.currentUserData.id) >= 0) {
1536
+ this.scrollCurrentPlayerToMiddle();
1537
+ return;
1538
+ }
1539
+ this.offset = this.currentUserData.rank - this.limit / 2 || 0;
1540
+ this.leaderboard = [];
1541
+ this.isLeaderboardLoading = true;
1542
+ this.loadLeaderboardById().catch(console.error);
1543
+ this.isCurrentPlayerInview = true;
1544
+ }
1545
+ loadMore() {
1546
+ var _a;
1547
+ if (((_a = this.leaderboard) === null || _a === void 0 ? void 0 : _a.length) >= this.total) {
1548
+ return;
1549
+ }
1550
+ this.offset += this.limit;
1551
+ this.offset = this.offset > this.total ? this.total : this.offset;
1552
+ this.loadLeaderboardById().catch(console.error);
1553
+ }
1554
+ handleTableListScroll() {
1555
+ this.isCurrentPlayerInview = this.isElementInViewport();
1556
+ }
1557
+ isElementInViewport() {
1558
+ const activePlayerRow = this.tableListEle.querySelector(`.Active`);
1559
+ if (!activePlayerRow) {
1560
+ return false;
1561
+ }
1562
+ const rect = activePlayerRow.getBoundingClientRect();
1563
+ this.isCurrentOnTop = rect.top < this.stylingContainer.offsetTop;
1564
+ return (rect.top >= 0 && rect.top > this.stylingContainer.offsetTop &&
1565
+ rect.bottom <= (this.stylingContainer.offsetTop + this.stylingContainer.offsetHeight) &&
1566
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight));
1567
+ }
1568
+ onTournamentIdChanged() {
1569
+ this.disconnectedCallback();
1570
+ if (!this.endpoint || !this.session || this.session.length < 10 || !this.tournamentId) {
1571
+ return;
1572
+ }
1573
+ this.isLeaderboardLoading = true;
1574
+ this.resetLeaderboardStatus();
1575
+ this.loadLeaderboardById().catch(console.error);
1576
+ }
1577
+ resetLeaderboardStatus() {
1578
+ this.offset = 0;
1579
+ this.leaderboard = [];
1580
+ }
1581
+ componentWillLoad() {
1582
+ switch (this.state) {
1583
+ case 'Running':
1584
+ this.loadLeaderboardById().catch(console.error);
1585
+ break;
1586
+ case 'Unstarted':
1587
+ this.isLeaderboardLoading = false;
1588
+ this.resetLeaderboardStatus();
1589
+ break;
1590
+ }
1591
+ }
1592
+ render() {
1593
+ var _a;
1594
+ return index.h("div", { key: '0ea2213099af1f2e39cf38e636a181ae0b8111df', class: `LeaderboardWrapper ${this.theme} ${this.isMobile ? 'Mobile' : ''}`, ref: (el) => (this.stylingContainer = el) }, this.isLeaderboardLoading ? index.h("div", { class: 'Loading' }, " ", translate('loading', this.language), " ") :
1595
+ [
1596
+ index.h("div", null, (!this.isCurrentPlayerInview && this.isCurrentOnTop) && this.currentUserData &&
1597
+ index.h("div", { class: `PlayerRank Active` }, index.h("div", { class: 'Rank' }, this.currentUserData.rank === 0 ? '--' : this.currentUserData.rank), index.h("div", { class: 'Name' }, translate('you', this.language)), index.h("div", { class: 'Score' }, this.currentUserData.score), index.h("div", { class: 'Prize' }, this.currentUserData.prizeName))),
1598
+ this.isLoadingPrevious && index.h("div", null, "Loading"),
1599
+ index.h("div", { class: 'Leaderboard', onScroll: this.onLeaderboardScroll.bind(this), onTouchMove: this.onLeaderboardScroll.bind(this), ref: (el) => (this.tableListEle = el) }, !((_a = this.leaderboard) === null || _a === void 0 ? void 0 : _a.length)
1600
+ ? index.h("div", { class: 'NoWinners' }, index.h("div", { class: 'Title' }, " ", translate('noLeaderboard', this.language), " "), index.h("div", { class: 'Info' }, " ", translate('positionsWillShow', this.language), " "))
1601
+ : this.leaderboard.map((item, idx) => {
1602
+ var _a, _b;
1603
+ return index.h("div", { id: `Rank_${idx}`, class: `PlayerRank ${this.isLoadingPrevious && item.rank < this.preTopRank ? 'Hidden' : ''} ${((_a = this.currentUserData) === null || _a === void 0 ? void 0 : _a.id) === item.id ? 'Active' : ''}` }, index.h("div", { class: 'Rank' }, item.rank === 0 ? '' : item.rank), index.h("div", { class: 'Name' }, (((_b = this.currentUserData) === null || _b === void 0 ? void 0 : _b.id) === item.id) ? translate('you', this.language) : item.shortName), index.h("div", { class: 'Score' }, item.score), index.h("div", { class: 'Prize' }, item.prizeName));
1604
+ })),
1605
+ this.isLoadingMore && !this.isLoadingPrevious && index.h("div", null, "Loading"),
1606
+ !this.isCurrentPlayerInview &&
1607
+ index.h("div", { class: !this.isCurrentOnTop ? 'Bottom' : '' }, !this.isCurrentOnTop && this.currentUserData &&
1608
+ index.h("div", { class: `PlayerRank Active`, onClick: this.goToCurrentPlayerPage.bind(this) }, index.h("div", { class: 'Rank' }, this.currentUserData.rank === 0 ? '--' : this.currentUserData.rank), index.h("div", { class: 'Name' }, translate('you', this.language)), index.h("div", { class: 'Score' }, this.currentUserData.score), index.h("div", { class: 'Prize' }, this.currentUserData.prizeName)))
1609
+ ]);
1610
+ }
1611
+ handleClientStylingChange(newValue, oldValue) {
1612
+ if (newValue != oldValue) {
1613
+ setClientStyling(this.stylingContainer, this.clientStyling);
1614
+ }
1615
+ }
1616
+ handleClientStylingUrlChange(newValue, oldValue) {
1617
+ if (newValue != oldValue) {
1618
+ setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
1619
+ }
1620
+ }
1621
+ handleMbSourceChange(newValue, oldValue) {
1622
+ if (newValue != oldValue) {
1623
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
1624
+ }
1625
+ }
1626
+ componentDidLoad() {
1627
+ if (this.stylingContainer) {
1628
+ if (this.mbSource)
1629
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
1630
+ if (this.clientStyling)
1631
+ setClientStyling(this.stylingContainer, this.clientStyling);
1632
+ if (this.clientStylingUrl)
1633
+ setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
1634
+ }
1635
+ this.isMobile = getDevice() !== 'PC';
1636
+ }
1637
+ disconnectedCallback() {
1638
+ if (this.abortController) {
1639
+ this.abortController.abort('Disconnected callback');
1640
+ }
1641
+ this.stylingSubscription && this.stylingSubscription.unsubscribe();
1642
+ this.leaderboardUpdater && this.leaderboardUpdater.close();
1643
+ if (this.leaderboardUpdater) {
1644
+ this.leaderboardUpdater.close();
1645
+ this.leaderboardUpdater.removeEventListener('message', this.updateMessageHandler);
1646
+ }
1647
+ this.loadMoreObserver && this.loadMoreObserver.disconnect();
1648
+ this.topMoreObserver && this.topMoreObserver.disconnect();
1649
+ this.activePlayerObserver && this.activePlayerObserver.disconnect();
1650
+ if (this.tableListEle) {
1651
+ this.tableListEle.removeEventListener('scroll', this.handleTableListScroll.bind(this));
1652
+ }
1653
+ }
1654
+ static get watchers() { return {
1655
+ "state": ["onStateChanged"],
1656
+ "tournamentId": ["onTournamentIdChanged"],
1657
+ "endpoint": ["onTournamentIdChanged"],
1658
+ "session": ["onTournamentIdChanged"],
1659
+ "language": ["onTournamentIdChanged"],
1660
+ "clientStyling": ["handleClientStylingChange"],
1661
+ "clientStylingUrl": ["handleClientStylingUrlChange"],
1662
+ "mbSource": ["handleMbSourceChange"]
1663
+ }; }
1664
+ };
1665
+ CasinoTournamentsIngameTable.style = CasinoTournamentsIngameTableStyle0;
1666
+
1667
+ exports.CasinoTournamentsIngameTable = CasinoTournamentsIngameTable;