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

53 lines
1.7 KiB
Plaintext

import { removeItem } from 'motion-utils';
import { microtask } from '../frameloop/microtask.mjs';
import { startViewAnimation } from './start.mjs';
let builders = [];
let current = null;
function next() {
current = null;
const [nextBuilder] = builders;
if (nextBuilder)
start(nextBuilder);
}
function start(builder) {
removeItem(builders, builder);
current = builder;
startViewAnimation(builder).then((animation) => {
builder.notifyReady(animation);
animation.finished.finally(next);
});
}
function processQueue() {
/**
* Iterate backwards over the builders array. We can ignore the
* "wait" animations. If we have an interrupting animation in the
* queue then we need to batch all preceeding animations into it.
* Currently this only batches the update functions but will also
* need to batch the targets.
*/
for (let i = builders.length - 1; i >= 0; i--) {
const builder = builders[i];
const { interrupt } = builder.options;
if (interrupt === "immediate") {
const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update);
const remaining = builders.slice(i + 1);
builder.update = () => {
batchedUpdates.forEach((update) => update());
};
// Put the current builder at the front, followed by any "wait" builders
builders = [builder, ...remaining];
break;
}
}
if (!current || builders[0]?.options.interrupt === "immediate") {
next();
}
}
function addToQueue(builder) {
builders.push(builder);
microtask.render(processQueue);
}
export { addToQueue };