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,214 @@
1
+ // m-folds: the validation block advances through k train/validation splits.
2
+ // 2.1.0: with `splits` (and `samples`), each sample is a cell and each row is one split from scikit-learn's splitter
3
+ // (KFold with shuffle, StratifiedKFold = クラスの比率を保つ KFold, GroupKFold, TimeSeriesSplit, a holdout): test cells as the
4
+ // validation block, train cells as before, unused cells empty; class colours and names, group runs, time order. The k mode
5
+ // draws exactly as 2.0.1.
6
+ egatariParts.define({name: "folds", version: "2.1.2", requires: {base: "1.3.0"}, element: "m-folds"}, function(deps){
7
+ "use strict";
8
+ var base = deps.base;
9
+ var TEXT = {
10
+ ja: {train: "学習(学)", validate: "検証(検・枠)", t: "学", v: "検", error: "誤差", mean: "平均", fold: "分割", unused: "使わない", cls: "クラス", group: "グループ", time: "時間 →", test: "検証", trainS: "訓練"},
11
+ en: {train: "train (T)", validate: "validate (V, outline)", t: "T", v: "V", error: "error", mean: "mean", fold: "fold", unused: "unused", cls: "class", group: "group", time: "time →", test: "validate", trainS: "train"}
12
+ };
13
+ function set(e, a, v){ e.setAttribute(a, String(v)); }
14
+ function fmt(v){ return v.toFixed(2); }
15
+ var PAL = ["var(--series-1)", "var(--series-3)", "var(--fg)", "var(--series-4)"]; // m-classify2d の CLASS_COLORS と同じ並び
16
+ return class extends base.MotionElement {
17
+ static partName = "folds";
18
+ static preview = "none";
19
+ static shape = {schema: {type: "object", additionalProperties: false, anyOf: [{required: ["k"]}, {required: ["splits"]}], properties: {
20
+ k: {type: "number"}, errors: {type: "array", items: {type: "number"}}, labels: {type: "array", items: {type: "string"}},
21
+ samples: {type: "array", minItems: 2, maxItems: 60, items: {type: "object", additionalProperties: false, properties: {class: {type: "integer"}, group: {type: "string"}, t: {type: ["number", "string"]}}}},
22
+ splits: {type: "array", minItems: 1, maxItems: 10, items: {type: "object", additionalProperties: false, required: ["test"], properties: {test: {type: "array", items: {type: "integer"}}, train: {type: "array", items: {type: "integer"}}}}},
23
+ splitter: {type: "string", enum: ["KFold", "StratifiedKFold", "GroupKFold", "TimeSeriesSplit", "ShuffleSplit", "holdout"]},
24
+ classes: {type: "array", maxItems: 4, items: {type: "object", additionalProperties: false, required: ["id"], properties: {id: {type: "integer"}, label: {type: "string"}}}}
25
+ }}, example: {k: 5, errors: [0.21, 0.18, 0.25, 0.19, 0.22], labels: ["1", "2", "3", "4", "5"]}};
26
+ static props = {
27
+ dur: {type: "number", default: 1, doc: "ステップの秒数"},
28
+ size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
29
+ };
30
+ get steps(){ if (this.data.splits) return this.data.splits.length + 1; var k = this.data.k; return Number.isInteger(k) && k >= 2 && k <= 10 ? k + 1 : 0; }
31
+ duration(k){ return k >= 1 && k <= this.steps ? this.props.dur : 0; }
32
+ label(g, x, y, s, anchor){
33
+ var e = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
34
+ e.textContent = s; return e;
35
+ }
36
+ mount(ctx){
37
+ var self = this, d = this.data, P = this.props;
38
+ this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
39
+ var T = this.T;
40
+ if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[folds] dur must be positive; using 1"); P.dur = 1; }
41
+ if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[folds] size must be 0 or at least 24; using 26"); P.size = 0; }
42
+ this.fs = P.size || 26;
43
+ this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb"; this.setAttribute("role", "img");
44
+ if (d.splits) return this.mountSamples(ctx);
45
+ if (!Number.isInteger(d.k) || d.k < 2 || d.k > 10){ ctx.report("data", "[folds] k must be an integer 2–10"); return; }
46
+ if (d.errors && (d.errors.length !== d.k || d.errors.some(function(v){ return v < 0; }))){ ctx.report("data", "[folds] errors must contain k non-negative numbers"); return; }
47
+ if (d.labels && d.labels.length !== d.k){ ctx.report("data", "[folds] labels must contain k names"); return; }
48
+ var labels = d.labels || Array.from({length: d.k}, function(_, i){ return String(i + 1); });
49
+ var errors = d.errors || null, mean = errors ? errors.reduce(function(s, v){ return s + v / d.k; }, 0) : null;
50
+ this.model = {k: d.k, labels: labels, errors: errors, mean: mean};
51
+ var summary = labels.map(function(s, i){ return T.fold + " " + (i + 1) + ": " + T.validate + " " + s + ", " + T.train + " " + labels.filter(function(_, j){ return j !== i; }).join(", ") + (errors ? "; " + T.error + " " + fmt(errors[i]) : ""); }).join("; ");
52
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", summary + (errors ? "; " + T.mean + " " + fmt(mean) : ""));
53
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = this.fs, line = fs * 1.45 + 4;
54
+ var width = function(s){ return base.textWidth(s, fs, {font: self}); };
55
+ var errorWidth = errors ? Math.max(width(T.error), width(T.mean + " " + fmt(mean)), ...errors.map(function(v){ return Math.max(width(fmt(v)), fmt(v).length * fs * 0.62); })) + 8 : 0;
56
+ var left = Math.max(42, width(String(d.k)) + 16), ex = W - errorWidth - 8, right = errors ? ex - 20 : W - 8;
57
+ var bw = (right - left) / d.k, top = 2 * line + 16;
58
+ var footer = errors ? line + fs * 0.4 : 0, minRow = Math.max(32, Math.ceil(fs * 1.2));
59
+ var minHeight = Math.ceil(top + d.k * minRow + footer + 4);
60
+ var rh = Math.max(minRow, Math.min(Math.max(44, line + 4), (H - top - footer - 4) / d.k)), bh = rh - 6;
61
+ var letters = bh >= fs * 1.43;
62
+ this.geometry = {row: rh, minRow: minRow, minHeight: minHeight, letters: letters};
63
+ // Compact row numbers/errors use a monospace font whose box fits 32px rows.
64
+ function rowLabel(g, x, y, s, anchor){
65
+ var e = self.label(g, x, y, s, anchor);
66
+ if (!letters) e.setAttribute("style", "font-family:ui-monospace, Menlo, Consolas, monospace;fill:var(--fg)");
67
+ return e;
68
+ }
69
+ this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
70
+ this.header = base.el("g", {opacity: 0}, this.svg);
71
+ function swatch(x, validate, text){
72
+ base.el("rect", {x: x, y: 8, width: 32, height: fs * 1.45, fill: validate ? "var(--emph-tint)" : "var(--term-tint)", stroke: validate ? "var(--emph)" : "none", "stroke-width": 3}, self.header);
73
+ self.label(self.header, x + 42, fs + 4, text);
74
+ }
75
+ var legend2 = 8 + 42 + width(T.train) + 28;
76
+ swatch(8, false, T.train); swatch(legend2, true, T.validate);
77
+ var legendWidth = Math.ceil(legend2 + 42 + width(T.validate) + 8);
78
+ if (legendWidth > W) ctx.report("size", "[folds] legend needs " + legendWidth + " px width; element has " + W + " px");
79
+ if (bw < 8) ctx.report("size", "[folds] " + d.k + " blocks have " + Math.floor(bw) + " px each; allow at least 8 px per block");
80
+ labels.forEach(function(s, i){
81
+ self.label(self.header, left + (i + 0.5) * bw, 2 * line, s, "middle");
82
+ if (width(s) > bw - 8) ctx.report("size", "[folds] label " + (i + 1) + " needs " + Math.ceil(width(s)) + " px; block fits " + Math.max(0, Math.floor(bw - 8)) + " px (shorten the label)");
83
+ });
84
+ if (errors) this.label(this.header, ex, 2 * line, T.error);
85
+ this.rows = labels.map(function(_, i){
86
+ var g = base.el("g", {opacity: 0}, self.svg), y = top + i * rh;
87
+ rowLabel(g, left - 12, y + bh / 2 + fs * 0.31, String(i + 1), "end");
88
+ var blocks = labels.map(function(_, j){
89
+ var valid = i === j, x = left + j * bw + 3;
90
+ var rect = base.el("rect", {x: x, y: y, width: Math.max(1, bw - 6), height: bh, rx: 3, fill: valid ? "var(--emph-tint)" : "var(--term-tint)", stroke: valid ? "var(--emph)" : "none", "stroke-width": 3}, g);
91
+ if (letters && bw - 6 >= 40) self.label(g, x + (bw - 6) / 2, y + bh / 2 + fs * 0.31, valid ? T.v : T.t, "middle");
92
+ return {rect: rect, validation: valid};
93
+ });
94
+ if (errors) rowLabel(g, ex, y + bh / 2 + fs * 0.31, fmt(errors[i]));
95
+ return {g: g, blocks: blocks};
96
+ });
97
+ this.finalLayer = base.el("g", {opacity: 0}, this.svg);
98
+ var bottom = top + d.k * rh, finalY = bottom + line;
99
+ if (errors){
100
+ base.el("line", {x1: ex, x2: W - 8, y1: bottom + 6, y2: bottom + 6, stroke: "var(--muted)", "stroke-width": 2}, this.finalLayer);
101
+ this.label(this.finalLayer, ex, finalY, T.mean + " " + fmt(mean));
102
+ }
103
+ if (H < minHeight) ctx.report("size", "[folds] k = " + d.k + " needs at least " + minHeight + " px height (header " + top.toFixed(1) + " + " + d.k + " × " + minRow + " rows + " + (footer + 4).toFixed(1) + " footer); element has " + H + " px");
104
+ }
105
+ render(k, t){
106
+ if (this.sm) return this.renderSamples(k, t);
107
+ if (!this.model) return;
108
+ var dur = this.props.dur, phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, dur); };
109
+ set(this.header, "opacity", phase(1));
110
+ this.rows.forEach(function(o, i){ set(o.g, "opacity", phase(i + 1)); });
111
+ set(this.finalLayer, "opacity", phase(this.model.k + 1));
112
+ }
113
+ // 標本のモード(2.1.0):列が標本、行が分割。データの確かめと描き方。クラスの色は --emph(検証の枠)と同じ色にならないよう
114
+ // --series-2 を飛ばす(1 つの意味に 1 つの色)。m-classify2d の CLASS_COLORS と同じ並び
115
+ mountSamples(ctx){
116
+ var self = this, d = this.data, T = this.T, sp = d.splits, kind = d.splitter || "";
117
+ var n = d.samples ? d.samples.length : 1 + Math.max.apply(null, [].concat.apply([], sp.map(function(s){ return s.test.concat(s.train || []); })).concat([0]));
118
+ var samples = d.samples || Array.from({length: n}, function(){ return {}; }), bad = [];
119
+ if (n < 2 || n > 60) bad.push("splits cover " + n + " samples; 2–60 can be drawn");
120
+ var cls = {}; (d.classes || []).forEach(function(c, i){ cls[c.id] = i; });
121
+ samples.forEach(function(s, i){ if (s.class !== undefined && !(s.class in cls)) bad.push("samples[" + i + "].class " + s.class + " is not in classes"); });
122
+ var role = sp.map(function(s, r){
123
+ var a = Array(n).fill(0), testSet = {};
124
+ s.test.forEach(function(i){ if (!(i >= 0 && i < n)) bad.push("splits[" + r + "].test has " + i + " (samples 0–" + (n - 1) + ")"); else { a[i] = 2; testSet[i] = 1; } });
125
+ (s.train || Array.from({length: n}, function(_, i){ return i; }).filter(function(i){ return !testSet[i]; })).forEach(function(i){
126
+ if (!(i >= 0 && i < n)) bad.push("splits[" + r + "].train has " + i); else if (testSet[i]) bad.push("splits[" + r + "]: sample " + i + " is in both train and test"); else a[i] = 1;
127
+ });
128
+ return a;
129
+ });
130
+ // 分け方の決まり:KFold の仲間は、どの標本もちょうど 1 回だけ検証に入る
131
+ var kfold = !kind || kind === "KFold" || kind === "StratifiedKFold" || kind === "GroupKFold";
132
+ if (kfold){
133
+ for (var i = 0; i < n; i++){ var c = role.filter(function(a){ return a[i] === 2; }).length; if (c !== 1){ bad.push("sample " + i + " is in the test set of " + c + " splits; " + (kind || "KFold") + " uses each sample once (set splitter for TimeSeriesSplit, ShuffleSplit or holdout)"); break; } }
134
+ }
135
+ if (kind === "GroupKFold") role.forEach(function(a, r){ var tr = {}, te = {}; a.forEach(function(v, i){ var g = samples[i].group; if (v === 1) tr[g] = 1; if (v === 2) te[g] = 1; }); Object.keys(te).forEach(function(g){ if (tr[g]) bad.push("splits[" + r + "]: group \"" + g + "\" is in both train and test (GroupKFold keeps a group together)"); }); });
136
+ if (kind === "TimeSeriesSplit") role.forEach(function(a, r){ var lastTrain = a.lastIndexOf(1), firstTest = a.indexOf(2); if (lastTrain > firstTest && firstTest >= 0) bad.push("splits[" + r + "]: a train sample comes after a test sample (TimeSeriesSplit trains on the past)"); });
137
+ if (kind === "holdout" && sp.length !== 1) bad.push("holdout has one split; got " + sp.length);
138
+ if (kind === "StratifiedKFold") role.forEach(function(a, r){
139
+ // クラスの比率を保つ:検証に入る各クラスの数が、全体の数 ÷ 分割数から 1 未満しかずれない
140
+ Object.keys(cls).forEach(function(c){ var tot = samples.filter(function(s){ return String(s.class) === c; }).length, got = a.filter(function(v, i){ return v === 2 && String(samples[i].class) === c; }).length; if (Math.abs(got - tot / sp.length) >= 1) bad.push("splits[" + r + "]: class " + c + " has " + got + " test samples; StratifiedKFold keeps about " + +(tot / sp.length).toFixed(2)); });
141
+ });
142
+ if (d.errors && (d.errors.length !== sp.length || d.errors.some(function(v){ return v < 0; }))) bad.push("errors must contain one non-negative number per split");
143
+ bad.forEach(function(s){ ctx.report("data", "[folds] " + s); });
144
+ if (bad.length && bad.some(function(s){ return /samples 0–|2–60|errors must/.test(s); })) return;
145
+ var errors = d.errors && d.errors.length === sp.length ? d.errors : null, mean = errors ? errors.reduce(function(s, v){ return s + v / errors.length; }, 0) : null;
146
+ this.sm = {n: n, role: role, errors: errors, mean: mean};
147
+ var used = role.some(function(a){ return a.indexOf(0) >= 0; });
148
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", (kind ? kind + ": " : "") + role.map(function(a, r){ return T.fold + " " + (r + 1) + ": " + T.test + " " + a.map(function(v, i){ return v === 2 ? i + 1 : null; }).filter(Boolean).join(", ") + (errors ? "; " + T.error + " " + fmt(errors[r]) : ""); }).join("; ") + (errors ? "; " + T.mean + " " + fmt(mean) : ""));
149
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = this.fs, line = Math.ceil(fs * 1.45 + 4);
150
+ var width = function(s){ return base.textWidth(s, fs, {font: self}); };
151
+ var hasCls = samples.some(function(s){ return s.class !== undefined; }), hasGrp = samples.some(function(s){ return s.group !== undefined; }), hasT = samples.some(function(s){ return s.t !== undefined; });
152
+ var errorWidth = errors ? Math.max(width(T.error), width(T.mean + " " + fmt(mean)), width("0.00")) + 8 : 0;
153
+ var stripLab = Math.max(hasCls ? width(T.cls) : 0, hasGrp ? width(T.group) : 0, width(String(sp.length))) + 16;
154
+ var left = Math.max(42, stripLab), ex = W - errorWidth - 8, right = errors ? ex - 20 : W - 8, cw = (right - left) / n;
155
+ var strips = (hasCls ? 1 : 0) + (hasGrp ? 1 : 0) + (hasT ? 1 : 0), top = line + 8 + strips * line;
156
+ var footer = errors ? line + 8 : 4, rh = Math.max(28, Math.min(Math.ceil(fs * 2.6), (H - top - footer) / sp.length)), bh = rh - 6;
157
+ if (cw < 6) ctx.report("size", "[folds] " + n + " samples have " + cw.toFixed(1) + " px each; allow at least 6 px per sample (a wider element or fewer samples)");
158
+ if (H < top + sp.length * 28 + footer) ctx.report("size", "[folds] " + sp.length + " splits need at least " + Math.ceil(top + sp.length * 28 + footer) + " px height; element has " + H + " px");
159
+ this.geometry = {cell: cw, row: rh, top: top};
160
+ var svg = this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
161
+ var head = this.header = base.el("g", {opacity: 0}, svg);
162
+ // 凡例:学習・検証(・使わない)・クラスの名前(右へ並べる)
163
+ var x = 8, item = function(fill, stroke, text, dash){ base.el("rect", {x: x, y: 8, width: 28, height: fs * 1.2, fill: fill, stroke: stroke || "none", "stroke-width": 3, "stroke-dasharray": dash ? "4 3" : null}, head); self.label(head, x + 36, fs + 4, text); x += 36 + width(text) + 24; };
164
+ item("var(--term-tint)", null, T.trainS); item("var(--emph-tint)", "var(--emph)", T.test);
165
+ if (used) item("var(--bg)", "var(--line)", T.unused, true);
166
+ (d.classes || []).forEach(function(c, i){ base.el("circle", {cx: x + 10, cy: 8 + fs * 0.6, r: 9, fill: PAL[i]}, head); self.label(head, x + 26, fs + 4, c.label || String(c.id)); x += 26 + width(c.label || String(c.id)) + 24; });
167
+ if (x > W) ctx.report("size", "[folds] the legend needs " + Math.ceil(x) + " px width; element has " + W + " px");
168
+ var sy = line + 8;
169
+ if (hasCls){
170
+ self.label(head, left - 12, sy + fs * 0.85, T.cls, "end");
171
+ samples.forEach(function(s, i){ if (s.class !== undefined) base.el("rect", {x: left + i * cw + 1, y: sy + 4, width: Math.max(1, cw - 2), height: line - 12, fill: PAL[cls[s.class] || 0]}, head); });
172
+ sy += line;
173
+ }
174
+ if (hasGrp){
175
+ self.label(head, left - 12, sy + fs * 0.85, T.group, "end");
176
+ // 同じグループの続き:枠で囲み、入れば名前
177
+ var i0 = 0;
178
+ for (var i = 1; i <= n; i++) if (i === n || samples[i].group !== samples[i0].group){
179
+ base.el("rect", {x: left + i0 * cw + 1, y: sy + 4, width: Math.max(1, (i - i0) * cw - 2), height: line - 12, fill: "none", stroke: "var(--muted)", "stroke-width": 2, rx: 4}, head);
180
+ var gname = samples[i0].group === undefined ? "" : String(samples[i0].group);
181
+ // 名前は枠(sy + 4 から line − 12)の縦の中ほどに:基線を sy + 0.85 字にすると、字の上が枠から 5 px 出ていた(Studio の svgTextBox、handoff #45)
182
+ if (gname && width(gname) <= (i - i0) * cw - 8) self.label(head, left + (i0 + (i - i0) / 2) * cw, sy + 4 + (line - 12) / 2 + fs * 0.35, gname, "middle");
183
+ i0 = i;
184
+ }
185
+ sy += line;
186
+ }
187
+ if (hasT){
188
+ self.label(head, left, sy + fs * 0.85, String(samples[0].t !== undefined ? samples[0].t : ""));
189
+ var tEnd = String(samples[n - 1].t !== undefined ? samples[n - 1].t : "");
190
+ self.label(head, right, sy + fs * 0.85, tEnd, "end");
191
+ var mid = left + (right - left) / 2, tw0 = width(T.time);
192
+ if (width(String(samples[0].t)) + width(tEnd) + tw0 + 48 <= right - left) self.label(head, mid, sy + fs * 0.85, T.time, "middle");
193
+ }
194
+ if (errors) this.label(head, ex, top - 8, T.error);
195
+ this.rows = role.map(function(a, r){
196
+ var g = base.el("g", {opacity: 0}, svg), y = top + r * rh;
197
+ self.label(g, left - 12, y + bh / 2 + fs * 0.31, String(r + 1), "end");
198
+ a.forEach(function(v, i){
199
+ base.el("rect", {x: left + i * cw + 1, y: y, width: Math.max(1, cw - 2), height: bh, rx: Math.max(0, Math.min(3, cw / 4)), fill: v === 2 ? "var(--emph-tint)" : v === 1 ? "var(--term-tint)" : "var(--bg)", stroke: v === 2 ? "var(--emph)" : v === 0 ? "var(--line)" : "none", "stroke-width": v === 2 ? 2.5 : 1.5, "stroke-dasharray": v === 0 ? "4 3" : null}, g);
200
+ });
201
+ if (errors) self.label(g, ex, y + bh / 2 + fs * 0.31, fmt(errors[r]));
202
+ return {g: g};
203
+ });
204
+ this.finalLayer = base.el("g", {opacity: 0}, svg);
205
+ if (errors){ var bottom = top + sp.length * rh; base.el("line", {x1: ex, x2: W - 8, y1: bottom + 2, y2: bottom + 2, stroke: "var(--muted)", "stroke-width": 2}, this.finalLayer); this.label(this.finalLayer, ex, bottom + line - 4, T.mean + " " + fmt(mean)); }
206
+ }
207
+ renderSamples(k, t){
208
+ var dur = this.props.dur, n = this.sm.role.length, phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, dur); };
209
+ set(this.header, "opacity", phase(1));
210
+ this.rows.forEach(function(o, i){ set(o.g, "opacity", phase(i + 1)); });
211
+ set(this.finalLayer, "opacity", phase(n + 1));
212
+ }
213
+ };
214
+ });