egatari 0.6.18 → 0.6.20-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.ja.md +7 -2
  3. package/README.md +7 -2
  4. package/components.lock.json +40 -12
  5. package/components2.lock.json +534 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +4 -0
  8. package/kit/check.mjs +6 -2
  9. package/kit/core/bookmark.mjs +13 -0
  10. package/kit/core/build-core.mjs +1 -1
  11. package/kit/core/check-parity.mjs +2 -0
  12. package/kit/core/check-rules.mjs +1 -1
  13. package/kit/core/check-source.mjs +4 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +17 -10
  22. package/kit/core/llm-pack-data.mjs +94 -30
  23. package/kit/core/llm-pack.mjs +2 -1
  24. package/kit/core/part-labels.mjs +1 -0
  25. package/kit/core/portable.mjs +5 -2
  26. package/kit/core/scorm.mjs +30 -6
  27. package/kit/core/script-unclosed.mjs +66 -0
  28. package/kit/core/slide-ops.mjs +5 -1
  29. package/kit/core/template-text.mjs +2 -0
  30. package/kit/deck.js +71 -4
  31. package/kit/instruction-version.json +1 -1
  32. package/kit/layouts.css +8 -0
  33. package/kit/panes.js +17 -1
  34. package/kit/player.json +1 -1
  35. package/kit/player.lock.json +2 -2
  36. package/kit/templates/new-deck.mjs +1 -1
  37. package/kit/tools.js +136 -4
  38. package/kit/track.js +46 -5
  39. package/package.json +1 -1
  40. package/server/editor-ui.js +21 -1
  41. package/server/script-field.js +1 -1
  42. package/vendor/components/CATALOG.md +5 -4
  43. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  44. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  45. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  46. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  47. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  48. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  49. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  50. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  51. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/README.en.md +38 -0
  52. package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/index.js +414 -0
  53. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/README.en.md +40 -0
  54. package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/index.js +355 -0
  55. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  56. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  57. package/vendor/components/sha256/9a426812105a44446e8b3f98e0ccfdb6701e8386c08e8aa201b69cb5b52a4c1f/index.js +278 -0
  58. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  59. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  60. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  61. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  62. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/README.en.md +54 -0
  63. package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/index.js +470 -0
  64. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/README.en.md +23 -0
  65. package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/index.js +150 -0
  66. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  67. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  68. package/vendor/components-2/manifest-2.22.0.json +3240 -0
  69. package/vendor/egatari-spec/SOURCE.json +2 -2
  70. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  71. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,306 @@
1
+ // m-scatter:散布図。点の組(系列)を段階ごとに出し、そのあと傾向の線を引く
2
+ // <m-scatter xr="[20,36]" yr="[0,800]" xl="最高気温(℃)" yl="売上(個)" style="height:420px">
3
+ // <script type="application/json">{"series": [{"label": "晴れ", "points": [[24, 210], [31, 560]]}], "trend": "linear"}
4
+ // (JSON の終わり)</m-scatter>
5
+ // 段階:既定は系列 1 つ = 1 段階、そのあと傾向の線(全部で 1 段階)。系列・線の step で直接
6
+ // 軸の属性(xr yr xt yt xf yf xl yl)は m-curves と同じ名前と意味。xr / yr を書かなければデータから切りのよい範囲を決め、
7
+ // xt / yt を書かなければ目盛りも決める
8
+ // 見せ方(docs/conventions.md §1):fade(点がフェードして現れる、既定)・sweep(左から右へ順に現れる)・grow(点が小さい点から
9
+ // 大きくなる)。傾向の線は fade では薄く現れ、sweep では左から引き、grow では真ん中から両側へ伸びる。段階の数・長さ・最後の中身は同じ
10
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity と plot の Plot を使い、
11
+ // プレイヤーのグローバルは使わない。名前の置き場がない・傾向の線が軸の外・上の名前が図より広い、は ctx.report で知らせる
12
+ // (1.x は console.warn)
13
+ egatariParts.define({name: "scatter", version: "2.1.0", requires: {base: "1.3.0", plot: "1.1.3"}, element: "m-scatter"}, function(deps){
14
+ "use strict";
15
+ var base = deps.base, plot = deps.plot;
16
+ return class extends base.MotionElement {
17
+ static partName = "scatter"; // the registry name (define meta name), for report prefixes
18
+ static variants = ["fade", "sweep", "grow"];
19
+ // データの形(kit/shape.js)
20
+ static shape = (function(){
21
+ // 傾向の線の 2 点:ちょうど 2 つの [x, y]
22
+ var PTS = {type: "array", minItems: 2, maxItems: 2, items: {type: "array", minItems: 2, maxItems: 2, items: {type: "number"}}};
23
+ return {
24
+ schema: {type: "object", additionalProperties: false, required: ["series"], properties: {
25
+ series: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["points"], properties: {
26
+ label: {type: "string"}, tone: {type: "string"}, step: {type: "integer"}, at: {type: "number"},
27
+ points: {type: "array", items: {type: ["array", "object"], items: {type: "number"}, minItems: 2, maxItems: 2, required: ["x", "y"],
28
+ properties: {x: {type: "number"}, y: {type: "number"}, label: {type: "string"}, anchor: {enum: ["right", "left", "above", "below", "top", "bottom"]}, tone: {type: "string"}}}}}}},
29
+ trend: {type: ["string", "object", "array"], properties: {fit: {enum: ["linear"]}, pts: PTS, series: {type: ["integer", "array"]},
30
+ label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"}, step: {type: "integer"}, at: {type: "number"}, digits: {type: "integer"}},
31
+ items: {type: "object", properties: {fit: {enum: ["linear"]}, pts: PTS, series: {type: ["integer", "array"]},
32
+ label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"}, step: {type: "integer"}, at: {type: "number"}, digits: {type: "integer"}}}}}},
33
+ example: {series: [{label: "晴れ", points: [[24, 210], [28, 380], [31, 560], {x: 34, y: 690, label: "猛暑日"}]}], trend: "linear"},
34
+ note: {en: "points are [x, y] or {\"x\", \"y\", \"label\"}; axes go in attributes (xr=\"[0,10]\" xl=\"…\"); trend is \"linear\" or {\"fit\": \"linear\", \"label\": \"…\"} or {\"pts\": [[x0, y0], [x1, y1]]}",
35
+ ja: "点は [x, y] か {\"x\", \"y\", \"label\"}。軸は属性に書く(xr=\"[0,10]\" xl=\"…\")。trend は \"linear\" か {\"fit\": \"linear\", \"label\": \"…\"} か {\"pts\": [[x0, y0], [x1, y1]]}"},
36
+ };
37
+ })();
38
+ static props = {
39
+ xr: {type: "json", default: null, doc: "横軸の範囲(書かなければデータから)"}, yr: {type: "json", default: null, doc: "縦軸の範囲(書かなければデータから)"},
40
+ xt: {type: "json", default: null, doc: "横軸の目盛り(書かなければ自動)"}, yt: {type: "json", default: null, doc: "縦軸の目盛り(書かなければ自動)"},
41
+ xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
42
+ xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
43
+ r: {type: "number", default: 9, doc: "点の半径(px)"},
44
+ dur: {type: "number", default: 1.0, doc: "1 ステップの動きの秒数"},
45
+ };
46
+ get steps(){
47
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
48
+ var m = 0, pl = this.plan();
49
+ pl.series.forEach(function(s){ m = Math.max(m, s.step); });
50
+ pl.trends.forEach(function(s){ m = Math.max(m, s.step); });
51
+ return m;
52
+ }
53
+ // 系列と傾向の線の段階(mount の前にも steps が要るので、データだけから決める)
54
+ plan(){
55
+ if (this._plan) return this._plan;
56
+ var d = this.data || {}, last = 0;
57
+ var series = (d.series || []).map(function(s, i){
58
+ var step = s.step !== undefined ? s.step : i + 1;
59
+ last = Math.max(last, step);
60
+ return {s: s, i: i, step: step, at: s.at || 0};
61
+ });
62
+ var tr = d.trend === undefined || d.trend === null || d.trend === false ? [] : Array.isArray(d.trend) ? d.trend : [d.trend];
63
+ var trends = tr.map(function(t, i){
64
+ if (typeof t === "string") t = {fit: t}; // "linear" のほかは mount で知らせる(steps の計算では投げない)
65
+ return {t: t, i: i, step: t.step !== undefined ? t.step : last + 1, at: t.at || 0};
66
+ });
67
+ return (this._plan = {series: series, trends: trends});
68
+ }
69
+ mount(ctx){
70
+ var P = this.props, D = base, self = this, pl = this.plan();
71
+ this.variant = base.variant(this);
72
+ this.classList.add("plot"); this.style.display = "block";
73
+ // 字の幅(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
74
+ var est = function(s, size){ return D.textWidth(s, size, {font: self, mark: true}); };
75
+ var colorOf = function(c, i){
76
+ if (!c) return "var(--series-" + (i % 4 + 1) + ")";
77
+ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(c) ? "var(--" + c + ")" : "var(--series-" + (i % 4 + 1) + ")";
78
+ };
79
+ // 点を {x, y, label, anchor, tone} にそろえる
80
+ var all = [];
81
+ pl.series.forEach(function(o){
82
+ o.pts = (o.s.points || []).map(function(q){ var p = Array.isArray(q) ? {x: +q[0], y: +q[1]} : {x: +q.x, y: +q.y, label: q.label, anchor: q.anchor, tone: q.tone}; all.push(p); return p; });
83
+ });
84
+ // 軸の範囲と目盛り:書かれていなければデータから切りのよい数に
85
+ var auto = function(vals, pad){
86
+ var lo = Math.min.apply(null, vals), hi = Math.max.apply(null, vals);
87
+ if (!isFinite(lo)) return [0, 1];
88
+ if (hi === lo){ hi += 1; lo -= 1; }
89
+ var st = tickStep((hi - lo) * (1 + 2 * pad)), a = Math.floor((lo - (hi - lo) * pad) / st) * st, b = Math.ceil((hi + (hi - lo) * pad) / st) * st;
90
+ if (lo >= 0 && a < 0) a = 0;
91
+ return [+a.toFixed(10), +b.toFixed(10)];
92
+ };
93
+ // 書かれた範囲は [小, 大] の 2 つの数のときだけ使う(1 つの数・逆向き・数でない、は知らせてデータから決める)
94
+ var range = function(name){
95
+ var v = P[name];
96
+ if (v === null || v === undefined) return null;
97
+ if (Array.isArray(v) && v.length === 2 && v.every(function(x){ return typeof x === "number" && isFinite(x); }) && v[0] < v[1]) return v;
98
+ ctx.report("attr", "[scatter] " + name + "=\"" + self.getAttribute(name) + "\" is not a range [low, high] of two numbers with low < high (the range is taken from the data)");
99
+ return null;
100
+ };
101
+ var xr = range("xr") || auto(all.map(function(p){ return p.x; }), 0.04), yr = range("yr") || auto(all.map(function(p){ return p.y; }), 0.06);
102
+ // 範囲の外の点は描かない(軸の外や枠の外に出さない)。系列ごとにまとめて知らせる
103
+ pl.series.forEach(function(o){
104
+ var outs = o.pts.filter(function(q){ return !(q.x >= xr[0] && q.x <= xr[1] && q.y >= yr[0] && q.y <= yr[1]); });
105
+ outs.forEach(function(q){ q.out = true; });
106
+ if (outs.length) ctx.report("data", "[scatter] " + outs.length + " point" + (outs.length > 1 ? "s" : "") + (o.s.label ? " of \"" + o.s.label + "\"" : " of series " + (o.i + 1)) + " lie outside xr/yr and are not drawn: " +
107
+ outs.slice(0, 3).map(function(q){ return "(" + q.x + ", " + q.y + ")"; }).join(", ") + (outs.length > 3 ? ", …" : "") + " (widen xr/yr or leave them out)");
108
+ });
109
+ var ticks = function(r){ var st = tickStep(r[1] - r[0]), out = []; for (var v = Math.ceil(r[0] / st - 1e-9) * st; v <= r[1] + st * 1e-6; v += st) out.push(+v.toFixed(10)); return out; };
110
+ var xt = P.xt || ticks(xr), yt = P.yt || ticks(yr);
111
+ var fmt = function(v, f){ return f !== undefined ? v.toFixed(f) : String(v); };
112
+ var named = pl.series.some(function(o){ return o.s.label; }) || pl.trends.some(function(o){ return o.t.label; });
113
+ var yw = Math.max.apply(null, yt.map(function(v){ return est(fmt(v, P.yf), 24); }).concat([0]));
114
+ var m = {l: Math.max(64, yw + 22 + (P.yl ? 40 : 0)), r: 24, t: named ? 72 : 20, b: P.xl ? 66 : 42};
115
+ var p = this.p = plot.Plot(this, {xr: xr, yr: yr, xt: xt, yt: yt, xf: P.xf, yf: P.yf, xl: P.xl, yl: P.yl, m: m});
116
+ p.svg.setAttribute("aria-hidden", "true");
117
+ // 軸の線(横軸と縦軸。目盛りの短い線は除く)に印を付ける(tools/test-components.mjs が字との交差を見る)
118
+ var axl = p.svg.querySelectorAll("g.axes > line");
119
+ for (var a = 0; a < Math.min(2, axl.length); a++) axl[a].setAttribute("class", "axis");
120
+ var W = p.W, H = p.H, x0 = m.l, x1 = W - m.r, y0 = m.t, y1 = H - m.b;
121
+ var gT = D.el("g", {}, p.svg), gP = D.el("g", {}, p.svg), gL = D.el("g", {}, p.svg);
122
+ var R = P.r;
123
+ if (!(typeof R === "number" && isFinite(R) && R > 0)){
124
+ ctx.report("attr", "[scatter] r=\"" + this.getAttribute("r") + "\" is not a positive number (the default radius 9 is used)");
125
+ R = 9;
126
+ }
127
+ // 系列の印の形:丸・四角・三角・ひし形(色だけに頼らない)
128
+ var shapes = [
129
+ function(r){ return "M" + r + ",0A" + r + "," + r + " 0 1,1 " + (-r) + ",0A" + r + "," + r + " 0 1,1 " + r + ",0Z"; },
130
+ function(r){ var s = r * 0.86; return "M" + (-s) + "," + (-s) + "H" + s + "V" + s + "H" + (-s) + "Z"; },
131
+ function(r){ var s = r * 1.2; return "M0," + (-s) + "L" + (s * 0.95).toFixed(2) + "," + (s * 0.62).toFixed(2) + "H" + (-s * 0.95).toFixed(2) + "Z"; },
132
+ function(r){ var s = r * 1.2; return "M0," + (-s) + "L" + s + ",0L0," + s + "L" + (-s) + ",0Z"; }];
133
+ // 置いた字と点の箱(重なりを避ける)
134
+ var boxes = [];
135
+ all.forEach(function(q){ if (!q.out) boxes.push({l: p.x(q.x) - R - 2, r: p.x(q.x) + R + 2, t: p.y(q.y) - R - 2, b: p.y(q.y) + R + 2, pt: q}); });
136
+ var hits = function(b, self2){ return boxes.some(function(o){ return o.pt !== self2 && b.l < o.r && o.l < b.r && b.t < o.b && o.t < b.b; }); };
137
+ this.series = pl.series.map(function(o){
138
+ var col = colorOf(o.s.tone, o.i), path = shapes[o.i % 4](R);
139
+ // marks for the geometry check (spec §8.4): each point is a mark, its name a label outside it; a trend line is an edge
140
+ var marks = o.pts.filter(function(q){ return !q.out; }).map(function(q, j){
141
+ var g = D.el("g", {"data-part": "mark", "data-part-id": "@s" + (o.i + 1) + "p" + (j + 1), transform: "translate(" + p.x(q.x).toFixed(1) + " " + p.y(q.y).toFixed(1) + ")", opacity: 0}, gP);
142
+ var c = q.tone ? colorOf(q.tone, o.i) : col;
143
+ var sh = D.el("path", {d: path, fill: c, "fill-opacity": 0.85, stroke: "var(--bg)", "stroke-width": 1.5}, g);
144
+ return {q: q, g: g, sh: sh, cx: p.x(q.x), cy: p.y(q.y)};
145
+ });
146
+ // 左から右の順(sweep)
147
+ var order = marks.slice().sort(function(u, v){ return u.cx - v.cx; });
148
+ order.forEach(function(mk, j){ mk.rank = order.length > 1 ? j / (order.length - 1) : 0; });
149
+ // 名前のある点:右 → 左 → 上 → 下(anchor があればそれを先に)の順に、点・字・軸と重ならず枠に収まる所へ
150
+ var labels = marks.filter(function(mk){ return mk.q.label; }).map(function(mk){
151
+ var w = est(mk.q.label, 24), cands = {
152
+ right: {x: mk.cx + R + 8, y: mk.cy + 8, a: "start", b: {l: mk.cx + R + 6, r: mk.cx + R + 10 + w, t: mk.cy - 14, b: mk.cy + 12}},
153
+ left: {x: mk.cx - R - 8, y: mk.cy + 8, a: "end", b: {l: mk.cx - R - 10 - w, r: mk.cx - R - 6, t: mk.cy - 14, b: mk.cy + 12}},
154
+ above: {x: mk.cx, y: mk.cy - R - 10, a: "middle", b: {l: mk.cx - w / 2 - 2, r: mk.cx + w / 2 + 2, t: mk.cy - R - 34, b: mk.cy - R - 4}},
155
+ below: {x: mk.cx, y: mk.cy + R + 28, a: "middle", b: {l: mk.cx - w / 2 - 2, r: mk.cx + w / 2 + 2, t: mk.cy + R + 4, b: mk.cy + R + 34}}};
156
+ var pref = ["right", "left", "above", "below"];
157
+ var an = {top: "above", bottom: "below"}[mk.q.anchor] || mk.q.anchor; // top / bottom は above / below の別名
158
+ if (an) pref = [an].concat(pref.filter(function(x){ return x !== an; }));
159
+ var inPlot = function(b){ return b.l >= x0 + 4 && b.r <= x1 && b.t >= y0 && b.b <= y1 - 4; };
160
+ var inBox = function(b){ return b.l >= 0 && b.r <= W && b.t >= 0 && b.b <= H; };
161
+ var pick = pref.filter(function(k){ return inPlot(cands[k].b) && !hits(cands[k].b, mk.q); })[0]
162
+ || pref.filter(function(k){ return inBox(cands[k].b) && !hits(cands[k].b, mk.q); })[0];
163
+ if (!pick){ pick = pref.filter(function(k){ return inBox(cands[k].b); })[0] || pref[0]; ctx.report("layout", "[scatter] the label \"" + mk.q.label + "\" has no free place (it may overlap)"); }
164
+ var c = cands[pick];
165
+ boxes.push({l: c.b.l, r: c.b.r, t: c.b.t, b: c.b.b, pt: mk.q});
166
+ return D.mtext(gL, c.x, c.y, mk.q.label, {"data-part": "label", "data-part-id": mk.g.getAttribute("data-part-id"), "data-part-of": "mark", "data-part-at": "outside", "text-anchor": c.a, "font-size": 24, fill: mk.q.tone ? colorOf(mk.q.tone, o.i) : "var(--fg)", opacity: 0});
167
+ });
168
+ return {o: o, col: col, path: path, marks: marks, labels: labels};
169
+ });
170
+ // 傾向の線:最小二乗の直線(fit: "linear")か、2 点(pts)
171
+ this.trends = pl.trends.map(function(o, ti){
172
+ var t = o.t, a, b, r = null, xa, xb;
173
+ var ya, yb;
174
+ if (t.pts){
175
+ if (t.pts.length !== 2 || !t.pts.every(function(q){ return Array.isArray(q) && q.length === 2 && q.every(isFinite); }))
176
+ throw new Error("trend.pts: write two points [[x0, y0], [x1, y1]]");
177
+ xa = +t.pts[0][0]; xb = +t.pts[1][0]; ya = +t.pts[0][1]; yb = +t.pts[1][1];
178
+ if (xa === xb && ya === yb) throw new Error("trend.pts: the two points are the same (write two different points)");
179
+ // 書いた 2 点をそのまま端にする(縦の線なら傾きと切片はない)
180
+ if (xb !== xa){ a = (yb - ya) / (xb - xa); b = ya - a * xa; } else { a = null; b = null; }
181
+ } else {
182
+ if (t.fit !== undefined && t.fit !== "linear") throw new Error('trend: "' + t.fit + '" is not "linear" (write "linear", {"fit": "linear"} or {"pts": [[x0, y0], [x1, y1]]})');
183
+ var use = t.series === undefined ? pl.series : [].concat(t.series).map(function(i){ return pl.series[i]; }).filter(Boolean);
184
+ var q = [].concat.apply([], use.map(function(s){ return s.pts; }));
185
+ if (q.length < 2) throw new Error("trend: a linear fit needs two or more points");
186
+ var n = q.length, sx = 0, sy = 0;
187
+ q.forEach(function(v){ sx += v.x; sy += v.y; });
188
+ var mx = sx / n, my = sy / n, sxx = 0, sxy = 0, syy = 0;
189
+ q.forEach(function(v){ sxx += (v.x - mx) * (v.x - mx); sxy += (v.x - mx) * (v.y - my); syy += (v.y - my) * (v.y - my); });
190
+ a = sxx ? sxy / sxx : 0; b = my - a * mx;
191
+ r = sxx && syy ? sxy / Math.sqrt(sxx * syy) : 0;
192
+ xa = Math.min.apply(null, q.map(function(v){ return v.x; })); xb = Math.max.apply(null, q.map(function(v){ return v.x; }));
193
+ ya = a * xa + b; yb = a * xb + b;
194
+ }
195
+ var col = t.tone ? colorOf(t.tone, 0) : "var(--fg)";
196
+ var A = [p.x(xa), p.y(ya)], B = [p.x(xb), p.y(yb)], out = false;
197
+ // 図の枠の中に切る(Liang–Barsky。clip-path は使わない)
198
+ var u0 = 0, u1 = 1, dx = B[0] - A[0], dy = B[1] - A[1];
199
+ [[-dx, A[0] - x0], [dx, x1 - A[0]], [-dy, A[1] - y0], [dy, y1 - A[1]]].forEach(function(c){
200
+ if (c[0] === 0){ if (c[1] < 0) u1 = -1; return; }
201
+ var u = c[1] / c[0];
202
+ if (c[0] < 0) u0 = Math.max(u0, u); else u1 = Math.min(u1, u);
203
+ });
204
+ // 枠の外の線は描かない(名前も図の上に出さない)
205
+ if (u1 <= u0){ out = true; ctx.report("range", "[scatter] the trend line is outside the axes (it is not drawn)"); }
206
+ else { B = [A[0] + dx * u1, A[1] + dy * u1]; A = [A[0] + dx * u0, A[1] + dy * u0]; }
207
+ var line = D.el("path", {"data-part-line": "", d: "M0,0", fill: "none", stroke: col, "stroke-width": 3.5, "stroke-linecap": "round", opacity: 0},
208
+ D.el("g", {"data-part": "edge", "data-part-id": "trend" + (ti + 1), "data-part-from": "@trend", "data-part-to": "@trend"}, gT));
209
+ if (t.dash) line.setAttribute("stroke-dasharray", "12 9");
210
+ // 名前:{r} {a} {b} を相関係数・傾き・切片に置き換える(digits 桁、既定 2)
211
+ var dg = t.digits !== undefined ? t.digits : 2, num = function(v){ return v === null ? "" : (v < 0 ? "−" : "") + Math.abs(v).toFixed(dg); };
212
+ var text = String(t.label || "").replace(/\{r\}/g, num(r)).replace(/\{a\}/g, num(a)).replace(/\{b\}/g, num(b));
213
+ var len = Math.hypot(B[0] - A[0], B[1] - A[1]);
214
+ return {o: o, line: line, text: out ? "" : text, col: col, A: A, B: B, len: len, dash: !!t.dash, out: out, a: a};
215
+ });
216
+ // 系列と傾向の線の名前:図の上(右寄せ)に印と一緒に並べる(凡例の箱は作らない。点や線と重ならない)
217
+ var lx = x1, entries = this.series.filter(function(se){ return se.o.s.label; }).map(function(se){ return {it: se, text: se.o.s.label, col: se.col, path: se.path}; })
218
+ .concat(this.trends.filter(function(tr){ return tr.text; }).map(function(tr){ return {it: tr, text: tr.text, col: tr.col, line: true, dash: tr.dash}; }));
219
+ // 印を左、字をその右に置く(字の幅は見積もりなので、ずれは右端に出る)
220
+ entries.reverse().forEach(function(en){
221
+ var w = est(en.text, 24), sw = en.line ? 40 : 2 * R, sx = lx - w - 10 - sw;
222
+ var g = D.el("g", {opacity: 0}, gL);
223
+ if (en.line){
224
+ var ln = D.el("line", {x1: sx, x2: sx + sw, y1: 26, y2: 26, stroke: en.col, "stroke-width": 3.5, "stroke-linecap": "round"}, g);
225
+ if (en.dash) ln.setAttribute("stroke-dasharray", "10 7");
226
+ } else D.el("path", {d: en.path, fill: en.col, "fill-opacity": 0.85, transform: "translate(" + (sx + R).toFixed(1) + " 26)"}, g);
227
+ D.mtext(g, sx + sw + 10, 34, en.text, {"font-size": 24, "font-weight": 700, fill: en.col});
228
+ en.it.leg = g;
229
+ lx = sx - 32;
230
+ });
231
+ if (lx + 32 < 0) ctx.report("size", "[scatter] the names above the figure are wider than the figure");
232
+ // 読み上げ:最後の形(描いた点と傾向の線)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
233
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
234
+ this.setAttribute("role", "img");
235
+ if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
236
+ function tickStep(span){ var r = span / 5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
237
+ return (x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e; }
238
+ }
239
+ // 最後の形を 1 文で(読み上げの名前):「散布図(横:最高気温、縦:売上):12 点(晴れ 8 点、雨 4 点)、横 24〜34、縦 210〜690、
240
+ // 猛暑日 (34, 690)、傾向の線は右上がり(r = 0.93)」。範囲の外で描かない点は数えない
241
+ summary(ja){
242
+ var P = this.props, self = this, one = function(s){ return String(s || "").replace(/\s*\n\s*/g, " ").replace(/[*_^]/g, ""); };
243
+ var ax = [P.xl ? (ja ? "横:" : "x: ") + one(P.xl) : "", P.yl ? (ja ? "縦:" : "y: ") + one(P.yl) : ""].filter(Boolean).join(ja ? "、" : ", ");
244
+ var pts = [], ss = this.series.map(function(se){ se.marks.forEach(function(mk){ pts.push(mk.q); }); return {l: se.o.s.label, n: se.marks.length}; });
245
+ var cnt = function(n){ return ja ? n + " 点" : n + (n === 1 ? " point" : " points"); };
246
+ var out = [cnt(pts.length) + (ss.length > 1 && ss.some(function(x){ return x.l; }) ? (ja ? "(" : " (") + ss.map(function(x){ return (x.l ? one(x.l) + " " : "") + cnt(x.n); }).join(ja ? "、" : ", ") + (ja ? ")" : ")") : "")];
247
+ if (pts.length){
248
+ var mm = function(f){ var v = pts.map(f), lo = Math.min.apply(null, v), hi = Math.max.apply(null, v); return lo === hi ? String(lo) : lo + (ja ? "〜" : " to ") + hi; };
249
+ out.push((ja ? "横 " : "x ") + mm(function(q){ return q.x; }), (ja ? "縦 " : "y ") + mm(function(q){ return q.y; }));
250
+ }
251
+ pts.filter(function(q){ return q.label; }).slice(0, 6).forEach(function(q){ out.push(one(q.label) + " (" + q.x + ", " + q.y + ")"); });
252
+ this.trends.forEach(function(tr){
253
+ if (tr.out) return;
254
+ var dir = tr.a === null ? (ja ? "垂直" : "vertical") : tr.a > 0 ? (ja ? "右上がり" : "rising") : tr.a < 0 ? (ja ? "右下がり" : "falling") : (ja ? "水平" : "flat");
255
+ var ts = tr.o.t.series, sn = !tr.o.t.pts && ts !== undefined && [].concat(ts).length === 1 && self.series[[].concat(ts)[0]] ? self.series[[].concat(ts)[0]].o.s.label : "";
256
+ out.push((sn ? one(sn) + (ja ? "の" : ": ") : "") + (ja ? "傾向の線は" : "the trend line is ") + dir + (tr.text ? (ja ? "(" : " (") + one(tr.text) + (ja ? ")" : ")") : ""));
257
+ });
258
+ return (ja ? "散布図" : "Scatter plot") + (ax ? (ja ? "(" + ax + ")" : " (" + ax + ")") : "") + (ja ? ":" : ": ") + out.join(ja ? "、" : ", ");
259
+ }
260
+ duration(k){
261
+ var P = this.props, d = 0, pl = this.plan();
262
+ pl.series.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + P.dur); });
263
+ pl.trends.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + P.dur); });
264
+ return d;
265
+ }
266
+ cues(k){
267
+ var c = [], pl = this.plan();
268
+ pl.series.concat(pl.trends).forEach(function(o){ if (o.step === k && o.at > 0 && c.indexOf(o.at) < 0) c.push(o.at); });
269
+ return c.length ? c.sort(function(a, b){ return a - b; }) : null;
270
+ }
271
+ render(k, t, ctx){
272
+ var P = this.props, D = base, vr = this.variant, dur = P.dur, lecture = !!ctx.preview, FAINT = 0.45;
273
+ if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
274
+ // この部品の段階の中の時刻(-1 = まだ。授業の表示では先の段階を薄く見せる)
275
+ var local = function(o){ return o.step < k ? Infinity : o.step > k ? -1 : t - o.at; };
276
+ var faint = function(o){ return lecture && o.step > k; };
277
+ this.series.forEach(function(se){
278
+ var o = se.o, tt = local(o), f = faint(o), span = dur * 0.7;
279
+ se.marks.forEach(function(mk){
280
+ var op, sc = 1;
281
+ if (f){ op = FAINT; }
282
+ else if (tt < 0){ op = 0; }
283
+ else if (vr === "sweep"){ op = D.prog(tt, mk.rank * (span - 0.2), 0.2); }
284
+ else if (vr === "grow"){ sc = D.prog(tt, 0, span); op = sc > 0 ? Math.min(1, sc * 3) : 0; }
285
+ else { op = D.prog(tt, 0, span); }
286
+ mk.g.setAttribute("opacity", op.toFixed(3));
287
+ mk.g.setAttribute("transform", "translate(" + mk.cx.toFixed(1) + " " + mk.cy.toFixed(1) + ")" + (sc < 1 ? " scale(" + Math.max(0.001, sc).toFixed(4) + ")" : ""));
288
+ });
289
+ var lo = f ? FAINT : tt < 0 ? 0 : D.prog(tt, dur * 0.6, dur * 0.4);
290
+ se.labels.forEach(function(l){ l.setAttribute("opacity", lo.toFixed(3)); });
291
+ if (se.leg) se.leg.setAttribute("opacity", (f ? FAINT : tt < 0 ? 0 : D.prog(tt, 0, dur * 0.5)).toFixed(3));
292
+ });
293
+ this.trends.forEach(function(tr){
294
+ var o = tr.o, tt = local(o), f = faint(o), span = dur * 0.7, A = tr.A, B = tr.B, e = f ? 1 : tt < 0 ? 0 : D.prog(tt, 0, span);
295
+ var s0 = 0, s1 = 1, op = e > 0 ? 1 : 0;
296
+ if (!f && vr === "sweep"){ s1 = e; }
297
+ else if (!f && vr === "grow"){ s0 = 0.5 - e / 2; s1 = 0.5 + e / 2; }
298
+ else op = e;
299
+ tr.line.setAttribute("d", "M" + D.lerp(A[0], B[0], s0).toFixed(1) + "," + D.lerp(A[1], B[1], s0).toFixed(1) + "L" + D.lerp(A[0], B[0], s1).toFixed(1) + "," + D.lerp(A[1], B[1], s1).toFixed(1));
300
+ if (tr.dash) tr.line.setAttribute("stroke-dashoffset", (s0 * tr.len).toFixed(1));
301
+ tr.line.setAttribute("opacity", (tr.out ? 0 : f ? FAINT : op).toFixed(3));
302
+ if (tr.leg) tr.leg.setAttribute("opacity", (f ? FAINT : tt < 0 ? 0 : D.prog(tt, span, dur * 0.3)).toFixed(3));
303
+ });
304
+ }
305
+ };
306
+ });
@@ -0,0 +1,38 @@
1
+ ---
2
+ summary: Code notes
3
+ steps: Code → notes → output (n+1/+2)
4
+ props:
5
+ dur: Seconds
6
+ size: Text px
7
+ outputPos: Output
8
+ example: {"lang":"python","code":"import pandas as pd\ndf = pd.read_csv(\"sales.csv\")\ndf.groupby(\"store\")[\"sales\"].mean()","steps":[{"lines":[1],"note":"Load pandas"},{"lines":[2],"note":"Read CSV"},{"lines":[3],"note":"Mean"}],"output":"store\nA 120.5\nB 98.0"}
9
+ ---
10
+
11
+ `<m-code>` child JSON.
12
+
13
+ - `code`: 440px shows 9 lines of 76 chars; longer lines wrap, more scroll in a window (≤16; else split).
14
+ - `lang` (colours for python, r, shell, js only); `steps[{lines,note}]`: `[3]`, range `[3,4]`, or 3+ lines `[2,5,9]`; notes ≤30 chars.
15
+ - `output`: ≤8 lines.
16
+
17
+ Script: explain each line; never read code aloud.
18
+
19
+ <!-- llm: omit -->
20
+ Displays supplied text; never runs code. Code first, then highlights and notes. Beside: natural code width ≤55% and every note fits; earlier notes stay muted, all shown at completion. Otherwise band: only the current note, prefixed “lines 3–4”. Final/print: numbered compact list, no code highlight. If the list needs more height, report and keep the last numbered note. Deterministic seeking. Fit layout (2.2.0), only when the 2.1.0 layout would not fit (same pixels otherwise): band notes up to 2 rows; long lines wrap after a space, comma or opening bracket under a "↪" gutter; a window per step centred on its lines, "⋮ n" for hidden rows (it changes in the step's first half, then shows in the second); a final list that does not fit keeps the last note with `data-fit="last-note"` (no report); a window under 3 rows reports size. Full source and output in `pre[data-readable]`. Preview uses --preview-opacity; the final list previews before notes begin.
21
+
22
+ dur .6s; size 0=24px code/26px notes, otherwise ≥24. outputPos auto/below/right. Beside auto: right for ≤8 lines when columns fit. Band auto: right when natural code width ≤70% and output fits, else below the band. Explicit right/below retained. Bad props report/default.
23
+
24
+ Colours are theme roles: for Python, R, shell and JavaScript (js), keywords term, strings accent2 (Python triple quotes and JS templates span lines), # (JS //) comments outside strings muted, the rest fg; other languages stay fg. Code reads the same without colour. `[[3,4]]` reads as `[3,4]`; two ranges in one step report range. Tabs: four spaces. Monospace width .6em, wide characters 1em. Full-width band mode at 1184px/24px fits 77 ASCII characters with single-digit line numbers, 76 with two digits. Beside notes/right output reduce this. Beside notes wrap/stack with connectors; each band note is one truncated row.
25
+
26
+ Default height, one band row, right/no output: header 50 + n × row 34 + padding 16 + gap 8 + band 58 = **132 + 34n px**. General: r=ceil(1.4×size), header=r+16, b=ceil(1.45×note px+4)+16; H=header+n×r+16+8+b. No notes: omit 8+b. Below output adds 16+header+output rows×r+16. Final list (24px, 35px rows) packs “3–4: note” items; each row beyond one adds 35px. Auto output that would go below sits beside the band when its natural width ≤45%; the zone is then max(band, output). Every “give the element about H px” uses this formula; above 440px (body under a heading) reports give lines that fit at 440px and say fewer lines/shorter notes/split instead. If only the list misses, all code stays and the final state keeps the last note.
27
+
28
+ | Height | Code lines (one band row) |
29
+ |---|---|
30
+ | 380px | 7 (needs 370px) |
31
+ | 440px | 9 (438px) |
32
+ | 540px | 12 (540px) |
33
+ | 680px | 16 (676px) |
34
+
35
+ A 59-character line exceeds 70% width: auto output goes below. Seven lines + band + one output row need 486px; two output rows need 520px. Without output, 380px fits. Separate layout reports give line count/capacity/needed height, longest line/character capacity, or note index/width/capacity/target length. Oversize text truncates with …; tiny elements retain clipped content and numeric size reports. Code ≤16 lines, output ≤8. Invalid ranges report; no highlight/connector, notes/steps preserved.
36
+
37
+ ctx.lang ja/en. Figure role; author label preserved; SVG hidden. Full source/output in non-focusable sr-only pre. All notes remain in the accessible summary. Fictional sales data.
38
+ <!-- llm: end -->