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,197 @@
|
|
|
1
|
+
// 本文に画像を足す(編集アプリのスライド ▾ の「画像を挿入…」。app/image-insert.js。handoff #85)。Node にもブラウザにも依存しない(純粋な ESM)
|
|
2
|
+
// 原稿(deck.html)の文字列を受け取り、新しい文字列を返す。読み書きはしない。
|
|
3
|
+
// 自由な配置はしない:置き方は本文の中(全幅・半分・3 分の 1)と 2 列の左・右だけ。縦横比を保って幅に合わせる(はみ出しは今の品質チェック)。
|
|
4
|
+
// 体裁は今あるものだけ(kit/layouts.css の .fig・.cols。幅は要素の style)。画像は <img src="data:…">(SVG も data:image/svg+xml なので中のスクリプトは動かない)
|
|
5
|
+
//
|
|
6
|
+
// IMAGE_TYPES 受け取る画像の種類(PNG・JPEG・WebP・SVG)
|
|
7
|
+
// PLACEMENTS 置き方:'full' | 'half' | 'third' | 'left' | 'right'
|
|
8
|
+
// imageType(bytes) 中身(先頭のバイト)から種類を決める → IMAGE_TYPES のどれか | null(名前や申告の type は信じない)
|
|
9
|
+
// dataUrl(bytes, mime) → 'data:<mime>;base64,…'
|
|
10
|
+
// sizeNotice(n) 1 つの画像の目安(kit/core/image-size.mjs の MAX_IMAGE_BYTES、1 MiB)を超えれば MB の字(小数 1 桁)、超えなければ null
|
|
11
|
+
// slideSteps(src, index) そのスライドのステップの数(結論の行を除く){max, isStatic, auto, concl}。concl:結論の行があるか。auto:本文の直下の箇条が 1 つずつ出る形(kit/deck.js の autoList)
|
|
12
|
+
// imageHtml({src, alt, placement, step}) 入れる塊:<div class="fig"[ data-step]><img src alt style></div>
|
|
13
|
+
// insertImage(src, index, opts) index 番目のスライドに入れた原稿。本文(.body)の終わり(結論の行 .concl は .body の外なので、その前)、
|
|
14
|
+
// 2 列なら .body の直下の .cols の左・右の列の終わり。.cols がなければ本文を右(左)の列に入れて 2 列にする。
|
|
15
|
+
// ステップを付けるときと 2 列にするときは、本文の直下の箇条の自動のステップを data-step に書き出す(見え方を変えない)
|
|
16
|
+
import { parse } from 'parse5';
|
|
17
|
+
import { MAX_IMAGE_BYTES } from './image-size.mjs';
|
|
18
|
+
|
|
19
|
+
export const IMAGE_TYPES = Object.freeze(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml']);
|
|
20
|
+
export const PLACEMENTS = Object.freeze(['full', 'half', 'third', 'left', 'right']);
|
|
21
|
+
const WIDTH = { full: '100%', half: '50%', third: '33.333%', left: '100%', right: '100%' };
|
|
22
|
+
const MiB = 1048576;
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------- 種類・data: URL・大きさの知らせ
|
|
25
|
+
export function imageType(bytes) {
|
|
26
|
+
const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes || []);
|
|
27
|
+
const at = (i, ...xs) => xs.every((x, j) => b[i + j] === x);
|
|
28
|
+
if (at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return 'image/png';
|
|
29
|
+
if (at(0, 0xff, 0xd8, 0xff)) return 'image/jpeg';
|
|
30
|
+
if (at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50)) return 'image/webp';
|
|
31
|
+
// SVG:先頭(BOM・空白・<?xml …?>・注釈・<!DOCTYPE …> を除く)が <svg
|
|
32
|
+
let t;
|
|
33
|
+
try { t = new TextDecoder('utf-8', { fatal: false }).decode(b.subarray(0, 4096)); } catch { return null; }
|
|
34
|
+
t = t.replace(/^/, '');
|
|
35
|
+
for (let k = 0; k < 20; k++) {
|
|
36
|
+
const s = t.replace(/^\s+/, '');
|
|
37
|
+
const m = /^(<\?xml[\s\S]*?\?>|<!--[\s\S]*?-->|<!DOCTYPE[^>]*>)/i.exec(s);
|
|
38
|
+
if (!m) { t = s; break; }
|
|
39
|
+
t = s.slice(m[0].length);
|
|
40
|
+
}
|
|
41
|
+
return /^<svg[\s>]/i.test(t) ? 'image/svg+xml' : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function dataUrl(bytes, mime) {
|
|
45
|
+
if (!IMAGE_TYPES.includes(mime)) throw new Error('unsupported image type: ' + mime);
|
|
46
|
+
const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
47
|
+
let bin = '';
|
|
48
|
+
for (let i = 0; i < b.length; i += 0x8000) bin += String.fromCharCode.apply(null, b.subarray(i, i + 0x8000));
|
|
49
|
+
return `data:${mime};base64,${btoa(bin)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function sizeNotice(n) {
|
|
53
|
+
return n > MAX_IMAGE_BYTES ? (Math.round((n / MiB) * 10) / 10).toFixed(1) : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------- スライドの木
|
|
57
|
+
function walk(node, fn) {
|
|
58
|
+
if (fn(node) === false) return;
|
|
59
|
+
for (const c of node.childNodes || []) walk(c, fn);
|
|
60
|
+
if (node.content) walk(node.content, fn);
|
|
61
|
+
}
|
|
62
|
+
const attrOf = (n, a) => (n.attrs || []).find((x) => x.name === a);
|
|
63
|
+
const classes = (n) => (attrOf(n, 'class')?.value || '').split(/\s+/).filter(Boolean);
|
|
64
|
+
const hasClass = (n, c) => classes(n).includes(c);
|
|
65
|
+
const isSlide = (n) => n.tagName === 'section' && hasClass(n, 'slide');
|
|
66
|
+
const kids = (n) => (n.childNodes || []).filter((c) => c.tagName);
|
|
67
|
+
function slideNode(src, index) {
|
|
68
|
+
const doc = parse(src, { sourceCodeLocationInfo: true });
|
|
69
|
+
let node = null, k = 0;
|
|
70
|
+
walk(doc, (x) => { if (x.tagName && isSlide(x)) { if (k === index) node = x; k++; return false; } return true; });
|
|
71
|
+
if (!node) throw Object.assign(new Error(`no slide ${index + 1}`), { code: 'no-slide' });
|
|
72
|
+
if (!node.sourceCodeLocation || !node.sourceCodeLocation.endTag) throw Object.assign(new Error(`slide ${index + 1} has no end tag (</section>)`), { code: 'deck-problem' });
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
function descendants(node, pred) {
|
|
76
|
+
const out = [];
|
|
77
|
+
walk(node, (x) => { if (x !== node && x.tagName && pred(x)) out.push(x); return true; });
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
// 本文の直下の箇条(kit/deck.js の autoList と同じ:.body > ul > li, .body > ol > li を文書の順に)
|
|
81
|
+
function autoItems(slide) {
|
|
82
|
+
const out = [];
|
|
83
|
+
walk(slide, (x) => {
|
|
84
|
+
if (x.tagName === 'li' && x.parentNode && /^(ul|ol)$/.test(x.parentNode.tagName || '') && x.parentNode.parentNode && hasClass(x.parentNode.parentNode, 'body')) out.push(x);
|
|
85
|
+
return true;
|
|
86
|
+
});
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
function autoListOn(slide) {
|
|
90
|
+
return !hasClass(slide, 'static') && !hasClass(slide, 'nostep') && !descendants(slide, (x) => attrOf(x, 'data-step') || attrOf(x, 'data-from')).length;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function slideSteps(src, index) {
|
|
94
|
+
const s = slideNode(src, index);
|
|
95
|
+
const concl = descendants(s, (x) => hasClass(x, 'concl')).length > 0;
|
|
96
|
+
if (hasClass(s, 'static')) return { max: 0, isStatic: true, auto: false, concl };
|
|
97
|
+
if (autoListOn(s)) return { max: autoItems(s).length, isStatic: false, auto: autoItems(s).length > 0, concl };
|
|
98
|
+
let max = 0;
|
|
99
|
+
for (const e of descendants(s, (x) => attrOf(x, 'data-step') || attrOf(x, 'data-from'))) {
|
|
100
|
+
const v = Number((attrOf(e, 'data-step') || attrOf(e, 'data-from')).value);
|
|
101
|
+
if (Number.isInteger(v) && v > max) max = v;
|
|
102
|
+
}
|
|
103
|
+
const ds = Number(attrOf(s, 'data-steps')?.value);
|
|
104
|
+
if (Number.isInteger(ds) && ds > max) max = ds;
|
|
105
|
+
return { max, isStatic: false, auto: false, concl };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ---------------------------------------------------------------- 入れる塊
|
|
109
|
+
const escAttr = (v) => String(v).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
110
|
+
export function imageHtml({ src, alt, placement, step }) {
|
|
111
|
+
if (!PLACEMENTS.includes(placement)) throw new Error('unknown placement: ' + placement);
|
|
112
|
+
if (!/^data:image\/(png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]*={0,2}$/.test(String(src))) throw new Error('the image must be a base64 data: URL of PNG, JPEG, WebP or SVG');
|
|
113
|
+
const st = step == null || step === 0 ? '' : ` data-step="${Number(step)}"`;
|
|
114
|
+
if (st && !(Number.isInteger(Number(step)) && Number(step) > 0)) throw new Error('bad step: ' + step);
|
|
115
|
+
const center = placement === 'half' || placement === 'third' ? ';margin:0 auto' : '';
|
|
116
|
+
return `<div class="fig"${st}><img src="${src}" alt="${escAttr(alt == null ? '' : String(alt).replace(/\s+/g, ' ').trim())}" style="display:block;width:${WIDTH[placement]};height:auto${center}"></div>`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------- 入れる
|
|
120
|
+
const eolOf = (t) => (t.includes('\r\n') ? '\r\n' : '\n');
|
|
121
|
+
// off の前が行の頭からの空白だけなら、その行の頭。そうでなければ -1
|
|
122
|
+
function lineHead(src, off) {
|
|
123
|
+
const h = src.lastIndexOf('\n', off - 1) + 1;
|
|
124
|
+
return /^[ \t]*$/.test(src.slice(h, off)) ? h : -1;
|
|
125
|
+
}
|
|
126
|
+
const indentAt = (src, off) => { const h = src.lastIndexOf('\n', off - 1) + 1; return /^[ \t]*/.exec(src.slice(h))[0]; };
|
|
127
|
+
// 要素の終わりのタグの前に、子として html を入れる(終わりのタグが自分の行にあれば、その前の行として字下げを揃える)
|
|
128
|
+
function appendChild(src, node, html) {
|
|
129
|
+
const L = node.sourceCodeLocation, e = L.endTag.startOffset, eol = eolOf(src);
|
|
130
|
+
const pad = indentAt(src, L.startOffset) + ' ';
|
|
131
|
+
const h = lineHead(src, e);
|
|
132
|
+
if (h >= 0) return src.slice(0, h) + pad + html + eol + src.slice(h);
|
|
133
|
+
return src.slice(0, e) + html + src.slice(e);
|
|
134
|
+
}
|
|
135
|
+
// 本文の直下の箇条の自動のステップを data-step に書き出す(autoList のときだけ。見え方は変わらない)
|
|
136
|
+
function materialize(src, index) {
|
|
137
|
+
const s = slideNode(src, index);
|
|
138
|
+
if (!autoListOn(s)) return src;
|
|
139
|
+
const edits = autoItems(s).map((li, k) => {
|
|
140
|
+
const t = li.sourceCodeLocation.startTag;
|
|
141
|
+
let at = t.endOffset - 1; if (src[at - 1] === '/') at--;
|
|
142
|
+
return [at, ` data-step="${k + 1}"`];
|
|
143
|
+
});
|
|
144
|
+
edits.sort((a, b) => b[0] - a[0]);
|
|
145
|
+
for (const [at, t] of edits) src = src.slice(0, at) + t + src.slice(at);
|
|
146
|
+
return src;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function insertImage(src, index, opts) {
|
|
150
|
+
const html = imageHtml(opts);
|
|
151
|
+
const cols = opts.placement === 'left' || opts.placement === 'right';
|
|
152
|
+
const stepped = !(opts.step == null || opts.step === 0);
|
|
153
|
+
if (stepped && hasClass(slideNode(src, index), 'static')) throw Object.assign(new Error('a static slide has no steps'), { code: 'static' });
|
|
154
|
+
if (stepped || cols) src = materialize(src, index);
|
|
155
|
+
const s = slideNode(src, index), eol = eolOf(src);
|
|
156
|
+
let body = kids(s).find((x) => hasClass(x, 'body'));
|
|
157
|
+
if (!body) {
|
|
158
|
+
// 本文がない:結論の行の前(なければ </section> の前)に本文を作る
|
|
159
|
+
const pad = indentAt(src, s.sourceCodeLocation.startOffset) + ' ';
|
|
160
|
+
const concl = kids(s).find((x) => hasClass(x, 'concl'));
|
|
161
|
+
const inner = cols ? colsHtml(opts.placement, html, '', pad + ' ', eol) : `${pad} ${html}`;
|
|
162
|
+
const block = `${pad}<div class="body">${eol}${inner}${eol}${pad}</div>`;
|
|
163
|
+
if (concl) { const at = concl.sourceCodeLocation.startOffset, h = lineHead(src, at); return h >= 0 ? src.slice(0, h) + block + eol + src.slice(h) : src.slice(0, at) + block.trimStart() + src.slice(at); }
|
|
164
|
+
return appendChild(src, s, block.trimStart());
|
|
165
|
+
}
|
|
166
|
+
if (!cols) return appendChild(src, body, html);
|
|
167
|
+
const wrap = kids(body).find((x) => hasClass(x, 'cols'));
|
|
168
|
+
if (wrap) {
|
|
169
|
+
const c = kids(wrap), k = opts.placement === 'left' ? 0 : 1, target = c[k];
|
|
170
|
+
if (target && target.tagName === 'div' && target.sourceCodeLocation && target.sourceCodeLocation.endTag) return appendChild(src, target, html);
|
|
171
|
+
// その列がない・パーツなどの要素:新しい列(<div>)として左なら先頭、右なら左の列の後ろに入れる
|
|
172
|
+
const col = `<div>${html}</div>`;
|
|
173
|
+
if (k === 0 || !c[0]) {
|
|
174
|
+
const at = c[0] ? c[0].sourceCodeLocation.startOffset : wrap.sourceCodeLocation.startTag.endOffset;
|
|
175
|
+
if (!c[0]) return appendChild(src, wrap, col);
|
|
176
|
+
const h = lineHead(src, at), pad = indentAt(src, at);
|
|
177
|
+
return h >= 0 ? src.slice(0, h) + pad + col + eol + src.slice(h) : src.slice(0, at) + col + src.slice(at);
|
|
178
|
+
}
|
|
179
|
+
const after = c[0].sourceCodeLocation.endOffset;
|
|
180
|
+
return src.slice(0, after) + eol + indentAt(src, c[0].sourceCodeLocation.startOffset) + col + src.slice(after);
|
|
181
|
+
}
|
|
182
|
+
// 2 列にする:今の本文をもう一方の列へ
|
|
183
|
+
const B = body.sourceCodeLocation, a = B.startTag.endOffset, b = B.endTag.startOffset;
|
|
184
|
+
const pad = indentAt(src, B.startOffset) + ' ';
|
|
185
|
+
let inner = src.slice(a, b).replace(/^[ \t]*\r?\n/, '').replace(/\s+$/, '');
|
|
186
|
+
// 列の中へ動かす本文は 4 字下げる(空白に意味のある pre・textarea を含むときは字を変えない)
|
|
187
|
+
if (!/<(pre|textarea)\b/i.test(inner)) inner = inner.split(/(\r?\n)/).map((x, k) => (k % 2 === 0 && x.trim() ? ' ' + x : x)).join('');
|
|
188
|
+
const close = lineHead(src, b) >= 0 ? eol + indentAt(src, b) : eol + indentAt(src, B.startOffset);
|
|
189
|
+
return src.slice(0, a) + eol + colsHtml(opts.placement, html, inner, pad, eol) + close + src.slice(b);
|
|
190
|
+
}
|
|
191
|
+
function colsHtml(placement, html, inner, pad, eol) {
|
|
192
|
+
const img = `${pad} ${html}`;
|
|
193
|
+
const other = inner ? inner : '';
|
|
194
|
+
const colOf = (x) => (x ? `${pad} <div>${eol}${x}${eol}${pad} </div>` : `${pad} <div></div>`);
|
|
195
|
+
const L = placement === 'left' ? img : other, R = placement === 'left' ? other : img;
|
|
196
|
+
return `${pad}<div class="cols">${eol}${colOf(L)}${eol}${colOf(R)}${eol}${pad}</div>`;
|
|
197
|
+
}
|
package/kit/core/image-size.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 埋め込んだ画像の大きさ(data: URI を戻したバイト数)。組み立てた HTML をコマンド版と編集アプリで同じように調べる
|
|
2
2
|
import { parse } from 'parse5';
|
|
3
3
|
|
|
4
|
-
const MAX_IMAGE_BYTES = 1048576;
|
|
4
|
+
export const MAX_IMAGE_BYTES = 1048576; // 1 つの画像の目安(1 MiB)。編集アプリの「画像を挿入」の知らせも同じ値(kit/core/image-insert.mjs)
|
|
5
5
|
const attr = (n, name) => (n.attrs || []).find((a) => a.name === name)?.value || '';
|
|
6
6
|
function dataBytes(src) {
|
|
7
7
|
const m = /^data:([^,]*),([\s\S]*)$/i.exec(src.trim());
|
package/kit/core/layout-scan.mjs
CHANGED
|
@@ -200,7 +200,7 @@ export function layoutScan(s, o) {
|
|
|
200
200
|
if (!n.textContent.trim()) continue;
|
|
201
201
|
const e = n.parentElement;
|
|
202
202
|
// ルビ(rt)の振り仮名は本文の半分の大きさが決まり(docs/reference.md「Japanese language arts」)
|
|
203
|
-
if (e.closest('svg') || e.closest('.katex') || e.closest('[' + ANNOT + ']') || e.closest('.cite') || e.closest('.pn') || e.closest('.figcap') || e.closest('rt')) continue;
|
|
203
|
+
if (e.closest('svg') || e.closest('.katex') || e.closest('[' + ANNOT + ']') || e.closest('.cite') || e.closest('.source') || e.closest('.pn') || e.closest('.figcap') || e.closest('rt')) continue;
|
|
204
204
|
if (hiddenEl(e)) continue; // 読み上げ用の隠し方の中の字(.sr-only の形の 1×1 の箱・clip-path: inset(50%) など)は見えない
|
|
205
205
|
const f = parseFloat(getComputedStyle(e).fontSize);
|
|
206
206
|
const lim2 = e.closest('table,.plot') ? 23.9 : 26.6;
|
package/kit/core/llm-fix.mjs
CHANGED
|
@@ -47,7 +47,7 @@ const BY_CODE = {
|
|
|
47
47
|
titleLong: ['R-title'], titleLongEn: ['R-title'], conclLong: ['R-concl'], conclLongEn: ['R-concl'], conclOverflow: ['R-concl', 'R-fit'],
|
|
48
48
|
overflowBottom: ['R-fit'], overflowRight: ['R-fit'], smallText: ['R-fit'], katexError: ['R-math'],
|
|
49
49
|
noNarration: ['R-narr-steps'], orphanNarration: ['R-narr-steps'], readingExpr: ['R-reading', 'R-formula'], readingSeveral: ['R-reading'], readingGap: ['R-reading'],
|
|
50
|
-
compData: ['R-components'], consoleError: ['R-components'],
|
|
50
|
+
compData: ['R-components'], scriptUnclosed: ['R-components'], consoleError: ['R-components'],
|
|
51
51
|
contrast: ['R-colors'], formula: ['R-formula'], missingSection: ['R-headings'], narrHeadingDiffers: ['R-headings'], markTarget: ['R-marks'],
|
|
52
52
|
// 体裁の検査(kit/core/layout-scan.mjs)がブラウザ版にも出すコマンド版の code
|
|
53
53
|
titleColon: ['R-title'], tateTitle: ['R-title'], tateBodyHead: ['R-fit'], bodyConclCol: ['R-fit'], bodyLeft: ['R-fit'], smallSvgText: ['R-fit'],
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
// plan:お使いの AI のプラン。'free'(既定)では、標準の部品のうち中核の 4 つ(FREE_CORE)だけを詳しく書き、ほかの標準の部品は一覧の 1 行だけにする
|
|
12
12
|
// (標準すべてが無料のプランの上限に収まるように。backlog #125)。'paid' はどの部品も詳しく書く。専門の部品はどちらのプランでも詳しく書く
|
|
13
13
|
// short:無料のプランで、中核の 4 つも一覧の 1 行だけにする(束を足して上限を越えたとき、新規作成が外す候補より先に使う。kit/core/new-deck.mjs の fitPlan)
|
|
14
|
-
// full:無料のプランで詳しく書く標準の部品(既定は中核の 4 つ。short なら [])。渡せば short
|
|
15
|
-
//
|
|
14
|
+
// full:無料のプランで詳しく書く標準の部品(既定は中核の 4 つ。short なら [])。渡せば short より先に読む
|
|
15
|
+
// named:順位で組む指示(新規作成 ④。handoff #43)。配列なら、exclude にない部品はどれも詳しく書き(プランで paidOnly を除かず、一覧の 1 行だけにしない)、
|
|
16
|
+
// named の部品は言いたいことの表に名前だけ載せる(説明・一覧の行はない。表の下の 1 文が「使わない」と言う)。rankedPack が順位から決める
|
|
16
17
|
import { purposesTable } from './purposes.mjs';
|
|
17
18
|
|
|
18
19
|
// 指示の大きさの上限(KB = 1024 バイト。生成した指示で、頼みたいことは記入欄のまま。写す文に入る内容・場面の節は数えない)。
|
|
@@ -69,6 +70,8 @@ export function normalizeSets(sets, data) {
|
|
|
69
70
|
export const langOf = (data, lang) => data[lang === 'ja' ? 'ja' : 'en'];
|
|
70
71
|
const tidy = (s) => s.replace(/\n{3,}/g, '\n\n').trim();
|
|
71
72
|
// 部品に結び付いた文:exclude の部品があれば除き、なければ印だけを外す
|
|
73
|
+
// 有料のプランだけの文(<!--paid-->…<!--/paid-->):無料のプランでは除き、有料のプランでは印だけを外す(無料のプランの貼り付けの長さに入らない行。handoff #85)
|
|
74
|
+
export const planSpans = (text, plan) => text.replace(/<!--paid-->([\s\S]*?)<!--\/paid-->/g, (_, inner) => (planName(plan) === 'paid' ? inner : ''));
|
|
72
75
|
export const partSpans = (text, exclude = []) => text.replace(/<!--part:([a-z0-9,-]+)-->([\s\S]*?)<!--\/part-->/g, (_, tags, inner) => (tags.split(',').some((t) => exclude.includes(t)) ? '' : inner));
|
|
73
76
|
|
|
74
77
|
// gone:組み立てに入らない部品(説明の中でその名前を出す所を除く。<!--part:…--> は make-llm-guide の markRefs が付ける)。
|
|
@@ -97,14 +100,15 @@ export const membersOf = (D, set) => Object.keys(D.components).sort().filter((n)
|
|
|
97
100
|
// 共通の本体(標準の部品の一覧と説明・言いたいことの表)。sets:入っている束(表が指す部品を決める。既定 [] は標準だけ。null ならすべて)。off:外した札
|
|
98
101
|
// 有料のプランの指示にだけ入る部品(材料の paidOnly:受け皿のない束のパーツ。tools/make-llm-guide.mjs の hasReceiver)
|
|
99
102
|
export const paidOnlyParts = (data) => Object.keys(data.en.components).sort().filter((t) => data.en.components[t].paidOnly);
|
|
100
|
-
export function commonOf(data, lang, { exclude: exclude0 = [], sets = [], off = [], plan = 'free', short = false, full = null } = {}) {
|
|
103
|
+
export function commonOf(data, lang, { exclude: exclude0 = [], sets = [], off = [], plan = 'free', short = false, full = null, named = null } = {}) {
|
|
101
104
|
const D = langOf(data, lang);
|
|
102
|
-
const
|
|
105
|
+
const ranked = Array.isArray(named);
|
|
106
|
+
const exclude = planName(plan) === 'free' && !ranked ? [...new Set([...exclude0, ...paidOnlyParts(data)])] : exclude0;
|
|
103
107
|
const ss = sets === null ? [...data.sets] : normalizeSets(sets, data);
|
|
104
108
|
const gone = goneParts(data, lang, exclude, ss);
|
|
105
|
-
const table = () => (data.purposes ? purposesTable(data.purposes, data.parts || [], lang, data.partsSrc || '', { exclude, sets: ss, off }) : '');
|
|
106
|
-
return tidy(partSpans(D.common, exclude).replace('{{PURPOSES}}', table)
|
|
107
|
-
.replace('{{CATALOG}}', () => catalog(D, membersOf(D, STANDARD).filter((n) => !exclude.includes(n)), gone, briefParts(data, plan, short, full), planName(plan) === 'free')));
|
|
109
|
+
const table = () => (data.purposes ? purposesTable(data.purposes, data.parts || [], lang, data.partsSrc || '', { exclude, sets: ss, off, ...(ranked ? { named } : {}) }) : '');
|
|
110
|
+
return tidy(partSpans(planSpans(D.common, plan), exclude).replace('{{PURPOSES}}', table)
|
|
111
|
+
.replace('{{CATALOG}}', () => catalog(D, membersOf(D, STANDARD).filter((n) => !exclude.includes(n)), gone, ranked ? [] : briefParts(data, plan, short, full), planName(plan) === 'free')));
|
|
108
112
|
}
|
|
109
113
|
// 1 つの束の指示。sets:一緒に入る束(説明の中の名前を残す部品を決める。既定はこの束だけ)
|
|
110
114
|
export function partOf(data, name, lang, { exclude = [], sets = [name] } = {}) {
|
|
@@ -118,12 +122,12 @@ export function partOf(data, name, lang, { exclude = [], sets = [name] } = {}) {
|
|
|
118
122
|
export const requestOf = (data, lang) => tidy(langOf(data, lang).request || '');
|
|
119
123
|
|
|
120
124
|
// sets:選んだ束('a,b'・配列・'all')。plan:'free'(既定)| 'paid'(詳しさだけが変わる)
|
|
121
|
-
export function packParts(data, { sets = [], lang = 'en', exclude = [], off = [], plan = 'free', short = false, full = null } = {}) {
|
|
125
|
+
export function packParts(data, { sets = [], lang = 'en', exclude = [], off = [], plan = 'free', short = false, full = null, named = null } = {}) {
|
|
122
126
|
const ss = normalizeSets(sets, data);
|
|
123
|
-
return [commonOf(data, lang, { exclude, sets: ss, off, plan, short, full }), ...ss.map((s) => partOf(data, s, lang, { exclude, sets: ss }))];
|
|
127
|
+
return [commonOf(data, lang, { exclude, sets: ss, off, plan, short, full, named }), ...ss.map((s) => partOf(data, s, lang, { exclude, sets: ss }))];
|
|
124
128
|
}
|
|
125
|
-
export function assemble(data, { sets = [], lang = 'en', exclude = [], off = [], plan = 'free', short = false, full = null } = {}) {
|
|
126
|
-
const parts = [...packParts(data, { sets, lang, exclude, off, plan, short, full }), requestOf(data, lang)].filter(Boolean);
|
|
129
|
+
export function assemble(data, { sets = [], lang = 'en', exclude = [], off = [], plan = 'free', short = false, full = null, named = null } = {}) {
|
|
130
|
+
const parts = [...packParts(data, { sets, lang, exclude, off, plan, short, full, named }), requestOf(data, lang)].filter(Boolean);
|
|
127
131
|
return parts.join('\n\n') + '\n';
|
|
128
132
|
}
|
|
129
133
|
|
|
@@ -141,6 +145,31 @@ export function packOptsOf(data, tags, plan = 'free', { short = false, full = nu
|
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
// ---------------------------------------------------------------- 順位で組む指示(新規作成 ④。handoff #43、作者の決定 2026-11-19)
|
|
149
|
+
// order:パーツの順位(kit/core/new-deck.mjs の rankParts)。上から k 個を詳しく書き、残りは言いたいことの表に名前だけ。軽量(free)も詳細(paid)も同じ仕組みで、
|
|
150
|
+
// 違うのは上限だけ(capBytes。fitSize で測る:軽量は 45 KB と貼り付けの長さ 31,000 の小さいほう、詳細は 150 KB)。k は上限に収まるいちばん大きい数
|
|
151
|
+
// (説明を足すほど指示は長くなるので、二分探索)。材料にない部品(特殊・ローカル)は順位から除く。
|
|
152
|
+
// rankedOpts(data, described, named, plan) → {sets, exclude, plan, named}(assemble・packWithRequest に渡す)
|
|
153
|
+
// rankedPack(data, order, plan, {textOf, capBytes}) → {described, named, text, size, over}。textOf(opts) は組んだ指示(頼みたいことも入れる)
|
|
154
|
+
export function rankedOpts(data, described, named, plan = 'free') {
|
|
155
|
+
const { sets, exclude } = packOptsOf(data, described, plan);
|
|
156
|
+
return { sets, exclude, plan: planName(plan), named: named.filter((t) => data.en.components[t]) };
|
|
157
|
+
}
|
|
158
|
+
export function rankedPack(data, order, plan, { textOf, capBytes }) {
|
|
159
|
+
const tags = [...new Set(order)].filter((t) => data.en.components[t]);
|
|
160
|
+
const build = (k) => { const text = textOf(rankedOpts(data, tags.slice(0, k), tags.slice(k), plan)); return { k, text, size: fitSize(text, plan) }; };
|
|
161
|
+
let best = build(0);
|
|
162
|
+
if (best.size <= capBytes) {
|
|
163
|
+
let lo = 0, hi = tags.length;
|
|
164
|
+
const all = build(hi);
|
|
165
|
+
if (all.size <= capBytes) best = all;
|
|
166
|
+
else {
|
|
167
|
+
while (hi - lo > 1) { const mid = (lo + hi) >> 1; const r = build(mid); if (r.size <= capBytes) { lo = mid; best = r; } else hi = mid; }
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { described: tags.slice(0, best.k), named: tags.slice(best.k), text: best.text, size: best.size, over: best.size > capBytes };
|
|
171
|
+
}
|
|
172
|
+
|
|
144
173
|
// ---------------------------------------------------------------- 無料のプランの目安に収める(backlog #125)。編集アプリ・コマンド・npm run gen が同じ関数を使う
|
|
145
174
|
// 外す候補:sizeOf(tags) は選んだパーツで組んだ指示のバイト数。keep は候補にしない(fitPlan では標準のパーツ)。
|
|
146
175
|
// 1 つずつ外したときに減る大きさの大きい順に、越えた分に届くまで(届かなければ候補の全部)
|
|
@@ -194,59 +223,3 @@ export function fitPack(data, ticked, plan, { sizeOf, capBytes, keep = [] }) {
|
|
|
194
223
|
const bytes = sizeOf(tags, short);
|
|
195
224
|
return { tags, short, dropped: first.candidates, bytes, over: bytes > capBytes };
|
|
196
225
|
}
|
|
197
|
-
|
|
198
|
-
// 「このサンプルを参考に作る」の目安に収める(backlog #130。編集アプリの新規作成とコマンドの --from-sample が同じ関数を使う)。
|
|
199
|
-
// サンプルのパーツ(own)は無料のプランでも詳しく書く(中核の 4 つでも、ほかの標準のパーツでも)。越えたら、この順に 1 段ずつ:
|
|
200
|
-
// 1. サンプルが使わない中核の 4 つを短くする(減る大きさの大きい順に 1 つずつ、収まるまで)
|
|
201
|
-
// 2. サンプルが使わない専門のパーツを外す(trimCandidates。減る大きさの大きい順)。無料のプランでそれでも越えるなら、
|
|
202
|
-
// サンプルが使わない標準のパーツを SINGLE_SET_DROP_ORDER の順に外す(中核の 4 つとサンプルのパーツは外さない)
|
|
203
|
-
// 3. それでも越えるときだけ、サンプルの標準のパーツを短くする(減る大きさの大きい順に 1 つずつ)
|
|
204
|
-
// 2 で外したら、残ったパーツでもう一度 1 から決める(編集アプリで[候補を外す]を押した後と同じ指示になる。外して収まれば 1 で短くした分も戻る)。
|
|
205
|
-
// 有料のプランは短くしない(2 だけ)。sizeOf(tags, full) は選んだパーツと詳しく書く標準の部品で組んだ指示のバイト数。
|
|
206
|
-
// → {tags, full, step1Full・step1Shortened:初めの 1 の後の full と短くしたもの(外す候補を見せている間の編集アプリの指示と知らせ), shortened:1 で短くしたもの, dropped:2 で外したもの,
|
|
207
|
-
// ownShortened:3 で短くしたもの, short:何かを短くしたか, bytes, over}
|
|
208
|
-
export function fitSample(data, ticked, plan, { sizeOf, capBytes, own = [] }) {
|
|
209
|
-
const free = planName(plan) === 'free';
|
|
210
|
-
const isStd = (t) => !!data.en.components[t] && data.en.components[t].set === STANDARD;
|
|
211
|
-
const once = (tags) => {
|
|
212
|
-
const mine = tags.filter((t) => own.includes(t));
|
|
213
|
-
let full = free ? [...new Set([...FREE_CORE, ...mine.filter(isStd)])].sort() : null;
|
|
214
|
-
const size = () => sizeOf(tags, full);
|
|
215
|
-
// full から 1 つずつ外して短くする(減る大きさの大きい順。同じなら名前の順)。選んでいないパーツは指示に入らないので数えない
|
|
216
|
-
const shorten = (pool) => {
|
|
217
|
-
const out = [];
|
|
218
|
-
let left = pool.filter((t) => tags.includes(t) && full.includes(t));
|
|
219
|
-
while (left.length && size() > capBytes) {
|
|
220
|
-
const now = size();
|
|
221
|
-
const [t] = left.map((x) => [x, now - sizeOf(tags, full.filter((y) => y !== x))]).sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))[0];
|
|
222
|
-
full = full.filter((y) => y !== t); out.push(t); left = left.filter((y) => y !== t);
|
|
223
|
-
}
|
|
224
|
-
return out;
|
|
225
|
-
};
|
|
226
|
-
const shortened = free ? shorten(FREE_CORE.filter((t) => !mine.includes(t))) : [];
|
|
227
|
-
const step1Full = full;
|
|
228
|
-
const keep = new Set(tags.filter((t) => !data.en.components[t] || isStd(t) || mine.includes(t)));
|
|
229
|
-
const dropped = size() > capBytes ? trimCandidates(tags, { sizeOf: (x) => sizeOf(x, full), capBytes, keep }) : [];
|
|
230
|
-
// 2 の続き(無料のプラン):専門のパーツを外してもまだ越えるなら、サンプルが使わない標準のパーツを SINGLE_SET_DROP_ORDER の順に外す
|
|
231
|
-
// (中核の 4 つとサンプルのパーツは外さない。2026-11-07 決定:英語の kokugo-kanbun が貼り付けの長さで越えたまま、外す候補がなかった)
|
|
232
|
-
if (free) {
|
|
233
|
-
const rest = () => tags.filter((t) => !dropped.includes(t));
|
|
234
|
-
if (sizeOf(rest(), full) > capBytes) {
|
|
235
|
-
for (const t of SINGLE_SET_DROP_ORDER) {
|
|
236
|
-
if (FREE_CORE.includes(t) || !tags.includes(t) || mine.includes(t) || dropped.includes(t)) continue;
|
|
237
|
-
dropped.push(t);
|
|
238
|
-
if (sizeOf(rest(), full) <= capBytes) break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (dropped.length) return { tags, full, step1Full, shortened, dropped, ownShortened: [] };
|
|
243
|
-
const ownShortened = free ? shorten(mine.filter(isStd)) : [];
|
|
244
|
-
return { tags, full, step1Full, shortened, dropped, ownShortened };
|
|
245
|
-
};
|
|
246
|
-
const first = once([...ticked]);
|
|
247
|
-
let r = first, dropped = [];
|
|
248
|
-
while (r.dropped.length) { dropped = [...dropped, ...r.dropped]; r = once(r.tags.filter((t) => !r.dropped.includes(t))); }
|
|
249
|
-
const bytes = sizeOf(r.tags, r.full);
|
|
250
|
-
return { tags: r.tags, full: r.full, step1Full: first.step1Full, step1Shortened: first.shortened, shortened: r.shortened, dropped, ownShortened: r.ownShortened,
|
|
251
|
-
short: r.shortened.length + r.ownShortened.length > 0, bytes, over: bytes > capBytes };
|
|
252
|
-
}
|