@citolab/qti-components 10.0.0-next.27 → 10.0.0-next.29

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 (39) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +165 -165
  3. package/dist/base.d.ts +2 -2
  4. package/dist/{chunk-EA7UK4NL.js → chunk-2ZT47EUK.js} +4 -4
  5. package/dist/{chunk-U5HL4SF3.js → chunk-566LB3G2.js} +2 -2
  6. package/dist/{chunk-GYWC44CE.js → chunk-5KNTKBP6.js} +2 -2
  7. package/dist/{chunk-I2UB2NOX.js → chunk-ADTCTKXS.js} +2 -2
  8. package/dist/{chunk-EGN2SVIN.js → chunk-BBP7QV32.js} +2 -2
  9. package/dist/{chunk-EWX4R46G.js → chunk-CFTWXYBO.js} +2 -2
  10. package/dist/{chunk-HZCPYU53.js → chunk-GAPMCYR5.js} +2 -2
  11. package/dist/{chunk-FEWA5I3V.js → chunk-O2XRZPKA.js} +1 -1
  12. package/dist/chunk-O2XRZPKA.js.map +1 -0
  13. package/dist/{chunk-THV42AHU.js → chunk-YRR6D6UP.js} +196 -247
  14. package/dist/chunk-YRR6D6UP.js.map +1 -0
  15. package/dist/{computed.types.d-DcAfzw8v.d.ts → computed.types.d-BPzPFX3Z.d.ts} +6 -0
  16. package/dist/corrections.d.ts +3 -3
  17. package/dist/corrections.js +5 -5
  18. package/dist/elements.js +3 -3
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +9 -9
  21. package/dist/item.js +3 -3
  22. package/dist/loader.js +2 -2
  23. package/dist/{qti-test-state-D-edVvB3.d.ts → qti-test-state-ybQ6ausy.d.ts} +7 -3
  24. package/dist/{qti-test-state.d-D8Q89RzZ.d.ts → qti-test-state.d-CjvdranT.d.ts} +5 -1
  25. package/dist/{qti-test.d-0fARwLm2.d.ts → qti-test.d-BbtCG7A-.d.ts} +2 -2
  26. package/dist/test-plugin-api.d.ts +3 -3
  27. package/dist/test.d.ts +6 -6
  28. package/dist/test.js +4 -4
  29. package/dist/transformers.js +1 -1
  30. package/package.json +4 -4
  31. package/dist/chunk-FEWA5I3V.js.map +0 -1
  32. package/dist/chunk-THV42AHU.js.map +0 -1
  33. /package/dist/{chunk-EA7UK4NL.js.map → chunk-2ZT47EUK.js.map} +0 -0
  34. /package/dist/{chunk-U5HL4SF3.js.map → chunk-566LB3G2.js.map} +0 -0
  35. /package/dist/{chunk-GYWC44CE.js.map → chunk-5KNTKBP6.js.map} +0 -0
  36. /package/dist/{chunk-I2UB2NOX.js.map → chunk-ADTCTKXS.js.map} +0 -0
  37. /package/dist/{chunk-EGN2SVIN.js.map → chunk-BBP7QV32.js.map} +0 -0
  38. /package/dist/{chunk-EWX4R46G.js.map → chunk-CFTWXYBO.js.map} +0 -0
  39. /package/dist/{chunk-HZCPYU53.js.map → chunk-GAPMCYR5.js.map} +0 -0
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-7ISPUOJG.js";
9
9
  import {
10
10
  QtiModalFeedback
11
- } from "./chunk-HZCPYU53.js";
11
+ } from "./chunk-GAPMCYR5.js";
12
12
  import {
13
13
  listenPublic
14
14
  } from "./chunk-UCXLDQYA.js";
@@ -21,7 +21,7 @@ import {
21
21
  import {
22
22
  qtiTransformItem,
23
23
  qtiTransformTest
24
- } from "./chunk-FEWA5I3V.js";
24
+ } from "./chunk-O2XRZPKA.js";
25
25
  import {
26
26
  INITIAL_SESSION_CONTEXT,
27
27
  INITIAL_TEST_CONTEXT,
@@ -2701,7 +2701,8 @@ var TestBaseMixin = (superClass) => {
2701
2701
  * The test context is replaced rather than changed in place, so its consumers update and
2702
2702
  * `qc-test-state-changed` fires.
2703
2703
  *
2704
- * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.
2704
+ * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a
2705
+ * `with-replacement` clone's instance id (`item-3#2`).
2705
2706
  * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.
2706
2707
  */
2707
2708
  updateItemVariables(itemRefID, values, state6) {
@@ -3320,6 +3321,163 @@ import { ContextConsumer, consume as consume8, provide as provide4 } from "@lit/
3320
3321
  import { html as html11, LitElement as LitElement13 } from "lit";
3321
3322
  import { property as property12, state as state5 } from "lit/decorators.js";
3322
3323
 
3324
+ // ../qti-test/dist/internal/derive-computed-context.js
3325
+ function deriveComputedContext(inputs) {
3326
+ const { model, sessionContext: sessionContext2, itemElement } = inputs;
3327
+ const itemIndexes = indexesInDocumentOrder(model.testParts.flatMap((part) => itemRefsInOrder(part.sections)), inputs.infoItemCategory);
3328
+ return {
3329
+ itemElement,
3330
+ identifier: model.identifier,
3331
+ title: model.title,
3332
+ view: sessionContext2?.view,
3333
+ plugins: sessionContext2?.plugins ?? {},
3334
+ testParts: model.testParts.map((testPart) => ({
3335
+ active: sessionContext2?.navPartId === testPart.identifier,
3336
+ identifier: testPart.identifier,
3337
+ navigationMode: testPart.navigationMode,
3338
+ submissionMode: testPart.submissionMode,
3339
+ allowSkipping: testPart.sessionControl.allowSkipping,
3340
+ itemOrder: itemRefsInOrder(testPart.sections).map((item) => item.identifier),
3341
+ // Flat, depth first: every section once, each with only its own item-refs, so every item is
3342
+ // listed once. Where a section's item-refs and subsections interleave, this list is not in
3343
+ // document order; `index` is.
3344
+ sections: sectionsInOrder(testPart.sections).map((section) => ({
3345
+ active: sessionContext2?.navSectionId === section.identifier,
3346
+ identifier: section.identifier,
3347
+ title: section.title,
3348
+ allowSkipping: section.sessionControl.allowSkipping,
3349
+ // A section that only holds subsections is completed when theirs are.
3350
+ completed: itemRefsInOrder(section.content).every((item) => variableValue(itemContextFor(inputs, item.identifier), "completionStatus") === "completed"),
3351
+ items: ownItemRefs(section).map((item) => deriveItem(inputs, item, itemIndexes.get(item.identifier) ?? null))
3352
+ }))
3353
+ }))
3354
+ };
3355
+ }
3356
+ function deriveItem(inputs, item, index) {
3357
+ const itemContext = itemContextFor(inputs, item.identifier);
3358
+ const computedItem = {
3359
+ active: false,
3360
+ identifier: item.identifier,
3361
+ categories: [...item.categories],
3362
+ href: item.href,
3363
+ variables: [],
3364
+ sessionControl: { ...item.sessionControl },
3365
+ ...factsFor(inputs.itemFacts, item.identifier),
3366
+ ...itemContext,
3367
+ ...inputs.itemData?.find((data) => data.identifier === item.identifier)
3368
+ };
3369
+ const rawScore = variableValue(computedItem, "SCORE");
3370
+ const score = rawScore === void 0 || rawScore === null ? null : parseFloat(rawScore.toString());
3371
+ const rawMaxScore = variableValue(computedItem, "MAXSCORE");
3372
+ const maxScore = rawMaxScore === void 0 || rawMaxScore === null ? null : parseFloat(rawMaxScore.toString());
3373
+ const completionStatus = variableValue(computedItem, "completionStatus");
3374
+ const response = variableValue(computedItem, "RESPONSE") || "";
3375
+ const numAttempts = Number(variableValue(computedItem, "numAttempts")) || 0;
3376
+ const latched = inputs.optimality.get(item.identifier);
3377
+ const optimality = latched ?? (itemContext ? assessOptimality(itemContext) : "unscored");
3378
+ return {
3379
+ ...computedItem,
3380
+ completionStatus,
3381
+ numAttempts,
3382
+ score,
3383
+ response,
3384
+ index,
3385
+ active: inputs.sessionContext?.navItemRefId === item.identifier,
3386
+ // Published by the item. One that is not on screen has nothing to be invalid.
3387
+ valid: itemContext?.valid ?? true,
3388
+ isDefaultResponse: isDefaultResponse(itemContext),
3389
+ maxScore,
3390
+ done: isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus),
3391
+ // Reflects the last *ended* attempt only: the latch, not the fallback above.
3392
+ optimal: latched === "optimal"
3393
+ };
3394
+ }
3395
+ function itemContextFor(inputs, identifier) {
3396
+ return inputs.testContext?.items?.find((item) => item.identifier === identifier);
3397
+ }
3398
+ function variableValue(item, identifier) {
3399
+ return item?.variables?.find((variable2) => variable2.identifier === identifier)?.value;
3400
+ }
3401
+ function factsFor(itemFacts, identifier) {
3402
+ const facts = itemFacts?.get(identifier);
3403
+ if (!facts)
3404
+ return {};
3405
+ const { identifier: assessmentItemIdentifier, ...rest } = facts;
3406
+ return { ...rest, assessmentItemIdentifier };
3407
+ }
3408
+ function indexesInDocumentOrder(items, infoItemCategory) {
3409
+ let index = 1;
3410
+ return new Map(items.map((item) => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++]));
3411
+ }
3412
+ function isDefaultResponse(itemContext) {
3413
+ const responseVariables = itemContext?.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts") || [];
3414
+ return responseVariables.every((v) => {
3415
+ if (v.value === void 0 || v.value === null)
3416
+ return true;
3417
+ let fallbackValue;
3418
+ switch (v.baseType) {
3419
+ case "integer":
3420
+ case "float":
3421
+ case "duration":
3422
+ fallbackValue = "0";
3423
+ break;
3424
+ case "boolean":
3425
+ fallbackValue = "false";
3426
+ break;
3427
+ default:
3428
+ fallbackValue = "";
3429
+ break;
3430
+ }
3431
+ const defaultValue = v.defaultValue ?? fallbackValue;
3432
+ if (Array.isArray(v.value)) {
3433
+ const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
3434
+ return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);
3435
+ }
3436
+ return v.value === defaultValue;
3437
+ });
3438
+ }
3439
+ function isItemDone(numAttempts, optimality, maxAttempts, adaptive, completionStatus) {
3440
+ if (numAttempts === 0)
3441
+ return false;
3442
+ if (adaptive)
3443
+ return completionStatus === "completed";
3444
+ if (optimality !== "suboptimal")
3445
+ return true;
3446
+ const max = maxAttempts ?? 1;
3447
+ return max > 0 && numAttempts >= max;
3448
+ }
3449
+ function assessOptimality(item) {
3450
+ const variables = item.variables ?? [];
3451
+ const score = numericVariable(variables, "SCORE");
3452
+ const maxScore = numericVariable(variables, "MAXSCORE");
3453
+ if (score !== null && maxScore !== null) {
3454
+ return score >= maxScore ? "optimal" : "suboptimal";
3455
+ }
3456
+ const responseVars = variables.filter((v) => v.type === "response" && v.correctResponse !== void 0 && v.correctResponse !== null);
3457
+ if (responseVars.length === 0)
3458
+ return "unscored";
3459
+ const allMatch = responseVars.every((v) => {
3460
+ const expected = v.correctResponse;
3461
+ const actual = v.value;
3462
+ if (actual === void 0 || actual === null)
3463
+ return false;
3464
+ if (Array.isArray(expected) && Array.isArray(actual)) {
3465
+ return expected.length === actual.length && expected.every((e) => actual.includes(e));
3466
+ }
3467
+ if (Array.isArray(expected) || Array.isArray(actual))
3468
+ return false;
3469
+ return expected === actual;
3470
+ });
3471
+ return allMatch ? "optimal" : "suboptimal";
3472
+ }
3473
+ function numericVariable(variables, identifier) {
3474
+ const raw = variables?.find((v) => v.identifier === identifier)?.value;
3475
+ if (raw === void 0 || raw === null || Array.isArray(raw))
3476
+ return null;
3477
+ const parsed = parseFloat(raw.toString());
3478
+ return Number.isNaN(parsed) ? null : parsed;
3479
+ }
3480
+
3323
3481
  // ../qti-test/dist/internal/rendered-markup.js
3324
3482
  function renderedMarkup(element) {
3325
3483
  return {
@@ -3406,8 +3564,6 @@ var TestNavigation = class extends LitElement13 {
3406
3564
  this.autoScoreItems = false;
3407
3565
  this.#optimality = /* @__PURE__ */ new Map();
3408
3566
  this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
3409
- this.#sectionItems = /* @__PURE__ */ new Map();
3410
- this.#itemOrder = [];
3411
3567
  this.#lockedItems = /* @__PURE__ */ new WeakSet();
3412
3568
  listenPublic2(this, "qc-test-loaded", this.#handleTestConnected.bind(this));
3413
3569
  listenPublic(this, "qc-item-response-changed", this.#handleInteractionChanged.bind(this));
@@ -3428,12 +3584,12 @@ var TestNavigation = class extends LitElement13 {
3428
3584
  const itemContext = event.detail.itemContext;
3429
3585
  if (!itemContext?.identifier)
3430
3586
  return;
3431
- const optimality = this.#assessOptimality(itemContext);
3587
+ const optimality = assessOptimality(itemContext);
3432
3588
  this.#optimality.set(itemContext.identifier, optimality);
3433
3589
  const computedItem = this.computedItemFor(itemContext.identifier);
3434
3590
  const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3435
3591
  const completionStatus = itemContext.variables?.find((v) => v.identifier === "completionStatus")?.value;
3436
- this.afterAttemptEnded(event.composedPath()[0]?.closest("qti-assessment-item"), computedItem, this.#isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
3592
+ this.afterAttemptEnded(event.composedPath()[0]?.closest("qti-assessment-item"), computedItem, isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
3437
3593
  }
3438
3594
  /**
3439
3595
  * Extension point for presentation packages reacting to an ended attempt.
@@ -3527,57 +3683,38 @@ var TestNavigation = class extends LitElement13 {
3527
3683
  });
3528
3684
  }
3529
3685
  });
3530
- const model = buildTestModel(renderedMarkup(this.#testElement));
3531
- this.#sectionItems = new Map(model.testParts.flatMap((part) => sectionsInOrder(part.sections).map((section) => [section.identifier, itemRefsInOrder(section.content).map((item) => item.identifier)])));
3532
- this.#itemOrder = model.testParts.flatMap((part) => itemRefsInOrder(part.sections));
3533
- this.computedContext = {
3534
- itemElement: this.#itemElement,
3535
- identifier: model.identifier,
3536
- title: model.title,
3537
- view: this._sessionContext?.view,
3538
- plugins: this._sessionContext?.plugins ?? {},
3539
- testParts: model.testParts.map((testPart) => ({
3540
- active: false,
3541
- identifier: testPart.identifier,
3542
- navigationMode: testPart.navigationMode,
3543
- submissionMode: testPart.submissionMode,
3544
- allowSkipping: testPart.sessionControl.allowSkipping,
3545
- itemOrder: itemRefsInOrder(testPart.sections).map((item) => item.identifier),
3546
- // Flat, depth first: every section once, each with only its own item-refs, so every item is
3547
- // listed once. Where a section's item-refs and subsections interleave, this list is not in
3548
- // document order; `index` is.
3549
- sections: sectionsInOrder(testPart.sections).map((section) => ({
3550
- active: false,
3551
- identifier: section.identifier,
3552
- title: section.title,
3553
- allowSkipping: section.sessionControl.allowSkipping,
3554
- items: ownItemRefs(section).map((item) => ({
3555
- ...this.initContext?.find((i) => i.identifier === item.identifier),
3556
- active: false,
3557
- identifier: item.identifier,
3558
- categories: item.categories,
3559
- href: item.href,
3560
- variables: [],
3561
- sessionControl: { ...item.sessionControl }
3562
- }))
3563
- }))
3564
- }))
3565
- };
3686
+ this.#model = buildTestModel(renderedMarkup(this.#testElement));
3687
+ this.computedContext = this.#derive();
3688
+ }
3689
+ /** The test's structure and resolved session control, read from its markup when it is connected. */
3690
+ #model;
3691
+ /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */
3692
+ #derive() {
3693
+ this.#seedOptimality();
3694
+ return deriveComputedContext({
3695
+ model: this.#model,
3696
+ itemFacts: this._itemFacts,
3697
+ testContext: this._testContext,
3698
+ sessionContext: this._sessionContext,
3699
+ infoItemCategory: this.configContext?.infoItemCategory,
3700
+ itemData: this.initContext,
3701
+ optimality: this.#optimality,
3702
+ itemElement: this.#itemElement
3703
+ });
3566
3704
  }
3567
3705
  /**
3568
- * The item-refs of each section, its subsections' included, by section identifier: a section that
3569
- * only holds subsections is completed when theirs are.
3706
+ * On a restored session no attempt is ended this run, so the latch is seeded once from the
3707
+ * persisted context, which still holds the submitted response. A later change of the answer
3708
+ * leaves the seeded value alone.
3570
3709
  */
3571
- #sectionItems;
3572
- /** Every item-ref of the test in document order, which item numbers follow. */
3573
- #itemOrder;
3574
- /** Item numbers in document order, skipping info items; null for an info item. */
3575
- #itemIndexes() {
3576
- let index = 1;
3577
- return new Map(this.#itemOrder.map((item) => [
3578
- item.identifier,
3579
- item.categories.includes(this.configContext?.infoItemCategory) ? null : index++
3580
- ]));
3710
+ #seedOptimality() {
3711
+ for (const itemContext of this._testContext?.items ?? []) {
3712
+ if (!itemContext.identifier || this.#optimality.has(itemContext.identifier))
3713
+ continue;
3714
+ const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3715
+ if (numAttempts > 0)
3716
+ this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));
3717
+ }
3581
3718
  }
3582
3719
  /**
3583
3720
  * Extract default values from a qti-context-declaration element
@@ -3616,117 +3753,11 @@ var TestNavigation = class extends LitElement13 {
3616
3753
  });
3617
3754
  return defaultValues;
3618
3755
  }
3619
- /** An item's facts as `computedContext` has carried them; nothing until the item is fetched. */
3620
- #factsFor(identifier) {
3621
- const facts = this._itemFacts?.get(identifier);
3622
- if (!facts)
3623
- return {};
3624
- const { identifier: assessmentItemIdentifier, ...rest } = facts;
3625
- return { ...rest, assessmentItemIdentifier };
3626
- }
3627
- /* PK: on every change of the candidate we will recomputed the computedContext */
3756
+ /* On every change of the candidate's state, the context is derived again. */
3628
3757
  willUpdate(_changedProperties) {
3629
- if (!this.computedContext)
3758
+ if (!this.#model)
3630
3759
  return;
3631
- const itemIndexes = this.#itemIndexes();
3632
- this.computedContext = {
3633
- ...this.computedContext,
3634
- view: this._sessionContext?.view,
3635
- plugins: this._sessionContext?.plugins ?? {},
3636
- testParts: this.computedContext.testParts.map((testPart) => {
3637
- return {
3638
- ...testPart,
3639
- active: this._sessionContext?.navPartId === testPart.identifier || false,
3640
- sections: testPart.sections.map((section) => {
3641
- return {
3642
- ...section,
3643
- active: this._sessionContext?.navSectionId === section.identifier || false,
3644
- completed: (this.#sectionItems.get(section.identifier) ?? section.items.map((i) => i.identifier)).every((identifier) => this._testContext.items.find((i) => i.identifier === identifier)?.variables.find((v) => v.identifier === "completionStatus")?.value === "completed"),
3645
- items: section.items.map((item) => {
3646
- const itemContext = this._testContext?.items.find((i) => i.identifier === item.identifier);
3647
- const computedItem = {
3648
- ...item,
3649
- ...this.#factsFor(item.identifier),
3650
- ...itemContext,
3651
- ...this.initContext?.find((i) => i.identifier === item.identifier)
3652
- };
3653
- const rawscore = computedItem.variables?.find((vr) => vr.identifier == "SCORE")?.value;
3654
- const score = rawscore === void 0 || rawscore === null ? null : parseFloat(rawscore?.toString());
3655
- const completionStatus = computedItem.variables?.find((v) => v.identifier === "completionStatus")?.value;
3656
- const response = computedItem.variables?.find((v) => v.identifier === "RESPONSE")?.value || "";
3657
- const numAttempts = Number(computedItem.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3658
- const active = this._sessionContext?.navItemRefId === computedItem.identifier || false;
3659
- const valid = itemContext?.valid ?? true;
3660
- const responseVars = itemContext?.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts") || [];
3661
- const isDefaultResponse = responseVars.every((v) => {
3662
- if (v.value === void 0 || v.value === null) {
3663
- return true;
3664
- }
3665
- let fallbackValue;
3666
- switch (v.baseType) {
3667
- case "integer":
3668
- case "float":
3669
- case "duration":
3670
- fallbackValue = "0";
3671
- break;
3672
- case "boolean":
3673
- fallbackValue = "false";
3674
- break;
3675
- case "string":
3676
- case "directedPair":
3677
- case "identifier":
3678
- case "pair":
3679
- case "record":
3680
- default:
3681
- fallbackValue = "";
3682
- break;
3683
- }
3684
- const defaultValue = v.defaultValue ?? fallbackValue;
3685
- if (Array.isArray(v.value)) {
3686
- const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
3687
- return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);
3688
- }
3689
- return v.value === defaultValue;
3690
- });
3691
- const index = itemIndexes.get(item.identifier) ?? null;
3692
- const rawMaxScore = item.variables?.find((vr) => vr.identifier == "MAXSCORE")?.value;
3693
- const maxScore = rawMaxScore === void 0 || rawMaxScore === null ? null : parseFloat(rawMaxScore?.toString());
3694
- let optimality = this.#optimality.get(computedItem.identifier);
3695
- if (optimality === void 0) {
3696
- optimality = itemContext ? this.#assessOptimality(itemContext) : "unscored";
3697
- if (numAttempts > 0)
3698
- this.#optimality.set(computedItem.identifier, optimality);
3699
- }
3700
- const done = this.#isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus);
3701
- return {
3702
- ...computedItem,
3703
- completionStatus,
3704
- numAttempts,
3705
- score,
3706
- response,
3707
- index,
3708
- active,
3709
- valid,
3710
- isDefaultResponse,
3711
- maxScore,
3712
- done,
3713
- // Reflects the last *ended* attempt only. Read the latch directly
3714
- // (not the `optimality` local) — the latch is written solely on
3715
- // responseProcessed / restore-seed (line above, guarded by
3716
- // numAttempts > 0), so a freshly-picked mid-attempt selection
3717
- // computed live is never stored and never counts as optimal.
3718
- optimal: this.#optimality.get(computedItem.identifier) === "optimal"
3719
- // type,
3720
- // correct,
3721
- // incorrect,
3722
- // completed
3723
- };
3724
- })
3725
- };
3726
- })
3727
- };
3728
- })
3729
- };
3760
+ this.computedContext = this.#derive();
3730
3761
  this.dispatchEvent(new CustomEvent("qti-computed-context-updated", {
3731
3762
  detail: this.computedContext,
3732
3763
  bubbles: true
@@ -3779,88 +3810,6 @@ var TestNavigation = class extends LitElement13 {
3779
3810
  const maxAttempts = item.sessionControl?.maxAttempts ?? 1;
3780
3811
  return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;
3781
3812
  }
3782
- /**
3783
- * Decide whether an item should be treated as "the candidate is done with it"
3784
- * for the purpose of gating forward navigation and further attempts.
3785
- *
3786
- * - The candidate must have actually ended an attempt (numAttempts > 0).
3787
- * - Once attempted, the item is done if they reached the optimal outcome
3788
- * ('optimal'), or there's nothing to improve on ('unscored'). It is only *not*
3789
- * done while a better attempt is still possible ('suboptimal') and attempts
3790
- * remain — see #assessOptimality for how "optimal" is determined.
3791
- *
3792
- * `optimality` reflects the last *ended attempt* (see #optimality), not the
3793
- * live selection — so a freshly-picked optimal answer doesn't count as done
3794
- * until test-end-attempt evaluates it.
3795
- *
3796
- * Adaptive items decide this themselves: max-attempts does not apply to them
3797
- * (QTI 3, itemSessionControl), and a wrong attempt may be the step that leads
3798
- * on to the next part of the item. They are done once their response
3799
- * processing sets completionStatus to 'completed'.
3800
- */
3801
- #isItemDone(numAttempts, optimality, maxAttempts, adaptive, completionStatus) {
3802
- if (numAttempts === 0)
3803
- return false;
3804
- if (adaptive)
3805
- return completionStatus === "completed";
3806
- if (optimality !== "suboptimal")
3807
- return true;
3808
- const max = maxAttempts ?? 1;
3809
- return max > 0 && numAttempts >= max;
3810
- }
3811
- /**
3812
- * Decide whether an item's submission is as good as it can get — i.e. the
3813
- * candidate reached the *optimal* outcome, so there's no reason to make them
3814
- * try again. 'optimal' means best achievable, 'suboptimal' means a better
3815
- * attempt is still possible, 'unscored' means there's nothing to judge against.
3816
- * ("optimal" is the spec's own word — a qti-correct-response is defined as
3817
- * "the (or an) optimal value".)
3818
- *
3819
- * Two signals, in order of authority:
3820
- * 1. The scored outcome: optimal ⟺ SCORE has reached its maximum (MAXSCORE).
3821
- * This correctly handles partial-credit / qti-mapping items, where an exact
3822
- * response match would under- or over-judge.
3823
- * 2. The declared qti-correct-response, for items that aren't scored (no
3824
- * SCORE/MAXSCORE) — an exact match is the best available proxy. Bookkeeping
3825
- * variables like numAttempts can be typed 'response' but never declare a
3826
- * correctResponse, so we filter on a declared correctResponse.
3827
- *
3828
- * Items with neither a comparable score nor a correctResponse (essays, info
3829
- * items, etc.) are 'unscored' — there's no optimal value to require, so one
3830
- * attempt is enough.
3831
- */
3832
- #assessOptimality(item) {
3833
- const variables = item.variables ?? [];
3834
- const score = this.#numericVariable(variables, "SCORE");
3835
- const maxScore = this.#numericVariable(variables, "MAXSCORE");
3836
- if (score !== null && maxScore !== null) {
3837
- return score >= maxScore ? "optimal" : "suboptimal";
3838
- }
3839
- const responseVars = variables.filter((v) => v.type === "response" && v.correctResponse !== void 0 && v.correctResponse !== null);
3840
- if (responseVars.length === 0)
3841
- return "unscored";
3842
- const allMatch = responseVars.every((v) => {
3843
- const expected = v.correctResponse;
3844
- const actual = v.value;
3845
- if (actual === void 0 || actual === null)
3846
- return false;
3847
- if (Array.isArray(expected) && Array.isArray(actual)) {
3848
- return expected.length === actual.length && expected.every((e) => actual.includes(e));
3849
- }
3850
- if (Array.isArray(expected) || Array.isArray(actual))
3851
- return false;
3852
- return expected === actual;
3853
- });
3854
- return allMatch ? "optimal" : "suboptimal";
3855
- }
3856
- /** Read a single numeric outcome value, or null when absent / non-numeric. */
3857
- #numericVariable(variables, identifier) {
3858
- const raw = variables?.find((v) => v.identifier === identifier)?.value;
3859
- if (raw === void 0 || raw === null || Array.isArray(raw))
3860
- return null;
3861
- const parsed = parseFloat(raw.toString());
3862
- return Number.isNaN(parsed) ? null : parsed;
3863
- }
3864
3813
  };
3865
3814
  __decorate15([
3866
3815
  property12({ type: String })
@@ -4103,4 +4052,4 @@ export {
4103
4052
  * Portions Copyright (c) 2013, the Dart project authors.
4104
4053
  *)
4105
4054
  */
4106
- //# sourceMappingURL=chunk-THV42AHU.js.map
4055
+ //# sourceMappingURL=chunk-YRR6D6UP.js.map