@cardenelabs/dragon 0.43.0 → 0.45.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 (97) hide show
  1. package/README.md +21 -0
  2. package/dist/cli.cjs +6804 -5032
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +6804 -5032
  5. package/dist/cli.js.map +1 -1
  6. package/dist/export.cjs +7172 -5536
  7. package/dist/export.cjs.map +1 -1
  8. package/dist/export.d.cts +1 -1
  9. package/dist/export.d.ts +1 -1
  10. package/dist/export.js +7171 -5537
  11. package/dist/export.js.map +1 -1
  12. package/dist/index.cjs +12244 -10449
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +55 -3
  15. package/dist/index.d.ts +55 -3
  16. package/dist/index.js +12244 -10449
  17. package/dist/index.js.map +1 -1
  18. package/dist/{ink-B6s_SMXG.d.cts → ink-DeDtzaTL.d.cts} +27 -3
  19. package/dist/{ink-B6s_SMXG.d.ts → ink-DeDtzaTL.d.ts} +27 -3
  20. package/dist/light/chunk-6ZUKJ3VO.js +489 -0
  21. package/dist/light/chunk-6ZUKJ3VO.js.map +1 -0
  22. package/dist/light/chunk-CLS6JVKK.cjs +84 -0
  23. package/dist/light/chunk-CLS6JVKK.cjs.map +1 -0
  24. package/dist/light/chunk-JNSHZTPF.js +1141 -0
  25. package/dist/light/chunk-JNSHZTPF.js.map +1 -0
  26. package/dist/light/chunk-OUQ44P45.cjs +489 -0
  27. package/dist/light/chunk-OUQ44P45.cjs.map +1 -0
  28. package/dist/light/chunk-VRAW7VAQ.cjs +1141 -0
  29. package/dist/light/chunk-VRAW7VAQ.cjs.map +1 -0
  30. package/dist/light/chunk-YDKPEKGZ.js +84 -0
  31. package/dist/light/chunk-YDKPEKGZ.js.map +1 -0
  32. package/dist/light/git-C4RVNFT6.js +637 -0
  33. package/dist/light/git-C4RVNFT6.js.map +1 -0
  34. package/dist/light/git-I7D7RIW2.cjs +637 -0
  35. package/dist/light/git-I7D7RIW2.cjs.map +1 -0
  36. package/dist/light/index.cjs +9885 -0
  37. package/dist/light/index.cjs.map +1 -0
  38. package/dist/light/index.d.cts +976 -0
  39. package/dist/light/index.d.ts +976 -0
  40. package/dist/light/index.js +9885 -0
  41. package/dist/light/index.js.map +1 -0
  42. package/dist/light/lineup-FAIKTH3Y.cjs +283 -0
  43. package/dist/light/lineup-FAIKTH3Y.cjs.map +1 -0
  44. package/dist/light/lineup-YEG4HHEI.js +283 -0
  45. package/dist/light/lineup-YEG4HHEI.js.map +1 -0
  46. package/dist/light/state-P3LIVI3K.js +335 -0
  47. package/dist/light/state-P3LIVI3K.js.map +1 -0
  48. package/dist/light/state-ZZUK6AQT.cjs +335 -0
  49. package/dist/light/state-ZZUK6AQT.cjs.map +1 -0
  50. package/dist/light/time-64DJKYAL.cjs +719 -0
  51. package/dist/light/time-64DJKYAL.cjs.map +1 -0
  52. package/dist/light/time-B5WUQOFP.js +719 -0
  53. package/dist/light/time-B5WUQOFP.js.map +1 -0
  54. package/dist/light/tree-5HPREYW2.js +478 -0
  55. package/dist/light/tree-5HPREYW2.js.map +1 -0
  56. package/dist/light/tree-66EH4QVI.cjs +478 -0
  57. package/dist/light/tree-66EH4QVI.cjs.map +1 -0
  58. package/dist/node.cjs +1932 -680
  59. package/dist/node.cjs.map +1 -1
  60. package/dist/node.js +1932 -680
  61. package/dist/node.js.map +1 -1
  62. package/dist/player.global.js +3 -3
  63. package/package.json +14 -2
  64. package/src/api.ts +71 -0
  65. package/src/field-messages.ts +6 -0
  66. package/src/figure-text.ts +4 -0
  67. package/src/index.ts +6 -65
  68. package/src/kinds/all.ts +16 -0
  69. package/src/kinds/git.ts +3 -0
  70. package/src/kinds/lineup.ts +3 -0
  71. package/src/kinds/registry.ts +46 -0
  72. package/src/kinds/state.ts +2 -0
  73. package/src/kinds/time.ts +3 -0
  74. package/src/kinds/tree.ts +3 -0
  75. package/src/layout/git.ts +0 -1
  76. package/src/layout/lineup.ts +218 -0
  77. package/src/layout/time.ts +0 -1
  78. package/src/layout/tree.ts +0 -1
  79. package/src/light.ts +31 -0
  80. package/src/look/values.ts +31 -2
  81. package/src/messages.ts +54 -0
  82. package/src/parser.ts +123 -1
  83. package/src/player-global.ts +3 -0
  84. package/src/player.ts +1 -1
  85. package/src/printer.ts +30 -1
  86. package/src/render/draw.ts +731 -0
  87. package/src/render/lineup.ts +184 -0
  88. package/src/render/parts.ts +19 -7
  89. package/src/render/svg.ts +4 -697
  90. package/src/render/time.ts +1 -4
  91. package/src/render/tree.ts +3 -2
  92. package/src/schema.ts +52 -4
  93. package/src/schemas/diagram.schema.json +145 -22
  94. package/src/schemas/validate-diagram.js +1 -1
  95. package/src/timeline.ts +14 -0
  96. package/src/view.ts +1 -1
  97. package/src/words.ts +15 -2
@@ -124,6 +124,9 @@ export const TYPE = {
124
124
  rootHash: text(15, 700, "mono"),
125
125
  rootName: text(11, 700),
126
126
  treeCard: text(11.5, 650),
127
+ /** 列の図 (#3239) の、チップの字と札の字 */
128
+ chip: text(10.5, 700, "mono"),
129
+ stamp: text(11, 700),
127
130
  /**
128
131
  * 時間軸の図 (#3165)。拡大の帯の列の上の字、印の列の名前、時刻の字、区切りの名前と目盛りの番号の範囲、
129
132
  * 節目の名札と状態、範囲の括弧の字、空きの枠の字、物差しの線の字。和文を含む字は同じ大きさと太さの和文の字で描く
@@ -248,6 +251,26 @@ export const LOOK = {
248
251
  color: "violet",
249
252
  rootColor: "green",
250
253
  },
254
+ /**
255
+ * 列の図 (#3239)。step 2 で本人が選んだ見本の「列の図」の形で、1 列 12 枚の図の幅が携帯の幅で全体を見せられる 400 に収まる寸法にする。
256
+ * 列は左右の余白 `padX`、高さ `h`、角の丸み `radius`。列の名前と右上の字の基準線は列の上端から `textY`、チップの上端は列の上端から `trackY`、
257
+ * 名前と右上の字の間の下限は `textGap`、選ばなかった列の濃さは `faint`。
258
+ * `chip` はチップの幅の下限 `w`、高さ `h`、隣のチップとの間 `gap`、角の丸み `radius`、字の左右の余白 `padX`。字が幅を超える図は全てのチップの幅を広げる。
259
+ * `seal` は封で、チップの並びの外へ `over` 広げ、角の丸み `radius`、縞の幅 `stripe`。
260
+ * `stamp` は札で、高さ `h`、字の左右の余白 `padX`、角の丸み `radius`、傾き `tilt`、色 `color`
261
+ */
262
+ lineup: {
263
+ padX: 12,
264
+ h: 61,
265
+ radius: 10,
266
+ textY: 20,
267
+ trackY: 33,
268
+ textGap: 10,
269
+ faint: 0.35,
270
+ chip: { w: 25, h: 18, gap: 4, radius: 4, padX: 3 },
271
+ seal: { over: 3, radius: 5, stripe: 7 },
272
+ stamp: { h: 22, padX: 8, radius: 5, tilt: -4, color: "green" },
273
+ },
251
274
  /**
252
275
  * 時間軸の図 (#3165)。見本帳の試作 (`scenes/finality.js`) の寸法を写す。
253
276
  * 図の幅は `width` で、時間軸は左の `axisX` から右の余白 `right` の手前まで。印の列の名前が長い時は、名前の右に `gutterGap` を空けて軸を右へ寄せる。
@@ -355,6 +378,7 @@ export const LOOK = {
355
378
  tree: 1.5,
356
379
  treeTrail: 2.6,
357
380
  treeCon: 1.3,
381
+ stamp: 2,
358
382
  },
359
383
  shadow: { near: 0.8, far: 4, nearY: 1, farY: 3 },
360
384
  mini: { w: 168, pad: 8, title: 14, inset: 12, radius: 10 },
@@ -369,8 +393,8 @@ export const LOOK = {
369
393
  */
370
394
  follow: { aspect: 0.75, minH: 320, fitMinH: 160, ease: 0.6, narrow: 440, badgeRoom: 8, headRoom: 10, head: { pad: 8, h: 40, nameY: 17, subY: 31 } },
371
395
  /** 色を混ぜる割合 (%) */
372
- /** `time` から始まる値は時間軸の図 (#3165) の、区切りの地、範囲の囲みの地、空きの枠の地、拡大の点線の濃さ */
373
- mix: { slot: 45, icon: 14, regionIcon: 16, regionIconEdge: 34, cap: 12, capEdge: 42, badgePast: 14, badgePastEdge: 70, mini: 62, miniBand: 16, miniBandEdge: 36, view: 6, side: 4, sideEdge: 36, ghostEdge: 60, path: 55, past: 72, timeShade: 3.5, timeSpan: 6, timeEmpty: 8, timeGuide: 50 },
396
+ /** `time` から始まる値は時間軸の図 (#3165) の、区切りの地、範囲の囲みの地、空きの枠の地、拡大の点線の濃さ。`chip` と `seal` から始まる値は列の図 (#3239) の、色を持たないチップの地と封の縞の濃さ */
397
+ mix: { slot: 45, icon: 14, regionIcon: 16, regionIconEdge: 34, cap: 12, capEdge: 42, badgePast: 14, badgePastEdge: 70, mini: 62, miniBand: 16, miniBandEdge: 36, view: 6, side: 4, sideEdge: 36, ghostEdge: 60, path: 55, past: 72, timeShade: 3.5, timeSpan: 6, timeEmpty: 8, timeGuide: 50, chipPlain: 34, sealDark: 60, sealLight: 34 },
374
398
  /** 字の並びの基準線を、置きたい高さの真ん中からどれだけ下げるか */
375
399
  baseline: { label: 3.8, badge: 3.5, carrier: 3.7, stripTitle: 4.5, tag: 3.6, action: 3.8, mark: 4 },
376
400
  /** 浮いて出る物が下から上がる長さと、弾んで出る物の始まりの大きさ */
@@ -424,6 +448,11 @@ export const MOTION = {
424
448
  * `after` は針が止まってから次の出来事を起こすまで、`reset` は区切りが替わって物差しが 0 に戻る長さ
425
449
  */
426
450
  time: { axis: 11.5, unitMin: 0.12, unitMax: 0.4, wait: 0.15, after: 0.15, reset: 0.05 },
451
+ /**
452
+ * 列の図 (#3239)。`slide` はチップが滑る長さ、`seal` は封が列を覆う長さ、`stagger` は同じ段の出来事を起こす間、
453
+ * `cut` はチップと封が一瞬で入れ替わる長さ
454
+ */
455
+ lineup: { slide: 0.7, seal: 0.6, stagger: 0.2, cut: 0.01 },
427
456
  } as const;
428
457
 
429
458
  /** 見せ方を決める字の大きさ。全体を枠に収めた時の箱の名前がこれを下回ると寄って追う。 */
package/src/messages.ts CHANGED
@@ -102,6 +102,28 @@ export interface Messages {
102
102
  twoParents: (id: string) => string;
103
103
  /** 最後の段を終えて、親を持たない箱が根の外に残った */
104
104
  manyRoots: (id: string, root: string) => string;
105
+ /** 列の図だけの行 (`item`、`line`、`seal`、`open`、`pick`、`stamp`) を、別の種類の図に書いた (#3239) */
106
+ lineupOnly: (word: string) => string;
107
+ lineupNoGroup: string;
108
+ lineupNoEdge: string;
109
+ lineupNoAct: string;
110
+ noItems: string;
111
+ itemShape: string;
112
+ lineShape: string;
113
+ /** `seal`、`open`、`pick` の行の形 */
114
+ laneShape: (word: string) => string;
115
+ stampShape: string;
116
+ /** チップの字が上限の字数を超えた */
117
+ labelTooLong: (limit: number) => string;
118
+ /** `line` の行に、宣言していないチップを書いた */
119
+ noSuchItem: (id: string) => string;
120
+ /** 同じ `line` の行に、同じチップを 2 度書いた */
121
+ itemTwice: (id: string) => string;
122
+ /** `line` の行のチップが、1 列の上限を超えた */
123
+ laneFull: (lane: string, limit: number) => string;
124
+ lineOnSealed: (lane: string) => string;
125
+ sealTwice: (lane: string) => string;
126
+ openUnsealed: (lane: string) => string;
105
127
  /** 時間軸の図の宣言の行を 2 つ書いた */
106
128
  timeTwice: (word: string) => string;
107
129
  noScale: string;
@@ -233,6 +255,22 @@ const ja = (): Messages => {
233
255
  notTreeBox: (id) => `${id} は box の行で置いた箱で、木の箱でない。子は leaf か node で書いた名札にする`,
234
256
  twoParents: (id) => `${id} はもう別の親の子になっている。木の箱の親は 1 つだけ`,
235
257
  manyRoots: (id, root) => `${id} が親を持たないまま残る。木の根は 1 つだけで、${id} も ${root} も最後に 1 つの根へ組む`,
258
+ lineupOnly: (word) => `${word} の行は lineup (列の図) でだけ書ける`,
259
+ lineupNoGroup: "lineup (列の図) には group を書けない。列は box の行で宣言する",
260
+ lineupNoEdge: "lineup (列の図) には線の行を書けない。チップは line の行で列の並びを書くと動く",
261
+ lineupNoAct: "lineup (列の図) には act の行を書けない。列の右上の字は note の行で書き換える",
262
+ noItems: "item の行でチップを 1 つ以上宣言する",
263
+ itemShape: "item は item <名札>, <名札> [color: <色>, label: <字>] の形で書く",
264
+ lineShape: "line は line <列>: <チップ>, <チップ> の形で書く",
265
+ laneShape: (word) => `${word} は ${word} <列> の形で書く`,
266
+ stampShape: "stamp は stamp <列>: <字> の形で書く",
267
+ labelTooLong: (limit) => `label は ${limit} 字までにする`,
268
+ noSuchItem: (id) => `${id} というチップは宣言していない`,
269
+ itemTwice: (id) => `${id} はこの行に 2 度書いている。同じ列に同じチップは 1 枚だけ`,
270
+ laneFull: (lane, limit) => `${lane} の列に並べられるチップは ${limit} 枚まで`,
271
+ lineOnSealed: (lane) => `${lane} の列は封をしているので並びを書けない。先に open で開ける`,
272
+ sealTwice: (lane) => `${lane} の列にはもう封をしている`,
273
+ openUnsealed: (lane) => `${lane} の列には封をしていない`,
236
274
  timeTwice: (word) => `${word} は 1 つだけ宣言する`,
237
275
  noScale: "scale の行で目盛りを宣言する",
238
276
  noRows: "row の行で印の列を 1 つ以上宣言する",
@@ -356,6 +394,22 @@ const en = (): Messages => {
356
394
  notTreeBox: (id) => `${id} is a box from a box line, not a tree box. A child must be an id written with leaf or node`,
357
395
  twoParents: (id) => `${id} is already a child of another node. A tree box has only one parent`,
358
396
  manyRoots: (id, root) => `${id} is left without a parent. A tree has one root, so join ${id} and ${root} under one root by the end`,
397
+ lineupOnly: (word) => `${word} lines can be written only in lineup diagrams`,
398
+ lineupNoGroup: "A lineup diagram takes no group. Declare the lanes with box lines",
399
+ lineupNoEdge: "A lineup diagram takes no edge lines. Chips move when a line line rewrites a lane",
400
+ lineupNoAct: "A lineup diagram takes no act lines. Rewrite the text at the top right of a lane with a note line",
401
+ noItems: "Declare at least one chip with an item line",
402
+ itemShape: "Write an item as item <id>, <id> [color: <color>, label: <text>]",
403
+ lineShape: "Write a line as line <lane>: <chip>, <chip>",
404
+ laneShape: (word) => `Write ${word} as ${word} <lane>`,
405
+ stampShape: "Write a stamp as stamp <lane>: <text>",
406
+ labelTooLong: (limit) => `A label is at most ${limit} characters`,
407
+ noSuchItem: (id) => `The chip ${id} is not declared`,
408
+ itemTwice: (id) => `${id} is written twice on this line. A lane holds one of each chip`,
409
+ laneFull: (lane, limit) => `The lane ${lane} holds at most ${limit} chips`,
410
+ lineOnSealed: (lane) => `The lane ${lane} is sealed, so its order cannot be written. Open it first`,
411
+ sealTwice: (lane) => `The lane ${lane} is already sealed`,
412
+ openUnsealed: (lane) => `The lane ${lane} is not sealed`,
359
413
  timeTwice: (word) => `Declare only one ${word}`,
360
414
  noScale: "Declare the scale with a scale line",
361
415
  noRows: "Declare at least one row with a row line",
package/src/parser.ts CHANGED
@@ -55,6 +55,11 @@
55
55
  * 前に書いた葉か親を子にして親を組む。箱は書いた段で現れ、親は 1 つだけ持てる。最後の段を終えた時に親を持たない木の箱は根の 1 つだけ。
56
56
  * 線の端には木の箱も `box` の箱も書ける。木の図に区画 (`group`) は書けず、`leaf` と `node` の行は木の図でだけ書ける。
57
57
  *
58
+ * 列の図 (`lineup`、#3239) は、`box` の行が列になり、最初の `step` より前に `item <名札>, <名札> [color: <色>, label: <字>]` でチップを宣言する。
59
+ * 段の中で `line <列>: <チップ>, <チップ>` と書くと列の並びが替わり、`seal <列>` で封をし、`open <列>` で開け、`pick <列>` で列を選び、
60
+ * `stamp <列>: <字>` で札を押す。列の図に区画 (`group`) と線と `act` の行は書けない。封をした列の並びは、開けるまで書けない。
61
+ * `item`、`line`、`seal`、`open`、`pick`、`stamp` の行は列の図でだけ書ける。
62
+ *
58
63
  * 行の頭の語と同じ綴りの名札 (`end` や `step`) も書ける。名札の次に `->` が来る行は線と読む。
59
64
  * 誤りは最初の 1 つで止め、行と列を示す。誤りの文の言葉は呼ぶ側が渡す。
60
65
  */
@@ -69,6 +74,7 @@ import {
69
74
  type GitBranch,
70
75
  type GitCommit,
71
76
  type LabelSide,
77
+ type LineupItem,
72
78
  type Region,
73
79
  type StatePath,
74
80
  type Step,
@@ -92,6 +98,10 @@ import {
92
98
  HEAD,
93
99
  HEADS,
94
100
  KINDS,
101
+ LABEL_MOST,
102
+ LANE_ATTRS,
103
+ LANE_MOST,
104
+ LINEUP_HEADS,
95
105
  MERGE,
96
106
  type NotationLang,
97
107
  NOW,
@@ -144,6 +154,10 @@ const CUT = new RegExp(`^([^\\s[]+)\\s+${FROM}(?:\\s+([^\\s[]+))?\\s*$`, "du");
144
154
  /** 木の図の `leaf` の行の名札と、`node` の行の名札と `of` */
145
155
  const LEAF = /^leaf\s+([^\s[]+)/du;
146
156
  const NODE = new RegExp(`^node\\s+([^\\s[]+)\\s+${OF}\\s+`, "du");
157
+ /** 列の図の、`line <列>:` と `stamp <列>:` の行の列と、`seal`、`open`、`pick` の行の列 */
158
+ const ORDER = /^line\s+([^\s:[]+)\s*:/du;
159
+ const STAMP = /^stamp\s+([^\s:[]+)\s*:/du;
160
+ const ON_LANE = /^(?:seal|open|pick)\s+(\S+)\s*$/du;
147
161
  /** commit の hash。原本の JSON の hash の形と同じ */
148
162
  const HASH = /^[0-9a-f]{4,40}$/u;
149
163
  /** 箱の飛び先と段の出典の URL。原本の JSON の URL の形と同じ */
@@ -366,6 +380,10 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
366
380
  const isGit = kind === "git";
367
381
  const isTime = kind === "time";
368
382
  const isTree = kind === "tree";
383
+ const isLineup = kind === "lineup";
384
+ /** 列の図で宣言したチップと、今封をしている列 (#3239) */
385
+ const items: LineupItem[] = [];
386
+ const sealed = new Set<string>();
369
387
  /** 木の図で書いた木の箱と、書いた行と名札の位置。子の箱から親の名札 */
370
388
  const trees = new Map<string, { source: SourceLine; at: number }>();
371
389
  const parents = new Map<string, string>();
@@ -472,6 +490,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
472
490
  // 名札の次に `->` が来る行は、名札が行の頭の語と同じ綴りでも線と読む
473
491
  const edge = EDGE.exec(text);
474
492
  if (edge) {
493
+ if (isLineup) throw fail(source, 0, m.lineupNoEdge);
475
494
  // 状態遷移図の最初の step より前の線は、移れる道の地図
476
495
  if (isState && !building) paths.push(readPath(source, edge));
477
496
  else inStep(source).events.push(readEdge(source, edge));
@@ -487,6 +506,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
487
506
  if (!isGit && (word === "branch" || word === "commit")) throw fail(source, 0, m.gitOnly(word));
488
507
  if (!isTime && isOneOf(TIME_HEADS, word)) throw fail(source, 0, m.timeOnly(word));
489
508
  if (!isTree && isOneOf(TREE_HEADS, word)) throw fail(source, 0, m.treeOnly(word));
509
+ if (!isLineup && isOneOf(LINEUP_HEADS, word)) throw fail(source, 0, m.lineupOnly(word));
490
510
  if (!isOneOf(HEADS, word)) {
491
511
  const old = oldForm(text, building !== undefined);
492
512
  throw fail(source, 0, old ? m.oldForm(old.word, old.shape) : m.unknownHead(word));
@@ -530,6 +550,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
530
550
  inStep(source).sources.push(readSource(source));
531
551
  break;
532
552
  case "act": {
553
+ if (isLineup) throw fail(source, 0, m.lineupNoAct);
533
554
  const step = inStep(source);
534
555
  const on = readOnBox(source, word, m.actShape);
535
556
  step.events.push({ type: "action", box: on.box, label: on.text });
@@ -587,6 +608,26 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
587
608
  step.events.push(readNode(source));
588
609
  break;
589
610
  }
611
+ case "item":
612
+ readItem(source);
613
+ break;
614
+ case "line": {
615
+ const step = inStep(source);
616
+ step.events.push(readOrder(source));
617
+ break;
618
+ }
619
+ case "seal":
620
+ case "open":
621
+ case "pick": {
622
+ const step = inStep(source);
623
+ step.events.push(readOnLane(source, word));
624
+ break;
625
+ }
626
+ case "stamp": {
627
+ const step = inStep(source);
628
+ step.events.push(readStamp(source));
629
+ break;
630
+ }
590
631
  }
591
632
  }
592
633
  if (group) throw fail(group.source, 0, m.unclosedGroup(group.id));
@@ -595,6 +636,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
595
636
 
596
637
  if (isGit && branches.length === 0) throw fail(head, 0, m.noBranches);
597
638
  if (isTree && trees.size === 0) throw fail(head, 0, m.noLeaves);
639
+ if (isLineup && items.length === 0) throw fail(head, 0, m.noItems);
598
640
  if (boxes.length === 0 && !isGit && !isTime && !isTree) throw fail(head, 0, m.noBoxes);
599
641
  if (steps.length === 0) throw fail(head, 0, m.noSteps);
600
642
  // 木の形は全ての行を読んでから確かめる。親を持たない木の箱が 2 つ以上なら、書いた順で 2 つ目を示す
@@ -615,6 +657,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
615
657
  ...(kind === "sequence" ? { sequence: { lifelines: boxes.map((box) => box.id) } } : {}),
616
658
  ...(paths.length > 0 ? { state: { paths } } : {}),
617
659
  ...(isGit ? { git: { branches } } : {}),
660
+ ...(isLineup ? { lineup: { items } } : {}),
618
661
  ...(isTime && scale
619
662
  ? {
620
663
  time: {
@@ -818,6 +861,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
818
861
  beforeSteps(source);
819
862
  if (isGit) throw fail(source, 0, m.gitNoGroup);
820
863
  if (isTree) throw fail(source, 0, m.treeNoGroup);
864
+ if (isLineup) throw fail(source, 0, m.lineupNoGroup);
821
865
  if (group) throw fail(source, 0, m.nestedGroup);
822
866
  const declared = readDeclared(source, "group", ATTRS.group, m);
823
867
  if (regions.some((region) => region.id === declared.id)) {
@@ -833,7 +877,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
833
877
  /** `box` の行。開いている `group` の中なら、その区画に置く */
834
878
  function readBox(source: SourceLine): void {
835
879
  beforeSteps(source);
836
- const declared = readDeclared(source, "box", ATTRS.box, m);
880
+ const declared = readDeclared(source, "box", isLineup ? LANE_ATTRS : ATTRS.box, m);
837
881
  notReserved(source, declared.id, declared.idAt);
838
882
  declare(source, declared.id, declared.idAt);
839
883
  firstBox ??= source;
@@ -986,6 +1030,84 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
986
1030
  return hash?.value;
987
1031
  }
988
1032
 
1033
+ /** `from` から `to` の前までの、`,` で区切った名札と、それぞれの位置 */
1034
+ function namesAt(source: SourceLine, from: number, to: number, shape: string): { value: string; at: number }[] {
1035
+ const text = source.text;
1036
+ const names: { value: string; at: number }[] = [];
1037
+ for (let i = from; ; ) {
1038
+ const start = skipSpaces(text, i);
1039
+ const comma = text.indexOf(",", start);
1040
+ const end = comma < 0 || comma > to ? to : comma;
1041
+ const value = text.slice(start, end).trim();
1042
+ if (value === "") throw fail(source, start, shape);
1043
+ if (!ID.test(value)) throw fail(source, start, m.badId(value));
1044
+ names.push({ value, at: start });
1045
+ if (end >= to) return names;
1046
+ i = end + 1;
1047
+ }
1048
+ }
1049
+
1050
+ /** 列の図の `item <名札>, <名札> [color: <色>, label: <字>]` の行。並べた名札ごとに、同じ色と字のチップを宣言する */
1051
+ function readItem(source: SourceLine): void {
1052
+ beforeSteps(source);
1053
+ const open = source.text.indexOf("[");
1054
+ const end = open < 0 ? source.text.length : open;
1055
+ const attrs = open < 0 ? new Map<string, Attr>() : readAttrs(source, open, ATTRS.item, m);
1056
+ const color = attrs.get("color");
1057
+ if (color && !isOneOf(COLORS, color.value)) throw fail(source, color.at, m.badColor);
1058
+ const label = attrs.get("label");
1059
+ if (label && [...label.value].length > LABEL_MOST) throw fail(source, label.at, m.labelTooLong(LABEL_MOST));
1060
+ for (const { value, at } of namesAt(source, "item".length, end, m.itemShape)) {
1061
+ declare(source, value, at);
1062
+ items.push({ id: value, ...(color ? { color: color.value as Color } : {}), ...(label ? { label: label.value } : {}) });
1063
+ }
1064
+ }
1065
+
1066
+ /** 列の図の `line <列>: <チップ>, <チップ>` の行。チップは宣言したチップで、列に 1 枚ずつ、上限まで。封をした列には書けない */
1067
+ function readOrder(source: SourceLine): DiagramEvent {
1068
+ const found = ORDER.exec(source.text);
1069
+ const lane = found?.[1];
1070
+ if (!found || lane === undefined) throw fail(source, 0, m.lineShape);
1071
+ const at = found.indices?.[1]?.[0] ?? 0;
1072
+ const box = boxAt(source, lane, at);
1073
+ if (sealed.has(box)) throw fail(source, at, m.lineOnSealed(box));
1074
+ const chips = namesAt(source, found[0].length, source.text.length, m.lineShape);
1075
+ const seen = new Set<string>();
1076
+ chips.forEach(({ value, at: chipAt }, k) => {
1077
+ if (!items.some((item) => item.id === value)) throw fail(source, chipAt, m.noSuchItem(value));
1078
+ if (seen.has(value)) throw fail(source, chipAt, m.itemTwice(value));
1079
+ if (k >= LANE_MOST) throw fail(source, chipAt, m.laneFull(box, LANE_MOST));
1080
+ seen.add(value);
1081
+ });
1082
+ return { type: "line", box, items: chips.map((chip) => chip.value) };
1083
+ }
1084
+
1085
+ /** 列の図の `seal <列>`、`open <列>`、`pick <列>` の行。封は 1 列に 1 つで、封をした列だけを開けられる */
1086
+ function readOnLane(source: SourceLine, word: "seal" | "open" | "pick"): DiagramEvent {
1087
+ const found = ON_LANE.exec(source.text);
1088
+ const lane = found?.[1];
1089
+ if (!found || lane === undefined) throw fail(source, 0, m.laneShape(word));
1090
+ const at = found.indices?.[1]?.[0] ?? 0;
1091
+ const box = boxAt(source, lane, at);
1092
+ if (word === "seal") {
1093
+ if (sealed.has(box)) throw fail(source, at, m.sealTwice(box));
1094
+ sealed.add(box);
1095
+ }
1096
+ if (word === "open" && !sealed.delete(box)) throw fail(source, at, m.openUnsealed(box));
1097
+ return { type: word, box };
1098
+ }
1099
+
1100
+ /** 列の図の `stamp <列>: <字>` の行 */
1101
+ function readStamp(source: SourceLine): DiagramEvent {
1102
+ const found = STAMP.exec(source.text);
1103
+ const lane = found?.[1];
1104
+ if (!found || lane === undefined) throw fail(source, 0, m.stampShape);
1105
+ const box = boxAt(source, lane, found.indices?.[1]?.[0] ?? 0);
1106
+ const named = readName(source, found[0].length, m);
1107
+ if (named.value === "" || named.rest < source.text.length) throw fail(source, 0, m.stampShape);
1108
+ return { type: "stamp", box, text: named.value };
1109
+ }
1110
+
989
1111
  /** `strip <題>: <欄>, <欄>` の行 */
990
1112
  function readStrip(source: SourceLine): void {
991
1113
  beforeSteps(source);
@@ -1,4 +1,7 @@
1
1
  /**
2
2
  * HTML に書き出した頁へ埋める script の入口。1 file に束ね、`DragonPlayer.mountDiagram` として出す。
3
+ * 書き出した頁は外を読めないので、全ての図の種類の部品を持つ (#3248)。
3
4
  */
5
+ import "./kinds/all";
6
+
4
7
  export { mountDiagram } from "./player";
package/src/player.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  import { FIGURE_TEXT } from "./figure-text";
19
19
  import type { Rect } from "./layout/scene";
20
20
  import { FONT_VARS, LOOK, paletteVars, type TextStyle, TYPE } from "./look/values";
21
- import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/svg";
21
+ import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/draw";
22
22
  import type { Span } from "./timeline";
23
23
  import { chooseView } from "./view";
24
24
 
package/src/printer.ts CHANGED
@@ -14,9 +14,10 @@
14
14
  * 時間軸の図 (#3165) は、目盛りと区切りと印の列と節目と拡大の範囲の行を箱より前に書き、物差しの欄の後ろに `[meter: <割合>]` を書く。
15
15
  * 時間軸の図の `note` は属性を持てるので、`[` を含む字を `"` で囲む。
16
16
  * 木の図 (#3233) の葉と親は、段の中に `leaf` と `node … of …` の行で書く。
17
+ * 列の図 (#3239) のチップは箱の後ろに `item` の行で書き、色が同じで字を持たないチップが続く所は 1 行に並べる。
17
18
  * 段の出典 (#3199) は `say` と `code` の後ろ、段の中で起きることより前に、JSON の並びのまま 1 つずつ `source` の行に書く。
18
19
  */
19
- import type { Box, Diagram, DiagramEvent, Region, TimeSpec } from "./schema";
20
+ import type { Box, Diagram, DiagramEvent, LineupItem, Region, TimeSpec } from "./schema";
20
21
  import { AT, COPY, FROM, MERGE, NOW, OF, ON } from "./words";
21
22
 
22
23
  const quote = (text: string): string => `"${text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
@@ -94,9 +95,36 @@ function event(e: DiagramEvent, kind: Diagram["kind"]): string {
94
95
  return `leaf ${e.id}${attrs([["hash", e.hash]])}`;
95
96
  case "node":
96
97
  return `node ${e.id} ${OF} ${e.children.join(", ")}${attrs([["hash", e.hash]])}`;
98
+ case "line":
99
+ return `line ${e.box}: ${e.items.join(", ")}`;
100
+ case "seal":
101
+ case "open":
102
+ case "pick":
103
+ return `${e.type} ${e.box}`;
104
+ case "stamp":
105
+ return `stamp ${e.box}: ${name(e.text)}`;
97
106
  }
98
107
  }
99
108
 
109
+ /** 列の図のチップの宣言の行。色が同じで字を持たないチップが続く所は 1 行に並べる */
110
+ function itemLines(items: LineupItem[]): string {
111
+ const rows: LineupItem[][] = [];
112
+ for (const item of items) {
113
+ const row = rows.at(-1);
114
+ if (row && item.label === undefined && row[0]?.label === undefined && row[0]?.color === item.color) row.push(item);
115
+ else rows.push([item]);
116
+ }
117
+ return rows
118
+ .map(
119
+ (row) =>
120
+ `item ${row.map((item) => item.id).join(", ")}${attrs([
121
+ ["color", row[0]?.color],
122
+ ["label", row[0]?.label],
123
+ ])}`,
124
+ )
125
+ .join("\n");
126
+ }
127
+
100
128
  /** 時間軸の図の目盛りと区切りと印の列と節目と拡大の範囲の宣言の塊 */
101
129
  function timeBlocks(time: TimeSpec): string[] {
102
130
  const head = [
@@ -155,6 +183,7 @@ export function printNotation(diagram: Diagram): string {
155
183
  ...(branches.length > 0 ? [branches.join("\n")] : []),
156
184
  ...(diagram.time ? timeBlocks(diagram.time) : []),
157
185
  ...declarations(diagram),
186
+ ...(diagram.lineup && diagram.lineup.items.length > 0 ? [itemLines(diagram.lineup.items)] : []),
158
187
  ];
159
188
  if (diagram.strip) {
160
189
  const meters = new Map((diagram.strip.meters ?? []).map((m) => [m.field, m.line]));