@cardenelabs/dragon 0.7.0 → 0.8.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/dist/index.d.cts CHANGED
@@ -82,7 +82,7 @@ declare function orderByDependency(items: ReadonlyArray<{
82
82
  * docs/cdl/text-dsl-spec.md の文法を AST に変換した中間表現
83
83
  */
84
84
 
85
- type PresetType = "sequence" | "flow" | "swimlane" | "er" | "state" | "topology" | "solidity" | "gantt" | "class" | "pie" | "c4" | "mind";
85
+ type PresetType = "sequence" | "flow" | "swimlane" | "er" | "state" | "topology" | "solidity" | "gantt" | "class" | "pie" | "bar" | "line" | "funnel" | "tree" | "journey" | "quadrant" | "c4" | "mind";
86
86
  type Position = {
87
87
  line: number;
88
88
  column?: number;
@@ -110,9 +110,42 @@ type LayoutMode = "auto" | "manual";
110
110
  type DslDocument = {
111
111
  title: string;
112
112
  type: PresetType;
113
+ /**
114
+ * 図全体を 1 箱にする図種 (`pie` / `bar` / `line` / `funnel` / `tree` / `journey` /
115
+ * `quadrant` / `mind` / `gantt`) で、 その箱の上に出す小見出し (#1247)。
116
+ *
117
+ * これらの図種は箱を 1 つしか作らないため「どの箱の小見出しか」 が決まる。 箱ごとに
118
+ * 分かれる図種では決まらないので、 書かれていたら組み立て側が知らせる。
119
+ */
120
+ eyebrow?: string;
121
+ /**
122
+ * `eyebrow` を書いた行 (#1247)。 知らせの行番号に使う。
123
+ *
124
+ * 図の `pos` は常に 1 行目を指すため、 そこを使うと「10 行目に書いた `eyebrow` が効かない」
125
+ * を 1 行目として知らせることになり、 書いた場所に辿り着けない。
126
+ */
127
+ eyebrowPos?: Position;
128
+ /**
129
+ * 2 軸で仕分ける図 (`type: quadrant`) の軸の名前 (#1251)。
130
+ *
131
+ * 書かないと「小さい / 大きい」 のままになり、何を判断する図か読めない。
132
+ * 区画の名前 (`右上` 等) は軸の名前から `{上} × {右}` の形で決まる。
133
+ *
134
+ * 他の図種には軸が無いため、書かれていたら組み立て側が知らせる。
135
+ */
136
+ axes?: DslAxes;
137
+ /** `axes` を書いた行 (#1251)。 知らせの行番号に使う */
138
+ axesPos?: Position;
113
139
  actors: DslActor[];
114
140
  flow: DslStep[];
115
141
  animate?: DslAnimate;
142
+ /**
143
+ * 他の値から自動で決まる値 (`values:`)。 時間を持たず、 参照した値が動けば常に追随する。
144
+ *
145
+ * `states` (初期値だけを持つ) と `animation` (いつ何を動かすか) の間に置く層で、
146
+ * 値どうしの関係を書く場所。 書かなければ今までと同じ挙動。
147
+ */
148
+ values?: DslValue[];
116
149
  /** v0.5+ 拡張 ... viewport / lanes / groups */
117
150
  viewport?: DslViewport;
118
151
  lanes?: Record<string, DslLane>;
@@ -124,6 +157,17 @@ type DslDocument = {
124
157
  layout?: LayoutMode;
125
158
  pos: Position;
126
159
  };
160
+ /** 2 軸で仕分ける図の軸の名前 (#1251) */
161
+ type DslAxes = {
162
+ x?: {
163
+ left?: string;
164
+ right?: string;
165
+ };
166
+ y?: {
167
+ bottom?: string;
168
+ top?: string;
169
+ };
170
+ };
127
171
  /** 登場人物 (v0.5+ ... inline option 拡張) */
128
172
  type DslActor = {
129
173
  name: string;
@@ -142,6 +186,35 @@ type DslActor = {
142
186
  eyebrow?: string;
143
187
  value?: string;
144
188
  rows?: string[];
189
+ /**
190
+ * 工程の並び (`type: gantt`) で、その工程の担当 (#1251)。
191
+ *
192
+ * 他の図種では相手が無いため、書かれていたら組み立て側が知らせる。
193
+ */
194
+ owner?: string;
195
+ /**
196
+ * 工程の並び (`type: gantt`) で、その工程が終わる時期 (#1251)。
197
+ *
198
+ * 書かなければ始まりと同じ時期に終わる (帯が 1 コマ)。 `{名前}` を書くと状態から取り、
199
+ * 段で帯が伸び縮みする様子を見せられる。
200
+ *
201
+ * 他の図種では相手が無いため、書かれていたら組み立て側が知らせる。
202
+ */
203
+ end?: string;
204
+ /**
205
+ * 体験の道筋 (`type: journey`) で、その段階が起きる場所 (#1251)。
206
+ *
207
+ * 「どこで起きたか」 を段の下に出す。 他の図種では相手が無いため、書かれていたら
208
+ * 組み立て側が知らせる。
209
+ */
210
+ touchpoint?: string;
211
+ /**
212
+ * 体験の道筋 (`type: journey`) で、その段階の改善の余地 (#1251)。
213
+ *
214
+ * 気持ちが落ちる段に「何を直せるか」 を添える。 他の図種では相手が無いため、
215
+ * 書かれていたら組み立て側が知らせる。
216
+ */
217
+ opportunity?: string;
145
218
  lane?: string;
146
219
  stack?: number;
147
220
  initial?: boolean;
@@ -246,6 +319,8 @@ type DslStep = {
246
319
  cardinality?: string;
247
320
  labelOffsetX?: number;
248
321
  labelOffsetY?: number;
322
+ /** true で説明文を矢印の線の上に重ねる。 分岐図の条件ラベル用。 */
323
+ overlay?: boolean;
249
324
  /**
250
325
  * canvas pivot (CAR-1693 Phase 1) DSL 表面 `pos: {x, y}` 由来の layout offset。 step の edge
251
326
  * label 位置を auto layout compute から (dx, dy) shift する。 未指定は auto、 set 済は Phase 2 で適用。
@@ -310,6 +385,51 @@ type DslState = {
310
385
  initial: number | string;
311
386
  pos: Position;
312
387
  };
388
+ /**
389
+ * 値が動き出すきっかけ (#1161 段 2)。
390
+ *
391
+ * `step` は段が始まった時、 `reaches` は別の値が境目を越えた時。 どちらも「成り立った瞬間の
392
+ * 出来事」 で、 常に成り立つ関係を表す式とは別物 (spec § 2.3)。
393
+ */
394
+ type DslValueTrigger = {
395
+ kind: "step";
396
+ step: string;
397
+ } | {
398
+ kind: "reaches";
399
+ /** 見張る相手の値の名前 */
400
+ source: string;
401
+ op: ">=" | ">" | "<=" | "<" | "==" | "!=";
402
+ threshold: number;
403
+ };
404
+ /**
405
+ * 記法の `values:` の 1 件。 形は 2 つある。
406
+ *
407
+ * | 形 | 持つもの | 意味 |
408
+ * |---|---|---|
409
+ * | 式 | `expression` | 常に成り立つ関係。 時間を持たない |
410
+ * | きっかけ | `trigger` / `to` / `durationMs` | きっかけから `to` まで動く。 時間を持つ |
411
+ *
412
+ * 両方を持つ形は無い (parser が弾く)。 きっかけ形は組み立ての時点で段の時計を読む式へ畳まれる
413
+ * ため、 図に載る時にはどちらも `derived` になる。
414
+ */
415
+ type DslValue = {
416
+ name: string;
417
+ pos: Position;
418
+ } & ({
419
+ /** 式そのもの。 評価は描画側が毎 frame 行う */
420
+ expression: string;
421
+ trigger?: never;
422
+ to?: never;
423
+ durationMs?: never;
424
+ } | {
425
+ expression?: never;
426
+ /** 動き出すきっかけ */
427
+ trigger: DslValueTrigger;
428
+ /** 動いた先の値 */
429
+ to: number;
430
+ /** 動く長さ (ms) */
431
+ durationMs: number;
432
+ });
313
433
  /** ステップ (phase) */
314
434
  type DslPhase = {
315
435
  name: string;
@@ -397,7 +517,7 @@ interface CompileToCdlOpts {
397
517
  }
398
518
  /** 図は出せるが書いた通りにならなかった、 という知らせ。 */
399
519
  type CompileNotice = {
400
- kind: "relative-position-ignored" | "focus-target-missing" | "state-override-rejected" | "external-paint-dropped" | "part-not-drawn" | "scale-reserved";
520
+ kind: "relative-position-ignored" | "focus-target-missing" | "state-override-rejected" | "external-paint-dropped" | "part-not-drawn" | "scale-reserved" | "chart-value-unreadable" | "chart-edge-dropped" | "value-shadows-state" | "value-unresolved" | "value-duplicate" | "flow-actor-missing" | "value-trigger-unresolved" | "flow-self-loop" | "lane-not-honored" | "lane-declared-empty" | "eyebrow-not-honored" | "flow-endpoint-not-honored";
401
521
  /** 対象の名前。 光らせる相手なら書かれた指定そのまま */
402
522
  actor: string;
403
523
  /** 書かれていた行 */
@@ -639,6 +759,14 @@ type V05ParseResult = {
639
759
  ok: false;
640
760
  errors: DslError[];
641
761
  };
762
+ /**
763
+ * 記法が受ける top-level の項目 (#1190)。
764
+ *
765
+ * 読めない行の案内と、記法一覧が全て載せているかの検査が、どちらもここを見る。 一覧に手で
766
+ * 書くと、項目を足した時に案内か一覧のどちらかが取り残される (実際に `states` / `values` が
767
+ * 一覧に 1 件も無い状態で放置されていた)。
768
+ */
769
+ declare const TOP_LEVEL_KEYS: readonly ["title", "type", "actors", "flow", "states", "values", "animation", "viewport", "lanes", "groups", "eyebrow", "axes"];
642
770
  /** 受け付ける図種。 記法一覧はここを見る。 */
643
771
  declare const PRESET_TYPES: ReadonlySet<PresetType>;
644
772
  /**
@@ -911,6 +1039,9 @@ interface InputSize {
911
1039
  * **段の中身 (光らせる相手 / 遷移 / 即時変更) も数える**。 段の数だけを見ると、
912
1040
  * 1 段に 1,000 件の相手を書いた形が 1 件として通る。 実測ではこの形が組み立ての中で
913
1041
  * 約 100 万件に展開され、 呼び出しの深さが上限を超えて落ちた。
1042
+ *
1043
+ * **他の値から決まる値 (`values:`) も数える** (#1162)。 これらは毎 frame 解かれるので、
1044
+ * 数に入れないと上限をすり抜けた本文が描画のたびに重さを持つ。
914
1045
  */
915
1046
  declare function countDocElements(doc: DslDocument): number;
916
1047
  /**
@@ -933,6 +1064,7 @@ declare function countDiagramElements(diagram: {
933
1064
  formulas?: unknown[];
934
1065
  scrollTriggers?: unknown[];
935
1066
  eventBindings?: unknown[];
1067
+ derived?: unknown[];
936
1068
  }): number;
937
1069
  /** 本文の大きさを byte で数える (文字数ではなく実際の大きさ) */
938
1070
  declare function countBytes(src: string): number;
@@ -981,10 +1113,35 @@ interface DragonJson {
981
1113
  title: string;
982
1114
  /** preset type (必須): sequence / flow / swimlane / er / state / topology / solidity / gantt / class / pie / c4 / mind */
983
1115
  type: PresetType;
1116
+ /**
1117
+ * 図表の箱の上に出す小見出し (optional)。 記法の最上位 `eyebrow:` と同じ (#1247)。
1118
+ *
1119
+ * 効くのは図全体を 1 箱にする図種 (`pie` / `bar` / `line` / `funnel` / `tree` / `journey` /
1120
+ * `quadrant` / `mind` / `gantt`) だけ。 箱ごとに分かれる図種では相手が決まらないため、
1121
+ * 組み立て側が知らせを出す。 そちらは `actors[].eyebrow` に書く。
1122
+ */
1123
+ eyebrow?: string;
984
1124
  /** 登場人物 (必須): 文字列 or { name, kind, ... } object */
985
1125
  actors: (string | JsonActor)[];
986
1126
  /** flow step 配列 (必須): { from, to, label, ... } */
987
1127
  flow: JsonStep[];
1128
+ /**
1129
+ * 状態の初期値 (optional)。 記法の `states:` と同じ (#1181)。
1130
+ *
1131
+ * `{名前}` を箱の文字に置くと、ここに書いた値が描画側で置き換わる。 名前は英数字と `_`
1132
+ * だけ (描画側が置き換える時に見る範囲と揃える)。
1133
+ *
1134
+ * ここに書けるのは初期値まで。 段で動かすのは `animation[].tween` / `animation[].set`
1135
+ * (`#1186` で追加、記法の `tween:` / `set:` と同じ)。
1136
+ */
1137
+ states?: Record<string, number | string>;
1138
+ /**
1139
+ * 他の値から自動で決まる値 (optional)。 記法の `values:` と同じ (#1181)。
1140
+ *
1141
+ * 式には四則 (`+ - * /`) と括弧、比較 (`> >= < <= == !=`)、`min` / `max` が書ける。
1142
+ * 他の値は `{名前}` で読む。 解くのは描画側で、毎 frame 参照から順に決まる。
1143
+ */
1144
+ values?: Record<string, string>;
988
1145
  /** animation phase 配列 (optional) */
989
1146
  animation?: JsonPhase[];
990
1147
  /** viewport (optional): 全体 canvas size / gap */
@@ -1063,6 +1220,8 @@ interface JsonStep {
1063
1220
  cardinality?: string;
1064
1221
  labelOffsetX?: number;
1065
1222
  labelOffsetY?: number;
1223
+ /** true で説明文を矢印の線の上に重ねる。 分岐図の条件ラベル用。 */
1224
+ overlay?: boolean;
1066
1225
  /**
1067
1226
  * canvas pivot (CAR-1693 Phase 1) DSL 表面 `pos: {x, y}` = edge label offset。 未指定は
1068
1227
  * backward compat、 set 済は Phase 2 の applyPosOffset で edge label 位置を shift する。
@@ -1080,6 +1239,19 @@ interface JsonPhase {
1080
1239
  body?: string;
1081
1240
  /** badge label */
1082
1241
  badge?: string;
1242
+ /**
1243
+ * 段の中で値を動かす (#1186)。 記法の `tween: name 100 -> 90` と同じ。
1244
+ *
1245
+ * 足すまで JSON の入口は `states:` で初期値を書けても **動かす手段が無かった** ため、
1246
+ * 同じ図を記法で書くと動き JSON で書くと静止する状態だった (#1181 で状態を足した時の残り)。
1247
+ */
1248
+ tween?: Record<string, readonly [number, number]>;
1249
+ /**
1250
+ * 段の切替で値を差し替える (#1186)。 記法の `set: name value` と同じ。
1251
+ *
1252
+ * `tween` が段の中を補間するのに対し、こちらは段の切替時に 1 度だけ変える。
1253
+ */
1254
+ set?: Record<string, number | string>;
1083
1255
  }
1084
1256
  /**
1085
1257
  * JSON DSL error。 line 概念がないため、 field path (JSON pointer style) で位置を示す。
@@ -1112,6 +1284,7 @@ interface JsonDslError {
1112
1284
  */
1113
1285
  declare function jsonToDiagram(json: unknown, opts?: {
1114
1286
  partsCatalog?: Record<string, CdlDiagram>;
1287
+ onNotice?: CompileToCdlOpts["onNotice"];
1115
1288
  }): CdlDiagram;
1116
1289
  /**
1117
1290
  * JSON DSL を validate だけ実施 (compile しない)。 error 詳細を配列で取得したい場合に使う。
@@ -1164,6 +1337,10 @@ declare const diagramJsonSchema: {
1164
1337
  enum: string[];
1165
1338
  description: string;
1166
1339
  };
1340
+ eyebrow: {
1341
+ type: string;
1342
+ description: string;
1343
+ };
1167
1344
  actors: {
1168
1345
  type: string;
1169
1346
  minItems: number;
@@ -1280,9 +1457,44 @@ declare const diagramJsonSchema: {
1280
1457
  type: string;
1281
1458
  description: string;
1282
1459
  };
1460
+ overlay: {
1461
+ type: string;
1462
+ description: string;
1463
+ };
1283
1464
  };
1284
1465
  };
1285
1466
  };
1467
+ states: {
1468
+ type: string;
1469
+ description: string;
1470
+ additionalProperties: boolean;
1471
+ patternProperties: {
1472
+ "^[a-zA-Z_][a-zA-Z0-9_]*$": {
1473
+ type: string[];
1474
+ description: string;
1475
+ };
1476
+ };
1477
+ examples: {
1478
+ inflow: number;
1479
+ done: number;
1480
+ }[];
1481
+ };
1482
+ values: {
1483
+ type: string;
1484
+ description: string;
1485
+ additionalProperties: boolean;
1486
+ patternProperties: {
1487
+ "^[a-zA-Z_][a-zA-Z0-9_]*$": {
1488
+ type: string;
1489
+ minLength: number;
1490
+ description: string;
1491
+ };
1492
+ };
1493
+ examples: {
1494
+ waiting: string;
1495
+ busy: string;
1496
+ }[];
1497
+ };
1286
1498
  animation: {
1287
1499
  type: string;
1288
1500
  description: string;
@@ -1316,6 +1528,31 @@ declare const diagramJsonSchema: {
1316
1528
  type: string;
1317
1529
  description: string;
1318
1530
  };
1531
+ tween: {
1532
+ type: string;
1533
+ description: string;
1534
+ additionalProperties: boolean;
1535
+ patternProperties: {
1536
+ "^[a-zA-Z_][a-zA-Z0-9_]*$": {
1537
+ type: string;
1538
+ items: {
1539
+ type: string;
1540
+ };
1541
+ minItems: number;
1542
+ maxItems: number;
1543
+ };
1544
+ };
1545
+ };
1546
+ set: {
1547
+ type: string;
1548
+ description: string;
1549
+ additionalProperties: boolean;
1550
+ patternProperties: {
1551
+ "^[a-zA-Z_][a-zA-Z0-9_]*$": {
1552
+ type: string[];
1553
+ };
1554
+ };
1555
+ };
1319
1556
  };
1320
1557
  };
1321
1558
  };
@@ -1448,4 +1685,4 @@ interface CompileOpts {
1448
1685
  */
1449
1686
  declare function textDslToDiagram(src: string, opts?: CompileOpts): CdlDiagram;
1450
1687
 
1451
- export { type AnchorBox, type CompileNotice, type CompileOpts, DIAGRAM_BOUNDARY_PADDING, type DiagramBoundingBox, type DragonJson, type DslActor, type DslAnimate, type DslDocument, type DslError, type DslGroup, type DslLane, type DslPhase, type DslSet, type DslState, type DslStep, type DslTween, type DslViewport, type FocusEntry, type InputSize, type JsonActor, type JsonDslError, type JsonPhase, type JsonStep, type LayoutMode, type LayoutPos, type LintIssue, type LintReport, type LintSeverity, MAX_INPUT_BYTES, MAX_INPUT_ELEMENTS, MAX_PART_SCALE, NODE_KIND_ALIAS, NODE_KIND_VALID, PRESET_TYPES, type PresetType, RELATIVE_GAP_DEFAULT, type RelativeDirection, type RelativePos, TONE_ALIAS, autoFix, compileToCdl, computeDiagramBoundingBox, countBytes, countDiagramElements, countDocElements, describeOversize, describeOversizeSource, diagramJsonSchema, isColorValue, jsonToDiagram, lintDiagram, measureActorBoxes, normalizePartScale, orderByDependency, parseFocusEntry, parseRelativePos, parseTextDsl, parseTextDslV05, partBoxInFrame, partDrawsInDiagram, partIsMeasurable, partRenderSize, partScaleFactor, partTargetScale, partTargetSize, partVisualSize, partsGridCenters, pointsOutside, rectsOverlap, resolveRelativePos, stripExternalPaint, stripQuotes, textDslToDiagram, validateDragonJson, writeActorPosition };
1688
+ export { type AnchorBox, type CompileNotice, type CompileOpts, DIAGRAM_BOUNDARY_PADDING, type DiagramBoundingBox, type DragonJson, type DslActor, type DslAnimate, type DslDocument, type DslError, type DslGroup, type DslLane, type DslPhase, type DslSet, type DslState, type DslStep, type DslTween, type DslValue, type DslViewport, type FocusEntry, type InputSize, type JsonActor, type JsonDslError, type JsonPhase, type JsonStep, type LayoutMode, type LayoutPos, type LintIssue, type LintReport, type LintSeverity, MAX_INPUT_BYTES, MAX_INPUT_ELEMENTS, MAX_PART_SCALE, NODE_KIND_ALIAS, NODE_KIND_VALID, PRESET_TYPES, type PresetType, RELATIVE_GAP_DEFAULT, type RelativeDirection, type RelativePos, TONE_ALIAS, TOP_LEVEL_KEYS, autoFix, compileToCdl, computeDiagramBoundingBox, countBytes, countDiagramElements, countDocElements, describeOversize, describeOversizeSource, diagramJsonSchema, isColorValue, jsonToDiagram, lintDiagram, measureActorBoxes, normalizePartScale, orderByDependency, parseFocusEntry, parseRelativePos, parseTextDsl, parseTextDslV05, partBoxInFrame, partDrawsInDiagram, partIsMeasurable, partRenderSize, partScaleFactor, partTargetScale, partTargetSize, partVisualSize, partsGridCenters, pointsOutside, rectsOverlap, resolveRelativePos, stripExternalPaint, stripQuotes, textDslToDiagram, validateDragonJson, writeActorPosition };