@citolab/qti-components 10.0.0-next.3 → 10.0.0-next.31
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/cdn/index.global.js +1 -1
- package/cdn/index.js +4335 -2689
- package/dist/base.d.ts +39 -13
- package/dist/base.js +14 -1
- package/dist/{chunk-OQDBARD5.js → chunk-3HG5GIKR.js} +2 -2
- package/dist/{chunk-RU6332MD.js → chunk-566LB3G2.js} +4 -4
- package/dist/{chunk-MI7774NV.js → chunk-5BP2A7BI.js} +2 -2
- package/dist/{chunk-D3BYGEQU.js → chunk-5LNSB6J6.js} +117 -92
- package/dist/chunk-5LNSB6J6.js.map +1 -0
- package/dist/chunk-7ISPUOJG.js +209 -0
- package/dist/chunk-7ISPUOJG.js.map +1 -0
- package/dist/{chunk-GBZNFSFY.js → chunk-ADTCTKXS.js} +2 -2
- package/dist/{chunk-FD4AB6TM.js → chunk-BBP7QV32.js} +2 -2
- package/dist/{chunk-LFVPS7KB.js → chunk-CFTWXYBO.js} +2 -2
- package/dist/{chunk-35WWWFS6.js → chunk-DAESCCLR.js} +2 -2
- package/dist/chunk-DJ7PB252.js +7 -0
- package/dist/chunk-DJ7PB252.js.map +1 -0
- package/dist/{chunk-6U3YPHXU.js → chunk-GAPMCYR5.js} +277 -154
- package/dist/chunk-GAPMCYR5.js.map +1 -0
- package/dist/{chunk-TDWJ6WZA.js → chunk-GPC53O7P.js} +166 -10
- package/dist/chunk-GPC53O7P.js.map +1 -0
- package/dist/{chunk-6K3QWJHH.js → chunk-LPYZVKHX.js} +48 -7
- package/dist/chunk-LPYZVKHX.js.map +1 -0
- package/dist/{chunk-TLAVOBEM.js → chunk-O2XRZPKA.js} +356 -62
- package/dist/chunk-O2XRZPKA.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/{chunk-SIE3E4FG.js → chunk-R352K4KZ.js} +966 -2078
- package/dist/chunk-R352K4KZ.js.map +1 -0
- package/dist/{chunk-RSMYGGQK.js → chunk-TZCOXFPB.js} +1590 -610
- package/dist/chunk-TZCOXFPB.js.map +1 -0
- package/dist/chunk-UCXLDQYA.js +56 -0
- package/dist/chunk-UCXLDQYA.js.map +1 -0
- package/dist/chunk-WWY2H2YO.js +7 -0
- package/dist/chunk-WWY2H2YO.js.map +1 -0
- package/dist/computed.types.d-D06SAPP2.d.ts +131 -0
- package/dist/{config.context.d-BvU9r-Mg.d.ts → config.context.d-Dm11aAuw.d.ts} +21 -3
- package/dist/corrections.d.ts +137 -24
- package/dist/corrections.js +12 -12
- package/dist/corrections.js.map +1 -1
- package/dist/elements.d.ts +66 -73
- package/dist/elements.js +9 -6
- package/dist/index.d.ts +21 -17
- package/dist/index.js +50 -61
- package/dist/interactions.d.ts +98 -19
- package/dist/interactions.js +8 -3
- package/dist/item.css +1948 -1946
- package/dist/item.d.ts +8 -6
- package/dist/item.js +6 -5
- package/dist/item.types.d-Zc6ZQDhu.d.ts +25 -0
- package/dist/loader.d.ts +5 -3
- package/dist/loader.js +3 -2
- package/dist/processing.d.ts +19 -7
- package/dist/processing.js +4 -3
- package/dist/public-events.d-3dGip9pd.d.ts +105 -0
- package/dist/qti-components-jsx.d.ts +1725 -1777
- package/dist/{qti-condition-expression.d-VJH6cWxf.d.ts → qti-condition-expression.d-7Kd4LBxn.d.ts} +1 -1
- package/dist/{qti-expression.d-BPxEp8HU.d.ts → qti-expression.d-iH3w6mqf.d.ts} +2 -1
- package/dist/{qti-feedback.d-wMYNVkkj.d.ts → qti-feedback.d-CT0W-8Gm.d.ts} +8 -1
- package/dist/{qti-item.d-DgC1AQbY.d.ts → qti-item.d-CxP6KtCH.d.ts} +3 -2
- package/dist/{qti-rule-base.d-Bdzg8eGH.d.ts → qti-rule-base.d-CeKP0Ooi.d.ts} +2 -2
- package/dist/qti-test-state-B7LgeKnN.d.ts +81 -0
- package/dist/qti-test-state.d-CjvdranT.d.ts +61 -0
- package/dist/{qti-test.d-86TlaMlI.d.ts → qti-test.d-DGXU-4tv.d.ts} +91 -487
- package/dist/{qti-text-entry-interaction.d-q8u5BiVK.d.ts → qti-text-entry-interaction.d-m0EFv9no.d.ts} +221 -73
- package/dist/{qti-transform-test.d-BL7GGFJj.d.ts → qti-transform-test.d-CtNaWJr8.d.ts} +9 -0
- package/dist/{interaction.d-g6XG0T0Z.d.ts → record.d-N1Bq7e1f.d.ts} +67 -4
- package/dist/{session.context.d-D5080LVx.d.ts → session.context.d-9gRdGK4T.d.ts} +7 -1
- package/dist/test-plugin-api.d.ts +143 -0
- package/dist/test-plugin-api.js +21 -0
- package/dist/test-plugin-api.js.map +1 -0
- package/dist/test.d.ts +72 -57
- package/dist/test.js +22 -48
- package/dist/transformers.d.ts +1 -1
- package/dist/transformers.js +2 -1
- package/dist/{item.types.d-B55QkJ92.d.ts → variables.d-DWHlTszN.d.ts} +8 -24
- package/package.json +16 -11
- package/dist/chunk-6K3QWJHH.js.map +0 -1
- package/dist/chunk-6U3YPHXU.js.map +0 -1
- package/dist/chunk-D3BYGEQU.js.map +0 -1
- package/dist/chunk-RSMYGGQK.js.map +0 -1
- package/dist/chunk-SIE3E4FG.js.map +0 -1
- package/dist/chunk-TDWJ6WZA.js.map +0 -1
- package/dist/chunk-TLAVOBEM.js.map +0 -1
- package/dist/chunk-ZP6QQYSU.js +0 -7
- package/dist/chunk-ZP6QQYSU.js.map +0 -1
- package/dist/computed.types.d-gJrBeUMG.d.ts +0 -42
- /package/dist/{chunk-OQDBARD5.js.map → chunk-3HG5GIKR.js.map} +0 -0
- /package/dist/{chunk-RU6332MD.js.map → chunk-566LB3G2.js.map} +0 -0
- /package/dist/{chunk-MI7774NV.js.map → chunk-5BP2A7BI.js.map} +0 -0
- /package/dist/{chunk-GBZNFSFY.js.map → chunk-ADTCTKXS.js.map} +0 -0
- /package/dist/{chunk-FD4AB6TM.js.map → chunk-BBP7QV32.js.map} +0 -0
- /package/dist/{chunk-LFVPS7KB.js.map → chunk-CFTWXYBO.js.map} +0 -0
- /package/dist/{chunk-35WWWFS6.js.map → chunk-DAESCCLR.js.map} +0 -0
|
@@ -195,7 +195,7 @@ function pciHooks(xmlFragment, uri) {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
// ../qti-
|
|
198
|
+
// ../qti-delivery/dist/random/seeded-random.js
|
|
199
199
|
var SeededRandom = class _SeededRandom {
|
|
200
200
|
#state;
|
|
201
201
|
constructor(seed) {
|
|
@@ -264,18 +264,52 @@ function finalizeHash(hash) {
|
|
|
264
264
|
return (h ^ h >>> 16) >>> 0;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
// ../qti-
|
|
267
|
+
// ../qti-delivery/dist/random/selection.js
|
|
268
268
|
var randomValue = (source) => typeof source === "function" ? source() : source.random();
|
|
269
|
+
function selectUnits(units, rule, random) {
|
|
270
|
+
const { select, withReplacement = false } = rule;
|
|
271
|
+
if (!Number.isInteger(select) || select < 0) {
|
|
272
|
+
throw new RangeError(`qti-selection select="${select}" is not a whole number of zero or more.`);
|
|
273
|
+
}
|
|
274
|
+
const required = units.flatMap((unit, index) => unit.required ? [index] : []);
|
|
275
|
+
if (select < required.length) {
|
|
276
|
+
throw new RangeError(`qti-selection select="${select}" is less than the ${required.length} required items and subsections.`);
|
|
277
|
+
}
|
|
278
|
+
if (select > units.length && (!withReplacement || units.length === 0)) {
|
|
279
|
+
throw new RangeError(`qti-selection select="${select}" is more than the ${units.length} items and subsections, without with-replacement="true".`);
|
|
280
|
+
}
|
|
281
|
+
const optional = units.flatMap((unit, index) => unit.required ? [] : [index]);
|
|
282
|
+
const needed = Math.min(select, units.length) - required.length;
|
|
283
|
+
if (needed < optional.length) {
|
|
284
|
+
for (let i = 0; i < needed; i++) {
|
|
285
|
+
const j = i + Math.floor(randomValue(random) * (optional.length - i));
|
|
286
|
+
[optional[i], optional[j]] = [optional[j], optional[i]];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const occurrences = new Array(units.length).fill(0);
|
|
290
|
+
for (const index of [...required, ...optional.slice(0, needed)])
|
|
291
|
+
occurrences[index] = 1;
|
|
292
|
+
for (let clone = units.length; clone < select; clone++) {
|
|
293
|
+
occurrences[Math.floor(randomValue(random) * units.length)]++;
|
|
294
|
+
}
|
|
295
|
+
return occurrences.flatMap((count, index) => new Array(count).fill(index));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ../qti-delivery/dist/random/shuffle.js
|
|
299
|
+
var randomValue2 = (source) => typeof source === "function" ? source() : source.random();
|
|
269
300
|
function shuffleKeepingFixed(units, random) {
|
|
270
301
|
const movable = units.filter((unit) => !unit.fixed);
|
|
271
302
|
for (let i = movable.length - 1; i > 0; i--) {
|
|
272
|
-
const j = Math.floor(
|
|
303
|
+
const j = Math.floor(randomValue2(random) * (i + 1));
|
|
273
304
|
[movable[i], movable[j]] = [movable[j], movable[i]];
|
|
274
305
|
}
|
|
275
306
|
let movableIndex = 0;
|
|
276
307
|
return units.map((unit) => unit.fixed ? unit : movable[movableIndex++]);
|
|
277
308
|
}
|
|
278
309
|
|
|
310
|
+
// ../qti-delivery/dist/state/delivery-state.js
|
|
311
|
+
var itemInstanceId = (itemRefIdentifier, occurrence = 1) => occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;
|
|
312
|
+
|
|
279
313
|
// ../qti-transformers/dist/item/shuffle-interactions.js
|
|
280
314
|
function getShuffleQuerySelectorByTagName(tagName) {
|
|
281
315
|
switch (tagName) {
|
|
@@ -349,6 +383,120 @@ function stripStyleSheets(xmlFragment) {
|
|
|
349
383
|
xmlFragment.querySelectorAll("qti-stylesheet").forEach((stylesheet) => stylesheet.remove());
|
|
350
384
|
}
|
|
351
385
|
|
|
386
|
+
// ../qti-transformers/dist/item/validate-bindings.js
|
|
387
|
+
var BINDING_RULES = {
|
|
388
|
+
// §5.8
|
|
389
|
+
"qti-associate-interaction": {
|
|
390
|
+
baseTypes: ["pair"],
|
|
391
|
+
cardinalities: ["single", "multiple"],
|
|
392
|
+
max: { attribute: "max-associations", default: 1 }
|
|
393
|
+
},
|
|
394
|
+
// §5.30
|
|
395
|
+
"qti-choice-interaction": {
|
|
396
|
+
baseTypes: ["identifier"],
|
|
397
|
+
cardinalities: ["single", "multiple"],
|
|
398
|
+
max: { attribute: "max-choices", default: 1 }
|
|
399
|
+
},
|
|
400
|
+
// §5.44
|
|
401
|
+
"qti-drawing-interaction": { baseTypes: ["file"], cardinalities: ["single"] },
|
|
402
|
+
// §5.45
|
|
403
|
+
"qti-end-attempt-interaction": { baseTypes: ["boolean"], cardinalities: ["single"] },
|
|
404
|
+
// §5.48
|
|
405
|
+
"qti-extended-text-interaction": {
|
|
406
|
+
baseTypes: ["string", "integer", "float"],
|
|
407
|
+
cardinalities: ["single", "multiple", "ordered", "record"]
|
|
408
|
+
},
|
|
409
|
+
// §5.57
|
|
410
|
+
"qti-gap-match-interaction": {
|
|
411
|
+
baseTypes: ["directedPair"],
|
|
412
|
+
cardinalities: ["single", "multiple"],
|
|
413
|
+
max: { attribute: "max-associations", default: 1 }
|
|
414
|
+
},
|
|
415
|
+
// §5.59
|
|
416
|
+
"qti-graphic-associate-interaction": {
|
|
417
|
+
baseTypes: ["pair"],
|
|
418
|
+
cardinalities: ["single", "multiple"],
|
|
419
|
+
max: { attribute: "max-associations", default: 1 }
|
|
420
|
+
},
|
|
421
|
+
// §5.60
|
|
422
|
+
"qti-graphic-gap-match-interaction": { baseTypes: ["directedPair"], cardinalities: ["multiple"] },
|
|
423
|
+
// §5.61
|
|
424
|
+
"qti-graphic-order-interaction": { baseTypes: ["identifier"], cardinalities: ["ordered"] },
|
|
425
|
+
// §5.68
|
|
426
|
+
"qti-hotspot-interaction": {
|
|
427
|
+
baseTypes: ["identifier"],
|
|
428
|
+
cardinalities: ["single", "multiple"],
|
|
429
|
+
max: { attribute: "max-choices", default: 1 }
|
|
430
|
+
},
|
|
431
|
+
// §5.66
|
|
432
|
+
"qti-hottext-interaction": {
|
|
433
|
+
baseTypes: ["identifier"],
|
|
434
|
+
cardinalities: ["single", "multiple"],
|
|
435
|
+
max: { attribute: "max-choices", default: 1 }
|
|
436
|
+
},
|
|
437
|
+
// §5.74
|
|
438
|
+
"qti-inline-choice-interaction": { baseTypes: ["identifier"], cardinalities: ["single"] },
|
|
439
|
+
// §5.89
|
|
440
|
+
"qti-match-interaction": {
|
|
441
|
+
baseTypes: ["directedPair"],
|
|
442
|
+
cardinalities: ["single", "multiple"],
|
|
443
|
+
max: { attribute: "max-associations", default: 1 }
|
|
444
|
+
},
|
|
445
|
+
// §5.92
|
|
446
|
+
"qti-media-interaction": { baseTypes: ["integer"], cardinalities: ["single"] },
|
|
447
|
+
// §2.4.1.2; its own §5.97 states no rule
|
|
448
|
+
"qti-order-interaction": { baseTypes: ["identifier"], cardinalities: ["ordered"] },
|
|
449
|
+
// §5.107
|
|
450
|
+
"qti-position-object-interaction": {
|
|
451
|
+
baseTypes: ["point"],
|
|
452
|
+
cardinalities: ["single", "multiple"],
|
|
453
|
+
max: { attribute: "max-choices", default: 1 }
|
|
454
|
+
},
|
|
455
|
+
// §5.128
|
|
456
|
+
"qti-select-point-interaction": {
|
|
457
|
+
baseTypes: ["point"],
|
|
458
|
+
cardinalities: ["single", "multiple"],
|
|
459
|
+
max: { attribute: "max-choices", default: 0 }
|
|
460
|
+
},
|
|
461
|
+
// §5.134
|
|
462
|
+
"qti-slider-interaction": { baseTypes: ["integer", "float"], cardinalities: ["single"] },
|
|
463
|
+
// §5.162
|
|
464
|
+
"qti-text-entry-interaction": { baseTypes: ["string", "integer", "float"], cardinalities: ["single", "record"] },
|
|
465
|
+
// §5.165
|
|
466
|
+
"qti-upload-interaction": { baseTypes: ["file"], cardinalities: ["single"] }
|
|
467
|
+
};
|
|
468
|
+
var either = (values) => values.length === 1 ? values[0] : `${values.slice(0, -1).join(", ")} or ${values[values.length - 1]}`;
|
|
469
|
+
function validateBindings(xmlFragment) {
|
|
470
|
+
const declarations = new Map(Array.from(xmlFragment.querySelectorAll("qti-response-declaration"), (d) => [d.getAttribute("identifier"), d]));
|
|
471
|
+
const violations = [];
|
|
472
|
+
for (const [tagName, rule] of Object.entries(BINDING_RULES)) {
|
|
473
|
+
for (const interaction of Array.from(xmlFragment.querySelectorAll(tagName))) {
|
|
474
|
+
const responseIdentifier = interaction.getAttribute("response-identifier");
|
|
475
|
+
const declaration = declarations.get(responseIdentifier);
|
|
476
|
+
if (!declaration)
|
|
477
|
+
continue;
|
|
478
|
+
const where = `${tagName} (response "${responseIdentifier}")`;
|
|
479
|
+
const cardinality = declaration.getAttribute("cardinality");
|
|
480
|
+
const baseType = declaration.getAttribute("base-type");
|
|
481
|
+
if (cardinality && !rule.cardinalities.includes(cardinality)) {
|
|
482
|
+
violations.push(`${where}: ${cardinality} cardinality is not permitted; it must be ${either(rule.cardinalities)}`);
|
|
483
|
+
} else if (cardinality && rule.max && cardinality !== "multiple") {
|
|
484
|
+
const value = interaction.getAttribute(rule.max.attribute);
|
|
485
|
+
const max = value === null ? rule.max.default : Number(value);
|
|
486
|
+
if (max === 0 || max > 1) {
|
|
487
|
+
violations.push(`${where}: ${rule.max.attribute} ${max} requires multiple cardinality, not ${cardinality}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (cardinality !== "record" && baseType && !rule.baseTypes.includes(baseType)) {
|
|
491
|
+
violations.push(`${where}: base-type ${baseType} is not permitted; it must be ${either(rule.baseTypes)}`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (violations.length > 0) {
|
|
496
|
+
throw new Error(`QTI validation error: ${violations.join("; ")}.`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
352
500
|
// ../qti-transformers/dist/shared/missing-seed-warning.js
|
|
353
501
|
var missingSeedWarned = false;
|
|
354
502
|
function warnMissingSeed(scope, fallbackSeed) {
|
|
@@ -503,6 +651,11 @@ var qtiTransformItem = () => {
|
|
|
503
651
|
stripStyleSheets(xmlFragment);
|
|
504
652
|
return api;
|
|
505
653
|
},
|
|
654
|
+
/** Throws a QTI validation error when an interaction is bound to a response it cannot hold. */
|
|
655
|
+
validateBindings() {
|
|
656
|
+
validateBindings(xmlFragment);
|
|
657
|
+
return api;
|
|
658
|
+
},
|
|
506
659
|
html() {
|
|
507
660
|
if (xmlUri !== null) {
|
|
508
661
|
setLocation(xmlFragment, xmlUri.substring(0, xmlUri.lastIndexOf("/")));
|
|
@@ -560,10 +713,70 @@ function itemsFromTest(xmlFragment) {
|
|
|
560
713
|
return items;
|
|
561
714
|
}
|
|
562
715
|
|
|
563
|
-
// ../qti-transformers/dist/test/
|
|
564
|
-
var
|
|
565
|
-
var
|
|
566
|
-
var
|
|
716
|
+
// ../qti-transformers/dist/test/section-refs.js
|
|
717
|
+
var SECTION_REF = "qti-assessment-section-ref";
|
|
718
|
+
var SECTION = "qti-assessment-section";
|
|
719
|
+
var ITEM_REF = "qti-assessment-item-ref";
|
|
720
|
+
var URL_ATTRIBUTES = ["src", "href", "srcset", "poster"];
|
|
721
|
+
var ABSOLUTE = /^(data:|https?:|blob:)/;
|
|
722
|
+
var isLocal = (el, name) => el.localName === name || el.localName?.toLowerCase() === name;
|
|
723
|
+
var refsIn = (root) => Array.from(root.getElementsByTagName("*")).filter((el) => isLocal(el, SECTION_REF));
|
|
724
|
+
var folderOf = (href) => href.slice(0, href.lastIndexOf("/") + 1);
|
|
725
|
+
var keyOf = (url) => new URL(url, "https://base.invalid/").href;
|
|
726
|
+
function rebase(section, folder) {
|
|
727
|
+
if (!folder)
|
|
728
|
+
return;
|
|
729
|
+
for (const el of [section, ...Array.from(section.getElementsByTagName("*"))]) {
|
|
730
|
+
for (const attr of URL_ATTRIBUTES) {
|
|
731
|
+
const value = el.getAttribute(attr)?.trim();
|
|
732
|
+
if (value && !ABSOLUTE.test(value))
|
|
733
|
+
el.setAttribute(attr, folder + value);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
async function resolveSectionRefs(root, location, signal) {
|
|
738
|
+
if (!hasSectionRefs(root))
|
|
739
|
+
return;
|
|
740
|
+
await resolve(root, location, signal, []);
|
|
741
|
+
const seen = /* @__PURE__ */ new Set();
|
|
742
|
+
for (const itemRef of Array.from(root.getElementsByTagName("*")).filter((el) => isLocal(el, ITEM_REF))) {
|
|
743
|
+
const identifier = itemRef.getAttribute("identifier") ?? "";
|
|
744
|
+
if (seen.has(identifier)) {
|
|
745
|
+
throw new Error(`The test repeats ${ITEM_REF} "${identifier}" once its ${SECTION_REF}s are included; item-ref identifiers must be unique.`);
|
|
746
|
+
}
|
|
747
|
+
seen.add(identifier);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
async function resolve(root, location, signal, seen) {
|
|
751
|
+
const base = location.endsWith("/") ? location : `${location}/`;
|
|
752
|
+
for (const ref of refsIn(root)) {
|
|
753
|
+
const href = ref.getAttribute("href")?.trim();
|
|
754
|
+
if (!href)
|
|
755
|
+
throw new Error(`${SECTION_REF} "${ref.getAttribute("identifier")}" has no href.`);
|
|
756
|
+
const url = ABSOLUTE.test(href) ? href : base + encodeURI(href);
|
|
757
|
+
const key = keyOf(url);
|
|
758
|
+
if (seen.includes(key))
|
|
759
|
+
throw new Error(`${SECTION_REF} "${href}" refers back to itself.`);
|
|
760
|
+
const doc = await loadXML(url, signal);
|
|
761
|
+
const section = doc?.documentElement;
|
|
762
|
+
if (!section || !isLocal(section, SECTION)) {
|
|
763
|
+
throw new Error(`${SECTION_REF} "${href}" does not hold a single ${SECTION}.`);
|
|
764
|
+
}
|
|
765
|
+
await resolve(doc, url.slice(0, url.lastIndexOf("/") + 1), signal, [...seen, key]);
|
|
766
|
+
if (!ABSOLUTE.test(href))
|
|
767
|
+
rebase(section, folderOf(href));
|
|
768
|
+
const identifier = ref.getAttribute("identifier");
|
|
769
|
+
if (identifier)
|
|
770
|
+
section.setAttribute("identifier", identifier);
|
|
771
|
+
ref.replaceWith(root.importNode(section, true));
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
var hasSectionRefs = (root) => refsIn(root).length > 0;
|
|
775
|
+
|
|
776
|
+
// ../qti-transformers/dist/test/section-elements.js
|
|
777
|
+
var isLocal2 = (el, ...names) => names.includes(el.localName) || names.includes(el.localName?.toLowerCase?.());
|
|
778
|
+
var isItemRef = (el) => isLocal2(el, "qti-assessment-item-ref", "assessmentitemref");
|
|
779
|
+
var isSection = (el) => isLocal2(el, "qti-assessment-section", "assessmentsection");
|
|
567
780
|
var attrIsTrue = (el, ...names) => names.some((n) => {
|
|
568
781
|
const v = (el.getAttribute(n) ?? "").trim().toLowerCase();
|
|
569
782
|
return v === "true" || v === "1";
|
|
@@ -572,32 +785,115 @@ var attrIsFalse = (el, ...names) => names.some((n) => {
|
|
|
572
785
|
const v = (el.getAttribute(n) ?? "").trim().toLowerCase();
|
|
573
786
|
return v === "false" || v === "0";
|
|
574
787
|
});
|
|
575
|
-
var isOrdering = (el) =>
|
|
576
|
-
var isSelection = (el) =>
|
|
577
|
-
var
|
|
578
|
-
var
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
788
|
+
var isOrdering = (el) => isLocal2(el, "qti-ordering", "ordering");
|
|
789
|
+
var isSelection = (el) => isLocal2(el, "qti-selection", "selection");
|
|
790
|
+
var isSessionControl = (el) => isLocal2(el, "qti-item-session-control", "itemsessioncontrol");
|
|
791
|
+
var sectionUnits = (section) => Array.from(section.children).filter((child) => isItemRef(child) || isSection(child));
|
|
792
|
+
|
|
793
|
+
// ../qti-transformers/dist/test/select-sections.js
|
|
794
|
+
var isStandardSelection = (el) => el.children.length === 0 && Array.from(el.attributes).every((a) => a.name === "select" || a.name === "with-replacement" || a.name === "xmlns" || a.name.startsWith("xmlns:"));
|
|
795
|
+
var selectionOf = (section) => Array.from(section.children).find((child) => isSelection(child) && isStandardSelection(child));
|
|
796
|
+
function renameClone(clone, instances) {
|
|
797
|
+
for (const el of [clone, ...Array.from(clone.getElementsByTagName("*"))]) {
|
|
798
|
+
if (!isItemRef(el) && !isSection(el))
|
|
799
|
+
continue;
|
|
800
|
+
const identifier = el.getAttribute("identifier") ?? "";
|
|
801
|
+
const occurrence = (instances.get(identifier) ?? 1) + 1;
|
|
802
|
+
instances.set(identifier, occurrence);
|
|
803
|
+
el.setAttribute("identifier", itemInstanceId(identifier, occurrence));
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
function selectSection(section, seed, instances) {
|
|
807
|
+
const selection = selectionOf(section);
|
|
808
|
+
if (selection) {
|
|
809
|
+
const identifier = section.getAttribute("identifier") ?? "";
|
|
810
|
+
const children = sectionUnits(section);
|
|
811
|
+
let selected;
|
|
812
|
+
try {
|
|
813
|
+
selected = selectUnits(children.map((child) => ({ required: attrIsTrue(child, "required") })), {
|
|
814
|
+
select: Number(selection.getAttribute("select") ?? Number.NaN),
|
|
815
|
+
withReplacement: attrIsTrue(selection, "with-replacement")
|
|
816
|
+
}, createSeededRandom(`${seed}:select:${identifier}`));
|
|
817
|
+
} catch (error) {
|
|
818
|
+
throw new RangeError(`[qtiTransformTest] Section "${identifier}": ${error.message}`);
|
|
819
|
+
}
|
|
820
|
+
const kept = new Set(selected);
|
|
821
|
+
for (const [index, child] of children.entries()) {
|
|
822
|
+
if (!kept.has(index))
|
|
823
|
+
child.remove();
|
|
824
|
+
}
|
|
825
|
+
let previous = null;
|
|
826
|
+
let last = null;
|
|
827
|
+
for (const index of selected) {
|
|
828
|
+
if (index !== previous) {
|
|
829
|
+
last = children[index];
|
|
830
|
+
} else {
|
|
831
|
+
const clone = children[index].cloneNode(true);
|
|
832
|
+
renameClone(clone, instances);
|
|
833
|
+
last.after(clone);
|
|
834
|
+
last = clone;
|
|
590
835
|
}
|
|
836
|
+
previous = index;
|
|
591
837
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
838
|
+
selection.remove();
|
|
839
|
+
}
|
|
840
|
+
for (const child of sectionUnits(section)) {
|
|
841
|
+
if (isSection(child))
|
|
842
|
+
selectSection(child, seed, instances);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
function hasSelection(doc) {
|
|
846
|
+
return Array.from(doc.getElementsByTagName("*")).some((el) => isSelection(el) && isStandardSelection(el));
|
|
847
|
+
}
|
|
848
|
+
function selectSections(doc, seed) {
|
|
849
|
+
const instances = /* @__PURE__ */ new Map();
|
|
850
|
+
const topLevel = Array.from(doc.getElementsByTagName("*")).filter((el) => isSection(el) && !(el.parentElement && isSection(el.parentElement)));
|
|
851
|
+
for (const section of topLevel)
|
|
852
|
+
selectSection(section, seed, instances);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// ../qti-transformers/dist/test/shuffle-sections.js
|
|
856
|
+
var isStandardOrdering = (el) => el.children.length === 0 && Array.from(el.attributes).every((a) => a.name === "shuffle" || a.name === "xmlns" || a.name.startsWith("xmlns:"));
|
|
857
|
+
var shuffleOrderingElements = (section) => Array.from(section.children).filter((child) => isOrdering(child) && isStandardOrdering(child) && attrIsTrue(child, "shuffle"));
|
|
858
|
+
var rngFor = (seed, key) => createSeededRandom(`${seed}:${key}`);
|
|
859
|
+
var dissolves = (section) => attrIsFalse(section, "visible") && attrIsFalse(section, "keep-together", "keeptogether");
|
|
860
|
+
function inheritSessionControl(child, from) {
|
|
861
|
+
if (!from)
|
|
862
|
+
return;
|
|
863
|
+
let own = Array.from(child.children).find(isSessionControl);
|
|
864
|
+
if (!own) {
|
|
865
|
+
own = child.ownerDocument.createElementNS(from.namespaceURI, from.tagName);
|
|
866
|
+
child.insertBefore(own, child.firstChild);
|
|
867
|
+
}
|
|
868
|
+
for (const attribute of Array.from(from.attributes)) {
|
|
869
|
+
if (!own.hasAttribute(attribute.name))
|
|
870
|
+
own.setAttribute(attribute.name, attribute.value);
|
|
871
|
+
}
|
|
595
872
|
}
|
|
596
873
|
function warnDroppedChildren(section, dropped) {
|
|
597
874
|
if (dropped.length === 0)
|
|
598
875
|
return;
|
|
599
876
|
const identifier = section.getAttribute("identifier") ?? "(no identifier)";
|
|
600
|
-
console.warn(`[qtiTransformTest] Subsection "${identifier}" is
|
|
877
|
+
console.warn(`[qtiTransformTest] Subsection "${identifier}" (visible="false", keep-together="false") is merged into its parent by section ordering; discarding its ${[...new Set(dropped)].join(", ")}.`);
|
|
878
|
+
}
|
|
879
|
+
function unitsOf(child) {
|
|
880
|
+
if (isItemRef(child))
|
|
881
|
+
return [{ node: child, fixed: attrIsTrue(child, "fixed") }];
|
|
882
|
+
if (!dissolves(child))
|
|
883
|
+
return [{ node: child, fixed: attrIsTrue(child, "fixed") }];
|
|
884
|
+
const sessionControl = Array.from(child.children).find(isSessionControl);
|
|
885
|
+
const dropped = [];
|
|
886
|
+
const units = [];
|
|
887
|
+
for (const grandchild of Array.from(child.children)) {
|
|
888
|
+
if (isItemRef(grandchild) || isSection(grandchild)) {
|
|
889
|
+
inheritSessionControl(grandchild, sessionControl);
|
|
890
|
+
units.push(...unitsOf(grandchild));
|
|
891
|
+
} else if (!isOrdering(grandchild) && !isSelection(grandchild) && !isSessionControl(grandchild)) {
|
|
892
|
+
dropped.push(grandchild.localName);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
warnDroppedChildren(child, dropped);
|
|
896
|
+
return units;
|
|
601
897
|
}
|
|
602
898
|
function orderSection(section, seed) {
|
|
603
899
|
for (const child of Array.from(section.children)) {
|
|
@@ -609,42 +905,23 @@ function orderSection(section, seed) {
|
|
|
609
905
|
if (orderingEls.length === 0) {
|
|
610
906
|
return;
|
|
611
907
|
}
|
|
612
|
-
const
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
if (isItemRef(child)) {
|
|
616
|
-
units.push({ nodes: [child], fixed: attrIsTrue(child, "fixed") });
|
|
617
|
-
toDetach.push(child);
|
|
618
|
-
} else if (isSection(child)) {
|
|
619
|
-
const { itemRefs, dropped } = collectItemRefsDeep(child);
|
|
620
|
-
warnDroppedChildren(child, dropped);
|
|
621
|
-
if (attrIsFalse(child, "keep-together", "keeptogether")) {
|
|
622
|
-
for (const itemRef of itemRefs) {
|
|
623
|
-
units.push({ nodes: [itemRef], fixed: attrIsTrue(itemRef, "fixed") });
|
|
624
|
-
}
|
|
625
|
-
} else if (itemRefs.length > 0) {
|
|
626
|
-
units.push({ nodes: itemRefs, fixed: attrIsTrue(child, "fixed") });
|
|
627
|
-
}
|
|
628
|
-
toDetach.push(child);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
const anchor = toDetach.length > 0 ? toDetach[toDetach.length - 1].nextSibling : null;
|
|
908
|
+
const children = sectionUnits(section);
|
|
909
|
+
const units = children.flatMap(unitsOf);
|
|
910
|
+
const anchor = children.length > 0 ? children[children.length - 1].nextSibling : null;
|
|
632
911
|
const sectionKey = section.getAttribute("identifier") ?? "";
|
|
633
912
|
const ordered = shuffleKeepingFixed(units, rngFor(seed, sectionKey));
|
|
634
|
-
for (const
|
|
635
|
-
|
|
913
|
+
for (const child of children) {
|
|
914
|
+
child.remove();
|
|
636
915
|
}
|
|
637
916
|
for (const unit of ordered) {
|
|
638
|
-
|
|
639
|
-
section.insertBefore(node, anchor);
|
|
640
|
-
}
|
|
917
|
+
section.insertBefore(unit.node, anchor);
|
|
641
918
|
}
|
|
642
919
|
for (const orderingEl of orderingEls) {
|
|
643
920
|
orderingEl.remove();
|
|
644
921
|
}
|
|
645
922
|
}
|
|
646
923
|
function hasShuffleOrdering(doc) {
|
|
647
|
-
return Array.from(doc.getElementsByTagName("*")).some((el) => isOrdering(el) && attrIsTrue(el, "shuffle"));
|
|
924
|
+
return Array.from(doc.getElementsByTagName("*")).some((el) => isOrdering(el) && isStandardOrdering(el) && attrIsTrue(el, "shuffle"));
|
|
648
925
|
}
|
|
649
926
|
function shuffleSectionsOrdering(doc, seed) {
|
|
650
927
|
const sections = Array.from(doc.getElementsByTagName("*")).filter((el) => isSection(el));
|
|
@@ -662,20 +939,38 @@ function shuffleSectionsOrdering(doc, seed) {
|
|
|
662
939
|
var qtiTransformTest = () => {
|
|
663
940
|
let xmlFragment;
|
|
664
941
|
let xmlUri = "";
|
|
942
|
+
const seedOrFallback = (seed) => {
|
|
943
|
+
const normalizedSeed = typeof seed === "string" ? seed.trim() : seed;
|
|
944
|
+
if (normalizedSeed !== null && normalizedSeed !== void 0 && normalizedSeed !== "")
|
|
945
|
+
return normalizedSeed;
|
|
946
|
+
const fallbackSeed = xmlUri || "default-test-seed";
|
|
947
|
+
warnMissingSeed("qtiTransformTest", fallbackSeed);
|
|
948
|
+
return fallbackSeed;
|
|
949
|
+
};
|
|
665
950
|
const api = {
|
|
666
951
|
// Awaits loadXML so a failed fetch (network, CORS, non-2xx) rejects this
|
|
667
952
|
// promise. Callers own the failure: they can render it, retry it or let it
|
|
668
953
|
// bubble — rather than it escaping as an unhandled rejection while their
|
|
669
954
|
// own `await` never settles.
|
|
955
|
+
//
|
|
956
|
+
// Every qti-assessment-section-ref is replaced by the section it names, fetched relative to the
|
|
957
|
+
// test, before anything else reads the test: QTI makes the reference a facade (info model §7.5).
|
|
670
958
|
async load(uri, signal) {
|
|
671
959
|
xmlFragment = await loadXML(uri, signal);
|
|
672
960
|
xmlUri = uri;
|
|
673
|
-
|
|
961
|
+
const location = uri.substring(0, uri.lastIndexOf("/"));
|
|
962
|
+
await resolveSectionRefs(xmlFragment, location, signal);
|
|
963
|
+
api.path(location);
|
|
674
964
|
return api;
|
|
675
965
|
},
|
|
966
|
+
// A test given as a string has no location to fetch referenced sections from, so a
|
|
967
|
+
// qti-assessment-section-ref stays as it is (with a warning) and its items are not in the test.
|
|
676
968
|
parse(xmlString) {
|
|
677
969
|
xmlFragment = parseXML(xmlString);
|
|
678
970
|
xmlUri = "";
|
|
971
|
+
if (hasSectionRefs(xmlFragment)) {
|
|
972
|
+
console.warn("[qtiTransformTest] qti-assessment-section-ref needs the test's location: load() the test by URL to include referenced sections.");
|
|
973
|
+
}
|
|
679
974
|
return api;
|
|
680
975
|
},
|
|
681
976
|
path: (location) => {
|
|
@@ -686,18 +981,17 @@ var qtiTransformTest = () => {
|
|
|
686
981
|
fn(xmlFragment);
|
|
687
982
|
return api;
|
|
688
983
|
},
|
|
984
|
+
applySelection(seed) {
|
|
985
|
+
if (!hasSelection(xmlFragment))
|
|
986
|
+
return api;
|
|
987
|
+
selectSections(xmlFragment, seedOrFallback(seed));
|
|
988
|
+
return api;
|
|
989
|
+
},
|
|
689
990
|
shuffleOrdering(seed) {
|
|
690
991
|
if (!hasShuffleOrdering(xmlFragment)) {
|
|
691
992
|
return api;
|
|
692
993
|
}
|
|
693
|
-
|
|
694
|
-
if (normalizedSeed === null || normalizedSeed === void 0 || normalizedSeed === "") {
|
|
695
|
-
const fallbackSeed = xmlUri || "default-test-seed";
|
|
696
|
-
warnMissingSeed("qtiTransformTest", fallbackSeed);
|
|
697
|
-
shuffleSectionsOrdering(xmlFragment, fallbackSeed);
|
|
698
|
-
return api;
|
|
699
|
-
}
|
|
700
|
-
shuffleSectionsOrdering(xmlFragment, normalizedSeed);
|
|
994
|
+
shuffleSectionsOrdering(xmlFragment, seedOrFallback(seed));
|
|
701
995
|
return api;
|
|
702
996
|
},
|
|
703
997
|
items() {
|
|
@@ -724,4 +1018,4 @@ export {
|
|
|
724
1018
|
qtiTransformManifest,
|
|
725
1019
|
qtiTransformTest
|
|
726
1020
|
};
|
|
727
|
-
//# sourceMappingURL=chunk-
|
|
1021
|
+
//# sourceMappingURL=chunk-O2XRZPKA.js.map
|