@cardenelabs/dragon 0.41.1 → 0.42.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 +21 -1
- package/dist/cli.cjs +4094 -961
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4094 -961
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +3681 -939
- 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 +3681 -939
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +4016 -815
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -3
- package/dist/index.d.ts +159 -3
- package/dist/index.js +4016 -815
- package/dist/index.js.map +1 -1
- package/dist/{ink-B_7OXxtb.d.cts → ink-B8EZL7JV.d.cts} +95 -3
- package/dist/{ink-B_7OXxtb.d.ts → ink-B8EZL7JV.d.ts} +95 -3
- package/dist/node.cjs +2461 -726
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +2461 -726
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +2 -2
- package/package.json +1 -1
- package/src/field-messages.ts +12 -0
- package/src/figure-text.ts +26 -0
- package/src/index.ts +11 -1
- package/src/layout/scene.ts +23 -2
- package/src/layout/time.ts +680 -0
- package/src/look/values.ts +142 -2
- package/src/messages.ts +108 -5
- package/src/parser.ts +427 -6
- package/src/player.ts +48 -10
- package/src/printer.ts +63 -12
- package/src/render/icons.ts +2 -0
- package/src/render/parts.ts +29 -9
- package/src/render/svg.ts +129 -21
- package/src/render/time.ts +291 -0
- package/src/schema.ts +109 -10
- package/src/schemas/diagram.schema.json +224 -12
- package/src/schemas/validate-diagram.js +1 -1
- package/src/timeline.ts +147 -10
- package/src/words.ts +39 -6
package/src/player.ts
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* 頁に図を置いて動かす。
|
|
3
3
|
*
|
|
4
4
|
* 動きを嫌う設定 (`prefers-reduced-motion: reduce`) は描く前に読み、その人には一瞬も自動再生せず、
|
|
5
|
-
*
|
|
5
|
+
* 段ごとの止め絵を釦で送る。各段の題と本文と出典は、読み上げの道具が段の順に読める番号付きの一覧として置き、
|
|
6
6
|
* 図そのものは読み上げから隠して同じ中身を 2 度読ませない。
|
|
7
7
|
* 見せ方は枠の幅で選び (`view.ts`)、寄って追う時は窓と全体図で描き直す。
|
|
8
8
|
* 釦と段の一覧の読み上げの名前と全体図の札は、渡した言葉 (`options.lang`、書かなければ日本語) で出す (#3001)。
|
|
9
|
+
* 色は `options.palette` の名前の色味に `options.colors` の色の値を重ね、図と全体図と釦と段の帯を同じ色で塗る (#3198)。
|
|
9
10
|
* 段が替わるたびに `options.onStep` で今の段を知らせ、頁の側が段の札や進み具合を出せるようにする (#3031)。
|
|
11
|
+
* 置いた時に流さず決めた段で止めて置く (`options.pausedAt`) ことと、1 度だけ流して最後の段で止める (`options.playOnce`) ことを選べる。
|
|
12
|
+
* 止め絵を選んだ図 (`options.still`) は、最後の段で止まった時に全ての段の線の名前を出す (#3200)。
|
|
10
13
|
* 頁は `goTo` で段へ移って止め、`mark` で図の上に点線の四角を描く。頁の側では SVG を組まないので、編集画面が字の重なりを囲む時もこれを呼ぶ (#3178)。
|
|
11
14
|
* 段の本文の帯は本文の最も長い段の高さに保ち、段を送っても図の大きさと位置を変えない (#3049)。
|
|
12
15
|
* 帯の中身の幅が `LOOK.player.narrow` より狭い時は、段を送る釦を指で押せる大きさにして段の番号と上の段に並べ、
|
|
@@ -14,8 +17,8 @@
|
|
|
14
17
|
*/
|
|
15
18
|
import { FIGURE_TEXT } from "./figure-text";
|
|
16
19
|
import type { Rect } from "./layout/scene";
|
|
17
|
-
import { FONT_VARS, LOOK, paletteVars,
|
|
18
|
-
import { drawSvg, type RenderOptions, renderDiagram } from "./render/svg";
|
|
20
|
+
import { FONT_VARS, LOOK, paletteVars, type TextStyle, TYPE } from "./look/values";
|
|
21
|
+
import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/svg";
|
|
19
22
|
import type { Span } from "./timeline";
|
|
20
23
|
import { chooseView } from "./view";
|
|
21
24
|
|
|
@@ -27,6 +30,10 @@ export interface PlayerOptions extends RenderOptions {
|
|
|
27
30
|
* 枠の高さが決まっている置き場 (カタログの拡大の重ね窓) で使う。枠の高さが図に合わせて伸びる置き場で使うと、描くたびに低くなる
|
|
28
31
|
*/
|
|
29
32
|
fitHeight?: boolean;
|
|
33
|
+
/** 置いた時に流さず、段 `pausedAt` (0 から) の止め絵で止めて置く。段の数を超えた時は最後の段で止める。書かなければ置いた時から流す (#3200) */
|
|
34
|
+
pausedAt?: number;
|
|
35
|
+
/** 流した時に最後の段の止め絵で止め、繰り返さない。最後の段で止まった図を流すと、最初の段から流し直す (#3200) */
|
|
36
|
+
playOnce?: boolean;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export interface Player {
|
|
@@ -115,7 +122,7 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
115
122
|
const rendered = renderDiagram(diagram, options);
|
|
116
123
|
const lang = options.lang ?? "ja";
|
|
117
124
|
const words = FIGURE_TEXT[lang];
|
|
118
|
-
const palette =
|
|
125
|
+
const palette = paletteOf(options, rendered.theme);
|
|
119
126
|
const { timeline } = rendered;
|
|
120
127
|
const steps = rendered.diagram.steps;
|
|
121
128
|
const count = steps.length;
|
|
@@ -190,7 +197,8 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
190
197
|
bar.className = "dg-bar";
|
|
191
198
|
bar.append(row);
|
|
192
199
|
|
|
193
|
-
//
|
|
200
|
+
// 読み上げの道具が段の順に読む一覧。見た目からは外すが、読み上げからは隠さない。
|
|
201
|
+
// 段の出典は本文の後ろに、名前を URL への link にして書いた順に並べる (#3199)
|
|
194
202
|
const list = doc.createElement("ol");
|
|
195
203
|
list.className = "dg-sr";
|
|
196
204
|
list.dataset.dragon = "steps";
|
|
@@ -205,6 +213,18 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
205
213
|
p.textContent = line;
|
|
206
214
|
item.append(p);
|
|
207
215
|
}
|
|
216
|
+
if (step.sources) {
|
|
217
|
+
const sources = doc.createElement("ul");
|
|
218
|
+
for (const source of step.sources) {
|
|
219
|
+
const link = doc.createElement("a");
|
|
220
|
+
link.href = source.url;
|
|
221
|
+
link.textContent = source.name;
|
|
222
|
+
const entry = doc.createElement("li");
|
|
223
|
+
entry.append(link);
|
|
224
|
+
sources.append(entry);
|
|
225
|
+
}
|
|
226
|
+
item.append(sources);
|
|
227
|
+
}
|
|
208
228
|
list.append(item);
|
|
209
229
|
}
|
|
210
230
|
|
|
@@ -223,9 +243,12 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
223
243
|
let width = frameWidth();
|
|
224
244
|
let height = frameHeight();
|
|
225
245
|
let svg: SVGSVGElement | null = null;
|
|
226
|
-
|
|
227
|
-
let
|
|
228
|
-
let
|
|
246
|
+
// 止めて置く段を渡された図は、動きを嫌う人と同じく止め絵で置く
|
|
247
|
+
let step = options.pausedAt === undefined ? 0 : Math.min(count - 1, Math.max(0, options.pausedAt));
|
|
248
|
+
let playing = !reduce && options.pausedAt === undefined;
|
|
249
|
+
let at = playing ? 0 : (timeline.stills[step] ?? 0);
|
|
250
|
+
/** 1 度だけ流す図が止まる時刻 (最後の段の止め絵) */
|
|
251
|
+
const lastStill = timeline.stills[count - 1] ?? 0;
|
|
229
252
|
let born = Date.now();
|
|
230
253
|
let marked: readonly Rect[] = [];
|
|
231
254
|
|
|
@@ -307,11 +330,26 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
307
330
|
restart(playing ? span.start : (timeline.stills[step] ?? span.start), playing);
|
|
308
331
|
};
|
|
309
332
|
|
|
333
|
+
/** 流し始める。1 度だけ流す図が最後の段の止め絵まで来ていれば、最初の段から流し直す */
|
|
334
|
+
const resume = (): void => {
|
|
335
|
+
if (options.playOnce && at >= lastStill) {
|
|
336
|
+
step = 0;
|
|
337
|
+
at = 0;
|
|
338
|
+
}
|
|
339
|
+
restart(at, true);
|
|
340
|
+
};
|
|
341
|
+
|
|
310
342
|
place(markup());
|
|
311
343
|
show();
|
|
312
344
|
|
|
313
345
|
const timer = win?.setInterval(() => {
|
|
314
346
|
if (!playing) return;
|
|
347
|
+
// 1 度だけ流す図は、1 周の中の時刻に直す前の経った時間で最後の段の止め絵まで来たかを見る
|
|
348
|
+
if (options.playOnce && at + (Date.now() - born) / 1000 >= lastStill) {
|
|
349
|
+
step = count - 1;
|
|
350
|
+
restart(lastStill, false);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
315
353
|
const s = stepAt(now());
|
|
316
354
|
if (s !== step) {
|
|
317
355
|
step = s;
|
|
@@ -320,7 +358,7 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
320
358
|
}, 120);
|
|
321
359
|
const onPrev = (): void => go(step - 1);
|
|
322
360
|
const onNext = (): void => go(step + 1);
|
|
323
|
-
const onToggle = (): void => (playing ? restart(now(), false) :
|
|
361
|
+
const onToggle = (): void => (playing ? restart(now(), false) : resume());
|
|
324
362
|
// 段の番号を押すとその段へ移る
|
|
325
363
|
const onFigure = (event: Event): void => {
|
|
326
364
|
const target = (event.target as Element | null)?.closest?.("[data-step]");
|
|
@@ -360,7 +398,7 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
|
|
|
360
398
|
next: onNext,
|
|
361
399
|
prev: onPrev,
|
|
362
400
|
play: () => {
|
|
363
|
-
if (!playing)
|
|
401
|
+
if (!playing) resume();
|
|
364
402
|
},
|
|
365
403
|
pause: () => {
|
|
366
404
|
if (playing) restart(now(), false);
|
package/src/printer.ts
CHANGED
|
@@ -11,17 +11,20 @@
|
|
|
11
11
|
* 区画の箱が飛び飛びの時は同じ `group` を開き直す。区画の並びが箱の現れる順と違う時と、
|
|
12
12
|
* 箱の無い区画がある時は、先に全ての区画を中の無い `group … end` で宣言してから開き直す。
|
|
13
13
|
* 枝分かれの図 (#3164) は、枝の `branch` の行を箱より前に書き、札を動かす線の運ぶ物が送る側の名前の札なら書かない。
|
|
14
|
+
* 時間軸の図 (#3165) は、目盛りと区切りと印の列と節目と拡大の範囲の行を箱より前に書き、物差しの欄の後ろに `[meter: <割合>]` を書く。
|
|
15
|
+
* 時間軸の図の `note` は属性を持てるので、`[` を含む字を `"` で囲む。
|
|
16
|
+
* 段の出典 (#3199) は `say` と `code` の後ろ、段の中で起きることより前に、JSON の並びのまま 1 つずつ `source` の行に書く。
|
|
14
17
|
*/
|
|
15
|
-
import type { Box, Diagram, DiagramEvent, Region } from "./schema";
|
|
16
|
-
import { COPY, FROM, MERGE, ON } from "./words";
|
|
18
|
+
import type { Box, Diagram, DiagramEvent, Region, TimeSpec } from "./schema";
|
|
19
|
+
import { AT, COPY, FROM, MERGE, NOW, ON } from "./words";
|
|
17
20
|
|
|
18
21
|
const quote = (text: string): string => `"${text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
19
22
|
/** 行の終わりか `[` の前に置く名前と文 */
|
|
20
23
|
const name = (text: string): string => (text.includes("[") || text.startsWith('"') ? quote(text) : text);
|
|
21
24
|
/** `:` の前に置く字 (帯の題と、`set` の欄) */
|
|
22
25
|
const key = (text: string): string => (text.includes(":") || text.includes("[") || text.startsWith('"') ? quote(text) : text);
|
|
23
|
-
/** `strip` の行に `,`
|
|
24
|
-
const field = (text: string): string => (text.includes(",") || text.startsWith('"') ? quote(text) : text);
|
|
26
|
+
/** `strip` の行に `,` で並べる欄。時間軸の図の欄は後ろに物差しの属性を書けるので、`[` を含む名前も囲む */
|
|
27
|
+
const field = (text: string, time: boolean): string => (text.includes(",") || text.startsWith('"') || (time && text.includes("[")) ? quote(text) : text);
|
|
25
28
|
/** 属性の値 */
|
|
26
29
|
const value = (text: string): string => (text.includes(",") || text.includes("]") || text.startsWith('"') ? quote(text) : text);
|
|
27
30
|
|
|
@@ -45,23 +48,38 @@ const declareBox = (b: Box): string =>
|
|
|
45
48
|
["note", b.sub],
|
|
46
49
|
["color", b.color],
|
|
47
50
|
["icon", b.icon],
|
|
51
|
+
["link", b.link],
|
|
48
52
|
])}`;
|
|
49
53
|
|
|
50
54
|
/** 線の行の両端と名前 */
|
|
51
55
|
const line = (from: string, to: string, label: string | undefined): string => `${from} -> ${to}${label === undefined ? "" : `: ${name(label)}`}`;
|
|
52
56
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
57
|
+
/** 目盛りの範囲。1 つの目盛りは番号だけを書く */
|
|
58
|
+
const range = (from: number, to: number): string => (from === to ? `${from}` : `${from}-${to}`);
|
|
59
|
+
/** 数の属性の値 */
|
|
60
|
+
const num = (n: number | undefined): string | undefined => (n === undefined ? undefined : `${n}`);
|
|
61
|
+
|
|
62
|
+
/** 段の中の 1 行。`kind` は図の種類。枝分かれの図の線は、送る側の名前の札を書かない時の運ぶ物にする */
|
|
63
|
+
function event(e: DiagramEvent, kind: Diagram["kind"]): string {
|
|
55
64
|
switch (e.type) {
|
|
56
65
|
case "edge": {
|
|
57
|
-
const plain = git ? e.carry.kind === "tag" && e.carry.text === e.from : e.carry.kind === "envelope";
|
|
66
|
+
const plain = kind === "git" ? e.carry.kind === "tag" && e.carry.text === e.from : e.carry.kind === "envelope";
|
|
58
67
|
const carry: [string, string][] = plain ? [] : e.carry.kind === "tag" ? [["tag", e.carry.text]] : [["carry", e.carry.kind]];
|
|
59
|
-
return `${line(e.from, e.to, e.label)}${attrs([...carry, ["side", e.labelSide]])}`;
|
|
68
|
+
return `${line(e.from, e.to, e.label)}${attrs([...carry, ["side", e.labelSide], ["at", num(e.at)], ["into", num(e.into)]])}`;
|
|
60
69
|
}
|
|
61
70
|
case "action":
|
|
62
71
|
return `act ${e.box}: ${e.label}`;
|
|
63
72
|
case "swap":
|
|
64
|
-
return `note ${e.box}: ${e.text}`;
|
|
73
|
+
return kind === "time" ? `note ${e.box}: ${name(e.text)}${attrs([["color", e.color]])}` : `note ${e.box}: ${e.text}`;
|
|
74
|
+
case "now":
|
|
75
|
+
return `${NOW} -> ${e.to}`;
|
|
76
|
+
case "mark":
|
|
77
|
+
return `mark ${e.row} ${range(e.from, e.to)}${attrs([["color", e.color]])}`;
|
|
78
|
+
case "span":
|
|
79
|
+
return `span ${range(e.from, e.to)}: ${name(e.text)}${attrs([
|
|
80
|
+
["shape", e.shape],
|
|
81
|
+
["color", e.color],
|
|
82
|
+
])}`;
|
|
65
83
|
case "strip":
|
|
66
84
|
return `set ${key(e.field)}${e.value === undefined ? "" : `: ${name(e.value)}`}${attrs([["tag", e.tag]])}`;
|
|
67
85
|
case "commit":
|
|
@@ -74,6 +92,23 @@ function event(e: DiagramEvent, git: boolean): string {
|
|
|
74
92
|
}
|
|
75
93
|
}
|
|
76
94
|
|
|
95
|
+
/** 時間軸の図の目盛りと区切りと印の列と節目と拡大の範囲の宣言の塊 */
|
|
96
|
+
function timeBlocks(time: TimeSpec): string[] {
|
|
97
|
+
const head = [
|
|
98
|
+
`scale ${time.scale.unit} ${time.scale.length} ${time.scale.count}${attrs([["from", num(time.scale.from)]])}`,
|
|
99
|
+
...(time.period ? [`period ${time.period.name} ${time.period.length}${attrs([["from", num(time.period.from)]])}`] : []),
|
|
100
|
+
];
|
|
101
|
+
const rows = time.rows.map(
|
|
102
|
+
(r) =>
|
|
103
|
+
`row ${r.id}${shown(r.id, r.name)}${attrs([
|
|
104
|
+
["color", r.color],
|
|
105
|
+
["empty", r.empty && r.empty.length > 0 ? r.empty.join(" ") : undefined],
|
|
106
|
+
])}`,
|
|
107
|
+
);
|
|
108
|
+
const points = (time.points ?? []).map((p) => `point ${p.id} ${AT} ${p.at}`);
|
|
109
|
+
return [head.join("\n"), rows.join("\n"), ...(points.length > 0 ? [points.join("\n")] : []), ...(time.zoom ? [`zoom ${range(time.zoom.from, time.zoom.to)}`] : [])];
|
|
110
|
+
}
|
|
111
|
+
|
|
77
112
|
/** 区画と箱の宣言の塊。塊どうしは空行で区切る */
|
|
78
113
|
function declarations(diagram: Diagram): string[] {
|
|
79
114
|
const regions = diagram.regions ?? [];
|
|
@@ -109,14 +144,30 @@ function declarations(diagram: Diagram): string[] {
|
|
|
109
144
|
|
|
110
145
|
export function printNotation(diagram: Diagram): string {
|
|
111
146
|
const branches = (diagram.git?.branches ?? []).map((b) => `branch ${b.id}${attrs([["note", b.note]])}`);
|
|
112
|
-
const
|
|
113
|
-
|
|
147
|
+
const time = diagram.kind === "time";
|
|
148
|
+
const blocks = [
|
|
149
|
+
`${diagram.kind} ${name(diagram.title)}${attrs([["view", diagram.view]])}`,
|
|
150
|
+
...(branches.length > 0 ? [branches.join("\n")] : []),
|
|
151
|
+
...(diagram.time ? timeBlocks(diagram.time) : []),
|
|
152
|
+
...declarations(diagram),
|
|
153
|
+
];
|
|
154
|
+
if (diagram.strip) {
|
|
155
|
+
const meters = new Map((diagram.strip.meters ?? []).map((m) => [m.field, m.line]));
|
|
156
|
+
const fields = diagram.strip.fields.map((f) => `${field(f, time)}${attrs([["meter", meters.get(f)]])}`);
|
|
157
|
+
blocks.push(`strip ${key(diagram.strip.title)}: ${fields.join(", ")}`);
|
|
158
|
+
}
|
|
114
159
|
if (diagram.state) blocks.push(diagram.state.paths.map((p) => line(p.from, p.to, p.label)).join("\n"));
|
|
115
160
|
for (const step of diagram.steps) {
|
|
116
161
|
const body = step.body.split("\n");
|
|
117
162
|
const say = body.length === 1 ? [` say ${step.body}`] : [" say", ...body.map((line) => (line === "" ? "" : ` ${line}`))];
|
|
118
163
|
blocks.push(
|
|
119
|
-
[
|
|
164
|
+
[
|
|
165
|
+
`step ${step.title}`,
|
|
166
|
+
...say,
|
|
167
|
+
...(step.code === undefined ? [] : [` code ${step.code}`]),
|
|
168
|
+
...(step.sources ?? []).map((s) => ` source ${name(s.name)}${attrs([["url", s.url]])}`),
|
|
169
|
+
...step.events.map((e) => ` ${event(e, diagram.kind)}`),
|
|
170
|
+
].join("\n"),
|
|
120
171
|
);
|
|
121
172
|
}
|
|
122
173
|
return `${blocks.join("\n\n")}\n`;
|
package/src/render/icons.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* 見本帳 (`docs/design/base/engine.js` の `G`) と同じ形を持つ。`block` だけは見本帳が絵を手で描いていたので、ここで足した。
|
|
5
5
|
* `undo` (戻る矢印) と `yen` (円の印) は、注文の試作 (`docs/design/base/scenes/order.js`) が返品と返金に足した形 (#3171)。
|
|
6
6
|
* package の入口からも出し、見本帳の部品「絵」の頁がこの表から使える絵柄の一覧を作る。1 つずつの絵は `iconSvg` が描く (#3172)。
|
|
7
|
+
* `flag` (旗) は、時間軸の図の節目の丸に描く形 (#3165)。ブロックの確定の試作 (`docs/design/base/scenes/finality.js`) が持っていた。
|
|
7
8
|
*/
|
|
8
9
|
export const ICONS: Readonly<Record<string, string>> = {
|
|
9
10
|
app: "M -9 -7 h18 a2 2 0 0 1 2 2 v10 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-10 a2 2 0 0 1 2 -2 z M -11 -2 h22",
|
|
@@ -18,6 +19,7 @@ export const ICONS: Readonly<Record<string, string>> = {
|
|
|
18
19
|
env: "M -8 -5.5 h16 v11 h-16 z M -8 -5.5 l8 6 l8 -6",
|
|
19
20
|
lock: "M -5.5 -1 h11 v8 h-11 z M -3.5 -1 v-3 a3.5 3.5 0 0 1 7 0 v3",
|
|
20
21
|
check: "M -5 0 l3.5 3.5 l6.5 -7",
|
|
22
|
+
flag: "M -4 8 V -8 M -4 -7 H 6 L 3.5 -3.5 L 6 0 H -4",
|
|
21
23
|
x: "M -5 -5 l10 10 M 5 -5 l-10 10",
|
|
22
24
|
chain: "M -1.5 4.5 l-2 2 a3.5 3.5 0 0 1 -5 -5 l3 -3 a3.5 3.5 0 0 1 5 0 M 1.5 -4.5 l2 -2 a3.5 3.5 0 0 1 5 5 l-3 3 a3.5 3.5 0 0 1 -5 0 M -2.5 2.5 l5 -5",
|
|
23
25
|
net: "M -1.3 -4.6 L -5.8 3 M 1.3 -4.6 L 5.8 3 M -4.3 5.5 H 4.3 M -2.2 -7 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M -9.2 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M 4.8 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0",
|
package/src/render/parts.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
type SceneBox,
|
|
17
17
|
type SceneEdge,
|
|
18
18
|
type SceneEnd,
|
|
19
|
+
type SceneField,
|
|
19
20
|
type SceneLabel,
|
|
20
21
|
type ScenePath,
|
|
21
22
|
type SceneRegion,
|
|
@@ -29,7 +30,9 @@ import { ALWAYS, type Ink, type Shown, type Trace } from "./ink";
|
|
|
29
30
|
import type { Frame, Motion } from "./motion";
|
|
30
31
|
|
|
31
32
|
export const esc = (s: string): string => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
32
|
-
|
|
33
|
+
/** 箱の飛び先 (#3199)。飛び先を持つ箱の札を、その飛び先への link で包む */
|
|
34
|
+
export const linkTo = (link: string | undefined, markup: string): string => (link === undefined ? markup : `<a href="${esc(link)}">${markup}</a>`);
|
|
35
|
+
const r1 =(v: number): number => Math.round(v * 100) / 100;
|
|
33
36
|
|
|
34
37
|
/** 色の役を部品へ渡す変数。 */
|
|
35
38
|
export const cs = (k: ColorKey): string => (k === "coin" ? "--c:var(--coin);--ct:var(--coint)" : `--c:var(--c-${k});--ct:var(--t-${k})`);
|
|
@@ -301,23 +304,34 @@ export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false): { ba
|
|
|
301
304
|
};
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
/**
|
|
307
|
+
/**
|
|
308
|
+
* 線の名前の札。その段の間だけ出し、段の終わりまでに消え終わる。時刻の表が `after` を持つ時は、その間だけ札を外した灰の字で薄く残す (#3171)。
|
|
309
|
+
* `again` を持つ時は (止め絵を選んだ図、#3200)、その間に同じ札をもう 1 つ出す。
|
|
310
|
+
*/
|
|
305
311
|
export function label(l: SceneLabel, time: LabelTime, ctx: Ctx): string {
|
|
306
312
|
const ja = l.family === "sans" ? " dg-capj" : "";
|
|
307
313
|
const { radius } = LOOK.label;
|
|
314
|
+
const shown: Shown[] = time.again ? [[time.start, time.end], [time.again.start, time.again.end]] : [[time.start, time.end]];
|
|
308
315
|
// 札の間は札の四角を、薄く残す間は札を外した字の四角を記録する
|
|
309
|
-
ctx.ink.push({ text: l.text, rect: l, shown
|
|
316
|
+
ctx.ink.push({ text: l.text, rect: l, shown, boxed: true });
|
|
310
317
|
if (time.after) ctx.ink.push({ text: l.text, rect: textBox(l.text, l.x + l.w / 2, l.y + l.h / 2 + LOOK.baseline.label, l.family === "sans" ? TYPE.labelJa : TYPE.label, "middle"), shown: [[time.after.start, time.after.end]] });
|
|
311
318
|
const x = r1(l.x + l.w / 2);
|
|
312
319
|
const y = r1(l.y + l.h / 2 + LOOK.baseline.label);
|
|
313
320
|
const past = time.after ? `<g class="dg-cap-past${l.family === "sans" ? " dg-cap-pastj" : ""} dg-a" style="${ctx.m.vis(time.after.start, time.after.end)}"><text x="${x}" y="${y}" text-anchor="middle">${esc(l.text)}</text></g>` : "";
|
|
314
|
-
|
|
321
|
+
const caps = shown.map(([a, b]) => `<g class="dg-cap${ja} dg-a" style="${cs(l.color)};${ctx.m.rise(a, b, true)}"><rect x="${r1(l.x)}" y="${r1(l.y)}" width="${r1(l.w)}" height="${l.h}" rx="${radius}"/><text x="${x}" y="${y}" text-anchor="middle">${esc(l.text)}</text></g>`);
|
|
322
|
+
return `${past}${caps.join("")}`;
|
|
315
323
|
}
|
|
316
324
|
|
|
317
|
-
/**
|
|
318
|
-
export function action(a: SceneAction, at: number, until: number, ctx: Ctx): string {
|
|
319
|
-
|
|
320
|
-
|
|
325
|
+
/** 時系列図の箱の中の処理の札。その段の間だけ生存線の上に出す。`again` を渡すと (止め絵を選んだ図、#3200)、その間に同じ札をもう 1 つ出す。 */
|
|
326
|
+
export function action(a: SceneAction, at: number, until: number, ctx: Ctx, again?: Span): string {
|
|
327
|
+
const shown: Shown[] = again ? [[at, until], [again.start, again.end]] : [[at, until]];
|
|
328
|
+
ctx.ink.push({ text: a.text, rect: a, shown, boxed: true });
|
|
329
|
+
return shown
|
|
330
|
+
.map(
|
|
331
|
+
([from, to]) =>
|
|
332
|
+
`<g class="dg-act dg-a" style="${cs(a.color)};${ctx.m.rise(from, to, true)}"><rect x="${r1(a.x)}" y="${r1(a.y)}" width="${r1(a.w)}" height="${a.h}" rx="${LOOK.action.radius}"/><text x="${r1(a.x + a.w / 2)}" y="${r1(a.y + a.h / 2 + LOOK.baseline.action)}" text-anchor="middle">${esc(a.text)}</text></g>`,
|
|
333
|
+
)
|
|
334
|
+
.join("");
|
|
321
335
|
}
|
|
322
336
|
|
|
323
337
|
function carrierShape(e: SceneEdge, sh: string): string {
|
|
@@ -440,8 +454,9 @@ export interface FieldChange {
|
|
|
440
454
|
/**
|
|
441
455
|
* 中身の帯。`now` を立てると (状態遷移図、#3171)、段の中で変わった値をその段の終わりまで線の色 (今の状態の色) で描き、
|
|
442
456
|
* 欄の名前の横に同じ色の点を置く。帯の通った状態の欄は、`arrivals` が持つ着いた時刻に点を塗る。
|
|
457
|
+
* `meter` を渡すと (時間軸の図、#3165)、物差しの欄は値の字の代わりに `meter` が描く物差しを置く
|
|
443
458
|
*/
|
|
444
|
-
export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: Ctx, now = false, arrivals = new Map<string, number>()): string {
|
|
459
|
+
export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: Ctx, now = false, arrivals = new Map<string, number>(), meter?: (field: SceneField) => string | undefined): string {
|
|
445
460
|
const { m, sh } = ctx;
|
|
446
461
|
const S = LOOK.strip;
|
|
447
462
|
const my = s.y + S.h / 2;
|
|
@@ -457,6 +472,11 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
|
|
|
457
472
|
parts.push(`<line class="dg-sep" x1="${r1(sx)}" y1="${r1(field.y + S.sepInset)}" x2="${r1(sx)}" y2="${r1(field.y + S.h - S.sepInset)}"/>`);
|
|
458
473
|
}
|
|
459
474
|
parts.push(write(ctx.ink, "dg-fl", field.x, field.y + S.nameY, field.name, TYPE.fieldName));
|
|
475
|
+
const gauge = meter?.(field);
|
|
476
|
+
if (gauge !== undefined) {
|
|
477
|
+
parts.push(gauge);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
460
480
|
const list = changes.get(field.name) ?? [];
|
|
461
481
|
const values = list.filter((c) => c.value !== undefined);
|
|
462
482
|
const tags = list.filter((c) => c.tag !== undefined);
|