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,272 @@
1
+ // m-pie:円グラフとドーナツグラフ。切れの名前と値(と割合)は、大きい切れなら中に、小さい切れなら外に引き出し線で書く
2
+ // <m-pie unit="万円" digits="1" show="both" style="height:420px"><script type="application/json">
3
+ // {"slices": [{"label": "食費", "value": 7.2}, {"label": "住まい", "value": 8.5}, {"label": "その他", "value": 2.1, "tone": "muted"}]}
4
+ // (JSON の終わり)</m-pie>
5
+ // 段階:既定は全部を段階 1 で(全体と内訳は一度に見せる)。per-step="1" で 1 切れずつ(口述原稿が 1 切れずつ話すときだけ)、切れの step で直接
6
+ // 切れは 12 時の位置から時計回りに、書いた順に並べる。割合は足して 100 になるように丸める(最大剰余法)
7
+ // donut="0.55" でドーナツ(内側の半径の割合)。中の字は JSON の center({total} は合計に置き換わる)
8
+ // 見せ方(docs/conventions.md §1):fade(フェードして少し上がりながら現れる、既定)・sweep(12 時の位置から時計回りに掃くように現れる)・
9
+ // grow(中心から少し小さい大きさで現れて元の大きさに戻る)。段階の数・長さ・最後の中身は同じ
10
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
11
+ // 負の値と、字が収まらないことは ctx.report で知らせる(1.x の console.warn の代わり)
12
+ egatariParts.define({name: "pie", version: "2.1.0", requires: {base: "1.3.0"}, element: "m-pie"}, function(deps){
13
+ "use strict";
14
+ var base = deps.base;
15
+ return class extends base.MotionElement {
16
+ static partName = "pie"; // the registry name (define meta name), for report prefixes
17
+ static variants = ["fade", "sweep", "grow"];
18
+ // データの形(kit/shape.js)
19
+ static shape = {
20
+ schema: {type: "object", additionalProperties: false, required: ["slices"], properties: {
21
+ slices: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["value"], properties: {
22
+ label: {type: "string"}, value: {type: "number"}, tone: {type: "string"}, step: {type: "integer"}, place: {enum: ["auto", "in", "out"]}}}},
23
+ center: {type: "string"}}},
24
+ example: {slices: [{label: "食費", value: 7.2}, {label: "住まい", value: 8.5}, {label: "その他", value: 2.1, tone: "muted"}]},
25
+ note: {en: "the slices go in \"slices\" (not \"data\" or \"groups\"); value is a number, not a percentage string; the slices are drawn clockwise from 12 o'clock in the written order",
26
+ ja: "切れは \"slices\" に書く(\"data\" や \"groups\" ではない)。value は数(\"26%\" のような字ではない)。12 時の位置から時計回りに、書いた順に並ぶ"},
27
+ };
28
+ static props = {
29
+ donut: {type: "number", default: 0, doc: "ドーナツの内側の半径の割合(0 = 円グラフ。0.5〜0.6 がよい)"},
30
+ unit: {type: "string", default: "", doc: "値の単位(数字の後ろに付ける。万円、人、% など)"},
31
+ digits: {type: "number", default: 0, doc: "値の小数桁"},
32
+ "pct-digits": {type: "number", default: 0, doc: "割合の小数桁"},
33
+ show: {type: "string", default: "pct", doc: "名前の下に書くもの:pct(割合)・value(値)・both(値と割合)・none"},
34
+ "per-step": {type: "number", default: 0, doc: "1 ステップに出す切れの数(0 = 全部をステップ 1 で)"},
35
+ dur: {type: "number", default: 1.0, doc: "1 ステップの動きの秒数"},
36
+ };
37
+ get steps(){
38
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
39
+ var m = 0;
40
+ this.plan().forEach(function(o){ m = Math.max(m, o.step); });
41
+ return m;
42
+ }
43
+ plan(){
44
+ if (this._plan) return this._plan;
45
+ var per = this.props["per-step"];
46
+ return (this._plan = ((this.data || {}).slices || []).map(function(s, i){
47
+ return {s: s, i: i, step: s.step !== undefined ? s.step : per > 0 ? Math.floor(i / per) + 1 : 1};
48
+ }));
49
+ }
50
+ mount(ctx){
51
+ var P = this.props, D = base, self = this, pl = this.plan(), d = this.data || {};
52
+ var ja = /^ja\b/i.test(ctx.lang || "ja");
53
+ this.variant = base.variant(this);
54
+ this.style.display = "block"; this.style.position = "relative";
55
+ var W = this.clientWidth, H = this.clientHeight, TAU = Math.PI * 2;
56
+ var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
57
+ // 字の幅(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
58
+ var est = function(s, size){ return D.textWidth(s, size, {font: self, mark: true}); };
59
+ var total = pl.reduce(function(a, o){ return a + Math.max(0, +o.s.value); }, 0);
60
+ if (!(total > 0)) throw new Error("slices: the values add up to 0 (write positive numbers)");
61
+ pl.forEach(function(o){ if (+o.s.value < 0) ctx.report("data", "[pie] the slice \"" + (o.s.label || o.i) + "\" has a negative value (drawn as 0)"); });
62
+ // 割合:足して 100 になるように丸める(最大剰余法)
63
+ var pd = P["pct-digits"], sc = Math.pow(10, pd), raw = pl.map(function(o){ return Math.max(0, +o.s.value) / total * 100 * sc; });
64
+ var fl = raw.map(Math.floor), left = Math.round(100 * sc) - fl.reduce(function(a, b){ return a + b; }, 0);
65
+ raw.map(function(v, i){ return [v - fl[i], i]; }).sort(function(a, b){ return b[0] - a[0] || a[1] - b[1]; }).slice(0, Math.max(0, left)).forEach(function(x){ fl[x[1]]++; });
66
+ var show = /^(pct|value|both|none)$/.test(P.show) ? P.show : "pct";
67
+ // 角度(12 時の位置から時計回り)と字
68
+ var acc = 0;
69
+ var sl = this.slices = pl.map(function(o, i){
70
+ var v = Math.max(0, +o.s.value), a0 = acc / total * TAU; acc += v;
71
+ var a1 = acc / total * TAU, pct = (fl[i] / sc).toFixed(pd) + "%", val = self.fmt(v);
72
+ var sub = show === "pct" ? pct : show === "value" ? val : show === "both" ? val + (ja ? "(" + pct + ")" : " (" + pct + ")") : "";
73
+ var lines = [];
74
+ if (o.s.label) lines.push({t: o.s.label, size: 26, bold: true});
75
+ if (sub) lines.push({t: sub, size: 24, bold: false});
76
+ // 中に入れるときの別の形:値と割合を 2 行に分けて幅を狭くする
77
+ var alt = show === "both" ? lines.slice(0, lines.length - 1).concat([{t: val, size: 24}, {t: pct, size: 24}]) : null;
78
+ // 既定の色:--series-1..3、次に同じ 3 色を薄く(0.5)、7 切れ目から --series-4(灰色は「その他」のために残す)、そのあとは繰り返し
79
+ var j6 = i % 7, tone = /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(o.s.tone || "") ? o.s.tone : j6 === 6 ? "series-4" : "series-" + (j6 % 3 + 1);
80
+ return {o: o, i: i, a0: a0, a1: a1, mid: (a0 + a1) / 2, lines: lines, col: "var(--" + tone + ")", light: !o.s.tone && j6 >= 3 && j6 < 6,
81
+ forms: [lines].concat(alt ? [alt] : []).map(function(ls){ return {lines: ls, w: Math.max.apply(null, ls.map(function(l){ return est(l.t, l.size); }).concat([0])), h: ls.length * 30}; })};
82
+ });
83
+ var ratio = Math.max(0, Math.min(0.85, P.donut || 0));
84
+ // 中に収まるか:字の箱の 4 隅が、その切れの扇形(内側と外側の半径、両端の角度)の中にあるか
85
+ var pt = function(cx, cy, r, a){ return [cx + r * Math.sin(a), cy - r * Math.cos(a)]; };
86
+ var fits1 = function(s, R){
87
+ s.rm = ratio ? (1 + ratio) / 2 : 0.6;
88
+ if (!s.lines.length || s.o.s.place === "in") return true;
89
+ if (s.o.s.place === "out") return false;
90
+ // 字の中心の半径:ドーナツは輪の真ん中、円グラフは 0.6R → 0.5R → 0.7R の順に試す
91
+ var ri = R * ratio, cands = ratio ? [(ri + R) / 2] : [R * 0.6, R * 0.5, R * 0.7];
92
+ for (var n = 0; n < cands.length; n++){
93
+ var c = pt(0, 0, cands[n], s.mid), ok = true;
94
+ [[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function(q){
95
+ var x = c[0] + q[0] * (s.w / 2 + 4), y = c[1] + q[1] * (s.h / 2 + 2), r = Math.hypot(x, y), a = Math.atan2(x, -y);
96
+ if (a < 0) a += TAU;
97
+ if (s.a1 - s.a0 < TAU - 1e-6 && !(a >= s.a0 + 0.02 && a <= s.a1 - 0.02)) ok = false;
98
+ if (r > R - 6 || r < ri + 6) ok = false;
99
+ });
100
+ if (ok){ s.rm = cands[n] / R; return true; }
101
+ }
102
+ return false;
103
+ };
104
+ // 形を 1 つずつ試す。どれも入らなければ外に書く形(最初の形)に戻す
105
+ var fits = function(s, R){
106
+ for (var f = 0; f < s.forms.length; f++){ use(s, f); if (fits1(s, R)) return true; }
107
+ use(s, 0);
108
+ return false;
109
+ };
110
+ function use(s, f){ s.lines = s.forms[f].lines; s.w = s.forms[f].w; s.h = s.forms[f].h; }
111
+ sl.forEach(function(s){ use(s, 0); });
112
+ // 半径:外の字の幅の分だけ左右をあける。中に収まる切れが増えれば半径を見直す(2 回)
113
+ var pad = 10, gap = 44, want = 0, radius = function(outs){
114
+ var wl = 0, wr = 0;
115
+ outs.forEach(function(s){ if (Math.sin(s.mid) >= 0) wr = Math.max(wr, s.w); else wl = Math.max(wl, s.w); });
116
+ var side = Math.max(wl, wr), r = Math.min((H / 2 - pad) * (outs.length ? 0.86 : 1), W / 2 - pad - (side ? side + gap : 0));
117
+ want = 40 - r; // 40 px より小さくなるなら、足りない幅(最小の 40 px で描く)
118
+ return Math.max(40, r);
119
+ };
120
+ var R = radius(sl.filter(function(s){ return s.lines.length; }));
121
+ for (var pass = 0; pass < 2; pass++){
122
+ sl.forEach(function(s){ s.inside = fits(s, R); });
123
+ R = radius(sl.filter(function(s){ return !s.inside; }));
124
+ }
125
+ sl.forEach(function(s){ if (!s.inside && s.o.s.place !== "out" && fits(s, R)) s.inside = true; });
126
+ if (want > 0) ctx.report("size", "[pie] the labels outside leave too little room: the pie is drawn at the smallest radius, 40 px (" + Math.ceil(want * 2) + " px more width needed; make the element wider or the labels shorter)");
127
+ // 字が片側だけなら、字と円をひとまとまりとして真ん中に寄せる
128
+ var wl = 0, wr = 0;
129
+ sl.forEach(function(s){ if (!s.inside && s.lines.length){ if (Math.sin(s.mid) >= 0) wr = Math.max(wr, s.w + gap); else wl = Math.max(wl, s.w + gap); } });
130
+ var cx = W / 2 + (wl - wr) / 2, cy = H / 2, ri = R * ratio;
131
+ this.R = R; this.ri = ri; this.cx = cx; this.cy = cy;
132
+ // 読み上げ:最後の形(すべての切れ)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
133
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
134
+ this.setAttribute("role", "img");
135
+ if (!this._aria) this.setAttribute("aria-label", this.summary(ja, sl, fl, sc, pd, show, total));
136
+ // 1 切れずつ出すときは、全体の輪郭を初めから薄く見せる(どれだけのうちの 1 切れかが分かるように)
137
+ if (pl.some(function(o){ return o.step > 1; })){
138
+ D.el("circle", {cx: cx, cy: cy, r: R, fill: "none", stroke: "var(--line)", "stroke-width": 2}, svg);
139
+ if (ri) D.el("circle", {cx: cx, cy: cy, r: ri, fill: "none", stroke: "var(--line)", "stroke-width": 2}, svg);
140
+ }
141
+ var gS = D.el("g", {}, svg), gL = D.el("g", {}, svg);
142
+ // 外の字:左右の列に置き、縦に重ならないように並べ直す
143
+ [1, -1].forEach(function(side){
144
+ var outs = sl.filter(function(s){ return !s.inside && s.lines.length && (Math.sin(s.mid) >= 0 ? 1 : -1) === side; });
145
+ outs.forEach(function(s){ s.yc = cy - (R + 18) * Math.cos(s.mid); });
146
+ outs.sort(function(a, b){ return a.yc - b.yc; });
147
+ // 上から押し下げ、下からはみ出す分を押し上げる(字の箱の間は 8 px)
148
+ for (var j = 0; j < outs.length; j++){
149
+ var mn = j ? outs[j - 1].yc + (outs[j - 1].h + outs[j].h) / 2 + 8 : outs[0].h / 2 + 2;
150
+ if (outs[j].yc < mn) outs[j].yc = mn;
151
+ }
152
+ for (var q = outs.length - 1; q >= 0; q--){
153
+ var mx = q === outs.length - 1 ? H - 2 - outs[q].h / 2 : outs[q + 1].yc - (outs[q + 1].h + outs[q].h) / 2 - 8;
154
+ if (outs[q].yc > mx) outs[q].yc = mx;
155
+ }
156
+ if (outs.length && outs[0].yc - outs[0].h / 2 < 0) ctx.report("size", "[pie] the labels outside do not fit the height (make the element taller or put fewer slices)");
157
+ var colX = cx + side * (R + gap - 8);
158
+ outs.forEach(function(s){
159
+ // 引き出し線:切れの外の縁から、円の外側を回って字の列へ
160
+ var p1 = pt(cx, cy, R + 4, s.mid), dy = s.yc - cy, rr = R + 14;
161
+ var qx = cx + side * Math.max(Math.abs((R + 16) * Math.sin(s.mid)), Math.sqrt(Math.max(0, rr * rr - dy * dy)));
162
+ // the leader is an edge from its slice (a box) to the slice's own label (spec §8.4)
163
+ var sid = "s" + (sl.indexOf(s) + 1);
164
+ s.leader = D.el("path", {"data-part-line": "", d: "M" + p1[0].toFixed(1) + "," + p1[1].toFixed(1) + "L" + qx.toFixed(1) + "," + s.yc.toFixed(1) + "L" + (colX - side * 6).toFixed(1) + "," + s.yc.toFixed(1),
165
+ fill: "none", stroke: "var(--muted)", "stroke-width": 1.5}, D.el("g", {"data-part": "edge", "data-part-id": "lead-" + sid, "data-part-from": sid, "data-part-to": sid}, gL));
166
+ s.tx = colX; s.anchor = side > 0 ? "start" : "end";
167
+ if (side > 0 ? colX + s.w > W + 1 : colX - s.w < -1) ctx.report("size", "[pie] the label \"" + s.lines[0].t + "\" is wider than the space beside the pie");
168
+ });
169
+ });
170
+ sl.forEach(function(s){
171
+ // marks for the geometry check (spec §8.4): each slice is a box, its text a label (outside the slice when it stands beside the pie)
172
+ var sid = "s" + (sl.indexOf(s) + 1);
173
+ s.path = D.el("path", {"data-part": "box", "data-part-id": sid, d: "", fill: s.col, "fill-opacity": s.light ? 0.5 : 1, stroke: "var(--bg)", "stroke-width": 2, "stroke-linejoin": "round"}, gS);
174
+ if (!s.lines.length) return;
175
+ var g = s.g = D.el("g", {opacity: 0}, gL), x, y0;
176
+ if (s.inside){
177
+ var c = pt(cx, cy, s.rm * R, s.mid);
178
+ x = c[0]; y0 = c[1] - s.h / 2;
179
+ } else { x = s.tx; y0 = s.yc - s.h / 2; }
180
+ // 中の字は切れの色の上なので背景の色(濃い色の切れ)か本文の色(薄い切れ)
181
+ var fill = s.inside ? (s.light ? "var(--fg)" : "var(--bg)") : "var(--fg)";
182
+ s.lines.forEach(function(l, j){
183
+ D.mtext(g, x, y0 + j * 30 + 24, l.t, Object.assign({"data-part": "label", "data-part-id": sid, "data-part-of": "box"}, s.inside ? {} : {"data-part-at": "outside"}, {"text-anchor": s.inside ? "middle" : s.anchor, "font-size": l.size, "font-weight": l.bold ? 700 : 400, fill: fill}));
184
+ });
185
+ });
186
+ // ドーナツの中の字({total} は合計)
187
+ this.center = null;
188
+ if (ri && d.center){
189
+ var cl = String(d.center).replace(/\{total\}/g, this.fmt(total)).split("\n"), size = 26;
190
+ var cw = Math.max.apply(null, cl.map(function(t){ return est(t, size); }));
191
+ if (cw > ri * 1.8){ size = 24; cw = cw * 24 / 26; }
192
+ if (cw > ri * 1.8) ctx.report("size", "[pie] the center text is wider than the hole (make donut larger or the text shorter)");
193
+ var cg = this.center = D.el("g", {opacity: 0}, gL);
194
+ cl.forEach(function(t, j){ D.mtext(cg, cx, cy - (cl.length - 1) * 16 + j * 32 + 9, t, {"text-anchor": "middle", "font-size": size, "font-weight": j === 0 ? 700 : 400}); });
195
+ }
196
+ }
197
+ // 最後の形を 1 文で(読み上げの名前):「内訳:食費 35%、住まい 41%、…(中:合計 21.2万円)」。show が value / both なら値も書く
198
+ summary(ja, sl, fl, sc, pd, show, total){
199
+ var self = this, d = this.data || {};
200
+ var parts = sl.map(function(s){
201
+ var pct = (fl[s.i] / sc).toFixed(pd) + "%", v = self.fmt(Math.max(0, +s.o.s.value));
202
+ var x = show === "value" ? v : show === "both" ? v + (ja ? "(" + pct + ")" : " (" + pct + ")") : pct;
203
+ return (s.o.s.label ? String(s.o.s.label).replace(/\s*\n\s*/g, " ") + " " : "") + x;
204
+ });
205
+ var c = this.ri && d.center ? String(d.center).replace(/\{total\}/g, this.fmt(total)).replace(/\s*\n\s*/g, " ") : "";
206
+ return (ja ? "内訳:" : "Breakdown: ") + parts.join(ja ? "、" : ", ") + (c ? (ja ? "(中:" + c + ")" : " (centre: " + c + ")") : "");
207
+ }
208
+ // 数の書き方:3 桁ごとのカンマ、小数桁、単位(m-bars と同じ)
209
+ fmt(v){
210
+ var s = Math.abs(v).toFixed(this.props.digits).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
211
+ return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "") + this.props.unit;
212
+ }
213
+ wedge(a0, a1, r0, r1){
214
+ var cx = this.cx, cy = this.cy, TAU = Math.PI * 2;
215
+ if (a1 - a0 <= 1e-6 || r1 <= 0) return "";
216
+ var p = function(r, a){ return (cx + r * Math.sin(a)).toFixed(2) + "," + (cy - r * Math.cos(a)).toFixed(2); };
217
+ // 全周、または残りが小さくて両端の点が丸めると重なる(99.999 % のような切れ)ときは、全周で描く(1 つの弧では何も描かれない)
218
+ if (a1 - a0 >= TAU - 1e-6 || (TAU - (a1 - a0)) * r1 < 0.05){
219
+ // 全周:2 つの半円で描く
220
+ var full = "M" + p(r1, 0) + "A" + r1 + "," + r1 + " 0 1,1 " + p(r1, Math.PI) + "A" + r1 + "," + r1 + " 0 1,1 " + p(r1, 0) + "Z";
221
+ return r0 > 0 ? full + "M" + p(r0, 0) + "A" + r0 + "," + r0 + " 0 1,0 " + p(r0, Math.PI) + "A" + r0 + "," + r0 + " 0 1,0 " + p(r0, 0) + "Z" : full;
222
+ }
223
+ var big = a1 - a0 > Math.PI ? 1 : 0;
224
+ var s = "M" + p(r1, a0) + "A" + r1 + "," + r1 + " 0 " + big + ",1 " + p(r1, a1);
225
+ s += r0 > 0 ? "L" + p(r0, a1) + "A" + r0 + "," + r0 + " 0 " + big + ",0 " + p(r0, a0) + "Z" : "L" + cx.toFixed(2) + "," + cy.toFixed(2) + "Z";
226
+ return s;
227
+ }
228
+ duration(k){
229
+ return this.plan().some(function(o){ return o.step === k; }) ? this.props.dur : 0;
230
+ }
231
+ render(k, t, ctx){
232
+ var P = this.props, D = base, self = this, vr = this.variant, dur = P.dur, span = dur * 0.6, lecture = !!ctx.preview, FAINT = 0.45;
233
+ if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
234
+ var TAU = Math.PI * 2, R = this.R, ri = this.ri;
235
+ // 同じ段階の切れが占める角度の範囲(sweep はこの範囲を掃く)
236
+ var rng = {};
237
+ this.slices.forEach(function(s){ var st = s.o.step, q = rng[st] || (rng[st] = [Infinity, -Infinity]); q[0] = Math.min(q[0], s.a0); q[1] = Math.max(q[1], s.a1); });
238
+ var first = Infinity;
239
+ this.slices.forEach(function(s){
240
+ var st = s.o.step, tt = st < k ? Infinity : st > k ? -1 : t, faint = lecture && st > k;
241
+ first = Math.min(first, st);
242
+ var a0 = s.a0, a1 = s.a1, r0 = ri, r1 = R, op = 1, dy = 0, lo;
243
+ if (faint){ op = FAINT; lo = FAINT; }
244
+ else if (tt < 0){ op = 0; lo = 0; }
245
+ else if (vr === "sweep"){
246
+ // 12 時の位置(1 切れずつなら、その段階の最初の切れの端)から時計回りに掃く
247
+ var q = rng[st], e = D.prog(tt, 0, span), edge = q[0] + (q[1] - q[0]) * e;
248
+ a1 = Math.min(a1, edge);
249
+ lo = D.prog(tt, span * (s.a1 - q[0]) / Math.max(1e-6, q[1] - q[0]) * 0.9, dur - span);
250
+ } else if (vr === "grow"){
251
+ // 中心から:外側の縁が 12 px 内側から元の大きさへ(fade の上がる距離と同じ)
252
+ var g = D.prog(tt, 0, span), f = (R - 12 * (1 - g)) / R;
253
+ r0 = ri * f; r1 = R * f; op = Math.min(1, g * 2.5 + (g > 0 ? 0.2 : 0));
254
+ lo = D.prog(tt, span, dur - span);
255
+ } else {
256
+ var e2 = D.prog(tt, 0, span);
257
+ op = e2; dy = (1 - e2) * 12;
258
+ lo = D.prog(tt, span, dur - span);
259
+ }
260
+ s.path.setAttribute("d", op > 0 ? self.wedge(a0, a1, r0, r1) : "");
261
+ s.path.setAttribute("opacity", op.toFixed(3));
262
+ s.path.setAttribute("transform", dy ? "translate(0 " + dy.toFixed(2) + ")" : "");
263
+ if (s.g) s.g.setAttribute("opacity", lo.toFixed(3));
264
+ if (s.leader) s.leader.setAttribute("opacity", lo.toFixed(3));
265
+ });
266
+ if (this.center){
267
+ var c = first < k ? 1 : first > k ? (lecture ? FAINT : 0) : D.prog(t, span, dur - span);
268
+ this.center.setAttribute("opacity", c.toFixed(3));
269
+ }
270
+ }
271
+ };
272
+ });
@@ -0,0 +1,30 @@
1
+ ---
2
+ summary: Code run line by line (tracer output); current line, changed variables, output
3
+ steps: trace lines (time: 1)
4
+ props:
5
+ dur: s per step
6
+ by: step or time
7
+ rate: lines/s
8
+ size: text px
9
+ example: {"lang":"python","code":"total = 0\nfor x in [3, 1]:\n total += x\nprint(total)","source":{"tool":"egatari-trace 0.1","python":"3.13.1","sha256":"","truncated":false},"steps":[{"line":1,"vars":{"total":0}},{"line":2,"vars":{"total":0,"x":3}},{"line":3,"vars":{"total":3,"x":3}},{"line":2,"vars":{"total":3,"x":1}},{"line":3,"vars":{"total":4,"x":1}},{"line":2,"vars":{"total":4,"x":1}},{"line":4,"vars":{"total":4,"x":1},"out":"4\n"}]}
10
+ ---
11
+
12
+ JSON from `uv run tools/trace.py prog.py --out trace.json`, never by hand.
13
+ <!-- llm: omit -->
14
+ - Not in any chat pack (tier local): an AI chatbot cannot run the tracer. Use it from Claude Code or locally.
15
+ - `steps[i]`: `line` or `lines: [a, b]`, `vars` (the FULL state after the line, not a delta), `out` (what the line printed), `note` (added by hand after tracing, ≤2 band rows).
16
+ - Values: numbers, strings (≤40 chars), booleans, null, lists (≤12, or 2-D ≤6×6), dicts (≤8 keys), nesting ≤2, else `{"repr": "…"}`.
17
+ - Caps: 16 code lines, 60 steps, 6 variables (`show` picks them), 8 output lines.
18
+ - `by="time"` plays the whole trace inside one step at `rate` lines/s; cues are the line times.
19
+ - Current line: emph ground and bold number. Changed variables: emph text, ground and bold.
20
+ - Code and output in `pre[data-readable]`; final variables in `table[data-readable]`. No preview of later steps.
21
+ <!-- llm: end -->
22
+
23
+ Demo: `demo.html` (a for-loop sum, counting words in a dict, bubble sort with by="time"); traces from `tools/trace-demo/` through `tools/trace.py`.
24
+
25
+ <!-- llm: omit -->
26
+ Notes
27
+
28
+ - The tracer runs the code locally. Trace short teaching code, not code that touches files or the network.
29
+ - A for line becomes one more step when the loop ends (that is how Python runs it); say so in the notes.
30
+ <!-- llm: end -->
@@ -0,0 +1,305 @@
1
+ // m-trace:コードの実行を 1 行ずつ追う。左にコード(今の行に印)、右に変数(変わった変数に印)と、その時点までの出力。
2
+ // 値はトレーサー(tools/trace.py、sys.settrace)が書いた JSON だけを描く。パーツはコードを実行しない。
3
+ // <m-trace style="height:440px"><script type="application/json">
4
+ // {"lang": "python", "code": "xs = [3, 1, 2]\ntotal = 0\nfor x in xs:\n total += x\nprint(total)",
5
+ // "source": {"tool": "egatari-trace 0.1", "python": "3.13.1", "sha256": "…", "truncated": false},
6
+ // "steps": [{"line": 1, "vars": {"xs": [3, 1, 2]}}, …, {"line": 5, "vars": {…}, "out": "6\n"}]}
7
+ // (JSON の終わり)</m-trace>
8
+ // steps[i]:line(または lines: [a, b])、vars(その行を実行した後の、見せる変数すべての値。差分ではない)、out(その行の出力)、note。
9
+ // ステップ:k = 0 はコードと空の変数、k = i + 1 はトレースの i 番目(by="time" なら 1 つのステップの中で rate 個/秒で進む)。
10
+ // 色:今の行 --emph の地と行番号、変わった変数 --emph の字と地と太字(色だけに頼らない)。
11
+ egatariParts.define({name: "trace", version: "2.0.1", requires: {base: "1.3.0", "code-core": "1.0.1"}, element: "m-trace"}, function(deps){
12
+ "use strict";
13
+ var base = deps.base, C = deps["code-core"], MONO = C.MONO, set = C.set, monoWidth = C.monoWidth, cut = C.cut;
14
+ var CAP = {lines: 16, steps: 60, show: 6, str: 40, list: 12, grid: 6, dict: 8, out: 8};
15
+ var TEXT = {
16
+ ja: {vars: "変数", output: "出力", readable: "コードと出力", final: "最後の変数", name: "変数", value: "値", more: function(n){ return "⋮(ほか " + n + " 行)"; }, older: function(n){ return "…(前の " + n + " 行)"; },
17
+ line: function(a, b){ return (a === b ? a : a + "–" + b) + " 行目"; }, summary: function(lang, n, m){ return lang + " のコード " + n + " 行の実行を " + m + " ステップで追う"; }},
18
+ en: {vars: "Variables", output: "Output", readable: "Code and output", final: "Final variables", name: "Variable", value: "Value", more: function(n){ return "⋮ (" + n + " more line" + (n === 1 ? "" : "s") + ")"; }, older: function(n){ return "… (" + n + " earlier)"; },
19
+ line: function(a, b){ return a === b ? "line " + a : "lines " + a + "–" + b; }, summary: function(lang, n, m){ return lang + ": " + n + " lines of code traced in " + m + " steps"; }}
20
+ };
21
+ // 値の文法:数・文字(40 字まで)・真偽・null、リスト(12 個まで、2 次元なら 6 × 6 まで)、辞書(8 個まで)、入れ子は 2 段まで、ほかは {"repr": "…"}
22
+ function grammar(v, depth){
23
+ if (v === null || typeof v === "boolean") return "";
24
+ if (typeof v === "number") return isFinite(v) ? "" : "a number that is not finite";
25
+ if (typeof v === "string") return [...v].length <= CAP.str ? "" : "a string over " + CAP.str + " characters (write {\"repr\": …})";
26
+ if (depth >= 2) return "values nested deeper than 2 levels (write {\"repr\": …})";
27
+ if (Array.isArray(v)){
28
+ if (v.length && v.every(Array.isArray)){ if (v.length > CAP.grid || v.some(function(r){ return r.length > CAP.grid; })) return "a 2-D list over " + CAP.grid + " × " + CAP.grid; }
29
+ else if (v.length > CAP.list) return "a list over " + CAP.list + " items";
30
+ for (var i = 0; i < v.length; i++){ var e = grammar(v[i], depth + 1); if (e) return e; }
31
+ return "";
32
+ }
33
+ if (typeof v === "object"){
34
+ var ks = Object.keys(v);
35
+ if ("repr" in v) return ks.length === 1 && typeof v.repr === "string" ? "" : "{\"repr\"} takes one string and nothing else";
36
+ if (ks.length > CAP.dict) return "a dict over " + CAP.dict + " keys";
37
+ for (var j = 0; j < ks.length; j++){ var e2 = grammar(v[ks[j]], depth + 1); if (e2) return e2; }
38
+ return "";
39
+ }
40
+ return "an unknown value";
41
+ }
42
+ // 値の字(Python なら Python の書き方:'a'・True・None)。2 次元のリストは 1 行ずつ
43
+ function fmt(v, py){
44
+ if (v === null) return py ? "None" : "null";
45
+ if (typeof v === "boolean") return py ? (v ? "True" : "False") : String(v);
46
+ if (typeof v === "number") return String(v);
47
+ if (typeof v === "string") return py ? "'" + v.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n") + "'" : JSON.stringify(v);
48
+ if (Array.isArray(v)) return "[" + v.map(function(x){ return fmt(x, py); }).join(", ") + "]";
49
+ if (v && typeof v === "object"){
50
+ if ("repr" in v) return String(v.repr);
51
+ return "{" + Object.keys(v).map(function(k){ return fmt(k, py) + ": " + fmt(v[k], py); }).join(", ") + "}";
52
+ }
53
+ return String(v);
54
+ }
55
+ function rowsOf(v, py){
56
+ if (Array.isArray(v) && v.length > 1 && v.every(Array.isArray)) return v.map(function(r, i){ return (i ? " " : "[") + fmt(r, py) + (i < v.length - 1 ? "," : "]"); });
57
+ return [fmt(v, py)];
58
+ }
59
+ function outLines(s){ var L = s.replace(/\r\n?/g, "\n").split("\n"); if (L[L.length - 1] === "") L.pop(); return L; }
60
+ return class extends base.MotionElement {
61
+ static partName = "trace";
62
+ static preview = "none";
63
+ static shape = {schema: {type: "object", additionalProperties: false, required: ["code", "steps"], properties: {
64
+ lang: {type: "string"}, code: {type: "string"},
65
+ source: {type: "object", additionalProperties: false, properties: {tool: {type: "string"}, python: {type: "string"}, sha256: {type: "string"}, truncated: {type: "boolean"}}},
66
+ show: {type: "array", minItems: 1, maxItems: 6, items: {type: "string"}},
67
+ steps: {type: "array", minItems: 1, maxItems: 60, items: {type: "object", additionalProperties: false, required: ["vars"], anyOf: [{required: ["line"]}, {required: ["lines"]}], properties: {
68
+ line: {type: "integer"}, lines: {type: "array", minItems: 2, maxItems: 2, items: {type: "integer"}}, vars: {type: "object"}, out: {type: "string"}, note: {type: "string"}
69
+ }}}
70
+ }}, example: /*@egatari-block example*/{"lang":"python","code":"total = 0\nfor x in [3, 1]:\n total += x\nprint(total)","source":{"tool":"egatari-trace 0.1","python":"3.13.1","sha256":"","truncated":false},"steps":[{"line":1,"vars":{"total":0}},{"line":2,"vars":{"total":0,"x":3}},{"line":3,"vars":{"total":3,"x":3}},{"line":2,"vars":{"total":3,"x":1}},{"line":3,"vars":{"total":4,"x":1}},{"line":2,"vars":{"total":4,"x":1}},{"line":4,"vars":{"total":4,"x":1},"out":"4\n"}]}/*@egatari-block-end*/};
71
+ static props = {
72
+ dur: {type: "number", default: 0.5, doc: "1 ステップの秒数"},
73
+ by: {type: "enum", values: ["step", "time"], default: "step", doc: "step はトレースの 1 行を 1 ステップに、time は全体を 1 ステップの中で流す"},
74
+ rate: {type: "number", default: 2, doc: "by=\"time\" のとき 1 秒に進む行の数"},
75
+ size: {type: "number", default: 0, doc: "文字 px(0 は既定)"}
76
+ };
77
+ get steps(){ var n = ((this.data || {}).steps || []).length; return this.props.by === "time" ? (n ? 1 : 0) : n; }
78
+ duration(k){ var n = this.data.steps.length; return this.props.by === "time" ? (k === 1 ? n / this.props.rate : 0) : (k >= 1 && k <= n ? this.props.dur : 0); }
79
+ cues(k){ var r = this.props.rate; return this.props.by === "time" && k === 1 ? this.data.steps.map(function(_, i){ return i / r; }) : null; }
80
+ label(g, x, y, s, fs, color, mono){
81
+ var e = base.el("text", {x: x, y: y, "font-size": fs, fill: color || "var(--fg)"}, g);
82
+ if (mono) e.setAttribute("style", "font-family:" + MONO + ";white-space:pre;");
83
+ e.textContent = s; return e;
84
+ }
85
+ mount(ctx){
86
+ var self = this, d = this.data, P = this.props, T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
87
+ if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[trace] dur must be positive; using 0.5"); P.dur = 0.5; }
88
+ if (!(Number.isFinite(P.rate) && P.rate > 0)){ ctx.report("attr", "[trace] rate must be positive; using 2"); P.rate = 2; }
89
+ if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[trace] size must be 0 or at least 24; using defaults"); P.size = 0; }
90
+ this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
91
+ var lang = d.lang || "", py = /^python/i.test(lang), program = C.lines(d.code), marks = C.spans(program, lang.toLowerCase()), N = d.steps.length;
92
+ this.T = T; this.py = py;
93
+ // ---- データの確かめ(形は shape、ここでは欄どうしの関係と値の文法)
94
+ var bad = function(s){ ctx.report("data", "[trace] " + s); };
95
+ if (program.length > CAP.lines) bad("code has " + program.length + " lines; at most " + CAP.lines + " (trace a shorter program or one function)");
96
+ var st = d.steps.map(function(s, i){
97
+ var a = s.line !== undefined ? s.line : s.lines[0], b = s.line !== undefined ? s.line : s.lines[1];
98
+ if (!(a >= 1 && b >= a && b <= program.length)){ bad("steps[" + i + "]: line " + (a === b ? a : a + "–" + b) + " is outside 1–" + program.length); a = b = 0; }
99
+ Object.keys(s.vars).forEach(function(k){ var e = grammar(s.vars[k], 0); if (e) bad("steps[" + i + "].vars." + k + ": " + e); });
100
+ return {a: a, b: b, vars: s.vars, out: s.out || "", note: s.note || ""};
101
+ });
102
+ var seen = []; st.forEach(function(s){ Object.keys(s.vars).forEach(function(k){ if (seen.indexOf(k) < 0) seen.push(k); }); });
103
+ var names = d.show ? d.show.slice() : seen.slice(0, CAP.show);
104
+ if (!d.show && seen.length > CAP.show) bad(seen.length + " variables (" + seen.join(", ") + "); at most " + CAP.show + " are shown: choose them with show");
105
+ if (d.show) d.show.forEach(function(k){ if (seen.indexOf(k) < 0) bad("show: \"" + k + "\" is in no step's vars"); });
106
+ var acc = [], all = "";
107
+ st.forEach(function(s, i){
108
+ all += s.out; acc.push(outLines(all));
109
+ var prev = i ? st[i - 1].vars : {};
110
+ s.changed = names.filter(function(k){ return (k in s.vars) && JSON.stringify(s.vars[k]) !== JSON.stringify(prev[k]); });
111
+ });
112
+ var outTotal = acc.length ? acc[acc.length - 1].length : 0;
113
+ if (outTotal > CAP.out) bad("the output has " + outTotal + " lines; at most " + CAP.out + " (print less, or trace a shorter run)");
114
+ this.st = st; this.names = names; this.acc = acc;
115
+ // ---- 読める層:コードと出力(pre)、最後の変数(table)
116
+ this.setAttribute("role", "figure");
117
+ var langName = py ? "Python" : lang || (T === TEXT.ja ? "プログラム" : "Program");
118
+ if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.summary(langName, program.length, N) + (st.some(function(s){ return s.note; }) ? "; " + st.map(function(s){ return s.note; }).filter(Boolean).join("; ") : ""));
119
+ var hide = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0;";
120
+ var pre = document.createElement("pre"); pre.className = "sr-only"; pre.setAttribute("style", hide + "white-space:pre"); pre.setAttribute("aria-label", T.readable); pre.setAttribute("data-readable", "");
121
+ pre.textContent = d.code + (all ? "\n\n" + T.output + "\n" + all.replace(/\n$/, "") : ""); this.appendChild(pre);
122
+ var tbl = document.createElement("table"); tbl.className = "sr-only"; tbl.setAttribute("style", hide); tbl.setAttribute("data-readable", ""); tbl.setAttribute("aria-label", T.final);
123
+ var last = st[N - 1].vars, head = document.createElement("tr");
124
+ [T.name, T.value].forEach(function(h){ var th = document.createElement("th"); th.textContent = h; head.appendChild(th); }); tbl.appendChild(head);
125
+ names.filter(function(k){ return k in last; }).forEach(function(k){
126
+ var tr = document.createElement("tr"), th = document.createElement("th"), td = document.createElement("td");
127
+ th.textContent = k; td.textContent = fmt(last[k], py); tr.appendChild(th); tr.appendChild(td); tbl.appendChild(tr);
128
+ });
129
+ this.appendChild(tbl);
130
+ // ---- 配置:左にコードと説明の帯、右に変数と出力
131
+ var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight);
132
+ var fs = P.size || 24, nf = P.size || 26, row = Math.ceil(fs * 1.4), noteRow = Math.ceil(nf * 1.45 + 4), pad = 16, gap = 24, header = row + 16;
133
+ var expanded = program.map(function(s){ return s.replace(/\t/g, " "); });
134
+ var numW = monoWidth(String(program.length), fs) + 16, textX = pad + numW;
135
+ var codeNatural = textX + Math.max(160, Math.max.apply(null, expanded.map(function(s){ return monoWidth(s, fs); }))) + pad;
136
+ var nameW = Math.max(0, Math.max.apply(null, names.map(function(k){ return monoWidth(k + " = ", fs); })));
137
+ var valueW = 0, varRows = 1;
138
+ st.forEach(function(s){
139
+ var r = 0;
140
+ names.forEach(function(k){ if (k in s.vars){ var R = rowsOf(s.vars[k], py); r += R.length; R.forEach(function(t){ valueW = Math.max(valueW, monoWidth(t, fs)); }); } });
141
+ varRows = Math.max(varRows, r);
142
+ });
143
+ var hasOut = all.length > 0, outW = hasOut ? Math.max.apply(null, acc[N - 1].map(function(s){ return monoWidth(s.replace(/\t/g, " "), fs); }).concat([0])) : 0;
144
+ var counterW = monoWidth(N + " / " + N, fs);
145
+ var rightNatural = Math.max(240, 2 * pad + nameW + valueW, 2 * pad + outW, 2 * pad + base.textWidth(T.vars, fs, {font: this}) + 16 + counterW);
146
+ var codeW, rightW;
147
+ if (codeNatural + gap + rightNatural <= W){ codeW = Math.max(codeNatural, Math.min(W * 0.5, W - gap - rightNatural)); }
148
+ else codeW = Math.max(Math.min(codeNatural, W * 0.45), W - gap - rightNatural);
149
+ codeW = Math.max(1, Math.min(codeW, W - gap - 120)); rightW = Math.max(1, W - codeW - gap);
150
+ var rx = codeW + gap;
151
+ // 説明の帯(コードの下、2 行まで)
152
+ var noteLines = st.map(function(s, i){
153
+ if (!s.note) return [];
154
+ var w = C.wrap(s.note.replace(/\s*\n\s*/g, " "), codeW - 24, nf, self);
155
+ if (w.length > 2){ ctx.report("layout", "[trace] note of step " + (i + 1) + " needs " + w.length + " rows in the band (2 fit); shorten it"); w = [w[0], proseCut(w.slice(1).join(""), codeW - 24, nf)]; }
156
+ return w;
157
+ });
158
+ function proseCut(s, width, f){
159
+ if (base.textWidth(s, f, {font: self}) <= width) return s;
160
+ var ch = [...s]; while (ch.length && base.textWidth(ch.join("") + "…", f, {font: self}) > width) ch.pop();
161
+ return width >= f ? ch.join("") + "…" : "";
162
+ }
163
+ var nr = Math.max(0, Math.max.apply(null, noteLines.map(function(w){ return w.length; }))), bandH = nr ? nr * noteRow + 16 : 0;
164
+ var codeH = H - (bandH ? bandH + 8 : 0);
165
+ // コードの見た目の行(長い行は折り返し、続きの行は番号の欄に ↪)
166
+ var textW = Math.max(fs, codeW - textX - pad), vrows = [], rowsOfLine = [];
167
+ program.forEach(function(line, i){
168
+ var ex = expanded[i], chars = [...ex], at = function(m){ return [...line.slice(0, m).replace(/\t/g, " ")].length; }, mine = [];
169
+ C.softWrap(ex, textW, fs).forEach(function(g, j){
170
+ var sp = marks[i].map(function(m){ return [Math.max(at(m[0]), g.from) - g.from, Math.min(at(m[1]), g.to) - g.from, m[2]]; }).filter(function(m){ return m[1] > m[0]; });
171
+ mine.push(vrows.length); vrows.push({line: i + 1, cont: j > 0, text: chars.slice(g.from, g.to).join(""), spans: sp});
172
+ });
173
+ rowsOfLine.push(mine);
174
+ });
175
+ var slots = Math.floor((codeH - header - pad) / row);
176
+ if (slots < 3) ctx.report("size", "[trace] element is " + W + " × " + H + " px; the code needs at least " + Math.ceil(header + pad + 3 * row + (bandH ? bandH + 8 : 0)) + " px height for 3 rows and the notes");
177
+ var shown = Math.max(1, Math.min(slots, vrows.length));
178
+ var span = function(s){ if (!s || !s.a) return null; var r = [].concat.apply([], rowsOfLine.slice(s.a - 1, s.b)); return [Math.min.apply(null, r), Math.max.apply(null, r)]; };
179
+ this.window0 = C.windowFor(vrows.length, shown, 0, 0);
180
+ this.windows = st.map(function(s){ var r = span(s); return r ? C.windowFor(vrows.length, shown, r[0], r[1]) : self.window0; });
181
+ this.spans = st.map(span);
182
+ // 右:変数のパネルと出力のパネル
183
+ var varsH = hasOut ? Math.min(H, header + varRows * row + pad) : H, outY = varsH + 8, outSlots = hasOut ? Math.floor((H - outY - header - pad) / row) : 0;
184
+ if (hasOut && outSlots < 1) ctx.report("size", "[trace] element is " + W + " × " + H + " px; the variables and the output need about " + Math.ceil(header + varRows * row + pad + 8 + header + row + pad) + " px height");
185
+ if (header + varRows * row + pad > H) ctx.report("size", "[trace] the variables need " + varRows + " rows (" + Math.ceil(header + varRows * row + pad) + " px); the element is " + H + " px high");
186
+ var cutValue = false;
187
+ st.forEach(function(s){ names.forEach(function(k){ if (k in s.vars) rowsOf(s.vars[k], py).forEach(function(t){ if (monoWidth(t, fs) > rightW - 2 * pad - nameW) cutValue = true; }); }); });
188
+ if (cutValue) ctx.report("layout", "[trace] a value is wider than the variables panel (" + Math.floor(rightW - 2 * pad - nameW) + " px); it is cut with …");
189
+ this.geo = {W: W, H: H, fs: fs, row: row, pad: pad, header: header, firstY: header + fs, codeW: codeW, codeH: codeH, rx: rx, rightW: rightW, varsH: varsH, outY: outY, outSlots: Math.max(0, outSlots), nameW: nameW, slots: shown, rows: vrows.length, bandH: bandH, varRows: varRows};
190
+ this.geometry = {codeW: codeW, codeH: codeH, rightW: rightW, varsH: varsH, outSlots: Math.max(0, outSlots), slots: shown, rows: vrows.length, windowed: vrows.length > shown, bandRows: nr};
191
+ this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "overflow:hidden"}, this);
192
+ var panel = function(x, y, w, h){ base.el("rect", {x: x + 1, y: y + 1, width: Math.max(1, w - 2), height: Math.max(1, h - 2), rx: 12, fill: "var(--term-tint, color-mix(in srgb, var(--fg) 5%, var(--bg)))", stroke: "var(--line)", "stroke-width": 2}, self.svg); };
193
+ var tint = "var(--emph-tint, color-mix(in srgb, var(--emph) 12%, var(--bg)))";
194
+ // コード
195
+ panel(0, 0, codeW, codeH);
196
+ var tag = cut(lang, Math.max(1, codeW - 2 * pad), fs);
197
+ this.label(this.svg, codeW - pad - monoWidth(tag, fs), pad + fs, tag, fs, "var(--muted)", true);
198
+ this.band = base.el("rect", {x: 4, y: header, width: Math.max(1, codeW - 8), height: row, rx: 4, fill: tint, opacity: 0}, this.svg);
199
+ this.vrows = vrows.map(function(r){
200
+ var num = self.label(self.svg, pad, header + fs, r.cont ? "↪" : String(r.line), fs, "var(--muted)", true);
201
+ var e = self.label(self.svg, textX, header + fs, "", fs, "var(--fg)", true), pos = 0, ch = [...r.text];
202
+ var put = function(a, b, role){ if (b > a) base.el("tspan", role ? {fill: "var(--" + role + ")"} : {}, e).textContent = ch.slice(a, b).join(""); };
203
+ r.spans.forEach(function(m){ put(pos, m[0]); put(m[0], m[1], m[2]); pos = m[1]; });
204
+ put(pos, ch.length);
205
+ return {num: num, text: e, line: r.line};
206
+ });
207
+ this.markTop = this.label(this.svg, pad, header + fs, "", fs, "var(--muted)", true);
208
+ this.markBottom = this.label(this.svg, pad, header + fs, "", fs, "var(--muted)", true);
209
+ // 説明の帯
210
+ this.notes = noteLines.map(function(w){
211
+ var g = base.el("g", {opacity: 0}, self.svg);
212
+ if (w.length){
213
+ base.el("rect", {x: 1, y: codeH + 8, width: Math.max(1, codeW - 2), height: bandH, rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, g);
214
+ w.forEach(function(t, i){ self.label(g, 12, codeH + 8 + 8 + nf + i * noteRow, t, nf); });
215
+ }
216
+ return g;
217
+ });
218
+ // 変数
219
+ panel(rx, 0, rightW, varsH);
220
+ this.label(this.svg, rx + pad, pad + fs, T.vars, fs);
221
+ this.counter = this.label(this.svg, rx + rightW - pad, pad + fs, "", fs, "var(--muted)", true); this.counter.setAttribute("text-anchor", "end");
222
+ var vRoom = Math.max(1, Math.floor((varsH - header - pad) / row));
223
+ this.varSlots = [];
224
+ for (var i = 0; i < Math.min(varRows, vRoom); i++){
225
+ var y = header + fs + i * row;
226
+ this.varSlots.push({
227
+ bg: base.el("rect", {x: rx + 6, y: header + i * row, width: Math.max(1, rightW - 12), height: row, rx: 4, fill: tint, opacity: 0}, this.svg),
228
+ name: this.label(this.svg, rx + pad, y, "", fs, "var(--fg)", true),
229
+ value: this.label(this.svg, rx + pad + nameW, y, "", fs, "var(--fg)", true)
230
+ });
231
+ }
232
+ // 出力
233
+ this.outLabels = [];
234
+ if (hasOut && outSlots >= 1){
235
+ panel(rx, outY, rightW, H - outY);
236
+ this.label(this.svg, rx + pad, outY + pad + fs, T.output, fs);
237
+ for (var j = 0; j < outSlots; j++) this.outLabels.push(this.label(this.svg, rx + pad, outY + header + fs + j * row, "", fs, "var(--fg)", true));
238
+ }
239
+ }
240
+ // (k, t) → トレースの何番目(-1 はまだ何も実行していない)と、その中の進み具合 e(0〜1)
241
+ at(k, t){
242
+ var n = this.st.length, P = this.props;
243
+ if (k < 1) return {i: -1, e: 1};
244
+ if (P.by === "time"){
245
+ if (k > 1 || t === Infinity) return {i: n - 1, e: 1};
246
+ var x = Math.max(0, t) * P.rate, i = Math.min(n - 1, Math.floor(x));
247
+ return {i: i, e: i === n - 1 && x >= n ? 1 : Math.min(1, (x - i) * 2.5)};
248
+ }
249
+ if (k > n) return {i: n - 1, e: 1};
250
+ return {i: k - 1, e: base.prog(t, 0, P.dur)};
251
+ }
252
+ render(k, t, ctx){
253
+ if (!this.svg) return;
254
+ var self = this, G = this.geo, T = this.T, py = this.py, s = this.at(k, t), i = s.i, e = s.e, st = this.st;
255
+ var cur = i >= 0 ? st[i] : null, win = function(j){ return j < 0 ? self.window0 : self.windows[j]; };
256
+ // 表示する範囲:変わるときは前半で消えて後半で新しい位置に出る
257
+ var w0 = win(i - 1), w1 = win(i), moving = w0.f !== w1.f || w0.l !== w1.l, w = moving && e < 0.5 ? w0 : w1, fade = moving ? (e < 0.5 ? 1 - 2 * e : 2 * e - 1) : 1;
258
+ var slotY = function(r, ww){ ww = ww || w; return G.firstY + (r - ww.f + (ww.top ? 1 : 0)) * G.row; };
259
+ this.vrows.forEach(function(o, r){
260
+ var vis = r >= w.f && r <= w.l, y = vis ? slotY(r) : G.firstY, lit = cur && o.line >= cur.a && o.line <= cur.b;
261
+ set(o.num, "y", y); set(o.text, "y", y);
262
+ set(o.num, "opacity", vis ? fade.toFixed(3) : 0); set(o.text, "opacity", vis ? fade.toFixed(3) : 0);
263
+ set(o.num, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--" + (lit ? "emph" : "muted") + ")" + (lit ? ";font-weight:700" : ""));
264
+ });
265
+ var vr = this.vrows, linesIn = function(a, b){ var seen = {}; for (var r = a; r <= b; r++) if (vr[r]) seen[vr[r].line] = 1; return Object.keys(seen).length; };
266
+ this.markTop.textContent = w.top ? T.more(Math.max(1, linesIn(0, w.f - 1))) : ""; set(this.markTop, "y", G.firstY); set(this.markTop, "opacity", w.top ? fade.toFixed(3) : 0);
267
+ this.markBottom.textContent = w.bottom ? T.more(Math.max(1, linesIn(w.l + 1, vr.length - 1))) : ""; set(this.markBottom, "y", slotY(w.l + 1)); set(this.markBottom, "opacity", w.bottom ? fade.toFixed(3) : 0);
268
+ // 今の行の地:同じ表示する範囲の中なら前の行から滑らせる
269
+ var sp1 = i >= 0 ? this.spans[i] : null, sp0 = i >= 1 ? this.spans[i - 1] : null;
270
+ if (sp1){
271
+ var top1 = slotY(sp1[0], w1) - G.fs, h1 = (sp1[1] - sp1[0] + 1) * G.row, top = top1, h = h1, op = 1;
272
+ if (!moving && sp0){ var top0 = slotY(sp0[0], w0) - G.fs, h0 = (sp0[1] - sp0[0] + 1) * G.row; top = base.lerp(top0, top1, e); h = base.lerp(h0, h1, e); }
273
+ else if (moving) op = e < 0.5 ? 0 : fade;
274
+ else op = e;
275
+ set(this.band, "y", +top.toFixed(1)); set(this.band, "height", +h.toFixed(1)); set(this.band, "opacity", op.toFixed(3));
276
+ } else { set(this.band, "y", G.header); set(this.band, "height", G.row); set(this.band, "opacity", 0); }
277
+ this.notes.forEach(function(g, j){ set(g, "opacity", j === i ? (i >= 1 && st[i - 1].note === st[i].note ? 1 : e).toFixed(3) : 0); });
278
+ this.counter.textContent = (i + 1) + " / " + st.length;
279
+ // 変数:その時点の値。変わった変数は字と地と太字で
280
+ var slot = 0, vars = cur ? cur.vars : {};
281
+ this.names.forEach(function(k){
282
+ if (!(k in vars)) return;
283
+ var ch = cur.changed.indexOf(k) >= 0, vx = monoWidth(k + " = ", G.fs);
284
+ rowsOf(vars[k], py).forEach(function(txt, r){
285
+ var o = self.varSlots[slot++]; if (!o) return;
286
+ o.name.textContent = r ? "" : k + " = ";
287
+ set(o.value, "x", +(G.rx + G.pad + vx).toFixed(1));
288
+ o.value.textContent = cut(txt, G.rightW - 2 * G.pad - vx, G.fs);
289
+ set(o.value, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--" + (ch ? "emph" : "fg") + ")" + (ch ? ";font-weight:700" : ""));
290
+ set(o.bg, "opacity", ch ? e.toFixed(3) : 0);
291
+ });
292
+ });
293
+ for (; slot < this.varSlots.length; slot++){ var o = this.varSlots[slot]; o.name.textContent = ""; o.value.textContent = ""; set(o.value, "x", G.rx + G.pad + G.nameW); set(o.value, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--fg)"); set(o.bg, "opacity", 0); }
294
+ // 出力:その時点までの出力。入らなければ新しい行を残し、上に「…(前の n 行)」
295
+ var L = i >= 0 ? this.acc[i] : [], n = this.outLabels.length, from = L.length > n ? L.length - n + 1 : 0;
296
+ var newFrom = i >= 1 ? this.acc[i - 1].length : 0;
297
+ this.outLabels.forEach(function(lab, j){
298
+ var idx = from ? from + j - 1 : j, txt = from && j === 0 ? T.older(from) : idx < L.length ? cut(L[idx].replace(/\t/g, " "), G.rightW - 2 * G.pad, G.fs) : "";
299
+ lab.textContent = txt;
300
+ set(lab, "opacity", !(from && j === 0) && idx >= newFrom && idx < L.length ? e.toFixed(3) : 1);
301
+ set(lab, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--" + (from && j === 0 ? "muted" : "fg") + ")");
302
+ });
303
+ }
304
+ };
305
+ });