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,214 @@
1
+ // m-contour:2 変数の関数の等高線。等高線を値ごとに引き、勾配の矢印(と接線)、勾配降下法などの反復の道を 1 点ずつ。
2
+ // 関数は式 f(expr:算術だけの式。コードとしては動かさない)か、スクリプトが格子の上で計算した値 grid のどちらか。
3
+ // <m-contour style="height:440px"><script type="application/json">
4
+ // {"f": "x**2 + 3*y**2", "range": {"x": [-3, 3], "y": [-2, 2]}, "levels": [1, 2, 4, 8],
5
+ // "gradient": {"at": [[1, 1]]}, "path": [[2.5, 1.5], [1.5, 0.3], [0.9, 0.06]], "monotone": true}
6
+ // (JSON の終わり)</m-contour>
7
+ // 色:等高線 --term、値の名前 --fg(地の色の縁取り)、勾配の矢印 --accent2(接線は --muted の破線)、反復の道 --fg、今の点 --emph。
8
+ egatariParts.define({name: "contour", version: "2.0.1", requires: {base: "1.3.0", expr: "1.0.0", "contour-core": "1.0.0"}, element: "m-contour"}, function(deps){
9
+ "use strict";
10
+ var base = deps.base, D = base, expr = deps.expr, K = deps["contour-core"], clipN = 0;
11
+ var NUM = {type: "number"}, R2 = {type: "array", minItems: 2, maxItems: 2, items: NUM}, P2 = {type: "array", minItems: 2, maxItems: 2, items: NUM};
12
+ var SAMPLE = {nx: 97, ny: 73};
13
+ var T = {
14
+ ja: {iter: function(i, v){ return "反復 " + i + ":f = " + v; }, summary: function(n, lv){ return "等高線の図:値 " + lv.join("、") + (n ? "、反復 " + n + " 回の道" : ""); }, grad: "勾配"},
15
+ en: {iter: function(i, v){ return "iteration " + i + ": f = " + v; }, summary: function(n, lv){ return "Contour plot: levels " + lv.join(", ") + (n ? "; a path of " + n + " iterations" : ""); }, grad: "gradient"}
16
+ };
17
+ function nice(lo, hi, n){
18
+ var span = hi - lo, raw = span / Math.max(1, n), p = Math.pow(10, Math.floor(Math.log10(raw))), m = raw / p, st = (m < 1.5 ? 1 : m < 3 ? 2 : m < 7 ? 5 : 10) * p, out = [];
19
+ for (var v = Math.ceil(lo / st - 1e-9) * st; v <= hi + 1e-9 * span; v += st) out.push(Math.abs(v) < st * 1e-9 ? 0 : v);
20
+ return {ticks: out, step: st};
21
+ }
22
+ function fmt(v, st){ var d = Math.max(0, -Math.floor(Math.log10(st) + 1e-9)); var s = v.toFixed(Math.min(4, d)); return s.indexOf("-") === 0 ? "−" + s.slice(1) : s; }
23
+ function num(v){ var a = Math.abs(v), s = a >= 100 ? a.toFixed(0) : a >= 1 ? +a.toFixed(3) + "" : +a.toPrecision(3) + ""; return (v < 0 && +s !== 0 ? "−" : "") + s; }
24
+ return class extends base.MotionElement {
25
+ static partName = "contour";
26
+ static preview = "none";
27
+ static shape = {schema: {type: "object", additionalProperties: false, required: ["range", "levels"], anyOf: [{required: ["f"]}, {required: ["grid"]}], properties: {
28
+ f: {type: "string"}, label: {type: "string"},
29
+ grid: {type: "object", additionalProperties: false, required: ["nx", "ny", "values"], properties: {nx: {type: "integer"}, ny: {type: "integer"}, values: {type: "array"}}},
30
+ range: {type: "object", additionalProperties: false, required: ["x", "y"], properties: {x: R2, y: R2}},
31
+ axes: {type: "object", additionalProperties: false, properties: {x: {type: "string"}, y: {type: "string"}}},
32
+ levels: {type: "array", minItems: 1, maxItems: 8, items: NUM},
33
+ gradient: {type: "object", additionalProperties: false, required: ["at"], properties: {at: {type: "array", minItems: 1, maxItems: 6, items: P2}, scale: NUM, tangent: {type: "boolean"}}},
34
+ path: {type: "array", minItems: 1, maxItems: 30, items: P2},
35
+ monotone: {type: "boolean"},
36
+ equal: {type: "boolean"}
37
+ }}, example: /*@egatari-block example*/{"f":"x**2 + 3*y**2","range":{"x":[-3,3],"y":[-2,2]},"levels":[1,2,4,8],"gradient":{"at":[[1,1]]},"path":[[2.5,1.5],[1.5,0.3],[0.9,0.06]],"monotone":true}/*@egatari-block-end*/};
38
+ static props = {
39
+ dur: {type: "number", default: 0.8, doc: "1 ステップの秒数"},
40
+ size: {type: "number", default: 24, doc: "字の大きさ(px、24 以上)"},
41
+ by: {type: "enum", values: ["level", "all"], default: "level", doc: "等高線を値ごとに 1 ステップ(level)か、まとめて 1 ステップ(all)"}
42
+ };
43
+ get steps(){ return this.plan().steps.length; }
44
+ duration(k){ return k >= 1 && k <= this.plan().steps.length ? this.props.dur : 0; }
45
+ plan(){
46
+ if (this._plan) return this._plan;
47
+ var d = this.data || {}, bad = [], fn = null, rx = d.range.x, ry = d.range.y, values = null, nx, ny;
48
+ if (d.f !== undefined && d.grid) bad.push("give f or grid, not both");
49
+ if (!(rx[1] > rx[0] && ry[1] > ry[0])) bad.push("range.x and range.y are [min, max] with min < max");
50
+ if (d.f !== undefined && !d.grid){
51
+ try { var g = expr.compile(d.f, {name: "f", vars: ["x", "y"], bareMath: true}); fn = function(x, y){ var v = g(x, y); return typeof v === "number" ? v : NaN; }; }
52
+ catch (e){ bad.push("f: " + (e && e.message || e)); fn = function(){ return NaN; }; }
53
+ nx = SAMPLE.nx; ny = SAMPLE.ny; values = [];
54
+ for (var j = 0; j < ny; j++){ var row = []; for (var i = 0; i < nx; i++) row.push(fn(rx[0] + (rx[1] - rx[0]) * i / (nx - 1), ry[0] + (ry[1] - ry[0]) * j / (ny - 1))); values.push(row); }
55
+ } else if (d.grid){
56
+ nx = d.grid.nx; ny = d.grid.ny; values = d.grid.values;
57
+ var okg = nx >= 2 && ny >= 2 && nx <= 200 && ny <= 200 && Array.isArray(values) && values.length === ny && values.every(function(r){ return Array.isArray(r) && r.length === nx && r.every(function(v){ return typeof v === "number"; }); });
58
+ if (!okg){ bad.push("grid.values must be ny × nx numbers (2–200 each; row 0 is the smallest y)"); values = [[0, 0], [0, 0]]; nx = ny = 2; }
59
+ // 格子の値の双一次補間(勾配と道の f に使う)
60
+ fn = function(x, y){
61
+ var u = (x - rx[0]) / (rx[1] - rx[0]) * (nx - 1), w = (y - ry[0]) / (ry[1] - ry[0]) * (ny - 1);
62
+ if (!(u >= 0 && u <= nx - 1 && w >= 0 && w <= ny - 1)) return NaN;
63
+ var i0 = Math.min(nx - 2, Math.floor(u)), j0 = Math.min(ny - 2, Math.floor(w)), a = u - i0, b = w - j0;
64
+ return values[j0][i0] * (1 - a) * (1 - b) + values[j0][i0 + 1] * a * (1 - b) + values[j0 + 1][i0] * (1 - a) * b + values[j0 + 1][i0 + 1] * a * b;
65
+ };
66
+ }
67
+ var lv = d.levels.slice().sort(function(a, b){ return a - b; }), steps = [];
68
+ var hx = (rx[1] - rx[0]) / (d.grid ? Math.max(1, nx - 1) : 1e4), hy = (ry[1] - ry[0]) / (d.grid ? Math.max(1, ny - 1) : 1e4);
69
+ var grad = function(x, y){ return [(fn(x + hx, y) - fn(x - hx, y)) / (2 * hx), (fn(x, y + hy) - fn(x, y - hy)) / (2 * hy)]; };
70
+ var grads = d.gradient ? d.gradient.at.map(function(p){ return {p: p, g: grad(p[0], p[1])}; }) : [];
71
+ grads.forEach(function(o, i){ if (!o.g.every(Number.isFinite)) bad.push("gradient.at[" + i + "] is outside the range or where f is not defined"); });
72
+ var fp = (d.path || []).map(function(p){ return fn(p[0], p[1]); });
73
+ if (d.monotone) fp.forEach(function(v, i){ if (i && v > fp[i - 1] + 1e-12 * Math.max(1, Math.abs(v))) bad.push("path: f goes up at iteration " + i + " (" + num(fp[i - 1]) + " → " + num(v) + ") but monotone is true"); });
74
+ fp.forEach(function(v, i){ if (!Number.isFinite(v)) bad.push("path[" + i + "] is outside the range or where f is not defined"); });
75
+ if (this.props && this.props.by === "all") steps.push({kind: "levels", levels: lv});
76
+ else lv.forEach(function(l){ steps.push({kind: "levels", levels: [l]}); });
77
+ if (grads.length) steps.push({kind: "gradient"});
78
+ (d.path || []).forEach(function(_, i){ steps.push({kind: "path", i: i}); });
79
+ return (this._plan = {d: d, bad: bad, values: values, nx: nx, ny: ny, levels: lv, steps: steps, grads: grads, fp: fp, rx: rx, ry: ry});
80
+ }
81
+ mount(ctx){
82
+ var self = this, P = this.props, pl, ja = /^ja\b/i.test(ctx.lang || "ja"), L = ja ? T.ja : T.en;
83
+ if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[contour] dur must be positive; using 0.8"); P.dur = 0.8; }
84
+ if (!(Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[contour] size must be at least 24; using 24"); P.size = 24; }
85
+ if (["level", "all"].indexOf(P.by) < 0){ ctx.report("attr", "[contour] by must be level or all; using level"); P.by = "level"; }
86
+ this._plan = null; pl = this.plan(); var d = pl.d;
87
+ pl.bad.forEach(function(s){ ctx.report("data", "[contour] " + s); });
88
+ this.L = L;
89
+ this.style.display = "block"; this.style.position = "relative";
90
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = P.size, rx = pl.rx, ry = pl.ry;
91
+ var tw = function(s){ return base.textWidth(s, fs, {font: self}); }, top = Math.ceil(fs * 2.1);
92
+ // 目盛りの数は、描く大きさから(数の幅と字の高さが入る間隔)
93
+ var ty = nice(ry[0], ry[1], Math.max(2, Math.min(5, Math.floor((H - top - 2 * fs) / (2.2 * fs)))));
94
+ var yTickW = Math.max.apply(null, ty.ticks.map(function(v){ return tw(fmt(v, ty.step)); }).concat([0]));
95
+ var m = {l: Math.ceil(yTickW) + 14, r: 12, t: top + 6, b: Math.ceil(fs * 1.3) + 6};
96
+ var aw = Math.max(1, W - m.l - m.r), ah = Math.max(1, H - m.t - m.b), pw = aw, ph = ah;
97
+ if (d.equal !== false){ var s = Math.min(aw / (rx[1] - rx[0]), ah / (ry[1] - ry[0])); pw = s * (rx[1] - rx[0]); ph = s * (ry[1] - ry[0]); }
98
+ // 縦と横をそろえて横が余るときは、図を左に寄せ、右を欄にする(関数の名前と、反復ごとの f の値)
99
+ var side = W - m.l - pw - 32 >= 240, px = side ? m.l : m.l + (aw - pw) / 2, py = m.t;
100
+ if (pw < 160 || ph < 120) ctx.report("size", "[contour] element is " + W + " × " + H + " px; allow at least " + Math.ceil(m.l + m.r + 160) + " × " + Math.ceil(m.t + m.b + 120) + " px");
101
+ var X = function(x){ return px + (x - rx[0]) / (rx[1] - rx[0]) * pw; }, Y = function(y){ return py + (ry[1] - y) / (ry[1] - ry[0]) * ph; };
102
+ var tx = nice(rx[0], rx[1], Math.max(2, Math.min(6, Math.floor(pw / (tw("−0.00") + 24)))));
103
+ this.geo = {X: X, Y: Y, px: px, py: py, pw: pw, ph: ph, fs: fs, top: top};
104
+ this.setAttribute("role", "img");
105
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
106
+ if (!this._aria) this.setAttribute("aria-label", (d.label ? d.label.replace(/[*]/g, "").replace(/[_^]/g, "") + "; " : "") + L.summary((d.path || []).length ? d.path.length - 1 : 0, pl.levels.map(num)));
107
+ var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
108
+ var cid = "contour-2-0-0-clip" + (++clipN);
109
+ D.el("rect", {x: px, y: py, width: pw, height: ph}, D.el("clipPath", {id: cid}, D.el("defs", {}, svg)));
110
+ var plot = D.el("g", {"clip-path": "url(#" + cid + ")"}, svg);
111
+ var gridG = D.el("g", {}, plot);
112
+ tx.ticks.forEach(function(v){ D.el("line", {x1: X(v), y1: py, x2: X(v), y2: py + ph, stroke: "var(--line)", "stroke-width": 1, opacity: 0.6}, gridG); });
113
+ ty.ticks.forEach(function(v){ D.el("line", {x1: px, y1: Y(v), x2: px + pw, y2: Y(v), stroke: "var(--line)", "stroke-width": 1, opacity: 0.6}, gridG); });
114
+ D.el("rect", {x: px, y: py, width: pw, height: ph, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, svg);
115
+ // 軸の名前は、添え字(*w*_1)があれば 32px 以上で組む(mtext の添え字は 24px より小さくしないので、本文が 24px だと同じ大きさに見える)
116
+ var axFs = function(t){ return /(^|[^\\])[_^]./.test(t) ? Math.max(fs, 32) : fs; };
117
+ var xLabW = d.axes && d.axes.x ? base.textWidth(d.axes.x.replace(/[*_^]/g, ""), axFs(d.axes.x), {font: self}) + 12 : 0;
118
+ tx.ticks.forEach(function(v){ var s = fmt(v, tx.step); if (X(v) + tw(s) / 2 > px + pw - xLabW) return; D.el("text", {x: X(v), y: py + ph + fs + 2, "font-size": fs, "text-anchor": "middle", fill: "var(--muted)"}, svg).textContent = s; });
119
+ ty.ticks.forEach(function(v){ if (v === ty.ticks[0] && Math.abs(v - ry[0]) < 1e-9 * (ry[1] - ry[0])) return; D.el("text", {x: px - 8, y: Y(v) + fs * 0.35, "font-size": fs, "text-anchor": "end", fill: "var(--muted)"}, svg).textContent = fmt(v, ty.step); });
120
+ if (d.axes && d.axes.x) D.mtext(svg, px + pw, py + ph + fs + 2, d.axes.x, {"font-size": axFs(d.axes.x), "text-anchor": "end", fill: "var(--fg)"});
121
+ if (d.axes && d.axes.y) D.mtext(svg, px, top - fs * 0.35, d.axes.y, {"font-size": axFs(d.axes.y), fill: "var(--fg)"});
122
+ // 上の行:右に関数の名前(label)、反復の値はそこに替わる
123
+ var yLabW = d.axes && d.axes.y ? base.textWidth(d.axes.y.replace(/[*_^]/g, ""), axFs(d.axes.y), {font: self}) + 24 : 0;
124
+ this.titleG = D.el("g", {}, svg); this.side = side; this.iterRows = [];
125
+ if (side){
126
+ var sx0 = px + pw + 32, sw = W - sx0 - m.r, row = Math.ceil(fs * 1.5), y0 = py + fs;
127
+ if (d.label){ D.mtext(this.titleG, sx0, y0, d.label, {"font-size": fs, fill: "var(--fg)"}); y0 += row * 1.3; if (tw(d.label.replace(/[*_^]/g, "")) > sw) ctx.report("layout", "[contour] the label is wider than the panel beside the plot; shorten it"); }
128
+ // 反復の行:入るだけ(多ければ新しい行を残す)
129
+ var n = (d.path || []).length, fit = Math.max(1, Math.floor((py + ph - y0 + fs) / row));
130
+ this.iterFit = Math.min(n, fit);
131
+ for (var r = 0; r < this.iterFit; r++) this.iterRows.push(D.el("text", {x: sx0, y: y0 + r * row, "font-size": fs, fill: "var(--fg)", opacity: 0}, svg));
132
+ } else if (d.label){ D.mtext(this.titleG, W - m.r, top - fs * 0.35, d.label, {"font-size": fs, "text-anchor": "end", fill: "var(--fg)"}); if (tw(d.label.replace(/[*_^]/g, "")) > W - m.r - px - yLabW) ctx.report("layout", "[contour] the label is wider than the row above the plot; shorten it"); }
133
+ this.iterText = D.el("text", {x: W - m.r, y: top - fs * 0.35, "font-size": fs, "text-anchor": "end", fill: "var(--fg)", opacity: 0}, svg);
134
+ // 等高線(値ごとの群)と値の名前
135
+ var sx = (rx[1] - rx[0]) / (pl.nx - 1), sy = (ry[1] - ry[0]) / (pl.ny - 1), gxp = function(p){ return X(rx[0] + p[0] * sx); }, gyp = function(p){ return Y(ry[0] + p[1] * sy); };
136
+ var placed = [];
137
+ this.levelG = pl.levels.map(function(lv, li){
138
+ var g = D.el("g", {opacity: 0}, plot), lines = K.lines(pl.values, lv);
139
+ if (!lines.length) ctx.report("layout", "[contour] level " + lv + " does not cross the range");
140
+ lines.forEach(function(line){
141
+ if (line.length < 2) return;
142
+ D.el("path", {d: "M" + line.map(function(p){ return gxp(p).toFixed(1) + " " + gyp(p).toFixed(1); }).join("L"), fill: "none", stroke: "var(--term)", "stroke-width": 2.5}, g);
143
+ // 名前:線の長さの何割かの所(値ごとにずらす)。ほかの名前と重なるなら、次の候補へ
144
+ var lenPx = K.labelAt(line).length * Math.max(pw / (pl.nx - 1), ph / (pl.ny - 1));
145
+ if (lenPx < 3 * fs) return;
146
+ var txt = num(lv), w = tw(txt) + 8;
147
+ for (var c = 0; c < 6; c++){
148
+ var at = K.labelAt(line, ((0.2 + 0.13 * li + 0.17 * c) % 1)), x = gxp([at.x, at.y]), y = gyp([at.x, at.y]);
149
+ if (x - w / 2 < px || x + w / 2 > px + pw || y - fs * 0.7 < py || y + fs * 0.4 > py + ph) continue;
150
+ if (placed.some(function(q){ return Math.abs(q.x - x) < (q.w + w) / 2 && Math.abs(q.y - y) < fs * 1.1; })) continue;
151
+ placed.push({x: x, y: y, w: w});
152
+ D.el("text", {x: x.toFixed(1), y: (y + fs * 0.35).toFixed(1), "font-size": fs, "text-anchor": "middle", fill: "var(--fg)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "stroke-linejoin": "round"}, g).textContent = txt;
153
+ break;
154
+ }
155
+ });
156
+ return g;
157
+ });
158
+ // 勾配の矢印:長さは scale × |∇f|(書いていなければ、いちばん長い矢印が範囲の幅の 18 %)
159
+ var gmax = Math.max.apply(null, pl.grads.map(function(o){ return Math.hypot(o.g[0], o.g[1]); }).concat([1e-12]));
160
+ var scale = d.gradient && d.gradient.scale ? d.gradient.scale : 0.18 * (rx[1] - rx[0]) / gmax;
161
+ this.gradG = D.el("g", {opacity: 0}, plot);
162
+ pl.grads.forEach(function(o){
163
+ if (!o.g.every(Number.isFinite)) return;
164
+ var x0 = X(o.p[0]), y0 = Y(o.p[1]), x1 = X(o.p[0] + o.g[0] * scale), y1 = Y(o.p[1] + o.g[1] * scale), n = Math.hypot(x1 - x0, y1 - y0);
165
+ if (d.gradient.tangent){ var ux = -(y1 - y0) / (n || 1), uy = (x1 - x0) / (n || 1), tl = 0.12 * pw; D.el("line", {x1: x0 - ux * tl, y1: y0 - uy * tl, x2: x0 + ux * tl, y2: y0 + uy * tl, stroke: "var(--muted)", "stroke-width": 2, "stroke-dasharray": "8 6"}, self.gradG); }
166
+ D.el("circle", {cx: x0, cy: y0, r: 5, fill: "var(--accent2)"}, self.gradG);
167
+ if (n > 4){
168
+ var hx = (x1 - x0) / n, hy = (y1 - y0) / n, h = Math.min(16, n * 0.5), w = h * 0.55, bx = x1 - hx * h, by = y1 - hy * h;
169
+ D.el("line", {x1: x0, y1: y0, x2: bx, y2: by, stroke: "var(--accent2)", "stroke-width": 4}, self.gradG);
170
+ D.el("path", {d: "M" + x1.toFixed(1) + " " + y1.toFixed(1) + "L" + (bx - hy * w).toFixed(1) + " " + (by + hx * w).toFixed(1) + "L" + (bx + hy * w).toFixed(1) + " " + (by - hx * w).toFixed(1) + "Z", fill: "var(--accent2)"}, self.gradG);
171
+ }
172
+ });
173
+ // 反復の道:線分と点(今の点は --emph)
174
+ var pathG = D.el("g", {}, svg);
175
+ this.segs = (d.path || []).map(function(p, i){ return i ? D.el("line", {x1: X(d.path[i - 1][0]), y1: Y(d.path[i - 1][1]), x2: X(d.path[i - 1][0]), y2: Y(d.path[i - 1][1]), stroke: "var(--fg)", "stroke-width": 3, opacity: 0}, pathG) : null; });
176
+ this.dots = (d.path || []).map(function(p){ return D.el("circle", {cx: X(p[0]), cy: Y(p[1]), r: 7, fill: "var(--fg)", stroke: "var(--bg)", "stroke-width": 2, opacity: 0}, pathG); });
177
+ }
178
+ render(k, t){
179
+ if (!this.svg) return;
180
+ var self = this, pl = this.plan(), d = pl.d, G = this.geo, dur = this.props.dur, steps = pl.steps;
181
+ var ph = function(n){ return k > n + 1 ? 1 : k < n + 1 ? 0 : base.prog(t, 0, dur); };
182
+ var li = 0;
183
+ steps.forEach(function(s, n){
184
+ var e = ph(n);
185
+ if (s.kind === "levels") s.levels.forEach(function(){ self.levelG[li++].setAttribute("opacity", e.toFixed(3)); });
186
+ if (s.kind === "gradient") self.gradG.setAttribute("opacity", e.toFixed(3));
187
+ });
188
+ var cur = -1, ecur = 0;
189
+ steps.forEach(function(s, n){
190
+ if (s.kind !== "path") return;
191
+ var e = ph(n), i = s.i, p = d.path[i];
192
+ if (e > 0){ cur = i; ecur = e; }
193
+ self.dots[i].setAttribute("opacity", e > 0 ? 1 : 0);
194
+ if (self.segs[i]){
195
+ var q = d.path[i - 1];
196
+ self.segs[i].setAttribute("x2", G.X(q[0] + (p[0] - q[0]) * e).toFixed(1)); self.segs[i].setAttribute("y2", G.Y(q[1] + (p[1] - q[1]) * e).toFixed(1));
197
+ self.segs[i].setAttribute("opacity", e > 0 ? 1 : 0);
198
+ self.dots[i].setAttribute("opacity", e >= 1 ? 1 : 0);
199
+ }
200
+ });
201
+ this.dots.forEach(function(c, i){ c.setAttribute("style", "fill:var(--" + (i === cur ? "emph" : "fg") + ")"); c.setAttribute("r", i === cur ? 9 : 6); });
202
+ if (this.side){
203
+ // 欄:反復 0 から今の反復まで、1 行ずつ(入らなければ新しい行を残す)。今の行は --emph
204
+ var first = Math.max(0, cur - this.iterFit + 1), L = this.L;
205
+ this.iterRows.forEach(function(e, r){
206
+ var i = first + r, on = cur >= 0 && i <= cur;
207
+ e.textContent = on ? L.iter(i, num(pl.fp[i])) : ""; e.setAttribute("opacity", on ? 1 : 0);
208
+ e.setAttribute("style", "fill:var(--" + (i === cur ? "emph" : "fg") + ")");
209
+ });
210
+ } else if (cur >= 0){ this.iterText.textContent = this.L.iter(cur, num(pl.fp[cur])); this.iterText.setAttribute("opacity", 1); this.titleG.setAttribute("opacity", 0); }
211
+ else { this.iterText.textContent = ""; this.iterText.setAttribute("opacity", 0); this.titleG.setAttribute("opacity", 1); }
212
+ }
213
+ };
214
+ });