egatari 0.6.16 → 0.6.18
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 +43 -1
- package/README.ja.md +14 -13
- package/README.md +2 -1
- package/components.lock.json +119 -45
- package/components2.lock.json +639 -1
- package/kit/check-messages.mjs +5 -0
- package/kit/check.mjs +6 -0
- package/kit/core/bookmark.mjs +28 -0
- package/kit/core/build-core.mjs +4 -2
- package/kit/core/check-parity.mjs +4 -0
- package/kit/core/check-rules.mjs +3 -2
- package/kit/core/check-source.mjs +6 -0
- package/kit/core/llm-pack-assemble.mjs +37 -66
- package/kit/core/llm-pack-data.mjs +839 -45
- 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 +2 -0
- package/kit/core/purposes.mjs +9 -3
- package/kit/core/sample-info.mjs +17 -3
- package/kit/core/slide-ops.mjs +22 -0
- package/kit/core/tate-mix.mjs +25 -0
- package/kit/core/theme-derive.mjs +56 -17
- package/kit/core/theme-shapes.mjs +15 -1
- package/kit/deck.js +53 -2
- package/kit/instruction-version.json +1 -1
- package/kit/llm-pack.mjs +5 -7
- 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/package.json +1 -1
- package/vendor/components/CATALOG.md +24 -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/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/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/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/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/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -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/egatari-spec/SOURCE.json +2 -2
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// m-syntax:英文の構造(中学・高校の英語)。S V O C M の札、句と節の括弧、修飾の矢印、品詞、それから和訳
|
|
2
|
+
// <m-syntax style="height:420px">
|
|
3
|
+
// [S The girl {形^girl [S who] [V lives] [M next door]}] [V is] [C my friend].
|
|
4
|
+
// = 隣に住んでいる女の子は私の友達だ。
|
|
5
|
+
// </m-syntax>
|
|
6
|
+
// 1 行が 1 文。「= 」で始まる行は直前の文の和訳。
|
|
7
|
+
// [S …] [V …] [O …] [C …] [M …] 文の要素(O1 O2 も)。語の下に下線と記号。{ } の中の要素は小文字(s v o c m)
|
|
8
|
+
// {形 …} {副 …} {名 …} 句・節の括弧(形容詞は ( )、副詞は < >、名詞は [ ])。句か節かは中に V があるかで決まる(形句・形節と書けば固定)
|
|
9
|
+
// {形^girl …} 語^語(tall^boy) 修飾の矢印:括弧(語)から、^ の後の語(同じ文のいちばん近いもの)へ。^ だけなら隣の語({形^ …} は前、tall^ は次)
|
|
10
|
+
// 語[品詞](boy[名]) 品詞。pos="on" のときだけ出す
|
|
11
|
+
// 段階:(pos)→ 要素を 1 つずつ(S V O C M のうち出てくるもの)→ 括弧(と中の小文字の要素)→ 矢印 → 和訳。build="whole" で 1 段階
|
|
12
|
+
// 字は HTML(英文は var(--font-sans)、和訳も)。線・括弧・札は SVG で、描くたびに語の位置を測る(呼び出しの順によらない)
|
|
13
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
14
|
+
// 書き方の誤りは ctx.report("data", "[syntax] …")、属性の誤りは ctx.report("attr", …)・ctx.report("range", …)、矢印が行をまたぐときと
|
|
15
|
+
// 要素の高さが足りないときは ctx.report("size", …) で知らせる(1.x の console.warn("m-syntax: …") の代わり)。
|
|
16
|
+
// 読み取りと段階(parse・plan・durationOf と表)は試験のために static testing に出す(ほかのパーツは読まない)
|
|
17
|
+
egatariParts.define({name: "syntax", version: "2.0.4", requires: {base: "1.3.0"}, element: "m-syntax"}, function(deps){
|
|
18
|
+
"use strict";
|
|
19
|
+
var base = deps.base;
|
|
20
|
+
var D = base;
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------- 決まり
|
|
23
|
+
var ROLES = ["S", "V", "O", "C", "M"];
|
|
24
|
+
var ROLE_COLOR = {S: "var(--series-1)", V: "var(--series-2)", O: "var(--series-3)", C: "var(--series-4)", M: "var(--muted)"};
|
|
25
|
+
// 括弧の種類:名詞 [ ]・形容詞 ( )・副詞 < >(形と記号の両方で種類が分かる。色だけに頼らない)
|
|
26
|
+
var KIND = {"名": {name: "名詞", shape: "square"}, "形": {name: "形容詞", shape: "round"}, "副": {name: "副詞", shape: "angle"}};
|
|
27
|
+
// 品詞:略号 → [名前, 色の組]
|
|
28
|
+
var POS = {"名": ["名詞", "n"], "代": ["代名詞", "n"], "動": ["動詞", "v"], "助": ["助動詞", "v"], "形": ["形容詞", "a"], "副": ["副詞", "d"],
|
|
29
|
+
"冠": ["冠詞", "x"], "前": ["前置詞", "x"], "接": ["接続詞", "x"], "関": ["関係詞", "x"], "間": ["間投詞", "x"]};
|
|
30
|
+
var POS_COLOR = {n: "var(--series-1)", v: "var(--series-2)", a: "var(--series-3)", d: "var(--series-4)", x: "var(--fg)"};
|
|
31
|
+
var PUNCT = /^[.,!?;:]+$/;
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------- 読み取り
|
|
34
|
+
// parse(文字列) → {sentences: [{tokens, roles, groups, mods, yaku, text}], warnings}
|
|
35
|
+
// tokens[i] = {t, punct, pos: {tag, name, cls} | null}
|
|
36
|
+
// roles[j] = {code: "S"…"M", sub: "" | "1" | "2", a, b, lower({ } の中), depth(囲む要素の数), owner(いちばん内側の括弧の番号 | -1)}
|
|
37
|
+
// groups[j] = {kind: "名" | "形" | "副" | null, unit: "句" | "節", label, a, b, depth(囲む括弧の数), head: 語 | null}
|
|
38
|
+
// mods[j] = {from: {group: j} | {token: i}, a, b, to(頭の語の番号)} a..b は修飾する側の語の範囲
|
|
39
|
+
function norm(w){ return String(w).toLowerCase().replace(/[^\p{L}\p{N}'’-]/gu, ""); }
|
|
40
|
+
function parse(src){
|
|
41
|
+
var sentences = [], warnings = [];
|
|
42
|
+
String(src || "").split(/\r?\n/).map(function(l){ return l.trim(); }).filter(Boolean).forEach(function(l, li){
|
|
43
|
+
if (/^[==]/.test(l)){
|
|
44
|
+
var y = l.replace(/^[==]\s*/, "");
|
|
45
|
+
if (!sentences.length) warnings.push("和訳の前に英文がない:" + l);
|
|
46
|
+
else if (sentences[sentences.length - 1].yaku) warnings.push("和訳が 2 行ある(" + (li + 1) + " 行目。1 行にまとめる):" + l);
|
|
47
|
+
else sentences[sentences.length - 1].yaku = y;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
sentences.push(sentence(l, li + 1, warnings));
|
|
51
|
+
});
|
|
52
|
+
return {sentences: sentences, warnings: warnings};
|
|
53
|
+
}
|
|
54
|
+
function sentence(src, ln, warnings){
|
|
55
|
+
var l = src.replace(/[/g, "[").replace(/]/g, "]").replace(/{/g, "{").replace(/}/g, "}").replace(/^/g, "^");
|
|
56
|
+
var at = "(" + ln + " 行目)";
|
|
57
|
+
var tokens = [], roles = [], groups = [], wmods = [], stack = [], cur = "", curPos = null, nOpen = 0;
|
|
58
|
+
var lastWord = function(){ for (var i = tokens.length - 1; i >= 0; i--) if (!tokens[i].punct) return i; return -1; };
|
|
59
|
+
var push = function(t, pos){
|
|
60
|
+
var m = /^(.*?)([.,!?;:]*)$/.exec(t), w = m[1], p = m[2];
|
|
61
|
+
if (w){
|
|
62
|
+
var head = null, k = w.indexOf("^");
|
|
63
|
+
if (k === 0){ warnings.push("「^」の前に語がない:" + w + at); w = w.slice(1); }
|
|
64
|
+
else if (k > 0){ head = w.slice(k + 1); w = w.slice(0, k); } // head が "" なら次の語
|
|
65
|
+
if (w){
|
|
66
|
+
tokens.push({t: w, punct: false, pos: pos});
|
|
67
|
+
if (head !== null) wmods.push({i: tokens.length - 1, head: head});
|
|
68
|
+
}
|
|
69
|
+
} else if (pos) warnings.push("品詞の前に語がない:[" + pos.tag + "]" + at);
|
|
70
|
+
if (p) tokens.push({t: p, punct: true, pos: null});
|
|
71
|
+
};
|
|
72
|
+
var flush = function(){
|
|
73
|
+
if (!cur) return;
|
|
74
|
+
var pos = null;
|
|
75
|
+
if (curPos !== null){
|
|
76
|
+
var P = POS[curPos];
|
|
77
|
+
if (!P) warnings.push("知らない品詞「" + curPos + "」(" + Object.keys(POS).join(" ") + " のどれか)" + at);
|
|
78
|
+
pos = {tag: curPos, name: P ? P[0] : curPos, cls: P ? P[1] : "x"};
|
|
79
|
+
}
|
|
80
|
+
push(cur, pos); cur = ""; curPos = null;
|
|
81
|
+
};
|
|
82
|
+
var close = function(item){
|
|
83
|
+
var b = lastWord();
|
|
84
|
+
if (b < item.a){ warnings.push("中に語のない" + (item.type === "role" ? "要素 [" + item.code : "括弧 {" + (item.kind || "")) + "]" + at); return; }
|
|
85
|
+
item.b = b;
|
|
86
|
+
if (item.type === "role") roles.push(item); else groups.push(item);
|
|
87
|
+
};
|
|
88
|
+
var closeUntil = function(type, ch){
|
|
89
|
+
for (var j = stack.length - 1; j >= 0; j--) if (stack[j].type === type){
|
|
90
|
+
if (j !== stack.length - 1) warnings.push("閉じる順が違う:「" + ch + "」の前に閉じていないものがある" + at);
|
|
91
|
+
while (stack.length > j){ var it = stack.pop(); if (it.type !== "bad") close(it); }
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 開いていない(読めなかった開きは bad として積んである)
|
|
95
|
+
for (var q = stack.length - 1; q >= 0; q--) if (stack[q].type === "bad" && stack[q].ch === (ch === "]" ? "[" : "{")){ stack.splice(q, 1); return; }
|
|
96
|
+
warnings.push("「" + ch + "」に対応する開きがない" + at);
|
|
97
|
+
};
|
|
98
|
+
var nGroups = function(){ return stack.filter(function(x){ return x.type === "group"; }); };
|
|
99
|
+
for (var i = 0; i < l.length; i++){
|
|
100
|
+
var ch = l[i], rest = l.slice(i), m;
|
|
101
|
+
if (/\s/.test(ch)){ flush(); continue; }
|
|
102
|
+
if (ch === "[" && cur){
|
|
103
|
+
// 語に付いた [ ]:品詞
|
|
104
|
+
var e = l.indexOf("]", i), body = e > 0 ? l.slice(i + 1, e) : "";
|
|
105
|
+
if (e > 0 && body && !/\s/.test(body)){ curPos = body; i = e; continue; }
|
|
106
|
+
}
|
|
107
|
+
if (ch === "["){
|
|
108
|
+
flush();
|
|
109
|
+
m = /^\[([SVOCMsvocm])([12]?)(?=\s)/.exec(rest);
|
|
110
|
+
if (!m){ warnings.push("「[」の後に要素の記号(S V O C M)と空白がない:" + rest.slice(0, 12) + at); stack.push({type: "bad", ch: "["}); continue; }
|
|
111
|
+
var gs = nGroups();
|
|
112
|
+
stack.push({type: "role", code: m[1].toUpperCase(), sub: m[2], a: tokens.length, lower: gs.length > 0,
|
|
113
|
+
owner: gs.length ? gs[gs.length - 1].id : -1, depth: stack.filter(function(x){ return x.type === "role"; }).length});
|
|
114
|
+
i += m[0].length - 1; continue;
|
|
115
|
+
}
|
|
116
|
+
if (ch === "{"){
|
|
117
|
+
flush();
|
|
118
|
+
m = /^\{([名形副])(句|節)?(?:\^([^\s[\]{}^]*))?(?=\s)/.exec(rest);
|
|
119
|
+
var id = nOpen++;
|
|
120
|
+
if (!m){
|
|
121
|
+
var bad = /^\{(\S*)/.exec(rest)[1];
|
|
122
|
+
warnings.push("知らない括弧の種類「" + bad + "」(形・副・名。句・節と ^語 を続けてよい:{形節^girl …})" + at);
|
|
123
|
+
stack.push({type: "group", id: id, kind: null, unit: "", label: bad.replace(/\^.*$/, ""), head: null, a: tokens.length, depth: nGroups().length});
|
|
124
|
+
i += bad.length; continue;
|
|
125
|
+
}
|
|
126
|
+
stack.push({type: "group", id: id, kind: m[1], unit: m[2] || "", head: m[3] === undefined ? null : m[3], a: tokens.length, depth: nGroups().length});
|
|
127
|
+
i += m[0].length - 1; continue;
|
|
128
|
+
}
|
|
129
|
+
if (ch === "]"){ flush(); closeUntil("role", "]"); continue; }
|
|
130
|
+
if (ch === "}"){ flush(); closeUntil("group", "}"); continue; }
|
|
131
|
+
cur += ch;
|
|
132
|
+
}
|
|
133
|
+
flush();
|
|
134
|
+
while (stack.length){
|
|
135
|
+
var it = stack.pop();
|
|
136
|
+
if (it.type === "bad") continue;
|
|
137
|
+
warnings.push("閉じていない" + (it.type === "role" ? "「[" + it.code + "」" : "「{" + (it.kind || it.label) + "」") + at);
|
|
138
|
+
close(it);
|
|
139
|
+
}
|
|
140
|
+
// 括弧の番号を開いた順に(id は開いた順に振ってある)
|
|
141
|
+
groups.sort(function(x, y){ return x.id - y.id; });
|
|
142
|
+
var gid = {};
|
|
143
|
+
groups.forEach(function(g, j){ gid[g.id] = j; });
|
|
144
|
+
roles.forEach(function(r){ r.owner = r.owner >= 0 && gid[r.owner] !== undefined ? gid[r.owner] : -1; });
|
|
145
|
+
roles.sort(function(x, y){ return x.a - y.a || x.depth - y.depth; });
|
|
146
|
+
groups.forEach(function(g){
|
|
147
|
+
if (g.kind && !g.unit) g.unit = roles.some(function(r){ return r.code === "V" && r.a >= g.a && r.b <= g.b; }) ? "節" : "句";
|
|
148
|
+
if (g.kind) g.label = KIND[g.kind].name + g.unit;
|
|
149
|
+
delete g.id;
|
|
150
|
+
});
|
|
151
|
+
// 修飾の矢印:頭の語は、修飾する側の外で、いちばん近い同じ語(同じ距離なら左)
|
|
152
|
+
var mods = [];
|
|
153
|
+
var find = function(head, a, b){
|
|
154
|
+
var h = norm(head), best = -1, bd = Infinity;
|
|
155
|
+
tokens.forEach(function(t, i){
|
|
156
|
+
if (t.punct || (i >= a && i <= b) || norm(t.t) !== h) return;
|
|
157
|
+
var d = i < a ? a - i : i - b;
|
|
158
|
+
if (d < bd){ bd = d; best = i; }
|
|
159
|
+
});
|
|
160
|
+
return best;
|
|
161
|
+
};
|
|
162
|
+
// ^ だけなら隣の語:括弧は前の語、語は次の語
|
|
163
|
+
var near = function(i, dir){ for (i += dir; i >= 0 && i < tokens.length; i += dir) if (!tokens[i].punct) return i; return -1; };
|
|
164
|
+
groups.forEach(function(g, j){
|
|
165
|
+
if (g.head === null) return;
|
|
166
|
+
var to = g.head ? find(g.head, g.a, g.b) : near(g.a, -1);
|
|
167
|
+
if (to < 0) warnings.push((g.head ? "矢印の先「" + g.head + "」が括弧の外にない" : "括弧の前に語がない") + "({" + (g.kind || g.label) + "^" + g.head + " …})" + at);
|
|
168
|
+
else mods.push({from: {group: j}, a: g.a, b: g.b, to: to});
|
|
169
|
+
});
|
|
170
|
+
wmods.forEach(function(w){
|
|
171
|
+
var to = w.head ? find(w.head, w.i, w.i) : near(w.i, 1);
|
|
172
|
+
if (to < 0) warnings.push((w.head ? "矢印の先「" + w.head + "」がない" : "「^」の後に語がない") + "(" + tokens[w.i].t + "^" + w.head + ")" + at);
|
|
173
|
+
else mods.push({from: {token: w.i}, a: w.i, b: w.i, to: to});
|
|
174
|
+
});
|
|
175
|
+
mods.sort(function(x, y){ return Math.min(x.a, x.to) - Math.min(y.a, y.to) || x.a - y.a; });
|
|
176
|
+
// 矢印の段:つなぐ範囲の短いものから、重なる矢印より 1 つ上の段へ
|
|
177
|
+
var placed = [];
|
|
178
|
+
mods.map(function(o){ return {o: o, lo: Math.min(o.a, o.to), hi: Math.max(o.b, o.to)}; })
|
|
179
|
+
.sort(function(x, y){ return (x.hi - x.lo) - (y.hi - y.lo) || x.lo - y.lo; })
|
|
180
|
+
.forEach(function(s){
|
|
181
|
+
var lv = 1;
|
|
182
|
+
placed.forEach(function(q){ if (q.lo < s.hi && s.lo < q.hi) lv = Math.max(lv, q.o.lane + 1); }); // 端で接するだけなら同じ段(同じ語に来る矢印は語の幅に並べる)
|
|
183
|
+
s.o.lane = lv; placed.push(s);
|
|
184
|
+
});
|
|
185
|
+
var text = tokens.map(function(t, i){ return (i && !t.punct ? " " : "") + t.t; }).join("");
|
|
186
|
+
return {tokens: tokens, roles: roles, groups: groups, mods: mods, yaku: "", text: text};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------- 段階
|
|
190
|
+
// plan(model, {pos, yaku, whole}) → {phases: [{name, code, n, dur, step, off}], steps}
|
|
191
|
+
// name:pos(品詞)・role(code の要素)・brackets(括弧と中の小文字の要素)・arrows(矢印)・yaku(和訳)
|
|
192
|
+
var GAP = 0.2; // build="whole" の段の間
|
|
193
|
+
function phaseDur(name, n){
|
|
194
|
+
if (name === "pos") return 0.8;
|
|
195
|
+
if (name === "role") return 0.5 + 0.2 * (n - 1);
|
|
196
|
+
if (name === "brackets") return 0.7 + 0.3 * (n - 1);
|
|
197
|
+
if (name === "arrows") return 0.6 + 0.4 * (n - 1);
|
|
198
|
+
return 0.6;
|
|
199
|
+
}
|
|
200
|
+
function plan(model, o){
|
|
201
|
+
o = o || {};
|
|
202
|
+
var S = model.sentences, ph = [];
|
|
203
|
+
var all = function(f){ var n = 0; S.forEach(function(s){ n += f(s); }); return n; };
|
|
204
|
+
var nPos = all(function(s){ return s.tokens.filter(function(t){ return t.pos; }).length; });
|
|
205
|
+
if (o.pos && nPos) ph.push({name: "pos", n: nPos});
|
|
206
|
+
ROLES.forEach(function(c){
|
|
207
|
+
var n = all(function(s){ return s.roles.filter(function(r){ return !r.lower && r.code === c; }).length; });
|
|
208
|
+
if (n) ph.push({name: "role", code: c, n: n});
|
|
209
|
+
});
|
|
210
|
+
var nG = all(function(s){ return s.groups.length; });
|
|
211
|
+
if (nG) ph.push({name: "brackets", n: nG});
|
|
212
|
+
var nM = all(function(s){ return s.mods.length; });
|
|
213
|
+
if (nM) ph.push({name: "arrows", n: nM});
|
|
214
|
+
var nY = all(function(s){ return s.yaku ? 1 : 0; });
|
|
215
|
+
if (o.yaku !== false && nY) ph.push({name: "yaku", n: nY});
|
|
216
|
+
var off = 0;
|
|
217
|
+
ph.forEach(function(p, j){
|
|
218
|
+
p.dur = phaseDur(p.name, p.n);
|
|
219
|
+
if (o.whole){ p.step = 1; p.off = off; off += p.dur + GAP; }
|
|
220
|
+
else { p.step = j + 1; p.off = 0; }
|
|
221
|
+
});
|
|
222
|
+
return {phases: ph, steps: o.whole ? (ph.length ? 1 : 0) : ph.length};
|
|
223
|
+
}
|
|
224
|
+
function durationOf(pl, k){
|
|
225
|
+
var d = 0;
|
|
226
|
+
pl.phases.forEach(function(p){ if (p.step === k) d = Math.max(d, p.off + p.dur); });
|
|
227
|
+
return d;
|
|
228
|
+
}
|
|
229
|
+
// 段の中の時刻:済んだ段は Infinity、まだの段は -Infinity
|
|
230
|
+
function localTime(p, k, t){ return p.step < k ? Infinity : p.step > k ? -Infinity : t - p.off; }
|
|
231
|
+
function prog(lt, a, d){ if (lt === Infinity) return 1; if (!(lt > a)) return 0; return D.prog ? D.prog(lt, a, d) : Math.min(1, (lt - a) / d); }
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
// ---------------------------------------------------------------- 部品
|
|
235
|
+
var CSS = [
|
|
236
|
+
"m-syntax{display:block;position:relative;color:var(--fg);font-family:var(--font-sans)}",
|
|
237
|
+
"m-syntax .sx-s{display:flex;flex-wrap:wrap;align-items:flex-start}",
|
|
238
|
+
"m-syntax .sx-w{display:inline-block;white-space:nowrap}",
|
|
239
|
+
"m-syntax .sx-t{display:inline-block}",
|
|
240
|
+
"m-syntax .sx-y{font-size:28px;line-height:1.4;margin:0 0 14px}",
|
|
241
|
+
].join("\n");
|
|
242
|
+
var TAGROW = 30; // 括弧の名前の段の高さ(24px の字)
|
|
243
|
+
var LANE = 14; // 矢印の段の間
|
|
244
|
+
var ROWH = 40; // 要素の下線と記号の段の高さ
|
|
245
|
+
var POSH = 30; // 品詞の段の高さ
|
|
246
|
+
var ON = function(v){ return /^(on|true|yes)$/i.test(String(v || "").trim()); };
|
|
247
|
+
var f1 = function(x){ return x.toFixed(1); };
|
|
248
|
+
var CSS_ID = "syntax-2-0-3-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
|
|
249
|
+
return class extends base.MotionElement {
|
|
250
|
+
static partName = "syntax"; // the registry name (define meta name), for report prefixes
|
|
251
|
+
static testing = {parse: parse, plan: plan, durationOf: durationOf, POS: POS, KIND: KIND}; // for tools/test-syntax.mjs only (no part reads it)
|
|
252
|
+
static variants = ["fade", "draw"];
|
|
253
|
+
// データの形(kit/shape.js):JSON ではなく、要素の中に 1 行 1 文の英文(「= 」の行は和訳)
|
|
254
|
+
static shape = {text: true, example: "[S We] [V call] [O him] [C Ken].\n= 私たちは彼をケンと呼ぶ。"};
|
|
255
|
+
static props = {
|
|
256
|
+
size: {type: "number", default: 36, doc: "英文の字の大きさ(px)"},
|
|
257
|
+
pos: {type: "string", default: "off", doc: "on で品詞(語[名])を語の下に"},
|
|
258
|
+
build: {type: "string", default: "steps", doc: "whole で全部を 1 ステップに"},
|
|
259
|
+
yaku: {type: "bool", default: true, doc: "和訳(= の行)を最後に出す"},
|
|
260
|
+
};
|
|
261
|
+
get model(){ if (!this._m) this._m = parse(this._src !== undefined ? this._src : this.textContent); return this._m; }
|
|
262
|
+
get plan(){
|
|
263
|
+
if (!this._pl){ var P = this.props; this._pl = plan(this.model, {pos: ON(P.pos), yaku: P.yaku, whole: String(P.build).trim() === "whole"}); }
|
|
264
|
+
return this._pl;
|
|
265
|
+
}
|
|
266
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.plan.steps; }
|
|
267
|
+
duration(k){ return durationOf(this.plan, k); }
|
|
268
|
+
mount(ctx){
|
|
269
|
+
var self = this, P = this.props, size = P.size, m = this.model, pos = ON(P.pos);
|
|
270
|
+
this._src = this.textContent;
|
|
271
|
+
m.warnings.forEach(function(w){ ctx.report("data", "[syntax] " + w); });
|
|
272
|
+
if (!/^(steps|whole)$/.test(String(P.build).trim())) ctx.report("attr", '[syntax] build="' + P.build + '" is not steps or whole (steps is used)');
|
|
273
|
+
if (!(typeof size === "number" && isFinite(size))){ ctx.report("attr", '[syntax] size="' + self.getAttribute("size") + '" is not a number (36 is used)'); size = 36; }
|
|
274
|
+
if (size < 27){ ctx.report("range", "[syntax] size " + size + " is below 27 px (27 is used)"); size = 27; }
|
|
275
|
+
this.size = size;
|
|
276
|
+
this.variant = base.variant(this);
|
|
277
|
+
this.textContent = "";
|
|
278
|
+
this.classList.add("plot");
|
|
279
|
+
if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
|
|
280
|
+
var W = this.clientWidth || 1184, H = this.clientHeight || 400;
|
|
281
|
+
var mk = function(tag, cls, parent, text){ var e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; parent.appendChild(e); return e; };
|
|
282
|
+
var box = mk("div", "sx-text", this);
|
|
283
|
+
box.setAttribute("aria-hidden", "true");
|
|
284
|
+
this.box = box;
|
|
285
|
+
var svg = 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);
|
|
286
|
+
var gB = D.el("g", {}, svg), gL = D.el("g", {}, svg), gA = D.el("g", {}, svg);
|
|
287
|
+
var BR = Math.round(size * 0.36);
|
|
288
|
+
this.BR = BR;
|
|
289
|
+
this.S = m.sentences.map(function(s){
|
|
290
|
+
var G = 0, R = 0, L = 0;
|
|
291
|
+
s.groups.forEach(function(g){ G = Math.max(G, g.depth + 1); });
|
|
292
|
+
s.roles.forEach(function(r){ R = Math.max(R, r.depth + 1); });
|
|
293
|
+
s.mods.forEach(function(o){ L = Math.max(L, o.lane); });
|
|
294
|
+
var above = G * TAGROW + (L ? 14 + (L - 1) * LANE + 4 : 0) + 6, below = (pos ? POSH : 0) + R * ROWH + 6;
|
|
295
|
+
var el = mk("div", "sx-s", box);
|
|
296
|
+
el.style.cssText = "font-size:" + size + "px;line-height:1.25;column-gap:" + Math.round(size * 0.3) + "px;row-gap:" + (above + below) + "px;padding:" + above + "px 0 " + below + "px 0";
|
|
297
|
+
var opens = s.tokens.map(function(){ return 0; }), closes = opens.slice();
|
|
298
|
+
s.groups.forEach(function(g){ opens[g.a]++; closes[g.b]++; });
|
|
299
|
+
var T = [], outer = null;
|
|
300
|
+
s.tokens.forEach(function(t, i){
|
|
301
|
+
if (t.punct && outer){ T.push({el: mk("span", "sx-p", outer, t.t), t: t}); return; }
|
|
302
|
+
if (outer) el.appendChild(document.createTextNode(" ")); // 字として読むときの語の間(flex の中の空白は場所を取らない)
|
|
303
|
+
outer = mk("span", "sx-w", el);
|
|
304
|
+
var tx = mk("span", "sx-t", outer, t.t);
|
|
305
|
+
if (opens[i] || closes[i]) tx.style.margin = "0 " + closes[i] * BR + "px 0 " + opens[i] * BR + "px";
|
|
306
|
+
T.push({el: tx, t: t});
|
|
307
|
+
});
|
|
308
|
+
var S2 = {s: s, el: el, T: T, G: G, R: R, L: L};
|
|
309
|
+
S2.roles = s.roles.map(function(r){
|
|
310
|
+
var c = ROLE_COLOR[r.code];
|
|
311
|
+
var line = D.el("path", {fill: "none", stroke: c, "stroke-width": 3, "stroke-linecap": "round", pathLength: 1}, gL);
|
|
312
|
+
var lab = D.el("text", {"font-size": 28, "font-weight": 700, fill: c, "text-anchor": "middle"}, gL);
|
|
313
|
+
lab.appendChild(document.createTextNode(r.lower ? r.code.toLowerCase() : r.code));
|
|
314
|
+
if (r.sub){ var ts = D.el("tspan", {"font-size": 24, dy: 6}, lab); ts.textContent = r.sub; }
|
|
315
|
+
return {r: r, line: line, lab: lab};
|
|
316
|
+
});
|
|
317
|
+
S2.groups = s.groups.map(function(g){
|
|
318
|
+
return {g: g, path: D.el("path", {fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linecap": "round", "stroke-linejoin": "round", pathLength: 1}, gB),
|
|
319
|
+
tag: (function(){ var e = D.el("text", {"font-size": 24, fill: "var(--fg)"}, gB); e.textContent = g.label; return e; })()};
|
|
320
|
+
});
|
|
321
|
+
S2.mods = s.mods.map(function(o){
|
|
322
|
+
return {o: o, path: D.el("path", {fill: "none", stroke: "var(--emph)", "stroke-width": 2.5, "stroke-linecap": "round", "stroke-linejoin": "round", pathLength: 1}, gA),
|
|
323
|
+
head: D.el("path", {d: "M0,0L-13,-6.5L-13,6.5Z", fill: "var(--emph)"}, gA)};
|
|
324
|
+
});
|
|
325
|
+
S2.pos = pos ? s.tokens.map(function(t, i){
|
|
326
|
+
if (!t.pos) return null;
|
|
327
|
+
var e = D.el("text", {"font-size": 24, fill: POS_COLOR[t.pos.cls], "text-anchor": "middle"}, gL);
|
|
328
|
+
e.textContent = t.pos.tag;
|
|
329
|
+
return {i: i, el: e};
|
|
330
|
+
}).filter(Boolean) : [];
|
|
331
|
+
S2.yaku = s.yaku && P.yaku ? mk("div", "sx-y", box, s.yaku) : null;
|
|
332
|
+
return S2;
|
|
333
|
+
});
|
|
334
|
+
// 順番(段の中で何番目に出るか):文の順、文の中は左から
|
|
335
|
+
var cnt = {};
|
|
336
|
+
var next = function(key){ cnt[key] = (cnt[key] || 0) + 1; return cnt[key] - 1; };
|
|
337
|
+
var gIndex = [];
|
|
338
|
+
this.S.forEach(function(S2){
|
|
339
|
+
S2.pos.forEach(function(p){ p.j = next("pos"); });
|
|
340
|
+
S2.roles.forEach(function(R2){ if (!R2.r.lower) R2.j = next("role" + R2.r.code); });
|
|
341
|
+
S2.groups.forEach(function(G2){ G2.j = next("brackets"); });
|
|
342
|
+
gIndex.push(S2.groups);
|
|
343
|
+
S2.roles.forEach(function(R2){ if (R2.r.lower) R2.j = R2.r.owner >= 0 ? S2.groups[R2.r.owner].j : 0; });
|
|
344
|
+
S2.mods.forEach(function(M2){ M2.j = next("arrows"); });
|
|
345
|
+
});
|
|
346
|
+
// 読める層(画面にも印刷にも出ない):英文と構造と和訳を字で
|
|
347
|
+
var lines = m.sentences.map(function(s){
|
|
348
|
+
var span = function(a, b){ return s.tokens.slice(a, b + 1).map(function(t, i){ return (i && !t.punct ? " " : "") + t.t; }).join(""); };
|
|
349
|
+
var out = [s.text];
|
|
350
|
+
if (s.roles.length) out.push("要素:" + s.roles.map(function(r){ return (r.lower ? r.code.toLowerCase() : r.code) + r.sub + "「" + span(r.a, r.b) + "」"; }).join("、"));
|
|
351
|
+
if (s.groups.length) out.push("括弧:" + s.groups.map(function(g){ return g.label + "「" + span(g.a, g.b) + "」"; }).join("、"));
|
|
352
|
+
if (s.mods.length) out.push("修飾:" + s.mods.map(function(o){ return "「" + span(o.a, o.b) + "」→「" + s.tokens[o.to].t + "」"; }).join("、"));
|
|
353
|
+
if (pos){ var ps = s.tokens.filter(function(t){ return t.pos; }); if (ps.length) out.push("品詞:" + ps.map(function(t){ return t.t + "(" + t.pos.name + ")"; }).join("、")); }
|
|
354
|
+
if (s.yaku) out.push("訳:" + s.yaku);
|
|
355
|
+
return out.join(" ");
|
|
356
|
+
});
|
|
357
|
+
var sr = document.createElement("p");
|
|
358
|
+
sr.className = "sr-only";
|
|
359
|
+
sr.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0");
|
|
360
|
+
sr.textContent = "文の構造:" + lines.join(";");
|
|
361
|
+
this.appendChild(sr);
|
|
362
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", m.sentences.map(function(s){ return s.text; }).join(" ") + "(文の構造)");
|
|
363
|
+
}
|
|
364
|
+
// 要素の字の箱を部品の座標で。部品の外側の拡大(舞台の scale)によらない
|
|
365
|
+
rect(e){
|
|
366
|
+
var R = this.getBoundingClientRect(), sc = R.width / (this.offsetWidth || 1) || 1, r = e.getBoundingClientRect();
|
|
367
|
+
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};
|
|
368
|
+
}
|
|
369
|
+
render(k, t, ctx){
|
|
370
|
+
var self = this, P = this.props, pl = this.plan, draw = this.variant === "draw", BR = this.BR;
|
|
371
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0.45;
|
|
372
|
+
// 段ごとの時刻と、薄く見せるか
|
|
373
|
+
var phase = {};
|
|
374
|
+
pl.phases.forEach(function(p){ phase[p.name === "role" ? "role" + p.code : p.name] = p; });
|
|
375
|
+
var st = function(key){
|
|
376
|
+
var p = phase[key];
|
|
377
|
+
if (!p) return {lt: -Infinity, faint: false};
|
|
378
|
+
var faint = preview && p.step > k;
|
|
379
|
+
return {lt: faint ? Infinity : localTime(p, k, t), faint: faint};
|
|
380
|
+
};
|
|
381
|
+
var show = function(e, s, a, d){ var v = s.faint ? PV : prog(s.lt, a, d); e.setAttribute("opacity", v.toFixed(3)); return v; };
|
|
382
|
+
var stroke = function(e, s, a, d, v){ e.setAttribute("stroke-dasharray", "1"); e.setAttribute("stroke-dashoffset", (draw && !s.faint ? 1 - prog(s.lt, a, d) : 0).toFixed(4)); if (draw && !s.faint) e.setAttribute("opacity", v > 0 ? 1 : 0); };
|
|
383
|
+
var warns = [];
|
|
384
|
+
this.S.forEach(function(S2){
|
|
385
|
+
var s = S2.s, R = S2.R, G = S2.G;
|
|
386
|
+
// 語の箱と行(上の位置が変わるところで次の行)
|
|
387
|
+
var box = S2.T.map(function(x){ return self.rect(x.el); }), line = [], ln = 0, top = null;
|
|
388
|
+
box.forEach(function(b, i){
|
|
389
|
+
if (S2.T[i].t.punct){ line.push(ln); return; }
|
|
390
|
+
if (top !== null && b.t > top + 4) ln++;
|
|
391
|
+
top = b.t; line.push(ln);
|
|
392
|
+
});
|
|
393
|
+
// 範囲 a..b の語を行ごとの区間に(句読点は除く)
|
|
394
|
+
var segs = function(a, b){
|
|
395
|
+
var out = [];
|
|
396
|
+
for (var i = a; i <= b; i++){
|
|
397
|
+
if (S2.T[i].t.punct) continue;
|
|
398
|
+
var x = box[i], last = out[out.length - 1];
|
|
399
|
+
if (last && last.line === line[i]) last.r = x.r;
|
|
400
|
+
else out.push({l: x.l, r: x.r, t: x.t, b: x.b, line: line[i]});
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
};
|
|
404
|
+
// ---- 品詞:語の下
|
|
405
|
+
var sPos = st("pos");
|
|
406
|
+
S2.pos.forEach(function(p){
|
|
407
|
+
var x = box[p.i];
|
|
408
|
+
p.el.setAttribute("x", f1((x.l + x.r) / 2)); p.el.setAttribute("y", f1(x.b + 24));
|
|
409
|
+
show(p.el, sPos, 0.3 * p.j / Math.max(1, phase.pos ? phase.pos.n - 1 : 1), 0.5);
|
|
410
|
+
});
|
|
411
|
+
// ---- 要素:下線と記号。囲む要素の数だけ下の段(文の要素は同じ段にそろう)
|
|
412
|
+
var posH = S2.pos.length ? POSH : 0;
|
|
413
|
+
S2.roles.forEach(function(R2){
|
|
414
|
+
var r = R2.r, sg = segs(r.a, r.b), row = R - 1 - r.depth, d = "", best = null;
|
|
415
|
+
sg.forEach(function(g){
|
|
416
|
+
var y = g.b + posH + 6 + row * ROWH;
|
|
417
|
+
var cx = (g.l + g.r) / 2, hw = Math.max(14, (g.r - g.l) / 2 - 2); // 1 字の語(I)でも記号の幅はある
|
|
418
|
+
d += "M" + f1(cx - hw) + "," + f1(y) + "H" + f1(cx + hw);
|
|
419
|
+
if (!best || g.r - g.l > best.r - best.l) best = {l: g.l, r: g.r, y: y};
|
|
420
|
+
});
|
|
421
|
+
R2.line.setAttribute("d", d || "M0,0");
|
|
422
|
+
R2.lab.setAttribute("x", f1(best ? (best.l + best.r) / 2 : 0)); R2.lab.setAttribute("y", f1(best ? best.y + 27 : 0));
|
|
423
|
+
var s1 = r.lower ? st("brackets") : st("role" + r.code), a = r.lower ? 0.3 * R2.j + 0.2 : 0.2 * R2.j;
|
|
424
|
+
var v = show(R2.line, s1, a, 0.5); stroke(R2.line, s1, a, 0.5, v);
|
|
425
|
+
show(R2.lab, s1, a + (draw ? 0.2 : 0), draw ? 0.3 : 0.5);
|
|
426
|
+
});
|
|
427
|
+
// ---- 括弧:最初の語の前と最後の語の後。同じ語で開く(閉じる)括弧は外のものほど外へ、少し高く
|
|
428
|
+
var sB = st("brackets"), tags = [];
|
|
429
|
+
var slot = function(i, key){ return s.groups.filter(function(g){ return g[key] === i; }).sort(function(x, y){ return y.depth - x.depth; }); };
|
|
430
|
+
S2.groups.forEach(function(G2){
|
|
431
|
+
var g = G2.g, A = box[g.a], B = box[g.b], shape = g.kind ? KIND[g.kind].shape : "round";
|
|
432
|
+
var jo = slot(g.a, "a").indexOf(g), jc = slot(g.b, "b").indexOf(g), w = BR * 0.5;
|
|
433
|
+
var glyph = function(x, t0, b0, dir){ // dir 1:開き(右へ開く)、-1:閉じ
|
|
434
|
+
var h = w * dir, mid = (t0 + b0) / 2;
|
|
435
|
+
if (shape === "square") return "M" + f1(x + h / 2) + "," + f1(t0) + "H" + f1(x - h / 2) + "V" + f1(b0) + "H" + f1(x + h / 2);
|
|
436
|
+
if (shape === "angle") return "M" + f1(x + h / 2) + "," + f1(t0) + "L" + f1(x - h / 2) + "," + f1(mid) + "L" + f1(x + h / 2) + "," + f1(b0);
|
|
437
|
+
return "M" + f1(x + h / 2) + "," + f1(t0) + "Q" + f1(x - h * 0.9) + "," + f1(mid) + " " + f1(x + h / 2) + "," + f1(b0);
|
|
438
|
+
};
|
|
439
|
+
var xo = A.l - BR * (jo + 0.5), xc = B.r + BR * (jc + 0.5);
|
|
440
|
+
G2.path.setAttribute("d", glyph(xo, A.t + 4 - jo * 3, A.b - 4 + jo * 3, 1) + glyph(xc, B.t + 4 - jc * 3, B.b - 4 + jc * 3, -1));
|
|
441
|
+
var a = 0.3 * G2.j, v = show(G2.path, sB, a, 0.5); stroke(G2.path, sB, a, 0.5, v);
|
|
442
|
+
// 名前:開きの括弧の上。外の括弧ほど上の段。同じ段・同じ行で前の名前に重なれば右へずらす
|
|
443
|
+
var row = G - 1 - g.depth, tw = Array.from(g.label).length * 24, x = xo - w / 2, y = A.t - 6 - row * TAGROW;
|
|
444
|
+
tags.forEach(function(q){ if (q.line === line[g.a] && q.row === row && x < q.r + 8 && x + tw > q.l - 8) x = q.r + 8; });
|
|
445
|
+
tags.push({line: line[g.a], row: row, l: x, r: x + tw});
|
|
446
|
+
G2.tag.setAttribute("x", f1(x)); G2.tag.setAttribute("y", f1(y));
|
|
447
|
+
show(G2.tag, sB, a, 0.5);
|
|
448
|
+
G2.tagBox = {l: x, r: x + tw, t: y - 21};
|
|
449
|
+
});
|
|
450
|
+
// ---- 矢印:修飾する側(括弧の名前、または語)の上から段の高さへ上がり、頭の語の上へ下りる
|
|
451
|
+
var sA = st("arrows"), ends = {};
|
|
452
|
+
S2.mods.forEach(function(M2){ (ends[M2.o.to] = ends[M2.o.to] || []).push(M2); });
|
|
453
|
+
Object.keys(ends).forEach(function(h){
|
|
454
|
+
var list = ends[h], x = box[+h], n = list.length;
|
|
455
|
+
list.sort(function(p, q){ return p.o.a - q.o.a; });
|
|
456
|
+
list.forEach(function(M2, j){ M2.x1 = n === 1 ? (x.l + x.r) / 2 : x.l + (x.r - x.l) * (j + 1) / (n + 1); });
|
|
457
|
+
});
|
|
458
|
+
S2.mods.forEach(function(M2){
|
|
459
|
+
var o = M2.o, H = box[o.to], x0, y0, x1 = M2.x1, y1 = H.t + 3, left = o.to < o.a;
|
|
460
|
+
if (o.from.group !== undefined){ var tb = S2.groups[o.from.group].tagBox; x0 = left ? tb.l + 12 : tb.r - 12; y0 = tb.t - 2; }
|
|
461
|
+
else { var F = box[o.from.token]; x0 = (F.l + F.r) / 2; y0 = F.t + 3; }
|
|
462
|
+
var F0 = box[o.a];
|
|
463
|
+
if (line[o.a] !== line[o.to]) warns.push("「" + s.tokens[o.a].t + "」から「" + s.tokens[o.to].t + "」への矢印が行をまたぐ(要素を広くするか size を小さく、文を短く)");
|
|
464
|
+
var yl = Math.min(F0.t, H.t) - 6 - G * TAGROW - 10 - (o.lane - 1) * LANE, rr = Math.min(8, Math.abs(x1 - x0) / 2), sx = x1 < x0 ? -1 : 1;
|
|
465
|
+
var d = "M" + f1(x0) + "," + f1(y0) + "V" + f1(yl + rr) + "Q" + f1(x0) + "," + f1(yl) + " " + f1(x0 + sx * rr) + "," + f1(yl) +
|
|
466
|
+
"H" + f1(x1 - sx * rr) + "Q" + f1(x1) + "," + f1(yl) + " " + f1(x1) + "," + f1(yl + rr) + "V" + f1(y1 - 2);
|
|
467
|
+
M2.path.setAttribute("d", d);
|
|
468
|
+
M2.head.setAttribute("transform", "translate(" + f1(x1) + " " + f1(y1) + ") rotate(90)");
|
|
469
|
+
var a = 0.4 * M2.j, v = show(M2.path, sA, a, 0.6); stroke(M2.path, sA, a, 0.6, v);
|
|
470
|
+
if (draw && !sA.faint) M2.head.setAttribute("opacity", prog(sA.lt, a, 0.6) >= 0.98 ? 1 : 0);
|
|
471
|
+
else show(M2.head, sA, a, 0.6);
|
|
472
|
+
});
|
|
473
|
+
// ---- 和訳
|
|
474
|
+
if (S2.yaku){ var sY = st("yaku"); S2.yaku.style.opacity = (sY.faint ? PV : prog(sY.lt, 0, 0.6)).toFixed(3); }
|
|
475
|
+
});
|
|
476
|
+
// 収まらないとき(1 度だけ知らせる。描く絵は変えない)
|
|
477
|
+
if (!this._warned){
|
|
478
|
+
var last = this.box.lastElementChild, bottom = last ? last.offsetTop + last.offsetHeight : 0;
|
|
479
|
+
if (bottom > this.clientHeight + 2) warns.push("要素の高さ " + this.clientHeight + "px に " + Math.ceil(bottom - this.clientHeight) + "px 足りない(要素を高くするか、文を分ける)");
|
|
480
|
+
if (warns.length && document.fonts && document.fonts.status === "loaded"){ this._warned = true; warns.filter(function(w, i){ return warns.indexOf(w) === i; }).forEach(function(w){ ctx.report("size", "[syntax] " + w); }); }
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
});
|