{"version":3,"file":"chunk-Toolbar.mjs","names":["toolbar.machine","toolbar.connect","ScrollArea.Root","ScrollArea.Viewport","ToggleGroup.Root"],"sources":["../../src/components/Toolbar/toolbar-machine.ts","../../src/components/Toolbar/Toolbar.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Scope, type Service, createMachine } from '@zag-js/core';\n\n/**\n * Roving focus for `role=toolbar` (decision 9): one item is tabbable and arrow keys, Home and End move between items.\n * Framework-neutral: the machine and `connect` import no React, so a Solid binding reuses both.\n */\n\nexport type Orientation = 'horizontal' | 'vertical';\n\nexport type ToolbarProps = {\n  id: string;\n  orientation?: Orientation;\n  /** Wrap from the last item to the first and back. */\n  loop?: boolean;\n  /** Disables every item, so the toolbar has no tab stop. */\n  disabled?: boolean;\n};\n\ntype Direction = 'next' | 'prev' | 'first' | 'last';\n\nexport type ToolbarSchema = {\n  state: 'idle';\n  props: ToolbarProps;\n  context: { focusedValue: string | null };\n  event: { type: 'ITEM.FOCUS'; value: string } | { type: 'NAVIGATE'; direction: Direction };\n  action: 'setFocusedValue' | 'focusItem' | 'initFocusedValue';\n};\n\nexport type ToolbarService = Service<ToolbarSchema>;\n\nconst getRootId = (scope: Scope) => `toolbar:${scope.id}`;\n\n/** Items owned by this toolbar only, so a nested toolbar keeps its own roving set. */\nconst getItems = (scope: Scope): HTMLElement[] => {\n  const root = scope.getById(getRootId(scope));\n  if (!root) {\n    return [];\n  }\n  return Array.from(root.querySelectorAll<HTMLElement>(`[data-toolbar-item=\"${getRootId(scope)}\"]`)).filter(\n    (element) => !element.hasAttribute('disabled') && !element.hasAttribute('data-disabled'),\n  );\n};\n\nexport const machine = createMachine<ToolbarSchema>({\n  props: ({ props }) => ({ orientation: 'horizontal', loop: true, id: '', ...props }),\n\n  initialState: () => 'idle',\n\n  context: ({ bindable }) => ({\n    focusedValue: bindable<string | null>(() => ({ defaultValue: null })),\n  }),\n\n  entry: ['initFocusedValue'],\n\n  states: {\n    idle: {\n      on: {\n        'ITEM.FOCUS': { actions: ['setFocusedValue'] },\n        'NAVIGATE': { actions: ['focusItem'] },\n      },\n    },\n  },\n\n  implementations: {\n    actions: {\n      initFocusedValue: ({ context, scope }) => {\n        const [first] = getItems(scope);\n        context.set('focusedValue', first?.dataset.value ?? null);\n      },\n\n      setFocusedValue: ({ context, event }) => {\n        if (event.type === 'ITEM.FOCUS') {\n          context.set('focusedValue', event.value);\n        }\n      },\n\n      focusItem: ({ event, scope, prop }) => {\n        if (event.type !== 'NAVIGATE') {\n          return;\n        }\n        const items = getItems(scope);\n        if (items.length === 0) {\n          return;\n        }\n        const active = scope.getActiveElement();\n        const index = items.findIndex((item) => item === active || (active !== null && item.contains(active)));\n        const last = items.length - 1;\n        const loop = prop('loop');\n        const target = (() => {\n          switch (event.direction) {\n            case 'first':\n              return 0;\n            case 'last':\n              return last;\n            case 'next':\n              return index >= last ? (loop ? 0 : last) : index + 1;\n            case 'prev':\n              return index <= 0 ? (loop ? last : 0) : index - 1;\n          }\n        })();\n        items[target]?.focus();\n      },\n    },\n  },\n});\n\n/** Keyboard event fields the root handler reads; a React or DOM event both satisfy it. */\ntype KeyEvent = { key: string; target: EventTarget | null; preventDefault: () => void };\n\n// Arrow, Home and End keys belong to a text field's caret, so they never move focus out of one.\nconst isTextEntry = (target: EventTarget | null) =>\n  target instanceof HTMLTextAreaElement ||\n  (target instanceof HTMLElement && target.isContentEditable) ||\n  (target instanceof HTMLInputElement && !['button', 'checkbox', 'radio', 'submit', 'reset'].includes(target.type));\n\nexport type ToolbarApi = {\n  focusedValue: string | null;\n  orientation: Orientation;\n  disabled: boolean;\n  getRootProps: () => {\n    'id': string;\n    'role': 'toolbar';\n    'aria-orientation': Orientation;\n    'aria-disabled'?: true;\n    'data-disabled'?: '';\n    'data-scope': 'toolbar';\n    'data-part': 'root';\n    'data-orientation': Orientation;\n    'onKeyDown': (event: KeyEvent) => void;\n  };\n  /** No `id`: items are found by `data-toolbar-item`, so a composing machine (Select, Tooltip) keeps its own ids. */\n  getItemProps: (options: { value: string; disabled?: boolean }) => {\n    /** Present only while the whole toolbar is disabled, so it never re-enables an item disabled on its own. */\n    'disabled'?: true;\n    'tabIndex': number;\n    'data-toolbar-item': string;\n    'data-value': string;\n    'onFocus': () => void;\n  };\n};\n\nexport const connect = (service: ToolbarService): ToolbarApi => {\n  const { context, prop, scope, send } = service;\n  const focusedValue = context.get('focusedValue');\n  const orientation = prop('orientation') ?? 'horizontal';\n  const rootDisabled = !!prop('disabled');\n  const keys: Record<string, Direction> =\n    orientation === 'horizontal'\n      ? { ArrowRight: 'next', ArrowLeft: 'prev', Home: 'first', End: 'last' }\n      : { ArrowDown: 'next', ArrowUp: 'prev', Home: 'first', End: 'last' };\n\n  return {\n    focusedValue,\n    orientation,\n    disabled: rootDisabled,\n    getRootProps: () => ({\n      'id': getRootId(scope),\n      'role': 'toolbar',\n      'aria-orientation': orientation,\n      ...(rootDisabled && { 'aria-disabled': true as const, 'data-disabled': '' as const }),\n      'data-scope': 'toolbar',\n      'data-part': 'root',\n      'data-orientation': orientation,\n      'onKeyDown': (event) => {\n        const direction = keys[event.key];\n        if (!direction || isTextEntry(event.target)) {\n          return;\n        }\n        event.preventDefault();\n        send({ type: 'NAVIGATE', direction });\n      },\n    }),\n    getItemProps: ({ value, disabled }) => ({\n      ...(rootDisabled && { disabled: true as const }),\n      // Until an item is known every item stays tabbable, so the toolbar is never unreachable.\n      'tabIndex': disabled || rootDisabled ? -1 : focusedValue === null || focusedValue === value ? 0 : -1,\n      'data-toolbar-item': getRootId(scope),\n      'data-value': value,\n      'onFocus': () => send({ type: 'ITEM.FOCUS', value }),\n    }),\n  };\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { ark } from '@ark-ui/react/factory';\nimport { useMachine } from '@zag-js/react';\nimport React, { type AnchorHTMLAttributes, type HTMLAttributes, forwardRef, useContext, useId } from 'react';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { composable, composableProps, slottable } from '../../util/slots.ts';\nimport * as ScrollArea from '../ScrollArea/ScrollArea.tsx';\nimport { Separator, type SeparatorProps } from '../Separator/Separator.tsx';\nimport * as ToggleGroup from '../ToggleGroup/ToggleGroup.tsx';\nimport { ToolbarContext, useToolbarItem } from './toolbar-context.ts';\nimport * as toolbar from './toolbar-machine.ts';\n\n//\n// Root\n//\n\ntype ToolbarRootProps = {\n  size?: Size;\n  orientation?: toolbar.Orientation;\n  /** Arrow keys wrap from the last item to the first and back; on by default. */\n  loop?: boolean;\n  /** Disables every control in the toolbar. */\n  disabled?: boolean;\n  /**\n   * Dims the controls without disabling them, for a toolbar whose host is not in play (an unattended plank): they stay\n   * operable, so the first press both brings the host into play and acts.\n   */\n  inactive?: boolean;\n};\n\n/**\n * The toolbar element as a composable part, so the ScrollArea viewport slot merges onto it (a plain `ark.div` gets the\n * dev warning wrapper, which breaks the frame's child rules).\n */\nconst ToolbarElement = composable<HTMLDivElement, HTMLAttributes<HTMLDivElement> & { asChild?: boolean }>(\n  (props, forwardedRef) => <ark.div {...composableProps(props)} ref={forwardedRef} />,\n);\n\n/**\n * `role=toolbar` with the roving focus that role promises (decision 9); items that overflow scroll along its axis in a\n * thin ScrollArea whose bar shows on hover, the toolbar itself being the viewport.\n */\nconst ToolbarRoot = slottable<HTMLDivElement, ToolbarRootProps>(\n  (\n    { children, asChild, size, orientation = 'horizontal', loop = true, disabled, inactive, ...props },\n    forwardedRef,\n  ) => {\n    const service = useMachine(toolbar.machine, { id: useId(), orientation, loop, disabled });\n    const api = toolbar.connect(service);\n    const { className, ...rest } = composableProps(props, { classNames: recipes.toolbar() });\n    const rootProps = api.getRootProps();\n    return (\n      <ToolbarContext.Provider value={api}>\n        <ScrollArea.Root size={size} width='thin' orientation={orientation} classNames={recipes.toolbarScroll()}>\n          <ScrollArea.Viewport asChild>\n            <ToolbarElement\n              asChild={asChild}\n              {...rest}\n              {...rootProps}\n              // A toolbar that is also a landmark (an app bar's `banner`) keeps the role it is given.\n              role={rest.role ?? rootProps.role}\n              data-size={size}\n              data-inactive={inactive ? '' : undefined}\n              classNames={className}\n              ref={forwardedRef}\n            >\n              {children}\n            </ToolbarElement>\n          </ScrollArea.Viewport>\n        </ScrollArea.Root>\n      </ToolbarContext.Provider>\n    );\n  },\n);\n\nToolbarRoot.displayName = 'Toolbar.Root';\n\n//\n// Separator\n//\n\ntype ToolbarSeparatorProps = Omit<SeparatorProps, 'orientation'> & {\n  /** `gap` is an empty spacer that grows, pushing the items after it to the toolbar's end. */\n  variant?: 'line' | 'gap';\n};\n\n/**\n * A rule across the toolbar's axis (vertical in a horizontal toolbar), or with `variant='gap'` a growing spacer; not an\n * item, so roving focus skips it.\n */\nconst ToolbarSeparator = composable<HTMLDivElement, ToolbarSeparatorProps>(({ variant, ...props }, forwardedRef) => {\n  const api = useContext(ToolbarContext);\n  if (variant === 'gap') {\n    const { className, ...rest } = composableProps(props, { classNames: recipes.toolbarGap() });\n    return <div {...rest} role='none' data-scope='toolbar' data-part='gap' className={className} ref={forwardedRef} />;\n  }\n\n  return (\n    <Separator\n      {...props}\n      orientation={api?.orientation === 'vertical' ? 'horizontal' : 'vertical'}\n      ref={forwardedRef}\n    />\n  );\n});\n\nToolbarSeparator.displayName = 'Toolbar.Separator';\n\n//\n// Text\n//\n\ntype ToolbarTextProps = {};\n\n/** A run of text that takes the free space and truncates; not an item, so roving focus skips it. */\nconst ToolbarText = slottable<HTMLDivElement, ToolbarTextProps>(({ children, asChild, ...props }, forwardedRef) => {\n  const { className, ...rest } = composableProps(props, { classNames: recipes.toolbarText() });\n  return (\n    <ark.div asChild={asChild} {...rest} data-scope='toolbar' data-part='text' className={className} ref={forwardedRef}>\n      {children}\n    </ark.div>\n  );\n});\n\nToolbarText.displayName = 'Toolbar.Text';\n\n//\n// Link\n//\n\ntype ToolbarLinkProps = AnchorHTMLAttributes<HTMLAnchorElement>;\n\n/** A link that is a toolbar item (roving focus); opens in a new tab by default, like the current `Link`. */\nconst ToolbarLink = composable<HTMLAnchorElement, ToolbarLinkProps>(\n  ({ children, target = '_blank', rel = 'noreferrer', onFocus, onClick, ...props }, forwardedRef) => {\n    const { disabled, ...toolbarItem } = useToolbarItem() ?? { disabled: undefined, onFocus: undefined };\n    const { className, ...rest } = composableProps<HTMLAnchorElement>(props, { classNames: recipes.toolbarLink() });\n    return (\n      <a\n        {...rest}\n        {...toolbarItem}\n        target={target}\n        rel={rel}\n        aria-disabled={disabled}\n        onFocus={(event) => {\n          onFocus?.(event);\n          toolbarItem.onFocus?.();\n        }}\n        onClick={(event) => {\n          if (disabled) {\n            event.preventDefault();\n            return;\n          }\n          onClick?.(event);\n        }}\n        data-scope='toolbar'\n        data-part='link'\n        className={className}\n        ref={forwardedRef}\n      >\n        {children}\n      </a>\n    );\n  },\n);\n\nToolbarLink.displayName = 'Toolbar.Link';\n\n//\n// ToggleGroup\n//\n\ntype ToolbarToggleGroupProps = ToggleGroup.RootProps;\n\n/** A ToggleGroup whose items join the toolbar's roving focus, so the group adds no tab stop or arrow handling of its own. */\nconst ToolbarToggleGroup = forwardRef<HTMLDivElement, ToolbarToggleGroupProps>((props, forwardedRef) => (\n  <ToggleGroup.Root {...props} rovingFocus={false} ref={forwardedRef} />\n));\n\nToolbarToggleGroup.displayName = 'Toolbar.ToggleGroup';\nexport type {\n  ToolbarLinkProps as LinkProps,\n  ToolbarRootProps as RootProps,\n  ToolbarSeparatorProps as SeparatorProps,\n  ToolbarTextProps as TextProps,\n  ToolbarToggleGroupProps as ToggleGroupProps,\n};\n\nexport {\n  ToolbarLink as Link,\n  ToolbarRoot as Root,\n  ToolbarSeparator as Separator,\n  ToolbarText as Text,\n  ToolbarToggleGroup as ToggleGroup,\n};\nexport * from './toolbar-context.ts';\n"],"mappings":";;;;;;;;;;;;;AAkCA,IAAM,aAAa,UAAiB,WAAW,MAAM;;AAGrD,IAAM,YAAY,UAAgC;CAChD,MAAM,OAAO,MAAM,QAAQ,UAAU,KAAK,CAAC;CAC3C,IAA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