@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.
- package/CHANGELOG.md +60 -0
- package/LICENSE +202 -0
- package/README.md +38 -0
- package/dist/answers.d.ts +29 -0
- package/dist/answers.d.ts.map +1 -0
- package/dist/answers.js +40 -0
- package/dist/answers.js.map +1 -0
- package/dist/ast.d.ts +25 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +27 -0
- package/dist/ast.js.map +1 -0
- package/dist/authoring.d.ts +451 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +2 -0
- package/dist/authoring.js.map +1 -0
- package/dist/checker.d.ts +78 -0
- package/dist/checker.d.ts.map +1 -0
- package/dist/checker.js +10 -0
- package/dist/checker.js.map +1 -0
- package/dist/compiled.d.ts +94 -0
- package/dist/compiled.d.ts.map +1 -0
- package/dist/compiled.js +16 -0
- package/dist/compiled.js.map +1 -0
- package/dist/content.d.ts +72 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +128 -0
- package/dist/content.js.map +1 -0
- package/dist/declarations.d.ts +52 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +358 -0
- package/dist/declarations.js.map +1 -0
- package/dist/definition.d.ts +106 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +2 -0
- package/dist/definition.js.map +1 -0
- package/dist/engine.d.ts +95 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -0
- package/dist/format.d.ts +29 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +55 -0
- package/dist/format.js.map +1 -0
- package/dist/help.d.ts +38 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +22 -0
- package/dist/help.js.map +1 -0
- package/dist/i18n/check.d.ts +11 -0
- package/dist/i18n/check.d.ts.map +1 -0
- package/dist/i18n/check.js +64 -0
- package/dist/i18n/check.js.map +1 -0
- package/dist/i18n/format.d.ts +40 -0
- package/dist/i18n/format.d.ts.map +1 -0
- package/dist/i18n/format.js +280 -0
- package/dist/i18n/format.js.map +1 -0
- package/dist/i18n/i18n.d.ts +14 -0
- package/dist/i18n/i18n.d.ts.map +1 -0
- package/dist/i18n/i18n.js +82 -0
- package/dist/i18n/i18n.js.map +1 -0
- package/dist/i18n/types.d.ts +31 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +7 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/issues.d.ts +98 -0
- package/dist/issues.d.ts.map +1 -0
- package/dist/issues.js +74 -0
- package/dist/issues.js.map +1 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +2 -0
- package/dist/json.js.map +1 -0
- package/dist/manifest.d.ts +135 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +63 -0
- package/dist/manifest.js.map +1 -0
- package/dist/player.d.ts +129 -0
- package/dist/player.d.ts.map +1 -0
- package/dist/player.js +18 -0
- package/dist/player.js.map +1 -0
- package/dist/policy.d.ts +53 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +55 -0
- package/dist/policy.js.map +1 -0
- package/dist/protocol.d.ts +54 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +51 -0
- package/dist/protocol.js.map +1 -0
- package/dist/result.d.ts +44 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +5 -0
- package/dist/result.js.map +1 -0
- package/dist/scoring.d.ts +27 -0
- package/dist/scoring.d.ts.map +1 -0
- package/dist/scoring.js +6 -0
- package/dist/scoring.js.map +1 -0
- package/dist/slots.d.ts +47 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +9 -0
- package/dist/slots.js.map +1 -0
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +22 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/style.d.ts +51 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +36 -0
- package/dist/style.js.map +1 -0
- package/package.json +52 -4
- package/src/answers.ts +52 -0
- package/src/ast.ts +49 -0
- package/src/authoring.ts +475 -0
- package/src/checker.ts +91 -0
- package/src/compiled.ts +115 -0
- package/src/content.ts +156 -0
- package/src/declarations.ts +427 -0
- package/src/definition.ts +104 -0
- package/src/engine.ts +98 -0
- package/src/format.ts +67 -0
- package/src/help.ts +41 -0
- package/src/i18n/check.ts +67 -0
- package/src/i18n/format.ts +318 -0
- package/src/i18n/i18n.ts +92 -0
- package/src/i18n/types.ts +35 -0
- package/src/index.ts +201 -0
- package/src/issues.ts +107 -0
- package/src/json.ts +6 -0
- package/src/manifest.ts +193 -0
- package/src/player.ts +145 -0
- package/src/policy.ts +117 -0
- package/src/protocol.ts +65 -0
- package/src/result.ts +53 -0
- package/src/scoring.ts +31 -0
- package/src/slots.ts +57 -0
- package/src/snapshot.ts +40 -0
- package/src/style.ts +89 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18n contracts. Two axes are kept apart everywhere:
|
|
3
|
+
* - UI locale: chrome, labels, issue messages, announcements (the reader's choice);
|
|
4
|
+
* - content language: the `lang` of the exercise text, used for grading and rendering (the author's choice).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type MessageParams = Readonly<Record<string, string | number>>;
|
|
8
|
+
|
|
9
|
+
/** Messages of one namespace in one locale. Values are ICU MessageFormat 1 strings. */
|
|
10
|
+
export interface MessageCatalog {
|
|
11
|
+
/** e.g. `astl.player`, `astl.gap`. */
|
|
12
|
+
readonly namespace: string;
|
|
13
|
+
/** BCP 47, e.g. `pl`. */
|
|
14
|
+
readonly locale: string;
|
|
15
|
+
readonly messages: Readonly<Record<string, string>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Port for message formatting. The default is the ICU MessageFormat 1 subset in `format.ts`. */
|
|
19
|
+
export interface MessageFormatter {
|
|
20
|
+
format(message: string, params: MessageParams, locale: string): string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Translate = (key: string, params?: MessageParams) => string;
|
|
24
|
+
|
|
25
|
+
export interface I18n {
|
|
26
|
+
readonly fallbackLocale: string;
|
|
27
|
+
/** Locales that have at least one catalog (for a namespace, if given). */
|
|
28
|
+
locales(namespace?: string): readonly string[];
|
|
29
|
+
/** Formats `namespace:key` in the best matching locale, then the fallback locale, else returns the key. */
|
|
30
|
+
t(locale: string, namespace: string, key: string, params?: MessageParams): string;
|
|
31
|
+
/** A translate function bound to one locale and namespace. */
|
|
32
|
+
translator(locale: string, namespace: string): Translate;
|
|
33
|
+
/** A new instance with more catalogs. Later catalogs override earlier keys of the same namespace and locale. */
|
|
34
|
+
with(catalogs: readonly MessageCatalog[]): I18n;
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
export type { Answers, SlotId } from './answers.js';
|
|
2
|
+
export {
|
|
3
|
+
FLAG_SELECTED,
|
|
4
|
+
fitsAnswer,
|
|
5
|
+
isAnswers,
|
|
6
|
+
MAX_ANSWER_COUNT,
|
|
7
|
+
MAX_ANSWER_LENGTH,
|
|
8
|
+
MAX_OPEN_ANSWER_LENGTH,
|
|
9
|
+
maxAnswerLength,
|
|
10
|
+
OPEN_SLOT_KIND,
|
|
11
|
+
} from './answers.js';
|
|
12
|
+
export type { ElementNode, Node, TextNode } from './ast.js';
|
|
13
|
+
export { childElements, element, isElement, text, textContent } from './ast.js';
|
|
14
|
+
export type {
|
|
15
|
+
EditorAdapter,
|
|
16
|
+
EditorBlockPlace,
|
|
17
|
+
EditorDescriptor,
|
|
18
|
+
EditorFormat,
|
|
19
|
+
EditorFormatState,
|
|
20
|
+
EditorInsertOptions,
|
|
21
|
+
EditorLayoutEdit,
|
|
22
|
+
EditorLayoutShape,
|
|
23
|
+
EditorLayoutState,
|
|
24
|
+
EditorSelection,
|
|
25
|
+
EditorStyleChanges,
|
|
26
|
+
EditorStyleRule,
|
|
27
|
+
EditorStyleState,
|
|
28
|
+
EditorStyles,
|
|
29
|
+
EditorStyleTarget,
|
|
30
|
+
EditorStyleTargetKind,
|
|
31
|
+
EditorTemplate,
|
|
32
|
+
EditorWrap,
|
|
33
|
+
InspectorField,
|
|
34
|
+
} from './authoring.js';
|
|
35
|
+
export type {
|
|
36
|
+
Checker,
|
|
37
|
+
CheckRequest,
|
|
38
|
+
CheckResponse,
|
|
39
|
+
HintRequest,
|
|
40
|
+
HintResponse,
|
|
41
|
+
ResultHelp,
|
|
42
|
+
SubmitRequest,
|
|
43
|
+
SubmitResponse,
|
|
44
|
+
} from './checker.js';
|
|
45
|
+
export { CheckerError } from './checker.js';
|
|
46
|
+
export type {
|
|
47
|
+
AnswerKey,
|
|
48
|
+
Compilation,
|
|
49
|
+
KeyHelp,
|
|
50
|
+
KeyHint,
|
|
51
|
+
KeySlot,
|
|
52
|
+
Metadata,
|
|
53
|
+
PageMetadata,
|
|
54
|
+
} from './compiled.js';
|
|
55
|
+
export { isAnswerKey, KEY_FORMAT_VERSION } from './compiled.js';
|
|
56
|
+
export {
|
|
57
|
+
BLOCK_TAGS,
|
|
58
|
+
CAPTION_TAG,
|
|
59
|
+
CLASS_ATTRIBUTE,
|
|
60
|
+
COLUMN_TAG,
|
|
61
|
+
COLUMNS_TAG,
|
|
62
|
+
CONTENT_ATTRIBUTES,
|
|
63
|
+
DEFAULT_DOC_KIND,
|
|
64
|
+
DOC_ATTRIBUTES,
|
|
65
|
+
DOC_KINDS,
|
|
66
|
+
type DocKind,
|
|
67
|
+
FIGURE_TAG,
|
|
68
|
+
INERT_STYLE,
|
|
69
|
+
INLINE_TAGS,
|
|
70
|
+
inertStyles,
|
|
71
|
+
isSafeUrl,
|
|
72
|
+
MAX_ATTRIBUTES_PER_ELEMENT,
|
|
73
|
+
MAX_COLUMNS,
|
|
74
|
+
MAX_NESTING_DEPTH,
|
|
75
|
+
MIN_COLUMNS,
|
|
76
|
+
PAGE_ATTRIBUTES,
|
|
77
|
+
REMOVED_WITH_CONTENT,
|
|
78
|
+
STYLE_TAG,
|
|
79
|
+
strictUrlPolicy,
|
|
80
|
+
TAG_ATTRIBUTES,
|
|
81
|
+
URL_ATTRIBUTES,
|
|
82
|
+
} from './content.js';
|
|
83
|
+
export type {
|
|
84
|
+
CompileContext,
|
|
85
|
+
ComponentDefinition,
|
|
86
|
+
GroupSpec,
|
|
87
|
+
SlotSpec,
|
|
88
|
+
ValidateContext,
|
|
89
|
+
} from './definition.js';
|
|
90
|
+
export type {
|
|
91
|
+
CompileOptions,
|
|
92
|
+
CompileResult,
|
|
93
|
+
Engine,
|
|
94
|
+
EngineOptions,
|
|
95
|
+
GradeOptions,
|
|
96
|
+
GroundColors,
|
|
97
|
+
UrlPolicy,
|
|
98
|
+
ValidationReport,
|
|
99
|
+
} from './engine.js';
|
|
100
|
+
export type { Direction } from './format.js';
|
|
101
|
+
export {
|
|
102
|
+
BUILT_IN_PREFIX,
|
|
103
|
+
DOC_TAG,
|
|
104
|
+
directionOf,
|
|
105
|
+
ELEMENT_TAG_PATTERN,
|
|
106
|
+
FORMAT_VERSION,
|
|
107
|
+
isOpaqueId,
|
|
108
|
+
isSourceId,
|
|
109
|
+
LANGUAGE_TAG_PATTERN,
|
|
110
|
+
MAX_SOURCE_LENGTH,
|
|
111
|
+
OPAQUE_ID_PATTERN,
|
|
112
|
+
PAGE_TAG,
|
|
113
|
+
SOURCE_ID_PATTERN,
|
|
114
|
+
SUPPORTED_FORMATS,
|
|
115
|
+
} from './format.js';
|
|
116
|
+
export type { ElementHelp, Feedback, FeedbackVariant } from './help.js';
|
|
117
|
+
export {
|
|
118
|
+
EXPLANATION_TAG,
|
|
119
|
+
FEEDBACK_TAG,
|
|
120
|
+
FEEDBACK_VARIANTS,
|
|
121
|
+
HELP_ATTRIBUTES,
|
|
122
|
+
HELP_TAGS,
|
|
123
|
+
HINT_TAG,
|
|
124
|
+
} from './help.js';
|
|
125
|
+
export type { CatalogProblem } from './i18n/check.js';
|
|
126
|
+
export { checkCatalog, compareCatalogs } from './i18n/check.js';
|
|
127
|
+
export type { MessagePart } from './i18n/format.js';
|
|
128
|
+
export {
|
|
129
|
+
icuFormatter,
|
|
130
|
+
MessageSyntaxError,
|
|
131
|
+
messageParams,
|
|
132
|
+
parseMessage,
|
|
133
|
+
pluralCategories,
|
|
134
|
+
} from './i18n/format.js';
|
|
135
|
+
export type { CreateI18nOptions } from './i18n/i18n.js';
|
|
136
|
+
export { createI18n, negotiateLocale } from './i18n/i18n.js';
|
|
137
|
+
export type { I18n, MessageCatalog, MessageFormatter, MessageParams, Translate } from './i18n/types.js';
|
|
138
|
+
export type { EngineIssueCode, Issue, IssueLocation, IssueParams, Severity } from './issues.js';
|
|
139
|
+
export { ENGINE_NAMESPACE, EngineIssue, hasErrors } from './issues.js';
|
|
140
|
+
export type { JsonArray, JsonObject, JsonValue } from './json.js';
|
|
141
|
+
export type {
|
|
142
|
+
AttributeSpec,
|
|
143
|
+
AttributeType,
|
|
144
|
+
ChildSpec,
|
|
145
|
+
ComponentManifest,
|
|
146
|
+
ScoringSpec,
|
|
147
|
+
VariantSpec,
|
|
148
|
+
Visibility,
|
|
149
|
+
} from './manifest.js';
|
|
150
|
+
export {
|
|
151
|
+
allAttributes,
|
|
152
|
+
COMMON_ATTRIBUTES,
|
|
153
|
+
childTagConflict,
|
|
154
|
+
SCORING_ATTRIBUTES,
|
|
155
|
+
sameChildSpec,
|
|
156
|
+
variantAttribute,
|
|
157
|
+
} from './manifest.js';
|
|
158
|
+
export type {
|
|
159
|
+
AttemptState,
|
|
160
|
+
ChangeDetail,
|
|
161
|
+
ElementContext,
|
|
162
|
+
ElementFeedback,
|
|
163
|
+
ErrorDetail,
|
|
164
|
+
PageDetail,
|
|
165
|
+
PlayerElementApi,
|
|
166
|
+
ReadyDetail,
|
|
167
|
+
SourceCompiler,
|
|
168
|
+
StateDetail,
|
|
169
|
+
Units,
|
|
170
|
+
} from './player.js';
|
|
171
|
+
export { PlayerEvent } from './player.js';
|
|
172
|
+
export type { AttemptMode, AttemptPolicy, CheckScope, HelpMoment, HelpPolicy, Reveal } from './policy.js';
|
|
173
|
+
export { helpPolicy, isAttemptPolicy, PRACTICE_POLICY, TEST_POLICY } from './policy.js';
|
|
174
|
+
export type { ProblemCodeValue, ProblemDetails } from './protocol.js';
|
|
175
|
+
export {
|
|
176
|
+
isProblemDetails,
|
|
177
|
+
JSON_MEDIA_TYPE,
|
|
178
|
+
MAX_REQUEST_BYTES,
|
|
179
|
+
PROBLEM_MEDIA_TYPE,
|
|
180
|
+
PROTOCOL_VERSION,
|
|
181
|
+
ProblemCode,
|
|
182
|
+
ProtocolPath,
|
|
183
|
+
} from './protocol.js';
|
|
184
|
+
export type {
|
|
185
|
+
GradeResult,
|
|
186
|
+
GroupResult,
|
|
187
|
+
GroupVerdict,
|
|
188
|
+
Score,
|
|
189
|
+
SlotVerdict,
|
|
190
|
+
Solution,
|
|
191
|
+
VerdictCounts,
|
|
192
|
+
} from './result.js';
|
|
193
|
+
export { roundScore } from './result.js';
|
|
194
|
+
export type { ScoringGroup, ScoringRule } from './scoring.js';
|
|
195
|
+
export { groupMax, SCORING_RULES } from './scoring.js';
|
|
196
|
+
export type { GradeContext, NormalisationProfile, SlotKind } from './slots.js';
|
|
197
|
+
export { DEFAULT_PROFILE } from './slots.js';
|
|
198
|
+
export type { Snapshot } from './snapshot.js';
|
|
199
|
+
export { isSnapshot, SNAPSHOT_FORMAT } from './snapshot.js';
|
|
200
|
+
export type { Declarations, StyleScope, StyleTemplate, TokenOverrides } from './style.js';
|
|
201
|
+
export { isStyleTemplate, STYLE_TEMPLATE_ATTRIBUTE, STYLE_TEMPLATE_NAME } from './style.js';
|
package/src/issues.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation issues. Codes + params, never English sentences: hosts render them with message catalogs
|
|
3
|
+
* (`<namespace>` of the reporting component, or `astl.engine` for document-level codes).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type Severity = 'error' | 'warning';
|
|
7
|
+
|
|
8
|
+
export type IssueParams = Readonly<Record<string, string | number>>;
|
|
9
|
+
|
|
10
|
+
export interface IssueLocation {
|
|
11
|
+
/** Source id of the page, or null for the implicit page / document level. */
|
|
12
|
+
readonly page: string | null;
|
|
13
|
+
/** Source id of the closest element that has one (the component), or null. */
|
|
14
|
+
readonly element: string | null;
|
|
15
|
+
/** Tag of the element the issue is about, or null for the document. */
|
|
16
|
+
readonly tag: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Readable path from the root, e.g. `astl-doc > astl-page#p1 > p[2] > astl-gap#g1`. Empty for issues raised before
|
|
19
|
+
* the document could be parsed (SOURCE_TOO_LARGE, DOC_ROOT_INVALID), whose `tag` is null.
|
|
20
|
+
*/
|
|
21
|
+
readonly path: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Issue {
|
|
25
|
+
/** Stable UPPER_SNAKE code. Component codes start with the type, e.g. `CHOICE_CORRECT_MISSING`. */
|
|
26
|
+
readonly code: string;
|
|
27
|
+
/** Errors block compiling; warnings do not. */
|
|
28
|
+
readonly severity: Severity;
|
|
29
|
+
/** i18n namespace of the message (`astl.engine` or the manifest's `messages`). */
|
|
30
|
+
readonly namespace: string;
|
|
31
|
+
readonly params: IssueParams;
|
|
32
|
+
readonly at: IssueLocation;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** i18n namespace of document-level issues reported by the engine. */
|
|
36
|
+
export const ENGINE_NAMESPACE = 'astl.engine';
|
|
37
|
+
|
|
38
|
+
/** Document-level issue codes. Component codes are listed in each manifest's `issues`. */
|
|
39
|
+
export const EngineIssue = {
|
|
40
|
+
SOURCE_TOO_LARGE: 'SOURCE_TOO_LARGE',
|
|
41
|
+
SOURCE_TOO_DEEP: 'SOURCE_TOO_DEEP',
|
|
42
|
+
SOURCE_TOO_COMPLEX: 'SOURCE_TOO_COMPLEX',
|
|
43
|
+
DOC_ROOT_INVALID: 'DOC_ROOT_INVALID',
|
|
44
|
+
DOC_FORMAT_UNSUPPORTED: 'DOC_FORMAT_UNSUPPORTED',
|
|
45
|
+
DOC_LANG_MISSING: 'DOC_LANG_MISSING',
|
|
46
|
+
DOC_LANG_INVALID: 'DOC_LANG_INVALID',
|
|
47
|
+
DOC_EMPTY: 'DOC_EMPTY',
|
|
48
|
+
DOC_MIXED_PAGES: 'DOC_MIXED_PAGES',
|
|
49
|
+
NO_COMPONENTS: 'NO_COMPONENTS',
|
|
50
|
+
PAGE_EMPTY: 'PAGE_EMPTY',
|
|
51
|
+
PAGE_NESTED: 'PAGE_NESTED',
|
|
52
|
+
ID_MISSING: 'ID_MISSING',
|
|
53
|
+
ID_INVALID: 'ID_INVALID',
|
|
54
|
+
ID_DUPLICATE: 'ID_DUPLICATE',
|
|
55
|
+
ELEMENT_UNKNOWN: 'ELEMENT_UNKNOWN',
|
|
56
|
+
ELEMENT_REMOVED: 'ELEMENT_REMOVED',
|
|
57
|
+
ATTRIBUTE_REMOVED: 'ATTRIBUTE_REMOVED',
|
|
58
|
+
ATTRIBUTE_INVALID: 'ATTRIBUTE_INVALID',
|
|
59
|
+
ATTRIBUTE_REQUIRED: 'ATTRIBUTE_REQUIRED',
|
|
60
|
+
CHILD_UNEXPECTED: 'CHILD_UNEXPECTED',
|
|
61
|
+
/** A child tag of a registered component outside that component (a word to select outside its passage). */
|
|
62
|
+
CHILD_OUTSIDE: 'CHILD_OUTSIDE',
|
|
63
|
+
CHILD_COUNT: 'CHILD_COUNT',
|
|
64
|
+
PLACEMENT_INVALID: 'PLACEMENT_INVALID',
|
|
65
|
+
COMPONENT_NESTED: 'COMPONENT_NESTED',
|
|
66
|
+
URL_BLOCKED: 'URL_BLOCKED',
|
|
67
|
+
IMG_ALT_MISSING: 'IMG_ALT_MISSING',
|
|
68
|
+
FIGURE_INVALID: 'FIGURE_INVALID',
|
|
69
|
+
SCORING_MODE_INVALID: 'SCORING_MODE_INVALID',
|
|
70
|
+
POINTS_INVALID: 'POINTS_INVALID',
|
|
71
|
+
VERSION_UNSUPPORTED: 'VERSION_UNSUPPORTED',
|
|
72
|
+
STYLE_TEMPLATE_UNKNOWN: 'STYLE_TEMPLATE_UNKNOWN',
|
|
73
|
+
/** A declaration the `style` allow-list refuses (`declarations.ts`): it goes, the rest of the style stays. */
|
|
74
|
+
STYLE_REMOVED: 'STYLE_REMOVED',
|
|
75
|
+
/** A `style` over MAX_STYLE_LENGTH: it goes whole. */
|
|
76
|
+
STYLE_TOO_LONG: 'STYLE_TOO_LONG',
|
|
77
|
+
/** A class no `<astl-style>` defines. */
|
|
78
|
+
STYLE_UNKNOWN: 'STYLE_UNKNOWN',
|
|
79
|
+
/** An `<astl-style>` that defines nothing usable: a bad or reserved `name`, an unknown `for`, or both or neither. */
|
|
80
|
+
STYLE_NAME_INVALID: 'STYLE_NAME_INVALID',
|
|
81
|
+
/** More `<astl-style>` rules than MAX_STYLE_RULES. */
|
|
82
|
+
STYLE_RULES_TOO_MANY: 'STYLE_RULES_TOO_MANY',
|
|
83
|
+
/** Inlining the rules would write more than MAX_INLINED_STYLES into the view. */
|
|
84
|
+
STYLE_TOO_LARGE: 'STYLE_TOO_LARGE',
|
|
85
|
+
/** Text and background of an element too close to read: the author decides. */
|
|
86
|
+
STYLE_LOW_CONTRAST: 'STYLE_LOW_CONTRAST',
|
|
87
|
+
/** Help (`astl-hint`, `astl-explanation`, `astl-feedback`) with nothing graded around it or on its page: it goes. */
|
|
88
|
+
HELP_UNGRADED: 'HELP_UNGRADED',
|
|
89
|
+
/** Help without content: it goes. */
|
|
90
|
+
HELP_EMPTY: 'HELP_EMPTY',
|
|
91
|
+
/** A hint `cost` that is not a number from 0 to 1. */
|
|
92
|
+
HINT_COST_INVALID: 'HINT_COST_INVALID',
|
|
93
|
+
/** A feedback `when` that is not one of `correct`, `incorrect`, `partial`, `omitted`. */
|
|
94
|
+
FEEDBACK_WHEN_INVALID: 'FEEDBACK_WHEN_INVALID',
|
|
95
|
+
/** Two feedback texts for one `when` in one interaction or page. */
|
|
96
|
+
FEEDBACK_DUPLICATE: 'FEEDBACK_DUPLICATE',
|
|
97
|
+
/** Two explanations in one interaction or page. */
|
|
98
|
+
EXPLANATION_DUPLICATE: 'EXPLANATION_DUPLICATE',
|
|
99
|
+
/** A layout of the wrong shape: `<astl-columns>` directly on a page, holding 2 to 4 `<astl-column>`, not nested. */
|
|
100
|
+
COLUMNS_INVALID: 'COLUMNS_INVALID',
|
|
101
|
+
} as const;
|
|
102
|
+
|
|
103
|
+
export type EngineIssueCode = (typeof EngineIssue)[keyof typeof EngineIssue];
|
|
104
|
+
|
|
105
|
+
export function hasErrors(issues: readonly Issue[]): boolean {
|
|
106
|
+
return issues.some((i) => i.severity === 'error');
|
|
107
|
+
}
|
package/src/json.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A JSON value. Every contract object that crosses a process boundary is made of these. */
|
|
2
|
+
export type JsonValue = string | number | boolean | null | JsonArray | JsonObject;
|
|
3
|
+
export type JsonArray = readonly JsonValue[];
|
|
4
|
+
export interface JsonObject {
|
|
5
|
+
readonly [key: string]: JsonValue;
|
|
6
|
+
}
|
package/src/manifest.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ComponentManifest: the ONLY per-type schema. Plain data, shared by the engine (sanitiser allow-list, validation,
|
|
3
|
+
* view allow-list), the player (attribute parsing), the editor (node attributes, default inspector), docs, JSON Schema
|
|
4
|
+
* and agent tool schemas. Nothing else may restate a component's attributes.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScoringRule } from './scoring.js';
|
|
7
|
+
import { STYLE_TEMPLATE_ATTRIBUTE } from './style.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* - `public`: kept in the view as written.
|
|
11
|
+
* - `private`: kept only in the answer key / never leaves the server.
|
|
12
|
+
* - `derived`: computed by the definition's `toView`; authors cannot write it.
|
|
13
|
+
*/
|
|
14
|
+
export type Visibility = 'public' | 'private' | 'derived';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* - `id`: a source id local to the component (e.g. an option id); replaced by an opaque id in the view.
|
|
18
|
+
* - `boolean`: HTML boolean attribute (present = true; `"false"` is invalid).
|
|
19
|
+
* - `url`: checked by the engine's UrlPolicy; a blocked URL is removed with a URL_BLOCKED warning.
|
|
20
|
+
*/
|
|
21
|
+
export type AttributeType = 'string' | 'boolean' | 'integer' | 'number' | 'enum' | 'id' | 'url';
|
|
22
|
+
|
|
23
|
+
export interface AttributeSpec {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly type: AttributeType;
|
|
26
|
+
readonly visibility: Visibility;
|
|
27
|
+
readonly required?: boolean;
|
|
28
|
+
/** Allowed values for `enum`. */
|
|
29
|
+
readonly values?: readonly string[];
|
|
30
|
+
/** Inclusive bounds for `integer` and `number`. */
|
|
31
|
+
readonly min?: number;
|
|
32
|
+
readonly max?: number;
|
|
33
|
+
/** Value used when the attribute is absent. Documented and shown by the editor. */
|
|
34
|
+
readonly default?: string | number | boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A child element type a component accepts, e.g. `<astl-option>` inside `<astl-choice>`.
|
|
39
|
+
* - `content: 'text'`: plain text only (e.g. an accepted alternative answer).
|
|
40
|
+
* - `content: 'inline'`: rich inline content (emphasis, `lang` spans, math).
|
|
41
|
+
*/
|
|
42
|
+
export interface ChildSpec {
|
|
43
|
+
readonly tag: string;
|
|
44
|
+
readonly visibility: 'public' | 'private';
|
|
45
|
+
readonly content: 'text' | 'inline';
|
|
46
|
+
readonly min: number;
|
|
47
|
+
/** null = unbounded. */
|
|
48
|
+
readonly max: number | null;
|
|
49
|
+
readonly attributes: readonly AttributeSpec[];
|
|
50
|
+
/**
|
|
51
|
+
* Only in a type with rich content (`content: 'flow'`). Absent: the child sits in that content's text (a word to
|
|
52
|
+
* select). `'lead'`: it stands before the content, as the element's first child, never in its text (a prompt).
|
|
53
|
+
*/
|
|
54
|
+
readonly place?: 'lead';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Scoring modes an author can pick with the `scoring` attribute, each mapped to one engine rule.
|
|
59
|
+
* Mode names speak the author's language (`all`, `per-option`); rules are the three engine rules.
|
|
60
|
+
*/
|
|
61
|
+
export interface ScoringSpec {
|
|
62
|
+
readonly default: string;
|
|
63
|
+
readonly modes: Readonly<Record<string, ScoringRule>>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Presentation variants, picked by authors with the public `variant` attribute: how the element looks and behaves for
|
|
68
|
+
* the student (a gap that grows while typing, a select with a search box), never what it grades or which answers
|
|
69
|
+
* exist, so every variant of a source grades the same. The engine validates the value (an enum of `values`), elements
|
|
70
|
+
* render it, the authoring kit offers it (labels: `editor.value.variant.<value>` in the manifest's namespace).
|
|
71
|
+
* Adding a variant is not a breaking change; removing one or changing the default is (bump `version`).
|
|
72
|
+
*/
|
|
73
|
+
export interface VariantSpec {
|
|
74
|
+
/** Used when the attribute is absent or unknown to an older player. */
|
|
75
|
+
readonly default: string;
|
|
76
|
+
/** Kebab-case names, `default` included. */
|
|
77
|
+
readonly values: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ComponentManifest {
|
|
81
|
+
/** Custom element name. Built-ins use the `astl-` prefix; third parties use their own. */
|
|
82
|
+
readonly tag: string;
|
|
83
|
+
/** Element format version, written as `v="n"` in views. Bump on incompatible changes and add a migration. */
|
|
84
|
+
readonly version: number;
|
|
85
|
+
/** `inline` sits inside text (a gap); `block` stands between paragraphs (a multiple choice). */
|
|
86
|
+
readonly display: 'inline' | 'block';
|
|
87
|
+
/**
|
|
88
|
+
* Whether the type is scored. Graded types form one scoring group of graded slots. Ungraded types have no scoring
|
|
89
|
+
* and add nothing to the maximum: they produce no slots (flash cards, media), or only open slots (a long answer),
|
|
90
|
+
* whose answers are stored with the attempt for a teacher.
|
|
91
|
+
*/
|
|
92
|
+
readonly graded: boolean;
|
|
93
|
+
/** Type-specific attributes. The common ones (`id`, `v`, `scoring`, `points`) come from `COMMON_ATTRIBUTES`. */
|
|
94
|
+
readonly attributes: readonly AttributeSpec[];
|
|
95
|
+
/**
|
|
96
|
+
* Absent: the element holds its declared children only. `'flow'` (blocks only): it wraps rich content as a page
|
|
97
|
+
* holds it (paragraphs, headings, lists, quotes, figures, formatting, pictures; no components), and its declared
|
|
98
|
+
* children are inline children that sit in that content's text where an inline component may sit (a word to
|
|
99
|
+
* select in a passage), except those with `place: 'lead'`, which come first, before the content (a prompt);
|
|
100
|
+
* `min` and `max` count them wherever they are.
|
|
101
|
+
*/
|
|
102
|
+
readonly content?: 'flow';
|
|
103
|
+
readonly children: readonly ChildSpec[];
|
|
104
|
+
/** null for ungraded types. */
|
|
105
|
+
readonly scoring: ScoringSpec | null;
|
|
106
|
+
/** null for types with a single presentation. */
|
|
107
|
+
readonly variants: VariantSpec | null;
|
|
108
|
+
/**
|
|
109
|
+
* Slot kinds the definition produces; each must be registered with the engine. Graded types list graded kinds only,
|
|
110
|
+
* ungraded types ungraded ones only (`open`).
|
|
111
|
+
*/
|
|
112
|
+
readonly slotKinds: readonly string[];
|
|
113
|
+
/** Issue codes the definition may report (namespace = `messages`). */
|
|
114
|
+
readonly issues: readonly string[];
|
|
115
|
+
/** i18n namespace for this type's messages, e.g. `astl.gap`. */
|
|
116
|
+
readonly messages: string;
|
|
117
|
+
/** Accessibility contract, used by docs and conformance: ARIA pattern and the keys that operate it. */
|
|
118
|
+
readonly a11y: { readonly pattern: string; readonly keys: readonly string[] };
|
|
119
|
+
/** `part` names the element exposes for `::part()` styling. Public theming API. */
|
|
120
|
+
readonly cssParts: readonly string[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Attributes every component accepts. `scoring` and `points` only apply to graded types. */
|
|
124
|
+
export const COMMON_ATTRIBUTES: readonly AttributeSpec[] = [
|
|
125
|
+
/** Source id, unique in the document. Views carry an opaque id instead. */
|
|
126
|
+
{ name: 'id', type: 'id', visibility: 'public', required: true },
|
|
127
|
+
/** Element format version. Optional in sources (absent = 1); the compiler always writes the current one. */
|
|
128
|
+
{ name: 'v', type: 'integer', visibility: 'public', min: 1 },
|
|
129
|
+
/** A registered StyleTemplate with the `component` scope (see style.ts); checked by the engine's registry. */
|
|
130
|
+
{ name: STYLE_TEMPLATE_ATTRIBUTE, type: 'string', visibility: 'public' },
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
export const SCORING_ATTRIBUTES: readonly AttributeSpec[] = [
|
|
134
|
+
/** One of the manifest's scoring modes; absent = the manifest's default mode. */
|
|
135
|
+
{ name: 'scoring', type: 'string', visibility: 'private' },
|
|
136
|
+
/** Points of the element's scoring group. */
|
|
137
|
+
{ name: 'points', type: 'number', visibility: 'private', min: 0.01, max: 1000, default: 1 },
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
/** The `variant` attribute of a type with variants: an enum of the manifest's variant names. */
|
|
141
|
+
export function variantAttribute(variants: VariantSpec): AttributeSpec {
|
|
142
|
+
return {
|
|
143
|
+
name: 'variant',
|
|
144
|
+
type: 'enum',
|
|
145
|
+
visibility: 'public',
|
|
146
|
+
values: variants.values,
|
|
147
|
+
default: variants.default,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Every attribute an element of this type may carry, common ones first. */
|
|
152
|
+
export function allAttributes(manifest: ComponentManifest): readonly AttributeSpec[] {
|
|
153
|
+
const scoring = manifest.scoring === null ? [] : SCORING_ATTRIBUTES;
|
|
154
|
+
const variant = manifest.variants === null ? [] : [variantAttribute(manifest.variants)];
|
|
155
|
+
return [...COMMON_ATTRIBUTES, ...scoring, ...variant, ...manifest.attributes];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** JSON with object keys sorted, so equal specs compare equal whatever order their keys are written in. */
|
|
159
|
+
function canonical(value: unknown): string {
|
|
160
|
+
return JSON.stringify(value, (_key, v: unknown) =>
|
|
161
|
+
v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
162
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : 1)))
|
|
163
|
+
: v,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Whether two child specs may share a tag: the same visibility and attributes (in any order), so the tag carries the
|
|
169
|
+
* same data and keeps the same things private in every type that declares it (`astl-prompt`, `astl-option`). Content
|
|
170
|
+
* and counts are each type's own: a select's options are plain text, a choice's options rich.
|
|
171
|
+
*/
|
|
172
|
+
export function sameChildSpec(a: ChildSpec, b: ChildSpec): boolean {
|
|
173
|
+
const attributes = (spec: ChildSpec) =>
|
|
174
|
+
canonical([...spec.attributes].sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0)));
|
|
175
|
+
return a.visibility === b.visibility && attributes(a) === attributes(b);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A child tag two of the manifests declare with specs that differ (see `sameChildSpec`), or null when none does. */
|
|
179
|
+
export function childTagConflict(
|
|
180
|
+
manifests: readonly ComponentManifest[],
|
|
181
|
+
): { readonly tag: string; readonly components: readonly [string, string] } | null {
|
|
182
|
+
const first = new Map<string, { readonly component: string; readonly spec: ChildSpec }>();
|
|
183
|
+
for (const manifest of manifests) {
|
|
184
|
+
for (const child of manifest.children) {
|
|
185
|
+
const seen = first.get(child.tag);
|
|
186
|
+
if (seen === undefined) first.set(child.tag, { component: manifest.tag, spec: child });
|
|
187
|
+
else if (!sameChildSpec(seen.spec, child)) {
|
|
188
|
+
return { tag: child.tag, components: [seen.component, manifest.tag] };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
package/src/player.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
|
|
13
|
+
export interface ElementFeedback {
|
|
14
|
+
/** Verdicts for this element's slots that the student may see. */
|
|
15
|
+
readonly slots: Readonly<Record<SlotId, SlotVerdict>>;
|
|
16
|
+
/** Verdict of the element's scoring group; null when ungraded or graded in parts. */
|
|
17
|
+
readonly group: GroupVerdict | null;
|
|
18
|
+
/** Verdicts of the groups an element graded in parts names in `groupIds` (a crossword's words), by group id. */
|
|
19
|
+
readonly groups?: Readonly<Record<string, GroupVerdict>>;
|
|
20
|
+
/**
|
|
21
|
+
* The author's feedback for the element's verdict and its explanation (HTML), when the policy shows them. The player
|
|
22
|
+
* shows both under the element, so an element needs to do nothing with them.
|
|
23
|
+
*/
|
|
24
|
+
readonly message?: Feedback | null;
|
|
25
|
+
readonly explanation?: string | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Units {
|
|
29
|
+
readonly answered: number;
|
|
30
|
+
readonly total: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** What the player gives each element when it mounts the view. */
|
|
34
|
+
export interface ElementContext {
|
|
35
|
+
/** UI locale for labels and announcements (not the content language). */
|
|
36
|
+
readonly locale: string;
|
|
37
|
+
/**
|
|
38
|
+
* Formats a message in the UI locale from the element type's namespace, falling back to the shared `astl.player`
|
|
39
|
+
* namespace (verdict words such as `verdict.correct`, generic labels).
|
|
40
|
+
*/
|
|
41
|
+
t(key: string, params?: MessageParams): string;
|
|
42
|
+
/** Polite announcement through the player's single live region. */
|
|
43
|
+
announce(message: string): void;
|
|
44
|
+
/** 1-based position among numbered elements (inline questions), for labels such as "Gap 3". 0 = not numbered. */
|
|
45
|
+
readonly number: number;
|
|
46
|
+
/** Per-attempt seed for UI shuffles; null = keep the view order. */
|
|
47
|
+
readonly seed: string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PlayerElementApi {
|
|
51
|
+
/** Slot ids this element answers, in reading order. Stable after the element connects. */
|
|
52
|
+
readonly slotIds: readonly SlotId[];
|
|
53
|
+
/**
|
|
54
|
+
* The ids of the groups an element may be graded in (`ComponentDefinition.groups`), as its view names them: the
|
|
55
|
+
* player passes their verdicts in `feedback.groups`. Absent: one group, the element's id.
|
|
56
|
+
*/
|
|
57
|
+
readonly groupIds?: readonly string[];
|
|
58
|
+
/** Answered slots only. */
|
|
59
|
+
getAnswers(): Answers;
|
|
60
|
+
/** Unknown ids are ignored; `''` clears a slot. Does not fire a change event. */
|
|
61
|
+
setAnswers(answers: Answers): void;
|
|
62
|
+
/** Shows verdicts; null clears them. Editing a slot clears its own verdict. */
|
|
63
|
+
feedback: ElementFeedback | null;
|
|
64
|
+
/** Shows the correct answers next to the student's; null hides them. */
|
|
65
|
+
solution: Solution | null;
|
|
66
|
+
disabled: boolean;
|
|
67
|
+
/** Progress units, e.g. 3 of 5 cards placed. */
|
|
68
|
+
units(): Units;
|
|
69
|
+
/** Called by the player once, before the first render. Elements must work with a default context too. */
|
|
70
|
+
attach(context: ElementContext): void;
|
|
71
|
+
/** Non-answer UI state worth restoring after a reload. */
|
|
72
|
+
getUiState?(): JsonValue;
|
|
73
|
+
setUiState?(state: JsonValue): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** DOM events. All bubble and are composed (they cross shadow roots). */
|
|
77
|
+
export const PlayerEvent = {
|
|
78
|
+
/** From an element when the student changes an answer. Detail: ChangeDetail. */
|
|
79
|
+
change: 'astl-change',
|
|
80
|
+
/** From `<astl-player>` when the view is mounted and elements are attached. Detail: ReadyDetail. */
|
|
81
|
+
ready: 'astl-ready',
|
|
82
|
+
/** Page changed. Detail: PageDetail. */
|
|
83
|
+
page: 'astl-page',
|
|
84
|
+
/** Attempt state changed. Detail: StateDetail. */
|
|
85
|
+
state: 'astl-state',
|
|
86
|
+
/** A check or submit finished. Detail: the CheckResponse or SubmitResponse. */
|
|
87
|
+
result: 'astl-result',
|
|
88
|
+
/** Snapshot to persist (debounced). Detail: Snapshot. */
|
|
89
|
+
snapshot: 'astl-snapshot',
|
|
90
|
+
/** Loading or grading failed. Detail: ErrorDetail. */
|
|
91
|
+
error: 'astl-error',
|
|
92
|
+
} as const;
|
|
93
|
+
|
|
94
|
+
/** Detail of `astl-ready`. */
|
|
95
|
+
export interface ReadyDetail {
|
|
96
|
+
readonly viewHash: string;
|
|
97
|
+
/** Number of pages. */
|
|
98
|
+
readonly pages: number;
|
|
99
|
+
/** Number of slots across all registered elements. */
|
|
100
|
+
readonly slots: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ChangeDetail {
|
|
104
|
+
/** Changed slots only; `''` = cleared. */
|
|
105
|
+
readonly answers: Answers;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface PageDetail {
|
|
109
|
+
readonly index: number;
|
|
110
|
+
readonly count: number;
|
|
111
|
+
/** View page id. */
|
|
112
|
+
readonly id: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type AttemptState =
|
|
116
|
+
| 'loading'
|
|
117
|
+
| 'ready'
|
|
118
|
+
| 'active'
|
|
119
|
+
| 'checking'
|
|
120
|
+
| 'submitting'
|
|
121
|
+
| 'submitted'
|
|
122
|
+
| 'review'
|
|
123
|
+
| 'error';
|
|
124
|
+
|
|
125
|
+
export interface StateDetail {
|
|
126
|
+
readonly state: AttemptState;
|
|
127
|
+
readonly previous: AttemptState;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ErrorDetail {
|
|
131
|
+
readonly code: string;
|
|
132
|
+
readonly message: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Turns source HTML (with answers) into a view and a checker for it, for `<astl-player>` light-DOM sources. Registered
|
|
137
|
+
* by bundles that ship the engine (the HTML-with-answers mode); the player itself never holds answer logic.
|
|
138
|
+
* - `lang`: content language of the source (filled from the page when the `<astl-doc>` has none);
|
|
139
|
+
* - `locale`: UI locale of the asking player, for the messages of a failed compile.
|
|
140
|
+
* A failed compile throws; the Error message (plain text, one issue per line) is shown to the author.
|
|
141
|
+
*/
|
|
142
|
+
export type SourceCompiler = (
|
|
143
|
+
source: string,
|
|
144
|
+
context: { readonly lang: string; readonly locale: string },
|
|
145
|
+
) => Promise<{ readonly view: string; readonly checker: Checker }>;
|