egatari 0.6.17 → 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 +36 -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,315 @@
|
|
|
1
|
+
// m-keyboard:音楽の授業のピアノの鍵盤。段階ごとに鍵盤を光らせ(音階・和音・半音と全音)、その音を再生器に鳴らしてもらう
|
|
2
|
+
// <m-keyboard style="height:380px"><script type="application/json">
|
|
3
|
+
// {"range": "C4-C6", "names": "solfa", "steps": [{"keys": ["C4", "E4", "G4"], "label": "主和音"}]}
|
|
4
|
+
// (JSON の終わり)</m-keyboard>
|
|
5
|
+
// 段階 0 は鍵盤だけ。段階 k は steps[k-1] の keys を --emph(または step の tone)で光らせる。keys ごとの t(秒)でずらせば音階・分散和音、
|
|
6
|
+
// 同じ t なら和音。cumulative: true なら前の段階の鍵盤も薄く光ったまま
|
|
7
|
+
// 音(仕様 §8.4「Component sounds」):events(k) は鍵盤 1 つに 1 つの note(pitch は鍵盤の名前、vel 0.7、dur は dur の欄か、
|
|
8
|
+
// 次の t まで(なければ 0.8 秒))。duration(k) は最後の音の終わりまで。音だけに頼らない:光った鍵盤と印がいつも同じことを示す
|
|
9
|
+
// 鍵盤の形(customElements.get("m-keyboard").kb、tools/test-keyboard.mjs):白鍵の幅を 1 として、ド〜ミの 3 つを 5 等分、ファ〜シの 4 つを
|
|
10
|
+
// 7 等分した 2・4(・6)番目に黒鍵を置く(本物の鍵盤と同じく、ド♯とレ♯は外へ、ファ♯とラ♯も外へ寄り、ソ♯は真ん中)
|
|
11
|
+
// 授業の表示(ctx.preview):先の段階の鍵盤をテーマの --preview-opacity(なければ 0.45)で薄く、印なしで見せる
|
|
12
|
+
// 見せ方(docs/conventions.md §1):light(既定。光がフェード)・press(鍵盤が少し沈んで戻る)・rise(光が鍵盤の下から上へ満ちる)
|
|
13
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
14
|
+
// 段階の数は ctx にも言語にもよらない(spec §8.4):既定の鍵盤の名前(日本語ならドレミ、ほかは CDE)は plan() ではなく mount で選ぶ。
|
|
15
|
+
// レッスンのデータや要素の大きさの問題は ctx.report で知らせる(1.x の console.warn("m-keyboard: …") の代わり)
|
|
16
|
+
egatariParts.define({name: "keyboard", version: "2.0.6", requires: {base: "1.3.0"}, element: "m-keyboard"}, function(deps){
|
|
17
|
+
"use strict";
|
|
18
|
+
var base = deps.base;
|
|
19
|
+
// ---- 鍵盤の名前と形(DOM を使わない。tools/test-keyboard.mjs が試す) ----
|
|
20
|
+
var KB = (function(){
|
|
21
|
+
var LETTERS = "CDEFGAB", PC = {C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11};
|
|
22
|
+
var SOLFA = {C: "ド", D: "レ", E: "ミ", F: "ファ", G: "ソ", A: "ラ", B: "シ"};
|
|
23
|
+
var IROHA = {C: "ハ", D: "ニ", E: "ホ", F: "ヘ", G: "ト", A: "イ", B: "ロ"};
|
|
24
|
+
var BW = 0.58, BH = 0.62; // 黒鍵の幅(白鍵の幅に対して)と長さ(白鍵の長さに対して)
|
|
25
|
+
// "C4" "C#4" "Db4"(♯ ♭ も)→ {letter, acc: "" | "#" | "b", oct, midi, white, name}。読めなければ null
|
|
26
|
+
function parseKey(s){
|
|
27
|
+
var m = /^([A-G])([#b♯♭]?)(-?\d)$/.exec(String(s).trim());
|
|
28
|
+
if (!m) return null;
|
|
29
|
+
var acc = m[2] === "♯" ? "#" : m[2] === "♭" ? "b" : m[2], oct = +m[3];
|
|
30
|
+
// E♯・B♯・F♭・C♭ は白鍵の別の名前:鍵盤の名前としては使わない
|
|
31
|
+
if ((acc === "#" && (m[1] === "E" || m[1] === "B")) || (acc === "b" && (m[1] === "F" || m[1] === "C"))) return null;
|
|
32
|
+
var midi = 12 * (oct + 1) + PC[m[1]] + (acc === "#" ? 1 : acc === "b" ? -1 : 0);
|
|
33
|
+
return {letter: m[1], acc: acc, oct: oct, midi: midi, white: !acc, name: m[1] + acc + oct};
|
|
34
|
+
}
|
|
35
|
+
// "C4-C6" → {lo, hi}(鍵盤 2 つ)。両端は白鍵、1〜3 オクターブ(半音 12〜36 個)。違えば Error(何が・どう書くか)
|
|
36
|
+
function parseRange(s){
|
|
37
|
+
var m = /^\s*([A-G][#b♯♭]?-?\d)\s*[-–〜~]\s*([A-G][#b♯♭]?-?\d)\s*$/.exec(String(s || ""));
|
|
38
|
+
if (!m) throw new Error('m-keyboard: range "' + s + '" is not two key names such as "C4-C6"');
|
|
39
|
+
var lo = parseKey(m[1]), hi = parseKey(m[2]);
|
|
40
|
+
if (!lo || !hi) throw new Error('m-keyboard: range "' + s + '": ' + (!lo ? m[1] : m[2]) + " is not a key name (C4, F#3, Bb4, …)");
|
|
41
|
+
if (!lo.white || !hi.white) throw new Error('m-keyboard: range "' + s + '" must start and end on white keys (C D E F G A B)');
|
|
42
|
+
var span = hi.midi - lo.midi;
|
|
43
|
+
if (span < 12 || span > 36) throw new Error('m-keyboard: range "' + s + '" covers ' + span + " semitones; it must cover 1–3 octaves (12–36, such as C4-C5 or C3-C6)");
|
|
44
|
+
return {lo: lo, hi: hi};
|
|
45
|
+
}
|
|
46
|
+
// 鍵 lo〜hi(midi)を覆う範囲の書き方:"C4-D5"(両端は白鍵、半音 12〜36 個。12 に足りなければ上に広げる)。36 を超えれば null
|
|
47
|
+
function cover(lo, hi){
|
|
48
|
+
var name = function(mi){ return "C D EF G A B".charAt(((mi % 12) + 12) % 12) + (Math.floor(mi / 12) - 1); };
|
|
49
|
+
var white = function(mi){ return [0, 2, 4, 5, 7, 9, 11].indexOf(((mi % 12) + 12) % 12) >= 0; };
|
|
50
|
+
if (!white(lo)) lo--;
|
|
51
|
+
if (!white(hi)) hi++;
|
|
52
|
+
if (hi - lo < 12){ hi = lo + 12; if (!white(hi)) hi++; }
|
|
53
|
+
return hi - lo > 36 ? null : name(lo) + "-" + name(hi);
|
|
54
|
+
}
|
|
55
|
+
// 範囲の鍵盤:白鍵 {midi, white: true, i, x(左の端), w: 1}、黒鍵 {midi, white: false, x(左の端), cx(真ん中), w: BW}。単位は白鍵の幅
|
|
56
|
+
function keys(r){
|
|
57
|
+
var out = [], whites = [], wi = -1;
|
|
58
|
+
for (var mi = r.lo.midi; mi <= r.hi.midi; mi++){
|
|
59
|
+
var pc = ((mi % 12) + 12) % 12, white = [0, 2, 4, 5, 7, 9, 11].indexOf(pc) >= 0;
|
|
60
|
+
if (white){ wi++; var k = {midi: mi, pc: pc, white: true, i: wi, x: wi, w: 1}; whites.push(k); out.push(k); continue; }
|
|
61
|
+
// 黒鍵:下の白鍵(i = wi)の組(ド〜ミ か ファ〜シ)の始まりから数える
|
|
62
|
+
var g = pc < 5 ? {start: wi - (pc - 1) / 2, n: 3, slot: (pc === 1 ? 1 : 3)} : {start: wi - (pc - 6) / 2, n: 4, slot: (pc === 6 ? 1 : pc === 8 ? 3 : 5)};
|
|
63
|
+
var cx = g.start + (g.slot + 0.5) * g.n / (2 * g.n - 1);
|
|
64
|
+
out.push({midi: mi, pc: pc, white: false, below: wi, cx: cx, x: cx - BW / 2, w: BW});
|
|
65
|
+
}
|
|
66
|
+
return {all: out, whites: whites, n: whites.length, BW: BW, BH: BH};
|
|
67
|
+
}
|
|
68
|
+
// 鍵盤の名前:names = "solfa"(ドレミ)・"abc"(CDE)・"iroha"(ハニホ)・"none"(null)。黒鍵は ♯・♭ をつける(ド♯ / C♯、レ♭ / D♭)。
|
|
69
|
+
// iroha は前に 嬰・変 をつける(嬰ハ、変ニ)
|
|
70
|
+
function label(k, names){
|
|
71
|
+
if (names === "none") return null;
|
|
72
|
+
if (names === "iroha") return (k.acc === "#" ? "嬰" : k.acc === "b" ? "変" : "") + IROHA[k.letter];
|
|
73
|
+
var s = names === "abc" ? k.letter : SOLFA[k.letter];
|
|
74
|
+
return s + (k.acc === "#" ? "♯" : k.acc === "b" ? "♭" : "");
|
|
75
|
+
}
|
|
76
|
+
// 白鍵の名前(範囲の中の midi から。白鍵は ♯ も ♭ もない)
|
|
77
|
+
function whiteLetter(midi){ return "C D EF G A B".charAt(((midi % 12) + 12) % 12); }
|
|
78
|
+
// 段階 1 つの音:鍵盤 1 つに 1 つ。t は keys ごと(なければ 0)。dur は step.dur → 全体の dur → 次の(より遅い)t まで → 0.8 秒
|
|
79
|
+
function notes(step, dur){
|
|
80
|
+
var ts = (step.keys || []).map(function(_, i){ return step.t && typeof step.t[i] === "number" ? step.t[i] : 0; });
|
|
81
|
+
var d0 = typeof step.dur === "number" ? step.dur : typeof dur === "number" ? dur : null;
|
|
82
|
+
return step.keys.map(function(key, i){
|
|
83
|
+
var k = parseKey(key), t = ts[i], later = ts.filter(function(u){ return u > t + 1e-9; }), next = later.length ? Math.min.apply(null, later) : null;
|
|
84
|
+
return {t: t, sound: "note", pitch: k ? k.name : String(key), dur: d0 !== null ? d0 : next !== null ? +(next - t).toFixed(6) : 0.8, vel: 0.7};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// 段階の長さ:最後の音の終わり
|
|
88
|
+
function length(step, dur){ return notes(step, dur).reduce(function(a, n){ return Math.max(a, n.t + n.dur); }, 0); }
|
|
89
|
+
// 段階 k・時刻 t の鍵盤ごとの状態(render が描く。DOM を使わない)。steps は plan の段階(keys は parseKey の結果、ev は notes)。
|
|
90
|
+
// o = {cumulative, preview, variant, prog(t, at, len)}。{midi: {e: 今の段階の光の進み 0〜1, p: 動きの進み, tone, ids: {綴り: e},
|
|
91
|
+
// faded: 前の段階で光った(cumulative), fadeTone, fids, pre: 先の段階で光る(授業の表示で薄く。印なし), preTone}}
|
|
92
|
+
function state(steps, k, t, o){
|
|
93
|
+
var st = {}, cur = steps[k - 1];
|
|
94
|
+
var get = function(m){ return st[m] || (st[m] = {e: 0, p: 0, faded: false, pre: false, tone: null, fadeTone: null, preTone: null, ids: {}, fids: {}}); };
|
|
95
|
+
if (o.cumulative) for (var j = 0; j < k - 1 && j < steps.length; j++){
|
|
96
|
+
var sj = steps[j];
|
|
97
|
+
sj.keys.forEach(function(kk){ var s = get(kk.midi); s.faded = true; s.fadeTone = sj.tone; s.fids[kk.midi + "|" + kk.acc] = true; });
|
|
98
|
+
}
|
|
99
|
+
if (cur) cur.keys.forEach(function(kk, i){
|
|
100
|
+
var n = cur.ev[i], len = o.variant === "light" ? Math.min(0.2, n.dur) : Math.min(0.3, n.dur);
|
|
101
|
+
var e = t === Infinity ? 1 : o.prog(t, n.t, len), s = get(kk.midi), id = kk.midi + "|" + kk.acc;
|
|
102
|
+
if (e >= s.e){ s.e = e; s.p = t === Infinity ? 1 : Math.max(0, Math.min(1, (t - n.t) / len)); }
|
|
103
|
+
s.tone = cur.tone; if (e > 0) s.ids[id] = Math.max(s.ids[id] || 0, e);
|
|
104
|
+
});
|
|
105
|
+
// 授業の表示:先の段階の鍵盤を薄く(いちばん近い段階の色。今・前の段階で光っている鍵盤はそのまま)
|
|
106
|
+
if (o.preview) for (var q = steps.length - 1; q >= Math.max(0, k); q--){
|
|
107
|
+
var sq = steps[q];
|
|
108
|
+
sq.keys.forEach(function(kk){ var s = get(kk.midi); if (s.e > 0 || s.faded) return; s.pre = true; s.preTone = sq.tone; });
|
|
109
|
+
}
|
|
110
|
+
return st;
|
|
111
|
+
}
|
|
112
|
+
return {state: state, parseKey: parseKey, parseRange: parseRange, cover: cover, keys: keys, label: label, whiteLetter: whiteLetter, notes: notes, length: length, LETTERS: LETTERS, BW: BW, BH: BH};
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
var TONES = /^(term|emph|muted|accent2|fg|series-[1-4])$/;
|
|
116
|
+
// 字の幅(base の textWidth:font の要素の字で測った幅)
|
|
117
|
+
var est = function(s, size, font){ return base.textWidth(s, size, {font: font}); };
|
|
118
|
+
return class extends base.MotionElement {
|
|
119
|
+
static partName = "keyboard"; // the registry name (define meta name), for report prefixes
|
|
120
|
+
static variants = ["light", "press", "rise"];
|
|
121
|
+
static kb = KB;
|
|
122
|
+
static shape = {
|
|
123
|
+
schema: {type: "object", additionalProperties: false, required: ["range", "steps"], properties: {
|
|
124
|
+
range: {type: "string"}, names: {type: "string", enum: ["solfa", "abc", "iroha", "none"]}, cumulative: {type: "boolean"}, dur: {type: "number"},
|
|
125
|
+
steps: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["keys"], properties: {
|
|
126
|
+
keys: {type: "array", minItems: 1, items: {type: "string"}}, label: {type: "string"}, t: {type: "array", items: {type: "number"}},
|
|
127
|
+
tone: {type: "string"}, dur: {type: "number"}}}}}},
|
|
128
|
+
example: {range: "C4-C6", names: "solfa", steps: [{keys: ["C4", "E4", "G4"], label: "主和音(ドミソ)"}]},
|
|
129
|
+
note: {en: "range \"C4-C6\" (white keys at both ends, 1–3 octaves); steps [{keys: [\"C4\", \"E4\"], label, t: [seconds per key], tone, dur}]",
|
|
130
|
+
ja: "range \"C4-C6\"(両端は白鍵、1〜3 オクターブ)、steps [{keys: [\"C4\", \"E4\"], label, t: [鍵盤ごとの秒], tone, dur}]"},
|
|
131
|
+
};
|
|
132
|
+
static props = {};
|
|
133
|
+
get steps(){
|
|
134
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
135
|
+
return this.plan().steps.length;
|
|
136
|
+
}
|
|
137
|
+
// 範囲と段階を読む(mount の前にも steps が要る)。範囲・鍵盤の名前・t の数が違えば Error(札が出る)
|
|
138
|
+
plan(){
|
|
139
|
+
if (this._plan) return this._plan;
|
|
140
|
+
var d = this.data || {}, notes = [];
|
|
141
|
+
var r = KB.parseRange(d.range), kb = KB.keys(r), outside = [];
|
|
142
|
+
// 音の長さ dur(全体と段階ごと)は 0 より長い秒数:0 以下は知らせて、書いていないものとする(次の t まで、なければ 0.8 秒)
|
|
143
|
+
var gdur = d.dur;
|
|
144
|
+
if (typeof gdur === "number" && !(gdur > 0)){ notes.push("[keyboard] dur " + gdur + " is not more than 0 seconds (ignored: each note lasts until the next t, or 0.8 s)"); gdur = undefined; }
|
|
145
|
+
var steps = d.steps.map(function(s0, j){
|
|
146
|
+
var s = s0;
|
|
147
|
+
if (typeof s0.dur === "number" && !(s0.dur > 0)){ notes.push("[keyboard] steps[" + j + "] dur " + s0.dur + " is not more than 0 seconds (ignored)"); s = Object.assign({}, s0); delete s.dur; }
|
|
148
|
+
var ks = s.keys.map(function(name){
|
|
149
|
+
var k = KB.parseKey(name);
|
|
150
|
+
if (!k) throw new Error("m-keyboard: steps[" + j + "] key \"" + name + "\" is not a key name (C4, F#3, Bb4, …)");
|
|
151
|
+
if (k.midi < r.lo.midi || k.midi > r.hi.midi) outside.push("steps[" + j + "] key " + name);
|
|
152
|
+
return k;
|
|
153
|
+
});
|
|
154
|
+
if (s.t && s.t.length !== s.keys.length) throw new Error("m-keyboard: steps[" + j + "] has " + s.keys.length + " keys but " + s.t.length + " times in t (one per key)");
|
|
155
|
+
if (s.t && s.t.some(function(v){ return !(v >= 0); })) throw new Error("m-keyboard: steps[" + j + "] t must be seconds ≥ 0");
|
|
156
|
+
if (s.tone !== undefined && !TONES.test(s.tone)) notes.push('[keyboard] steps[' + j + '] tone "' + s.tone + '" is not a theme colour (emph is used)');
|
|
157
|
+
var ev = KB.notes(s, gdur);
|
|
158
|
+
return {o: s, keys: ks, ev: ev, len: KB.length(s, gdur), tone: TONES.test(s.tone || "") ? s.tone : "emph"};
|
|
159
|
+
});
|
|
160
|
+
if (outside.length){
|
|
161
|
+
// 範囲の外の鍵:すべての鍵を覆う範囲を示す(範囲そのものではなく、段階の鍵だけから)
|
|
162
|
+
var lo = Infinity, hi = -Infinity;
|
|
163
|
+
steps.forEach(function(s){ s.keys.forEach(function(k){ lo = Math.min(lo, k.midi); hi = Math.max(hi, k.midi); }); });
|
|
164
|
+
var c = KB.cover(lo, hi);
|
|
165
|
+
throw new Error("m-keyboard: " + outside.join(", ") + (outside.length > 1 ? " are" : " is") + " outside range " + d.range + "; " +
|
|
166
|
+
(c ? "use " + c + " (covers every key in steps)" : "the keys in steps span " + (hi - lo) + " semitones, more than 3 octaves: split them over two keyboards"));
|
|
167
|
+
}
|
|
168
|
+
return (this._plan = {r: r, kb: kb, steps: steps, cumulative: d.cumulative === true, notes: notes});
|
|
169
|
+
}
|
|
170
|
+
duration(k){ var s = k >= 1 && this.plan().steps[k - 1]; return s ? s.len : 0; }
|
|
171
|
+
events(k){ var s = k >= 1 && this.plan().steps[k - 1]; return s ? s.ev.map(function(e){ return Object.assign({}, e); }) : []; }
|
|
172
|
+
mount(ctx){
|
|
173
|
+
var self = this, D = base, pl = this.plan(), kb = pl.kb, d = this.data || {};
|
|
174
|
+
this.variant = base.variant(this);
|
|
175
|
+
// 鍵盤の名前:書いていなければ日本語の授業はドレミ、ほかは CDE(段階の数は変わらないので plan() ではなくここで選ぶ)
|
|
176
|
+
var names = d.names === undefined ? (/^ja\b/i.test(ctx.lang) ? "solfa" : "abc") : d.names;
|
|
177
|
+
pl.notes.forEach(function(n){ ctx.report("data", n); });
|
|
178
|
+
this.style.display = "block";
|
|
179
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
180
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
181
|
+
// 読み上げ:最後の形で光っている鍵盤(cumulative なら全部の段階の)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
182
|
+
var ja = /^ja\b/i.test(ctx.lang || "ja");
|
|
183
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
184
|
+
this.setAttribute("role", "img");
|
|
185
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(ja, names === "none" ? (ja ? "solfa" : "abc") : names));
|
|
186
|
+
var hasLabel = pl.steps.some(function(s){ return s.o.label; });
|
|
187
|
+
// 光る黒鍵の名前の行:となりの名前に重なるなら 2 行目へ(どの段階でも同じ置き場所)
|
|
188
|
+
var LFS = 30, NFS = 26, BFS = 24;
|
|
189
|
+
var unitW = Math.max(0, Math.min((W - 6) / kb.n, 96));
|
|
190
|
+
var x0 = (W - unitW * kb.n) / 2;
|
|
191
|
+
var bl = {};
|
|
192
|
+
pl.steps.forEach(function(s){ s.keys.forEach(function(k){ if (!k.white && names !== "none") bl[k.midi + "|" + k.acc] = k; }); });
|
|
193
|
+
var blist = Object.keys(bl).map(function(id){
|
|
194
|
+
var k = bl[id], key = kb.all.filter(function(q){ return q.midi === k.midi; })[0], s = KB.label(k, names);
|
|
195
|
+
return {id: id, k: k, s: s, cx: x0 + key.cx * unitW, w: est(s, BFS, self)};
|
|
196
|
+
}).sort(function(a, b){ return a.cx - b.cx || a.id.localeCompare(b.id); });
|
|
197
|
+
var rowsEnd = [-1e9, -1e9], nRows = 0;
|
|
198
|
+
blist.forEach(function(b){
|
|
199
|
+
var row = b.cx - b.w / 2 > rowsEnd[0] + 10 ? 0 : 1;
|
|
200
|
+
if (row === 1 && b.cx - b.w / 2 <= rowsEnd[1] + 10) ctx.report("size", "[keyboard] the names of black keys near " + b.s + " overlap (use a wider element or a narrower range)");
|
|
201
|
+
rowsEnd[row] = b.cx + b.w / 2; b.row = row; nRows = Math.max(nRows, row + 1);
|
|
202
|
+
});
|
|
203
|
+
// cumulative:段階の名前を、その段階の鍵盤の真ん中の上に残す(前の段階の名前も消さない。色だけで見分けないように)。
|
|
204
|
+
// 名前が重なれば次の行へ(行は 40 px)
|
|
205
|
+
var cumLabs = pl.cumulative && hasLabel ? [] : null, labRows = 1;
|
|
206
|
+
if (cumLabs) pl.steps.forEach(function(s, j){
|
|
207
|
+
if (!s.o.label) return;
|
|
208
|
+
var xs = s.keys.map(function(k){ var key = kb.all.filter(function(q){ return q.midi === k.midi; })[0]; return x0 + (key.white ? key.x + 0.5 : key.cx) * unitW; });
|
|
209
|
+
var w = est(s.o.label, LFS, self), cx = (Math.min.apply(null, xs) + Math.max.apply(null, xs)) / 2;
|
|
210
|
+
cx = Math.max(w / 2 + 2, Math.min(W - w / 2 - 2, cx));
|
|
211
|
+
var row = 0;
|
|
212
|
+
while (cumLabs.some(function(o){ return o.row === row && Math.abs(o.cx - cx) < (o.w + w) / 2 + 16; })) row++;
|
|
213
|
+
cumLabs.push({j: j, s: s.o.label, w: w, cx: cx, row: row, tone: s.tone}); labRows = Math.max(labRows, row + 1);
|
|
214
|
+
});
|
|
215
|
+
var labH = hasLabel ? 46 + (labRows - 1) * 40 : 0, bnH = nRows * 32, namesH = names === "none" ? 0 : 40, gapTop = nRows ? 8 : (hasLabel ? 10 : 0);
|
|
216
|
+
var avail = H - labH - bnH - gapTop - namesH - 8;
|
|
217
|
+
var keyH = Math.max(0, Math.min(avail, unitW * 4.4));
|
|
218
|
+
if (avail < 110) ctx.report("size", "[keyboard] the element (" + W + "×" + H + " px) leaves only " + Math.round(avail) + " px for the keys; make it taller (about " + Math.ceil(H + 110 - avail) + " px)");
|
|
219
|
+
if (unitW < 40) ctx.report("size", "[keyboard] white keys are " + unitW.toFixed(0) + " px wide; the names under them may not fit (use a narrower range or a wider element)");
|
|
220
|
+
var used = labH + bnH + gapTop + keyH + namesH, top0 = Math.max(0, (H - used) / 2);
|
|
221
|
+
var labY = top0 + 34, bnTop = top0 + labH, keyTop = bnTop + bnH + gapTop, keyBot = keyTop + keyH, bH = keyH * KB.BH;
|
|
222
|
+
this.geo = {x0: x0, unitW: unitW, keyTop: keyTop, keyH: keyH};
|
|
223
|
+
// 鍵盤:白鍵 → 白鍵の光 → 黒鍵 → 黒鍵の光(黒鍵は短く、上に)
|
|
224
|
+
var gW = D.el("g", {}, svg), gB = D.el("g", {}, svg), gT = D.el("g", {}, svg);
|
|
225
|
+
var K = this.K = {};
|
|
226
|
+
var rise = this.variant === "rise";
|
|
227
|
+
kb.all.forEach(function(key){
|
|
228
|
+
var white = key.white, x = x0 + key.x * unitW, w = key.w * unitW, h = white ? keyH : bH;
|
|
229
|
+
var par = white ? gW : gB, g = D.el("g", {}, par);
|
|
230
|
+
D.el("rect", {x: x.toFixed(1), y: keyTop.toFixed(1), width: w.toFixed(1), height: h.toFixed(1), rx: white ? 4 : 3,
|
|
231
|
+
fill: white ? "var(--bg)" : "var(--fg)", stroke: "var(--fg)", "stroke-width": white ? 2 : 1.5}, g);
|
|
232
|
+
var ins = white ? 3 : 4;
|
|
233
|
+
var lit = D.el("rect", {x: (x + ins).toFixed(1), y: (keyTop + (white ? 2 : 0)).toFixed(1), width: Math.max(0, w - 2 * ins).toFixed(1), height: Math.max(0, h - ins - (white ? 2 : 0)).toFixed(1), rx: 2, opacity: 0}, g);
|
|
234
|
+
var cx = x + w / 2, r = white ? Math.min(9, w * 0.16) : Math.min(7, w * 0.2), cy = keyTop + h - (white ? 14 + r : 10 + r);
|
|
235
|
+
var dot = D.el("circle", {cx: cx.toFixed(1), cy: cy.toFixed(1), r: r.toFixed(1), opacity: 0}, g);
|
|
236
|
+
K[key.midi] = {key: key, g: g, lit: lit, dot: dot, y: keyTop + (white ? 2 : 0), h: Math.max(0, h - ins - (white ? 2 : 0)), white: white, nm: null, bn: {}};
|
|
237
|
+
});
|
|
238
|
+
// 白鍵の名前(鍵盤の下)
|
|
239
|
+
if (names !== "none") kb.whites.forEach(function(key){
|
|
240
|
+
var s = KB.label({letter: KB.whiteLetter(key.midi), acc: ""}, names);
|
|
241
|
+
var t = D.el("text", {x: (x0 + (key.x + 0.5) * unitW).toFixed(1), y: (keyBot + 32).toFixed(1), "font-size": NFS, "text-anchor": "middle", fill: "var(--fg)"}, gT);
|
|
242
|
+
t.textContent = s;
|
|
243
|
+
K[key.midi].nm = t;
|
|
244
|
+
});
|
|
245
|
+
// 光る黒鍵の名前(鍵盤の上。光っているときだけ)
|
|
246
|
+
blist.forEach(function(b){
|
|
247
|
+
var t = D.el("text", {x: b.cx.toFixed(1), y: (bnTop + 25 + (nRows - 1 - b.row) * 32).toFixed(1), "font-size": BFS, "font-weight": 700, "text-anchor": "middle", fill: "var(--fg)", opacity: 0}, gT);
|
|
248
|
+
t.textContent = b.s;
|
|
249
|
+
K[b.k.midi].bn[b.id] = t;
|
|
250
|
+
});
|
|
251
|
+
// 段階の名前(鍵盤の上、24 px 以上)
|
|
252
|
+
this.lab = D.el("text", {x: (W / 2).toFixed(1), y: labY.toFixed(1), "font-size": LFS, "font-weight": 700, "text-anchor": "middle", fill: "var(--fg)", opacity: 0}, gT);
|
|
253
|
+
// cumulative の段階の名前:字と、その段階の色の下線(鍵盤の光と同じ色)
|
|
254
|
+
this.cumLabs = cumLabs && cumLabs.map(function(o){
|
|
255
|
+
var g = D.el("g", {opacity: 0}, gT), y = labY + o.row * 40;
|
|
256
|
+
var tx = D.el("text", {x: o.cx.toFixed(1), y: y.toFixed(1), "font-size": LFS, "font-weight": 700, "text-anchor": "middle", fill: "var(--fg)"}, g);
|
|
257
|
+
tx.textContent = o.s;
|
|
258
|
+
D.el("rect", {x: (o.cx - o.w / 2).toFixed(1), y: (y + 6).toFixed(1), width: o.w.toFixed(1), height: 4, rx: 2, fill: "var(--" + o.tone + ")"}, g);
|
|
259
|
+
return {j: o.j, g: g, tx: tx};
|
|
260
|
+
});
|
|
261
|
+
pl.steps.forEach(function(s, j){ if (s.o.label && est(s.o.label, LFS, self) > W) ctx.report("size", "[keyboard] steps[" + j + "] label is wider than the element; shorten it"); });
|
|
262
|
+
if (rise) Object.keys(K).forEach(function(m){ K[m].lit.setAttribute("data-y", K[m].y); });
|
|
263
|
+
}
|
|
264
|
+
// 最後の形を 1 文で(読み上げの名前):「鍵盤:ド・ミ・ソ(Ⅰ)」。cumulative なら全部の段階を順に、そうでなければ最後の段階
|
|
265
|
+
summary(ja, names){
|
|
266
|
+
var pl = this.plan(), st = pl.cumulative ? pl.steps : pl.steps.slice(-1);
|
|
267
|
+
return (ja ? "鍵盤:" : "Keyboard: ") + st.map(function(s){
|
|
268
|
+
return s.keys.map(function(k){ return KB.label(k, names); }).join(ja ? "・" : ", ") + (s.o.label ? (ja ? "(" + s.o.label + ")" : " (" + s.o.label + ")") : "");
|
|
269
|
+
}).join(ja ? "、" : "; ");
|
|
270
|
+
}
|
|
271
|
+
render(k, t, ctx){
|
|
272
|
+
var pl = this.plan(), K = this.K, v = this.variant, cur = pl.steps[k - 1];
|
|
273
|
+
// 薄さはテーマの --preview-opacity(仕様 §8.4「Answers under preview」)。書いていないテーマだけ 0.45
|
|
274
|
+
var preview = !!ctx.preview, FAINT = preview ? base.previewOpacity(this) : 0.45;
|
|
275
|
+
var st = KB.state(pl.steps, k, t, {cumulative: pl.cumulative, preview: preview, variant: v, prog: base.prog});
|
|
276
|
+
Object.keys(K).forEach(function(m){
|
|
277
|
+
var o = K[m], s = st[m] || {e: 0, faded: false, pre: false, ids: {}, fids: {}}, on = s.e > 0;
|
|
278
|
+
var tone = on ? s.tone : s.faded ? s.fadeTone : s.preTone;
|
|
279
|
+
o.lit.setAttribute("fill", "var(--" + (tone || "emph") + ")");
|
|
280
|
+
var op = on ? (s.faded ? Math.max(0.4, v === "light" ? s.e : 1) : v === "light" ? s.e : 1) : s.faded ? 0.4 : s.pre ? FAINT : 0;
|
|
281
|
+
// rise:光が鍵盤の下から上へ満ちる
|
|
282
|
+
if (v === "rise"){
|
|
283
|
+
var f = on ? (s.faded ? 1 : s.e) : 1, h = o.h * f;
|
|
284
|
+
o.lit.setAttribute("y", (o.y + o.h - h).toFixed(1)); o.lit.setAttribute("height", h.toFixed(1));
|
|
285
|
+
}
|
|
286
|
+
o.lit.setAttribute("opacity", op.toFixed(3));
|
|
287
|
+
// 印:今の段階は塗った丸、前の段階は輪(色だけに頼らない)
|
|
288
|
+
o.dot.setAttribute("fill", on ? "var(--bg)" : "none");
|
|
289
|
+
o.dot.setAttribute("stroke", on ? "none" : o.white ? "var(--fg)" : "var(--bg)");
|
|
290
|
+
o.dot.setAttribute("stroke-width", on ? 0 : 2.5);
|
|
291
|
+
o.dot.setAttribute("opacity", (on ? (v === "press" ? 1 : s.e) : s.faded ? 0.9 : 0).toFixed(3));
|
|
292
|
+
// press:少し沈んで戻る(4 px、0.3 秒まで)
|
|
293
|
+
var dy = v === "press" && on && s.p < 1 ? 4 * Math.sin(Math.PI * s.p) : 0;
|
|
294
|
+
o.g.setAttribute("transform", dy ? "translate(0," + dy.toFixed(2) + ")" : "");
|
|
295
|
+
for (var id in o.bn){
|
|
296
|
+
var a = s.ids[id] ? (v === "light" ? s.ids[id] : 1) : 0;
|
|
297
|
+
if (!a && s.fids[id]) a = 0.75;
|
|
298
|
+
o.bn[id].setAttribute("opacity", a.toFixed(3));
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
var lab = cur && cur.o.label, la = lab ? (t === Infinity ? 1 : base.prog(t, 0, Math.min(0.3, cur.len || 0.3))) : 0;
|
|
302
|
+
if (this.cumLabs){
|
|
303
|
+
// cumulative:前の段階の名前はそのまま、今の段階の名前は太字でフェードして現れる
|
|
304
|
+
this.lab.textContent = ""; this.lab.setAttribute("opacity", 0);
|
|
305
|
+
this.cumLabs.forEach(function(o){
|
|
306
|
+
o.g.setAttribute("opacity", (o.j < k - 1 ? 1 : o.j === k - 1 ? la : 0).toFixed(3));
|
|
307
|
+
o.tx.setAttribute("font-weight", o.j === k - 1 ? 700 : 400);
|
|
308
|
+
});
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
this.lab.textContent = lab || "";
|
|
312
|
+
this.lab.setAttribute("opacity", lab ? la.toFixed(3) : 0);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2026 Paweł Kuna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|