@overdoser/react-toolkit 0.18.0 → 0.19.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.
Files changed (156) hide show
  1. package/AGENTS.md +51 -7
  2. package/CHANGELOG.md +129 -0
  3. package/components/Accordion/Accordion.d.ts +94 -0
  4. package/components/Accordion/Accordion.js +180 -0
  5. package/components/Accordion/Accordion.module.scss.js +36 -0
  6. package/components/Accordion/index.d.ts +2 -0
  7. package/components/Alert/Alert.d.ts +29 -1
  8. package/components/Alert/Alert.js +44 -30
  9. package/components/Alert/Alert.module.scss.js +24 -16
  10. package/components/Alert/index.d.ts +1 -1
  11. package/components/Card/Card.d.ts +86 -0
  12. package/components/Card/Card.js +132 -0
  13. package/components/Card/Card.module.scss.js +60 -0
  14. package/components/Card/index.d.ts +2 -0
  15. package/components/Chip/Chip.d.ts +86 -0
  16. package/components/Chip/Chip.js +141 -0
  17. package/components/Chip/Chip.module.scss.js +59 -0
  18. package/components/Chip/index.d.ts +2 -0
  19. package/components/CodeBlock/CodeBlock.d.ts +78 -0
  20. package/components/CodeBlock/CodeBlock.js +120 -0
  21. package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
  22. package/components/CodeBlock/index.d.ts +2 -0
  23. package/components/CommandPalette/CommandPalette.d.ts +141 -0
  24. package/components/CommandPalette/CommandPalette.js +397 -0
  25. package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
  26. package/components/CommandPalette/index.d.ts +2 -0
  27. package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
  28. package/components/ConfirmDialog/ConfirmDialog.js +201 -0
  29. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
  30. package/components/ConfirmDialog/index.d.ts +2 -0
  31. package/components/Drawer/Drawer.d.ts +1 -0
  32. package/components/Drawer/Drawer.js +35 -36
  33. package/components/Drawer/Drawer.module.scss.js +20 -18
  34. package/components/Dropdown/Dropdown.d.ts +47 -7
  35. package/components/Dropdown/Dropdown.js +174 -81
  36. package/components/Dropdown/Dropdown.module.scss.js +40 -22
  37. package/components/Dropdown/DropdownItem.d.ts +31 -2
  38. package/components/Dropdown/DropdownItem.js +54 -27
  39. package/components/Dropdown/DropdownLabel.d.ts +11 -0
  40. package/components/Dropdown/DropdownLabel.js +11 -0
  41. package/components/Dropdown/DropdownSeparator.d.ts +12 -0
  42. package/components/Dropdown/DropdownSeparator.js +11 -0
  43. package/components/Dropdown/dropdownContext.d.ts +6 -0
  44. package/components/Dropdown/dropdownContext.js +5 -0
  45. package/components/Dropdown/index.d.ts +8 -2
  46. package/components/Dropdown/useContextMenu.d.ts +32 -0
  47. package/components/Dropdown/useContextMenu.js +18 -0
  48. package/components/EmptyState/EmptyState.d.ts +53 -0
  49. package/components/EmptyState/EmptyState.js +55 -0
  50. package/components/EmptyState/EmptyState.module.scss.js +25 -0
  51. package/components/EmptyState/index.d.ts +2 -0
  52. package/components/Form/FormField.js +25 -24
  53. package/components/ImageViewer/ImageViewer.d.ts +105 -0
  54. package/components/ImageViewer/ImageViewer.js +201 -0
  55. package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
  56. package/components/ImageViewer/index.d.ts +4 -0
  57. package/components/ImageViewer/useZoomPan.d.ts +94 -0
  58. package/components/ImageViewer/useZoomPan.js +141 -0
  59. package/components/Kbd/Kbd.d.ts +26 -0
  60. package/components/Kbd/Kbd.js +22 -0
  61. package/components/Kbd/Kbd.module.scss.js +17 -0
  62. package/components/Kbd/index.d.ts +2 -0
  63. package/components/KeyValueList/KeyValueList.d.ts +84 -0
  64. package/components/KeyValueList/KeyValueList.js +127 -0
  65. package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
  66. package/components/KeyValueList/index.d.ts +2 -0
  67. package/components/Modal/Modal.d.ts +1 -0
  68. package/components/Modal/Modal.js +40 -41
  69. package/components/Modal/Modal.module.scss.js +18 -16
  70. package/components/PageHeader/PageHeader.d.ts +61 -0
  71. package/components/PageHeader/PageHeader.js +73 -0
  72. package/components/PageHeader/PageHeader.module.scss.js +43 -0
  73. package/components/PageHeader/index.d.ts +2 -0
  74. package/components/ProgressBar/ProgressBar.d.ts +74 -0
  75. package/components/ProgressBar/ProgressBar.js +90 -0
  76. package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
  77. package/components/ProgressBar/index.d.ts +2 -0
  78. package/components/RelativeTime/RelativeTime.d.ts +45 -0
  79. package/components/RelativeTime/RelativeTime.js +43 -0
  80. package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
  81. package/components/RelativeTime/index.d.ts +2 -0
  82. package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
  83. package/components/SegmentedControl/SegmentedControl.js +131 -0
  84. package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
  85. package/components/SegmentedControl/index.d.ts +2 -0
  86. package/components/SplitPane/SplitPane.d.ts +61 -0
  87. package/components/SplitPane/SplitPane.js +171 -0
  88. package/components/SplitPane/SplitPane.module.scss.js +25 -0
  89. package/components/SplitPane/index.d.ts +2 -0
  90. package/components/StatCard/StatCard.d.ts +105 -0
  91. package/components/StatCard/StatCard.js +127 -0
  92. package/components/StatCard/StatCard.module.scss.js +72 -0
  93. package/components/StatCard/index.d.ts +2 -0
  94. package/components/StatusDot/StatusDot.d.ts +33 -0
  95. package/components/StatusDot/StatusDot.js +39 -0
  96. package/components/StatusDot/StatusDot.module.scss.js +32 -0
  97. package/components/StatusDot/index.d.ts +2 -0
  98. package/components/Table/Table.d.ts +100 -2
  99. package/components/Table/Table.js +371 -210
  100. package/components/Table/Table.module.scss.js +68 -46
  101. package/components/Table/index.d.ts +1 -1
  102. package/components/ThemeToggle/ThemeToggle.d.ts +38 -0
  103. package/components/ThemeToggle/ThemeToggle.js +97 -0
  104. package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
  105. package/components/ThemeToggle/index.d.ts +2 -0
  106. package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
  107. package/components/inputs/Checkbox/Checkbox.js +29 -28
  108. package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
  109. package/components/inputs/Input/Input.d.ts +33 -1
  110. package/components/inputs/Input/Input.js +94 -35
  111. package/components/inputs/Input/Input.module.scss.js +14 -12
  112. package/components/inputs/Radio/Radio.d.ts +5 -4
  113. package/components/inputs/Radio/Radio.js +55 -50
  114. package/components/inputs/Radio/Radio.module.scss.js +12 -10
  115. package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
  116. package/components/inputs/SearchInput/SearchInput.js +116 -0
  117. package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
  118. package/components/inputs/SearchInput/index.d.ts +2 -0
  119. package/components/inputs/Select/Select.d.ts +52 -0
  120. package/components/inputs/Select/Select.js +494 -385
  121. package/components/inputs/Select/Select.module.scss.js +34 -30
  122. package/components/inputs/Switch/Switch.d.ts +15 -0
  123. package/components/inputs/Switch/Switch.js +8 -0
  124. package/components/inputs/Switch/index.d.ts +2 -0
  125. package/hooks/useDebouncedValue.d.ts +15 -0
  126. package/hooks/useDebouncedValue.js +15 -0
  127. package/hooks/useElementSize.d.ts +20 -0
  128. package/hooks/useElementSize.js +23 -0
  129. package/hooks/useKeyboard.d.ts +49 -5
  130. package/hooks/useKeyboard.js +66 -16
  131. package/hooks/useMediaQuery.d.ts +14 -0
  132. package/hooks/useMediaQuery.js +16 -0
  133. package/hooks/useNow.d.ts +14 -0
  134. package/hooks/useNow.js +35 -0
  135. package/hooks/usePersistedState.d.ts +30 -0
  136. package/hooks/usePersistedState.js +96 -0
  137. package/hooks/useResizable.d.ts +66 -0
  138. package/hooks/useResizable.js +105 -0
  139. package/hooks/useTheme.d.ts +33 -0
  140. package/hooks/useTheme.js +27 -0
  141. package/index.css +1 -1
  142. package/index.d.ts +58 -4
  143. package/index.js +208 -132
  144. package/index.layered.css +1 -1
  145. package/llms.txt +619 -25
  146. package/manifest.json +1739 -91
  147. package/package.json +1 -1
  148. package/recipes/confirm-modal.tsx +65 -53
  149. package/recipes/floating-copy-button.tsx +32 -28
  150. package/utils/formatBytes.d.ts +21 -0
  151. package/utils/formatBytes.js +14 -0
  152. package/utils/index.d.ts +6 -0
  153. package/utils/themeScript.d.ts +17 -0
  154. package/utils/themeScript.js +9 -0
  155. package/utils/timeAgo.d.ts +33 -0
  156. package/utils/timeAgo.js +37 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overdoser/react-toolkit",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "homepage": "https://react-toolkit.overdoser.org",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -1,63 +1,75 @@
1
1
  import { useState } from 'react';
2
- import { Modal, Button, Typography } from '@overdoser/react-toolkit';
2
+ import { Button, ConfirmDialog, ConfirmProvider, toast, useConfirm } from '@overdoser/react-toolkit';
3
3
 
4
- interface ConfirmModalProps {
5
- open: boolean;
6
- title: string;
7
- message: React.ReactNode;
8
- confirmLabel?: string;
9
- cancelLabel?: string;
10
- destructive?: boolean;
11
- onConfirm: () => void | Promise<void>;
12
- onClose: () => void;
4
+ /**
5
+ * Confirm prompts without `window.confirm`.
6
+ *
7
+ * Mount `<ConfirmProvider>` once near the root (inside `<ToastProvider>` if
8
+ * you use toasts from `onConfirm`). Anywhere below it, `useConfirm()` returns
9
+ * a function that opens the dialog and resolves `true` / `false`:
10
+ *
11
+ * - `onConfirm` may be async: the confirm button shows `loading`, Cancel /
12
+ * Escape / backdrop are locked, and a rejection is shown inside the dialog
13
+ * (the promise stays pending until the user confirms successfully or cancels).
14
+ * - `danger` flips the confirm button to the danger variant and puts initial
15
+ * focus on Cancel.
16
+ * - `requireText` adds a type-to-confirm field.
17
+ *
18
+ * For a flow that needs its own state (multi-step, custom body), use the
19
+ * controlled `<ConfirmDialog>` directly — see `ControlledExample`.
20
+ */
21
+
22
+ export function AppRoot({ children }: { children: React.ReactNode }) {
23
+ return <ConfirmProvider defaults={{ cancelLabel: 'Keep' }}>{children}</ConfirmProvider>;
24
+ }
25
+
26
+ interface DeleteProjectButtonProps {
27
+ project: { id: string; name: string; slug: string };
28
+ remove: (id: string) => Promise<void>;
13
29
  }
14
30
 
15
- export function ConfirmModal({
16
- open,
17
- title,
18
- message,
19
- confirmLabel = 'Confirm',
20
- cancelLabel = 'Cancel',
21
- destructive = false,
22
- onConfirm,
23
- onClose,
24
- }: ConfirmModalProps) {
25
- const [busy, setBusy] = useState(false);
31
+ export function DeleteProjectButton({ project, remove }: DeleteProjectButtonProps) {
32
+ const confirm = useConfirm();
26
33
 
27
- const handleConfirm = async () => {
28
- setBusy(true);
29
- try {
30
- await onConfirm();
31
- onClose();
32
- } finally {
33
- setBusy(false);
34
- }
34
+ const handleClick = async () => {
35
+ const ok = await confirm({
36
+ title: `Delete “${project.name}”?`,
37
+ description: 'All environments and deploy history go with it. This cannot be undone.',
38
+ danger: true,
39
+ confirmLabel: 'Delete project',
40
+ requireText: project.slug,
41
+ // Awaited by the dialog; a thrown error is displayed inline.
42
+ onConfirm: () => remove(project.id),
43
+ });
44
+ if (ok) toast({ variant: 'success', title: 'Project deleted' });
35
45
  };
36
46
 
37
47
  return (
38
- <Modal open={open} onClose={onClose} size="sm" closeOnBackdrop={!busy} closeOnEscape={!busy}>
39
- <Modal.Header onClose={busy ? undefined : onClose}>
40
- <Typography variant="h3" weight="semibold">
41
- {title}
42
- </Typography>
43
- </Modal.Header>
44
- <Modal.Body>
45
- <Typography variant="p" color="muted">
46
- {message}
47
- </Typography>
48
- </Modal.Body>
49
- <Modal.Footer>
50
- <Button variant="ghost" onClick={onClose} disabled={busy}>
51
- {cancelLabel}
52
- </Button>
53
- <Button
54
- variant={destructive ? 'danger' : 'primary'}
55
- onClick={handleConfirm}
56
- loading={busy}
57
- >
58
- {confirmLabel}
59
- </Button>
60
- </Modal.Footer>
61
- </Modal>
48
+ <Button variant="danger" onClick={handleClick}>
49
+ Delete
50
+ </Button>
51
+ );
52
+ }
53
+
54
+ /** Controlled variant for custom flows. */
55
+ export function ControlledExample({ onArchive }: { onArchive: () => Promise<void> }) {
56
+ const [open, setOpen] = useState(false);
57
+ return (
58
+ <>
59
+ <Button variant="secondary" onClick={() => setOpen(true)}>
60
+ Archive
61
+ </Button>
62
+ <ConfirmDialog
63
+ open={open}
64
+ title="Archive this workspace?"
65
+ description="Members lose access until it is restored."
66
+ confirmLabel="Archive"
67
+ onConfirm={async () => {
68
+ await onArchive();
69
+ setOpen(false);
70
+ }}
71
+ onCancel={() => setOpen(false)}
72
+ />
73
+ </>
62
74
  );
63
75
  }
@@ -1,47 +1,43 @@
1
- import { CopyButton } from '@overdoser/react-toolkit';
1
+ import { CopyButton, CodeBlock } from '@overdoser/react-toolkit';
2
2
 
3
3
  /**
4
- * Copy button floating over a code snippet (docs-site pattern).
4
+ * Copy button floating over content.
5
5
  *
6
- * The two things this recipe encodes:
6
+ * For **code**, don't build this — `<CodeBlock>` ships the floating copy
7
+ * button (plus header / line numbers / wrap). This recipe is the generic
8
+ * version for any other box: a JSON preview, a generated URL, a log excerpt.
9
+ *
10
+ * The two things it encodes:
7
11
  *
8
12
  * 1. **Solid wrapper surface.** The `secondary` and `ghost` variants are
9
13
  * transparent at rest by design, so a button floated over content would
10
- * let the code text run straight under the glyph. Give the *wrapper* a
11
- * solid `--crk-color-bg` fill (with the button's border radius) — every
12
- * button state then composites over that surface instead of the code.
14
+ * let the text run straight under the glyph. Give the *wrapper* a solid
15
+ * `--crk-color-bg` fill (with the button's border radius) — every button
16
+ * state then composites over that surface instead of the content.
13
17
  * 2. **`secondary` over `ghost` for floating use.** Ghost has no border in
14
18
  * its resting state; secondary's inset outline gives the floating button
15
- * a visible affordance against the snippet background.
16
- *
17
- * The hover/success fills themselves are opaque (they mix the accent into
18
- * `--crk-color-bg`), so mid-morph the code never shines through the button.
19
+ * a visible affordance against the box background.
19
20
  */
20
21
 
21
- interface CodeSnippetProps {
22
- code: string;
23
- /** Language hint rendered as a class for external highlighters. @default undefined */
24
- language?: string;
22
+ interface CopyableBoxProps {
23
+ /** Text the button copies. */
24
+ text: string;
25
+ children: React.ReactNode;
25
26
  }
26
27
 
27
- export function CodeSnippet({ code, language }: CodeSnippetProps) {
28
+ export function CopyableBox({ text, children }: CopyableBoxProps) {
28
29
  return (
29
30
  <div style={{ position: 'relative' }}>
30
- <pre
31
+ <div
31
32
  style={{
32
- margin: 0,
33
33
  padding: '16px 20px',
34
- // Keep long lines scrollable; the button stays pinned to the box.
35
- overflowX: 'auto',
36
34
  background: 'var(--crk-color-bg-muted)',
37
35
  border: '1px solid var(--crk-color-border-hover)',
38
36
  borderRadius: 'var(--crk-border-radius-md)',
39
- fontSize: 'var(--crk-font-size-sm)',
40
- lineHeight: 1.6,
41
37
  }}
42
38
  >
43
- <code className={language ? `language-${language}` : undefined}>{code}</code>
44
- </pre>
39
+ {children}
40
+ </div>
45
41
  {/* Solid layer under the (transparent-at-rest) button — see note above. */}
46
42
  <div
47
43
  style={{
@@ -52,17 +48,25 @@ export function CodeSnippet({ code, language }: CodeSnippetProps) {
52
48
  borderRadius: 'var(--crk-border-radius-md)',
53
49
  }}
54
50
  >
55
- <CopyButton value={code} variant="secondary" iconOnly aria-label="Copy code" />
51
+ <CopyButton value={text} variant="secondary" iconOnly aria-label="Copy" />
56
52
  </div>
57
53
  </div>
58
54
  );
59
55
  }
60
56
 
61
57
  export function Example() {
58
+ const url = 'https://example.com/invite/8f3a-ab12';
62
59
  return (
63
- <CodeSnippet
64
- language="bash"
65
- code={'npm install @overdoser/react-toolkit\n# then import the theme once:\n# import "@overdoser/react-toolkit/theme.css"'}
66
- />
60
+ <>
61
+ <CopyableBox text={url}>
62
+ Share this link: <strong>{url}</strong>
63
+ </CopyableBox>
64
+
65
+ {/* Code goes through CodeBlock instead. */}
66
+ <CodeBlock
67
+ language="bash"
68
+ code={'npm install @overdoser/react-toolkit\n# then import the theme once:\n# import "@overdoser/react-toolkit/theme.css"'}
69
+ />
70
+ </>
67
71
  );
68
72
  }
@@ -0,0 +1,21 @@
1
+ export interface FormatBytesOptions {
2
+ /** Fraction digits. @default 1 */
3
+ decimals?: number;
4
+ /** `1024` for binary (KiB-style steps labelled KB), `1000` for decimal. @default 1024 */
5
+ base?: 1000 | 1024;
6
+ /** Use IEC unit labels (KiB, MiB) when `base` is 1024. @default false */
7
+ iec?: boolean;
8
+ /** Locale for number formatting; `undefined` = runtime default. */
9
+ locale?: string;
10
+ }
11
+ /**
12
+ * Human-readable byte count: `formatBytes(1536)` → `"1.5 KB"`.
13
+ * Whole bytes never get decimals (`"512 B"`). Negative values keep their sign.
14
+ *
15
+ * @example
16
+ * formatBytes(0) // "0 B"
17
+ * formatBytes(1_048_576) // "1.0 MB"
18
+ * formatBytes(1_500_000, { base: 1000 }) // "1.5 MB"
19
+ * formatBytes(2048, { iec: true }) // "2.0 KiB"
20
+ */
21
+ export declare function formatBytes(bytes: number, options?: FormatBytesOptions): string;
@@ -0,0 +1,14 @@
1
+ const u = ["B", "KB", "MB", "GB", "TB", "PB", "EB"], g = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
2
+ function f(t, B = {}) {
3
+ const { decimals: c = 1, base: n = 1024, iec: a = !1, locale: m } = B;
4
+ if (!Number.isFinite(t)) return "—";
5
+ const e = n === 1024 && a ? g : u, r = t < 0 ? "-" : "";
6
+ let s = Math.abs(t), i = 0;
7
+ for (; s >= n && i < e.length - 1; )
8
+ s /= n, i++;
9
+ const o = i === 0 ? 0 : Math.max(0, c), l = s.toLocaleString(m, { minimumFractionDigits: o, maximumFractionDigits: o });
10
+ return `${r}${l} ${e[i]}`;
11
+ }
12
+ export {
13
+ f as formatBytes
14
+ };
@@ -0,0 +1,6 @@
1
+ export { formatBytes } from './formatBytes';
2
+ export type { FormatBytesOptions } from './formatBytes';
3
+ export { timeAgo } from './timeAgo';
4
+ export type { TimeAgoOptions, TimeAgoUnit } from './timeAgo';
5
+ export { THEME_INIT_SCRIPT, getThemeInitScript } from './themeScript';
6
+ export type { ThemeInitScriptOptions } from './themeScript';
@@ -0,0 +1,17 @@
1
+ export interface ThemeInitScriptOptions {
2
+ /** localStorage key `useTheme` persists to. @default 'crk-theme' */
3
+ storageKey?: string;
4
+ /** Attribute set on `<html>`. @default 'data-theme' */
5
+ attribute?: string;
6
+ }
7
+ /**
8
+ * Builds the pre-paint theme script: reads the persisted theme and sets the
9
+ * attribute on `<html>` before React renders, so a dark page never flashes
10
+ * light. Inline it in `<head>` (it has no dependencies):
11
+ *
12
+ * @example
13
+ * <script dangerouslySetInnerHTML={{ __html: getThemeInitScript() }} />
14
+ */
15
+ export declare function getThemeInitScript(options?: ThemeInitScriptOptions): string;
16
+ /** `getThemeInitScript()` with the defaults — drop it into `<head>`. */
17
+ export declare const THEME_INIT_SCRIPT: string;
@@ -0,0 +1,9 @@
1
+ function a(t = {}) {
2
+ const e = JSON.stringify(t.storageKey ?? "crk-theme"), r = JSON.stringify(t.attribute ?? "data-theme");
3
+ return "(function(){try{var k=" + e + ",a=" + r + ',d=document.documentElement,v=localStorage.getItem(k);if(v){try{v=JSON.parse(v)}catch(e){}}if(v==="dark"||v==="light"){d.setAttribute(a,v)}else{d.removeAttribute(a)}}catch(e){}})();';
4
+ }
5
+ const c = a();
6
+ export {
7
+ c as THEME_INIT_SCRIPT,
8
+ a as getThemeInitScript
9
+ };
@@ -0,0 +1,33 @@
1
+ export interface TimeAgoOptions {
2
+ /** Reference instant (ms). @default Date.now() */
3
+ now?: number;
4
+ /** BCP 47 locale; `undefined` = runtime default. */
5
+ locale?: string;
6
+ /** `Intl.RelativeTimeFormat` style. @default 'long' */
7
+ format?: 'long' | 'short' | 'narrow';
8
+ /** `'auto'` says "yesterday" / "now"; `'always'` says "1 day ago". @default 'auto' */
9
+ numeric?: 'always' | 'auto';
10
+ /** Beyond this many ms (absolute), return `null` so the caller can show a date instead. */
11
+ maxAge?: number;
12
+ }
13
+ export type TimeAgoUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
14
+ export declare function toTimestamp(value: Date | number | string): number;
15
+ /** Pick the unit and signed count for a delta (ms, positive = future). */
16
+ export declare function relativeParts(deltaMs: number): {
17
+ unit: TimeAgoUnit;
18
+ value: number;
19
+ };
20
+ /** The tick period that keeps a relative label accurate for this delta. */
21
+ export declare function refreshIntervalFor(deltaMs: number): number;
22
+ /**
23
+ * Relative time text via `Intl.RelativeTimeFormat`:
24
+ * `timeAgo(Date.now() - 3 * 60_000)` → `"3 minutes ago"`.
25
+ *
26
+ * Returns `null` when `maxAge` is set and exceeded (show an absolute date).
27
+ *
28
+ * @example
29
+ * timeAgo(past) // "3 minutes ago"
30
+ * timeAgo(future, { format: 'short' }) // "in 2 hr."
31
+ * timeAgo(yesterday, { numeric: 'auto' }) // "yesterday"
32
+ */
33
+ export declare function timeAgo(value: Date | number | string, options?: TimeAgoOptions): string | null;
@@ -0,0 +1,37 @@
1
+ const f = [
2
+ { unit: "year", ms: 31536e6 },
3
+ { unit: "month", ms: 2592e6 },
4
+ { unit: "week", ms: 6048e5 },
5
+ { unit: "day", ms: 864e5 },
6
+ { unit: "hour", ms: 36e5 },
7
+ { unit: "minute", ms: 6e4 },
8
+ { unit: "second", ms: 1e3 }
9
+ ];
10
+ function l(t) {
11
+ return t instanceof Date ? t.getTime() : typeof t == "number" ? t : new Date(t).getTime();
12
+ }
13
+ function h(t) {
14
+ const e = Math.abs(t);
15
+ for (const n of f)
16
+ if (e >= n.ms || n.unit === "second")
17
+ return { unit: n.unit, value: Math.sign(t) * Math.round(e / n.ms) };
18
+ return { unit: "second", value: 0 };
19
+ }
20
+ function b(t) {
21
+ const e = Math.abs(t);
22
+ return e < 6e4 ? 1e3 : e < 36e5 ? 3e4 : 6e4;
23
+ }
24
+ function d(t, e = {}) {
25
+ const { now: n = Date.now(), locale: r, format: i = "long", numeric: o = "auto", maxAge: u } = e, s = l(t);
26
+ if (!Number.isFinite(s)) return null;
27
+ const a = s - n;
28
+ if (u !== void 0 && Math.abs(a) > u) return null;
29
+ const { unit: m, value: c } = h(a);
30
+ return m === "second" && Math.abs(c) < 5 && o === "auto" ? new Intl.RelativeTimeFormat(r, { style: i, numeric: "auto" }).format(0, "second") : new Intl.RelativeTimeFormat(r, { style: i, numeric: o }).format(c, m);
31
+ }
32
+ export {
33
+ b as refreshIntervalFor,
34
+ h as relativeParts,
35
+ d as timeAgo,
36
+ l as toTimestamp
37
+ };