egatari 0.6.6 → 0.6.7

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 (82) hide show
  1. package/CHANGELOG.md +92 -1
  2. package/NOTICE +6 -0
  3. package/README.ja.md +3 -3
  4. package/README.md +3 -3
  5. package/bin/egatari.mjs +2 -2
  6. package/components.lock.json +33 -15
  7. package/components2.lock.json +409 -1
  8. package/kit/build.mjs +28 -4
  9. package/kit/check-messages.mjs +14 -0
  10. package/kit/check.mjs +21 -0
  11. package/kit/core/build-core.mjs +84 -19
  12. package/kit/core/colab-core.mjs +3 -1
  13. package/kit/core/fill-measure.mjs +79 -0
  14. package/kit/core/font-coverage.mjs +52 -0
  15. package/kit/core/font-subset-core.mjs +101 -0
  16. package/kit/core/llm-fix.mjs +3 -2
  17. package/kit/core/llm-pack-data.mjs +39 -41
  18. package/kit/core/parts2.mjs +34 -0
  19. package/kit/core/portable.mjs +30 -2
  20. package/kit/core/scorm.mjs +109 -0
  21. package/kit/core/tier-a.mjs +72 -26
  22. package/kit/core/zip-write.mjs +57 -0
  23. package/kit/deck.js +118 -29
  24. package/kit/fill-scan.mjs +95 -0
  25. package/kit/font-subset.mjs +33 -0
  26. package/kit/instruction-version.json +1 -1
  27. package/kit/live.js +3 -1
  28. package/kit/llm-pack.mjs +15 -14
  29. package/kit/panes.js +26 -14
  30. package/kit/player.json +1 -1
  31. package/kit/player.lock.json +2 -2
  32. package/kit/tools.js +20 -23
  33. package/kit/track.js +11 -5
  34. package/package.json +4 -2
  35. package/render/audio-track.mjs +112 -0
  36. package/render/render.mjs +99 -51
  37. package/tools/video.mjs +17 -9
  38. package/vendor/components/CATALOG.md +2 -2
  39. package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/README.en.md +40 -0
  40. package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/index.js +348 -0
  41. package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/README.en.md +32 -0
  42. package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/index.js +222 -0
  43. package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/README.en.md +42 -0
  44. package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/index.js +481 -0
  45. package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/README.en.md +39 -0
  46. package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/index.js +323 -0
  47. package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/README.en.md +42 -0
  48. package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/index.js +267 -0
  49. package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/README.en.md +52 -0
  50. package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/index.js +219 -0
  51. package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/README.en.md +66 -0
  52. package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/index.js +920 -0
  53. package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/README.en.md +32 -0
  54. package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/index.js +352 -0
  55. package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/README.en.md +31 -0
  56. package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/index.js +232 -0
  57. package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/README.en.md +48 -0
  58. package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/index.js +384 -0
  59. package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/README.en.md +42 -0
  60. package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/index.js +481 -0
  61. package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/README.en.md +37 -0
  62. package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/index.js +424 -0
  63. package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/README.en.md +44 -0
  64. package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/index.js +304 -0
  65. package/vendor/components/sha256/8c3d7e9921f249cf45ce26d5a449f2b01fef683f500afed69d0b189312c4464e/index.js +904 -0
  66. package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/README.en.md +42 -0
  67. package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/index.js +170 -0
  68. package/vendor/components/sha256/b86c0e95622ff3be5fb0b208672ebca5018c34fd192e1b431cfd0fe912df2a7f/index.js +916 -0
  69. package/vendor/components/sha256/bec04685638f8fc1217c380d361fd9a425ffeade0291a4f2b2d4e41a5628e0ef/index.js +809 -0
  70. package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/README.en.md +37 -0
  71. package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/index.js +424 -0
  72. package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/README.en.md +34 -0
  73. package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/index.js +244 -0
  74. package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/README.en.md +50 -0
  75. package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/index.js +171 -0
  76. package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/README.en.md +35 -0
  77. package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/index.js +179 -0
  78. package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/README.en.md +51 -0
  79. package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/index.js +228 -0
  80. package/vendor/components-2/manifest-2.4.3.json +1962 -0
  81. package/vendor/components-2/manifest-2.4.4.json +1911 -0
  82. package/vendor/components-2/manifest-2.5.0.json +1911 -0
@@ -0,0 +1,267 @@
1
+ // m-pie:円グラフとドーナツグラフ。切れの名前と値(と割合)は、大きい切れなら中に、小さい切れなら外に引き出し線で書く
2
+ // <m-pie unit="万円" digits="1" show="both" style="height:420px"><script type="application/json">
3
+ // {"slices": [{"label": "食費", "value": 7.2}, {"label": "住まい", "value": 8.5}, {"label": "その他", "value": 2.1, "tone": "muted"}]}
4
+ // (JSON の終わり)</m-pie>
5
+ // 段階:既定は全部を段階 1 で(全体と内訳は一度に見せる)。per-step="1" で 1 切れずつ(口述原稿が 1 切れずつ話すときだけ)、切れの step で直接
6
+ // 切れは 12 時の位置から時計回りに、書いた順に並べる。割合は足して 100 になるように丸める(最大剰余法)
7
+ // donut="0.55" でドーナツ(内側の半径の割合)。中の字は JSON の center({total} は合計に置き換わる)
8
+ // 見せ方(docs/conventions.md §1):fade(フェードして少し上がりながら現れる、既定)・sweep(12 時の位置から時計回りに掃くように現れる)・
9
+ // 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: "pie", version: "2.0.2", requires: {base: "1.1.0"}, element: "m-pie"}, function(deps){
13
+ "use strict";
14
+ var base = deps.base;
15
+ return class extends base.MotionElement {
16
+ static partName = "pie"; // the registry name (define meta name), for report prefixes
17
+ static variants = ["fade", "sweep", "grow"];
18
+ // データの形(kit/shape.js)
19
+ static shape = {
20
+ schema: {type: "object", additionalProperties: false, required: ["slices"], properties: {
21
+ slices: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["value"], properties: {
22
+ label: {type: "string"}, value: {type: "number"}, tone: {type: "string"}, step: {type: "integer"}, place: {enum: ["auto", "in", "out"]}}}},
23
+ center: {type: "string"}}},
24
+ example: {slices: [{label: "食費", value: 7.2}, {label: "住まい", value: 8.5}, {label: "その他", value: 2.1, tone: "muted"}]},
25
+ note: {en: "the slices go in \"slices\" (not \"data\" or \"groups\"); value is a number, not a percentage string; the slices are drawn clockwise from 12 o'clock in the written order",
26
+ ja: "切れは \"slices\" に書く(\"data\" や \"groups\" ではない)。value は数(\"26%\" のような字ではない)。12 時の位置から時計回りに、書いた順に並ぶ"},
27
+ };
28
+ static props = {
29
+ donut: {type: "number", default: 0, doc: "ドーナツの内側の半径の割合(0 = 円グラフ。0.5〜0.6 がよい)"},
30
+ unit: {type: "string", default: "", doc: "値の単位(数字の後ろに付ける。万円、人、% など)"},
31
+ digits: {type: "number", default: 0, doc: "値の小数桁"},
32
+ "pct-digits": {type: "number", default: 0, doc: "割合の小数桁"},
33
+ show: {type: "string", default: "pct", doc: "名前の下に書くもの:pct(割合)・value(値)・both(値と割合)・none"},
34
+ "per-step": {type: "number", default: 0, doc: "1 段階に出す切れの数(0 = 全部を段階 1 で)"},
35
+ dur: {type: "number", default: 1.0, doc: "1 段階の動きの秒数"},
36
+ };
37
+ get steps(){
38
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
39
+ var m = 0;
40
+ this.plan().forEach(function(o){ m = Math.max(m, o.step); });
41
+ return m;
42
+ }
43
+ plan(){
44
+ if (this._plan) return this._plan;
45
+ var per = this.props["per-step"];
46
+ return (this._plan = ((this.data || {}).slices || []).map(function(s, i){
47
+ return {s: s, i: i, step: s.step !== undefined ? s.step : per > 0 ? Math.floor(i / per) + 1 : 1};
48
+ }));
49
+ }
50
+ mount(ctx){
51
+ var P = this.props, D = base, self = this, pl = this.plan(), d = this.data || {};
52
+ this.variant = base.variant(this);
53
+ this.style.display = "block"; this.style.position = "relative";
54
+ var W = this.clientWidth, H = this.clientHeight, TAU = Math.PI * 2;
55
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
56
+ // 字の幅(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
57
+ var est = function(s, size){ return D.textWidth(s, size, {font: self, mark: true}); };
58
+ var total = pl.reduce(function(a, o){ return a + Math.max(0, +o.s.value); }, 0);
59
+ if (!(total > 0)) throw new Error("slices: the values add up to 0 (write positive numbers)");
60
+ pl.forEach(function(o){ if (+o.s.value < 0) ctx.report("data", "[pie] the slice \"" + (o.s.label || o.i) + "\" has a negative value (drawn as 0)"); });
61
+ // 割合:足して 100 になるように丸める(最大剰余法)
62
+ var pd = P["pct-digits"], sc = Math.pow(10, pd), raw = pl.map(function(o){ return Math.max(0, +o.s.value) / total * 100 * sc; });
63
+ var fl = raw.map(Math.floor), left = Math.round(100 * sc) - fl.reduce(function(a, b){ return a + b; }, 0);
64
+ raw.map(function(v, i){ return [v - fl[i], i]; }).sort(function(a, b){ return b[0] - a[0] || a[1] - b[1]; }).slice(0, Math.max(0, left)).forEach(function(x){ fl[x[1]]++; });
65
+ var show = /^(pct|value|both|none)$/.test(P.show) ? P.show : "pct";
66
+ // 角度(12 時の位置から時計回り)と字
67
+ var acc = 0;
68
+ var sl = this.slices = pl.map(function(o, i){
69
+ var v = Math.max(0, +o.s.value), a0 = acc / total * TAU; acc += v;
70
+ var a1 = acc / total * TAU, pct = (fl[i] / sc).toFixed(pd) + "%", val = self.fmt(v);
71
+ var sub = show === "pct" ? pct : show === "value" ? val : show === "both" ? val + "(" + pct + ")" : "";
72
+ var lines = [];
73
+ if (o.s.label) lines.push({t: o.s.label, size: 26, bold: true});
74
+ if (sub) lines.push({t: sub, size: 24, bold: false});
75
+ // 中に入れるときの別の形:値と割合を 2 行に分けて幅を狭くする
76
+ var alt = show === "both" ? lines.slice(0, lines.length - 1).concat([{t: val, size: 24}, {t: pct, size: 24}]) : null;
77
+ // 既定の色:--series-1..3、次に同じ 3 色を薄く(0.5)、7 切れ目から --series-4(灰色は「その他」のために残す)、そのあとは繰り返し
78
+ var j6 = i % 7, tone = /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(o.s.tone || "") ? o.s.tone : j6 === 6 ? "series-4" : "series-" + (j6 % 3 + 1);
79
+ return {o: o, i: i, a0: a0, a1: a1, mid: (a0 + a1) / 2, lines: lines, col: "var(--" + tone + ")", light: !o.s.tone && j6 >= 3 && j6 < 6,
80
+ forms: [lines].concat(alt ? [alt] : []).map(function(ls){ return {lines: ls, w: Math.max.apply(null, ls.map(function(l){ return est(l.t, l.size); }).concat([0])), h: ls.length * 30}; })};
81
+ });
82
+ var ratio = Math.max(0, Math.min(0.85, P.donut || 0));
83
+ // 中に収まるか:字の箱の 4 隅が、その切れの扇形(内側と外側の半径、両端の角度)の中にあるか
84
+ var pt = function(cx, cy, r, a){ return [cx + r * Math.sin(a), cy - r * Math.cos(a)]; };
85
+ var fits1 = function(s, R){
86
+ s.rm = ratio ? (1 + ratio) / 2 : 0.6;
87
+ if (!s.lines.length || s.o.s.place === "in") return true;
88
+ if (s.o.s.place === "out") return false;
89
+ // 字の中心の半径:ドーナツは輪の真ん中、円グラフは 0.6R → 0.5R → 0.7R の順に試す
90
+ var ri = R * ratio, cands = ratio ? [(ri + R) / 2] : [R * 0.6, R * 0.5, R * 0.7];
91
+ for (var n = 0; n < cands.length; n++){
92
+ var c = pt(0, 0, cands[n], s.mid), ok = true;
93
+ [[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function(q){
94
+ var x = c[0] + q[0] * (s.w / 2 + 4), y = c[1] + q[1] * (s.h / 2 + 2), r = Math.hypot(x, y), a = Math.atan2(x, -y);
95
+ if (a < 0) a += TAU;
96
+ if (s.a1 - s.a0 < TAU - 1e-6 && !(a >= s.a0 + 0.02 && a <= s.a1 - 0.02)) ok = false;
97
+ if (r > R - 6 || r < ri + 6) ok = false;
98
+ });
99
+ if (ok){ s.rm = cands[n] / R; return true; }
100
+ }
101
+ return false;
102
+ };
103
+ // 形を 1 つずつ試す。どれも入らなければ外に書く形(最初の形)に戻す
104
+ var fits = function(s, R){
105
+ for (var f = 0; f < s.forms.length; f++){ use(s, f); if (fits1(s, R)) return true; }
106
+ use(s, 0);
107
+ return false;
108
+ };
109
+ function use(s, f){ s.lines = s.forms[f].lines; s.w = s.forms[f].w; s.h = s.forms[f].h; }
110
+ sl.forEach(function(s){ use(s, 0); });
111
+ // 半径:外の字の幅の分だけ左右をあける。中に収まる切れが増えれば半径を見直す(2 回)
112
+ var pad = 10, gap = 44, want = 0, radius = function(outs){
113
+ var wl = 0, wr = 0;
114
+ outs.forEach(function(s){ if (Math.sin(s.mid) >= 0) wr = Math.max(wr, s.w); else wl = Math.max(wl, s.w); });
115
+ var side = Math.max(wl, wr), r = Math.min((H / 2 - pad) * (outs.length ? 0.86 : 1), W / 2 - pad - (side ? side + gap : 0));
116
+ want = 40 - r; // 40 px より小さくなるなら、足りない幅(最小の 40 px で描く)
117
+ return Math.max(40, r);
118
+ };
119
+ var R = radius(sl.filter(function(s){ return s.lines.length; }));
120
+ for (var pass = 0; pass < 2; pass++){
121
+ sl.forEach(function(s){ s.inside = fits(s, R); });
122
+ R = radius(sl.filter(function(s){ return !s.inside; }));
123
+ }
124
+ sl.forEach(function(s){ if (!s.inside && s.o.s.place !== "out" && fits(s, R)) s.inside = true; });
125
+ if (want > 0) ctx.report("size", "[pie] the labels outside leave too little room: the pie is drawn at the smallest radius, 40 px (" + Math.ceil(want * 2) + " px more width needed; make the element wider or the labels shorter)");
126
+ // 字が片側だけなら、字と円をひとまとまりとして真ん中に寄せる
127
+ var wl = 0, wr = 0;
128
+ sl.forEach(function(s){ if (!s.inside && s.lines.length){ if (Math.sin(s.mid) >= 0) wr = Math.max(wr, s.w + gap); else wl = Math.max(wl, s.w + gap); } });
129
+ var cx = W / 2 + (wl - wr) / 2, cy = H / 2, ri = R * ratio;
130
+ this.R = R; this.ri = ri; this.cx = cx; this.cy = cy;
131
+ // 読み上げ:最後の形(すべての切れ)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
132
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
133
+ this.setAttribute("role", "img");
134
+ if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja"), sl, fl, sc, pd, show, total));
135
+ // 1 切れずつ出すときは、全体の輪郭を初めから薄く見せる(どれだけのうちの 1 切れかが分かるように)
136
+ if (pl.some(function(o){ return o.step > 1; })){
137
+ D.el("circle", {cx: cx, cy: cy, r: R, fill: "none", stroke: "var(--line)", "stroke-width": 2}, svg);
138
+ if (ri) D.el("circle", {cx: cx, cy: cy, r: ri, fill: "none", stroke: "var(--line)", "stroke-width": 2}, svg);
139
+ }
140
+ var gS = D.el("g", {}, svg), gL = D.el("g", {}, svg);
141
+ // 外の字:左右の列に置き、縦に重ならないように並べ直す
142
+ [1, -1].forEach(function(side){
143
+ var outs = sl.filter(function(s){ return !s.inside && s.lines.length && (Math.sin(s.mid) >= 0 ? 1 : -1) === side; });
144
+ outs.forEach(function(s){ s.yc = cy - (R + 18) * Math.cos(s.mid); });
145
+ outs.sort(function(a, b){ return a.yc - b.yc; });
146
+ // 上から押し下げ、下からはみ出す分を押し上げる(字の箱の間は 8 px)
147
+ for (var j = 0; j < outs.length; j++){
148
+ var mn = j ? outs[j - 1].yc + (outs[j - 1].h + outs[j].h) / 2 + 8 : outs[0].h / 2 + 2;
149
+ if (outs[j].yc < mn) outs[j].yc = mn;
150
+ }
151
+ for (var q = outs.length - 1; q >= 0; q--){
152
+ var mx = q === outs.length - 1 ? H - 2 - outs[q].h / 2 : outs[q + 1].yc - (outs[q + 1].h + outs[q].h) / 2 - 8;
153
+ if (outs[q].yc > mx) outs[q].yc = mx;
154
+ }
155
+ if (outs.length && outs[0].yc - outs[0].h / 2 < 0) ctx.report("size", "[pie] the labels outside do not fit the height (make the element taller or put fewer slices)");
156
+ var colX = cx + side * (R + gap - 8);
157
+ outs.forEach(function(s){
158
+ // 引き出し線:切れの外の縁から、円の外側を回って字の列へ
159
+ var p1 = pt(cx, cy, R + 4, s.mid), dy = s.yc - cy, rr = R + 14;
160
+ var qx = cx + side * Math.max(Math.abs((R + 16) * Math.sin(s.mid)), Math.sqrt(Math.max(0, rr * rr - dy * dy)));
161
+ s.leader = D.el("path", {d: "M" + p1[0].toFixed(1) + "," + p1[1].toFixed(1) + "L" + qx.toFixed(1) + "," + s.yc.toFixed(1) + "L" + (colX - side * 6).toFixed(1) + "," + s.yc.toFixed(1),
162
+ fill: "none", stroke: "var(--muted)", "stroke-width": 1.5}, gL);
163
+ s.tx = colX; s.anchor = side > 0 ? "start" : "end";
164
+ if (side > 0 ? colX + s.w > W + 1 : colX - s.w < -1) ctx.report("size", "[pie] the label \"" + s.lines[0].t + "\" is wider than the space beside the pie");
165
+ });
166
+ });
167
+ sl.forEach(function(s){
168
+ s.path = D.el("path", {d: "", fill: s.col, "fill-opacity": s.light ? 0.5 : 1, stroke: "var(--bg)", "stroke-width": 2, "stroke-linejoin": "round"}, gS);
169
+ if (!s.lines.length) return;
170
+ var g = s.g = D.el("g", {opacity: 0}, gL), x, y0;
171
+ if (s.inside){
172
+ var c = pt(cx, cy, s.rm * R, s.mid);
173
+ x = c[0]; y0 = c[1] - s.h / 2;
174
+ } else { x = s.tx; y0 = s.yc - s.h / 2; }
175
+ // 中の字は切れの色の上なので背景の色(濃い色の切れ)か本文の色(薄い切れ)
176
+ var fill = s.inside ? (s.light ? "var(--fg)" : "var(--bg)") : "var(--fg)";
177
+ s.lines.forEach(function(l, j){
178
+ D.mtext(g, x, y0 + j * 30 + 24, l.t, {"text-anchor": s.inside ? "middle" : s.anchor, "font-size": l.size, "font-weight": l.bold ? 700 : 400, fill: fill});
179
+ });
180
+ });
181
+ // ドーナツの中の字({total} は合計)
182
+ this.center = null;
183
+ if (ri && d.center){
184
+ var cl = String(d.center).replace(/\{total\}/g, this.fmt(total)).split("\n"), size = 26;
185
+ var cw = Math.max.apply(null, cl.map(function(t){ return est(t, size); }));
186
+ if (cw > ri * 1.8){ size = 24; cw = cw * 24 / 26; }
187
+ if (cw > ri * 1.8) ctx.report("size", "[pie] the center text is wider than the hole (make donut larger or the text shorter)");
188
+ var cg = this.center = D.el("g", {opacity: 0}, gL);
189
+ cl.forEach(function(t, j){ D.mtext(cg, cx, cy - (cl.length - 1) * 16 + j * 32 + 9, t, {"text-anchor": "middle", "font-size": size, "font-weight": j === 0 ? 700 : 400}); });
190
+ }
191
+ }
192
+ // 最後の形を 1 文で(読み上げの名前):「内訳:食費 35%、住まい 41%、…(中:合計 21.2万円)」。show が value / both なら値も書く
193
+ summary(ja, sl, fl, sc, pd, show, total){
194
+ var self = this, d = this.data || {};
195
+ var parts = sl.map(function(s){
196
+ var pct = (fl[s.i] / sc).toFixed(pd) + "%", v = self.fmt(Math.max(0, +s.o.s.value));
197
+ var x = show === "value" ? v : show === "both" ? v + (ja ? "(" + pct + ")" : " (" + pct + ")") : pct;
198
+ return (s.o.s.label ? String(s.o.s.label).replace(/\s*\n\s*/g, " ") + " " : "") + x;
199
+ });
200
+ var c = this.ri && d.center ? String(d.center).replace(/\{total\}/g, this.fmt(total)).replace(/\s*\n\s*/g, " ") : "";
201
+ return (ja ? "内訳:" : "Breakdown: ") + parts.join(ja ? "、" : ", ") + (c ? (ja ? "(中:" + c + ")" : " (centre: " + c + ")") : "");
202
+ }
203
+ // 数の書き方:3 桁ごとのカンマ、小数桁、単位(m-bars と同じ)
204
+ fmt(v){
205
+ var s = Math.abs(v).toFixed(this.props.digits).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
206
+ return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "") + this.props.unit;
207
+ }
208
+ wedge(a0, a1, r0, r1){
209
+ var cx = this.cx, cy = this.cy, TAU = Math.PI * 2;
210
+ if (a1 - a0 <= 1e-6 || r1 <= 0) return "";
211
+ var p = function(r, a){ return (cx + r * Math.sin(a)).toFixed(2) + "," + (cy - r * Math.cos(a)).toFixed(2); };
212
+ // 全周、または残りが小さくて両端の点が丸めると重なる(99.999 % のような切れ)ときは、全周で描く(1 つの弧では何も描かれない)
213
+ if (a1 - a0 >= TAU - 1e-6 || (TAU - (a1 - a0)) * r1 < 0.05){
214
+ // 全周:2 つの半円で描く
215
+ var full = "M" + p(r1, 0) + "A" + r1 + "," + r1 + " 0 1,1 " + p(r1, Math.PI) + "A" + r1 + "," + r1 + " 0 1,1 " + p(r1, 0) + "Z";
216
+ return r0 > 0 ? full + "M" + p(r0, 0) + "A" + r0 + "," + r0 + " 0 1,0 " + p(r0, Math.PI) + "A" + r0 + "," + r0 + " 0 1,0 " + p(r0, 0) + "Z" : full;
217
+ }
218
+ var big = a1 - a0 > Math.PI ? 1 : 0;
219
+ var s = "M" + p(r1, a0) + "A" + r1 + "," + r1 + " 0 " + big + ",1 " + p(r1, a1);
220
+ s += r0 > 0 ? "L" + p(r0, a1) + "A" + r0 + "," + r0 + " 0 " + big + ",0 " + p(r0, a0) + "Z" : "L" + cx.toFixed(2) + "," + cy.toFixed(2) + "Z";
221
+ return s;
222
+ }
223
+ duration(k){
224
+ return this.plan().some(function(o){ return o.step === k; }) ? this.props.dur : 0;
225
+ }
226
+ render(k, t, ctx){
227
+ var P = this.props, D = base, self = this, vr = this.variant, dur = P.dur, span = dur * 0.6, lecture = !!ctx.preview, FAINT = 0.45;
228
+ if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
229
+ var TAU = Math.PI * 2, R = this.R, ri = this.ri;
230
+ // 同じ段階の切れが占める角度の範囲(sweep はこの範囲を掃く)
231
+ var rng = {};
232
+ this.slices.forEach(function(s){ var st = s.o.step, q = rng[st] || (rng[st] = [Infinity, -Infinity]); q[0] = Math.min(q[0], s.a0); q[1] = Math.max(q[1], s.a1); });
233
+ var first = Infinity;
234
+ this.slices.forEach(function(s){
235
+ var st = s.o.step, tt = st < k ? Infinity : st > k ? -1 : t, faint = lecture && st > k;
236
+ first = Math.min(first, st);
237
+ var a0 = s.a0, a1 = s.a1, r0 = ri, r1 = R, op = 1, dy = 0, lo;
238
+ if (faint){ op = FAINT; lo = FAINT; }
239
+ else if (tt < 0){ op = 0; lo = 0; }
240
+ else if (vr === "sweep"){
241
+ // 12 時の位置(1 切れずつなら、その段階の最初の切れの端)から時計回りに掃く
242
+ var q = rng[st], e = D.prog(tt, 0, span), edge = q[0] + (q[1] - q[0]) * e;
243
+ a1 = Math.min(a1, edge);
244
+ lo = D.prog(tt, span * (s.a1 - q[0]) / Math.max(1e-6, q[1] - q[0]) * 0.9, dur - span);
245
+ } else if (vr === "grow"){
246
+ // 中心から:外側の縁が 12 px 内側から元の大きさへ(fade の上がる距離と同じ)
247
+ var g = D.prog(tt, 0, span), f = (R - 12 * (1 - g)) / R;
248
+ r0 = ri * f; r1 = R * f; op = Math.min(1, g * 2.5 + (g > 0 ? 0.2 : 0));
249
+ lo = D.prog(tt, span, dur - span);
250
+ } else {
251
+ var e2 = D.prog(tt, 0, span);
252
+ op = e2; dy = (1 - e2) * 12;
253
+ lo = D.prog(tt, span, dur - span);
254
+ }
255
+ s.path.setAttribute("d", op > 0 ? self.wedge(a0, a1, r0, r1) : "");
256
+ s.path.setAttribute("opacity", op.toFixed(3));
257
+ s.path.setAttribute("transform", dy ? "translate(0 " + dy.toFixed(2) + ")" : "");
258
+ if (s.g) s.g.setAttribute("opacity", lo.toFixed(3));
259
+ if (s.leader) s.leader.setAttribute("opacity", lo.toFixed(3));
260
+ });
261
+ if (this.center){
262
+ var c = first < k ? 1 : first > k ? (lecture ? FAINT : 0) : D.prog(t, span, dur - span);
263
+ this.center.setAttribute("opacity", c.toFixed(3));
264
+ }
265
+ }
266
+ };
267
+ });
@@ -0,0 +1,52 @@
1
+ ---
2
+ summary: Icon cards in a row or 2 rows, by step; arrows for order
3
+ steps: largest card step (default 1 card = 1 step)
4
+ props:
5
+ layout: row, or grid (2×2; 3×2 for 5–6)
6
+ arrows: order arrows (grid: Z order)
7
+ nums: number circles
8
+ hilite: last or a number (from 1)
9
+ per-step: cards per step (0 = all)
10
+ stagger: card offset (s)
11
+ dur: appear seconds
12
+ example: {"cards": [{"icon": "user", "title": "Listen", "text": "Hear the problem"}, {"icon": "bulb", "title": "Think", "text": "Find 3 ideas"}, {"icon": "rocket", "title": "Try", "text": "Build small, show"}]}
13
+ ---
14
+
15
+ Steps, 3–4 key points, or a 2×2 of cases, as icon cards.
16
+
17
+ Child JSON: `{"cards": [{"n", "icon", "title", "text", "step", "tone"}, …]}` (2–6 cards).
18
+
19
+ - `title`: required, ≤ 2 lines. `text`: wraps; cut with … and reported if too long
20
+ - `icon`: Tabler outline name (list below); unknown = dashed box, reported
21
+ - `n`: circle text (`"A"`, `"1"`); `nums` numbers the rest 1, 2, 3 …
22
+ - `tone`: circle and icon colour (`term`, `emph`, `accent2`, `series-1..4`)
23
+ - `layout="grid"`: wide cards put number, icon, title on one line
24
+ - `arrows`; `hilite="last"` or `"3"`: `--emph` frame and fill
25
+ - `variant`: `rise` (default), `fade`, `draw`
26
+
27
+ Icons:
28
+
29
+ - People: user users user-check user-plus user-circle friends mood-smile man woman id-badge
30
+ - Data: chart-bar chart-line chart-pie chart-dots trending-up trending-down table database filter adjustments percentage sum
31
+ - Money: coin cash credit-card wallet receipt pig-money building-bank report-money shopping-cart tag
32
+ - Time: clock calendar calendar-event calendar-time hourglass history alarm stopwatch
33
+ - Place: map-pin map world home building building-factory building-store route truck
34
+ - Flow: arrow-right arrows-right-left refresh repeat circle-check checklist list-numbers git-branch target flag rocket hand-click
35
+ - Talk: message messages mail phone bell speakerphone share world-www microphone presentation
36
+ - Docs: file file-text files notebook book clipboard-list folder news certificate award
37
+ - Tools: tool settings hammer bulb puzzle cpu device-laptop device-mobile robot code scale
38
+ - Nature: leaf tree plant sun moon cloud cloud-rain droplet flame snowflake
39
+ - Safety: shield shield-check lock key alert-triangle first-aid-kit heart heart-rate-monitor eye
40
+ - Learning: school pencil ruler math-function atom flask microscope palette music language
41
+
42
+ The demo is `demo.html`. Companies and numbers are fictional.
43
+
44
+ <!-- llm: omit -->
45
+ Notes for authors of parts
46
+
47
+ - Icons come by name from the library part `icons` (Tabler outline, MIT); a build keeps only the names a lesson uses. Colour: `currentColor`
48
+ - Sizes: icon 32–64 px, title 26–34 px, text 24 px
49
+ - Overflow is cut with … and reported once (`layout`)
50
+ - Screen readers: svg `role="list"`, cards `role="listitem"` with number, title and text; icons and arrows `aria-hidden`
51
+ - Lecture view: later cards at `--preview-opacity`; print and video show the last step
52
+ <!-- llm: end -->
@@ -0,0 +1,219 @@
1
+ // m-cards:カードを横一列(row)か 2 段(grid:2×2、5〜6 枚なら 3×2)に並べ、段階ごとに出す。カードは番号の丸・アイコン・見出し・説明
2
+ // <m-cards arrows style="height:320px"><script type="application/json">
3
+ // {"cards": [{"icon": "user", "title": "聞く", "text": "相手の困りごとを聞く"}, {"icon": "bulb", "title": "考える"}]}
4
+ // (JSON の終わり)</m-cards>
5
+ // 段階:既定はカード 1 枚 = 1 段階(per-step で n 枚ずつ、カードの step で直接)
6
+ // アイコンは名前で引く(ライブラリ部品 icons、Tabler Icons outline)。組み立てはレッスンに書かれた名前のアイコンだけを残す
7
+ // 説明は和文を文節の切れ目らしい所(平仮名の後ろで平仮名でない字の前、読点・空白の後ろ)で折り返し、入らなければ … で切って ctx.report
8
+ // 見せ方(docs/conventions.md §1):rise(下から、既定)・fade(その場で)・draw(枠と矢印を描いてから中身)。段階の数・長さ・最後の中身はどれも同じ
9
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・clamp・variant・previewOpacity と icons の svg を使い、プレイヤーのグローバルは使わない
10
+ egatariParts.define({name: "cards", version: "2.0.2", requires: {base: "1.1.0", icons: "1.0.0"}, element: "m-cards"}, function(deps){
11
+ "use strict";
12
+ var base = deps.base, icons = deps.icons;
13
+ var TONES = /^(term|emph|accent2|series-[1-4])$/;
14
+ // 字の幅の見積もり(字の大きさ 1 あたり。base の textWidth:font の要素の字で測った幅。mtext で書くので *_^ は数えない)
15
+ function est(s, font){ return base.textWidth(s, 1, {font: font, mark: true}); }
16
+ // 折ってよい所:空白・読点の後ろ、平仮名の後ろで平仮名でない字の前、欧文と和文の境(数と単位の間は除く)。行の頭に置かない字(小さい仮名・長音・句読点・閉じ括弧)の前では折らない
17
+ var HEADLESS = /[ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮー、。,.・)」』】〕!?!?,.)]/, HIRA = /[ぁ-ゖ]/, LATIN = /[\u0000-ɏ]/;
18
+ function breaks(ch){
19
+ var ok = [];
20
+ for (var i = 1; i < ch.length; i++){
21
+ var a = ch[i - 1], b = ch[i];
22
+ // 数と単位(「5 分」「1 枚」)の間では折らない
23
+ if (/[0-9]/.test(a) && (b === " " || !LATIN.test(b)) || a === " " && /[0-9]/.test(ch[i - 2] || "") && !LATIN.test(b)){ ok[i] = false; continue; }
24
+ ok[i] = !HEADLESS.test(b) && !/[(「『【〔(]/.test(a) &&
25
+ (a === " " || /[、。,.]/.test(a) || (HIRA.test(a) && !HIRA.test(b)) || (LATIN.test(a) !== LATIN.test(b) && b !== " "));
26
+ }
27
+ return ok;
28
+ }
29
+ // s を幅 w(字の大きさ size、字は要素 font のもの)の行に折る。行の数が max を超えれば最後の行を … で切る。{lines, cut}
30
+ function wrap(s, w, size, max, font){
31
+ var out = [], paras = String(s).split("\n"), cut = false;
32
+ paras.forEach(function(p){
33
+ var ch = [...p], ok = breaks(ch), start = 0, last = -1;
34
+ for (var i = 0; i <= ch.length; i++){
35
+ if (i > start && est(ch.slice(start, i).join(""), font) * size > w){
36
+ // 入らない:最後の折ってよい所で折る(なければ字の所で。行の頭に置かない字は前の行に残す)
37
+ var at = last > start ? last : i - 1;
38
+ if (at <= start) at = start + 1;
39
+ while (last <= start && at < ch.length && HEADLESS.test(ch[at]) && at - start > 1) at--;
40
+ out.push(ch.slice(start, at).join("").replace(/ +$/, ""));
41
+ start = at; while (ch[start] === " ") start++;
42
+ last = -1; i = start;
43
+ continue;
44
+ }
45
+ if (i < ch.length && ok[i]) last = i;
46
+ }
47
+ out.push(ch.slice(start).join(""));
48
+ });
49
+ if (out.length > max){
50
+ cut = true; out = out.slice(0, max);
51
+ var l = [...out[max - 1]];
52
+ while (l.length && est(l.join("") + "…", font) * size > w) l.pop();
53
+ out[max - 1] = l.join("").replace(/[、。 ]$/, "") + "…";
54
+ }
55
+ return {lines: out, cut: cut};
56
+ }
57
+ return class extends base.MotionElement {
58
+ static partName = "cards"; // the registry name (define meta name), for report prefixes
59
+ static variants = ["rise", "fade", "draw"];
60
+ // データの形(kit/shape.js)
61
+ static shape = {
62
+ schema: {type: "object", additionalProperties: false, required: ["cards"], properties: {
63
+ cards: {type: "array", minItems: 2, maxItems: 6, items: {type: "object", additionalProperties: false, required: ["title"], properties: {
64
+ n: {type: "string"}, icon: {type: "string"}, title: {type: "string"}, text: {type: "string"}, step: {type: "integer"}, tone: {type: "string"}}}}}},
65
+ example: {cards: [{icon: "user", title: "聞く", text: "相手の困りごとを聞く"}, {icon: "bulb", title: "考える", text: "案を 3 つ出す"}, {icon: "rocket", title: "試す", text: "小さく作って見せる"}]},
66
+ };
67
+ static props = {
68
+ layout: {type: "enum", values: ["row", "grid"], default: "row", doc: "row:横一列。grid:2 段(4 枚までは 2×2、5〜6 枚は 3×2)"},
69
+ arrows: {type: "bool", default: false, doc: "カードの間に順の矢印(grid では 1→2→3→4 の Z の順)"},
70
+ nums: {type: "bool", default: false, doc: "番号の丸を出す(カードの n が優先。n だけ書いたカードはそれを出す)"},
71
+ hilite: {type: "string", default: "", doc: "強調するカード:last か番号(1 から)。--emph の枠と地"},
72
+ "per-step": {type: "number", default: 1, doc: "1 段階に出すカードの数(0 = 全部を段階 1 で)"},
73
+ stagger: {type: "number", default: 0.25, doc: "同じ段階のカードの出だしのずれ(秒)"},
74
+ dur: {type: "number", default: 0.5, doc: "1 枚が出る秒数"},
75
+ };
76
+ get steps(){
77
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
78
+ var m = 0;
79
+ this.plan().forEach(function(o){ m = Math.max(m, o.step); });
80
+ return m;
81
+ }
82
+ plan(){
83
+ if (this._plan) return this._plan;
84
+ var P = this.props, per = P["per-step"], seen = {};
85
+ return (this._plan = ((this.data || {}).cards || []).slice(0, 6).map(function(c, i){
86
+ var step = c.step !== undefined ? c.step : per > 0 ? Math.floor(i / per) + 1 : 1;
87
+ var j = seen[step] = (seen[step] || 0) + 1;
88
+ return {c: c, i: i, step: step, at: +((j - 1) * P.stagger).toFixed(3)};
89
+ }));
90
+ }
91
+ mount(ctx){
92
+ var P = this.props, D = base, self = this, pl = this.plan(), n = pl.length;
93
+ this.variant = base.variant(this);
94
+ this.style.display = "block"; this.style.position = "relative";
95
+ var W = this.clientWidth, H = this.clientHeight;
96
+ var grid = P.layout === "grid" && n > 2, cols = grid ? (n <= 4 ? 2 : 3) : n, rows = grid ? 2 : 1;
97
+ var gap = P.arrows ? 60 : 24, vgap = P.arrows ? 48 : 24;
98
+ var cw = (W - gap * (cols - 1)) / cols, ch = (H - vgap * (rows - 1)) / rows;
99
+ this.cards = []; this.arrows = [];
100
+ // 高さ(幅)のない要素:カードの枠が負の大きさになる。描かずに知らせる
101
+ if (!(cw > 0 && ch > 0)){
102
+ ctx.report("size", "[cards] the element is " + W + "×" + H + "px, too small for " + n + " card" + (n === 1 ? "" : "s") + "; give it a height (e.g. style=\"height:320px\")");
103
+ return;
104
+ }
105
+ // 読み上げの名前:作者の aria-label、なければカードの数と見出し
106
+ var ja = /^ja\b/i.test(ctx.lang || "ja");
107
+ var name = this.getAttribute("aria-label") || (ja ? "カード " + n + " 枚:" : n + " cards: ") + pl.map(function(o){ return o.c.title; }).join(ja ? "、" : ", ");
108
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, role: "list", "aria-label": name, style: "display:block;overflow:visible"}, this);
109
+ var hl = P.hilite === "last" ? n - 1 : /^\d+$/.test(P.hilite) ? +P.hilite - 1 : -1;
110
+ if (P.hilite && (hl < 0 || hl >= n)) ctx.report("attr", '[cards] hilite="' + P.hilite + '" is not last or a card number 1–' + n);
111
+ // カードの中:横に広いカード(幅が高さの 1.6 倍以上)は 番号・アイコン・見出しを 1 行に、ほかは縦に積む
112
+ var pad = 20, wide = cw >= ch * 1.6;
113
+ var isz = Math.round(Math.max(32, Math.min(64, cw * 0.22, ch * 0.24)));
114
+ var tsz = Math.round(Math.max(26, Math.min(34, cw * 0.11))), xsz = 24, lh = 34, bd = 44;
115
+ var missing = function(m){ ctx.report("data", "[cards] " + m); };
116
+ var unfit = [];
117
+ this.cards = pl.map(function(o, i){
118
+ var c = o.c, col = i % cols, row = Math.floor(i / cols);
119
+ var x = col * (cw + gap), y = row * (ch + vgap);
120
+ var tone = TONES.test(c.tone || "") ? c.tone : "term", hi = i === hl;
121
+ var g = D.el("g", {opacity: 0, role: "listitem", "aria-label": [c.n || (P.nums ? String(i + 1) : ""), c.title, c.text || ""].filter(Boolean).join(" ")}, svg);
122
+ var frame = D.el("rect", {x: x + 1, y: y + 1, width: cw - 2, height: ch - 2, rx: 14, fill: hi ? "var(--emph-tint)" : "var(--term-tint)", stroke: hi ? "var(--emph)" : "var(--line)", "stroke-width": hi ? 4 : 2}, g);
123
+ var body = D.el("g", {}, g);
124
+ var badge = c.n !== undefined ? String(c.n) : P.nums ? String(i + 1) : "";
125
+ var cy = y + pad, textW = cw - 2 * pad, hx = x + pad;
126
+ if (wide){
127
+ // 1 行目:番号・アイコン・見出し(左から)
128
+ var lineH = Math.max(bd, isz * 0.8);
129
+ if (badge){ self.badge(body, hx + bd / 2, cy + lineH / 2, badge, tone); hx += bd + 14; }
130
+ if (c.icon){ self.icon(body, c.icon, hx, cy + lineH / 2 - isz * 0.4, isz * 0.8, tone, missing); hx += isz * 0.8 + 14; }
131
+ var tw = wrap(c.title, x + cw - pad - hx, tsz, 2, self);
132
+ tw.lines.forEach(function(s, j){ D.mtext(body, hx, cy + lineH / 2 + tsz * 0.36 + (j - (tw.lines.length - 1) / 2) * (tsz + 6), s, {"font-size": tsz, "font-weight": 700}); });
133
+ if (tw.cut) unfit.push(i + 1 + " (title)");
134
+ cy += Math.max(lineH, tw.lines.length * (tsz + 6)) + 16;
135
+ } else {
136
+ // 縦:番号は左上、アイコンは上の真ん中、その下に見出し(真ん中)
137
+ if (badge) self.badge(body, x + pad + bd / 2, y + pad + bd / 2, badge, tone);
138
+ if (c.icon){ self.icon(body, c.icon, x + cw / 2 - isz / 2, cy, isz, tone, missing); cy += isz + 14; }
139
+ else if (badge) cy += bd + 8;
140
+ var tw2 = wrap(c.title, textW, tsz, 2, self);
141
+ tw2.lines.forEach(function(s){ cy += tsz; D.mtext(body, x + cw / 2, cy, s, {"text-anchor": "middle", "font-size": tsz, "font-weight": 700}); cy += 6; });
142
+ if (tw2.cut) unfit.push(i + 1 + " (title)");
143
+ cy += 12;
144
+ }
145
+ if (c.text){
146
+ var room = Math.max(0, Math.floor((y + ch - pad - cy + (lh - xsz)) / lh));
147
+ var tx = wrap(c.text, textW, xsz, Math.max(1, room), self);
148
+ var center = !wide && tx.lines.length === 1;
149
+ tx.lines.forEach(function(s, j){ D.mtext(body, center ? x + cw / 2 : x + pad, cy + xsz + j * lh, s, center ? {"text-anchor": "middle", "font-size": xsz} : {"font-size": xsz}); });
150
+ if (tx.cut || room < 1) unfit.push(String(i + 1));
151
+ }
152
+ // 前のカードからの矢印(この カードと一緒に出る)
153
+ var arrow = null;
154
+ if (P.arrows && i > 0){
155
+ var pc = (i - 1) % cols, pr = Math.floor((i - 1) / cols);
156
+ var ax, ay, d, alen = 60;
157
+ if (pr === row){ ax = pc * (cw + gap) + cw + gap / 2; ay = y + ch / 2; d = "M" + (ax - 10) + "," + (ay - 16) + "L" + (ax + 8) + "," + ay + "L" + (ax - 10) + "," + (ay + 16); }
158
+ else {
159
+ // 段が変わる(grid の 2→3、3→4):前の段の最後のカードの下から出て、段の間を左へ、次の段の最初のカードへ下りる
160
+ var bx = pc * (cw + gap) + cw / 2, ex = col * (cw + gap) + cw / 2, y0 = pr * (ch + vgap) + ch + 6, ym = y0 - 6 + vgap / 2, y1 = y - 6;
161
+ d = "M" + bx + "," + y0 + "V" + ym + "H" + ex + "V" + y1 + "L" + (ex - 10) + "," + (y1 - 9) + "L" + ex + "," + y1 + "L" + (ex + 10) + "," + (y1 - 9);
162
+ alen = (ym - y0) + Math.abs(bx - ex) + (y1 - ym) + 42; // 1 本の道(破線で描くとき矢じりが最後に出る)
163
+ }
164
+ arrow = D.el("path", {d: d, fill: "none", stroke: "var(--muted)", "stroke-width": 5, "stroke-linecap": "round", "stroke-linejoin": "round", opacity: 0, "aria-hidden": "true"}, svg);
165
+ arrow._len = alen;
166
+ self.arrows.push(arrow);
167
+ }
168
+ return {o: o, g: g, body: body, frame: frame, arrow: arrow, per: 2 * (cw + ch)};
169
+ });
170
+ if (unfit.length) ctx.report("layout", "[cards] the text of card " + unfit.join(", ") + " does not fit; it is cut with …. Shorten it, or give the element more height");
171
+ }
172
+ badge(parent, cx, cy, s, tone){
173
+ var D = base;
174
+ D.el("circle", {cx: cx, cy: cy, r: 22, fill: "var(--" + tone + ")"}, parent);
175
+ D.mtext(parent, cx, cy + 9, s, {"text-anchor": "middle", "font-size": 26, "font-weight": 700, fill: "var(--bg)"});
176
+ }
177
+ icon(parent, name, x, y, size, tone, missing){
178
+ var wrapG = base.el("g", {style: "color:var(--" + tone + ");"}, parent);
179
+ wrapG.appendChild(icons.svg(name, {x: x, y: y, size: size, missing: missing}));
180
+ }
181
+ duration(k){
182
+ var P = this.props, d = 0, dr = this.variant === "draw" ? 0.4 : 0;
183
+ this.plan().forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + dr + P.dur); });
184
+ return d;
185
+ }
186
+ cues(k){
187
+ var c = [];
188
+ this.plan().forEach(function(o){ if (o.step === k && o.at > 0) c.push(o.at); });
189
+ return c.length ? c.sort(function(a, b){ return a - b; }) : null;
190
+ }
191
+ render(k, t, ctx){
192
+ var P = this.props, D = base, vr = this.variant;
193
+ // 先の段階を薄く見せる表示(授業の表示):後の段階のカードを最後の形で、テーマの --preview-opacity の濃さに
194
+ var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
195
+ this.cards.forEach(function(o){
196
+ var s = o.o.step, at = o.o.at, ahead = preview && s > k;
197
+ var tt = s < k || ahead ? Infinity : s > k ? -1 : t; // このカードの段階の中の時刻(-1 = まだ)
198
+ var dr = vr === "draw" ? 0.4 : 0;
199
+ var e = tt < 0 ? 0 : D.prog(tt, at + dr, P.dur);
200
+ if (vr === "draw"){
201
+ // 枠を描いてから中身
202
+ var f = tt < 0 ? 0 : D.prog(tt, at, dr + P.dur * 0.3);
203
+ o.g.setAttribute("opacity", ahead ? PV.toFixed(3) : tt < 0 ? "0" : "1");
204
+ o.frame.setAttribute("stroke-dasharray", f >= 1 ? "" : (o.per * f).toFixed(1) + " " + o.per.toFixed(1));
205
+ o.frame.setAttribute("fill-opacity", f >= 1 ? "1" : "0");
206
+ o.body.setAttribute("opacity", e.toFixed(3));
207
+ } else {
208
+ o.g.setAttribute("opacity", ahead ? PV.toFixed(3) : e.toFixed(3));
209
+ o.g.setAttribute("transform", vr === "rise" && e < 1 ? "translate(0 " + ((1 - e) * 16).toFixed(2) + ")" : "");
210
+ }
211
+ if (o.arrow){
212
+ var a = tt < 0 ? 0 : D.prog(tt, at, vr === "draw" ? dr : P.dur * 0.6);
213
+ o.arrow.setAttribute("opacity", ahead ? PV.toFixed(3) : vr === "draw" ? (a > 0 ? "1" : "0") : a.toFixed(3));
214
+ o.arrow.setAttribute("stroke-dasharray", vr === "draw" && a < 1 ? (o.arrow._len * a).toFixed(1) + " " + o.arrow._len.toFixed(1) : "");
215
+ }
216
+ });
217
+ }
218
+ };
219
+ });
@@ -0,0 +1,66 @@
1
+ ---
2
+ summary: Timeline; events one by one; periods as bands, overlaps stacked; end exclusive ("1912" = start of 1912)
3
+ steps: event count (default 1 per step in time order; per-step n each; node step wins)
4
+ props:
5
+ orient: h or v
6
+ scale: time or even
7
+ per-step: events per step (0 = all)
8
+ size: label px (shrinks to 24)
9
+ dur: event appear (s)
10
+ stagger: event offset (s)
11
+ unit: ticks: day, week, month
12
+ today: today line (YYYY-MM-DD)
13
+ example: {"nodes": [{"id": "a", "label": "Meiji Restoration", "when": "1868", "whenLabel": "Meiji 1"}, {"id": "b", "label": "Constitution", "when": "1889", "note": "Feb 11"}, {"id": "c", "label": "Sino-Japanese War", "when": "1894", "end": "1895", "tone": "emph"}]}
14
+ ---
15
+
16
+ History, lives, schedules. No coordinates; content and times only.
17
+
18
+ Child JSON: `{"nodes": [...], "edges": [...]}` (`edges` optional).
19
+
20
+ - `when`: number (`1868`, `-500`, `0.5`) or `"YYYY"` `"YYYY-MM"` `"YYYY-MM-DD"`; shown as the date line
21
+ - `whenLabel`: text replacing the date ("Meiji 1"); `when` still sets position
22
+ - `label` (`\n`) or `tex` (KaTeX)
23
+ - `note`: small last line in the box (`--muted`); after the name for periods/milestones
24
+ - `tone`: `term` (default), `emph`, `muted`, `accent2`, `series-1..4`
25
+ - `end`: period, a band below the axis; name inside (or beside); `\n` names thicken it
26
+ - `end` is exclusive: Meiji 1868–1912 and Taishō 1912–1926 share a row; through December = next month (`"2027-01"`)
27
+ - `lane`: named group of rows ("Eras", "Authors"); overlaps stack within; `lane` without `end` = milestone (◆)
28
+ - `step`, `at` (start s)
29
+ - `edges`: extra links (`from` `to` `label` `tone` `dash` `step`); dashed arrows (`dash: false` solid)
30
+ - Schedules: `after: ["id", …]` (arrow end→start), `progress` (0–100 %); `today` line; tick `unit`
31
+ - `after` only between periods and milestones; `today` needs a period
32
+
33
+ Layout:
34
+
35
+ - `orient`: `h` (default) or `v`; `scale`: `time` (default) or `even` (very uneven gaps)
36
+ - Events (no `end` or `lane`): axis dot plus date-and-name box, alternating sides (`v`: left/right); 2 rows when crowded
37
+ - With periods: round ticks; event boxes all above the axis
38
+ - Steps: time order, periods and events together; the axis comes with the first
39
+ - `variant`: `fade` (default), `draw` (lines first, bands drawn), `grow` (boxes grow, bands stretch); same steps and end
40
+ - Lecture view (`ctx.preview`): later items faint
41
+ - `cues(k)`: start times of 2nd+ items in a step (for `{cue}`)
42
+
43
+ The demo is `demo.html`; the schedule is fictional, years are history.
44
+
45
+ <!-- llm: omit -->
46
+ Notes
47
+
48
+ - Box and tick widths estimated from characters (CJK 1, digits 0.6, Latin 0.62)
49
+ - No fit: names shrink from `size` by 2px to 24px, then `ctx.report("size", …)`
50
+ - No `Date` (leap years computed); months and days as positions in the year
51
+ - Band names sit in the band's `g`
52
+ - Axis `--muted` 5 px; lane dividers `--line`; links and `edges` `--muted` 3 px
53
+ - Motion: boxes and bands move ≤ 12 px from the axis side, within `fade` time (conventions §1.2)
54
+ <!-- llm: end -->
55
+
56
+ <!-- llm: omit -->
57
+ Schedules (`after`, `progress`, `today`, `unit`)
58
+
59
+ - Any `after`: one row per task in each lane (written order). Arrows only between periods and milestones (others reported)
60
+ - Arrows (`--muted` 3px, right-angled) from a task's end to the next one's start; drawn with the later task; avoid crossing bands where possible
61
+ - A last milestone gets room for its name; arrows to bands whose name is left of the start enter at the edge
62
+ - `progress`: band filled darker from the start; "70%" shown if room; outside 0–100 clamped and reported
63
+ - `today`: only with periods (else reported); small triangle and vertical line (`--accent2`, 3px), "Today" below; range widens to include it
64
+ - `unit`: default month (≤ 4 years with months/days) or round numbers. `day`: 1–2 days or 1–8 weeks (Mondays); `week`: 1–26 weeks; `month`: 1–120 months; finest step whose 24px labels don't overlap; minor ticks unlabeled. Day/week labels "11/2"; `day` shades weekends (`--line`)
65
+ - No plan-vs-actual bands yet
66
+ <!-- llm: end -->