{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-shimmer",
  "title": "Text shimmer",
  "description": "Text that shows work going on, such as \"Thinking…\". While it loads, light moves over the words at an even pace (a band that passes, a glow, or a breath), and when the work ends they settle once at their full colour. It moves only on the compositor, so it keeps going while the page is busy.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/swap.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/text-shimmer.tsx",
      "content": "'use client'\n\nimport { SwapText, SwapTextStack } from '@/registry/lib/swap'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * Text that shows work going on, such as \"Thinking…\". While `loading`, light\n * moves over the words at an even pace; when the work ends they settle once\n * at their full colour. A label that changes crossfades as the Badge's and the\n * Button's do, and starts a new pass.\n *\n * The words are drawn twice while it runs: the copy underneath, which is the\n * one read, selected and drawn at rest, and a copy on top that carries the\n * light. In `sweep` and `glow` the top copy sits in a window as wide as the\n * words twice over and the band; the window slides across while the words in\n * it slide back as far, so they stand still. Everything moves on `translate`\n * and `opacity`, which run off the main thread, so the light keeps moving\n * while the page is busy with the work it shows. The loops pause rather than\n * stop, so what settles starts from wherever it was.\n */\n\n// The copy underneath. In `sweep` and `breathe` it fades down while the top copy is\n// already on, and comes back up before the top copy goes, so the words never dim\n// outside the light as it starts and stops.\nconst baseVariants = cva('inline-flex max-w-full min-w-0', {\n  variants: {\n    variant: {\n      sweep:\n        'transition-opacity duration-(--motion-exit-duration) ease-(--motion-exit-easing) group-data-loading/text-shimmer:opacity-35 group-data-loading/text-shimmer:duration-(--motion-enter-duration) group-data-loading/text-shimmer:ease-(--motion-enter-easing) motion-reduce:group-data-loading/text-shimmer:opacity-75 forced-colors:opacity-100',\n      glow: '',\n      breathe:\n        'transition-opacity duration-(--motion-exit-duration) ease-(--motion-exit-easing) group-data-loading/text-shimmer:opacity-50 motion-reduce:group-data-loading/text-shimmer:opacity-100 forced-colors:opacity-100',\n    },\n  },\n  defaultVariants: { variant: 'sweep' },\n})\n\n// The top layer: the band's window, or in `breathe` a layer over the words. One pass and\n// its rest, or one breath, take five `layout` durations, as the Progress's sheen does. A\n// new label flips `data-pass`, which runs the same loop under a second name and so starts\n// a new pass: the band's path is measured in the label's width.\nconst layerVariants = cva('pointer-events-none absolute select-none', {\n  variants: {\n    variant: {\n      // Light taken: under the band the words fade towards the page, so it shows on any\n      // colour and surface, and the words keep their full colour everywhere else.\n      sweep:\n        'inset-y-0 -start-[calc(100%+var(--text-shimmer-spread,2em)*3)] w-[calc(200%+var(--text-shimmer-spread,2em)*4)] opacity-0 transition-opacity delay-[calc(var(--motion-exit-duration)*0.9)] duration-[calc(var(--motion-exit-duration)*0.1)] group-data-loading/text-shimmer:opacity-100 group-data-loading/text-shimmer:transition-none [mask-image:linear-gradient(to_right,black_calc(50%-var(--text-shimmer-spread,2em)),transparent_50%,black_calc(50%+var(--text-shimmer-spread,2em)))] motion-reduce:[mask-image:none] forced-colors:[mask-image:none] motion-safe:animate-[kino-text-shimmer-sweep_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:animate-[kino-text-shimmer-sweep_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-safe:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-b_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-b_calc(var(--motion-layout-duration)*5)_linear_infinite_running]',\n      // Light added: the band lights the words up to `--text-shimmer-highlight`, the\n      // foreground by default, so it shows on muted text.\n      glow: 'inset-y-0 -start-[calc(100%+var(--text-shimmer-spread,2em)*3)] w-[calc(200%+var(--text-shimmer-spread,2em)*4)] text-(--text-shimmer-highlight,var(--foreground)) opacity-0 transition-opacity duration-(--motion-exit-duration) ease-(--motion-exit-easing) group-data-loading/text-shimmer:opacity-100 group-data-loading/text-shimmer:duration-(--motion-enter-duration) group-data-loading/text-shimmer:ease-(--motion-enter-easing) [mask-image:linear-gradient(to_right,transparent_calc(50%-var(--text-shimmer-spread,2em)),black_50%,transparent_calc(50%+var(--text-shimmer-spread,2em)))] motion-reduce:[mask-image:none] forced-colors:hidden motion-safe:animate-[kino-text-shimmer-sweep_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:animate-[kino-text-shimmer-sweep_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-safe:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-b_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-b_calc(var(--motion-layout-duration)*5)_linear_infinite_running]',\n      // Nothing travels: the whole line fades a little and comes back.\n      breathe:\n        'inset-0 flex opacity-0 motion-reduce:hidden transition-opacity delay-[calc(var(--motion-exit-duration)*0.9)] duration-[calc(var(--motion-exit-duration)*0.1)] group-data-loading/text-shimmer:opacity-100 group-data-loading/text-shimmer:transition-none',\n    },\n  },\n  defaultVariants: { variant: 'sweep' },\n})\n\n// The words on top. Under reduced motion nothing travels: in `sweep` and `glow` they\n// breathe in place over the copy underneath; `breathe` holds still. Their box is\n// worked out from the window's width, which Firefox can round a fraction of a pixel\n// under the words' own: they draw an ellipsis only once they measure cut, or it\n// would eat a letter the copy underneath shows whole (\"Failing tes…ts\").\nconst copyVariants = cva(\n  'flex [&_[data-slot=swap-text]_span]:text-clip [&_[data-slot=swap-text][data-cut=cut]_span]:text-ellipsis',\n  {\n    variants: {\n      variant: {\n        sweep:\n          'absolute inset-y-0 start-[calc(50%+var(--text-shimmer-spread,2em))] w-[calc(50%-var(--text-shimmer-spread,2em)*2)] motion-safe:animate-[kino-text-shimmer-sweep-text_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:animate-[kino-text-shimmer-sweep-text_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-safe:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-text-b_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-text-b_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-reduce:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_paused] motion-reduce:group-data-loading/text-shimmer:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_running] forced-colors:animate-none',\n        glow: 'absolute inset-y-0 start-[calc(50%+var(--text-shimmer-spread,2em))] w-[calc(50%-var(--text-shimmer-spread,2em)*2)] motion-safe:animate-[kino-text-shimmer-sweep-text_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:animate-[kino-text-shimmer-sweep-text_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-safe:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-text-b_calc(var(--motion-layout-duration)*5)_linear_infinite_paused] motion-safe:group-data-loading/text-shimmer:group-data-[pass=b]/text-shimmer:animate-[kino-text-shimmer-sweep-text-b_calc(var(--motion-layout-duration)*5)_linear_infinite_running] motion-reduce:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_paused] motion-reduce:group-data-loading/text-shimmer:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_running]',\n        breathe:\n          'min-w-0 flex-1 motion-safe:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_paused] motion-safe:group-data-loading/text-shimmer:animate-[kino-text-shimmer-breathe_calc(var(--motion-layout-duration)*5)_ease-in-out_infinite_running] forced-colors:animate-none',\n      },\n    },\n    defaultVariants: { variant: 'sweep' },\n  },\n)\n\nfunction TextShimmer({\n  className,\n  variant,\n  loading = true,\n  children,\n  render,\n  ...props\n}: Omit<PartProps<'span'>, 'className' | 'children'> &\n  VariantProps<typeof layerVariants> & {\n    className?: string\n    /** The status, such as \"Thinking…\". One line: it truncates, with the whole text as its `title`. */\n    children: string\n    /** Whether the work is going on, as a Button's `loading`. When it ends, the words settle at their full colour. */\n    loading?: boolean\n  }) {\n  // A new label while it loads starts a new pass. One that comes as the work ends waits, so\n  // the light settles from where it was; it starts a new pass if loading begins again.\n  const [pass, setPass] = useState({ text: children, second: false })\n  if (loading && pass.text !== children) setPass({ text: children, second: !pass.second })\n  const look = { variant: variant ?? 'sweep' }\n  return renderElement(\n    'span',\n    mergeProps(\n      {\n        'data-slot': 'text-shimmer',\n        'data-variant': look.variant,\n        'data-loading': loading ? '' : undefined,\n        'data-pass': pass.second ? 'b' : 'a',\n        className: cn(\n          'group/text-shimmer relative inline-flex w-fit max-w-full min-w-0 overflow-x-clip align-bottom [--text-shimmer-dir:1] rtl:[--text-shimmer-dir:-1]',\n          className,\n        ),\n        children: (\n          <SwapTextStack>\n            <span data-slot='text-shimmer-text' className={baseVariants(look)}>\n              <SwapText text={children} />\n            </span>\n            <span\n              aria-hidden\n              data-slot='text-shimmer-light'\n              className={layerVariants(look)}\n            >\n              <span className={copyVariants(look)}>\n                <SwapText text={children} />\n              </span>\n            </span>\n          </SwapTextStack>\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\nexport { TextShimmer }\n",
      "type": "registry:component",
      "target": "@components/kino/text-shimmer.tsx"
    }
  ],
  "css": {
    "@keyframes kino-text-shimmer-sweep": {
      "0%": {
        "translate": "0 0"
      },
      "65%, 100%": {
        "translate": "calc(50% * var(--text-shimmer-dir, 1)) 0"
      }
    },
    "@keyframes kino-text-shimmer-sweep-b": {
      "0%": {
        "translate": "0 0"
      },
      "65%, 100%": {
        "translate": "calc(50% * var(--text-shimmer-dir, 1)) 0"
      }
    },
    "@keyframes kino-text-shimmer-sweep-text": {
      "0%": {
        "translate": "0 0"
      },
      "65%, 100%": {
        "translate": "calc((-100% - var(--text-shimmer-spread, 2em) * 2) * var(--text-shimmer-dir, 1)) 0"
      }
    },
    "@keyframes kino-text-shimmer-sweep-text-b": {
      "0%": {
        "translate": "0 0"
      },
      "65%, 100%": {
        "translate": "calc((-100% - var(--text-shimmer-spread, 2em) * 2) * var(--text-shimmer-dir, 1)) 0"
      }
    },
    "@keyframes kino-text-shimmer-breathe": {
      "0%, 100%": {
        "opacity": "1"
      },
      "50%": {
        "opacity": "0"
      }
    }
  },
  "type": "registry:component"
}