@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
@@ -0,0 +1,360 @@
1
+ /**
2
+ * 図が使う 2 つの字。どちらも package の依存として同梱する。
3
+ *
4
+ * 描いた SVG は字をこの 2 つの名前でしか名指さない。端末の字の名前を持たないので、
5
+ * 同梱した字が読み込まれていない時に、端末の字へ黙って落ちて幅が変わることが無い。
6
+ * 頁に字を読み込むのは `@cardenelabs/dragon/fonts` の入口 (`load-fonts.ts`) が持つ。
7
+ */
8
+ declare const FONTS: {
9
+ readonly sans: "Noto Sans JP Variable";
10
+ readonly mono: "JetBrains Mono Variable";
11
+ };
12
+ type Family = keyof typeof FONTS;
13
+
14
+ type Theme = "light" | "dark";
15
+ interface Palette {
16
+ id: string;
17
+ name: string;
18
+ note: string;
19
+ light: Record<string, string>;
20
+ dark: Record<string, string>;
21
+ }
22
+ /** 色味を指定しない時と、知らない名前を渡した時に使う色味。 */
23
+ declare const DEFAULT_PALETTE = "paper";
24
+ declare const PALETTES: Readonly<Record<string, Palette>>;
25
+ /** 名前から色味を引く。指定が無いか、知らない名前 (外した墨と朱の `ink` を含む) なら紙と墨。 */
26
+ declare function resolvePalette(id?: string): Palette;
27
+ /** 区画や箱を分ける色の役。灰 (slate) と硬貨 (coin) は分類の色として順に配らない。 */
28
+ declare const COLOR_ORDER: readonly ["blue", "amber", "green", "violet", "rose"];
29
+ type ColorKey = (typeof COLOR_ORDER)[number] | "slate" | "coin";
30
+ /** 見せ方を決める字の大きさ。全体を枠に収めた時の箱の名前がこれを下回ると寄って追う。 */
31
+ declare const READABLE_PX = 10.5;
32
+
33
+ /**
34
+ * dragon記法の語 (#3137)。
35
+ *
36
+ * 行の種類は行の頭の英語の語で決まり、属性は `[<鍵>: <値>]` で書く。
37
+ * 語は英語だけで、原本の JSON が使う名前に揃え、記法と JSON で覚える語を 1 組にする。
38
+ *
39
+ * 言葉の型 (`NotationLang`) は、誤りの文と図の中の字の言葉を選ぶために持つ。
40
+ * 語が英語だけなので、記法の file から言葉は決めず、呼ぶ側が渡す。
41
+ *
42
+ * 型が欠けを止める。原本の JSON の値 (図の種類、運ぶ物、見せ方、名前の側) に語が無い時は、型の検査が落ちる。
43
+ */
44
+
45
+ type NotationLang = "ja" | "en";
46
+
47
+ type Color = "blue" | "amber" | "green" | "violet" | "rose" | "slate" | "coin";
48
+ interface Region {
49
+ id: string;
50
+ name: string;
51
+ note?: string;
52
+ color?: Color;
53
+ icon?: string;
54
+ }
55
+ interface Box {
56
+ id: string;
57
+ name: string;
58
+ sub?: string;
59
+ color?: Color;
60
+ icon?: string;
61
+ region?: string;
62
+ }
63
+ type Carry = {
64
+ kind: "envelope";
65
+ } | {
66
+ kind: "tag";
67
+ text: string;
68
+ } | {
69
+ kind: "coin";
70
+ } | {
71
+ kind: "none";
72
+ };
73
+ type LabelSide = "above" | "below" | "left" | "right";
74
+ /** 見せ方。`fixed` は全体を止めて中だけ動かし、`follow` は寄って動かし全体図で今どこかを示す。 */
75
+ type ViewMode = "fixed" | "follow";
76
+ type DiagramEvent = {
77
+ type: "edge";
78
+ from: string;
79
+ to: string;
80
+ label?: string;
81
+ carry: Carry;
82
+ labelSide?: LabelSide;
83
+ } | {
84
+ type: "action";
85
+ box: string;
86
+ label: string;
87
+ } | {
88
+ type: "swap";
89
+ box: string;
90
+ text: string;
91
+ } | {
92
+ type: "strip";
93
+ field: string;
94
+ value?: string;
95
+ tag?: string;
96
+ } | GitCommit | {
97
+ type: "branch";
98
+ branch: string;
99
+ from: string;
100
+ };
101
+ /**
102
+ * 枝分かれの図 (#3164) の commit を積む出来事。積んだ枝の札と、その枝を指す HEAD が新しい commit へ進む。
103
+ * 当て直し (`copy`) は枝の札を動かさず、merge commit (`merge`) は取り込む枝の先端も親に持つ
104
+ */
105
+ interface GitCommit {
106
+ type: "commit";
107
+ id: string;
108
+ branch: string;
109
+ copy?: string;
110
+ merge?: string;
111
+ hash?: string;
112
+ note?: string;
113
+ }
114
+ /** 枝分かれの図の枝。上から宣言した順に帯を並べる */
115
+ interface GitBranch {
116
+ id: string;
117
+ note?: string;
118
+ }
119
+ /** 状態遷移図の、最初の段より前に書いた移れる道。`from` に `start`、`to` に `finish` を書ける */
120
+ interface StatePath {
121
+ from: string;
122
+ to: string;
123
+ label?: string;
124
+ }
125
+ interface Step {
126
+ title: string;
127
+ body: string;
128
+ code?: string;
129
+ events: DiagramEvent[];
130
+ }
131
+ interface Diagram {
132
+ version: number;
133
+ kind: "sequence" | "architecture" | "state" | "git";
134
+ title: string;
135
+ view?: ViewMode;
136
+ regions?: Region[];
137
+ boxes: Box[];
138
+ strip?: {
139
+ title: string;
140
+ fields: string[];
141
+ };
142
+ steps: Step[];
143
+ sequence?: {
144
+ lifelines: string[];
145
+ };
146
+ state?: {
147
+ paths: StatePath[];
148
+ };
149
+ git?: {
150
+ branches: GitBranch[];
151
+ };
152
+ }
153
+ interface FieldError {
154
+ /** 誤った欄の場所 (JSON Pointer) */
155
+ pointer: string;
156
+ message: string;
157
+ }
158
+ type Checked = {
159
+ ok: true;
160
+ } | {
161
+ ok: false;
162
+ errors: FieldError[];
163
+ };
164
+ interface CheckOptions {
165
+ /** 誤りの文の言葉。渡さなければ日本語 */
166
+ lang?: NotationLang;
167
+ }
168
+ /** 原本の JSON を検査する。版が道具より新しいかは見ない (`readDiagram` が見る)。 */
169
+ declare function validateDiagram(input: unknown, options?: CheckOptions): Checked;
170
+
171
+ type Point = [number, number];
172
+ interface Rect {
173
+ x: number;
174
+ y: number;
175
+ w: number;
176
+ h: number;
177
+ }
178
+ interface SceneBox extends Rect {
179
+ id: string;
180
+ name: string;
181
+ sub?: string;
182
+ icon?: string;
183
+ color: ColorKey;
184
+ cx: number;
185
+ cy: number;
186
+ /** 状態遷移図で、どの段も辿り着かない状態。点線の箱で脇道の囲みに描く */
187
+ ghost?: boolean;
188
+ /** 運ぶ物の置き場の枠 (#3176)。運ぶ物を出し入れする箱だけが持つ */
189
+ slot?: Rect;
190
+ /** 絵柄の真ん中の x。置き場を持つ箱は、絵柄を左へ寄せて右を置き場にする。無ければ箱の真ん中 */
191
+ iconX?: number;
192
+ }
193
+ interface SceneRegion extends Rect {
194
+ id: string;
195
+ /** 名前を折り返した行 */
196
+ lines: string[];
197
+ note?: string;
198
+ icon?: string;
199
+ color: ColorKey;
200
+ /** 名前と印が占める所 */
201
+ header: Rect;
202
+ }
203
+ /** 線。`step` と `event` は原本の `steps[step].events[event]` を指す。 */
204
+ interface SceneEdge {
205
+ step: number;
206
+ event: number;
207
+ from: string;
208
+ to: string;
209
+ points: Point[];
210
+ color: ColorKey;
211
+ carry: Carry;
212
+ /** 着いた運ぶ物が留まる点。無ければ線の終わり */
213
+ settle?: Point;
214
+ /** 走り出す前に運ぶ物が待つ点 (#3176)。運ぶ物はここから線の始まりへ出て線を走る。無ければ線の始まり */
215
+ wait?: Point;
216
+ }
217
+ interface SceneLabel extends Rect {
218
+ step: number;
219
+ event: number;
220
+ text: string;
221
+ family: Family;
222
+ color: ColorKey;
223
+ /** 同じ線の同じ名前を次に置く段 (状態遷移図、#3184)。その段が始まると、薄く残した名前を消す */
224
+ until?: number;
225
+ }
226
+ /** 状態遷移図の、最初の段より前に書いてどの段にも出ない線。点線で描き、運ぶ物を走らせない */
227
+ interface ScenePath {
228
+ from: string;
229
+ to: string;
230
+ points: Point[];
231
+ label?: Rect & {
232
+ text: string;
233
+ family: Family;
234
+ };
235
+ }
236
+ /** 状態遷移図の始まりと終わりの印。`ghost` は脇道の中の終わりの印 */
237
+ interface SceneEnd {
238
+ kind: "start" | "finish";
239
+ x: number;
240
+ y: number;
241
+ r: number;
242
+ ghost: boolean;
243
+ /** 印の右に添える字 */
244
+ text: string;
245
+ /** 終わりの印へ線を引く状態 */
246
+ box?: string;
247
+ }
248
+ /** 状態遷移図の脇道の囲み。`title` と `notes` は囲みの左上に置く字 */
249
+ interface SceneSide extends Rect {
250
+ title: string;
251
+ /** 囲みの名前の下に 1 行ずつ置く添え書き */
252
+ notes: string[];
253
+ }
254
+ /** 時系列図の箱の中の処理。生存線の上に札で出す。 */
255
+ interface SceneAction extends Rect {
256
+ step: number;
257
+ event: number;
258
+ box: string;
259
+ text: string;
260
+ color: ColorKey;
261
+ }
262
+ interface SceneBadge {
263
+ step: number;
264
+ x: number;
265
+ y: number;
266
+ color: ColorKey;
267
+ /** 同じ所に次に番号を置く段 (#3184)。その段が始まると、この番号を消して数字を入れ替える。無ければ最後まで残る */
268
+ until?: number;
269
+ }
270
+ interface SceneLifeline {
271
+ id: string;
272
+ x: number;
273
+ y1: number;
274
+ y2: number;
275
+ }
276
+ interface SceneField {
277
+ name: string;
278
+ x: number;
279
+ y: number;
280
+ w: number;
281
+ }
282
+ /** 状態遷移図の帯の最後の欄。段が辿り着く順に状態を点で並べ、着いた状態を塗る (#3171) */
283
+ interface SceneTrail {
284
+ title: string;
285
+ states: {
286
+ box: string;
287
+ color: ColorKey;
288
+ }[];
289
+ x: number;
290
+ y: number;
291
+ w: number;
292
+ }
293
+ interface SceneStrip extends Rect {
294
+ title: string;
295
+ fields: SceneField[];
296
+ trail?: SceneTrail;
297
+ }
298
+ interface Layout {
299
+ kind: Diagram["kind"];
300
+ width: number;
301
+ height: number;
302
+ regions: SceneRegion[];
303
+ boxes: SceneBox[];
304
+ lifelines: SceneLifeline[];
305
+ edges: SceneEdge[];
306
+ labels: SceneLabel[];
307
+ actions: SceneAction[];
308
+ badges: SceneBadge[];
309
+ strip?: SceneStrip;
310
+ /** 状態遷移図の通らない道。他の図の種類では空 */
311
+ paths: ScenePath[];
312
+ /** 状態遷移図の始まりと終わりの印。他の図の種類では空 */
313
+ ends: SceneEnd[];
314
+ /** 状態遷移図の脇道の囲み。通らない状態が無ければ無い */
315
+ side?: SceneSide;
316
+ }
317
+
318
+ /** 書き手が書いていない図の部品。`icon` は箱 `box` の絵柄、`coin` と `envelope` は運ぶ物の硬貨と封筒 (#3184) */
319
+ type InkPart = {
320
+ kind: "icon";
321
+ box: string;
322
+ } | {
323
+ kind: "coin";
324
+ } | {
325
+ kind: "envelope";
326
+ };
327
+ /** 重なる字。`rect` は字 (札に入った字は札) の四角、`badge` は段の番号の丸の字か、`part` は図の部品の種類 (部品の時だけ持つ) */
328
+ interface OverlapSpot {
329
+ text: string;
330
+ rect: Rect;
331
+ badge: boolean;
332
+ part?: InkPart;
333
+ }
334
+ /**
335
+ * 重なり。`step` は重なりが見える段 (0 から数える)。
336
+ * `texts` は重なる 2 つの字、`line` は札を持たない字 `text` を横切る線の両端の名札。
337
+ * `spots` は重なる字で、`texts` は 2 つの字を同じ順に、`line` は横切られる字を 1 つ持つ
338
+ */
339
+ type Overlap = {
340
+ kind: "texts";
341
+ step: number;
342
+ texts: [string, string];
343
+ spots: [OverlapSpot, OverlapSpot];
344
+ } | {
345
+ kind: "line";
346
+ step: number;
347
+ text: string;
348
+ line: {
349
+ from: string;
350
+ to: string;
351
+ };
352
+ spots: [OverlapSpot];
353
+ };
354
+ /**
355
+ * 重なりを知らせる文 (#3178)。段の番号は「段の番号 N」と呼び、図の部品は言葉ごとの呼び方で呼び (#3184)、ほかの字は鉤括弧か引用符で囲む。
356
+ * 段の番号は文に含めない
357
+ */
358
+ declare function describeOverlap(overlap: Overlap, lang?: NotationLang): string;
359
+
360
+ export { type SceneTrail as A, type Box as B, type CheckOptions as C, type Diagram as D, type StatePath as E, type FieldError as F, type GitBranch as G, type Step as H, type InkPart as I, describeOverlap as J, resolvePalette as K, type Layout as L, validateDiagram as M, type NotationLang as N, type Overlap as O, PALETTES as P, type Rect as R, type SceneAction as S, type Theme as T, type ViewMode as V, type Carry as a, type Checked as b, type Color as c, type ColorKey as d, DEFAULT_PALETTE as e, type DiagramEvent as f, FONTS as g, type Family as h, type GitCommit as i, type LabelSide as j, type OverlapSpot as k, type Palette as l, type Point as m, READABLE_PX as n, type Region as o, type SceneBadge as p, type SceneBox as q, type SceneEdge as r, type SceneEnd as s, type SceneField as t, type SceneLabel as u, type SceneLifeline as v, type ScenePath as w, type SceneRegion as x, type SceneSide as y, type SceneStrip as z };