{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "media-media-player",
  "type": "registry:component",
  "title": "MediaPlayer",
  "description": "A clip's poster and Mux's transport, on the app's clock",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-components.json",
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/media/src/internal.ts",
      "target": "@ui/gpuixui/media/internal.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { classesToStyle } from \"../tw/index.js\";\nimport type { Theme } from \"../tokens/index.js\";\n\nexport { ThemeProvider, useTheme } from \"../tokens/react.js\";\nexport type { Theme } from \"../tokens/index.js\";\n\nexport const recipeStyle = (recipe: string, theme: Theme): StyleDesc =>\n  classesToStyle(recipe, theme).style;\n"
    },
    {
      "path": "packages/media/src/media-player.tsx",
      "target": "@ui/gpuixui/media/media-player.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport {\n  useGpuix,\n  type ImgInstance,\n  type Props,\n  type PublicInstance,\n  type StyleDesc,\n} from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuLabel,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuTrigger,\n} from \"../components/dropdown-menu.js\";\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"../components/popover.js\";\nimport { Icon } from \"../icons/index.js\";\nimport { Button, IconButton } from \"../primitives/button.js\";\nimport { Slider } from \"../primitives/slider.js\";\nimport { keyboardFocusRing, targetSize, textStyle } from \"../tokens/index.js\";\nimport { cn } from \"../tw/index.js\";\nimport { Match } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport {\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n  type ReactElement,\n  type RefObject,\n} from \"react\";\nimport { recipeStyle, useTheme, type Theme } from \"./internal.js\";\nimport { accessibleName } from \"./name.js\";\nimport {\n  advancePlayhead,\n  clampPlayhead,\n  durationOf,\n  frameAtOf,\n  isFinished,\n  isFrame,\n  isScrubPress,\n  mediaPaint,\n  MEDIA_LARGE_SEEK_STEP_MS,\n  MEDIA_RATES,\n  MEDIA_SEEK_STEP_MS,\n  MEDIA_TICK_MS,\n  playerIntent,\n  qualityOf,\n  rateLabel,\n  rateOf,\n  restingState,\n  scrubPlayhead,\n  seekIntent,\n  stepOf,\n  toggleIntent,\n  volumeOf,\n  type MediaFrameAt,\n  type MediaIntent,\n  type MediaKey,\n  type MediaPointer,\n  type MediaPopup,\n  type MediaState,\n} from \"./player/logic.js\";\n\nexport type {\n  MediaFrame,\n  MediaFrameAt,\n  MediaIntent,\n  MediaPopup,\n} from \"./player/logic.js\";\n\nexport interface MediaPlayerSurface {\n  readonly onIntent: (intent: MediaIntent) => void;\n\n  readonly onVolume: (level: number) => void;\n  readonly onRate: (rate: number) => void;\n  readonly onQuality: (quality: string) => void;\n\n  readonly onPopup: (popup: MediaPopup | null) => void;\n\n  readonly onTrackDown: (event: MediaPointer) => void;\n  readonly onTrackMove: (event: MediaPointer) => void;\n  readonly onTrackUp: () => void;\n\n  readonly onActivity: () => void;\n\n  readonly onKey: (event: MediaKey) => void;\n\n  readonly registerRoot: (instance: PublicInstance | null) => void;\n  readonly registerTrack: (instance: PublicInstance | null) => void;\n}\n\nexport interface MediaPlayerProps extends Omit<Props, \"children\"> {\n  readonly duration: number;\n\n  readonly frameAt?: MediaFrameAt | null;\n\n  readonly alt: string;\n\n  readonly label?: string;\n\n  readonly width?: number;\n\n  readonly height?: number;\n\n  readonly buffered?: number;\n\n  readonly defaultPlayhead?: number;\n\n  readonly onPlayheadChange?: (playhead: number) => void;\n\n  readonly defaultPlaying?: boolean;\n\n  readonly onPlayingChange?: (playing: boolean) => void;\n\n  readonly defaultVolume?: number;\n\n  readonly onVolumeChange?: (volume: number) => void;\n\n  readonly defaultMuted?: boolean;\n\n  readonly onMutedChange?: (muted: boolean) => void;\n\n  readonly rates?: ReadonlyArray<number>;\n\n  readonly defaultRate?: number;\n\n  readonly onRateChange?: (rate: number) => void;\n\n  readonly qualities?: ReadonlyArray<string>;\n\n  readonly defaultQuality?: string;\n\n  readonly onQualityChange?: (quality: string) => void;\n\n  readonly tickMs?: number;\n\n  readonly seekStep?: number;\n\n  readonly largeSeekStep?: number;\n\n  readonly idleMs?: number;\n\n  readonly onFullscreenChange?: (fullscreen: boolean) => void;\n\n  readonly playLabel?: string;\n\n  readonly pauseLabel?: string;\n\n  readonly disabled?: boolean;\n  readonly className?: string;\n}\n\nconst DEFAULT_WIDTH = 640;\nconst DEFAULT_HEIGHT = 360;\nconst DEFAULT_LABEL = \"Media player\";\nconst DEFAULT_PLAY_LABEL = \"Play\";\nconst DEFAULT_PAUSE_LABEL = \"Pause\";\nconst DEFAULT_IDLE_MS = 3000;\nconst TRACK_HEIGHT = 4;\nconst THUMB_SIZE = 12;\nconst CENTER_PLAY_SIZE = 56;\nconst VOLUME_MAX = 100;\n\nconst sideOf = (value: number, fallback: number): number =>\n  Number.isFinite(value) && value > 0 ? value : fallback;\n\nconst trackWidthOf = (width: number, inset: number): number =>\n  Math.max(width - inset * 2, 0);\n\nconst frameStyle = (\n  theme: Theme,\n  width: number,\n  height: number,\n): StyleDesc => ({\n  position: \"relative\",\n  width,\n  height,\n  borderRadius: theme.radius.md,\n  backgroundColor: theme.colors.muted,\n  overflow: \"visible\",\n});\n\nconst posterStyle = (theme: Theme): StyleDesc => ({\n  position: \"absolute\",\n  top: 0,\n  left: 0,\n  width: \"100%\",\n  height: \"100%\",\n  borderRadius: theme.radius.md,\n  pointerEvents: \"none\",\n});\n\nconst scrimStyle = (theme: Theme, visible: boolean): StyleDesc => ({\n  position: \"absolute\",\n  left: 0,\n  right: 0,\n  bottom: 0,\n  height: theme.spacing[\"5xl\"],\n  borderBottomLeftRadius: theme.radius.md,\n  borderBottomRightRadius: theme.radius.md,\n  backgroundColor: theme.colors.background,\n  opacity: visible ? 0.82 : 0,\n  pointerEvents: \"none\",\n});\n\nconst centerStyle = (visible: boolean): StyleDesc => ({\n  position: \"absolute\",\n  top: 0,\n  left: 0,\n  right: 0,\n  bottom: 0,\n  display: \"flex\",\n  alignItems: \"center\",\n  justifyContent: \"center\",\n  opacity: visible ? 1 : 0,\n  pointerEvents: \"none\",\n});\n\nconst barStyle = (theme: Theme, visible: boolean): StyleDesc => ({\n  position: \"absolute\",\n  left: 0,\n  right: 0,\n  bottom: 0,\n  display: \"flex\",\n  flexDirection: \"column\",\n  gap: theme.spacing.xs,\n  padding: theme.spacing.md,\n  opacity: visible ? 1 : 0,\n  pointerEvents: visible ? \"auto\" : \"none\",\n});\n\nconst rowStyle = (theme: Theme): StyleDesc => ({\n  display: \"flex\",\n  flexDirection: \"row\",\n  alignItems: \"center\",\n  gap: theme.spacing.xs,\n});\n\nconst trackStyle = (theme: Theme, width: number): StyleDesc => ({\n  position: \"relative\",\n  width,\n  height: TRACK_HEIGHT,\n  borderRadius: TRACK_HEIGHT,\n  backgroundColor: theme.colors.muted,\n  pointerEvents: \"none\",\n});\n\nconst fillStyle = (\n  color: string,\n  width: number,\n  height: number,\n): StyleDesc => ({\n  position: \"absolute\",\n  top: 0,\n  left: 0,\n  width,\n  height,\n  borderRadius: height,\n  backgroundColor: color,\n  pointerEvents: \"none\",\n});\n\nconst rateRows = (\n  rate: number,\n  rates: ReadonlyArray<number>,\n  onRate: (rate: number) => void,\n): ReactElement => (\n  <DropdownMenuRadioGroup\n    label=\"Playback speed\"\n    value={String(rate)}\n    onValueChange={(value) => onRate(rateOf(Number(value)))}\n  >\n    {rates.map((value) => (\n      <DropdownMenuRadioItem key={value} value={String(value)}>\n        {rateLabel(value)}\n      </DropdownMenuRadioItem>\n    ))}\n  </DropdownMenuRadioGroup>\n);\n\nconst qualityRows = (\n  quality: string,\n  qualities: ReadonlyArray<string>,\n  onQuality: (quality: string) => void,\n): ReactElement | null =>\n  qualities.length === 0 ? null : (\n    <DropdownMenuRadioGroup\n      label=\"Quality\"\n      value={quality}\n      onValueChange={onQuality}\n    >\n      {qualities.map((value) => (\n        <DropdownMenuRadioItem key={value} value={value}>\n          {value}\n        </DropdownMenuRadioItem>\n      ))}\n    </DropdownMenuRadioGroup>\n  );\n\nconst popupOf = (state: MediaState, popup: MediaPopup): boolean =>\n  state.popup === popup;\n\nexport const renderMediaPlayer = (\n  props: MediaPlayerProps,\n  theme: Theme,\n  state: MediaState,\n  surface: MediaPlayerSurface,\n  poster: RefObject<ImgInstance | null>,\n): ReactElement => {\n  const {\n    duration,\n    frameAt,\n    alt,\n    label,\n    width = DEFAULT_WIDTH,\n    height = DEFAULT_HEIGHT,\n    buffered,\n    defaultPlayhead: _defaultPlayhead,\n    onPlayheadChange: _onPlayheadChange,\n    defaultPlaying: _defaultPlaying,\n    onPlayingChange: _onPlayingChange,\n    defaultVolume: _defaultVolume,\n    onVolumeChange: _onVolumeChange,\n    defaultMuted: _defaultMuted,\n    onMutedChange: _onMutedChange,\n    rates = MEDIA_RATES,\n    defaultRate: _defaultRate,\n    onRateChange: _onRateChange,\n    qualities = [],\n    defaultQuality: _defaultQuality,\n    onQualityChange: _onQualityChange,\n    tickMs: _tickMs,\n    seekStep = MEDIA_SEEK_STEP_MS,\n    largeSeekStep: _largeSeekStep,\n    idleMs: _idleMs,\n    onFullscreenChange: _onFullscreenChange,\n    playLabel,\n    pauseLabel,\n    disabled = false,\n    className,\n    style,\n    testId = \"media-player\",\n    ...rest\n  } = props;\n  const end = durationOf(duration);\n  const playhead = clampPlayhead(state.playhead, end);\n  const boxWidth = sideOf(width, DEFAULT_WIDTH);\n  const boxHeight = sideOf(height, DEFAULT_HEIGHT);\n  const barWidth = trackWidthOf(boxWidth, theme.spacing.md);\n  const paint = mediaPaint(\n    { ...state, playhead },\n    buffered ?? end,\n    end,\n    barWidth,\n    THUMB_SIZE,\n  );\n  const name = accessibleName(label, DEFAULT_LABEL);\n  const pictureName = accessibleName(alt, name);\n  const playWord = accessibleName(playLabel, DEFAULT_PLAY_LABEL);\n  const pauseWord = accessibleName(pauseLabel, DEFAULT_PAUSE_LABEL);\n  const frameSource = frameAtOf(frameAt);\n  const { playing } = state;\n  const visible = state.controls;\n  const muted = state.muted || state.volume === 0;\n  const level = Math.round(state.volume * VOLUME_MAX);\n  const quality = qualityOf(state.quality, qualities);\n  const ratesOffered = rates.length === 0 ? MEDIA_RATES : rates;\n  const onActivity = surface.onActivity;\n  const action = (intent: MediaIntent) => () => surface.onIntent(intent);\n\n  return (\n    <div\n      {...rest}\n      testId={testId}\n      ref={surface.registerRoot}\n      role=\"group\"\n      aria-label={name}\n      tabIndex={disabled ? -1 : 0}\n      onKeyDown={(event) => surface.onKey(event)}\n      onFocus={onActivity}\n      onMouseMove={onActivity}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(\"flex flex-col\", className), theme), {\n          ...frameStyle(theme, boxWidth, boxHeight),\n          ...(disabled ? {} : keyboardFocusRing(theme)),\n        }),\n        style,\n      )}\n    >\n      {frameSource === undefined ? null : (\n        <img\n          testId=\"media-poster\"\n          ref={poster}\n          alt={pictureName}\n          objectFit=\"cover\"\n          style={posterStyle(theme)}\n        />\n      )}\n      <div testId=\"media-scrim\" style={scrimStyle(theme, visible)} />\n      {!playing || visible ? (\n        <div style={centerStyle(!playing || visible)} onMouseMove={onActivity}>\n          {}\n          <div\n            style={{\n              position: \"absolute\",\n              width: CENTER_PLAY_SIZE,\n              height: CENTER_PLAY_SIZE,\n              borderRadius: CENTER_PLAY_SIZE / 2,\n              backgroundColor: theme.colors.secondary,\n              pointerEvents: \"none\",\n            }}\n          />\n          <IconButton\n            testId=\"media-play\"\n            label={playing ? pauseWord : playWord}\n            icon={\n              <Icon\n                name={playing ? \"pause\" : \"play\"}\n                color={theme.colors.secondaryForeground}\n                size={24}\n              />\n            }\n            size=\"lg\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action(toggleIntent)}\n            style={{\n              width: CENTER_PLAY_SIZE,\n              height: CENTER_PLAY_SIZE,\n              borderRadius: CENTER_PLAY_SIZE / 2,\n              hover: { backgroundColor: theme.colors.hover },\n              active: { backgroundColor: theme.colors.active },\n            }}\n          />\n        </div>\n      ) : null}\n      <div\n        testId=\"media-controls\"\n        onMouseMove={onActivity}\n        style={barStyle(theme, visible)}\n      >\n        <div\n          testId=\"media-track-hit\"\n          ref={surface.registerTrack}\n          role=\"slider\"\n          aria-label={`${name} position`}\n          aria-valuetext={paint.clock}\n          tabIndex={disabled ? -1 : 0}\n          onFocus={onActivity}\n          onMouseDown={\n            disabled ? undefined : (event) => surface.onTrackDown(event)\n          }\n          onMouseMove={\n            disabled ? undefined : (event) => surface.onTrackMove(event)\n          }\n          onMouseUp={() => surface.onTrackUp()}\n          onMouseLeave={() => surface.onTrackUp()}\n          style={{\n            display: \"flex\",\n            alignItems: \"center\",\n            height: targetSize.minimum,\n            cursor: disabled ? \"default\" : \"pointer\",\n            ...(disabled ? {} : keyboardFocusRing(theme)),\n          }}\n        >\n          <div testId=\"media-track\" style={trackStyle(theme, barWidth)}>\n            <div\n              testId=\"media-buffered\"\n              style={fillStyle(\n                theme.colors.mutedForeground,\n                paint.buffered,\n                TRACK_HEIGHT,\n              )}\n            />\n            <div\n              testId=\"media-fill\"\n              style={fillStyle(\n                theme.colors.primary,\n                paint.played,\n                TRACK_HEIGHT,\n              )}\n            />\n            <div\n              testId=\"media-thumb\"\n              style={{\n                position: \"absolute\",\n                top: (TRACK_HEIGHT - THUMB_SIZE) / 2,\n                left: paint.thumb,\n                width: THUMB_SIZE,\n                height: THUMB_SIZE,\n                borderRadius: THUMB_SIZE / 2,\n                backgroundColor: theme.colors.primary,\n                pointerEvents: \"none\",\n              }}\n            />\n          </div>\n        </div>\n        <div style={rowStyle(theme)}>\n          <IconButton\n            testId=\"media-play-bar\"\n            label={playing ? pauseWord : playWord}\n            icon={\n              <Icon\n                name={playing ? \"pause\" : \"play\"}\n                color={theme.colors.foreground}\n                size={16}\n              />\n            }\n            size=\"sm\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action(toggleIntent)}\n          />\n          <Button\n            testId=\"media-back\"\n            variant=\"ghost\"\n            size=\"sm\"\n            label=\"Seek back one second\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action(seekIntent(-seekStep))}\n          >\n            −1s\n          </Button>\n          <Button\n            testId=\"media-forward\"\n            variant=\"ghost\"\n            size=\"sm\"\n            label=\"Seek forward one second\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action(seekIntent(seekStep))}\n          >\n            +1s\n          </Button>\n          <text\n            testId=\"media-time\"\n            style={{\n              ...textStyle(theme, \"caption\"),\n              color: theme.colors.foreground,\n              fontFamily: theme.typography.mono,\n            }}\n          >\n            {paint.clock}\n          </text>\n          <div style={{ flexGrow: 1 }} />\n          <IconButton\n            testId=\"media-mute\"\n            label={muted ? \"Unmute\" : \"Mute\"}\n            icon={\n              <Icon\n                name={muted ? \"volume-x\" : \"volume-2\"}\n                color={theme.colors.foreground}\n                size={16}\n              />\n            }\n            size=\"sm\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action({ kind: \"mute\" })}\n          />\n          <Popover\n            open={popupOf(state, \"volume\")}\n            onOpenChange={(open) => surface.onPopup(open ? \"volume\" : null)}\n          >\n            <PopoverTrigger\n              testId=\"media-volume\"\n              variant=\"ghost\"\n              size=\"sm\"\n              square\n              label=\"Volume\"\n              disabled={disabled}\n              onFocus={onActivity}\n              leading={\n                <Icon\n                  name=\"sliders-horizontal\"\n                  color={theme.colors.foreground}\n                  size={16}\n                />\n              }\n            />\n            <PopoverContent\n              testId=\"media-volume-popover\"\n              side=\"top\"\n              align=\"center\"\n            >\n              <div\n                style={{\n                  display: \"flex\",\n                  flexDirection: \"column\",\n                  gap: theme.spacing.sm,\n                }}\n              >\n                <text\n                  style={{\n                    ...textStyle(theme, \"caption\"),\n                    color: theme.colors.mutedForeground,\n                  }}\n                >\n                  Volume {level}%\n                </text>\n                <Slider\n                  label=\"Volume\"\n                  value={level}\n                  min={0}\n                  max={VOLUME_MAX}\n                  step={1}\n                  formatValue={(value) => `${value}%`}\n                  disabled={disabled}\n                  onValueChange={(value) => surface.onVolume(value)}\n                />\n              </div>\n            </PopoverContent>\n          </Popover>\n          <DropdownMenu\n            open={popupOf(state, \"rate\")}\n            onOpenChange={(open) => surface.onPopup(open ? \"rate\" : null)}\n          >\n            <DropdownMenuTrigger\n              testId=\"media-rate\"\n              variant=\"ghost\"\n              size=\"sm\"\n              aria-label=\"Playback rate\"\n              disabled={disabled}\n              onFocus={onActivity}\n            >\n              {rateLabel(state.rate)}\n            </DropdownMenuTrigger>\n            <DropdownMenuContent\n              testId=\"media-rate-menu\"\n              side=\"top\"\n              align=\"end\"\n              label=\"Playback speed\"\n            >\n              <DropdownMenuLabel>Playback speed</DropdownMenuLabel>\n              {rateRows(state.rate, ratesOffered, surface.onRate)}\n            </DropdownMenuContent>\n          </DropdownMenu>\n          <DropdownMenu\n            open={popupOf(state, \"settings\")}\n            onOpenChange={(open) => surface.onPopup(open ? \"settings\" : null)}\n          >\n            <DropdownMenuTrigger\n              testId=\"media-settings\"\n              variant=\"ghost\"\n              size=\"sm\"\n              aria-label=\"Settings\"\n              disabled={disabled}\n              onFocus={onActivity}\n              leading={\n                <Icon\n                  name=\"settings\"\n                  color={theme.colors.foreground}\n                  size={16}\n                />\n              }\n            />\n            <DropdownMenuContent\n              testId=\"media-settings-menu\"\n              side=\"top\"\n              align=\"end\"\n              label=\"Settings\"\n            >\n              {qualityRows(quality, qualities, surface.onQuality)}\n              <DropdownMenuLabel>Playback speed</DropdownMenuLabel>\n              {rateRows(state.rate, ratesOffered, surface.onRate)}\n            </DropdownMenuContent>\n          </DropdownMenu>\n          <IconButton\n            testId=\"media-fullscreen\"\n            label={state.fullscreen ? \"Exit fullscreen\" : \"Fullscreen\"}\n            icon={\n              <Icon\n                name={state.fullscreen ? \"minimize\" : \"maximize\"}\n                color={theme.colors.foreground}\n                size={16}\n              />\n            }\n            size=\"sm\"\n            disabled={disabled}\n            onFocus={onActivity}\n            onActivate={action({ kind: \"fullscreen\" })}\n          />\n        </div>\n      </div>\n    </div>\n  );\n};\n\nexport const MediaPlayer = (props: MediaPlayerProps): ReactElement => {\n  const theme = useTheme();\n  const { renderer } = useGpuix();\n  const duration = durationOf(props.duration);\n  const tick = stepOf(props.tickMs ?? MEDIA_TICK_MS, MEDIA_TICK_MS);\n  const seekStep = stepOf(\n    props.seekStep ?? MEDIA_SEEK_STEP_MS,\n    MEDIA_SEEK_STEP_MS,\n  );\n  const largeStep = stepOf(\n    props.largeSeekStep ?? MEDIA_LARGE_SEEK_STEP_MS,\n    MEDIA_LARGE_SEEK_STEP_MS,\n  );\n  const idle = stepOf(props.idleMs ?? DEFAULT_IDLE_MS, DEFAULT_IDLE_MS);\n  const qualities = props.qualities ?? [];\n  const poster = useRef<ImgInstance | null>(null);\n  const rootId = useRef<number | null>(null);\n  const trackId = useRef<number | null>(null);\n  const scrubbing = useRef(false);\n  const [state, setState] = useState<MediaState>(() =>\n    restingState({\n      duration,\n      playhead: props.defaultPlayhead,\n      playing: props.defaultPlaying,\n      volume: props.defaultVolume,\n      muted: props.defaultMuted,\n      rate: props.defaultRate,\n      quality: props.defaultQuality,\n      qualities,\n      controls: true,\n    }),\n  );\n  const stateRef = useRef(state);\n  const [activity, setActivity] = useState(0);\n\n  const reports = useRef({\n    onPlayheadChange: props.onPlayheadChange,\n    onPlayingChange: props.onPlayingChange,\n    onVolumeChange: props.onVolumeChange,\n    onMutedChange: props.onMutedChange,\n    onRateChange: props.onRateChange,\n    onQualityChange: props.onQualityChange,\n    onFullscreenChange: props.onFullscreenChange,\n  });\n  useEffect(() => {\n    reports.current = {\n      onPlayheadChange: props.onPlayheadChange,\n      onPlayingChange: props.onPlayingChange,\n      onVolumeChange: props.onVolumeChange,\n      onMutedChange: props.onMutedChange,\n      onRateChange: props.onRateChange,\n      onQualityChange: props.onQualityChange,\n      onFullscreenChange: props.onFullscreenChange,\n    };\n  });\n\n  const wake = (): void => {\n    if (!stateRef.current.controls) {\n      stateRef.current = { ...stateRef.current, controls: true };\n      setState(stateRef.current);\n    }\n    setActivity((current) => current + 1);\n  };\n\n  const commit = (next: MediaState): void => {\n    const current = stateRef.current;\n    const settled = restingState({\n      duration,\n      playhead: next.playhead,\n      playing: next.playing,\n      volume: next.volume,\n      muted: next.muted,\n      rate: next.rate,\n      quality: next.quality,\n      qualities,\n      fullscreen: next.fullscreen,\n      controls: next.controls,\n      popup: next.popup,\n    });\n    if (\n      settled.playing === current.playing &&\n      settled.playhead === current.playhead &&\n      settled.volume === current.volume &&\n      settled.muted === current.muted &&\n      settled.rate === current.rate &&\n      settled.quality === current.quality &&\n      settled.fullscreen === current.fullscreen &&\n      settled.controls === current.controls &&\n      settled.popup === current.popup\n    ) {\n      return;\n    }\n    stateRef.current = settled;\n    setState(settled);\n    const report = reports.current;\n    if (settled.playhead !== current.playhead) {\n      report.onPlayheadChange?.(settled.playhead);\n    }\n    if (settled.playing !== current.playing) {\n      report.onPlayingChange?.(settled.playing);\n    }\n    if (settled.volume !== current.volume) {\n      report.onVolumeChange?.(settled.volume);\n    }\n    if (settled.muted !== current.muted) {\n      report.onMutedChange?.(settled.muted);\n    }\n    if (settled.rate !== current.rate) {\n      report.onRateChange?.(settled.rate);\n    }\n    if (settled.quality !== current.quality) {\n      report.onQualityChange?.(settled.quality);\n    }\n    if (settled.fullscreen !== current.fullscreen) {\n      report.onFullscreenChange?.(settled.fullscreen);\n    }\n  };\n\n  useEffect(() => {\n    if (!state.playing || props.disabled === true) return undefined;\n    const timer = setInterval(() => {\n      const current = stateRef.current;\n      commit({\n        ...current,\n        playhead: advancePlayhead(\n          current.playhead,\n          tick * current.rate,\n          duration,\n        ),\n      });\n    }, tick);\n    return () => clearInterval(timer);\n  }, [state.playing, props.disabled, tick, duration]);\n\n  useEffect(() => {\n    if (state.playing && isFinished(state.playhead, duration)) {\n      commit({ ...stateRef.current, playing: false });\n    }\n  }, [state.playing, state.playhead, duration]);\n\n  useEffect(() => {\n    if (props.disabled === true && stateRef.current.playing) {\n      commit({ ...stateRef.current, playing: false });\n    }\n    if (props.disabled === true) scrubbing.current = false;\n  }, [props.disabled]);\n\n  useEffect(() => {\n    const current = stateRef.current;\n    const clamped = clampPlayhead(current.playhead, duration);\n    if (current.playhead !== clamped) {\n      commit({ ...current, playhead: clamped });\n    }\n  }, [duration]);\n\n  useEffect(() => {\n    if (state.popup !== null || !state.controls || props.disabled === true) {\n      return undefined;\n    }\n    const timer = setTimeout(\n      () => commit({ ...stateRef.current, controls: false }),\n      idle,\n    );\n    return () => clearTimeout(timer);\n  }, [state.controls, state.popup, activity, idle, props.disabled]);\n\n  useLayoutEffect(() => {\n    const instance = poster.current;\n    const frameAt = frameAtOf(props.frameAt);\n    if (instance === null || frameAt === undefined) return;\n    Option.match(Option.filter(frameAt(state.playhead), isFrame), {\n      onNone: () => undefined,\n      onSome: (frame) =>\n        instance.setImagePixels(frame.width, frame.height, frame.pixels),\n    });\n  }, [state.playhead, props.frameAt]);\n\n  const scrub = (event: MediaPointer): void => {\n    if (trackId.current === null) return;\n    const box = renderer?.getElementBounds?.(trackId.current);\n    if (box === null || box === undefined) return;\n    Option.match(\n      scrubPlayhead(event.x ?? box.x, { x: box.x, width: box.width }, duration),\n      {\n        onNone: () => undefined,\n        onSome: (next) => commit({ ...stateRef.current, playhead: next }),\n      },\n    );\n  };\n\n  const apply = (intent: MediaIntent): void => {\n    if (props.disabled === true) return;\n    wake();\n    const current = stateRef.current;\n    Match.value(intent).pipe(\n      Match.discriminatorsExhaustive(\"kind\")({\n        toggle: () => {\n          if (current.playing) {\n            commit({ ...current, playing: false });\n            return;\n          }\n          if (duration <= 0) return;\n\n          commit({\n            ...current,\n            playing: true,\n            playhead: isFinished(current.playhead, duration)\n              ? 0\n              : current.playhead,\n          });\n        },\n        seek: (move) => {\n          commit({\n            ...current,\n            playhead: advancePlayhead(current.playhead, move.delta, duration),\n          });\n        },\n        seekTo: (move) => {\n          commit({\n            ...current,\n            playhead: move.edge === \"start\" ? 0 : duration,\n          });\n        },\n        volume: (move) => {\n          commit({\n            ...current,\n            volume: volumeOf(current.volume + move.delta),\n            muted: move.delta > 0 ? false : current.muted,\n          });\n        },\n        mute: () => {\n          commit({ ...current, muted: !current.muted });\n        },\n        fullscreen: () => {\n          renderer?.toggleFullscreen?.();\n          commit({ ...current, fullscreen: !current.fullscreen });\n        },\n      }),\n    );\n  };\n\n  const surface: MediaPlayerSurface = {\n    onIntent: apply,\n    onVolume: (level) => {\n      wake();\n      commit({ ...stateRef.current, volume: volumeOf(level / VOLUME_MAX) });\n    },\n    onRate: (rate) => {\n      wake();\n      commit({ ...stateRef.current, rate: rateOf(rate) });\n    },\n    onQuality: (quality) => {\n      wake();\n      commit({ ...stateRef.current, quality: qualityOf(quality, qualities) });\n    },\n    onPopup: (popup) => {\n      wake();\n      commit({ ...stateRef.current, popup, controls: true });\n    },\n\n    onTrackDown: (event) => {\n      if (props.disabled === true || !isScrubPress(event.button)) return;\n      wake();\n      scrubbing.current = true;\n      scrub(event);\n    },\n\n    onTrackMove: (event) => {\n      if (props.disabled === true) return;\n      wake();\n      if (!scrubbing.current) return;\n      if (event.pressedButton !== 0) {\n        scrubbing.current = false;\n        return;\n      }\n      scrub(event);\n    },\n    onTrackUp: () => {\n      scrubbing.current = false;\n    },\n    onActivity: wake,\n    onKey: (event) => {\n      const key = (event.key ?? \"\").toLowerCase();\n\n      const focused = renderer?.getFocusedElementId?.() ?? null;\n      const transport =\n        focused === rootId.current || focused === trackId.current;\n      if (key === \"space\" && !transport) return;\n      Option.match(\n        playerIntent(key, event.modifiers?.shift === true, seekStep, largeStep),\n        {\n          onNone: () => undefined,\n          onSome: (intent) => {\n            event.preventDefault?.();\n            apply(intent);\n          },\n        },\n      );\n    },\n    registerRoot: (instance) => {\n      rootId.current = instance?.id ?? null;\n    },\n    registerTrack: (instance) => {\n      trackId.current = instance?.id ?? null;\n    },\n  };\n\n  return renderMediaPlayer(props, theme, state, surface, poster);\n};\n"
    },
    {
      "path": "packages/media/src/name.ts",
      "target": "@ui/gpuixui/media/name.ts",
      "type": "registry:lib",
      "content": "import * as Str from \"effect/String\";\n\nexport const accessibleName = (label: unknown, fallback: string): string => {\n  const text = typeof label === \"string\" ? Str.trim(label) : \"\";\n  return Str.isEmpty(text) ? fallback : text;\n};\n\nexport const PICTURE_NAME = \"Picture\";\n"
    },
    {
      "path": "packages/media/src/player/logic.ts",
      "target": "@ui/gpuixui/media/player/logic.ts",
      "type": "registry:lib",
      "content": "import { Match } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport * as P from \"effect/Predicate\";\nimport * as Str from \"effect/String\";\n\nexport const MEDIA_TICK_MS = 100;\n\nexport const MEDIA_SEEK_STEP_MS = 1000;\n\nexport const MEDIA_LARGE_SEEK_STEP_MS = 10_000;\n\nexport const MEDIA_RATES: ReadonlyArray<number> = [0.5, 1, 1.5, 2];\n\nexport const MEDIA_VOLUME_STEP = 0.05;\n\nexport type MediaPopup = \"volume\" | \"rate\" | \"settings\";\n\nexport interface MediaState {\n  readonly playing: boolean;\n  readonly playhead: number;\n\n  readonly volume: number;\n  readonly muted: boolean;\n  readonly rate: number;\n\n  readonly quality: string;\n  readonly fullscreen: boolean;\n\n  readonly controls: boolean;\n\n  readonly popup: MediaPopup | null;\n}\n\nexport interface MediaFrame {\n  readonly width: number;\n  readonly height: number;\n\n  readonly pixels: Uint8Array;\n}\n\nexport type MediaFrameAt = (playhead: number) => Option.Option<MediaFrame>;\n\nexport const frameAtOf = (\n  value: MediaFrameAt | null | undefined,\n): MediaFrameAt | undefined =>\n  typeof value === \"function\" ? value : undefined;\n\nexport const isFrame = (frame: unknown): frame is MediaFrame => {\n  if (!P.isObject(frame)) return false;\n  const width: unknown = frame.width;\n  const height: unknown = frame.height;\n  const pixels: unknown = frame.pixels;\n  return (\n    P.isNumber(width) &&\n    width > 0 &&\n    P.isNumber(height) &&\n    height > 0 &&\n    pixels instanceof Uint8Array &&\n    pixels.length >= width * height * 4\n  );\n};\n\nexport const durationOf = (duration: number): number =>\n  Number.isFinite(duration) && duration > 0 ? duration : 0;\n\nexport const stepOf = (value: number, fallback: number): number =>\n  Number.isFinite(value) && value > 0 ? value : fallback;\n\nexport const clampPlayhead = (playhead: number, duration: number): number => {\n  const end = durationOf(duration);\n  const at = Number.isFinite(playhead) ? playhead : 0;\n  return Math.min(Math.max(at, 0), end);\n};\n\nexport const advancePlayhead = (\n  playhead: number,\n  delta: number,\n  duration: number,\n): number =>\n  clampPlayhead(\n    clampPlayhead(playhead, duration) + (Number.isFinite(delta) ? delta : 0),\n    duration,\n  );\n\nexport const isFinished = (playhead: number, duration: number): boolean =>\n  durationOf(duration) > 0 && clampPlayhead(playhead, duration) >= duration;\n\nexport const volumeOf = (volume: number): number =>\n  Number.isFinite(volume) ? Math.min(Math.max(volume, 0), 1) : 0;\n\nexport const rateOf = (rate: number): number =>\n  Number.isFinite(rate) && rate > 0 ? rate : 1;\n\nexport const qualityOf = (\n  quality: string,\n  qualities: ReadonlyArray<string>,\n): string => {\n  const trimmed = Str.trim(quality);\n  if (Arr.length(qualities) === 0) return \"\";\n  return Arr.contains(qualities, trimmed) ? trimmed : (qualities[0] ?? \"\");\n};\n\nexport const rateLabel = (rate: number): string => `${rateOf(rate)}×`;\n\nexport const restingState = (options: {\n  readonly duration: number;\n  readonly playhead?: number;\n  readonly playing?: boolean;\n  readonly volume?: number;\n  readonly muted?: boolean;\n  readonly rate?: number;\n  readonly quality?: string;\n  readonly qualities?: ReadonlyArray<string>;\n  readonly fullscreen?: boolean;\n  readonly controls?: boolean;\n  readonly popup?: MediaPopup | null;\n}): MediaState => ({\n  playing: options.playing === true && durationOf(options.duration) > 0,\n  playhead: clampPlayhead(options.playhead ?? 0, options.duration),\n  volume: volumeOf(options.volume ?? 1),\n  muted: options.muted === true,\n  rate: rateOf(options.rate ?? 1),\n  quality: qualityOf(options.quality ?? \"\", options.qualities ?? []),\n  fullscreen: options.fullscreen === true,\n  controls: options.controls !== false,\n  popup: options.popup ?? null,\n});\n\nexport type MediaIntent =\n  | { readonly kind: \"toggle\" }\n  | { readonly kind: \"seek\"; readonly delta: number }\n  | { readonly kind: \"seekTo\"; readonly edge: \"start\" | \"end\" }\n  | { readonly kind: \"volume\"; readonly delta: number }\n  | { readonly kind: \"mute\" }\n  | { readonly kind: \"fullscreen\" };\n\nexport const toggleIntent: MediaIntent = { kind: \"toggle\" };\n\nexport const seekIntent = (delta: number): MediaIntent => ({\n  kind: \"seek\",\n  delta,\n});\n\nexport const playerIntent = (\n  key: string,\n  shift: boolean,\n  seekStep: number,\n  largeStep: number,\n): Option.Option<MediaIntent> => {\n  const small = stepOf(seekStep, MEDIA_SEEK_STEP_MS);\n  const large = stepOf(largeStep, MEDIA_LARGE_SEEK_STEP_MS);\n  return Match.value(key).pipe(\n    Match.when(\"space\", () => Option.some(toggleIntent)),\n    Match.when(\"k\", () => Option.some(toggleIntent)),\n    Match.when(\"left\", () => Option.some(seekIntent(shift ? -large : -small))),\n    Match.when(\"right\", () => Option.some(seekIntent(shift ? large : small))),\n    Match.when(\"j\", () => Option.some(seekIntent(-large))),\n    Match.when(\"l\", () => Option.some(seekIntent(large))),\n    Match.when(\"home\", () =>\n      Option.some<MediaIntent>({ kind: \"seekTo\", edge: \"start\" }),\n    ),\n    Match.when(\"end\", () =>\n      Option.some<MediaIntent>({ kind: \"seekTo\", edge: \"end\" }),\n    ),\n    Match.when(\"up\", () =>\n      Option.some<MediaIntent>({ kind: \"volume\", delta: MEDIA_VOLUME_STEP }),\n    ),\n    Match.when(\"down\", () =>\n      Option.some<MediaIntent>({ kind: \"volume\", delta: -MEDIA_VOLUME_STEP }),\n    ),\n    Match.when(\"m\", () => Option.some<MediaIntent>({ kind: \"mute\" })),\n    Match.when(\"f\", () => Option.some<MediaIntent>({ kind: \"fullscreen\" })),\n    Match.orElse(() => Option.none()),\n  );\n};\n\nexport const formatClock = (milliseconds: number): string => {\n  const seconds = Number.isFinite(milliseconds)\n    ? Math.max(0, Math.floor(milliseconds / 1000))\n    : 0;\n  return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, \"0\")}`;\n};\n\nexport const timeLabel = (playhead: number, duration: number): string =>\n  `${formatClock(clampPlayhead(playhead, duration))} / ${formatClock(durationOf(duration))}`;\n\nconst shareWidth = (share: number, track: number): number =>\n  Number.isFinite(track) && track > 0 && Number.isFinite(share)\n    ? Math.round(track * Math.min(Math.max(share, 0), 1))\n    : 0;\n\nexport const progressWidth = (\n  playhead: number,\n  duration: number,\n  track: number,\n): number => {\n  const end = durationOf(duration);\n  if (end === 0) return 0;\n  return shareWidth(clampPlayhead(playhead, end) / end, track);\n};\n\nexport const bufferedWidth = (\n  buffered: number,\n  duration: number,\n  track: number,\n): number => {\n  const end = durationOf(duration);\n  if (end === 0) return 0;\n  return shareWidth(clampPlayhead(buffered, end) / end, track);\n};\n\nexport interface MediaKey {\n  readonly key?: string | null;\n  readonly elementId?: number | null;\n  readonly modifiers?: { readonly shift?: boolean } | null;\n  readonly preventDefault?: () => void;\n}\n\nexport interface MediaPointer {\n  readonly x?: number | null;\n\n  readonly button?: number | null;\n\n  readonly pressedButton?: number | null;\n}\n\nexport interface MediaTrackBox {\n  readonly x: number;\n  readonly width: number;\n}\n\nexport const isScrubPress = (button: number | null | undefined): boolean =>\n  button === undefined || button === null || button === 0;\n\nexport const scrubShare = (\n  x: number,\n  track: MediaTrackBox,\n): Option.Option<number> => {\n  const width =\n    Number.isFinite(track.width) && track.width > 0 ? track.width : 0;\n  if (width === 0) return Option.none();\n  const origin = Number.isFinite(track.x) ? track.x : 0;\n  const at = Number.isFinite(x) ? x : origin;\n  return Option.some(Math.min(Math.max((at - origin) / width, 0), 1));\n};\n\nexport const scrubPlayhead = (\n  x: number,\n  track: MediaTrackBox,\n  duration: number,\n): Option.Option<number> => {\n  const end = durationOf(duration);\n  if (end === 0) return Option.none();\n  return Option.map(scrubShare(x, track), (share) =>\n    clampPlayhead(share * end, end),\n  );\n};\n\nexport interface MediaPaint {\n  readonly played: number;\n  readonly buffered: number;\n  readonly thumb: number;\n  readonly clock: string;\n}\n\nexport const mediaPaint = (\n  state: MediaState,\n  buffered: number,\n  duration: number,\n  track: number,\n  thumbSize: number,\n): MediaPaint => {\n  const played = progressWidth(state.playhead, duration, track);\n  const thumb =\n    Number.isFinite(track) && track > 0\n      ? Math.min(\n          Math.max(played - thumbSize / 2, 0),\n          Math.max(track - thumbSize, 0),\n        )\n      : 0;\n  return {\n    played,\n    buffered: Math.max(\n      bufferedWidth(buffered, duration, track),\n      progressWidth(state.playhead, duration, track),\n    ),\n    thumb,\n    clock: timeLabel(state.playhead, duration),\n  };\n};\n"
    }
  ],
  "docs": "[MediaPlayer](https://gpuixui.sudokw.com/media/media-player) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/media/media-player",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}