@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/dist/index.d.cts CHANGED
@@ -1,18 +1,5 @@
1
- import { N as NotationLang, D as Diagram, F as FieldError, C as CheckOptions, a as ColorKey, b as Carry, T as Theme, V as ViewMode } from './schema-B2MTRv66.cjs';
2
- export { B as Box, c as Checked, d as Color, e as DEFAULT_PALETTE, f as DiagramEvent, L as LabelSide, P as PALETTES, g as Palette, R as READABLE_PX, h as Region, S as StatePath, i as Step, r as resolvePalette, v as validateDiagram } from './schema-B2MTRv66.cjs';
3
-
4
- /**
5
- * 図が使う 2 つの字。どちらも package の依存として同梱する。
6
- *
7
- * 描いた SVG は字をこの 2 つの名前でしか名指さない。端末の字の名前を持たないので、
8
- * 同梱した字が読み込まれていない時に、端末の字へ黙って落ちて幅が変わることが無い。
9
- * 頁に字を読み込むのは `@cardenelabs/dragon/fonts` の入口 (`load-fonts.ts`) が持つ。
10
- */
11
- declare const FONTS: {
12
- readonly sans: "Noto Sans JP Variable";
13
- readonly mono: "JetBrains Mono Variable";
14
- };
15
- type Family = keyof typeof FONTS;
1
+ import { N as NotationLang, D as Diagram, F as FieldError, C as CheckOptions, T as Theme, V as ViewMode, L as Layout, O as Overlap, R as Rect } from './ink-B_7OXxtb.cjs';
2
+ export { B as Box, a as Carry, b as Checked, c as Color, d as ColorKey, e as DEFAULT_PALETTE, f as DiagramEvent, g as FONTS, h as Family, G as GitBranch, i as GitCommit, I as InkPart, j as LabelSide, k as OverlapSpot, P as PALETTES, l as Palette, m as Point, n as READABLE_PX, o as Region, S as SceneAction, p as SceneBadge, q as SceneBox, r as SceneEdge, s as SceneEnd, t as SceneField, u as SceneLabel, v as SceneLifeline, w as ScenePath, x as SceneRegion, y as SceneSide, z as SceneStrip, A as SceneTrail, E as StatePath, H as Step, J as describeOverlap, K as resolvePalette, M as validateDiagram } from './ink-B_7OXxtb.cjs';
16
3
 
17
4
  /**
18
5
  * Markdown の中の dragon の囲み (```dragon) を、囲みごとに取り出す。
@@ -58,6 +45,7 @@ declare function parseNotation(notation: string, options?: ParseOptions): Parsed
58
45
  * 箱は JSON の並びのまま書き、同じ区画の箱が続く所を 1 つの `group … end` にする。
59
46
  * 区画の箱が飛び飛びの時は同じ `group` を開き直す。区画の並びが箱の現れる順と違う時と、
60
47
  * 箱の無い区画がある時は、先に全ての区画を中の無い `group … end` で宣言してから開き直す。
48
+ * 枝分かれの図 (#3164) は、枝の `branch` の行を箱より前に書き、札を動かす線の運ぶ物が送る側の名前の札なら書かない。
61
49
  */
62
50
 
63
51
  declare function printNotation(diagram: Diagram): string;
@@ -86,149 +74,12 @@ declare function readDiagram(input: unknown, options?: CheckOptions): Read;
86
74
  */
87
75
  declare function migrateFile(path: string): Promise<Migrated>;
88
76
 
89
- type Point = [number, number];
90
- interface Rect {
91
- x: number;
92
- y: number;
93
- w: number;
94
- h: number;
95
- }
96
- interface SceneBox extends Rect {
97
- id: string;
98
- name: string;
99
- sub?: string;
100
- icon?: string;
101
- color: ColorKey;
102
- cx: number;
103
- cy: number;
104
- /** 状態遷移図で、どの段も辿り着かない状態。点線の箱で脇道の囲みに描く */
105
- ghost?: boolean;
106
- }
107
- interface SceneRegion extends Rect {
108
- id: string;
109
- /** 名前を折り返した行 */
110
- lines: string[];
111
- note?: string;
112
- icon?: string;
113
- color: ColorKey;
114
- /** 名前と印が占める所 */
115
- header: Rect;
116
- }
117
- /** 線。`step` と `event` は原本の `steps[step].events[event]` を指す。 */
118
- interface SceneEdge {
119
- step: number;
120
- event: number;
121
- from: string;
122
- to: string;
123
- points: Point[];
124
- color: ColorKey;
125
- carry: Carry;
126
- /** 着いた運ぶ物が留まる点。無ければ線の終わり */
127
- settle?: Point;
128
- }
129
- interface SceneLabel extends Rect {
130
- step: number;
131
- event: number;
132
- text: string;
133
- family: Family;
134
- color: ColorKey;
135
- }
136
- /** 状態遷移図の、最初の段より前に書いてどの段にも出ない線。点線で描き、運ぶ物を走らせない */
137
- interface ScenePath {
138
- from: string;
139
- to: string;
140
- points: Point[];
141
- label?: Rect & {
142
- text: string;
143
- family: Family;
144
- };
145
- }
146
- /** 状態遷移図の始まりと終わりの印。`ghost` は脇道の中の終わりの印 */
147
- interface SceneEnd {
148
- kind: "start" | "finish";
149
- x: number;
150
- y: number;
151
- r: number;
152
- ghost: boolean;
153
- /** 印の右に添える字 */
154
- text: string;
155
- /** 終わりの印へ線を引く状態 */
156
- box?: string;
157
- }
158
- /** 状態遷移図の脇道の囲み。`title` と `notes` は囲みの左上に置く字 */
159
- interface SceneSide extends Rect {
160
- title: string;
161
- /** 囲みの名前の下に 1 行ずつ置く添え書き */
162
- notes: string[];
163
- }
164
- /** 時系列図の箱の中の処理。生存線の上に札で出す。 */
165
- interface SceneAction extends Rect {
166
- step: number;
167
- event: number;
168
- box: string;
169
- text: string;
170
- color: ColorKey;
171
- }
172
- interface SceneBadge {
173
- step: number;
174
- x: number;
175
- y: number;
176
- color: ColorKey;
177
- }
178
- interface SceneLifeline {
179
- id: string;
180
- x: number;
181
- y1: number;
182
- y2: number;
183
- }
184
- interface SceneField {
185
- name: string;
186
- x: number;
187
- y: number;
188
- w: number;
189
- }
190
- /** 状態遷移図の帯の最後の欄。段が辿り着く順に状態を点で並べ、着いた状態を塗る (#3171) */
191
- interface SceneTrail {
192
- title: string;
193
- states: {
194
- box: string;
195
- color: ColorKey;
196
- }[];
197
- x: number;
198
- y: number;
199
- w: number;
200
- }
201
- interface SceneStrip extends Rect {
202
- title: string;
203
- fields: SceneField[];
204
- trail?: SceneTrail;
205
- }
206
- interface Layout {
207
- kind: Diagram["kind"];
208
- width: number;
209
- height: number;
210
- regions: SceneRegion[];
211
- boxes: SceneBox[];
212
- lifelines: SceneLifeline[];
213
- edges: SceneEdge[];
214
- labels: SceneLabel[];
215
- actions: SceneAction[];
216
- badges: SceneBadge[];
217
- strip?: SceneStrip;
218
- /** 状態遷移図の通らない道。他の図の種類では空 */
219
- paths: ScenePath[];
220
- /** 状態遷移図の始まりと終わりの印。他の図の種類では空 */
221
- ends: SceneEnd[];
222
- /** 状態遷移図の脇道の囲み。通らない状態が無ければ無い */
223
- side?: SceneSide;
224
- }
225
-
226
77
  /** 秒で表した、見えている間。`end` の時刻は含まない。 */
227
78
  interface Span {
228
79
  start: number;
229
80
  end: number;
230
81
  }
231
- /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。 */
82
+ /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。枝分かれの図では commit を積む出来事と枝を切る出来事も持つ */
232
83
  interface EdgeTime extends Span {
233
84
  step: number;
234
85
  event: number;
@@ -300,6 +151,8 @@ interface Rendered {
300
151
  layout: Layout;
301
152
  timeline: Timeline;
302
153
  diagram: Diagram;
154
+ /** 段ごとの止め絵で、同時に見えている字どうしの重なりと、線が札を持たない字を横切る所 (#3175)。重なりが無ければ空 */
155
+ overlaps: Overlap[];
303
156
  }
304
157
  /** 原本の JSON から図を描く。原本が形に合わない時は、誤りの場所を添えて断る。 */
305
158
  declare function renderDiagram(input: unknown, options?: RenderOptions): Rendered;
@@ -322,6 +175,10 @@ interface Player {
322
175
  prev(): void;
323
176
  play(): void;
324
177
  pause(): void;
178
+ /** 段 `step` (0 から) へ移って止める。段の数を超えた時は最後の段で止める (#3178) */
179
+ goTo(step: number): void;
180
+ /** 図の上に点線の四角を描く。四角は図の座標で渡し、空を渡すと消す。図を置き直しても残る (#3178) */
181
+ mark(rects: readonly Rect[]): void;
325
182
  destroy(): void;
326
183
  }
327
184
  declare function mountDiagram(host: HTMLElement, diagram: unknown, options?: PlayerOptions): Player;
@@ -346,4 +203,4 @@ declare function chooseView(rendered: Pick<Rendered, "layout" | "view">, frameWi
346
203
  textPx: number;
347
204
  };
348
205
 
349
- export { type CarrierTime, Carry, CheckOptions, ColorKey, Diagram, type EdgeTime, type EventTime, FONTS, FORMAT_VERSION, type Family, type Fence, FieldError, ICONS, type LabelTime, type Layout, type LineError, type Migrated, NotationLang, type ParseOptions, type Parsed, type Player, type PlayerOptions, type Point, type Read, type Rect, type RenderOptions, type Rendered, type SceneAction, type SceneBadge, type SceneBox, type SceneEdge, type SceneEnd, type SceneField, type SceneLabel, type SceneLifeline, type ScenePath, type SceneRegion, type SceneSide, type SceneStrip, type SceneTrail, type Span, type StateTime, Theme, type Timeline, ViewMode, chooseView, extractDiagrams, iconSvg, migrateFile, mountDiagram, parseNotation, printNotation, readDiagram, renderDiagram };
206
+ export { type CarrierTime, CheckOptions, Diagram, type EdgeTime, type EventTime, FORMAT_VERSION, type Fence, FieldError, ICONS, type LabelTime, Layout, type LineError, type Migrated, NotationLang, Overlap, type ParseOptions, type Parsed, type Player, type PlayerOptions, type Read, Rect, type RenderOptions, type Rendered, type Span, type StateTime, Theme, type Timeline, ViewMode, chooseView, extractDiagrams, iconSvg, migrateFile, mountDiagram, parseNotation, printNotation, readDiagram, renderDiagram };
package/dist/index.d.ts CHANGED
@@ -1,18 +1,5 @@
1
- import { N as NotationLang, D as Diagram, F as FieldError, C as CheckOptions, a as ColorKey, b as Carry, T as Theme, V as ViewMode } from './schema-B2MTRv66.js';
2
- export { B as Box, c as Checked, d as Color, e as DEFAULT_PALETTE, f as DiagramEvent, L as LabelSide, P as PALETTES, g as Palette, R as READABLE_PX, h as Region, S as StatePath, i as Step, r as resolvePalette, v as validateDiagram } from './schema-B2MTRv66.js';
3
-
4
- /**
5
- * 図が使う 2 つの字。どちらも package の依存として同梱する。
6
- *
7
- * 描いた SVG は字をこの 2 つの名前でしか名指さない。端末の字の名前を持たないので、
8
- * 同梱した字が読み込まれていない時に、端末の字へ黙って落ちて幅が変わることが無い。
9
- * 頁に字を読み込むのは `@cardenelabs/dragon/fonts` の入口 (`load-fonts.ts`) が持つ。
10
- */
11
- declare const FONTS: {
12
- readonly sans: "Noto Sans JP Variable";
13
- readonly mono: "JetBrains Mono Variable";
14
- };
15
- type Family = keyof typeof FONTS;
1
+ import { N as NotationLang, D as Diagram, F as FieldError, C as CheckOptions, T as Theme, V as ViewMode, L as Layout, O as Overlap, R as Rect } from './ink-B_7OXxtb.js';
2
+ export { B as Box, a as Carry, b as Checked, c as Color, d as ColorKey, e as DEFAULT_PALETTE, f as DiagramEvent, g as FONTS, h as Family, G as GitBranch, i as GitCommit, I as InkPart, j as LabelSide, k as OverlapSpot, P as PALETTES, l as Palette, m as Point, n as READABLE_PX, o as Region, S as SceneAction, p as SceneBadge, q as SceneBox, r as SceneEdge, s as SceneEnd, t as SceneField, u as SceneLabel, v as SceneLifeline, w as ScenePath, x as SceneRegion, y as SceneSide, z as SceneStrip, A as SceneTrail, E as StatePath, H as Step, J as describeOverlap, K as resolvePalette, M as validateDiagram } from './ink-B_7OXxtb.js';
16
3
 
17
4
  /**
18
5
  * Markdown の中の dragon の囲み (```dragon) を、囲みごとに取り出す。
@@ -58,6 +45,7 @@ declare function parseNotation(notation: string, options?: ParseOptions): Parsed
58
45
  * 箱は JSON の並びのまま書き、同じ区画の箱が続く所を 1 つの `group … end` にする。
59
46
  * 区画の箱が飛び飛びの時は同じ `group` を開き直す。区画の並びが箱の現れる順と違う時と、
60
47
  * 箱の無い区画がある時は、先に全ての区画を中の無い `group … end` で宣言してから開き直す。
48
+ * 枝分かれの図 (#3164) は、枝の `branch` の行を箱より前に書き、札を動かす線の運ぶ物が送る側の名前の札なら書かない。
61
49
  */
62
50
 
63
51
  declare function printNotation(diagram: Diagram): string;
@@ -86,149 +74,12 @@ declare function readDiagram(input: unknown, options?: CheckOptions): Read;
86
74
  */
87
75
  declare function migrateFile(path: string): Promise<Migrated>;
88
76
 
89
- type Point = [number, number];
90
- interface Rect {
91
- x: number;
92
- y: number;
93
- w: number;
94
- h: number;
95
- }
96
- interface SceneBox extends Rect {
97
- id: string;
98
- name: string;
99
- sub?: string;
100
- icon?: string;
101
- color: ColorKey;
102
- cx: number;
103
- cy: number;
104
- /** 状態遷移図で、どの段も辿り着かない状態。点線の箱で脇道の囲みに描く */
105
- ghost?: boolean;
106
- }
107
- interface SceneRegion extends Rect {
108
- id: string;
109
- /** 名前を折り返した行 */
110
- lines: string[];
111
- note?: string;
112
- icon?: string;
113
- color: ColorKey;
114
- /** 名前と印が占める所 */
115
- header: Rect;
116
- }
117
- /** 線。`step` と `event` は原本の `steps[step].events[event]` を指す。 */
118
- interface SceneEdge {
119
- step: number;
120
- event: number;
121
- from: string;
122
- to: string;
123
- points: Point[];
124
- color: ColorKey;
125
- carry: Carry;
126
- /** 着いた運ぶ物が留まる点。無ければ線の終わり */
127
- settle?: Point;
128
- }
129
- interface SceneLabel extends Rect {
130
- step: number;
131
- event: number;
132
- text: string;
133
- family: Family;
134
- color: ColorKey;
135
- }
136
- /** 状態遷移図の、最初の段より前に書いてどの段にも出ない線。点線で描き、運ぶ物を走らせない */
137
- interface ScenePath {
138
- from: string;
139
- to: string;
140
- points: Point[];
141
- label?: Rect & {
142
- text: string;
143
- family: Family;
144
- };
145
- }
146
- /** 状態遷移図の始まりと終わりの印。`ghost` は脇道の中の終わりの印 */
147
- interface SceneEnd {
148
- kind: "start" | "finish";
149
- x: number;
150
- y: number;
151
- r: number;
152
- ghost: boolean;
153
- /** 印の右に添える字 */
154
- text: string;
155
- /** 終わりの印へ線を引く状態 */
156
- box?: string;
157
- }
158
- /** 状態遷移図の脇道の囲み。`title` と `notes` は囲みの左上に置く字 */
159
- interface SceneSide extends Rect {
160
- title: string;
161
- /** 囲みの名前の下に 1 行ずつ置く添え書き */
162
- notes: string[];
163
- }
164
- /** 時系列図の箱の中の処理。生存線の上に札で出す。 */
165
- interface SceneAction extends Rect {
166
- step: number;
167
- event: number;
168
- box: string;
169
- text: string;
170
- color: ColorKey;
171
- }
172
- interface SceneBadge {
173
- step: number;
174
- x: number;
175
- y: number;
176
- color: ColorKey;
177
- }
178
- interface SceneLifeline {
179
- id: string;
180
- x: number;
181
- y1: number;
182
- y2: number;
183
- }
184
- interface SceneField {
185
- name: string;
186
- x: number;
187
- y: number;
188
- w: number;
189
- }
190
- /** 状態遷移図の帯の最後の欄。段が辿り着く順に状態を点で並べ、着いた状態を塗る (#3171) */
191
- interface SceneTrail {
192
- title: string;
193
- states: {
194
- box: string;
195
- color: ColorKey;
196
- }[];
197
- x: number;
198
- y: number;
199
- w: number;
200
- }
201
- interface SceneStrip extends Rect {
202
- title: string;
203
- fields: SceneField[];
204
- trail?: SceneTrail;
205
- }
206
- interface Layout {
207
- kind: Diagram["kind"];
208
- width: number;
209
- height: number;
210
- regions: SceneRegion[];
211
- boxes: SceneBox[];
212
- lifelines: SceneLifeline[];
213
- edges: SceneEdge[];
214
- labels: SceneLabel[];
215
- actions: SceneAction[];
216
- badges: SceneBadge[];
217
- strip?: SceneStrip;
218
- /** 状態遷移図の通らない道。他の図の種類では空 */
219
- paths: ScenePath[];
220
- /** 状態遷移図の始まりと終わりの印。他の図の種類では空 */
221
- ends: SceneEnd[];
222
- /** 状態遷移図の脇道の囲み。通らない状態が無ければ無い */
223
- side?: SceneSide;
224
- }
225
-
226
77
  /** 秒で表した、見えている間。`end` の時刻は含まない。 */
227
78
  interface Span {
228
79
  start: number;
229
80
  end: number;
230
81
  }
231
- /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。 */
82
+ /** 線を引いている間。`start` で引き始め、`drawn` で引き終わり、`end` (段の終わり) まで濃く残す。枝分かれの図では commit を積む出来事と枝を切る出来事も持つ */
232
83
  interface EdgeTime extends Span {
233
84
  step: number;
234
85
  event: number;
@@ -300,6 +151,8 @@ interface Rendered {
300
151
  layout: Layout;
301
152
  timeline: Timeline;
302
153
  diagram: Diagram;
154
+ /** 段ごとの止め絵で、同時に見えている字どうしの重なりと、線が札を持たない字を横切る所 (#3175)。重なりが無ければ空 */
155
+ overlaps: Overlap[];
303
156
  }
304
157
  /** 原本の JSON から図を描く。原本が形に合わない時は、誤りの場所を添えて断る。 */
305
158
  declare function renderDiagram(input: unknown, options?: RenderOptions): Rendered;
@@ -322,6 +175,10 @@ interface Player {
322
175
  prev(): void;
323
176
  play(): void;
324
177
  pause(): void;
178
+ /** 段 `step` (0 から) へ移って止める。段の数を超えた時は最後の段で止める (#3178) */
179
+ goTo(step: number): void;
180
+ /** 図の上に点線の四角を描く。四角は図の座標で渡し、空を渡すと消す。図を置き直しても残る (#3178) */
181
+ mark(rects: readonly Rect[]): void;
325
182
  destroy(): void;
326
183
  }
327
184
  declare function mountDiagram(host: HTMLElement, diagram: unknown, options?: PlayerOptions): Player;
@@ -346,4 +203,4 @@ declare function chooseView(rendered: Pick<Rendered, "layout" | "view">, frameWi
346
203
  textPx: number;
347
204
  };
348
205
 
349
- export { type CarrierTime, Carry, CheckOptions, ColorKey, Diagram, type EdgeTime, type EventTime, FONTS, FORMAT_VERSION, type Family, type Fence, FieldError, ICONS, type LabelTime, type Layout, type LineError, type Migrated, NotationLang, type ParseOptions, type Parsed, type Player, type PlayerOptions, type Point, type Read, type Rect, type RenderOptions, type Rendered, type SceneAction, type SceneBadge, type SceneBox, type SceneEdge, type SceneEnd, type SceneField, type SceneLabel, type SceneLifeline, type ScenePath, type SceneRegion, type SceneSide, type SceneStrip, type SceneTrail, type Span, type StateTime, Theme, type Timeline, ViewMode, chooseView, extractDiagrams, iconSvg, migrateFile, mountDiagram, parseNotation, printNotation, readDiagram, renderDiagram };
206
+ export { type CarrierTime, CheckOptions, Diagram, type EdgeTime, type EventTime, FORMAT_VERSION, type Fence, FieldError, ICONS, type LabelTime, Layout, type LineError, type Migrated, NotationLang, Overlap, type ParseOptions, type Parsed, type Player, type PlayerOptions, type Read, Rect, type RenderOptions, type Rendered, type Span, type StateTime, Theme, type Timeline, ViewMode, chooseView, extractDiagrams, iconSvg, migrateFile, mountDiagram, parseNotation, printNotation, readDiagram, renderDiagram };