1 line
20 KiB
JSON
1 line
20 KiB
JSON
|
|
{"ast":null,"code":"import _objectSpread from \"/Users/apple/Documents/cursor/Web\\u8BFE\\u4EF6/AI\\u8BFE/education_web_\\u591AAgent\\u534F\\u4F5C\\u7CFB\\u7EDF/node_modules/@babel/runtime/helpers/esm/objectSpread2.js\";\nimport { secondsToMilliseconds } from 'motion-utils';\nimport { GroupAnimation } from '../animation/GroupAnimation.mjs';\nimport { NativeAnimation } from '../animation/NativeAnimation.mjs';\nimport { NativeAnimationWrapper } from '../animation/NativeAnimationWrapper.mjs';\nimport { getValueTransition } from '../animation/utils/get-value-transition.mjs';\nimport { mapEasingToNativeEasing } from '../animation/waapi/easing/map-easing.mjs';\nimport { applyGeneratorOptions } from '../animation/waapi/utils/apply-generator.mjs';\nimport { chooseLayerType } from './utils/choose-layer-type.mjs';\nimport { css } from './utils/css.mjs';\nimport { getLayerName } from './utils/get-layer-name.mjs';\nimport { getViewAnimations } from './utils/get-view-animations.mjs';\nimport { hasTarget } from './utils/has-target.mjs';\nconst definitionNames = [\"layout\", \"enter\", \"exit\", \"new\", \"old\"];\nfunction startViewAnimation(builder) {\n const {\n update,\n targets,\n options: defaultOptions\n } = builder;\n if (!document.startViewTransition) {\n return new Promise(async resolve => {\n await update();\n resolve(new GroupAnimation([]));\n });\n }\n // TODO: Go over existing targets and ensure they all have ids\n /**\n * If we don't have any animations defined for the root target,\n * remove it from being captured.\n */\n if (!hasTarget(\"root\", targets)) {\n css.set(\":root\", {\n \"view-transition-name\": \"none\"\n });\n }\n /**\n * Set the timing curve to linear for all view transition layers.\n * This gets baked into the keyframes, which can't be changed\n * without breaking the generated animation.\n *\n * This allows us to set easing via updateTiming - which can be changed.\n */\n css.set(\"::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)\", {\n \"animation-timing-function\": \"linear !important\"\n });\n css.commit(); // Write\n const transition = document.startViewTransition(async () => {\n await update();\n // TODO: Go over new targets and ensure they all have ids\n });\n transition.finished.finally(() => {\n css.remove(); // Write\n });\n return new Promise(resolve => {\n transition.ready.then(() => {\n const generatedViewAnimations = getViewAnimations();\n const animations = [];\n /**\n * Create animations for each of our explicitly-defined subjects.\n */\n targets.forEach((definition, target) => {\n // TODO: If target is not \"root\", resolve elements\n // and iterate over each\n for (const key of definitionNames) {\n if (!definition[key]) continue;\n const {\n keyframes,\n options\n } = definition[key];\n for (let [valueName, valueKeyframes] of Object.entries(keyframes)) {\n if (!valueKeyframes) continue;\n const valueOptions = _objectSpread(_objectSpread({}, getValueTransition(defaultOptions, valueName)), getValueTransition(options, valueName));\n const type = chooseLayerType(key);\n /**\n * If this is an opacity animation, and keyframes are not an array,\n * we need to convert them into an array and set an initial value.\n */\n if (valueName === \"opacity\" && !Array.isArray(valueKeyframes)) {\n const initialValue = type === \"new\" ? 0 : 1;\n valueKeyframes = [initialValue, valueKeyframes];\n }\n /**\n * Resolve stagger function if provided.\n */\n if (typeof valueOptions.delay === \"function\") {\n valueOptions.delay = valueOptions.delay(0, 1);\n }\n valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));\n valueOptions.d
|