egatari 0.6.12 → 0.6.13-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 +2 -2
- package/README.md +2 -2
- package/bin/egatari.mjs +3 -1
- package/components.lock.json +141 -51
- package/components2.lock.json +500 -1
- package/kit/browser.mjs +19 -7
- package/kit/check-messages.mjs +2 -0
- package/kit/check.mjs +2 -0
- package/kit/core/article-links.mjs +5 -4
- package/kit/core/article-messages.mjs +6 -1
- package/kit/core/article-render.mjs +61 -42
- package/kit/core/article-text.mjs +42 -1
- package/kit/core/article.mjs +7 -6
- package/kit/core/build-core.mjs +4 -0
- package/kit/core/caution.mjs +49 -0
- package/kit/core/check-parity.mjs +1 -0
- package/kit/core/check-rules.mjs +3 -0
- package/kit/core/check-source.mjs +2 -0
- package/kit/core/colab-core.mjs +1 -1
- package/kit/core/llm-pack-assemble.mjs +4 -3
- package/kit/core/llm-pack-data.mjs +124 -10
- package/kit/core/part-labels.mjs +3 -0
- package/kit/core/purposes.mjs +6 -8
- package/kit/instruction-version.json +1 -1
- package/kit/layouts.css +8 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/package.json +1 -1
- package/themes/asagi/theme.json +1 -1
- package/themes/asagi/tokens.css +2 -0
- package/themes/bengara/theme.json +1 -1
- package/themes/bengara/tokens.css +2 -0
- package/themes/business/theme.json +1 -1
- package/themes/business/tokens.css +2 -0
- package/themes/default/theme.json +1 -1
- package/themes/default/tokens.css +2 -0
- package/themes/kogecha/theme.json +1 -1
- package/themes/kogecha/tokens.css +2 -0
- package/themes/kokugo/theme.json +1 -1
- package/themes/kokugo/tokens.css +2 -0
- package/themes/murasaki/theme.json +1 -1
- package/themes/murasaki/tokens.css +2 -0
- package/themes/sumi/theme.json +1 -1
- package/themes/sumi/tokens.css +2 -0
- package/themes/tokiwa/theme.json +1 -1
- package/themes/tokiwa/tokens.css +2 -0
- package/themes.lock.json +92 -28
- package/vendor/components/CATALOG.md +6 -3
- package/vendor/components/sha256/061415b5f5a1861e115103224ebbcaf689b602cd9972516001f50f4646d3692a/README.en.md +33 -0
- package/vendor/components/sha256/061415b5f5a1861e115103224ebbcaf689b602cd9972516001f50f4646d3692a/index.js +390 -0
- package/vendor/components/sha256/1854c2d9091a44f465a8de71de2ef3cfa26de3750c67aba4d0ab6eef9b826b8c/README.en.md +21 -0
- package/vendor/components/sha256/1854c2d9091a44f465a8de71de2ef3cfa26de3750c67aba4d0ab6eef9b826b8c/index.js +108 -0
- package/vendor/components/sha256/19803bbabc26cab7937b17c101f0529239ad505e2ef72a5b21c5d0b9afb063b5/README.en.md +35 -0
- package/vendor/components/sha256/19803bbabc26cab7937b17c101f0529239ad505e2ef72a5b21c5d0b9afb063b5/index.js +179 -0
- package/vendor/components/sha256/1fac9a4c6608f0150a51275fb11bad0dcff00bed1696c2d93d150fa97219e41a/README.en.md +23 -0
- package/vendor/components/sha256/1fac9a4c6608f0150a51275fb11bad0dcff00bed1696c2d93d150fa97219e41a/index.js +147 -0
- package/vendor/components/sha256/24e433f4e96427b5b4625ea6542ae74393a8610a9e3d331d01481b3185c827d4/README.en.md +66 -0
- package/vendor/components/sha256/24e433f4e96427b5b4625ea6542ae74393a8610a9e3d331d01481b3185c827d4/index.js +984 -0
- package/vendor/components/sha256/336f518ad98df0700348406a1fcc4a2de6843b68de0d2e6fcb2cf92428cc3f32/index.js +121 -0
- package/vendor/components/sha256/362590bb028486c9b92c90b0c04bb21c9989b7da1b9d234f0d3c26093770eb52/index.js +228 -0
- package/vendor/components/sha256/3c79d2605e1949c302a5e190dab3d12812e548af7d66e80dd73dc517dfa1ae3d/index.js +268 -0
- package/vendor/components/sha256/4526a332a77fce02370c58d6acd2b83777bfac10aca91e304f105ca2d6935e21/README.en.md +40 -0
- package/vendor/components/sha256/4526a332a77fce02370c58d6acd2b83777bfac10aca91e304f105ca2d6935e21/index.js +405 -0
- package/vendor/components/sha256/46fd8b2bfa296e18d7720dec9c9639421fb02cec1b641e50e2cadefcc3945675/README.en.md +31 -0
- package/vendor/components/sha256/46fd8b2bfa296e18d7720dec9c9639421fb02cec1b641e50e2cadefcc3945675/index.js +236 -0
- package/vendor/components/sha256/49fc5add9b34d9a34fcf9ffa3772da4a36d054feead033a7212b98ce1e18705d/index.js +465 -0
- package/vendor/components/sha256/4bedc6e22490461bb624d1801954aed230e9f47e393d2a9779c89c4c6483ab3e/README.en.md +42 -0
- package/vendor/components/sha256/4bedc6e22490461bb624d1801954aed230e9f47e393d2a9779c89c4c6483ab3e/index.js +549 -0
- package/vendor/components/sha256/5b3a29cd3ad1c572ba2864430fde589a0fa90f5a7cf6c8753ccfc97dd16d99f3/README.en.md +37 -0
- package/vendor/components/sha256/5b3a29cd3ad1c572ba2864430fde589a0fa90f5a7cf6c8753ccfc97dd16d99f3/index.js +501 -0
- package/vendor/components/sha256/6e9d8d26ba0427f26a8143ecaf1ff3a3fec1a6cb114ef5feed15a62f6a6e77c2/README.en.md +54 -0
- package/vendor/components/sha256/6e9d8d26ba0427f26a8143ecaf1ff3a3fec1a6cb114ef5feed15a62f6a6e77c2/index.js +470 -0
- package/vendor/components/sha256/9ffe48f7c39657aacbbca355c8268a4682f306c0e453bdd73b69c3ed7e0cb030/README.en.md +30 -0
- package/vendor/components/sha256/9ffe48f7c39657aacbbca355c8268a4682f306c0e453bdd73b69c3ed7e0cb030/index.js +192 -0
- package/vendor/components/sha256/a04ba1b59cae0406ad91c64da77df1f77d0ae6fb5629da4549452f68b926a20b/index.js +315 -0
- package/vendor/components/sha256/c129c1c6c5df8ddafed87ea41fe6f9fc03784b2904059321f970d16ff3238bf8/index.js +312 -0
- package/vendor/components/sha256/d831672acd189fd9e6bd294bdbceab539f4b2dc4ec0415e776a9fe740c499544/index.js +97 -0
- package/vendor/components/sha256/dc5d9e6da444ef49ac343c870271c6679601040bf3a38a389a7991ffd39dd0fc/index.js +607 -0
- package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/index.js +4868 -0
- package/vendor/components/sha256/deae02519dd79e53cf18137777d486cb3b3234ab02a71d26c4e2925593b047ba/names.txt +4808 -0
- package/vendor/components/sha256/e76667b8fbaeb6c5d05ada81b2230f21388e2e68f3437034d2a54ead1c8ccbef/README.en.md +32 -0
- package/vendor/components/sha256/e76667b8fbaeb6c5d05ada81b2230f21388e2e68f3437034d2a54ead1c8ccbef/index.js +222 -0
- package/vendor/components-2/manifest-2.9.0.json +2204 -0
- package/vendor/components-2/manifest-2.9.1.json +2204 -0
- package/vendor/egatari-spec/SOURCE.json +3 -3
- package/vendor/themes/asagi/1.3.0/theme.json +14 -0
- package/vendor/themes/asagi/1.3.0/tokens.css +36 -0
- package/vendor/themes/bengara/1.0.0/theme.json +13 -0
- package/vendor/themes/bengara/1.0.0/tokens.css +66 -0
- package/vendor/themes/business/1.3.0/theme.json +5 -0
- package/vendor/themes/business/1.3.0/tokens.css +47 -0
- package/vendor/themes/default/1.5.0/README.ja.md +65 -0
- package/vendor/themes/default/1.5.0/README.md +65 -0
- package/vendor/themes/default/1.5.0/theme.json +4 -0
- package/vendor/themes/default/1.5.0/tokens.css +95 -0
- package/vendor/themes/kogecha/1.3.0/theme.json +10 -0
- package/vendor/themes/kogecha/1.3.0/tokens.css +35 -0
- package/vendor/themes/kokugo/1.3.0/theme.json +5 -0
- package/vendor/themes/kokugo/1.3.0/tokens.css +31 -0
- package/vendor/themes/murasaki/1.3.0/theme.json +10 -0
- package/vendor/themes/murasaki/1.3.0/tokens.css +31 -0
- package/vendor/themes/sumi/1.3.0/theme.json +10 -0
- package/vendor/themes/sumi/1.3.0/tokens.css +57 -0
- package/vendor/themes/tokiwa/1.3.0/theme.json +10 -0
- package/vendor/themes/tokiwa/1.3.0/tokens.css +33 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// m-orbit:月の満ち欠け(mode="moon"、既定)と金星の満ち欠け(mode="venus")。左に北極の上から見た図、右に地球から見た形を並べ、同じ角度で動かす
|
|
2
|
+
// <m-orbit style="height:440px"></m-orbit>(データは省ける。8 つの位置を新月から順に回り、最後に新月へ戻る)
|
|
3
|
+
// <m-orbit mode="venus" style="height:440px"><script type="application/json">{"visit": [3, 4, 5]}</script></m-orbit>
|
|
4
|
+
// 形は絵ではなく位置から計算する:太陽・地球・天体の角度から、光っている側(地球から見て右か左か)と欠け方(明暗の境の楕円)を決める。
|
|
5
|
+
// 大きさと距離は実際の比ではない(教えるための図)。比は earth・moon の属性で変えられる。
|
|
6
|
+
// 月:位置 i は太陽の向きから反時計回りに 360°·i/N(0 が新月)。太陽の光は sun の側から来る。地球の上の人(observer)は、
|
|
7
|
+
// 月が真夜中の側にあるとき(90°〜270°)は月が南中する時刻に、夕方の側(0°〜90°)は日の入り、明け方の側(270°〜360°)は日の出に立つ。
|
|
8
|
+
// 新月は正午。人の時刻は段階の間で反時計回りに進む。
|
|
9
|
+
// 金星:太陽を中心に、地球を下に止めて(地球との位置の関係だけを見せる)、位置 i は外合から反時計回りに 360°·i/N。
|
|
10
|
+
// 地球から見た大きさは距離に反比例し、太陽からの離角で夕方の西の空か明け方の東の空かを決める。
|
|
11
|
+
// 字は部品の中の表から授業の言語(ctx.lang)で選ぶ。データの labels・notes で位置ごとに上書きできる(null は表のまま、"" は字なし)。
|
|
12
|
+
// eclipse(月だけ):新月と満月の位置で、太陽・月・地球がそろったときの影(日食・月食)を描く。月の軌道の傾きは描かない(README)。
|
|
13
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・lerp だけを使い、プレイヤーのグローバルは使わない。
|
|
14
|
+
egatariParts.define({name: "orbit", version: "2.0.6", requires: {base: "1.2.0"}, element: "m-orbit"}, function(deps){
|
|
15
|
+
"use strict";
|
|
16
|
+
var base = deps.base;
|
|
17
|
+
var TAU = 2 * Math.PI;
|
|
18
|
+
// 字の表。ja と en。位置の名前は角度(度)で引く
|
|
19
|
+
var TEXT = {
|
|
20
|
+
ja: {top: "北極の上から見た図", moonView: "地球から見た月", venusView: "地球から見た金星", light: "太陽の光", sun: "太陽", earth: "地球",
|
|
21
|
+
moon: {0: "新月", 45: "三日月", 90: "上弦の月", 180: "満月", 270: "下弦の月"},
|
|
22
|
+
venusEast: "よいの明星", venusWest: "明けの明星",
|
|
23
|
+
solar: "日食", lunar: "月食", solarNote: "月が太陽をかくす", lunarNote: "月が地球の影に入る",
|
|
24
|
+
hidden: "見えない", nearSun: "太陽に近くて見えない", eveningSky: "夕方・西の空", dawnSky: "明け方・東の空",
|
|
25
|
+
time: function(h){ return h === 0 ? "真夜中" : h === 6 ? "明け方" : h === 12 ? "正午" : h === 18 ? "夕方" : h + "時ごろ"; },
|
|
26
|
+
sky: function(d){ return d + "の空"; }, join: "・",
|
|
27
|
+
dirs: {S: "南", SE: "南東", SW: "南西", E: "東", W: "西", N: "北", NE: "北東", NW: "北西"}},
|
|
28
|
+
en: {top: "Seen from above the North Pole", moonView: "The Moon from Earth", venusView: "Venus from Earth", light: "Sunlight", sun: "Sun", earth: "Earth",
|
|
29
|
+
moon: {0: "new moon", 45: "waxing crescent", 90: "first quarter", 180: "full moon", 270: "last quarter"},
|
|
30
|
+
venusEast: "evening star", venusWest: "morning star",
|
|
31
|
+
solar: "solar eclipse", lunar: "lunar eclipse", solarNote: "the Moon hides the Sun", lunarNote: "the Moon is in Earth's shadow",
|
|
32
|
+
hidden: "not visible", nearSun: "too close to the Sun to see", eveningSky: "evening, western sky", dawnSky: "dawn, eastern sky",
|
|
33
|
+
time: function(h){ return h === 0 ? "midnight" : h === 6 ? "dawn" : h === 12 ? "noon" : h === 18 ? "evening" : "about " + (h % 12 || 12) + (h < 12 ? " am" : " pm"); },
|
|
34
|
+
sky: function(d){ return d + " sky"; }, join: ", ",
|
|
35
|
+
dirs: {S: "southern", SE: "southeastern", SW: "southwestern", E: "eastern", W: "western", N: "northern", NE: "northeastern", NW: "northwestern"}},
|
|
36
|
+
};
|
|
37
|
+
// 金星の軌道の半径(地球の軌道を 1 とした比。距離と最大離角はこの値から計算する)
|
|
38
|
+
var VENUS_R = 0.723;
|
|
39
|
+
// 光っている面と影の面の色(テーマの色だけ)。明るい地(地が字より明るい):明るい面は --accent2 を地に薄く混ぜ、影の面は字の色を
|
|
40
|
+
// 地に混ぜた灰。暗い地:明るい面は --accent2 を字の色に混ぜ、影の面は字の色を地に少し混ぜる。どちらの地でも明るい面が影の面より明るい
|
|
41
|
+
var FILLS = {
|
|
42
|
+
// 光っている面はテーマの --lit(光とそれが照らすもの。形式 §8.4)。テーマが持たなければ今までの色
|
|
43
|
+
light: {lit: "var(--lit, color-mix(in srgb, var(--accent2) 22%, var(--bg)))", dark: "color-mix(in srgb, var(--fg) 42%, var(--bg))", eclipse: "var(--muted)"},
|
|
44
|
+
dark: {lit: "var(--lit, color-mix(in srgb, var(--accent2) 55%, var(--fg)))", dark: "color-mix(in srgb, var(--fg) 22%, var(--bg))", eclipse: "color-mix(in srgb, var(--muted) 45%, var(--bg))"},
|
|
45
|
+
};
|
|
46
|
+
var Part = class extends base.MotionElement {
|
|
47
|
+
static partName = "orbit";
|
|
48
|
+
// 先の形は答え(どう欠けるかを予想させる):授業の表示でも先を見せない
|
|
49
|
+
static preview = "none";
|
|
50
|
+
static shape = {
|
|
51
|
+
schema: {type: "object", additionalProperties: false, properties: {
|
|
52
|
+
positions: {type: "integer"}, start: {type: "integer"}, visit: {type: "array", items: {type: "integer"}},
|
|
53
|
+
labels: {type: "array", items: {type: ["string", "null"]}}, notes: {type: "array", items: {type: ["string", "null"]}},
|
|
54
|
+
eclipse: {type: "boolean"}}},
|
|
55
|
+
example: {positions: 8, visit: [1, 2, 3, 4, 5, 6, 7, 0]},
|
|
56
|
+
};
|
|
57
|
+
static props = {
|
|
58
|
+
mode: {type: "string", default: "moon", doc: "moon(月の満ち欠け)か venus(金星の満ち欠け)"},
|
|
59
|
+
hemisphere: {type: "string", default: "north", doc: "north(北半球から見た形。満ちていく月は右が光る)か south(南半球。左右が逆)"},
|
|
60
|
+
sun: {type: "string", default: "right", doc: "月の図で太陽の光が来る側(right か left)"},
|
|
61
|
+
earth: {type: "number", default: 0.2, doc: "地球の半径(月の軌道の半径に対する比。金星の図では地球の軌道に対する比の半分)"},
|
|
62
|
+
moon: {type: "number", default: 0.5, doc: "月の半径(地球の半径に対する比。実際の月は 0.27。金星の図では金星をこの 1.4 倍に)"},
|
|
63
|
+
observer: {type: "bool", default: true, doc: "月の図で、地球の上の人と、月を見る向きを描く"},
|
|
64
|
+
size: {type: "number", default: 28, doc: "地球から見た形の名前の字の大きさ(px。24 以上)"},
|
|
65
|
+
dur: {type: "number", default: 1.2, doc: "となりの位置へ動く秒数(2 つ先なら 2 倍)"},
|
|
66
|
+
};
|
|
67
|
+
get steps(){
|
|
68
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
69
|
+
return this.plan().visit.length;
|
|
70
|
+
}
|
|
71
|
+
plan(){
|
|
72
|
+
if (this._plan) return this._plan;
|
|
73
|
+
var notes = this._notes = [], d = this.data || {}, venus = this.props.mode === "venus";
|
|
74
|
+
var N = d.positions !== undefined ? d.positions : 8;
|
|
75
|
+
if (!(N >= 4 && N <= 24)){ notes.push("[orbit] positions must be 4 to 24 (got " + N + "); using 8"); N = 8; }
|
|
76
|
+
var fix = function(i, what){
|
|
77
|
+
if (i >= 0 && i < N) return i;
|
|
78
|
+
notes.push("[orbit] " + what + " " + i + " is not a position 0 to " + (N - 1) + " (wrapped)");
|
|
79
|
+
return ((i % N) + N) % N;
|
|
80
|
+
};
|
|
81
|
+
var start = d.start !== undefined ? fix(d.start, "start") : 0;
|
|
82
|
+
var visit = d.visit ? d.visit.map(function(i){ return fix(i, "visit"); }) : null;
|
|
83
|
+
if (!visit){ visit = []; for (var i = 1; i <= N; i++) visit.push((start + i) % N); }
|
|
84
|
+
// 段階ごとの出発点・到着点と、反時計回りに進む位置の数
|
|
85
|
+
var legs = [], prev = start;
|
|
86
|
+
visit.forEach(function(v){ legs.push({from: prev, to: v, n: ((v - prev) % N + N) % N}); prev = v; });
|
|
87
|
+
return (this._plan = {N: N, venus: venus, start: start, visit: visit, legs: legs, eclipse: !venus && !!d.eclipse});
|
|
88
|
+
}
|
|
89
|
+
duration(k){
|
|
90
|
+
var l = this.plan().legs[k - 1];
|
|
91
|
+
return l ? l.n * this.props.dur : 0;
|
|
92
|
+
}
|
|
93
|
+
mount(ctx){
|
|
94
|
+
var P = this.props, D = base, self = this, pl = this.plan();
|
|
95
|
+
this._notes.forEach(function(m){ ctx.report("data", m); });
|
|
96
|
+
["mode", "hemisphere", "sun"].forEach(function(a){
|
|
97
|
+
var ok = {mode: ["moon", "venus"], hemisphere: ["north", "south"], sun: ["right", "left"]}[a];
|
|
98
|
+
if (ok.indexOf(P[a]) < 0) ctx.report("attr", "[orbit] " + a + "=\"" + P[a] + "\" is not one of " + ok.join(", ") + "; using " + ok[0]);
|
|
99
|
+
});
|
|
100
|
+
// earth・moon:正の数でなければ既定に(NaN の図にしない)
|
|
101
|
+
[["earth", 0.2, 0.5], ["moon", 0.5, 2]].forEach(function(a){
|
|
102
|
+
var v = P[a[0]];
|
|
103
|
+
if (!(typeof v === "number" && v > 0 && v <= a[2])){
|
|
104
|
+
ctx.report("attr", "[orbit] " + a[0] + "=\"" + self.getAttribute(a[0]) + "\" is not a number above 0 and up to " + a[2] + "; using " + a[1]);
|
|
105
|
+
P[a[0]] = a[1];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
this.F = isDarkBg(this) ? FILLS.dark : FILLS.light;
|
|
109
|
+
this.south = P.hemisphere === "south";
|
|
110
|
+
this.sunLeft = !pl.venus && P.sun === "left";
|
|
111
|
+
this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
112
|
+
this.labels = this.positionLabels();
|
|
113
|
+
this.noteData = (this.data && this.data.notes) || [];
|
|
114
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
|
|
115
|
+
var W = this.W = this.clientWidth, H = this.H = this.clientHeight;
|
|
116
|
+
this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, style: "display:block;overflow:visible"}, this);
|
|
117
|
+
var L = this.L = this.arrange();
|
|
118
|
+
if (!L.fits) ctx.report("size", "[orbit] the diagram does not fit its box (" + L.why + "); make the element larger");
|
|
119
|
+
this.draw(L);
|
|
120
|
+
// 読み上げ:最後の状態(最後の位置と、その名前か説明)。作者の aria-label はそのまま
|
|
121
|
+
this.setAttribute("role", "img");
|
|
122
|
+
if (!this.getAttribute("aria-label")){
|
|
123
|
+
var last = pl.visit.length ? pl.visit[pl.visit.length - 1] : pl.start, ja = this.T === TEXT.ja;
|
|
124
|
+
var what = this.labels[last] || this.caption(last, this.observerAngleAt(last));
|
|
125
|
+
this.setAttribute("aria-label", ja
|
|
126
|
+
? (pl.venus ? "金星の満ち欠け" : "月の満ち欠け") + ":位置 " + last + (what ? "、" + what : "") + (pl.venus ? "" : "(地球から見た形)")
|
|
127
|
+
: (pl.venus ? "Phases of Venus" : "Phases of the Moon") + ": position " + last + (what ? ", " + what : "") + (pl.venus ? "" : " (as seen from Earth)"));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// 位置ごとの名前:データの labels が先、なければ表(月は角度で、金星は最大離角に近い位置)
|
|
131
|
+
positionLabels(){
|
|
132
|
+
var pl = this.plan(), N = pl.N, T = this.T, given = (this.data && this.data.labels) || [], out = [];
|
|
133
|
+
for (var i = 0; i < N; i++){
|
|
134
|
+
var def = "";
|
|
135
|
+
if (!pl.venus){
|
|
136
|
+
var deg = 360 * i / N;
|
|
137
|
+
if (Math.abs(deg - Math.round(deg)) < 1e-9 && T.moon[Math.round(deg)]) def = T.moon[Math.round(deg)];
|
|
138
|
+
} else {
|
|
139
|
+
var ge = Math.round(N * (180 - Math.acos(VENUS_R) * 180 / Math.PI) / 360);
|
|
140
|
+
if (i === ge) def = T.venusEast; else if (i === N - ge) def = T.venusWest;
|
|
141
|
+
}
|
|
142
|
+
out.push(given[i] === undefined || given[i] === null ? def : given[i]);
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
// 配置:左に上から見た図(正方形に近い)、右に地球から見た形。上に 2 つの図の題
|
|
147
|
+
arrange(){
|
|
148
|
+
var W = this.W, H = this.H, P = this.props, pl = this.plan(), N = pl.N, why = [];
|
|
149
|
+
var head = 40, gap = 24, fs = Math.max(24, P.size);
|
|
150
|
+
var rightW = Math.max(300, Math.min(420, W * 0.32)), topW = W - rightW - gap, rightX = topW + gap;
|
|
151
|
+
var lab = 24, lh = 30, labelW = 0, self = this;
|
|
152
|
+
this.labels.forEach(function(s){ labelW = Math.max(labelW, est(s, lab, self)); });
|
|
153
|
+
var L = {head: head, topW: topW, rightX: rightX, rightW: rightW, fs: fs, lab: lab, why: why};
|
|
154
|
+
var areaTop = head, areaH = H - head;
|
|
155
|
+
if (!pl.venus){
|
|
156
|
+
// 太陽の光の矢印の列(太陽の側の端)。題の字の幅だけ取る
|
|
157
|
+
var col = Math.max(70, est(this.T.light, 24, self) + 8);
|
|
158
|
+
var side = this.sunLeft ? -1 : 1;
|
|
159
|
+
// 軌道の半径 R:横は(光の列を除いた幅)、縦は(高さ)に、月と名前が入る最大
|
|
160
|
+
var mr = function(R){ return R * P.earth * P.moon; };
|
|
161
|
+
// 軌道と名前の幅(blockW)の太陽の側に、16px あけて光の列を置き、全体を左の図の幅の中ほどに
|
|
162
|
+
var blockW = function(R){ return 2 * (R + mr(R) + 10 + labelW); };
|
|
163
|
+
var fitsR = function(R){
|
|
164
|
+
var hNeed = 2 * (R + mr(R) + 8 + (labelW ? lh : 0));
|
|
165
|
+
return blockW(R) + 16 + col <= topW && hNeed <= areaH;
|
|
166
|
+
};
|
|
167
|
+
var lo = 20, hi = Math.max(lo, Math.min(topW, areaH));
|
|
168
|
+
for (var it = 0; it < 40; it++){ var mid = (lo + hi) / 2; if (fitsR(mid)) lo = mid; else hi = mid; }
|
|
169
|
+
var R = lo, bw = blockW(R), x0 = Math.max(0, (topW - bw - 16 - col) / 2);
|
|
170
|
+
L.R = R; L.cy = areaTop + areaH / 2; L.er = R * P.earth; L.mr = mr(R); L.col = col; L.side = side;
|
|
171
|
+
L.cx = side > 0 ? x0 + bw / 2 : x0 + col + 16 + bw / 2;
|
|
172
|
+
L.colX = side > 0 ? x0 + bw + 16 : x0;
|
|
173
|
+
if (L.er + (P.observer ? 34 : 0) + L.mr + 6 > R) why.push("the Earth and the Moon touch; lower earth or moon");
|
|
174
|
+
if (R < 60) why.push("the orbit is " + Math.round(R) + "px");
|
|
175
|
+
} else {
|
|
176
|
+
// 金星:太陽が中心、地球の軌道 RE。地球は下、名前は右の図だけ
|
|
177
|
+
// 地球の名前を地球の下に置く分(34px)を下にあける
|
|
178
|
+
var RE = Math.max(0, Math.min(topW / 2 - 12, (areaH - 34) / 2 - 12) / (1 + P.earth * 0.5));
|
|
179
|
+
L.R = RE; L.cx = topW / 2; L.cy = areaTop + (areaH - 34) / 2; L.er = RE * P.earth * 0.5; L.mr = L.er * P.moon * 1.4; L.sr = RE * 0.14;
|
|
180
|
+
if (RE < 80) why.push("the orbit is " + Math.round(RE) + "px");
|
|
181
|
+
}
|
|
182
|
+
// 右の図:大きな円盤と、その下の名前(fs)と説明(24px)の 2 行
|
|
183
|
+
var textH = fs * 1.3 + 24 * 1.3 + 12;
|
|
184
|
+
L.dr = Math.max(10, Math.min(150, rightW / 2 - 12, (areaH - textH) / 2 - 8));
|
|
185
|
+
L.dcx = rightX + rightW / 2; L.dcy = areaTop + 8 + L.dr;
|
|
186
|
+
L.nameY = L.dcy + L.dr + 12 + fs; L.noteY = L.nameY + 10 + 24;
|
|
187
|
+
var noteW = 0;
|
|
188
|
+
this.L = L; // caption が位置の幾何を使う
|
|
189
|
+
for (var i = 0; i < N; i++) noteW = Math.max(noteW, est(this.caption(i, this.observerAngleAt(i)), 24, self), est(this.labels[i], fs, self));
|
|
190
|
+
if (noteW > rightW) why.push("a caption is " + Math.round(noteW) + "px wide, the right side " + Math.round(rightW) + "px");
|
|
191
|
+
if (L.dr < 50) why.push("the view from Earth is " + Math.round(L.dr) + "px");
|
|
192
|
+
L.fits = !why.length; L.why = why.join("; ");
|
|
193
|
+
return L;
|
|
194
|
+
}
|
|
195
|
+
// ---- 幾何(数学の向き:x は右、y は上。描くときに SVG の向きに直す)
|
|
196
|
+
// 位置 a(小数可)の天体の中心(上から見た図)と、太陽の向き(天体から太陽への単位ベクトル)
|
|
197
|
+
bodyAt(a){
|
|
198
|
+
var L = this.L, pl = this.plan(), th = TAU * a / pl.N;
|
|
199
|
+
if (!pl.venus){
|
|
200
|
+
var s = this.sunLeft ? Math.PI : 0, g = s + th;
|
|
201
|
+
return {x: L.R * Math.cos(g), y: L.R * Math.sin(g), sun: [Math.cos(s), Math.sin(s)], earth: [0, 0]};
|
|
202
|
+
}
|
|
203
|
+
// 金星:外合(地球の反対側、上)から反時計回り
|
|
204
|
+
var psi = Math.PI / 2 + th, r = L.R * VENUS_R, x = r * Math.cos(psi), y = r * Math.sin(psi), d = Math.hypot(x, y);
|
|
205
|
+
return {x: x, y: y, sun: [-x / d, -y / d], earth: [0, -L.R]};
|
|
206
|
+
}
|
|
207
|
+
// 地球から見た形:照らされた割合のもとの cos(位相角)、光っている側(+1 右、-1 左)、地球からの距離と離角
|
|
208
|
+
phaseAt(a){
|
|
209
|
+
var b = this.bodyAt(a), ex = b.earth[0], ey = b.earth[1], dx = b.x - ex, dy = b.y - ey, d = Math.hypot(dx, dy) || 1;
|
|
210
|
+
var ux = dx / d, uy = dy / d;
|
|
211
|
+
// 天体から地球への向きと、天体から太陽への向きのなす角(位相角)
|
|
212
|
+
var cosP = b.sun[0] * (-ux) + b.sun[1] * (-uy);
|
|
213
|
+
// 見る人の左(上から見て反時計回りに 90°)は東。太陽が西(右)にあれば右が光る
|
|
214
|
+
var east = b.sun[0] * (-uy) + b.sun[1] * ux;
|
|
215
|
+
var side = east < 0 ? 1 : -1;
|
|
216
|
+
if (this.south) side = -side;
|
|
217
|
+
// 地球から見た太陽の向きと天体の向きの離角(東が正)
|
|
218
|
+
var sx = -ex, sy = -ey, sd = Math.hypot(sx, sy);
|
|
219
|
+
var elong = sd ? Math.atan2(sx * uy - sy * ux, sx * ux + sy * uy) : 0;
|
|
220
|
+
if (!this.plan().venus){ elong = Math.atan2(this.bodyAt(0).sun[0] * uy - this.bodyAt(0).sun[1] * ux, this.bodyAt(0).sun[0] * ux + this.bodyAt(0).sun[1] * uy); }
|
|
221
|
+
return {cosP: Math.max(-1, Math.min(1, cosP)), side: side, d: d, elong: elong};
|
|
222
|
+
}
|
|
223
|
+
// 位置 i にいるときの地球の上の人の角度(太陽の向きから反時計回り、度)。0 は正午、90 は夕方、180 は真夜中、270 は明け方
|
|
224
|
+
observerAngleAt(i){
|
|
225
|
+
var e = 360 * i / this.plan().N;
|
|
226
|
+
if (e === 0) return 0;
|
|
227
|
+
if (e < 90) return 90;
|
|
228
|
+
if (e > 270) return 270;
|
|
229
|
+
return e;
|
|
230
|
+
}
|
|
231
|
+
caption(i, w){
|
|
232
|
+
var T = this.T, pl = this.plan();
|
|
233
|
+
var given = this.noteData && this.noteData[i];
|
|
234
|
+
if (given !== undefined && given !== null) return given;
|
|
235
|
+
var ph = this.phaseAt(i), lit = (1 + ph.cosP) / 2;
|
|
236
|
+
if (pl.venus){
|
|
237
|
+
var deg = ph.elong * 180 / Math.PI;
|
|
238
|
+
if (Math.abs(deg) < 10) return T.nearSun;
|
|
239
|
+
return deg > 0 ? T.eveningSky : T.dawnSky;
|
|
240
|
+
}
|
|
241
|
+
if (pl.eclipse){
|
|
242
|
+
var e0 = (360 * i / pl.N) % 360;
|
|
243
|
+
if (e0 === 0) return T.solarNote;
|
|
244
|
+
if (e0 === 180) return T.lunarNote;
|
|
245
|
+
}
|
|
246
|
+
var h = Math.round(((12 + w / 15) % 24 + 24) % 24);
|
|
247
|
+
// 見る向き:人の真上から月への角(東が正)。南(南半球は北)の空を基準に 45° ごと
|
|
248
|
+
var a = ((360 * i / pl.N - w) % 360 + 540) % 360 - 180, n = this.south ? "N" : "S";
|
|
249
|
+
var dir = Math.abs(a) <= 22.5 ? n : Math.abs(a) < 67.5 ? n + (a > 0 ? "E" : "W") : (a > 0 ? "E" : "W");
|
|
250
|
+
var s = T.time(h) + T.join + T.sky(T.dirs[dir]);
|
|
251
|
+
if (lit < 0.02) s = T.time(h) + T.join + T.hidden;
|
|
252
|
+
return s;
|
|
253
|
+
}
|
|
254
|
+
draw(L){
|
|
255
|
+
var D = base, svg = this.svg, pl = this.plan(), N = pl.N, self = this, T = this.T, P = this.props;
|
|
256
|
+
var X = function(x){ return L.cx + x; }, Y = function(y){ return L.cy - y; };
|
|
257
|
+
// 題
|
|
258
|
+
D.el("text", {x: 0, y: 28, "font-size": 24, fill: "var(--muted)"}, svg).textContent = T.top;
|
|
259
|
+
D.el("text", {x: L.dcx, y: 28, "font-size": 24, fill: "var(--muted)", "text-anchor": "middle"}, svg).textContent = pl.venus ? T.venusView : T.moonView;
|
|
260
|
+
var fig = D.el("g", {}, svg);
|
|
261
|
+
if (!pl.venus){
|
|
262
|
+
// 太陽の光:端の列に、地球の側へ向かう矢印
|
|
263
|
+
var side = L.side, x0 = L.colX + (side > 0 ? L.col - 4 : 4), x1 = L.colX + (side > 0 ? 4 : L.col - 4);
|
|
264
|
+
var lg = D.el("g", {}, fig);
|
|
265
|
+
for (var j = 0; j < 4; j++){
|
|
266
|
+
var yy = L.cy - L.R * 0.75 + j * L.R * 0.5;
|
|
267
|
+
D.el("line", {x1: x0, y1: yy, x2: x1 + (side > 0 ? 10 : -10), y2: yy, stroke: "var(--accent2)", "stroke-width": 3}, lg);
|
|
268
|
+
D.el("path", {d: "M" + x1 + "," + yy + "l" + (side > 0 ? 14 : -14) + ",-7v14z", fill: "var(--accent2)"}, lg);
|
|
269
|
+
}
|
|
270
|
+
D.el("text", {x: side > 0 ? L.colX + L.col : L.colX, y: L.cy - L.R * 0.75 - 18, "font-size": 24, fill: "var(--fg)", "text-anchor": side > 0 ? "end" : "start"}, lg).textContent = T.light;
|
|
271
|
+
// 軌道
|
|
272
|
+
D.el("circle", {cx: X(0), cy: Y(0), r: L.R, fill: "none", stroke: "var(--muted)", "stroke-width": 2, "stroke-dasharray": "6 6"}, fig);
|
|
273
|
+
} else {
|
|
274
|
+
D.el("circle", {cx: X(0), cy: Y(0), r: L.R, fill: "none", stroke: "var(--muted)", "stroke-width": 2, "stroke-dasharray": "6 6"}, fig);
|
|
275
|
+
D.el("circle", {cx: X(0), cy: Y(0), r: L.R * VENUS_R, fill: "none", stroke: "var(--muted)", "stroke-width": 2, "stroke-dasharray": "6 6"}, fig);
|
|
276
|
+
D.el("circle", {cx: X(0), cy: Y(0), r: L.sr, fill: "var(--lit, var(--accent2))", stroke: "var(--muted)", "stroke-width": 1.5}, fig);
|
|
277
|
+
}
|
|
278
|
+
// 影(食)。render が濃さを決める
|
|
279
|
+
this.shadow = D.el("path", {d: "", fill: "var(--fg)", opacity: 0}, fig);
|
|
280
|
+
// 位置の印:薄い天体(光っている半分は太陽の側)
|
|
281
|
+
this.ghosts = [];
|
|
282
|
+
for (var i = 0; i < N; i++){
|
|
283
|
+
var b = this.bodyAt(i), g = D.el("g", {opacity: 0.35}, fig);
|
|
284
|
+
body(g, X(b.x), Y(b.y), L.mr, b.sun, null, this.F);
|
|
285
|
+
this.ghosts.push(g);
|
|
286
|
+
}
|
|
287
|
+
// 地球
|
|
288
|
+
var eb = pl.venus ? {x: 0, y: -L.R} : {x: 0, y: 0}, esun = pl.venus ? [0, 1] : this.bodyAt(0).sun;
|
|
289
|
+
body(D.el("g", {}, fig), X(eb.x), Y(eb.y), L.er, esun, "var(--term)", this.F);
|
|
290
|
+
if (pl.venus) D.el("text", {x: X(eb.x), y: Y(eb.y) + L.er + 28, "font-size": 24, fill: "var(--fg)", "text-anchor": "middle"}, fig).textContent = T.earth;
|
|
291
|
+
// 見る線(地球の上の人、または地球から天体へ)と人
|
|
292
|
+
this.sight = D.el("path", {d: "", fill: "none", stroke: "var(--fg)", "stroke-width": 2, "stroke-dasharray": "4 5"}, fig);
|
|
293
|
+
this.person = D.el("g", {}, fig);
|
|
294
|
+
if (!pl.venus && P.observer){
|
|
295
|
+
// 地球の表面に立つ人(上が外向き)。render が回す
|
|
296
|
+
D.el("line", {x1: 0, y1: 0, x2: 0, y2: -16, stroke: "var(--fg)", "stroke-width": 3}, this.person);
|
|
297
|
+
D.el("line", {x1: -7, y1: -10, x2: 7, y2: -10, stroke: "var(--fg)", "stroke-width": 3}, this.person);
|
|
298
|
+
D.el("circle", {cx: 0, cy: -22, r: 6, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 3}, this.person);
|
|
299
|
+
}
|
|
300
|
+
// 今の天体
|
|
301
|
+
this.cur = D.el("g", {}, fig);
|
|
302
|
+
// 上から見た図の位置の名前(月だけ):軌道の外、天体の外側に
|
|
303
|
+
this.posLabels = [];
|
|
304
|
+
if (!pl.venus){
|
|
305
|
+
for (i = 0; i < N; i++){
|
|
306
|
+
if (!this.labels[i]) { this.posLabels.push(null); continue; }
|
|
307
|
+
var th = (this.sunLeft ? Math.PI : 0) + TAU * i / N, c = Math.cos(th), s = Math.sin(th), rr = L.R + L.mr + 10;
|
|
308
|
+
var anchor = c > 0.3 ? "start" : c < -0.3 ? "end" : "middle";
|
|
309
|
+
var ty = Y(rr * s) + (s > 0.3 ? -6 : s < -0.3 ? 24 : 8) + (anchor === "middle" ? 0 : 0);
|
|
310
|
+
var tx = X(rr * c);
|
|
311
|
+
var t = D.el("text", {x: tx.toFixed(1), y: ty.toFixed(1), "font-size": L.lab, fill: "var(--fg)", "text-anchor": anchor, opacity: 0}, fig);
|
|
312
|
+
t.textContent = this.labels[i];
|
|
313
|
+
this.posLabels.push(t);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// 右:地球から見た形
|
|
317
|
+
var view = D.el("g", {}, svg);
|
|
318
|
+
this.vSun = D.el("circle", {cx: L.dcx, cy: L.dcy, r: L.dr, fill: "var(--lit, var(--accent2))", stroke: "var(--muted)", "stroke-width": 1.5, opacity: 0}, view);
|
|
319
|
+
this.vDark = D.el("circle", {cx: L.dcx, cy: L.dcy, r: L.dr, fill: this.F.dark}, view);
|
|
320
|
+
this.vLit = D.el("path", {d: "", fill: this.F.lit}, view);
|
|
321
|
+
this.vRim = D.el("circle", {cx: L.dcx, cy: L.dcy, r: L.dr, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, view);
|
|
322
|
+
this.vName = D.el("text", {x: L.dcx, y: L.nameY, "font-size": L.fs, "font-weight": 700, fill: "var(--fg)", "text-anchor": "middle"}, view);
|
|
323
|
+
this.vNote = D.el("text", {x: L.dcx, y: L.noteY, "font-size": 24, fill: "var(--muted)", "text-anchor": "middle"}, view);
|
|
324
|
+
}
|
|
325
|
+
render(k, t, ctx){
|
|
326
|
+
var pl = this.plan(), L = this.L, N = pl.N, self = this, D = base;
|
|
327
|
+
if (!L) return;
|
|
328
|
+
var X = function(x){ return L.cx + x; }, Y = function(y){ return L.cy - y; };
|
|
329
|
+
var leg = k >= 1 ? pl.legs[Math.min(k, pl.legs.length) - 1] : null;
|
|
330
|
+
var from = leg ? leg.from : pl.start, to = leg ? leg.to : pl.start, n = leg ? leg.n : 0;
|
|
331
|
+
var dur = n * this.props.dur, e = k > pl.legs.length || !leg || !n ? 1 : D.prog(t, 0, dur);
|
|
332
|
+
var a = from + n * e; // 位置(小数)
|
|
333
|
+
// 天体
|
|
334
|
+
var b = this.bodyAt(a), ph = this.phaseAt(a);
|
|
335
|
+
while (this.cur.firstChild) this.cur.removeChild(this.cur.firstChild);
|
|
336
|
+
body(this.cur, X(b.x), Y(b.y), L.mr, b.sun, null, this.F);
|
|
337
|
+
// 地球の上の人と見る線
|
|
338
|
+
if (!pl.venus){
|
|
339
|
+
var w0 = this.observerAngleAt(from), w1 = this.observerAngleAt(to);
|
|
340
|
+
// 位置 0(新月)を通る段階だけ一回り足す。同じ向きの位置どうし(夕方に寄せた 1→2 など)は回さない
|
|
341
|
+
if (n && from + n >= N) w1 += 360;
|
|
342
|
+
var w = n ? D.lerp(w0, w1, e) : w1;
|
|
343
|
+
var wr = (this.sunLeft ? 180 : 0) + w, wrad = wr * Math.PI / 180;
|
|
344
|
+
var ox = (L.er + 22) * Math.cos(wrad), oy = (L.er + 22) * Math.sin(wrad);
|
|
345
|
+
if (this.props.observer){
|
|
346
|
+
setIf(this.person, "transform", "translate(" + X(L.er * Math.cos(wrad)).toFixed(2) + " " + Y(L.er * Math.sin(wrad)).toFixed(2) + ") rotate(" + (90 - wr).toFixed(2) + ")");
|
|
347
|
+
sightLine(this.sight, X(ox), Y(oy), X(b.x), Y(b.y), L.mr + 4);
|
|
348
|
+
} else setIf(this.sight, "d", "");
|
|
349
|
+
} else sightLine(this.sight, X(0), Y(-L.R + L.er + 4), X(b.x), Y(b.y), L.mr + 4);
|
|
350
|
+
// 位置の名前(上から見た図):着いた位置から出る
|
|
351
|
+
var seen = {};
|
|
352
|
+
seen[pl.start] = 1;
|
|
353
|
+
for (var s = 1; s < k && s <= pl.legs.length; s++) seen[pl.legs[s - 1].to] = 1;
|
|
354
|
+
this.posLabels.forEach(function(el, i){
|
|
355
|
+
if (!el) return;
|
|
356
|
+
var op = seen[i] ? 1 : i === to && leg && k <= pl.legs.length ? D.prog(t, Math.max(0, dur - 0.3), 0.3) : 0;
|
|
357
|
+
if (i === to && k > pl.legs.length) op = 1;
|
|
358
|
+
setIf(el, "opacity", (+op).toFixed(3));
|
|
359
|
+
});
|
|
360
|
+
// 右の図
|
|
361
|
+
var R = L.dr, scale = 1;
|
|
362
|
+
if (pl.venus){
|
|
363
|
+
// 大きさは距離に反比例。いちばん近い位置を R にする
|
|
364
|
+
var dmin = Infinity;
|
|
365
|
+
for (var i = 0; i < N; i++) dmin = Math.min(dmin, this.phaseAt(i).d);
|
|
366
|
+
var near = Math.max(dmin, L.R * (1 - VENUS_R) * 1.4);
|
|
367
|
+
scale = Math.min(1, near / ph.d);
|
|
368
|
+
}
|
|
369
|
+
var r = R * scale;
|
|
370
|
+
setIf(this.vDark, "r", r.toFixed(2));
|
|
371
|
+
setIf(this.vRim, "r", r.toFixed(2));
|
|
372
|
+
setIf(this.vLit, "d", litPath(L.dcx, L.dcy, r, ph.cosP, ph.side));
|
|
373
|
+
// 食:そろった位置のまわり 12° で濃くなる
|
|
374
|
+
var deg = ((360 * a / N) % 360 + 360) % 360, solar = 0, lunar = 0;
|
|
375
|
+
if (pl.eclipse){
|
|
376
|
+
solar = Math.max(0, 1 - Math.min(deg, 360 - deg) / 12);
|
|
377
|
+
lunar = Math.max(0, 1 - Math.abs(deg - 180) / 12);
|
|
378
|
+
}
|
|
379
|
+
setIf(this.vSun, "opacity", solar.toFixed(3));
|
|
380
|
+
setIf(this.vSun, "r", (r * 1.1).toFixed(2)); // 日食:月のまわりに太陽の縁が少し出る
|
|
381
|
+
// 月食:影に入った月は暗く(明るい地では --muted)
|
|
382
|
+
setIf(this.vDark, "style", "fill:" + (lunar > 0.5 ? this.F.eclipse : this.F.dark) + ";"); // base.el と同じ書き方
|
|
383
|
+
if (lunar > 0) setIf(this.vLit, "opacity", (1 - lunar).toFixed(3)); else setIf(this.vLit, "opacity", "1");
|
|
384
|
+
// 影の形:日食は月から地球へ、月食は地球から月の先へ
|
|
385
|
+
var sd = "";
|
|
386
|
+
if (solar > 0 || lunar > 0){
|
|
387
|
+
var sun = this.bodyAt(0).sun, px = -sun[1], py = sun[0];
|
|
388
|
+
if (solar > 0){
|
|
389
|
+
sd = poly([[b.x + px * L.mr, b.y + py * L.mr], [b.x - px * L.mr, b.y - py * L.mr], [-sun[0] * L.er * 0.2 - px * 2, -sun[1] * L.er * 0.2 - py * 2], [-sun[0] * L.er * 0.2 + px * 2, -sun[1] * L.er * 0.2 + py * 2]], X, Y);
|
|
390
|
+
} else {
|
|
391
|
+
var far = L.R + L.mr * 2.5;
|
|
392
|
+
sd = poly([[px * L.er, py * L.er], [-px * L.er, -py * L.er], [-sun[0] * far - px * L.er * 0.7, -sun[1] * far - py * L.er * 0.7], [-sun[0] * far + px * L.er * 0.7, -sun[1] * far + py * L.er * 0.7]], X, Y);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
setIf(this.shadow, "d", sd);
|
|
396
|
+
setIf(this.shadow, "opacity", (0.22 * Math.max(solar, lunar)).toFixed(3));
|
|
397
|
+
// 名前と説明:前半は出発点のものが消え、後半に到着点のものが出る
|
|
398
|
+
var useTo = !n || e >= 0.5 || k > pl.legs.length;
|
|
399
|
+
var idx = useTo ? to : from, op = !n || k > pl.legs.length ? 1 : useTo ? D.prog(t, dur * 0.75, dur * 0.25) : 1 - D.prog(t, 0, dur * 0.25);
|
|
400
|
+
var name = this.labels[idx] || "";
|
|
401
|
+
if (pl.eclipse && useTo){
|
|
402
|
+
var dg = (360 * idx / N) % 360;
|
|
403
|
+
if (dg === 0) name = (name ? name + "(" : "") + this.T.solar + (name ? ")" : "");
|
|
404
|
+
if (dg === 180) name = (name ? name + "(" : "") + this.T.lunar + (name ? ")" : "");
|
|
405
|
+
}
|
|
406
|
+
if (this.T === TEXT.en) name = name.replace("(", " (").replace(")", ")");
|
|
407
|
+
setText(this.vName, name);
|
|
408
|
+
setText(this.vNote, this.caption(idx, this.observerAngleAt(idx)));
|
|
409
|
+
setIf(this.vName, "opacity", op.toFixed(3));
|
|
410
|
+
setIf(this.vNote, "opacity", op.toFixed(3));
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// ---- 下の関数は m-orbit の中だけで使う
|
|
415
|
+
function setIf(el, a, v){ v = String(v); if (el.getAttribute(a) !== v) el.setAttribute(a, v); }
|
|
416
|
+
function setText(el, s){ if (el.textContent !== s) el.textContent = s; }
|
|
417
|
+
// 字の幅(px):base の textWidth(font の要素の字で測った幅)
|
|
418
|
+
function est(s, fs, font){ return base.textWidth(s || "", fs, {font: font}); }
|
|
419
|
+
// 地が字の色より暗いか(テーマの変数を読む。読めなければ明るい地)
|
|
420
|
+
function isDarkBg(el){
|
|
421
|
+
var cs = getComputedStyle(el), bg = rgbOf(cs.getPropertyValue("--bg").trim()), fg = rgbOf(cs.getPropertyValue("--fg").trim());
|
|
422
|
+
return !!(bg && fg) && luma(bg) < luma(fg);
|
|
423
|
+
}
|
|
424
|
+
// 色を sRGB で読む(m-map-world と同じ:キャンバスに 1 点塗って読む。読めなければ null)
|
|
425
|
+
function rgbOf(css){
|
|
426
|
+
try {
|
|
427
|
+
if (!css) return null;
|
|
428
|
+
var cv = document.createElement("canvas"); cv.width = cv.height = 1;
|
|
429
|
+
var g = cv.getContext("2d", {willReadFrequently: true});
|
|
430
|
+
if (!g) return null;
|
|
431
|
+
g.fillStyle = "#010203"; g.fillStyle = css;
|
|
432
|
+
if (/^#010203$/i.test(g.fillStyle) && !/^#010203$/i.test(css)) return null;
|
|
433
|
+
g.fillRect(0, 0, 1, 1);
|
|
434
|
+
var d = g.getImageData(0, 0, 1, 1).data;
|
|
435
|
+
return [d[0], d[1], d[2]];
|
|
436
|
+
} catch (e) { return null; }
|
|
437
|
+
}
|
|
438
|
+
function luma(c){ return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]; }
|
|
439
|
+
// 上から見た天体:暗い円盤と、太陽の側の明るい半分
|
|
440
|
+
function body(g, cx, cy, r, sun, litFill, F){
|
|
441
|
+
base.el("circle", {cx: cx.toFixed(2), cy: cy.toFixed(2), r: r.toFixed(2), fill: F.dark}, g);
|
|
442
|
+
var a = Math.atan2(-sun[1], sun[0]), p = [];
|
|
443
|
+
for (var i = 0; i <= 24; i++){ var u = a - Math.PI / 2 + Math.PI * i / 24; p.push([cx + r * Math.cos(u), cy + r * Math.sin(u)]); }
|
|
444
|
+
base.el("path", {d: "M" + p.map(function(q){ return q[0].toFixed(2) + "," + q[1].toFixed(2); }).join("L") + "Z", fill: litFill || F.lit}, g);
|
|
445
|
+
base.el("circle", {cx: cx.toFixed(2), cy: cy.toFixed(2), r: r.toFixed(2), fill: "none", stroke: "var(--muted)", "stroke-width": 1.5}, g);
|
|
446
|
+
}
|
|
447
|
+
// 地球から見た明るい部分:光っている側の縁(半円)と、明暗の境(横の半径が r·|cos 位相角| の半楕円)
|
|
448
|
+
function litPath(cx, cy, r, cosP, side){
|
|
449
|
+
if ((1 + cosP) / 2 < 1e-4) return "";
|
|
450
|
+
var pts = [], M = 48, i, u;
|
|
451
|
+
for (i = 0; i <= M; i++){ u = -Math.PI / 2 + Math.PI * i / M; pts.push([cx + side * r * Math.cos(u), cy + r * Math.sin(u)]); }
|
|
452
|
+
for (i = M; i >= 0; i--){ u = -Math.PI / 2 + Math.PI * i / M; pts.push([cx - side * cosP * r * Math.cos(u), cy + r * Math.sin(u)]); }
|
|
453
|
+
return "M" + pts.map(function(q){ return q[0].toFixed(2) + "," + q[1].toFixed(2); }).join("L") + "Z";
|
|
454
|
+
}
|
|
455
|
+
function poly(pts, X, Y){ return "M" + pts.map(function(q){ return X(q[0]).toFixed(2) + "," + Y(q[1]).toFixed(2); }).join("L") + "Z"; }
|
|
456
|
+
// 見る線:出発点から天体の縁の手前まで、先に小さな矢じり
|
|
457
|
+
function sightLine(el, x0, y0, x1, y1, stop){
|
|
458
|
+
var dx = x1 - x0, dy = y1 - y0, d = Math.hypot(dx, dy);
|
|
459
|
+
if (d <= stop + 4){ setIf(el, "d", ""); return; }
|
|
460
|
+
var ux = dx / d, uy = dy / d, ex = x1 - ux * stop, ey = y1 - uy * stop, px = -uy, py = ux;
|
|
461
|
+
setIf(el, "d", "M" + x0.toFixed(2) + "," + y0.toFixed(2) + "L" + ex.toFixed(2) + "," + ey.toFixed(2) +
|
|
462
|
+
"M" + (ex - ux * 9 + px * 5).toFixed(2) + "," + (ey - uy * 9 + py * 5).toFixed(2) + "L" + ex.toFixed(2) + "," + ey.toFixed(2) + "L" + (ex - ux * 9 - px * 5).toFixed(2) + "," + (ey - uy * 9 - py * 5).toFixed(2));
|
|
463
|
+
}
|
|
464
|
+
return Part;
|
|
465
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Hierarchy tree (org chart, taxonomy), built level by level from the root; auto layout
|
|
3
|
+
steps: depth (by="level") or node count (by="node"); or the largest step
|
|
4
|
+
props:
|
|
5
|
+
orient: down (default) or right
|
|
6
|
+
by: level (default) or node (depth-first)
|
|
7
|
+
link: elbow (default) or straight
|
|
8
|
+
size: box text px (0 = 27, shrink to 24)
|
|
9
|
+
fade: box appear (s)
|
|
10
|
+
draw: line draw (s)
|
|
11
|
+
example: {"nodes": [{"id": "r", "label": "Animals"}, {"id": "a", "label": "Vertebrates", "parent": "r"}, {"id": "b", "label": "Invertebrates", "parent": "r"}]}
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Parent–child structures (org charts, taxonomies, outlines). No coordinates; laid out without overlaps.
|
|
15
|
+
|
|
16
|
+
Child JSON: `{"nodes": [...], "edges": [...]}` (`edges` optional).
|
|
17
|
+
|
|
18
|
+
- node: `id`, `label` (`\n`) or `tex` (KaTeX), `parent` (parent `id`; exactly one root without `parent`), `note` (small, **under** box), `tone` (`term` default, `emph`, `muted`, `accent2`, `series-1..4`), `step`, `at` (start s)
|
|
19
|
+
- Children in array order; parent centred over them
|
|
20
|
+
- edge: extra links (`from` `to` `label` `tone` `dash` `step`), dashed arrow outside the tree; best at same depth; step: later end
|
|
21
|
+
- Child `branch`: line text (e.g. probability). `path`: root-first `id`s highlighted in turn (default 1 step per line, after the tree; `pathStep`: in one step; `pathNote`: end note)
|
|
22
|
+
- `orient="right"` for wide taxonomies. `by="node"`: one at a time, depth-first (to follow a branch). Node `step` wins
|
|
23
|
+
- Lines `--muted`, 3 px; `tone: emph` box: `--emph-tint` fill
|
|
24
|
+
- Fit (~440 px high): ~8 four-character boxes per level (`down`), ~7 (`right`); ~5 levels. More leaves: 2 staggered rows (~16 / ~11), then 2-line names. Text ≥ 24 px; overflow spills, reported. Too many: split
|
|
25
|
+
- `variant`: `fade` (default), `draw` (lines first), `grow`
|
|
26
|
+
- Show later steps faintly (`ctx.preview`): later parts faint
|
|
27
|
+
|
|
28
|
+
The demo is `demo.html` (company and values fictional).
|
|
29
|
+
|
|
30
|
+
<!-- llm: omit -->
|
|
31
|
+
Notes
|
|
32
|
+
|
|
33
|
+
- Moves ≤ 12 px within `fade` time. Edge step default: later end; edges bulge outward (`down` below, `right` right)
|
|
34
|
+
- Layout: subtrees placed bottom-up and pushed together until level contours touch (Reingold–Tilford); small subtrees in between go left
|
|
35
|
+
- Text 27 → 24 px (`size` fixes it). Width estimated from characters (CJK 1, others 0.6)
|
|
36
|
+
- At 24 px, no smaller text (conventions §2.3); tries: stagger children of parents with ≥ 3 leaf children (not with `straight`) → wrap names (≥ 4 chars, no `\n` or `*_^`; at the middle space, or after a mid hiragana; single Latin words never). Else least-overflow layout; shortfall via `ctx.report("size", …)`
|
|
37
|
+
- Motion: `fade` from below; `draw`, `grow` from the parent's direction, 12 px (root always as `fade`). `grow` from 0.92×
|
|
38
|
+
- `branch`: 24 px, `--fg`. `elbow` bends 20 px from the parent, text on the child line; levels widen to fit (`right` +52 px, `down` ≥ 76 px); no staggering. `straight`: outside the line's middle (crowded at ≥ 3 children)
|
|
39
|
+
- `path`: must start at the root, each pair parent–child, else a data card. Default: one step per line after the tree's last step. `pathStep`: drawn in that step (`draw` s each). `--emph` 6 px over the line, `--emph` 4 px frame on reached boxes, `branch` in `--emph`. `pathNote` beyond the end box after the last line; may overlap if the end box is not at the deepest level
|
|
40
|
+
- Show later steps faintly: later path faint; `branch` colour changes only at its step
|
|
41
|
+
- Edges take room outside the tree (`down`: 56 px below, +36 with a label); across depths they may cross boxes
|
|
42
|
+
<!-- llm: end -->
|