@cardenelabs/dragon 0.42.2 → 0.44.0
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.md +34 -1
- package/dist/cli.cjs +4630 -1690
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4630 -1690
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +4267 -1555
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/export.js +4267 -1555
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +4348 -1381
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -3
- package/dist/index.d.ts +118 -3
- package/dist/index.js +4348 -1381
- package/dist/index.js.map +1 -1
- package/dist/{ink-B8EZL7JV.d.cts → ink-DeDtzaTL.d.cts} +47 -3
- package/dist/{ink-B8EZL7JV.d.ts → ink-DeDtzaTL.d.ts} +47 -3
- package/dist/node.cjs +3504 -1625
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +3504 -1625
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +3 -2
- package/package.json +1 -1
- package/src/field-messages.ts +6 -0
- package/src/index.ts +8 -1
- package/src/layout/lineup.ts +219 -0
- package/src/layout/tree.ts +458 -0
- package/src/look/values.ts +73 -2
- package/src/messages.ts +88 -2
- package/src/parser.ts +212 -2
- package/src/printer.ts +36 -2
- package/src/render/icons.ts +2 -0
- package/src/render/lineup.ts +184 -0
- package/src/render/parts.ts +16 -7
- package/src/render/svg.ts +72 -6
- package/src/render/tree.ts +165 -0
- package/src/schema.ts +76 -4
- package/src/schemas/diagram.schema.json +207 -19
- package/src/schemas/validate-diagram.js +1 -1
- package/src/timeline.ts +16 -2
- package/src/words.ts +25 -2
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 列の図 (#3239) を描く部品。見た目の元は step 2 で本人が選んだ見本の「列の図」。
|
|
3
|
+
*
|
|
4
|
+
* 列の地と字は下の層に、チップと封と札は上の層に描く。チップが別の列へ滑る時に、途中の列の地の下へ隠れないため。
|
|
5
|
+
* チップは席に居る間ごとに 1 つの部品で、座った時に滑り始める所から席へ滑るか、弾んで現れる。席を離れる時は、同じ段で別の席へ滑るなら滑り始める時に一瞬で替わり、
|
|
6
|
+
* 別の席へ滑らないなら消えていく。
|
|
7
|
+
* 封は列の左から右へ伸び、覆い終えた時に列のチップを隠す。開ける時はチップを出してから封を消す。
|
|
8
|
+
* 列を選ぶと選んだ列の縁に色が付き、ほかの列を薄くする。薄くした列は、後の段で並びを書き換えるか選ぶと濃く戻る。
|
|
9
|
+
*/
|
|
10
|
+
import type { LineupAt, LineupLayout, LineupPick, LineupSeal, LineupSeat } from "../layout/lineup";
|
|
11
|
+
import { EASE, LOOK, MOTION, TYPE } from "../look/values";
|
|
12
|
+
import type { Diagram } from "../schema";
|
|
13
|
+
import type { Timeline } from "../timeline";
|
|
14
|
+
import { ALWAYS, type Shown } from "./ink";
|
|
15
|
+
import type { Frame } from "./motion";
|
|
16
|
+
import { type Ctx, cs, esc, type SubChange, subLines, write } from "./parts";
|
|
17
|
+
|
|
18
|
+
const r1 = (v: number): number => Math.round(v * 100) / 100;
|
|
19
|
+
|
|
20
|
+
/** 席から `(dx, dy)` ずらして大きさを `scale` 倍にした時の `transform` */
|
|
21
|
+
const place = (dx: number, dy: number, scale = 1): string => `translate(${r1(dx)}px,${r1(dy)}px) scale(${scale})`;
|
|
22
|
+
|
|
23
|
+
/** `span` から `holes` の間を抜いた間 */
|
|
24
|
+
const without = (span: Shown, holes: Shown[]): Shown[] =>
|
|
25
|
+
holes.reduce<Shown[]>((rest, [x, y]) => rest.flatMap(([a, b]): Shown[] => (y <= a || x >= b ? [[a, b]] : [...(a < x ? ([[a, x]] as Shown[]) : []), ...(y < b ? ([[y, b]] as Shown[]) : [])])), [span]);
|
|
26
|
+
|
|
27
|
+
export function drawLineup(layout: LineupLayout, diagram: Diagram, timeline: Timeline, ctx: Ctx, subs: Map<string, SubChange[]>): { lanes: string; chips: string } {
|
|
28
|
+
const { m } = ctx;
|
|
29
|
+
const N = LOOK.lineup;
|
|
30
|
+
const cut = MOTION.lineup.cut;
|
|
31
|
+
const timeOf = (at: LineupAt): { start: number; drawn: number } => timeline.edges.find((t) => t.step === at.step && t.event === at.event) ?? { start: 0, drawn: 0 };
|
|
32
|
+
const items = new Map((diagram.lineup?.items ?? []).map((item) => [item.id, item]));
|
|
33
|
+
|
|
34
|
+
// 列ごとの、薄くなるか濃く戻る時刻。列を選ぶ時に薄くし、並びを書き換えるか選ぶ時に濃く戻す
|
|
35
|
+
const turns = new Map<string, [number, boolean][]>(layout.lanes.map((lane) => [lane.id, []]));
|
|
36
|
+
const faint = new Set<string>();
|
|
37
|
+
const turn = (id: string, at: number, to: boolean): void => {
|
|
38
|
+
if (faint.has(id) === to) return;
|
|
39
|
+
if (to) faint.add(id);
|
|
40
|
+
else faint.delete(id);
|
|
41
|
+
turns.get(id)?.push([at, to]);
|
|
42
|
+
};
|
|
43
|
+
for (const time of [...timeline.edges].sort((a, b) => a.start - b.start)) {
|
|
44
|
+
const e = diagram.steps[time.step]?.events[time.event];
|
|
45
|
+
if (e?.type === "line") turn(e.box, time.start, false);
|
|
46
|
+
if (e?.type === "pick") for (const lane of layout.lanes) turn(lane.id, time.start, lane.id !== e.box);
|
|
47
|
+
}
|
|
48
|
+
/** 列の濃さの動き。薄くならない列は `undefined` */
|
|
49
|
+
const fadeOf = (id: string): string | undefined => {
|
|
50
|
+
const list = turns.get(id) ?? [];
|
|
51
|
+
if (list.length === 0) return undefined;
|
|
52
|
+
const frames: Frame[] = [[0, { opacity: 1 }]];
|
|
53
|
+
let now: number = 1;
|
|
54
|
+
for (const [t, to] of list) {
|
|
55
|
+
const next = to ? N.faint : 1;
|
|
56
|
+
frames.push([t, { opacity: now }, EASE.inOut], [t + MOTION.fade, { opacity: next }]);
|
|
57
|
+
now = next;
|
|
58
|
+
}
|
|
59
|
+
frames.push([m.last, { opacity: now }, EASE.inOut], [m.total, { opacity: 1 }]);
|
|
60
|
+
return m.kf(frames);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** 封が列を隠す間。覆い終えてから開けるまで */
|
|
64
|
+
const closedOf = (seal: LineupSeal): Shown => [timeOf(seal).drawn, seal.until ? timeOf(seal.until).start : Number.POSITIVE_INFINITY];
|
|
65
|
+
|
|
66
|
+
/** 列のチップを隠す動き。封の無い列は `undefined` */
|
|
67
|
+
const hideOf = (seals: LineupSeal[]): string | undefined => {
|
|
68
|
+
if (seals.length === 0) return undefined;
|
|
69
|
+
const frames: Frame[] = [[0, { opacity: 1 }]];
|
|
70
|
+
for (const seal of seals) {
|
|
71
|
+
const [a, b] = closedOf(seal);
|
|
72
|
+
frames.push([a, { opacity: 1 }], [a + cut, { opacity: 0 }]);
|
|
73
|
+
if (seal.until) frames.push([b, { opacity: 0 }], [b + cut, { opacity: 1 }]);
|
|
74
|
+
}
|
|
75
|
+
frames.push([m.total - cut, { opacity: seals.at(-1)?.until ? 1 : 0 }], [m.total, { opacity: 1 }]);
|
|
76
|
+
return m.kf(frames);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const sealKf = (seal: LineupSeal): string => {
|
|
80
|
+
const { start, drawn } = timeOf(seal);
|
|
81
|
+
const none = { opacity: 0, transform: "scaleX(0)" };
|
|
82
|
+
const end: Frame[] = seal.until
|
|
83
|
+
? [
|
|
84
|
+
[timeOf(seal.until).start, { opacity: 1 }, EASE.inOut],
|
|
85
|
+
[timeOf(seal.until).start + MOTION.fade, { opacity: 0 }],
|
|
86
|
+
[m.total, { opacity: 0 }],
|
|
87
|
+
]
|
|
88
|
+
: [
|
|
89
|
+
[m.last, { opacity: 1 }, EASE.inOut],
|
|
90
|
+
[m.total, { opacity: 0 }],
|
|
91
|
+
];
|
|
92
|
+
return m.kf([[0, none], [start - cut, none], [start, { opacity: 1, transform: "scaleX(0)" }, EASE.inOut], [drawn, { transform: "scaleX(1)" }], ...end]);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** 席を離れた同じ出来事で、別の席へ滑るチップか */
|
|
96
|
+
/**
|
|
97
|
+
* チップが席を離れる時刻と、別の席へ滑って離れるか。席を離れる段の中で、この席から滑り始めるチップが在れば、滑り始める時に一瞬で替わる。
|
|
98
|
+
* 列の並びを書き換える出来事と、別の列へ滑る出来事の順は問わない。どちらが先でも、同じチップが 2 枚見える間と、1 枚も見えない間を作らない
|
|
99
|
+
*/
|
|
100
|
+
const leaving = (c: LineupSeat): { at: number; moved: boolean } | undefined => {
|
|
101
|
+
if (!c.until) return undefined;
|
|
102
|
+
const until = c.until;
|
|
103
|
+
const next = layout.chips.find((n) => n !== c && n.id === c.id && n.step === until.step && n.from?.[0] === c.x && n.from?.[1] === c.y);
|
|
104
|
+
return next ? { at: timeOf(next).start, moved: true } : { at: timeOf(until).start, moved: false };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const chipKf = (c: LineupSeat): string => {
|
|
108
|
+
const a = timeOf(c).start;
|
|
109
|
+
const rest = place(0, 0);
|
|
110
|
+
const frames: Frame[] = [];
|
|
111
|
+
if (c.from) {
|
|
112
|
+
const off = place(c.from[0] - c.x, c.from[1] - c.y);
|
|
113
|
+
frames.push([0, { opacity: 0, transform: off }], [a - cut, { opacity: 0, transform: off }], [a, { opacity: 1, transform: off }, EASE.inOut], [a + MOTION.lineup.slide, { transform: rest }]);
|
|
114
|
+
} else {
|
|
115
|
+
const off = place(0, 0, LOOK.popFrom);
|
|
116
|
+
frames.push([0, { opacity: 0, transform: off }], [a, { opacity: 0, transform: off }, EASE.pop], [a + MOTION.popFade, { opacity: 1, transform: rest }]);
|
|
117
|
+
}
|
|
118
|
+
const leaves = leaving(c);
|
|
119
|
+
if (leaves) {
|
|
120
|
+
frames.push([leaves.at, { opacity: 1 }, EASE.inOut], [leaves.at + (leaves.moved ? cut : MOTION.fade), { opacity: 0 }], [m.total, { opacity: 0 }]);
|
|
121
|
+
} else {
|
|
122
|
+
frames.push([m.last, { opacity: 1 }, EASE.inOut], [m.total, { opacity: 0 }]);
|
|
123
|
+
}
|
|
124
|
+
return m.kf(frames);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const chip = (c: LineupSeat, closed: Shown[]): string => {
|
|
128
|
+
const item = items.get(c.id);
|
|
129
|
+
const color = item?.color;
|
|
130
|
+
const rect = `<rect class="${color ? "dg-ln-chip" : "dg-ln-plain"}" x="${r1(c.x)}" y="${r1(c.y)}" width="${r1(c.w)}" height="${c.h}" rx="${N.chip.radius}"/>`;
|
|
131
|
+
const shown = without([timeOf(c).start + MOTION.lineup.slide, leaving(c)?.at ?? Number.POSITIVE_INFINITY], closed);
|
|
132
|
+
const text = item?.label === undefined ? "" : write(ctx.ink, color ? "dg-ln-t" : "dg-ln-tp", c.x + c.w / 2, c.y + c.h / 2 + LOOK.baseline.tag, item.label, TYPE.chip, shown, "middle");
|
|
133
|
+
return `<g class="dg-popc dg-a" data-lineup-chip="${esc(c.id)}" data-lineup-on="${esc(c.lane)}" data-lineup-seat="${c.index}" style="${color ? `${cs(color)};` : ""}${chipKf(c)}">${rect}${text}</g>`;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** 選んだ列の縁の色が見える間。次に別の列を選ぶまで */
|
|
137
|
+
const ring = (pick: LineupPick, next: LineupPick | undefined, frame: string): string =>
|
|
138
|
+
`<g class="dg-a" data-lineup-ring="${esc(pick.lane)}" style="${m.vis(timeOf(pick).start, next ? timeOf(next).start : m.last)}">${frame}</g>`;
|
|
139
|
+
|
|
140
|
+
const faded = new Map(layout.lanes.map((lane) => [lane.id, fadeOf(lane.id)]));
|
|
141
|
+
|
|
142
|
+
const lanes = layout.lanes
|
|
143
|
+
.map((lane) => {
|
|
144
|
+
const rect = (cls: string, extra = ""): string => `<rect class="${cls}" x="${r1(lane.x)}" y="${r1(lane.y)}" width="${r1(lane.w)}" height="${lane.h}" rx="${N.radius}"${extra}/>`;
|
|
145
|
+
const rings = layout.picks.flatMap((pick, k) => (pick.lane === lane.id ? [ring(pick, layout.picks[k + 1], `${rect("dg-halo")}${rect("dg-on")}`)] : [])).join("");
|
|
146
|
+
const notes = subLines(lane, m, subs.get(lane.id) ?? [], lane.title.baseline, ctx.ink, lane.noteRight);
|
|
147
|
+
const fade = faded.get(lane.id);
|
|
148
|
+
return (
|
|
149
|
+
`<g${fade ? ' class="dg-a"' : ""} data-lineup-lane="${esc(lane.id)}" style="${cs(lane.color)}${fade ? `;${fade}` : ""}">` +
|
|
150
|
+
`${rect("dg-st", ` ${ctx.sh}`)}${rings}${write(ctx.ink, "dg-sn", lane.title.x, lane.title.baseline, lane.name, TYPE.boxName, ALWAYS)}${notes}</g>`
|
|
151
|
+
);
|
|
152
|
+
})
|
|
153
|
+
.join("");
|
|
154
|
+
|
|
155
|
+
const stripes = N.seal.stripe;
|
|
156
|
+
const pattern = `<defs><pattern id="dg-seal-${ctx.id}" patternUnits="userSpaceOnUse" width="${stripes * 2}" height="${stripes * 2}" patternTransform="rotate(45)"><rect class="dg-ln-sl" width="${stripes * 2}" height="${stripes * 2}"/><rect class="dg-ln-sd" width="${stripes}" height="${stripes * 2}"/></pattern></defs>`;
|
|
157
|
+
|
|
158
|
+
const chips = layout.lanes
|
|
159
|
+
.map((lane) => {
|
|
160
|
+
const seals = layout.seals.filter((s) => s.lane === lane.id);
|
|
161
|
+
const closed = seals.map(closedOf);
|
|
162
|
+
const seats = layout.chips.filter((c) => c.lane === lane.id).map((c) => chip(c, closed)).join("");
|
|
163
|
+
const hide = hideOf(seals);
|
|
164
|
+
const track = `<g${hide ? ' class="dg-a"' : ""} data-lineup-track="${esc(lane.id)}"${hide ? ` style="${hide}"` : ""}>${seats}</g>`;
|
|
165
|
+
const covers = seals
|
|
166
|
+
.map((s) => `<rect class="dg-ln-seal dg-a" data-lineup-seal="${esc(lane.id)}" x="${r1(s.x)}" y="${r1(s.y)}" width="${r1(s.w)}" height="${r1(s.h)}" rx="${N.seal.radius}" fill="url(#dg-seal-${ctx.id})" style="${sealKf(s)}"/>`)
|
|
167
|
+
.join("");
|
|
168
|
+
const stamps = layout.stamps
|
|
169
|
+
.filter((s) => s.lane === lane.id)
|
|
170
|
+
.map((s) => {
|
|
171
|
+
const at = timeOf(s).start;
|
|
172
|
+
const cx = s.x + s.w / 2;
|
|
173
|
+
const cy = s.y + s.h / 2;
|
|
174
|
+
const text = write(ctx.ink, "dg-ln-st", cx, cy + LOOK.baseline.tag, s.text, TYPE.stamp, [[at, Number.POSITIVE_INFINITY]], "middle");
|
|
175
|
+
return `<g class="dg-popc dg-a" data-lineup-stamp="${esc(lane.id)}" style="${cs(N.stamp.color)};${m.pop(at)}"><g transform="rotate(${N.stamp.tilt} ${r1(cx)} ${r1(cy)})"><rect class="dg-ln-stamp" x="${r1(s.x)}" y="${r1(s.y)}" width="${r1(s.w)}" height="${s.h}" rx="${N.stamp.radius}"/>${text}</g></g>`;
|
|
176
|
+
})
|
|
177
|
+
.join("");
|
|
178
|
+
const fade = faded.get(lane.id);
|
|
179
|
+
return `<g${fade ? ` class="dg-a" style="${fade}"` : ""}>${track}${covers}${stamps}</g>`;
|
|
180
|
+
})
|
|
181
|
+
.join("");
|
|
182
|
+
|
|
183
|
+
return { lanes, chips: `${pattern}${chips}` };
|
|
184
|
+
}
|
package/src/render/parts.ts
CHANGED
|
@@ -87,6 +87,8 @@ export function arrowHead(points: Point[]): string {
|
|
|
87
87
|
export interface Ctx {
|
|
88
88
|
m: Motion;
|
|
89
89
|
t: Timeline;
|
|
90
|
+
/** 図の名前。図の中の定義 (影の filter、封の縞) の名札に使う */
|
|
91
|
+
id: string;
|
|
90
92
|
/** 影の filter を付ける属性 */
|
|
91
93
|
sh: string;
|
|
92
94
|
/** 最後の段の終わり */
|
|
@@ -138,8 +140,11 @@ export function band(region: SceneRegion, ink: Ink[]): string {
|
|
|
138
140
|
/** 箱の下の小さな字の移り変わり。`[時刻, 字, class]` の並びで、最初は元の字。 */
|
|
139
141
|
export type SubChange = [number, string, string];
|
|
140
142
|
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
+
/**
|
|
144
|
+
* 箱の下の小さな字。基準線を `y` に置き、起きたことに合わせて書き換わる。
|
|
145
|
+
* `right` を渡すと、箱の真ん中でなく字の右端を `right` に揃える (列の図の列の右上の字、#3239)
|
|
146
|
+
*/
|
|
147
|
+
export function subLines(box: SceneBox, m: Motion, changes: SubChange[], y: number, ink?: Ink[], right?: number): string {
|
|
143
148
|
const seq: SubChange[] = [[0, box.sub ?? "", "dg-ss"], ...changes];
|
|
144
149
|
return seq
|
|
145
150
|
.map(([t, text, cls], k) => {
|
|
@@ -147,7 +152,9 @@ function subLines(box: SceneBox, m: Motion, changes: SubChange[], y: number, ink
|
|
|
147
152
|
const anim = k === 0 ? (next === undefined ? "" : m.until(next - MOTION.untilFade)) : next === undefined ? m.rise(t) : m.rise(t, next - MOTION.untilFade);
|
|
148
153
|
if (text === "") return "";
|
|
149
154
|
const shown: Shown[] = [[k === 0 ? 0 : t, next === undefined ? Number.POSITIVE_INFINITY : next - MOTION.untilFade]];
|
|
150
|
-
|
|
155
|
+
const style = cls === "dg-ss" ? TYPE.boxSub : TYPE.boxSubStrong;
|
|
156
|
+
const drawn = right === undefined ? write(ink, cls, box.cx, y, text, style, shown, "middle") : write(ink, cls, right - textWidth(text, style), y, text, style, shown);
|
|
157
|
+
return `<g${anim ? ` class="dg-a" style="${anim}"` : ""}>${drawn}</g>`;
|
|
151
158
|
})
|
|
152
159
|
.join("");
|
|
153
160
|
}
|
|
@@ -256,11 +263,12 @@ export function lifeline(x: number, y1: number, y2: number): string {
|
|
|
256
263
|
* 線。点線で道を見せておき、その段で色の線を引いて、段の終わりまで流れる点で向きを見せる。
|
|
257
264
|
* 済んだ段は薄く残し、最後の段の後に通った道を全て濃くし直す。
|
|
258
265
|
* `past` を立てると (状態遷移図、#3171)、段が終わった後は色の線を消して灰の実線に替え、最後の段まで残す。
|
|
266
|
+
* `since` を渡すと (木の図の後から現れる箱へ向かう線、#3240)、点線の道をその時刻から出す。
|
|
259
267
|
*/
|
|
260
|
-
export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false): { base: string; lit: string } {
|
|
268
|
+
export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false, since = 0): { base: string; lit: string } {
|
|
261
269
|
const { m } = ctx;
|
|
262
|
-
//
|
|
263
|
-
ctx.traces.push({ from: e.from, to: e.to, points: e.points, shown: ALWAYS });
|
|
270
|
+
// 点線の道は `since` から最後まで見えている。`since` が 0 なら初めから見えている
|
|
271
|
+
ctx.traces.push({ from: e.from, to: e.to, points: e.points, shown: since > 0 ? [[since, Number.POSITIVE_INFINITY]] : ALWAYS });
|
|
264
272
|
const d = pathOf(e.points);
|
|
265
273
|
const head = arrowHead(e.points);
|
|
266
274
|
const { start: a, drawn: b, end } = time;
|
|
@@ -298,8 +306,9 @@ export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false): { ba
|
|
|
298
306
|
[m.total, { opacity: 0, "stroke-dashoffset": run }],
|
|
299
307
|
]);
|
|
300
308
|
const grey = past ? m.kf([[0, { opacity: 0 }], [end, { opacity: 0 }, EASE.inOut], [end + 0.4, { opacity: 1 }], [m.last, { opacity: 1 }, EASE.inOut], [m.total, { opacity: 0 }]]) : "";
|
|
309
|
+
const path = `<path class="dg-e" d="${d}"/><path class="dg-eh" d="${head}"/>`;
|
|
301
310
|
return {
|
|
302
|
-
base: `<
|
|
311
|
+
base: `${since > 0 ? `<g class="dg-a" style="${m.vis(since)}">${path}</g>` : path}${past ? `<path class="dg-e-past dg-a" d="${d}" style="${grey}"/><path class="dg-eh-past dg-a" d="${head}" style="${grey}"/>` : ""}`,
|
|
303
312
|
lit: `<g style="${cs(e.color)}"><path class="dg-e-on dg-a" pathLength="1" d="${d}" style="${line}"/><path class="dg-eh-on dg-a" d="${head}" style="${hk}"/><path class="dg-flow dg-a" d="${d}" style="${flow}"/></g>`,
|
|
304
313
|
};
|
|
305
314
|
}
|
package/src/render/svg.ts
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
import { FIGURE_TEXT } from "../figure-text";
|
|
10
10
|
import { layoutArchitecture } from "../layout/architecture";
|
|
11
11
|
import { isGitLayout, layoutGit } from "../layout/git";
|
|
12
|
+
import { isLineupLayout, layoutLineup } from "../layout/lineup";
|
|
12
13
|
import { textWidth } from "../layout/measure";
|
|
13
14
|
import type { Layout, Rect, SceneField, SceneLabel } from "../layout/scene";
|
|
14
15
|
import { layoutSequence } from "../layout/sequence";
|
|
15
16
|
import { layoutState } from "../layout/state";
|
|
16
17
|
import { isTimeLayout, layoutTime } from "../layout/time";
|
|
18
|
+
import { isTreeLayout, layoutTree } from "../layout/tree";
|
|
17
19
|
import { FONTS } from "../look/fonts";
|
|
18
20
|
import { type ColorKey, type Colors, EASE, FONT_VARS, isColorName, isColorValue, LOOK, MOTION, type Palette, paletteVars, resolvePalette, type TextStyle, type Theme, TYPE } from "../look/values";
|
|
19
21
|
import { readDiagram } from "../version";
|
|
@@ -44,7 +46,9 @@ import {
|
|
|
44
46
|
type SubChange,
|
|
45
47
|
} from "./parts";
|
|
46
48
|
import { drawGit } from "./git";
|
|
49
|
+
import { drawLineup } from "./lineup";
|
|
47
50
|
import { drawTime, meterField, sansOf, timeFocus } from "./time";
|
|
51
|
+
import { drawTree } from "./tree";
|
|
48
52
|
import { findOverlaps, type Ink, type Overlap, type Trace } from "./ink";
|
|
49
53
|
import { Motion } from "./motion";
|
|
50
54
|
|
|
@@ -172,6 +176,29 @@ const PART_CSS = [
|
|
|
172
176
|
`.dg-git-n{${font(TYPE.gitNote)};fill:var(--ink2)}`,
|
|
173
177
|
`.dg-git-old{fill:var(--surf);stroke:var(--c);stroke-width:${S.gitOrphan};stroke-dasharray:3 3;stroke-opacity:.6}`,
|
|
174
178
|
`.dg-git-oldl{${font(TYPE.gitId)};fill:var(--ct);opacity:.55}`,
|
|
179
|
+
// 木の図 (#3233)。木の線は線の灰で、運ぶ物が通った跡は運ぶ物の色で引く
|
|
180
|
+
`.dg-tree-l{fill:none;stroke:var(--line);stroke-width:${S.tree};stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1 2}`,
|
|
181
|
+
`.dg-tree-tr{fill:none;stroke:var(--c);stroke-width:${S.treeTrail};stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1 2}`,
|
|
182
|
+
`.dg-tree-h{fill:none;stroke:var(--c);stroke-width:${S.treeTrail};stroke-linecap:round;stroke-linejoin:round}`,
|
|
183
|
+
`.dg-tree-con{fill:none;stroke:var(--line);stroke-width:${S.treeCon};stroke-linecap:round;stroke-dasharray:2 3.5}`,
|
|
184
|
+
`.dg-tree-card{fill:var(--surf);stroke:var(--hair);stroke-width:${S.hair}}`,
|
|
185
|
+
`.dg-tree-cg{fill:none;stroke:var(--mute);stroke-width:${S.glyph};stroke-linecap:round;stroke-linejoin:round}`,
|
|
186
|
+
`.dg-tree-ct{${font(TYPE.treeCard)};fill:var(--ink)}`,
|
|
187
|
+
`.dg-tree-hash{${font(TYPE.treeHash)};fill:var(--ink)}`,
|
|
188
|
+
`.dg-tree-name{${font(TYPE.treeName)};fill:var(--mute)}`,
|
|
189
|
+
`.dg-tree-one{${font(TYPE.boxName)};fill:var(--ink)}`,
|
|
190
|
+
`.dg-tree-rh{${font(TYPE.rootHash)};fill:var(--ink)}`,
|
|
191
|
+
`.dg-tree-rn{${font(TYPE.rootName)};fill:var(--mute)}`,
|
|
192
|
+
// 列の図 (#3239)。封は列の左端から右へ伸びる
|
|
193
|
+
".dg-ln-chip{fill:var(--c)}",
|
|
194
|
+
`.dg-ln-plain{fill:color-mix(in srgb,var(--mute) ${X.chipPlain}%,var(--surf))}`,
|
|
195
|
+
`.dg-ln-t{${font(TYPE.chip)};fill:var(--on-c)}`,
|
|
196
|
+
`.dg-ln-tp{${font(TYPE.chip)};fill:var(--ink)}`,
|
|
197
|
+
".dg-ln-seal{transform-box:fill-box;transform-origin:0 50%}",
|
|
198
|
+
`.dg-ln-sd{fill:color-mix(in srgb,var(--mute) ${X.sealDark}%,var(--surf))}`,
|
|
199
|
+
`.dg-ln-sl{fill:color-mix(in srgb,var(--mute) ${X.sealLight}%,var(--surf))}`,
|
|
200
|
+
`.dg-ln-stamp{fill:var(--surf);stroke:var(--c);stroke-width:${S.stamp}}`,
|
|
201
|
+
`.dg-ln-st{${font(TYPE.stamp)};fill:var(--ct)}`,
|
|
175
202
|
// 時間軸の図 (#3165)。和文を含む字は、末尾に j を付けた class で同じ大きさと太さの和文の字にする
|
|
176
203
|
`.dg-tm-ep{fill:color-mix(in srgb,var(--ink) ${X.timeShade}%,transparent)}`,
|
|
177
204
|
`.dg-tm-sep{stroke:var(--hair);stroke-width:${S.hair};stroke-dasharray:2 4}`,
|
|
@@ -341,7 +368,7 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
341
368
|
const vars = paletteVars(palette, theme);
|
|
342
369
|
const id = nameOf(`${JSON.stringify(diagram)}|${vars}|${follow ? `${follow.width}|${follow.lang}` : ""}`);
|
|
343
370
|
const m = new Motion(`dg${id}`, timeline.total, timeline.last);
|
|
344
|
-
const ctx: Ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: (timeline.steps[timeline.steps.length - 1] as Span).end, ink, traces };
|
|
371
|
+
const ctx: Ctx = { m, t: timeline, id, sh: `filter="url(#dg-sh-${id})"`, end: (timeline.steps[timeline.steps.length - 1] as Span).end, ink, traces };
|
|
345
372
|
const on = involved(diagram);
|
|
346
373
|
// 時系列図の処理は生存線の上の札に出し、他の図の種類は箱の下の字に出す
|
|
347
374
|
const subs = subChanges(diagram, timeline, layout.kind !== "sequence");
|
|
@@ -370,6 +397,22 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
370
397
|
L.node.push(git.commits);
|
|
371
398
|
L.top.push(git.tags);
|
|
372
399
|
}
|
|
400
|
+
// 木の図の木の線と通った跡と木の箱と札は、木の図を描く部品が描く (#3233)。木の線を走る線は通った跡が見せるので、ほかの線と同じ線で描かない
|
|
401
|
+
const treeLayout = isTreeLayout(layout) ? layout : undefined;
|
|
402
|
+
const tree = treeLayout ? drawTree(treeLayout, diagram, timeline, ctx) : undefined;
|
|
403
|
+
if (tree) {
|
|
404
|
+
L.base.push(tree.links);
|
|
405
|
+
L.lit.push(tree.trails);
|
|
406
|
+
L.node.push(tree.nodes);
|
|
407
|
+
}
|
|
408
|
+
const runs = new Set((treeLayout?.runs ?? []).map((r) => `${r.step}/${r.event}`));
|
|
409
|
+
// 列の図の列とチップと封と札は、列の図を描く部品が描く (#3239)
|
|
410
|
+
const lineupLayout = isLineupLayout(layout) ? layout : undefined;
|
|
411
|
+
if (lineupLayout) {
|
|
412
|
+
const lineup = drawLineup(lineupLayout, diagram, timeline, ctx, subs);
|
|
413
|
+
L.base.push(lineup.lanes);
|
|
414
|
+
L.node.push(lineup.chips);
|
|
415
|
+
}
|
|
373
416
|
// 時間軸の図の目盛りと印と拡大の帯の箱と節目は、時間軸の図を描く部品が描く (#3165)。拡大の帯の線は他の図と同じ線で描く
|
|
374
417
|
const timeLayout = isTimeLayout(layout) ? layout : undefined;
|
|
375
418
|
if (timeLayout) {
|
|
@@ -382,8 +425,10 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
382
425
|
const wired = new Set((timeLayout?.wires ?? []).map((w) => `${w.step}/${w.event}`));
|
|
383
426
|
for (const e of layout.edges) {
|
|
384
427
|
const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
|
|
385
|
-
if (!time || (timeLayout && !wired.has(`${e.step}/${e.event}`))) continue;
|
|
386
|
-
|
|
428
|
+
if (!time || (timeLayout && !wired.has(`${e.step}/${e.event}`)) || runs.has(`${e.step}/${e.event}`)) continue;
|
|
429
|
+
// 木の図の箱は段ごとに現れるので、木の線を走らない線の点線は、両端の木の箱が現れてから出す (#3240)
|
|
430
|
+
const since = Math.max(tree?.appear.get(e.from) ?? 0, tree?.appear.get(e.to) ?? 0);
|
|
431
|
+
const drawn = edge(e, time, ctx, isState, since);
|
|
387
432
|
L.base.push(drawn.base);
|
|
388
433
|
L.lit.push(drawn.lit);
|
|
389
434
|
}
|
|
@@ -391,7 +436,7 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
391
436
|
// 飛び先を持つ箱は、箱の札をその飛び先への link で包む (#3199)。時間軸の図の箱は時間軸の図を描く部品が包む
|
|
392
437
|
const links = new Map(diagram.boxes.flatMap((b) => (b.link === undefined ? [] : [[b.id, b.link] as [string, string]])));
|
|
393
438
|
const linked = (id: string, markup: string): string => linkTo(links.get(id), markup);
|
|
394
|
-
for (const box of timeLayout ? [] : layout.boxes) {
|
|
439
|
+
for (const box of timeLayout || lineupLayout ? [] : layout.boxes) {
|
|
395
440
|
if (box.ghost) {
|
|
396
441
|
L.node.push(linked(box.id, ghostCard(box, ink)));
|
|
397
442
|
continue;
|
|
@@ -413,9 +458,10 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
413
458
|
const until = (timeline.steps[a.step] as Span).end;
|
|
414
459
|
L.top.push(whole && until > whole.start ? action(a, time.at, whole.end, ctx) : action(a, time.at, until, ctx, whole));
|
|
415
460
|
}
|
|
461
|
+
// 木の図の運ぶ物は着いた所で消える。通った跡が行き先を残し、兄弟の箱から同じ親へ着いた運ぶ物が重ならないため
|
|
416
462
|
for (const time of timeline.carriers) {
|
|
417
463
|
const e = layout.edges.find((x) => x.step === time.step && x.event === time.event);
|
|
418
|
-
if (e) L.top.push(carrier(e, time, ctx));
|
|
464
|
+
if (e) L.top.push(carrier(e, treeLayout ? { ...time, start: time.depart, end: time.arrive + MOTION.fade } : time, ctx));
|
|
419
465
|
}
|
|
420
466
|
const content = Object.values(L)
|
|
421
467
|
.map((parts) => parts.join(""))
|
|
@@ -471,6 +517,21 @@ function focusParts(layout: Layout, diagram: Diagram, step: number): Rect[] {
|
|
|
471
517
|
rects.push({ x: Math.min(...xs), y: Math.min(...ys), w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys) });
|
|
472
518
|
}
|
|
473
519
|
rects.push(...layout.labels.filter((l) => l.step === step), ...layout.actions.filter((a) => a.step === step));
|
|
520
|
+
// 木の図は、その段で現れる木の箱と木の線と、線の両端の木の箱を見る (#3233)
|
|
521
|
+
if (isTreeLayout(layout)) {
|
|
522
|
+
const ends = new Set((diagram.steps[step]?.events ?? []).flatMap((e) => (e.type === "edge" ? [e.from, e.to] : [])));
|
|
523
|
+
rects.push(...layout.nodes.filter((n) => n.step === step || ends.has(n.id)));
|
|
524
|
+
for (const l of layout.links.filter((x) => x.step === step)) {
|
|
525
|
+
const xs = l.points.map((p) => p[0]);
|
|
526
|
+
const ys = l.points.map((p) => p[1]);
|
|
527
|
+
rects.push({ x: Math.min(...xs), y: Math.min(...ys), w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys) });
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// 列の図は、その段で変わる列を見る (#3239)
|
|
531
|
+
if (isLineupLayout(layout)) {
|
|
532
|
+
const changed = new Set((diagram.steps[step]?.events ?? []).flatMap((e) => ("box" in e ? [e.box] : [])));
|
|
533
|
+
rects.push(...layout.lanes.filter((lane) => changed.has(lane.id)));
|
|
534
|
+
}
|
|
474
535
|
for (const event of diagram.steps[step]?.events ?? []) {
|
|
475
536
|
const ids = event.type === "edge" ? [event.from, event.to] : event.type === "action" || event.type === "swap" ? [event.box] : [];
|
|
476
537
|
for (const id of ids) {
|
|
@@ -582,6 +643,7 @@ function followView(layout: Layout, timeline: Timeline, diagram: Diagram, m: Mot
|
|
|
582
643
|
const shapes = [
|
|
583
644
|
...layout.regions.map((r) => `<rect class="dg-mm-band" style="${cs(r.color)}" x="${mx + r.x * k}" y="${my + r.y * k}" width="${r.w * k}" height="${r.h * k}" rx="3"/>`),
|
|
584
645
|
...layout.boxes.map((b) => `<rect class="dg-mm-card" style="${cs(b.color)}" x="${mx + b.x * k}" y="${my + b.y * k}" width="${b.w * k}" height="${b.h * k}" rx="1.5"/>`),
|
|
646
|
+
...(isTreeLayout(layout) ? layout.nodes : []).map((n) => `<rect class="dg-mm-card" style="${cs(n.color)}" x="${mx + n.x * k}" y="${my + n.y * k}" width="${n.w * k}" height="${n.h * k}" rx="1.5"/>`),
|
|
585
647
|
].join("");
|
|
586
648
|
const vp = m.move(cam.map(([t, cx, cy, , e]) => [t, mx + (cx - vw / 2) * k, my + (cy - vh / 2) * k, 1, e]));
|
|
587
649
|
return {
|
|
@@ -634,7 +696,11 @@ export function renderDiagram(input: unknown, options: RenderOptions = {}): Rend
|
|
|
634
696
|
? layoutGit(diagram)
|
|
635
697
|
: diagram.kind === "time"
|
|
636
698
|
? layoutTime(diagram, lang)
|
|
637
|
-
:
|
|
699
|
+
: diagram.kind === "tree"
|
|
700
|
+
? layoutTree(diagram)
|
|
701
|
+
: diagram.kind === "lineup"
|
|
702
|
+
? layoutLineup(diagram)
|
|
703
|
+
: layoutArchitecture(diagram);
|
|
638
704
|
return renderLayout(diagram, layout, buildTimeline(diagram, options.still === true), options);
|
|
639
705
|
}
|
|
640
706
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 木の図 (#3233) を描く部品。見た目の元は step 2 で本人が選んだ「根を上」の試作 (`.context/propose/merkle-look/`)。
|
|
3
|
+
*
|
|
4
|
+
* 木の箱は書いた段で、親から子への木の線を引き終えた時に弾んで出る。木の線は親を書いた段で引き、最後まで残す。
|
|
5
|
+
* 値を持つ葉の下の名札の札は、葉より前の最初の段から出しておき、葉が出た時に葉と札を点線で結ぶ。
|
|
6
|
+
* 木の線を走る運ぶ物は着いた所で消え、通った木の線を運ぶ物の色で最後まで残す (`data-tree-trail`)。
|
|
7
|
+
* 木の線を運ぶ物が初めて通った段から後は、それまでに運ぶ物を送るか受けた木の箱だけを濃く出し、ほかの木の箱と札と木の線を薄く出す。
|
|
8
|
+
* 線の両端になった木の箱は、その段の間だけ縁に色を付ける。
|
|
9
|
+
* 木の箱が現れる時刻 (`appear`) を返し、木の線を走らない線の点線はその時刻から出す (#3240)。
|
|
10
|
+
*/
|
|
11
|
+
import type { TreeLayout } from "../layout/tree";
|
|
12
|
+
import { EASE, LOOK, MOTION, TYPE } from "../look/values";
|
|
13
|
+
import type { Diagram } from "../schema";
|
|
14
|
+
import type { EdgeTime, Timeline } from "../timeline";
|
|
15
|
+
import type { Frame } from "./motion";
|
|
16
|
+
import { ALWAYS } from "./ink";
|
|
17
|
+
import { activeKf, arrowHead, type Ctx, cs, esc, glyph, pathOf, write } from "./parts";
|
|
18
|
+
|
|
19
|
+
const r1 = (v: number): number => Math.round(v * 100) / 100;
|
|
20
|
+
|
|
21
|
+
export function drawTree(layout: TreeLayout, diagram: Diagram, timeline: Timeline, ctx: Ctx): { links: string; trails: string; nodes: string; appear: Map<string, number> } {
|
|
22
|
+
const { m } = ctx;
|
|
23
|
+
const T = LOOK.tree;
|
|
24
|
+
const B = LOOK.box;
|
|
25
|
+
const timeOf = (step: number, event: number): EdgeTime | undefined => timeline.edges.find((t) => t.step === step && t.event === event);
|
|
26
|
+
|
|
27
|
+
// 木の箱ごとの、線の両端になる段と、運ぶ物を初めて送るか受けた段
|
|
28
|
+
const active = new Map<string, Set<number>>();
|
|
29
|
+
const touched = new Map<string, number>();
|
|
30
|
+
diagram.steps.forEach((step, s) => {
|
|
31
|
+
for (const e of step.events) {
|
|
32
|
+
if (e.type !== "edge") continue;
|
|
33
|
+
for (const id of [e.from, e.to]) {
|
|
34
|
+
active.set(id, (active.get(id) ?? new Set()).add(s));
|
|
35
|
+
if (e.carry.kind !== "none" && !touched.has(id)) touched.set(id, s);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const carries = (step: number, event: number): boolean => {
|
|
40
|
+
const e = diagram.steps[step]?.events[event];
|
|
41
|
+
return e?.type === "edge" && e.carry.kind !== "none";
|
|
42
|
+
};
|
|
43
|
+
const fadeStep = layout.runs.filter((run) => carries(run.step, run.event)).reduce<number | undefined>((s, run) => (s === undefined ? run.step : Math.min(s, run.step)), undefined);
|
|
44
|
+
const fadeAt = fadeStep === undefined ? undefined : timeline.steps[fadeStep]?.start;
|
|
45
|
+
|
|
46
|
+
/** 木の箱 `id` の薄くなる動き。薄くしない箱は `undefined` */
|
|
47
|
+
const fadeOf = (id: string): string | undefined => {
|
|
48
|
+
if (fadeStep === undefined || fadeAt === undefined) return undefined;
|
|
49
|
+
const t = touched.get(id);
|
|
50
|
+
if (t !== undefined && t <= fadeStep) return undefined;
|
|
51
|
+
const back = t === undefined ? undefined : timeline.steps[t]?.start;
|
|
52
|
+
const frames: Frame[] = [
|
|
53
|
+
[0, { opacity: 1 }],
|
|
54
|
+
[fadeAt, { opacity: 1 }, EASE.inOut],
|
|
55
|
+
[fadeAt + MOTION.fade, { opacity: T.faint }],
|
|
56
|
+
];
|
|
57
|
+
if (back !== undefined) frames.push([back, { opacity: T.faint }, EASE.inOut], [back + MOTION.fade, { opacity: 1 }]);
|
|
58
|
+
frames.push([m.last, { opacity: back === undefined ? T.faint : 1 }, EASE.inOut], [m.total, { opacity: 1 }]);
|
|
59
|
+
return m.kf(frames);
|
|
60
|
+
};
|
|
61
|
+
const faded = (id: string, markup: string, attrs = ""): string => {
|
|
62
|
+
const fade = fadeOf(id);
|
|
63
|
+
return fade ? `<g class="dg-a"${attrs} style="${fade}">${markup}</g>` : attrs === "" ? markup : `<g${attrs}>${markup}</g>`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const drawnAt = new Map(layout.nodes.map((n) => [n.id, timeOf(n.step, n.event)?.drawn ?? 0]));
|
|
67
|
+
|
|
68
|
+
// 木の線と、葉と札を結ぶ点線。木の線は親を書いた段で引き始め、引き終えた後も残す
|
|
69
|
+
const links = layout.links
|
|
70
|
+
.map((l) => {
|
|
71
|
+
const time = timeOf(l.step, l.event);
|
|
72
|
+
if (!time) return "";
|
|
73
|
+
ctx.traces.push({ from: l.from, to: l.to, points: l.points, shown: [[time.start, Number.POSITIVE_INFINITY]] });
|
|
74
|
+
const kf = m.kf([
|
|
75
|
+
[0, { opacity: 0, "stroke-dashoffset": 1 }],
|
|
76
|
+
[time.start, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
|
|
77
|
+
[time.start + 0.05, { opacity: 1 }],
|
|
78
|
+
[time.drawn, { "stroke-dashoffset": 0 }],
|
|
79
|
+
[m.last, { opacity: 1, "stroke-dashoffset": 0 }, EASE.inOut],
|
|
80
|
+
[m.total, { opacity: 0, "stroke-dashoffset": 0 }],
|
|
81
|
+
]);
|
|
82
|
+
return faded(l.from, `<path class="dg-tree-l dg-a" data-tree-link="${esc(l.from)}" pathLength="1" d="${pathOf(l.points)}" style="${kf}"/>`);
|
|
83
|
+
})
|
|
84
|
+
.join("");
|
|
85
|
+
const ties = layout.nodes
|
|
86
|
+
.flatMap((n) => {
|
|
87
|
+
if (!n.card) return [];
|
|
88
|
+
const at = drawnAt.get(n.id) ?? 0;
|
|
89
|
+
const d = `M ${r1(n.cx)} ${r1(n.y + n.h + LOOK.edge.inset)} V ${r1(n.card.y - LOOK.edge.inset)}`;
|
|
90
|
+
return [faded(n.id, `<path class="dg-tree-con dg-a" d="${d}" style="${m.vis(at)}"/>`)];
|
|
91
|
+
})
|
|
92
|
+
.join("");
|
|
93
|
+
|
|
94
|
+
// 木の線を運ぶ物が通った跡。運ぶ物が走るのに合わせて引き、最後まで残す。同じ木の線は最初に通った段の跡だけを描く
|
|
95
|
+
const traced = new Set<string>();
|
|
96
|
+
const trails = layout.runs
|
|
97
|
+
.flatMap((run) => {
|
|
98
|
+
const e = layout.edges.find((x) => x.step === run.step && x.event === run.event);
|
|
99
|
+
if (!e || traced.has(run.link)) return [];
|
|
100
|
+
const carried = timeline.carriers.find((c) => c.step === run.step && c.event === run.event);
|
|
101
|
+
const time = timeOf(run.step, run.event);
|
|
102
|
+
const a = carried?.depart ?? time?.start;
|
|
103
|
+
const b = carried?.arrive ?? time?.drawn;
|
|
104
|
+
if (a === undefined || b === undefined) return [];
|
|
105
|
+
traced.add(run.link);
|
|
106
|
+
const kf = m.kf([
|
|
107
|
+
[0, { opacity: 0, "stroke-dashoffset": 1 }],
|
|
108
|
+
[a, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
|
|
109
|
+
[a + 0.05, { opacity: 1 }],
|
|
110
|
+
[b, { "stroke-dashoffset": 0 }],
|
|
111
|
+
[m.last, { opacity: 1, "stroke-dashoffset": 0 }, EASE.inOut],
|
|
112
|
+
[m.total, { opacity: 0, "stroke-dashoffset": 0 }],
|
|
113
|
+
]);
|
|
114
|
+
const d = pathOf(e.points);
|
|
115
|
+
return [
|
|
116
|
+
`<g style="${cs(e.color)}"><path class="dg-tree-tr dg-a" data-tree-trail="${esc(run.link)}" pathLength="1" d="${d}" style="${kf}"/><path class="dg-tree-h dg-a" d="${arrowHead(e.points)}" style="${m.vis(b)}"/></g>`,
|
|
117
|
+
];
|
|
118
|
+
})
|
|
119
|
+
.join("");
|
|
120
|
+
|
|
121
|
+
// 葉の下の名札の札。最初の段から出しておく
|
|
122
|
+
const cards = layout.nodes
|
|
123
|
+
.flatMap((n) => {
|
|
124
|
+
const c = n.card;
|
|
125
|
+
if (!c) return [];
|
|
126
|
+
const gx = c.x + T.card.padX + T.card.icon / 2;
|
|
127
|
+
const cy = c.y + c.h / 2;
|
|
128
|
+
const text = write(ctx.ink, "dg-tree-ct", c.x + T.card.padX + T.card.icon + T.card.gap, cy + LOOK.baseline.label, c.text, TYPE.treeCard, ALWAYS);
|
|
129
|
+
return [
|
|
130
|
+
faded(
|
|
131
|
+
n.id,
|
|
132
|
+
`<rect class="dg-tree-card" x="${r1(c.x)}" y="${r1(c.y)}" width="${r1(c.w)}" height="${c.h}" rx="${T.card.radius}"/>${glyph("doc", gx, cy, T.card.glyph, "dg-tree-cg")}${text}`,
|
|
133
|
+
` data-tree-card="${esc(n.id)}"`,
|
|
134
|
+
),
|
|
135
|
+
];
|
|
136
|
+
})
|
|
137
|
+
.join("");
|
|
138
|
+
|
|
139
|
+
// 木の箱。親から子への線を引き終えた時に弾んで出る。根は左に枝の絵柄を持ち、字を絵柄の右に左揃えで並べる
|
|
140
|
+
const nodes = layout.nodes
|
|
141
|
+
.map((n) => {
|
|
142
|
+
const at = drawnAt.get(n.id) ?? 0;
|
|
143
|
+
const on = [...(active.get(n.id) ?? [])].sort((x, y) => x - y);
|
|
144
|
+
const act = on.length > 0 ? activeKf(ctx, on) : undefined;
|
|
145
|
+
const radius = n.root ? T.root.radius : T.radius;
|
|
146
|
+
const rect = (cls: string, extra = ""): string => `<rect class="${cls}" x="${r1(n.x)}" y="${r1(n.y)}" width="${r1(n.w)}" height="${n.h}" rx="${radius}"${extra}/>`;
|
|
147
|
+
const frame = `${act ? `<g class="dg-a" style="${act}">${rect("dg-halo")}</g>` : ""}${rect("dg-st", ` ${ctx.sh}`)}${act ? `<g class="dg-a" style="${act}">${rect("dg-on")}</g>` : ""}`;
|
|
148
|
+
const ix = n.x + T.root.iconX + B.icon / 2;
|
|
149
|
+
const mark = n.root ? `<rect class="dg-ic" x="${r1(ix - B.icon / 2)}" y="${r1(n.cy - B.icon / 2)}" width="${B.icon}" height="${B.icon}" rx="${B.iconRadius}"/>${glyph("tree", ix, n.cy, B.iconScale)}` : "";
|
|
150
|
+
const shown: [number, number][] = [[at, Number.POSITIVE_INFINITY]];
|
|
151
|
+
const texts = n.lines
|
|
152
|
+
.map((line, k) => {
|
|
153
|
+
const style = n.styles[k] ?? TYPE.boxName;
|
|
154
|
+
const cls = style === TYPE.treeHash ? "dg-tree-hash" : style === TYPE.treeName ? "dg-tree-name" : style === TYPE.rootHash ? "dg-tree-rh" : style === TYPE.rootName ? "dg-tree-rn" : "dg-tree-one";
|
|
155
|
+
const baseline = n.baselines[k] ?? n.cy;
|
|
156
|
+
return n.root ? write(ctx.ink, cls, n.x + T.root.textX, baseline, line, style, shown) : write(ctx.ink, cls, n.cx, baseline, line, style, shown, "middle");
|
|
157
|
+
})
|
|
158
|
+
.join("");
|
|
159
|
+
const inner = faded(n.id, `${frame}${mark}${texts}`, ` data-tree-node="${esc(n.id)}"${n.root ? ` data-tree-root="${esc(n.id)}"` : ""}`);
|
|
160
|
+
return `<g class="dg-popc dg-a" style="${cs(n.color)};${m.pop(at)}">${inner}</g>`;
|
|
161
|
+
})
|
|
162
|
+
.join("");
|
|
163
|
+
|
|
164
|
+
return { links: links + ties, trails, nodes: cards + nodes, appear: drawnAt };
|
|
165
|
+
}
|