@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
@@ -0,0 +1,719 @@
1
+ import {
2
+ ALWAYS,
3
+ arrowHead,
4
+ card,
5
+ cs,
6
+ esc,
7
+ glyph,
8
+ linkTo,
9
+ pathOf,
10
+ write
11
+ } from "./chunk-6ZUKJ3VO.js";
12
+ import {
13
+ COLOR_ORDER,
14
+ EASE,
15
+ FIGURE_TEXT,
16
+ LOOK,
17
+ MOTION,
18
+ TYPE,
19
+ badgeOnPath,
20
+ badgeRect,
21
+ boxColors,
22
+ boxWidth,
23
+ edgeColor,
24
+ hasWide,
25
+ layoutStrip,
26
+ placeLabel,
27
+ placeSlot,
28
+ replaceSameSpot,
29
+ seatCarriers,
30
+ slotBoxWidth,
31
+ slotRooms,
32
+ stripNeed,
33
+ textBox,
34
+ textWidth
35
+ } from "./chunk-JNSHZTPF.js";
36
+
37
+ // src/layout/time.ts
38
+ var SECONDS = { d: 86400, h: 3600, min: 60, s: 1, ms: 1e-3 };
39
+ var UNITS = Object.keys(SECONDS);
40
+ function durationOf(text) {
41
+ const m = /^([0-9]+(?:\.[0-9]+)?)(ms|s|min|h|d)$/u.exec(text);
42
+ if (!m) return { seconds: 1, unit: "s" };
43
+ const unit = m[2];
44
+ return { seconds: Number(m[1]) * SECONDS[unit], unit };
45
+ }
46
+ var unitFor = (max, fallback) => UNITS.find((u) => max / SECONDS[u] >= 2 - 1e-9) ?? fallback;
47
+ var timeText = (seconds, unit, lang) => `${Number((seconds / SECONDS[unit]).toFixed(2))} ${FIGURE_TEXT[lang].timeUnits[unit]}`;
48
+ function majorTicks(count, period, unitPx) {
49
+ let step = 1;
50
+ if (period) step = period * Math.max(1, Math.ceil(count / period / 8));
51
+ else {
52
+ for (let k = 1; ; k *= 10) {
53
+ const found = [k, k * 2, k * 5].find((n) => count / n <= LOOK.time.ticks);
54
+ if (found !== void 0) {
55
+ step = found;
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ const at = [];
61
+ for (let u = 0; u <= count; u += step) at.push(u);
62
+ const last = at[at.length - 1];
63
+ if (last !== count && (count - last) * unitPx >= LOOK.time.minorPx) at.push(count);
64
+ return { at, step };
65
+ }
66
+ function minorTicks(count, step, unitPx, majors) {
67
+ const by = Array.from({ length: step - 1 }, (_, k) => k + 1).find((d) => step % d === 0 && d * unitPx >= LOOK.time.minorPx);
68
+ if (by === void 0) return [];
69
+ const out = [];
70
+ for (let u = by; u < count; u += by) if (!majors.includes(u)) out.push(u);
71
+ return out;
72
+ }
73
+ function needleSteps(diagram) {
74
+ let at = 0;
75
+ return diagram.steps.map((step) => {
76
+ const from = at;
77
+ for (const event of step.events) if (event.type === "now") at = Math.max(at, event.to + 1);
78
+ return [from, at];
79
+ });
80
+ }
81
+ function layoutTime(diagram, lang = "ja") {
82
+ const T = LOOK.time;
83
+ const { margin, gap } = LOOK;
84
+ const R = LOOK.region;
85
+ const text = FIGURE_TEXT[lang];
86
+ const spec = diagram.time ?? { scale: { unit: "", length: "1s", count: 1 }, rows: [] };
87
+ const { scale } = spec;
88
+ const count = Math.max(1, scale.count);
89
+ const length = durationOf(scale.length);
90
+ const width = Math.max(T.width, stripNeed(diagram) + margin * 2);
91
+ const nameRight = Math.max(0, ...spec.rows.map((r) => textWidth(r.name, TYPE.timeRow)));
92
+ const axisX = Math.max(T.axisX, margin + R.inset + nameRight + T.gutterGap);
93
+ const axisW = width - T.right - axisX;
94
+ const unit = axisW / count;
95
+ const colors = boxColors(diagram);
96
+ const rooms = slotRooms(diagram);
97
+ const regions = [];
98
+ const boxes = [];
99
+ const edges = [];
100
+ const wires = [];
101
+ const rowIds = new Map(spec.rows.map((r) => [r.id, r]));
102
+ let zoom;
103
+ let axisTop = margin;
104
+ if (spec.zoom) {
105
+ const { from, to } = spec.zoom;
106
+ const n = to - from + 1;
107
+ const colW = axisW / n;
108
+ const top = margin;
109
+ const headUnit = unitFor(to * length.seconds, length.unit);
110
+ const columns = [];
111
+ for (let k = 0; k < n; k++) {
112
+ const u = from + k;
113
+ const x = axisX + k * colW;
114
+ const placed = diagram.boxes.map((b, j) => {
115
+ const room = rooms.get(b.id);
116
+ const w = Math.max(boxWidth(diagram, b.id, false), slotBoxWidth(room, b.icon !== void 0, LOOK.box.padX));
117
+ const y2 = top + T.boxTop + j * (LOOK.box.h + T.boxGap);
118
+ const row = rowIds.get(b.id);
119
+ const box = {
120
+ id: b.id,
121
+ name: b.name,
122
+ ...b.sub !== void 0 ? { sub: b.sub } : {},
123
+ ...b.icon !== void 0 ? { icon: b.icon } : {},
124
+ color: colors.get(b.id) ?? "slate",
125
+ x: x + colW / 2 - w / 2,
126
+ y: y2,
127
+ w,
128
+ h: LOOK.box.h,
129
+ cx: x + colW / 2,
130
+ cy: y2 + LOOK.box.h / 2,
131
+ ...row ? { row: row.id } : {},
132
+ ...row?.empty?.includes(u) ? { empty: true } : {}
133
+ };
134
+ placeSlot(box, room);
135
+ return box;
136
+ });
137
+ boxes.push(...placed);
138
+ const head = `${scale.unit} ${(scale.from ?? 0) + u}${text.headJoin}${timeText(u * length.seconds, headUnit, lang)}`;
139
+ columns.push({ unit: u, head, boxes: placed, x, y: top, w: colW, h: 0 });
140
+ }
141
+ const last = Math.max(top + T.boxTop, ...boxes.map((b) => b.y + b.h));
142
+ const bottom2 = last + T.zoomBottom;
143
+ for (const c of columns) c.h = bottom2 - top;
144
+ regions.push({
145
+ id: "zoom",
146
+ lines: [text.zoom],
147
+ note: `${n} ${scale.unit}`,
148
+ icon: "clock",
149
+ color: "blue",
150
+ x: margin,
151
+ y: top,
152
+ w: width - margin * 2,
153
+ h: bottom2 - top,
154
+ header: { x: margin + R.inset, y: top + R.inset, w: Math.max(R.icon, textWidth(text.zoom, TYPE.regionName)), h: R.nameY - R.inset + R.line }
155
+ });
156
+ zoom = { from, to, frame: { x: 0, y: 0, w: 0, h: 0 }, guides: [], columns, empty: text.empty, headY: top + T.head };
157
+ axisTop = bottom2 + T.zoomGap;
158
+ }
159
+ const rowsTop = axisTop + T.rowsTop;
160
+ const rows = spec.rows.map((r, k) => ({
161
+ id: r.id,
162
+ name: r.name,
163
+ // 色を書かない列は、同じ名札の箱の色にそろえる。印と拡大の帯の箱が同じ物だと見て分かるため
164
+ color: r.color ?? colors.get(r.id) ?? COLOR_ORDER[k % COLOR_ORDER.length],
165
+ x: axisX,
166
+ y: rowsTop + k * (T.row + T.rowGap),
167
+ w: axisW,
168
+ h: T.row
169
+ }));
170
+ const rowsBottom = rows.length > 0 ? Math.max(...rows.map((r) => r.y + r.h)) : rowsTop;
171
+ const markW = Math.min(T.markMax, Math.max(T.markMin, unit * T.markRatio));
172
+ const marks = rows.flatMap(
173
+ (row, k) => Array.from({ length: count }, (_, u) => ({
174
+ row: row.id,
175
+ unit: u,
176
+ empty: spec.rows[k]?.empty?.includes(u) === true,
177
+ color: row.color,
178
+ colors: [],
179
+ x: axisX + (u + 0.5) * unit - markW / 2,
180
+ y: row.y,
181
+ w: markW,
182
+ h: row.h
183
+ }))
184
+ );
185
+ diagram.steps.forEach(
186
+ (step, s) => step.events.forEach((event, e) => {
187
+ if (event.type !== "mark") return;
188
+ for (const m of marks) if (m.row === event.row && m.unit >= event.from && m.unit <= event.to && !m.empty) m.colors.push({ step: s, event: e, color: event.color });
189
+ })
190
+ );
191
+ if (zoom) {
192
+ const frame = { x: axisX + zoom.from * unit - T.frame, y: rowsTop - T.frame, w: (zoom.to - zoom.from + 1) * unit + T.frame * 2, h: rowsBottom - rowsTop + T.frame * 2 };
193
+ const band = Math.max(...zoom.columns.map((c) => c.y + c.h));
194
+ zoom.frame = frame;
195
+ zoom.guides = [
196
+ [
197
+ [frame.x, frame.y],
198
+ [axisX, band]
199
+ ],
200
+ [
201
+ [frame.x + frame.w, frame.y],
202
+ [axisX + axisW, band]
203
+ ]
204
+ ];
205
+ }
206
+ const pointCy = rowsBottom + T.point.drop;
207
+ const points = (spec.points ?? []).map((p) => {
208
+ const changes = [];
209
+ diagram.steps.forEach(
210
+ (step, s) => step.events.forEach((event, e) => {
211
+ if (event.type === "swap" && event.box === p.id) changes.push({ step: s, event: e, text: event.text, ...event.color ? { color: event.color } : {} });
212
+ })
213
+ );
214
+ const cx = axisX + (p.at + 0.5) * unit;
215
+ const tx = cx + T.point.text;
216
+ const w = Math.max(textWidth(p.id, TYPE.pointName), ...changes.map((c) => textWidth(c.text, TYPE.pointState)));
217
+ const top = pointCy + T.point.nameY - TYPE.pointName.size * 0.8;
218
+ const bottom2 = pointCy + T.point.stateY + TYPE.pointState.size * 0.2;
219
+ return { id: p.id, unit: p.at, cx, cy: pointCy, r: T.point.r, text: { x: tx, y: top, w, h: bottom2 - top }, changes };
220
+ });
221
+ const pointOf = new Map(points.map((p) => [p.id, p]));
222
+ const colorAt = (id, step) => {
223
+ const point = pointOf.get(id);
224
+ return point?.changes.filter((c) => c.step <= step && c.color).at(-1)?.color;
225
+ };
226
+ diagram.steps.forEach(
227
+ (step, s) => step.events.forEach((event, e) => {
228
+ if (event.type !== "edge") return;
229
+ if (event.at === void 0) {
230
+ const a = pointOf.get(event.from);
231
+ const b = pointOf.get(event.to);
232
+ if (!a || !b || a === b) return;
233
+ const right = b.cx > a.cx;
234
+ const x0 = right ? Math.max(a.cx + a.r, a.text.x + a.text.w + T.point.link) : a.cx - a.r - T.point.end;
235
+ const x1 = right ? b.cx - b.r - T.point.end : Math.min(b.cx - b.r, b.text.x + b.text.w + T.point.link);
236
+ const edge2 = { step: s, event: e, from: event.from, to: event.to, points: [[x0, a.cy], [x1, b.cy]], color: event.carry.kind === "coin" ? "coin" : colorAt(event.to, s) ?? "slate", carry: event.carry };
237
+ if (event.carry.kind !== "none") edge2.settle = [x1 - (right ? 1 : -1) * (LOOK.carrier.coinR + LOOK.edge.arrow), b.cy];
238
+ edges.push(edge2);
239
+ return;
240
+ }
241
+ const wired = wire(event, zoom);
242
+ if (!wired) return;
243
+ const edge = { step: s, event: e, from: event.from, to: event.to, points: wired.points, color: edgeColor(event, colors), carry: event.carry };
244
+ seat(edge, wired.from, wired.to, rooms);
245
+ edges.push(edge);
246
+ wires.push({ step: s, event: e, from: wired.from, to: wired.to, column: event.at, into: event.into ?? event.at });
247
+ })
248
+ );
249
+ const layout = {
250
+ kind: "time",
251
+ width,
252
+ height: 0,
253
+ regions,
254
+ boxes,
255
+ lifelines: [],
256
+ edges,
257
+ labels: [],
258
+ actions: [],
259
+ badges: [],
260
+ paths: [],
261
+ ends: [],
262
+ axis: { x: axisX, w: axisW, unit, count, line: 0 },
263
+ rows,
264
+ marks,
265
+ ticks: [],
266
+ minor: [],
267
+ periods: [],
268
+ points,
269
+ ...zoom ? { zoom } : {},
270
+ spans: [],
271
+ wires,
272
+ needle: { y1: rowsTop - T.needle.over, y2: rowsBottom + T.needle.over }
273
+ };
274
+ const marksBottom = rowsBottom;
275
+ const named = diagram.steps.some((step) => step.events.some((e) => e.type === "edge" && e.at === void 0 && e.label !== void 0));
276
+ const { r: badgeR, inset } = LOOK.badge;
277
+ let y = points.length > 0 ? pointCy + T.point.r + (named ? T.point.room : T.point.plain) : marksBottom + (badgeR + inset) * 2;
278
+ const spans = [];
279
+ const events = diagram.steps.flatMap((step, s) => step.events.flatMap((event, e) => event.type === "span" ? [{ s, e, event }] : []));
280
+ for (const { s, e, event } of events) {
281
+ const kind = event.shape === "box" ? "box" : "bracket";
282
+ const later = events.find((o) => o.s > s && (o.event.shape === "box" ? "box" : "bracket") === kind && o.event.from <= event.to && event.from <= o.event.to);
283
+ const color = event.color ?? "slate";
284
+ const x0 = axisX + event.from * unit;
285
+ const x1 = axisX + (event.to + 1) * unit;
286
+ const base = { step: s, event: e, kind, from: event.from, to: event.to, text: event.text, color, ...later ? { until: later.s } : {} };
287
+ if (kind === "box") {
288
+ const B = T.box;
289
+ const rect = { x: x0 - B.pad, y: rowsTop - B.pad, w: x1 - x0 + B.pad * 2, h: rowsBottom - rowsTop + B.pad * 2 };
290
+ const w = textWidth(event.text, TYPE.tag) + B.tagPadX * 2;
291
+ const textRect = { x: rect.x + B.tagX, y: rect.y - B.tagH / 2, w, h: B.tagH };
292
+ spans.push({ ...base, ...rect, textRect, textY: rect.y + LOOK.baseline.tag });
293
+ } else spans.push({ ...base, x: x0, y: 0, w: x1 - x0, h: T.bracket.tick, textRect: { x: 0, y: 0, w: 0, h: 0 }, textY: 0 });
294
+ }
295
+ layout.spans = spans;
296
+ layout.badges = badgesOf(diagram, layout, needleSteps(diagram));
297
+ layout.labels = labelsOf(diagram, layout);
298
+ y = Math.max(y, ...layout.labels.map((l) => l.y + l.h + LOOK.label.soft));
299
+ const lanes = [];
300
+ for (const span of spans.filter((x) => x.kind === "bracket")) {
301
+ const w = textWidth(span.text, TYPE.spanText);
302
+ const cx = Math.min(axisX + axisW - w / 2, Math.max(axisX + w / 2, span.x + span.w / 2));
303
+ const reach = { x: Math.min(span.x, cx - w / 2), w: Math.max(span.x + span.w, cx + w / 2) - Math.min(span.x, cx - w / 2) };
304
+ const clash = (other) => {
305
+ const seen = other.until === void 0 || other.until > span.step;
306
+ const ox = Math.min(other.x, other.textRect.x);
307
+ const ow = Math.max(other.x + other.w, other.textRect.x + other.textRect.w) - ox;
308
+ return seen && reach.x < ox + ow && ox < reach.x + reach.w;
309
+ };
310
+ let lane = lanes.findIndex((list) => !list.some(clash));
311
+ if (lane < 0) {
312
+ lanes.push([]);
313
+ lane = lanes.length - 1;
314
+ }
315
+ lanes[lane].push(span);
316
+ span.y = y + T.bracket.gap + lane * T.bracket.lane;
317
+ span.textY = span.y + T.bracket.tick + T.bracket.text;
318
+ span.textRect = textBox(span.text, cx, span.textY, TYPE.spanText, "middle");
319
+ }
320
+ if (lanes.length > 0) y = Math.max(...spans.filter((x) => x.kind === "bracket").map((x) => x.textRect.y + x.textRect.h));
321
+ const axisLine = y + T.axisGap;
322
+ layout.axis.line = axisLine;
323
+ const majors = majorTicks(count, spec.period?.length, unit);
324
+ const tickY = axisLine + T.tickY;
325
+ const tickUnit = unitFor(count * length.seconds, length.unit);
326
+ layout.ticks = majors.at.map((at) => {
327
+ const label = timeText(at * length.seconds, tickUnit, lang);
328
+ const w = textWidth(label, TYPE.timeTick);
329
+ const x = axisX + at * unit;
330
+ const left = at === 0 ? x : at === count ? x - w : Math.min(axisX + axisW - w, Math.max(axisX, x - w / 2));
331
+ return { at, x, text: label, left, y: tickY };
332
+ });
333
+ layout.minor = minorTicks(count, majors.step, unit, majors.at);
334
+ let bottom = tickY + TYPE.timeTick.size * 0.2;
335
+ if (spec.period) {
336
+ const P = spec.period;
337
+ const list = [];
338
+ for (let index = 0, from = 0; from < count; index++, from += P.length) {
339
+ const to = Math.min(count, from + P.length) - 1;
340
+ const name = `${P.name} ${(P.from ?? 0) + index}`;
341
+ const first = (scale.from ?? 0) + from;
342
+ const range = `${scale.unit} ${text.range(String(first), String((scale.from ?? 0) + to))}`;
343
+ list.push({ index, from, to, name, range, x: axisX + from * unit, y: axisLine, w: (to - from + 1) * unit, h: 0, nameY: tickY, rangeY: tickY + T.rangeY });
344
+ }
345
+ const tickRects = layout.ticks.map((t) => textBox(t.text, t.left, t.y, TYPE.timeTick));
346
+ const clash = list.some((p) => {
347
+ const r = textBox(p.name, p.x + p.w / 2, p.nameY, TYPE.timePeriod, "middle");
348
+ return tickRects.some((t) => r.x < t.x + t.w + T.nameGap && t.x < r.x + r.w + T.nameGap);
349
+ });
350
+ for (const p of list) {
351
+ if (clash) {
352
+ p.nameY = tickY + T.rangeY + 2;
353
+ p.rangeY = p.nameY + T.rangeY;
354
+ }
355
+ p.h = p.rangeY + TYPE.timeRange.size * 0.2 - axisLine;
356
+ }
357
+ layout.periods = list;
358
+ bottom = Math.max(bottom, ...list.map((p) => p.rangeY + TYPE.timeRange.size * 0.2));
359
+ }
360
+ const axisBottom = bottom + T.bottom;
361
+ regions.push({ id: "axis", lines: [], color: "slate", x: margin, y: axisTop, w: width - margin * 2, h: axisBottom - axisTop, header: { x: margin + R.inset, y: axisTop + R.inset, w: 0, h: 0 } });
362
+ const strip = layoutStrip(diagram, margin, axisBottom + gap, width - margin * 2);
363
+ if (strip) layout.strip = strip;
364
+ layout.height = (strip ? strip.y + strip.h : axisBottom) + margin;
365
+ layout.badges = badgesOf(diagram, layout, needleSteps(diagram));
366
+ return layout;
367
+ }
368
+ function wire(event, zoom) {
369
+ if (!zoom || event.at === void 0) return void 0;
370
+ const into = event.into ?? event.at;
371
+ const fromColumn = zoom.columns.find((c) => c.unit === event.at);
372
+ const toColumn = zoom.columns.find((c) => c.unit === into);
373
+ const from = fromColumn?.boxes.find((b) => b.id === event.from);
374
+ const to = toColumn?.boxes.find((b) => b.id === event.to);
375
+ if (!fromColumn || !toColumn || !from || !to || from === to) return void 0;
376
+ const jf = fromColumn.boxes.indexOf(from);
377
+ const jt = toColumn.boxes.indexOf(to);
378
+ const down = jt > jf;
379
+ if (fromColumn === toColumn) {
380
+ if (Math.abs(jt - jf) === 1) return { from, to, points: [[from.cx, down ? from.y + from.h + 1 : from.y - 1], [to.cx, down ? to.y - 1 : to.y + to.h + 1]] };
381
+ const lane = Math.min(fromColumn.x + fromColumn.w - LOOK.gap, Math.max(from.x + from.w, to.x + to.w) + LOOK.gap);
382
+ return {
383
+ from,
384
+ to,
385
+ points: [
386
+ [from.x + from.w + 1, from.cy],
387
+ [lane, from.cy],
388
+ [lane, to.cy],
389
+ [to.x + to.w + 1, to.cy]
390
+ ]
391
+ };
392
+ }
393
+ const right = toColumn.x > fromColumn.x;
394
+ if (jf === jt) return { from, to, points: [[right ? from.x + from.w + 1 : from.x - 1, from.cy], [right ? to.x - 1 : to.x + to.w + 1, to.cy]] };
395
+ const fx = from.cx + (right ? 1 : -1) * from.w / 4;
396
+ const tx = to.cx - (right ? 1 : -1) * to.w / 4;
397
+ return { from, to, points: [[fx, down ? from.y + from.h + 1 : from.y - 1], [tx, down ? to.y - 1 : to.y + to.h + 1]] };
398
+ }
399
+ function seat(edge, from, to, rooms) {
400
+ const arrive = { ...edge };
401
+ seatCarriers([arrive], /* @__PURE__ */ new Map([[edge.to, to]]), rooms);
402
+ const leave = { ...edge };
403
+ seatCarriers([leave], /* @__PURE__ */ new Map([[edge.from, from]]), rooms);
404
+ if (arrive.settle) edge.settle = arrive.settle;
405
+ if (leave.wait) edge.wait = leave.wait;
406
+ }
407
+ function badgesOf(diagram, layout, needle) {
408
+ const { r, inset } = LOOK.badge;
409
+ const { axis } = layout;
410
+ const taken = [];
411
+ const out = [];
412
+ const top = Math.min(...layout.rows.map((row) => row.y), layout.needle.y1 + LOOK.time.needle.over);
413
+ const bottom = Math.max(...layout.rows.map((row) => row.y + row.h), top);
414
+ const between = layout.points[0] ? (bottom + layout.points[0].cy - layout.points[0].r) / 2 : bottom + r + inset;
415
+ diagram.steps.forEach((step, s) => {
416
+ const push = (p, color) => {
417
+ taken.push(p);
418
+ out.push({ step: s, x: p[0], y: p[1], color });
419
+ };
420
+ const edge = layout.edges.filter((e) => e.step === s).sort((a, b) => a.event - b.event)[0];
421
+ if (edge) {
422
+ const waits = edge.carry.kind !== "none" && !edge.wait ? [edge.points[0]] : [];
423
+ const others = layout.edges.filter((e) => e !== edge).map((e) => e.points);
424
+ push(badgeOnPath(edge.points, [...taken, ...waits], others), edge.color);
425
+ return;
426
+ }
427
+ const [from, to] = needle[s] ?? [0, 0];
428
+ if (to > from) {
429
+ let x = axis.x + (from + to) / 2 * axis.unit;
430
+ const near = layout.points.find((p) => Math.abs(p.cx - x) < r + inset);
431
+ if (near) x = near.cx + r + inset * 2;
432
+ push([x, between], "slate");
433
+ return;
434
+ }
435
+ for (const event of step.events) {
436
+ const spot = spotOf(event, s, layout);
437
+ if (spot) {
438
+ push(spot.at, spot.color);
439
+ return;
440
+ }
441
+ }
442
+ if (layout.strip && step.events.some((e) => e.type === "strip")) {
443
+ out.push({ step: s, x: layout.strip.x + inset, y: layout.strip.y + inset, color: "slate" });
444
+ return;
445
+ }
446
+ const before = out[out.length - 1];
447
+ out.push(before ? { ...before, step: s } : { step: s, x: axis.x - r - inset, y: top, color: "slate" });
448
+ });
449
+ return replaceSameSpot(out);
450
+ }
451
+ function spotOf(event, step, layout) {
452
+ const { r, inset } = LOOK.badge;
453
+ if (event.type === "span") {
454
+ const span = layout.spans.find((x) => x.step === step && x.from === event.from && x.to === event.to && x.text === event.text);
455
+ if (!span) return void 0;
456
+ if (span.kind === "box") return { at: [span.x, span.y], color: span.color };
457
+ return { at: [span.x - r - inset, span.y + span.h / 2], color: span.color };
458
+ }
459
+ if (event.type === "swap") {
460
+ const point = layout.points.find((p) => p.id === event.box);
461
+ if (point) return { at: [point.cx - point.r - inset - r, point.cy], color: event.color ?? "slate" };
462
+ }
463
+ if (event.type === "mark") {
464
+ const row = layout.rows.find((x) => x.id === event.row);
465
+ const top = Math.min(...layout.rows.map((x) => x.y));
466
+ if (row) return { at: [layout.axis.x + (event.from + event.to + 1) / 2 * layout.axis.unit, top - r - inset], color: event.color };
467
+ }
468
+ return void 0;
469
+ }
470
+ function labelsOf(diagram, layout) {
471
+ const labels = [];
472
+ const circles = layout.points.map((p) => ({ x: p.cx - p.r, y: p.cy - p.r, w: p.r * 2, h: p.r * 2 }));
473
+ const texts = layout.points.map((p) => p.text);
474
+ const heads = (layout.zoom?.columns ?? []).map((c) => textBox(c.head, c.x + c.w / 2, layout.zoom?.headY ?? 0, TYPE.timeHead, "middle"));
475
+ for (const edge of layout.edges) {
476
+ const source = diagram.steps[edge.step]?.events[edge.event];
477
+ if (source?.type !== "edge" || source.label === void 0) continue;
478
+ const seen = layout.badges.filter((b) => b.step <= edge.step).map((b) => badgeRect([b.x, b.y]));
479
+ const side = source.labelSide ?? (source.at === void 0 ? "below" : void 0);
480
+ labels.push(
481
+ placeLabel(
482
+ { step: edge.step, event: edge.event, text: source.label, points: edge.points, color: edge.color, ...side ? { side } : {}, flip: source.at !== void 0 },
483
+ { hard: [...circles, ...layout.boxes], soft: [...texts, ...heads, ...labels.filter((l) => l.step === edge.step)], touch: seen }
484
+ )
485
+ );
486
+ }
487
+ return labels;
488
+ }
489
+
490
+ // src/render/time.ts
491
+ var r1 = (v) => Math.round(v * 100) / 100;
492
+ var ja = (cls, text) => hasWide(text) ? `${cls} ${cls}j` : cls;
493
+ function simplify(keys) {
494
+ const out = [];
495
+ for (const key of keys) {
496
+ const a = out[out.length - 2];
497
+ const b = out[out.length - 1];
498
+ if (a && b) {
499
+ const s1 = b[0] === a[0] ? Number.NaN : (b[1] - a[1]) / (b[0] - a[0]);
500
+ const s2 = key[0] === b[0] ? Number.NaN : (key[1] - b[1]) / (key[0] - b[0]);
501
+ if (Number.isFinite(s1) && Number.isFinite(s2) && Math.abs(s1 - s2) < 1e-9) out[out.length - 1] = key;
502
+ else out.push(key);
503
+ } else out.push(key);
504
+ }
505
+ return out;
506
+ }
507
+ function valueAt(keys, t) {
508
+ const first = keys[0];
509
+ if (!first) return 0;
510
+ if (t <= first[0]) return first[1];
511
+ for (let k = 1; k < keys.length; k++) {
512
+ const [t1, v1] = keys[k];
513
+ const [t0, v0] = keys[k - 1];
514
+ if (t <= t1) return t1 === t0 ? v1 : v0 + (v1 - v0) * (t - t0) / (t1 - t0);
515
+ }
516
+ return keys[keys.length - 1][1];
517
+ }
518
+ function drawTime(layout, diagram, timeline, ctx, subs) {
519
+ const { m, ink } = ctx;
520
+ const T = LOOK.time;
521
+ const { axis } = layout;
522
+ const passed = new Map((timeline.units ?? []).map((u) => [u.unit, u.passed]));
523
+ const at = (step, event) => timeline.events.find((t) => t.step === step && t.event === event)?.at;
524
+ const drawnOf = (step, event) => timeline.edges.find((t) => t.step === step && t.event === event)?.drawn;
525
+ const base = [];
526
+ const lit = [];
527
+ const node = [];
528
+ const top = [];
529
+ const rowsTop = Math.min(...layout.rows.map((r) => r.y));
530
+ const rowsBottom = Math.max(...layout.rows.map((r) => r.y + r.h));
531
+ const arrivals = /* @__PURE__ */ new Map();
532
+ for (const w of layout.wires) {
533
+ const drawn = drawnOf(w.step, w.event);
534
+ if (drawn !== void 0) arrivals.set(w.to, Math.min(arrivals.get(w.to) ?? Number.POSITIVE_INFINITY, drawn));
535
+ }
536
+ const filled = (row, u) => {
537
+ const box = layout.zoom?.columns.find((c) => c.unit === u)?.boxes.find((b) => b.id === row);
538
+ const times = [passed.get(u), box ? arrivals.get(box) : void 0].filter((t) => t !== void 0);
539
+ return times.length > 0 ? Math.min(...times) : void 0;
540
+ };
541
+ for (const p of layout.periods) if (p.index % 2 === 1) base.push(`<rect class="dg-tm-ep" x="${r1(p.x)}" y="${r1(rowsTop - T.shade)}" width="${r1(p.w)}" height="${r1(rowsBottom - rowsTop + T.shade * 2)}" rx="4"/>`);
542
+ if (layout.zoom) {
543
+ const z = layout.zoom;
544
+ z.columns.forEach((c, k) => {
545
+ if (k > 0) base.push(`<line class="dg-tm-sep" x1="${r1(c.x)}" y1="${r1(c.y + T.sep)}" x2="${r1(c.x)}" y2="${r1(c.y + c.h - T.sep)}"/>`);
546
+ base.push(write(ink, ja("dg-tm-hd", c.head), c.x + c.w / 2, z.headY, c.head, TYPE.timeHead, ALWAYS, "middle"));
547
+ for (const box of c.boxes) node.push(columnBox(box, c.unit));
548
+ });
549
+ }
550
+ function columnBox(box, unit) {
551
+ const on = [...new Set(layout.wires.filter((w) => w.from === box || w.to === box).map((w) => w.step))].sort((a, b) => a - b);
552
+ const frame = (cls) => `<rect class="${cls}" x="${r1(box.x)}" y="${r1(box.y)}" width="${r1(box.w)}" height="${box.h}" rx="${LOOK.box.radius}"/>`;
553
+ if (box.empty) {
554
+ const shown2 = passed.get(unit);
555
+ const word = layout.zoom?.empty ?? "";
556
+ const mark = shown2 === void 0 ? "" : `<g class="dg-a" style="${m.vis(shown2)}">${frame("dg-tm-ex")}${write(ink, "dg-tm-ext", box.cx, box.cy + LOOK.baseline.mark, word, TYPE.emptyText, [[shown2, Number.POSITIVE_INFINITY]], "middle")}</g>`;
557
+ return `<g data-empty="${esc(box.id)}">${frame("dg-tm-ph")}${mark}</g>`;
558
+ }
559
+ const drawn = linkTo(diagram.boxes.find((b) => b.id === box.id)?.link, card(box, ctx, on, subs.get(box.id) ?? []));
560
+ if (!box.row) return drawn;
561
+ const shown = filled(box.row, unit);
562
+ if (shown === void 0) return frame("dg-tm-ph");
563
+ return `<g class="dg-a" style="${m.until(shown)}">${frame("dg-tm-ph")}</g><g class="dg-popc dg-a" style="${m.pop(shown)}">${drawn}</g>`;
564
+ }
565
+ for (const row of layout.rows) {
566
+ const parts = [];
567
+ for (const mark of layout.marks.filter((x2) => x2.row === row.id)) {
568
+ const rect = (cls, extra = "") => `<rect class="${cls}" x="${r1(mark.x)}" y="${r1(mark.y)}" width="${r1(mark.w)}" height="${r1(mark.h)}" rx="${T.markRadius}"${extra}/>`;
569
+ parts.push(rect("dg-tm-slot"));
570
+ if (mark.empty) {
571
+ const shown2 = passed.get(mark.unit);
572
+ if (shown2 !== void 0) parts.push(`<circle class="dg-tm-x dg-a" cx="${r1(mark.x + mark.w / 2)}" cy="${r1(mark.y + mark.h / 2)}" r="${T.emptyR}" style="${m.vis(shown2, m.last, { f: 0.2 })}"/>`);
573
+ continue;
574
+ }
575
+ const shown = filled(row.id, mark.unit);
576
+ if (shown !== void 0) parts.push(rect("dg-tm-m dg-a", ` style="${m.vis(shown, m.last, { f: 0.2 })}"`));
577
+ mark.colors.forEach((c, k) => {
578
+ const t = at(c.step, c.event);
579
+ if (t === void 0) return;
580
+ const next = mark.colors[k + 1];
581
+ const until = next ? at(next.step, next.event) : void 0;
582
+ parts.push(`<g style="${cs(c.color)}">${rect("dg-tm-m dg-a", ` style="${m.vis(t, until ?? m.last, { f: 0.35 })}"`)}</g>`);
583
+ });
584
+ }
585
+ base.push(`<g data-row="${esc(row.id)}" style="${cs(row.color)}">${parts.join("")}</g>`);
586
+ base.push(write(ink, "dg-tm-rn", LOOK.margin + LOOK.region.inset, row.y + row.h / 2 + LOOK.baseline.mark, row.name, TYPE.timeRow));
587
+ }
588
+ if (layout.zoom) {
589
+ const z = layout.zoom;
590
+ const hide = layout.spans.filter((s) => s.kind === "box" && s.from <= z.to && z.from <= s.to).map((s) => at(s.step, s.event)).filter((t) => t !== void 0).sort((a, b) => a - b)[0];
591
+ const guides = z.guides.map((g) => `<path class="dg-tm-gd" d="${pathOf(g)}"/>`).join("");
592
+ const lens = `<rect class="dg-tm-fr" x="${r1(z.frame.x)}" y="${r1(z.frame.y)}" width="${r1(z.frame.w)}" height="${r1(z.frame.h)}" rx="4"/>${guides}`;
593
+ base.push(hide === void 0 ? lens : `<g class="dg-a" style="${m.until(hide)}">${lens}</g>`);
594
+ }
595
+ const x = (u) => r1(axis.x + u * axis.unit);
596
+ const majors = layout.ticks.map((t) => `M ${x(t.at)} ${r1(axis.line - T.major / 2)} V ${r1(axis.line + T.major / 2)}`);
597
+ const minors = layout.minor.map((u) => `M ${x(u)} ${r1(axis.line - T.minor / 2)} V ${r1(axis.line + T.minor / 2)}`);
598
+ base.push(`<path class="dg-tm-ax" d="M ${x(0)} ${r1(axis.line)} H ${x(axis.count)} ${[...majors, ...minors].join(" ")}"/>`);
599
+ for (const t of layout.ticks) base.push(write(ink, ja("dg-tm-tk", t.text), t.left, t.y, t.text, TYPE.timeTick));
600
+ for (const p of layout.periods) {
601
+ base.push(write(ink, ja("dg-tm-en", p.name), p.x + p.w / 2, p.nameY, p.name, TYPE.timePeriod, ALWAYS, "middle"));
602
+ base.push(write(ink, ja("dg-tm-er", p.range), p.x + p.w / 2, p.rangeY, p.range, TYPE.timeRange, ALWAYS, "middle"));
603
+ }
604
+ for (const span of layout.spans) {
605
+ const a = at(span.step, span.event);
606
+ if (a === void 0) continue;
607
+ const until = span.until === void 0 ? void 0 : timeline.steps[span.until].start;
608
+ const shown = [[a, until ?? Number.POSITIVE_INFINITY]];
609
+ const vis = until === void 0 ? m.vis(a) : m.vis(a, until, { within: true });
610
+ if (span.kind === "bracket") {
611
+ const [x0, x1, y0, y12] = [r1(span.x + 1), r1(span.x + span.w - 1), r1(span.y), r1(span.y + span.h)];
612
+ const words = write(ink, ja("dg-tm-bt", span.text), span.textRect.x + span.textRect.w / 2, span.textY, span.text, TYPE.spanText, shown, "middle");
613
+ base.push(`<g class="dg-a" data-span="${span.step}" style="${cs(span.color)};${vis}"><path class="dg-tm-br" d="M ${x0} ${y0} L ${x0} ${y12} L ${x1} ${y12} L ${x1} ${y0}"/>${words}</g>`);
614
+ continue;
615
+ }
616
+ base.push(`<g class="dg-a" data-span="${span.step}" style="${cs(span.color)};${vis}"><rect class="dg-tm-bx" x="${r1(span.x)}" y="${r1(span.y)}" width="${r1(span.w)}" height="${r1(span.h)}" rx="6"/></g>`);
617
+ const tag = span.textRect;
618
+ ink.push({ text: span.text, rect: tag, shown, boxed: true });
619
+ top.push(
620
+ `<g class="dg-tg dg-popc dg-a" style="${cs(span.color)};${until === void 0 ? m.pop(a) : m.pop(a, until)}"><rect x="${r1(tag.x)}" y="${r1(tag.y)}" width="${r1(tag.w)}" height="${tag.h}" rx="${tag.h / 2}"/><text x="${r1(tag.x + tag.w / 2)}" y="${r1(span.textY)}" text-anchor="middle">${esc(span.text)}</text></g>`
621
+ );
622
+ }
623
+ const P = T.point;
624
+ for (const point of layout.points) {
625
+ const { cx, cy, r } = point;
626
+ const times = point.changes.map((c) => at(c.step, c.event) ?? Number.POSITIVE_INFINITY);
627
+ const first = times[0];
628
+ base.push(`<path class="dg-tm-con" d="M ${r1(cx)} ${r1(rowsBottom + 3)} L ${r1(cx)} ${r1(cy - r - 2)}"/>`);
629
+ const tx = point.text.x;
630
+ const name = write(ink, ja("dg-tm-pn", point.id), tx, cy + P.nameY, point.id, TYPE.pointName);
631
+ const grey = name.replace(/class="([^"]*)"/u, 'class="$1 dg-tm-pn-g"');
632
+ const label = first === void 0 || !Number.isFinite(first) ? grey : `<g class="dg-a" style="${m.until(first)}">${grey}</g><g class="dg-a" style="${m.vis(first)}">${name}</g>`;
633
+ const states = point.changes.map((c, k) => {
634
+ const t = times[k];
635
+ if (!Number.isFinite(t)) return "";
636
+ const next = times[k + 1];
637
+ const end2 = next !== void 0 && Number.isFinite(next) ? next - MOTION.untilFade : void 0;
638
+ const words = write(ink, ja("dg-tm-ps", c.text), tx, cy + P.stateY, c.text, TYPE.pointState, [[t, end2 ?? Number.POSITIVE_INFINITY]]);
639
+ return `<g class="dg-a" style="${cs(c.color ?? "slate")};${end2 === void 0 ? m.rise(t) : m.rise(t, end2)}">${words}</g>`;
640
+ }).join("");
641
+ const rings = point.changes.map((c, k) => {
642
+ const t = times[k];
643
+ if (!c.color || !Number.isFinite(t)) return "";
644
+ return `<g class="dg-popc dg-a" style="${cs(c.color)};${m.pop(t)}"><circle class="dg-tm-pc" cx="${r1(cx)}" cy="${r1(cy)}" r="${r + 0.5}"/>${glyph("flag", cx, cy, P.glyph, "dg-tm-pcg")}</g>`;
645
+ }).join("");
646
+ node.push(`<g data-point="${esc(point.id)}"><circle class="dg-tm-pg" cx="${r1(cx)}" cy="${r1(cy)}" r="${r}"/>${glyph("flag", cx, cy, P.glyph, "dg-tm-pgl")}${rings}${label}${states}</g>`);
647
+ }
648
+ const wired = new Set(layout.wires.map((w) => `${w.step}/${w.event}`));
649
+ for (const e of layout.edges) {
650
+ if (wired.has(`${e.step}/${e.event}`)) continue;
651
+ const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
652
+ if (!time) continue;
653
+ ctx.traces.push({ from: e.from, to: e.to, points: e.points, shown: [[time.start, Number.POSITIVE_INFINITY]] });
654
+ const kf = m.kf([
655
+ [0, { opacity: 0, "stroke-dashoffset": 1 }],
656
+ [time.start, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
657
+ [time.start + 0.05, { opacity: 1 }],
658
+ [time.drawn, { "stroke-dashoffset": 0 }],
659
+ [m.last, { opacity: 1, "stroke-dashoffset": 0 }, EASE.inOut],
660
+ [m.total, { opacity: 0, "stroke-dashoffset": 0 }]
661
+ ]);
662
+ const head = m.kf([
663
+ [0, { opacity: 0 }],
664
+ [time.drawn - 0.05, { opacity: 0 }],
665
+ [time.drawn, { opacity: 1 }],
666
+ [m.last, { opacity: 1 }, EASE.inOut],
667
+ [m.total, { opacity: 0 }]
668
+ ]);
669
+ lit.push(`<g data-link="${esc(`${e.from}->${e.to}`)}" style="${cs(e.color)}"><path class="dg-tm-ln dg-a" pathLength="1" d="${pathOf(e.points)}" style="${kf}"/><path class="dg-eh-on dg-a" d="${arrowHead(e.points)}" style="${head}"/></g>`);
670
+ }
671
+ const keys = timeline.needle ?? [];
672
+ const moved = simplify(keys.filter(([t]) => t < m.total));
673
+ const end = moved[moved.length - 1]?.[1] ?? 0;
674
+ const path = [...moved.map(([t, u]) => [t, axis.x + u * axis.unit, 0]), [m.last, axis.x + end * axis.unit, 0], [m.total, axis.x, 0]];
675
+ const { y1, y2 } = layout.needle;
676
+ const N = T.needle;
677
+ top.push(
678
+ `<g class="dg-a" data-needle="" style="${m.move(path)}"><line class="dg-tm-nd" x1="0" y1="${r1(y1)}" x2="0" y2="${r1(y2)}"/><path class="dg-tm-nh" d="M ${-N.head * 0.75} ${r1(y1 - N.head)} L ${N.head * 0.75} ${r1(y1 - N.head)} L 0 ${r1(y1)} Z"/><circle class="dg-tm-nh" cy="${r1(axis.line)}" r="${N.dot}"/></g>`
679
+ );
680
+ return { base: base.join(""), lit: lit.join(""), node: node.join(""), top: top.join("") };
681
+ }
682
+ function meterField(field, keys, ctx) {
683
+ const { m } = ctx;
684
+ const M = LOOK.time.meter;
685
+ const { x, w, line, text } = field.meter;
686
+ const y = field.y + M.y;
687
+ const kf = m.kf([
688
+ ...simplify(keys).map(([t, v]) => [t, { transform: `scaleX(${r1(v * 1e3) / 1e3})` }]),
689
+ [m.last, { transform: `scaleX(${r1(valueAt(keys, m.last) * 1e3) / 1e3})` }, EASE.inOut],
690
+ [m.total, { transform: "scaleX(0)" }]
691
+ ]);
692
+ const lx = x + w * line;
693
+ return `<rect class="dg-tm-mt" x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${M.h}" rx="${M.h / 2}"/><rect class="dg-tm-mf dg-a" x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${M.h}" rx="${M.h / 2}" style="${cs(M.color)};${kf}"/><line class="dg-tm-mk" x1="${r1(lx)}" y1="${r1(y - M.mark)}" x2="${r1(lx)}" y2="${r1(y + M.h + M.mark)}"/>` + write(ctx.ink, "dg-tm-ml", lx, field.y + M.textY, text, TYPE.meterLine, ALWAYS, "middle");
694
+ }
695
+ function timeFocus(layout, timeline, step, parts, vw, vh) {
696
+ const span = timeline.steps[step];
697
+ const position = valueAt(timeline.needle ?? [], span.end - MOTION.still);
698
+ const nx = layout.axis.x + position * layout.axis.unit;
699
+ const top = Math.min(...layout.rows.map((r) => r.y));
700
+ const bottom = Math.max(...layout.rows.map((r) => r.y + r.h));
701
+ let held = { x: nx - 1, y: top, w: 2, h: bottom - top };
702
+ const badge = layout.badges.find((b) => b.step === step);
703
+ const near = (p) => Math.hypot(Math.max(0, p.x - nx, nx - p.x - p.w), Math.max(0, p.y - top, top - p.y - p.h));
704
+ const extra = [...badge ? [{ x: badge.x - LOOK.badge.r, y: badge.y - LOOK.badge.r, w: LOOK.badge.r * 2, h: LOOK.badge.r * 2 }] : [], ...[...parts].sort((a, b) => near(a) - near(b))];
705
+ for (const p of extra) {
706
+ const x = Math.min(held.x, p.x);
707
+ const y = Math.min(held.y, p.y);
708
+ const next = { x, y, w: Math.max(held.x + held.w, p.x + p.w) - x, h: Math.max(held.y + held.h, p.y + p.h) - y };
709
+ if (next.w <= vw && next.h <= vh) held = next;
710
+ }
711
+ return held;
712
+ }
713
+ export {
714
+ drawTime,
715
+ layoutTime,
716
+ meterField,
717
+ timeFocus
718
+ };
719
+ //# sourceMappingURL=time-B5WUQOFP.js.map