@astl/engine 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/analyse.d.ts.map +1 -1
- package/dist/analyse.js +250 -11
- package/dist/analyse.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +4 -1
- package/dist/compile.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +16 -2
- package/dist/engine.js.map +1 -1
- package/dist/messages/en.json +2 -0
- package/dist/messages/pl.json +2 -0
- package/package.json +2 -2
- package/src/analyse.ts +276 -10
- package/src/compile.ts +4 -0
- package/src/engine.ts +23 -1
- package/src/messages/en.json +2 -0
- package/src/messages/pl.json +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @astl/engine
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 839e146: Frames: `<astl-box>` groups text and components under a title (a "work with the text" box, a review card, a project sheet), a format element like a layout, so it holds block components, which `astl-callout` cannot. It goes on a page, in the document or in a column; a frame in a frame is the new error `BOX_NESTED`, its content still checked, and it holds a layout only where it is not in a column. `<astl-box-title>` (optional, first) and `<astl-box-tag>` (optional, after it, an outlined label) hold text with formatting, a badge or a picture; then come blocks, components, layouts and Check elements. Its questions grade as outside it, and the Check of a question in it stays in it. `title-place` is `inside`, `border`, `pill` or `tab`; `variant` is `outline`, `soft` or `card`; `icon` is `info`, `tip`, `warning`, `book`, `pencil`, `checklist` or `star`; `palette` 1 to 8. The player draws it with the module of styles, from `boxCss` and `BOX_ICON_PATHS` in `@astl/tokens`: a title that wraps on a phone grows down into the frame, text on a filled title at 4.5:1, and with a title it is a region named by the title's words. In the editor, "Frame" (pl "Ramka") in the Layout menu inserts one with the cursor in its title; its style form (the new style target `frame`, and `frame()` and `editFrame()` of `EditorStyles`) sets its title position, look, icon, colour and tag, removes it keeping its content or deletes it; blocks move into it and out of it, and a block inserted in it stays in it. Also: a component manifest can no longer take the tag `astl-badge`, nor the frame's tags, which are the format's own.
|
|
8
|
+
- 9f84f15: Tasks: `<astl-task>` is a numbered exercise of a page, a format element like a frame: its number, its instruction (`<astl-instruction>`), up to 3 tags (`<astl-tag>`, with an optional `icon`: `pair`, `group`, `notebook`), its lettered sub-tasks (`<astl-subtask>`, with `level` A to D) and what a page holds. It goes on a page, in the document, in a column or in a frame; a task in a task is the new error `TASK_NESTED`, its content still checked. Its `id` is required. The document's `task-numbering` (`page`, the default, `doc` or `none`) and a task's own `number`, after which the next ones count on, give its number, which the engine writes into the view. `level` 1 to 3 is a difficulty mark (stars, said in words to screen readers), `palette` 1 to 8 the colour of its number. With `check` it has one Check for every graded question in it, at its end ("Check the task"): core's rule for Check elements takes it (`CheckTree.taskCheck`), and the view holds it as a Check element at the end of the task. The player draws it with the module of styles, from `taskCss`, `TASK_ICON_PATHS` and `TASK_MARK_PATH` in `@astl/tokens`: the number and the stars in a gutter, the tags in the instruction's row, the sub-tasks lettered; on a phone the number beside the instruction. It is a region named "Task 3" in the player's language, its instruction its description. In the editor, "Task" (pl "Zadanie") in the Layout menu inserts one with a fresh id (`insertTask(adapter)` for a host's menu), the cursor in its instruction; its card (the inspector) sets its number, difficulty, Check, colour and tags with their icons, and the document's card how tasks are numbered. On the surface its number and stars are drawn as the player draws them; blocks move into a task and its sub-tasks and out of them. `scanElements` lists tasks, and the outline's checks say which is a task's own (`OutlineCheck.task`).
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [839e146]
|
|
13
|
+
- Updated dependencies [9f84f15]
|
|
14
|
+
- @astl/core@0.6.0
|
|
15
|
+
|
|
3
16
|
## 0.5.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/analyse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../src/analyse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../src/analyse.ts"],"names":[],"mappings":"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"}
|
package/dist/analyse.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* One pass over a source that sanitises it and validates it against the registered manifests. `validate` and
|
|
3
3
|
* `compile` share it: compile only runs on an error-free analysis and works on the sanitised tree it returns.
|
|
4
4
|
*/
|
|
5
|
-
import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUPPORTED_FORMATS, TAG_ATTRIBUTES, URL_ATTRIBUTES, } from '@astl/core';
|
|
5
|
+
import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, BOX_ICONS, BOX_LABEL_TAG, BOX_TAG, BOX_TITLE_PLACES, BOX_TITLE_TAG, BOX_VARIANTS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, INSTRUCTION_TAG, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MAX_TASK_LABELS, MAX_TASK_LEVEL, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUBTASK_LEVELS, SUBTASK_TAG, SUPPORTED_FORMATS, TAG_ATTRIBUTES, TASK_LABEL_ICONS, TASK_LABEL_TAG, TASK_NUMBERING_ATTRIBUTE, TASK_NUMBERINGS, TASK_TAG, URL_ATTRIBUTES, } from '@astl/core';
|
|
6
6
|
import { cleanStyle, isStyleName, MAX_INLINED_STYLES, MAX_STYLE_LENGTH, MAX_STYLE_RULES, mergeStyles, overStyleColor, parseStyleColor, styleContrast, styleText, } from '@astl/core/declarations';
|
|
7
7
|
import { appendText, isHtmlWhitespace, parseSource } from './html.js';
|
|
8
8
|
import { isBooleanValue, parseDecimalValue, parseIntegerValue } from './kit/attributes.js';
|
|
@@ -29,6 +29,13 @@ const RULE_TARGETS = new Set([
|
|
|
29
29
|
FIGURE_TAG,
|
|
30
30
|
CAPTION_TAG,
|
|
31
31
|
BADGE_TAG,
|
|
32
|
+
BOX_TAG,
|
|
33
|
+
BOX_TITLE_TAG,
|
|
34
|
+
BOX_LABEL_TAG,
|
|
35
|
+
TASK_TAG,
|
|
36
|
+
INSTRUCTION_TAG,
|
|
37
|
+
TASK_LABEL_TAG,
|
|
38
|
+
SUBTASK_TAG,
|
|
32
39
|
]);
|
|
33
40
|
/** The contrast WCAG asks of normal text (AA); large text may have less, and then the warning is only stricter. */
|
|
34
41
|
const MIN_CONTRAST = 4.5;
|
|
@@ -54,7 +61,13 @@ function isBlank(nodes) {
|
|
|
54
61
|
return nodes.every((n) => n.type === 'text'
|
|
55
62
|
? n.value.trim() === ''
|
|
56
63
|
: n.tag === 'br' ||
|
|
57
|
-
((n.tag === 'p' ||
|
|
64
|
+
((n.tag === 'p' ||
|
|
65
|
+
n.tag === COLUMNS_TAG ||
|
|
66
|
+
n.tag === COLUMN_TAG ||
|
|
67
|
+
n.tag === BOX_TAG ||
|
|
68
|
+
n.tag === TASK_TAG ||
|
|
69
|
+
n.tag === SUBTASK_TAG) &&
|
|
70
|
+
isBlank(n.children)));
|
|
58
71
|
}
|
|
59
72
|
/**
|
|
60
73
|
* How a message names a page: by its number (from 1; 0 for the content of a document without pages) and its title when
|
|
@@ -70,7 +83,12 @@ function isSupportedFormat(value) {
|
|
|
70
83
|
function placementAllowed(display, scope) {
|
|
71
84
|
if (display === 'inline')
|
|
72
85
|
return !scope.inLink && TEXT_PARENTS.has(scope.parent);
|
|
73
|
-
return scope.parent === PAGE_TAG ||
|
|
86
|
+
return (scope.parent === PAGE_TAG ||
|
|
87
|
+
scope.parent === DOC_TAG ||
|
|
88
|
+
scope.parent === COLUMN_TAG ||
|
|
89
|
+
scope.parent === BOX_TAG ||
|
|
90
|
+
scope.parent === TASK_TAG ||
|
|
91
|
+
scope.parent === SUBTASK_TAG);
|
|
74
92
|
}
|
|
75
93
|
function outOfRange(value, spec) {
|
|
76
94
|
return (spec.min !== undefined && value < spec.min) || (spec.max !== undefined && value > spec.max);
|
|
@@ -132,6 +150,11 @@ class Analyser {
|
|
|
132
150
|
/** The help placed directly on each page, by page index. */
|
|
133
151
|
pageHelp = new Map();
|
|
134
152
|
explicitPages = false;
|
|
153
|
+
/** How the tasks are numbered (`task-numbering`), and the number of the last one so far. */
|
|
154
|
+
taskNumbering = 'page';
|
|
155
|
+
taskNumber = 0;
|
|
156
|
+
/** The tasks with a Check of their own, with their ids (their Check's). */
|
|
157
|
+
checkedTasks = new Map();
|
|
135
158
|
/** While help content is read (`visitHelp`): it takes no style (see `inline`). */
|
|
136
159
|
inHelp = false;
|
|
137
160
|
/** The components that declare each child tag, as listed in CHILD_OUTSIDE. */
|
|
@@ -213,6 +236,13 @@ class Analyser {
|
|
|
213
236
|
else
|
|
214
237
|
this.invalid(DOC_TAG, name, value, 'enum', DOC_KINDS, onRoot);
|
|
215
238
|
}
|
|
239
|
+
else if (name === TASK_NUMBERING_ATTRIBUTE) {
|
|
240
|
+
// The engine numbers the tasks into the view: the player needs no more of it.
|
|
241
|
+
if (TASK_NUMBERINGS.includes(value))
|
|
242
|
+
this.taskNumbering = value;
|
|
243
|
+
else
|
|
244
|
+
this.invalid(DOC_TAG, name, value, 'enum', TASK_NUMBERINGS, onRoot);
|
|
245
|
+
}
|
|
216
246
|
else {
|
|
217
247
|
attrs[name] = value;
|
|
218
248
|
if (name === STYLE_TEMPLATE_ATTRIBUTE)
|
|
@@ -235,6 +265,9 @@ class Analyser {
|
|
|
235
265
|
inLink: false,
|
|
236
266
|
mode: 'flow',
|
|
237
267
|
host: null,
|
|
268
|
+
box: null,
|
|
269
|
+
column: false,
|
|
270
|
+
task: false,
|
|
238
271
|
help: null,
|
|
239
272
|
page: null,
|
|
240
273
|
pageIndex: 0,
|
|
@@ -313,7 +346,7 @@ class Analyser {
|
|
|
313
346
|
const met = new Map(this.checkNodes.map((c) => [c.node, c]));
|
|
314
347
|
const named = new Map();
|
|
315
348
|
for (const { node, page, where } of this.checkNodes) {
|
|
316
|
-
const id = own(node.attrs, 'id') ?? '';
|
|
349
|
+
const id = this.checkedTasks.get(node) ?? own(node.attrs, 'id') ?? '';
|
|
317
350
|
if (own(node.attrs, CHECK_FOR_ATTRIBUTE) === undefined) {
|
|
318
351
|
named.set(node, null);
|
|
319
352
|
continue;
|
|
@@ -358,6 +391,7 @@ class Analyser {
|
|
|
358
391
|
};
|
|
359
392
|
},
|
|
360
393
|
checkFor: (node) => (node.type === 'element' ? (named.get(node) ?? null) : null),
|
|
394
|
+
taskCheck: (node) => node.type === 'element' && this.checkedTasks.has(node),
|
|
361
395
|
};
|
|
362
396
|
const pages = this.explicitPages ? [...pageNodes.keys()].map((page) => page.children) : [loose];
|
|
363
397
|
pages.forEach((content, index) => {
|
|
@@ -368,7 +402,7 @@ class Analyser {
|
|
|
368
402
|
const check = met.get(node);
|
|
369
403
|
if (check === undefined)
|
|
370
404
|
return;
|
|
371
|
-
const id = own(node.attrs, 'id') ?? '';
|
|
405
|
+
const id = this.checkedTasks.get(node) ?? own(node.attrs, 'id') ?? '';
|
|
372
406
|
for (const target of plan.twice[k] ?? []) {
|
|
373
407
|
this.add(EngineIssue.CHECK_TARGET_TWICE, { check: id, id: target }, check.where, 'warning');
|
|
374
408
|
}
|
|
@@ -616,6 +650,10 @@ class Analyser {
|
|
|
616
650
|
}
|
|
617
651
|
if (tag === BADGE_TAG)
|
|
618
652
|
return this.visitBadge(el, scope, place, where);
|
|
653
|
+
if (tag === BOX_TAG)
|
|
654
|
+
return this.visitBox(el, scope, place, where);
|
|
655
|
+
if (tag === TASK_TAG)
|
|
656
|
+
return this.visitTask(el, scope, place, where);
|
|
619
657
|
if (BLOCK_TAGS.has(tag) || INLINE_TAGS.has(tag)) {
|
|
620
658
|
if (scope.mode === 'text' || (scope.mode === 'inline' && BLOCK_TAGS.has(tag))) {
|
|
621
659
|
this.add(EngineIssue.ELEMENT_REMOVED, { tag }, where, 'warning');
|
|
@@ -649,6 +687,16 @@ class Analyser {
|
|
|
649
687
|
}
|
|
650
688
|
if (tag === COLUMNS_TAG)
|
|
651
689
|
return [this.visitColumns(el, scope, place, where)];
|
|
690
|
+
// A frame's title or tag, a task's instruction, tag or sub-task out of its place (after the content, twice,
|
|
691
|
+
// outside its frame or task): its content stays.
|
|
692
|
+
if (tag === BOX_TITLE_TAG ||
|
|
693
|
+
tag === BOX_LABEL_TAG ||
|
|
694
|
+
tag === INSTRUCTION_TAG ||
|
|
695
|
+
tag === TASK_LABEL_TAG ||
|
|
696
|
+
tag === SUBTASK_TAG) {
|
|
697
|
+
this.add(EngineIssue.PLACEMENT_INVALID, { tag }, where);
|
|
698
|
+
return this.visitNodes(el, scope, place.path);
|
|
699
|
+
}
|
|
652
700
|
// A column without its layout (`astl-match` has columns of its own, which it reads itself). The content stays,
|
|
653
701
|
// to be validated.
|
|
654
702
|
if (tag === COLUMN_TAG && !(host && spec)) {
|
|
@@ -676,6 +724,9 @@ class Analyser {
|
|
|
676
724
|
scope.help === null &&
|
|
677
725
|
(scope.parent === PAGE_TAG ||
|
|
678
726
|
scope.parent === COLUMN_TAG ||
|
|
727
|
+
scope.parent === BOX_TAG ||
|
|
728
|
+
scope.parent === TASK_TAG ||
|
|
729
|
+
scope.parent === SUBTASK_TAG ||
|
|
679
730
|
(scope.parent === DOC_TAG && !this.explicitPages));
|
|
680
731
|
if (!onPage) {
|
|
681
732
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag: CHECK_TAG }, where);
|
|
@@ -713,7 +764,13 @@ class Analyser {
|
|
|
713
764
|
visitBadge(el, scope, place, where) {
|
|
714
765
|
const id = own(el.attrs, 'id');
|
|
715
766
|
const at = { ...where, element: id ?? null };
|
|
716
|
-
const inText = TEXT_PARENTS.has(scope.parent)
|
|
767
|
+
const inText = (TEXT_PARENTS.has(scope.parent) ||
|
|
768
|
+
scope.parent === BOX_TITLE_TAG ||
|
|
769
|
+
scope.parent === BOX_LABEL_TAG ||
|
|
770
|
+
scope.parent === INSTRUCTION_TAG ||
|
|
771
|
+
scope.parent === TASK_LABEL_TAG) &&
|
|
772
|
+
!scope.inLink &&
|
|
773
|
+
scope.mode !== 'text';
|
|
717
774
|
if (!inText || (scope.host !== null && scope.mode !== 'flow')) {
|
|
718
775
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag: BADGE_TAG }, at);
|
|
719
776
|
return this.visitNodes(el, scope, place.path);
|
|
@@ -766,6 +823,176 @@ class Analyser {
|
|
|
766
823
|
};
|
|
767
824
|
return element(el.tag, attrs, this.visitNodes(el, inner, place.path));
|
|
768
825
|
}
|
|
826
|
+
/**
|
|
827
|
+
* A frame: directly on a page, in the document without pages or in a column, outside components and help; in another
|
|
828
|
+
* frame it is `BOX_NESTED`, elsewhere `PLACEMENT_INVALID`, and its content is validated where it stands. Its title and
|
|
829
|
+
* its tag lead it, inline text without components (a badge, a picture); then content as a page holds it.
|
|
830
|
+
*/
|
|
831
|
+
visitBox(el, scope, place, where) {
|
|
832
|
+
if (scope.box !== null) {
|
|
833
|
+
this.add(EngineIssue.BOX_NESTED, { tag: BOX_TAG }, where);
|
|
834
|
+
return this.visitNodes(el, scope, place.path);
|
|
835
|
+
}
|
|
836
|
+
const placed = scope.host === null &&
|
|
837
|
+
scope.help === null &&
|
|
838
|
+
scope.mode === 'flow' &&
|
|
839
|
+
(scope.parent === PAGE_TAG ||
|
|
840
|
+
scope.parent === COLUMN_TAG ||
|
|
841
|
+
scope.parent === TASK_TAG ||
|
|
842
|
+
scope.parent === SUBTASK_TAG ||
|
|
843
|
+
(scope.parent === DOC_TAG && !this.explicitPages));
|
|
844
|
+
if (!placed) {
|
|
845
|
+
this.add(EngineIssue.PLACEMENT_INVALID, { tag: BOX_TAG }, where);
|
|
846
|
+
return this.visitNodes(el, scope, place.path);
|
|
847
|
+
}
|
|
848
|
+
const attrs = this.richAttributes(el, where, scope);
|
|
849
|
+
const allowed = {
|
|
850
|
+
'title-place': BOX_TITLE_PLACES,
|
|
851
|
+
variant: BOX_VARIANTS,
|
|
852
|
+
icon: BOX_ICONS,
|
|
853
|
+
};
|
|
854
|
+
for (const [name, values] of [...Object.entries(allowed), ['palette', null]]) {
|
|
855
|
+
const value = own(attrs, name);
|
|
856
|
+
if (value === undefined)
|
|
857
|
+
continue;
|
|
858
|
+
const palette = parseIntegerValue(value);
|
|
859
|
+
const valid = values === null
|
|
860
|
+
? palette !== null && palette >= 1 && palette <= MAX_BADGE_PALETTE
|
|
861
|
+
: values.includes(value);
|
|
862
|
+
if (valid)
|
|
863
|
+
continue;
|
|
864
|
+
this.invalid(BOX_TAG, name, value, values === null ? 'integer' : 'enum', values ?? [], where);
|
|
865
|
+
delete attrs[name];
|
|
866
|
+
}
|
|
867
|
+
const inner = {
|
|
868
|
+
...scope,
|
|
869
|
+
...this.below(attrs, scope),
|
|
870
|
+
parent: BOX_TAG,
|
|
871
|
+
box: scope.column ? 'column' : 'top',
|
|
872
|
+
};
|
|
873
|
+
// The title, then the tag, may only lead: before the first content (text or any other element).
|
|
874
|
+
const content = el.children.findIndex((n) => n.type === 'text' ? !isHtmlWhitespace(n.value) : n.tag !== BOX_TITLE_TAG && n.tag !== BOX_LABEL_TAG);
|
|
875
|
+
let led = '';
|
|
876
|
+
const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
|
|
877
|
+
const head = child.tag === BOX_TITLE_TAG || child.tag === BOX_LABEL_TAG;
|
|
878
|
+
const leads = content === -1 || el.children.indexOf(child) < content;
|
|
879
|
+
const order = child.tag === BOX_TITLE_TAG ? led === '' : led !== BOX_LABEL_TAG;
|
|
880
|
+
if (!head || !leads || !order)
|
|
881
|
+
return this.visitElement(child, inner, childPlace);
|
|
882
|
+
led = child.tag;
|
|
883
|
+
const at = this.where(inner, childPlace, child.tag);
|
|
884
|
+
const headAttrs = this.richAttributes(child, at, inner);
|
|
885
|
+
const text = { ...inner, ...this.below(headAttrs, inner), parent: child.tag, mode: 'inline' };
|
|
886
|
+
return [element(child.tag, headAttrs, this.visitNodes(child, text, childPlace.path))];
|
|
887
|
+
});
|
|
888
|
+
return [element(BOX_TAG, attrs, children)];
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* A task: directly on a page, in the document without pages, in a column or in a frame, outside components and help;
|
|
892
|
+
* in another task it is `TASK_NESTED`, elsewhere `PLACEMENT_INVALID`, and its content is validated where it stands.
|
|
893
|
+
* Its id is required: its Check is addressed by it. Its instruction, then its tags (up to MAX_TASK_LABELS), may only
|
|
894
|
+
* lead it; out of place, each is `PLACEMENT_INVALID` and its text stays. Then a page's content, its sub-tasks among
|
|
895
|
+
* it. The view has its number: its own `number`, after which the next ones count on, else the next of its page or of
|
|
896
|
+
* the document (`task-numbering`), none with `none`. A task with `check` has a Check of its own for all its graded
|
|
897
|
+
* questions, which the view holds as a Check element at its end.
|
|
898
|
+
*/
|
|
899
|
+
visitTask(el, scope, place, where) {
|
|
900
|
+
const id = own(el.attrs, 'id');
|
|
901
|
+
const at = { ...where, element: id ?? null };
|
|
902
|
+
if (scope.task) {
|
|
903
|
+
// One error for the task: its head's content and its sub-tasks stay, as the outer task's.
|
|
904
|
+
this.add(EngineIssue.TASK_NESTED, { tag: TASK_TAG }, at);
|
|
905
|
+
return this.visitNodes(el, scope, place.path, (child, childPlace) => child.tag === SUBTASK_TAG
|
|
906
|
+
? [this.visitSubtask(child, scope, childPlace)]
|
|
907
|
+
: child.tag === INSTRUCTION_TAG || child.tag === TASK_LABEL_TAG
|
|
908
|
+
? this.visitNodes(child, scope, childPlace.path)
|
|
909
|
+
: null);
|
|
910
|
+
}
|
|
911
|
+
const placed = scope.host === null &&
|
|
912
|
+
scope.help === null &&
|
|
913
|
+
scope.mode === 'flow' &&
|
|
914
|
+
(scope.parent === PAGE_TAG ||
|
|
915
|
+
scope.parent === COLUMN_TAG ||
|
|
916
|
+
scope.parent === BOX_TAG ||
|
|
917
|
+
(scope.parent === DOC_TAG && !this.explicitPages));
|
|
918
|
+
if (!placed) {
|
|
919
|
+
this.add(EngineIssue.PLACEMENT_INVALID, { tag: TASK_TAG }, at);
|
|
920
|
+
return this.visitNodes(el, scope, place.path);
|
|
921
|
+
}
|
|
922
|
+
if (id === undefined)
|
|
923
|
+
this.add(EngineIssue.ID_MISSING, { tag: TASK_TAG }, at);
|
|
924
|
+
else
|
|
925
|
+
this.sourceId(id, TASK_TAG, at);
|
|
926
|
+
const attrs = this.richAttributes(element(TASK_TAG, Object.fromEntries(Object.entries(el.attrs).filter(([name]) => name !== 'id')), []), at, scope);
|
|
927
|
+
const bounded = (name, max) => {
|
|
928
|
+
const value = own(attrs, name);
|
|
929
|
+
if (value === undefined)
|
|
930
|
+
return null;
|
|
931
|
+
const n = parseIntegerValue(value);
|
|
932
|
+
if (n !== null && n >= 1 && n <= max)
|
|
933
|
+
return n;
|
|
934
|
+
this.invalid(TASK_TAG, name, value, 'integer', [], at);
|
|
935
|
+
delete attrs[name];
|
|
936
|
+
return null;
|
|
937
|
+
};
|
|
938
|
+
bounded('level', MAX_TASK_LEVEL);
|
|
939
|
+
bounded('palette', MAX_BADGE_PALETTE);
|
|
940
|
+
const written = bounded('number', Number.MAX_SAFE_INTEGER);
|
|
941
|
+
// A boolean: present or not, whatever its value. The view holds the Check itself, at the end of the task.
|
|
942
|
+
const check = Object.hasOwn(attrs, 'check');
|
|
943
|
+
delete attrs.check;
|
|
944
|
+
if (written !== null)
|
|
945
|
+
this.taskNumber = written;
|
|
946
|
+
else if (this.taskNumbering !== 'none')
|
|
947
|
+
this.taskNumber += 1;
|
|
948
|
+
if (written !== null || this.taskNumbering !== 'none')
|
|
949
|
+
attrs.number = String(this.taskNumber);
|
|
950
|
+
const inner = { ...scope, ...this.below(attrs, scope), parent: TASK_TAG, task: true };
|
|
951
|
+
// The instruction, then the tags, may only lead: before the first content (text or any other element).
|
|
952
|
+
const content = el.children.findIndex((n) => n.type === 'text' ? !isHtmlWhitespace(n.value) : n.tag !== INSTRUCTION_TAG && n.tag !== TASK_LABEL_TAG);
|
|
953
|
+
let led = false;
|
|
954
|
+
let labels = 0;
|
|
955
|
+
const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
|
|
956
|
+
if (child.tag === SUBTASK_TAG)
|
|
957
|
+
return [this.visitSubtask(child, inner, childPlace)];
|
|
958
|
+
const head = child.tag === INSTRUCTION_TAG || child.tag === TASK_LABEL_TAG;
|
|
959
|
+
const leads = content === -1 || el.children.indexOf(child) < content;
|
|
960
|
+
const order = child.tag === INSTRUCTION_TAG ? !led : labels < MAX_TASK_LABELS;
|
|
961
|
+
if (!head || !leads || !order)
|
|
962
|
+
return this.visitElement(child, inner, childPlace);
|
|
963
|
+
led = true;
|
|
964
|
+
const where = this.where(inner, childPlace, child.tag);
|
|
965
|
+
const headAttrs = this.richAttributes(child, where, inner);
|
|
966
|
+
if (child.tag === TASK_LABEL_TAG) {
|
|
967
|
+
labels++;
|
|
968
|
+
const icon = own(headAttrs, 'icon');
|
|
969
|
+
if (icon !== undefined && !TASK_LABEL_ICONS.includes(icon)) {
|
|
970
|
+
this.invalid(TASK_LABEL_TAG, 'icon', icon, 'enum', TASK_LABEL_ICONS, where);
|
|
971
|
+
delete headAttrs.icon;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
const text = { ...inner, ...this.below(headAttrs, inner), parent: child.tag, mode: 'inline' };
|
|
975
|
+
return [element(child.tag, headAttrs, this.visitNodes(child, text, childPlace.path))];
|
|
976
|
+
});
|
|
977
|
+
const node = element(TASK_TAG, attrs, children);
|
|
978
|
+
if (check) {
|
|
979
|
+
this.checkNodes.push({ node, page: scope.pageIndex, where: at });
|
|
980
|
+
this.checkedTasks.set(node, id ?? '');
|
|
981
|
+
}
|
|
982
|
+
return [node];
|
|
983
|
+
}
|
|
984
|
+
/** A sub-task: a lettered part of a task, a page's content in it; its `level`, A to D, shows beside its letter. */
|
|
985
|
+
visitSubtask(el, scope, place) {
|
|
986
|
+
const where = this.where(scope, place, SUBTASK_TAG);
|
|
987
|
+
const attrs = this.richAttributes(el, where, scope);
|
|
988
|
+
const level = own(attrs, 'level');
|
|
989
|
+
if (level !== undefined && !SUBTASK_LEVELS.includes(level)) {
|
|
990
|
+
this.invalid(SUBTASK_TAG, 'level', level, 'enum', SUBTASK_LEVELS, where);
|
|
991
|
+
delete attrs.level;
|
|
992
|
+
}
|
|
993
|
+
const inner = { ...scope, ...this.below(attrs, scope), parent: SUBTASK_TAG };
|
|
994
|
+
return element(SUBTASK_TAG, attrs, this.visitNodes(el, inner, place.path));
|
|
995
|
+
}
|
|
769
996
|
/**
|
|
770
997
|
* A layout: 2 to 4 columns, directly on a page or in the document, outside components. Whatever its shape, its
|
|
771
998
|
* content is still validated, each piece as what it is.
|
|
@@ -782,12 +1009,19 @@ class Analyser {
|
|
|
782
1009
|
}
|
|
783
1010
|
columns++;
|
|
784
1011
|
const column = this.richAttributes(child, this.where(inner, childPlace, COLUMN_TAG), inner);
|
|
785
|
-
const content = { ...inner, ...this.below(column, inner), parent: COLUMN_TAG };
|
|
1012
|
+
const content = { ...inner, ...this.below(column, inner), parent: COLUMN_TAG, column: true };
|
|
786
1013
|
return [element(COLUMN_TAG, column, this.visitNodes(child, content, childPlace.path))];
|
|
787
1014
|
});
|
|
788
1015
|
if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value)))
|
|
789
1016
|
stray = true;
|
|
790
|
-
|
|
1017
|
+
// In a frame or a task too, never in a column, however deep: two layout levels at most.
|
|
1018
|
+
const placed = scope.host === null &&
|
|
1019
|
+
!scope.column &&
|
|
1020
|
+
(scope.parent === PAGE_TAG ||
|
|
1021
|
+
scope.parent === DOC_TAG ||
|
|
1022
|
+
scope.parent === BOX_TAG ||
|
|
1023
|
+
scope.parent === TASK_TAG ||
|
|
1024
|
+
scope.parent === SUBTASK_TAG);
|
|
791
1025
|
if (!placed || stray || columns < MIN_COLUMNS || columns > MAX_COLUMNS) {
|
|
792
1026
|
this.add(EngineIssue.COLUMNS_INVALID, { tag: COLUMNS_TAG }, where);
|
|
793
1027
|
}
|
|
@@ -840,13 +1074,16 @@ class Analyser {
|
|
|
840
1074
|
return attrs;
|
|
841
1075
|
}
|
|
842
1076
|
/**
|
|
843
|
-
* A figure: directly in a page, a column or the document (a block), or in a rich block, with exactly one picture
|
|
844
|
-
* one caption. A caption holds rich inline text, which may hold inline components like any text.
|
|
1077
|
+
* A figure: directly in a page, a column, a frame or the document (a block), or in a rich block, with exactly one picture
|
|
1078
|
+
* and at most one caption. A caption holds rich inline text, which may hold inline components like any text.
|
|
845
1079
|
*/
|
|
846
1080
|
visitFigure(el, scope, place, where) {
|
|
847
1081
|
if (scope.parent !== PAGE_TAG &&
|
|
848
1082
|
scope.parent !== DOC_TAG &&
|
|
849
1083
|
scope.parent !== COLUMN_TAG &&
|
|
1084
|
+
scope.parent !== BOX_TAG &&
|
|
1085
|
+
scope.parent !== TASK_TAG &&
|
|
1086
|
+
scope.parent !== SUBTASK_TAG &&
|
|
850
1087
|
scope.parent !== scope.host?.manifest.tag &&
|
|
851
1088
|
!HELP_TAGS.has(scope.parent)) {
|
|
852
1089
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag: el.tag }, where);
|
|
@@ -913,6 +1150,8 @@ class Analyser {
|
|
|
913
1150
|
pageIndex: index,
|
|
914
1151
|
pageName: namePage(index + 1, own(el.attrs, 'label')),
|
|
915
1152
|
};
|
|
1153
|
+
if (this.taskNumbering === 'page')
|
|
1154
|
+
this.taskNumber = 0;
|
|
916
1155
|
const children = this.visitNodes(el, scope, place.path);
|
|
917
1156
|
if (isBlank(children))
|
|
918
1157
|
this.add(EngineIssue.PAGE_EMPTY, scope.pageName, where, 'warning');
|
|
@@ -1108,7 +1347,7 @@ class Analyser {
|
|
|
1108
1347
|
else if (child.tag === COLUMNS_TAG || child.tag === COLUMN_TAG) {
|
|
1109
1348
|
this.add(EngineIssue.COLUMNS_INVALID, { tag: child.tag }, where);
|
|
1110
1349
|
}
|
|
1111
|
-
else if (child.tag === STYLE_TAG) {
|
|
1350
|
+
else if (child.tag === STYLE_TAG || child.tag === BOX_TAG || child.tag === TASK_TAG) {
|
|
1112
1351
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag: child.tag }, where);
|
|
1113
1352
|
}
|
|
1114
1353
|
else if (child.tag.includes('-') && child.tag !== DOC_TAG && child.tag !== PAGE_TAG) {
|