egatari 0.6.17 → 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 +36 -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,122 @@
1
+ // heatmap-core 1.0.0: m-heatmap's calculations (a library part, Egatari spec §6.1): row normalisation, the colour domain and
2
+ // the place of a value on it, mixing in OKLab and WCAG contrast (the text colour and halo per cell), the layout (cell size,
3
+ // label thinning, vertical column labels), the size of the numbers in the cells and the steps. Pure functions of their
4
+ // arguments: no DOM, no state. m-heatmap 2.0.0 requires it; tools/test-heatmap.mjs tests it without a browser. Moved from
5
+ // m-heatmap 1.13.0 (its `static calc`) unchanged, except that layout's notes no longer start with "m-heatmap: ".
6
+ // returns {clean, normalizeRows, domain, frac, mix, contrast, lum, pick, est, layout, shown, numberSize, steps}
7
+ egatariParts.define({name: "heatmap-core", version: "1.0.0", requires: {}}, function(){
8
+ "use strict";
9
+ function clean(v){ return +(+v).toFixed(10); }
10
+ // 行ごとの割合(混同行列)。行の和が 0 なら 0 のまま
11
+ function normalizeRows(values){
12
+ return values.map(function(row){
13
+ var s = row.reduce(function(a, v){ return a + v; }, 0);
14
+ return row.map(function(v){ return s ? v / s : 0; });
15
+ });
16
+ }
17
+ // 色の範囲:sequential は [min(0, 最小), 最大]、diverging は center を真ん中に対称(|値 − center| の最大)
18
+ function domain(values, kind, center, range){
19
+ var all = [].concat.apply([], values).filter(function(v){ return isFinite(v); });
20
+ if (range && range.length === 2) return {lo: +range[0], hi: +range[1], c: kind === "diverging" ? center : (+range[0] + +range[1]) / 2};
21
+ var lo = Math.min.apply(null, all), hi = Math.max.apply(null, all);
22
+ if (kind === "diverging"){
23
+ var m = Math.max(Math.abs(hi - center), Math.abs(lo - center)) || 1;
24
+ return {lo: clean(center - m), hi: clean(center + m), c: center};
25
+ }
26
+ lo = Math.min(0, lo);
27
+ if (hi === lo) hi = lo + 1;
28
+ return {lo: lo, hi: hi, c: clean((lo + hi) / 2)};
29
+ }
30
+ // 値 → 混ぜる割合 f(sequential は 0〜1、diverging は −1〜1。負は lowtone の側)。範囲の外は端にそろえる
31
+ function frac(v, kind, d){
32
+ if (kind === "diverging"){
33
+ var f = v >= d.c ? (d.hi > d.c ? (v - d.c) / (d.hi - d.c) : 0) : (d.lo < d.c ? -(d.c - v) / (d.c - d.lo) : 0);
34
+ return Math.max(-1, Math.min(1, f));
35
+ }
36
+ return Math.max(0, Math.min(1, (v - d.lo) / (d.hi - d.lo)));
37
+ }
38
+ // ---- 色(sRGB 0〜255 の [r, g, b]) ----
39
+ function lin(c){ c /= 255; return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); }
40
+ function lum(c){ return 0.2126 * lin(c[0]) + 0.7152 * lin(c[1]) + 0.0722 * lin(c[2]); }
41
+ function oklab(c){
42
+ var r = lin(c[0]), g = lin(c[1]), b = lin(c[2]);
43
+ var l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b), m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b), s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
44
+ return [0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s, 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s];
45
+ }
46
+ function fromOklab(o){
47
+ var l = Math.pow(o[0] + 0.3963377774 * o[1] + 0.2158037573 * o[2], 3), m = Math.pow(o[0] - 0.1055613458 * o[1] - 0.0638541728 * o[2], 3), s = Math.pow(o[0] - 0.0894841775 * o[1] - 1.2914855480 * o[2], 3);
48
+ var f = function(x){ x = Math.max(0, Math.min(1, x)); return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055); };
49
+ return [f(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s), f(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s), f(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s)];
50
+ }
51
+ function contrast(a, b){ var x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); }
52
+ // color-mix(in oklab, tone p, bg) の色(oklab での直線の補間)
53
+ function mix(tone, bg, p){ var a = oklab(tone), b = oklab(bg); return fromOklab([0, 1, 2].map(function(i){ return b[i] + (a[i] - b[i]) * p; })); }
54
+ var MIN = 4.6; // 4.5:1 に、ブラウザの丸めの分の余裕
55
+ // 字の色:割合 p(0〜1)の色(セルの色は変えない。色がデータなので)に対して、--fg と --bg のうちコントラストの高い方。
56
+ // それでも MIN に届かない(明るさがちょうど中くらいの帯)ときは halo:字の周りに反対の色の細い縁(paint-order: stroke)を付ける。
57
+ // 返すのは {p, text: "fg" | "bg", cr, halo}
58
+ function pick(tone, bg, fg, p){
59
+ var c = mix(tone, bg, p), a = contrast(c, fg), b = contrast(c, bg), o = a >= b ? {p: p, text: "fg", cr: a} : {p: p, text: "bg", cr: b};
60
+ o.halo = o.cr < MIN;
61
+ return o;
62
+ }
63
+ // ---- 配置(字の幅は見積もり:半角 0.56 字、全角 1 字) ----
64
+ // セルの数字は表の数字の幅(0.7 字。−も同じ)で見積もる
65
+ function est(s, size, an){ an = an || 0.56; return [...String(s)].reduce(function(a, c){ return a + (/[\u0000-ɏ−]/.test(c) ? an : 1); }, 0) * size; }
66
+ // o: {W, H, rows, cols, legend: [字], xl, yl, rotate: "auto" | "0" | "90"}。
67
+ // 字は 26 px(入らなければ 24 px。それより小さくしない)。列の名前は横か縦(rotate)。入らなければ k 個おきに出す
68
+ function layout(o){
69
+ var nr = o.rows.length, nc = o.cols.length, best = null;
70
+ var rot = String(o.rotate || "auto"), orients = rot === "0" ? ["h"] : rot === "90" ? ["v"] : ["h", "v"];
71
+ var legW = Math.max.apply(null, [0].concat((o.legend || []).map(function(s){ return est(s, 24); })));
72
+ [26, 24].forEach(function(fs){
73
+ var rowW = Math.max.apply(null, [0].concat(o.rows.map(function(s){ return est(s, fs); })));
74
+ var colW = Math.max.apply(null, [0].concat(o.cols.map(function(s){ return est(s, fs); })));
75
+ var left = (o.yl ? 40 : 0) + (rowW ? rowW + 14 : 4), right = o.legend ? 22 + 24 + 10 + legW + 4 : 4;
76
+ orients.forEach(function(or){
77
+ var top = (o.xl ? 40 : 0) + (colW ? (or === "h" ? Math.ceil(fs * 1.25) + 8 : Math.ceil(colW) + 14) : 4);
78
+ var cs = Math.min((o.W - left - right) / nc, (o.H - top - 4) / nr, 180);
79
+ if (!(cs > 0)) cs = 0;
80
+ var kc = colW ? Math.max(1, Math.ceil((or === "h" ? colW + 10 : fs * 1.25) / Math.max(cs, 1e-6) - 1e-9)) : 1;
81
+ var kr = rowW ? Math.max(1, Math.ceil(fs * 1.25 / Math.max(cs, 1e-6) - 1e-9)) : 1;
82
+ var c = {fs: fs, orient: or, left: left, right: right, top: top, cs: cs, kc: kc, kr: kr, rowW: rowW, colW: colW, legW: legW};
83
+ var score = function(x){ return (x.kc - 1) + (x.kr - 1); };
84
+ if (!best || score(c) < score(best) || (score(c) === score(best) && c.cs > best.cs + 0.5 && score(c) > 0)) best = c;
85
+ });
86
+ });
87
+ var b = best, gw = nc * b.cs, gh = nr * b.cs, total = b.left + gw + b.right;
88
+ b.x0 = Math.max(0, (o.W - total) / 2); // 左の端(行の名前の左)
89
+ b.gx = b.x0 + b.left; b.gy = b.top + Math.max(0, (o.H - b.top - gh - 4) / 2);
90
+ b.gw = gw; b.gh = gh;
91
+ b.notes = []; // messages without a prefix: m-heatmap reports them with its own
92
+ if (b.kc > 1) b.notes.push(nc + " columns are too many to label at 24 px; every " + ord(b.kc) + " column label is shown");
93
+ if (b.kr > 1) b.notes.push(nr + " rows are too many to label at 24 px; every " + ord(b.kr) + " row label is shown");
94
+ if (b.cs < 4) b.notes.push("the element (" + o.W + "×" + o.H + " px) is too small for " + nr + "×" + nc + " cells");
95
+ return b;
96
+ }
97
+ function ord(k){ return k + (k % 10 === 2 && k % 100 !== 12 ? "nd" : k % 10 === 3 && k % 100 !== 13 ? "rd" : "th"); }
98
+ // 出す名前の番号(k 個おき、0 から)
99
+ function shown(n, k){ var out = []; for (var i = 0; i < n; i += k) out.push(i); return out; }
100
+ // セルの数字の大きさ:lines 行(1 か 2)の字 texts が cs の正方形に収まる最も大きい大きさ(34 px まで)。24 px でも入らなければ 0
101
+ function numberSize(cs, texts, lines){
102
+ var w = Math.max.apply(null, [0].concat(texts.map(function(s){ return est(s, 1, 0.7); })));
103
+ for (var f = Math.min(34, Math.floor(cs * 0.28)); f >= 24; f--){
104
+ if (w * f <= cs - 12 && lines * f * 1.2 <= cs - 6) return f;
105
+ }
106
+ return w * 24 <= cs - 12 && lines * 24 * 1.2 <= cs - 6 ? 24 : 0;
107
+ }
108
+ // 段階:セルごとの段階 cell[r][c]、強調の段階、全体の段階の数
109
+ function steps(nr, nc, build, highlight){
110
+ var cell = [], k = 1, hs;
111
+ for (var r = 0; r < nr; r++){ cell.push([]); for (var c = 0; c < nc; c++) cell[r].push(build === "rows" ? r + 1 : 1); }
112
+ var last = build === "rows" ? nr : 1;
113
+ hs = (highlight || []).map(function(h, i){
114
+ var st = h.length > 2 && isFinite(h[2]) ? Math.max(1, Math.round(h[2])) : build === "cells" ? 2 + i : build === "rows" ? nr + 1 : 1;
115
+ return {r: h[0], c: h[1], st: st};
116
+ });
117
+ k = Math.max.apply(null, [last].concat(hs.map(function(h){ return h.st; })));
118
+ return {cell: cell, hl: hs, steps: Math.max(1, k)};
119
+ }
120
+ return {clean: clean, normalizeRows: normalizeRows, domain: domain, frac: frac, mix: mix, contrast: contrast, lum: lum, pick: pick,
121
+ est: est, layout: layout, shown: shown, numberSize: numberSize, steps: steps, MIN: MIN};
122
+ });
@@ -0,0 +1,37 @@
1
+ // boxplot-core 1.0.0: m-boxplot's quartiles (a library part, Egatari spec §6.1): the median, the quartiles by three methods
2
+ // (jp: the median of each half, leaving out the median when n is odd — 中2・数学Ⅰ; inc / exc: spreadsheet QUARTILE.INC /
3
+ // QUARTILE.EXC) and the 1.5 × IQR fences. Pure functions of their arguments: no DOM, no state. m-boxplot 2.0.0 requires it;
4
+ // tools/test-stats.mjs tests it. Moved verbatim from m-boxplot 1.13.0 (its `static stats`).
5
+ // returns {sorted, at, median, quartiles, fences, clean}
6
+ egatariParts.define({name: "boxplot-core", version: "1.0.0", requires: {}}, function(){
7
+ "use strict";
8
+ function sorted(a){ return a.slice().sort(function(x, y){ return x - y; }); }
9
+ function clean(v){ return +(+v).toFixed(10); }
10
+ // 並べた値 s の、0 から数えた位置 h(小数なら前後の値の間を比で分ける)の値
11
+ function at(s, h){ var lo = Math.floor(h + 1e-9), f = h - lo; return clean(f > 1e-9 ? s[lo] + f * (s[lo + 1] - s[lo]) : s[lo]); }
12
+ function median(a){ var s = sorted(a); return at(s, (s.length - 1) / 2); }
13
+ // 四分位数。iq1 imed iq3 は並べた値の中の位置(0 から。x.5 なら 2 つの値の間)、halves は jp の前半・後半の位置の範囲
14
+ function quartiles(values, method){
15
+ var s = sorted(values), n = s.length;
16
+ if (!n) throw new Error("m-boxplot: a group has no values");
17
+ var imed = (n - 1) / 2, iq1, iq3, halves = null;
18
+ if (!method || method === "jp"){
19
+ var m = Math.floor(n / 2);
20
+ if (m === 0){ iq1 = iq3 = 0; }
21
+ else { iq1 = (m - 1) / 2; iq3 = n - m + (m - 1) / 2; halves = [[0, m - 1], [n - m, n - 1]]; }
22
+ } else if (method === "inc"){ iq1 = (n - 1) * 0.25; iq3 = (n - 1) * 0.75; }
23
+ else if (method === "exc"){
24
+ iq1 = (n + 1) * 0.25 - 1; iq3 = (n + 1) * 0.75 - 1;
25
+ if (iq1 < -1e-9 || iq3 > n - 1 + 1e-9) throw new Error('m-boxplot: method="exc" needs 3 or more values (like QUARTILE.EXC)');
26
+ } else throw new Error('m-boxplot: method="' + method + '" is not jp, inc or exc');
27
+ return {n: n, sorted: s, min: s[0], q1: at(s, iq1), med: at(s, imed), q3: at(s, iq3), max: s[n - 1], iq1: iq1, imed: imed, iq3: iq3, halves: halves};
28
+ }
29
+ // 外れ値:第1四分位数 − 1.5 × 四分位範囲 より小さいか、第3四分位数 + 1.5 × 四分位範囲 より大きい値。ひげはその内側の最小・最大まで
30
+ function fences(q, values){
31
+ var r = q.q3 - q.q1, lo = clean(q.q1 - 1.5 * r), hi = clean(q.q3 + 1.5 * r), s = sorted(values);
32
+ var inside = s.filter(function(v){ return v >= lo && v <= hi; });
33
+ return {lo: lo, hi: hi, wlo: inside.length ? inside[0] : q.q1, whi: inside.length ? inside[inside.length - 1] : q.q3,
34
+ out: s.filter(function(v){ return v < lo || v > hi; })};
35
+ }
36
+ return {sorted: sorted, at: at, median: median, quartiles: quartiles, fences: fences, clean: clean};
37
+ });
@@ -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,382 @@
1
+ // m-matrix 2.1.0: a comparison matrix in two forms (handoff #64; 2.1 for the positioning types, handoff #71).
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; {"self": "one sentence"} adds this work's finding under it),
5
+ // and an empty cell shows — with a note number; the notes ("trivial", "meaningless", "not yet done") stand under the table.
6
+ // A third axis is a mark after a study's name (†, ‡) explained by "marks". "design" adds a small table under the cross
7
+ // (the design of the data or the identification, earlier work against this work, and what it made possible).
8
+ // Steps (order "build", default): the axes and the empty grid → the earlier studies → this work's cell, framed → the notes
9
+ // of the empty cells. order "whole": everything at step 1.
10
+ // kind "attributes": rows are studies (this work first), columns their elements (aim, setting, input, output, criterion …),
11
+ // a cell a short text (✓ △ × too). A column may name where it comes from ({"name", "source"}: the source stands over the
12
+ // name, so a reader sees the requirement was not picked to suit this work). order "whole" (default), "col" (a column per
13
+ // step) or "row" (a row per step); the row marked self is framed at the last step. "marks" explains the symbols under the
14
+ // table ("— not stated" too).
15
+ // Headers: a cross table names its axes once (the row axis in the corner, the column axis over its values); the readable
16
+ // table (data-readable, the final state) writes each header as "axis: value". Cells are data-part boxes and their texts
17
+ // 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
18
+ // reports size with what it needs. Colours: grid --line, headers --fg bold, this work's frame --emph, notes, sources and
19
+ // dashes --muted.
20
+ egatariParts.define({name: "matrix", version: "2.1.0", requires: {base: "1.3.0"}, element: "m-matrix"}, function(deps){
21
+ "use strict";
22
+ var base = deps.base;
23
+ var T = {ja: {self: "本研究", note: "注", sep: ":", label: "表:", none: "該当なし", source: "出どころ"},
24
+ en: {self: "This work", note: "Note ", sep: ": ", label: "Table: ", none: "none", source: "From"}};
25
+ var STR = {type: "string"};
26
+ var CELL = {type: ["array", "object"]};
27
+ var WRAP = 11; // a wrapped text's line before the table is measured, in full-width characters (a half-width one counts 0.55)
28
+ var units = function(t){ var w = 0; for (var i = 0; i < t.length; i++) w += t.charCodeAt(i) < 0x100 ? 0.55 : 1; return w; };
29
+ // lines no wider than maxW by measure: "\n" breaks where the author wants; otherwise between characters as Japanese text
30
+ // breaks, but never inside a run of Latin letters or digits, nor between a number and the word after it ("7 割"), nor
31
+ // before 、。)」 (they stay on the line before); a 、 or 。 late in the line is the break when there is one
32
+ var TOKEN = /[A-Za-z0-9.,%+\-\/]+(?: [^\sA-Za-z0-9、。,.)」])?[、。,.)」]*|\S[、。,.・)」]*|\s+/g;
33
+ // a better break than the last character that fits: after 、 or 。 in the later 40 % of the line, else where hiragana gives way
34
+ // to a kanji, katakana or a digit (after a particle: 「割は|学校の」) in its later half; -1 when there is none
35
+ var HIRA = /[\u3041-\u309f]/, WORD = /[\u4e00-\u9fff\u30a0-\u30ffA-Za-z0-9]/;
36
+ function breakAt(t){
37
+ var n = t.length, i;
38
+ for (i = n - 1; i >= n * 0.6; i--) if (/[、。,.]/.test(t[i - 1]) && i < n) return i;
39
+ for (i = n - 1; i >= n * 0.5; i--) if (HIRA.test(t[i - 1]) && (WORD.test(t[i]) || (t[i] === " " && WORD.test(t[i + 1] || "")))) return i;
40
+ return -1;
41
+ }
42
+ function wrap(s, maxW, measure){
43
+ measure = measure || units; maxW = maxW || WRAP;
44
+ var out = [];
45
+ String(s).split("\n").forEach(function(part){
46
+ var cur = "", toks = part.match(TOKEN) || [];
47
+ toks.forEach(function(tok){
48
+ if (/^\s+$/.test(tok)) { if (cur) cur += " "; return; }
49
+ if (!cur || measure(cur + tok) <= maxW) { cur += tok; return; }
50
+ var line = cur.replace(/ +$/, ""), rest = "", p = breakAt(line + tok);
51
+ if (p > 0 && p < line.length) { rest = line.slice(p).replace(/^ +/, ""); line = line.slice(0, p).replace(/ +$/, ""); }
52
+ out.push(line); cur = rest + tok;
53
+ });
54
+ out.push(cur.replace(/ +$/, ""));
55
+ });
56
+ return out;
57
+ }
58
+ // the marks under the table: one line when they are short (a legend of symbols), else a line each
59
+ function markLines(marks, ja){
60
+ var items = marks.map(function(m){ return String(m.mark) + " " + String(m.text); });
61
+ var one = items.join(ja ? " " : " "), w = 0;
62
+ for (var i = 0; i < one.length; i++) w += one.charCodeAt(i) < 0x100 ? 0.55 : 1;
63
+ return (items.length > 1 && w <= 40 ? [one] : items).map(function(t){ return {text: t, step: 1}; });
64
+ }
65
+ return class extends base.MotionElement {
66
+ static partName = "matrix";
67
+ static shape = {
68
+ schema: {type: "object", additionalProperties: false, properties: {
69
+ kind: {type: "string", enum: ["cross", "attributes"]},
70
+ rows: {type: ["object", "array"]},
71
+ cols: {type: ["object", "array"]},
72
+ cells: {type: "array", maxItems: 4, items: {type: "array", maxItems: 4, items: CELL}},
73
+ marks: {type: "array", maxItems: 4, items: {type: "object", additionalProperties: false, required: ["mark", "text"], properties: {mark: STR, text: STR}}},
74
+ design: {type: "object", additionalProperties: false, required: ["cols", "rows"], properties: {
75
+ cols: {type: "array", minItems: 2, maxItems: 3, items: STR},
76
+ rows: {type: "array", minItems: 1, maxItems: 3, items: {type: "object", additionalProperties: false, required: ["cells"], properties: {
77
+ label: STR, self: {type: "boolean"}, cells: {type: "array", items: STR}}}}}},
78
+ self: STR}},
79
+ example: {kind: "cross", rows: {axis: "評価基準", values: ["予測誤差", "ベイズリスク"]}, cols: {axis: "予測の形", values: ["点予測", "分布予測"]},
80
+ cells: [[["[1]", "[2]"], ["[3]"]], [{none: "自明"}, {self: true}]]},
81
+ note: {en: "cross: rows, cols {\"axis\", \"values\"}; cells[r][c] study names, {\"self\": true or \"finding\"} or {\"none\": \"why\"}; design {\"cols\", \"rows\"}. attributes: cols names or {\"name\", \"source\"}, rows {\"label\", \"cells\", \"self\"?}",
82
+ ja: "cross:rows・cols は {\"axis\", \"values\"}、cells[r][c] は研究の名前の並び・{\"self\": true か \"結論\"}・{\"none\": \"理由\"}、design は {\"cols\", \"rows\"}。attributes:cols は名前か {\"name\", \"source\"}、rows は {\"label\", \"cells\", \"self\"?}"},
83
+ };
84
+ static props = {
85
+ order: {type: "string", default: "", doc: "出し方:cross は build(既定)・whole、attributes は whole(既定)・col・row"},
86
+ dur: {type: "number", default: 0.6, doc: "1 ステップの秒数"},
87
+ size: {type: "number", default: 28, doc: "字の大きさ(px、24 以上。入らなければ 24 まで縮める)"},
88
+ };
89
+ get steps(){
90
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
91
+ return this.plan().steps;
92
+ }
93
+ // the cells and when each appears; from the data alone
94
+ plan(){
95
+ if (this._plan) return this._plan;
96
+ var d = this.data || {}, bad = [], ja = !/^en\b/i.test(this.closest && this.closest("[lang]") ? this.closest("[lang]").getAttribute("lang") : "ja");
97
+ var L = ja ? T.ja : T.en, selfText = d.self || L.self, kind = d.kind || "cross", order = this.props.order;
98
+ var cells = [], notes = [], grid = {}, steps = 0, selfBox = null;
99
+ var cell = function(r, c, lines, o){ var x = Object.assign({r: r, c: c, lines: lines, step: 0}, o || {}); cells.push(x); if (!x.dz) grid[r + "," + c] = x; return x; };
100
+ var marks = Array.isArray(d.marks) ? d.marks : [];
101
+ var nr, nc, head;
102
+ if (kind === "cross") {
103
+ var R = d.rows && !Array.isArray(d.rows) ? d.rows : {}, C = d.cols && !Array.isArray(d.cols) ? d.cols : {};
104
+ var rv = Array.isArray(R.values) ? R.values.map(String) : [], cv = Array.isArray(C.values) ? C.values.map(String) : [];
105
+ 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)");
106
+ if (order && order !== "build" && order !== "whole") bad.push("order for cross is build or whole, not " + order);
107
+ var whole = order === "whole";
108
+ // grid: row 0 = the column axis's name over its values, row 1 = the column values; column 0 = the row values
109
+ nr = rv.length + 2; nc = cv.length + 1; head = {rows: 2, cols: 1};
110
+ cell(0, 0, [String(R.axis || "")], {head: true, corner: true, span: [2, 1]});
111
+ cell(0, 1, [String(C.axis || "")], {head: true, span: [1, cv.length]});
112
+ cv.forEach(function(v, j){ cell(1, j + 1, [v], {head: true}); });
113
+ rv.forEach(function(v, i){ cell(i + 2, 0, [v], {head: true}); });
114
+ var cs = Array.isArray(d.cells) ? d.cells : [];
115
+ 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)");
116
+ // build: the studies at 1, this work at 2 (when there is one), the notes at the last step (when there are any)
117
+ var anySelf = cs.some(function(row){ return Array.isArray(row) && row.some(function(v){ return v && typeof v === "object" && !Array.isArray(v) && v.self; }); });
118
+ 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; }); });
119
+ var sSelf = whole ? 1 : 2, sNote = whole ? 1 : anySelf ? 3 : 2;
120
+ steps = whole ? 1 : 1 + (anySelf ? 1 : 0) + (anyNote ? 1 : 0);
121
+ rv.forEach(function(_, i){ cv.forEach(function(_, j){
122
+ var v = (cs[i] || [])[j], r = i + 2, c = j + 1, obj = v && typeof v === "object" && !Array.isArray(v);
123
+ if (Array.isArray(v) && v.length) {
124
+ if (v.length > 3) bad.push("cell " + (i + 1) + "," + (j + 1) + " lists " + v.length + " studies; at most 3 (pick the main ones)");
125
+ cell(r, c, v.slice(0, 3).map(String), {step: 1});
126
+ } else if (obj && v.self) {
127
+ if (selfBox) bad.push("only one cell is this work's (self)");
128
+ var claim = typeof v.self === "string" && v.self.trim() ? wrap(v.self.trim(), WRAP) : [];
129
+ if (claim.length > 4) bad.push("this work's sentence takes " + claim.length + " lines; at most 4 (about 40 characters: the finding, not the method)");
130
+ var x = cell(r, c, [selfText].concat(claim.slice(0, 4), (Array.isArray(v.studies) ? v.studies : []).map(String)), {step: sSelf, self: !selfBox,
131
+ text: claim.length ? v.self.trim() : "", pre: [selfText], post: (Array.isArray(v.studies) ? v.studies : []).map(String), maxLines: 4});
132
+ if (!selfBox) selfBox = x;
133
+ } else if (obj && typeof v.none === "string" && v.none) {
134
+ notes.push(v.none);
135
+ cell(r, c, ["— " + L.note + notes.length], {step: sNote, dash: true, note: notes.length});
136
+ } else {
137
+ cell(r, c, ["—"], {step: 1, dash: true});
138
+ }
139
+ }); });
140
+ // the design rows under the cross: a header row, then the rows (earlier work with the studies, this work with its cell)
141
+ var design = null, Dz = d.design && typeof d.design === "object" ? d.design : null;
142
+ if (Dz) {
143
+ var dcols = Array.isArray(Dz.cols) ? Dz.cols.map(String) : [], drows = Array.isArray(Dz.rows) ? Dz.rows : [];
144
+ if (dcols.length < 2 || dcols.length > 3) bad.push("design needs 2 or 3 cols");
145
+ if (drows.length < 1 || drows.length > 3) bad.push("design needs 1 to 3 rows");
146
+ if (dcols.length >= 2 && dcols.length <= 3 && drows.length >= 1 && drows.length <= 3) {
147
+ design = {nr: drows.length + 1, nc: dcols.length + 1, cols: dcols, rows: []};
148
+ cell(0, 0, [""], {dz: true, head: true});
149
+ dcols.forEach(function(s, j){ cell(0, j + 1, wrap(s, WRAP + 2), {dz: true, head: true, text: s}); });
150
+ drows.forEach(function(row, i){
151
+ row = row && typeof row === "object" ? row : {};
152
+ var dc = Array.isArray(row.cells) ? row.cells : [], st = row.self ? sSelf : 1;
153
+ if (dc.length !== dcols.length) bad.push("design row " + (i + 1) + " has " + dc.length + " cells; design.cols has " + dcols.length);
154
+ var lab = row.label ? String(row.label) : row.self ? selfText : "";
155
+ cell(i + 1, 0, lab ? wrap(lab, WRAP) : [""], {dz: true, head: true, step: st, self: !!row.self});
156
+ dcols.forEach(function(_, j){
157
+ var s = dc[j] === undefined || dc[j] === null || dc[j] === "" ? "—" : String(dc[j]);
158
+ cell(i + 1, j + 1, wrap(s, WRAP + 2), {dz: true, step: st, dash: s === "—", text: s});
159
+ });
160
+ design.rows.push({label: lab, cells: dcols.map(function(_, j){ return dc[j] === undefined || dc[j] === null || dc[j] === "" ? "—" : String(dc[j]); }), self: !!row.self, step: st});
161
+ });
162
+ if (!whole && !anySelf && design.rows.some(function(r){ return r.self; })) {
163
+ // a self design row without a self cell: it comes after the studies all the same
164
+ steps = Math.max(steps, sSelf);
165
+ }
166
+ }
167
+ }
168
+ var below = markLines(marks, ja)
169
+ .concat(notes.map(function(t, i){ return {text: L.note + (i + 1) + L.sep + t, step: sNote}; }));
170
+ 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,
171
+ design: design, rv: rv, cv: cv, raxis: String(R.axis || ""), caxis: String(C.axis || "")});
172
+ }
173
+ if (kind !== "attributes") bad.push("kind is cross or attributes");
174
+ if (d.design) bad.push("design is for kind cross");
175
+ var colsIn = Array.isArray(d.cols) ? d.cols : [], rows = Array.isArray(d.rows) ? d.rows : [];
176
+ var cols = colsIn.map(function(v){ return v && typeof v === "object" ? String(v.name || "") : String(v); });
177
+ var sources = colsIn.map(function(v){ return v && typeof v === "object" && v.source ? String(v.source) : ""; });
178
+ var anySource = sources.some(Boolean);
179
+ if (cols.length < 1 || cols.length > 6) bad.push("attributes needs 1 to 6 cols");
180
+ if (rows.length < 1 || rows.length > 10) bad.push("attributes needs 1 to 10 rows");
181
+ order = order || "whole";
182
+ if (["whole", "col", "row"].indexOf(order) < 0) { bad.push("order for attributes is whole, col or row, not " + order); order = "whole"; }
183
+ var hr = anySource ? 2 : 1;
184
+ nr = rows.length + hr; nc = cols.length + 1; head = {rows: hr, cols: 1};
185
+ var selfRow = -1;
186
+ rows.forEach(function(r, i){ if (r && r.self && selfRow < 0) selfRow = i; });
187
+ var groups = order === "whole" ? 1 : order === "col" ? cols.length : rows.length;
188
+ steps = groups + (selfRow >= 0 && order !== "whole" ? 1 : 0);
189
+ var colStep = function(j){ return order === "col" ? j + 1 : 0; };
190
+ if (anySource) {
191
+ // the sources stand over the names, with their column
192
+ cell(0, 0, [L.source], {head: true, corner: true, muted: true});
193
+ sources.forEach(function(s, j){ cell(0, j + 1, s ? wrap(s, WRAP) : [""], {muted: true, step: colStep(j), text: s}); });
194
+ }
195
+ cell(hr - 1, 0, [""], {head: true, corner: true});
196
+ cols.forEach(function(v, j){ cell(hr - 1, j + 1, [v], {head: true}); });
197
+ rows.forEach(function(r, i){
198
+ r = r && typeof r === "object" ? r : {};
199
+ var cs = Array.isArray(r.cells) ? r.cells : [];
200
+ if (cs.length !== cols.length) bad.push("row " + (i + 1) + " has " + cs.length + " cells; cols has " + cols.length);
201
+ var at = function(j){ return order === "whole" ? 1 : order === "col" ? j + 1 : i + 1; };
202
+ cell(i + hr, 0, [String(r.label || "")], {head: true, step: order === "row" ? i + 1 : 0, self: i === selfRow});
203
+ cols.forEach(function(_, j){
204
+ var v = cs[j], s = v === undefined || v === null || v === "" ? "—" : String(v);
205
+ cell(i + hr, j + 1, [s], {step: at(j), dash: s === "—"});
206
+ });
207
+ });
208
+ var belowA = markLines(marks, ja);
209
+ return (this._plan = {kind: kind, L: L, bad: bad, cells: cells, grid: grid, nr: nr, nc: nc, head: head, steps: steps, selfRow: selfRow,
210
+ selfStep: selfRow >= 0 ? (order === "whole" ? 1 : steps) : 0, below: belowA, cols: cols, sources: anySource ? sources : null,
211
+ rowsLabels: rows.map(function(r){ return String((r || {}).label || ""); })});
212
+ }
213
+ mount(ctx){
214
+ var self = this, P = this.props, D = base, pl = this.plan();
215
+ this.style.display = "block"; this.style.position = "relative";
216
+ var W = this.clientWidth, H = this.clientHeight;
217
+ if (!(P.dur >= 0)) { ctx.report("attr", "[matrix] dur must be ≥ 0; using 0.6"); P.dur = 0.6; }
218
+ if (!(P.size >= 24)) { ctx.report("attr", "[matrix] size must be ≥ 24; using 28"); P.size = 28; }
219
+ pl.bad.forEach(function(m){ ctx.report("data", "[matrix] " + m); });
220
+ if (pl.bad.length && (pl.nr < 2 || pl.nc < 2)) return; // nothing to draw a grid from
221
+ // sizes: the largest font from size down to 24 at which the table fits; else 24 and a size report
222
+ var fit = null;
223
+ for (var fs = Math.round(P.size); fs >= 24 && !fit; fs -= 2) fit = this._fit(fs, W, H);
224
+ if (!fit) {
225
+ var g24 = this._fit(24, W, H, true);
226
+ 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)");
227
+ fit = g24;
228
+ }
229
+ var G = this.geo = fit, fsz = G.fs;
230
+ 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);
231
+ 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);
232
+ var xs = G.xs, ys = G.ys, x0 = xs[0], y0 = ys[0], hr = pl.head.rows, hc = pl.head.cols;
233
+ // grid: thick under the header rows and right of the header column; the column-axis row has no vertical lines inside its span
234
+ for (var r = 0; r <= pl.nr; r++) {
235
+ var xa = pl.kind === "cross" && r === 1 ? xs[1] : x0;
236
+ 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);
237
+ }
238
+ for (var c = 0; c <= pl.nc; c++) {
239
+ var ya = pl.kind === "cross" && c >= 2 && c < pl.nc ? ys[1] : y0;
240
+ 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);
241
+ }
242
+ var dxs = G.dxs, dys = G.dys, dz = pl.design;
243
+ if (dz) {
244
+ for (var r2 = 0; r2 <= dz.nr; r2++) D.el("line", {x1: dxs[0], x2: dxs[dz.nc], y1: dys[r2], y2: dys[r2], stroke: "var(--line)", "stroke-width": r2 === 1 ? 2.5 : 1.2}, gL);
245
+ for (var c2 = 0; c2 <= dz.nc; c2++) D.el("line", {x1: dxs[c2], x2: dxs[c2], y1: dys[0], y2: dys[dz.nr], stroke: "var(--line)", "stroke-width": c2 === 1 ? 2.5 : 1.2}, gL);
246
+ }
247
+ var lh = Math.ceil(fsz * 1.3), pad = G.pad;
248
+ this.cellEls = pl.cells.map(function(x, ci){
249
+ var X = x.dz ? dxs : xs, Y = x.dz ? dys : ys;
250
+ var sp = x.span || [1, 1], cx0 = X[x.c], cx1 = X[x.c + sp[1]], cy0 = Y[x.r], cy1 = Y[x.r + sp[0]];
251
+ var id = (x.dz ? "d" : "m") + x.r + "-" + x.c, g = D.el("g", {}, gT);
252
+ 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);
253
+ var ls = G.lines[ci], left = x.head && x.c === 0, n = ls.length, top = (cy0 + cy1) / 2 - (n - 1) * lh / 2 + fsz * 0.36;
254
+ ls.forEach(function(s, i){
255
+ if (!s) return;
256
+ var t = D.el("text", {x: (left ? cx0 + pad : (cx0 + cx1) / 2).toFixed(1), y: (top + i * lh).toFixed(1), "font-size": fsz,
257
+ "text-anchor": left ? "start" : "middle", fill: x.dash || x.muted ? "var(--muted)" : "var(--fg)", "font-weight": x.head && !x.muted || (x.self && i === 0) ? 700 : 400,
258
+ "data-part": "label", "data-part-id": id, "data-part-of": "box"}, g);
259
+ t.textContent = s;
260
+ });
261
+ return {x: x, g: g};
262
+ });
263
+ // this work: the cell (cross) or the row (attributes), framed in --emph; a self design row too
264
+ var frames = [];
265
+ if (pl.selfBox) { var b = pl.selfBox; frames.push({r: [xs[b.c] + 3, ys[b.r] + 3, xs[b.c + 1] - xs[b.c] - 6, ys[b.r + 1] - ys[b.r] - 6], step: b.step}); }
266
+ else if (pl.selfRow >= 0) { var rr = pl.selfRow + hr; frames.push({r: [x0 + 3, ys[rr] + 3, xs[pl.nc] - x0 - 6, ys[rr + 1] - ys[rr] - 6], step: pl.selfStep}); }
267
+ if (dz) dz.rows.forEach(function(o, i){ if (o.self) frames.push({r: [dxs[0] + 3, dys[i + 1] + 3, dxs[dz.nc] - dxs[0] - 6, dys[i + 2] - dys[i + 1] - 6], step: o.step}); });
268
+ this.frames = frames.map(function(f){ return {step: f.step, el: D.el("rect", {x: f.r[0], y: f.r[1], width: f.r[2], height: f.r[3], rx: 5, fill: "none", stroke: "var(--emph)", "stroke-width": 4}, gF)}; });
269
+ // notes and marks under the table (under the design rows when there are any)
270
+ this.belowEls = pl.below.map(function(o, i){
271
+ var t = D.el("text", {x: x0.toFixed(1), y: (G.belowTop + 14 + fsz * 0.9 + i * Math.ceil(fsz * 1.35)).toFixed(1), "font-size": fsz, fill: "var(--fg)"}, gN);
272
+ t.textContent = o.text;
273
+ return {o: o, t: t};
274
+ });
275
+ // the readable table (data-readable): the final state, headers as "axis: value"
276
+ var tbl = document.createElement("table");
277
+ tbl.className = "sr-only"; tbl.setAttribute("data-readable", "");
278
+ tbl.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0");
279
+ 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); };
280
+ var join = function(x){ return (x.pre || []).concat(x.text ? [x.text] : [], x.post || []).join(" "); };
281
+ if (pl.kind === "cross") {
282
+ tr([pl.raxis + " \ " + pl.caxis].concat(pl.cv.map(function(v){ return pl.caxis + L.sep + v; })), true);
283
+ pl.rv.forEach(function(v, i){ tr([pl.raxis + L.sep + v].concat(pl.cv.map(function(_, j){ var x = pl.grid[(i + 2) + "," + (j + 1)]; return x.self ? join(x) : x.lines.join("、"); }))); });
284
+ if (dz) {
285
+ tr([""].concat(dz.cols), true);
286
+ dz.rows.forEach(function(o){ tr([o.label || (o.self ? L.self : "")].concat(o.cells)); });
287
+ }
288
+ } else {
289
+ if (pl.sources) tr([L.source].concat(pl.sources), true);
290
+ tr([""].concat(pl.cols), true);
291
+ pl.rowsLabels.forEach(function(v, i){ tr([v + (i === pl.selfRow ? "(" + L.self + ")" : "")].concat(pl.cols.map(function(_, j){ return pl.grid[(i + hr) + "," + (j + 1)].lines.join(" "); }))); });
292
+ }
293
+ 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); }
294
+ this.appendChild(tbl);
295
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
296
+ this.setAttribute("role", "img");
297
+ if (!this._aria) this.setAttribute("aria-label", L.label + (pl.kind === "cross" ? pl.raxis + " × " + pl.caxis : pl.cols.join(pl.L === T.ja ? "、" : ", ")));
298
+ }
299
+ // column widths and row heights at font size fs; null when the table does not fit W × H (unless force)
300
+ _fit(fs, W, H, force){
301
+ var pl = this.plan(), D = base, self = this, pad = Math.round(fs * 0.5), lh = Math.ceil(fs * 1.3);
302
+ var tw = function(s, b){ return D.textWidth(s, fs, {font: self}) * (b ? 1.06 : 1); };
303
+ var cw = [], rh = [], dz = pl.design, dcw = [], drh = [];
304
+ for (var c = 0; c < pl.nc; c++) cw[c] = fs * 2;
305
+ for (var r = 0; r < pl.nr; r++) rh[r] = Math.ceil(fs * 1.6);
306
+ if (dz) { for (var c1 = 0; c1 < dz.nc; c1++) dcw[c1] = fs * 2; for (var r1 = 0; r1 < dz.nr; r1++) drh[r1] = Math.ceil(fs * 1.6); }
307
+ pl.cells.forEach(function(x){
308
+ if (x.span && x.span[1] > 1) return;
309
+ var CW = x.dz ? dcw : cw, RH = x.dz ? drh : rh;
310
+ var w = Math.max.apply(null, x.lines.map(function(s, i){ return tw(s, (x.head && !x.muted) || (x.self && i === 0)); })) + 2 * pad;
311
+ if (w > CW[x.c]) CW[x.c] = Math.ceil(w);
312
+ });
313
+ // value columns of the same width (a matrix reads by its grid), the header column as wide as it needs
314
+ var vmax = Math.max.apply(null, cw.slice(1));
315
+ for (var c2 = 1; c2 < pl.nc; c2++) cw[c2] = vmax;
316
+ // the design rows line up with the cross: the same header column, their value columns sharing the cross's width
317
+ if (dz) { cw[0] = dcw[0] = Math.max(cw[0], dcw[0]); }
318
+ var spanW = pl.kind === "cross" ? tw(pl.caxis, true) + 2 * pad : 0;
319
+ var tableW = cw.reduce(function(a, b){ return a + b; }, 0);
320
+ 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]; }
321
+ if (dz) {
322
+ var dneed = Math.max.apply(null, dcw.slice(1)) * (dz.nc - 1);
323
+ if (dneed > tableW - cw[0]) { var add2 = (dneed - (tableW - cw[0])) / (pl.nc - 1); for (var c5 = 1; c5 < pl.nc; c5++) cw[c5] += add2; tableW = dneed + cw[0]; }
324
+ }
325
+ // spread the value columns over the width the element has, up to 1.4 times what they need
326
+ var room = W - 4 - tableW;
327
+ 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); }
328
+ if (dz) for (var c6 = 1; c6 < dz.nc; c6++) dcw[c6] = (tableW - cw[0]) / (dz.nc - 1);
329
+ // the texts that wrap (this work's sentence, the design rows, the sources) take the width their column now has; then the heights
330
+ var lines = pl.cells.map(function(x){
331
+ if (!x.text) return x.lines;
332
+ var CW = x.dz ? dcw : cw, b = !!(x.head && !x.muted);
333
+ var m = function(t){ return tw(t, b); }, full = CW[x.c] - 2 * pad, ls = wrap(x.text, full, m);
334
+ // balanced: the narrowest width that keeps the number of lines (no one-character last line)
335
+ if (ls.length > 1) {
336
+ var lo = full / ls.length, hi = full;
337
+ for (var it = 0; it < 12; it++) { var mid = (lo + hi) / 2; if (wrap(x.text, mid, m).length > ls.length) lo = mid; else hi = mid; }
338
+ ls = wrap(x.text, hi, m);
339
+ }
340
+ if (x.maxLines) ls = ls.slice(0, x.maxLines);
341
+ return (x.pre || []).concat(ls, x.post || []);
342
+ });
343
+ pl.cells.forEach(function(x, i){
344
+ if (x.span && x.span[0] > 1) return;
345
+ var RH = x.dz ? drh : rh, h = Math.ceil(lines[i].length * lh + fs * 0.5);
346
+ if (h > RH[x.r]) RH[x.r] = h;
347
+ });
348
+ var gap = dz ? Math.round(fs * 0.8) : 0, designH = dz ? gap + drh.reduce(function(a, b){ return a + b; }, 0) : 0;
349
+ 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;
350
+ var needH = tableH + designH + belowH + 8;
351
+ if (!force && (tableW > W - 2 || needH > H)) return null;
352
+ // 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)
353
+ if (needH < H) {
354
+ var nb = pl.nr - pl.head.rows, each = Math.min((H - needH) / nb, Math.min.apply(null, rh.slice(pl.head.rows)) * 0.8);
355
+ for (var r2 = pl.head.rows; r2 < pl.nr; r2++) rh[r2] += each;
356
+ tableH += each * nb; needH += each * nb;
357
+ }
358
+ var x0 = Math.max(1, (W - tableW) / 2), xs = [x0], ys = [4];
359
+ cw.forEach(function(w, i){ xs.push(xs[i] + w); });
360
+ rh.forEach(function(h, i){ ys.push(ys[i] + h); });
361
+ var tableBottom = ys[ys.length - 1], dxs = null, dys = null;
362
+ if (dz) {
363
+ dxs = [x0]; dys = [tableBottom + gap];
364
+ dcw.forEach(function(w, i){ dxs.push(dxs[i] + w); });
365
+ drh.forEach(function(h, i){ dys.push(dys[i] + h); });
366
+ }
367
+ return {fs: fs, pad: pad, lines: lines, xs: xs, ys: ys, dxs: dxs, dys: dys, tableW: tableW, needH: needH, tableBottom: tableBottom,
368
+ belowTop: dz ? dys[dys.length - 1] : tableBottom};
369
+ }
370
+ duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
371
+ render(k, t, ctx){
372
+ if (!this.cellEls) return;
373
+ var D = base, P = this.props, N = this.plan().steps, faint = ctx && (ctx.preview || ctx.mode === "lecture") ? base.previewOpacity(this) : 0;
374
+ k = Math.max(0, Math.min(k, N));
375
+ var e = k === 0 ? 1 : D.prog(t, 0, P.dur);
376
+ var op = function(st){ var v = st === 0 || st < k ? 1 : st > k ? 0 : e; return Math.max(v, st > k ? faint : 0); };
377
+ this.cellEls.forEach(function(o){ o.g.setAttribute("opacity", op(o.x.step).toFixed(3)); });
378
+ this.frames.forEach(function(f){ f.el.setAttribute("opacity", (f.step > k ? 0 : f.step < k ? 1 : e).toFixed(3)); });
379
+ this.belowEls.forEach(function(o){ o.t.setAttribute("opacity", op(o.o.step).toFixed(3)); });
380
+ }
381
+ };
382
+ });