egatari 0.6.17 → 0.6.19

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 (171) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/README.ja.md +14 -13
  3. package/README.md +2 -1
  4. package/components.lock.json +153 -54
  5. package/components2.lock.json +1001 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +9 -0
  8. package/kit/check.mjs +8 -0
  9. package/kit/core/bookmark.mjs +28 -0
  10. package/kit/core/build-core.mjs +5 -3
  11. package/kit/core/check-parity.mjs +6 -0
  12. package/kit/core/check-rules.mjs +4 -3
  13. package/kit/core/check-source.mjs +10 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +40 -67
  22. package/kit/core/llm-pack-data.mjs +882 -52
  23. package/kit/core/llm-pack.mjs +6 -4
  24. package/kit/core/llm-request.mjs +2 -2
  25. package/kit/core/new-deck-pack.mjs +38 -44
  26. package/kit/core/new-deck.mjs +82 -74
  27. package/kit/core/part-labels.mjs +3 -0
  28. package/kit/core/portable.mjs +5 -2
  29. package/kit/core/purposes.mjs +9 -3
  30. package/kit/core/sample-info.mjs +17 -3
  31. package/kit/core/scorm.mjs +30 -6
  32. package/kit/core/script-unclosed.mjs +49 -0
  33. package/kit/core/slide-ops.mjs +27 -1
  34. package/kit/core/tate-mix.mjs +25 -0
  35. package/kit/core/template-text.mjs +2 -0
  36. package/kit/core/theme-derive.mjs +56 -17
  37. package/kit/core/theme-shapes.mjs +15 -1
  38. package/kit/deck.js +124 -6
  39. package/kit/instruction-version.json +1 -1
  40. package/kit/layouts.css +8 -0
  41. package/kit/llm-pack.mjs +5 -7
  42. package/kit/panes.js +17 -1
  43. package/kit/player.json +1 -1
  44. package/kit/player.lock.json +2 -2
  45. package/kit/presenter.js +36 -4
  46. package/kit/tools.js +54 -2
  47. package/kit/track.js +46 -5
  48. package/package.json +1 -1
  49. package/server/editor-ui.js +21 -1
  50. package/vendor/components/CATALOG.md +25 -22
  51. package/vendor/components/sha256/038f9d32c89c8212ab25d6e3180023b6fe024a53053ab2ef1443ecab92e3ce43/index.js +205 -0
  52. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/README.en.md +44 -0
  53. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/index.js +306 -0
  54. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/README.en.md +54 -0
  55. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/index.js +470 -0
  56. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/README.en.md +23 -0
  57. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/index.js +289 -0
  58. package/vendor/components/sha256/0c25d49d23529879054737aa181951519fe585c4728fd505e0e3c8869953eac7/index.js +934 -0
  59. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/LICENSE-strokesvg.txt +115 -0
  60. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/OFL.txt +93 -0
  61. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/index.js +755 -0
  62. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/strokes-CHANGES.md +20 -0
  63. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/README.en.md +25 -0
  64. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/index.js +317 -0
  65. package/vendor/components/sha256/12ef6a11055407f5cddc40154a49cf2737b0786429fe0fcc94ee1d8245597b40/index.js +244 -0
  66. package/vendor/components/sha256/13c9ce43396b2f5693ce430a924dae4ddcd1e8a4ad0c9b9e724ff52acb874d0c/index.js +354 -0
  67. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  68. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  69. package/vendor/components/sha256/1a0f21def0efbbdef64461cafa40f3883bc7f7122adf79d01f09ca4a245e5dcb/index.js +465 -0
  70. package/vendor/components/sha256/208175d05b37d326855fad792b10137f785e5d05d91a2cde119d0dbd69d2ed98/index.js +100 -0
  71. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/README.en.md +34 -0
  72. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/index.js +246 -0
  73. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/README.en.md +24 -0
  74. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/index.js +554 -0
  75. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  76. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  77. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/README.en.md +28 -0
  78. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/index.js +214 -0
  79. package/vendor/components/sha256/2a011338d0fc3c77e102eaa57cde2b6e3726bc279f133174b0b8c9a654263cbc/index.js +824 -0
  80. package/vendor/components/sha256/2fce5ab0c31dca0aa1586a2c69237870a9cce46c0bc6ab7392c27968d016bd15/index.js +75 -0
  81. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/README.en.md +23 -0
  82. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/index.js +150 -0
  83. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/README.en.md +18 -0
  84. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/index.js +279 -0
  85. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  86. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  87. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/README.en.md +42 -0
  88. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/index.js +272 -0
  89. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/README.en.md +30 -0
  90. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/index.js +305 -0
  91. package/vendor/components/sha256/4c8cae404d551a1bb021e8345af5aa45d4f412f13497aa84b142f11a29a365dc/index.js +124 -0
  92. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/README.en.md +23 -0
  93. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/index.js +120 -0
  94. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/README.en.md +18 -0
  95. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/index.js +243 -0
  96. package/vendor/components/sha256/631f4c4b90c9a41c0f26c9600d5cf2d6447251d04a20f08f48a85aeb4cb0f6fb/index.js +107 -0
  97. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/README.en.md +31 -0
  98. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/index.js +271 -0
  99. package/vendor/components/sha256/701f1deef79fe05eeb18e1119e5a5c4d60a9dfe265e93a4dff79223bc598dbf0/index.js +521 -0
  100. package/vendor/components/sha256/711cf58fa946c9c0abc953b2f695d02bf5a5a7f73851b09f834e894baf88be38/index.js +122 -0
  101. package/vendor/components/sha256/728576c57a5ccb39531ad4cb8074fce95480f01603a77dbf57dca0e52199f7c4/index.js +37 -0
  102. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/README.en.md +18 -0
  103. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/index.js +382 -0
  104. package/vendor/components/sha256/76bdb63c3e5e14fbb4816bc9f235490817bb5d7be990a826f5077aa08226702c/index.js +162 -0
  105. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/README.en.md +51 -0
  106. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/index.js +230 -0
  107. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/README.en.md +26 -0
  108. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/index.js +322 -0
  109. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/README.en.md +18 -0
  110. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/index.js +103 -0
  111. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  112. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  113. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ABCJS-ADAPTER.md +101 -0
  114. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/LICENSE-abcjs.txt +21 -0
  115. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/chords.json +89 -0
  116. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/doremi.json +261 -0
  117. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/extras.json +192 -0
  118. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/kaeru.json +521 -0
  119. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/rhythm.json +248 -0
  120. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ties.json +360 -0
  121. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/index.js +508 -0
  122. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/README.en.md +22 -0
  123. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/index.js +145 -0
  124. package/vendor/components/sha256/8a4b6dce84d7a69aaafeb75c1c572fe7904fd49e3169c1c85851ccaeae2a7b11/index.js +41 -0
  125. package/vendor/components/sha256/8bb511cb90902bc7721e59ca08685b26adbf33539e36a4a45172485d6d3d455b/index.js +250 -0
  126. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/README.en.md +21 -0
  127. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/index.js +108 -0
  128. package/vendor/components/sha256/8e5e90c90cb6b06a790b0420e43d79d7da663f1cc19ff06d381ec849b4a8fc57/index.js +312 -0
  129. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  130. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  131. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  132. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  133. package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
  134. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  135. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  136. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/README.en.md +38 -0
  137. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/index.js +414 -0
  138. package/vendor/components/sha256/aac2f8a23cb1b606e9635061cb288f006588c80a7258540cae846ae677f55ff5/index.js +238 -0
  139. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/README.en.md +45 -0
  140. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/index.js +211 -0
  141. package/vendor/components/sha256/aeb0b9b5991a5c1df7191c397780a699f2c7310123ca210a58486c0a23e44006/index.js +342 -0
  142. package/vendor/components/sha256/af3355efd6739a56c6cb53990100f41703361c475c123b9b2762421c68509036/index.js +315 -0
  143. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/LICENSE-tabler.txt +21 -0
  144. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/index.js +4868 -0
  145. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/names.txt +4808 -0
  146. package/vendor/components/sha256/b348ea64cc19632df96a91dfd7c435e4a62095aede72b504d03537be70d6d930/index.js +606 -0
  147. package/vendor/components/sha256/b53bfa03d1e9feb3cb492f440bf9d100c96eb4fe6b76c42b512a56e9158829cd/index.js +351 -0
  148. package/vendor/components/sha256/b9443e1cdac4850b1ead9f8449a3061678bbb77fbc53eb9b23d01e1cf50750c3/index.js +619 -0
  149. package/vendor/components/sha256/bc1e2a02c959ac203819d03c0d25b3776a6a9a4290aae860b26cbbe3d29e876d/index.js +268 -0
  150. package/vendor/components/sha256/beeb180c0e2250bb04490b092c0a235cae47fca2ed1de2d9ef078a5c14b1a963/index.js +429 -0
  151. package/vendor/components/sha256/c5fd7713e55e96d75824a21146c0251896d7d9dd028b4d169191433135a97981/index.js +200 -0
  152. package/vendor/components/sha256/c61987e9994940fc668ed8a010e575ee52027b54ed9c5dd1cc9fdf67649092b3/index.js +404 -0
  153. package/vendor/components/sha256/ccc8bfe174b6903ec254dfef4f5d1c614271ea39963649add7fcb8d83c081eba/index.js +278 -0
  154. package/vendor/components/sha256/da267bc65fde0a9279127d5a82f6c253ad74984da6fb11391f00604ad9ffe80d/index.js +93 -0
  155. package/vendor/components/sha256/dea36cd7010991a572ef394ee32b5e17564aeff09d3ec4ed3820d7e43c9a58be/index.js +484 -0
  156. package/vendor/components/sha256/df3fdb2aed487d4f6e60a8abab1fe0d1e9fa2a4193fd162edf3c384ea8db5a1b/index.js +180 -0
  157. package/vendor/components/sha256/e27d517f39eb554c7a9ecea7b59fcf1d347c4deeb3fe2250797aa233bfb7e2b0/index.js +747 -0
  158. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/README.en.md +20 -0
  159. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/index.js +310 -0
  160. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/README.en.md +30 -0
  161. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/index.js +192 -0
  162. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/README.en.md +24 -0
  163. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/index.js +214 -0
  164. package/vendor/components-2/manifest-2.16.0.json +2919 -0
  165. package/vendor/components-2/manifest-2.17.0.json +2852 -0
  166. package/vendor/components-2/manifest-2.18.0.json +3182 -0
  167. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  168. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  169. package/vendor/egatari-spec/SOURCE.json +2 -2
  170. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  171. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,223 @@
1
+ // m-curves:同じ座標軸に線を 1 本ずつ引く。線の名前は凡例でなく線の端に直接書く
2
+ // <m-curves xr="[-3,3]" yr="[0,0.5]" xt="[-2,0,2]" yt="[0,0.2,0.4]" xl="*y*" yl="密度" style="height:380px">
3
+ // <script type="application/json">[{"label":"予測分布","f":"N(x,0,1)"},{"label":"中央値","pts":[[0,0],[0,0.4]],"dash":true}]
4
+ // (JSON の終わり)</m-curves>
5
+ // 1 系列 = 1 段階(書いた順。系列の step で変えられ、同じ step の系列は一緒に引く)。f は x の式(Math の関数と N(x,平均,標準偏差) が使える)、pts は点列
6
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・previewOpacity、plot の Plot、expr の compile を使い、
7
+ // プレイヤーのグローバルは使わない(1.x は式の評価器 egatari-expr を写して持っていた)。破線の mask の id は
8
+ // curves-2-2-1-<n>m<系列>:このパーツの名前と版に、このパーツだけの数え(1.x は mc<n>m<系列> で、DECK.Plot の数えを進めていた)
9
+ egatariParts.define({name: "curves", version: "2.4.0", requires: {base: "1.3.0", expr: "1.0.0", plot: "1.1.3"}, element: "m-curves"}, function(deps){
10
+ "use strict";
11
+ var base = deps.base, plot = deps.plot, expr = deps.expr;
12
+ var ID = "curves-2-3-1-"; // name and version of this part, dots replaced (spec §6.1 Identifiers)
13
+ var count = 0; // this part's own counter for its ids (deterministic: the order of mounting)
14
+ // 線の名前(26px)の下付き・上付きの分の高さ(px)。base 1.1.0 で mtext の下付き・上付きは 24px 以上になり、下付きの字の下端は基線から
15
+ // 添字の 0.75 倍まで、上付きの字の上端は 1.4 倍まで届く(Source Sans 3 で測った値。BIZ UDPGothic ではそれぞれ 0.5 倍と 1.2 倍)。
16
+ // 字の下の余白(字の 0.12 倍)・上の高さ(0.88 倍)を超える分。記法がなければ 0
17
+ function subX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /_./.test(s) ? Math.max(0, 0.75 * ss - 0.12 * fs) : 0; }
18
+ function supX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /\^./.test(s) ? Math.max(0, 1.4 * ss - 0.88 * fs) : 0; }
19
+ return class extends base.MotionElement {
20
+ static partName = "curves"; // the registry name (define meta name), for report prefixes
21
+ // データの形(kit/shape.js):線の配列。軸(xr yr xt yt xl yl)は属性に書く(JSON の中ではない)
22
+ static shape = {
23
+ schema: {type: "array", items: {type: "object", additionalProperties: false, anyOf: [{required: ["f"]}, {required: ["pts"]}],
24
+ properties: {label: {type: "string"}, f: {type: "string"}, pts: {type: "array", items: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2}},
25
+ tone: {type: "string"}, step: {type: "integer"}, labelAt: {type: "number"},
26
+ color: {type: "string"}, dash: {type: "boolean"}, xr: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2},
27
+ area: {type: "array"}, areaLabel: {type: ["string", "array"]},
28
+ at: {type: "number"}, anchor: {enum: ["right", "left", "above", "below", "top", "bottom", "start", "middle", "end"]}, dx: {type: "number"}, dy: {type: "number"}, ly: {type: "number"}}}},
29
+ example: [{label: "需要 D", f: "10 - x"}, {label: "供給 S", f: "2 + x"}, {label: "均衡", pts: [[4, 0], [4, 6]], dash: true}],
30
+ // よくある書き違い(指示の部品の一覧に書く)
31
+ note: {en: "the data is the array itself, not {\"series\": […]}; axes go in attributes (xr=\"[0,10]\" xl=\"…\"); the expression field is f in x (not fn, not u)",
32
+ ja: "データは配列そのもの({\"series\": […]} ではない)。軸は属性に書く(xr=\"[0,10]\" xl=\"…\")。式の欄は f で、変数は x(fn・u ではない)"},
33
+ };
34
+ static props = {
35
+ xr: {type: "json", default: [0, 1], doc: "横軸の範囲"}, yr: {type: "json", default: [0, 1], doc: "縦軸の範囲"},
36
+ xt: {type: "json", default: []}, yt: {type: "json", default: []},
37
+ xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
38
+ xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
39
+ n: {type: "number", default: 300, doc: "f を描く分割数"},
40
+ dur: {type: "number", default: 1.0, doc: "1 本を引く秒数"},
41
+ lw: {type: "number", default: 3.5, doc: "線の太さ"},
42
+ size: {type: "number", default: 0, doc: "字の大きさ(24 以上。0 = 既定)"},
43
+ };
44
+ // 系列 i の段階:step(書いてあれば)、なければ i + 1。段階の数はその最大(step がなければ系列の数で、今までと同じ)
45
+ stepOf(s, i){ return s && s.step !== undefined ? s.step : i + 1; }
46
+ get steps(){
47
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
48
+ var self = this, m = 0;
49
+ (this.data || []).forEach(function(s, i){ m = Math.max(m, self.stepOf(s, i)); });
50
+ return m;
51
+ }
52
+ mount(ctx){
53
+ var P = this.props, D = base, self = this, S = this.data || [];
54
+ this.classList.add("plot"); this.style.display = "block";
55
+ // size:字の大きさ(24 未満は 24 にして知らせる)。0 なら 2.0 と同じ大きさと余白
56
+ var SZ = P.size > 0 ? Math.max(24, P.size) : 0, K = SZ ? SZ / 26 : 1, F = SZ || 26;
57
+ if (P.size > 0 && P.size < 24) ctx.report("attr", "[curves] size " + P.size + " is under 24 px; 24 is used");
58
+ // 字の目盛り(2.4.0):xt に字("4月"。i 番目は x = i + 1)か [x, "字"] があれば、目盛りは自分で描く(plot は数だけを書く)
59
+ var XT = Array.isArray(P.xt) ? P.xt : [], named = XT.some(function(v){ return typeof v === "string" || Array.isArray(v); });
60
+ var ticks = named ? XT.map(function(v, i){ return typeof v === "string" ? [i + 1, v] : Array.isArray(v) ? [+v[0], String(v[1] === undefined ? v[0] : v[1])] : [+v, null]; }) : null;
61
+ var p = this.p = plot.Plot(this, {xr: P.xr, yr: P.yr, xt: named ? [] : P.xt, yt: P.yt, xf: P.xf, yf: P.yf, xl: P.xl, yl: P.yl, fs: SZ || undefined, m: {l: Math.round(86 * K), r: 24, t: Math.round(24 * K), b: Math.round(64 * K)}});
62
+ if (ticks) {
63
+ // plot 1.1.3 と同じ線と位置(字の大きさ fs のときは 6 + fs 下、なければ 30 下)。数の目盛りは xf の桁で書く
64
+ var ax = p.svg.querySelector(".axes") || p.svg, yb = p.H - p.m.b, dX = SZ ? 6 + SZ : 30;
65
+ ticks.forEach(function(t){
66
+ var x = p.x(t[0]), lab = t[1] !== null ? t[1] : (P.xf !== undefined ? t[0].toFixed(P.xf) : String(t[0])).replace("-", "−");
67
+ D.el("line", {x1: x, y1: yb, x2: x, y2: yb + 6, stroke: "var(--fg)", "stroke-width": 1.5}, ax);
68
+ D.mtext(ax, x, yb + dX, lab, SZ ? {"text-anchor": "middle", "font-size": SZ} : {"text-anchor": "middle"});
69
+ });
70
+ }
71
+ var uid = ID + (++count), defs = D.el("defs", {}, p.svg);
72
+ var N = function(x, m, s){ return Math.exp(-0.5 * Math.pow((x - m) / s, 2)) / (s * Math.sqrt(2 * Math.PI)); };
73
+ var x0 = p.m.l, x1 = p.W - p.m.r, y0 = p.m.t, y1 = p.H - p.m.b;
74
+ // 系列ごとに:点列、線、(破線なら)描く範囲の mask、端の名前
75
+ this.items = S.map(function(s, i){
76
+ var pts;
77
+ var raw;
78
+ if (s.pts){ raw = s.pts; pts = s.pts.map(function(q){ return [p.x(q[0]), p.y(q[1])]; }); }
79
+ else {
80
+ // 式は木にしてから計算する(コードとしては実行しない。Egatari spec §6)。書けない式は SyntaxError で、base が受け止めて札を出す(spec §6.1 Containment)
81
+ var g = expr.compile(s.f, {name: "[" + i + "].f", vars: ["x"], funcs: {N: N}, bareMath: true}), a = s.xr ? s.xr[0] : P.xr[0], b = s.xr ? s.xr[1] : P.xr[1];
82
+ pts = []; raw = [];
83
+ for (var j = 0; j <= P.n; j++){ var v = a + (b - a) * j / P.n, w = g(v); raw.push([v, w]); pts.push([p.x(v), p.y(w)]); }
84
+ }
85
+ // 軸の範囲を書かなかったとき(既定の [0, 1])に線が範囲の外に出るなら知らせる(切れて平らな線に見えるため。書いた範囲で切るのは意図とみなす)
86
+ [["xr", 0], ["yr", 1]].forEach(function(ax){
87
+ if (self.hasAttribute(ax[0])) return;
88
+ var r = P[ax[0]], lo = Math.min(r[0], r[1]), hi = Math.max(r[0], r[1]), tol = (hi - lo) * 1e-9, vs = raw.map(function(q){ return q[ax[1]]; }).filter(function(v){ return typeof v === "number" && isFinite(v); });
89
+ var out = vs.filter(function(v){ return v < lo - tol || v > hi + tol; });
90
+ if (out.length) ctx.report("range", "[curves] series " + i + " (" + JSON.stringify(s.label || "") + "): " + out.length + " of " + vs.length + " points are outside " + ax[0] + " " + JSON.stringify(r) + " (the default; values from " + +Math.min.apply(null, vs).toPrecision(4) + " to " + +Math.max.apply(null, vs).toPrecision(4) + "), so the line is cut at the edge. Write " + ax[0] + " to cover them");
91
+ });
92
+ // 有限でない点(NaN・±Infinity)は線を切り、有限な区間ごとに M から引き直す(1 つの NaN で線全体が消えない)
93
+ var d = "", pen = false, gap = false;
94
+ pts.forEach(function(q){
95
+ if (isFinite(q[0]) && isFinite(q[1])){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; }
96
+ else { pen = false; gap = true; }
97
+ });
98
+ if (gap) ctx.report("data", "[curves] series " + i + " (" + JSON.stringify(s.label || "") + ") has points that are not finite numbers (NaN or ±Infinity, e.g. log or division by zero); the line is broken there");
99
+ pts = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]); });
100
+ var col = colorOf(s.tone || s.color, i);
101
+ var it = {step: self.stepOf(s, i)};
102
+ if (s.dash){
103
+ // 破線は dasharray を描画に使えないので、同じ線を mask にして引く
104
+ var mk = D.el("mask", {id: uid + "m" + i, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: p.W, height: p.H}, defs);
105
+ it.mpath = D.el("path", {d: d, fill: "none", stroke: "#fff", "stroke-width": P.lw + 6, pathLength: 1, "stroke-dasharray": "1 2"}, mk);
106
+ var gg = D.el("g", {mask: "url(#" + uid + "m" + i + ")", "clip-path": p.clip}, p.svg);
107
+ it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "stroke-dasharray": "10 8", "stroke-linecap": "butt"}, gg);
108
+ it.draw = it.mpath;
109
+ } else {
110
+ it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "clip-path": p.clip, pathLength: 1, "stroke-dasharray": "1 2", "stroke-linejoin": "round"}, p.svg);
111
+ it.draw = it.path;
112
+ }
113
+ // 面積(area:[a, b] か [[a, b], …]。null は軸の端):線と横軸(y = 0、範囲の外なら下の端)のあいだを、その区間だけ薄く塗る。
114
+ // 棄却域・p 値・信頼区間・確率など。線が引き終わってから出る(名前と同じ時に)。areaLabel は区間ごとに中に書く(字の列なら区間の順に)
115
+ if (s.area !== undefined){
116
+ var A = Array.isArray(s.area) && s.area.length && Array.isArray(s.area[0]) ? s.area : [s.area];
117
+ var yb = p.y(Math.max(Math.min(P.yr[0], P.yr[1]), Math.min(Math.max(P.yr[0], P.yr[1]), 0))), ad = "", segs = [];
118
+ A.forEach(function(r){
119
+ if (!Array.isArray(r) || r.length !== 2 || r.some(function(v){ return v !== null && !(typeof v === "number" && isFinite(v)); })){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " is not [from, to] (numbers, or null for the edge)"); return; }
120
+ var la = p.x(r[0] === null ? P.xr[0] : r[0]), lb = p.x(r[1] === null ? P.xr[1] : r[1]);
121
+ if (la > lb){ var tt = la; la = lb; lb = tt; }
122
+ var seg = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]) && q[0] >= la - 0.01 && q[0] <= lb + 0.01; });
123
+ if (seg.length < 2){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " has no part of the line in it"); return; }
124
+ ad += "M" + seg[0][0].toFixed(1) + "," + yb.toFixed(1) + seg.map(function(q){ return "L" + q[0].toFixed(1) + "," + q[1].toFixed(1); }).join("") + "L" + seg[seg.length - 1][0].toFixed(1) + "," + yb.toFixed(1) + "Z";
125
+ segs.push({w: seg[seg.length - 1][0] - seg[0][0], seg: seg});
126
+ });
127
+ if (ad){
128
+ it.area = D.el("path", {d: ad, fill: col, "fill-opacity": 0.28, stroke: "none", "clip-path": p.clip, opacity: 0}, p.svg);
129
+ p.svg.insertBefore(it.area, s.dash ? it.path.parentNode : it.path); // 線の下に
130
+ // 区間の名前:区間の真ん中の上(線より上、字の高さぶん離す)。細い区間でも読めるように線の上に置き、背景色で縁取る
131
+ it.areaLabs = [];
132
+ segs.forEach(function(o, j){
133
+ var t = Array.isArray(s.areaLabel) ? s.areaLabel[j] : s.areaLabel;
134
+ if (!t) return;
135
+ var mid = o.seg[Math.floor(o.seg.length / 2)], top = Math.min.apply(null, o.seg.map(function(q){ return q[1]; }));
136
+ var tx = Math.max(x0 + 4, Math.min(x1 - 4, mid[0])), ty = Math.max(y0 + F, top - 10);
137
+ it.areaLabs.push(D.mtext(p.svg, tx, ty, t, {"text-anchor": "middle", fill: col, stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": F, "font-weight": 700, opacity: 0}));
138
+ });
139
+ }
140
+ }
141
+ // 名前の位置:labelAt(横軸の値)の点、なければ描画範囲の中の最後の点。at は labelAt の古い名前(labelAt がないときだけ)
142
+ var inside = pts.filter(function(q){ return q[0] >= x0 - .5 && q[0] <= x1 + .5 && q[1] >= y0 - .5 && q[1] <= y1 + .5; });
143
+ var end = inside.length ? inside[inside.length - 1] : pts[pts.length - 1];
144
+ var lat = s.labelAt !== undefined ? s.labelAt : s.at;
145
+ if (!end){ it.lx = it.ly = it.x0 = it.x1 = 0; it.anchor = "start"; it.col = col; it.label = ""; return it; } // 有限な点がない:名前は書かない
146
+ if (lat !== undefined){
147
+ var ax = p.x(lat), best = pts[0];
148
+ pts.forEach(function(q){ if (Math.abs(q[0] - ax) < Math.abs(best[0] - ax)) best = q; });
149
+ end = best;
150
+ }
151
+ // anchor:right(点の右から書く)・left(点の左で終わる)・above / below(点の上・下に中央そろえ、約 0.9 字ぶん離す)。
152
+ // start / middle / end は古い書き方(text-anchor そのもの)で、今までどおり
153
+ var an = {top: "above", bottom: "below"}[s.anchor] || s.anchor; // top / bottom は above / below の別名
154
+ var side = {right: "start", left: "end", above: "middle", below: "middle"}, anchor = side[an] || an || (end[0] > x1 - 160 ? "end" : "start");
155
+ var ly0 = an === "above" ? end[1] - Math.round(14 * K) : an === "below" ? end[1] + Math.round(32 * K) : end[1] - Math.round(12 * K);
156
+ if (an === "below" && ly0 > y1 - 4) ly0 = end[1] - Math.round(14 * K); // 下に入らなければ上へ
157
+ it.lx = end[0] + (anchor === "end" ? -8 : anchor === "start" ? 10 : 0) + (s.dx || 0);
158
+ it.ly = (s.ly !== undefined ? p.y(s.ly) : ly0) + (s.dy || 0);
159
+ // 字の幅の見積もり(26px。base の textWidth:テーマの字で測った幅。記法の * _ ^ を除く)
160
+ var w = D.textWidth(s.label || "", F, {font: self, mark: true});
161
+ it.x0 = anchor === "end" ? it.lx - w : anchor === "middle" ? it.lx - w / 2 : it.lx; it.x1 = it.x0 + w;
162
+ it.anchor = anchor; it.col = col; it.label = s.label || "";
163
+ return it;
164
+ });
165
+ // 名前どうしが重ならないように、横に重なる名前を下へずらす。先に描く高さ(上は 26、下は横軸の 6 px 上)に収めてから離し、
166
+ // 下に収まらなければ下から上へ押し戻す(目盛りの数字にかからない)。上付きのある名前は上端を、下付きのある名前は下端を
167
+ // その分だけ内に、上の名前の下付き・下の名前の上付きの分だけ間を広げる(記法がなければ今までと同じ)
168
+ var min = Math.round(32 * K), lo = F, hi = y1 - 6, ov = function(u, v){ return u.x0 < v.x1 && v.x0 < u.x1; };
169
+ var loOf = function(it){ return lo + supX(it.label, F); }, hiOf = function(it){ return hi - subX(it.label, F); };
170
+ var gap = function(u, v){ return min + subX(u.label, F) + supX(v.label, F); }; // u が上、v が下
171
+ var g = self.items.filter(function(it){ return it.label; });
172
+ g.forEach(function(it){ it.ly = Math.min(hiOf(it), Math.max(loOf(it), it.ly)); });
173
+ g.sort(function(u, v){ return u.ly - v.ly; });
174
+ g.forEach(function(it, j){
175
+ for (var q = 0; q < j; q++){
176
+ var o = g[q];
177
+ if (ov(it, o) && it.ly - o.ly < gap(o, it)) it.ly = o.ly + gap(o, it);
178
+ }
179
+ });
180
+ for (var j = g.length - 1; j >= 0; j--){
181
+ var it = g[j];
182
+ it.ly = Math.min(hiOf(it), it.ly);
183
+ for (var q = j + 1; q < g.length; q++) if (ov(it, g[q]) && g[q].ly - it.ly < gap(it, g[q])) it.ly = g[q].ly - gap(it, g[q]);
184
+ }
185
+ g.forEach(function(it){ it.ly = Math.max(loOf(it), it.ly); });
186
+ this.items.forEach(function(it){
187
+ it.lab = D.mtext(p.svg, it.lx, it.ly, it.label, {"text-anchor": it.anchor, fill: it.col, "font-size": F, "font-weight": 700, opacity: 0});
188
+ });
189
+ // tone:テーマの色の名前か var(--…)。知らない名前は既定の色(series-1..4 の順)にして知らせる
190
+ function colorOf(c, i){
191
+ var def = "var(--series-" + (i % 4 + 1) + ")";
192
+ if (!c) return def;
193
+ if (c.indexOf("var(") === 0) return c;
194
+ var nm = c.replace(/^--/, "");
195
+ if (/^(term|emph|accent2|muted|fg|line|series-[1-4])$/.test(nm)) return "var(--" + nm + ")";
196
+ ctx.report("attr", "[curves] series " + i + ": tone " + JSON.stringify(c) + " is not term, emph, accent2, muted, fg or series-1..4 (" + def.slice(6, -1) + " is used)");
197
+ return def;
198
+ }
199
+ }
200
+ duration(k){ return k >= 1 ? this.props.dur * 0.7 + 0.6 : 0; }
201
+ render(k, t, ctx){
202
+ var dur = this.props.dur, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0;
203
+ // 先を薄く見せる表示:後の段階の線と名前を、引き終えた形のままテーマの --preview-opacity(なければ 0.45)で描く
204
+ this.items.forEach(function(it){
205
+ if (preview && it.step > k){
206
+ it.draw.setAttribute("stroke-dashoffset", (0).toFixed(4));
207
+ it.path.setAttribute("opacity", PV);
208
+ it.lab.setAttribute("opacity", PV.toFixed(3));
209
+ if (it.area) it.area.setAttribute("opacity", PV.toFixed(3));
210
+ (it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", PV.toFixed(3)); });
211
+ return;
212
+ }
213
+ var pd = it.step < k ? 1 : it.step === k ? base.prog(t, 0, dur) : 0;
214
+ var pl = it.step < k ? 1 : it.step === k ? base.prog(t, dur * 0.7, 0.6) : 0;
215
+ it.draw.setAttribute("stroke-dashoffset", (1 - pd).toFixed(4));
216
+ it.path.setAttribute("opacity", pd > 0 ? 1 : 0);
217
+ it.lab.setAttribute("opacity", pl.toFixed(3));
218
+ if (it.area) it.area.setAttribute("opacity", pl.toFixed(3));
219
+ (it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", pl.toFixed(3)); });
220
+ });
221
+ }
222
+ };
223
+ });
@@ -0,0 +1,42 @@
1
+ ---
2
+ summary: Pie/donut; labels inside big slices, leader lines for small
3
+ steps: 1 (all at once); per-step n slices; or slice step
4
+ props:
5
+ donut: inner radius ratio (0 = pie)
6
+ unit: value unit
7
+ digits: value decimals
8
+ pct-digits: percent decimals
9
+ show: pct, value, both or none
10
+ per-step: slices per step (0 = all)
11
+ dur: step seconds
12
+ example: {"slices": [{"label": "Food", "value": 7.2}, {"label": "Housing", "value": 8.5}, {"label": "Other", "value": 2.1, "tone": "muted"}]}
13
+ ---
14
+
15
+ Shares of a whole, all at once. Fine comparison: `m-bars`.
16
+
17
+ Child JSON: `{"slices": [...], "center": "…"}`.
18
+
19
+ - slice: `label`, `value` (percent computed), `tone` (`term` `emph` `accent2` `muted` `fg` `series-1..4`), `step`, `place` (`auto` default, `in`, `out`)
20
+ - Clockwise from 12 in order; "Other" last, `"tone": "muted"`
21
+ - ≤ 6–7 slices
22
+ - `center`: hole text, a string (`\n`; `{total}` = sum, e.g. `"Answers\n{total}"`); `m-cycle`'s `center` is an object
23
+ - `donut`: `0.5`–`0.6`
24
+ - `show` (under name): `pct` (default), `value`, `both`, `none`
25
+ - `unit` `digits`: value unit, decimals; `pct-digits` (default 0). Percents rounded to sum to 100%
26
+ - Steps: all at step 1; `per-step="1"` only if narrated slice by slice (outline faint). Slice `step` wins
27
+ - `variant`: `fade` (default), `sweep` (clockwise from 12), `grow` (rim grows out)
28
+
29
+ The demo is `demo.html`. All numbers are fictional.
30
+
31
+ <!-- llm: omit -->
32
+ Notes
33
+
34
+ - Default colours `--series-1..3`, slices 4–6 lighter, 7th `--series-4`. Values: thousands commas
35
+ - Inside labels on dark slices use bg colour; one-sided outside labels centre with the pie
36
+ - Labels inside if they fit, else in side columns with leader lines, de-overlapped
37
+ - Show later steps faintly (`ctx.preview`): later slices faint
38
+ - `sweep`: names after all slices are out
39
+ - Text width estimated from characters; "fits inside" = all 4 label-box corners in the sector (`show="both"` also tries 2 lines)
40
+ - Reported (`ctx.report`): outside labels too tall or too wide, hole text wider than the hole, negative values
41
+ - Motion: `fade` rises 12 px; `grow` rim from 12 px inside (conventions §1.2); `sweep` does not move
42
+ <!-- llm: end -->
@@ -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 -->