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,348 @@
|
|
|
1
|
+
// m-cycle:循環の図。段階の箱を円(横に長い場所では楕円)の上に 12 時から時計回りに並べ、となりの段階へ円に沿った矢印でつなぐ
|
|
2
|
+
// <m-cycle style="height:420px"><script type="application/json">
|
|
3
|
+
// {"center": {"label": "PDCA"},
|
|
4
|
+
// "nodes": [{"label": "計画", "note": "目標と手順"}, {"label": "実行"}, {"label": "評価"}, {"label": "改善"}]}
|
|
5
|
+
// (JSON の終わり)</m-cycle>
|
|
6
|
+
// 座標はデータに書かない(docs/conventions.md §2)。配列の順に回り、最後から最初へ戻る矢印は自動で引く(最後の段階と一緒に出る)
|
|
7
|
+
// 段階は 3〜8 個を想定。箱の幅は字数から見積もる(字の読み込みを待たない)。入らなければ字を 24px まで縮め、それでも入らなければ ctx.report("size", …)
|
|
8
|
+
// center(任意):真ん中の名前。最初の段階と一緒に出る(center.step で変えられる)
|
|
9
|
+
// 段階:既定は 1 段階に 1 つ(per-step で n 個ずつ、node の step で直接、at で段階の中の開始秒)
|
|
10
|
+
// 見せ方(docs/conventions.md §2.5):fade(既定。箱が下から 12 px 上がりながら現れてから入ってくる矢印を引く)・draw(矢印を先に引き、
|
|
11
|
+
// その先に箱が前の箱の側から 12 px 寄りながら出る)・grow(矢印を引きながら、箱が前の箱の側から 12 px 寄って 0.92 → 1 に大きくなる)。
|
|
12
|
+
// 箱の動きはどれも 12 px まで。段階の数・長さ・合図・最後の中身はどれも同じ
|
|
13
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
14
|
+
// 式(tex)は組み立てのときに KaTeX で描く(spec §6.2):build.fields の nodes[].tex・center.tex を作り手が描いて texHtml を足し、
|
|
15
|
+
// この部品は markup-reader で決まった要素と属性だけを読んで置く(再生のときに KaTeX は動かない)。描いた結果がなければ tex を字のまま出して知らせる。
|
|
16
|
+
// データの問題(ない箱を指す辺)と、入らないときは ctx.report で知らせる(1.x の console.warn の代わり)。
|
|
17
|
+
// 配置を決める内部の関数は arrange(size)(1.x の layout(size)。2.0 の layout(ctx) は再生器が呼ぶので名前を分けた)
|
|
18
|
+
egatariParts.define({name: "cycle", version: "2.0.4", requires: {base: "1.2.0", "markup-reader": "1.0.2"}, element: "m-cycle"}, function(deps){
|
|
19
|
+
"use strict";
|
|
20
|
+
var base = deps.base, MR = deps["markup-reader"];
|
|
21
|
+
var Part = class extends base.MotionElement {
|
|
22
|
+
static partName = "cycle"; // the registry name (define meta name), for report prefixes
|
|
23
|
+
// 組み立てのときに描く欄(spec §6.2)。式の意味は字(tex)でも持つので、KaTeX の出力は HTML だけ
|
|
24
|
+
static build = {fields: {"nodes[].tex": "katex", "center.tex": "katex"}, options: {katex: {output: "html"}}};
|
|
25
|
+
static variants = ["fade", "draw", "grow"];
|
|
26
|
+
// データの形(kit/shape.js)
|
|
27
|
+
static shape = {
|
|
28
|
+
schema: {type: "object", additionalProperties: false, required: ["nodes"], properties: {
|
|
29
|
+
nodes: {type: "array", minItems: 2, items: {type: "object", properties: {
|
|
30
|
+
id: {type: ["string", "integer"]}, label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, note: {type: "string"}, tone: {type: "string"},
|
|
31
|
+
step: {type: "integer"}, at: {type: "number"}}}},
|
|
32
|
+
center: {type: "object", properties: {label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, note: {type: "string"}, tone: {type: "string"},
|
|
33
|
+
step: {type: "integer"}, at: {type: "number"}}},
|
|
34
|
+
edges: {type: "array", items: {type: "object", required: ["from", "to"], properties: {
|
|
35
|
+
from: {type: ["string", "integer"]}, to: {type: ["string", "integer"]}, label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"},
|
|
36
|
+
step: {type: "integer"}, at: {type: "number"}}}},
|
|
37
|
+
renderers: {type: "object"}}},
|
|
38
|
+
example: {center: {label: "PDCA"}, nodes: [{label: "計画"}, {label: "実行"}, {label: "評価"}, {label: "改善"}]},
|
|
39
|
+
};
|
|
40
|
+
static props = {
|
|
41
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップに出す箱の数(0 = 全部をステップ 1 で)"},
|
|
42
|
+
size: {type: "number", default: 26, doc: "箱の字の大きさ(px。入らなければ 24 まで縮める)"},
|
|
43
|
+
dur: {type: "number", default: 0.8, doc: "1 つの項目(入ってくる矢印と箱)が現れる秒数"},
|
|
44
|
+
stagger: {type: "number", default: 0.3, doc: "同じステップの箱の出だしのずれ(秒)"},
|
|
45
|
+
};
|
|
46
|
+
get steps(){
|
|
47
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
48
|
+
var p = this.plan(), m = p.center ? p.center.step : 0;
|
|
49
|
+
p.stages.concat(p.arrows, p.edges).forEach(function(o){ m = Math.max(m, o.step); });
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
plan(){
|
|
53
|
+
if (this._plan) return this._plan;
|
|
54
|
+
var notes = this._notes = []; // データの問題:mount が ctx.report で知らせる(段階の数を数えるときには ctx がない)
|
|
55
|
+
var P = this.props, per = P["per-step"], T = P.dur, data = this.data || {}, seen = {};
|
|
56
|
+
var stages = (data.nodes || []).map(function(n, i){
|
|
57
|
+
var step = n.step !== undefined ? n.step : per > 0 ? Math.floor(i / per) + 1 : 1, j = seen[step] = (seen[step] || 0) + 1;
|
|
58
|
+
return {n: n, i: i, step: step, at0: n.at !== undefined ? n.at : +((j - 1) * P.stagger).toFixed(3)};
|
|
59
|
+
});
|
|
60
|
+
stages.forEach(function(o){ o.at = o.at0; });
|
|
61
|
+
var N = stages.length, arrows = [];
|
|
62
|
+
// 矢印 i:段階 i から i + 1 へ(最後は最初へ戻る)。後に出る端の段階と一緒に出る
|
|
63
|
+
for (var i = 0; i < N && N > 1; i++){
|
|
64
|
+
var a = stages[i], b = stages[(i + 1) % N], closing = i === N - 1;
|
|
65
|
+
var owner = closing ? (a.step >= b.step ? a : b) : (b.step >= a.step ? b : a);
|
|
66
|
+
// ふつうは入っていく先の箱と一緒(見せ方で順が変わる)。戻る矢印と、先の箱がもう出ているものは、持ち主の箱が出終わってから
|
|
67
|
+
var withBox = !closing && owner === b;
|
|
68
|
+
arrows.push({i: i, from: a, to: b, step: owner.step, owner: owner, withBox: withBox, at: withBox ? owner.at : +(owner.at + T).toFixed(3)});
|
|
69
|
+
}
|
|
70
|
+
stages.forEach(function(o){ o.inArrow = null; });
|
|
71
|
+
arrows.forEach(function(r){ if (r.withBox) r.to.inArrow = r; });
|
|
72
|
+
var c = data.center ? {n: data.center, step: data.center.step !== undefined ? data.center.step : stages.length ? stages[0].step : 1, at: data.center.at || 0} : null;
|
|
73
|
+
var byId = {};
|
|
74
|
+
stages.forEach(function(o){ if (o.n.id !== undefined) byId[o.n.id] = o; });
|
|
75
|
+
var edges = (data.edges || []).map(function(e){
|
|
76
|
+
var a = byId[e.from], b = byId[e.to];
|
|
77
|
+
if (!a || !b){ notes.push("[cycle] an edge refers to an unknown node: " + JSON.stringify(e.from) + " → " + JSON.stringify(e.to) + " (not drawn)"); return null; }
|
|
78
|
+
var step = e.step !== undefined ? e.step : Math.max(a.step, b.step), at = 0;
|
|
79
|
+
[a, b].forEach(function(o){ if (o.step === step) at = Math.max(at, o.at + T); });
|
|
80
|
+
return {e: e, a: a, b: b, step: step, at: e.at !== undefined ? e.at : at};
|
|
81
|
+
}).filter(Boolean);
|
|
82
|
+
return (this._plan = {stages: stages, arrows: arrows, center: c, edges: edges});
|
|
83
|
+
}
|
|
84
|
+
mount(ctx){
|
|
85
|
+
var P = this.props, D = base, self = this;
|
|
86
|
+
this.variant = base.variant(this);
|
|
87
|
+
this.plan();
|
|
88
|
+
this._notes.forEach(function(m){ ctx.report("data", m); });
|
|
89
|
+
this.texSink = MR.sink(this, ctx);
|
|
90
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
91
|
+
var W = this.W = this.clientWidth, H = this.H = this.clientHeight;
|
|
92
|
+
this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
93
|
+
this.reportLayout = function(msg){ ctx.report("layout", msg); }; // draw の知らせ(名前の置き場がない辺)
|
|
94
|
+
// size:24 より小さい字は使わない(24 にする)。数でなければ既定の 26
|
|
95
|
+
var s0 = P.size;
|
|
96
|
+
if (!(typeof s0 === "number" && isFinite(s0))){ ctx.report("attr", "[cycle] size=\"" + this.getAttribute("size") + "\" is not a number (26 is used)"); s0 = 26; }
|
|
97
|
+
else if (s0 < 24){ ctx.report("attr", "[cycle] size=\"" + this.getAttribute("size") + "\" is below 24 (text is at least 24px; 24 is used)"); s0 = 24; }
|
|
98
|
+
var L = null;
|
|
99
|
+
for (var s = s0; ; s = Math.max(24, s - 2)){
|
|
100
|
+
L = this.arrange(s);
|
|
101
|
+
if (L.fits || s <= 24) break;
|
|
102
|
+
}
|
|
103
|
+
if (!L.fits) ctx.report("size", "[cycle] the cycle does not fit its box even at 24px (" + L.why + "); make the element larger or shorten the labels");
|
|
104
|
+
this.draw(L);
|
|
105
|
+
// 読み上げ:最後の形(一回りと、ほかのつながり)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
106
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
107
|
+
this.setAttribute("role", "img");
|
|
108
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
|
|
109
|
+
this.texSink.flush(); // what the formulas have to report, once per kind (spec §6.2)
|
|
110
|
+
}
|
|
111
|
+
arrange(size){
|
|
112
|
+
var self = this, W = this.W, H = this.H, pl = this.plan(), N = pl.stages.length, why = [];
|
|
113
|
+
var th = function(i){ return -Math.PI / 2 + 2 * Math.PI * i / N; };
|
|
114
|
+
var boxes = pl.stages.map(function(o, i){
|
|
115
|
+
var lines = labelLines(o.n, size, textFill(o.n.tone));
|
|
116
|
+
// 強調の箱(--emph-tint の地)の中の補足は --fg(--muted では 4.5:1 に届かない。共通の決まり §2.3)
|
|
117
|
+
if (o.n.note) lines.push({text: o.n.note, size: 24, fill: o.n.tone === "emph" ? "var(--fg)" : "var(--muted)"});
|
|
118
|
+
var bs = boxSize(self, lines);
|
|
119
|
+
return {o: o, bs: bs, w: bs.w, h: bs.h, th: th(i)};
|
|
120
|
+
});
|
|
121
|
+
var cen = null;
|
|
122
|
+
if (pl.center){
|
|
123
|
+
var cl = labelLines(pl.center.n, size + 4).map(function(l){ l.weight = 700; l.fill = tone(pl.center.n.tone); return l; });
|
|
124
|
+
if (pl.center.n.note) cl.push({text: pl.center.n.note, size: 24, fill: "var(--muted)"});
|
|
125
|
+
cen = boxSize(self, cl);
|
|
126
|
+
}
|
|
127
|
+
// 縦:箱と円の上端から下端までが H に入る最大の ry(二分法)。横:箱と円が W に入る最大の rx(縦の 1.9 倍まで)。
|
|
128
|
+
// 円は縦に長くしない(ry ≤ rx の上限)
|
|
129
|
+
var span = function(ry){
|
|
130
|
+
var lo = -ry, hi = ry;
|
|
131
|
+
boxes.forEach(function(b){ var y = ry * Math.sin(b.th); lo = Math.min(lo, y - b.h / 2); hi = Math.max(hi, y + b.h / 2); });
|
|
132
|
+
return [lo, hi];
|
|
133
|
+
};
|
|
134
|
+
var rxMax = W / 2 - 4;
|
|
135
|
+
// 12 時と 6 時の箱(cos = 0)は rx によらない:要素より広ければ入らない
|
|
136
|
+
boxes.forEach(function(b, i){ var c = Math.abs(Math.cos(b.th)); if (c > 1e-6) rxMax = Math.min(rxMax, (W / 2 - 3 - b.w / 2) / c); else if (b.w > W - 6) why.push("box " + (i + 1) + " is " + Math.ceil(b.w) + "px wide, wider than the element (" + W + "px)"); });
|
|
137
|
+
var a = 0, b = H;
|
|
138
|
+
for (var it = 0; it < 40; it++){ var m = (a + b) / 2, sp = span(m); if (sp[1] - sp[0] <= H - 6) a = m; else b = m; }
|
|
139
|
+
var ry = Math.max(0, Math.min(a, rxMax)), sp = span(ry), cy = 3 - sp[0] + (H - 6 - (sp[1] - sp[0])) / 2, cx = W / 2;
|
|
140
|
+
var rx = Math.max(0, Math.min(rxMax, ry * 1.9));
|
|
141
|
+
if (ry < 40 || rx < 40) why.push("no room for the circle");
|
|
142
|
+
var P = function(t){ return [cx + rx * Math.cos(t), cy + ry * Math.sin(t)]; };
|
|
143
|
+
boxes.forEach(function(b){ var p = P(b.th); b.cx = p[0]; b.cy = p[1]; b.x = p[0] - b.w / 2; b.y = p[1] - b.h / 2; });
|
|
144
|
+
// 箱どうしが近すぎないか
|
|
145
|
+
for (var i = 0; i < N; i++) for (var j = i + 1; j < N; j++){
|
|
146
|
+
var p = boxes[i], q = boxes[j];
|
|
147
|
+
if (p.x < q.x + q.w + 8 && q.x < p.x + p.w + 8 && p.y < q.y + q.h + 8 && q.y < p.y + p.h + 8) why.push("boxes " + (i + 1) + " and " + (j + 1) + " overlap");
|
|
148
|
+
}
|
|
149
|
+
// 矢印:円に沿って、箱 i の外へ出たところから、箱 i+1 に入る手前まで(箱から 8px 空ける)
|
|
150
|
+
var inside = function(bx, t){ var p = P(t); return p[0] > bx.x - 8 && p[0] < bx.x + bx.w + 8 && p[1] > bx.y - 8 && p[1] < bx.y + bx.h + 8; };
|
|
151
|
+
var arcs = pl.arrows.map(function(r){
|
|
152
|
+
var A = boxes[r.i], B = boxes[(r.i + 1) % N], t0 = A.th, t1 = r.i === N - 1 ? B.th + 2 * Math.PI : B.th, d = 0.002;
|
|
153
|
+
while (t0 < t1 && inside(A, t0)) t0 += d;
|
|
154
|
+
while (t1 > t0 && inside(B, t1)) t1 -= d;
|
|
155
|
+
var len = 0, q = P(t0);
|
|
156
|
+
for (var t = t0 + d; t <= t1; t += d){ var p2 = P(t); len += Math.hypot(p2[0] - q[0], p2[1] - q[1]); q = p2; }
|
|
157
|
+
if (len < 30) why.push("no room for the arrow from " + (r.i + 1));
|
|
158
|
+
return {r: r, t0: t0, t1: t1, len: len};
|
|
159
|
+
});
|
|
160
|
+
if (cen){
|
|
161
|
+
var hw = cen.w / 2 + 16, hh = cen.h / 2 + 16;
|
|
162
|
+
if (Math.pow(hw / rx, 2) + Math.pow(hh / ry, 2) > 1) why.push("the center label is too large for the circle");
|
|
163
|
+
boxes.forEach(function(b){ if (Math.abs(b.cx - cx) < b.w / 2 + hw && Math.abs(b.cy - cy) < b.h / 2 + hh) why.push("the center label touches a box"); });
|
|
164
|
+
}
|
|
165
|
+
return {fits: !why.length, why: why.join("; "), size: size, boxes: boxes, arcs: arcs, cen: cen, cx: cx, cy: cy, rx: rx, ry: ry};
|
|
166
|
+
}
|
|
167
|
+
draw(L){
|
|
168
|
+
var D = base, self = this, svg = this.svg;
|
|
169
|
+
var gA = D.el("g", {}, svg), gB = D.el("g", {}, svg), gE = D.el("g", {}, svg), gC = D.el("g", {}, svg);
|
|
170
|
+
this.L = L;
|
|
171
|
+
this.pt = function(t){ return [L.cx + L.rx * Math.cos(t), L.cy + L.ry * Math.sin(t)]; };
|
|
172
|
+
var rects = {};
|
|
173
|
+
this.boxes = L.boxes.map(function(b){
|
|
174
|
+
var col = tone(b.o.n.tone), g = D.el("g", {opacity: 0}, gB);
|
|
175
|
+
D.el("rect", {class: "box", x: b.x.toFixed(1), y: b.y.toFixed(1), width: b.w, height: b.h, rx: 12, fill: boxFill(b.o.n.tone), stroke: col, "stroke-width": b.o.n.tone === "emph" ? 3 : 2.2}, g);
|
|
176
|
+
boxDraw(self, g, b.x, b.y, b.bs);
|
|
177
|
+
if (b.o.n.id !== undefined) rects[b.o.n.id] = b;
|
|
178
|
+
return {b: b, g: g, o: b.o};
|
|
179
|
+
});
|
|
180
|
+
this.arcs = L.arcs.map(function(a){
|
|
181
|
+
var col = "var(--muted)", g = D.el("g", {opacity: 0}, gA);
|
|
182
|
+
return {a: a, r: a.r, g: g, path: D.el("path", {d: "", fill: "none", stroke: col, "stroke-width": 3, "stroke-linecap": "round"}, g),
|
|
183
|
+
head: D.el("path", {d: "M0,0L-16,-7L-16,7Z", fill: col}, g)};
|
|
184
|
+
});
|
|
185
|
+
// 前の段階の箱から、この箱へ向かう向き(draw と grow で箱が寄ってくる向き)
|
|
186
|
+
this.boxes.forEach(function(o, i){
|
|
187
|
+
var q = L.boxes[(i + L.boxes.length - 1) % L.boxes.length], dx = o.b.cx - q.cx, dy = o.b.cy - q.cy, dl = Math.hypot(dx, dy) || 1;
|
|
188
|
+
o.dir = [dx / dl, dy / dl];
|
|
189
|
+
});
|
|
190
|
+
this.center = null;
|
|
191
|
+
if (L.cen){
|
|
192
|
+
var g = D.el("g", {opacity: 0}, gC);
|
|
193
|
+
boxDraw(self, g, L.cx - L.cen.w / 2, L.cy - L.cen.h / 2, L.cen);
|
|
194
|
+
this.center = {g: g};
|
|
195
|
+
}
|
|
196
|
+
this.edges = this.plan().edges.map(function(x){
|
|
197
|
+
var e = x.e, A = rects[e.from], B = rects[e.to];
|
|
198
|
+
if (!A || !B) return null;
|
|
199
|
+
var dx = B.cx - A.cx, dy = B.cy - A.cy, Lh = Math.hypot(dx, dy) || 1;
|
|
200
|
+
var cut = function(R, sx, sy){ var s = Math.min(sx ? (R.w / 2 + 6) / Math.abs(sx) : Infinity, sy ? (R.h / 2 + 6) / Math.abs(sy) : Infinity); return [R.cx + sx * s, R.cy + sy * s]; };
|
|
201
|
+
var p0 = cut(A, dx / Lh, dy / Lh), p1 = cut(B, -dx / Lh, -dy / Lh), col = e.tone ? tone(e.tone) : "var(--muted)";
|
|
202
|
+
var g = D.el("g", {opacity: 0}, gE), ux = p1[0] - p0[0], uy = p1[1] - p0[1], l2 = Math.hypot(ux, uy) || 1;
|
|
203
|
+
D.el("line", {x1: p0[0].toFixed(1), y1: p0[1].toFixed(1), x2: (p1[0] - ux / l2 * 14).toFixed(1), y2: (p1[1] - uy / l2 * 14).toFixed(1), stroke: col, "stroke-width": 3, "stroke-dasharray": e.dash === false ? "none" : "8 6"}, g);
|
|
204
|
+
D.el("path", {d: "M0,0L-16,-7L-16,7Z", fill: col, transform: "translate(" + p1[0].toFixed(1) + " " + p1[1].toFixed(1) + ") rotate(" + (Math.atan2(uy, ux) * 180 / Math.PI).toFixed(1) + ")"}, g);
|
|
205
|
+
if (e.label){
|
|
206
|
+
// 名前は線の横に(線・真ん中の名前・箱と重ならない所。なければ知らせる)
|
|
207
|
+
var obst = L.boxes.map(function(b){ return {x: b.x, y: b.y, w: b.w, h: b.h}; });
|
|
208
|
+
if (L.cen) obst.push({x: L.cx - L.cen.w / 2, y: L.cy - L.cen.h / 2, w: L.cen.w, h: L.cen.h});
|
|
209
|
+
var at = sideLabel(p0, p1, est(e.label, 24, self), 30, obst, self.W, self.H);
|
|
210
|
+
if (!at.ok) self.reportLayout("[cycle] the label \"" + e.label + "\" of the edge " + JSON.stringify(e.from) + " → " + JSON.stringify(e.to) + " has no free place beside its line (it may overlap; make the element larger or the label shorter)");
|
|
211
|
+
D.mtext(g, at.x, at.y, e.label, {"text-anchor": "middle", "font-size": 24, fill: e.tone ? col : "var(--muted)"});
|
|
212
|
+
}
|
|
213
|
+
return {g: g, step: x.step, at: x.at};
|
|
214
|
+
}).filter(Boolean);
|
|
215
|
+
}
|
|
216
|
+
// 最後の形を 1 文で(読み上げの名前):「循環(PDCA):計画:目標と手順 → 実行 → 評価 → 改善 → 計画に戻る。ほかのつながり:計画 → 評価(見直し)」
|
|
217
|
+
summary(ja){
|
|
218
|
+
var pl = this.plan(), one = function(n){ return String(n.label || n.tex || "").replace(/\s*\n\s*/g, " ").replace(/\*/g, ""); };
|
|
219
|
+
var full = function(n){ return one(n) + (n.note ? (ja ? ":" : ": ") + n.note : ""); };
|
|
220
|
+
var st = pl.stages.map(function(o){ return full(o.n); });
|
|
221
|
+
var s = (ja ? "循環" : "Cycle") + (pl.center ? (ja ? "(" + full(pl.center.n) + ")" : " (" + full(pl.center.n) + ")") : "") + (ja ? ":" : ": ") +
|
|
222
|
+
st.join(" → ") + (st.length > 1 ? (ja ? " → " + one(pl.stages[0].n) + "に戻る" : " → back to " + one(pl.stages[0].n)) : "");
|
|
223
|
+
var ed = pl.edges.map(function(x){ return one(x.a.n) + " → " + one(x.b.n) + (x.e.label ? (ja ? "(" + x.e.label + ")" : " (" + x.e.label + ")") : ""); });
|
|
224
|
+
if (ed.length) s += (ja ? "。ほかのつながり:" : ". Other links: ") + ed.join(ja ? "、" : ", ");
|
|
225
|
+
return s;
|
|
226
|
+
}
|
|
227
|
+
duration(k){
|
|
228
|
+
var T = this.props.dur, p = this.plan(), d = 0;
|
|
229
|
+
p.stages.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + T); });
|
|
230
|
+
p.arrows.forEach(function(o){ if (o.step === k && !o.withBox) d = Math.max(d, o.at + 0.5); });
|
|
231
|
+
if (p.center && p.center.step === k) d = Math.max(d, p.center.at + 0.45);
|
|
232
|
+
p.edges.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + 0.4); });
|
|
233
|
+
return d;
|
|
234
|
+
}
|
|
235
|
+
// 同じ段階の 2 つ目からの箱の開始時刻(口述原稿の {cue} に合わせられる)
|
|
236
|
+
cues(k){
|
|
237
|
+
var c = [];
|
|
238
|
+
this.plan().stages.forEach(function(o){ if (o.step === k && o.at0 > 0 && c.indexOf(o.at) < 0) c.push(o.at); });
|
|
239
|
+
return c.length ? c.sort(function(a, b){ return a - b; }) : null;
|
|
240
|
+
}
|
|
241
|
+
render(k, t, ctx){
|
|
242
|
+
var D = base, self = this, vr = this.variant, T = this.props.dur, L = this.L;
|
|
243
|
+
var lecture = !!ctx.preview, FAINT = 0.45;
|
|
244
|
+
if (lecture) FAINT = base.previewOpacity(this);
|
|
245
|
+
var pr = function(s, start, len){ return s < k ? 1 : s > k ? 0 : D.prog(t, start, len); };
|
|
246
|
+
// 授業の表示:後の段階は最後の形を薄く(テーマの --preview-opacity、ないときは 0.45)、今の段階はその薄さから濃くなる。形は動かさない(どの見せ方でも同じ)
|
|
247
|
+
var faint = function(s, start, len){ return s < k ? 1 : s > k ? FAINT : FAINT + (1 - FAINT) * D.prog(t, start, len); };
|
|
248
|
+
var boxE = {}, arrE = {};
|
|
249
|
+
// 段階ごとの箱と、一緒に出る入ってくる矢印の進み
|
|
250
|
+
// 箱の動きは 12 px まで(docs/conventions.md §1.2:どの見せ方も fade より遠くへ動かさない)
|
|
251
|
+
var OFF = 12;
|
|
252
|
+
this.boxes.forEach(function(o){
|
|
253
|
+
var s = o.o.step, st = o.o.at, op, sc = 1, e = 1, d = [0, -1], ar;
|
|
254
|
+
if (lecture){ op = faint(s, st, T); ar = 1; }
|
|
255
|
+
else if (vr === "draw"){
|
|
256
|
+
// 矢印を先に引き、その先に箱が前の箱の側から 12 px 寄りながら出る
|
|
257
|
+
ar = pr(s, st, 0.5 * T); e = op = pr(s, st + 0.45 * T, 0.55 * T); sc = 0.92 + 0.08 * e; d = o.dir;
|
|
258
|
+
} else if (vr === "grow"){
|
|
259
|
+
// 矢印を引きながら、箱が前の箱の側から 12 px 寄り、0.92 → 1 に大きくなる
|
|
260
|
+
ar = pr(s, st, 0.5 * T); e = pr(s, st + 0.3 * T, 0.55 * T); op = Math.min(1, e * 1.6); sc = 0.92 + 0.08 * e; d = o.dir;
|
|
261
|
+
} else {
|
|
262
|
+
// fade:箱が下から 12 px 上がりながら現れてから、入ってくる矢印を引く
|
|
263
|
+
e = op = pr(s, st, 0.55 * T); sc = 0.92 + 0.08 * e; ar = pr(s, st + 0.45 * T, 0.55 * T);
|
|
264
|
+
}
|
|
265
|
+
var dx = -d[0] * OFF * (1 - e), dy = -d[1] * OFF * (1 - e), cx = o.b.cx, cy = o.b.cy;
|
|
266
|
+
setIf(o.g, "opacity", op.toFixed(3));
|
|
267
|
+
setIf(o.g, "transform", sc >= 1 && Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01 ? "" :
|
|
268
|
+
"translate(" + (cx + dx).toFixed(2) + " " + (cy + dy).toFixed(2) + ") scale(" + sc.toFixed(4) + ") translate(" + (-cx).toFixed(2) + " " + (-cy).toFixed(2) + ")");
|
|
269
|
+
if (o.o.inArrow) arrE[o.o.inArrow.i] = lecture ? [1, op] : [ar, 1];
|
|
270
|
+
});
|
|
271
|
+
this.arcs.forEach(function(o){
|
|
272
|
+
var r = o.r, v = arrE[r.i] || (lecture ? [1, faint(r.step, r.at, 0.5)] : [pr(r.step, r.at, 0.5), 1]);
|
|
273
|
+
var e = v[0], a = o.a, tc = a.t0 + (a.t1 - a.t0) * e;
|
|
274
|
+
setIf(o.g, "opacity", e > 0 ? v[1].toFixed(3) : 0);
|
|
275
|
+
// 見えない矢印も、render が書く属性はすべて書き直す(前の呼び出しの transform を残さない。docs/contract.md §3)
|
|
276
|
+
if (e <= 0){ setIf(o.path, "d", ""); if (o.head.hasAttribute("transform")) o.head.removeAttribute("transform"); return; }
|
|
277
|
+
// 線は矢じりの根元まで(矢じりは 14px、線が 20px 伸びるまでに大きくなる)
|
|
278
|
+
var p = self.pt(tc), sp = Math.hypot(L.rx * Math.sin(tc), L.ry * Math.cos(tc)) || 1;
|
|
279
|
+
var back = Math.min(14 / sp, tc - a.t0), te = tc - back, q0 = self.pt(a.t0), q1 = self.pt(te);
|
|
280
|
+
setIf(o.path, "d", "M" + q0[0].toFixed(2) + "," + q0[1].toFixed(2) + "A" + L.rx.toFixed(2) + "," + L.ry.toFixed(2) + " 0 " + (te - a.t0 > Math.PI ? 1 : 0) + " 1 " + q1[0].toFixed(2) + "," + q1[1].toFixed(2));
|
|
281
|
+
var ang = Math.atan2(L.ry * Math.cos(tc), -L.rx * Math.sin(tc)) * 180 / Math.PI, hs = Math.min(1, a.len * e / 20);
|
|
282
|
+
setIf(o.head, "transform", "translate(" + p[0].toFixed(2) + " " + p[1].toFixed(2) + ") rotate(" + ang.toFixed(2) + ") scale(" + hs.toFixed(4) + ")");
|
|
283
|
+
});
|
|
284
|
+
var c = this.plan().center;
|
|
285
|
+
if (this.center) setIf(this.center.g, "opacity", (lecture ? faint(c.step, c.at, 0.45) : pr(c.step, c.at, 0.45)).toFixed(3));
|
|
286
|
+
this.edges.forEach(function(o){ setIf(o.g, "opacity", (lecture ? faint(o.step, o.at, 0.4) : pr(o.step, o.at, 0.4)).toFixed(3)); });
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// ---- 下の関数は m-cycle の中だけで使う(字の幅の見積もり・箱の中の行)
|
|
291
|
+
// 属性は値が変わるときだけ書く:同じ値を書き直しても Chrome は塗り直し、macOS では入り直すたびに箱の縁の画素が揺れた(DOM は同じ)
|
|
292
|
+
// 線 p0 → p1 の名前(幅 w、高さ h)の置き場:線の真ん中(次に 1/3・2/3・1/4・3/4・端の近く)の横に、線から離して(近くになければ 24・48 px 遠くへ)。
|
|
293
|
+
// 上(か左)の側を先に試す。箱 obst と枠の外を避ける。返すのは字の基線の中心 {x, y, ok}
|
|
294
|
+
function sideLabel(p0, p1, w, h, obst, W, H){
|
|
295
|
+
var ux = p1[0] - p0[0], uy = p1[1] - p0[1], l = Math.hypot(ux, uy) || 1, nx = -uy / l, ny = ux / l, first = null;
|
|
296
|
+
if (ny > 0 || (ny === 0 && nx > 0)){ nx = -nx; ny = -ny; }
|
|
297
|
+
var ts = [0.5, 0.35, 0.65, 0.25, 0.75, 0.1, 0.9];
|
|
298
|
+
for (var ex = 0; ex <= 48; ex += 24) for (var i = 0; i < ts.length; i++) for (var sd = 1; sd >= -1; sd -= 2){
|
|
299
|
+
var d = Math.abs(nx) * w / 2 + Math.abs(ny) * h / 2 + 8 + ex;
|
|
300
|
+
var cx = p0[0] + ux * ts[i] + sd * nx * d, cy = p0[1] + uy * ts[i] + sd * ny * d;
|
|
301
|
+
var b = {l: cx - w / 2, r: cx + w / 2, t: cy - h / 2, b: cy + h / 2};
|
|
302
|
+
var at = {x: cx, y: cy + 8, ok: true};
|
|
303
|
+
if (!first) first = at;
|
|
304
|
+
if (b.l < 0 || b.r > W || b.t < 0 || b.b > H) continue;
|
|
305
|
+
if (obst.some(function(o){ return b.l < o.x + o.w + 4 && o.x - 4 < b.r && b.t < o.y + o.h + 4 && o.y - 4 < b.b; })) continue;
|
|
306
|
+
return at;
|
|
307
|
+
}
|
|
308
|
+
return {x: first.x, y: first.y, ok: false};
|
|
309
|
+
}
|
|
310
|
+
function setIf(el, a, v){ v = String(v); if (el.getAttribute(a) !== v) el.setAttribute(a, v); }
|
|
311
|
+
function tone(t){ return "var(--" + (/^(term|emph|muted|accent2|series-[1-4])$/.test(t || "") ? t : "term") + ")"; }
|
|
312
|
+
// 箱の地と字の色(m-tree・m-fishbone と同じ決まり):term と emph はテーマの薄い色の地、emph は字も emph
|
|
313
|
+
function boxFill(t){ return t === "emph" ? "var(--emph-tint)" : /^(muted|accent2|series-[1-4])$/.test(t || "") ? tint(tone(t), 12) : "var(--term-tint)"; }
|
|
314
|
+
function textFill(t){ return t === "emph" ? "var(--emph)" : "var(--fg)"; }
|
|
315
|
+
function tint(c, p){ return "color-mix(in srgb," + c + " " + p + "%,var(--bg))"; }
|
|
316
|
+
// 字の幅(px):base の textWidth(font の要素の字で測った幅)。mtext の *_^ は数えない
|
|
317
|
+
function est(s, fs, font){ return base.textWidth(s, fs, {font: font, mark: true}); }
|
|
318
|
+
// KaTeX の式の幅:一度置いて測る
|
|
319
|
+
function texWidth(el, l){
|
|
320
|
+
var g = base.el("g", {opacity: 0}, el.svg), fo = MR.texFrame(g, 0, 0, l.src, "tex", {size: l.size, anchor: "start"}, el.texSink);
|
|
321
|
+
var w = Math.max(0, (+fo.getAttribute("width") || 4) - 4);
|
|
322
|
+
el.svg.removeChild(g);
|
|
323
|
+
return w;
|
|
324
|
+
}
|
|
325
|
+
function labelLines(n, size, fill){
|
|
326
|
+
fill = fill || "var(--fg)";
|
|
327
|
+
if (n.tex) return [{tex: n.tex, src: n, size: size, fill: fill}];
|
|
328
|
+
return String(n.label || "").split("\n").map(function(s){ return {text: s, size: size, fill: fill}; });
|
|
329
|
+
}
|
|
330
|
+
// 箱の大きさと行の位置(基線は前の行の下 0.3 字 + 今の行の 1.12 字:字の箱どうしが重ならない)
|
|
331
|
+
function boxSize(el, lines){
|
|
332
|
+
var w = 0, y = 10, prev = null;
|
|
333
|
+
lines.forEach(function(l){
|
|
334
|
+
l.w = l.tex ? texWidth(el, l) : est(l.text, l.size, el) * (l.weight ? 1.05 : 1);
|
|
335
|
+
w = Math.max(w, l.w);
|
|
336
|
+
y += prev ? 0.3 * prev.size + 1.12 * l.size : 0.9 * l.size;
|
|
337
|
+
l.y = y; prev = l;
|
|
338
|
+
});
|
|
339
|
+
return {w: Math.ceil(w + 36), h: Math.ceil(y + 0.28 * prev.size + 10), lines: lines};
|
|
340
|
+
}
|
|
341
|
+
function boxDraw(el, g, x, y, bs){
|
|
342
|
+
bs.lines.forEach(function(l){
|
|
343
|
+
if (l.tex) MR.texFrame(g, x + bs.w / 2, y + l.y, l.src, "tex", {size: l.size, anchor: "middle", color: l.fill, w: l.w + 8, h: l.size * 1.6}, el.texSink).firstChild.style.verticalAlign = "top";
|
|
344
|
+
else base.mtext(g, x + bs.w / 2, y + l.y, l.text, {"text-anchor": "middle", "font-size": l.size, fill: l.fill, "font-weight": l.weight || 400});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return Part;
|
|
348
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// markup-reader 1.0.0: the reader of build-time rendered markup (Egatari spec §6.2 "Rendered output is data"), a library part
|
|
2
|
+
// (spec §6.1). Parts that show what the producer rendered (KaTeX's HTML and MathML, abcjs's SVG) insert it only through this
|
|
3
|
+
// reader, never as HTML: a small parser of its own (no innerHTML, no DOMParser, no browser parser at all) that creates each
|
|
4
|
+
// element in its namespace (HTML, SVG, MathML) with createElementNS and sets only what egatari-spec's
|
|
5
|
+
// schema/rendered-markup-1.json (normative) admits:
|
|
6
|
+
// - an element listed for its namespace, else the element is dropped with its subtree;
|
|
7
|
+
// - an attribute listed for the element or globally for its namespace ("data-*" is a prefix), with the value grammar the
|
|
8
|
+
// schema gives for it (id, data-*, fill, stroke), else the attribute is dropped;
|
|
9
|
+
// - style only as the listed properties with a length or a listed keyword, or the listed shorthands (each part a length or
|
|
10
|
+
// a listed keyword), each set with style.setProperty (color only as transparent);
|
|
11
|
+
// - xmlns is the namespace declaration of serialised markup, not an attribute: it must name the namespace the reader
|
|
12
|
+
// creates the element in (else the element is dropped) and is never set;
|
|
13
|
+
// - a dropped element is removed with its subtree, a dropped attribute or style declaration only by itself;
|
|
14
|
+
// - text is kept (as text nodes; & < > " ' &#n; &#xh; decoded); comments, doctypes, CDATA and
|
|
15
|
+
// processing instructions are dropped.
|
|
16
|
+
// Everything dropped is listed in what read() returns, and a part reports it once (sink below, ctx.report("data", …)).
|
|
17
|
+
// The list is not edited here: it is the generated block below (node tools/markup-sync.mjs writes it from the spec's schema at
|
|
18
|
+
// the commit pinned in tools/spec.json; tools/test-markup-reader.mjs checks that it equals the schema). Additions are made in
|
|
19
|
+
// the spec, never in a reader.
|
|
20
|
+
//
|
|
21
|
+
// It returns {read, texFrame, sink, LIST}:
|
|
22
|
+
// read(markup, parent, ns) parse markup and append what is admitted to parent; ns is the namespace of parent's content
|
|
23
|
+
// ("html" by default, "svg", "mathml"). Returns the list of what was dropped (strings), [] when
|
|
24
|
+
// nothing was.
|
|
25
|
+
// texFrame(parent, x, y, item, key, o, sk) a formula in an SVG figure, from the producer's output item[key + "Html"]
|
|
26
|
+
// (spec §6.2: e.g. texHtml beside tex), framed as Egatari Studio's kit/deck.js did at play time:
|
|
27
|
+
// a foreignObject (class smath) holding an inline-block div of size o.size and colour o.color,
|
|
28
|
+
// placed so that x is the anchor (start, middle, end) and y the baseline. Without rendered
|
|
29
|
+
// output (a file built without the renderer, a tier A edit), the div shows item[key] as plain
|
|
30
|
+
// text (spec §6.2 Missing output) and sk.missing reports it. Returns the foreignObject.
|
|
31
|
+
// sink(part, ctx) {missing(src), dropped(src, list), flush()}: collects what an element has to report; flush(),
|
|
32
|
+
// at the end of mount, reports each kind once per element with its count (spec §6.2: once per
|
|
33
|
+
// instance and kind) through ctx.report("data", "[<name>] …"), <name> = the tag without m-.
|
|
34
|
+
// Kinds: "not rendered at build time", and each kind of drop (element, attribute, style property).
|
|
35
|
+
//
|
|
36
|
+
// Provenance of texFrame: the frame that the math-in-SVG function of Egatari Studio's kit/deck.js (DECK.svg + Math; the name is not written here, because
|
|
37
|
+
// that Studio build loads KaTeX at play time for any component code that names it) drew (https://github.com/egatari/egatari-studio,
|
|
38
|
+
// commit 03eaf0607598b993eb020f8e619caa53526bc771), MIT License, Copyright (c) 2026 Gendo Kumoi, the same owner and licence as
|
|
39
|
+
// this repository; KaTeX's render call there is replaced by read() of the producer's output.
|
|
40
|
+
egatariParts.define({name: "markup-reader", version: "1.0.2", requires: {base: "1.2.0"}}, function(deps){
|
|
41
|
+
"use strict";
|
|
42
|
+
var el = deps.base.el;
|
|
43
|
+
// ---- BEGIN rendered-markup-1 (generated by tools/markup-sync.mjs from egatari-spec schema/rendered-markup-1.json; do not edit) ----
|
|
44
|
+
var LIST = {"global":{"html":["class","aria-hidden","id","data-*","style"],"svg":["class","aria-hidden","id","data-*","style","transform"],"mathml":["class","style"]},"elements":{"html":{"span":[]},"svg":{"svg":["width","height","viewBox","preserveAspectRatio","role","aria-label","fill","stroke","stroke-width"],"g":["fill","stroke","stroke-width"],"path":["d","fill","stroke","stroke-width","stroke-linecap","stroke-linejoin","stroke-dasharray"],"line":["x1","y1","x2","y2","stroke","stroke-width","stroke-dasharray"],"rect":["x","y","width","height","rx","ry","fill","stroke","stroke-width"],"circle":["cx","cy","r","fill","stroke","stroke-width"],"ellipse":["cx","cy","rx","ry","fill","stroke","stroke-width"],"polygon":["points","fill","stroke","stroke-width"],"polyline":["points","fill","stroke","stroke-width"],"text":["x","y","dx","dy","text-anchor","dominant-baseline","font-size","font-style","font-weight","fill","stroke"],"tspan":["x","y","dx","dy","font-size","font-style","font-weight","baseline-shift","fill","stroke"],"title":[]},"mathml":{"math":["display"],"semantics":[],"annotation":["encoding"],"mrow":[],"mi":["mathvariant","separator"],"mn":["mathvariant"],"mo":["accent","fence","largeop","lspace","mathvariant","maxsize","minsize","movablelimits","rspace","separator","stretchy","symmetric"],"ms":[],"mtext":["mathvariant"],"mspace":["width","height","depth","linebreak"],"mfrac":["linethickness"],"msqrt":[],"mroot":[],"msub":[],"msup":[],"msubsup":[],"munder":["accentunder"],"mover":["accent"],"munderover":["accent","accentunder"],"mtable":["columnalign","columnspacing","rowspacing","columnlines","rowlines","frame","width"],"mtr":[],"mtd":["columnalign","width"],"mstyle":["displaystyle","scriptlevel","mathsize"],"mpadded":["width","height","depth","lspace","voffset"],"menclose":["notation"],"mphantom":[]}},"values":{"id":"^[A-Za-z][A-Za-z0-9_.:-]{0,127}$","data-*":{"name":"^data-[a-z][a-z0-9-]{0,63}$","value":"^[^<>]{0,256}$"},"fill":["none","currentColor"],"stroke":["none","currentColor"],"length":"^-?(\\d+\\.?\\d*|\\.\\d+)(em|ex|px|%|pt|mu)?$"},"style":{"lengths":["border-bottom-width","border-left-width","border-right-width","border-top-width","border-width","bottom","font-size","height","left","line-height","margin-bottom","margin-left","margin-right","margin-top","max-width","min-width","padding-bottom","padding-left","padding-right","padding-top","right","top","vertical-align","width"],"keywords":{"position":["relative","absolute"],"display":["inline-block","inline","block","none"],"border-bottom-style":["solid","dashed"],"border-top-style":["solid","dashed"],"border-right-style":["solid","dashed"],"border-left-style":["solid","dashed"],"vertical-align":["top","middle","bottom","baseline"],"white-space":["nowrap"],"overflow":["hidden","visible"],"color":["transparent"]},"shorthands":{"margin":{"max":4},"padding":{"max":4},"border-width":{"max":4},"border-style":{"max":4,"keywords":["solid","dashed","dotted","double","none"]},"border":{"max":3,"keywords":["solid","dashed","dotted","double","none"]},"border-top":{"max":3,"keywords":["solid","dashed","none"]},"border-bottom":{"max":3,"keywords":["solid","dashed","none"]},"border-left":{"max":3,"keywords":["solid","dashed","none"]},"border-right":{"max":3,"keywords":["solid","dashed","none"]}}}};
|
|
45
|
+
// ---- END rendered-markup-1 ----
|
|
46
|
+
var NSURI = {html: "http://www.w3.org/1999/xhtml", svg: "http://www.w3.org/2000/svg", mathml: "http://www.w3.org/1998/Math/MathML"};
|
|
47
|
+
var LENGTH = new RegExp(LIST.values.length);
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------- the parser (markup → tree; nothing is created here)
|
|
50
|
+
var ENT = {amp: "&", lt: "<", gt: ">", quot: "\"", apos: "'"};
|
|
51
|
+
function decode(s){
|
|
52
|
+
return s.replace(/&(#x[0-9A-Fa-f]{1,6}|#[0-9]{1,7}|[A-Za-z]+);/g, function(m, e){
|
|
53
|
+
if (e[0] === "#"){
|
|
54
|
+
var n = e[1] === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
55
|
+
return n > 0 && n <= 0x10ffff && !(n >= 0xd800 && n <= 0xdfff) ? String.fromCodePoint(n) : "�";
|
|
56
|
+
}
|
|
57
|
+
return Object.prototype.hasOwnProperty.call(ENT, e) ? ENT[e] : m;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// {kids: [node]}, node = {tag, attrs: [[name, value]], kids} | {text}; other = what the parser itself dropped
|
|
61
|
+
function parse(src, other){
|
|
62
|
+
var root = {tag: null, attrs: [], kids: []}, stack = [root], i = 0, n = src.length;
|
|
63
|
+
var top = function(){ return stack[stack.length - 1]; };
|
|
64
|
+
while (i < n){
|
|
65
|
+
var lt = src.indexOf("<", i);
|
|
66
|
+
if (lt < 0) lt = n;
|
|
67
|
+
if (lt > i){ top().kids.push({text: decode(src.slice(i, lt))}); i = lt; continue; }
|
|
68
|
+
if (src.startsWith("<!--", i)){ var ce = src.indexOf("-->", i + 4); other.push("a comment"); i = ce < 0 ? n : ce + 3; continue; }
|
|
69
|
+
if (src[i + 1] === "!" || src[i + 1] === "?"){ var de = src.indexOf(">", i); other.push("<" + src.slice(i + 1, Math.min(de < 0 ? n : de, i + 12))); i = de < 0 ? n : de + 1; continue; }
|
|
70
|
+
if (src[i + 1] === "/"){
|
|
71
|
+
var m = /^<\/([A-Za-z][^\s/>]*)\s*>/.exec(src.slice(i, i + 200));
|
|
72
|
+
if (!m){ top().kids.push({text: "<"}); i++; continue; }
|
|
73
|
+
var j = stack.length - 1;
|
|
74
|
+
while (j > 0 && stack[j].tag !== m[1]) j--;
|
|
75
|
+
if (j > 0) stack.length = j; else other.push("an end tag </" + m[1] + "> without its start");
|
|
76
|
+
i += m[0].length;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
var t = /^<([A-Za-z][^\s/>]*)/.exec(src.slice(i, i + 200));
|
|
80
|
+
if (!t){ top().kids.push({text: "<"}); i++; continue; }
|
|
81
|
+
var node = {tag: t[1], attrs: [], kids: []}, seen = {};
|
|
82
|
+
i += t[0].length;
|
|
83
|
+
var self = false;
|
|
84
|
+
for (;;){
|
|
85
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
86
|
+
if (i >= n) break;
|
|
87
|
+
if (src[i] === ">"){ i++; break; }
|
|
88
|
+
if (src[i] === "/" && src[i + 1] === ">"){ i += 2; self = true; break; }
|
|
89
|
+
if (src[i] === "/"){ i++; continue; }
|
|
90
|
+
var a = /^[^\s"'>\/=]+/.exec(src.slice(i, i + 200));
|
|
91
|
+
if (!a){ i++; continue; }
|
|
92
|
+
var name = a[0], value = "";
|
|
93
|
+
i += name.length;
|
|
94
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
95
|
+
if (src[i] === "="){
|
|
96
|
+
i++;
|
|
97
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
98
|
+
var q = src[i];
|
|
99
|
+
if (q === "\"" || q === "'"){ var e = src.indexOf(q, i + 1); if (e < 0) e = n; value = src.slice(i + 1, e); i = e + 1; }
|
|
100
|
+
else { var u = /^[^\s>]*/.exec(src.slice(i)); value = u[0]; i += value.length; }
|
|
101
|
+
}
|
|
102
|
+
if (seen[name]) continue; // the first of repeated attributes counts (as in HTML)
|
|
103
|
+
seen[name] = true;
|
|
104
|
+
node.attrs.push([name, decode(value)]);
|
|
105
|
+
}
|
|
106
|
+
top().kids.push(node);
|
|
107
|
+
if (!self) stack.push(node);
|
|
108
|
+
}
|
|
109
|
+
return root;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------- the admission (the generated LIST)
|
|
113
|
+
function listed(names, a){
|
|
114
|
+
for (var i = 0; i < names.length; i++){
|
|
115
|
+
var x = names[i];
|
|
116
|
+
if (x === a || (x[x.length - 1] === "*" && a.indexOf(x.slice(0, -1)) === 0)) return x;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
// The admitted declarations of a style attribute ([[property, value]]); the others go to drop
|
|
121
|
+
var own = function(o, k){ return Object.prototype.hasOwnProperty.call(o, k) ? o[k] : null; };
|
|
122
|
+
// A shorthand (margin, padding, border-width, border-style, border, border-<side>): at most max parts separated by spaces,
|
|
123
|
+
// each a length or one of its keywords
|
|
124
|
+
function shorthandOk(sh, x){
|
|
125
|
+
var parts = x.split(/\s+/).filter(Boolean), kws = sh.keywords || [];
|
|
126
|
+
return parts.length >= 1 && parts.length <= sh.max && parts.every(function(t){ return LENGTH.test(t) || kws.indexOf(t) >= 0; });
|
|
127
|
+
}
|
|
128
|
+
function styleOf(v, tag, drop){
|
|
129
|
+
var out = [];
|
|
130
|
+
v.split(";").forEach(function(d){
|
|
131
|
+
if (!d.trim()) return;
|
|
132
|
+
var c = d.indexOf(":"), p = (c < 0 ? d : d.slice(0, c)).trim().toLowerCase(), x = c < 0 ? "" : d.slice(c + 1).trim();
|
|
133
|
+
var kw = own(LIST.style.keywords, p), sh = LIST.style.shorthands ? own(LIST.style.shorthands, p) : null;
|
|
134
|
+
if ((LIST.style.lengths.indexOf(p) >= 0 && LENGTH.test(x)) || (kw && kw.indexOf(x) >= 0) || (sh && shorthandOk(sh, x))) out.push([p, x]);
|
|
135
|
+
else drop.push("style " + p + ":" + x + " on <" + tag + ">");
|
|
136
|
+
});
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
// Whether the value fits the schema's grammar for the attribute (as listed: x is the list entry, a the name)
|
|
140
|
+
var RE = {};
|
|
141
|
+
function re(s){ return RE[s] || (RE[s] = new RegExp(s)); }
|
|
142
|
+
function valueOk(x, a, v){
|
|
143
|
+
var g = Object.prototype.hasOwnProperty.call(LIST.values, x) ? LIST.values[x] : undefined;
|
|
144
|
+
if (x === "data-*") return re(g.name).test(a) && re(g.value).test(v);
|
|
145
|
+
if (g === undefined) return true;
|
|
146
|
+
return typeof g === "string" ? re(g).test(v) : g.indexOf(v) >= 0;
|
|
147
|
+
}
|
|
148
|
+
// The namespace of an element named tag inside content of namespace ns (svg and math switch, as in HTML)
|
|
149
|
+
function nsOf(tag, ns){ return ns === "html" ? (tag.toLowerCase() === "svg" ? "svg" : tag.toLowerCase() === "math" ? "mathml" : "html") : ns; }
|
|
150
|
+
function build(node, parent, ns, drop){
|
|
151
|
+
node.kids.forEach(function(k){
|
|
152
|
+
if (k.text !== undefined){ if (k.text) parent.appendChild(document.createTextNode(k.text)); return; }
|
|
153
|
+
var kns = nsOf(k.tag, ns), tag = kns === "html" || ns === "html" ? k.tag.toLowerCase() : k.tag;
|
|
154
|
+
var allowed = LIST.elements[kns], own = allowed && Object.prototype.hasOwnProperty.call(allowed, tag) ? allowed[tag] : null;
|
|
155
|
+
if (!own){ drop.push("element <" + k.tag + ">" + (parent.localName ? " in <" + parent.localName + ">" : "")); return; }
|
|
156
|
+
var xmlns = k.attrs.filter(function(a){ return a[0] === "xmlns"; })[0];
|
|
157
|
+
if (xmlns && xmlns[1] !== NSURI[kns]){ drop.push("element <" + k.tag + "> declared in namespace " + xmlns[1]); return; }
|
|
158
|
+
var e = document.createElementNS(NSURI[kns], tag);
|
|
159
|
+
k.attrs.forEach(function(a){
|
|
160
|
+
var name = kns === "html" ? a[0].toLowerCase() : a[0], v = a[1];
|
|
161
|
+
if (name === "xmlns") return;
|
|
162
|
+
var x = listed(own, name) || listed(LIST.global[kns], name);
|
|
163
|
+
if (!x || !valueOk(x, name, v)){ drop.push("attribute " + name + "=\"" + v.slice(0, 40) + "\" on <" + tag + ">"); return; }
|
|
164
|
+
// style: an empty attribute in its place among the others (so that attributes keep the producer's order), then each
|
|
165
|
+
// admitted declaration with setProperty; nothing of the producer's text is set as is. A value the browser refuses for its
|
|
166
|
+
// property (a negative height) sets nothing, and a style left empty is removed
|
|
167
|
+
if (name === "style"){ var st = styleOf(v, tag, drop); if (st.length){ e.setAttribute("style", ""); st.forEach(function(d){ e.style.setProperty(d[0], d[1]); }); if (!e.style.length) e.removeAttribute("style"); } return; }
|
|
168
|
+
e.setAttribute(name, v);
|
|
169
|
+
});
|
|
170
|
+
build(k, e, kns, drop);
|
|
171
|
+
parent.appendChild(e);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function read(markup, parent, ns){
|
|
175
|
+
var drop = [];
|
|
176
|
+
build(parse(String(markup), drop), parent, ns || "html", drop);
|
|
177
|
+
return drop;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---------------------------------------------------------------- reports (spec §6.2: once, code data)
|
|
181
|
+
// The kind of a drop, without its value: "element <a>", "attribute title on <span>", "style color on <span>", "a comment", …
|
|
182
|
+
function kindOf(x){
|
|
183
|
+
return x.replace(/^(attribute [^=]+)=".*" on (<[^>]+>)$/, "$1 on $2").replace(/^(element <[^>]+>) in <[^>]+>$/, "$1")
|
|
184
|
+
.replace(/^style ([a-z-]+):.* on (<[^>]+>)$/, "style $1 on $2").replace(/^(<!?\??[A-Za-z\[]*).*$/, "$1");
|
|
185
|
+
}
|
|
186
|
+
// What an element has to report (spec §6.2: once per instance and kind, with the count): kept per element across sinks,
|
|
187
|
+
// counted once per formula source (a formula measured and then drawn is read twice), reported by flush() at the end of mount
|
|
188
|
+
var state = new WeakMap();
|
|
189
|
+
function sink(part, ctx){
|
|
190
|
+
var name = part.tagName.toLowerCase().replace(/^m-/, ""); // = the part's name for every m-<name> element part
|
|
191
|
+
var st = state.get(part);
|
|
192
|
+
if (!st){ st = {kinds: {}, order: [], seen: {}, done: {}}; state.set(part, st); }
|
|
193
|
+
var q = function(s){ s = String(s); return JSON.stringify(s.length > 60 ? s.slice(0, 60) + "…" : s); };
|
|
194
|
+
var add = function(kind, src, msg){
|
|
195
|
+
var k = st.kinds[kind];
|
|
196
|
+
if (!k){ k = st.kinds[kind] = {n: 0, src: src, msg: msg}; st.order.push(kind); }
|
|
197
|
+
k.n++;
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
missing: function(src){
|
|
201
|
+
if (st.seen["m\u0000" + src]) return;
|
|
202
|
+
st.seen["m\u0000" + src] = true;
|
|
203
|
+
add("missing", src, null);
|
|
204
|
+
},
|
|
205
|
+
dropped: function(src, list){
|
|
206
|
+
if (st.seen["d\u0000" + src]) return;
|
|
207
|
+
st.seen["d\u0000" + src] = true;
|
|
208
|
+
list.forEach(function(x){ add("drop " + kindOf(x), src, x); });
|
|
209
|
+
},
|
|
210
|
+
// Reports each kind not reported yet for this element, once, through ctx.report("data", "[<name>] …")
|
|
211
|
+
flush: function(){
|
|
212
|
+
st.order.forEach(function(kind){
|
|
213
|
+
if (st.done[kind]) return;
|
|
214
|
+
st.done[kind] = true;
|
|
215
|
+
var k = st.kinds[kind], msg = kind === "missing"
|
|
216
|
+
? k.n + " tex field(s) not rendered at build time, e.g. " + q(k.src) + " (the source is shown as text)"
|
|
217
|
+
: "rendered markup: dropped " + kind.slice(5) + " ×" + k.n + ", e.g. " + k.msg + " in tex " + q(k.src) + " (not in rendered-markup-1, spec §6.2)";
|
|
218
|
+
if (ctx && typeof ctx.report === "function") ctx.report("data", "[" + name + "] " + msg);
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ---------------------------------------------------------------- a formula in an SVG figure (kit/deck.js's frame)
|
|
225
|
+
function texFrame(parent, x, y, item, key, o, sk){
|
|
226
|
+
o = o || {};
|
|
227
|
+
var w = o.w || 600, h = o.h || 80, size = o.size || 24;
|
|
228
|
+
var fo = el("foreignObject", {x: 0, y: 0, width: w, height: h, class: "smath"}, parent);
|
|
229
|
+
var div = document.createElement("div");
|
|
230
|
+
div.setAttribute("xmlns", NSURI.html);
|
|
231
|
+
div.style.cssText = "display:inline-block;vertical-align:top;white-space:nowrap;line-height:1;font-size:" + size + "px;color:" + (o.color || "var(--fg)");
|
|
232
|
+
var src = item[key], html = item[key + "Html"];
|
|
233
|
+
if (typeof html === "string"){
|
|
234
|
+
var drop = read(html, div, "html");
|
|
235
|
+
if (drop.length && sk) sk.dropped(src, drop);
|
|
236
|
+
} else {
|
|
237
|
+
div.textContent = src;
|
|
238
|
+
if (sk) sk.missing(src);
|
|
239
|
+
}
|
|
240
|
+
fo.appendChild(div);
|
|
241
|
+
// 位置合わせ:x は anchor の位置、y はベースライン
|
|
242
|
+
var bw = div.offsetWidth || 0, base = size * 0.78;
|
|
243
|
+
var dx = o.anchor === "middle" ? -bw / 2 : o.anchor === "end" ? -bw : 0;
|
|
244
|
+
fo.setAttribute("x", x + dx); fo.setAttribute("y", y - base);
|
|
245
|
+
fo.setAttribute("width", Math.max(bw + 4, 1));
|
|
246
|
+
return fo;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {read: read, texFrame: texFrame, sink: sink, LIST: LIST};
|
|
250
|
+
});
|