@cuemath/leap 3.1.2-j2 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/assets/illustrations/illustrations.js +2 -1
  2. package/dist/assets/illustrations/illustrations.js.map +1 -1
  3. package/dist/assets/line-icons/icons/check.js +3 -3
  4. package/dist/assets/line-icons/icons/check.js.map +1 -1
  5. package/dist/assets/line-icons/icons/puzzle-icon.js +51 -0
  6. package/dist/assets/line-icons/icons/puzzle-icon.js.map +1 -0
  7. package/dist/assets/line-icons/icons/share.js +48 -0
  8. package/dist/assets/line-icons/icons/share.js.map +1 -0
  9. package/dist/assets/line-icons/icons/tile.js +54 -0
  10. package/dist/assets/line-icons/icons/tile.js.map +1 -0
  11. package/dist/features/auth/account-selector/account-selector.js +36 -56
  12. package/dist/features/auth/account-selector/account-selector.js.map +1 -1
  13. package/dist/features/auth/comps/auth-page-layout/auth-page-layout-styles.js +12 -0
  14. package/dist/features/auth/comps/auth-page-layout/auth-page-layout-styles.js.map +1 -0
  15. package/dist/features/auth/comps/auth-page-layout/auth-page-layout.js +9 -8
  16. package/dist/features/auth/comps/auth-page-layout/auth-page-layout.js.map +1 -1
  17. package/dist/features/auth/comps/auth-static-panel/auth-static-panel.js +1 -1
  18. package/dist/features/auth/comps/auth-static-panel/auth-static-panel.js.map +1 -1
  19. package/dist/features/auth/forgot-password/forgot-password-styled.js +3 -15
  20. package/dist/features/auth/forgot-password/forgot-password-styled.js.map +1 -1
  21. package/dist/features/auth/forgot-password/otp-form/otp-form.js +29 -29
  22. package/dist/features/auth/forgot-password/otp-form/otp-form.js.map +1 -1
  23. package/dist/features/auth/forgot-password/reset-password-form/reset-password-form.js +18 -14
  24. package/dist/features/auth/forgot-password/reset-password-form/reset-password-form.js.map +1 -1
  25. package/dist/features/auth/forgot-password/user-identifier-form/user-identifier-form.js +24 -23
  26. package/dist/features/auth/forgot-password/user-identifier-form/user-identifier-form.js.map +1 -1
  27. package/dist/features/auth/login/identifier-otp-form/identifier-otp-form-styled.js +2 -4
  28. package/dist/features/auth/login/identifier-otp-form/identifier-otp-form-styled.js.map +1 -1
  29. package/dist/features/auth/login/identifier-otp-form/identifier-otp-form.js +75 -85
  30. package/dist/features/auth/login/identifier-otp-form/identifier-otp-form.js.map +1 -1
  31. package/dist/features/auth/login/social-account-not-found/social-account-not-found.js +20 -26
  32. package/dist/features/auth/login/social-account-not-found/social-account-not-found.js.map +1 -1
  33. package/dist/features/auth/login/social-login-methods/social-login-methods.js +34 -43
  34. package/dist/features/auth/login/social-login-methods/social-login-methods.js.map +1 -1
  35. package/dist/features/auth/login/username-password-form/username-password-form.js +21 -22
  36. package/dist/features/auth/login/username-password-form/username-password-form.js.map +1 -1
  37. package/dist/features/auth/user-list/user-item/user-item.js +24 -25
  38. package/dist/features/auth/user-list/user-item/user-item.js.map +1 -1
  39. package/dist/features/auth/user-list/user-list.js +51 -60
  40. package/dist/features/auth/user-list/user-list.js.map +1 -1
  41. package/dist/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.js +74 -74
  42. package/dist/features/circle-games/hooks/use-circle-sounds/use-circle-sounds.js.map +1 -1
  43. package/dist/features/cue-canvas/bottombar/homework-controls.js +73 -0
  44. package/dist/features/cue-canvas/bottombar/homework-controls.js.map +1 -0
  45. package/dist/features/cue-canvas/cue-canvas-context.js +8 -5
  46. package/dist/features/cue-canvas/cue-canvas-context.js.map +1 -1
  47. package/dist/features/cue-canvas/cue-canvas-core.js +84 -74
  48. package/dist/features/cue-canvas/cue-canvas-core.js.map +1 -1
  49. package/dist/features/cue-canvas/cue-canvas-helpers.js +31 -25
  50. package/dist/features/cue-canvas/cue-canvas-helpers.js.map +1 -1
  51. package/dist/features/cue-canvas/cue-canvas-provider.js +14 -12
  52. package/dist/features/cue-canvas/cue-canvas-provider.js.map +1 -1
  53. package/dist/features/cue-canvas/cue-canvas.js +66 -59
  54. package/dist/features/cue-canvas/cue-canvas.js.map +1 -1
  55. package/dist/features/cue-canvas/cue-cavas-styled.js +45 -42
  56. package/dist/features/cue-canvas/cue-cavas-styled.js.map +1 -1
  57. package/dist/features/cue-canvas/hooks/use-canvas-sync-broker.js +61 -54
  58. package/dist/features/cue-canvas/hooks/use-canvas-sync-broker.js.map +1 -1
  59. package/dist/features/cue-canvas/hooks/use-config-updater.js +12 -0
  60. package/dist/features/cue-canvas/hooks/use-config-updater.js.map +1 -0
  61. package/dist/features/cue-canvas/hooks/use-cue-canvas-actions.js +18 -14
  62. package/dist/features/cue-canvas/hooks/use-cue-canvas-actions.js.map +1 -1
  63. package/dist/features/cue-canvas/hooks/use-upload-helper.js +23 -0
  64. package/dist/features/cue-canvas/hooks/use-upload-helper.js.map +1 -0
  65. package/dist/features/cue-canvas/sidebar/homework/helper.js +20 -0
  66. package/dist/features/cue-canvas/sidebar/homework/helper.js.map +1 -0
  67. package/dist/features/cue-canvas/sidebar/homework/homework-menu.js +33 -0
  68. package/dist/features/cue-canvas/sidebar/homework/homework-menu.js.map +1 -0
  69. package/dist/features/cue-canvas/sidebar/homework/homework-request.js +68 -0
  70. package/dist/features/cue-canvas/sidebar/homework/homework-request.js.map +1 -0
  71. package/dist/features/cue-canvas/sidebar/homework/homework-styled.js +25 -0
  72. package/dist/features/cue-canvas/sidebar/homework/homework-styled.js.map +1 -0
  73. package/dist/features/cue-canvas/sidebar/homework/homework.js +39 -0
  74. package/dist/features/cue-canvas/sidebar/homework/homework.js.map +1 -0
  75. package/dist/features/cue-canvas/sidebar/puzzles/api/get-puzzles.js +13 -0
  76. package/dist/features/cue-canvas/sidebar/puzzles/api/get-puzzles.js.map +1 -0
  77. package/dist/features/cue-canvas/sidebar/puzzles/filter-selection-menu.js +60 -0
  78. package/dist/features/cue-canvas/sidebar/puzzles/filter-selection-menu.js.map +1 -0
  79. package/dist/features/cue-canvas/sidebar/puzzles/filters-section.js +44 -0
  80. package/dist/features/cue-canvas/sidebar/puzzles/filters-section.js.map +1 -0
  81. package/dist/features/cue-canvas/sidebar/puzzles/filters.js +107 -0
  82. package/dist/features/cue-canvas/sidebar/puzzles/filters.js.map +1 -0
  83. package/dist/features/cue-canvas/sidebar/puzzles/hooks/use-fetch-cue-canvas-activity.js +42 -0
  84. package/dist/features/cue-canvas/sidebar/puzzles/hooks/use-fetch-cue-canvas-activity.js.map +1 -0
  85. package/dist/features/cue-canvas/sidebar/puzzles/launch-puzzle.js +84 -0
  86. package/dist/features/cue-canvas/sidebar/puzzles/launch-puzzle.js.map +1 -0
  87. package/dist/features/cue-canvas/sidebar/puzzles/puzzle-menu-header.js +36 -0
  88. package/dist/features/cue-canvas/sidebar/puzzles/puzzle-menu-header.js.map +1 -0
  89. package/dist/features/cue-canvas/sidebar/puzzles/puzzle-menu.js +133 -0
  90. package/dist/features/cue-canvas/sidebar/puzzles/puzzle-menu.js.map +1 -0
  91. package/dist/features/cue-canvas/sidebar/puzzles/puzzles-styled.js +96 -0
  92. package/dist/features/cue-canvas/sidebar/puzzles/puzzles-styled.js.map +1 -0
  93. package/dist/features/cue-canvas/sidebar/puzzles/puzzles.js +29 -0
  94. package/dist/features/cue-canvas/sidebar/puzzles/puzzles.js.map +1 -0
  95. package/dist/features/cue-canvas/sidebar/puzzles/utils.js +120 -0
  96. package/dist/features/cue-canvas/sidebar/puzzles/utils.js.map +1 -0
  97. package/dist/features/cue-canvas/sidebar/sidebar-styled.js +32 -0
  98. package/dist/features/cue-canvas/sidebar/sidebar-styled.js.map +1 -0
  99. package/dist/features/cue-canvas/sidebar/sidebar.js +29 -0
  100. package/dist/features/cue-canvas/sidebar/sidebar.js.map +1 -0
  101. package/dist/features/cue-canvas/sidebar/tiles/tile.js +16 -0
  102. package/dist/features/cue-canvas/sidebar/tiles/tile.js.map +1 -0
  103. package/dist/features/cue-canvas/toolbar/grid-menu.js +13 -13
  104. package/dist/features/cue-canvas/toolbar/grid-menu.js.map +1 -1
  105. package/dist/features/cue-canvas/toolbar/tool.js +22 -20
  106. package/dist/features/cue-canvas/toolbar/tool.js.map +1 -1
  107. package/dist/features/homework/styles.js +5 -4
  108. package/dist/features/homework/styles.js.map +1 -1
  109. package/dist/features/hooks/use-debounce.js +16 -0
  110. package/dist/features/hooks/use-debounce.js.map +1 -0
  111. package/dist/features/milestone/create/comps/add-custom-chapter/course-catalog.js +38 -36
  112. package/dist/features/milestone/create/comps/add-custom-chapter/course-catalog.js.map +1 -1
  113. package/dist/features/milestone/create/comps/add-custom-chapter/hooks/use-catalog-helpers.js +24 -22
  114. package/dist/features/milestone/create/comps/add-custom-chapter/hooks/use-catalog-helpers.js.map +1 -1
  115. package/dist/features/milestone/create/comps/chapters-selection-step/chapter-selection-step-v2/chapter-category/chapter-category-container.js +23 -22
  116. package/dist/features/milestone/create/comps/chapters-selection-step/chapter-selection-step-v2/chapter-category/chapter-category-container.js.map +1 -1
  117. package/dist/features/milestone/create/comps/chapters-selection-step/utils.js +49 -47
  118. package/dist/features/milestone/create/comps/chapters-selection-step/utils.js.map +1 -1
  119. package/dist/features/milestone/create/comps/class-details-step/class-details-step.js +94 -87
  120. package/dist/features/milestone/create/comps/class-details-step/class-details-step.js.map +1 -1
  121. package/dist/features/milestone/create/comps/class-details-step/class-details-utils.js +13 -12
  122. package/dist/features/milestone/create/comps/class-details-step/class-details-utils.js.map +1 -1
  123. package/dist/features/milestone/create/comps/test-type-step/test-type-step.js +23 -21
  124. package/dist/features/milestone/create/comps/test-type-step/test-type-step.js.map +1 -1
  125. package/dist/features/milestone/create/milestone-create-helpers.js +165 -162
  126. package/dist/features/milestone/create/milestone-create-helpers.js.map +1 -1
  127. package/dist/features/trial-session/comps/pricing/india-pricing/index.js +96 -0
  128. package/dist/features/trial-session/comps/pricing/india-pricing/index.js.map +1 -0
  129. package/dist/features/trial-session/comps/pricing/india-pricing/india-pricing-styled.js +59 -0
  130. package/dist/features/trial-session/comps/pricing/india-pricing/india-pricing-styled.js.map +1 -0
  131. package/dist/features/trial-session/comps/pricing/pricing.js +36 -35
  132. package/dist/features/trial-session/comps/pricing/pricing.js.map +1 -1
  133. package/dist/features/ui/buttons/button/button-styled.js +29 -29
  134. package/dist/features/ui/buttons/button/button-styled.js.map +1 -1
  135. package/dist/features/ui/stepper/stepper.js +7 -7
  136. package/dist/features/worksheet/worksheet/hooks/use-s3-helper.js +22 -19
  137. package/dist/features/worksheet/worksheet/hooks/use-s3-helper.js.map +1 -1
  138. package/dist/index.d.ts +54 -24
  139. package/dist/index.js +202 -202
  140. package/dist/static/ellipse-clip.dfb25608.svg +1 -0
  141. package/package.json +1 -1
  142. package/dist/features/auth/account-selector/account-selector-styled.js +0 -9
  143. package/dist/features/auth/account-selector/account-selector-styled.js.map +0 -1
  144. package/dist/features/auth/comps/auth-page-layout/auth-page-layout-styled.js +0 -21
  145. package/dist/features/auth/comps/auth-page-layout/auth-page-layout-styled.js.map +0 -1
  146. package/dist/features/auth/login/login-styled.js +0 -13
  147. package/dist/features/auth/login/login-styled.js.map +0 -1
  148. package/dist/features/auth/login/social-login-methods/social-login-methods-styled.js +0 -9
  149. package/dist/features/auth/login/social-login-methods/social-login-methods-styled.js.map +0 -1
  150. package/dist/features/hooks/use-device-type.js +0 -25
  151. package/dist/features/hooks/use-device-type.js.map +0 -1
  152. package/dist/features/utils/media.js +0 -16
  153. package/dist/features/utils/media.js.map +0 -1
  154. package/dist/static/cuemath-app-qr-code.7205ee79.svg +0 -1
@@ -1,118 +1,118 @@
1
- import { useCallback as c, useRef as C, useEffect as T } from "react";
1
+ import { useCallback as a, 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 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;
3
+ import { CircleSoundKey as e } from "./use-circle-sounds-enums.js";
4
+ let I = 0;
5
+ const r = {
6
+ [e.BACKGROUND]: null,
7
+ [e.BACKGROUND_RUSHHOUR]: null,
8
+ [e.TUTORIAL]: null,
9
+ [e.SWIPE_01]: null,
10
+ [e.SWIPE_02]: null,
11
+ [e.SWIPE_03]: null,
12
+ [e.SWIPE_04]: null,
13
+ [e.SWIPE_DOWN]: null,
14
+ [e.TOGGLE]: null,
15
+ [e.POINTS_AWARDED]: null,
16
+ [e.POINTS_ADDED]: null,
17
+ [e.GAME_CARD_CLICK]: null,
18
+ [e.CLOCK_IN]: null,
19
+ [e.CLOCK_OUT]: null,
20
+ [e.ACCURACY_IN]: null,
21
+ [e.ACCURACY_OUT]: null,
22
+ [e.STREAK_IN]: null,
23
+ [e.STREAK_OUT]: null,
24
+ [e.ACCURACY_INTRO]: null,
25
+ [e.ACCURACY_TARGET]: null,
26
+ [e.TIME_INTRO]: null,
27
+ [e.TIME_TARGET]: null,
28
+ [e.METER_FILL]: null
29
+ }, f = {}, D = () => {
30
+ const c = a((n) => {
31
+ if (!r[n]) {
32
+ const l = new Audio(A[n]);
33
+ r[n] = l;
34
34
  }
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];
35
+ }, []), v = C(/* @__PURE__ */ new Set()), o = C({}), p = a(() => {
36
+ document.visibilityState === "hidden" ? Object.keys(r).forEach((n) => {
37
+ const l = r[n];
38
+ l && !l.paused && (l.pause(), v.current.add(n));
39
+ }) : document.visibilityState === "visible" && (v.current.forEach((n) => {
40
+ const l = r[n];
41
41
  l == null || l.play();
42
- }), f.current.clear());
42
+ }), v.current.clear());
43
43
  }, []);
44
44
  T(() => {
45
- document.addEventListener("visibilitychange", v);
46
- const e = p.current;
45
+ document.addEventListener("visibilitychange", p);
46
+ const n = o.current;
47
47
  return () => {
48
- document.removeEventListener("visibilitychange", v);
49
- for (const l of Object.values(e))
48
+ document.removeEventListener("visibilitychange", p);
49
+ for (const l of Object.values(n))
50
50
  l != null && clearInterval(l);
51
51
  };
52
- }, [v]);
53
- const S = c(() => {
52
+ }, [p]);
53
+ const S = a(() => {
54
54
  var l;
55
55
  E.forEach((u) => {
56
- s(u);
56
+ c(u);
57
57
  });
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(() => {
58
+ const n = E[I] || e.SWIPE_01;
59
+ I < E.length - 1 ? I++ : I = 0, (l = r[n]) == null || l.play();
60
+ }, [c]), m = a(() => {
61
61
  var l;
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];
62
+ return c(e.TOGGLE), (l = r[e.TOGGLE]) == null ? void 0 : l.play();
63
+ }, [c]), _ = a(
64
+ (n, l = !0, u = !1) => {
65
+ c(n);
66
+ const t = r[n];
67
67
  if (!t) return;
68
- if (!t.paused && t.currentTime > 0 && !t.ended)
68
+ if (o.current[n] && clearInterval(o.current[n]), !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 a = t.play();
73
- I[e] = a;
72
+ const d = t.play();
73
+ f[n] = d;
74
74
  return;
75
75
  }
76
76
  t.volume = 0;
77
- const r = t.play();
78
- I[e] = r;
77
+ const s = t.play();
78
+ f[n] = s;
79
79
  const i = setInterval(() => {
80
80
  if (!t) {
81
81
  clearInterval(i);
82
82
  return;
83
83
  }
84
- const a = t.volume || 0;
85
- a < 1 ? t.volume = Math.min(a + 0.1, 1) : clearInterval(i);
84
+ const d = t.volume || 0;
85
+ d < 1 ? t.volume = Math.min(d + 0.1, 1) : clearInterval(i);
86
86
  }, 100);
87
- return p.current[e] = i, t;
87
+ return o.current[n] = i, t;
88
88
  },
89
- [s]
90
- ), R = c((e, l = !0) => {
89
+ [c]
90
+ ), R = a((n, l = !0) => {
91
91
  var t;
92
- const u = o[e];
93
- I[e] !== void 0 && ((t = I[e]) == null || t.then(() => {
92
+ const u = r[n];
93
+ f[n] !== void 0 && ((t = f[n]) == null || t.then(() => {
94
94
  if (!u) return;
95
- if (l) {
95
+ if (o.current[n] && clearInterval(o.current[n]), l) {
96
96
  u.pause();
97
97
  return;
98
98
  }
99
- const r = setInterval(() => {
99
+ const s = setInterval(() => {
100
100
  if (!u) {
101
- clearInterval(r);
101
+ clearInterval(s);
102
102
  return;
103
103
  }
104
104
  const i = u.volume || 0;
105
- i - 0.1 <= 0 ? (u.volume = 0, u.pause(), clearInterval(r)) : u.volume = i - 0.1;
105
+ i - 0.1 <= 0 ? (u.volume = 0, u.pause(), clearInterval(s)) : u.volume = i - 0.1;
106
106
  }, 100);
107
- p.current[e] = r;
108
- }).catch((r) => {
109
- console.log("sound not playing", r);
107
+ o.current[n] = s;
108
+ }).catch((s) => {
109
+ console.log("sound not playing", s);
110
110
  }));
111
111
  }, []);
112
112
  return { playSwipSound: S, play: _, stop: R, playButtonSound: m };
113
113
  };
114
114
  export {
115
- o as soundMapper,
115
+ r 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 (!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,EAAe,QAAQ,GAAG;AAAA,EAC3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AAA;AAAA,EAG5C,GAAG,CAAE,CAAA;AAEL,SAAO,EAAE,eAAAZ,GAAe,MAAAI,GAAM,MAAAO,GAAM,iBAAAR,EAAgB;AACtD;"}
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 (timeoutRefs.current[key]) {\n clearInterval(timeoutRefs.current[key]);\n }\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 (timeoutRefs.current[key]) {\n clearInterval(timeoutRefs.current[key]);\n }\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;A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,EAAc,SAAS,GACvBA,EAAc,MAAM,GACpB,cAAcE,CAAU,KAExBF,EAAc,SAASG,IAAM;AAAA,SAE9B,GAAG;AAEM,MAAAhB,EAAA,QAAQL,CAAG,IAAIoB;AAAA,IAAA,GAE5B,MAAM,CAAOG,MAAA;AAEJ,cAAA,IAAI,qBAAqBA,CAAG;AAAA,IAAA;AAAA,EAG5C,GAAG,CAAE,CAAA;AAEL,SAAO,EAAE,eAAAZ,GAAe,MAAAI,GAAM,MAAAO,GAAM,iBAAAR,EAAgB;AACtD;"}
@@ -0,0 +1,73 @@
1
+ import { jsx as n, jsxs as g } from "react/jsx-runtime";
2
+ import { memo as b, useState as w, useCallback as i } from "react";
3
+ import k from "../../../assets/line-icons/icons/check.js";
4
+ import y from "../../../assets/line-icons/icons/share.js";
5
+ import f from "../../ui/buttons/button/button.js";
6
+ import p from "../../ui/layout/flex-view.js";
7
+ import I from "../../ui/separator/separator.js";
8
+ import B from "../../ui/text/text.js";
9
+ import { dataURIToBlob as x } from "../cue-canvas-helpers.js";
10
+ import { useCueCanvasActions as A } from "../hooks/use-cue-canvas-actions.js";
11
+ const S = (h) => {
12
+ const { width: c, onSendImageToChat: t, onMarkAsResolved: s } = h, { homeworkId: o, activeInstance: r, setHomeworkId: l } = A(), [m, u] = w(!1), a = i(() => {
13
+ r == null || r.clearCanvas(), l(void 0), u(!1);
14
+ }, [r, l]), d = i(async () => {
15
+ if (!r) return;
16
+ const e = await (r == null ? void 0 : r.getCanvasAsImage());
17
+ return e ? [x(e)] : void 0;
18
+ }, [r]), $ = i(async () => {
19
+ const e = await d();
20
+ !o || !t || !e || t == null || t(o, e, a);
21
+ }, [d, o, t, a]), C = i(() => {
22
+ o && (u(!0), s == null || s(o, a));
23
+ }, [o, s, a]);
24
+ return o ? m ? /* @__PURE__ */ n(
25
+ p,
26
+ {
27
+ $gapX: 1,
28
+ $gutterX: 0.5,
29
+ $alignItems: "center",
30
+ $justifyContent: "center",
31
+ $width: c,
32
+ $background: "YELLOW_1",
33
+ children: /* @__PURE__ */ n(B, { $renderAs: "body3", $color: "BLACK", children: "Resolving...." })
34
+ }
35
+ ) : /* @__PURE__ */ g(
36
+ p,
37
+ {
38
+ $flexDirection: "row",
39
+ $gapX: 1,
40
+ $gutterX: 0.5,
41
+ $alignItems: "center",
42
+ $justifyContent: "center",
43
+ $width: c,
44
+ $background: "YELLOW_1",
45
+ children: [
46
+ /* @__PURE__ */ n(
47
+ f,
48
+ {
49
+ label: "Mark as reolved",
50
+ onClick: C,
51
+ renderAs: "primary",
52
+ Icon: k,
53
+ busy: m
54
+ }
55
+ ),
56
+ /* @__PURE__ */ n(I, { width: 16 }),
57
+ /* @__PURE__ */ n(
58
+ f,
59
+ {
60
+ label: "Send CueBoard image to chat",
61
+ onClick: $,
62
+ renderAs: "primary",
63
+ Icon: y
64
+ }
65
+ )
66
+ ]
67
+ }
68
+ ) : null;
69
+ }, _ = b(S);
70
+ export {
71
+ _ as default
72
+ };
73
+ //# sourceMappingURL=homework-controls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"homework-controls.js","sources":["../../../../src/features/cue-canvas/bottombar/homework-controls.tsx"],"sourcesContent":["import type { IHomeWorkControllerProps } from './bottombar-types';\nimport type { FC } from 'react';\n\nimport { memo, useCallback, useState } from 'react';\n\nimport CheckIcon from '../../../assets/line-icons/icons/check';\nimport ShareIcon from '../../../assets/line-icons/icons/share';\nimport Button from '../../ui/buttons/button/button';\nimport FlexView from '../../ui/layout/flex-view';\nimport Separator from '../../ui/separator/separator';\nimport Text from '../../ui/text/text';\nimport { dataURIToBlob } from '../cue-canvas-helpers';\nimport { useCueCanvasActions } from '../hooks/use-cue-canvas-actions';\n\nconst HomeworkController: FC<IHomeWorkControllerProps> = props => {\n const { width, onSendImageToChat, onMarkAsResolved } = props;\n const { homeworkId, activeInstance, setHomeworkId } = useCueCanvasActions();\n const [isBusy, setIsBusy] = useState(false);\n\n const onSuccess = useCallback(() => {\n activeInstance?.clearCanvas();\n setHomeworkId(undefined);\n setIsBusy(false);\n }, [activeInstance, setHomeworkId]);\n\n const getBoardSnapshot = useCallback(async () => {\n if (!activeInstance) return;\n\n const snapshot = await activeInstance?.getCanvasAsImage();\n\n if (!snapshot) {\n return;\n }\n\n const blobdata = dataURIToBlob(snapshot);\n\n return [blobdata];\n }, [activeInstance]);\n\n const handleSendImageToChat = useCallback(async () => {\n const snapshot = await getBoardSnapshot();\n\n if (!homeworkId || !onSendImageToChat || !snapshot) return;\n\n onSendImageToChat?.(homeworkId, snapshot, onSuccess);\n }, [getBoardSnapshot, homeworkId, onSendImageToChat, onSuccess]);\n\n const handleMarkAsResolved = useCallback(() => {\n if (!homeworkId) return;\n setIsBusy(true);\n onMarkAsResolved?.(homeworkId, onSuccess);\n }, [homeworkId, onMarkAsResolved, onSuccess]);\n\n if (!homeworkId) return null;\n\n if (isBusy) {\n return (\n <FlexView\n $gapX={1}\n $gutterX={0.5}\n $alignItems=\"center\"\n $justifyContent=\"center\"\n $width={width}\n $background=\"YELLOW_1\"\n >\n <Text $renderAs=\"body3\" $color=\"BLACK\">\n Resolving....\n </Text>\n </FlexView>\n );\n }\n\n return (\n <FlexView\n $flexDirection=\"row\"\n $gapX={1}\n $gutterX={0.5}\n $alignItems=\"center\"\n $justifyContent=\"center\"\n $width={width}\n $background=\"YELLOW_1\"\n >\n <Button\n label=\"Mark as reolved\"\n onClick={handleMarkAsResolved}\n renderAs={'primary'}\n Icon={CheckIcon}\n busy={isBusy}\n />\n <Separator width={16} />\n <Button\n label=\"Send CueBoard image to chat\"\n onClick={handleSendImageToChat}\n renderAs={'primary'}\n Icon={ShareIcon}\n />\n </FlexView>\n );\n};\n\nexport default memo(HomeworkController);\n"],"names":["HomeworkController","props","width","onSendImageToChat","onMarkAsResolved","homeworkId","activeInstance","setHomeworkId","useCueCanvasActions","isBusy","setIsBusy","useState","onSuccess","useCallback","getBoardSnapshot","snapshot","dataURIToBlob","handleSendImageToChat","handleMarkAsResolved","jsx","FlexView","Text","js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AAC;AAAA,IAACF;AAAA,IAAA;AAAA,MACC,gBAAe;AAAA,MACf,OAAO;AAAA,MACP,UAAU;AAAA,MACV,aAAY;AAAA,MACZ,iBAAgB;AAAA,MAChB,QAAQlB;AAAA,MACR,aAAY;AAAA,MAEZ,UAAA;AAAA,QAAA,gBAAAiB;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,OAAM;AAAA,YACN,SAASL;AAAA,YACT,UAAU;AAAA,YACV,MAAMM;AAAA,YACN,MAAMf;AAAA,UAAA;AAAA,QACR;AAAA,QACA,gBAAAU,EAACM,GAAU,EAAA,OAAO,GAAI,CAAA;AAAA,QACtB,gBAAAN;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,OAAM;AAAA,YACN,SAASN;AAAA,YACT,UAAU;AAAA,YACV,MAAMS;AAAA,UAAA;AAAA,QACR;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,IA1CoB;AA6C1B,GAEeC,IAAAC,EAAK5B,CAAkB;"}
@@ -1,17 +1,20 @@
1
- import { createContext as t } from "react";
2
- import { CANVAS_COLORS as o } from "./constants/constants.js";
3
- const c = t({
1
+ import { createContext as o } from "react";
2
+ import { CANVAS_COLORS as e } from "./constants/constants.js";
3
+ const v = o({
4
4
  activeInstance: void 0,
5
5
  setActiveInstance: () => {
6
6
  },
7
7
  activeTool: "pen",
8
8
  setActiveTool: () => {
9
9
  },
10
- activeColor: Object.keys(o)[0],
10
+ activeColor: Object.keys(e)[0],
11
11
  setActiveColor: () => {
12
+ },
13
+ homeworkId: void 0,
14
+ setHomeworkId: () => {
12
15
  }
13
16
  });
14
17
  export {
15
- c as default
18
+ v as default
16
19
  };
17
20
  //# sourceMappingURL=cue-canvas-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cue-canvas-context.js","sources":["../../../src/features/cue-canvas/cue-canvas-context.tsx"],"sourcesContent":["import type { TPolyContextValue } from './types/context';\nimport type { TCueCanvasColors } from './types/cue-canvas';\n\nimport { createContext } from 'react';\n\nimport { CANVAS_COLORS } from './constants/constants';\n\nconst PolyContext = createContext<TPolyContextValue>({\n activeInstance: undefined,\n setActiveInstance: () => undefined,\n activeTool: 'pen',\n setActiveTool: () => undefined,\n activeColor: Object.keys(CANVAS_COLORS)[0] as TCueCanvasColors,\n setActiveColor: () => undefined,\n});\n\nexport default PolyContext;\n"],"names":["PolyContext","createContext","CANVAS_COLORS"],"mappings":";;AAOA,MAAMA,IAAcC,EAAiC;AAAA,EACnD,gBAAgB;AAAA,EAChB,mBAAmB,MAAM;AAAA;AAAA,EACzB,YAAY;AAAA,EACZ,eAAe,MAAM;AAAA;AAAA,EACrB,aAAa,OAAO,KAAKC,CAAa,EAAE,CAAC;AAAA,EACzC,gBAAgB,MAAM;AAAA;AACxB,CAAC;"}
1
+ {"version":3,"file":"cue-canvas-context.js","sources":["../../../src/features/cue-canvas/cue-canvas-context.tsx"],"sourcesContent":["import type { TPolyContextValue } from './types/context';\nimport type { TCueCanvasColors } from './types/cue-canvas';\n\nimport { createContext } from 'react';\n\nimport { CANVAS_COLORS } from './constants/constants';\n\nconst PolyContext = createContext<TPolyContextValue>({\n activeInstance: undefined,\n setActiveInstance: () => undefined,\n activeTool: 'pen',\n setActiveTool: () => undefined,\n activeColor: Object.keys(CANVAS_COLORS)[0] as TCueCanvasColors,\n setActiveColor: () => undefined,\n homeworkId: undefined,\n setHomeworkId: () => undefined,\n});\n\nexport default PolyContext;\n"],"names":["PolyContext","createContext","CANVAS_COLORS"],"mappings":";;AAOA,MAAMA,IAAcC,EAAiC;AAAA,EACnD,gBAAgB;AAAA,EAChB,mBAAmB,MAAM;AAAA;AAAA,EACzB,YAAY;AAAA,EACZ,eAAe,MAAM;AAAA;AAAA,EACrB,aAAa,OAAO,KAAKC,CAAa,EAAE,CAAC;AAAA,EACzC,gBAAgB,MAAM;AAAA;AAAA,EACtB,YAAY;AAAA,EACZ,eAAe,MAAM;AAAA;AACvB,CAAC;"}
@@ -1,20 +1,22 @@
1
- var d = Object.defineProperty;
2
- var u = (r, t, e) => t in r ? d(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var s = (r, t, e) => u(r, typeof t != "symbol" ? t + "" : t, e);
4
- import v from "../../node_modules/lodash.debounce/index.js";
5
- import { removeTileButton as f, removeMask as g, checkTextOrEquationTool as y, getReverseMap as C, getToolAndSubtool as m } from "./cue-canvas-helpers.js";
6
- class b {
1
+ var u = Object.defineProperty;
2
+ var g = (c, t, e) => t in c ? u(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
+ var s = (c, t, e) => g(c, typeof t != "symbol" ? t + "" : t, e);
4
+ import { captureMessage as v } from "@sentry/browser";
5
+ import f from "../../node_modules/lodash.debounce/index.js";
6
+ import { removeTileButton as y, removeMask as C, checkTextOrEquationTool as m, getReverseMap as T, getToolAndSubtool as w } from "./cue-canvas-helpers.js";
7
+ class E {
7
8
  constructor({
8
9
  onPublish: t,
9
10
  onSubscribe: e,
10
11
  onUpdateActiveTool: a,
11
- onUpdateHeight: n,
12
+ onUpdateHeight: i,
12
13
  uploadImageToS3: o,
13
- height: i,
14
- userId: l,
15
- canvasId: h,
16
- userType: c,
17
- renderAs: p
14
+ height: n,
15
+ userId: h,
16
+ canvasId: r,
17
+ userType: l,
18
+ renderAs: p,
19
+ updateCanvasConfig: d
18
20
  }) {
19
21
  s(this, "polycanvas");
20
22
  s(this, "publish");
@@ -28,22 +30,22 @@ class b {
28
30
  s(this, "fileInput", null);
29
31
  s(this, "debouncedViewportChange");
30
32
  s(this, "uploadImageToS3");
31
- s(this, "publishToChannel", (t, e, a) => {
33
+ s(this, "updateCanvasConfigChange");
34
+ s(this, "gridName");
35
+ s(this, "publishToChannel", (t) => {
32
36
  this.publish && this.publish({
33
37
  eventName: "cue_canvas_changed",
34
38
  eventPayload: {
35
39
  data: t,
36
40
  height: this.height,
37
41
  userId: this.userId,
38
- responseId: this.canvasId,
39
- gridName: e,
40
- dimension: a
42
+ responseId: this.canvasId
41
43
  }
42
44
  });
43
45
  });
44
46
  s(this, "onChange", (t) => {
45
47
  const a = Object.fromEntries(t.entries());
46
- y(a) && this.onUpdateActiveTool("move"), this.publishToChannel(a);
48
+ m(a) && this.onUpdateActiveTool("move"), this.publishToChannel(a);
47
49
  });
48
50
  s(this, "undo", () => {
49
51
  if (!this.polycanvas)
@@ -51,7 +53,7 @@ class b {
51
53
  const t = this.polycanvas.undo();
52
54
  if (!t)
53
55
  return;
54
- const e = C(t);
56
+ const e = T(t);
55
57
  this.onChange(e);
56
58
  });
57
59
  s(this, "redo", () => {
@@ -73,6 +75,7 @@ class b {
73
75
  const t = this.polycanvas.getViewport();
74
76
  this.polycanvas.setViewport(t.x, t.y, t.zoom * 0.9);
75
77
  });
78
+ s(this, "getCanvasAsImage", async () => this.polycanvas ? await this.polycanvas.image(3e3, 3e3, "png") : void 0);
76
79
  s(this, "downloadCanvasAsImage", async () => {
77
80
  if (!this.polycanvas) return;
78
81
  const t = await this.polycanvas.image(3e3, 3e3, "png");
@@ -80,96 +83,103 @@ class b {
80
83
  const e = document.createElement("a");
81
84
  e.href = t, e.download = `canvas-drawing-${Date.now()}.png`, e.click();
82
85
  });
83
- s(this, "uploadFileToCanvas", async (t) => new Promise((e, a) => {
84
- this.uploadImageToS3 ? e(this.uploadImageToS3(t)) : a(new Error("Upload function not provided"));
85
- }));
86
86
  s(this, "onViewPortChange", (t) => {
87
- if (!this.publish) return;
88
- const e = t;
89
- this.publishToChannel({}, void 0, e);
87
+ this.updateCanvasConfigChange && this.updateCanvasConfigChange({ dimesion: t });
90
88
  });
91
89
  s(this, "openFileUpload", () => {
92
- this.fileInput || (this.fileInput = document.createElement("input"), this.fileInput.type = "file", this.fileInput.accept = "image/*", this.fileInput.style.display = "none", this.fileInput.onchange = this.addImageToCanvas, document.body.appendChild(this.fileInput)), this.fileInput.click();
90
+ this.fileInput || (this.fileInput = document.createElement("input"), this.fileInput.type = "file", this.fileInput.accept = "image/*", this.fileInput.style.display = "none", this.fileInput.onchange = this.onSelectImage, document.body.appendChild(this.fileInput)), this.fileInput.click();
93
91
  });
94
- s(this, "addImageToCanvas", async (t) => {
95
- var h;
96
- const e = t.target, a = (h = e.files) == null ? void 0 : h[0];
97
- if (!a || !this.polycanvas || !this.uploadImageToS3) return;
98
- const n = await this.uploadImageToS3(a), o = this.polycanvas.getViewport(), i = {
92
+ s(this, "addImageToCanvas", (t) => {
93
+ if (!this.polycanvas) return;
94
+ const e = this.polycanvas.getViewport(), a = {
99
95
  name: "image",
100
- href: n,
101
- x: o.x + 88,
102
- y: o.y + 88
103
- }, l = this.polycanvas.add({
104
- ...i
96
+ href: t,
97
+ x: e.x + 24,
98
+ y: e.y + 24,
99
+ width: 500
100
+ }, i = this.polycanvas.add({
101
+ ...a
105
102
  });
106
103
  this.publishToChannel({
107
- [l]: [void 0, { ...i, status: "locked" }]
108
- }), e.value = "";
104
+ [i]: [void 0, { ...a, status: "locked" }]
105
+ });
109
106
  });
110
- s(this, "updateCanvasConfig", (t, e, a) => {
111
- this.polycanvas && (t > this.height && this.updateHeight(t), e && this.polycanvas.setViewport(e.x, e.y, e.zoom), a && this.polycanvas.setOptions({
112
- grid: a
113
- }));
107
+ s(this, "onSelectImage", async (t) => {
108
+ var o;
109
+ const e = t.target, a = (o = e.files) == null ? void 0 : o[0];
110
+ if (!a || !this.polycanvas || !this.uploadImageToS3) return;
111
+ const i = await this.uploadImageToS3(a);
112
+ i !== "error" && (this.addImageToCanvas(i), e.value = "");
114
113
  });
115
114
  s(this, "updateCanvas", ({ data: t, userId: e }) => {
116
115
  const a = this.userType === "TEACHER" || e === this.userId;
117
- Object.entries(t).forEach(([n, o]) => {
118
- var i, l, h;
119
- !o[0] && o[1] ? (i = this.polycanvas) == null || i.add({ ...o[1], cannotEdit: !a }, n) : o[0] && !o[1] ? (l = this.polycanvas) == null || l.delete(n) : o[0] && o[1] && ((h = this.polycanvas) == null || h.update(n, { ...o[1] }));
120
- });
116
+ try {
117
+ Object.entries(t).forEach(([i, o]) => {
118
+ var n, h, r;
119
+ !o[0] && o[1] ? ("name" in o[1] && o[1].name === "image" && (o[1].status = this.userType === "STUDENT" ? "locked" : void 0), (n = this.polycanvas) == null || n.add({ ...o[1], cannotEdit: !a }, i)) : o[0] && !o[1] ? (h = this.polycanvas) == null || h.delete(i) : o[0] && o[1] && ((r = this.polycanvas) == null || r.update(i, { ...o[1] }));
120
+ });
121
+ } catch {
122
+ v("Error Updating Canvas", t);
123
+ }
121
124
  });
122
125
  s(this, "toggleTiles", (t) => {
123
126
  var e;
124
127
  (e = this.polycanvas) == null || e.toggleSidebar(t);
125
128
  });
129
+ s(this, "setViewPort", ({ x: t, y: e, zoom: a }) => {
130
+ var i;
131
+ if (this.polycanvas) {
132
+ const o = (i = this.polycanvas) == null ? void 0 : i.getViewport();
133
+ if (o.x === t && o.y === e && o.zoom === a)
134
+ return;
135
+ this.polycanvas.setViewport(t, e, a);
136
+ }
137
+ });
126
138
  s(this, "resetViewPort", () => {
127
139
  this.polycanvas && this.polycanvas.resetViewport();
128
140
  });
129
141
  s(this, "changeGrid", (t) => {
130
- this.polycanvas && (this.polycanvas.setOptions({
142
+ !this.polycanvas || this.gridName === t || (this.polycanvas.setOptions({
131
143
  grid: t
132
- }), this.publishToChannel({}, t));
144
+ }), this.gridName = t, this.updateCanvasConfigChange && this.updateCanvasConfigChange({ gridName: t }));
133
145
  });
134
146
  s(this, "lockSelectedTiles", () => {
135
- var a, n;
136
- const { tiles: t } = ((a = this.polycanvas) == null ? void 0 : a.serialize()) || {}, e = ((n = this.polycanvas) == null ? void 0 : n.getSelection()) || [];
147
+ var a, i;
148
+ const { tiles: t } = ((a = this.polycanvas) == null ? void 0 : a.serialize()) || {}, e = ((i = this.polycanvas) == null ? void 0 : i.getSelection()) || [];
137
149
  if (e.length > 0 && t) {
138
150
  const o = {};
139
- e.forEach((i) => {
140
- var h, c, p;
141
- if (!((h = t[i]) != null && h.name)) return;
142
- const l = { ...t[i], status: "locked" };
143
- (c = this.polycanvas) == null || c.update(i, l), (p = t[i]) != null && p.name && (o[i] = [t[i], l]);
151
+ e.forEach((n) => {
152
+ var r, l, p;
153
+ if (!((r = t[n]) != null && r.name)) return;
154
+ const h = { ...t[n], status: "locked" };
155
+ (l = this.polycanvas) == null || l.update(n, h), (p = t[n]) != null && p.name && (o[n] = [t[n], h]);
144
156
  }), this.publishToChannel(o);
145
157
  }
146
158
  });
147
159
  s(this, "unlockAllTiles", () => {
148
160
  if (!this.polycanvas) return;
149
161
  const { tiles: t } = this.polycanvas.serialize(), e = {};
150
- t && Object.entries(t).length > 0 && (Object.entries(t).forEach(([a, n]) => {
151
- var i;
152
- if (n.status !== "locked") return;
153
- const o = { ...n, status: void 0 };
154
- (i = this.polycanvas) == null || i.update(a, o), e[a] = [n, o];
162
+ t && Object.entries(t).length > 0 && (Object.entries(t).forEach(([a, i]) => {
163
+ var n;
164
+ if (i.status !== "locked") return;
165
+ const o = { ...i, status: void 0 };
166
+ (n = this.polycanvas) == null || n.update(a, o), e[a] = [i, o];
155
167
  }), this.publishToChannel(e));
156
168
  });
157
169
  s(this, "replaceCanvas", (t) => {
158
170
  if (!this.polycanvas) return;
159
171
  const { data: e, gridName: a } = t;
160
- this.polycanvas.clear(), a && this.polycanvas.setOptions({
161
- grid: a
162
- }), Object.entries(e).forEach(([n, o]) => {
163
- var i;
172
+ this.polycanvas.clear(), a && this.changeGrid(a), Object.entries(e).forEach(([i, o]) => {
173
+ var n;
164
174
  if (!o[0] && o[1]) {
165
- (i = this.polycanvas) == null || i.add({ ...o[1] }, n);
175
+ (n = this.polycanvas) == null || n.add({ ...o[1] }, i);
166
176
  return;
167
177
  }
168
- }), this.publishToChannel(e, a);
178
+ }), this.publishToChannel(e);
169
179
  });
170
180
  s(this, "setTool", (t) => {
171
181
  if (this.polycanvas) {
172
- const [e, a] = m(t);
182
+ const [e, a] = w(t);
173
183
  switch (e) {
174
184
  case "clearAll":
175
185
  this.clearCanvas();
@@ -222,10 +232,10 @@ class b {
222
232
  */
223
233
  s(this, "update", (t) => {
224
234
  if (Array.isArray(t)) {
225
- const e = t.map((i) => i.height).filter(Boolean), a = Math.max(...e), n = t.map((i) => i.dimension).filter(Boolean)[t.length - 1], o = t.map((i) => i.gridName).filter(Boolean)[t.length - 1];
226
- this.updateCanvasConfig(a, n, o), t.forEach((i) => this.updateCanvas(i));
235
+ const e = t.map((i) => i.height).filter(Boolean), a = Math.max(...e);
236
+ a > this.height && this.updateHeight(a), t.forEach((i) => this.updateCanvas(i));
227
237
  } else
228
- this.updateCanvasConfig(t.height, t.dimension, t == null ? void 0 : t.gridName), this.updateCanvas(t);
238
+ t.height > this.height && this.updateHeight(t.height), this.updateCanvas(t);
229
239
  });
230
240
  s(this, "setColor", (t) => {
231
241
  this.polycanvas && this.polycanvas.setColor(t);
@@ -237,9 +247,9 @@ class b {
237
247
  s(this, "destroy", () => {
238
248
  this.polycanvas && (this.polycanvas.off("change", this.onChange), this.polycanvas.destroy(), this.debouncedViewportChange.cancel(), this.renderAs === "whiteboard" && this.userType === "TEACHER" && this.polycanvas.off("viewport", this.debouncedViewportChange), this.polycanvas = void 0, this.fileInput && this.fileInput.parentNode && (this.fileInput.parentNode.removeChild(this.fileInput), this.fileInput = null));
239
249
  });
240
- this.onUpdateHeight = n, this.onUpdateActiveTool = a, this.height = i, this.uploadImageToS3 = o, this.userId = l, this.canvasId = h, this.publish = t, this.userType = c, this.renderAs = p, this.debouncedViewportChange = v(this.onViewPortChange, 300), e == null || e(this.canvasId, this.update);
250
+ this.onUpdateHeight = i, this.onUpdateActiveTool = a, this.height = n, this.uploadImageToS3 = o, this.userId = h, this.canvasId = r, this.publish = t, this.userType = l, this.renderAs = p, this.debouncedViewportChange = f(this.onViewPortChange, 300), this.updateCanvasConfigChange = d, e == null || e(this.canvasId, this.update);
241
251
  }
242
- async create({ canvasElementRef: t, canvasConfig: e, canvasSetting: a, initialData: n }) {
252
+ async create({ canvasElementRef: t, canvasConfig: e, canvasSetting: a, initialData: i }) {
243
253
  if (!t.current)
244
254
  throw new Error("PolyCanvas: Div Element Not found for canvas");
245
255
  this.polycanvas = await window.Polypad.create(t.current, {
@@ -247,11 +257,11 @@ class b {
247
257
  options: e
248
258
  },
249
259
  ...a,
250
- imageUpload: this.renderAs === "whiteboard" && this.userType === "TEACHER" ? this.uploadFileToCanvas : void 0
251
- }), this.renderAs === "whiteboard" && this.userType === "TEACHER" && (this.polycanvas.toggleSidebar(!1), f(t), this.polycanvas.on("viewport", this.debouncedViewportChange)), g(t), this.polycanvas.on("change", this.onChange), n && this.update(n);
260
+ imageUpload: this.renderAs === "whiteboard" && this.userType === "TEACHER" && this.uploadImageToS3 ? this.uploadImageToS3 : void 0
261
+ }), this.renderAs === "whiteboard" && this.userType === "TEACHER" && (this.polycanvas.toggleSidebar(!1), this.polycanvas.bindKeyboardEvents({}), y(t), this.polycanvas.on("viewport", this.debouncedViewportChange)), C(t), this.polycanvas.on("change", this.onChange), i && this.update(i);
252
262
  }
253
263
  }
254
264
  export {
255
- b as CueCanvasCore
265
+ E as CueCanvasCore
256
266
  };
257
267
  //# sourceMappingURL=cue-canvas-core.js.map