UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

2 lines (1 loc) • 33.2 kB
import{createContext as t}from"react";function e(t,e){-1===t.indexOf(e)&&t.push(e)}function s(t,e){const s=t.indexOf(e);s>-1&&t.splice(s,1)}const n=(t,e,s)=>s>e?e:s<t?t:s;function i(t,e){return e?`${t}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${e}`:t}let a=()=>{},r=()=>{};"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&(a=(t,e,s)=>{t||"undefined"==typeof console||console.warn(i(e,s))},r=(t,e,s)=>{if(!t)throw new Error(i(e,s))});const o={},h=t=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(t),l=t=>/^0[^.\s]+$/u.test(t);function u(t){let e;return()=>(void 0===e&&(e=t()),e)}const c=t=>t;class d{constructor(){this.subscriptions=[]}add(t){return e(this.subscriptions,t),()=>this.remove(t)}remove(t){s(this.subscriptions,t)}notify(t,e,s){const n=this.subscriptions.length;if(n)if(1===n)this.subscriptions[0](t,e,s);else for(let i=0;i<n;i++){const n=this.subscriptions[i];n&&n(t,e,s)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}}const p=t=>1e3*t,f=t=>t/1e3,m=(t,e)=>e?t*(1e3/e):0,g=t=>Array.isArray(t)&&"number"==typeof t[0],v=t({}),y=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function b(t,e){let s=!1,n=!0;const i={delta:0,timestamp:0,isProcessing:!1},a=()=>s=!0,r=y.reduce((t,e)=>(t[e]=function(t){let e=new Set,s=new Set,n=!1,i=!1;const a=new Set;let r={delta:0,timestamp:0,isProcessing:!1};function o(e){a.has(e)&&(s.add(e),t()),e(r)}const h={schedule:(t,i=!1,r=!1)=>{const o=r&&n?e:s;return i&&a.add(t),o.add(t),t},cancel:t=>{s.delete(t),a.delete(t)},process:t=>{if(r=t,n)return void(i=!0);n=!0;const a=e;e=s,s=a,e.forEach(o),e.clear(),n=!1,i&&(i=!1,h.process(t))}};return h}(a),t),{}),{setup:h,read:l,resolveKeyframes:u,preUpdate:c,update:d,preRender:p,render:f,postRender:m}=r,g=()=>{const a=o.useManualTiming,r=a?i.timestamp:performance.now();s=!1,a||(i.delta=n?1e3/60:Math.max(Math.min(r-i.timestamp,40),1)),i.timestamp=r,i.isProcessing=!0,h.process(i),l.process(i),u.process(i),c.process(i),d.process(i),p.process(i),f.process(i),m.process(i),i.isProcessing=!1,s&&e&&(n=!1,t(g))};return{schedule:y.reduce((e,a)=>{const o=r[a];return e[a]=(e,a=!1,r=!1)=>(s||(s=!0,n=!0,i.isProcessing||t(g)),o.schedule(e,a,r)),e},{}),cancel:t=>{for(let e=0;e<y.length;e++)r[y[e]].cancel(t)},state:i,steps:r}}const{schedule:w,cancel:S,state:V,steps:M}=b("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:c,!0);let T;function C(){T=void 0}const x={now:()=>(void 0===T&&x.set(V.isProcessing||o.useManualTiming?V.timestamp:performance.now()),T),set:t=>{T=t,queueMicrotask(C)}},A=t=>Math.round(1e5*t)/1e5,k=t=>e=>"string"==typeof e&&e.startsWith(t),E=k("--"),R=k("var(--"),F=t=>!!R(t)&&P.test(t.split("/*")[0].trim()),P=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function B(t){return"string"==typeof t&&t.split("/*")[0].includes("var(--")}const I={test:t=>"number"==typeof t,parse:parseFloat,transform:t=>t},N={...I,transform:t=>n(0,1,t)},O={...I,default:1},$=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;const L=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,Y=(t,e)=>s=>Boolean("string"==typeof s&&L.test(s)&&s.startsWith(t)||e&&!function(t){return null==t}(s)&&Object.prototype.hasOwnProperty.call(s,e)),W=(t,e,s)=>n=>{if("string"!=typeof n)return n;const[i,a,r,o]=n.match($);return{[t]:parseFloat(i),[e]:parseFloat(a),[s]:parseFloat(r),alpha:void 0!==o?parseFloat(o):1}},X={...I,transform:t=>Math.round((t=>n(0,255,t))(t))},j={test:Y("rgb","red"),parse:W("red","green","blue"),transform:({red:t,green:e,blue:s,alpha:n=1})=>"rgba("+X.transform(t)+", "+X.transform(e)+", "+X.transform(s)+", "+A(N.transform(n))+")"};const _={test:Y("#"),parse:function(t){let e="",s="",n="",i="";return t.length>5?(e=t.substring(1,3),s=t.substring(3,5),n=t.substring(5,7),i=t.substring(7,9)):(e=t.substring(1,2),s=t.substring(2,3),n=t.substring(3,4),i=t.substring(4,5),e+=e,s+=s,n+=n,i+=i),{red:parseInt(e,16),green:parseInt(s,16),blue:parseInt(n,16),alpha:i?parseInt(i,16)/255:1}},transform:j.transform},U=t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}),z=U("deg"),K=U("%"),Z=U("px"),D=U("vh"),q=U("vw"),H=(()=>({...K,parse:t=>K.parse(t)/100,transform:t=>K.transform(100*t)}))(),G={test:Y("hsl","hue"),parse:W("hue","saturation","lightness"),transform:({hue:t,saturation:e,lightness:s,alpha:n=1})=>"hsla("+Math.round(t)+", "+K.transform(A(e))+", "+K.transform(A(s))+", "+A(N.transform(n))+")"},J={test:t=>j.test(t)||_.test(t)||G.test(t),parse:t=>j.test(t)?j.parse(t):G.test(t)?G.parse(t):_.parse(t),transform:t=>"string"==typeof t?t:t.hasOwnProperty("red")?j.transform(t):G.transform(t),getAnimatableNone:t=>{const e=J.parse(t);return e.alpha=0,J.transform(e)}},Q=new RegExp($.source),tt=new RegExp(/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu.source,"i");const et="number",st="color",nt=/var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;function it(t){const e=t.toString();return Q.test(e)||tt.test(e)}function at(t){const e=t.toString(),s=[],n={color:[],number:[],var:[]},i=[];let a=0;const r=e.replace(nt,t=>(J.test(t)?(n.color.push(a),i.push(st),s.push(J.parse(t))):t.startsWith("var(")?(n.var.push(a),i.push("var"),s.push(t)):(n.number.push(a),i.push(et),s.push(parseFloat(t))),++a,"${}")).split("${}");return{values:s,split:r,indexes:n,types:i}}function rt({split:t,types:e}){const s=t.length;return n=>{let i="";for(let a=0;a<s;a++)if(i+=t[a],void 0!==n[a]){const t=e[a];i+=t===et?A(n[a]):t===st?J.transform(n[a]):n[a]}return i}}const ot=(t,e)=>{return"number"==typeof t?e?.trim().endsWith("/")?t:0:"number"==typeof(s=t)?0:J.test(s)?J.getAnimatableNone(s):s;var s};const ht={test:function(t){return isNaN(t)&&"string"==typeof t&&(Q.test(t)||tt.test(t))},parse:function(t){return at(t).values},createTransformer:function(t){return rt(at(t))},getAnimatableNone:function(t){const e=at(t);return rt(e)(e.values.map((t,s)=>ot(t,e.split[s])))}},lt=(t,e,s)=>t+(e-t)*s,ut=(t,e,s=10)=>{let n="";const i=Math.max(Math.round(e/s),2);for(let e=0;e<i;e++)n+=Math.round(1e4*t(e/(i-1)))/1e4+", ";return`linear(${n.substring(0,n.length-2)})`},ct=t=>null!==t;function dt(t,{repeat:e,repeatType:s="loop"},n,i=1){const a=t.filter(ct),r=i<0||e&&"loop"!==s&&e%2==1?0:a.length-1;return r&&void 0!==n?n:a[r]}function pt(t,e){return{kind:t,animation:e,timestamp:x.now(),frameTimestamp:V.timestamp,frameIsProcessing:V.isProcessing}}function ft(t,e,s){const n=globalThis.__MOTION_INSPECT__;if(n)try{n({...pt("animation-start",t),options:s?{...e,...s}:e})}catch{}}function mt(t,e){const s=globalThis.__MOTION_INSPECT__;if(s)try{s({...pt("layout-animation-start",t),node:e})}catch{}}class gt{constructor(){this.isResolved=!1}get finished(){return this._finished||(this._finished=this.isResolved?Promise.resolve():new Promise(t=>{this._resolve=t})),this._finished}updateFinished(){this._finished=this._resolve=void 0,this.isResolved=!1}notifyFinished(){this.isResolved=!0,this._resolve?.()}then(t,e){return this.finished.then(t,e)}}const vt=new Set(["brightness","contrast","saturate","opacity"]);function yt(t){const[e,s]=t.slice(0,-1).split("(");if("drop-shadow"===e)return t;const[n]=s.match($)||[];if(!n)return t;const i=s.replace(n,"");let a=vt.has(e)?1:0;return n!==s&&(a*=100),e+"("+a+i+")"}const bt=/\b([a-z-]*)\(.*?\)/gu,wt={...ht,getAnimatableNone:t=>{const e=t.match(bt);return e?e.map(yt).join(" "):t}},St={...ht,getAnimatableNone:t=>{const e=ht.parse(t);return ht.createTransformer(t)(e.map(t=>"number"==typeof t?0:"object"==typeof t?{...t,alpha:1}:t))}},Vt={...I,transform:Math.round},Mt={borderWidth:Z,borderTopWidth:Z,borderRightWidth:Z,borderBottomWidth:Z,borderLeftWidth:Z,borderRadius:Z,borderTopLeftRadius:Z,borderTopRightRadius:Z,borderBottomRightRadius:Z,borderBottomLeftRadius:Z,width:Z,maxWidth:Z,height:Z,maxHeight:Z,top:Z,right:Z,bottom:Z,left:Z,inset:Z,insetBlock:Z,insetBlockStart:Z,insetBlockEnd:Z,insetInline:Z,insetInlineStart:Z,insetInlineEnd:Z,padding:Z,paddingTop:Z,paddingRight:Z,paddingBottom:Z,paddingLeft:Z,paddingBlock:Z,paddingBlockStart:Z,paddingBlockEnd:Z,paddingInline:Z,paddingInlineStart:Z,paddingInlineEnd:Z,margin:Z,marginTop:Z,marginRight:Z,marginBottom:Z,marginLeft:Z,marginBlock:Z,marginBlockStart:Z,marginBlockEnd:Z,marginInline:Z,marginInlineStart:Z,marginInlineEnd:Z,fontSize:Z,backgroundPositionX:Z,backgroundPositionY:Z,...{rotate:z,pathRotation:z,rotateX:z,rotateY:z,rotateZ:z,scale:O,scaleX:O,scaleY:O,scaleZ:O,skew:z,skewX:z,skewY:z,distance:Z,translateX:Z,translateY:Z,translateZ:Z,x:Z,y:Z,z:Z,perspective:Z,transformPerspective:Z,opacity:N,originX:H,originY:H,originZ:Z},zIndex:Vt,fillOpacity:N,strokeOpacity:N,numOctaves:Vt},Tt={...Mt,color:J,backgroundColor:J,outlineColor:J,fill:J,stroke:J,borderColor:J,borderTopColor:J,borderRightColor:J,borderBottomColor:J,borderLeftColor:J,filter:wt,WebkitFilter:wt,mask:St,WebkitMask:St},Ct=t=>Tt[t],xt=new Set([wt,St]);function At(t,e){let s=Ct(t);return xt.has(s)||(s=ht),s.getAnimatableNone?s.getAnimatableNone(e):void 0}const kt=t=>180*t/Math.PI,Et=t=>{const e=kt(Math.atan2(t[1],t[0]));return Ft(e)},Rt={x:4,y:5,translateX:4,translateY:5,scaleX:0,scaleY:3,scale:t=>(Math.abs(t[0])+Math.abs(t[3]))/2,rotate:Et,rotateZ:Et,skewX:t=>kt(Math.atan(t[1])),skewY:t=>kt(Math.atan(t[2])),skew:t=>(Math.abs(t[1])+Math.abs(t[2]))/2},Ft=t=>((t%=360)<0&&(t+=360),t),Pt=t=>Math.sqrt(t[0]*t[0]+t[1]*t[1]),Bt=t=>Math.sqrt(t[4]*t[4]+t[5]*t[5]),It={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:Pt,scaleY:Bt,scale:t=>(Pt(t)+Bt(t))/2,rotateX:t=>Ft(kt(Math.atan2(t[6],t[5]))),rotateY:t=>Ft(kt(Math.atan2(-t[2],t[0]))),rotateZ:Et,rotate:Et,skewX:t=>kt(Math.atan(t[4])),skewY:t=>kt(Math.atan(t[1])),skew:t=>(Math.abs(t[1])+Math.abs(t[4]))/2};function Nt(t){return t.includes("scale")?1:0}function Ot(t,e){if(!t||"none"===t)return Nt(e);const s=t.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);let n,i;if(s)n=It,i=s;else{const e=t.match(/^matrix\(([-\d.e\s,]+)\)$/u);n=Rt,i=e}if(!i)return Nt(e);const a=n[e],r=i[1].split(",").map(Lt);return"function"==typeof a?a(r):r[a]}const $t=(t,e)=>{const{transform:s="none"}=getComputedStyle(t);return Ot(s,e)};function Lt(t){return parseFloat(t.trim())}const Yt=["transformPerspective","x","y","z","translateX","translateY","translateZ","scale","scaleX","scaleY","rotate","rotateX","rotateY","rotateZ","skew","skewX","skewY"],Wt=(()=>new Set([...Yt,"pathRotation"]))(),Xt=t=>t===I||t===Z,jt=new Set(["x","y","z"]),_t=Yt.filter(t=>!jt.has(t));const Ut=new Set(["bottom","right"]);function zt(t,e,s,n,i,a){const r=parseFloat(t);if(!isNaN(r))return r;const{min:o,max:h}=e()[s],l=h-o;return"border-box"===a?l:l-parseFloat(n)-parseFloat(i)}const Kt={width:({width:t,paddingLeft:e="0",paddingRight:s="0",boxSizing:n},i)=>zt(t,i,"x",e,s,n),height:({height:t,paddingTop:e="0",paddingBottom:s="0",boxSizing:n},i)=>zt(t,i,"y",e,s,n),top:({top:t})=>parseFloat(t),left:({left:t})=>parseFloat(t),bottom:({top:t},e)=>{const{y:s}=e();return parseFloat(t)+(s.max-s.min)},right:({left:t},e)=>{const{x:s}=e();return parseFloat(t)+(s.max-s.min)},x:({transform:t})=>Ot(t,"x"),y:({transform:t})=>Ot(t,"y")};Kt.translateX=Kt.x,Kt.translateY=Kt.y;const Zt=new Set;let Dt=!1,qt=!1,Ht=!1;function Gt(){if(qt){const t=[],e=new Set,s=new Set;Zt.forEach(n=>{n.needsMeasurement&&(t.push(n),e.add(n.element),Ut.has(n.name)&&s.add(n.element))});const n=new Map;s.forEach(t=>{const e=function(t){const e=[];return _t.forEach(s=>{const n=t.getValue(s);if(void 0!==n){const t=n.get(),i=s.startsWith("scale")?1:0;if(t===i)return;e.push([s,t]),n.set(i)}}),e}(t);e.length&&(n.set(t,e),t.render())}),t.forEach(t=>t.measureInitialState()),e.forEach(t=>{t.render();const e=n.get(t);e&&e.forEach(([e,s])=>{t.getValue(e)?.set(s)})}),t.forEach(t=>t.measureEndState()),t.forEach(t=>{void 0!==t.suspendedScrollY&&window.scrollTo(0,t.suspendedScrollY)})}qt=!1,Dt=!1,Zt.forEach(t=>t.complete(Ht)),Zt.clear()}function Jt(){Zt.forEach(t=>{t.readKeyframes(),t.needsMeasurement&&(qt=!0)})}function Qt(){Ht=!0,Jt(),Gt(),Ht=!1}class te{constructor(t,e,s,n,i,a=!1){this.state="pending",this.isAsync=!1,this.needsMeasurement=!1,this.unresolvedKeyframes=[...t],this.onComplete=e,this.name=s,this.motionValue=n,this.element=i,this.isAsync=a}scheduleResolve(){this.state="scheduled",this.isAsync?(Zt.add(this),Dt||(Dt=!0,w.read(Jt),w.resolveKeyframes(Gt))):(this.readKeyframes(),this.complete())}readKeyframes(){const{unresolvedKeyframes:t,name:e,element:s,motionValue:n}=this;if(null===t[0]){const i=n?.get(),a=t[t.length-1];if(void 0!==i)t[0]=i;else if(s&&e){const n=function(t,e,s){if("string"==typeof t){if(h(t)||l(t))return parseFloat(t);if(!ht.test(t)&&ht.test(s))return At(e,s)}return t??void 0}(s.readValue(e,a),e,a);void 0!==n&&(t[0]=n)}void 0===t[0]&&(t[0]=a),n&&void 0===i&&n.set(t[0])}!function(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}(t)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(t=!1){this.state="complete",this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,t),Zt.delete(this)}cancel(){"scheduled"===this.state&&(Zt.delete(this),this.state="pending")}resume(){"pending"===this.state&&this.scheduleResolve()}}function ee(t,e,s){(t=>t.startsWith("--"))(e)?t.style.setProperty(e,s):t.style[e]=s}const se={};function ne(t,e){const s=u(t);return()=>se[e]??s()}const ie=ne(()=>void 0!==window.ScrollTimeline,"scrollTimeline"),ae=ne(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),re=([t,e,s,n])=>`cubic-bezier(${t}, ${e}, ${s}, ${n})`,oe={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:re([0,.65,.55,1]),circOut:re([.55,0,1,.45]),backIn:re([.31,.01,.66,-.59]),backOut:re([.33,1.53,.69,.99])};function he(t,e){return t?"function"==typeof t?ae()?ut(t,e):"ease-out":g(t)?re(t):Array.isArray(t)?t.map(t=>he(t,e)||oe.easeOut):oe[t]:void 0}function le(t,e,s,{delay:n=0,duration:i=300,repeat:a=0,repeatType:r="loop",ease:o="easeOut",times:h}={},l=void 0){const u={[e]:s};h&&(u.offset=h);const c=he(o,i);Array.isArray(c)&&(u.easing=c);const d={delay:n,duration:i,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:a+1,direction:"reverse"===r?"alternate":"normal"};return l&&(d.pseudoElement=l),t.animate(u,d)}function ue(t){return"function"==typeof t&&"applyToOptions"in t}class ce extends gt{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:e,name:s,keyframes:n,pseudoElement:i,allowFlatten:a=!1,finalKeyframe:o,onComplete:h}=t;this.isPseudoElement=Boolean(i),this.allowFlatten=a,this.options=t,r("string"!=typeof t.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const l=function({type:t,...e}){return ue(t)&&ae()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(t);this.animation=le(e,s,n,l,i),!1===l.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!i){const t=dt(n,this.options,o,this.speed);this.updateMotionValue&&this.updateMotionValue(t),ee(e,s,t),this.animation.cancel()}h?.(),this.notifyFinished()},ft(this,t,l)}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){const t=this.options?.element;!this.isPseudoElement&&t?.isConnected&&this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return f(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+f(t)}get time(){return f(Number(this.animation.currentTime)||0)}set time(t){const e=null!==this.finishedTime;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=p(t),e&&this.animation.pause()}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,rangeStart:e,rangeEnd:s,observe:n}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&ie()?(this.animation.timeline=t,e&&(this.animation.rangeStart=e),s&&(this.animation.rangeEnd=s),c):n(this)}}const de=new Set(["opacity","clipPath","filter","transform","backgroundColor"]);class pe{constructor(t,e={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=t=>{const e=x.now();if(this.updatedAt!==e&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(t),this.current!==this.prev&&(this.notifyChange(),this.dependents))for(const t of this.dependents)t.dirty()},this.hasAnimated=!1,this.setCurrent(t),this.owner=e.owner}setCurrent(t){var e;this.current=t,this.updatedAt=x.now(),null===this.canTrackVelocity&&void 0!==t&&(this.canTrackVelocity=(e=this.current,!isNaN(parseFloat(e))))}setPrevFrameValue(t=this.current){this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt}onChange(t){return this.on("change",t)}on(t,e){var s;return"change"===t?this.onChangeSubscribe(e):((s=this.events)[t]||(s[t]=new d)).add(e)}onChangeSubscribe(t){const{events:e}=this;return e.change||this.changeSubscriber?(e.change||(e.change=new d,e.change.add(this.changeSubscriber),this.changeSubscriber=void 0),e.change.add(t)):this.changeSubscriber=t,()=>{this.changeSubscriber===t?this.changeSubscriber=void 0:e.change?.remove(t),this.stopIfUnobserved()}}stopIfUnobserved(){w.read(()=>{this.changeSubscriber||this.events.change?.getSize()||this.stop()})}clearListeners(){this.changeSubscriber=void 0;for(const t in this.events)this.events[t].clear()}attach(t,e){this.passiveEffect=t,this.stopPassiveEffect=e}set(t){this.passiveEffect?this.passiveEffect(t,this.updateAndNotify):this.updateAndNotify(t)}setWithVelocity(t,e,s){this.set(e),this.prev=void 0,this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt-s}jump(t,e=!0){this.updateAndNotify(t),this.prev=t,this.prevUpdatedAt=this.prevFrameValue=void 0,e&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){this.notifyChange()}notifyChange(){const{current:t,changeSubscriber:e}=this;e?e(t):this.events.change?.notify(t)}addDependent(t){this.dependents||(this.dependents=new Set),this.dependents.add(t)}removeDependent(t){this.dependents&&this.dependents.delete(t)}get(){return this.current}getPrevious(){return this.prev}getVelocity(){const t=x.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||t-this.updatedAt>30)return 0;const e=Math.min(this.updatedAt-this.prevUpdatedAt,30);return m(parseFloat(this.current)-parseFloat(this.prevFrameValue),e)}start(t){return this.stop(),new Promise(e=>{this.hasAnimated=!0;let s,n=!1;s=t(()=>{n=!0,this.events.animationComplete?.notify(),this.animation===s&&this.clearAnimation(),e()}),n||(this.animation=s),this.events.animationStart?.notify()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){this.animation=void 0}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function fe(t,e){return new pe(t,e)}function me(t){const e=[{},{}];return t?.values.forEach((t,s)=>{e[0][s]=t.get(),e[1][s]=t.getVelocity()}),e}function ge(t,e,s,n){if("function"==typeof e){const[i,a]=me(n);e=e(void 0!==s?s:t.custom,i,a)}if("string"==typeof e&&(e=t.variants&&t.variants[e]),"function"==typeof e){const[i,a]=me(n);e=e(void 0!==s?s:t.custom,i,a)}return e}const ve=t=>Boolean(t&&t.getVelocity);function ye(t){return t.replace(/([A-Z])/g,t=>`-${t.toLowerCase()}`)}const be="data-"+ye("framerAppearId"),we=["borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius"],Se=(t,e)=>e&&"number"==typeof t?e.transform(t):t,Ve={x:"translateX",y:"translateY",z:"translateZ",transformPerspective:"perspective"},Me=Yt.length;function Te(t,e,s){const{style:n,vars:i,transformOrigin:a}=t;let r=!1,o=!1;for(const t in e){const s=e[t];if(Wt.has(t))r=!0;else if(E(t))i[t]=s;else{const e=Se(s,Mt[t]);t.startsWith("origin")?(o=!0,a[t]=e):n[t]=e}}if(e.transform||(r||s?n.transform=function(t,e,s){let n="",i=!0;for(let a=0;a<Me;a++){const r=Yt[a],o=t[r];if(void 0===o)continue;let h=!0;if("number"==typeof o)h=o===(r.startsWith("scale")?1:0);else{const t=parseFloat(o);h=r.startsWith("scale")?1===t:0===t}if(!h||s){const t=Se(o,Mt[r]);h||(i=!1,n+=`${Ve[r]||r}(${t}) `),s&&(e[r]=t)}}const a=t.pathRotation;return a&&(i=!1,n+=`rotate(${Se(a,Mt.pathRotation)}) `),n=n.trim(),s?n=s(e,i?"":n):i&&(n="none"),n}(e,t.transform,s):n.transform&&(n.transform="none")),o){const{originX:t="50%",originY:e="50%",originZ:s=0}=a;n.transformOrigin=`${t} ${e} ${s}`}}const Ce={offset:"stroke-dashoffset",array:"stroke-dasharray"},xe={offset:"strokeDashoffset",array:"strokeDasharray"};const Ae=["transform","opacity","offsetDistance","offsetPath","offsetRotate","offsetAnchor"];function ke(t,{attrX:e,attrY:s,attrScale:n,pathLength:i,pathSpacing:a=1,pathOffset:r=0,...o},h,l,u){if(Te(t,o,l),h)return void(t.style.viewBox&&(t.attrs.viewBox=t.style.viewBox));t.attrs=t.style,t.style={};const{attrs:c,style:d}=t;for(const t of Ae)void 0!==c[t]&&(d[t]=c[t],delete c[t]);(d.transform||c.transformOrigin)&&(d.transformOrigin=c.transformOrigin??"50% 50%",delete c.transformOrigin),d.transform&&(d.transformBox=u?.transformBox??"fill-box",delete c.transformBox),void 0!==e&&(c.x=e),void 0!==s&&(c.y=s),void 0!==n&&(c.scale=n),void 0!==i&&function(t,e,s=1,n=0,i=!0){t.pathLength=1;const a=i?Ce:xe;t[a.offset]=""+-n,t[a.array]=`${e} ${s}`}(c,i,a,r,!1)}const{schedule:Ee}=b(queueMicrotask,!1),Re=()=>({x:{translate:0,scale:1,origin:0,originPoint:0},y:{translate:0,scale:1,origin:0,originPoint:0}}),Fe=()=>({x:{min:0,max:0},y:{min:0,max:0}}),Pe=new WeakMap;function Be(t){return null!==t&&"object"==typeof t&&"function"==typeof t.start}function Ie(t){return"string"==typeof t||Array.isArray(t)}const Ne=["animate","whileInView","whileFocus","whileHover","whileTap","whileDrag","exit"],Oe=["initial",...Ne];function $e(t){if(Be(t.animate))return!0;for(let e=0;e<Oe.length;e++)if(Ie(t[Oe[e]]))return!0;return!1}function Le(t){return Boolean($e(t)||t.variants)}const Ye={current:null},We={current:!1},Xe="undefined"!=typeof window;const je=["AnimationStart","AnimationComplete","Update","BeforeLayoutMeasure","LayoutMeasure","LayoutAnimationStart","LayoutAnimationComplete"];let _e={};function Ue(t){_e=t}function ze(){return _e}class Ke{scrapeMotionValuesFromProps(t,e,s){return{}}constructor({parent:t,props:e,presenceContext:s,reducedMotionConfig:n,skipAnimations:i,blockInitialAnimation:a,visualState:r},o={}){this.current=null,this.children=new Set,this.isVariantNode=!1,this.isControllingVariants=!1,this.shouldReduceMotion=null,this.shouldSkipAnimations=!1,this.values=new Map,this.KeyframeResolver=te,this.features={},this.valueSubscriptions=new Map,this.prevMotionValues={},this.hasBeenMounted=!1,this.events={},this.propEventSubscriptions={},this.notifyUpdate=()=>this.notify("Update",this.latestValues),this.render=()=>{this.current&&(this.triggerBuild(),this.renderInstance(this.current,this.renderState,this.props.style,this.projection))},this.renderScheduledAt=0,this.scheduleRender=()=>{const t=x.now();this.renderScheduledAt<t&&(this.renderScheduledAt=t,w.render(this.render,!1,!0))};const{latestValues:h,renderState:l}=r;this.latestValues=h,this.baseTarget={...h},this.initialValues=e.initial?{...h}:{},this.renderState=l,this.parent=t,this.props=e,this.presenceContext=s,this.depth=t?t.depth+1:0,this.reducedMotionConfig=n,this.skipAnimationsConfig=i,this.options=o,this.blockInitialAnimation=Boolean(a),this.isControllingVariants=$e(e),this.isVariantNode=Le(e),this.isVariantNode&&(this.variantChildren=new Set),this.manuallyAnimateOnMount=Boolean(t&&t.current);const{willChange:u,...c}=this.scrapeMotionValuesFromProps(e,{},this);for(const t in c){const e=c[t];void 0!==h[t]&&ve(e)&&e.set(h[t])}}mount(t){if(this.hasBeenMounted)for(const t in this.initialValues)this.values.get(t)?.jump(this.initialValues[t]),this.latestValues[t]=this.initialValues[t];this.current=t,Pe.set(t,this),this.projection&&!this.projection.instance&&this.projection.mount(t),this.parent&&this.isVariantNode&&!this.isControllingVariants&&(this.removeFromVariantTree=this.parent.addVariantChild(this)),this.values.forEach((t,e)=>this.bindToMotionValue(e,t)),"never"===this.reducedMotionConfig?this.shouldReduceMotion=!1:"always"===this.reducedMotionConfig?this.shouldReduceMotion=!0:(We.current||function(){if(We.current=!0,Xe)if(window.matchMedia){const t=window.matchMedia("(prefers-reduced-motion)"),e=()=>Ye.current=t.matches;t.addEventListener("change",e),e()}else Ye.current=!1}(),this.shouldReduceMotion=Ye.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,this.parent?.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){this.projection&&this.projection.unmount(),S(this.notifyUpdate),S(this.render),this.valueSubscriptions.forEach(t=>t()),this.valueSubscriptions.clear(),this.removeFromVariantTree&&this.removeFromVariantTree(),this.parent?.removeChild(this);for(const t in this.events)this.events[t].clear();for(const t in this.features){const e=this.features[t];e&&(e.unmount(),e.isMounted=!1)}this.current=null}addChild(t){this.children.add(t),this.enteringChildren??(this.enteringChildren=new Set),this.enteringChildren.add(t)}removeChild(t){this.children.delete(t),this.enteringChildren&&this.enteringChildren.delete(t)}bindToMotionValue(t,e){if(this.valueSubscriptions.has(t)&&this.valueSubscriptions.get(t)(),e.accelerate&&de.has(t)&&this.current instanceof HTMLElement){const{factory:s,keyframes:n,times:i,ease:a,duration:r}=e.accelerate,o=new ce({element:this.current,name:t,keyframes:n,times:i,ease:a,duration:p(r)}),h=s(o);return void this.valueSubscriptions.set(t,()=>{h(),o.cancel()})}const s=Wt.has(t);s&&this.onBindTransform&&this.onBindTransform();const n=e.on("change",e=>{this.latestValues[t]=e,this.props.onUpdate&&w.preRender(this.notifyUpdate),s&&this.projection&&(this.projection.isTransformDirty=!0),this.scheduleRender()});let i;"undefined"!=typeof window&&window.MotionCheckAppearSync&&(i=window.MotionCheckAppearSync(this,t,e)),this.valueSubscriptions.set(t,()=>{n(),i&&i()})}sortNodePosition(t){return this.current&&this.sortInstanceNodePosition&&this.type===t.type?this.sortInstanceNodePosition(this.current,t.current):0}updateFeatures(){let t="animation";for(t in _e){const e=_e[t];if(!e)continue;const{isEnabled:s,Feature:n}=e;if(!this.features[t]&&n&&s(this.props)&&(this.features[t]=new n(this)),this.features[t]){const e=this.features[t];e.isMounted?e.update():(e.mount(),e.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):{x:{min:0,max:0},y:{min:0,max:0}}}getStaticValue(t){return this.latestValues[t]}setStaticValue(t,e){this.latestValues[t]=e}update(t,e){(t.transformTemplate||this.props.transformTemplate)&&this.scheduleRender(),this.prevProps=this.props,this.props=t,this.prevPresenceContext=this.presenceContext,this.presenceContext=e;for(let e=0;e<je.length;e++){const s=je[e];this.propEventSubscriptions[s]&&(this.propEventSubscriptions[s](),delete this.propEventSubscriptions[s]);const n=t["on"+s];n&&(this.propEventSubscriptions[s]=this.on(s,n))}this.prevMotionValues=function(t,e,s){for(const n in e){const i=e[n],a=s[n];if(ve(i))t.addValue(n,i);else if(ve(a))t.addValue(n,fe(i,{owner:t}));else if(a!==i)if(t.hasValue(n)){const e=t.getValue(n);!0===e.liveStyle?e.jump(i):e.hasAnimated||e.set(i)}else{const e=t.getStaticValue(n);t.addValue(n,fe(void 0!==e?e:i,{owner:t}))}}for(const n in s)void 0===e[n]&&t.removeValue(n);return e}(this,this.scrapeMotionValuesFromProps(t,this.prevProps||{},this),this.prevMotionValues),this.handleChildMotionValue&&this.handleChildMotionValue()}getProps(){return this.props}getVariant(t){return this.props.variants?this.props.variants[t]:void 0}getDefaultTransition(){return this.props.transition}getTransformPagePoint(){return this.props.transformPagePoint}getClosestVariantNode(){return this.isVariantNode?this:this.parent?this.parent.getClosestVariantNode():void 0}addVariantChild(t){const e=this.getClosestVariantNode();if(e)return e.variantChildren&&e.variantChildren.add(t),()=>e.variantChildren.delete(t)}addValue(t,e){const s=this.values.get(t);e!==s&&(s&&this.removeValue(t),this.bindToMotionValue(t,e),this.values.set(t,e),this.latestValues[t]=e.get())}removeValue(t){this.values.delete(t);const e=this.valueSubscriptions.get(t);e&&(e(),this.valueSubscriptions.delete(t)),delete this.latestValues[t],this.removeValueFromRenderState(t,this.renderState)}hasValue(t){return this.values.has(t)}getValue(t,e){if(this.props.values&&this.props.values[t])return this.props.values[t];let s=this.values.get(t);return void 0===s&&void 0!==e&&(s=fe(null===e?void 0:e,{owner:this}),this.addValue(t,s)),s}readValue(t,e){let s=void 0===this.latestValues[t]&&this.current?this.getBaseTargetFromProps(this.props,t)??this.readValueFromInstance(this.current,t,this.options):this.latestValues[t];return null!=s&&("string"==typeof s&&(h(s)||l(s))?s=parseFloat(s):"number"!=typeof s&&!ht.test(s)&&ht.test(e)&&(s=At(t,e)),this.setBaseTarget(t,ve(s)?s.get():s)),ve(s)?s.get():s}setBaseTarget(t,e){this.baseTarget[t]=e}getBaseTarget(t){const{initial:e}=this.props;let s;if("string"==typeof e||"object"==typeof e){const n=ge(this.props,e,this.presenceContext?.custom);n&&(s=n[t])}if(e&&void 0!==s)return s;const n=this.getBaseTargetFromProps(this.props,t);return void 0===n||ve(n)?void 0!==this.initialValues[t]&&void 0===s?void 0:this.baseTarget[t]:n}on(t,e){return this.events[t]||(this.events[t]=new d),this.events[t].add(e)}notify(t,...e){this.events[t]&&this.events[t].notify(...e)}scheduleRenderMicrotask(){Ee.render(this.render)}}function Ze(t,e){return e.max===e.min?0:t/(e.max-e.min)*100}const De={correct:(t,e)=>{if(!e.target)return t;if("string"==typeof t){if(!Z.test(t))return t;t=parseFloat(t)}return`${Ze(t,e.target.x)}% ${Ze(t,e.target.y)}%`}},qe={correct:(t,{treeScale:e,projectionDelta:s})=>{const n=t,i=ht.parse(t);if(i.length>5)return n;const a=ht.createTransformer(t),r="number"!=typeof i[0]?1:0,o=s.x.scale*e.x,h=s.y.scale*e.y;i[0+r]/=o,i[1+r]/=h;const l=lt(o,h,.5);return"number"==typeof i[2+r]&&(i[2+r]/=l),"number"==typeof i[3+r]&&(i[3+r]/=l),a(i)}},He={borderRadius:{...De,applyTo:[...we]},borderTopLeftRadius:De,borderTopRightRadius:De,borderBottomLeftRadius:De,borderBottomRightRadius:De,boxShadow:qe};function Ge(t,{layout:e,layoutId:s}){return Wt.has(t)||t.startsWith("origin")||(e||void 0!==s)&&(!!He[t]||"opacity"===t)}function Je(t,e,s){const n=t.style,i=e?.style,a={};if(!n)return a;for(const e in n)(ve(n[e])||i&&ve(i[e])||Ge(e,t)||void 0!==s?.getValue(e)?.liveStyle)&&(a[e]=n[e]);return a}const Qe=t=>"string"==typeof t&&"svg"===t.toLowerCase();function ts(t,e,s){const n=Je(t,e,s);for(const s in t)if(ve(t[s])||ve(e[s])){n[-1!==Yt.indexOf(s)?"attr"+s.charAt(0).toUpperCase()+s.substring(1):s]=t[s]}return n}function es(t){return ve(t)?t.get():t}const ss=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function ns(t){return"string"==typeof t&&!t.includes("-")&&!!(ss.indexOf(t)>-1||/[A-Z]/u.test(t))}const is=t(null),as=t({});function rs(t){return t&&"object"==typeof t&&Object.prototype.hasOwnProperty.call(t,"current")}export{Qt as $,F as A,J as B,ht as C,at as D,A as E,V as F,x as G,S as H,w as I,f as J,n as K,v as L,ut as M,p as N,o as O,is as P,m as Q,ft as R,as as S,dt as T,ce as U,ee as V,gt as W,ue as X,de as Y,u as Z,te as _,Ie as a,Wt as a0,h as a1,Yt as a2,fe as a3,I as a4,Z as a5,K as a6,z as a7,q as a8,D as a9,l as aa,it as ab,At as ac,B as ad,Kt as ae,Xt as af,Ke as ag,Nt as ah,$t as ai,E as aj,ye as ak,Fe as al,Ae as am,Ct as an,Oe as ao,Ne as ap,we as aq,e as ar,s as as,d as at,M as au,Ee as av,Re as aw,mt as ax,He as ay,ve as b,Ge as c,Te as d,ke as e,Qe as f,ns as g,Le as h,$e as i,Be as j,ge as k,ts as l,ze as m,Ue as n,be as o,rs as p,c as q,es as r,Je as s,g as t,r as u,lt as v,j as w,G as x,_ as y,a as z};