@cardenelabs/dragon 0.37.0 → 0.40.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.
Files changed (48) hide show
  1. package/README.md +38 -1
  2. package/dist/cli.cjs +2403 -550
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +2408 -555
  5. package/dist/cli.js.map +1 -1
  6. package/dist/export.cjs +2252 -537
  7. package/dist/export.cjs.map +1 -1
  8. package/dist/export.d.cts +3 -1
  9. package/dist/export.d.ts +3 -1
  10. package/dist/export.js +2257 -542
  11. package/dist/export.js.map +1 -1
  12. package/dist/index.cjs +2387 -495
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +11 -154
  15. package/dist/index.d.ts +11 -154
  16. package/dist/index.js +2387 -496
  17. package/dist/index.js.map +1 -1
  18. package/dist/ink-B_7OXxtb.d.cts +360 -0
  19. package/dist/ink-B_7OXxtb.d.ts +360 -0
  20. package/dist/player.global.js +2 -2
  21. package/package.json +1 -1
  22. package/src/cli.ts +9 -0
  23. package/src/export/index.ts +4 -1
  24. package/src/field-messages.ts +8 -0
  25. package/src/figure-text.ts +28 -0
  26. package/src/index.ts +3 -0
  27. package/src/layout/architecture.ts +123 -44
  28. package/src/layout/git.ts +728 -0
  29. package/src/layout/measure.ts +10 -0
  30. package/src/layout/scene.ts +300 -19
  31. package/src/layout/sequence.ts +29 -11
  32. package/src/layout/state.ts +82 -62
  33. package/src/look/values.ts +57 -4
  34. package/src/messages.ts +47 -4
  35. package/src/parser.ts +142 -7
  36. package/src/player.ts +44 -0
  37. package/src/printer.ts +16 -4
  38. package/src/render/git.ts +161 -0
  39. package/src/render/ink.ts +104 -0
  40. package/src/render/parts.ts +103 -36
  41. package/src/render/svg.ts +63 -15
  42. package/src/schema.ts +47 -13
  43. package/src/schemas/diagram.schema.json +75 -8
  44. package/src/schemas/validate-diagram.js +1 -1
  45. package/src/timeline.ts +18 -3
  46. package/src/words.ts +19 -3
  47. package/dist/schema-B2MTRv66.d.cts +0 -133
  48. package/dist/schema-B2MTRv66.d.ts +0 -133
@@ -4,9 +4,11 @@
4
4
  * どの部品も、置き場所は場面 (`layout/scene.ts`) から、いつ見えるかは時刻の表 (`timeline.ts`) から読む。
5
5
  * 色は色の役の変数 (`--c` と `--ct`) だけを渡し、値は色味の表が持つ。
6
6
  */
7
- import { hasWide, textWidth } from "../layout/measure";
7
+ import { hasWide, textBox, textWidth } from "../layout/measure";
8
8
  import {
9
9
  along,
10
+ carrierHalf,
11
+ markText,
10
12
  type Point,
11
13
  pathLength,
12
14
  type SceneAction,
@@ -20,9 +22,10 @@ import {
20
22
  type SceneSide,
21
23
  type SceneStrip,
22
24
  } from "../layout/scene";
23
- import { type ColorKey, EASE, LOOK, MOTION, TYPE } from "../look/values";
25
+ import { type ColorKey, EASE, LOOK, MOTION, type TextStyle, TYPE } from "../look/values";
24
26
  import type { CarrierTime, EdgeTime, LabelTime, Span, Timeline } from "../timeline";
25
27
  import { ICONS } from "./icons";
28
+ import { ALWAYS, type Ink, type Shown, type Trace } from "./ink";
26
29
  import type { Frame, Motion } from "./motion";
27
30
 
28
31
  export const esc = (s: string): string => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -85,6 +88,19 @@ export interface Ctx {
85
88
  sh: string;
86
89
  /** 最後の段の終わり */
87
90
  end: number;
91
+ /** 描いた字の記録 (#3175) */
92
+ ink: Ink[];
93
+ /** 描いた線の記録 (#3175)。札を持たない字を横切る線を数える */
94
+ traces: Trace[];
95
+ }
96
+
97
+ /**
98
+ * 字を 1 つ描き、字の四角と見えている間を `ink` に記録する (#3175)。`ink` を渡さない字 (寄って追う窓の頭の列) は記録しない。
99
+ * `anchor` を渡さない字は左端を `x` に置き、`text-anchor` を書かない
100
+ */
101
+ export function write(ink: Ink[] | undefined, cls: string, x: number, y: number, text: string, style: TextStyle, shown: Shown[] = ALWAYS, anchor?: "start" | "middle"): string {
102
+ ink?.push({ text, rect: textBox(text, x, y, style, anchor), shown });
103
+ return `<text class="${cls}" x="${r1(x)}" y="${r1(y)}"${anchor ? ` text-anchor="${anchor}"` : ""}>${esc(text)}</text>`;
88
104
  }
89
105
 
90
106
  /** 時刻の範囲 `[[a, b], ...]` の間だけ出る。 */
@@ -107,11 +123,11 @@ export function activeKf(ctx: Ctx, on: number[]): string {
107
123
  return rangeKf(ctx.m, ranges);
108
124
  }
109
125
 
110
- export function band(region: SceneRegion): string {
126
+ export function band(region: SceneRegion, ink: Ink[]): string {
111
127
  const { radius, icon, iconRadius, iconScale, nameY, line } = LOOK.region;
112
128
  const { x, y } = region.header;
113
- const lines = region.lines.map((t, k) => `<text class="dg-bz" x="${r1(x)}" y="${r1(region.y + nameY + k * line)}">${esc(t)}</text>`).join("");
114
- const note = region.note ? `<text class="dg-bx" x="${r1(x)}" y="${r1(region.y + nameY + region.lines.length * line + 1)}">${esc(region.note)}</text>` : "";
129
+ const lines = region.lines.map((t, k) => write(ink, "dg-bz", x, region.y + nameY + k * line, t, TYPE.regionName)).join("");
130
+ const note = region.note ? write(ink, "dg-bx", x, region.y + nameY + region.lines.length * line + 1, region.note, TYPE.regionNote) : "";
115
131
  const mark = region.icon && ICONS[region.icon] ? `<rect class="dg-bi" x="${r1(x)}" y="${r1(y)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(region.icon, x + icon / 2, y + icon / 2, iconScale)}` : "";
116
132
  return `<g style="${cs(region.color)}"><rect class="dg-band" x="${r1(region.x + 0.5)}" y="${r1(region.y + 0.5)}" width="${r1(region.w - 1)}" height="${r1(region.h - 1)}" rx="${radius}"/>${mark}${lines}${note}</g>`;
117
133
  }
@@ -120,14 +136,15 @@ export function band(region: SceneRegion): string {
120
136
  export type SubChange = [number, string, string];
121
137
 
122
138
  /** 箱の下の小さな字。基準線を `y` に置き、起きたことに合わせて書き換わる。 */
123
- function subLines(box: SceneBox, m: Motion, changes: SubChange[], y: number): string {
139
+ function subLines(box: SceneBox, m: Motion, changes: SubChange[], y: number, ink?: Ink[]): string {
124
140
  const seq: SubChange[] = [[0, box.sub ?? "", "dg-ss"], ...changes];
125
141
  return seq
126
142
  .map(([t, text, cls], k) => {
127
143
  const next = seq[k + 1]?.[0];
128
144
  const anim = k === 0 ? (next === undefined ? "" : m.until(next - MOTION.untilFade)) : next === undefined ? m.rise(t) : m.rise(t, next - MOTION.untilFade);
129
145
  if (text === "") return "";
130
- return `<g${anim ? ` class="dg-a" style="${anim}"` : ""}><text class="${cls}" x="${r1(box.cx)}" y="${r1(y)}" text-anchor="middle">${esc(text)}</text></g>`;
146
+ const shown: Shown[] = [[k === 0 ? 0 : t, next === undefined ? Number.POSITIVE_INFINITY : next - MOTION.untilFade]];
147
+ return `<g${anim ? ` class="dg-a" style="${anim}"` : ""}>${write(ink, cls, box.cx, y, text, cls === "dg-ss" ? TYPE.boxSub : TYPE.boxSubStrong, shown, "middle")}</g>`;
131
148
  })
132
149
  .join("");
133
150
  }
@@ -144,15 +161,20 @@ function cardFrame(box: SceneBox, ctx: Ctx, act: string | undefined, y: number,
144
161
  */
145
162
  export function card(box: SceneBox, ctx: Ctx, on: number[], changes: SubChange[], lit?: Span[]): string {
146
163
  const { icon, iconRadius, iconScale, iconY, nameY, subY } = LOOK.box;
147
- const subs = subLines(box, ctx.m, changes, box.cy + subY);
164
+ const subs = subLines(box, ctx.m, changes, box.cy + subY, ctx.ink);
148
165
  const act = lit ? (lit.length > 0 ? rangeKf(ctx.m, lit.map((s) => [s.start, s.end])) : undefined) : on.length > 0 ? activeKf(ctx, on) : undefined;
149
- const mark =
150
- box.icon && ICONS[box.icon]
151
- ? `<rect class="dg-ic" x="${r1(box.cx - icon / 2)}" y="${r1(box.cy + iconY - icon / 2)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, box.cx, box.cy + iconY, iconScale)}`
152
- : "";
166
+ // 置き場を持つ箱は絵柄を左へ寄せ、右に点線の枠を初めから見せる (#3176)
167
+ const ix = box.iconX ?? box.cx;
168
+ const slot = box.slot ? `<rect class="dg-slot" x="${r1(box.slot.x)}" y="${r1(box.slot.y)}" width="${r1(box.slot.w)}" height="${r1(box.slot.h)}" rx="${LOOK.slot.radius}"/>` : "";
169
+ let mark = "";
170
+ if (box.icon && ICONS[box.icon]) {
171
+ const rect = { x: ix - icon / 2, y: box.cy + iconY - icon / 2, w: icon, h: icon };
172
+ ctx.ink.push({ text: `${box.name} の絵柄`, rect, shown: ALWAYS, boxed: true, part: { kind: "icon", box: box.name } });
173
+ mark = `<rect class="dg-ic" x="${r1(rect.x)}" y="${r1(rect.y)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, ix, box.cy + iconY, iconScale)}`;
174
+ }
153
175
  return (
154
176
  `<g style="${cs(box.color)}">${cardFrame(box, ctx, act, box.y, box.h)}` +
155
- `${mark}<text class="dg-sn" x="${r1(box.cx)}" y="${r1(box.cy + nameY)}" text-anchor="middle">${esc(box.name)}</text>${subs}</g>`
177
+ `${slot}${mark}${write(ctx.ink, "dg-sn", box.cx, box.cy + nameY, box.name, TYPE.boxName, ALWAYS, "middle")}${subs}</g>`
156
178
  );
157
179
  }
158
180
 
@@ -168,17 +190,17 @@ export function headCard(box: SceneBox, ctx: Ctx, on: number[], changes: SubChan
168
190
  }
169
191
 
170
192
  /** 状態遷移図の、どの段も辿り着かない状態。点線の縁の札で、絵柄を左に、名前と下の字を右に並べる (#3171)。光らず、字も書き換わらない */
171
- export function ghostCard(box: SceneBox): string {
193
+ export function ghostCard(box: SceneBox, ink: Ink[]): string {
172
194
  const { icon, iconRadius, iconScale, radius } = LOOK.box;
173
195
  const G = LOOK.state.ghost;
174
196
  const ix = box.x + G.pad + icon / 2;
175
197
  const tx = box.x + G.pad + icon + G.gap;
176
198
  const mark = box.icon && ICONS[box.icon] ? `<rect class="dg-ic" x="${r1(ix - icon / 2)}" y="${r1(box.cy - icon / 2)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, ix, box.cy, iconScale)}` : "";
177
199
  const nameY = box.sub ? G.nameY : LOOK.baseline.mark;
178
- const sub = box.sub ? `<text class="dg-ss" x="${r1(tx)}" y="${r1(box.cy + G.subY)}" text-anchor="start">${esc(box.sub)}</text>` : "";
200
+ const sub = box.sub ? write(ink, "dg-ss", tx, box.cy + G.subY, box.sub, TYPE.boxSub, ALWAYS, "start") : "";
179
201
  return (
180
202
  `<g data-ghost="${esc(box.id)}" style="${cs(box.color)}"><rect class="dg-ghost" x="${r1(box.x)}" y="${r1(box.y)}" width="${r1(box.w)}" height="${box.h}" rx="${radius}"/>` +
181
- `${mark}<text class="dg-sn" x="${r1(tx)}" y="${r1(box.cy + nameY)}" text-anchor="start">${esc(box.name)}</text>${sub}</g>`
203
+ `${mark}${write(ink, "dg-sn", tx, box.cy + nameY, box.name, TYPE.boxName, ALWAYS, "start")}${sub}</g>`
182
204
  );
183
205
  }
184
206
 
@@ -191,28 +213,31 @@ export function doneMark(box: SceneBox, at: number, ctx: Ctx): string {
191
213
  }
192
214
 
193
215
  /** 状態遷移図の通らない道。点線で道と向きだけを見せ、運ぶ物を走らせない */
194
- export function path(p: ScenePath, color: ColorKey): string {
216
+ export function path(p: ScenePath, color: ColorKey, ink: Ink[], traces: Trace[]): string {
217
+ traces.push({ from: p.from, to: p.to, points: p.points, shown: ALWAYS });
218
+ const sans = p.label?.family === "sans";
195
219
  const label = p.label
196
- ? `<text class="dg-path-t${p.label.family === "sans" ? " dg-path-tj" : ""}" x="${r1(p.label.x + LOOK.label.padX)}" y="${r1(p.label.y + p.label.h / 2 + LOOK.baseline.label)}">${esc(p.label.text)}</text>`
220
+ ? write(ink, `dg-path-t${sans ? " dg-path-tj" : ""}`, p.label.x + LOOK.label.padX, p.label.y + p.label.h / 2 + LOOK.baseline.label, p.label.text, sans ? TYPE.labelJa : TYPE.label)
197
221
  : "";
198
222
  return `<g data-path="${esc(`${p.from}->${p.to}`)}" style="${cs(color)}"><path class="dg-path" d="${pathOf(p.points)}"/><path class="dg-path-h" d="${arrowHead(p.points)}"/>${label}</g>`;
199
223
  }
200
224
 
201
225
  /** 状態遷移図の脇道の囲み。左上に囲みの名前を、その下に添え書きを 1 行ずつ置く */
202
- export function side(s: SceneSide, color: ColorKey): string {
226
+ export function side(s: SceneSide, color: ColorKey, ink: Ink[]): string {
203
227
  const { pad } = LOOK.state.side;
204
228
  const title = s.y + pad + TYPE.regionName.size;
205
- const notes = s.notes.map((note, k) => `<text class="dg-side-n" x="${r1(s.x + pad)}" y="${r1(title + LOOK.region.line * (k + 1))}">${esc(note)}</text>`).join("");
229
+ const notes = s.notes.map((note, k) => write(ink, "dg-side-n", s.x + pad, title + LOOK.region.line * (k + 1), note, TYPE.regionNote)).join("");
206
230
  return (
207
231
  `<g style="${cs(color)}"><rect class="dg-side" x="${r1(s.x + 0.5)}" y="${r1(s.y + 0.5)}" width="${r1(s.w - 1)}" height="${r1(s.h - 1)}" rx="${LOOK.region.radius}"/>` +
208
- `<text class="dg-side-t" x="${r1(s.x + pad)}" y="${r1(title)}">${esc(s.title)}</text>${notes}</g>`
232
+ `${write(ink, "dg-side-t", s.x + pad, title, s.title, TYPE.regionName)}${notes}</g>`
209
233
  );
210
234
  }
211
235
 
212
236
  /** 状態遷移図の始まりと終わりの印。始まりは塗った丸、終わりは輪の中の丸で、脇道の中の終わりは点線の輪 */
213
- export function endMark(e: SceneEnd, color: ColorKey): string {
237
+ export function endMark(e: SceneEnd, color: ColorKey, ink: Ink[]): string {
214
238
  const { end } = LOOK.state;
215
- const text = e.text === "" ? "" : `<text class="dg-mark" x="${r1(e.x + LOOK.state.text)}" y="${r1(e.y + LOOK.baseline.mark)}">${esc(e.text)}</text>`;
239
+ const at = markText(e);
240
+ const text = e.text === "" ? "" : write(ink, "dg-mark", at[0], at[1], e.text, TYPE.regionNote);
216
241
  const x = r1(e.x);
217
242
  const y = r1(e.y);
218
243
  if (e.kind === "start") return `<g data-end="start"><circle class="dg-start" cx="${x}" cy="${y}" r="${e.r}"/>${text}</g>`;
@@ -231,6 +256,8 @@ export function lifeline(x: number, y1: number, y2: number): string {
231
256
  */
232
257
  export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false): { base: string; lit: string } {
233
258
  const { m } = ctx;
259
+ // 点線の道は初めから最後まで見えている
260
+ ctx.traces.push({ from: e.from, to: e.to, points: e.points, shown: ALWAYS });
234
261
  const d = pathOf(e.points);
235
262
  const head = arrowHead(e.points);
236
263
  const { start: a, drawn: b, end } = time;
@@ -278,6 +305,9 @@ export function edge(e: SceneEdge, time: EdgeTime, ctx: Ctx, past = false): { ba
278
305
  export function label(l: SceneLabel, time: LabelTime, ctx: Ctx): string {
279
306
  const ja = l.family === "sans" ? " dg-capj" : "";
280
307
  const { radius } = LOOK.label;
308
+ // 札の間は札の四角を、薄く残す間は札を外した字の四角を記録する
309
+ ctx.ink.push({ text: l.text, rect: l, shown: [[time.start, time.end]], boxed: true });
310
+ 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]] });
281
311
  const x = r1(l.x + l.w / 2);
282
312
  const y = r1(l.y + l.h / 2 + LOOK.baseline.label);
283
313
  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>` : "";
@@ -286,6 +316,7 @@ export function label(l: SceneLabel, time: LabelTime, ctx: Ctx): string {
286
316
 
287
317
  /** 時系列図の箱の中の処理の札。その段の間だけ生存線の上に出す。 */
288
318
  export function action(a: SceneAction, at: number, until: number, ctx: Ctx): string {
319
+ ctx.ink.push({ text: a.text, rect: a, shown: [[at, until]], boxed: true });
289
320
  return `<g class="dg-act dg-a" style="${cs(a.color)};${ctx.m.rise(at, until, 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>`;
290
321
  }
291
322
 
@@ -303,15 +334,19 @@ function carrierShape(e: SceneEdge, sh: string): string {
303
334
 
304
335
  const easeInOut = (t: number): number => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
305
336
 
306
- /** 運ぶ物。線の上を走り、着いた先 (`settle`) へ寄って、次の同じ主役が出発するまで留まる。 */
337
+ /**
338
+ * 運ぶ物。走り出す前は待つ点 (`wait`) に居て、そこから線の始まりへ出て線の上を走り、
339
+ * 着いた先 (`settle`) へ寄って、次の同じ主役が出発するまで留まる。
340
+ */
307
341
  export function carrier(e: SceneEdge, time: CarrierTime, ctx: Ctx): string {
308
342
  const { m } = ctx;
309
343
  const n = LOOK.carrier.samples;
310
- const length = pathLength(e.points);
344
+ const route = e.wait ? [e.wait, ...e.points] : e.points;
345
+ const length = pathLength(route);
311
346
  const { depart: a, arrive: b, start: from, end: gone } = time;
312
347
  const path: [number, number, number][] = [];
313
348
  for (let k = 0; k <= n; k++) {
314
- const [x, y] = along(e.points, easeInOut(k / n) * length);
349
+ const [x, y] = along(route, easeInOut(k / n) * length);
315
350
  path.push([a + ((b - a) * k) / n, x, y]);
316
351
  }
317
352
  const first = path[0] as [number, number, number];
@@ -320,6 +355,14 @@ export function carrier(e: SceneEdge, time: CarrierTime, ctx: Ctx): string {
320
355
  const pts: [number, number, number][] = [[0, first[1], first[2]], ...path];
321
356
  if (e.settle) pts.push([Math.min(b + 0.3, Math.max(gone, b + 0.01)), rest[0], rest[1]]);
322
357
  pts.push([gone, rest[0], rest[1]], [m.total, rest[0], rest[1]]);
358
+ // 運ぶ物は、走り出しを待つ間と着いて留まる間を記録する。走っている途中は数えない (#3175, #3176)
359
+ const [hx, hy] = carrierHalf(e.carry);
360
+ const name = e.carry.kind === "tag" ? e.carry.text : e.carry.kind === "coin" ? "硬貨" : "封筒";
361
+ // 札は書き手の字なので部品の種類を持たず、硬貨と封筒は知らせる文の言葉で呼ぶ (#3184)
362
+ const part: Pick<Ink, "part"> = e.carry.kind === "tag" ? {} : { part: { kind: e.carry.kind === "coin" ? "coin" : "envelope" } };
363
+ const box = (p: Point) => ({ x: p[0] - hx, y: p[1] - hy, w: hx * 2, h: hy * 2 });
364
+ if (a > from) ctx.ink.push({ text: name, rect: box([first[1], first[2]]), shown: [[from, a]], boxed: true, ...part });
365
+ ctx.ink.push({ text: name, rect: box(rest), shown: [[b, gone]], boxed: true, ...part });
323
366
  // 次の運ぶ物と入れ替わる時は、重なって 2 つに見えないよう素早く消す
324
367
  const fade = gone < m.last ? 0.05 : 0.18;
325
368
  return `<g class="dg-a" style="${m.move(pts, m.blink(from + 0.02, gone, fade))}">${carrierShape(e, ctx.sh)}</g>`;
@@ -328,6 +371,8 @@ export function carrier(e: SceneEdge, time: CarrierTime, ctx: Ctx): string {
328
371
  /**
329
372
  * 段の番号。まだ来ていない段は出さず、今の段は塗り、済んだ段は縁取りに変えて番号を読めるまま残す。
330
373
  * `grey` を立てると (状態遷移図、#3171)、済んだ段の縁取りを線と同じ灰にする。
374
+ * 同じ所に後の段の番号が来る時 (`until`) は、その段が始まる時に素早く消して数字を入れ替える (#3184)。
375
+ * 見えていない間は `visibility` も隠し、同じ所に重ねたまだ来ていない段の番号が、押した時に前の段の番号を遮らないようにする。
331
376
  */
332
377
  export function badge(b: SceneBadge, ctx: Ctx, grey = false): string {
333
378
  const { m } = ctx;
@@ -335,15 +380,33 @@ export function badge(b: SceneBadge, ctx: Ctx, grey = false): string {
335
380
  const a = span.start;
336
381
  const e = span.end;
337
382
  const { r, ring: rr } = LOOK.badge;
383
+ const shown = { visibility: "visible" };
384
+ const hidden = { visibility: "hidden" };
385
+ const swap = b.until === undefined ? undefined : (ctx.t.steps[b.until] as Span).start;
386
+ // 次の段がすぐ入れ替える時は、塗った番号のまま素早く消し、縁取りを出さない
387
+ const next = swap !== undefined && swap <= e + 1e-6;
338
388
  const fill = m.kf([
339
- [0, { opacity: 0, transform: "scale(.5)" }],
340
- [a, { opacity: 0, transform: "scale(.5)" }, EASE.pop],
341
- [a + 0.35, { opacity: 1, transform: "scale(1)" }],
342
- [e, { opacity: 1, transform: "scale(1)" }, EASE.inOut],
343
- [e + 0.4, { opacity: 0, transform: "scale(1)" }],
344
- [m.total, { opacity: 0, transform: "scale(.5)" }],
389
+ [0, { opacity: 0, transform: "scale(.5)", ...hidden }],
390
+ [a, { opacity: 0, transform: "scale(.5)", ...hidden }, EASE.pop],
391
+ [a + 0.35, { opacity: 1, transform: "scale(1)", ...shown }],
392
+ [e, { opacity: 1, transform: "scale(1)", ...shown }, EASE.inOut],
393
+ [e + (next ? MOTION.untilFade : 0.4), { opacity: 0, transform: "scale(1)", ...hidden }],
394
+ [m.total, { opacity: 0, transform: "scale(.5)", ...hidden }],
345
395
  ]);
346
- const past = m.kf([[0, { opacity: 0 }], [e, { opacity: 0 }, EASE.inOut], [e + 0.4, { opacity: 1 }], [m.last, { opacity: 1 }, EASE.inOut], [m.total, { opacity: 0 }]]);
396
+ const pastEnd = swap ?? m.last;
397
+ const past = next
398
+ ? m.kf([
399
+ [0, { opacity: 0, ...hidden }],
400
+ [m.total, { opacity: 0, ...hidden }],
401
+ ])
402
+ : m.kf([
403
+ [0, { opacity: 0, ...hidden }],
404
+ [e, { opacity: 0, ...hidden }, EASE.inOut],
405
+ [e + 0.4, { opacity: 1, ...shown }],
406
+ [pastEnd, { opacity: 1, ...shown }, EASE.inOut],
407
+ ...(swap === undefined ? [] : [[swap + MOTION.untilFade, { opacity: 0, ...hidden }] as Frame]),
408
+ [m.total, { opacity: 0, ...hidden }],
409
+ ]);
347
410
  const ring = m.kf([
348
411
  [0, { opacity: 0, transform: "scale(1)" }],
349
412
  [a + 0.05, { opacity: 0, transform: "scale(1)" }],
@@ -355,6 +418,7 @@ export function badge(b: SceneBadge, ctx: Ctx, grey = false): string {
355
418
  const y = r1(b.y);
356
419
  const ty = r1(b.y + LOOK.baseline.badge);
357
420
  const no = b.step + 1;
421
+ ctx.ink.push({ text: String(no), rect: { x: b.x - r, y: b.y - r, w: r * 2, h: r * 2 }, shown: [[a, pastEnd]], boxed: true, badge: true });
358
422
  return (
359
423
  `<g class="dg-bd" data-step="${b.step}" style="${cs(b.color)}"><circle class="dg-bdr dg-popc dg-a" cx="${x}" cy="${y}" r="${rr}" style="${ring}"/>` +
360
424
  `<g class="dg-a" style="${past}"><circle class="${grey ? "dg-bdp-g" : "dg-bdp"}" cx="${x}" cy="${y}" r="${rr}"/><text class="${grey ? "dg-bdpt-g" : "dg-bdpt"}" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g>` +
@@ -384,7 +448,7 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
384
448
  const parts = [
385
449
  `<rect class="dg-strip" x="${r1(s.x + 0.5)}" y="${r1(s.y + 0.5)}" width="${r1(s.w - 1)}" height="${r1(s.h - 1)}" rx="${LOOK.region.radius}" ${sh}/>`,
386
450
  `<g style="${cs("slate")}"><rect class="dg-bi" x="${r1(s.x + S.pad)}" y="${r1(my - S.icon / 2)}" width="${S.icon}" height="${S.icon}" rx="${LOOK.box.iconRadius}"/>${glyph("env", s.x + S.pad + S.icon / 2, my, 0.78)}</g>`,
387
- `<text class="dg-sh" x="${r1(s.x + S.titleX)}" y="${r1(my + LOOK.baseline.stripTitle)}">${esc(s.title)}</text>`,
451
+ write(ctx.ink, "dg-sh", s.x + S.titleX, my + LOOK.baseline.stripTitle, s.title, TYPE.stripTitle),
388
452
  ];
389
453
  s.fields.forEach((field, i) => {
390
454
  const prev = s.fields[i - 1];
@@ -392,7 +456,7 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
392
456
  const sx = field.x - S.fieldGap / 2;
393
457
  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)}"/>`);
394
458
  }
395
- parts.push(`<text class="dg-fl" x="${r1(field.x)}" y="${r1(field.y + S.nameY)}">${esc(field.name)}</text>`);
459
+ parts.push(write(ctx.ink, "dg-fl", field.x, field.y + S.nameY, field.name, TYPE.fieldName));
396
460
  const list = changes.get(field.name) ?? [];
397
461
  const values = list.filter((c) => c.value !== undefined);
398
462
  const tags = list.filter((c) => c.tag !== undefined);
@@ -400,6 +464,8 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
400
464
  const next = values[k + 1]?.at;
401
465
  const value = c.value as string;
402
466
  const cls = hasWide(value) ? "dg-fvj" : "dg-fv";
467
+ // 値は、次の値が来るまで (色を付けた間と墨に戻した間を合わせて) 1 件で記録する
468
+ ctx.ink.push({ text: value, rect: textBox(value, field.x, field.y + S.valueY, hasWide(value) ? TYPE.fieldValueJa : TYPE.fieldValue), shown: [[c.at, next === undefined ? Number.POSITIVE_INFINITY : next - MOTION.untilFade]] });
403
469
  const textOf = (c: string): string => `<text class="${c}" x="${r1(field.x)}" y="${r1(field.y + S.valueY)}">${esc(value)}</text>`;
404
470
  const text = textOf(cls);
405
471
  if (!now) {
@@ -421,6 +487,7 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
421
487
  const x = field.x + (shown ? textWidth(shown, hasWide(shown) ? TYPE.fieldValueJa : TYPE.fieldValue) + S.tagGap : 0);
422
488
  const w = textWidth(tag, TYPE.tag) + S.tagPadX * 2;
423
489
  const y = field.y + S.valueY - S.tagH / 2 - LOOK.baseline.tag;
490
+ ctx.ink.push({ text: tag, rect: { x, y, w, h: S.tagH }, shown: [[c.at, next === undefined ? Number.POSITIVE_INFINITY : next - MOTION.untilFade]], boxed: true });
424
491
  parts.push(
425
492
  `<g class="dg-tg dg-popc dg-a" style="${cs(c.color)};${next === undefined ? m.pop(c.at) : m.pop(c.at, next - MOTION.untilFade)}"><rect x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${S.tagH}" rx="${S.tagH / 2}"/><text x="${r1(x + w / 2)}" y="${r1(y + S.tagH / 2 + LOOK.baseline.tag)}" text-anchor="middle">${esc(tag)}</text></g>`,
426
493
  );
@@ -433,7 +500,7 @@ export function strip(s: SceneStrip, changes: Map<string, FieldChange[]>, ctx: C
433
500
  const sx = t.x - S.fieldGap / 2;
434
501
  parts.push(`<line class="dg-sep" x1="${r1(sx)}" y1="${r1(t.y + S.sepInset)}" x2="${r1(sx)}" y2="${r1(t.y + S.h - S.sepInset)}"/>`);
435
502
  }
436
- parts.push(`<text class="dg-fl" x="${r1(t.x)}" y="${r1(t.y + S.nameY)}">${esc(t.title)}</text>`);
503
+ parts.push(write(ctx.ink, "dg-fl", t.x, t.y + S.nameY, t.title, TYPE.fieldName));
437
504
  const dy = t.y + S.valueY - TYPE.fieldValue.size / 3;
438
505
  t.states.forEach((state, k) => {
439
506
  const cx = r1(t.x + S.trail.r + k * S.trail.step);
package/src/render/svg.ts CHANGED
@@ -7,15 +7,16 @@
7
7
  */
8
8
  import { FIGURE_TEXT } from "../figure-text";
9
9
  import { layoutArchitecture } from "../layout/architecture";
10
+ import { isGitLayout, layoutGit } from "../layout/git";
10
11
  import { textWidth } from "../layout/measure";
11
- import type { Layout, Rect } from "../layout/scene";
12
+ import type { Layout, Rect, SceneLabel } from "../layout/scene";
12
13
  import { layoutSequence } from "../layout/sequence";
13
14
  import { layoutState } from "../layout/state";
14
15
  import { FONTS } from "../look/fonts";
15
16
  import { type ColorKey, EASE, FONT_VARS, LOOK, MOTION, type Palette, paletteVars, resolvePalette, type TextStyle, type Theme, TYPE } from "../look/values";
16
17
  import { readDiagram } from "../version";
17
18
  import type { Diagram, ViewMode } from "../schema";
18
- import { buildTimeline, type Span, type Timeline } from "../timeline";
19
+ import { buildTimeline, type LabelTime, type Span, type Timeline } from "../timeline";
19
20
  import type { NotationLang } from "../words";
20
21
  import {
21
22
  action,
@@ -39,6 +40,8 @@ import {
39
40
  strip,
40
41
  type SubChange,
41
42
  } from "./parts";
43
+ import { drawGit } from "./git";
44
+ import { findOverlaps, type Ink, type Overlap, type Trace } from "./ink";
42
45
  import { Motion } from "./motion";
43
46
 
44
47
  export interface RenderOptions {
@@ -59,6 +62,8 @@ export interface Rendered {
59
62
  layout: Layout;
60
63
  timeline: Timeline;
61
64
  diagram: Diagram;
65
+ /** 段ごとの止め絵で、同時に見えている字どうしの重なりと、線が札を持たない字を横切る所 (#3175)。重なりが無ければ空 */
66
+ overlaps: Overlap[];
62
67
  }
63
68
 
64
69
  const font = (t: TextStyle): string => `font:${t.weight} ${t.size}px var(--${t.family})`;
@@ -82,6 +87,7 @@ const PART_CSS = [
82
87
  `.dg-halo{fill:none;stroke:var(--c);stroke-width:${S.halo};stroke-opacity:.16}`,
83
88
  `.dg-on{fill:none;stroke:var(--c);stroke-width:${S.on}}`,
84
89
  `.dg-ic{fill:${mix(X.icon)}}`,
90
+ `.dg-slot{fill:none;stroke:${mix(X.slot, "transparent")};stroke-width:${S.slot};stroke-dasharray:3 3}`,
85
91
  `.dg-gl{fill:none;stroke:var(--c);stroke-width:${S.glyph};stroke-linecap:round;stroke-linejoin:round}`,
86
92
  `.dg-sn{${font(TYPE.boxName)};fill:var(--ink)}`,
87
93
  `.dg-ss{${font(TYPE.boxSub)};fill:var(--mute)}`,
@@ -98,7 +104,7 @@ const PART_CSS = [
98
104
  ".dg-bd{cursor:pointer}",
99
105
  ".dg-bdf{fill:var(--c)}",
100
106
  `.dg-bdft{${font(TYPE.badge)};fill:var(--on-c)}`,
101
- `.dg-bdr{fill:none;stroke:var(--c);stroke-width:${S.badgeRing}}`,
107
+ `.dg-bdr{fill:none;stroke:var(--c);stroke-width:${S.badgeRing};pointer-events:none}`,
102
108
  `.dg-bdp{fill:${mix(X.badgePast)};stroke:${mix(X.badgePastEdge, "transparent")};stroke-width:${S.hair}}`,
103
109
  `.dg-bdpt{${font(TYPE.badge)};fill:var(--ct)}`,
104
110
  `.dg-bdp-g{fill:var(--surf);stroke:${PAST};stroke-width:${S.hair}}`,
@@ -144,6 +150,14 @@ const PART_CSS = [
144
150
  `.dg-mark{${font(TYPE.regionNote)};fill:var(--mute)}`,
145
151
  `.dg-done{fill:var(--ink);stroke:var(--surf);stroke-width:${S.done}}`,
146
152
  `.dg-done-ck{fill:none;stroke:var(--surf);stroke-width:${S.glyph};stroke-linecap:round;stroke-linejoin:round}`,
153
+ `.dg-git-l{fill:none;stroke:var(--c);stroke-width:${S.git};stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1 2}`,
154
+ `.dg-git-cp{fill:none;stroke:var(--c);stroke-width:${S.gitOrphan};stroke-linecap:round;stroke-dasharray:3 3;stroke-opacity:.7}`,
155
+ `.dg-git-c{fill:var(--surf);stroke:var(--c);stroke-width:${S.git}}`,
156
+ `.dg-git-id{${font(TYPE.gitId)};fill:var(--ct)}`,
157
+ `.dg-git-h{${font(TYPE.gitHash)};fill:var(--mute)}`,
158
+ `.dg-git-n{${font(TYPE.gitNote)};fill:var(--ink2)}`,
159
+ `.dg-git-old{fill:var(--surf);stroke:var(--c);stroke-width:${S.gitOrphan};stroke-dasharray:3 3;stroke-opacity:.6}`,
160
+ `.dg-git-oldl{${font(TYPE.gitId)};fill:var(--ct);opacity:.55}`,
147
161
  ".dg-vp-bg{fill:var(--bg)}",
148
162
  ".dg-vp-frame{fill:none;stroke:var(--hair)}",
149
163
  ".dg-hd-bg{fill:var(--bg)}",
@@ -247,29 +261,45 @@ export interface FollowFrame {
247
261
  lang: NotationLang;
248
262
  }
249
263
 
250
- /** 図を描く。`follow` を渡すと、寄って追う窓と隅の全体図で描く。 */
251
- export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, palette: Palette, theme: Theme, follow?: FollowFrame): string {
264
+ /** 同じ線の同じ名前を後の段が置く時は、薄く残した名前をその段が始まるまでで消す (#3184) */
265
+ function fadeBefore(l: SceneLabel, time: LabelTime, steps: Span[]): LabelTime {
266
+ if (l.until === undefined || !time.after) return time;
267
+ const cut = (steps[l.until] as Span).start;
268
+ const { after, ...rest } = time;
269
+ return cut > after.start ? { ...rest, after: { start: after.start, end: Math.min(after.end, cut) } } : rest;
270
+ }
271
+
272
+ /** 図を描く。`follow` を渡すと、寄って追う窓と隅の全体図で描く。`ink` を渡すと、描いた字の四角と見えている間をそこへ記録する (#3175)。 */
273
+ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, palette: Palette, theme: Theme, follow?: FollowFrame, ink: Ink[] = [], traces: Trace[] = []): string {
252
274
  // 札の言葉で全体図の地の幅が変わりうるので、同じ頁に置いた別の言葉の図と名前を分ける
253
275
  const id = nameOf(`${JSON.stringify(diagram)}|${palette.id}|${theme}|${follow ? `${follow.width}|${follow.lang}` : ""}`);
254
276
  const m = new Motion(`dg${id}`, timeline.total, timeline.last);
255
- const ctx: Ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: (timeline.steps[timeline.steps.length - 1] as Span).end };
277
+ const ctx: Ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: (timeline.steps[timeline.steps.length - 1] as Span).end, ink, traces };
256
278
  const on = involved(diagram);
257
279
  // 時系列図の処理は生存線の上の札に出し、他の図の種類は箱の下の字に出す
258
280
  const subs = subChanges(diagram, timeline, layout.kind !== "sequence");
259
281
 
260
282
  const L = { band: [] as string[], base: [] as string[], lit: [] as string[], node: [] as string[], badge: [] as string[], top: [] as string[] };
261
- for (const region of layout.regions) L.band.push(band(region));
283
+ for (const region of layout.regions) L.band.push(band(region, ink));
262
284
  const ghostColor = layout.boxes.find((b) => b.ghost)?.color ?? "slate";
263
- if (layout.side) L.band.push(side(layout.side, ghostColor));
285
+ if (layout.side) L.band.push(side(layout.side, ghostColor, ink));
264
286
  // 脇道へ入る道は脇道の状態の色、それ以外の道は送る側の色で描く
265
287
  const boxColor = (id: string, ghost?: boolean): ColorKey | undefined => layout.boxes.find((b) => b.id === id && (ghost === undefined || b.ghost === ghost))?.color;
266
- for (const p of layout.paths) L.base.push(path(p, boxColor(p.to, true) ?? boxColor(p.from) ?? ghostColor));
267
- for (const e of layout.ends) L.node.push(endMark(e, ghostColor));
288
+ for (const p of layout.paths) L.base.push(path(p, boxColor(p.to, true) ?? boxColor(p.from) ?? ghostColor, ink, traces));
289
+ for (const e of layout.ends) L.node.push(endMark(e, ghostColor, ink));
268
290
  // 状態遷移図は、段で変わった値を今の状態の色で描き、帯の通った状態の点を着いた時刻に塗る (#3171)
269
291
  const isState = layout.kind === "state";
270
292
  const arrivals = new Map((timeline.states ?? []).flatMap((s) => (s.lit[0] ? [[s.box, s.lit[0].start] as [string, number]] : [])));
271
293
  if (layout.strip) L.band.push(strip(layout.strip, fieldChanges(diagram, timeline, layout), ctx, isState, arrivals));
272
294
  for (const line of layout.lifelines) L.base.push(lifeline(line.x, line.y1, line.y2));
295
+ // 枝分かれの図の線と commit と札は、枝分かれの図を描く部品が描く (#3164)
296
+ if (isGitLayout(layout)) {
297
+ const git = drawGit(layout, diagram, timeline, ctx);
298
+ L.base.push(git.links);
299
+ L.lit.push(git.lines);
300
+ L.node.push(git.commits);
301
+ L.top.push(git.tags);
302
+ }
273
303
  for (const e of layout.edges) {
274
304
  const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
275
305
  if (!time) continue;
@@ -280,7 +310,7 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
280
310
  const states = new Map((timeline.states ?? []).map((s) => [s.box, s]));
281
311
  for (const box of layout.boxes) {
282
312
  if (box.ghost) {
283
- L.node.push(ghostCard(box));
313
+ L.node.push(ghostCard(box, ink));
284
314
  continue;
285
315
  }
286
316
  const state = states.get(box.id);
@@ -290,7 +320,7 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
290
320
  for (const b of layout.badges) L.badge.push(badge(b, ctx, isState));
291
321
  for (const l of layout.labels) {
292
322
  const time = timeline.labels.find((t) => t.step === l.step && t.event === l.event);
293
- if (time) L.top.push(label(l, time, ctx));
323
+ if (time) L.top.push(label(l, fadeBefore(l, time, timeline.steps), ctx));
294
324
  }
295
325
  for (const a of layout.actions) {
296
326
  const time = timeline.events.find((t) => t.step === a.step && t.event === a.event);
@@ -489,12 +519,29 @@ export function renderDiagram(input: unknown, options: RenderOptions = {}): Rend
489
519
  const read = readDiagram(input, { lang });
490
520
  if (!read.ok) throw new Error(FIGURE_TEXT[lang].cannotDraw(read.errors.map((e) => `${e.pointer} ${e.message}`).join(" / ")));
491
521
  const diagram = read.diagram;
522
+ const layout =
523
+ diagram.kind === "sequence"
524
+ ? layoutSequence(diagram)
525
+ : diagram.kind === "state"
526
+ ? layoutState(diagram, lang)
527
+ : diagram.kind === "git"
528
+ ? layoutGit(diagram)
529
+ : layoutArchitecture(diagram);
530
+ return renderLayout(diagram, layout, buildTimeline(diagram), options);
531
+ }
532
+
533
+ /**
534
+ * 置き場所を決めた図を描き、描いた字の重なりを数える (#3175)。`renderDiagram` が原本を読んで置き場所を決めた後に呼ぶ。
535
+ * 重なりは、字を描く部品が記録した字だけから数えるので、描く所が位置を決める字 (箱の名前) も対象に入る
536
+ */
537
+ export function renderLayout(diagram: Diagram, layout: Layout, timeline: Timeline, options: RenderOptions = {}): Rendered {
492
538
  const palette = resolvePalette(options.palette);
493
539
  const theme: Theme = options.theme === "dark" ? "dark" : "light";
494
- const layout = diagram.kind === "sequence" ? layoutSequence(diagram) : diagram.kind === "state" ? layoutState(diagram, lang) : layoutArchitecture(diagram);
495
- const timeline = buildTimeline(diagram);
540
+ const ink: Ink[] = [];
541
+ const traces: Trace[] = [];
542
+ const svg = drawSvg(diagram, layout, timeline, palette, theme, undefined, ink, traces);
496
543
  return {
497
- svg: drawSvg(diagram, layout, timeline, palette, theme),
544
+ svg,
498
545
  palette: palette.id,
499
546
  theme,
500
547
  ...(diagram.view ? { view: diagram.view } : {}),
@@ -502,5 +549,6 @@ export function renderDiagram(input: unknown, options: RenderOptions = {}): Rend
502
549
  layout,
503
550
  timeline,
504
551
  diagram,
552
+ overlaps: findOverlaps(ink, timeline.stills, traces),
505
553
  };
506
554
  }
package/src/schema.ts CHANGED
@@ -46,7 +46,29 @@ export type DiagramEvent =
46
46
  | { type: "edge"; from: string; to: string; label?: string; carry: Carry; labelSide?: LabelSide }
47
47
  | { type: "action"; box: string; label: string }
48
48
  | { type: "swap"; box: string; text: string }
49
- | { type: "strip"; field: string; value?: string; tag?: string };
49
+ | { type: "strip"; field: string; value?: string; tag?: string }
50
+ | GitCommit
51
+ | { type: "branch"; branch: string; from: string };
52
+
53
+ /**
54
+ * 枝分かれの図 (#3164) の commit を積む出来事。積んだ枝の札と、その枝を指す HEAD が新しい commit へ進む。
55
+ * 当て直し (`copy`) は枝の札を動かさず、merge commit (`merge`) は取り込む枝の先端も親に持つ
56
+ */
57
+ export interface GitCommit {
58
+ type: "commit";
59
+ id: string;
60
+ branch: string;
61
+ copy?: string;
62
+ merge?: string;
63
+ hash?: string;
64
+ note?: string;
65
+ }
66
+
67
+ /** 枝分かれの図の枝。上から宣言した順に帯を並べる */
68
+ export interface GitBranch {
69
+ id: string;
70
+ note?: string;
71
+ }
50
72
 
51
73
  /** 状態遷移図の、最初の段より前に書いた移れる道。`from` に `start`、`to` に `finish` を書ける */
52
74
  export interface StatePath {
@@ -64,7 +86,7 @@ export interface Step {
64
86
 
65
87
  export interface Diagram {
66
88
  version: number;
67
- kind: "sequence" | "architecture" | "state";
89
+ kind: "sequence" | "architecture" | "state" | "git";
68
90
  title: string;
69
91
  view?: ViewMode;
70
92
  regions?: Region[];
@@ -73,6 +95,7 @@ export interface Diagram {
73
95
  steps: Step[];
74
96
  sequence?: { lifelines: string[] };
75
97
  state?: { paths: StatePath[] };
98
+ git?: { branches: GitBranch[] };
76
99
  }
77
100
 
78
101
  export interface FieldError {
@@ -89,26 +112,32 @@ export interface CheckOptions {
89
112
  }
90
113
 
91
114
  /** 段の中で起きることの種類。schema の event の `discriminator` が見る `type` の値 */
92
- const EVENT_TYPES = ["edge", "action", "swap", "strip"] as const satisfies readonly DiagramEvent["type"][];
115
+ const EVENT_TYPES = ["edge", "action", "swap", "strip", "commit", "branch"] as const satisfies readonly DiagramEvent["type"][];
93
116
 
94
117
  /**
95
- * schema の書けない組み合わせ (`not: { required: [欄] }`) の欄。根の 3 か所は決まりの場所で引き、運ぶ物は誤りの場所の最後の欄で引く。
96
- * 根の `sequence` と運ぶ物の `text` は ajv の誤りでは決まりの場所 (`#/else/not`) が同じになるので、誤りの場所でも分ける
118
+ * その種類の図に書けない根の欄を書いた時の決まりの場所 (#3164)。根の欄に `not: {}` を置く決まり (`absent`) を指し、
119
+ * 誤りの場所の最後の欄が書いた欄になる。種類の欄は、その欄と同じ名前の図の種類だけが書ける
97
120
  */
98
- const ROOT_NOT_ALLOWED: Record<string, Allowed> = {
99
- "#/else/not": { field: "sequence", kind: "sequence" },
100
- "#/then/not": { field: "state", kind: "state" },
101
- "#/else/else/not": { field: "state", kind: "state" },
102
- };
121
+ const ABSENT = "#/definitions/absent/not";
122
+ /** 種類の欄でない根の欄を書ける図の種類。区画は枝分かれの図に書けない */
123
+ const ABSENT_KINDS: Record<string, string> = { regions: "sequence / architecture / state" };
124
+ /** 運ぶ物の書けない組み合わせ (`not: { required: [欄] }`)。誤りの場所の最後の欄で引く */
103
125
  const NOT_ALLOWED: Record<string, Allowed> = {
104
126
  carry: { field: "text", kind: "tag" },
105
127
  };
106
128
 
107
129
  /** 状態遷移図の箱の名札に予約の名前を書いた時の決まりの場所 */
108
130
  const RESERVED_ID = /\/boxes\/items\/properties\/id\/not$/u;
131
+ /** 枝分かれの図でない図に、枝分かれの図だけの出来事を書いた時の決まりの場所 (#3164) */
132
+ const GIT_EVENT = /\/events\/items\/properties\/type\/not$/u;
133
+ /** 枝分かれの図だけが書ける出来事 */
134
+ const GIT_EVENTS = ["commit", "branch"] as const satisfies readonly DiagramEvent["type"][];
109
135
 
110
136
  const escape = (key: string): string => key.replaceAll("~", "~0").replaceAll("/", "~1");
111
137
 
138
+ /** commit の hash の決まり (`^[0-9a-f]{<最小>,<最大>}$`)。字の数の幅を読む */
139
+ const HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
140
+
112
141
  /** `^[^…]+$` の形の決まりから書けない字を読む。違う形の決まりでは `undefined` */
113
142
  function forbiddenOf(pattern: string): Forbidden | undefined {
114
143
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -140,7 +169,10 @@ function toFieldError(error: ErrorObject, errors: readonly ErrorObject[], m: Fie
140
169
  }
141
170
  case "not": {
142
171
  if (RESERVED_ID.test(error.schemaPath)) return { pointer: at, message: m.reserved(STATE_ENDS) };
143
- const allowed = at === "" ? ROOT_NOT_ALLOWED[error.schemaPath] : NOT_ALLOWED[at.slice(at.lastIndexOf("/") + 1)];
172
+ if (GIT_EVENT.test(error.schemaPath)) return { pointer: at, message: m.kindOnly(GIT_EVENTS, "git") };
173
+ const last = at.slice(at.lastIndexOf("/") + 1);
174
+ if (error.schemaPath === ABSENT) return { pointer: at, message: m.not({ field: last, kind: ABSENT_KINDS[last] ?? last }) };
175
+ const allowed = NOT_ALLOWED[last];
144
176
  return { pointer: allowed ? `${at}/${allowed.field}` : at, message: m.not(allowed) };
145
177
  }
146
178
  case "anyOf": {
@@ -158,8 +190,10 @@ function toFieldError(error: ErrorObject, errors: readonly ErrorObject[], m: Fie
158
190
  return { pointer: at, message: m.type(String(params.type)) };
159
191
  case "minLength":
160
192
  return { pointer: at, message: m.minLength(Number(params.limit)) };
161
- case "pattern":
162
- return { pointer: at, message: m.pattern(forbiddenOf(String(params.pattern))) };
193
+ case "pattern": {
194
+ const hex = HEX.exec(String(params.pattern));
195
+ return { pointer: at, message: hex ? m.hex(Number(hex[1]), Number(hex[2])) : m.pattern(forbiddenOf(String(params.pattern))) };
196
+ }
163
197
  case "minItems":
164
198
  return { pointer: at, message: m.minItems(Number(params.limit)) };
165
199
  case "minimum":