@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
package/src/timeline.ts CHANGED
@@ -7,6 +7,9 @@
7
7
  * 線の名前はその段の間だけ出し、同じ段に何本あっても同時に見えるのは 2 つまでにする。
8
8
  * 状態遷移図では、段が終わった後も線の名前を最後の段まで薄く残す (#3171)。薄い名前は 2 つまでの数に入れない。
9
9
  * 状態遷移図では、主役の運ぶ物が乗っている状態を光らせ、運ぶ物が出た状態には少し後に済んだ印を出す (#3163)。
10
+ * 枝分かれの図では、commit を積む出来事と枝を切る出来事も線と同じ間で引く (#3164)。
11
+ * 札を動かす線が運ぶ枝の札は運ぶ物の表に載せない。札は同じ時刻にいくつも出ていて、どの札も主役ではないので、
12
+ * 枝分かれの図を描く部品が札ごとに動かす。線に書いた運ぶ物 (`tag` と `carry`) だけを表に載せる。
10
13
  */
11
14
  import { MOTION } from "./look/values";
12
15
  import type { Diagram } from "./schema";
@@ -18,7 +21,7 @@ export interface Span {
18
21
  end: number;
19
22
  }
20
23
 
21
- /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。 */
24
+ /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。枝分かれの図では commit を積む出来事と枝を切る出来事も持つ */
22
25
  export interface EdgeTime extends Span {
23
26
  step: number;
24
27
  event: number;
@@ -85,7 +88,16 @@ function plan(step: Diagram["steps"][number]): Planned {
85
88
  let arrived: number | undefined;
86
89
  let changes = 0;
87
90
  step.events.forEach((event, e) => {
88
- if (event.type === "edge") {
91
+ // 枝分かれの図の commit を積む出来事と枝を切る出来事は、親から引く線と同じ間で引く
92
+ if (event.type === "commit" || event.type === "branch") {
93
+ const a = cursor;
94
+ const b = a + MOTION.draw;
95
+ out.edges.push({ event: e, a, b, carries: false, coin: false, named: false });
96
+ cursor = a + MOTION.stagger;
97
+ arrived = b;
98
+ changes = 0;
99
+ out.busy = Math.max(out.busy, b);
100
+ } else if (event.type === "edge") {
89
101
  const carries = event.carry.kind !== "none";
90
102
  const a = cursor;
91
103
  const b = a + (carries ? MOTION.drawCarry : MOTION.draw);
@@ -132,7 +144,10 @@ export function buildTimeline(diagram: Diagram): Timeline {
132
144
  for (const edge of p.edges) {
133
145
  const a = span.start + edge.a;
134
146
  edges.push({ step: s, event: edge.event, start: a, drawn: span.start + edge.b, end: span.end });
135
- if (edge.carries) departures.push({ step: s, event: edge.event, who: edge.coin ? "coin" : "main", a, b: span.start + edge.b });
147
+ // 枝分かれの図の、札を書かない線が運ぶ札は、枝分かれの図を描く部品が札ごとに動かす
148
+ const event = diagram.steps[s]?.events[edge.event];
149
+ const own = diagram.kind === "git" && event?.type === "edge" && event.carry.kind === "tag" && event.carry.text === event.from;
150
+ if (edge.carries && !own) departures.push({ step: s, event: edge.event, who: edge.coin ? "coin" : "main", a, b: span.start + edge.b });
136
151
  if (edge.named) named.push({ step: s, event: edge.event, start: a + MOTION.labelDelay, end: span.end });
137
152
  }
138
153
  // 3 つ目の名前が出る時に 1 つ目を消す
package/src/words.ts CHANGED
@@ -16,7 +16,7 @@ export type NotationLang = "ja" | "en";
16
16
  const keys = <K extends string>(table: Record<K, true>): K[] => Object.keys(table) as K[];
17
17
 
18
18
  /** 図の種類。最初の行の頭の語 */
19
- export const KINDS = keys<Diagram["kind"]>({ sequence: true, architecture: true, state: true });
19
+ export const KINDS = keys<Diagram["kind"]>({ sequence: true, architecture: true, state: true, git: true });
20
20
 
21
21
  /**
22
22
  * 状態遷移図の始まりと終わりの印の名前 (#3163)。線の送る側に `start`、受ける側に `finish` を書き、
@@ -25,13 +25,27 @@ export const KINDS = keys<Diagram["kind"]>({ sequence: true, architecture: true,
25
25
  export const STATE_ENDS = ["start", "finish"] as const;
26
26
  export type StateEnd = (typeof STATE_ENDS)[number];
27
27
 
28
- /** 最初の行より後の行の頭の語。線の行だけは箱の名札から始まる */
29
- export const HEADS = ["group", "end", "box", "strip", "step", "say", "code", "act", "note", "set"] as const;
28
+ /**
29
+ * 最初の行より後の行の頭の語。線の行だけは箱の名札から始まる。
30
+ * `branch` と `commit` は枝分かれの図 (`git`) だけが書ける (#3164)
31
+ */
32
+ export const HEADS = ["group", "end", "box", "strip", "step", "say", "code", "act", "note", "set", "branch", "commit"] as const;
30
33
  type Head = (typeof HEADS)[number];
31
34
 
32
35
  /** 箱と区画の名札の後ろに、見せる名前を続ける語 (`box <名札> as <名前>`) */
33
36
  export const AS = "as";
34
37
 
38
+ /** 枝分かれの図 (#3164) の `commit` の行で、積む枝、当て直しの元、取り込む枝を続ける語 (`commit <名札> on <枝> copy <commit>`) */
39
+ export const ON = "on";
40
+ export const COPY = "copy";
41
+ export const MERGE = "merge";
42
+ /** 枝分かれの図で枝を切る行の、枝の後ろに切る commit を続ける語 (`<枝> from <commit>`) */
43
+ export const FROM = "from";
44
+ /** 枝分かれの図で今いる場所を指す札の名前。枝と commit と箱の名札に使えない */
45
+ export const HEAD = "HEAD";
46
+ /** 枝分かれの図の行の中の語のうち、行の頭の語でも属性でもない語。見本帳の部品が受け持つ語に数える (`on` は commit の行に必ず書くので数えない) */
47
+ export const GIT_WORDS = [FROM, COPY, MERGE] as const;
48
+
35
49
  /** 行ごとに書ける属性の鍵 */
36
50
  export const ATTRS = {
37
51
  diagram: ["view"],
@@ -39,6 +53,8 @@ export const ATTRS = {
39
53
  box: ["note", "color", "icon"],
40
54
  edge: ["carry", "tag", "side"],
41
55
  set: ["tag"],
56
+ branch: ["note"],
57
+ commit: ["hash", "note"],
42
58
  } as const;
43
59
 
44
60
  /** `carry` に書ける運ぶ物。封筒は書かない時、札は `tag` で書く */
@@ -1,133 +0,0 @@
1
- type Theme = "light" | "dark";
2
- interface Palette {
3
- id: string;
4
- name: string;
5
- note: string;
6
- light: Record<string, string>;
7
- dark: Record<string, string>;
8
- }
9
- /** 色味を指定しない時と、知らない名前を渡した時に使う色味。 */
10
- declare const DEFAULT_PALETTE = "paper";
11
- declare const PALETTES: Readonly<Record<string, Palette>>;
12
- /** 名前から色味を引く。指定が無いか、知らない名前 (外した墨と朱の `ink` を含む) なら紙と墨。 */
13
- declare function resolvePalette(id?: string): Palette;
14
- /** 区画や箱を分ける色の役。灰 (slate) と硬貨 (coin) は分類の色として順に配らない。 */
15
- declare const COLOR_ORDER: readonly ["blue", "amber", "green", "violet", "rose"];
16
- type ColorKey = (typeof COLOR_ORDER)[number] | "slate" | "coin";
17
- /** 見せ方を決める字の大きさ。全体を枠に収めた時の箱の名前がこれを下回ると寄って追う。 */
18
- declare const READABLE_PX = 10.5;
19
-
20
- /**
21
- * dragon記法の語 (#3137)。
22
- *
23
- * 行の種類は行の頭の英語の語で決まり、属性は `[<鍵>: <値>]` で書く。
24
- * 語は英語だけで、原本の JSON が使う名前に揃え、記法と JSON で覚える語を 1 組にする。
25
- *
26
- * 言葉の型 (`NotationLang`) は、誤りの文と図の中の字の言葉を選ぶために持つ。
27
- * 語が英語だけなので、記法の file から言葉は決めず、呼ぶ側が渡す。
28
- *
29
- * 型が欠けを止める。原本の JSON の値 (図の種類、運ぶ物、見せ方、名前の側) に語が無い時は、型の検査が落ちる。
30
- */
31
-
32
- type NotationLang = "ja" | "en";
33
-
34
- type Color = "blue" | "amber" | "green" | "violet" | "rose" | "slate" | "coin";
35
- interface Region {
36
- id: string;
37
- name: string;
38
- note?: string;
39
- color?: Color;
40
- icon?: string;
41
- }
42
- interface Box {
43
- id: string;
44
- name: string;
45
- sub?: string;
46
- color?: Color;
47
- icon?: string;
48
- region?: string;
49
- }
50
- type Carry = {
51
- kind: "envelope";
52
- } | {
53
- kind: "tag";
54
- text: string;
55
- } | {
56
- kind: "coin";
57
- } | {
58
- kind: "none";
59
- };
60
- type LabelSide = "above" | "below" | "left" | "right";
61
- /** 見せ方。`fixed` は全体を止めて中だけ動かし、`follow` は寄って動かし全体図で今どこかを示す。 */
62
- type ViewMode = "fixed" | "follow";
63
- type DiagramEvent = {
64
- type: "edge";
65
- from: string;
66
- to: string;
67
- label?: string;
68
- carry: Carry;
69
- labelSide?: LabelSide;
70
- } | {
71
- type: "action";
72
- box: string;
73
- label: string;
74
- } | {
75
- type: "swap";
76
- box: string;
77
- text: string;
78
- } | {
79
- type: "strip";
80
- field: string;
81
- value?: string;
82
- tag?: string;
83
- };
84
- /** 状態遷移図の、最初の段より前に書いた移れる道。`from` に `start`、`to` に `finish` を書ける */
85
- interface StatePath {
86
- from: string;
87
- to: string;
88
- label?: string;
89
- }
90
- interface Step {
91
- title: string;
92
- body: string;
93
- code?: string;
94
- events: DiagramEvent[];
95
- }
96
- interface Diagram {
97
- version: number;
98
- kind: "sequence" | "architecture" | "state";
99
- title: string;
100
- view?: ViewMode;
101
- regions?: Region[];
102
- boxes: Box[];
103
- strip?: {
104
- title: string;
105
- fields: string[];
106
- };
107
- steps: Step[];
108
- sequence?: {
109
- lifelines: string[];
110
- };
111
- state?: {
112
- paths: StatePath[];
113
- };
114
- }
115
- interface FieldError {
116
- /** 誤った欄の場所 (JSON Pointer) */
117
- pointer: string;
118
- message: string;
119
- }
120
- type Checked = {
121
- ok: true;
122
- } | {
123
- ok: false;
124
- errors: FieldError[];
125
- };
126
- interface CheckOptions {
127
- /** 誤りの文の言葉。渡さなければ日本語 */
128
- lang?: NotationLang;
129
- }
130
- /** 原本の JSON を検査する。版が道具より新しいかは見ない (`readDiagram` が見る)。 */
131
- declare function validateDiagram(input: unknown, options?: CheckOptions): Checked;
132
-
133
- export { type Box as B, type CheckOptions as C, type Diagram as D, type FieldError as F, type LabelSide as L, type NotationLang as N, PALETTES as P, READABLE_PX as R, type StatePath as S, type Theme as T, type ViewMode as V, type ColorKey as a, type Carry as b, type Checked as c, type Color as d, DEFAULT_PALETTE as e, type DiagramEvent as f, type Palette as g, type Region as h, type Step as i, resolvePalette as r, validateDiagram as v };
@@ -1,133 +0,0 @@
1
- type Theme = "light" | "dark";
2
- interface Palette {
3
- id: string;
4
- name: string;
5
- note: string;
6
- light: Record<string, string>;
7
- dark: Record<string, string>;
8
- }
9
- /** 色味を指定しない時と、知らない名前を渡した時に使う色味。 */
10
- declare const DEFAULT_PALETTE = "paper";
11
- declare const PALETTES: Readonly<Record<string, Palette>>;
12
- /** 名前から色味を引く。指定が無いか、知らない名前 (外した墨と朱の `ink` を含む) なら紙と墨。 */
13
- declare function resolvePalette(id?: string): Palette;
14
- /** 区画や箱を分ける色の役。灰 (slate) と硬貨 (coin) は分類の色として順に配らない。 */
15
- declare const COLOR_ORDER: readonly ["blue", "amber", "green", "violet", "rose"];
16
- type ColorKey = (typeof COLOR_ORDER)[number] | "slate" | "coin";
17
- /** 見せ方を決める字の大きさ。全体を枠に収めた時の箱の名前がこれを下回ると寄って追う。 */
18
- declare const READABLE_PX = 10.5;
19
-
20
- /**
21
- * dragon記法の語 (#3137)。
22
- *
23
- * 行の種類は行の頭の英語の語で決まり、属性は `[<鍵>: <値>]` で書く。
24
- * 語は英語だけで、原本の JSON が使う名前に揃え、記法と JSON で覚える語を 1 組にする。
25
- *
26
- * 言葉の型 (`NotationLang`) は、誤りの文と図の中の字の言葉を選ぶために持つ。
27
- * 語が英語だけなので、記法の file から言葉は決めず、呼ぶ側が渡す。
28
- *
29
- * 型が欠けを止める。原本の JSON の値 (図の種類、運ぶ物、見せ方、名前の側) に語が無い時は、型の検査が落ちる。
30
- */
31
-
32
- type NotationLang = "ja" | "en";
33
-
34
- type Color = "blue" | "amber" | "green" | "violet" | "rose" | "slate" | "coin";
35
- interface Region {
36
- id: string;
37
- name: string;
38
- note?: string;
39
- color?: Color;
40
- icon?: string;
41
- }
42
- interface Box {
43
- id: string;
44
- name: string;
45
- sub?: string;
46
- color?: Color;
47
- icon?: string;
48
- region?: string;
49
- }
50
- type Carry = {
51
- kind: "envelope";
52
- } | {
53
- kind: "tag";
54
- text: string;
55
- } | {
56
- kind: "coin";
57
- } | {
58
- kind: "none";
59
- };
60
- type LabelSide = "above" | "below" | "left" | "right";
61
- /** 見せ方。`fixed` は全体を止めて中だけ動かし、`follow` は寄って動かし全体図で今どこかを示す。 */
62
- type ViewMode = "fixed" | "follow";
63
- type DiagramEvent = {
64
- type: "edge";
65
- from: string;
66
- to: string;
67
- label?: string;
68
- carry: Carry;
69
- labelSide?: LabelSide;
70
- } | {
71
- type: "action";
72
- box: string;
73
- label: string;
74
- } | {
75
- type: "swap";
76
- box: string;
77
- text: string;
78
- } | {
79
- type: "strip";
80
- field: string;
81
- value?: string;
82
- tag?: string;
83
- };
84
- /** 状態遷移図の、最初の段より前に書いた移れる道。`from` に `start`、`to` に `finish` を書ける */
85
- interface StatePath {
86
- from: string;
87
- to: string;
88
- label?: string;
89
- }
90
- interface Step {
91
- title: string;
92
- body: string;
93
- code?: string;
94
- events: DiagramEvent[];
95
- }
96
- interface Diagram {
97
- version: number;
98
- kind: "sequence" | "architecture" | "state";
99
- title: string;
100
- view?: ViewMode;
101
- regions?: Region[];
102
- boxes: Box[];
103
- strip?: {
104
- title: string;
105
- fields: string[];
106
- };
107
- steps: Step[];
108
- sequence?: {
109
- lifelines: string[];
110
- };
111
- state?: {
112
- paths: StatePath[];
113
- };
114
- }
115
- interface FieldError {
116
- /** 誤った欄の場所 (JSON Pointer) */
117
- pointer: string;
118
- message: string;
119
- }
120
- type Checked = {
121
- ok: true;
122
- } | {
123
- ok: false;
124
- errors: FieldError[];
125
- };
126
- interface CheckOptions {
127
- /** 誤りの文の言葉。渡さなければ日本語 */
128
- lang?: NotationLang;
129
- }
130
- /** 原本の JSON を検査する。版が道具より新しいかは見ない (`readDiagram` が見る)。 */
131
- declare function validateDiagram(input: unknown, options?: CheckOptions): Checked;
132
-
133
- export { type Box as B, type CheckOptions as C, type Diagram as D, type FieldError as F, type LabelSide as L, type NotationLang as N, PALETTES as P, READABLE_PX as R, type StatePath as S, type Theme as T, type ViewMode as V, type ColorKey as a, type Carry as b, type Checked as c, type Color as d, DEFAULT_PALETTE as e, type DiagramEvent as f, type Palette as g, type Region as h, type Step as i, resolvePalette as r, validateDiagram as v };