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,244 @@
|
|
|
1
|
+
// m-seq:観測を 1 つずつ加えて、分布(事後分布など)と数値が更新されていく様子を見せる
|
|
2
|
+
// <m-seq per-step="2" style="height:400px"><script type="application/json">
|
|
3
|
+
// {"xs":[…], "steps":[{"dens":[…], "readout":{"n":0,"μ_n":0.00}}, {"dens":[…], "readout":{…}, "mark":1.2}, …],
|
|
4
|
+
// "xl":"*θ*", "yl":"密度", "yr":[0,2], "digits":{"n":0}, "markLabel":"*y*_n"}
|
|
5
|
+
// (JSON の終わり)</m-seq>
|
|
6
|
+
// steps[0] は始めの状態(段階 0)。steps[1..] が 1 回ずつの更新。1 段階に per-step 回の更新を、等しい時間枠で順に動かす。
|
|
7
|
+
// 今の分布は濃く、前の分布は薄い線で残す。右の欄に readout の数値(桁をそろえる)。mark は今回の観測の位置
|
|
8
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity と plot の Plot を使い、プレイヤーのグローバルは使わない
|
|
9
|
+
egatariParts.define({name: "seq", version: "2.2.0", requires: {base: "1.3.0", plot: "1.1.3"}, element: "m-seq"}, function(deps){
|
|
10
|
+
"use strict";
|
|
11
|
+
var base = deps.base, plot = deps.plot;
|
|
12
|
+
// 点列の d。null の所で線を切り、次の有限な点から M で引き直す(plot の p.d と同じ字。切れ目がなければ同じ d)
|
|
13
|
+
function pathOf(pts){
|
|
14
|
+
var d = "", pen = false;
|
|
15
|
+
pts.forEach(function(q){ if (q){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; } else pen = false; });
|
|
16
|
+
return d;
|
|
17
|
+
}
|
|
18
|
+
// 線分 s = [[x, y], [x, y]] が箱 r = [x0, y0, x1, y1] にかかるか(Liang–Barsky)
|
|
19
|
+
function segHitsBox(s, r){
|
|
20
|
+
var x = s[0][0], y = s[0][1], dx = s[1][0] - x, dy = s[1][1] - y, t0 = 0, t1 = 1;
|
|
21
|
+
var pp = [-dx, dx, -dy, dy], qq = [x - r[0], r[2] - x, y - r[1], r[3] - y];
|
|
22
|
+
for (var i = 0; i < 4; i++){
|
|
23
|
+
if (pp[i] === 0){ if (qq[i] < 0) return false; continue; }
|
|
24
|
+
var u = qq[i] / pp[i];
|
|
25
|
+
if (pp[i] < 0){ if (u > t1) return false; if (u > t0) t0 = u; }
|
|
26
|
+
else { if (u < t0) return false; if (u < t1) t1 = u; }
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// 灰色の線の名前の置き場所:その線の上に、線の点を中心にして置く(字は背景色の縁取りで線を切るので、どの線の名前か読める)。
|
|
31
|
+
// bd(字を置ける範囲)の中で、置いた字(boxes)に重ならず、ほかの線(lines:点列の配列。cl の中だけ描かれる)にかかる数が最も少なく、
|
|
32
|
+
// 自分の線が字の高さの中に収まり(平らな所)、ほかの線から離れている所(40 px まで)。w は字の幅の見積もり、fs は字の大きさ。置けなければ null
|
|
33
|
+
function placeOn(own, w, fs, lines, boxes, bd, cl){
|
|
34
|
+
var best = null, bc = Infinity;
|
|
35
|
+
var hits = function(L, r){
|
|
36
|
+
var q = [Math.max(r[0], cl[0]), Math.max(r[1], cl[1]), Math.min(r[2], cl[2]), Math.min(r[3], cl[3])];
|
|
37
|
+
if (q[0] >= q[2] || q[1] >= q[3]) return false;
|
|
38
|
+
for (var i = 1; i < L.length; i++) if (L[i - 1] && L[i] && segHitsBox([L[i - 1], L[i]], q)) return true;
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
for (var j = 0; j < own.length; j += 3){
|
|
42
|
+
var q = own[j];
|
|
43
|
+
if (!q || q[0] < cl[0] || q[0] > cl[2] || q[1] < cl[1] || q[1] > cl[3]) continue; // 描かれている点だけ
|
|
44
|
+
// 横軸や上の端に沿う線では、字を範囲の中へ上下にずらす(線のすぐ上・下になる)
|
|
45
|
+
var y = q[1] + fs * 0.33;
|
|
46
|
+
y = Math.max(bd[1] + fs * 0.88, Math.min(bd[3] - fs * 0.22, y));
|
|
47
|
+
var r = [q[0] - w / 2, y - fs * 0.88, q[0] + w / 2, y + fs * 0.22];
|
|
48
|
+
if (r[0] < bd[0] || r[2] > bd[2]) continue;
|
|
49
|
+
if (boxes.some(function(b){ return r[0] < b[2] + 6 && b[0] < r[2] + 6 && r[1] < b[3] + 4 && b[1] < r[3] + 4; })) continue;
|
|
50
|
+
// ほかの線にかかれば 1 本につき 1000。自分の線が字の幅の間に字の高さより大きく上下すれば 300
|
|
51
|
+
var c = 0, r3 = [r[0] - 3, r[1] - 3, r[2] + 3, r[3] + 3], gap = 40, lo = Infinity, hi = -Infinity;
|
|
52
|
+
own.forEach(function(z){ if (z && z[0] >= r[0] && z[0] <= r[2]){ lo = Math.min(lo, z[1]); hi = Math.max(hi, z[1]); } });
|
|
53
|
+
if (hi - lo > fs * 0.9) c += 300;
|
|
54
|
+
lines.forEach(function(L){
|
|
55
|
+
if (L === own) return;
|
|
56
|
+
if (hits(L, r3)){ c += 1000; return; }
|
|
57
|
+
L.forEach(function(z){
|
|
58
|
+
if (z && z[0] >= cl[0] && z[0] <= cl[2] && z[1] >= cl[1] && z[1] <= cl[3]) gap = Math.min(gap, Math.hypot(Math.max(r[0] - z[0], 0, z[0] - r[2]), Math.max(r[1] - z[1], 0, z[1] - r[3])));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
c += 40 - gap + (hi - lo) / fs;
|
|
62
|
+
if (c < bc){ bc = c; best = {x: q[0], y: y, box: r}; }
|
|
63
|
+
}
|
|
64
|
+
return best;
|
|
65
|
+
}
|
|
66
|
+
return class extends base.MotionElement {
|
|
67
|
+
static partName = "seq"; // the registry name (define meta name), for report prefixes
|
|
68
|
+
// データの形(kit/shape.js)。軸の設定(xl yl yr など)も JSON に書ける
|
|
69
|
+
static shape = {
|
|
70
|
+
schema: {type: "object", required: ["xs", "steps"], properties: {
|
|
71
|
+
xs: {type: "array", minItems: 2, items: {type: "number"}},
|
|
72
|
+
steps: {type: "array", minItems: 1, items: {type: "object", required: ["dens"], properties: {dens: {type: "array", items: {type: "number"}}, readout: {type: "object"}, mark: {type: "number"}}}},
|
|
73
|
+
digits: {type: "object"}, markLabel: {type: "string"}}},
|
|
74
|
+
example: {xs: [-2, -1, 0, 1, 2], steps: [{dens: [0.05, 0.24, 0.4, 0.24, 0.05], readout: {n: 0}}, {dens: [0.02, 0.2, 0.5, 0.2, 0.02], readout: {n: 1}, mark: 0.3}]},
|
|
75
|
+
};
|
|
76
|
+
static props = {
|
|
77
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップで動かす更新の回数"},
|
|
78
|
+
slot: {type: "number", default: 0.9, doc: "更新 1 回の秒数(cues はこの間隔)"},
|
|
79
|
+
xr: {type: "json", default: null, doc: "横軸の範囲(既定は xs の端)"}, yr: {type: "json", default: [0, 1]},
|
|
80
|
+
xt: {type: "json", default: []}, yt: {type: "json", default: []},
|
|
81
|
+
xf: {type: "number", default: undefined}, yf: {type: "number", default: undefined},
|
|
82
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
83
|
+
digits: {type: "number", default: 2, doc: "数値の小数の桁数(data.digits で名前ごとに上書き)"},
|
|
84
|
+
panel: {type: "number", default: 250, doc: "右の数値の欄の幅(px)"},
|
|
85
|
+
ghosts: {type: "number", default: 99, doc: "残す前の分布の数"},
|
|
86
|
+
};
|
|
87
|
+
// 属性があれば属性、なければ data の同名の値、なければ既定
|
|
88
|
+
opt(name){ var d = this.data || {}; return this.hasAttribute(name) || d[name] === undefined ? this.props[name] : d[name]; }
|
|
89
|
+
get updates(){ return Math.max(0, ((this.data || {}).steps || []).length - 1); }
|
|
90
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : Math.ceil(this.updates / this.props["per-step"]); }
|
|
91
|
+
mount(ctx){
|
|
92
|
+
var D = base, self = this, data = this.data, xs = data.xs;
|
|
93
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
94
|
+
var xr = this.opt("xr") || [xs[0], xs[xs.length - 1]], pw = this.opt("panel");
|
|
95
|
+
var p = this.p = plot.Plot(this, {xr: xr, yr: this.opt("yr"), xt: this.opt("xt"), yt: this.opt("yt"), xf: this.opt("xf"), yf: this.opt("yf"),
|
|
96
|
+
xl: this.opt("xl"), yl: this.opt("yl"), m: {l: 86, r: pw + 16, t: 24, b: 64}});
|
|
97
|
+
// 密度の点列(px)。有限でない値(NaN・±Infinity・足りない値)の点は null で、線はそこで切る
|
|
98
|
+
this.pts = function(dens){ return xs.map(function(x, i){ var X = p.x(x), Y = p.y(dens[i]); return typeof dens[i] === "number" && isFinite(X) && isFinite(Y) ? [X, Y] : null; }); };
|
|
99
|
+
var bad = [];
|
|
100
|
+
data.steps.forEach(function(s, i){ if (self.pts(s.dens).indexOf(null) >= 0) bad.push(i); });
|
|
101
|
+
if (bad.length) ctx.report("data", "[seq] steps " + bad.join(", ") + ": dens has values that are not finite numbers (NaN, ±Infinity or missing for some xs); the curve is broken there");
|
|
102
|
+
// 軸の範囲を書かなかったとき(yr は既定の [0, 1]、xr は xs の端)に値が範囲の外に出るなら知らせる(m-curves 2.3.1 と同じ。書いた範囲で切るのは意図とみなし、知らせない)
|
|
103
|
+
var unset = function(name){ return !self.hasAttribute(name) && data[name] === undefined; };
|
|
104
|
+
var outside = function(ax, r, vs, what, cut){
|
|
105
|
+
var lo = Math.min(r[0], r[1]), hi = Math.max(r[0], r[1]), tol = (hi - lo) * 1e-9, out = vs.filter(function(v){ return v < lo - tol || v > hi + tol; });
|
|
106
|
+
if (out.length) ctx.report("range", "[seq] " + out.length + " of " + vs.length + " " + what + " are outside " + ax + " " + JSON.stringify(r) + " (the default" + (ax === "xr" ? ", the ends of xs" : "") + "; values from " + +Math.min.apply(null, vs).toPrecision(4) + " to " + +Math.max.apply(null, vs).toPrecision(4) + "), so " + cut + ". Write " + ax + " to cover them");
|
|
107
|
+
};
|
|
108
|
+
var fin = function(v){ return typeof v === "number" && isFinite(v); };
|
|
109
|
+
if (unset("yr")) outside("yr", this.opt("yr"), [].concat.apply([], data.steps.map(function(s){ return (s.dens || []).filter(fin); })), "dens values", "the curve is cut at the edge");
|
|
110
|
+
if (unset("xr")) outside("xr", xr, data.steps.map(function(s){ return s.mark; }).filter(fin), "marks", "they are drawn outside the plot");
|
|
111
|
+
// 塗り(今の分布の下)→ 前の分布の薄い線 → 今の分布の線 の順に重ねる
|
|
112
|
+
this.area = D.el("path", {fill: "var(--term-tint)", stroke: "none", "clip-path": p.clip}, p.svg);
|
|
113
|
+
var gG = D.el("g", {"clip-path": p.clip}, p.svg);
|
|
114
|
+
this.ghostEls = data.steps.map(function(s){
|
|
115
|
+
var e = D.el("path", {fill: "none", stroke: "var(--line)", "stroke-width": 2.5, opacity: 0}, gG);
|
|
116
|
+
e.setAttribute("d", pathOf(self.pts(s.dens)));
|
|
117
|
+
return e;
|
|
118
|
+
});
|
|
119
|
+
this.cur = D.el("path", {fill: "none", stroke: "var(--term)", "stroke-width": 3.5, "stroke-linejoin": "round", "clip-path": p.clip}, p.svg);
|
|
120
|
+
// 観測の印:今回は縦の点線と名前、前の観測は横軸の上の小さな点
|
|
121
|
+
// marks for the geometry check (spec §8.4): an earlier observation is a mark, the current one's dashed line an edge with its name,
|
|
122
|
+
// the readout panel a box with its names and values, a grey curve's name a haloed label outside the curve
|
|
123
|
+
this.dots = data.steps.map(function(s, i){
|
|
124
|
+
return s.mark === undefined ? null : D.el("circle", {"data-part": "mark", "data-part-id": "@obs" + i, cx: p.x(s.mark), cy: p.H - p.m.b - 7, r: 6, fill: "var(--muted)", opacity: 0}, p.svg);
|
|
125
|
+
});
|
|
126
|
+
this.markLine = D.el("line", {"data-part-line": "", x1: 0, x2: 0, y1: p.m.t + 34, y2: p.H - p.m.b, stroke: "var(--emph)", "stroke-width": 2.5, "stroke-dasharray": "7 6", opacity: 0}, D.el("g", {"data-part": "edge", "data-part-id": "obs", "data-part-from": "@obs", "data-part-to": "@obs"}, p.svg));
|
|
127
|
+
this.markLab = D.mtext(p.svg, 0, p.m.t + 24, data.markLabel || "", {"data-part": "label", "data-part-id": "obs", "data-part-of": "edge", "text-anchor": "middle", fill: "var(--emph)", "font-size": 26, opacity: 0});
|
|
128
|
+
// 数値の欄(名前は左寄せ、値は右寄せ。等幅の数字)
|
|
129
|
+
var keys = Object.keys(data.steps[0].readout || {}), px = p.W - pw + 8, px2 = p.W - 8;
|
|
130
|
+
D.el("rect", {"data-part": "box", "data-part-id": "readout", x: px - 8, y: p.m.t, width: pw, height: 40 + keys.length * 44, rx: 10, fill: "var(--term-tint)", stroke: "var(--line)", "stroke-width": 1.5}, p.svg);
|
|
131
|
+
this.rows = keys.map(function(key, j){
|
|
132
|
+
var y = p.m.t + 44 + j * 44;
|
|
133
|
+
D.mtext(p.svg, px + 12, y, key, {"data-part": "label", "data-part-id": "readout", "data-part-of": "box", "font-size": 28});
|
|
134
|
+
var v = D.el("text", {"data-part": "label", "data-part-id": "readout", "data-part-of": "box", x: px2 - 12, y: y, "text-anchor": "end", "font-size": 28, style: "font-variant-numeric:tabular-nums;font-feature-settings:'tnum'"}, p.svg);
|
|
135
|
+
return {key: key, el: v, dg: (data.digits || {})[key] !== undefined ? data.digits[key] : self.props.digits};
|
|
136
|
+
});
|
|
137
|
+
// readout に書いていない名前は、前の値のまま出す(1 回だけ知らせる)
|
|
138
|
+
var miss = [];
|
|
139
|
+
keys.forEach(function(key){
|
|
140
|
+
var at = []; data.steps.forEach(function(s, i){ if ((s.readout || {})[key] === undefined) at.push(i); });
|
|
141
|
+
if (at.length) miss.push(JSON.stringify(key) + " (steps " + at.join(", ") + ")");
|
|
142
|
+
});
|
|
143
|
+
if (miss.length) ctx.report("data", "[seq] readout has no value for " + miss.join(", ") + "; the previous value is shown");
|
|
144
|
+
// 灰色の線(前の分布)の名前「n = 3」:最後の段階で残る線に、--muted の 24px で線の上に(背景色で縁取って)書く。
|
|
145
|
+
// 5 本以上なら最初と最後だけ。n は readout の n(*n* など、字が n の名前)の値、なければ更新の回数。
|
|
146
|
+
// 置き場所は最後の段階の形(今の線・灰色の線・観測の印)で決め、その線が灰色で見えている間だけ出す
|
|
147
|
+
var last = this.updates, G = this.props.ghosts, fs = 24, nk = null;
|
|
148
|
+
keys.forEach(function(key){ if (nk === null && key.replace(/[*_^]/g, "") === "n") nk = key; });
|
|
149
|
+
var wOf = function(str){ return D.textWidth(str, fs, {font: self, mark: true}); }; // base の textWidth(記法の * _ ^ を除く)
|
|
150
|
+
var shown = [];
|
|
151
|
+
for (var i = Math.max(0, last - G); i < last; i++) shown.push(i);
|
|
152
|
+
if (shown.length > 4) shown = [shown[0], shown[shown.length - 1]];
|
|
153
|
+
var gp = data.steps.map(function(s){ return self.pts(s.dens); });
|
|
154
|
+
var lines = [gp[last]].concat(gp.slice(Math.max(0, last - G), last)), lm = data.steps[last].mark, boxes = [];
|
|
155
|
+
if (lm !== undefined && last > 0){
|
|
156
|
+
lines.push([[p.x(lm), p.m.t + 34], [p.x(lm), p.H - p.m.b]]);
|
|
157
|
+
var mw = wOf(data.markLabel || "") * 26 / 24;
|
|
158
|
+
boxes.push([p.x(lm) - mw / 2, p.m.t + 24 - 26 * 0.88, p.x(lm) + mw / 2, p.m.t + 24 + 26 * 0.22]);
|
|
159
|
+
}
|
|
160
|
+
data.steps.forEach(function(s, i){ if (s.mark !== undefined && i < last) boxes.push([p.x(s.mark) - 6, p.H - p.m.b - 13, p.x(s.mark) + 6, p.H - p.m.b - 1]); });
|
|
161
|
+
var bd = [p.m.l + 4, 4, p.W - pw - 16, p.H - p.m.b - 2], cl = [p.m.l, p.m.t - 4, p.W - pw - 16, p.H - p.m.b];
|
|
162
|
+
this.glabs = [];
|
|
163
|
+
shown.forEach(function(i){
|
|
164
|
+
var v = nk !== null ? (data.steps[i].readout || {})[nk] : i;
|
|
165
|
+
if (v === undefined) v = i;
|
|
166
|
+
var dg = nk !== null && (data.digits || {})[nk] !== undefined ? data.digits[nk] : 0;
|
|
167
|
+
var str = (nk !== null ? nk : "*n*") + " = " + (typeof v === "number" ? v.toFixed(dg).replace("-", "−") : String(v));
|
|
168
|
+
var at = placeOn(gp[i], wOf(str), fs, lines, boxes, bd, cl);
|
|
169
|
+
if (!at){ ctx.report("layout", "[seq] no free place for the name of the grey curve " + JSON.stringify(str) + " (not drawn)"); return; }
|
|
170
|
+
boxes.push(at.box);
|
|
171
|
+
self.glabs.push({i: i, el: D.mtext(p.svg, +at.x.toFixed(1), +at.y.toFixed(1), str, {"data-part": "label", "data-part-id": "@curve" + i, "data-part-of": "mark", "data-part-at": "outside", "data-part-halo": "", "text-anchor": "middle", fill: "var(--muted)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": fs, opacity: 0})});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
// 段階 i までで readout の key に最後に書かれた値(なければ undefined)
|
|
175
|
+
valAt(i, key){ var S = this.data.steps; for (; i >= 0; i--){ var v = (S[i].readout || {})[key]; if (v !== undefined) return v; } return undefined; }
|
|
176
|
+
// 段階 k が受け持つ更新の番号 [first, last]
|
|
177
|
+
span(k){ var P = this.props["per-step"]; return [(k - 1) * P + 1, Math.min(k * P, this.updates)]; }
|
|
178
|
+
duration(k){ if (k < 1) return 0; var s = this.span(k); return Math.max(0, s[1] - s[0] + 1) * this.props.slot; }
|
|
179
|
+
cues(k){
|
|
180
|
+
if (k < 1) return null;
|
|
181
|
+
var s = this.span(k), out = [];
|
|
182
|
+
for (var j = 0; j <= s[1] - s[0]; j++) out.push(+(j * this.props.slot).toFixed(4));
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
render(k, t, ctx){
|
|
186
|
+
var D = base, S = this.data.steps, p = this.p, slot = this.props.slot;
|
|
187
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
188
|
+
|
|
189
|
+
// 今の更新の番号 idx と、その更新の進み具合 e(0 なら一つ前の状態、1 なら更新後)
|
|
190
|
+
var idx = 0, e = 1, tm = 0;
|
|
191
|
+
if (k >= 1){
|
|
192
|
+
var s = this.span(k), n = s[1] - s[0] + 1;
|
|
193
|
+
if (t === Infinity){ idx = s[1]; tm = Infinity; }
|
|
194
|
+
else { var j = Math.max(0, Math.min(n - 1, Math.floor(t / slot))); idx = s[0] + j; tm = t - j * slot; }
|
|
195
|
+
e = D.prog(tm, 0, slot * 0.8);
|
|
196
|
+
}
|
|
197
|
+
var a = S[Math.max(0, idx - 1)], b = S[idx];
|
|
198
|
+
// 前後のどちらかが有限でなければ補間せず、動き終わり(e = 1)は後の値、始め(e = 0)は前の値
|
|
199
|
+
var dens = this.data.xs.map(function(_, i){
|
|
200
|
+
var A = a.dens[i], B = b.dens[i];
|
|
201
|
+
return typeof A === "number" && typeof B === "number" && isFinite(A) && isFinite(B) ? D.lerp(A, B, e) : e >= 1 ? B : e <= 0 ? A : NaN;
|
|
202
|
+
});
|
|
203
|
+
// 線は有限な区間ごとに引き、塗りも区間ごとに横軸まで閉じる(切れ目がなければ今までと同じ d)
|
|
204
|
+
var q = this.pts(dens), d = pathOf(q), ar = "", y0 = p.y(0).toFixed(1);
|
|
205
|
+
for (var i = 0; i < q.length; i++){
|
|
206
|
+
if (!q[i]) continue;
|
|
207
|
+
var j = i; while (j + 1 < q.length && q[j + 1]) j++;
|
|
208
|
+
ar += pathOf(q.slice(i, j + 1)) + "L" + q[j][0].toFixed(1) + "," + y0 + "L" + q[i][0].toFixed(1) + "," + y0 + "Z";
|
|
209
|
+
i = j;
|
|
210
|
+
}
|
|
211
|
+
this.cur.setAttribute("d", d);
|
|
212
|
+
this.area.setAttribute("d", ar);
|
|
213
|
+
var G = this.props.ghosts, last = this.updates, end = this.span(k)[1];
|
|
214
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の終わりの分布を今の線の色で、後の観測の点とともに、
|
|
215
|
+
// テーマの --preview-opacity の濃さに(途中の分布は重ねない)
|
|
216
|
+
var ahead = function(i){ return preview && i > Math.max(idx, k >= 1 ? end : 0); };
|
|
217
|
+
this.ghostEls.forEach(function(g, i){
|
|
218
|
+
var f = ahead(i) && i === last;
|
|
219
|
+
var col = f ? "var(--term)" : "var(--line)";
|
|
220
|
+
// style は base.el と同じ書き方で書く(style.stroke に代入すると "stroke: var(--x);" になり、作った直後と字が変わる)
|
|
221
|
+
g.setAttribute("style", "stroke:" + col + ";");
|
|
222
|
+
g.setAttribute("opacity", f ? PV : i < idx && i >= idx - G ? 1 : 0);
|
|
223
|
+
});
|
|
224
|
+
this.dots.forEach(function(c, i){ if (c) c.setAttribute("opacity", ahead(i) ? PV : i < idx ? 1 : 0); });
|
|
225
|
+
var mo = b.mark !== undefined && idx > 0 ? D.prog(tm, 0, 0.25) : 0;
|
|
226
|
+
// 印のない段階では作った直後の位置(0)に戻す(前の段階の位置を残さない。docs/contract.md §3)
|
|
227
|
+
var mx = b.mark !== undefined ? p.x(b.mark) : 0;
|
|
228
|
+
this.markLine.setAttribute("x1", mx); this.markLine.setAttribute("x2", mx); this.markLab.setAttribute("x", mx);
|
|
229
|
+
this.markLine.setAttribute("opacity", mo.toFixed(3));
|
|
230
|
+
this.markLab.setAttribute("opacity", mo.toFixed(3));
|
|
231
|
+
var self = this, ia = Math.max(0, idx - 1);
|
|
232
|
+
this.rows.forEach(function(r){
|
|
233
|
+
// 書いていない値は前の段階の値(桁もそろえる)
|
|
234
|
+
var va = self.valAt(ia, r.key), vb = self.valAt(idx, r.key), v;
|
|
235
|
+
if (typeof va === "number" && typeof vb === "number") v = D.lerp(va, vb, e);
|
|
236
|
+
else v = e < 0.5 && va !== undefined ? va : vb;
|
|
237
|
+
v = typeof v === "number" ? v.toFixed(r.dg).replace("-", "−") : String(v);
|
|
238
|
+
r.el.textContent = v === "−0" || /^−0\.0*$/.test(v) ? v.slice(1) : v;
|
|
239
|
+
});
|
|
240
|
+
// 灰色の線の名前は、その線が灰色で見えている間だけ
|
|
241
|
+
this.glabs.forEach(function(o){ o.el.setAttribute("opacity", !ahead(o.i) && o.i < idx && o.i >= idx - G ? 1 : 0); });
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
});
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// m-gendai:現代文の読解の図。傍線・二重傍線を引き、指示語から指す内容へ矢印を出し、段落を役割(主張・具体例・対比)の枠で囲んで線でつなぐ
|
|
2
|
+
// <m-gendai tate style="height:440px">
|
|
3
|
+
// @具体例#p1>p3
|
|
4
|
+
// 駅までの道を、私は{地図アプリ|#app}に頼って歩く。…{それ|>app}を閉じると、…
|
|
5
|
+
//
|
|
6
|
+
// @主張#p3
|
|
7
|
+
// 便利な道具は、私たちから=={迷う機会を奪う}==。…{迷うことこそが…営みなのである|_A}
|
|
8
|
+
// </m-gendai>
|
|
9
|
+
// 段落は空行で区切る。段落の頭の行「@役割#名前」で役割(主張・具体例・対比・反論・結論など、自由な言葉)と名前を付け、
|
|
10
|
+
// 「>名前」(その段落を支える・つながる。矢印)か「~名前」(対比。両向きの線)で別の段落とつなぐ。
|
|
11
|
+
// 本文の中:__語句__ 傍線、==語句== 二重傍線、{語句|しるし,…}(しるし:_A 傍線と記号 A、=B 二重傍線と記号 B、#名前 指す先、>名前 指示語)
|
|
12
|
+
// 段階(phases の順。中身のないものは飛ばす。既定は marks refs roles):marks 傍線 → refs 指示語の矢印 → roles 段落の枠と線
|
|
13
|
+
// 線と枠は、字の位置を測って SVG で描く(部品の中の座標。描く度に測るので、呼び出しの順によらない)
|
|
14
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
15
|
+
// 書き方の誤りは ctx.report("data", "[gendai] …") で知らせる(1.x の console.warn("m-gendai: …") の代わり)。
|
|
16
|
+
// 読み取り(parse)は試験のために static testing に出す(ほかのパーツは読まない)
|
|
17
|
+
egatariParts.define({name: "gendai", version: "2.0.4", requires: {base: "1.3.0"}, element: "m-gendai"}, function(deps){
|
|
18
|
+
"use strict";
|
|
19
|
+
var base = deps.base;
|
|
20
|
+
var D = base;
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------- 読み取り
|
|
23
|
+
// parse(文字列) → {paras: [{role, id, to, rel, runs: [{t, line, label, id, ref}]}], warnings}
|
|
24
|
+
function parse(src){
|
|
25
|
+
var paras = [], warnings = [], blocks = String(src || "").replace(/\r/g, "").split(/\n\s*\n/);
|
|
26
|
+
blocks.forEach(function(b){
|
|
27
|
+
var lines = b.split("\n").map(function(l){ return l.trim(); }).filter(Boolean);
|
|
28
|
+
if (!lines.length) return;
|
|
29
|
+
var p = {role: "", id: "", to: "", rel: "", runs: []};
|
|
30
|
+
var m = /^@([^#>~\s]*)(?:#([^>~\s]+))?(?:([>~])(\S+))?\s*$/.exec(lines[0]);
|
|
31
|
+
if (m){ p.role = m[1]; p.id = m[2] || ""; p.rel = m[3] || ""; p.to = m[4] || ""; lines.shift(); }
|
|
32
|
+
p.runs = inline(lines.join(""), warnings);
|
|
33
|
+
paras.push(p);
|
|
34
|
+
});
|
|
35
|
+
var ids = {};
|
|
36
|
+
paras.forEach(function(p){ if (p.id) ids[p.id] = true; });
|
|
37
|
+
paras.forEach(function(p){ if (p.to && !ids[p.to]) warnings.push("段落「" + p.to + "」がない(@" + p.role + ")"); });
|
|
38
|
+
var anchors = {};
|
|
39
|
+
paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.id) anchors[r.id] = true; }); });
|
|
40
|
+
paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.ref && !anchors[r.ref]) warnings.push("指す先「#" + r.ref + "」がない(" + r.t + ")"); }); });
|
|
41
|
+
return {paras: paras, warnings: warnings};
|
|
42
|
+
}
|
|
43
|
+
// 本文の中のしるし → 字の並び(runs)。run = {t, line: 0 | 1 | 2(傍線・二重傍線), label, id, ref}
|
|
44
|
+
function inline(s, warnings){
|
|
45
|
+
var runs = [], re = /__(.+?)__|==(.+?)==|\{([^{}|]+)\|([^{}]*)\}/g, last = 0, m;
|
|
46
|
+
var plain = function(t){ if (t) runs.push({t: t, line: 0, label: "", id: "", ref: ""}); };
|
|
47
|
+
while ((m = re.exec(s))){
|
|
48
|
+
plain(s.slice(last, m.index)); last = re.lastIndex;
|
|
49
|
+
if (m[1] !== undefined){ runs.push({t: m[1], line: 1, label: "", id: "", ref: ""}); continue; }
|
|
50
|
+
if (m[2] !== undefined){ runs.push({t: m[2], line: 2, label: "", id: "", ref: ""}); continue; }
|
|
51
|
+
var r = {t: m[3], line: 0, label: "", id: "", ref: ""};
|
|
52
|
+
m[4].split(/[,,、]/).map(function(f){ return f.trim(); }).filter(Boolean).forEach(function(f){
|
|
53
|
+
if (f[0] === "_"){ r.line = 1; r.label = f.slice(1); }
|
|
54
|
+
else if (f[0] === "="){ r.line = 2; r.label = f.slice(1); }
|
|
55
|
+
else if (f[0] === "#") r.id = f.slice(1);
|
|
56
|
+
else if (f[0] === ">") r.ref = f.slice(1);
|
|
57
|
+
else warnings.push("知らないしるし「" + f + "」(" + m[3] + ")");
|
|
58
|
+
});
|
|
59
|
+
runs.push(r);
|
|
60
|
+
}
|
|
61
|
+
plain(s.slice(last));
|
|
62
|
+
// 残った { } __ ==:閉じていないか、入れ子にしたしるし(しるしは入れ子にできない。{語句|=,#名前} のように 1 つにまとめる)
|
|
63
|
+
runs.forEach(function(r){ if (/[{}]|__|==/.test(r.t)) warnings.push("しるしの書き方が違う(閉じていない・入れ子):" + r.t); });
|
|
64
|
+
return runs;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- 部品
|
|
68
|
+
var ROLE_COLOR = function(role){ return /主張|結論|筆者/.test(role) ? "var(--emph)" : /対比|反論|対立/.test(role) ? "var(--accent2)" : /具体|例/.test(role) ? "var(--term)" : "var(--muted)"; };
|
|
69
|
+
var PH = ["marks", "refs", "roles"];
|
|
70
|
+
// 枠をつなぐ線は札(枠の上の名前)から札へ、札と枠の外の通り道(縦書きは札の上、横書きは札の左)を通す。
|
|
71
|
+
// 通り道は線ごとに段(level)を分け、間の段落を越える線ほど外の段を通る。段の数だけ場所を空ける(線が札や枠に重ならないように)
|
|
72
|
+
var CHIP = 34; // 札の高さ
|
|
73
|
+
var STUB = 22, STEP = 16; // 札から 1 段目までの距離、段の間
|
|
74
|
+
var LH_TATE = 2.4; // 縦書きの行の送り(傍線と記号 A の入る列の間を空ける)
|
|
75
|
+
return class extends base.MotionElement {
|
|
76
|
+
static partName = "gendai"; // the registry name (define meta name), for report prefixes
|
|
77
|
+
static testing = {parse: parse}; // for tools/test-kokugo.mjs only (no part reads it)
|
|
78
|
+
// データの形(kit/shape.js):JSON ではなく、要素の中に本文の字(段落は空行で区切る)
|
|
79
|
+
static shape = {text: true, example: "@主張#p1\n便利な道具は、私たちから==迷う機会を奪う==。"};
|
|
80
|
+
static props = {
|
|
81
|
+
size: {type: "number", default: 28, doc: "本文の字の大きさ(px)"},
|
|
82
|
+
tate: {type: "bool", default: false, doc: "縦書きにする(段落は右から左へ、枠をつなぐ線は上を通す)"},
|
|
83
|
+
phases: {type: "string", default: "marks refs roles", doc: "ステップの並び(marks 傍線・refs 指示語・roles 段落の枠から選ぶ。中身のないものは飛ばす)"},
|
|
84
|
+
draw: {type: "number", default: 0.7, doc: "線 1 本を引く秒数"},
|
|
85
|
+
};
|
|
86
|
+
get model(){ if (!this._m) this._m = parse(this._src !== undefined ? this._src : this.textContent); return this._m; }
|
|
87
|
+
get phaseList(){
|
|
88
|
+
var m = this.model, has = {
|
|
89
|
+
marks: m.paras.some(function(p){ return p.runs.some(function(r){ return r.line; }); }),
|
|
90
|
+
refs: m.paras.some(function(p){ return p.runs.some(function(r){ return r.ref; }); }),
|
|
91
|
+
roles: m.paras.some(function(p){ return p.role; })};
|
|
92
|
+
return String(this.props.phases || "").split(/[\s,]+/).filter(function(x){ return PH.indexOf(x) >= 0 && has[x]; });
|
|
93
|
+
}
|
|
94
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.phaseList.length; }
|
|
95
|
+
phaseStep(name){ return this.phaseList.indexOf(name) + 1; }
|
|
96
|
+
mount(ctx){
|
|
97
|
+
var self = this, P = this.props, tate = P.tate;
|
|
98
|
+
this._src = this.textContent;
|
|
99
|
+
var m = this.model;
|
|
100
|
+
m.warnings.forEach(function(w){ ctx.report("data", "[gendai] " + w); });
|
|
101
|
+
this.textContent = "";
|
|
102
|
+
this.classList.add("plot");
|
|
103
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
104
|
+
this.style.fontFamily = "var(--font-mincho)";
|
|
105
|
+
var W =this.clientWidth || 1184, H = this.clientHeight || 440;
|
|
106
|
+
var roles = m.paras.some(function(p){ return p.role; });
|
|
107
|
+
// つなぐ線の段:つなぐ段落の間の短いものから順に、重なる線より 1 つ外の段へ
|
|
108
|
+
var pIdx = {};
|
|
109
|
+
m.paras.forEach(function(p, i){ if (p.id) pIdx[p.id] = i; });
|
|
110
|
+
var spans = m.paras.map(function(p, i){ return p.to && pIdx[p.to] !== undefined ? {i: i, lo: Math.min(i, pIdx[p.to]), hi: Math.max(i, pIdx[p.to])} : null; }).filter(Boolean)
|
|
111
|
+
.sort(function(a, b){ return (a.hi - a.lo) - (b.hi - b.lo) || a.lo - b.lo; });
|
|
112
|
+
var levelOf = {}, placed = [], nLev = 0;
|
|
113
|
+
spans.forEach(function(o){
|
|
114
|
+
var lv = 1;
|
|
115
|
+
placed.forEach(function(q){ if (q.lo < o.hi && o.lo < q.hi) lv = Math.max(lv, q.lv + 1); });
|
|
116
|
+
o.lv = lv; placed.push(o); levelOf[o.i] = lv; nLev = Math.max(nLev, lv);
|
|
117
|
+
});
|
|
118
|
+
this.nLev = nLev;
|
|
119
|
+
// 通り道と札の場所:縦書きは上に(札 + 段)、横書きは左に(段)と上に(札)
|
|
120
|
+
var lane = nLev ? STUB + (nLev - 1) * STEP + 10 : 0;
|
|
121
|
+
this.padTop = tate ? (roles ? CHIP + lane + 10 : 20) : (roles ? CHIP + 10 : 20);
|
|
122
|
+
this.padLeft = tate ? 0 : (nLev ? lane - 2 : 4);
|
|
123
|
+
// 重ね順:塗り(指す先の淡い色)→ 字 → 線・枠・矢印
|
|
124
|
+
this.back = D.el("svg", {width: W, height: H, viewBox: "0 0 " + W + " " + H, "aria-hidden": "true", style: "position:absolute;left:0;top:0;overflow:visible;pointer-events:none"}, this);
|
|
125
|
+
var text = document.createElement("div");
|
|
126
|
+
text.style.cssText = "position:absolute;inset:0;font-size:" + P.size + "px;line-height:" + (tate ? LH_TATE : 1.85) + ";padding-top:" + this.padTop + "px;" + (tate ? "writing-mode:vertical-rl;" : "padding-left:" + this.padLeft + "px;");
|
|
127
|
+
this.appendChild(text);
|
|
128
|
+
this.front = D.el("svg", {width: W, height: H, viewBox: "0 0 " + W + " " + H, "aria-hidden": "true", style: "position:absolute;left:0;top:0;overflow:visible;pointer-events:none"}, this);
|
|
129
|
+
this.text = text;
|
|
130
|
+
var byId = {};
|
|
131
|
+
this.paras = m.paras.map(function(p, pi){
|
|
132
|
+
var d = document.createElement("div");
|
|
133
|
+
// 枠の内側の余白と、段落の間(枠の名前の札が入る)
|
|
134
|
+
// 横書きは次の段落の札が前の枠に掛からないように空ける
|
|
135
|
+
d.style.cssText = "padding:10px 14px;text-indent:1em;" + (tate ? "margin:0 0 0 22px;" : "margin:0 0 " + (roles ? CHIP + 12 : 22) + "px 0;");
|
|
136
|
+
text.appendChild(d);
|
|
137
|
+
var P2 = {p: p, el: d, spans: []};
|
|
138
|
+
p.runs.forEach(function(r){
|
|
139
|
+
if (!r.line && !r.id && !r.ref){ d.appendChild(document.createTextNode(r.t)); return; }
|
|
140
|
+
var s = document.createElement("span"); s.textContent = r.t; d.appendChild(s);
|
|
141
|
+
P2.spans.push({r: r, el: s});
|
|
142
|
+
if (r.id) byId[r.id] = s;
|
|
143
|
+
});
|
|
144
|
+
return P2;
|
|
145
|
+
});
|
|
146
|
+
this.byId = byId;
|
|
147
|
+
// 傍線(引く順に)
|
|
148
|
+
this.lines = [];
|
|
149
|
+
this.paras.forEach(function(P2){ P2.spans.forEach(function(s){ if (s.r.line){
|
|
150
|
+
var g = D.el("g", {}, self.front), o = {el: s.el, r: s.r, g: g, segs: [], lab: null};
|
|
151
|
+
if (s.r.label) o.lab = D.el("text", {"font-size": 24, "font-weight": 700, fill: "var(--emph)", "text-anchor": "middle", opacity: 0}, g);
|
|
152
|
+
if (o.lab) o.lab.textContent = s.r.label;
|
|
153
|
+
self.lines.push(o);
|
|
154
|
+
} }); });
|
|
155
|
+
// 指示語 → 指す先
|
|
156
|
+
this.refs = [];
|
|
157
|
+
this.paras.forEach(function(P2){ P2.spans.forEach(function(s){ if (s.r.ref && byId[s.r.ref]){
|
|
158
|
+
self.refs.push({from: s.el, to: byId[s.r.ref],
|
|
159
|
+
fill: D.el("g", {opacity: 0}, self.back),
|
|
160
|
+
box: D.el("g", {opacity: 0}, self.front),
|
|
161
|
+
path: D.el("path", {fill: "none", stroke: "var(--emph)", "stroke-width": 3, "stroke-linecap": "round", pathLength: 1, "stroke-dasharray": 1, "stroke-dashoffset": 1}, self.front),
|
|
162
|
+
head: D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: "var(--emph)", opacity: 0}, self.front)});
|
|
163
|
+
} }); });
|
|
164
|
+
// 段落の枠・札・つなぐ線
|
|
165
|
+
var pById = {};
|
|
166
|
+
this.paras.forEach(function(P2){ if (P2.p.id) pById[P2.p.id] = P2; });
|
|
167
|
+
this.boxes = this.paras.filter(function(P2){ return P2.p.role; }).map(function(P2){
|
|
168
|
+
var c = ROLE_COLOR(P2.p.role);
|
|
169
|
+
var rect = D.el("rect", {fill: "none", stroke: c, "stroke-width": 2.5, rx: 10, pathLength: 1, "stroke-dasharray": 1, "stroke-dashoffset": 1}, self.front);
|
|
170
|
+
var chip = D.el("g", {opacity: 0}, self.front);
|
|
171
|
+
var cr = D.el("rect", {fill: "var(--bg)", stroke: c, "stroke-width": 2, rx: 14, height: 34}, chip);
|
|
172
|
+
var ct = D.el("text", {"font-size": 24, "font-weight": 700, fill: c, "text-anchor": "middle"}, chip);
|
|
173
|
+
ct.textContent = P2.p.role;
|
|
174
|
+
return {P2: P2, c: c, rect: rect, chip: chip, cr: cr, ct: ct};
|
|
175
|
+
});
|
|
176
|
+
this.links = this.paras.filter(function(P2){ return P2.p.to && pById[P2.p.to]; }).map(function(P2){
|
|
177
|
+
var c = P2.p.rel === "~" ? "var(--accent2)" : "var(--muted)";
|
|
178
|
+
return {a: P2, b: pById[P2.p.to], rel: P2.p.rel, c: c, lv: levelOf[self.paras.indexOf(P2)] || 1,
|
|
179
|
+
path: D.el("path", {fill: "none", stroke: c, "stroke-width": 2.5, "stroke-dasharray": P2.p.rel === "~" ? "none" : "none", pathLength: 1}, self.front),
|
|
180
|
+
h1: D.el("path", {d: "M0,0L-13,-6.5L-13,6.5Z", fill: c, opacity: 0}, self.front),
|
|
181
|
+
h0: P2.p.rel === "~" ? D.el("path", {d: "M0,0L-13,-6.5L-13,6.5Z", fill: c, opacity: 0}, self.front) : null};
|
|
182
|
+
});
|
|
183
|
+
// 読み上げ:本文はそのまま読める字(role="figure" の中身)。名前は最後の形の読解のしるし(傍線・指示語・段落の役割とつながり。
|
|
184
|
+
// phases にある段階のものだけ)を 1 文で。線と枠の SVG は aria-hidden。作者の aria-label があればそれを使う(上書きしない)
|
|
185
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
186
|
+
this.setAttribute("role", "figure");
|
|
187
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary());
|
|
188
|
+
}
|
|
189
|
+
// 最後の形の読解のしるしを 1 文で(読み上げの名前)
|
|
190
|
+
summary(){
|
|
191
|
+
var m = this.model, ph = this.phaseList, out = [], anchors = {};
|
|
192
|
+
m.paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.id) anchors[r.id] = r.t; }); });
|
|
193
|
+
var runs = [].concat.apply([], m.paras.map(function(p){ return p.runs; }));
|
|
194
|
+
if (ph.indexOf("marks") >= 0) out.push(runs.filter(function(r){ return r.line; }).map(function(r){ return (r.line === 2 ? "二重傍線" : "傍線") + (r.label ? " " + r.label : "") + "「" + r.t + "」"; }).join("、"));
|
|
195
|
+
if (ph.indexOf("refs") >= 0) out.push(runs.filter(function(r){ return r.ref && anchors[r.ref] !== undefined; }).map(function(r){ return "指示語「" + r.t + "」は「" + anchors[r.ref] + "」を指す"; }).join("、"));
|
|
196
|
+
if (ph.indexOf("roles") >= 0){
|
|
197
|
+
var byId = {};
|
|
198
|
+
m.paras.forEach(function(p){ if (p.id) byId[p.id] = p; });
|
|
199
|
+
var links = m.paras.filter(function(p){ return p.to && byId[p.to]; }).map(function(p){ return (p.role || "段落") + (p.rel === "~" ? " ↔ " : " → ") + (byId[p.to].role || "段落"); });
|
|
200
|
+
out.push("段落の役割:" + m.paras.map(function(p){ return p.role; }).filter(Boolean).join("・") + (links.length ? "(" + links.join("、") + ")" : ""));
|
|
201
|
+
}
|
|
202
|
+
out = out.filter(Boolean);
|
|
203
|
+
return "現代文の読解" + (out.length ? ":" + out.join("。") : "");
|
|
204
|
+
}
|
|
205
|
+
// 要素の字の箱(行ごと)を部品の座標で。部品の外側の拡大(舞台の scale・段階の translate)によらない
|
|
206
|
+
rects(e){
|
|
207
|
+
var R = this.getBoundingClientRect(), sc = R.width / (this.offsetWidth || 1) || 1;
|
|
208
|
+
return [].map.call(e.getClientRects(), function(r){ return {l: (r.left - R.left) / sc, t: (r.top - R.top) / sc, r: (r.right - R.left) / sc, b: (r.bottom - R.top) / sc}; })
|
|
209
|
+
.filter(function(r){ return r.r - r.l > 0.5 && r.b - r.t > 0.5; });
|
|
210
|
+
}
|
|
211
|
+
box(e){ var r = this.rects(e), o = null; r.forEach(function(x){ o = o ? {l: Math.min(o.l, x.l), t: Math.min(o.t, x.t), r: Math.max(o.r, x.r), b: Math.max(o.b, x.b)} : x; }); return o; }
|
|
212
|
+
duration(k){
|
|
213
|
+
var name = this.phaseList[k - 1], P = this.props;
|
|
214
|
+
if (name === "marks") return this.lines.length * P.draw * 0.8 + 0.3;
|
|
215
|
+
if (name === "refs") return this.refs.length * (P.draw + 0.3) + 0.2;
|
|
216
|
+
if (name === "roles") return this.boxes.length * 0.35 + P.draw + (this.links.length ? 0.3 + P.draw : 0);
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
render(k, t, ctx){
|
|
220
|
+
var self = this, P = this.props, tate = P.tate;
|
|
221
|
+
var at = function(name){ var s = self.phaseStep(name); if (!s) return -1; return k > s ? Infinity : k < s ? -1 : t; };
|
|
222
|
+
var pr = function(tt, a, d){ return tt < 0 ? 0 : D.prog(tt, a, d); };
|
|
223
|
+
var tm = at("marks"), trf = at("refs"), tro = at("roles");
|
|
224
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の傍線・指示語の囲みと矢印・段落の枠と札とつなぐ線を、
|
|
225
|
+
// 引き終えた形のまま --preview-opacity の濃さで出す
|
|
226
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0.45;
|
|
227
|
+
var later = function(name){ return preview && self.phaseStep(name) > k; };
|
|
228
|
+
var fM = later("marks"), fR = later("refs"), fO = later("roles");
|
|
229
|
+
if (fM) tm = Infinity;
|
|
230
|
+
if (fR) trf = Infinity;
|
|
231
|
+
if (fO) tro = Infinity;
|
|
232
|
+
var f1 = function(x){ return x.toFixed(1); };
|
|
233
|
+
// ---- 傍線:縦書きは字の右、横書きは字の下。二重傍線は 2 本。行をまたぐときは行ごとに順に引く
|
|
234
|
+
this.lines.forEach(function(o, j){
|
|
235
|
+
var e = pr(tm, j * P.draw * 0.8, P.draw), rs = self.rects(o.el), total = 0;
|
|
236
|
+
rs.forEach(function(r){ total += tate ? r.b - r.t : r.r - r.l; });
|
|
237
|
+
while (o.g.childNodes.length > (o.lab ? 1 : 0)) o.g.removeChild(o.g.lastChild);
|
|
238
|
+
if (fM) o.g.setAttribute("opacity", PV); else o.g.removeAttribute("opacity");
|
|
239
|
+
var left = e * total;
|
|
240
|
+
rs.forEach(function(r){
|
|
241
|
+
var len = tate ? r.b - r.t : r.r - r.l, d = Math.max(0, Math.min(len, left)); left -= len;
|
|
242
|
+
if (d <= 0) return;
|
|
243
|
+
for (var q = 0; q < o.r.line; q++){
|
|
244
|
+
var off = 3 + q * 5;
|
|
245
|
+
var attrs = tate ? {x1: f1(r.r + off), x2: f1(r.r + off), y1: f1(r.t), y2: f1(r.t + d)} : {x1: f1(r.l), x2: f1(r.l + d), y1: f1(r.b + off), y2: f1(r.b + off)};
|
|
246
|
+
attrs.stroke = "var(--emph)"; attrs["stroke-width"] = 2.2;
|
|
247
|
+
D.el("line", attrs, o.g);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (o.lab && rs.length){
|
|
251
|
+
var r0 = rs[0];
|
|
252
|
+
// 記号(A など)は線の始まりの外:縦書きは線の右の列の間で始まりより上、横書きは線の下の行の間
|
|
253
|
+
// 縦書きは線のすぐ右(列の間の、自分の列に寄ったところ)に、線の始まりから下へ
|
|
254
|
+
if (tate){ o.lab.setAttribute("x", f1(r0.r + 3 + o.r.line * 5 + 7)); o.lab.setAttribute("y", f1(r0.t + 22)); }
|
|
255
|
+
else { o.lab.setAttribute("x", f1(r0.l + 10)); o.lab.setAttribute("y", f1(r0.b + 3 + o.r.line * 5 + 20)); }
|
|
256
|
+
o.lab.setAttribute("opacity", pr(tm, j * P.draw * 0.8, 0.3).toFixed(3));
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
// ---- 指示語:指示語を四角で囲み、指す先に淡い色を敷き、指示語から指す先へ矢印
|
|
260
|
+
this.refs.forEach(function(o, j){
|
|
261
|
+
var a0 = j * (P.draw + 0.3), eb = pr(trf, a0, 0.3), ea = pr(trf, a0 + 0.25, P.draw);
|
|
262
|
+
var A = self.box(o.from), B = self.box(o.to);
|
|
263
|
+
while (o.box.firstChild) o.box.removeChild(o.box.firstChild);
|
|
264
|
+
while (o.fill.firstChild) o.fill.removeChild(o.fill.firstChild);
|
|
265
|
+
if (!A || !B){ o.box.setAttribute("opacity", 0); return; }
|
|
266
|
+
if (fR) eb = ea = PV;
|
|
267
|
+
D.el("rect", {x: f1(A.l - 3), y: f1(A.t - 2), width: f1(A.r - A.l + 6), height: f1(A.b - A.t + 4), rx: 5, fill: "none", stroke: "var(--emph)", "stroke-width": 2.5}, o.box);
|
|
268
|
+
self.rects(o.to).forEach(function(r){ D.el("rect", {x: f1(r.l - 2), y: f1(r.t), width: f1(r.r - r.l + 4), height: f1(r.b - r.t), rx: 4, fill: "var(--emph-tint)"}, o.fill); });
|
|
269
|
+
o.box.setAttribute("opacity", eb.toFixed(3)); o.fill.setAttribute("opacity", ea.toFixed(3));
|
|
270
|
+
// 矢印:指す先の行(字の箱)のうち指示語に近いものへ。同じ列(行)なら列の右(行の上)に弧、違えば列の頭(行の上)の側を通す
|
|
271
|
+
var ac = {x: (A.l + A.r) / 2, y: (A.t + A.b) / 2}, Bn = null, bd = Infinity;
|
|
272
|
+
self.rects(o.to).forEach(function(r){ var d = Math.hypot((r.l + r.r) / 2 - ac.x, (r.t + r.b) / 2 - ac.y); if (d < bd){ bd = d; Bn = r; } });
|
|
273
|
+
var x0, y0, x1, y1, cx, cy, same = tate ? Math.abs((Bn.l + Bn.r) / 2 - ac.x) < 6 : Math.abs((Bn.t + Bn.b) / 2 - ac.y) < 6;
|
|
274
|
+
if (tate && same){ var up = Bn.b <= A.t; x0 = A.r + 4; y0 = up ? A.t + 4 : A.b - 4; x1 = Bn.r + 4; y1 = up ? Bn.b - 4 : Bn.t + 4; cx = Math.max(x0, x1) + 44; cy = (y0 + y1) / 2; }
|
|
275
|
+
else if (tate){ x0 = ac.x; y0 = A.t - 4; x1 = (Bn.l + Bn.r) / 2; y1 = Bn.t - 4; cx = (x0 + x1) / 2; cy = Math.min(y0, y1) - 60; }
|
|
276
|
+
else if (same){ x0 = ac.x; y0 = A.t - 2; x1 = (Bn.l + Bn.r) / 2; y1 = Bn.t - 2; cx = (x0 + x1) / 2; cy = Math.min(y0, y1) - 46; }
|
|
277
|
+
else { var above = Bn.b <= A.t; x0 = ac.x; y0 = above ? A.t - 2 : A.b + 2; x1 = (Bn.l + Bn.r) / 2; y1 = above ? Bn.b + 2 : Bn.t - 2; cx = (x0 + x1) / 2 + 40; cy = (y0 + y1) / 2; }
|
|
278
|
+
// 指示語と指す先が同じ段落なら、弧の膨らみをその段落の枠の内側にとどめる(2 次曲線の頂は端と制御点の中ほど)
|
|
279
|
+
var para = o.from.parentNode === o.to.parentNode ? self.box(o.from.parentNode) : null, pad = 6;
|
|
280
|
+
if (para){
|
|
281
|
+
var mid = function(a, b){ return (a + b) / 2; };
|
|
282
|
+
if (cy < mid(y0, y1)) cy = Math.max(cy, 2 * (para.t + pad) - mid(y0, y1));
|
|
283
|
+
if (cx > mid(x0, x1)) cx = Math.min(cx, 2 * (para.r - pad) - mid(x0, x1));
|
|
284
|
+
}
|
|
285
|
+
o.path.setAttribute("d", "M" + f1(x0) + "," + f1(y0) + "Q" + f1(cx) + "," + f1(cy) + " " + f1(x1) + "," + f1(y1));
|
|
286
|
+
o.path.setAttribute("stroke-dashoffset", (fR ? 0 : 1 - ea).toFixed(4));
|
|
287
|
+
o.path.setAttribute("opacity", fR ? PV : ea > 0 ? 1 : 0);
|
|
288
|
+
o.head.setAttribute("transform", "translate(" + f1(x1) + " " + f1(y1) + ") rotate(" + (Math.atan2(y1 - cy, x1 - cx) * 180 / Math.PI).toFixed(1) + ")");
|
|
289
|
+
o.head.setAttribute("opacity", fR ? PV : ea >= 0.98 ? 1 : 0);
|
|
290
|
+
});
|
|
291
|
+
// ---- 段落の枠:順に囲み、札を出し、最後につなぐ線
|
|
292
|
+
var nb = this.boxes.length, tLink = nb * 0.35 + P.draw;
|
|
293
|
+
var boxOf = {}, chipOf = {};
|
|
294
|
+
this.boxes.forEach(function(o, j){
|
|
295
|
+
var e = pr(tro, j * 0.35, P.draw), el = o.P2.el;
|
|
296
|
+
var x = el.offsetLeft, y = el.offsetTop, w = el.offsetWidth, h = el.offsetHeight;
|
|
297
|
+
// offset は .text の中の座標。.text は部品の左上にある
|
|
298
|
+
boxOf[o.P2.p.id || j] = {x: x, y: y, w: w, h: h};
|
|
299
|
+
o.rect.setAttribute("x", x); o.rect.setAttribute("y", y); o.rect.setAttribute("width", w); o.rect.setAttribute("height", h);
|
|
300
|
+
o.rect.setAttribute("stroke-dashoffset", (1 - e).toFixed(4));
|
|
301
|
+
o.rect.setAttribute("opacity", fO ? PV : e > 0 ? 1 : 0);
|
|
302
|
+
// 札:縦書きは枠の上の辺の右寄り、横書きは左上の角
|
|
303
|
+
var tw = Array.from(o.P2.p.role).length * 24 + 24;
|
|
304
|
+
var cx = tate ? x + w - tw / 2 - 12 : x + tw / 2 + 12, cy = tate ? y - 17 : y - 17;
|
|
305
|
+
o.cr.setAttribute("x", f1(cx - tw / 2)); o.cr.setAttribute("y", f1(cy - 17)); o.cr.setAttribute("width", tw);
|
|
306
|
+
o.ct.setAttribute("x", f1(cx)); o.ct.setAttribute("y", f1(cy + 8.5));
|
|
307
|
+
o.chip.setAttribute("opacity", (fO ? PV : pr(tro, j * 0.35 + P.draw * 0.5, 0.3)).toFixed(3));
|
|
308
|
+
chipOf[o.P2.p.id || j] = {l: cx - tw / 2, r: cx + tw / 2, t: cy - 17, b: cy + 17, at: []};
|
|
309
|
+
});
|
|
310
|
+
// 札に付く線の端:縦書きは札の上の辺に左から、横書きは札の左の辺に上から並べる。
|
|
311
|
+
// 相手が左(上)にある線を先に、段の低い順に。相手が右(下)にある線は後に、段の高い順に(縦の線が横の線を横切らないように)
|
|
312
|
+
var ends = [];
|
|
313
|
+
this.links.forEach(function(o){
|
|
314
|
+
var A = chipOf[o.a.p.id], B = chipOf[o.b.p.id];
|
|
315
|
+
if (!A || !B) return;
|
|
316
|
+
var ca = tate ? (A.l + A.r) / 2 : (A.t + A.b) / 2, cb = tate ? (B.l + B.r) / 2 : (B.t + B.b) / 2;
|
|
317
|
+
o.ea = {link: o, chip: A, dir: cb < ca ? -1 : 1}; o.eb = {link: o, chip: B, dir: ca < cb ? -1 : 1};
|
|
318
|
+
A.at.push(o.ea); B.at.push(o.eb); ends.push(A, B);
|
|
319
|
+
});
|
|
320
|
+
ends.forEach(function(C){
|
|
321
|
+
if (C.done) return; C.done = true;
|
|
322
|
+
C.at.sort(function(p, q){ return p.dir !== q.dir ? p.dir - q.dir : p.dir < 0 ? p.link.lv - q.link.lv : q.link.lv - p.link.lv; });
|
|
323
|
+
var n = C.at.length;
|
|
324
|
+
C.at.forEach(function(e, i){
|
|
325
|
+
if (tate){ e.x = C.l + (C.r - C.l) * (i + 1) / (n + 1); e.y = C.t - 1; }
|
|
326
|
+
else { e.x = C.l - 1; e.y = C.t + (C.b - C.t) * (i + 1) / (n + 1); }
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
this.links.forEach(function(o){
|
|
330
|
+
if (!o.ea){ o.path.setAttribute("opacity", 0); o.h1.setAttribute("opacity", 0); if (o.h0) o.h0.setAttribute("opacity", 0); return; }
|
|
331
|
+
var e = pr(tro, tLink, P.draw), d, ang1, ang0, x0 = o.ea.x, y0 = o.ea.y, x1 = o.eb.x, y1 = o.eb.y, rr = 8;
|
|
332
|
+
if (tate){
|
|
333
|
+
// 札の上の辺から上へ出て、段の高さを横に通り、相手の札の上の辺へ下りる(角は丸める)
|
|
334
|
+
var top = Math.min(o.ea.chip.t, o.eb.chip.t), yl = top - STUB - (o.lv - 1) * STEP, sx = x1 < x0 ? -1 : 1;
|
|
335
|
+
d = "M" + f1(x0) + "," + f1(y0) + "V" + f1(yl + rr) + "Q" + f1(x0) + "," + f1(yl) + " " + f1(x0 + sx * rr) + "," + f1(yl) +
|
|
336
|
+
"H" + f1(x1 - sx * rr) + "Q" + f1(x1) + "," + f1(yl) + " " + f1(x1) + "," + f1(yl + rr) + "V" + f1(y1);
|
|
337
|
+
ang1 = 90; ang0 = 90;
|
|
338
|
+
} else {
|
|
339
|
+
// 札の左の辺から左へ出て、段の位置を縦に通り、相手の札の左の辺へ
|
|
340
|
+
var lft = Math.min(o.ea.chip.l, o.eb.chip.l), xl = lft - STUB - (o.lv - 1) * STEP, sy = y1 < y0 ? -1 : 1;
|
|
341
|
+
d = "M" + f1(x0) + "," + f1(y0) + "H" + f1(xl + rr) + "Q" + f1(xl) + "," + f1(y0) + " " + f1(xl) + "," + f1(y0 + sy * rr) +
|
|
342
|
+
"V" + f1(y1 - sy * rr) + "Q" + f1(xl) + "," + f1(y1) + " " + f1(xl + rr) + "," + f1(y1) + "H" + f1(x1);
|
|
343
|
+
ang1 = 0; ang0 = 0;
|
|
344
|
+
}
|
|
345
|
+
o.path.setAttribute("d", d);
|
|
346
|
+
o.path.setAttribute("stroke-dasharray", "1"); o.path.setAttribute("stroke-dashoffset", (1 - e).toFixed(4));
|
|
347
|
+
o.path.setAttribute("opacity", fO ? PV : e > 0 ? 1 : 0);
|
|
348
|
+
o.h1.setAttribute("transform", "translate(" + f1(x1) + " " + f1(y1) + ") rotate(" + ang1 + ")");
|
|
349
|
+
o.h1.setAttribute("opacity", fO ? PV : e >= 0.98 ? 1 : 0);
|
|
350
|
+
if (o.h0){ o.h0.setAttribute("transform", "translate(" + f1(x0) + " " + f1(y0) + ") rotate(" + ang0 + ")"); o.h0.setAttribute("opacity", fO ? PV : e >= 0.98 ? 1 : 0); }
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
});
|