{"version":3,"file":"useTimelineRulerTicks.mjs","names":[],"sources":["../../../src/hooks/viewport/useTimelineRulerTicks.ts"],"sourcesContent":["import { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useTimelineGeometryRevision } from '#react/hooks/core/useTimelineGeometryRevision';\nimport { getTimelineRulerTicks } from '@techsquidtv/canvas-timeline-core';\nimport type {\n  TimelineRulerFormatOptions,\n  TimelineRulerGeometryOptions,\n  TimelineRulerTick,\n} from '@techsquidtv/canvas-timeline-core';\nimport { useMemo } from 'react';\n/** Options accepted by `useTimelineRulerTicks`. */\nexport type UseTimelineRulerTicksOptions = Partial<TimelineRulerGeometryOptions> &\n  TimelineRulerFormatOptions;\n\nfunction getRulerFormatOptions(\n  format: TimelineRulerFormatOptions['format'],\n  frameRate: TimelineRulerFormatOptions['frameRate'],\n  timecodeFormatOptions: TimelineRulerFormatOptions['timecodeFormatOptions']\n): TimelineRulerFormatOptions {\n  if (format === 'timecode') {\n    if (frameRate === undefined) {\n      throw new TypeError('A timecode ruler requires a frame rate.');\n    }\n    return { format, frameRate, timecodeFormatOptions };\n  }\n\n  if (format === 'frame-number') {\n    if (frameRate === undefined) {\n      throw new TypeError('A frame-number ruler requires a frame rate.');\n    }\n    return { format, frameRate };\n  }\n\n  return { format: 'seconds' };\n}\n\n/**\n * Returns shared viewport-space ruler ticks for DOM and custom timeline chrome.\n *\n * The hook subscribes to geometry-affecting timeline events and intentionally\n * does not subscribe to playhead-only updates.\n *\n * @param options - Optional viewport and frame-label overrides.\n * @returns Ruler ticks clipped to the visible viewport and optional duration.\n */\nexport function useTimelineRulerTicks(\n  options: UseTimelineRulerTicksOptions = { format: 'seconds' }\n): TimelineRulerTick[] {\n  const engine = useTimelineEngine();\n  const revision = useTimelineGeometryRevision();\n  const {\n    duration,\n    format,\n    frameRate,\n    includeLabels,\n    minimumMajorTickSpacing,\n    scrollLeft,\n    timecodeFormatOptions,\n    viewportWidth,\n    zoomScale,\n  } = options;\n\n  return useMemo(() => {\n    void revision;\n    const state = engine.getState();\n\n    return getTimelineRulerTicks({\n      duration: duration ?? state.duration,\n      includeLabels,\n      minimumMajorTickSpacing,\n      scrollLeft: scrollLeft ?? state.scrollLeft,\n      viewportWidth: viewportWidth ?? (state.viewportWidth || 1000),\n      zoomScale: zoomScale ?? state.zoomScale,\n      ...getRulerFormatOptions(format, frameRate, timecodeFormatOptions),\n    });\n  }, [\n    duration,\n    engine,\n    format,\n    frameRate,\n    includeLabels,\n    minimumMajorTickSpacing,\n    revision,\n    scrollLeft,\n    timecodeFormatOptions,\n    viewportWidth,\n    zoomScale,\n  ]);\n}\n"],"mappings":";;;;;AAaA,SAAS,sBACP,QACA,WACA,uBAC4B;CAC5B,IAAI,WAAW,YAAY;EACzB,IAAI,cAAc,KAAA,GAChB,MAAM,IAAI,UAAU,yCAAyC;EAE/D,OAAO;GAAE;GAAQ;GAAW;EAAsB;CACpD;CAEA,IAAI,WAAW,gBAAgB;EAC7B,IAAI,cAAc,KAAA,GAChB,MAAM,IAAI,UAAU,6CAA6C;EAEnE,OAAO;GAAE;GAAQ;EAAU;CAC7B;CAEA,OAAO,EAAE,QAAQ,UAAU;AAC7B;;;;;;;;;;AAWA,SAAgB,sBACd,UAAwC,EAAE,QAAQ,UAAU,GACvC;CACrB,MAAM,SAAS,kBAAkB;CACjC,MAAM,WAAW,4BAA4B;CAC7C,MAAM,EACJ,UACA,QACA,WACA,eACA,yBACA,YACA,uBACA,eACA,cACE;CAEJ,OAAO,cAAc;EAEnB,MAAM,QAAQ,OAAO,SAAS;EAE9B,OAAO,sBAAsB;GAC3B,UAAU,YAAY,MAAM;GAC5B;GACA;GACA,YAAY,cAAc,MAAM;GAChC,eAAe,kBAAkB,MAAM,iBAAiB;GACxD,WAAW,aAAa,MAAM;GAC9B,GAAG,sBAAsB,QAAQ,WAAW,qBAAqB;EACnE,CAAC;CACH,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}