@bigpixelrocket/uiok 0.0.0-stage → 0.1.1
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 +42 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# UIOK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Docs: https://bigpixelrocket.github.io/uiok/
|
|
4
|
+
|
|
5
|
+
UIOK is a React UI library with a retro look: compact controls set in system and monospace type, with every colour drawn from a swappable theme. It is extracted from the desktop apps Bigpixelrocket builds, and it works in any React 19 app.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
Pre-1.0; expect breaking changes in minor releases until 1.0. Version 0.1.0 ships the base stylesheet with 18 light and dark themes ([docs/themes.md](docs/themes.md)), shared labels, keyboard helpers, and component areas from buttons, tooltips, and dialogs to listings, data grids, pickers, palettes, and charts ([docs/components/](docs/components/)). Each area is importable on its own as `@bigpixelrocket/uiok/<area>`.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @bigpixelrocket/uiok
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`react` and `react-dom` 19 and `lucide-react` 1.31 or later within 1.x are peer dependencies.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Import the stylesheet once at your app's entry, then use the components:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import '@bigpixelrocket/uiok/styles.css';
|
|
25
|
+
import { VisuallyHidden } from '@bigpixelrocket/uiok';
|
|
26
|
+
|
|
27
|
+
export function CloseButton({ onClose }: { onClose: () => void }) {
|
|
28
|
+
return (
|
|
29
|
+
<button type="button" onClick={onClose}>
|
|
30
|
+
<span aria-hidden="true">×</span>
|
|
31
|
+
<VisuallyHidden>Close</VisuallyHidden>
|
|
32
|
+
</button>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The package is ESM only and ships one module per component, so bundlers drop what you do not import.
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Releases follow [docs/releasing.md](docs/releasing.md).
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef } from 'react';
|
|
2
|
+
/** Props for {@link VisuallyHidden}: every attribute a `<span>` accepts, `ref` included. */
|
|
3
|
+
export type VisuallyHiddenProps = ComponentPropsWithRef<'span'>;
|
|
4
|
+
/**
|
|
5
|
+
* Text that assistive technology reads but the screen does not show: a label
|
|
6
|
+
* for an icon-only control, a live announcement, or a description another
|
|
7
|
+
* element names through `aria-describedby`.
|
|
8
|
+
*
|
|
9
|
+
* Renders a `<span>` with the `visually-hidden` class from `@bigpixelrocket/uiok/styles.css`,
|
|
10
|
+
* which keeps it in the accessibility tree while clipping it to nothing on
|
|
11
|
+
* screen. A `className` passed in is added alongside that class.
|
|
12
|
+
*/
|
|
13
|
+
export declare function VisuallyHidden({ className, ...props }: VisuallyHiddenProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Text that assistive technology reads but the screen does not show: a label
|
|
4
|
+
* for an icon-only control, a live announcement, or a description another
|
|
5
|
+
* element names through `aria-describedby`.
|
|
6
|
+
*
|
|
7
|
+
* Renders a `<span>` with the `visually-hidden` class from `@bigpixelrocket/uiok/styles.css`,
|
|
8
|
+
* which keeps it in the accessibility tree while clipping it to nothing on
|
|
9
|
+
* screen. A `className` passed in is added alongside that class.
|
|
10
|
+
*/
|
|
11
|
+
export function VisuallyHidden({ className, ...props }) {
|
|
12
|
+
return (_jsx("span", { ...props, className: className ? `visually-hidden ${className}` : 'visually-hidden' }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
/** Props for {@link ActivityBar}. */
|
|
3
|
+
export interface ActivityBarProps {
|
|
4
|
+
/** Fraction done, in [0, 1], or null where the run reports none. */
|
|
5
|
+
readonly fraction: number | null;
|
|
6
|
+
/** The bar's accessible name ("Whole transfer"). */
|
|
7
|
+
readonly label: string;
|
|
8
|
+
/** Whether the run is working now; only then do the stripes move. */
|
|
9
|
+
readonly moving: boolean;
|
|
10
|
+
/** The track's class, which sizes and colours it where it is drawn. */
|
|
11
|
+
readonly className: string;
|
|
12
|
+
/** The fill's class, or the stripes' when the bar is indeterminate. */
|
|
13
|
+
readonly fillClassName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A progress bar that is either determinate, a fill as wide as the fraction
|
|
17
|
+
* done, or indeterminate, diagonal stripes across the whole track for a run
|
|
18
|
+
* that works without reporting how far it has got. The stripes scroll while
|
|
19
|
+
* the run goes on and stand still once it waits, pauses, or settles; with
|
|
20
|
+
* reduced motion they never scroll, and the caller's words and clock say
|
|
21
|
+
* that it is working (the `.activity-stripes` rules in `@bigpixelrocket/uiok/styles.css`).
|
|
22
|
+
* An indeterminate bar has no value for assistive technology, which reads
|
|
23
|
+
* it as busy while it moves.
|
|
24
|
+
*
|
|
25
|
+
* The track and fill look is the caller's (`className`, `fillClassName`);
|
|
26
|
+
* the stripes take their colour from `--stripe-ink` on the fill, the accent
|
|
27
|
+
* unless a rule sets another.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ActivityBar({ fraction, label, moving, className, fillClassName }: ActivityBarProps): ReactElement;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A progress bar that is either determinate, a fill as wide as the fraction
|
|
4
|
+
* done, or indeterminate, diagonal stripes across the whole track for a run
|
|
5
|
+
* that works without reporting how far it has got. The stripes scroll while
|
|
6
|
+
* the run goes on and stand still once it waits, pauses, or settles; with
|
|
7
|
+
* reduced motion they never scroll, and the caller's words and clock say
|
|
8
|
+
* that it is working (the `.activity-stripes` rules in `@bigpixelrocket/uiok/styles.css`).
|
|
9
|
+
* An indeterminate bar has no value for assistive technology, which reads
|
|
10
|
+
* it as busy while it moves.
|
|
11
|
+
*
|
|
12
|
+
* The track and fill look is the caller's (`className`, `fillClassName`);
|
|
13
|
+
* the stripes take their colour from `--stripe-ink` on the fill, the accent
|
|
14
|
+
* unless a rule sets another.
|
|
15
|
+
*/
|
|
16
|
+
export function ActivityBar({ fraction, label, moving, className, fillClassName }) {
|
|
17
|
+
if (fraction === null) {
|
|
18
|
+
return (_jsx("div", { "aria-busy": moving, "aria-label": label, className: `${className} indeterminate${moving ? ' moving' : ''}`, role: "progressbar", children: _jsx("div", { className: `${fillClassName} activity-stripes` }) }));
|
|
19
|
+
}
|
|
20
|
+
return (_jsx("div", { "aria-label": label, "aria-valuemax": 100, "aria-valuemin": 0, "aria-valuenow": Math.round(fraction * 100), className: className, role: "progressbar", children: _jsx("div", { className: fillClassName, style: { width: `${Math.min(Math.max(fraction, 0), 1) * 100}%` } }) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* ---- Activity stripes (ActivityBar) ----
|
|
2
|
+
|
|
3
|
+
The bar of a run that works without reporting how far it has got: diagonal
|
|
4
|
+
stripes across the whole track, in the bar's own colour (--stripe-ink)
|
|
5
|
+
over a fainter band of it (--stripe-ground). They scroll left to right
|
|
6
|
+
while the run goes on and stand still in every other state. A container
|
|
7
|
+
that shows a paused run dims them by setting --stripe-ink and
|
|
8
|
+
--stripe-ground on the stripes. The stripe period is 12px across the
|
|
9
|
+
stripes, 12 / sin 45deg = 16.97px along the track, which is how far one
|
|
10
|
+
loop moves them, so the loop is seamless. */
|
|
11
|
+
.indeterminate > .activity-stripes {
|
|
12
|
+
--stripe-ink: var(--accent);
|
|
13
|
+
width: 100%;
|
|
14
|
+
background-color: color-mix(in srgb, var(--stripe-ink) var(--stripe-ground, 38%), transparent);
|
|
15
|
+
background-image: repeating-linear-gradient(
|
|
16
|
+
-45deg,
|
|
17
|
+
var(--stripe-ink) 0 6px,
|
|
18
|
+
transparent 6px 12px
|
|
19
|
+
);
|
|
20
|
+
transition: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.indeterminate.moving > .activity-stripes {
|
|
24
|
+
animation: activity-stripes 0.9s linear infinite;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@keyframes activity-stripes {
|
|
28
|
+
from {
|
|
29
|
+
background-position: 0 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
to {
|
|
33
|
+
background-position: 16.97px 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Reduced motion: the stripes stand still, and the caller's clock and counts
|
|
38
|
+
say the run is working. */
|
|
39
|
+
@media (prefers-reduced-motion: reduce) {
|
|
40
|
+
.indeterminate.moving > .activity-stripes {
|
|
41
|
+
animation: none;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactElement, Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The action tiers: `primary` for the one main action of a view, `tonal` for
|
|
4
|
+
* a row's routine positive action (Install), `neutral` for everything else,
|
|
5
|
+
* destructive triggers included. A confirmation's destructive verb is the
|
|
6
|
+
* red lit primary of its dialog's key legend, not a button tier.
|
|
7
|
+
*/
|
|
8
|
+
export type ButtonVariant = 'primary' | 'tonal' | 'neutral';
|
|
9
|
+
/** The two button heights: `regular` (28px) and `small` (24px). */
|
|
10
|
+
export type ButtonSize = 'regular' | 'small';
|
|
11
|
+
/** Props for {@link Button}: every `<button>` attribute, plus its tier and size. */
|
|
12
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
13
|
+
/** The action tier; `neutral` unless given. */
|
|
14
|
+
readonly variant?: ButtonVariant;
|
|
15
|
+
/** The height; `regular` unless given. */
|
|
16
|
+
readonly size?: ButtonSize;
|
|
17
|
+
readonly ref?: Ref<HTMLButtonElement>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The one text action button, identical wherever it is drawn: styled only by
|
|
21
|
+
* the `.button` rules in `@bigpixelrocket/uiok/styles.css`, which carry their own font so no
|
|
22
|
+
* surrounding stylesheet restyles them. `className` is for layout (width,
|
|
23
|
+
* alignment), never for look. It is `type="button"` unless given another
|
|
24
|
+
* type, so it never submits a form by accident.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Button({ variant, size, className, type, ...rest }: ButtonProps): ReactElement;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The one text action button, identical wherever it is drawn: styled only by
|
|
4
|
+
* the `.button` rules in `@bigpixelrocket/uiok/styles.css`, which carry their own font so no
|
|
5
|
+
* surrounding stylesheet restyles them. `className` is for layout (width,
|
|
6
|
+
* alignment), never for look. It is `type="button"` unless given another
|
|
7
|
+
* type, so it never submits a form by accident.
|
|
8
|
+
*/
|
|
9
|
+
export function Button({ variant = 'neutral', size = 'regular', className, type = 'button', ...rest }) {
|
|
10
|
+
const classes = ['button', `button-${variant}`, size === 'small' ? 'button-small' : '', className]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join(' ');
|
|
13
|
+
return _jsx("button", { ...rest, className: classes, type: type });
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactElement, Ref } from 'react';
|
|
2
|
+
import type { ButtonSize } from './Button.js';
|
|
3
|
+
/** Props for {@link IconButton}: every `<button>` attribute, with a required accessible name. */
|
|
4
|
+
export interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
/** The accessible name; an icon alone names nothing. */
|
|
6
|
+
readonly 'aria-label': string;
|
|
7
|
+
/** The square's side; `regular` (28px) unless given. */
|
|
8
|
+
readonly size?: ButtonSize;
|
|
9
|
+
readonly ref?: Ref<HTMLButtonElement>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The one icon-only button, the neutral `Button`'s square sibling: styled
|
|
13
|
+
* only by the `.icon-button` rules in `@bigpixelrocket/uiok/styles.css`, so it looks the same
|
|
14
|
+
* wherever it is drawn. `className` is for layout, never for look. Always
|
|
15
|
+
* `type="button"`; pair it with `tooltip(label)` so a pointer user learns
|
|
16
|
+
* what the icon does.
|
|
17
|
+
*/
|
|
18
|
+
export declare function IconButton({ size, className, ...rest }: IconButtonProps): ReactElement;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The one icon-only button, the neutral `Button`'s square sibling: styled
|
|
4
|
+
* only by the `.icon-button` rules in `@bigpixelrocket/uiok/styles.css`, so it looks the same
|
|
5
|
+
* wherever it is drawn. `className` is for layout, never for look. Always
|
|
6
|
+
* `type="button"`; pair it with `tooltip(label)` so a pointer user learns
|
|
7
|
+
* what the icon does.
|
|
8
|
+
*/
|
|
9
|
+
export function IconButton({ size = 'regular', className, ...rest }) {
|
|
10
|
+
const classes = ['icon-button', size === 'small' ? 'icon-button-small' : '', className]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join(' ');
|
|
13
|
+
return _jsx("button", { ...rest, className: classes, type: "button" });
|
|
14
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* ---- Buttons (Button, IconButton) ----
|
|
2
|
+
|
|
3
|
+
The one action button and its icon-only sibling, identical wherever they
|
|
4
|
+
are drawn: they carry their own font, size, and box model, so no
|
|
5
|
+
surrounding stylesheet restyles them, and a consumer never overrides them
|
|
6
|
+
(a layout class may set width or alignment only). Tiers: primary for a
|
|
7
|
+
view's one main action, tonal for a row's routine positive action, neutral
|
|
8
|
+
for the rest. Hover is the glass edge: a lit top edge and a touch of
|
|
9
|
+
brightness on fills, a frosted wash on outlines; a press sinks the face. */
|
|
10
|
+
.button,
|
|
11
|
+
.icon-button {
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
flex: none;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
gap: 6px;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
height: 28px;
|
|
19
|
+
margin: 0;
|
|
20
|
+
border: 1px solid var(--border);
|
|
21
|
+
border-radius: 6px;
|
|
22
|
+
background: transparent;
|
|
23
|
+
color: var(--text);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
font-family: var(--font-ui);
|
|
26
|
+
font-size: 13px;
|
|
27
|
+
font-weight: 600;
|
|
28
|
+
line-height: 1;
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
transition:
|
|
31
|
+
background-color 120ms,
|
|
32
|
+
border-color 120ms,
|
|
33
|
+
box-shadow 120ms,
|
|
34
|
+
color 120ms,
|
|
35
|
+
filter 120ms;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.button {
|
|
39
|
+
padding: 0 12px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.button-small {
|
|
43
|
+
height: 24px;
|
|
44
|
+
padding: 0 9px;
|
|
45
|
+
font-size: 12px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.icon-button {
|
|
49
|
+
width: 28px;
|
|
50
|
+
padding: 0;
|
|
51
|
+
color: var(--text-dim);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.icon-button-small {
|
|
55
|
+
width: 24px;
|
|
56
|
+
height: 24px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.button-primary {
|
|
60
|
+
border-color: var(--primary);
|
|
61
|
+
background: var(--primary);
|
|
62
|
+
color: var(--on-primary);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.button-tonal {
|
|
66
|
+
border-color: var(--tonal-border);
|
|
67
|
+
background: var(--tonal);
|
|
68
|
+
color: var(--on-tonal);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.button-primary:hover:enabled:not([aria-disabled='true']) {
|
|
72
|
+
box-shadow: var(--hover-lit);
|
|
73
|
+
filter: brightness(1.08);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.button-tonal:hover:enabled:not([aria-disabled='true']) {
|
|
77
|
+
box-shadow: var(--hover-lit);
|
|
78
|
+
filter: brightness(var(--tonal-hover-brightness));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
:is(.button-neutral, .icon-button):hover:enabled:not([aria-disabled='true']) {
|
|
82
|
+
background: var(--hover-wash);
|
|
83
|
+
box-shadow: var(--hover-frost);
|
|
84
|
+
color: var(--text);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:is(.button, .icon-button):active:enabled:not([aria-disabled='true']) {
|
|
88
|
+
box-shadow: var(--shadow-pressed);
|
|
89
|
+
filter: brightness(0.94);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
:is(.button, .icon-button):focus-visible {
|
|
93
|
+
outline: 2px solid var(--accent);
|
|
94
|
+
outline-offset: 1px;
|
|
95
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ChartLabels } from '../labels/charts.js';
|
|
2
|
+
/** The failure messages a picture export throws with: the `charts` labels, or English. */
|
|
3
|
+
type DrawingLabels = Pick<ChartLabels, 'coloursUnreadable' | 'drawFailed'>;
|
|
4
|
+
/**
|
|
5
|
+
* A theme token's colour (`--chart-1`, `--bg`) as `#rrggbb`, read where
|
|
6
|
+
* `element` draws it, for a picture's background or anything else a file
|
|
7
|
+
* needs as a plain colour. Throws an `Error` with `labels.coloursUnreadable`
|
|
8
|
+
* where the theme sets no colour the function can read (a hex or `rgb()`
|
|
9
|
+
* value). Pass `useLabels().charts` to throw in the app's language.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tokenColour(element: Element, token: string, labels?: DrawingLabels): string;
|
|
12
|
+
/**
|
|
13
|
+
* A chart's SVG element (the one `ResultChart` hands to `svgRef`) as an SVG
|
|
14
|
+
* document of its own: every style it inherits from the stylesheet and the
|
|
15
|
+
* theme written in as attributes, fills and strokes as `#rrggbb`, classes
|
|
16
|
+
* dropped, sized to the element's box, on a `background` rectangle. The
|
|
17
|
+
* element must be in the document so its styles resolve.
|
|
18
|
+
*/
|
|
19
|
+
export declare function svgMarkup(svg: SVGSVGElement, background: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* An SVG document (from `svgMarkup`) drawn as PNG bytes at twice `width` by
|
|
22
|
+
* `height`, for sharp edges on a high-density screen. Rejects with an
|
|
23
|
+
* `Error` carrying `labels.drawFailed` when the browser cannot load, draw,
|
|
24
|
+
* or encode it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function svgPng(markup: string, width: number, height: number, labels?: DrawingLabels): Promise<Uint8Array>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Saving a chart as a picture, in the window: a theme token's colour, a
|
|
3
|
+
* chart's SVG element as SVG text with its styles written in, and that text
|
|
4
|
+
* drawn as PNG bytes on a canvas. Nothing here reaches a network: an SVG is
|
|
5
|
+
* loaded only from its own `data:` URL.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_CHART_LABELS } from '../labels/charts.js';
|
|
8
|
+
import { hexColour } from './Drawing.logic.js';
|
|
9
|
+
/**
|
|
10
|
+
* A theme token's colour (`--chart-1`, `--bg`) as `#rrggbb`, read where
|
|
11
|
+
* `element` draws it, for a picture's background or anything else a file
|
|
12
|
+
* needs as a plain colour. Throws an `Error` with `labels.coloursUnreadable`
|
|
13
|
+
* where the theme sets no colour the function can read (a hex or `rgb()`
|
|
14
|
+
* value). Pass `useLabels().charts` to throw in the app's language.
|
|
15
|
+
*/
|
|
16
|
+
export function tokenColour(element, token, labels = DEFAULT_CHART_LABELS) {
|
|
17
|
+
const colour = hexColour(getComputedStyle(element).getPropertyValue(token));
|
|
18
|
+
if (colour === null)
|
|
19
|
+
throw new Error(labels.coloursUnreadable);
|
|
20
|
+
return colour;
|
|
21
|
+
}
|
|
22
|
+
/** Bytes as base64, for a `data:` URL. */
|
|
23
|
+
const base64 = (bytes) => {
|
|
24
|
+
let binary = '';
|
|
25
|
+
for (let at = 0; at < bytes.length; at += 0x8000) {
|
|
26
|
+
binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000));
|
|
27
|
+
}
|
|
28
|
+
return btoa(binary);
|
|
29
|
+
};
|
|
30
|
+
/** A canvas's picture as PNG bytes. */
|
|
31
|
+
const canvasPng = (canvas, labels) => new Promise((resolve, reject) => {
|
|
32
|
+
canvas.toBlob((blob) => {
|
|
33
|
+
if (blob === null) {
|
|
34
|
+
reject(new Error(labels.drawFailed));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
void blob.arrayBuffer().then((buffer) => resolve(new Uint8Array(buffer)), reject);
|
|
38
|
+
}, 'image/png');
|
|
39
|
+
});
|
|
40
|
+
/** The styles a chart's element draws with, written into its copy so the file reads alone. */
|
|
41
|
+
const STYLED = [
|
|
42
|
+
'fill',
|
|
43
|
+
'fill-opacity',
|
|
44
|
+
'stroke',
|
|
45
|
+
'stroke-width',
|
|
46
|
+
'stroke-dasharray',
|
|
47
|
+
'opacity',
|
|
48
|
+
'font-size',
|
|
49
|
+
'font-family',
|
|
50
|
+
'font-weight',
|
|
51
|
+
'text-anchor',
|
|
52
|
+
'dominant-baseline'
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* A chart's SVG element (the one `ResultChart` hands to `svgRef`) as an SVG
|
|
56
|
+
* document of its own: every style it inherits from the stylesheet and the
|
|
57
|
+
* theme written in as attributes, fills and strokes as `#rrggbb`, classes
|
|
58
|
+
* dropped, sized to the element's box, on a `background` rectangle. The
|
|
59
|
+
* element must be in the document so its styles resolve.
|
|
60
|
+
*/
|
|
61
|
+
export function svgMarkup(svg, background) {
|
|
62
|
+
const copy = svg.cloneNode(true);
|
|
63
|
+
const sources = [svg, ...svg.querySelectorAll('*')];
|
|
64
|
+
const targets = [copy, ...copy.querySelectorAll('*')];
|
|
65
|
+
const box = svg.getBoundingClientRect();
|
|
66
|
+
sources.forEach((source, at) => {
|
|
67
|
+
const target = targets[at];
|
|
68
|
+
if (target === undefined)
|
|
69
|
+
return;
|
|
70
|
+
const style = getComputedStyle(source);
|
|
71
|
+
for (const name of STYLED) {
|
|
72
|
+
const value = style.getPropertyValue(name);
|
|
73
|
+
if (value !== '')
|
|
74
|
+
target.setAttribute(name, name === 'fill' || name === 'stroke'
|
|
75
|
+
? value === 'none'
|
|
76
|
+
? 'none'
|
|
77
|
+
: (hexColour(value) ?? value)
|
|
78
|
+
: value);
|
|
79
|
+
}
|
|
80
|
+
target.removeAttribute('class');
|
|
81
|
+
});
|
|
82
|
+
// The namespace declaration, set as one so a serializer writes it once.
|
|
83
|
+
copy.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
|
|
84
|
+
copy.setAttribute('width', String(Math.round(box.width)));
|
|
85
|
+
copy.setAttribute('height', String(Math.round(box.height)));
|
|
86
|
+
const ground = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
87
|
+
ground.setAttribute('width', '100%');
|
|
88
|
+
ground.setAttribute('height', '100%');
|
|
89
|
+
ground.setAttribute('fill', background);
|
|
90
|
+
copy.insertBefore(ground, copy.firstChild);
|
|
91
|
+
return new XMLSerializer().serializeToString(copy);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* An SVG document (from `svgMarkup`) drawn as PNG bytes at twice `width` by
|
|
95
|
+
* `height`, for sharp edges on a high-density screen. Rejects with an
|
|
96
|
+
* `Error` carrying `labels.drawFailed` when the browser cannot load, draw,
|
|
97
|
+
* or encode it.
|
|
98
|
+
*/
|
|
99
|
+
export function svgPng(markup, width, height, labels = DEFAULT_CHART_LABELS) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
const image = new Image();
|
|
102
|
+
image.onload = () => {
|
|
103
|
+
const canvas = document.createElement('canvas');
|
|
104
|
+
canvas.width = Math.round(width * 2);
|
|
105
|
+
canvas.height = Math.round(height * 2);
|
|
106
|
+
const context = canvas.getContext('2d');
|
|
107
|
+
if (context === null) {
|
|
108
|
+
reject(new Error(labels.drawFailed));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
112
|
+
canvasPng(canvas, labels).then(resolve, reject);
|
|
113
|
+
};
|
|
114
|
+
image.onerror = () => reject(new Error(labels.drawFailed));
|
|
115
|
+
image.src = `data:image/svg+xml;base64,${base64(new TextEncoder().encode(markup))}`;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A theme colour as a picture saved to a file takes it: resolved from the
|
|
3
|
+
* theme's tokens to `#rrggbb`, which every SVG and canvas reader accepts.
|
|
4
|
+
*/
|
|
5
|
+
/** A colour as a token resolves it (a three or six digit hex, or an rgb function), as `#rrggbb`; null for anything else. */
|
|
6
|
+
export function hexColour(text) {
|
|
7
|
+
const value = text.trim().toLowerCase();
|
|
8
|
+
const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/u.exec(value);
|
|
9
|
+
if (short !== null)
|
|
10
|
+
return `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}`;
|
|
11
|
+
if (/^#[0-9a-f]{6}$/u.test(value))
|
|
12
|
+
return value;
|
|
13
|
+
if (/^#[0-9a-f]{8}$/u.test(value))
|
|
14
|
+
return value.slice(0, 7);
|
|
15
|
+
const rgb = /^rgba?\(\s*(\d{1,3})[\s,]+(\d{1,3})[\s,]+(\d{1,3})/u.exec(value);
|
|
16
|
+
if (rgb !== null) {
|
|
17
|
+
return `#${[rgb[1], rgb[2], rgb[3]]
|
|
18
|
+
.map((part) => Math.min(255, Number(part)).toString(16).padStart(2, '0'))
|
|
19
|
+
.join('')}`;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Domain } from './Scatter.logic.js';
|
|
2
|
+
/** A value of a series at a moment (Unix milliseconds); null where it has none, which breaks the line. */
|
|
3
|
+
export interface LinePoint {
|
|
4
|
+
readonly at: number;
|
|
5
|
+
readonly value: number | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The value axis's domain over every value shown: from zero, or the lowest
|
|
9
|
+
* value where one is below zero, to the highest, with a tenth to spare
|
|
10
|
+
* above it; the unit domain when nothing is shown or every value is zero.
|
|
11
|
+
*/
|
|
12
|
+
export declare function valueDomain(values: readonly (number | null)[]): Domain;
|
|
13
|
+
/**
|
|
14
|
+
* A series' path through its points, each placed by `x` and `y`: a line
|
|
15
|
+
* from one value to the next, broken where a value is missing, a lone
|
|
16
|
+
* value a dot-sized stroke so it still shows.
|
|
17
|
+
*/
|
|
18
|
+
export declare function linePath(points: readonly LinePoint[], x: (at: number) => number, y: (value: number) => number): string;
|
|
19
|
+
/** The moment among `moments` (in order) nearest `at`; null when there is none. */
|
|
20
|
+
export declare function nearestMoment(moments: readonly number[], at: number): number | null;
|
|
21
|
+
/** A time label's position, kept inside the plot and clear of its neighbours. */
|
|
22
|
+
export interface TimeTickLabel {
|
|
23
|
+
readonly at: number;
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly left: number;
|
|
26
|
+
readonly width: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Centre labels on their ticks where there is room; slide boundary labels
|
|
30
|
+
* inside the plot (clear of the value axis), omitting only ticks whose
|
|
31
|
+
* complete labels would collide. The grid and data still use the true ticks.
|
|
32
|
+
*/
|
|
33
|
+
export declare function timeTickLabels(ticks: readonly number[], text: (at: number) => string, x: (at: number) => number, plotWidth: number, widthOf: (text: string) => number, gap?: number): TimeTickLabel[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The geometry of the line chart (`LineChart.tsx`): the value axis's domain,
|
|
3
|
+
* each series' path with its gaps, the point nearest a moment for the
|
|
4
|
+
* hover's read-out, and where the time labels fit.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The value axis's domain over every value shown: from zero, or the lowest
|
|
8
|
+
* value where one is below zero, to the highest, with a tenth to spare
|
|
9
|
+
* above it; the unit domain when nothing is shown or every value is zero.
|
|
10
|
+
*/
|
|
11
|
+
export function valueDomain(values) {
|
|
12
|
+
let min = 0;
|
|
13
|
+
let max = 0;
|
|
14
|
+
for (const value of values) {
|
|
15
|
+
if (value === null || !Number.isFinite(value))
|
|
16
|
+
continue;
|
|
17
|
+
if (value < min)
|
|
18
|
+
min = value;
|
|
19
|
+
if (value > max)
|
|
20
|
+
max = value;
|
|
21
|
+
}
|
|
22
|
+
if (max === min)
|
|
23
|
+
return { min, max: min + 1 };
|
|
24
|
+
return { min: min < 0 ? min - (max - min) / 10 : min, max: max + (max - min) / 10 };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A series' path through its points, each placed by `x` and `y`: a line
|
|
28
|
+
* from one value to the next, broken where a value is missing, a lone
|
|
29
|
+
* value a dot-sized stroke so it still shows.
|
|
30
|
+
*/
|
|
31
|
+
export function linePath(points, x, y) {
|
|
32
|
+
const parts = [];
|
|
33
|
+
let open = false;
|
|
34
|
+
for (const point of points) {
|
|
35
|
+
if (point.value === null || !Number.isFinite(point.value)) {
|
|
36
|
+
open = false;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const at = `${x(point.at).toFixed(1)} ${y(point.value).toFixed(1)}`;
|
|
40
|
+
parts.push(open ? `L ${at}` : `M ${at} l 0.01 0`);
|
|
41
|
+
open = true;
|
|
42
|
+
}
|
|
43
|
+
return parts.join(' ');
|
|
44
|
+
}
|
|
45
|
+
/** The moment among `moments` (in order) nearest `at`; null when there is none. */
|
|
46
|
+
export function nearestMoment(moments, at) {
|
|
47
|
+
let best = null;
|
|
48
|
+
for (const moment of moments) {
|
|
49
|
+
if (best === null || Math.abs(moment - at) < Math.abs(best - at))
|
|
50
|
+
best = moment;
|
|
51
|
+
}
|
|
52
|
+
return best;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Centre labels on their ticks where there is room; slide boundary labels
|
|
56
|
+
* inside the plot (clear of the value axis), omitting only ticks whose
|
|
57
|
+
* complete labels would collide. The grid and data still use the true ticks.
|
|
58
|
+
*/
|
|
59
|
+
export function timeTickLabels(ticks, text, x, plotWidth, widthOf, gap = 8) {
|
|
60
|
+
const labels = [];
|
|
61
|
+
for (const at of ticks) {
|
|
62
|
+
const label = text(at);
|
|
63
|
+
const width = widthOf(label);
|
|
64
|
+
const left = Math.max(0, Math.min(x(at) - width / 2, plotWidth - width));
|
|
65
|
+
const previous = labels.at(-1);
|
|
66
|
+
if (width > plotWidth ||
|
|
67
|
+
(previous !== undefined && left < previous.left + previous.width + gap))
|
|
68
|
+
continue;
|
|
69
|
+
labels.push({ at, text: label, left, width });
|
|
70
|
+
}
|
|
71
|
+
return labels;
|
|
72
|
+
}
|