提取 calcOfficialEquiv 为公共工具函数,7 个 Home 模板和 Packages 页面共用,自动选择折扣比例最大的模型展示等价额度。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 lines
26 KiB
JavaScript
2 lines
26 KiB
JavaScript
import{r as S,j as Qt}from"./index-ClhW4pXr.js";function kt(t){const e=S.useRef(null);return e.current===null&&(e.current=t()),e.current}const Yt=typeof window<"u",te=Yt?S.useLayoutEffect:S.useEffect;function ee(t,e){t.indexOf(e)===-1&&t.push(e)}function ne(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}const U=(t,e,n)=>n>e?e:n<t?t:n;let Ct=()=>{};const ft={},Y=t=>t,se=(t,e)=>n=>e(t(n)),ht=(...t)=>t.reduce(se),Vt=(t,e,n)=>{const r=e-t;return r===0?1:(n-t)/r};class re{constructor(){this.subscriptions=[]}add(e){return ee(this.subscriptions,e),()=>ne(this.subscriptions,e)}notify(e,n,r){const s=this.subscriptions.length;if(s)if(s===1)this.subscriptions[0](e,n,r);else for(let i=0;i<s;i++){const o=this.subscriptions[i];o&&o(e,n,r)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}}const L=t=>t*1e3,P=t=>t/1e3;function It(t,e){return e?t*(1e3/e):0}const Et=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t,ie=1e-7,oe=12;function ae(t,e,n,r,s){let i,o,a=0;do o=e+(n-e)/2,i=Et(o,r,s)-t,i>0?n=o:e=o;while(Math.abs(i)>ie&&++a<oe);return o}function j(t,e,n,r){if(t===e&&n===r)return Y;const s=i=>ae(i,0,1,t,n);return i=>i===0||i===1?i:Et(s(i),e,r)}const Rt=t=>e=>e<=.5?t(2*e)/2:(2-t(2*(1-e)))/2,Pt=t=>e=>1-t(1-e),Nt=j(.33,1.53,.69,.99),dt=Pt(Nt),ce=Rt(dt),ue=t=>t>=1?1:(t*=2)<1?.5*dt(t):.5*(2-Math.pow(2,-10*(t-1))),pt=t=>1-Math.sin(Math.acos(t)),le=Pt(pt),fe=Rt(pt),he=j(.42,0,1,1),de=j(0,0,.58,1),Ot=j(.42,0,.58,1),pe=t=>Array.isArray(t)&&typeof t[0]!="number",me=t=>Array.isArray(t)&&typeof t[0]=="number",ge={linear:Y,easeIn:he,easeInOut:Ot,easeOut:de,circIn:pt,circInOut:fe,circOut:le,backIn:dt,backInOut:ce,backOut:Nt,anticipate:ue},ye=t=>typeof t=="string",Tt=t=>{if(me(t)){Ct(t.length===4);const[e,n,r,s]=t;return j(e,n,r,s)}else if(ye(t))return ge[t];return t},z=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function be(t,e){let n=new Set,r=new Set,s=!1,i=!1;const o=new WeakSet;let a={delta:0,timestamp:0,isProcessing:!1};function u(c){o.has(c)&&(l.schedule(c),t()),c(a)}const l={schedule:(c,f=!1,d=!1)=>{const x=d&&s?n:r;return f&&o.add(c),x.add(c),c},cancel:c=>{r.delete(c),o.delete(c)},process:c=>{if(a=c,s){i=!0;return}s=!0;const f=n;n=r,r=f,n.forEach(u),n.clear(),s=!1,i&&(i=!1,l.process(c))}};return l}const Te=40;function ve(t,e){let n=!1,r=!0;const s={delta:0,timestamp:0,isProcessing:!1},i=()=>n=!0,o=z.reduce((T,g)=>(T[g]=be(i),T),{}),{setup:a,read:u,resolveKeyframes:l,preUpdate:c,update:f,preRender:d,render:M,postRender:x}=o,m=()=>{const T=ft.useManualTiming,g=T?s.timestamp:performance.now();n=!1,T||(s.delta=r?1e3/60:Math.max(Math.min(g-s.timestamp,Te),1)),s.timestamp=g,s.isProcessing=!0,a.process(s),u.process(s),l.process(s),c.process(s),f.process(s),d.process(s),M.process(s),x.process(s),s.isProcessing=!1,n&&e&&(r=!1,t(m))},v=()=>{n=!0,r=!0,s.isProcessing||t(m)};return{schedule:z.reduce((T,g)=>{const y=o[g];return T[g]=(D,C=!1,b=!1)=>(n||v(),y.schedule(D,C,b)),T},{}),cancel:T=>{for(let g=0;g<z.length;g++)o[z[g]].cancel(T)},state:s,steps:o}}const{schedule:tt,cancel:Ut,state:J}=ve(typeof requestAnimationFrame<"u"?requestAnimationFrame:Y,!0);let Z;function xe(){Z=void 0}const V={now:()=>(Z===void 0&&V.set(J.isProcessing||ft.useManualTiming?J.timestamp:performance.now()),Z),set:t=>{Z=t,queueMicrotask(xe)}},Me=t=>e=>typeof e=="string"&&e.startsWith(t),Ae=Me("var(--"),De=t=>Ae(t)?Fe.test(t.split("/*")[0].trim()):!1,Fe=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu,Kt={test:t=>typeof t=="number",parse:parseFloat,transform:t=>t},Gt={...Kt,transform:t=>U(0,1,t)},q=t=>Math.round(t*1e5)/1e5,Lt=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function Se(t){return t==null}const we=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,mt=(t,e)=>n=>!!(typeof n=="string"&&we.test(n)&&n.startsWith(t)||e&&!Se(n)&&Object.prototype.hasOwnProperty.call(n,e)),qt=(t,e,n)=>r=>{if(typeof r!="string")return r;const[s,i,o,a]=r.match(Lt);return{[t]:parseFloat(s),[e]:parseFloat(i),[n]:parseFloat(o),alpha:a!==void 0?parseFloat(a):1}},ke=t=>U(0,255,t),nt={...Kt,transform:t=>Math.round(ke(t))},O={test:mt("rgb","red"),parse:qt("red","green","blue"),transform:({red:t,green:e,blue:n,alpha:r=1})=>"rgba("+nt.transform(t)+", "+nt.transform(e)+", "+nt.transform(n)+", "+q(Gt.transform(r))+")"};function Ce(t){let e="",n="",r="",s="";return t.length>5?(e=t.substring(1,3),n=t.substring(3,5),r=t.substring(5,7),s=t.substring(7,9)):(e=t.substring(1,2),n=t.substring(2,3),r=t.substring(3,4),s=t.substring(4,5),e+=e,n+=n,r+=r,s+=s),{red:parseInt(e,16),green:parseInt(n,16),blue:parseInt(r,16),alpha:s?parseInt(s,16)/255:1}}const at={test:mt("#"),parse:Ce,transform:O.transform},Ve=t=>({test:e=>typeof e=="string"&&e.endsWith(t)&&e.split(" ").length===1,parse:parseFloat,transform:e=>`${e}${t}`}),vt=Ve("%"),G={test:mt("hsl","hue"),parse:qt("hue","saturation","lightness"),transform:({hue:t,saturation:e,lightness:n,alpha:r=1})=>"hsla("+Math.round(t)+", "+vt.transform(q(e))+", "+vt.transform(q(n))+", "+q(Gt.transform(r))+")"},I={test:t=>O.test(t)||at.test(t)||G.test(t),parse:t=>O.test(t)?O.parse(t):G.test(t)?G.parse(t):at.parse(t),transform:t=>typeof t=="string"?t:t.hasOwnProperty("red")?O.transform(t):G.transform(t),getAnimatableNone:t=>{const e=I.parse(t);return e.alpha=0,I.transform(e)}},Ie=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;function Ee(t){var e,n;return isNaN(t)&&typeof t=="string"&&(((e=t.match(Lt))==null?void 0:e.length)||0)+(((n=t.match(Ie))==null?void 0:n.length)||0)>0}const Wt="number",Bt="color",Re="var",Pe="var(",xt="${}",Ne=/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 _(t){const e=t.toString(),n=[],r={color:[],number:[],var:[]},s=[];let i=0;const a=e.replace(Ne,u=>(I.test(u)?(r.color.push(i),s.push(Bt),n.push(I.parse(u))):u.startsWith(Pe)?(r.var.push(i),s.push(Re),n.push(u)):(r.number.push(i),s.push(Wt),n.push(parseFloat(u))),++i,xt)).split(xt);return{values:n,split:a,indexes:r,types:s}}function Oe(t){return _(t).values}function _t({split:t,types:e}){const n=t.length;return r=>{let s="";for(let i=0;i<n;i++)if(s+=t[i],r[i]!==void 0){const o=e[i];o===Wt?s+=q(r[i]):o===Bt?s+=I.transform(r[i]):s+=r[i]}return s}}function Ue(t){return _t(_(t))}const Ke=t=>typeof t=="number"?0:I.test(t)?I.getAnimatableNone(t):t,Ge=(t,e)=>typeof t=="number"?e!=null&&e.trim().endsWith("/")?t:0:Ke(t);function Le(t){const e=_(t);return _t(e)(e.values.map((r,s)=>Ge(r,e.split[s])))}const qe={test:Ee,parse:Oe,createTransformer:Ue,getAnimatableNone:Le};function st(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+(e-t)*6*n:n<1/2?e:n<2/3?t+(e-t)*(2/3-n)*6:t}function We({hue:t,saturation:e,lightness:n,alpha:r}){t/=360,e/=100,n/=100;let s=0,i=0,o=0;if(!e)s=i=o=n;else{const a=n<.5?n*(1+e):n+e-n*e,u=2*n-a;s=st(u,a,t+1/3),i=st(u,a,t),o=st(u,a,t-1/3)}return{red:Math.round(s*255),green:Math.round(i*255),blue:Math.round(o*255),alpha:r}}function H(t,e){return n=>n>0?e:t}const et=(t,e,n)=>t+(e-t)*n,rt=(t,e,n)=>{const r=t*t,s=n*(e*e-r)+r;return s<0?0:Math.sqrt(s)},Be=[at,O,G],_e=t=>Be.find(e=>e.test(t));function Mt(t){const e=_e(t);if(!e)return!1;let n=e.parse(t);return e===G&&(n=We(n)),n}const At=(t,e)=>{const n=Mt(t),r=Mt(e);if(!n||!r)return H(t,e);const s={...n};return i=>(s.red=rt(n.red,r.red,i),s.green=rt(n.green,r.green,i),s.blue=rt(n.blue,r.blue,i),s.alpha=et(n.alpha,r.alpha,i),O.transform(s))},ct=new Set(["none","hidden"]);function je(t,e){return ct.has(t)?n=>n<=0?t:e:n=>n>=1?e:t}function $e(t,e){return n=>et(t,e,n)}function gt(t){return typeof t=="number"?$e:typeof t=="string"?De(t)?H:I.test(t)?At:Je:Array.isArray(t)?jt:typeof t=="object"?I.test(t)?At:ze:H}function jt(t,e){const n=[...t],r=n.length,s=t.map((i,o)=>gt(i)(i,e[o]));return i=>{for(let o=0;o<r;o++)n[o]=s[o](i);return n}}function ze(t,e){const n={...t,...e},r={};for(const s in n)t[s]!==void 0&&e[s]!==void 0&&(r[s]=gt(t[s])(t[s],e[s]));return s=>{for(const i in r)n[i]=r[i](s);return n}}function Ze(t,e){const n=[],r={color:0,var:0,number:0};for(let s=0;s<e.values.length;s++){const i=e.types[s],o=t.indexes[i][r[i]],a=t.values[o]??0;n[s]=a,r[i]++}return n}const Je=(t,e)=>{const n=qe.createTransformer(e),r=_(t),s=_(e);return r.indexes.var.length===s.indexes.var.length&&r.indexes.color.length===s.indexes.color.length&&r.indexes.number.length>=s.indexes.number.length?ct.has(t)&&!s.values.length||ct.has(e)&&!r.values.length?je(t,e):ht(jt(Ze(r,s),s.values),n):H(t,e)};function $t(t,e,n){return typeof t=="number"&&typeof e=="number"&&typeof n=="number"?et(t,e,n):gt(t)(t,e)}const He=t=>{const e=({timestamp:n})=>t(n);return{start:(n=!0)=>tt.update(e,n),stop:()=>Ut(e),now:()=>J.isProcessing?J.timestamp:V.now()}},Xe=(t,e,n=10)=>{let r="";const s=Math.max(Math.round(e/n),2);for(let i=0;i<s;i++)r+=Math.round(t(i/(s-1))*1e4)/1e4+", ";return`linear(${r.substring(0,r.length-2)})`},X=2e4;function yt(t){let e=0;const n=50;let r=t.next(e);for(;!r.done&&e<X;)e+=n,r=t.next(e);return e>=X?1/0:e}function Qe(t,e=100,n){const r=n({...t,keyframes:[0,e]}),s=Math.min(yt(r),X);return{type:"keyframes",ease:i=>r.next(s*i).value/e,duration:P(s)}}const A={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1};function ut(t,e){return t*Math.sqrt(1-e*e)}const Ye=12;function tn(t,e,n){let r=n;for(let s=1;s<Ye;s++)r=r-t(r)/e(r);return r}const it=.001;function en({duration:t=A.duration,bounce:e=A.bounce,velocity:n=A.velocity,mass:r=A.mass}){let s,i,o=1-e;o=U(A.minDamping,A.maxDamping,o),t=U(A.minDuration,A.maxDuration,P(t)),o<1?(s=l=>{const c=l*o,f=c*t,d=c-n,M=ut(l,o),x=Math.exp(-f);return it-d/M*x},i=l=>{const f=l*o*t,d=f*n+n,M=Math.pow(o,2)*Math.pow(l,2)*t,x=Math.exp(-f),m=ut(Math.pow(l,2),o);return(-s(l)+it>0?-1:1)*((d-M)*x)/m}):(s=l=>{const c=Math.exp(-l*t),f=(l-n)*t+1;return-it+c*f},i=l=>{const c=Math.exp(-l*t),f=(n-l)*(t*t);return c*f});const a=5/t,u=tn(s,i,a);if(t=L(t),isNaN(u))return{stiffness:A.stiffness,damping:A.damping,duration:t};{const l=Math.pow(u,2)*r;return{stiffness:l,damping:o*2*Math.sqrt(r*l),duration:t}}}const nn=["duration","bounce"],sn=["stiffness","damping","mass"];function Dt(t,e){return e.some(n=>t[n]!==void 0)}function rn(t){let e={velocity:A.velocity,stiffness:A.stiffness,damping:A.damping,mass:A.mass,isResolvedFromDuration:!1,...t};if(!Dt(t,sn)&&Dt(t,nn))if(e.velocity=0,t.visualDuration){const n=t.visualDuration,r=2*Math.PI/(n*1.2),s=r*r,i=2*U(.05,1,1-(t.bounce||0))*Math.sqrt(s);e={...e,mass:A.mass,stiffness:s,damping:i}}else{const n=en({...t,velocity:0});e={...e,...n,mass:A.mass},e.isResolvedFromDuration=!0}return e}function Q(t=A.visualDuration,e=A.bounce){const n=typeof t!="object"?{visualDuration:t,keyframes:[0,1],bounce:e}:t;let{restSpeed:r,restDelta:s}=n;const i=n.keyframes[0],o=n.keyframes[n.keyframes.length-1],a={done:!1,value:i},{stiffness:u,damping:l,mass:c,duration:f,velocity:d,isResolvedFromDuration:M}=rn({...n,velocity:-P(n.velocity||0)}),x=d||0,m=l/(2*Math.sqrt(u*c)),v=o-i,p=P(Math.sqrt(u/c)),w=Math.abs(v)<5;r||(r=w?A.restSpeed.granular:A.restSpeed.default),s||(s=w?A.restDelta.granular:A.restDelta.default);let T,g,y,D,C,b;if(m<1)y=ut(p,m),D=(x+m*p*v)/y,T=h=>{const F=Math.exp(-m*p*h);return o-F*(D*Math.sin(y*h)+v*Math.cos(y*h))},C=m*p*D+v*y,b=m*p*v-D*y,g=h=>Math.exp(-m*p*h)*(C*Math.sin(y*h)+b*Math.cos(y*h));else if(m===1){T=F=>o-Math.exp(-p*F)*(v+(x+p*v)*F);const h=x+p*v;g=F=>Math.exp(-p*F)*(p*h*F-x)}else{const h=p*Math.sqrt(m*m-1);T=R=>{const K=Math.exp(-m*p*R),N=Math.min(h*R,300);return o-K*((x+m*p*v)*Math.sinh(N)+h*v*Math.cosh(N))/h};const F=(x+m*p*v)/h,E=m*p*F-v*h,$=m*p*v-F*h;g=R=>{const K=Math.exp(-m*p*R),N=Math.min(h*R,300);return K*(E*Math.sinh(N)+$*Math.cosh(N))}}const k={calculatedDuration:M&&f||null,velocity:h=>L(g(h)),next:h=>{if(!M&&m<1){const E=Math.exp(-m*p*h),$=Math.sin(y*h),R=Math.cos(y*h),K=o-E*(D*$+v*R),N=L(E*(C*$+b*R));return a.done=Math.abs(N)<=r&&Math.abs(o-K)<=s,a.value=a.done?o:K,a}const F=T(h);if(M)a.done=h>=f;else{const E=L(g(h));a.done=Math.abs(E)<=r&&Math.abs(o-F)<=s}return a.value=a.done?o:F,a},toString:()=>{const h=Math.min(yt(k),X),F=Xe(E=>k.next(h*E).value,h,30);return h+"ms "+F},toTransition:()=>{}};return k}Q.applyToOptions=t=>{const e=Qe(t,100,Q);return t.ease=e.ease,t.duration=L(e.duration),t.type="keyframes",t};const on=5;function zt(t,e,n){const r=Math.max(e-on,0);return It(n-t(r),e-r)}function lt({keyframes:t,velocity:e=0,power:n=.8,timeConstant:r=325,bounceDamping:s=10,bounceStiffness:i=500,modifyTarget:o,min:a,max:u,restDelta:l=.5,restSpeed:c}){const f=t[0],d={done:!1,value:f},M=b=>a!==void 0&&b<a||u!==void 0&&b>u,x=b=>a===void 0?u:u===void 0||Math.abs(a-b)<Math.abs(u-b)?a:u;let m=n*e;const v=f+m,p=o===void 0?v:o(v);p!==v&&(m=p-f);const w=b=>-m*Math.exp(-b/r),T=b=>p+w(b),g=b=>{const k=w(b),h=T(b);d.done=Math.abs(k)<=l,d.value=d.done?p:h};let y,D;const C=b=>{M(d.value)&&(y=b,D=Q({keyframes:[d.value,x(d.value)],velocity:zt(T,b,d.value),damping:s,stiffness:i,restDelta:l,restSpeed:c}))};return C(0),{calculatedDuration:null,next:b=>{let k=!1;return!D&&y===void 0&&(k=!0,g(b),C(b)),y!==void 0&&b>=y?D.next(b-y):(!k&&g(b),d)}}}function an(t,e,n){const r=[],s=n||ft.mix||$t,i=t.length-1;for(let o=0;o<i;o++){let a=s(t[o],t[o+1]);if(e){const u=Array.isArray(e)?e[o]||Y:e;a=ht(u,a)}r.push(a)}return r}function Zt(t,e,{clamp:n=!0,ease:r,mixer:s}={}){const i=t.length;if(Ct(i===e.length),i===1)return()=>e[0];if(i===2&&e[0]===e[1])return()=>e[1];const o=t[0]===t[1];t[0]>t[i-1]&&(t=[...t].reverse(),e=[...e].reverse());const a=an(e,r,s),u=a.length,l=c=>{if(o&&c<t[0])return e[0];let f=0;if(u>1)for(;f<t.length-2&&!(c<t[f+1]);f++);const d=Vt(t[f],t[f+1],c);return a[f](d)};return n?c=>l(U(t[0],t[i-1],c)):l}function cn(t,e){const n=t[t.length-1];for(let r=1;r<=e;r++){const s=Vt(0,e,r);t.push(et(n,1,s))}}function un(t){const e=[0];return cn(e,t.length-1),e}function ln(t,e){return t.map(n=>n*e)}function fn(t,e){return t.map(()=>e||Ot).splice(0,t.length-1)}function W({duration:t=300,keyframes:e,times:n,ease:r="easeInOut"}){const s=pe(r)?r.map(Tt):Tt(r),i={done:!1,value:e[0]},o=ln(n&&n.length===e.length?n:un(e),t),a=Zt(o,e,{ease:Array.isArray(s)?s:fn(e,s)});return{calculatedDuration:t,next:u=>(i.value=a(u),i.done=u>=t,i)}}const hn=t=>t!==null;function dn(t,{repeat:e,repeatType:n="loop"},r,s=1){const i=t.filter(hn),a=s<0||e&&n!=="loop"&&e%2===1?0:i.length-1;return!a||r===void 0?i[a]:r}const pn={decay:lt,inertia:lt,tween:W,keyframes:W,spring:Q};function mn(t){typeof t.type=="string"&&(t.type=pn[t.type])}class gn{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(e=>{this.resolve=e})}notifyFinished(){this.resolve()}then(e,n){return this.finished.then(e,n)}}const yn=t=>t/100;class bn extends gn{constructor(e){super(),this.state="idle",this.startTime=null,this.isStopped=!1,this.currentTime=0,this.holdTime=null,this.playbackSpeed=1,this.delayState={done:!1,value:void 0},this.stop=()=>{var r,s;const{motionValue:n}=this.options;n&&n.updatedAt!==V.now()&&this.tick(V.now()),this.isStopped=!0,this.state!=="idle"&&(this.teardown(),(s=(r=this.options).onStop)==null||s.call(r))},this.options=e,this.initAnimation(),this.play(),e.autoplay===!1&&this.pause()}initAnimation(){const{options:e}=this;mn(e);const{type:n=W,repeat:r=0,repeatDelay:s=0,repeatType:i,velocity:o=0}=e;let{keyframes:a}=e;const u=n||W;u!==W&&typeof a[0]!="number"&&(this.mixKeyframes=ht(yn,$t(a[0],a[1])),a=[0,100]);const l=u({...e,keyframes:a});i==="mirror"&&(this.mirroredGenerator=u({...e,keyframes:[...a].reverse(),velocity:-o})),l.calculatedDuration===null&&(l.calculatedDuration=yt(l));const{calculatedDuration:c}=l;this.calculatedDuration=c,this.resolvedDuration=c+s,this.totalDuration=this.resolvedDuration*(r+1)-s,this.generator=l}updateTime(e){const n=Math.round(e-this.startTime)*this.playbackSpeed;this.holdTime!==null?this.currentTime=this.holdTime:this.currentTime=n}tick(e,n=!1){const{generator:r,totalDuration:s,mixKeyframes:i,mirroredGenerator:o,resolvedDuration:a,calculatedDuration:u}=this;if(this.startTime===null)return r.next(0);const{delay:l=0,keyframes:c,repeat:f,repeatType:d,repeatDelay:M,type:x,onUpdate:m,finalKeyframe:v}=this.options;this.speed>0?this.startTime=Math.min(this.startTime,e):this.speed<0&&(this.startTime=Math.min(e-s/this.speed,this.startTime)),n?this.currentTime=e:this.updateTime(e);const p=this.currentTime-l*(this.playbackSpeed>=0?1:-1),w=this.playbackSpeed>=0?p<0:p>s;this.currentTime=Math.max(p,0),this.state==="finished"&&this.holdTime===null&&(this.currentTime=s);let T=this.currentTime,g=r;if(f){const b=Math.min(this.currentTime,s)/a;let k=Math.floor(b),h=b%1;!h&&b>=1&&(h=1),h===1&&k--,k=Math.min(k,f+1),!!(k%2)&&(d==="reverse"?(h=1-h,M&&(h-=M/a)):d==="mirror"&&(g=o)),T=U(0,1,h)*a}let y;w?(this.delayState.value=c[0],y=this.delayState):y=g.next(T),i&&!w&&(y.value=i(y.value));let{done:D}=y;!w&&u!==null&&(D=this.playbackSpeed>=0?this.currentTime>=s:this.currentTime<=0);const C=this.holdTime===null&&(this.state==="finished"||this.state==="running"&&D);return C&&x!==lt&&(y.value=dn(c,this.options,v,this.speed)),m&&m(y.value),C&&this.finish(),y}then(e,n){return this.finished.then(e,n)}get duration(){return P(this.calculatedDuration)}get iterationDuration(){const{delay:e=0}=this.options||{};return this.duration+P(e)}get time(){return P(this.currentTime)}set time(e){e=L(e),this.currentTime=e,this.startTime===null||this.holdTime!==null||this.playbackSpeed===0?this.holdTime=e:this.driver&&(this.startTime=this.driver.now()-e/this.playbackSpeed),this.driver?this.driver.start(!1):(this.startTime=0,this.state="paused",this.holdTime=e,this.tick(e))}getGeneratorVelocity(){const e=this.currentTime;if(e<=0)return this.options.velocity||0;if(this.generator.velocity)return this.generator.velocity(e);const n=this.generator.next(e).value;return zt(r=>this.generator.next(r).value,e,n)}get speed(){return this.playbackSpeed}set speed(e){const n=this.playbackSpeed!==e;n&&this.driver&&this.updateTime(V.now()),this.playbackSpeed=e,n&&this.driver&&(this.time=P(this.currentTime))}play(){var s,i;if(this.isStopped)return;const{driver:e=He,startTime:n}=this.options;this.driver||(this.driver=e(o=>this.tick(o))),(i=(s=this.options).onPlay)==null||i.call(s);const r=this.driver.now();this.state==="finished"?(this.updateFinished(),this.startTime=r):this.holdTime!==null?this.startTime=r-this.holdTime:this.startTime||(this.startTime=n??r),this.state==="finished"&&this.speed<0&&(this.startTime+=this.calculatedDuration),this.holdTime=null,this.state="running",this.driver.start()}pause(){this.state="paused",this.updateTime(V.now()),this.holdTime=this.currentTime}complete(){this.state!=="running"&&this.play(),this.state="finished",this.holdTime=null}finish(){var e,n;this.notifyFinished(),this.teardown(),this.state="finished",(n=(e=this.options).onComplete)==null||n.call(e)}cancel(){var e,n;this.holdTime=null,this.startTime=0,this.tick(0),this.teardown(),(n=(e=this.options).onCancel)==null||n.call(e)}teardown(){this.state="idle",this.stopDriver(),this.startTime=this.holdTime=null}stopDriver(){this.driver&&(this.driver.stop(),this.driver=void 0)}sample(e){return this.startTime=0,this.tick(e,!0)}attachTimeline(e){var n;return this.options.allowFlatten&&(this.options.type="keyframes",this.options.ease="linear",this.initAnimation()),(n=this.driver)==null||n.stop(),e.observe(this)}}const Ft=30,Tn=t=>!isNaN(parseFloat(t)),B={current:void 0};class vn{constructor(e,n={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=r=>{var i;const s=V.now();if(this.updatedAt!==s&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(r),this.current!==this.prev&&((i=this.events.change)==null||i.notify(this.current),this.dependents))for(const o of this.dependents)o.dirty()},this.hasAnimated=!1,this.setCurrent(e),this.owner=n.owner}setCurrent(e){this.current=e,this.updatedAt=V.now(),this.canTrackVelocity===null&&e!==void 0&&(this.canTrackVelocity=Tn(this.current))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on("change",e)}on(e,n){this.events[e]||(this.events[e]=new re);const r=this.events[e].add(n);return e==="change"?()=>{r(),tt.read(()=>{this.events.change.getSize()||this.stop()})}:r}clearListeners(){for(const e in this.events)this.events[e].clear()}attach(e,n){this.passiveEffect=e,this.stopPassiveEffect=n}set(e){this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e)}setWithVelocity(e,n,r){this.set(n),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-r}jump(e,n=!0){this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,n&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){var e;(e=this.events.change)==null||e.notify(this.current)}addDependent(e){this.dependents||(this.dependents=new Set),this.dependents.add(e)}removeDependent(e){this.dependents&&this.dependents.delete(e)}get(){return B.current&&B.current.push(this),this.current}getPrevious(){return this.prev}getVelocity(){const e=V.now();if(!this.canTrackVelocity||this.prevFrameValue===void 0||e-this.updatedAt>Ft)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,Ft);return It(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(e){return this.stop(),new Promise(n=>{this.hasAnimated=!0,this.animation=e(n),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){var e,n;(e=this.dependents)==null||e.clear(),(n=this.events.destroy)==null||n.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function xn(t,e){return new vn(t,e)}const Jt=t=>!!(t&&t.getVelocity);function Mn(t,e,n){if(t==null)return[];if(t instanceof EventTarget)return[t];if(typeof t=="string"){const s=document.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t).filter(r=>r!=null)}function An(...t){const e=!Array.isArray(t[0]),n=e?0:-1,r=t[0+n],s=t[1+n],i=t[2+n],o=t[3+n],a=Zt(s,i,o);return e?a(r):a}function Dn(t,e,n={}){const r=t.get();let s=null,i=r,o;const a=typeof r=="string"?r.replace(/[\d.-]/g,""):void 0,u=()=>{s&&(s.stop(),s=null),t.animation=void 0},l=()=>{const f=St(t.get()),d=St(i);if(f===d){u();return}const M=s?s.getGeneratorVelocity():t.getVelocity();u(),s=new bn({keyframes:[f,d],velocity:M,type:"spring",restDelta:.001,restSpeed:.01,...n,onUpdate:o})},c=()=>{var f;l(),t.animation=s??void 0,(f=t.events.animationStart)==null||f.notify(),s==null||s.then(()=>{var d;t.animation=void 0,(d=t.events.animationComplete)==null||d.notify()})};if(t.attach((f,d)=>{i=f,o=M=>d(ot(M,a)),tt.postRender(c)},u),Jt(e)){let f=n.skipInitialAnimation===!0;const d=e.on("change",x=>{f?(f=!1,t.jump(ot(x,a),!1)):t.set(ot(x,a))}),M=t.on("destroy",d);return()=>{d(),M()}}return u}function ot(t,e){return e?t+e:t}function St(t){return typeof t=="number"?t:parseFloat(t)}const Ht=S.createContext({transformPagePoint:t=>t,isStatic:!1,reducedMotion:"never"});function bt(t){const e=kt(()=>xn(t)),{isStatic:n}=S.useContext(Ht);if(n){const[,r]=S.useState(t);S.useEffect(()=>e.on("change",r),[])}return e}function Xt(t,e){const n=bt(e()),r=()=>n.set(e());return r(),te(()=>{const s=()=>tt.preRender(r,!1,!0),i=t.map(o=>o.on("change",s));return()=>{i.forEach(o=>o()),Ut(r)}}),n}function Fn(t){B.current=[],t();const e=Xt(B.current,t);return B.current=void 0,e}function Sn(t,e,n,r){if(typeof t=="function")return Fn(t);const i=An(e,n,r),o=Array.isArray(t)?wt(t,i):wt([t],([u])=>i(u)),a=Array.isArray(t)?void 0:t.accelerate;return a&&!a.isTransformed&&typeof e!="function"&&Array.isArray(n)&&(r==null?void 0:r.clamp)!==!1&&(o.accelerate={...a,times:e,keyframes:n,isTransformed:!0}),o}function wt(t,e){const n=kt(()=>[]);return Xt(t,()=>{n.length=0;const r=t.length;for(let s=0;s<r;s++)n[s]=t[s].get();return e(n)})}function wn(t,e={}){const{isStatic:n}=S.useContext(Ht),r=()=>Jt(t)?t.get():t;if(n)return Sn(r);const s=bt(r());return S.useInsertionEffect(()=>Dn(s,t,e),[s,JSON.stringify(e)]),s}function kn(t,e={}){return wn(t,{type:"spring",...e})}const Cn={some:0,all:1};function Vn(t,e,{root:n,margin:r,amount:s="some"}={}){const i=Mn(t),o=new WeakMap,a=l=>{l.forEach(c=>{const f=o.get(c.target);if(c.isIntersecting!==!!f)if(c.isIntersecting){const d=e(c.target,c);typeof d=="function"?o.set(c.target,d):u.unobserve(c.target)}else typeof f=="function"&&(f(c),o.delete(c.target))})},u=new IntersectionObserver(a,{root:n,rootMargin:r,threshold:typeof s=="number"?s:Cn[s]});return i.forEach(l=>u.observe(l)),()=>u.disconnect()}function In(t,{root:e,margin:n,amount:r,once:s=!1,initial:i=!1}={}){const[o,a]=S.useState(i);return S.useEffect(()=>{if(!t.current||s&&o)return;const u=()=>(a(!0),s?void 0:()=>a(!1)),l={root:e&&e.current||void 0,margin:n,amount:r};return Vn(t.current,u,l)},[e,t,n,s,r]),o}function Rn({to:t,from:e=0,direction:n="up",delay:r=0,duration:s=2,className:i="",startWhen:o=!0,separator:a="",onStart:u,onEnd:l}){const c=S.useRef(null),f=bt(n==="down"?t:e),d=20+40*(1/s),M=100*(1/s),x=kn(f,{damping:d,stiffness:M}),m=In(c,{once:!0,margin:"0px"}),v=T=>{const g=T.toString();if(g.includes(".")){const y=g.split(".")[1];if(parseInt(y)!==0)return y.length}return 0},p=Math.max(v(e),v(t)),w=S.useCallback(T=>{const g=p>0,y={useGrouping:!!a,minimumFractionDigits:g?p:0,maximumFractionDigits:g?p:0},D=Intl.NumberFormat("en-US",y).format(T);return a?D.replace(/,/g,a):D},[p,a]);return S.useEffect(()=>{c.current&&(c.current.textContent=w(n==="down"?t:e))},[e,t,n,w]),S.useEffect(()=>{if(m&&o){typeof u=="function"&&u();const T=setTimeout(()=>{f.set(n==="down"?e:t)},r*1e3),g=setTimeout(()=>{typeof l=="function"&&l()},r*1e3+s*1e3);return()=>{clearTimeout(T),clearTimeout(g)}}},[m,o,f,n,e,t,r,u,l,s]),S.useEffect(()=>{const T=x.on("change",g=>{c.current&&(c.current.textContent=w(g))});return()=>T()},[x,w]),Qt.jsx("span",{className:i,ref:c})}export{Rn as C};
|