{"version":3,"file":"useTimelineGeometryRevision.mjs","names":[],"sources":["../../../src/hooks/core/useTimelineGeometryRevision.ts"],"sourcesContent":["import { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useCallback, useRef, useSyncExternalStore } from 'react';\ninterface TimelineGeometryRevisionOptions {\n  /** Include high-frequency playhead scrubs in the revision stream. */\n  redrawOnPlayhead?: boolean;\n  /** Include active edit preview frames in the revision stream. */\n  redrawOnPreview?: boolean;\n}\n\n/**\n * Subscribes to timeline events that can change viewport-space geometry.\n *\n * The snapshot is a stable numeric revision so geometry hooks can memoize their\n * derived arrays without returning a fresh external-store snapshot each render.\n */\nexport function useTimelineGeometryRevision(options: TimelineGeometryRevisionOptions = {}) {\n  const redrawOnPlayhead = options.redrawOnPlayhead ?? false;\n  const redrawOnPreview = options.redrawOnPreview ?? false;\n  const engine = useTimelineEngine();\n  const revisionRef = useRef(0);\n\n  const subscribe = useCallback(\n    (onStoreChange: () => void) => {\n      const update = () => {\n        revisionRef.current += 1;\n        onStoreChange();\n      };\n\n      const unsubScroll = engine.on('scroll:change', update);\n      const unsubZoom = engine.on('zoom:change', update);\n      const unsubRender = engine.on('render', update);\n      const unsubViewport = engine.on('viewport:resize', update);\n      const unsubPlayhead = redrawOnPlayhead\n        ? engine.on('playhead:scrub', update)\n        : () => undefined;\n      const unsubPreview = redrawOnPreview ? engine.on('state:preview', update) : () => undefined;\n\n      return () => {\n        unsubScroll();\n        unsubZoom();\n        unsubRender();\n        unsubViewport();\n        unsubPlayhead();\n        unsubPreview();\n      };\n    },\n    [engine, redrawOnPlayhead, redrawOnPreview]\n  );\n\n  const getSnapshot = useCallback(() => revisionRef.current, []);\n\n  return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,4BAA4B,UAA2C,CAAC,GAAG;CACzF,MAAM,mBAAmB,QAAQ,oBAAoB;CACrD,MAAM,kBAAkB,QAAQ,mBAAmB;CACnD,MAAM,SAAS,kBAAkB;CACjC,MAAM,cAAc,OAAO,CAAC;CAE5B,MAAM,YAAY,aACf,kBAA8B;EAC7B,MAAM,eAAe;GACnB,YAAY,WAAW;GACvB,cAAc;EAChB;EAEA,MAAM,cAAc,OAAO,GAAG,iBAAiB,MAAM;EACrD,MAAM,YAAY,OAAO,GAAG,eAAe,MAAM;EACjD,MAAM,cAAc,OAAO,GAAG,UAAU,MAAM;EAC9C,MAAM,gBAAgB,OAAO,GAAG,mBAAmB,MAAM;EACzD,MAAM,gBAAgB,mBAClB,OAAO,GAAG,kBAAkB,MAAM,UAC5B,KAAA;EACV,MAAM,eAAe,kBAAkB,OAAO,GAAG,iBAAiB,MAAM,UAAU,KAAA;EAElF,aAAa;GACX,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,cAAc;GACd,cAAc;GACd,aAAa;EACf;CACF,GACA;EAAC;EAAQ;EAAkB;CAAe,CAC5C;CAEA,MAAM,cAAc,kBAAkB,YAAY,SAAS,CAAC,CAAC;CAE7D,OAAO,qBAAqB,WAAW,aAAa,WAAW;AACjE"}