Skip to content

@astl/core

Contracts and the i18n runtime. Every interface between the packages lives here; no runtime dependencies.

Thrown by checkers for protocol-level refusals, carrying the RFC 9457 problem document.

  • Error
new CheckerError(problem): CheckerError;
Parameter Type
problem ProblemDetails

CheckerError

Error.constructor
Property Modifier Type
problem readonly ProblemDetails

  • Error
new MessageSyntaxError(message, offset): MessageSyntaxError;
Parameter Type
message string
offset number

MessageSyntaxError

Error.constructor
Property Modifier Type
offset readonly number
Property Modifier Type Description
format readonly 1 -
groups readonly readonly ScoringGroup[] -
help? readonly Readonly<Record<string, KeyHelp>> Help by view element id and view page id; absent when the source has none.
lang readonly string Content language of the document. Slots inherit it unless their key says otherwise.
pages readonly readonly string[] View page ids in order.
slots readonly Readonly<Record<string, KeySlot>> -
viewHash readonly string View hash this key belongs to. Hosts must store and serve them together.

Property Modifier Type Description
checkScope? readonly CheckScope Practice only.
deadline readonly string | null ISO 8601. The server auto-submits at the deadline; the player only shows the countdown.
explanations? readonly HelpMoment -
feedback? readonly HelpMoment -
hints? readonly boolean Hints on request, one at a time from the checker (Checker.hint). Practice only.
maxChecks readonly number | null Practice only. null = unlimited.
mode readonly AttemptMode practice: check any time. test: no check, one submit. review: read-only, shows a submitted attempt.
navigation readonly "free" | "linear" linear: no going back to earlier pages (tests).
passMark readonly number | null Fraction of the maximum score needed to pass, 0..1. null = no pass mark.
reveal readonly Reveal -
seed readonly string | null Seed for per-attempt UI shuffles. null = keep the view order.

Property Modifier Type Description
default? readonly string | number | boolean Value used when the attribute is absent. Documented and shown by the editor.
max? readonly number -
min? readonly number Inclusive bounds for integer and number.
name readonly string -
required? readonly boolean -
type readonly AttributeType -
values? readonly readonly string[] Allowed values for enum.
visibility readonly Visibility -

Property Modifier Type
detail readonly string
key readonly string
kind readonly "missing" | "extra" | "syntax" | "params" | "plural"

Property Modifier Type Description
answers readonly Answers Changed slots only; '' = cleared.

check(request): Promise<CheckResponse>;

Practice only. Rejects with CheckerError (check_not_allowed) under other policies.

Parameter Type
request CheckRequest

Promise<CheckResponse>

optional hint(request): Promise<HintResponse>;

The next hint, practice only; checkers without hints leave it out. Rejects with CheckerError hints_not_allowed when the policy offers none, hints_exhausted when all are used, not_found for an unknown element.

Parameter Type
request HintRequest

Promise<HintResponse>

submit(request): Promise<SubmitResponse>;
Parameter Type
request SubmitRequest

Promise<SubmitResponse>


What planChecks makes of a page's parts: the questions of each check, in the order of the checks.

Property Modifier Type Description
targets readonly readonly (readonly string[])[] Each check's questions: those its for names (callers pass only graded questions of the page), else the graded inline questions of the run of text right above it; without the ones an earlier check has.
twice readonly readonly (readonly string[])[] The questions each check names that an earlier check has already (CHECK_TARGET_TWICE).
uncovered readonly readonly (readonly string[])[] The graded inline questions of each run of text that no check has, for the runs that hold any: where the player puts an automatic Check, after the last of them.

Property Modifier Type Description
answers readonly Answers -
element? readonly string View element id: grade that interaction only, under a policy with checkScope: 'interaction'. It counts against maxChecks like any check. Never together with page.
elements? readonly readonly string[] View element ids: grade those interactions at once (a Check element's questions, CHECK_TAG), under a policy with checkScope: 'interaction'. One check against maxChecks. Never together with page or element.
page? readonly string View page id: grade only that page. Omit to grade everything.

Help that comes with a result when the policy shows it (the engine's helpShown), for what was graded: absent when there is none, so responses without help stay as they were.

Property Modifier Type Description
checksLeft readonly number | null Checks left in this attempt; null = unlimited.
explanations? readonly Readonly<Record<string, string>> HTML by view element id or view page id.
feedback? readonly Readonly<Record<string, Feedback>> By view element id, and by view page id for a page's own feedback (picked by the page's score).
result readonly GradeResult -

How checkParts reads a tree: the engine's and the authoring kit's (core AST), or the player's (DOM).

Type Parameter
T
checkFor(node): readonly string[] | null;

A check's for: the ids it names, or null without the attribute.

Parameter Type
node T

readonly string[] | null

children(node): readonly T[];
Parameter Type
node T

readonly T[]

component(node):
| {
block: boolean;
graded: boolean;
id: string | null;
}
| null;

A component: its source id (view id in a view), whether it is a graded question, whether it is a block.

Parameter Type
node T

| { block: boolean; graded: boolean; id: string | null; } | null

tag(node): string | null;

An element's tag, or null for text.

Parameter Type
node T

string | null

optional taskCheck(node): boolean;

Whether a task has a Check of its own (check in a source). Absent: never, as in a view, where the engine has written that Check as a Check element at the end of the task.

Parameter Type
node T

boolean


A child element type a component accepts, e.g. <astl-option> inside <astl-choice>.

  • content: 'text': plain text only (e.g. an accepted alternative answer).
  • content: 'inline': rich inline content (emphasis, lang spans, math).
Property Modifier Type Description
attributes readonly readonly AttributeSpec[] -
content readonly "text" | "inline" -
max readonly number | null null = unbounded.
min readonly number -
place? readonly "lead" Only in a type with rich content (content: 'flow'). Absent: the child sits in that content's text (a word to select). 'lead': it stands before the content, as the element's first child, never in its text (a prompt).
tag readonly string -
visibility readonly "public" | "private" -

Property Modifier Type Description
key readonly AnswerKey -
metadata readonly Metadata -
view readonly string -
viewHash readonly string Lowercase hex SHA-256 of the UTF-8 view.

Property Modifier Type Description
dir readonly Direction -
lang readonly string -
profile readonly NormalisationProfile Engine-wide text comparison defaults; definitions apply their own attributes on top.
opaque(localId?): string;

Opaque id for the current element (no argument) or for a source id local to it, e.g. an option id. Deterministic for (secret, salt, element id, local id), so recompiling gives the same view.

Parameter Type
localId? string

string

opaqueOf(id, localId?): string;

The opaque id of another component (by source id) or of a source id local to it, as that component's view writes it: what a drop's view and key need of its word bank. Throws for an id validate did not check (no such component, or no such local id).

Parameter Type
id string
localId? string

string

permute<T>(items, options?): T[];

Keyed permutation, a pure function of (element seed, salt, item count): calling it twice gives the same order, so slots and toView agree. With avoidOriginal, 2+ items never come back in source order (use it when the source order is the answer, e.g. ordering tasks). Use different salts for independent permutations.

Type Parameter
T
Parameter Type
items readonly T[]
options? { avoidOriginal?: boolean; salt?: string; }
options.avoidOriginal? boolean
options.salt? string

T[]


Property Modifier Type Description
salt? readonly string Mixed into opaque ids and permutations, e.g. the exercise id, so two exercises never share ids.

Property Modifier Type Description
manifest readonly ComponentManifest -
messages? readonly readonly MessageCatalog[] Catalogs of the manifest's namespace; the engine uses them to describe this type's issues.
migrations? readonly Readonly<Record<number, (element) => ElementNode>> migrations[n] upgrades a source element written for version n to n + 1.
optional example(element): boolean;

Whether the element shows a worked example (its example attribute): it is answered already, read-only, so it has no slots and no scoring group, counts towards no score and needs no Check. Absent: never an example.

Parameter Type
element ElementNode

boolean

optional groups(element, context): readonly GroupSpec[] | null;

The scoring groups of an element graded in parts (a crossword's words): each scores by the rule of the element's scoring mode and gets its points, and together they hold every slot. Null or absent: one group, with the element's id, of all its slots. Called for valid graded elements only, after slots.

Parameter Type
element ElementNode
context CompileContext

readonly GroupSpec[] | null

optional localIds(element): readonly string[];

Local ids of slots that no child stands for (a crossword's cells), read from the valid element. Each gets an opaque id as a child's id does: context.opaque(localId), fixture ref <id>/<localId>. Start them with a digit, so they never meet a child's id (source ids start with a letter). Absent: the children's ids only.

Parameter Type
element ElementNode

readonly string[]

optional metadata(element): Readonly<Record<string, number>>;

Extra numbers for metadata (e.g. { words: 12 }), stored as <tag>.<name>.

Parameter Type
element ElementNode

Readonly<Record<string, number>>

slots(element, context): readonly SlotSpec[];

Slots with their private keys, in reading order. Called only for valid elements.

Parameter Type
element ElementNode
context CompileContext

readonly SlotSpec[]

toView(element, context): ElementNode;

The public view element. Must not contain private attributes or private children; the engine enforces the manifest allow-list afterwards and fails the compile if a private value would leak.

Parameter Type
element ElementNode
context CompileContext

ElementNode

validate(element, context): void;

Type-specific checks on a sanitised element. The engine has already checked everything the manifest says (attribute types, enums, required attributes, child tags and counts, id).

Parameter Type
element ElementNode
context ValidateContext

void


Property Modifier Type Description
a11y readonly object Accessibility contract, used by docs and conformance: ARIA pattern and the keys that operate it.
a11y.keys readonly readonly string[] -
a11y.pattern readonly string -
attributes readonly readonly AttributeSpec[] Type-specific attributes. The common ones (id, v, scoring, points) come from COMMON_ATTRIBUTES.
children readonly readonly ChildSpec[] -
content? readonly "flow" Absent: the element holds its declared children only. 'flow' (blocks only): it wraps rich content as a page holds it (paragraphs, headings, lists, quotes, figures, formatting, pictures; no components), and its declared children are inline children that sit in that content's text where an inline component may sit (a word to select in a passage), except those with place: 'lead', which come first, before the content (a prompt); min and max count them wherever they are.
cssParts readonly readonly string[] part names the element exposes for ::part() styling. Public theming API.
display readonly "block" | "inline" inline sits inside text (a gap); block stands between paragraphs (a multiple choice).
graded readonly boolean Whether the type is scored. Graded types form one scoring group of graded slots. Ungraded types have no scoring and add nothing to the maximum: they produce no slots (flash cards, media), or only open slots (a long answer), whose answers are stored with the attempt for a teacher.
issues readonly readonly string[] Issue codes the definition may report (namespace = messages).
messages readonly string i18n namespace for this type's messages, e.g. astl.gap.
scoring readonly ScoringSpec | null null for ungraded types.
slotKinds readonly readonly string[] Slot kinds the definition produces; each must be registered with the engine. Graded types list graded kinds only, ungraded types ungraded ones only (open).
tag readonly string Custom element name. Built-ins use the astl- prefix; third parties use their own.
variants readonly VariantSpec | null null for types with a single presentation.
version readonly number Element format version, written as v="n" in views. Bump on incompatible changes and add a migration.

Property Modifier Type Description
catalogs readonly readonly MessageCatalog[] -
fallbackLocale? readonly string Default en.
formatter? readonly MessageFormatter -

What a WYSIWYG integration must provide so the authoring kit can drive it. Everything is in source HTML (the <astl-doc> format), so an adapter is free to use any internal model.

Property Modifier Type Description
editsSource? readonly boolean True when the editor shows and edits the source HTML as text (the textarea adapter, a code editor): <astl-editor> then names its view "HTML" and offers no HTML view of its own, which would show the same text. Absent: a visual editor.
style? readonly EditorStyles Styles at the cursor, named styles and layouts. Absent: an editor of source text (the textarea), no controls.
optional addPage(after?): string;

Adds an empty page (one empty paragraph) after the page after, or after the last page when after is not the id of one, and returns its id: fresh (page-<n>), without a label, lang or dir. The cursor goes into it. A document without pages becomes its first page in the same step. One undo step.

Parameter Type
after? string

string

optional focus(): void;

Focuses the editor, its cursor where it was (after a toolbar press from the keyboard). An editor that has the focus is left as it is, so a click there a moment before keeps its cursor.

void

optional format(format, href?): boolean;

Toggles a format on the selection and focuses the editor; returns whether the document changed. A mark goes on all of the selected text, or off when all of it has it; link with an href links the selected text (or changes the link at the cursor) and without one removes the link at the cursor; a text style sets the blocks of the selection to it (heading or subheading again sets paragraph); a list wraps them in that list, turns the other list into it, or lifts them out of it. One undo step. Absent (with formatState): no formatting commands.

Parameter Type
format EditorFormat
href? string

boolean

optional formatState(): EditorFormatState;

The formats at the cursor and whether undo or redo can run. Present with format.

EditorFormatState

optional getCursor(): EditorBlockPlace | null;

The block holding the cursor (in a document without pages: page null), or null while the editor has no cursor in content. A host follows it to show the page being edited.

EditorBlockPlace | null

getElement(id): string | null;

Source HTML of one component element, or null when the id is not in the document.

Parameter Type
id string

string | null

getSelection(): EditorSelection | null;

The component at the cursor, or null.

EditorSelection | null

getSource(): string;

The whole document as source HTML.

string

insert(html, options?): void;

Inserts a source snippet (an instantiated template) at the cursor, never into a component: after the component the cursor is in. With replaceSelection, an inline snippet takes the place of the selected text. A rich-text editor keeps the text whole: a snippet of blocks (a block component, a paragraph) goes after the element the cursor is in directly on its page or column (a paragraph, a heading, a list), or in the place of that element when it is an empty paragraph; a layout goes after the layout the cursor is in, as layouts do not nest. A source editor (the textarea adapter) puts any snippet at the caret, as the author would type it.

Parameter Type
html string
options? EditorInsertOptions

void

optional mergePage(id): boolean;

Joins the page id to the page before it: its content follows that page's content, and that page keeps its id, label, lang and dir. The cursor goes to the start of the joined content. Returns false, changing nothing, for the first page or an id that is not a page's. One undo step.

Parameter Type
id string

boolean

optional moveBlock(block, direction): boolean;

Moves a block one place up or down within its page, the cursor with it; returns false, changing nothing, at the page's start or end or for a place that holds no block. One undo step. Absent: blocks do not move. A block in a column stays in its column; a block directly on the page moves past a whole layout, which itself never moves. A block next to a frame moves into it (its last place going up, its first going down), and a frame's first or last block out of it; a frame itself never moves.

Parameter Type
block EditorBlockPlace
direction "up" | "down"

boolean

onChange(listener): () => void;

Subscribe to document changes. Returns an unsubscribe function.

Parameter Type
listener () => void

() => void

optional onCursorChange(listener): () => void;

Subscribe to every move of the cursor and every change of the document or its history: what getCursor and formatState return may have changed. Returns an unsubscribe function. Present with either.

Parameter Type
listener () => void

() => void

onSelectionChange(listener): () => void;

Subscribe to selection changes. Returns an unsubscribe function.

Parameter Type
listener (selection) => void

() => void

optional redo(): boolean;

Redoes the last undone step and focuses the editor; returns whether the document changed.

boolean

optional removeBlock(block): boolean;

Deletes a block: its component, or all of its text; a page, a column or a frame left without content keeps one empty paragraph. Returns false, changing nothing, for a place that holds no block. One undo step.

Parameter Type
block EditorBlockPlace

boolean

optional removePage(id): boolean;

Deletes the page id and everything on it. The cursor goes to the start of the page before it, or of the next page when it was the first. Returns false, changing nothing, for the only page or an id that is not a page's. One undo step.

Parameter Type
id string

boolean

replaceElement(id, html): void;

Replaces one component element in place (inspector edits); the rest of the document is untouched. A cursor inside the element stays inside it: the inspector follows the element at the cursor while it writes.

Parameter Type
id string
html string

void

select(id): void;

Moves the cursor to an element by source id (a component or a page) and focuses the editor.

Parameter Type
id string

void

optional selectedText(): string;

The plain text of the selection when it lies within one text block (trimmed), else ''. A template's {{selection}} takes it, and insert with replaceSelection puts the snippet in its place. Absent: ''.

string

optional setPageCheck(check, page?): boolean;

Sets (check: true) or clears check on the page page, or on every page when it is left out: a page's own Check in practice. A document without pages becomes one page with a fresh id (page-<n>) and check in the same step; clearing keeps the pages as they are. Returns whether anything changed (false when it was so already, or for an id that is not a page's). One undo step. Absent: the editor cannot set it.

Parameter Type
check boolean
page? string

boolean

setSource(source): void;

Replaces the whole document.

Parameter Type
source string

void

optional splitPage(): string | null;

A page break at the cursor (at the start of a selection, which stays): a new page from there on, whose id it returns, or null when the cursor is in no page's content. In a paragraph or a heading directly on a page, the page breaks at the cursor (at its start: before it; at its end: after it); anywhere else (a component, a rich block, a list, a column of a layout) after the block directly on the page, which stays whole. A side left without content gets one empty paragraph. The new page has a fresh id page-<n> (pages and components share one namespace), no label, and the lang and dir of the page it comes from; the cursor goes to the start of its first line. A document without pages becomes pages in the same step, the first with a fresh id too. One undo step. Absent: the editor cannot split pages.

string | null

optional undo(): boolean;

Undoes the last step and focuses the editor; returns whether the document changed. Absent: no history.

boolean

optional wrap(tag): boolean;

Runs the wrap command of the type tag (EditorDescriptor.wrap) on the selection and focuses the editor; returns whether the document changed. Absent: the editor offers no such command.

Parameter Type
tag string

boolean


A block by its place. A page's content is a list of blocks: each block component (display: 'block') directly on the page is one block, and so is each Check element (astl-check); the content between two of them (paragraphs, headings, lists, quotes, pictures, with the inline components in their text) is one text block. The authoring kit's outline lists the same blocks (OutlinePage.blocks). The content format has no blocks: they are a way to show and move a page's content. A layout is not a block either: the blocks in its columns are on the page's list, in reading order, and a column's content divides as a page's does; nor is a frame: the blocks it holds are, its title and tag aside.

Property Modifier Type Description
index readonly number The block's index on its page, from 0.
page readonly string | null The page's source id, or null for the content of a document without pages.

How authors create and edit one component type. Plain data, so it can also feed agent tools and docs. Message keys are looked up in the manifest's messages namespace.

Property Modifier Type Description
companion? readonly object The element this type works with, such as the word bank of a gap: an insert writes into an empty attribute the id of the first tag element of the inserted template (a starter that brings one), else of the new element's page (pages play one at a time), and adds that tag's template at the end of the page when it has none.
companion.attribute readonly string -
companion.tag readonly string -
description readonly string Message key of a one-line description for insert menus.
fields? readonly readonly InspectorField[] Inspector fields. Absent = derived from the manifest by the authoring kit.
icon readonly string Icon name in the host's icon set (Phosphor names recommended), e.g. text-t.
idPrefix readonly string Prefix for generated ids: gap gives gap-1, gap-2, ...
label readonly string Message key of the menu label, e.g. editor.label.
manifest readonly ComponentManifest -
messages? readonly readonly MessageCatalog[] Catalogs of the manifest's namespace (labels, help texts, template texts).
template readonly string Source HTML that insert menus add. Placeholders: {{id}} = a fresh unique id, {{t:key}} = a message from the manifest's namespace in the author's UI locale (escaped), {{selection}} = the text the author selected (escaped, '' without one), which the snippet then replaces. Local child ids (option ids) stay as written.
templates? readonly readonly EditorTemplate[] Named starters: whole exercises with sample content, listed apart from the default template (which stays what the type's own entry inserts).
wrap? readonly EditorWrap A command on the author's selection, for a type that holds rich content (content: 'flow').

The formats at the cursor (EditorAdapter.formatState), for a toolbar's pressed and disabled buttons.

Property Modifier Type Description
active readonly readonly EditorFormat[] The formats in effect: each mark on all of the selected text (at a cursor: the text before it), the text style of the block at the cursor (an <h2> counts as heading) and the list it is in.
enabled readonly readonly EditorFormat[] The formats that can be toggled here: none while a component is selected, marks only in text a component holds (an option, a word), all of them in a page's own text.
href readonly string | null The address of the link at the cursor, or null.
redo readonly boolean Whether redo would change the document.
undo readonly boolean Whether undo would change the document.

The frame at the cursor (EditorStyles.frame).

Property Modifier Type Description
empty readonly boolean Whether it holds nothing but empty paragraphs, with an empty title and tag: it can go without asking.
look readonly Readonly<Partial<Record<EditorFrameAttribute, string>>> Its look as written, by attribute; an attribute it does not have is absent (the default).
tag readonly boolean Whether it has a tag.

How EditorAdapter.insert places a snippet.

Property Modifier Type Description
replaceSelection? readonly boolean The snippet replaces the selected text (EditorAdapter.selectedText), e.g. a gap whose answer is that text. Default false: it goes after the cursor and the selection stays.

The layout at the cursor (EditorStyles.layout).

Property Modifier Type Description
columns readonly number -
empty readonly boolean Whether its columns hold nothing but empty paragraphs: it can go without asking.
shape readonly | EditorLayoutShape | null Its shape, or null for one of none (four columns, other widths).

The component the cursor is in, by source id; a selected Check element is one too (tag: astl-check).

Property Modifier Type
id readonly string
tag readonly string

A rule of the document (<astl-style>): a named style (name, label), or the style of a tag (for).

Property Modifier Type
for? readonly string
label? readonly string
name? readonly string
style readonly string

The styling commands of an editor (EditorAdapter.style). Each is one undo step, keeps the cursor and leaves the focus where it is, so a form beside the text can call them on every change.

clear(): boolean;

Clears formatting: the marks and styles of the selected text (a language and a link stay), and the style and named style of the blocks it covers whole; with only a cursor, of its block.

boolean

optional editFrame(edit): boolean;

Changes the frame the cursor is in, in one undo step: one of its look's attributes (BOX_ATTRIBUTES) to a value, or to its default (null); its tag (astl-box-tag) added, the cursor in it, or taken away with its text; unwrap removes the frame and keeps its content in place, its title a heading and its tag a paragraph before it; delete removes it with its content (a host asks first when it holds any). Returns false, changing nothing, without a frame at the cursor or for what it already has.

Parameter Type
edit EditorFrameEdit

boolean

optional editLayout(edit): boolean;

Changes the layout the cursor is in, in one undo step: unwrap removes the columns and keeps their content in place, one column after another; delete removes it with its content (a host asks first when it holds any); a shape gives it that many columns, the content kept: a column that goes gives its content to the last one left. Returns false, changing nothing, without a layout at the cursor or for the shape it has.

Parameter Type
edit EditorLayoutEdit

boolean

optional editTable(edit): boolean;

Changes the table the cursor is in, at the cell with the cursor, in one undo step: a row above or below it, a column before or after it, its row or column deleted (a merged cell across the line grows or shrinks, one that starts on it moves on); the cell merged with the one after it or below it (their content joined), or split back into single cells; the table's header row (its first row as th scope="col" in a thead) or header column (each body row's first cell as th scope="row") on or off; its caption added, the cursor in it, or taken away with its text; delete removes the table with its content (a host asks first when it holds any). Returns false, changing nothing, without a table at the cursor or for an edit EditorTableState.can says no to.

Parameter Type
edit EditorTableEdit

boolean

optional frame(): EditorFrameState | null;

The frame (astl-box) the cursor is in, or null. Absent: the editor cannot change a frame once inserted.

EditorFrameState | null

insertLayout(html): boolean;

Inserts a layout (source HTML, one <astl-columns>, one frame, <astl-box>, or one table) as insert does, the cursor in its first empty block (a new frame's: its title; a table's: its first cell). A frame never goes into a frame, nor a layout into a frame in a column, nor a table into a table: from inside one, it goes after it.

Parameter Type
html string

boolean

optional layout():
| EditorLayoutState
| null;

The layout the cursor is in, or null. Absent: the editor cannot change a layout once inserted.

| EditorLayoutState | null

removeRule(rule): boolean;

Deletes a rule; a named style's class goes from every element too. Returns false for an unknown rule.

Parameter Type
rule Pick<EditorStyleRule, "name" | "for">

boolean

replaceTarget(kind, style): boolean;

Replaces the target's own style with what the allow-list keeps of style (the "Own CSS" field).

Parameter Type
kind EditorStyleTargetKind
style string

boolean

rules(): readonly EditorStyleRule[];

The document's rules, in order.

readonly EditorStyleRule[]

saveRule(kind, label): string | null;

Makes the target's own style a named style: a new rule labelled label, the target's style gone and its class the new name, which it returns. Null, changing nothing, past the limit or without a target of this kind.

Parameter Type
kind EditorStyleTargetKind
label string

string | null

setClass(
where,
name,
rule?
): boolean;

Sets the named style on the selected text (text) or a target, in the place of any other; null clears it. With rule (a ready style: a named rule of the same name), a document without a rule of that name gets it in the same undo step; a rule of the document's own by that name stays as it is. Returns false, changing nothing, for a rule of another name or with for, a new rule past the limit, or a class that changes nothing (no target, or there).

Parameter Type
where | "text" | EditorStyleTargetKind
name string | null
rule? EditorStyleRule

boolean

setRule(rule): boolean;

Adds a rule, or changes the one with its name or for, in place. A tag's rule without declarations goes. Returns false, changing nothing, for a name the format refuses, or a new rule past the limit.

Parameter Type
rule EditorStyleRule

boolean

setTarget(kind, changes): boolean;

Sets declarations on the target of this kind at the cursor; block: on each text block of the selection.

Parameter Type
kind EditorStyleTargetKind
changes EditorStyleChanges

boolean

setText(changes): boolean;

Sets declarations on the selected text; with only a cursor, on what is typed next. Text ends up in one span, whose language and classes stay; a span left with nothing goes. Returns whether anything changed.

Parameter Type
changes EditorStyleChanges

boolean

state(): EditorStyleState;

EditorStyleState

optional table(): EditorTableState | null;

The table the cursor is in, or null. Absent: the editor cannot change a table once inserted.

EditorTableState | null


The state at the cursor (EditorStyles.state), for a toolbar and a form.

Property Modifier Type Description
hasSelection readonly boolean Text is selected; without it, only a cursor.
mixed readonly readonly string[] The properties that differ across the selected text.
targets readonly readonly EditorStyleTarget[] What the cursor is in, from the inside out.
text readonly Readonly<Record<string, string>> The declarations all of the selected text has, or what typing would get at the cursor.
textClass readonly string | null The named style on all of the selected text, or at the cursor; null: none, or not the same throughout.
textEnabled readonly boolean Whether styles can go on text here: not with a component or a picture selected.

An element at the cursor that takes a style (EditorStyleState.targets).

Property Modifier Type Description
className readonly string | null The named style on it (the first, for a source written by hand with more), or null.
kind readonly EditorStyleTargetKind -
style readonly string Its own style in the allow-list's normal form (name: value; name: value), '' without one.
tag readonly string Its tag in the source: p, img, astl-choice.

The table at the cursor (EditorStyles.table).

Property Modifier Type Description
can readonly Readonly<Record< | EditorTableCommand | "headerRow" | "headerColumn", boolean>> Whether each command would change it now, at the cell with the cursor (a merge needs a neighbour of the same span, a split a merged cell, a deletion another row or column), and whether its header row and header column can switch (a cell that holds a question can never be a header).
caption readonly boolean -
columns readonly number -
empty readonly boolean Whether its caption and cells hold nothing: it can go without asking.
headerColumn readonly boolean -
headerRow readonly boolean Whether its first row is a header row (a thead), each body row starts with a row header, it has a caption.
rows readonly number Its rows, the header's among them, and its columns, as its cells and their spans make them.

A named starter of a type, inserted like its default template.

Property Modifier Type Description
description? readonly string Message key of a one-line description.
icon? readonly string Icon name; default: the descriptor's.
id readonly string Kebab-case, unique among the descriptor's templates, e.g. two-gaps.
label readonly string Message key of the menu label.
template readonly string Source HTML with the placeholders of EditorDescriptor.template (one {{id}}, texts as {{t:key}}). Other components in it (the gaps of a word bank) are written without an id: each insert gives them fresh ones.

Wraps the selected words in an inline child (Mark word): the editor puts each selected word in a new child element (a fresh local id, attributes as given) and the blocks around them in an element of this type when they are in none (with a fresh id, joined to one right before or after); on words already in the child it removes the child, keeping the text. Editors offer it as a button labelled label (EditorAdapter.wrap).

Property Modifier Type Description
attributes? readonly Readonly<Record<string, string>> Attributes of a new child besides its id, e.g. { correct: '' } for a boolean.
child readonly string The inline child tag, one of the manifest's children.
label readonly string Message key of the button label.

What the player gives each element when it mounts the view.

Property Modifier Type Description
locale readonly string UI locale for labels and announcements (not the content language).
number readonly number 1-based position among numbered elements (inline questions), for labels such as "Gap 3". 0 = not numbered.
seed readonly string | null Per-attempt seed for UI shuffles; null = keep the view order.
announce(message): void;

Polite announcement through the player's single live region.

Parameter Type
message string

void

t(key, params?): string;

Formats a message in the UI locale from the element type's namespace, falling back to the shared astl.player namespace (verdict words such as verdict.correct, generic labels).

Parameter Type
key string
params? Readonly<Record<string, string | number>>

string


Property Modifier Type Description
explanation? readonly string | null -
group readonly GroupVerdict | null Verdict of the element's scoring group; null when ungraded or graded in parts.
groups? readonly Readonly<Record<string, GroupVerdict>> Verdicts of the groups an element graded in parts names in groupIds (a crossword's words), by group id.
message? readonly Feedback | null The author's feedback for the element's verdict and its explanation (HTML), when the policy shows them. The player shows both under the element, so an element needs to do nothing with them.
slots readonly Readonly<Record<SlotId, SlotVerdict>> Verdicts for this element's slots that the student may see.

What a view says about the help of an interaction or a page, so a player can offer it: never its text.

Property Modifier Type Description
explanation readonly boolean -
feedback readonly readonly FeedbackVariant[] The variants with a text, in FEEDBACK_VARIANTS order.
hintPoints? readonly readonly number[] What each hint can take off in points (its cost times the points of the interaction, or of the page's questions), in order; absent in views compiled before 0.2.
hints readonly readonly number[] The cost of each hint, in order (0: free).

The document tree the engine and component definitions work on. Produced by the engine's HTML parser (sources) and serialised back to HTML (views). Plain data: no DOM, no parent pointers.

Property Modifier Type Description
attrs readonly Readonly<Record<string, string>> Attributes in source order. Values are already entity-decoded.
children readonly readonly Node[] -
tag readonly string Lowercase tag name, e.g. p, astl-gap.
type readonly "element" -

Property Modifier Type Description
manifests readonly readonly ComponentManifest[] Manifests of the registered components, in registration order.
compile(source, options?): Promise<CompileResult>;
Parameter Type
source string
options? CompileOptions

Promise<CompileResult>

describe(issue, locale): string;

Renders an issue in the given UI locale (falls back to English, then to the code).

Parameter Type
issue Issue
locale string

string

grade(
key,
answers,
options?
): GradeResult;

Pure and synchronous: safe to call per request. Malformed answers count as unanswered.

Parameter Type
key AnswerKey
answers Answers
options? GradeOptions

GradeResult

solution(key, options?): Solution;
Parameter Type
key AnswerKey
options? GradeOptions

Solution

validate(source): ValidationReport;
Parameter Type
source string

ValidationReport


Property Modifier Type Description
catalogs? readonly readonly MessageCatalog[] Extra or replacement message catalogs (e.g. more locales) for describe.
components readonly readonly ComponentDefinition[] -
groundColors? readonly GroundColors The colours a page shows text on (hex), for the warning STYLE_LOW_CONTRAST: a colour declared in a style is compared with these where nothing else is declared around it. Without them, only colours both declared are compared.
profile? readonly Partial<NormalisationProfile> Overrides of the default text comparison profile.
secret? readonly string | Uint8Array<ArrayBufferLike> HMAC secret for opaque ids and permutations, at least 16 bytes. Keep it stable: it decides every view. Only compile needs it and throws without one. There is no default: a known secret undoes the keyed option order.
slotKinds? readonly readonly SlotKind<JsonObject>[] Added to the built-in slot kinds (text, number, choice, flag). Same kind twice = error.
styleTemplates? readonly readonly StyleTemplate[] Style templates the hosts' players register, so style-template values can be checked: a name that is not registered, or not allowed at its scope or for its tag, gives the warning STYLE_TEMPLATE_UNKNOWN (the attribute stays in the view). Same name twice = error.
urlPolicy? readonly UrlPolicy Which URLs stay in sources and views (UrlPolicy). Default isSafeUrl.

Property Modifier Type
code readonly string
message readonly string

A feedback text as a student gets it: the variant of the verdict and the author's text (HTML of format 1).

Property Modifier Type Description
html readonly string -
variant readonly FeedbackVariant The verdict's variant; its text is the incorrect one when a partial verdict has none of its own.

Property Modifier Type Description
lang readonly string Content language of the slot (BCP 47), for locale-aware comparisons.

Property Modifier Type Description
element? readonly string Grade one view element only (a check of one interaction): the groups of its slots.
elements? readonly readonly string[] Grade these view elements only (a Check element's questions): the groups of their slots.
hintsUsed? readonly Readonly<Record<string, number>> Hints used, by view element id or view page id (the first n of its hints). A group loses the costs of the hints used of its element and of its page, each a fraction of the group's maximum, never below 0. Its verdict stays.
page? readonly string Grade one view page only (per-page check).

Property Modifier Type Description
correct readonly boolean True when every included group is correct; false when no group is included (empty key or unknown page).
counts readonly VerdictCounts Counts over groups.
groups readonly readonly GroupResult[] -
max readonly number -
pages readonly Readonly<Record<string, Score>> Score per view page id.
score readonly number -
slots readonly Readonly<Record<SlotId, SlotVerdict>> Per-slot verdicts the student may see: answered slots only, selected flags only, and nothing for slots of a multi-slot all-correct group that is wrong or grades one part of its component (those show only the group verdict).

The colours a page shows text on (hex or rgb()).

Property Modifier Type
ink readonly string
surface readonly string

Property Modifier Type
id readonly string
max readonly number
score readonly number
verdict readonly GroupVerdict

A scoring group of an element graded in parts (see ComponentDefinition.groups).

Property Modifier Type Description
id readonly string Opaque group id, from context.opaque(localId): never the element's own id or one of its slot ids.
slots readonly readonly string[] Some of the element's slot ids, in reading order. A slot may sit in several groups (a crossword's crossing).

The help fields of a policy, with every absent one taken from its mode's default policy.

Property Modifier Type
checkScope readonly CheckScope
explanations readonly HelpMoment
feedback readonly HelpMoment
hints readonly boolean

Property Modifier Type Description
element readonly string View element id, or a view page id for the page's own hints.

The next hint of an interaction or page. Whoever grades records it: a hint's cost counts when it is used.

Property Modifier Type Description
cost readonly number The fraction 0..1 of the points this hint takes off (0: free).
html readonly string HTML of content format 1.
index readonly number 0-based position of this hint.
left readonly number Hints still to come after this one.

Property Modifier Type
fallbackLocale readonly string
locales(namespace?): readonly string[];

Locales that have at least one catalog (for a namespace, if given).

Parameter Type
namespace? string

readonly string[]

t(
locale,
namespace,
key,
params?
): string;

Formats namespace:key in the best matching locale, then the fallback locale, else returns the key.

Parameter Type
locale string
namespace string
key string
params? Readonly<Record<string, string | number>>

string

translator(locale, namespace): Translate;

A translate function bound to one locale and namespace.

Parameter Type
locale string
namespace string

Translate

with(catalogs): I18n;

A new instance with more catalogs. Later catalogs override earlier keys of the same namespace and locale.

Parameter Type
catalogs readonly MessageCatalog[]

I18n


Property Modifier Type Description
at readonly IssueLocation -
code readonly string Stable UPPER_SNAKE code. Component codes start with the type, e.g. CHOICE_CORRECT_MISSING.
namespace readonly string i18n namespace of the message (astl.engine or the manifest's messages).
params readonly IssueParams -
severity readonly Severity Errors block compiling; warnings do not.

Property Modifier Type Description
element readonly string | null Source id of the closest element that has one (the component), or null.
page readonly string | null Source id of the page, or null for the implicit page / document level.
path readonly string Readable path from the root, e.g. astl-doc > astl-page#p1 > p[2] > astl-gap#g1. Empty for issues raised before the document could be parsed (SOURCE_TOO_LARGE, DOC_ROOT_INVALID), whose tag is null.
tag readonly string | null Tag of the element the issue is about, or null for the document.

[key: string]: JsonValue

The help of one interaction or page (see help.ts): key-side, as it may give the answer away.

Property Modifier Type Description
explanation readonly string | null HTML; null when there is none.
feedback readonly Readonly<Partial<Record<FeedbackVariant, string>>> HTML by variant, only the variants written.
hints readonly readonly KeyHint[] -

A hint as the key holds it: its content (HTML of format 1) and the fraction 0..1 of the points it costs.

Property Modifier Type
cost readonly number
html readonly string

Property Modifier Type Description
group readonly string Opaque id of the component the slot belongs to, which is also the id of its scoring group, unless the component is graded in parts (ComponentDefinition.groups): then its groups list the slot. Open slots (an ungraded kind) belong to no group: no groups entry has this id or lists them.
key readonly JsonObject -
kind readonly string -
page readonly string View page id.

Messages of one namespace in one locale. Values are ICU MessageFormat 1 strings.

Property Modifier Type Description
locale readonly string BCP 47, e.g. pl.
messages readonly Readonly<Record<string, string>> -
namespace readonly string e.g. astl.player, astl.gap.

Port for message formatting. The default is the ICU MessageFormat 1 subset in format.ts.

format(
message,
params,
locale
): string;
Parameter Type
message string
params MessageParams
locale string

string


Property Modifier Type Description
dir readonly "ltr" | "rtl" -
elements readonly Readonly<Record<string, number>> Element counts by tag, e.g. { "astl-gap": 5 }.
extra readonly Readonly<Record<string, number>> Numbers contributed by component metadata hooks, keyed tag.name.
format readonly number -
groups readonly number -
kind? readonly "exercise" | "book" The document's kind when it is not exercise, the default: as in the view, the metadata of every exercise (and every conformance golden) stays as it was. Absent means exercise.
lang readonly string -
maxScore readonly number -
open readonly readonly string[] Ids of the open slots (stored for a teacher, never graded), in reading order, so a server or a teacher's view can pick these answers out of a submission. They add nothing to maxScore.
pages readonly readonly PageMetadata[] -
slots readonly number Answer slots, open ones included: what a player's astl-ready counts.
viewHash readonly string -
words readonly number Words of running text, for reading-time estimates.

How typed text is compared. Resolved at compile time and stored inside each text key, so stored keys grade the same forever, whatever the defaults are later.

Property Modifier Type Description
case readonly "sensitive" | "insensitive" insensitive: locale-aware lower-casing with the content language (Turkish dotless i works).
form readonly "NFC" | "NFKC" Unicode normalisation applied first.
marks readonly "strict" | "fold" fold: ignore diacritics (ą = a, ł = l, ø = o, ß = ss). strict keeps them: żółw != zolw.
punctuation readonly "strict" | "ignore-edge" ignore-edge: drop punctuation at the start and end ("ssak." = "ssak").
quotes readonly "strict" | "fold" fold: typographic quotes, apostrophes and dashes compare equal to ASCII ones.
space readonly "strict" | "collapse" collapse: trim and turn every whitespace run into one space.

Property Modifier Type Description
count readonly number -
id readonly string View page id.
index readonly number -

Property Modifier Type Description
id readonly string View page id.
label readonly string | null -
maxScore readonly number -
slots readonly number Answer slots on the page, open ones included.

Property Modifier Type Description
disabled public boolean -
feedback public ElementFeedback | null Shows verdicts; null clears them. Editing a slot clears its own verdict.
groupIds? readonly readonly string[] The ids of the groups an element may be graded in (ComponentDefinition.groups), as its view names them: the player passes their verdicts in feedback.groups. Absent: one group, the element's id.
slotIds readonly readonly string[] Slot ids this element answers, in reading order. Stable after the element connects.
solution public Readonly<Record<string, string>> | null Shows the correct answers next to the student's; null hides them.
attach(context): void;

Called by the player once, before the first render. Elements must work with a default context too.

Parameter Type
context ElementContext

void

getAnswers(): Answers;

Answered slots only.

Answers

optional getUiState(): JsonValue;

Non-answer UI state worth restoring after a reload.

JsonValue

setAnswers(answers): void;

Unknown ids are ignored; '' clears a slot. Does not fire a change event.

Parameter Type
answers Answers

void

optional setUiState(state): void;
Parameter Type
state JsonValue

void

units(): Units;

Progress units, e.g. 3 of 5 cards placed.

Units


Property Modifier Type
code readonly ProblemCodeValue
detail? readonly string
status readonly number
title readonly string
type readonly string

Detail of astl-ready.

Property Modifier Type Description
pages readonly number Number of pages.
slots readonly number Number of slots across all registered elements.
viewHash readonly string -

Help that comes with a result when the policy shows it (the engine's helpShown), for what was graded: absent when there is none, so responses without help stay as they were.

Property Modifier Type Description
explanations? readonly Readonly<Record<string, string>> HTML by view element id or view page id.
feedback? readonly Readonly<Record<string, Feedback>> By view element id, and by view page id for a page's own feedback (picked by the page's score).

Property Modifier Type
max readonly number
score readonly number

Property Modifier Type Description
id readonly string -
page readonly string View page id the group belongs to.
points readonly number -
rule readonly ScoringRule -
slots readonly readonly string[] Slot ids in reading order.

Scoring modes an author can pick with the scoring attribute, each mapped to one engine rule. Mode names speak the author's language (all, per-option); rules are the three engine rules.

Property Modifier Type
default readonly string
modes readonly Readonly<Record<string, ScoringRule>>

Type Parameter Default type
TKey extends JsonObject JsonObject
Property Modifier Type Description
graded? readonly boolean False for a kind that is stored but never graded (the built-in open): its slots belong to no scoring group, get no verdict and add nothing to the maximum, and only ungraded types (graded: false) produce them. Default true: graded types produce only graded kinds.
kind readonly string -
selection readonly boolean Selection slots use flag semantics (see scoring.ts).
isCorrect(
key,
answer,
context
): boolean;

answer is never empty here: the engine handles unanswered slots before calling.

Parameter Type
key TKey
answer string
context GradeContext

boolean

isKey(key): key is TKey;

Validates a stored key (compile output, or a key loaded from storage).

Parameter Type
key JsonObject

key is TKey

solution(key): string;

The answer that shows the solution. '' = leave the slot empty (an unselected flag).

Parameter Type
key TKey

string


One graded unit produced by an element. key must satisfy the registered SlotKind's isKey.

Property Modifier Type Description
id readonly string Opaque slot id, from context.opaque(...).
key readonly JsonObject -
kind readonly string -

Property Modifier Type Description
answers readonly Answers -
checks readonly number -
format readonly 1 -
page readonly number 0-based page index.
savedAt readonly string ISO 8601.
submitted readonly boolean -
ui readonly Readonly<Record<string, JsonValue>> Non-answer UI state per element id (e.g. a flashcard index).
viewHash readonly string | null View the snapshot was taken on. A player ignores snapshots of another view.

Property Modifier Type
previous readonly AttemptState
state readonly AttemptState

Property Modifier Type Description
catalogs? readonly readonly MessageCatalog[] Catalogs of that namespace.
components? readonly readonly string[] Component tags it supports at the component scope; absent = every registered component.
dark? readonly Readonly<Record<string, string>> Overrides on top of tokens for the dark theme only.
light? readonly Readonly<Record<string, string>> Overrides on top of tokens for the light theme only.
messages readonly string i18n namespace of its texts: label (picker label) and description (one line), e.g. astl.style.notebook.
name readonly string What authors write in style-template. Matches STYLE_TEMPLATE_NAME.
parts? readonly Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, string>>>>>> ::part() declarations by component tag, then part name (a name from the manifest's cssParts), e.g. { 'astl-choice': { option: { 'border-radius': 'var(--astl-radius-l)' } } }. Use tokens in values so the declarations follow the theme.
scopes readonly readonly StyleScope[] Where the template may be used.
tokens? readonly Readonly<Record<string, string>> Token overrides for the light and dark themes (never hc).
version readonly number Bumped when the look changes visibly. Exercises keep referring to the name.

Property Modifier Type
answers readonly Answers

Help that comes with a result when the policy shows it (the engine's helpShown), for what was graded: absent when there is none, so responses without help stay as they were.

Property Modifier Type Description
explanations? readonly Readonly<Record<string, string>> HTML by view element id or view page id.
feedback? readonly Readonly<Record<string, Feedback>> By view element id, and by view page id for a page's own feedback (picked by the page's score).
passed readonly boolean | null null when there is no pass mark or nothing is revealed.
result readonly GradeResult | null null when the policy reveals nothing yet.
solution readonly Readonly<Record<string, string>> | null Only when the policy reveals answers.
submittedAt readonly string ISO 8601, set by whoever grades.

Property Modifier Type
type readonly "text"
value readonly string

Property Modifier Type
answered readonly number
total readonly number

Property Modifier Type Description
lang readonly string Content language at this element (nearest lang, else the document's).
profile readonly NormalisationProfile Engine-wide text comparison defaults (for duplicate checks); definitions apply their own attributes on top.
find(id): ElementNode | undefined;

Another component on the same page, by source id, sanitised as its own definition sees it (a drop names its word bank); undefined when the page has none. Pages are played one at a time, so elements that work together share a page. Definitions run once the whole document is read, so the element may come later in the source.

Parameter Type
id string

ElementNode | undefined

report(
code,
params?,
options?
): void;

Reports an issue on the current element, or on one of its children (for a precise path). code must be listed in the manifest's issues. Default severity: error.

Parameter Type
code string
params? Readonly<Record<string, string | number>>
options? { child?: ElementNode; severity?: Severity; }
options.child? ElementNode
options.severity? Severity

void


Property Modifier Type Description
issues readonly readonly Issue[] -
ok readonly boolean True when there are no errors (warnings allowed).

Presentation variants, picked by authors with the public variant attribute: how the element looks and behaves for the student (a gap that grows while typing, a select with a search box), never what it grades or which answers exist, so every variant of a source grades the same. The engine validates the value (an enum of values), elements render it, the authoring kit offers it (labels: editor.value.variant.<value> in the manifest's namespace). Adding a variant is not a breaking change; removing one or changing the default is (bump version).

Property Modifier Type Description
default readonly string Used when the attribute is absent or unknown to an older player.
values readonly readonly string[] Kebab-case names, default included.

Property Modifier Type Description
correct readonly number -
empty readonly number -
incorrect readonly number -
partial readonly number -
total readonly number Number of groups counted.
type Answers = Readonly<Record<SlotId, string>>;

type AttemptMode = "practice" | "test" | "review";

Attempt policies. Practice, quiz and test are policies over the same content, not different content: a document's kind (DOC_KINDS, exercise or book) is how it shows, never how it grades. The server is authoritative: the player only reflects the policy it is given.


type AttemptState =
| "loading"
| "ready"
| "active"
| "checking"
| "submitting"
| "submitted"
| "review"
| "error";

type AttributeType = "string" | "boolean" | "integer" | "number" | "enum" | "id" | "url";
  • id: a source id local to the component (e.g. an option id); replaced by an opaque id in the view.
  • boolean: HTML boolean attribute (present = true; "false" is invalid).
  • url: checked by the engine's UrlPolicy; a blocked URL is removed with a URL_BLOCKED warning.

type BadgeFill = typeof BADGE_FILLS[number];

type BadgeShape = typeof BADGE_SHAPES[number];

type CheckPart =
| {
kind: "text";
questions: readonly string[];
}
| {
kind: "block";
question: string | null;
}
| {
for: readonly string[] | null;
kind: "check";
}
| {
kind: "edge";
};

One part of a page for the check rule, in reading order. A run of text is what lies between two block components (paragraphs, lists, quotes, pictures), up to the next heading: its graded inline questions, in order. A heading starts a new run (it usually starts a new exercise). A block component is one part, a check another; an edge (where a layout or one of its columns starts or ends) ends a run.


type CheckScope = "exercise" | "interaction";

interaction: a check may cover one interaction too (CheckRequest.element), not only the exercise or a page.


type CompileResult =
| object & Compilation
| {
issues: readonly Issue[];
ok: false;
};

type Declarations = Readonly<Record<string, string>>;

CSS declarations by property name, e.g. { 'border-radius': 'var(--astl-radius-l)' }.


type Direction = "ltr" | "rtl";

type DocKind = typeof DOC_KINDS[number];

type EditorFormat =
| "bold"
| "italic"
| "underline"
| "link"
| "paragraph"
| "heading"
| "subheading"
| "bulleted"
| "numbered";

A text format a toolbar toggles (EditorAdapter.format), each one of content format 1: the marks bold (<strong> or <b>), italic (<em> or <i>), underline (<u>) and link (<a href>); the text styles paragraph (<p>), heading (<h3>, below the page title the player shows as <h2>) and subheading (<h4>); the lists bulleted (<ul>) and numbered (<ol>).


type EditorFrameAttribute = "title-place" | "variant" | "icon" | "palette";

An attribute of a frame's look (BOX_ATTRIBUTES).


type EditorFrameEdit =
| "unwrap"
| "delete"
| {
attribute: EditorFrameAttribute;
value: string | null;
}
| {
tag: boolean;
};

What EditorStyles.editFrame does to the frame at the cursor.


type EditorLayoutEdit =
| "unwrap"
| "delete"
| EditorLayoutShape;

What EditorStyles.editLayout does to the layout at the cursor.


type EditorLayoutShape = "two" | "three" | "wide-narrow" | "narrow-wide";

The shapes a layout can be changed to: two or three equal columns, or a wide and a narrow one.


type EditorStyleChanges = Readonly<Record<string, string | null>>;

Declarations to set; null removes one. Only what the style allow-list keeps is ever written.


type EditorStyleTargetKind =
| "picture"
| "figure"
| "block"
| "component"
| "column"
| "layout"
| "frame"
| "rule"
| "table";

What takes a style besides the selected text (EditorStyles): a picture in text or in a figure, a figure, the text block with the cursor (a paragraph, a heading, a caption, an option, a table's cell), a component, a column, a layout, a frame (astl-box), a selected horizontal rule or a table.


type EditorTableCommand =
| "row-before"
| "row-after"
| "row-delete"
| "column-before"
| "column-after"
| "column-delete"
| "merge-right"
| "merge-down"
| "split"
| "delete";

A command on a table, at the cell with the cursor (EditorStyles.editTable).


type EditorTableEdit =
| EditorTableCommand
| {
headerRow: boolean;
}
| {
headerColumn: boolean;
}
| {
caption: boolean;
};

What EditorStyles.editTable does to the table at the cursor.


type EngineIssueCode = typeof EngineIssue[keyof typeof EngineIssue];

type FeedbackVariant = "correct" | "incorrect" | "partial" | "omitted";

The when of a feedback text: one per group verdict, omitted for empty.


type GroupVerdict = "correct" | "partial" | "incorrect" | "empty";

type HelpMoment = "never" | "check" | "submit";

When feedback texts or explanations come: never; check: after every check and the hand-in; submit: after the hand-in only. At the hand-in they come only with the answers (reveal: 'answers'): they may give them away.


type InspectorField =
| {
accept?: string;
help?: string;
kind: "attribute";
label: string;
name: string;
options?: {
from?: string;
tag: string;
};
variants?: readonly string[];
}
| {
help?: string;
kind: "text-list";
label: string;
multiline?: boolean;
tag: string;
}
| {
attribute: string;
help?: string;
kind: "child-flag" | "child-text";
label: string;
tag: string;
}
| {
attribute: string;
help?: string;
kind: "child-choice";
label: string;
options?: string;
tag: string;
}
| {
columns: readonly object[];
help?: string;
kind: "child-table";
label: string;
tag: string;
}
| {
alt?: string;
help?: string;
kind: "picture-regions" | "picture-points";
label: string;
src: string;
tag: string;
};

One inspector control:

  • attribute: an attribute of the element (control picked from the AttributeSpec type);
  • text-list: repeated private text children (e.g. accepted alternatives <astl-alt>);
  • child-flag: a boolean attribute on each child of a tag, listed by the child's text (e.g. which options are correct); its label and help messages get count (children) and checked (children with the flag);
  • child-text: a free-text attribute on each child of a tag, listed by the child's text (e.g. the word each clue hides); an empty value removes the attribute;
  • child-choice: one value of an attribute on each child of a tag, listed by the child's text: one of the attribute's enum values (e.g. whether each statement is true or false), or with options, the id of a child of another tag (e.g. the category of each card).
  • child-table: the children of a tag as rows, each listed by its text, with a control for each of columns (by the attribute's type: text, number or a select of its enum values) and a button that removes it; a button adds a row, a child with a fresh local id and a first value for each required attribute (e.g. a crossword's words).
  • picture-regions: zones on the element's picture, one child of tag each, drawn with a pointer or typed in number fields. A zone has id (local), shape (rect, circle or polygon), x and y (rect: its top-left corner; circle: its centre), width and height (rect), r (circle, a share of the width), points (polygon: x,y x,y ...) and an optional label. Every coordinate is a percentage of the picture, which never mirrors: x of its width from the left edge, y of its height from the top.
  • picture-points: pins on the picture, one child of tag each: id, x and y (percent) and label. Both show the picture of the element's url attribute src, which they set by upload or address; with alt, the element's attribute that holds the picture's alt text, a picture from the host that comes with alt text fills it in while it is empty. Rich content (prompts, option texts) is edited in the WYSIWYG itself. The children of a tag are found anywhere in the element, so the inline children of a type with rich content (content: 'flow') are listed too.
{
accept?: string;
help?: string;
kind: "attribute";
label: string;
name: string;
options?: {
from?: string;
tag: string;
};
variants?: readonly string[];
}
Name Type Description
accept? string A url attribute: the files an author may upload for it with the host's uploadAsset (a file input's accept, e.g. video/mp4,video/webm). Absent, or without an upload, the address is typed.
help? string Message key of help text, optional.
kind "attribute" -
label string Message key of the label.
name string Attribute name, e.g. answer.
options? object Choices in a select: the ids of the tag children of the element whose id is in this element's attribute from, listed by their text (e.g. the words of the bank a drop takes its words from); without from, of this element's own tag children (the option a select shows as its example). Without the document or that element, the attribute's own control.
options.from? string -
options.tag string -
variants? readonly string[] Shown only while the element shows one of these variants (its valid variant, else the manifest's default), for an attribute that only one presentation reads (a dropdown's native). Absent: shown in every variant.

{
help?: string;
kind: "text-list";
label: string;
multiline?: boolean;
tag: string;
}
Name Type Description
help? string -
kind "text-list" -
label string -
multiline? boolean Each child in a text area that keeps its line breaks (a transcript), not on one line.
tag string Child tag, e.g. astl-alt.

{
attribute: string;
help?: string;
kind: "child-flag" | "child-text";
label: string;
tag: string;
}
Name Type Description
attribute string Attribute on each child: a boolean for child-flag (e.g. correct), a string for child-text.
help? string -
kind "child-flag" | "child-text" -
label string -
tag string Child tag, e.g. astl-option.

{
attribute: string;
help?: string;
kind: "child-choice";
label: string;
options?: string;
tag: string;
}
Name Type Description
attribute string Attribute on each child, e.g. answer or category.
help? string -
kind "child-choice" -
label string -
options? string Where the choices come from. Absent: the attribute's enum values (editor.value.<attribute>.<value>, e.g. true / false of each statement). A child tag: the ids of the element's children with that tag, listed by their text (e.g. astl-category for the category of each card).
tag string Child tag, e.g. astl-statement or astl-card.

{
columns: readonly object[];
help?: string;
kind: "child-table";
label: string;
tag: string;
}
Name Type Description
columns readonly object[] The child's attributes edited in each row, in order, each with the message key of its label.
help? string -
kind "child-table" -
label string -
tag string Child tag, e.g. astl-crossword-word.

{
alt?: string;
help?: string;
kind: "picture-regions" | "picture-points";
label: string;
src: string;
tag: string;
}
Name Type Description
alt? string The element's attribute that holds the picture's alt text, e.g. alt: an uploaded or picked picture's UploadedAsset.alt fills it in while it is empty. Absent: nothing is filled in.
help? string -
kind "picture-regions" | "picture-points" -
label string -
src string The element's url attribute that holds the picture, e.g. src.
tag string Child tag of a zone or a pin, e.g. astl-region.

type IssueParams = Readonly<Record<string, string | number>>;

type JsonArray = readonly JsonValue[];

type JsonValue =
| string
| number
| boolean
| null
| JsonArray
| JsonObject;

A JSON value. Every contract object that crosses a process boundary is made of these.


type MessageParams = Readonly<Record<string, string | number>>;

i18n contracts. Two axes are kept apart everywhere:

  • UI locale: chrome, labels, issue messages, announcements (the reader's choice);
  • content language: the lang of the exercise text, used for grading and rendering (the author's choice).

type MessagePart =
| {
type: "text";
value: string;
}
| {
name: string;
style: "plain" | "number" | "integer" | "percent";
type: "arg";
}
| {
name: string;
offset: number;
options: Readonly<Record<string, readonly MessagePart[]>>;
ordinal: boolean;
type: "plural";
}
| {
name: string;
options: Readonly<Record<string, readonly MessagePart[]>>;
type: "select";
}
| {
type: "pound";
};

type Node =
| ElementNode
| TextNode;

type ProblemCodeValue = typeof ProblemCode[keyof typeof ProblemCode];

type Reveal = "nothing" | "score" | "answers";

What a submit returns to the student:

  • nothing: just the confirmation (results released later by the host);
  • score: score and verdicts;
  • answers: score, verdicts and the solution.

type ScoringRule = "all-correct" | "per-slot" | "proportional";

Scoring groups. Every graded component forms one group by default (id = the component's opaque id), or one per part when its definition grades it in parts (ComponentDefinition.groups, a crossword's words), where a slot may sit in several groups.

Rules (n = slots in the group, c = correct slots, P = points):

  • all-correct: max P; score P when c = n, else 0. Feedback never shows which slot is wrong: a wrong group shows only its verdict, a right one marks every answered slot right too, unless it grades one part of its component.
  • per-slot: max P x n; score P x c.
  • proportional: max P; score P x c / n (exact, not rounded).

Selection slots (flags, e.g. options of a multiple-answer choice): an unselected flag gets no verdict, and a group whose flags are all unselected scores 0 with verdict empty.


type Severity = "error" | "warning";

Validation issues. Codes + params, never English sentences: hosts render them with message catalogs (<namespace> of the reporting component, or astl.engine for document-level codes).


type SlotId = string;

Answers on the wire. Strings only, so any backend in any language can store and grade them.

  • A missing key or '' means unanswered.
  • Text and number slots: what the student typed.
  • Choice slots: the picked value, an opaque option id or a fixed public value (true / false of a statement).
  • Flag slots (selection): 'true' when selected.
  • Open slots: what the student wrote, kept for a teacher.

type SlotVerdict = "correct" | "incorrect";

type Solution = Readonly<Record<SlotId, string>>;

Correct answers by slot, shown when the policy reveals them. '' entries are omitted.


type SourceCompiler = (source, context) => Promise<{
checker: Checker;
view: string;
}>;

Turns source HTML (with answers) into a view and a checker for it, for <astl-player> light-DOM sources. Registered by bundles that ship the engine (the HTML-with-answers mode); the player itself never holds answer logic.

  • lang: content language of the source (filled from the page when the <astl-doc> has none);
  • locale: UI locale of the asking player, for the messages of a failed compile. A failed compile throws; the Error message (plain text, one issue per line) is shown to the author.
Parameter Type
source string
context { lang: string; locale: string; }
context.lang string
context.locale string

Promise<{ checker: Checker; view: string; }>


type StyleScope = "document" | "component";

document: the whole exercise (the player's canvas and chrome). component: one element and its subtree.


type TokenOverrides = Readonly<Record<string, string>>;

Token values by token name without the --astl- prefix, e.g. { accent: '#7a3ff2', 'radius-m': '1rem' }.


type Translate = (key, params?) => string;
Parameter Type
key string
params? MessageParams

string


type UrlPolicy = (url, context) => boolean;

Decides whether a URL in content may stay: asked with the element's tag and attribute (img and src for a picture in text, a component's tag and its url attribute). Only true keeps it: engines, players and the authoring kit treat a throw or any other answer as no (strictUrlPolicy). Default (isSafeUrl): absolute http:, https: and mailto: URLs.

Parameter Type
url string
context { attribute: string; tag: string; }
context.attribute string
context.tag string

boolean


type Visibility = "public" | "private" | "derived";
  • public: kept in the view as written.
  • private: kept only in the answer key / never leaves the server.
  • derived: computed by the definition's toView; authors cannot write it.
const BADGE_ATTRIBUTES: readonly string[];

The look of a badge in a view; besides them it keeps lang, dir and style, as any element of rich text.


const BADGE_FILLS: readonly ["solid", "soft", "outline"];

const BADGE_SHAPES: readonly ["pill", "circle", "square", "shield", "tag"];

const BADGE_TAG: "astl-badge" = 'astl-badge';

A badge: a number or a short text in a shape (a lesson number in a shield, a level pill, a tag). Inline, in text as an inline component sits there, outside the children of components and never in a link or another badge; a rich block's content (a callout's) may hold one. It holds plain text, at most MAX_BADGE_LENGTH characters (BADGE_TOO_LONG, a warning). Its id (required) is for editors: no view holds it. Its look: shape (default pill), fill (default solid) and palette, 1 to 8 (the author palette; without it the look's accent).


const BLOCK_TAGS: ReadonlySet<string>;

const BOX_ATTRIBUTES: readonly string[];

The look of a frame in a view; besides them it keeps lang, dir and style, as any element of rich text.


const BOX_ICONS: readonly ["info", "tip", "warning", "book", "pencil", "checklist", "star"];

const BOX_LABEL_TAG: "astl-box-tag" = 'astl-box-tag';

const BOX_TAG: "astl-box" = 'astl-box';

A frame: a box that groups text and components under an optional title, directly on a page, in the document or in a column, never in another frame (BOX_NESTED). astl-box-title (optional, first) holds inline text (formatting, a badge, a picture, whose alt then names the frame); astl-box-tag (optional, right after the title or first) a second, outlined part of it; then content as a page holds it: blocks, figures, block components, Check elements, and a layout unless the frame stands in a column (two layout levels at most). Its questions grade as they would outside it. Its look: title-place, variant, icon and palette 1 to 8.


const BOX_TITLE_PLACES: readonly ["inside", "border", "pill", "tab"];

Where the title stands: at the top inside (default), on the top border, in a pill across it, in a tab above it.


const BOX_TITLE_TAG: "astl-box-title" = 'astl-box-title';

const BOX_VARIANTS: readonly ["outline", "soft", "card"];

A border (default), a tint with no border, or a card with a soft shadow (for tinted pages).


const BUILT_IN_PREFIX: "astl-" = 'astl-';

Prefix reserved for built-in Astrolabe elements.


const CAPTION_TAG: "figcaption" = 'figcaption';

const CHECK_ATTRIBUTES: readonly string[];

The attributes of a check, in sources and views (with lang and dir); in a view id and for are opaque.


const CHECK_FOR_ATTRIBUTE: "for" = 'for';

const CHECK_LABEL_ATTRIBUTE: "label" = 'label';

const CHECK_TAG: "astl-check" = 'astl-check';

const CLASS_ATTRIBUTE: "class" = 'class';

A source attribute naming named styles (<astl-style name>); no view ever holds it.


const COLUMN_TAG: "astl-column" = 'astl-column';

One column of a layout: blocks, figures and block components, as a page holds them.


const COLUMNS_TAG: "astl-columns" = 'astl-columns';

A layout: 2 to 4 columns directly on a page or in the document, wrapping by themselves; no nesting.


const COMMON_ATTRIBUTES: readonly AttributeSpec[];

Attributes every component accepts. scoring and points only apply to graded types.


const CONTENT_ATTRIBUTES: ReadonlySet<string>;

Attributes allowed on every content element. style goes through the allow-list of declarations.ts at each side that reads it. class is not here on purpose: it exists in sources only, and the engine inlines it.


const DEFAULT_DOC_KIND: DocKind = 'exercise';

const DEFAULT_PROFILE: NormalisationProfile;

const DOC_ATTRIBUTES: readonly string[];

Attributes the document and page elements may carry in a view.


const DOC_KINDS: readonly ["exercise", "book"];

What a document is, its kind: how it shows, never how it grades. An exercise (the default when absent) shows one page at a time; a book shows two pages side by side (1-2, 3-4, ...) where the player is wide enough, turning them a spread at a time. Practice and test are not kinds: they are policies over any kind (policy.ts).


const DOC_TAG: "astl-doc" = 'astl-doc';

const ELEMENT_TAG_PATTERN: RegExp;

Custom element names that components may use (HTML custom element rules, lowercase ASCII).


const ENGINE_NAMESPACE: "astl.engine" = 'astl.engine';

i18n namespace of document-level issues reported by the engine.


const EngineIssue: object;

Document-level issue codes. Component codes are listed in each manifest's issues.

Name Type Description
ATTRIBUTE_INVALID "ATTRIBUTE_INVALID" -
ATTRIBUTE_REMOVED "ATTRIBUTE_REMOVED" -
ATTRIBUTE_REQUIRED "ATTRIBUTE_REQUIRED" -
BADGE_TOO_LONG "BADGE_TOO_LONG" A badge with more text than MAX_BADGE_LENGTH characters: it shows whole, but no longer reads as a badge (warning).
BOX_NESTED "BOX_NESTED" A frame (astl-box) inside another: frames do not nest. Its content is still validated, in the outer frame.
CHECK_EMPTY "CHECK_EMPTY" A Check element (astl-check) with no questions to check: it does not show (warning).
CHECK_TARGET_NOT_GRADED "CHECK_TARGET_NOT_GRADED" A check names an element that is not a graded question: it is left out (warning).
CHECK_TARGET_OTHER_PAGE "CHECK_TARGET_OTHER_PAGE" A check names a question on another page: it is left out (warning).
CHECK_TARGET_TWICE "CHECK_TARGET_TWICE" A check names a question an earlier check has: the earlier one keeps it (warning).
CHECK_TARGET_UNKNOWN "CHECK_TARGET_UNKNOWN" A check names an id that is no element of the document: it is left out (warning).
CHILD_COUNT "CHILD_COUNT" -
CHILD_OUTSIDE "CHILD_OUTSIDE" A child tag of a registered component outside that component (a word to select outside its passage).
CHILD_UNEXPECTED "CHILD_UNEXPECTED" -
COLUMNS_INVALID "COLUMNS_INVALID" A layout of the wrong shape: <astl-columns> directly on a page, holding 2 to 4 <astl-column>, not nested.
COMPONENT_NESTED "COMPONENT_NESTED" -
DOC_EMPTY "DOC_EMPTY" -
DOC_FORMAT_UNSUPPORTED "DOC_FORMAT_UNSUPPORTED" -
DOC_LANG_INVALID "DOC_LANG_INVALID" -
DOC_LANG_MISSING "DOC_LANG_MISSING" -
DOC_MIXED_PAGES "DOC_MIXED_PAGES" -
DOC_ROOT_INVALID "DOC_ROOT_INVALID" -
ELEMENT_REMOVED "ELEMENT_REMOVED" -
ELEMENT_UNKNOWN "ELEMENT_UNKNOWN" -
EXPLANATION_DUPLICATE "EXPLANATION_DUPLICATE" Two explanations in one interaction or page.
FEEDBACK_DUPLICATE "FEEDBACK_DUPLICATE" Two feedback texts for one when in one interaction or page.
FEEDBACK_WHEN_INVALID "FEEDBACK_WHEN_INVALID" A feedback when that is not one of correct, incorrect, partial, omitted.
FIGURE_INVALID "FIGURE_INVALID" -
HELP_EMPTY "HELP_EMPTY" Help without content: it goes.
HELP_UNGRADED "HELP_UNGRADED" Help (astl-hint, astl-explanation, astl-feedback) with nothing graded around it or on its page: it goes.
HINT_COST_INVALID "HINT_COST_INVALID" A hint cost that is not a number from 0 to 1.
ID_DUPLICATE "ID_DUPLICATE" -
ID_INVALID "ID_INVALID" -
ID_MISSING "ID_MISSING" -
IMG_ALT_MISSING "IMG_ALT_MISSING" -
NO_COMPONENTS "NO_COMPONENTS" -
PAGE_EMPTY "PAGE_EMPTY" -
PAGE_HELP_UNCHECKED "PAGE_HELP_UNCHECKED" Help on a page without check: the player gives the page its Check all the same (warning).
PAGE_NESTED "PAGE_NESTED" -
PLACEMENT_INVALID "PLACEMENT_INVALID" -
POINTS_INVALID "POINTS_INVALID" -
SCORING_MODE_INVALID "SCORING_MODE_INVALID" -
SOURCE_TOO_COMPLEX "SOURCE_TOO_COMPLEX" -
SOURCE_TOO_DEEP "SOURCE_TOO_DEEP" -
SOURCE_TOO_LARGE "SOURCE_TOO_LARGE" -
STYLE_LOW_CONTRAST "STYLE_LOW_CONTRAST" Text and background of an element too close to read: the author decides.
STYLE_NAME_INVALID "STYLE_NAME_INVALID" An <astl-style> that defines nothing usable: a bad or reserved name, an unknown for, or both or neither.
STYLE_REMOVED "STYLE_REMOVED" A declaration the style allow-list refuses (declarations.ts): it goes, the rest of the style stays.
STYLE_RULES_TOO_MANY "STYLE_RULES_TOO_MANY" More <astl-style> rules than MAX_STYLE_RULES.
STYLE_TEMPLATE_UNKNOWN "STYLE_TEMPLATE_UNKNOWN" -
STYLE_TOO_LARGE "STYLE_TOO_LARGE" Inlining the rules would write more than MAX_INLINED_STYLES into the view.
STYLE_TOO_LONG "STYLE_TOO_LONG" A style over MAX_STYLE_LENGTH: it goes whole.
STYLE_UNKNOWN "STYLE_UNKNOWN" A class no <astl-style> defines.
TABLE_INVALID "TABLE_INVALID" A table of the wrong shape: a part out of its place (a cell outside a row, a row outside a table), text or another element between rows and cells, rows that cover different columns, a span past its rows, no rows at all.
TABLE_TOO_LARGE "TABLE_TOO_LARGE" A table with more than MAX_TABLE_COLUMNS columns or MAX_TABLE_ROWS rows.
TASK_NESTED "TASK_NESTED" A task (astl-task) inside another: tasks do not nest. Its content is still validated, in the outer task.
URL_BLOCKED "URL_BLOCKED" -
VERSION_UNSUPPORTED "VERSION_UNSUPPORTED" -

const EXPLANATION_TAG: "astl-explanation" = 'astl-explanation';

Why the answer is what it is; at most one per interaction or page.


const FEEDBACK_TAG: "astl-feedback" = 'astl-feedback';

The text for one verdict, picked by when; at most one per when.


const FEEDBACK_VARIANTS: readonly FeedbackVariant[];

const FIGURE_TAG: "figure" = 'figure';

A picture with a caption: a block directly in a page (or the document), holding exactly one img and at most one figcaption (rich inline text), nothing else. A figcaption anywhere else is unwrapped.


const FLAG_SELECTED: "true" = 'true';

const FORMAT_VERSION: 1 = 1;

Current content format. Written as format="1" on <astl-doc> in sources and views.


const HELP_ATTRIBUTES: readonly string[];

The view attributes of ElementHelp, on a graded component or a page: hints="0 0.25" (the costs, space separated), hint-points="0 0.5" (what each takes off in points), explanation (present when there is one) and feedback="correct incorrect" (the variants with a text, in FEEDBACK_VARIANTS order). Only those with something to say are written; sources never carry them. The engine writes them (compile), the player reads them.


const HELP_TAGS: ReadonlySet<string>;

const HINT_TAG: "astl-hint" = 'astl-hint';

One hint, rich content; hints come in source order. cost: the fraction 0..1 of the points it takes off.


const icuFormatter: MessageFormatter;

The default MessageFormatter. A message with a syntax error renders as its raw text instead of throwing.


const INERT_STYLE: "data-astl-style" = 'data-astl-style';

What inertStyles renames style to.


const INLINE_TAGS: ReadonlySet<string>;

img is a picture: inline, so it can sit in text, prompts, options and cards.


const INSTRUCTION_TAG: "astl-instruction" = 'astl-instruction';

const JSON_MEDIA_TYPE: "application/json" = 'application/json';

const KEY_FORMAT_VERSION: 1 = 1;

const LANGUAGE_TAG_PATTERN: RegExp;

Loose BCP 47 check: pl, pl-PL, zh-Hant-TW, sr-Latn.


const MAX_ANSWER_COUNT: 2000 = 2000;

Most slots one request may carry.


const MAX_ANSWER_LENGTH: 500 = 500;

Longest accepted answer per slot, in Unicode code points, for every slot kind but open. Longer values count as unanswered (engine, servers, protocol 1).


const MAX_ATTRIBUTES_PER_ELEMENT: 256 = 256;

Most attributes one element may carry in a source (beyond it: SOURCE_TOO_COMPLEX, checked before parsing).


const MAX_BADGE_LENGTH: 24 = 24;

const MAX_BADGE_PALETTE: 8 = 8;

const MAX_COLUMNS: 4 = 4;

const MAX_NESTING_DEPTH: 100 = 100;

Deepest element nesting a source may have (beyond it: SOURCE_TOO_DEEP).


const MAX_OPEN_ANSWER_LENGTH: 2000 = 2000;

Longest open answer, in Unicode code points (so Polish and English letters count one each).


const MAX_REQUEST_BYTES: number;

Largest request body servers should accept, in bytes.


const MAX_SOURCE_LENGTH: 1000000 = 1_000_000;

Largest accepted source, in UTF-16 code units.


const MAX_TABLE_COLUMNS: 12 = 12;

const MAX_TABLE_ROWS: 50 = 50;

const MAX_TASK_LABELS: 3 = 3;

const MAX_TASK_LEVEL: 3 = 3;

const MIN_COLUMNS: 2 = 2;

const OPAQUE_ID_PATTERN: RegExp;

Opaque ids in views: k + 16 lowercase base32 characters (80 bits of an HMAC-SHA-256).


const OPEN_SLOT_KIND: "open" = 'open';

The built-in slot kind of open answers: stored with the attempt for a teacher, never graded.


const PAGE_ATTRIBUTES: readonly string[];

const PAGE_CHECK_ATTRIBUTE: "check" = 'check';

check (boolean): in practice the page has a Check of its own ("Check this page"), which checks all its questions at once and then shows the page's help (its hints stay on offer from the start). A page with help and without it gets that Check all the same, and a warning (PAGE_HELP_UNCHECKED).


const PAGE_TAG: "astl-page" = 'astl-page';

const PlayerEvent: object;

DOM events. All bubble and are composed (they cross shadow roots).

Name Type Description
change "astl-change" From an element when the student changes an answer. Detail: ChangeDetail.
error "astl-error" Loading or grading failed. Detail: ErrorDetail.
page "astl-page" Page changed. Detail: PageDetail.
ready "astl-ready" From <astl-player> when the view is mounted and elements are attached. Detail: ReadyDetail.
result "astl-result" A check or submit finished. Detail: the CheckResponse or SubmitResponse.
snapshot "astl-snapshot" Snapshot to persist (debounced). Detail: Snapshot.
state "astl-state" Attempt state changed. Detail: StateDetail.

const PRACTICE_POLICY: AttemptPolicy;

const PROBLEM_MEDIA_TYPE: "application/problem+json" = 'application/problem+json';

const ProblemCode: object;
Name Type Description
attemptClosed "attempt_closed" 409: the attempt is already submitted.
checkNotAllowed "check_not_allowed" 403: checking is not allowed under this policy (tests).
checksExhausted "checks_exhausted" 403: the practice policy's maxChecks is used up.
hintsExhausted "hints_exhausted" 403: every hint of that interaction or page is used.
hintsNotAllowed "hints_not_allowed" 403: the policy offers no hints (tests, or a practice policy with hints: false).
internal "internal_error" 500: unexpected server error.
invalidRequest "invalid_request" 400: body is not valid JSON or does not match the request schema.
methodNotAllowed "method_not_allowed" 405: wrong method.
notFound "not_found" 404: unknown attempt, page or element.
payloadTooLarge "payload_too_large" 413: body too large.
unauthorized "unauthorized" 401: the host could not identify the attempt.

const PROTOCOL_VERSION: 1 = 1;

Grading protocol over HTTP. Any backend in any language can implement it:

POST {endpoint}/check body CheckRequest -> 200 CheckResponse POST {endpoint}/submit body SubmitRequest -> 200 SubmitResponse POST {endpoint}/hint body HintRequest -> 200 HintResponse

{endpoint} identifies one attempt (e.g. /api/attempts/123); how it is authorised is up to the host (cookie, bearer token). Errors are application/problem+json (RFC 9457) with a code from ProblemCode.


const ProtocolPath: object;
Name Type
check "check"
hint "hint"
submit "submit"

const REMOVED_WITH_CONTENT: ReadonlySet<string>;

Dropped together with their content: active content, embeds, media and form controls.


const RULE_TAG: "hr" = 'hr';

A horizontal rule: a block that holds nothing, read as a separator, wherever a paragraph may be. It is drawn as its top border, so an author's border styles (colour, style, width), width and margin are its look.


const SCORING_ATTRIBUTES: readonly AttributeSpec[];

const SCORING_RULES: readonly ScoringRule[];

const SNAPSHOT_FORMAT: 1 = 1;

const SOURCE_ID_PATTERN: RegExp;

Author ids: a letter, then letters, digits, _ or -; at most 64 characters. Unique within one document.


const STYLE_TAG: "astl-style" = 'astl-style';

A rule, first in <astl-doc>: name and label (a named style, applied with class) or for (every element of that tag), with its declarations in style. Sources only: the engine inlines it.


const STYLE_TEMPLATE_ATTRIBUTE: "style-template" = 'style-template';

The attribute that picks a template, on <astl-doc> and on every component.


const STYLE_TEMPLATE_NAME: RegExp;

Template names: lowercase kebab-case, 1 to 40 characters, starting with a letter.


const SUBTASK_LEVELS: readonly ["A", "B", "C", "D"];

const SUBTASK_TAG: "astl-subtask" = 'astl-subtask';

const SUPPORTED_FORMATS: readonly number[];

const TABLE_BODY_TAG: "tbody" = 'tbody';

const TABLE_CAPTION_TAG: "caption" = 'caption';

const TABLE_CELL_TAG: "td" = 'td';

const TABLE_HEAD_TAG: "thead" = 'thead';

const TABLE_HEADER_CELL_TAG: "th" = 'th';

const TABLE_ROW_TAG: "tr" = 'tr';

const TABLE_SCOPES: readonly ["row", "col", "rowgroup", "colgroup"];

What a header cell heads: scope.


const TABLE_TAG: "table" = 'table';

A table: a block wherever a figure may be (a page, the document, a column, a frame, a task, a rich block, help). Its caption (optional, first) holds rich inline text; then rows (tr) in a head (thead, optional, once, before the bodies) and bodies (tbody), or directly in the table as HTML allows; a row holds cells, th (a header: scope) and td, both with colspan and rowspan. Cells hold inline content: text, formatting, pictures and inline components. Every row covers the same columns, spans included, and no span reaches past the rows of its part (TABLE_INVALID); at most MAX_TABLE_COLUMNS columns and MAX_TABLE_ROWS rows (TABLE_TOO_LARGE).


const TABLE_TAGS: ReadonlySet<string>;

Every tag of a table, the table's own included.


const TAG_ATTRIBUTES: Readonly<Record<string, readonly string[]>>;

Extra attributes allowed on specific rich-text elements. A picture: src and alt (required; alt="" marks decoration), width and height (positive integers, so the layout does not jump while it loads). A badge: its look.


const TASK_ATTRIBUTES: readonly string[];

const TASK_LABEL_ICONS: readonly ["pair", "group", "notebook"];

const TASK_LABEL_TAG: "astl-tag" = 'astl-tag';

const TASK_NUMBERING_ATTRIBUTE: "task-numbering" = 'task-numbering';

const TASK_NUMBERINGS: readonly ["page", "doc", "none"];

How the tasks of a document are numbered (task-numbering on astl-doc): on each page anew, through it, or not.


const TASK_TAG: "astl-task" = 'astl-task';

A task: a numbered exercise of a page, directly on a page, in the document, in a column or in a frame, never in another task (TASK_NESTED). astl-instruction (optional, first) holds inline text (formatting, a badge, a picture; no component); up to MAX_TASK_LABELS astl-tags after it, each a short label with an optional icon; then content as a page holds it, astl-subtasks among it (each a lettered part, a page's content in it, level A to D). Its id is required: its Check (check, one for all its graded questions) is addressed by it. Its number comes from the document's task-numbering (page, the default, doc or none), or its own number; the view always says the number it shows. level 1 to MAX_TASK_LEVEL is a difficulty mark; palette 1 to 8 colours the number.


const TEST_POLICY: AttemptPolicy;

const URL_ATTRIBUTES: Readonly<Record<string, string>>;

The attribute of a rich-text element that holds a URL, checked by the URL policy.

function allAttributes(manifest): readonly AttributeSpec[];

Every attribute an element of this type may carry, common ones first.

Parameter Type
manifest ComponentManifest

readonly AttributeSpec[]


function checkCatalog(catalog): CatalogProblem[];

Problems of catalog alone (syntax and plural coverage).

Parameter Type
catalog MessageCatalog

CatalogProblem[]


function checkFor(value): string[];

The ids a for names, in order, each once.

Parameter Type
value string | null | undefined

string[]


function checkNodes<T>(content, tree): T[];

The Check elements of a page's content (or a document's without pages) in the order checkParts meets them, so the nth is the one planChecks gives the nth targets: directly in the content, in its layouts' columns, in its frames and in its tasks and their sub-tasks, and a task with a Check of its own (taskCheck) after what it holds.

Type Parameter
T
Parameter Type
content readonly T[]
tree Pick<CheckTree<T>, "tag" | "children" | "taskCheck">

T[]


function checkParts<T>(content, tree): CheckPart[];

A page's content (or a document's without pages) as the parts of the check rule, in reading order: a layout's columns in turn, each between edges, and a frame's content between edges too (its title holds no question); so is a task's, each of its sub-tasks between edges, then its own Check when it has one (taskCheck), which names every graded question in the task. What lies between block components, checks, headings and edges is one run of text: its graded inline questions (none inside a component); a heading opens the next one.

Type Parameter
T
Parameter Type
content readonly T[]
tree CheckTree<T>

CheckPart[]


function childElements(node, tag?): ElementNode[];

Element children with the given tag, in order.

Parameter Type
node ElementNode
tag? string

ElementNode[]


function childTagConflict(manifests):
| {
components: readonly [string, string];
tag: string;
}
| null;

A child tag two of the manifests declare with specs that differ (see sameChildSpec), or null when none does.

Parameter Type
manifests readonly ComponentManifest[]

| { components: readonly [string, string]; tag: string; } | null


function compareCatalogs(source, translation): CatalogProblem[];

Problems of a translation compared with its source catalog (same namespace).

Parameter Type
source MessageCatalog
translation MessageCatalog

CatalogProblem[]


function createI18n(options): I18n;
Parameter Type
options CreateI18nOptions

I18n


function directionOf(lang): Direction;

Writing direction for a BCP 47 tag, e.g. he -> rtl, pl-PL -> ltr. Script subtags win (az-Arab).

Parameter Type
lang string

Direction


function element(
tag,
attrs?,
children?
): ElementNode;
Parameter Type Default value
tag string undefined
attrs? Readonly<Record<string, string>> {}
children? readonly Node[] []

ElementNode


function fitsAnswer(value, kind?): boolean;

Whether value is within the length limit of a slot of kind, counted in Unicode code points.

Parameter Type
value string
kind? string

boolean


function groupMax(
rule,
points,
slotCount
): number;

Group maximum for a rule.

Parameter Type
rule ScoringRule
points number
slotCount number

number


function hasErrors(issues): boolean;
Parameter Type
issues readonly Issue[]

boolean


function helpPolicy(policy): HelpPolicy;
Parameter Type
policy AttemptPolicy

HelpPolicy


function inertStyles(html): string;

The HTML with every style attribute under another name, for parsing. Under a strict CSP any HTML parser reports a style attribute as a violation the moment it meets one, in a template or a DOMParser document too (seen in Chromium on all of them), though nothing in those documents is ever drawn. Only start tags change, never text or values.

Parameter Type
html string

string


function isAnswerKey(value): value is AnswerKey;

Narrow check for keys loaded from storage. Full validation happens in the engine.

Parameter Type
value unknown

value is AnswerKey


function isAnswers(value): value is Readonly<Record<string, string>>;

Type guard for untrusted input (request bodies, storage).

Parameter Type
value unknown

value is Readonly<Record<string, string>>


function isAttemptPolicy(value): value is AttemptPolicy;
Parameter Type
value unknown

value is AttemptPolicy


function isCheckable(manifest): boolean;

A graded question: what a check can check (a graded type with something to answer).

Parameter Type
manifest ComponentManifest

boolean


function isElement(node, tag?): node is ElementNode;
Parameter Type
node Node | undefined
tag? string

node is ElementNode


function isOpaqueId(value): boolean;
Parameter Type
value string

boolean


function isProblemDetails(value): value is ProblemDetails;
Parameter Type
value unknown

value is ProblemDetails


function isSafeUrl(url): boolean;

The default URL policy: absolute http:, https: and mailto: URLs (tabs and newlines ignored, as browsers do).

Parameter Type
url string

boolean


function isSnapshot(value): value is Snapshot;
Parameter Type
value unknown

value is Snapshot


function isSourceId(value): boolean;
Parameter Type
value string

boolean


function isStyleTemplate(value): value is StyleTemplate;

Whether value has the shape of a StyleTemplate: a valid name, a positive version, one or both scopes, string tags, a namespace, and records of strings for tokens and parts. Registries use it for hosts without type checking.

Parameter Type
value unknown

value is StyleTemplate


function maxAnswerLength(kind): number;

The longest answer a slot of kind accepts, in code points: 2000 for open slots, 500 for the others.

Parameter Type
kind string | undefined

number


function messageParams(parts): Set<string>;

Names of all arguments a message uses, including plural and select selectors.

Parameter Type
parts readonly MessagePart[]

Set<string>


function negotiateLocale(
requested,
available,
fallback
): string;

BCP 47 lookup (RFC 4647 section 3.4, extended): for each requested tag try the tag, then shorter prefixes (pl-PL -> pl), then any available tag with the same language (pt -> pt-BR). Case-insensitive.

Parameter Type
requested readonly string[]
available readonly string[]
fallback string

string


function parseMessage(message): MessagePart[];
Parameter Type
message string

MessagePart[]


function planChecks(parts): CheckPlan;

The one rule for which questions a check takes, shared by the engine (what a view's checks hold), the authoring kit (its outline, the editor's tags and cards) and the player (where it checks several questions at once).

Parameter Type
parts readonly CheckPart[]

CheckPlan


function pluralCategories(locale, ordinal?): readonly string[];

Plural categories a locale needs, e.g. pl -> one, few, many, other.

Parameter Type Default value
locale string undefined
ordinal? boolean false

readonly string[]


function roundScore(value): number;

Rounds a score for display: at most 2 decimals, no trailing zeros.

Parameter Type
value number

number


function sameChildSpec(a, b): boolean;

Whether two child specs may share a tag: the same visibility and attributes (in any order), so the tag carries the same data and keeps the same things private in every type that declares it (astl-prompt, astl-option). Content and counts are each type's own: a select's options are plain text, a choice's options rich.

Parameter Type
a ChildSpec
b ChildSpec

boolean


function strictUrlPolicy(policy): UrlPolicy;

A host's URL policy as engines, players and the authoring kit use it: a URL passes only when the policy returns true. A policy that throws, or returns anything else (the Promise of an async function, say), blocks the URL.

Parameter Type
policy UrlPolicy

UrlPolicy


function text(value): TextNode;
Parameter Type
value string

TextNode


function textContent(node): string;

Concatenated text of a subtree, like DOM textContent.

Parameter Type
node Node

string


function variantAttribute(variants): AttributeSpec;

The variant attribute of a type with variants: an enum of the manifest's variant names.

Parameter Type
variants VariantSpec

AttributeSpec