@cardenelabs/dragon 0.42.2 → 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/README.md +34 -1
- package/dist/cli.cjs +4630 -1690
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4630 -1690
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +4267 -1555
- 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 +4267 -1555
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +4348 -1381
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -3
- package/dist/index.d.ts +118 -3
- package/dist/index.js +4348 -1381
- package/dist/index.js.map +1 -1
- package/dist/{ink-B8EZL7JV.d.cts → ink-DeDtzaTL.d.cts} +47 -3
- package/dist/{ink-B8EZL7JV.d.ts → ink-DeDtzaTL.d.ts} +47 -3
- package/dist/node.cjs +3504 -1625
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +3504 -1625
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +3 -2
- package/package.json +1 -1
- package/src/field-messages.ts +6 -0
- package/src/index.ts +8 -1
- package/src/layout/lineup.ts +219 -0
- package/src/layout/tree.ts +458 -0
- package/src/look/values.ts +73 -2
- package/src/messages.ts +88 -2
- package/src/parser.ts +212 -2
- package/src/printer.ts +36 -2
- package/src/render/icons.ts +2 -0
- package/src/render/lineup.ts +184 -0
- package/src/render/parts.ts +16 -7
- package/src/render/svg.ts +72 -6
- package/src/render/tree.ts +165 -0
- package/src/schema.ts +76 -4
- package/src/schemas/diagram.schema.json +207 -19
- package/src/schemas/validate-diagram.js +1 -1
- package/src/timeline.ts +16 -2
- package/src/words.ts +25 -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,
|
|
@@ -34,6 +37,8 @@ export {
|
|
|
34
37
|
type TimeScale,
|
|
35
38
|
type TimeSpanEvent,
|
|
36
39
|
type TimeSpec,
|
|
40
|
+
type TreeLeaf,
|
|
41
|
+
type TreeNode,
|
|
37
42
|
validateDiagram,
|
|
38
43
|
type ViewMode,
|
|
39
44
|
} from "./schema";
|
|
@@ -57,8 +62,10 @@ export type {
|
|
|
57
62
|
SceneTrail,
|
|
58
63
|
} from "./layout/scene";
|
|
59
64
|
export type { TimeAxis, TimeBox, TimeColumn, TimeLayout, TimeMark, TimePeriodPlaced, TimePointPlaced, TimeRowPlaced, TimeSpanPlaced, TimeTick, TimeWire, TimeZoom } from "./layout/time";
|
|
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";
|
|
60
67
|
export { type Family, FONTS } from "./look/fonts";
|
|
61
|
-
export { type ColorKey, type ColorName, type Colors, DEFAULT_PALETTE, type Palette, PALETTES, READABLE_PX, resolvePalette, type Theme } from "./look/values";
|
|
68
|
+
export { type ColorKey, type ColorName, type Colors, DEFAULT_PALETTE, type Palette, PALETTES, READABLE_PX, resolvePalette, type TextStyle, type Theme } from "./look/values";
|
|
62
69
|
export { mountDiagram, type Player, type PlayerOptions } from "./player";
|
|
63
70
|
export { ICONS } from "./render/icons";
|
|
64
71
|
export { describeOverlap, type InkPart, type Overlap, type OverlapSpot } from "./render/ink";
|
|
@@ -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
|
+
}
|