@cardenelabs/dragon 0.43.0 → 0.44.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/cli.cjs +2337 -627
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2337 -627
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +2193 -619
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/export.js +2193 -619
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +2377 -644
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -3
- package/dist/index.d.ts +55 -3
- package/dist/index.js +2377 -644
- package/dist/index.js.map +1 -1
- package/dist/{ink-B6s_SMXG.d.cts → ink-DeDtzaTL.d.cts} +27 -3
- package/dist/{ink-B6s_SMXG.d.ts → ink-DeDtzaTL.d.ts} +27 -3
- package/dist/node.cjs +1932 -680
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +1932 -680
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +3 -3
- package/package.json +1 -1
- package/src/field-messages.ts +6 -0
- package/src/index.ts +4 -0
- package/src/layout/lineup.ts +219 -0
- package/src/look/values.ts +31 -2
- package/src/messages.ts +54 -0
- package/src/parser.ts +123 -1
- package/src/printer.ts +30 -1
- package/src/render/lineup.ts +184 -0
- package/src/render/parts.ts +16 -7
- package/src/render/svg.ts +34 -6
- package/src/render/tree.ts +3 -2
- package/src/schema.ts +52 -4
- package/src/schemas/diagram.schema.json +145 -22
- package/src/schemas/validate-diagram.js +1 -1
- package/src/timeline.ts +14 -0
- package/src/words.ts +15 -2
package/package.json
CHANGED
package/src/field-messages.ts
CHANGED
|
@@ -25,9 +25,11 @@ export interface FieldMessages {
|
|
|
25
25
|
enum: (values: readonly string[]) => string;
|
|
26
26
|
type: (type: string) => string;
|
|
27
27
|
minLength: (limit: number) => string;
|
|
28
|
+
maxLength: (limit: number) => string;
|
|
28
29
|
/** 書けない字を読めない形の決まりでは `undefined` */
|
|
29
30
|
pattern: (forbidden: Forbidden | undefined) => string;
|
|
30
31
|
minItems: (limit: number) => string;
|
|
32
|
+
maxItems: (limit: number) => string;
|
|
31
33
|
minimum: (limit: number) => string;
|
|
32
34
|
const: (value: string) => string;
|
|
33
35
|
/** どの欄の組み合わせか判らない場所では `undefined` */
|
|
@@ -80,9 +82,11 @@ const ja: FieldMessages = {
|
|
|
80
82
|
enum: (values) => `${values.join(" / ")} のどれかにする`,
|
|
81
83
|
type: (type) => TYPES_JA[type] ?? `${type} にする`,
|
|
82
84
|
minLength: (limit) => `${limit} 字以上書く`,
|
|
85
|
+
maxLength: (limit) => `${limit} 字までにする`,
|
|
83
86
|
pattern: (forbidden) =>
|
|
84
87
|
forbidden ? `${forbidden.space ? "空白と " : ""}${forbidden.chars.join(" ")} は使えない` : "使えない字が入っている",
|
|
85
88
|
minItems: (limit) => `${limit} つ以上書く`,
|
|
89
|
+
maxItems: (limit) => `${limit} つまでにする`,
|
|
86
90
|
minimum: (limit) => `${limit} 以上にする`,
|
|
87
91
|
const: (value) => `${value} にする`,
|
|
88
92
|
not: (allowed) => (allowed ? `${allowed.field} の欄は kind が ${allowed.kind} の時だけ書ける` : "この欄の組み合わせは書けない"),
|
|
@@ -105,11 +109,13 @@ const en: FieldMessages = {
|
|
|
105
109
|
enum: (values) => `Use one of ${values.join(" / ")}`,
|
|
106
110
|
type: (type) => TYPES_EN[type] ?? `Use ${type}`,
|
|
107
111
|
minLength: (limit) => `Write at least ${plural(limit, "character")}`,
|
|
112
|
+
maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
|
|
108
113
|
pattern: (forbidden) =>
|
|
109
114
|
forbidden
|
|
110
115
|
? `Cannot contain ${forbidden.space ? "spaces or " : ""}${forbidden.chars.join(" ")}`
|
|
111
116
|
: "Contains characters that are not allowed",
|
|
112
117
|
minItems: (limit) => `Write at least ${plural(limit, "item")}`,
|
|
118
|
+
maxItems: (limit) => `Write at most ${plural(limit, "item")}`,
|
|
113
119
|
minimum: (limit) => `Use ${limit} or greater`,
|
|
114
120
|
const: (value) => `Use ${value}`,
|
|
115
121
|
not: (allowed) => (allowed ? `The ${allowed.field} field is allowed only when kind is ${allowed.kind}` : "This combination of fields is not allowed"),
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,9 @@ export {
|
|
|
22
22
|
type GitBranch,
|
|
23
23
|
type GitCommit,
|
|
24
24
|
type LabelSide,
|
|
25
|
+
type LineupItem,
|
|
26
|
+
type LineupOrder,
|
|
27
|
+
type LineupStamp,
|
|
25
28
|
type Region,
|
|
26
29
|
type StatePath,
|
|
27
30
|
type Step,
|
|
@@ -60,6 +63,7 @@ export type {
|
|
|
60
63
|
} from "./layout/scene";
|
|
61
64
|
export type { TimeAxis, TimeBox, TimeColumn, TimeLayout, TimeMark, TimePeriodPlaced, TimePointPlaced, TimeRowPlaced, TimeSpanPlaced, TimeTick, TimeWire, TimeZoom } from "./layout/time";
|
|
62
65
|
export type { TreeLayout, TreeLink, TreePlaced, TreeRun } from "./layout/tree";
|
|
66
|
+
export type { LaneText, LineupAt, LineupLane, LineupLayout, LineupPick, LineupSeal, LineupSeat, LineupStamp as LineupStampPlaced } from "./layout/lineup";
|
|
63
67
|
export { type Family, FONTS } from "./look/fonts";
|
|
64
68
|
export { type ColorKey, type ColorName, type Colors, DEFAULT_PALETTE, type Palette, PALETTES, READABLE_PX, resolvePalette, type TextStyle, type Theme } from "./look/values";
|
|
65
69
|
export { mountDiagram, type Player, type PlayerOptions } from "./player";
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 列の図の置き場所 (#3239)。見た目の元は step 2 で本人が選んだ見本の「列の図」。
|
|
3
|
+
*
|
|
4
|
+
* 箱 (`box`) が列になり、宣言した順に上から同じ幅で並ぶ。列の名前は列の左上に、箱の下の字 (`sub`) は列の右上に置く。
|
|
5
|
+
* チップは列の左から等間隔の席に座り、図の幅は上限の枚数の列の幅で決まる。チップの数で図の幅を変えないのは、段によって図の大きさが変わらないため。
|
|
6
|
+
* 字がチップの幅の下限を超える時は全てのチップを同じ幅に広げ、列の名前と右上の字が 1 列に収まらない時は全ての列を広げる。
|
|
7
|
+
*
|
|
8
|
+
* 段の中の `line` を書いた順に辿り、チップが席に居る間を 1 回ずつ `LineupSeat` にする。
|
|
9
|
+
* 滑り始める所は、同じ列に居たチップならその席、ほかの列に居たチップなら段の始まりの居場所で、選んだ列に居ればその席、なければ最後に座った席。
|
|
10
|
+
* どの列にも居なかったチップは滑り始める所を持たない。同じ席に残るチップは前の `LineupSeat` のまま続ける。
|
|
11
|
+
* 元の列を書き換えない時は元の席のチップも残る。元の列を書き換えた時は、元の席の `until` に書き換えた出来事を書く。
|
|
12
|
+
*
|
|
13
|
+
* 原本の JSON が宣言していない列とチップを書く時は、その列とチップを除いて描く。同じ列に同じチップを書く時は最初の 1 枚だけを描く。
|
|
14
|
+
* 開いている列への `open` と、封をした列への `seal` は描かない。
|
|
15
|
+
*
|
|
16
|
+
* 段の番号は、その段で最初に変わる列の左の縁に、チップの並びの高さで置く。列の変わらない段は帯の左上に置き、それも無ければ前の段の番号と入れ替える。
|
|
17
|
+
*/
|
|
18
|
+
import { type ColorKey, LOOK, TYPE } from "../look/values";
|
|
19
|
+
import type { Diagram } from "../schema";
|
|
20
|
+
import { LANE_MOST } from "../words";
|
|
21
|
+
import { textBox, textWidth } from "./measure";
|
|
22
|
+
import { boxColors, type Layout, layoutStrip, type Point, type Rect, replaceSameSpot, type SceneBadge, type SceneBox, stripNeed } from "./scene";
|
|
23
|
+
|
|
24
|
+
/** 列の中の字。`text` は描く字で、`y` から `h` は字の形の高さ */
|
|
25
|
+
export interface LaneText extends Rect {
|
|
26
|
+
text: string;
|
|
27
|
+
/** 基準線の高さ */
|
|
28
|
+
baseline: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 列。`track` はチップを並べる所で、上限の枚数の席が入る */
|
|
32
|
+
export interface LineupLane extends SceneBox {
|
|
33
|
+
title: LaneText;
|
|
34
|
+
/** 右上の字の最初の字。書かない列は持たない */
|
|
35
|
+
note?: LaneText;
|
|
36
|
+
/** 右上の字の右端 */
|
|
37
|
+
noteRight: number;
|
|
38
|
+
track: Rect;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 段の出来事の場所 */
|
|
42
|
+
export interface LineupAt {
|
|
43
|
+
step: number;
|
|
44
|
+
event: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** チップが列の席に居る間 1 回分。`from` は滑り始める左上で、弾んで現れるチップは持たない。`until` は席を離れる出来事 */
|
|
48
|
+
export interface LineupSeat extends Rect, LineupAt {
|
|
49
|
+
id: string;
|
|
50
|
+
lane: string;
|
|
51
|
+
index: number;
|
|
52
|
+
from?: Point;
|
|
53
|
+
until?: LineupAt;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 封。`until` は開ける出来事 */
|
|
57
|
+
export interface LineupSeal extends Rect, LineupAt {
|
|
58
|
+
lane: string;
|
|
59
|
+
until?: LineupAt;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 札 */
|
|
63
|
+
export interface LineupStamp extends Rect, LineupAt {
|
|
64
|
+
lane: string;
|
|
65
|
+
text: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 列を選ぶ出来事。同じ列を続けて選んだ時は最初の 1 つだけを持つ */
|
|
69
|
+
export interface LineupPick extends LineupAt {
|
|
70
|
+
lane: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface LineupLayout extends Layout {
|
|
74
|
+
kind: "lineup";
|
|
75
|
+
lanes: LineupLane[];
|
|
76
|
+
chips: LineupSeat[];
|
|
77
|
+
seals: LineupSeal[];
|
|
78
|
+
stamps: LineupStamp[];
|
|
79
|
+
picks: LineupPick[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const isLineupLayout = (layout: Layout): layout is LineupLayout => layout.kind === "lineup";
|
|
83
|
+
|
|
84
|
+
/** 列の右上に出る字と、その字の形。段の中の `note` は太い字で描く */
|
|
85
|
+
function notesOf(diagram: Diagram, id: string, sub: string | undefined): number[] {
|
|
86
|
+
const written = diagram.steps.flatMap((step) => step.events.flatMap((e) => (e.type === "swap" && e.box === id ? [textWidth(e.text, TYPE.boxSubStrong)] : [])));
|
|
87
|
+
return sub === undefined ? written : [textWidth(sub, TYPE.boxSub), ...written];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function layoutLineup(diagram: Diagram): LineupLayout {
|
|
91
|
+
const { margin, gap, lineup: N } = LOOK;
|
|
92
|
+
const items = diagram.lineup?.items ?? [];
|
|
93
|
+
const known = new Set(items.map((item) => item.id));
|
|
94
|
+
const chipW = Math.max(N.chip.w, ...items.map((item) => (item.label === undefined ? 0 : textWidth(item.label, TYPE.chip) + N.chip.padX * 2)));
|
|
95
|
+
const pitch = chipW + N.chip.gap;
|
|
96
|
+
const trackW = pitch * LANE_MOST - N.chip.gap;
|
|
97
|
+
const titled = diagram.boxes.map((b) => textWidth(b.name, TYPE.boxName) + N.textGap + Math.max(0, ...notesOf(diagram, b.id, b.sub)));
|
|
98
|
+
const laneW = Math.max(trackW + N.padX * 2, ...titled.map((w) => w + N.padX * 2), stripNeed(diagram));
|
|
99
|
+
|
|
100
|
+
const colors = boxColors(diagram);
|
|
101
|
+
const lanes: LineupLane[] = diagram.boxes.map((b, i) => {
|
|
102
|
+
const y = margin + i * (N.h + gap);
|
|
103
|
+
const baseline = y + N.textY;
|
|
104
|
+
const noteRight = margin + laneW - N.padX;
|
|
105
|
+
return {
|
|
106
|
+
id: b.id,
|
|
107
|
+
name: b.name,
|
|
108
|
+
...(b.sub !== undefined ? { sub: b.sub } : {}),
|
|
109
|
+
color: colors.get(b.id) ?? "slate",
|
|
110
|
+
x: margin,
|
|
111
|
+
y,
|
|
112
|
+
w: laneW,
|
|
113
|
+
h: N.h,
|
|
114
|
+
cx: margin + laneW / 2,
|
|
115
|
+
cy: y + N.h / 2,
|
|
116
|
+
title: { ...textBox(b.name, margin + N.padX, baseline, TYPE.boxName), text: b.name, baseline },
|
|
117
|
+
...(b.sub !== undefined ? { note: { ...textBox(b.sub, noteRight - textWidth(b.sub, TYPE.boxSub), baseline, TYPE.boxSub), text: b.sub, baseline } } : {}),
|
|
118
|
+
noteRight,
|
|
119
|
+
track: { x: margin + N.padX, y: y + N.trackY, w: trackW, h: N.chip.h },
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
const laneOf = new Map(lanes.map((lane) => [lane.id, lane]));
|
|
123
|
+
|
|
124
|
+
const chips: LineupSeat[] = [];
|
|
125
|
+
const seals: LineupSeal[] = [];
|
|
126
|
+
const stamps: LineupStamp[] = [];
|
|
127
|
+
const picks: LineupPick[] = [];
|
|
128
|
+
const seated = new Map<string, LineupSeat[]>();
|
|
129
|
+
const open = new Map<string, LineupSeal>();
|
|
130
|
+
let picked: string | undefined;
|
|
131
|
+
diagram.steps.forEach((step, s) => {
|
|
132
|
+
// 同じ段の `line` どうしは、段の始まりの居場所から滑る
|
|
133
|
+
const before = [...seated.values()].flat();
|
|
134
|
+
step.events.forEach((e, k) => {
|
|
135
|
+
if (e.type !== "line" && e.type !== "seal" && e.type !== "open" && e.type !== "pick" && e.type !== "stamp") return;
|
|
136
|
+
const lane = laneOf.get(e.box);
|
|
137
|
+
if (!lane) return;
|
|
138
|
+
const at: LineupAt = { step: s, event: k };
|
|
139
|
+
if (e.type === "seal" && !open.has(lane.id)) {
|
|
140
|
+
const { over } = N.seal;
|
|
141
|
+
const seal: LineupSeal = { ...at, lane: lane.id, x: lane.track.x - over, y: lane.track.y - over, w: lane.track.w + over * 2, h: lane.track.h + over * 2 };
|
|
142
|
+
seals.push(seal);
|
|
143
|
+
open.set(lane.id, seal);
|
|
144
|
+
} else if (e.type === "open") {
|
|
145
|
+
const seal = open.get(lane.id);
|
|
146
|
+
if (seal) seal.until = at;
|
|
147
|
+
open.delete(lane.id);
|
|
148
|
+
} else if (e.type === "pick" && picked !== lane.id) {
|
|
149
|
+
picks.push({ ...at, lane: lane.id });
|
|
150
|
+
picked = lane.id;
|
|
151
|
+
} else if (e.type === "stamp") {
|
|
152
|
+
const w = textWidth(e.text, TYPE.stamp) + N.stamp.padX * 2;
|
|
153
|
+
stamps.push({ ...at, lane: lane.id, text: e.text, x: lane.x + lane.w - N.padX - w, y: lane.track.y + (lane.track.h - N.stamp.h) / 2, w, h: N.stamp.h });
|
|
154
|
+
} else if (e.type === "line") {
|
|
155
|
+
const old = seated.get(lane.id) ?? [];
|
|
156
|
+
const order = [...new Set(e.items)].filter((id) => known.has(id)).slice(0, LANE_MOST);
|
|
157
|
+
const placed = order.map((id, index): LineupSeat => {
|
|
158
|
+
const same = old.find((c) => c.id === id);
|
|
159
|
+
if (same?.index === index) return same;
|
|
160
|
+
const others = before.filter((c) => c.id === id);
|
|
161
|
+
const source = same ?? others.find((c) => c.lane === picked) ?? others.at(-1);
|
|
162
|
+
const seat: LineupSeat = { ...at, id, lane: lane.id, index, x: lane.track.x + pitch * index, y: lane.track.y, w: chipW, h: N.chip.h, ...(source ? { from: [source.x, source.y] as Point } : {}) };
|
|
163
|
+
chips.push(seat);
|
|
164
|
+
return seat;
|
|
165
|
+
});
|
|
166
|
+
for (const c of old) if (!placed.includes(c)) c.until = at;
|
|
167
|
+
seated.set(lane.id, placed);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const layout: LineupLayout = {
|
|
173
|
+
kind: "lineup",
|
|
174
|
+
width: 0,
|
|
175
|
+
height: 0,
|
|
176
|
+
regions: [],
|
|
177
|
+
boxes: lanes,
|
|
178
|
+
lifelines: [],
|
|
179
|
+
edges: [],
|
|
180
|
+
labels: [],
|
|
181
|
+
actions: [],
|
|
182
|
+
badges: [],
|
|
183
|
+
paths: [],
|
|
184
|
+
ends: [],
|
|
185
|
+
lanes,
|
|
186
|
+
chips,
|
|
187
|
+
seals,
|
|
188
|
+
stamps,
|
|
189
|
+
picks,
|
|
190
|
+
};
|
|
191
|
+
const bottom = Math.max(...lanes.map((lane) => lane.y + lane.h), margin);
|
|
192
|
+
const width = laneW + margin * 2;
|
|
193
|
+
const strip = layoutStrip(diagram, margin, bottom + gap, width - margin * 2);
|
|
194
|
+
layout.width = width;
|
|
195
|
+
layout.height = (strip ? strip.y + strip.h : bottom) + margin;
|
|
196
|
+
if (strip) layout.strip = strip;
|
|
197
|
+
layout.badges = badgesOf(diagram, layout);
|
|
198
|
+
return layout;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function badgesOf(diagram: Diagram, layout: LineupLayout): SceneBadge[] {
|
|
202
|
+
const { inset } = LOOK.badge;
|
|
203
|
+
const out: SceneBadge[] = [];
|
|
204
|
+
const put = (step: number, x: number, y: number, color: ColorKey): void => {
|
|
205
|
+
out.push({ step, x, y, color });
|
|
206
|
+
};
|
|
207
|
+
diagram.steps.forEach((step, s) => {
|
|
208
|
+
const lane = step.events.flatMap((e) => ("box" in e ? [e.box] : [])).flatMap((id) => layout.lanes.filter((l) => l.id === id))[0];
|
|
209
|
+
if (lane) {
|
|
210
|
+
put(s, lane.x, lane.track.y + lane.track.h / 2, lane.color);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const before = out[out.length - 1];
|
|
214
|
+
if (layout.strip && step.events.some((e) => e.type === "strip")) put(s, layout.strip.x + inset, layout.strip.y + inset, "slate");
|
|
215
|
+
else if (before) out.push({ ...before, step: s });
|
|
216
|
+
else put(s, LOOK.margin, LOOK.margin, layout.lanes[0]?.color ?? "slate");
|
|
217
|
+
});
|
|
218
|
+
return replaceSameSpot(out);
|
|
219
|
+
}
|
package/src/look/values.ts
CHANGED
|
@@ -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);
|