egatari 0.6.10 → 0.6.11-rc.1
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/README.ja.md +22 -22
- package/README.md +1 -1
- package/bin/egatari.mjs +1 -1
- package/components.lock.json +288 -144
- package/components2.lock.json +657 -1
- package/kit/build.mjs +3 -2
- package/kit/check-messages.mjs +46 -12
- package/kit/check.mjs +54 -19
- package/kit/core/article-messages.mjs +5 -4
- package/kit/core/attachments.mjs +2 -1
- package/kit/core/build-core.mjs +2 -1
- package/kit/core/check-parity.mjs +3 -1
- package/kit/core/check-result.mjs +2 -1
- package/kit/core/check-rules.mjs +132 -0
- package/kit/core/colab-core.mjs +2 -2
- package/kit/core/geometry-check.mjs +302 -0
- package/kit/core/layout-scan.mjs +9 -2
- package/kit/core/live-results.mjs +1 -1
- package/kit/core/llm-fix.mjs +3 -2
- package/kit/core/llm-outline.mjs +3 -2
- package/kit/core/llm-pack-data.mjs +114 -114
- package/kit/core/narration-lint.mjs +37 -0
- package/kit/core/new-deck-pack.mjs +2 -1
- package/kit/core/new-deck.mjs +1 -1
- package/kit/core/plural.mjs +5 -0
- package/kit/core/portable.mjs +6 -5
- package/kit/core/sample-layout.mjs +14 -0
- package/kit/core/text-band.mjs +37 -0
- package/kit/core/tier-a.mjs +2 -1
- package/kit/instruction-version.json +1 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/render-compare.mjs +5 -4
- package/kit/tools.js +2 -2
- package/package.json +3 -2
- package/server/editor-ui.js +2 -2
- package/vendor/components/CATALOG.md +12 -12
- package/vendor/components/sha256/00d9072cb279a1a68166787f53395c747072388971d916c082a106844dbf888f/index.js +315 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/README.en.md +23 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/index.js +289 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/README.en.md +40 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/index.js +341 -0
- package/vendor/components/sha256/1073e03374f0fe65d2691f160bfd8c092986c168d0bd6a6094ebd444d4b89c27/index.js +592 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/README.en.md +48 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/index.js +384 -0
- package/vendor/components/sha256/147987bd84722249dab609293d4fafa93f0a2aac25b8517fda1710840b575d00/index.js +341 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/README.en.md +23 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/index.js +120 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/README.en.md +32 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/index.js +222 -0
- package/vendor/components/sha256/1b30dfd9b366ff07556024eb8ce75cca2eac8001fa392eed4e1232047001ec74/index.js +404 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/README.en.md +66 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/index.js +920 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/README.en.md +50 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/index.js +171 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/README.en.md +31 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/index.js +232 -0
- package/vendor/components/sha256/43740da51de85c1b7ec1eaf688f93fd9ea25b15977ab075e6abac196f08643a6/index.js +122 -0
- package/vendor/components/sha256/4817f77bd021ec5c77d5a15ee56e2e34d31d1d98630e86225eb20f2f9bf095e9/index.js +812 -0
- package/vendor/components/sha256/4e4bf3b2968c36a334dc997e32e36f22ecbc4f5dfe1c76bb7a5beef002fe8899/index.js +228 -0
- package/vendor/components/sha256/553e132d1f84caad648bb7175a206d4c5d18c005b5ca17989f5e8a5e3f5cdfa1/index.js +75 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/README.en.md +34 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/index.js +244 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/index.js +4868 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/names.txt +4808 -0
- package/vendor/components/sha256/636f47e955f5550f046cfc7a3de8de70c4b97aa77771bde2ee0e31d706bb032e/index.js +278 -0
- package/vendor/components/sha256/65ddc34bd9c75e073f4c2cd283369417fe88769521809670c6b8730852d4f647/index.js +97 -0
- package/vendor/components/sha256/6b0c75b0f697fe451197301de82a113f1c2548b67f7a8d2b56576d2bae8e240c/index.js +607 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/README.en.md +33 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/index.js +390 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/README.en.md +31 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/index.js +267 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/README.en.md +22 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/index.js +145 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/README.en.md +44 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/index.js +203 -0
- package/vendor/components/sha256/781a45d97f1325cfb40aa98d00e1db9600949158fdb2749b0223b019c67a80f2/index.js +919 -0
- package/vendor/components/sha256/850944419734168be3dc202057de128131869c471cb8ab3baec2cfe789d56493/index.js +465 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/README.en.md +37 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/index.js +424 -0
- package/vendor/components/sha256/8a892d25d0bb6105ba31ea690b465876ce3af1fbaf18e2a9ce44ad2fee81260e/index.js +162 -0
- package/vendor/components/sha256/8acec8f299510287fbad6a69311ec58a39b0e99647dd03609c818e053b3b6087/index.js +484 -0
- package/vendor/components/sha256/8ef66bd1e800bcbedef436585469d308665aaa1ab6011aee699544302d0a8ad0/index.js +312 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/README.en.md +40 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/index.js +348 -0
- package/vendor/components/sha256/a0c71874d83045baaef70285bd00d87a7c6c43219fa5630dfff60d5cb08509be/index.js +250 -0
- package/vendor/components/sha256/a31f39625d7d1087d06a72b644cec417372f98add940288257ef07f812d8395a/index.js +747 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/README.en.md +38 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/index.js +289 -0
- package/vendor/components/sha256/ae06622a328da2a01260bc68b28bb632c391e8d62a4e8387638e5a944525a418/index.js +521 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/README.en.md +24 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/index.js +103 -0
- package/vendor/components/sha256/b756c66d5c6e6ace90912ab467dea3031f2c9b291d8b2a786ca660faa0e8ac84/index.js +121 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/chords.json +89 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/extras.json +192 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ties.json +360 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/index.js +508 -0
- package/vendor/components/sha256/bea7cb344f55677d5756c9711b90cc971126830ec5f66a03f71f13dbfadc401e/index.js +351 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/README.en.md +42 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/index.js +268 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/README.en.md +51 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/index.js +228 -0
- package/vendor/components/sha256/d2df3d70fc7c6e07e3cad7332a7e5501e84abeb24653786e567f57046adebcba/index.js +268 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/README.en.md +35 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/index.js +179 -0
- package/vendor/components/sha256/e6d219f67d241fdf00a40d4cec261d9dd3c09ad3110d3418d4e843d0f2b8c196/index.js +429 -0
- package/vendor/components/sha256/ef60e6c089f5f6e909f439af8fc0c9c0a2d7a1aafad5e65be6328ba993b990a0/index.js +354 -0
- package/vendor/components/sha256/f6f47601c90f0195353e94b76d57499591d6330a7e35714958a2c41229f70da2/index.js +198 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/README.en.md +44 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/index.js +304 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/README.en.md +42 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/index.js +481 -0
- package/vendor/components/sha256/fdcea28e27638d8bfe234016672375e14de8bb97c32f7b6840d1b7b10ac4b1cd/index.js +233 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/LICENSE-strokesvg.txt +115 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/OFL.txt +93 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/index.js +749 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/strokes-CHANGES.md +20 -0
- package/vendor/components-2/manifest-2.7.0.json +2118 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// m-timer:グループワークの進行タイマー。段階 0 は準備の画面、段階 k で phases[k-1] の残り時間を数える(元は雲居玄道が研修の資料のために作った部品)
|
|
2
|
+
// <m-timer style="height:432px"><script type="application/json">
|
|
3
|
+
// {"ready": {"title": "準備の確認", "text": "用紙とペンがそろっているか"},
|
|
4
|
+
// "phases": [{"title": "① 付箋に書く", "short": "付箋に書く", "text": "1 枚に 1 件", "sec": 180}, …]}
|
|
5
|
+
// (JSON の終わり)</m-timer>
|
|
6
|
+
// duration(k) = phases[k-1].sec。実行系は t を実時間で進めるので、時計は (k, t) だけで決まる。→ キー(段階を進める)がスタートの合図
|
|
7
|
+
// 左:題・説明・残り時間の大きな時計・進みの棒。右:区切りの一覧(今の区切りに枠、終わった区切りは --muted)
|
|
8
|
+
// 最後の 1 分は時計と棒が --emph。最後の 10 秒は時計が 1 秒おきに薄くなる(注目のため。動画・動きを減らす設定・最後の状態では止まる)
|
|
9
|
+
// 字は部品の中に書かない:授業の言語(ctx.lang。<html lang> から)で日本語か英語の表を選び、データの labels で上書きできる
|
|
10
|
+
// +1 分・−1 分(仕様 §8.4 ctx.extend、egatari-spec 485ae54):実行系が ctx.extend を渡すときだけボタンを出す。延ばした秒数は見る人の状態で、
|
|
11
|
+
// 同じスライドにいるあいだは残り、ほかのスライドから入ったとき・飛んだとき(ctx.entered)だけ戻る。ctx.reset ではボタンのフォーカスだけを戻す(仕様 §8.4)。動画・印刷は作者の秒数
|
|
12
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog を使い、プレイヤーのグローバルは使わない。
|
|
13
|
+
// 延長を戻すのは ctx.entered だけ(1.x の deck:pos の代わりはない)。日本語かどうかは mount の ctx.lang、動画かどうかは ctx.mode。
|
|
14
|
+
// 要素の大きさの問題は ctx.report("size", …)。印刷の前後は document.defaultView の beforeprint・afterprint
|
|
15
|
+
egatariParts.define({name: "timer", version: "2.0.4", requires: {base: "1.2.0"}, element: "m-timer"}, function(deps){
|
|
16
|
+
"use strict";
|
|
17
|
+
var base = deps.base;
|
|
18
|
+
var CSS_ID = "timer-2-0-4-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
|
|
19
|
+
var JA = {ready: "準備の確認", total: "合計", remaining: "残り", done: "時間", start: "準備ができたら → キーでスタート", next: "終了 → キーで次へ", end: "終了",
|
|
20
|
+
min: "分", sec: "秒", plus: "+1 分", minus: "−1 分"};
|
|
21
|
+
var EN = {ready: "Ready?", total: "Total", remaining: "Remaining", done: "Time's up", start: "When ready, press → to start", next: "Time's up. Press → for the next", end: "Time's up",
|
|
22
|
+
min: " min", sec: " s", plus: "+1 min", minus: "−1 min"};
|
|
23
|
+
var CSS = [
|
|
24
|
+
"m-timer .tm-say{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}",
|
|
25
|
+
"m-timer .tm-ctl{position:absolute;display:flex;gap:12px}",
|
|
26
|
+
"m-timer .tm-btn{min-width:112px;height:52px;padding:0 14px;font:700 27px/1 var(--font-cap,var(--font-sans,sans-serif));color:var(--fg);background:var(--bg);border:2px solid var(--term);border-radius:8px;cursor:pointer;touch-action:manipulation}",
|
|
27
|
+
"m-timer .tm-btn:active{background:var(--term-tint)}",
|
|
28
|
+
"m-timer .tm-btn:focus-visible{outline:3px solid var(--emph);outline-offset:2px}",
|
|
29
|
+
"@media print{m-timer .tm-ctl{display:none!important}}",
|
|
30
|
+
].join("\n");
|
|
31
|
+
return class extends base.MotionElement {
|
|
32
|
+
static partName = "timer"; // the registry name (define meta name), for report prefixes
|
|
33
|
+
static variants = ["fade"];
|
|
34
|
+
static interactive = true; // 操作できるパーツ(docs/conventions.md §6)
|
|
35
|
+
static preview = "none"; // 先の時間は中身ではないので、授業の表示でも先の区切りを見せない(仕様 §8.4、docs/conventions.md §1.2)
|
|
36
|
+
static clock = true; // 経った時間そのものが中身:動きを減らす設定でも実時間の t で描く(仕様 §9.1)
|
|
37
|
+
// 「道具」の組(頼まれたときだけ使う部品)と、新規作成の道具の札(docs/conventions.md §7。tools/release.mjs が manifest に写す。JSON で書く)
|
|
38
|
+
static group = "tool";
|
|
39
|
+
static tile = {"label": {"ja": "タイマー", "en": "Timer"}, "examples": {"ja": "グループワークの時間・残り時間・ベル", "en": "Group-work time, time left, bells"}, "icon": "timer"};
|
|
40
|
+
static viewerInput = true; // 見る人の入力(区切りの時間を延ばす・縮める。仕様 §8.4)
|
|
41
|
+
// データの形(kit/shape.js)
|
|
42
|
+
static shape = {
|
|
43
|
+
schema: {type: "object", additionalProperties: false, required: ["phases"], properties: {
|
|
44
|
+
ready: {type: "object", additionalProperties: false, properties: {title: {type: "string"}, text: {type: "string"}}},
|
|
45
|
+
phases: {type: "array", minItems: 1, maxItems: 8, items: {type: "object", additionalProperties: false, required: ["title", "sec"], properties: {
|
|
46
|
+
title: {type: "string"}, short: {type: "string"}, text: {type: "string"}, sec: {type: "integer"}, bells: {type: "array", maxItems: 6, items: {type: "object", additionalProperties: false, required: ["left"], properties: {left: {type: "integer"}, count: {type: "integer"}}}}}}},
|
|
47
|
+
bells: {type: "array", maxItems: 6, items: {type: "object", additionalProperties: false, required: ["left"], properties: {left: {type: "integer"}, count: {type: "integer"}}}},
|
|
48
|
+
done: {type: "string"},
|
|
49
|
+
labels: {type: "object", additionalProperties: false, properties: {
|
|
50
|
+
ready: {type: "string"}, total: {type: "string"}, remaining: {type: "string"}, done: {type: "string"}, start: {type: "string"},
|
|
51
|
+
next: {type: "string"}, end: {type: "string"}, min: {type: "string"}, sec: {type: "string"}, plus: {type: "string"}, minus: {type: "string"}}}}},
|
|
52
|
+
example: {ready: {title: "準備の確認", text: "用紙とペンがそろっているか"}, phases: [{title: "① 付箋に書く", short: "付箋に書く", sec: 180}, {title: "② 島で選ぶ", short: "島で選ぶ", sec: 300}]},
|
|
53
|
+
note: {en: "phases is a list of {\"title\", \"sec\"} (sec: whole seconds, not \"3分\"); one phase per step",
|
|
54
|
+
ja: "phases は {\"title\", \"sec\"} の並び(sec は秒の整数。\"3分\" のような字ではない)。区切り 1 つが 1 段階"},
|
|
55
|
+
};
|
|
56
|
+
static props = {};
|
|
57
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : ((this.data || {}).phases || []).length; }
|
|
58
|
+
// 字の表(授業の言語 ctx.lang で選ぶ。mount が this.ja を決めてから読む。データの labels が勝つ。古い書き方の "done" も受け付ける)
|
|
59
|
+
get L(){
|
|
60
|
+
if (this._L) return this._L;
|
|
61
|
+
var d = this.data || {}, tbl = this.ja ? JA : EN, o = {};
|
|
62
|
+
for (var k in tbl) o[k] = tbl[k];
|
|
63
|
+
if (typeof d.done === "string") o.done = o.end = d.done;
|
|
64
|
+
var lb = d.labels || {};
|
|
65
|
+
for (var j in lb) o[j] = lb[j];
|
|
66
|
+
return (this._L = o);
|
|
67
|
+
}
|
|
68
|
+
mount(ctx){
|
|
69
|
+
this.ja = /^ja\b/i.test(ctx.lang);
|
|
70
|
+
var self = this, d = this.data || {};
|
|
71
|
+
this.P = d.phases || [];
|
|
72
|
+
if (this.P.some(function(p){ return !(p.sec > 0); })) throw new Error("every phase needs sec > 0 (whole seconds)");
|
|
73
|
+
// 読み上げ:要素は区切りとその時間を名前にした group(中の知らせ role="status" と ±1 分のボタンはそのまま届く)。作者の aria-label があればそれを使う(上書きしない)
|
|
74
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
75
|
+
this.setAttribute("role", "group");
|
|
76
|
+
if (!this._aria) this.setAttribute("aria-label", (this.ja ? "タイマー:" : "Timer: ") + this.P.map(function(p){ return p.title + " " + self.span(p.sec); }).join(this.ja ? "、" : ", "));
|
|
77
|
+
this.video = ctx.mode === "video";
|
|
78
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
79
|
+
if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
|
|
80
|
+
// 読み上げソフトへの知らせ(区切りの始まりと終わりだけ。毎秒は読まない)
|
|
81
|
+
this.say = document.createElement("div"); this.say.className = "tm-say"; this.say.setAttribute("role", "status"); this.say.setAttribute("aria-live", "polite");
|
|
82
|
+
this.appendChild(this.say);
|
|
83
|
+
this._ext = {};
|
|
84
|
+
this.total = this.P.reduce(function(a, p){ return a + p.sec; }, 0);
|
|
85
|
+
// 印刷は作者の秒数で描く(延長は消さない。afterprint で戻す)。beforeprint・afterprint は文書の窓(document.defaultView)に来る
|
|
86
|
+
var view = document.defaultView;
|
|
87
|
+
if (!this.video && view){
|
|
88
|
+
view.addEventListener("beforeprint", function(){ self._printing = true; self.redraw(); });
|
|
89
|
+
view.addEventListener("afterprint", function(){ self._printing = false; self.redraw(); });
|
|
90
|
+
}
|
|
91
|
+
this.place(ctx);
|
|
92
|
+
}
|
|
93
|
+
// 配置が変わった知らせ(仕様 §8.4 layout):要素の大きさが mount のときと変わったときだけ置き直す(変換で縮めるだけなら呼ばれない。
|
|
94
|
+
// 横に並んだ文の字が後から読み込まれて、段組みの中の幅が変わるときなど)。大きさ 0(隠れている)なら前の配置のまま
|
|
95
|
+
layout(ctx){
|
|
96
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
97
|
+
if (!W || !H || (W === this.W && H === this.H)) return;
|
|
98
|
+
this.place(ctx);
|
|
99
|
+
this.redraw();
|
|
100
|
+
}
|
|
101
|
+
// 大きさで決まる絵(svg と区切りの一覧、ボタンの位置)を作る。延長・読み上げの知らせは残す
|
|
102
|
+
place(ctx){
|
|
103
|
+
var self = this, D = base, d = this.data || {}, L = this.L;
|
|
104
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
105
|
+
if (this.svg) this.svg.remove();
|
|
106
|
+
var f = this.f = Math.max(0.6, Math.min(1.2, H / 432, W / 1180)), F = function(z){ return Math.max(24, Math.round(z * f)); };
|
|
107
|
+
var LW = this.LW = W * 0.525, RX = W * 0.576;
|
|
108
|
+
var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"});
|
|
109
|
+
this.insertBefore(svg, this.say);
|
|
110
|
+
// 字の幅(base の textWidth:テーマの字で測った幅)
|
|
111
|
+
var est = this.est = function(s, z){ return D.textWidth(s, z, {font: self}); };
|
|
112
|
+
// 題(長ければ 24 px まで小さく)と説明(2 行まで。幅で折り返す)
|
|
113
|
+
var fit = function(s, max, z, what){
|
|
114
|
+
var y = z; while (y > 24 && est(s, y) > max) y--;
|
|
115
|
+
if (est(s, y) > max) ctx.report("size", "[timer] the " + what + " " + JSON.stringify(s) + " does not fit (" + Math.ceil(est(s, y) - max) + " px too wide); shorten it");
|
|
116
|
+
return y;
|
|
117
|
+
};
|
|
118
|
+
var wrap = function(s, max, z, what){
|
|
119
|
+
var out = [];
|
|
120
|
+
String(s || "").split("\n").forEach(function(line){
|
|
121
|
+
var cur = "";
|
|
122
|
+
[...line].forEach(function(c){ if (cur && est(cur + c, z) > max){ out.push(cur); cur = ""; } cur += c; });
|
|
123
|
+
out.push(cur);
|
|
124
|
+
});
|
|
125
|
+
if (out.length > 2) ctx.report("size", "[timer] the text of " + what + " needs " + out.length + " lines (2 fit); shorten it");
|
|
126
|
+
return out.slice(0, 2);
|
|
127
|
+
};
|
|
128
|
+
var heads = [d.ready || {}].concat(this.P);
|
|
129
|
+
this.heads = heads.map(function(h, j){
|
|
130
|
+
var title = h.title || (j === 0 ? L.ready : "");
|
|
131
|
+
return {title: title, size: fit(title, LW, F(44), j ? "title of phase " + j : "ready title"), lines: wrap(h.text, LW, F(30), j ? "phase " + j : "ready")};
|
|
132
|
+
});
|
|
133
|
+
this.ttl = D.el("text", {x: 0, y: 46 * f, "font-weight": 700}, svg);
|
|
134
|
+
this.l1 = D.el("text", {x: 0, y: 96 * f, "font-size": F(30), fill: "var(--fg)"}, svg);
|
|
135
|
+
this.l2 = D.el("text", {x: 0, y: 136 * f, "font-size": F(30), fill: "var(--fg)"}, svg);
|
|
136
|
+
this.lab = D.el("text", {x: 0, y: 190 * f, "font-size": F(26), fill: "var(--muted)"}, svg);
|
|
137
|
+
// 時計:「00:00」が左の幅に収まる大きさ。字の上端が「残り」の字に重ならないように下げる
|
|
138
|
+
var cz = Math.min(150 * f, LW / 3.0), cy = 190 * f + 14 + cz * 0.98, by = cy + 18 * f;
|
|
139
|
+
this.clock = D.el("text", {x: 0, y: cy.toFixed(1), "font-size": cz.toFixed(0), "font-weight": 700, style: "font-variant-numeric:tabular-nums"}, svg);
|
|
140
|
+
D.el("rect", {x: 0, y: by.toFixed(1), width: LW, height: 20 * f, rx: 10 * f, fill: "var(--line)"}, svg);
|
|
141
|
+
this.bar = D.el("rect", {x: 0, y: by.toFixed(1), width: 0, height: 20 * f, rx: 10 * f}, svg);
|
|
142
|
+
if (by + 20 * f > H - 40 * f) ctx.report("size", "[timer] the element is too low for the clock, the bar and the line under it (make it taller)");
|
|
143
|
+
this.foot = D.el("text", {x: 0, y: H - 4, "font-size": F(32), "font-weight": 700, fill: "var(--emph)"}, svg);
|
|
144
|
+
// 区切りの一覧
|
|
145
|
+
var n = this.P.length, top = 180 * f, rh = Math.min(48 * f, (H - top) / Math.max(n, 1));
|
|
146
|
+
if (rh < 34) ctx.report("size", "[timer] " + n + " phases do not fit in the list (make the element taller or use fewer phases)");
|
|
147
|
+
this.rows = this.P.map(function(p, j){
|
|
148
|
+
var y = top + j * rh, s = (j + 1) + (self.ja ? " " : " ") + self.span(p.sec) + (self.ja ? " " : " ") + (p.short || p.title);
|
|
149
|
+
var box = D.el("rect", {x: RX, y: y, width: W - RX, height: rh - 6, rx: 8, fill: "none", stroke: "none", "stroke-width": 2.5}, svg);
|
|
150
|
+
var tx = D.el("text", {x: RX + 14, y: y + rh / 2 + 7, "font-size": fit(s, W - RX - 28, F(28), "phase list entry")}, svg);
|
|
151
|
+
tx.textContent = s;
|
|
152
|
+
return {box: box, tx: tx};
|
|
153
|
+
});
|
|
154
|
+
this.RX = RX; this.W = W; this.H = H;
|
|
155
|
+
if (this.btns) Object.assign(this.btns.style, {left: RX + "px", top: Math.round(96 * f - 34) + "px"});
|
|
156
|
+
}
|
|
157
|
+
// 秒数の書き方:「3分」「20秒」「1分30秒」(英語は 3 min・20 s)
|
|
158
|
+
span(s){
|
|
159
|
+
var L = this.L, m = Math.floor(s / 60), r = s % 60;
|
|
160
|
+
return s < 60 ? s + L.sec : r === 0 ? m + L.min : m + L.min + (this.ja ? "" : " ") + r + L.sec;
|
|
161
|
+
}
|
|
162
|
+
clockText(s){ s = Math.max(0, Math.ceil(s - 1e-9)); return Math.floor(s / 60) + ":" + ("0" + (s % 60)).slice(-2); }
|
|
163
|
+
duration(k){ return k >= 1 && this.P[k - 1] ? this.P[k - 1].sec : 0; }
|
|
164
|
+
// 学会タイマーのようなベル(仕様 §8.4「Component sounds」):部品は音を鳴らさず、鳴らす時刻を宣言するだけ。鳴らすのは再生器
|
|
165
|
+
// (発表の再生で t が前へ越えたときだけ、Web Audio で合成。動画には同じ時刻で入る。延長は再生器がずらす)。
|
|
166
|
+
// bells は区切りの bells か、全体の bells:[{left: 残りの秒, count: 1〜3}]。書かなければ鳴らない。音だけに頼らず、時計と色でも示す
|
|
167
|
+
events(k){
|
|
168
|
+
var p = k >= 1 && this.P[k - 1];
|
|
169
|
+
if (!p) return [];
|
|
170
|
+
var bells = (p.bells || (this.data && this.data.bells) || []);
|
|
171
|
+
return bells.filter(function(b){ return b.left >= 0 && b.left <= p.sec; })
|
|
172
|
+
.map(function(b){ return {t: p.sec - b.left, sound: "bell", count: Math.max(1, Math.min(3, b.count || 1))}; })
|
|
173
|
+
.sort(function(a, b){ return a.t - b.t; });
|
|
174
|
+
}
|
|
175
|
+
// ---- 見る人の状態:区切りごとに延ばした秒数(−sec より短くはしない)
|
|
176
|
+
ext(k){ return this.video || this._printing ? 0 : this._ext[k] || 0; }
|
|
177
|
+
extend(dl){
|
|
178
|
+
var ctx = this._ctx, k = this._k;
|
|
179
|
+
if (this.video || !ctx || typeof ctx.extend !== "function" || !(k >= 1)) return;
|
|
180
|
+
var sec = this.P[k - 1].sec, cur = this._ext[k] || 0, el = this._t === Infinity ? sec + cur : Math.min(this._t || 0, sec + cur);
|
|
181
|
+
// 縮めるのは今の時刻まで(0:00 で終わる)。延ばすのは 1 時間まで
|
|
182
|
+
var next = Math.max(cur + dl, el - sec, -sec);
|
|
183
|
+
next = Math.min(next, 3600);
|
|
184
|
+
if (next === cur) return;
|
|
185
|
+
var r = ctx.extend(next - cur);
|
|
186
|
+
this._ext[k] = typeof r === "number" && isFinite(r) ? r : next;
|
|
187
|
+
this.redraw();
|
|
188
|
+
this.say.textContent = this.L.remaining + " " + this.clockText(sec + this._ext[k] - Math.min(el, sec + this._ext[k]));
|
|
189
|
+
this.dispatchEvent(new CustomEvent("egatari-input", {bubbles: true, detail: {step: k, extend: this._ext[k]}}));
|
|
190
|
+
}
|
|
191
|
+
reset(){
|
|
192
|
+
var had = Object.keys(this._ext).some(function(k){ return this._ext[k]; }, this);
|
|
193
|
+
this._ext = {};
|
|
194
|
+
if (had) this.dispatchEvent(new CustomEvent("egatari-input", {bubbles: true, detail: {step: this._k, extend: 0}}));
|
|
195
|
+
return had;
|
|
196
|
+
}
|
|
197
|
+
// 触った跡だけを戻す(ctx.reset):ボタンのフォーカスを外す。延長(見る人の入力)は残す
|
|
198
|
+
untouch(){
|
|
199
|
+
var a = document.activeElement;
|
|
200
|
+
if (a && a !== this && this.contains(a) && a.blur) a.blur();
|
|
201
|
+
}
|
|
202
|
+
// 入力のあとの描き直し:最後の (k, t) で paint だけを呼ぶ(render を通さないので、ctx.entered・ctx.reset を繰り返さない)
|
|
203
|
+
redraw(){ if (this._k !== undefined) this.paint(this._k, this._t, this._ctx); }
|
|
204
|
+
// +1 分・−1 分:実行系が ctx.extend を渡したときに初めて作る(渡さない実行系・動画では作らない)
|
|
205
|
+
buttons(){
|
|
206
|
+
if (this.btns || this.video) return;
|
|
207
|
+
var self = this, L = this.L, box = this.btns = document.createElement("div");
|
|
208
|
+
box.className = "tm-ctl";
|
|
209
|
+
Object.assign(box.style, {left: this.RX + "px", top: Math.round(96 * this.f - 34) + "px"});
|
|
210
|
+
[[L.minus, -60], [L.plus, 60]].forEach(function(b){
|
|
211
|
+
var e = document.createElement("button");
|
|
212
|
+
e.type = "button"; e.className = "tm-btn"; e.textContent = b[0]; e.setAttribute("aria-label", b[0]);
|
|
213
|
+
e.addEventListener("click", function(ev){ ev.stopPropagation(); self.extend(b[1]); if (ev.detail !== 0) e.blur(); });
|
|
214
|
+
e.addEventListener("keydown", function(ev){
|
|
215
|
+
var up = ev.key === "+", dn = ev.key === "-" || ev.key === "−";
|
|
216
|
+
if (up || dn){ ev.preventDefault(); ev.stopPropagation(); self.extend(up ? 60 : -60); }
|
|
217
|
+
});
|
|
218
|
+
box.appendChild(e);
|
|
219
|
+
});
|
|
220
|
+
this.appendChild(box);
|
|
221
|
+
}
|
|
222
|
+
render(k, t, ctx){
|
|
223
|
+
if (ctx.entered === true) this.reset();
|
|
224
|
+
if (ctx.reset) this.untouch();
|
|
225
|
+
// 描き直し(redraw)で reset・entered をもう一度使わないように、それを除いて覚える(extend などはそのまま)
|
|
226
|
+
this._k = k; this._t = t; this._ctx = Object.assign({}, ctx); delete this._ctx.reset; delete this._ctx.entered;
|
|
227
|
+
this.paint(k, t, this._ctx);
|
|
228
|
+
}
|
|
229
|
+
// (k, t) と延長の絵。ctx は render の ctx から reset・entered を除いたもの
|
|
230
|
+
paint(k, t, ctx){
|
|
231
|
+
var D = base, L = this.L, P = this.P, n = P.length, run = k >= 1 && P[k - 1];
|
|
232
|
+
var hasExt = !this.video && ctx && typeof ctx.extend === "function";
|
|
233
|
+
if (hasExt) this.buttons();
|
|
234
|
+
if (this.btns) this.btns.style.display = hasExt && run ? "" : "none";
|
|
235
|
+
// 延ばした合計は実行系が持つ(ctx.extend(0) は変えずに読むだけ。仕様 §8.4)。発表者の画面で延ばした分もこれでそろう
|
|
236
|
+
if (hasExt && run){ var r0 = ctx.extend(0); if (typeof r0 === "number" && isFinite(r0)) this._ext[k] = r0; }
|
|
237
|
+
var sec = run ? P[k - 1].sec : 0, end = sec + (run ? this.ext(k) : 0);
|
|
238
|
+
var el = !run ? 0 : t === Infinity ? end : Math.min(Math.max(0, t), end);
|
|
239
|
+
var rem = run ? end - el : this.total, finished = run && el >= end, warn = run && rem <= 60;
|
|
240
|
+
// fade(見せ方 0):区切りが始まると、題・説明・時計がフェードして現れる
|
|
241
|
+
var a = run && t !== Infinity ? D.prog(t, 0, 0.4) : 1;
|
|
242
|
+
var h = this.heads[run ? k : 0];
|
|
243
|
+
this.ttl.textContent = h.title; this.ttl.setAttribute("font-size", h.size);
|
|
244
|
+
this.ttl.style.fill = run ? "var(--term)" : "var(--emph)";
|
|
245
|
+
this.l1.textContent = h.lines[0] || ""; this.l2.textContent = h.lines[1] || "";
|
|
246
|
+
[this.ttl, this.l1, this.l2].forEach(function(e){ e.setAttribute("opacity", a.toFixed(3)); });
|
|
247
|
+
this.lab.textContent = !run ? L.total : finished ? L.done : L.remaining;
|
|
248
|
+
this.clock.textContent = this.clockText(rem);
|
|
249
|
+
this.clock.style.fill = !run ? "var(--muted)" : warn || finished ? "var(--emph)" : "var(--fg)";
|
|
250
|
+
// 最後の 10 秒は 1 秒おきに薄く(注目のため。動画・最後の状態では止まる。動きを減らす設定では実行系が最後の状態で描く)
|
|
251
|
+
var pulse = run && !finished && rem <= 10 && t !== Infinity && !this.video && Math.floor(t) % 2 === 1;
|
|
252
|
+
this.clock.setAttribute("opacity", (pulse ? 0.45 : a).toFixed(3));
|
|
253
|
+
this.bar.setAttribute("width", (this.LW * (run ? el / end : 0)).toFixed(1));
|
|
254
|
+
this.bar.style.fill = warn || finished ? "var(--emph)" : "var(--term)";
|
|
255
|
+
this.foot.textContent = !run ? L.start : finished ? (k < n ? L.next : L.end) : "";
|
|
256
|
+
this.rows.forEach(function(r, j){
|
|
257
|
+
var cur = run && j + 1 === k, done = run && j + 1 < k;
|
|
258
|
+
r.box.style.fill = cur ? "var(--term-tint)" : "none";
|
|
259
|
+
r.box.style.stroke = cur ? "var(--term)" : "none";
|
|
260
|
+
// 終わった区切りは --muted(薄くしても 4.5:1 は保つので、透明にはしない)
|
|
261
|
+
r.tx.style.fill = done ? "var(--muted)" : "var(--fg)";
|
|
262
|
+
r.tx.setAttribute("font-weight", cur ? "700" : "400");
|
|
263
|
+
});
|
|
264
|
+
var s = !run ? "" : finished ? h.title + (this.ja ? ":" : ": ") + L.done : h.title;
|
|
265
|
+
if (this._said !== s && !this.video){ this._said = s; this.say.textContent = s; }
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: KPI cards by step; count-up, change arrow, note
|
|
3
|
+
steps: largest card step (default 1 card = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
cols: cards per row (0 = count, ≤ 4)
|
|
6
|
+
digits: decimals (card wins)
|
|
7
|
+
per-step: cards per step (0 = all)
|
|
8
|
+
dur: count seconds
|
|
9
|
+
stagger: card offset (s)
|
|
10
|
+
count: count up
|
|
11
|
+
size: number px (0 = auto)
|
|
12
|
+
example: {"cards": [{"label": "Drafting time", "value": 62, "unit": "%", "prefix": "−", "delta": {"dir": "down", "text": "8 pt vs last", "good": true}}]}
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Child JSON: `{"cards": [{"label", "value", "digits", "unit", "prefix", "from", "tone", "delta", "note", "step", "at"}, …]}`.
|
|
16
|
+
|
|
17
|
+
- `label`: above. `value` (`digits`, commas). `unit`: after. `prefix`: before (`+`, `~`). Negative `value` has its own −: no `prefix` `−` (−−12); `prefix: "−"` only with a positive decrease
|
|
18
|
+
- `from`: count start (default 0; may count down)
|
|
19
|
+
- `tone`: number, top band (`term`, `emph`, `accent2`, `series-1..4`)
|
|
20
|
+
- `delta`: `{"dir": "up" | "down", "text": "+4", "good": true}`: ▲/▼ + text; good (default `up`) `--term`, bad `--emph`
|
|
21
|
+
- `note`: bottom line
|
|
22
|
+
<!-- llm: omit -->
|
|
23
|
+
- Count-up eases out; depends on (k, t) only (t = Infinity = final). `count="false"`: no counting
|
|
24
|
+
<!-- llm: end -->
|
|
25
|
+
- `variant`: `count` (default), `rise`, `flip`, `underline`; `count="false"` → `rise`
|
|
26
|
+
- `cues(k)`: start times of 2nd+ cards in a step (for `{cue}`)
|
|
27
|
+
|
|
28
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
29
|
+
|
|
30
|
+
<!-- llm: omit -->
|
|
31
|
+
Notes
|
|
32
|
+
|
|
33
|
+
- `rise`: final value grows in; `flip`: digits flip from the right. Cards wrap past `cols`
|
|
34
|
+
- Number and unit width estimated from characters and centred; the right edge stays put while counting; may be off by a few characters
|
|
35
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// m-kpi:大きな数字の札(KPI)を段階ごとに出す。数字は 0(か from)から数え上げ、下に増減の矢印と一言
|
|
2
|
+
// <m-kpi style="height:300px"><script type="application/json">
|
|
3
|
+
// {"cards": [{"label": "作成時間", "value": 62, "unit": "%", "prefix": "−", "delta": {"dir": "down", "text": "前の版から 8 pt", "good": true}, "note": "1 本あたり"}]}
|
|
4
|
+
// (JSON の終わり)</m-kpi>
|
|
5
|
+
// 段階:既定は札 1 枚 = 1 段階(per-step で n 枚ずつ、札の step で直接、at で段階の中の開始秒)
|
|
6
|
+
// 数え上げは (k, t) だけで決まる(初めに速く、終わりにゆっくり。t = Infinity なら最後の値)。count="false" で数えずに出す
|
|
7
|
+
// 札の幅は cols(既定は札の数、4 まで)で決める。数字と単位の幅は字数から見積もって中央にそろえる(字の読み込みを待たない)
|
|
8
|
+
// 見せ方(docs/conventions.md §1):count(数え上げ、既定)・rise(最後の値のまま少し小さい大きさから戻る)・flip(右の桁から 1 桁ずつ
|
|
9
|
+
// めくれて止まる)・underline(出たあと数字の下に線を引く)。段階の数・長さ・合図・最後の中身はどれも同じ
|
|
10
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・clamp・variant・previewOpacity を使い、プレイヤーのグローバルは使わない
|
|
11
|
+
egatariParts.define({name: "kpi", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-kpi"}, function(deps){
|
|
12
|
+
"use strict";
|
|
13
|
+
var base = deps.base;
|
|
14
|
+
return class extends base.MotionElement {
|
|
15
|
+
static partName = "kpi"; // the registry name (define meta name), for report prefixes
|
|
16
|
+
static variants = ["count", "rise", "flip", "underline"];
|
|
17
|
+
// データの形(kit/shape.js)
|
|
18
|
+
static shape = {
|
|
19
|
+
schema: {type: "object", additionalProperties: false, required: ["cards"], properties: {
|
|
20
|
+
cards: {type: "array", minItems: 1, items: {type: "object", required: ["value"], properties: {
|
|
21
|
+
label: {type: "string"}, value: {type: "number"}, digits: {type: "integer"}, unit: {type: "string"}, prefix: {type: "string"}, from: {type: "number"}, tone: {type: "string"},
|
|
22
|
+
delta: {type: "object", properties: {dir: {enum: ["up", "down"]}, text: {type: "string"}, good: {type: "boolean"}}}, note: {type: "string"}, step: {type: "integer"}, at: {type: "number"}}}}}},
|
|
23
|
+
example: {cards: [{label: "作成時間", value: 62, unit: "%", prefix: "−", delta: {dir: "down", text: "前の版から 8 pt", good: true}}]},
|
|
24
|
+
};
|
|
25
|
+
static props = {
|
|
26
|
+
cols: {type: "number", default: 0, doc: "1 行の札の数(0 = 札の数、4 まで)"},
|
|
27
|
+
digits: {type: "number", default: 0, doc: "数字の小数桁(札の digits が優先)"},
|
|
28
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップに出す札の数(0 = 全部をステップ 1 で)"},
|
|
29
|
+
dur: {type: "number", default: 1.2, doc: "数え上げの秒数"},
|
|
30
|
+
stagger: {type: "number", default: 0.3, doc: "同じステップの札の出だしのずれ(秒)"},
|
|
31
|
+
count: {type: "bool", default: true, doc: "数字を数え上げる"},
|
|
32
|
+
size: {type: "number", default: 0, doc: "数字の字の大きさ(px。0 = 札の高さから)"},
|
|
33
|
+
};
|
|
34
|
+
get steps(){
|
|
35
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
36
|
+
var m = 0;
|
|
37
|
+
this.plan().forEach(function(o){ m = Math.max(m, o.step); });
|
|
38
|
+
return m;
|
|
39
|
+
}
|
|
40
|
+
plan(){
|
|
41
|
+
if (this._plan) return this._plan;
|
|
42
|
+
var P = this.props, per = P["per-step"], seen = {};
|
|
43
|
+
return (this._plan = ((this.data || {}).cards || []).map(function(c, i){
|
|
44
|
+
var step = c.step !== undefined ? c.step : per > 0 ? Math.floor(i / per) + 1 : 1;
|
|
45
|
+
var j = seen[step] = (seen[step] || 0) + 1;
|
|
46
|
+
return {c: c, step: step, at: c.at !== undefined ? c.at : +((j - 1) * P.stagger).toFixed(3)};
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
mount(ctx){
|
|
50
|
+
var P = this.props, D = base, self = this, pl = this.plan();
|
|
51
|
+
var vr = this.variant = base.variant(this);
|
|
52
|
+
// count="false"(数えない)が見せ方より強い:数える見せ方なら rise にする
|
|
53
|
+
if (!P.count && (vr === "count" || vr === "flip")){
|
|
54
|
+
console.info('[kpi] count="false", so the variant "' + vr + '" is shown as "rise"');
|
|
55
|
+
vr = this.variant = "rise";
|
|
56
|
+
}
|
|
57
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
58
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
59
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
60
|
+
// 読み上げ:最後の形(札ごとの名前・最後の値・増減・一言)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
61
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
62
|
+
this.setAttribute("role", "img");
|
|
63
|
+
if (!this._aria){
|
|
64
|
+
var ja = /^ja\b/i.test(ctx.lang || "ja");
|
|
65
|
+
this.setAttribute("aria-label", pl.map(function(o){
|
|
66
|
+
var c = o.c, dg = c.digits !== undefined ? c.digits : P.digits;
|
|
67
|
+
var more = [c.delta ? (c.delta.dir === "down" ? "↓ " : "↑ ") + (c.delta.text || "") : "", c.note || ""].filter(function(x){ return x.trim(); });
|
|
68
|
+
return (c.label ? c.label + " " : "") + (c.prefix || "") + self.fmt(c.value, dg) + (c.unit || "") + (more.length ? (ja ? "(" + more.join("、") + ")" : " (" + more.join(", ") + ")") : "");
|
|
69
|
+
}).join(ja ? "、" : "; "));
|
|
70
|
+
}
|
|
71
|
+
var n = pl.length || 1, cols = P.cols || Math.min(4, n), rows = Math.ceil(n / cols), gap = 28;
|
|
72
|
+
var cw = (W - gap * (cols - 1)) / cols, ch = (H - gap * (rows - 1)) / rows;
|
|
73
|
+
var size = P.size || Math.max(48, Math.min(84, ch * 0.3, cw * 0.24));
|
|
74
|
+
// 字の幅(base の textWidth:テーマの字で測った幅。mk:mtext で書く字で、*_^ は数えない)
|
|
75
|
+
var est = function(s, sz, mk){ return D.textWidth(s, sz, {font: self, mark: !!mk}); };
|
|
76
|
+
this.cards = pl.map(function(o, i){
|
|
77
|
+
var c = o.c, x = (i % cols) * (cw + gap), y = Math.floor(i / cols) * (ch + gap), cx = x + cw / 2;
|
|
78
|
+
var col = "var(--" + (/^(term|emph|accent2|series-[1-4])$/.test(c.tone || "") ? c.tone : "term") + ")";
|
|
79
|
+
var g = D.el("g", {opacity: 0}, svg);
|
|
80
|
+
D.el("rect", {x: x, y: y, width: cw, height: ch, rx: 12, fill: "var(--term-tint)"}, g);
|
|
81
|
+
D.el("rect", {x: x, y: y, width: cw, height: 7, rx: 3, fill: col}, g);
|
|
82
|
+
// 行の位置:名前・数字・増減・一言を札の高さに配る
|
|
83
|
+
var hasD = !!c.delta, hasN = !!c.note;
|
|
84
|
+
var yl = y + 26 + 26, yn = y + ch * (hasD || hasN ? 0.5 : 0.6) + size * 0.36;
|
|
85
|
+
D.mtext(g, cx, yl, c.label || "", {"text-anchor": "middle", "font-size": 26, "font-weight": 700});
|
|
86
|
+
var dg = c.digits !== undefined ? c.digits : P.digits, usz = Math.round(size * 0.46);
|
|
87
|
+
var finalS = (c.prefix || "") + self.fmt(c.value, dg);
|
|
88
|
+
var nw = est(finalS, size), uw = c.unit ? est(c.unit, usz) + 6 : 0, xr = cx - (nw + uw) / 2 + nw;
|
|
89
|
+
var gn = D.el("g", {}, g); // 数字と単位(rise はこれを拡大する)
|
|
90
|
+
var num = D.el("text", {x: xr.toFixed(1), y: yn.toFixed(1), "text-anchor": "end", "font-size": size, "font-weight": 700, fill: col, style: "font-variant-numeric:tabular-nums"}, gn);
|
|
91
|
+
if (c.unit){ var u = D.el("text", {x: (xr + 6).toFixed(1), y: yn.toFixed(1), "font-size": usz, "font-weight": 700, fill: col}, gn); u.textContent = c.unit; }
|
|
92
|
+
// flip:字ごとの tspan(桁だけがめくれる。y でなく dy で前の字との差を書く:y を書くと字の塊が分かれて右寄せが崩れる)
|
|
93
|
+
var digits = null;
|
|
94
|
+
if (vr === "flip"){
|
|
95
|
+
digits = [...finalS].map(function(ch){
|
|
96
|
+
var ts = D.el("tspan", {}, num); ts.textContent = ch;
|
|
97
|
+
return {ts: ts, d: /[0-9]/.test(ch) ? +ch : null};
|
|
98
|
+
});
|
|
99
|
+
var nd = digits.filter(function(o){ return o.d !== null; }).length, j = 0;
|
|
100
|
+
for (var q = digits.length - 1; q >= 0; q--) if (digits[q].d !== null) digits[q].j = j++, digits[q].n = nd;
|
|
101
|
+
}
|
|
102
|
+
var line = vr === "underline" ? D.el("line", {x1: (xr - nw).toFixed(1), x2: (xr - nw).toFixed(1), y1: (yn + size * 0.14).toFixed(1), y2: (yn + size * 0.14).toFixed(1), stroke: "var(--term)", "stroke-width": 5, "stroke-linecap": "round"}, g) : null;
|
|
103
|
+
var gd = null;
|
|
104
|
+
if (hasD){
|
|
105
|
+
// 増減:▲ / ▼ と一言。良い向き(good、既定は up)なら --term、悪い向きなら --emph
|
|
106
|
+
var up = c.delta.dir !== "down", good = c.delta.good !== undefined ? !!c.delta.good : up;
|
|
107
|
+
var dc = good ? "var(--term)" : "var(--emph)", yd = yn + Math.max(44, size * 0.62), tw = est(c.delta.text || "", 24, true) + 30;
|
|
108
|
+
gd = D.el("g", {opacity: 0}, g);
|
|
109
|
+
var tx = cx - tw / 2;
|
|
110
|
+
D.el("path", {d: up ? "M0,-9L9,7L-9,7Z" : "M0,9L9,-7L-9,-7Z", fill: dc, transform: "translate(" + (tx + 9).toFixed(1) + " " + (yd - 8).toFixed(1) + ")"}, gd);
|
|
111
|
+
D.mtext(gd, tx + 30, yd, c.delta.text || "", {"font-size": 24, fill: dc, "font-weight": 700});
|
|
112
|
+
}
|
|
113
|
+
var note = hasN ? D.mtext(g, cx, y + ch - 22, c.note, {"text-anchor": "middle", "font-size": 24, fill: "var(--muted)"}) : null;
|
|
114
|
+
return {o: o, g: g, gn: gn, num: num, gd: gd, dg: dg, from: c.from || 0, cx: cx, cy: y + ch / 2, xn: xr - nw / 2 + uw / 2, yn: yn, size: size, digits: digits, line: line, lx: xr - nw, lw: nw + uw};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
fmt(v, dg){
|
|
118
|
+
var s = Math.abs(v).toFixed(dg).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
119
|
+
return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "");
|
|
120
|
+
}
|
|
121
|
+
duration(k){
|
|
122
|
+
var P = this.props, d = 0;
|
|
123
|
+
this.plan().forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + (P.count ? P.dur : 0.45) + (o.c.delta ? 0.4 : 0)); });
|
|
124
|
+
return d;
|
|
125
|
+
}
|
|
126
|
+
cues(k){
|
|
127
|
+
var c = [];
|
|
128
|
+
this.plan().forEach(function(o){ if (o.step === k && o.at > 0) c.push(o.at); });
|
|
129
|
+
return c.length ? c.sort(function(a, b){ return a - b; }) : null;
|
|
130
|
+
}
|
|
131
|
+
render(k, t, ctx){
|
|
132
|
+
var P = this.props, D = base, self = this;
|
|
133
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の札を最後の値で、テーマの --preview-opacity の濃さに(動かさない)
|
|
134
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
135
|
+
this.cards.forEach(function(o){
|
|
136
|
+
var s = o.o.step, at = o.o.at, ahead = preview && s > k;
|
|
137
|
+
var tt = s < k || ahead ? Infinity : s > k ? -1 : t; // この札の段階の中の時刻(-1 = まだ)
|
|
138
|
+
var e = tt < 0 ? 0 : D.prog(tt, at, 0.45);
|
|
139
|
+
o.g.setAttribute("opacity", ahead ? PV.toFixed(3) : e.toFixed(3));
|
|
140
|
+
o.g.setAttribute("transform", "translate(0 " + ((1 - e) * 14).toFixed(2) + ")");
|
|
141
|
+
var vr = self.variant, span = P.count ? P.dur : 0.45;
|
|
142
|
+
if (vr === "count"){
|
|
143
|
+
// 数え上げ:ease-out(初めに速く)。t = Infinity なら最後の値
|
|
144
|
+
var c = tt < 0 ? 0 : tt === Infinity || !P.count ? 1 : D.clamp((tt - at) / P.dur);
|
|
145
|
+
var q = 1 - Math.pow(1 - c, 3), v = D.lerp(o.from, o.o.c.value, q);
|
|
146
|
+
o.num.textContent = (o.o.c.prefix || "") + self.fmt(c >= 1 ? o.o.c.value : v, o.dg);
|
|
147
|
+
} else if (vr === "rise"){
|
|
148
|
+
// 最後の値のまま、0.85 倍から元の大きさへ(札が現れるのと同じ 0.45 秒)
|
|
149
|
+
var s = 0.85 + 0.15 * (tt < 0 ? 0 : D.prog(tt, at, 0.45)), cx = o.xn, cy = o.yn - o.size * 0.35;
|
|
150
|
+
o.num.textContent = (o.o.c.prefix || "") + self.fmt(o.o.c.value, o.dg);
|
|
151
|
+
o.gn.setAttribute("transform", s >= 1 ? "" : "translate(" + cx.toFixed(1) + " " + cy.toFixed(1) + ") scale(" + s.toFixed(4) + ") translate(" + (-cx).toFixed(1) + " " + (-cy).toFixed(1) + ")");
|
|
152
|
+
} else if (vr === "flip"){
|
|
153
|
+
// 札が出たあと(0.45 秒)、右の桁から 1 桁ずつ 0 → 最後の数字へめくれて、上から定位置に止まる(段階の長さの中で終わる)
|
|
154
|
+
var t0 = at + 0.45, len = Math.max(0.1, span - 0.45), prev = 0;
|
|
155
|
+
o.digits.forEach(function(d){
|
|
156
|
+
var off = 0;
|
|
157
|
+
if (d.d !== null){
|
|
158
|
+
var w = len / (d.n + 1), st = t0 + d.j * w, e = tt < 0 ? 0 : tt === Infinity ? 1 : D.clamp((tt - st) / (2 * w));
|
|
159
|
+
var shown = e >= 1 ? d.d : Math.min(d.d, Math.floor(e * (d.d + 1))), frac = (e * (d.d + 1)) % 1;
|
|
160
|
+
d.ts.textContent = String(shown);
|
|
161
|
+
// めくれる桁は上から少し(字の 0.12)下りて止まる
|
|
162
|
+
off = e > 0 && e < 1 ? -(1 - D.prog(frac, 0, 1)) * o.size * 0.12 : 0;
|
|
163
|
+
}
|
|
164
|
+
d.ts.setAttribute("dy", (off - prev).toFixed(1));
|
|
165
|
+
prev = off;
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
// underline:最後の値で出て、数字の下に左から右へ線を引く
|
|
169
|
+
o.num.textContent = (o.o.c.prefix || "") + self.fmt(o.o.c.value, o.dg);
|
|
170
|
+
// 線は段階の長さの中で引き終える(count="false" なら段階は 0.45 秒なので、後半の半分で引く)
|
|
171
|
+
var u0 = Math.min(0.45, span * 0.5), u = tt < 0 ? 0 : D.prog(tt, at + u0, span - u0);
|
|
172
|
+
o.line.setAttribute("x2", (o.lx + o.lw * u).toFixed(1));
|
|
173
|
+
o.line.setAttribute("opacity", u > 0 ? 1 : 0);
|
|
174
|
+
}
|
|
175
|
+
if (o.gd) o.gd.setAttribute("opacity", (tt < 0 ? 0 : D.prog(tt, at + (P.count ? P.dur : 0.45) * 0.85, 0.4)).toFixed(3));
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
});
|