{"version":3,"file":"useTimelineRangeSelection.mjs","names":[],"sources":["../../../src/hooks/selection/useTimelineRangeSelection.ts"],"sourcesContent":["import { timelineCommandOk, timelineCommandFail } from '@techsquidtv/canvas-timeline-core';\nimport type {\n  TimelineCommandResult,\n  TimelineEditCommitResult,\n} from '@techsquidtv/canvas-timeline-core';\nimport { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useTimelineSelector } from '#react/hooks/core/useTimelineSelector';\nimport { useTimelineEditCommands } from '#react/hooks/editing/useTimelineEditCommands';\nimport type { RationalTime } from '@techsquidtv/canvas-timeline-utils';\nimport { useCallback, useMemo } from 'react';\n/** Timeline range selected for range edit commands. */\nexport interface TimelineRangeSelection {\n  /** Inclusive selected range start. */\n  startTime: RationalTime;\n  /** Exclusive selected range end. */\n  endTime: RationalTime;\n}\n\n/** Result returned by `useTimelineRangeSelection`. */\nexport interface UseTimelineRangeSelectionResult {\n  /** Selected timeline range, or null when both boundaries are not set. */\n  range: TimelineRangeSelection | null;\n  /** Whether a complete range is selected. */\n  hasRange: boolean;\n  /** Sets both range boundaries. */\n  setRange: (range: TimelineRangeSelection) => TimelineCommandResult;\n  /** Clears the range boundaries. */\n  clearRange: () => TimelineCommandResult;\n  /** Deletes the selected range, closing the gap by default. */\n  deleteRange: (options?: {\n    trackIds?: readonly string[];\n    ripple?: boolean;\n  }) => TimelineCommandResult<TimelineEditCommitResult>;\n  /** Lifts the selected range while leaving the gap in place. */\n  liftRange: (options?: {\n    trackIds?: readonly string[];\n  }) => TimelineCommandResult<TimelineEditCommitResult>;\n}\n\n/**\n * Adapts timeline In/Out points to command-layer range selection.\n *\n * The hook treats a complete In/Out pair as the selected edit range and delegates\n * range mutations to `useTimelineEditCommands`.\n *\n * @returns Range selection state and range edit commands.\n */\nexport function useTimelineRangeSelection(): UseTimelineRangeSelectionResult {\n  const engine = useTimelineEngine();\n  const state = useTimelineSelector((state) => ({\n    inPoint: state.inPoint,\n    outPoint: state.outPoint,\n  }));\n  const { deleteRange: commitDeleteRange, liftRange: commitLiftRange } = useTimelineEditCommands();\n  const range = useMemo(() => {\n    if (state.inPoint === undefined || state.outPoint === undefined) {\n      return null;\n    }\n    return {\n      startTime: state.inPoint,\n      endTime: state.outPoint,\n    };\n  }, [state.inPoint, state.outPoint]);\n\n  const setRange = useCallback(\n    (nextRange: TimelineRangeSelection) => {\n      return engine.setInOutRange(nextRange.startTime, nextRange.endTime);\n    },\n    [engine]\n  );\n\n  const clearRange = useCallback(() => {\n    engine.clearInOutPoints();\n    return timelineCommandOk();\n  }, [engine]);\n\n  const deleteRange = useCallback(\n    (options: { trackIds?: readonly string[]; ripple?: boolean } = {}) => {\n      const { inPoint, outPoint } = engine.getState();\n      if (inPoint === undefined || outPoint === undefined) {\n        return timelineCommandFail<TimelineEditCommitResult>('invalid-range');\n      }\n      return commitDeleteRange({\n        startTime: inPoint,\n        endTime: outPoint,\n        trackIds: options.trackIds,\n        ripple: options.ripple,\n      });\n    },\n    [commitDeleteRange, engine]\n  );\n\n  const liftRange = useCallback(\n    (options: { trackIds?: readonly string[] } = {}) => {\n      const { inPoint, outPoint } = engine.getState();\n      if (inPoint === undefined || outPoint === undefined) {\n        return timelineCommandFail<TimelineEditCommitResult>('invalid-range');\n      }\n      return commitLiftRange({\n        startTime: inPoint,\n        endTime: outPoint,\n        trackIds: options.trackIds,\n      });\n    },\n    [commitLiftRange, engine]\n  );\n\n  return useMemo(\n    () => ({\n      range,\n      hasRange: range !== null,\n      setRange,\n      clearRange,\n      deleteRange,\n      liftRange,\n    }),\n    [clearRange, deleteRange, liftRange, range, setRange]\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;AA+CA,SAAgB,4BAA6D;CAC3E,MAAM,SAAS,kBAAkB;CACjC,MAAM,QAAQ,qBAAqB,WAAW;EAC5C,SAAS,MAAM;EACf,UAAU,MAAM;CAClB,EAAE;CACF,MAAM,EAAE,aAAa,mBAAmB,WAAW,oBAAoB,wBAAwB;CAC/F,MAAM,QAAQ,cAA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