@pie-qti/item-player 0.1.20 → 0.1.21

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.
@@ -23,6 +23,7 @@ export declare class Player {
23
23
  private componentRegistry;
24
24
  private i18nProvider;
25
25
  private mapper;
26
+ private warnedImpliedZeroMaxScore;
26
27
  private responseProcessingProgram;
27
28
  private responseProcessing;
28
29
  private templateProcessingProgram;
@@ -147,6 +148,13 @@ export declare class Player {
147
148
  private resetOutcomesToDefault;
148
149
  private resetResponsesToDefault;
149
150
  private resetTemplatesToDefault;
151
+ /**
152
+ * A MAXSCORE declared without a <defaultValue> is 0 per the numeric outcome rule, so an item
153
+ * that never assigns it scores against a maximum of zero. That is the spec-correct reading of
154
+ * under-specified content, and silently substituting 1 would make this engine disagree with a
155
+ * conformant one — so surface the authoring gap instead of masking it.
156
+ */
157
+ private warnOnceOnImpliedZeroMaxScore;
150
158
  private runResponseProcessing;
151
159
  getItemBodyHtml(): HtmlContent;
152
160
  /**
@@ -230,6 +238,15 @@ export declare class Player {
230
238
  private updateDuration;
231
239
  private freezeDuration;
232
240
  private getDuration;
241
+ /**
242
+ * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is
243
+ * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.
244
+ * Response and template variables keep NULL — an unanswered numeric response must stay
245
+ * distinguishable from an answered zero.
246
+ */
247
+ private hasImpliedNumericDefault;
248
+ private impliedDefaultValue;
249
+ /** Returns undefined when the declaration carries no <defaultValue> at all. */
233
250
  private parseDefaultValue;
234
251
  private parseCorrectResponse;
235
252
  private parseDeclarationValues;
@@ -33,6 +33,7 @@ export function createPlayerFromPreparedInternal(config, prepared, skipTemplateP
33
33
  export class Player {
34
34
  constructor(config, prepared, construction = {}) {
35
35
  this.interactionDataCache = null;
36
+ this.warnedImpliedZeroMaxScore = false;
36
37
  this.responseProcessingProgram = null;
37
38
  this.templateProcessingProgram = null;
38
39
  this.outcomeProcessingProgram = null;
@@ -553,6 +554,24 @@ export class Player {
553
554
  this.ctx.resetToDefault(d.identifier);
554
555
  }
555
556
  }
557
+ /**
558
+ * A MAXSCORE declared without a <defaultValue> is 0 per the numeric outcome rule, so an item
559
+ * that never assigns it scores against a maximum of zero. That is the spec-correct reading of
560
+ * under-specified content, and silently substituting 1 would make this engine disagree with a
561
+ * conformant one — so surface the authoring gap instead of masking it.
562
+ */
563
+ warnOnceOnImpliedZeroMaxScore(outcomes) {
564
+ if (this.warnedImpliedZeroMaxScore)
565
+ return;
566
+ if (!this.decls.MAXSCORE?.impliedNumericDefault)
567
+ return;
568
+ if (outcomes.MAXSCORE !== 0)
569
+ return;
570
+ this.warnedImpliedZeroMaxScore = true;
571
+ console.warn(`[QTI Player] MAXSCORE is 0 for item "${this.itemDocument.getAssessmentItemAttribute('identifier') ?? 'unknown'}": its outcomeDeclaration ` +
572
+ 'has no <defaultValue>, so QTI initializes it to 0 and response processing never assigned it. ' +
573
+ 'Declare <defaultValue> on the MAXSCORE outcomeDeclaration to score against a real maximum.');
574
+ }
556
575
  runResponseProcessing(options) {
557
576
  this.updateDuration();
558
577
  // Spec-aligned behavior: each processing run starts from outcome defaults.
@@ -581,6 +600,7 @@ export class Player {
581
600
  }
582
601
  }
583
602
  const outcomes = this.collectOutcomes();
603
+ this.warnOnceOnImpliedZeroMaxScore(outcomes);
584
604
  const score = Number(outcomes.SCORE ?? 0);
585
605
  const maxScore = Number(outcomes.MAXSCORE ?? 1);
586
606
  const completionStatus = outcomes.completionStatus ?? 'not_attempted';
@@ -1091,7 +1111,9 @@ export class Player {
1091
1111
  : (this.getAttrMapped(el, 'baseType') || 'string');
1092
1112
  if (!identifier)
1093
1113
  return;
1094
- const defaultValue = this.parseDefaultValue(el, baseType, cardinality);
1114
+ const declaredDefault = this.parseDefaultValue(el, baseType, cardinality);
1115
+ const impliedNumericDefault = !declaredDefault && this.hasImpliedNumericDefault(kind, baseType, cardinality);
1116
+ const defaultValue = declaredDefault ?? this.impliedDefaultValue(kind, baseType, cardinality);
1095
1117
  decls[identifier] = {
1096
1118
  identifier,
1097
1119
  ...(baseType ? { baseType } : {}),
@@ -1099,6 +1121,7 @@ export class Player {
1099
1121
  defaultValue,
1100
1122
  value: defaultValue,
1101
1123
  isTemplate: kind === 'template',
1124
+ impliedNumericDefault,
1102
1125
  // @ts-expect-error internal marker for templates
1103
1126
  __kind: kind,
1104
1127
  };
@@ -1345,10 +1368,28 @@ export class Player {
1345
1368
  const value = this.ctx.getValue('duration');
1346
1369
  return Math.max(0, Math.floor(toNumber(value) || 0));
1347
1370
  }
1371
+ /**
1372
+ * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is
1373
+ * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.
1374
+ * Response and template variables keep NULL — an unanswered numeric response must stay
1375
+ * distinguishable from an answered zero.
1376
+ */
1377
+ hasImpliedNumericDefault(kind, baseType, cardinality) {
1378
+ if (kind !== 'outcome' || cardinality !== 'single')
1379
+ return false;
1380
+ return baseType === 'integer' || baseType === 'float';
1381
+ }
1382
+ impliedDefaultValue(kind, baseType, cardinality) {
1383
+ if (this.hasImpliedNumericDefault(kind, baseType, cardinality)) {
1384
+ return qtiValue(baseType, 'single', 0);
1385
+ }
1386
+ return qtiNull(baseType, cardinality);
1387
+ }
1388
+ /** Returns undefined when the declaration carries no <defaultValue> at all. */
1348
1389
  parseDefaultValue(declEl, baseType, cardinality) {
1349
1390
  const defaultEl = findFirstDescendant(declEl, this.mapper.toNative('defaultvalue'));
1350
1391
  if (!defaultEl)
1351
- return qtiNull(baseType, cardinality);
1392
+ return undefined;
1352
1393
  return this.parseDeclarationValues(defaultEl, baseType, cardinality);
1353
1394
  }
1354
1395
  parseCorrectResponse(correctEl, baseType, cardinality) {