@citolab/qti-components 10.0.0-next.28 → 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.
package/dist/base.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { C as ComputedItemContext } from './session.context.d-9gRdGK4T.js';
2
2
  export { I as INITIAL_SESSION_CONTEXT, S as SessionContext, V as View, s as sessionContext } from './session.context.d-9gRdGK4T.js';
3
- import { C as ComputedContext } from './computed.types.d-DcAfzw8v.js';
4
- export { a as ComputedItem, S as SessionControl } from './computed.types.d-DcAfzw8v.js';
3
+ import { C as ComputedContext } from './computed.types.d-BPzPFX3Z.js';
4
+ export { a as ComputedItem, S as SessionControl } from './computed.types.d-BPzPFX3Z.js';
5
5
  export { C as ConfigContext, V as ValidationDisplayMode, c as configContext } from './config.context.d-Dm11aAuw.js';
6
6
  export { C as ChoiceRole, I as Interaction, a as InteractionContext, R as RecordFieldValues, b as RecordValue, V as ValidityKind, c as ValidityTrigger, i as inferRecordFieldBaseType, d as interactionContext, e as isRecordValue, r as readRecordFieldValues } from './record.d-N1Bq7e1f.js';
7
7
  import { I as ItemContext } from './item.types.d-Zc6ZQDhu.js';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  QtiTest,
3
3
  TestNavigation
4
- } from "./chunk-4IWT7GLA.js";
4
+ } from "./chunk-YRR6D6UP.js";
5
5
  import {
6
6
  QtiAssessmentItem
7
7
  } from "./chunk-GAPMCYR5.js";
@@ -1686,4 +1686,4 @@ export {
1686
1686
  TestNavigationCorrection,
1687
1687
  QtiTestCorrection
1688
1688
  };
1689
- //# sourceMappingURL=chunk-EECRJEZ3.js.map
1689
+ //# sourceMappingURL=chunk-2ZT47EUK.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiTestElements
3
- } from "./chunk-4IWT7GLA.js";
3
+ } from "./chunk-YRR6D6UP.js";
4
4
 
5
5
  // ../qti-test/dist/register.js
6
6
  for (const { tag, ctor } of qtiTestElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiTestElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-HFLK46W3.js.map
11
+ //# sourceMappingURL=chunk-5KNTKBP6.js.map
@@ -3321,6 +3321,163 @@ import { ContextConsumer, consume as consume8, provide as provide4 } from "@lit/
3321
3321
  import { html as html11, LitElement as LitElement13 } from "lit";
3322
3322
  import { property as property12, state as state5 } from "lit/decorators.js";
3323
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
+
3324
3481
  // ../qti-test/dist/internal/rendered-markup.js
3325
3482
  function renderedMarkup(element) {
3326
3483
  return {
@@ -3407,8 +3564,6 @@ var TestNavigation = class extends LitElement13 {
3407
3564
  this.autoScoreItems = false;
3408
3565
  this.#optimality = /* @__PURE__ */ new Map();
3409
3566
  this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
3410
- this.#sectionItems = /* @__PURE__ */ new Map();
3411
- this.#itemOrder = [];
3412
3567
  this.#lockedItems = /* @__PURE__ */ new WeakSet();
3413
3568
  listenPublic2(this, "qc-test-loaded", this.#handleTestConnected.bind(this));
3414
3569
  listenPublic(this, "qc-item-response-changed", this.#handleInteractionChanged.bind(this));
@@ -3429,12 +3584,12 @@ var TestNavigation = class extends LitElement13 {
3429
3584
  const itemContext = event.detail.itemContext;
3430
3585
  if (!itemContext?.identifier)
3431
3586
  return;
3432
- const optimality = this.#assessOptimality(itemContext);
3587
+ const optimality = assessOptimality(itemContext);
3433
3588
  this.#optimality.set(itemContext.identifier, optimality);
3434
3589
  const computedItem = this.computedItemFor(itemContext.identifier);
3435
3590
  const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3436
3591
  const completionStatus = itemContext.variables?.find((v) => v.identifier === "completionStatus")?.value;
3437
- 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));
3438
3593
  }
3439
3594
  /**
3440
3595
  * Extension point for presentation packages reacting to an ended attempt.
@@ -3528,57 +3683,38 @@ var TestNavigation = class extends LitElement13 {
3528
3683
  });
3529
3684
  }
3530
3685
  });
3531
- const model = buildTestModel(renderedMarkup(this.#testElement));
3532
- this.#sectionItems = new Map(model.testParts.flatMap((part) => sectionsInOrder(part.sections).map((section) => [section.identifier, itemRefsInOrder(section.content).map((item) => item.identifier)])));
3533
- this.#itemOrder = model.testParts.flatMap((part) => itemRefsInOrder(part.sections));
3534
- this.computedContext = {
3535
- itemElement: this.#itemElement,
3536
- identifier: model.identifier,
3537
- title: model.title,
3538
- view: this._sessionContext?.view,
3539
- plugins: this._sessionContext?.plugins ?? {},
3540
- testParts: model.testParts.map((testPart) => ({
3541
- active: false,
3542
- identifier: testPart.identifier,
3543
- navigationMode: testPart.navigationMode,
3544
- submissionMode: testPart.submissionMode,
3545
- allowSkipping: testPart.sessionControl.allowSkipping,
3546
- itemOrder: itemRefsInOrder(testPart.sections).map((item) => item.identifier),
3547
- // Flat, depth first: every section once, each with only its own item-refs, so every item is
3548
- // listed once. Where a section's item-refs and subsections interleave, this list is not in
3549
- // document order; `index` is.
3550
- sections: sectionsInOrder(testPart.sections).map((section) => ({
3551
- active: false,
3552
- identifier: section.identifier,
3553
- title: section.title,
3554
- allowSkipping: section.sessionControl.allowSkipping,
3555
- items: ownItemRefs(section).map((item) => ({
3556
- ...this.initContext?.find((i) => i.identifier === item.identifier),
3557
- active: false,
3558
- identifier: item.identifier,
3559
- categories: item.categories,
3560
- href: item.href,
3561
- variables: [],
3562
- sessionControl: { ...item.sessionControl }
3563
- }))
3564
- }))
3565
- }))
3566
- };
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
+ });
3567
3704
  }
3568
3705
  /**
3569
- * The item-refs of each section, its subsections' included, by section identifier: a section that
3570
- * 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.
3571
3709
  */
3572
- #sectionItems;
3573
- /** Every item-ref of the test in document order, which item numbers follow. */
3574
- #itemOrder;
3575
- /** Item numbers in document order, skipping info items; null for an info item. */
3576
- #itemIndexes() {
3577
- let index = 1;
3578
- return new Map(this.#itemOrder.map((item) => [
3579
- item.identifier,
3580
- item.categories.includes(this.configContext?.infoItemCategory) ? null : index++
3581
- ]));
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
+ }
3582
3718
  }
3583
3719
  /**
3584
3720
  * Extract default values from a qti-context-declaration element
@@ -3617,117 +3753,11 @@ var TestNavigation = class extends LitElement13 {
3617
3753
  });
3618
3754
  return defaultValues;
3619
3755
  }
3620
- /** An item's facts as `computedContext` has carried them; nothing until the item is fetched. */
3621
- #factsFor(identifier) {
3622
- const facts = this._itemFacts?.get(identifier);
3623
- if (!facts)
3624
- return {};
3625
- const { identifier: assessmentItemIdentifier, ...rest } = facts;
3626
- return { ...rest, assessmentItemIdentifier };
3627
- }
3628
- /* 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. */
3629
3757
  willUpdate(_changedProperties) {
3630
- if (!this.computedContext)
3758
+ if (!this.#model)
3631
3759
  return;
3632
- const itemIndexes = this.#itemIndexes();
3633
- this.computedContext = {
3634
- ...this.computedContext,
3635
- view: this._sessionContext?.view,
3636
- plugins: this._sessionContext?.plugins ?? {},
3637
- testParts: this.computedContext.testParts.map((testPart) => {
3638
- return {
3639
- ...testPart,
3640
- active: this._sessionContext?.navPartId === testPart.identifier || false,
3641
- sections: testPart.sections.map((section) => {
3642
- return {
3643
- ...section,
3644
- active: this._sessionContext?.navSectionId === section.identifier || false,
3645
- 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"),
3646
- items: section.items.map((item) => {
3647
- const itemContext = this._testContext?.items.find((i) => i.identifier === item.identifier);
3648
- const computedItem = {
3649
- ...item,
3650
- ...this.#factsFor(item.identifier),
3651
- ...itemContext,
3652
- ...this.initContext?.find((i) => i.identifier === item.identifier)
3653
- };
3654
- const rawscore = computedItem.variables?.find((vr) => vr.identifier == "SCORE")?.value;
3655
- const score = rawscore === void 0 || rawscore === null ? null : parseFloat(rawscore?.toString());
3656
- const completionStatus = computedItem.variables?.find((v) => v.identifier === "completionStatus")?.value;
3657
- const response = computedItem.variables?.find((v) => v.identifier === "RESPONSE")?.value || "";
3658
- const numAttempts = Number(computedItem.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3659
- const active = this._sessionContext?.navItemRefId === computedItem.identifier || false;
3660
- const valid = itemContext?.valid ?? true;
3661
- const responseVars = itemContext?.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts") || [];
3662
- const isDefaultResponse = responseVars.every((v) => {
3663
- if (v.value === void 0 || v.value === null) {
3664
- return true;
3665
- }
3666
- let fallbackValue;
3667
- switch (v.baseType) {
3668
- case "integer":
3669
- case "float":
3670
- case "duration":
3671
- fallbackValue = "0";
3672
- break;
3673
- case "boolean":
3674
- fallbackValue = "false";
3675
- break;
3676
- case "string":
3677
- case "directedPair":
3678
- case "identifier":
3679
- case "pair":
3680
- case "record":
3681
- default:
3682
- fallbackValue = "";
3683
- break;
3684
- }
3685
- const defaultValue = v.defaultValue ?? fallbackValue;
3686
- if (Array.isArray(v.value)) {
3687
- const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
3688
- return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);
3689
- }
3690
- return v.value === defaultValue;
3691
- });
3692
- const index = itemIndexes.get(item.identifier) ?? null;
3693
- const rawMaxScore = item.variables?.find((vr) => vr.identifier == "MAXSCORE")?.value;
3694
- const maxScore = rawMaxScore === void 0 || rawMaxScore === null ? null : parseFloat(rawMaxScore?.toString());
3695
- let optimality = this.#optimality.get(computedItem.identifier);
3696
- if (optimality === void 0) {
3697
- optimality = itemContext ? this.#assessOptimality(itemContext) : "unscored";
3698
- if (numAttempts > 0)
3699
- this.#optimality.set(computedItem.identifier, optimality);
3700
- }
3701
- const done = this.#isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus);
3702
- return {
3703
- ...computedItem,
3704
- completionStatus,
3705
- numAttempts,
3706
- score,
3707
- response,
3708
- index,
3709
- active,
3710
- valid,
3711
- isDefaultResponse,
3712
- maxScore,
3713
- done,
3714
- // Reflects the last *ended* attempt only. Read the latch directly
3715
- // (not the `optimality` local) — the latch is written solely on
3716
- // responseProcessed / restore-seed (line above, guarded by
3717
- // numAttempts > 0), so a freshly-picked mid-attempt selection
3718
- // computed live is never stored and never counts as optimal.
3719
- optimal: this.#optimality.get(computedItem.identifier) === "optimal"
3720
- // type,
3721
- // correct,
3722
- // incorrect,
3723
- // completed
3724
- };
3725
- })
3726
- };
3727
- })
3728
- };
3729
- })
3730
- };
3760
+ this.computedContext = this.#derive();
3731
3761
  this.dispatchEvent(new CustomEvent("qti-computed-context-updated", {
3732
3762
  detail: this.computedContext,
3733
3763
  bubbles: true
@@ -3780,88 +3810,6 @@ var TestNavigation = class extends LitElement13 {
3780
3810
  const maxAttempts = item.sessionControl?.maxAttempts ?? 1;
3781
3811
  return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;
3782
3812
  }
3783
- /**
3784
- * Decide whether an item should be treated as "the candidate is done with it"
3785
- * for the purpose of gating forward navigation and further attempts.
3786
- *
3787
- * - The candidate must have actually ended an attempt (numAttempts > 0).
3788
- * - Once attempted, the item is done if they reached the optimal outcome
3789
- * ('optimal'), or there's nothing to improve on ('unscored'). It is only *not*
3790
- * done while a better attempt is still possible ('suboptimal') and attempts
3791
- * remain — see #assessOptimality for how "optimal" is determined.
3792
- *
3793
- * `optimality` reflects the last *ended attempt* (see #optimality), not the
3794
- * live selection — so a freshly-picked optimal answer doesn't count as done
3795
- * until test-end-attempt evaluates it.
3796
- *
3797
- * Adaptive items decide this themselves: max-attempts does not apply to them
3798
- * (QTI 3, itemSessionControl), and a wrong attempt may be the step that leads
3799
- * on to the next part of the item. They are done once their response
3800
- * processing sets completionStatus to 'completed'.
3801
- */
3802
- #isItemDone(numAttempts, optimality, maxAttempts, adaptive, completionStatus) {
3803
- if (numAttempts === 0)
3804
- return false;
3805
- if (adaptive)
3806
- return completionStatus === "completed";
3807
- if (optimality !== "suboptimal")
3808
- return true;
3809
- const max = maxAttempts ?? 1;
3810
- return max > 0 && numAttempts >= max;
3811
- }
3812
- /**
3813
- * Decide whether an item's submission is as good as it can get — i.e. the
3814
- * candidate reached the *optimal* outcome, so there's no reason to make them
3815
- * try again. 'optimal' means best achievable, 'suboptimal' means a better
3816
- * attempt is still possible, 'unscored' means there's nothing to judge against.
3817
- * ("optimal" is the spec's own word — a qti-correct-response is defined as
3818
- * "the (or an) optimal value".)
3819
- *
3820
- * Two signals, in order of authority:
3821
- * 1. The scored outcome: optimal ⟺ SCORE has reached its maximum (MAXSCORE).
3822
- * This correctly handles partial-credit / qti-mapping items, where an exact
3823
- * response match would under- or over-judge.
3824
- * 2. The declared qti-correct-response, for items that aren't scored (no
3825
- * SCORE/MAXSCORE) — an exact match is the best available proxy. Bookkeeping
3826
- * variables like numAttempts can be typed 'response' but never declare a
3827
- * correctResponse, so we filter on a declared correctResponse.
3828
- *
3829
- * Items with neither a comparable score nor a correctResponse (essays, info
3830
- * items, etc.) are 'unscored' — there's no optimal value to require, so one
3831
- * attempt is enough.
3832
- */
3833
- #assessOptimality(item) {
3834
- const variables = item.variables ?? [];
3835
- const score = this.#numericVariable(variables, "SCORE");
3836
- const maxScore = this.#numericVariable(variables, "MAXSCORE");
3837
- if (score !== null && maxScore !== null) {
3838
- return score >= maxScore ? "optimal" : "suboptimal";
3839
- }
3840
- const responseVars = variables.filter((v) => v.type === "response" && v.correctResponse !== void 0 && v.correctResponse !== null);
3841
- if (responseVars.length === 0)
3842
- return "unscored";
3843
- const allMatch = responseVars.every((v) => {
3844
- const expected = v.correctResponse;
3845
- const actual = v.value;
3846
- if (actual === void 0 || actual === null)
3847
- return false;
3848
- if (Array.isArray(expected) && Array.isArray(actual)) {
3849
- return expected.length === actual.length && expected.every((e) => actual.includes(e));
3850
- }
3851
- if (Array.isArray(expected) || Array.isArray(actual))
3852
- return false;
3853
- return expected === actual;
3854
- });
3855
- return allMatch ? "optimal" : "suboptimal";
3856
- }
3857
- /** Read a single numeric outcome value, or null when absent / non-numeric. */
3858
- #numericVariable(variables, identifier) {
3859
- const raw = variables?.find((v) => v.identifier === identifier)?.value;
3860
- if (raw === void 0 || raw === null || Array.isArray(raw))
3861
- return null;
3862
- const parsed = parseFloat(raw.toString());
3863
- return Number.isNaN(parsed) ? null : parsed;
3864
- }
3865
3813
  };
3866
3814
  __decorate15([
3867
3815
  property12({ type: String })
@@ -4104,4 +4052,4 @@ export {
4104
4052
  * Portions Copyright (c) 2013, the Dart project authors.
4105
4053
  *)
4106
4054
  */
4107
- //# sourceMappingURL=chunk-4IWT7GLA.js.map
4055
+ //# sourceMappingURL=chunk-YRR6D6UP.js.map