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,404 @@
|
|
|
1
|
+
// m-particles:状態変化の粒子モデルと、化学変化で保存される原子のモデル。
|
|
2
|
+
egatariParts.define({name: "particles", version: "2.0.3", requires: {base: "1.3.0"}, element: "m-particles"}, function(deps){
|
|
3
|
+
"use strict";
|
|
4
|
+
var base = deps.base;
|
|
5
|
+
var STATES = ["solid", "liquid", "gas"];
|
|
6
|
+
var SHAPES = ["linear", "bent", "trigonal", "tetrahedral", "chain"];
|
|
7
|
+
var MOLECULE_SHAPES = {H2O: "bent", H2S: "bent", SO2: "bent", CO2: "linear", NH3: "trigonal", CH4: "tetrahedral"};
|
|
8
|
+
var TEXT = {
|
|
9
|
+
ja: {states: ["固体", "液体", "気体"], changes: {solidliquid: "融解", liquidgas: "沸騰", liquidsolid: "凝固", gasliquid: "凝縮", solidgas: "昇華", gassolid: "昇華"}, before: "反応前", apart: "原子に分かれる", after: "反応後", atoms: "原子の数:", invalid: "データを確認してください"},
|
|
10
|
+
en: {states: ["Solid", "Liquid", "Gas"], changes: {solidliquid: "melting", liquidgas: "boiling", liquidsolid: "freezing", gasliquid: "condensation", solidgas: "sublimation", gassolid: "sublimation"}, before: "Reactants", apart: "Separate atoms", after: "Products", atoms: "Atoms: ", invalid: "Check the data"}
|
|
11
|
+
};
|
|
12
|
+
var COLORS = ["series-1", "series-2", "series-3", "series-4", "term", "accent2"];
|
|
13
|
+
// 全体が読めたときだけ採用する。括弧・電荷・係数・0・不正な桁を黙って落とさない。
|
|
14
|
+
function parseFormula(s){
|
|
15
|
+
if (typeof s !== "string" || !/^(?:[A-Z][a-z]?(?:[1-9][0-9]*)?)+$/.test(s)) throw new Error("formula " + JSON.stringify(s) + ": use element symbols and positive integer counts (no parentheses or charges)");
|
|
16
|
+
var out = [], counts = Object.create(null), re = /([A-Z][a-z]?)([1-9][0-9]*)?/g, m;
|
|
17
|
+
while ((m = re.exec(s))){
|
|
18
|
+
var n = m[2] ? +m[2] : 1;
|
|
19
|
+
if (!Number.isSafeInteger(n) || n > 24 || out.length + n > 24) throw new Error("formula " + s + ": more than 24 atoms");
|
|
20
|
+
counts[m[1]] = (counts[m[1]] || 0) + n;
|
|
21
|
+
for (var i = 0; i < n; i++) out.push(m[1]);
|
|
22
|
+
}
|
|
23
|
+
return {atoms: out, counts: counts};
|
|
24
|
+
}
|
|
25
|
+
function formulaText(s){ return s.replace(/([0-9])/g, "_$1"); }
|
|
26
|
+
function unicodeFormula(s){ return s.replace(/[0-9]/g, function(n){ return "₀₁₂₃₄₅₆₇₈₉"[+n]; }); }
|
|
27
|
+
function equation(side, format){ return side.map(function(m){ return (m.n === 1 ? "" : m.n) + format(m.formula); }).join(" + "); }
|
|
28
|
+
function hash(i){
|
|
29
|
+
var n = Math.imul(i + 1, 2654435761); n ^= n >>> 16;
|
|
30
|
+
n = Math.imul(n, 2246822507); n ^= n >>> 13; n = Math.imul(n, 3266489909); n ^= n >>> 16;
|
|
31
|
+
return (n >>> 0) / 4294967296;
|
|
32
|
+
}
|
|
33
|
+
// 正方形に近い因数の組を選ぶ。素数や容器に収まる組がない場合は最終行を中央に置く。
|
|
34
|
+
function latticeColumns(n, aspect, maxCols){
|
|
35
|
+
var ideal = Math.sqrt(n * aspect), best = 0, error = Infinity;
|
|
36
|
+
for (var c = Math.ceil(Math.sqrt(n)); c <= Math.min(maxCols || n, n > 3 ? n / 2 : n); c++) if (n % c === 0){
|
|
37
|
+
var d = Math.abs(c - ideal); if (d < error){ best = c; error = d; }
|
|
38
|
+
}
|
|
39
|
+
return Math.max(1, best || Math.min(maxCols || n, Math.ceil(ideal))); // at least 1 column, also when the box is 0 wide
|
|
40
|
+
}
|
|
41
|
+
function segmentDistance(p, a, b){
|
|
42
|
+
var dx = b.x - a.x, dy = b.y - a.y, den = dx * dx + dy * dy;
|
|
43
|
+
var u = den ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / den)) : 0;
|
|
44
|
+
return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
|
|
45
|
+
}
|
|
46
|
+
function set(e, a, v){ v = String(v); if (e.getAttribute(a) !== v) e.setAttribute(a, v); }
|
|
47
|
+
function text(e, s){ if (e.textContent !== s) e.textContent = s; }
|
|
48
|
+
var Part = class extends base.MotionElement {
|
|
49
|
+
static partName = "particles";
|
|
50
|
+
// 先の並び方・生成物を授業で予想させる(orbit と同じ扱い)。
|
|
51
|
+
static preview = "none";
|
|
52
|
+
static steps = 2;
|
|
53
|
+
static shape = {
|
|
54
|
+
schema: {type: "object", additionalProperties: false, properties: {
|
|
55
|
+
states: {type: "array", minItems: 1, items: {type: "string", enum: STATES}},
|
|
56
|
+
substance: {type: "string"},
|
|
57
|
+
labels: {type: ["array", "object"], items: {type: ["string", "null"]}, properties: {before: {type: "string"}, apart: {type: "string"}, after: {type: "string"}, atoms: {type: "string"}}, additionalProperties: false},
|
|
58
|
+
reactants: {type: "array", minItems: 1, maxItems: 24, items: {type: "object", required: ["formula", "n"], additionalProperties: false, properties: {formula: {type: "string"}, n: {type: "integer"}, shape: {type: "string", enum: SHAPES}}}},
|
|
59
|
+
products: {type: "array", minItems: 1, maxItems: 24, items: {type: "object", required: ["formula", "n"], additionalProperties: false, properties: {formula: {type: "string"}, n: {type: "integer"}, shape: {type: "string", enum: SHAPES}}}}
|
|
60
|
+
}},
|
|
61
|
+
example: {states: ["solid", "liquid", "gas"], substance: "水"}
|
|
62
|
+
};
|
|
63
|
+
static props = {
|
|
64
|
+
mode: {type: "string", default: "state", doc: "state(状態変化)か reaction(化学変化)"},
|
|
65
|
+
count: {type: "number", default: 16, doc: "状態変化で描く粒子の数(6〜30 の整数。数と大きさは一定)"},
|
|
66
|
+
size: {type: "number", default: 28, doc: "名前・式の字の大きさ(px。24 以上)"},
|
|
67
|
+
dur: {type: "number", default: 1.2, doc: "1 ステップの動きの秒数"},
|
|
68
|
+
volume: {type: "bool", default: false, doc: "状態に合わせて容器の幅を変える(気体は広い)"},
|
|
69
|
+
motion: {type: "bool", default: true, doc: "状態変化の粒子に静止した運動の印を付ける"}
|
|
70
|
+
};
|
|
71
|
+
get data(){
|
|
72
|
+
var d = super.data;
|
|
73
|
+
// JSON がない場合だけ既定値。JSON の null や不正な型は base の shape 検査へ渡す。
|
|
74
|
+
var hasJSON = [].some.call(this.children, function(c){ return c.localName === "script" && String(c.getAttribute("type") || "").trim().toLowerCase() === "application/json"; });
|
|
75
|
+
return d === null && !hasJSON ? {} : d;
|
|
76
|
+
}
|
|
77
|
+
get steps(){ return this.plan().reaction ? 3 : this.plan().states.length - 1; }
|
|
78
|
+
duration(k){ return k >= 1 && k <= this.steps ? (Number.isFinite(this.props.dur) && this.props.dur > 0 ? this.props.dur : 1.2) : 0; }
|
|
79
|
+
plan(){
|
|
80
|
+
if (this._plan) return this._plan;
|
|
81
|
+
var d = this.data || {}, p = {reaction: this.props.mode === "reaction", states: d.states || STATES, notes: [], fatal: false};
|
|
82
|
+
if (!p.reaction){
|
|
83
|
+
if (d.reactants || d.products || (d.labels && !Array.isArray(d.labels))){ p.notes.push("state mode takes states and a labels array"); p.fatal = true; }
|
|
84
|
+
return (this._plan = p);
|
|
85
|
+
}
|
|
86
|
+
p.elements = []; p.sides = []; p.totals = [];
|
|
87
|
+
try {
|
|
88
|
+
if (!d.reactants || !d.products || Array.isArray(d.labels) || d.states || d.substance) throw new Error("reaction mode needs reactants, products and optional labels object");
|
|
89
|
+
[d.reactants, d.products].forEach(function(side){
|
|
90
|
+
var molecules = [], total = Object.create(null), N = 0;
|
|
91
|
+
side.forEach(function(m){
|
|
92
|
+
if (!Number.isSafeInteger(m.n) || m.n < 1 || m.n > 24) throw new Error("coefficient n must be an integer from 1 to 24");
|
|
93
|
+
var f = parseFormula(m.formula);
|
|
94
|
+
N += f.atoms.length * m.n;
|
|
95
|
+
if (N > 24) throw new Error("more than 24 atoms on one side (maximum conserved inventory: 24)");
|
|
96
|
+
Object.keys(f.counts).forEach(function(e){
|
|
97
|
+
if (p.elements.indexOf(e) < 0) p.elements.push(e);
|
|
98
|
+
total[e] = (total[e] || 0) + f.counts[e] * m.n;
|
|
99
|
+
});
|
|
100
|
+
for (var j = 0; j < m.n; j++) molecules.push({atoms: f.atoms.slice(), shape: m.shape || MOLECULE_SHAPES[m.formula] || (f.atoms.length <= 3 ? "linear" : "chain")});
|
|
101
|
+
});
|
|
102
|
+
p.sides.push(molecules); p.totals.push(total);
|
|
103
|
+
});
|
|
104
|
+
if (p.elements.length > 6) throw new Error("more than 6 elements");
|
|
105
|
+
p.balanced = p.elements.every(function(e){ return (p.totals[0][e] || 0) === (p.totals[1][e] || 0); });
|
|
106
|
+
p.counts = p.elements.map(function(e){ return e + " " + (p.totals[0][e] || 0) + " → " + (p.totals[1][e] || 0); });
|
|
107
|
+
if (!p.balanced) p.notes.push("unbalanced equation: " + p.counts.join(", ") + "; static comparison only");
|
|
108
|
+
p.eq = equation(d.reactants, formulaText) + " → " + equation(d.products, formulaText);
|
|
109
|
+
p.accessible = equation(d.reactants, unicodeFormula) + " → " + equation(d.products, unicodeFormula);
|
|
110
|
+
} catch (e){ p.notes.push(e.message); p.fatal = true; }
|
|
111
|
+
return (this._plan = p);
|
|
112
|
+
}
|
|
113
|
+
mount(ctx){
|
|
114
|
+
var P = this.props, p = this.plan(), self = this;
|
|
115
|
+
p.notes.forEach(function(m){ ctx.report("data", "[particles] " + m); });
|
|
116
|
+
if (["state", "reaction"].indexOf(P.mode) < 0) ctx.report("attr", "[particles] unknown mode; using state");
|
|
117
|
+
[["count", 16, function(v){ return Number.isInteger(v) && v >= 6 && v <= 30; }], ["size", 28, function(v){ return Number.isFinite(v) && v >= 24; }], ["dur", 1.2, function(v){ return Number.isFinite(v) && v > 0; }]].forEach(function(a){
|
|
118
|
+
if (!a[2](P[a[0]])){ ctx.report("attr", "[particles] invalid " + a[0] + "; using " + a[1]); P[a[0]] = a[1]; }
|
|
119
|
+
});
|
|
120
|
+
var lang = this.closest("[lang]");
|
|
121
|
+
this.T = /^ja\b/i.test((lang && lang.getAttribute("lang")) || ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
122
|
+
this.words = Object.assign({}, this.T, p.reaction ? (this.data || {}).labels : {});
|
|
123
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
|
|
124
|
+
this.W = this.clientWidth; this.H = this.clientHeight;
|
|
125
|
+
this.svg = base.el("svg", {viewBox: "0 0 " + this.W + " " + this.H, width: this.W, height: this.H, "aria-hidden": "true", style: "display:block"}, this);
|
|
126
|
+
this.setAttribute("role", "img");
|
|
127
|
+
if (p.fatal){ this.label(this.svg, this.W / 2, this.H / 2, this.T.invalid); if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", this.T.invalid); return; }
|
|
128
|
+
if (p.reaction) this.drawReaction(ctx); else this.drawState(ctx);
|
|
129
|
+
if (!this.getAttribute("aria-label")){
|
|
130
|
+
var ja = this.T === TEXT.ja;
|
|
131
|
+
var name = p.reaction ? p.accessible + ". " + this.words.atoms + p.counts.join(ja ? "、" : ", ") :
|
|
132
|
+
((this.data || {}).substance ? this.data.substance + (ja ? "の" : " ") : "") + (ja ? "粒子のモデル:" : "particle model: ") + p.states.map(function(s, i){ return self.stateLabel(i); }).join("→") +
|
|
133
|
+
(ja ? "。粒子の数(" + P.count + ")と大きさは変わらず、間隔と動きが変わる" : ". Particle count (" + P.count + ") and size stay constant; spacing and motion change.");
|
|
134
|
+
this.setAttribute("aria-label", name);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
label(g, x, y, s, fs, anchor, tone){
|
|
138
|
+
return base.mtext(g, x, y, s, {"font-size": fs || this.props.size, "text-anchor": anchor || "middle", fill: "var(--" + (tone || "fg") + ")"});
|
|
139
|
+
}
|
|
140
|
+
checkWidth(s, fs, width, ctx){ if (base.textWidth(s, fs, {font: this, mark: true}) > width) ctx.report("size", "[particles] a label does not fit; shorten it or make the element larger"); }
|
|
141
|
+
stateLabel(i){ var d = this.data || {}, v = (d.labels || [])[i]; return v === undefined || v === null ? this.T.states[STATES.indexOf(this.plan().states[i])] : v; }
|
|
142
|
+
stateBox(s){
|
|
143
|
+
var full = Math.max(0, Math.min(this.W - 40, 700)), w = full; // 0 when the element is too narrow, never negative
|
|
144
|
+
if (this.props.volume && s !== "gas"){
|
|
145
|
+
var layerWidth = 54;
|
|
146
|
+
for (var i = 1; i < Math.ceil((this.props.count + 1) / 2); i++) layerWidth += 38.2 + 3 * hash(i + 71);
|
|
147
|
+
w = Math.min(full, Math.max(full * 0.72, layerWidth));
|
|
148
|
+
}
|
|
149
|
+
var h = Math.max(0, Math.min(this.H - 108, Math.max(240, Math.ceil(this.props.count / 6) * 50 + 40)));
|
|
150
|
+
return {x: (this.W - w) / 2, y: 44, width: w, height: h};
|
|
151
|
+
}
|
|
152
|
+
boxWidth(s){ return this.stateBox(s).width; }
|
|
153
|
+
arrangement(s){
|
|
154
|
+
var N = this.props.count, r = 19, box = this.stateBox(s), floor = box.y + box.height - r - 1.5, out = [], i;
|
|
155
|
+
if (s === "gas"){
|
|
156
|
+
// 最良候補法。格子からずらすのでなく、既存の点から最も離れた候補を採る。
|
|
157
|
+
var margin = r + 30;
|
|
158
|
+
for (i = 0; i < N; i++){
|
|
159
|
+
var best = null, score = -1;
|
|
160
|
+
for (var j = 0; j < 768; j++){
|
|
161
|
+
var seed = i * 1536 + j * 2 + 503;
|
|
162
|
+
var q = {x: box.x + margin + hash(seed) * (box.width - 2 * margin), y: box.y + margin + hash(seed + 1) * (box.height - 2 * margin)};
|
|
163
|
+
var d = out.length ? Math.min.apply(null, out.map(function(a){ return Math.hypot(q.x - a.x, q.y - a.y); })) : 1;
|
|
164
|
+
if (d > score){ score = d; best = q; }
|
|
165
|
+
if (!i) break;
|
|
166
|
+
}
|
|
167
|
+
out.push(best);
|
|
168
|
+
}
|
|
169
|
+
} else if (s === "solid"){
|
|
170
|
+
var pitch = 2 * r + 3, cols = latticeColumns(N, 1, Math.max(1, Math.floor((box.width - 2 * r - 8) / pitch) + 1));
|
|
171
|
+
for (i = 0; i < N;){
|
|
172
|
+
var row = Math.floor(i / cols), n = Math.min(cols, N - i);
|
|
173
|
+
for (var c = 0; c < n; c++, i++) out.push({x: this.W / 2 + (c - (n - 1) / 2) * pitch, y: floor - row * pitch});
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
// 床の列から積む。上の粒子は下の隣接する 2 粒子に接し、全ての中心間距離は 2r 以上。
|
|
177
|
+
var contact = 2 * r + 0.2;
|
|
178
|
+
var cols = Math.ceil((N + 1) / 2);
|
|
179
|
+
var row = [], x = 0;
|
|
180
|
+
for (i = 0; i < Math.min(cols, N); i++){
|
|
181
|
+
if (i){
|
|
182
|
+
var nextX = x + contact + 3 * hash(i + 71);
|
|
183
|
+
if (nextX + 2 * r + 16 > box.width + 1e-6) break;
|
|
184
|
+
x = nextX;
|
|
185
|
+
}
|
|
186
|
+
row.push({x: x, y: floor});
|
|
187
|
+
}
|
|
188
|
+
var offset = this.W / 2 - x / 2;
|
|
189
|
+
row.forEach(function(q){ q.x += offset; out.push(q); });
|
|
190
|
+
while (out.length < N && row.length > 1){
|
|
191
|
+
var next = [];
|
|
192
|
+
for (i = 0; i < row.length - 1; i++){
|
|
193
|
+
var a = row[i], b = row[i + 1], dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
|
|
194
|
+
var lift = Math.sqrt(Math.max(0, contact * contact - d * d / 4));
|
|
195
|
+
next.push({x: (a.x + b.x) / 2 + dy / d * lift, y: (a.y + b.y) / 2 - dx / d * lift});
|
|
196
|
+
}
|
|
197
|
+
var need = Math.min(next.length, N - out.length), start = Math.floor((next.length - need) / 2);
|
|
198
|
+
row = next.slice(start, start + need); row.forEach(function(q){ out.push(q); });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
separateParticles(points, box){
|
|
204
|
+
// 補間の途中も円を重ねない。毎フレーム同じ入力から解き、前の render に依存しない。
|
|
205
|
+
for (var it = 0; it < 240; it++){
|
|
206
|
+
var moved = false;
|
|
207
|
+
for (var i = 0; i < points.length; i++) for (var j = i + 1; j < points.length; j++){
|
|
208
|
+
var a = points[i], b = points[j], dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
|
|
209
|
+
if (d >= 38) continue;
|
|
210
|
+
var angle = hash(i * 31 + j) * 2 * Math.PI, ux = d > 1e-8 ? dx / d : Math.cos(angle), uy = d > 1e-8 ? dy / d : Math.sin(angle), shift = (38.02 - d) / 2;
|
|
211
|
+
a.x -= ux * shift; a.y -= uy * shift; b.x += ux * shift; b.y += uy * shift; moved = true;
|
|
212
|
+
}
|
|
213
|
+
points.forEach(function(q){ q.x = Math.max(box.x + 20.5, Math.min(box.x + box.width - 20.5, q.x)); q.y = Math.max(box.y + 20.5, Math.min(box.y + box.height - 20.5, q.y)); });
|
|
214
|
+
if (!moved) break;
|
|
215
|
+
}
|
|
216
|
+
return points;
|
|
217
|
+
}
|
|
218
|
+
transitionLabel(k){
|
|
219
|
+
if (!k) return this.stateLabel(0);
|
|
220
|
+
var p = this.plan(), change = this.T.changes[p.states[k - 1] + p.states[k]], ja = this.T === TEXT.ja;
|
|
221
|
+
return this.stateLabel(k - 1) + " → " + this.stateLabel(k) + (change ? (ja ? "(" : " (") + change + (ja ? ")" : ")") : "");
|
|
222
|
+
}
|
|
223
|
+
// 矢印の軸・矢じりの全てが、容器の中かつ他の粒子の外にある向きを選ぶ。
|
|
224
|
+
motionArrow(points, i, length, box){
|
|
225
|
+
var r = 19, p = points[i], best = null, score = -Infinity;
|
|
226
|
+
for (var n = 0; n < 72; n++){
|
|
227
|
+
var angle = (hash(i + 101) * 360 + n * 5) * Math.PI / 180, co = Math.cos(angle), si = Math.sin(angle);
|
|
228
|
+
var tip = r + 1.5 + length, local = [[r + 1.5, 0], [tip, 0], [tip - 3, -1.5], [tip - 3, 1.5]];
|
|
229
|
+
var q = local.map(function(v){ return {x: p.x + co * v[0] - si * v[1], y: p.y + si * v[0] + co * v[1]}; });
|
|
230
|
+
if (!q.every(function(v){ return v.x >= box.x + 2 && v.x <= box.x + box.width - 2 && v.y >= box.y + 2 && v.y <= box.y + box.height - 2; })) continue;
|
|
231
|
+
var segments = [[q[0], q[1]], [q[1], q[2]], [q[1], q[3]]], clearance = Infinity;
|
|
232
|
+
points.forEach(function(a, j){ if (j !== i) segments.forEach(function(seg){ clearance = Math.min(clearance, segmentDistance(a, seg[0], seg[1]) - r); }); });
|
|
233
|
+
if (clearance >= 1.2 && clearance > score){ score = clearance; best = {angle: angle * 180 / Math.PI, segments: segments, path: "M" + (r + 1.5) + ",0H" + tip + "m-3,-1.5L" + tip + ",0l-3,1.5"}; }
|
|
234
|
+
}
|
|
235
|
+
return best;
|
|
236
|
+
}
|
|
237
|
+
drawState(ctx){
|
|
238
|
+
var p = this.plan(), self = this, N = this.props.count;
|
|
239
|
+
this.particleRadius = 19; this.arrangements = {};
|
|
240
|
+
STATES.forEach(function(s){ self.arrangements[s] = self.arrangement(s); });
|
|
241
|
+
var fits = STATES.every(function(s){
|
|
242
|
+
var box = self.stateBox(s), points = self.arrangements[s];
|
|
243
|
+
return points.length === N && points.every(function(q, i){
|
|
244
|
+
return q.x - 19 >= box.x && q.x + 19 <= box.x + box.width && q.y - 19 >= box.y && q.y + 19 <= box.y + box.height &&
|
|
245
|
+
points.every(function(a, j){ return i === j || Math.hypot(q.x - a.x, q.y - a.y) >= (s === "gas" ? 2.6 * 19 : 38) - 1e-6; });
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
if (!fits) ctx.report("size", "[particles] particle model needs a larger box");
|
|
249
|
+
this.label(this.svg, this.W / 2, 29, (this.data || {}).substance || "");
|
|
250
|
+
this.box = base.el("rect", {rx: 16, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, this.svg);
|
|
251
|
+
this.particles = []; this.marks = [];
|
|
252
|
+
for (var i = 0; i < N; i++){
|
|
253
|
+
var g = base.el("g", {"data-particle": i}, this.svg);
|
|
254
|
+
base.el("circle", {r: 19, fill: "var(--term)"}, g);
|
|
255
|
+
this.marks.push(base.el("path", {fill: "none", stroke: "var(--fg)", "stroke-width": 1.5}, g));
|
|
256
|
+
this.particles.push(g);
|
|
257
|
+
}
|
|
258
|
+
this.stateName = this.label(this.svg, this.W / 2, this.stateBox("gas").y + this.stateBox("gas").height + 42, "");
|
|
259
|
+
for (var k = 0; k <= this.steps; k++) self.checkWidth(this.transitionLabel(k), this.props.size, this.W - 16, ctx);
|
|
260
|
+
this.checkWidth((this.data || {}).substance || "", this.props.size, this.W - 16, ctx);
|
|
261
|
+
}
|
|
262
|
+
// 中心原子と周囲の原子を平面に置く。未知の 3 原子分子は直線にする。
|
|
263
|
+
molecule(atoms, r, shape){
|
|
264
|
+
shape = shape || (atoms.length <= 3 ? "linear" : "chain");
|
|
265
|
+
var order = atoms.map(function(_, i){ return i; }), counts = {};
|
|
266
|
+
atoms.forEach(function(e){ counts[e] = (counts[e] || 0) + 1; });
|
|
267
|
+
var radial = (shape === "bent" && atoms.length === 3) || (shape === "trigonal" && atoms.length === 4) || (shape === "tetrahedral" && atoms.length === 5);
|
|
268
|
+
if (radial || (shape === "linear" && atoms.length === 3)){
|
|
269
|
+
var center = atoms.findIndex(function(e){ return counts[e] === 1; });
|
|
270
|
+
if (center >= 0){ order.splice(order.indexOf(center), 1); order.unshift(center); }
|
|
271
|
+
}
|
|
272
|
+
var cols = shape === "linear" ? atoms.length : Math.min(6, atoms.length), out = [];
|
|
273
|
+
order.forEach(function(j, i){
|
|
274
|
+
if (radial){
|
|
275
|
+
var angle = shape === "bent" ? (i === 1 ? 5 : 1) * Math.PI / 6 : -Math.PI / 2 + (i - 1) * 2 * Math.PI / (atoms.length - 1);
|
|
276
|
+
out[j] = i ? [2 * r * Math.cos(angle), 2 * r * Math.sin(angle)] : [0, 0];
|
|
277
|
+
} else if (shape === "linear" && atoms.length === 3){
|
|
278
|
+
out[j] = [[0, 0], [-2 * r, 0], [2 * r, 0]][i];
|
|
279
|
+
} else out[j] = [(i % cols) * r * 2, Math.floor(i / cols) * r * 2];
|
|
280
|
+
});
|
|
281
|
+
var minX = Math.min.apply(null, out.map(function(a){ return a[0]; })), minY = Math.min.apply(null, out.map(function(a){ return a[1]; }));
|
|
282
|
+
return out.map(function(a){ return {x: a[0] - minX + r, y: a[1] - minY + r}; });
|
|
283
|
+
}
|
|
284
|
+
moleculeLayout(side, width, r){
|
|
285
|
+
var self = this, slots = [], rows = [], row = [], rowW = 0, rowH = 0;
|
|
286
|
+
function flush(){ if (row.length) rows.push({molecules: row, width: rowW, height: rowH}); row = []; rowW = rowH = 0; }
|
|
287
|
+
side.forEach(function(m){
|
|
288
|
+
var atoms = m.atoms, pts = self.molecule(atoms, r, m.shape), w = Math.max.apply(null, pts.map(function(q){ return q.x; })) + r, h = Math.max.apply(null, pts.map(function(q){ return q.y; })) + r;
|
|
289
|
+
if (row.length && rowW + 24 + w > width) flush();
|
|
290
|
+
row.push({atoms: atoms, points: pts, width: w, height: h}); rowW += (row.length > 1 ? 24 : 0) + w; rowH = Math.max(rowH, h);
|
|
291
|
+
});
|
|
292
|
+
flush();
|
|
293
|
+
var y = 0, maxW = 0;
|
|
294
|
+
rows.forEach(function(row){
|
|
295
|
+
var x = (width - row.width) / 2; maxW = Math.max(maxW, row.width);
|
|
296
|
+
row.molecules.forEach(function(m){
|
|
297
|
+
m.points.forEach(function(q, i){ slots.push({e: m.atoms[i], x: x + q.x, y: y + (row.height - m.height) / 2 + q.y}); });
|
|
298
|
+
x += m.width + 24;
|
|
299
|
+
});
|
|
300
|
+
y += row.height + 22;
|
|
301
|
+
});
|
|
302
|
+
return {slots: slots, width: maxW, height: y - 22};
|
|
303
|
+
}
|
|
304
|
+
separatedLayout(n, r){
|
|
305
|
+
var cols = Math.min(n, latticeColumns(n, 2.5, Math.max(1, Math.floor((this.W - 24 - 2 * r) / (3 * r + 8)) + 1))), rows = Math.ceil(n / cols), pitch = 3 * r + 8, points = [];
|
|
306
|
+
for (var i = 0; i < n;){
|
|
307
|
+
var row = Math.floor(i / cols), count = Math.min(cols, n - i);
|
|
308
|
+
for (var j = 0; j < count; j++, i++) points.push({x: (j - (count - 1) / 2) * pitch, y: row * pitch + r});
|
|
309
|
+
}
|
|
310
|
+
return {points: points, width: (cols - 1) * pitch + 2 * r, height: (rows - 1) * pitch + 2 * r};
|
|
311
|
+
}
|
|
312
|
+
atom(g, a, id){
|
|
313
|
+
var p = this.plan(), tone = COLORS[p.elements.indexOf(a.e)], group = base.el("g", id === null ? {} : {"data-atom": id, "data-element": a.e}, g);
|
|
314
|
+
base.el("circle", {r: this.radius, fill: "none", stroke: "var(--" + tone + ")", "stroke-width": 3}, group);
|
|
315
|
+
this.label(group, 0, 8, a.e, 24, "middle", tone);
|
|
316
|
+
set(group, "transform", "translate(" + a.x + " " + a.y + ")");
|
|
317
|
+
return group;
|
|
318
|
+
}
|
|
319
|
+
drawReaction(ctx){
|
|
320
|
+
var p = this.plan(), self = this, W = this.W, gutter = 112, maxSide = (W - 24 - gutter) / 2, L;
|
|
321
|
+
// 全段階で同じ半径。大きいデータだけ少し小さくし、分離時にも一半径以上の隙間を確保する。
|
|
322
|
+
for (var r = 34; r >= 24; r--){
|
|
323
|
+
var source = this.moleculeLayout(p.sides[0], maxSide, r), target = this.moleculeLayout(p.sides[1], maxSide, r), free = this.separatedLayout(source.slots.length, r);
|
|
324
|
+
var pictureH = Math.max(source.height, target.height), height = Math.max(44 + pictureH + 94, 44 + free.height);
|
|
325
|
+
L = {radius: r, source: source, target: target, free: free, pictureH: pictureH, height: height};
|
|
326
|
+
if (height <= this.H - 8 && source.width <= maxSide && target.width <= maxSide && free.width <= W - 24) break;
|
|
327
|
+
}
|
|
328
|
+
if (L.height > this.H - 8 || L.source.width > maxSide || L.target.width > maxSide || L.free.width > W - 24) ctx.report("size", "[particles] molecules need a larger element");
|
|
329
|
+
this.radius = L.radius;
|
|
330
|
+
var sideW = Math.max(L.source.width, L.target.width, base.textWidth(this.words.before, 24, {font: this}), base.textWidth(this.words.after, 24, {font: this}), 160);
|
|
331
|
+
if (sideW > maxSide) ctx.report("size", "[particles] group captions need a wider element");
|
|
332
|
+
var left = (W - 2 * sideW - gutter) / 2, top = (this.H - L.height) / 2, captionY = top + 24, pictureTop = top + 44;
|
|
333
|
+
source = this.moleculeLayout(p.sides[0], sideW, L.radius); target = this.moleculeLayout(p.sides[1], sideW, L.radius);
|
|
334
|
+
function place(layout, x){ return layout.slots.map(function(q){ return {e: q.e, x: q.x + x, y: q.y + pictureTop + (L.pictureH - layout.height) / 2}; }); }
|
|
335
|
+
this.source = place(source, left); this.target = place(target, left + sideW + gutter);
|
|
336
|
+
this.separated = L.free.points.map(function(q){ return {x: W / 2 + q.x, y: pictureTop + q.y}; });
|
|
337
|
+
this.reactionLayout = {captionY: captionY, pictureTop: pictureTop, pictureBottom: pictureTop + L.pictureH, arrowY: pictureTop + L.pictureH / 2};
|
|
338
|
+
this.beforeName = this.label(this.svg, left + sideW / 2, captionY, this.words.before, 24);
|
|
339
|
+
this.afterName = this.label(this.svg, left + sideW * 1.5 + gutter, captionY, this.words.after, 24);
|
|
340
|
+
this.stageName = this.label(this.svg, W / 2, captionY, "", 24);
|
|
341
|
+
this.arrow = base.el("path", {d: "M" + (W / 2 - 32) + "," + this.reactionLayout.arrowY + "h64m-12,-8l12,8l-12,8", fill: "none", stroke: "var(--muted)", "stroke-width": 3}, this.svg);
|
|
342
|
+
this.reference = base.el("g", {"data-reference": "reactants"}, this.svg);
|
|
343
|
+
this.source.forEach(function(a){ self.atom(self.reference, a, null); });
|
|
344
|
+
this.live = base.el("g", {}, this.svg);
|
|
345
|
+
this.atoms = this.source.map(function(a, i){ return self.atom(self.live, a, i); });
|
|
346
|
+
var queues = Object.create(null);
|
|
347
|
+
this.source.forEach(function(a, i){ (queues[a.e] || (queues[a.e] = [])).push(i); });
|
|
348
|
+
this.destinations = this.source.map(function(a){ return a; });
|
|
349
|
+
if (p.balanced) this.target.forEach(function(a){ self.destinations[queues[a.e].shift()] = a; });
|
|
350
|
+
this.productReference = base.el("g", {"data-reference": "products"}, this.svg);
|
|
351
|
+
if (!p.balanced) this.target.forEach(function(a){ self.atom(self.productReference, a, null); });
|
|
352
|
+
this.summary = base.el("g", {}, this.svg);
|
|
353
|
+
this.equationName = this.label(this.summary, W / 2, this.reactionLayout.pictureBottom + 42, p.eq);
|
|
354
|
+
this.checkWidth(p.eq, this.props.size, W - 24, ctx);
|
|
355
|
+
var sep = this.T === TEXT.ja ? "、" : ", ", countText = this.words.atoms + p.counts.join(sep);
|
|
356
|
+
this.countsLine = base.el("text", {x: W / 2, y: this.reactionLayout.pictureBottom + 86, "font-size": 24, "text-anchor": "middle", fill: "var(--fg)"}, this.summary);
|
|
357
|
+
base.el("tspan", {}, this.countsLine).textContent = this.words.atoms;
|
|
358
|
+
p.elements.forEach(function(e, i){
|
|
359
|
+
base.el("tspan", {fill: "var(--" + ((p.totals[0][e] || 0) === (p.totals[1][e] || 0) ? "fg" : "emph") + ")"}, self.countsLine).textContent = (i ? sep : "") + p.counts[i];
|
|
360
|
+
});
|
|
361
|
+
this.checkWidth(countText, 24, W - 24, ctx);
|
|
362
|
+
[this.words.before, this.words.after].forEach(function(s){ self.checkWidth(s, 24, sideW, ctx); });
|
|
363
|
+
this.checkWidth(this.words.apart, 24, W - 24, ctx);
|
|
364
|
+
}
|
|
365
|
+
render(k, t){
|
|
366
|
+
var p = this.plan(); if (!this.svg || p.fatal) return;
|
|
367
|
+
k = Math.max(0, Math.min(this.steps, k));
|
|
368
|
+
var e = k ? base.prog(t, 0, this.duration(k)) : 0, self = this;
|
|
369
|
+
if (!p.reaction){
|
|
370
|
+
var a = Math.max(0, k - 1), b = k, from = p.states[a], to = p.states[b], A = this.arrangements[from], B = this.arrangements[to];
|
|
371
|
+
var boxA = this.stateBox(from), boxB = this.stateBox(to), box = {};
|
|
372
|
+
["x", "y", "width", "height"].forEach(function(key){ box[key] = base.lerp(boxA[key], boxB[key], e); set(self.box, key, box[key]); });
|
|
373
|
+
var points = this.currentParticles = this.separateParticles(A.map(function(q, i){ return {x: base.lerp(q.x, B[i].x, e), y: base.lerp(q.y, B[i].y, e)}; }), box);
|
|
374
|
+
this.motionPaths = [];
|
|
375
|
+
this.particles.forEach(function(g, i){
|
|
376
|
+
set(g, "transform", "translate(" + points[i].x.toFixed(3) + " " + points[i].y.toFixed(3) + ")");
|
|
377
|
+
var state = e < 0.5 ? from : to, solid = state === "solid", mark = null;
|
|
378
|
+
// 密に接した内部の粒子では、短縮せず空きのある粒子だけに矢印を描く。
|
|
379
|
+
if (self.props.motion && !solid) mark = self.motionArrow(points, i, state === "gas" ? 24 : 18, box);
|
|
380
|
+
self.motionPaths.push(mark);
|
|
381
|
+
set(self.marks[i], "transform", mark ? "rotate(" + mark.angle.toFixed(3) + ")" : "");
|
|
382
|
+
set(self.marks[i], "d", !self.props.motion ? "" : solid ? "M14,-19q4,2 5,5M-14,19q-4,-2 -5,-5" : mark ? mark.path : "");
|
|
383
|
+
});
|
|
384
|
+
text(this.stateName, this.transitionLabel(k));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
var final = k === 3 ? e : 0, visible = k === 0 ? 0 : k === 1 ? e : 1;
|
|
388
|
+
set(this.summary, "opacity", p.balanced ? final : visible);
|
|
389
|
+
set(this.live, "opacity", visible); set(this.arrow, "opacity", k >= 3 || !p.balanced ? 1 : 0);
|
|
390
|
+
set(this.reference, "opacity", p.balanced ? final : 0);
|
|
391
|
+
set(this.productReference, "opacity", p.balanced ? 0 : visible);
|
|
392
|
+
set(this.afterName, "opacity", p.balanced ? final : visible);
|
|
393
|
+
set(this.beforeName, "opacity", k === 3 || !p.balanced ? 1 : 0);
|
|
394
|
+
text(this.stageName, k === 3 || !p.balanced ? "" : k === 2 ? this.words.apart : this.words.before);
|
|
395
|
+
this.atoms.forEach(function(g, i){
|
|
396
|
+
var a = self.source[i], b = self.destinations[i], free = self.separated[i];
|
|
397
|
+
var from = k === 3 ? free : a, to = k >= 2 ? (k === 3 ? b : free) : a, q = k >= 2 ? e : 0;
|
|
398
|
+
if (!p.balanced){ from = to = a; q = 0; }
|
|
399
|
+
set(g, "transform", "translate(" + base.lerp(from.x, to.x, q).toFixed(3) + " " + base.lerp(from.y, to.y, q).toFixed(3) + ")");
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
return Part;
|
|
404
|
+
});
|