@streamlayer/react 0.2.12 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js DELETED
@@ -1,3081 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // node_modules/.pnpm/@esbuild-plugins+node-globals-polyfill@0.2.3_esbuild@0.19.5/node_modules/@esbuild-plugins/node-globals-polyfill/process.js
8
- function defaultSetTimout() {
9
- throw new Error("setTimeout has not been defined");
10
- }
11
- function defaultClearTimeout() {
12
- throw new Error("clearTimeout has not been defined");
13
- }
14
- var cachedSetTimeout = defaultSetTimout;
15
- var cachedClearTimeout = defaultClearTimeout;
16
- if (typeof globalThis.setTimeout === "function") {
17
- cachedSetTimeout = setTimeout;
18
- }
19
- if (typeof globalThis.clearTimeout === "function") {
20
- cachedClearTimeout = clearTimeout;
21
- }
22
- function runTimeout(fun) {
23
- if (cachedSetTimeout === setTimeout) {
24
- return setTimeout(fun, 0);
25
- }
26
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
27
- cachedSetTimeout = setTimeout;
28
- return setTimeout(fun, 0);
29
- }
30
- try {
31
- return cachedSetTimeout(fun, 0);
32
- } catch (e) {
33
- try {
34
- return cachedSetTimeout.call(null, fun, 0);
35
- } catch (e2) {
36
- return cachedSetTimeout.call(this, fun, 0);
37
- }
38
- }
39
- }
40
- function runClearTimeout(marker) {
41
- if (cachedClearTimeout === clearTimeout) {
42
- return clearTimeout(marker);
43
- }
44
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
45
- cachedClearTimeout = clearTimeout;
46
- return clearTimeout(marker);
47
- }
48
- try {
49
- return cachedClearTimeout(marker);
50
- } catch (e) {
51
- try {
52
- return cachedClearTimeout.call(null, marker);
53
- } catch (e2) {
54
- return cachedClearTimeout.call(this, marker);
55
- }
56
- }
57
- }
58
- var queue = [];
59
- var draining = false;
60
- var currentQueue;
61
- var queueIndex = -1;
62
- function cleanUpNextTick() {
63
- if (!draining || !currentQueue) {
64
- return;
65
- }
66
- draining = false;
67
- if (currentQueue.length) {
68
- queue = currentQueue.concat(queue);
69
- } else {
70
- queueIndex = -1;
71
- }
72
- if (queue.length) {
73
- drainQueue();
74
- }
75
- }
76
- function drainQueue() {
77
- if (draining) {
78
- return;
79
- }
80
- var timeout = runTimeout(cleanUpNextTick);
81
- draining = true;
82
- var len = queue.length;
83
- while (len) {
84
- currentQueue = queue;
85
- queue = [];
86
- while (++queueIndex < len) {
87
- if (currentQueue) {
88
- currentQueue[queueIndex].run();
89
- }
90
- }
91
- queueIndex = -1;
92
- len = queue.length;
93
- }
94
- currentQueue = null;
95
- draining = false;
96
- runClearTimeout(timeout);
97
- }
98
- function nextTick(fun) {
99
- var args = new Array(arguments.length - 1);
100
- if (arguments.length > 1) {
101
- for (var i = 1; i < arguments.length; i++) {
102
- args[i - 1] = arguments[i];
103
- }
104
- }
105
- queue.push(new Item(fun, args));
106
- if (queue.length === 1 && !draining) {
107
- runTimeout(drainQueue);
108
- }
109
- }
110
- function Item(fun, array) {
111
- this.fun = fun;
112
- this.array = array;
113
- }
114
- Item.prototype.run = function() {
115
- this.fun.apply(null, this.array);
116
- };
117
- var title = "browser";
118
- var platform = "browser";
119
- var browser = true;
120
- var env = {};
121
- var argv = [];
122
- var version = "";
123
- var versions = {};
124
- var release = {};
125
- var config = {};
126
- function noop() {
127
- }
128
- var on = noop;
129
- var addListener = noop;
130
- var once = noop;
131
- var off = noop;
132
- var removeListener = noop;
133
- var removeAllListeners = noop;
134
- var emit = noop;
135
- function binding(name) {
136
- throw new Error("process.binding is not supported");
137
- }
138
- function cwd() {
139
- return "/";
140
- }
141
- function chdir(dir) {
142
- throw new Error("process.chdir is not supported");
143
- }
144
- function umask() {
145
- return 0;
146
- }
147
- var performance = globalThis.performance || {};
148
- var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() {
149
- return (/* @__PURE__ */ new Date()).getTime();
150
- };
151
- function hrtime(previousTimestamp) {
152
- var clocktime = performanceNow.call(performance) * 1e-3;
153
- var seconds = Math.floor(clocktime);
154
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
155
- if (previousTimestamp) {
156
- seconds = seconds - previousTimestamp[0];
157
- nanoseconds = nanoseconds - previousTimestamp[1];
158
- if (nanoseconds < 0) {
159
- seconds--;
160
- nanoseconds += 1e9;
161
- }
162
- }
163
- return [seconds, nanoseconds];
164
- }
165
- var startTime = /* @__PURE__ */ new Date();
166
- function uptime() {
167
- var currentTime = /* @__PURE__ */ new Date();
168
- var dif = currentTime - startTime;
169
- return dif / 1e3;
170
- }
171
- var process = {
172
- nextTick,
173
- title,
174
- browser,
175
- env,
176
- argv,
177
- version,
178
- versions,
179
- on,
180
- addListener,
181
- once,
182
- off,
183
- removeListener,
184
- removeAllListeners,
185
- emit,
186
- binding,
187
- cwd,
188
- chdir,
189
- umask,
190
- hrtime,
191
- platform,
192
- release,
193
- config,
194
- uptime
195
- };
196
- var defines = {};
197
- Object.keys(defines).forEach((key) => {
198
- const segs = key.split(".");
199
- let target = process;
200
- for (let i = 0; i < segs.length; i++) {
201
- const seg = segs[i];
202
- if (i === segs.length - 1) {
203
- target[seg] = defines[key];
204
- } else {
205
- target = target[seg] || (target[seg] = {});
206
- }
207
- }
208
- });
209
-
210
- // packages/react-ui/src/lib/gamification/inapp/index.tsx
211
- import { useCallback } from "react";
212
-
213
- // packages/react-ui/src/assets/icons/icon-exit.svg
214
- var icon_exit_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A <rect width="24" height="24" rx="12" fill="white" fill-opacity="0.1"/>%0A <rect x="8.25" y="7" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(45 8.25 7)" fill="white"/>%0A <rect x="7" y="15.75" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(-45 7 15.75)" fill="white"/>%0A</svg>%0A';
215
-
216
- // packages/react-ui/src/lib/gamification/inapp/styles.tsx
217
- import styled from "@emotion/styled";
218
- var Container = styled.div`
219
- box-sizing: border-box;
220
- border: ${(props) => `1px solid ${props.theme.COLORS.BLUE_PRIMARY}`};
221
- border-radius: 13px;
222
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT};
223
- color: ${(props) => props.theme.COLORS.WHITE};
224
- display: flex;
225
- user-select: none;
226
- cursor: pointer;
227
- overflow: hidden;
228
- animation: slidein 0.3s ease-in;
229
-
230
- @keyframes slidein {
231
- from {
232
- transform: translateX(-100%);
233
- }
234
-
235
- to {
236
- transform: translateX(0);
237
- }
238
- }
239
- `;
240
- var IconWrap = styled.div`
241
- display: flex;
242
- justify-content: center;
243
- align-items: center;
244
- padding: 14px;
245
- background-color: ${(props) => props.theme.COLORS.BLUE_PRIMARY};
246
- `;
247
- var Icon = styled.img`
248
- max-width: 40px;
249
- max-height: 40px;
250
- width: 100%;
251
- height: 100%;
252
- border-radius: 50%;
253
- `;
254
- var Content = styled.div`
255
- display: flex;
256
- justify-content: space-between;
257
- width: 100%;
258
- align-items: center;
259
- `;
260
- var TitleWrap = styled.div`
261
- padding-left: 20px;
262
- padding-right: 5px;
263
- font-weight: 700;
264
- font-size: 14px;
265
- flex: 1;
266
- `;
267
- var Title = styled.div`
268
- display: -webkit-box;
269
- -webkit-box-orient: vertical;
270
- -webkit-line-clamp: 2;
271
- overflow: hidden;
272
- text-overflow: ellipsis;
273
- `;
274
- var CloseBtnWrap = styled.div`
275
- padding: 20px;
276
- `;
277
- var CloseBtn = styled.button`
278
- border: none;
279
- outline: none;
280
- background-color: transparent;
281
- cursor: pointer;
282
- display: flex;
283
- justify-content: center;
284
- align-items: center;
285
- `;
286
- var CloseIcon = styled.img`
287
- width: 24px;
288
- height: 24px;
289
- `;
290
-
291
- // packages/react-ui/src/lib/gamification/inapp/index.tsx
292
- import { jsx, jsxs } from "@emotion/react/jsx-runtime";
293
- var InApp = ({ title: title2 = "", icon, color, openVoiting, closeInApp }) => {
294
- const _closeInApp = useCallback(
295
- (e) => {
296
- e.stopPropagation();
297
- closeInApp();
298
- },
299
- [closeInApp]
300
- );
301
- return /* @__PURE__ */ jsxs(Container, { onClick: openVoiting, children: [
302
- /* @__PURE__ */ jsx(IconWrap, { style: color ? { backgroundColor: color } : {}, children: !!icon && /* @__PURE__ */ jsx(Icon, { alt: "in-app-icon", src: icon }) }),
303
- /* @__PURE__ */ jsxs(Content, { children: [
304
- /* @__PURE__ */ jsx(TitleWrap, { children: /* @__PURE__ */ jsx(Title, { id: "in-app-title", children: title2 }) }),
305
- /* @__PURE__ */ jsx(CloseBtnWrap, { children: /* @__PURE__ */ jsx(CloseBtn, { onClick: _closeInApp, children: /* @__PURE__ */ jsx(CloseIcon, { alt: "close-in-app-icon", src: icon_exit_default }) }) })
306
- ] })
307
- ] });
308
- };
309
-
310
- // packages/react-ui/src/lib/gamification/login/index.tsx
311
- import { useState } from "react";
312
- import PhoneInput, { isValidPhoneNumber, formatPhoneNumberIntl } from "react-phone-number-input";
313
- import "react-phone-number-input/style.css";
314
- import useDigitInput from "react-digit-input";
315
-
316
- // packages/react-ui/src/utils/login.ts
317
- import { createGrpcWebTransport } from "@bufbuild/connect-web";
318
- import { createPromiseClient } from "@connectrpc/connect";
319
- import { Users } from "@streamlayer/sl-eslib/users/users_connect";
320
- var requestLoginCode = async (phone) => {
321
- const transport2 = createGrpcWebTransport({
322
- baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
323
- });
324
- const userClient = createPromiseClient(Users, transport2);
325
- await userClient.requestPassword({ id: phone });
326
- return true;
327
- };
328
- var register = async (phone) => {
329
- const transport2 = createGrpcWebTransport({
330
- baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
331
- });
332
- const userClient = createPromiseClient(Users, transport2);
333
- await userClient.register({ id: phone });
334
- return true;
335
- };
336
- var login = async (phone, code) => {
337
- const transport2 = createGrpcWebTransport({
338
- baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443"
339
- });
340
- const userClient = createPromiseClient(Users, transport2);
341
- const res = await userClient.login({ id: phone, password: code });
342
- return res?.meta?.jwt;
343
- };
344
-
345
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
346
- import { useEffect } from "react";
347
- import { CountdownCircleTimer } from "react-countdown-circle-timer";
348
-
349
- // packages/react-ui/src/lib/theme/theme.ts
350
- var theme = {
351
- COLORS: {
352
- BG_TRANSPARENT: "rgba(0,0,0, .8)",
353
- BG_TRANSPARENT_VOTE_CONTAINER: "rgba(10, 14, 19, 0.8)",
354
- BG_TRANSPARENT_ITEM: "rgba(0, 0, 0, 0.7)",
355
- BG_TRANSPARENT_ITEM_VOTE: "rgba(255, 255, 255, 0.1)",
356
- BG_TRANSPARENT_ITEM_SUCCESS: "rgba(0, 139, 251, 0.2)",
357
- BG_TRANSPARENT_ITEM_ERROR: "rgba(205, 37, 37, 0.2)",
358
- BG_TRANSPARENT_VOTE_PROGRESS: "rgba(255, 255, 255, 0.2)",
359
- BG_TRANSPARENT_VOTE_PROGRESS_SUCCESS: "rgba(60, 139, 251, 0.5)",
360
- BG_TRANSPARENT_VOTE_PROGRESS_ERROR: "rgba(205, 37, 37, 0.5)",
361
- BG_TRANSPARENT_USER_CONTAINER: "rgba(255, 255, 255, 0.05)",
362
- BLUE_PRIMARY: "#1589EE",
363
- RED_PRIMARY: "#CD2525",
364
- BLUE_QUESTION_ACTION_BTN: "#1589ee",
365
- WHITE: "#FFFFFF",
366
- GREY_1: "#909395",
367
- GREY_2: "#22262b",
368
- GREY_3: "#2d3135",
369
- GREY_4: "#53565a",
370
- BLACK_1: "#161a1f",
371
- GREEN_1: "#F7B801",
372
- RED_1: "#A30000",
373
- RED_2: "#FF4170",
374
- GREY_PRIMARY: "#909395",
375
- DIVIDER_COLOR_PRIMARY: "#2d3135",
376
- DIVIDER_COLOR_SECONDARY: "#53565a",
377
- GREEN_PRIMARY_BTN: "#009B77"
378
- },
379
- FONT: {
380
- FAMILY: "Roboto, sans-serif",
381
- COLOR: "#fff"
382
- }
383
- };
384
-
385
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/styles.tsx
386
- import styled2 from "@emotion/styled";
387
- var RemainingTime = styled2.div`
388
- color: ${(props) => props.remainingTime ? "inherit" : props.theme.COLORS.RED_2};
389
- font-size: 12px;
390
- `;
391
-
392
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/timer/index.tsx
393
- import { jsx as jsx2 } from "@emotion/react/jsx-runtime";
394
- var TIMER_COLORS = [theme.COLORS.BLUE_PRIMARY, theme.COLORS.GREEN_1, theme.COLORS.RED_1];
395
- var TIMER_COLORS_TIME = [10, 6, 0];
396
- var DEFAULT_DURATION = 30;
397
- var TIMER_SIZE = 32;
398
- var STROKE_WIDTH = 4;
399
- var TRAIL_STROKE_WIDTH = 0;
400
- var Timer = ({ isPlaying = true, duration = DEFAULT_DURATION, setTimeToExpire }) => {
401
- const renderTime = ({ remainingTime }) => /* @__PURE__ */ jsx2(RemainingTime, { remainingTime, children: remainingTime });
402
- useEffect(() => {
403
- setTimeToExpire(false);
404
- }, [setTimeToExpire]);
405
- return /* @__PURE__ */ jsx2(
406
- CountdownCircleTimer,
407
- {
408
- isPlaying,
409
- duration,
410
- colors: TIMER_COLORS,
411
- colorsTime: TIMER_COLORS_TIME,
412
- size: TIMER_SIZE,
413
- strokeWidth: STROKE_WIDTH,
414
- trailStrokeWidth: TRAIL_STROKE_WIDTH,
415
- onComplete: () => setTimeToExpire(true),
416
- children: renderTime
417
- }
418
- );
419
- };
420
-
421
- // packages/react-ui/src/lib/gamification/login/styles.tsx
422
- import styled3 from "@emotion/styled";
423
- var Panel = styled3.div`
424
- border-radius: 8px;
425
- padding: 0 12px;
426
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
427
- display: flex;
428
- align-items: center;
429
- height: 100%;
430
- `;
431
- var Form = styled3.form`
432
- display: flex;
433
- margin: auto;
434
- flex-direction: column;
435
- align-items: center;
436
- text-align: center;
437
- `;
438
- var FormTitle = styled3.div`
439
- margin-bottom: 20px;
440
- font-size: 18px;
441
- `;
442
- var FormDescription = styled3.div`
443
- margin-bottom: 10px;
444
- font-size: 14px;
445
-
446
- display: flex;
447
- align-items: center;
448
- flex-direction: column;
449
- `;
450
- var FormSubmit = styled3.button`
451
- background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
452
- border: none;
453
- border-radius: 2px;
454
- padding: 6px;
455
- text-transform: uppercase;
456
- color: #fff;
457
- cursor: pointer;
458
-
459
- &:disabled {
460
- opacity: 0.5;
461
- cursor: default;
462
- }
463
- margin-bottom: 20px;
464
- `;
465
- var FormInputContainer = styled3.div`
466
- input {
467
- font-size: 20px;
468
- background: transparent;
469
- color: #fff;
470
- border: none;
471
- outline: none;
472
- }
473
-
474
- margin-bottom: 40px;
475
- border-bottom: 1px solid white;
476
- `;
477
- var Digits = styled3.div`
478
- display: flex;
479
- gap: 10px;
480
- margin-bottom: 20px;
481
-
482
- input {
483
- width: 20px;
484
- height: 40px;
485
- font-size: 40px;
486
- }
487
- `;
488
-
489
- // packages/react-ui/src/lib/gamification/login/index.tsx
490
- import { jsx as jsx3, jsxs as jsxs2 } from "@emotion/react/jsx-runtime";
491
- var Login = ({ login: login2, anonymousLogin }) => {
492
- const [phoneInput, setPhoneInput] = useState("");
493
- const [phone, setPhone] = useState("");
494
- const [code, setCode] = useState("");
495
- const digits = useDigitInput({
496
- acceptedCharacters: /^[0-9]$/,
497
- length: 4,
498
- value: code,
499
- onChange: setCode
500
- });
501
- const requestCode = async (e) => {
502
- e.preventDefault();
503
- try {
504
- const parsed = phoneInput.replaceAll("+", "");
505
- try {
506
- await requestLoginCode(parsed);
507
- } catch (err) {
508
- await register(parsed);
509
- }
510
- setPhone(parsed);
511
- } catch (err) {
512
- window.alert(err);
513
- }
514
- };
515
- const loginByCode = async (e) => {
516
- e.preventDefault();
517
- if (phone && code) {
518
- try {
519
- const token = await login(phone, code);
520
- if (token && login2) {
521
- await login2(token);
522
- } else {
523
- console.log("token", token);
524
- }
525
- } catch (err) {
526
- window.alert(err);
527
- }
528
- }
529
- };
530
- return /* @__PURE__ */ jsxs2(Panel, { children: [
531
- !phone && /* @__PURE__ */ jsxs2("div", { children: [
532
- /* @__PURE__ */ jsxs2(Form, { onSubmit: requestCode, children: [
533
- /* @__PURE__ */ jsx3(FormTitle, { children: "Enter your phone number" }),
534
- /* @__PURE__ */ jsx3(FormDescription, { children: "Enter your phone up for number to log in or sign an account." }),
535
- /* @__PURE__ */ jsx3(FormInputContainer, { children: /* @__PURE__ */ jsx3(PhoneInput, { value: phoneInput, onChange: (val) => setPhoneInput(`${val}`) }) }),
536
- /* @__PURE__ */ jsx3(FormSubmit, { disabled: !isValidPhoneNumber(phoneInput), type: "submit", children: "request code" })
537
- ] }),
538
- anonymousLogin && /* @__PURE__ */ jsx3(FormSubmit, { style: { display: "block", margin: "auto" }, onClick: anonymousLogin, children: "anonymous login" })
539
- ] }),
540
- phone && /* @__PURE__ */ jsxs2(Form, { onSubmit: loginByCode, children: [
541
- /* @__PURE__ */ jsx3(FormTitle, { children: "Enter Verification Code" }),
542
- /* @__PURE__ */ jsxs2(FormDescription, { children: [
543
- "Please enter the verification code ",
544
- /* @__PURE__ */ jsx3("br", {}),
545
- "sent to ",
546
- /* @__PURE__ */ jsx3("b", { children: formatPhoneNumberIntl(phoneInput) })
547
- ] }),
548
- /* @__PURE__ */ jsxs2(Digits, { children: [
549
- /* @__PURE__ */ jsx3("input", { autoFocus: true, inputMode: "decimal", ...digits[0] }),
550
- /* @__PURE__ */ jsx3("input", { inputMode: "decimal", ...digits[1] }),
551
- /* @__PURE__ */ jsx3("input", { inputMode: "decimal", ...digits[2] }),
552
- /* @__PURE__ */ jsx3("input", { inputMode: "decimal", ...digits[3] })
553
- ] }),
554
- /* @__PURE__ */ jsx3(FormSubmit, { disabled: code.length !== 4, type: "submit", children: "login" }),
555
- /* @__PURE__ */ jsxs2(FormDescription, { children: [
556
- "Didn't get 59 the code? ",
557
- /* @__PURE__ */ jsx3("br", {}),
558
- "Resend Code in",
559
- /* @__PURE__ */ jsx3(Timer, { duration: 30, setTimeToExpire: () => {
560
- }, isPlaying: true })
561
- ] })
562
- ] })
563
- ] });
564
- };
565
-
566
- // packages/react-ui/src/lib/gamification/onboarding/styles.tsx
567
- import styled4 from "@emotion/styled";
568
- var Container2 = styled4.div`
569
- box-sizing: border-box;
570
- display: flex;
571
- color: ${(props) => props.theme.COLORS.WHITE};
572
- flex-direction: column;
573
- height: 100%;
574
- width: 100%;
575
- `;
576
- var Content2 = styled4.div`
577
- flex: 1;
578
- display: flex;
579
- justify-content: center;
580
- flex-direction: column;
581
- align-items: center;
582
- `;
583
- var Description = styled4.div`
584
- font-size: 22px;
585
- font-weight: 300;
586
- margin-bottom: 4px;
587
- `;
588
- var Title2 = styled4.div`
589
- font-size: 26px;
590
- font-weight: 700;
591
- `;
592
- var OnboardingActionBtn = styled4.button`
593
- color: ${(props) => props.theme.COLORS.WHITE};
594
- width: 100%;
595
- border: none;
596
- outline: none;
597
- background-color: ${(props) => props.theme.COLORS.GREEN_PRIMARY_BTN};
598
- cursor: pointer;
599
- padding: 12px 16px;
600
- display: flex;
601
- justify-content: center;
602
- align-items: center;
603
- font-size: 16px;
604
- font-weight: 600;
605
- border-radius: 6px;
606
- `;
607
-
608
- // packages/react-ui/src/lib/gamification/onboarding/index.tsx
609
- import { jsx as jsx4, jsxs as jsxs3 } from "@emotion/react/jsx-runtime";
610
- var Onboarding = ({ action }) => /* @__PURE__ */ jsxs3(Container2, { children: [
611
- /* @__PURE__ */ jsxs3(Content2, { children: [
612
- /* @__PURE__ */ jsx4(Description, { children: "Welcome to the" }),
613
- /* @__PURE__ */ jsx4(Title2, { children: "Inplay Game" })
614
- ] }),
615
- /* @__PURE__ */ jsx4(OnboardingActionBtn, { onClick: action, children: "Let\u2019s play" })
616
- ] });
617
-
618
- // packages/sdk-web-types/src/sl-types.ts
619
- import { QuestionType, QuestionStatus } from "@streamlayer/sl-eslib/interactive/interactive.common_pb";
620
- import { PickHistoryStatus } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb";
621
- import { SdkOverlayType } from "@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb";
622
-
623
- // packages/react-ui/src/assets/icons/icon-poll.svg
624
- var icon_poll_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Poll">%0A<path id="Notification/Icon/Poll" fill-rule="evenodd" clip-rule="evenodd" d="M9.7778 1.68421V5.05263H13.3333C13.8243 5.05263 14.2222 4.67561 14.2222 4.21053V2.52632C14.2222 2.06123 13.8243 1.68421 13.3333 1.68421H9.7778ZM2.66667 0C1.19391 0 0 1.13107 0 2.52632V4.21053C0 5.60577 1.19391 6.73684 2.66667 6.73684H13.3333C14.8061 6.73684 16 5.60577 16 4.21053V2.52632C16 1.13107 14.8061 0 13.3333 0H2.66667ZM4.44446 10.9473H13.3333C13.8243 10.9473 14.2222 11.3243 14.2222 11.7894V13.4736C14.2222 13.9387 13.8243 14.3157 13.3333 14.3157H4.44446V10.9473ZM0 11.7894C0 10.3942 1.19391 9.2631 2.66667 9.2631H13.3333C14.8061 9.2631 16 10.3942 16 11.7894V13.4736C16 14.8689 14.8061 15.9999 13.3333 15.9999H2.66667C1.19391 15.9999 0 14.8689 0 13.4736V11.7894Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
625
-
626
- // packages/react-ui/src/assets/icons/icon-prediction.svg
627
- var icon_prediction_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Icon/Notification/Prediciton">%0A<path id="Icon/Prediction" fill-rule="evenodd" clip-rule="evenodd" d="M16 7.00522C16 7.00522 9.20048 6.81607 9.20048 0C9.20048 6.36168 3.27729 6.95056 2.48756 7.00078L2.40094 7.00522C2.40094 7.00522 9.20048 7.19435 9.20048 14.0104C9.20048 7.64877 15.1234 7.05989 15.9131 7.00964L16 7.00522ZM6.97382 12.5652C6.97382 12.5652 3.48691 12.4724 3.48691 9.13033C3.48691 12.2496 0.449402 12.5384 0.0444186 12.563L0 12.5652C0 12.5652 3.48691 12.6579 3.48691 16C3.48691 12.8807 6.52429 12.592 6.92927 12.5673L6.97382 12.5652Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
628
-
629
- // packages/react-ui/src/assets/icons/icon-trivia.svg
630
- var icon_trivia_default = 'data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Icon/Notification/Trivia">%0A<path id="Notification/Icon/Trivia" fill-rule="evenodd" clip-rule="evenodd" d="M2.01663 1.3808C0.739913 1.55586 -0.153153 2.73276 0.021912 4.00948L1.3808 13.9196C1.55586 15.1963 2.73276 16.0894 4.00948 15.9143L13.9196 14.5554C15.1963 14.3803 16.0894 13.2034 15.9143 11.9267L14.5554 2.01663C14.3803 0.739913 13.2034 -0.153153 11.9267 0.021912L2.01663 1.3808ZM9.59613 3.788C9.11431 3.46991 8.47813 3.30151 7.7566 3.30151C7.54377 3.30151 7.32625 3.31671 7.10872 3.34478C6.38836 3.44067 5.68901 3.79034 5.18965 4.30138C4.68445 4.82062 4.4377 5.45563 4.51722 6.04151C4.57452 6.4742 4.90078 6.7537 5.34635 6.7537C5.39429 6.7537 5.44341 6.7502 5.49136 6.74435C6.08778 6.66483 6.21642 6.25436 6.34036 5.85675L6.34045 5.85648C6.48192 5.40401 6.61534 4.97731 7.38585 4.87444C7.46537 4.86391 7.54138 4.85806 7.61506 4.85806C8.16939 4.85806 8.51436 5.15042 8.58454 5.68252C8.65353 6.20293 8.24307 6.61807 7.80684 7.0566L7.80393 7.05954C7.31582 7.55231 6.7639 8.1095 6.86895 8.90083C6.89585 9.10548 6.9859 9.29493 7.12272 9.43644C7.27826 9.599 7.4829 9.68436 7.71331 9.68436C7.75541 9.68436 7.79868 9.68203 7.84311 9.67618C8.46691 9.59324 8.55162 9.23139 8.63338 8.8821L8.63365 8.88097L8.63661 8.86859C8.66723 8.7403 8.69877 8.60813 8.75995 8.48804C8.84649 8.31613 9.06283 8.11265 9.31428 7.87875C9.9142 7.31858 10.734 6.55143 10.582 5.41589C10.4872 4.70603 10.1551 4.15757 9.59611 3.78802L9.59613 3.788ZM8.11605 10.28C8.06927 10.28 8.02132 10.2836 7.97454 10.2894C7.38396 10.3689 6.96765 10.9127 7.04599 11.5033C7.11733 12.0377 7.57808 12.4412 8.1172 12.4412C8.16397 12.4412 8.21192 12.4377 8.25987 12.4318C8.85045 12.3523 9.2656 11.8085 9.18842 11.2179C9.11591 10.6823 8.65517 10.28 8.11605 10.28Z" fill="white" fill-opacity="0.5"/>%0A</g>%0A</svg>%0A';
631
-
632
- // packages/react-ui/src/assets/icons/icon-check-green.svg
633
- var icon_check_green_default = 'data:image/svg+xml,<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Check">%0A<path id="Vector" d="M13.4315 3.18246L5.53321 11.0808L1.99771 7.54527C1.54056 7.08811 0.799913 7.08811 0.342864 7.54527C-0.114288 8.00242 -0.114288 8.74307 0.342864 9.20011L4.70567 13.5629C4.93331 13.7906 5.23415 13.9063 5.53307 13.9063C5.83202 13.9063 6.13096 13.7924 6.36048 13.5629L15.0861 4.83731C15.5432 4.38016 15.5432 3.63951 15.0861 3.18246C14.629 2.72531 13.8884 2.72531 13.4312 3.18246H13.4315Z" fill="%2300BD60"/>%0A</g>%0A</svg>%0A';
634
-
635
- // packages/react-ui/src/assets/icons/icon-cross.svg
636
- var icon_cross_default = 'data:image/svg+xml,<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Group 465">%0A<rect id="Rectangle 368" x="2" y="0.506104" width="16.4992" height="2.35702" rx="1.17851" transform="rotate(45 2 0.506104)" fill="%239e0a1f"/>%0A<rect id="Rectangle 369" x="0.333008" y="12.1729" width="16.4992" height="2.35702" rx="1.17851" transform="rotate(-45 0.333008 12.1729)" fill="%239e0a1f"/>%0A</g>%0A</svg>%0A';
637
-
638
- // packages/react-ui/src/assets/icons/icon-chevron.svg
639
- var icon_chevron_default = 'data:image/svg+xml,<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Chevron">%0A<path id="Chevron_2" d="M12 8.17222C12 8.28783 11.9781 8.39553 11.9342 8.49533C11.8903 8.59513 11.822 8.68992 11.7292 8.7797L6.36949 13.9439C6.21462 14.0965 6.02742 14.1729 5.80787 14.1729C5.65752 14.1729 5.52191 14.1379 5.40104 14.0679C5.28016 13.998 5.1831 13.9039 5.10986 13.7856C5.03662 13.6673 5 13.5345 5 13.3873C5 13.1721 5.08288 12.9818 5.24863 12.8164L10.0807 8.17095L5.24863 3.52799C5.08288 3.36425 5 3.17439 5 2.95841C5 2.81118 5.03662 2.67842 5.10986 2.56013C5.1831 2.44183 5.28016 2.34771 5.40104 2.27777C5.52191 2.20782 5.65752 2.17285 5.80787 2.17285C6.02742 2.17285 6.21462 2.24731 6.36949 2.39624L11.7292 7.56473C11.8211 7.65451 11.889 7.74909 11.9329 7.84846C11.9768 7.94784 11.9991 8.05576 12 8.17222Z" fill="%23FFFFFF"/>%0A</g>%0A</svg>%0A';
640
-
641
- // packages/react-ui/src/lib/gamification/question/styles.tsx
642
- import styled5 from "@emotion/styled";
643
- var Panel2 = styled5.div`
644
- border-radius: 8px;
645
- padding: 12px;
646
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
647
- display: flex;
648
- align-items: center;
649
- cursor: pointer;
650
-
651
- &:hover {
652
- background: #000;
653
- }
654
- `;
655
- var QuestionTypeIconWrap = styled5.div`
656
- padding-right: 12px;
657
- display: flex;
658
- align-items: center;
659
- justify-content: center;
660
- `;
661
- var QuestionTypeIcon = styled5.img`
662
- width: 16px;
663
- height: 16px;
664
- `;
665
- var QuestionContent = styled5.div`
666
- font-weight: 700;
667
- flex: 1;
668
- display: flex;
669
- flex-direction: column;
670
- overflow: hidden;
671
- `;
672
- var QuestionTypeLabel = styled5.div`
673
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
674
- font-size: 10px;
675
- overflow: hidden;
676
- text-overflow: ellipsis;
677
- white-space: nowrap;
678
- padding-bottom: 5px;
679
- text-transform: uppercase;
680
- `;
681
- var QuestionSubject = styled5.div`
682
- color: ${(props) => props.theme.COLORS.WHITE};
683
- font-size: 12px;
684
- overflow: hidden;
685
- text-overflow: ellipsis;
686
- white-space: nowrap;
687
- `;
688
- var QuestionActionTitle = styled5.button`
689
- background-color: ${(props) => props.theme.COLORS.BLUE_QUESTION_ACTION_BTN};
690
- border: none;
691
- border-radius: 2px;
692
- font-size: 8px;
693
- padding: 6px;
694
- height: 20px;
695
- text-transform: uppercase;
696
- color: #fff;
697
- cursor: pointer;
698
- `;
699
- var QuestionActionIcon = styled5.button`
700
- border: none;
701
- font-size: 8px;
702
- padding: 6px;
703
- display: flex;
704
- align-items: center;
705
- background-color: transparent;
706
- cursor: pointer;
707
- `;
708
- var QuestionStatusIcon = styled5.img`
709
- width: 16px;
710
- height: 16px;
711
- `;
712
- var QuestionTypeTitle = styled5.span`
713
- text-transform: uppercase;
714
- `;
715
- var ExpiredQuestion = styled5.span`
716
- text-transform: uppercase;
717
- border-left: ${(props) => `1px solid ${props.theme.COLORS.GREY_PRIMARY}`};
718
- padding-left: 5px;
719
- margin-left: 5px;
720
- `;
721
-
722
- // packages/react-ui/src/lib/gamification/question/index.tsx
723
- import { jsx as jsx5, jsxs as jsxs4 } from "@emotion/react/jsx-runtime";
724
- var QuestionTypeData = {
725
- [QuestionType.POLL]: { label: "Poll", icon: icon_poll_default },
726
- [QuestionType.TRIVIA]: { label: "Trivia", icon: icon_trivia_default },
727
- [QuestionType.PREDICTION]: { label: "Prediction", icon: icon_prediction_default }
728
- };
729
- var QuestionStatusTypeData = {
730
- [PickHistoryStatus.LOST]: icon_cross_default,
731
- [PickHistoryStatus.WON]: icon_check_green_default,
732
- [PickHistoryStatus.UNSET]: icon_chevron_default,
733
- [PickHistoryStatus.DNP]: icon_chevron_default
734
- };
735
- var Question = ({
736
- questionId,
737
- questionType,
738
- questionStatus,
739
- subject,
740
- openForVoting,
741
- openQuestion,
742
- status
743
- }) => {
744
- const questionTypeData = QuestionTypeData[questionType];
745
- if (questionTypeData === void 0) {
746
- return null;
747
- }
748
- return /* @__PURE__ */ jsxs4(Panel2, { onClick: () => openQuestion?.(questionId), children: [
749
- /* @__PURE__ */ jsx5(QuestionTypeIconWrap, { children: /* @__PURE__ */ jsx5(QuestionTypeIcon, { alt: "question-type-icon", src: questionTypeData.icon }) }),
750
- /* @__PURE__ */ jsxs4(QuestionContent, { children: [
751
- /* @__PURE__ */ jsxs4(QuestionTypeLabel, { children: [
752
- /* @__PURE__ */ jsx5(QuestionTypeTitle, { children: questionTypeData.label }),
753
- questionType === QuestionType.TRIVIA && questionStatus === QuestionStatus.RESOLVED && /* @__PURE__ */ jsx5(ExpiredQuestion, { children: "Expired" })
754
- ] }),
755
- /* @__PURE__ */ jsx5(QuestionSubject, { children: subject || "" })
756
- ] }),
757
- openForVoting ? /* @__PURE__ */ jsx5(QuestionActionTitle, { children: "play" }) : /* @__PURE__ */ jsx5(QuestionActionIcon, { children: /* @__PURE__ */ jsx5(QuestionStatusIcon, { alt: "question-status-icon", src: QuestionStatusTypeData[status] }) })
758
- ] });
759
- };
760
-
761
- // packages/react-ui/src/lib/gamification/question-list/styles.tsx
762
- import styled6 from "@emotion/styled";
763
- var Container3 = styled6.div`
764
- display: flex;
765
- flex-direction: column;
766
- height: calc(100% - 160px);
767
- border-radius: 13px;
768
- `;
769
- var Title3 = styled6.div`
770
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
771
- text-transform: uppercase;
772
- font-size: 12px;
773
- font-weight: 500;
774
- margin-bottom: 8px;
775
- `;
776
- var ItemsContainer = styled6.div`
777
- display: flex;
778
- flex-direction: column;
779
- overflow-y: auto;
780
- max-height: 100%;
781
-
782
- & > div {
783
- margin-bottom: 8px;
784
- }
785
- `;
786
-
787
- // packages/react-ui/src/lib/gamification/question-list/index.tsx
788
- import { jsx as jsx6, jsxs as jsxs5 } from "@emotion/react/jsx-runtime";
789
- var QuestionList = ({ questions, openQuestion }) => {
790
- return /* @__PURE__ */ jsxs5(Container3, { children: [
791
- /* @__PURE__ */ jsx6(Title3, { children: "PICK HISTORY" }),
792
- /* @__PURE__ */ jsx6(ItemsContainer, { children: questions?.map((props) => /* @__PURE__ */ jsx6(Question, { openQuestion, ...props }, props.questionId)) })
793
- ] });
794
- };
795
-
796
- // packages/react-ui/src/assets/icons/icon-trophy.svg
797
- var icon_trophy_default = 'data:image/svg+xml,<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Trophy">%0A<path id="Combined Shape" fill-rule="evenodd" clip-rule="evenodd" d="M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z" fill="%23F2C94C"/>%0A</g>%0A</svg>%0A';
798
-
799
- // packages/react-ui/src/lib/gamification/user-statistics/components/statistics/styles.tsx
800
- import styled7 from "@emotion/styled";
801
- var Container4 = styled7.div`
802
- font-weight: 700;
803
- display: flex;
804
- flex-direction: column;
805
- row-gap: 4px;
806
- align-items: center;
807
- text-align: center;
808
- `;
809
- var Indicator = styled7.div`
810
- font-size: 18px;
811
- color: #fff;
812
- `;
813
-
814
- // packages/react-ui/src/lib/gamification/user-statistics/components/statistics/index.tsx
815
- import { jsx as jsx7, jsxs as jsxs6 } from "@emotion/react/jsx-runtime";
816
- var Statistics = ({ indicator, title: title2 }) => /* @__PURE__ */ jsxs6(Container4, { children: [
817
- /* @__PURE__ */ jsx7(Indicator, { children: indicator }),
818
- /* @__PURE__ */ jsx7("p", { children: title2 })
819
- ] });
820
-
821
- // packages/react-ui/src/lib/gamification/user-statistics/components/rank/styles.tsx
822
- import styled8 from "@emotion/styled";
823
- var Container5 = styled8.div`
824
- display: flex;
825
- justify-content: flex-end;
826
- align-items: center;
827
- column-gap: 2px;
828
- overflow: hidden;
829
- `;
830
- var Title4 = styled8.div`
831
- width: 75px;
832
- `;
833
- var Indicator2 = styled8.div`
834
- font-size: 14px;
835
- color: #fff;
836
- overflow: hidden;
837
- text-overflow: ellipsis;
838
- white-space: nowrap;
839
- width: 25px;
840
- `;
841
-
842
- // packages/react-ui/src/lib/gamification/user-statistics/components/rank/index.tsx
843
- import { jsx as jsx8, jsxs as jsxs7 } from "@emotion/react/jsx-runtime";
844
- var Rank = ({ indicator, title: title2 }) => /* @__PURE__ */ jsxs7(Container5, { children: [
845
- /* @__PURE__ */ jsx8(Title4, { children: title2 }),
846
- /* @__PURE__ */ jsx8(Indicator2, { children: indicator })
847
- ] });
848
-
849
- // packages/react-ui/src/lib/gamification/user-statistics/styles.tsx
850
- import styled9 from "@emotion/styled";
851
- var Container6 = styled9.div`
852
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_USER_CONTAINER};
853
- border-radius: 12px;
854
- color: ${(props) => props.theme.COLORS.GREY_PRIMARY};
855
- font-size: 10px;
856
- font-weight: 600;
857
- `;
858
- var TopInfo = styled9.div`
859
- padding: 12px;
860
- border-bottom: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_PRIMARY}`};
861
- display: flex;
862
- justify-content: space-between;
863
- align-items: center;
864
- column-gap: 5px;
865
- `;
866
- var BottomInfo = styled9.div`
867
- padding: 12px 16px;
868
- text-transform: uppercase;
869
- display: flex;
870
- justify-content: space-between;
871
- column-gap: 16px;
872
- `;
873
- var User = styled9.div`
874
- display: flex;
875
- column-gap: 8px;
876
- flex: 1;
877
- overflow: hidden;
878
- `;
879
- var Avatar = styled9.img`
880
- width: 100%;
881
- height: 100%;
882
- max-width: 48px;
883
- max-height: 48px;
884
- border-radius: 50%;
885
- object-fit: cover;
886
- object-position: center;
887
- flex-shrink: 0;
888
- `;
889
- var UserInfo = styled9.div`
890
- padding-top: 4px;
891
- display: flex;
892
- flex-direction: column;
893
- row-gap: 4px;
894
- overflow: hidden;
895
- `;
896
- var UserName = styled9.div`
897
- font-size: 18px;
898
- color: ${(props) => props.theme.COLORS.WHITE};
899
- overflow: hidden;
900
- text-overflow: ellipsis;
901
- white-space: nowrap;
902
- `;
903
- var UserRating = styled9.div`
904
- text-transform: uppercase;
905
- display: flex;
906
- align-items: center;
907
- `;
908
- var TrophyIcon = styled9.img`
909
- width: 12px;
910
- height: 12px;
911
- margin-right: 4px;
912
- `;
913
- var Rts = styled9.div`
914
- display: flex;
915
- align-items: center;
916
- column-gap: 4px;
917
- border-right: ${(props) => `1px solid ${props.theme.COLORS.DIVIDER_COLOR_SECONDARY}`};
918
- padding-right: 5px;
919
- `;
920
- var RtsIndicator = styled9.div`
921
- font-size: 14px;
922
- color: ${(props) => props.theme.COLORS.WHITE};
923
- `;
924
- var Top = styled9.div`
925
- padding-left: 5px;
926
- `;
927
- var Ranks = styled9.div`
928
- text-transform: uppercase;
929
- display: flex;
930
- flex-direction: column;
931
- row-gap: 4px;
932
- `;
933
- var AvatarPlaceholder = styled9.div`
934
- background: #2d6ffd;
935
- border-radius: 50%;
936
- width: 48px;
937
- height: 48px;
938
- text-align: center;
939
- text-transform: uppercase;
940
- display: flex;
941
- align-items: center;
942
- justify-content: center;
943
- color: #fff;
944
- font-size: 18px;
945
- flex-shrink: 0;
946
- `;
947
-
948
- // packages/react-ui/src/lib/gamification/user-statistics/index.tsx
949
- import { jsx as jsx9, jsxs as jsxs8 } from "@emotion/react/jsx-runtime";
950
- var abbreviate = (name) => name.split(/\s+/).map((p) => p[0]).join("").toUpperCase();
951
- var UserStatistics = ({
952
- avatar,
953
- name,
954
- points,
955
- grade,
956
- friendsRank,
957
- globalRank,
958
- winStreak,
959
- correct,
960
- incorrect,
961
- successRate
962
- }) => {
963
- return /* @__PURE__ */ jsxs8(Container6, { children: [
964
- /* @__PURE__ */ jsxs8(TopInfo, { children: [
965
- /* @__PURE__ */ jsxs8(User, { children: [
966
- avatar && /* @__PURE__ */ jsx9(Avatar, { alt: "avatar", src: avatar }),
967
- !avatar && /* @__PURE__ */ jsx9(AvatarPlaceholder, { children: abbreviate(name) }),
968
- /* @__PURE__ */ jsxs8(UserInfo, { children: [
969
- /* @__PURE__ */ jsx9(UserName, { children: name }),
970
- /* @__PURE__ */ jsxs8(UserRating, { children: [
971
- /* @__PURE__ */ jsx9(TrophyIcon, { alt: "rank-icon", src: icon_trophy_default }),
972
- /* @__PURE__ */ jsxs8(Rts, { children: [
973
- /* @__PURE__ */ jsx9(RtsIndicator, { children: points || "-" }),
974
- "RTS"
975
- ] }),
976
- /* @__PURE__ */ jsxs8(Top, { children: [
977
- "TOP ",
978
- grade,
979
- "%"
980
- ] })
981
- ] })
982
- ] })
983
- ] }),
984
- /* @__PURE__ */ jsxs8(Ranks, { children: [
985
- /* @__PURE__ */ jsx9(Rank, { title: "Friens rank", indicator: friendsRank || "-" }),
986
- /* @__PURE__ */ jsx9(Rank, { title: "Global rank", indicator: globalRank || "-" })
987
- ] })
988
- ] }),
989
- /* @__PURE__ */ jsxs8(BottomInfo, { children: [
990
- /* @__PURE__ */ jsx9(Statistics, { indicator: winStreak || "-", title: "Win streak" }),
991
- /* @__PURE__ */ jsx9(Statistics, { indicator: correct || "-", title: "Correct" }),
992
- /* @__PURE__ */ jsx9(Statistics, { indicator: incorrect || "-", title: "Incorrect" }),
993
- /* @__PURE__ */ jsx9(Statistics, { indicator: `${successRate || "-"}%`, title: "Success rate" })
994
- ] })
995
- ] });
996
- };
997
-
998
- // packages/react-ui/src/lib/gamification/vote/index.tsx
999
- import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2 } from "react";
1000
-
1001
- // packages/react-ui/src/assets/icons/icon-check.svg
1002
- var icon_check_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Checkmark">%0A<path id="Selected" fill-rule="evenodd" clip-rule="evenodd" d="M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z" fill="%2300BD60"/>%0A</g>%0A</svg>%0A';
1003
-
1004
- // packages/react-ui/src/assets/icons/icon-close.svg
1005
- var icon_close_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<rect y="0.00195312" width="24" height="24" rx="12" fill="%23F80022"/>%0A<rect x="8.25" y="7.00195" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(45 8.25 7.00195)" fill="white"/>%0A<rect x="7" y="15.752" width="12.3744" height="1.76777" rx="0.883884" transform="rotate(-45 7 15.752)" fill="white"/>%0A</svg>%0A';
1006
-
1007
- // packages/react-ui/src/assets/icons/icon-check-white.svg
1008
- var icon_check_white_default = 'data:image/svg+xml,<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Checkmark">%0A<path id="Selected" fill-rule="evenodd" clip-rule="evenodd" d="M24 12.002C24 18.6294 18.6274 24.002 12 24.002C5.37258 24.002 0 18.6294 0 12.002C0 5.37454 5.37258 0.00195312 12 0.00195312C18.6274 0.00195312 24 5.37454 24 12.002ZM17.4086 8.15357C16.94 7.68494 16.1802 7.68494 15.7116 8.15357L10.4072 14.9579L7.62573 13.1036C7.07429 12.736 6.32925 12.885 5.96163 13.4365C5.59401 13.9879 5.74301 14.7329 6.29445 15.1006L9.89445 17.5006C10.3704 17.8179 11.0041 17.7551 11.4086 17.3506L17.4086 9.85063C17.8772 9.382 17.8772 8.6222 17.4086 8.15357Z" fill="%23FFFFFF"/>%0A</g>%0A</svg>%0A';
1009
-
1010
- // packages/react-ui/src/lib/gamification/vote/components/voting-option/styles.tsx
1011
- import styled10 from "@emotion/styled";
1012
- var Container7 = styled10.div`
1013
- box-sizing: border-box;
1014
- border-radius: 4px;
1015
- height: 44px;
1016
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM_VOTE};
1017
- border: 2px solid transparent;
1018
- position: relative;
1019
-
1020
- ${(props) => !props.questionAnswered && `
1021
- &:hover {
1022
- border-color: inherit;
1023
- }
1024
- `}
1025
- `;
1026
- var AnsweredContainer = styled10(Container7)`
1027
- background-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BG_TRANSPARENT_ITEM_SUCCESS : theme2.COLORS.BG_TRANSPARENT_ITEM_ERROR};
1028
- border: 2px solid;
1029
- border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
1030
-
1031
- &:hover {
1032
- border-color: ${({ answeredCorrect, theme: theme2 }) => answeredCorrect ? theme2.COLORS.BLUE_PRIMARY : theme2.COLORS.RED_PRIMARY};
1033
- }
1034
- `;
1035
- var ButtonPct = styled10.div`
1036
- position: absolute;
1037
- left: 0;
1038
- border-radius: 2px;
1039
- z-index: 0;
1040
- height: 100%;
1041
- background-color: inherit;
1042
- transition: all 1s ease-in;
1043
- `;
1044
- var Button = styled10.button`
1045
- border-radius: 20px;
1046
- position: relative;
1047
- background-color: transparent;
1048
- padding: 0px 16px;
1049
- display: flex;
1050
- align-items: center;
1051
- border: none;
1052
- outline: none;
1053
- width: 100%;
1054
- color: ${(props) => props.theme.COLORS.WHITE};
1055
- font-weight: 700;
1056
- font-size: 14px;
1057
- height: 100%;
1058
- border-radius: 2px;
1059
- cursor: pointer;
1060
-
1061
- &:disabled {
1062
- cursor: default;
1063
- }
1064
- `;
1065
- var Icon2 = styled10.img`
1066
- width: 32px;
1067
- height: 32px;
1068
- border-radius: 50%;
1069
- margin-right: 8px;
1070
- `;
1071
- var Title5 = styled10.span`
1072
- overflow: hidden;
1073
- text-overflow: ellipsis;
1074
- white-space: nowrap;
1075
- padding: 8px 0px;
1076
- flex: 1;
1077
- text-align: left;
1078
- `;
1079
- var Indicators = styled10.span`
1080
- display: flex;
1081
- `;
1082
- var CheckIconWrap = styled10.div`
1083
- width: 16px;
1084
- height: 16px;
1085
- margin-left: 8px;
1086
- `;
1087
- var Percentage = styled10.div`
1088
- margin-left: 12px;
1089
- `;
1090
- var CheckIcon = styled10.img`
1091
- width: 16px;
1092
- height: 16px;
1093
- `;
1094
-
1095
- // packages/react-ui/src/lib/gamification/vote/components/voting-option/index.tsx
1096
- import { jsx as jsx10, jsxs as jsxs9 } from "@emotion/react/jsx-runtime";
1097
- var VotingOption = ({
1098
- icon,
1099
- id,
1100
- title: title2,
1101
- questionId,
1102
- disabled,
1103
- percentage,
1104
- onVote,
1105
- toggleIsLoadingSubmitAnswer,
1106
- correct,
1107
- questionAnswered,
1108
- hasCorrectAnswer,
1109
- answered
1110
- }) => {
1111
- if (questionAnswered && answered) {
1112
- return /* @__PURE__ */ jsxs9(AnsweredContainer, { answeredCorrect: !hasCorrectAnswer || correct, questionAnswered: false, children: [
1113
- /* @__PURE__ */ jsx10(ButtonPct, { style: { width: `${percentage}%` } }),
1114
- /* @__PURE__ */ jsxs9(Button, { disabled, onClick: () => onVote(questionId, id), children: [
1115
- icon && /* @__PURE__ */ jsx10(Icon2, { alt: "option-icon", src: icon }),
1116
- /* @__PURE__ */ jsx10(Title5, { children: title2 }),
1117
- /* @__PURE__ */ jsxs9(Indicators, { children: [
1118
- hasCorrectAnswer && correct && /* @__PURE__ */ jsx10(CheckIconWrap, { children: /* @__PURE__ */ jsx10(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
1119
- /* @__PURE__ */ jsxs9(Percentage, { children: [
1120
- percentage,
1121
- "%"
1122
- ] })
1123
- ] })
1124
- ] })
1125
- ] });
1126
- }
1127
- return /* @__PURE__ */ jsxs9(Container7, { questionAnswered, children: [
1128
- questionAnswered && /* @__PURE__ */ jsx10(ButtonPct, { style: { width: `${percentage}%` } }),
1129
- /* @__PURE__ */ jsxs9(
1130
- Button,
1131
- {
1132
- disabled,
1133
- onClick: () => {
1134
- toggleIsLoadingSubmitAnswer(true);
1135
- onVote(questionId, id);
1136
- },
1137
- children: [
1138
- icon && /* @__PURE__ */ jsx10(Icon2, { alt: "option-icon", src: icon }),
1139
- /* @__PURE__ */ jsx10(Title5, { children: title2 }),
1140
- questionAnswered && /* @__PURE__ */ jsxs9(Indicators, { children: [
1141
- hasCorrectAnswer && correct && /* @__PURE__ */ jsx10(CheckIconWrap, { children: /* @__PURE__ */ jsx10(CheckIcon, { alt: "icon-correct", src: answered ? icon_check_white_default : icon_check_default }) }),
1142
- /* @__PURE__ */ jsxs9(Percentage, { children: [
1143
- percentage,
1144
- "%"
1145
- ] })
1146
- ] })
1147
- ]
1148
- }
1149
- )
1150
- ] });
1151
- };
1152
-
1153
- // packages/react-ui/src/lib/gamification/vote/styles.tsx
1154
- import styled11 from "@emotion/styled";
1155
- var Container8 = styled11.div`
1156
- padding: 16px;
1157
- color: ${(props) => props.theme.COLORS.WHITE};
1158
- font-weight: 700;
1159
- font-size: 14px;
1160
-
1161
- & > div:not(:last-child) {
1162
- margin-bottom: 16px;
1163
- }
1164
- `;
1165
- var Title6 = styled11.div`
1166
- font-size: 16px;
1167
- `;
1168
- var Options = styled11.div`
1169
- overflow-y: auto;
1170
- max-height: 220px;
1171
- position: relative;
1172
-
1173
- & > div:not(:last-child) {
1174
- margin-bottom: 12px;
1175
- }
1176
- `;
1177
- var Loader = styled11.div`
1178
- position: absolute;
1179
- left: 0px;
1180
- background-color: ${(props) => props.theme.COLORS.BG_TRANSPARENT_VOTE_CONTAINER};
1181
- width: 100%;
1182
- height: 100%;
1183
- z-index: 1;
1184
- display: flex;
1185
- justify-content: center;
1186
- align-items: center;
1187
- `;
1188
- var Feedback = styled11.div`
1189
- padding: 14px 12px 14px 16px;
1190
- display: flex;
1191
- align-items: center;
1192
- `;
1193
- var FeedbackIcon = styled11.img`
1194
- width: 24px;
1195
- height: 24px;
1196
- margin-right: 12px;
1197
- `;
1198
- var FeedbackTitle = styled11.div`
1199
- overflow: hidden;
1200
- text-overflow: ellipsis;
1201
- white-space: nowrap;
1202
- font-size: 16;
1203
- font-weight: 700;
1204
- margin-bottom: 10px;
1205
- `;
1206
- var FeedbackDescription = styled11.div`
1207
- display: -webkit-box;
1208
- -webkit-box-orient: vertical;
1209
- -webkit-line-clamp: 4;
1210
- overflow: hidden;
1211
- text-overflow: ellipsis;
1212
- font-size: 14;
1213
- font-weight: 500;
1214
- `;
1215
-
1216
- // packages/react-ui/src/lib/gamification/vote/index.tsx
1217
- import { jsx as jsx11, jsxs as jsxs10 } from "@emotion/react/jsx-runtime";
1218
- var Vote = ({
1219
- title: title2,
1220
- questionId,
1221
- options,
1222
- questionAnswered,
1223
- feedbackMessages,
1224
- questionAnsweredCorrectly,
1225
- questionType
1226
- }) => {
1227
- const [isLoadingSubmitAnswer, setIsLoadingSubmitAnswer] = useState2(false);
1228
- const toggleIsLoadingSubmitAnswer = useCallback2(
1229
- (flag) => {
1230
- setIsLoadingSubmitAnswer(flag);
1231
- },
1232
- [setIsLoadingSubmitAnswer]
1233
- );
1234
- useEffect2(() => {
1235
- toggleIsLoadingSubmitAnswer(false);
1236
- }, [options, toggleIsLoadingSubmitAnswer]);
1237
- return /* @__PURE__ */ jsxs10(Container8, { children: [
1238
- /* @__PURE__ */ jsx11(Title6, { children: title2 }),
1239
- /* @__PURE__ */ jsxs10(Options, { children: [
1240
- isLoadingSubmitAnswer && /* @__PURE__ */ jsx11(Loader, { children: "Loading..." }),
1241
- options.map((props) => /* @__PURE__ */ jsx11(
1242
- VotingOption,
1243
- {
1244
- toggleIsLoadingSubmitAnswer,
1245
- questionId,
1246
- ...props
1247
- },
1248
- props.id
1249
- ))
1250
- ] }),
1251
- questionAnswered && questionType === QuestionType.TRIVIA && /* @__PURE__ */ jsxs10(Feedback, { children: [
1252
- /* @__PURE__ */ jsx11(FeedbackIcon, { alt: "reaction-to-answer", src: questionAnsweredCorrectly ? icon_check_default : icon_close_default }),
1253
- /* @__PURE__ */ jsxs10("div", { children: [
1254
- /* @__PURE__ */ jsx11(FeedbackTitle, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.title : feedbackMessages.incorrectFeedback.title }),
1255
- /* @__PURE__ */ jsx11(FeedbackDescription, { children: questionAnsweredCorrectly ? feedbackMessages.correctFeedback.description : feedbackMessages.incorrectFeedback.description })
1256
- ] })
1257
- ] })
1258
- ] });
1259
- };
1260
-
1261
- // packages/react-ui/src/lib/demo/index.tsx
1262
- import { useStore as useStore6 } from "@nanostores/react";
1263
-
1264
- // packages/react-ui/src/lib/demo/Gamification.tsx
1265
- import { useStore as useStore5 } from "@nanostores/react";
1266
-
1267
- // packages/react-ui/src/lib/demo/components/UserSummary.tsx
1268
- import { useStore } from "@nanostores/react";
1269
- import { jsx as jsx12 } from "@emotion/react/jsx-runtime";
1270
- var UserSummary = ({ store: store2 }) => {
1271
- const { data: user } = useStore(store2);
1272
- if (!user?.summary) {
1273
- return /* @__PURE__ */ jsx12("div", { children: "wait user..." });
1274
- }
1275
- return /* @__PURE__ */ jsx12(
1276
- UserStatistics,
1277
- {
1278
- avatar: user.summary.avatar,
1279
- name: user.summary.name,
1280
- points: user.summary.points,
1281
- grade: "0",
1282
- friendsRank: user.summary.friendsRank,
1283
- globalRank: user.summary.rank,
1284
- winStreak: user.summary.streak,
1285
- correct: user.summary.correct,
1286
- incorrect: user.summary.incorrect,
1287
- successRate: user.percentage?.average
1288
- }
1289
- );
1290
- };
1291
-
1292
- // packages/react-ui/src/lib/demo/components/QuestionsList.tsx
1293
- import { useStore as useStore2 } from "@nanostores/react";
1294
- import { jsx as jsx13 } from "@emotion/react/jsx-runtime";
1295
- var QuestionsList = ({ store: store2, openQuestion }) => {
1296
- const { data: questions } = useStore2(store2);
1297
- if (!questions) {
1298
- return /* @__PURE__ */ jsx13("div", { children: "wait questions..." });
1299
- }
1300
- return /* @__PURE__ */ jsx13(QuestionList, { openQuestion, questions });
1301
- };
1302
-
1303
- // packages/react-ui/src/lib/demo/components/Question.tsx
1304
- import styled14 from "@emotion/styled";
1305
- import { useStore as useStore3 } from "@nanostores/react";
1306
- import { useState as useState3, useCallback as useCallback3, useMemo } from "react";
1307
-
1308
- // packages/react-ui/src/assets/icons/icon-trophy-green.svg
1309
- var icon_trophy_green_default = 'data:image/svg+xml,<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">%0A <g id="Trophy">%0A <path id="Combined Shape" fill-rule="evenodd" clip-rule="evenodd" d="M2.76916 3.50002C2.76916 4.49786 2.94705 5.38348 3.30282 6.15692C2.62493 6.01847 2.05883 5.74872 1.6045 5.34768C1.15017 4.94663 0.923008 4.55992 0.923008 4.18752V3.50002H2.76916ZM11.0768 3.50002V4.18752C11.0768 4.55992 10.8497 4.94663 10.3953 5.34768C9.941 5.74872 9.3749 6.01847 8.69701 6.15692C9.05278 5.38348 9.23066 4.49786 9.23066 3.50002H11.0768ZM12 4.1875V3.27083C12 3.07986 11.9327 2.91754 11.7981 2.78385C11.6635 2.65017 11.5 2.58333 11.3077 2.58333H9.23077V1.89583C9.23077 1.58073 9.11779 1.31098 8.89183 1.08659C8.66586 0.862195 8.39423 0.75 8.07692 0.75H3.92308C3.60577 0.75 3.33414 0.862195 3.10817 1.08659C2.88221 1.31098 2.76923 1.58073 2.76923 1.89583V2.58333H0.692308C0.499999 2.58333 0.336539 2.65017 0.201923 2.78385C0.067307 2.91754 0 3.07986 0 3.27083V4.1875C0 4.52648 0.0997586 4.86784 0.299279 5.21159C0.498799 5.55534 0.768027 5.86567 1.10697 6.14258C1.44592 6.41949 1.86178 6.65223 2.35457 6.84082C2.84736 7.02941 3.36538 7.13563 3.90865 7.15951C4.11058 7.41732 4.33894 7.6441 4.59375 7.83984C4.77644 8.00217 4.90264 8.17524 4.97236 8.35905C5.04207 8.54286 5.07692 8.75651 5.07692 9C5.07692 9.25781 5.00361 9.47504 4.85697 9.65169C4.71034 9.82834 4.47596 9.91667 4.15385 9.91667C3.79327 9.91667 3.47236 10.0253 3.19111 10.2425C2.90985 10.4597 2.76923 10.7331 2.76923 11.0625V11.5208C2.76923 11.5877 2.79087 11.6426 2.83413 11.6855C2.8774 11.7285 2.93269 11.75 3 11.75H9C9.06731 11.75 9.1226 11.7285 9.16586 11.6855C9.20913 11.6426 9.23077 11.5877 9.23077 11.5208V11.0625C9.23077 10.7331 9.09015 10.4597 8.80889 10.2425C8.52764 10.0253 8.20673 9.91667 7.84615 9.91667C7.52404 9.91667 7.28966 9.82834 7.14303 9.65169C6.99639 9.47504 6.92308 9.25781 6.92308 9C6.92308 8.75651 6.95793 8.54286 7.02764 8.35905C7.09736 8.17524 7.22356 8.00217 7.40625 7.83984C7.66106 7.6441 7.88942 7.41732 8.09135 7.15951C8.63462 7.13563 9.15264 7.02941 9.64543 6.84082C10.1382 6.65223 10.5541 6.41949 10.893 6.14258C11.232 5.86567 11.5012 5.55534 11.7007 5.21159C11.9002 4.86784 12 4.52648 12 4.1875ZM5.07033 5.38491L6.0383 4.87503L7.00627 5.38491L6.8214 4.30497L7.60451 3.54016L6.52228 3.3826L6.0383 2.40003L5.55431 3.3826L4.47209 3.54016L5.25519 4.30497L5.07033 5.38491Z" fill="white"/>%0A </g>%0A </svg>%0A';
1310
-
1311
- // packages/react-ui/src/assets/icons/icon-thumb-down.svg
1312
- var icon_thumb_down_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22" fill="none">%0A <path d="M5.5 2.78867V12.4137C5.5 13.1729 4.88426 13.75 4.125 13.75H1.375C0.615742 13.75 0 13.1343 0 12.4137V2.82734C0 2.06808 0.615742 1.49102 1.375 1.49102H4.125C4.88555 1.41367 5.5 1.99375 5.5 2.78867ZM22 12.3707C22 13.5094 21.077 14.4323 19.9375 14.4323H13.6426C14.621 16.0613 15.1259 17.9077 15.1259 18.5582C15.125 19.5714 14.3301 20.625 12.998 20.625C10.2854 20.625 11.8654 17.3529 8.34883 14.5406L7.64844 13.982C7.14141 13.5738 6.88359 12.9766 6.8793 12.375C6.87829 12.374 6.8793 12.375 6.8793 12.375L6.875 5.5C6.875 4.85117 7.18064 4.23973 7.7 3.85043L9.16695 2.75086C10.3555 1.85625 11.8035 1.375 13.2902 1.375H15.8125C16.952 1.375 17.875 2.29754 17.875 3.43664C17.875 3.59283 17.8544 3.74357 17.8215 3.88996C18.6484 4.15937 19.25 4.92422 19.25 5.84375C19.25 6.23683 19.1341 6.60043 18.9432 6.91281C19.8988 7.08984 20.625 7.92773 20.625 8.9332C20.625 9.47031 20.4148 9.955 20.0784 10.322C21.1492 10.3941 22 11.2793 22 12.3707Z" fill="white"/>%0A </svg>%0A';
1313
-
1314
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/styles.tsx
1315
- import styled12 from "@emotion/styled";
1316
- var Container9 = styled12.div`
1317
- box-sizing: border-box;
1318
- background-color: transparent;
1319
- color: ${(props) => props.theme.COLORS.WHITE};
1320
- display: flex;
1321
- flex-direction: row-reverse;
1322
- justify-content: space-between;
1323
- padding: 0px 16px;
1324
- align-items: center;
1325
- `;
1326
- var Logo = styled12.img`
1327
- width: 60px;
1328
- height: 80%;
1329
- `;
1330
- var RightBlock = styled12.div`
1331
- display: flex;
1332
- align-items: center;
1333
- `;
1334
- var ExitBtn = styled12.button`
1335
- border: none;
1336
- outline: none;
1337
- background-color: transparent;
1338
- border-radius: 50%;
1339
- padding: 0px;
1340
- width: 24px;
1341
- height: 24px;
1342
- margin-left: 25px;
1343
- cursor: pointer;
1344
- `;
1345
- var ExitIcon = styled12.img`
1346
- width: 24px;
1347
- height: 24px;
1348
- `;
1349
- var Interactive = styled12.div`
1350
- display: flex;
1351
- align-items: center;
1352
- padding: 4px 0px;
1353
- margin-left: 10px;
1354
- `;
1355
- var ReactionIconWrap = styled12.div`
1356
- background-color: ${(props) => props.isSuccess ? "#f1be1c" : "#da3732"};
1357
- width: 32px;
1358
- height: 32px;
1359
- border-radius: 50%;
1360
- display: flex;
1361
- justify-content: center;
1362
- align-items: center;
1363
- `;
1364
- var ReactionIcon = styled12.img`
1365
- width: 20px;
1366
- height: 20px;
1367
- `;
1368
-
1369
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/styles.tsx
1370
- import styled13 from "@emotion/styled";
1371
- var Container10 = styled13.div`
1372
- display: flex;
1373
- flex-direction: column;
1374
- align-items: flex-end;
1375
- margin-right: 10px;
1376
- font-weight: 700;
1377
- `;
1378
- var Title7 = styled13.div`
1379
- color: rgba(255, 255, 255, 0.8);
1380
- font-size: 8px;
1381
- line-height: 12px;
1382
- text-align: right;
1383
- `;
1384
- var PointContainer = styled13.div`
1385
- text-align: right;
1386
- `;
1387
- var Point = styled13.span`
1388
- color: rgba(255, 255, 255, 0.9);
1389
- font-size: 14px;
1390
- line-height: 16px;
1391
- margin-right: 2px;
1392
- `;
1393
- var PointLabel = styled13.span`
1394
- color: white;
1395
- font-size: 10px;
1396
- font-weight: 600;
1397
- line-height: 16px;
1398
- `;
1399
-
1400
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/components/points/index.tsx
1401
- import { jsx as jsx14, jsxs as jsxs11 } from "@emotion/react/jsx-runtime";
1402
- var Points = ({ points }) => /* @__PURE__ */ jsxs11(Container10, { children: [
1403
- /* @__PURE__ */ jsx14(Title7, { children: "YOU WON" }),
1404
- /* @__PURE__ */ jsxs11(PointContainer, { children: [
1405
- /* @__PURE__ */ jsx14(Point, { children: points }),
1406
- /* @__PURE__ */ jsx14(PointLabel, { children: "PTS" })
1407
- ] })
1408
- ] });
1409
-
1410
- // packages/react-ui/src/lib/gamification/vote/components/voting-header/index.tsx
1411
- import { Fragment, jsx as jsx15, jsxs as jsxs12 } from "@emotion/react/jsx-runtime";
1412
- var VotingHeader = ({
1413
- logo,
1414
- points,
1415
- questionAnswered,
1416
- questionAnsweredCorrectly,
1417
- questionType,
1418
- closeQuestion,
1419
- setTimeToExpire
1420
- }) => {
1421
- const isShowTimer = !questionAnswered && questionType !== QuestionType.PREDICTION;
1422
- const isShowTriviaFeedback = questionAnswered && questionType === QuestionType.TRIVIA;
1423
- const successTriviaFeedback = isShowTriviaFeedback && questionAnsweredCorrectly;
1424
- const errorTriviaFeedback = isShowTriviaFeedback && !questionAnsweredCorrectly;
1425
- const isShowPredictionFeedback = questionAnswered && questionType === QuestionType.PREDICTION;
1426
- return /* @__PURE__ */ jsxs12(Container9, { children: [
1427
- /* @__PURE__ */ jsxs12(RightBlock, { children: [
1428
- /* @__PURE__ */ jsxs12(Interactive, { children: [
1429
- isShowTimer && /* @__PURE__ */ jsx15(Timer, { setTimeToExpire }),
1430
- successTriviaFeedback && /* @__PURE__ */ jsxs12(Fragment, { children: [
1431
- /* @__PURE__ */ jsx15(Points, { points }),
1432
- /* @__PURE__ */ jsx15(ReactionIconWrap, { isSuccess: true, children: /* @__PURE__ */ jsx15(ReactionIcon, { alt: "reaction-icon", src: icon_trophy_green_default }) })
1433
- ] }),
1434
- errorTriviaFeedback && /* @__PURE__ */ jsxs12(Fragment, { children: [
1435
- /* @__PURE__ */ jsx15(Points, { points: 0 }),
1436
- /* @__PURE__ */ jsx15(ReactionIconWrap, { isSuccess: false, children: /* @__PURE__ */ jsx15(ReactionIcon, { alt: "reaction-icon", src: icon_thumb_down_default }) })
1437
- ] }),
1438
- isShowPredictionFeedback && /* @__PURE__ */ jsx15(Points, { points })
1439
- ] }),
1440
- /* @__PURE__ */ jsx15(ExitBtn, { onClick: closeQuestion, children: /* @__PURE__ */ jsx15(ExitIcon, { alt: "exit-icon", src: icon_exit_default }) })
1441
- ] }),
1442
- logo && /* @__PURE__ */ jsx15(Logo, { src: logo })
1443
- ] });
1444
- };
1445
-
1446
- // packages/react-ui/src/assets/icons/fedex.svg
1447
- var fedex_default = 'data:image/svg+xml,<svg width="68" height="22" viewBox="0 0 68 22" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<g id="Vector">%0A<path fill-rule="evenodd" clip-rule="evenodd" d="M56.6155 7.44146H50.7066L56.3072 13.8615L50.7066 20.2805H56.4357L59.1587 17.137L61.9068 20.2805H67.84L62.19 13.8348L67.7636 7.44146H62.0606L59.3897 10.5602L56.6155 7.44146ZM62.2721 7.91659L59.3964 11.2747L56.4092 7.91659H51.7446L56.9307 13.8615L51.7447 19.8054H56.2257L59.1571 16.4213L62.1156 19.8054H66.7987L61.566 13.8357L66.7261 7.91659H62.2721Z" fill="white"/>%0A<path fill-rule="evenodd" clip-rule="evenodd" d="M44.3635 7.44146V4.56406H50.7066V0.0559998H39.702V20.2805H50.7066V15.7601H44.3635V11.7794H50.7066V7.44146H44.3635ZM50.2408 7.91659H43.8978V4.08893H50.2408V0.531132H40.1678V19.8054H50.2408V16.2352H43.8978V11.3043H50.2408V7.91659Z" fill="white"/>%0A<path d="M35.06 0.0559998V8.33281H35.0087C33.9803 7.12787 32.6966 6.70881 31.207 6.70881C28.1552 6.70881 25.8561 8.826 25.0493 11.6236C24.128 8.54092 21.7544 6.65084 18.2349 6.65084C15.3769 6.65084 13.1197 7.95936 11.9422 10.0918V7.44146H6.03416V4.56406H12.4815V0.0559998H0.768005V20.2805H6.03416V11.7794H11.2836C11.127 12.4037 11.0432 13.0727 11.0432 13.7788C11.0432 17.997 14.2031 20.958 18.2349 20.958C21.6258 20.958 23.8607 19.334 25.0419 16.374H20.5284C19.9183 17.2644 19.4553 17.5276 18.2349 17.5276C16.8199 17.5276 15.5995 16.2685 15.5995 14.7756H24.7894C25.1881 18.1262 27.7472 21.016 31.2582 21.016C32.773 21.016 34.1601 20.2558 35.0078 18.9729H35.059V20.2824H39.701L39.702 0.0559998H35.06ZM15.7467 11.8393C16.0392 10.5545 17.0164 9.71545 18.2358 9.71545C19.5782 9.71545 20.5051 10.5289 20.7492 11.8393C20.8517 11.8393 15.7467 11.8393 15.7467 11.8393ZM32.242 17.2016C30.5307 17.2016 29.4668 15.5748 29.4668 13.8767C29.4668 12.0617 30.3919 10.316 32.242 10.316C34.1601 10.316 34.924 12.0617 34.924 13.8767C34.924 15.5976 34.1144 17.2016 32.242 17.2016Z" fill="white"/>%0A</g>%0A</svg>%0A';
1448
-
1449
- // packages/react-ui/src/lib/demo/components/Question.tsx
1450
- import { jsx as jsx16, jsxs as jsxs13 } from "@emotion/react/jsx-runtime";
1451
- var QuestionContainer = styled14.div`
1452
- position: absolute;
1453
- top: 0;
1454
- background: ${(props) => props.theme.COLORS.BG_TRANSPARENT_ITEM};
1455
- width: 100%;
1456
- height: 100%;
1457
-
1458
- display: flex;
1459
- align-items: center;
1460
- justify-content: center;
1461
- flex-direction: column;
1462
-
1463
- > div {
1464
- width: 100%;
1465
- background: #000;
1466
- animation: slidein 0.3s ease-in;
1467
- }
1468
-
1469
- @keyframes slidein {
1470
- from {
1471
- transform: translateX(-100%);
1472
- }
1473
-
1474
- to {
1475
- transform: translateX(0);
1476
- }
1477
- }
1478
- `;
1479
- var Question2 = ({ store: store2, closeQuestion, vote }) => {
1480
- const { data: openedQuestion } = useStore3(store2);
1481
- const [answerTimeExpired, setAnswerTimeExpired] = useState3(false);
1482
- const setTimeToExpire = useCallback3(
1483
- (flag) => {
1484
- setAnswerTimeExpired(flag);
1485
- },
1486
- [setAnswerTimeExpired]
1487
- );
1488
- const questionAnswered = useMemo(
1489
- () => openedQuestion?.answers.find((answer) => answer.youVoted === true),
1490
- [openedQuestion]
1491
- );
1492
- const hasCorrectAnswer = useMemo(
1493
- () => !!openedQuestion?.answers.find((answer) => answer.correct === true),
1494
- [openedQuestion]
1495
- );
1496
- if (!openedQuestion) {
1497
- return null;
1498
- }
1499
- return /* @__PURE__ */ jsx16(QuestionContainer, { children: /* @__PURE__ */ jsxs13("div", { children: [
1500
- /* @__PURE__ */ jsx16(
1501
- VotingHeader,
1502
- {
1503
- points: questionAnswered?.points || 0,
1504
- questionAnswered: !!questionAnswered,
1505
- questionAnsweredCorrectly: questionAnswered?.correct,
1506
- logo: fedex_default,
1507
- closeQuestion,
1508
- setTimeToExpire,
1509
- questionType: openedQuestion.type
1510
- }
1511
- ),
1512
- /* @__PURE__ */ jsx16("div", { children: /* @__PURE__ */ jsx16(
1513
- Vote,
1514
- {
1515
- title: openedQuestion.subject,
1516
- feedbackMessages: openedQuestion.options?.options.value,
1517
- questionType: openedQuestion.type,
1518
- questionId: openedQuestion.id,
1519
- questionAnswered: !!questionAnswered,
1520
- questionAnsweredCorrectly: questionAnswered?.correct,
1521
- options: openedQuestion.answers.map((answer) => ({
1522
- id: answer.id,
1523
- title: answer.text,
1524
- icon: answer.icon,
1525
- type: openedQuestion.type,
1526
- correct: answer.correct,
1527
- percentage: answer.percentage,
1528
- answered: answer.youVoted,
1529
- disabled: !!questionAnswered || openedQuestion.marketClosed || answerTimeExpired,
1530
- questionAnswered: !!questionAnswered,
1531
- hasCorrectAnswer,
1532
- onVote: vote
1533
- }))
1534
- }
1535
- ) })
1536
- ] }) });
1537
- };
1538
-
1539
- // packages/react-ui/src/lib/demo/components/Notifications.tsx
1540
- import { useStore as useStore4 } from "@nanostores/react";
1541
- import { useEffect as useEffect3, useRef, useState as useState4 } from "react";
1542
- import { jsx as jsx17 } from "@emotion/react/jsx-runtime";
1543
- var Notifications = ({ notificationsStore, openQuestion }) => {
1544
- const timeout = useRef();
1545
- const [lastNotification, setLastNotification] = useState4();
1546
- const notifications2 = useStore4(notificationsStore);
1547
- useEffect3(() => {
1548
- if (notifications2) {
1549
- setLastNotification(notifications2[notifications2.length - 1]?.data);
1550
- timeout.current = setTimeout(() => {
1551
- setLastNotification(void 0);
1552
- }, 5e3);
1553
- }
1554
- return () => {
1555
- if (timeout.current) {
1556
- clearTimeout(timeout.current);
1557
- }
1558
- };
1559
- }, [notifications2]);
1560
- if (!lastNotification?.question || !lastNotification?.notification) {
1561
- return null;
1562
- }
1563
- const closeInApp = () => {
1564
- if (timeout.current) {
1565
- clearTimeout(timeout.current);
1566
- }
1567
- setLastNotification(void 0);
1568
- };
1569
- const openVoiting = () => {
1570
- closeInApp();
1571
- openQuestion(lastNotification.question.id);
1572
- };
1573
- return /* @__PURE__ */ jsx17(
1574
- InApp,
1575
- {
1576
- openVoiting,
1577
- closeInApp,
1578
- title: lastNotification.notification.title,
1579
- icon: lastNotification.notification.image,
1580
- color: lastNotification.notification.indicatorColor
1581
- }
1582
- );
1583
- };
1584
-
1585
- // packages/react-ui/src/lib/demo/components/InPlayGame.tsx
1586
- import { jsx as jsx18 } from "@emotion/react/jsx-runtime";
1587
- var InPlayGame = ({ action }) => {
1588
- return /* @__PURE__ */ jsx18(Onboarding, { action });
1589
- };
1590
-
1591
- // packages/react-ui/src/lib/demo/styles.tsx
1592
- import styled15 from "@emotion/styled";
1593
- var DemoContainer = styled15.div`
1594
- position: relative;
1595
- height: 100%;
1596
- overflow: hidden;
1597
- `;
1598
- var DemoContainerNotifications = styled15.div`
1599
- position: absolute;
1600
- width: 100%;
1601
- `;
1602
- var UserStatisticsContainer = styled15.div`
1603
- margin-bottom: 15px;
1604
- `;
1605
-
1606
- // packages/react-ui/src/lib/demo/Gamification.tsx
1607
- import { jsx as jsx19, jsxs as jsxs14 } from "@emotion/react/jsx-runtime";
1608
- var GamificationComponent = ({
1609
- gamification,
1610
- sdk
1611
- }) => {
1612
- const onbordingComplete = useStore5(gamification.onbordingComplete);
1613
- const { slStreamId } = useStore5(sdk.sdkStore);
1614
- if (slStreamId?.loading) {
1615
- return /* @__PURE__ */ jsx19(DemoContainer, { children: /* @__PURE__ */ jsx19("div", { children: "Event is loading" }) });
1616
- }
1617
- if (!slStreamId?.data) {
1618
- return /* @__PURE__ */ jsx19(DemoContainer, { children: /* @__PURE__ */ jsx19("div", { children: "Event is forbidden" }) });
1619
- }
1620
- if (!onbordingComplete) {
1621
- return /* @__PURE__ */ jsx19(DemoContainer, { children: /* @__PURE__ */ jsx19(InPlayGame, { action: gamification.submitInplay }) });
1622
- }
1623
- const openQuestion = (questionId) => {
1624
- gamification.openQuestion(questionId);
1625
- };
1626
- const closeQuestion = () => {
1627
- gamification.closeQuestion();
1628
- };
1629
- const vote = (questionId, answerId) => {
1630
- void gamification.submitAnswer(questionId, answerId);
1631
- };
1632
- return /* @__PURE__ */ jsxs14(DemoContainer, { children: [
1633
- /* @__PURE__ */ jsx19(DemoContainerNotifications, { children: /* @__PURE__ */ jsx19(Notifications, { notificationsStore: sdk.getNotificationsStore(), openQuestion }) }),
1634
- /* @__PURE__ */ jsx19(UserStatisticsContainer, { children: gamification.userSummary && /* @__PURE__ */ jsx19(UserSummary, { store: gamification.userSummary.getStore() }) }),
1635
- gamification.questions && /* @__PURE__ */ jsx19(QuestionsList, { openQuestion, store: gamification.questions.getStore() }),
1636
- gamification.openedQuestion && /* @__PURE__ */ jsx19(Question2, { closeQuestion, vote, store: gamification.openedQuestion.getStore() })
1637
- ] });
1638
- };
1639
-
1640
- // packages/react-ui/src/lib/demo/Login.tsx
1641
- import { jsx as jsx20 } from "@emotion/react/jsx-runtime";
1642
- var LoginComponent = ({ sdk }) => {
1643
- const login2 = async (token) => {
1644
- try {
1645
- await sdk.authorizationBypass("streamlayer:streamlayer", token);
1646
- } catch (err) {
1647
- console.log("login err", err);
1648
- throw err;
1649
- }
1650
- };
1651
- return /* @__PURE__ */ jsx20(Login, { login: login2, anonymousLogin: sdk.anonymousAuthorization });
1652
- };
1653
-
1654
- // packages/react-ui/src/lib/demo/index.tsx
1655
- import { jsx as jsx21 } from "@emotion/react/jsx-runtime";
1656
- var Demo = ({ sdk }) => {
1657
- const user = useStore6(sdk.getUserStore());
1658
- if (user.loading) {
1659
- return /* @__PURE__ */ jsx21("div", { children: "authentificating..." });
1660
- }
1661
- if (!user.data) {
1662
- return /* @__PURE__ */ jsx21(LoginComponent, { sdk });
1663
- }
1664
- const gamification = sdk.getFeatures().get("games");
1665
- if (!gamification) {
1666
- return /* @__PURE__ */ jsx21("div", { children: "wait gamification..." });
1667
- }
1668
- return /* @__PURE__ */ jsx21(GamificationComponent, { gamification, sdk });
1669
- };
1670
-
1671
- // packages/react-ui/src/lib/theme/index.tsx
1672
- import { ThemeProvider } from "@emotion/react";
1673
- import { jsx as jsx22 } from "@emotion/react/jsx-runtime";
1674
- var StreamLayerThemeProvider = ({ children }) => /* @__PURE__ */ jsx22(ThemeProvider, { theme, children });
1675
-
1676
- // packages/react/src/app/provider.tsx
1677
- import { createContext, useMemo as useMemo2 } from "react";
1678
-
1679
- // packages/sdk-web-interfaces/src/auth.ts
1680
- var AbstractAuthenticationProvider = class {
1681
- };
1682
-
1683
- // packages/sdk-web-interfaces/src/feature.ts
1684
- import { SdkOverlayType as SdkOverlayType2 } from "@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb";
1685
- import { atom } from "nanostores";
1686
-
1687
- // packages/sdk-web-interfaces/src/store/map.ts
1688
- import { map } from "nanostores";
1689
-
1690
- // packages/sdk-web-interfaces/src/store/abstract.ts
1691
- import { computed } from "nanostores";
1692
- import { buildLogger } from "@nanostores/logger";
1693
- import diff from "microdiff";
1694
- window.storeLogger = /* @__PURE__ */ Object.create(null);
1695
- var slStoreLogger = (store2, name) => buildLogger(store2, name, {
1696
- mount: ({ storeName }) => {
1697
- if (!window.storeLogger[storeName]) {
1698
- window.storeLogger[storeName] = { mounted: true, history: [{ type: "mount" }] };
1699
- }
1700
- window.storeLogger[storeName].store = store2;
1701
- },
1702
- unmount: ({ storeName }) => {
1703
- window.storeLogger[storeName].mounted = false;
1704
- window.storeLogger[storeName]?.history.push({ type: "unmount" });
1705
- },
1706
- change: ({ actionName, storeName, changed, newValue, oldValue, valueMessage }) => {
1707
- window.storeLogger[storeName]?.history.push({
1708
- type: "change",
1709
- changed,
1710
- newValue,
1711
- oldValue,
1712
- diff: diff({ ...oldValue }, { ...newValue }, { cyclesFix: false }),
1713
- actionName,
1714
- valueMessage
1715
- });
1716
- },
1717
- action: {
1718
- start: ({ actionName, args, storeName }) => {
1719
- window.storeLogger[storeName]?.history.push({
1720
- type: "action:start",
1721
- actionName,
1722
- args,
1723
- storeName
1724
- });
1725
- },
1726
- error: ({ actionName, error, storeName }) => {
1727
- window.storeLogger[storeName]?.history.push({
1728
- type: "action:error",
1729
- actionName,
1730
- error
1731
- });
1732
- },
1733
- end: ({ actionName, storeName }) => {
1734
- window.storeLogger[storeName]?.history.push({
1735
- type: "action:end",
1736
- actionName
1737
- });
1738
- }
1739
- }
1740
- });
1741
- var AbstractStore = class {
1742
- /**
1743
- * store instance (nanostores)
1744
- */
1745
- store;
1746
- name;
1747
- constructor(store2, name) {
1748
- this.store = store2;
1749
- this.name = name;
1750
- if (process.env.NODE_ENV !== "production") {
1751
- slStoreLogger(this.store, this.name);
1752
- }
1753
- }
1754
- /**
1755
- * return store instance
1756
- */
1757
- getStore() {
1758
- return this.store;
1759
- }
1760
- };
1761
- var mergeStores = (stores) => {
1762
- const storeKeys = Object.keys(stores);
1763
- return computed(
1764
- storeKeys.map((key) => stores[key].getStore()),
1765
- (...storeValues) => Object.fromEntries(storeKeys.map((key, i) => [key, storeValues[i]]))
1766
- );
1767
- };
1768
-
1769
- // packages/sdk-web-interfaces/src/store/map.ts
1770
- var MapStore = class extends AbstractStore {
1771
- getValues = () => {
1772
- const store2 = this.getStore();
1773
- return store2.get();
1774
- };
1775
- getValue = (key) => {
1776
- const store2 = this.getStore();
1777
- return store2.get()[key];
1778
- };
1779
- setValue = (path, value) => {
1780
- const store2 = this.getStore();
1781
- return store2.setKey(path, value);
1782
- };
1783
- subscribe = (...args) => {
1784
- const store2 = this.getStore();
1785
- return store2.subscribe(...args);
1786
- };
1787
- unsubscribe = () => {
1788
- const store2 = this.getStore();
1789
- return store2.off();
1790
- };
1791
- };
1792
- var createMapStore = (initialData) => {
1793
- return map(initialData);
1794
- };
1795
-
1796
- // packages/sdk-web-interfaces/src/feature.ts
1797
- var FeatureTypes = {
1798
- [SdkOverlayType2.BETTING]: "betting",
1799
- [SdkOverlayType2.GAMES]: "games",
1800
- [SdkOverlayType2.PUBLIC_CHAT]: "publicChat",
1801
- [SdkOverlayType2.TWITTER]: "twitter"
1802
- };
1803
- var AbstractFeature = class {
1804
- status;
1805
- source;
1806
- config;
1807
- settings;
1808
- listeners = /* @__PURE__ */ new Set();
1809
- settingsKey;
1810
- constructor({ settings, ...config2 }, source) {
1811
- this.settingsKey = FeatureTypes[config2.type];
1812
- this.status = atom("suspended" /* Suspended */);
1813
- this.config = new MapStore(createMapStore(config2), `feature:config:${this.settingsKey}`);
1814
- if (this.settingsKey !== void 0 && settings?.overlaySettings.case === this.settingsKey) {
1815
- this.settings = new MapStore(
1816
- createMapStore(settings.overlaySettings.value),
1817
- `feature:settings:${this.settingsKey}`
1818
- );
1819
- } else {
1820
- this.settings = new MapStore(createMapStore({}), `feature:settings:${this.settingsKey}`);
1821
- }
1822
- this.source = source;
1823
- }
1824
- get featureConfig() {
1825
- return this.config.getStore();
1826
- }
1827
- get featureSettings() {
1828
- return this.settings.getStore();
1829
- }
1830
- registerEventListener(listener) {
1831
- this.listeners.add(listener);
1832
- }
1833
- enable = () => {
1834
- this.status.set("ready" /* Ready */);
1835
- };
1836
- disabled = () => {
1837
- this.status.set("suspended" /* Suspended */);
1838
- };
1839
- setFeatureConfig = ({ settings, ...config2 }) => {
1840
- let configKey;
1841
- for (configKey in config2) {
1842
- this.config.setValue(configKey, config2[configKey]);
1843
- }
1844
- if (settings?.overlaySettings.case === this.settingsKey) {
1845
- const newSettings = settings.overlaySettings.value;
1846
- if (newSettings !== void 0) {
1847
- let key;
1848
- for (key in newSettings) {
1849
- console.log(key, newSettings[key]);
1850
- if (newSettings[key] !== 0 && newSettings[key] !== "") {
1851
- this.settings.setValue(key, newSettings[key]);
1852
- }
1853
- }
1854
- }
1855
- }
1856
- };
1857
- update = (config2, source) => {
1858
- if (this.source === "STREAM" /* STREAM */ && source === "ORGANIZATION" /* ORGANIZATION */) {
1859
- return;
1860
- }
1861
- this.setFeatureConfig(config2);
1862
- this.source = source;
1863
- };
1864
- fireEvent(event) {
1865
- for (const listener of this.listeners.values()) {
1866
- try {
1867
- listener.onEvent(event);
1868
- } catch (err) {
1869
- console.error(err);
1870
- }
1871
- }
1872
- }
1873
- };
1874
-
1875
- // packages/sdk-web-interfaces/src/store/single.ts
1876
- import { atom as atom2 } from "nanostores";
1877
- var SingleStore = class extends AbstractStore {
1878
- getValue = () => {
1879
- const store2 = this.getStore();
1880
- return store2.get();
1881
- };
1882
- getValues() {
1883
- throw new Error("not implemented");
1884
- }
1885
- setValue = (value) => {
1886
- const store2 = this.getStore();
1887
- return store2.set(value);
1888
- };
1889
- subscribe = (listener) => {
1890
- const store2 = this.getStore();
1891
- return store2.subscribe(listener);
1892
- };
1893
- unsubscribe = () => {
1894
- const store2 = this.getStore();
1895
- return store2.off();
1896
- };
1897
- listen(listener) {
1898
- const store2 = this.getStore();
1899
- return store2.listen(listener);
1900
- }
1901
- get() {
1902
- const store2 = this.getStore();
1903
- return store2.get();
1904
- }
1905
- };
1906
- var createSingleStore = (initialData) => atom2(initialData);
1907
-
1908
- // packages/sdk-web-interfaces/src/store/api.ts
1909
- import { atom as atom3 } from "nanostores";
1910
- var ApiStore = class extends AbstractStore {
1911
- atomStore;
1912
- constructor(store2, name, atomPicker) {
1913
- super(store2, `api:${name}`);
1914
- this.atomStore = atom3();
1915
- if (atomPicker) {
1916
- store2.subscribe((data) => {
1917
- this.atomStore.set(atomPicker(data));
1918
- });
1919
- }
1920
- }
1921
- getAtomStore = () => this.atomStore;
1922
- getValue = async () => {
1923
- const store2 = this.getStore();
1924
- if (store2.value === void 0) {
1925
- throw new Error("no store");
1926
- }
1927
- await store2.value.promise;
1928
- return store2.get().data;
1929
- };
1930
- getValues = () => {
1931
- throw new Error("not implemented");
1932
- };
1933
- setValue = (value) => {
1934
- const store2 = this.getStore();
1935
- return store2.set({ loading: false, data: value?.data });
1936
- };
1937
- subscribe = (listener) => {
1938
- const store2 = this.getStore();
1939
- return store2.subscribe(listener);
1940
- };
1941
- unsubscribe = () => {
1942
- throw new Error("not implemented");
1943
- };
1944
- invalidate = () => {
1945
- this.store.invalidate();
1946
- };
1947
- listen = (cb) => {
1948
- const store2 = this.getStore();
1949
- return store2.listen(cb);
1950
- };
1951
- get() {
1952
- throw new Error("not implemented");
1953
- }
1954
- key = () => {
1955
- const store2 = this.getStore();
1956
- return store2.key;
1957
- };
1958
- off = () => {
1959
- const store2 = this.getStore();
1960
- return store2.off();
1961
- };
1962
- };
1963
-
1964
- // packages/sdk-web-api/src/grpc/transport.ts
1965
- import {
1966
- createRouterTransport,
1967
- createPromiseClient as createPromiseClient2,
1968
- createCallbackClient
1969
- } from "@connectrpc/connect";
1970
- import { createGrpcWebTransport as createGrpcWebTransport2 } from "@bufbuild/connect-web";
1971
- import { nanoquery } from "@nanostores/query";
1972
-
1973
- // packages/sdk-web-api/src/utils/devtools.ts
1974
- async function* logEach(store2, stream) {
1975
- for await (const m of stream) {
1976
- store2.response.message = m;
1977
- store2.received_at = Date.now();
1978
- const msg = {
1979
- type: "__GRPC_DEVTOOLS_EXTENSION__",
1980
- data: store2
1981
- };
1982
- window.postMessage(msg);
1983
- yield m;
1984
- }
1985
- }
1986
- var __GRPC_DEVTOOLS_EXTENSION__ = () => (next) => async (request) => {
1987
- const store2 = {
1988
- name: request.url,
1989
- request: {},
1990
- response: {}
1991
- };
1992
- store2.request.header = Object.fromEntries(request.header.entries());
1993
- store2.sent_at = Date.now();
1994
- try {
1995
- const response = await next(request);
1996
- store2.received_at = Date.now();
1997
- store2.stream = response.stream;
1998
- store2.response.header = Object.fromEntries(response.header.entries());
1999
- store2.response.trailer = Object.fromEntries(response.trailer.entries());
2000
- if (!response.stream) {
2001
- store2.request.message = request.message;
2002
- store2.response.message = response.message;
2003
- store2.latency = store2.received_at - store2.sent_at;
2004
- const msg = {
2005
- type: "__GRPC_DEVTOOLS_EXTENSION__",
2006
- data: store2
2007
- };
2008
- window.postMessage(msg);
2009
- } else {
2010
- return {
2011
- ...response,
2012
- message: logEach(store2, response.message)
2013
- };
2014
- }
2015
- return response;
2016
- } catch (e) {
2017
- store2.received_at = Date.now();
2018
- store2.request.message = request.message;
2019
- store2.response.trailer = {
2020
- ["grpc-status"]: e.code,
2021
- ["grpc-message"]: e.rawMessage
2022
- };
2023
- store2.response.message = e.rawMessage;
2024
- store2.latency = store2.received_at - store2.sent_at;
2025
- const msg = {
2026
- type: "__GRPC_DEVTOOLS_EXTENSION__",
2027
- data: store2
2028
- };
2029
- window.postMessage(msg);
2030
- throw e;
2031
- }
2032
- };
2033
- window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
2034
-
2035
- // packages/sdk-web-api/src/grpc/subscription.ts
2036
- import { Code } from "@connectrpc/connect";
2037
- var ServerStreamSubscription = class {
2038
- params;
2039
- stream;
2040
- method;
2041
- name;
2042
- headers;
2043
- listeners;
2044
- state;
2045
- store;
2046
- constructor(headers, method, params, options) {
2047
- const initState = {
2048
- status: "init" /* Init */,
2049
- ts: /* @__PURE__ */ new Date(),
2050
- log: []
2051
- };
2052
- this.state = new MapStore(createMapStore(initState), `subscription:${options.name}:state`);
2053
- this.name = options.name;
2054
- this.headers = headers;
2055
- this.listeners = /* @__PURE__ */ new Map();
2056
- this.params = params;
2057
- this.method = method;
2058
- if (options.withStore) {
2059
- this.store = new SingleStore(createSingleStore(null), `subscription:${options.name}:store`);
2060
- }
2061
- if ("subscribe" in params && typeof params.subscribe === "function") {
2062
- params.subscribe(() => {
2063
- this.reconnect();
2064
- });
2065
- }
2066
- this.updateState("ready" /* Ready */);
2067
- }
2068
- updateState = (status) => {
2069
- this.state.setValue("status", status);
2070
- this.state.setValue("ts", /* @__PURE__ */ new Date());
2071
- this.addStateLog(`status => ${status}`);
2072
- };
2073
- addStateLog = (msg) => {
2074
- const log = this.state.getStore().get()["log"];
2075
- this.state.setValue("log", [...log, `${(/* @__PURE__ */ new Date()).toLocaleString()}: ${msg}`]);
2076
- };
2077
- addListener = (name, listener) => {
2078
- if (this.listeners.has(name)) {
2079
- this.addStateLog(`listener '${name}' not added`);
2080
- return false;
2081
- }
2082
- this.listeners.set(name, listener);
2083
- this.addStateLog(`listener '${name}' added`);
2084
- return true;
2085
- };
2086
- removeListener = (name) => {
2087
- this.listeners.delete(name);
2088
- this.addStateLog(`listener '${name}' removed`);
2089
- };
2090
- connect = () => {
2091
- this.updateState("connecting" /* Connecting */);
2092
- if (this.stream) {
2093
- this.addStateLog(`disconnect prev connection`);
2094
- this.stream();
2095
- }
2096
- const params = "get" in this.params && typeof this.params.get === "function" ? this.params.get() : this.params;
2097
- this.stream = this.method(
2098
- params,
2099
- // ToDo: fix types
2100
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2101
- // @ts-ignore
2102
- this.onData,
2103
- this.onStreamError,
2104
- { headers: this.headers.getValues() }
2105
- );
2106
- this.updateState("connected" /* Connected */);
2107
- };
2108
- disconnect = () => {
2109
- if (this.stream) {
2110
- this.stream();
2111
- }
2112
- this.listeners.clear();
2113
- this.updateState("disconnected" /* Disconnected */);
2114
- };
2115
- reconnect = () => {
2116
- this.updateState("reconnecting" /* Reconnecting */);
2117
- this.connect();
2118
- };
2119
- getStore = () => this.store?.getStore();
2120
- onData = (response) => {
2121
- this.addStateLog(`received data => ${JSON.stringify(response)}`);
2122
- if (this.store) {
2123
- this.store.setValue(response);
2124
- }
2125
- for (const [, listener] of this.listeners) {
2126
- listener(response);
2127
- }
2128
- this.addStateLog(`data routed to ${this.listeners.size} listeners`);
2129
- };
2130
- onStreamError = (error) => {
2131
- if (error.code !== Code.Canceled && error.rawMessage !== "[canceled] BodyStreamBuffer was aborted") {
2132
- this.updateState("failed" /* Failed */);
2133
- this.state.setValue("error", error);
2134
- } else {
2135
- this.disconnect();
2136
- }
2137
- };
2138
- };
2139
-
2140
- // packages/sdk-web-api/src/grpc/transport.ts
2141
- var Transport = class {
2142
- toJsonOptions = {
2143
- emitDefaultValues: false,
2144
- enumAsInteger: true,
2145
- useProtoFieldName: false
2146
- };
2147
- transport;
2148
- nanoquery;
2149
- interceptors = [];
2150
- $headers;
2151
- clients;
2152
- callbackClients;
2153
- subscriptions;
2154
- constructor() {
2155
- this.$headers = new MapStore(
2156
- createMapStore({
2157
- ["sl-device-id"]: process.env.NX_DEVICE_ID || "sdk-web-dev"
2158
- }),
2159
- "transport:headers"
2160
- );
2161
- this.initInterceptors();
2162
- this.clients = /* @__PURE__ */ new Map();
2163
- this.callbackClients = /* @__PURE__ */ new Map();
2164
- this.subscriptions = /* @__PURE__ */ new Map();
2165
- const [createFetcherStore, createMutatorStore, utils] = nanoquery();
2166
- this.nanoquery = { createFetcherStore, createMutatorStore, utils };
2167
- this.transport = createGrpcWebTransport2({
2168
- baseUrl: process.env.NX_GRPC_HOST || "https://grpc-web.next.streamlayer.io:443",
2169
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2170
- // @ts-ignore
2171
- interceptors: this.interceptors,
2172
- useBinaryFormat: true
2173
- });
2174
- }
2175
- // use shared request params, based on Atom, each new Atom will create new subscription
2176
- // mutate Atom, subscription automatically reconnect with new params
2177
- // if headers changed, reconnect subscription with new headers automatically
2178
- addSubscription = (method, params, options) => {
2179
- const currentSubscription = this.subscriptions.get(params);
2180
- if (currentSubscription) {
2181
- return currentSubscription;
2182
- }
2183
- const subscription = new ServerStreamSubscription(this.$headers, method, params, options);
2184
- this.subscriptions.set(params, subscription);
2185
- return subscription;
2186
- };
2187
- removeSubscription = (subscription) => {
2188
- subscription.disconnect();
2189
- this.subscriptions.delete(subscription.params);
2190
- };
2191
- // cleanup subscriptions
2192
- disconnect = () => {
2193
- for (const [name, subscription] of this.subscriptions) {
2194
- subscription.disconnect();
2195
- this.subscriptions.delete(name);
2196
- }
2197
- };
2198
- registerInterceptor = (interceptor) => {
2199
- this.interceptors.push(interceptor);
2200
- };
2201
- removeInterceptor = (interceptor) => {
2202
- this.interceptors = this.interceptors.filter((i) => i !== interceptor);
2203
- };
2204
- getClient = (service) => {
2205
- const serviceName = service.typeName;
2206
- if (this.clients.has(serviceName)) {
2207
- return this.clients.get(serviceName);
2208
- }
2209
- const client = createPromiseClient2(service, this.transport);
2210
- this.clients.set(serviceName, client);
2211
- return client;
2212
- };
2213
- getCallbackClient = (service) => {
2214
- const serviceName = service.typeName;
2215
- if (this.callbackClients.has(serviceName)) {
2216
- return this.callbackClients.get(serviceName);
2217
- }
2218
- const client = createCallbackClient(service, this.transport);
2219
- this.callbackClients.set(serviceName, client);
2220
- return client;
2221
- };
2222
- // create unary client, used for query request
2223
- createPromiseClient = (service, { params = [], method }) => {
2224
- const client = this.getClient(service);
2225
- const methodName = service.methods[method].name;
2226
- const queryKey = [
2227
- service.typeName,
2228
- methodName.charAt(0).toLowerCase() + methodName.slice(1),
2229
- ...Array.isArray(params) ? params : [params]
2230
- ];
2231
- const queryKeyWithoutParams = [service.typeName, methodName.charAt(0).toLowerCase() + methodName.slice(1)];
2232
- return { client, queryKey, queryKeyStr: queryKeyWithoutParams.join("") };
2233
- };
2234
- // create callback client, used for server stream subscriptions
2235
- createCallbackClient = (service) => {
2236
- const client = this.getCallbackClient(service);
2237
- return { client };
2238
- };
2239
- setSdkKey = (sdkKey) => {
2240
- this.$headers.setValue("sdk", sdkKey);
2241
- };
2242
- setAuth = (token) => {
2243
- this.$headers.setValue("authorization", token);
2244
- };
2245
- setHeader = (name, value) => this.$headers.setValue(name, value);
2246
- getHeader = (name) => this.$headers.getValue(name);
2247
- getHeaders = () => this.$headers.getValues();
2248
- initInterceptors = () => {
2249
- if (this.interceptors.length !== 0) {
2250
- return;
2251
- }
2252
- const auth = (next) => async (req) => {
2253
- const headers = this.$headers.getValues();
2254
- for (const header in headers) {
2255
- req.header.set(header, headers[header]);
2256
- }
2257
- try {
2258
- return await next(req);
2259
- } catch (err) {
2260
- console.log({ err, req }, "catch err");
2261
- throw err;
2262
- }
2263
- };
2264
- this.interceptors.push(auth);
2265
- this.interceptors.push(__GRPC_DEVTOOLS_EXTENSION__());
2266
- };
2267
- };
2268
-
2269
- // packages/sdk-web-api/src/grpc/queries/index.ts
2270
- var queries_exports = {};
2271
- __export(queries_exports, {
2272
- $bypassLogin: () => $bypassLogin,
2273
- $organizationAdvertising: () => $organizationAdvertising,
2274
- $organizationSettings: () => $organizationSettings,
2275
- $retrieveEventId: () => $retrieveEventId,
2276
- $streamSettings: () => $streamSettings,
2277
- $user: () => $user,
2278
- $userSettings: () => $userSettings,
2279
- bypassAuth: () => bypassAuth,
2280
- register: () => register2
2281
- });
2282
-
2283
- // packages/sdk-web-api/src/grpc/queries/event.ts
2284
- import { Events } from "@streamlayer/sl-eslib/sports/events/events_connect";
2285
- import { Client } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
2286
- var $retrieveEventId = ($providerStreamId, transport2) => {
2287
- const { client, queryKey } = transport2.createPromiseClient(Events, {
2288
- method: "retrieveEventId",
2289
- params: [$providerStreamId]
2290
- });
2291
- return transport2.nanoquery.createFetcherStore(queryKey, {
2292
- fetcher: async (_, __, id) => {
2293
- if (!id || typeof id !== "string") {
2294
- return "";
2295
- }
2296
- try {
2297
- const res = await client.retrieveEventId({
2298
- id
2299
- });
2300
- return res.data?.id || "";
2301
- } catch (err) {
2302
- return "";
2303
- }
2304
- }
2305
- });
2306
- };
2307
- var $streamSettings = (slStreamId, transport2) => {
2308
- const { client, queryKey } = transport2.createPromiseClient(Client, { method: "getStream", params: [slStreamId] });
2309
- return transport2.nanoquery.createFetcherStore(queryKey, {
2310
- fetcher: async (_, __, id) => {
2311
- if (!id) {
2312
- return void 0;
2313
- }
2314
- const res = await client.getStream({
2315
- id
2316
- // we are sure that id is a string
2317
- });
2318
- return res.data?.attributes;
2319
- }
2320
- });
2321
- };
2322
-
2323
- // packages/sdk-web-api/src/grpc/queries/organization.ts
2324
- import { Client as Client3 } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
2325
-
2326
- // packages/sdk-web-api/src/grpc/queries/user.ts
2327
- import { Users as Users2 } from "@streamlayer/sl-eslib/users/users_connect";
2328
- import { Client as Client2 } from "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
2329
- var $user = ($userToken, transport2) => {
2330
- const { queryKey, client } = transport2.createPromiseClient(Users2, { method: "me", params: [$userToken] });
2331
- return transport2.nanoquery.createFetcherStore(queryKey, {
2332
- fetcher: () => client.me({})
2333
- });
2334
- };
2335
- var $bypassLogin = (transport2) => {
2336
- const { client, queryKeyStr } = transport2.createPromiseClient(Users2, { method: "bypassAuth" });
2337
- return transport2.nanoquery.createMutatorStore(
2338
- async ({ data: { userKey, schema, init }, getCacheUpdater }) => {
2339
- const [updateCache] = getCacheUpdater(queryKeyStr);
2340
- const user = await client.bypassAuth({ userKey, schema, init });
2341
- updateCache(user);
2342
- return user;
2343
- }
2344
- );
2345
- };
2346
- var bypassAuth = (transport2, params) => {
2347
- const { client } = transport2.createPromiseClient(Users2, { method: "bypassAuth" });
2348
- return client.bypassAuth(params);
2349
- };
2350
- var $userSettings = ($userToken, transport2) => {
2351
- const { client, queryKey } = transport2.createPromiseClient(Client2, { method: "get", params: [$userToken] });
2352
- return transport2.nanoquery.createFetcherStore(queryKey, {
2353
- fetcher: async () => {
2354
- const data = await client.get({});
2355
- return data.data?.attributes;
2356
- }
2357
- });
2358
- };
2359
- var register2 = (transport2, phone) => {
2360
- const { client } = transport2.createPromiseClient(Users2, { method: "register" });
2361
- return client.register({ id: phone });
2362
- };
2363
-
2364
- // packages/sdk-web-api/src/grpc/queries/organization.ts
2365
- var $organizationSettings = ($enabled, transport2) => {
2366
- const { client, queryKey } = transport2.createPromiseClient(Client3, { method: "getOrganization", params: [$enabled] });
2367
- return transport2.nanoquery.createFetcherStore(queryKey, {
2368
- fetcher: async () => {
2369
- const res = await client.getOrganization({});
2370
- return res.data ? {
2371
- ...res.data.attributes,
2372
- id: res.data.id
2373
- } : void 0;
2374
- }
2375
- });
2376
- };
2377
- var $organizationAdvertising = ($enabled, transport2) => {
2378
- const { client, queryKey } = transport2.createPromiseClient(Client3, {
2379
- method: "getOrganizationAdvertising",
2380
- params: [$enabled]
2381
- });
2382
- return transport2.nanoquery.createFetcherStore(queryKey, {
2383
- fetcher: async () => {
2384
- const res = await client.getOrganizationAdvertising({});
2385
- return res.data?.attributes;
2386
- }
2387
- });
2388
- };
2389
-
2390
- // packages/sdk-web-api/src/index.ts
2391
- var transport = (instance, opts, done) => {
2392
- instance.transport = new Transport();
2393
- instance.transport.setSdkKey(opts.sdkKey);
2394
- done();
2395
- };
2396
-
2397
- // packages/sdk-web-core/src/store/store.ts
2398
- var initializeStore = (transport2) => {
2399
- const enabled = new SingleStore(createSingleStore(), "enabled");
2400
- const status = new SingleStore(createSingleStore("disabled" /* DISABLED */), "status");
2401
- const userKey = new SingleStore(createSingleStore(), "userKey");
2402
- const userToken = new SingleStore(createSingleStore(), "userToken");
2403
- userToken.listen((token) => {
2404
- if (token) {
2405
- localStorage.setItem("sl-user-token", token);
2406
- } else {
2407
- localStorage.removeItem("sl-user-token");
2408
- }
2409
- });
2410
- const providerStreamId = new SingleStore(createSingleStore(), "providerStreamId");
2411
- const slStreamId = new ApiStore(
2412
- queries_exports.$retrieveEventId(providerStreamId.getStore(), transport2),
2413
- "slStreamId",
2414
- (data) => data?.data
2415
- );
2416
- const user = new ApiStore(
2417
- queries_exports.$user(userToken.getStore(), transport2),
2418
- "user",
2419
- (data) => data?.data?.data?.id
2420
- );
2421
- const userSettings = new ApiStore(
2422
- queries_exports.$userSettings(userToken.getStore(), transport2),
2423
- "userSettings"
2424
- );
2425
- const streamSettings = new ApiStore(
2426
- queries_exports.$streamSettings(slStreamId.getAtomStore(), transport2),
2427
- "streamSettings"
2428
- );
2429
- slStreamId.getAtomStore().listen((eventId) => {
2430
- if (eventId === "" || eventId === void 0) {
2431
- streamSettings.getStore().mutate(void 0);
2432
- }
2433
- });
2434
- const organizationSettings = new ApiStore(
2435
- queries_exports.$organizationSettings(enabled.getStore(), transport2),
2436
- "organizationSettings",
2437
- (data) => data?.data?.id
2438
- );
2439
- const organizationAdvertising = new ApiStore(
2440
- queries_exports.$organizationAdvertising(organizationSettings.getAtomStore(), transport2),
2441
- "organizationAdvertising"
2442
- );
2443
- return {
2444
- enabled,
2445
- status,
2446
- providerStreamId,
2447
- slStreamId,
2448
- streamSettings,
2449
- user,
2450
- userKey,
2451
- userToken,
2452
- userSettings,
2453
- organizationSettings,
2454
- organizationAdvertising
2455
- };
2456
- };
2457
- var CoreStore = class extends AbstractStore {
2458
- stores;
2459
- constructor(transport2) {
2460
- const storesObj = initializeStore(transport2);
2461
- const store2 = mergeStores(storesObj);
2462
- super(store2, "core");
2463
- this.stores = storesObj;
2464
- }
2465
- getValue() {
2466
- throw new Error("Not implemented");
2467
- }
2468
- getValues() {
2469
- return this.stores;
2470
- }
2471
- setValue() {
2472
- throw new Error("Not implemented");
2473
- }
2474
- subscribe = (subscribes) => {
2475
- let storeKey;
2476
- for (storeKey in this.stores) {
2477
- const fn = subscribes[storeKey];
2478
- if (storeKey in subscribes && fn !== void 0) {
2479
- this.stores[storeKey].subscribe(subscribes[storeKey]);
2480
- }
2481
- }
2482
- };
2483
- unsubscribe = () => {
2484
- const store2 = this.getStore();
2485
- return store2.off();
2486
- };
2487
- };
2488
-
2489
- // packages/sdk-web-core/src/index.ts
2490
- var core = (instance, opts, done) => {
2491
- instance.sdk = /* @__PURE__ */ Object.create(null);
2492
- instance.sdk.initializeApp = async () => {
2493
- instance.storeSubscribe();
2494
- instance.stores.enabled.setValue("on");
2495
- instance.stores.status.setValue("initialization" /* INITIALIZATION */);
2496
- try {
2497
- const organizationSettings = await instance.stores.organizationSettings.getValue();
2498
- if (organizationSettings) {
2499
- instance.stores.status.setValue("ready" /* READY */);
2500
- return { enabled: !!organizationSettings };
2501
- }
2502
- instance.stores.status.setValue("failed" /* FAILED */);
2503
- return { err: "failed" };
2504
- } catch (err) {
2505
- instance.stores.enabled.setValue();
2506
- instance.stores.status.setValue("failed" /* FAILED */);
2507
- return { err: `${err}` };
2508
- }
2509
- };
2510
- instance.sdk.disableApp = () => {
2511
- instance.stores.enabled.setValue();
2512
- instance.stores.status.setValue("disabled" /* DISABLED */);
2513
- instance.storeUnsubscribe();
2514
- };
2515
- instance.sdk.createEventSession = (providerStreamId) => {
2516
- instance.stores.providerStreamId.setValue("");
2517
- instance.stores.providerStreamId.setValue(providerStreamId);
2518
- };
2519
- done();
2520
- };
2521
-
2522
- // packages/feature-gamification/src/queries/index.ts
2523
- import { atom as atom4 } from "nanostores";
2524
- import { Feed } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect";
2525
-
2526
- // packages/feature-gamification/src/queries/leaderboard.ts
2527
- import { Leaderboard } from "@streamlayer/sl-eslib/interactive/leaderboard/interactive.leaderboard_connect";
2528
- var $userSummary = ($eventId, $userId, transport2) => {
2529
- const { client, queryKey } = transport2.createPromiseClient(Leaderboard, {
2530
- method: "summary",
2531
- params: [$eventId, $userId]
2532
- });
2533
- return transport2.nanoquery.createFetcherStore(queryKey, {
2534
- fetcher: async (_, __, eventId, userId) => {
2535
- const res = await client.summary({
2536
- eventId,
2537
- userId
2538
- });
2539
- return res.data?.attributes;
2540
- }
2541
- });
2542
- };
2543
-
2544
- // packages/feature-gamification/src/queries/index.ts
2545
- var $activeQuestion = (slStreamId, transport2) => {
2546
- const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "syncQuestion", params: [slStreamId] });
2547
- return transport2.nanoquery.createFetcherStore(queryKey, {
2548
- fetcher: async (_, __, id) => {
2549
- if (!id) {
2550
- return void 0;
2551
- }
2552
- const res = await client.syncQuestion({
2553
- filter: {
2554
- eventId: id
2555
- }
2556
- });
2557
- return res.data?.attributes;
2558
- }
2559
- });
2560
- };
2561
- var feedSubscription = ($slStreamId, transport2) => {
2562
- const { client } = transport2.createCallbackClient(Feed);
2563
- const params = atom4({ eventId: $slStreamId.get() || "", feedId: "" });
2564
- $slStreamId.subscribe((eventId = "") => {
2565
- params.set({ eventId, feedId: "" });
2566
- });
2567
- const subscription = transport2.addSubscription(
2568
- client.subscription,
2569
- params,
2570
- { name: "feedSubscription" }
2571
- );
2572
- return subscription;
2573
- };
2574
- var questionSubscription = (questionId, transport2) => {
2575
- const { client } = transport2.createCallbackClient(Feed);
2576
- const subscription = transport2.addSubscription(client.questionSubscription, { questionId }, { name: "questionSubscription" });
2577
- return subscription;
2578
- };
2579
- var $questionByUser = ($questionId, transport2) => {
2580
- const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "questionByUser", params: [$questionId] });
2581
- return transport2.nanoquery.createFetcherStore(queryKey, {
2582
- fetcher: async (_, __, questionId) => {
2583
- const res = await client.questionByUser({
2584
- questionId
2585
- });
2586
- return res.data?.attributes?.question;
2587
- }
2588
- });
2589
- };
2590
- var $pickHistory = (slStreamId, transport2) => {
2591
- const { client, queryKey } = transport2.createPromiseClient(Feed, { method: "pickHistory", params: [slStreamId] });
2592
- return transport2.nanoquery.createFetcherStore(queryKey, {
2593
- fetcher: async (_, __, eventId) => {
2594
- if (!eventId) {
2595
- return void 0;
2596
- }
2597
- const res = await client.pickHistory({
2598
- eventId
2599
- });
2600
- return res.data?.map(({ attributes }) => attributes);
2601
- }
2602
- });
2603
- };
2604
-
2605
- // packages/feature-gamification/src/queries/actions.ts
2606
- import { Feed as Feed2 } from "@streamlayer/sl-eslib/interactive/feed/interactive.feed_connect";
2607
- var submitAnswer = (transport2, data) => {
2608
- const { client } = transport2.createPromiseClient(Feed2, { method: "submitAnswer" });
2609
- return client.submitAnswer({ data });
2610
- };
2611
- var submitInplay = (transport2, eventId) => {
2612
- const { client } = transport2.createPromiseClient(Feed2, { method: "submitInplay" });
2613
- return client.submitInplay({ data: { eventId: +eventId } });
2614
- };
2615
- var skipQuestion = (transport2, questionId) => {
2616
- const { client } = transport2.createPromiseClient(Feed2, { method: "skipQuestion" });
2617
- return client.skipQuestion({ data: { id: questionId } });
2618
- };
2619
-
2620
- // packages/feature-gamification/src/index.ts
2621
- var Gamification = class extends AbstractFeature {
2622
- // user statistics (leaderboard panel)
2623
- userSummary;
2624
- // questions list (pick history)
2625
- questions;
2626
- // pinned leaderboard id
2627
- leaderboardId;
2628
- // sl event id
2629
- slStreamId;
2630
- // current user id
2631
- userId;
2632
- organizationId;
2633
- // opened question, using to download statistics
2634
- openedQuestionId;
2635
- // opened question statistics
2636
- openedQuestion;
2637
- // last active question in feed
2638
- activeQuestionId;
2639
- // moderation id
2640
- moderationId;
2641
- // feed id (deprecated?)
2642
- feedId;
2643
- // pinned leaderboard id
2644
- onbordingComplete;
2645
- notifications;
2646
- transport;
2647
- constructor(config2, source, instance) {
2648
- super(config2, source);
2649
- this.leaderboardId = new SingleStore(
2650
- createSingleStore(this.settings.getValue("pinnedLeaderboardId")),
2651
- "pinnedLeaderboardId"
2652
- ).getStore();
2653
- this.slStreamId = instance.stores.slStreamId.getAtomStore();
2654
- this.userId = instance.stores.user.getAtomStore();
2655
- this.organizationId = instance.stores.organizationSettings.getAtomStore();
2656
- this.moderationId = new SingleStore(createSingleStore(), "moderationId").getStore();
2657
- this.feedId = new SingleStore(createSingleStore(), "feedId").getStore();
2658
- this.onbordingComplete = new SingleStore(createSingleStore(false), "onbordingComplete").getStore();
2659
- this.openedQuestionId = new SingleStore(createSingleStore(), "openedQuestionId").getStore();
2660
- this.notifications = instance.notifications;
2661
- this.transport = instance.transport;
2662
- if (!this.userId.get()) {
2663
- this.userId.subscribe((userId) => {
2664
- if (userId) {
2665
- this.connect(instance.transport);
2666
- const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
2667
- this.onbordingComplete.set(!!cached);
2668
- }
2669
- });
2670
- } else {
2671
- this.connect(instance.transport);
2672
- const userId = this.userId.get();
2673
- const cached = localStorage.getItem(`sl-onbording:${userId}:${this.slStreamId.get()}`);
2674
- this.onbordingComplete.set(!!cached);
2675
- }
2676
- }
2677
- getCurrentSessionIdPrefix = (opts) => {
2678
- const eventId = opts.eventId || this.slStreamId.get();
2679
- const userId = opts.userId || this.userId.get();
2680
- const organizationId = opts.organizationId || this.organizationId.get();
2681
- return `${organizationId}:${userId}:${eventId}:${opts.prefix || ""}`;
2682
- };
2683
- connect = (transport2) => {
2684
- this.userSummary = new ApiStore(
2685
- $userSummary(this.slStreamId, this.userId, transport2),
2686
- "gamification:userSummary"
2687
- );
2688
- this.questions = new ApiStore(
2689
- $pickHistory(this.slStreamId, transport2),
2690
- "gamification:questions"
2691
- );
2692
- this.activeQuestionId = new ApiStore(
2693
- $activeQuestion(this.slStreamId, transport2),
2694
- "gamification:activeQuestionId"
2695
- );
2696
- this.openedQuestion = new ApiStore(
2697
- $questionByUser(this.openedQuestionId, transport2),
2698
- "gamification:activeQuestionId"
2699
- );
2700
- let questionSubscription2 = void 0;
2701
- this.openedQuestionId.listen((questionId) => {
2702
- if (questionId) {
2703
- questionSubscription2 = questionSubscription(questionId, transport2);
2704
- questionSubscription2.addListener(
2705
- "feed-subscription-opened-question",
2706
- (response) => {
2707
- window.requestAnimationFrame(() => {
2708
- this.openedQuestion?.getStore().mutate(response.data?.attributes?.question);
2709
- this.openedQuestion?.getStore().invalidate();
2710
- this.userSummary?.getStore().invalidate();
2711
- });
2712
- }
2713
- );
2714
- questionSubscription2.connect();
2715
- } else {
2716
- console.log("cleanup on close question");
2717
- this.openedQuestion?.getStore().mutate(void 0);
2718
- if (questionSubscription2 !== void 0) {
2719
- transport2.removeSubscription(questionSubscription2);
2720
- }
2721
- }
2722
- });
2723
- this.activeQuestionId?.listen((question) => {
2724
- if (question?.data?.notification?.title) {
2725
- if (question.data.question.status === QuestionStatus.ACTIVE) {
2726
- this.notifications.add({
2727
- id: this.getCurrentSessionIdPrefix({ prefix: `notification-id:${question.data.question.id}` }),
2728
- data: question.data
2729
- });
2730
- }
2731
- }
2732
- });
2733
- const feedSubscription2 = feedSubscription(this.slStreamId, transport2);
2734
- feedSubscription2.addListener("feed-subscription-active-question", (response) => {
2735
- window.requestAnimationFrame(() => {
2736
- const $activeQuestionId = this.activeQuestionId?.getStore();
2737
- if ($activeQuestionId) {
2738
- $activeQuestionId.mutate(response.data?.attributes);
2739
- }
2740
- });
2741
- });
2742
- feedSubscription2.addListener("feed-subscription-questions-list", () => {
2743
- window.requestAnimationFrame(() => {
2744
- this.questions?.invalidate();
2745
- });
2746
- });
2747
- };
2748
- // onboarding
2749
- submitInplay = async () => {
2750
- const eventId = this.slStreamId.get();
2751
- if (eventId) {
2752
- await submitInplay(this.transport, eventId);
2753
- this.onbordingComplete.set(true);
2754
- localStorage.setItem(`sl-onbording:${this.userId.get()}:${eventId}`, "true");
2755
- }
2756
- };
2757
- submitAnswer = async (questionId, answerId) => {
2758
- await submitAnswer(this.transport, { questionId, answerId });
2759
- this.questions?.invalidate();
2760
- };
2761
- skipQuestion = async (questionId) => {
2762
- await skipQuestion(this.transport, questionId);
2763
- this.questions?.invalidate();
2764
- };
2765
- openQuestion = (questionId) => {
2766
- this.openedQuestionId.set(questionId);
2767
- this.notifications.markAsViewed(this.getCurrentSessionIdPrefix({ prefix: `notification-id:${questionId}` }));
2768
- };
2769
- closeQuestion = () => {
2770
- this.notifications.markAsViewed(
2771
- this.getCurrentSessionIdPrefix({ prefix: `notification-id:${this.openedQuestionId.get()}` })
2772
- );
2773
- window.requestAnimationFrame(() => {
2774
- this.openedQuestionId.set(void 0);
2775
- });
2776
- };
2777
- };
2778
-
2779
- // packages/sdk-web-features/src/index.ts
2780
- var Feature = class extends AbstractFeature {
2781
- };
2782
- var initFeature = (overlay, source, instance) => {
2783
- if (overlay.type === SdkOverlayType.GAMES) {
2784
- return new Gamification(overlay, source, instance);
2785
- }
2786
- return new Feature(overlay, source);
2787
- };
2788
- var features = (instance, opts, done) => {
2789
- instance.features = /* @__PURE__ */ new Map();
2790
- instance.sdk.getFeatures = () => instance.features;
2791
- instance.initFeature = (overlay, source = "ORGANIZATION" /* ORGANIZATION */) => {
2792
- const feature = initFeature(overlay, source, instance);
2793
- instance.features.set(overlay.name, feature);
2794
- };
2795
- instance.updateFeature = (overlay, source) => {
2796
- instance.features.get(overlay.name)?.update(overlay, source);
2797
- };
2798
- instance.destroyFeature = (overlay) => {
2799
- instance.features.delete(overlay.name);
2800
- };
2801
- instance.reinitializeFeatures = async () => {
2802
- const organizationSettings = await instance.stores.organizationSettings.getValue();
2803
- instance.features.clear();
2804
- for (const overlay of organizationSettings?.overlays || []) {
2805
- instance.initFeature(overlay, "ORGANIZATION" /* ORGANIZATION */);
2806
- }
2807
- };
2808
- instance.stores.providerStreamId.listen((eventId) => {
2809
- if (!eventId) {
2810
- void instance.reinitializeFeatures();
2811
- }
2812
- });
2813
- done();
2814
- };
2815
-
2816
- // packages/sdk-web/src/index.ts
2817
- import avvio from "avvio";
2818
-
2819
- // packages/sdk-web-core/src/store/index.ts
2820
- var store = (instance, opts, done) => {
2821
- instance.store = new CoreStore(instance.transport);
2822
- instance.stores = instance.store.getValues();
2823
- instance.sdk.sdkStore = instance.store.getStore();
2824
- instance.storeSubscribe = () => {
2825
- const processSettings = (source, settings) => {
2826
- if (!settings?.overlays)
2827
- return;
2828
- if (source === "STREAM" /* STREAM */) {
2829
- instance.features.clear();
2830
- }
2831
- for (const overlay of settings.overlays) {
2832
- const featureName = overlay.name;
2833
- if (!instance.features.has(featureName)) {
2834
- instance.initFeature(overlay, source);
2835
- } else {
2836
- instance.updateFeature(overlay, source);
2837
- }
2838
- }
2839
- };
2840
- const subscribes = {
2841
- /**
2842
- * During the initial SDK initialization, it's imperative to initialize features first,
2843
- * followed by their direct subscriptions to store fields.
2844
- * This section is currently in development, and it's
2845
- * essential to implement checks to determine whether a feature
2846
- * has already been initialized. If it has, events related to
2847
- * that feature should be skipped. Conversely, if a feature is
2848
- * missing in the new settings, it should be deinitialized.
2849
- */
2850
- organizationSettings: (orgSettings) => {
2851
- if (orgSettings.data) {
2852
- try {
2853
- processSettings("ORGANIZATION" /* ORGANIZATION */, orgSettings.data);
2854
- } catch (err) {
2855
- console.log(err);
2856
- }
2857
- }
2858
- },
2859
- streamSettings: (streamSettings) => {
2860
- if (streamSettings.data) {
2861
- try {
2862
- processSettings("STREAM" /* STREAM */, streamSettings.data);
2863
- } catch (err) {
2864
- console.log(err);
2865
- }
2866
- }
2867
- }
2868
- };
2869
- instance.store.subscribe(subscribes);
2870
- };
2871
- instance.storeUnsubscribe = () => {
2872
- instance.store.unsubscribe();
2873
- };
2874
- done();
2875
- };
2876
-
2877
- // packages/sdk-web-core/src/auth/bypass/index.ts
2878
- var BypassAuth = class extends AbstractAuthenticationProvider {
2879
- $coreStore;
2880
- transport;
2881
- $bypassLogin;
2882
- constructor(store2, transport2) {
2883
- super();
2884
- this.$coreStore = store2;
2885
- this.transport = transport2;
2886
- this.$bypassLogin = queries_exports.$bypassLogin(this.transport);
2887
- this.subscribe();
2888
- }
2889
- me = async () => {
2890
- const res = await this.$coreStore.getValues().user.getValue();
2891
- return res?.data;
2892
- };
2893
- login = async (schema, userKey) => {
2894
- this.$coreStore.getValues().userKey.setValue(userKey);
2895
- await this.$bypassLogin.mutate({ schema, userKey, init: false });
2896
- return this.me();
2897
- };
2898
- isAuthenticated = () => {
2899
- return this.me();
2900
- };
2901
- logout = () => {
2902
- this.$coreStore.getValues().user.setValue();
2903
- this.$coreStore.getValues().userKey.setValue();
2904
- this.$coreStore.getValues().userToken.setValue();
2905
- this.transport.setAuth("");
2906
- };
2907
- /**
2908
- * subscribe to user store and set auth header to the Transport on user update
2909
- */
2910
- subscribe = () => {
2911
- this.$bypassLogin.subscribe((user, key) => {
2912
- if (key === "data") {
2913
- this.transport.setAuth(user?.data?.meta?.jwt);
2914
- this.$coreStore.getValues().userToken.setValue(user?.data?.meta?.jwt);
2915
- }
2916
- });
2917
- };
2918
- };
2919
-
2920
- // packages/sdk-web-core/src/auth/index.ts
2921
- var bypass = async (instance, opts, done) => {
2922
- instance.auth = new BypassAuth(instance.store, instance.transport);
2923
- const prevUserSchema = localStorage.getItem("sl-user-schema");
2924
- const prevUserToken = localStorage.getItem("sl-user-token");
2925
- if (prevUserSchema && prevUserToken) {
2926
- console.log("try to login prev user");
2927
- await instance.auth.login(prevUserSchema, prevUserToken);
2928
- }
2929
- instance.sdk.authorizationBypass = async (schema, userKey) => {
2930
- await instance.auth.login(schema, userKey);
2931
- localStorage.setItem("sl-user-schema", "streamlayer:streamlayer");
2932
- };
2933
- instance.sdk.logout = () => {
2934
- instance.auth.logout();
2935
- };
2936
- instance.sdk.getUserStore = () => {
2937
- return instance.stores.user.getStore();
2938
- };
2939
- instance.sdk.isUserAuthorized = () => {
2940
- return instance.auth.isAuthenticated();
2941
- };
2942
- done();
2943
- };
2944
-
2945
- // packages/sdk-web-core/src/notifications/notifications.ts
2946
- var Notifications2 = class {
2947
- queue;
2948
- constructor() {
2949
- this.queue = new SingleStore(createSingleStore([]), "notifications");
2950
- }
2951
- add = (notification) => {
2952
- if (this.isNewNotify(notification.id)) {
2953
- this.queue.getStore().set([...this.queue.getValue() || [], notification]);
2954
- } else {
2955
- console.log("skip notification:", notification);
2956
- }
2957
- };
2958
- getQueueStore = () => {
2959
- return this.queue.getStore();
2960
- };
2961
- isNewNotify = (id) => {
2962
- const exist = localStorage.getItem(`opened:${id}`);
2963
- return !exist;
2964
- };
2965
- markAsViewed = (id) => {
2966
- localStorage.setItem(`opened:${id}`, id);
2967
- };
2968
- };
2969
-
2970
- // packages/sdk-web-core/src/notifications/index.ts
2971
- var notifications = (instance, opts, done) => {
2972
- instance.notifications = new Notifications2();
2973
- instance.addNotification = instance.notifications.add;
2974
- instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
2975
- done();
2976
- };
2977
-
2978
- // packages/sdk-web/src/index.ts
2979
- function StreamLayer(sdkKey) {
2980
- const streamLayer = avvio(/* @__PURE__ */ Object.create(null), { autostart: false });
2981
- streamLayer.use(core);
2982
- streamLayer.use(transport, { sdkKey });
2983
- streamLayer.use(store);
2984
- streamLayer.use(bypass);
2985
- streamLayer.use(features);
2986
- streamLayer.use(notifications);
2987
- streamLayer.after(async (err, context, done) => {
2988
- if (err) {
2989
- throw err;
2990
- }
2991
- await context.sdk.initializeApp();
2992
- done();
2993
- });
2994
- streamLayer.onClose(() => {
2995
- console.log("close");
2996
- });
2997
- return streamLayer;
2998
- }
2999
-
3000
- // packages/react/src/app/useStreamLayer.ts
3001
- import { useState as useState5, useEffect as useEffect4 } from "react";
3002
- window.instance = null;
3003
- var useStreamLayer = (sdkKey, plugins) => {
3004
- const [sdk, setSdk] = useState5(null);
3005
- useEffect4(() => {
3006
- let ignore = false;
3007
- if (!sdkKey) {
3008
- throw new Error("sdk key should be provided");
3009
- }
3010
- const instance = StreamLayer(sdkKey);
3011
- if (plugins) {
3012
- for (const plugin of plugins) {
3013
- instance.use(plugin);
3014
- }
3015
- }
3016
- instance.ready().then((service) => {
3017
- if (!ignore) {
3018
- window.instance = service;
3019
- setSdk(service.sdk);
3020
- }
3021
- }).catch((err) => console.log(err));
3022
- return () => {
3023
- ignore = true;
3024
- instance.close(function(err) {
3025
- if (err)
3026
- throw err;
3027
- });
3028
- };
3029
- }, [sdkKey]);
3030
- return sdk;
3031
- };
3032
-
3033
- // packages/react/src/app/provider.tsx
3034
- import { jsx as jsx23 } from "@emotion/react/jsx-runtime";
3035
- var StreamLayerContext3 = createContext({
3036
- status: 0 /* UNSET */
3037
- });
3038
- if (process.env.NODE_ENV !== "production") {
3039
- StreamLayerContext3.displayName = "StreamLayerProvider";
3040
- }
3041
- var StreamLayerProvider = ({
3042
- sdkKey,
3043
- plugins,
3044
- children
3045
- }) => {
3046
- const streamLayer = useStreamLayer(sdkKey, plugins);
3047
- const value = useMemo2(() => {
3048
- if (!streamLayer) {
3049
- return { status: 1 /* CONNECTED */ };
3050
- }
3051
- return { sdk: streamLayer, status: 2 /* READY */ };
3052
- }, [streamLayer]);
3053
- return /* @__PURE__ */ jsx23(StreamLayerThemeProvider, { children: /* @__PURE__ */ jsx23(StreamLayerContext3.Provider, { value, children }) });
3054
- };
3055
-
3056
- // packages/react/src/app/app.tsx
3057
- import { useContext } from "react";
3058
- import { jsx as jsx24 } from "@emotion/react/jsx-runtime";
3059
- var useSDK = () => {
3060
- const { sdk } = useContext(StreamLayerContext3);
3061
- return sdk;
3062
- };
3063
- var StreamLayerSDKReact = () => {
3064
- const { sdk, status } = useContext(StreamLayerContext3);
3065
- if (status === 0 /* UNSET */) {
3066
- throw new Error("Wrap app in `StreamLayerProvider`");
3067
- }
3068
- if (status === 1 /* CONNECTED */) {
3069
- return /* @__PURE__ */ jsx24("div", { children: "wait" });
3070
- }
3071
- if (sdk === void 0) {
3072
- return /* @__PURE__ */ jsx24("div", { children: "sdk not initialized" });
3073
- }
3074
- return /* @__PURE__ */ jsx24(Demo, { sdk });
3075
- };
3076
- export {
3077
- StreamLayerProvider,
3078
- StreamLayerSDKReact,
3079
- useSDK,
3080
- useStreamLayer
3081
- };