lido-player 0.0.2-alpha-50 → 0.0.2-alpha-50-dev

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 (160) hide show
  1. package/dist/cjs/{index-fe562525.js → index-6a69c33a.js} +36 -3
  2. package/dist/cjs/index.cjs.js +2 -2
  3. package/dist/cjs/{lido-avatar_19.cjs.entry.js → lido-avatar_21.cjs.entry.js} +433 -182
  4. package/dist/cjs/lido-player.cjs.js +2 -2
  5. package/dist/cjs/loader.cjs.js +2 -2
  6. package/dist/cjs/{utils-c3e7cbcc.js → utils-079a5e7d.js} +1033 -169
  7. package/dist/collection/collection-manifest.json +2 -0
  8. package/dist/collection/components/calculator/lido-calculator.css +87 -0
  9. package/dist/collection/components/calculator/lido-calculator.js +321 -0
  10. package/dist/collection/components/cell/lido-cell.js +1 -1
  11. package/dist/collection/components/column/lido-col.js +1 -1
  12. package/dist/collection/components/container/lido-container.js +20 -2
  13. package/dist/collection/components/flashCard/lido-flash-card.js +1 -1
  14. package/dist/collection/components/float/lido-float.js +1 -1
  15. package/dist/collection/components/home/lido-home.css +0 -4
  16. package/dist/collection/components/home/lido-home.js +10 -29
  17. package/dist/collection/components/keyboard/lido-keyboard.js +2 -2
  18. package/dist/collection/components/mathMatrix/lido-math-matrix.css +10 -2
  19. package/dist/collection/components/mathMatrix/lido-math-matrix.js +226 -20
  20. package/dist/collection/components/position/lido-pos.js +1 -1
  21. package/dist/collection/components/random/lido-random.js +1 -1
  22. package/dist/collection/components/row/lido-row.js +1 -1
  23. package/dist/collection/components/scale/lido-balance.css +114 -0
  24. package/dist/collection/components/scale/lido-balance.js +549 -0
  25. package/dist/collection/components/shape/lido-shape.js +1 -1
  26. package/dist/collection/components/slideFill/lido-slide-fill.js +1 -1
  27. package/dist/collection/components/text/lido-text.js +1 -1
  28. package/dist/collection/components/trace/lido-trace.js +49 -128
  29. package/dist/collection/components/wrap/lido-wrap.js +1 -1
  30. package/dist/collection/css/animation.css +21 -0
  31. package/dist/collection/css/index.css +45 -0
  32. package/dist/collection/stories/Templates/Fill-Up/fill-up.stories.js +24 -25
  33. package/dist/collection/stories/Templates/RocketGame/rocketGame.stories.js +0 -3
  34. package/dist/collection/stories/Templates/balancing/balancing.stories.js +67 -0
  35. package/dist/collection/stories/Templates/checker-block/checkerBlock.stories.js +156 -0
  36. package/dist/collection/stories/Templates/checkerBlock/checkerBlock.stories.js +49 -0
  37. package/dist/collection/stories/Templates/fillAnswer/fill-answer.stories.js +66 -0
  38. package/dist/collection/stories/Templates/foodJar/food-jar.stories.js +65 -0
  39. package/dist/collection/stories/Templates/matchBox/matchBox.stories.js +105 -0
  40. package/dist/collection/stories/Templates/matchBox/matchBox2.stories.js +92 -0
  41. package/dist/collection/stories/Templates/matchingCard/matching-card.stories.js +47 -0
  42. package/dist/collection/stories/Templates/multiplyBeeds/multiplyBeeds.stories.js +59 -0
  43. package/dist/collection/stories/Templates/nimbleTable/nimbleTable.stories.js +93 -0
  44. package/dist/collection/stories/Templates/numberBoardTwo/numberBoardTwo.stories.js +100 -0
  45. package/dist/collection/stories/Templates/numberPair/numberPair.stories.js +212 -0
  46. package/dist/collection/stories/Templates/order-tractor/order-tractor-ascending-order.stories.js +6 -7
  47. package/dist/collection/stories/Templates/order-tractor/order-tractor.stories.js +6 -7
  48. package/dist/collection/stories/Templates/questionBoard/questionBoard.stories.js +158 -0
  49. package/dist/collection/stories/Templates/sequenceBox/sequenceBox1.stories.js +102 -0
  50. package/dist/collection/stories/Templates/sequenceBox/sequenceBox2.stories.js +94 -0
  51. package/dist/collection/stories/Templates/shapePair/shape-pair.stories.js +184 -0
  52. package/dist/collection/stories/Templates/shapeTractor/shape-tractor.stories.js +213 -0
  53. package/dist/collection/stories/Templates/sumTogether/sumTogether.stories.js +109 -0
  54. package/dist/collection/stories/Templates/total/total.stories.js +59 -0
  55. package/dist/collection/stories/Templates/writeNumber/writeNumber.stories.js +96 -0
  56. package/dist/collection/stories/Templates/writeSet/writeSet.stories.js +55 -0
  57. package/dist/collection/stories/Templates/writeWord/writeWord.stories.js +5 -6
  58. package/dist/collection/utils/utils.js +440 -84
  59. package/dist/collection/utils/utilsHandlers/clickHandler.js +21 -26
  60. package/dist/collection/utils/utilsHandlers/dragDropHandler.js +95 -42
  61. package/dist/collection/utils/utilsHandlers/lidoBalanceHandler.js +67 -0
  62. package/dist/collection/utils/utilsHandlers/lidoCalculatorHandler.js +94 -0
  63. package/dist/collection/utils/utilsHandlers/matrixHandler.js +298 -0
  64. package/dist/collection/utils/utilsHandlers/slideHandler.js +4 -2
  65. package/dist/collection/utils/utilsHandlers/sortHandler.js +21 -12
  66. package/dist/components/index.js +1 -1
  67. package/dist/components/lido-avatar.js +1 -1
  68. package/dist/components/lido-balance.d.ts +11 -0
  69. package/dist/components/lido-balance.js +6 -0
  70. package/dist/components/lido-calculator.d.ts +11 -0
  71. package/dist/components/lido-calculator.js +6 -0
  72. package/dist/components/lido-cell.js +1 -1
  73. package/dist/components/lido-col.js +1 -1
  74. package/dist/components/lido-container.js +1 -1
  75. package/dist/components/lido-flash-card.js +1 -1
  76. package/dist/components/lido-float.js +1 -1
  77. package/dist/components/lido-home.js +1 -1
  78. package/dist/components/lido-image.js +1 -1
  79. package/dist/components/lido-keyboard.js +1 -1
  80. package/dist/components/lido-math-matrix.js +1 -1
  81. package/dist/components/lido-pos.js +1 -1
  82. package/dist/components/lido-random.js +1 -1
  83. package/dist/components/lido-root.js +32 -20
  84. package/dist/components/lido-row.js +1 -1
  85. package/dist/components/lido-shape.js +1 -1
  86. package/dist/components/lido-slide-fill.js +1 -1
  87. package/dist/components/lido-text.js +1 -1
  88. package/dist/components/lido-trace.js +1 -1
  89. package/dist/components/lido-wrap.js +1 -1
  90. package/dist/components/p-08d0deab.js +254 -0
  91. package/dist/components/{p-7fc73a13.js → p-15971ede.js} +1 -1
  92. package/dist/components/{p-1cb590fb.js → p-1fbdb431.js} +2 -2
  93. package/dist/components/{p-b2d7b151.js → p-29bdd953.js} +2 -2
  94. package/dist/components/{p-20ffe2e9.js → p-322acda6.js} +42 -49
  95. package/dist/components/{p-d489f16f.js → p-3f406017.js} +2 -2
  96. package/dist/components/p-44808985.js +186 -0
  97. package/dist/components/{p-6917debf.js → p-52844fa4.js} +2 -2
  98. package/dist/components/{p-ababe351.js → p-73e31a86.js} +2 -2
  99. package/dist/components/{p-513a03e1.js → p-74849cdd.js} +4 -4
  100. package/dist/components/{p-6c98fc03.js → p-7f7e5672.js} +2 -2
  101. package/dist/components/{p-76423463.js → p-835b973d.js} +2 -2
  102. package/dist/components/{p-3d732e48.js → p-90465904.js} +50 -129
  103. package/dist/components/{p-6405d878.js → p-904711c8.js} +2 -2
  104. package/dist/components/{p-926348de.js → p-9be56729.js} +5 -4
  105. package/dist/components/{p-b83c7a68.js → p-afbc196f.js} +2 -2
  106. package/dist/components/{p-135e98bf.js → p-bed94c37.js} +1048 -168
  107. package/dist/components/{p-33588c7a.js → p-cbac3cbc.js} +1 -1
  108. package/dist/components/{p-a9689087.js → p-d37ab4dc.js} +2 -2
  109. package/dist/components/p-e36ddcc1.js +166 -0
  110. package/dist/components/{p-868beaa6.js → p-e4e42677.js} +2 -2
  111. package/dist/esm/{index-f47852d4.js → index-170e58c7.js} +36 -4
  112. package/dist/esm/index.js +2 -2
  113. package/dist/esm/{lido-avatar_19.entry.js → lido-avatar_21.entry.js} +432 -183
  114. package/dist/esm/lido-player.js +3 -3
  115. package/dist/esm/loader.js +3 -3
  116. package/dist/esm/{utils-99110070.js → utils-5df09162.js} +1032 -168
  117. package/dist/lido-player/index.esm.js +1 -1
  118. package/dist/lido-player/lido-player.css +1 -1
  119. package/dist/lido-player/lido-player.esm.js +1 -1
  120. package/dist/lido-player/p-137c99ce.js +2 -0
  121. package/dist/lido-player/p-7556e652.js +9 -0
  122. package/dist/lido-player/p-eb956325.entry.js +1 -0
  123. package/dist/types/components/calculator/lido-calculator.d.ts +40 -0
  124. package/dist/types/components/container/lido-container.d.ts +4 -0
  125. package/dist/types/components/home/lido-home.d.ts +0 -1
  126. package/dist/types/components/mathMatrix/lido-math-matrix.d.ts +24 -4
  127. package/dist/types/components/scale/lido-balance.d.ts +160 -0
  128. package/dist/types/components/trace/lido-trace.d.ts +0 -1
  129. package/dist/types/components.d.ts +342 -14
  130. package/dist/types/stories/Templates/balancing/balancing.stories.d.ts +4 -0
  131. package/dist/types/stories/Templates/checker-block/checkerBlock.stories.d.ts +4 -0
  132. package/dist/types/stories/Templates/checkerBlock/checkerBlock.stories.d.ts +4 -0
  133. package/dist/types/stories/Templates/fillAnswer/fill-answer.stories.d.ts +4 -0
  134. package/dist/types/stories/Templates/foodJar/food-jar.stories.d.ts +4 -0
  135. package/dist/types/stories/Templates/matchBox/matchBox.stories.d.ts +4 -0
  136. package/dist/types/stories/Templates/matchBox/matchBox2.stories.d.ts +4 -0
  137. package/dist/types/stories/Templates/matchingCard/matching-card.stories.d.ts +4 -0
  138. package/dist/types/stories/Templates/multiplyBeeds/multiplyBeeds.stories.d.ts +9 -0
  139. package/dist/types/stories/Templates/nimbleTable/nimbleTable.stories.d.ts +4 -0
  140. package/dist/types/stories/Templates/numberBoardTwo/numberBoardTwo.stories.d.ts +4 -0
  141. package/dist/types/stories/Templates/numberPair/numberPair.stories.d.ts +4 -0
  142. package/dist/types/stories/Templates/questionBoard/questionBoard.stories.d.ts +15 -0
  143. package/dist/types/stories/Templates/sequenceBox/sequenceBox1.stories.d.ts +11 -0
  144. package/dist/types/stories/Templates/sequenceBox/sequenceBox2.stories.d.ts +11 -0
  145. package/dist/types/stories/Templates/shapePair/shape-pair.stories.d.ts +4 -0
  146. package/dist/types/stories/Templates/shapeTractor/shape-tractor.stories.d.ts +12 -0
  147. package/dist/types/stories/Templates/sumTogether/sumTogether.stories.d.ts +11 -0
  148. package/dist/types/stories/Templates/total/total.stories.d.ts +4 -0
  149. package/dist/types/stories/Templates/writeNumber/writeNumber.stories.d.ts +13 -0
  150. package/dist/types/stories/Templates/writeSet/writeSet.stories.d.ts +4 -0
  151. package/dist/types/utils/utils.d.ts +8 -2
  152. package/dist/types/utils/utilsHandlers/dragDropHandler.d.ts +4 -0
  153. package/dist/types/utils/utilsHandlers/lidoBalanceHandler.d.ts +2 -0
  154. package/dist/types/utils/utilsHandlers/lidoCalculatorHandler.d.ts +1 -0
  155. package/dist/types/utils/utilsHandlers/matrixHandler.d.ts +1 -0
  156. package/package.json +1 -1
  157. package/dist/components/p-58b69b3f.js +0 -160
  158. package/dist/lido-player/p-b83634bf.entry.js +0 -1
  159. package/dist/lido-player/p-c8c00dcb.js +0 -9
  160. package/dist/lido-player/p-ddf627b0.js +0 -2
@@ -1,4 +1,4 @@
1
- import { ActivityScoreKey, DragSelectedMapKey, DragMapKey, SelectedValuesKey, DropMode, DropToAttr, DropTimeAttr, LidoContainer, DropAction, DropHasDrag, DropLength, } from "./constants";
1
+ import { ActivityScoreKey, DragMapKey, SelectedValuesKey, DropMode, DropToAttr, DropTimeAttr, LidoContainer, DropAction, } from "./constants";
2
2
  import { dispatchActivityEndEvent, dispatchLessonEndEvent, dispatchNextContainerEvent, dispatchPrevContainerEvent } from "./customEvents";
3
3
  import GameScore from "./constants";
4
4
  import { RiveService } from "./rive-service";
@@ -11,7 +11,43 @@ import { addClickListenerForClickType, onTouchListenerForOnTouch } from "./utils
11
11
  import { evaluate, isArray } from "mathjs";
12
12
  import { fillSlideHandle } from "./utilsHandlers/floatHandler";
13
13
  import { stopHighlightForSpeakingElement } from "./utilsHandlers/highlightHandler";
14
+ import { handleSolvedEquationSubmissionAndScoreUpdate } from "./utilsHandlers/lidoCalculatorHandler";
15
+ import { handlingMatrix } from "./utilsHandlers/matrixHandler";
16
+ import { balanceResult } from "./utilsHandlers/lidoBalanceHandler";
14
17
  const gameScore = new GameScore();
18
+ export function buildDragSelectedMapFromDOM() {
19
+ const map = {};
20
+ const draggedEls = document.querySelectorAll(`[${DropToAttr}]`);
21
+ draggedEls.forEach(dragEl => {
22
+ var _a, _b, _c;
23
+ const to = dragEl.getAttribute(DropToAttr);
24
+ if (!to)
25
+ return;
26
+ const dropEl = document.getElementById(to);
27
+ if (!dropEl)
28
+ return;
29
+ const tabIndex = (_a = dropEl.getAttribute('tab-index')) !== null && _a !== void 0 ? _a : to;
30
+ if (!map[tabIndex])
31
+ map[tabIndex] = [];
32
+ const value = (_c = (_b = dragEl.getAttribute('value')) !== null && _b !== void 0 ? _b : dragEl.value) !== null && _c !== void 0 ? _c : '';
33
+ map[tabIndex].push(value);
34
+ });
35
+ return map;
36
+ }
37
+ export function getSortedValuesArrayFromMap(map) {
38
+ const sortedKeys = Object.keys(map).sort((a, b) => parseInt(a) - parseInt(b));
39
+ const sortedValues = sortedKeys.reduce((acc, key) => {
40
+ const values = map[key];
41
+ if (values.length > 1) {
42
+ acc.push(`(${values.join('|')})`);
43
+ }
44
+ else {
45
+ acc.push(values[0]);
46
+ }
47
+ return acc;
48
+ }, []);
49
+ return sortedValues;
50
+ }
15
51
  export function format(first, middle, last) {
16
52
  return (first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '');
17
53
  }
@@ -56,6 +92,10 @@ export const initEventsForElement = async (element, type) => {
56
92
  enableOptionArea(element);
57
93
  break;
58
94
  }
95
+ case 'checkerBlock': {
96
+ handlingMatrix(element);
97
+ break;
98
+ }
59
99
  default:
60
100
  break;
61
101
  }
@@ -63,9 +103,8 @@ export const initEventsForElement = async (element, type) => {
63
103
  };
64
104
  // Function to execute actions parsed from the onMatch string
65
105
  export const executeActions = async (actionsString, thisElement, element) => {
66
- var _a;
106
+ var _a, _b, _c, _d, _e, _f, _g;
67
107
  const actions = parseActions(actionsString);
68
- body.style.pointerEvents = 'none';
69
108
  for (let i = 0; i < actions.length; i++) {
70
109
  const action = actions[i];
71
110
  const queriedElement = document.querySelector(action.actor);
@@ -78,13 +117,25 @@ export const executeActions = async (actionsString, thisElement, element) => {
78
117
  targetElement.style.transform = currentTransform !== 'none' ? `${currentTransform} ${action.value}` : action.value;
79
118
  break;
80
119
  }
120
+ case 'revealImageValue': {
121
+ if (targetElement) {
122
+ revealImageValue(targetElement); // call your function here
123
+ }
124
+ break;
125
+ }
126
+ case 'scrollCellAfterEquationSolved': {
127
+ if (targetElement) {
128
+ handleSolvedEquationSubmissionAndScoreUpdate();
129
+ }
130
+ break;
131
+ }
81
132
  case 'alignMatch': {
82
133
  const dropElement = targetElement;
83
134
  const dragElement = element;
84
135
  const container = document.getElementById(LidoContainer);
85
136
  const containerScale = getElementScale(container);
86
137
  dragElement.style.transform = 'translate(0,0)';
87
- console.log('logg alinmatch');
138
+ console.log("logg alinmatch");
88
139
  const dropRect = dropElement.getBoundingClientRect();
89
140
  const dragRect = dragElement.getBoundingClientRect();
90
141
  const dropCenterX = dropRect.left + dropRect.width / 2;
@@ -130,7 +181,7 @@ export const executeActions = async (actionsString, thisElement, element) => {
130
181
  if (container.getAttribute('is-continue-on-correct') !== 'true') {
131
182
  targetElement.style.pointerEvents = 'none';
132
183
  }
133
- await validateObjectiveStatus();
184
+ validateObjectiveStatus();
134
185
  break;
135
186
  }
136
187
  case 'prevBtn': {
@@ -170,10 +221,76 @@ export const executeActions = async (actionsString, thisElement, element) => {
170
221
  }
171
222
  break;
172
223
  }
224
+ case 'highlightStarsAndDisapper': {
225
+ const value = action.value;
226
+ if (value && targetElement) {
227
+ console.log('highlightStar action triggered');
228
+ console.log('Target Element:', targetElement);
229
+ await HighlightStarsOneByOne(targetElement, value);
230
+ }
231
+ break;
232
+ }
233
+ case 'boxAnimationOneByOne': {
234
+ const value = action.value;
235
+ if (value && targetElement) {
236
+ await animateBoxCells(targetElement, value);
237
+ }
238
+ break;
239
+ }
240
+ case 'questionBoxAnimate': {
241
+ const value = action.value;
242
+ if (value && targetElement) {
243
+ await questionBoxAnimation(targetElement, value);
244
+ }
245
+ break;
246
+ }
173
247
  case 'slideAnimation': {
174
248
  slideAnimation();
175
249
  break;
176
250
  }
251
+ case 'showBalanceSymbol': {
252
+ const balanceEl = document.querySelector('lido-balance');
253
+ if (!balanceEl)
254
+ break;
255
+ const leftVal = Number((_b = balanceEl.leftVal) !== null && _b !== void 0 ? _b : Number((_d = (_c = balanceEl.dataset) === null || _c === void 0 ? void 0 : _c.leftVal) !== null && _d !== void 0 ? _d : 0));
256
+ const rightVal = Number((_e = balanceEl.rightVal) !== null && _e !== void 0 ? _e : Number((_g = (_f = balanceEl.dataset) === null || _f === void 0 ? void 0 : _f.rightVal) !== null && _g !== void 0 ? _g : 0));
257
+ const symbol = leftVal > rightVal ? '>' : leftVal < rightVal ? '<' : '=';
258
+ balanceEl.balanceSymbol = symbol;
259
+ balanceEl.dataset.balanceSymbol = symbol;
260
+ if (balanceEl.revealSymbol) {
261
+ await balanceEl.revealSymbol();
262
+ }
263
+ else {
264
+ balanceEl.showSymbol = true;
265
+ }
266
+ break;
267
+ }
268
+ case 'hideBalanceSymbol': {
269
+ const balanceEl = document.querySelector('lido-balance');
270
+ if (!balanceEl)
271
+ break;
272
+ if (balanceEl.hideSymbol) {
273
+ await balanceEl.hideSymbol();
274
+ }
275
+ else {
276
+ balanceEl.showSymbol = false;
277
+ }
278
+ break;
279
+ }
280
+ case 'sumTogetherAnimation': {
281
+ const value = action.value;
282
+ if (value) {
283
+ SumTogetherAnimation(targetElement, value);
284
+ }
285
+ break;
286
+ }
287
+ case 'addText': {
288
+ const value = action.value;
289
+ if (value) {
290
+ targetElement.textContent += value;
291
+ }
292
+ break;
293
+ }
177
294
  default: {
178
295
  targetElement.style[action.action] = action.value;
179
296
  break;
@@ -181,7 +298,6 @@ export const executeActions = async (actionsString, thisElement, element) => {
181
298
  }
182
299
  }
183
300
  }
184
- body.style.pointerEvents = 'auto';
185
301
  };
186
302
  const afterDropDragHandling = (dragElement, dropElement) => {
187
303
  const container = document.getElementById(LidoContainer);
@@ -272,6 +388,9 @@ export const matchStringPattern = (pattern, arr) => {
272
388
  const patternGroups = pattern.split(',').map(group => group.trim());
273
389
  let arrIndex = 0;
274
390
  let options = new Set();
391
+ if (patternGroups.length == 0) { // If pattern is empty
392
+ return true;
393
+ }
275
394
  if (patternGroups.length > 0) {
276
395
  if (arr.length === 0)
277
396
  return false; // If pattern is not empty but user provided array is empty, return false
@@ -356,20 +475,29 @@ export const calculateScore = () => {
356
475
  gameScore.wrongMoves = 0;
357
476
  };
358
477
  export async function onActivityComplete(dragElement, dropElement) {
359
- var _a, _b;
478
+ var _a;
360
479
  const container = document.getElementById(LidoContainer);
361
480
  if (!container)
362
481
  return;
363
482
  await executeActions("this.alignMatch='true'", dropElement, dragElement);
364
- let dragScore = JSON.parse((_a = localStorage.getItem(DragSelectedMapKey)) !== null && _a !== void 0 ? _a : '{}');
365
- const tabindex = dropElement.getAttribute('tab-index');
366
- if (!dragScore[tabindex]) {
367
- dragScore[tabindex] = [];
483
+ if (dragElement && dropElement) {
484
+ const isCorrect = dropElement['value'].toLowerCase().includes(dragElement['value'].toLowerCase());
485
+ if (isCorrect) {
486
+ const onCorrect = dropElement.getAttribute('onCorrect');
487
+ if (onCorrect) {
488
+ await executeActions(onCorrect, dropElement, dragElement);
489
+ }
490
+ }
491
+ else {
492
+ const onInCorrect = dropElement.getAttribute('onInCorrect');
493
+ await executeActions(onInCorrect, dropElement, dragElement);
494
+ }
368
495
  }
369
- dragScore[tabindex].push(dragElement['value']);
370
- localStorage.setItem(DragSelectedMapKey, JSON.stringify(dragScore));
496
+ let dragScore = buildDragSelectedMapFromDOM();
497
+ const sortedValues = getSortedValuesArrayFromMap(dragScore);
498
+ container.setAttribute(SelectedValuesKey, JSON.stringify(sortedValues));
371
499
  //localStorage
372
- let drag = JSON.parse((_b = localStorage.getItem(DragMapKey)) !== null && _b !== void 0 ? _b : '{}');
500
+ let drag = JSON.parse((_a = localStorage.getItem(DragMapKey)) !== null && _a !== void 0 ? _a : '{}');
373
501
  const index = dropElement.getAttribute('tab-index');
374
502
  if (!drag[index]) {
375
503
  drag[index] = [];
@@ -377,17 +505,6 @@ export async function onActivityComplete(dragElement, dropElement) {
377
505
  drag[index].push(dragElement.id);
378
506
  // localStorage.setItem(DragMapKey, JSON.stringify(drag));
379
507
  const sortedKeys = Object.keys(dragScore).sort((a, b) => parseInt(a) - parseInt(b));
380
- const sortedValues = sortedKeys.reduce((acc, key) => {
381
- const values = dragScore[key];
382
- if (values.length > 1) {
383
- acc.push(`(${values.join('|')})`);
384
- }
385
- else {
386
- acc.push(values[0]);
387
- }
388
- return acc;
389
- }, []);
390
- localStorage.setItem(SelectedValuesKey, JSON.stringify(sortedValues));
391
508
  if (dragElement && dropElement) {
392
509
  const isCorrect = dropElement['value'].toLowerCase().includes(dragElement['value'].toLowerCase());
393
510
  if (isCorrect) {
@@ -404,8 +521,7 @@ export async function onActivityComplete(dragElement, dropElement) {
404
521
  const allElements = document.querySelectorAll("[type='drop']");
405
522
  allElements.forEach(otherElement => {
406
523
  var _a;
407
- const dropObject = JSON.parse(localStorage.getItem(DragSelectedMapKey)) || {};
408
- const storedTabIndexes = Object.keys(dropObject).map(Number);
524
+ const storedTabIndexes = Object.keys(dragScore).map(Number);
409
525
  if (storedTabIndexes.includes(JSON.parse(otherElement.getAttribute('tab-index')))) {
410
526
  if (!(((_a = otherElement.getAttribute('dropAttr')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === DropMode.Diagonal)) {
411
527
  if (otherElement.tagName.toLowerCase() === 'lido-text') {
@@ -457,77 +573,97 @@ export const handleShowCheck = () => {
457
573
  var _a, _b;
458
574
  const container = document.getElementById(LidoContainer);
459
575
  const objectiveString = container['objective'];
460
- const selectValues = (_a = localStorage.getItem(SelectedValuesKey)) !== null && _a !== void 0 ? _a : '';
576
+ const selectValues = (_a = container.getAttribute(SelectedValuesKey)) !== null && _a !== void 0 ? _a : '';
461
577
  const checkButton = document.querySelector('#lido-checkButton');
462
- if (!selectValues || countPatternWords(selectValues) !== countPatternWords(objectiveString)) {
578
+ if (!selectValues || countPatternWords(selectValues) < countPatternWords(objectiveString)) {
463
579
  executeActions("this.addClass='lido-disable-check-button'", checkButton);
464
580
  return;
465
581
  }
466
582
  const showCheck = container.getAttribute('show-check') == 'true';
467
583
  if (showCheck) {
468
584
  (_b = checkButton === null || checkButton === void 0 ? void 0 : checkButton.classList) === null || _b === void 0 ? void 0 : _b.remove('lido-disable-check-button');
585
+ const balanceEl = document.querySelector('lido-balance');
586
+ if (balanceEl) {
587
+ if (!checkButton.hasAttribute('data-balance-listener')) {
588
+ checkButton.addEventListener('click', async function onClick() {
589
+ if (balanceResult && res) {
590
+ await executeActions("this.showBalanceSymbol='true'", checkButton);
591
+ checkButton.removeEventListener('click', onClick);
592
+ }
593
+ });
594
+ checkButton.setAttribute('data-balance-listener', 'true');
595
+ }
596
+ }
469
597
  }
470
598
  else {
471
599
  validateObjectiveStatus();
472
600
  }
473
601
  };
474
- const body = document.body;
602
+ let res;
475
603
  export const validateObjectiveStatus = async () => {
476
- var _a;
604
+ var _a, _b;
477
605
  const container = document.getElementById(LidoContainer);
478
606
  if (!container)
479
607
  return;
480
608
  const objectiveString = container['objective'];
609
+ const additionalCheck = container.getAttribute('equationCheck');
610
+ console.log('🚀 ~ validateObjectiveStatus ~ additionalCheck:', additionalCheck);
611
+ let equationGiven = false;
481
612
  if (objectiveString == null || objectiveString.length === 0) {
482
- body.style.pointerEvents = 'none';
483
- const onCorrect = container.getAttribute('onCorrect');
484
- if (onCorrect) {
485
- await executeActions(onCorrect, container);
613
+ if (additionalCheck) {
614
+ equationGiven = true;
615
+ }
616
+ if (!equationGiven) {
617
+ const onCorrect = container.getAttribute('onCorrect');
618
+ if (onCorrect) {
619
+ await executeActions(onCorrect, container);
620
+ }
621
+ storeActivityScore(100);
622
+ storingEachActivityScore(true);
623
+ triggerNextContainer();
624
+ return;
486
625
  }
487
- storeActivityScore(100);
488
- storingEachActivityScore(true);
489
- triggerNextContainer();
490
- return;
491
626
  }
492
- else {
493
- const objectiveArray = (_a = JSON.parse(localStorage.getItem(SelectedValuesKey))) !== null && _a !== void 0 ? _a : [];
494
- let res;
495
- const additionalCheck = container.getAttribute('equationCheck');
496
- if (!!additionalCheck) {
627
+ const objectiveArray = (_b = JSON.parse((_a = container.getAttribute(SelectedValuesKey)) !== null && _a !== void 0 ? _a : '[]')) !== null && _b !== void 0 ? _b : [];
628
+ if (!!additionalCheck) {
629
+ const balanceEl = document.querySelector('lido-balance');
630
+ if (!balanceEl) {
497
631
  res = equationCheck(additionalCheck);
498
- console.log('🚀 ~ handleShowCheck ~ res:', res);
499
632
  }
500
633
  else {
501
- res = matchStringPattern(objectiveString, objectiveArray);
634
+ res = balanceResult(container, objectiveString);
502
635
  }
503
- if (res) {
504
- const attach = container.getAttribute('appendToDropOnCompletion');
505
- body.style.pointerEvents = 'none';
506
- const onCorrect = container.getAttribute('onCorrect');
507
- if (onCorrect) {
508
- if (attach === 'true') {
509
- appendingDragElementsInDrop();
510
- }
511
- await executeActions(onCorrect, container);
512
- }
513
- if (container.getAttribute('dropAttr') === 'EnableAnimation') {
514
- setTimeout(() => {
515
- triggerNextContainer();
516
- }, 2000);
636
+ console.log('🚀 ~ handleShowCheck ~ res:', res);
637
+ }
638
+ else {
639
+ res = matchStringPattern(objectiveString, objectiveArray);
640
+ }
641
+ if (res) {
642
+ const attach = container.getAttribute('appendToDropOnCompletion');
643
+ const onCorrect = container.getAttribute('onCorrect');
644
+ if (onCorrect) {
645
+ if (attach === 'true') {
646
+ appendingDragElementsInDrop();
517
647
  }
518
- else {
648
+ await executeActions(onCorrect, container);
649
+ }
650
+ if (container.getAttribute('dropAttr') === 'EnableAnimation') {
651
+ setTimeout(() => {
519
652
  triggerNextContainer();
520
- }
521
- await calculateScore();
653
+ }, 2000);
522
654
  }
523
655
  else {
524
- const onInCorrect = container.getAttribute('onInCorrect');
525
- await executeActions(onInCorrect, container);
526
- const isContinueOnCorrect = container.getAttribute('is-continue-on-correct') === 'true';
527
- if (!isContinueOnCorrect) {
528
- triggerNextContainer();
529
- await calculateScore();
530
- }
656
+ triggerNextContainer();
657
+ }
658
+ await calculateScore();
659
+ }
660
+ else {
661
+ const onInCorrect = container.getAttribute('onInCorrect');
662
+ await executeActions(onInCorrect, container);
663
+ const isContinueOnCorrect = container.getAttribute('is-continue-on-correct') === 'true';
664
+ if (!isContinueOnCorrect) {
665
+ triggerNextContainer();
666
+ await calculateScore();
531
667
  }
532
668
  }
533
669
  };
@@ -546,16 +682,16 @@ export const triggerPrevcontainer = () => {
546
682
  export function convertUrlToRelative(url) {
547
683
  const container = document.getElementById(LidoContainer);
548
684
  const baseUrl = container.getAttribute('baseUrl');
549
- if ((url === null || url === void 0 ? void 0 : url.startsWith('http')) || (url === null || url === void 0 ? void 0 : url.startsWith('blob')) || (url === null || url === void 0 ? void 0 : url.startsWith('data'))) {
685
+ if ((url === null || url === void 0 ? void 0 : url.startsWith('http')) || (url === null || url === void 0 ? void 0 : url.startsWith('blob'))) {
550
686
  return url;
551
687
  }
552
- if (baseUrl) {
553
- const newUrl = url.startsWith('/') ? url.slice(1) : url;
554
- if (newUrl.startsWith(baseUrl.replace(/^\/+|\/+$/g, '')))
555
- return newUrl;
556
- return baseUrl.endsWith('/') ? baseUrl + newUrl : `${baseUrl}/${newUrl}`;
688
+ else if (baseUrl) {
689
+ const newUrl = !url.startsWith('/') ? url : url.substring(1);
690
+ return baseUrl + (baseUrl.endsWith('/') ? newUrl : '/' + newUrl);
691
+ }
692
+ else {
693
+ return getAssetPath(url);
557
694
  }
558
- return getAssetPath(url);
559
695
  }
560
696
  /**
561
697
  * Asynchronously speaks the given text using the browser's text-to-speech API.
@@ -744,7 +880,10 @@ export const equationCheck = (additionalCheck) => {
744
880
  });
745
881
  // 3. Join the modified parts back into one string
746
882
  const resultString = modifiedParts.join('');
883
+ console.log('🚀 ~ equationCheck ~ resultString:', resultString);
884
+ // 4. Evaluate the final string as a mathematical expression
747
885
  const finalRes = evaluate(resultString);
886
+ console.log('🚀 ~ equationCheck ~ finalRes:', finalRes);
748
887
  return finalRes;
749
888
  };
750
889
  const getElementsForQueries = (query) => {
@@ -813,13 +952,6 @@ export const attachSpeakIcon = async (element) => {
813
952
  }
814
953
  element.appendChild(speakIconElement);
815
954
  };
816
- export const clearLocalStorage = () => {
817
- localStorage.removeItem(DragSelectedMapKey);
818
- localStorage.removeItem(DragMapKey);
819
- localStorage.removeItem(SelectedValuesKey);
820
- localStorage.removeItem(DropHasDrag);
821
- localStorage.removeItem(DropLength);
822
- };
823
955
  /**
824
956
  * Applies a delay to the element's visibility based on `delayVisible`.
825
957
  */
@@ -905,3 +1037,227 @@ export function generateUUIDFallback() {
905
1037
  return v.toString(16);
906
1038
  });
907
1039
  }
1040
+ export const revealImageValue = (imageEl) => {
1041
+ if (!imageEl)
1042
+ return;
1043
+ const value = imageEl.getAttribute('value');
1044
+ if (!value)
1045
+ return;
1046
+ let valueElement = imageEl.querySelector('.lido-display-hiddenvalue');
1047
+ if (!valueElement) {
1048
+ valueElement = document.createElement('div');
1049
+ valueElement.classList.add('lido-display-hiddenvalue');
1050
+ imageEl.style.position = 'relative';
1051
+ imageEl.appendChild(valueElement);
1052
+ }
1053
+ valueElement.innerText = value;
1054
+ };
1055
+ const setImageBackground = (el, color) => {
1056
+ if (!el)
1057
+ return;
1058
+ el.classList.add('lido-image-colorize');
1059
+ const img = el.querySelector('img');
1060
+ if (img) {
1061
+ // use same image as mask
1062
+ el.style.setProperty('--mask-url', `url(${img.src})`);
1063
+ }
1064
+ if (color === 'red') {
1065
+ el.style.setProperty('--tint-color', '#ff0000');
1066
+ }
1067
+ else if (color === 'green') {
1068
+ el.style.setProperty('--tint-color', '#00c853');
1069
+ }
1070
+ else {
1071
+ el.style.removeProperty('--tint-color');
1072
+ el.style.removeProperty('--mask-url');
1073
+ }
1074
+ };
1075
+ export const HighlightStarsOneByOne = async (element, value) => {
1076
+ if (!element)
1077
+ return;
1078
+ if (!value)
1079
+ return;
1080
+ // Dynamically find the parent row of stars
1081
+ const stars = Array.from(element.children);
1082
+ console.log('starRow', stars);
1083
+ for (const star of stars) {
1084
+ // Highlight the star
1085
+ star.classList.add('lido-glow');
1086
+ // Play star sound
1087
+ await AudioPlayer.getI().play(star);
1088
+ // Fade out the star (disappear)
1089
+ star.style.opacity = '0';
1090
+ star.style.visibility = 'hidden';
1091
+ await new Promise(resolve => setTimeout(resolve, 300)); // Wait for fade-out to complete
1092
+ // Remove the highlight
1093
+ star.classList.remove('lido-glow');
1094
+ }
1095
+ };
1096
+ export const animateBoxCells = async (element, value) => {
1097
+ if (!element)
1098
+ return;
1099
+ if (!value)
1100
+ return;
1101
+ // Select all cells with the attribute type="box"
1102
+ const boxCells = Array.from(element.children);
1103
+ console.log('boxCells', boxCells);
1104
+ if (!boxCells)
1105
+ return;
1106
+ boxCells.forEach(cell => {
1107
+ // Reset any previous styles
1108
+ cell.style.visibility = 'hidden';
1109
+ });
1110
+ // Animate each cell one by one
1111
+ for (const cell of boxCells) {
1112
+ cell.style.visibility = 'visible';
1113
+ cell.style.opacity = '1';
1114
+ // Apply the "come from top" animation
1115
+ cell.classList.add('lido-box-highlight');
1116
+ // Delay for each cell to come one after another
1117
+ await new Promise(resolve => setTimeout(resolve, 600)); // Adjust delay as needed
1118
+ cell.classList.remove('lido-box-highlight');
1119
+ }
1120
+ // After all cells have come down, apply the bounce animation
1121
+ for (const cell of boxCells) {
1122
+ // play the text child inside cell
1123
+ await AudioPlayer.getI().play(cell);
1124
+ }
1125
+ };
1126
+ export const questionBoxAnimation = async (element, value) => {
1127
+ if (!element)
1128
+ return;
1129
+ if (!value)
1130
+ return;
1131
+ // Select all drag elements and drop elements
1132
+ const dragElements = Array.from(element.querySelectorAll("[type='drag']"));
1133
+ // Ensure all drag childrens which is dropped disappear
1134
+ dragElements.forEach(dragElement => {
1135
+ if (dragElement.hasAttribute('drop-to')) {
1136
+ dragElement.style.transition = 'opacity 0.5s ease';
1137
+ dragElement.style.opacity = '0'; // Fade out
1138
+ setTimeout(() => {
1139
+ dragElement.remove(); // Remove from view after fade-out
1140
+ }, 500);
1141
+ }
1142
+ });
1143
+ // Reveal all drop childrens which is hidden
1144
+ const dropElements = Array.from(element.querySelectorAll("[type='drop']"));
1145
+ let check = false;
1146
+ dropElements.forEach(dropEl => {
1147
+ const dropVal = dropEl.getAttribute("value");
1148
+ if (dropVal && dropEl.innerText.trim() === "?") {
1149
+ dropEl.innerText = dropVal;
1150
+ if (dropElements.length > 1 && check == false) {
1151
+ if (window.innerWidth > window.innerHeight) {
1152
+ dropEl.style.marginRight = "-45px";
1153
+ }
1154
+ else {
1155
+ dropEl.style.marginRight = "-65px";
1156
+ }
1157
+ check = true;
1158
+ }
1159
+ }
1160
+ });
1161
+ };
1162
+ export const SumTogetherAnimation = async (element, value) => {
1163
+ if (!element)
1164
+ return;
1165
+ if (!value)
1166
+ return;
1167
+ const container = document.getElementById(LidoContainer);
1168
+ if (!container)
1169
+ return;
1170
+ // Expecting structure: [_, TopRow, questionRow, optionRow, ...]
1171
+ const TopRow = Array.from(element.children)[1];
1172
+ const questionRow = Array.from(element.children)[2];
1173
+ const optionRow = Array.from(element.children)[3];
1174
+ if (!TopRow || !questionRow || !optionRow)
1175
+ return;
1176
+ const topRowChildren = Array.from(TopRow.children);
1177
+ const questionRowChildren = Array.from(questionRow.children);
1178
+ const firstNumberEl = questionRowChildren[0];
1179
+ const signElement = questionRowChildren[1];
1180
+ const secondNumberEl = questionRowChildren[2];
1181
+ const equalElement = questionRowChildren[3];
1182
+ const answerElement = questionRowChildren[4];
1183
+ // helper functions
1184
+ const showElement = (el) => {
1185
+ if (!el)
1186
+ return;
1187
+ el.style.visibility = 'visible';
1188
+ el.style.display = '';
1189
+ el.style.opacity = '1';
1190
+ };
1191
+ const readNumber = (el) => {
1192
+ if (!el)
1193
+ return 0;
1194
+ const v = (el.getAttribute && (el.getAttribute('value') || el.getAttribute('string'))) || el.textContent || '';
1195
+ return parseInt(String(v).trim(), 10) || 0;
1196
+ };
1197
+ const elementAppearance = async (flag) => {
1198
+ if (flag) {
1199
+ if (firstNumberEl) {
1200
+ await new Promise(r => setTimeout(r, 200));
1201
+ showElement(firstNumberEl);
1202
+ }
1203
+ if (signElement) {
1204
+ await new Promise(r => setTimeout(r, 200));
1205
+ showElement(signElement);
1206
+ }
1207
+ }
1208
+ else {
1209
+ if (secondNumberEl) {
1210
+ await new Promise(r => setTimeout(r, 200));
1211
+ showElement(secondNumberEl);
1212
+ }
1213
+ if (equalElement) {
1214
+ await new Promise(r => setTimeout(r, 300));
1215
+ showElement(equalElement);
1216
+ }
1217
+ if (optionRow) {
1218
+ await new Promise(r => setTimeout(r, 300));
1219
+ showElement(optionRow);
1220
+ }
1221
+ if (answerElement) {
1222
+ await new Promise(r => setTimeout(r, 200));
1223
+ showElement(answerElement);
1224
+ }
1225
+ }
1226
+ };
1227
+ const number1 = readNumber(firstNumberEl);
1228
+ const number2 = readNumber(secondNumberEl);
1229
+ const sign = ((signElement && ((signElement.getAttribute('string') || signElement.textContent) || '')).toString().trim() === '+') ? '+' : '-';
1230
+ if (sign === '-') {
1231
+ // '-' flow: reveal one by one then change bgColor of last B to red
1232
+ for (let i = 0; i < topRowChildren.length; i++) {
1233
+ await new Promise(resolve => setTimeout(resolve, 75));
1234
+ showElement(topRowChildren[i]);
1235
+ }
1236
+ elementAppearance(true);
1237
+ await new Promise(r => setTimeout(r, 500));
1238
+ for (let k = 0; k < Math.min(number2, topRowChildren.length); k++) {
1239
+ const idx = topRowChildren.length - 1 - k;
1240
+ setImageBackground(topRowChildren[idx], 'red');
1241
+ await new Promise(r => setTimeout(r, 200));
1242
+ }
1243
+ elementAppearance(false);
1244
+ }
1245
+ else {
1246
+ // '+' flow: hide all, then showElement first A, then showElement next B in green
1247
+ for (let i = 0; i < Math.min(number1, topRowChildren.length); i++) {
1248
+ await new Promise(resolve => setTimeout(resolve, 120));
1249
+ showElement(topRowChildren[i]);
1250
+ }
1251
+ elementAppearance(true);
1252
+ await new Promise(r => setTimeout(r, 500));
1253
+ for (let j = 0; j < Math.min(number2, Math.max(0, topRowChildren.length - number1)); j++) {
1254
+ const idx = number1 + j;
1255
+ if (topRowChildren[idx]) {
1256
+ showElement(topRowChildren[idx]);
1257
+ setImageBackground(topRowChildren[idx], 'green');
1258
+ }
1259
+ await new Promise(r => setTimeout(r, 80));
1260
+ }
1261
+ elementAppearance(false);
1262
+ }
1263
+ };