egatari 0.6.11 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -1
- package/bin/egatari.mjs +4 -3
- package/components.lock.json +30 -15
- package/components2.lock.json +201 -1
- package/fonts/@fontsource/fraunces/400.css +29 -0
- package/fonts/@fontsource/fraunces/700.css +29 -0
- package/fonts/@fontsource/fraunces/LICENSE +93 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/package.json +6 -0
- package/kit/check-messages.mjs +18 -7
- package/kit/check.mjs +12 -4
- package/kit/core/article-render.mjs +5 -5
- package/kit/core/build-core.mjs +25 -9
- package/kit/core/check-parity.mjs +1 -1
- package/kit/core/check-rules.mjs +2 -2
- package/kit/core/check-source.mjs +3 -0
- package/kit/core/colab-core.mjs +1 -1
- package/kit/core/kicker.mjs +42 -0
- package/kit/core/layout-scan.mjs +19 -7
- package/kit/core/llm-pack-data.mjs +8 -8
- package/kit/core/llm-pack.mjs +2 -2
- package/kit/core/theme-shapes.mjs +3 -1
- package/kit/core/themes-list.mjs +2 -0
- package/kit/instruction-version.json +1 -1
- package/kit/layouts.css +8 -0
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/package.json +2 -1
- package/themes/asagi/theme.json +1 -1
- package/themes/asagi/tokens.css +6 -0
- package/themes/bengara/theme.json +13 -0
- package/themes/bengara/tokens.css +66 -0
- package/themes/business/theme.json +1 -1
- package/themes/business/tokens.css +6 -0
- package/themes/default/theme.json +1 -1
- package/themes/default/tokens.css +9 -0
- package/themes/kogecha/theme.json +1 -1
- package/themes/kogecha/tokens.css +6 -0
- package/themes/kokugo/theme.json +1 -1
- package/themes/kokugo/tokens.css +6 -0
- package/themes/murasaki/theme.json +1 -1
- package/themes/murasaki/tokens.css +6 -0
- package/themes/sumi/theme.json +1 -1
- package/themes/sumi/tokens.css +8 -0
- package/themes/tokiwa/theme.json +1 -1
- package/themes/tokiwa/tokens.css +6 -0
- package/themes.lock.json +90 -24
- package/vendor/components/CATALOG.md +11 -11
- package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/README.en.md +38 -0
- package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/index.js +289 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/chords.json +89 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/extras.json +192 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ties.json +360 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/index.js +508 -0
- package/vendor/components/sha256/0dc2a0945e7a4004278fcc9b8f02223bbb87f6269bffe3dd3ebeb3a78ce23d34/index.js +404 -0
- package/vendor/components/sha256/0e2e45b024bb2f37e82c83a4d9cd9f9c16b5dc4924dde81735c268a3d49f9d7f/index.js +97 -0
- package/vendor/components/sha256/0ef62e33d330f8e31ccb1f480b5e3b349769a142cc2737a9e6583d5eff9f56ca/index.js +919 -0
- package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/README.en.md +48 -0
- package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/index.js +384 -0
- package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/README.en.md +34 -0
- package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/index.js +244 -0
- package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/README.en.md +44 -0
- package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/index.js +304 -0
- package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/README.en.md +44 -0
- package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/index.js +203 -0
- package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/README.en.md +37 -0
- package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/index.js +438 -0
- package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/README.en.md +24 -0
- package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/index.js +103 -0
- package/vendor/components/sha256/48a776e7683e1aba8cad5aa4067914c017681efaa74f175066e0ab081bf3d013/index.js +351 -0
- package/vendor/components/sha256/4a9331635c2dd28e4b46108eaffe49c6d29cf626ecb900ac6e9029552be0cf49/index.js +607 -0
- package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/README.en.md +23 -0
- package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/index.js +120 -0
- package/vendor/components/sha256/586063d3a4e24e2995923811b2b9466bde86dbaafb3bcf103546d3f28159205a/index.js +812 -0
- package/vendor/components/sha256/5acc5f87e29f1170bc35dbee08087d0d03c1023969c6c1b1367a0f559d60e5ee/index.js +198 -0
- package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/README.en.md +32 -0
- package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/index.js +222 -0
- package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/README.en.md +50 -0
- package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/index.js +171 -0
- package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/README.en.md +51 -0
- package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/index.js +228 -0
- package/vendor/components/sha256/6364043cb31bbd86aacb7432af1a8affef8cae5c6efdbe13fbebd116fd51b91f/index.js +233 -0
- package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/README.en.md +66 -0
- package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/index.js +920 -0
- package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/README.en.md +35 -0
- package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/index.js +179 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/index.js +4868 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/names.txt +4808 -0
- package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/README.en.md +40 -0
- package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/index.js +348 -0
- package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/README.en.md +42 -0
- package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/index.js +268 -0
- package/vendor/components/sha256/8cb367c71c002c689defddc6f075be911d5485421715119b5515181e962a2401/index.js +121 -0
- package/vendor/components/sha256/97bfd6e79c7278c55153bf4c2330da0432cf0ee312baa11650e07cdd7912831d/index.js +354 -0
- package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/README.en.md +40 -0
- package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/index.js +348 -0
- package/vendor/components/sha256/c108119117042cacc65a35ec73fcab95a2a92b2a2797129f66e326783f8db178/index.js +465 -0
- package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/README.en.md +23 -0
- package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/index.js +289 -0
- package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/README.en.md +31 -0
- package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/index.js +236 -0
- package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/README.en.md +42 -0
- package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/index.js +488 -0
- package/vendor/components/sha256/d998b5db828427505e39cdae67676dc6480c791d6037152dec222ae81cdbba1f/index.js +484 -0
- package/vendor/components/sha256/ea17602aaecca64b672b3bc827965ff378cb460250177f7b66f73081a48d4e81/index.js +278 -0
- package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/README.en.md +22 -0
- package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/index.js +145 -0
- package/vendor/components-2/manifest-2.8.0.json +2199 -0
- package/vendor/themes/asagi/1.2.0/theme.json +14 -0
- package/vendor/themes/asagi/1.2.0/tokens.css +30 -0
- package/vendor/themes/business/1.2.0/theme.json +5 -0
- package/vendor/themes/business/1.2.0/tokens.css +41 -0
- package/vendor/themes/default/1.4.0/theme.json +4 -0
- package/vendor/themes/default/1.4.0/tokens.css +86 -0
- package/vendor/themes/kogecha/1.2.0/theme.json +10 -0
- package/vendor/themes/kogecha/1.2.0/tokens.css +29 -0
- package/vendor/themes/kokugo/1.2.0/theme.json +5 -0
- package/vendor/themes/kokugo/1.2.0/tokens.css +25 -0
- package/vendor/themes/murasaki/1.2.0/theme.json +10 -0
- package/vendor/themes/murasaki/1.2.0/tokens.css +25 -0
- package/vendor/themes/sumi/1.2.0/theme.json +10 -0
- package/vendor/themes/sumi/1.2.0/tokens.css +49 -0
- package/vendor/themes/tokiwa/1.2.0/theme.json +10 -0
- package/vendor/themes/tokiwa/1.2.0/tokens.css +27 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// m-particles:状態変化の粒子モデルと、化学変化で保存される原子のモデル。
|
|
2
|
+
egatariParts.define({name: "particles", version: "2.0.2", 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 Math.max(1, best || Math.min(maxCols || n, Math.ceil(ideal))); // at least 1 column, also when the box is 0 wide
|
|
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.max(0, Math.min(this.W - 40, 700)), w = full; // 0 when the element is too narrow, never negative
|
|
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.max(0, 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.max(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
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// m-market:市場規模の入れ子の円(TAM / SAM / SOM)。外の円から 1 つずつ、前の円の大きさから縮んで現れる
|
|
2
|
+
// <m-market unit="億円" style="height:420px"><script type="application/json">
|
|
3
|
+
// {"rings": [{"key": "TAM", "value": 3000, "basis": "国内の…"}, {"key": "SAM", "value": 600, "basis": "…"}, {"key": "SOM", "value": 30, "basis": "…"}]}
|
|
4
|
+
// (JSON の終わり)</m-market>
|
|
5
|
+
// 段階 j(1〜円の数)で j 番目の円。数字は円が縮みきってから出る(count="true" で縮みに合わせて数え上げる)
|
|
6
|
+
// 円の大きさ:scale="fixed"(既定。見やすい決まった比)か "area"(面積を値に比例。小さすぎる円は最小の大きさにする)
|
|
7
|
+
// 配置:layout="bottom"(既定。下端をそろえる)か "center"(同心)。円の名前・値・根拠(basis)は右に引き出し線で書く
|
|
8
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity を使い、プレイヤーのグローバルは使わない
|
|
9
|
+
egatariParts.define({name: "market", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-market"}, function(deps){
|
|
10
|
+
"use strict";
|
|
11
|
+
var base = deps.base;
|
|
12
|
+
return class extends base.MotionElement {
|
|
13
|
+
static partName = "market"; // the registry name (define meta name), for report prefixes
|
|
14
|
+
// データの形(kit/shape.js)。円は外から順
|
|
15
|
+
static shape = {
|
|
16
|
+
schema: {type: "object", additionalProperties: false, required: ["rings"], properties: {
|
|
17
|
+
rings: {type: "array", minItems: 1, items: {type: "object", required: ["value"], properties: {key: {type: "string"}, value: {type: "number"}, basis: {type: "string"}, tone: {type: "string"}}}}}},
|
|
18
|
+
example: {rings: [{key: "TAM", value: 3000, basis: "国内の…"}, {key: "SAM", value: 600, basis: "…"}, {key: "SOM", value: 30, basis: "…"}]},
|
|
19
|
+
};
|
|
20
|
+
static props = {
|
|
21
|
+
unit: {type: "string", default: "", doc: "値の単位(数字の後ろに付ける)"},
|
|
22
|
+
digits: {type: "number", default: 0, doc: "値の小数桁"},
|
|
23
|
+
scale: {type: "string", default: "fixed", doc: "fixed(決まった比)か area(面積を値に比例)"},
|
|
24
|
+
layout: {type: "string", default: "bottom", doc: "bottom(下端をそろえる)か center(同心)"},
|
|
25
|
+
dur: {type: "number", default: 0.9, doc: "1 つの円が現れる秒数"},
|
|
26
|
+
count: {type: "bool", default: false, doc: "値の数字を縮みに合わせて数え上げる"},
|
|
27
|
+
};
|
|
28
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : ((this.data || {}).rings || []).length; }
|
|
29
|
+
mount(ctx){
|
|
30
|
+
var P = this.props, D = base, self = this, R = (this.data || {}).rings || [];
|
|
31
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
32
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
33
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"}, this);
|
|
34
|
+
// 円は左の 4 割ほど、名前と数字は右
|
|
35
|
+
var big = Math.min(H / 2 - 6, W * 0.22), cx = 6 + big, bottom = H / 2 + big;
|
|
36
|
+
var fixed = [1, 0.64, 0.34, 0.16];
|
|
37
|
+
// area は値がすべて正で、外の円から順に小さくなるときだけ(そうでなければ円が要素の外にはみ出すか、半径が NaN になる)。
|
|
38
|
+
// そうでなければ知らせて、この図は fixed の比で描く
|
|
39
|
+
var area = P.scale === "area";
|
|
40
|
+
if (area && !R.every(function(r, i){ return typeof r.value === "number" && isFinite(r.value) && r.value > 0 && (i === 0 || r.value < R[i - 1].value); })){
|
|
41
|
+
ctx.report("data", "[market] scale=\"area\" needs values that are positive and get smaller from the outer ring inwards; the fixed spacing is used for this figure");
|
|
42
|
+
area = false;
|
|
43
|
+
}
|
|
44
|
+
var radii = R.map(function(r, i){
|
|
45
|
+
if (area) return Math.max(big * 0.14, big * Math.sqrt(r.value / R[0].value));
|
|
46
|
+
return big * (fixed[i] !== undefined ? fixed[i] : fixed[fixed.length - 1] * Math.pow(0.5, i - fixed.length + 1));
|
|
47
|
+
});
|
|
48
|
+
var cy = function(i){ return P.layout === "center" ? H / 2 : bottom - radii[i]; };
|
|
49
|
+
var tones = ["var(--term)", "var(--term)", "var(--emph)", "var(--emph)"];
|
|
50
|
+
var fills = [0.10, 0.18, 0.22, 0.3];
|
|
51
|
+
var gC = D.el("g", {}, svg), gL = D.el("g", {}, svg);
|
|
52
|
+
var lx = cx + big + 64, n = R.length;
|
|
53
|
+
this.rings = R.map(function(r, i){
|
|
54
|
+
var col = r.tone ? "var(--" + (/^(term|emph|muted|accent2|series-[1-4])$/.test(r.tone) ? r.tone : "term") + ")" : tones[Math.min(i, 3)];
|
|
55
|
+
var c = D.el("circle", {cx: cx, cy: cy(i), r: radii[i], fill: col, "fill-opacity": fills[Math.min(i, 3)], stroke: col, "stroke-width": i === n - 1 ? 3 : 2.2, opacity: 0}, gC);
|
|
56
|
+
// 引き出し線の起点:この円の見えている帯の中(次の円の上端との間)。最後の円は中心
|
|
57
|
+
var top = cy(i) - radii[i], nextTop = i + 1 < n ? cy(i + 1) - radii[i + 1] : null;
|
|
58
|
+
var py = nextTop !== null ? (top + nextTop) / 2 : cy(i);
|
|
59
|
+
// 名前と数字の行は高さを等分して並べる(上から順に)
|
|
60
|
+
var ly = (H / (n + 0.2)) * (i + 0.5) + 14;
|
|
61
|
+
var g = D.el("g", {opacity: 0}, gL);
|
|
62
|
+
D.el("circle", {cx: cx, cy: py, r: 5, fill: col}, g);
|
|
63
|
+
D.el("polyline", {points: cx + "," + py + " " + (lx - 40) + "," + py + " " + (lx - 12) + "," + (ly - 10), fill: "none", stroke: col, "stroke-width": 1.6}, g);
|
|
64
|
+
var key = D.mtext(g, lx, ly, r.key || "", {"font-size": 28, "font-weight": 700, fill: col});
|
|
65
|
+
// 数字は名前の後ろ(名前の幅は和文 1 字 = 1 字幅、ほかは 0.6 字幅の見積もり)、根拠は次の行
|
|
66
|
+
var kw = [...String(r.key || "")].reduce(function(a, ch){ return a + (/[\u0000-\u024f]/.test(ch) ? 0.7 : 1); }, 0) * 28;
|
|
67
|
+
var val = D.el("text", {x: lx + kw + 20, y: ly, "font-size": 36, "font-weight": 700, fill: "var(--fg)", style: "font-variant-numeric:tabular-nums"}, g);
|
|
68
|
+
var basis = r.basis ? D.mtext(g, lx, ly + 34, r.basis, {"font-size": 24, fill: "var(--muted)"}) : null;
|
|
69
|
+
// 最初の円は 1.15 倍から縮む。ただし要素の外にはみ出さない大きさまで
|
|
70
|
+
var prev = i ? radii[i - 1] : Math.max(radii[0], Math.min(radii[0] * 1.15, cy(0), H - cy(0), cx, W - cx));
|
|
71
|
+
return {r: r, c: c, g: g, val: val, basis: basis, rad: radii[i], prev: prev, cy: cy(i), pcy: i ? cy(i - 1) : cy(i), i: i};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
fmt(v){
|
|
75
|
+
var s = Math.abs(v).toFixed(this.props.digits).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
76
|
+
return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "") + this.props.unit;
|
|
77
|
+
}
|
|
78
|
+
duration(k){ return k >= 1 ? this.props.dur + (this.props.count ? 0 : 0.35) : 0; }
|
|
79
|
+
render(k, t, ctx){
|
|
80
|
+
var P = this.props, D = base, self = this, n = this.rings.length;
|
|
81
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の円と名前・数字を、最後の形でテーマの --preview-opacity の濃さに
|
|
82
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
83
|
+
this.rings.forEach(function(o){
|
|
84
|
+
var j = o.i + 1, ahead = preview && j > k;
|
|
85
|
+
var e = j < k || ahead ? 1 : j > k ? 0 : D.prog(t, 0, P.dur);
|
|
86
|
+
// 前の円の大きさ・位置から縮んで今の大きさへ
|
|
87
|
+
o.c.setAttribute("r", D.lerp(o.prev, o.rad, e).toFixed(2));
|
|
88
|
+
o.c.setAttribute("cy", D.lerp(o.pcy, o.cy, e).toFixed(2));
|
|
89
|
+
o.c.setAttribute("opacity", (ahead ? PV : j <= k ? Math.min(1, e * 2) : 0).toFixed(3));
|
|
90
|
+
// 名前と数字:縮みきってから(count なら縮みに合わせて)
|
|
91
|
+
var lo = ahead ? PV : P.count ? (j <= k ? Math.min(1, e * 3) : 0) : j < k ? 1 : j > k ? 0 : D.prog(t, P.dur, 0.35);
|
|
92
|
+
o.val.textContent = self.fmt(P.count ? o.r.value * (j < k ? 1 : e) : o.r.value);
|
|
93
|
+
o.g.setAttribute("opacity", lo.toFixed(3));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|