@pie-players/pie-tool-answer-eliminator 0.3.49 → 0.3.50

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.
@@ -7,7 +7,7 @@ import { ChoiceAdapter } from './choice-adapter.js';
7
7
  */
8
8
  export declare class EBSRAdapter implements ChoiceAdapter {
9
9
  readonly elementType = "ebsr";
10
- readonly priority = 95;
10
+ readonly priority = 110;
11
11
  private mcAdapter;
12
12
  canHandle(element: HTMLElement): boolean;
13
13
  findChoices(root: HTMLElement): HTMLElement[];
@@ -1,4 +1,25 @@
1
1
  import { MultipleChoiceAdapter } from "./multiple-choice-adapter.js";
2
+ const EBSR_MULTIPLE_CHOICE_TAG = "ebsr-multiple-choice";
3
+ const EBSR_MULTIPLE_CHOICE_VERSIONED_PREFIX = `${EBSR_MULTIPLE_CHOICE_TAG}--version-`;
4
+ const isEbsrMultipleChoiceElement = (element) => {
5
+ if (!(element instanceof HTMLElement)) {
6
+ return false;
7
+ }
8
+ const tagName = element.tagName.toLowerCase();
9
+ return (tagName === EBSR_MULTIPLE_CHOICE_TAG ||
10
+ tagName.startsWith(EBSR_MULTIPLE_CHOICE_VERSIONED_PREFIX));
11
+ };
12
+ const findEbsrMultipleChoicePart = (root, id) => Array.from(root.querySelectorAll(`[id="${id}"]`)).find(isEbsrMultipleChoiceElement) ?? null;
13
+ const findClosestEbsrMultipleChoicePart = (choice) => {
14
+ let element = choice.parentElement;
15
+ while (element !== null) {
16
+ if (isEbsrMultipleChoiceElement(element)) {
17
+ return element;
18
+ }
19
+ element = element.parentElement;
20
+ }
21
+ return null;
22
+ };
2
23
  /**
3
24
  * Adapter for EBSR (Evidence-Based Selected Response) elements
4
25
  *
@@ -7,17 +28,17 @@ import { MultipleChoiceAdapter } from "./multiple-choice-adapter.js";
7
28
  */
8
29
  export class EBSRAdapter {
9
30
  elementType = "ebsr";
10
- priority = 95;
31
+ priority = 110;
11
32
  mcAdapter = new MultipleChoiceAdapter();
12
33
  canHandle(element) {
13
34
  return (element.tagName.toLowerCase() === "ebsr" ||
14
- element.querySelector("ebsr-multiple-choice") !== null);
35
+ Array.from(element.querySelectorAll("*")).some(isEbsrMultipleChoiceElement));
15
36
  }
16
37
  findChoices(root) {
17
- // EBSR contains ebsr-multiple-choice elements
38
+ // EBSR contains private multiple-choice elements, version-scoped in modern bundles.
18
39
  // Find choices in both Part A and Part B
19
- const partA = root.querySelector('ebsr-multiple-choice[id="a"]');
20
- const partB = root.querySelector('ebsr-multiple-choice[id="b"]');
40
+ const partA = findEbsrMultipleChoicePart(root, "a");
41
+ const partB = findEbsrMultipleChoicePart(root, "b");
21
42
  const choices = [];
22
43
  if (partA)
23
44
  choices.push(...this.mcAdapter.findChoices(partA));
@@ -31,7 +52,7 @@ export class EBSRAdapter {
31
52
  }
32
53
  getChoiceId(choice) {
33
54
  // Prefix with part ID (a or b)
34
- const part = choice.closest("ebsr-multiple-choice")?.id || "unknown";
55
+ const part = findClosestEbsrMultipleChoicePart(choice)?.id || "unknown";
35
56
  const choiceId = this.mcAdapter.getChoiceId(choice);
36
57
  return `${part}-${choiceId}`;
37
58
  }