@underpin/ui 0.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +44 -1
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +21 -0
- package/components/button-group.js +32 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +145 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/data-table.d.ts +120 -0
- package/components/data-table.js +336 -0
- package/components/data-table.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +73 -0
- package/components/pagination.js +212 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +276 -0
- package/components/table.js +572 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +36 -0
- package/components/tabs.js +120 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +29 -0
- package/lib/icons.js +34 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +122 -3
- package/styles.css +630 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
- package/publish.log +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/lib/time-series.ts
|
|
2
|
+
/** The hues of a multi-series chart's lines, in series order; a fourth line wraps to the first. */
|
|
3
|
+
const SERIES_COLORS = [
|
|
4
|
+
"var(--color-chart-1)",
|
|
5
|
+
"var(--color-chart-2)",
|
|
6
|
+
"var(--color-chart-3)"
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* The wash under a line, as `TimeSeriesChart` and `Sparkline` draw it: a quarter of the series'
|
|
10
|
+
* hue at the line, fading to nothing at the baseline. Offsets run from the top of the plot.
|
|
11
|
+
*/
|
|
12
|
+
const AREA_FADE = [{
|
|
13
|
+
offset: .05,
|
|
14
|
+
opacity: .25
|
|
15
|
+
}, {
|
|
16
|
+
offset: .95,
|
|
17
|
+
opacity: .01
|
|
18
|
+
}];
|
|
19
|
+
/** How many buckets at the end of the series are still running. */
|
|
20
|
+
function countRunning(data) {
|
|
21
|
+
let count = 0;
|
|
22
|
+
while (count < data.length && data[data.length - 1 - count]?.partial) count += 1;
|
|
23
|
+
return count;
|
|
24
|
+
}
|
|
25
|
+
/** How many partial buckets open the series, leaving out the running ones at its end. */
|
|
26
|
+
function countPartialStart(data) {
|
|
27
|
+
const limit = data.length - countRunning(data);
|
|
28
|
+
let count = 0;
|
|
29
|
+
while (count < limit && data[count]?.partial) count += 1;
|
|
30
|
+
return count;
|
|
31
|
+
}
|
|
32
|
+
/** The sum of one series over the range, for the legend; a point without the key counts as zero. */
|
|
33
|
+
function seriesTotal(data, key) {
|
|
34
|
+
return data.reduce((sum, point) => sum + (point.values?.[key] ?? 0), 0);
|
|
35
|
+
}
|
|
36
|
+
/** Plainest tick steps, tried first: one of these times a power of ten. */
|
|
37
|
+
const PLAIN_STEPS = [
|
|
38
|
+
1,
|
|
39
|
+
2,
|
|
40
|
+
5,
|
|
41
|
+
10
|
|
42
|
+
];
|
|
43
|
+
/** Finer steps, for the ranges no plain step fits without leaving the plot half empty. */
|
|
44
|
+
const FINE_STEPS = [
|
|
45
|
+
1,
|
|
46
|
+
1.2,
|
|
47
|
+
1.5,
|
|
48
|
+
2,
|
|
49
|
+
2.5,
|
|
50
|
+
3,
|
|
51
|
+
4,
|
|
52
|
+
5,
|
|
53
|
+
6,
|
|
54
|
+
8,
|
|
55
|
+
10
|
|
56
|
+
];
|
|
57
|
+
/** The smallest step on `ladder` that fits `raw`; a whole-number series never gets a fractional one. */
|
|
58
|
+
function roundStep(raw, ladder, integer) {
|
|
59
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
60
|
+
return ladder.map((unit) => unit * power).find((unit) => unit >= raw && (!integer || Number.isInteger(unit))) ?? raw;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Intervals between horizontal grid lines. Fixed rather than scaled to the data, so the
|
|
64
|
+
* bar axis, drawn on the same lines over its own unit, keeps one scale as the metric on the
|
|
65
|
+
* value axis changes; otherwise the same revenue bars resize on every switch of the stat strip.
|
|
66
|
+
* Four intervals also divide a `[0, 100]` rate into round quarters.
|
|
67
|
+
*/
|
|
68
|
+
const GRID_INTERVALS = 4;
|
|
69
|
+
/** The grid lines at `step` apart, from zero. */
|
|
70
|
+
function ticksOf(step) {
|
|
71
|
+
return Array.from({ length: 5 }, (_, index) => Number((step * index).toPrecision(12)));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Grid lines from 0 up past `max`, all on round numbers. A plain step (1, 2, 5) wins unless the
|
|
75
|
+
* data would fill less than three quarters of the scale it makes, and steps whose ticks render
|
|
76
|
+
* the same label are ruled out: a currency axis over a few cents otherwise reads "$0.01,
|
|
77
|
+
* $0.01". An empty series is a plain 0–4.
|
|
78
|
+
*/
|
|
79
|
+
function niceTicks(max, { integer = false, format } = {}) {
|
|
80
|
+
if (!(max > 0)) return ticksOf(1);
|
|
81
|
+
function scaleOn(ladder) {
|
|
82
|
+
const step = roundStep(max / GRID_INTERVALS, ladder, integer);
|
|
83
|
+
return {
|
|
84
|
+
top: step * GRID_INTERVALS,
|
|
85
|
+
ticks: ticksOf(step)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const plain = scaleOn(PLAIN_STEPS);
|
|
89
|
+
const readable = [plain, scaleOn(FINE_STEPS)].filter((scale) => !format || new Set(scale.ticks.map(format)).size === scale.ticks.length);
|
|
90
|
+
const fallback = readable[0] ?? plain;
|
|
91
|
+
return readable.find((scale) => max >= scale.top * .75)?.ticks ?? fallback.ticks;
|
|
92
|
+
}
|
|
93
|
+
/** Grid lines over a fixed scale (a rate pinned to `[0, 100]`), in equal intervals. */
|
|
94
|
+
function domainTicks([low, high]) {
|
|
95
|
+
return ticksOf((high - low) / GRID_INTERVALS).map((value) => low + value);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Tick instants on a time axis: every nth bucket from the first, with the smallest whole n
|
|
99
|
+
* that fits `count` labels. Ticks land on real buckets and the gaps are equal, so the labels
|
|
100
|
+
* step by a constant amount ("2 AM, 4 AM, 6 AM") instead of drifting between 1 and 2. The
|
|
101
|
+
* tail bucket is dropped when it doesn't fall on the step rather than crowding the last gap.
|
|
102
|
+
*/
|
|
103
|
+
function pickTicks(times, count) {
|
|
104
|
+
const total = times.length;
|
|
105
|
+
if (total <= count) return times;
|
|
106
|
+
const step = Math.ceil((total - 1) / (count - 1));
|
|
107
|
+
return times.filter((_, index) => index % step === 0);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Notes grouped onto the bucket that holds them: a note belongs to the last bucket starting at
|
|
111
|
+
* or before it, so a week bucket folds in its seven days and an hourly chart shows a midnight
|
|
112
|
+
* note on its 00:00 bucket. Anything past the trailing bucket's `end` is outside the range and
|
|
113
|
+
* dropped, as is anything before the first bucket. Without an `end` the trailing bucket is taken
|
|
114
|
+
* to be as wide as the one before it (wrong for months, hence the parameter); a lone bucket
|
|
115
|
+
* then has no width to infer from, so only a note on its exact instant lands.
|
|
116
|
+
*/
|
|
117
|
+
function bucketNotes(times, notes, endOfLast) {
|
|
118
|
+
const bucketed = /* @__PURE__ */ new Map();
|
|
119
|
+
const count = times.length;
|
|
120
|
+
const first = times[0];
|
|
121
|
+
const last = times[count - 1];
|
|
122
|
+
if (first === void 0 || last === void 0) return bucketed;
|
|
123
|
+
const before = times[count - 2];
|
|
124
|
+
const end = endOfLast ?? (before === void 0 ? last : last + (last - before));
|
|
125
|
+
for (const note of notes) {
|
|
126
|
+
const time = note.date.getTime();
|
|
127
|
+
if (time < first || (end === last ? time !== last : time >= end)) continue;
|
|
128
|
+
let low = 0;
|
|
129
|
+
let high = count - 1;
|
|
130
|
+
while (low < high) {
|
|
131
|
+
const middle = Math.ceil((low + high) / 2);
|
|
132
|
+
if ((times[middle] ?? Number.POSITIVE_INFINITY) <= time) low = middle;
|
|
133
|
+
else high = middle - 1;
|
|
134
|
+
}
|
|
135
|
+
const start = times[low] ?? first;
|
|
136
|
+
const existing = bucketed.get(start);
|
|
137
|
+
if (existing) existing.push(note);
|
|
138
|
+
else bucketed.set(start, [note]);
|
|
139
|
+
}
|
|
140
|
+
return bucketed;
|
|
141
|
+
}
|
|
142
|
+
export { AREA_FADE, SERIES_COLORS, bucketNotes, countPartialStart, countRunning, domainTicks, niceTicks, pickTicks, seriesTotal };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=time-series.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series.js","names":[],"sources":["../../src/lib/time-series.ts"],"sourcesContent":["/**\n * The arithmetic behind `TimeSeriesChart`: its point and note shapes, round grid lines, evenly\n * spaced date ticks, and notes folded onto the buckets that hold them. Pure, so it is tested\n * without rendering a chart.\n */\n\nexport interface TimeSeriesSeries {\n /** Reads `point.values[key]`. */\n key: string\n label: string\n /** One of the `--color-chart-*` tokens; defaults to `SERIES_COLORS` by index. */\n color?: string\n}\n\n/** The hues of a multi-series chart's lines, in series order; a fourth line wraps to the first. */\nexport const SERIES_COLORS = [\n \"var(--color-chart-1)\",\n \"var(--color-chart-2)\",\n \"var(--color-chart-3)\",\n]\n\nexport interface TimeSeriesPoint {\n date: Date\n value: number\n /**\n * The same bucket in a compared period, drawn as a dashed, unfilled line.\n */\n previous?: number\n /**\n * An optional second series drawn as bars behind the line, on its own left-hand axis\n * (a different unit, e.g. revenue against a traffic line). Shown when any point is above zero.\n */\n bar?: number\n /**\n * A segment stacked on `bar`, drawn as a dashed outline: the part the bar lost (a refund\n * over net revenue). Drawn, and listed in the tooltip, once any point is above zero.\n */\n outline?: number\n /** Multi-series mode: one figure per `TimeSeriesSeries.key`. */\n values?: Record<string, number>\n /**\n * The bucket covers only part of its period, so its figures read low: the last buckets while\n * they are still running, or the first when a rolling range starts mid-bucket. The line\n * reaches them dashed and their bars are dashed outlines, so a partial bucket never reads as\n * a drop.\n */\n partial?: boolean\n /**\n * Figures of the bucket that the chart does not draw, already formatted, listed in its\n * tooltip under a hairline.\n */\n details?: { label: string; value: string }[]\n}\n\nexport interface TimeSeriesNote {\n date: Date\n text: string\n /** Who wrote it; the tooltip's small line over the text (\"Piotr · Sep 10\"). */\n author?: string\n}\n\n/**\n * The wash under a line, as `TimeSeriesChart` and `Sparkline` draw it: a quarter of the series'\n * hue at the line, fading to nothing at the baseline. Offsets run from the top of the plot.\n */\nexport const AREA_FADE = [\n { offset: 0.05, opacity: 0.25 },\n { offset: 0.95, opacity: 0.01 },\n] as const\n\n/** How many buckets at the end of the series are still running. */\nexport function countRunning(data: Pick<TimeSeriesPoint, \"partial\">[]): number {\n let count = 0\n while (count < data.length && data[data.length - 1 - count]?.partial) count += 1\n return count\n}\n\n/** How many partial buckets open the series, leaving out the running ones at its end. */\nexport function countPartialStart(data: Pick<TimeSeriesPoint, \"partial\">[]): number {\n const limit = data.length - countRunning(data)\n let count = 0\n while (count < limit && data[count]?.partial) count += 1\n return count\n}\n\n/** The sum of one series over the range, for the legend; a point without the key counts as zero. */\nexport function seriesTotal(data: TimeSeriesPoint[], key: string): number {\n return data.reduce((sum, point) => sum + (point.values?.[key] ?? 0), 0)\n}\n\n/** Plainest tick steps, tried first: one of these times a power of ten. */\nconst PLAIN_STEPS = [1, 2, 5, 10]\n\n/** Finer steps, for the ranges no plain step fits without leaving the plot half empty. */\nconst FINE_STEPS = [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10]\n\n/** The smallest step on `ladder` that fits `raw`; a whole-number series never gets a fractional one. */\nfunction roundStep(raw: number, ladder: number[], integer: boolean): number {\n const power = 10 ** Math.floor(Math.log10(raw))\n return (\n ladder\n .map(unit => unit * power)\n .find(unit => unit >= raw && (!integer || Number.isInteger(unit))) ?? raw\n )\n}\n\n/**\n * Intervals between horizontal grid lines. Fixed rather than scaled to the data, so the\n * bar axis, drawn on the same lines over its own unit, keeps one scale as the metric on the\n * value axis changes; otherwise the same revenue bars resize on every switch of the stat strip.\n * Four intervals also divide a `[0, 100]` rate into round quarters.\n */\nconst GRID_INTERVALS = 4\n\n/** The grid lines at `step` apart, from zero. */\nfunction ticksOf(step: number): number[] {\n // toPrecision kills the float dust a 0.1 step leaves behind (0.30000000000000004).\n return Array.from({ length: GRID_INTERVALS + 1 }, (_, index) =>\n Number((step * index).toPrecision(12)),\n )\n}\n\n/**\n * Grid lines from 0 up past `max`, all on round numbers. A plain step (1, 2, 5) wins unless the\n * data would fill less than three quarters of the scale it makes, and steps whose ticks render\n * the same label are ruled out: a currency axis over a few cents otherwise reads \"$0.01,\n * $0.01\". An empty series is a plain 0–4.\n */\nexport function niceTicks(\n max: number,\n { integer = false, format }: { integer?: boolean; format?: (value: number) => string } = {},\n): number[] {\n if (!(max > 0)) return ticksOf(1)\n\n function scaleOn(ladder: number[]) {\n const step = roundStep(max / GRID_INTERVALS, ladder, integer)\n return { top: step * GRID_INTERVALS, ticks: ticksOf(step) }\n }\n const plain = scaleOn(PLAIN_STEPS)\n const readable = [plain, scaleOn(FINE_STEPS)].filter(\n scale => !format || new Set(scale.ticks.map(format)).size === scale.ticks.length,\n )\n // Where neither step can tell its labels apart (a sub-cent money axis, a sub-second\n // duration), the plain one stands: it repeats itself least.\n const fallback = readable[0] ?? plain\n\n return readable.find(scale => max >= scale.top * 0.75)?.ticks ?? fallback.ticks\n}\n\n/** Grid lines over a fixed scale (a rate pinned to `[0, 100]`), in equal intervals. */\nexport function domainTicks([low, high]: [number, number]): number[] {\n return ticksOf((high - low) / GRID_INTERVALS).map(value => low + value)\n}\n\n/**\n * Tick instants on a time axis: every nth bucket from the first, with the smallest whole n\n * that fits `count` labels. Ticks land on real buckets and the gaps are equal, so the labels\n * step by a constant amount (\"2 AM, 4 AM, 6 AM\") instead of drifting between 1 and 2. The\n * tail bucket is dropped when it doesn't fall on the step rather than crowding the last gap.\n */\nexport function pickTicks(times: number[], count: number): number[] {\n const total = times.length\n if (total <= count) return times\n const step = Math.ceil((total - 1) / (count - 1))\n return times.filter((_, index) => index % step === 0)\n}\n\n/**\n * Notes grouped onto the bucket that holds them: a note belongs to the last bucket starting at\n * or before it, so a week bucket folds in its seven days and an hourly chart shows a midnight\n * note on its 00:00 bucket. Anything past the trailing bucket's `end` is outside the range and\n * dropped, as is anything before the first bucket. Without an `end` the trailing bucket is taken\n * to be as wide as the one before it (wrong for months, hence the parameter); a lone bucket\n * then has no width to infer from, so only a note on its exact instant lands.\n */\nexport function bucketNotes(\n times: number[],\n notes: TimeSeriesNote[],\n endOfLast?: number,\n): Map<number, TimeSeriesNote[]> {\n const bucketed = new Map<number, TimeSeriesNote[]>()\n const count = times.length\n const first = times[0]\n const last = times[count - 1]\n if (first === undefined || last === undefined) return bucketed\n\n const before = times[count - 2]\n const end = endOfLast ?? (before === undefined ? last : last + (last - before))\n\n for (const note of notes) {\n const time = note.date.getTime()\n if (time < first || (end === last ? time !== last : time >= end)) continue\n\n // The last bucket starting at or before the note; `times` is ascending.\n let low = 0\n let high = count - 1\n while (low < high) {\n const middle = Math.ceil((low + high) / 2)\n if ((times[middle] ?? Number.POSITIVE_INFINITY) <= time) low = middle\n else high = middle - 1\n }\n\n const start = times[low] ?? first\n const existing = bucketed.get(start)\n if (existing) existing.push(note)\n else bucketed.set(start, [note])\n }\n\n return bucketed\n}\n"],"mappings":"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"}
|
package/lib/tone.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The semantic status vocabulary shared by tone-aware primitives (Ping, Badge, Callout) and
|
|
3
|
+
* by consumers that colour a state: callers pick a meaning, never a palette, so two views of
|
|
4
|
+
* the same state can't drift apart.
|
|
5
|
+
*/
|
|
6
|
+
export type Tone = "success" | "warning" | "danger" | "neutral";
|
package/lib/tone.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CnFunction } from "cn";
|
|
2
|
+
import { VariantProps } from "tailwind-variants";
|
|
3
|
+
export declare const MERGE_CONFIG: {
|
|
4
|
+
extend: {
|
|
5
|
+
theme: {
|
|
6
|
+
text: string[];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const cn: CnFunction;
|
|
11
|
+
export declare const variants: import("tailwind-variants").TV<import("tailwind-variants").TVCustomConfig>;
|
|
12
|
+
export type { VariantProps };
|
package/lib/variants.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCn } from "cn/config";
|
|
2
|
+
import { createTV } from "tailwind-variants/config";
|
|
3
|
+
// src/lib/variants.ts
|
|
4
|
+
const MERGE_CONFIG = { extend: { theme: { text: [
|
|
5
|
+
"2xs",
|
|
6
|
+
"control",
|
|
7
|
+
"copy",
|
|
8
|
+
"figure"
|
|
9
|
+
] } } };
|
|
10
|
+
const cn = createCn(MERGE_CONFIG);
|
|
11
|
+
const variants = createTV({ twMergeConfig: MERGE_CONFIG });
|
|
12
|
+
export { MERGE_CONFIG, cn, variants };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants.js","names":[],"sources":["../../src/lib/variants.ts"],"sourcesContent":["import type { CnFunction } from \"cn\"\nimport { createCn } from \"cn/config\"\nimport { createTV } from \"tailwind-variants/config\"\n\n/*\n * The theme's own text sizes. Both class-merge engines only know Tailwind's steps, so without\n * this they read `text-control` as a colour and drop it beside `text-ink-muted`. An app with\n * sizes of its own extends this list in its own `cn`.\n */\nexport const MERGE_CONFIG = {\n extend: { theme: { text: [\"2xs\", \"control\", \"copy\", \"figure\"] } },\n}\n\nexport const cn: CnFunction = createCn(MERGE_CONFIG)\nexport const variants = createTV({ twMergeConfig: MERGE_CONFIG })\nexport type { VariantProps } from \"tailwind-variants\"\n"],"mappings":";;;AASA,MAAa,eAAe,EAC1B,QAAQ,EAAE,OAAO,EAAE,MAAM;CAAC;CAAO;CAAW;CAAQ;AAAQ,EAAE,EAAE,EAClE;AAEA,MAAa,KAAiB,SAAS,YAAY;AACnD,MAAa,WAAW,SAAS,EAAE,eAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,130 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@underpin/ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "React components on Base UI and Tailwind CSS v4: controls, overlays, forms, charts and the design tokens they share.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"base-ui",
|
|
7
|
+
"components",
|
|
8
|
+
"design-system",
|
|
9
|
+
"react",
|
|
10
|
+
"tailwind",
|
|
11
|
+
"ui"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/underpinhq/underpin/tree/main/packages/ui#readme",
|
|
14
|
+
"bugs": "https://github.com/underpinhq/underpin/issues",
|
|
5
15
|
"license": "MIT",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Piotr Kulpinski",
|
|
18
|
+
"email": "piotr@kulpinski.pl",
|
|
19
|
+
"url": "https://kulpinski.pl"
|
|
20
|
+
},
|
|
6
21
|
"repository": {
|
|
7
22
|
"type": "git",
|
|
8
23
|
"url": "git+https://github.com/underpinhq/underpin.git",
|
|
9
24
|
"directory": "packages/ui"
|
|
10
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": [
|
|
28
|
+
"**/*.css"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
"./styles.css": "./styles.css",
|
|
32
|
+
"./variants": {
|
|
33
|
+
"types": "./lib/variants.d.ts",
|
|
34
|
+
"default": "./lib/variants.js"
|
|
35
|
+
},
|
|
36
|
+
"./classes": {
|
|
37
|
+
"types": "./lib/classes.d.ts",
|
|
38
|
+
"default": "./lib/classes.js"
|
|
39
|
+
},
|
|
40
|
+
"./interactive": {
|
|
41
|
+
"types": "./lib/interactive.d.ts",
|
|
42
|
+
"default": "./lib/interactive.js"
|
|
43
|
+
},
|
|
44
|
+
"./slot": {
|
|
45
|
+
"types": "./lib/slot.d.ts",
|
|
46
|
+
"default": "./lib/slot.js"
|
|
47
|
+
},
|
|
48
|
+
"./tone": {
|
|
49
|
+
"types": "./lib/tone.d.ts",
|
|
50
|
+
"default": "./lib/tone.js"
|
|
51
|
+
},
|
|
52
|
+
"./animation": {
|
|
53
|
+
"types": "./lib/animation.d.ts",
|
|
54
|
+
"default": "./lib/animation.js"
|
|
55
|
+
},
|
|
56
|
+
"./icon": {
|
|
57
|
+
"types": "./lib/icon.d.ts",
|
|
58
|
+
"default": "./lib/icon.js"
|
|
59
|
+
},
|
|
60
|
+
"./day": {
|
|
61
|
+
"types": "./lib/day.d.ts",
|
|
62
|
+
"default": "./lib/day.js"
|
|
63
|
+
},
|
|
64
|
+
"./shortcuts": {
|
|
65
|
+
"types": "./lib/shortcuts.d.ts",
|
|
66
|
+
"default": "./lib/shortcuts.js"
|
|
67
|
+
},
|
|
68
|
+
"./media": {
|
|
69
|
+
"types": "./lib/media.d.ts",
|
|
70
|
+
"default": "./lib/media.js"
|
|
71
|
+
},
|
|
72
|
+
"./load-more": {
|
|
73
|
+
"types": "./lib/load-more.d.ts",
|
|
74
|
+
"default": "./lib/load-more.js"
|
|
75
|
+
},
|
|
76
|
+
"./data-table-state": {
|
|
77
|
+
"types": "./lib/data-table-state.d.ts",
|
|
78
|
+
"default": "./lib/data-table-state.js"
|
|
79
|
+
},
|
|
80
|
+
"./time-series": {
|
|
81
|
+
"types": "./lib/time-series.d.ts",
|
|
82
|
+
"default": "./lib/time-series.js"
|
|
83
|
+
},
|
|
84
|
+
"./chart-curve": {
|
|
85
|
+
"types": "./lib/chart-curve.d.ts",
|
|
86
|
+
"default": "./lib/chart-curve.js"
|
|
87
|
+
},
|
|
88
|
+
"./tokens": {
|
|
89
|
+
"types": "./tokens.d.ts",
|
|
90
|
+
"default": "./tokens.js"
|
|
91
|
+
},
|
|
92
|
+
"./*": {
|
|
93
|
+
"types": "./components/*.d.ts",
|
|
94
|
+
"default": "./components/*.js"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"access": "public"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@fontsource-variable/geist-mono": "^5.3.0",
|
|
102
|
+
"@hugeicons/core-free-icons": "^4.4.0",
|
|
103
|
+
"@hugeicons/react": "^1.1.10",
|
|
104
|
+
"@tanstack/charts": "1.0.0",
|
|
105
|
+
"cn": "^0.5.2",
|
|
106
|
+
"d3-shape": "3.2.0",
|
|
107
|
+
"react-day-picker": "^10.0.2",
|
|
108
|
+
"react-hotkeys-hook": "^5.3.3",
|
|
109
|
+
"sonner": "^2.0.8",
|
|
110
|
+
"tailwind-variants": "^4.0.1"
|
|
111
|
+
},
|
|
112
|
+
"peerDependencies": {
|
|
113
|
+
"@base-ui/react": ">=1",
|
|
114
|
+
"@tanstack/react-form": ">=1",
|
|
115
|
+
"@tanstack/react-table": ">=9",
|
|
116
|
+
"react": ">=19",
|
|
117
|
+
"react-dom": ">=19",
|
|
118
|
+
"tailwindcss": ">=4",
|
|
119
|
+
"tailwindcss-animate": ">=1"
|
|
120
|
+
},
|
|
121
|
+
"peerDependenciesMeta": {
|
|
122
|
+
"@tanstack/react-form": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"@tanstack/react-table": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"_sideEffects": "The stylesheet is a real side effect: `false` let a bundler tree-shake away a consumer's `import \"@underpin/ui/styles.css\"` and ship an unstyled app."
|
|
11
130
|
}
|