@cardenelabs/dragon 0.17.0 → 0.18.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/README.md CHANGED
@@ -71,6 +71,7 @@ flow:
71
71
  | `scrolls` | 巻き上げに応じて進む値 (画面を巻き上げた量から 0 から 1 を作る) |
72
72
  | `bands` | 動いている間の帯 (順序図。 `- DB: 1..2` の形で段の番号の区間を書く) |
73
73
  | `reveal` | 矢印をいつ出すか (`phase` = 段が名指しする矢印はその段まで描かない (既定) / `all` = 最初から全部描く) |
74
+ | `direction` | 図の並ぶ向き (`縦` / `横`、英語なら `vertical` / `horizontal`)。 効くのは `flow` と `swimlane` だけ |
74
75
 
75
76
  <!-- notation:top-level:end -->
76
77
 
package/dist/index.cjs CHANGED
@@ -11,6 +11,17 @@ var HEADERS = {
11
11
  animate: ["\u30A2\u30CB\u30E1\u30FC\u30B7\u30E7\u30F3", "animate", "animation"]
12
12
  };
13
13
  var PRESET_NAMES = ["sequence", "flow", "swimlane", "er", "state", "topology"];
14
+ var DIRECTIONS = ["\u7E26", "\u6A2A"];
15
+ var DIRECTION_ALIAS = {
16
+ \u7E26: "\u7E26",
17
+ \u6A2A: "\u6A2A",
18
+ vertical: "\u7E26",
19
+ horizontal: "\u6A2A"
20
+ };
21
+ function resolveDirection(s) {
22
+ const k = s.trim().toLowerCase();
23
+ return Object.hasOwn(DIRECTION_ALIAS, k) ? DIRECTION_ALIAS[k] : null;
24
+ }
14
25
  var NODE_KIND_ALIAS = {
15
26
  // 日本語
16
27
  \u4EBA: "actor",
@@ -1917,7 +1928,18 @@ var TOP_LEVEL_KEYS = [
1917
1928
  // 動いている間の帯 (#1466)。 順序図だけが読む
1918
1929
  "bands",
1919
1930
  // 矢印をいつ出すか (#1470)
1920
- "reveal"
1931
+ "reveal",
1932
+ /*
1933
+ * 図の並ぶ向き (#1494)。
1934
+ *
1935
+ * **最上位の語は英語にする**。 日本語の見出し (`タイトル:` / `種類:` 等) は v0.4 の
1936
+ * 書き方で、2026-12-31 に廃止する側にある。 ここで日本語の語を足すと、消す予定の形を
1937
+ * 増やすことになる。
1938
+ *
1939
+ * 値は日本語と英語の両方を受ける。 箱の項目 (`色` / `種類` / `位置` / `大きさ`) は v0.5 でも
1940
+ * 日本語で書けるので、書き手が自然に言う語 (`縦` / `横`) を残せる。
1941
+ */
1942
+ "direction"
1921
1943
  ];
1922
1944
  var LANE_ID_ENTRY = /^([\p{L}\p{N}_-]+)\s*:\s*\{([^}]*)\}\s*$/u;
1923
1945
  function \u540D\u524D\u3068\u4E2D\u62EC\u5F27\u306B\u5272\u308B(\u884C) {
@@ -2078,6 +2100,8 @@ function parseTextDslV05(src) {
2078
2100
  let eyebrow = null;
2079
2101
  let eyebrowLine = 0;
2080
2102
  let reveal = null;
2103
+ let direction = null;
2104
+ let directionLine = 0;
2081
2105
  let axes = void 0;
2082
2106
  let axesLine = 0;
2083
2107
  let actors = [];
@@ -2135,6 +2159,24 @@ function parseTextDslV05(src) {
2135
2159
  i += 1;
2136
2160
  continue;
2137
2161
  }
2162
+ if (head.key === "direction") {
2163
+ const v = (head.value ?? "").trim();
2164
+ if (v.length > 0) {
2165
+ const \u89E3\u3051\u305F = resolveDirection(v);
2166
+ if (\u89E3\u3051\u305F !== null) {
2167
+ direction = \u89E3\u3051\u305F;
2168
+ directionLine = line.no;
2169
+ } else {
2170
+ errors.push({
2171
+ line: line.no,
2172
+ message: `direction \u304C\u8AAD\u3081\u307E\u305B\u3093 (\u66F8\u3044\u305F\u5024: ${v})`,
2173
+ hint: `\u4F7F\u3048\u308B\u8A9E = ${DIRECTIONS.join(" / ")} / vertical / horizontal`
2174
+ });
2175
+ }
2176
+ }
2177
+ i += 1;
2178
+ continue;
2179
+ }
2138
2180
  if (head.key === "eyebrow") {
2139
2181
  const v = (head.value ?? "").trim();
2140
2182
  eyebrow = v.length > 0 ? v : null;
@@ -2548,6 +2590,7 @@ function parseTextDslV05(src) {
2548
2590
  type,
2549
2591
  ...eyebrow !== null ? { eyebrow, eyebrowPos: { line: eyebrowLine } } : {},
2550
2592
  ...reveal !== null ? { reveal } : {},
2593
+ ...direction !== null ? { direction, directionPos: { line: directionLine } } : {},
2551
2594
  ...axes !== void 0 ? { axes, axesPos: { line: axesLine } } : {},
2552
2595
  actors,
2553
2596
  flow: flow2,
@@ -5014,6 +5057,7 @@ function compileToCdl(doc, opts) {
5014
5057
  reportActorKindNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5015
5058
  reportMessageOptionNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5016
5059
  reportDocEyebrowNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5060
+ reportDirectionNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5017
5061
  reportDrawNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5018
5062
  reportChartFieldsNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
5019
5063
  reportAxesNotHonored(\u66F8\u3044\u305F\u307E\u307E, opts?.onNotice);
@@ -8232,7 +8276,7 @@ function slugLookup(byName, wanted) {
8232
8276
  return hit;
8233
8277
  }
8234
8278
  function compileFlow(doc) {
8235
- if (doc.animate && doc.animate.phases.length > 0 || \u66F8\u3044\u305F\u7E26\u5217\u306B\u7F6E\u304F("flow", doc)) {
8279
+ if (doc.animate && doc.animate.phases.length > 0 || \u66F8\u3044\u305F\u7E26\u5217\u306B\u7F6E\u304F("flow", doc) || doc.direction !== void 0) {
8236
8280
  return compileGenericWithAnimate(doc, { kind: "flow", laneId: "main", laneWidth: 400 });
8237
8281
  }
8238
8282
  if (doc.actors.length === 0) {
@@ -8258,7 +8302,7 @@ function compileFlow(doc) {
8258
8302
  return flowBuilder.build();
8259
8303
  }
8260
8304
  function compileSwimlane(doc) {
8261
- if (doc.animate && doc.animate.phases.length > 0 || \u66F8\u3044\u305F\u7E26\u5217\u306B\u7F6E\u304F("swimlane", doc)) {
8305
+ if (doc.animate && doc.animate.phases.length > 0 || \u66F8\u3044\u305F\u7E26\u5217\u306B\u7F6E\u304F("swimlane", doc) || doc.direction !== void 0) {
8262
8306
  return compileGenericWithAnimate(doc, { kind: "swimlane", laneWidth: 400 });
8263
8307
  }
8264
8308
  const swim = cdl.swimlane({
@@ -8418,6 +8462,39 @@ function \u5F8C\u308D\u3078\u623B\u308B\u77E2\u5370\u304B(kind, fromId, toId, \u
8418
8462
  if (\u5143 === void 0 || \u5148 === void 0) return false;
8419
8463
  return \u5148 < \u5143;
8420
8464
  }
8465
+ var \u5411\u304D\u3092\u9078\u3079\u308B\u56F3\u7A2E = /* @__PURE__ */ new Set(["flow", "swimlane"]);
8466
+ function \u65E2\u5B9A\u306E\u5411\u304D(kind) {
8467
+ return kind === "flow" || kind === "topology" ? "\u7E26" : "\u6A2A";
8468
+ }
8469
+ function \u4E26\u3079\u308B\u5411\u304D(kind, doc) {
8470
+ if (doc.direction === void 0) return \u65E2\u5B9A\u306E\u5411\u304D(kind);
8471
+ if (!\u5411\u304D\u3092\u9078\u3079\u308B\u56F3\u7A2E.has(kind)) return \u65E2\u5B9A\u306E\u5411\u304D(kind);
8472
+ return doc.direction;
8473
+ }
8474
+ function reportDirectionNotHonored(doc, onNotice) {
8475
+ if (!onNotice) return;
8476
+ if (doc.direction === void 0) return;
8477
+ const \u884C = doc.directionPos?.line ?? doc.pos?.line ?? 0;
8478
+ if (!\u5411\u304D\u3092\u9078\u3079\u308B\u56F3\u7A2E.has(doc.type)) {
8479
+ onNotice({
8480
+ kind: "direction-not-honored",
8481
+ actor: doc.title,
8482
+ line: \u884C,
8483
+ message: `\u66F8\u3044\u305F direction \u306F\u52B9\u304D\u307E\u305B\u3093 (type: ${doc.type} \u306F\u4E26\u3073\u65B9\u305D\u306E\u3082\u306E\u304C\u8AAD\u307F\u65B9\u3092\u6C7A\u3081\u307E\u3059)`,
8484
+ hint: `direction \u3092\u66F8\u3051\u308B\u306E\u306F ${[...\u5411\u304D\u3092\u9078\u3079\u308B\u56F3\u7A2E].join(" / ")} \u3067\u3059`
8485
+ });
8486
+ return;
8487
+ }
8488
+ if (\u66F8\u3044\u305F\u7E26\u5217\u306B\u7F6E\u304F(doc.type, doc)) {
8489
+ onNotice({
8490
+ kind: "direction-not-honored",
8491
+ actor: doc.title,
8492
+ line: \u884C,
8493
+ message: "\u66F8\u3044\u305F direction \u306F\u52B9\u304D\u307E\u305B\u3093 (\u5168\u3066\u306E\u7BB1\u304C\u7E26\u5217\u3092\u66F8\u3044\u3066\u3044\u308B\u306E\u3067\u3001\u305D\u3061\u3089\u304C\u512A\u5148\u3055\u308C\u307E\u3059)",
8494
+ hint: "direction \u3067\u4E26\u3079\u305F\u3044\u6642\u306F\u7BB1\u306E `lane` \u3092\u5916\u3057\u3066\u304F\u3060\u3055\u3044"
8495
+ });
8496
+ }
8497
+ }
8421
8498
  var \u7E26\u5217\u3092\u9078\u3079\u308B\u56F3\u7A2E = /* @__PURE__ */ new Set([
8422
8499
  "flow",
8423
8500
  "topology",
@@ -8475,11 +8552,17 @@ function compileGenericWithAnimate(doc, opts) {
8475
8552
  title: \u7BB1\u306E\u984C(a)
8476
8553
  });
8477
8554
  });
8478
- } else if (kind === "flow" || kind === "topology") {
8555
+ } else if (\u4E26\u3079\u308B\u5411\u304D(kind, doc) === "\u7E26") {
8479
8556
  const lid = opts.laneId ?? "main";
8480
8557
  b.lane(lid, {
8481
8558
  width: laneWidth,
8482
- label: doc.title,
8559
+ /*
8560
+ * **見出しは自然に縦へ積む図種だけ** (#1494)。
8561
+ *
8562
+ * `direction: 縦` を書いた泳法図がここへ来るようになった。 その図に題を渡すと、図の題が
8563
+ * 縦列の見出しとしてもう 1 度出る (実測 = 「認証の流れ」 が題と見出しの 2 箇所に並んだ)。
8564
+ */
8565
+ ...kind === "flow" || kind === "topology" ? { label: doc.title } : {},
8483
8566
  ...kind === "topology" ? { contain: true } : {}
8484
8567
  });
8485
8568
  doc.actors.forEach((a, idx) => {
@@ -9223,7 +9306,9 @@ var ACCEPTED_KEYS = {
9223
9306
  // 順序図で面が動いている間の帯 (#1466)
9224
9307
  "bands",
9225
9308
  // 矢印をいつ出すか (#1470)
9226
- "reveal"
9309
+ "reveal",
9310
+ // 図の並ぶ向き (#1494)
9311
+ "direction"
9227
9312
  ],
9228
9313
  actor: [
9229
9314
  "name",
@@ -9331,7 +9416,9 @@ var \u6B04\u306E\u578B\u8868 = {
9331
9416
  // 順序図で面が動いている間の帯 (#1466)
9332
9417
  bands: "\u4E26\u3073",
9333
9418
  // 矢印をいつ出すか (#1470)
9334
- reveal: "\u975E\u7A7A\u306E\u6587\u5B57\u5217"
9419
+ reveal: "\u975E\u7A7A\u306E\u6587\u5B57\u5217",
9420
+ // 図の並ぶ向き (#1494)
9421
+ direction: "\u975E\u7A7A\u306E\u6587\u5B57\u5217"
9335
9422
  },
9336
9423
  actor: {
9337
9424
  name: "\u5FC5\u9808\u306E\u975E\u7A7A\u6587\u5B57\u5217",
@@ -10652,6 +10739,8 @@ function jsonToDoc(json) {
10652
10739
  bands: json.bands,
10653
10740
  // 矢印をいつ出すか (#1470)
10654
10741
  reveal: json.reveal,
10742
+ // 図の並ぶ向き (#1494)。 JSON は英語で書くので、記法と同じ語に直してから渡す
10743
+ ...json.direction !== void 0 ? { direction: json.direction === "horizontal" ? "\u6A2A" : "\u7E26" } : {},
10655
10744
  pos: p0
10656
10745
  };
10657
10746
  }
@@ -12468,6 +12557,11 @@ var diagram_default = {
12468
12557
  pattern: "^[A-Za-z_][A-Za-z0-9_]*$"
12469
12558
  }
12470
12559
  },
12560
+ direction: {
12561
+ type: "string",
12562
+ enum: ["vertical", "horizontal"],
12563
+ description: "\u56F3\u306E\u4E26\u3076\u5411\u304D\u3002 vertical = 1 \u3064\u306E\u7E26\u5217\u306B\u7A4D\u3080\u3002 horizontal = 1 \u4EBA\u305A\u3064\u7E26\u5217\u3092\u4F5C\u308B\u3002 \u52B9\u304F\u306E\u306F flow \u3068 swimlane \u3060\u3051\u3002"
12564
+ },
12471
12565
  reveal: {
12472
12566
  type: "string",
12473
12567
  enum: ["phase", "all"],