egatari 0.6.18 → 0.6.19

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 (54) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/components.lock.json +34 -9
  3. package/components2.lock.json +363 -1
  4. package/kit/build.mjs +1 -1
  5. package/kit/check-messages.mjs +4 -0
  6. package/kit/check.mjs +3 -1
  7. package/kit/core/build-core.mjs +1 -1
  8. package/kit/core/check-parity.mjs +2 -0
  9. package/kit/core/check-rules.mjs +1 -1
  10. package/kit/core/check-source.mjs +4 -1
  11. package/kit/core/checks.mjs +79 -0
  12. package/kit/core/find-replace.mjs +170 -0
  13. package/kit/core/format.mjs +4 -1
  14. package/kit/core/image-insert.mjs +197 -0
  15. package/kit/core/image-size.mjs +1 -1
  16. package/kit/core/layout-scan.mjs +1 -1
  17. package/kit/core/llm-fix.mjs +1 -1
  18. package/kit/core/llm-pack-assemble.mjs +3 -1
  19. package/kit/core/llm-pack-data.mjs +51 -15
  20. package/kit/core/part-labels.mjs +1 -0
  21. package/kit/core/portable.mjs +5 -2
  22. package/kit/core/scorm.mjs +30 -6
  23. package/kit/core/script-unclosed.mjs +49 -0
  24. package/kit/core/slide-ops.mjs +5 -1
  25. package/kit/core/template-text.mjs +2 -0
  26. package/kit/deck.js +71 -4
  27. package/kit/instruction-version.json +1 -1
  28. package/kit/layouts.css +8 -0
  29. package/kit/panes.js +17 -1
  30. package/kit/player.json +1 -1
  31. package/kit/player.lock.json +2 -2
  32. package/kit/track.js +46 -5
  33. package/package.json +1 -1
  34. package/server/editor-ui.js +21 -1
  35. package/vendor/components/CATALOG.md +3 -2
  36. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  37. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  38. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  39. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  40. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  41. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  42. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  43. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  44. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  45. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  46. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  47. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  48. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  49. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  50. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  51. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  52. package/vendor/egatari-spec/SOURCE.json +2 -2
  53. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  54. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,397 @@
1
+ // m-predict:予想してから答えを開く。問いと選択肢、クラスの数(手を挙げた人数)を選択肢ごとの棒で見せ、作者の書いた段階で答えを開く
2
+ // <m-predict unit="人" style="height:440px"><script type="application/json">
3
+ // {"question": "重い球と軽い球、どちらが先に落ちる?",
4
+ // "choices": [{"label": "重い球"}, {"label": "軽い球"}, {"label": "同時"}],
5
+ // "answer": 2, "counts": [14, 3, 9], "note": "空気の抵抗を除けば、重さによらず同時に落ちる(ガリレオ)"}
6
+ // (JSON の終わり)</m-predict>
7
+ // 段階:0 = 問いと選択肢(と目盛り)。1 = 数の棒。answer-step(既定 2)= 答え(正しい選択肢に枠と ✓、ほかは薄く、note)
8
+ // 見る人の入力(仕様 §8.4「Viewer input」、Studio の約束事 §3):選択肢ごとの −1・+1 と数の欄(発表者が数える)、選択肢の名前を押すと「自分の予想」。
9
+ // 入力は (i, k, t) の外で、同じスライドにいるあいだは(段階を進めても戻っても)残る。ほかのスライドから入ったとき・飛んだとき(ctx.entered)だけ作者の counts に戻る。
10
+ // ctx.reset(触った部品を段階に入るときに戻す)では、触った跡(欄やボタンのフォーカス)だけを戻し、数と予想は残す(仕様 §8.4)
11
+ // 動画(?mode=video)では操作を作らず、input() も受け付けない。印刷では操作を隠し、作者の数を字で出す
12
+ // live(拡張 live §2.5):poll="p1" と書き、ctx.live があれば ctx.live.poll("p1") の数(number[] | null)を棒に出す。
13
+ // 見せてよいか(先生が見せると決めたか、3 人以上か)は実行系が決める。部品は配列が来たときだけ出し、動画・印刷では出さない
14
+ // 見せ方(docs/conventions.md §1):fade(0。棒と答えの印がフェードして現れる)・draw(棒が上の選択肢から順に現れ、答えの枠を線で引く。長さは同じ)
15
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・variant を使い、プレイヤーのグローバルは使わない。
16
+ // 見る人の入力を戻すのは ctx.entered だけ(1.x の deck:pos の代わりはない)。動画かどうかは mount の ctx.mode。
17
+ // 要素の大きさの問題は ctx.report("size", …)。印刷の前後は document.defaultView の beforeprint・afterprint
18
+ egatariParts.define({name: "predict", version: "2.2.0", requires: {base: "1.3.0"}, element: "m-predict"}, function(deps){
19
+ "use strict";
20
+ var base = deps.base;
21
+ // 表示の文字(ctx.lang、見る人の言語ではなく文書の言語)。correct は子の JSON の labels.correct で上書きできる
22
+ var TEXT = {
23
+ ja: {
24
+ correct: "✓ 正解",
25
+ noteWrong: "予想ははずれ。", noteRight: "予想は当たり。",
26
+ liveResults: "投票の結果",
27
+ guessLabel: function(label){ return "予想:" + label; },
28
+ countGroup: function(label){ return label + "の数"; },
29
+ countField: function(label, unit){ return label + "の数" + (unit ? "(" + unit + ")" : ""); },
30
+ decrease: function(label){ return label + ":1 減らす"; },
31
+ increase: function(label){ return label + ":1 増やす"; },
32
+ countAnnounce: function(label, v, unit){ return label + ":" + v + unit; },
33
+ unpicked: "予想を外しました",
34
+ pickedRight: function(label){ return "当たり:" + label; },
35
+ pickedWrong: function(label){ return "はずれ。答えは " + label; },
36
+ myGuess: function(label){ return "あなたの予想:" + label; },
37
+ answerAnnounce: function(label, note){ return "答え:" + label + (note ? "。" + note : ""); },
38
+ },
39
+ en: {
40
+ correct: "✓ Correct",
41
+ noteWrong: "Wrong. ", noteRight: "Right! ",
42
+ liveResults: "Poll results",
43
+ guessLabel: function(label){ return "Guess: " + label; },
44
+ countGroup: function(label){ return label + " count"; },
45
+ countField: function(label, unit){ return label + " count" + (unit ? " (" + unit + ")" : ""); },
46
+ decrease: function(label){ return label + ": decrease by 1"; },
47
+ increase: function(label){ return label + ": increase by 1"; },
48
+ countAnnounce: function(label, v, unit){ return label + ": " + v + (unit ? " " + unit : ""); },
49
+ unpicked: "Guess cleared",
50
+ pickedRight: function(label){ return "Correct: " + label; },
51
+ pickedWrong: function(label){ return "Wrong. The answer is " + label; },
52
+ myGuess: function(label){ return "My guess: " + label; },
53
+ answerAnnounce: function(label, note){ return "Answer: " + label + (note ? ". " + note : ""); },
54
+ }
55
+ };
56
+ var CSS_ID = "predict-2-1-1-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
57
+ var CSS = [
58
+ "m-predict .pd-say{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}",
59
+ "m-predict .pd-pick{position:absolute;background:transparent;border:0;border-radius:10px;cursor:pointer;padding:0;margin:0}",
60
+ "m-predict .pd-pick:focus-visible,m-predict .pd-btn:focus-visible,m-predict .pd-num:focus-visible{outline:3px solid var(--emph);outline-offset:2px}",
61
+ "m-predict .pd-ctl{position:absolute;display:flex;gap:8px;align-items:center;height:48px}",
62
+ "m-predict .pd-btn{width:60px;height:48px;font:700 27px/1 var(--font-cap,var(--font-sans,sans-serif));color:var(--fg);background:var(--bg);border:2px solid var(--term);border-radius:8px;cursor:pointer;padding:0;touch-action:manipulation}",
63
+ "m-predict .pd-btn:active{background:var(--term-tint)}",
64
+ "m-predict .pd-num{width:80px;height:48px;box-sizing:border-box;font:700 27px/1 var(--font-cap,var(--font-sans,sans-serif));font-variant-numeric:tabular-nums;text-align:center;color:var(--fg);background:var(--bg);border:2px solid var(--muted);border-radius:8px;padding:0}",
65
+ "@media print{m-predict .pd-ctl,m-predict .pd-pick,m-predict .pd-mark,m-predict .pd-live{display:none!important}}",
66
+ ].join("\n");
67
+ return class extends base.MotionElement {
68
+ static partName = "predict"; // the registry name (define meta name), for report prefixes
69
+ static variants = ["fade", "draw"];
70
+ static interactive = true; // 操作できるパーツ(docs/conventions.md §6)
71
+ static viewerInput = true; // 見る人の入力を受け付ける(仕様 §8.4)
72
+ static preview = "none"; // 先の段階は答えなので、授業の表示でも先を見せない(仕様 §8.4、docs/conventions.md §1.2)
73
+ // データの形(kit/shape.js)
74
+ static shape = {
75
+ schema: {type: "object", additionalProperties: false, required: ["choices", "answer"], properties: {
76
+ question: {type: "string"},
77
+ choices: {type: "array", minItems: 2, maxItems: 6, items: {type: "object", additionalProperties: false, required: ["label"], properties: {
78
+ label: {type: "string"}, tone: {type: "string"}}}},
79
+ answer: {type: "integer"},
80
+ counts: {type: "array", items: {type: "integer"}},
81
+ note: {type: "string"},
82
+ labels: {type: "object", additionalProperties: false, properties: {correct: {type: "string"}}}}},
83
+ example: {question: "重い球と軽い球、どちらが先に落ちる?", choices: [{label: "重い球"}, {label: "軽い球"}, {label: "同時"}], answer: 2, counts: [14, 3, 9], note: "空気の抵抗を除けば同時に落ちる"},
84
+ note: {en: "choices are objects {\"label\": …} (not strings); answer is the 0-based index of the right choice; counts (optional) has one whole number ≥ 0 per choice",
85
+ ja: "choices は {\"label\": …} の並び(字の並びではない)。answer は正しい選択肢の番号(0 から数える)。counts(省略可)は選択肢ごとに 0 以上の整数を 1 つずつ"},
86
+ };
87
+ static props = {
88
+ "answer-step": {type: "number", default: 2, doc: "2 以上(既定 2)。人数を数えるステップ 1 のあとに答えを開く"},
89
+ unit: {type: "string", default: "", doc: "数の単位(人 など)"},
90
+ poll: {type: "string", default: "", doc: "live の投票の id(live 拡張のある再生で、見せてよいと決まった集計を棒に出す)"},
91
+ ticks: {type: "bool", default: true, doc: "数の軸の目盛りと格子"},
92
+ };
93
+ get aStep(){ return Math.max(1, Math.round(this.props["answer-step"]) || 2); }
94
+ get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.aStep; }
95
+ // 作者の数(counts。書かなければ全部 0)
96
+ get author(){
97
+ var d = this.data || {}, n = (d.choices || []).length;
98
+ // 9999 まで(−1・+1 と数の欄が扱う数の上限。mount で知らせる)
99
+ return Array.from({length: n}, function(_, i){ var v = d.counts && d.counts[i]; return Number.isInteger(v) && v > 0 ? Math.min(9999, v) : 0; });
100
+ }
101
+ mount(ctx){
102
+ var self = this, d = this.data || {}, n = (d.choices || []).length;
103
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
104
+ if (!(d.answer >= 0 && d.answer < n)) throw new Error("answer " + d.answer + " is not a choice index (0–" + (n - 1) + ")");
105
+ if (d.counts && d.counts.length !== n) throw new Error("counts has " + d.counts.length + " numbers for " + n + " choices");
106
+ if (d.counts && d.counts.some(function(v){ return v < 0; })) throw new Error("counts must be 0 or more");
107
+ var big = (d.counts || []).filter(function(v){ return v > 9999; });
108
+ if (big.length) ctx.report("data", "[predict] counts " + big.join(", ") + " are more than 9999, the most the −1/+1 buttons and the field take; 9999 is shown");
109
+ this.variant = base.variant(this);
110
+ this.video = ctx.mode === "video";
111
+ // 答えの知らせ(2.2.0、仕様 §8.4 ctx.answer):答えのステップに予想を選んだ状態で着いたとき、そのときの予想の正誤と選択肢を渡す(render)。ctx.answer の無いプレーヤーでは何もしない
112
+ this._answer = typeof ctx.answer === "function" ? ctx.answer : null;
113
+ this.style.display = "block"; this.style.position = "relative";
114
+ if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
115
+ // 読み上げソフトへの知らせ
116
+ this.say = document.createElement("div"); this.say.className = "pd-say"; this.say.setAttribute("role", "status"); this.say.setAttribute("aria-live", "polite");
117
+ this.appendChild(this.say);
118
+ if (d.question) this.setAttribute("aria-label", d.question);
119
+ // 印刷は作者の値で描く(画面の数は消さない。afterprint で戻す)。beforeprint・afterprint は文書の窓(document.defaultView)に来る
120
+ var view = document.defaultView;
121
+ if (!this.video && view){
122
+ view.addEventListener("beforeprint", function(){ self._printing = true; self.redraw(); });
123
+ view.addEventListener("afterprint", function(){ self._printing = false; self.redraw(); });
124
+ }
125
+ this.place(ctx);
126
+ }
127
+ // 配置が変わった知らせ(仕様 §8.4 layout):要素の大きさが mount のときと変わったときだけ置き直す(変換で縮めるだけなら呼ばれない。
128
+ // 横に並んだ文の字が後から読み込まれて、段組みの中の幅が変わるときなど)。大きさ 0(隠れている)なら前の配置のまま
129
+ layout(ctx){
130
+ var W = this.clientWidth, H = this.clientHeight;
131
+ if (!W || !H || (W === this.g.W && H === this.g.H)) return;
132
+ // フォーカスが操作の中にあれば、作り直した同じ行・同じ場所の操作に戻す(字の読み込みや画面の切り替えで呼ばれても、キーボードや読み上げソフトで使う人に見えないように)
133
+ var a = document.activeElement, keep = null;
134
+ if (a && a !== this && this.contains(a)) this.rows.forEach(function(r, i){
135
+ if (a === r.pick) keep = {i: i, at: -1};
136
+ else if (r.ctl && r.ctl.contains(a)) keep = {i: i, at: Array.prototype.indexOf.call(r.ctl.children, a), sel: a === r.field ? [a.selectionStart, a.selectionEnd] : null};
137
+ });
138
+ this.place(ctx);
139
+ this.redraw();
140
+ var r = keep && this.rows[keep.i], e = r && (keep.at < 0 ? r.pick : r.ctl && r.ctl.children[keep.at]);
141
+ if (e){
142
+ e.focus({preventScroll: true});
143
+ if (keep.sel && keep.sel[0] != null) try { e.setSelectionRange(keep.sel[0], keep.sel[1]); } catch (x) {}
144
+ }
145
+ }
146
+ // 大きさで決まる絵と操作を作る。数と予想(見る人の入力)・読み上げの知らせは残す(フォーカスは layout が戻す)
147
+ place(ctx){
148
+ var self = this, P = this.props, D = base, d = this.data || {}, ch = d.choices || [], n = ch.length, T = this.T;
149
+ var correctLabel = (d.labels && d.labels.correct) || T.correct;
150
+ var W = this.clientWidth, H = this.clientHeight, inter = !this.video;
151
+ if (this.svg){
152
+ this.svg.remove();
153
+ this.rows.forEach(function(r){ if (r.pick) r.pick.remove(); if (r.ctl) r.ctl.remove(); });
154
+ }
155
+ // 字の幅(base の textWidth:テーマの字で測った幅。mk:mtext で書く字で、*_^ は数えない)
156
+ var est = function(s, size, mk){ return D.textWidth(s, size, {font: self, mark: !!mk}); };
157
+ // 縦:問い・行・目盛り・注(と予想の当たり外れ)
158
+ var qh = d.question ? 54 : 0, nh = d.note || inter ? 50 : 0, tb = P.ticks ? 40 : 8;
159
+ var rh = Math.min(88, (H - qh - nh - tb) / n);
160
+ if (inter && rh < 54) ctx.report("size", "[predict] rows are " + rh.toFixed(0) + " px high; the −1/+1 buttons need 54 (make the element taller or use fewer choices)");
161
+ // 横:予想の印・選択肢の名前・棒・数と「正解」・操作
162
+ var mk = inter ? 40 : 0, LS = 26;
163
+ var lw = Math.min(W * 0.34, Math.max.apply(null, ch.map(function(c){ return est(c.label, LS, true); })) + 16);
164
+ var cw = inter ? 232 : 0;
165
+ var valW = est("9999" + P.unit, 26) + 12, okW = est(correctLabel, 26) + 16;
166
+ // 棒の軸の長さ:選択肢の名前・数・「正解」・操作の残り。BARMIN px より短ければ知らせ、その長さは残す(負の長さで棒が消え、目盛りが重ならないように)
167
+ var x0 = mk + lw + 8, x1 = W - cw - valW - okW - 8, BARMIN = 120;
168
+ if (x1 < x0 + BARMIN){ ctx.report("size", "[predict] the element is " + W + " px wide; the bars get " + Math.round(x1 - x0) + " px, less than " + BARMIN + " (make it about " + Math.ceil(W + x0 + BARMIN - x1) + " px wide or shorten the labels)"); x1 = x0 + BARMIN; }
169
+ this.g = {W: W, H: H, qh: qh, nh: nh, rh: rh, mk: mk, lw: lw, cw: cw,
170
+ x0: x0, x1: x1, y0: qh, y1: qh + rh * n};
171
+ var G = this.g;
172
+ var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"});
173
+ this.insertBefore(svg, this.say);
174
+ var fitText = function(el, s, max, size, what, mk){
175
+ var z = size;
176
+ while (z > 24 && est(s, z, mk) > max) z--;
177
+ if (est(s, z, mk) > max) ctx.report("size", "[predict] the " + what + " does not fit (" + Math.ceil(est(s, z, mk) - max) + " px too wide at 24 px); shorten it");
178
+ el.setAttribute("font-size", z);
179
+ return el;
180
+ };
181
+ if (d.question) fitText(D.mtext(svg, 0, 36, d.question, {"font-size": 30, "font-weight": 700}), d.question, W - 8, 30, "question", true);
182
+ // 答えの枠(行の後ろ)
183
+ this.frame = D.el("rect", {x: 2, y: 0, width: Math.max(0, W - cw - 12), height: Math.max(0, rh - 8), rx: 10, fill: "none", stroke: "var(--emph)", "stroke-width": 3, opacity: 0}, svg);
184
+ this.frameLen = 2 * (W - cw - 12 + rh - 8);
185
+ // 目盛り(数の軸の上限は数で決まるので、render で置き直す。入れ物は先に作る)
186
+ var gT = D.el("g", {}, svg);
187
+ this.ticks = !P.ticks ? [] : Array.from({length: 8}, function(){
188
+ return {grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2, y1: G.y0 + 4, y2: G.y1}, gT),
189
+ text: D.el("text", {"font-size": 24, "text-anchor": "middle", y: G.y1 + 30, style: "font-variant-numeric:tabular-nums"}, gT)};
190
+ });
191
+ if (P.ticks){ var z = D.el("text", {"font-size": 24, "text-anchor": "middle", x: G.x0, y: G.y1 + 30}, gT); z.textContent = "0"; }
192
+ D.el("line", {x1: G.x0, y1: G.y0 + 4, x2: G.x0, y2: G.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
193
+ var bw = Math.max(0, Math.min(46, rh * 0.56));
194
+ this.rows = ch.map(function(c, i){
195
+ var cy = G.y0 + rh * (i + 0.5), col = tone(c.tone);
196
+ var r = {cy: cy, col: col,
197
+ mark: inter ? D.el("circle", {cx: 16, cy: cy, r: 11, fill: "none", stroke: "var(--term)", "stroke-width": 2.5, "class": "pd-mark"}, svg) : null,
198
+ dot: inter ? D.el("circle", {cx: 16, cy: cy, r: 6, fill: "var(--term)", opacity: 0, "class": "pd-mark"}, svg) : null,
199
+ bar: D.el("rect", {x: G.x0, y: (cy - bw / 2).toFixed(1), height: bw.toFixed(1), rx: 3, fill: col, opacity: 0}, svg),
200
+ label: fitText(D.mtext(svg, mk + lw, cy + 9, c.label, {"text-anchor": "end", "font-size": LS}), c.label, lw - 8, LS, "label " + JSON.stringify(c.label), true),
201
+ val: D.el("text", {"font-size": 26, "font-weight": 700, y: (cy + 9).toFixed(1), opacity: 0, style: "font-variant-numeric:tabular-nums"}, svg)};
202
+ if (i === d.answer) r.ok = D.el("text", {"font-size": 26, "font-weight": 700, y: (cy + 9).toFixed(1), fill: "var(--emph)", opacity: 0}, svg);
203
+ if (r.ok) r.ok.textContent = correctLabel;
204
+ return r;
205
+ });
206
+ this.bw = bw;
207
+ // 注(答えと一緒に)と、予想の当たり外れ(見る人が予想したときだけ)
208
+ this.noteEl = D.el("text", {x: 0, y: H - 14, "font-size": 26, opacity: 0}, svg);
209
+ this.noteText = d.note || "";
210
+ if (d.note){ var notePrefix = est(T.noteWrong, 26) >= est(T.noteRight, 26) ? T.noteWrong : T.noteRight; fitText(this.noteEl, notePrefix + d.note, W - 8, 26, "note"); }
211
+ // live の集計の見出し(集計を出すときだけ)
212
+ this.liveEl = D.el("text", {x: W, y: G.y1 + 30, "font-size": 24, "text-anchor": "end", opacity: 0, "class": "pd-live"}, svg);
213
+ this.liveEl.textContent = T.liveResults;
214
+ // 操作:選択肢の名前(自分の予想)、−1・数の欄・+1。動画では作らない
215
+ if (inter){
216
+ var mkEl = function(tag, cls, attrs){ var e = document.createElement(tag); e.className = cls; for (var a in attrs) e.setAttribute(a, attrs[a]); self.appendChild(e); return e; };
217
+ var unit = P.unit;
218
+ this.rows.forEach(function(r, i){
219
+ var top = r.cy - 24;
220
+ r.pick = mkEl("button", "pd-pick", {type: "button", "aria-pressed": "false", "aria-label": T.guessLabel(ch[i].label)});
221
+ Object.assign(r.pick.style, {left: "0px", top: (r.cy - rh / 2 + 4) + "px", width: (mk + lw) + "px", height: (rh - 8) + "px"});
222
+ r.pick.addEventListener("click", function(e){ e.stopPropagation(); self.choose(i); });
223
+ var ctl = r.ctl = mkEl("div", "pd-ctl", {role: "group", "aria-label": T.countGroup(ch[i].label)});
224
+ Object.assign(ctl.style, {left: (W - cw + 16) + "px", top: top + "px"});
225
+ var bt = function(txt, dlt, ariaLabel){
226
+ var b = document.createElement("button"); b.type = "button"; b.className = "pd-btn"; b.textContent = txt; b.setAttribute("aria-label", ariaLabel);
227
+ b.addEventListener("click", function(e){ e.stopPropagation(); self.bump(i, dlt); });
228
+ b.addEventListener("keydown", function(e){ self.key(e, i, false); });
229
+ return b;
230
+ };
231
+ ctl.appendChild(bt("−1", -1, T.decrease(ch[i].label)));
232
+ var f = r.field = document.createElement("input");
233
+ f.type = "text"; f.className = "pd-num"; f.setAttribute("inputmode", "numeric"); f.setAttribute("autocomplete", "off");
234
+ f.setAttribute("aria-label", T.countField(ch[i].label, unit));
235
+ f.addEventListener("keydown", function(e){ self.key(e, i, true); });
236
+ f.addEventListener("input", function(){
237
+ var s = f.value.replace(/[^0-9]/g, "").slice(0, 4);
238
+ if (s !== f.value) f.value = s;
239
+ self.set(i, s === "" ? 0 : +s);
240
+ });
241
+ f.addEventListener("change", function(){ f.value = String(self.counts()[i]); });
242
+ ctl.appendChild(f);
243
+ ctl.appendChild(bt("+1", 1, T.increase(ch[i].label)));
244
+ });
245
+ }
246
+ function tone(t){ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(t || "") ? "var(--" + t + ")" : "var(--term)"; }
247
+ }
248
+ // ---- 見る人の状態((i, k, t) の外)
249
+ // 今の数(見る人が変えていればその値、そうでなければ作者の値)。新しい配列を返す
250
+ counts(){ return (this._vc || this.author).slice(); }
251
+ // 発表者の画面から(Studio が呼ぶ):choice は 0 から数える選択肢の番号、count は新しい数(0 以上の整数)
252
+ input(choice, count){
253
+ if (this.video) return;
254
+ var n = this.author.length;
255
+ if (!Number.isInteger(choice) || choice < 0 || choice >= n || !Number.isInteger(count) || count < 0 || count > 9999){
256
+ console.warn("[predict] input(" + JSON.stringify(choice) + ", " + JSON.stringify(count) + ") ignored (choice 0–" + (n - 1) + ", count a whole number 0–9999)");
257
+ return;
258
+ }
259
+ this.set(choice, count);
260
+ }
261
+ bump(i, dl){ this.set(i, this.counts()[i] + dl); }
262
+ set(i, v){
263
+ if (this.video || !this.rows) return;
264
+ v = Math.max(0, Math.min(9999, v));
265
+ var c = this.counts();
266
+ if (c[i] === v) return;
267
+ c[i] = v; this._vc = c;
268
+ this.redraw();
269
+ this.say.textContent = this.T.countAnnounce(this.data.choices[i].label, v, this.props.unit);
270
+ this.emit();
271
+ }
272
+ // 自分の予想(1 つ。もう一度押すと外す)
273
+ choose(i){
274
+ if (this.video) return;
275
+ var d = this.data, T = this.T;
276
+ this._pick = this._pick === i ? null : i;
277
+ this.redraw();
278
+ var lab = d.choices[i].label;
279
+ this.say.textContent = this._pick === null ? T.unpicked : this.revealed() ? (i === d.answer ? T.pickedRight(lab) : T.pickedWrong(d.choices[d.answer].label)) : T.myGuess(lab);
280
+ }
281
+ revealed(){ return this._k !== undefined && this._k >= this.aStep; }
282
+ key(e, i, field){
283
+ var k = e.key, up = k === "+" || k === "ArrowUp" || (!field && k === "ArrowRight"), dn = k === "-" || k === "−" || k === "ArrowDown" || (!field && k === "ArrowLeft");
284
+ if (up || dn){ e.preventDefault(); e.stopPropagation(); this.bump(i, up ? 1 : -1); return; }
285
+ if (field){
286
+ // 欄の中のキー(数字・矢印・Space など)はスライドを動かさない。Esc で欄を出る
287
+ e.stopPropagation();
288
+ if (k === "Escape" || k === "Enter") e.target.blur();
289
+ }
290
+ }
291
+ emit(){ this.dispatchEvent(new CustomEvent("egatari-input", {bubbles: true, detail: {counts: this.counts()}})); }
292
+ // 見る人の状態を捨てて作者の値に戻す。数を変えていたら知らせる
293
+ reset(){
294
+ var had = !!this._vc;
295
+ if (!had && this._pick == null) return false;
296
+ this._vc = null; this._pick = null;
297
+ if (had) this.emit();
298
+ return true;
299
+ }
300
+ // 触った跡だけを戻す(ctx.reset):部品の中のフォーカスを外す(欄は今の数を出し直す)。数と予想(見る人の入力)は残す
301
+ untouch(){
302
+ var a = document.activeElement;
303
+ if (a && a !== this && this.contains(a) && a.blur) a.blur();
304
+ }
305
+ // 入力のあとの描き直し:最後の (k, t) で paint だけを呼ぶ(render を通さないので、ctx.entered・ctx.reset を繰り返さない)
306
+ redraw(){ if (this._k !== undefined) this.paint(this._k, this._t, this._ctx); }
307
+ duration(k){
308
+ var a = this.aStep, d = 0;
309
+ if (k === 1) d = 0.6;
310
+ if (k === a) d += 0.6;
311
+ return d;
312
+ }
313
+ render(k, t, ctx){
314
+ // ほかのスライドから入ったとき・飛んだとき(ctx.entered)だけ、見る人の状態を捨てる。同じスライドの中の段階の移りでは残す。
315
+ // ctx.reset(触った部品が段階に入るとき)は触った跡だけを戻し、見る人の入力は消さない(仕様 §8.4)
316
+ if (ctx.entered === true) this.reset();
317
+ if (ctx.reset) this.untouch();
318
+ // 答えのステップに着いたとき(その前は答えより前のステップか、初めての描画)に予想があれば 1 回知らせる。同じステップの描き直しでは知らせない。
319
+ // 戻ってまた着けばもう 1 回。問いは部品に 1 つなので id は "q"。動画・印刷では知らせない
320
+ var a = this.aStep, was = this._k !== undefined && this._k >= a;
321
+ if (k >= a && !was && this._pick != null && this._answer && !this.video && !this._printing)
322
+ this._answer("q", this._pick === this.data.answer, String(this.data.choices[this._pick].label));
323
+ this._k = k; this._t = t; this._ctx = {mode: ctx.mode, preview: ctx.preview, live: ctx.live};
324
+ this.paint(k, t, this._ctx);
325
+ }
326
+ // (k, t) と見る人の状態の絵。ctx は {mode, preview, live}
327
+ paint(k, t, ctx){
328
+ var self = this, P = this.props, D = base, G = this.g, dd = this.data, n = this.rows.length, vr = this.variant, T = this.T;
329
+ var a = this.aStep;
330
+ // 数:live の集計(実行系が見せてよいと渡したときだけ)→ 見る人の数 → 作者の数
331
+ var live = null;
332
+ if (P.poll && ctx && ctx.live && typeof ctx.live.poll === "function" && !this.video && !this._printing){
333
+ var lv = ctx.live.poll(P.poll);
334
+ if (Array.isArray(lv)) live = Array.from({length: n}, function(_, i){ var v = +lv[i]; return isFinite(v) && v > 0 ? Math.round(v) : 0; });
335
+ }
336
+ var c = live || (this._printing ? this.author : this.counts()), pick = this._printing ? null : this._pick;
337
+ // 段階 1 の棒(draw は上から順に、同じ長さの中で)、答えの段階
338
+ // 先の段階は授業の表示(ctx.preview)でも見せない:予想する前に棒や答えが見えてはいけない(static preview = "none")
339
+ var e1 = k > 1 ? 1 : k < 1 ? 0 : null;
340
+ var at1 = 0, ea = k > a ? 1 : k < a ? 0 : D.prog(t, a === 1 ? 0.6 : 0, 0.6);
341
+ var rowE = function(j){
342
+ if (e1 !== null) return e1;
343
+ if (vr === "draw"){ var s = n > 1 ? 0.3 / (n - 1) : 0; return D.prog(t, at1 + j * s, 0.3); }
344
+ return D.prog(t, at1, 0.6);
345
+ };
346
+ // 数の軸
347
+ var M = nice(Math.max(4, Math.max.apply(null, c)) * 1.12), len = G.x1 - G.x0, X = function(v){ return G.x0 + Math.min(v, M) / M * len; };
348
+ var ts = Math.max(1, tickStep(M)), ti = 0;
349
+ // 短い軸では目盛りの数が重ならない間隔まで広げる(数の幅+16 px)
350
+ while (ts < M && len * ts / M < est(String(Math.ceil(M)), 24) + 16) ts = up(ts);
351
+ this.ticks.forEach(function(o, j){
352
+ var v = (j + 1) * ts, on = v <= M + 1e-9;
353
+ o.grid.setAttribute("x1", X(v).toFixed(1)); o.grid.setAttribute("x2", X(v).toFixed(1));
354
+ o.text.setAttribute("x", X(v).toFixed(1)); o.text.textContent = on ? String(v) : "";
355
+ o.grid.setAttribute("opacity", on ? 0.8 : 0); o.text.setAttribute("opacity", on ? 1 : 0);
356
+ });
357
+ var shown = ea > 0.5;
358
+ this.rows.forEach(function(r, j){
359
+ var e = rowE(j), isA = j === dd.answer, dim = isA ? 1 : 1 - 0.65 * ea;
360
+ r.bar.setAttribute("width", Math.max(0, X(c[j]) - G.x0).toFixed(1));
361
+ r.bar.setAttribute("opacity", (e * dim).toFixed(3));
362
+ r.val.textContent = self.fmt(c[j]);
363
+ r.val.setAttribute("x", (X(c[j]) + 10).toFixed(1));
364
+ r.val.setAttribute("opacity", e.toFixed(3));
365
+ // 答えを開いたら、ほかの選択肢の字は --muted(読める濃さのまま)
366
+ var txt = !isA && shown ? "var(--muted)" : "var(--fg)";
367
+ r.val.style.fill = txt; r.label.style.fill = txt;
368
+ r.label.setAttribute("font-weight", isA && shown ? 700 : 400);
369
+ if (r.ok){ r.ok.setAttribute("x", (X(c[j]) + 10 + est(self.fmt(c[j]), 26) + 14).toFixed(1)); r.ok.setAttribute("opacity", ea.toFixed(3)); }
370
+ if (r.dot){ r.dot.setAttribute("opacity", pick === j ? 1 : 0); r.pick.setAttribute("aria-pressed", pick === j ? "true" : "false"); }
371
+ if (r.ctl){
372
+ r.ctl.style.display = k >= 1 && !live ? "" : "none";
373
+ if (document.activeElement !== r.field) r.field.value = String(c[j]);
374
+ }
375
+ });
376
+ // 答えの枠:fade はフェード、draw は線を引く(同じ長さ)
377
+ var fy = G.y0 + G.rh * dd.answer + 4;
378
+ this.frame.setAttribute("y", fy.toFixed(1));
379
+ if (vr === "draw" && ea > 0 && ea < 1){ this.frame.setAttribute("stroke-dasharray", this.frameLen.toFixed(0)); this.frame.setAttribute("stroke-dashoffset", (this.frameLen * (1 - ea)).toFixed(1)); this.frame.setAttribute("opacity", 1); }
380
+ else { this.frame.removeAttribute("stroke-dasharray"); this.frame.removeAttribute("stroke-dashoffset"); this.frame.setAttribute("opacity", ea.toFixed(3)); }
381
+ // 注と、予想の当たり外れ
382
+ var pk = pick, st = pk != null && k >= a ? (pk === dd.answer ? T.noteRight : T.noteWrong) : "";
383
+ this.noteEl.textContent = (k >= a ? st : "") + this.noteText;
384
+ this.noteEl.setAttribute("opacity", ea.toFixed(3));
385
+ this.liveEl.setAttribute("opacity", live && k >= 1 ? 1 : 0);
386
+ // 答えを開いた段階に入ったら知らせる(入力の知らせは set・choose が後から書く)
387
+ if (this._sayK !== k && !this.video){ this._sayK = k; this.say.textContent = k >= a ? T.answerAnnounce(dd.choices[dd.answer].label, this.noteText) : ""; }
388
+ function est(s, size){ return D.textWidth(s, size, {font: self}); }
389
+ function nice(v){ var e = Math.pow(10, Math.floor(Math.log10(v))), x = v / e;
390
+ return [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10].filter(function(s){ return s >= x - 1e-9; })[0] * e; }
391
+ function up(v){ var e = Math.pow(10, Math.floor(Math.log10(v))); return Math.round([1, 2, 5, 10, 20].filter(function(s){ return s * e > v + 1e-9; })[0] * e); }
392
+ function tickStep(M){ var r = M / 4.5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
393
+ return Math.round((x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e); }
394
+ }
395
+ fmt(v){ return String(v).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + this.props.unit; }
396
+ };
397
+ });
@@ -0,0 +1,44 @@
1
+ ---
2
+ summary: Hierarchy tree (org chart, taxonomy), built level by level from the root; auto layout
3
+ steps: depth (by="level") or node count (by="node"); or the largest step
4
+ props:
5
+ orient: down (default) or right
6
+ by: level (default) or node (depth-first)
7
+ link: elbow (default) or straight
8
+ size: box text px (0 = 27, shrink to 24)
9
+ fade: box appear (s)
10
+ draw: line draw (s)
11
+ example: {"nodes": [{"id": "r", "label": "Animals"}, {"id": "a", "label": "Vertebrates", "parent": "r"}, {"id": "b", "label": "Invertebrates", "parent": "r"}]}
12
+ ---
13
+
14
+ Parent–child structures (org charts, taxonomies, outlines). No coordinates; laid out without overlaps.
15
+
16
+ Child JSON: `{"nodes": [...], "edges": [...]}` (`edges` optional).
17
+
18
+ - node: `id`, `label` (`\n`) or `tex` (KaTeX), `parent` (parent `id`; exactly one root without `parent`), `note` (small, **under** box), `tone` (`term` default, `emph`, `muted`, `accent2`, `series-1..4`), `dash: true` (dashed, unfilled), `step`, `at` (start s)
19
+ - Children in array order; parent centred over them
20
+ - edge: extra links (`from` `to` `label` `tone` `dash` `step`), dashed arrow outside the tree; best at same depth; step: later end
21
+ - Child `branch`: line text (e.g. probability). `path`: root-first `id`s highlighted in turn (default 1 step per line, after the tree; `pathStep`: in one step; `pathNote`: end note)
22
+ - `orient="right"` for wide taxonomies. `by="node"`: one at a time, depth-first (to follow a branch). Node `step` wins
23
+ - Lines `--muted`, 3 px; `tone: emph` box: `--emph-tint` fill
24
+ - Fit (~440 px high): ~8 four-character boxes per level (`down`), ~7 (`right`); ~5 levels. More leaves: 2 staggered rows (~16 / ~11), then 2-line names. Text ≥ 24 px; overflow spills, reported. Too many: split
25
+ - `variant`: `fade`, `draw`, `grow`
26
+ - Show later steps faintly (`ctx.preview`): later parts faint
27
+
28
+ Premise contrast (positioning): root the question, children the positions (this work `emph`), then premises, then what each can say; a dropped premise `dash: true`.
29
+
30
+ The demo is `demo.html` (company, values and the premise contrast fictional).
31
+
32
+ <!-- llm: omit -->
33
+ Notes
34
+
35
+ - Moves ≤ 12 px within `fade` time. Edge step default: later end; edges bulge outward (`down` below, `right` right)
36
+ - Layout: subtrees placed bottom-up and pushed together until level contours touch (Reingold–Tilford); small subtrees in between go left
37
+ - Text 27 → 24 px (`size` fixes it). Width estimated from characters (CJK 1, others 0.6)
38
+ - At 24 px, no smaller text (conventions §2.3); tries: stagger children of parents with ≥ 3 leaf children (not with `straight`) → wrap names (≥ 4 chars, no `\n` or `*_^`; at the middle space, or after a mid hiragana; single Latin words never). Else least-overflow layout; shortfall via `ctx.report("size", …)`
39
+ - Motion: `fade` from below; `draw`, `grow` from the parent's direction, 12 px (root always as `fade`). `grow` from 0.92×
40
+ - `branch`: 24 px, `--fg`. `elbow` bends 20 px from the parent, text on the child line; levels widen to fit (`right` +52 px, `down` ≥ 76 px); no staggering. `straight`: outside the line's middle (crowded at ≥ 3 children)
41
+ - `path`: must start at the root, each pair parent–child, else a data card. Default: one step per line after the tree's last step. `pathStep`: drawn in that step (`draw` s each). `--emph` 6 px over the line, `--emph` 4 px frame on reached boxes, `branch` in `--emph`. `pathNote` beyond the end box after the last line; may overlap if the end box is not at the deepest level
42
+ - Show later steps faintly: later path faint; `branch` colour changes only at its step
43
+ - Edges take room outside the tree (`down`: 56 px below, +36 with a label); across depths they may cross boxes
44
+ <!-- llm: end -->