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,222 @@
|
|
|
1
|
+
// m-compare:2 つ(3 つまで)を横に並べて比べる表。列ごとに見出し、行ごとに比べる観点、最後に行ごとの違い
|
|
2
|
+
// <m-compare style="height:420px"><script type="application/json">
|
|
3
|
+
// {"sides": [{"label": "紙の申請", "tone": "muted"}, {"label": "オンライン申請"}],
|
|
4
|
+
// "rows": [{"label": "受付時間", "values": ["平日 9〜17 時", "24 時間"], "better": 1, "diff": "いつでも出せる"}, …]}
|
|
5
|
+
// (JSON の終わり)</m-compare>
|
|
6
|
+
// 段階:既定は 一方の列 → もう一方の列(→ 3 つ目の列)→ 違い(diff の列と better の枠)。違いのない表は列の数だけ
|
|
7
|
+
// 観点の名前(行の名前)は最初の列と一緒に出る。値は列の幅で折り返す(字数から幅を見積もる。\n で改行)
|
|
8
|
+
// 字は size(既定 28 px)から 24 px まで縮めて要素の箱に収める。収まらなければ ctx.report(size)
|
|
9
|
+
// 見せ方(docs/conventions.md §1):fade(既定。列が少し上がりながら現れる)・slide(列が自分の側から横に寄って現れる)・
|
|
10
|
+
// reveal(列の中を上の行から 1 行ずつ)。どれも動く距離(16 px)と長さ(dur)は同じで、段階の数・長さ・最後の中身は変わらない
|
|
11
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
12
|
+
// 違いの列の既定の見出しの言語は ctx.lang(mount で読む)。収まらない表は ctx.report で知らせる(1.x の console.warn の代わり)
|
|
13
|
+
egatariParts.define({name: "compare", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-compare"}, function(deps){
|
|
14
|
+
"use strict";
|
|
15
|
+
var base = deps.base;
|
|
16
|
+
return class extends base.MotionElement {
|
|
17
|
+
static partName = "compare"; // the registry name (define meta name), for report prefixes
|
|
18
|
+
static variants = ["fade", "slide", "reveal"];
|
|
19
|
+
// データの形(kit/shape.js)
|
|
20
|
+
static shape = {
|
|
21
|
+
schema: {type: "object", additionalProperties: false, required: ["sides", "rows"], properties: {
|
|
22
|
+
sides: {type: "array", minItems: 2, maxItems: 3, items: {type: "object", additionalProperties: false, required: ["label"], properties: {
|
|
23
|
+
label: {type: "string"}, tone: {type: "string"}, step: {type: "integer"}}}},
|
|
24
|
+
rows: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["values"], properties: {
|
|
25
|
+
label: {type: "string"}, values: {type: "array", items: {type: ["string", "number"]}}, diff: {type: "string"}, better: {type: "integer"}}}}}},
|
|
26
|
+
example: {sides: [{label: "紙の申請", tone: "muted"}, {label: "オンライン申請"}],
|
|
27
|
+
rows: [{label: "受付時間", values: ["平日 9〜17 時", "24 時間"], better: 1, diff: "いつでも出せる"}]},
|
|
28
|
+
};
|
|
29
|
+
static props = {
|
|
30
|
+
size: {type: "number", default: 28, doc: "値の字の大きさ(px)。収まらなければ 24 まで縮める"},
|
|
31
|
+
dur: {type: "number", default: 0.6, doc: "1 つの列(と違い)が現れる秒数"},
|
|
32
|
+
"diff-label": {type: "string", default: "", doc: "違いの列の見出し(空なら「違い」)"},
|
|
33
|
+
};
|
|
34
|
+
get steps(){
|
|
35
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
36
|
+
var d = this.data || {}, m = 0;
|
|
37
|
+
(d.sides || []).forEach(function(s, i){ m = Math.max(m, s.step || i + 1); });
|
|
38
|
+
return m + (this.hasDiff() ? 1 : 0);
|
|
39
|
+
}
|
|
40
|
+
hasDiff(){
|
|
41
|
+
return ((this.data || {}).rows || []).some(function(r){ return (r.diff !== undefined && r.diff !== "") || r.better !== undefined; });
|
|
42
|
+
}
|
|
43
|
+
mount(ctx){
|
|
44
|
+
var P = this.props, D = base, self = this, data = this.data || {sides: [], rows: []};
|
|
45
|
+
this.variant = base.variant(this);
|
|
46
|
+
// 形(static shape)では書けない決まり:values は列の数だけ、better は列の番号(0 から)。黙って値を落とさない
|
|
47
|
+
var ns = (data.sides || []).length;
|
|
48
|
+
(data.rows || []).forEach(function(r, j){
|
|
49
|
+
var nv = (r.values || []).length;
|
|
50
|
+
if (nv !== ns) throw new Error("m-compare: rows[" + j + "].values has " + nv + " value(s) but there are " + ns + " sides (write one value per side, in the order of sides)");
|
|
51
|
+
if (r.better !== undefined && !(r.better >= 0 && r.better < ns)) throw new Error("m-compare: rows[" + j + "].better is " + JSON.stringify(r.better) + " but it must be a side number from 0 to " + (ns - 1));
|
|
52
|
+
});
|
|
53
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
54
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
55
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
56
|
+
var sides = data.sides || [], rows = data.rows || [], n = sides.length;
|
|
57
|
+
var TONES = /^(term|emph|muted|accent2|series-[1-4])$/, DEF = ["term", "accent2", "series-4"];
|
|
58
|
+
var tone = function(s, i){ return "var(--" + (TONES.test(s.tone || "") ? s.tone : DEF[i] || "term") + ")"; };
|
|
59
|
+
var hasDiff = this.hasDiff(), hasDiffCol = rows.some(function(r){ return r.diff !== undefined && r.diff !== ""; });
|
|
60
|
+
this.ja = /^ja\b/i.test(ctx.lang);
|
|
61
|
+
var diffHead = P["diff-label"] || (this.ja ? "違い" : "Difference");
|
|
62
|
+
// 字の幅の見積もり(base の textWidth:テーマの字で測った幅。mtext で書くので *_^ は数えない。太字は 1.04 倍)
|
|
63
|
+
var est = function(s, fs, bold){ return D.textWidth(s, fs, {font: self, mark: true}) * (bold ? 1.04 : 1); };
|
|
64
|
+
// 折り返し:英数字の語はまとめ、行頭に来てはいけない字(、。)」など)の前では折らない。幅は 0.5 px まで超えてよい
|
|
65
|
+
// (列の幅はいちばん長い名前の見積もりで決まり、字ごとの和はその見積もりと浮動小数点の誤差だけ違うことがある)
|
|
66
|
+
var wrap = function(s, maxW, fs, bold){
|
|
67
|
+
var out = [], over = false;
|
|
68
|
+
String(s === undefined ? "" : s).split("\n").forEach(function(par){
|
|
69
|
+
var toks = par.match(/[A-Za-z0-9.,%+\-−:\/'’]+|\s+|[^]/gu) || [""], line = "", w = 0;
|
|
70
|
+
toks.forEach(function(tk){
|
|
71
|
+
var tw = est(tk, fs, bold), sp = /^\s+$/.test(tk);
|
|
72
|
+
if (line && w + tw > maxW + 0.5 && !sp && !/^[、。,.)」』!?ー々ゃゅょっャュョッぁぃぅぇぉ〜]/.test(tk)){ out.push(line.trim()); line = ""; w = 0; }
|
|
73
|
+
if (sp && !line) return;
|
|
74
|
+
line += tk; w += tw;
|
|
75
|
+
});
|
|
76
|
+
out.push(line.trim());
|
|
77
|
+
});
|
|
78
|
+
out.forEach(function(l){ if (est(l, fs, bold) > maxW + 0.5) over = true; });
|
|
79
|
+
return {lines: out, over: over};
|
|
80
|
+
};
|
|
81
|
+
// 字の大きさを size から 24 まで下げて、要素の箱に収まる配置を探す
|
|
82
|
+
var gap = 14, padX = 16, padY = 12, bar = 7, L = null;
|
|
83
|
+
// size が数でなければ既定の 28
|
|
84
|
+
var size0 = P.size;
|
|
85
|
+
if (!(typeof size0 === "number" && isFinite(size0))){ ctx.report("attr", "[compare] size=\"" + this.getAttribute("size") + "\" is not a number (28 is used)"); size0 = 28; }
|
|
86
|
+
for (var fs = Math.max(24, size0); fs >= 24; fs--){
|
|
87
|
+
L = (function(fs){
|
|
88
|
+
var lh = Math.round(fs * 1.3), hs = fs + 2, hlh = Math.round(hs * 1.25), over = false;
|
|
89
|
+
var anyLabel = rows.some(function(r){ return r.label; });
|
|
90
|
+
var lw = anyLabel ? Math.min(W * 0.24, Math.max(W * 0.1, Math.max.apply(null, rows.map(function(r){ return est(r.label || "", fs, true); })) + padX * 2)) : 0;
|
|
91
|
+
var dw = hasDiffCol ? Math.min(W * 0.3, Math.max(W * 0.18, Math.max.apply(null, rows.map(function(r){ return est(r.diff || "", fs, true); })) + padX * 2)) : 0;
|
|
92
|
+
var cw = (W - lw - dw - gap * (n - 1 + (lw ? 1 : 0) + (dw ? 1 : 0))) / n;
|
|
93
|
+
var heads = sides.map(function(s){ var w = wrap(s.label, cw - padX * 2, hs, true); over = over || w.over; return w.lines; });
|
|
94
|
+
var cells = rows.map(function(r){
|
|
95
|
+
var lab = wrap(r.label || "", lw - padX * 2, fs, true), dif = wrap(r.diff || "", dw - padX * 2, fs, true);
|
|
96
|
+
var vals = sides.map(function(s, i){ var v = (r.values || [])[i]; return wrap(v === undefined || v === null ? "" : v, cw - padX * 2, fs, r.better === i); });
|
|
97
|
+
over = over || (lw && lab.over) || (dw && dif.over) || vals.some(function(v){ return v.over; });
|
|
98
|
+
var nl = Math.max(lw ? lab.lines.length : 1, dw ? dif.lines.length : 1, Math.max.apply(null, vals.map(function(v){ return v.lines.length; })));
|
|
99
|
+
return {lab: lab.lines, dif: dif.lines, vals: vals.map(function(v){ return v.lines; }), h: nl * lh + padY * 2};
|
|
100
|
+
});
|
|
101
|
+
var hh = bar + padY * 2 + Math.max.apply(null, heads.map(function(h){ return h.length; })) * hlh;
|
|
102
|
+
var tot = hh + cells.reduce(function(a, c){ return a + c.h; }, 0);
|
|
103
|
+
return {fs: fs, lh: lh, hs: hs, hlh: hlh, lw: lw, dw: dw, cw: cw, heads: heads, cells: cells, hh: hh, tot: tot, ok: !over && tot <= H};
|
|
104
|
+
})(fs);
|
|
105
|
+
if (L.ok) break;
|
|
106
|
+
}
|
|
107
|
+
if (!L.ok) ctx.report("size", "[compare] the table does not fit in " + W + "×" + H + " px even at 24 px (shorten the texts or make the element taller)");
|
|
108
|
+
// 余った高さは行に分ける(1 行につき字の行の高さまで。表は上にそろえる)
|
|
109
|
+
var extra = Math.max(0, Math.min((H - L.tot) / Math.max(1, rows.length), L.lh));
|
|
110
|
+
var ys = [], y = L.hh;
|
|
111
|
+
L.cells.forEach(function(c){ c.h += extra; ys.push(y); y += c.h; });
|
|
112
|
+
var tableH = y;
|
|
113
|
+
var x = 0, colX = {};
|
|
114
|
+
if (L.lw){ colX.label = x; x += L.lw + gap; }
|
|
115
|
+
colX.sides = sides.map(function(){ var x0 = x; x += L.cw + gap; return x0; });
|
|
116
|
+
if (L.dw) colX.diff = x;
|
|
117
|
+
var lastSide = 0;
|
|
118
|
+
sides.forEach(function(s, i){ lastSide = Math.max(lastSide, s.step || i + 1); });
|
|
119
|
+
var diffStep = lastSide + 1;
|
|
120
|
+
// 字の塊を (cx, 行の中央) に置く
|
|
121
|
+
var block = function(g, lines, xx, yc, anchor, attrs, lh){
|
|
122
|
+
var y0 = yc - (lines.length - 1) * lh / 2 + L.fs * 0.36;
|
|
123
|
+
lines.forEach(function(s, j){ if (s) D.mtext(g, xx, y0 + j * lh, s, Object.assign({"text-anchor": anchor, "font-size": L.fs}, attrs)); });
|
|
124
|
+
};
|
|
125
|
+
// 現れる単位(piece):{g, step, row(reveal の順。見出しは 0、行 j は j + 1), dir(slide の向き:-1 左から、1 右から、0 下から)}
|
|
126
|
+
var pieces = [], m = rows.length + 1;
|
|
127
|
+
var piece = function(step, row, dir){ var g = D.el("g", {opacity: 0}, svg); pieces.push({g: g, step: step, row: row, dir: dir}); return g; };
|
|
128
|
+
var sepLine = function(g, x0, w, yy){ D.el("line", {x1: x0, x2: x0 + w, y1: yy, y2: yy, stroke: "var(--line)", "stroke-width": 1.5}, g); };
|
|
129
|
+
// 左右の列は外から、3 つの列の真ん中は下から寄る
|
|
130
|
+
var dirOf = function(i){ return i === 0 ? -1 : i === n - 1 ? 1 : 0; };
|
|
131
|
+
// 観点の名前(最初の列と一緒に、その列の向きで)
|
|
132
|
+
var s0 = sides.length ? (sides[0].step || 1) : 1;
|
|
133
|
+
if (L.lw) L.cells.forEach(function(c, j){
|
|
134
|
+
var g = piece(s0, j + 1, -1);
|
|
135
|
+
block(g, c.lab, colX.label + padX * 0.5, ys[j] + c.h / 2, "start", {"font-weight": 700, fill: "var(--fg)"}, L.lh);
|
|
136
|
+
if (j < rows.length - 1) sepLine(g, colX.label, L.lw, ys[j] + c.h);
|
|
137
|
+
});
|
|
138
|
+
// 列:薄い地の札・上の帯・見出し、行ごとの値
|
|
139
|
+
sides.forEach(function(s, i){
|
|
140
|
+
var st = s.step || i + 1, col = tone(s, i), x0 = colX.sides[i], dir = dirOf(i);
|
|
141
|
+
var g = piece(st, 0, dir);
|
|
142
|
+
D.el("rect", {x: x0, y: 0, width: L.cw, height: tableH, rx: 12, fill: col, "fill-opacity": 0.07}, g);
|
|
143
|
+
D.el("rect", {x: x0, y: 0, width: L.cw, height: bar, rx: 3, fill: col}, g);
|
|
144
|
+
var hl = L.heads[i];
|
|
145
|
+
hl.forEach(function(t, j){
|
|
146
|
+
D.mtext(g, x0 + L.cw / 2, bar + padY + (L.hh - bar - padY * 2 - hl.length * L.hlh) / 2 + j * L.hlh + L.hlh / 2 + L.hs * 0.36, t,
|
|
147
|
+
{"text-anchor": "middle", "font-size": L.hs, "font-weight": 700, fill: col});
|
|
148
|
+
});
|
|
149
|
+
L.cells.forEach(function(c, j){
|
|
150
|
+
var gc = piece(st, j + 1, dir), r = rows[j];
|
|
151
|
+
block(gc, c.vals[i], x0 + L.cw / 2, ys[j] + c.h / 2, "middle", r.better === i ? {"font-weight": 700, fill: col} : {fill: "var(--fg)"}, L.lh);
|
|
152
|
+
sepLine(gc, x0 + 10, L.cw - 20, ys[j]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
// 違い:右の列(見出しと diff の字)と、better の値を囲む枠
|
|
156
|
+
if (hasDiff){
|
|
157
|
+
if (L.dw){
|
|
158
|
+
var gd = piece(diffStep, 0, 1);
|
|
159
|
+
D.el("rect", {x: colX.diff, y: 0, width: L.dw, height: tableH, rx: 12, fill: "var(--emph-tint)"}, gd);
|
|
160
|
+
D.el("rect", {x: colX.diff, y: 0, width: L.dw, height: bar, rx: 3, fill: "var(--emph)"}, gd);
|
|
161
|
+
D.mtext(gd, colX.diff + L.dw / 2, bar + (L.hh - bar) / 2 + L.hs * 0.36, diffHead, {"text-anchor": "middle", "font-size": L.hs, "font-weight": 700, fill: "var(--emph)"});
|
|
162
|
+
}
|
|
163
|
+
L.cells.forEach(function(c, j){
|
|
164
|
+
var r = rows[j], hasD = r.diff !== undefined && r.diff !== "", hasB = r.better !== undefined && r.better >= 0 && r.better < n;
|
|
165
|
+
if (!hasD && !hasB && !L.dw) return;
|
|
166
|
+
var g = piece(diffStep, j + 1, 1);
|
|
167
|
+
if (L.dw){
|
|
168
|
+
if (hasD) block(g, c.dif, colX.diff + padX, ys[j] + c.h / 2, "start", {"font-weight": 700, fill: "var(--emph)"}, L.lh);
|
|
169
|
+
D.el("line", {x1: colX.diff + 10, x2: colX.diff + L.dw - 10, y1: ys[j], y2: ys[j], stroke: "var(--line)", "stroke-width": 1.5}, g);
|
|
170
|
+
}
|
|
171
|
+
if (hasB) D.el("rect", {x: colX.sides[r.better] + 5, y: ys[j] + 5, width: L.cw - 10, height: c.h - 10, rx: 9, fill: "none", stroke: "var(--emph)", "stroke-width": 3}, g);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
this.pieces = pieces; this.m = m;
|
|
175
|
+
// 読み上げ:最後の形(すべての列と行、違い)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
176
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
177
|
+
this.setAttribute("role", "img");
|
|
178
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(this.ja, diffHead));
|
|
179
|
+
}
|
|
180
|
+
// 最後の形を 1 文で(読み上げの名前):「紙の申請とオンライン申請の比較。受付時間:紙の申請 平日 9〜17 時、オンライン申請 24 時間(オンライン申請がよい。違い:いつでも出せる)」
|
|
181
|
+
summary(ja, diffHead){
|
|
182
|
+
var d = this.data || {}, sides = d.sides || [], one = function(v){ return String(v === undefined || v === null ? "" : v).replace(/\s*\n\s*/g, " ").replace(/\*/g, ""); };
|
|
183
|
+
var names = sides.map(function(s){ return one(s.label); });
|
|
184
|
+
var s = ja ? names.join("と") + "の比較" : "Comparison of " + names.join(" and ");
|
|
185
|
+
(d.rows || []).forEach(function(r){
|
|
186
|
+
var vs = sides.map(function(sd, i){ return names[i] + " " + one((r.values || [])[i]); }).join(ja ? "、" : ", ");
|
|
187
|
+
var ex = [];
|
|
188
|
+
if (r.better !== undefined && names[r.better] !== undefined) ex.push(ja ? names[r.better] + "がよい" : names[r.better] + " is better");
|
|
189
|
+
if (r.diff !== undefined && r.diff !== "") ex.push(one(diffHead) + (ja ? ":" : ": ") + one(r.diff));
|
|
190
|
+
s += (ja ? "。" : ". ") + (r.label ? one(r.label) + (ja ? ":" : ": ") : "") + vs + (ex.length ? (ja ? "(" + ex.join("。") + ")" : " (" + ex.join("; ") + ")") : "");
|
|
191
|
+
});
|
|
192
|
+
return s;
|
|
193
|
+
}
|
|
194
|
+
duration(k){
|
|
195
|
+
var d = 0, F = this.props.dur;
|
|
196
|
+
(this.pieces || []).forEach(function(p){ if (p.step === k) d = F; });
|
|
197
|
+
return d;
|
|
198
|
+
}
|
|
199
|
+
cues(){ return null; }
|
|
200
|
+
render(k, t, ctx){
|
|
201
|
+
var D = base, F = this.props.dur, vr = this.variant, m = this.m, lecture = !!ctx.preview;
|
|
202
|
+
// 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
203
|
+
var dim = lecture ? base.previewOpacity(this) : 0.45;
|
|
204
|
+
var TRAVEL = 16;
|
|
205
|
+
this.pieces.forEach(function(p){
|
|
206
|
+
// reveal:行ごとに F/2 秒ずつ、出だしを F/2 の中で上から順にずらす(全体で F 秒。fade と同じ長さ)
|
|
207
|
+
var at = 0, len = F;
|
|
208
|
+
if (vr === "reveal"){ len = F / 2; at = m > 1 ? p.row / (m - 1) * F / 2 : 0; }
|
|
209
|
+
var e = p.step < k ? 1 : p.step > k ? 0 : D.prog(t, at, len);
|
|
210
|
+
if (lecture){
|
|
211
|
+
p.g.setAttribute("opacity", (p.step > k ? dim : p.step === k ? D.lerp(dim, 1, e) : 1).toFixed(3));
|
|
212
|
+
p.g.removeAttribute("transform");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
p.g.setAttribute("opacity", e.toFixed(3));
|
|
216
|
+
var off = (1 - e) * TRAVEL, tr = "";
|
|
217
|
+
if (off > 0.01) tr = vr === "slide" && p.dir ? "translate(" + (p.dir * off).toFixed(2) + " 0)" : "translate(0 " + off.toFixed(2) + ")";
|
|
218
|
+
if (tr) p.g.setAttribute("transform", tr); else p.g.removeAttribute("transform");
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
});
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// m-particles:状態変化の粒子モデルと、化学変化で保存される原子のモデル。
|
|
2
|
+
egatariParts.define({name: "particles", version: "2.0.1", requires: {base: "1.2.0"}, element: "m-particles"}, function(deps){
|
|
3
|
+
"use strict";
|
|
4
|
+
var base = deps.base;
|
|
5
|
+
var STATES = ["solid", "liquid", "gas"];
|
|
6
|
+
var SHAPES = ["linear", "bent", "trigonal", "tetrahedral", "chain"];
|
|
7
|
+
var MOLECULE_SHAPES = {H2O: "bent", H2S: "bent", SO2: "bent", CO2: "linear", NH3: "trigonal", CH4: "tetrahedral"};
|
|
8
|
+
var TEXT = {
|
|
9
|
+
ja: {states: ["固体", "液体", "気体"], changes: {solidliquid: "融解", liquidgas: "沸騰", liquidsolid: "凝固", gasliquid: "凝縮", solidgas: "昇華", gassolid: "昇華"}, before: "反応前", apart: "原子に分かれる", after: "反応後", atoms: "原子の数:", invalid: "データを確認してください"},
|
|
10
|
+
en: {states: ["Solid", "Liquid", "Gas"], changes: {solidliquid: "melting", liquidgas: "boiling", liquidsolid: "freezing", gasliquid: "condensation", solidgas: "sublimation", gassolid: "sublimation"}, before: "Reactants", apart: "Separate atoms", after: "Products", atoms: "Atoms: ", invalid: "Check the data"}
|
|
11
|
+
};
|
|
12
|
+
var COLORS = ["series-1", "series-2", "series-3", "series-4", "term", "accent2"];
|
|
13
|
+
// 全体が読めたときだけ採用する。括弧・電荷・係数・0・不正な桁を黙って落とさない。
|
|
14
|
+
function parseFormula(s){
|
|
15
|
+
if (typeof s !== "string" || !/^(?:[A-Z][a-z]?(?:[1-9][0-9]*)?)+$/.test(s)) throw new Error("formula " + JSON.stringify(s) + ": use element symbols and positive integer counts (no parentheses or charges)");
|
|
16
|
+
var out = [], counts = Object.create(null), re = /([A-Z][a-z]?)([1-9][0-9]*)?/g, m;
|
|
17
|
+
while ((m = re.exec(s))){
|
|
18
|
+
var n = m[2] ? +m[2] : 1;
|
|
19
|
+
if (!Number.isSafeInteger(n) || n > 24 || out.length + n > 24) throw new Error("formula " + s + ": more than 24 atoms");
|
|
20
|
+
counts[m[1]] = (counts[m[1]] || 0) + n;
|
|
21
|
+
for (var i = 0; i < n; i++) out.push(m[1]);
|
|
22
|
+
}
|
|
23
|
+
return {atoms: out, counts: counts};
|
|
24
|
+
}
|
|
25
|
+
function formulaText(s){ return s.replace(/([0-9])/g, "_$1"); }
|
|
26
|
+
function unicodeFormula(s){ return s.replace(/[0-9]/g, function(n){ return "₀₁₂₃₄₅₆₇₈₉"[+n]; }); }
|
|
27
|
+
function equation(side, format){ return side.map(function(m){ return (m.n === 1 ? "" : m.n) + format(m.formula); }).join(" + "); }
|
|
28
|
+
function hash(i){
|
|
29
|
+
var n = Math.imul(i + 1, 2654435761); n ^= n >>> 16;
|
|
30
|
+
n = Math.imul(n, 2246822507); n ^= n >>> 13; n = Math.imul(n, 3266489909); n ^= n >>> 16;
|
|
31
|
+
return (n >>> 0) / 4294967296;
|
|
32
|
+
}
|
|
33
|
+
// 正方形に近い因数の組を選ぶ。素数や容器に収まる組がない場合は最終行を中央に置く。
|
|
34
|
+
function latticeColumns(n, aspect, maxCols){
|
|
35
|
+
var ideal = Math.sqrt(n * aspect), best = 0, error = Infinity;
|
|
36
|
+
for (var c = Math.ceil(Math.sqrt(n)); c <= Math.min(maxCols || n, n > 3 ? n / 2 : n); c++) if (n % c === 0){
|
|
37
|
+
var d = Math.abs(c - ideal); if (d < error){ best = c; error = d; }
|
|
38
|
+
}
|
|
39
|
+
return best || Math.min(maxCols || n, Math.ceil(ideal));
|
|
40
|
+
}
|
|
41
|
+
function segmentDistance(p, a, b){
|
|
42
|
+
var dx = b.x - a.x, dy = b.y - a.y, den = dx * dx + dy * dy;
|
|
43
|
+
var u = den ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / den)) : 0;
|
|
44
|
+
return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
|
|
45
|
+
}
|
|
46
|
+
function set(e, a, v){ v = String(v); if (e.getAttribute(a) !== v) e.setAttribute(a, v); }
|
|
47
|
+
function text(e, s){ if (e.textContent !== s) e.textContent = s; }
|
|
48
|
+
var Part = class extends base.MotionElement {
|
|
49
|
+
static partName = "particles";
|
|
50
|
+
// 先の並び方・生成物を授業で予想させる(orbit と同じ扱い)。
|
|
51
|
+
static preview = "none";
|
|
52
|
+
static steps = 2;
|
|
53
|
+
static shape = {
|
|
54
|
+
schema: {type: "object", additionalProperties: false, properties: {
|
|
55
|
+
states: {type: "array", minItems: 1, items: {type: "string", enum: STATES}},
|
|
56
|
+
substance: {type: "string"},
|
|
57
|
+
labels: {type: ["array", "object"], items: {type: ["string", "null"]}, properties: {before: {type: "string"}, apart: {type: "string"}, after: {type: "string"}, atoms: {type: "string"}}, additionalProperties: false},
|
|
58
|
+
reactants: {type: "array", minItems: 1, maxItems: 24, items: {type: "object", required: ["formula", "n"], additionalProperties: false, properties: {formula: {type: "string"}, n: {type: "integer"}, shape: {type: "string", enum: SHAPES}}}},
|
|
59
|
+
products: {type: "array", minItems: 1, maxItems: 24, items: {type: "object", required: ["formula", "n"], additionalProperties: false, properties: {formula: {type: "string"}, n: {type: "integer"}, shape: {type: "string", enum: SHAPES}}}}
|
|
60
|
+
}},
|
|
61
|
+
example: {states: ["solid", "liquid", "gas"], substance: "水"}
|
|
62
|
+
};
|
|
63
|
+
static props = {
|
|
64
|
+
mode: {type: "string", default: "state", doc: "state(状態変化)か reaction(化学変化)"},
|
|
65
|
+
count: {type: "number", default: 16, doc: "状態変化で描く粒子の数(6〜30 の整数。数と大きさは一定)"},
|
|
66
|
+
size: {type: "number", default: 28, doc: "名前・式の字の大きさ(px。24 以上)"},
|
|
67
|
+
dur: {type: "number", default: 1.2, doc: "1 ステップの動きの秒数"},
|
|
68
|
+
volume: {type: "bool", default: false, doc: "状態に合わせて容器の幅を変える(気体は広い)"},
|
|
69
|
+
motion: {type: "bool", default: true, doc: "状態変化の粒子に静止した運動の印を付ける"}
|
|
70
|
+
};
|
|
71
|
+
get data(){
|
|
72
|
+
var d = super.data;
|
|
73
|
+
// JSON がない場合だけ既定値。JSON の null や不正な型は base の shape 検査へ渡す。
|
|
74
|
+
var hasJSON = [].some.call(this.children, function(c){ return c.localName === "script" && String(c.getAttribute("type") || "").trim().toLowerCase() === "application/json"; });
|
|
75
|
+
return d === null && !hasJSON ? {} : d;
|
|
76
|
+
}
|
|
77
|
+
get steps(){ return this.plan().reaction ? 3 : this.plan().states.length - 1; }
|
|
78
|
+
duration(k){ return k >= 1 && k <= this.steps ? (Number.isFinite(this.props.dur) && this.props.dur > 0 ? this.props.dur : 1.2) : 0; }
|
|
79
|
+
plan(){
|
|
80
|
+
if (this._plan) return this._plan;
|
|
81
|
+
var d = this.data || {}, p = {reaction: this.props.mode === "reaction", states: d.states || STATES, notes: [], fatal: false};
|
|
82
|
+
if (!p.reaction){
|
|
83
|
+
if (d.reactants || d.products || (d.labels && !Array.isArray(d.labels))){ p.notes.push("state mode takes states and a labels array"); p.fatal = true; }
|
|
84
|
+
return (this._plan = p);
|
|
85
|
+
}
|
|
86
|
+
p.elements = []; p.sides = []; p.totals = [];
|
|
87
|
+
try {
|
|
88
|
+
if (!d.reactants || !d.products || Array.isArray(d.labels) || d.states || d.substance) throw new Error("reaction mode needs reactants, products and optional labels object");
|
|
89
|
+
[d.reactants, d.products].forEach(function(side){
|
|
90
|
+
var molecules = [], total = Object.create(null), N = 0;
|
|
91
|
+
side.forEach(function(m){
|
|
92
|
+
if (!Number.isSafeInteger(m.n) || m.n < 1 || m.n > 24) throw new Error("coefficient n must be an integer from 1 to 24");
|
|
93
|
+
var f = parseFormula(m.formula);
|
|
94
|
+
N += f.atoms.length * m.n;
|
|
95
|
+
if (N > 24) throw new Error("more than 24 atoms on one side (maximum conserved inventory: 24)");
|
|
96
|
+
Object.keys(f.counts).forEach(function(e){
|
|
97
|
+
if (p.elements.indexOf(e) < 0) p.elements.push(e);
|
|
98
|
+
total[e] = (total[e] || 0) + f.counts[e] * m.n;
|
|
99
|
+
});
|
|
100
|
+
for (var j = 0; j < m.n; j++) molecules.push({atoms: f.atoms.slice(), shape: m.shape || MOLECULE_SHAPES[m.formula] || (f.atoms.length <= 3 ? "linear" : "chain")});
|
|
101
|
+
});
|
|
102
|
+
p.sides.push(molecules); p.totals.push(total);
|
|
103
|
+
});
|
|
104
|
+
if (p.elements.length > 6) throw new Error("more than 6 elements");
|
|
105
|
+
p.balanced = p.elements.every(function(e){ return (p.totals[0][e] || 0) === (p.totals[1][e] || 0); });
|
|
106
|
+
p.counts = p.elements.map(function(e){ return e + " " + (p.totals[0][e] || 0) + " → " + (p.totals[1][e] || 0); });
|
|
107
|
+
if (!p.balanced) p.notes.push("unbalanced equation: " + p.counts.join(", ") + "; static comparison only");
|
|
108
|
+
p.eq = equation(d.reactants, formulaText) + " → " + equation(d.products, formulaText);
|
|
109
|
+
p.accessible = equation(d.reactants, unicodeFormula) + " → " + equation(d.products, unicodeFormula);
|
|
110
|
+
} catch (e){ p.notes.push(e.message); p.fatal = true; }
|
|
111
|
+
return (this._plan = p);
|
|
112
|
+
}
|
|
113
|
+
mount(ctx){
|
|
114
|
+
var P = this.props, p = this.plan(), self = this;
|
|
115
|
+
p.notes.forEach(function(m){ ctx.report("data", "[particles] " + m); });
|
|
116
|
+
if (["state", "reaction"].indexOf(P.mode) < 0) ctx.report("attr", "[particles] unknown mode; using state");
|
|
117
|
+
[["count", 16, function(v){ return Number.isInteger(v) && v >= 6 && v <= 30; }], ["size", 28, function(v){ return Number.isFinite(v) && v >= 24; }], ["dur", 1.2, function(v){ return Number.isFinite(v) && v > 0; }]].forEach(function(a){
|
|
118
|
+
if (!a[2](P[a[0]])){ ctx.report("attr", "[particles] invalid " + a[0] + "; using " + a[1]); P[a[0]] = a[1]; }
|
|
119
|
+
});
|
|
120
|
+
var lang = this.closest("[lang]");
|
|
121
|
+
this.T = /^ja\b/i.test((lang && lang.getAttribute("lang")) || ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
122
|
+
this.words = Object.assign({}, this.T, p.reaction ? (this.data || {}).labels : {});
|
|
123
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
|
|
124
|
+
this.W = this.clientWidth; this.H = this.clientHeight;
|
|
125
|
+
this.svg = base.el("svg", {viewBox: "0 0 " + this.W + " " + this.H, width: this.W, height: this.H, "aria-hidden": "true", style: "display:block"}, this);
|
|
126
|
+
this.setAttribute("role", "img");
|
|
127
|
+
if (p.fatal){ this.label(this.svg, this.W / 2, this.H / 2, this.T.invalid); if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", this.T.invalid); return; }
|
|
128
|
+
if (p.reaction) this.drawReaction(ctx); else this.drawState(ctx);
|
|
129
|
+
if (!this.getAttribute("aria-label")){
|
|
130
|
+
var ja = this.T === TEXT.ja;
|
|
131
|
+
var name = p.reaction ? p.accessible + ". " + this.words.atoms + p.counts.join(ja ? "、" : ", ") :
|
|
132
|
+
((this.data || {}).substance ? this.data.substance + (ja ? "の" : " ") : "") + (ja ? "粒子のモデル:" : "particle model: ") + p.states.map(function(s, i){ return self.stateLabel(i); }).join("→") +
|
|
133
|
+
(ja ? "。粒子の数(" + P.count + ")と大きさは変わらず、間隔と動きが変わる" : ". Particle count (" + P.count + ") and size stay constant; spacing and motion change.");
|
|
134
|
+
this.setAttribute("aria-label", name);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
label(g, x, y, s, fs, anchor, tone){
|
|
138
|
+
return base.mtext(g, x, y, s, {"font-size": fs || this.props.size, "text-anchor": anchor || "middle", fill: "var(--" + (tone || "fg") + ")"});
|
|
139
|
+
}
|
|
140
|
+
checkWidth(s, fs, width, ctx){ if (base.textWidth(s, fs, {font: this, mark: true}) > width) ctx.report("size", "[particles] a label does not fit; shorten it or make the element larger"); }
|
|
141
|
+
stateLabel(i){ var d = this.data || {}, v = (d.labels || [])[i]; return v === undefined || v === null ? this.T.states[STATES.indexOf(this.plan().states[i])] : v; }
|
|
142
|
+
stateBox(s){
|
|
143
|
+
var full = Math.min(this.W - 40, 700), w = full;
|
|
144
|
+
if (this.props.volume && s !== "gas"){
|
|
145
|
+
var layerWidth = 54;
|
|
146
|
+
for (var i = 1; i < Math.ceil((this.props.count + 1) / 2); i++) layerWidth += 38.2 + 3 * hash(i + 71);
|
|
147
|
+
w = Math.min(full, Math.max(full * 0.72, layerWidth));
|
|
148
|
+
}
|
|
149
|
+
var h = Math.min(this.H - 108, Math.max(240, Math.ceil(this.props.count / 6) * 50 + 40));
|
|
150
|
+
return {x: (this.W - w) / 2, y: 44, width: w, height: h};
|
|
151
|
+
}
|
|
152
|
+
boxWidth(s){ return this.stateBox(s).width; }
|
|
153
|
+
arrangement(s){
|
|
154
|
+
var N = this.props.count, r = 19, box = this.stateBox(s), floor = box.y + box.height - r - 1.5, out = [], i;
|
|
155
|
+
if (s === "gas"){
|
|
156
|
+
// 最良候補法。格子からずらすのでなく、既存の点から最も離れた候補を採る。
|
|
157
|
+
var margin = r + 30;
|
|
158
|
+
for (i = 0; i < N; i++){
|
|
159
|
+
var best = null, score = -1;
|
|
160
|
+
for (var j = 0; j < 768; j++){
|
|
161
|
+
var seed = i * 1536 + j * 2 + 503;
|
|
162
|
+
var q = {x: box.x + margin + hash(seed) * (box.width - 2 * margin), y: box.y + margin + hash(seed + 1) * (box.height - 2 * margin)};
|
|
163
|
+
var d = out.length ? Math.min.apply(null, out.map(function(a){ return Math.hypot(q.x - a.x, q.y - a.y); })) : 1;
|
|
164
|
+
if (d > score){ score = d; best = q; }
|
|
165
|
+
if (!i) break;
|
|
166
|
+
}
|
|
167
|
+
out.push(best);
|
|
168
|
+
}
|
|
169
|
+
} else if (s === "solid"){
|
|
170
|
+
var pitch = 2 * r + 3, cols = latticeColumns(N, 1, Math.floor((box.width - 2 * r - 8) / pitch) + 1);
|
|
171
|
+
for (i = 0; i < N;){
|
|
172
|
+
var row = Math.floor(i / cols), n = Math.min(cols, N - i);
|
|
173
|
+
for (var c = 0; c < n; c++, i++) out.push({x: this.W / 2 + (c - (n - 1) / 2) * pitch, y: floor - row * pitch});
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
// 床の列から積む。上の粒子は下の隣接する 2 粒子に接し、全ての中心間距離は 2r 以上。
|
|
177
|
+
var contact = 2 * r + 0.2;
|
|
178
|
+
var cols = Math.ceil((N + 1) / 2);
|
|
179
|
+
var row = [], x = 0;
|
|
180
|
+
for (i = 0; i < Math.min(cols, N); i++){
|
|
181
|
+
if (i){
|
|
182
|
+
var nextX = x + contact + 3 * hash(i + 71);
|
|
183
|
+
if (nextX + 2 * r + 16 > box.width + 1e-6) break;
|
|
184
|
+
x = nextX;
|
|
185
|
+
}
|
|
186
|
+
row.push({x: x, y: floor});
|
|
187
|
+
}
|
|
188
|
+
var offset = this.W / 2 - x / 2;
|
|
189
|
+
row.forEach(function(q){ q.x += offset; out.push(q); });
|
|
190
|
+
while (out.length < N && row.length > 1){
|
|
191
|
+
var next = [];
|
|
192
|
+
for (i = 0; i < row.length - 1; i++){
|
|
193
|
+
var a = row[i], b = row[i + 1], dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
|
|
194
|
+
var lift = Math.sqrt(Math.max(0, contact * contact - d * d / 4));
|
|
195
|
+
next.push({x: (a.x + b.x) / 2 + dy / d * lift, y: (a.y + b.y) / 2 - dx / d * lift});
|
|
196
|
+
}
|
|
197
|
+
var need = Math.min(next.length, N - out.length), start = Math.floor((next.length - need) / 2);
|
|
198
|
+
row = next.slice(start, start + need); row.forEach(function(q){ out.push(q); });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
separateParticles(points, box){
|
|
204
|
+
// 補間の途中も円を重ねない。毎フレーム同じ入力から解き、前の render に依存しない。
|
|
205
|
+
for (var it = 0; it < 240; it++){
|
|
206
|
+
var moved = false;
|
|
207
|
+
for (var i = 0; i < points.length; i++) for (var j = i + 1; j < points.length; j++){
|
|
208
|
+
var a = points[i], b = points[j], dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
|
|
209
|
+
if (d >= 38) continue;
|
|
210
|
+
var angle = hash(i * 31 + j) * 2 * Math.PI, ux = d > 1e-8 ? dx / d : Math.cos(angle), uy = d > 1e-8 ? dy / d : Math.sin(angle), shift = (38.02 - d) / 2;
|
|
211
|
+
a.x -= ux * shift; a.y -= uy * shift; b.x += ux * shift; b.y += uy * shift; moved = true;
|
|
212
|
+
}
|
|
213
|
+
points.forEach(function(q){ q.x = Math.max(box.x + 20.5, Math.min(box.x + box.width - 20.5, q.x)); q.y = Math.max(box.y + 20.5, Math.min(box.y + box.height - 20.5, q.y)); });
|
|
214
|
+
if (!moved) break;
|
|
215
|
+
}
|
|
216
|
+
return points;
|
|
217
|
+
}
|
|
218
|
+
transitionLabel(k){
|
|
219
|
+
if (!k) return this.stateLabel(0);
|
|
220
|
+
var p = this.plan(), change = this.T.changes[p.states[k - 1] + p.states[k]], ja = this.T === TEXT.ja;
|
|
221
|
+
return this.stateLabel(k - 1) + " → " + this.stateLabel(k) + (change ? (ja ? "(" : " (") + change + (ja ? ")" : ")") : "");
|
|
222
|
+
}
|
|
223
|
+
// 矢印の軸・矢じりの全てが、容器の中かつ他の粒子の外にある向きを選ぶ。
|
|
224
|
+
motionArrow(points, i, length, box){
|
|
225
|
+
var r = 19, p = points[i], best = null, score = -Infinity;
|
|
226
|
+
for (var n = 0; n < 72; n++){
|
|
227
|
+
var angle = (hash(i + 101) * 360 + n * 5) * Math.PI / 180, co = Math.cos(angle), si = Math.sin(angle);
|
|
228
|
+
var tip = r + 1.5 + length, local = [[r + 1.5, 0], [tip, 0], [tip - 3, -1.5], [tip - 3, 1.5]];
|
|
229
|
+
var q = local.map(function(v){ return {x: p.x + co * v[0] - si * v[1], y: p.y + si * v[0] + co * v[1]}; });
|
|
230
|
+
if (!q.every(function(v){ return v.x >= box.x + 2 && v.x <= box.x + box.width - 2 && v.y >= box.y + 2 && v.y <= box.y + box.height - 2; })) continue;
|
|
231
|
+
var segments = [[q[0], q[1]], [q[1], q[2]], [q[1], q[3]]], clearance = Infinity;
|
|
232
|
+
points.forEach(function(a, j){ if (j !== i) segments.forEach(function(seg){ clearance = Math.min(clearance, segmentDistance(a, seg[0], seg[1]) - r); }); });
|
|
233
|
+
if (clearance >= 1.2 && clearance > score){ score = clearance; best = {angle: angle * 180 / Math.PI, segments: segments, path: "M" + (r + 1.5) + ",0H" + tip + "m-3,-1.5L" + tip + ",0l-3,1.5"}; }
|
|
234
|
+
}
|
|
235
|
+
return best;
|
|
236
|
+
}
|
|
237
|
+
drawState(ctx){
|
|
238
|
+
var p = this.plan(), self = this, N = this.props.count;
|
|
239
|
+
this.particleRadius = 19; this.arrangements = {};
|
|
240
|
+
STATES.forEach(function(s){ self.arrangements[s] = self.arrangement(s); });
|
|
241
|
+
var fits = STATES.every(function(s){
|
|
242
|
+
var box = self.stateBox(s), points = self.arrangements[s];
|
|
243
|
+
return points.length === N && points.every(function(q, i){
|
|
244
|
+
return q.x - 19 >= box.x && q.x + 19 <= box.x + box.width && q.y - 19 >= box.y && q.y + 19 <= box.y + box.height &&
|
|
245
|
+
points.every(function(a, j){ return i === j || Math.hypot(q.x - a.x, q.y - a.y) >= (s === "gas" ? 2.6 * 19 : 38) - 1e-6; });
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
if (!fits) ctx.report("size", "[particles] particle model needs a larger box");
|
|
249
|
+
this.label(this.svg, this.W / 2, 29, (this.data || {}).substance || "");
|
|
250
|
+
this.box = base.el("rect", {rx: 16, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, this.svg);
|
|
251
|
+
this.particles = []; this.marks = [];
|
|
252
|
+
for (var i = 0; i < N; i++){
|
|
253
|
+
var g = base.el("g", {"data-particle": i}, this.svg);
|
|
254
|
+
base.el("circle", {r: 19, fill: "var(--term)"}, g);
|
|
255
|
+
this.marks.push(base.el("path", {fill: "none", stroke: "var(--fg)", "stroke-width": 1.5}, g));
|
|
256
|
+
this.particles.push(g);
|
|
257
|
+
}
|
|
258
|
+
this.stateName = this.label(this.svg, this.W / 2, this.stateBox("gas").y + this.stateBox("gas").height + 42, "");
|
|
259
|
+
for (var k = 0; k <= this.steps; k++) self.checkWidth(this.transitionLabel(k), this.props.size, this.W - 16, ctx);
|
|
260
|
+
this.checkWidth((this.data || {}).substance || "", this.props.size, this.W - 16, ctx);
|
|
261
|
+
}
|
|
262
|
+
// 中心原子と周囲の原子を平面に置く。未知の 3 原子分子は直線にする。
|
|
263
|
+
molecule(atoms, r, shape){
|
|
264
|
+
shape = shape || (atoms.length <= 3 ? "linear" : "chain");
|
|
265
|
+
var order = atoms.map(function(_, i){ return i; }), counts = {};
|
|
266
|
+
atoms.forEach(function(e){ counts[e] = (counts[e] || 0) + 1; });
|
|
267
|
+
var radial = (shape === "bent" && atoms.length === 3) || (shape === "trigonal" && atoms.length === 4) || (shape === "tetrahedral" && atoms.length === 5);
|
|
268
|
+
if (radial || (shape === "linear" && atoms.length === 3)){
|
|
269
|
+
var center = atoms.findIndex(function(e){ return counts[e] === 1; });
|
|
270
|
+
if (center >= 0){ order.splice(order.indexOf(center), 1); order.unshift(center); }
|
|
271
|
+
}
|
|
272
|
+
var cols = shape === "linear" ? atoms.length : Math.min(6, atoms.length), out = [];
|
|
273
|
+
order.forEach(function(j, i){
|
|
274
|
+
if (radial){
|
|
275
|
+
var angle = shape === "bent" ? (i === 1 ? 5 : 1) * Math.PI / 6 : -Math.PI / 2 + (i - 1) * 2 * Math.PI / (atoms.length - 1);
|
|
276
|
+
out[j] = i ? [2 * r * Math.cos(angle), 2 * r * Math.sin(angle)] : [0, 0];
|
|
277
|
+
} else if (shape === "linear" && atoms.length === 3){
|
|
278
|
+
out[j] = [[0, 0], [-2 * r, 0], [2 * r, 0]][i];
|
|
279
|
+
} else out[j] = [(i % cols) * r * 2, Math.floor(i / cols) * r * 2];
|
|
280
|
+
});
|
|
281
|
+
var minX = Math.min.apply(null, out.map(function(a){ return a[0]; })), minY = Math.min.apply(null, out.map(function(a){ return a[1]; }));
|
|
282
|
+
return out.map(function(a){ return {x: a[0] - minX + r, y: a[1] - minY + r}; });
|
|
283
|
+
}
|
|
284
|
+
moleculeLayout(side, width, r){
|
|
285
|
+
var self = this, slots = [], rows = [], row = [], rowW = 0, rowH = 0;
|
|
286
|
+
function flush(){ if (row.length) rows.push({molecules: row, width: rowW, height: rowH}); row = []; rowW = rowH = 0; }
|
|
287
|
+
side.forEach(function(m){
|
|
288
|
+
var atoms = m.atoms, pts = self.molecule(atoms, r, m.shape), w = Math.max.apply(null, pts.map(function(q){ return q.x; })) + r, h = Math.max.apply(null, pts.map(function(q){ return q.y; })) + r;
|
|
289
|
+
if (row.length && rowW + 24 + w > width) flush();
|
|
290
|
+
row.push({atoms: atoms, points: pts, width: w, height: h}); rowW += (row.length > 1 ? 24 : 0) + w; rowH = Math.max(rowH, h);
|
|
291
|
+
});
|
|
292
|
+
flush();
|
|
293
|
+
var y = 0, maxW = 0;
|
|
294
|
+
rows.forEach(function(row){
|
|
295
|
+
var x = (width - row.width) / 2; maxW = Math.max(maxW, row.width);
|
|
296
|
+
row.molecules.forEach(function(m){
|
|
297
|
+
m.points.forEach(function(q, i){ slots.push({e: m.atoms[i], x: x + q.x, y: y + (row.height - m.height) / 2 + q.y}); });
|
|
298
|
+
x += m.width + 24;
|
|
299
|
+
});
|
|
300
|
+
y += row.height + 22;
|
|
301
|
+
});
|
|
302
|
+
return {slots: slots, width: maxW, height: y - 22};
|
|
303
|
+
}
|
|
304
|
+
separatedLayout(n, r){
|
|
305
|
+
var cols = Math.min(n, latticeColumns(n, 2.5, Math.max(1, Math.floor((this.W - 24 - 2 * r) / (3 * r + 8)) + 1))), rows = Math.ceil(n / cols), pitch = 3 * r + 8, points = [];
|
|
306
|
+
for (var i = 0; i < n;){
|
|
307
|
+
var row = Math.floor(i / cols), count = Math.min(cols, n - i);
|
|
308
|
+
for (var j = 0; j < count; j++, i++) points.push({x: (j - (count - 1) / 2) * pitch, y: row * pitch + r});
|
|
309
|
+
}
|
|
310
|
+
return {points: points, width: (cols - 1) * pitch + 2 * r, height: (rows - 1) * pitch + 2 * r};
|
|
311
|
+
}
|
|
312
|
+
atom(g, a, id){
|
|
313
|
+
var p = this.plan(), tone = COLORS[p.elements.indexOf(a.e)], group = base.el("g", id === null ? {} : {"data-atom": id, "data-element": a.e}, g);
|
|
314
|
+
base.el("circle", {r: this.radius, fill: "none", stroke: "var(--" + tone + ")", "stroke-width": 3}, group);
|
|
315
|
+
this.label(group, 0, 8, a.e, 24, "middle", tone);
|
|
316
|
+
set(group, "transform", "translate(" + a.x + " " + a.y + ")");
|
|
317
|
+
return group;
|
|
318
|
+
}
|
|
319
|
+
drawReaction(ctx){
|
|
320
|
+
var p = this.plan(), self = this, W = this.W, gutter = 112, maxSide = (W - 24 - gutter) / 2, L;
|
|
321
|
+
// 全段階で同じ半径。大きいデータだけ少し小さくし、分離時にも一半径以上の隙間を確保する。
|
|
322
|
+
for (var r = 34; r >= 24; r--){
|
|
323
|
+
var source = this.moleculeLayout(p.sides[0], maxSide, r), target = this.moleculeLayout(p.sides[1], maxSide, r), free = this.separatedLayout(source.slots.length, r);
|
|
324
|
+
var pictureH = Math.max(source.height, target.height), height = Math.max(44 + pictureH + 94, 44 + free.height);
|
|
325
|
+
L = {radius: r, source: source, target: target, free: free, pictureH: pictureH, height: height};
|
|
326
|
+
if (height <= this.H - 8 && source.width <= maxSide && target.width <= maxSide && free.width <= W - 24) break;
|
|
327
|
+
}
|
|
328
|
+
if (L.height > this.H - 8 || L.source.width > maxSide || L.target.width > maxSide || L.free.width > W - 24) ctx.report("size", "[particles] molecules need a larger element");
|
|
329
|
+
this.radius = L.radius;
|
|
330
|
+
var sideW = Math.max(L.source.width, L.target.width, base.textWidth(this.words.before, 24, {font: this}), base.textWidth(this.words.after, 24, {font: this}), 160);
|
|
331
|
+
if (sideW > maxSide) ctx.report("size", "[particles] group captions need a wider element");
|
|
332
|
+
var left = (W - 2 * sideW - gutter) / 2, top = (this.H - L.height) / 2, captionY = top + 24, pictureTop = top + 44;
|
|
333
|
+
source = this.moleculeLayout(p.sides[0], sideW, L.radius); target = this.moleculeLayout(p.sides[1], sideW, L.radius);
|
|
334
|
+
function place(layout, x){ return layout.slots.map(function(q){ return {e: q.e, x: q.x + x, y: q.y + pictureTop + (L.pictureH - layout.height) / 2}; }); }
|
|
335
|
+
this.source = place(source, left); this.target = place(target, left + sideW + gutter);
|
|
336
|
+
this.separated = L.free.points.map(function(q){ return {x: W / 2 + q.x, y: pictureTop + q.y}; });
|
|
337
|
+
this.reactionLayout = {captionY: captionY, pictureTop: pictureTop, pictureBottom: pictureTop + L.pictureH, arrowY: pictureTop + L.pictureH / 2};
|
|
338
|
+
this.beforeName = this.label(this.svg, left + sideW / 2, captionY, this.words.before, 24);
|
|
339
|
+
this.afterName = this.label(this.svg, left + sideW * 1.5 + gutter, captionY, this.words.after, 24);
|
|
340
|
+
this.stageName = this.label(this.svg, W / 2, captionY, "", 24);
|
|
341
|
+
this.arrow = base.el("path", {d: "M" + (W / 2 - 32) + "," + this.reactionLayout.arrowY + "h64m-12,-8l12,8l-12,8", fill: "none", stroke: "var(--muted)", "stroke-width": 3}, this.svg);
|
|
342
|
+
this.reference = base.el("g", {"data-reference": "reactants"}, this.svg);
|
|
343
|
+
this.source.forEach(function(a){ self.atom(self.reference, a, null); });
|
|
344
|
+
this.live = base.el("g", {}, this.svg);
|
|
345
|
+
this.atoms = this.source.map(function(a, i){ return self.atom(self.live, a, i); });
|
|
346
|
+
var queues = Object.create(null);
|
|
347
|
+
this.source.forEach(function(a, i){ (queues[a.e] || (queues[a.e] = [])).push(i); });
|
|
348
|
+
this.destinations = this.source.map(function(a){ return a; });
|
|
349
|
+
if (p.balanced) this.target.forEach(function(a){ self.destinations[queues[a.e].shift()] = a; });
|
|
350
|
+
this.productReference = base.el("g", {"data-reference": "products"}, this.svg);
|
|
351
|
+
if (!p.balanced) this.target.forEach(function(a){ self.atom(self.productReference, a, null); });
|
|
352
|
+
this.summary = base.el("g", {}, this.svg);
|
|
353
|
+
this.equationName = this.label(this.summary, W / 2, this.reactionLayout.pictureBottom + 42, p.eq);
|
|
354
|
+
this.checkWidth(p.eq, this.props.size, W - 24, ctx);
|
|
355
|
+
var sep = this.T === TEXT.ja ? "、" : ", ", countText = this.words.atoms + p.counts.join(sep);
|
|
356
|
+
this.countsLine = base.el("text", {x: W / 2, y: this.reactionLayout.pictureBottom + 86, "font-size": 24, "text-anchor": "middle", fill: "var(--fg)"}, this.summary);
|
|
357
|
+
base.el("tspan", {}, this.countsLine).textContent = this.words.atoms;
|
|
358
|
+
p.elements.forEach(function(e, i){
|
|
359
|
+
base.el("tspan", {fill: "var(--" + ((p.totals[0][e] || 0) === (p.totals[1][e] || 0) ? "fg" : "emph") + ")"}, self.countsLine).textContent = (i ? sep : "") + p.counts[i];
|
|
360
|
+
});
|
|
361
|
+
this.checkWidth(countText, 24, W - 24, ctx);
|
|
362
|
+
[this.words.before, this.words.after].forEach(function(s){ self.checkWidth(s, 24, sideW, ctx); });
|
|
363
|
+
this.checkWidth(this.words.apart, 24, W - 24, ctx);
|
|
364
|
+
}
|
|
365
|
+
render(k, t){
|
|
366
|
+
var p = this.plan(); if (!this.svg || p.fatal) return;
|
|
367
|
+
k = Math.max(0, Math.min(this.steps, k));
|
|
368
|
+
var e = k ? base.prog(t, 0, this.duration(k)) : 0, self = this;
|
|
369
|
+
if (!p.reaction){
|
|
370
|
+
var a = Math.max(0, k - 1), b = k, from = p.states[a], to = p.states[b], A = this.arrangements[from], B = this.arrangements[to];
|
|
371
|
+
var boxA = this.stateBox(from), boxB = this.stateBox(to), box = {};
|
|
372
|
+
["x", "y", "width", "height"].forEach(function(key){ box[key] = base.lerp(boxA[key], boxB[key], e); set(self.box, key, box[key]); });
|
|
373
|
+
var points = this.currentParticles = this.separateParticles(A.map(function(q, i){ return {x: base.lerp(q.x, B[i].x, e), y: base.lerp(q.y, B[i].y, e)}; }), box);
|
|
374
|
+
this.motionPaths = [];
|
|
375
|
+
this.particles.forEach(function(g, i){
|
|
376
|
+
set(g, "transform", "translate(" + points[i].x.toFixed(3) + " " + points[i].y.toFixed(3) + ")");
|
|
377
|
+
var state = e < 0.5 ? from : to, solid = state === "solid", mark = null;
|
|
378
|
+
// 密に接した内部の粒子では、短縮せず空きのある粒子だけに矢印を描く。
|
|
379
|
+
if (self.props.motion && !solid) mark = self.motionArrow(points, i, state === "gas" ? 24 : 18, box);
|
|
380
|
+
self.motionPaths.push(mark);
|
|
381
|
+
set(self.marks[i], "transform", mark ? "rotate(" + mark.angle.toFixed(3) + ")" : "");
|
|
382
|
+
set(self.marks[i], "d", !self.props.motion ? "" : solid ? "M14,-19q4,2 5,5M-14,19q-4,-2 -5,-5" : mark ? mark.path : "");
|
|
383
|
+
});
|
|
384
|
+
text(this.stateName, this.transitionLabel(k));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
var final = k === 3 ? e : 0, visible = k === 0 ? 0 : k === 1 ? e : 1;
|
|
388
|
+
set(this.summary, "opacity", p.balanced ? final : visible);
|
|
389
|
+
set(this.live, "opacity", visible); set(this.arrow, "opacity", k >= 3 || !p.balanced ? 1 : 0);
|
|
390
|
+
set(this.reference, "opacity", p.balanced ? final : 0);
|
|
391
|
+
set(this.productReference, "opacity", p.balanced ? 0 : visible);
|
|
392
|
+
set(this.afterName, "opacity", p.balanced ? final : visible);
|
|
393
|
+
set(this.beforeName, "opacity", k === 3 || !p.balanced ? 1 : 0);
|
|
394
|
+
text(this.stageName, k === 3 || !p.balanced ? "" : k === 2 ? this.words.apart : this.words.before);
|
|
395
|
+
this.atoms.forEach(function(g, i){
|
|
396
|
+
var a = self.source[i], b = self.destinations[i], free = self.separated[i];
|
|
397
|
+
var from = k === 3 ? free : a, to = k >= 2 ? (k === 3 ? b : free) : a, q = k >= 2 ? e : 0;
|
|
398
|
+
if (!p.balanced){ from = to = a; q = 0; }
|
|
399
|
+
set(g, "transform", "translate(" + base.lerp(from.x, to.x, q).toFixed(3) + " " + base.lerp(from.y, to.y, q).toFixed(3) + ")");
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
return Part;
|
|
404
|
+
});
|