egatari 0.6.12 → 0.6.13-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 (106) hide show
  1. package/README.ja.md +2 -2
  2. package/README.md +2 -2
  3. package/bin/egatari.mjs +3 -1
  4. package/components.lock.json +141 -51
  5. package/components2.lock.json +500 -1
  6. package/kit/browser.mjs +19 -7
  7. package/kit/check-messages.mjs +2 -0
  8. package/kit/check.mjs +2 -0
  9. package/kit/core/article-links.mjs +5 -4
  10. package/kit/core/article-messages.mjs +6 -1
  11. package/kit/core/article-render.mjs +61 -42
  12. package/kit/core/article-text.mjs +42 -1
  13. package/kit/core/article.mjs +7 -6
  14. package/kit/core/build-core.mjs +4 -0
  15. package/kit/core/caution.mjs +49 -0
  16. package/kit/core/check-parity.mjs +1 -0
  17. package/kit/core/check-rules.mjs +3 -0
  18. package/kit/core/check-source.mjs +2 -0
  19. package/kit/core/colab-core.mjs +1 -1
  20. package/kit/core/llm-pack-assemble.mjs +4 -3
  21. package/kit/core/llm-pack-data.mjs +124 -10
  22. package/kit/core/part-labels.mjs +3 -0
  23. package/kit/core/purposes.mjs +6 -8
  24. package/kit/instruction-version.json +1 -1
  25. package/kit/layouts.css +8 -1
  26. package/kit/player.json +1 -1
  27. package/kit/player.lock.json +2 -2
  28. package/package.json +1 -1
  29. package/themes/asagi/theme.json +1 -1
  30. package/themes/asagi/tokens.css +2 -0
  31. package/themes/bengara/theme.json +1 -1
  32. package/themes/bengara/tokens.css +2 -0
  33. package/themes/business/theme.json +1 -1
  34. package/themes/business/tokens.css +2 -0
  35. package/themes/default/theme.json +1 -1
  36. package/themes/default/tokens.css +2 -0
  37. package/themes/kogecha/theme.json +1 -1
  38. package/themes/kogecha/tokens.css +2 -0
  39. package/themes/kokugo/theme.json +1 -1
  40. package/themes/kokugo/tokens.css +2 -0
  41. package/themes/murasaki/theme.json +1 -1
  42. package/themes/murasaki/tokens.css +2 -0
  43. package/themes/sumi/theme.json +1 -1
  44. package/themes/sumi/tokens.css +2 -0
  45. package/themes/tokiwa/theme.json +1 -1
  46. package/themes/tokiwa/tokens.css +2 -0
  47. package/themes.lock.json +92 -28
  48. package/vendor/components/CATALOG.md +6 -3
  49. package/vendor/components/sha256/061415b5f5a1861e115103224ebbcaf689b602cd9972516001f50f4646d3692a/README.en.md +33 -0
  50. package/vendor/components/sha256/061415b5f5a1861e115103224ebbcaf689b602cd9972516001f50f4646d3692a/index.js +390 -0
  51. package/vendor/components/sha256/1854c2d9091a44f465a8de71de2ef3cfa26de3750c67aba4d0ab6eef9b826b8c/README.en.md +21 -0
  52. package/vendor/components/sha256/1854c2d9091a44f465a8de71de2ef3cfa26de3750c67aba4d0ab6eef9b826b8c/index.js +108 -0
  53. package/vendor/components/sha256/19803bbabc26cab7937b17c101f0529239ad505e2ef72a5b21c5d0b9afb063b5/README.en.md +35 -0
  54. package/vendor/components/sha256/19803bbabc26cab7937b17c101f0529239ad505e2ef72a5b21c5d0b9afb063b5/index.js +179 -0
  55. package/vendor/components/sha256/1fac9a4c6608f0150a51275fb11bad0dcff00bed1696c2d93d150fa97219e41a/README.en.md +23 -0
  56. package/vendor/components/sha256/1fac9a4c6608f0150a51275fb11bad0dcff00bed1696c2d93d150fa97219e41a/index.js +147 -0
  57. package/vendor/components/sha256/24e433f4e96427b5b4625ea6542ae74393a8610a9e3d331d01481b3185c827d4/README.en.md +66 -0
  58. package/vendor/components/sha256/24e433f4e96427b5b4625ea6542ae74393a8610a9e3d331d01481b3185c827d4/index.js +984 -0
  59. package/vendor/components/sha256/336f518ad98df0700348406a1fcc4a2de6843b68de0d2e6fcb2cf92428cc3f32/index.js +121 -0
  60. package/vendor/components/sha256/362590bb028486c9b92c90b0c04bb21c9989b7da1b9d234f0d3c26093770eb52/index.js +228 -0
  61. package/vendor/components/sha256/3c79d2605e1949c302a5e190dab3d12812e548af7d66e80dd73dc517dfa1ae3d/index.js +268 -0
  62. package/vendor/components/sha256/4526a332a77fce02370c58d6acd2b83777bfac10aca91e304f105ca2d6935e21/README.en.md +40 -0
  63. package/vendor/components/sha256/4526a332a77fce02370c58d6acd2b83777bfac10aca91e304f105ca2d6935e21/index.js +405 -0
  64. package/vendor/components/sha256/46fd8b2bfa296e18d7720dec9c9639421fb02cec1b641e50e2cadefcc3945675/README.en.md +31 -0
  65. package/vendor/components/sha256/46fd8b2bfa296e18d7720dec9c9639421fb02cec1b641e50e2cadefcc3945675/index.js +236 -0
  66. package/vendor/components/sha256/49fc5add9b34d9a34fcf9ffa3772da4a36d054feead033a7212b98ce1e18705d/index.js +465 -0
  67. package/vendor/components/sha256/4bedc6e22490461bb624d1801954aed230e9f47e393d2a9779c89c4c6483ab3e/README.en.md +42 -0
  68. package/vendor/components/sha256/4bedc6e22490461bb624d1801954aed230e9f47e393d2a9779c89c4c6483ab3e/index.js +549 -0
  69. package/vendor/components/sha256/5b3a29cd3ad1c572ba2864430fde589a0fa90f5a7cf6c8753ccfc97dd16d99f3/README.en.md +37 -0
  70. package/vendor/components/sha256/5b3a29cd3ad1c572ba2864430fde589a0fa90f5a7cf6c8753ccfc97dd16d99f3/index.js +501 -0
  71. package/vendor/components/sha256/6e9d8d26ba0427f26a8143ecaf1ff3a3fec1a6cb114ef5feed15a62f6a6e77c2/README.en.md +54 -0
  72. package/vendor/components/sha256/6e9d8d26ba0427f26a8143ecaf1ff3a3fec1a6cb114ef5feed15a62f6a6e77c2/index.js +470 -0
  73. package/vendor/components/sha256/9ffe48f7c39657aacbbca355c8268a4682f306c0e453bdd73b69c3ed7e0cb030/README.en.md +30 -0
  74. package/vendor/components/sha256/9ffe48f7c39657aacbbca355c8268a4682f306c0e453bdd73b69c3ed7e0cb030/index.js +192 -0
  75. package/vendor/components/sha256/a04ba1b59cae0406ad91c64da77df1f77d0ae6fb5629da4549452f68b926a20b/index.js +315 -0
  76. package/vendor/components/sha256/c129c1c6c5df8ddafed87ea41fe6f9fc03784b2904059321f970d16ff3238bf8/index.js +312 -0
  77. package/vendor/components/sha256/d831672acd189fd9e6bd294bdbceab539f4b2dc4ec0415e776a9fe740c499544/index.js +97 -0
  78. package/vendor/components/sha256/dc5d9e6da444ef49ac343c870271c6679601040bf3a38a389a7991ffd39dd0fc/index.js +607 -0
  79. package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/LICENSE-tabler.txt +21 -0
  80. package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/index.js +4868 -0
  81. package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/names.txt +4808 -0
  82. package/vendor/components/sha256/e76667b8fbaeb6c5d05ada81b2230f21388e2e68f3437034d2a54ead1c8ccbef/README.en.md +32 -0
  83. package/vendor/components/sha256/e76667b8fbaeb6c5d05ada81b2230f21388e2e68f3437034d2a54ead1c8ccbef/index.js +222 -0
  84. package/vendor/components-2/manifest-2.9.0.json +2204 -0
  85. package/vendor/components-2/manifest-2.9.1.json +2204 -0
  86. package/vendor/egatari-spec/SOURCE.json +3 -3
  87. package/vendor/themes/asagi/1.3.0/theme.json +14 -0
  88. package/vendor/themes/asagi/1.3.0/tokens.css +36 -0
  89. package/vendor/themes/bengara/1.0.0/theme.json +13 -0
  90. package/vendor/themes/bengara/1.0.0/tokens.css +66 -0
  91. package/vendor/themes/business/1.3.0/theme.json +5 -0
  92. package/vendor/themes/business/1.3.0/tokens.css +47 -0
  93. package/vendor/themes/default/1.5.0/README.ja.md +65 -0
  94. package/vendor/themes/default/1.5.0/README.md +65 -0
  95. package/vendor/themes/default/1.5.0/theme.json +4 -0
  96. package/vendor/themes/default/1.5.0/tokens.css +95 -0
  97. package/vendor/themes/kogecha/1.3.0/theme.json +10 -0
  98. package/vendor/themes/kogecha/1.3.0/tokens.css +35 -0
  99. package/vendor/themes/kokugo/1.3.0/theme.json +5 -0
  100. package/vendor/themes/kokugo/1.3.0/tokens.css +31 -0
  101. package/vendor/themes/murasaki/1.3.0/theme.json +10 -0
  102. package/vendor/themes/murasaki/1.3.0/tokens.css +31 -0
  103. package/vendor/themes/sumi/1.3.0/theme.json +10 -0
  104. package/vendor/themes/sumi/1.3.0/tokens.css +57 -0
  105. package/vendor/themes/tokiwa/1.3.0/theme.json +10 -0
  106. package/vendor/themes/tokiwa/1.3.0/tokens.css +33 -0
@@ -0,0 +1,121 @@
1
+ // m-collect:並んだ札(回答など)が動いて縮み、少数の箱(要約)にまとまる
2
+ // <m-collect style="height:400px"><script type="application/json">
3
+ // {"chips":[{"label":"回答 1","to":[0,1]}, …], "targets":[{"label":"事後平均","tex":"\\mu_n"}, …], "cols":4}
4
+ // (JSON の終わり)</m-collect>
5
+ // 段階 1 で、札 i が targets[to] へ動く(to は番号か番号の配列。配列なら札の写しがそれぞれへ動く)。
6
+ // 箱は始めに点線の枠だけ出し、札が着いてから中身(label / tex / value)を出す
7
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity を使い、プレイヤーのグローバルは使わない。
8
+ // 式(tex)は組み立てのときに KaTeX で描く(spec §6.2):build.fields の targets[].tex を作り手が描いて texHtml を足し、
9
+ // この部品は markup-reader で決まった要素と属性だけを読んで置く(再生のときに KaTeX は動かない)。描いた結果がなければ tex を字のまま出して知らせる
10
+ egatariParts.define({name: "collect", version: "2.0.4", requires: {base: "1.2.0", "markup-reader": "1.0.2"}, element: "m-collect"}, function(deps){
11
+ "use strict";
12
+ var base = deps.base, MR = deps["markup-reader"];
13
+ return class extends base.MotionElement {
14
+ static partName = "collect"; // the registry name (define meta name), for report prefixes
15
+ // 組み立てのときに描く欄(spec §6.2)。式の意味は字(tex)でも持つので、KaTeX の出力は HTML だけ
16
+ static build = {fields: {"targets[].tex": "katex"}, options: {katex: {output: "html"}}};
17
+ // データの形(kit/shape.js)
18
+ static shape = {
19
+ schema: {type: "object", additionalProperties: false, required: ["chips", "targets"], properties: {
20
+ chips: {type: "array", minItems: 1, items: {type: "object", required: ["to"], properties: {label: {type: "string"}, to: {type: ["integer", "array"], items: {type: "integer"}}}}},
21
+ targets: {type: "array", minItems: 1, items: {type: "object", properties: {label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, value: {type: ["string", "number"]}, tone: {type: "string"}, x: {type: "number"}, y: {type: "number"}}}},
22
+ cols: {type: "integer"}, renderers: {type: "object"}}},
23
+ example: {chips: [{label: "表", to: 0}, {label: "裏", to: 1}], targets: [{label: "表の数"}, {label: "裏の数"}], cols: 2},
24
+ };
25
+ static steps = 1;
26
+ static props = {
27
+ move: {type: "number", default: 0.9, doc: "札 1 枚が動く秒数"},
28
+ stagger: {type: "number", default: 0.08, doc: "札ごとの出発のずれ(秒)"},
29
+ shrink: {type: "number", default: 0.35, doc: "着いたときの札の縮尺"},
30
+ "chip-w": {type: "number", default: 0, doc: "札の幅(0 なら列の数から決める)"},
31
+ "chip-h": {type: "number", default: 56, doc: "札の高さ"},
32
+ "box-w": {type: "number", default: 260, doc: "箱の幅"},
33
+ "box-h": {type: "number", default: 110, doc: "箱の高さ"},
34
+ };
35
+ mount(ctx){
36
+ var P = this.props, D = base, self = this, data = this.data || {chips: [], targets: []}, sk = MR.sink(this, ctx);
37
+ this.style.display = "block";
38
+ var W = this.clientWidth, H = this.clientHeight;
39
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"}, this);
40
+ var tone = {term: ["var(--term)", "var(--term-tint)"], emph: ["var(--emph)", "var(--emph-tint)"], muted: ["var(--muted)", "var(--bg)"]};
41
+ // 札の並び:上の段に cols 列で並べる
42
+ var C = data.chips || [], n = C.length, cols = data.cols || n, rows = Math.ceil(n / cols), gap = 14;
43
+ var cw = P["chip-w"] || Math.max(0, Math.min(220, (W - gap * (cols - 1)) / cols)), ch = P["chip-h"];
44
+ var gx = (W - (cw * cols + gap * (cols - 1))) / 2;
45
+ // 箱の並び:下の段に等間隔(x, y を書けばその位置。中心の座標)
46
+ var T = data.targets || [], bw = P["box-w"], bh = P["box-h"];
47
+ // tex と label のある箱は label を箱の下に書くので、その分(36 px)だけ下の段を上げる(要素の下にはみ出さない)
48
+ var gR = D.el("g", {}, svg); // 残る札(箱より下に重ねる。札の段が箱にかかっても箱の字は隠れない)
49
+ var under = T.some(function(tg){ return tg.tex && tg.label && tg.y === undefined; }) ? 36 : 0;
50
+ this.targets = T.map(function(tg, j){
51
+ var cx = tg.x !== undefined ? tg.x : W * (j + 1) / (T.length + 1), cy = tg.y !== undefined ? tg.y : H - bh / 2 - 4 - under;
52
+ var c = tone[tg.tone || "emph"] || tone.emph;
53
+ var frame = D.el("rect", {x: cx - bw / 2, y: cy - bh / 2, width: bw, height: bh, rx: 12, fill: "none", stroke: "var(--line)", "stroke-width": 2, "stroke-dasharray": "8 6", opacity: 0}, svg);
54
+ var g = D.el("g", {opacity: 0}, svg);
55
+ D.el("rect", {x: cx - bw / 2, y: cy - bh / 2, width: bw, height: bh, rx: 12, fill: c[1], stroke: c[0], "stroke-width": 3}, g);
56
+ var hasV = tg.value !== undefined, ly = cy + (hasV ? -16 : 9);
57
+ if (tg.tex) MR.texFrame(g, cx, ly + 4, tg, "tex", {size: 30, anchor: "middle", color: c[0], w: bw, h: 50}, sk).firstChild.style.verticalAlign = "top";
58
+ else D.mtext(g, cx, ly, tg.label || "", {"text-anchor": "middle", "font-size": 28, "font-weight": 700, fill: c[0]});
59
+ if (hasV) D.mtext(g, cx, cy + 38, String(tg.value), {"text-anchor": "middle", "font-size": 24, fill: "var(--fg)"});
60
+ // 下に入らなければ(y を書いた箱)箱の上に
61
+ if (tg.tex && tg.label) D.mtext(g, cx, cy + bh / 2 + 32 + 4 <= H ? cy + bh / 2 + 32 : cy - bh / 2 - 10, tg.label, {"text-anchor": "middle", "font-size": 24, fill: "var(--muted)"});
62
+ return {frame: frame, g: g, cx: cx, cy: cy, col: c, last: 0};
63
+ });
64
+ // 札と、行き先ごとの写し。もとの札は元の場所に薄い枠で残る(動いた後も、何を集めたかが図に残る。印刷でも読める)
65
+ this.chips = []; this.rests = [];
66
+ var badTo = [];
67
+ C.forEach(function(cp, i){
68
+ var r = Math.floor(i / cols), q = i % cols;
69
+ var x = gx + q * (cw + gap) + cw / 2, y = 4 + ch / 2 + r * (ch + gap);
70
+ var to = Array.isArray(cp.to) ? cp.to : [cp.to === undefined ? 0 : cp.to];
71
+ var start = i * P.stagger;
72
+ to.forEach(function(j){ if (!self.targets[j]) badTo.push("chip " + i + " (" + JSON.stringify(cp.label || "") + "): to " + JSON.stringify(j)); });
73
+ if (to.some(function(j){ return self.targets[j]; })){
74
+ var rg = D.el("g", {transform: "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ")", opacity: 0}, gR);
75
+ D.el("rect", {x: -cw / 2, y: -ch / 2, width: cw, height: ch, rx: 8, fill: "none", stroke: "var(--line)", "stroke-width": 2, "stroke-dasharray": "6 5"}, rg);
76
+ D.mtext(rg, 0, 9, cp.label || "", {"text-anchor": "middle", "font-size": 24, fill: "var(--muted)"});
77
+ self.rests.push({g: rg, start: start});
78
+ }
79
+ to.forEach(function(j){
80
+ var tg = self.targets[j]; if (!tg) return;
81
+ var c = tone[cp.tone || "term"] || tone.term;
82
+ var g = D.el("g", {}, svg);
83
+ D.el("rect", {x: -cw / 2, y: -ch / 2, width: cw, height: ch, rx: 8, fill: c[1], stroke: c[0], "stroke-width": 2}, g);
84
+ D.mtext(g, 0, 9, cp.label || "", {"text-anchor": "middle", "font-size": 24});
85
+ tg.last = Math.max(tg.last, start + P.move);
86
+ self.chips.push({g: g, x0: x, y0: y, x1: tg.cx, y1: tg.cy, start: start});
87
+ });
88
+ });
89
+ if (badTo.length) ctx.report("data", "[collect] " + badTo.join("; ") + ": not a target number 0–" + (T.length - 1) + " (the copy is not drawn)");
90
+ this.rows = rows;
91
+ sk.flush(); // what the formulas have to report, once per kind (spec §6.2)
92
+ }
93
+ duration(k){ var d = 0; this.targets.forEach(function(tg){ d = Math.max(d, tg.last + 0.3); }); return k >= 1 ? d : 0; }
94
+ render(k, t, ctx){
95
+ var P = this.props, D = base;
96
+ var T = k < 1 ? -Infinity : t; // 段階 0 は動く前
97
+ // 先の段階を薄く見せる表示(授業の表示):段階 0 では、まとめた後の箱をテーマの --preview-opacity の濃さで出す(札は動かさない)
98
+ var PV = 0;
99
+ if (k < 1 && ctx.preview) PV = base.previewOpacity(this);
100
+ var pr = function(start, dur){ return T === -Infinity ? 0 : D.prog(T, start, dur); };
101
+ this.chips.forEach(function(c){
102
+ var e = pr(c.start, P.move);
103
+ // 少し持ち上げてから落ちる弧(中点で上へ 40px)
104
+ var x = D.lerp(c.x0, c.x1, e), y = D.lerp(c.y0, c.y1, e) - Math.sin(Math.PI * e) * 40;
105
+ var s = D.lerp(1, P.shrink, e), op = e < 0.75 ? 1 : 1 - (e - 0.75) / 0.25;
106
+ c.g.setAttribute("transform", "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ") scale(" + s.toFixed(4) + ")");
107
+ c.g.setAttribute("opacity", op.toFixed(3));
108
+ });
109
+ // 残る札:写しが出発したら現れる
110
+ this.rests.forEach(function(c){ c.g.setAttribute("opacity", Math.min(1, pr(c.start, P.move) * 4).toFixed(3)); });
111
+ this.targets.forEach(function(tg){
112
+ tg.frame.setAttribute("opacity", (pr(0, 0.3) * (1 - pr(tg.last - 0.1, 0.3))).toFixed(3));
113
+ var e = pr(tg.last - 0.15, 0.45);
114
+ if (PV){ e = 1; tg.g.setAttribute("opacity", PV.toFixed(3)); }
115
+ else tg.g.setAttribute("opacity", e.toFixed(3));
116
+ var s = D.lerp(0.9, 1, e);
117
+ tg.g.setAttribute("transform", "translate(" + tg.cx + " " + tg.cy + ") scale(" + s.toFixed(4) + ") translate(" + (-tg.cx) + " " + (-tg.cy) + ")");
118
+ });
119
+ }
120
+ };
121
+ });
@@ -0,0 +1,228 @@
1
+ // m-tape:テープ図・線分図。行の長さは全部の行で同じ尺度。全体や部分を括る括弧と名前、行から行への「2 倍」の矢印
2
+ // <m-tape style="height:360px">
3
+ // <script type="application/json">{"rows": [{"label": "みかん", "segs": [{"v": 8, "label": "食べた 8 こ"}, {"v": 15, "label": "のこり 15 こ"}]}],
4
+ // "brace": [{"row": 0, "from": 0, "to": 1, "label": "はじめ □ こ", "side": "above"}]}
5
+ // (JSON の終わり)</m-tape>
6
+ // 段階:build="steps"(既定)は 行を 1 つずつ → 括弧を 1 つずつ → 倍の矢印を 1 つずつ。build="rows" は行を 1 つずつ(括弧と矢印はその行と)、
7
+ // build="whole" は全部を 1 段階で。項目の show で段階を指定できる
8
+ // kind="tape"(既定、テープ図)か "line"(線分図)
9
+ // 見せ方(docs/conventions.md §1):fade(フェード、既定)・grow(テープが左から伸び、括弧と矢印は線を引く)
10
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
11
+ // データや大きさの問題は ctx.report で知らせる(1.x の console.warn の代わり)
12
+ egatariParts.define({name: "tape", version: "2.0.4", requires: {base: "1.2.0"}, element: "m-tape"}, function(deps){
13
+ "use strict";
14
+ var base = deps.base;
15
+ // 字の幅(base の textWidth:font の要素の字で測った幅。字は mtext で書くので *_^ は数えない)
16
+ var est = function(s, size, font){ return base.textWidth(s, size, {font: font, mark: true}); };
17
+ var TONES = /^(term|emph|muted|accent2|fg|series-[1-4])$/;
18
+ var UNK = ["?", "□"];
19
+ return class extends base.MotionElement {
20
+ static partName = "tape"; // the registry name (define meta name), for report prefixes
21
+ static variants = ["fade", "grow"];
22
+ static shape = {
23
+ schema: {type: "object", additionalProperties: false, required: ["rows"], properties: {
24
+ rows: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["segs"], properties: {
25
+ label: {type: "string"}, tone: {type: "string"}, show: {type: "integer"},
26
+ segs: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["v"], properties: {
27
+ v: {type: "number"}, label: {type: "string"}, unknown: {type: "string"}}}}}}},
28
+ brace: {type: "array", items: {type: "object", additionalProperties: false, required: ["row", "from", "to"], properties: {
29
+ row: {type: "integer"}, from: {type: "integer"}, to: {type: "integer"}, label: {type: "string"}, side: {type: "string", enum: ["above", "below"]}, show: {type: "integer"}}}},
30
+ times: {type: "array", items: {type: "object", additionalProperties: false, required: ["from", "to"], properties: {
31
+ from: {type: "integer"}, to: {type: "integer"}, label: {type: "string"}, show: {type: "integer"}}}}}},
32
+ example: {rows: [{label: "みかん", segs: [{v: 8, label: "食べた 8 こ"}, {v: 15, label: "のこり 15 こ"}]}], brace: [{row: 0, from: 0, to: 1, label: "はじめ □ こ", side: "above"}]},
33
+ note: {en: "rows [{label, segs: [{v, label, unknown: \"?\" | \"□\"}]}]; brace [{row, from, to, label, side: above|below}] (from/to are segment numbers from 0); times [{from, to, label}] (row numbers)",
34
+ ja: "rows [{label, segs: [{v, label, unknown: \"?\" か \"□\"}]}]、brace [{row, from, to, label, side: above|below}](from・to は 0 から数えた区切りの番号)、times [{from, to, label}](行の番号)"},
35
+ };
36
+ static props = {
37
+ kind: {type: "string", default: "tape", doc: "tape(テープ図)か line(線分図)"},
38
+ build: {type: "string", default: "steps", doc: "steps(行・括弧・矢印を 1 つずつ)・rows(行を 1 つずつ。括弧と矢印はその行と)・whole(全部を 1 ステップで)"},
39
+ dur: {type: "number", default: 0.8, doc: "1 ステップの動きの秒数"},
40
+ };
41
+ get steps(){
42
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
43
+ return this.plan().steps;
44
+ }
45
+ plan(){
46
+ if (this._plan) return this._plan;
47
+ var d = this.data || {}, P = this.props, notes = [];
48
+ var rows = d.rows.map(function(r, i){
49
+ r.segs.forEach(function(s){ if (s.unknown !== undefined && UNK.indexOf(s.unknown) < 0) notes.push('[tape] unknown "' + s.unknown + '" is not "?" or "□" ("?" is used)'); if (!(s.v > 0)) throw new Error("m-tape: a segment's v must be a positive number (" + s.v + ")"); });
50
+ return {i: i, o: r};
51
+ });
52
+ var R = rows.length;
53
+ var braces = (d.brace || []).filter(function(b){
54
+ if (b.row < 0 || b.row >= R){ notes.push("[tape] brace row " + b.row + " does not exist (ignored)"); return false; }
55
+ var n = rows[b.row].o.segs.length;
56
+ if (b.from < 0 || b.to >= n || b.from > b.to){ notes.push("[tape] brace from " + b.from + " to " + b.to + " is not a segment range of row " + b.row + " (0 to " + (n - 1) + ")"); return false; }
57
+ if (b.side !== undefined && b.side !== "above" && b.side !== "below"){ notes.push('[tape] brace side "' + b.side + '" is not above or below'); }
58
+ return true;
59
+ }).map(function(b){ return {o: b, row: b.row, side: b.side === "below" ? "below" : "above"}; });
60
+ var times = (d.times || []).filter(function(x){
61
+ var ok = x.from >= 0 && x.from < R && x.to >= 0 && x.to < R && x.from !== x.to;
62
+ if (!ok) notes.push("[tape] times from " + x.from + " to " + x.to + " needs two different rows (ignored)");
63
+ return ok;
64
+ }).map(function(x){ return {o: x}; });
65
+ var build = P.build;
66
+ if (["steps", "rows", "whole"].indexOf(build) < 0){ notes.push('[tape] build="' + build + '" is not steps, rows or whole (steps is used)'); build = "steps"; }
67
+ var sh = function(o){ return Number.isInteger(o.show) && o.show >= 1 ? o.show : null; };
68
+ var k = 0;
69
+ rows.forEach(function(r){ r.st = sh(r.o) || (build === "whole" ? 1 : ++k); });
70
+ braces.forEach(function(b){ b.st = sh(b.o) || (build === "whole" ? 1 : build === "rows" ? rows[b.row].st : ++k); });
71
+ times.forEach(function(x){ x.st = sh(x.o) || (build === "whole" ? 1 : build === "rows" ? Math.max(rows[x.o.from].st, rows[x.o.to].st) : ++k); });
72
+ var steps = Math.max.apply(null, [1].concat(rows.map(function(r){ return r.st; }), braces.map(function(b){ return b.st; }), times.map(function(x){ return x.st; })));
73
+ return (this._plan = {rows: rows, braces: braces, times: times, steps: steps, notes: notes});
74
+ }
75
+ duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
76
+ // 最後の形を 1 文で(読み上げの名前):「テープ図:A 12 m、B 12 m+5 m、B 全体 □ m」。区切りは図に書く字(? □ と名前)を+でつなぎ、
77
+ // 字のない区切りは書かない。括弧は行の名前と括弧の名前、倍の矢印は「A→B 2 倍」
78
+ summary(ja, line){
79
+ var pl = this.plan(), rows = pl.rows, sep = ja ? "、" : ", ";
80
+ var segText = function(s){ return [s.unknown !== undefined ? (UNK.indexOf(s.unknown) >= 0 ? s.unknown : "?") : "", s.label || ""].filter(Boolean).join(" "); };
81
+ var name = function(i){ return rows[i].o.label || (ja ? (i + 1) + " 行目" : "row " + (i + 1)); };
82
+ var out = rows.map(function(r, i){
83
+ var segs = r.o.segs.map(segText).filter(Boolean);
84
+ return [r.o.label || (rows.length > 1 || !segs.length ? name(i) : ""), segs.join(ja ? "+" : " + ")].filter(Boolean).join(" ");
85
+ });
86
+ pl.braces.forEach(function(b){ if (b.o.label) out.push((rows[b.row].o.label || rows.length > 1 ? name(b.row) + " " : "") + b.o.label); });
87
+ pl.times.forEach(function(x){ out.push(name(x.o.from) + "→" + name(x.o.to) + (x.o.label ? " " + x.o.label : "")); });
88
+ return (line ? (ja ? "線分図" : "Line diagram") : (ja ? "テープ図" : "Tape diagram")) + (ja ? ":" : ": ") + out.join(sep);
89
+ }
90
+ mount(ctx){
91
+ var P = this.props, D = base, self = this, pl = this.plan();
92
+ this.variant = base.variant(this);
93
+ pl.notes.forEach(function(n){ ctx.report("data", n); });
94
+ var line = P.kind === "line";
95
+ if (P.kind !== "tape" && P.kind !== "line") ctx.report("data", '[tape] kind="' + P.kind + '" is not tape or line (tape is used)');
96
+ this.style.display = "block";
97
+ var W = this.clientWidth, H = this.clientHeight, dur = P.dur, grow = this.variant === "grow";
98
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
99
+ // 読み上げ:最後の形(行ごとの区切り、括弧、倍の矢印)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
100
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
101
+ this.setAttribute("role", "img");
102
+ if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja"), line));
103
+ var items = this.items = [];
104
+ var add = function(el, o){ o.el = el; items.push(o); return el; };
105
+ var FS = 24, ROW = 34, BR = 16, BLV = BR + 6 + ROW + 6;
106
+ var rows = pl.rows, labW = Math.max.apply(null, [0].concat(rows.map(function(r){ return r.o.label ? est(r.o.label, 26, self) : 0; })));
107
+ // 倍の矢印は行の左の端(どの行もそろう)を結ぶ。名前はその左に
108
+ var tW = pl.times.length ? Math.max.apply(null, pl.times.map(function(x){ return x.o.label ? est(x.o.label, 26, self) + 14 : 0; })) + 52 : 0;
109
+ var x0 = (labW ? labW + 28 : 8) + tW, labX = tW ? labW + 8 : x0 - 18; // 矢印があれば行の名前は左の列に
110
+ var mR = 10;
111
+ var maxT = Math.max.apply(null, rows.map(function(r){ return r.o.segs.reduce(function(a, s){ return a + s.v; }, 0); }));
112
+ var sc = (W - x0 - mR) / maxT;
113
+ // 区切りの中身(□ の枠・?・名前)と幅
114
+ var content = function(s){
115
+ var parts = [];
116
+ if (s.unknown !== undefined) parts.push(s.unknown === "□" ? {box: true, w: 30} : {t: "?", w: est("?", 28, self), q: true});
117
+ if (s.label) parts.push({t: s.label, w: est(s.label, FS, self)});
118
+ return {parts: parts, w: parts.reduce(function(a, p){ return a + p.w; }, 0) + 8 * Math.max(0, parts.length - 1)};
119
+ };
120
+ // 行ごとの寸法
121
+ rows.forEach(function(r){
122
+ var x = x0;
123
+ r.segs = r.o.segs.map(function(s){ var o = {s: s, x: x, w: s.v * sc, c: content(s)}; x += o.w; return o; });
124
+ r.end = x;
125
+ r.tapeH = line ? 24 : 52;
126
+ r.out = line ? r.segs.some(function(g){ return g.c.parts.length; }) : r.segs.some(function(g){ return g.c.parts.length && g.c.w + 14 > g.w; });
127
+ r.segs.forEach(function(g){ g.outside = line || g.c.w + 14 > g.w; });
128
+ var lv = function(side){
129
+ var bs = pl.braces.filter(function(b){ return b.row === r.i && b.side === side; });
130
+ bs.sort(function(a, b){ return (a.o.to - a.o.from) - (b.o.to - b.o.from); });
131
+ var placed = [];
132
+ bs.forEach(function(b){
133
+ var l = 0;
134
+ while (placed.some(function(p){ return p.lv === l && p.o.from <= b.o.to && b.o.from <= p.o.to; })) l++;
135
+ b.lv = l; placed.push(b);
136
+ });
137
+ return bs.length ? Math.max.apply(null, bs.map(function(b){ return b.lv; })) + 1 : 0;
138
+ };
139
+ r.upN = lv("above"); r.downN = lv("below");
140
+ r.above = (r.out ? ROW + 8 : 0) + r.upN * BLV;
141
+ r.below = r.downN * BLV;
142
+ r.h = r.above + r.tapeH + r.below;
143
+ });
144
+ var need = rows.reduce(function(a, r){ return a + r.h; }, 0) + 24 * (rows.length - 1) + 8;
145
+ if (need > H + 1) ctx.report("size", "[tape] the element (" + W + "×" + H + " px) is too small; it needs about " + Math.ceil(need) + " px of height");
146
+ var gap = rows.length > 1 ? Math.min(60, 24 + Math.max(0, H - need) / (rows.length + 1)) : 0;
147
+ var total = rows.reduce(function(a, r){ return a + r.h; }, 0) + gap * (rows.length - 1);
148
+ var y = Math.max(4, (H - total) / 2);
149
+ rows.forEach(function(r){ r.top = y + r.above; r.cy = r.top + r.tapeH / 2; y += r.h + gap; });
150
+ var gT = D.el("g", {}, svg), gS = D.el("g", {}, svg), gA = D.el("g", {}, svg), gX = D.el("g", {}, svg);
151
+ var drawContent = function(par, cx, base, c){
152
+ var x = cx - c.w / 2;
153
+ c.parts.forEach(function(p){
154
+ if (p.box) D.el("rect", {x: x.toFixed(1), y: (base - 25).toFixed(1), width: 30, height: 30, rx: 2, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 2.5}, par);
155
+ else D.mtext(par, x + p.w / 2, base, p.t, {"text-anchor": "middle", "font-size": p.q ? 28 : FS, "font-weight": p.q ? 700 : 400, fill: "var(--fg)"});
156
+ x += p.w + 8;
157
+ });
158
+ };
159
+ rows.forEach(function(r, ri){
160
+ var col = TONES.test(r.o.tone || "") ? "var(--" + r.o.tone + ")" : "var(--series-" + (ri % 4 + 1) + ")", st = r.st, n = r.segs.length;
161
+ if (r.o.label) add(D.mtext(gX, labX, r.cy + 9, r.o.label, {"text-anchor": "end", "font-size": 26, "font-weight": 700, fill: "var(--fg)", opacity: 0}), {st: st, at: 0, len: dur * 0.5, kind: "fade"});
162
+ r.segs.forEach(function(g, j){
163
+ var at = grow ? dur * 0.75 * j / n : 0, len = grow ? dur * 0.75 / n : dur * 0.7;
164
+ if (!line){
165
+ var rect = D.el("rect", {x: g.x.toFixed(1), y: r.top.toFixed(1), width: Math.max(0, g.w).toFixed(1), height: r.tapeH, fill: col, "fill-opacity": 0.14, stroke: "var(--fg)", "stroke-width": 2.5, opacity: 0}, gS);
166
+ add(rect, {st: st, at: at, len: len, kind: "seg", w: g.w});
167
+ } else {
168
+ add(D.el("line", {x1: g.x.toFixed(1), x2: (g.x + g.w).toFixed(1), y1: r.cy.toFixed(1), y2: r.cy.toFixed(1), stroke: col, "stroke-width": 4, opacity: 0}, gS), {st: st, at: at, len: len, kind: "line"});
169
+ [g.x, g.x + g.w].forEach(function(x, e){
170
+ if (e === 0 && j > 0) return;
171
+ add(D.el("line", {x1: x.toFixed(1), x2: x.toFixed(1), y1: (r.cy - 12).toFixed(1), y2: (r.cy + 12).toFixed(1), stroke: "var(--fg)", "stroke-width": 3, opacity: 0}, gS), {st: st, at: grow ? (e ? at + len * 0.8 : at) : 0, len: grow ? dur * 0.15 : dur * 0.7, kind: "fade"});
172
+ });
173
+ }
174
+ if (g.c.parts.length){
175
+ var cg = D.el("g", {opacity: 0}, gT), base = g.outside ? r.top - 8 - ROW + 25 : r.cy + 9;
176
+ var cx = Math.max(x0 + g.c.w / 2, Math.min(W - g.c.w / 2 - 2, g.x + g.w / 2));
177
+ drawContent(cg, cx, base, g.c);
178
+ add(cg, {st: st, at: grow ? at + len * 0.6 : dur * 0.2, len: grow ? Math.max(0.15, dur * 0.25) : dur * 0.5, kind: "fade"});
179
+ }
180
+ });
181
+ // 括弧
182
+ pl.braces.filter(function(b){ return b.row === ri; }).forEach(function(b){
183
+ var xa = r.segs[b.o.from].x + 2, xb = r.segs[b.o.to].x + r.segs[b.o.to].w - 2, up = b.side === "above", dsg = up ? -1 : 1;
184
+ var yb = up ? r.top - (r.out ? ROW + 8 : 0) - 6 - b.lv * BLV : r.top + r.tapeH + 6 + b.lv * BLV;
185
+ var xm = (xa + xb) / 2, q = BR, rr = Math.min(12, (xb - xa) / 4), f = function(v){ return v.toFixed(1); };
186
+ var d = "M" + f(xa) + "," + f(yb) + "Q" + f(xa) + "," + f(yb + dsg * q / 2) + " " + f(xa + rr) + "," + f(yb + dsg * q / 2) + "L" + f(xm - rr) + "," + f(yb + dsg * q / 2) +
187
+ "Q" + f(xm) + "," + f(yb + dsg * q / 2) + " " + f(xm) + "," + f(yb + dsg * q) + "Q" + f(xm) + "," + f(yb + dsg * q / 2) + " " + f(xm + rr) + "," + f(yb + dsg * q / 2) +
188
+ "L" + f(xb - rr) + "," + f(yb + dsg * q / 2) + "Q" + f(xb) + "," + f(yb + dsg * q / 2) + " " + f(xb) + "," + f(yb);
189
+ add(D.el("path", {d: d, fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linejoin": "round", opacity: 0}, gA), {st: b.st, at: 0, len: dur * 0.6, kind: "line"});
190
+ if (b.o.label){
191
+ var c = content({label: b.o.label}), cx = Math.max(c.w / 2 + 2, Math.min(W - c.w / 2 - 2, xm)), base = up ? yb - q - 6 - ROW + 25 : yb + q + 6 + 25;
192
+ var cg = D.el("g", {opacity: 0}, gT);
193
+ drawContent(cg, cx, base, c);
194
+ add(cg, {st: b.st, at: dur * 0.3, len: dur * 0.5, kind: "fade"});
195
+ }
196
+ });
197
+ });
198
+ // 倍の矢印:行の左の端から端へ、左にふくらむ弧
199
+ pl.times.forEach(function(x){
200
+ var a = rows[x.o.from], b = rows[x.o.to], xs = x0 - 8, xc = x0 - 44, ya = a.cy, yb = b.cy;
201
+ add(D.el("path", {d: "M" + xs.toFixed(1) + "," + ya.toFixed(1) + "C" + xc.toFixed(1) + "," + ya.toFixed(1) + " " + xc.toFixed(1) + "," + yb.toFixed(1) + " " + (xs - 10).toFixed(1) + "," + yb.toFixed(1),
202
+ fill: "none", stroke: "var(--emph)", "stroke-width": 3, "stroke-linecap": "round", opacity: 0}, gA), {st: x.st, at: 0, len: dur * 0.6, kind: "line"});
203
+ add(D.el("path", {d: "M" + xs.toFixed(1) + "," + yb.toFixed(1) + "l-14,-7v14Z", fill: "var(--emph)", opacity: 0}, gA), {st: x.st, at: dur * 0.5, len: dur * 0.2, kind: "fade"});
204
+ if (x.o.label){
205
+ var lx = 0.75 * xc + 0.125 * (xs + xs - 10) - 12;
206
+ add(D.mtext(gT, lx, (ya + yb) / 2 + 9, x.o.label, {"text-anchor": "end", "font-size": 26, "font-weight": 700, fill: "var(--fg)", opacity: 0}), {st: x.st, at: dur * 0.3, len: dur * 0.5, kind: "fade"});
207
+ }
208
+ });
209
+ if (grow) items.forEach(function(it){ if (it.kind === "line") it.el.setAttribute("pathLength", 1); });
210
+ }
211
+ render(k, t, ctx){
212
+ var D = base, lecture = !!ctx.preview, grow = this.variant === "grow", FAINT = 0.45;
213
+ if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
214
+ this.items.forEach(function(it){
215
+ var e = it.st < k ? 1 : it.st > k ? (lecture ? -1 : 0) : D.prog(t, it.at, it.len), op;
216
+ if (e < 0){ op = FAINT; e = 1; } else op = e;
217
+ if (grow && it.kind === "seg"){
218
+ it.el.setAttribute("width", Math.max(0, it.w * e).toFixed(1));
219
+ op = e > 0 ? (op === FAINT && it.st > k ? FAINT : 1) : 0;
220
+ } else if (grow && it.kind === "line"){
221
+ it.el.setAttribute("stroke-dasharray", e >= 1 ? "none" : e.toFixed(4) + " 2");
222
+ op = e > 0 ? (op === FAINT && it.st > k ? FAINT : 1) : 0;
223
+ }
224
+ it.el.setAttribute("opacity", op.toFixed(3));
225
+ });
226
+ }
227
+ };
228
+ });