@altnovatrail/canvas 0.3.20 → 0.3.22
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/README.md +1 -1
- package/lib/core/page.d.ts +12 -1
- package/lib/core/page.js +15 -12
- package/lib/element/attributes.d.ts +4 -1
- package/lib/element/attributes.js +4 -1
- package/lib/element/index.js +28 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ The file opens with a comment that says what it is and holds the license notices
|
|
|
70
70
|
- `tasks/` — the file of open tasks of a release of tutor that the synthetic samples answer, as the release has it, with its signature, which spec's `release-verify` checks in CI; and the index of a release of modules, signed too, with the inventory and canonical view of two packages it names: grade-3-math, on which CI writes the samples of a module's eval set, and english-essays, whose essays and choices the tests hold to the digests of their open views that module-kit gives.
|
|
71
71
|
- `licenses.json` — the packages the license check accepts by name, each with why.
|
|
72
72
|
|
|
73
|
-
`just build` builds the package into `lib/`, and `just release-files v0.1.0` writes the files of that release into `dist/` — the package's archive, with NOTICE in it, the synthetic samples' archive and the list of what each shows, the samples page, the generator of a module's eval set, LICENSE and SHA256SUMS — and prints the sums, which a build of the same commit gives again. `just synthetic <folder>` writes the synthetic samples into a folder, one file each, and prints what each shows: no tree holds them. `just synthetic-module <package> <tag> <folder> <task>:<seed>...` writes synthetic samples of a module's eval set, by the same file a release carries, built from the tree: to write what a release's file writes in a module's CI, run that file, or the recipe in a clone of canvas at its tag, with the package that `module-kit build` wrote of the module at the commit the samples go into, the tag of the newest release of modules, and the module's `eval/` folder; it writes `synthetic-<seed>.json` for each task and seed named, writes a seed's file anew only when it is a sample of the same task, and refuses a template, a choice, an essay or a zone, writing nothing then. `just ci` runs the checks CI runs: format, lint and types; the tests in Node and in Chromium; advisories; licenses. They run in the devcontainer, whose toolchain stage holds the
|
|
73
|
+
`just build` builds the package into `lib/`, and `just release-files v0.1.0` writes the files of that release into `dist/` — the package's archive, with NOTICE in it, the synthetic samples' archive and the list of what each shows, the samples page, the generator of a module's eval set, LICENSE and SHA256SUMS — and prints the sums, which a build of the same commit gives again. `just synthetic <folder>` writes the synthetic samples into a folder, one file each, and prints what each shows: no tree holds them. `just synthetic-module <package> <tag> <folder> <task>:<seed>...` writes synthetic samples of a module's eval set, by the same file a release carries, built from the tree: to write what a release's file writes in a module's CI, run that file, or the recipe in a clone of canvas at its tag, with the package that `module-kit build` wrote of the module at the commit the samples go into, the tag of the newest release of modules, and the module's `eval/` folder; it writes `synthetic-<seed>.json` for each task and seed named, writes a seed's file anew only when it is a sample of the same task, and refuses a template, a choice, an essay or a zone, writing nothing then. `just ci` runs the checks CI runs: format, lint and types; the tests in Node and in Chromium; the tests in WebKit and Firefox; advisories; licenses. They run in the devcontainer, whose toolchain stage holds the browsers the tests run in. The license check is spec's recipe, run from the `spec/` submodule with the exceptions in `licenses.json`, so it needs `spec/` checked out: see [CLAUDE.md](CLAUDE.md), Environment.
|
|
74
74
|
|
|
75
75
|
## Documents
|
|
76
76
|
|
package/lib/core/page.d.ts
CHANGED
|
@@ -39,8 +39,19 @@ export interface PageBox {
|
|
|
39
39
|
readonly width: number;
|
|
40
40
|
readonly height: number;
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* An item on the page: its place and size, its number, its line in the order it is read, and its
|
|
44
|
+
* boxes by slot.
|
|
45
|
+
*/
|
|
43
46
|
export interface PageItem {
|
|
47
|
+
/**
|
|
48
|
+
* Its place and size, in page units: its column's left edge, its row's top, its column's width or
|
|
49
|
+
* the page's within its margins, and the height of its lines.
|
|
50
|
+
*/
|
|
51
|
+
readonly left: number;
|
|
52
|
+
readonly top: number;
|
|
53
|
+
readonly width: number;
|
|
54
|
+
readonly height: number;
|
|
44
55
|
readonly number: PageText;
|
|
45
56
|
readonly line: readonly (PageText | PageBox)[];
|
|
46
57
|
/** The boxes of the line, the same objects as in `line`: slot 1 first. */
|
package/lib/core/page.js
CHANGED
|
@@ -42,6 +42,7 @@ function measuresOf(layout) {
|
|
|
42
42
|
numbers,
|
|
43
43
|
indent,
|
|
44
44
|
column,
|
|
45
|
+
content,
|
|
45
46
|
full: content - indent,
|
|
46
47
|
second: layout.margin + column + layout.gutter,
|
|
47
48
|
floor: SHEET.height - layout.margin,
|
|
@@ -88,20 +89,22 @@ export function pageOf(items, layout = LAYOUT) {
|
|
|
88
89
|
throw new TypeError(noRoom(i, measures));
|
|
89
90
|
if (short(i)) {
|
|
90
91
|
const cells = short(i + 1) && i + 1 < MOST ? [i, i + 1] : [i];
|
|
91
|
-
const laid = cells.map((n, c) => itemOf([lineOf(n)], n, c === 0 ? layout.margin : measures.second, top, measures));
|
|
92
|
-
const height = Math.max(...laid.map((
|
|
92
|
+
const laid = cells.map((n, c) => itemOf([lineOf(n)], n, c === 0 ? layout.margin : measures.second, measures.column, top, measures));
|
|
93
|
+
const height = Math.max(...laid.map((item) => item.height));
|
|
93
94
|
if (height > room)
|
|
94
95
|
throw new TypeError(noRoom(i, measures));
|
|
95
|
-
placed.push(...laid
|
|
96
|
+
placed.push(...laid);
|
|
96
97
|
bottom = top + height;
|
|
97
98
|
i += cells.length;
|
|
98
99
|
}
|
|
99
100
|
else {
|
|
100
101
|
const wrapped = linesOf(lineOf(i), measures, room);
|
|
101
|
-
const laid = wrapped === undefined
|
|
102
|
+
const laid = wrapped === undefined
|
|
103
|
+
? undefined
|
|
104
|
+
: itemOf(wrapped, i, layout.margin, measures.content, top, measures);
|
|
102
105
|
if (laid === undefined || laid.height > room)
|
|
103
106
|
throw new TypeError(noRoom(i, measures));
|
|
104
|
-
placed.push(laid
|
|
107
|
+
placed.push(laid);
|
|
105
108
|
bottom = top + laid.height;
|
|
106
109
|
i += 1;
|
|
107
110
|
}
|
|
@@ -276,10 +279,10 @@ function runsOf(entries) {
|
|
|
276
279
|
return runs;
|
|
277
280
|
}
|
|
278
281
|
/**
|
|
279
|
-
* An item laid out from its lines at a place on the page: its parts in their places,
|
|
280
|
-
* the first line's baseline, right in the column of the numbers, and its height.
|
|
282
|
+
* An item laid out from its lines at a place on the page, `width` wide: its parts in their places,
|
|
283
|
+
* its number on the first line's baseline, right in the column of the numbers, and its height.
|
|
281
284
|
*/
|
|
282
|
-
function itemOf(lines, n, left, top, measures) {
|
|
285
|
+
function itemOf(lines, n, left, width, top, measures) {
|
|
283
286
|
const { layout } = measures;
|
|
284
287
|
const line = [];
|
|
285
288
|
const baselines = [];
|
|
@@ -303,15 +306,15 @@ function itemOf(lines, n, left, top, measures) {
|
|
|
303
306
|
boxed = hasBox;
|
|
304
307
|
}
|
|
305
308
|
const label = `${n + 1}.`;
|
|
306
|
-
const
|
|
309
|
+
const span = textWidth(layout, wordWidth(label));
|
|
307
310
|
const number = {
|
|
308
311
|
text: label,
|
|
309
|
-
left: left + measures.numbers -
|
|
312
|
+
left: left + measures.numbers - span,
|
|
310
313
|
baseline: baselines[0] ?? top + Math.floor(layout.line / 2) + Math.floor(layout.size / 3),
|
|
311
|
-
width,
|
|
314
|
+
width: span,
|
|
312
315
|
};
|
|
313
316
|
const height = Math.max(y - top, lines.length === 0 ? layout.line : 0);
|
|
314
|
-
return {
|
|
317
|
+
return { left, top, width, height, number, line, boxes: line.filter(isBox) };
|
|
315
318
|
}
|
|
316
319
|
function deepFreeze(value) {
|
|
317
320
|
if (typeof value === "object" && value !== null) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** The namespace of the SVG elements the element makes: its layers, and the row's icons. */
|
|
2
2
|
export declare const SVG = "http://www.w3.org/2000/svg";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* An SVG shape — a workbook's item or box, a demo's picture — set over a box in its layer's
|
|
5
|
+
* units.
|
|
6
|
+
*/
|
|
4
7
|
export declare function placeOver(shape: SVGElement, { left, top, width, height }: {
|
|
5
8
|
left: number;
|
|
6
9
|
top: number;
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// no entry point of the package.
|
|
5
5
|
/** The namespace of the SVG elements the element makes: its layers, and the row's icons. */
|
|
6
6
|
export const SVG = "http://www.w3.org/2000/svg";
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* An SVG shape — a workbook's item or box, a demo's picture — set over a box in its layer's
|
|
9
|
+
* units.
|
|
10
|
+
*/
|
|
8
11
|
export function placeOver(shape, { left, top, width, height }) {
|
|
9
12
|
shape.setAttribute("x", String(left));
|
|
10
13
|
shape.setAttribute("y", String(top));
|
package/lib/element/index.js
CHANGED
|
@@ -1815,9 +1815,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1815
1815
|
this.#values[c] = undefined;
|
|
1816
1816
|
continue;
|
|
1817
1817
|
}
|
|
1818
|
-
const
|
|
1818
|
+
const item = page.items[cell.item - 1];
|
|
1819
|
+
const box = item?.boxes[cell.slot - 1];
|
|
1819
1820
|
const rect = this.#rects[c];
|
|
1820
|
-
if (box === undefined || rect === undefined)
|
|
1821
|
+
if (item === undefined || box === undefined || rect === undefined)
|
|
1821
1822
|
continue;
|
|
1822
1823
|
if (text === undefined) {
|
|
1823
1824
|
text = document.createElementNS(SVG, "text");
|
|
@@ -1826,9 +1827,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1826
1827
|
rect.after(text);
|
|
1827
1828
|
this.#values[c] = text;
|
|
1828
1829
|
}
|
|
1830
|
+
// In the item's `<svg>`, from its origin, as its box's frame is.
|
|
1829
1831
|
const width = pieceWidth(value);
|
|
1830
|
-
|
|
1831
|
-
text.setAttribute("
|
|
1832
|
+
const { x, y } = fromItem(item, box.left + Math.floor((box.width - width) / 2), box.top + Math.floor(box.height / 2) + Math.floor(LAYOUT.size / 3));
|
|
1833
|
+
text.setAttribute("x", String(x));
|
|
1834
|
+
text.setAttribute("y", String(y));
|
|
1832
1835
|
text.setAttribute("textLength", String(width));
|
|
1833
1836
|
text.textContent = value;
|
|
1834
1837
|
}
|
|
@@ -2145,28 +2148,38 @@ function near({ x, y }, box, reach) {
|
|
|
2145
2148
|
}
|
|
2146
2149
|
/**
|
|
2147
2150
|
* An item of a workbook's lines (R36): its number, then its text and its boxes in the order they
|
|
2148
|
-
* are read, each where the layout put it.
|
|
2149
|
-
*
|
|
2151
|
+
* are read, each where the layout put it. The item is an `<svg>` of its own place and size, which
|
|
2152
|
+
* shows what it holds beyond its edges, and its parts lie from its origin: Firefox brings a group
|
|
2153
|
+
* into view as a point at its origin, and only a box with a size whole (measurements 1.5 and 1.6).
|
|
2154
|
+
* A piece of text is fitted to its width by SVG, whatever the font, and its size is never read.
|
|
2150
2155
|
*/
|
|
2151
2156
|
function itemOf(item) {
|
|
2152
|
-
const
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2157
|
+
const svg = document.createElementNS(SVG, "svg");
|
|
2158
|
+
placeOver(svg, item);
|
|
2159
|
+
svg.setAttribute("overflow", "visible");
|
|
2160
|
+
svg.setAttribute("role", "listitem");
|
|
2161
|
+
svg.append(textOf(item.number, item), ...item.line.map((part) => (isBox(part) ? rectOf(part, item) : textOf(part, item))));
|
|
2162
|
+
return svg;
|
|
2163
|
+
}
|
|
2164
|
+
/** Where the layout puts a part of an item, from the item's origin, in page units. */
|
|
2165
|
+
function fromItem(item, left, top) {
|
|
2166
|
+
return { x: left - item.left, y: top - item.top };
|
|
2156
2167
|
}
|
|
2157
|
-
function textOf({ text, left, baseline, width }) {
|
|
2168
|
+
function textOf({ text, left, baseline, width }, item) {
|
|
2158
2169
|
const element = document.createElementNS(SVG, "text");
|
|
2159
|
-
|
|
2160
|
-
element.setAttribute("
|
|
2170
|
+
const { x, y } = fromItem(item, left, baseline);
|
|
2171
|
+
element.setAttribute("x", String(x));
|
|
2172
|
+
element.setAttribute("y", String(y));
|
|
2161
2173
|
element.setAttribute("textLength", String(width));
|
|
2162
2174
|
element.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
2163
2175
|
element.textContent = text;
|
|
2164
2176
|
return element;
|
|
2165
2177
|
}
|
|
2166
2178
|
/** A box, a picture to a screen reader, which its name tells of (R34). */
|
|
2167
|
-
function rectOf(box) {
|
|
2179
|
+
function rectOf(box, item) {
|
|
2168
2180
|
const rect = document.createElementNS(SVG, "rect");
|
|
2169
|
-
|
|
2181
|
+
const { x, y } = fromItem(item, box.left, box.top);
|
|
2182
|
+
placeOver(rect, { ...box, left: x, top: y });
|
|
2170
2183
|
rect.setAttribute("role", "img");
|
|
2171
2184
|
return rect;
|
|
2172
2185
|
}
|