@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.5

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 (124) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +85 -0
  5. package/dist/bar-chart/bar-chart.d.ts +33 -19
  6. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  7. package/dist/bar-chart/bar-chart.js +68 -64
  8. package/dist/bar-chart/bar-chart.js.map +1 -1
  9. package/dist/bar-chart/category-axis.d.ts +2 -2
  10. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  11. package/dist/bar-chart/category-axis.js +2 -2
  12. package/dist/bar-chart/category-axis.js.map +1 -1
  13. package/dist/bar-chart/chart-bars.d.ts +1 -1
  14. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  15. package/dist/bar-chart/chart-bars.js +2 -2
  16. package/dist/bar-chart/chart-bars.js.map +1 -1
  17. package/dist/bar-chart/index.js.map +1 -1
  18. package/dist/bar-chart/shared.d.ts +4 -4
  19. package/dist/bar-chart/shared.d.ts.map +1 -1
  20. package/dist/bar-chart/shared.js +4 -4
  21. package/dist/bar-chart/shared.js.map +1 -1
  22. package/dist/browser/chunks/chunk-5ZPBV6BU.js +2 -0
  23. package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +7 -0
  24. package/dist/browser/index.js +1 -1
  25. package/dist/browser/index.js.map +3 -3
  26. package/dist/browser/kit.js +1 -1
  27. package/dist/browser/manifest.json +4 -3
  28. package/dist/engine.d.ts +1 -1
  29. package/dist/engine.d.ts.map +1 -1
  30. package/dist/engine.js +1 -1
  31. package/dist/engine.js.map +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/kit/chart-border.d.ts +1 -1
  34. package/dist/kit/chart-border.d.ts.map +1 -1
  35. package/dist/kit/chart-border.js +2 -2
  36. package/dist/kit/chart-border.js.map +1 -1
  37. package/dist/kit/chart-canvas.d.ts +1 -1
  38. package/dist/kit/chart-canvas.d.ts.map +1 -1
  39. package/dist/kit/chart-canvas.js +2 -2
  40. package/dist/kit/chart-canvas.js.map +1 -1
  41. package/dist/kit/chart-legend.d.ts +6 -27
  42. package/dist/kit/chart-legend.d.ts.map +1 -1
  43. package/dist/kit/chart-legend.js +33 -57
  44. package/dist/kit/chart-legend.js.map +1 -1
  45. package/dist/kit/shared.d.ts +31 -8
  46. package/dist/kit/shared.d.ts.map +1 -1
  47. package/dist/kit/shared.js +67 -11
  48. package/dist/kit/shared.js.map +1 -1
  49. package/dist/kit/vertical-axis.d.ts +2 -2
  50. package/dist/kit/vertical-axis.d.ts.map +1 -1
  51. package/dist/kit/vertical-axis.js +2 -2
  52. package/dist/kit/vertical-axis.js.map +1 -1
  53. package/dist/line-chart/chart-line.d.ts +3 -3
  54. package/dist/line-chart/chart-line.d.ts.map +1 -1
  55. package/dist/line-chart/chart-line.js +2 -2
  56. package/dist/line-chart/chart-line.js.map +1 -1
  57. package/dist/line-chart/chart-region.d.ts +1 -1
  58. package/dist/line-chart/chart-region.d.ts.map +1 -1
  59. package/dist/line-chart/chart-region.js +2 -2
  60. package/dist/line-chart/chart-region.js.map +1 -1
  61. package/dist/line-chart/horizontal-axis.d.ts +2 -2
  62. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  63. package/dist/line-chart/horizontal-axis.js +2 -2
  64. package/dist/line-chart/horizontal-axis.js.map +1 -1
  65. package/dist/line-chart/index.js.map +1 -1
  66. package/dist/line-chart/line-chart.d.ts +25 -9
  67. package/dist/line-chart/line-chart.d.ts.map +1 -1
  68. package/dist/line-chart/line-chart.js +66 -43
  69. package/dist/line-chart/line-chart.js.map +1 -1
  70. package/dist/line-chart/shared.d.ts +4 -4
  71. package/dist/line-chart/shared.d.ts.map +1 -1
  72. package/dist/line-chart/shared.js +20 -5
  73. package/dist/line-chart/shared.js.map +1 -1
  74. package/dist/line-chart/x-scale.d.ts +2 -2
  75. package/dist/line-chart/x-scale.d.ts.map +1 -1
  76. package/dist/line-chart/x-scale.js +2 -2
  77. package/dist/line-chart/x-scale.js.map +1 -1
  78. package/dist/nodes.js.map +1 -1
  79. package/dist/pie-chart/index.js.map +1 -1
  80. package/dist/pie-chart/pie-chart.d.ts +16 -10
  81. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  82. package/dist/pie-chart/pie-chart.js +15 -16
  83. package/dist/pie-chart/pie-chart.js.map +1 -1
  84. package/dist/pie-chart/pie-legend.d.ts +2 -2
  85. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  86. package/dist/pie-chart/pie-legend.js +6 -6
  87. package/dist/pie-chart/pie-legend.js.map +1 -1
  88. package/dist/pie-chart/pie-ring.d.ts +14 -5
  89. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  90. package/dist/pie-chart/pie-ring.js +45 -15
  91. package/dist/pie-chart/pie-ring.js.map +1 -1
  92. package/dist/pie-chart/shared.d.ts +4 -4
  93. package/dist/pie-chart/shared.d.ts.map +1 -1
  94. package/dist/pie-chart/shared.js +4 -4
  95. package/dist/pie-chart/shared.js.map +1 -1
  96. package/package.json +6 -4
  97. package/registry.json +23 -23
  98. package/src/bar-chart/bar-chart.ts +820 -804
  99. package/src/bar-chart/category-axis.ts +177 -177
  100. package/src/bar-chart/chart-bars.ts +310 -310
  101. package/src/bar-chart/index.ts +31 -31
  102. package/src/bar-chart/shared.ts +354 -354
  103. package/src/engine.ts +26 -26
  104. package/src/index.ts +5 -5
  105. package/src/kit/chart-border.ts +61 -61
  106. package/src/kit/chart-canvas.ts +157 -157
  107. package/src/kit/chart-legend.ts +245 -250
  108. package/src/kit/shared.ts +733 -675
  109. package/src/kit/vertical-axis.ts +224 -224
  110. package/src/line-chart/chart-line.ts +208 -208
  111. package/src/line-chart/chart-region.ts +135 -135
  112. package/src/line-chart/horizontal-axis.ts +202 -202
  113. package/src/line-chart/index.ts +39 -39
  114. package/src/line-chart/line-chart.ts +961 -894
  115. package/src/line-chart/shared.ts +473 -459
  116. package/src/line-chart/x-scale.ts +367 -367
  117. package/src/nodes.ts +20 -20
  118. package/src/pie-chart/index.ts +37 -37
  119. package/src/pie-chart/pie-chart.ts +383 -374
  120. package/src/pie-chart/pie-legend.ts +159 -159
  121. package/src/pie-chart/pie-ring.ts +935 -903
  122. package/src/pie-chart/shared.ts +490 -490
  123. package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
  124. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
@@ -1,224 +1,224 @@
1
- import {
2
- command,
3
- Node2D,
4
- Rect,
5
- RotatedBox,
6
- Text,
7
- easeOut,
8
- property,
9
- insetsOps,
10
- textOps,
11
- type CommandArgs,
12
- type NodeConfig,
13
- type Node2DProps,
14
- } from "@motionscript/core"
15
-
16
- import {
17
- DEFAULT_Y_AXIS,
18
- enterBudget,
19
- formatMarker,
20
- type AxisConfig,
21
- type Range,
22
- } from "./shared"
23
- import { at, compose, type Seekable } from "@motionscript/core/component"
24
-
25
- export interface VerticalAxisProps extends Node2DProps {
26
- /** `[min, max]` of the vertical scale the markers are positioned within. */
27
- range: Range
28
- /**
29
- * Tick values (in data units) to draw up the axis, each placed by its fraction
30
- * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include
31
- * the ends.
32
- */
33
- markers: number[]
34
- /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
35
- axis: AxisConfig
36
- /**
37
- * Rotated caption drawn in the gutter to the left of the marker column. Empty
38
- * string (the default) hides it — no caption node is built and no label gutter
39
- * is reserved.
40
- */
41
- label: string
42
- }
43
-
44
- /** How far a marker starts to the right of its slot when it enters, in px. */
45
- const SLIDE = 24
46
-
47
- /** How a tick value is captioned — see {@link VerticalAxis.labelFor}. */
48
- export type MarkerLabel = (value: number) => string
49
-
50
- /**
51
- * The numeric vertical axis shared by the cartesian charts: a **column of
52
- * {@link Text} nodes**, one per marker value, running top-to-bottom (highest
53
- * value at the top). Pure layout — no `Graphics` — so the markers are real text
54
- * nodes the scene can measure, restyle, or animate individually.
55
- *
56
- * Each marker is positioned so its centre lands exactly on its value's fraction
57
- * across `range` within the axis's filled height, so unevenly-spaced markers
58
- * land where their values fall. Both the caption and the position are *bound*,
59
- * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
60
- * tweens `range`/`markers` live. Only the marker **count** is fixed at
61
- * construction.
62
- *
63
- * {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a
64
- * little to the right and transparent, then fades and slides left into place.
65
- * The resting state is the landed one, so a chart that is never told to enter
66
- * still reads as a finished chart.
67
- */
68
- export class VerticalAxis extends Node2D<VerticalAxisProps> {
69
- @property({ default: () => [0, 1] as Range }) declare range: Range
70
- @property({ default: () => [] as number[] }) declare markers: number[]
71
- @property({ default: DEFAULT_Y_AXIS }) declare axis: AxisConfig
72
- @property({ default: "" }) declare label: string
73
-
74
- /**
75
- * How a tick value is captioned. Defaults to the bare numeric reading; a
76
- * chart with a number format on this axis replaces it (see `number-format`).
77
- *
78
- * A plain field rather than a `@property`, for the reason the horizontal
79
- * axis's twin spells out: it is a policy, not a value, and there is nothing
80
- * to tween between two formatters.
81
- */
82
- labelFor: MarkerLabel = formatMarker
83
-
84
- /** One text node per marker, ordered top → bottom, for the staggered enter. */
85
- private markerNodes: Text[] = []
86
- /** The caption node, or null when `label` is empty. Entered after the markers. */
87
- private labelNode: Text | null = null
88
-
89
- /** The live tick values, top → bottom (highest first) — re-read every frame. */
90
- private get sortedMarkers(): number[] {
91
- return [...this.markers].sort((a, b) => b - a)
92
- }
93
-
94
- /**
95
- * Tick `i`'s value, or `undefined` once the live `markers` list is shorter
96
- * than the column of text nodes built for it — a slot with no value renders as
97
- * empty text rather than repeating its neighbour.
98
- */
99
- private valueAt(index: number): number | undefined {
100
- return this.sortedMarkers[index]
101
- }
102
-
103
- /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
104
- private fracAt(index: number): number {
105
- const v = this.valueAt(index)
106
- if (v === undefined) return 0
107
- const [min, max] = this.range
108
- return max <= min ? 0 : (v - min) / (max - min)
109
- }
110
-
111
- constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>) {
112
- super(props)
113
-
114
- // Composed from plain props (range/markers/label) — no context needed, so
115
- // it's built here. super() applied the props, so the reads below resolve.
116
- const tickPad = insetsOps.resolve(this.axis.tickPadding).right
117
- const titlePad = insetsOps.resolve(this.axis.titlePadding).right
118
-
119
- this.markerNodes = this.markers.map((_, i) => {
120
- const marker: Text = new Text({
121
- ...textOps.styleProps(this.axis.labelStyle),
122
- text: () => {
123
- const v = this.valueAt(i)
124
- return v === undefined ? "" : this.labelFor(v)
125
- },
126
- y: () => {
127
- // Node2D space is y-up, so the fraction runs from the bottom.
128
- const height = this.layoutBounds.height
129
- const centred = (this.fracAt(i) - 0.5) * height
130
- // Held inside the axis's top edge — the backstop for a chart whose
131
- // headroom is smaller than its marker text is tall, which a theme with
132
- // much larger markers can arrange. Only the top, because what lies
133
- // below the axis is the chart's own horizontal axis and legend.
134
- const limit = height / 2 - marker.layoutBounds.height / 2
135
- return Math.min(centred, limit)
136
- },
137
- })
138
- return marker
139
- })
140
-
141
- const children: Node2D[] = []
142
- if (this.label !== "") {
143
- this.labelNode = new Text({
144
- ...textOps.styleProps(this.axis.titleStyle),
145
- text: this.label,
146
- })
147
- // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
148
- children.push(
149
- new RotatedBox({
150
- angle: -90,
151
- width: "hug",
152
- height: "hug",
153
- children: this.labelNode,
154
- })
155
- )
156
- }
157
- children.push(
158
- new Rect({
159
- height: "fill",
160
- width: "hug",
161
- padding: { right: tickPad },
162
- children: this.markerNodes,
163
- })
164
- )
165
-
166
- this.add(new Rect({ flow: "horizontal", gap: titlePad, children }))
167
- }
168
-
169
- /**
170
- * Primes every marker (and the caption) at its pre-entrance state: shifted
171
- * right and transparent. Idempotent, and separate from {@link enter} so the
172
- * chart can arm its whole composition before the first frame is drawn.
173
- */
174
- arm(slide = SLIDE): void {
175
- for (const marker of this.markerNodes) marker.set({ opacity: 0, x: slide })
176
- this.labelNode?.set({ opacity: 0, x: slide })
177
- }
178
-
179
- /**
180
- * Stagger the markers in bottom to top, then slide the caption in from the
181
- * right after them.
182
- *
183
- * A {@link Seekable} rather than a generator — see the note on the horizontal
184
- * axis's `enter`. The offsets were always static; expressing them as `wait`
185
- * inside a generator is what made them reachable only by running it.
186
- *
187
- * `args.duration` is the **whole** entrance, not one marker's slide: the
188
- * stagger and the caption are carved out of it rather than added on top. See
189
- * {@link enterBudget} for why that distinction matters here.
190
- *
191
- * `args.data.stagger` is seconds between successive markers (derived when
192
- * omitted); `args.data.slide` is the starting rightward offset in px.
193
- */
194
- @command()
195
- enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {
196
- const { stagger, slide = SLIDE } = args.data ?? {}
197
- const easing = args.easing ?? easeOut()
198
- const nodes = this.markerNodes
199
- if (nodes.length === 0) return compose([])
200
- const { step, per, caption } = enterBudget(
201
- args.duration,
202
- nodes.length,
203
- this.labelNode !== null,
204
- stagger
205
- )
206
-
207
- this.arm(slide)
208
-
209
- // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.
210
- const markers = nodes.map((node, i) => {
211
- const order = nodes.length - 1 - i // bottom-most = 0
212
- return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))
213
- })
214
- const lastMarkerEnds = (nodes.length - 1) * step + per
215
-
216
- // Once every marker has landed, the caption slides in from the right.
217
- return compose([
218
- ...markers,
219
- ...(this.labelNode
220
- ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]
221
- : []),
222
- ])
223
- }
224
- }
1
+ import {
2
+ command,
3
+ Node2D,
4
+ Rect,
5
+ RotatedBox,
6
+ Text,
7
+ easeOut,
8
+ property,
9
+ insetsOps,
10
+ textOps,
11
+ type CommandArgs,
12
+ type NodeConfig,
13
+ type Node2DProps,
14
+ } from "@motionscript/sdk"
15
+
16
+ import {
17
+ DEFAULT_Y_AXIS,
18
+ enterBudget,
19
+ formatMarker,
20
+ type AxisConfig,
21
+ type Range,
22
+ } from "./shared"
23
+ import { at, compose, type Seekable } from "@motionscript/sdk/component"
24
+
25
+ export interface VerticalAxisProps extends Node2DProps {
26
+ /** `[min, max]` of the vertical scale the markers are positioned within. */
27
+ range: Range
28
+ /**
29
+ * Tick values (in data units) to draw up the axis, each placed by its fraction
30
+ * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include
31
+ * the ends.
32
+ */
33
+ markers: number[]
34
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
35
+ axis: AxisConfig
36
+ /**
37
+ * Rotated caption drawn in the gutter to the left of the marker column. Empty
38
+ * string (the default) hides it — no caption node is built and no label gutter
39
+ * is reserved.
40
+ */
41
+ label: string
42
+ }
43
+
44
+ /** How far a marker starts to the right of its slot when it enters, in px. */
45
+ const SLIDE = 24
46
+
47
+ /** How a tick value is captioned — see {@link VerticalAxis.labelFor}. */
48
+ export type MarkerLabel = (value: number) => string
49
+
50
+ /**
51
+ * The numeric vertical axis shared by the cartesian charts: a **column of
52
+ * {@link Text} nodes**, one per marker value, running top-to-bottom (highest
53
+ * value at the top). Pure layout — no `Graphics` — so the markers are real text
54
+ * nodes the scene can measure, restyle, or animate individually.
55
+ *
56
+ * Each marker is positioned so its centre lands exactly on its value's fraction
57
+ * across `range` within the axis's filled height, so unevenly-spaced markers
58
+ * land where their values fall. Both the caption and the position are *bound*,
59
+ * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
60
+ * tweens `range`/`markers` live. Only the marker **count** is fixed at
61
+ * construction.
62
+ *
63
+ * {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a
64
+ * little to the right and transparent, then fades and slides left into place.
65
+ * The resting state is the landed one, so a chart that is never told to enter
66
+ * still reads as a finished chart.
67
+ */
68
+ export class VerticalAxis extends Node2D<VerticalAxisProps> {
69
+ @property({ default: () => [0, 1] as Range }) declare range: Range
70
+ @property({ default: () => [] as number[] }) declare markers: number[]
71
+ @property({ default: DEFAULT_Y_AXIS }) declare axis: AxisConfig
72
+ @property({ default: "" }) declare label: string
73
+
74
+ /**
75
+ * How a tick value is captioned. Defaults to the bare numeric reading; a
76
+ * chart with a number format on this axis replaces it (see `number-format`).
77
+ *
78
+ * A plain field rather than a `@property`, for the reason the horizontal
79
+ * axis's twin spells out: it is a policy, not a value, and there is nothing
80
+ * to tween between two formatters.
81
+ */
82
+ labelFor: MarkerLabel = formatMarker
83
+
84
+ /** One text node per marker, ordered top → bottom, for the staggered enter. */
85
+ private markerNodes: Text[] = []
86
+ /** The caption node, or null when `label` is empty. Entered after the markers. */
87
+ private labelNode: Text | null = null
88
+
89
+ /** The live tick values, top → bottom (highest first) — re-read every frame. */
90
+ private get sortedMarkers(): number[] {
91
+ return [...this.markers].sort((a, b) => b - a)
92
+ }
93
+
94
+ /**
95
+ * Tick `i`'s value, or `undefined` once the live `markers` list is shorter
96
+ * than the column of text nodes built for it — a slot with no value renders as
97
+ * empty text rather than repeating its neighbour.
98
+ */
99
+ private valueAt(index: number): number | undefined {
100
+ return this.sortedMarkers[index]
101
+ }
102
+
103
+ /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
104
+ private fracAt(index: number): number {
105
+ const v = this.valueAt(index)
106
+ if (v === undefined) return 0
107
+ const [min, max] = this.range
108
+ return max <= min ? 0 : (v - min) / (max - min)
109
+ }
110
+
111
+ constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>) {
112
+ super(props)
113
+
114
+ // Composed from plain props (range/markers/label) — no context needed, so
115
+ // it's built here. super() applied the props, so the reads below resolve.
116
+ const tickPad = insetsOps.resolve(this.axis.tickPadding).right
117
+ const titlePad = insetsOps.resolve(this.axis.titlePadding).right
118
+
119
+ this.markerNodes = this.markers.map((_, i) => {
120
+ const marker: Text = new Text({
121
+ ...textOps.styleProps(this.axis.labelStyle),
122
+ text: () => {
123
+ const v = this.valueAt(i)
124
+ return v === undefined ? "" : this.labelFor(v)
125
+ },
126
+ y: () => {
127
+ // Node2D space is y-up, so the fraction runs from the bottom.
128
+ const height = this.layoutBounds.height
129
+ const centred = (this.fracAt(i) - 0.5) * height
130
+ // Held inside the axis's top edge — the backstop for a chart whose
131
+ // headroom is smaller than its marker text is tall, which a theme with
132
+ // much larger markers can arrange. Only the top, because what lies
133
+ // below the axis is the chart's own horizontal axis and legend.
134
+ const limit = height / 2 - marker.layoutBounds.height / 2
135
+ return Math.min(centred, limit)
136
+ },
137
+ })
138
+ return marker
139
+ })
140
+
141
+ const children: Node2D[] = []
142
+ if (this.label !== "") {
143
+ this.labelNode = new Text({
144
+ ...textOps.styleProps(this.axis.titleStyle),
145
+ text: this.label,
146
+ })
147
+ // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
148
+ children.push(
149
+ new RotatedBox({
150
+ angle: -90,
151
+ width: "hug",
152
+ height: "hug",
153
+ children: this.labelNode,
154
+ })
155
+ )
156
+ }
157
+ children.push(
158
+ new Rect({
159
+ height: "fill",
160
+ width: "hug",
161
+ padding: { right: tickPad },
162
+ children: this.markerNodes,
163
+ })
164
+ )
165
+
166
+ this.add(new Rect({ flow: "horizontal", gap: titlePad, children }))
167
+ }
168
+
169
+ /**
170
+ * Primes every marker (and the caption) at its pre-entrance state: shifted
171
+ * right and transparent. Idempotent, and separate from {@link enter} so the
172
+ * chart can arm its whole composition before the first frame is drawn.
173
+ */
174
+ arm(slide = SLIDE): void {
175
+ for (const marker of this.markerNodes) marker.set({ opacity: 0, x: slide })
176
+ this.labelNode?.set({ opacity: 0, x: slide })
177
+ }
178
+
179
+ /**
180
+ * Stagger the markers in bottom to top, then slide the caption in from the
181
+ * right after them.
182
+ *
183
+ * A {@link Seekable} rather than a generator — see the note on the horizontal
184
+ * axis's `enter`. The offsets were always static; expressing them as `wait`
185
+ * inside a generator is what made them reachable only by running it.
186
+ *
187
+ * `args.duration` is the **whole** entrance, not one marker's slide: the
188
+ * stagger and the caption are carved out of it rather than added on top. See
189
+ * {@link enterBudget} for why that distinction matters here.
190
+ *
191
+ * `args.data.stagger` is seconds between successive markers (derived when
192
+ * omitted); `args.data.slide` is the starting rightward offset in px.
193
+ */
194
+ @command()
195
+ enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {
196
+ const { stagger, slide = SLIDE } = args.data ?? {}
197
+ const easing = args.easing ?? easeOut()
198
+ const nodes = this.markerNodes
199
+ if (nodes.length === 0) return compose([])
200
+ const { step, per, caption } = enterBudget(
201
+ args.duration,
202
+ nodes.length,
203
+ this.labelNode !== null,
204
+ stagger
205
+ )
206
+
207
+ this.arm(slide)
208
+
209
+ // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.
210
+ const markers = nodes.map((node, i) => {
211
+ const order = nodes.length - 1 - i // bottom-most = 0
212
+ return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))
213
+ })
214
+ const lastMarkerEnds = (nodes.length - 1) * step + per
215
+
216
+ // Once every marker has landed, the caption slides in from the right.
217
+ return compose([
218
+ ...markers,
219
+ ...(this.labelNode
220
+ ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]
221
+ : []),
222
+ ])
223
+ }
224
+ }