Files
SnowLuma/.pnpm-store/v11/files/44/ee8eac5d2d317b4b92aa9ec3d0c9d4288906e9d895c3ff0f713bbcb570a26928eb8f20f623dbc7909e8ca65013ffb576a08473efe1587c5ac490202c0a6726
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

63 lines
2.0 KiB
Plaintext

import { scrollInfo } from '../track.mjs';
import { canUseNativeTimeline } from './can-use-native-timeline.mjs';
import { offsetToViewTimelineRange } from './offset-to-range.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;
let containerCache = timelineCache.get(container);
if (!containerCache) {
containerCache = new Map();
timelineCache.set(container, containerCache);
}
const targetKey = options.target ?? "self";
let targetCache = containerCache.get(targetKey);
if (!targetCache) {
targetCache = {};
containerCache.set(targetKey, targetCache);
}
const axisKey = axis + (options.offset ?? []).join(",");
if (!targetCache[axisKey]) {
if (options.target && canUseNativeTimeline(options.target)) {
const range = offsetToViewTimelineRange(options.offset);
if (range) {
targetCache[axisKey] = new ViewTimeline({
subject: options.target,
axis,
});
}
else {
targetCache[axisKey] = scrollTimelineFallback({
container,
...options,
});
}
}
else if (canUseNativeTimeline()) {
targetCache[axisKey] = new ScrollTimeline({
source: container,
axis,
});
}
else {
targetCache[axisKey] = scrollTimelineFallback({
container,
...options,
});
}
}
return targetCache[axisKey];
}
export { getTimeline };
//# sourceMappingURL=get-timeline.mjs.map