@nextlyhq/ui 0.0.2-alpha.77 → 0.0.2-alpha.79
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/dist/index.cjs +472 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -9
- package/dist/index.d.ts +61 -9
- package/dist/index.mjs +473 -68
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,7 @@ function cn(...inputs) {
|
|
|
93
93
|
* - destructive: Destructive action button (red background)
|
|
94
94
|
* - outline: Outlined button (transparent background, border)
|
|
95
95
|
* - ghost: Minimal button (transparent, no border)
|
|
96
|
-
* - link: Link-style button (underlined
|
|
96
|
+
* - link: Link-style button (text colour, underlined at rest)
|
|
97
97
|
*
|
|
98
98
|
* Note: 'primary' is a semantic alias for 'default' variant for better code readability
|
|
99
99
|
* @experimental
|
|
@@ -107,7 +107,7 @@ const buttonVariants = (0, class_variance_authority.cva)(`inline-flex items-cent
|
|
|
107
107
|
outline: "border border-border text-foreground hover-unified bg-background",
|
|
108
108
|
secondary: "bg-background border border-border text-foreground hover:bg-primary/5",
|
|
109
109
|
ghost: "text-foreground border border-transparent hover-unified",
|
|
110
|
-
link: "text-
|
|
110
|
+
link: "text-foreground border border-transparent underline underline-offset-4 hover:decoration-2"
|
|
111
111
|
},
|
|
112
112
|
size: {
|
|
113
113
|
default: "h-[var(--nx-control-height)] px-6 py-2",
|
|
@@ -1863,7 +1863,9 @@ AlertDialogCancel.displayName = _radix_ui_react_alert_dialog.Cancel.displayName;
|
|
|
1863
1863
|
* **Accessibility**:
|
|
1864
1864
|
* - Full keyboard navigation (Arrow keys, Enter, Escape, Tab)
|
|
1865
1865
|
* - ARIA roles and attributes (menu, menuitem, menuitemcheckbox, menuitemradio)
|
|
1866
|
-
* - Focus management (focus
|
|
1866
|
+
* - Focus management (auto-focus first item, focus back to the trigger)
|
|
1867
|
+
* - Not modal by default: the page around an open menu stays in reach and
|
|
1868
|
+
* in the accessibility tree; pass `modal` for a menu that must hold it
|
|
1867
1869
|
* - Screen reader support (labels, descriptions, indicators)
|
|
1868
1870
|
* - WCAG 2.2 Level AA compliant
|
|
1869
1871
|
*
|
|
@@ -1939,8 +1941,24 @@ AlertDialogCancel.displayName = _radix_ui_react_alert_dialog.Cancel.displayName;
|
|
|
1939
1941
|
*
|
|
1940
1942
|
* @see https://www.radix-ui.com/docs/primitives/components/dropdown-menu - Radix UI DropdownMenu
|
|
1941
1943
|
*/
|
|
1942
|
-
/**
|
|
1943
|
-
|
|
1944
|
+
/**
|
|
1945
|
+
* The menu's root: Radix's, not modal unless a caller asks.
|
|
1946
|
+
*
|
|
1947
|
+
* A menu is a list of choices, not a dialog. A modal one marks everything
|
|
1948
|
+
* around it `aria-hidden` while those controls stay focusable, which hides
|
|
1949
|
+
* the page from a screen reader without taking it out of reach (axe:
|
|
1950
|
+
* `aria-hidden-focus`). Not modal, the menu still closes on Escape, on Tab
|
|
1951
|
+
* and on a press outside, and gives focus back to its trigger; the press
|
|
1952
|
+
* outside also reaches what it was on, and the page can scroll while the
|
|
1953
|
+
* menu is open. A menu that must hold the page still passes `modal`.
|
|
1954
|
+
*
|
|
1955
|
+
* @public
|
|
1956
|
+
*/
|
|
1957
|
+
const DropdownMenu = ({ modal = false, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Root, {
|
|
1958
|
+
modal,
|
|
1959
|
+
...props
|
|
1960
|
+
});
|
|
1961
|
+
DropdownMenu.displayName = "DropdownMenu";
|
|
1944
1962
|
/** @public */
|
|
1945
1963
|
const DropdownMenuTrigger = _radix_ui_react_dropdown_menu.Trigger;
|
|
1946
1964
|
/** @experimental */
|
|
@@ -2368,6 +2386,53 @@ function SheetDragHandle({ onDismiss }) {
|
|
|
2368
2386
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "h-1 w-10 rounded-full bg-border" })
|
|
2369
2387
|
});
|
|
2370
2388
|
}
|
|
2389
|
+
/** What the keyboard can reach by Tab: enabled, not hidden, and in the tab order. */
|
|
2390
|
+
const TABBABLE = "a[href], area[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex], [contenteditable=\"true\"]";
|
|
2391
|
+
/**
|
|
2392
|
+
* Whether an element is drawn: neither it nor a container it sits in is `display: none` or
|
|
2393
|
+
* `visibility: hidden`. One that is not is no stop for the keyboard, and no edge of a sheet.
|
|
2394
|
+
*/
|
|
2395
|
+
function isRendered(element) {
|
|
2396
|
+
for (let node = element; node !== null; node = node.parentElement) {
|
|
2397
|
+
const style = getComputedStyle(node);
|
|
2398
|
+
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
2399
|
+
}
|
|
2400
|
+
return true;
|
|
2401
|
+
}
|
|
2402
|
+
function tabbablesIn(root) {
|
|
2403
|
+
return Array.from(root.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 && !element.hidden && !element.matches(":disabled") && !element.hasAttribute("data-radix-focus-guard") && element.closest("[aria-hidden=\"true\"], [inert]") === null && isRendered(element));
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Tab at a non-modal sheet's edge, moved out of it as for any other part of the page.
|
|
2407
|
+
*
|
|
2408
|
+
* Radix's dialog keeps its focus scope looping even when it is not modal, so Tab from the
|
|
2409
|
+
* sheet's last control would go round to its first, and Shift+Tab from its first to its last:
|
|
2410
|
+
* a keyboard reader could not get from the sheet back to the page beside it. At those two edges
|
|
2411
|
+
* this sends focus where the browser would: forward to the nearest control after the sheet in
|
|
2412
|
+
* the document, back to the nearest before it. Anywhere else, Tab is left to the browser.
|
|
2413
|
+
* Runs before the focus scope's own handler on the same element, which then finds focus already
|
|
2414
|
+
* outside and does nothing.
|
|
2415
|
+
*/
|
|
2416
|
+
function leaveNonModalAtEdge(event) {
|
|
2417
|
+
if (event.defaultPrevented) return;
|
|
2418
|
+
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
2419
|
+
const sheet = event.currentTarget;
|
|
2420
|
+
const inside = tabbablesIn(sheet);
|
|
2421
|
+
if (document.activeElement === sheet && inside.length > 0) {
|
|
2422
|
+
event.preventDefault();
|
|
2423
|
+
(event.shiftKey ? inside[inside.length - 1] : inside[0])?.focus();
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
const edge = event.shiftKey ? inside[0] : inside[inside.length - 1];
|
|
2427
|
+
if (!(document.activeElement === sheet || edge !== void 0 && document.activeElement === edge)) return;
|
|
2428
|
+
const page = tabbablesIn(sheet.ownerDocument.body).filter((element) => !sheet.contains(element));
|
|
2429
|
+
const before = page.filter((element) => (sheet.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING) !== 0);
|
|
2430
|
+
const after = page.filter((element) => !before.includes(element));
|
|
2431
|
+
const next = event.shiftKey ? before[before.length - 1] ?? page[page.length - 1] : after[0] ?? page[0];
|
|
2432
|
+
if (next === void 0) return;
|
|
2433
|
+
event.preventDefault();
|
|
2434
|
+
next.focus();
|
|
2435
|
+
}
|
|
2371
2436
|
/**
|
|
2372
2437
|
* SheetContent
|
|
2373
2438
|
*
|
|
@@ -2382,7 +2447,7 @@ function SheetDragHandle({ onDismiss }) {
|
|
|
2382
2447
|
* @param side - Which edge to slide in from: "left", "right", "top", "bottom"
|
|
2383
2448
|
* @public
|
|
2384
2449
|
*/
|
|
2385
|
-
const SheetContent = react.forwardRef(({ side = "right", className, children, dragHandle = false, ...props }, ref) => {
|
|
2450
|
+
const SheetContent = react.forwardRef(({ side = "right", className, children, dragHandle = false, onKeyDown, ...props }, ref) => {
|
|
2386
2451
|
const portalContainer = usePortalContainer();
|
|
2387
2452
|
const modal = react.useContext(SheetModalContext);
|
|
2388
2453
|
const close = react.useRef(null);
|
|
@@ -2394,6 +2459,10 @@ const SheetContent = react.forwardRef(({ side = "right", className, children, dr
|
|
|
2394
2459
|
"data-slot": "sheet-content",
|
|
2395
2460
|
className: cn(sheetVariants({ side }), className),
|
|
2396
2461
|
...props,
|
|
2462
|
+
onKeyDown: (event) => {
|
|
2463
|
+
onKeyDown?.(event);
|
|
2464
|
+
if (!modal) leaveNonModalAtEdge(event);
|
|
2465
|
+
},
|
|
2397
2466
|
children: [draggable ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetDragHandle, { onDismiss: () => close.current?.click() }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Close, {
|
|
2398
2467
|
ref: close,
|
|
2399
2468
|
hidden: true,
|
|
@@ -2514,21 +2583,32 @@ CommandDialogOverlay.displayName = "CommandDialogOverlay";
|
|
|
2514
2583
|
* ```
|
|
2515
2584
|
* @experimental
|
|
2516
2585
|
*/
|
|
2517
|
-
const CommandDialog = ({ children, commandProps, contentProps, ...props }) => {
|
|
2586
|
+
const CommandDialog = ({ children, title = "Command palette", description, commandProps, contentProps, ...props }) => {
|
|
2518
2587
|
const portalContainer = usePortalContainer();
|
|
2519
2588
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Root, {
|
|
2520
2589
|
...props,
|
|
2521
2590
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Portal, {
|
|
2522
2591
|
container: portalContainer,
|
|
2523
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CommandDialogOverlay, {}), /* @__PURE__ */ (0, react_jsx_runtime.
|
|
2592
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CommandDialogOverlay, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Content, {
|
|
2593
|
+
...description === void 0 ? { "aria-describedby": void 0 } : {},
|
|
2524
2594
|
...contentProps,
|
|
2525
2595
|
"data-slot": "command-content",
|
|
2526
2596
|
className: cn("fixed left-[50%] top-[13vh] z-[100] translate-x-[-50%]", "w-full max-w-lg", "max-h-[80vh]", "sm:max-w-lg", "max-w-full", "m-4 sm:m-0", "overflow-hidden rounded-lg border border-border bg-background shadow-xl", "duration-200", "data-[state=open]:animate-in data-[state=closed]:animate-out", "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95", "data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2"),
|
|
2527
|
-
children:
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2597
|
+
children: [
|
|
2598
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Title, {
|
|
2599
|
+
className: "sr-only",
|
|
2600
|
+
children: title
|
|
2601
|
+
}),
|
|
2602
|
+
description === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Description, {
|
|
2603
|
+
className: "sr-only",
|
|
2604
|
+
children: description
|
|
2605
|
+
}),
|
|
2606
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Command, {
|
|
2607
|
+
...commandProps,
|
|
2608
|
+
className: cn("[&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:mb-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4", commandProps?.className),
|
|
2609
|
+
children
|
|
2610
|
+
})
|
|
2611
|
+
]
|
|
2532
2612
|
})]
|
|
2533
2613
|
})
|
|
2534
2614
|
});
|
|
@@ -2548,27 +2628,77 @@ const CommandInput = (0, react.forwardRef)(({ className, ...props }, ref) => /*
|
|
|
2548
2628
|
})]
|
|
2549
2629
|
}));
|
|
2550
2630
|
CommandInput.displayName = "CommandInput";
|
|
2631
|
+
const EmptyNoticeContext = (0, react.createContext)(null);
|
|
2632
|
+
/** Says `notice` from the list's status line while it is mounted. */
|
|
2633
|
+
function SayEmpty({ say, notice }) {
|
|
2634
|
+
(0, react.useEffect)(() => {
|
|
2635
|
+
say(() => notice);
|
|
2636
|
+
return () => say(null);
|
|
2637
|
+
}, [say, notice]);
|
|
2638
|
+
return null;
|
|
2639
|
+
}
|
|
2551
2640
|
/**
|
|
2552
2641
|
* CommandList - Scrollable container for command results.
|
|
2553
2642
|
* Max height 400px per design spec to prevent tall dialogs.
|
|
2554
2643
|
* @experimental
|
|
2555
2644
|
*/
|
|
2556
|
-
const CommandList = (0, react.forwardRef)(({ className, ...props }, ref) =>
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2645
|
+
const CommandList = (0, react.forwardRef)(({ className, children, ...props }, ref) => {
|
|
2646
|
+
const [emptyHeld, holdEmpty] = (0, react.useState)(0);
|
|
2647
|
+
const [emptyNotice, setEmptyNotice] = (0, react.useState)(null);
|
|
2648
|
+
const notice = (0, react.useMemo)(() => ({
|
|
2649
|
+
hold: holdEmpty,
|
|
2650
|
+
say: setEmptyNotice
|
|
2651
|
+
}), []);
|
|
2652
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(cmdk.Command.List, {
|
|
2653
|
+
ref,
|
|
2654
|
+
className: cn("max-h-[400px] overflow-y-auto overflow-x-hidden", "p-2", className),
|
|
2655
|
+
...props,
|
|
2656
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EmptyNoticeContext.Provider, {
|
|
2657
|
+
value: notice,
|
|
2658
|
+
children
|
|
2659
|
+
})
|
|
2660
|
+
}), emptyHeld > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2661
|
+
role: "status",
|
|
2662
|
+
"data-slot": "command-empty-status",
|
|
2663
|
+
className: "sr-only",
|
|
2664
|
+
children: emptyNotice
|
|
2665
|
+
}) : null] });
|
|
2666
|
+
});
|
|
2561
2667
|
CommandList.displayName = "CommandList";
|
|
2562
2668
|
/**
|
|
2563
2669
|
* CommandEmpty - Empty state message when no results found.
|
|
2564
2670
|
* Centered text with muted color per design spec.
|
|
2671
|
+
*
|
|
2672
|
+
* A message of plain text inside a `CommandList` is drawn in the list but hidden from screen
|
|
2673
|
+
* readers, and the list says it from its own status line outside the list. The list is a
|
|
2674
|
+
* `listbox`, which may own only options and their groups: the library gives the message
|
|
2675
|
+
* `role="presentation"`, set after the props it is given, so the list would own its words, and
|
|
2676
|
+
* axe-core's `aria-required-children` fails a list a search found nothing in. A message holding
|
|
2677
|
+
* anything else, a "Try again" button say, stays where it is, so what it holds can still be
|
|
2678
|
+
* reached; so does one outside a list.
|
|
2565
2679
|
* @experimental
|
|
2566
2680
|
*/
|
|
2567
|
-
const CommandEmpty = (0, react.forwardRef)((
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2681
|
+
const CommandEmpty = (0, react.forwardRef)(({ children, "aria-hidden": ariaHidden, ...props }, ref) => {
|
|
2682
|
+
const notice = (0, react.useContext)(EmptyNoticeContext);
|
|
2683
|
+
const words = typeof children === "string" || typeof children === "number" ? String(children) : null;
|
|
2684
|
+
const sayer = words === null ? void 0 : notice?.say;
|
|
2685
|
+
const hold = sayer === void 0 ? void 0 : notice?.hold;
|
|
2686
|
+
(0, react.useEffect)(() => {
|
|
2687
|
+
if (hold === void 0) return void 0;
|
|
2688
|
+
hold((count) => count + 1);
|
|
2689
|
+
return () => hold((count) => count - 1);
|
|
2690
|
+
}, [hold]);
|
|
2691
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(cmdk.Command.Empty, {
|
|
2692
|
+
ref,
|
|
2693
|
+
className: "py-8 px-4 text-center text-sm text-muted-foreground",
|
|
2694
|
+
"aria-hidden": ariaHidden ?? (sayer === void 0 ? void 0 : true),
|
|
2695
|
+
...props,
|
|
2696
|
+
children: [children, sayer === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SayEmpty, {
|
|
2697
|
+
say: sayer,
|
|
2698
|
+
notice: words
|
|
2699
|
+
})]
|
|
2700
|
+
});
|
|
2701
|
+
});
|
|
2572
2702
|
CommandEmpty.displayName = "CommandEmpty";
|
|
2573
2703
|
/**
|
|
2574
2704
|
* CommandGroup - Grouped section of commands with optional heading.
|
|
@@ -2583,12 +2713,20 @@ const CommandGroup = (0, react.forwardRef)(({ className, ...props }, ref) => /*
|
|
|
2583
2713
|
CommandGroup.displayName = "CommandGroup";
|
|
2584
2714
|
/**
|
|
2585
2715
|
* CommandSeparator - Visual divider between command groups.
|
|
2586
|
-
* 1px line
|
|
2716
|
+
* 1px line in the border colour, 8px margin top/bottom.
|
|
2717
|
+
*
|
|
2718
|
+
* Hidden from screen readers by default. It usually sits inside the list, which is a `listbox`,
|
|
2719
|
+
* and a listbox may own only options and their groups: the library's separator sets
|
|
2720
|
+
* `role="separator"` after the props it is given, so the role cannot be swapped out, and a
|
|
2721
|
+
* screen reader meeting it there finds a child the list should not have (axe-core's
|
|
2722
|
+
* `aria-required-children`). Groups already carry their own headings, so the line adds nothing
|
|
2723
|
+
* to what is announced. Placed outside the list, pass `aria-hidden={false}` to announce it.
|
|
2587
2724
|
* @experimental
|
|
2588
2725
|
*/
|
|
2589
|
-
const CommandSeparator = (0, react.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(cmdk.Command.Separator, {
|
|
2726
|
+
const CommandSeparator = (0, react.forwardRef)(({ className, "aria-hidden": ariaHidden = true, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(cmdk.Command.Separator, {
|
|
2590
2727
|
ref,
|
|
2591
2728
|
className: cn("h-px bg-border my-2", className),
|
|
2729
|
+
"aria-hidden": ariaHidden,
|
|
2592
2730
|
...props
|
|
2593
2731
|
}));
|
|
2594
2732
|
CommandSeparator.displayName = "CommandSeparator";
|
|
@@ -3076,7 +3214,7 @@ const TableSkeleton = ({ columns = 5, rowCount = 8, hideWrapper = false, hideFoo
|
|
|
3076
3214
|
};
|
|
3077
3215
|
TableSkeleton.displayName = "TableSkeleton";
|
|
3078
3216
|
// src/lib/color/convert.ts
|
|
3079
|
-
const clamp01$
|
|
3217
|
+
const clamp01$3 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3080
3218
|
/**
|
|
3081
3219
|
* Wrap a hue into [0, 360), so -30 and 330 are the same angle.
|
|
3082
3220
|
*
|
|
@@ -3096,8 +3234,8 @@ function normalizeHue(hue) {
|
|
|
3096
3234
|
*/
|
|
3097
3235
|
function hsvToRgb({ h, s, v }) {
|
|
3098
3236
|
const hue = normalizeHue(h);
|
|
3099
|
-
const sat = clamp01$
|
|
3100
|
-
const val = clamp01$
|
|
3237
|
+
const sat = clamp01$3(s);
|
|
3238
|
+
const val = clamp01$3(v);
|
|
3101
3239
|
const sector = hue / 60;
|
|
3102
3240
|
const chroma = val * sat;
|
|
3103
3241
|
const x = chroma * (1 - Math.abs(sector % 2 - 1));
|
|
@@ -3149,9 +3287,9 @@ function hsvToRgb({ h, s, v }) {
|
|
|
3149
3287
|
* @experimental
|
|
3150
3288
|
*/
|
|
3151
3289
|
function rgbToHsv({ r, g, b }) {
|
|
3152
|
-
const red = clamp01$
|
|
3153
|
-
const green = clamp01$
|
|
3154
|
-
const blue = clamp01$
|
|
3290
|
+
const red = clamp01$3(r);
|
|
3291
|
+
const green = clamp01$3(g);
|
|
3292
|
+
const blue = clamp01$3(b);
|
|
3155
3293
|
const max = Math.max(red, green, blue);
|
|
3156
3294
|
const chroma = max - Math.min(red, green, blue);
|
|
3157
3295
|
let hue = 0;
|
|
@@ -3170,10 +3308,10 @@ function rgbToHsv({ r, g, b }) {
|
|
|
3170
3308
|
// src/lib/color/hex.ts
|
|
3171
3309
|
/** `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, with the hash optional and case ignored. */
|
|
3172
3310
|
const HEX = /^#?(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
3173
|
-
const clamp01$
|
|
3311
|
+
const clamp01$2 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3174
3312
|
/** A channel byte as a two-digit lowercase pair. */
|
|
3175
3313
|
function pair(channel) {
|
|
3176
|
-
const value = Number.isFinite(channel) ? clamp01$
|
|
3314
|
+
const value = Number.isFinite(channel) ? clamp01$2(channel) : 0;
|
|
3177
3315
|
return Math.round(value * 255).toString(16).padStart(2, "0");
|
|
3178
3316
|
}
|
|
3179
3317
|
/**
|
|
@@ -3223,12 +3361,12 @@ function parseHex(input) {
|
|
|
3223
3361
|
* @experimental
|
|
3224
3362
|
*/
|
|
3225
3363
|
function toHex(color, alpha = 1) {
|
|
3226
|
-
const opacity = Number.isFinite(alpha) ? clamp01$
|
|
3364
|
+
const opacity = Number.isFinite(alpha) ? clamp01$2(alpha) : 1;
|
|
3227
3365
|
const opaque = `#${pair(color.r)}${pair(color.g)}${pair(color.b)}`;
|
|
3228
3366
|
return opacity === 1 ? opaque : `${opaque}${pair(opacity)}`;
|
|
3229
3367
|
}
|
|
3230
3368
|
// src/lib/color/picker-geometry.ts
|
|
3231
|
-
const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3369
|
+
const clamp01$1 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3232
3370
|
/**
|
|
3233
3371
|
* A pointer position as a fraction of a surface.
|
|
3234
3372
|
*
|
|
@@ -3244,8 +3382,8 @@ const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
|
3244
3382
|
*/
|
|
3245
3383
|
function pointOnSurface(clientX, clientY, rect) {
|
|
3246
3384
|
return {
|
|
3247
|
-
x: rect.width === 0 ? 0 : clamp01((clientX - rect.left) / rect.width),
|
|
3248
|
-
y: rect.height === 0 ? 0 : clamp01((clientY - rect.top) / rect.height)
|
|
3385
|
+
x: rect.width === 0 ? 0 : clamp01$1((clientX - rect.left) / rect.width),
|
|
3386
|
+
y: rect.height === 0 ? 0 : clamp01$1((clientY - rect.top) / rect.height)
|
|
3249
3387
|
};
|
|
3250
3388
|
}
|
|
3251
3389
|
/**
|
|
@@ -3259,8 +3397,8 @@ function pointOnSurface(clientX, clientY, rect) {
|
|
|
3259
3397
|
*/
|
|
3260
3398
|
function saturationValueAt(point) {
|
|
3261
3399
|
return {
|
|
3262
|
-
s: clamp01(point.x),
|
|
3263
|
-
v: 1 - clamp01(point.y)
|
|
3400
|
+
s: clamp01$1(point.x),
|
|
3401
|
+
v: 1 - clamp01$1(point.y)
|
|
3264
3402
|
};
|
|
3265
3403
|
}
|
|
3266
3404
|
/**
|
|
@@ -3274,8 +3412,8 @@ function saturationValueAt(point) {
|
|
|
3274
3412
|
*/
|
|
3275
3413
|
function surfacePointFor(s, v) {
|
|
3276
3414
|
return {
|
|
3277
|
-
x: clamp01(s),
|
|
3278
|
-
y: 1 - clamp01(v)
|
|
3415
|
+
x: clamp01$1(s),
|
|
3416
|
+
y: 1 - clamp01$1(v)
|
|
3279
3417
|
};
|
|
3280
3418
|
}
|
|
3281
3419
|
/**
|
|
@@ -3287,7 +3425,7 @@ function surfacePointFor(s, v) {
|
|
|
3287
3425
|
* @experimental
|
|
3288
3426
|
*/
|
|
3289
3427
|
function hueAt(fraction) {
|
|
3290
|
-
const hue = clamp01(fraction) * 360;
|
|
3428
|
+
const hue = clamp01$1(fraction) * 360;
|
|
3291
3429
|
return hue >= 360 ? 0 : hue;
|
|
3292
3430
|
}
|
|
3293
3431
|
/** Where the hue handle sits, as a fraction of the strip. @experimental */
|
|
@@ -3310,6 +3448,207 @@ function hueSliderValue(hue, max) {
|
|
|
3310
3448
|
const step = Math.round(huePosition(hue) * (max + 1));
|
|
3311
3449
|
return step > max ? max : step;
|
|
3312
3450
|
}
|
|
3451
|
+
// src/lib/color/formats.ts
|
|
3452
|
+
const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3453
|
+
/** A CSS number, optionally signed, with an optional fraction and exponent. */
|
|
3454
|
+
const NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
3455
|
+
/** A number and the unit written after it: `50%`, `120deg`, `0.5`. */
|
|
3456
|
+
const NUMBER_AND_UNIT = /^(.*?)(%|[a-z]*)$/i;
|
|
3457
|
+
/** One component as written: its number, and the unit after it, if any. */
|
|
3458
|
+
function numberAndUnit(text) {
|
|
3459
|
+
const [, digits = "", unit = ""] = NUMBER_AND_UNIT.exec(text) ?? [];
|
|
3460
|
+
const value = Number(digits);
|
|
3461
|
+
if (!NUMBER.test(digits) || !Number.isFinite(value)) return null;
|
|
3462
|
+
return {
|
|
3463
|
+
value,
|
|
3464
|
+
unit: unit.toLowerCase()
|
|
3465
|
+
};
|
|
3466
|
+
}
|
|
3467
|
+
/** A percentage as [0, 1], or a bare number divided by `whole`. */
|
|
3468
|
+
function fractionOf(text, whole) {
|
|
3469
|
+
if (text === void 0) return null;
|
|
3470
|
+
const part = numberAndUnit(text);
|
|
3471
|
+
if (part === null) return null;
|
|
3472
|
+
if (part.unit === "%") return clamp01(part.value / 100);
|
|
3473
|
+
return part.unit === "" ? clamp01(part.value / whole) : null;
|
|
3474
|
+
}
|
|
3475
|
+
/** Degrees in one of each angle unit CSS takes for a hue. */
|
|
3476
|
+
const DEGREES = {
|
|
3477
|
+
"": 1,
|
|
3478
|
+
deg: 1,
|
|
3479
|
+
grad: 360 / 400,
|
|
3480
|
+
rad: 180 / Math.PI,
|
|
3481
|
+
turn: 360
|
|
3482
|
+
};
|
|
3483
|
+
/** A hue, a bare number of degrees or an angle, as [0, 360). */
|
|
3484
|
+
function hueOf(text) {
|
|
3485
|
+
const part = numberAndUnit(text);
|
|
3486
|
+
const scale = part === null ? void 0 : DEGREES[part.unit];
|
|
3487
|
+
if (part === null || scale === void 0) return null;
|
|
3488
|
+
const degrees = part.value * scale % 360;
|
|
3489
|
+
return degrees < 0 ? degrees + 360 : degrees;
|
|
3490
|
+
}
|
|
3491
|
+
/** Every component separated by commas: `rgb(255, 0, 0, 0.5)`. */
|
|
3492
|
+
function commaComponents(body) {
|
|
3493
|
+
if (body.includes("/")) return null;
|
|
3494
|
+
const parts = body.split(",").map((part) => part.trim());
|
|
3495
|
+
if (parts.length !== 3 && parts.length !== 4) return null;
|
|
3496
|
+
return {
|
|
3497
|
+
channels: parts.slice(0, 3),
|
|
3498
|
+
alpha: parts[3],
|
|
3499
|
+
legacy: true
|
|
3500
|
+
};
|
|
3501
|
+
}
|
|
3502
|
+
/** Channels separated by spaces, the alpha after a slash: `rgb(255 0 0 / 50%)`. */
|
|
3503
|
+
function spaceComponents(body) {
|
|
3504
|
+
const [channelText = "", alpha, extra] = body.split("/");
|
|
3505
|
+
if (extra !== void 0 || alpha?.trim() === "") return null;
|
|
3506
|
+
const channels = channelText.trim().split(/\s+/);
|
|
3507
|
+
return channels.length === 3 ? {
|
|
3508
|
+
channels,
|
|
3509
|
+
alpha: alpha?.trim(),
|
|
3510
|
+
legacy: false
|
|
3511
|
+
} : null;
|
|
3512
|
+
}
|
|
3513
|
+
/**
|
|
3514
|
+
* The components of a colour function, or `null` when its punctuation is
|
|
3515
|
+
* neither of the two grammars CSS has. The two are never mixed: `rgb(0 0 0
|
|
3516
|
+
* 0.5)` and `rgb(0, 0, 0 / 1)` are no colour to a browser, so none here.
|
|
3517
|
+
*/
|
|
3518
|
+
function componentsOf(body) {
|
|
3519
|
+
return body.includes(",") ? commaComponents(body) : spaceComponents(body);
|
|
3520
|
+
}
|
|
3521
|
+
/** A colour function, as its name and the text between its brackets. */
|
|
3522
|
+
const FUNCTION = /^(rgba?|hsla?)\(\s*([^()]*?)\s*\)$/i;
|
|
3523
|
+
const isPercent = (text) => text?.endsWith("%") === true;
|
|
3524
|
+
/**
|
|
3525
|
+
* Whether the comma syntax's stricter channels hold: `rgb()` takes three
|
|
3526
|
+
* numbers or three percentages, never a mix, and `hsl()` takes its
|
|
3527
|
+
* saturation and lightness as percentages. A browser drops anything else.
|
|
3528
|
+
*/
|
|
3529
|
+
function legacyChannelsHold(rgb, [first, ...rest]) {
|
|
3530
|
+
if (!rgb) return rest.every(isPercent);
|
|
3531
|
+
return rest.every((channel) => isPercent(channel) === isPercent(first));
|
|
3532
|
+
}
|
|
3533
|
+
function readRgb([r, g, b], alpha) {
|
|
3534
|
+
const red = fractionOf(r, 255);
|
|
3535
|
+
const green = fractionOf(g, 255);
|
|
3536
|
+
const blue = fractionOf(b, 255);
|
|
3537
|
+
if (red === null || green === null || blue === null) return null;
|
|
3538
|
+
return {
|
|
3539
|
+
r: red,
|
|
3540
|
+
g: green,
|
|
3541
|
+
b: blue,
|
|
3542
|
+
alpha
|
|
3543
|
+
};
|
|
3544
|
+
}
|
|
3545
|
+
function readHsl([hue = "", sat, light], alpha) {
|
|
3546
|
+
const h = hueOf(hue);
|
|
3547
|
+
const s = fractionOf(sat, 100);
|
|
3548
|
+
const l = fractionOf(light, 100);
|
|
3549
|
+
if (h === null || s === null || l === null) return null;
|
|
3550
|
+
return {
|
|
3551
|
+
...hslToRgb({
|
|
3552
|
+
h,
|
|
3553
|
+
s,
|
|
3554
|
+
l
|
|
3555
|
+
}),
|
|
3556
|
+
alpha
|
|
3557
|
+
};
|
|
3558
|
+
}
|
|
3559
|
+
/** `rgb()`, `rgba()`, `hsl()` or `hsla()`, or `null` for anything else. */
|
|
3560
|
+
function parseFunction(text) {
|
|
3561
|
+
const [, name = "", body = ""] = FUNCTION.exec(text) ?? [];
|
|
3562
|
+
const parts = name === "" ? null : componentsOf(body);
|
|
3563
|
+
if (parts === null) return null;
|
|
3564
|
+
const rgb = name.toLowerCase().startsWith("rgb");
|
|
3565
|
+
if (parts.legacy && !legacyChannelsHold(rgb, parts.channels)) return null;
|
|
3566
|
+
const alpha = parts.alpha === void 0 ? 1 : fractionOf(parts.alpha, 1);
|
|
3567
|
+
if (alpha === null) return null;
|
|
3568
|
+
return rgb ? readRgb(parts.channels, alpha) : readHsl(parts.channels, alpha);
|
|
3569
|
+
}
|
|
3570
|
+
/**
|
|
3571
|
+
* Read a colour typed or pasted as hex (3, 4, 6 or 8 digits), `rgb()`/`rgba()`
|
|
3572
|
+
* or `hsl()`/`hsla()`, in either the comma or the space syntax, or `null` if
|
|
3573
|
+
* the text is none of them yet.
|
|
3574
|
+
*
|
|
3575
|
+
* `null` rather than a guess, as `parseHex` answers: a field someone is typing
|
|
3576
|
+
* into holds "not a colour yet" most of the time. Components out of range are
|
|
3577
|
+
* clamped, as a browser clamps them.
|
|
3578
|
+
*
|
|
3579
|
+
* @experimental
|
|
3580
|
+
*/
|
|
3581
|
+
function parseColour(input) {
|
|
3582
|
+
const text = input.trim();
|
|
3583
|
+
return parseHex(text) ?? parseFunction(text);
|
|
3584
|
+
}
|
|
3585
|
+
/** Which sixth of the hue circle a colour sits in, from its largest channel. */
|
|
3586
|
+
function hueSector({ r, g, b }, max, d) {
|
|
3587
|
+
if (max === r) return ((g - b) / d + 6) % 6;
|
|
3588
|
+
if (max === g) return (b - r) / d + 2;
|
|
3589
|
+
return (r - g) / d + 4;
|
|
3590
|
+
}
|
|
3591
|
+
/** sRGB channels in [0, 1] as hue, saturation and lightness. */
|
|
3592
|
+
function rgbToHsl(color) {
|
|
3593
|
+
const max = Math.max(color.r, color.g, color.b);
|
|
3594
|
+
const min = Math.min(color.r, color.g, color.b);
|
|
3595
|
+
const l = (max + min) / 2;
|
|
3596
|
+
const d = max - min;
|
|
3597
|
+
if (d === 0) return {
|
|
3598
|
+
h: 0,
|
|
3599
|
+
s: 0,
|
|
3600
|
+
l
|
|
3601
|
+
};
|
|
3602
|
+
const s = d / (1 - Math.abs(2 * l - 1));
|
|
3603
|
+
return {
|
|
3604
|
+
h: hueSector(color, max, d) * 60,
|
|
3605
|
+
s,
|
|
3606
|
+
l
|
|
3607
|
+
};
|
|
3608
|
+
}
|
|
3609
|
+
/** Hue, saturation and lightness as sRGB channels in [0, 1]. */
|
|
3610
|
+
function hslToRgb({ h, s, l }) {
|
|
3611
|
+
const a = s * Math.min(l, 1 - l);
|
|
3612
|
+
const f = (n) => {
|
|
3613
|
+
const k = (n + h / 30) % 12;
|
|
3614
|
+
return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
|
|
3615
|
+
};
|
|
3616
|
+
return {
|
|
3617
|
+
r: f(0),
|
|
3618
|
+
g: f(8),
|
|
3619
|
+
b: f(4)
|
|
3620
|
+
};
|
|
3621
|
+
}
|
|
3622
|
+
/** ` / 0.5` for a translucent colour, nothing for an opaque one. */
|
|
3623
|
+
function alphaSuffix(alpha) {
|
|
3624
|
+
const opacity = Number.isFinite(alpha) ? clamp01(alpha) : 1;
|
|
3625
|
+
return opacity === 1 ? "" : ` / ${Math.round(opacity * 100) / 100}`;
|
|
3626
|
+
}
|
|
3627
|
+
/** A channel in [0, 1] as the 0-255 `rgb()` writes. */
|
|
3628
|
+
const byte = (channel) => Math.round(clamp01(Number.isFinite(channel) ? channel : 0) * 255);
|
|
3629
|
+
/** A fraction as a whole percentage. */
|
|
3630
|
+
const percent = (fraction) => `${Math.round(fraction * 100)}%`;
|
|
3631
|
+
/** `hsl()` for a colour, read from its bytes so it names what hex would. */
|
|
3632
|
+
function hslText(color, alpha) {
|
|
3633
|
+
const { h, s, l } = rgbToHsl({
|
|
3634
|
+
r: byte(color.r) / 255,
|
|
3635
|
+
g: byte(color.g) / 255,
|
|
3636
|
+
b: byte(color.b) / 255
|
|
3637
|
+
});
|
|
3638
|
+
return `hsl(${Math.round(h) % 360} ${percent(s)} ${percent(l)}${alphaSuffix(alpha)})`;
|
|
3639
|
+
}
|
|
3640
|
+
/**
|
|
3641
|
+
* Write a colour in one of the three notations: hex as `toHex` writes it, and
|
|
3642
|
+
* the functions in the space-separated syntax, with the alpha after a slash
|
|
3643
|
+
* only when the colour is not opaque.
|
|
3644
|
+
*
|
|
3645
|
+
* @experimental
|
|
3646
|
+
*/
|
|
3647
|
+
function formatColour(color, alpha, format) {
|
|
3648
|
+
if (format === "hex") return toHex(color, alpha);
|
|
3649
|
+
if (format === "hsl") return hslText(color, alpha);
|
|
3650
|
+
return `rgb(${byte(color.r)} ${byte(color.g)} ${byte(color.b)}${alphaSuffix(alpha)})`;
|
|
3651
|
+
}
|
|
3313
3652
|
// src/lib/isomorphic-layout-effect.ts
|
|
3314
3653
|
/**
|
|
3315
3654
|
* A layout effect in the browser, a plain effect where there is no DOM.
|
|
@@ -3353,6 +3692,21 @@ function toHsva(hex) {
|
|
|
3353
3692
|
function toHexString(hsva, withAlpha) {
|
|
3354
3693
|
return toHex(hsvToRgb(hsva), withAlpha ? hsva.a : 1);
|
|
3355
3694
|
}
|
|
3695
|
+
/** The notations the field can show, as their buttons name them. */
|
|
3696
|
+
const FORMATS = [
|
|
3697
|
+
{
|
|
3698
|
+
format: "hex",
|
|
3699
|
+
label: "Hex"
|
|
3700
|
+
},
|
|
3701
|
+
{
|
|
3702
|
+
format: "rgb",
|
|
3703
|
+
label: "RGB"
|
|
3704
|
+
},
|
|
3705
|
+
{
|
|
3706
|
+
format: "hsl",
|
|
3707
|
+
label: "HSL"
|
|
3708
|
+
}
|
|
3709
|
+
];
|
|
3356
3710
|
/** The last step of the hue strip. Kept beside the input it sizes. */
|
|
3357
3711
|
const HUE_MAX = 359;
|
|
3358
3712
|
/**
|
|
@@ -3408,8 +3762,10 @@ function isNode(value) {
|
|
|
3408
3762
|
return value !== null && typeof value.nodeType === "number";
|
|
3409
3763
|
}
|
|
3410
3764
|
/**
|
|
3411
|
-
* A colour control: a saturation square, a hue strip, optional alpha, a
|
|
3412
|
-
*
|
|
3765
|
+
* A colour control: a saturation square, a hue strip, optional alpha, a field
|
|
3766
|
+
* that reads hex, `rgb()` or `hsl()` and shows whichever of the three the
|
|
3767
|
+
* author picks, the screen's eyedropper where the browser has one, and any
|
|
3768
|
+
* presets and recent colours the host supplies. What it reports is hex.
|
|
3413
3769
|
*
|
|
3414
3770
|
* Deliberately knows nothing about design tokens. A swatch carries an opaque
|
|
3415
3771
|
* `value` this component never reads and hands back untouched, so a host can
|
|
@@ -3429,8 +3785,9 @@ function isNode(value) {
|
|
|
3429
3785
|
* />
|
|
3430
3786
|
* ```
|
|
3431
3787
|
*/
|
|
3432
|
-
function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, recentColors
|
|
3788
|
+
function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, recentColors, onRecentSelect, showAlpha = false, className }) {
|
|
3433
3789
|
const fieldId = react.useId();
|
|
3790
|
+
const [format, setFormat] = react.useState("hex");
|
|
3434
3791
|
/** The picker's own subtree, for telling a press inside it from a dismissal. */
|
|
3435
3792
|
const rootRef = react.useRef(null);
|
|
3436
3793
|
/**
|
|
@@ -3462,6 +3819,7 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3462
3819
|
const [draftHex, setDraftHex] = react.useState(null);
|
|
3463
3820
|
const draftRef = react.useRef(null);
|
|
3464
3821
|
const rendered = toHexString(hsva, showAlpha);
|
|
3822
|
+
const shownText = formatColour(hsvToRgb(hsva), showAlpha ? hsva.a : 1, format);
|
|
3465
3823
|
useIsomorphicLayoutEffect(() => {
|
|
3466
3824
|
const incoming = parseHex(color);
|
|
3467
3825
|
if (incoming && toHex(incoming, showAlpha ? incoming.alpha : 1) !== rendered) {
|
|
@@ -3484,7 +3842,8 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3484
3842
|
draftRef.current = null;
|
|
3485
3843
|
if (text === null) return;
|
|
3486
3844
|
setDraftHex(null);
|
|
3487
|
-
|
|
3845
|
+
if (text.trim() === shownText) return;
|
|
3846
|
+
const parsed = parseColour(text);
|
|
3488
3847
|
if (!parsed) return;
|
|
3489
3848
|
setHsva((prev) => hsvaFrom(parsed, parsed.alpha, prev.h));
|
|
3490
3849
|
onColorChange(toHex(parsed, showAlpha ? parsed.alpha : 1));
|
|
@@ -3586,6 +3945,20 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3586
3945
|
s: 1,
|
|
3587
3946
|
v: 1
|
|
3588
3947
|
}));
|
|
3948
|
+
const formatLabel = FORMATS.find((entry) => entry.format === format)?.label ?? "Hex";
|
|
3949
|
+
const chooseFormat = (next) => {
|
|
3950
|
+
commitDraft();
|
|
3951
|
+
setFormat(next);
|
|
3952
|
+
};
|
|
3953
|
+
const chooseRecent = (recent) => {
|
|
3954
|
+
if (onRecentSelect !== void 0) {
|
|
3955
|
+
dropDraft();
|
|
3956
|
+
onRecentSelect(recent);
|
|
3957
|
+
return;
|
|
3958
|
+
}
|
|
3959
|
+
const parsed = parseColour(recent);
|
|
3960
|
+
if (parsed) commit(hsvaFrom(parsed, parsed.alpha, hsva.h));
|
|
3961
|
+
};
|
|
3589
3962
|
const pickFromScreen = async () => {
|
|
3590
3963
|
const ctor = window.EyeDropper;
|
|
3591
3964
|
if (!ctor) return;
|
|
@@ -3603,7 +3976,7 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3603
3976
|
};
|
|
3604
3977
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3605
3978
|
ref: rootRef,
|
|
3606
|
-
className: cn("w-64 space-y-3", className),
|
|
3979
|
+
className: cn("w-full max-w-64 space-y-3", className),
|
|
3607
3980
|
onBlur: (event) => {
|
|
3608
3981
|
const next = event.relatedTarget;
|
|
3609
3982
|
const root = rootRef.current;
|
|
@@ -3685,18 +4058,32 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3685
4058
|
backgroundSize: "100% 100%, 8px 8px"
|
|
3686
4059
|
}
|
|
3687
4060
|
})] }),
|
|
4061
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4062
|
+
role: "group",
|
|
4063
|
+
"aria-label": "Colour format",
|
|
4064
|
+
className: "bg-muted inline-flex rounded-md p-0.5",
|
|
4065
|
+
children: FORMATS.map((entry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4066
|
+
type: "button",
|
|
4067
|
+
"aria-pressed": entry.format === format,
|
|
4068
|
+
className: cn("text-muted-foreground hover:text-foreground focus-visible:ring-ring min-h-6 min-w-10 rounded px-2 text-xs font-medium focus-visible:ring-2 focus-visible:outline-none", entry.format === format && "bg-background text-foreground shadow-sm"),
|
|
4069
|
+
onClick: () => chooseFormat(entry.format),
|
|
4070
|
+
children: entry.label
|
|
4071
|
+
}, entry.format))
|
|
4072
|
+
}),
|
|
3688
4073
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3689
4074
|
className: "flex items-center gap-2",
|
|
3690
4075
|
children: [
|
|
3691
4076
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
3692
4077
|
className: "sr-only",
|
|
3693
4078
|
htmlFor: `${fieldId}-hex`,
|
|
3694
|
-
children:
|
|
4079
|
+
children: `${formatLabel} colour`
|
|
3695
4080
|
}),
|
|
3696
4081
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Input, {
|
|
3697
4082
|
id: `${fieldId}-hex`,
|
|
3698
4083
|
className: "font-mono",
|
|
3699
|
-
|
|
4084
|
+
spellCheck: false,
|
|
4085
|
+
autoComplete: "off",
|
|
4086
|
+
value: draftHex ?? shownText,
|
|
3700
4087
|
onChange: (event) => {
|
|
3701
4088
|
draftRef.current = event.target.value;
|
|
3702
4089
|
setDraftHex(event.target.value);
|
|
@@ -3712,7 +4099,8 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3712
4099
|
type: "button",
|
|
3713
4100
|
variant: "outline",
|
|
3714
4101
|
size: "icon",
|
|
3715
|
-
"aria-label": "Pick
|
|
4102
|
+
"aria-label": "Pick from screen",
|
|
4103
|
+
title: "Pick from screen",
|
|
3716
4104
|
onClick: () => void pickFromScreen(),
|
|
3717
4105
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Pipette, { className: "size-4" })
|
|
3718
4106
|
})
|
|
@@ -3736,26 +4124,43 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3736
4124
|
}
|
|
3737
4125
|
}, swatch.id))
|
|
3738
4126
|
})] }),
|
|
3739
|
-
recentColors
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
})
|
|
3743
|
-
className: "flex flex-wrap gap-1",
|
|
3744
|
-
children: recentColors.map((recent) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
3745
|
-
type: "button",
|
|
3746
|
-
title: recent,
|
|
3747
|
-
"aria-label": recent,
|
|
3748
|
-
className: "size-6 rounded border shadow-sm",
|
|
3749
|
-
style: { backgroundColor: recent },
|
|
3750
|
-
onClick: () => {
|
|
3751
|
-
const parsed = parseHex(recent);
|
|
3752
|
-
if (parsed) commit(hsvaFrom(parsed, parsed.alpha, hsva.h));
|
|
3753
|
-
}
|
|
3754
|
-
}, recent))
|
|
3755
|
-
})] })
|
|
4127
|
+
recentColors === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RecentColors, {
|
|
4128
|
+
colors: recentColors,
|
|
4129
|
+
onChoose: chooseRecent
|
|
4130
|
+
})
|
|
3756
4131
|
]
|
|
3757
4132
|
});
|
|
3758
4133
|
}
|
|
4134
|
+
/**
|
|
4135
|
+
* The host's recent colours, under their heading, each a swatch named by its
|
|
4136
|
+
* value. Shown while there are none too, saying what will appear there, so
|
|
4137
|
+
* the place is known before it is filled.
|
|
4138
|
+
*/
|
|
4139
|
+
function RecentColors({ colors, onChoose }) {
|
|
4140
|
+
const headingId = react.useId();
|
|
4141
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4142
|
+
role: "group",
|
|
4143
|
+
"aria-labelledby": headingId,
|
|
4144
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4145
|
+
id: headingId,
|
|
4146
|
+
className: "text-muted-foreground mb-1 text-xs",
|
|
4147
|
+
children: "Recent colours"
|
|
4148
|
+
}), colors.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4149
|
+
className: "text-muted-foreground text-xs",
|
|
4150
|
+
children: "Colours you type or pick show here."
|
|
4151
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4152
|
+
className: "flex flex-wrap gap-1",
|
|
4153
|
+
children: colors.map((recent) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4154
|
+
type: "button",
|
|
4155
|
+
title: recent,
|
|
4156
|
+
"aria-label": recent,
|
|
4157
|
+
className: "size-6 rounded border shadow-sm",
|
|
4158
|
+
style: { backgroundColor: recent },
|
|
4159
|
+
onClick: () => onChoose(recent)
|
|
4160
|
+
}, recent))
|
|
4161
|
+
})]
|
|
4162
|
+
});
|
|
4163
|
+
}
|
|
3759
4164
|
// src/components/icon-glyph.tsx
|
|
3760
4165
|
/** The shape elements a body may contain. */
|
|
3761
4166
|
const SHAPES = /* @__PURE__ */ new Set([
|