{"version":3,"file":"useTimelineClips.mjs","names":[],"sources":["../../../src/hooks/clips/useTimelineClips.ts"],"sourcesContent":["import { flattenTimelineClips } from '#react/hooks/clips/timelineClipModel';\nimport type { TimelineClipEntry } from '#react/hooks/clips/timelineClipModel';\nimport type {\n  TimelineCommandResult,\n  Clip,\n  TimelineReadonly,\n  TimelineEngine,\n} from '@techsquidtv/canvas-timeline-core';\nimport { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useTimelineSelector } from '#react/hooks/core/useTimelineSelector';\nimport { useMemo } from 'react';\n\n/** Editable clip presentation fields; structural edits belong to `useTimelineEditCommands`. */\nexport type TimelineClipUpdate = Partial<Pick<Clip, 'label' | 'opacity' | 'color'>>;\n\n/** Clip collection, lookup, edit capabilities, and presentation commands. */\nexport interface UseTimelineClipsResult {\n  /** Flattened clips in timeline track order. */\n  clips: TimelineReadonly<TimelineClipEntry>[];\n  /** Looks up a clip and its containing track in current engine state. */\n  getClip: TimelineEngine['geometry']['getClip'];\n  /** Whether the clip and its track allow movement. */\n  canMoveClip: (clipId: string) => boolean;\n  /** Whether the clip and its track allow trimming. */\n  canTrimClip: (clipId: string) => boolean;\n  /** Whether the clip and its track allow source slipping. */\n  canSlipClip: (clipId: string) => boolean;\n  /** Whether the clip and its track allow sliding. */\n  canSlideClip: (clipId: string) => boolean;\n  /** Updates clip presentation through the engine's validated command API. */\n  updateClip: (clipId: string, properties: TimelineClipUpdate) => TimelineCommandResult;\n}\n\n/**\n * Reads clip collection state without subscribing to viewport or playback updates.\n *\n * Compose `useTimelineSelection` for selection, geometry hooks for reactive rectangles,\n * and `useTimelineEngine().media` for imperative source-time mapping.\n * @returns Clip entries, current lookups, capabilities, and presentation commands.\n * @example\n * ```tsx\n * import { useTimelineClips, useTimelineSelection } from '@techsquidtv/canvas-timeline-react';\n * export function ClipLabelEditor() {\n *   const { selectedClip } = useTimelineSelection();\n *   const { updateClip } = useTimelineClips();\n *   return selectedClip ? <input value={selectedClip.label ?? ''}\n *     onChange={event => updateClip(selectedClip.id, { label: event.target.value })} /> : null;\n * }\n * ```\n */\nexport function useTimelineClips(): UseTimelineClipsResult {\n  const engine = useTimelineEngine();\n  const tracks = useTimelineSelector((state) => state.tracks, Object.is);\n  const clips = useMemo(() => flattenTimelineClips(tracks), [tracks]);\n  const commands = useMemo(() => {\n    const canEdit = (clipId: string, capability: 'movable' | 'resizable') => {\n      const entry = engine.geometry.getClip(clipId);\n      return Boolean(entry && !entry.track.locked && entry.clip[capability] !== false);\n    };\n    return {\n      getClip: engine.geometry.getClip.bind(engine.geometry),\n      canMoveClip: (clipId: string) => canEdit(clipId, 'movable'),\n      canTrimClip: (clipId: string) => canEdit(clipId, 'resizable'),\n      canSlipClip: (clipId: string) => canEdit(clipId, 'resizable'),\n      canSlideClip: (clipId: string) => canEdit(clipId, 'movable'),\n      updateClip: (clipId: string, properties: TimelineClipUpdate) =>\n        engine.updateClipProperties(clipId, properties),\n    };\n  }, [engine]);\n  return useMemo(() => ({ clips, ...commands }), [clips, commands]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,mBAA2C;CACzD,MAAM,SAAS,kBAAkB;CACjC,MAAM,SAAS,qBAAqB,UAAU,MAAM,QAAQ,OAAO,EAAE;CACrE,MAAM,QAAQ,cAAc,qBAAqB,MAAM,GAAG,CAAC,MAAM,CAAC;CAClE,MAAM,WAAW,cAAc;EAC7B,MAAM,WAAW,QAAgB,eAAwC;GACvE,MAAM,QAAQ,OAAO,SAAS,QAAQ,MAAM;GAC5C,OAAO,QAAQ,SAAS,CAAC,MAAM,MAAM,UAAU,MAAM,KAAK,gBAAgB,KAAK;EACjF;EACA,OAAO;GACL,SAAS,OAAO,SAAS,QAAQ,KAAK,OAAO,QAAQ;GACrD,cAAc,WAAmB,QAAQ,QAAQ,SAAS;GAC1D,cAAc,WAAmB,QAAQ,QAAQ,WAAW;GAC5D,cAAc,WAAmB,QAAQ,QAAQ,WAAW;GAC5D,eAAe,WAAmB,QAAQ,QAAQ,SAAS;GAC3D,aAAa,QAAgB,eAC3B,OAAO,qBAAqB,QAAQ,UAAU;EAClD;CACF,GAAG,CAAC,MAAM,CAAC;CACX,OAAO,eAAe;EAAE;EAAO,GAAG;CAAS,IAAI,CAAC,OAAO,QAAQ,CAAC;AAClE"}