strata-react 1.0.9 → 1.0.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.
- package/README.md +2 -0
- package/dist/components/line-chart.d.ts +14 -1
- package/dist/components/media.d.ts +99 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +775 -114
- package/dist/index.js.map +1 -1
- package/dist/lib/format.d.ts +20 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridList, GridListItem, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useDragAndDrop, useFilter } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, Upload, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
6
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, Pause, Play, RotateCcw, Scan, Search, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
7
7
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
8
8
|
import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
9
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
@@ -140,6 +140,22 @@ function createFormat(locale, options = {}) {
|
|
|
140
140
|
const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
|
|
141
141
|
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
142
142
|
},
|
|
143
|
+
/**
|
|
144
|
+
* A position in media as an editor shows it, to a chosen precision: "4:05" (seconds), "4:05.250"
|
|
145
|
+
* (`"ms"`), or "4:05:07" (`"frames"` at `fps`, the last part the frame). Hours appear only from
|
|
146
|
+
* one hour. Floors, never rounds up, so a time never reads ahead of the picture. Unknown
|
|
147
|
+
* (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
|
|
148
|
+
*/
|
|
149
|
+
timecode: (seconds, { precision = "seconds", fps = 30 } = {}) => {
|
|
150
|
+
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
|
|
151
|
+
const whole = Math.floor(seconds);
|
|
152
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
153
|
+
const [h, m] = [Math.floor(whole / 3600), Math.floor(whole % 3600 / 60)];
|
|
154
|
+
const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;
|
|
155
|
+
if (precision === "ms") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1e3 + 1e-6), 999)).padStart(3, "0")}`;
|
|
156
|
+
if (precision === "frames") return `${base}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;
|
|
157
|
+
return base;
|
|
158
|
+
},
|
|
143
159
|
/** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
|
|
144
160
|
missing,
|
|
145
161
|
/** A time of day: `format.clock(at)` is "06:05". */
|
|
@@ -2876,6 +2892,411 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
|
2876
2892
|
}, r))]
|
|
2877
2893
|
});
|
|
2878
2894
|
}
|
|
2895
|
+
// src/components/media.tsx
|
|
2896
|
+
var clamp$1 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
2897
|
+
var timecode = (t, { precision, fps }) => format.timecode(t, {
|
|
2898
|
+
precision,
|
|
2899
|
+
fps
|
|
2900
|
+
});
|
|
2901
|
+
/** The current and total time, in `tabular-nums`, as `<time>` elements. */
|
|
2902
|
+
function TimeReadout({ time, duration, precision = "seconds", fps = 30, className }) {
|
|
2903
|
+
const total = duration === null ? null : timecode(duration, {
|
|
2904
|
+
precision,
|
|
2905
|
+
fps
|
|
2906
|
+
});
|
|
2907
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
2908
|
+
className: cn("inline-flex items-baseline gap-1 type-body-sm tabular-nums", className),
|
|
2909
|
+
children: [
|
|
2910
|
+
/* @__PURE__ */ jsx("time", {
|
|
2911
|
+
dateTime: `PT${Math.floor(time)}S`,
|
|
2912
|
+
"aria-label": `Position ${timecode(time, {
|
|
2913
|
+
precision,
|
|
2914
|
+
fps
|
|
2915
|
+
})}`,
|
|
2916
|
+
className: "text-foreground",
|
|
2917
|
+
style: total ? { minWidth: `${total.length}ch` } : void 0,
|
|
2918
|
+
children: timecode(time, {
|
|
2919
|
+
precision,
|
|
2920
|
+
fps
|
|
2921
|
+
})
|
|
2922
|
+
}),
|
|
2923
|
+
/* @__PURE__ */ jsx("span", {
|
|
2924
|
+
"aria-hidden": true,
|
|
2925
|
+
className: "text-muted-foreground",
|
|
2926
|
+
children: "/"
|
|
2927
|
+
}),
|
|
2928
|
+
/* @__PURE__ */ jsx("time", {
|
|
2929
|
+
dateTime: duration === null ? void 0 : `PT${Math.floor(duration)}S`,
|
|
2930
|
+
"aria-label": `Length ${total ?? format.missing}`,
|
|
2931
|
+
className: "text-muted-foreground",
|
|
2932
|
+
children: total ?? format.missing
|
|
2933
|
+
})
|
|
2934
|
+
]
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2937
|
+
/** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
|
|
2938
|
+
function SeekBar({ time, duration, onSeek, marks = [], buffered, step = 5, bigStep = 30, label = "Seek", precision = "seconds", fps = 30, disabled, className }) {
|
|
2939
|
+
const track = React.useRef(null);
|
|
2940
|
+
const input = React.useRef(null);
|
|
2941
|
+
const frac = duration > 0 ? clamp$1(time / duration, 0, 1) : 0;
|
|
2942
|
+
const seekTo = (t) => onSeek(clamp$1(t, 0, duration));
|
|
2943
|
+
const timeText = React.useMemo(() => {
|
|
2944
|
+
const say = (t) => timecode(t, {
|
|
2945
|
+
precision,
|
|
2946
|
+
fps
|
|
2947
|
+
});
|
|
2948
|
+
return {
|
|
2949
|
+
format: say,
|
|
2950
|
+
formatRange: (a, b) => `${say(a)} to ${say(b)}`,
|
|
2951
|
+
resolvedOptions: () => ({ locale: "en-US" })
|
|
2952
|
+
};
|
|
2953
|
+
}, [precision, fps]);
|
|
2954
|
+
const fine = precision === "frames" ? 1 / fps : precision === "ms" ? .001 : .01;
|
|
2955
|
+
const state = useSliderState({
|
|
2956
|
+
minValue: 0,
|
|
2957
|
+
maxValue: Math.max(duration, fine),
|
|
2958
|
+
step: fine,
|
|
2959
|
+
value: [clamp$1(time, 0, duration)],
|
|
2960
|
+
onChange: ([t]) => seekTo(t),
|
|
2961
|
+
numberFormatter: timeText,
|
|
2962
|
+
isDisabled: disabled
|
|
2963
|
+
});
|
|
2964
|
+
const { groupProps, trackProps } = useSlider({
|
|
2965
|
+
"aria-label": label,
|
|
2966
|
+
isDisabled: disabled
|
|
2967
|
+
}, state, track);
|
|
2968
|
+
const { thumbProps, inputProps } = useSliderThumb({
|
|
2969
|
+
index: 0,
|
|
2970
|
+
trackRef: track,
|
|
2971
|
+
inputRef: input,
|
|
2972
|
+
"aria-label": label,
|
|
2973
|
+
isDisabled: disabled
|
|
2974
|
+
}, state);
|
|
2975
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
2976
|
+
const keys = {
|
|
2977
|
+
ArrowLeft: -step,
|
|
2978
|
+
ArrowDown: -step,
|
|
2979
|
+
ArrowRight: step,
|
|
2980
|
+
ArrowUp: step,
|
|
2981
|
+
PageDown: -bigStep,
|
|
2982
|
+
PageUp: bigStep
|
|
2983
|
+
};
|
|
2984
|
+
const onKeyDownCapture = (e) => {
|
|
2985
|
+
if (disabled) return;
|
|
2986
|
+
if (e.key in keys) seekTo(time + keys[e.key]);
|
|
2987
|
+
else if (e.key === "Home") seekTo(0);
|
|
2988
|
+
else if (e.key === "End") seekTo(duration);
|
|
2989
|
+
else return;
|
|
2990
|
+
e.preventDefault();
|
|
2991
|
+
e.stopPropagation();
|
|
2992
|
+
};
|
|
2993
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2994
|
+
...groupProps,
|
|
2995
|
+
className: cn("relative flex h-(--control-h) min-w-0 flex-1 items-center", disabled && "cursor-not-allowed opacity-50", className),
|
|
2996
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2997
|
+
...trackProps,
|
|
2998
|
+
ref: track,
|
|
2999
|
+
className: cn("relative flex h-full w-full cursor-pointer touch-none items-center", disabled && "cursor-not-allowed"),
|
|
3000
|
+
children: [
|
|
3001
|
+
/* @__PURE__ */ jsx("span", {
|
|
3002
|
+
"aria-hidden": true,
|
|
3003
|
+
className: "absolute inset-x-0 h-1.5 rounded-pill bg-muted"
|
|
3004
|
+
}),
|
|
3005
|
+
buffered !== void 0 && duration > 0 && /* @__PURE__ */ jsx("span", {
|
|
3006
|
+
"aria-hidden": true,
|
|
3007
|
+
className: "absolute left-0 h-1.5 rounded-pill bg-neutral-4",
|
|
3008
|
+
style: { width: `${clamp$1(buffered / duration, 0, 1) * 100}%` }
|
|
3009
|
+
}),
|
|
3010
|
+
/* @__PURE__ */ jsx("span", {
|
|
3011
|
+
"aria-hidden": true,
|
|
3012
|
+
className: "absolute left-0 h-1.5 rounded-pill bg-primary",
|
|
3013
|
+
style: { width: `${frac * 100}%` }
|
|
3014
|
+
}),
|
|
3015
|
+
duration > 0 && marks.map((m) => /* @__PURE__ */ jsx("button", {
|
|
3016
|
+
type: "button",
|
|
3017
|
+
tabIndex: -1,
|
|
3018
|
+
disabled,
|
|
3019
|
+
title: `${m.label}, ${timecode(m.time, {
|
|
3020
|
+
precision,
|
|
3021
|
+
fps
|
|
3022
|
+
})}`,
|
|
3023
|
+
"aria-label": `${m.label}, ${timecode(m.time, {
|
|
3024
|
+
precision,
|
|
3025
|
+
fps
|
|
3026
|
+
})}`,
|
|
3027
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
3028
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
3029
|
+
onClick: () => seekTo(m.time),
|
|
3030
|
+
className: "absolute top-1/2 h-3 w-1 -translate-y-1/2 cursor-pointer rounded-pill bg-foreground",
|
|
3031
|
+
style: { left: `${m.time / duration * 100}%` }
|
|
3032
|
+
}, `${m.time}-${m.label}`)),
|
|
3033
|
+
/* @__PURE__ */ jsx("div", {
|
|
3034
|
+
...thumbProps,
|
|
3035
|
+
className: cn("absolute top-1/2 size-4 -translate-x-1/2 -translate-y-1/2 rounded-pill border-2 border-primary bg-background", isFocusVisible && "outline-2 outline-offset-2 outline-ring"),
|
|
3036
|
+
style: { left: `${frac * 100}%` },
|
|
3037
|
+
children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
|
|
3038
|
+
ref: input,
|
|
3039
|
+
...mergeProps(inputProps, focusProps),
|
|
3040
|
+
"aria-labelledby": void 0,
|
|
3041
|
+
onKeyDownCapture
|
|
3042
|
+
}) })
|
|
3043
|
+
})
|
|
3044
|
+
]
|
|
3045
|
+
})
|
|
3046
|
+
});
|
|
3047
|
+
}
|
|
3048
|
+
/** The transport buttons for a player the app owns. Every control is a named icon button; the play button's name is "Play" or "Pause" from `playing`. Only the buttons whose handler is passed are drawn. */
|
|
3049
|
+
function Transport({ playing, onPlayPause, onStop, onToStart, onToEnd, onStepBack, onStepForward, stepUnit = "frame", children, className }) {
|
|
3050
|
+
return /* @__PURE__ */ jsxs(Toolbar, {
|
|
3051
|
+
label: "Playback",
|
|
3052
|
+
className: cn("gap-2", className),
|
|
3053
|
+
children: [
|
|
3054
|
+
onToStart && /* @__PURE__ */ jsx(IconButton, {
|
|
3055
|
+
icon: SkipBack,
|
|
3056
|
+
label: "Go to start",
|
|
3057
|
+
hint: "Home",
|
|
3058
|
+
onClick: onToStart
|
|
3059
|
+
}),
|
|
3060
|
+
onStepBack && /* @__PURE__ */ jsx(IconButton, {
|
|
3061
|
+
icon: StepBack,
|
|
3062
|
+
label: `Back one ${stepUnit}`,
|
|
3063
|
+
hint: "←",
|
|
3064
|
+
onClick: onStepBack
|
|
3065
|
+
}),
|
|
3066
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
3067
|
+
icon: playing ? Pause : Play,
|
|
3068
|
+
label: playing ? "Pause" : "Play",
|
|
3069
|
+
hint: "Space",
|
|
3070
|
+
variant: "outline",
|
|
3071
|
+
onClick: onPlayPause
|
|
3072
|
+
}),
|
|
3073
|
+
onStop && /* @__PURE__ */ jsx(IconButton, {
|
|
3074
|
+
icon: Square,
|
|
3075
|
+
label: "Stop",
|
|
3076
|
+
onClick: onStop
|
|
3077
|
+
}),
|
|
3078
|
+
onStepForward && /* @__PURE__ */ jsx(IconButton, {
|
|
3079
|
+
icon: StepForward,
|
|
3080
|
+
label: `Forward one ${stepUnit}`,
|
|
3081
|
+
hint: "→",
|
|
3082
|
+
onClick: onStepForward
|
|
3083
|
+
}),
|
|
3084
|
+
onToEnd && /* @__PURE__ */ jsx(IconButton, {
|
|
3085
|
+
icon: SkipForward,
|
|
3086
|
+
label: "Go to end",
|
|
3087
|
+
hint: "End",
|
|
3088
|
+
onClick: onToEnd
|
|
3089
|
+
}),
|
|
3090
|
+
children
|
|
3091
|
+
]
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
3094
|
+
/** A mute button and a volume slider with its value in percent. Muting sets the volume to 0 and remembers the level; unmuting puts it back. Moving the slider from 0 unmutes. */
|
|
3095
|
+
function VolumeControl({ volume, onVolumeChange, max = 100, disabled, className }) {
|
|
3096
|
+
const last = React.useRef(volume > 0 ? volume : 100);
|
|
3097
|
+
if (volume > 0) last.current = volume;
|
|
3098
|
+
const muted = volume === 0;
|
|
3099
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3100
|
+
className: cn("flex items-center gap-2", className),
|
|
3101
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
3102
|
+
icon: muted ? VolumeX : Volume2,
|
|
3103
|
+
label: muted ? "Unmute" : "Mute",
|
|
3104
|
+
hint: "M",
|
|
3105
|
+
disabled,
|
|
3106
|
+
onClick: () => onVolumeChange(muted ? last.current : 0)
|
|
3107
|
+
}), /* @__PURE__ */ jsx(Slider, {
|
|
3108
|
+
"aria-label": "Volume",
|
|
3109
|
+
value: volume,
|
|
3110
|
+
onChange: onVolumeChange,
|
|
3111
|
+
min: 0,
|
|
3112
|
+
max,
|
|
3113
|
+
unit: "%",
|
|
3114
|
+
disabled,
|
|
3115
|
+
className: "w-40"
|
|
3116
|
+
})]
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
/** A choice of playback speed ("0.5×", "1×", "1.5×") on a native select, named "Playback speed". */
|
|
3120
|
+
function RateChoice({ rate, onRateChange, rates = [
|
|
3121
|
+
.5,
|
|
3122
|
+
1,
|
|
3123
|
+
1.25,
|
|
3124
|
+
1.5,
|
|
3125
|
+
2
|
|
3126
|
+
], className }) {
|
|
3127
|
+
return /* @__PURE__ */ jsx(NativeSelect, {
|
|
3128
|
+
"aria-label": "Playback speed",
|
|
3129
|
+
value: String(rate),
|
|
3130
|
+
onChange: (e) => onRateChange(Number(e.target.value)),
|
|
3131
|
+
className: cn("w-auto", className),
|
|
3132
|
+
children: rates.map((r) => /* @__PURE__ */ jsx("option", {
|
|
3133
|
+
value: String(r),
|
|
3134
|
+
children: `${r}×`
|
|
3135
|
+
}, r))
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
/**
|
|
3139
|
+
* The shortcuts a player takes, as one list for `useHotkeys` and `KeysLegend`: Space and K play
|
|
3140
|
+
* or pause, J and L go back or forward `jump` seconds, the arrows by `frame` seconds, Home and End
|
|
3141
|
+
* to the ends, M mutes. Pass the player's actions; the labels are the legend's words.
|
|
3142
|
+
*/
|
|
3143
|
+
function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump = 1, toggleMute }) {
|
|
3144
|
+
const to = (t) => () => seek(clamp$1(t, 0, duration));
|
|
3145
|
+
return [
|
|
3146
|
+
{
|
|
3147
|
+
keys: [" ", "k"],
|
|
3148
|
+
label: "Play or pause",
|
|
3149
|
+
run: toggle
|
|
3150
|
+
},
|
|
3151
|
+
{
|
|
3152
|
+
keys: ["j"],
|
|
3153
|
+
label: `Back ${jump} s`,
|
|
3154
|
+
run: to(time - jump),
|
|
3155
|
+
repeat: true
|
|
3156
|
+
},
|
|
3157
|
+
{
|
|
3158
|
+
keys: ["l"],
|
|
3159
|
+
label: `Forward ${jump} s`,
|
|
3160
|
+
run: to(time + jump),
|
|
3161
|
+
repeat: true
|
|
3162
|
+
},
|
|
3163
|
+
{
|
|
3164
|
+
keys: ["ArrowLeft"],
|
|
3165
|
+
label: "Back one frame",
|
|
3166
|
+
run: to(time - frame),
|
|
3167
|
+
repeat: true
|
|
3168
|
+
},
|
|
3169
|
+
{
|
|
3170
|
+
keys: ["ArrowRight"],
|
|
3171
|
+
label: "Forward one frame",
|
|
3172
|
+
run: to(time + frame),
|
|
3173
|
+
repeat: true
|
|
3174
|
+
},
|
|
3175
|
+
{
|
|
3176
|
+
keys: ["Home"],
|
|
3177
|
+
label: "Go to start",
|
|
3178
|
+
run: to(0)
|
|
3179
|
+
},
|
|
3180
|
+
{
|
|
3181
|
+
keys: ["End"],
|
|
3182
|
+
label: "Go to end",
|
|
3183
|
+
run: to(duration)
|
|
3184
|
+
},
|
|
3185
|
+
...toggleMute ? [{
|
|
3186
|
+
keys: ["m"],
|
|
3187
|
+
label: "Mute",
|
|
3188
|
+
run: toggleMute
|
|
3189
|
+
}] : []
|
|
3190
|
+
];
|
|
3191
|
+
}
|
|
3192
|
+
/** A frame that fits content of an aspect ratio into the pane, letterboxed on the sunken surface role (light and dark both), with room for the app's overlays. */
|
|
3193
|
+
function MediaStage({ aspect, children, label, className }) {
|
|
3194
|
+
const outer = React.useRef(null);
|
|
3195
|
+
const [box, setBox] = React.useState(null);
|
|
3196
|
+
const ratio = typeof aspect === "number" ? aspect : (() => {
|
|
3197
|
+
const [w, h] = aspect.split("/").map(Number);
|
|
3198
|
+
return w / h;
|
|
3199
|
+
})();
|
|
3200
|
+
React.useEffect(() => {
|
|
3201
|
+
const el = outer.current;
|
|
3202
|
+
if (!el) return;
|
|
3203
|
+
const read = () => setBox({
|
|
3204
|
+
w: el.clientWidth,
|
|
3205
|
+
h: el.clientHeight
|
|
3206
|
+
});
|
|
3207
|
+
read();
|
|
3208
|
+
const ro = new ResizeObserver(read);
|
|
3209
|
+
ro.observe(el);
|
|
3210
|
+
return () => ro.disconnect();
|
|
3211
|
+
}, []);
|
|
3212
|
+
const fit = box && box.w > 0 && box.h > 0 ? box.w / box.h > ratio ? {
|
|
3213
|
+
w: box.h * ratio,
|
|
3214
|
+
h: box.h
|
|
3215
|
+
} : {
|
|
3216
|
+
w: box.w,
|
|
3217
|
+
h: box.w / ratio
|
|
3218
|
+
} : null;
|
|
3219
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3220
|
+
ref: outer,
|
|
3221
|
+
role: "group",
|
|
3222
|
+
"aria-label": label,
|
|
3223
|
+
className: cn("grid min-h-0 min-w-0 place-items-center overflow-hidden bg-surface-sunken", className),
|
|
3224
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
3225
|
+
className: "relative overflow-hidden bg-background",
|
|
3226
|
+
style: fit ? {
|
|
3227
|
+
width: fit.w,
|
|
3228
|
+
height: fit.h
|
|
3229
|
+
} : {
|
|
3230
|
+
width: "100%",
|
|
3231
|
+
aspectRatio: String(ratio)
|
|
3232
|
+
},
|
|
3233
|
+
children
|
|
3234
|
+
})
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
/** Guides over a stage: action-safe and title-safe frames (90% and 80%), a centre cross and a rule-of-thirds grid. Drawn as two strokes (light over dark) so they read on any picture. */
|
|
3238
|
+
function StageGuides({ safe, thirds, centre, className }) {
|
|
3239
|
+
const lines = [];
|
|
3240
|
+
if (thirds) lines.push([
|
|
3241
|
+
100 / 3,
|
|
3242
|
+
0,
|
|
3243
|
+
100 / 3,
|
|
3244
|
+
100
|
|
3245
|
+
], [
|
|
3246
|
+
200 / 3,
|
|
3247
|
+
0,
|
|
3248
|
+
200 / 3,
|
|
3249
|
+
100
|
|
3250
|
+
], [
|
|
3251
|
+
0,
|
|
3252
|
+
100 / 3,
|
|
3253
|
+
100,
|
|
3254
|
+
100 / 3
|
|
3255
|
+
], [
|
|
3256
|
+
0,
|
|
3257
|
+
200 / 3,
|
|
3258
|
+
100,
|
|
3259
|
+
200 / 3
|
|
3260
|
+
]);
|
|
3261
|
+
if (centre) lines.push([
|
|
3262
|
+
50,
|
|
3263
|
+
46,
|
|
3264
|
+
50,
|
|
3265
|
+
54
|
|
3266
|
+
], [
|
|
3267
|
+
46,
|
|
3268
|
+
50,
|
|
3269
|
+
54,
|
|
3270
|
+
50
|
|
3271
|
+
]);
|
|
3272
|
+
const rects = safe ? [5, 10] : [];
|
|
3273
|
+
const draw = (cls, w) => /* @__PURE__ */ jsxs("g", {
|
|
3274
|
+
className: cls,
|
|
3275
|
+
strokeWidth: w,
|
|
3276
|
+
fill: "none",
|
|
3277
|
+
vectorEffect: "non-scaling-stroke",
|
|
3278
|
+
children: [lines.map((l, i) => /* @__PURE__ */ jsx("line", {
|
|
3279
|
+
x1: l[0],
|
|
3280
|
+
y1: l[1],
|
|
3281
|
+
x2: l[2],
|
|
3282
|
+
y2: l[3],
|
|
3283
|
+
vectorEffect: "non-scaling-stroke"
|
|
3284
|
+
}, i)), rects.map((m) => /* @__PURE__ */ jsx("rect", {
|
|
3285
|
+
x: m,
|
|
3286
|
+
y: m,
|
|
3287
|
+
width: 100 - 2 * m,
|
|
3288
|
+
height: 100 - 2 * m,
|
|
3289
|
+
vectorEffect: "non-scaling-stroke"
|
|
3290
|
+
}, m))]
|
|
3291
|
+
});
|
|
3292
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
3293
|
+
"aria-hidden": true,
|
|
3294
|
+
viewBox: "0 0 100 100",
|
|
3295
|
+
preserveAspectRatio: "none",
|
|
3296
|
+
className: cn("pointer-events-none absolute inset-0 size-full", className),
|
|
3297
|
+
children: [draw("stroke-foreground", 3), draw("stroke-background", 1)]
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
2879
3300
|
// src/lib/timeline.ts
|
|
2880
3301
|
/** Steps a person would write on a scale, in seconds: 1, 2, 5 and 10 × 10ⁿ below a minute, then 15 s, 30 s, minutes, quarter hours, hours, days. ux-research components.md §3.8: ticks land on values people would write. */
|
|
2881
3302
|
var STEPS = [
|
|
@@ -4587,7 +5008,7 @@ function fitTicks(ticks, scale, widthOf, gap = 12) {
|
|
|
4587
5008
|
return sorted.slice(0, 1);
|
|
4588
5009
|
}
|
|
4589
5010
|
/** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
|
|
4590
|
-
function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, height = 280, className }) {
|
|
5011
|
+
function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, current, formatCurrent, readout, onPick, area, height = 280, className }) {
|
|
4591
5012
|
const [ref, width] = useWidth();
|
|
4592
5013
|
const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
|
|
4593
5014
|
const all = [...series, ...planned ?? []];
|
|
@@ -4612,7 +5033,13 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
|
|
|
4612
5033
|
const half = xLabelWidth(t) / 2;
|
|
4613
5034
|
return Math.min(Math.max(sx(t), half), Math.max(half, width - half));
|
|
4614
5035
|
};
|
|
4615
|
-
const shownXTicks = fitTicks(xTicks, xLabelAt, xLabelWidth)
|
|
5036
|
+
const shownXTicks = React.useMemo(() => fitTicks(xTicks, xLabelAt, xLabelWidth), [
|
|
5037
|
+
xTicks,
|
|
5038
|
+
width,
|
|
5039
|
+
xMin,
|
|
5040
|
+
xMax,
|
|
5041
|
+
formatX
|
|
5042
|
+
]);
|
|
4616
5043
|
const path = (pts) => pts.map((p, i) => `${i ? "L" : "M"}${sx(p.x).toFixed(1)},${sy(p.y).toFixed(1)}`).join("");
|
|
4617
5044
|
const last = series[series.length - 1];
|
|
4618
5045
|
const peak = series.reduce((a, b) => b.y > a.y ? b : a, series[0]);
|
|
@@ -4620,115 +5047,296 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
|
|
|
4620
5047
|
/** The colour a value lands on: the highest stop at or below it. Used for the labelled points. */
|
|
4621
5048
|
const colourAt = (y) => stops.length ? [...stops].reverse().find((s) => s.at <= y)?.colour ?? stops[0].colour : colour;
|
|
4622
5049
|
const stroke = stops.length ? `url(#${gradientId})` : colour;
|
|
5050
|
+
const plot = React.useMemo(() => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5051
|
+
stops.length > 0 && /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("linearGradient", {
|
|
5052
|
+
id: gradientId,
|
|
5053
|
+
gradientUnits: "userSpaceOnUse",
|
|
5054
|
+
x1: 0,
|
|
5055
|
+
x2: 0,
|
|
5056
|
+
y1: sy(y.min),
|
|
5057
|
+
y2: sy(y.max),
|
|
5058
|
+
children: stops.map((s) => /* @__PURE__ */ jsx("stop", {
|
|
5059
|
+
offset: Math.min(1, Math.max(0, (s.at - y.min) / (y.max - y.min))),
|
|
5060
|
+
stopColor: s.colour
|
|
5061
|
+
}, s.at))
|
|
5062
|
+
}) }),
|
|
5063
|
+
band && band.below > y.min && /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
5064
|
+
x: pad.left,
|
|
5065
|
+
y: sy(Math.min(band.below, y.max)),
|
|
5066
|
+
width: w,
|
|
5067
|
+
height: sy(y.min) - sy(Math.min(band.below, y.max)),
|
|
5068
|
+
fill: "var(--success-subtle)"
|
|
5069
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
5070
|
+
x: pad.left + 8,
|
|
5071
|
+
y: sy(Math.min(band.below, y.max)) + 16,
|
|
5072
|
+
className: "fill-success type-caption",
|
|
5073
|
+
children: band.label
|
|
5074
|
+
})] }),
|
|
5075
|
+
y.ticks.map((t) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
5076
|
+
x1: pad.left,
|
|
5077
|
+
x2: pad.left + w,
|
|
5078
|
+
y1: sy(t),
|
|
5079
|
+
y2: sy(t),
|
|
5080
|
+
stroke: "var(--border)",
|
|
5081
|
+
strokeWidth: 1
|
|
5082
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
5083
|
+
x: pad.left - 8,
|
|
5084
|
+
y: sy(t),
|
|
5085
|
+
dy: "0.32em",
|
|
5086
|
+
textAnchor: "end",
|
|
5087
|
+
className: "fill-muted-foreground type-caption tabular-nums",
|
|
5088
|
+
children: formatY(t)
|
|
5089
|
+
})] }, t)),
|
|
5090
|
+
shownXTicks.map((t) => /* @__PURE__ */ jsx("text", {
|
|
5091
|
+
x: xLabelAt(t),
|
|
5092
|
+
y: height - 8,
|
|
5093
|
+
textAnchor: "middle",
|
|
5094
|
+
className: "fill-muted-foreground type-caption tabular-nums",
|
|
5095
|
+
children: formatX(t)
|
|
5096
|
+
}, t)),
|
|
5097
|
+
planned && /* @__PURE__ */ jsx("path", {
|
|
5098
|
+
d: path(planned),
|
|
5099
|
+
fill: "none",
|
|
5100
|
+
stroke: "var(--muted-foreground)",
|
|
5101
|
+
strokeWidth: 1.5,
|
|
5102
|
+
strokeDasharray: "4 4"
|
|
5103
|
+
}),
|
|
5104
|
+
area && series.length > 1 && /* @__PURE__ */ jsx("path", {
|
|
5105
|
+
d: `${path(series)}L${sx(series[series.length - 1].x).toFixed(1)},${sy(y.min).toFixed(1)}L${sx(series[0].x).toFixed(1)},${sy(y.min).toFixed(1)}Z`,
|
|
5106
|
+
fill: colour,
|
|
5107
|
+
fillOpacity: .12,
|
|
5108
|
+
stroke: "none"
|
|
5109
|
+
}),
|
|
5110
|
+
/* @__PURE__ */ jsx("path", {
|
|
5111
|
+
d: path(series),
|
|
5112
|
+
fill: "none",
|
|
5113
|
+
stroke,
|
|
5114
|
+
strokeWidth: stops.length ? 2.5 : 2,
|
|
5115
|
+
strokeLinejoin: "round",
|
|
5116
|
+
strokeLinecap: "round"
|
|
5117
|
+
}),
|
|
5118
|
+
/* @__PURE__ */ jsx("circle", {
|
|
5119
|
+
cx: sx(peak.x),
|
|
5120
|
+
cy: sy(peak.y),
|
|
5121
|
+
r: 3,
|
|
5122
|
+
fill: colourAt(peak.y)
|
|
5123
|
+
}),
|
|
5124
|
+
/* @__PURE__ */ jsxs("text", {
|
|
5125
|
+
x: sx(peak.x) + 8,
|
|
5126
|
+
y: sy(peak.y) - 8,
|
|
5127
|
+
className: "fill-foreground type-caption tabular-nums",
|
|
5128
|
+
children: [formatY(peak.y), " peak"]
|
|
5129
|
+
}),
|
|
5130
|
+
/* @__PURE__ */ jsx("line", {
|
|
5131
|
+
x1: sx(last.x),
|
|
5132
|
+
x2: sx(last.x),
|
|
5133
|
+
y1: pad.top,
|
|
5134
|
+
y2: pad.top + h,
|
|
5135
|
+
stroke: "var(--foreground)",
|
|
5136
|
+
strokeWidth: 1
|
|
5137
|
+
}),
|
|
5138
|
+
/* @__PURE__ */ jsx("circle", {
|
|
5139
|
+
cx: sx(last.x),
|
|
5140
|
+
cy: sy(last.y),
|
|
5141
|
+
r: 3.5,
|
|
5142
|
+
fill: colourAt(last.y)
|
|
5143
|
+
}),
|
|
5144
|
+
/* @__PURE__ */ jsxs("text", {
|
|
5145
|
+
x: sx(last.x) - 8,
|
|
5146
|
+
y: sy(last.y) - 10,
|
|
5147
|
+
textAnchor: "end",
|
|
5148
|
+
className: "fill-foreground type-label tabular-nums",
|
|
5149
|
+
children: [formatY(last.y), " now"]
|
|
5150
|
+
})
|
|
5151
|
+
] }), [
|
|
5152
|
+
width,
|
|
5153
|
+
height,
|
|
5154
|
+
series,
|
|
5155
|
+
planned,
|
|
5156
|
+
band,
|
|
5157
|
+
xTicks,
|
|
5158
|
+
yMin,
|
|
5159
|
+
yMax,
|
|
5160
|
+
colour,
|
|
5161
|
+
colourScale,
|
|
5162
|
+
formatX,
|
|
5163
|
+
formatY,
|
|
5164
|
+
area
|
|
5165
|
+
]);
|
|
5166
|
+
const tableEl = React.useMemo(() => /* @__PURE__ */ jsx("div", {
|
|
5167
|
+
className: "sr-only",
|
|
5168
|
+
children: /* @__PURE__ */ jsxs("table", { children: [
|
|
5169
|
+
/* @__PURE__ */ jsx("caption", { children: label }),
|
|
5170
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
5171
|
+
scope: "col",
|
|
5172
|
+
children: "Time"
|
|
5173
|
+
}), /* @__PURE__ */ jsx("th", {
|
|
5174
|
+
scope: "col",
|
|
5175
|
+
children: seriesLabel
|
|
5176
|
+
})] }) }),
|
|
5177
|
+
/* @__PURE__ */ jsx("tbody", { children: series.map((p) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", { children: formatX(p.x) }), /* @__PURE__ */ jsx("td", { children: formatY(p.y) })] }, p.x)) })
|
|
5178
|
+
] })
|
|
5179
|
+
}), [
|
|
5180
|
+
label,
|
|
5181
|
+
seriesLabel,
|
|
5182
|
+
series,
|
|
5183
|
+
formatX,
|
|
5184
|
+
formatY
|
|
5185
|
+
]);
|
|
5186
|
+
const sorted = React.useMemo(() => [...series].sort((p, q) => p.x - q.x), [series]);
|
|
5187
|
+
const interactive = Boolean(readout || onPick);
|
|
5188
|
+
const [hover, setHover] = React.useState(null);
|
|
5189
|
+
const [kbd, setKbd] = React.useState(null);
|
|
5190
|
+
const [focused, setFocused] = React.useState(false);
|
|
5191
|
+
const readoutText = (pt) => typeof readout === "function" ? readout(pt) : `${formatX(pt.x)}: ${formatY(pt.y)}`;
|
|
5192
|
+
const nearest = (px) => {
|
|
5193
|
+
const target = xMin + (px - pad.left) / (w || 1) * (xMax - xMin || 1);
|
|
5194
|
+
let best = 0;
|
|
5195
|
+
for (let i = 1; i < sorted.length; i++) if (Math.abs(sorted[i].x - target) < Math.abs(sorted[best].x - target)) best = i;
|
|
5196
|
+
return best;
|
|
5197
|
+
};
|
|
5198
|
+
/** The value of the line at x, read between the two readings either side (flat beyond the ends). */
|
|
5199
|
+
const yAt = (x) => {
|
|
5200
|
+
if (!sorted.length) return 0;
|
|
5201
|
+
if (x <= sorted[0].x) return sorted[0].y;
|
|
5202
|
+
for (let i = 1; i < sorted.length; i++) if (x <= sorted[i].x) {
|
|
5203
|
+
const [p0, p1] = [sorted[i - 1], sorted[i]];
|
|
5204
|
+
return p0.y + (p1.y - p0.y) * (x - p0.x) / (p1.x - p0.x || 1);
|
|
5205
|
+
}
|
|
5206
|
+
return sorted[sorted.length - 1].y;
|
|
5207
|
+
};
|
|
5208
|
+
const currentAt = current === void 0 ? null : {
|
|
5209
|
+
x: Math.min(Math.max(current, xMin), xMax),
|
|
5210
|
+
y: yAt(current)
|
|
5211
|
+
};
|
|
5212
|
+
const fallbackIdx = sorted.length ? currentAt ? nearest(sx(currentAt.x)) : sorted.length - 1 : 0;
|
|
5213
|
+
const heldIdx = kbd === null ? fallbackIdx : Math.min(kbd, Math.max(sorted.length - 1, 0));
|
|
5214
|
+
const selectedIdx = hover === null ? heldIdx : Math.min(hover, Math.max(sorted.length - 1, 0));
|
|
5215
|
+
const active = (hover !== null || focused) && sorted.length ? sorted[selectedIdx] : null;
|
|
5216
|
+
const onKey = (e) => {
|
|
5217
|
+
const at = selectedIdx;
|
|
5218
|
+
let next = at;
|
|
5219
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") next = Math.min(at + 1, sorted.length - 1);
|
|
5220
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") next = Math.max(at - 1, 0);
|
|
5221
|
+
else if (e.key === "Home") next = 0;
|
|
5222
|
+
else if (e.key === "End") next = sorted.length - 1;
|
|
5223
|
+
else if ((e.key === "Enter" || e.key === " ") && onPick) {
|
|
5224
|
+
e.preventDefault();
|
|
5225
|
+
onPick(sorted[at].x);
|
|
5226
|
+
return;
|
|
5227
|
+
} else return;
|
|
5228
|
+
e.preventDefault();
|
|
5229
|
+
setHover(null);
|
|
5230
|
+
setKbd(next);
|
|
5231
|
+
};
|
|
5232
|
+
const flip = (px, text) => px + labelWidth(text) + 16 > width ? {
|
|
5233
|
+
x: px - 8,
|
|
5234
|
+
anchor: "end"
|
|
5235
|
+
} : {
|
|
5236
|
+
x: px + 8,
|
|
5237
|
+
anchor: "start"
|
|
5238
|
+
};
|
|
4623
5239
|
return /* @__PURE__ */ jsxs("figure", {
|
|
4624
5240
|
className: cn("grid min-w-0 gap-2", className),
|
|
4625
5241
|
children: [
|
|
4626
|
-
/* @__PURE__ */
|
|
5242
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4627
5243
|
ref,
|
|
4628
|
-
className: "min-w-0",
|
|
4629
|
-
children: width > 0 && /* @__PURE__ */ jsxs("svg", {
|
|
5244
|
+
className: "relative min-w-0",
|
|
5245
|
+
children: [width > 0 && /* @__PURE__ */ jsxs("svg", {
|
|
4630
5246
|
width,
|
|
4631
5247
|
height,
|
|
4632
5248
|
role: "img",
|
|
4633
5249
|
"aria-label": label,
|
|
4634
5250
|
className: "block overflow-visible",
|
|
4635
5251
|
children: [
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
x: pad.left - 8,
|
|
4669
|
-
y: sy(t),
|
|
4670
|
-
dy: "0.32em",
|
|
4671
|
-
textAnchor: "end",
|
|
4672
|
-
className: "fill-muted-foreground type-caption tabular-nums",
|
|
4673
|
-
children: formatY(t)
|
|
4674
|
-
})] }, t)),
|
|
4675
|
-
shownXTicks.map((t) => /* @__PURE__ */ jsx("text", {
|
|
4676
|
-
x: xLabelAt(t),
|
|
4677
|
-
y: height - 8,
|
|
4678
|
-
textAnchor: "middle",
|
|
4679
|
-
className: "fill-muted-foreground type-caption tabular-nums",
|
|
4680
|
-
children: formatX(t)
|
|
4681
|
-
}, t)),
|
|
4682
|
-
planned && /* @__PURE__ */ jsx("path", {
|
|
4683
|
-
d: path(planned),
|
|
4684
|
-
fill: "none",
|
|
4685
|
-
stroke: "var(--muted-foreground)",
|
|
4686
|
-
strokeWidth: 1.5,
|
|
4687
|
-
strokeDasharray: "4 4"
|
|
4688
|
-
}),
|
|
4689
|
-
/* @__PURE__ */ jsx("path", {
|
|
4690
|
-
d: path(series),
|
|
4691
|
-
fill: "none",
|
|
4692
|
-
stroke,
|
|
4693
|
-
strokeWidth: stops.length ? 2.5 : 2,
|
|
4694
|
-
strokeLinejoin: "round",
|
|
4695
|
-
strokeLinecap: "round"
|
|
4696
|
-
}),
|
|
4697
|
-
/* @__PURE__ */ jsx("circle", {
|
|
4698
|
-
cx: sx(peak.x),
|
|
4699
|
-
cy: sy(peak.y),
|
|
4700
|
-
r: 3,
|
|
4701
|
-
fill: colourAt(peak.y)
|
|
4702
|
-
}),
|
|
4703
|
-
/* @__PURE__ */ jsxs("text", {
|
|
4704
|
-
x: sx(peak.x) + 8,
|
|
4705
|
-
y: sy(peak.y) - 8,
|
|
4706
|
-
className: "fill-foreground type-caption tabular-nums",
|
|
4707
|
-
children: [formatY(peak.y), " peak"]
|
|
4708
|
-
}),
|
|
4709
|
-
/* @__PURE__ */ jsx("line", {
|
|
4710
|
-
x1: sx(last.x),
|
|
4711
|
-
x2: sx(last.x),
|
|
4712
|
-
y1: pad.top,
|
|
4713
|
-
y2: pad.top + h,
|
|
4714
|
-
stroke: "var(--foreground)",
|
|
4715
|
-
strokeWidth: 1
|
|
4716
|
-
}),
|
|
4717
|
-
/* @__PURE__ */ jsx("circle", {
|
|
4718
|
-
cx: sx(last.x),
|
|
4719
|
-
cy: sy(last.y),
|
|
4720
|
-
r: 3.5,
|
|
4721
|
-
fill: colourAt(last.y)
|
|
5252
|
+
plot,
|
|
5253
|
+
currentAt && /* @__PURE__ */ jsxs("g", {
|
|
5254
|
+
"aria-hidden": true,
|
|
5255
|
+
children: [
|
|
5256
|
+
/* @__PURE__ */ jsx("line", {
|
|
5257
|
+
x1: sx(currentAt.x),
|
|
5258
|
+
x2: sx(currentAt.x),
|
|
5259
|
+
y1: pad.top,
|
|
5260
|
+
y2: pad.top + h,
|
|
5261
|
+
stroke: "var(--primary)",
|
|
5262
|
+
strokeWidth: 1.5
|
|
5263
|
+
}),
|
|
5264
|
+
/* @__PURE__ */ jsx("circle", {
|
|
5265
|
+
cx: sx(currentAt.x),
|
|
5266
|
+
cy: sy(currentAt.y),
|
|
5267
|
+
r: 4,
|
|
5268
|
+
fill: "var(--background)",
|
|
5269
|
+
stroke: "var(--primary)",
|
|
5270
|
+
strokeWidth: 2
|
|
5271
|
+
}),
|
|
5272
|
+
(() => {
|
|
5273
|
+
const text = formatCurrent ? formatCurrent(currentAt) : `${formatX(currentAt.x)}: ${formatY(currentAt.y)}`;
|
|
5274
|
+
const at = flip(sx(currentAt.x), text);
|
|
5275
|
+
return /* @__PURE__ */ jsx("text", {
|
|
5276
|
+
x: at.x,
|
|
5277
|
+
y: pad.top + 12,
|
|
5278
|
+
textAnchor: at.anchor,
|
|
5279
|
+
className: "fill-foreground type-caption tabular-nums",
|
|
5280
|
+
children: text
|
|
5281
|
+
});
|
|
5282
|
+
})()
|
|
5283
|
+
]
|
|
4722
5284
|
}),
|
|
4723
|
-
/* @__PURE__ */ jsxs("
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
5285
|
+
active && /* @__PURE__ */ jsxs("g", {
|
|
5286
|
+
"aria-hidden": true,
|
|
5287
|
+
children: [
|
|
5288
|
+
/* @__PURE__ */ jsx("line", {
|
|
5289
|
+
x1: sx(active.x),
|
|
5290
|
+
x2: sx(active.x),
|
|
5291
|
+
y1: pad.top,
|
|
5292
|
+
y2: pad.top + h,
|
|
5293
|
+
stroke: "var(--muted-foreground)",
|
|
5294
|
+
strokeWidth: 1,
|
|
5295
|
+
strokeDasharray: "2 3"
|
|
5296
|
+
}),
|
|
5297
|
+
/* @__PURE__ */ jsx("circle", {
|
|
5298
|
+
cx: sx(active.x),
|
|
5299
|
+
cy: sy(active.y),
|
|
5300
|
+
r: 4,
|
|
5301
|
+
fill: "var(--foreground)"
|
|
5302
|
+
}),
|
|
5303
|
+
(() => {
|
|
5304
|
+
const text = readoutText(active);
|
|
5305
|
+
const at = flip(sx(active.x), text);
|
|
5306
|
+
return /* @__PURE__ */ jsx("text", {
|
|
5307
|
+
x: at.x,
|
|
5308
|
+
y: sy(active.y) - 10,
|
|
5309
|
+
textAnchor: at.anchor,
|
|
5310
|
+
className: "fill-foreground type-label tabular-nums",
|
|
5311
|
+
paintOrder: "stroke",
|
|
5312
|
+
stroke: "var(--background)",
|
|
5313
|
+
strokeWidth: 3,
|
|
5314
|
+
children: text
|
|
5315
|
+
});
|
|
5316
|
+
})()
|
|
5317
|
+
]
|
|
4729
5318
|
})
|
|
4730
5319
|
]
|
|
4731
|
-
})
|
|
5320
|
+
}), width > 0 && interactive && sorted.length > 0 && /* @__PURE__ */ jsx(ReadingSlider, {
|
|
5321
|
+
label: `${label}: read values`,
|
|
5322
|
+
sorted,
|
|
5323
|
+
selected: selectedIdx,
|
|
5324
|
+
text: readoutText,
|
|
5325
|
+
onSelect: (i) => {
|
|
5326
|
+
setHover(null);
|
|
5327
|
+
setKbd(i);
|
|
5328
|
+
},
|
|
5329
|
+
onPick,
|
|
5330
|
+
onKeyDownCapture: onKey,
|
|
5331
|
+
onHover: (px) => setHover(px === null ? null : nearest(px)),
|
|
5332
|
+
onFocusChange: setFocused,
|
|
5333
|
+
box: {
|
|
5334
|
+
left: pad.left,
|
|
5335
|
+
top: pad.top,
|
|
5336
|
+
width: w,
|
|
5337
|
+
height: h
|
|
5338
|
+
}
|
|
5339
|
+
})]
|
|
4732
5340
|
}),
|
|
4733
5341
|
/* @__PURE__ */ jsxs("figcaption", {
|
|
4734
5342
|
className: "flex flex-wrap gap-x-5 gap-y-1 type-caption text-muted-foreground",
|
|
@@ -4785,23 +5393,76 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
|
|
|
4785
5393
|
}), plannedLabel]
|
|
4786
5394
|
})]
|
|
4787
5395
|
}),
|
|
4788
|
-
|
|
4789
|
-
className: "sr-only",
|
|
4790
|
-
children: /* @__PURE__ */ jsxs("table", { children: [
|
|
4791
|
-
/* @__PURE__ */ jsx("caption", { children: label }),
|
|
4792
|
-
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
4793
|
-
scope: "col",
|
|
4794
|
-
children: "Time"
|
|
4795
|
-
}), /* @__PURE__ */ jsx("th", {
|
|
4796
|
-
scope: "col",
|
|
4797
|
-
children: seriesLabel
|
|
4798
|
-
})] }) }),
|
|
4799
|
-
/* @__PURE__ */ jsx("tbody", { children: series.map((p) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", { children: formatX(p.x) }), /* @__PURE__ */ jsx("td", { children: formatY(p.y) })] }, p.x)) })
|
|
4800
|
-
] })
|
|
4801
|
-
})
|
|
5396
|
+
tableEl
|
|
4802
5397
|
]
|
|
4803
5398
|
});
|
|
4804
5399
|
}
|
|
5400
|
+
/** The slider over the plot: React Aria's hooks, snapped to the readings, with the reading as its spoken value. */
|
|
5401
|
+
function ReadingSlider({ label, sorted, selected, text, onSelect, onPick, onKeyDownCapture, onHover, onFocusChange, box }) {
|
|
5402
|
+
const track = React.useRef(null);
|
|
5403
|
+
const input = React.useRef(null);
|
|
5404
|
+
const lo = sorted[0].x;
|
|
5405
|
+
const hi = Math.max(sorted[sorted.length - 1].x, lo + 1e-9);
|
|
5406
|
+
const indexAt = (x) => {
|
|
5407
|
+
let best = 0;
|
|
5408
|
+
for (let i = 1; i < sorted.length; i++) if (Math.abs(sorted[i].x - x) < Math.abs(sorted[best].x - x)) best = i;
|
|
5409
|
+
return best;
|
|
5410
|
+
};
|
|
5411
|
+
const spoken = React.useMemo(() => {
|
|
5412
|
+
const say = (x) => text(sorted[indexAt(x)]);
|
|
5413
|
+
return {
|
|
5414
|
+
format: say,
|
|
5415
|
+
formatRange: (a, b) => `${say(a)} to ${say(b)}`,
|
|
5416
|
+
resolvedOptions: () => ({ locale: "en-US" })
|
|
5417
|
+
};
|
|
5418
|
+
}, [sorted, text]);
|
|
5419
|
+
const state = useSliderState({
|
|
5420
|
+
minValue: lo,
|
|
5421
|
+
maxValue: hi,
|
|
5422
|
+
step: (hi - lo) / 1e4,
|
|
5423
|
+
value: [sorted[selected].x],
|
|
5424
|
+
onChange: ([x]) => onSelect(indexAt(x)),
|
|
5425
|
+
onChangeEnd: ([x]) => onPick?.(sorted[indexAt(x)].x),
|
|
5426
|
+
numberFormatter: spoken
|
|
5427
|
+
});
|
|
5428
|
+
const { groupProps, trackProps } = useSlider({ "aria-label": label }, state, track);
|
|
5429
|
+
const { thumbProps, inputProps } = useSliderThumb({
|
|
5430
|
+
index: 0,
|
|
5431
|
+
trackRef: track,
|
|
5432
|
+
inputRef: input,
|
|
5433
|
+
"aria-label": label
|
|
5434
|
+
}, state);
|
|
5435
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
5436
|
+
return /* @__PURE__ */ jsx("div", {
|
|
5437
|
+
...groupProps,
|
|
5438
|
+
className: "absolute",
|
|
5439
|
+
style: box,
|
|
5440
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
5441
|
+
...trackProps,
|
|
5442
|
+
ref: track,
|
|
5443
|
+
onPointerMove: (e) => onHover(e.clientX - e.currentTarget.getBoundingClientRect().left + box.left),
|
|
5444
|
+
onPointerLeave: () => onHover(null),
|
|
5445
|
+
className: cn("relative size-full cursor-crosshair touch-none", isFocusVisible && "outline-2 outline-offset-2 outline-ring"),
|
|
5446
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
5447
|
+
...thumbProps,
|
|
5448
|
+
className: "absolute inset-y-0 w-0",
|
|
5449
|
+
style: { left: `${state.getThumbPercent(0) * 100}%` },
|
|
5450
|
+
children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
|
|
5451
|
+
ref: input,
|
|
5452
|
+
...mergeProps(inputProps, focusProps, {
|
|
5453
|
+
onFocus: () => onFocusChange(true),
|
|
5454
|
+
onBlur: () => onFocusChange(false)
|
|
5455
|
+
}),
|
|
5456
|
+
"aria-labelledby": void 0,
|
|
5457
|
+
onKeyDownCapture: (e) => {
|
|
5458
|
+
onKeyDownCapture(e);
|
|
5459
|
+
if (e.defaultPrevented) e.stopPropagation();
|
|
5460
|
+
}
|
|
5461
|
+
}) })
|
|
5462
|
+
})
|
|
5463
|
+
})
|
|
5464
|
+
});
|
|
5465
|
+
}
|
|
4805
5466
|
// src/components/page-header.tsx
|
|
4806
5467
|
/** The top of an Operate screen: a noun title, its scope, the main action, and the finding (the one fact in today's data that most needs attention). */
|
|
4807
5468
|
function PageHeader({ title, scope, actions, finding, as: Heading = "h1" }) {
|
|
@@ -6342,6 +7003,6 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
6342
7003
|
})
|
|
6343
7004
|
});
|
|
6344
7005
|
}
|
|
6345
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RowAction, SelectableGrid, SideNav, Skeleton, Slider, SortableList, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, zoomAt };
|
|
7006
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, zoomAt };
|
|
6346
7007
|
|
|
6347
7008
|
//# sourceMappingURL=index.js.map
|