@qti-components/test 1.6.2 → 1.8.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.
Files changed (41) hide show
  1. package/dist/components/index.d.ts +1 -0
  2. package/dist/components/index.js +1 -0
  3. package/dist/components/index.js.map +1 -1
  4. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +38 -3
  5. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +128 -16
  6. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
  7. package/dist/components/qti-number-selected/qti-number-selected.d.ts +24 -0
  8. package/dist/components/qti-number-selected/qti-number-selected.js +42 -0
  9. package/dist/components/qti-number-selected/qti-number-selected.js.map +1 -0
  10. package/dist/components/qti-outcome-processing/qti-outcome-processing.js +12 -2
  11. package/dist/components/qti-outcome-processing/qti-outcome-processing.js.map +1 -1
  12. package/dist/components/qti-test-variables/qti-test-variables.js +28 -30
  13. package/dist/components/qti-test-variables/qti-test-variables.js.map +1 -1
  14. package/dist/components/styles.d.ts +3 -0
  15. package/dist/components/styles.js +29 -4
  16. package/dist/components/styles.js.map +1 -1
  17. package/dist/components/test-check-item/test-check-item.js +6 -0
  18. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  19. package/dist/components/test-end-attempt/test-end-attempt.js +6 -0
  20. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  21. package/dist/components/test-item-link/test-item-link.js +6 -0
  22. package/dist/components/test-item-link/test-item-link.js.map +1 -1
  23. package/dist/components/test-item-to-speech/test-item-to-speech.d.ts +82 -11
  24. package/dist/components/test-item-to-speech/test-item-to-speech.js +429 -62
  25. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
  26. package/dist/components/test-next/test-next.js +6 -0
  27. package/dist/components/test-next/test-next.js.map +1 -1
  28. package/dist/components/test-prev/test-prev.js +6 -0
  29. package/dist/components/test-prev/test-prev.js.map +1 -1
  30. package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +1 -1
  31. package/dist/components/test-section-link/test-section-link.js +6 -0
  32. package/dist/components/test-section-link/test-section-link.js.map +1 -1
  33. package/dist/elements.d.ts +9 -2
  34. package/dist/elements.js +5 -2
  35. package/dist/elements.js.map +1 -1
  36. package/dist/internal/item-ref-selection.d.ts +27 -0
  37. package/dist/internal/item-ref-selection.js +44 -0
  38. package/dist/internal/item-ref-selection.js.map +1 -0
  39. package/dist/mixins/test-base.js +0 -1
  40. package/dist/mixins/test-base.js.map +1 -1
  41. package/package.json +6 -6
@@ -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,52 @@
1
1
  import { LitElement } from 'lit';
2
+ import type { ComputedContext, ComputedItem } from '@qti-components/base';
2
3
  import type { QtiAssessmentItem } from '@qti-components/elements';
3
4
  import type { TemplateFunction } from '@heximal/templates';
5
+ /**
6
+ * The model a `<template item-ref>` is rendered with.
7
+ *
8
+ * Only what this element already knows: the item's parsed document and the
9
+ * attributes off the item-ref itself. `itemRef` is the escape hatch — a
10
+ * template that needs anything else (a click handler, a value from the host
11
+ * app) reaches it through a property on the element, which the host is free to
12
+ * set.
13
+ */
14
+ export interface ItemRefTemplateModel {
15
+ /** The item's parsed document, i.e. what the element renders by default. */
16
+ xmlDoc: DocumentFragment;
17
+ identifier?: string;
18
+ href?: string;
19
+ category?: string;
20
+ /**
21
+ * This item's entry in the computed context, the same object the stamps
22
+ * iterate as `item`: `index` (1-based, null for info items), `score`,
23
+ * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.
24
+ */
25
+ item?: ComputedItem;
26
+ /** The element being rendered. */
27
+ itemRef: QtiAssessmentItemRef;
28
+ }
4
29
  export declare class QtiAssessmentItemRef extends LitElement {
30
+ #private;
5
31
  category?: string;
6
32
  identifier?: string;
7
33
  required?: boolean;
8
34
  fixed?: boolean;
9
35
  href?: string;
10
- weigths: Map<string, number>;
11
- xmlDoc: DocumentFragment;
36
+ protected computedContext?: ComputedContext;
37
+ /**
38
+ * The `<qti-weight>` children of this ref, keyed by identifier — what
39
+ * `qti-test-variables`' `weight-identifier` resolves against.
40
+ *
41
+ * Read on access rather than cached: the test document is rendered into this
42
+ * element's light DOM, so the weights are not in place at construction time,
43
+ * and outcome processing runs long after they are.
44
+ */
45
+ get weights(): Map<string, number>;
46
+ xmlDoc: DocumentFragment | null;
12
47
  protected createRenderRoot(): HTMLElement | DocumentFragment;
13
48
  get assessmentItem(): QtiAssessmentItem | null;
14
- myTemplate: TemplateFunction;
49
+ myTemplate: TemplateFunction | null;
15
50
  connectedCallback(): Promise<void>;
16
51
  render(): unknown;
17
52
  }
@@ -4,8 +4,11 @@ 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';
8
- import { property } from 'lit/decorators.js';
7
+ import { LitElement, nothing } from 'lit';
8
+ import { property, state } from 'lit/decorators.js';
9
+ import { consume } from '@lit/context';
10
+ import { prepareTemplate } from '@heximal/templates';
11
+ import { computedContext } from '@qti-components/base';
9
12
  // Converter function to interpret "true" and "false" as booleans
10
13
  const stringToBooleanConverter = {
11
14
  fromAttribute(value) {
@@ -19,9 +22,39 @@ const stringToBooleanConverter = {
19
22
  export class QtiAssessmentItemRef extends LitElement {
20
23
  constructor() {
21
24
  super(...arguments);
22
- // @consume({ context: computedContext, subscribe: true })
23
- // private computedContext: ComputedContext;
24
- this.weigths = new Map();
25
+ this.xmlDoc = null;
26
+ this.myTemplate = null;
27
+ /**
28
+ * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned
29
+ * once per document and template, not per render: re-renders from
30
+ * computed-context changes then hand Lit the same fragment, which it leaves
31
+ * alone, instead of rebuilding the item (and reloading its PCIs, which
32
+ * changes the context again).
33
+ */
34
+ this.#rendered = null;
35
+ }
36
+ /**
37
+ * The `<qti-weight>` children of this ref, keyed by identifier — what
38
+ * `qti-test-variables`' `weight-identifier` resolves against.
39
+ *
40
+ * Read on access rather than cached: the test document is rendered into this
41
+ * element's light DOM, so the weights are not in place at construction time,
42
+ * and outcome processing runs long after they are.
43
+ */
44
+ get weights() {
45
+ const weights = new Map();
46
+ for (const weight of this.querySelectorAll(':scope > qti-weight')) {
47
+ const identifier = weight.getAttribute('identifier');
48
+ if (!identifier)
49
+ continue;
50
+ const value = Number(weight.getAttribute('value'));
51
+ if (Number.isNaN(value)) {
52
+ console.warn(`qti-weight "${identifier}" has a non-numeric value, ignoring it`);
53
+ continue;
54
+ }
55
+ weights.set(identifier, value);
56
+ }
57
+ return weights;
25
58
  }
26
59
  createRenderRoot() {
27
60
  return this;
@@ -29,20 +62,54 @@ export class QtiAssessmentItemRef extends LitElement {
29
62
  get assessmentItem() {
30
63
  return this.renderRoot?.querySelector('qti-assessment-item');
31
64
  }
65
+ /**
66
+ * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way
67
+ * up.
68
+ *
69
+ * `<test-container>` renders its items into a shadow root, so an item-ref is
70
+ * usually one hop below one; but it is also valid in plain light DOM, and a
71
+ * host is free to nest it deeper. Climbing root by root covers all three
72
+ * without assuming any of them.
73
+ */
74
+ #findTestElement() {
75
+ const own = this.closest('qti-test');
76
+ if (own)
77
+ return own;
78
+ let root = this.getRootNode();
79
+ while (root instanceof ShadowRoot) {
80
+ const test = root.host.closest('qti-test');
81
+ if (test)
82
+ return test;
83
+ root = root.host.getRootNode();
84
+ }
85
+ // A Document, or a fragment that is not attached to one: nowhere left to climb.
86
+ return null;
87
+ }
32
88
  async connectedCallback() {
33
89
  super.connectedCallback();
34
90
  /*
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>
91
+ Optional per-item template, used to render extra things around an item —
92
+ a bookmark, an index number, a score badge. Put it in the light DOM of
93
+ your qti-test, and every item-ref in the test renders with it:
94
+
95
+ <qti-test>
96
+ <template item-ref>
97
+ <div class="badge">{{ identifier }}</div>
98
+ {{ xmlDoc }}
99
+ </template>
100
+ …
101
+ </qti-test>
102
+
103
+ The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;
104
+ leaving it out renders the chrome and no item. Without a template the
105
+ element renders the item on its own, exactly as before.
106
+
107
+ Resolved once, on connect: one template serves every item, and everything
108
+ that varies per item comes through the model (see ItemRefTemplateModel).
41
109
  */
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);
110
+ const templateElement = this.#findTestElement()?.querySelector('template[item-ref]');
111
+ this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
112
+ this.requestUpdate();
46
113
  await this.updateComplete;
47
114
  this.dispatchEvent(new CustomEvent('qti-assessment-item-ref-connected', {
48
115
  bubbles: true,
@@ -50,8 +117,49 @@ export class QtiAssessmentItemRef extends LitElement {
50
117
  detail: { identifier: this.identifier, href: this.href, category: this.category }
51
118
  }));
52
119
  }
120
+ #computedItem() {
121
+ for (const testPart of this.computedContext?.testParts ?? []) {
122
+ for (const section of testPart.sections) {
123
+ const item = section.items.find(i => i.identifier === this.identifier);
124
+ if (item)
125
+ return item;
126
+ }
127
+ }
128
+ return undefined;
129
+ }
130
+ /**
131
+ * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned
132
+ * once per document and template, not per render: re-renders from
133
+ * computed-context changes then hand Lit the same fragment, which it leaves
134
+ * alone, instead of rebuilding the item (and reloading its PCIs, which
135
+ * changes the context again).
136
+ */
137
+ #rendered;
53
138
  render() {
54
- return this.myTemplate ? this.myTemplate({ xmlDoc: this.xmlDoc }) : this.xmlDoc;
139
+ // Item refs connect before loading, and navigation clears their documents.
140
+ if (!this.xmlDoc) {
141
+ this.#rendered = null;
142
+ return nothing;
143
+ }
144
+ if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {
145
+ this.#rendered = {
146
+ source: this.xmlDoc,
147
+ template: this.myTemplate,
148
+ doc: this.xmlDoc.cloneNode(true)
149
+ };
150
+ }
151
+ const xmlDoc = this.#rendered.doc;
152
+ if (!this.myTemplate)
153
+ return xmlDoc;
154
+ const model = {
155
+ xmlDoc,
156
+ identifier: this.identifier,
157
+ href: this.href,
158
+ category: this.category,
159
+ item: this.#computedItem(),
160
+ itemRef: this
161
+ };
162
+ return this.myTemplate(model);
55
163
  }
56
164
  }
57
165
  __decorate([
@@ -69,6 +177,10 @@ __decorate([
69
177
  __decorate([
70
178
  property({ type: String })
71
179
  ], QtiAssessmentItemRef.prototype, "href", void 0);
180
+ __decorate([
181
+ state(),
182
+ consume({ context: computedContext, subscribe: true })
183
+ ], QtiAssessmentItemRef.prototype, "computedContext", void 0);
72
184
  __decorate([
73
185
  property({ type: Object, attribute: false })
74
186
  ], QtiAssessmentItemRef.prototype, "xmlDoc", void 0);
@@ -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,CAA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AAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AAQ1C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACnB","sourcesContent":["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,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAMvD,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;AA2BF,4CAA4C;AAC5C,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAApD;;QAoCE,WAAM,GAA4B,IAAI,CAAC;QAUvC,eAAU,GAA4B,IAAI,CAAC;QAyE3C;;;;;;WAMG;QACH,cAAS,GAAkG,IAAI,CAAC;IA6BlH,CAAC;IA/IC;;;;;;;OAOG;IACH,IAAI,OAAO;QACT,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,gBAAg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EAAE,CAAC;oDACN","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\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 /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\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 // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected 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 #computedItem(): ComputedItem | undefined {\n for (const testPart of this.computedContext?.testParts ?? []) {\n for (const section of testPart.sections) {\n const item = section.items.find(i => i.identifier === this.identifier);\n if (item) return item;\n }\n }\n return undefined;\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\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 item: this.#computedItem(),\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,0CAA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AC,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,MAA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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"]}
@@ -1,4 +1,7 @@
1
1
  export declare const form: import("lit").CSSResult;
2
2
  export declare const btn: import("lit").CSSResult;
3
+ /** Hover and keyboard focus; paint only, so the box never moves. */
4
+ export declare const btnInteractive: import("lit").CSSResult;
5
+ export declare const focusRing: import("lit").CSSResult;
3
6
  export declare const dis: import("lit").CSSResult;
4
7
  export declare const ind: import("lit").CSSResult;
@@ -1,20 +1,45 @@
1
1
  // /* eslint-disable lit-plugin(no-invalid-css) */
2
2
  import { css } from 'lit';
3
+ /*
4
+ * The resting look of the test controls (next, prev, item/section links, TTS buttons).
5
+ *
6
+ * Paint reads the qti-theme tokens, so a theme or brand that re-values them repaints the test
7
+ * chrome along with the items; every token has a literal fallback equal to the theme's own
8
+ * default, so the controls look the same without qti-theme loaded. A `--test-button-*` slot
9
+ * in front of each token repaints the test controls alone.
10
+ */
3
11
  export const form = css `
4
12
  display: inline-flex;
5
13
  align-items: center;
14
+ justify-content: center;
15
+ gap: 0.375em;
16
+ box-sizing: border-box;
17
+ min-block-size: var(--test-button-size, 2.25rem);
18
+ padding: 0 0.875rem;
19
+ font: inherit;
20
+ line-height: 1.25;
6
21
  cursor: pointer;
7
- padding: 0.5rem 1rem;
8
- border-radius: 0.25rem;
9
22
  user-select: none;
23
+ border-radius: var(--test-button-border-radius, var(--qti-component-border-radius, 0.2rem));
10
24
  `;
11
25
  export const btn = css `
12
- background-color: lightgray;
13
26
  ${form};
27
+ background-color: var(--test-button-background-color, var(--qti-component-background-color, #fff));
28
+ color: var(--test-button-color, var(--qti-component-color, inherit));
29
+ border: var(--qti-component-border-width, 1px) var(--qti-component-border-style, solid)
30
+ var(--test-button-border-color, var(--qti-component-border-color, #0175aa));
31
+ `;
32
+ /** Hover and keyboard focus; paint only, so the box never moves. */
33
+ export const btnInteractive = css `
34
+ background-color: var(--test-button-hover-background-color, var(--qti-bg-active, #f2f8fb));
35
+ `;
36
+ export const focusRing = css `
37
+ outline: var(--qti-focus-border-width, 2px) solid var(--qti-focus-color, #007ac3);
38
+ outline-offset: 2px;
14
39
  `;
15
40
  export const dis = css `
16
41
  cursor: not-allowed;
17
- opacity: 0.8;
42
+ opacity: 0.45;
18
43
  `;
19
44
  export const ind = css `
20
45
  ${form};
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/components/styles.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAA;;;;;;;CAOtB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;;IAElB,IAAI;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;;;CAGrB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;IAClB,IAAI;;CAEP,CAAC","sourcesContent":["// /* eslint-disable lit-plugin(no-invalid-css) */\nimport { css } from 'lit';\n\nexport const form = css`\n display: inline-flex;\n align-items: center;\n cursor: pointer;\n padding: 0.5rem 1rem;\n border-radius: 0.25rem;\n user-select: none;\n`;\n\nexport const btn = css`\n background-color: lightgray;\n ${form};\n`;\n\nexport const dis = css`\n cursor: not-allowed;\n opacity: 0.8;\n`;\n\nexport const ind = css`\n ${form};\n border: 1px solid gray;\n`;\n"]}
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/components/styles.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAA;;;;;;;;;;;;;CAatB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;IAClB,IAAI;;;;;CAKP,CAAC;AAEF,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;CAEhC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;;;CAG3B,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;;;CAGrB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;IAClB,IAAI;;CAEP,CAAC","sourcesContent":["// /* eslint-disable lit-plugin(no-invalid-css) */\nimport { css } from 'lit';\n\n/*\n * The resting look of the test controls (next, prev, item/section links, TTS buttons).\n *\n * Paint reads the qti-theme tokens, so a theme or brand that re-values them repaints the test\n * chrome along with the items; every token has a literal fallback equal to the theme's own\n * default, so the controls look the same without qti-theme loaded. A `--test-button-*` slot\n * in front of each token repaints the test controls alone.\n */\n\nexport const form = css`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 0.375em;\n box-sizing: border-box;\n min-block-size: var(--test-button-size, 2.25rem);\n padding: 0 0.875rem;\n font: inherit;\n line-height: 1.25;\n cursor: pointer;\n user-select: none;\n border-radius: var(--test-button-border-radius, var(--qti-component-border-radius, 0.2rem));\n`;\n\nexport const btn = css`\n ${form};\n background-color: var(--test-button-background-color, var(--qti-component-background-color, #fff));\n color: var(--test-button-color, var(--qti-component-color, inherit));\n border: var(--qti-component-border-width, 1px) var(--qti-component-border-style, solid)\n var(--test-button-border-color, var(--qti-component-border-color, #0175aa));\n`;\n\n/** Hover and keyboard focus; paint only, so the box never moves. */\nexport const btnInteractive = css`\n background-color: var(--test-button-hover-background-color, var(--qti-bg-active, #f2f8fb));\n`;\n\nexport const focusRing = css`\n outline: var(--qti-focus-border-width, 2px) solid var(--qti-focus-color, #007ac3);\n outline-offset: 2px;\n`;\n\nexport const dis = css`\n cursor: not-allowed;\n opacity: 0.45;\n`;\n\nexport const ind = css`\n ${form};\n border: 1px solid gray;\n`;\n"]}