@cuemath/leap 3.0.11-akm-2 → 3.0.11-akm-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/circle-games/games/web-view/web-view.js +94 -61
- package/dist/features/circle-games/games/web-view/web-view.js.map +1 -1
- package/dist/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.js +74 -74
- package/dist/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.js.map +1 -1
- package/dist/features/post-game-stats/accuracy/accuracy.js +39 -40
- package/dist/features/post-game-stats/accuracy/accuracy.js.map +1 -1
- package/dist/features/post-game-stats/clock/clock.js +45 -45
- package/dist/features/post-game-stats/clock/clock.js.map +1 -1
- package/package.json +1 -1
@@ -1,100 +1,133 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { forwardRef as
|
3
|
-
import { useUIContext as
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import { ALLOWED_ORIGIN as
|
7
|
-
import { ProjectType as
|
1
|
+
import { jsxs as V, jsx as y } from "react/jsx-runtime";
|
2
|
+
import { forwardRef as $, useRef as P, useMemo as R, useCallback as A, useImperativeHandle as G, useEffect as x } from "react";
|
3
|
+
import { useUIContext as B } from "../../../ui/context/context.js";
|
4
|
+
import J from "../../../ui/layout/flex-view.js";
|
5
|
+
import I from "../../../ui/separator/separator.js";
|
6
|
+
import { ALLOWED_ORIGIN as _ } from "./constants.js";
|
7
|
+
import { ProjectType as a } from "./enums/project-type-enum.js";
|
8
8
|
import { WebViewEvent as o } from "./enums/web-view-events-enum.js";
|
9
|
-
const X =
|
9
|
+
const X = $((h, C) => {
|
10
10
|
const {
|
11
|
-
baseUrl:
|
12
|
-
projectDetails:
|
11
|
+
baseUrl: b,
|
12
|
+
projectDetails: T,
|
13
13
|
playerDetails: E,
|
14
|
-
onGameLoad:
|
14
|
+
onGameLoad: n,
|
15
15
|
onGamePlayFinish: c,
|
16
16
|
handleInfoMessage: p,
|
17
17
|
onBack: f,
|
18
|
-
parentDomain:
|
19
|
-
...
|
20
|
-
} =
|
21
|
-
let
|
22
|
-
const { onEvent:
|
23
|
-
t.projectType ===
|
24
|
-
const l =
|
25
|
-
const { enableCloseButton:
|
18
|
+
parentDomain: g,
|
19
|
+
...W
|
20
|
+
} = h, m = P(null), N = R(() => E, [E]), t = R(() => T, [T]);
|
21
|
+
let u = "";
|
22
|
+
const { onEvent: j } = B();
|
23
|
+
t.projectType === a.LESSON && (u = t.miniGameIdentifier);
|
24
|
+
const l = A(() => {
|
25
|
+
const { enableCloseButton: i = !0 } = t;
|
26
26
|
let e = {
|
27
|
-
enableCloseButton:
|
27
|
+
enableCloseButton: i
|
28
28
|
};
|
29
|
-
return t.projectType ===
|
29
|
+
return t.projectType === a.GAME && (e = {
|
30
30
|
...e,
|
31
31
|
...t
|
32
|
-
}), t.projectType ===
|
32
|
+
}), t.projectType === a.PUZZLE && (e = {
|
33
33
|
...e,
|
34
34
|
...t
|
35
|
-
}), t.projectType ===
|
35
|
+
}), t.projectType === a.LESSON && (e = {
|
36
36
|
...e,
|
37
37
|
...t
|
38
|
-
}), t.projectType ===
|
38
|
+
}), t.projectType === a.TABLE && (e = {
|
39
39
|
...e,
|
40
40
|
...t
|
41
41
|
}), e;
|
42
|
-
}, [t]),
|
43
|
-
var e,
|
44
|
-
const
|
45
|
-
(
|
42
|
+
}, [t]), w = A(() => {
|
43
|
+
var e, r;
|
44
|
+
const i = l();
|
45
|
+
(r = (e = m.current) == null ? void 0 : e.contentWindow) == null || r.postMessage(
|
46
46
|
JSON.stringify({
|
47
47
|
event: o.GAME_DATA,
|
48
|
-
payload:
|
48
|
+
payload: i
|
49
49
|
}),
|
50
|
-
|
50
|
+
_
|
51
51
|
);
|
52
|
-
}, [l]),
|
53
|
-
var e,
|
54
|
-
const
|
55
|
-
(
|
52
|
+
}, [l]), O = A(() => {
|
53
|
+
var e, r;
|
54
|
+
const i = l();
|
55
|
+
(r = (e = m.current) == null ? void 0 : e.contentWindow) == null || r.postMessage(
|
56
56
|
JSON.stringify({
|
57
57
|
event: o.SET_CONFIG,
|
58
58
|
payload: {
|
59
|
-
user:
|
60
|
-
projectConfig:
|
61
|
-
parentDomain:
|
59
|
+
user: N,
|
60
|
+
projectConfig: i,
|
61
|
+
parentDomain: g
|
62
62
|
}
|
63
63
|
}),
|
64
|
-
|
64
|
+
_
|
65
65
|
);
|
66
|
-
}, [
|
67
|
-
|
68
|
-
const
|
69
|
-
var
|
70
|
-
const
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
66
|
+
}, [N, l, g]);
|
67
|
+
G(C, () => m.current, []), x(() => {
|
68
|
+
const i = (e) => {
|
69
|
+
var S, D;
|
70
|
+
const r = e.data;
|
71
|
+
let s;
|
72
|
+
if (typeof r == "string" && (r.trim().startsWith("{") || r.trim().startsWith("[")))
|
73
|
+
try {
|
74
|
+
s = JSON.parse(r);
|
75
|
+
} catch {
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
else typeof r == "object" && "event" in r && (s = r);
|
79
|
+
if (!s || typeof s != "object" || !("event" in s))
|
80
|
+
return;
|
81
|
+
const { event: L, payload: d = null } = s;
|
82
|
+
switch (L) {
|
83
|
+
case o.VIBRATE: {
|
84
|
+
const { pattern: v } = d;
|
85
|
+
window.ReactNativeWebView ? window.ReactNativeWebView.postMessage(JSON.stringify(s)) : (D = (S = window.navigator).vibrate) == null || D.call(S, v);
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
case o.GAME_BACK:
|
89
|
+
f == null || f();
|
90
|
+
break;
|
91
|
+
case o.HIDE_LOADER:
|
92
|
+
n == null || n();
|
93
|
+
break;
|
94
|
+
case o.LOAD_DATA_FROM_APP:
|
95
|
+
w == null || w();
|
96
|
+
break;
|
97
|
+
case o.GET_CONFIG:
|
98
|
+
O();
|
99
|
+
break;
|
100
|
+
case o.UPDATE_STATS:
|
101
|
+
c == null || c(d);
|
102
|
+
break;
|
103
|
+
case o.SHOW_SNACKBAR:
|
104
|
+
p == null || p(d);
|
105
|
+
break;
|
106
|
+
case o.TRACK_EVENT: {
|
107
|
+
const { eventName: v, properties: M } = d;
|
108
|
+
j(v, M);
|
109
|
+
break;
|
110
|
+
}
|
78
111
|
}
|
79
112
|
};
|
80
|
-
return window.addEventListener("message",
|
81
|
-
window.removeEventListener("message",
|
113
|
+
return window.addEventListener("message", i), () => {
|
114
|
+
window.removeEventListener("message", i);
|
82
115
|
};
|
83
116
|
}, [
|
84
117
|
p,
|
85
118
|
f,
|
86
119
|
c,
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
120
|
+
n,
|
121
|
+
O,
|
122
|
+
w,
|
123
|
+
j
|
91
124
|
]);
|
92
|
-
const
|
93
|
-
return /* @__PURE__ */
|
94
|
-
/* @__PURE__ */
|
95
|
-
/* @__PURE__ */
|
125
|
+
const k = E.isAdmin ? b : `${b}/play-game/${t.projectId}/${t.variant}${u ? `/${u}` : ""}`;
|
126
|
+
return /* @__PURE__ */ V(J, { $height: "100%", $width: "100%", children: [
|
127
|
+
/* @__PURE__ */ y(I, { height: window.ReactNativeTopInset || 0 }),
|
128
|
+
/* @__PURE__ */ y("iframe", { ...W, ref: m, src: `${k}?version=2`, allow: "autoplay" }),
|
96
129
|
";",
|
97
|
-
/* @__PURE__ */
|
130
|
+
/* @__PURE__ */ y(I, { height: window.ReactNativeBottomInset || 0 })
|
98
131
|
] });
|
99
132
|
});
|
100
133
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"web-view.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view.tsx"],"sourcesContent":["import type {\n IInfoMessage,\n ILessonWebGameProps,\n IMessageProps,\n IMultiplayerWebGameProps,\n IPlayerStats,\n IPuzzleWebGameProps,\n ITableWebGameProps,\n IVibrationPattern,\n IWebViewProps,\n} from './web-view-types';\nimport type { ForwardedRef } from 'react';\n\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\n\nimport { useUIContext } from '../../../ui/context/context';\nimport FlexView from '../../../ui/layout/flex-view';\nimport Separator from '../../../ui/separator/separator';\nimport { ALLOWED_ORIGIN } from './constants';\nimport { ProjectType, WebViewEvent } from './enums';\n\nexport const WebView = forwardRef((props: IWebViewProps, ref: ForwardedRef<HTMLIFrameElement>) => {\n const {\n baseUrl,\n projectDetails,\n playerDetails,\n onGameLoad,\n onGamePlayFinish,\n handleInfoMessage,\n onBack,\n parentDomain,\n ...rest\n } = props;\n const webViewRef = useRef<HTMLIFrameElement>(null);\n const memoizedPlayerDetails = useMemo(() => playerDetails, [playerDetails]);\n const memoizedProjectDetails = useMemo(() => projectDetails, [projectDetails]);\n\n let miniGameIdentifier = '';\n const { onEvent: trackEvent } = useUIContext();\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n miniGameIdentifier = (memoizedProjectDetails as ILessonWebGameProps).miniGameIdentifier;\n }\n\n const getProjectDetails = useCallback(() => {\n const { enableCloseButton = true } = memoizedProjectDetails;\n\n let payload = {\n enableCloseButton,\n } as IMultiplayerWebGameProps | IPuzzleWebGameProps | ILessonWebGameProps;\n\n if (memoizedProjectDetails.projectType === ProjectType.GAME) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IMultiplayerWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.PUZZLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IPuzzleWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ILessonWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.TABLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ITableWebGameProps;\n }\n\n return payload;\n }, [memoizedProjectDetails]);\n\n const sendGamesData = useCallback(() => {\n const payload = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.GAME_DATA,\n payload,\n }),\n ALLOWED_ORIGIN,\n );\n }, [getProjectDetails]);\n\n const setConfig = useCallback(() => {\n const projectConfig = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.SET_CONFIG,\n payload: {\n user: memoizedPlayerDetails,\n projectConfig,\n parentDomain,\n },\n }),\n ALLOWED_ORIGIN,\n );\n }, [memoizedPlayerDetails, getProjectDetails, parentDomain]);\n\n useImperativeHandle(ref, () => webViewRef.current as HTMLIFrameElement, []);\n\n useEffect(() => {\n const handleMessage = (e: MessageEvent) => {\n const data: string = e.data;\n const parsedData = typeof data === 'string' ? JSON.parse(data) : (data as IMessageProps);\n\n const { event, payload = null } = parsedData;\n\n if (event === WebViewEvent.VIBRATE) {\n const { pattern } = payload as IVibrationPattern;\n\n if (window.ReactNativeWebView) {\n window.ReactNativeWebView.postMessage(JSON.stringify(parsedData));\n } else {\n window.navigator.vibrate?.(pattern);\n }\n }\n\n if (event === WebViewEvent.GAME_BACK) {\n onBack?.();\n }\n\n if (event === WebViewEvent.HIDE_LOADER) {\n onGameLoad?.();\n }\n\n if (event === WebViewEvent.LOAD_DATA_FROM_APP) {\n sendGamesData?.();\n }\n\n if (event === WebViewEvent.GET_CONFIG) {\n setConfig();\n }\n\n if (event === WebViewEvent.UPDATE_STATS) {\n onGamePlayFinish?.(payload as IPlayerStats);\n }\n\n if (event === WebViewEvent.SHOW_SNACKBAR) {\n handleInfoMessage?.(payload as IInfoMessage);\n }\n\n if (event === WebViewEvent.TRACK_EVENT) {\n const { eventName, properties } = payload;\n\n trackEvent(eventName, properties);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => {\n window.removeEventListener('message', handleMessage);\n };\n }, [\n handleInfoMessage,\n onBack,\n onGamePlayFinish,\n onGameLoad,\n setConfig,\n sendGamesData,\n trackEvent,\n ]);\n\n const url = playerDetails.isAdmin\n ? baseUrl\n : `${baseUrl}/play-game/${memoizedProjectDetails.projectId}/${memoizedProjectDetails.variant}${\n miniGameIdentifier ? `/${miniGameIdentifier}` : ''\n }`;\n\n return (\n <FlexView $height=\"100%\" $width=\"100%\">\n <Separator height={window.ReactNativeTopInset || 0} />\n <iframe {...rest} ref={webViewRef} src={`${url}?version=2`} allow=\"autoplay\" />;\n <Separator height={window.ReactNativeBottomInset || 0} />\n </FlexView>\n );\n});\n"],"names":["WebView","forwardRef","props","ref","baseUrl","projectDetails","playerDetails","onGameLoad","onGamePlayFinish","handleInfoMessage","onBack","parentDomain","rest","webViewRef","useRef","memoizedPlayerDetails","useMemo","memoizedProjectDetails","miniGameIdentifier","trackEvent","useUIContext","ProjectType","getProjectDetails","useCallback","enableCloseButton","payload","sendGamesData","_b","_a","WebViewEvent","ALLOWED_ORIGIN","setConfig","projectConfig","useImperativeHandle","useEffect","handleMessage","data","parsedData","event","pattern","eventName","properties","url","jsxs","FlexView","jsx","Separator"],"mappings":";;;;;;;;AAqBO,MAAMA,IAAUC,EAAW,CAACC,GAAsBC,MAAyC;AAC1F,QAAA;AAAA,IACJ,SAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,YAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,cAAAC;AAAA,IACA,GAAGC;AAAA,EACD,IAAAV,GACEW,IAAaC,EAA0B,IAAI,GAC3CC,IAAwBC,EAAQ,MAAMV,GAAe,CAACA,CAAa,CAAC,GACpEW,IAAyBD,EAAQ,MAAMX,GAAgB,CAACA,CAAc,CAAC;AAE7E,MAAIa,IAAqB;AACzB,QAAM,EAAE,SAASC,EAAW,IAAIC,EAAa;AAEzC,EAAAH,EAAuB,gBAAgBI,EAAY,WACrDH,IAAsBD,EAA+C;AAGjE,QAAAK,IAAoBC,EAAY,MAAM;AACpC,UAAA,EAAE,mBAAAC,IAAoB,GAAS,IAAAP;AAErC,QAAIQ,IAAU;AAAA,MACZ,mBAAAD;AAAA,IAAA;AAGE,WAAAP,EAAuB,gBAAgBI,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CAAG,cAAc,OAAM,WAAW,CAAA;AAAA,IAAE;AAAA,IAC9E,gBAAAG,EAAAC,GAAA,EAAU,QAAQ,OAAO,0BAA0B,GAAG;AAAA,EACzD,EAAA,CAAA;AAEJ,CAAC;"}
|
1
|
+
{"version":3,"file":"web-view.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view.tsx"],"sourcesContent":["import type {\n IInfoMessage,\n ILessonWebGameProps,\n IMessageProps,\n IMultiplayerWebGameProps,\n IPlayerStats,\n IPuzzleWebGameProps,\n ITableWebGameProps,\n IVibrationPattern,\n IWebViewProps,\n} from './web-view-types';\nimport type { ForwardedRef } from 'react';\n\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\n\nimport { useUIContext } from '../../../ui/context/context';\nimport FlexView from '../../../ui/layout/flex-view';\nimport Separator from '../../../ui/separator/separator';\nimport { ALLOWED_ORIGIN } from './constants';\nimport { ProjectType, WebViewEvent } from './enums';\n\nexport const WebView = forwardRef((props: IWebViewProps, ref: ForwardedRef<HTMLIFrameElement>) => {\n const {\n baseUrl,\n projectDetails,\n playerDetails,\n onGameLoad,\n onGamePlayFinish,\n handleInfoMessage,\n onBack,\n parentDomain,\n ...rest\n } = props;\n const webViewRef = useRef<HTMLIFrameElement>(null);\n const memoizedPlayerDetails = useMemo(() => playerDetails, [playerDetails]);\n const memoizedProjectDetails = useMemo(() => projectDetails, [projectDetails]);\n\n let miniGameIdentifier = '';\n const { onEvent: trackEvent } = useUIContext();\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n miniGameIdentifier = (memoizedProjectDetails as ILessonWebGameProps).miniGameIdentifier;\n }\n\n const getProjectDetails = useCallback(() => {\n const { enableCloseButton = true } = memoizedProjectDetails;\n\n let payload = {\n enableCloseButton,\n } as IMultiplayerWebGameProps | IPuzzleWebGameProps | ILessonWebGameProps;\n\n if (memoizedProjectDetails.projectType === ProjectType.GAME) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IMultiplayerWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.PUZZLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IPuzzleWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ILessonWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.TABLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ITableWebGameProps;\n }\n\n return payload;\n }, [memoizedProjectDetails]);\n\n const sendGamesData = useCallback(() => {\n const payload = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.GAME_DATA,\n payload,\n }),\n ALLOWED_ORIGIN,\n );\n }, [getProjectDetails]);\n\n const setConfig = useCallback(() => {\n const projectConfig = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.SET_CONFIG,\n payload: {\n user: memoizedPlayerDetails,\n projectConfig,\n parentDomain,\n },\n }),\n ALLOWED_ORIGIN,\n );\n }, [memoizedPlayerDetails, getProjectDetails, parentDomain]);\n\n useImperativeHandle(ref, () => webViewRef.current as HTMLIFrameElement, []);\n\n useEffect(() => {\n const handleMessage = (e: MessageEvent) => {\n const data = e.data;\n let parsedData;\n\n if (\n typeof data === 'string' &&\n (data.trim().startsWith('{') || data.trim().startsWith('['))\n ) {\n try {\n // Still need to guard against parse errors here\n parsedData = JSON.parse(data);\n } catch {\n // Do nothing — malformed JSON, ignore\n return;\n }\n } else if (typeof data === 'object' && 'event' in data) {\n parsedData = data as IMessageProps;\n }\n\n if (!parsedData || typeof parsedData !== 'object' || !('event' in parsedData)) {\n return; // Not a valid message we care about\n }\n\n const { event, payload = null } = parsedData;\n\n switch (event) {\n case WebViewEvent.VIBRATE: {\n const { pattern } = payload as IVibrationPattern;\n\n if (window.ReactNativeWebView) {\n window.ReactNativeWebView.postMessage(JSON.stringify(parsedData));\n } else {\n window.navigator.vibrate?.(pattern);\n }\n break;\n }\n\n case WebViewEvent.GAME_BACK:\n onBack?.();\n break;\n\n case WebViewEvent.HIDE_LOADER:\n onGameLoad?.();\n break;\n\n case WebViewEvent.LOAD_DATA_FROM_APP:\n sendGamesData?.();\n break;\n\n case WebViewEvent.GET_CONFIG:\n setConfig();\n break;\n\n case WebViewEvent.UPDATE_STATS:\n onGamePlayFinish?.(payload as IPlayerStats);\n break;\n\n case WebViewEvent.SHOW_SNACKBAR:\n handleInfoMessage?.(payload as IInfoMessage);\n break;\n\n case WebViewEvent.TRACK_EVENT: {\n const { eventName, properties } = payload;\n\n trackEvent(eventName, properties);\n break;\n }\n\n default:\n // Unknown event — no-op\n break;\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => {\n window.removeEventListener('message', handleMessage);\n };\n }, [\n handleInfoMessage,\n onBack,\n onGamePlayFinish,\n onGameLoad,\n setConfig,\n sendGamesData,\n trackEvent,\n ]);\n\n const url = playerDetails.isAdmin\n ? baseUrl\n : `${baseUrl}/play-game/${memoizedProjectDetails.projectId}/${memoizedProjectDetails.variant}${\n miniGameIdentifier ? `/${miniGameIdentifier}` : ''\n }`;\n\n return (\n <FlexView $height=\"100%\" $width=\"100%\">\n <Separator height={window.ReactNativeTopInset || 0} />\n <iframe {...rest} ref={webViewRef} src={`${url}?version=2`} allow=\"autoplay\" />;\n <Separator height={window.ReactNativeBottomInset || 0} />\n </FlexView>\n );\n});\n"],"names":["WebView","forwardRef","props","ref","baseUrl","projectDetails","playerDetails","onGameLoad","onGamePlayFinish","handleInfoMessage","onBack","parentDomain","rest","webViewRef","useRef","memoizedPlayerDetails","useMemo","memoizedProjectDetails","miniGameIdentifier","trackEvent","useUIContext","ProjectType","getProjectDetails","useCallback","enableCloseButton","payload","sendGamesData","_b","_a","WebViewEvent","ALLOWED_ORIGIN","setConfig","projectConfig","useImperativeHandle","useEffect","handleMessage","data","parsedData","event","pattern","eventName","properties","url","jsxs","FlexView","js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"}
|
@@ -1,118 +1,118 @@
|
|
1
|
-
import { useCallback as
|
1
|
+
import { useCallback as c, useRef as C, useEffect as T } from "react";
|
2
2
|
import { CircleSoundKeyMapper as A, SWIPE_SOUND_ORDER as E } from "./constants.js";
|
3
|
-
import { CircleSoundKey as
|
4
|
-
let
|
5
|
-
const
|
6
|
-
[
|
7
|
-
[
|
8
|
-
[
|
9
|
-
[
|
10
|
-
[
|
11
|
-
[
|
12
|
-
[
|
13
|
-
[
|
14
|
-
[
|
15
|
-
[
|
16
|
-
[
|
17
|
-
[
|
18
|
-
[
|
19
|
-
[
|
20
|
-
[
|
21
|
-
[
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
},
|
30
|
-
const
|
31
|
-
if (!
|
32
|
-
const l = new Audio(A[
|
33
|
-
|
3
|
+
import { CircleSoundKey as n } from "./use-circle-sounds-enums.js";
|
4
|
+
let d = 0;
|
5
|
+
const o = {
|
6
|
+
[n.BACKGROUND]: null,
|
7
|
+
[n.BACKGROUND_RUSHHOUR]: null,
|
8
|
+
[n.TUTORIAL]: null,
|
9
|
+
[n.SWIPE_01]: null,
|
10
|
+
[n.SWIPE_02]: null,
|
11
|
+
[n.SWIPE_03]: null,
|
12
|
+
[n.SWIPE_04]: null,
|
13
|
+
[n.SWIPE_DOWN]: null,
|
14
|
+
[n.TOGGLE]: null,
|
15
|
+
[n.POINTS_AWARDED]: null,
|
16
|
+
[n.POINTS_ADDED]: null,
|
17
|
+
[n.GAME_CARD_CLICK]: null,
|
18
|
+
[n.CLOCK_IN]: null,
|
19
|
+
[n.CLOCK_OUT]: null,
|
20
|
+
[n.ACCURACY_IN]: null,
|
21
|
+
[n.ACCURACY_OUT]: null,
|
22
|
+
[n.STREAK_IN]: null,
|
23
|
+
[n.STREAK_OUT]: null,
|
24
|
+
[n.ACCURACY_INTRO]: null,
|
25
|
+
[n.ACCURACY_TARGET]: null,
|
26
|
+
[n.TIME_INTRO]: null,
|
27
|
+
[n.TIME_TARGET]: null,
|
28
|
+
[n.METER_FILL]: null
|
29
|
+
}, I = {}, D = () => {
|
30
|
+
const s = c((e) => {
|
31
|
+
if (!o[e]) {
|
32
|
+
const l = new Audio(A[e]);
|
33
|
+
o[e] = l;
|
34
34
|
}
|
35
|
-
}, []),
|
36
|
-
document.visibilityState === "hidden" ? Object.keys(
|
37
|
-
const l =
|
38
|
-
l && !l.paused && (l.pause(),
|
39
|
-
}) : document.visibilityState === "visible" && (
|
40
|
-
const l =
|
35
|
+
}, []), f = C(/* @__PURE__ */ new Set()), p = C({}), v = c(() => {
|
36
|
+
document.visibilityState === "hidden" ? Object.keys(o).forEach((e) => {
|
37
|
+
const l = o[e];
|
38
|
+
l && !l.paused && (l.pause(), f.current.add(e));
|
39
|
+
}) : document.visibilityState === "visible" && (f.current.forEach((e) => {
|
40
|
+
const l = o[e];
|
41
41
|
l == null || l.play();
|
42
|
-
}),
|
42
|
+
}), f.current.clear());
|
43
43
|
}, []);
|
44
44
|
T(() => {
|
45
|
-
document.addEventListener("visibilitychange",
|
46
|
-
const
|
45
|
+
document.addEventListener("visibilitychange", v);
|
46
|
+
const e = p.current;
|
47
47
|
return () => {
|
48
|
-
document.removeEventListener("visibilitychange",
|
49
|
-
for (const l of Object.values(
|
48
|
+
document.removeEventListener("visibilitychange", v);
|
49
|
+
for (const l of Object.values(e))
|
50
50
|
l != null && clearInterval(l);
|
51
51
|
};
|
52
|
-
}, [
|
53
|
-
const S =
|
52
|
+
}, [v]);
|
53
|
+
const S = c(() => {
|
54
54
|
var l;
|
55
55
|
E.forEach((u) => {
|
56
|
-
|
56
|
+
s(u);
|
57
57
|
});
|
58
|
-
const
|
59
|
-
|
60
|
-
}, [
|
58
|
+
const e = E[d] || n.SWIPE_01;
|
59
|
+
d < E.length - 1 ? d++ : d = 0, (l = o[e]) == null || l.play();
|
60
|
+
}, [s]), m = c(() => {
|
61
61
|
var l;
|
62
|
-
return
|
63
|
-
}, [
|
64
|
-
(
|
65
|
-
|
66
|
-
const t =
|
62
|
+
return s(n.TOGGLE), (l = o[n.TOGGLE]) == null ? void 0 : l.play();
|
63
|
+
}, [s]), _ = c(
|
64
|
+
(e, l = !0, u = !1) => {
|
65
|
+
s(e);
|
66
|
+
const t = o[e];
|
67
67
|
if (!t) return;
|
68
|
-
if (
|
68
|
+
if (!t.paused && t.currentTime > 0 && !t.ended)
|
69
69
|
return t;
|
70
70
|
if (t.loop = u, l) {
|
71
71
|
t.volume = 1;
|
72
|
-
const
|
73
|
-
|
72
|
+
const a = t.play();
|
73
|
+
I[e] = a;
|
74
74
|
return;
|
75
75
|
}
|
76
76
|
t.volume = 0;
|
77
|
-
const
|
78
|
-
|
77
|
+
const r = t.play();
|
78
|
+
I[e] = r;
|
79
79
|
const i = setInterval(() => {
|
80
80
|
if (!t) {
|
81
81
|
clearInterval(i);
|
82
82
|
return;
|
83
83
|
}
|
84
|
-
const
|
85
|
-
|
84
|
+
const a = t.volume || 0;
|
85
|
+
a < 1 ? t.volume = Math.min(a + 0.1, 1) : clearInterval(i);
|
86
86
|
}, 100);
|
87
|
-
return
|
87
|
+
return p.current[e] = i, t;
|
88
88
|
},
|
89
|
-
[
|
90
|
-
), R =
|
89
|
+
[s]
|
90
|
+
), R = c((e, l = !0) => {
|
91
91
|
var t;
|
92
|
-
const u =
|
93
|
-
|
92
|
+
const u = o[e];
|
93
|
+
I[e] !== void 0 && ((t = I[e]) == null || t.then(() => {
|
94
94
|
if (!u) return;
|
95
|
-
if (
|
95
|
+
if (l) {
|
96
96
|
u.pause();
|
97
97
|
return;
|
98
98
|
}
|
99
|
-
const
|
99
|
+
const r = setInterval(() => {
|
100
100
|
if (!u) {
|
101
|
-
clearInterval(
|
101
|
+
clearInterval(r);
|
102
102
|
return;
|
103
103
|
}
|
104
104
|
const i = u.volume || 0;
|
105
|
-
i - 0.1 <= 0 ? (u.volume = 0, u.pause(), clearInterval(
|
105
|
+
i - 0.1 <= 0 ? (u.volume = 0, u.pause(), clearInterval(r)) : u.volume = i - 0.1;
|
106
106
|
}, 100);
|
107
|
-
|
108
|
-
}).catch((
|
109
|
-
console.log("sound not playing",
|
107
|
+
p.current[e] = r;
|
108
|
+
}).catch((r) => {
|
109
|
+
console.log("sound not playing", r);
|
110
110
|
}));
|
111
111
|
}, []);
|
112
112
|
return { playSwipSound: S, play: _, stop: R, playButtonSound: m };
|
113
113
|
};
|
114
114
|
export {
|
115
|
-
|
115
|
+
o as soundMapper,
|
116
116
|
D as useCircleSounds
|
117
117
|
};
|
118
118
|
//# sourceMappingURL=use-circle-sounds.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-circle-sounds.js","sources":["../../../../../src/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.ts"],"sourcesContent":["import type { TimeoutMap } from './use-circle-sound-types';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport { CircleSoundKeyMapper, SWIPE_SOUND_ORDER } from './constants';\nimport { CircleSoundKey } from './use-circle-sounds-enums';\n\nlet swipeSoundIndex = 0;\n\nexport const soundMapper: Record<keyof typeof CircleSoundKeyMapper, null | HTMLAudioElement> = {\n [CircleSoundKey.BACKGROUND]: null,\n [CircleSoundKey.BACKGROUND_RUSHHOUR]: null,\n [CircleSoundKey.TUTORIAL]: null,\n [CircleSoundKey.SWIPE_01]: null,\n [CircleSoundKey.SWIPE_02]: null,\n [CircleSoundKey.SWIPE_03]: null,\n [CircleSoundKey.SWIPE_04]: null,\n [CircleSoundKey.SWIPE_DOWN]: null,\n [CircleSoundKey.TOGGLE]: null,\n [CircleSoundKey.POINTS_AWARDED]: null,\n [CircleSoundKey.POINTS_ADDED]: null,\n [CircleSoundKey.GAME_CARD_CLICK]: null,\n [CircleSoundKey.CLOCK_IN]: null,\n [CircleSoundKey.CLOCK_OUT]: null,\n [CircleSoundKey.ACCURACY_IN]: null,\n [CircleSoundKey.ACCURACY_OUT]: null,\n [CircleSoundKey.STREAK_IN]: null,\n [CircleSoundKey.STREAK_OUT]: null,\n [CircleSoundKey.ACCURACY_INTRO]: null,\n [CircleSoundKey.ACCURACY_TARGET]: null,\n [CircleSoundKey.TIME_INTRO]: null,\n [CircleSoundKey.TIME_TARGET]: null,\n [CircleSoundKey.METER_FILL]: null,\n};\n\nconst soundInstancePromise: Partial<Record<keyof typeof CircleSoundKeyMapper, Promise<void>>> = {};\n\nexport const useCircleSounds = () => {\n const loadSound = useCallback((key: CircleSoundKey) => {\n if (!soundMapper[key]) {\n const loadedSound = new Audio(CircleSoundKeyMapper[key]);\n\n soundMapper[key] = loadedSound;\n }\n }, []);\n\n const pausedSoundsRef = useRef<Set<CircleSoundKey>>(new Set());\n const timeoutRefs = useRef<TimeoutMap>({});\n\n const handleVisibilityChange = useCallback(() => {\n if (document.visibilityState === 'hidden') {\n (Object.keys(soundMapper) as CircleSoundKey[]).forEach(key => {\n const sound = soundMapper[key];\n\n if (sound && !sound.paused) {\n sound.pause();\n pausedSoundsRef.current.add(key);\n }\n });\n } else if (document.visibilityState === 'visible') {\n pausedSoundsRef.current.forEach(key => {\n const sound = soundMapper[key];\n\n sound?.play();\n });\n pausedSoundsRef.current.clear();\n }\n }, []);\n\n useEffect(() => {\n document.addEventListener('visibilitychange', handleVisibilityChange);\n const timeouts = timeoutRefs.current;\n\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange);\n for (const id of Object.values(timeouts)) {\n if (id != null) clearInterval(id);\n }\n };\n }, [handleVisibilityChange]);\n\n const playSwipSound = useCallback(() => {\n SWIPE_SOUND_ORDER.forEach(key => {\n loadSound(key);\n });\n\n const key = SWIPE_SOUND_ORDER[swipeSoundIndex] || CircleSoundKey.SWIPE_01;\n\n if (swipeSoundIndex < SWIPE_SOUND_ORDER.length - 1) {\n swipeSoundIndex++;\n } else {\n swipeSoundIndex = 0;\n }\n soundMapper[key]?.play();\n }, [loadSound]);\n\n const playButtonSound = useCallback(() => {\n loadSound(CircleSoundKey.TOGGLE);\n const sound = soundMapper[CircleSoundKey.TOGGLE]?.play();\n\n return sound;\n }, [loadSound]);\n\n const play = useCallback(\n (key: CircleSoundKey, immediately: boolean = true, loop = false) => {\n loadSound(key);\n const soundInstance = soundMapper[key];\n\n if (!soundInstance) return;\n\n if (
|
1
|
+
{"version":3,"file":"use-circle-sounds.js","sources":["../../../../../src/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.ts"],"sourcesContent":["import type { TimeoutMap } from './use-circle-sound-types';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport { CircleSoundKeyMapper, SWIPE_SOUND_ORDER } from './constants';\nimport { CircleSoundKey } from './use-circle-sounds-enums';\n\nlet swipeSoundIndex = 0;\n\nexport const soundMapper: Record<keyof typeof CircleSoundKeyMapper, null | HTMLAudioElement> = {\n [CircleSoundKey.BACKGROUND]: null,\n [CircleSoundKey.BACKGROUND_RUSHHOUR]: null,\n [CircleSoundKey.TUTORIAL]: null,\n [CircleSoundKey.SWIPE_01]: null,\n [CircleSoundKey.SWIPE_02]: null,\n [CircleSoundKey.SWIPE_03]: null,\n [CircleSoundKey.SWIPE_04]: null,\n [CircleSoundKey.SWIPE_DOWN]: null,\n [CircleSoundKey.TOGGLE]: null,\n [CircleSoundKey.POINTS_AWARDED]: null,\n [CircleSoundKey.POINTS_ADDED]: null,\n [CircleSoundKey.GAME_CARD_CLICK]: null,\n [CircleSoundKey.CLOCK_IN]: null,\n [CircleSoundKey.CLOCK_OUT]: null,\n [CircleSoundKey.ACCURACY_IN]: null,\n [CircleSoundKey.ACCURACY_OUT]: null,\n [CircleSoundKey.STREAK_IN]: null,\n [CircleSoundKey.STREAK_OUT]: null,\n [CircleSoundKey.ACCURACY_INTRO]: null,\n [CircleSoundKey.ACCURACY_TARGET]: null,\n [CircleSoundKey.TIME_INTRO]: null,\n [CircleSoundKey.TIME_TARGET]: null,\n [CircleSoundKey.METER_FILL]: null,\n};\n\nconst soundInstancePromise: Partial<Record<keyof typeof CircleSoundKeyMapper, Promise<void>>> = {};\n\nexport const useCircleSounds = () => {\n const loadSound = useCallback((key: CircleSoundKey) => {\n if (!soundMapper[key]) {\n const loadedSound = new Audio(CircleSoundKeyMapper[key]);\n\n soundMapper[key] = loadedSound;\n }\n }, []);\n\n const pausedSoundsRef = useRef<Set<CircleSoundKey>>(new Set());\n const timeoutRefs = useRef<TimeoutMap>({});\n\n const handleVisibilityChange = useCallback(() => {\n if (document.visibilityState === 'hidden') {\n (Object.keys(soundMapper) as CircleSoundKey[]).forEach(key => {\n const sound = soundMapper[key];\n\n if (sound && !sound.paused) {\n sound.pause();\n pausedSoundsRef.current.add(key);\n }\n });\n } else if (document.visibilityState === 'visible') {\n pausedSoundsRef.current.forEach(key => {\n const sound = soundMapper[key];\n\n sound?.play();\n });\n pausedSoundsRef.current.clear();\n }\n }, []);\n\n useEffect(() => {\n document.addEventListener('visibilitychange', handleVisibilityChange);\n const timeouts = timeoutRefs.current;\n\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange);\n for (const id of Object.values(timeouts)) {\n if (id != null) clearInterval(id);\n }\n };\n }, [handleVisibilityChange]);\n\n const playSwipSound = useCallback(() => {\n SWIPE_SOUND_ORDER.forEach(key => {\n loadSound(key);\n });\n\n const key = SWIPE_SOUND_ORDER[swipeSoundIndex] || CircleSoundKey.SWIPE_01;\n\n if (swipeSoundIndex < SWIPE_SOUND_ORDER.length - 1) {\n swipeSoundIndex++;\n } else {\n swipeSoundIndex = 0;\n }\n soundMapper[key]?.play();\n }, [loadSound]);\n\n const playButtonSound = useCallback(() => {\n loadSound(CircleSoundKey.TOGGLE);\n const sound = soundMapper[CircleSoundKey.TOGGLE]?.play();\n\n return sound;\n }, [loadSound]);\n\n const play = useCallback(\n (key: CircleSoundKey, immediately: boolean = true, loop = false) => {\n loadSound(key);\n const soundInstance = soundMapper[key];\n\n if (!soundInstance) return;\n\n if (!soundInstance.paused && soundInstance.currentTime > 0 && !soundInstance.ended) {\n return soundInstance;\n }\n\n soundInstance.loop = loop;\n if (immediately) {\n soundInstance.volume = 1;\n const promise = soundInstance.play();\n\n soundInstancePromise[key] = promise;\n\n return;\n }\n\n soundInstance.volume = 0;\n const promise = soundInstance.play();\n\n soundInstancePromise[key] = promise;\n\n const intervalId = setInterval(() => {\n if (!soundInstance) {\n clearInterval(intervalId);\n\n return;\n }\n\n const vol = soundInstance.volume || 0;\n\n if (vol < 1) {\n soundInstance.volume = Math.min(vol + 0.1, 1);\n } else {\n clearInterval(intervalId);\n }\n }, 100);\n\n timeoutRefs.current[key] = intervalId;\n\n return soundInstance;\n },\n [loadSound],\n );\n\n const stop = useCallback((key: CircleSoundKey, immediately: boolean = true) => {\n const soundInstance = soundMapper[key];\n\n if (soundInstancePromise[key] !== undefined) {\n soundInstancePromise[key]\n ?.then(() => {\n if (!soundInstance) return;\n\n if (immediately) {\n soundInstance.pause();\n\n return;\n }\n\n const intervalId = setInterval(() => {\n if (!soundInstance) {\n clearInterval(intervalId);\n\n return;\n }\n\n const vol = soundInstance.volume || 0;\n\n if (vol - 0.1 <= 0) {\n soundInstance.volume = 0;\n soundInstance.pause();\n clearInterval(intervalId);\n } else {\n soundInstance.volume = vol - 0.1;\n }\n }, 100);\n\n timeoutRefs.current[key] = intervalId;\n })\n .catch(err => {\n // eslint-disable-next-line no-console\n console.log('sound not playing', err);\n });\n }\n }, []);\n\n return { playSwipSound, play, stop, playButtonSound };\n};\n"],"names":["swipeSoundIndex","soundMapper","CircleSoundKey","soundInstancePromise","useCircleSounds","loadSound","useCallback","key","loadedSound","CircleSoundKeyMapper","pausedSoundsRef","useRef","timeoutRefs","handleVisibilityChange","sound","useEffect","timeouts","id","playSwipSound","SWIPE_SOUND_ORDER","_a","playButtonSound","play","immediately","loop","soundInstance","promise","intervalId","vol","stop","err"],"mappings":";;;AAOA,IAAIA,IAAkB;AAEf,MAAMC,IAAkF;AAAA,EAC7F,CAACC,EAAe,UAAU,GAAG;AAAA,EAC7B,CAACA,EAAe,mBAAmB,GAAG;AAAA,EACtC,CAACA,EAA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AI,qBAAqBA,CAAG;AAAA,IAAA;AAAA,EAG5C,GAAG,CAAE,CAAA;AAEL,SAAO,EAAE,eAAAZ,GAAe,MAAAI,GAAM,MAAAO,GAAM,iBAAAR,EAAgB;AACtD;"}
|
@@ -1,81 +1,80 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import
|
3
|
-
import { memo as
|
4
|
-
import { LOTTIE as
|
5
|
-
import { useCircleSounds as
|
6
|
-
import { CircleSoundKey as
|
1
|
+
import { jsxs as v, jsx as t } from "react/jsx-runtime";
|
2
|
+
import I from "lottie-web";
|
3
|
+
import { memo as X, useRef as a, useState as d, useCallback as W, useEffect as b } from "react";
|
4
|
+
import { LOTTIE as M } from "../../../assets/lottie/lottie.js";
|
5
|
+
import { useCircleSounds as k } from "../../circle-games/hooks/use-circle-sounds/use-circle-sounds.js";
|
6
|
+
import { CircleSoundKey as h } from "../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums.js";
|
7
7
|
import { delay as s } from "../../utils/utils.js";
|
8
|
-
import { AnimatedPercentTextInput as
|
9
|
-
import { Accuracy as
|
10
|
-
import { getAccuracyFramesToPlay as
|
11
|
-
import { NEEDLE_HOLD_TIME as
|
12
|
-
const
|
13
|
-
const { play: c } =
|
8
|
+
import { AnimatedPercentTextInput as H } from "./accuracy-comps.js";
|
9
|
+
import { Accuracy as K, AccuracyMeterLottie as q, AnimatedAccuracyNeedleContainer as z, AccuracyNeedleLottie as B, TextWrapper as G, PercentTextWrapper as J } from "./accuracy-styled.js";
|
10
|
+
import { getAccuracyFramesToPlay as Q } from "./accuracy-utils.js";
|
11
|
+
import { NEEDLE_HOLD_TIME as C, METER as O, TEXT_DISAPPEAR_DELAY as V, TEXT_DISAPPEAR_DURATION as Z, TEXT_APPEAR_DURATION as ee, NEEDLE as F, NEEDLE_LOTTIE_FPS as U } from "./constants.js";
|
12
|
+
const Ae = X(({ show: u, onComplete: n, accuracy: l, helperText: E }) => {
|
13
|
+
const { play: c } = k(), y = a(null), p = a(null), o = a(), r = a(), [g, w] = d(!0), [m, T] = d(!1), [R, x] = d(!1), $ = a(0), _ = (F.IN_FRAMES[1] - F.IN_FRAMES[0]) / U * 1e3, S = W(async () => {
|
14
14
|
var A;
|
15
15
|
try {
|
16
|
-
await s(
|
17
|
-
} catch (
|
18
|
-
console.log(
|
16
|
+
await s(C), w(!1), T(!1), c(h.ACCURACY_OUT), (A = o.current) == null || A.playSegments(O.OUT_FRAMES, !0), await s(V), x(!0), n == null || n();
|
17
|
+
} catch (e) {
|
18
|
+
console.log(e);
|
19
19
|
}
|
20
20
|
}, [n, c]);
|
21
|
-
return
|
21
|
+
return b(() => {
|
22
22
|
if (u)
|
23
23
|
return (async () => {
|
24
|
-
var
|
25
|
-
const [
|
26
|
-
fetch(
|
27
|
-
fetch(
|
24
|
+
var L;
|
25
|
+
const [e, i] = await Promise.all([
|
26
|
+
fetch(M.ACCURACY_METER),
|
27
|
+
fetch(M.ACCURACY_NEEDLE)
|
28
28
|
]), [Y, j] = await Promise.all([
|
29
|
-
|
29
|
+
e.json(),
|
30
30
|
i.json()
|
31
31
|
]);
|
32
|
-
o.current =
|
32
|
+
o.current = I.loadAnimation({
|
33
33
|
container: y.current,
|
34
34
|
animationData: Y,
|
35
35
|
autoplay: !1,
|
36
36
|
loop: !1,
|
37
37
|
renderer: "svg"
|
38
|
-
}),
|
38
|
+
}), r.current = I.loadAnimation({
|
39
39
|
container: p.current,
|
40
40
|
animationData: j,
|
41
41
|
autoplay: !1,
|
42
42
|
loop: !1,
|
43
43
|
renderer: "svg"
|
44
|
-
}), c(
|
44
|
+
}), c(h.ACCURACY_IN), (L = o.current) == null || L.playSegments(O.IN_FRAMES, !0), s(_).then(() => {
|
45
45
|
var D, P, N;
|
46
|
-
const f =
|
47
|
-
|
48
|
-
|
49
|
-
(I = e.current) == null || I.removeEventListener("complete"), s(O).then(() => L());
|
46
|
+
const f = Q(l);
|
47
|
+
$.current = f, (D = r.current) == null || D.setSpeed(f / U), (P = r.current) == null || P.playSegments([0, f], !0), T(!0), (N = r.current) == null || N.addEventListener("complete", () => {
|
48
|
+
s(C).then(() => S());
|
50
49
|
});
|
51
50
|
});
|
52
51
|
})(), () => {
|
53
|
-
var
|
54
|
-
(
|
52
|
+
var e, i;
|
53
|
+
(e = o.current) == null || e.destroy(), (i = r.current) == null || i.destroy();
|
55
54
|
};
|
56
|
-
}, [u, l, _,
|
57
|
-
/* @__PURE__ */
|
58
|
-
|
59
|
-
E && /* @__PURE__ */
|
60
|
-
|
55
|
+
}, [u, l, _, S, c]), u ? /* @__PURE__ */ v(K, { children: [
|
56
|
+
/* @__PURE__ */ t(q, { ref: y }),
|
57
|
+
g && /* @__PURE__ */ t(z, { children: /* @__PURE__ */ t(B, { ref: p }) }),
|
58
|
+
E && /* @__PURE__ */ t(
|
59
|
+
G,
|
61
60
|
{
|
62
61
|
$delay: 1e3,
|
63
62
|
$animationType: R ? "fadeout" : "fadein",
|
64
|
-
$duration: R ?
|
63
|
+
$duration: R ? Z : ee,
|
65
64
|
children: E
|
66
65
|
}
|
67
66
|
),
|
68
|
-
m && /* @__PURE__ */
|
69
|
-
|
67
|
+
m && /* @__PURE__ */ t(
|
68
|
+
J,
|
70
69
|
{
|
71
70
|
$animationType: m ? "fadein" : "fadeout",
|
72
71
|
$duration: 200,
|
73
|
-
children: /* @__PURE__ */
|
72
|
+
children: /* @__PURE__ */ t(H, { accuracy: Math.round(l), time: 1e3 })
|
74
73
|
}
|
75
74
|
)
|
76
75
|
] }) : null;
|
77
76
|
});
|
78
77
|
export {
|
79
|
-
|
78
|
+
Ae as Accuracy
|
80
79
|
};
|
81
80
|
//# sourceMappingURL=accuracy.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accuracy.js","sources":["../../../../src/features/post-game-stats/accuracy/accuracy.tsx"],"sourcesContent":["import type { IAccuracyProps } from './accuracy-types';\nimport type { AnimationItem } from 'lottie-web';\nimport type { FC } from 'react';\n\nimport Lottie from 'lottie-web';\nimport { memo, useEffect, useRef, useState, useCallback } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { useCircleSounds } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { delay } from '../../utils/utils';\nimport { AnimatedPercentTextInput } from './accuracy-comps';\nimport * as Styled from './accuracy-styled';\nimport { getAccuracyFramesToPlay } from './accuracy-utils';\nimport {\n METER,\n NEEDLE,\n NEEDLE_HOLD_TIME,\n TEXT_APPEAR_DURATION,\n TEXT_DISAPPEAR_DELAY,\n TEXT_DISAPPEAR_DURATION,\n NEEDLE_LOTTIE_FPS,\n} from './constants';\n\nexport const Accuracy: FC<IAccuracyProps> = memo(({ show, onComplete, accuracy, helperText }) => {\n const { play } = useCircleSounds();\n const accuracyMeterRef = useRef<HTMLDivElement>(null);\n const accuracyNeedleRef = useRef<HTMLDivElement>(null);\n const accuracyMeterAnimationRef = useRef<AnimationItem>();\n const accuracyNeedleAnimationRef = useRef<AnimationItem>();\n\n const [showAccuracy, setShowAccuracy] = useState(true);\n const [showPercent, setShowPercent] = useState(false);\n const [fadeOut, setFadeOut] = useState(false);\n const needleFramesToPlay = useRef(0);\n\n const percentStartAnimationDelayInMs =\n ((NEEDLE.IN_FRAMES[1] - NEEDLE.IN_FRAMES[0]) / NEEDLE_LOTTIE_FPS) * 1000;\n\n const playExitAnimation = useCallback(async () => {\n try {\n await delay(NEEDLE_HOLD_TIME);\n setShowAccuracy(false);\n setShowPercent(false);\n play(CircleSoundKey.ACCURACY_OUT);\n accuracyMeterAnimationRef.current?.playSegments(METER.OUT_FRAMES, true);\n await delay(TEXT_DISAPPEAR_DELAY);\n setFadeOut(true);\n onComplete?.();\n } catch (err) {\n /* eslint-disable no-console */\n console.log(err);\n }\n }, [onComplete, play]);\n\n useEffect(() => {\n if (show) {\n const loadAnimations = async () => {\n const [meterLottie, needleLottie] = await Promise.all([\n fetch(LOTTIE.ACCURACY_METER),\n fetch(LOTTIE.ACCURACY_NEEDLE),\n ]);\n const [meterLottieData, needleLottieData] = await Promise.all([\n meterLottie.json(),\n needleLottie.json(),\n ]);\n\n accuracyMeterAnimationRef.current = Lottie.loadAnimation({\n container: accuracyMeterRef.current as Element,\n animationData: meterLottieData,\n autoplay: false,\n loop: false,\n renderer: 'svg',\n });\n\n accuracyNeedleAnimationRef.current = Lottie.loadAnimation({\n container: accuracyNeedleRef.current as Element,\n animationData: needleLottieData,\n autoplay: false,\n loop: false,\n renderer: 'svg',\n });\n\n play(CircleSoundKey.ACCURACY_IN);\n accuracyMeterAnimationRef.current?.playSegments(METER.IN_FRAMES, true);\n\n delay(percentStartAnimationDelayInMs).then(() => {\n const frames = getAccuracyFramesToPlay(accuracy);\n\n needleFramesToPlay.current = frames;\n accuracyNeedleAnimationRef.current?.setSpeed(frames / NEEDLE_LOTTIE_FPS);\n accuracyNeedleAnimationRef.current?.playSegments([0, frames], true);\n setShowPercent(true);\n\n accuracyNeedleAnimationRef.current?.addEventListener('complete', () => {\n
|
1
|
+
{"version":3,"file":"accuracy.js","sources":["../../../../src/features/post-game-stats/accuracy/accuracy.tsx"],"sourcesContent":["import type { IAccuracyProps } from './accuracy-types';\nimport type { AnimationItem } from 'lottie-web';\nimport type { FC } from 'react';\n\nimport Lottie from 'lottie-web';\nimport { memo, useEffect, useRef, useState, useCallback } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { useCircleSounds } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { delay } from '../../utils/utils';\nimport { AnimatedPercentTextInput } from './accuracy-comps';\nimport * as Styled from './accuracy-styled';\nimport { getAccuracyFramesToPlay } from './accuracy-utils';\nimport {\n METER,\n NEEDLE,\n NEEDLE_HOLD_TIME,\n TEXT_APPEAR_DURATION,\n TEXT_DISAPPEAR_DELAY,\n TEXT_DISAPPEAR_DURATION,\n NEEDLE_LOTTIE_FPS,\n} from './constants';\n\nexport const Accuracy: FC<IAccuracyProps> = memo(({ show, onComplete, accuracy, helperText }) => {\n const { play } = useCircleSounds();\n const accuracyMeterRef = useRef<HTMLDivElement>(null);\n const accuracyNeedleRef = useRef<HTMLDivElement>(null);\n const accuracyMeterAnimationRef = useRef<AnimationItem>();\n const accuracyNeedleAnimationRef = useRef<AnimationItem>();\n\n const [showAccuracy, setShowAccuracy] = useState(true);\n const [showPercent, setShowPercent] = useState(false);\n const [fadeOut, setFadeOut] = useState(false);\n const needleFramesToPlay = useRef(0);\n\n const percentStartAnimationDelayInMs =\n ((NEEDLE.IN_FRAMES[1] - NEEDLE.IN_FRAMES[0]) / NEEDLE_LOTTIE_FPS) * 1000;\n\n const playExitAnimation = useCallback(async () => {\n try {\n await delay(NEEDLE_HOLD_TIME);\n setShowAccuracy(false);\n setShowPercent(false);\n play(CircleSoundKey.ACCURACY_OUT);\n accuracyMeterAnimationRef.current?.playSegments(METER.OUT_FRAMES, true);\n await delay(TEXT_DISAPPEAR_DELAY);\n setFadeOut(true);\n onComplete?.();\n } catch (err) {\n /* eslint-disable no-console */\n console.log(err);\n }\n }, [onComplete, play]);\n\n useEffect(() => {\n if (show) {\n const loadAnimations = async () => {\n const [meterLottie, needleLottie] = await Promise.all([\n fetch(LOTTIE.ACCURACY_METER),\n fetch(LOTTIE.ACCURACY_NEEDLE),\n ]);\n const [meterLottieData, needleLottieData] = await Promise.all([\n meterLottie.json(),\n needleLottie.json(),\n ]);\n\n accuracyMeterAnimationRef.current = Lottie.loadAnimation({\n container: accuracyMeterRef.current as Element,\n animationData: meterLottieData,\n autoplay: false,\n loop: false,\n renderer: 'svg',\n });\n\n accuracyNeedleAnimationRef.current = Lottie.loadAnimation({\n container: accuracyNeedleRef.current as Element,\n animationData: needleLottieData,\n autoplay: false,\n loop: false,\n renderer: 'svg',\n });\n\n play(CircleSoundKey.ACCURACY_IN);\n accuracyMeterAnimationRef.current?.playSegments(METER.IN_FRAMES, true);\n\n delay(percentStartAnimationDelayInMs).then(() => {\n const frames = getAccuracyFramesToPlay(accuracy);\n\n needleFramesToPlay.current = frames;\n accuracyNeedleAnimationRef.current?.setSpeed(frames / NEEDLE_LOTTIE_FPS);\n accuracyNeedleAnimationRef.current?.playSegments([0, frames], true);\n setShowPercent(true);\n\n accuracyNeedleAnimationRef.current?.addEventListener('complete', () => {\n delay(NEEDLE_HOLD_TIME).then(() => playExitAnimation());\n });\n });\n };\n\n loadAnimations();\n\n return () => {\n accuracyMeterAnimationRef.current?.destroy();\n accuracyNeedleAnimationRef.current?.destroy();\n };\n }\n }, [show, accuracy, percentStartAnimationDelayInMs, playExitAnimation, play]);\n\n if (show) {\n return (\n <Styled.Accuracy>\n <Styled.AccuracyMeterLottie ref={accuracyMeterRef} />\n {showAccuracy && (\n <Styled.AnimatedAccuracyNeedleContainer>\n <Styled.AccuracyNeedleLottie ref={accuracyNeedleRef} />\n </Styled.AnimatedAccuracyNeedleContainer>\n )}\n {helperText && (\n <Styled.TextWrapper\n $delay={1000}\n $animationType={fadeOut ? 'fadeout' : 'fadein'}\n $duration={fadeOut ? TEXT_DISAPPEAR_DURATION : TEXT_APPEAR_DURATION}\n >\n {helperText}\n </Styled.TextWrapper>\n )}\n {showPercent && (\n <Styled.PercentTextWrapper\n $animationType={showPercent ? 'fadein' : 'fadeout'}\n $duration={showPercent ? 200 : 200}\n >\n <AnimatedPercentTextInput accuracy={Math.round(accuracy)} time={1000} />\n </Styled.PercentTextWrapper>\n )}\n </Styled.Accuracy>\n );\n }\n\n return null;\n});\n"],"names":["Accuracy","memo","show","onComplete","accuracy","helperText","play","useCircleSounds","accuracyMeterRef","useRef","accuracyNeedleRef","accuracyMeterAnimationRef","accuracyNeedleAnimationRef","showAccuracy","setShowAccuracy","useState","showPercent","setShowPercent","fadeOut","setFadeOut","needleFramesToPlay","percentStartAnimationDelayInMs","NEEDLE","NEEDLE_LOTTIE_FPS","playExitAnimation","useCallback","delay","NEEDLE_HOLD_TIME","CircleSoundKey","_a","METER","TEXT_DISAPPEAR_DELAY","err","useEffect","meterLottie","needleLottie","LOTTIE","meterLottieData","needleLottieData","Lottie","frames","getAccuracyFramesToPlay","_b","_c","jsxs","Styled.Accuracy","jsx","Styled.AccuracyMeterLottie","Styled.AnimatedAccuracyNeedleContainer","Styled.AccuracyNeedleLottie","Styled.TextWrapper","TEXT_DISAPPEAR_DURATION","TEXT_APPEAR_DURATION","Styled.PercentTextWrapper","AnimatedPercentTextInput"],"mappings":";;;;;;;;;;;AAwBa,MAAAA,KAA+BC,EAAK,CAAC,EAAE,MAAAC,GAAM,YAAAC,GAAY,UAAAC,GAAU,YAAAC,QAAiB;AACzF,QAAA,EAAE,MAAAC,MAASC,KACXC,IAAmBC,EAAuB,IAAI,GAC9CC,IAAoBD,EAAuB,IAAI,GAC/CE,IAA4BF,KAC5BG,IAA6BH,KAE7B,CAACI,GAAcC,CAAe,IAAIC,EAAS,EAAI,GAC/C,CAACC,GAAaC,CAAc,IAAIF,EAAS,EAAK,GAC9C,CAACG,GAASC,CAAU,IAAIJ,EAAS,EAAK,GACtCK,IAAqBX,EAAO,CAAC,GAE7BY,KACFC,EAAO,UAAU,CAAC,IAAIA,EAAO,UAAU,CAAC,KAAKC,IAAqB,KAEhEC,IAAoBC,EAAY,YAAY;;AAC5C,QAAA;AACF,YAAMC,EAAMC,CAAgB,GAC5Bb,EAAgB,EAAK,GACrBG,EAAe,EAAK,GACpBX,EAAKsB,EAAe,YAAY,IAChCC,IAAAlB,EAA0B,YAA1B,QAAAkB,EAAmC,aAAaC,EAAM,YAAY,KAClE,MAAMJ,EAAMK,CAAoB,GAChCZ,EAAW,EAAI,GACFhB,KAAA,QAAAA;AAAA,aACN6B,GAAK;AAEZ,cAAQ,IAAIA,CAAG;AAAA,IACjB;AAAA,EAAA,GACC,CAAC7B,GAAYG,CAAI,CAAC;AAwDrB,SAtDA2B,EAAU,MAAM;AACd,QAAI/B;AA4Ca,cA3CQ,Y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;AAAA,EAEhD,GACC,CAACxC,GAAME,GAAUiB,GAAgCG,GAAmBlB,CAAI,CAAC,GAExEJ,IAEA,gBAAA0C,EAACC,GAAA,EACC,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EAA2B,KAAKvC,EAAkB,CAAA;AAAA,IAClDK,KACE,gBAAAiC,EAAAE,GAAA,EACC,UAAC,gBAAAF,EAAAG,GAAA,EAA4B,KAAKvC,EAAmB,CAAA,GACvD;AAAA,IAEDL,KACC,gBAAAyC;AAAA,MAACI;AAAAA,MAAA;AAAA,QACC,QAAQ;AAAA,QACR,gBAAgBhC,IAAU,YAAY;AAAA,QACtC,WAAWA,IAAUiC,IAA0BC;AAAA,QAE9C,UAAA/C;AAAA,MAAA;AAAA,IACH;AAAA,IAEDW,KACC,gBAAA8B;AAAA,MAACO;AAAAA,MAAA;AAAA,QACC,gBAAgBrC,IAAc,WAAW;AAAA,QACzC,WAAyB;AAAA,QAEzB,UAAA,gBAAA8B,EAACQ,KAAyB,UAAU,KAAK,MAAMlD,CAAQ,GAAG,MAAM,KAAM;AAAA,MAAA;AAAA,IACxE;AAAA,EAEJ,EAAA,CAAA,IAIG;AACT,CAAC;"}
|
@@ -1,75 +1,75 @@
|
|
1
|
-
import { jsxs as K, jsx as
|
2
|
-
import
|
3
|
-
import { memo as g, useState as h, useRef as o, useCallback as
|
4
|
-
import { LOTTIE as
|
1
|
+
import { jsxs as K, jsx as u } from "react/jsx-runtime";
|
2
|
+
import I from "lottie-web";
|
3
|
+
import { memo as g, useState as h, useRef as o, useCallback as T, useEffect as j } from "react";
|
4
|
+
import { LOTTIE as k } from "../../../assets/lottie/lottie.js";
|
5
5
|
import { useCircleSounds as x } from "../../circle-games/hooks/use-circle-sounds/use-circle-sounds.js";
|
6
|
-
import { CircleSoundKey as
|
7
|
-
import { delay as
|
6
|
+
import { CircleSoundKey as R } from "../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums.js";
|
7
|
+
import { delay as D } from "../../utils/utils.js";
|
8
8
|
import { Clock as U, ClockLottie as $, ClockTimeSpentLottie as w, TextWrapper as X } from "./clock-styled.js";
|
9
9
|
import { getClockTimeSpentFramesToPlay as Y } from "./clock-util.js";
|
10
10
|
import { CLOCK_TIME_SPENT_FPS as H, CLOCK as N, CLOCK_INFRAME_LOTTIE_TO_PLAY as W, TIME_LOTTIE_TO_PLAY_IN as b, TEXT_DISAPPEAR_DURATION as q, TEXT_APPEAR_DURATION as z, TIME_SHOWN_HOLD_TIME as B, TEXT_DISAPPEAR_DELAY as G } from "./constants.js";
|
11
|
-
const
|
12
|
-
const { play: c } = x(), [
|
13
|
-
var
|
14
|
-
const r = Y(
|
15
|
-
r && (
|
16
|
-
}, [
|
17
|
-
var r,
|
18
|
-
await
|
19
|
-
var
|
20
|
-
|
11
|
+
const it = g(({ show: s, onComplete: i, timeInMs: f, helperText: p }) => {
|
12
|
+
const { play: c } = x(), [L, F] = h(!1), m = o(!1), l = o(0), d = o(null), E = o(null), a = o(), n = o(), _ = T(() => {
|
13
|
+
var t, e;
|
14
|
+
const r = Y(f);
|
15
|
+
r && (l.current = r, (t = n.current) == null || t.setSpeed(r / H), (e = n.current) == null || e.playSegments([0, r], !0), m.current = !0);
|
16
|
+
}, [f]), S = T(async () => {
|
17
|
+
var r, t;
|
18
|
+
await D(B), (r = n.current) == null || r.playSegments([l.current, 0], !0), await D(G), F(!0), m.current && ((t = n.current) == null || t.addEventListener("complete", () => {
|
19
|
+
var e;
|
20
|
+
c(R.CLOCK_OUT), (e = a.current) == null || e.playSegments(N.OUT_FRAMES, !0);
|
21
21
|
}));
|
22
|
-
}, [
|
22
|
+
}, [l, c]), A = T(() => {
|
23
23
|
i == null || i();
|
24
24
|
}, [i]);
|
25
25
|
return j(() => {
|
26
|
-
if (
|
26
|
+
if (s)
|
27
27
|
return (async () => {
|
28
|
-
var C, y
|
29
|
-
const [
|
30
|
-
fetch(
|
31
|
-
fetch(
|
32
|
-
]), [
|
33
|
-
|
34
|
-
|
28
|
+
var O, C, y;
|
29
|
+
const [t, e] = await Promise.all([
|
30
|
+
fetch(k.TOTAL_TIME),
|
31
|
+
fetch(k.TOTAL_TIME_SPENT)
|
32
|
+
]), [M, v] = await Promise.all([
|
33
|
+
t.json(),
|
34
|
+
e.json()
|
35
35
|
]);
|
36
|
-
a.current =
|
36
|
+
a.current = I.loadAnimation({
|
37
37
|
container: d.current,
|
38
|
-
animationData:
|
38
|
+
animationData: M,
|
39
39
|
autoplay: !1,
|
40
40
|
loop: !1,
|
41
41
|
renderer: "canvas"
|
42
|
-
}), n.current =
|
43
|
-
container:
|
44
|
-
animationData:
|
42
|
+
}), n.current = I.loadAnimation({
|
43
|
+
container: E.current,
|
44
|
+
animationData: v,
|
45
45
|
autoplay: !1,
|
46
46
|
loop: !1,
|
47
47
|
renderer: "canvas"
|
48
|
-
}), c(
|
49
|
-
|
50
|
-
}), (
|
51
|
-
var
|
52
|
-
(
|
48
|
+
}), c(R.CLOCK_IN), (O = a.current) == null || O.playSegments(N.IN_FRAMES, !0), (C = a.current) == null || C.addEventListener("complete", () => {
|
49
|
+
m.current ? A() : _();
|
50
|
+
}), (y = n.current) == null || y.addEventListener("complete", () => {
|
51
|
+
var P;
|
52
|
+
(P = n.current) == null || P.removeEventListener("complete"), S();
|
53
53
|
});
|
54
54
|
})(), () => {
|
55
|
-
var
|
56
|
-
(
|
55
|
+
var t, e;
|
56
|
+
(t = a.current) == null || t.destroy(), (e = n.current) == null || e.destroy();
|
57
57
|
};
|
58
|
-
}, [
|
59
|
-
/* @__PURE__ */
|
60
|
-
/* @__PURE__ */
|
61
|
-
|
58
|
+
}, [s, _, A, S, c]), s ? /* @__PURE__ */ K(U, { children: [
|
59
|
+
/* @__PURE__ */ u($, { ref: d }),
|
60
|
+
/* @__PURE__ */ u(w, { ref: E }),
|
61
|
+
p && /* @__PURE__ */ u(
|
62
62
|
X,
|
63
63
|
{
|
64
64
|
$delay: W + b,
|
65
|
-
$animationType:
|
66
|
-
$duration:
|
67
|
-
children:
|
65
|
+
$animationType: L ? "fadeout" : "fadein",
|
66
|
+
$duration: L ? q : z,
|
67
|
+
children: p
|
68
68
|
}
|
69
69
|
)
|
70
70
|
] }) : null;
|
71
71
|
});
|
72
72
|
export {
|
73
|
-
|
73
|
+
it as Clock
|
74
74
|
};
|
75
75
|
//# sourceMappingURL=clock.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"clock.js","sources":["../../../../src/features/post-game-stats/clock/clock.tsx"],"sourcesContent":["import type { IClockProps } from './clock-types';\nimport type { AnimationItem } from 'lottie-web';\nimport type { FC } from 'react';\n\nimport Lottie from 'lottie-web';\nimport { memo, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { useCircleSounds } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { delay } from '../../utils/utils';\nimport * as Styled from './clock-styled';\nimport { getClockTimeSpentFramesToPlay } from './clock-util';\nimport {\n CLOCK,\n CLOCK_TIME_SPENT_FPS,\n TIME_SHOWN_HOLD_TIME,\n TEXT_APPEAR_DURATION,\n TEXT_DISAPPEAR_DELAY,\n TEXT_DISAPPEAR_DURATION,\n CLOCK_INFRAME_LOTTIE_TO_PLAY,\n TIME_LOTTIE_TO_PLAY_IN,\n} from './constants';\n\nexport const Clock: FC<IClockProps> = memo(({ show, onComplete, timeInMs, helperText }) => {\n const { play } = useCircleSounds();\n const [fadeOut, setFadeOut] = useState(false);\n const isClockTimeSpentShown = useRef(false);\n const framesToPlay = useRef(0);\n\n const clockLottieContainerRef = useRef<HTMLDivElement>(null);\n const clockTimeSpentLottieContainerRef = useRef<HTMLDivElement>(null);\n const clockLottieAnimationRef = useRef<AnimationItem>();\n const clockTimeSpentLottieAnimationRef = useRef<AnimationItem>();\n\n const setClockTimeSpentFrames = useCallback(() => {\n const frames = getClockTimeSpentFramesToPlay(timeInMs);\n\n if (frames) {\n framesToPlay.current = frames;\n // Speed adjustment\n clockTimeSpentLottieAnimationRef.current?.setSpeed(frames / CLOCK_TIME_SPENT_FPS);\n clockTimeSpentLottieAnimationRef.current?.playSegments([0, frames], true);\n isClockTimeSpentShown.current = true;\n }\n }, [timeInMs]);\n\n const onClockTimeSpentExitAnimationFinished = useCallback(async () => {\n await delay(TIME_SHOWN_HOLD_TIME);\n\n // Reverse play time spent animation\n clockTimeSpentLottieAnimationRef.current?.playSegments([framesToPlay.current, 0], true);\n\n await delay(TEXT_DISAPPEAR_DELAY);\n setFadeOut(true);\n\n if (isClockTimeSpentShown.current) {\n clockTimeSpentLottieAnimationRef.current?.addEventListener('complete', () => {\n
|
1
|
+
{"version":3,"file":"clock.js","sources":["../../../../src/features/post-game-stats/clock/clock.tsx"],"sourcesContent":["import type { IClockProps } from './clock-types';\nimport type { AnimationItem } from 'lottie-web';\nimport type { FC } from 'react';\n\nimport Lottie from 'lottie-web';\nimport { memo, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { useCircleSounds } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../../circle-games/hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { delay } from '../../utils/utils';\nimport * as Styled from './clock-styled';\nimport { getClockTimeSpentFramesToPlay } from './clock-util';\nimport {\n CLOCK,\n CLOCK_TIME_SPENT_FPS,\n TIME_SHOWN_HOLD_TIME,\n TEXT_APPEAR_DURATION,\n TEXT_DISAPPEAR_DELAY,\n TEXT_DISAPPEAR_DURATION,\n CLOCK_INFRAME_LOTTIE_TO_PLAY,\n TIME_LOTTIE_TO_PLAY_IN,\n} from './constants';\n\nexport const Clock: FC<IClockProps> = memo(({ show, onComplete, timeInMs, helperText }) => {\n const { play } = useCircleSounds();\n const [fadeOut, setFadeOut] = useState(false);\n const isClockTimeSpentShown = useRef(false);\n const framesToPlay = useRef(0);\n\n const clockLottieContainerRef = useRef<HTMLDivElement>(null);\n const clockTimeSpentLottieContainerRef = useRef<HTMLDivElement>(null);\n const clockLottieAnimationRef = useRef<AnimationItem>();\n const clockTimeSpentLottieAnimationRef = useRef<AnimationItem>();\n\n const setClockTimeSpentFrames = useCallback(() => {\n const frames = getClockTimeSpentFramesToPlay(timeInMs);\n\n if (frames) {\n framesToPlay.current = frames;\n // Speed adjustment\n clockTimeSpentLottieAnimationRef.current?.setSpeed(frames / CLOCK_TIME_SPENT_FPS);\n clockTimeSpentLottieAnimationRef.current?.playSegments([0, frames], true);\n isClockTimeSpentShown.current = true;\n }\n }, [timeInMs]);\n\n const onClockTimeSpentExitAnimationFinished = useCallback(async () => {\n await delay(TIME_SHOWN_HOLD_TIME);\n\n // Reverse play time spent animation\n clockTimeSpentLottieAnimationRef.current?.playSegments([framesToPlay.current, 0], true);\n\n await delay(TEXT_DISAPPEAR_DELAY);\n setFadeOut(true);\n\n if (isClockTimeSpentShown.current) {\n clockTimeSpentLottieAnimationRef.current?.addEventListener('complete', () => {\n play(CircleSoundKey.CLOCK_OUT);\n clockLottieAnimationRef.current?.playSegments(CLOCK.OUT_FRAMES, true);\n });\n }\n }, [framesToPlay, play]);\n\n const onAnimationEnd = useCallback(() => {\n onComplete?.();\n }, [onComplete]);\n\n // Play entry animation\n useEffect(() => {\n if (show) {\n const loadAnimations = async () => {\n const [timeLottiePath, timeSpentLottiePath] = await Promise.all([\n fetch(LOTTIE.TOTAL_TIME),\n fetch(LOTTIE.TOTAL_TIME_SPENT),\n ]);\n const [timeLottieData, timeSpentLottieData] = await Promise.all([\n timeLottiePath.json(),\n timeSpentLottiePath.json(),\n ]);\n\n // Clock Lottie\n clockLottieAnimationRef.current = Lottie.loadAnimation({\n container: clockLottieContainerRef.current as Element,\n animationData: timeLottieData,\n autoplay: false,\n loop: false,\n renderer: 'canvas',\n });\n\n // Clock Time Spent Lottie\n clockTimeSpentLottieAnimationRef.current = Lottie.loadAnimation({\n container: clockTimeSpentLottieContainerRef.current as Element,\n animationData: timeSpentLottieData,\n autoplay: false,\n loop: false,\n renderer: 'canvas',\n });\n\n // Play clock in animation sounds and lottie\n play(CircleSoundKey.CLOCK_IN);\n clockLottieAnimationRef.current?.playSegments(CLOCK.IN_FRAMES, true);\n\n clockLottieAnimationRef.current?.addEventListener('complete', () => {\n if (!isClockTimeSpentShown.current) {\n setClockTimeSpentFrames();\n } else {\n onAnimationEnd();\n }\n });\n\n // Setup event listener for time spent animation\n clockTimeSpentLottieAnimationRef.current?.addEventListener('complete', () => {\n clockTimeSpentLottieAnimationRef.current?.removeEventListener('complete');\n onClockTimeSpentExitAnimationFinished();\n });\n };\n\n loadAnimations();\n\n return () => {\n clockLottieAnimationRef.current?.destroy();\n clockTimeSpentLottieAnimationRef.current?.destroy();\n };\n }\n }, [show, setClockTimeSpentFrames, onAnimationEnd, onClockTimeSpentExitAnimationFinished, play]);\n\n if (show) {\n return (\n <Styled.Clock>\n <Styled.ClockLottie ref={clockLottieContainerRef} />\n <Styled.ClockTimeSpentLottie ref={clockTimeSpentLottieContainerRef} />\n {helperText && (\n <Styled.TextWrapper\n $delay={CLOCK_INFRAME_LOTTIE_TO_PLAY + TIME_LOTTIE_TO_PLAY_IN}\n $animationType={fadeOut ? 'fadeout' : 'fadein'}\n $duration={fadeOut ? TEXT_DISAPPEAR_DURATION : TEXT_APPEAR_DURATION}\n >\n {helperText}\n </Styled.TextWrapper>\n )}\n </Styled.Clock>\n );\n }\n\n return null;\n});\n"],"names":["Clock","memo","show","onComplete","timeInMs","helperText","play","useCircleSounds","fadeOut","setFadeOut","useState","isClockTimeSpentShown","useRef","framesToPlay","clockLottieContainerRef","clockTimeSpentLottieContainerRef","clockLottieAnimationRef","clockTimeSpentLottieAnimationRef","setClockTimeSpentFrames","useCallback","frames","getClockTimeSpentFramesToPlay","_a","CLOCK_TIME_SPENT_FPS","_b","onClockTimeSpentExitAnimationFinished","delay","TIME_SHOWN_HOLD_TIME","TEXT_DISAPPEAR_DELAY","CircleSoundKey","CLOCK","onAnimationEnd","useEffect","timeLottiePath","timeSpentLottiePath","LOTTIE","timeLottieData","timeSpentLottieData","Lottie","_c","jsxs","Styled.Clock","jsx","Styled.ClockLottie","Styled.ClockTimeSpentLottie","Styled.TextWrapper","CLOCK_INFRAME_LOTTIE_TO_PLAY","TIME_LOTTIE_TO_PLAY_IN","TEXT_DISAPPEAR_DURATION","TEXT_APPEAR_DURATION"],"mappings":";;;;;;;;;;AAwBa,MAAAA,KAAyBC,EAAK,CAAC,EAAE,MAAAC,GAAM,YAAAC,GAAY,UAAAC,GAAU,YAAAC,QAAiB;AACnF,QAAA,EAAE,MAAAC,MAASC,KACX,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtCC,IAAwBC,EAAO,EAAK,GACpCC,IAAeD,EAAO,CAAC,GAEvBE,IAA0BF,EAAuB,IAAI,GACrDG,IAAmCH,EAAuB,IAAI,GAC9DI,IAA0BJ,KAC1BK,IAAmCL,KAEnCM,IAA0BC,EAAY,MAAM;;AAC1C,UAAAC,IAASC,EAA8BjB,CAAQ;AAErD,IAAIgB,MACFP,EAAa,UAAUO,IAEUE,IAAAL,EAAA,YAAA,QAAAK,EAAS,SAASF,IAASG,KAC5DC,IAAAP,EAAiC,YAAjC,QAAAO,EAA0C,aAAa,CAAC,GAAGJ,CAAM,GAAG,KACpET,EAAsB,UAAU;AAAA,EAClC,GACC,CAACP,CAAQ,CAAC,GAEPqB,IAAwCN,EAAY,YAAY;;AACpE,UAAMO,EAAMC,CAAoB,IAGhCL,IAAAL,EAAiC,YAAjC,QAAAK,EAA0C,aAAa,CAACT,EAAa,SAAS,CAAC,GAAG,KAElF,MAAMa,EAAME,CAAoB,GAChCnB,EAAW,EAAI,GAEXE,EAAsB,aACSa,IAAAP,EAAA,YAAA,QAAAO,EAAS,iBAAiB,YAAY,MAAM;;AAC3E,MAAAlB,EAAKuB,EAAe,SAAS,IAC7BP,IAAAN,EAAwB,YAAxB,QAAAM,EAAiC,aAAaQ,EA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