@qti-components/test 1.6.2 → 1.7.0

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.
@@ -6,6 +6,7 @@ export * from '../components/qti-test-part/qti-test-part';
6
6
  export * from '../components/qti-test-feedback/qti-test-feedback';
7
7
  export * from '../components/qti-outcome-processing/qti-outcome-processing';
8
8
  export * from '../components/qti-test-variables/qti-test-variables';
9
+ export * from '../components/qti-number-selected/qti-number-selected';
9
10
  export * from '../components/qti-item-session-control/qti-item-session-control';
10
11
  export * from './test-navigation/test-navigation';
11
12
  export * from './test-next/test-next';
@@ -7,6 +7,7 @@ export * from '../components/qti-test-part/qti-test-part';
7
7
  export * from '../components/qti-test-feedback/qti-test-feedback';
8
8
  export * from '../components/qti-outcome-processing/qti-outcome-processing';
9
9
  export * from '../components/qti-test-variables/qti-test-variables';
10
+ export * from '../components/qti-number-selected/qti-number-selected';
10
11
  export * from '../components/qti-item-session-control/qti-item-session-control';
11
12
  export * from './test-navigation/test-navigation';
12
13
  export * from './test-next/test-next';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,cAAc,iCAAiC,CAAC;AAChD,cAAc,+DAA+D,CAAC;AAC9E,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mDAAmD,CAAC;AAClE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,qDAAqD,CAAC;AACpE,cAAc,iEAAiE,CAAC;AAEhF,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uDAAuD,CAAC;AACtE,cAAc,iCAAiC,CAAC;AAChD,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,qCAAqC,CAAC;AACpD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC","sourcesContent":["/* test functionality webcomponents which are tested and can be used in your project */\nexport * from '../components/qti-test/qti-test';\nexport * from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nexport * from '../components/qti-assessment-section/qti-assessment-section';\nexport * from '../components/qti-assessment-test/qti-assessment-test';\nexport * from '../components/qti-test-part/qti-test-part';\nexport * from '../components/qti-test-feedback/qti-test-feedback';\nexport * from '../components/qti-outcome-processing/qti-outcome-processing';\nexport * from '../components/qti-test-variables/qti-test-variables';\nexport * from '../components/qti-item-session-control/qti-item-session-control';\n\nexport * from './test-navigation/test-navigation';\nexport * from './test-next/test-next';\nexport * from './test-prev/test-prev';\nexport * from './test-view-toggle/test-view';\nexport * from './test-item-link/test-item-link';\nexport * from './test-end-attempt/test-end-attempt';\nexport * from './test-paging-buttons-stamp/test-paging-buttons-stamp';\nexport * from './test-container/test-container';\nexport * from './test-print-item-variables/test-print-item-variables';\nexport * from './test-section-buttons-stamp/test-section-buttons-stamp';\nexport * from './test-section-link/test-section-link';\nexport * from './test-print-context/test-print-context';\nexport * from './test-stamp/test-stamp';\nexport * from './test-scoring-buttons/test-scoring-buttons';\nexport * from './test-view-toggle/test-view-toggle';\nexport * from './test-scoring-feedback/test-scoring-feedback';\nexport * from './test-check-item/test-check-item';\nexport * from './test-item-to-speech/test-item-to-speech';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,cAAc,iCAAiC,CAAC;AAChD,cAAc,+DAA+D,CAAC;AAC9E,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mDAAmD,CAAC;AAClE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,iEAAiE,CAAC;AAEhF,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uDAAuD,CAAC;AACtE,cAAc,iCAAiC,CAAC;AAChD,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,qCAAqC,CAAC;AACpD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC","sourcesContent":["/* test functionality webcomponents which are tested and can be used in your project */\nexport * from '../components/qti-test/qti-test';\nexport * from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nexport * from '../components/qti-assessment-section/qti-assessment-section';\nexport * from '../components/qti-assessment-test/qti-assessment-test';\nexport * from '../components/qti-test-part/qti-test-part';\nexport * from '../components/qti-test-feedback/qti-test-feedback';\nexport * from '../components/qti-outcome-processing/qti-outcome-processing';\nexport * from '../components/qti-test-variables/qti-test-variables';\nexport * from '../components/qti-number-selected/qti-number-selected';\nexport * from '../components/qti-item-session-control/qti-item-session-control';\n\nexport * from './test-navigation/test-navigation';\nexport * from './test-next/test-next';\nexport * from './test-prev/test-prev';\nexport * from './test-view-toggle/test-view';\nexport * from './test-item-link/test-item-link';\nexport * from './test-end-attempt/test-end-attempt';\nexport * from './test-paging-buttons-stamp/test-paging-buttons-stamp';\nexport * from './test-container/test-container';\nexport * from './test-print-item-variables/test-print-item-variables';\nexport * from './test-section-buttons-stamp/test-section-buttons-stamp';\nexport * from './test-section-link/test-section-link';\nexport * from './test-print-context/test-print-context';\nexport * from './test-stamp/test-stamp';\nexport * from './test-scoring-buttons/test-scoring-buttons';\nexport * from './test-view-toggle/test-view-toggle';\nexport * from './test-scoring-feedback/test-scoring-feedback';\nexport * from './test-check-item/test-check-item';\nexport * from './test-item-to-speech/test-item-to-speech';\n"]}
@@ -1,17 +1,44 @@
1
1
  import { LitElement } from 'lit';
2
2
  import type { QtiAssessmentItem } from '@qti-components/elements';
3
3
  import type { TemplateFunction } from '@heximal/templates';
4
+ /**
5
+ * The model a `<template item-ref>` is rendered with.
6
+ *
7
+ * Only what this element already knows: the item's parsed document and the
8
+ * attributes off the item-ref itself. `itemRef` is the escape hatch — a
9
+ * template that needs anything else (a click handler, a value from the host
10
+ * app) reaches it through a property on the element, which the host is free to
11
+ * set.
12
+ */
13
+ export interface ItemRefTemplateModel {
14
+ /** The item's parsed document, i.e. what the element renders by default. */
15
+ xmlDoc: DocumentFragment;
16
+ identifier?: string;
17
+ href?: string;
18
+ category?: string;
19
+ /** The element being rendered. */
20
+ itemRef: QtiAssessmentItemRef;
21
+ }
4
22
  export declare class QtiAssessmentItemRef extends LitElement {
23
+ #private;
5
24
  category?: string;
6
25
  identifier?: string;
7
26
  required?: boolean;
8
27
  fixed?: boolean;
9
28
  href?: string;
10
- weigths: Map<string, number>;
11
- xmlDoc: DocumentFragment;
29
+ /**
30
+ * The `<qti-weight>` children of this ref, keyed by identifier — what
31
+ * `qti-test-variables`' `weight-identifier` resolves against.
32
+ *
33
+ * Read on access rather than cached: the test document is rendered into this
34
+ * element's light DOM, so the weights are not in place at construction time,
35
+ * and outcome processing runs long after they are.
36
+ */
37
+ get weights(): Map<string, number>;
38
+ xmlDoc: DocumentFragment | null;
12
39
  protected createRenderRoot(): HTMLElement | DocumentFragment;
13
40
  get assessmentItem(): QtiAssessmentItem | null;
14
- myTemplate: TemplateFunction;
41
+ myTemplate: TemplateFunction | null;
15
42
  connectedCallback(): Promise<void>;
16
43
  render(): unknown;
17
44
  }
@@ -4,8 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { LitElement } from 'lit';
7
+ import { LitElement, nothing } from 'lit';
8
8
  import { property } from 'lit/decorators.js';
9
+ import { prepareTemplate } from '@heximal/templates';
9
10
  // Converter function to interpret "true" and "false" as booleans
10
11
  const stringToBooleanConverter = {
11
12
  fromAttribute(value) {
@@ -19,9 +20,33 @@ const stringToBooleanConverter = {
19
20
  export class QtiAssessmentItemRef extends LitElement {
20
21
  constructor() {
21
22
  super(...arguments);
22
- // @consume({ context: computedContext, subscribe: true })
23
- // private computedContext: ComputedContext;
24
- this.weigths = new Map();
23
+ this.xmlDoc = null;
24
+ this.myTemplate = null;
25
+ }
26
+ // @consume({ context: computedContext, subscribe: true })
27
+ // private computedContext: ComputedContext;
28
+ /**
29
+ * The `<qti-weight>` children of this ref, keyed by identifier — what
30
+ * `qti-test-variables`' `weight-identifier` resolves against.
31
+ *
32
+ * Read on access rather than cached: the test document is rendered into this
33
+ * element's light DOM, so the weights are not in place at construction time,
34
+ * and outcome processing runs long after they are.
35
+ */
36
+ get weights() {
37
+ const weights = new Map();
38
+ for (const weight of this.querySelectorAll(':scope > qti-weight')) {
39
+ const identifier = weight.getAttribute('identifier');
40
+ if (!identifier)
41
+ continue;
42
+ const value = Number(weight.getAttribute('value'));
43
+ if (Number.isNaN(value)) {
44
+ console.warn(`qti-weight "${identifier}" has a non-numeric value, ignoring it`);
45
+ continue;
46
+ }
47
+ weights.set(identifier, value);
48
+ }
49
+ return weights;
25
50
  }
26
51
  createRenderRoot() {
27
52
  return this;
@@ -29,20 +54,54 @@ export class QtiAssessmentItemRef extends LitElement {
29
54
  get assessmentItem() {
30
55
  return this.renderRoot?.querySelector('qti-assessment-item');
31
56
  }
57
+ /**
58
+ * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way
59
+ * up.
60
+ *
61
+ * `<test-container>` renders its items into a shadow root, so an item-ref is
62
+ * usually one hop below one; but it is also valid in plain light DOM, and a
63
+ * host is free to nest it deeper. Climbing root by root covers all three
64
+ * without assuming any of them.
65
+ */
66
+ #findTestElement() {
67
+ const own = this.closest('qti-test');
68
+ if (own)
69
+ return own;
70
+ let root = this.getRootNode();
71
+ while (root instanceof ShadowRoot) {
72
+ const test = root.host.closest('qti-test');
73
+ if (test)
74
+ return test;
75
+ root = root.host.getRootNode();
76
+ }
77
+ // A Document, or a fragment that is not attached to one: nowhere left to climb.
78
+ return null;
79
+ }
32
80
  async connectedCallback() {
33
81
  super.connectedCallback();
34
82
  /*
35
- searches for the template element to use in the qti-test component
36
- can be used to render extra things for an item, like a bookmark, index nummer
37
- put this in your test-container component
38
- <template item-ref>
39
- <div>Extra content</div>
40
- </template>
83
+ Optional per-item template, used to render extra things around an item —
84
+ a bookmark, an index number, a score badge. Put it in the light DOM of
85
+ your qti-test, and every item-ref in the test renders with it:
86
+
87
+ <qti-test>
88
+ <template item-ref>
89
+ <div class="badge">{{ identifier }}</div>
90
+ {{ xmlDoc }}
91
+ </template>
92
+ …
93
+ </qti-test>
94
+
95
+ The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;
96
+ leaving it out renders the chrome and no item. Without a template the
97
+ element renders the item on its own, exactly as before.
98
+
99
+ Resolved once, on connect: one template serves every item, and everything
100
+ that varies per item comes through the model (see ItemRefTemplateModel).
41
101
  */
42
- // const templateElement = ((this.getRootNode() as any).host as HTMLElement)
43
- // .closest('qti-test')
44
- // .querySelector<HTMLTemplateElement>('template[item-ref]');
45
- // if (templateElement) this.myTemplate = prepareTemplate(templateElement);
102
+ const templateElement = this.#findTestElement()?.querySelector('template[item-ref]');
103
+ this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
104
+ this.requestUpdate();
46
105
  await this.updateComplete;
47
106
  this.dispatchEvent(new CustomEvent('qti-assessment-item-ref-connected', {
48
107
  bubbles: true,
@@ -51,7 +110,20 @@ export class QtiAssessmentItemRef extends LitElement {
51
110
  }));
52
111
  }
53
112
  render() {
54
- return this.myTemplate ? this.myTemplate({ xmlDoc: this.xmlDoc }) : this.xmlDoc;
113
+ // Item refs connect before loading, and navigation clears their documents.
114
+ if (!this.xmlDoc)
115
+ return nothing;
116
+ const xmlDoc = this.xmlDoc.cloneNode(true);
117
+ if (!this.myTemplate)
118
+ return xmlDoc;
119
+ const model = {
120
+ xmlDoc,
121
+ identifier: this.identifier,
122
+ href: this.href,
123
+ category: this.category,
124
+ itemRef: this
125
+ };
126
+ return this.myTemplate(model);
55
127
  }
56
128
  }
57
129
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK7C,iEAAiE;AACjE,MAAM,wBAAwB,GAAG;IAC/B,aAAa,CAAC,KAAa;QACzB,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IACD,WAAW,CAAC,KAAc;QACxB,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAClC,CAAC;CACF,CAAC;AAEF,4CAA4C;AAC5C,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAApD;;QAOE,0DAA0D;QAC1D,4CAA4C;QAE5C,YAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IA8C3C,CAAC;IAzCoB,gBAAgB;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,I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Content":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // @consume({ context: computedContext, subscribe: true })\n // private computedContext: ComputedContext;\n\n weigths: Map<string, number> = new Map();\n\n @property({ type: Object, attribute: false })\n xmlDoc!: DocumentFragment; // the XMLDocument\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction;\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n searches for the template element to use in the qti-test component\n can be used to render extra things for an item, like a bookmark, index nummer\n put this in your test-container component\n <template item-ref>\n <div>Extra content</div>\n </template>\n */\n // const templateElement = ((this.getRootNode() as any).host as HTMLElement)\n // .closest('qti-test')\n // .querySelector<HTMLTemplateElement>('template[item-ref]');\n\n // if (templateElement) this.myTemplate = prepareTemplate(templateElement);\n\n await this.updateComplete;\n\n this.dispatchEvent(\n new CustomEvent('qti-assessment-item-ref-connected', {\n bubbles: true,\n composed: true,\n detail: { identifier: this.identifier, href: this.href, category: this.category }\n })\n );\n }\n\n override render() {\n return this.myTemplate ? this.myTemplate({ xmlDoc: this.xmlDoc }) : this.xmlDoc;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,iEAAiE;AACjE,MAAM,wBAAwB,GAAG;IAC/B,aAAa,CAAC,KAAa;QACzB,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IACD,WAAW,CAAC,KAAc;QACxB,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAClC,CAAC;CACF,CAAC;AAqBF,4CAA4C;AAC5C,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAApD;;QAkCE,WAAM,GAA4B,IAAI,CAAC;QAUvC,eAAU,GAA4B,IAAI,CAAC;IA+E7C,CAAC;IApHC,0DAA0D;IAC1D,4CAA4C;IAE5C;;;;;;;OAOG;IACH,IAAI,OAAO;QACT,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAClE,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU;gBAAE,SAAS;YAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YACnD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,IAAI,CAAC,eAAe,UAAU,wCAAwC,CAAC,CAAC;gBAChF,SAAS;YACX,CAAC;YACD,OAAO,CAAC,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U,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;SAClF,CAAC,CACH,CAAC;IACJ,CAAC;IAEQ,MAAM;QACb,2EAA2E;QAC3E,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,OAAO,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAqB,CAAC;QAC/D,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,MAAM,CAAC;QAEpC,MAAM,KAAK,GAAyB;YAClC,MAAM;YACN,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI;SACd,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AA1H6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqB;AACkB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;sDAAoB;AACnB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AA6B1C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // @consume({ context: computedContext, subscribe: true })\n // private computedContext: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /**\n * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way\n * up.\n *\n * `<test-container>` renders its items into a shadow root, so an item-ref is\n * usually one hop below one; but it is also valid in plain light DOM, and a\n * host is free to nest it deeper. Climbing root by root covers all three\n * without assuming any of them.\n */\n #findTestElement(): Element | null {\n const own = this.closest('qti-test');\n if (own) return own;\n\n let root: Node = this.getRootNode();\n while (root instanceof ShadowRoot) {\n const test = root.host.closest('qti-test');\n if (test) return test;\n root = root.host.getRootNode();\n }\n // A Document, or a fragment that is not attached to one: nowhere left to climb.\n return null;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.#findTestElement()?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n this.dispatchEvent(\n new CustomEvent('qti-assessment-item-ref-connected', {\n bubbles: true,\n composed: true,\n detail: { identifier: this.identifier, href: this.href, category: this.category }\n })\n );\n }\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) return nothing;\n\n const xmlDoc = this.xmlDoc.cloneNode(true) as DocumentFragment;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { QtiExpression } from '@qti-components/base';
2
+ /**
3
+ * @summary The qti-number-selected expression counts the item refs selected for the test.
4
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected
5
+ *
6
+ * Outcome processing only. `section-identifier`, `include-category` and
7
+ * `exclude-category` narrow which item references are counted; with none of
8
+ * them it is every item reference in the test.
9
+ *
10
+ * The count comes from the item refs in the document rather than the test
11
+ * context, so it is the same set `qti-test-variables` aggregates over — and it
12
+ * is right before any item has been attempted.
13
+ */
14
+ export declare class QtiNumberSelected extends QtiExpression<number> {
15
+ #private;
16
+ constructor();
17
+ getResult(): number;
18
+ calculate(): number;
19
+ }
20
+ declare global {
21
+ interface HTMLElementTagNameMap {
22
+ 'qti-number-selected': QtiNumberSelected;
23
+ }
24
+ }
@@ -0,0 +1,42 @@
1
+ import { QtiExpression } from '@qti-components/base';
2
+ import { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';
3
+ /**
4
+ * @summary The qti-number-selected expression counts the item refs selected for the test.
5
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected
6
+ *
7
+ * Outcome processing only. `section-identifier`, `include-category` and
8
+ * `exclude-category` narrow which item references are counted; with none of
9
+ * them it is every item reference in the test.
10
+ *
11
+ * The count comes from the item refs in the document rather than the test
12
+ * context, so it is the same set `qti-test-variables` aggregates over — and it
13
+ * is right before any item has been attempted.
14
+ */
15
+ export class QtiNumberSelected extends QtiExpression {
16
+ #connectedTest = null;
17
+ constructor() {
18
+ super();
19
+ this.addEventListener('qti-assessment-test-connected', (e) => (this.#connectedTest = e.detail));
20
+ }
21
+ /**
22
+ * `qti-assessment-test-connected` bubbles *up* from the test element, and this
23
+ * expression lives inside that test's `qti-outcome-processing` — so the
24
+ * listener above only ever fires for a test handed to us directly (a test
25
+ * harness). Walking up the tree is what resolves the test in a real document.
26
+ */
27
+ get #testElement() {
28
+ return this.#connectedTest ?? this.closest('qti-assessment-test');
29
+ }
30
+ getResult() {
31
+ const testElement = this.#testElement;
32
+ if (!testElement) {
33
+ console.warn('qti-number-selected: no enclosing qti-assessment-test, nothing to count');
34
+ return 0;
35
+ }
36
+ return selectItemRefs(testElement, selectionFrom(this)).length;
37
+ }
38
+ calculate() {
39
+ return this.getResult();
40
+ }
41
+ }
42
+ //# sourceMappingURL=qti-number-selected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qti-number-selected.js","sourceRoot":"","sources":["../../../src/components/qti-number-selected/qti-number-selected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAIlF;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAqB;IAC1D,cAAc,GAA6B,IAAI,CAAC;IAEhD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CACnB,+BAA+B,EAC/B,CAAC,CAAiC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CACxE,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAoB,qBAAqB,CAAC,CAAC;IACvF,CAAC;IAEe,SAAS;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;YACxF,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,CAAC;IAEe,SAAS;QACvB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\n\n/**\n * @summary The qti-number-selected expression counts the item refs selected for the test.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected\n *\n * Outcome processing only. `section-identifier`, `include-category` and\n * `exclude-category` narrow which item references are counted; with none of\n * them it is every item reference in the test.\n *\n * The count comes from the item refs in the document rather than the test\n * context, so it is the same set `qti-test-variables` aggregates over — and it\n * is right before any item has been attempted.\n */\nexport class QtiNumberSelected extends QtiExpression<number> {\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n this.addEventListener(\n 'qti-assessment-test-connected',\n (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail)\n );\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult(): number {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-number-selected: no enclosing qti-assessment-test, nothing to count');\n return 0;\n }\n\n return selectItemRefs(testElement, selectionFrom(this)).length;\n }\n\n public override calculate(): number {\n return this.getResult();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-number-selected': QtiNumberSelected;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { css, html, LitElement } from 'lit';
2
+ import { QtiExitTestSignal } from '@qti-components/base';
2
3
  export class QtiOutcomeProcessing extends LitElement {
3
4
  static { this.styles = [
4
5
  css `
@@ -18,8 +19,17 @@ export class QtiOutcomeProcessing extends LitElement {
18
19
  }
19
20
  export class QtiOutcomeProcessingProcessor {
20
21
  process(rules) {
21
- for (const rule of rules) {
22
- rule.process();
22
+ try {
23
+ for (const rule of rules) {
24
+ rule.process();
25
+ }
26
+ }
27
+ catch (error) {
28
+ // `qti-exit-test` ends the run from wherever it sits, however deeply
29
+ // nested. Reaching here is the rule doing its job; anything else is a
30
+ // real failure and rethrows.
31
+ if (!(error instanceof QtiExitTestSignal))
32
+ throw error;
23
33
  }
24
34
  }
25
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"qti-outcome-processing.js","sourceRoot":"","sources":["../../../src/components/qti-outcome-processing/qti-outcome-processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAI5C,MAAM,OAAO,oBAAqB,SAAQ,UAAU;aAClC,WAAM,GAAG;QACvB,GAAG,CAAA;;;;KAIF;KACF,CAAC;IAEO,MAAM;QACb,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;IAEM,OAAO;QACZ,MAAM,KAAK,GAAG,IAAI,6BAA6B,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAA6B,CAAC;QAC7D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;;AASH,MAAM,OAAO,6BAA6B;IACjC,OAAO,CAAC,KAAoB;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { css, html, LitElement } from 'lit';\n\nimport type { QtiRuleBase } from '@qti-components/base';\n\nexport class QtiOutcomeProcessing extends LitElement {\n static override styles = [\n css`\n :host {\n display: none;\n }\n `\n ];\n\n override render() {\n return html`<slot></slot>`;\n }\n\n public process() {\n const logic = new QtiOutcomeProcessingProcessor();\n const rules = [...this.children] as unknown as QtiRuleBase[];\n logic.process(rules);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-outcome-processing': QtiOutcomeProcessing;\n }\n}\n\nexport class QtiOutcomeProcessingProcessor {\n public process(rules: QtiRuleBase[]) {\n for (const rule of rules) {\n rule.process();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"qti-outcome-processing.js","sourceRoot":"","sources":["../../../src/components/qti-outcome-processing/qti-outcome-processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD,MAAM,OAAO,oBAAqB,SAAQ,UAAU;aAClC,WAAM,GAAG;QACvB,GAAG,CAAA;;;;KAIF;KACF,CAAC;IAEO,MAAM;QACb,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;IAEM,OAAO;QACZ,MAAM,KAAK,GAAG,IAAI,6BAA6B,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAA6B,CAAC;QAC7D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;;AASH,MAAM,OAAO,6BAA6B;IACjC,OAAO,CAAC,KAAoB;QACjC,IAAI,CAAC;YACH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qEAAqE;YACrE,sEAAsE;YACtE,6BAA6B;YAC7B,IAAI,CAAC,CAAC,KAAK,YAAY,iBAAiB,CAAC;gBAAE,MAAM,KAAK,CAAC;QACzD,CAAC;IACH,CAAC;CACF","sourcesContent":["import { css, html, LitElement } from 'lit';\n\nimport { QtiExitTestSignal } from '@qti-components/base';\n\nimport type { QtiRuleBase } from '@qti-components/base';\n\nexport class QtiOutcomeProcessing extends LitElement {\n static override styles = [\n css`\n :host {\n display: none;\n }\n `\n ];\n\n override render() {\n return html`<slot></slot>`;\n }\n\n public process() {\n const logic = new QtiOutcomeProcessingProcessor();\n const rules = [...this.children] as unknown as QtiRuleBase[];\n logic.process(rules);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-outcome-processing': QtiOutcomeProcessing;\n }\n}\n\nexport class QtiOutcomeProcessingProcessor {\n public process(rules: QtiRuleBase[]) {\n try {\n for (const rule of rules) {\n rule.process();\n }\n } catch (error) {\n // `qti-exit-test` ends the run from wherever it sits, however deeply\n // nested. Reaching here is the rule doing its job; anything else is a\n // real failure and rethrows.\n if (!(error instanceof QtiExitTestSignal)) throw error;\n }\n }\n}\n"]}
@@ -7,41 +7,34 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { consume } from '@lit/context';
8
8
  import { testContext } from '@qti-components/base';
9
9
  import { QtiExpression } from '@qti-components/base';
10
- // <qti-custom-operator definition="trim">
10
+ import { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';
11
11
  export class QtiTestVariables extends QtiExpression {
12
- #testElement;
12
+ #connectedTest = null;
13
13
  constructor() {
14
14
  super();
15
- this.addEventListener('qti-assessment-test-connected', (e) => (this.#testElement = e.detail));
15
+ this.addEventListener('qti-assessment-test-connected', (e) => (this.#connectedTest = e.detail));
16
+ }
17
+ /**
18
+ * `qti-assessment-test-connected` bubbles *up* from the test element, and this
19
+ * expression lives inside that test's `qti-outcome-processing` — so the
20
+ * listener above only ever fires for a test handed to us directly (a test
21
+ * harness). Walking up the tree is what resolves the test in a real document.
22
+ */
23
+ get #testElement() {
24
+ return this.#connectedTest ?? this.closest('qti-assessment-test');
16
25
  }
17
26
  getResult() {
18
- // children can be a mix of qti-expression and qti-condition-expression
19
- const includedCategories = this.getAttribute('include-category')?.split(' ') ?? [];
20
- const excludedCategories = this.getAttribute('exclude-category')?.split(' ') ?? [];
27
+ const testElement = this.#testElement;
28
+ if (!testElement) {
29
+ console.warn('qti-test-variables: no enclosing qti-assessment-test, nothing to aggregate');
30
+ return 0;
31
+ }
21
32
  const weightIdentifier = this.getAttribute('weight-identifier') ?? '';
22
33
  const itemVariable = this.getAttribute('variable-identifier');
23
- const itemRefEls = Array.from(this.#testElement.querySelectorAll(`qti-asssessment-test qti-assessment-item-ref`));
24
- const includedItems = itemRefEls
25
- .filter(itemRef => {
26
- let include = true;
27
- if (includedCategories.length > 0) {
28
- include = includedCategories.includes(itemRef.category);
29
- }
30
- if (excludedCategories.length > 0) {
31
- include = !excludedCategories.includes(itemRef.category);
32
- }
33
- return include;
34
- })
35
- .map(itemRef => {
36
- let weight = 1;
37
- if (weightIdentifier) {
38
- const weightVariable = itemRef.weigths.get(weightIdentifier);
39
- if (weightVariable !== null && weightVariable !== undefined) {
40
- weight = weightVariable;
41
- }
42
- }
43
- return { item: itemRef.identifier, weight };
44
- });
34
+ const includedItems = selectItemRefs(testElement, selectionFrom(this)).map(itemRef => ({
35
+ item: itemRef.identifier,
36
+ weight: (weightIdentifier ? itemRef.weights.get(weightIdentifier) : undefined) ?? 1
37
+ }));
45
38
  const logic = new QtiTestVariablesExpression(this._testContext, itemVariable, includedItems);
46
39
  const value = logic.calculate();
47
40
  return value;
@@ -60,7 +53,7 @@ export class QtiTestVariablesExpression {
60
53
  this.includedItems = includedItems;
61
54
  }
62
55
  calculate() {
63
- const { items } = this.testContext;
56
+ const items = this.testContext?.items ?? [];
64
57
  let total = 0;
65
58
  const uniqueItems = [...new Set(this.includedItems.map(item => item.item))];
66
59
  items.forEach(item => {
@@ -68,7 +61,12 @@ export class QtiTestVariablesExpression {
68
61
  const variable = item.variables.find(vr => vr.identifier === this.itemVariable);
69
62
  const weight = this.includedItems.find(i => i.item === item.identifier)?.weight ?? 1;
70
63
  if (variable) {
71
- total += Number(variable.value) * weight;
64
+ // An unscored item carries a non-numeric value; counting it as NaN
65
+ // would poison the whole total rather than just its own contribution.
66
+ const value = Number(variable.value);
67
+ if (!Number.isNaN(value)) {
68
+ total += value * weight;
69
+ }
72
70
  }
73
71
  }
74
72
  });
@@ -1 +1 @@
1
- {"version":3,"file":"qti-test-variables.js","sourceRoot":"","sources":["../../../src/components/qti-test-variables/qti-test-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAOrD,0CAA0C;AAC1C,MAAM,OAAO,gBAAiB,SAAQ,aAAqB;IAIzD,YAAY,CAAoB;IAEhC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,+BAA+B,EAAE,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7G,CAAC;IAEe,SAAS;QACvB,uEAAuE;QACvE,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACnF,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACnF,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAE9D,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAC3B,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAuB,8CAA8C,CAAC,CACzG,CAAC;QAEF,MAAM,aAAa,GAAG,UAAU;aAC7B,MAAM,CAAC,OAAO,CAAC,EAAE;YAChB,IAAI,OAAO,GAAG,I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AAZ,YAAY,CAAQ;QACpB,kBAAa,GAAb,aAAa,CAAoC;IACxD,CAAC;IAEJ,SAAS;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;QACnC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5E,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACnB,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,KAAK,IAAI,CAAC,YAAY,CAAC,CAAC;gBAChF,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;gBACrF,IAAI,QAAQ,EAAE,CAAC;oBACb,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;gBAC3C,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { consume } from '@lit/context';\n\nimport { testContext } from '@qti-components/base';\nimport { QtiExpression } from '@qti-components/base';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { TestContext } from '@qti-components/base';\nimport type { QtiAssessmentItemRef } from '../qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiExpressionBase } from '@qti-components/base';\n\n// <qti-custom-operator definition=\"trim\">\nexport class QtiTestVariables extends QtiExpression<number> {\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n\n #testElement: QtiAssessmentTest;\n\n constructor() {\n super();\n this.addEventListener('qti-assessment-test-connected', (e: CustomEvent) => (this.#testElement = e.detail));\n }\n\n public override getResult() {\n // children can be a mix of qti-expression and qti-condition-expression\n const includedCategories = this.getAttribute('include-category')?.split(' ') ?? [];\n const excludedCategories = this.getAttribute('exclude-category')?.split(' ') ?? [];\n const weightIdentifier = this.getAttribute('weight-identifier') ?? '';\n const itemVariable = this.getAttribute('variable-identifier');\n\n const itemRefEls = Array.from<QtiAssessmentItemRef>(\n this.#testElement.querySelectorAll<QtiAssessmentItemRef>(`qti-asssessment-test qti-assessment-item-ref`)\n );\n\n const includedItems = itemRefEls\n .filter(itemRef => {\n let include = true;\n if (includedCategories.length > 0) {\n include = includedCategories.includes(itemRef.category);\n }\n if (excludedCategories.length > 0) {\n include = !excludedCategories.includes(itemRef.category);\n }\n return include;\n })\n .map(itemRef => {\n let weight = 1;\n if (weightIdentifier) {\n const weightVariable = itemRef.weigths.get(weightIdentifier);\n if (weightVariable !== null && weightVariable !== undefined) {\n weight = weightVariable;\n }\n }\n return { item: itemRef.identifier, weight };\n });\n\n const logic = new QtiTestVariablesExpression(this._testContext, itemVariable, includedItems);\n const value = logic.calculate();\n return value;\n }\n\n public override calculate() {\n return this.getResult();\n }\n}\n\nexport class QtiTestVariablesExpression implements QtiExpressionBase<number> {\n constructor(\n private testContext: TestContext,\n private itemVariable: string,\n private includedItems: { item: string; weight: number }[]\n ) {}\n\n calculate(): number {\n const { items } = this.testContext;\n let total = 0;\n const uniqueItems = [...new Set(this.includedItems.map(item => item.item))];\n items.forEach(item => {\n if (uniqueItems.includes(item.identifier)) {\n const variable = item.variables.find(vr => vr.identifier === this.itemVariable);\n const weight = this.includedItems.find(i => i.item === item.identifier)?.weight ?? 1;\n if (variable) {\n total += Number(variable.value) * weight;\n }\n }\n });\n return total;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test-variables': QtiTestVariables;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-test-variables.js","sourceRoot":"","sources":["../../../src/components/qti-test-variables/qti-test-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAMlF,MAAM,OAAO,gBAAiB,SAAQ,aAAqB;IAIzD,cAAc,GAA6B,IAAI,CAAC;IAEhD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CACnB,+BAA+B,EAC/B,CAAC,CAAiC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CACxE,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAoB,qBAAqB,CAAC,CAAC;IACvF,CAAC;IAEe,SAAS;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;YAC3F,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAE9D,MAAM,aAAa,GAAG,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACrF,IAAI,EAAE,OAAO,CAAC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AAC,YAAY,CAAC,CAAC;gBAChF,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;gBACrF,IAAI,QAAQ,EAAE,CAAC;oBACb,mEAAmE;oBACnE,sEAAsE;oBACtE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;wBACzB,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { consume } from '@lit/context';\n\nimport { testContext } from '@qti-components/base';\nimport { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { TestContext } from '@qti-components/base';\nimport type { QtiExpressionBase } from '@qti-components/base';\n\nexport class QtiTestVariables extends QtiExpression<number> {\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n this.addEventListener(\n 'qti-assessment-test-connected',\n (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail)\n );\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult() {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-test-variables: no enclosing qti-assessment-test, nothing to aggregate');\n return 0;\n }\n\n const weightIdentifier = this.getAttribute('weight-identifier') ?? '';\n const itemVariable = this.getAttribute('variable-identifier');\n\n const includedItems = selectItemRefs(testElement, selectionFrom(this)).map(itemRef => ({\n item: itemRef.identifier,\n weight: (weightIdentifier ? itemRef.weights.get(weightIdentifier) : undefined) ?? 1\n }));\n\n const logic = new QtiTestVariablesExpression(this._testContext, itemVariable, includedItems);\n const value = logic.calculate();\n return value;\n }\n\n public override calculate() {\n return this.getResult();\n }\n}\n\nexport class QtiTestVariablesExpression implements QtiExpressionBase<number> {\n constructor(\n private testContext: TestContext,\n private itemVariable: string,\n private includedItems: { item: string; weight: number }[]\n ) {}\n\n calculate(): number {\n const items = this.testContext?.items ?? [];\n let total = 0;\n const uniqueItems = [...new Set(this.includedItems.map(item => item.item))];\n items.forEach(item => {\n if (uniqueItems.includes(item.identifier)) {\n const variable = item.variables.find(vr => vr.identifier === this.itemVariable);\n const weight = this.includedItems.find(i => i.item === item.identifier)?.weight ?? 1;\n if (variable) {\n // An unscored item carries a non-numeric value; counting it as NaN\n // would poison the whole total rather than just its own contribution.\n const value = Number(variable.value);\n if (!Number.isNaN(value)) {\n total += value * weight;\n }\n }\n }\n });\n return total;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test-variables': QtiTestVariables;\n }\n}\n"]}
@@ -9,7 +9,7 @@ export declare class TestScoringButtons extends LitElement {
9
9
  protected createRenderRoot(): HTMLElement | DocumentFragment;
10
10
  connectedCallback(): void;
11
11
  protected computedContext?: ComputedContext;
12
- render(): import("lit").TemplateResult<1> | typeof nothing;
12
+ render(): typeof nothing | import("lit").TemplateResult<1>;
13
13
  constructor();
14
14
  }
15
15
  declare global {
@@ -2,6 +2,7 @@ import { QtiAssessmentItemRef } from './components/qti-assessment-item-ref/qti-a
2
2
  import { QtiAssessmentSection } from './components/qti-assessment-section/qti-assessment-section';
3
3
  import { QtiAssessmentTest } from './components/qti-assessment-test/qti-assessment-test';
4
4
  import { QtiItemSessionControl } from './components/qti-item-session-control/qti-item-session-control';
5
+ import { QtiNumberSelected } from './components/qti-number-selected/qti-number-selected';
5
6
  import { QtiOutcomeProcessing } from './components/qti-outcome-processing/qti-outcome-processing';
6
7
  import { QtiTestFeedback } from './components/qti-test-feedback/qti-test-feedback';
7
8
  import { QtiTestPart } from './components/qti-test-part/qti-test-part';
@@ -25,7 +26,7 @@ import { TestSectionLink } from './components/test-section-link/test-section-lin
25
26
  import { TestStamp } from './components/test-stamp/test-stamp';
26
27
  import { TestView } from './components/test-view-toggle/test-view';
27
28
  import { TestViewToggle } from './components/test-view-toggle/test-view-toggle';
28
- export { QtiAssessmentItemRef, QtiAssessmentSection, QtiAssessmentTest, QtiItemSessionControl, QtiOutcomeProcessing, QtiTest, QtiTestFeedback, QtiTestPart, QtiTestVariables, TestCheckItem, TestContainer, TestEndAttempt, TestItemLink, TestItemToSpeech, TestNavigation, TestNext, TestPagingButtonsStamp, TestPrev, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestSectionButtonsStamp, TestSectionLink, TestStamp, TestTtsNext, TestTtsPause, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop, TestView, TestViewToggle };
29
+ export { QtiAssessmentItemRef, QtiAssessmentSection, QtiAssessmentTest, QtiItemSessionControl, QtiNumberSelected, QtiOutcomeProcessing, QtiTest, QtiTestFeedback, QtiTestPart, QtiTestVariables, TestCheckItem, TestContainer, TestEndAttempt, TestItemLink, TestItemToSpeech, TestNavigation, TestNext, TestPagingButtonsStamp, TestPrev, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestSectionButtonsStamp, TestSectionLink, TestStamp, TestTtsNext, TestTtsPause, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop, TestView, TestViewToggle };
29
30
  export declare const qtiTestElements: readonly [{
30
31
  readonly tag: "qti-assessment-item-ref";
31
32
  readonly ctor: typeof QtiAssessmentItemRef;
@@ -38,6 +39,9 @@ export declare const qtiTestElements: readonly [{
38
39
  }, {
39
40
  readonly tag: "qti-item-session-control";
40
41
  readonly ctor: typeof QtiItemSessionControl;
42
+ }, {
43
+ readonly tag: "qti-number-selected";
44
+ readonly ctor: typeof QtiNumberSelected;
41
45
  }, {
42
46
  readonly tag: "qti-outcome-processing";
43
47
  readonly ctor: typeof QtiOutcomeProcessing;
package/dist/elements.js CHANGED
@@ -2,6 +2,7 @@ import { QtiAssessmentItemRef } from './components/qti-assessment-item-ref/qti-a
2
2
  import { QtiAssessmentSection } from './components/qti-assessment-section/qti-assessment-section';
3
3
  import { QtiAssessmentTest } from './components/qti-assessment-test/qti-assessment-test';
4
4
  import { QtiItemSessionControl } from './components/qti-item-session-control/qti-item-session-control';
5
+ import { QtiNumberSelected } from './components/qti-number-selected/qti-number-selected';
5
6
  import { QtiOutcomeProcessing } from './components/qti-outcome-processing/qti-outcome-processing';
6
7
  import { QtiTestFeedback } from './components/qti-test-feedback/qti-test-feedback';
7
8
  import { QtiTestPart } from './components/qti-test-part/qti-test-part';
@@ -25,12 +26,13 @@ import { TestSectionLink } from './components/test-section-link/test-section-lin
25
26
  import { TestStamp } from './components/test-stamp/test-stamp';
26
27
  import { TestView } from './components/test-view-toggle/test-view';
27
28
  import { TestViewToggle } from './components/test-view-toggle/test-view-toggle';
28
- export { QtiAssessmentItemRef, QtiAssessmentSection, QtiAssessmentTest, QtiItemSessionControl, QtiOutcomeProcessing, QtiTest, QtiTestFeedback, QtiTestPart, QtiTestVariables, TestCheckItem, TestContainer, TestEndAttempt, TestItemLink, TestItemToSpeech, TestNavigation, TestNext, TestPagingButtonsStamp, TestPrev, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestSectionButtonsStamp, TestSectionLink, TestStamp, TestTtsNext, TestTtsPause, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop, TestView, TestViewToggle };
29
+ export { QtiAssessmentItemRef, QtiAssessmentSection, QtiAssessmentTest, QtiItemSessionControl, QtiNumberSelected, QtiOutcomeProcessing, QtiTest, QtiTestFeedback, QtiTestPart, QtiTestVariables, TestCheckItem, TestContainer, TestEndAttempt, TestItemLink, TestItemToSpeech, TestNavigation, TestNext, TestPagingButtonsStamp, TestPrev, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestSectionButtonsStamp, TestSectionLink, TestStamp, TestTtsNext, TestTtsPause, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop, TestView, TestViewToggle };
29
30
  export const qtiTestElements = [
30
31
  { tag: 'qti-assessment-item-ref', ctor: QtiAssessmentItemRef },
31
32
  { tag: 'qti-assessment-section', ctor: QtiAssessmentSection },
32
33
  { tag: 'qti-assessment-test', ctor: QtiAssessmentTest },
33
34
  { tag: 'qti-item-session-control', ctor: QtiItemSessionControl },
35
+ { tag: 'qti-number-selected', ctor: QtiNumberSelected },
34
36
  { tag: 'qti-outcome-processing', ctor: QtiOutcomeProcessing },
35
37
  { tag: 'qti-test', ctor: QtiTest },
36
38
  { tag: 'qti-test-feedback', ctor: QtiTestFeedback },
@@ -1 +1 @@
1
- {"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8DAA8D,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gEAAgE,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAA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AE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,2BAA2B,EAAE,IAAI,EAAE,sBAAsB,EAAE;IAClE,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,gBAAgB,EAAE;IACrD,EAAE,GAAG,EAAE,2BAA2B,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC9D,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,kBAAkB,EAAE;IACzD,EAAE,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,mBAAmB,EAAE;IAC3D,EAAE,GAAG,EAAE,4BAA4B,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACpE,EAAE,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAE;IACnD,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;IACtC,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE;IAC7C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,cAAc,EAAE;CACzC,CAAC","sourcesContent":["import { QtiAssessmentItemRef } from './components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport { QtiAssessmentSection } from './components/qti-assessment-section/qti-assessment-section';\nimport { QtiAssessmentTest } from './components/qti-assessment-test/qti-assessment-test';\nimport { QtiItemSessionControl } from './components/qti-item-session-control/qti-item-session-control';\nimport { QtiOutcomeProcessing } from './components/qti-outcome-processing/qti-outcome-processing';\nimport { QtiTestFeedback } from './components/qti-test-feedback/qti-test-feedback';\nimport { QtiTestPart } from './components/qti-test-part/qti-test-part';\nimport { QtiTestVariables } from './components/qti-test-variables/qti-test-variables';\nimport { QtiTest } from './components/qti-test/qti-test';\nimport { TestCheckItem } from './components/test-check-item/test-check-item';\nimport { TestContainer } from './components/test-container/test-container';\nimport { TestEndAttempt } from './components/test-end-attempt/test-end-attempt';\nimport { TestItemLink } from './components/test-item-link/test-item-link';\nimport {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n} from './components/test-item-to-speech/test-item-to-speech';\nimport { TestNavigation } from './components/test-navigation/test-navigation';\nimport { TestNext } from './components/test-next/test-next';\nimport { TestPagingButtonsStamp } from './components/test-paging-buttons-stamp/test-paging-buttons-stamp';\nimport { TestPrev } from './components/test-prev/test-prev';\nimport { TestPrintContext } from './components/test-print-context/test-print-context';\nimport { TestPrintVariables } from './components/test-print-item-variables/test-print-item-variables';\nimport { TestScoringButtons } from './components/test-scoring-buttons/test-scoring-buttons';\nimport { TestScoringFeedback } from './components/test-scoring-feedback/test-scoring-feedback';\nimport { TestSectionButtonsStamp } from './components/test-section-buttons-stamp/test-section-buttons-stamp';\nimport { TestSectionLink } from './components/test-section-link/test-section-link';\nimport { TestStamp } from './components/test-stamp/test-stamp';\nimport { TestView } from './components/test-view-toggle/test-view';\nimport { TestViewToggle } from './components/test-view-toggle/test-view-toggle';\n\nexport {\n QtiAssessmentItemRef,\n QtiAssessmentSection,\n QtiAssessmentTest,\n QtiItemSessionControl,\n QtiOutcomeProcessing,\n QtiTest,\n QtiTestFeedback,\n QtiTestPart,\n QtiTestVariables,\n TestCheckItem,\n TestContainer,\n TestEndAttempt,\n TestItemLink,\n TestItemToSpeech,\n TestNavigation,\n TestNext,\n TestPagingButtonsStamp,\n TestPrev,\n TestPrintContext,\n TestPrintVariables,\n TestScoringButtons,\n TestScoringFeedback,\n TestSectionButtonsStamp,\n TestSectionLink,\n TestStamp,\n TestTtsNext,\n TestTtsPause,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop,\n TestView,\n TestViewToggle\n};\n\nexport const qtiTestElements = [\n { tag: 'qti-assessment-item-ref', ctor: QtiAssessmentItemRef },\n { tag: 'qti-assessment-section', ctor: QtiAssessmentSection },\n { tag: 'qti-assessment-test', ctor: QtiAssessmentTest },\n { tag: 'qti-item-session-control', ctor: QtiItemSessionControl },\n { tag: 'qti-outcome-processing', ctor: QtiOutcomeProcessing },\n { tag: 'qti-test', ctor: QtiTest },\n { tag: 'qti-test-feedback', ctor: QtiTestFeedback },\n { tag: 'qti-test-part', ctor: QtiTestPart },\n { tag: 'qti-test-variables', ctor: QtiTestVariables },\n { tag: 'test-check-item', ctor: TestCheckItem },\n { tag: 'test-container', ctor: TestContainer },\n { tag: 'test-end-attempt', ctor: TestEndAttempt },\n { tag: 'test-item-link', ctor: TestItemLink },\n { tag: 'test-item-to-speech', ctor: TestItemToSpeech },\n { tag: 'test-navigation', ctor: TestNavigation },\n { tag: 'test-next', ctor: TestNext },\n { tag: 'test-paging-buttons-stamp', ctor: TestPagingButtonsStamp },\n { tag: 'test-prev', ctor: TestPrev },\n { tag: 'test-print-context', ctor: TestPrintContext },\n { tag: 'test-print-item-variables', ctor: TestPrintVariables },\n { tag: 'test-scoring-buttons', ctor: TestScoringButtons },\n { tag: 'test-scoring-feedback', ctor: TestScoringFeedback },\n { tag: 'test-section-buttons-stamp', ctor: TestSectionButtonsStamp },\n { tag: 'test-section-link', ctor: TestSectionLink },\n { tag: 'test-stamp', ctor: TestStamp },\n { tag: 'test-tts-next', ctor: TestTtsNext },\n { tag: 'test-tts-pause', ctor: TestTtsPause },\n { tag: 'test-tts-play', ctor: TestTtsPlay },\n { tag: 'test-tts-prev', ctor: TestTtsPrev },\n { tag: 'test-tts-resume', ctor: TestTtsResume },\n { tag: 'test-tts-stop', ctor: TestTtsStop },\n { tag: 'test-view', ctor: TestView },\n { tag: 'test-view-toggle', ctor: TestViewToggle }\n] as const;\n"]}
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8DAA8D,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gEAAgE,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,sBA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GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,mBAAmB,EAAE;IAC3D,EAAE,GAAG,EAAE,4BAA4B,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACpE,EAAE,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAE;IACnD,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;IACtC,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE;IAC7C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,cAAc,EAAE;CACzC,CAAC","sourcesContent":["import { QtiAssessmentItemRef } from './components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport { QtiAssessmentSection } from './components/qti-assessment-section/qti-assessment-section';\nimport { QtiAssessmentTest } from './components/qti-assessment-test/qti-assessment-test';\nimport { QtiItemSessionControl } from './components/qti-item-session-control/qti-item-session-control';\nimport { QtiNumberSelected } from './components/qti-number-selected/qti-number-selected';\nimport { QtiOutcomeProcessing } from './components/qti-outcome-processing/qti-outcome-processing';\nimport { QtiTestFeedback } from './components/qti-test-feedback/qti-test-feedback';\nimport { QtiTestPart } from './components/qti-test-part/qti-test-part';\nimport { QtiTestVariables } from './components/qti-test-variables/qti-test-variables';\nimport { QtiTest } from './components/qti-test/qti-test';\nimport { TestCheckItem } from './components/test-check-item/test-check-item';\nimport { TestContainer } from './components/test-container/test-container';\nimport { TestEndAttempt } from './components/test-end-attempt/test-end-attempt';\nimport { TestItemLink } from './components/test-item-link/test-item-link';\nimport {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n} from './components/test-item-to-speech/test-item-to-speech';\nimport { TestNavigation } from './components/test-navigation/test-navigation';\nimport { TestNext } from './components/test-next/test-next';\nimport { TestPagingButtonsStamp } from './components/test-paging-buttons-stamp/test-paging-buttons-stamp';\nimport { TestPrev } from './components/test-prev/test-prev';\nimport { TestPrintContext } from './components/test-print-context/test-print-context';\nimport { TestPrintVariables } from './components/test-print-item-variables/test-print-item-variables';\nimport { TestScoringButtons } from './components/test-scoring-buttons/test-scoring-buttons';\nimport { TestScoringFeedback } from './components/test-scoring-feedback/test-scoring-feedback';\nimport { TestSectionButtonsStamp } from './components/test-section-buttons-stamp/test-section-buttons-stamp';\nimport { TestSectionLink } from './components/test-section-link/test-section-link';\nimport { TestStamp } from './components/test-stamp/test-stamp';\nimport { TestView } from './components/test-view-toggle/test-view';\nimport { TestViewToggle } from './components/test-view-toggle/test-view-toggle';\n\nexport {\n QtiAssessmentItemRef,\n QtiAssessmentSection,\n QtiAssessmentTest,\n QtiItemSessionControl,\n QtiNumberSelected,\n QtiOutcomeProcessing,\n QtiTest,\n QtiTestFeedback,\n QtiTestPart,\n QtiTestVariables,\n TestCheckItem,\n TestContainer,\n TestEndAttempt,\n TestItemLink,\n TestItemToSpeech,\n TestNavigation,\n TestNext,\n TestPagingButtonsStamp,\n TestPrev,\n TestPrintContext,\n TestPrintVariables,\n TestScoringButtons,\n TestScoringFeedback,\n TestSectionButtonsStamp,\n TestSectionLink,\n TestStamp,\n TestTtsNext,\n TestTtsPause,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop,\n TestView,\n TestViewToggle\n};\n\nexport const qtiTestElements = [\n { tag: 'qti-assessment-item-ref', ctor: QtiAssessmentItemRef },\n { tag: 'qti-assessment-section', ctor: QtiAssessmentSection },\n { tag: 'qti-assessment-test', ctor: QtiAssessmentTest },\n { tag: 'qti-item-session-control', ctor: QtiItemSessionControl },\n { tag: 'qti-number-selected', ctor: QtiNumberSelected },\n { tag: 'qti-outcome-processing', ctor: QtiOutcomeProcessing },\n { tag: 'qti-test', ctor: QtiTest },\n { tag: 'qti-test-feedback', ctor: QtiTestFeedback },\n { tag: 'qti-test-part', ctor: QtiTestPart },\n { tag: 'qti-test-variables', ctor: QtiTestVariables },\n { tag: 'test-check-item', ctor: TestCheckItem },\n { tag: 'test-container', ctor: TestContainer },\n { tag: 'test-end-attempt', ctor: TestEndAttempt },\n { tag: 'test-item-link', ctor: TestItemLink },\n { tag: 'test-item-to-speech', ctor: TestItemToSpeech },\n { tag: 'test-navigation', ctor: TestNavigation },\n { tag: 'test-next', ctor: TestNext },\n { tag: 'test-paging-buttons-stamp', ctor: TestPagingButtonsStamp },\n { tag: 'test-prev', ctor: TestPrev },\n { tag: 'test-print-context', ctor: TestPrintContext },\n { tag: 'test-print-item-variables', ctor: TestPrintVariables },\n { tag: 'test-scoring-buttons', ctor: TestScoringButtons },\n { tag: 'test-scoring-feedback', ctor: TestScoringFeedback },\n { tag: 'test-section-buttons-stamp', ctor: TestSectionButtonsStamp },\n { tag: 'test-section-link', ctor: TestSectionLink },\n { tag: 'test-stamp', ctor: TestStamp },\n { tag: 'test-tts-next', ctor: TestTtsNext },\n { tag: 'test-tts-pause', ctor: TestTtsPause },\n { tag: 'test-tts-play', ctor: TestTtsPlay },\n { tag: 'test-tts-prev', ctor: TestTtsPrev },\n { tag: 'test-tts-resume', ctor: TestTtsResume },\n { tag: 'test-tts-stop', ctor: TestTtsStop },\n { tag: 'test-view', ctor: TestView },\n { tag: 'test-view-toggle', ctor: TestViewToggle }\n] as const;\n"]}
@@ -0,0 +1,27 @@
1
+ import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';
2
+ import type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';
3
+ /**
4
+ * How the test-level expressions choose which item references they read.
5
+ *
6
+ * `qti-test-variables` and `qti-number-selected` select over the same set with
7
+ * the same attributes, so the rules live here rather than in either element.
8
+ */
9
+ /** `category`, `include-category` and `exclude-category` are space-separated lists. */
10
+ export declare const categoryList: (value: string | null | undefined) => string[];
11
+ export interface ItemRefSelection {
12
+ /** Only item refs inside the section with this identifier; every section when absent. */
13
+ sectionIdentifier?: string | null;
14
+ includeCategories: string[];
15
+ excludeCategories: string[];
16
+ }
17
+ /** Read the selection attributes an expression element carries. */
18
+ export declare const selectionFrom: (element: Element) => ItemRefSelection;
19
+ /**
20
+ * The item refs of a test that a selection covers.
21
+ *
22
+ * Both category attributes may be present, and then both have to hold: an item
23
+ * ref qualifies when it carries one of the included categories and none of the
24
+ * excluded ones. Its own `category` is a list too, so matching any entry of it
25
+ * is enough.
26
+ */
27
+ export declare const selectItemRefs: (testElement: QtiAssessmentTest, { sectionIdentifier, includeCategories, excludeCategories }: ItemRefSelection) => QtiAssessmentItemRef[];
@@ -0,0 +1,44 @@
1
+ /**
2
+ * How the test-level expressions choose which item references they read.
3
+ *
4
+ * `qti-test-variables` and `qti-number-selected` select over the same set with
5
+ * the same attributes, so the rules live here rather than in either element.
6
+ */
7
+ /** `category`, `include-category` and `exclude-category` are space-separated lists. */
8
+ export const categoryList = (value) => value?.split(/\s+/).filter(Boolean) ?? [];
9
+ /** Read the selection attributes an expression element carries. */
10
+ export const selectionFrom = (element) => ({
11
+ sectionIdentifier: element.getAttribute('section-identifier'),
12
+ includeCategories: categoryList(element.getAttribute('include-category')),
13
+ excludeCategories: categoryList(element.getAttribute('exclude-category'))
14
+ });
15
+ /**
16
+ * The item refs of a test that a selection covers.
17
+ *
18
+ * Both category attributes may be present, and then both have to hold: an item
19
+ * ref qualifies when it carries one of the included categories and none of the
20
+ * excluded ones. Its own `category` is a list too, so matching any entry of it
21
+ * is enough.
22
+ */
23
+ export const selectItemRefs = (testElement, { sectionIdentifier, includeCategories, excludeCategories }) => {
24
+ const scopes = sectionIdentifier
25
+ ? Array.from(testElement.querySelectorAll(`qti-assessment-section[identifier="${CSS.escape(sectionIdentifier)}"]`))
26
+ : [testElement];
27
+ if (scopes.length === 0) {
28
+ console.warn(`no qti-assessment-section with identifier "${sectionIdentifier}"`);
29
+ return [];
30
+ }
31
+ return scopes
32
+ .flatMap(scope => Array.from(scope.querySelectorAll('qti-assessment-item-ref')))
33
+ .filter(itemRef => {
34
+ const categories = categoryList(itemRef.category);
35
+ if (includeCategories.length > 0 && !categories.some(c => includeCategories.includes(c))) {
36
+ return false;
37
+ }
38
+ if (excludeCategories.length > 0 && categories.some(c => excludeCategories.includes(c))) {
39
+ return false;
40
+ }
41
+ return true;
42
+ });
43
+ };
44
+ //# sourceMappingURL=item-ref-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-ref-selection.js","sourceRoot":"","sources":["../../src/internal/item-ref-selection.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAgC,EAAY,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAStH,mEAAmE;AACnE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAoB,EAAE,CAAC,CAAC;IACpE,iBAAiB,EAAE,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC;IAC7D,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;IACzE,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;CAC1E,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,WAA8B,EAC9B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAoB,EACrD,EAAE;IAC1B,MAAM,MAAM,GAAG,iBAAiB;QAC9B,CAAC,CAAC,KAAK,CAAC,IAAI,CACR,WAAW,CAAC,gBAAgB,CAAC,sCAAsC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CACtG;QACH,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAClB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,8CAA8C,iBAAiB,GAAG,CAAC,CAAC;QACjF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,MAAM;SACV,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAuB,yBAAyB,CAAC,CAAC,CAAC;SACrG,MAAM,CAAC,OAAO,CAAC,EAAE;QAChB,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClD,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACzF,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACxF,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\n\n/**\n * How the test-level expressions choose which item references they read.\n *\n * `qti-test-variables` and `qti-number-selected` select over the same set with\n * the same attributes, so the rules live here rather than in either element.\n */\n\n/** `category`, `include-category` and `exclude-category` are space-separated lists. */\nexport const categoryList = (value: string | null | undefined): string[] => value?.split(/\\s+/).filter(Boolean) ?? [];\n\nexport interface ItemRefSelection {\n /** Only item refs inside the section with this identifier; every section when absent. */\n sectionIdentifier?: string | null;\n includeCategories: string[];\n excludeCategories: string[];\n}\n\n/** Read the selection attributes an expression element carries. */\nexport const selectionFrom = (element: Element): ItemRefSelection => ({\n sectionIdentifier: element.getAttribute('section-identifier'),\n includeCategories: categoryList(element.getAttribute('include-category')),\n excludeCategories: categoryList(element.getAttribute('exclude-category'))\n});\n\n/**\n * The item refs of a test that a selection covers.\n *\n * Both category attributes may be present, and then both have to hold: an item\n * ref qualifies when it carries one of the included categories and none of the\n * excluded ones. Its own `category` is a list too, so matching any entry of it\n * is enough.\n */\nexport const selectItemRefs = (\n testElement: QtiAssessmentTest,\n { sectionIdentifier, includeCategories, excludeCategories }: ItemRefSelection\n): QtiAssessmentItemRef[] => {\n const scopes = sectionIdentifier\n ? Array.from(\n testElement.querySelectorAll(`qti-assessment-section[identifier=\"${CSS.escape(sectionIdentifier)}\"]`)\n )\n : [testElement];\n if (scopes.length === 0) {\n console.warn(`no qti-assessment-section with identifier \"${sectionIdentifier}\"`);\n return [];\n }\n\n return scopes\n .flatMap(scope => Array.from(scope.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref')))\n .filter(itemRef => {\n const categories = categoryList(itemRef.category);\n if (includeCategories.length > 0 && !categories.some(c => includeCategories.includes(c))) {\n return false;\n }\n if (excludeCategories.length > 0 && categories.some(c => excludeCategories.includes(c))) {\n return false;\n }\n return true;\n });\n};\n"]}
@@ -28,7 +28,6 @@ export const TestBaseMixin = (superClass) => {
28
28
  const context = assessmentItem._context;
29
29
  const identifier = context.identifier;
30
30
  const fullVariables = context.variables;
31
- // console.log(this._testContext);
32
31
  // Find the corresponding item in the test context by identifier
33
32
  const itemContext = this.testContext.items.find(i => i?.identifier === identifier);
34
33
  if (!itemContext) {
@@ -1 +1 @@
1
- {"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAuB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAoBpG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAoC,UAAa,EAAE,EAAE;IAChF,MAAe,aAAc,SAAQ,UAAU;QAW7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YATV,gBAAW,GAA0B,oBAAoB,CAAC;YAI1D,mBAAc,GAA6B,uBAAuB,CAAC;YAuH1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAI,cAAsB,CAAC,QAAQ,CAAC;gBACjD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;gBAExC,kCAAkC;gBAClC,gEAAgE;gBAChE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC;gBAEnF,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,8DAA8D,UAAU,gBAAgB,CAAC,CAAC;oBACvG,OAAO;gBACT,CAAC;gBAED,2EAA2E;gBAC3E,IAAI,W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AAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC;4BAE/F,gFAAgF;4BAChF,OAAO,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;wBAC5E,CAAC,CAAC;wBACF,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC5E,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;YACF,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAC3G,CAAC;QACJ,CAAC;KA2CF;IApKQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IAkK5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;\n}\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void {\n // Update variables in the testContext for the specified itemRefID\n const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);\n if (itemContext) {\n itemContext.variables = itemContext.variables.map(variable => {\n const updatedVariable = variables.find(v => v.identifier === variable.identifier);\n return updatedVariable ? { ...variable, ...updatedVariable } : variable;\n });\n }\n // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well\n const itemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemRefID}\"]`\n );\n if (itemRef && itemRef.assessmentItem) {\n itemRef.assessmentItem.variables = variables;\n }\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qti-assessment-test-connected`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n this.addEventListener('qti-assessment-test-connected', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state']\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {})\n };\n })\n };\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = (assessmentItem as any)._context;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // console.log(this._testContext);\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n }\n };\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]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,gFAAgF;4BAChF,OAAO,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;wBAC5E,CAAC,CAAC;wBACF,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC5E,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;YACF,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAC3G,CAAC;QACJ,CAAC;KA0CF;IAnKQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IAiK5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;\n}\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void {\n // Update variables in the testContext for the specified itemRefID\n const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);\n if (itemContext) {\n itemContext.variables = itemContext.variables.map(variable => {\n const updatedVariable = variables.find(v => v.identifier === variable.identifier);\n return updatedVariable ? { ...variable, ...updatedVariable } : variable;\n });\n }\n // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well\n const itemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemRefID}\"]`\n );\n if (itemRef && itemRef.assessmentItem) {\n itemRef.assessmentItem.variables = variables;\n }\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qti-assessment-test-connected`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n this.addEventListener('qti-assessment-test-connected', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state']\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {})\n };\n })\n };\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = (assessmentItem as any)._context;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n }\n };\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@qti-components/test",
3
3
  "description": "QTI test utilities",
4
- "version": "1.6.2",
4
+ "version": "1.7.0",
5
5
  "author": "",
6
6
  "dependencies": {
7
7
  "@heximal/templates": "^0.1.5",
8
- "@qti-components/base": "^2.2.0",
9
- "@qti-components/elements": "^1.7.0",
8
+ "@qti-components/base": "^2.3.0",
9
+ "@qti-components/elements": "^1.8.0",
10
10
  "@qti-components/interactions": "^1.10.4",
11
- "@qti-components/processing": "^1.5.0",
12
- "@qti-components/theme": "^2.2.0",
13
- "@qti-components/transformers": "^1.7.2",
11
+ "@qti-components/processing": "^1.6.0",
12
+ "@qti-components/theme": "^2.2.1",
13
+ "@qti-components/transformers": "^1.7.3",
14
14
  "@qti-components/utilities": "^1.3.3"
15
15
  },
16
16
  "devDependencies": {