egatari 0.6.18 → 0.6.20-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.ja.md +7 -2
  3. package/README.md +7 -2
  4. package/components.lock.json +40 -12
  5. package/components2.lock.json +534 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +4 -0
  8. package/kit/check.mjs +6 -2
  9. package/kit/core/bookmark.mjs +13 -0
  10. package/kit/core/build-core.mjs +1 -1
  11. package/kit/core/check-parity.mjs +2 -0
  12. package/kit/core/check-rules.mjs +1 -1
  13. package/kit/core/check-source.mjs +4 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +17 -10
  22. package/kit/core/llm-pack-data.mjs +94 -30
  23. package/kit/core/llm-pack.mjs +2 -1
  24. package/kit/core/part-labels.mjs +1 -0
  25. package/kit/core/portable.mjs +5 -2
  26. package/kit/core/scorm.mjs +30 -6
  27. package/kit/core/script-unclosed.mjs +66 -0
  28. package/kit/core/slide-ops.mjs +5 -1
  29. package/kit/core/template-text.mjs +2 -0
  30. package/kit/deck.js +71 -4
  31. package/kit/instruction-version.json +1 -1
  32. package/kit/layouts.css +8 -0
  33. package/kit/panes.js +17 -1
  34. package/kit/player.json +1 -1
  35. package/kit/player.lock.json +2 -2
  36. package/kit/templates/new-deck.mjs +1 -1
  37. package/kit/tools.js +136 -4
  38. package/kit/track.js +46 -5
  39. package/package.json +1 -1
  40. package/server/editor-ui.js +21 -1
  41. package/server/script-field.js +1 -1
  42. package/vendor/components/CATALOG.md +5 -4
  43. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  44. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  45. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  46. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  47. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  48. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  49. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  50. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  51. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/README.en.md +38 -0
  52. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/index.js +414 -0
  53. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/README.en.md +40 -0
  54. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/index.js +355 -0
  55. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  56. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  57. package/vendor/components/sha256/9a426812105a44446e8b3f98e0ccfdb6701e8386c08e8aa201b69cb5b52a4c1f/index.js +278 -0
  58. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  59. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  60. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  61. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  62. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/README.en.md +54 -0
  63. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/index.js +470 -0
  64. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/README.en.md +23 -0
  65. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/index.js +150 -0
  66. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  67. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  68. package/vendor/components-2/manifest-2.22.0.json +3240 -0
  69. package/vendor/egatari-spec/SOURCE.json +2 -2
  70. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  71. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,382 @@
1
+ // m-matrix 2.1.0: a comparison matrix in two forms (handoff #64; 2.1 for the positioning types, handoff #71).
2
+ // kind "cross" (default): the cross of two axes. Rows are the values of axis 1, columns the values of axis 2 (2 to 4 each);
3
+ // a cell lists the studies that fall there (a citation number or "Author (year)", 1 to 3), "self" marks the cell of this work
4
+ // (written as 本研究 / This work and framed, never colour alone; {"self": "one sentence"} adds this work's finding under it),
5
+ // and an empty cell shows — with a note number; the notes ("trivial", "meaningless", "not yet done") stand under the table.
6
+ // A third axis is a mark after a study's name (†, ‡) explained by "marks". "design" adds a small table under the cross
7
+ // (the design of the data or the identification, earlier work against this work, and what it made possible).
8
+ // Steps (order "build", default): the axes and the empty grid → the earlier studies → this work's cell, framed → the notes
9
+ // of the empty cells. order "whole": everything at step 1.
10
+ // kind "attributes": rows are studies (this work first), columns their elements (aim, setting, input, output, criterion …),
11
+ // a cell a short text (✓ △ × too). A column may name where it comes from ({"name", "source"}: the source stands over the
12
+ // name, so a reader sees the requirement was not picked to suit this work). order "whole" (default), "col" (a column per
13
+ // step) or "row" (a row per step); the row marked self is framed at the last step. "marks" explains the symbols under the
14
+ // table ("— not stated" too).
15
+ // Headers: a cross table names its axes once (the row axis in the corner, the column axis over its values); the readable
16
+ // table (data-readable, the final state) writes each header as "axis: value". Cells are data-part boxes and their texts
17
+ // labels, for Studio's geometry check (spec §8.4). Text is size px (≥ 24); when the table does not fit at 24 px the part
18
+ // reports size with what it needs. Colours: grid --line, headers --fg bold, this work's frame --emph, notes, sources and
19
+ // dashes --muted.
20
+ egatariParts.define({name: "matrix", version: "2.1.0", requires: {base: "1.3.0"}, element: "m-matrix"}, function(deps){
21
+ "use strict";
22
+ var base = deps.base;
23
+ var T = {ja: {self: "本研究", note: "注", sep: ":", label: "表:", none: "該当なし", source: "出どころ"},
24
+ en: {self: "This work", note: "Note ", sep: ": ", label: "Table: ", none: "none", source: "From"}};
25
+ var STR = {type: "string"};
26
+ var CELL = {type: ["array", "object"]};
27
+ var WRAP = 11; // a wrapped text's line before the table is measured, in full-width characters (a half-width one counts 0.55)
28
+ var units = function(t){ var w = 0; for (var i = 0; i < t.length; i++) w += t.charCodeAt(i) < 0x100 ? 0.55 : 1; return w; };
29
+ // lines no wider than maxW by measure: "\n" breaks where the author wants; otherwise between characters as Japanese text
30
+ // breaks, but never inside a run of Latin letters or digits, nor between a number and the word after it ("7 割"), nor
31
+ // before 、。)」 (they stay on the line before); a 、 or 。 late in the line is the break when there is one
32
+ var TOKEN = /[A-Za-z0-9.,%+\-\/]+(?: [^\sA-Za-z0-9、。,.)」])?[、。,.)」]*|\S[、。,.・)」]*|\s+/g;
33
+ // a better break than the last character that fits: after 、 or 。 in the later 40 % of the line, else where hiragana gives way
34
+ // to a kanji, katakana or a digit (after a particle: 「割は|学校の」) in its later half; -1 when there is none
35
+ var HIRA = /[\u3041-\u309f]/, WORD = /[\u4e00-\u9fff\u30a0-\u30ffA-Za-z0-9]/;
36
+ function breakAt(t){
37
+ var n = t.length, i;
38
+ for (i = n - 1; i >= n * 0.6; i--) if (/[、。,.]/.test(t[i - 1]) && i < n) return i;
39
+ for (i = n - 1; i >= n * 0.5; i--) if (HIRA.test(t[i - 1]) && (WORD.test(t[i]) || (t[i] === " " && WORD.test(t[i + 1] || "")))) return i;
40
+ return -1;
41
+ }
42
+ function wrap(s, maxW, measure){
43
+ measure = measure || units; maxW = maxW || WRAP;
44
+ var out = [];
45
+ String(s).split("\n").forEach(function(part){
46
+ var cur = "", toks = part.match(TOKEN) || [];
47
+ toks.forEach(function(tok){
48
+ if (/^\s+$/.test(tok)) { if (cur) cur += " "; return; }
49
+ if (!cur || measure(cur + tok) <= maxW) { cur += tok; return; }
50
+ var line = cur.replace(/ +$/, ""), rest = "", p = breakAt(line + tok);
51
+ if (p > 0 && p < line.length) { rest = line.slice(p).replace(/^ +/, ""); line = line.slice(0, p).replace(/ +$/, ""); }
52
+ out.push(line); cur = rest + tok;
53
+ });
54
+ out.push(cur.replace(/ +$/, ""));
55
+ });
56
+ return out;
57
+ }
58
+ // the marks under the table: one line when they are short (a legend of symbols), else a line each
59
+ function markLines(marks, ja){
60
+ var items = marks.map(function(m){ return String(m.mark) + " " + String(m.text); });
61
+ var one = items.join(ja ? " " : " "), w = 0;
62
+ for (var i = 0; i < one.length; i++) w += one.charCodeAt(i) < 0x100 ? 0.55 : 1;
63
+ return (items.length > 1 && w <= 40 ? [one] : items).map(function(t){ return {text: t, step: 1}; });
64
+ }
65
+ return class extends base.MotionElement {
66
+ static partName = "matrix";
67
+ static shape = {
68
+ schema: {type: "object", additionalProperties: false, properties: {
69
+ kind: {type: "string", enum: ["cross", "attributes"]},
70
+ rows: {type: ["object", "array"]},
71
+ cols: {type: ["object", "array"]},
72
+ cells: {type: "array", maxItems: 4, items: {type: "array", maxItems: 4, items: CELL}},
73
+ marks: {type: "array", maxItems: 4, items: {type: "object", additionalProperties: false, required: ["mark", "text"], properties: {mark: STR, text: STR}}},
74
+ design: {type: "object", additionalProperties: false, required: ["cols", "rows"], properties: {
75
+ cols: {type: "array", minItems: 2, maxItems: 3, items: STR},
76
+ rows: {type: "array", minItems: 1, maxItems: 3, items: {type: "object", additionalProperties: false, required: ["cells"], properties: {
77
+ label: STR, self: {type: "boolean"}, cells: {type: "array", items: STR}}}}}},
78
+ self: STR}},
79
+ example: {kind: "cross", rows: {axis: "評価基準", values: ["予測誤差", "ベイズリスク"]}, cols: {axis: "予測の形", values: ["点予測", "分布予測"]},
80
+ cells: [[["[1]", "[2]"], ["[3]"]], [{none: "自明"}, {self: true}]]},
81
+ note: {en: "cross: rows, cols {\"axis\", \"values\"}; cells[r][c] study names, {\"self\": true or \"finding\"} or {\"none\": \"why\"}; design {\"cols\", \"rows\"}. attributes: cols names or {\"name\", \"source\"}, rows {\"label\", \"cells\", \"self\"?}",
82
+ ja: "cross:rows・cols は {\"axis\", \"values\"}、cells[r][c] は研究の名前の並び・{\"self\": true か \"結論\"}・{\"none\": \"理由\"}、design は {\"cols\", \"rows\"}。attributes:cols は名前か {\"name\", \"source\"}、rows は {\"label\", \"cells\", \"self\"?}"},
83
+ };
84
+ static props = {
85
+ order: {type: "string", default: "", doc: "出し方:cross は build(既定)・whole、attributes は whole(既定)・col・row"},
86
+ dur: {type: "number", default: 0.6, doc: "1 ステップの秒数"},
87
+ size: {type: "number", default: 28, doc: "字の大きさ(px、24 以上。入らなければ 24 まで縮める)"},
88
+ };
89
+ get steps(){
90
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
91
+ return this.plan().steps;
92
+ }
93
+ // the cells and when each appears; from the data alone
94
+ plan(){
95
+ if (this._plan) return this._plan;
96
+ var d = this.data || {}, bad = [], ja = !/^en\b/i.test(this.closest && this.closest("[lang]") ? this.closest("[lang]").getAttribute("lang") : "ja");
97
+ var L = ja ? T.ja : T.en, selfText = d.self || L.self, kind = d.kind || "cross", order = this.props.order;
98
+ var cells = [], notes = [], grid = {}, steps = 0, selfBox = null;
99
+ var cell = function(r, c, lines, o){ var x = Object.assign({r: r, c: c, lines: lines, step: 0}, o || {}); cells.push(x); if (!x.dz) grid[r + "," + c] = x; return x; };
100
+ var marks = Array.isArray(d.marks) ? d.marks : [];
101
+ var nr, nc, head;
102
+ if (kind === "cross") {
103
+ var R = d.rows && !Array.isArray(d.rows) ? d.rows : {}, C = d.cols && !Array.isArray(d.cols) ? d.cols : {};
104
+ var rv = Array.isArray(R.values) ? R.values.map(String) : [], cv = Array.isArray(C.values) ? C.values.map(String) : [];
105
+ if (rv.length < 2 || rv.length > 4 || cv.length < 2 || cv.length > 4) bad.push("cross needs 2 to 4 values on each axis (rows.values, cols.values)");
106
+ if (order && order !== "build" && order !== "whole") bad.push("order for cross is build or whole, not " + order);
107
+ var whole = order === "whole";
108
+ // grid: row 0 = the column axis's name over its values, row 1 = the column values; column 0 = the row values
109
+ nr = rv.length + 2; nc = cv.length + 1; head = {rows: 2, cols: 1};
110
+ cell(0, 0, [String(R.axis || "")], {head: true, corner: true, span: [2, 1]});
111
+ cell(0, 1, [String(C.axis || "")], {head: true, span: [1, cv.length]});
112
+ cv.forEach(function(v, j){ cell(1, j + 1, [v], {head: true}); });
113
+ rv.forEach(function(v, i){ cell(i + 2, 0, [v], {head: true}); });
114
+ var cs = Array.isArray(d.cells) ? d.cells : [];
115
+ if (cs.length !== rv.length || cs.some(function(row, i){ return !Array.isArray(row) || row.length !== cv.length; })) bad.push("cells must be " + rv.length + " rows of " + cv.length + " cells (rows.values × cols.values)");
116
+ // build: the studies at 1, this work at 2 (when there is one), the notes at the last step (when there are any)
117
+ var anySelf = cs.some(function(row){ return Array.isArray(row) && row.some(function(v){ return v && typeof v === "object" && !Array.isArray(v) && v.self; }); });
118
+ var anyNote = cs.some(function(row){ return Array.isArray(row) && row.some(function(v){ return v && typeof v === "object" && !Array.isArray(v) && typeof v.none === "string" && v.none; }); });
119
+ var sSelf = whole ? 1 : 2, sNote = whole ? 1 : anySelf ? 3 : 2;
120
+ steps = whole ? 1 : 1 + (anySelf ? 1 : 0) + (anyNote ? 1 : 0);
121
+ rv.forEach(function(_, i){ cv.forEach(function(_, j){
122
+ var v = (cs[i] || [])[j], r = i + 2, c = j + 1, obj = v && typeof v === "object" && !Array.isArray(v);
123
+ if (Array.isArray(v) && v.length) {
124
+ if (v.length > 3) bad.push("cell " + (i + 1) + "," + (j + 1) + " lists " + v.length + " studies; at most 3 (pick the main ones)");
125
+ cell(r, c, v.slice(0, 3).map(String), {step: 1});
126
+ } else if (obj && v.self) {
127
+ if (selfBox) bad.push("only one cell is this work's (self)");
128
+ var claim = typeof v.self === "string" && v.self.trim() ? wrap(v.self.trim(), WRAP) : [];
129
+ if (claim.length > 4) bad.push("this work's sentence takes " + claim.length + " lines; at most 4 (about 40 characters: the finding, not the method)");
130
+ var x = cell(r, c, [selfText].concat(claim.slice(0, 4), (Array.isArray(v.studies) ? v.studies : []).map(String)), {step: sSelf, self: !selfBox,
131
+ text: claim.length ? v.self.trim() : "", pre: [selfText], post: (Array.isArray(v.studies) ? v.studies : []).map(String), maxLines: 4});
132
+ if (!selfBox) selfBox = x;
133
+ } else if (obj && typeof v.none === "string" && v.none) {
134
+ notes.push(v.none);
135
+ cell(r, c, ["— " + L.note + notes.length], {step: sNote, dash: true, note: notes.length});
136
+ } else {
137
+ cell(r, c, ["—"], {step: 1, dash: true});
138
+ }
139
+ }); });
140
+ // the design rows under the cross: a header row, then the rows (earlier work with the studies, this work with its cell)
141
+ var design = null, Dz = d.design && typeof d.design === "object" ? d.design : null;
142
+ if (Dz) {
143
+ var dcols = Array.isArray(Dz.cols) ? Dz.cols.map(String) : [], drows = Array.isArray(Dz.rows) ? Dz.rows : [];
144
+ if (dcols.length < 2 || dcols.length > 3) bad.push("design needs 2 or 3 cols");
145
+ if (drows.length < 1 || drows.length > 3) bad.push("design needs 1 to 3 rows");
146
+ if (dcols.length >= 2 && dcols.length <= 3 && drows.length >= 1 && drows.length <= 3) {
147
+ design = {nr: drows.length + 1, nc: dcols.length + 1, cols: dcols, rows: []};
148
+ cell(0, 0, [""], {dz: true, head: true});
149
+ dcols.forEach(function(s, j){ cell(0, j + 1, wrap(s, WRAP + 2), {dz: true, head: true, text: s}); });
150
+ drows.forEach(function(row, i){
151
+ row = row && typeof row === "object" ? row : {};
152
+ var dc = Array.isArray(row.cells) ? row.cells : [], st = row.self ? sSelf : 1;
153
+ if (dc.length !== dcols.length) bad.push("design row " + (i + 1) + " has " + dc.length + " cells; design.cols has " + dcols.length);
154
+ var lab = row.label ? String(row.label) : row.self ? selfText : "";
155
+ cell(i + 1, 0, lab ? wrap(lab, WRAP) : [""], {dz: true, head: true, step: st, self: !!row.self});
156
+ dcols.forEach(function(_, j){
157
+ var s = dc[j] === undefined || dc[j] === null || dc[j] === "" ? "—" : String(dc[j]);
158
+ cell(i + 1, j + 1, wrap(s, WRAP + 2), {dz: true, step: st, dash: s === "—", text: s});
159
+ });
160
+ design.rows.push({label: lab, cells: dcols.map(function(_, j){ return dc[j] === undefined || dc[j] === null || dc[j] === "" ? "—" : String(dc[j]); }), self: !!row.self, step: st});
161
+ });
162
+ if (!whole && !anySelf && design.rows.some(function(r){ return r.self; })) {
163
+ // a self design row without a self cell: it comes after the studies all the same
164
+ steps = Math.max(steps, sSelf);
165
+ }
166
+ }
167
+ }
168
+ var below = markLines(marks, ja)
169
+ .concat(notes.map(function(t, i){ return {text: L.note + (i + 1) + L.sep + t, step: sNote}; }));
170
+ return (this._plan = {kind: kind, L: L, bad: bad, cells: cells, grid: grid, nr: nr, nc: nc, head: head, steps: steps, selfBox: selfBox, below: below,
171
+ design: design, rv: rv, cv: cv, raxis: String(R.axis || ""), caxis: String(C.axis || "")});
172
+ }
173
+ if (kind !== "attributes") bad.push("kind is cross or attributes");
174
+ if (d.design) bad.push("design is for kind cross");
175
+ var colsIn = Array.isArray(d.cols) ? d.cols : [], rows = Array.isArray(d.rows) ? d.rows : [];
176
+ var cols = colsIn.map(function(v){ return v && typeof v === "object" ? String(v.name || "") : String(v); });
177
+ var sources = colsIn.map(function(v){ return v && typeof v === "object" && v.source ? String(v.source) : ""; });
178
+ var anySource = sources.some(Boolean);
179
+ if (cols.length < 1 || cols.length > 6) bad.push("attributes needs 1 to 6 cols");
180
+ if (rows.length < 1 || rows.length > 10) bad.push("attributes needs 1 to 10 rows");
181
+ order = order || "whole";
182
+ if (["whole", "col", "row"].indexOf(order) < 0) { bad.push("order for attributes is whole, col or row, not " + order); order = "whole"; }
183
+ var hr = anySource ? 2 : 1;
184
+ nr = rows.length + hr; nc = cols.length + 1; head = {rows: hr, cols: 1};
185
+ var selfRow = -1;
186
+ rows.forEach(function(r, i){ if (r && r.self && selfRow < 0) selfRow = i; });
187
+ var groups = order === "whole" ? 1 : order === "col" ? cols.length : rows.length;
188
+ steps = groups + (selfRow >= 0 && order !== "whole" ? 1 : 0);
189
+ var colStep = function(j){ return order === "col" ? j + 1 : 0; };
190
+ if (anySource) {
191
+ // the sources stand over the names, with their column
192
+ cell(0, 0, [L.source], {head: true, corner: true, muted: true});
193
+ sources.forEach(function(s, j){ cell(0, j + 1, s ? wrap(s, WRAP) : [""], {muted: true, step: colStep(j), text: s}); });
194
+ }
195
+ cell(hr - 1, 0, [""], {head: true, corner: true});
196
+ cols.forEach(function(v, j){ cell(hr - 1, j + 1, [v], {head: true}); });
197
+ rows.forEach(function(r, i){
198
+ r = r && typeof r === "object" ? r : {};
199
+ var cs = Array.isArray(r.cells) ? r.cells : [];
200
+ if (cs.length !== cols.length) bad.push("row " + (i + 1) + " has " + cs.length + " cells; cols has " + cols.length);
201
+ var at = function(j){ return order === "whole" ? 1 : order === "col" ? j + 1 : i + 1; };
202
+ cell(i + hr, 0, [String(r.label || "")], {head: true, step: order === "row" ? i + 1 : 0, self: i === selfRow});
203
+ cols.forEach(function(_, j){
204
+ var v = cs[j], s = v === undefined || v === null || v === "" ? "—" : String(v);
205
+ cell(i + hr, j + 1, [s], {step: at(j), dash: s === "—"});
206
+ });
207
+ });
208
+ var belowA = markLines(marks, ja);
209
+ return (this._plan = {kind: kind, L: L, bad: bad, cells: cells, grid: grid, nr: nr, nc: nc, head: head, steps: steps, selfRow: selfRow,
210
+ selfStep: selfRow >= 0 ? (order === "whole" ? 1 : steps) : 0, below: belowA, cols: cols, sources: anySource ? sources : null,
211
+ rowsLabels: rows.map(function(r){ return String((r || {}).label || ""); })});
212
+ }
213
+ mount(ctx){
214
+ var self = this, P = this.props, D = base, pl = this.plan();
215
+ this.style.display = "block"; this.style.position = "relative";
216
+ var W = this.clientWidth, H = this.clientHeight;
217
+ if (!(P.dur >= 0)) { ctx.report("attr", "[matrix] dur must be ≥ 0; using 0.6"); P.dur = 0.6; }
218
+ if (!(P.size >= 24)) { ctx.report("attr", "[matrix] size must be ≥ 24; using 28"); P.size = 28; }
219
+ pl.bad.forEach(function(m){ ctx.report("data", "[matrix] " + m); });
220
+ if (pl.bad.length && (pl.nr < 2 || pl.nc < 2)) return; // nothing to draw a grid from
221
+ // sizes: the largest font from size down to 24 at which the table fits; else 24 and a size report
222
+ var fit = null;
223
+ for (var fs = Math.round(P.size); fs >= 24 && !fit; fs -= 2) fit = this._fit(fs, W, H);
224
+ if (!fit) {
225
+ var g24 = this._fit(24, W, H, true);
226
+ ctx.report("size", "[matrix] the table needs " + Math.ceil(g24.tableW) + " × " + Math.ceil(g24.needH) + " px at 24 px; the element is " + W + " × " + H + " px (fewer rows or columns, shorter names, or a larger element)");
227
+ fit = g24;
228
+ }
229
+ var G = this.geo = fit, fsz = G.fs;
230
+ var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
231
+ var gB = D.el("g", {}, svg), gL = D.el("g", {}, svg), gT = D.el("g", {}, svg), gF = D.el("g", {}, svg), gN = D.el("g", {}, svg);
232
+ var xs = G.xs, ys = G.ys, x0 = xs[0], y0 = ys[0], hr = pl.head.rows, hc = pl.head.cols;
233
+ // grid: thick under the header rows and right of the header column; the column-axis row has no vertical lines inside its span
234
+ for (var r = 0; r <= pl.nr; r++) {
235
+ var xa = pl.kind === "cross" && r === 1 ? xs[1] : x0;
236
+ D.el("line", {x1: xa, x2: xs[pl.nc], y1: ys[r], y2: ys[r], stroke: "var(--line)", "stroke-width": r === hr ? 2.5 : 1.2}, gL);
237
+ }
238
+ for (var c = 0; c <= pl.nc; c++) {
239
+ var ya = pl.kind === "cross" && c >= 2 && c < pl.nc ? ys[1] : y0;
240
+ D.el("line", {x1: xs[c], x2: xs[c], y1: ya, y2: ys[pl.nr], stroke: "var(--line)", "stroke-width": c === hc ? 2.5 : 1.2}, gL);
241
+ }
242
+ var dxs = G.dxs, dys = G.dys, dz = pl.design;
243
+ if (dz) {
244
+ for (var r2 = 0; r2 <= dz.nr; r2++) D.el("line", {x1: dxs[0], x2: dxs[dz.nc], y1: dys[r2], y2: dys[r2], stroke: "var(--line)", "stroke-width": r2 === 1 ? 2.5 : 1.2}, gL);
245
+ for (var c2 = 0; c2 <= dz.nc; c2++) D.el("line", {x1: dxs[c2], x2: dxs[c2], y1: dys[0], y2: dys[dz.nr], stroke: "var(--line)", "stroke-width": c2 === 1 ? 2.5 : 1.2}, gL);
246
+ }
247
+ var lh = Math.ceil(fsz * 1.3), pad = G.pad;
248
+ this.cellEls = pl.cells.map(function(x, ci){
249
+ var X = x.dz ? dxs : xs, Y = x.dz ? dys : ys;
250
+ var sp = x.span || [1, 1], cx0 = X[x.c], cx1 = X[x.c + sp[1]], cy0 = Y[x.r], cy1 = Y[x.r + sp[0]];
251
+ var id = (x.dz ? "d" : "m") + x.r + "-" + x.c, g = D.el("g", {}, gT);
252
+ D.el("rect", {x: cx0, y: cy0, width: cx1 - cx0, height: cy1 - cy0, fill: "none", stroke: "none", "data-part": "box", "data-part-id": id}, gB);
253
+ var ls = G.lines[ci], left = x.head && x.c === 0, n = ls.length, top = (cy0 + cy1) / 2 - (n - 1) * lh / 2 + fsz * 0.36;
254
+ ls.forEach(function(s, i){
255
+ if (!s) return;
256
+ var t = D.el("text", {x: (left ? cx0 + pad : (cx0 + cx1) / 2).toFixed(1), y: (top + i * lh).toFixed(1), "font-size": fsz,
257
+ "text-anchor": left ? "start" : "middle", fill: x.dash || x.muted ? "var(--muted)" : "var(--fg)", "font-weight": x.head && !x.muted || (x.self && i === 0) ? 700 : 400,
258
+ "data-part": "label", "data-part-id": id, "data-part-of": "box"}, g);
259
+ t.textContent = s;
260
+ });
261
+ return {x: x, g: g};
262
+ });
263
+ // this work: the cell (cross) or the row (attributes), framed in --emph; a self design row too
264
+ var frames = [];
265
+ if (pl.selfBox) { var b = pl.selfBox; frames.push({r: [xs[b.c] + 3, ys[b.r] + 3, xs[b.c + 1] - xs[b.c] - 6, ys[b.r + 1] - ys[b.r] - 6], step: b.step}); }
266
+ else if (pl.selfRow >= 0) { var rr = pl.selfRow + hr; frames.push({r: [x0 + 3, ys[rr] + 3, xs[pl.nc] - x0 - 6, ys[rr + 1] - ys[rr] - 6], step: pl.selfStep}); }
267
+ if (dz) dz.rows.forEach(function(o, i){ if (o.self) frames.push({r: [dxs[0] + 3, dys[i + 1] + 3, dxs[dz.nc] - dxs[0] - 6, dys[i + 2] - dys[i + 1] - 6], step: o.step}); });
268
+ this.frames = frames.map(function(f){ return {step: f.step, el: D.el("rect", {x: f.r[0], y: f.r[1], width: f.r[2], height: f.r[3], rx: 5, fill: "none", stroke: "var(--emph)", "stroke-width": 4}, gF)}; });
269
+ // notes and marks under the table (under the design rows when there are any)
270
+ this.belowEls = pl.below.map(function(o, i){
271
+ var t = D.el("text", {x: x0.toFixed(1), y: (G.belowTop + 14 + fsz * 0.9 + i * Math.ceil(fsz * 1.35)).toFixed(1), "font-size": fsz, fill: "var(--fg)"}, gN);
272
+ t.textContent = o.text;
273
+ return {o: o, t: t};
274
+ });
275
+ // the readable table (data-readable): the final state, headers as "axis: value"
276
+ var tbl = document.createElement("table");
277
+ tbl.className = "sr-only"; tbl.setAttribute("data-readable", "");
278
+ tbl.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0");
279
+ var L = pl.L, tr = function(list, th){ var e = document.createElement("tr"); list.forEach(function(s, i){ var td = document.createElement(th || i === 0 ? "th" : "td"); td.textContent = s; e.appendChild(td); }); tbl.appendChild(e); };
280
+ var join = function(x){ return (x.pre || []).concat(x.text ? [x.text] : [], x.post || []).join(" "); };
281
+ if (pl.kind === "cross") {
282
+ tr([pl.raxis + " \ " + pl.caxis].concat(pl.cv.map(function(v){ return pl.caxis + L.sep + v; })), true);
283
+ pl.rv.forEach(function(v, i){ tr([pl.raxis + L.sep + v].concat(pl.cv.map(function(_, j){ var x = pl.grid[(i + 2) + "," + (j + 1)]; return x.self ? join(x) : x.lines.join("、"); }))); });
284
+ if (dz) {
285
+ tr([""].concat(dz.cols), true);
286
+ dz.rows.forEach(function(o){ tr([o.label || (o.self ? L.self : "")].concat(o.cells)); });
287
+ }
288
+ } else {
289
+ if (pl.sources) tr([L.source].concat(pl.sources), true);
290
+ tr([""].concat(pl.cols), true);
291
+ pl.rowsLabels.forEach(function(v, i){ tr([v + (i === pl.selfRow ? "(" + L.self + ")" : "")].concat(pl.cols.map(function(_, j){ return pl.grid[(i + hr) + "," + (j + 1)].lines.join(" "); }))); });
292
+ }
293
+ if (pl.below.length) { var cap = document.createElement("caption"); cap.textContent = pl.below.map(function(o){ return o.text; }).join(" "); tbl.insertBefore(cap, tbl.firstChild); }
294
+ this.appendChild(tbl);
295
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
296
+ this.setAttribute("role", "img");
297
+ if (!this._aria) this.setAttribute("aria-label", L.label + (pl.kind === "cross" ? pl.raxis + " × " + pl.caxis : pl.cols.join(pl.L === T.ja ? "、" : ", ")));
298
+ }
299
+ // column widths and row heights at font size fs; null when the table does not fit W × H (unless force)
300
+ _fit(fs, W, H, force){
301
+ var pl = this.plan(), D = base, self = this, pad = Math.round(fs * 0.5), lh = Math.ceil(fs * 1.3);
302
+ var tw = function(s, b){ return D.textWidth(s, fs, {font: self}) * (b ? 1.06 : 1); };
303
+ var cw = [], rh = [], dz = pl.design, dcw = [], drh = [];
304
+ for (var c = 0; c < pl.nc; c++) cw[c] = fs * 2;
305
+ for (var r = 0; r < pl.nr; r++) rh[r] = Math.ceil(fs * 1.6);
306
+ if (dz) { for (var c1 = 0; c1 < dz.nc; c1++) dcw[c1] = fs * 2; for (var r1 = 0; r1 < dz.nr; r1++) drh[r1] = Math.ceil(fs * 1.6); }
307
+ pl.cells.forEach(function(x){
308
+ if (x.span && x.span[1] > 1) return;
309
+ var CW = x.dz ? dcw : cw, RH = x.dz ? drh : rh;
310
+ var w = Math.max.apply(null, x.lines.map(function(s, i){ return tw(s, (x.head && !x.muted) || (x.self && i === 0)); })) + 2 * pad;
311
+ if (w > CW[x.c]) CW[x.c] = Math.ceil(w);
312
+ });
313
+ // value columns of the same width (a matrix reads by its grid), the header column as wide as it needs
314
+ var vmax = Math.max.apply(null, cw.slice(1));
315
+ for (var c2 = 1; c2 < pl.nc; c2++) cw[c2] = vmax;
316
+ // the design rows line up with the cross: the same header column, their value columns sharing the cross's width
317
+ if (dz) { cw[0] = dcw[0] = Math.max(cw[0], dcw[0]); }
318
+ var spanW = pl.kind === "cross" ? tw(pl.caxis, true) + 2 * pad : 0;
319
+ var tableW = cw.reduce(function(a, b){ return a + b; }, 0);
320
+ if (spanW > tableW - cw[0]) { var add = (spanW - (tableW - cw[0])) / (pl.nc - 1); for (var c3 = 1; c3 < pl.nc; c3++) cw[c3] += add; tableW = spanW + cw[0]; }
321
+ if (dz) {
322
+ var dneed = Math.max.apply(null, dcw.slice(1)) * (dz.nc - 1);
323
+ if (dneed > tableW - cw[0]) { var add2 = (dneed - (tableW - cw[0])) / (pl.nc - 1); for (var c5 = 1; c5 < pl.nc; c5++) cw[c5] += add2; tableW = dneed + cw[0]; }
324
+ }
325
+ // spread the value columns over the width the element has, up to 1.4 times what they need
326
+ var room = W - 4 - tableW;
327
+ if (room > 0) { var grow = Math.min(room, (tableW - cw[0]) * 0.4) / (pl.nc - 1); for (var c4 = 1; c4 < pl.nc; c4++) cw[c4] += grow; tableW += grow * (pl.nc - 1); }
328
+ if (dz) for (var c6 = 1; c6 < dz.nc; c6++) dcw[c6] = (tableW - cw[0]) / (dz.nc - 1);
329
+ // the texts that wrap (this work's sentence, the design rows, the sources) take the width their column now has; then the heights
330
+ var lines = pl.cells.map(function(x){
331
+ if (!x.text) return x.lines;
332
+ var CW = x.dz ? dcw : cw, b = !!(x.head && !x.muted);
333
+ var m = function(t){ return tw(t, b); }, full = CW[x.c] - 2 * pad, ls = wrap(x.text, full, m);
334
+ // balanced: the narrowest width that keeps the number of lines (no one-character last line)
335
+ if (ls.length > 1) {
336
+ var lo = full / ls.length, hi = full;
337
+ for (var it = 0; it < 12; it++) { var mid = (lo + hi) / 2; if (wrap(x.text, mid, m).length > ls.length) lo = mid; else hi = mid; }
338
+ ls = wrap(x.text, hi, m);
339
+ }
340
+ if (x.maxLines) ls = ls.slice(0, x.maxLines);
341
+ return (x.pre || []).concat(ls, x.post || []);
342
+ });
343
+ pl.cells.forEach(function(x, i){
344
+ if (x.span && x.span[0] > 1) return;
345
+ var RH = x.dz ? drh : rh, h = Math.ceil(lines[i].length * lh + fs * 0.5);
346
+ if (h > RH[x.r]) RH[x.r] = h;
347
+ });
348
+ var gap = dz ? Math.round(fs * 0.8) : 0, designH = dz ? gap + drh.reduce(function(a, b){ return a + b; }, 0) : 0;
349
+ var tableH = rh.reduce(function(a, b){ return a + b; }, 0), belowH = pl.below.length ? 14 + pl.below.length * Math.ceil(fs * 1.35) : 0;
350
+ var needH = tableH + designH + belowH + 8;
351
+ if (!force && (tableW > W - 2 || needH > H)) return null;
352
+ // fill the element's height: the body rows grow, each to at most 1.8 times its height (no wide empty band under a short table)
353
+ if (needH < H) {
354
+ var nb = pl.nr - pl.head.rows, each = Math.min((H - needH) / nb, Math.min.apply(null, rh.slice(pl.head.rows)) * 0.8);
355
+ for (var r2 = pl.head.rows; r2 < pl.nr; r2++) rh[r2] += each;
356
+ tableH += each * nb; needH += each * nb;
357
+ }
358
+ var x0 = Math.max(1, (W - tableW) / 2), xs = [x0], ys = [4];
359
+ cw.forEach(function(w, i){ xs.push(xs[i] + w); });
360
+ rh.forEach(function(h, i){ ys.push(ys[i] + h); });
361
+ var tableBottom = ys[ys.length - 1], dxs = null, dys = null;
362
+ if (dz) {
363
+ dxs = [x0]; dys = [tableBottom + gap];
364
+ dcw.forEach(function(w, i){ dxs.push(dxs[i] + w); });
365
+ drh.forEach(function(h, i){ dys.push(dys[i] + h); });
366
+ }
367
+ return {fs: fs, pad: pad, lines: lines, xs: xs, ys: ys, dxs: dxs, dys: dys, tableW: tableW, needH: needH, tableBottom: tableBottom,
368
+ belowTop: dz ? dys[dys.length - 1] : tableBottom};
369
+ }
370
+ duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
371
+ render(k, t, ctx){
372
+ if (!this.cellEls) return;
373
+ var D = base, P = this.props, N = this.plan().steps, faint = ctx && (ctx.preview || ctx.mode === "lecture") ? base.previewOpacity(this) : 0;
374
+ k = Math.max(0, Math.min(k, N));
375
+ var e = k === 0 ? 1 : D.prog(t, 0, P.dur);
376
+ var op = function(st){ var v = st === 0 || st < k ? 1 : st > k ? 0 : e; return Math.max(v, st > k ? faint : 0); };
377
+ this.cellEls.forEach(function(o){ o.g.setAttribute("opacity", op(o.x.step).toFixed(3)); });
378
+ this.frames.forEach(function(f){ f.el.setAttribute("opacity", (f.step > k ? 0 : f.step < k ? 1 : e).toFixed(3)); });
379
+ this.belowEls.forEach(function(o){ o.t.setAttribute("opacity", op(o.o.step).toFixed(3)); });
380
+ }
381
+ };
382
+ });
@@ -0,0 +1,54 @@
1
+ ---
2
+ summary: Bars grow from 0 by step (vertical, horizontal, grouped, stacked); the axis max can widen by step
3
+ steps: max group/scale step (default 1 group = 1 step)
4
+ props:
5
+ orient: v or h
6
+ max: axis max (0 = auto)
7
+ unit: value unit
8
+ digits: decimals
9
+ per-step: groups per step (0 = all)
10
+ dur: grow seconds
11
+ stagger: group offset (s)
12
+ count: count values up
13
+ ticks: ticks and grid
14
+ zoom: scale-change seconds
15
+ al: axis title
16
+ stack: stack values; "percent" = 100 %
17
+ mark: bar or dot (a point with its error bar)
18
+ example: {"series": [{"label": "Sales"}], "groups": [{"label": "Year 1", "value": 1.2}, {"label": "Year 2", "value": 3.4}]}
19
+ ---
20
+
21
+ For quantities shown and compared one at a time: yearly sales, ranked answers, before/after.
22
+
23
+ Child JSON: `{"series": [...], "groups": [...], "scale": [...], "sig": [...]}`.
24
+
25
+ - group: `label` (`\n` = 2 lines), `value` or `values` (one per series), `step`, `at` (start s), `tone` (bar and value colour)
26
+ - err: ± number or `[low, high]`; per series for `values`
27
+ - sig: `[{"from": 0, "to": 2, "label": "**"}]` brackets groups 0 and 2 (`group`: series in a group); vertical, unstacked only
28
+ <!-- llm: omit -->
29
+ - Error bars and values appear once a bar is grown; values sit beyond the error bar's end. `mark="dot"` points appear without growing. Brackets stack from the shortest
30
+ <!-- llm: end -->
31
+ - series: `label` (2+ series: on the first group's bars; no legend), `tone` (default `--series-1..4`)
32
+ - scale: `[{"step": 3, "max": 27, "at": 0.4}]`: the max moves to `max` over `zoom` s; the old range stays as a faint band; taller bars stop at the top and grow as it widens
33
+ <!-- llm: omit -->
34
+ - Auto max: 1.12 × the largest value (before the first scale), rounded
35
+ <!-- llm: end -->
36
+ - `orient="h"`: names left, values right; `ticks="false"` for ranks
37
+ - `stack="true"` (`"percent"` = 100 %): a group's `values` in one bar; total at the end, values inside segments; values ≥ 0
38
+ <!-- llm: omit -->
39
+ - Values: `digits` decimals, thousands separators, `unit` appended
40
+ - Negatives (not stacked): the axis includes 0; bars grow down/left from a `--fg` baseline; values outside the bar end
41
+ - `stack="percent"`: axis 0–100 %, no `max`/`scale`, segment values in % when they fit, no total
42
+ - Show later steps faintly (`ctx.preview`): later bars fully grown at `--preview-opacity`; no axis change or over-max bar shown ahead
43
+ <!-- llm: end -->
44
+
45
+ The demo is `demo.html`. All numbers are fictional.
46
+
47
+ Notes
48
+
49
+ - Values appear once a bar is fully grown; `count="true"` counts them up
50
+ - Series names sit on the first group's bars: keep to 2–3 series
51
+
52
+ <!-- llm: omit -->
53
+ - `examples/tmlr2026-calibration` keeps its own deck-local `components/bars/`
54
+ <!-- llm: end -->