egatari 0.6.11 → 0.6.12-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 (134) hide show
  1. package/bin/egatari.mjs +4 -3
  2. package/components.lock.json +30 -15
  3. package/components2.lock.json +201 -1
  4. package/fonts/@fontsource/fraunces/400.css +29 -0
  5. package/fonts/@fontsource/fraunces/700.css +29 -0
  6. package/fonts/@fontsource/fraunces/LICENSE +93 -0
  7. package/fonts/@fontsource/fraunces/files/fraunces-latin-400-normal.woff2 +0 -0
  8. package/fonts/@fontsource/fraunces/files/fraunces-latin-700-normal.woff2 +0 -0
  9. package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-400-normal.woff2 +0 -0
  10. package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-700-normal.woff2 +0 -0
  11. package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-400-normal.woff2 +0 -0
  12. package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-700-normal.woff2 +0 -0
  13. package/fonts/@fontsource/fraunces/package.json +6 -0
  14. package/kit/check-messages.mjs +18 -7
  15. package/kit/check.mjs +12 -4
  16. package/kit/core/article-render.mjs +5 -5
  17. package/kit/core/build-core.mjs +25 -9
  18. package/kit/core/check-parity.mjs +1 -1
  19. package/kit/core/check-rules.mjs +2 -2
  20. package/kit/core/check-source.mjs +3 -0
  21. package/kit/core/colab-core.mjs +1 -1
  22. package/kit/core/kicker.mjs +42 -0
  23. package/kit/core/layout-scan.mjs +19 -7
  24. package/kit/core/llm-pack-data.mjs +8 -8
  25. package/kit/core/llm-pack.mjs +2 -2
  26. package/kit/core/theme-shapes.mjs +3 -1
  27. package/kit/core/themes-list.mjs +2 -0
  28. package/kit/instruction-version.json +1 -1
  29. package/kit/layouts.css +8 -0
  30. package/kit/player.json +1 -1
  31. package/kit/player.lock.json +2 -2
  32. package/package.json +2 -1
  33. package/themes/asagi/theme.json +1 -1
  34. package/themes/asagi/tokens.css +6 -0
  35. package/themes/bengara/theme.json +13 -0
  36. package/themes/bengara/tokens.css +66 -0
  37. package/themes/business/theme.json +1 -1
  38. package/themes/business/tokens.css +6 -0
  39. package/themes/default/theme.json +1 -1
  40. package/themes/default/tokens.css +9 -0
  41. package/themes/kogecha/theme.json +1 -1
  42. package/themes/kogecha/tokens.css +6 -0
  43. package/themes/kokugo/theme.json +1 -1
  44. package/themes/kokugo/tokens.css +6 -0
  45. package/themes/murasaki/theme.json +1 -1
  46. package/themes/murasaki/tokens.css +6 -0
  47. package/themes/sumi/theme.json +1 -1
  48. package/themes/sumi/tokens.css +8 -0
  49. package/themes/tokiwa/theme.json +1 -1
  50. package/themes/tokiwa/tokens.css +6 -0
  51. package/themes.lock.json +90 -24
  52. package/vendor/components/CATALOG.md +11 -11
  53. package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/README.en.md +38 -0
  54. package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/index.js +289 -0
  55. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ABCJS-ADAPTER.md +101 -0
  56. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/LICENSE-abcjs.txt +21 -0
  57. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/chords.json +89 -0
  58. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/doremi.json +261 -0
  59. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/extras.json +192 -0
  60. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/kaeru.json +521 -0
  61. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/rhythm.json +248 -0
  62. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ties.json +360 -0
  63. package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/index.js +508 -0
  64. package/vendor/components/sha256/0dc2a0945e7a4004278fcc9b8f02223bbb87f6269bffe3dd3ebeb3a78ce23d34/index.js +404 -0
  65. package/vendor/components/sha256/0e2e45b024bb2f37e82c83a4d9cd9f9c16b5dc4924dde81735c268a3d49f9d7f/index.js +97 -0
  66. package/vendor/components/sha256/0ef62e33d330f8e31ccb1f480b5e3b349769a142cc2737a9e6583d5eff9f56ca/index.js +919 -0
  67. package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/README.en.md +48 -0
  68. package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/index.js +384 -0
  69. package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/README.en.md +34 -0
  70. package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/index.js +244 -0
  71. package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/README.en.md +44 -0
  72. package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/index.js +304 -0
  73. package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/README.en.md +44 -0
  74. package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/index.js +203 -0
  75. package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/README.en.md +37 -0
  76. package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/index.js +438 -0
  77. package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/README.en.md +24 -0
  78. package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/index.js +103 -0
  79. package/vendor/components/sha256/48a776e7683e1aba8cad5aa4067914c017681efaa74f175066e0ab081bf3d013/index.js +351 -0
  80. package/vendor/components/sha256/4a9331635c2dd28e4b46108eaffe49c6d29cf626ecb900ac6e9029552be0cf49/index.js +607 -0
  81. package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/README.en.md +23 -0
  82. package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/index.js +120 -0
  83. package/vendor/components/sha256/586063d3a4e24e2995923811b2b9466bde86dbaafb3bcf103546d3f28159205a/index.js +812 -0
  84. package/vendor/components/sha256/5acc5f87e29f1170bc35dbee08087d0d03c1023969c6c1b1367a0f559d60e5ee/index.js +198 -0
  85. package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/README.en.md +32 -0
  86. package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/index.js +222 -0
  87. package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/README.en.md +50 -0
  88. package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/index.js +171 -0
  89. package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/README.en.md +51 -0
  90. package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/index.js +228 -0
  91. package/vendor/components/sha256/6364043cb31bbd86aacb7432af1a8affef8cae5c6efdbe13fbebd116fd51b91f/index.js +233 -0
  92. package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/README.en.md +66 -0
  93. package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/index.js +920 -0
  94. package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/README.en.md +35 -0
  95. package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/index.js +179 -0
  96. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/LICENSE-tabler.txt +21 -0
  97. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/index.js +4868 -0
  98. package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/names.txt +4808 -0
  99. package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/README.en.md +40 -0
  100. package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/index.js +348 -0
  101. package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/README.en.md +42 -0
  102. package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/index.js +268 -0
  103. package/vendor/components/sha256/8cb367c71c002c689defddc6f075be911d5485421715119b5515181e962a2401/index.js +121 -0
  104. package/vendor/components/sha256/97bfd6e79c7278c55153bf4c2330da0432cf0ee312baa11650e07cdd7912831d/index.js +354 -0
  105. package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/README.en.md +40 -0
  106. package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/index.js +348 -0
  107. package/vendor/components/sha256/c108119117042cacc65a35ec73fcab95a2a92b2a2797129f66e326783f8db178/index.js +465 -0
  108. package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/README.en.md +23 -0
  109. package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/index.js +289 -0
  110. package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/README.en.md +31 -0
  111. package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/index.js +236 -0
  112. package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/README.en.md +42 -0
  113. package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/index.js +488 -0
  114. package/vendor/components/sha256/d998b5db828427505e39cdae67676dc6480c791d6037152dec222ae81cdbba1f/index.js +484 -0
  115. package/vendor/components/sha256/ea17602aaecca64b672b3bc827965ff378cb460250177f7b66f73081a48d4e81/index.js +278 -0
  116. package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/README.en.md +22 -0
  117. package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/index.js +145 -0
  118. package/vendor/components-2/manifest-2.8.0.json +2199 -0
  119. package/vendor/themes/asagi/1.2.0/theme.json +14 -0
  120. package/vendor/themes/asagi/1.2.0/tokens.css +30 -0
  121. package/vendor/themes/business/1.2.0/theme.json +5 -0
  122. package/vendor/themes/business/1.2.0/tokens.css +41 -0
  123. package/vendor/themes/default/1.4.0/theme.json +4 -0
  124. package/vendor/themes/default/1.4.0/tokens.css +86 -0
  125. package/vendor/themes/kogecha/1.2.0/theme.json +10 -0
  126. package/vendor/themes/kogecha/1.2.0/tokens.css +29 -0
  127. package/vendor/themes/kokugo/1.2.0/theme.json +5 -0
  128. package/vendor/themes/kokugo/1.2.0/tokens.css +25 -0
  129. package/vendor/themes/murasaki/1.2.0/theme.json +10 -0
  130. package/vendor/themes/murasaki/1.2.0/tokens.css +25 -0
  131. package/vendor/themes/sumi/1.2.0/theme.json +10 -0
  132. package/vendor/themes/sumi/1.2.0/tokens.css +49 -0
  133. package/vendor/themes/tokiwa/1.2.0/theme.json +10 -0
  134. package/vendor/themes/tokiwa/1.2.0/tokens.css +27 -0
@@ -0,0 +1,120 @@
1
+ // m-balance: expectation is the zero-moment position of probability weights.
2
+ egatariParts.define({name: "balance", version: "2.0.1", requires: {base: "1.2.0", plot: "1.1.2"}, element: "m-balance"}, function(deps){
3
+ "use strict";
4
+ var base = deps.base;
5
+ var TEXT = {
6
+ ja: {title: "期待値はつり合いの位置", probability: "確率", sum: "確率の合計", expectation: "期待値"},
7
+ en: {title: "Expectation is the balance point", probability: "probability", sum: "probability total", expectation: "expectation"}
8
+ };
9
+ function set(e, a, v){ e.setAttribute(a, String(v)); }
10
+ function ticks(lo, hi){
11
+ var rough = (hi - lo) / 5, power = Math.pow(10, Math.floor(Math.log10(rough))), f = rough / power;
12
+ var step = (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power, out = [];
13
+ for (var i = Math.ceil(lo / step); out.length < 10 && i * step <= hi + step * 1e-9; i++) out.push(+(i * step).toPrecision(12));
14
+ return out;
15
+ }
16
+ function num(v){ return String(+v.toPrecision(6)); }
17
+ return class extends base.MotionElement {
18
+ static partName = "balance";
19
+ static preview = "none";
20
+ static steps = 3;
21
+ static shape = {schema: {type: "object", additionalProperties: false, required: ["values", "probs"], properties: {
22
+ values: {type: "array", minItems: 2, maxItems: 12, items: {type: "number"}},
23
+ probs: {type: "array", minItems: 2, maxItems: 12, items: {type: "number"}}, name: {type: "string"}
24
+ }}, example: {values: [0, 1, 2, 3], probs: [0.1, 0.3, 0.4, 0.2], name: "X"}};
25
+ static props = {
26
+ dur: {type: "number", default: 1.5, doc: "ステップの秒数"},
27
+ digits: {type: "number", default: 2, doc: "期待値の小数桁"},
28
+ size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
29
+ };
30
+ duration(k){ return k >= 1 && k <= 3 ? this.props.dur : 0; }
31
+ label(g, x, y, s, anchor){
32
+ var e = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
33
+ e.textContent = s; return e;
34
+ }
35
+ mount(ctx){
36
+ var self = this, d = this.data, P = this.props;
37
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
38
+ if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[balance] dur must be positive; using 1.5"); P.dur = 1.5; }
39
+ if (!Number.isInteger(P.digits) || P.digits < 0 || P.digits > 10){ ctx.report("attr", "[balance] digits must be an integer 0–10; using 2"); P.digits = 2; }
40
+ if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[balance] size must be 0 or at least 24; using 26"); P.size = 0; }
41
+ this.fs = P.size || 26;
42
+ this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb"; this.setAttribute("role", "img");
43
+ if (d.values.length !== d.probs.length || new Set(d.values).size !== d.values.length){ ctx.report("data", "[balance] values must be distinct and probs must have the same length"); return; }
44
+ var total = d.probs.reduce(function(s, p){ return s + p; }, 0);
45
+ if (Math.abs(total - 1) > 1e-9) ctx.report("data", "[balance] probs must sum to 1 (±1e-9); drawing supplied weights, total " + total);
46
+ if (d.probs.some(function(p){ return p < 0 || p > 1; })){ ctx.report("data", "[balance] probabilities must be between 0 and 1"); return; }
47
+ // Scale before sums and coordinate differences to keep finite extreme values usable.
48
+ var scale = Math.pow(10, Math.floor(Math.log10(Math.max(1, ...d.values.map(Math.abs))))), vals = d.values.map(function(v){ return v / scale; });
49
+ var expectedN = vals.reduce(function(s, v, i){ return s + v * d.probs[i]; }, 0), expected = expectedN * scale;
50
+ if (!Number.isFinite(expected)){ ctx.report("data", "[balance] expectation exceeds the numerical range; rescale values"); return; }
51
+ var lo = Math.min(...vals, expectedN), hi = Math.max(...vals, expectedN), span = hi - lo;
52
+ if (!(span > 0)){ ctx.report("data", "[balance] values are too close to represent; rescale values"); return; }
53
+ var name = d.name === undefined ? "X" : d.name, answer = String(+expected.toFixed(P.digits));
54
+ var expectation = "E[" + name + "] = " + answer;
55
+ var terms = d.values.map(function(v, i){ return (v < 0 ? "(" + num(v) + ")" : num(v)) + "×" + num(d.probs[i]); });
56
+ var formula = terms.slice(0, 6).join(" + ") + (terms.length > 6 ? " + …" : "") + " = " + answer;
57
+ this.model = {values: d.values.slice(), probs: d.probs.slice(), total: total, expected: expected, expectedN: expectedN, scale: scale, name: name, formula: formula, lo: lo, hi: hi};
58
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", this.T.title + "; " + d.values.map(function(v, i){ return num(v) + ": " + self.T.probability + " " + num(d.probs[i]); }).join("; ") + "; " + this.T.sum + " " + num(total) + "; " + this.T.expectation + " " + expectation + "; " + formula);
59
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = this.fs, line = fs * 1.45 + 4;
60
+ var width = function(s){ return base.textWidth(s, fs, {font: self}); };
61
+ var pad = Math.max(56, ...d.values.map(function(v){ return width(num(v)) / 2 + 16; }));
62
+ var axisY = H / 2, plot = deps.plot.Plot(this, {xr: [lo, hi], yr: [0, 1], xt: [], yt: [], noY: true, m: {l: pad, r: pad, t: 0, b: H - axisY}});
63
+ this.svg = plot.svg; set(this.svg, "width", W); set(this.svg, "height", H); set(this.svg, "aria-hidden", "true");
64
+ var axes = Array.from(this.svg.children).filter(function(e){ return e.getAttribute("class") === "axes"; })[0]; this.svg.removeChild(axes);
65
+ this.weightLayer = base.el("g", {opacity: 0}, this.svg);
66
+ this.beam = base.el("g", {}, this.weightLayer);
67
+ base.el("line", {x1: pad, x2: W - pad, y1: axisY, y2: axisY, stroke: "var(--muted)", "stroke-width": 4}, this.beam);
68
+ var plotWidth = Math.max(1, W - 2 * pad), maxRise = plotWidth * Math.sin(8 * Math.PI / 180) / 4;
69
+ var barH = Math.max(20, axisY - 1.45 * fs - maxRise - 24), maxP = Math.max(1e-12, ...d.probs);
70
+ var positions = vals.map(plot.x), sorted = positions.slice().sort(function(a, b){ return a - b; });
71
+ var minGap = Math.min(...sorted.slice(1).map(function(x, i){ return x - sorted[i]; })), bw = Math.max(2, Math.min(44, minGap - 12));
72
+ var small = W < 2 * pad + 40 || axisY - barH - 1.1 * fs - maxRise < 0 || axisY + plotWidth * Math.sin(8 * Math.PI / 180) + line + fs * 0.4 > H;
73
+ this.bars = d.values.map(function(v, i){
74
+ var h = d.probs[i] / maxP * barH, x = positions[i], s = num(d.probs[i]);
75
+ var bar = base.el("rect", {x: x - bw / 2, y: axisY - h, width: bw, height: h, fill: "var(--term)"}, self.beam);
76
+ var text = self.label(self.beam, x, axisY - h - fs * 0.4 - 8, s, "middle");
77
+ return {bar: bar, text: text, x: x, h: h, w: width(s)};
78
+ });
79
+ this.bars.forEach(function(a, i){ self.bars.slice(i + 1).forEach(function(b){
80
+ if (Math.abs(a.x - b.x) < (a.w + b.w) / 2 + 6 && Math.abs(a.h - b.h) < 1.45 * fs + 4) small = true;
81
+ // A neighbouring tall bar must not run through a probability label.
82
+ if (Math.abs(a.x - b.x) < a.w / 2 + bw / 2 + 4 && b.h > a.h + 4 || Math.abs(a.x - b.x) < b.w / 2 + bw / 2 + 4 && a.h > b.h + 4) small = true;
83
+ }); });
84
+ // Nice ticks in normalized coordinates; labels retain the original units.
85
+ this.ticks = ticks(lo, hi);
86
+ var lastRight = -Infinity;
87
+ this.ticks.forEach(function(v){
88
+ var x = plot.x(v), s = num(v * scale), w = width(s);
89
+ if (x - w / 2 < lastRight + 4 || x - w / 2 < 0 || x + w / 2 > W) small = true;
90
+ lastRight = x + w / 2;
91
+ base.el("line", {x1: x, x2: x, y1: axisY, y2: axisY + 6, stroke: "var(--muted)", "stroke-width": 2}, self.beam);
92
+ self.label(self.beam, x, axisY + line, s, "middle");
93
+ });
94
+ this.fulcrum = base.el("g", {opacity: 0}, this.svg);
95
+ base.el("path", {d: "M0," + (axisY + 2) + "l-18,26h36Z", fill: "var(--emph-tint)", stroke: "var(--emph)", "stroke-width": 3}, this.fulcrum);
96
+ this.finalLayer = base.el("g", {opacity: 0}, this.svg);
97
+ this.start = plot.x(Math.min(...vals)); this.end = plot.x(expectedN); this.axisY = axisY;
98
+ var ew = width(expectation), labelX = Math.max(ew / 2 + 4, Math.min(W - ew / 2 - 4, this.end));
99
+ var labelY = axisY + 2 * line + 14, formulaY = H - fs * 0.4 - 4;
100
+ this.label(this.finalLayer, labelX, labelY, expectation, "middle");
101
+ // The sum has numeric terms only; variable names above are literal text.
102
+ this.formulaText = base.mtext(this.finalLayer, W / 2, formulaY, formula, {"font-size": fs, "text-anchor": "middle", fill: "var(--fg)"});
103
+ if (ew > W - 8 || width(formula) > W - 8 || formulaY - labelY < line || labelY + fs * 0.4 > H) small = true;
104
+ if (small) ctx.report("size", "[balance] weights, ticks, tilt or formula do not fit; enlarge the element or separate close values");
105
+ }
106
+ render(k, t){
107
+ if (!this.model) return;
108
+ var dur = this.props.dur, e = k > 2 ? 1 : k < 2 ? 0 : base.prog(t, 0, dur);
109
+ var pivot = base.lerp(this.start, this.end, e), m = this.model;
110
+ var pivotN = base.lerp(Math.min(...m.values.map(function(v){ return v / m.scale; })), m.expectedN, e);
111
+ // Positive moment means a heavier right side (clockwise in SVG). At E, the beam levels.
112
+ var moment = m.values.reduce(function(s, v, i){ return s + (v / m.scale - pivotN) * m.probs[i]; }, 0);
113
+ var angle = k >= 2 && e < 1 ? Math.max(-8, Math.min(8, 8 * moment / (m.hi - m.lo))) : 0;
114
+ set(this.weightLayer, "opacity", k > 1 ? 1 : k < 1 ? 0 : base.prog(t, 0, dur));
115
+ set(this.beam, "transform", "rotate(" + angle + " " + pivot + " " + this.axisY + ")");
116
+ set(this.fulcrum, "opacity", k >= 1 ? 1 : 0); set(this.fulcrum, "transform", "translate(" + pivot + " 0)");
117
+ set(this.finalLayer, "opacity", k > 3 ? 1 : k < 3 ? 0 : base.prog(t, 0, dur));
118
+ }
119
+ };
120
+ });