@astl/core 0.0.0 → 0.1.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +202 -0
  3. package/README.md +38 -0
  4. package/dist/answers.d.ts +29 -0
  5. package/dist/answers.d.ts.map +1 -0
  6. package/dist/answers.js +40 -0
  7. package/dist/answers.js.map +1 -0
  8. package/dist/ast.d.ts +25 -0
  9. package/dist/ast.d.ts.map +1 -0
  10. package/dist/ast.js +27 -0
  11. package/dist/ast.js.map +1 -0
  12. package/dist/authoring.d.ts +451 -0
  13. package/dist/authoring.d.ts.map +1 -0
  14. package/dist/authoring.js +2 -0
  15. package/dist/authoring.js.map +1 -0
  16. package/dist/checker.d.ts +78 -0
  17. package/dist/checker.d.ts.map +1 -0
  18. package/dist/checker.js +10 -0
  19. package/dist/checker.js.map +1 -0
  20. package/dist/compiled.d.ts +94 -0
  21. package/dist/compiled.d.ts.map +1 -0
  22. package/dist/compiled.js +16 -0
  23. package/dist/compiled.js.map +1 -0
  24. package/dist/content.d.ts +72 -0
  25. package/dist/content.d.ts.map +1 -0
  26. package/dist/content.js +128 -0
  27. package/dist/content.js.map +1 -0
  28. package/dist/declarations.d.ts +52 -0
  29. package/dist/declarations.d.ts.map +1 -0
  30. package/dist/declarations.js +358 -0
  31. package/dist/declarations.js.map +1 -0
  32. package/dist/definition.d.ts +106 -0
  33. package/dist/definition.d.ts.map +1 -0
  34. package/dist/definition.js +2 -0
  35. package/dist/definition.js.map +1 -0
  36. package/dist/engine.d.ts +95 -0
  37. package/dist/engine.d.ts.map +1 -0
  38. package/dist/engine.js +2 -0
  39. package/dist/engine.js.map +1 -0
  40. package/dist/format.d.ts +29 -0
  41. package/dist/format.d.ts.map +1 -0
  42. package/dist/format.js +55 -0
  43. package/dist/format.js.map +1 -0
  44. package/dist/help.d.ts +38 -0
  45. package/dist/help.d.ts.map +1 -0
  46. package/dist/help.js +22 -0
  47. package/dist/help.js.map +1 -0
  48. package/dist/i18n/check.d.ts +11 -0
  49. package/dist/i18n/check.d.ts.map +1 -0
  50. package/dist/i18n/check.js +64 -0
  51. package/dist/i18n/check.js.map +1 -0
  52. package/dist/i18n/format.d.ts +40 -0
  53. package/dist/i18n/format.d.ts.map +1 -0
  54. package/dist/i18n/format.js +280 -0
  55. package/dist/i18n/format.js.map +1 -0
  56. package/dist/i18n/i18n.d.ts +14 -0
  57. package/dist/i18n/i18n.d.ts.map +1 -0
  58. package/dist/i18n/i18n.js +82 -0
  59. package/dist/i18n/i18n.js.map +1 -0
  60. package/dist/i18n/types.d.ts +31 -0
  61. package/dist/i18n/types.d.ts.map +1 -0
  62. package/dist/i18n/types.js +7 -0
  63. package/dist/i18n/types.js.map +1 -0
  64. package/dist/index.d.ts +45 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +21 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/issues.d.ts +98 -0
  69. package/dist/issues.d.ts.map +1 -0
  70. package/dist/issues.js +74 -0
  71. package/dist/issues.js.map +1 -0
  72. package/dist/json.d.ts +7 -0
  73. package/dist/json.d.ts.map +1 -0
  74. package/dist/json.js +2 -0
  75. package/dist/json.js.map +1 -0
  76. package/dist/manifest.d.ts +135 -0
  77. package/dist/manifest.d.ts.map +1 -0
  78. package/dist/manifest.js +63 -0
  79. package/dist/manifest.js.map +1 -0
  80. package/dist/player.d.ts +129 -0
  81. package/dist/player.d.ts.map +1 -0
  82. package/dist/player.js +18 -0
  83. package/dist/player.js.map +1 -0
  84. package/dist/policy.d.ts +53 -0
  85. package/dist/policy.d.ts.map +1 -0
  86. package/dist/policy.js +55 -0
  87. package/dist/policy.js.map +1 -0
  88. package/dist/protocol.d.ts +54 -0
  89. package/dist/protocol.d.ts.map +1 -0
  90. package/dist/protocol.js +51 -0
  91. package/dist/protocol.js.map +1 -0
  92. package/dist/result.d.ts +44 -0
  93. package/dist/result.d.ts.map +1 -0
  94. package/dist/result.js +5 -0
  95. package/dist/result.js.map +1 -0
  96. package/dist/scoring.d.ts +27 -0
  97. package/dist/scoring.d.ts.map +1 -0
  98. package/dist/scoring.js +6 -0
  99. package/dist/scoring.js.map +1 -0
  100. package/dist/slots.d.ts +47 -0
  101. package/dist/slots.d.ts.map +1 -0
  102. package/dist/slots.js +9 -0
  103. package/dist/slots.js.map +1 -0
  104. package/dist/snapshot.d.ts +23 -0
  105. package/dist/snapshot.d.ts.map +1 -0
  106. package/dist/snapshot.js +22 -0
  107. package/dist/snapshot.js.map +1 -0
  108. package/dist/style.d.ts +51 -0
  109. package/dist/style.d.ts.map +1 -0
  110. package/dist/style.js +36 -0
  111. package/dist/style.js.map +1 -0
  112. package/package.json +52 -4
  113. package/src/answers.ts +52 -0
  114. package/src/ast.ts +49 -0
  115. package/src/authoring.ts +475 -0
  116. package/src/checker.ts +91 -0
  117. package/src/compiled.ts +115 -0
  118. package/src/content.ts +156 -0
  119. package/src/declarations.ts +427 -0
  120. package/src/definition.ts +104 -0
  121. package/src/engine.ts +98 -0
  122. package/src/format.ts +67 -0
  123. package/src/help.ts +41 -0
  124. package/src/i18n/check.ts +67 -0
  125. package/src/i18n/format.ts +318 -0
  126. package/src/i18n/i18n.ts +92 -0
  127. package/src/i18n/types.ts +35 -0
  128. package/src/index.ts +201 -0
  129. package/src/issues.ts +107 -0
  130. package/src/json.ts +6 -0
  131. package/src/manifest.ts +193 -0
  132. package/src/player.ts +145 -0
  133. package/src/policy.ts +117 -0
  134. package/src/protocol.ts +65 -0
  135. package/src/result.ts +53 -0
  136. package/src/scoring.ts +31 -0
  137. package/src/slots.ts +57 -0
  138. package/src/snapshot.ts +40 -0
  139. package/src/style.ts +89 -0
@@ -0,0 +1,63 @@
1
+ import { STYLE_TEMPLATE_ATTRIBUTE } from './style.js';
2
+ /** Attributes every component accepts. `scoring` and `points` only apply to graded types. */
3
+ export const COMMON_ATTRIBUTES = [
4
+ /** Source id, unique in the document. Views carry an opaque id instead. */
5
+ { name: 'id', type: 'id', visibility: 'public', required: true },
6
+ /** Element format version. Optional in sources (absent = 1); the compiler always writes the current one. */
7
+ { name: 'v', type: 'integer', visibility: 'public', min: 1 },
8
+ /** A registered StyleTemplate with the `component` scope (see style.ts); checked by the engine's registry. */
9
+ { name: STYLE_TEMPLATE_ATTRIBUTE, type: 'string', visibility: 'public' },
10
+ ];
11
+ export const SCORING_ATTRIBUTES = [
12
+ /** One of the manifest's scoring modes; absent = the manifest's default mode. */
13
+ { name: 'scoring', type: 'string', visibility: 'private' },
14
+ /** Points of the element's scoring group. */
15
+ { name: 'points', type: 'number', visibility: 'private', min: 0.01, max: 1000, default: 1 },
16
+ ];
17
+ /** The `variant` attribute of a type with variants: an enum of the manifest's variant names. */
18
+ export function variantAttribute(variants) {
19
+ return {
20
+ name: 'variant',
21
+ type: 'enum',
22
+ visibility: 'public',
23
+ values: variants.values,
24
+ default: variants.default,
25
+ };
26
+ }
27
+ /** Every attribute an element of this type may carry, common ones first. */
28
+ export function allAttributes(manifest) {
29
+ const scoring = manifest.scoring === null ? [] : SCORING_ATTRIBUTES;
30
+ const variant = manifest.variants === null ? [] : [variantAttribute(manifest.variants)];
31
+ return [...COMMON_ATTRIBUTES, ...scoring, ...variant, ...manifest.attributes];
32
+ }
33
+ /** JSON with object keys sorted, so equal specs compare equal whatever order their keys are written in. */
34
+ function canonical(value) {
35
+ return JSON.stringify(value, (_key, v) => v !== null && typeof v === 'object' && !Array.isArray(v)
36
+ ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : 1)))
37
+ : v);
38
+ }
39
+ /**
40
+ * Whether two child specs may share a tag: the same visibility and attributes (in any order), so the tag carries the
41
+ * same data and keeps the same things private in every type that declares it (`astl-prompt`, `astl-option`). Content
42
+ * and counts are each type's own: a select's options are plain text, a choice's options rich.
43
+ */
44
+ export function sameChildSpec(a, b) {
45
+ const attributes = (spec) => canonical([...spec.attributes].sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0)));
46
+ return a.visibility === b.visibility && attributes(a) === attributes(b);
47
+ }
48
+ /** A child tag two of the manifests declare with specs that differ (see `sameChildSpec`), or null when none does. */
49
+ export function childTagConflict(manifests) {
50
+ const first = new Map();
51
+ for (const manifest of manifests) {
52
+ for (const child of manifest.children) {
53
+ const seen = first.get(child.tag);
54
+ if (seen === undefined)
55
+ first.set(child.tag, { component: manifest.tag, spec: child });
56
+ else if (!sameChildSpec(seen.spec, child)) {
57
+ return { tag: child.tag, components: [seen.component, manifest.tag] };
58
+ }
59
+ }
60
+ }
61
+ return null;
62
+ }
63
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAoHtD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,iBAAiB,GAA6B;IACzD,2EAA2E;IAC3E,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;IAChE,4GAA4G;IAC5G,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE;IAC5D,8GAA8G;IAC9G,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE;CACzE,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA6B;IAC1D,iFAAiF;IACjF,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE;IAC1D,6CAA6C;IAC7C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG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AI,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Player element contract. Every component element (built-in or third-party, Lit or not) implements
3
+ * PlayerElementApi; `<astl-player>` talks to elements only through it. No DOM types here on purpose:
4
+ * the player package intersects it with HTMLElement.
5
+ */
6
+ import type { Answers, SlotId } from './answers.js';
7
+ import type { Checker } from './checker.js';
8
+ import type { Feedback } from './help.js';
9
+ import type { MessageParams } from './i18n/types.js';
10
+ import type { JsonValue } from './json.js';
11
+ import type { GroupVerdict, SlotVerdict, Solution } from './result.js';
12
+ export interface ElementFeedback {
13
+ /** Verdicts for this element's slots that the student may see. */
14
+ readonly slots: Readonly<Record<SlotId, SlotVerdict>>;
15
+ /** Verdict of the element's scoring group; null when ungraded or graded in parts. */
16
+ readonly group: GroupVerdict | null;
17
+ /** Verdicts of the groups an element graded in parts names in `groupIds` (a crossword's words), by group id. */
18
+ readonly groups?: Readonly<Record<string, GroupVerdict>>;
19
+ /**
20
+ * The author's feedback for the element's verdict and its explanation (HTML), when the policy shows them. The player
21
+ * shows both under the element, so an element needs to do nothing with them.
22
+ */
23
+ readonly message?: Feedback | null;
24
+ readonly explanation?: string | null;
25
+ }
26
+ export interface Units {
27
+ readonly answered: number;
28
+ readonly total: number;
29
+ }
30
+ /** What the player gives each element when it mounts the view. */
31
+ export interface ElementContext {
32
+ /** UI locale for labels and announcements (not the content language). */
33
+ readonly locale: string;
34
+ /**
35
+ * Formats a message in the UI locale from the element type's namespace, falling back to the shared `astl.player`
36
+ * namespace (verdict words such as `verdict.correct`, generic labels).
37
+ */
38
+ t(key: string, params?: MessageParams): string;
39
+ /** Polite announcement through the player's single live region. */
40
+ announce(message: string): void;
41
+ /** 1-based position among numbered elements (inline questions), for labels such as "Gap 3". 0 = not numbered. */
42
+ readonly number: number;
43
+ /** Per-attempt seed for UI shuffles; null = keep the view order. */
44
+ readonly seed: string | null;
45
+ }
46
+ export interface PlayerElementApi {
47
+ /** Slot ids this element answers, in reading order. Stable after the element connects. */
48
+ readonly slotIds: readonly SlotId[];
49
+ /**
50
+ * The ids of the groups an element may be graded in (`ComponentDefinition.groups`), as its view names them: the
51
+ * player passes their verdicts in `feedback.groups`. Absent: one group, the element's id.
52
+ */
53
+ readonly groupIds?: readonly string[];
54
+ /** Answered slots only. */
55
+ getAnswers(): Answers;
56
+ /** Unknown ids are ignored; `''` clears a slot. Does not fire a change event. */
57
+ setAnswers(answers: Answers): void;
58
+ /** Shows verdicts; null clears them. Editing a slot clears its own verdict. */
59
+ feedback: ElementFeedback | null;
60
+ /** Shows the correct answers next to the student's; null hides them. */
61
+ solution: Solution | null;
62
+ disabled: boolean;
63
+ /** Progress units, e.g. 3 of 5 cards placed. */
64
+ units(): Units;
65
+ /** Called by the player once, before the first render. Elements must work with a default context too. */
66
+ attach(context: ElementContext): void;
67
+ /** Non-answer UI state worth restoring after a reload. */
68
+ getUiState?(): JsonValue;
69
+ setUiState?(state: JsonValue): void;
70
+ }
71
+ /** DOM events. All bubble and are composed (they cross shadow roots). */
72
+ export declare const PlayerEvent: {
73
+ /** From an element when the student changes an answer. Detail: ChangeDetail. */
74
+ readonly change: 'astl-change';
75
+ /** From `<astl-player>` when the view is mounted and elements are attached. Detail: ReadyDetail. */
76
+ readonly ready: 'astl-ready';
77
+ /** Page changed. Detail: PageDetail. */
78
+ readonly page: 'astl-page';
79
+ /** Attempt state changed. Detail: StateDetail. */
80
+ readonly state: 'astl-state';
81
+ /** A check or submit finished. Detail: the CheckResponse or SubmitResponse. */
82
+ readonly result: 'astl-result';
83
+ /** Snapshot to persist (debounced). Detail: Snapshot. */
84
+ readonly snapshot: 'astl-snapshot';
85
+ /** Loading or grading failed. Detail: ErrorDetail. */
86
+ readonly error: 'astl-error';
87
+ };
88
+ /** Detail of `astl-ready`. */
89
+ export interface ReadyDetail {
90
+ readonly viewHash: string;
91
+ /** Number of pages. */
92
+ readonly pages: number;
93
+ /** Number of slots across all registered elements. */
94
+ readonly slots: number;
95
+ }
96
+ export interface ChangeDetail {
97
+ /** Changed slots only; `''` = cleared. */
98
+ readonly answers: Answers;
99
+ }
100
+ export interface PageDetail {
101
+ readonly index: number;
102
+ readonly count: number;
103
+ /** View page id. */
104
+ readonly id: string;
105
+ }
106
+ export type AttemptState = 'loading' | 'ready' | 'active' | 'checking' | 'submitting' | 'submitted' | 'review' | 'error';
107
+ export interface StateDetail {
108
+ readonly state: AttemptState;
109
+ readonly previous: AttemptState;
110
+ }
111
+ export interface ErrorDetail {
112
+ readonly code: string;
113
+ readonly message: string;
114
+ }
115
+ /**
116
+ * Turns source HTML (with answers) into a view and a checker for it, for `<astl-player>` light-DOM sources. Registered
117
+ * by bundles that ship the engine (the HTML-with-answers mode); the player itself never holds answer logic.
118
+ * - `lang`: content language of the source (filled from the page when the `<astl-doc>` has none);
119
+ * - `locale`: UI locale of the asking player, for the messages of a failed compile.
120
+ * A failed compile throws; the Error message (plain text, one issue per line) is shown to the author.
121
+ */
122
+ export type SourceCompiler = (source: string, context: {
123
+ readonly lang: string;
124
+ readonly locale: string;
125
+ }) => Promise<{
126
+ readonly view: string;
127
+ readonly checker: Checker;
128
+ }>;
129
+ //# sourceMappingURL=player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK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AAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,OAAO,GACP,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KACxD,OAAO,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC"}
package/dist/player.js ADDED
@@ -0,0 +1,18 @@
1
+ /** DOM events. All bubble and are composed (they cross shadow roots). */
2
+ export const PlayerEvent = {
3
+ /** From an element when the student changes an answer. Detail: ChangeDetail. */
4
+ change: 'astl-change',
5
+ /** From `<astl-player>` when the view is mounted and elements are attached. Detail: ReadyDetail. */
6
+ ready: 'astl-ready',
7
+ /** Page changed. Detail: PageDetail. */
8
+ page: 'astl-page',
9
+ /** Attempt state changed. Detail: StateDetail. */
10
+ state: 'astl-state',
11
+ /** A check or submit finished. Detail: the CheckResponse or SubmitResponse. */
12
+ result: 'astl-result',
13
+ /** Snapshot to persist (debounced). Detail: Snapshot. */
14
+ snapshot: 'astl-snapshot',
15
+ /** Loading or grading failed. Detail: ErrorDetail. */
16
+ error: 'astl-error',
17
+ };
18
+ //# sourceMappingURL=player.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player.js","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AA2EA,yEAAyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,gFAAgF;IAChF,MAAM,EAAE,aAAa;IACrB,oGAAoG;IACpG,KAAK,EAAE,YAAY;IACnB,wCAAwC;IACxC,IAAI,EAAE,WAAW;IACjB,kDAAkD;IAClD,KAAK,EAAE,YAAY;IACnB,+EAA+E;IAC/E,MAAM,EAAE,aAAa;IACrB,yDAAyD;IACzD,QAAQ,EAAE,eAAe;IACzB,sDAAsD;IACtD,KAAK,EAAE,YAAY;CACX,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Attempt policies. Practice, quiz and test are policies over the same content, not different content: a document's
3
+ * `kind` (`DOC_KINDS`, exercise or book) is how it shows, never how it grades.
4
+ * The server is authoritative: the player only reflects the policy it is given.
5
+ */
6
+ export type AttemptMode = 'practice' | 'test' | 'review';
7
+ /**
8
+ * What a submit returns to the student:
9
+ * - `nothing`: just the confirmation (results released later by the host);
10
+ * - `score`: score and verdicts;
11
+ * - `answers`: score, verdicts and the solution.
12
+ */
13
+ export type Reveal = 'nothing' | 'score' | 'answers';
14
+ /** `interaction`: a check may cover one interaction too (`CheckRequest.element`), not only the exercise or a page. */
15
+ export type CheckScope = 'exercise' | 'interaction';
16
+ /**
17
+ * When feedback texts or explanations come: `never`; `check`: after every check and the hand-in; `submit`: after the
18
+ * hand-in only. At the hand-in they come only with the answers (`reveal: 'answers'`): they may give them away.
19
+ */
20
+ export type HelpMoment = 'never' | 'check' | 'submit';
21
+ export interface AttemptPolicy {
22
+ /** `practice`: check any time. `test`: no check, one submit. `review`: read-only, shows a submitted attempt. */
23
+ readonly mode: AttemptMode;
24
+ /** `linear`: no going back to earlier pages (tests). */
25
+ readonly navigation: 'free' | 'linear';
26
+ /** Practice only. null = unlimited. */
27
+ readonly maxChecks: number | null;
28
+ /** ISO 8601. The server auto-submits at the deadline; the player only shows the countdown. */
29
+ readonly deadline: string | null;
30
+ /** Fraction of the maximum score needed to pass, 0..1. null = no pass mark. */
31
+ readonly passMark: number | null;
32
+ readonly reveal: Reveal;
33
+ /** Seed for per-attempt UI shuffles. null = keep the view order. */
34
+ readonly seed: string | null;
35
+ /** Hints on request, one at a time from the checker (`Checker.hint`). Practice only. */
36
+ readonly hints?: boolean;
37
+ /** Practice only. */
38
+ readonly checkScope?: CheckScope;
39
+ readonly feedback?: HelpMoment;
40
+ readonly explanations?: HelpMoment;
41
+ }
42
+ export declare const PRACTICE_POLICY: AttemptPolicy;
43
+ export declare const TEST_POLICY: AttemptPolicy;
44
+ /** The help fields of a policy, with every absent one taken from its mode's default policy. */
45
+ export interface HelpPolicy {
46
+ readonly hints: boolean;
47
+ readonly checkScope: CheckScope;
48
+ readonly feedback: HelpMoment;
49
+ readonly explanations: HelpMoment;
50
+ }
51
+ export declare function helpPolicy(policy: AttemptPolicy): HelpPolicy;
52
+ export declare function isAttemptPolicy(value: unknown): value is AttemptPolicy;
53
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAErD,sHAAsH;AACtH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,gHAAgH;IAChH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC;IACvC,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,8FAA8F;IAC9F,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAI7B,wFAAwF;IACxF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,qBAAqB;IACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC;CACpC;AAED,eAAO,MAAM,eAAe,EAAE,aAY7B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,aAYzB,CAAC;AAEF,+FAA+F;AAC/F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;CACnC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAS5D;AAID,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAkBtE"}
package/dist/policy.js ADDED
@@ -0,0 +1,55 @@
1
+ export const PRACTICE_POLICY = {
2
+ mode: 'practice',
3
+ navigation: 'free',
4
+ maxChecks: null,
5
+ deadline: null,
6
+ passMark: null,
7
+ reveal: 'answers',
8
+ seed: null,
9
+ hints: true,
10
+ checkScope: 'interaction',
11
+ feedback: 'check',
12
+ explanations: 'check',
13
+ };
14
+ export const TEST_POLICY = {
15
+ mode: 'test',
16
+ navigation: 'free',
17
+ maxChecks: 0,
18
+ deadline: null,
19
+ passMark: null,
20
+ reveal: 'score',
21
+ seed: null,
22
+ hints: false,
23
+ checkScope: 'exercise',
24
+ feedback: 'submit',
25
+ explanations: 'submit',
26
+ };
27
+ export function helpPolicy(policy) {
28
+ const base = policy.mode === 'practice' ? PRACTICE_POLICY : TEST_POLICY;
29
+ const practice = policy.mode === 'practice';
30
+ return {
31
+ hints: practice && (policy.hints ?? base.hints) === true,
32
+ checkScope: practice ? (policy.checkScope ?? base.checkScope ?? 'exercise') : 'exercise',
33
+ feedback: policy.feedback ?? base.feedback ?? 'never',
34
+ explanations: policy.explanations ?? base.explanations ?? 'never',
35
+ };
36
+ }
37
+ const isMoment = (x) => x === 'never' || x === 'check' || x === 'submit';
38
+ export function isAttemptPolicy(value) {
39
+ if (typeof value !== 'object' || value === null)
40
+ return false;
41
+ const v = value;
42
+ const nullableNumber = (x) => x === null || (typeof x === 'number' && Number.isFinite(x) && x >= 0);
43
+ return ((v.mode === 'practice' || v.mode === 'test' || v.mode === 'review') &&
44
+ (v.navigation === 'free' || v.navigation === 'linear') &&
45
+ nullableNumber(v.maxChecks) &&
46
+ (v.deadline === null || (typeof v.deadline === 'string' && !Number.isNaN(Date.parse(v.deadline)))) &&
47
+ (v.passMark === null || (typeof v.passMark === 'number' && v.passMark >= 0 && v.passMark <= 1)) &&
48
+ (v.reveal === 'nothing' || v.reveal === 'score' || v.reveal === 'answers') &&
49
+ (v.seed === null || typeof v.seed === 'string') &&
50
+ (v.hints === undefined || typeof v.hints === 'boolean') &&
51
+ (v.checkScope === undefined || v.checkScope === 'exercise' || v.checkScope === 'interaction') &&
52
+ (v.feedback === undefined || isMoment(v.feedback)) &&
53
+ (v.explanations === undefined || isMoment(v.explanations)));
54
+ }
55
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"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AAI,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC;QAC1E,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;QAC/C,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC;QACvD,CAAC,CAAC,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,KAAK,UAAU,IAAI,CAAC,CAAC,UAAU,KAAK,aAAa,CAAC;QAC7F,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC,YAAY,KAAK,SAAS,IAAI,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Grading protocol over HTTP. Any backend in any language can implement it:
3
+ *
4
+ * POST {endpoint}/check body CheckRequest -> 200 CheckResponse
5
+ * POST {endpoint}/submit body SubmitRequest -> 200 SubmitResponse
6
+ * POST {endpoint}/hint body HintRequest -> 200 HintResponse
7
+ *
8
+ * `{endpoint}` identifies one attempt (e.g. `/api/attempts/123`); how it is authorised is up to the host
9
+ * (cookie, bearer token). Errors are `application/problem+json` (RFC 9457) with a `code` from ProblemCode.
10
+ */
11
+ export declare const PROTOCOL_VERSION = 1;
12
+ export declare const JSON_MEDIA_TYPE = "application/json";
13
+ export declare const PROBLEM_MEDIA_TYPE = "application/problem+json";
14
+ export declare const ProtocolPath: {
15
+ readonly check: 'check';
16
+ readonly submit: 'submit';
17
+ readonly hint: 'hint';
18
+ };
19
+ export declare const ProblemCode: {
20
+ /** 400: body is not valid JSON or does not match the request schema. */
21
+ readonly invalidRequest: 'invalid_request';
22
+ /** 401: the host could not identify the attempt. */
23
+ readonly unauthorized: 'unauthorized';
24
+ /** 403: checking is not allowed under this policy (tests). */
25
+ readonly checkNotAllowed: 'check_not_allowed';
26
+ /** 403: the practice policy's maxChecks is used up. */
27
+ readonly checksExhausted: 'checks_exhausted';
28
+ /** 403: the policy offers no hints (tests, or a practice policy with `hints: false`). */
29
+ readonly hintsNotAllowed: 'hints_not_allowed';
30
+ /** 403: every hint of that interaction or page is used. */
31
+ readonly hintsExhausted: 'hints_exhausted';
32
+ /** 404: unknown attempt, page or element. */
33
+ readonly notFound: 'not_found';
34
+ /** 405: wrong method. */
35
+ readonly methodNotAllowed: 'method_not_allowed';
36
+ /** 409: the attempt is already submitted. */
37
+ readonly attemptClosed: 'attempt_closed';
38
+ /** 413: body too large. */
39
+ readonly payloadTooLarge: 'payload_too_large';
40
+ /** 500: unexpected server error. */
41
+ readonly internal: 'internal_error';
42
+ };
43
+ export type ProblemCodeValue = (typeof ProblemCode)[keyof typeof ProblemCode];
44
+ export interface ProblemDetails {
45
+ readonly type: string;
46
+ readonly title: string;
47
+ readonly status: number;
48
+ readonly detail?: string;
49
+ readonly code: ProblemCodeValue;
50
+ }
51
+ /** Largest request body servers should accept, in bytes. */
52
+ export declare const MAX_REQUEST_BYTES: number;
53
+ export declare function isProblemDetails(value: unknown): value is ProblemDetails;
54
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D,eAAO,MAAM,YAAY;aACvB,KAAK,EAAE,OAAO;aACd,MAAM,EAAE,QAAQ;aAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,eAAO,MAAM,WAAW;IACtB,wEAAwE;aACxE,cAAc,EAAE,iBAAiB;IACjC,oDAAoD;aACpD,YAAY,EAAE,cAAc;IAC5B,8DAA8D;aAC9D,eAAe,EAAE,mBAAmB;IACpC,uDAAuD;aACvD,eAAe,EAAE,kBAAkB;IACnC,yFAAyF;aACzF,eAAe,EAAE,mBAAmB;IACpC,2DAA2D;aAC3D,cAAc,EAAE,iBAAiB;IACjC,6CAA6C;aAC7C,QAAQ,EAAE,WAAW;IACrB,yBAAyB;aACzB,gBAAgB,EAAE,oBAAoB;IACtC,6CAA6C;aAC7C,aAAa,EAAE,gBAAgB;IAC/B,2BAA2B;aAC3B,eAAe,EAAE,mBAAmB;IACpC,oCAAoC;aACpC,QAAQ,EAAE,gBAAgB;CAClB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE9E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC;AAED,4DAA4D;AAC5D,eAAO,MAAM,iBAAiB,EAAE,MAAmB,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAIxE"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Grading protocol over HTTP. Any backend in any language can implement it:
3
+ *
4
+ * POST {endpoint}/check body CheckRequest -> 200 CheckResponse
5
+ * POST {endpoint}/submit body SubmitRequest -> 200 SubmitResponse
6
+ * POST {endpoint}/hint body HintRequest -> 200 HintResponse
7
+ *
8
+ * `{endpoint}` identifies one attempt (e.g. `/api/attempts/123`); how it is authorised is up to the host
9
+ * (cookie, bearer token). Errors are `application/problem+json` (RFC 9457) with a `code` from ProblemCode.
10
+ */
11
+ export const PROTOCOL_VERSION = 1;
12
+ export const JSON_MEDIA_TYPE = 'application/json';
13
+ export const PROBLEM_MEDIA_TYPE = 'application/problem+json';
14
+ export const ProtocolPath = {
15
+ check: 'check',
16
+ submit: 'submit',
17
+ hint: 'hint',
18
+ };
19
+ export const ProblemCode = {
20
+ /** 400: body is not valid JSON or does not match the request schema. */
21
+ invalidRequest: 'invalid_request',
22
+ /** 401: the host could not identify the attempt. */
23
+ unauthorized: 'unauthorized',
24
+ /** 403: checking is not allowed under this policy (tests). */
25
+ checkNotAllowed: 'check_not_allowed',
26
+ /** 403: the practice policy's maxChecks is used up. */
27
+ checksExhausted: 'checks_exhausted',
28
+ /** 403: the policy offers no hints (tests, or a practice policy with `hints: false`). */
29
+ hintsNotAllowed: 'hints_not_allowed',
30
+ /** 403: every hint of that interaction or page is used. */
31
+ hintsExhausted: 'hints_exhausted',
32
+ /** 404: unknown attempt, page or element. */
33
+ notFound: 'not_found',
34
+ /** 405: wrong method. */
35
+ methodNotAllowed: 'method_not_allowed',
36
+ /** 409: the attempt is already submitted. */
37
+ attemptClosed: 'attempt_closed',
38
+ /** 413: body too large. */
39
+ payloadTooLarge: 'payload_too_large',
40
+ /** 500: unexpected server error. */
41
+ internal: 'internal_error',
42
+ };
43
+ /** Largest request body servers should accept, in bytes. */
44
+ export const MAX_REQUEST_BYTES = 256 * 1024;
45
+ export function isProblemDetails(value) {
46
+ if (typeof value !== 'object' || value === null)
47
+ return false;
48
+ const v = value;
49
+ return typeof v.title === 'string' && typeof v.status === 'number' && typeof v.code === 'string';
50
+ }
51
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,MAAM,CAAC,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AAE7D,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,wEAAwE;IACxE,cAAc,EAAE,iBAAiB;IACjC,oDAAoD;IACpD,YAAY,EAAE,cAAc;IAC5B,8DAA8D;IAC9D,eAAe,EAAE,mBAAmB;IACpC,uDAAuD;IACvD,eAAe,EAAE,kBAAkB;IACnC,yFAAyF;IACzF,eAAe,EAAE,mBAAmB;IACpC,2DAA2D;IAC3D,cAAc,EAAE,iBAAiB;IACjC,6CAA6C;IAC7C,QAAQ,EAAE,WAAW;IACrB,yBAAyB;IACzB,gBAAgB,EAAE,oBAAoB;IACtC,6CAA6C;IAC7C,aAAa,EAAE,gBAAgB;IAC/B,2BAA2B;IAC3B,eAAe,EAAE,mBAAmB;IACpC,oCAAoC;IACpC,QAAQ,EAAE,gBAAgB;CAClB,CAAC;AAYX,4DAA4D;AAC5D,MAAM,CAAC,MAAM,iBAAiB,GAAW,GAAG,GAAG,IAAI,CAAC;AAEpD,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,OAAO,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AACnG,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Grading results as students and hosts see them. Results never contain key data: no accepted answers, no correct
3
+ * option ids. Solutions travel separately and only when the attempt policy reveals them.
4
+ */
5
+ import type { SlotId } from './answers.js';
6
+ export type SlotVerdict = 'correct' | 'incorrect';
7
+ export type GroupVerdict = 'correct' | 'partial' | 'incorrect' | 'empty';
8
+ export interface GroupResult {
9
+ readonly id: string;
10
+ readonly verdict: GroupVerdict;
11
+ readonly score: number;
12
+ readonly max: number;
13
+ }
14
+ export interface Score {
15
+ readonly score: number;
16
+ readonly max: number;
17
+ }
18
+ export interface VerdictCounts {
19
+ readonly correct: number;
20
+ readonly partial: number;
21
+ readonly incorrect: number;
22
+ readonly empty: number;
23
+ /** Number of groups counted. */
24
+ readonly total: number;
25
+ }
26
+ export interface GradeResult extends Score {
27
+ /** True when every included group is correct; false when no group is included (empty key or unknown page). */
28
+ readonly correct: boolean;
29
+ /**
30
+ * Per-slot verdicts the student may see: answered slots only, selected flags only, and nothing for slots of
31
+ * multi-slot `all-correct` groups (those show only the group verdict).
32
+ */
33
+ readonly slots: Readonly<Record<SlotId, SlotVerdict>>;
34
+ readonly groups: readonly GroupResult[];
35
+ /** Score per view page id. */
36
+ readonly pages: Readonly<Record<string, Score>>;
37
+ /** Counts over groups. */
38
+ readonly counts: VerdictCounts;
39
+ }
40
+ /** Correct answers by slot, shown when the policy reveals them. `''` entries are omitted. */
41
+ export type Solution = Readonly<Record<SlotId, string>>;
42
+ /** Rounds a score for display: at most 2 decimals, no trailing zeros. */
43
+ export declare function roundScore(value: number): number;
44
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAEzE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAChD,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;CAChC;AAED,6FAA6F;AAC7F,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExD,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD"}
package/dist/result.js ADDED
@@ -0,0 +1,5 @@
1
+ /** Rounds a score for display: at most 2 decimals, no trailing zeros. */
2
+ export function roundScore(value) {
3
+ return Math.round(value * 100) / 100;
4
+ }
5
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAiDA,yEAAyE;AACzE,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACvC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Scoring groups. Every graded component forms one group by default (id = the component's opaque id), or one per
3
+ * part when its definition grades it in parts (`ComponentDefinition.groups`, a crossword's words), where a slot may
4
+ * sit in several groups.
5
+ *
6
+ * Rules (n = slots in the group, c = correct slots, P = points):
7
+ * - `all-correct`: max P; score P when c = n, else 0. Feedback shows only the group verdict, never which slot is wrong.
8
+ * - `per-slot`: max P x n; score P x c.
9
+ * - `proportional`: max P; score P x c / n (exact, not rounded).
10
+ *
11
+ * Selection slots (flags, e.g. options of a multiple-answer choice): an unselected flag gets no verdict, and a group
12
+ * whose flags are all unselected scores 0 with verdict `empty`.
13
+ */
14
+ export type ScoringRule = 'all-correct' | 'per-slot' | 'proportional';
15
+ export declare const SCORING_RULES: readonly ScoringRule[];
16
+ export interface ScoringGroup {
17
+ readonly id: string;
18
+ readonly rule: ScoringRule;
19
+ readonly points: number;
20
+ /** Slot ids in reading order. */
21
+ readonly slots: readonly string[];
22
+ /** View page id the group belongs to. */
23
+ readonly page: string;
24
+ }
25
+ /** Group maximum for a rule. */
26
+ export declare function groupMax(rule: ScoringRule, points: number, slotCount: number): number;
27
+ //# sourceMappingURL=scoring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../src/scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,UAAU,GAAG,cAAc,CAAC;AAEtE,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAAgD,CAAC;AAEjG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAErF"}
@@ -0,0 +1,6 @@
1
+ export const SCORING_RULES = ['all-correct', 'per-slot', 'proportional'];
2
+ /** Group maximum for a rule. */
3
+ export function groupMax(rule, points, slotCount) {
4
+ return rule === 'per-slot' ? points * slotCount : points;
5
+ }
6
+ //# sourceMappingURL=scoring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.js","sourceRoot":"","sources":["../src/scoring.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;AAYjG,gCAAgC;AAChC,MAAM,UAAU,QAAQ,CAAC,IAAiB,EAAE,MAAc,EAAE,SAAiB;IAC3E,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Slot kinds: the open registry of grading semantics. The engine never switches on a kind; it asks the registered
3
+ * SlotKind. Built-ins (engine): `text`, `number`, `choice`, `flag`, and `open` (stored for a teacher, never graded).
4
+ * Hosts and third parties may register more.
5
+ */
6
+ import type { JsonObject } from './json.js';
7
+ export interface GradeContext {
8
+ /** Content language of the slot (BCP 47), for locale-aware comparisons. */
9
+ readonly lang: string;
10
+ }
11
+ export interface SlotKind<TKey extends JsonObject = JsonObject> {
12
+ readonly kind: string;
13
+ /** Selection slots use flag semantics (see scoring.ts). */
14
+ readonly selection: boolean;
15
+ /**
16
+ * False for a kind that is stored but never graded (the built-in `open`): its slots belong to no scoring group, get
17
+ * no verdict and add nothing to the maximum, and only ungraded types (`graded: false`) produce them. Default true:
18
+ * graded types produce only graded kinds.
19
+ */
20
+ readonly graded?: boolean;
21
+ /** Validates a stored key (compile output, or a key loaded from storage). */
22
+ isKey(key: JsonObject): key is TKey;
23
+ /** `answer` is never empty here: the engine handles unanswered slots before calling. */
24
+ isCorrect(key: TKey, answer: string, context: GradeContext): boolean;
25
+ /** The answer that shows the solution. `''` = leave the slot empty (an unselected flag). */
26
+ solution(key: TKey): string;
27
+ }
28
+ /**
29
+ * How typed text is compared. Resolved at compile time and stored inside each text key, so stored keys grade the same
30
+ * forever, whatever the defaults are later.
31
+ */
32
+ export interface NormalisationProfile {
33
+ /** Unicode normalisation applied first. */
34
+ readonly form: 'NFC' | 'NFKC';
35
+ /** `collapse`: trim and turn every whitespace run into one space. */
36
+ readonly space: 'strict' | 'collapse';
37
+ /** `insensitive`: locale-aware lower-casing with the content language (Turkish dotless i works). */
38
+ readonly case: 'sensitive' | 'insensitive';
39
+ /** `fold`: ignore diacritics (ą = a, ł = l, ø = o, ß = ss). `strict` keeps them: żółw != zolw. */
40
+ readonly marks: 'strict' | 'fold';
41
+ /** `ignore-edge`: drop punctuation at the start and end ("ssak." = "ssak"). */
42
+ readonly punctuation: 'strict' | 'ignore-edge';
43
+ /** `fold`: typographic quotes, apostrophes and dashes compare equal to ASCII ones. */
44
+ readonly quotes: 'strict' | 'fold';
45
+ }
46
+ export declare const DEFAULT_PROFILE: NormalisationProfile;
47
+ //# sourceMappingURL=slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../src/slots.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM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