@carbonid1/design-system 7.3.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ Shared React UI primitives + Tailwind v4 theme presets (`reader`, `dashboard`) +
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- pnpm add @carbonid1/design-system react react-dom @base-ui/react class-variance-authority clsx tailwind-merge lucide-react next-themes react-hotkeys-hook
8
+ pnpm add @carbonid1/design-system
9
9
  ```
10
10
 
11
11
  And Tailwind CSS v4 (with `tw-animate-css` + `shadcn/tailwind.css` if you want matching utilities/base):
@@ -103,7 +103,7 @@ you want the same styled native input through the Field namespace:
103
103
 
104
104
  ## Helpers
105
105
 
106
- - `cn(...inputs)` — `clsx` + `tailwind-merge`
106
+ - `cn(...inputs)` — joins class names and merges conflicting Tailwind classes (built on [`cn`](https://www.npmjs.com/package/cn))
107
107
  - `getModKey()` — returns `'Cmd'` on Mac, `'Ctrl'` elsewhere
108
108
 
109
109
  ## Theming
@@ -1,5 +1,5 @@
1
1
  import { cva } from 'class-variance-authority';
2
- const buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[color,background-color,opacity,transform] outline-hidden select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
2
+ const buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[color,background-color,opacity,translate] outline-hidden select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
3
3
  variants: {
4
4
  variant: {
5
5
  ghost: 'hover:bg-accent aria-expanded:bg-accent dark:hover:bg-accent/50',
@@ -1,56 +1,40 @@
1
1
  import { ContextMenu as BaseContextMenu } from '@base-ui/react/context-menu';
2
- import type { ComponentPropsWithoutRef, Ref } from 'react';
3
- type BasePopupProps = ComponentPropsWithoutRef<typeof BaseContextMenu.Popup>;
4
- type BasePositionerProps = ComponentPropsWithoutRef<typeof BaseContextMenu.Positioner>;
5
- type BaseItemProps = ComponentPropsWithoutRef<typeof BaseContextMenu.Item>;
6
- type BaseSeparatorProps = ComponentPropsWithoutRef<typeof BaseContextMenu.Separator>;
7
- type BaseGroupLabelProps = ComponentPropsWithoutRef<typeof BaseContextMenu.GroupLabel>;
8
- type BaseSubmenuTriggerProps = ComponentPropsWithoutRef<typeof BaseContextMenu.SubmenuTrigger>;
9
- type BaseCheckboxItemProps = ComponentPropsWithoutRef<typeof BaseContextMenu.CheckboxItem>;
10
- type BaseRadioItemProps = ComponentPropsWithoutRef<typeof BaseContextMenu.RadioItem>;
11
- type ItemVariant = 'default' | 'destructive';
12
- type PositionerProps = BasePositionerProps & {
13
- ref?: Ref<HTMLDivElement>;
14
- };
15
- type PopupProps = BasePopupProps & {
16
- ref?: Ref<HTMLDivElement>;
17
- };
18
- type SeparatorProps = BaseSeparatorProps & {
19
- ref?: Ref<HTMLDivElement>;
20
- };
21
- type GroupLabelProps = BaseGroupLabelProps & {
22
- ref?: Ref<HTMLDivElement>;
23
- };
24
- type ItemProps = BaseItemProps & {
25
- ref?: Ref<HTMLDivElement>;
26
- variant?: ItemVariant;
27
- };
28
- type CheckboxItemProps = BaseCheckboxItemProps & {
29
- ref?: Ref<HTMLDivElement>;
30
- };
31
- type RadioItemProps = BaseRadioItemProps & {
32
- ref?: Ref<HTMLDivElement>;
33
- };
34
- type SubmenuTriggerProps = BaseSubmenuTriggerProps & {
35
- ref?: Ref<HTMLDivElement>;
36
- };
2
+ import type { ComponentProps } from 'react';
3
+ import { Menu } from '../Menu/Menu';
37
4
  export declare const ContextMenu: {
38
5
  Root: typeof BaseContextMenu.Root;
39
6
  Trigger: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuTriggerProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
7
+ Popup: ({ className, ...props }: ComponentProps<typeof Menu.Popup>) => import("react/jsx-runtime").JSX.Element;
40
8
  Portal: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuPortalProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
41
9
  Backdrop: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuBackdropProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
42
- Positioner: ({ className, sideOffset, ...props }: PositionerProps) => import("react/jsx-runtime").JSX.Element;
43
- Popup: ({ className, ...props }: PopupProps) => import("react/jsx-runtime").JSX.Element;
10
+ Positioner: ({ className, sideOffset, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuPositionerProps, "ref"> & import("react").RefAttributes<HTMLDivElement>, "ref"> & {
11
+ ref?: import("react").Ref<HTMLDivElement>;
12
+ }) => import("react/jsx-runtime").JSX.Element;
44
13
  Arrow: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuArrowProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
45
14
  Group: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
46
- GroupLabel: ({ className, ...props }: GroupLabelProps) => import("react/jsx-runtime").JSX.Element;
47
- Separator: ({ className, ...props }: SeparatorProps) => import("react/jsx-runtime").JSX.Element;
48
- Item: ({ className, variant, ...props }: ItemProps) => import("react/jsx-runtime").JSX.Element;
49
- LinkItem: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuLinkItemProps, "ref"> & import("react").RefAttributes<Element>>;
50
- CheckboxItem: ({ className, children, ...props }: CheckboxItemProps) => import("react/jsx-runtime").JSX.Element;
15
+ GroupLabel: ({ className, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuGroupLabelProps, "ref"> & import("react").RefAttributes<HTMLDivElement>, "ref"> & {
16
+ ref?: import("react").Ref<HTMLDivElement>;
17
+ }) => import("react/jsx-runtime").JSX.Element;
18
+ Separator: ({ className, ...props }: Omit<Omit<import("@base-ui/react").SeparatorProps, "ref"> & import("react").RefAttributes<HTMLDivElement>, "ref"> & {
19
+ ref?: import("react").Ref<HTMLDivElement>;
20
+ }) => import("react/jsx-runtime").JSX.Element;
21
+ Item: ({ className, variant, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuItemProps, "ref"> & import("react").RefAttributes<HTMLElement>, "ref"> & {
22
+ ref?: import("react").Ref<HTMLDivElement>;
23
+ variant?: "default" | "destructive";
24
+ }) => import("react/jsx-runtime").JSX.Element;
25
+ LinkItem: ({ className, variant, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuLinkItemProps, "ref"> & import("react").RefAttributes<Element>, "ref"> & {
26
+ ref?: import("react").Ref<HTMLAnchorElement>;
27
+ variant?: "default" | "destructive";
28
+ }) => import("react/jsx-runtime").JSX.Element;
29
+ CheckboxItem: ({ className, children, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuCheckboxItemProps, "ref"> & import("react").RefAttributes<HTMLElement>, "ref"> & {
30
+ ref?: import("react").Ref<HTMLDivElement>;
31
+ }) => import("react/jsx-runtime").JSX.Element;
51
32
  RadioGroup: import("react").NamedExoticComponent<Omit<import("@base-ui/react").ContextMenuRadioGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
52
- RadioItem: ({ className, children, ...props }: RadioItemProps) => import("react/jsx-runtime").JSX.Element;
33
+ RadioItem: ({ className, children, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuRadioItemProps, "ref"> & import("react").RefAttributes<HTMLElement>, "ref"> & {
34
+ ref?: import("react").Ref<HTMLDivElement>;
35
+ }) => import("react/jsx-runtime").JSX.Element;
53
36
  SubmenuRoot: typeof BaseContextMenu.SubmenuRoot;
54
- SubmenuTrigger: ({ className, children, ...props }: SubmenuTriggerProps) => import("react/jsx-runtime").JSX.Element;
37
+ SubmenuTrigger: ({ className, children, ...props }: Omit<Omit<import("@base-ui/react").ContextMenuSubmenuTriggerProps, "ref"> & import("react").RefAttributes<HTMLElement>, "ref"> & {
38
+ ref?: import("react").Ref<HTMLDivElement>;
39
+ }) => import("react/jsx-runtime").JSX.Element;
55
40
  };
56
- export {};
@@ -1,41 +1,14 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { ContextMenu as BaseContextMenu } from '@base-ui/react/context-menu';
4
- import { ChevronRight } from 'lucide-react';
5
- import { cn } from '../helpers/cn/cn';
6
4
  import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
7
- const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover z-50 min-w-45 origin-[var(--transform-origin)] rounded-lg border py-1 outline-hidden transition-[transform,opacity] data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0';
8
- const itemBaseClasses = 'relative flex h-7 cursor-default items-center gap-1.5 rounded-[calc(var(--radius)-0.25rem)] px-2.5 text-[0.8rem] outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4 data-[disabled]:pointer-events-none data-[disabled]:opacity-50';
9
- const itemVariantClasses = {
10
- default: 'data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground',
11
- destructive: 'text-destructive data-[highlighted]:bg-destructive/10 data-[highlighted]:text-destructive',
12
- };
13
- const Positioner = ({ className, sideOffset = 4, ...props }) => (_jsx(BaseContextMenu.Positioner, { sideOffset: sideOffset, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
14
- const Popup = ({ className, ...props }) => (_jsx(BaseContextMenu.Popup, { className: mergeStatefulClassName(popupClasses, className), ...props }));
15
- const Item = ({ className, variant = 'default', ...props }) => (_jsx(BaseContextMenu.Item, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses[variant]), className), ...props }));
16
- const Separator = ({ className, ...props }) => (_jsx(BaseContextMenu.Separator, { className: mergeStatefulClassName('bg-border my-1 h-px', className), ...props }));
17
- const GroupLabel = ({ className, ...props }) => (_jsx(BaseContextMenu.GroupLabel, { className: mergeStatefulClassName('text-muted-foreground px-2.5 py-1 text-xs', className), ...props }));
18
- const CheckboxItem = ({ className, children, ...props }) => (_jsxs(BaseContextMenu.CheckboxItem, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses.default, 'pl-7'), className), ...props, children: [_jsx("span", { "aria-hidden": true, className: "absolute left-2 flex size-3.5 items-center justify-center", children: _jsx(BaseContextMenu.CheckboxItemIndicator, { className: "size-3.5", children: _jsx(CheckIcon, {}) }) }), children] }));
19
- const RadioItem = ({ className, children, ...props }) => (_jsxs(BaseContextMenu.RadioItem, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses.default, 'pl-7'), className), ...props, children: [_jsx("span", { "aria-hidden": true, className: "absolute left-2 flex size-3.5 items-center justify-center", children: _jsx(BaseContextMenu.RadioItemIndicator, { className: "size-3.5", children: _jsx(DotIcon, {}) }) }), children] }));
20
- const SubmenuTrigger = ({ className, children, ...props }) => (_jsxs(BaseContextMenu.SubmenuTrigger, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses.default, 'data-popup-open:bg-accent data-popup-open:text-accent-foreground pr-2'), className), ...props, children: [children, _jsx(ChevronRight, { className: "ml-auto size-4 opacity-60", "aria-hidden": true })] }));
21
- const CheckIcon = () => (_jsx("svg", { viewBox: "0 0 14 14", fill: "none", className: "size-3.5", children: _jsx("path", { d: "M3 7.5 6 10.5 11 4.5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) }));
22
- const DotIcon = () => (_jsx("svg", { viewBox: "0 0 14 14", className: "size-3.5", children: _jsx("circle", { cx: "7", cy: "7", r: "3", fill: "currentColor" }) }));
5
+ import { Menu } from '../Menu/Menu';
6
+ // Base UI's ContextMenu is Menu with its own Root and Trigger; every other part is the same
7
+ // component, so the styled Menu parts apply as-is. A context menu just opens a little wider.
8
+ const Popup = ({ className, ...props }) => (_jsx(Menu.Popup, { className: mergeStatefulClassName('min-w-45', className), ...props }));
23
9
  export const ContextMenu = {
10
+ ...Menu,
24
11
  Root: BaseContextMenu.Root,
25
12
  Trigger: BaseContextMenu.Trigger,
26
- Portal: BaseContextMenu.Portal,
27
- Backdrop: BaseContextMenu.Backdrop,
28
- Positioner,
29
13
  Popup,
30
- Arrow: BaseContextMenu.Arrow,
31
- Group: BaseContextMenu.Group,
32
- GroupLabel,
33
- Separator,
34
- Item,
35
- LinkItem: BaseContextMenu.LinkItem,
36
- CheckboxItem,
37
- RadioGroup: BaseContextMenu.RadioGroup,
38
- RadioItem,
39
- SubmenuRoot: BaseContextMenu.SubmenuRoot,
40
- SubmenuTrigger,
41
14
  };
@@ -1,7 +1,7 @@
1
1
  import type { ElementType } from 'react';
2
2
  import type { ItemActionsProps, ItemContentProps, ItemDescriptionProps, ItemMediaProps, ItemRootProps, ItemTitleProps } from './Item.types';
3
3
  declare const itemVariants: (props?: ({
4
- surface?: "inset" | "outline" | "raised" | "plain" | null | undefined;
4
+ surface?: "outline" | "raised" | "plain" | "inset" | null | undefined;
5
5
  interactive?: boolean | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  /**
package/dist/Kbd/Kbd.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useSyncExternalStore } from 'react';
3
4
  import { getModKey } from '../helpers/getModKey/getModKey';
4
5
  import { cn } from '../helpers/cn/cn';
5
6
  import { kbdVariants } from './Kbd.variants';
@@ -16,16 +17,22 @@ const KEY_SYMBOLS = {
16
17
  up: '↑',
17
18
  down: '↓',
18
19
  };
19
- const resolveKey = (key) => {
20
+ const resolveKey = (key, modKey) => {
20
21
  const lower = key.toLowerCase();
21
22
  if (lower === 'mod')
22
- return MOD_SYMBOLS[getModKey()] ?? 'Ctrl';
23
+ return MOD_SYMBOLS[modKey] ?? 'Ctrl';
23
24
  if (lower === 'ctrl')
24
- return getModKey() === 'Cmd' ? '⌃' : 'Ctrl';
25
+ return modKey === 'Cmd' ? '⌃' : 'Ctrl';
25
26
  return KEY_SYMBOLS[lower] ?? key;
26
27
  };
28
+ // The platform never changes after load, so there is nothing to subscribe to. The server
29
+ // snapshot pins SSR and hydration to the non-Mac glyphs; React then re-renders with the
30
+ // client's real platform, so Mac users get ⌘ without a hydration mismatch.
31
+ const subscribeToNothing = () => () => { };
32
+ const getServerModKey = () => 'Ctrl';
27
33
  const Kbd = ({ keys, size, className }) => {
28
34
  const keyList = Array.isArray(keys) ? keys : [keys];
29
- return (_jsx("span", { className: "inline-flex items-center gap-0.5", role: "presentation", children: keyList.map((key, i) => (_jsx("kbd", { className: cn(kbdVariants({ size }), className), children: resolveKey(key) }, i))) }));
35
+ const modKey = useSyncExternalStore(subscribeToNothing, getModKey, getServerModKey);
36
+ return (_jsx("span", { className: "inline-flex items-center gap-0.5", role: "presentation", children: keyList.map((key, i) => (_jsx("kbd", { className: cn(kbdVariants({ size }), className), children: resolveKey(key, modKey) }, i))) }));
30
37
  };
31
38
  export { Kbd };
@@ -8,6 +8,7 @@ type BaseGroupLabelProps = ComponentPropsWithoutRef<typeof BaseMenu.GroupLabel>;
8
8
  type BaseSubmenuTriggerProps = ComponentPropsWithoutRef<typeof BaseMenu.SubmenuTrigger>;
9
9
  type BaseCheckboxItemProps = ComponentPropsWithoutRef<typeof BaseMenu.CheckboxItem>;
10
10
  type BaseRadioItemProps = ComponentPropsWithoutRef<typeof BaseMenu.RadioItem>;
11
+ type BaseLinkItemProps = ComponentPropsWithoutRef<typeof BaseMenu.LinkItem>;
11
12
  type ItemVariant = 'default' | 'destructive';
12
13
  type PositionerProps = BasePositionerProps & {
13
14
  ref?: Ref<HTMLDivElement>;
@@ -16,7 +17,7 @@ type PopupProps = BasePopupProps & {
16
17
  ref?: Ref<HTMLDivElement>;
17
18
  };
18
19
  type SeparatorProps = BaseSeparatorProps & {
19
- ref?: Ref<HTMLHRElement>;
20
+ ref?: Ref<HTMLDivElement>;
20
21
  };
21
22
  type GroupLabelProps = BaseGroupLabelProps & {
22
23
  ref?: Ref<HTMLDivElement>;
@@ -25,6 +26,10 @@ type ItemProps = BaseItemProps & {
25
26
  ref?: Ref<HTMLDivElement>;
26
27
  variant?: ItemVariant;
27
28
  };
29
+ type LinkItemProps = BaseLinkItemProps & {
30
+ ref?: Ref<HTMLAnchorElement>;
31
+ variant?: ItemVariant;
32
+ };
28
33
  type CheckboxItemProps = BaseCheckboxItemProps & {
29
34
  ref?: Ref<HTMLDivElement>;
30
35
  };
@@ -46,7 +51,7 @@ export declare const Menu: {
46
51
  GroupLabel: ({ className, ...props }: GroupLabelProps) => import("react/jsx-runtime").JSX.Element;
47
52
  Separator: ({ className, ...props }: SeparatorProps) => import("react/jsx-runtime").JSX.Element;
48
53
  Item: ({ className, variant, ...props }: ItemProps) => import("react/jsx-runtime").JSX.Element;
49
- LinkItem: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ContextMenuLinkItemProps, "ref"> & import("react").RefAttributes<Element>>;
54
+ LinkItem: ({ className, variant, ...props }: LinkItemProps) => import("react/jsx-runtime").JSX.Element;
50
55
  CheckboxItem: ({ className, children, ...props }: CheckboxItemProps) => import("react/jsx-runtime").JSX.Element;
51
56
  RadioGroup: import("react").NamedExoticComponent<Omit<import("@base-ui/react").ContextMenuRadioGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
52
57
  RadioItem: ({ className, children, ...props }: RadioItemProps) => import("react/jsx-runtime").JSX.Element;
package/dist/Menu/Menu.js CHANGED
@@ -4,7 +4,7 @@ import { Menu as BaseMenu } from '@base-ui/react/menu';
4
4
  import { ChevronRight } from 'lucide-react';
5
5
  import { cn } from '../helpers/cn/cn';
6
6
  import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
7
- const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover z-50 min-w-36 origin-[var(--transform-origin)] rounded-lg border py-1 outline-hidden transition-[transform,opacity] data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0';
7
+ const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover z-50 min-w-36 origin-[var(--transform-origin)] rounded-lg border py-1 outline-hidden transition-[scale,opacity] data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 motion-reduce:transition-none';
8
8
  const itemBaseClasses = 'relative flex h-7 cursor-default items-center gap-1.5 rounded-[calc(var(--radius)-0.25rem)] px-2.5 text-[0.8rem] outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4 data-[disabled]:pointer-events-none data-[disabled]:opacity-50';
9
9
  const itemVariantClasses = {
10
10
  default: 'data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground',
@@ -13,6 +13,7 @@ const itemVariantClasses = {
13
13
  const Positioner = ({ className, sideOffset = 4, ...props }) => (_jsx(BaseMenu.Positioner, { sideOffset: sideOffset, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
14
14
  const Popup = ({ className, ...props }) => (_jsx(BaseMenu.Popup, { className: mergeStatefulClassName(popupClasses, className), ...props }));
15
15
  const Item = ({ className, variant = 'default', ...props }) => (_jsx(BaseMenu.Item, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses[variant]), className), ...props }));
16
+ const LinkItem = ({ className, variant = 'default', ...props }) => (_jsx(BaseMenu.LinkItem, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses[variant]), className), ...props }));
16
17
  const Separator = ({ className, ...props }) => (_jsx(BaseMenu.Separator, { className: mergeStatefulClassName('bg-border my-1 h-px', className), ...props }));
17
18
  const GroupLabel = ({ className, ...props }) => (_jsx(BaseMenu.GroupLabel, { className: mergeStatefulClassName('text-muted-foreground px-2.5 py-1 text-xs', className), ...props }));
18
19
  const CheckboxItem = ({ className, children, ...props }) => (_jsxs(BaseMenu.CheckboxItem, { className: mergeStatefulClassName(cn(itemBaseClasses, itemVariantClasses.default, 'pl-7'), className), ...props, children: [_jsx("span", { "aria-hidden": true, className: "absolute left-2 flex size-3.5 items-center justify-center", children: _jsx(BaseMenu.CheckboxItemIndicator, { className: "size-3.5", children: _jsx(CheckIcon, {}) }) }), children] }));
@@ -32,7 +33,7 @@ export const Menu = {
32
33
  GroupLabel,
33
34
  Separator,
34
35
  Item,
35
- LinkItem: BaseMenu.LinkItem,
36
+ LinkItem,
36
37
  CheckboxItem,
37
38
  RadioGroup: BaseMenu.RadioGroup,
38
39
  RadioItem,
@@ -70,6 +70,27 @@ function assignRef(ref, element) {
70
70
  ;
71
71
  ref.current = element;
72
72
  }
73
+ // Returns a ref callback that stays the same across renders and also forwards the element to
74
+ // the consumer's `ref`. An inline `ref={node => ...}` is a new function every render; if our
75
+ // callback changed with it, React would detach and reattach the element each render, and
76
+ // detaching resets the scroller.
77
+ function useForwardedRef(ref, onElement) {
78
+ const elementRef = useRef(null);
79
+ const forwardedRef = useRef(ref);
80
+ useLayoutEffect(() => {
81
+ if (forwardedRef.current === ref) {
82
+ return;
83
+ }
84
+ assignRef(forwardedRef.current, null);
85
+ forwardedRef.current = ref;
86
+ assignRef(ref, elementRef.current);
87
+ });
88
+ return useCallback((element) => {
89
+ elementRef.current = element;
90
+ onElement(element);
91
+ assignRef(forwardedRef.current, element);
92
+ }, [onElement]);
93
+ }
73
94
  function getMessageElements(contentElement, spacerElement) {
74
95
  if (!contentElement) {
75
96
  return [];
@@ -102,6 +123,18 @@ function canKeyboardScroll(viewportElement, event) {
102
123
  }
103
124
  return false;
104
125
  }
126
+ // Keys pressed in a text field move its caret or change its value, and Space presses a button.
127
+ // Neither scrolls the viewport, so they don't mean the reader took over.
128
+ function isKeyHandledByTarget(event) {
129
+ const target = event.target;
130
+ if (!(target instanceof HTMLElement)) {
131
+ return false;
132
+ }
133
+ if (target.isContentEditable || target.matches('input, select, textarea')) {
134
+ return true;
135
+ }
136
+ return event.key === ' ' && target.matches('button, summary');
137
+ }
105
138
  function getElementTop(element, viewportElement) {
106
139
  const elementRectangle = element.getBoundingClientRect();
107
140
  const viewportRectangle = viewportElement.getBoundingClientRect();
@@ -187,8 +220,10 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
187
220
  const userScrollIntentRef = useRef(false);
188
221
  // Smooth bottom scrolls can briefly measure as away from bottom while still settling.
189
222
  const bottomFollowIntentRef = useRef(autoFollow);
190
- const ignoreAnchoredBottomResumeFrameRef = useRef(null);
191
- const ignoreAnchoredBottomResumeRef = useRef(false);
223
+ const lastScrollTopRef = useRef(0);
224
+ // Where the current jump is headed. A smooth jump sends scroll events for many frames, and one
225
+ // that lands on the bottom must not read as the reader scrolling there to resume following.
226
+ const jumpInFlightRef = useRef(null);
192
227
  const pendingDefaultScrollFrameRef = useRef(null);
193
228
  const pendingSyncFrameRef = useRef(null);
194
229
  const pendingScrollToMessageRef = useRef(null);
@@ -266,6 +301,17 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
266
301
  const commitStatus = useCallback(() => {
267
302
  const status = measureStatus();
268
303
  const isAnchoredMode = modeRef.current === 'anchored-to-message' || modeRef.current === 'settling-jump';
304
+ const scrollTop = viewportElementRef.current?.scrollTop ?? 0;
305
+ const scrolledUp = scrollTop < lastScrollTopRef.current - SCROLL_TOLERANCE;
306
+ lastScrollTopRef.current = scrollTop;
307
+ // Following never scrolls up on its own, so moving up means someone else scrolled: a
308
+ // scrollbar drag, find-in-page, or scrollIntoView. None of those fire wheel, touch, or key
309
+ // input, so treat them as the reader taking over.
310
+ if (scrolledUp && modeRef.current === 'following-bottom' && !status.isAtBottom) {
311
+ autoscrollingRef.current = false;
312
+ bottomFollowIntentRef.current = false;
313
+ modeRef.current = 'free-scrolling';
314
+ }
269
315
  if (status.isAtBottom) {
270
316
  userScrollIntentRef.current = false;
271
317
  }
@@ -351,16 +397,6 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
351
397
  syncVisibility();
352
398
  capturePrependAnchor();
353
399
  }, [capturePrependAnchor, commitStatus, syncVisibility]);
354
- const ignoreAnchoredBottomResumeForCurrentFrame = useCallback(() => {
355
- ignoreAnchoredBottomResumeRef.current = true;
356
- if (ignoreAnchoredBottomResumeFrameRef.current !== null) {
357
- window.cancelAnimationFrame(ignoreAnchoredBottomResumeFrameRef.current);
358
- }
359
- ignoreAnchoredBottomResumeFrameRef.current = window.requestAnimationFrame(() => {
360
- ignoreAnchoredBottomResumeFrameRef.current = null;
361
- ignoreAnchoredBottomResumeRef.current = false;
362
- });
363
- }, []);
364
400
  const scheduleSyncAfterScroll = useCallback(() => {
365
401
  if (pendingSyncFrameRef.current !== null) {
366
402
  return;
@@ -447,15 +483,12 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
447
483
  setSpacerHeight(spacerHeight);
448
484
  anchoredElementRef.current = keepPreviousItemPeek ? element : null;
449
485
  modeRef.current = keepPreviousItemPeek ? 'anchored-to-message' : 'settling-jump';
450
- ignoreAnchoredBottomResumeForCurrentFrame();
486
+ jumpInFlightRef.current = {
487
+ distance: Math.abs(viewportElement.scrollTop - Math.max(0, targetScrollTop)),
488
+ targetScrollTop: Math.max(0, targetScrollTop),
489
+ };
451
490
  return scrollToTopValue(targetScrollTop, { behavior });
452
- }, [
453
- clearSpacer,
454
- ignoreAnchoredBottomResumeForCurrentFrame,
455
- scrollToTopValue,
456
- setAutoscrolling,
457
- setSpacerHeight,
458
- ]);
491
+ }, [clearSpacer, scrollToTopValue, setAutoscrolling, setSpacerHeight]);
459
492
  const scrollToAnchorElement = useCallback((element, options = {}) => scrollToElement(element, {
460
493
  align: 'start',
461
494
  behavior: options.behavior,
@@ -491,6 +524,11 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
491
524
  }
492
525
  const element = messageElementsRef.current.get(pendingScrollToMessage.messageId);
493
526
  if (!element) {
527
+ // The jump waited for messages, and these don't have its target. Drop it like a direct
528
+ // miss, or it would fire whenever that id shows up later and yank the reader there.
529
+ if (messageElementsRef.current.size > 0) {
530
+ pendingScrollToMessageRef.current = null;
531
+ }
494
532
  return false;
495
533
  }
496
534
  pendingScrollToMessageRef.current = null;
@@ -601,7 +639,9 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
601
639
  }, [scrollToAnchorElement]);
602
640
  const handleContentChange = useCallback(() => {
603
641
  const contentElement = contentElementRef.current;
604
- if (!contentElement) {
642
+ // Content's layout effects run before the Viewport's ref attaches when both mount together.
643
+ // Wait for the Viewport's own pass instead of spending queued jumps and anchors on nothing.
644
+ if (!contentElement || !viewportElementRef.current) {
605
645
  return;
606
646
  }
607
647
  if (flushPendingScrollToMessage()) {
@@ -658,8 +698,16 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
658
698
  }, [reanchorToAnchoredMessage, scrollToBottom, syncAfterScroll]);
659
699
  const handleViewportScroll = useCallback(() => {
660
700
  syncAfterScroll();
661
- if (ignoreAnchoredBottomResumeRef.current) {
662
- return;
701
+ const jump = jumpInFlightRef.current;
702
+ if (jump && viewportElementRef.current) {
703
+ const distance = Math.abs(viewportElementRef.current.scrollTop - jump.targetScrollTop);
704
+ // Closing in on the target, or resting on it, is the jump itself. Moving away is someone
705
+ // else scrolling, so from then on the bottom check below applies.
706
+ if (distance <= jump.distance + SCROLL_TOLERANCE) {
707
+ jump.distance = Math.min(jump.distance, distance);
708
+ return;
709
+ }
710
+ jumpInFlightRef.current = null;
663
711
  }
664
712
  const status = measureStatus();
665
713
  const isAnchoredMode = modeRef.current === 'anchored-to-message' || modeRef.current === 'settling-jump';
@@ -676,6 +724,7 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
676
724
  }, [clearSpacer, measureStatus, syncAfterScroll]);
677
725
  const markUserScrollIntent = useCallback(() => {
678
726
  userScrollIntentRef.current = true;
727
+ jumpInFlightRef.current = null;
679
728
  if (modeRef.current === 'following-bottom' ||
680
729
  modeRef.current === 'anchored-to-message' ||
681
730
  modeRef.current === 'settling-jump') {
@@ -719,7 +768,7 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
719
768
  userScrollIntentRef.current = false;
720
769
  defaultScrollPositionAppliedRef.current = false;
721
770
  prependRestoreRef.current = null;
722
- ignoreAnchoredBottomResumeRef.current = false;
771
+ jumpInFlightRef.current = null;
723
772
  visibilityStore.setSnapshot(DEFAULT_VISIBILITY);
724
773
  scheduleSyncAfterScroll();
725
774
  }, [clearSpacer, scheduleSyncAfterScroll, visibilityStore]);
@@ -735,9 +784,6 @@ function useMessageScrollerEngine({ autoFollow, defaultScrollPosition, scrollEdg
735
784
  if (pendingDefaultScrollFrameRef.current !== null) {
736
785
  window.cancelAnimationFrame(pendingDefaultScrollFrameRef.current);
737
786
  }
738
- if (ignoreAnchoredBottomResumeFrameRef.current !== null) {
739
- window.cancelAnimationFrame(ignoreAnchoredBottomResumeFrameRef.current);
740
- }
741
787
  }, []);
742
788
  return useMemo(() => ({
743
789
  handleContentChange,
@@ -797,10 +843,7 @@ function MessageScrollerViewport({ 'aria-label': ariaLabel, children, className,
797
843
  const { handleContentChange, handleResize, handleViewportScroll, markUserScrollIntent, preserveScrollOnPrependRef, setViewportElement, viewportElementRef, } = useMessageScrollerContext('MessageScroller.Viewport');
798
844
  const touchClientYRef = useRef(null);
799
845
  preserveScrollOnPrependRef.current = preserveScrollOnPrepend;
800
- const handleRef = useCallback((element) => {
801
- setViewportElement(element);
802
- assignRef(ref, element);
803
- }, [ref, setViewportElement]);
846
+ const handleRef = useForwardedRef(ref, setViewportElement);
804
847
  useLayoutEffect(() => {
805
848
  handleContentChange();
806
849
  }, [handleContentChange]);
@@ -842,6 +885,7 @@ function MessageScrollerViewport({ 'aria-label': ariaLabel, children, className,
842
885
  onKeyDown?.(event);
843
886
  if (!event.defaultPrevented &&
844
887
  USER_SCROLL_INTENT_KEYS.has(event.key) &&
888
+ !isKeyHandledByTarget(event) &&
845
889
  canKeyboardScroll(event.currentTarget, event)) {
846
890
  markUserScrollIntent();
847
891
  }
@@ -862,12 +906,11 @@ function MessageScrollerContent({ 'aria-relevant': ariaRelevant, children, class
862
906
  const contentElementRef = useRef(null);
863
907
  const contentSignatureRef = useRef('');
864
908
  const spacerElementRef = useRef(null);
865
- const handleContentRef = useCallback((element) => {
909
+ const handleContentRef = useForwardedRef(ref, useCallback((element) => {
866
910
  contentElementRef.current = element;
867
911
  contentSignatureRef.current = '';
868
912
  setContentElement(element);
869
- assignRef(ref, element);
870
- }, [ref, setContentElement]);
913
+ }, [setContentElement]));
871
914
  const handleSpacerRef = useCallback((element) => {
872
915
  spacerElementRef.current = element;
873
916
  setSpacerElement(element);
@@ -7,7 +7,7 @@ const POPOVER_COLLISION_AVOIDANCE = {
7
7
  align: 'shift',
8
8
  fallbackAxisSide: 'none',
9
9
  };
10
- const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover box-border max-h-[var(--available-height)] max-w-[var(--available-width)] origin-[var(--transform-origin)] overflow-x-hidden overflow-y-auto rounded-lg border outline-hidden transition-[transform,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 data-[instant]:transition-none data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:transition-none motion-reduce:transform-none motion-reduce:transition-none';
10
+ const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover box-border max-h-[var(--available-height)] max-w-[var(--available-width)] origin-[var(--transform-origin)] overflow-x-hidden overflow-y-auto rounded-lg border outline-hidden transition-[scale,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 data-[instant]:transition-none data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:transition-none motion-reduce:transition-none';
11
11
  const Positioner = ({ className, sideOffset = 6, collisionPadding = 8, collisionAvoidance = POPOVER_COLLISION_AVOIDANCE, positionMethod = 'fixed', ...props }) => (_jsx(BasePopover.Positioner, { sideOffset: sideOffset, collisionPadding: collisionPadding, collisionAvoidance: collisionAvoidance, positionMethod: positionMethod, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
12
12
  const Popup = ({ className, ...props }) => (_jsx(BasePopover.Popup, { className: mergeStatefulClassName(popupClasses, className), ...props }));
13
13
  /** Accessible floating disclosure over Base UI Popover. The popup supplies the semantic surface,
@@ -6,11 +6,11 @@ import type { TextProps } from './Text.types';
6
6
  * composes with any font family or color context.
7
7
  */
8
8
  declare const textVariants: (props?: ({
9
- variant?: "caption" | "display" | "title" | "heading" | "body" | "label" | "subheading" | "bodyLg" | "overline" | null | undefined;
9
+ variant?: "title" | "heading" | "display" | "body" | "caption" | "label" | "subheading" | "bodyLg" | "overline" | null | undefined;
10
10
  color?: "default" | "primary" | "success" | "attention" | "destructive" | "highlight" | "muted" | null | undefined;
11
11
  font?: "sans" | "serif" | "mono" | null | undefined;
12
12
  weight?: "bold" | "regular" | "medium" | "semibold" | null | undefined;
13
- align?: "end" | "start" | "center" | null | undefined;
13
+ align?: "end" | "center" | "start" | null | undefined;
14
14
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
15
15
  declare const Text: <E extends ElementType = "p">({ as, variant, color, font, weight, align, numeric, truncate, lines, className, style, title, children, ...props }: TextProps<E>) => import("react/jsx-runtime").JSX.Element;
16
16
  export { Text, textVariants };
@@ -13,7 +13,7 @@ const TOOLTIP_COLLISION_AVOIDANCE = {
13
13
  align: 'shift',
14
14
  fallbackAxisSide: 'none',
15
15
  };
16
- const popupClasses = 'bg-foreground text-background shadow-popover pointer-events-none flex origin-[var(--transform-origin)] items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs transition-[transform,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[ending-style]:scale-[0.97] data-[ending-style]:opacity-0 data-[instant]:transition-none data-[starting-style]:scale-[0.97] data-[starting-style]:opacity-0 motion-reduce:transform-none motion-reduce:transition-none';
16
+ const popupClasses = 'bg-foreground text-background shadow-popover pointer-events-none flex origin-[var(--transform-origin)] items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs transition-[scale,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[ending-style]:scale-[0.97] data-[ending-style]:opacity-0 data-[instant]:transition-none data-[starting-style]:scale-[0.97] data-[starting-style]:opacity-0 motion-reduce:transition-none';
17
17
  const Positioner = ({ className, sideOffset = TRIGGER_GAP, collisionPadding = VIEWPORT_MARGIN, collisionAvoidance = TOOLTIP_COLLISION_AVOIDANCE, positionMethod = 'fixed', ...props }) => (_jsx(BaseTooltip.Positioner, { sideOffset: sideOffset, collisionPadding: collisionPadding, collisionAvoidance: collisionAvoidance, positionMethod: positionMethod, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
18
18
  const Popup = ({ className, role = 'tooltip', ...props }) => (_jsx(BaseTooltip.Popup, { role: role, className: mergeStatefulClassName(popupClasses, className), ...props }));
19
19
  const TooltipComponent = ({ label, shortcut, position = 'top', delay = DEFAULT_DELAY, maxWidth, disabled, className, children, }) => {
@@ -1,2 +1,2 @@
1
- import { type ClassValue } from 'clsx';
2
- export declare function cn(...inputs: ClassValue[]): string;
1
+ import type { CnFunction } from 'cn';
2
+ export declare const cn: CnFunction;
@@ -1,12 +1,3 @@
1
- import { clsx } from 'clsx';
2
- import { extendTailwindMerge } from 'tailwind-merge';
3
- const mergeTailwindClasses = extendTailwindMerge({
4
- extend: {
5
- theme: {
6
- 'inset-shadow': ['surface'],
7
- },
8
- },
9
- });
10
- export function cn(...inputs) {
11
- return mergeTailwindClasses(clsx(inputs));
12
- }
1
+ import { createCn } from 'cn/engine';
2
+ import tables from './cn.tables';
3
+ export const cn = createCn(tables);
@@ -0,0 +1,51 @@
1
+ declare namespace _default {
2
+ export { GROUP_COUNT };
3
+ export { customValidatorNames };
4
+ export { edgeStart };
5
+ export { labelStart };
6
+ export { labelText };
7
+ export { edgeTarget };
8
+ export { nodeGroup };
9
+ export { nodeVlist };
10
+ export { vlistPat };
11
+ export { vlistOps };
12
+ export { vlistRef };
13
+ export { vlistGroup };
14
+ export { litAnchor };
15
+ export { litGroup };
16
+ export { litPool };
17
+ export { poolOffsets };
18
+ export { poolText };
19
+ export { adjGid };
20
+ export { adjStart };
21
+ export { adjTgt };
22
+ export { patGid };
23
+ export { patTgt };
24
+ export { postfixLookupGroups };
25
+ export { orderSensitiveModifiers };
26
+ }
27
+ export default _default;
28
+ declare const GROUP_COUNT: 384;
29
+ declare const customValidatorNames: any[];
30
+ declare const edgeStart: Int32Array<any>;
31
+ declare const labelStart: Int32Array<any>;
32
+ declare const labelText: "@containerabcdefghinlmoprstunderlineviawzccentlignnimatespectuto-colsrowsaglorightnessckdrop-sisbcontrastfiltergrayscalehue-rotateinvertopacityslurrightnessaturateepia-coniclinearpositionradialsizeockurrderttom-belrstxyespacing-xyaretoursorlnt-umnsendspantartainentrasteividerop-shadowurationcorationlay-xyasendillexontromlter-featuresstretchapr-xyayscaleidow-colsrowsue-rotatedentlinesetvert-beringsxyeshadoweiadingftnest-clamp-imageabein-lrstxyskx--b-coniclpositionrsizet-x-y-fromto-fromto-inearfromto-fromto-adialfromto-fromtofromtofromtofromtoblockhinlinew-screenesblockhinlinewbjectpacityrutlinederigin-offsetbelrstxyesrspective-originaceholderioghtng-offsettateundedw-xyz-belrstlreseslr-endspantartaturatecepiahizekewpace-taleroll-xyz-barmpbelrstxyesbelrstxyes-thumbrackadowrink-xyxyartrokeabextora-shadowpckingnsformitionlate-xyz-offsetill-changeoom";
33
+ declare const edgeTarget: Int32Array<ArrayBuffer>;
34
+ declare const nodeGroup: Int32Array<any>;
35
+ declare const nodeVlist: Int32Array<ArrayBuffer>;
36
+ declare const vlistPat: Int32Array<any>;
37
+ declare const vlistOps: Int32Array<any>;
38
+ declare const vlistRef: Int32Array<any>;
39
+ declare const vlistGroup: Int32Array<any>;
40
+ declare const litAnchor: Int32Array<ArrayBuffer>;
41
+ declare const litGroup: Int32Array<ArrayBuffer>;
42
+ declare const litPool: Int32Array<ArrayBuffer>;
43
+ declare const poolOffsets: Int32Array<ArrayBuffer>;
44
+ declare let poolText: string;
45
+ declare const adjGid: Int32Array<any>;
46
+ declare const adjStart: Int32Array<any>;
47
+ declare const adjTgt: Int32Array<any>;
48
+ declare const patGid: Int32Array<any>;
49
+ declare const patTgt: Int32Array<any>;
50
+ declare const postfixLookupGroups: Int32Array<any>;
51
+ declare const orderSensitiveModifiers: "* ** after backdrop before details-content file first-letter first-line marker placeholder selection";