This commit is contained in:
morgan
2026-03-13 19:23:37 +03:00
parent 8917f1631f
commit cc7403191a
5113 changed files with 168404 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { warnOnce } from 'motion-utils';
import { useScroll } from '../use-scroll.mjs';
/**
* @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
*/
function useElementScroll(ref) {
if (process.env.NODE_ENV === "development") {
warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
}
return useScroll({ container: ref });
}
export { useElementScroll };
//# sourceMappingURL=use-element-scroll.mjs.map

View File

@@ -0,0 +1,47 @@
"use client";
import { isMotionValue } from 'motion-dom';
import { useCombineMotionValues } from './use-combine-values.mjs';
/**
* Combine multiple motion values into a new one using a string template literal.
*
* ```jsx
* import {
* motion,
* useSpring,
* useMotionValue,
* useMotionTemplate
* } from "framer-motion"
*
* function Component() {
* const shadowX = useSpring(0)
* const shadowY = useMotionValue(0)
* const shadow = useMotionTemplate`drop-shadow(${shadowX}px ${shadowY}px 20px rgba(0,0,0,0.3))`
*
* return <motion.div style={{ filter: shadow }} />
* }
* ```
*
* @public
*/
function useMotionTemplate(fragments, ...values) {
/**
* Create a function that will build a string from the latest motion values.
*/
const numFragments = fragments.length;
function buildValue() {
let output = ``;
for (let i = 0; i < numFragments; i++) {
output += fragments[i];
const value = values[i];
if (value) {
output += isMotionValue(value) ? value.get() : value;
}
}
return output;
}
return useCombineMotionValues(values.filter(isMotionValue), buildValue);
}
export { useMotionTemplate };
//# sourceMappingURL=use-motion-template.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"use-scroll.mjs","sources":["../../../src/value/use-scroll.ts"],"sourcesContent":["\"use client\"\n\nimport {\n AnimationPlaybackControls,\n motionValue,\n supportsScrollTimeline,\n supportsViewTimeline,\n} from \"motion-dom\"\nimport { invariant } from \"motion-utils\"\nimport { RefObject, useCallback, useEffect, useRef } from \"react\"\nimport { scroll } from \"../render/dom/scroll\"\nimport { ScrollInfoOptions } from \"../render/dom/scroll/types\"\nimport { offsetToViewTimelineRange } from \"../render/dom/scroll/utils/offset-to-range\"\nimport { useConstant } from \"../utils/use-constant\"\nimport { useIsomorphicLayoutEffect } from \"../utils/use-isomorphic-effect\"\n\nexport interface UseScrollOptions\n extends Omit<ScrollInfoOptions, \"container\" | \"target\"> {\n container?: RefObject<HTMLElement | null>\n target?: RefObject<HTMLElement | null>\n}\n\nconst createScrollMotionValues = () => ({\n scrollX: motionValue(0),\n scrollY: motionValue(0),\n scrollXProgress: motionValue(0),\n scrollYProgress: motionValue(0),\n})\n\nconst isRefPending = (ref?: RefObject<HTMLElement | null>) => {\n if (!ref) return false\n return !ref.current\n}\n\nfunction makeAccelerateConfig(\n axis: \"x\" | \"y\",\n options: Omit<UseScrollOptions, \"container\" | \"target\">,\n container?: RefObject<HTMLElement | null>,\n target?: RefObject<HTMLElement | null>\n) {\n return {\n factory: (animation: AnimationPlaybackControls) =>\n scroll(animation, {\n ...options,\n axis,\n container: container?.current || undefined,\n target: target?.current || undefined,\n }),\n times: [0, 1],\n keyframes: [0, 1],\n ease: (v: number) => v,\n duration: 1,\n }\n}\n\nfunction canAccelerateScroll(\n target?: RefObject<HTMLElement | null>,\n offset?: ScrollInfoOptions[\"offset\"]\n) {\n if (typeof window === \"undefined\") return false\n return target\n ? supportsViewTimeline() && !!offsetToViewTimelineRange(offset)\n : supportsScrollTimeline()\n}\n\nexport function useScroll({\n container,\n target,\n ...options\n}: UseScrollOptions = {}) {\n const values = useConstant(createScrollMotionValues)\n\n if (canAccelerateScroll(target, options.offset)) {\n values.scrollXProgress.accelerate = makeAccelerateConfig(\n \"x\",\n options,\n container,\n target\n )\n values.scrollYProgress.accelerate = makeAccelerateConfig(\n \"y\",\n options,\n container,\n target\n )\n }\n\n const scrollAnimation = useRef<VoidFunction | null>(null)\n const needsStart = useRef(false)\n\n const start = useCallback(() => {\n scrollAnimation.current = scroll(\n (\n _progress: number,\n {\n x,\n y,\n }: {\n x: { current: number; progress: number }\n y: { current: number; progress: number }\n }\n ) => {\n values.scrollX.set(x.current)\n values.scrollXProgress.set(x.progress)\n values.scrollY.set(y.current)\n values.scrollYProgress.set(y.progress)\n },\n {\n ...options,\n container: container?.current || undefined,\n target: target?.current || undefined,\n }\n )\n\n return () => {\n scrollAnimation.current?.()\n }\n }, [container, target, JSON.stringify(options.offset)])\n\n useIsomorphicLayoutEffect(() => {\n needsStart.current = false\n\n if (isRefPending(container) || isRefPending(target)) {\n needsStart.current = true\n return\n } else {\n return start()\n }\n }, [start])\n\n useEffect(() => {\n if (needsStart.current) {\n invariant(\n !isRefPending(container),\n \"Container ref is defined but not hydrated\",\n \"use-scroll-ref\"\n )\n invariant(\n !isRefPending(target),\n \"Target ref is defined but not hydrated\",\n \"use-scroll-ref\"\n )\n return start()\n } else {\n return\n }\n }, [start])\n\n return values\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBA;AACI;AACA;AACA;AACA;AACH;AAED;AACI;AAAU;AACV;AACJ;AAEA;;;AASgB;;AAEA;AACA;;AAER;AACA;AACA;AACA;;AAER;AAEA;;AAIuC;AACnC;;;AAGJ;AAEM;AAKF;;AAGI;AAMA;;AAQJ;AACA;AAEA;AACI;;;;;AAeI;AAEI;AACA;AACA;AACH;AAGL;AACI;AACJ;AACJ;;AAGI;;AAGI;;;;;;AAKR;;AAGI;;;;;;;;AAeJ;AAEA;AACJ;;"}

View File

@@ -0,0 +1,9 @@
"use client";
import { useFollowValue } from './use-follow-value.mjs';
function useSpring(source, options = {}) {
return useFollowValue(source, { type: "spring", ...options });
}
export { useSpring };
//# sourceMappingURL=use-spring.mjs.map

View File

@@ -0,0 +1,20 @@
import { MotionValue, transformProps, acceleratedValues } from 'motion-dom';
class WillChangeMotionValue extends MotionValue {
constructor() {
super(...arguments);
this.isEnabled = false;
}
add(name) {
if (transformProps.has(name) || acceleratedValues.has(name)) {
this.isEnabled = true;
this.update();
}
}
update() {
this.set(this.isEnabled ? "transform" : "auto");
}
}
export { WillChangeMotionValue };
//# sourceMappingURL=WillChangeMotionValue.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"WillChangeMotionValue.mjs","sources":["../../../../src/value/use-will-change/WillChangeMotionValue.ts"],"sourcesContent":["import {\n acceleratedValues,\n MotionValue,\n transformProps,\n type WillChange,\n} from \"motion-dom\"\n\nexport class WillChangeMotionValue\n extends MotionValue<string>\n implements WillChange\n{\n private isEnabled = false\n\n add(name: string) {\n if (transformProps.has(name) || acceleratedValues.has(name)) {\n this.isEnabled = true\n this.update()\n }\n }\n\n private update() {\n this.set(this.isEnabled ? \"transform\" : \"auto\")\n }\n}\n"],"names":[],"mappings":";;AAOM,MAAO,qBACT,SAAQ,WAAmB,CAAA;AAD/B,IAAA,WAAA,GAAA;;QAIY,IAAA,CAAA,SAAS,GAAG,KAAK;IAY7B;AAVI,IAAA,GAAG,CAAC,IAAY,EAAA;AACZ,QAAA,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AACzD,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;YACrB,IAAI,CAAC,MAAM,EAAE;QACjB;IACJ;IAEQ,MAAM,GAAA;AACV,QAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;IACnD;AACH;;;;"}