@qti-components/delivery 0.1.0-next.0 → 0.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './model/test-model.js';
2
+ export * from './model/item-facts.js';
2
3
  export type { XmlElement, XmlNode } from './model/xml-node.js';
3
4
  export * from './random/seeded-random.js';
4
5
  export * from './random/shuffle.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './model/test-model.js';
2
+ export * from './model/item-facts.js';
2
3
  export * from './random/seeded-random.js';
3
4
  export * from './random/shuffle.js';
4
5
  export * from './state/clock.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AAEtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './random/seeded-random.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './random/seeded-random.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\n"]}
@@ -0,0 +1,34 @@
1
+ import type { XmlElement } from './xml-node.js';
2
+ /**
3
+ * What a `qti-assessment-item` says about itself, read from its XML when it is fetched: no live
4
+ * state, nothing that needs the item rendered. Plain JSON, so a server can read the same file.
5
+ *
6
+ * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.
7
+ */
8
+ export interface ItemFacts {
9
+ /** The item's own `identifier`, which may differ from the item-ref's. */
10
+ identifier: string;
11
+ /** `adaptive`; false when absent (XSD default). */
12
+ adaptive: boolean;
13
+ /** `time-dependent`; false when absent. */
14
+ timeDependent: boolean;
15
+ /**
16
+ * A response declaration has a correct response, or a mapping with a map entry, or an area
17
+ * mapping with an area-map entry: something to compare a response with.
18
+ */
19
+ hasCorrectResponse: boolean;
20
+ /** The item has `qti-response-processing`. */
21
+ hasResponseProcessing: boolean;
22
+ /** `external-scored` on the `SCORE` outcome declaration, or null when not externally scored. */
23
+ externalScored: 'human' | 'externalMachine' | null;
24
+ /** `label`, or null when absent. */
25
+ label: string | null;
26
+ /** `title`; empty when absent. */
27
+ title: string;
28
+ }
29
+ /**
30
+ * Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,
31
+ * the fetched document in the browser. Reads attributes and child elements only, so no element
32
+ * needs to be registered.
33
+ */
34
+ export declare function readItemFacts(item: XmlElement): ItemFacts;
@@ -0,0 +1,37 @@
1
+ import { booleanAttribute, childElement, childElements } from './xml-node.js';
2
+ /**
3
+ * Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,
4
+ * the fetched document in the browser. Reads attributes and child elements only, so no element
5
+ * needs to be registered.
6
+ */
7
+ export function readItemFacts(item) {
8
+ if (item.localName !== 'qti-assessment-item') {
9
+ throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);
10
+ }
11
+ const responseDeclarations = childElements(item, 'qti-response-declaration');
12
+ const score = childElements(item, 'qti-outcome-declaration').find(declaration => declaration.getAttribute('identifier') === 'SCORE');
13
+ return {
14
+ identifier: item.getAttribute('identifier') ?? '',
15
+ adaptive: booleanAttribute(item, 'adaptive') ?? false,
16
+ timeDependent: booleanAttribute(item, 'time-dependent') ?? false,
17
+ hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),
18
+ hasResponseProcessing: childElement(item, 'qti-response-processing') !== null,
19
+ externalScored: externalScored(score),
20
+ label: item.getAttribute('label'),
21
+ title: item.getAttribute('title') ?? ''
22
+ };
23
+ }
24
+ function hasSomethingToCompareWith(declaration) {
25
+ if (childElement(declaration, 'qti-correct-response'))
26
+ return true;
27
+ const mapping = childElement(declaration, 'qti-mapping');
28
+ if (mapping && childElement(mapping, 'qti-map-entry'))
29
+ return true;
30
+ const areaMapping = childElement(declaration, 'qti-area-mapping');
31
+ return areaMapping !== null && childElement(areaMapping, 'qti-area-map-entry') !== null;
32
+ }
33
+ function externalScored(declaration) {
34
+ const value = declaration?.getAttribute('external-scored')?.trim();
35
+ return value === 'human' || value === 'externalMachine' ? value : null;
36
+ }
37
+ //# sourceMappingURL=item-facts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-facts.js","sourceRoot":"","sources":["../../src/model/item-facts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAgC9E;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,IAAI,IAAI,CAAC,SAAS,KAAK,qBAAqB,EAAE,CAAC;QAC7C,MAAM,IAAI,SAAS,CAAC,+CAA+C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAChG,CA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WAAmC;IACzD,MAAM,KAAK,GAAG,WAAW,EAAE,YAAY,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC;IACnE,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { booleanAttribute, childElement, childElements } from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * What a `qti-assessment-item` says about itself, read from its XML when it is fetched: no live\n * state, nothing that needs the item rendered. Plain JSON, so a server can read the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface ItemFacts {\n /** The item's own `identifier`, which may differ from the item-ref's. */\n identifier: string;\n /** `adaptive`; false when absent (XSD default). */\n adaptive: boolean;\n /** `time-dependent`; false when absent. */\n timeDependent: boolean;\n /**\n * A response declaration has a correct response, or a mapping with a map entry, or an area\n * mapping with an area-map entry: something to compare a response with.\n */\n hasCorrectResponse: boolean;\n /** The item has `qti-response-processing`. */\n hasResponseProcessing: boolean;\n /** `external-scored` on the `SCORE` outcome declaration, or null when not externally scored. */\n externalScored: 'human' | 'externalMachine' | null;\n /** `label`, or null when absent. */\n label: string | null;\n /** `title`; empty when absent. */\n title: string;\n}\n\n/**\n * Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,\n * the fetched document in the browser. Reads attributes and child elements only, so no element\n * needs to be registered.\n */\nexport function readItemFacts(item: XmlElement): ItemFacts {\n if (item.localName !== 'qti-assessment-item') {\n throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);\n }\n const responseDeclarations = childElements(item, 'qti-response-declaration');\n const score = childElements(item, 'qti-outcome-declaration').find(\n declaration => declaration.getAttribute('identifier') === 'SCORE'\n );\n return {\n identifier: item.getAttribute('identifier') ?? '',\n adaptive: booleanAttribute(item, 'adaptive') ?? false,\n timeDependent: booleanAttribute(item, 'time-dependent') ?? false,\n hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),\n hasResponseProcessing: childElement(item, 'qti-response-processing') !== null,\n externalScored: externalScored(score),\n label: item.getAttribute('label'),\n title: item.getAttribute('title') ?? ''\n };\n}\n\nfunction hasSomethingToCompareWith(declaration: XmlElement): boolean {\n if (childElement(declaration, 'qti-correct-response')) return true;\n const mapping = childElement(declaration, 'qti-mapping');\n if (mapping && childElement(mapping, 'qti-map-entry')) return true;\n const areaMapping = childElement(declaration, 'qti-area-mapping');\n return areaMapping !== null && childElement(areaMapping, 'qti-area-map-entry') !== null;\n}\n\nfunction externalScored(declaration: XmlElement | undefined): ItemFacts['externalScored'] {\n const value = declaration?.getAttribute('external-scored')?.trim();\n return value === 'human' || value === 'externalMachine' ? value : null;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qti-components/delivery",
3
3
  "description": "The QTI 3 delivery engine: test model, item session lifecycle, sequencing and session state, with no browser globals",
4
- "version": "0.1.0-next.0",
4
+ "version": "0.1.0-next.1",
5
5
  "author": "",
6
6
  "keywords": [
7
7
  "qti",