# Selection Actions

A toolbar of AI actions that appears under the text a person selects.

A floating toolbar of AI actions that appears under the text a person selects. Select part of the passage and a pill of actions hangs under the selection, centred on it; run one and the toolbar shows a shimmering status while the result streams into the passage in place of the selection, then offers Keep, Discard and Try again. Positioned by the Zag popover machine (through Ark UI in React, Vue and Svelte); it is a toolbar: one tab stop, arrows move between actions, Escape dismisses and gives the selection back. It scales out of the selection when the text was selected with a pointer and appears instantly from the keyboard.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `popover` machine, through Ark UI

## Add

```bash
npx fndn add selection-actions
```

It writes the folder `selection-actions/` into the project's ui folder (`index.ts`, `selection-actions.tsx`, `SelectionActions.vue`, `SelectionActions.svelte`, `selection-actions.recipe.ts`), and what it is built from: [Button](/components/button.md), [Shimmer](/components/shimmer.md), [Spinner](/components/spinner.md), [Streaming Text](/components/streaming-text.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { SelectionActions } from "@/components/ui/selection-actions";
```

```vue
import { SelectionActions } from "@/components/ui/selection-actions";
```

```svelte
import { SelectionActions } from "$lib/components/ui/selection-actions";
```

## Parts

In the DOM the root carries `data-slot="selection-actions"` and each part `data-slot="selection-actions-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `selection-actions` |  | data-slot="selection-actions"; the passage wrapper |
| `text` | `div` | `selection-actions-text` |  | The passage, and the popover's anchor. Focusable (tabindex=-1) so Escape, Keep and Discard can hand the selection back. |
| `mark` | `mark` | `selection-actions-mark` | optional | The selection, highlighted while the toolbar is open (the recipe open variant). It holds the original text, then the streamed result. Streaming-text caret part (data-slot="streaming-text-caret", that recipe caret classes) follows the result while busy. |
| `positioner` | `div` | `selection-actions-positioner` |  | The engine positioner (Zag places it under the selection; rendered in a portal; stacked by base.css). |
| `content` | `div` | `selection-actions-content` |  | Inside the positioner. role=toolbar; the shared popup surface (`lib/popup.ts`: motion, keyboard-instant; stacking from base.css); data-state=open\|closed (Zag). What stays its own: a 36px pill (radius.pill, not the card radius), shadow.overlay, a sideways scroll. |
| `action` | `button` | `selection-actions-action` | repeats | The real Button (ghost, sm, with an icon), marked data-selection-actions="action"; data-value |
| `status` | `span` | `selection-actions-status` |  | role=status while busy: the Spinner (sm, decorative) and the busy label (a Shimmer until the result starts streaming) |
| `label` | `span` | `selection-actions-label` | optional | The busy label once the result streams |
| `keep` | `button` | `selection-actions-keep` |  | The real Button (primary, sm), marked data-selection-actions="keep" |
| `discard` | `button` | `selection-actions-discard` |  | The real Button (ghost, sm), marked data-selection-actions="discard" |
| `separator` | `span` | `selection-actions-separator` |  |  |
| `retry` | `button` | `selection-actions-retry` |  | The real Button (ghost, sm, square), marked data-selection-actions="retry"; aria-label Try again |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` |  | Bindable (React: `defaultText` and `onTextChange`; Vue: `v-model:text`; Svelte: `bind:text`). The passage. Keep writes the result into it. |
| `selection` | `object` |  | Bindable (React: `defaultSelection` and `onSelectionChange`; Vue: `v-model:selection`; Svelte: `bind:selection`). { start, end } character offsets into text, or null. Set by selecting in the passage. |
| `open` | `boolean` | `false` | Bindable (React: `defaultOpen` and `onOpenChange`; Vue: `v-model:open`; Svelte: `bind:open`). The toolbar is showing. Opens when text is selected; closes on Escape, Tab, a press outside, Keep or Discard. |
| `result` | `string` | `""` | Bindable (React: `defaultResult` and `onResultChange`; Vue: `v-model:result`; Svelte: `bind:result`). The action's output, shown in place of the selection. Feed it as it streams; Keep, Discard and closing clear it. |
| `busy` | `boolean` | `false` | The action is running (status in the toolbar, caret after the streamed result). |
| `actions` | `{ value: string; label: string; icon?: 'question' \| 'sparkle' \| 'corners-in' \| 'chat-text' \| 'text-aa' \| 'magic-wand' \| 'pencil-simple' \| 'list-bullets'; busyLabel?: string }[]` |  | The actions offered while idle. busyLabel is the status while it runs (default Editing). |
| `busyLabel` | `string` |  | Overrides the status label while busy (an ellipsis is added). |
| `aria-label` | `string` | `"Edit selection"` | Name of the toolbar. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `textChange` | (text: string) Keep |
| `selectionChange` | (selection: { start, end } \| null) |
| `openChange` | (open: boolean) |
| `resultChange` | (result: string) cleared by Keep, Discard, Try again and closing |
| `action` | ({ value, text }) an action or Try again; text is the selected original |
| `keep` | ({ text, result }) the passage now holds the result |
| `discard` | () Discard, or closing while busy or holding a result |

## States

`open`, `busy`, `result`, `hover`, `press`, `focus-visible`

## Keyboard and accessibility

Role: toolbar (in a non-modal popover) anchored to a text selection.

Keyboard:

- Selecting text opens the toolbar: on pointer release, or on releasing Shift after a keyboard selection; focus moves to the first action
- The toolbar is one tab stop: ArrowRight / ArrowLeft move between buttons (wrapping, mirrored right-to-left), Home / End jump
- Enter / Space run the focused action; when the buttons change (running, result) focus moves to the first new one, or to the toolbar while busy
- Escape closes the toolbar, focuses the passage and selects the same text again
- Keep / Discard close the toolbar and select the kept or original text
- Tab closes the toolbar and returns to the passage with the selection given back (the toolbar sits at the end of the page, so Tab would otherwise only come back to it); the next Tab moves on

Notes:

- The status is role=status, so the busy label is announced; the streamed text itself is not announced word by word.
- Try again is icon-only: aria-label Try again.
- The passage takes focus programmatically (tabindex=-1); the restored selection is its focus indicator.

## Motion

- toolbar: the shared popup recipe (`popup`): opacity + scale from motion.popup-scale out of --transform-origin, duration.popup, easing.out-strong when the text was selected with a pointer; instant from the keyboard; closes at duration.fast
- mode swap (idle → busy → result): the new controls fade in over duration.base under the pointer; instant from the keyboard; the bar's width eases to the new controls over duration.base (easing.out-strong) and stays centred under the selection (instant from the keyboard). Opening plays only the popup's entrance (the controls arrive with it)
- veils: the edge veils of a bar wider than the screen show at once while there is more on their side (data-overflow-start, data-overflow-end, set from the scroll position by lib/veil.ts, the same in every browser; no animation); not judged while the bar eases between widths; a bar that fits shows none
- mark: background over duration.base as it opens and closes; streamed words do not animate; the caret is streaming-text's
- buttons: the button component's press scale and colour; the spinner loops (it is the loading signal)

## Tokens

`color.surface`, `color.ink`, `color.ink-2`, `color.line`, `color.accent-tint`, `shadow.overlay`, `radius.pill`, `text.xs`, `text.sm`, `text.md`, `duration.base`, `easing.out-strong`

## Dependencies

- [Button](/components/button.md)
- [Shimmer](/components/shimmer.md)
- [Spinner](/components/spinner.md)
- [Streaming Text](/components/streaming-text.md)

## Examples

### Select any sentence to edit it

React · `select-text.tsx`

```tsx
import type { ComponentProps } from "react";
import { SelectionActions } from "@/components/ui/selection-actions";

type Props = ComponentProps<typeof SelectionActions>;

const actions: Props["actions"] = [
  { value: "explain", label: "Explain", icon: "question" },
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle",
    busyLabel: "Improving",
  },
  {
    value: "shorten",
    label: "Shorten",
    icon: "corners-in",
    busyLabel: "Shortening",
  },
  {
    value: "tone",
    label: "Tone",
    icon: "chat-text",
    busyLabel: "Changing tone",
  },
];

export default function SelectText() {
  return (
    <SelectionActions
      defaultText="Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning."
      actions={actions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `select-text.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { SelectionActions } from "@/components/ui/selection-actions";

const actions = [
  { value: "explain", label: "Explain", icon: "question" as const },
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle" as const,
    busyLabel: "Improving",
  },
  {
    value: "shorten",
    label: "Shorten",
    icon: "corners-in" as const,
    busyLabel: "Shortening",
  },
  {
    value: "tone",
    label: "Tone",
    icon: "chat-text" as const,
    busyLabel: "Changing tone",
  },
];

const text = ref("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");
</script>

<template>
  <SelectionActions
    v-model:text="text"
    :actions="actions"
    style="width: 420px"
  />
</template>
```

Svelte · `select-text.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { SelectionActions } from "$lib/components/ui/selection-actions";

  type Props = ComponentProps<typeof SelectionActions>;

  const actions: Props["actions"] = [
    { value: "explain", label: "Explain", icon: "question" },
    {
      value: "improve",
      label: "Improve",
      icon: "sparkle",
      busyLabel: "Improving",
    },
    {
      value: "shorten",
      label: "Shorten",
      icon: "corners-in",
      busyLabel: "Shortening",
    },
    {
      value: "tone",
      label: "Tone",
      icon: "chat-text",
      busyLabel: "Changing tone",
    },
  ];

  let text = $state("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");
</script>

<SelectionActions bind:text={text} actions={actions} style="width: 420px" />
```

### Rewrite a sentence in a support reply

React · `selected.tsx`

```tsx
import type { ComponentProps } from "react";
import { SelectionActions } from "@/components/ui/selection-actions";

type Props = ComponentProps<typeof SelectionActions>;

const actions: Props["actions"] = [
  { value: "explain", label: "Explain", icon: "question" },
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle",
    busyLabel: "Improving",
  },
  {
    value: "shorten",
    label: "Shorten",
    icon: "corners-in",
    busyLabel: "Shortening",
  },
  {
    value: "tone",
    label: "Tone",
    icon: "chat-text",
    busyLabel: "Changing tone",
  },
];

export default function Selected() {
  return (
    <SelectionActions
      defaultText="Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning."
      defaultSelection={{ start: 65, end: 195 }}
      defaultOpen
      actions={actions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `selected.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { SelectionActions } from "@/components/ui/selection-actions";

const actions = [
  { value: "explain", label: "Explain", icon: "question" as const },
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle" as const,
    busyLabel: "Improving",
  },
  {
    value: "shorten",
    label: "Shorten",
    icon: "corners-in" as const,
    busyLabel: "Shortening",
  },
  {
    value: "tone",
    label: "Tone",
    icon: "chat-text" as const,
    busyLabel: "Changing tone",
  },
];

const text = ref("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

const selection = ref({ start: 65, end: 195 });

const open = ref(true);
</script>

<template>
  <SelectionActions
    v-model:text="text"
    v-model:selection="selection"
    v-model:open="open"
    :actions="actions"
    style="width: 420px"
  />
</template>
```

Svelte · `selected.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { SelectionActions } from "$lib/components/ui/selection-actions";

  type Props = ComponentProps<typeof SelectionActions>;

  const actions: Props["actions"] = [
    { value: "explain", label: "Explain", icon: "question" },
    {
      value: "improve",
      label: "Improve",
      icon: "sparkle",
      busyLabel: "Improving",
    },
    {
      value: "shorten",
      label: "Shorten",
      icon: "corners-in",
      busyLabel: "Shortening",
    },
    {
      value: "tone",
      label: "Tone",
      icon: "chat-text",
      busyLabel: "Changing tone",
    },
  ];

  let text = $state("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

  let selection = $state({ start: 65, end: 195 });

  let open = $state(true);
</script>

<SelectionActions
  bind:text={text}
  bind:selection={selection}
  bind:open={open}
  actions={actions}
  style="width: 420px"
/>
```

### Waiting for the rewrite

React · `thinking.tsx`

```tsx
import type { ComponentProps } from "react";
import { SelectionActions } from "@/components/ui/selection-actions";

type Props = ComponentProps<typeof SelectionActions>;

const actions: Props["actions"] = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle",
    busyLabel: "Improving",
  },
];

export default function Thinking() {
  return (
    <SelectionActions
      defaultText="Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning."
      defaultSelection={{ start: 65, end: 195 }}
      defaultOpen
      busy
      busyLabel="Improving"
      actions={actions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `thinking.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { SelectionActions } from "@/components/ui/selection-actions";

const actions = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle" as const,
    busyLabel: "Improving",
  },
];

const text = ref("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

const selection = ref({ start: 65, end: 195 });

const open = ref(true);
</script>

<template>
  <SelectionActions
    v-model:text="text"
    v-model:selection="selection"
    v-model:open="open"
    busy
    busyLabel="Improving"
    :actions="actions"
    style="width: 420px"
  />
</template>
```

Svelte · `thinking.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { SelectionActions } from "$lib/components/ui/selection-actions";

  type Props = ComponentProps<typeof SelectionActions>;

  const actions: Props["actions"] = [
    {
      value: "improve",
      label: "Improve",
      icon: "sparkle",
      busyLabel: "Improving",
    },
  ];

  let text = $state("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

  let selection = $state({ start: 65, end: 195 });

  let open = $state(true);
</script>

<SelectionActions
  bind:text={text}
  bind:selection={selection}
  bind:open={open}
  busy
  busyLabel="Improving"
  actions={actions}
  style="width: 420px"
/>
```

### Rewrite streaming into the reply

React · `streaming.tsx`

```tsx
import type { ComponentProps } from "react";
import { SelectionActions } from "@/components/ui/selection-actions";

type Props = ComponentProps<typeof SelectionActions>;

const actions: Props["actions"] = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle",
    busyLabel: "Improving",
  },
];

export default function Streaming() {
  return (
    <SelectionActions
      defaultText="Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning."
      defaultSelection={{ start: 65, end: 195 }}
      defaultOpen
      busy
      busyLabel="Improving"
      defaultResult="Reminders set before 6 a.m. went out an hour late "
      actions={actions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `streaming.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { SelectionActions } from "@/components/ui/selection-actions";

const actions = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle" as const,
    busyLabel: "Improving",
  },
];

const text = ref("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

const selection = ref({ start: 65, end: 195 });

const open = ref(true);

const result = ref("Reminders set before 6 a.m. went out an hour late ");
</script>

<template>
  <SelectionActions
    v-model:text="text"
    v-model:selection="selection"
    v-model:open="open"
    busy
    busyLabel="Improving"
    v-model:result="result"
    :actions="actions"
    style="width: 420px"
  />
</template>
```

Svelte · `streaming.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { SelectionActions } from "$lib/components/ui/selection-actions";

  type Props = ComponentProps<typeof SelectionActions>;

  const actions: Props["actions"] = [
    {
      value: "improve",
      label: "Improve",
      icon: "sparkle",
      busyLabel: "Improving",
    },
  ];

  let text = $state("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

  let selection = $state({ start: 65, end: 195 });

  let open = $state(true);

  let result = $state("Reminders set before 6 a.m. went out an hour late ");
</script>

<SelectionActions
  bind:text={text}
  bind:selection={selection}
  bind:open={open}
  busy
  busyLabel="Improving"
  bind:result={result}
  actions={actions}
  style="width: 420px"
/>
```

### Keep or discard the rewrite

React · `result.tsx`

```tsx
import type { ComponentProps } from "react";
import { SelectionActions } from "@/components/ui/selection-actions";

type Props = ComponentProps<typeof SelectionActions>;

const actions: Props["actions"] = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle",
    busyLabel: "Improving",
  },
];

export default function Result() {
  return (
    <SelectionActions
      defaultText="Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning."
      defaultSelection={{ start: 65, end: 195 }}
      defaultOpen
      defaultResult="Reminders set before 6 a.m. went out an hour late after the daylight saving change. We shipped a fix this morning."
      actions={actions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `result.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { SelectionActions } from "@/components/ui/selection-actions";

const actions = [
  {
    value: "improve",
    label: "Improve",
    icon: "sparkle" as const,
    busyLabel: "Improving",
  },
];

const text = ref("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

const selection = ref({ start: 65, end: 195 });

const open = ref(true);

const result = ref("Reminders set before 6 a.m. went out an hour late after the daylight saving change. We shipped a fix this morning.");
</script>

<template>
  <SelectionActions
    v-model:text="text"
    v-model:selection="selection"
    v-model:open="open"
    v-model:result="result"
    :actions="actions"
    style="width: 420px"
  />
</template>
```

Svelte · `result.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { SelectionActions } from "$lib/components/ui/selection-actions";

  type Props = ComponentProps<typeof SelectionActions>;

  const actions: Props["actions"] = [
    {
      value: "improve",
      label: "Improve",
      icon: "sparkle",
      busyLabel: "Improving",
    },
  ];

  let text = $state("Thanks for flagging this, and sorry for the confusion on Monday. Reminders scheduled before 6 a.m. were going out an hour late after the daylight saving change, and we shipped a fix this morning.");

  let selection = $state({ start: 65, end: 195 });

  let open = $state(true);

  let result = $state("Reminders set before 6 a.m. went out an hour late after the daylight saving change. We shipped a fix this morning.");
</script>

<SelectionActions
  bind:text={text}
  bind:selection={selection}
  bind:open={open}
  bind:result={result}
  actions={actions}
  style="width: 420px"
/>
```

## Recipe

`selection-actions.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";
import { popup } from "../lib/popup";

/* selection-actions — a pill toolbar that hangs under a text selection.
 * Placement is the Zag popover machine's (anchored to the passage, getAnchorRect = the mark).
 * The toolbar lives in a portal, so nothing below it depends on the root being an ancestor.
 * A 36px pill wraps 28px controls at a 4px inset, so the controls' pill radius stays concentric.
 *
 * Composed parts, rendered by the adapter: the actions, Keep, Discard and Try again are Buttons
 * (sm; ghost, primary for Keep), restyled by the action/keep/discard/retry slots passed as their
 * class; while a rewrite runs the status shows a Spinner (sm) and a Shimmer (fast).
 * The Buttons are marked data-selection-actions="action|keep|discard|retry". The streaming caret in
 * the mark is streaming-text's caret part (its recipe's caret slot). */

/* Keep, Discard and the actions: capped width, a 14px icon */
const PILL_BUTTON = "max-w-[200px] [&>[data-slot=button-icon]]:text-[14px]";

export const selectionActions = tv({
  slots: {
    base: "block w-full max-w-[460px] min-w-0",
    /* the passage takes focus only to hand the selection back; the selection is the indicator */
    text: [
      "m-0 text-sm leading-[1.625] text-ink wrap-anywhere outline-none focus-visible:outline-none",
      "[@media(pointer:coarse)]:text-md",
    ],
    mark: [
      "rounded-[3px] bg-transparent text-inherit [-webkit-box-decoration-break:clone] [box-decoration-break:clone]",
      "motion-colors-base",
    ],
    /* the shared popup recipe (lib/popup.ts: surface, motion from the anchor, fast exit, keyboard-instant,
     * stacking). What differs is the toolbar's own: one 36px row of controls in a pill (not the
     * card radius), the heavier overlay shadow of a surface that floats over running text, and a
     * sideways scroll instead of a tall list. */
    /* the engine's positioner (placement and stacking come from Zag and base.css). While the bar eases
     * between widths it holds the widest of them (rovingToolbar), so it only passes the pointer
     * through; the bar takes it back */
    positioner: "pointer-events-none",
    content: [
      popup(), "flex items-center gap-0.5 w-max h-9",
      "overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
      "rounded-pill shadow-overlay",
      /* on a phone the bar is wider than the screen and scrolls; the edge it continues past fades
       * into the surface, so an action cut by the edge never reads as a stray letter. Two sticky
       * veils ride the scroller's edges. Each shows while there is more on its side, at once (no
       * time involved): data-overflow-start and data-overflow-end, kept in step with the scroll
       * position by watchVeils (lib/veil.ts, from rovingToolbar). A bar that fits shows nothing. */
      "before:content-[''] before:sticky before:z-1 before:flex-[0_0_20px] before:self-stretch before:-my-1 before:pointer-events-none before:opacity-0",
      "after:content-[''] after:sticky after:z-1 after:flex-[0_0_20px] after:self-stretch after:-my-1 after:pointer-events-none after:opacity-0",
      /* the margins net to nothing with the 2px gap: the actions do not move */
      "before:-start-1 before:ms-[-4px] before:me-[-18px] before:bg-[linear-gradient(to_var(--_end,right),var(--fndn-surface),transparent)]",
      "after:-end-1 after:ms-[-18px] after:me-[-4px] after:bg-[linear-gradient(to_var(--_start,left),var(--fndn-surface),transparent)]",
      "rtl:[--_end:left] rtl:[--_start:right]",
      "data-overflow-start:before:opacity-100 data-overflow-end:after:opacity-100",
      /* a mode swap (idle → busy → result) fades the new controls in; opening is the popup's own one
       * entrance (data-swapped is set only by a swap while open); from the keyboard it is instant */
      "[&>*]:shrink-0 [&[data-swapped]>*]:animate-[fndn-fade-in_var(--fndn-duration-base)_var(--fndn-easing-out-strong)_both]",
      "[:root[data-fndn-input=keyboard]_&>*]:animate-none",
      /* the bar's width eases between modes with the controls' fade (duration.base, out-strong): the
       * rovingToolbar helper holds the old width for a frame, then sets the new one; kbd-instant (from
       * popup) makes it a snap from the keyboard.
       * fndn-check-ok: the pill has to change width between modes; it is childless of layout
       * consequence (absolutely positioned popup) and kept to duration.base */
      "motion-size-base-out mx-auto pointer-events-auto",
    ],
    action: [PILL_BUTTON, "[&>[data-slot=button-icon]]:text-ink-2"],
    status: "inline-flex items-center gap-1.5 h-7 px-2.5 text-xs whitespace-nowrap text-ink-2",
    label: "text-ink-2",
    keep: PILL_BUTTON,
    discard: PILL_BUTTON,
    separator: "w-px h-4 mx-0.5 bg-line",
    /* Try again keeps the ghost Button's own ink */
    retry: "",
  },
  variants: {
    /* the selection is highlighted while the toolbar is open */
    open: { true: { mark: "bg-accent-tint" } },
  },
});

export type SelectionActionsRecipeProps = VariantProps<typeof selectionActions>;
```
