@altnovatrail/canvas 0.3.8 → 0.3.9
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/lib/element/index.js +7 -7
- package/lib/element/labels.d.ts +19 -5
- package/lib/element/labels.js +41 -10
- package/lib/element/parts.js +2 -2
- package/package.json +1 -1
package/lib/element/index.js
CHANGED
|
@@ -52,7 +52,7 @@ import { cellsForCheck, workForCheck } from "../core/submission.js";
|
|
|
52
52
|
import { isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
53
53
|
import { nextIdOf, resumeOf, Work } from "../core/work.js";
|
|
54
54
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
55
|
-
import { labelsFor } from "./labels.js";
|
|
55
|
+
import { labelsFor, say } from "./labels.js";
|
|
56
56
|
import { Parts } from "./parts.js";
|
|
57
57
|
import { Pictures } from "./pictures.js";
|
|
58
58
|
import { attachProbe } from "./probe.js";
|
|
@@ -850,9 +850,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
850
850
|
#nameBoxes(tag = this.getAttribute("lang")) {
|
|
851
851
|
const { lang, labels } = labelsFor(tag);
|
|
852
852
|
this.#parts.fillWords = (part) => {
|
|
853
|
-
const name =
|
|
853
|
+
const name = say(labels.boxIn, { line: part.fill.line, slot: part.fill.box });
|
|
854
854
|
const value = this.#example === undefined ? "" : fillValue(this.#example, part);
|
|
855
|
-
return { number: value === "" ? name :
|
|
855
|
+
return { number: value === "" ? name : say(labels.valued, { name, value }), lang };
|
|
856
856
|
};
|
|
857
857
|
}
|
|
858
858
|
/**
|
|
@@ -1068,13 +1068,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1068
1068
|
continue;
|
|
1069
1069
|
const several = (this.#laid?.items[cell.item - 1]?.boxes.length ?? 0) > 1;
|
|
1070
1070
|
const filled = this.#filled?.[cell.item - 1]?.[cell.slot - 1] === true;
|
|
1071
|
-
const name = several ?
|
|
1071
|
+
const name = several ? say(labels.boxAt, { slot: cell.slot }) : labels.box;
|
|
1072
1072
|
// A worked example's box says what its demo wrote in it: the text itself says nothing.
|
|
1073
1073
|
const value = this.#fills.get(`${cell.item}.${cell.slot}`);
|
|
1074
1074
|
rect.classList.toggle("filled", filled);
|
|
1075
|
-
let label = filled ?
|
|
1075
|
+
let label = filled ? say(labels.filled, { name }) : name;
|
|
1076
1076
|
if (value !== undefined)
|
|
1077
|
-
label =
|
|
1077
|
+
label = say(labels.valued, { name, value });
|
|
1078
1078
|
write(rect, "aria-label", label);
|
|
1079
1079
|
write(rect, "lang", lang);
|
|
1080
1080
|
}
|
|
@@ -1545,7 +1545,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1545
1545
|
if (target !== undefined)
|
|
1546
1546
|
this.#bringIntoSight(target);
|
|
1547
1547
|
const { lang, labels } = labelsFor(this.getAttribute("lang"));
|
|
1548
|
-
const number =
|
|
1548
|
+
const number = say(labels.part, { n: opened, total: example.demo.length });
|
|
1549
1549
|
this.#parts.tell(part, { number, lang });
|
|
1550
1550
|
this.#demoChanged();
|
|
1551
1551
|
}
|
package/lib/element/labels.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What the element says: the row of buttons its own name — the canvas kind's, or a worked
|
|
3
3
|
* example's — the name of the group of tools and each button, a workbook's box its name, and the
|
|
4
|
-
* number of a part of a demo the element tells of.
|
|
4
|
+
* number of a part of a demo the element tells of. A label with places names them in braces.
|
|
5
5
|
*/
|
|
6
6
|
export interface Labels {
|
|
7
7
|
readonly sheet: string;
|
|
@@ -21,14 +21,21 @@ export interface Labels {
|
|
|
21
21
|
readonly down: string;
|
|
22
22
|
/** The button that lets a finger write again, in pen mode (R29). */
|
|
23
23
|
readonly finger: string;
|
|
24
|
-
/** A box of a workbook's line,
|
|
24
|
+
/** A box of a workbook's line, alone in it (R36). */
|
|
25
25
|
readonly box: string;
|
|
26
|
-
/**
|
|
26
|
+
/** A box among several of its line, by its slot: {slot} (R36). */
|
|
27
|
+
readonly boxAt: string;
|
|
28
|
+
/** A box a demo fills, by its line and its slot in it: {line} and {slot} (R42). */
|
|
29
|
+
readonly boxIn: string;
|
|
30
|
+
/** A box's {name} when the box is filled (R37). */
|
|
27
31
|
readonly filled: string;
|
|
28
|
-
/**
|
|
32
|
+
/** A box's {name} and the {value} a demo wrote in it (R42). */
|
|
33
|
+
readonly valued: string;
|
|
34
|
+
/** The part of a demo the element tells of, {n}, of so many, {total} (R42). */
|
|
29
35
|
readonly part: string;
|
|
30
|
-
readonly of: string;
|
|
31
36
|
}
|
|
37
|
+
/** Every language the table has, by its tag: the tests hold each to English's places. */
|
|
38
|
+
export declare const LANGUAGES: readonly string[];
|
|
32
39
|
/**
|
|
33
40
|
* The labels for a language tag, and the language they are in. The tag is looked up as RFC 4647,
|
|
34
41
|
* section 3.4, does it: in lower case, cut subtag by subtag from its end until the table has what
|
|
@@ -39,3 +46,10 @@ export declare function labelsFor(tag: string | null): {
|
|
|
39
46
|
readonly lang: string;
|
|
40
47
|
readonly labels: Labels;
|
|
41
48
|
};
|
|
49
|
+
/** The places a label names, each once, in the order it names them. */
|
|
50
|
+
export declare function placesOf(label: string): string[];
|
|
51
|
+
/**
|
|
52
|
+
* A label with its places filled by name. A place the values do not give is a TypeError: a label
|
|
53
|
+
* never shows its braces.
|
|
54
|
+
*/
|
|
55
|
+
export declare function say(label: string, values: Readonly<Record<string, string | number>>): string;
|
package/lib/element/labels.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
// The labels of the element's own buttons, of a workbook's boxes and of the parts of a worked
|
|
2
|
-
// example's demo, in the languages of
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// example's demo, in the languages of the interface, English and Russian (R92 spec), by the shared
|
|
3
|
+
// rules of the packages' translations (R91 spec; R28, R29, R33, R36, R37, R42; T91 in RUN.md):
|
|
4
|
+
// - the language is the element's own `lang`, looked up as RFC 4647 does it, and English stands for
|
|
5
|
+
// any other, under a `lang` of its own;
|
|
6
|
+
// - a label with a number or a word in it is one string with named places, «Часть {n} из {total}.»,
|
|
7
|
+
// never pieces glued together: languages put their words in other orders;
|
|
8
|
+
// - no label counts a thing, so none has forms of number yet. The first that does takes CLDR's
|
|
9
|
+
// categories, `other` always among them, chosen by `Intl.PluralRules` of the label's language;
|
|
10
|
+
// - no label tells the learner's gender (R70 spec) or speaks as the AI in the first person (П-15);
|
|
11
|
+
// - the buttons' words are those of the table of words of architecture 6 spec.
|
|
12
|
+
// This module is no entry point of the package.
|
|
6
13
|
/** The labels in English, the code's own language: those of any language the table has not. */
|
|
7
14
|
const ENGLISH = Object.freeze({
|
|
8
15
|
sheet: "Sheet",
|
|
@@ -19,9 +26,11 @@ const ENGLISH = Object.freeze({
|
|
|
19
26
|
down: "Down",
|
|
20
27
|
finger: "Draw with finger",
|
|
21
28
|
box: "Box",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
boxAt: "Box {slot}",
|
|
30
|
+
boxIn: "Box {line}.{slot}",
|
|
31
|
+
filled: "{name}, filled",
|
|
32
|
+
valued: "{name}: {value}",
|
|
33
|
+
part: "Part {n} of {total}.",
|
|
25
34
|
});
|
|
26
35
|
/**
|
|
27
36
|
* The labels by language, each a language tag in lower case. A map, not an object: a tag such as
|
|
@@ -46,12 +55,16 @@ const LABELS = new Map([
|
|
|
46
55
|
down: "Ниже",
|
|
47
56
|
finger: "Рисовать пальцем",
|
|
48
57
|
box: "Окошко",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
boxAt: "Окошко {slot}",
|
|
59
|
+
boxIn: "Окошко {line}.{slot}",
|
|
60
|
+
filled: "{name}, заполнено",
|
|
61
|
+
valued: "{name}: {value}",
|
|
62
|
+
part: "Часть {n} из {total}.",
|
|
52
63
|
}),
|
|
53
64
|
],
|
|
54
65
|
]);
|
|
66
|
+
/** Every language the table has, by its tag: the tests hold each to English's places. */
|
|
67
|
+
export const LANGUAGES = [...LABELS.keys()];
|
|
55
68
|
/**
|
|
56
69
|
* The labels for a language tag, and the language they are in. The tag is looked up as RFC 4647,
|
|
57
70
|
* section 3.4, does it: in lower case, cut subtag by subtag from its end until the table has what
|
|
@@ -72,3 +85,21 @@ export function labelsFor(tag) {
|
|
|
72
85
|
}
|
|
73
86
|
return { lang: "en", labels: ENGLISH };
|
|
74
87
|
}
|
|
88
|
+
/** A place of a label: a name of Latin letters, digits and underscores in braces. */
|
|
89
|
+
const PLACE = /\{(\w+)\}/g;
|
|
90
|
+
/** The places a label names, each once, in the order it names them. */
|
|
91
|
+
export function placesOf(label) {
|
|
92
|
+
return [...new Set([...label.matchAll(PLACE)].map(([, name]) => String(name)))];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A label with its places filled by name. A place the values do not give is a TypeError: a label
|
|
96
|
+
* never shows its braces.
|
|
97
|
+
*/
|
|
98
|
+
export function say(label, values) {
|
|
99
|
+
return label.replace(PLACE, (_, name) => {
|
|
100
|
+
const value = Object.hasOwn(values, name) ? values[name] : undefined;
|
|
101
|
+
if (value === undefined)
|
|
102
|
+
throw new TypeError(`the label "${label}" has no value for {${name}}`);
|
|
103
|
+
return String(value);
|
|
104
|
+
});
|
|
105
|
+
}
|
package/lib/element/parts.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { isFill, onSheet, } from "../core/example.js";
|
|
13
13
|
import { SHEET } from "../core/sheet.js";
|
|
14
14
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
15
|
-
import { labelsFor } from "./labels.js";
|
|
15
|
+
import { labelsFor, say } from "./labels.js";
|
|
16
16
|
import { framed } from "./statement.js";
|
|
17
17
|
/** The list of a demo's open parts and the region that tells of them, as the element shows them. */
|
|
18
18
|
export class Parts {
|
|
@@ -48,7 +48,7 @@ export class Parts {
|
|
|
48
48
|
*/
|
|
49
49
|
#fillWords = ({ fill }) => {
|
|
50
50
|
const { lang, labels } = labelsFor(null);
|
|
51
|
-
return { number:
|
|
51
|
+
return { number: say(labels.boxIn, { line: fill.line, slot: fill.box }), lang };
|
|
52
52
|
};
|
|
53
53
|
/** What a part that fills a box says from now on, the items already open too. */
|
|
54
54
|
set fillWords(words) {
|