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

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 (152) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/NOTICE +49 -0
  3. package/README.md +99 -0
  4. package/dist/bar-chart/bar-chart.d.ts +133 -228
  5. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  6. package/dist/bar-chart/bar-chart.js +386 -565
  7. package/dist/bar-chart/bar-chart.js.map +1 -1
  8. package/dist/bar-chart/category-axis.d.ts +35 -41
  9. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  10. package/dist/bar-chart/category-axis.js +93 -115
  11. package/dist/bar-chart/category-axis.js.map +1 -1
  12. package/dist/bar-chart/chart-bars.d.ts +50 -70
  13. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  14. package/dist/bar-chart/chart-bars.js +155 -210
  15. package/dist/bar-chart/chart-bars.js.map +1 -1
  16. package/dist/bar-chart/index.d.ts +2 -2
  17. package/dist/bar-chart/index.d.ts.map +1 -1
  18. package/dist/bar-chart/index.js +1 -1
  19. package/dist/bar-chart/index.js.map +1 -1
  20. package/dist/bar-chart/shared.d.ts +7 -7
  21. package/dist/bar-chart/shared.d.ts.map +1 -1
  22. package/dist/bar-chart/shared.js +7 -7
  23. package/dist/bar-chart/shared.js.map +1 -1
  24. package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
  25. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
  26. package/dist/browser/index.js +1 -1
  27. package/dist/browser/index.js.map +3 -3
  28. package/dist/browser/kit.js +1 -1
  29. package/dist/browser/manifest.json +4 -3
  30. package/dist/engine.d.ts +10 -8
  31. package/dist/engine.d.ts.map +1 -1
  32. package/dist/engine.js +10 -8
  33. package/dist/engine.js.map +1 -1
  34. package/dist/kit/cartesian.d.ts +44 -0
  35. package/dist/kit/cartesian.d.ts.map +1 -0
  36. package/dist/kit/cartesian.js +59 -0
  37. package/dist/kit/cartesian.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +10 -11
  39. package/dist/kit/chart-border.d.ts.map +1 -1
  40. package/dist/kit/chart-border.js +15 -32
  41. package/dist/kit/chart-border.js.map +1 -1
  42. package/dist/kit/chart-canvas.d.ts +32 -21
  43. package/dist/kit/chart-canvas.d.ts.map +1 -1
  44. package/dist/kit/chart-canvas.js +33 -90
  45. package/dist/kit/chart-canvas.js.map +1 -1
  46. package/dist/kit/chart-legend.d.ts +123 -85
  47. package/dist/kit/chart-legend.d.ts.map +1 -1
  48. package/dist/kit/chart-legend.js +137 -186
  49. package/dist/kit/chart-legend.js.map +1 -1
  50. package/dist/kit/entries.d.ts +17 -0
  51. package/dist/kit/entries.d.ts.map +1 -0
  52. package/dist/kit/entries.js +19 -0
  53. package/dist/kit/entries.js.map +1 -0
  54. package/dist/kit/motion.d.ts +48 -0
  55. package/dist/kit/motion.d.ts.map +1 -0
  56. package/dist/kit/motion.js +63 -0
  57. package/dist/kit/motion.js.map +1 -0
  58. package/dist/kit/paints.d.ts +10 -0
  59. package/dist/kit/paints.d.ts.map +1 -0
  60. package/dist/kit/paints.js +12 -0
  61. package/dist/kit/paints.js.map +1 -0
  62. package/dist/kit/shared.d.ts +61 -10
  63. package/dist/kit/shared.d.ts.map +1 -1
  64. package/dist/kit/shared.js +108 -13
  65. package/dist/kit/shared.js.map +1 -1
  66. package/dist/kit/vertical-axis.d.ts +48 -61
  67. package/dist/kit/vertical-axis.d.ts.map +1 -1
  68. package/dist/kit/vertical-axis.js +97 -132
  69. package/dist/kit/vertical-axis.js.map +1 -1
  70. package/dist/line-chart/chart-line.d.ts +60 -77
  71. package/dist/line-chart/chart-line.d.ts.map +1 -1
  72. package/dist/line-chart/chart-line.js +100 -121
  73. package/dist/line-chart/chart-line.js.map +1 -1
  74. package/dist/line-chart/chart-region.d.ts +32 -33
  75. package/dist/line-chart/chart-region.d.ts.map +1 -1
  76. package/dist/line-chart/chart-region.js +31 -65
  77. package/dist/line-chart/chart-region.js.map +1 -1
  78. package/dist/line-chart/horizontal-axis.d.ts +58 -64
  79. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  80. package/dist/line-chart/horizontal-axis.js +94 -123
  81. package/dist/line-chart/horizontal-axis.js.map +1 -1
  82. package/dist/line-chart/index.d.ts +3 -3
  83. package/dist/line-chart/index.d.ts.map +1 -1
  84. package/dist/line-chart/index.js +2 -2
  85. package/dist/line-chart/index.js.map +1 -1
  86. package/dist/line-chart/line-chart.d.ts +156 -303
  87. package/dist/line-chart/line-chart.d.ts.map +1 -1
  88. package/dist/line-chart/line-chart.js +410 -638
  89. package/dist/line-chart/line-chart.js.map +1 -1
  90. package/dist/line-chart/shared.d.ts +7 -7
  91. package/dist/line-chart/shared.d.ts.map +1 -1
  92. package/dist/line-chart/shared.js +23 -8
  93. package/dist/line-chart/shared.js.map +1 -1
  94. package/dist/line-chart/x-scale.d.ts +4 -11
  95. package/dist/line-chart/x-scale.d.ts.map +1 -1
  96. package/dist/line-chart/x-scale.js +16 -5
  97. package/dist/line-chart/x-scale.js.map +1 -1
  98. package/dist/nodes.d.ts +6 -9
  99. package/dist/nodes.d.ts.map +1 -1
  100. package/dist/nodes.js +7 -9
  101. package/dist/nodes.js.map +1 -1
  102. package/dist/pie-chart/index.d.ts +2 -2
  103. package/dist/pie-chart/index.d.ts.map +1 -1
  104. package/dist/pie-chart/index.js +1 -1
  105. package/dist/pie-chart/index.js.map +1 -1
  106. package/dist/pie-chart/pie-chart.d.ts +108 -126
  107. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  108. package/dist/pie-chart/pie-chart.js +202 -271
  109. package/dist/pie-chart/pie-chart.js.map +1 -1
  110. package/dist/pie-chart/pie-legend.d.ts +84 -31
  111. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  112. package/dist/pie-chart/pie-legend.js +93 -107
  113. package/dist/pie-chart/pie-legend.js.map +1 -1
  114. package/dist/pie-chart/pie-ring.d.ts +160 -122
  115. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  116. package/dist/pie-chart/pie-ring.js +333 -361
  117. package/dist/pie-chart/pie-ring.js.map +1 -1
  118. package/dist/pie-chart/shared.d.ts +12 -6
  119. package/dist/pie-chart/shared.d.ts.map +1 -1
  120. package/dist/pie-chart/shared.js +14 -8
  121. package/dist/pie-chart/shared.js.map +1 -1
  122. package/package.json +7 -4
  123. package/src/bar-chart/bar-chart.ts +424 -686
  124. package/src/bar-chart/category-axis.ts +96 -111
  125. package/src/bar-chart/chart-bars.ts +178 -201
  126. package/src/bar-chart/index.ts +2 -2
  127. package/src/bar-chart/shared.ts +7 -7
  128. package/src/engine.ts +10 -8
  129. package/src/kit/cartesian.ts +81 -0
  130. package/src/kit/chart-border.ts +23 -34
  131. package/src/kit/chart-canvas.ts +45 -80
  132. package/src/kit/chart-legend.ts +185 -206
  133. package/src/kit/entries.ts +20 -0
  134. package/src/kit/motion.ts +90 -0
  135. package/src/kit/paints.ts +15 -0
  136. package/src/kit/shared.ts +120 -13
  137. package/src/kit/vertical-axis.ts +111 -141
  138. package/src/line-chart/chart-line.ts +103 -155
  139. package/src/line-chart/chart-region.ts +36 -81
  140. package/src/line-chart/horizontal-axis.ts +102 -153
  141. package/src/line-chart/index.ts +3 -3
  142. package/src/line-chart/line-chart.ts +463 -759
  143. package/src/line-chart/shared.ts +22 -8
  144. package/src/line-chart/x-scale.ts +20 -5
  145. package/src/nodes.ts +8 -10
  146. package/src/pie-chart/index.ts +2 -2
  147. package/src/pie-chart/pie-chart.ts +225 -303
  148. package/src/pie-chart/pie-legend.ts +125 -115
  149. package/src/pie-chart/pie-ring.ts +388 -443
  150. package/src/pie-chart/shared.ts +14 -8
  151. package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
  152. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
@@ -1,212 +1,163 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Rect, Text, command, easeOut, property, textOps, } from "@motionscript/core";
8
- import { drive, hold, together } from "@motionscript/core/component";
1
+ import { Flow, Paint, Rect, Shapes, Text, Types, component2d, textOps, } from "@motionscript/sdk";
2
+ import { fresh } from "./entries.js";
3
+ import { frameEase } from "./motion.js";
9
4
  import { DEFAULT_LEGEND, SPOTLIGHT_DIM, } from "./shared.js";
5
+ /** A row's entries are a `Rect`'s: paint, the flow of its children, its corners. */
6
+ const row = { ...Paint.state, ...Flow.state, ...Shapes.corners };
7
+ /**
8
+ * One legend entry. It hugs its caption and swatch; `shown` scales that width
9
+ * from nothing to the whole of it.
10
+ *
11
+ * The width is taken from the content on every measure, at any reveal, so a frame
12
+ * never depends on whether the entry was once seen fully shown. A collapse needs a
13
+ * number to scale, and `"hug"` is not one until something measures it — this is
14
+ * the something.
15
+ */
16
+ const LegendEntry = component2d({
17
+ key: "legendEntry",
18
+ state: { ...row, shown: Types.number(1) },
19
+ commands: { ...Paint.commands },
20
+ measure: (measurer, state, children) => {
21
+ const size = Flow.measure(measurer, state, children, Paint.inset(state));
22
+ return state.shown >= 1 ? size : { ...size, width: state.shown * size.width };
23
+ },
24
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
25
+ render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
26
+ });
27
+ /**
28
+ * How far each entry is shown, written whole (a document, a `set`) or one
29
+ * entry at a time (a command, as `{ [index]: reveal }`), which leaves the others
30
+ * as the frame left them — so two series moving at once each move their own.
31
+ */
32
+ function revealOf(value, previous) {
33
+ if (Array.isArray(value))
34
+ return value;
35
+ const next = [...(previous ?? [])];
36
+ for (const [index, reveal] of Object.entries(value))
37
+ next[Number(index)] = reveal;
38
+ return next;
39
+ }
10
40
  /**
11
41
  * The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
12
42
  * left-to-right with the theme's `itemGap`. Each entry pairs the series label
13
43
  * with a rounded colour swatch; only the swatch carries the series colour, the
14
44
  * caption reads in the legend's neutral ink.
15
45
  *
16
- * {@link showSeries}/{@link hideSeries} flip a series on or off — showing one
17
- * adds its entry back into the row at its stable series position and grows it
18
- * in, hiding one shrinks it away and removes it. So the row only ever holds the
19
- * currently-enabled series, in series order, and closes the gap when one leaves.
46
+ * `showSeries`/`hideSeries` flip a series on or off — showing one grows its
47
+ * entry back in at its stable series position, hiding one shrinks it away. So
48
+ * the row only ever shows the currently-enabled series, in series order, and
49
+ * closes the gap when one leaves.
20
50
  *
21
51
  * This node *is* the row, so the parent places it (centred below the chart) and
22
52
  * it hugs its entries.
23
53
  */
24
- export class ChartLegend extends Rect {
25
- /** One entry per series. **Every** entry is a child — see {@link reveal}. */
26
- items = [];
27
- /**
28
- * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
29
- * together, so `0` is an entry that takes no room and `1` is one at its
30
- * natural size.
31
- *
32
- * This replaces adding and removing the entry from the row, which is what
33
- * `showSeries`/`hideSeries` used to do. That could not be a command: a command
34
- * is asked what it looks like at a time, and "is this node a child" is not a
35
- * value a time can produce — the tree either contains it or it doesn't, and
36
- * getting there means having run the add. Collapsed-but-present is the same
37
- * picture reached by a route that *is* a function of `t`.
38
- *
39
- * A plain array rather than reactive props because the count is the series
40
- * count, which is data. The entries' props are bound to it, so writing one
41
- * still moves the layout.
42
- */
43
- reveal = [];
44
- /**
45
- * Each entry's natural width, last time it was fully shown.
46
- *
47
- * A collapse needs numeric endpoints — `lerpSizeInput` snaps between a token
48
- * and a number rather than interpolating — and `"hug"` is not a number until
49
- * something measures it. Refreshed on every frame an entry is at full reveal
50
- * (see {@link widthFor}), so it is current by the time a hide starts, and it
51
- * tracks a relabelled series or a restyled legend without being told.
52
- */
53
- natural = [];
54
- constructor(props) {
55
- // `flow` after the spread, with the rest of the geometry: this class *is*
56
- // the row, so the direction is its own answer and not the caller's. It has
57
- // to be stated — a `Rect` given no flow lays its children out `freeform`,
58
- // which stacks every entry on the same spot. One series looks perfect that
59
- // way and three look like one smeared caption, so the failure only shows up
60
- // on the charts that most need a legend.
61
- super({
62
- ...props,
54
+ export const ChartLegend = component2d({
55
+ key: "chartLegend",
56
+ state: {
57
+ ...row,
58
+ series: fresh(() => []),
59
+ swatches: fresh(() => []),
60
+ legend: Types.custom(DEFAULT_LEGEND),
61
+ /**
62
+ * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
63
+ * together, so `0` is an entry that takes no room and `1` is one at its
64
+ * natural size.
65
+ *
66
+ * This replaces adding and removing the entry from the row: a command is
67
+ * asked what it looks like at a time, and "is this node a child" is not a
68
+ * value a time can produce. Collapsed-but-present is the same picture reached
69
+ * by a route that *is* a function of `t`.
70
+ */
71
+ reveal: fresh(() => [], { resolve: revealOf }),
72
+ },
73
+ // This node *is* the row, so the direction is its own answer. It has to be
74
+ // stated — a `Rect` given no flow lays its children out `freeform`, which
75
+ // stacks every entry on the same spot. The gap and padding are the theme's.
76
+ defaults: {
77
+ flow: "horizontal",
78
+ width: "hug",
79
+ height: "hug",
80
+ gap: (state) => state.legend.itemGap,
81
+ padding: (state) => state.legend.padding,
82
+ reveal: (state) => state.series.map((s) => ((s.enabled ?? true) ? 1 : 0)),
83
+ },
84
+ // One entry per series, in series order, every one a child for good: order is
85
+ // fixed rather than depending on which siblings happen to be shown, so an entry
86
+ // always comes back where it belongs.
87
+ children: (state) => {
88
+ const marker = state.legend.markerStyle;
89
+ return state.series.map((series, index) => LegendEntry({
63
90
  flow: "horizontal",
91
+ gap: 12,
64
92
  align: "center",
65
93
  width: "hug",
66
94
  height: "hug",
67
- });
68
- // Structure is one entry per series, so it's composed here from the resolved
69
- // props super() applied. Fixed row geometry last, so it wins over super().
70
- this.set({ gap: this.legend.itemGap, padding: this.legend.padding });
71
- this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0));
72
- this.natural = this.series.map(() => 0);
73
- this.items = this.series.map((s, i) => this.buildItem(s, i));
74
- // All of them, in series order. Order is now fixed rather than depending on
75
- // which siblings happen to be shown, so an entry always comes back where it
76
- // belongs and `insertionIndex` has nothing left to compute.
77
- for (const item of this.items)
78
- this.add(item);
79
- }
80
- /**
81
- * An entry's width for its current reveal.
82
- *
83
- * `"hug"` at full reveal rather than the pinned number, so a shown entry stays
84
- * responsive to its own content; the number only takes over while it is
85
- * collapsing, which is the only time a token cannot express it.
86
- *
87
- * Records the natural width as a side effect, which is the honest place for it:
88
- * this runs inside a binding, so it is already reading the layout every frame,
89
- * and the value it wants is the one the layout just produced. It writes a plain
90
- * array rather than a signal, so nothing is invalidated by it.
91
- */
92
- widthFor(index) {
93
- const shown = this.reveal[index] ?? 0;
94
- if (shown >= 1) {
95
- const measured = this.items[index]?.measuredWidth ?? 0;
96
- if (measured > 0)
97
- this.natural[index] = measured;
98
- return "hug";
99
- }
100
- return shown * (this.natural[index] ?? 0);
101
- }
102
- /** One entry: the series caption beside its colour swatch. */
103
- buildItem(series, index) {
104
- const marker = this.legend.markerStyle;
105
- const item = new Rect({ flow: "horizontal",
106
- gap: 12,
107
- align: "center",
108
95
  // Bound to the reveal, so showing and hiding is a number moving rather
109
- // than a child arriving and leaving.
110
- width: () => this.widthFor(index),
111
- opacity: () => this.reveal[index] ?? 0,
112
- height: "hug",
96
+ // than a child arriving and leaving. The width follows it in `measure`,
97
+ // and the flanking gap closes with the entry rather than snapping.
98
+ opacity: () => state.reveal[index] ?? 0,
99
+ gapScale: () => state.reveal[index] ?? 0,
100
+ shown: () => state.reveal[index] ?? 0,
113
101
  children: [
114
- new Text({
115
- ...textOps.styleProps(this.legend.textStyle),
116
- text: series.label,
117
- }),
118
- new Rect({
102
+ Text({ ...textOps.styleProps(state.legend.textStyle), text: series.label }),
103
+ Rect({
119
104
  width: marker.width,
120
105
  height: marker.height,
121
106
  cornerRadius: marker.borderRadius,
122
- fill: this.swatches[index] ?? "white",
107
+ fill: state.swatches[index] ?? "white",
123
108
  stroke: marker.stroke,
124
109
  shadow: marker.shadow,
125
110
  }),
126
111
  ],
127
- });
128
- // `gapScale` is a `Node` prop rather than a container one, so it is bound here
129
- // instead of in the config. It tracks the reveal so the flanking gap closes
130
- // with the entry rather than snapping when it reaches zero.
131
- item.set({ gapScale: () => this.reveal[index] ?? 0 });
132
- return item;
133
- }
134
- /** True if series `index` is showing at all — see {@link reveal}. */
135
- isEnabled(index) {
136
- return (this.reveal[index] ?? 0) > 0;
137
- }
138
- /**
139
- * Grow series `index`'s entry back in at its series-order position, the
140
- * siblings sliding over to make room.
141
- *
142
- * A reveal tween rather than an animated `addChildAt`. The entry never left —
143
- * see {@link reveal} — so there is no add to have happened, and the whole
144
- * thing is a function of `t`.
145
- */
146
- showSeries(args) {
147
- const { index = 0 } = args.data ?? {};
148
- return this.revealTo(index, 1, args.duration ?? 0.35, args.easing ?? easeOut());
149
- }
150
- /**
151
- * Shrink series `index`'s entry away, the gap closing behind it — the mirror
152
- * of {@link showSeries}.
153
- */
154
- hideSeries(args) {
155
- const { index = 0 } = args.data ?? {};
156
- return this.revealTo(index, 0, args.duration ?? 0.35, args.easing ?? easeOut());
157
- }
158
- /**
159
- * Ramp one entry's reveal to `target`.
160
- *
161
- * `from` is read when the command is built, which for a driven scene is with
162
- * the node in the state its own start time implies — so a hide that follows a
163
- * show starts where the show left it rather than at whatever the node happens
164
- * to hold now.
165
- */
166
- revealTo(index, target, duration, easing) {
167
- if (this.items[index] === undefined)
168
- return hold(duration);
169
- const from = this.reveal[index] ?? 0;
170
- return drive(duration, (t) => {
171
- this.reveal[index] = from + (target - from) * easing(t);
172
- });
173
- }
174
- /**
175
- * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
176
- * one back to full — the legend half of a chart's `spotlightSeries`. Entries
177
- * stay in place; only their opacity moves, so the row doesn't reflow.
178
- *
179
- * Only the currently-shown entries are touched — a hidden series' entry is
180
- * left as {@link hideSeries} left it.
181
- */
182
- spotlightSeries(args) {
183
- const { index = 0 } = args.data ?? {};
184
- const duration = args.duration ?? 0.35;
185
- const easing = args.easing ?? easeOut();
186
- // Opacity only, on entries that are already in the row — no membership
187
- // changes, so unlike {@link showSeries} this is a plain function of `t`.
188
- return together(...this.items
189
- .map((item, i) => ({ item, i }))
190
- .filter(({ i }) => this.isEnabled(i))
191
- .map(({ item, i }) => item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })));
192
- }
112
+ }));
113
+ },
114
+ commands: {
115
+ ...Paint.commands,
116
+ /**
117
+ * Grow series `index`'s entry back in at its series-order position, the
118
+ * siblings sliding over to make room. A reveal tween rather than an animated
119
+ * `addChildAt`: the entry never left, so the whole thing is a function of `t`.
120
+ */
121
+ showSeries: {
122
+ args: { index: Types.number(0, { min: 0, step: 1 }) },
123
+ // An index that is not a series takes its slot and moves nothing.
124
+ run: (timeline, state) => (timeline.args.index in state.series
125
+ ? timeline.animate(revealFrame(state, timeline.args.index, 1, frameEase(timeline)))
126
+ : timeline.wait(timeline.duration)),
127
+ },
128
+ /** Shrink series `index`'s entry away, the gap closing behind it — the mirror of `showSeries`. */
129
+ hideSeries: {
130
+ args: { index: Types.number(0, { min: 0, step: 1 }) },
131
+ run: (timeline, state) => (timeline.args.index in state.series
132
+ ? timeline.animate(revealFrame(state, timeline.args.index, 0, frameEase(timeline)))
133
+ : timeline.wait(timeline.duration)),
134
+ },
135
+ /**
136
+ * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
137
+ * one back to full — the legend half of a chart's `spotlightSeries`. Entries
138
+ * stay in place; only their opacity moves, so the row doesn't reflow. Only
139
+ * the entries shown when it is built are touched: a hidden series' entry is
140
+ * left as `hideSeries` left it.
141
+ */
142
+ spotlightSeries: {
143
+ args: { index: Types.number(0, { min: 0, step: 1 }) },
144
+ run: (timeline, state, children) => timeline.together(children.flatMap((entry, i) => (state.reveal[i] ?? 0) > 0 ? [entry.to({ opacity: i === timeline.args.index ? 1 : SPOTLIGHT_DIM })] : [])),
145
+ },
146
+ },
147
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
148
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
149
+ render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
150
+ });
151
+ /**
152
+ * One entry's reveal ramping to `target` from where the command finds it — so a
153
+ * hide that follows a show starts where the show left it.
154
+ */
155
+ function revealFrame(state, index, target, ease) {
156
+ const from = state.reveal[index] ?? 0;
157
+ return (t) => ({ reveal: { [index]: from + (target - from) * ease(t) } });
158
+ }
159
+ /** Whether series `index` is showing at all on `legend`. */
160
+ export function legendShows(legend, index) {
161
+ return (legend.reveal[index] ?? 0) > 0;
193
162
  }
194
- __decorate([
195
- property({ default: () => [] })
196
- ], ChartLegend.prototype, "series", void 0);
197
- __decorate([
198
- property({ default: () => [] })
199
- ], ChartLegend.prototype, "swatches", void 0);
200
- __decorate([
201
- property({ default: DEFAULT_LEGEND })
202
- ], ChartLegend.prototype, "legend", void 0);
203
- __decorate([
204
- command()
205
- ], ChartLegend.prototype, "showSeries", null);
206
- __decorate([
207
- command()
208
- ], ChartLegend.prototype, "hideSeries", null);
209
- __decorate([
210
- command()
211
- ], ChartLegend.prototype, "spotlightSeries", null);
212
163
  //# sourceMappingURL=chart-legend.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-legend.js","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,OAAO,GAMR,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAA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CAAC,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAClF,CACJ,CAAA;IACH,CAAC;CACF;AAhM2D;IAAzD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAmB,EAAE,CAAC;2CAA8B;AAC5B;IAAlD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAY,EAAE,CAAC;6CAAyB;AACpB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;2CAA6B;AAkInE;IADC,OAAO,EAAE;6CAIT;AAOD;IADC,OAAO,EAAE;6CAIT;AAgCD;IADC,OAAO,EAAE;kDAeT","sourcesContent":["import {\n Rect,\n Text,\n command,\n easeOut,\n property,\n textOps,\n type CommandArgs,\n type EasingFunction,\n type Fill,\n type NodeConfig,\n type RectProps,\n} from \"@motionscript/core\"\n\nimport { drive, hold, together, type Seekable } from \"@motionscript/core/component\"\n\nimport {\n DEFAULT_LEGEND,\n SPOTLIGHT_DIM,\n type ChartSeries,\n type LegendConfig,\n} from \"./shared\"\n\nexport interface ChartLegendProps extends RectProps {\n /**\n * One entry per series: legend `label`, its `enabled` default, and — through\n * {@link ChartLegendProps.swatches} — the colour its chip is painted. A series\n * that starts enabled (the default) is added to the row up front; one that\n * starts `false` is hidden until a later {@link ChartLegend.showSeries}.\n */\n series: ChartSeries[]\n /**\n * The swatch colour for each series, by index — resolved by the chart, whose\n * business it is whether a series' colour comes out of a stroke palette (a\n * line) or a fill palette (a bar). Shorter than the series list means the\n * missing entries fall back to white.\n */\n swatches: Fill[]\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\n legend: LegendConfig\n}\n\n/**\n * The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out\n * left-to-right with the theme's `itemGap`. Each entry pairs the series label\n * with a rounded colour swatch; only the swatch carries the series colour, the\n * caption reads in the legend's neutral ink.\n *\n * {@link showSeries}/{@link hideSeries} flip a series on or off — showing one\n * adds its entry back into the row at its stable series position and grows it\n * in, hiding one shrinks it away and removes it. So the row only ever holds the\n * currently-enabled series, in series order, and closes the gap when one leaves.\n *\n * This node *is* the row, so the parent places it (centred below the chart) and\n * it hugs its entries.\n */\nexport class ChartLegend extends Rect {\n @property({ default: () => [] as ChartSeries[] }) declare series: ChartSeries[]\n @property({ default: () => [] as Fill[] }) declare swatches: Fill[]\n @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig\n\n /** One entry per series. **Every** entry is a child — see {@link reveal}. */\n private items: Rect[] = []\n /**\n * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap\n * together, so `0` is an entry that takes no room and `1` is one at its\n * natural size.\n *\n * This replaces adding and removing the entry from the row, which is what\n * `showSeries`/`hideSeries` used to do. That could not be a command: a command\n * is asked what it looks like at a time, and \"is this node a child\" is not a\n * value a time can produce — the tree either contains it or it doesn't, and\n * getting there means having run the add. Collapsed-but-present is the same\n * picture reached by a route that *is* a function of `t`.\n *\n * A plain array rather than reactive props because the count is the series\n * count, which is data. The entries' props are bound to it, so writing one\n * still moves the layout.\n */\n private reveal: number[] = []\n /**\n * Each entry's natural width, last time it was fully shown.\n *\n * A collapse needs numeric endpoints — `lerpSizeInput` snaps between a token\n * and a number rather than interpolating — and `\"hug\"` is not a number until\n * something measures it. Refreshed on every frame an entry is at full reveal\n * (see {@link widthFor}), so it is current by the time a hide starts, and it\n * tracks a relabelled series or a restyled legend without being told.\n */\n private natural: number[] = []\n\n constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>) {\n // `flow` after the spread, with the rest of the geometry: this class *is*\n // the row, so the direction is its own answer and not the caller's. It has\n // to be stated — a `Rect` given no flow lays its children out `freeform`,\n // which stacks every entry on the same spot. One series looks perfect that\n // way and three look like one smeared caption, so the failure only shows up\n // on the charts that most need a legend.\n super({\n ...(props as RectProps),\n flow: \"horizontal\",\n align: \"center\",\n width: \"hug\",\n height: \"hug\",\n })\n\n // Structure is one entry per series, so it's composed here from the resolved\n // props super() applied. Fixed row geometry last, so it wins over super().\n this.set({ gap: this.legend.itemGap, padding: this.legend.padding })\n\n this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0))\n this.natural = this.series.map(() => 0)\n this.items = this.series.map((s, i) => this.buildItem(s, i))\n\n // All of them, in series order. Order is now fixed rather than depending on\n // which siblings happen to be shown, so an entry always comes back where it\n // belongs and `insertionIndex` has nothing left to compute.\n for (const item of this.items) this.add(item)\n }\n\n /**\n * An entry's width for its current reveal.\n *\n * `\"hug\"` at full reveal rather than the pinned number, so a shown entry stays\n * responsive to its own content; the number only takes over while it is\n * collapsing, which is the only time a token cannot express it.\n *\n * Records the natural width as a side effect, which is the honest place for it:\n * this runs inside a binding, so it is already reading the layout every frame,\n * and the value it wants is the one the layout just produced. It writes a plain\n * array rather than a signal, so nothing is invalidated by it.\n */\n private widthFor(index: number): number | \"hug\" {\n const shown = this.reveal[index] ?? 0\n if (shown >= 1) {\n const measured = this.items[index]?.measuredWidth ?? 0\n if (measured > 0) this.natural[index] = measured\n return \"hug\"\n }\n return shown * (this.natural[index] ?? 0)\n }\n\n /** One entry: the series caption beside its colour swatch. */\n private buildItem(series: ChartSeries, index: number): Rect {\n const marker = this.legend.markerStyle\n const item = new Rect({ flow: \"horizontal\",\n gap: 12,\n align: \"center\",\n // Bound to the reveal, so showing and hiding is a number moving rather\n // than a child arriving and leaving.\n width: () => this.widthFor(index),\n opacity: () => this.reveal[index] ?? 0,\n height: \"hug\",\n children: [\n new Text({\n ...textOps.styleProps(this.legend.textStyle),\n text: series.label,\n }),\n new Rect({\n width: marker.width,\n height: marker.height,\n cornerRadius: marker.borderRadius,\n fill: this.swatches[index] ?? \"white\",\n stroke: marker.stroke,\n shadow: marker.shadow,\n }),\n ],\n })\n // `gapScale` is a `Node` prop rather than a container one, so it is bound here\n // instead of in the config. It tracks the reveal so the flanking gap closes\n // with the entry rather than snapping when it reaches zero.\n item.set({ gapScale: () => this.reveal[index] ?? 0 })\n return item\n }\n\n /** True if series `index` is showing at all — see {@link reveal}. */\n isEnabled(index: number): boolean {\n return (this.reveal[index] ?? 0) > 0\n }\n\n /**\n * Grow series `index`'s entry back in at its series-order position, the\n * siblings sliding over to make room.\n *\n * A reveal tween rather than an animated `addChildAt`. The entry never left —\n * see {@link reveal} — so there is no add to have happened, and the whole\n * thing is a function of `t`.\n */\n @command()\n showSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n return this.revealTo(index, 1, args.duration ?? 0.35, args.easing ?? easeOut())\n }\n\n /**\n * Shrink series `index`'s entry away, the gap closing behind it — the mirror\n * of {@link showSeries}.\n */\n @command()\n hideSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n return this.revealTo(index, 0, args.duration ?? 0.35, args.easing ?? easeOut())\n }\n\n /**\n * Ramp one entry's reveal to `target`.\n *\n * `from` is read when the command is built, which for a driven scene is with\n * the node in the state its own start time implies — so a hide that follows a\n * show starts where the show left it rather than at whatever the node happens\n * to hold now.\n */\n private revealTo(\n index: number,\n target: number,\n duration: number,\n easing: EasingFunction\n ): Seekable {\n if (this.items[index] === undefined) return hold(duration)\n const from = this.reveal[index] ?? 0\n return drive(duration, (t) => {\n this.reveal[index] = from + (target - from) * easing(t)\n })\n }\n\n /**\n * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that\n * one back to full — the legend half of a chart's `spotlightSeries`. Entries\n * stay in place; only their opacity moves, so the row doesn't reflow.\n *\n * Only the currently-shown entries are touched — a hidden series' entry is\n * left as {@link hideSeries} left it.\n */\n @command()\n spotlightSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n const duration = args.duration ?? 0.35\n const easing = args.easing ?? easeOut()\n // Opacity only, on entries that are already in the row — no membership\n // changes, so unlike {@link showSeries} this is a plain function of `t`.\n return together(\n ...this.items\n .map((item, i) => ({ item, i }))\n .filter(({ i }) => this.isEnabled(i))\n .map(({ item, i }) =>\n item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })\n )\n )\n }\n}\n"]}
1
+ {"version":3,"file":"chart-legend.js","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,OAAO,GAqBR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EACL,cAAc,EACd,aAAa,GAGd,MAAM,UAAU,CAAA;AAqBjB,oFAAoF;AACpF,MAAM,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;AAEhE;;;;;;;;GAQG;AACH,MAAM,WAAW,GAAG,WAAW,CAAC;IAC9B,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;IACzC,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE;IAC/B,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;QACxE,OAAO,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA;IAC/E,CAAC;IACD,MAAM,EAAE,CAAC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AC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvF,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CAC7E,CAAC,CAAA;AAEF;;;GAGG;AACH,SAAS,WAAW,CAAC,KAA6C,EAAE,KAAa,EAAE,MAAc,EAAE,IAA2B;IAC5H,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACrC,OAAO,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACnF,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,WAAW,CAAC,MAA8C,EAAE,KAAa;IACvF,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;AACxC,CAAC","sourcesContent":["import {\n Flow,\n Paint,\n Rect,\n Shapes,\n Text,\n Types,\n component2d,\n textOps,\n type Fill,\n type NodeOf,\n type RectProps,\n // Named so the row's emitted type reaches the Rect surface it spreads through the sdk, not core.\n type Alignment as _Alignment,\n type CornerRadiusResolved as _CornerRadiusResolved,\n type CornerStyleResolved as _CornerStyleResolved,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type RectCornerRadius as _RectCornerRadius,\n type RectCornerStyle as _RectCornerStyle,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"./entries\"\nimport { frameEase } from \"./motion\"\nimport {\n DEFAULT_LEGEND,\n SPOTLIGHT_DIM,\n type ChartSeries,\n type LegendConfig,\n} from \"./shared\"\n\nexport interface ChartLegendProps extends RectProps {\n /**\n * One entry per series: legend `label`, its `enabled` default, and — through\n * {@link ChartLegendProps.swatches} — the colour its chip is painted. A series\n * that starts enabled (the default) is added to the row up front; one that\n * starts `false` is hidden until a later `showSeries`.\n */\n series: ChartSeries[]\n /**\n * The swatch colour for each series, by index — resolved by the chart, whose\n * business it is whether a series' colour comes out of a stroke palette (a\n * line) or a fill palette (a bar). Shorter than the series list means the\n * missing entries fall back to white.\n */\n swatches: Fill[]\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\n legend: LegendConfig\n}\n\n/** A row's entries are a `Rect`'s: paint, the flow of its children, its corners. */\nconst row = { ...Paint.state, ...Flow.state, ...Shapes.corners }\n\n/**\n * One legend entry. It hugs its caption and swatch; `shown` scales that width\n * from nothing to the whole of it.\n *\n * The width is taken from the content on every measure, at any reveal, so a frame\n * never depends on whether the entry was once seen fully shown. A collapse needs a\n * number to scale, and `\"hug\"` is not one until something measures it — this is\n * the something.\n */\nconst LegendEntry = component2d({\n key: \"legendEntry\",\n state: { ...row, shown: Types.number(1) },\n commands: { ...Paint.commands },\n measure: (measurer, state, children) => {\n const size = Flow.measure(measurer, state, children, Paint.inset(state))\n return state.shown >= 1 ? size : { ...size, width: state.shown * size.width }\n },\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),\n})\n\n/**\n * How far each entry is shown, written whole (a document, a `set`) or one\n * entry at a time (a command, as `{ [index]: reveal }`), which leaves the others\n * as the frame left them — so two series moving at once each move their own.\n */\nfunction revealOf(value: readonly number[] | Readonly<Record<number, number>>, previous?: number[]): number[] {\n if (Array.isArray(value)) return value as number[]\n const next = [...(previous ?? [])]\n for (const [index, reveal] of Object.entries(value)) next[Number(index)] = reveal\n return next\n}\n\n/**\n * The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out\n * left-to-right with the theme's `itemGap`. Each entry pairs the series label\n * with a rounded colour swatch; only the swatch carries the series colour, the\n * caption reads in the legend's neutral ink.\n *\n * `showSeries`/`hideSeries` flip a series on or off — showing one grows its\n * entry back in at its stable series position, hiding one shrinks it away. So\n * the row only ever shows the currently-enabled series, in series order, and\n * closes the gap when one leaves.\n *\n * This node *is* the row, so the parent places it (centred below the chart) and\n * it hugs its entries.\n */\nexport const ChartLegend = component2d({\n key: \"chartLegend\",\n state: {\n ...row,\n series: fresh<ChartSeries[]>(() => []),\n swatches: fresh<Fill[]>(() => []),\n legend: Types.custom<LegendConfig>(DEFAULT_LEGEND),\n /**\n * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap\n * together, so `0` is an entry that takes no room and `1` is one at its\n * natural size.\n *\n * This replaces adding and removing the entry from the row: a command is\n * asked what it looks like at a time, and \"is this node a child\" is not a\n * value a time can produce. Collapsed-but-present is the same picture reached\n * by a route that *is* a function of `t`.\n */\n reveal: fresh<number[], number[] | Readonly<Record<number, number>>>(() => [], { resolve: revealOf }),\n },\n // This node *is* the row, so the direction is its own answer. It has to be\n // stated — a `Rect` given no flow lays its children out `freeform`, which\n // stacks every entry on the same spot. The gap and padding are the theme's.\n defaults: {\n flow: \"horizontal\",\n width: \"hug\",\n height: \"hug\",\n gap: (state) => state.legend.itemGap,\n padding: (state) => state.legend.padding,\n reveal: (state) => state.series.map((s) => ((s.enabled ?? true) ? 1 : 0)),\n },\n // One entry per series, in series order, every one a child for good: order is\n // fixed rather than depending on which siblings happen to be shown, so an entry\n // always comes back where it belongs.\n children: (state) => {\n const marker = state.legend.markerStyle\n return state.series.map((series, index) =>\n LegendEntry({\n flow: \"horizontal\",\n gap: 12,\n align: \"center\",\n width: \"hug\",\n height: \"hug\",\n // Bound to the reveal, so showing and hiding is a number moving rather\n // than a child arriving and leaving. The width follows it in `measure`,\n // and the flanking gap closes with the entry rather than snapping.\n opacity: () => state.reveal[index] ?? 0,\n gapScale: () => state.reveal[index] ?? 0,\n shown: () => state.reveal[index] ?? 0,\n children: [\n Text({ ...textOps.styleProps(state.legend.textStyle), text: series.label }),\n Rect({\n width: marker.width,\n height: marker.height,\n cornerRadius: marker.borderRadius,\n fill: state.swatches[index] ?? \"white\",\n stroke: marker.stroke,\n shadow: marker.shadow,\n }),\n ],\n })\n )\n },\n commands: {\n ...Paint.commands,\n /**\n * Grow series `index`'s entry back in at its series-order position, the\n * siblings sliding over to make room. A reveal tween rather than an animated\n * `addChildAt`: the entry never left, so the whole thing is a function of `t`.\n */\n showSeries: {\n args: { index: Types.number(0, { min: 0, step: 1 }) },\n // An index that is not a series takes its slot and moves nothing.\n run: (timeline, state) => (timeline.args.index in state.series\n ? timeline.animate(revealFrame(state, timeline.args.index, 1, frameEase(timeline)))\n : timeline.wait(timeline.duration)),\n },\n /** Shrink series `index`'s entry away, the gap closing behind it — the mirror of `showSeries`. */\n hideSeries: {\n args: { index: Types.number(0, { min: 0, step: 1 }) },\n run: (timeline, state) => (timeline.args.index in state.series\n ? timeline.animate(revealFrame(state, timeline.args.index, 0, frameEase(timeline)))\n : timeline.wait(timeline.duration)),\n },\n /**\n * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that\n * one back to full — the legend half of a chart's `spotlightSeries`. Entries\n * stay in place; only their opacity moves, so the row doesn't reflow. Only\n * the entries shown when it is built are touched: a hidden series' entry is\n * left as `hideSeries` left it.\n */\n spotlightSeries: {\n args: { index: Types.number(0, { min: 0, step: 1 }) },\n run: (timeline, state, children) =>\n timeline.together(\n children.flatMap((entry, i) =>\n (state.reveal[i] ?? 0) > 0 ? [entry.to({ opacity: i === timeline.args.index ? 1 : SPOTLIGHT_DIM })] : []\n )\n ),\n },\n },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),\n})\n\n/**\n * One entry's reveal ramping to `target` from where the command finds it — so a\n * hide that follows a show starts where the show left it.\n */\nfunction revealFrame(state: { readonly reveal: readonly number[] }, index: number, target: number, ease: (t: number) => number) {\n const from = state.reveal[index] ?? 0\n return (t: number) => ({ reveal: { [index]: from + (target - from) * ease(t) } })\n}\n\n/** Whether series `index` is showing at all on `legend`. */\nexport function legendShows(legend: { readonly reveal: readonly number[] }, index: number): boolean {\n return (legend.reveal[index] ?? 0) > 0\n}\n\nexport type ChartLegend = NodeOf<typeof ChartLegend>\n"]}
@@ -0,0 +1,17 @@
1
+ import { type Element, type Node2D, type Type } from "@motionscript/sdk";
2
+ /**
3
+ * An entry made fresh for every node: each node gets its own array or box
4
+ * rather than one shared literal, and a host is told no default for it.
5
+ */
6
+ export declare function fresh<T, In = T>(make: () => T, options?: {
7
+ readonly resolve?: (value: In) => T;
8
+ readonly kind?: string;
9
+ }): Type<In, T>;
10
+ /**
11
+ * Nodes a `children` builder made with `new`, as the elements it returns. A
12
+ * part built that way can be read in a binding — its own box, or its parent's,
13
+ * which is the component it was built for — where a call would hand back only
14
+ * the element.
15
+ */
16
+ export declare function asParts(nodes: readonly Node2D[]): readonly Element[];
17
+ //# sourceMappingURL=entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../src/kit/entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAE/E;;;GAGG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAGtI;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,OAAO,EAAE,CAEpE"}
@@ -0,0 +1,19 @@
1
+ import { Types } from "@motionscript/sdk";
2
+ /**
3
+ * An entry made fresh for every node: each node gets its own array or box
4
+ * rather than one shared literal, and a host is told no default for it.
5
+ */
6
+ export function fresh(make, options) {
7
+ // A function default is a factory: the component calls it once per node.
8
+ return Types.custom(make, options);
9
+ }
10
+ /**
11
+ * Nodes a `children` builder made with `new`, as the elements it returns. A
12
+ * part built that way can be read in a binding — its own box, or its parent's,
13
+ * which is the component it was built for — where a call would hand back only
14
+ * the element.
15
+ */
16
+ export function asParts(nodes) {
17
+ return nodes;
18
+ }
19
+ //# sourceMappingURL=entries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entries.js","sourceRoot":"","sources":["../../src/kit/entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAwC,MAAM,mBAAmB,CAAA;AAE/E;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAY,IAAa,EAAE,OAAyE;IACvH,yEAAyE;IACzE,OAAO,KAAK,CAAC,MAAM,CAAQ,IAAqB,EAAE,OAAO,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAwB;IAC9C,OAAO,KAAsC,CAAA;AAC/C,CAAC","sourcesContent":["import { Types, type Element, type Node2D, type Type } from \"@motionscript/sdk\"\n\n/**\n * An entry made fresh for every node: each node gets its own array or box\n * rather than one shared literal, and a host is told no default for it.\n */\nexport function fresh<T, In = T>(make: () => T, options?: { readonly resolve?: (value: In) => T; readonly kind?: string }): Type<In, T> {\n // A function default is a factory: the component calls it once per node.\n return Types.custom<In, T>(make as unknown as In, options)\n}\n\n/**\n * Nodes a `children` builder made with `new`, as the elements it returns. A\n * part built that way can be read in a binding — its own box, or its parent's,\n * which is the component it was built for — where a call would hand back only\n * the element.\n */\nexport function asParts(nodes: readonly Node2D[]): readonly Element[] {\n return nodes as unknown as readonly Element[]\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import { type EasingFunction, type Piece, type Timeline } from "@motionscript/sdk";
2
+ /** Any component's timeline: these helpers only build pieces, which every timeline builds alike. */
3
+ type AnyTimeline = Timeline<any, any>;
4
+ /**
5
+ * The ease a part's own frames apply to `t`: none when its command was given
6
+ * one, which already eases every frame the command builds, and otherwise the
7
+ * ease-out every chart command defaults to.
8
+ */
9
+ export declare function frameEase(timeline: {
10
+ readonly easing: EasingFunction | undefined;
11
+ }): EasingFunction;
12
+ /** A piece of a command placed at its own time: from `at` seconds, for `duration` seconds. */
13
+ export interface Beat {
14
+ readonly at: number;
15
+ readonly duration: number;
16
+ readonly piece: Piece;
17
+ }
18
+ /**
19
+ * `beats` at their own offsets over the command, each eased on its own and held
20
+ * at its last frame once it is done. A beat ahead of the playhead writes nothing,
21
+ * so whatever stands before it is written by a piece ahead of these. Beats that
22
+ * run past the command are played faster to end with it.
23
+ */
24
+ export declare function beats(timeline: AnyTimeline, parts: readonly Beat[]): Piece;
25
+ /** How far one piece of a staggered entrance has come: its opacity, and how far it still sits off its place. */
26
+ export interface Arrival {
27
+ readonly opacity: number;
28
+ readonly shift: number;
29
+ }
30
+ /** Each piece's arrival, by key. An unlisted piece has landed. */
31
+ export type Arrivals = Readonly<Record<string, Arrival>>;
32
+ export declare const LANDED: Arrival;
33
+ /**
34
+ * A part's private record of its pieces' arrivals. A write merges into it, so
35
+ * beats placed apart each write their own piece and leave the others as the
36
+ * frame left them.
37
+ */
38
+ export declare function arrivalsEntry(): import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
39
+ export declare function arrivalOf(arrivals: Arrivals, key: string | number): Arrival;
40
+ /** Every piece in `keys` armed at `from`: the first frame of their entrance. */
41
+ export declare function armed(keys: readonly (string | number)[], from: Arrival): Arrivals;
42
+ /**
43
+ * A piece arriving from `from` over its beat: a part armed at `from` tweened to
44
+ * `{ opacity: 1, [axis]: 0 }`, eased by `ease`.
45
+ */
46
+ export declare function arrival(timeline: AnyTimeline, key: string | number, from: Arrival, ease: EasingFunction): Piece;
47
+ export {};
48
+ //# sourceMappingURL=motion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/kit/motion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAIlG,oGAAoG;AACpG,KAAK,WAAW,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAErC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAA;CAAE,GAAG,cAAc,CAEnG;AAED,8FAA8F;AAC9F,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,KAAK,CAW1E;AAED,gHAAgH;AAChH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAExD,eAAO,MAAM,MAAM,EAAE,OAAkC,CAAA;AAEvD;;;;GAIG;AACH,wBAAgB,aAAa,kHAE5B;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAE3E;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,QAAQ,CAIjF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,KAAK,CAY/G"}
@@ -0,0 +1,63 @@
1
+ import { Types, easeOut } from "@motionscript/sdk";
2
+ const identity = (t) => t;
3
+ /**
4
+ * The ease a part's own frames apply to `t`: none when its command was given
5
+ * one, which already eases every frame the command builds, and otherwise the
6
+ * ease-out every chart command defaults to.
7
+ */
8
+ export function frameEase(timeline) {
9
+ return timeline.easing ? identity : easeOut();
10
+ }
11
+ /**
12
+ * `beats` at their own offsets over the command, each eased on its own and held
13
+ * at its last frame once it is done. A beat ahead of the playhead writes nothing,
14
+ * so whatever stands before it is written by a piece ahead of these. Beats that
15
+ * run past the command are played faster to end with it.
16
+ */
17
+ export function beats(timeline, parts) {
18
+ const total = timeline.duration;
19
+ const natural = parts.reduce((end, part) => Math.max(end, part.at + part.duration), 0);
20
+ const k = natural > total && natural > 0 ? total / natural : 1;
21
+ return timeline.together(parts.map(({ at, duration, piece }) => {
22
+ const start = at * k;
23
+ const length = duration * k;
24
+ return timeline.sequence([timeline.wait(start), piece, timeline.wait(Math.max(0, total - start - length))]);
25
+ }));
26
+ }
27
+ export const LANDED = { opacity: 1, shift: 0 };
28
+ /**
29
+ * A part's private record of its pieces' arrivals. A write merges into it, so
30
+ * beats placed apart each write their own piece and leave the others as the
31
+ * frame left them.
32
+ */
33
+ export function arrivalsEntry() {
34
+ return Types.custom({}, { private: true, resolve: (next, previous) => ({ ...previous, ...next }) });
35
+ }
36
+ export function arrivalOf(arrivals, key) {
37
+ return arrivals[key] ?? LANDED;
38
+ }
39
+ /** Every piece in `keys` armed at `from`: the first frame of their entrance. */
40
+ export function armed(keys, from) {
41
+ const record = {};
42
+ for (const key of keys)
43
+ record[key] = from;
44
+ return record;
45
+ }
46
+ /**
47
+ * A piece arriving from `from` over its beat: a part armed at `from` tweened to
48
+ * `{ opacity: 1, [axis]: 0 }`, eased by `ease`.
49
+ */
50
+ export function arrival(timeline, key, from, ease) {
51
+ return timeline.animate((t) => {
52
+ const e = ease(t);
53
+ return {
54
+ arrivals: {
55
+ [key]: {
56
+ opacity: from.opacity + (LANDED.opacity - from.opacity) * e,
57
+ shift: from.shift + (LANDED.shift - from.shift) * e,
58
+ },
59
+ },
60
+ };
61
+ });
62
+ }
63
+ //# sourceMappingURL=motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.js","sourceRoot":"","sources":["../../src/kit/motion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAkD,MAAM,mBAAmB,CAAA;AAElG,MAAM,QAAQ,GAAmB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAKzC;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,QAAyD;IACjF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;AAC/C,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAqB,EAAE,KAAsB;IACjE,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAA;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,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B,EAAE,CAAA;IAC1C,KAAK,MAAM,GAAG,IAAI,IAAI;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAC1C,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,QAAqB,EAAE,GAAoB,EAAE,IAAa,EAAE,IAAoB;IACtG,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,OAAO;YACL,QAAQ,EAAE;gBACR,CAAC,GAAG,CAAC,EAAE;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;oBAC3D,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;iBACpD;aACF;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { Types, easeOut, type EasingFunction, type Piece, type Timeline } from \"@motionscript/sdk\"\n\nconst identity: EasingFunction = (t) => t\n\n/** Any component's timeline: these helpers only build pieces, which every timeline builds alike. */\ntype AnyTimeline = Timeline<any, any>\n\n/**\n * The ease a part's own frames apply to `t`: none when its command was given\n * one, which already eases every frame the command builds, and otherwise the\n * ease-out every chart command defaults to.\n */\nexport function frameEase(timeline: { readonly easing: EasingFunction | undefined }): EasingFunction {\n return timeline.easing ? identity : easeOut()\n}\n\n/** A piece of a command placed at its own time: from `at` seconds, for `duration` seconds. */\nexport interface Beat {\n readonly at: number\n readonly duration: number\n readonly piece: Piece\n}\n\n/**\n * `beats` at their own offsets over the command, each eased on its own and held\n * at its last frame once it is done. A beat ahead of the playhead writes nothing,\n * so whatever stands before it is written by a piece ahead of these. Beats that\n * run past the command are played faster to end with it.\n */\nexport function beats(timeline: AnyTimeline, parts: readonly Beat[]): Piece {\n const total = timeline.duration\n const natural = parts.reduce((end, part) => Math.max(end, part.at + part.duration), 0)\n const k = natural > total && natural > 0 ? total / natural : 1\n return timeline.together(\n parts.map(({ at, duration, piece }) => {\n const start = at * k\n const length = duration * k\n return timeline.sequence([timeline.wait(start), piece, timeline.wait(Math.max(0, total - start - length))])\n })\n )\n}\n\n/** How far one piece of a staggered entrance has come: its opacity, and how far it still sits off its place. */\nexport interface Arrival {\n readonly opacity: number\n readonly shift: number\n}\n\n/** Each piece's arrival, by key. An unlisted piece has landed. */\nexport type Arrivals = Readonly<Record<string, Arrival>>\n\nexport const LANDED: Arrival = { opacity: 1, shift: 0 }\n\n/**\n * A part's private record of its pieces' arrivals. A write merges into it, so\n * beats placed apart each write their own piece and leave the others as the\n * frame left them.\n */\nexport function arrivalsEntry() {\n return Types.custom<Arrivals>({}, { private: true, resolve: (next: Arrivals, previous?: Arrivals) => ({ ...previous, ...next }) })\n}\n\nexport function arrivalOf(arrivals: Arrivals, key: string | number): Arrival {\n return arrivals[key] ?? LANDED\n}\n\n/** Every piece in `keys` armed at `from`: the first frame of their entrance. */\nexport function armed(keys: readonly (string | number)[], from: Arrival): Arrivals {\n const record: Record<string, Arrival> = {}\n for (const key of keys) record[key] = from\n return record\n}\n\n/**\n * A piece arriving from `from` over its beat: a part armed at `from` tweened to\n * `{ opacity: 1, [axis]: 0 }`, eased by `ease`.\n */\nexport function arrival(timeline: AnyTimeline, key: string | number, from: Arrival, ease: EasingFunction): Piece {\n return timeline.animate((t) => {\n const e = ease(t)\n return {\n arrivals: {\n [key]: {\n opacity: from.opacity + (LANDED.opacity - from.opacity) * e,\n shift: from.shift + (LANDED.shift - from.shift) * e,\n },\n },\n }\n })\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { FillResolved, Loader, ShadowResolved, StrokeResolved } from "@motionscript/sdk";
2
+ /** Paints a chart part holds in entries of its own, which no paint entry loads for it. */
3
+ export interface PartPaints {
4
+ readonly fills?: readonly (readonly FillResolved[])[];
5
+ readonly strokes?: readonly (readonly StrokeResolved[])[];
6
+ readonly shadows?: readonly (readonly ShadowResolved[])[];
7
+ }
8
+ /** Declare `paints` from a component's `load`. */
9
+ export declare function loadPaints(loader: Loader, paints: PartPaints): void;
10
+ //# sourceMappingURL=paints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paints.d.ts","sourceRoot":"","sources":["../../src/kit/paints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE7F,0FAA0F;AAC1F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,YAAY,EAAE,CAAC,EAAE,CAAA;IACrD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,CAAA;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,CAAA;CAC1D;AAED,kDAAkD;AAClD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAInE"}