bloom-player 2.20.1-alpha.2 → 2.20.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A library for displaying Bloom books in iframes or WebViews",
4
4
  "author": "SIL Global",
5
5
  "license": "MIT",
6
- "version": "2.20.1-alpha.2",
6
+ "version": "2.20.1-alpha.4",
7
7
  "packageManager": "pnpm@11.1.2",
8
8
  "private": false,
9
9
  "// sideeffects might need to be ['*.css'] to avoid 'shaking' our CSS, if we ever get tree shaking working": "",
@@ -43,7 +43,7 @@ let positionsToRestore: { x: string; y: string; elt: HTMLElement }[] = [];
43
43
  // Save the current positions of all draggables (when entering Play tab, so we can restore them when leaving).
44
44
  const savePositions = (page: HTMLElement) => {
45
45
  positionsToRestore = [];
46
- page.querySelectorAll("[data-draggable-id]").forEach((elt: HTMLElement) => {
46
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
47
47
  positionsToRestore.push({
48
48
  x: elt.style.left,
49
49
  y: elt.style.top,
@@ -66,7 +66,9 @@ export function adjustDraggablesForLanguage(page: HTMLElement) {
66
66
  if (page.getAttribute("data-activity") !== "drag-letter-to-target") {
67
67
  return;
68
68
  }
69
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
69
+ const draggables = Array.from(
70
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
71
+ );
70
72
  draggables.shift(); // The first one is always visible.
71
73
  draggables.forEach((draggable: HTMLElement) => {
72
74
  const shouldBeVisible = !!(
@@ -110,7 +112,9 @@ export function prepareActivity(
110
112
 
111
113
  // Set up event listeners for any change page buttons.
112
114
  const changePageButtons = Array.from(
113
- page.getElementsByClassName("bloom-change-page-button"),
115
+ page.getElementsByClassName(
116
+ "bloom-change-page-button",
117
+ ) as HTMLCollectionOf<HTMLElement>,
114
118
  );
115
119
  changePageButtons.forEach((b) =>
116
120
  b.addEventListener("click", changePageButtonClicked),
@@ -138,7 +142,9 @@ export function prepareActivity(
138
142
  // Add event listeners to draggables to start dragging.
139
143
  targetPositions = [];
140
144
  originalPositions = new Map<HTMLElement, { x: number; y: number }>();
141
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
145
+ const draggables = Array.from(
146
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
147
+ );
142
148
  const targets: HTMLElement[] = [];
143
149
  draggables.forEach((elt: HTMLElement) => {
144
150
  const targetId = elt.getAttribute("data-draggable-id");
@@ -190,7 +196,9 @@ export function prepareActivity(
190
196
  // Add event listeners to (other) text items that should play audio when clicked.
191
197
  const dontPlayWhenClicked = draggables.concat(targets);
192
198
  const otherTextItems = Array.from(
193
- page.getElementsByClassName("bloom-visibility-code-on"),
199
+ page.getElementsByClassName(
200
+ "bloom-visibility-code-on",
201
+ ) as HTMLCollectionOf<HTMLElement>,
194
202
  ).filter((e) => {
195
203
  var top = e.closest(kLegacyCanvasElementSelector) as HTMLElement;
196
204
  if (!top) {
@@ -209,13 +217,19 @@ export function prepareActivity(
209
217
 
210
218
  // Add event listeners to check, try again, and show correct buttons.
211
219
  const checkButtons = Array.from(
212
- page.getElementsByClassName("check-button"),
220
+ page.getElementsByClassName(
221
+ "check-button",
222
+ ) as HTMLCollectionOf<HTMLElement>,
213
223
  );
214
224
  const tryAgainButtons = Array.from(
215
- page.getElementsByClassName("try-again-button"),
225
+ page.getElementsByClassName(
226
+ "try-again-button",
227
+ ) as HTMLCollectionOf<HTMLElement>,
216
228
  );
217
229
  const showCorrectButtons = Array.from(
218
- page.getElementsByClassName("show-correct-button"),
230
+ page.getElementsByClassName(
231
+ "show-correct-button",
232
+ ) as HTMLCollectionOf<HTMLElement>,
219
233
  );
220
234
 
221
235
  checkButtons.forEach((elt: HTMLElement) => {
@@ -228,7 +242,9 @@ export function prepareActivity(
228
242
  elt.addEventListener("click", showCorrect);
229
243
  });
230
244
 
231
- const soundItems = Array.from(page.querySelectorAll("[data-sound]"));
245
+ const soundItems = Array.from(
246
+ page.querySelectorAll<HTMLElement>("[data-sound]"),
247
+ );
232
248
  soundItems.forEach((elt: HTMLElement) => {
233
249
  elt.addEventListener("click", playSoundOf);
234
250
  });
@@ -254,7 +270,11 @@ export function prepareActivity(
254
270
  // Break any order-sentence element into words and
255
271
  // randomize word order in sentence for reader to sort
256
272
  const prepareOrderSentenceActivity = (page: HTMLElement) => {
257
- Array.from(page.getElementsByClassName("drag-item-order-sentence")).forEach(
273
+ Array.from(
274
+ page.getElementsByClassName(
275
+ "drag-item-order-sentence",
276
+ ) as HTMLCollectionOf<HTMLElement>,
277
+ ).forEach(
258
278
  (elt: HTMLElement) => {
259
279
  const contentElt = elt.getElementsByClassName(
260
280
  "bloom-content1 bloom-visibility-code-on",
@@ -291,19 +311,23 @@ export function undoPrepareActivity(page: HTMLElement) {
291
311
  positionsToRestore = [];
292
312
 
293
313
  const changePageButtons = Array.from(
294
- page.getElementsByClassName("bloom-change-page-button"),
314
+ page.getElementsByClassName(
315
+ "bloom-change-page-button",
316
+ ) as HTMLCollectionOf<HTMLElement>,
295
317
  );
296
318
  changePageButtons.forEach((b) =>
297
319
  b.removeEventListener("click", changePageButtonClicked),
298
320
  );
299
321
 
300
- Array.from(page.getElementsByClassName("bloom-visibility-code-on")).forEach(
301
- (e) => {
302
- e.removeEventListener("pointerdown", playAudioOfTarget);
303
- },
304
- );
322
+ Array.from(
323
+ page.getElementsByClassName(
324
+ "bloom-visibility-code-on",
325
+ ) as HTMLCollectionOf<HTMLElement>,
326
+ ).forEach((e) => {
327
+ e.removeEventListener("pointerdown", playAudioOfTarget);
328
+ });
305
329
 
306
- page.querySelectorAll("[data-draggable-id]").forEach((elt: HTMLElement) => {
330
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
307
331
  elt.removeEventListener("pointerdown", startDrag, { capture: true });
308
332
  });
309
333
 
@@ -317,13 +341,19 @@ export function undoPrepareActivity(page: HTMLElement) {
317
341
  video.classList.remove("bloom-ui-no-controls");
318
342
  });
319
343
  const checkButtons = Array.from(
320
- page.getElementsByClassName("check-button"),
344
+ page.getElementsByClassName(
345
+ "check-button",
346
+ ) as HTMLCollectionOf<HTMLElement>,
321
347
  );
322
348
  const tryAgainButtons = Array.from(
323
- page.getElementsByClassName("try-again-button"),
349
+ page.getElementsByClassName(
350
+ "try-again-button",
351
+ ) as HTMLCollectionOf<HTMLElement>,
324
352
  );
325
353
  const showCorrectButtons = Array.from(
326
- page.getElementsByClassName("show-correct-button"),
354
+ page.getElementsByClassName(
355
+ "show-correct-button",
356
+ ) as HTMLCollectionOf<HTMLElement>,
327
357
  );
328
358
 
329
359
  checkButtons.forEach((elt: HTMLElement) => {
@@ -339,13 +369,17 @@ export function undoPrepareActivity(page: HTMLElement) {
339
369
  // In Bloom Player, this will have been done by other play code, since data-sound is not
340
370
  // specific to games. But we're adding a listener for the same function, so it doesn't matter.
341
371
  // In Bloom desktop, we need this to make clicking data-sound elements work in Play mode.
342
- const soundItems = Array.from(page.querySelectorAll("[data-sound]"));
372
+ const soundItems = Array.from(
373
+ page.querySelectorAll<HTMLElement>("[data-sound]"),
374
+ );
343
375
  soundItems.forEach((elt: HTMLElement) => {
344
376
  elt.removeEventListener("click", playSoundOf);
345
377
  });
346
378
 
347
379
  Array.from(
348
- page.getElementsByClassName("drag-item-random-sentence"),
380
+ page.getElementsByClassName(
381
+ "drag-item-random-sentence",
382
+ ) as HTMLCollectionOf<HTMLElement>,
349
383
  ).forEach((elt: HTMLElement) => {
350
384
  elt.parentElement?.removeChild(elt);
351
385
  });
@@ -602,7 +636,7 @@ const showCorrect = (e: MouseEvent) => {
602
636
  }
603
637
  restorePositions(); // any distractors return to start positions.
604
638
  currentPage
605
- .querySelectorAll("[data-draggable-id]")
639
+ .querySelectorAll<HTMLElement>("[data-draggable-id]")
606
640
  .forEach((elt: HTMLElement) => {
607
641
  const targetId = elt.getAttribute("data-draggable-id");
608
642
  const target = currentPage?.querySelector(
@@ -631,7 +665,9 @@ const showCorrect = (e: MouseEvent) => {
631
665
  elt.style.top = y + "px";
632
666
  });
633
667
  Array.from(
634
- currentPage.getElementsByClassName("drag-item-random-sentence"),
668
+ currentPage.getElementsByClassName(
669
+ "drag-item-random-sentence",
670
+ ) as HTMLCollectionOf<HTMLElement>,
635
671
  ).forEach((container: HTMLElement) => {
636
672
  const correctAnswer =
637
673
  container.getAttribute("data-answer")?.split(" ") ?? [];
@@ -651,7 +687,7 @@ const showCorrect = (e: MouseEvent) => {
651
687
  // Play any videos that are part of a correct answer, in document order.
652
688
  const videoElements: HTMLVideoElement[] = [];
653
689
  currentPage!
654
- .querySelectorAll("[data-draggable-id]")
690
+ .querySelectorAll<HTMLElement>("[data-draggable-id]")
655
691
  .forEach((elt: HTMLElement) => {
656
692
  const targetId = elt.getAttribute("data-draggable-id");
657
693
  const target = currentPage?.querySelector(
@@ -751,7 +787,9 @@ const stopDrag = (e: PointerEvent) => {
751
787
  // back to its original position.
752
788
  // Enhance: animate?
753
789
  const page = dragTarget.closest(".bloom-page") as HTMLElement;
754
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
790
+ const draggables = Array.from(
791
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
792
+ );
755
793
  draggables.forEach((elt: HTMLElement) => {
756
794
  if (elt === dragTarget) {
757
795
  return;
@@ -1029,7 +1067,9 @@ function playSound(
1029
1067
 
1030
1068
  function checkDraggables(page: HTMLElement) {
1031
1069
  let allCorrect = true;
1032
- const draggables = Array.from(page.querySelectorAll("[data-draggable-id]"));
1070
+ const draggables = Array.from(
1071
+ page.querySelectorAll<HTMLElement>("[data-draggable-id]"),
1072
+ );
1033
1073
  draggables.forEach((draggableToCheck: HTMLElement) => {
1034
1074
  const targetId = draggableToCheck.getAttribute("data-draggable-id");
1035
1075
  const target = page.querySelector(
@@ -386,8 +386,8 @@ function removeHighlightClasses(element: HTMLElement) {
386
386
  element.classList.remove(kDisableHighlightClass);
387
387
  element.classList.remove(kEnableHighlightClass);
388
388
 
389
- Array.from(element.children).forEach((child: HTMLElement) => {
390
- removeHighlightClasses(child);
389
+ Array.from(element.children).forEach((child) => {
390
+ removeHighlightClasses(child as HTMLElement);
391
391
  });
392
392
  }
393
393
 
@@ -1266,7 +1266,7 @@ function getPageAudioElements(
1266
1266
  page?: HTMLElement,
1267
1267
  canvasToExclude?: HTMLElement,
1268
1268
  ): HTMLElement[] {
1269
- return [].concat.apply(
1269
+ return ([] as HTMLElement[]).concat.apply(
1270
1270
  [],
1271
1271
  getPagePlayableDivs(page, canvasToExclude).map((x) =>
1272
1272
  findAll(".audio-sentence", x, true),
@@ -345,8 +345,14 @@ export function setupSpecialMouseTrackingForNiceScroll(
345
345
  bloomPage: Element,
346
346
  pointerEventHandler?: (e: PointerEvent) => void,
347
347
  ) {
348
- bloomPage.removeEventListener("pointerdown", listenForPointerDown); // only want one!
349
- bloomPage.addEventListener("pointerdown", listenForPointerDown);
348
+ bloomPage.removeEventListener(
349
+ "pointerdown",
350
+ listenForPointerDown as EventListener,
351
+ ); // only want one!
352
+ bloomPage.addEventListener(
353
+ "pointerdown",
354
+ listenForPointerDown as EventListener,
355
+ );
350
356
  if (!pointerEventHandler) {
351
357
  return;
352
358
  }
@@ -355,7 +361,7 @@ export function setupSpecialMouseTrackingForNiceScroll(
355
361
  for (const eventName of ["pointermove", "pointerup"]) {
356
362
  bloomPage.ownerDocument.body.addEventListener(
357
363
  eventName,
358
- pointerEventHandler,
364
+ pointerEventHandler as EventListener,
359
365
  {
360
366
  capture: true,
361
367
  },