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,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Grid of slide-link cards (contents); plain <a href="#<slide id>">; visited mark
|
|
3
|
+
steps: ceil(cards / per-step) (per-step="0": 0)
|
|
4
|
+
props:
|
|
5
|
+
cols: columns (0 = auto)
|
|
6
|
+
per-step: cards per step (0 = all, no steps)
|
|
7
|
+
size: title px
|
|
8
|
+
fade: appear (s)
|
|
9
|
+
stagger: card offset (s)
|
|
10
|
+
visited: mark visited cards
|
|
11
|
+
example: "<a href=\"#s-abc123\" data-sub=\"Subtitle\">Title</a>"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Contents; choosing where to start.
|
|
15
|
+
<!-- llm: omit -->
|
|
16
|
+
Cards are plain child links; the part only styles them (grid, circle, subtitle, mark). Clicks are handled by the runtime (`kit/deck.js`)
|
|
17
|
+
([format spec §9.1A](https://github.com/egatari/egatari-spec/blob/main/egatari-1.0.md#91a-links-to-slides), `docs/contract.md` §9).
|
|
18
|
+
|
|
19
|
+
<!-- llm: end -->
|
|
20
|
+
```html
|
|
21
|
+
<m-menu cols="3" aria-label="Today">
|
|
22
|
+
<a href="#s-njd4kp" data-icon="1" data-sub="Poet">Poem A</a>
|
|
23
|
+
<a href="#s-uhqygr:2" data-icon="2" data-sub="Order">Poem B</a>
|
|
24
|
+
<a href="lesson2.ega.html" data-sub="Next">Drill</a>
|
|
25
|
+
</m-menu>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- One child `<a href>` = one card. `href`: `#<slide id>` (step 0) or `#<id>:<step>` (`0`, `1`, … `concl`); ids from `npm run ids`; content = title
|
|
29
|
+
- `data-icon`: circle text (`1`, `A`). `data-sub`: subtitle
|
|
30
|
+
<!-- llm: omit -->
|
|
31
|
+
- Links to other files (`other.ega.html#s-…`): plain links, "other file" mark bottom right; not bundled into the single .ega.html
|
|
32
|
+
- Click: presenting = that step's final state; autoplay continues from there. "Back" top left (Backspace, Alt+←, browser back)
|
|
33
|
+
- Visited mark: ✓ top right once the target slide was opened this session (not saved; not in video or print).
|
|
34
|
+
Viewer-side state outside (i, k, t) (like `m-kobun` cards). `visited="false"` disables
|
|
35
|
+
<!-- llm: end -->
|
|
36
|
+
- `per-step="n"`: n cards per step (from `data-from`); unshown cards inert. `0` = all at once
|
|
37
|
+
- `cols` default: ≤ 3 cards 1 row, 4 → 2, more → 3. Min height `--mm-h` (104px), gap `--mm-gap` (18px). Fill, centred: `style="height:100%;align-content:center;--mm-h:150px"`
|
|
38
|
+
<!-- llm: omit -->
|
|
39
|
+
- Text: title `size` (34px), subtitle 0.8× (≥ 27px body minimum). Circle `--term`, subtitle `--muted`. `stagger` within a step; depends on (k, t) only
|
|
40
|
+
<!-- llm: end -->
|
|
41
|
+
|
|
42
|
+
The demo is `demo.html`; also slide 2 of `examples/kokugo-kanbun`.
|
|
43
|
+
|
|
44
|
+
<!-- llm: omit -->
|
|
45
|
+
Notes
|
|
46
|
+
|
|
47
|
+
- Without scripts (readable layer, pre-print HTML) it reads as a plain list of links
|
|
48
|
+
- The part wraps title, subtitle, circle in `span`s but leaves `<a>` and `href` as written
|
|
49
|
+
- No CSS transitions (real time would break (k, t))
|
|
50
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// m-menu:スライドへのリンクの札を格子に並べる(目次・単元の選び方・「どこから見るか」)
|
|
2
|
+
// <m-menu cols="3">
|
|
3
|
+
// <a href="#s-njd4kp" data-icon="一" data-sub="孟浩然">春暁</a> ← スライドへ(その段階 0)
|
|
4
|
+
// <a href="#s-uhqygr:2" data-sub="杜甫(読む順から)">春望</a> ← スライドの段階へ(#<id>:<段階の鍵>)
|
|
5
|
+
// <a href="lesson2.ega.html" data-sub="次の課">返り点の練習</a> ← ほかのファイル:ふつうのリンク
|
|
6
|
+
// </m-menu>
|
|
7
|
+
// 札はふつうの <a href>(format spec §9.1A:スクリプトのないリンクで、Core の文書に入れてよい)。部品は見た目を整えるだけで、
|
|
8
|
+
// 押したときの動き(発表では最終状態へ、自動再生中はそこから続ける、「戻る」)は実行系(kit/deck.js)が受け持つ。
|
|
9
|
+
// 段階:per-step="n" なら札が n 枚ずつ段階ごとに出る(data-from から)。0(既定)なら初めから全部(段階を使わない)。
|
|
10
|
+
// 「見た」の印:このセッションで札の行き先のスライドを開いたら、札の右上に印(保存しない。動画では付けない、印刷に出ない)。
|
|
11
|
+
// 印は見ている人の側の状態で、(i, k, t) の外(m-kobun の札と同じ扱い)。visited="false" で付けない
|
|
12
|
+
// 大きさ:札の高さの下限は --mm-h(既定 104px)、間は --mm-gap。CSS の transition は使わない(実時間で動くので、画面が (k, t) で決まらなくなる)
|
|
13
|
+
// 2.0(Egatari spec §6.1 の部品):base を使い、プレイヤーのグローバルは使わない。札の行き先(# の後ろ、spec §9.1A)はこのパーツが
|
|
14
|
+
// ctx.slides で読み(slideOf)、「見た」は ctx.visited(スライドの鍵)。印はスライドに入ったときの描画(ctx.entered)で付け直す
|
|
15
|
+
// (1.x は DECK の deck:pos を聞いていた。ほかのスライドを見られるのは、このスライドを離れている間だけ)
|
|
16
|
+
egatariParts.define({name: "menu", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-menu"}, function(deps){
|
|
17
|
+
"use strict";
|
|
18
|
+
var base = deps.base;
|
|
19
|
+
var CSS_ID = "menu-2-0-3-css"; // the style element this part writes, named with its name and version (spec §6.1 Identifiers)
|
|
20
|
+
var CSS =
|
|
21
|
+
"m-menu{display:grid;gap:var(--mm-gap,18px);grid-template-columns:repeat(var(--mm-cols,3),minmax(0,1fr));grid-auto-rows:minmax(var(--mm-h,104px),auto);align-content:start}" +
|
|
22
|
+
"m-menu>a{position:relative;display:flex;align-items:center;gap:18px;padding:14px 22px;box-sizing:border-box;" +
|
|
23
|
+
"border:2px solid var(--line);border-radius:14px;background:var(--bg);color:var(--fg);text-decoration:none;cursor:pointer}" +
|
|
24
|
+
"m-menu>a:hover{border-color:var(--term);box-shadow:0 3px 14px color-mix(in srgb,var(--term) 18%,transparent)}" +
|
|
25
|
+
"m-menu>a:focus{outline:none}m-menu>a:focus-visible{outline:3px solid var(--term);outline-offset:3px}" +
|
|
26
|
+
"m-menu .mm-icon{flex:none;display:grid;place-items:center;width:1.9em;height:1.9em;border-radius:50%;background:var(--term);color:var(--bg);font-weight:700;line-height:1}" +
|
|
27
|
+
"m-menu .mm-text{display:flex;flex-direction:column;gap:4px;min-width:0;overflow-wrap:anywhere}" +
|
|
28
|
+
"m-menu>a.mm-r{padding-right:46px}" +
|
|
29
|
+
"m-menu .mm-title{font-weight:700;line-height:1.25}" +
|
|
30
|
+
"m-menu .mm-sub{font-size:max(27px,.8em);line-height:1.3;color:var(--muted)}" +
|
|
31
|
+
"m-menu .mm-to{display:none;position:absolute;right:12px;top:10px;font-size:27px;line-height:1.2;font-weight:700;white-space:nowrap;color:var(--muted);font-variant-numeric:tabular-nums}" +
|
|
32
|
+
"m-menu .mm-ext{position:absolute;right:12px;bottom:10px;width:20px;height:20px;color:var(--muted)}" +
|
|
33
|
+
"m-menu .mm-seen{position:absolute;right:10px;top:10px;display:none;width:26px;height:26px;border-radius:50%;background:var(--muted);color:var(--bg)}" +
|
|
34
|
+
"m-menu>a.mm-visited{border-color:color-mix(in srgb,var(--muted) 55%,var(--line))}" +
|
|
35
|
+
"m-menu>a.mm-visited .mm-seen{display:block}" +
|
|
36
|
+
"m-menu svg{fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}" +
|
|
37
|
+
".printing m-menu .mm-seen{display:none!important}@media print{m-menu .mm-seen{display:none!important}}" +
|
|
38
|
+
".printing m-menu .mm-to{display:block}.printing m-menu>a.mm-d{padding-right:78px}" +
|
|
39
|
+
"@media print{m-menu .mm-to{display:block}m-menu>a.mm-d{padding-right:78px}}m-menu .mm-to:empty{display:none!important}" +
|
|
40
|
+
".mm-sr{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap}";
|
|
41
|
+
var CHECK = '<svg class="mm-seen" viewBox="0 0 26 26" aria-hidden="true"><path d="M7.5 13.5l3.6 3.6 7.4-8"/></svg>';
|
|
42
|
+
var EXT = '<svg class="mm-ext" viewBox="0 0 20 20" aria-hidden="true"><path d="M8 4H4v12h12v-4M11 3h6v6M17 3l-8 8"/></svg>';
|
|
43
|
+
function cards(el){ return [].filter.call(el.children, function(x){ return x.localName === "a" && x.hasAttribute("href"); }); }
|
|
44
|
+
// 札の行き先のスライドの鍵(spec §9.1A:#<スライドの id>、#<id>:<段階の鍵>。段階の鍵は最後の : で切り、0・1・…(3 桁まで)か concl。
|
|
45
|
+
// 数字だけの #N は 1 から数えたスライドの番号)。読めなければ null。数字の段階の鍵は、そのスライドの数字の段階の最後
|
|
46
|
+
// (ctx.slides の steps。spec §8.4)を超えれば読めない。concl は結論の段階があるスライド(ctx.slides の concl)でだけ読める
|
|
47
|
+
// (どちらも 1.x の DECK.resolveFragment と同じ)
|
|
48
|
+
function slideOf(frag, slides){
|
|
49
|
+
var f = String(frag == null ? "" : frag);
|
|
50
|
+
try { f = decodeURIComponent(f); } catch (e) { /* the fragment as written */ }
|
|
51
|
+
if (!f) return null;
|
|
52
|
+
if (/^[0-9]+$/.test(f)){ var n = +f; return n >= 1 && n <= slides.length ? slides[n - 1].key : null; }
|
|
53
|
+
var find = function(key){ for (var j = 0; j < slides.length; j++) if (slides[j].key === key) return slides[j]; return null; };
|
|
54
|
+
if (find(f)) return f;
|
|
55
|
+
var p = f.lastIndexOf(":"), s = p > 0 ? find(f.slice(0, p)) : null;
|
|
56
|
+
if (!s) return null;
|
|
57
|
+
var sk = f.slice(p + 1);
|
|
58
|
+
if (sk === "concl") return s.concl === true ? s.key : null;
|
|
59
|
+
return /^(0|[1-9][0-9]{0,2})$/.test(sk) && +sk <= (s.steps || 0) ? s.key : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return class extends base.MotionElement {
|
|
63
|
+
static partName = "menu"; // the registry name (define meta name), for report prefixes
|
|
64
|
+
static interactive = true; // 操作できるパーツ(札はリンク。docs/conventions.md §6)
|
|
65
|
+
// データの形(kit/shape.js):JSON ではなく、子のリンク <a href="#<スライドの id>">題</a>
|
|
66
|
+
static shape = {links: true, example: '<a href="#s-abc123" data-sub="副題">題</a>'};
|
|
67
|
+
static props = {
|
|
68
|
+
cols: {type: "number", default: 0, doc: "列の数(0 なら札の数から:3 枚までは 1 行、4 枚は 2 列、それより多ければ 3 列)"},
|
|
69
|
+
"per-step": {type: "number", default: 0, doc: "1 ステップに出す札の数(0 なら初めから全部出し、ステップを使わない)"},
|
|
70
|
+
size: {type: "number", default: 34, doc: "札の題の字の大きさ(px)。副題はその 0.8 倍(本文の下限の 27px より小さくしない)"},
|
|
71
|
+
fade: {type: "number", default: 0.4, doc: "札が出る秒数"},
|
|
72
|
+
stagger: {type: "number", default: 0.12, doc: "同じステップの札どうしの出るずれ(秒)"},
|
|
73
|
+
visited: {type: "bool", default: true, doc: "このセッションで行き先のスライドを開いた札に「見た」の印を付ける"},
|
|
74
|
+
};
|
|
75
|
+
get steps(){
|
|
76
|
+
var a = this.getAttribute("steps");
|
|
77
|
+
if (a !== null && /^\d+$/.test(a.trim())) return +a;
|
|
78
|
+
var per = +this.getAttribute("per-step") || 0;
|
|
79
|
+
return per > 0 ? Math.ceil(cards(this).length / per) : 0;
|
|
80
|
+
}
|
|
81
|
+
mount(ctx){
|
|
82
|
+
var P = this.props, list = cards(this), n = list.length;
|
|
83
|
+
if (!document.getElementById(CSS_ID)){ var st = document.createElement("style"); st.id = CSS_ID; st.textContent = CSS; document.head.appendChild(st); }
|
|
84
|
+
var cols = P.cols > 0 ? P.cols : n <= 3 ? Math.max(1, n) : n === 4 ? 2 : 3;
|
|
85
|
+
this.style.setProperty("--mm-cols", cols);
|
|
86
|
+
this.style.fontSize = P.size + "px";
|
|
87
|
+
var per = P["per-step"] > 0 ? P["per-step"] : 0;
|
|
88
|
+
var ja = /^ja\b/i.test(ctx.lang), visitedOn = P.visited && ctx.mode !== "video";
|
|
89
|
+
this.cards = list.map(function(a, j){
|
|
90
|
+
// 書いた中身(文字・<b> など)を題にし、data-icon と data-sub から丸の字と副題を足す(リンクはそのまま)
|
|
91
|
+
var title = document.createElement("span"); title.className = "mm-title";
|
|
92
|
+
while (a.firstChild) title.appendChild(a.firstChild);
|
|
93
|
+
var text = document.createElement("span"); text.className = "mm-text"; text.appendChild(title);
|
|
94
|
+
var sub = a.getAttribute("data-sub");
|
|
95
|
+
if (sub){ var sp = document.createElement("span"); sp.className = "mm-sub"; sp.textContent = sub; text.appendChild(sp); }
|
|
96
|
+
var icon = a.getAttribute("data-icon");
|
|
97
|
+
if (icon){ var ic = document.createElement("span"); ic.className = "mm-icon"; ic.setAttribute("aria-hidden", "true"); ic.textContent = icon; a.appendChild(ic); }
|
|
98
|
+
a.appendChild(text);
|
|
99
|
+
var href = a.getAttribute("href"), inDoc = href.charAt(0) === "#";
|
|
100
|
+
// 印刷にだけ出す行き先(印刷では押せないので):右上(画面の「見た」の印の場所)に行き先のスライドの番号「→12」(dests が ctx.slides から書く)。
|
|
101
|
+
// 札の高さを変えない(札の多い目次がスライドからはみ出さない)。ほかのファイルへの札は右下の印のまま。読み上げはしない(リンクの題がある)
|
|
102
|
+
var to = document.createElement("span"); to.className = "mm-to"; to.setAttribute("aria-hidden", "true"); a.appendChild(to);
|
|
103
|
+
// 右上の「見た」の印・右下の「別のファイル」の印の場所を空けておく(長い題が印の下に入らない)
|
|
104
|
+
if ((visitedOn && inDoc) || !inDoc) a.classList.add("mm-r");
|
|
105
|
+
a.insertAdjacentHTML("beforeend", CHECK + (inDoc ? "" : EXT));
|
|
106
|
+
var sr = document.createElement("span"); sr.className = "mm-sr"; a.appendChild(sr);
|
|
107
|
+
// 作り手が書いた style(render はこの後ろに自分の値を足して書く)
|
|
108
|
+
var css = (a.getAttribute("style") || "").trim().replace(/\s*;$/, ""); if (css) css += ";";
|
|
109
|
+
return {a: a, sr: sr, to: to, css: css, frag: inDoc ? href.slice(1) : null, ext: !inDoc, step: per ? Math.floor(j / per) + 1 : 0, at: per ? (j % per) * P.stagger : 0};
|
|
110
|
+
});
|
|
111
|
+
this.ja = ja;
|
|
112
|
+
this.visitedOn = visitedOn;
|
|
113
|
+
// 読み上げ:札の並びはリンクの集まり(navigation)。名前は札の題を並べた 1 文。作者の aria-label があればそれを使う(上書きしない)
|
|
114
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
115
|
+
this.setAttribute("role", "navigation");
|
|
116
|
+
if (!this._aria) this.setAttribute("aria-label", (ja ? "スライドへのリンク " + n + " 件:" : n + " links: ") +
|
|
117
|
+
this.cards.map(function(c){ return c.a.querySelector(".mm-title").textContent.trim(); }).join(ja ? "、" : ", "));
|
|
118
|
+
if (this.visitedOn) this.markVisited(ctx);
|
|
119
|
+
this.dests(ctx);
|
|
120
|
+
}
|
|
121
|
+
// 印刷の行き先の字(スライドの番号)。ctx.slides は部品を組むときにはまだ空のことがあるので、読めた最初の描画で 1 回だけ書く
|
|
122
|
+
dests(ctx){
|
|
123
|
+
var slides = ctx.slides || [];
|
|
124
|
+
if (this._dests || !slides.length) return;
|
|
125
|
+
this._dests = true;
|
|
126
|
+
this.cards.forEach(function(c){
|
|
127
|
+
if (c.frag === null) return;
|
|
128
|
+
var key = slideOf(c.frag, slides), s = "";
|
|
129
|
+
for (var q = 0; q < slides.length; q++) if (key !== null && slides[q].key === key) s = "→" + (q + 1);
|
|
130
|
+
c.to.textContent = s;
|
|
131
|
+
if (s) c.a.classList.add("mm-d");
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// 「見た」の印(見ている人の側の状態。(i, k, t) の外)
|
|
135
|
+
markVisited(ctx){
|
|
136
|
+
var ja = this.ja, slides = ctx.slides || [];
|
|
137
|
+
this.cards.forEach(function(c){
|
|
138
|
+
var v = false;
|
|
139
|
+
if (c.frag !== null){ var key = slideOf(c.frag, slides); v = key !== null && ctx.visited(key) === true; }
|
|
140
|
+
c.a.classList.toggle("mm-visited", v);
|
|
141
|
+
c.sr.textContent = (v ? (ja ? "(見た)" : " (visited)") : "") + (c.ext ? (ja ? "(別のファイル)" : " (another file)") : "");
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
duration(k){
|
|
145
|
+
var d = 0, F = this.props.fade;
|
|
146
|
+
this.cards.forEach(function(c){ if (c.step === k) d = Math.max(d, c.at + F); });
|
|
147
|
+
return d;
|
|
148
|
+
}
|
|
149
|
+
render(k, t, ctx){
|
|
150
|
+
var F = this.props.fade, lecture = !!ctx.preview, FAINT = 0.45;
|
|
151
|
+
// 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
152
|
+
if (lecture) FAINT = base.previewOpacity(this);
|
|
153
|
+
// 「見た」の印は、ほかのスライドから入ったときに付け直す
|
|
154
|
+
if (this.visitedOn && ctx.entered) this.markVisited(ctx);
|
|
155
|
+
this.dests(ctx);
|
|
156
|
+
this.cards.forEach(function(c){
|
|
157
|
+
var p = c.step < k ? 1 : c.step > k ? 0 : base.prog(t, c.at, F);
|
|
158
|
+
if (lecture && p < 1) p = Math.max(p, c.step > k ? FAINT : p);
|
|
159
|
+
// 見えていない札は押せない・選べない・読み上げない
|
|
160
|
+
// 授業の表示で薄く見せている先の札も押せない・選べない(読み上げはする)
|
|
161
|
+
var off = p <= 0, inert = off || (lecture && c.step > k);
|
|
162
|
+
// 書く属性は毎回、同じ順・同じ書き方で書き直す(style は作り手の style の後ろに 1 つの文字列で。
|
|
163
|
+
// tabindex・aria-hidden は消してから付け直す)。呼ぶ順で属性の字や並びが変わらない(docs/contract.md §3)
|
|
164
|
+
c.a.removeAttribute("tabindex"); c.a.removeAttribute("aria-hidden");
|
|
165
|
+
c.a.setAttribute("style", c.css + "opacity:" + p.toFixed(3) + ";" + (p < 1 && !lecture ? "transform:translateY(" + ((1 - p) * 14).toFixed(2) + "px);" : "") + (inert ? "pointer-events:none;" : ""));
|
|
166
|
+
if (inert) c.a.setAttribute("tabindex", "-1");
|
|
167
|
+
if (off) c.a.setAttribute("aria-hidden", "true");
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: 2-axis positioning map (4 quadrants); points one per step
|
|
3
|
+
steps: largest step / to.step (1 point = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
fade: point appear (s)
|
|
6
|
+
move: to move (s)
|
|
7
|
+
size: label px
|
|
8
|
+
quads-step: quadrant-name step (0 = start)
|
|
9
|
+
example: {"x": {"lo": "Manual", "hi": "Auto"}, "y": {"lo": "Costly", "hi": "Cheap"}, "items": [{"label": "Co. A", "x": 0.25, "y": 0.7}, {"label": "Us", "x": 0.8, "y": 0.82, "self": true}]}
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Positioning, effect×effort, SWOT: show the empty space.
|
|
13
|
+
|
|
14
|
+
Child JSON: `{"x": {"lo", "hi"}, "y": {"lo", "hi"}, "quads": {"tr", "tl", "bl", "br", "fill"}, "items": [...]}`.
|
|
15
|
+
|
|
16
|
+
- `x` `y`: axis end words (step 0)
|
|
17
|
+
- `quads`: names (tr = top-right, tl, bl, br); `fill: "tr"` tints one; names at `quads-step`
|
|
18
|
+
- item: `label`, `x` `y` (0–1; 0.5 = axis cross), `step` (default next), `at`, `tone` (`term`/`fg`; default muted), `anchor` (`right`, `left`, `above`, `below`), `r`
|
|
19
|
+
- `self: true`: big `--emph` point, ring pulse
|
|
20
|
+
- `to: {"x", "y", "label", "step", "at"}`: slides at `to.step` (default next), dashed trail; `label` on arrival
|
|
21
|
+
- `cues(k)`: start times of 2nd+ points in a step, for `{cue}`
|
|
22
|
+
|
|
23
|
+
The demo is `demo.html`. Names and positions are fictional.
|
|
24
|
+
|
|
25
|
+
Notes
|
|
26
|
+
|
|
27
|
+
<!-- llm: omit -->
|
|
28
|
+
- Labels crossing an axis move: opposite side → above → below (start and `to`; even with `anchor`). Axis lines have `class="axis"`; `tools/test-components.mjs` flags crossings
|
|
29
|
+
<!-- llm: end -->
|
|
30
|
+
- Quadrant names avoid points and labels (else labels move, or `ctx.report`)
|
|
31
|
+
- Label overlaps not fixed: change `anchor` or shift
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// m-quad:2 軸の位置づけ(ポジショニングマップ・SWOT 風の 4 象限)。点を段階ごとに 1 つずつ置く
|
|
2
|
+
// <m-quad style="height:420px"><script type="application/json">
|
|
3
|
+
// {"x": {"lo": "手作業", "hi": "自動"}, "y": {"lo": "高い", "hi": "安い"},
|
|
4
|
+
// "quads": {"tr": "狙う場所", "tl": "", "bl": "", "br": ""},
|
|
5
|
+
// "items": [{"label": "A 社", "x": 0.25, "y": 0.7}, {"label": "自社", "x": 0.8, "y": 0.82, "self": true, "to": {"x": 0.9, "y": 0.9, "label": "3 年後"}}]}
|
|
6
|
+
// (JSON の終わり)</m-quad>
|
|
7
|
+
// 座標は 0〜1(0.5 が軸の交わるところ)。軸と両端の言葉は段階 0 から見える。象限の名前は quads-step(既定 0)で出る
|
|
8
|
+
// 点は既定で 1 つ = 1 段階(step で直接、at で段階の中の開始秒)。self の点は強調の色で大きく、着いたときに輪が広がる
|
|
9
|
+
// to は移動先:to.step(既定は点の次の段階)に、点が破線の跡を引きながら滑る
|
|
10
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・lerp・clamp・previewOpacity を使い、プレイヤーのグローバルは使わない
|
|
11
|
+
egatariParts.define({name: "quad", version: "2.0.4", requires: {base: "1.2.0"}, element: "m-quad"}, function(deps){
|
|
12
|
+
"use strict";
|
|
13
|
+
var base = deps.base;
|
|
14
|
+
return class extends base.MotionElement {
|
|
15
|
+
static partName = "quad"; // the registry name (define meta name), for report prefixes
|
|
16
|
+
// データの形(kit/shape.js)。x・y は 0〜1(0.5 が軸の交わるところ)
|
|
17
|
+
static shape = {
|
|
18
|
+
schema: {type: "object", additionalProperties: false, required: ["items"], properties: {
|
|
19
|
+
x: {type: "object", properties: {lo: {type: "string"}, hi: {type: "string"}}}, y: {type: "object", properties: {lo: {type: "string"}, hi: {type: "string"}}},
|
|
20
|
+
quads: {type: "object", properties: {tr: {type: "string"}, tl: {type: "string"}, bl: {type: "string"}, br: {type: "string"}, fill: {type: "string"}}},
|
|
21
|
+
items: {type: "array", minItems: 1, items: {type: "object", required: ["x", "y"], properties: {
|
|
22
|
+
label: {type: "string"}, x: {type: "number"}, y: {type: "number"}, step: {type: "integer"}, at: {type: "number"}, tone: {type: "string"}, anchor: {enum: ["right", "left", "above", "below"]},
|
|
23
|
+
r: {type: "number"}, self: {type: "boolean"}, to: {type: "object", required: ["x", "y"], properties: {x: {type: "number"}, y: {type: "number"}, label: {type: "string"}, step: {type: "integer"}, at: {type: "number"}}}}}}}},
|
|
24
|
+
example: {x: {lo: "手作業", hi: "自動"}, y: {lo: "高い", hi: "安い"}, items: [{label: "A 社", x: 0.25, y: 0.7}, {label: "自社", x: 0.8, y: 0.82, self: true}]},
|
|
25
|
+
};
|
|
26
|
+
static props = {
|
|
27
|
+
fade: {type: "number", default: 0.5, doc: "点が現れる秒数"},
|
|
28
|
+
move: {type: "number", default: 1.2, doc: "to の移動の秒数"},
|
|
29
|
+
size: {type: "number", default: 26, doc: "点の名前の字の大きさ(px)"},
|
|
30
|
+
"quads-step": {type: "number", default: 0, doc: "象限の名前を出すステップ(0 = 初めから)"},
|
|
31
|
+
};
|
|
32
|
+
get steps(){
|
|
33
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
34
|
+
var m = this.props["quads-step"];
|
|
35
|
+
this.plan().forEach(function(o){ m = Math.max(m, o.step, o.to ? o.to.step : 0); });
|
|
36
|
+
return m;
|
|
37
|
+
}
|
|
38
|
+
// 点の段階と開始時刻(データだけから決める)
|
|
39
|
+
plan(){
|
|
40
|
+
if (this._plan) return this._plan;
|
|
41
|
+
var d = this.data || {}, q0 = this.props["quads-step"], n = 0, seen = {};
|
|
42
|
+
return (this._plan = (d.items || []).map(function(it){
|
|
43
|
+
var step = it.step !== undefined ? it.step : q0 + (++n);
|
|
44
|
+
n = Math.max(n, step - q0);
|
|
45
|
+
var j = seen[step] = (seen[step] || 0) + 1;
|
|
46
|
+
var to = it.to ? {x: it.to.x, y: it.to.y, label: it.to.label || "", step: it.to.step !== undefined ? it.to.step : step + 1, at: it.to.at || 0} : null;
|
|
47
|
+
return {it: it, step: step, at: it.at !== undefined ? it.at : (j - 1) * 0.6, to: to};
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
mount(ctx){
|
|
51
|
+
var P = this.props, D = base, self = this, d = this.data || {};
|
|
52
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
53
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
54
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
55
|
+
// 読み上げ:最後の形(点はすべて置かれ、to の点は行き先にいる)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
56
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
57
|
+
this.setAttribute("role", "img");
|
|
58
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
|
|
59
|
+
// 図の枠:両端の言葉の分だけ上下と左右に余白
|
|
60
|
+
var m = {l: 12, r: 12, t: 40, b: 40};
|
|
61
|
+
var x0 = m.l, x1 = W - m.r, y0 = m.t, y1 = H - m.b, cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;
|
|
62
|
+
this.X = function(v){ return x0 + v * (x1 - x0); };
|
|
63
|
+
this.Y = function(v){ return y1 - v * (y1 - y0); };
|
|
64
|
+
// 象限の地(右上だけ淡く塗れる:quads.fill = "tr" など)と名前
|
|
65
|
+
var q = d.quads || {}, xa0 = d.x || {}, gQ = D.el("g", {}, svg);
|
|
66
|
+
this.quadG = D.el("g", {}, svg);
|
|
67
|
+
var corner = {tr: [cx, y0, x1 - cx, cy - y0, x1 - 16, y0 + 34, "end"], tl: [x0, y0, cx - x0, cy - y0, x0 + 16, y0 + 34, "start"],
|
|
68
|
+
bl: [x0, cy, cx - x0, y1 - cy, x0 + 16, y1 - 16, "start"], br: [cx, cy, x1 - cx, y1 - cy, x1 - 16, y1 - 16, "end"]};
|
|
69
|
+
["tr", "tl", "bl", "br"].forEach(function(key){
|
|
70
|
+
var c = corner[key];
|
|
71
|
+
if (q.fill === key) D.el("rect", {x: c[0], y: c[1], width: c[2], height: c[3], fill: "var(--term-tint)"}, gQ);
|
|
72
|
+
});
|
|
73
|
+
// 軸(両向きの矢印)と両端の言葉。横軸の言葉は軸の下、縦軸の言葉は軸の上端・下端の外
|
|
74
|
+
var ax = D.el("g", {}, svg), K = "var(--fg)";
|
|
75
|
+
D.el("line", {x1: x0, y1: cy, x2: x1, y2: cy, stroke: K, "stroke-width": 2, class: "axis"}, ax);
|
|
76
|
+
D.el("line", {x1: cx, y1: y0, x2: cx, y2: y1, stroke: K, "stroke-width": 2, class: "axis"}, ax);
|
|
77
|
+
[[x1, cy, 0], [x0, cy, 180], [cx, y0, -90], [cx, y1, 90]].forEach(function(a){
|
|
78
|
+
D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: K, transform: "translate(" + a[0] + " " + a[1] + ") rotate(" + a[2] + ")"}, ax);
|
|
79
|
+
});
|
|
80
|
+
var xa = xa0, ya = d.y || {};
|
|
81
|
+
if (xa.lo) D.mtext(ax, x0 + 4, cy + 34, xa.lo, {"text-anchor": "start", "font-size": 24});
|
|
82
|
+
if (xa.hi) D.mtext(ax, x1 - 4, cy + 34, xa.hi, {"text-anchor": "end", "font-size": 24});
|
|
83
|
+
if (ya.hi) D.mtext(ax, cx, y0 - 14, ya.hi, {"text-anchor": "middle", "font-size": 24});
|
|
84
|
+
if (ya.lo) D.mtext(ax, cx, y1 + 32, ya.lo, {"text-anchor": "middle", "font-size": 24});
|
|
85
|
+
// 点の名前の置き場所(既定は右。anchor で left / above / below)。
|
|
86
|
+
// 名前が軸の線を横切るなら、丸の反対の側 → 上 → 下の順に置き直す(点の始めの位置と to の位置の両方で確かめる)。
|
|
87
|
+
// 象限の名前を置いたあとは、その名前にかかる置き場所も避ける。幅は字から見積もる(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
|
|
88
|
+
var est = function(s, z){ return D.textWidth(s || "", z, {font: self, mark: true}); };
|
|
89
|
+
var meet = function(a, b, gp){ return a[0] < b[2] + gp && a[2] > b[0] - gp && a[1] < b[3] + gp && a[3] > b[1] - gp; };
|
|
90
|
+
var items = this.plan().map(function(o){
|
|
91
|
+
var it = o.it, me = !!it.self, r = it.r || (me ? 14 : 11), off = r + 10, w = est(it.label, P.size);
|
|
92
|
+
var place = function(an){ return an === "left" ? [-off, 9, "end"] : an === "above" ? [0, -off - 4, "middle"] : an === "below" ? [0, off + 22, "middle"] : [off, 9, "start"]; };
|
|
93
|
+
var boxAt = function(an, px, py){
|
|
94
|
+
var lp = place(an), lx = px + lp[0], ly = py + lp[1], a0 = lp[2] === "start" ? lx : lp[2] === "end" ? lx - w : lx - w / 2;
|
|
95
|
+
return [a0, ly - P.size * 0.88, a0 + w, ly + P.size * 0.22];
|
|
96
|
+
};
|
|
97
|
+
var crosses = function(an, px, py){
|
|
98
|
+
var b = boxAt(an, px, py);
|
|
99
|
+
return (b[0] - 6 < cx && b[2] + 6 > cx && b[1] < y1 && b[3] > y0) || (b[1] - 6 < cy && b[3] + 6 > cy && b[0] < x1 && b[2] > x0);
|
|
100
|
+
};
|
|
101
|
+
var pts = [[self.X(it.x), self.Y(it.y)]].concat(o.to ? [[self.X(o.to.x), self.Y(o.to.y)]] : []);
|
|
102
|
+
var pref = it.anchor || "right", order = [pref, pref === "left" ? "right" : pref === "right" ? "left" : pref === "above" ? "below" : "above", "above", "below", "left", "right"];
|
|
103
|
+
var pick = function(names){
|
|
104
|
+
return order.filter(function(a){ return !pts.some(function(q){ return crosses(a, q[0], q[1]) || names.some(function(nb){ return meet(boxAt(a, q[0], q[1]), nb, 6); }); }); })[0];
|
|
105
|
+
};
|
|
106
|
+
var an = pick([]) || pref;
|
|
107
|
+
return {o: o, it: it, me: me, r: r, pts: pts, place: place, boxAt: boxAt, pick: pick, an: an,
|
|
108
|
+
// 丸と名前が占める箱(点の始めと to の位置)
|
|
109
|
+
boxes: function(a){ return [].concat.apply([], pts.map(function(q){ return [[q[0] - r, q[1] - r, q[0] + r, q[1] + r], boxAt(a, q[0], q[1])]; })); }};
|
|
110
|
+
});
|
|
111
|
+
// 象限の名前:隅(外側の角)に置く。点や点の名前、軸の言葉にかかるなら、同じ象限の残りの 3 つの隅を順に試す。
|
|
112
|
+
// どこもかかるなら外側の角に置き、点の名前のほうを動かす(上の pick)。動かせなければ知らせる(layout)
|
|
113
|
+
var axisBoxes = [];
|
|
114
|
+
if (xa0.lo) axisBoxes.push([x0 + 4, cy + 34 - 24 * 0.88, x0 + 4 + est(xa0.lo, 24), cy + 34 + 24 * 0.22]);
|
|
115
|
+
if (xa0.hi) axisBoxes.push([x1 - 4 - est(xa0.hi, 24), cy + 34 - 24 * 0.88, x1 - 4, cy + 34 + 24 * 0.22]);
|
|
116
|
+
var names = [];
|
|
117
|
+
["tr", "tl", "bl", "br"].forEach(function(key){
|
|
118
|
+
if (!q[key]) return;
|
|
119
|
+
var c = corner[key], top = key[0] === "t", right = key[1] === "r", w = est(q[key], 26);
|
|
120
|
+
var ins = [c[0] + 16, c[0] + c[2] - 16], ys = top ? [y0 + 34, cy - 16] : [y1 - 16, cy + 42];
|
|
121
|
+
var cand = [[right ? ins[1] : ins[0], ys[0], right ? "end" : "start"], [right ? ins[0] : ins[1], ys[0], right ? "start" : "end"],
|
|
122
|
+
[right ? ins[1] : ins[0], ys[1], right ? "end" : "start"], [right ? ins[0] : ins[1], ys[1], right ? "start" : "end"]];
|
|
123
|
+
var boxOf = function(k){ var x = k[2] === "end" ? k[0] - w : k[0]; return [x, k[1] - 26 * 0.88, x + w, k[1] + 26 * 0.22]; };
|
|
124
|
+
var busy = function(b){ return axisBoxes.some(function(a){ return meet(b, a, 6); }) || items.some(function(m){ return m.boxes(m.an).some(function(a){ return meet(b, a, 6); }); }); };
|
|
125
|
+
var k = cand.filter(function(k){ return !busy(boxOf(k)); })[0] || cand[0];
|
|
126
|
+
D.mtext(self.quadG, k[0], k[1], q[key], {"text-anchor": k[2], "font-size": 26, "font-weight": 700, fill: q.fill === key ? "var(--term)" : "var(--muted)"});
|
|
127
|
+
names.push({key: key, box: boxOf(k)});
|
|
128
|
+
});
|
|
129
|
+
items.forEach(function(m){
|
|
130
|
+
if (!names.length || !m.boxes(m.an).some(function(a){ return names.some(function(nm){ return meet(a, nm.box, 6); }); })) return;
|
|
131
|
+
var a = m.pick(names.map(function(nm){ return nm.box; }));
|
|
132
|
+
if (a) m.an = a;
|
|
133
|
+
else ctx.report("layout", "[quad] the label " + JSON.stringify(m.it.label || "") + " overlaps a quadrant name and has no free side; move the point or shorten a name");
|
|
134
|
+
});
|
|
135
|
+
// 点:丸と名前
|
|
136
|
+
var gT = D.el("g", {}, svg), gP = D.el("g", {}, svg);
|
|
137
|
+
this.pts = items.map(function(m){
|
|
138
|
+
var o = m.o, it = m.it, me = m.me, r = m.r, col = me ? "var(--emph)" : it.tone === "term" ? "var(--term)" : it.tone === "fg" ? "var(--fg)" : "var(--muted)";
|
|
139
|
+
var trail = o.to ? D.el("line", {stroke: col, "stroke-width": 2.5, "stroke-dasharray": "7 6", opacity: 0}, gT) : null;
|
|
140
|
+
// 動いた跡の印(最後の形にも残す):出発点の白抜きの丸と、行き先へ向く矢じり(丸の手前)
|
|
141
|
+
var from = o.to ? D.el("circle", {cx: self.X(it.x).toFixed(2), cy: self.Y(it.y).toFixed(2), r: (r * 0.8).toFixed(1), fill: "var(--bg)", stroke: col, "stroke-width": 2.5, opacity: 0}, gT) : null;
|
|
142
|
+
var head = o.to ? D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: col, opacity: 0}, gT) : null;
|
|
143
|
+
var ring = me ? D.el("circle", {r: r, fill: "none", stroke: col, "stroke-width": 3, opacity: 0}, gP) : null;
|
|
144
|
+
var g = D.el("g", {opacity: 0}, gP);
|
|
145
|
+
D.el("circle", {cx: 0, cy: 0, r: r, fill: col, stroke: "var(--bg)", "stroke-width": 2.5}, g);
|
|
146
|
+
var lp = m.place(m.an);
|
|
147
|
+
D.mtext(g, lp[0], lp[1], it.label || "", {"text-anchor": lp[2], "font-size": P.size, "font-weight": me ? 700 : 400, fill: me ? col : "var(--fg)"});
|
|
148
|
+
var lab2 = o.to && o.to.label ? D.mtext(gP, 0, 0, o.to.label, {"text-anchor": "middle", "font-size": 24, fill: col, opacity: 0}) : null;
|
|
149
|
+
return {o: o, g: g, ring: ring, r: r, trail: trail, from: from, head: head, lab2: lab2};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
// 最後の形を 1 文で(読み上げの名前):象限の名前と、点ごとの最後の位置(右上・左下など。to の点は出発点から行き先へ)
|
|
153
|
+
summary(ja){
|
|
154
|
+
var d = this.data || {}, q = d.quads || {}, xa = d.x || {}, ya = d.y || {};
|
|
155
|
+
var where = function(x, y, bare){
|
|
156
|
+
var h = x > 0.5 ? (ja ? "右" : "right") : x < 0.5 ? (ja ? "左" : "left") : "", v = y > 0.5 ? (ja ? "上" : "upper") : y < 0.5 ? (ja ? "下" : "lower") : "";
|
|
157
|
+
var key = (y > 0.5 ? "t" : "b") + (x > 0.5 ? "r" : "l");
|
|
158
|
+
var s = ja ? (h + v || "中央") : ([v, h].filter(Boolean).join(" ") || "centre");
|
|
159
|
+
return s + (h && v && q[key] && !bare ? (ja ? "(" + q[key] + ")" : " (" + q[key] + ")") : "");
|
|
160
|
+
};
|
|
161
|
+
var axis = function(a, n){ return a.lo || a.hi ? (ja ? n + ":" + (a.lo || "") + "→" + (a.hi || "") : n + ": " + (a.lo || "") + " to " + (a.hi || "")) : ""; };
|
|
162
|
+
var ax = [axis(xa, ja ? "横" : "x"), axis(ya, ja ? "縦" : "y")].filter(Boolean).join(ja ? "、" : "; ");
|
|
163
|
+
var pts = this.plan().map(function(o){
|
|
164
|
+
var it = o.it, nm = it.label || (ja ? "点" : "a point");
|
|
165
|
+
if (!o.to) return ja ? nm + "は" + where(it.x, it.y) : nm + " is " + where(it.x, it.y);
|
|
166
|
+
var lb = o.to.label ? (ja ? "(" + o.to.label + ")" : " (" + o.to.label + ")") : "", w0 = where(it.x, it.y), w1 = where(o.to.x, o.to.y, true);
|
|
167
|
+
// 同じ象限の中の移動なら、行き先に象限の名前を繰り返さない
|
|
168
|
+
if (w1 !== where(it.x, it.y, true)) w1 = where(o.to.x, o.to.y);
|
|
169
|
+
return ja ? nm + "は" + w0 + "から" + w1 + "へ" + lb : nm + " moves from " + w0 + " to " + w1 + lb;
|
|
170
|
+
});
|
|
171
|
+
return (ja ? "4 象限" : "Four quadrants") + (ax ? (ja ? "(" + ax + ")" : " (" + ax + ")") : "") + (ja ? ":" : ": ") + pts.join(ja ? "、" : ", ");
|
|
172
|
+
}
|
|
173
|
+
duration(k){
|
|
174
|
+
var P = this.props, d = k === P["quads-step"] && k > 0 ? P.fade : 0;
|
|
175
|
+
this.plan().forEach(function(o){
|
|
176
|
+
if (o.step === k) d = Math.max(d, o.at + P.fade + (o.it.self ? 0.6 : 0));
|
|
177
|
+
if (o.to && o.to.step === k) d = Math.max(d, o.to.at + P.move + 0.3);
|
|
178
|
+
});
|
|
179
|
+
return d;
|
|
180
|
+
}
|
|
181
|
+
// 同じ段階に 2 つ以上の点があれば、2 つ目からの開始時刻を口述原稿の {cue} に合わせられる
|
|
182
|
+
cues(k){
|
|
183
|
+
var c = [];
|
|
184
|
+
this.plan().forEach(function(o){ if (o.step === k && o.at > 0) c.push(o.at); });
|
|
185
|
+
return c.length ? c.sort(function(a, b){ return a - b; }) : null;
|
|
186
|
+
}
|
|
187
|
+
render(k, t, ctx){
|
|
188
|
+
var P = this.props, D = base, self = this;
|
|
189
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の点(動いた後の位置)・動く跡・行き先の名前・象限の名前を、
|
|
190
|
+
// テーマの --preview-opacity の濃さに。今の段階に出ている点は元の位置のまま
|
|
191
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
192
|
+
var pr = function(step, at, dur){ return step < k ? 1 : step > k ? 0 : D.prog(t, at, dur); };
|
|
193
|
+
var qs = P["quads-step"];
|
|
194
|
+
this.quadG.setAttribute("opacity", (qs === 0 ? 1 : preview && qs > k ? PV : pr(qs, 0, P.fade)).toFixed(3));
|
|
195
|
+
this.pts.forEach(function(p){
|
|
196
|
+
var o = p.o, e = pr(o.step, o.at, P.fade), fp = preview && o.step > k, fm = preview && o.to && o.to.step > k;
|
|
197
|
+
var m = o.to ? (fp ? 1 : pr(o.to.step, o.to.at, P.move)) : 0;
|
|
198
|
+
if (fp) e = 1;
|
|
199
|
+
var x0 = self.X(o.it.x), y0 = self.Y(o.it.y);
|
|
200
|
+
var x = o.to ? D.lerp(x0, self.X(o.to.x), m) : x0, y = o.to ? D.lerp(y0, self.Y(o.to.y), m) : y0;
|
|
201
|
+
var s = D.lerp(0.6, 1, e);
|
|
202
|
+
p.g.setAttribute("opacity", fp ? PV.toFixed(3) : e.toFixed(3));
|
|
203
|
+
p.g.setAttribute("transform", "translate(" + x.toFixed(2) + " " + y.toFixed(2) + ") scale(" + s.toFixed(4) + ")");
|
|
204
|
+
// 自社の点:着いたときに輪が 1 回広がって消える(最終状態では出さない)
|
|
205
|
+
if (p.ring){
|
|
206
|
+
var rt = !fp && o.step === k && t !== Infinity ? D.clamp((t - o.at - P.fade * 0.6) / 0.8) : 1;
|
|
207
|
+
p.ring.setAttribute("cx", x.toFixed(2)); p.ring.setAttribute("cy", y.toFixed(2));
|
|
208
|
+
p.ring.setAttribute("r", (p.r * (1 + 1.6 * rt)).toFixed(2));
|
|
209
|
+
p.ring.setAttribute("opacity", (rt > 0 && rt < 1 ? 0.8 * (1 - rt) : 0).toFixed(3));
|
|
210
|
+
}
|
|
211
|
+
if (p.trail){
|
|
212
|
+
p.trail.setAttribute("x1", x0.toFixed(2)); p.trail.setAttribute("y1", y0.toFixed(2));
|
|
213
|
+
p.trail.setAttribute("x2", x.toFixed(2)); p.trail.setAttribute("y2", y.toFixed(2));
|
|
214
|
+
if (fm){ p.trail.setAttribute("x2", self.X(o.to.x).toFixed(2)); p.trail.setAttribute("y2", self.Y(o.to.y).toFixed(2)); }
|
|
215
|
+
p.trail.setAttribute("opacity", fm ? PV : m > 0 ? 0.9 : 0);
|
|
216
|
+
// 出発点の丸は跡と同じ濃さ。矢じりは今の点の丸の手前(丸の縁から 3px)に、跡が丸と出発点の丸の外に出ている長さがあるときだけ
|
|
217
|
+
var hx = fm ? self.X(o.to.x) : x, hy = fm ? self.Y(o.to.y) : y, len = Math.hypot(hx - x0, hy - y0), ho = fm ? PV : m > 0 ? 0.9 : 0;
|
|
218
|
+
p.from.setAttribute("opacity", ho);
|
|
219
|
+
if (len > p.r * 1.8 + 3 + 14 + 4){
|
|
220
|
+
var ux = (hx - x0) / len, uy = (hy - y0) / len, tip = p.r * s + 3;
|
|
221
|
+
p.head.setAttribute("transform", "translate(" + (hx - ux * tip).toFixed(2) + " " + (hy - uy * tip).toFixed(2) + ") rotate(" + (Math.atan2(uy, ux) * 180 / Math.PI).toFixed(1) + ")");
|
|
222
|
+
p.head.setAttribute("opacity", ho);
|
|
223
|
+
} else { p.head.removeAttribute("transform"); p.head.setAttribute("opacity", 0); } // 作った直後と同じ(呼ぶ順で DOM が変わらない)
|
|
224
|
+
}
|
|
225
|
+
if (p.lab2){
|
|
226
|
+
p.lab2.setAttribute("x", self.X(o.to.x).toFixed(2)); p.lab2.setAttribute("y", (self.Y(o.to.y) - p.r - 14).toFixed(2));
|
|
227
|
+
p.lab2.setAttribute("opacity", fm ? PV.toFixed(3) : pr(o.to.step, o.to.at + P.move * 0.8, 0.3).toFixed(3));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// heatmap-core 1.0.0: m-heatmap's calculations (a library part, Egatari spec §6.1): row normalisation, the colour domain and
|
|
2
|
+
// the place of a value on it, mixing in OKLab and WCAG contrast (the text colour and halo per cell), the layout (cell size,
|
|
3
|
+
// label thinning, vertical column labels), the size of the numbers in the cells and the steps. Pure functions of their
|
|
4
|
+
// arguments: no DOM, no state. m-heatmap 2.0.0 requires it; tools/test-heatmap.mjs tests it without a browser. Moved from
|
|
5
|
+
// m-heatmap 1.13.0 (its `static calc`) unchanged, except that layout's notes no longer start with "m-heatmap: ".
|
|
6
|
+
// returns {clean, normalizeRows, domain, frac, mix, contrast, lum, pick, est, layout, shown, numberSize, steps}
|
|
7
|
+
egatariParts.define({name: "heatmap-core", version: "1.0.0", requires: {}}, function(){
|
|
8
|
+
"use strict";
|
|
9
|
+
function clean(v){ return +(+v).toFixed(10); }
|
|
10
|
+
// 行ごとの割合(混同行列)。行の和が 0 なら 0 のまま
|
|
11
|
+
function normalizeRows(values){
|
|
12
|
+
return values.map(function(row){
|
|
13
|
+
var s = row.reduce(function(a, v){ return a + v; }, 0);
|
|
14
|
+
return row.map(function(v){ return s ? v / s : 0; });
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
// 色の範囲:sequential は [min(0, 最小), 最大]、diverging は center を真ん中に対称(|値 − center| の最大)
|
|
18
|
+
function domain(values, kind, center, range){
|
|
19
|
+
var all = [].concat.apply([], values).filter(function(v){ return isFinite(v); });
|
|
20
|
+
if (range && range.length === 2) return {lo: +range[0], hi: +range[1], c: kind === "diverging" ? center : (+range[0] + +range[1]) / 2};
|
|
21
|
+
var lo = Math.min.apply(null, all), hi = Math.max.apply(null, all);
|
|
22
|
+
if (kind === "diverging"){
|
|
23
|
+
var m = Math.max(Math.abs(hi - center), Math.abs(lo - center)) || 1;
|
|
24
|
+
return {lo: clean(center - m), hi: clean(center + m), c: center};
|
|
25
|
+
}
|
|
26
|
+
lo = Math.min(0, lo);
|
|
27
|
+
if (hi === lo) hi = lo + 1;
|
|
28
|
+
return {lo: lo, hi: hi, c: clean((lo + hi) / 2)};
|
|
29
|
+
}
|
|
30
|
+
// 値 → 混ぜる割合 f(sequential は 0〜1、diverging は −1〜1。負は lowtone の側)。範囲の外は端にそろえる
|
|
31
|
+
function frac(v, kind, d){
|
|
32
|
+
if (kind === "diverging"){
|
|
33
|
+
var f = v >= d.c ? (d.hi > d.c ? (v - d.c) / (d.hi - d.c) : 0) : (d.lo < d.c ? -(d.c - v) / (d.c - d.lo) : 0);
|
|
34
|
+
return Math.max(-1, Math.min(1, f));
|
|
35
|
+
}
|
|
36
|
+
return Math.max(0, Math.min(1, (v - d.lo) / (d.hi - d.lo)));
|
|
37
|
+
}
|
|
38
|
+
// ---- 色(sRGB 0〜255 の [r, g, b]) ----
|
|
39
|
+
function lin(c){ c /= 255; return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); }
|
|
40
|
+
function lum(c){ return 0.2126 * lin(c[0]) + 0.7152 * lin(c[1]) + 0.0722 * lin(c[2]); }
|
|
41
|
+
function oklab(c){
|
|
42
|
+
var r = lin(c[0]), g = lin(c[1]), b = lin(c[2]);
|
|
43
|
+
var l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b), m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b), s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
44
|
+
return [0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s, 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s];
|
|
45
|
+
}
|
|
46
|
+
function fromOklab(o){
|
|
47
|
+
var l = Math.pow(o[0] + 0.3963377774 * o[1] + 0.2158037573 * o[2], 3), m = Math.pow(o[0] - 0.1055613458 * o[1] - 0.0638541728 * o[2], 3), s = Math.pow(o[0] - 0.0894841775 * o[1] - 1.2914855480 * o[2], 3);
|
|
48
|
+
var f = function(x){ x = Math.max(0, Math.min(1, x)); return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055); };
|
|
49
|
+
return [f(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s), f(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s), f(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s)];
|
|
50
|
+
}
|
|
51
|
+
function contrast(a, b){ var x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); }
|
|
52
|
+
// color-mix(in oklab, tone p, bg) の色(oklab での直線の補間)
|
|
53
|
+
function mix(tone, bg, p){ var a = oklab(tone), b = oklab(bg); return fromOklab([0, 1, 2].map(function(i){ return b[i] + (a[i] - b[i]) * p; })); }
|
|
54
|
+
var MIN = 4.6; // 4.5:1 に、ブラウザの丸めの分の余裕
|
|
55
|
+
// 字の色:割合 p(0〜1)の色(セルの色は変えない。色がデータなので)に対して、--fg と --bg のうちコントラストの高い方。
|
|
56
|
+
// それでも MIN に届かない(明るさがちょうど中くらいの帯)ときは halo:字の周りに反対の色の細い縁(paint-order: stroke)を付ける。
|
|
57
|
+
// 返すのは {p, text: "fg" | "bg", cr, halo}
|
|
58
|
+
function pick(tone, bg, fg, p){
|
|
59
|
+
var c = mix(tone, bg, p), a = contrast(c, fg), b = contrast(c, bg), o = a >= b ? {p: p, text: "fg", cr: a} : {p: p, text: "bg", cr: b};
|
|
60
|
+
o.halo = o.cr < MIN;
|
|
61
|
+
return o;
|
|
62
|
+
}
|
|
63
|
+
// ---- 配置(字の幅は見積もり:半角 0.56 字、全角 1 字) ----
|
|
64
|
+
// セルの数字は表の数字の幅(0.7 字。−も同じ)で見積もる
|
|
65
|
+
function est(s, size, an){ an = an || 0.56; return [...String(s)].reduce(function(a, c){ return a + (/[\u0000-ɏ−]/.test(c) ? an : 1); }, 0) * size; }
|
|
66
|
+
// o: {W, H, rows, cols, legend: [字], xl, yl, rotate: "auto" | "0" | "90"}。
|
|
67
|
+
// 字は 26 px(入らなければ 24 px。それより小さくしない)。列の名前は横か縦(rotate)。入らなければ k 個おきに出す
|
|
68
|
+
function layout(o){
|
|
69
|
+
var nr = o.rows.length, nc = o.cols.length, best = null;
|
|
70
|
+
var rot = String(o.rotate || "auto"), orients = rot === "0" ? ["h"] : rot === "90" ? ["v"] : ["h", "v"];
|
|
71
|
+
var legW = Math.max.apply(null, [0].concat((o.legend || []).map(function(s){ return est(s, 24); })));
|
|
72
|
+
[26, 24].forEach(function(fs){
|
|
73
|
+
var rowW = Math.max.apply(null, [0].concat(o.rows.map(function(s){ return est(s, fs); })));
|
|
74
|
+
var colW = Math.max.apply(null, [0].concat(o.cols.map(function(s){ return est(s, fs); })));
|
|
75
|
+
var left = (o.yl ? 40 : 0) + (rowW ? rowW + 14 : 4), right = o.legend ? 22 + 24 + 10 + legW + 4 : 4;
|
|
76
|
+
orients.forEach(function(or){
|
|
77
|
+
var top = (o.xl ? 40 : 0) + (colW ? (or === "h" ? Math.ceil(fs * 1.25) + 8 : Math.ceil(colW) + 14) : 4);
|
|
78
|
+
var cs = Math.min((o.W - left - right) / nc, (o.H - top - 4) / nr, 180);
|
|
79
|
+
if (!(cs > 0)) cs = 0;
|
|
80
|
+
var kc = colW ? Math.max(1, Math.ceil((or === "h" ? colW + 10 : fs * 1.25) / Math.max(cs, 1e-6) - 1e-9)) : 1;
|
|
81
|
+
var kr = rowW ? Math.max(1, Math.ceil(fs * 1.25 / Math.max(cs, 1e-6) - 1e-9)) : 1;
|
|
82
|
+
var c = {fs: fs, orient: or, left: left, right: right, top: top, cs: cs, kc: kc, kr: kr, rowW: rowW, colW: colW, legW: legW};
|
|
83
|
+
var score = function(x){ return (x.kc - 1) + (x.kr - 1); };
|
|
84
|
+
if (!best || score(c) < score(best) || (score(c) === score(best) && c.cs > best.cs + 0.5 && score(c) > 0)) best = c;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
var b = best, gw = nc * b.cs, gh = nr * b.cs, total = b.left + gw + b.right;
|
|
88
|
+
b.x0 = Math.max(0, (o.W - total) / 2); // 左の端(行の名前の左)
|
|
89
|
+
b.gx = b.x0 + b.left; b.gy = b.top + Math.max(0, (o.H - b.top - gh - 4) / 2);
|
|
90
|
+
b.gw = gw; b.gh = gh;
|
|
91
|
+
b.notes = []; // messages without a prefix: m-heatmap reports them with its own
|
|
92
|
+
if (b.kc > 1) b.notes.push(nc + " columns are too many to label at 24 px; every " + ord(b.kc) + " column label is shown");
|
|
93
|
+
if (b.kr > 1) b.notes.push(nr + " rows are too many to label at 24 px; every " + ord(b.kr) + " row label is shown");
|
|
94
|
+
if (b.cs < 4) b.notes.push("the element (" + o.W + "×" + o.H + " px) is too small for " + nr + "×" + nc + " cells");
|
|
95
|
+
return b;
|
|
96
|
+
}
|
|
97
|
+
function ord(k){ return k + (k % 10 === 2 && k % 100 !== 12 ? "nd" : k % 10 === 3 && k % 100 !== 13 ? "rd" : "th"); }
|
|
98
|
+
// 出す名前の番号(k 個おき、0 から)
|
|
99
|
+
function shown(n, k){ var out = []; for (var i = 0; i < n; i += k) out.push(i); return out; }
|
|
100
|
+
// セルの数字の大きさ:lines 行(1 か 2)の字 texts が cs の正方形に収まる最も大きい大きさ(34 px まで)。24 px でも入らなければ 0
|
|
101
|
+
function numberSize(cs, texts, lines){
|
|
102
|
+
var w = Math.max.apply(null, [0].concat(texts.map(function(s){ return est(s, 1, 0.7); })));
|
|
103
|
+
for (var f = Math.min(34, Math.floor(cs * 0.28)); f >= 24; f--){
|
|
104
|
+
if (w * f <= cs - 12 && lines * f * 1.2 <= cs - 6) return f;
|
|
105
|
+
}
|
|
106
|
+
return w * 24 <= cs - 12 && lines * 24 * 1.2 <= cs - 6 ? 24 : 0;
|
|
107
|
+
}
|
|
108
|
+
// 段階:セルごとの段階 cell[r][c]、強調の段階、全体の段階の数
|
|
109
|
+
function steps(nr, nc, build, highlight){
|
|
110
|
+
var cell = [], k = 1, hs;
|
|
111
|
+
for (var r = 0; r < nr; r++){ cell.push([]); for (var c = 0; c < nc; c++) cell[r].push(build === "rows" ? r + 1 : 1); }
|
|
112
|
+
var last = build === "rows" ? nr : 1;
|
|
113
|
+
hs = (highlight || []).map(function(h, i){
|
|
114
|
+
var st = h.length > 2 && isFinite(h[2]) ? Math.max(1, Math.round(h[2])) : build === "cells" ? 2 + i : build === "rows" ? nr + 1 : 1;
|
|
115
|
+
return {r: h[0], c: h[1], st: st};
|
|
116
|
+
});
|
|
117
|
+
k = Math.max.apply(null, [last].concat(hs.map(function(h){ return h.st; })));
|
|
118
|
+
return {cell: cell, hl: hs, steps: Math.max(1, k)};
|
|
119
|
+
}
|
|
120
|
+
return {clean: clean, normalizeRows: normalizeRows, domain: domain, frac: frac, mix: mix, contrast: contrast, lum: lum, pick: pick,
|
|
121
|
+
est: est, layout: layout, shown: shown, numberSize: numberSize, steps: steps, MIN: MIN};
|
|
122
|
+
});
|