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.
- package/CHANGELOG.md +68 -1
- package/README.ja.md +14 -13
- package/README.md +2 -1
- package/components.lock.json +153 -54
- package/components2.lock.json +1001 -1
- package/kit/build.mjs +1 -1
- package/kit/check-messages.mjs +9 -0
- package/kit/check.mjs +8 -0
- package/kit/core/bookmark.mjs +28 -0
- package/kit/core/build-core.mjs +5 -3
- package/kit/core/check-parity.mjs +6 -0
- package/kit/core/check-rules.mjs +4 -3
- package/kit/core/check-source.mjs +10 -1
- package/kit/core/checks.mjs +79 -0
- package/kit/core/find-replace.mjs +170 -0
- package/kit/core/format.mjs +4 -1
- package/kit/core/image-insert.mjs +197 -0
- package/kit/core/image-size.mjs +1 -1
- package/kit/core/layout-scan.mjs +1 -1
- package/kit/core/llm-fix.mjs +1 -1
- package/kit/core/llm-pack-assemble.mjs +40 -67
- package/kit/core/llm-pack-data.mjs +882 -52
- package/kit/core/llm-pack.mjs +6 -4
- package/kit/core/llm-request.mjs +2 -2
- package/kit/core/new-deck-pack.mjs +38 -44
- package/kit/core/new-deck.mjs +82 -74
- package/kit/core/part-labels.mjs +3 -0
- package/kit/core/portable.mjs +5 -2
- package/kit/core/purposes.mjs +9 -3
- package/kit/core/sample-info.mjs +17 -3
- package/kit/core/scorm.mjs +30 -6
- package/kit/core/script-unclosed.mjs +49 -0
- package/kit/core/slide-ops.mjs +27 -1
- package/kit/core/tate-mix.mjs +25 -0
- package/kit/core/template-text.mjs +2 -0
- package/kit/core/theme-derive.mjs +56 -17
- package/kit/core/theme-shapes.mjs +15 -1
- package/kit/deck.js +124 -6
- package/kit/instruction-version.json +1 -1
- package/kit/layouts.css +8 -0
- package/kit/llm-pack.mjs +5 -7
- package/kit/panes.js +17 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/presenter.js +36 -4
- package/kit/tools.js +54 -2
- package/kit/track.js +46 -5
- package/package.json +1 -1
- package/server/editor-ui.js +21 -1
- package/vendor/components/CATALOG.md +25 -22
- package/vendor/components/sha256/038f9d32c89c8212ab25d6e3180023b6fe024a53053ab2ef1443ecab92e3ce43/index.js +205 -0
- package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/README.en.md +44 -0
- package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/index.js +306 -0
- package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/README.en.md +54 -0
- package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/index.js +470 -0
- package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/README.en.md +23 -0
- package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/index.js +289 -0
- package/vendor/components/sha256/0c25d49d23529879054737aa181951519fe585c4728fd505e0e3c8869953eac7/index.js +934 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/LICENSE-strokesvg.txt +115 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/OFL.txt +93 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/index.js +755 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/strokes-CHANGES.md +20 -0
- package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/README.en.md +25 -0
- package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/index.js +317 -0
- package/vendor/components/sha256/12ef6a11055407f5cddc40154a49cf2737b0786429fe0fcc94ee1d8245597b40/index.js +244 -0
- package/vendor/components/sha256/13c9ce43396b2f5693ce430a924dae4ddcd1e8a4ad0c9b9e724ff52acb874d0c/index.js +354 -0
- package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
- package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
- package/vendor/components/sha256/1a0f21def0efbbdef64461cafa40f3883bc7f7122adf79d01f09ca4a245e5dcb/index.js +465 -0
- package/vendor/components/sha256/208175d05b37d326855fad792b10137f785e5d05d91a2cde119d0dbd69d2ed98/index.js +100 -0
- package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/README.en.md +34 -0
- package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/index.js +246 -0
- package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/README.en.md +24 -0
- package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/index.js +554 -0
- package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
- package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
- package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/README.en.md +28 -0
- package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/index.js +214 -0
- package/vendor/components/sha256/2a011338d0fc3c77e102eaa57cde2b6e3726bc279f133174b0b8c9a654263cbc/index.js +824 -0
- package/vendor/components/sha256/2fce5ab0c31dca0aa1586a2c69237870a9cce46c0bc6ab7392c27968d016bd15/index.js +75 -0
- package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/README.en.md +23 -0
- package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/index.js +150 -0
- package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/README.en.md +18 -0
- package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/index.js +279 -0
- package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
- package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
- package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/README.en.md +42 -0
- package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/index.js +272 -0
- package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/README.en.md +30 -0
- package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/index.js +305 -0
- package/vendor/components/sha256/4c8cae404d551a1bb021e8345af5aa45d4f412f13497aa84b142f11a29a365dc/index.js +124 -0
- package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/README.en.md +23 -0
- package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/index.js +120 -0
- package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/README.en.md +18 -0
- package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/index.js +243 -0
- package/vendor/components/sha256/631f4c4b90c9a41c0f26c9600d5cf2d6447251d04a20f08f48a85aeb4cb0f6fb/index.js +107 -0
- package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/README.en.md +31 -0
- package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/index.js +271 -0
- package/vendor/components/sha256/701f1deef79fe05eeb18e1119e5a5c4d60a9dfe265e93a4dff79223bc598dbf0/index.js +521 -0
- package/vendor/components/sha256/711cf58fa946c9c0abc953b2f695d02bf5a5a7f73851b09f834e894baf88be38/index.js +122 -0
- package/vendor/components/sha256/728576c57a5ccb39531ad4cb8074fce95480f01603a77dbf57dca0e52199f7c4/index.js +37 -0
- package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/README.en.md +18 -0
- package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/index.js +382 -0
- package/vendor/components/sha256/76bdb63c3e5e14fbb4816bc9f235490817bb5d7be990a826f5077aa08226702c/index.js +162 -0
- package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/README.en.md +51 -0
- package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/index.js +230 -0
- package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/README.en.md +26 -0
- package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/index.js +322 -0
- package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/README.en.md +18 -0
- package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/index.js +103 -0
- package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
- package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/chords.json +89 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/extras.json +192 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ties.json +360 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/index.js +508 -0
- package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/README.en.md +22 -0
- package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/index.js +145 -0
- package/vendor/components/sha256/8a4b6dce84d7a69aaafeb75c1c572fe7904fd49e3169c1c85851ccaeae2a7b11/index.js +41 -0
- package/vendor/components/sha256/8bb511cb90902bc7721e59ca08685b26adbf33539e36a4a45172485d6d3d455b/index.js +250 -0
- package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/README.en.md +21 -0
- package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/index.js +108 -0
- package/vendor/components/sha256/8e5e90c90cb6b06a790b0420e43d79d7da663f1cc19ff06d381ec849b4a8fc57/index.js +312 -0
- package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
- package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
- package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
- package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
- package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
- package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
- package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
- package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/README.en.md +38 -0
- package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/index.js +414 -0
- package/vendor/components/sha256/aac2f8a23cb1b606e9635061cb288f006588c80a7258540cae846ae677f55ff5/index.js +238 -0
- package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/README.en.md +45 -0
- package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/index.js +211 -0
- package/vendor/components/sha256/aeb0b9b5991a5c1df7191c397780a699f2c7310123ca210a58486c0a23e44006/index.js +342 -0
- package/vendor/components/sha256/af3355efd6739a56c6cb53990100f41703361c475c123b9b2762421c68509036/index.js +315 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/index.js +4868 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/names.txt +4808 -0
- package/vendor/components/sha256/b348ea64cc19632df96a91dfd7c435e4a62095aede72b504d03537be70d6d930/index.js +606 -0
- package/vendor/components/sha256/b53bfa03d1e9feb3cb492f440bf9d100c96eb4fe6b76c42b512a56e9158829cd/index.js +351 -0
- package/vendor/components/sha256/b9443e1cdac4850b1ead9f8449a3061678bbb77fbc53eb9b23d01e1cf50750c3/index.js +619 -0
- package/vendor/components/sha256/bc1e2a02c959ac203819d03c0d25b3776a6a9a4290aae860b26cbbe3d29e876d/index.js +268 -0
- package/vendor/components/sha256/beeb180c0e2250bb04490b092c0a235cae47fca2ed1de2d9ef078a5c14b1a963/index.js +429 -0
- package/vendor/components/sha256/c5fd7713e55e96d75824a21146c0251896d7d9dd028b4d169191433135a97981/index.js +200 -0
- package/vendor/components/sha256/c61987e9994940fc668ed8a010e575ee52027b54ed9c5dd1cc9fdf67649092b3/index.js +404 -0
- package/vendor/components/sha256/ccc8bfe174b6903ec254dfef4f5d1c614271ea39963649add7fcb8d83c081eba/index.js +278 -0
- package/vendor/components/sha256/da267bc65fde0a9279127d5a82f6c253ad74984da6fb11391f00604ad9ffe80d/index.js +93 -0
- package/vendor/components/sha256/dea36cd7010991a572ef394ee32b5e17564aeff09d3ec4ed3820d7e43c9a58be/index.js +484 -0
- package/vendor/components/sha256/df3fdb2aed487d4f6e60a8abab1fe0d1e9fa2a4193fd162edf3c384ea8db5a1b/index.js +180 -0
- package/vendor/components/sha256/e27d517f39eb554c7a9ecea7b59fcf1d347c4deeb3fe2250797aa233bfb7e2b0/index.js +747 -0
- package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/README.en.md +20 -0
- package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/index.js +310 -0
- package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/README.en.md +30 -0
- package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/index.js +192 -0
- package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/README.en.md +24 -0
- package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/index.js +214 -0
- package/vendor/components-2/manifest-2.16.0.json +2919 -0
- package/vendor/components-2/manifest-2.17.0.json +2852 -0
- package/vendor/components-2/manifest-2.18.0.json +3182 -0
- package/vendor/components-2/manifest-2.20.0.json +3217 -0
- package/vendor/components-2/manifest-2.21.0.json +3220 -0
- package/vendor/egatari-spec/SOURCE.json +2 -2
- package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
- package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// m-code: a program, successive line explanations, then its supplied output. Never executes code.
|
|
2
|
+
// 2.2.0: the drawing helpers live in code-core. Whenever 2.1.0's layout fits (no layout report), the same layout is drawn.
|
|
3
|
+
// Otherwise (code taller or wider than the box, a note too long for the band, or a step that lists 3+ lines) the fit layout
|
|
4
|
+
// is drawn instead: notes in the band (up to 2 rows), long lines soft-wrapped under a "↪" gutter, and a moving window of rows
|
|
5
|
+
// centred on each step's lines with "⋮" markers for the hidden ones. The full source and output stay in a child
|
|
6
|
+
// <pre data-readable> (the readable layer copies it as visible text).
|
|
7
|
+
egatariParts.define({name: "code", version: "2.2.1", requires: {base: "1.3.0", "code-core": "1.0.1"}, element: "m-code"}, function(deps){
|
|
8
|
+
"use strict";
|
|
9
|
+
var base = deps.base, MONO = deps["code-core"].MONO;
|
|
10
|
+
var TEXT = {
|
|
11
|
+
ja: {output: "出力", run: "▶ 実行", readable: "コードと出力", summary: function(lang, n, output){ return (lang || "プログラム") + " のコード " + n + " 行" + (output ? "と出力" : ""); }},
|
|
12
|
+
en: {output: "Output", run: "▶ Run", readable: "Code and output", summary: function(lang, n, output){ return (lang || "Program") + ": " + n + " lines of code" + (output ? " and output" : ""); }}
|
|
13
|
+
};
|
|
14
|
+
var C = deps["code-core"], set = C.set, lines = C.lines, monoWidth = C.monoWidth, cut = C.cut, spans = C.spans, wrap = C.wrap;
|
|
15
|
+
return class extends base.MotionElement {
|
|
16
|
+
static partName = "code";
|
|
17
|
+
static shape = {schema: {type: "object", additionalProperties: false, required: ["code", "steps"], properties: {
|
|
18
|
+
code: {type: "string"}, lang: {type: "string"}, output: {type: "string"},
|
|
19
|
+
steps: {type: "array", items: {type: "object", additionalProperties: false, required: ["lines", "note"], properties: {
|
|
20
|
+
lines: {type: "array", minItems: 1, maxItems: 16, items: {type: ["integer", "array"], minItems: 2, maxItems: 2, items: {type: "integer"}}}, note: {type: "string"}
|
|
21
|
+
}}}
|
|
22
|
+
}}, example: /*@egatari-block example*/{"lang":"python","code":"import pandas as pd\ndf = pd.read_csv(\"sales.csv\")\ndf.groupby(\"store\")[\"sales\"].mean()","steps":[{"lines":[1],"note":"pandas を読み込む"},{"lines":[2],"note":"CSV を表として読む"},{"lines":[3],"note":"店ごとの平均"}],"output":"store\nA 120.5\nB 98.0"}/*@egatari-block-end*/};
|
|
23
|
+
static props = {
|
|
24
|
+
dur: {type: "number", default: 0.6, doc: "ステップの秒数"},
|
|
25
|
+
size: {type: "number", default: 0, doc: "文字 px(0 は既定)"},
|
|
26
|
+
outputPos: {type: "enum", values: ["auto", "below", "right"], default: "auto", doc: "出力の位置"}
|
|
27
|
+
};
|
|
28
|
+
get steps(){ return this.data.steps.length + 1 + (this.data.output !== undefined ? 1 : 0); }
|
|
29
|
+
duration(k){ return k >= 1 && k <= this.steps ? this.props.dur : 0; }
|
|
30
|
+
label(g, x, y, s, fs, color, mono){
|
|
31
|
+
var e = base.el("text", {x: x, y: y, "font-size": fs, fill: color || "var(--fg)"}, g);
|
|
32
|
+
// 等幅と空白:テーマの `svg text{font-family}` は属性より強いので style に書く。行頭の字下げを残す(white-space: pre)
|
|
33
|
+
if (mono){ e.setAttribute("style", (e.getAttribute("style") || "") + "font-family:" + MONO + ";white-space:pre;"); }
|
|
34
|
+
e.textContent = s; return e;
|
|
35
|
+
}
|
|
36
|
+
mount(ctx){
|
|
37
|
+
// [[3, 4]] is read as [3, 4] (one range per step); any other nesting is a range problem below
|
|
38
|
+
var self = this, d = Object.assign({}, this.data, {steps: this.data.steps.map(function(s, j){
|
|
39
|
+
var r = s.lines.length === 1 && Array.isArray(s.lines[0]) ? s.lines[0] : s.lines;
|
|
40
|
+
if (r.some(Array.isArray)){ ctx.report("range", "[code] steps[" + j + "].lines: one range per step, e.g. [3, 4]"); return {lines: [0], note: s.note, nested: true}; }
|
|
41
|
+
// 3 つ以上の整数は、その行だけ(飛び飛びでよい)。1〜2 個は今までどおり 1 行か範囲
|
|
42
|
+
if (r.length >= 3) return {lines: [Math.min.apply(null, r), Math.max.apply(null, r)], set: r.slice().sort(function(x, y){ return x - y; }), note: s.note};
|
|
43
|
+
return {lines: r, note: s.note};
|
|
44
|
+
})}), P = this.props, T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
45
|
+
if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[code] dur must be positive; using 0.6"); P.dur = 0.6; }
|
|
46
|
+
if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[code] size must be 0 or at least 24; using defaults"); P.size = 0; }
|
|
47
|
+
if (!["auto", "below", "right"].includes(P.outputPos)){ ctx.report("attr", "[code] invalid outputPos; using auto"); P.outputPos = "auto"; }
|
|
48
|
+
// 大きさを測る前にブロックにする(インラインのままだと幅が 0 になる)
|
|
49
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
|
|
50
|
+
this.fs = P.size || 24; this.noteSize = P.size || 26;
|
|
51
|
+
var fs = this.fs, nf = this.noteSize, row = Math.ceil(fs * 1.4), noteRow = Math.ceil(nf * 1.45 + 4);
|
|
52
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), program = lines(d.code), output = d.output === undefined ? [] : lines(d.output);
|
|
53
|
+
var lang = d.lang || "", marks = spans(program, lang.toLowerCase());
|
|
54
|
+
this.setAttribute("role", "figure"); // 中の読める pre が読まれるように(img の子は読まれない)
|
|
55
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.summary(lang.toLowerCase() === "python" ? "Python" : lang, program.length, d.output !== undefined) + "; " + d.steps.map(function(s){ return s.note; }).join("; "));
|
|
56
|
+
// Keep the full source readable inside the figure even when the SVG is truncated.
|
|
57
|
+
var pre = document.createElement("pre"); pre.className = "sr-only";
|
|
58
|
+
pre.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:pre;border:0");
|
|
59
|
+
pre.setAttribute("aria-label", T.readable); pre.setAttribute("data-readable", "");
|
|
60
|
+
pre.textContent = d.code + (d.output !== undefined ? "\n\n" + T.output + "\n" + d.output : ""); this.appendChild(pre);
|
|
61
|
+
this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
|
|
62
|
+
var header = row + 16, pad = 16, gap = 32, numW = monoWidth(String(program.length), fs) + 16;
|
|
63
|
+
var expanded = program.map(function(s){ return s.replace(/\t/g, " "); });
|
|
64
|
+
var longest = expanded.reduce(function(a, b){ return monoWidth(a, fs) >= monoWidth(b, fs) ? a : b; }, "");
|
|
65
|
+
var natural = Math.max(160, monoWidth(longest, fs)) + numW + 2 * pad;
|
|
66
|
+
var outNatural = Math.max(monoWidth(T.output, fs) + monoWidth(T.run, fs) + pad + 8, ...output.slice(0, 8).map(function(s){ return monoWidth(s.replace(/\t/g, " "), fs); })) + 2 * pad;
|
|
67
|
+
var outputH = output.length ? header + row * Math.min(8, output.length) + pad : 0;
|
|
68
|
+
var right = output.length > 0 && (P.outputPos === "right" || P.outputPos === "auto" && program.length <= 8 && natural + 280 + outNatural + 2 * gap <= W);
|
|
69
|
+
var outW = right ? Math.max(120, Math.min(outNatural, W * 0.3)) : 0;
|
|
70
|
+
var available = W - (right ? outW + gap : 0), codeW = natural;
|
|
71
|
+
var nx = codeW + gap, nw = Math.max(1, available - nx);
|
|
72
|
+
var areaH = H - (!right && output.length ? outputH + 16 : 0), nextY = header;
|
|
73
|
+
// Keep the beside layout only if *all* the notes fit at their line targets.
|
|
74
|
+
var beside = natural <= W * 0.55 && natural + gap + 260 <= available;
|
|
75
|
+
d.steps.forEach(function(s){
|
|
76
|
+
var a = s.lines[0], b = s.lines.length === 2 ? s.lines[1] : a;
|
|
77
|
+
var target = header + ((a + b - 2) / 2 + 0.5) * row;
|
|
78
|
+
var h = Math.max(1, wrap(s.note, nw - 24, nf, self).length) * noteRow + 16;
|
|
79
|
+
nextY = Math.max(nextY, target - h / 2) + h + 8;
|
|
80
|
+
if (nextY - 8 > areaH) beside = false;
|
|
81
|
+
});
|
|
82
|
+
this.noteLayout = beside ? "beside" : "band";
|
|
83
|
+
if (!beside){
|
|
84
|
+
// 出力は、コードの横に入るなら右に(幅で決める。短い出力なら広いコードの横にも入る)
|
|
85
|
+
right = output.length > 0 && (P.outputPos === "right" || P.outputPos === "auto" && natural + gap + Math.max(120, outNatural) <= W);
|
|
86
|
+
outW = right ? Math.max(120, Math.min(outNatural, W - gap - natural)) : 0;
|
|
87
|
+
available = W - (right ? outW + gap : 0);
|
|
88
|
+
codeW = Math.max(1, Math.min(natural, available));
|
|
89
|
+
nx = 0; nw = right ? codeW : W;
|
|
90
|
+
areaH = H - (!right && output.length ? outputH + 16 : 0);
|
|
91
|
+
}
|
|
92
|
+
// 下帯の最終一覧:説明ごとに行の範囲を付け(「3–4:…」)、説明の途中では折らずに行へ詰める。字は 24px、行間は字の箱 1.45em
|
|
93
|
+
var listFont = Math.max(24, nf - 2), listRow = Math.ceil(listFont * 1.45);
|
|
94
|
+
var items = d.steps.map(function(s){ var r = Array.isArray(s.lines) ? s.lines : []; var x = r[0], y = r.length > 1 ? r[1] : r[0]; return x + (y === x ? "" : "–" + y) + (T === TEXT.ja ? ":" : ": ") + s.note.replace(/\s*\n\s*/g, " "); });
|
|
95
|
+
// 出力が下に回るときは説明帯の右に並べ、帯と出力の高い方だけを使う
|
|
96
|
+
var sideW = Math.max(120, outNatural);
|
|
97
|
+
var side = !beside && !right && output.length > 0 && P.outputPos === "auto" && d.steps.length > 0 && outNatural <= W * 0.45 && W - sideW - gap >= W * 0.4;
|
|
98
|
+
if (side){ nw = W - sideW - gap; areaH = H; }
|
|
99
|
+
var list = [];
|
|
100
|
+
if (!beside && d.steps.length){
|
|
101
|
+
var cur = "", sep = T === TEXT.ja ? " " : " ";
|
|
102
|
+
items.forEach(function(t){
|
|
103
|
+
var cand = cur ? cur + sep + t : t;
|
|
104
|
+
if (cur && base.textWidth(cand, listFont, {font: self}) > nw - 24){ list.push(cur); cur = t; } else cur = cand;
|
|
105
|
+
});
|
|
106
|
+
if (cur) list.push(cur);
|
|
107
|
+
}
|
|
108
|
+
// 高さの式は 1 つ:コード部 + 帯(一覧 r 行)と横の出力の高い方 + 下の出力。報告もこの式で数える
|
|
109
|
+
function bandFor(r){ return r ? noteRow + 16 + (r - 1) * listRow : 0; }
|
|
110
|
+
function need(n, r){ var zone = Math.max(bandFor(r), side ? outputH : 0); return Math.ceil(header + n * row + pad + (zone ? 8 + zone : 0) + (!right && !side && output.length ? outputH + 16 : 0)); }
|
|
111
|
+
var want = Math.min(16, program.length), rows = list.length, fullList = true;
|
|
112
|
+
function fitsAt(h, r){ return Math.max(0, Math.floor((h - need(0, r)) / row)); }
|
|
113
|
+
var capacity = fitsAt(H, rows);
|
|
114
|
+
if (capacity < want && rows > 1 && fitsAt(H, 1) >= want){ fullList = false; capacity = fitsAt(H, 1); } // コードを全部残し、最終一覧は最後の説明だけ
|
|
115
|
+
var bandH = bandFor(fullList ? rows : Math.min(1, rows)), bandSpace = bandH ? bandH + 8 : 0;
|
|
116
|
+
var count = Math.min(want, capacity), codeH = header + count * row + pad;
|
|
117
|
+
var neededH = need(want, rows), SLIDE = 440;
|
|
118
|
+
function advice(){
|
|
119
|
+
return neededH <= SLIDE ? "give the element about " + neededH + " px" : "more than a slide body under a heading (about " + SLIDE + " px) holds; " + SLIDE + " px fits " + Math.min(want, fitsAt(SLIDE, rows)) + " lines with these notes: show fewer lines, shorten notes or split the slide";
|
|
120
|
+
}
|
|
121
|
+
var textX = pad + numW, firstY = header + fs, textW = Math.max(0, codeW - textX - pad);
|
|
122
|
+
// 2.1.0 の配置で収まらないとき(報告が出るとき)だけ、収める配置に切り替える
|
|
123
|
+
var noteTooLong = !beside && d.steps.some(function(s){
|
|
124
|
+
var a = s.lines[0], b = s.lines.length === 2 ? s.lines[1] : a, pre = (T === TEXT.ja ? a + (b === a ? "" : "–" + b) + " 行目" : (a === b ? "line " + a : "lines " + a + "–" + b)) + " · ";
|
|
125
|
+
return base.textWidth(s.note, nf, {font: self}) > Math.max(0, nw - 24 - base.textWidth(pre, nf, {font: self})) || lines(s.note).length > 1;
|
|
126
|
+
});
|
|
127
|
+
if (count < program.length || monoWidth(longest, fs) > textW || noteTooLong || d.steps.some(function(s){ return s.set; })){
|
|
128
|
+
this.fit = true; return this.mountFit(ctx, d, T, program, output, marks, lang);
|
|
129
|
+
}
|
|
130
|
+
if (count < program.length) ctx.report("layout", "[code] " + program.length + " lines; this height fits " + Math.min(16, capacity) + " (" + advice() + (neededH <= SLIDE ? ", or show fewer lines" : "") + ")" + (program.length > 16 ? "; at most 16 lines per panel" : ""));
|
|
131
|
+
if (monoWidth(longest, fs) > textW) ctx.report("layout", "[code] the longest line is " + [...longest].length + " characters; this width fits " + Math.floor(textW / (0.6 * fs)) + " at " + fs + "px (break the line)");
|
|
132
|
+
this.geometry = {side: side, listRows: rows, codeW: codeW, codeH: codeH, nx: nx, nw: nw, row: row, firstY: firstY, right: right, count: count, neededH: neededH, bandH: bandH, noteLayout: this.noteLayout};
|
|
133
|
+
this.codeLayer = base.el("g", {opacity: 0}, this.svg);
|
|
134
|
+
function panel(g, x, y, w, h){ base.el("rect", {x: x, y: y, width: Math.max(1, w), height: Math.max(1, h), rx: 12, fill: "var(--term-tint, color-mix(in srgb, var(--fg) 5%, var(--bg)))", stroke: "var(--line)", "stroke-width": 2}, g); }
|
|
135
|
+
panel(this.codeLayer, 1, 1, codeW - 2, codeH - 2);
|
|
136
|
+
var tagW = Math.max(1, codeW - 2 * pad), tag = cut(lang, tagW, fs);
|
|
137
|
+
if (count || H >= header + pad) this.label(this.codeLayer, codeW - pad - monoWidth(tag, fs), pad + fs, tag, fs, "var(--muted)", true);
|
|
138
|
+
this.bands = d.steps.map(function(){ return base.el("rect", {x: 4, y: header, width: Math.max(1, codeW - 8), height: row, fill: "var(--emph-tint, color-mix(in srgb, var(--emph) 12%, var(--bg)))", opacity: 0}, self.codeLayer); });
|
|
139
|
+
if (tag !== lang) ctx.report("layout", "[code] language tag needs " + Math.ceil(monoWidth(lang, fs)) + " px; header fits " + Math.floor(tagW) + " px");
|
|
140
|
+
this.numbers = [];
|
|
141
|
+
for (var i = 0; i < count; i++){
|
|
142
|
+
var y = firstY + i * row, original = program[i].replace(/\t/g, " "), s = cut(original, Math.max(0, codeW - textX - pad), fs);
|
|
143
|
+
if (i === count - 1 && count < program.length) s = cut(s + "…", Math.max(0, codeW - textX - pad), fs);
|
|
144
|
+
this.numbers.push(this.label(this.codeLayer, pad, y, String(i + 1), fs, "var(--muted)", true));
|
|
145
|
+
// One <text> per line; coloured runs are tspans, so the browser's own advance places them (indices after tab expansion)
|
|
146
|
+
var e = this.label(this.codeLayer, textX, y, "", fs, "var(--fg)", true), pos = 0, line = program[i];
|
|
147
|
+
var put = function(a, b, role){ if (b > a) base.el("tspan", role ? {fill: "var(--" + role + ")"} : {}, e).textContent = s.slice(a, b); };
|
|
148
|
+
marks[i].forEach(function(m){
|
|
149
|
+
var a = Math.min(s.length, line.slice(0, m[0]).replace(/\t/g, " ").length), b = Math.min(s.length, line.slice(0, m[1]).replace(/\t/g, " ").length);
|
|
150
|
+
put(pos, a); put(a, b, m[2]); pos = b;
|
|
151
|
+
});
|
|
152
|
+
put(pos, s.length);
|
|
153
|
+
}
|
|
154
|
+
if (count === 0 || W < 360 || textW < fs){
|
|
155
|
+
ctx.report("size", "[code] element is " + W + " × " + H + " px; allow at least 360 × " + Math.ceil(header + row + pad + bandSpace) + " px for one code line and notes");
|
|
156
|
+
}
|
|
157
|
+
// Even unusably small boxes retain a clipped panel and an ellipsis.
|
|
158
|
+
this.svg.setAttribute("style", "overflow:hidden");
|
|
159
|
+
if (!count) this.label(this.codeLayer, Math.min(pad, W / 4), Math.min(fs, H), "…", fs);
|
|
160
|
+
nextY = header;
|
|
161
|
+
var bandY = codeH + 8, bandRoom = Math.max(0, areaH - bandY);
|
|
162
|
+
function proseCut(s, width, f){
|
|
163
|
+
f = f || nf;
|
|
164
|
+
if (base.textWidth(s, f, {font: self}) <= width) return s;
|
|
165
|
+
var chars = [...s];
|
|
166
|
+
while (chars.length && base.textWidth(chars.join("") + "…", f, {font: self}) > width) chars.pop();
|
|
167
|
+
return width >= f ? chars.join("") + "…" : "";
|
|
168
|
+
}
|
|
169
|
+
function marker(a, b){ return T === TEXT.ja ? a + (b === a ? "" : "–" + b) + " 行目" : (a === b ? "line " + a : "lines " + a + "–" + b); }
|
|
170
|
+
this.notes = d.steps.map(function(s, j){
|
|
171
|
+
var a = s.lines[0], b = s.lines.length === 2 ? s.lines[1] : a;
|
|
172
|
+
var valid = a >= 1 && b >= a && b <= program.length;
|
|
173
|
+
if (!valid && !s.nested) ctx.report("range", "[code] steps[" + j + "].lines must be an inclusive range within 1–" + program.length);
|
|
174
|
+
var target = valid && a <= count ? header + ((a - 1 + Math.min(b, count) - 1) / 2 + 0.5) * row : header;
|
|
175
|
+
var g = base.el("g", {opacity: 0}, self.svg), text, top, h, labels;
|
|
176
|
+
if (beside){
|
|
177
|
+
text = wrap(s.note, nw - 24, nf, self); h = Math.max(noteRow, text.length * noteRow) + 16;
|
|
178
|
+
top = Math.max(nextY, target - h / 2);
|
|
179
|
+
if (valid && a <= count) base.el("path", {d: "M " + codeW + " " + target + " H " + (nx - 12) + " V " + (top + h / 2) + " H " + nx, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, g);
|
|
180
|
+
base.el("rect", {x: nx, y: top, width: nw - 1, height: h, rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, g);
|
|
181
|
+
labels = text.map(function(t, k){ return self.label(g, nx + 12, top + 8 + nf + k * noteRow, t, nf); });
|
|
182
|
+
nextY = top + h + 8;
|
|
183
|
+
} else {
|
|
184
|
+
top = bandY; h = Math.min(bandFor(1), bandRoom);
|
|
185
|
+
var prefix = marker(a, b) + " · ", prefixW = base.textWidth(prefix, nf, {font: self}), room = Math.max(0, nw - 24 - prefixW);
|
|
186
|
+
var width = base.textWidth(s.note, nf, {font: self});
|
|
187
|
+
if (width > room || lines(s.note).length > 1){
|
|
188
|
+
var approx = Math.max(0, Math.floor([...s.note].length * room / Math.max(1, width)));
|
|
189
|
+
ctx.report("layout", "[code] note " + (j + 1) + " is too long for the band (" + Math.ceil(width) + " px of " + Math.floor(room) + "); shorten it to about " + approx + " characters");
|
|
190
|
+
}
|
|
191
|
+
base.el("rect", {x: 1, y: top, width: Math.max(1, nw - 2), height: Math.max(1, h), rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, g);
|
|
192
|
+
labels = [self.label(g, 12, top + 8 + nf, proseCut(prefix + s.note.replace(/\s*\n\s*/g, " "), nw - 24), nf)];
|
|
193
|
+
}
|
|
194
|
+
if (valid && a <= count){ set(self.bands[j], "y", header + (a - 1) * row); set(self.bands[j], "height", (Math.min(b, count) - a + 1) * row); }
|
|
195
|
+
return {g: g, labels: labels, a: a, b: b, valid: valid && a <= count, top: top, height: h, fits: true};
|
|
196
|
+
});
|
|
197
|
+
this.finalNotes = base.el("g", {opacity: 0}, this.svg);
|
|
198
|
+
if (!beside && d.steps.length){
|
|
199
|
+
list = list.map(function(t){ return proseCut(t, nw - 24, listFont); });
|
|
200
|
+
if (!fullList || bandFor(list.length) > bandRoom){
|
|
201
|
+
// 最後の説明だけを残す(説明はすべて読み上げの要約にある)。報告にはせず、要素に印を付ける
|
|
202
|
+
this.setAttribute("data-fit", "last-note");
|
|
203
|
+
list = [proseCut(items[items.length - 1], nw - 24, listFont)];
|
|
204
|
+
}
|
|
205
|
+
base.el("rect", {x: 1, y: bandY, width: Math.max(1, nw - 2), height: Math.max(1, Math.min(bandRoom, bandFor(list.length))), rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, this.finalNotes);
|
|
206
|
+
list.forEach(function(s, i){ self.label(self.finalNotes, 12, bandY + 8 + nf + i * listRow, s, listFont); });
|
|
207
|
+
}
|
|
208
|
+
this.outputLayer = base.el("g", {opacity: 0}, this.svg);
|
|
209
|
+
if (output.length){
|
|
210
|
+
var ox = right ? W - outW : side ? W - sideW : 0, oy = right ? 0 : side ? codeH + 8 : areaH + 16, ow = right ? outW : side ? sideW : codeW;
|
|
211
|
+
var oc = Math.max(0, Math.min(8, output.length, Math.floor((H - oy - header - pad) / row)));
|
|
212
|
+
panel(this.outputLayer, ox + 1, oy + 1, ow - 2, header + oc * row + pad - 2);
|
|
213
|
+
self.label(this.outputLayer, ox + pad, oy + pad + fs, cut(T.output, ow - 2 * pad, fs), fs);
|
|
214
|
+
// Run precedes the supplied plain text in a separate header region.
|
|
215
|
+
var run = cut(T.run, ow - 2 * pad - monoWidth(T.output, fs) - pad, fs);
|
|
216
|
+
self.label(this.outputLayer, ox + ow - pad - monoWidth(run, fs), oy + pad + fs, run, fs, "var(--muted)", true);
|
|
217
|
+
var outputCut = oc < output.length || run !== T.run || monoWidth(T.output, fs) > ow - 2 * pad;
|
|
218
|
+
output.slice(0, oc).forEach(function(s, i){
|
|
219
|
+
var txt = cut(s.replace(/\t/g, " "), ow - 2 * pad, fs);
|
|
220
|
+
if (i === oc - 1 && oc < output.length) txt = cut(txt + "…", ow - 2 * pad, fs);
|
|
221
|
+
if (txt !== s) outputCut = true;
|
|
222
|
+
self.label(self.outputLayer, ox + pad, oy + header + fs + i * row, txt, fs, "var(--fg)", true);
|
|
223
|
+
});
|
|
224
|
+
if (outputCut) ctx.report("layout", "[code] output exceeds eight lines or panel width/height; showing what fits with …");
|
|
225
|
+
}
|
|
226
|
+
if (outputH > H) ctx.report("size", "[code] output needs " + outputH + " px height; element has " + H + " px");
|
|
227
|
+
}
|
|
228
|
+
// 収める配置(2.2.0):説明は下の帯(2 行まで)、長い行は折り返し(続きの行は番号の欄に ↪)、行が多ければステップごとに
|
|
229
|
+
// そのステップの行が中央に来るようにスクロールして表示する(隠れた行は ⋮ と数)。表示する範囲はステップの前半で消え、後半で新しい位置に出る((k, t) だけで決まる)
|
|
230
|
+
mountFit(ctx, d, T, program, output, marks, lang){
|
|
231
|
+
var self = this, P = this.props, fs = this.fs, nf = this.noteSize, row = Math.ceil(fs * 1.4), noteRow = Math.ceil(nf * 1.45 + 4);
|
|
232
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), header = row + 16, pad = 16, gap = 32, ja = T === TEXT.ja;
|
|
233
|
+
this.ja = ja;
|
|
234
|
+
var outNatural = Math.max(monoWidth(T.output, fs) + monoWidth(T.run, fs) + pad + 8, ...output.slice(0, 8).map(function(s){ return monoWidth(s.replace(/\t/g, " "), fs); })) + 2 * pad;
|
|
235
|
+
var outputH = output.length ? header + row * Math.min(8, output.length) + pad : 0;
|
|
236
|
+
var right = output.length > 0 && (P.outputPos === "right" || P.outputPos === "auto" && W - gap - Math.max(120, outNatural) >= W * 0.55);
|
|
237
|
+
var outW = right ? Math.max(120, Math.min(outNatural, W * 0.4)) : 0, codeW = right ? W - outW - gap : W;
|
|
238
|
+
// 出力が下に回るとき、帯が幅の 4 割以上残るなら、出力は帯の右に並べる(帯と出力の高い方だけ使う)
|
|
239
|
+
var sideW = Math.max(120, outNatural), side = !right && output.length > 0 && P.outputPos === "auto" && d.steps.length > 0 && W - sideW - gap >= W * 0.4;
|
|
240
|
+
var numW = monoWidth(String(program.length), fs) + 16, textX = pad + numW, textW = Math.max(fs, codeW - textX - pad), firstY = header + fs;
|
|
241
|
+
// 見た目の行:元の行ごとに折り返す。色の範囲は字下げを広げた後の位置に直して、行の切れ目で分ける
|
|
242
|
+
var vrows = [], rowsOf = [];
|
|
243
|
+
program.forEach(function(line, i){
|
|
244
|
+
var ex = line.replace(/\t/g, " "), chars = [...ex], at = function(m){ return [...line.slice(0, m).replace(/\t/g, " ")].length; };
|
|
245
|
+
var segs = C.softWrap(ex, textW, fs), mine = [];
|
|
246
|
+
segs.forEach(function(g, j){
|
|
247
|
+
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]; });
|
|
248
|
+
mine.push(vrows.length); vrows.push({line: i + 1, cont: j > 0, text: chars.slice(g.from, g.to).join(""), spans: sp});
|
|
249
|
+
});
|
|
250
|
+
rowsOf.push(mine);
|
|
251
|
+
});
|
|
252
|
+
var stepRows = d.steps.map(function(s){
|
|
253
|
+
var want = s.set ? s.set : s.lines.length === 2 ? range(s.lines[0], s.lines[1]) : [s.lines[0]];
|
|
254
|
+
var ok = want.every(function(n){ return n >= 1 && n <= program.length; }) && !s.nested && (s.set || s.lines.length === 1 || s.lines[1] >= s.lines[0]);
|
|
255
|
+
if (!ok && !s.nested) ctx.report("range", "[code] steps[" + d.steps.indexOf(s) + "].lines must be within 1–" + program.length);
|
|
256
|
+
var rs = ok ? [].concat.apply([], want.map(function(n){ return rowsOf[n - 1]; })) : [];
|
|
257
|
+
return {lines: ok ? want : [], rows: rs};
|
|
258
|
+
});
|
|
259
|
+
function range(a, b){ var o = []; for (var i = a; i <= b; i++) o.push(i); return o; }
|
|
260
|
+
// 帯の説明:「3–4 行目 · 説明」を 2 行までに折る。3 行以上なら 2 行目の末を … にして知らせる
|
|
261
|
+
var nw = side ? W - sideW - gap : codeW, marker = function(st){ var L = st.lines; if (!L.length) return ""; var cont = L.every(function(n, i){ return i === 0 || n === L[i - 1] + 1; });
|
|
262
|
+
var t = cont ? (L.length === 1 ? String(L[0]) : L[0] + "–" + L[L.length - 1]) : L.join(", ");
|
|
263
|
+
return ja ? t + " 行目" : (L.length === 1 ? "line " : "lines ") + t; };
|
|
264
|
+
var noteLines = d.steps.map(function(s, j){
|
|
265
|
+
var w = wrap(marker(stepRows[j]) + " · " + s.note.replace(/\s*\n\s*/g, " "), nw - 24, nf, self);
|
|
266
|
+
if (w.length > 2){
|
|
267
|
+
ctx.report("layout", "[code] note " + (j + 1) + " needs " + w.length + " rows in the band (2 fit); shorten it");
|
|
268
|
+
w = [w[0], proseCut(w.slice(1).join(" "), nw - 24, nf)];
|
|
269
|
+
}
|
|
270
|
+
return w;
|
|
271
|
+
});
|
|
272
|
+
function proseCut(s, width, f){
|
|
273
|
+
f = f || nf;
|
|
274
|
+
if (base.textWidth(s, f, {font: self}) <= width) return s;
|
|
275
|
+
var ch = [...s];
|
|
276
|
+
while (ch.length && base.textWidth(ch.join("") + "…", f, {font: self}) > width) ch.pop();
|
|
277
|
+
return width >= f ? ch.join("") + "…" : "";
|
|
278
|
+
}
|
|
279
|
+
var nr = Math.max(1, ...noteLines.map(function(w){ return w.length; })), bandH = d.steps.length ? nr * noteRow + 16 : 0;
|
|
280
|
+
// 最後の一覧:説明ごとに「3–4:…」を行へ詰める。入らなければ最後の説明だけ(data-fit="last-note")
|
|
281
|
+
var listFont = Math.max(24, nf - 2), listRow = Math.ceil(listFont * 1.45), sep = ja ? " " : " ", list = [], cur = "";
|
|
282
|
+
d.steps.forEach(function(s, j){
|
|
283
|
+
var L = stepRows[j].lines, t = (L.length ? (marker(stepRows[j]).replace(/ 行目$|^lines? /, "")) : "?") + (ja ? ":" : ": ") + s.note.replace(/\s*\n\s*/g, " ");
|
|
284
|
+
var cand = cur ? cur + sep + t : t;
|
|
285
|
+
if (cur && base.textWidth(cand, listFont, {font: self}) > nw - 24){ list.push(cur); cur = t; } else cur = cand;
|
|
286
|
+
});
|
|
287
|
+
if (cur) list.push(cur);
|
|
288
|
+
var listH = list.length ? noteRow + 16 + (list.length - 1) * listRow : 0, below = !right && !side && output.length ? outputH + 16 : 0;
|
|
289
|
+
var zone = Math.max(bandH, listH, side ? outputH : 0), slots = Math.floor((H - header - pad - (zone ? 8 + zone : 0) - below) / row);
|
|
290
|
+
// コードを先に:最後の一覧の分だけコードの行が減るなら、一覧は最後の説明だけにする
|
|
291
|
+
var zoneNoList = Math.max(bandH, side ? outputH : 0), slotsNoList = Math.floor((H - header - pad - (zoneNoList ? 8 + zoneNoList : 0) - below) / row);
|
|
292
|
+
if (list.length > 1 && slots < Math.min(vrows.length, slotsNoList)){
|
|
293
|
+
zone = zoneNoList; slots = slotsNoList;
|
|
294
|
+
this.setAttribute("data-fit", "last-note"); list = [proseCut(list[list.length - 1], nw - 24, listFont)];
|
|
295
|
+
listH = noteRow + 16;
|
|
296
|
+
}
|
|
297
|
+
if (slots < 3){
|
|
298
|
+
var needH = header + pad + 3 * row + (zone ? 8 + zone : 0) + below;
|
|
299
|
+
ctx.report("size", "[code] element is " + W + " × " + H + " px; the fit layout needs at least " + Math.ceil(needH) + " px height for 3 code rows and the notes");
|
|
300
|
+
slots = Math.max(1, slots);
|
|
301
|
+
}
|
|
302
|
+
var shown = Math.min(slots, vrows.length), codeH = header + shown * row + pad;
|
|
303
|
+
this.windows = stepRows.map(function(st, j){
|
|
304
|
+
var ra = st.rows.length ? Math.min.apply(null, st.rows) : 0, rb = st.rows.length ? Math.max.apply(null, st.rows) : 0, w = C.windowFor(vrows.length, shown, ra, rb);
|
|
305
|
+
if (!w.fits && shown >= 3) ctx.report("layout", "[code] step " + (j + 1) + " highlights " + (rb - ra + 1) + " rows; the code view shows " + shown + " (split the step or give the element more height)");
|
|
306
|
+
return w;
|
|
307
|
+
});
|
|
308
|
+
this.window0 = C.windowFor(vrows.length, shown, 0, 0);
|
|
309
|
+
this.geometry = {fit: true, side: side, codeW: codeW, codeH: codeH, rows: vrows.length, slots: shown, right: right, bandRows: nr, listRows: list.length, windowed: vrows.length > shown};
|
|
310
|
+
this.noteLayout = "band";
|
|
311
|
+
var g = this.codeLayer = base.el("g", {opacity: 0}, this.svg);
|
|
312
|
+
base.el("rect", {x: 1, y: 1, width: Math.max(1, codeW - 2), height: Math.max(1, codeH - 2), rx: 12, fill: "var(--term-tint, color-mix(in srgb, var(--fg) 5%, var(--bg)))", stroke: "var(--line)", "stroke-width": 2}, g);
|
|
313
|
+
var tag = cut(lang, Math.max(1, codeW - 2 * pad), fs);
|
|
314
|
+
this.label(g, codeW - pad - monoWidth(tag, fs), pad + fs, tag, fs, "var(--muted)", true);
|
|
315
|
+
this.fitBands = d.steps.map(function(){ return base.el("g", {opacity: 0}, g); });
|
|
316
|
+
this.fitBandRects = stepRows.map(function(st, j){ return st.rows.map(function(){ return base.el("rect", {x: 4, y: header, width: Math.max(1, codeW - 8), height: row, fill: "var(--emph-tint, color-mix(in srgb, var(--emph) 12%, var(--bg)))"}, self.fitBands[j]); }); });
|
|
317
|
+
this.vrows = vrows.map(function(r){
|
|
318
|
+
var num = self.label(g, pad, firstY, r.cont ? "↪" : String(r.line), fs, "var(--muted)", true);
|
|
319
|
+
var e = self.label(g, textX, firstY, "", fs, "var(--fg)", true), pos = 0;
|
|
320
|
+
var put = function(a, b, role){ if (b > a) base.el("tspan", role ? {fill: "var(--" + role + ")"} : {}, e).textContent = [...r.text].slice(a, b).join(""); };
|
|
321
|
+
r.spans.forEach(function(m){ put(pos, m[0]); put(m[0], m[1], m[2]); pos = m[1]; });
|
|
322
|
+
put(pos, [...r.text].length);
|
|
323
|
+
return {num: num, text: e, line: r.line};
|
|
324
|
+
});
|
|
325
|
+
this.markTop = this.label(g, pad, firstY, "", fs, "var(--muted)", true);
|
|
326
|
+
this.markBottom = this.label(g, pad, firstY, "", fs, "var(--muted)", true);
|
|
327
|
+
this.fitGeo = {header: header, row: row, firstY: firstY};
|
|
328
|
+
this.stepLines = stepRows.map(function(st){ return st.lines; });
|
|
329
|
+
var bandY = codeH + 8;
|
|
330
|
+
this.notes = d.steps.map(function(s, j){
|
|
331
|
+
var ng = base.el("g", {opacity: 0}, self.svg);
|
|
332
|
+
base.el("rect", {x: 1, y: bandY, width: Math.max(1, nw - 2), height: bandH, rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, ng);
|
|
333
|
+
var labels = noteLines[j].map(function(t, i){ return self.label(ng, 12, bandY + 8 + nf + i * noteRow, t, nf); });
|
|
334
|
+
return {g: ng, labels: labels};
|
|
335
|
+
});
|
|
336
|
+
this.finalNotes = base.el("g", {opacity: 0}, this.svg);
|
|
337
|
+
if (list.length){
|
|
338
|
+
base.el("rect", {x: 1, y: bandY, width: Math.max(1, nw - 2), height: listH, rx: 8, fill: "var(--bg)", stroke: "var(--line)", "stroke-width": 2}, this.finalNotes);
|
|
339
|
+
list.forEach(function(t, i){ self.label(self.finalNotes, 12, bandY + 8 + nf + i * listRow, proseCut(t, nw - 24, listFont), listFont); });
|
|
340
|
+
}
|
|
341
|
+
this.outputLayer = base.el("g", {opacity: 0}, this.svg);
|
|
342
|
+
if (output.length){
|
|
343
|
+
var ox = right ? W - outW : side ? W - sideW : 0, oy = right ? 0 : side ? bandY : bandY + zone + 16, ow = right ? outW : side ? sideW : codeW;
|
|
344
|
+
var oc = Math.max(0, Math.min(8, output.length, Math.floor((H - oy - header - pad) / row)));
|
|
345
|
+
base.el("rect", {x: ox + 1, y: oy + 1, width: Math.max(1, ow - 2), height: Math.max(1, header + oc * row + pad - 2), rx: 12, fill: "var(--term-tint, color-mix(in srgb, var(--fg) 5%, var(--bg)))", stroke: "var(--line)", "stroke-width": 2}, this.outputLayer);
|
|
346
|
+
this.label(this.outputLayer, ox + pad, oy + pad + fs, cut(T.output, ow - 2 * pad, fs), fs);
|
|
347
|
+
var run = cut(T.run, ow - 2 * pad - monoWidth(T.output, fs) - pad, fs);
|
|
348
|
+
this.label(this.outputLayer, ox + ow - pad - monoWidth(run, fs), oy + pad + fs, run, fs, "var(--muted)", true);
|
|
349
|
+
var outputCut = oc < output.length || run !== T.run;
|
|
350
|
+
output.slice(0, oc).forEach(function(s, i){
|
|
351
|
+
var txt = cut(s.replace(/\t/g, " "), ow - 2 * pad, fs);
|
|
352
|
+
if (i === oc - 1 && oc < output.length) txt = cut(txt + "…", ow - 2 * pad, fs);
|
|
353
|
+
if (txt !== s) outputCut = true;
|
|
354
|
+
self.label(self.outputLayer, ox + pad, oy + header + fs + i * row, txt, fs, "var(--fg)", true);
|
|
355
|
+
});
|
|
356
|
+
if (outputCut) ctx.report("layout", "[code] output exceeds eight lines or panel width/height; showing what fits with …");
|
|
357
|
+
}
|
|
358
|
+
this.svg.setAttribute("style", "overflow:hidden");
|
|
359
|
+
}
|
|
360
|
+
// 表示する範囲:k ≤ 1 は先頭、説明のステップはその説明の範囲、最後の状態は最後の説明の範囲
|
|
361
|
+
windowAt(k){ var n = this.windows.length; return k <= 1 || !n ? this.window0 : this.windows[Math.min(k - 2, n - 1)]; }
|
|
362
|
+
renderFit(k, t, ctx){
|
|
363
|
+
ctx = ctx || {};
|
|
364
|
+
var self = this, P = this.props, G = this.fitGeo, preview = ctx.preview || ctx.mode === "lecture", faint = preview ? base.previewOpacity(this) : 0;
|
|
365
|
+
var phase = function(step){ return k > step ? 1 : k < step ? faint : base.prog(t, 0, P.dur); };
|
|
366
|
+
set(this.codeLayer, "opacity", phase(1));
|
|
367
|
+
var nNotes = this.notes.length, final = k > this.steps || k === this.steps && t >= P.dur, active = !final && k >= 2 && k <= nNotes + 1 ? k - 2 : -1;
|
|
368
|
+
var w1 = this.windowAt(k), w0 = this.windowAt(k - 1), e = base.prog(t, 0, P.dur), moving = w0.f !== w1.f || w0.l !== w1.l;
|
|
369
|
+
var w = moving && e < 0.5 ? w0 : w1, fade = moving ? (e < 0.5 ? 1 - 2 * e : 2 * e - 1) : 1;
|
|
370
|
+
var slotY = function(r){ return G.firstY + (r - w.f + (w.top ? 1 : 0)) * G.row; };
|
|
371
|
+
var lit = active >= 0 ? this.stepLines[active] : [];
|
|
372
|
+
this.vrows.forEach(function(o, r){
|
|
373
|
+
var vis = r >= w.f && r <= w.l, y = vis ? slotY(r) : G.firstY;
|
|
374
|
+
set(o.num, "y", y); set(o.text, "y", y);
|
|
375
|
+
set(o.num, "opacity", vis ? fade.toFixed(3) : 0); set(o.text, "opacity", vis ? fade.toFixed(3) : 0);
|
|
376
|
+
set(o.num, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--" + (lit.indexOf(o.line) >= 0 ? "emph" : "muted") + ")");
|
|
377
|
+
});
|
|
378
|
+
// 隠れた行の数(折り返しの続きは数えない、元の行の数)
|
|
379
|
+
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; };
|
|
380
|
+
var more = function(n){ return self.ja ? "⋮(ほか " + n + " 行)" : "⋮ (" + n + " more line" + (n === 1 ? "" : "s") + ")"; };
|
|
381
|
+
var hiddenTop = w.top ? linesIn(0, w.f - 1) - (vr[w.f] && vr[w.f].cont && vr[w.f - 1] && vr[w.f - 1].line === vr[w.f].line ? 1 : 0) : 0, hiddenBottom = w.bottom ? linesIn(w.l + 1, vr.length - 1) : 0;
|
|
382
|
+
this.markTop.textContent = w.top ? more(Math.max(1, hiddenTop)) : ""; set(this.markTop, "y", G.firstY); set(this.markTop, "opacity", w.top ? fade.toFixed(3) : 0);
|
|
383
|
+
this.markBottom.textContent = w.bottom ? more(Math.max(1, hiddenBottom)) : ""; set(this.markBottom, "y", slotY(w.l + 1)); set(this.markBottom, "opacity", w.bottom ? fade.toFixed(3) : 0);
|
|
384
|
+
this.fitBands.forEach(function(bg, j){
|
|
385
|
+
var rows = self.vrows.map(function(o, r){ return self.stepLines[j].indexOf(o.line) >= 0 ? r : -1; }).filter(function(r){ return r >= 0; });
|
|
386
|
+
self.fitBandRects[j].forEach(function(rect, i){ var r = rows[i], vis = r !== undefined && r >= w.f && r <= w.l; set(rect, "y", vis ? slotY(r) - G.firstY + G.header : G.header); set(rect, "opacity", vis ? 1 : 0); });
|
|
387
|
+
set(bg, "opacity", j === active ? (moving ? Math.max(0, 2 * e - 1) : e).toFixed(3) : 0);
|
|
388
|
+
});
|
|
389
|
+
this.notes.forEach(function(n, i){
|
|
390
|
+
set(n.g, "opacity", !final && i === active ? phase(i + 2) : !final && active < 0 && k > nNotes + 1 && i === nNotes - 1 ? 1 : 0);
|
|
391
|
+
});
|
|
392
|
+
set(this.finalNotes, "opacity", final ? 1 : k < 2 ? faint : 0);
|
|
393
|
+
set(this.outputLayer, "opacity", phase(nNotes + 2));
|
|
394
|
+
}
|
|
395
|
+
render(k, t, ctx){
|
|
396
|
+
if (!this.codeLayer) return;
|
|
397
|
+
if (this.fit) return this.renderFit(k, t, ctx);
|
|
398
|
+
ctx = ctx || {};
|
|
399
|
+
var self = this, preview = ctx.preview || ctx.mode === "lecture", faint = preview ? base.previewOpacity(this) : 0;
|
|
400
|
+
var phase = function(step){ return k > step ? 1 : k < step ? faint : base.prog(t, 0, self.props.dur); };
|
|
401
|
+
set(this.codeLayer, "opacity", phase(1));
|
|
402
|
+
var final = k > this.steps || k === this.steps && t >= this.props.dur, active = !final && k >= 2 && k <= this.notes.length + 1 ? k - 2 : -1;
|
|
403
|
+
this.notes.forEach(function(n, i){
|
|
404
|
+
var band = self.noteLayout === "band", shown = !final && (i === active || active < 0 && k > self.notes.length + 1 && i === self.notes.length - 1);
|
|
405
|
+
set(n.g, "opacity", band ? (shown ? phase(i + 2) : 0) : phase(i + 2));
|
|
406
|
+
n.labels.forEach(function(e){ set(e, "style", "fill:var(--" + (i < k - 2 && !final ? "muted" : "fg") + ")"); });
|
|
407
|
+
set(self.bands[i], "opacity", i === active && n.valid ? base.prog(t, 0, self.props.dur) : 0);
|
|
408
|
+
});
|
|
409
|
+
set(this.finalNotes, "opacity", this.noteLayout === "band" ? (final ? 1 : k < 2 ? faint : 0) : 0);
|
|
410
|
+
this.numbers.forEach(function(e, i){ var n = self.notes[active]; set(e, "style", "font-family:" + MONO + ";white-space:pre;fill:var(--" + (n && n.valid && i + 1 >= n.a && i + 1 <= n.b ? "emph" : "muted") + ")"); });
|
|
411
|
+
set(this.outputLayer, "opacity", phase(this.notes.length + 2));
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
});
|