main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

64
node_modules/motion-dom/dist/es/view/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,64 @@
import { noop } from 'motion-utils';
import { addToQueue } from './queue.mjs';
class ViewTransitionBuilder {
constructor(update, options = {}) {
this.currentSubject = "root";
this.targets = new Map();
this.notifyReady = noop;
this.readyPromise = new Promise((resolve) => {
this.notifyReady = resolve;
});
this.update = update;
this.options = {
interrupt: "wait",
...options,
};
addToQueue(this);
}
get(subject) {
this.currentSubject = subject;
return this;
}
layout(keyframes, options) {
this.updateTarget("layout", keyframes, options);
return this;
}
new(keyframes, options) {
this.updateTarget("new", keyframes, options);
return this;
}
old(keyframes, options) {
this.updateTarget("old", keyframes, options);
return this;
}
enter(keyframes, options) {
this.updateTarget("enter", keyframes, options);
return this;
}
exit(keyframes, options) {
this.updateTarget("exit", keyframes, options);
return this;
}
crossfade(options) {
this.updateTarget("enter", { opacity: 1 }, options);
this.updateTarget("exit", { opacity: 0 }, options);
return this;
}
updateTarget(target, keyframes, options = {}) {
const { currentSubject, targets } = this;
if (!targets.has(currentSubject)) {
targets.set(currentSubject, {});
}
const targetData = targets.get(currentSubject);
targetData[target] = { keyframes, options };
}
then(resolve, reject) {
return this.readyPromise.then(resolve, reject);
}
}
function animateView(update, defaultOptions = {}) {
return new ViewTransitionBuilder(update, defaultOptions);
}
export { ViewTransitionBuilder, animateView };

52
node_modules/motion-dom/dist/es/view/queue.mjs generated vendored Normal file
View File

@@ -0,0 +1,52 @@
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 };

155
node_modules/motion-dom/dist/es/view/start.mjs generated vendored Normal file
View File

@@ -0,0 +1,155 @@
import { secondsToMilliseconds } from 'motion-utils';
import { GroupAnimation } from '../animation/GroupAnimation.mjs';
import { NativeAnimation } from '../animation/NativeAnimation.mjs';
import { NativeAnimationWrapper } from '../animation/NativeAnimationWrapper.mjs';
import { getValueTransition } from '../animation/utils/get-value-transition.mjs';
import { mapEasingToNativeEasing } from '../animation/waapi/easing/map-easing.mjs';
import { applyGeneratorOptions } from '../animation/waapi/utils/apply-generator.mjs';
import { chooseLayerType } from './utils/choose-layer-type.mjs';
import { css } from './utils/css.mjs';
import { getViewAnimationLayerInfo } from './utils/get-layer-info.mjs';
import { getViewAnimations } from './utils/get-view-animations.mjs';
import { hasTarget } from './utils/has-target.mjs';
const definitionNames = ["layout", "enter", "exit", "new", "old"];
function startViewAnimation(builder) {
const { update, targets, options: defaultOptions } = builder;
if (!document.startViewTransition) {
return new Promise(async (resolve) => {
await update();
resolve(new GroupAnimation([]));
});
}
// TODO: Go over existing targets and ensure they all have ids
/**
* If we don't have any animations defined for the root target,
* remove it from being captured.
*/
if (!hasTarget("root", targets)) {
css.set(":root", {
"view-transition-name": "none",
});
}
/**
* Set the timing curve to linear for all view transition layers.
* This gets baked into the keyframes, which can't be changed
* without breaking the generated animation.
*
* This allows us to set easing via updateTiming - which can be changed.
*/
css.set("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)", { "animation-timing-function": "linear !important" });
css.commit(); // Write
const transition = document.startViewTransition(async () => {
await update();
// TODO: Go over new targets and ensure they all have ids
});
transition.finished.finally(() => {
css.remove(); // Write
});
return new Promise((resolve) => {
transition.ready.then(() => {
const generatedViewAnimations = getViewAnimations();
const animations = [];
/**
* Create animations for each of our explicitly-defined subjects.
*/
targets.forEach((definition, target) => {
// TODO: If target is not "root", resolve elements
// and iterate over each
for (const key of definitionNames) {
if (!definition[key])
continue;
const { keyframes, options } = definition[key];
for (let [valueName, valueKeyframes] of Object.entries(keyframes)) {
if (!valueKeyframes)
continue;
const valueOptions = {
...getValueTransition(defaultOptions, valueName),
...getValueTransition(options, valueName),
};
const type = chooseLayerType(key);
/**
* If this is an opacity animation, and keyframes are not an array,
* we need to convert them into an array and set an initial value.
*/
if (valueName === "opacity" &&
!Array.isArray(valueKeyframes)) {
const initialValue = type === "new" ? 0 : 1;
valueKeyframes = [initialValue, valueKeyframes];
}
/**
* Resolve stagger function if provided.
*/
if (typeof valueOptions.delay === "function") {
valueOptions.delay = valueOptions.delay(0, 1);
}
valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));
valueOptions.delay && (valueOptions.delay = secondsToMilliseconds(valueOptions.delay));
const animation = new NativeAnimation({
...valueOptions,
element: document.documentElement,
name: valueName,
pseudoElement: `::view-transition-${type}(${target})`,
keyframes: valueKeyframes,
});
animations.push(animation);
}
}
});
/**
* Handle browser generated animations
*/
for (const animation of generatedViewAnimations) {
if (animation.playState === "finished")
continue;
const { effect } = animation;
if (!effect || !(effect instanceof KeyframeEffect))
continue;
const { pseudoElement } = effect;
if (!pseudoElement)
continue;
const name = getViewAnimationLayerInfo(pseudoElement);
if (!name)
continue;
const targetDefinition = targets.get(name.layer);
if (!targetDefinition) {
/**
* If transition name is group then update the timing of the animation
* whereas if it's old or new then we could possibly replace it using
* the above method.
*/
const transitionName = name.type === "group" ? "layout" : "";
let animationTransition = {
...getValueTransition(defaultOptions, transitionName),
};
animationTransition.duration && (animationTransition.duration = secondsToMilliseconds(animationTransition.duration));
animationTransition =
applyGeneratorOptions(animationTransition);
const easing = mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
effect.updateTiming({
delay: secondsToMilliseconds(animationTransition.delay ?? 0),
duration: animationTransition.duration,
easing,
});
animations.push(new NativeAnimationWrapper(animation));
}
else if (hasOpacity(targetDefinition, "enter") &&
hasOpacity(targetDefinition, "exit") &&
effect
.getKeyframes()
.some((keyframe) => keyframe.mixBlendMode)) {
animations.push(new NativeAnimationWrapper(animation));
}
else {
animation.cancel();
}
}
resolve(new GroupAnimation(animations));
});
});
}
function hasOpacity(target, key) {
return target?.[key]?.keyframes.opacity;
}
export { startViewAnimation };

View File

@@ -0,0 +1,11 @@
function chooseLayerType(valueName) {
if (valueName === "layout")
return "group";
if (valueName === "enter" || valueName === "new")
return "new";
if (valueName === "exit" || valueName === "old")
return "old";
return "group";
}
export { chooseLayerType };

32
node_modules/motion-dom/dist/es/view/utils/css.mjs generated vendored Normal file
View File

@@ -0,0 +1,32 @@
let pendingRules = {};
let style = null;
const css = {
set: (selector, values) => {
pendingRules[selector] = values;
},
commit: () => {
if (!style) {
style = document.createElement("style");
style.id = "motion-view";
}
let cssText = "";
for (const selector in pendingRules) {
const rule = pendingRules[selector];
cssText += `${selector} {\n`;
for (const [property, value] of Object.entries(rule)) {
cssText += ` ${property}: ${value};\n`;
}
cssText += "}\n";
}
style.textContent = cssText;
document.head.appendChild(style);
pendingRules = {};
},
remove: () => {
if (style && style.parentElement) {
style.parentElement.removeChild(style);
}
},
};
export { css };

View File

@@ -0,0 +1,8 @@
function getViewAnimationLayerInfo(pseudoElement) {
const match = pseudoElement.match(/::view-transition-(old|new|group|image-pair)\((.*?)\)/);
if (!match)
return null;
return { layer: match[2], type: match[1] };
}
export { getViewAnimationLayerInfo };

View File

@@ -0,0 +1,12 @@
function filterViewAnimations(animation) {
const { effect } = animation;
if (!effect)
return false;
return (effect.target === document.documentElement &&
effect.pseudoElement?.startsWith("::view-transition"));
}
function getViewAnimations() {
return document.getAnimations().filter(filterViewAnimations);
}
export { getViewAnimations };

View File

@@ -0,0 +1,5 @@
function hasTarget(target, targets) {
return targets.has(target) && Object.keys(targets.get(target)).length > 0;
}
export { hasTarget };