Files
NapCatQQ/.pnpm-store/v3/files/7e/a8ea2f61a2fe6c4a0bea33bb6a21114bbd4bb5213cd009ccb0efab458c052e037c71120a8337b6e226fd7dc1792ed6f5b0441c6976b1032032e879dad62883
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

31 lines
1.1 KiB
Plaintext

import { supportsScrollTimeline } from 'motion-dom';
import { scrollInfo } from '../track.mjs';
const timelineCache = new Map();
function scrollTimelineFallback(options) {
const currentTime = { value: 0 };
const cancel = scrollInfo((info) => {
currentTime.value = info[options.axis].progress * 100;
}, options);
return { currentTime, cancel };
}
function getTimeline({ source, container, ...options }) {
const { axis } = options;
if (source)
container = source;
const containerCache = timelineCache.get(container) ?? new Map();
timelineCache.set(container, containerCache);
const targetKey = options.target ?? "self";
const targetCache = containerCache.get(targetKey) ?? {};
const axisKey = axis + (options.offset ?? []).join(",");
if (!targetCache[axisKey]) {
targetCache[axisKey] =
!options.target && supportsScrollTimeline()
? new ScrollTimeline({ source: container, axis })
: scrollTimelineFallback({ container, ...options });
}
return targetCache[axisKey];
}
export { getTimeline };