egatari 0.6.16 → 0.6.18

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 (137) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.ja.md +14 -13
  3. package/README.md +2 -1
  4. package/components.lock.json +119 -45
  5. package/components2.lock.json +639 -1
  6. package/kit/check-messages.mjs +5 -0
  7. package/kit/check.mjs +6 -0
  8. package/kit/core/bookmark.mjs +28 -0
  9. package/kit/core/build-core.mjs +4 -2
  10. package/kit/core/check-parity.mjs +4 -0
  11. package/kit/core/check-rules.mjs +3 -2
  12. package/kit/core/check-source.mjs +6 -0
  13. package/kit/core/llm-pack-assemble.mjs +37 -66
  14. package/kit/core/llm-pack-data.mjs +839 -45
  15. package/kit/core/llm-pack.mjs +6 -4
  16. package/kit/core/llm-request.mjs +2 -2
  17. package/kit/core/new-deck-pack.mjs +38 -44
  18. package/kit/core/new-deck.mjs +82 -74
  19. package/kit/core/part-labels.mjs +2 -0
  20. package/kit/core/purposes.mjs +9 -3
  21. package/kit/core/sample-info.mjs +17 -3
  22. package/kit/core/slide-ops.mjs +22 -0
  23. package/kit/core/tate-mix.mjs +25 -0
  24. package/kit/core/theme-derive.mjs +56 -17
  25. package/kit/core/theme-shapes.mjs +15 -1
  26. package/kit/deck.js +53 -2
  27. package/kit/instruction-version.json +1 -1
  28. package/kit/llm-pack.mjs +5 -7
  29. package/kit/player.json +1 -1
  30. package/kit/player.lock.json +2 -2
  31. package/kit/presenter.js +36 -4
  32. package/kit/tools.js +54 -2
  33. package/package.json +1 -1
  34. package/vendor/components/CATALOG.md +24 -22
  35. package/vendor/components/sha256/038f9d32c89c8212ab25d6e3180023b6fe024a53053ab2ef1443ecab92e3ce43/index.js +205 -0
  36. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/README.en.md +44 -0
  37. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/index.js +306 -0
  38. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/README.en.md +54 -0
  39. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/index.js +470 -0
  40. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/README.en.md +23 -0
  41. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/index.js +289 -0
  42. package/vendor/components/sha256/0c25d49d23529879054737aa181951519fe585c4728fd505e0e3c8869953eac7/index.js +934 -0
  43. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/LICENSE-strokesvg.txt +115 -0
  44. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/OFL.txt +93 -0
  45. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/index.js +755 -0
  46. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/strokes-CHANGES.md +20 -0
  47. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/README.en.md +25 -0
  48. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/index.js +317 -0
  49. package/vendor/components/sha256/12ef6a11055407f5cddc40154a49cf2737b0786429fe0fcc94ee1d8245597b40/index.js +244 -0
  50. package/vendor/components/sha256/13c9ce43396b2f5693ce430a924dae4ddcd1e8a4ad0c9b9e724ff52acb874d0c/index.js +354 -0
  51. package/vendor/components/sha256/1a0f21def0efbbdef64461cafa40f3883bc7f7122adf79d01f09ca4a245e5dcb/index.js +465 -0
  52. package/vendor/components/sha256/208175d05b37d326855fad792b10137f785e5d05d91a2cde119d0dbd69d2ed98/index.js +100 -0
  53. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/README.en.md +34 -0
  54. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/index.js +246 -0
  55. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/README.en.md +24 -0
  56. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/index.js +554 -0
  57. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/README.en.md +28 -0
  58. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/index.js +214 -0
  59. package/vendor/components/sha256/2a011338d0fc3c77e102eaa57cde2b6e3726bc279f133174b0b8c9a654263cbc/index.js +824 -0
  60. package/vendor/components/sha256/2fce5ab0c31dca0aa1586a2c69237870a9cce46c0bc6ab7392c27968d016bd15/index.js +75 -0
  61. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/README.en.md +23 -0
  62. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/index.js +150 -0
  63. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/README.en.md +18 -0
  64. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/index.js +279 -0
  65. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/README.en.md +42 -0
  66. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/index.js +272 -0
  67. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/README.en.md +30 -0
  68. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/index.js +305 -0
  69. package/vendor/components/sha256/4c8cae404d551a1bb021e8345af5aa45d4f412f13497aa84b142f11a29a365dc/index.js +124 -0
  70. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/README.en.md +23 -0
  71. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/index.js +120 -0
  72. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/README.en.md +18 -0
  73. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/index.js +243 -0
  74. package/vendor/components/sha256/631f4c4b90c9a41c0f26c9600d5cf2d6447251d04a20f08f48a85aeb4cb0f6fb/index.js +107 -0
  75. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/README.en.md +31 -0
  76. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/index.js +271 -0
  77. package/vendor/components/sha256/701f1deef79fe05eeb18e1119e5a5c4d60a9dfe265e93a4dff79223bc598dbf0/index.js +521 -0
  78. package/vendor/components/sha256/711cf58fa946c9c0abc953b2f695d02bf5a5a7f73851b09f834e894baf88be38/index.js +122 -0
  79. package/vendor/components/sha256/728576c57a5ccb39531ad4cb8074fce95480f01603a77dbf57dca0e52199f7c4/index.js +37 -0
  80. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/README.en.md +18 -0
  81. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/index.js +382 -0
  82. package/vendor/components/sha256/76bdb63c3e5e14fbb4816bc9f235490817bb5d7be990a826f5077aa08226702c/index.js +162 -0
  83. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/README.en.md +51 -0
  84. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/index.js +230 -0
  85. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/README.en.md +26 -0
  86. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/index.js +322 -0
  87. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/README.en.md +18 -0
  88. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/index.js +103 -0
  89. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ABCJS-ADAPTER.md +101 -0
  90. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/LICENSE-abcjs.txt +21 -0
  91. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/chords.json +89 -0
  92. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/doremi.json +261 -0
  93. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/extras.json +192 -0
  94. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/kaeru.json +521 -0
  95. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/rhythm.json +248 -0
  96. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ties.json +360 -0
  97. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/index.js +508 -0
  98. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/README.en.md +22 -0
  99. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/index.js +145 -0
  100. package/vendor/components/sha256/8a4b6dce84d7a69aaafeb75c1c572fe7904fd49e3169c1c85851ccaeae2a7b11/index.js +41 -0
  101. package/vendor/components/sha256/8bb511cb90902bc7721e59ca08685b26adbf33539e36a4a45172485d6d3d455b/index.js +250 -0
  102. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/README.en.md +21 -0
  103. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/index.js +108 -0
  104. package/vendor/components/sha256/8e5e90c90cb6b06a790b0420e43d79d7da663f1cc19ff06d381ec849b4a8fc57/index.js +312 -0
  105. package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
  106. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/README.en.md +38 -0
  107. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/index.js +414 -0
  108. package/vendor/components/sha256/aac2f8a23cb1b606e9635061cb288f006588c80a7258540cae846ae677f55ff5/index.js +238 -0
  109. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/README.en.md +45 -0
  110. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/index.js +211 -0
  111. package/vendor/components/sha256/aeb0b9b5991a5c1df7191c397780a699f2c7310123ca210a58486c0a23e44006/index.js +342 -0
  112. package/vendor/components/sha256/af3355efd6739a56c6cb53990100f41703361c475c123b9b2762421c68509036/index.js +315 -0
  113. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/LICENSE-tabler.txt +21 -0
  114. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/index.js +4868 -0
  115. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/names.txt +4808 -0
  116. package/vendor/components/sha256/b348ea64cc19632df96a91dfd7c435e4a62095aede72b504d03537be70d6d930/index.js +606 -0
  117. package/vendor/components/sha256/b53bfa03d1e9feb3cb492f440bf9d100c96eb4fe6b76c42b512a56e9158829cd/index.js +351 -0
  118. package/vendor/components/sha256/b9443e1cdac4850b1ead9f8449a3061678bbb77fbc53eb9b23d01e1cf50750c3/index.js +619 -0
  119. package/vendor/components/sha256/bc1e2a02c959ac203819d03c0d25b3776a6a9a4290aae860b26cbbe3d29e876d/index.js +268 -0
  120. package/vendor/components/sha256/beeb180c0e2250bb04490b092c0a235cae47fca2ed1de2d9ef078a5c14b1a963/index.js +429 -0
  121. package/vendor/components/sha256/c5fd7713e55e96d75824a21146c0251896d7d9dd028b4d169191433135a97981/index.js +200 -0
  122. package/vendor/components/sha256/c61987e9994940fc668ed8a010e575ee52027b54ed9c5dd1cc9fdf67649092b3/index.js +404 -0
  123. package/vendor/components/sha256/ccc8bfe174b6903ec254dfef4f5d1c614271ea39963649add7fcb8d83c081eba/index.js +278 -0
  124. package/vendor/components/sha256/da267bc65fde0a9279127d5a82f6c253ad74984da6fb11391f00604ad9ffe80d/index.js +93 -0
  125. package/vendor/components/sha256/dea36cd7010991a572ef394ee32b5e17564aeff09d3ec4ed3820d7e43c9a58be/index.js +484 -0
  126. package/vendor/components/sha256/df3fdb2aed487d4f6e60a8abab1fe0d1e9fa2a4193fd162edf3c384ea8db5a1b/index.js +180 -0
  127. package/vendor/components/sha256/e27d517f39eb554c7a9ecea7b59fcf1d347c4deeb3fe2250797aa233bfb7e2b0/index.js +747 -0
  128. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/README.en.md +20 -0
  129. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/index.js +310 -0
  130. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/README.en.md +30 -0
  131. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/index.js +192 -0
  132. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/README.en.md +24 -0
  133. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/index.js +214 -0
  134. package/vendor/components-2/manifest-2.16.0.json +2919 -0
  135. package/vendor/components-2/manifest-2.17.0.json +2852 -0
  136. package/vendor/components-2/manifest-2.18.0.json +3182 -0
  137. package/vendor/egatari-spec/SOURCE.json +2 -2
@@ -0,0 +1,124 @@
1
+ // m-collect:並んだ札(回答など)が動いて縮み、少数の箱(要約)にまとまる
2
+ // <m-collect style="height:400px"><script type="application/json">
3
+ // {"chips":[{"label":"回答 1","to":[0,1]}, …], "targets":[{"label":"事後平均","tex":"\\mu_n"}, …], "cols":4}
4
+ // (JSON の終わり)</m-collect>
5
+ // 段階 1 で、札 i が targets[to] へ動く(to は番号か番号の配列。配列なら札の写しがそれぞれへ動く)。
6
+ // 箱は始めに点線の枠だけ出し、札が着いてから中身(label / tex / value)を出す
7
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity を使い、プレイヤーのグローバルは使わない。
8
+ // 式(tex)は組み立てのときに KaTeX で描く(spec §6.2):build.fields の targets[].tex を作り手が描いて texHtml を足し、
9
+ // この部品は markup-reader で決まった要素と属性だけを読んで置く(再生のときに KaTeX は動かない)。描いた結果がなければ tex を字のまま出して知らせる
10
+ egatariParts.define({name: "collect", version: "2.1.0", requires: {base: "1.3.0", "markup-reader": "1.0.3"}, element: "m-collect"}, function(deps){
11
+ "use strict";
12
+ var base = deps.base, MR = deps["markup-reader"];
13
+ return class extends base.MotionElement {
14
+ static partName = "collect"; // the registry name (define meta name), for report prefixes
15
+ // 組み立てのときに描く欄(spec §6.2)。式の意味は字(tex)でも持つので、KaTeX の出力は HTML だけ
16
+ static build = {fields: {"targets[].tex": "katex"}, options: {katex: {output: "html"}}};
17
+ // データの形(kit/shape.js)
18
+ static shape = {
19
+ schema: {type: "object", additionalProperties: false, required: ["chips", "targets"], properties: {
20
+ chips: {type: "array", minItems: 1, items: {type: "object", required: ["to"], properties: {label: {type: "string"}, to: {type: ["integer", "array"], items: {type: "integer"}}}}},
21
+ targets: {type: "array", minItems: 1, items: {type: "object", properties: {label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, value: {type: ["string", "number"]}, tone: {type: "string"}, x: {type: "number"}, y: {type: "number"}}}},
22
+ cols: {type: "integer"}, renderers: {type: "object"}}},
23
+ example: {chips: [{label: "表", to: 0}, {label: "裏", to: 1}], targets: [{label: "表の数"}, {label: "裏の数"}], cols: 2},
24
+ };
25
+ static steps = 1;
26
+ static props = {
27
+ move: {type: "number", default: 0.9, doc: "札 1 枚が動く秒数"},
28
+ stagger: {type: "number", default: 0.08, doc: "札ごとの出発のずれ(秒)"},
29
+ shrink: {type: "number", default: 0.35, doc: "着いたときの札の縮尺"},
30
+ "chip-w": {type: "number", default: 0, doc: "札の幅(0 なら列の数から決める)"},
31
+ "chip-h": {type: "number", default: 56, doc: "札の高さ"},
32
+ "box-w": {type: "number", default: 260, doc: "箱の幅"},
33
+ "box-h": {type: "number", default: 110, doc: "箱の高さ"},
34
+ };
35
+ mount(ctx){
36
+ var P = this.props, D = base, self = this, data = this.data || {chips: [], targets: []}, sk = MR.sink(this, ctx);
37
+ this.style.display = "block";
38
+ var W = this.clientWidth, H = this.clientHeight;
39
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"}, this);
40
+ var tone = {term: ["var(--term)", "var(--term-tint)"], emph: ["var(--emph)", "var(--emph-tint)"], muted: ["var(--muted)", "var(--bg)"]};
41
+ // 札の並び:上の段に cols 列で並べる
42
+ var C = data.chips || [], n = C.length, cols = data.cols || n, rows = Math.ceil(n / cols), gap = 14;
43
+ var cw = P["chip-w"] || Math.max(0, Math.min(220, (W - gap * (cols - 1)) / cols)), ch = P["chip-h"];
44
+ var gx = (W - (cw * cols + gap * (cols - 1))) / 2;
45
+ // 箱の並び:下の段に等間隔(x, y を書けばその位置。中心の座標)
46
+ var T = data.targets || [], bw = P["box-w"], bh = P["box-h"];
47
+ // tex と label のある箱は label を箱の下に書くので、その分(36 px)だけ下の段を上げる(要素の下にはみ出さない)
48
+ var gR = D.el("g", {}, svg); // 残る札(箱より下に重ねる。札の段が箱にかかっても箱の字は隠れない)
49
+ var under = T.some(function(tg){ return tg.tex && tg.label && tg.y === undefined; }) ? 36 : 0;
50
+ this.targets = T.map(function(tg, j){
51
+ var cx = tg.x !== undefined ? tg.x : W * (j + 1) / (T.length + 1), cy = tg.y !== undefined ? tg.y : H - bh / 2 - 4 - under;
52
+ var c = tone[tg.tone || "emph"] || tone.emph;
53
+ var frame = D.el("rect", {x: cx - bw / 2, y: cy - bh / 2, width: bw, height: bh, rx: 12, fill: "none", stroke: "var(--line)", "stroke-width": 2, "stroke-dasharray": "8 6", opacity: 0}, svg);
54
+ var g = D.el("g", {opacity: 0}, svg);
55
+ // marks for the geometry check (spec §8.4): the box is a box, its name, formula and value its labels; a name under or over the box stands outside
56
+ var bid = "t" + (j + 1), lab = function(e, out){ if (e){ e.setAttribute("data-part", "label"); e.setAttribute("data-part-id", bid); e.setAttribute("data-part-of", "box"); if (out) e.setAttribute("data-part-at", "outside"); } return e; };
57
+ D.el("rect", {"data-part": "box", "data-part-id": bid, x: cx - bw / 2, y: cy - bh / 2, width: bw, height: bh, rx: 12, fill: c[1], stroke: c[0], "stroke-width": 3}, g);
58
+ var hasV = tg.value !== undefined, ly = cy + (hasV ? -16 : 9);
59
+ if (tg.tex){ var tf = lab(MR.texFrame(g, cx, ly + 4, tg, "tex", {size: 30, anchor: "middle", color: c[0], w: bw, h: 50}, sk)); tf.firstChild.style.verticalAlign = "top"; }
60
+ else lab(D.mtext(g, cx, ly, tg.label || "", {"text-anchor": "middle", "font-size": 28, "font-weight": 700, fill: c[0]}));
61
+ if (hasV) lab(D.mtext(g, cx, cy + 38, String(tg.value), {"text-anchor": "middle", "font-size": 24, fill: "var(--fg)"}));
62
+ // 下に入らなければ(y を書いた箱)箱の上に
63
+ if (tg.tex && tg.label) lab(D.mtext(g, cx, cy + bh / 2 + 32 + 4 <= H ? cy + bh / 2 + 32 : cy - bh / 2 - 10, tg.label, {"text-anchor": "middle", "font-size": 24, fill: "var(--muted)"}), true);
64
+ return {frame: frame, g: g, cx: cx, cy: cy, col: c, last: 0};
65
+ });
66
+ // 札と、行き先ごとの写し。もとの札は元の場所に薄い枠で残る(動いた後も、何を集めたかが図に残る。印刷でも読める)
67
+ this.chips = []; this.rests = [];
68
+ var badTo = [];
69
+ C.forEach(function(cp, i){
70
+ var r = Math.floor(i / cols), q = i % cols;
71
+ var x = gx + q * (cw + gap) + cw / 2, y = 4 + ch / 2 + r * (ch + gap);
72
+ var to = Array.isArray(cp.to) ? cp.to : [cp.to === undefined ? 0 : cp.to];
73
+ var start = i * P.stagger;
74
+ to.forEach(function(j){ if (!self.targets[j]) badTo.push("chip " + i + " (" + JSON.stringify(cp.label || "") + "): to " + JSON.stringify(j)); });
75
+ if (to.some(function(j){ return self.targets[j]; })){
76
+ var rg = D.el("g", {transform: "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ")", opacity: 0}, gR);
77
+ // the chip left in place is a box with its label (the moving copies fade out, so they are not marked)
78
+ D.el("rect", {"data-part": "box", "data-part-id": "c" + (i + 1), x: -cw / 2, y: -ch / 2, width: cw, height: ch, rx: 8, fill: "none", stroke: "var(--line)", "stroke-width": 2, "stroke-dasharray": "6 5"}, rg);
79
+ D.mtext(rg, 0, 9, cp.label || "", {"data-part": "label", "data-part-id": "c" + (i + 1), "data-part-of": "box", "text-anchor": "middle", "font-size": 24, fill: "var(--muted)"});
80
+ self.rests.push({g: rg, start: start});
81
+ }
82
+ to.forEach(function(j){
83
+ var tg = self.targets[j]; if (!tg) return;
84
+ var c = tone[cp.tone || "term"] || tone.term;
85
+ var g = D.el("g", {}, svg);
86
+ D.el("rect", {x: -cw / 2, y: -ch / 2, width: cw, height: ch, rx: 8, fill: c[1], stroke: c[0], "stroke-width": 2}, g);
87
+ D.mtext(g, 0, 9, cp.label || "", {"text-anchor": "middle", "font-size": 24});
88
+ tg.last = Math.max(tg.last, start + P.move);
89
+ self.chips.push({g: g, x0: x, y0: y, x1: tg.cx, y1: tg.cy, start: start});
90
+ });
91
+ });
92
+ if (badTo.length) ctx.report("data", "[collect] " + badTo.join("; ") + ": not a target number 0–" + (T.length - 1) + " (the copy is not drawn)");
93
+ this.rows = rows;
94
+ sk.flush(); // what the formulas have to report, once per kind (spec §6.2)
95
+ }
96
+ duration(k){ var d = 0; this.targets.forEach(function(tg){ d = Math.max(d, tg.last + 0.3); }); return k >= 1 ? d : 0; }
97
+ render(k, t, ctx){
98
+ var P = this.props, D = base;
99
+ var T = k < 1 ? -Infinity : t; // 段階 0 は動く前
100
+ // 先の段階を薄く見せる表示(授業の表示):段階 0 では、まとめた後の箱をテーマの --preview-opacity の濃さで出す(札は動かさない)
101
+ var PV = 0;
102
+ if (k < 1 && ctx.preview) PV = base.previewOpacity(this);
103
+ var pr = function(start, dur){ return T === -Infinity ? 0 : D.prog(T, start, dur); };
104
+ this.chips.forEach(function(c){
105
+ var e = pr(c.start, P.move);
106
+ // 少し持ち上げてから落ちる弧(中点で上へ 40px)
107
+ var x = D.lerp(c.x0, c.x1, e), y = D.lerp(c.y0, c.y1, e) - Math.sin(Math.PI * e) * 40;
108
+ var s = D.lerp(1, P.shrink, e), op = e < 0.75 ? 1 : 1 - (e - 0.75) / 0.25;
109
+ c.g.setAttribute("transform", "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ") scale(" + s.toFixed(4) + ")");
110
+ c.g.setAttribute("opacity", op.toFixed(3));
111
+ });
112
+ // 残る札:写しが出発したら現れる
113
+ this.rests.forEach(function(c){ c.g.setAttribute("opacity", Math.min(1, pr(c.start, P.move) * 4).toFixed(3)); });
114
+ this.targets.forEach(function(tg){
115
+ tg.frame.setAttribute("opacity", (pr(0, 0.3) * (1 - pr(tg.last - 0.1, 0.3))).toFixed(3));
116
+ var e = pr(tg.last - 0.15, 0.45);
117
+ if (PV){ e = 1; tg.g.setAttribute("opacity", PV.toFixed(3)); }
118
+ else tg.g.setAttribute("opacity", e.toFixed(3));
119
+ var s = D.lerp(0.9, 1, e);
120
+ tg.g.setAttribute("transform", "translate(" + tg.cx + " " + tg.cy + ") scale(" + s.toFixed(4) + ") translate(" + (-tg.cx) + " " + (-tg.cy) + ")");
121
+ });
122
+ }
123
+ };
124
+ });
@@ -0,0 +1,23 @@
1
+ ---
2
+ summary: Balance at expectation
3
+ steps: Weights → pivot → sum (3)
4
+ props:
5
+ dur: Seconds
6
+ digits: Decimal places
7
+ size: Text px
8
+ ---
9
+
10
+ JSON:
11
+ - `values`: 2–12 distinct numbers.
12
+ - `probs`: sum to 1 (else reported).
13
+ - `name`: X.
14
+
15
+ <!-- llm: omit -->
16
+ Bars proportional to probabilities. Pivot: minimum → E[X]. Moment controls tilt, clamped ±8°, then levels. Beam, bars and ticks rotate together. Starts horizontal; tilts at step 2. Final E and mtext sum; first 6 terms then …; computation and accessible weights include all terms. Negative terms parenthesized.
17
+
18
+ Invalid totals stay unnormalized. Out-of-range probabilities, mismatched lengths, duplicates or unrepresentable calculations: report, no draw. dur 1.5s; digits 0–10 (2), trailing zeros removed; size 0=26px, ≥24. Bad props default/report.
19
+
20
+ 1184×440px suggested. Scaled coordinates, nice ticks. Close bars, labels or long sums report size.
21
+
22
+ ctx.lang selects ja/en. Font boxes ≥1.43em plus gap. Image role, final summary; preserve author label, hide SVG. No answer preview. Fictional demo.
23
+ <!-- llm: end -->
@@ -0,0 +1,120 @@
1
+ // m-balance: expectation is the zero-moment position of probability weights.
2
+ egatariParts.define({name: "balance", version: "2.0.2", requires: {base: "1.3.0", plot: "1.1.3"}, 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
+ });
@@ -0,0 +1,18 @@
1
+ ---
2
+ summary: A positioning table: the cross of two axes (studies in cells, this work framed, empty cells — with a note) or studies × elements (✓ △ × or short text), filled by step
3
+ steps: cross: axes → studies → this work → notes (order="whole": 1). attributes: per column or row (order) + frame
4
+ props:
5
+ order: cross build|whole; attributes whole|col|row
6
+ dur: seconds per step
7
+ size: text px (≥ 24)
8
+ example: {"kind": "cross", "rows": {"axis": "Criterion", "values": ["Error", "Bayes risk"]}, "cols": {"axis": "Output", "values": ["Point", "Distribution"]}, "cells": [[["[1]", "[2]"], ["[3]"]], [{"none": "Trivial"}, {"self": true}]]}
9
+ ---
10
+
11
+ `kind`: `cross` (default) or `attributes`.
12
+
13
+ - cross: `rows`, `cols` = `{"axis", "values"}` (2–4 each). `cells[r][c]`: study names (1–3), `{"self": true}` or `{"none": "why"}` (— and a note). `marks`: `[{"mark": "†", "text"}]`
14
+ - attributes: `cols` names; `rows` `{"label", "cells", "self"}`, this work first
15
+ - This work is written out and framed in `--emph`
16
+ <!-- llm: omit -->
17
+ - Readable table: headers as "axis: value". Text shrinks to 24 px, then reports size.
18
+ <!-- llm: end -->
@@ -0,0 +1,243 @@
1
+ // m-matrix 2.0.0: a comparison matrix in two forms (handoff #64).
2
+ // kind "cross" (default): the cross of two axes. Rows are the values of axis 1, columns the values of axis 2 (2 to 4 each);
3
+ // a cell lists the studies that fall there (a citation number or "Author (year)", 1 to 3), "self" marks the cell of this work
4
+ // (written as 本研究 / This work and framed, never colour alone), and an empty cell shows — with a note number; the notes
5
+ // ("trivial", "meaningless", "not yet done") stand under the table. A third axis is a mark after a study's name (†, ‡)
6
+ // explained by "marks". Steps (order "build", default): the axes and the empty grid → the earlier studies → this work's
7
+ // cell, framed → the notes of the empty cells. order "whole": everything at step 1.
8
+ // kind "attributes": rows are studies (this work first), columns their elements (aim, setting, input, output, criterion …),
9
+ // a cell a short text (✓ △ × too). order "whole" (default), "col" (a column per step) or "row" (a row per step);
10
+ // the row marked self is framed at the last step.
11
+ // Headers: a cross table names its axes once (the row axis in the corner, the column axis over its values); the readable
12
+ // table (data-readable, the final state) writes each header as "axis: value". Cells are data-part boxes and their texts
13
+ // labels, for Studio's geometry check (spec §8.4). Text is size px (≥ 24); when the table does not fit at 24 px the part
14
+ // reports size with what it needs. Colours: grid --line, headers --fg bold, this work's frame --emph, notes and dashes --muted.
15
+ egatariParts.define({name: "matrix", version: "2.0.0", requires: {base: "1.3.0"}, element: "m-matrix"}, function(deps){
16
+ "use strict";
17
+ var base = deps.base;
18
+ var T = {ja: {self: "本研究", note: "注", sep: ":", label: "表:", none: "該当なし"},
19
+ en: {self: "This work", note: "Note ", sep: ": ", label: "Table: ", none: "none"}};
20
+ var STR = {type: "string"};
21
+ var CELL = {type: ["array", "object"]};
22
+ return class extends base.MotionElement {
23
+ static partName = "matrix";
24
+ static shape = {
25
+ schema: {type: "object", additionalProperties: false, properties: {
26
+ kind: {type: "string", enum: ["cross", "attributes"]},
27
+ rows: {type: ["object", "array"]},
28
+ cols: {type: ["object", "array"]},
29
+ cells: {type: "array", maxItems: 4, items: {type: "array", maxItems: 4, items: CELL}},
30
+ marks: {type: "array", maxItems: 3, items: {type: "object", additionalProperties: false, required: ["mark", "text"], properties: {mark: STR, text: STR}}},
31
+ self: STR}},
32
+ example: {kind: "cross", rows: {axis: "評価基準", values: ["予測誤差", "ベイズリスク"]}, cols: {axis: "予測の形", values: ["点予測", "分布予測"]},
33
+ cells: [[["[1]", "[2]"], ["[3]"]], [{none: "自明"}, {self: true}]]},
34
+ note: {en: "cross: rows and cols are {\"axis\", \"values\"}; cells[r][c] is a list of study names, {\"self\": true} or {\"none\": \"why it is empty\"}. attributes: cols is a list of names, rows a list of {\"label\", \"cells\", \"self\"?}",
35
+ ja: "cross:rows と cols は {\"axis\", \"values\"}、cells[r][c] は研究の名前の並び、{\"self\": true}、{\"none\": \"空きの理由\"} のどれか。attributes:cols は名前の並び、rows は {\"label\", \"cells\", \"self\"?} の並び"},
36
+ };
37
+ static props = {
38
+ order: {type: "string", default: "", doc: "出し方:cross は build(既定)・whole、attributes は whole(既定)・col・row"},
39
+ dur: {type: "number", default: 0.6, doc: "1 ステップの秒数"},
40
+ size: {type: "number", default: 28, doc: "字の大きさ(px、24 以上。入らなければ 24 まで縮める)"},
41
+ };
42
+ get steps(){
43
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
44
+ return this.plan().steps;
45
+ }
46
+ // the cells and when each appears; from the data alone
47
+ plan(){
48
+ if (this._plan) return this._plan;
49
+ var d = this.data || {}, bad = [], ja = !/^en\b/i.test(this.closest && this.closest("[lang]") ? this.closest("[lang]").getAttribute("lang") : "ja");
50
+ var L = ja ? T.ja : T.en, selfText = d.self || L.self, kind = d.kind || "cross", order = this.props.order;
51
+ var cells = [], notes = [], grid = {}, steps = 0, selfBox = null;
52
+ var cell = function(r, c, lines, o){ var x = Object.assign({r: r, c: c, lines: lines, step: 0}, o || {}); cells.push(x); grid[r + "," + c] = x; return x; };
53
+ var nr, nc, head;
54
+ if (kind === "cross") {
55
+ var R = d.rows && !Array.isArray(d.rows) ? d.rows : {}, C = d.cols && !Array.isArray(d.cols) ? d.cols : {};
56
+ var rv = Array.isArray(R.values) ? R.values.map(String) : [], cv = Array.isArray(C.values) ? C.values.map(String) : [];
57
+ if (rv.length < 2 || rv.length > 4 || cv.length < 2 || cv.length > 4) bad.push("cross needs 2 to 4 values on each axis (rows.values, cols.values)");
58
+ if (order && order !== "build" && order !== "whole") bad.push("order for cross is build or whole, not " + order);
59
+ var whole = order === "whole";
60
+ // grid: row 0 = the column axis's name over its values, row 1 = the column values; column 0 = the row values
61
+ nr = rv.length + 2; nc = cv.length + 1; head = {rows: 2, cols: 1};
62
+ cell(0, 0, [String(R.axis || "")], {head: true, corner: true, span: [2, 1]});
63
+ cell(0, 1, [String(C.axis || "")], {head: true, span: [1, cv.length]});
64
+ cv.forEach(function(v, j){ cell(1, j + 1, [v], {head: true}); });
65
+ rv.forEach(function(v, i){ cell(i + 2, 0, [v], {head: true}); });
66
+ var cs = Array.isArray(d.cells) ? d.cells : [];
67
+ if (cs.length !== rv.length || cs.some(function(row, i){ return !Array.isArray(row) || row.length !== cv.length; })) bad.push("cells must be " + rv.length + " rows of " + cv.length + " cells (rows.values × cols.values)");
68
+ // build: the studies at 1, this work at 2 (when there is one), the notes at the last step (when there are any)
69
+ var anySelf = cs.some(function(row){ return Array.isArray(row) && row.some(function(v){ return v && typeof v === "object" && !Array.isArray(v) && v.self; }); });
70
+ var anyNote = cs.some(function(row){ return Array.isArray(row) && row.some(function(v){ return v && typeof v === "object" && !Array.isArray(v) && typeof v.none === "string" && v.none; }); });
71
+ var sSelf = whole ? 1 : 2, sNote = whole ? 1 : anySelf ? 3 : 2;
72
+ steps = whole ? 1 : 1 + (anySelf ? 1 : 0) + (anyNote ? 1 : 0);
73
+ rv.forEach(function(_, i){ cv.forEach(function(_, j){
74
+ var v = (cs[i] || [])[j], r = i + 2, c = j + 1, obj = v && typeof v === "object" && !Array.isArray(v);
75
+ if (Array.isArray(v) && v.length) {
76
+ if (v.length > 3) bad.push("cell " + (i + 1) + "," + (j + 1) + " lists " + v.length + " studies; at most 3 (pick the main ones)");
77
+ cell(r, c, v.slice(0, 3).map(String), {step: 1});
78
+ } else if (obj && v.self) {
79
+ if (selfBox) bad.push("only one cell is this work's (self)");
80
+ var x = cell(r, c, [selfText].concat((Array.isArray(v.studies) ? v.studies : []).map(String)), {step: sSelf, self: !selfBox});
81
+ if (!selfBox) selfBox = x;
82
+ } else if (obj && typeof v.none === "string" && v.none) {
83
+ notes.push(v.none);
84
+ cell(r, c, ["— " + L.note + notes.length], {step: sNote, dash: true, note: notes.length});
85
+ } else {
86
+ cell(r, c, ["—"], {step: 1, dash: true});
87
+ }
88
+ }); });
89
+ var marks = Array.isArray(d.marks) ? d.marks : [];
90
+ var below = marks.map(function(m){ return {text: m.mark + " " + m.text, step: 1}; })
91
+ .concat(notes.map(function(t, i){ return {text: L.note + (i + 1) + L.sep + t, step: sNote}; }));
92
+ return (this._plan = {kind: kind, L: L, bad: bad, cells: cells, grid: grid, nr: nr, nc: nc, head: head, steps: steps, selfBox: selfBox, below: below,
93
+ rv: rv, cv: cv, raxis: String(R.axis || ""), caxis: String(C.axis || "")});
94
+ }
95
+ if (kind !== "attributes") bad.push("kind is cross or attributes");
96
+ var cols = Array.isArray(d.cols) ? d.cols.map(String) : [], rows = Array.isArray(d.rows) ? d.rows : [];
97
+ if (cols.length < 1 || cols.length > 6) bad.push("attributes needs 1 to 6 cols");
98
+ if (rows.length < 1 || rows.length > 10) bad.push("attributes needs 1 to 10 rows");
99
+ order = order || "whole";
100
+ if (["whole", "col", "row"].indexOf(order) < 0) { bad.push("order for attributes is whole, col or row, not " + order); order = "whole"; }
101
+ nr = rows.length + 1; nc = cols.length + 1; head = {rows: 1, cols: 1};
102
+ var selfRow = -1;
103
+ rows.forEach(function(r, i){ if (r && r.self && selfRow < 0) selfRow = i; });
104
+ var groups = order === "whole" ? 1 : order === "col" ? cols.length : rows.length;
105
+ steps = groups + (selfRow >= 0 && order !== "whole" ? 1 : 0);
106
+ cell(0, 0, [""], {head: true, corner: true});
107
+ cols.forEach(function(v, j){ cell(0, j + 1, [v], {head: true}); });
108
+ rows.forEach(function(r, i){
109
+ r = r && typeof r === "object" ? r : {};
110
+ var cs = Array.isArray(r.cells) ? r.cells : [];
111
+ if (cs.length !== cols.length) bad.push("row " + (i + 1) + " has " + cs.length + " cells; cols has " + cols.length);
112
+ var at = function(j){ return order === "whole" ? 1 : order === "col" ? j + 1 : i + 1; };
113
+ cell(i + 1, 0, [String(r.label || "")], {head: true, step: order === "row" ? i + 1 : 0, self: i === selfRow});
114
+ cols.forEach(function(_, j){
115
+ var v = cs[j], s = v === undefined || v === null || v === "" ? "—" : String(v);
116
+ cell(i + 1, j + 1, [s], {step: at(j), dash: s === "—"});
117
+ });
118
+ });
119
+ return (this._plan = {kind: kind, L: L, bad: bad, cells: cells, grid: grid, nr: nr, nc: nc, head: head, steps: steps, selfRow: selfRow,
120
+ selfStep: selfRow >= 0 ? (order === "whole" ? 1 : steps) : 0, below: [], cols: cols, rowsLabels: rows.map(function(r){ return String((r || {}).label || ""); })});
121
+ }
122
+ mount(ctx){
123
+ var self = this, P = this.props, D = base, pl = this.plan();
124
+ this.style.display = "block"; this.style.position = "relative";
125
+ var W = this.clientWidth, H = this.clientHeight;
126
+ if (!(P.dur >= 0)) { ctx.report("attr", "[matrix] dur must be ≥ 0; using 0.6"); P.dur = 0.6; }
127
+ if (!(P.size >= 24)) { ctx.report("attr", "[matrix] size must be ≥ 24; using 28"); P.size = 28; }
128
+ pl.bad.forEach(function(m){ ctx.report("data", "[matrix] " + m); });
129
+ if (pl.bad.length && (pl.nr < 2 || pl.nc < 2)) return; // nothing to draw a grid from
130
+ // sizes: the largest font from size down to 24 at which the table fits; else 24 and a size report
131
+ var fit = null;
132
+ for (var fs = Math.round(P.size); fs >= 24 && !fit; fs -= 2) fit = this._fit(fs, W, H);
133
+ if (!fit) {
134
+ var g24 = this._fit(24, W, H, true);
135
+ ctx.report("size", "[matrix] the table needs " + Math.ceil(g24.tableW) + " × " + Math.ceil(g24.needH) + " px at 24 px; the element is " + W + " × " + H + " px (fewer rows or columns, shorter names, or a larger element)");
136
+ fit = g24;
137
+ }
138
+ var G = this.geo = fit, fsz = G.fs;
139
+ var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
140
+ var gB = D.el("g", {}, svg), gL = D.el("g", {}, svg), gT = D.el("g", {}, svg), gF = D.el("g", {}, svg), gN = D.el("g", {}, svg);
141
+ var xs = G.xs, ys = G.ys, x0 = xs[0], y0 = ys[0], hr = pl.head.rows, hc = pl.head.cols;
142
+ // grid: thick under the header rows and right of the header column; the column-axis row has no vertical lines inside its span
143
+ for (var r = 0; r <= pl.nr; r++) {
144
+ var xa = pl.kind === "cross" && r === 1 ? xs[1] : x0;
145
+ D.el("line", {x1: xa, x2: xs[pl.nc], y1: ys[r], y2: ys[r], stroke: "var(--line)", "stroke-width": r === hr ? 2.5 : 1.2}, gL);
146
+ }
147
+ for (var c = 0; c <= pl.nc; c++) {
148
+ var ya = pl.kind === "cross" && c >= 2 && c < pl.nc ? ys[1] : y0;
149
+ D.el("line", {x1: xs[c], x2: xs[c], y1: ya, y2: ys[pl.nr], stroke: "var(--line)", "stroke-width": c === hc ? 2.5 : 1.2}, gL);
150
+ }
151
+ var lh = Math.ceil(fsz * 1.3), pad = G.pad;
152
+ this.cellEls = pl.cells.map(function(x){
153
+ var sp = x.span || [1, 1], cx0 = xs[x.c], cx1 = xs[x.c + sp[1]], cy0 = ys[x.r], cy1 = ys[x.r + sp[0]];
154
+ var id = "m" + x.r + "-" + x.c, g = D.el("g", {}, gT);
155
+ D.el("rect", {x: cx0, y: cy0, width: cx1 - cx0, height: cy1 - cy0, fill: "none", stroke: "none", "data-part": "box", "data-part-id": id}, gB);
156
+ var left = x.head && x.c === 0, n = x.lines.length, top = (cy0 + cy1) / 2 - (n - 1) * lh / 2 + fsz * 0.36;
157
+ x.lines.forEach(function(s, i){
158
+ var t = D.el("text", {x: (left ? cx0 + pad : (cx0 + cx1) / 2).toFixed(1), y: (top + i * lh).toFixed(1), "font-size": fsz,
159
+ "text-anchor": left ? "start" : "middle", fill: x.dash ? "var(--muted)" : "var(--fg)", "font-weight": x.head || (x.self && i === 0) ? 700 : 400,
160
+ "data-part": "label", "data-part-id": id, "data-part-of": "box"}, g);
161
+ t.textContent = s;
162
+ });
163
+ return {x: x, g: g};
164
+ });
165
+ // this work: the cell (cross) or the row (attributes), framed in --emph
166
+ var fr = null;
167
+ if (pl.selfBox) { var b = pl.selfBox; fr = [xs[b.c] + 3, ys[b.r] + 3, xs[b.c + 1] - xs[b.c] - 6, ys[b.r + 1] - ys[b.r] - 6]; this.frameStep = b.step; }
168
+ else if (pl.selfRow >= 0) { var rr = pl.selfRow + 1; fr = [x0 + 3, ys[rr] + 3, xs[pl.nc] - x0 - 6, ys[rr + 1] - ys[rr] - 6]; this.frameStep = pl.selfStep; }
169
+ this.frame = fr ? D.el("rect", {x: fr[0], y: fr[1], width: fr[2], height: fr[3], rx: 5, fill: "none", stroke: "var(--emph)", "stroke-width": 4}, gF) : null;
170
+ // notes and marks under the table
171
+ this.belowEls = pl.below.map(function(o, i){
172
+ var t = D.el("text", {x: x0.toFixed(1), y: (G.tableBottom + 14 + fsz * 0.9 + i * Math.ceil(fsz * 1.35)).toFixed(1), "font-size": fsz, fill: "var(--fg)"}, gN);
173
+ t.textContent = o.text;
174
+ return {o: o, t: t};
175
+ });
176
+ // the readable table (data-readable): the final state, headers as "axis: value"
177
+ var tbl = document.createElement("table");
178
+ tbl.className = "sr-only"; tbl.setAttribute("data-readable", "");
179
+ tbl.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0");
180
+ var L = pl.L, tr = function(list, th){ var e = document.createElement("tr"); list.forEach(function(s, i){ var td = document.createElement(th || i === 0 ? "th" : "td"); td.textContent = s; e.appendChild(td); }); tbl.appendChild(e); };
181
+ if (pl.kind === "cross") {
182
+ tr([pl.raxis + " \ " + pl.caxis].concat(pl.cv.map(function(v){ return pl.caxis + L.sep + v; })), true);
183
+ pl.rv.forEach(function(v, i){ tr([pl.raxis + L.sep + v].concat(pl.cv.map(function(_, j){ return pl.grid[(i + 2) + "," + (j + 1)].lines.join("、"); }))); });
184
+ if (pl.below.length) { var cap = document.createElement("caption"); cap.textContent = pl.below.map(function(o){ return o.text; }).join(" "); tbl.insertBefore(cap, tbl.firstChild); }
185
+ } else {
186
+ tr([""].concat(pl.cols), true);
187
+ pl.rowsLabels.forEach(function(v, i){ tr([v + (i === pl.selfRow ? "(" + L.self + ")" : "")].concat(pl.cols.map(function(_, j){ return pl.grid[(i + 1) + "," + (j + 1)].lines.join(" "); }))); });
188
+ }
189
+ this.appendChild(tbl);
190
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
191
+ this.setAttribute("role", "img");
192
+ if (!this._aria) this.setAttribute("aria-label", L.label + (pl.kind === "cross" ? pl.raxis + " × " + pl.caxis : pl.cols.join(pl.L === T.ja ? "、" : ", ")));
193
+ }
194
+ // column widths and row heights at font size fs; null when the table does not fit W × H (unless force)
195
+ _fit(fs, W, H, force){
196
+ var pl = this.plan(), D = base, self = this, pad = Math.round(fs * 0.5), lh = Math.ceil(fs * 1.3);
197
+ var tw = function(s, b){ return D.textWidth(s, fs, {font: self}) * (b ? 1.06 : 1); };
198
+ var cw = [], rh = [];
199
+ for (var c = 0; c < pl.nc; c++) cw[c] = fs * 2;
200
+ for (var r = 0; r < pl.nr; r++) rh[r] = Math.ceil(fs * 1.6);
201
+ pl.cells.forEach(function(x){
202
+ if (x.span && x.span[1] > 1) return;
203
+ var w = Math.max.apply(null, x.lines.map(function(s, i){ return tw(s, x.head || (x.self && i === 0)); })) + 2 * pad;
204
+ if (w > cw[x.c]) cw[x.c] = Math.ceil(w);
205
+ var h = Math.ceil(x.lines.length * lh + fs * 0.5);
206
+ if (!(x.span && x.span[0] > 1) && h > rh[x.r]) rh[x.r] = h;
207
+ });
208
+ // value columns of the same width (a matrix reads by its grid), the header column as wide as it needs
209
+ var vmax = Math.max.apply(null, cw.slice(1));
210
+ for (var c2 = 1; c2 < pl.nc; c2++) cw[c2] = vmax;
211
+ var spanW = pl.kind === "cross" ? tw(pl.caxis, true) + 2 * pad : 0;
212
+ var tableW = cw.reduce(function(a, b){ return a + b; }, 0);
213
+ if (spanW > tableW - cw[0]) { var add = (spanW - (tableW - cw[0])) / (pl.nc - 1); for (var c3 = 1; c3 < pl.nc; c3++) cw[c3] += add; tableW = spanW + cw[0]; }
214
+ // spread the value columns over the width the element has, up to 1.4 times what they need
215
+ var room = W - 4 - tableW;
216
+ if (room > 0) { var grow = Math.min(room, (tableW - cw[0]) * 0.4) / (pl.nc - 1); for (var c4 = 1; c4 < pl.nc; c4++) cw[c4] += grow; tableW += grow * (pl.nc - 1); }
217
+ var tableH = rh.reduce(function(a, b){ return a + b; }, 0), belowH = pl.below.length ? 14 + pl.below.length * Math.ceil(fs * 1.35) : 0;
218
+ var needH = tableH + belowH + 8;
219
+ if (!force && (tableW > W - 2 || needH > H)) return null;
220
+ // fill the element's height: the body rows grow, each to at most 1.8 times its height (no wide empty band under a short table)
221
+ if (needH < H) {
222
+ var nb = pl.nr - pl.head.rows, each = Math.min((H - needH) / nb, Math.min.apply(null, rh.slice(pl.head.rows)) * 0.8);
223
+ for (var r2 = pl.head.rows; r2 < pl.nr; r2++) rh[r2] += each;
224
+ tableH += each * nb; needH += each * nb;
225
+ }
226
+ var x0 = Math.max(1, (W - tableW) / 2), xs = [x0], ys = [4];
227
+ cw.forEach(function(w, i){ xs.push(xs[i] + w); });
228
+ rh.forEach(function(h, i){ ys.push(ys[i] + h); });
229
+ return {fs: fs, pad: pad, xs: xs, ys: ys, tableW: tableW, needH: needH, tableBottom: ys[ys.length - 1]};
230
+ }
231
+ duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
232
+ render(k, t, ctx){
233
+ if (!this.cellEls) return;
234
+ var D = base, P = this.props, N = this.plan().steps, faint = ctx && (ctx.preview || ctx.mode === "lecture") ? base.previewOpacity(this) : 0;
235
+ k = Math.max(0, Math.min(k, N));
236
+ var e = k === 0 ? 1 : D.prog(t, 0, P.dur);
237
+ var op = function(st){ var v = st === 0 || st < k ? 1 : st > k ? 0 : e; return Math.max(v, st > k ? faint : 0); };
238
+ this.cellEls.forEach(function(o){ o.g.setAttribute("opacity", op(o.x.step).toFixed(3)); });
239
+ if (this.frame) this.frame.setAttribute("opacity", (this.frameStep > k ? 0 : this.frameStep < k ? 1 : e).toFixed(3));
240
+ this.belowEls.forEach(function(o){ o.t.setAttribute("opacity", op(o.o.step).toFixed(3)); });
241
+ }
242
+ };
243
+ });