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,289 @@
1
+ // m-sampling: population → sample → simulated sampling distribution.
2
+ egatariParts.define({name: "sampling", version: "2.0.2", requires: {base: "1.3.0", plot: "1.1.3"}, element: "m-sampling"}, function(deps){
3
+ "use strict";
4
+ var base = deps.base;
5
+ var TEXT = {
6
+ ja: {population: "母集団", sample: "標本", distribution: "標本分布", with: "戻す(復元抽出)", without: "戻さない(非復元抽出)", mean: "平均", proportion: "の割合", meanAxis: "標本平均", proportionAxis: "標本比率", statsMean: "標本統計量の平均", caption: function(n, r){ return "n = " + n + "、" + r + " 回"; }},
7
+ en: {population: "population", sample: "Sample", distribution: "Sampling distribution", with: "with replacement", without: "without replacement", mean: "Mean", proportion: " proportion", meanAxis: "Sample mean", proportionAxis: "Sample proportion", statsMean: "mean of sample statistics", caption: function(n, r){ return "n = " + n + ", " + r + " samples"; }}
8
+ };
9
+ var OBJ = {white: "#ffffff", black: "#222222", red: "#d62728", green: "#2ca02c", yellow: "#f2c12e", blue: "#1f77b4", brown: "#8c564b", purple: "#9467bd", pink: "#e377c2", orange: "#ff7f0e", gray: "#7f7f7f"};
10
+ var OBJ_NAME = {"白": "white", "黒": "black", "赤": "red", "緑": "green", "黄": "yellow", "青": "blue", "茶": "brown", "紫": "purple", "桃": "pink", "橙": "orange", "灰": "gray",
11
+ "白色": "white", "黒色": "black", "赤色": "red", "緑色": "green", "黄色": "yellow", "青色": "blue", "茶色": "brown", "紫色": "purple", "桃色": "pink", "橙色": "orange", "灰色": "gray", "ピンク": "pink", "オレンジ": "orange", "グレー": "gray", "grey": "gray"};
12
+ function objColor(name){
13
+ var k = String(name).trim(), lower = k.toLowerCase(), own = Object.prototype.hasOwnProperty;
14
+ var en = own.call(OBJ, lower) ? lower : own.call(OBJ_NAME, k) ? OBJ_NAME[k] : own.call(OBJ_NAME, lower) ? OBJ_NAME[lower] : null;
15
+ return en ? "var(--obj-" + en + ", " + OBJ[en] + ")" : null;
16
+ }
17
+ // Mulberry32; the only mutable random state lives in mount's local generator.
18
+ function random(seed){
19
+ return function(){
20
+ seed = (seed + 0x6D2B79F5) | 0;
21
+ var z = Math.imul(seed ^ seed >>> 15, 1 | seed);
22
+ z ^= z + Math.imul(z ^ z >>> 7, 61 | z);
23
+ return ((z ^ z >>> 14) >>> 0) / 4294967296;
24
+ };
25
+ }
26
+ function set(e, a, v){ e.setAttribute(a, String(v)); }
27
+ function mean(values){
28
+ var scale = Math.max.apply(null, values.map(function(v){ return Math.abs(v); }).concat([1]));
29
+ var average = values.reduce(function(s, v){ return s + v / scale; }, 0) / values.length;
30
+ return Math.max(-1, Math.min(1, average)) * scale;
31
+ }
32
+ function meanTicks(lo, hi, values){
33
+ if (lo === hi) return [lo];
34
+ if (hi - lo <= 10 && values.every(Number.isInteger)) return Array.from({length: hi - lo + 1}, function(_, i){ return lo + i; });
35
+ var scale = Math.max(1, Math.abs(lo), Math.abs(hi));
36
+ var rough = Math.max(Number.MIN_VALUE, (hi / scale - lo / scale) / 4 * scale);
37
+ var power = Math.pow(10, Math.floor(Math.log10(rough))) || Number.MIN_VALUE, fraction = rough / power;
38
+ var step = (fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10) * power;
39
+ var start = Math.ceil(lo / step), ticks = [];
40
+ for (var i = 0; i < 10; i++){
41
+ var v = (start + i) * step;
42
+ if (!Number.isFinite(v) || v > hi + step * 1e-10) break;
43
+ ticks.push(v);
44
+ }
45
+ return ticks;
46
+ }
47
+ return class extends base.MotionElement {
48
+ static partName = "sampling";
49
+ static preview = "none";
50
+ static steps = 4;
51
+ static shape = {
52
+ schema: {type: "object", additionalProperties: false, required: ["n"], anyOf: [{required: ["balls"]}, {required: ["values"]}], properties: {
53
+ balls: {type: "object"}, values: {type: "array", minItems: 2, maxItems: 30, items: {type: "number"}},
54
+ of: {type: "string"}, n: {type: "number"}, replace: {type: "boolean"}, repeat: {type: "number"}, seed: {type: "number"},
55
+ stat: {enum: ["mean", "proportion"]}, digits: {type: "number"}
56
+ }},
57
+ example: {values: [1, 2, 3, 4, 5, 6], n: 2, replace: true, repeat: 40, seed: 3}
58
+ };
59
+ static props = {
60
+ dur: {type: "number", default: 1, doc: "ステップの秒数"},
61
+ stagger: {type: "number", default: 0.25, doc: "抽出のずれ(秒)"},
62
+ fast: {type: "number", default: 2.5, doc: "反復の秒数"},
63
+ size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
64
+ };
65
+ timing(name, fallback, zero){ var v = this.props[name]; return Number.isFinite(v) && (zero ? v >= 0 : v > 0) ? v : fallback; }
66
+ duration(k){
67
+ if (k < 1 || k > 4) return 0;
68
+ if (k === 4) return this.timing("fast", 2.5);
69
+ var n = this.model ? this.model.n : Math.max(1, Math.min(30, Math.round(this.data.n)));
70
+ return this.timing("dur", 1) + (k === 2 ? (n - 1) * this.timing("stagger", 0.25, true) : 0);
71
+ }
72
+ fmt(v){ return v.toFixed(this.model.digits); }
73
+ label(g, x, y, s, anchor){
74
+ var t = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
75
+ t.textContent = s; return t;
76
+ }
77
+ mount(ctx){
78
+ var self = this, d = this.data, P = this.props;
79
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
80
+ var T = this.T;
81
+ [["dur", 1, false], ["stagger", 0.25, true], ["fast", 2.5, false]].forEach(function(a){
82
+ if (self.timing(a[0], -1, a[2]) === -1){ ctx.report("attr", "[sampling] invalid " + a[0] + "; using " + a[1]); P[a[0]] = a[1]; }
83
+ });
84
+ if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[sampling] size must be 0 or at least 24; using 26"); P.size = 0; }
85
+ this.fs = P.size || 26;
86
+ this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
87
+ this.setAttribute("role", "img");
88
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight);
89
+ var items = [], composition = [], balls = d.balls !== undefined;
90
+ var invalid = balls && d.values !== undefined;
91
+ if (balls){
92
+ Object.keys(d.balls).forEach(function(name){
93
+ var count = d.balls[name], col = objColor(name);
94
+ if (!col) ctx.report("data", "[sampling] unknown colour " + name + "; drawn as gray with its name");
95
+ if (!Number.isInteger(count) || count < 0 || count > 30){ invalid = true; return; }
96
+ composition.push(name + " " + count);
97
+ for (var i = 0; i < count; i++) items.push({label: name, color: col || objColor("gray")});
98
+ });
99
+ } else {
100
+ items = d.values.map(function(v){ return {label: String(v), value: v}; });
101
+ composition = items.map(function(o){ return o.label; });
102
+ }
103
+ if (invalid || items.length < 2 || items.length > 30){
104
+ ctx.report("data", "[sampling] supply exactly one population: 2–30 values or balls with non-negative integer counts totalling 2–30");
105
+ this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
106
+ this.label(this.svg, 8, this.fs + 4, T.population + ": 2–30");
107
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": 2–30");
108
+ return;
109
+ }
110
+ function integer(key, fallback, lo, hi){
111
+ var v = d[key] === undefined ? fallback : d[key];
112
+ if (!Number.isInteger(v) || v < lo || v > hi){
113
+ v = Math.max(lo, Math.min(hi, Math.round(v)));
114
+ ctx.report("data", "[sampling] " + key + " must be an integer " + lo + "–" + hi + "; clamped to " + v);
115
+ }
116
+ return v;
117
+ }
118
+ var stat = balls ? "proportion" : "mean", of = d.of === undefined ? (balls ? Object.keys(d.balls)[0] : "") : d.of;
119
+ if (d.stat !== undefined && d.stat !== stat) ctx.report("data", "[sampling] stat=" + d.stat + " is incompatible with this population; using " + stat);
120
+ if (balls && !Object.prototype.hasOwnProperty.call(d.balls, of)) ctx.report("data", "[sampling] of=" + of + " is absent from the population; proportion is zero");
121
+ var n = integer("n", 1, 1, d.replace ? 30 : items.length), repeat = integer("repeat", 40, 1, 200), digits = integer("digits", 2, 0, 10);
122
+ var seed = d.seed === undefined ? 1 : d.seed;
123
+ if (!Number.isSafeInteger(seed)){ ctx.report("data", "[sampling] seed must be a safe integer; using 1"); seed = 1; }
124
+ function statistic(sample){
125
+ return balls ? sample.filter(function(id){ return items[id].label === of; }).length / sample.length : mean(sample.map(function(id){ return items[id].value; }));
126
+ }
127
+ var rng = random(seed), samples = [];
128
+ for (var r = 0; r < repeat; r++){
129
+ var pool = items.map(function(_, i){ return i; }), ids = [];
130
+ for (var j = 0; j < n; j++){
131
+ var at = Math.floor(rng() * pool.length); ids.push(pool[at]);
132
+ if (!d.replace) pool.splice(at, 1);
133
+ }
134
+ samples.push({ids: ids, value: statistic(ids)});
135
+ }
136
+ this.model = {items: items, samples: samples, n: n, repeat: repeat, digits: digits, replace: !!d.replace, stat: stat, of: of,
137
+ population: statistic(items.map(function(_, i){ return i; })), average: mean(samples.map(function(o){ return o.value; }))};
138
+ var m = this.model, rule = m.replace ? T.with : T.without;
139
+ this.composition = composition.join(T === TEXT.ja ? "・" : ", ");
140
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": " + this.composition + "; " + rule + "; " + T.caption(n, repeat) + "; " + T.population + " " + this.fmt(m.population) + "; " + T.statsMean + " " + this.fmt(m.average));
141
+ // Source Sans 3's SVG box is 1.43em tall, including its descender.
142
+ var fs = this.fs, line = fs * 1.45 + 4, width = function(s){ return base.textWidth(s, fs, {font: self}) + 8; };
143
+ var left = W * 0.24, middle = W * 0.38, sx = left + 22, px = left + middle + 48, pw = Math.max(1, W - px - 22);
144
+ // Plot supplies the numerical mapping and axis; normalized values avoid overflow.
145
+ var vals = items.map(function(o){ return o.value; }), lo = balls ? 0 : Math.min.apply(null, vals), hi = balls ? 1 : Math.max.apply(null, vals);
146
+ var scale = Math.max(1, Math.abs(lo), Math.abs(hi)), a = lo / scale, b = hi / scale;
147
+ var captionY = H - fs * 0.4 - 4, axisY = captionY - 3 * line;
148
+ var plotTop = fs + 4 + fs * 0.4 + 8, plotH = axisY - plotTop;
149
+ var plot = deps.plot.Plot(this, {xr: a === b ? [a - 1, b + 1] : [a, b], yr: [0, 1], xt: [], yt: [], noY: true,
150
+ m: {l: px + 12, r: W - px - 12 - Math.max(1, pw - 24), t: plotTop, b: H - axisY}});
151
+ this.svg = plot.svg;
152
+ set(this.svg, "width", W); set(this.svg, "height", H); set(this.svg, "aria-hidden", "true");
153
+ var axes = [].filter.call(this.svg.children, function(e){ return e.getAttribute("class") === "axes"; })[0];
154
+ this.svg.removeChild(axes);
155
+ var X = function(v){ return plot.x(v / scale); };
156
+ this.populationLayer = base.el("g", {opacity: 0}, this.svg);
157
+ this.sampleLayer = base.el("g", {opacity: 0}, this.svg);
158
+ this.plotLayer = base.el("g", {opacity: 0}, this.svg);
159
+ this.plotLayer.appendChild(axes);
160
+ this.finalLayer = base.el("g", {opacity: 0}, this.plotLayer);
161
+ this.label(this.populationLayer, 8, fs + 4, T.population);
162
+ this.label(this.sampleLayer, sx, fs + 4, T.sample);
163
+ this.label(this.plotLayer, px, fs + 4, T.distribution);
164
+ var small = false, itemW = Math.max(52, ...items.map(function(o){ return width(o.label) + (balls ? 36 : 16); }));
165
+ var cols = Math.max(1, Math.min(items.length, Math.floor((left - 24) / itemW))), rows = Math.ceil(items.length / cols), rowH = Math.max(48, line);
166
+ var bagTop = line + 10, bagBottom = bagTop + rows * rowH + 12;
167
+ base.el("rect", {x: 4, y: bagTop, width: Math.max(1, left - 8), height: bagBottom - bagTop, rx: 18, fill: "none", stroke: "var(--fg)", "stroke-width": 2}, this.populationLayer);
168
+ function item(g, o){
169
+ var shape = base.el(balls ? "circle" : "rect", balls ? {cx: 14, cy: 0, r: 12, fill: o.color, stroke: "var(--fg)", "stroke-width": 2} : {x: 0, y: -rowH / 2 + 3, width: itemW - 8, height: rowH - 6, rx: 6, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 2}, g);
170
+ var text = self.label(g, balls ? 34 : (itemW - 8) / 2, fs * 0.312, o.label, balls ? "start" : "middle");
171
+ return {g: g, shape: shape, text: text};
172
+ }
173
+ this.originals = items.map(function(o, i){
174
+ var x = 14 + (i % cols) * itemW, y = bagTop + 8 + rowH / 2 + Math.floor(i / cols) * rowH;
175
+ var q = item(base.el("g", {transform: "translate(" + x + " " + y + ")"}, self.populationLayer), o); q.x = x; q.y = y; return q;
176
+ });
177
+ // Wrap word groups below the bag; reserve a full font box between baselines.
178
+ var y = bagBottom;
179
+ if (balls){
180
+ // Keep separators inside the string: width padding must not add spaces around ・.
181
+ var words = "";
182
+ composition.forEach(function(s){
183
+ var joined = words ? words + (T === TEXT.ja ? "・" : ", ") + s : s;
184
+ if (words && width(joined) > left - 16){ y += line; self.label(self.populationLayer, 8, y, words); words = s; }
185
+ else words = joined;
186
+ if (width(s) > left - 16) small = true;
187
+ });
188
+ y += line; self.label(self.populationLayer, 8, y, words);
189
+ }
190
+ var rules = width(rule) <= left - 16 ? [rule] : (T === TEXT.ja ? [m.replace ? "戻す" : "戻さない", m.replace ? "(復元抽出)" : "(非復元抽出)"] : rule.split(" "));
191
+ rules.forEach(function(s){ y += line; self.label(self.populationLayer, 8, y, s); if (width(s) > left - 16) small = true; });
192
+ if (y + fs * 0.4 + 4 > H || itemW > left - 24) small = true;
193
+ var sampleY = bagTop + rowH / 2 + 8, sampleW = n * itemW;
194
+ if (sampleW > middle - 10) small = true;
195
+ this.drawn = Array.from({length: n}, function(_, j){ var q = item(base.el("g", {}, self.sampleLayer), items[samples[0].ids[j]]); q.x = sx + j * itemW; q.y = sampleY; return q; });
196
+ this.statLayer = base.el("g", {opacity: 0}, this.sampleLayer);
197
+ var statY = sampleY + rowH / 2 + line;
198
+ this.statName = this.label(this.statLayer, sx, statY, balls ? of + T.proportion : T.mean);
199
+ this.statValue = this.label(this.statLayer, sx, statY + line, "");
200
+ var statLabel = balls ? of + T.proportion : T.mean;
201
+ if (width(statLabel) > middle - 10 || statY + line + fs * 0.4 > H) small = true;
202
+ var ticks = balls ? [0, 0.25, 0.5, 0.75, 1] : meanTicks(lo, hi, vals), lastRight = -Infinity;
203
+ ticks.forEach(function(v){
204
+ var xx = X(v), rounded = +v.toPrecision(4), s = Number.isFinite(rounded) ? String(rounded) : String(v), w = width(s);
205
+ base.el("line", {x1: xx, x2: xx, y1: axisY, y2: axisY + 7, stroke: "var(--fg)", "stroke-width": 2}, self.plotLayer);
206
+ var anchor = v === lo ? "start" : v === hi ? "end" : "middle";
207
+ var tx = anchor === "start" ? xx : anchor === "end" ? xx - w : xx - w / 2;
208
+ if (tx < lastRight + 4) small = true; lastRight = tx + w;
209
+ self.label(self.plotLayer, xx, axisY + line, s, anchor);
210
+ });
211
+ this.label(this.plotLayer, px, axisY + 2 * line, balls ? T.proportionAxis : T.meanAxis);
212
+ this.label(this.finalLayer, px, captionY, T.caption(n, repeat));
213
+ var markerLabel = T.population + " " + this.fmt(m.population);
214
+ var markerY = fs + 4 + line, markerRight = px + width(markerLabel);
215
+ this.label(this.finalLayer, px, markerY, markerLabel);
216
+ var markerBottom = markerY + fs * 0.4 + 8;
217
+ base.el("line", {x1: X(m.population), x2: X(m.population), y1: markerBottom, y2: axisY, stroke: "var(--emph)", "stroke-width": 2, "stroke-dasharray": "6 5"}, this.finalLayer);
218
+ // Stack horizontally intersecting dots at separate levels, preserving exact numerical x.
219
+ function stack(radius){
220
+ var levels = [];
221
+ return samples.map(function(o){
222
+ var xx = X(o.value), lv = 0;
223
+ while (levels[lv] && levels[lv].some(function(v){ return Math.abs(v - xx) < 2 * radius + 2; })) lv++;
224
+ if (!levels[lv]) levels[lv] = []; levels[lv].push(xx);
225
+ return {x: xx, level: lv};
226
+ });
227
+ }
228
+ // The marker label occupies only the plot's upper-left corner, not a whole row.
229
+ // A 1px gap between circle fills leaves more room for repeated values.
230
+ function fits(positions, radius){
231
+ return positions.every(function(o){
232
+ var top = axisY - 2 * radius - 3 - o.level * (2 * radius + 1);
233
+ return top >= (o.x - radius < markerRight && o.x + radius > px ? markerBottom : plotTop);
234
+ });
235
+ }
236
+ var radius = 8, positions;
237
+ while (true){
238
+ positions = stack(radius);
239
+ if (fits(positions, radius) || radius === 5) break;
240
+ radius--;
241
+ }
242
+ if (!fits(positions, radius)) ctx.report("size", "[sampling] dot stack exceeds plot at minimum 5px radius; increase height or reduce repeat");
243
+ this.dots = positions.map(function(o){
244
+ var yy = axisY - radius - 3 - o.level * (2 * radius + 1);
245
+ return {x: o.x, y: yy, el: base.el("circle", {cx: o.x, cy: yy, r: radius, fill: "var(--term)", stroke: "var(--fg)", "stroke-width": 1, opacity: 0}, self.plotLayer)};
246
+ });
247
+ this.plotTop = plotTop;
248
+ if ([T.distribution, markerLabel, T.caption(n, repeat), balls ? T.proportionAxis : T.meanAxis].some(function(s){ return width(s) > pw; }) || plotH < 40) small = true;
249
+ if (small) ctx.report("size", "[sampling] population, sample row or plot labels do not fit; enlarge the element or shorten names");
250
+ // Check all statistic strings, since a later sample can be wider than the first.
251
+ if (samples.some(function(o){ return width(self.statText(o)) > middle - 10; })) ctx.report("size", "[sampling] statistic does not fit; enlarge width or reduce digits");
252
+ }
253
+ statText(sample){
254
+ var m = this.model;
255
+ return (m.stat === "proportion" ? sample.ids.filter(function(i){ return m.items[i].label === m.of; }).length + "/" + m.n + " = " : "") + this.fmt(sample.value);
256
+ }
257
+ render(k, t){
258
+ if (!this.model) return;
259
+ var self = this, m = this.model, P = this.props;
260
+ var phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, P.dur); };
261
+ set(this.populationLayer, "opacity", phase(1));
262
+ set(this.sampleLayer, "opacity", k >= 2 ? 1 : 0);
263
+ set(this.statLayer, "opacity", phase(3));
264
+ set(this.plotLayer, "opacity", phase(3));
265
+ var progress = k > 4 ? 1 : k < 4 ? 0 : Math.max(0, Math.min(1, t / P.fast));
266
+ var completed = k < 3 ? 0 : k === 3 ? (t >= P.dur ? 1 : 0) : 1 + Math.floor(progress * (m.repeat - 1));
267
+ var rep = k >= 4 ? Math.min(m.repeat - 1, completed - 1) : 0, sample = m.samples[rep];
268
+ var full = k >= 4 && progress === 1 || k === 3 && t >= P.dur;
269
+ this.originals.forEach(function(o, i){
270
+ var j = sample.ids.indexOf(i), gone = !m.replace && j >= 0 && !full && (k >= 3 || k === 2 && t > j * P.stagger);
271
+ set(o.g, "opacity", gone ? 0 : 1);
272
+ });
273
+ this.drawn.forEach(function(o, j){
274
+ var id = sample.ids[j], original = self.originals[id], e = k > 2 ? 1 : k < 2 ? 0 : base.prog(t, j * P.stagger, P.dur);
275
+ set(o.g, "opacity", k >= 2 && (k > 2 || t > j * P.stagger) ? 1 : 0);
276
+ set(o.g, "transform", "translate(" + base.lerp(original.x, o.x, e) + " " + base.lerp(original.y, o.y, e) + ")");
277
+ o.text.textContent = m.items[id].label;
278
+ if (m.stat === "proportion") set(o.shape, "style", "fill:" + m.items[id].color + ";stroke:var(--fg)");
279
+ });
280
+ this.statValue.textContent = this.statText(sample);
281
+ this.dots.forEach(function(o, i){
282
+ var drop = i === 0 && k === 3 ? base.prog(t, 0, P.dur) : 1;
283
+ set(o.el, "opacity", i < completed || i === 0 && k === 3 && t > 0 ? 1 : 0);
284
+ set(o.el, "cy", base.lerp(self.plotTop, o.y, drop));
285
+ });
286
+ set(this.finalLayer, "opacity", k >= 4 && progress === 1 ? 1 : 0);
287
+ }
288
+ };
289
+ });