{"version":3,"file":"useTimelinePlayheadControl.mjs","names":[],"sources":["../../../src/hooks/playback/useTimelinePlayheadControl.ts"],"sourcesContent":["import { formatTimelineTimeValue } from '#react/accessibility';\nimport type { TimelineControlCommitDetails } from '#react/hooks/core/timelineControlEvents';\nimport { createTimelineScalarControlProps } from '#react/hooks/core/timelineScalarControlProps';\nimport { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useTimelineViewportBounds } from '#react/hooks/viewport/useTimelineViewportBounds';\nimport { useTimelinePlayheadTime } from '#react/hooks/playback/useTimelinePlayheadTime';\nimport { clamp, fromSeconds, toSeconds } from '@techsquidtv/canvas-timeline-utils';\nimport { useCallback, useMemo } from 'react';\n/**\n * Options for adapting the timeline playhead to a scalar control.\n */\nexport interface TimelinePlayheadControlOptions {\n  /** Minimum timeline time in seconds. Defaults to 0. */\n  min?: number;\n  /** Maximum timeline time in seconds. Defaults to timeline duration/content end. */\n  max?: number;\n  /** Slider step in seconds for consumers using slider primitives. */\n  step?: number;\n  /** Accessible label for the playhead control. */\n  label?: string;\n  /**\n   * Called after the hook applies a committed control value to the engine.\n   *\n   * When the underlying scalar control provides commit details, Canvas Timeline\n   * forwards them unchanged as the second argument and does not read their\n   * fields.\n   */\n  onValueCommitted?: (value: number[], eventDetails?: TimelineControlCommitDetails) => void;\n}\n\n/**\n * Adapts the timeline playhead to a Base UI-compatible scalar slider.\n *\n * Use this hook when an application wants its own playhead scrubber, time field,\n * or transport control while preserving the shared `TimelineEngine` state. It\n * composes with `useTimelinePlayback`, which exposes imperative transport\n * commands without subscribing to live playhead ticks.\n *\n * @param options - Optional bounds, step size, label, and commit callback for the playhead control.\n * @returns Current playhead seconds, formatted value text, imperative setters, and props for `Slider.Root` plus `Slider.Thumb`.\n *\n * @example\n * ```tsx\n * const playhead = useTimelinePlayheadControl();\n *\n * return (\n *   <Slider.Root {...playhead.rootProps}>\n *     <Slider.Control>\n *       <Slider.Track>\n *         <Slider.Indicator />\n *         <Slider.Thumb {...playhead.thumbProps} />\n *       </Slider.Track>\n *     </Slider.Control>\n *   </Slider.Root>\n * );\n * ```\n */\nexport function useTimelinePlayheadControl(options: TimelinePlayheadControlOptions = {}) {\n  const { label: optionLabel, max: optionMax, min: optionMin, onValueCommitted, step } = options;\n  const engine = useTimelineEngine();\n  const bounds = useTimelineViewportBounds();\n  const playheadTime = useTimelinePlayheadTime();\n  const max = optionMax ?? toSeconds(bounds.maxContentTime);\n  const control = useMemo(() => {\n    const value = toSeconds(playheadTime);\n    return {\n      label: optionLabel ?? 'Playhead',\n      max,\n      min: optionMin ?? 0,\n      step: step ?? 0.01,\n      value,\n      valueText: formatTimelineTimeValue(value),\n    };\n  }, [max, optionLabel, optionMin, playheadTime, step]);\n\n  const setValue = useCallback(\n    (nextValue: number) => {\n      const bounded = clamp(nextValue, control.min, control.max);\n      engine.updatePlayhead(fromSeconds(bounded, playheadTime.r));\n    },\n    [control.max, control.min, engine, playheadTime.r]\n  );\n\n  const stepBy = useCallback(\n    (deltaSeconds: number) => {\n      setValue(control.value + deltaSeconds);\n    },\n    [control.value, setValue]\n  );\n\n  const commit = useCallback(\n    (nextValue = control.value) => {\n      setValue(nextValue);\n      engine.settle();\n    },\n    [control.value, engine, setValue]\n  );\n\n  return useMemo(() => {\n    const scalarProps = createTimelineScalarControlProps({\n      control,\n      setValue,\n      commit,\n      getAriaValueText: formatTimelineTimeValue,\n      onEmptyCommit: () => engine.settle(),\n      onValueCommitted,\n    });\n\n    return {\n      /** Accessible label used by the default thumb props. */\n      label: control.label,\n      /** Maximum playhead time in seconds. */\n      max: control.max,\n      /** Minimum playhead time in seconds. */\n      min: control.min,\n      /** Slider step in seconds. */\n      step: control.step,\n      /** Current playhead time in seconds. */\n      value: control.value,\n      /** Formatted playhead value for assistive technology. */\n      valueText: control.valueText,\n      /** Moves the playhead to an absolute time in seconds without settling history. */\n      setValue,\n      /** Moves the playhead by a relative number of seconds. */\n      stepBy,\n      /** Moves the playhead and settles the engine interaction. */\n      commit,\n      /** Formats a timeline second value for `aria-valuetext`. */\n      getAriaValueText: scalarProps.getAriaValueText,\n      /** Props for a Base UI `Slider.Root`. */\n      rootProps: scalarProps.rootProps,\n      /** Props for a Base UI `Slider.Thumb`. */\n      thumbProps: scalarProps.thumbProps,\n    };\n  }, [commit, control, engine, onValueCommitted, setValue, stepBy]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,2BAA2B,UAA0C,CAAC,GAAG;CACvF,MAAM,EAAE,OAAO,aAAa,KAAK,WAAW,KAAK,WAAW,kBAAkB,SAAS;CACvF,MAAM,SAAS,kBAAkB;CACjC,MAAM,SAAS,0BAA0B;CACzC,MAAM,eAAe,wBAAwB;CAC7C,MAAM,MAAM,aAAa,UAAU,OAAO,cAAc;CACxD,MAAM,UAAU,cAAc;EAC5B,MAAM,QAAQ,UAAU,YAAY;EACpC,OAAO;GACL,OAAO,eAAe;GACtB;GACA,KAAK,aAAa;GAClB,MAAM,QAAQ;GACd;GACA,WAAW,wBAAwB,KAAK;EAC1C;CACF,GAAG;EAAC;EAAK;EAAa;EAAW;EAAc;CAAI,CAAC;CAEpD,MAAM,WAAW,aACd,cAAsB;EACrB,MAAM,UAAU,MAAM,WAAW,QAAQ,KAAK,QAAQ,GAAG;EACzD,OAAO,eAAe,YAAY,SAAS,aAAa,CAAC,CAAC;CAC5D,GACA;EAAC,QAAQ;EAAK,QAAQ;EAAK;EAAQ,aAAa;CAAC,CACnD;CAEA,MAAM,SAAS,aACZ,iBAAyB;EACxB,SAAS,QAAQ,QAAQ,YAAY;CACvC,GACA,CAAC,QAAQ,OAAO,QAAQ,CAC1B;CAEA,MAAM,SAAS,aACZ,YAAY,QAAQ,UAAU;EAC7B,SAAS,SAAS;EAClB,OAAO,OAAO;CAChB,GACA;EAAC,QAAQ;EAAO;EAAQ;CAAQ,CAClC;CAEA,OAAO,cAAc;EACnB,MAAM,cAAc,iCAAiC;GACnD;GACA;GACA;GACA,kBAAkB;GAClB,qBAAqB,OAAO,OAAO;GACnC;EACF,CAAC;EAED,OAAO;;GAEL,OAAO,QAAQ;;GAEf,KAAK,QAAQ;;GAEb,KAAK,QAAQ;;GAEb,MAAM,QAAQ;;GAEd,OAAO,QAAQ;;GAEf,WAAW,QAAQ;;GAEnB;;GAEA;;GAEA;;GAEA,kBAAkB,YAAY;;GAE9B,WAAW,YAAY;;GAEvB,YAAY,YAAY;EAC1B;CACF,GAAG;EAAC;EAAQ;EAAS;EAAQ;EAAkB;EAAU;CAAM,CAAC;AAClE"}