framer-motion
Version:
A simple and powerful JavaScript animation library
2 lines (1 loc) • 7.09 kB
JavaScript
import{jsxs as t,jsx as n}from"react/jsx-runtime";import{createContext as e,useContext as r,useMemo as o,useCallback as a,useLayoutEffect as i,useEffect as s,useRef as u,useInsertionEffect as l,forwardRef as c,Fragment as d,createElement as f}from"react";import{i as m,a as p,f as y,b as g,c as v,P as h,S,o as M,m as w,L as b,d as E,e as P,g as j,h as C,j as V,k as T,r as A,l as x,n as L,p as W,s as I,q as k,t as O,u as D,v as R,w as F}from"./size-rollup-dom-max-assets.js";const N=e({strict:!1}),H=e({transformPagePoint:t=>t,isStatic:!1,reducedMotion:"never"}),U=e({});function q(t){const{initial:n,animate:e}=function(t,n){if(m(t)){const{initial:n,animate:e}=t;return{initial:!1===n||p(n)?n:void 0,animate:p(e)?e:void 0}}return!1!==t.inherit?n:{}}(t,r(U));return o((()=>({initial:n,animate:e})),[B(n),B(e)])}function B(t){return Array.isArray(t)?t.join(" "):t}const $=Symbol.for("motionComponentSymbol");function _(t,n,e){return a((r=>{r&&t.onMount&&t.onMount(r),n&&(r?n.mount(r):n.unmount()),e&&("function"==typeof e?e(r):g(e)&&(e.current=r))}),[n])}const z=v?i:s;function X(t,n,e,o,a){const{visualElement:i}=r(U),c=r(N),d=r(h),f=r(H).reducedMotion,m=u(null);o=o||c.renderer,!m.current&&o&&(m.current=o(t,{visualState:n,parent:i,props:e,presenceContext:d,blockInitialAnimation:!!d&&!1===d.initial,reducedMotionConfig:f}));const p=m.current,y=r(S);!p||p.projection||!a||"html"!==p.type&&"svg"!==p.type||function(t,n,e,r){const{layoutId:o,layout:a,drag:i,dragConstraints:s,layoutScroll:u,layoutRoot:l,layoutCrossfade:c}=n;t.projection=new e(t.latestValues,n["data-framer-portal-id"]?void 0:Y(t.parent)),t.projection.setOptions({layoutId:o,layout:a,alwaysMeasureLayout:Boolean(i)||s&&g(s),visualElement:t,animationType:"string"==typeof a?a:"both",initialPromotionConfig:r,crossfade:c,layoutScroll:u,layoutRoot:l})}(m.current,e,a,y);const v=u(!1);l((()=>{p&&v.current&&p.update(e,d)}));const b=e[M],E=u(Boolean(b)&&!window.MotionHandoffIsComplete?.(b)&&window.MotionHasOptimisedAnimation?.(b));return z((()=>{p&&(v.current=!0,window.MotionIsMounted=!0,p.updateFeatures(),w.render(p.render),E.current&&p.animationState&&p.animationState.animateChanges())})),s((()=>{p&&(!E.current&&p.animationState&&p.animationState.animateChanges(),E.current&&(queueMicrotask((()=>{window.MotionHandoffMarkAsComplete?.(b)})),E.current=!1))})),p}function Y(t){if(t)return!1!==t.options.allowProjection?t.projection:Y(t.parent)}function G({preloadedFeatures:e,createVisualElement:o,useRender:a,useVisualState:i,Component:s}){function u(e,u){let l;const c={...r(H),...e,layoutId:J(e)},{isStatic:d}=c,f=q(e),m=i(e,d);if(!d&&v){r(N).strict;const t=function(t){const{drag:n,layout:e}=y;if(!n&&!e)return{};const r={...n,...e};return{MeasureLayout:n?.isEnabled(t)||e?.isEnabled(t)?r.MeasureLayout:void 0,ProjectionNode:r.ProjectionNode}}(c);l=t.MeasureLayout,f.visualElement=X(s,m,c,o,t.ProjectionNode)}return t(U.Provider,{value:f,children:[l&&f.visualElement?n(l,{visualElement:f.visualElement,...c}):null,a(s,e,_(m,f.visualElement,u),m,d,f.visualElement)]})}e&&function(t){for(const n in t)y[n]={...y[n],...t[n]}}(e),u.displayName=`motion.${"string"==typeof s?s:`create(${s.displayName??s.name??""})`}`;const l=c(u);return l[$]=s,l}function J({layoutId:t}){const n=r(b).id;return n&&void 0!==t?n+"-"+t:t}const K=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function Q(t,n,e){for(const r in n)E(n[r])||P(r,e)||(t[r]=n[r])}function Z(t,n){const e={};return Q(e,t.style||{},t),Object.assign(e,function({transformTemplate:t},n){return o((()=>{const e={style:{},transform:{},transformOrigin:{},vars:{}};return j(e,n,t),Object.assign({},e.vars,e.style)}),[n])}(t,n)),e}function tt(t,n){const e={},r=Z(t,n);return t.drag&&!1!==t.dragListener&&(e.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=!0===t.drag?"none":"pan-"+("x"===t.drag?"y":"x")),void 0===t.tabIndex&&(t.onTap||t.onTapStart||t.whileTap)&&(e.tabIndex=0),e.style=r,e}const nt=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","ignoreStrict","viewport"]);function et(t){return t.startsWith("while")||t.startsWith("drag")&&"draggable"!==t||t.startsWith("layout")||t.startsWith("onTap")||t.startsWith("onPan")||t.startsWith("onLayout")||nt.has(t)}let rt=t=>!et(t);try{(ot=require("@emotion/is-prop-valid").default)&&(rt=t=>t.startsWith("on")?!et(t):ot(t))}catch{}var ot;const at=()=>({style:{},transform:{},transformOrigin:{},vars:{},attrs:{}});function it(t,n,e,r){const a=o((()=>{const e={style:{},transform:{},transformOrigin:{},vars:{},attrs:{}};return C(e,n,V(r),t.transformTemplate),{...e.attrs,style:{...e.style}}}),[n]);if(t.style){const n={};Q(n,t.style,t),a.style={...n,...a.style}}return a}function st(t=!1){return(n,e,r,{latestValues:a},i)=>{const s=(T(n)?it:tt)(e,a,i,n),u=function(t,n,e){const r={};for(const o in t)"values"===o&&"object"==typeof t.values||(rt(o)||!0===e&&et(o)||!n&&!et(o)||t.draggable&&o.startsWith("onDrag"))&&(r[o]=t[o]);return r}(e,"string"==typeof n,t),l=n!==d?{...u,...s,ref:r}:{},{children:c}=e,m=o((()=>E(c)?c.get():c),[c]);return f(n,{...l,children:m})}}const ut=t=>(n,e)=>{const o=r(U),a=r(h),i=()=>function({scrapeMotionValuesFromProps:t,createRenderState:n,onUpdate:e},r,o,a){const i={latestValues:lt(r,o,a,t),renderState:n()};return e&&(i.onMount=t=>e({props:r,current:t,...i}),i.onUpdate=t=>e(t)),i}(t,n,o,a);return e?i():function(t){const n=u(null);return null===n.current&&(n.current=t()),n.current}(i)};function lt(t,n,e,r){const o={},a=r(t,{});for(const t in a)o[t]=A(a[t]);let{initial:i,animate:s}=t;const u=m(t),l=x(t);n&&l&&!u&&!1!==t.inherit&&(void 0===i&&(i=n.initial),void 0===s&&(s=n.animate));let c=!!e&&!1===e.initial;c=c||!1===i;const d=c?s:i;if(d&&"boolean"!=typeof d&&!L(d)){const n=Array.isArray(d)?d:[d];for(let e=0;e<n.length;e++){const r=W(t,n[e]);if(r){const{transitionEnd:t,transition:n,...e}=r;for(const t in e){let n=e[t];if(Array.isArray(n)){n=n[c?n.length-1:0]}null!==n&&(o[t]=n)}for(const n in t)o[n]=t[n]}}}return o}const ct={useVisualState:ut({scrapeMotionValuesFromProps:I,createRenderState:K})},dt=["x","y","width","height","cx","cy","r"],ft={useVisualState:ut({scrapeMotionValuesFromProps:k,createRenderState:at,onUpdate:({props:t,prevProps:n,current:e,renderState:r,latestValues:o})=>{if(!e)return;let a=!!t.drag;if(!a)for(const t in o)if(O.has(t)){a=!0;break}if(!a)return;let i=!n;if(n)for(let e=0;e<dt.length;e++){const r=dt[e];t[r]!==n[r]&&(i=!0)}i&&D.read((()=>{R(e,r),D.render((()=>{C(r,o,V(e.tagName),t.transformTemplate),F(e,r)}))}))}})};function mt(t,n){return function(e,{forwardMotionProps:r}={forwardMotionProps:!1}){return G({...T(e)?ft:ct,preloadedFeatures:t,useRender:st(r),createVisualElement:n,Component:e})}}const pt=mt()("div");export{pt as MotionDiv};