@motionscript/charts 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/dist/bar-chart/bar-chart.d.ts +286 -0
- package/dist/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/bar-chart/bar-chart.js +610 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/category-axis.d.ts +77 -0
- package/dist/bar-chart/category-axis.d.ts.map +1 -0
- package/dist/bar-chart/category-axis.js +141 -0
- package/dist/bar-chart/category-axis.js.map +1 -0
- package/dist/bar-chart/chart-bars.d.ts +149 -0
- package/dist/bar-chart/chart-bars.d.ts.map +1 -0
- package/dist/bar-chart/chart-bars.js +236 -0
- package/dist/bar-chart/chart-bars.js.map +1 -0
- package/dist/bar-chart/index.d.ts +16 -0
- package/dist/bar-chart/index.d.ts.map +1 -0
- package/dist/bar-chart/index.js +12 -0
- package/dist/bar-chart/index.js.map +1 -0
- package/dist/bar-chart/shared.d.ts +146 -0
- package/dist/bar-chart/shared.d.ts.map +1 -0
- package/dist/bar-chart/shared.js +182 -0
- package/dist/bar-chart/shared.js.map +1 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +12 -0
- package/dist/engine.d.ts +27 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +27 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/chart-border.d.ts +28 -0
- package/dist/kit/chart-border.d.ts.map +1 -0
- package/dist/kit/chart-border.js +45 -0
- package/dist/kit/chart-border.js.map +1 -0
- package/dist/kit/chart-canvas.d.ts +56 -0
- package/dist/kit/chart-canvas.d.ts.map +1 -0
- package/dist/kit/chart-canvas.js +125 -0
- package/dist/kit/chart-canvas.js.map +1 -0
- package/dist/kit/chart-legend.d.ts +126 -0
- package/dist/kit/chart-legend.d.ts.map +1 -0
- package/dist/kit/chart-legend.js +212 -0
- package/dist/kit/chart-legend.js.map +1 -0
- package/dist/kit/shared.d.ts +251 -0
- package/dist/kit/shared.d.ts.map +1 -0
- package/dist/kit/shared.js +401 -0
- package/dist/kit/shared.js.map +1 -0
- package/dist/kit/vertical-axis.d.ts +99 -0
- package/dist/kit/vertical-axis.d.ts.map +1 -0
- package/dist/kit/vertical-axis.js +176 -0
- package/dist/kit/vertical-axis.js.map +1 -0
- package/dist/line-chart/chart-line.d.ts +91 -0
- package/dist/line-chart/chart-line.d.ts.map +1 -0
- package/dist/line-chart/chart-line.js +156 -0
- package/dist/line-chart/chart-line.js.map +1 -0
- package/dist/line-chart/chart-region.d.ts +47 -0
- package/dist/line-chart/chart-region.d.ts.map +1 -0
- package/dist/line-chart/chart-region.js +101 -0
- package/dist/line-chart/chart-region.js.map +1 -0
- package/dist/line-chart/horizontal-axis.d.ts +85 -0
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
- package/dist/line-chart/horizontal-axis.js +158 -0
- package/dist/line-chart/horizontal-axis.js.map +1 -0
- package/dist/line-chart/index.d.ts +22 -0
- package/dist/line-chart/index.d.ts.map +1 -0
- package/dist/line-chart/index.js +19 -0
- package/dist/line-chart/index.js.map +1 -0
- package/dist/line-chart/line-chart.d.ts +347 -0
- package/dist/line-chart/line-chart.d.ts.map +1 -0
- package/dist/line-chart/line-chart.js +701 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/line-chart/shared.d.ts +171 -0
- package/dist/line-chart/shared.d.ts.map +1 -0
- package/dist/line-chart/shared.js +270 -0
- package/dist/line-chart/shared.js.map +1 -0
- package/dist/line-chart/x-scale.d.ts +84 -0
- package/dist/line-chart/x-scale.d.ts.map +1 -0
- package/dist/line-chart/x-scale.js +302 -0
- package/dist/line-chart/x-scale.js.map +1 -0
- package/dist/nodes.d.ts +20 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +20 -0
- package/dist/nodes.js.map +1 -0
- package/dist/pie-chart/index.d.ts +18 -0
- package/dist/pie-chart/index.d.ts.map +1 -0
- package/dist/pie-chart/index.js +14 -0
- package/dist/pie-chart/index.js.map +1 -0
- package/dist/pie-chart/pie-chart.d.ts +170 -0
- package/dist/pie-chart/pie-chart.d.ts.map +1 -0
- package/dist/pie-chart/pie-chart.js +291 -0
- package/dist/pie-chart/pie-chart.js.map +1 -0
- package/dist/pie-chart/pie-legend.d.ts +60 -0
- package/dist/pie-chart/pie-legend.d.ts.map +1 -0
- package/dist/pie-chart/pie-legend.js +131 -0
- package/dist/pie-chart/pie-legend.js.map +1 -0
- package/dist/pie-chart/pie-ring.d.ts +266 -0
- package/dist/pie-chart/pie-ring.d.ts.map +1 -0
- package/dist/pie-chart/pie-ring.js +708 -0
- package/dist/pie-chart/pie-ring.js.map +1 -0
- package/dist/pie-chart/shared.d.ts +210 -0
- package/dist/pie-chart/shared.d.ts.map +1 -0
- package/dist/pie-chart/shared.js +240 -0
- package/dist/pie-chart/shared.js.map +1 -0
- package/package.json +69 -3
- package/registry.json +23 -0
- package/src/bar-chart/bar-chart.ts +804 -0
- package/src/bar-chart/category-axis.ts +177 -0
- package/src/bar-chart/chart-bars.ts +310 -0
- package/src/bar-chart/index.ts +31 -0
- package/src/bar-chart/shared.ts +354 -0
- package/src/engine.ts +26 -0
- package/src/index.ts +5 -0
- package/src/kit/chart-border.ts +61 -0
- package/src/kit/chart-canvas.ts +157 -0
- package/src/kit/chart-legend.ts +250 -0
- package/src/kit/shared.ts +675 -0
- package/src/kit/vertical-axis.ts +224 -0
- package/src/line-chart/chart-line.ts +208 -0
- package/src/line-chart/chart-region.ts +135 -0
- package/src/line-chart/horizontal-axis.ts +202 -0
- package/src/line-chart/index.ts +39 -0
- package/src/line-chart/line-chart.ts +894 -0
- package/src/line-chart/shared.ts +459 -0
- package/src/line-chart/x-scale.ts +367 -0
- package/src/nodes.ts +20 -0
- package/src/pie-chart/index.ts +37 -0
- package/src/pie-chart/pie-chart.ts +374 -0
- package/src/pie-chart/pie-legend.ts +159 -0
- package/src/pie-chart/pie-ring.ts +903 -0
- package/src/pie-chart/shared.ts +490 -0
- package/README.md +0 -4
|
@@ -0,0 +1,212 @@
|
|
|
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";
|
|
9
|
+
import { DEFAULT_LEGEND, SPOTLIGHT_DIM, } from "./shared.js";
|
|
10
|
+
/**
|
|
11
|
+
* The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
|
|
12
|
+
* left-to-right with the theme's `itemGap`. Each entry pairs the series label
|
|
13
|
+
* with a rounded colour swatch; only the swatch carries the series colour, the
|
|
14
|
+
* caption reads in the legend's neutral ink.
|
|
15
|
+
*
|
|
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.
|
|
20
|
+
*
|
|
21
|
+
* This node *is* the row, so the parent places it (centred below the chart) and
|
|
22
|
+
* it hugs its entries.
|
|
23
|
+
*/
|
|
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,
|
|
63
|
+
flow: "horizontal",
|
|
64
|
+
align: "center",
|
|
65
|
+
width: "hug",
|
|
66
|
+
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
|
+
// 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",
|
|
113
|
+
children: [
|
|
114
|
+
new Text({
|
|
115
|
+
...textOps.styleProps(this.legend.textStyle),
|
|
116
|
+
text: series.label,
|
|
117
|
+
}),
|
|
118
|
+
new Rect({
|
|
119
|
+
width: marker.width,
|
|
120
|
+
height: marker.height,
|
|
121
|
+
cornerRadius: marker.borderRadius,
|
|
122
|
+
fill: this.swatches[index] ?? "white",
|
|
123
|
+
stroke: marker.stroke,
|
|
124
|
+
shadow: marker.shadow,
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
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
|
+
}
|
|
193
|
+
}
|
|
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
|
+
//# sourceMappingURL=chart-legend.js.map
|
|
@@ -0,0 +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,QAAQ,EAAiB,MAAM,8BAA8B,CAAA;AAEnF,OAAO,EACL,cAAc,EACd,aAAa,GAGd,MAAM,UAAU,CAAA;AAqBjB;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,WAAY,SAAQ,IAAI;IAKnC,6EAA6E;IACrE,KAAK,GAAW,EAAE,CAAA;I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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"]}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vocabulary every chart node shares: what a *series* is, how an axis is
|
|
3
|
+
* scaled and formatted, and the theme leaves each chart's own theme is assembled
|
|
4
|
+
* from.
|
|
5
|
+
*
|
|
6
|
+
* This module exists because the three chart types are three ways of drawing the
|
|
7
|
+
* same table. A line chart, a bar chart and a pie chart disagree about almost
|
|
8
|
+
* everything visible — polylines against columns against wedges — and agree
|
|
9
|
+
* about almost everything underneath: a series is a column with a caption and a
|
|
10
|
+
* paint, a marker is a number formatted one way, a legend is a swatch beside a
|
|
11
|
+
* label, and a theme is a tree of paints with one mapper and one tween. Writing
|
|
12
|
+
* that three times would mean three answers to "how does a chart round its axis"
|
|
13
|
+
* within one app.
|
|
14
|
+
*
|
|
15
|
+
* Kept renderer-agnostic (no `Node` imports) so the studio's own inspector
|
|
16
|
+
* mappings can build a partial theme without pulling the node classes in, the
|
|
17
|
+
* same way `line-chart-props.ts` always has.
|
|
18
|
+
*
|
|
19
|
+
* **Two conventions run through every resolver and lerp below**, inherited from
|
|
20
|
+
* the shape system's `resolveStroke`/`resolveShadow`:
|
|
21
|
+
*
|
|
22
|
+
* - A **mapper** merges the author's loose, partial input onto a `previous`
|
|
23
|
+
* resolved value and resolves every leaf, so the tween always has resolved
|
|
24
|
+
* data to interpolate. It is idempotent.
|
|
25
|
+
* - A **tween** interpolates two resolved values leaf by leaf. Categorical
|
|
26
|
+
* fields (`fontFamily`, `textAlign`) and fields that are `undefined` on either
|
|
27
|
+
* side **step at the midpoint**, because there is no meaningful in-between and
|
|
28
|
+
* defaulting the missing side to 0 would animate a font weight down to nothing
|
|
29
|
+
* on the way to "unset".
|
|
30
|
+
*/
|
|
31
|
+
import { type DataRecord, type Fill, type Insets, type Shadow, type Stroke, type TextStyle } from "@motionscript/core";
|
|
32
|
+
/**
|
|
33
|
+
* One series of a chart: a column of the table, captioned and painted.
|
|
34
|
+
*
|
|
35
|
+
* `field` names the column carrying this series' values. What that becomes is
|
|
36
|
+
* the chart's business — a traced polyline, a column of bars, a wedge — but the
|
|
37
|
+
* three questions asked of it are the same everywhere: which column, what to
|
|
38
|
+
* call it, what to paint it, and whether it is currently drawn.
|
|
39
|
+
*
|
|
40
|
+
* `fill` is an **override**: omit it and the series takes the theme palette's
|
|
41
|
+
* entry for its own index, which is what makes a chart nobody has themed come
|
|
42
|
+
* out in five distinct colours rather than five identical ones.
|
|
43
|
+
*/
|
|
44
|
+
export interface ChartSeries {
|
|
45
|
+
/** Key into each data row for this series' value. */
|
|
46
|
+
field: string;
|
|
47
|
+
/** Legend caption for this series. */
|
|
48
|
+
label: string;
|
|
49
|
+
/**
|
|
50
|
+
* Paint override for this series' mark and its legend swatch. Omit to take
|
|
51
|
+
* the theme palette's entry for this series' index.
|
|
52
|
+
*/
|
|
53
|
+
fill?: Fill;
|
|
54
|
+
/** Whether the series shows by default. Defaults to `true`. */
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** A `[min, max]` numeric range in data units. */
|
|
58
|
+
export type Range = [min: number, max: number];
|
|
59
|
+
/**
|
|
60
|
+
* One axis's *data* domain — what it shows — as opposed to {@link AxisConfig},
|
|
61
|
+
* which is how it's *styled*. Every field is optional: `range`/`ticks` derive
|
|
62
|
+
* from the plotted data when omitted, and `label` defaults to `""`.
|
|
63
|
+
*/
|
|
64
|
+
export interface AxisDomainConfig {
|
|
65
|
+
/** Caption drawn alongside the axis. Pass `""` (the default) to hide it. */
|
|
66
|
+
label?: string;
|
|
67
|
+
/** `[min, max]` of the scale. Derived from the data bounds when omitted. */
|
|
68
|
+
range?: Range;
|
|
69
|
+
/** Tick values (in data units). Derived (five evenly-spaced) when omitted. */
|
|
70
|
+
ticks?: number[];
|
|
71
|
+
/**
|
|
72
|
+
* How a tick value is written down — a `number-format` pattern such as
|
|
73
|
+
* `#,##0.00` or `$#,##0`.
|
|
74
|
+
*
|
|
75
|
+
* Here rather than in {@link AxisConfig} because it is a statement about the
|
|
76
|
+
* *numbers*, not about the ink they are set in: `$` on a revenue axis says
|
|
77
|
+
* what the column holds, and it has to survive a re-theme. It sits beside
|
|
78
|
+
* `range` and `ticks` for the same reason those do.
|
|
79
|
+
*/
|
|
80
|
+
format?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* An axis domain's @property mapper: merges the author's partial input onto
|
|
84
|
+
* `previous`, so a later partial `.set({ yAxis: {...} })` patches
|
|
85
|
+
* `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`
|
|
86
|
+
* after the merge is the auto-derive signal the scale getters read.
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveAxisDomain(domain: AxisDomainConfig | undefined, previous?: AxisDomainConfig): AxisDomainConfig;
|
|
89
|
+
/**
|
|
90
|
+
* An axis domain's @property tween: interpolates `range`/`ticks` numerically
|
|
91
|
+
* (pairwise by index for `ticks`), so a `to` command that restates a range
|
|
92
|
+
* rescales the plot smoothly. `label`, and either field when one side is in
|
|
93
|
+
* auto-derive mode, step at the midpoint.
|
|
94
|
+
*/
|
|
95
|
+
export declare function lerpAxisDomain(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig;
|
|
96
|
+
/**
|
|
97
|
+
* The low-level colour tokens the default themes are built from — a dark plot
|
|
98
|
+
* panel with warm-grey axis furniture.
|
|
99
|
+
*/
|
|
100
|
+
export declare const CHART_PALETTE: {
|
|
101
|
+
/** Fill of the plot panel behind the marks. */
|
|
102
|
+
readonly plotFill: "#15130e";
|
|
103
|
+
/** Colour of the plot's thick border. */
|
|
104
|
+
readonly borderColor: "#4a4036";
|
|
105
|
+
/** Colour of the faint grid lines spanning the plot. */
|
|
106
|
+
readonly gridColor: "#2c2820";
|
|
107
|
+
/** Colour of the numeric axis markers, axis captions, and legend labels. */
|
|
108
|
+
readonly markerColor: "#8a7f70";
|
|
109
|
+
/** Colour of a spotlit region's dashed rules and its wash. */
|
|
110
|
+
readonly regionColor: "#d99a3a";
|
|
111
|
+
};
|
|
112
|
+
/** The out-of-the-box series palette, cycled by series index. */
|
|
113
|
+
export declare const DEFAULT_SERIES_COLORS: readonly ["#d9603b", "#8194ad", "#e0a93b", "#5e9d6b", "#9ec85a"];
|
|
114
|
+
/**
|
|
115
|
+
* Opacity an *un*-spotlighted series fades to — its mark and its legend entry
|
|
116
|
+
* alike, so the two dim together.
|
|
117
|
+
*/
|
|
118
|
+
export declare const SPOTLIGHT_DIM = 0.2;
|
|
119
|
+
/** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */
|
|
120
|
+
export declare function clampUnit(value: number): number;
|
|
121
|
+
/**
|
|
122
|
+
* Read a numeric field off a row, defaulting missing/non-numeric values to 0.
|
|
123
|
+
*
|
|
124
|
+
* A column left as strings silently plots as 0, which is why the CSV parser's
|
|
125
|
+
* numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
|
|
126
|
+
* until it's coerced.
|
|
127
|
+
*/
|
|
128
|
+
export declare function num(row: DataRecord, field: string | undefined): number;
|
|
129
|
+
/**
|
|
130
|
+
* Read a field off a row as its caption — the counterpart to {@link num} for
|
|
131
|
+
* the columns a chart *names* things by rather than measures them by (a bar's
|
|
132
|
+
* category, a wedge's slice). A missing cell reads as empty rather than as the
|
|
133
|
+
* string `"undefined"`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function text(row: DataRecord, field: string | undefined): string;
|
|
136
|
+
/**
|
|
137
|
+
* Every column that holds numbers across `data`, in header order, skipping the
|
|
138
|
+
* names in `exclude` (typically the category column).
|
|
139
|
+
*
|
|
140
|
+
* A column counts as numeric only if every non-empty cell in it is a number, so
|
|
141
|
+
* a stray text cell leaves the column out rather than plotting zeros. This is
|
|
142
|
+
* what lets a chart plot "every other column" without the author naming twenty
|
|
143
|
+
* fields.
|
|
144
|
+
*/
|
|
145
|
+
export declare function numericFields(data: DataRecord[], exclude?: string[]): string[];
|
|
146
|
+
/** One axis's (x or y) style vocabulary. */
|
|
147
|
+
export interface AxisConfig {
|
|
148
|
+
/** Style of each marker along the axis. */
|
|
149
|
+
labelStyle: TextStyle;
|
|
150
|
+
/** Style of the axis caption. */
|
|
151
|
+
titleStyle: TextStyle;
|
|
152
|
+
/**
|
|
153
|
+
* This axis's direction of the plot's internal grid — weight+fill honoured,
|
|
154
|
+
* dash/cap/join ignored (grid lines are drawn as filled rects).
|
|
155
|
+
*/
|
|
156
|
+
lineStyle: Stroke;
|
|
157
|
+
/**
|
|
158
|
+
* Gap between the plot and the marker row. Only the side facing the plot is
|
|
159
|
+
* read — `.top` for a horizontal axis, `.right` for a vertical one.
|
|
160
|
+
*/
|
|
161
|
+
tickPadding: Insets;
|
|
162
|
+
/** Gap between the marker row and the caption, read the same side. */
|
|
163
|
+
titlePadding: Insets;
|
|
164
|
+
}
|
|
165
|
+
/** A legend's per-series colour swatch — a rounded chip, not the caption. */
|
|
166
|
+
export interface LegendMarkerConfig {
|
|
167
|
+
width: number;
|
|
168
|
+
height: number;
|
|
169
|
+
borderRadius: number;
|
|
170
|
+
stroke: Stroke;
|
|
171
|
+
shadow: Shadow;
|
|
172
|
+
}
|
|
173
|
+
/** A legend's visual theme. */
|
|
174
|
+
export interface LegendConfig {
|
|
175
|
+
padding: Insets;
|
|
176
|
+
/** Caption style — only the swatch carries the series colour. */
|
|
177
|
+
textStyle: TextStyle;
|
|
178
|
+
/** Gap between legend entries. */
|
|
179
|
+
itemGap: number;
|
|
180
|
+
markerStyle: LegendMarkerConfig;
|
|
181
|
+
}
|
|
182
|
+
/** The plot panel a cartesian chart draws its marks over. */
|
|
183
|
+
export interface PlotAreaConfig {
|
|
184
|
+
stroke: Stroke;
|
|
185
|
+
fill: Fill;
|
|
186
|
+
shadow: Shadow;
|
|
187
|
+
}
|
|
188
|
+
/** The default styling of a horizontal (marker row beneath the plot) axis. */
|
|
189
|
+
export declare const DEFAULT_X_AXIS: AxisConfig;
|
|
190
|
+
/** The default styling of a vertical (marker column beside the plot) axis. */
|
|
191
|
+
export declare const DEFAULT_Y_AXIS: AxisConfig;
|
|
192
|
+
/**
|
|
193
|
+
* The default plot panel: **unpainted**, framed. A chart reads against the
|
|
194
|
+
* stage rather than punching a panel into it, which is the look the family was
|
|
195
|
+
* designed at.
|
|
196
|
+
*/
|
|
197
|
+
export declare const DEFAULT_PLOT_AREA: PlotAreaConfig;
|
|
198
|
+
/** The default legend styling, shared by every chart that draws one. */
|
|
199
|
+
export declare const DEFAULT_LEGEND: LegendConfig;
|
|
200
|
+
/** The default per-series stroke palette — {@link DEFAULT_SERIES_COLORS}, drawn 4px. */
|
|
201
|
+
export declare const DEFAULT_SERIES_STROKES: Stroke[];
|
|
202
|
+
/** The default per-series fill palette — the same colours, as solid paint. */
|
|
203
|
+
export declare const DEFAULT_SERIES_FILLS: Fill[];
|
|
204
|
+
export declare function resolveAxisConfig(axis: Partial<AxisConfig> | undefined, previous: AxisConfig): AxisConfig;
|
|
205
|
+
export declare function lerpAxisConfig(from: AxisConfig, to: AxisConfig, t: number): AxisConfig;
|
|
206
|
+
export declare function resolvePlotArea(plotArea: Partial<PlotAreaConfig> | undefined, previous: PlotAreaConfig): PlotAreaConfig;
|
|
207
|
+
export declare function lerpPlotArea(from: PlotAreaConfig, to: PlotAreaConfig, t: number): PlotAreaConfig;
|
|
208
|
+
/** A legend theme as the author may state it — every branch optional. */
|
|
209
|
+
export type LegendTheme = Partial<Omit<LegendConfig, "markerStyle">> & {
|
|
210
|
+
markerStyle?: Partial<LegendMarkerConfig>;
|
|
211
|
+
};
|
|
212
|
+
export declare function resolveLegendConfig(legend: LegendTheme | undefined, previous: LegendConfig): LegendConfig;
|
|
213
|
+
export declare function lerpLegendConfig(from: LegendConfig, to: LegendConfig, t: number): LegendConfig;
|
|
214
|
+
/** A whole-palette override replaces the previous palette outright. */
|
|
215
|
+
export declare function resolveSeriesStrokes(styles: Stroke[] | undefined, previous: Stroke[]): Stroke[];
|
|
216
|
+
/** Pairwise by index; a palette that grows/shrinks holds the longer side's tail. */
|
|
217
|
+
export declare function lerpSeriesStrokes(from: Stroke[], to: Stroke[], t: number): Stroke[];
|
|
218
|
+
/** The fill-palette twin of {@link resolveSeriesStrokes}, for filled marks. */
|
|
219
|
+
export declare function resolveSeriesFills(fills: Fill[] | undefined, previous: Fill[]): Fill[];
|
|
220
|
+
/** The fill-palette twin of {@link lerpSeriesStrokes}. */
|
|
221
|
+
export declare function lerpSeriesFills(from: Fill[], to: Fill[], t: number): Fill[];
|
|
222
|
+
/**
|
|
223
|
+
* The effective stroke for series `index`: the palette's entry at
|
|
224
|
+
* `index % palette.length`, with the series' own `fill`, if set, overriding just
|
|
225
|
+
* the last (topmost) layer's colour.
|
|
226
|
+
*/
|
|
227
|
+
export declare function resolveSeriesStroke(palette: Stroke[], series: ChartSeries, index: number): Stroke;
|
|
228
|
+
/**
|
|
229
|
+
* The effective *colour* for series `index` — the same colour
|
|
230
|
+
* {@link resolveSeriesStroke} draws its line in — for contexts (a legend
|
|
231
|
+
* swatch) that only need the fill.
|
|
232
|
+
*/
|
|
233
|
+
export declare function resolveSeriesFill(palette: Stroke[], series: ChartSeries, index: number): Fill;
|
|
234
|
+
/**
|
|
235
|
+
* The effective paint for mark `index` of a **filled** chart (a bar, a wedge):
|
|
236
|
+
* the series' own `fill` when it carries one, else the palette's entry for its
|
|
237
|
+
* index, cycled.
|
|
238
|
+
*
|
|
239
|
+
* The stroke twin above has to reach inside a stroke to swap one layer's colour;
|
|
240
|
+
* a filled mark has no such geometry wrapped around its paint, so an override is
|
|
241
|
+
* simply the whole answer.
|
|
242
|
+
*/
|
|
243
|
+
export declare function resolvePalettePaint(palette: Fill[], override: Fill | undefined, index: number): Fill;
|
|
244
|
+
/** Format a marker value: integers plain, otherwise trimmed to one decimal. */
|
|
245
|
+
export declare function formatMarker(value: number): string;
|
|
246
|
+
/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
|
|
247
|
+
export declare function formatPercent(fraction: number): string;
|
|
248
|
+
/** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */
|
|
249
|
+
export declare function markerValues([min, max]: Range, markerCount: number): number[];
|
|
250
|
+
export { niceStep, enterBudget } from "@motionscript/core/component";
|
|
251
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@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