{"version":3,"file":"get-timeline.mjs","sources":["../../../../../../src/render/dom/scroll/utils/get-timeline.ts"],"sourcesContent":["import { ProgressTimeline } from \"motion-dom\"\nimport { ScrollOptionsWithDefaults } from \"../types\"\n\ndeclare class ScrollTimeline implements ProgressTimeline {\n    constructor(options: ScrollOptions)\n\n    currentTime: null | { value: number }\n\n    cancel?: VoidFunction\n}\n\ndeclare class ViewTimeline implements ProgressTimeline {\n    constructor(options: { subject: Element; axis?: string })\n\n    currentTime: null | { value: number }\n\n    cancel?: VoidFunction\n}\n\nconst timelineCache = new Map<\n    Element,\n    Map<Element | \"self\", Record<string, ProgressTimeline>>\n>()\n\n/**\n * Native timelines are only attached to WAAPI animations. Offsets are\n * applied to each animation as a range, so a timeline is shared by every\n * offset.\n */\nexport function getTimeline({\n    container,\n    target,\n    axis,\n}: ScrollOptionsWithDefaults): ProgressTimeline {\n    let containerCache = timelineCache.get(container)\n    if (!containerCache) {\n        containerCache = new Map()\n        timelineCache.set(container, containerCache)\n    }\n\n    const targetKey = target ?? \"self\"\n    let targetCache = containerCache.get(targetKey)\n    if (!targetCache) {\n        targetCache = {}\n        containerCache.set(targetKey, targetCache)\n    }\n\n    return (targetCache[axis] ||= target\n        ? new ViewTimeline({ subject: target, axis })\n        : new ScrollTimeline({ source: container, axis } as any))\n}\n"],"names":[],"mappings":"AAmBA,MAAM,aAAa,GAAG,IAAI,GAAG,EAG1B;AAEH;;;;AAIG;AACG,SAAU,WAAW,CAAC,EACxB,SAAS,EACT,MAAM,EACN,IAAI,GACoB,EAAA;IACxB,IAAI,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC;IACjD,IAAI,CAAC,cAAc,EAAE;AACjB,QAAA,cAAc,GAAG,IAAI,GAAG,EAAE;AAC1B,QAAA,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC;IAChD;AAEA,IAAA,MAAM,SAAS,GAAG,MAAM,IAAI,MAAM;IAClC,IAAI,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC;IAC/C,IAAI,CAAC,WAAW,EAAE;QACd,WAAW,GAAG,EAAE;AAChB,QAAA,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC;IAC9C;IAEA,QAAQ,WAAW,CAAC,IAAI,MAAhB,WAAW,CAAC,IAAI,CAAA,GAAM;UACxB,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;AAC5C,UAAE,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAS,CAAC;AAChE;;;;"}