svg-scroll-draw 2.2.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/angular/index.cjs +3 -3
- package/dist/angular/index.d.mts +194 -9
- package/dist/angular/index.d.ts +194 -9
- package/dist/angular/index.mjs +3 -3
- package/dist/astro/index.cjs +3 -3
- package/dist/astro/index.d.mts +78 -1
- package/dist/astro/index.d.ts +78 -1
- package/dist/astro/index.mjs +3 -3
- package/dist/cdn/svg-scroll-draw.global.js +3 -3
- package/dist/devtools/index.cjs +1 -1
- package/dist/devtools/index.d.mts +12 -0
- package/dist/devtools/index.d.ts +12 -0
- package/dist/devtools/index.mjs +1 -1
- package/dist/group/index.cjs +3 -3
- package/dist/group/index.d.mts +88 -1
- package/dist/group/index.d.ts +88 -1
- package/dist/group/index.mjs +3 -3
- package/dist/index.cjs +4 -4
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +4 -4
- package/dist/lenis/index.cjs +1 -0
- package/dist/lenis/index.d.mts +51 -0
- package/dist/lenis/index.d.ts +51 -0
- package/dist/lenis/index.mjs +1 -0
- package/dist/nuxt/index.cjs +3 -3
- package/dist/nuxt/index.d.mts +286 -5
- package/dist/nuxt/index.d.ts +286 -5
- package/dist/nuxt/index.mjs +3 -3
- package/dist/pin/index.cjs +1 -0
- package/dist/pin/index.d.mts +29 -0
- package/dist/pin/index.d.ts +29 -0
- package/dist/pin/index.mjs +1 -0
- package/dist/react/index.cjs +3 -3
- package/dist/react/index.d.mts +16 -0
- package/dist/react/index.d.ts +16 -0
- package/dist/react/index.mjs +3 -3
- package/dist/snap/index.cjs +1 -0
- package/dist/snap/index.d.mts +30 -0
- package/dist/snap/index.d.ts +30 -0
- package/dist/snap/index.mjs +1 -0
- package/dist/solid/index.cjs +3 -3
- package/dist/solid/index.d.mts +171 -1
- package/dist/solid/index.d.ts +171 -1
- package/dist/solid/index.mjs +3 -3
- package/dist/svelte/index.cjs +3 -3
- package/dist/svelte/index.d.mts +183 -10
- package/dist/svelte/index.d.ts +183 -10
- package/dist/svelte/index.mjs +3 -3
- package/dist/vue/index.cjs +3 -3
- package/dist/vue/index.d.mts +278 -1
- package/dist/vue/index.d.ts +278 -1
- package/dist/vue/index.mjs +3 -3
- package/dist/web-component/index.cjs +3 -3
- package/dist/web-component/index.mjs +3 -3
- package/package.json +16 -1
package/dist/solid/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var solidJs=require('solid-js');function
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${S?`left:${x}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${x}px;left:0;right:0;border-top:2px dashed #ef4444;`}padding:2px 6px;color:#ef4444;background:rgba(0,0,0,.6)">\u25A0 end</div>`;}return document.body.appendChild(o),window.addEventListener("scroll",h,{passive:true}),h(),o}function Ie(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),h=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,g=>{let P=parseFloat(g),x=o[h++]??P;return String(+(P+(x-P)*n).toFixed(4))})}function Oe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let{preset:n,...o}=r,h=n?{...Be[n],...o}:o,g=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:P="path, polyline, line, polygon, rect, circle",speed:x=1,fade:S=false,easing:p="linear",trigger:E={},stagger:G=0,direction:d="forward",once:K=false,debug:Je=false,axis:N="y",scrollContainer:$e,autoReverse:me=false,delay:ue=0,strokeColor:Q,strokeWidth:Y,fillOpacity:Z,waypoints:ee,velocityScale:pe=false,threshold:Fe=0,rootMargin:Ce="0px",repeat:te=0,repeatDelay:Me=0,morphTo:H,clip:Se,autoplay:Ke=false,duration:Qe=1e3,native:Ye=true,onProgress:ce,onStart:de,onComplete:ae}=h,_=Se===true?"left":typeof Se=="string"?Se:false,re=typeof p=="function"?p:Le[p]??Le.linear,Re=De(E.start??"top bottom"),Ne=De(E.end??"bottom top"),I=typeof $e=="string"?document.querySelector($e):$e??null,W=Array.isArray(Q)?Q[0]:null,T=Array.isArray(Q)?Q[1]:typeof Q=="string"?Q:null,O=Array.isArray(Y)?Y[0]:null,k=Array.isArray(Y)?Y[1]:typeof Y=="number"?Y:null,F=Array.isArray(Z)?Z[0]:null,A=Array.isArray(Z)?Z[1]:typeof Z=="number"?Z:null;function ne(t){let s=t*100;switch(_){case "right":return `inset(0 0 0 ${100-s}%)`;case "top":return `inset(0 0 ${100-s}% 0)`;case "bottom":return `inset(${100-s}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-s}% 0 0)`}}let $=_?[]:Array.from(e.querySelectorAll(P)),w=[],z=[],X=0,U=0,M=false,R=false,v=0,ye=false,q=-1,he=-1,L=false,se=0,B=0,j,Te=null,J=new Set,ge=-1,He=performance.now();function fe(){return I?N==="x"?I.scrollLeft:I.scrollTop:N==="x"?window.scrollX:window.scrollY}function We(){return I?N==="x"?I.clientWidth:I.clientHeight:N==="x"?window.innerWidth:window.innerHeight}function ze(){let t=e.getBoundingClientRect(),s,l,y;if(I){let D=I.getBoundingClientRect();s=N==="x"?t.left-D.left+I.scrollLeft:t.top-D.top+I.scrollTop,l=N==="x"?t.width:t.height,y=fe();}else s=N==="x"?t.left:t.top,l=N==="x"?t.width:t.height,y=fe();let C=Pe({top:s,height:l},y,We(),Re,Ne);X=C.tStart,U=C.tEnd,Je&&process.env.NODE_ENV!=="production"&&(Te?.remove(),Te=ut(X,U,N));}function Ze(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),_){let l=s==="reverse"?1-t:t;e.style.clipPath=ne(l);return}$.forEach((l,y)=>{l.style.strokeDashoffset=s==="reverse"?`${w[y]*t}`:`${w[y]*(1-t)}`,S&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),W&&T?l.style.stroke=xe(W,T,t):T&&(l.style.stroke=T),O!==null&&k!==null?l.style.strokeWidth=`${O+(k-O)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),F!==null&&A!==null?l.style.fillOpacity=`${F+(A-F)*t}`:A!==null&&(l.style.fillOpacity=`${A}`),H&&l.tagName.toLowerCase()==="path"&&z[y]&&l.setAttribute("d",Ie(z[y],H,t));});}function be(){if(e.style.setProperty("--scroll-draw-progress","0"),_){e.style.clipPath=ne(0);return}$.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=d==="reverse"?"0":`${w[s]}`,S?t.style.opacity=d==="reverse"?"1":"0":t.style.opacity="",W&&(t.style.stroke=W),O!==null&&(t.style.strokeWidth=`${O}`),F!==null&&(t.style.fillOpacity=`${F}`),H&&t.tagName.toLowerCase()==="path"&&z[s]&&t.setAttribute("d",z[s]);});}if($.forEach(t=>{lt(t);let s=Ee(t);w.push(s),t.tagName.toLowerCase()==="path"?z.push(t.getAttribute("d")??""):z.push(""),g?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=d==="reverse"?`${s}`:"0",S&&(t.style.opacity="1"),T&&(t.style.stroke=T),k!==null&&(t.style.strokeWidth=`${k}`),A!==null&&(t.style.fillOpacity=`${A}`),H&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",H)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=d==="reverse"?"0":`${s}`,S?t.style.opacity=d==="reverse"?"1":"0":t.style.opacity="",W&&(t.style.stroke=W),O!==null&&(t.style.strokeWidth=`${O}`),F!==null&&(t.style.fillOpacity=`${F}`));}),_){if(g)return e.style.clipPath=ne(1),ae?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=ne(0);}else if(g)return ae?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function et(){return !(Ye===false||!at()||!$.length||typeof p!="string"||!(p in Xe)||_||N!=="y"||I||x!==1||G!==0||K||me||pe!==false||H||ee||te||ue>0||ce||de||ae||Q!=null||Y!=null||Z!=null||(E.start??"top bottom").trim()!=="top bottom"||(E.end??"bottom top").trim()!=="bottom top")}function tt(){let t=`svg-scroll-draw-${++it}`,s=d==="reverse"?"0":"var(--ssd-len)",l=d==="reverse"?"var(--ssd-len)":"0",y=`stroke-dashoffset:${s};`,C=`stroke-dashoffset:${l};`;S&&(y+=`opacity:${d==="reverse"?1:0};`,C+=`opacity:${d==="reverse"?0:1};`);let D=document.createElement("style");D.setAttribute("data-svg-scroll-draw",""),D.textContent=`@keyframes ${t}{from{${y}}to{${C}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Xe[p]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(D);function a(i,c){i.style.setProperty("--ssd-len",String(w[c])),i.style.strokeDasharray=`${w[c]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}$.forEach(a);let f=false,b=-1;function u(){if(b>=0)return b;let i=e.getBoundingClientRect(),{tStart:c,tEnd:m}=Pe({top:i.top,height:i.height},fe(),We(),Re,Ne);return re(ie(fe(),c,m,x))}return {destroy(){$.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),D.remove();},replay(){f=false,b=-1,$.forEach(a);},pause(){f=true,$.forEach(i=>{i.style.animationPlayState="paused";});},resume(){f&&(f=false,$.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let c=Math.min(1,Math.max(0,i));b=c,f=true,$.forEach((m,oe)=>{m.classList.remove(t),m.style.strokeDashoffset=d==="reverse"?`${w[oe]*c}`:`${w[oe]*(1-c)}`,S&&(m.style.opacity=d==="reverse"?`${1-c}`:`${c}`);});},getProgress(){return u()}}}if(et())return tt();function rt(){let t=Math.max(1,Qe),s=0,l=0;function y(u){let i=true;if(_){let c=Math.min(1,Math.max(0,u/t)),m=re(c);se=m,e.style.setProperty("--scroll-draw-progress",String(m)),e.style.clipPath=ne(d==="reverse"?1-m:m),ce?.(m),c<1&&(i=false);}else $.forEach((c,m)=>{let oe=m*G*t,le=Math.min(1,Math.max(0,(u-oe)/t)),V=re(le);c.style.strokeDashoffset=d==="reverse"?`${w[m]*V}`:`${w[m]*(1-V)}`,S&&(c.style.opacity=d==="reverse"?`${1-V}`:`${V}`),W&&T?c.style.stroke=xe(W,T,V):T&&(c.style.stroke=T),O!==null&&k!==null?c.style.strokeWidth=`${O+(k-O)*V}`:k!==null&&(c.style.strokeWidth=`${k}`),F!==null&&A!==null?c.style.fillOpacity=`${F+(A-F)*V}`:A!==null&&(c.style.fillOpacity=`${A}`),H&&c.tagName.toLowerCase()==="path"&&z[m]&&c.setAttribute("d",Ie(z[m],H,V)),m===0&&(ce?.(V),e.style.setProperty("--scroll-draw-progress",String(V))),le<1&&(i=false);});if(ee){let c=Math.min(1,Math.max(0,u/t)),m=re(c);for(let oe in ee){let le=parseFloat(oe);m>=le&&!J.has(le)&&(J.add(le),ee[oe]?.());}}return i}function C(u){if(L)return;let i=u-s;R||(R=true,de?.());let c=y(i);if(c&&!M){M=true,y(t*(1+Math.max(0,$.length-1)*G)),ae?.(),B<(te==="infinite"?1/0:te??0)&&(B++,j=setTimeout(()=>{s=performance.now(),R=false,M=false,J.clear(),be(),v=requestAnimationFrame(C);},Me));return}c||(v=requestAnimationFrame(C));}function D(){cancelAnimationFrame(v),clearTimeout(j),s=performance.now(),l=0,L=false,R=false,M=false,B=0,J.clear(),be(),v=requestAnimationFrame(C);}let a=new IntersectionObserver(u=>{u.forEach(i=>{i.isIntersecting&&!(K&&M)?D():!i.isIntersecting&&!K&&!M&&(cancelAnimationFrame(v),clearTimeout(j),s=null);});},{root:I??null,threshold:Fe,rootMargin:Ce}),f;function b(){clearTimeout(f),f=setTimeout(()=>{$.forEach((u,i)=>{w[i]=Ee(u),u.style.strokeDasharray=`${w[i]}`;});},150);}return window.addEventListener("resize",b),window.addEventListener("orientationchange",b),ue>0?setTimeout(()=>a.observe(e),ue):a.observe(e),{destroy(){cancelAnimationFrame(v),clearTimeout(j),a.disconnect(),window.removeEventListener("resize",b),window.removeEventListener("orientationchange",b),clearTimeout(f);},replay(){B=0,D();},pause(){L||(L=true,l=performance.now()-s,cancelAnimationFrame(v));},resume(){L&&(L=false,s=performance.now()-l,v=requestAnimationFrame(C));},seek(u){let i=Math.min(1,Math.max(0,u));se=i,L=true,l=i*t,s=performance.now()-l,cancelAnimationFrame(v),y(l);},getProgress(){return se}}}if(Ke)return rt();ze();function we(){if(!ye||L)return;let t=performance.now(),s=fe(),l=x;if(pe!==false){let a=t-He,f=a>0?Math.abs(s-(ge<0?s:ge))/a:0;l=x*Math.max(.2,1+f*(typeof pe=="number"?pe:1)*.04);}ge=s,He=t;let y=me?he===-1||s>=he?"forward":"reverse":d;he=s;let C=U-X,D=true;if(_){let a=re(ie(s,X,U,l));K&&!me&&(q=Math.max(q,a),a=q),se=a,e.style.setProperty("--scroll-draw-progress",String(a));let f=y==="reverse"?1-a:a;e.style.clipPath=ne(f),ce?.(a),!R&&ie(s,X,U,l)>0&&(R=true,de?.()),a>=1&&!M?(M=true,ae?.(),B<(te==="infinite"?1/0:te??0)&&(B++,j=setTimeout(()=>{q=-1,R=false,M=false,e.style.clipPath=ne(0);},Me))):a<1&&!K&&(M=false),v=requestAnimationFrame(we);return}if($.forEach((a,f)=>{let b=f*G*C,u=re(ie(s,X+b,U+b,l));K&&!me&&(q=Math.max(q,u),u=q),se=u,a.style.strokeDashoffset=y==="reverse"?`${w[f]*u}`:`${w[f]*(1-u)}`,S&&(a.style.opacity=y==="reverse"?`${1-u}`:`${u}`),W&&T?a.style.stroke=xe(W,T,u):T&&(a.style.stroke=T),O!==null&&k!==null?a.style.strokeWidth=`${O+(k-O)*u}`:k!==null&&(a.style.strokeWidth=`${k}`),F!==null&&A!==null?a.style.fillOpacity=`${F+(A-F)*u}`:A!==null&&(a.style.fillOpacity=`${A}`),H&&a.tagName.toLowerCase()==="path"&&z[f]&&a.setAttribute("d",Ie(z[f],H,u)),f===0&&(ce?.(u),e.style.setProperty("--scroll-draw-progress",String(u))),u<1&&(D=false);}),ee){let a=re(ie(s,X,U,l));for(let f in ee){let b=parseFloat(f);a>=b&&!J.has(b)&&(J.add(b),ee[f]?.());}}!R&&ie(s,X,U,l)>0&&(R=true,de?.()),D&&!M?(M=true,ae?.(),B<(te==="infinite"?1/0:te??0)&&(B++,j=setTimeout(()=>{q=-1,R=false,M=false,J.clear(),be();},Me))):!D&&!K&&(M=false),v=requestAnimationFrame(we);}let ke=new IntersectionObserver(t=>{t.forEach(s=>{ye=s.isIntersecting,ye&&!L?v=requestAnimationFrame(we):cancelAnimationFrame(v);});},{root:I??null,threshold:Fe,rootMargin:Ce}),Ae;function ve(){clearTimeout(Ae),Ae=setTimeout(()=>{$.forEach((t,s)=>{w[s]=Ee(t),t.style.strokeDasharray=`${w[s]}`;}),ze();},150);}return window.addEventListener("resize",ve),window.addEventListener("orientationchange",ve),ue>0?setTimeout(()=>ke.observe(e),ue):ke.observe(e),{destroy(){cancelAnimationFrame(v),clearTimeout(j),ke.disconnect(),window.removeEventListener("resize",ve),window.removeEventListener("orientationchange",ve),clearTimeout(Ae),Te?.remove();},replay(){q=-1,he=-1,ge=-1,R=false,M=false,B=0,L=false,J.clear(),clearTimeout(j),be();},pause(){L=true,cancelAnimationFrame(v);},resume(){L&&(L=false,ye&&(v=requestAnimationFrame(we)));},seek(t){let s=Math.min(1,Math.max(0,t));se=s,q=s,L=true,cancelAnimationFrame(v),Ze(s,d);},getProgress(){return se}}}function gt(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Oe(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),o=>{r=o;}}function bt(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Oe(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:o=>{r=o;},getInstance:()=>n}}exports.createScrollDraw=bt;exports.useScrollDraw=gt;
|
|
1
|
+
'use strict';var solidJs=require('solid-js');function Tt({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),t=Math.max(.01,Math.min(.99,r)),u=Math.sqrt(t),s=0,m=[];for(let h=0;h<n;h++){let $=Math.pow(u,h);m.push($),s+=$;}let l=[0],c=0;for(let h=0;h<n;h++)c+=m[h]/s,l.push(c);return h=>{if(h<=0)return 0;if(h>=1)return 1;for(let $=0;$<n;$++)if(h<=l[$+1]){let B=(h-l[$])/(l[$+1]-l[$]);if($===0)return B*(2-B);let S=1-Math.pow(t,$);return S+(1-S)*(2*B-1)*(2*B-1)}return 1}}function xt({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),t=Math.max(.1,r),u=n<=1?t/4:t/(2*Math.PI)*Math.asin(1/n);return s=>s<=0?0:s>=1?1:n*Math.pow(2,-10*s)*Math.sin((s-u)*(2*Math.PI)/t)+1}var ie={linear:e=>e,"ease-in":e=>e*e,"ease-out":e=>e*(2-e),"ease-in-out":e=>e<.5?2*e*e:-1+(4-2*e)*e,spring:e=>1-Math.cos(e*Math.PI*2.5)*Math.pow(1-e,2.2),bounce:Tt(),elastic:xt()};function ae(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",t="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:t}}function st(e,r,n,t){switch(t){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function it(e,r){if(/^\d+(\.\d+)?%$/.test(e))return r*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return r/2;case "bottom":return r;default:return r}}function Ge(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),t=parseFloat(e.getAttribute("height")??"0");return 2*(n+t)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function At(e,r,n){return Math.min(n,Math.max(r,e))}function K(e,r,n,t){return n===r?0:At((e-r)/(n-r)*t,0,1)}function pe(e,r,n,t,u){let s=st(e.top,e.height,r,t.element)-it(t.viewport,n),m=st(e.top,e.height,r,u.element)-it(u.viewport,n);return {tStart:s,tEnd:m}}function at(e){let r=/^#([a-f\d])([a-f\d])([a-f\d])$/i.exec(e);if(r)return [parseInt(r[1]+r[1],16),parseInt(r[2]+r[2],16),parseInt(r[3]+r[3],16)];let n=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(n)return [parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16)];let t=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return t?[parseInt(t[1]),parseInt(t[2]),parseInt(t[3])]:null}function He(e,r,n){let t=at(e),u=at(r);return !t||!u?e:`rgb(${Math.round(t[0]+(u[0]-t[0])*n)},${Math.round(t[1]+(u[1]-t[1])*n)},${Math.round(t[2]+(u[2]-t[2])*n)})`}var lt={sketch:{easing:"ease-in",stagger:.1,speed:.9,fade:false},reveal:{easing:"ease-out",fade:true,speed:1.2,once:true},typewriter:{easing:"linear",stagger:.05,speed:1.5},cinematic:{easing:"ease-in-out",fade:true,speed:.75},spring:{easing:"spring",speed:1.1}};function ct(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var ut={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},Mt=0;function Lt(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function $t(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?ct("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&ct("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ct(e,r,n){let t=document.createElement("div");t.setAttribute("data-svg-scroll-draw-debug",""),t.style.cssText="position:fixed;pointer-events:none;z-index:9999;font-family:monospace;font-size:11px;top:0;left:0;right:0;bottom:0;";function u(){let s=n==="x"?window.scrollX:window.scrollY,m=e-s,l=r-s,c=n==="x";t.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${c?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}padding:2px 6px;color:#22c55e;background:rgba(0,0,0,.6)">\u25B6 start</div>
|
|
3
|
+
<div style="position:absolute;${c?`left:${l}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${l}px;left:0;right:0;border-top:2px dashed #ef4444;`}padding:2px 6px;color:#ef4444;background:rgba(0,0,0,.6)">\u25A0 end</div>`;}return document.body.appendChild(t),window.addEventListener("scroll",u,{passive:true}),u(),t}function Ue(e,r,n){let t=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),u=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,s=>{let m=parseFloat(s),l=t[u++]??m;return String(+(m+(l-m)*n).toFixed(4))})}function Ze(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let{preset:n,...t}=r,u=n?{...lt[n],...t}:t,s=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:m="path, polyline, line, polygon, rect, circle",speed:l=1,fade:c=false,easing:h="linear",trigger:$={},stagger:B=0,direction:S="forward",once:Q=false,debug:he=false,axis:R="y",scrollContainer:ee,autoReverse:te=false,delay:q=0,strokeColor:T,strokeWidth:A,fillOpacity:w,waypoints:b,velocityScale:P=false,threshold:I=0,rootMargin:G="0px",repeat:C=0,repeatDelay:F=0,morphTo:M,clip:V,autoplay:ne=false,duration:H=1e3,native:W=true,onProgress:d,onStart:L,onComplete:g,onEnter:y,onLeave:X,onEnterBack:xe,onLeaveBack:be}=u,we=V===true?"left":typeof V=="string"?V:false,de=typeof h=="function"?h:ie[h]??ie.linear,Ne=ae($.start??"top bottom"),ke=ae($.end??"bottom top"),U=typeof ee=="string"?document.querySelector(ee):ee??null,i=Array.isArray(T)?T[0]:null,p=Array.isArray(T)?T[1]:typeof T=="string"?T:null,Y=Array.isArray(A)?A[0]:null,N=Array.isArray(A)?A[1]:typeof A=="number"?A:null,Z=Array.isArray(w)?w[0]:null,oe=Array.isArray(w)?w[1]:typeof w=="number"?w:null;function J(o){let a=o*100;switch(we){case "right":return `inset(0 0 0 ${100-a}%)`;case "top":return `inset(0 0 ${100-a}% 0)`;case "bottom":return `inset(${100-a}% 0 0 0)`;case "center":return `circle(${o*150}% at 50% 50%)`;default:return `inset(0 ${100-a}% 0 0)`}}let _=we?[]:Array.from(e.querySelectorAll(m)),O=[],fe=[],ge=0,Me=0,se=false,ye=false,re=0,Ve=false,ve=-1,ze=-1,le=false,Ie=0,Ae=0,Le,Xe=null,$e=new Set,qe=-1,nt=performance.now(),De=NaN;function Re(){return U?R==="x"?U.scrollLeft:U.scrollTop:R==="x"?window.scrollX:window.scrollY}function rt(){return U?R==="x"?U.clientWidth:U.clientHeight:R==="x"?window.innerWidth:window.innerHeight}function ot(){let o=e.getBoundingClientRect(),a,E,j;if(U){let ue=U.getBoundingClientRect();a=R==="x"?o.left-ue.left+U.scrollLeft:o.top-ue.top+U.scrollTop,E=R==="x"?o.width:o.height,j=Re();}else a=R==="x"?o.left:o.top,E=R==="x"?o.width:o.height,j=Re();let ce=pe({top:a,height:E},j,rt(),Ne,ke);ge=ce.tStart,Me=ce.tEnd,he&&process.env.NODE_ENV!=="production"&&(Xe?.remove(),Xe=Ct(ge,Me,R));}function wt(o,a){if(e.style.setProperty("--scroll-draw-progress",String(o)),we){let E=a==="reverse"?1-o:o;e.style.clipPath=J(E);return}_.forEach((E,j)=>{E.style.strokeDashoffset=a==="reverse"?`${O[j]*o}`:`${O[j]*(1-o)}`,c&&(E.style.opacity=a==="reverse"?`${1-o}`:`${o}`),i&&p?E.style.stroke=He(i,p,o):p&&(E.style.stroke=p),Y!==null&&N!==null?E.style.strokeWidth=`${Y+(N-Y)*o}`:N!==null&&(E.style.strokeWidth=`${N}`),Z!==null&&oe!==null?E.style.fillOpacity=`${Z+(oe-Z)*o}`:oe!==null&&(E.style.fillOpacity=`${oe}`),M&&E.tagName.toLowerCase()==="path"&&fe[j]&&E.setAttribute("d",Ue(fe[j],M,o));});}function We(){if(e.style.setProperty("--scroll-draw-progress","0"),we){e.style.clipPath=J(0);return}_.forEach((o,a)=>{o.style.strokeDasharray=`${O[a]}`,o.style.strokeDashoffset=S==="reverse"?"0":`${O[a]}`,c?o.style.opacity=S==="reverse"?"1":"0":o.style.opacity="",i&&(o.style.stroke=i),Y!==null&&(o.style.strokeWidth=`${Y}`),Z!==null&&(o.style.fillOpacity=`${Z}`),M&&o.tagName.toLowerCase()==="path"&&fe[a]&&o.setAttribute("d",fe[a]);});}if(_.forEach(o=>{$t(o);let a=Ge(o);O.push(a),o.tagName.toLowerCase()==="path"?fe.push(o.getAttribute("d")??""):fe.push(""),s?(o.style.strokeDasharray=`${a}`,o.style.strokeDashoffset=S==="reverse"?`${a}`:"0",c&&(o.style.opacity="1"),p&&(o.style.stroke=p),N!==null&&(o.style.strokeWidth=`${N}`),oe!==null&&(o.style.fillOpacity=`${oe}`),M&&o.tagName.toLowerCase()==="path"&&o.setAttribute("d",M)):(o.style.strokeDasharray=`${a}`,o.style.strokeDashoffset=S==="reverse"?"0":`${a}`,c?o.style.opacity=S==="reverse"?"1":"0":o.style.opacity="",i&&(o.style.stroke=i),Y!==null&&(o.style.strokeWidth=`${Y}`),Z!==null&&(o.style.fillOpacity=`${Z}`));}),we){if(s)return e.style.clipPath=J(1),g?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=J(0);}else if(s)return g?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function vt(){return !(W===false||!Lt()||!_.length||typeof h!="string"||!(h in ut)||we||R!=="y"||U||l!==1||B!==0||Q||te||P!==false||M||b||C||q>0||d||L||g||y||X||xe||be||T!=null||A!=null||w!=null||($.start??"top bottom").trim()!=="top bottom"||($.end??"bottom top").trim()!=="bottom top")}function Et(){let o=`svg-scroll-draw-${++Mt}`,a=S==="reverse"?"0":"var(--ssd-len)",E=S==="reverse"?"var(--ssd-len)":"0",j=`stroke-dashoffset:${a};`,ce=`stroke-dashoffset:${E};`;c&&(j+=`opacity:${S==="reverse"?1:0};`,ce+=`opacity:${S==="reverse"?0:1};`);let ue=document.createElement("style");ue.setAttribute("data-svg-scroll-draw",""),ue.textContent=`@keyframes ${o}{from{${j}}to{${ce}}}.${o}{animation-name:${o};animation-duration:auto;animation-timing-function:${ut[h]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(ue);function me(f,x){f.style.setProperty("--ssd-len",String(O[x])),f.style.strokeDasharray=`${O[x]}`,f.style.strokeDashoffset="",f.style.opacity="",f.style.animationPlayState="",f.classList.add(o);}_.forEach(me);let v=false,k=-1;function D(){if(k>=0)return k;let f=e.getBoundingClientRect(),{tStart:x,tEnd:z}=pe({top:f.top,height:f.height},Re(),rt(),Ne,ke);return de(K(Re(),x,z,l))}return {destroy(){_.forEach(f=>{f.classList.remove(o),f.style.removeProperty("--ssd-len"),f.style.animationPlayState="";}),ue.remove();},replay(){v=false,k=-1,_.forEach(me);},pause(){v=true,_.forEach(f=>{f.style.animationPlayState="paused";});},resume(){v&&(v=false,_.forEach(f=>{f.style.animationPlayState="running";}));},seek(f){let x=Math.min(1,Math.max(0,f));k=x,v=true,_.forEach((z,Oe)=>{z.classList.remove(o),z.style.strokeDashoffset=S==="reverse"?`${O[Oe]*x}`:`${O[Oe]*(1-x)}`,c&&(z.style.opacity=S==="reverse"?`${1-x}`:`${x}`);});},getProgress(){return D()}}}if(vt())return Et();function St(){let o=Math.max(1,H),a=0,E=0;function j(D){let f=true;if(we){let x=Math.min(1,Math.max(0,D/o)),z=de(x);Ie=z,e.style.setProperty("--scroll-draw-progress",String(z)),e.style.clipPath=J(S==="reverse"?1-z:z),d?.(z),x<1&&(f=false);}else _.forEach((x,z)=>{let Oe=z*B*o,Fe=Math.min(1,Math.max(0,(D-Oe)/o)),Ee=de(Fe);x.style.strokeDashoffset=S==="reverse"?`${O[z]*Ee}`:`${O[z]*(1-Ee)}`,c&&(x.style.opacity=S==="reverse"?`${1-Ee}`:`${Ee}`),i&&p?x.style.stroke=He(i,p,Ee):p&&(x.style.stroke=p),Y!==null&&N!==null?x.style.strokeWidth=`${Y+(N-Y)*Ee}`:N!==null&&(x.style.strokeWidth=`${N}`),Z!==null&&oe!==null?x.style.fillOpacity=`${Z+(oe-Z)*Ee}`:oe!==null&&(x.style.fillOpacity=`${oe}`),M&&x.tagName.toLowerCase()==="path"&&fe[z]&&x.setAttribute("d",Ue(fe[z],M,Ee)),z===0&&(d?.(Ee),e.style.setProperty("--scroll-draw-progress",String(Ee))),Fe<1&&(f=false);});if(b){let x=Math.min(1,Math.max(0,D/o)),z=de(x);for(let Oe in b){let Fe=parseFloat(Oe);z>=Fe&&!$e.has(Fe)&&($e.add(Fe),b[Oe]?.());}}return f}function ce(D){if(le)return;let f=D-a;ye||(ye=true,L?.());let x=j(f);if(x&&!se){se=true,j(o*(1+Math.max(0,_.length-1)*B)),g?.(),Ae<(C==="infinite"?1/0:C??0)&&(Ae++,Le=setTimeout(()=>{a=performance.now(),ye=false,se=false,$e.clear(),We(),re=requestAnimationFrame(ce);},F));return}x||(re=requestAnimationFrame(ce));}function ue(){cancelAnimationFrame(re),clearTimeout(Le),a=performance.now(),E=0,le=false,ye=false,se=false,Ae=0,$e.clear(),We(),re=requestAnimationFrame(ce);}let me=new IntersectionObserver(D=>{D.forEach(f=>{f.isIntersecting&&!(Q&&se)?ue():!f.isIntersecting&&!Q&&!se&&(cancelAnimationFrame(re),clearTimeout(Le),a=null);});},{root:U??null,threshold:I,rootMargin:G}),v;function k(){clearTimeout(v),v=setTimeout(()=>{_.forEach((D,f)=>{O[f]=Ge(D),D.style.strokeDasharray=`${O[f]}`;});},150);}return window.addEventListener("resize",k),window.addEventListener("orientationchange",k),q>0?setTimeout(()=>me.observe(e),q):me.observe(e),{destroy(){cancelAnimationFrame(re),clearTimeout(Le),me.disconnect(),window.removeEventListener("resize",k),window.removeEventListener("orientationchange",k),clearTimeout(v);},replay(){Ae=0,ue();},pause(){le||(le=true,E=performance.now()-a,cancelAnimationFrame(re));},resume(){le&&(le=false,a=performance.now()-E,re=requestAnimationFrame(ce));},seek(D){let f=Math.min(1,Math.max(0,D));Ie=f,le=true,E=f*o,a=performance.now()-E,cancelAnimationFrame(re),j(E);},getProgress(){return Ie}}}if(ne)return St();ot();function _e(){if(!Ve||le)return;let o=performance.now(),a=Re(),E=l;if(P!==false){let v=o-nt,k=v>0?Math.abs(a-(qe<0?a:qe))/v:0;E=l*Math.max(.2,1+k*(typeof P=="number"?P:1)*.04);}qe=a,nt=o;let j=te?ze===-1||a>=ze?"forward":"reverse":S;ze=a;let ce=Me-ge,ue=true,me=ce===0?0:(a-ge)/ce;if(isNaN(De)||(De<=0&&me>0?y?.():De>0&&me<=0&&be?.(),De<1&&me>=1?X?.():De>=1&&me<1&&xe?.()),De=me,we){let v=de(K(a,ge,Me,E));Q&&!te&&(ve=Math.max(ve,v),v=ve),Ie=v,e.style.setProperty("--scroll-draw-progress",String(v));let k=j==="reverse"?1-v:v;e.style.clipPath=J(k),d?.(v),!ye&&K(a,ge,Me,E)>0&&(ye=true,L?.()),v>=1&&!se?(se=true,g?.(),Ae<(C==="infinite"?1/0:C??0)&&(Ae++,Le=setTimeout(()=>{ve=-1,ye=false,se=false,e.style.clipPath=J(0);},F))):v<1&&!Q&&(se=false),re=requestAnimationFrame(_e);return}if(_.forEach((v,k)=>{let D=k*B*ce,f=de(K(a,ge+D,Me+D,E));Q&&!te&&(ve=Math.max(ve,f),f=ve),Ie=f,v.style.strokeDashoffset=j==="reverse"?`${O[k]*f}`:`${O[k]*(1-f)}`,c&&(v.style.opacity=j==="reverse"?`${1-f}`:`${f}`),i&&p?v.style.stroke=He(i,p,f):p&&(v.style.stroke=p),Y!==null&&N!==null?v.style.strokeWidth=`${Y+(N-Y)*f}`:N!==null&&(v.style.strokeWidth=`${N}`),Z!==null&&oe!==null?v.style.fillOpacity=`${Z+(oe-Z)*f}`:oe!==null&&(v.style.fillOpacity=`${oe}`),M&&v.tagName.toLowerCase()==="path"&&fe[k]&&v.setAttribute("d",Ue(fe[k],M,f)),k===0&&(d?.(f),e.style.setProperty("--scroll-draw-progress",String(f))),f<1&&(ue=false);}),b){let v=de(K(a,ge,Me,E));for(let k in b){let D=parseFloat(k);v>=D&&!$e.has(D)&&($e.add(D),b[k]?.());}}!ye&&K(a,ge,Me,E)>0&&(ye=true,L?.()),ue&&!se?(se=true,g?.(),Ae<(C==="infinite"?1/0:C??0)&&(Ae++,Le=setTimeout(()=>{ve=-1,ye=false,se=false,$e.clear(),We();},F))):!ue&&!Q&&(se=false),re=requestAnimationFrame(_e);}let Ye=new IntersectionObserver(o=>{o.forEach(a=>{Ve=a.isIntersecting,Ve&&!le?re=requestAnimationFrame(_e):cancelAnimationFrame(re);});},{root:U??null,threshold:I,rootMargin:G}),je;function Be(){clearTimeout(je),je=setTimeout(()=>{_.forEach((o,a)=>{O[a]=Ge(o),o.style.strokeDasharray=`${O[a]}`;}),ot();},150);}return window.addEventListener("resize",Be),window.addEventListener("orientationchange",Be),q>0?setTimeout(()=>Ye.observe(e),q):Ye.observe(e),{destroy(){cancelAnimationFrame(re),clearTimeout(Le),Ye.disconnect(),window.removeEventListener("resize",Be),window.removeEventListener("orientationchange",Be),clearTimeout(je),Xe?.remove();},replay(){ve=-1,ze=-1,qe=-1,ye=false,se=false,Ae=0,le=false,$e.clear(),clearTimeout(Le),We();},pause(){le=true,cancelAnimationFrame(re);},resume(){le&&(le=false,Ve&&(re=requestAnimationFrame(_e)));},seek(o){let a=Math.min(1,Math.max(0,o));Ie=a,ve=a,le=true,cancelAnimationFrame(re),wt(a,S);},getProgress(){return Ie}}}var ft=new Map;function Ce(e,r){ft.set(e,r);}function Pe(e){ft.delete(e);}function Pt(e){return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")}function mt(e){let r=[],n=/([\w]+)\(([^)]*)\)/g,t;for(;(t=n.exec(e))!==null;){let u=[],s=[],m=t[2].trim();if(m)for(let l of m.split(/[\s,]+/)){let c=l.match(/^([-+]?[\d.eE]+)(.*)$/);u.push(c?parseFloat(c[1]):0),s.push(c?c[2]:"");}r.push({fn:t[1],nums:u,units:s});}return r}function It(e,r,n){let t=mt(e),u=mt(r);return t.length===0||t.length!==u.length?n<1?e:r:t.map((s,m)=>{let l=u[m];return s.fn!==l.fn||s.nums.length!==l.nums.length?n<1?`${s.fn}(${s.nums.map((c,h)=>`${c}${s.units[h]}`).join(", ")})`:`${l.fn}(${l.nums.map((c,h)=>`${c}${l.units[h]}`).join(", ")})`:`${s.fn}(${s.nums.map((c,h)=>`${c+(l.nums[h]-c)*n}${s.units[h]}`).join(", ")})`}).join(" ")}function pt(e,r,n){if(typeof e=="number"&&typeof r=="number")return String(e+(r-e)*n);let t=String(e),u=String(r);if(Pt(t))return He(t,u,n);if(t.includes("("))return It(t,u,n);let s=t.match(/^([-+]?[\d.]+)(.*)$/),m=u.match(/^([-+]?[\d.]+)(.*)$/);if(s&&m){let l=parseFloat(s[1]),c=parseFloat(m[1]);return `${l+(c-l)*n}${s[2]||m[2]}`}return n<1?t:u}function Ot(e){return e.replace(/([A-Z])/g,r=>`-${r.toLowerCase()}`)}var dt={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},kt=new Set(["opacity","transform","background-color","color","filter","scale","translate","rotate"]),Dt=0;function Ft(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function Je(e,r){let n={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};if(typeof window>"u")return n;let{props:t,trigger:u={},easing:s="ease-out",speed:m=1,once:l=false,axis:c="y",scrollContainer:h,native:$=true,onProgress:B,onComplete:S,onEnter:Q,onLeave:he,onEnterBack:R,onLeaveBack:ee}=r,te=window.matchMedia("(prefers-reduced-motion: reduce)").matches,q=typeof s=="function"?s:ie[s]??ie["ease-out"],T=ae(u.start??"top bottom"),A=ae(u.end??"bottom top"),w=typeof h=="string"?document.querySelector(h):h??null,b=Object.entries(t).map(([i,p])=>({prop:Ot(i),from:Array.isArray(p)?p[0]:"",to:Array.isArray(p)?p[1]:p}));function P(){let i=window.getComputedStyle(e);for(let p of b)p.from===""&&(p.from=i.getPropertyValue(p.prop).trim()||"0");}function I(){for(let i of b)e.style.setProperty(i.prop,String(i.to));}if(te)return I(),S?.(),n;P();function G(){if(!$||!Ft()||typeof s!="string"||!(s in dt)||c!=="y"||w||l||m!==1||B||S||Q||he||R||ee||(u.start??"top bottom").trim()!=="top bottom"||(u.end??"bottom top").trim()!=="bottom top")return false;for(let i of b)if(!kt.has(i.prop))return false;return true}function C(){let i=`ssd-a-${++Dt}`,p=b.map(J=>`${J.prop}:${J.from}`).join(";"),Y=b.map(J=>`${J.prop}:${J.to}`).join(";"),N=document.createElement("style");N.setAttribute("data-ssd-animate",""),N.textContent=`@keyframes ${i}{from{${p}}to{${Y}}}.${i}{animation-name:${i};animation-duration:auto;animation-timing-function:${dt[s]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(N),e.classList.add(i);let Z=()=>c==="x"?window.scrollX:window.scrollY,oe=()=>c==="x"?window.innerWidth:window.innerHeight;return {destroy(){e.classList.remove(i),N.remove();},replay(){e.classList.remove(i),e.offsetWidth,e.classList.add(i);},pause(){e.style.animationPlayState="paused";},resume(){e.style.animationPlayState="";},seek(J){let _=Math.min(1,Math.max(0,J));e.classList.remove(i);for(let O of b)e.style.setProperty(O.prop,pt(O.from,O.to,_));},getProgress(){let J=e.getBoundingClientRect(),_=Z(),O=oe(),{tStart:fe,tEnd:ge}=pe({top:J.top,height:J.height},_,O,T,A);return q(K(_,fe,ge,m))}}}if(G())return C();let F=0,M=0,V=0,ne=false,H=false,W=-1,d=0,L=false,g=NaN,y=()=>w?c==="x"?w.scrollLeft:w.scrollTop:c==="x"?window.scrollX:window.scrollY,X=()=>w?c==="x"?w.clientWidth:w.clientHeight:c==="x"?window.innerWidth:window.innerHeight;function xe(){let i=e.getBoundingClientRect(),p,Y;if(w){let Z=w.getBoundingClientRect();p=c==="x"?i.left-Z.left+w.scrollLeft:i.top-Z.top+w.scrollTop,Y=c==="x"?i.width:i.height;}else p=c==="x"?i.left:i.top,Y=c==="x"?i.width:i.height;let N=pe({top:p,height:Y},y(),X(),T,A);F=N.tStart,M=N.tEnd;}function be(i){e.style.setProperty("--scroll-draw-progress",String(i));for(let p of b)e.style.setProperty(p.prop,pt(p.from,p.to,i));B?.(i);}function we(i){if(isNaN(g)){g=i;return}g<=0&&i>0?Q?.():g>0&&i<=0&&ee?.(),g<1&&i>=1?he?.():g>=1&&i<1&&R?.(),g=i;}function de(){if(!ne||H)return;let i=M===F?0:(y()-F)/(M-F);we(i);let p=q(K(y(),F,M,m));l&&(W=Math.max(W,p),p=W),d=p,be(p),p>=1&&!L?(L=true,S?.()):p<1&&!l&&(L=false),V=requestAnimationFrame(de);}xe();{let i=q(K(y(),F,M,m));l&&i>0&&(W=i),d=i,be(i);}let Ne=new IntersectionObserver(i=>{i.forEach(p=>{ne=p.isIntersecting,ne&&!H?V=requestAnimationFrame(de):cancelAnimationFrame(V);});},{root:w??null}),ke;function U(){clearTimeout(ke),ke=setTimeout(xe,150);}return window.addEventListener("resize",U),window.addEventListener("orientationchange",U),Ne.observe(e),Ce(e,{type:"animate",getProgress:()=>d,getTrigger:()=>({tStart:F,tEnd:M})}),{destroy(){cancelAnimationFrame(V),Ne.disconnect(),window.removeEventListener("resize",U),window.removeEventListener("orientationchange",U),clearTimeout(ke),Pe(e);},replay(){W=-1,L=false,d=0,H=false,be(0);},pause(){H=true,cancelAnimationFrame(V);},resume(){H&&(H=false,ne&&(V=requestAnimationFrame(de)));},seek(i){let p=Math.min(1,Math.max(0,i));d=p,W=p,H=true,cancelAnimationFrame(V),be(p);},getProgress(){return d}}}var Ke={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};function Qe(e,r){if(typeof window>"u")return Ke;let n=typeof e=="string"?document.querySelector(e):e;if(!n)return process.env.NODE_ENV!=="production"&&console.warn("[svg-scroll-draw] scrollCounter: element not found:",e),Ke;let t=n,{from:u=0,to:s,format:m,easing:l="ease-out",trigger:c={},once:h=true,decimals:$,onComplete:B}=r,S=$!==void 0?d=>d.toFixed($):m??(d=>String(Math.round(d))),Q=typeof l=="function"?l:ie[l]??ie["ease-out"],he=ae(c.start??"top 80%"),R=ae(c.end??"top 20%");if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return t.textContent=S(s),B?.(),Ke;t.textContent=S(u);let te=0,q=0,T=0,A=false,w=false,b=-1,P=0,I=false,G=()=>window.scrollY,C=()=>window.innerHeight;function F(){let d=t.getBoundingClientRect(),L=pe({top:d.top,height:d.height},G(),C(),he,R);te=L.tStart,q=L.tEnd;}function M(d){t.textContent=S(u+(s-u)*d),t.style.setProperty("--scroll-draw-progress",String(d));}function V(){if(!A||w)return;let d=Q(K(G(),te,q,1));h&&(b=Math.max(b,d),d=b),P=d,M(d),d>=1&&!I?(I=true,B?.()):d<1&&!h&&(I=false),T=requestAnimationFrame(V);}F();{let d=Q(K(G(),te,q,1));h&&d>0&&(b=d),P=d,M(d);}let ne=new IntersectionObserver(d=>{d.forEach(L=>{A=L.isIntersecting,A&&!w?T=requestAnimationFrame(V):cancelAnimationFrame(T);});}),H;function W(){clearTimeout(H),H=setTimeout(F,150);}return window.addEventListener("resize",W),window.addEventListener("orientationchange",W),ne.observe(t),Ce(t,{type:"counter",getProgress:()=>P,getTrigger:()=>({tStart:te,tEnd:q})}),{destroy(){cancelAnimationFrame(T),ne.disconnect(),window.removeEventListener("resize",W),window.removeEventListener("orientationchange",W),clearTimeout(H),Pe(t);},replay(){b=-1,I=false,P=0,w=false,M(0);},pause(){w=true,cancelAnimationFrame(T);},resume(){w&&(w=false,A&&(T=requestAnimationFrame(V)));},seek(d){let L=Math.min(1,Math.max(0,d));P=L,b=L,w=true,cancelAnimationFrame(T),M(L);},getProgress(){return P}}}var gt={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};function et(e,r={}){if(typeof window>"u")return gt;let n=typeof e=="string"?document.querySelector(e):e;if(!n||n.tagName.toLowerCase()!=="video")return process.env.NODE_ENV!=="production"&&console.warn("[svg-scroll-draw] scrollVideo: <video> element not found:",e),gt;let t=n,{trigger:u={},easing:s="linear",once:m=false,axis:l="y",preload:c="auto",onReady:h,onComplete:$,onProgress:B}=r,S=window.matchMedia("(prefers-reduced-motion: reduce)").matches,Q=typeof s=="function"?s:ie[s]??ie.linear,he=ae(u.start??"top top"),R=ae(u.end??"bottom top");t.pause(),t.hasAttribute("preload")||(t.preload=c);let ee=r.from??0,te=r.to,q=0,T=0,A=0,w=false,b=false,P=-1,I=0,G=false,C=false,F=()=>l==="x"?window.scrollX:window.scrollY,M=()=>l==="x"?window.innerWidth:window.innerHeight;function V(){let y=t.getBoundingClientRect(),X=l==="x"?y.left:y.top,xe=l==="x"?y.width:y.height,be=pe({top:X,height:xe},F(),M(),he,R);q=be.tStart,T=be.tEnd;}function ne(y){if(!C)return;let X=te??t.duration??0;t.currentTime=ee+(X-ee)*y,t.style.setProperty("--scroll-draw-progress",String(y)),B?.(y);}function H(){if(!w||b||!C)return;let y=Q(K(F(),q,T,1));m&&(P=Math.max(P,y),y=P),I=y,ne(y),y>=1&&!G?(G=true,$?.()):y<1&&!m&&(G=false),A=requestAnimationFrame(H);}function W(){if(C=true,te===void 0&&(te=t.duration),S){ne(1),h?.();return}V(),h?.(),w&&!b&&(A=requestAnimationFrame(H));}t.readyState>=1?W():t.addEventListener("loadedmetadata",W,{once:true}),C||V();let d=new IntersectionObserver(y=>{y.forEach(X=>{w=X.isIntersecting,w&&!b&&C?A=requestAnimationFrame(H):cancelAnimationFrame(A);});}),L;function g(){clearTimeout(L),L=setTimeout(V,150);}return window.addEventListener("resize",g),window.addEventListener("orientationchange",g),d.observe(t),Ce(t,{type:"video",getProgress:()=>I,getTrigger:()=>({tStart:q,tEnd:T})}),{destroy(){cancelAnimationFrame(A),d.disconnect(),t.removeEventListener("loadedmetadata",W),window.removeEventListener("resize",g),window.removeEventListener("orientationchange",g),clearTimeout(L),Pe(t);},replay(){P=-1,G=false,I=0,b=false,ne(0);},pause(){b=true,cancelAnimationFrame(A);},resume(){b&&(b=false,w&&C&&(A=requestAnimationFrame(H)));},seek(y){let X=Math.min(1,Math.max(0,y));I=X,P=X,b=true,cancelAnimationFrame(A),ne(X);},getProgress(){return I}}}function bt(e){let r=e.textContent??"";return e.textContent="",r.split(/(\s+)/).filter(Boolean).map(n=>{let t=document.createElement("span");return t.setAttribute("aria-hidden","true"),/^\s+$/.test(n)?(t.textContent=n,t.style.whiteSpace="pre"):(t.textContent=n,t.style.display="inline-block"),e.appendChild(t),/^\s+$/.test(n)?null:t}).filter(n=>n!==null)}function Ht(e){let r=e.textContent??"";return e.textContent="",r.split("").map(n=>{let t=document.createElement("span");return t.setAttribute("aria-hidden","true"),t.textContent=n,n===" "?t.style.whiteSpace="pre":t.style.display="inline-block",e.appendChild(t),n===" "?null:t}).filter(n=>n!==null)}function yt(e){let r=bt(e),n=new Map;for(let s of r){let m=s.offsetTop;n.has(m)||n.set(m,[]),n.get(m).push(s);}let t=[],u=Array.from(n.keys()).sort((s,m)=>s-m);for(let s of u){let m=n.get(s),l=document.createElement("span");l.setAttribute("aria-hidden","true"),l.style.display="inline-block";for(let c of m)l.appendChild(c);t.push(l);}e.textContent="";for(let s of t)e.appendChild(s),e.appendChild(document.createTextNode(" "));return t}function Nt(e,r,n,t){if(n<=1||t===0)return e;let u=(n-1)*t,s=r*t,m=s+(1-u);return m<=s?e>=s?1:0:Math.min(1,Math.max(0,(e-s)/(m-s)))}function Rt(e,r){let n=[];if(r?.y!==void 0&&n.push(`translateY(${r.y*(1-e)}px)`),r?.x!==void 0&&n.push(`translateX(${r.x*(1-e)}px)`),r?.rotate!==void 0&&n.push(`rotate(${r.rotate*(1-e)}deg)`),r?.scale!==void 0){let t=r.scale+(1-r.scale)*e;n.push(`scale(${t})`);}return n.join(" ")||""}var ht={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};function tt(e,r={}){if(typeof window>"u")return ht;let n=typeof e=="string"?document.querySelector(e):e;if(!n)return process.env.NODE_ENV!=="production"&&console.warn("[svg-scroll-draw] scrollText: element not found:",e),ht;let t=n,{split:u="words",stagger:s=.04,easing:m="ease-out",from:l={opacity:0,y:24},trigger:c={},once:h=true,onComplete:$}=r,B=window.matchMedia("(prefers-reduced-motion: reduce)").matches,S=typeof m=="function"?m:ie[m]??ie["ease-out"],Q=ae(c.start??"top 85%"),he=ae(c.end??"top 40%"),R=t.innerHTML;t.setAttribute("aria-label",t.textContent??"");let ee;u==="chars"?ee=Ht(t):u==="lines"?ee=yt(t):ee=bt(t);let te=ee.length;function q(g,y){l?.opacity!==void 0&&(g.style.opacity=String(l.opacity+(1-l.opacity)*y));let X=Rt(y,l);X&&(g.style.transform=X);}function T(g){t.style.setProperty("--scroll-draw-progress",String(g)),ee.forEach((y,X)=>{let xe=S(Nt(g,X,te,s));q(y,xe);});}if(B)return T(1),$?.(),{destroy(){t.innerHTML=R,t.removeAttribute("aria-label");},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};T(0);let A=0,w=0,b=0,P=false,I=false,G=-1,C=0,F=false,M=()=>window.scrollY,V=()=>window.innerHeight;function ne(){let g=t.getBoundingClientRect(),y=pe({top:g.top,height:g.height},M(),V(),Q,he);A=y.tStart,w=y.tEnd;}function H(){if(!P||I)return;let g=K(M(),A,w,1);h&&(G=Math.max(G,g),g=G),C=g,T(g),g>=1&&!F?(F=true,$?.()):g<1&&!h&&(F=false),b=requestAnimationFrame(H);}ne();let W=new IntersectionObserver(g=>{g.forEach(y=>{P=y.isIntersecting,P&&!I?b=requestAnimationFrame(H):cancelAnimationFrame(b);});}),d;function L(){clearTimeout(d),d=setTimeout(()=>{if(u==="lines"){let g=C;t.innerHTML=R,t.setAttribute("aria-label",t.textContent??""),ee=yt(t),T(g);}ne();},150);}return window.addEventListener("resize",L),window.addEventListener("orientationchange",L),W.observe(t),Ce(t,{type:"text",getProgress:()=>C,getTrigger:()=>({tStart:A,tEnd:w})}),{destroy(){cancelAnimationFrame(b),W.disconnect(),window.removeEventListener("resize",L),window.removeEventListener("orientationchange",L),clearTimeout(d),t.innerHTML=R,t.removeAttribute("aria-label"),Pe(t);},replay(){G=-1,F=false,C=0,I=false,T(0);},pause(){I=true,cancelAnimationFrame(b);},resume(){I&&(I=false,P&&(b=requestAnimationFrame(H)));},seek(g){let y=Math.min(1,Math.max(0,g));C=y,G=y,I=true,cancelAnimationFrame(b),T(y);},getProgress(){return C}}}function un(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Ze(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),t=>{r=t;}}function fn(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Ze(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:t=>{r=t;},getInstance:()=>n}}function mn(e){let r,n;return solidJs.onMount(()=>{r&&(n=Je(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),t=>{r=t;}}function pn(e){let r,n;return solidJs.onMount(()=>{r&&(n=Je(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:t=>{r=t;},getInstance:()=>n}}function dn(e){let r,n;return solidJs.onMount(()=>{r&&(n=Qe(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),t=>{r=t;}}function gn(e){let r,n;return solidJs.onMount(()=>{r&&(n=Qe(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:t=>{r=t;},getInstance:()=>n}}function yn(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=et(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),t=>{r=t;}}function hn(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=et(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:t=>{r=t;},getInstance:()=>n}}function bn(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=tt(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),t=>{r=t;}}function wn(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=tt(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:t=>{r=t;},getInstance:()=>n}}exports.createScrollAnimate=pn;exports.createScrollCounter=gn;exports.createScrollDraw=fn;exports.createScrollText=wn;exports.createScrollVideo=hn;exports.useScrollAnimate=mn;exports.useScrollCounter=dn;exports.useScrollDraw=un;exports.useScrollText=bn;exports.useScrollVideo=yn;
|
package/dist/solid/index.d.mts
CHANGED
|
@@ -71,6 +71,14 @@ interface ScrollDrawOptions {
|
|
|
71
71
|
onProgress?: (alpha: number) => void;
|
|
72
72
|
onStart?: () => void;
|
|
73
73
|
onComplete?: () => void;
|
|
74
|
+
/** Fires when scroll position enters the trigger zone (scrolling forward). */
|
|
75
|
+
onEnter?: () => void;
|
|
76
|
+
/** Fires when scroll position exits the trigger zone at the end (scrolling forward). */
|
|
77
|
+
onLeave?: () => void;
|
|
78
|
+
/** Fires when scroll position re-enters the trigger zone from the end (scrolling back). */
|
|
79
|
+
onEnterBack?: () => void;
|
|
80
|
+
/** Fires when scroll position exits the trigger zone at the start (scrolling back). */
|
|
81
|
+
onLeaveBack?: () => void;
|
|
74
82
|
/**
|
|
75
83
|
* Trigger the animation when the element enters the viewport instead of
|
|
76
84
|
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
@@ -119,6 +127,67 @@ interface ScrollDrawInstance {
|
|
|
119
127
|
getProgress: () => number;
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
interface ScrollAnimateOptions {
|
|
131
|
+
props: Record<string, string | number | [string | number, string | number]>;
|
|
132
|
+
trigger?: TriggerConfig;
|
|
133
|
+
easing?: EasingName | ((t: number) => number);
|
|
134
|
+
speed?: number;
|
|
135
|
+
once?: boolean;
|
|
136
|
+
axis?: 'x' | 'y';
|
|
137
|
+
scrollContainer?: string | Element;
|
|
138
|
+
native?: boolean;
|
|
139
|
+
onProgress?: (alpha: number) => void;
|
|
140
|
+
onComplete?: () => void;
|
|
141
|
+
/** Fires when scroll enters the trigger zone (scrolling forward). */
|
|
142
|
+
onEnter?: () => void;
|
|
143
|
+
/** Fires when scroll exits the trigger zone at the end (scrolling forward). */
|
|
144
|
+
onLeave?: () => void;
|
|
145
|
+
/** Fires when scroll re-enters the trigger zone from the end (scrolling back). */
|
|
146
|
+
onEnterBack?: () => void;
|
|
147
|
+
/** Fires when scroll exits the trigger zone at the start (scrolling back). */
|
|
148
|
+
onLeaveBack?: () => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface ScrollCounterOptions {
|
|
152
|
+
from?: number;
|
|
153
|
+
to: number;
|
|
154
|
+
format?: (value: number) => string;
|
|
155
|
+
easing?: EasingName | ((t: number) => number);
|
|
156
|
+
trigger?: TriggerConfig;
|
|
157
|
+
once?: boolean;
|
|
158
|
+
decimals?: number;
|
|
159
|
+
onComplete?: () => void;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
interface ScrollVideoOptions {
|
|
163
|
+
trigger?: TriggerConfig;
|
|
164
|
+
from?: number;
|
|
165
|
+
to?: number;
|
|
166
|
+
easing?: EasingName | ((t: number) => number);
|
|
167
|
+
once?: boolean;
|
|
168
|
+
axis?: 'x' | 'y';
|
|
169
|
+
preload?: 'auto' | 'metadata';
|
|
170
|
+
onReady?: () => void;
|
|
171
|
+
onComplete?: () => void;
|
|
172
|
+
onProgress?: (alpha: number) => void;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface ScrollTextOptions {
|
|
176
|
+
split?: 'chars' | 'words' | 'lines';
|
|
177
|
+
stagger?: number;
|
|
178
|
+
easing?: EasingName | ((t: number) => number);
|
|
179
|
+
from?: {
|
|
180
|
+
opacity?: number;
|
|
181
|
+
y?: number;
|
|
182
|
+
x?: number;
|
|
183
|
+
rotate?: number;
|
|
184
|
+
scale?: number;
|
|
185
|
+
};
|
|
186
|
+
trigger?: TriggerConfig;
|
|
187
|
+
once?: boolean;
|
|
188
|
+
onComplete?: () => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
122
191
|
/**
|
|
123
192
|
* SolidJS hook — returns a ref setter to attach to any container element.
|
|
124
193
|
*
|
|
@@ -144,5 +213,106 @@ declare function createScrollDraw(options?: ScrollDrawOptions): {
|
|
|
144
213
|
ref: (node: HTMLElement) => void;
|
|
145
214
|
getInstance: () => ScrollDrawInstance | undefined;
|
|
146
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* SolidJS hook — animate any CSS property on any element driven by scroll.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* import { useScrollAnimate } from 'svg-scroll-draw/solid';
|
|
221
|
+
*
|
|
222
|
+
* function Card() {
|
|
223
|
+
* const ref = useScrollAnimate({
|
|
224
|
+
* props: { opacity: [0, 1], transform: ['translateY(40px)', 'translateY(0)'] },
|
|
225
|
+
* easing: 'ease-out',
|
|
226
|
+
* once: true,
|
|
227
|
+
* });
|
|
228
|
+
* return <div ref={ref}>...</div>;
|
|
229
|
+
* }
|
|
230
|
+
*/
|
|
231
|
+
declare function useScrollAnimate(options: ScrollAnimateOptions): (node: HTMLElement) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Returns both the ref setter and a getter for the live instance.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* const { ref, getInstance } = createScrollAnimate({
|
|
237
|
+
* props: { opacity: [0, 1] }, easing: 'ease-out', once: true,
|
|
238
|
+
* });
|
|
239
|
+
* <div ref={ref}>...</div>
|
|
240
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
241
|
+
*/
|
|
242
|
+
declare function createScrollAnimate(options: ScrollAnimateOptions): {
|
|
243
|
+
ref: (node: HTMLElement) => void;
|
|
244
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* SolidJS hook — animate a number from `from` to `to` as the element scrolls in.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* import { useScrollCounter } from 'svg-scroll-draw/solid';
|
|
251
|
+
*
|
|
252
|
+
* function Stats() {
|
|
253
|
+
* const ref = useScrollCounter({ to: 1_250_000, format: n => '$' + Math.round(n).toLocaleString(), once: true });
|
|
254
|
+
* return <span ref={ref} />;
|
|
255
|
+
* }
|
|
256
|
+
*/
|
|
257
|
+
declare function useScrollCounter(options: ScrollCounterOptions): (node: HTMLElement) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Returns both the ref setter and a getter for the live counter instance.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* const { ref, getInstance } = createScrollCounter({ to: 1000, once: true });
|
|
263
|
+
* <span ref={ref} />
|
|
264
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
265
|
+
*/
|
|
266
|
+
declare function createScrollCounter(options: ScrollCounterOptions): {
|
|
267
|
+
ref: (node: HTMLElement) => void;
|
|
268
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* SolidJS hook — tie a <video> element's currentTime to scroll position.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* import { useScrollVideo } from 'svg-scroll-draw/solid';
|
|
275
|
+
*
|
|
276
|
+
* function HeroSection() {
|
|
277
|
+
* const ref = useScrollVideo({ trigger: { start: 'top top', end: 'bottom top' } });
|
|
278
|
+
* return <video ref={ref} src="/hero.mp4" muted playsinline preload="auto" />;
|
|
279
|
+
* }
|
|
280
|
+
*/
|
|
281
|
+
declare function useScrollVideo(options?: ScrollVideoOptions): (node: HTMLVideoElement) => void;
|
|
282
|
+
/**
|
|
283
|
+
* Returns both the ref setter and a getter for the live video instance.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* const { ref, getInstance } = createScrollVideo({ once: false });
|
|
287
|
+
* <video ref={ref} src="/hero.mp4" muted playsinline preload="auto" />
|
|
288
|
+
*/
|
|
289
|
+
declare function createScrollVideo(options?: ScrollVideoOptions): {
|
|
290
|
+
ref: (node: HTMLVideoElement) => void;
|
|
291
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* SolidJS hook — split text and stagger-animate each piece on scroll.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* import { useScrollText } from 'svg-scroll-draw/solid';
|
|
298
|
+
*
|
|
299
|
+
* function Headline() {
|
|
300
|
+
* const ref = useScrollText({ split: 'words', stagger: 0.05, once: true });
|
|
301
|
+
* return <h2 ref={ref}>Animate on scroll.</h2>;
|
|
302
|
+
* }
|
|
303
|
+
*/
|
|
304
|
+
declare function useScrollText(options?: ScrollTextOptions): (node: HTMLElement) => void;
|
|
305
|
+
/**
|
|
306
|
+
* Returns both the ref setter and a getter for the live text instance.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* const { ref, getInstance } = createScrollText({ split: 'chars', stagger: 0.03 });
|
|
310
|
+
* <p ref={ref}>Hello world.</p>
|
|
311
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
312
|
+
*/
|
|
313
|
+
declare function createScrollText(options?: ScrollTextOptions): {
|
|
314
|
+
ref: (node: HTMLElement) => void;
|
|
315
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
316
|
+
};
|
|
147
317
|
|
|
148
|
-
export { type ScrollDrawOptions, createScrollDraw, useScrollDraw };
|
|
318
|
+
export { type ScrollAnimateOptions, type ScrollCounterOptions, type ScrollDrawOptions, type ScrollTextOptions, type ScrollVideoOptions, createScrollAnimate, createScrollCounter, createScrollDraw, createScrollText, createScrollVideo, useScrollAnimate, useScrollCounter, useScrollDraw, useScrollText, useScrollVideo };
|
package/dist/solid/index.d.ts
CHANGED
|
@@ -71,6 +71,14 @@ interface ScrollDrawOptions {
|
|
|
71
71
|
onProgress?: (alpha: number) => void;
|
|
72
72
|
onStart?: () => void;
|
|
73
73
|
onComplete?: () => void;
|
|
74
|
+
/** Fires when scroll position enters the trigger zone (scrolling forward). */
|
|
75
|
+
onEnter?: () => void;
|
|
76
|
+
/** Fires when scroll position exits the trigger zone at the end (scrolling forward). */
|
|
77
|
+
onLeave?: () => void;
|
|
78
|
+
/** Fires when scroll position re-enters the trigger zone from the end (scrolling back). */
|
|
79
|
+
onEnterBack?: () => void;
|
|
80
|
+
/** Fires when scroll position exits the trigger zone at the start (scrolling back). */
|
|
81
|
+
onLeaveBack?: () => void;
|
|
74
82
|
/**
|
|
75
83
|
* Trigger the animation when the element enters the viewport instead of
|
|
76
84
|
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
@@ -119,6 +127,67 @@ interface ScrollDrawInstance {
|
|
|
119
127
|
getProgress: () => number;
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
interface ScrollAnimateOptions {
|
|
131
|
+
props: Record<string, string | number | [string | number, string | number]>;
|
|
132
|
+
trigger?: TriggerConfig;
|
|
133
|
+
easing?: EasingName | ((t: number) => number);
|
|
134
|
+
speed?: number;
|
|
135
|
+
once?: boolean;
|
|
136
|
+
axis?: 'x' | 'y';
|
|
137
|
+
scrollContainer?: string | Element;
|
|
138
|
+
native?: boolean;
|
|
139
|
+
onProgress?: (alpha: number) => void;
|
|
140
|
+
onComplete?: () => void;
|
|
141
|
+
/** Fires when scroll enters the trigger zone (scrolling forward). */
|
|
142
|
+
onEnter?: () => void;
|
|
143
|
+
/** Fires when scroll exits the trigger zone at the end (scrolling forward). */
|
|
144
|
+
onLeave?: () => void;
|
|
145
|
+
/** Fires when scroll re-enters the trigger zone from the end (scrolling back). */
|
|
146
|
+
onEnterBack?: () => void;
|
|
147
|
+
/** Fires when scroll exits the trigger zone at the start (scrolling back). */
|
|
148
|
+
onLeaveBack?: () => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface ScrollCounterOptions {
|
|
152
|
+
from?: number;
|
|
153
|
+
to: number;
|
|
154
|
+
format?: (value: number) => string;
|
|
155
|
+
easing?: EasingName | ((t: number) => number);
|
|
156
|
+
trigger?: TriggerConfig;
|
|
157
|
+
once?: boolean;
|
|
158
|
+
decimals?: number;
|
|
159
|
+
onComplete?: () => void;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
interface ScrollVideoOptions {
|
|
163
|
+
trigger?: TriggerConfig;
|
|
164
|
+
from?: number;
|
|
165
|
+
to?: number;
|
|
166
|
+
easing?: EasingName | ((t: number) => number);
|
|
167
|
+
once?: boolean;
|
|
168
|
+
axis?: 'x' | 'y';
|
|
169
|
+
preload?: 'auto' | 'metadata';
|
|
170
|
+
onReady?: () => void;
|
|
171
|
+
onComplete?: () => void;
|
|
172
|
+
onProgress?: (alpha: number) => void;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface ScrollTextOptions {
|
|
176
|
+
split?: 'chars' | 'words' | 'lines';
|
|
177
|
+
stagger?: number;
|
|
178
|
+
easing?: EasingName | ((t: number) => number);
|
|
179
|
+
from?: {
|
|
180
|
+
opacity?: number;
|
|
181
|
+
y?: number;
|
|
182
|
+
x?: number;
|
|
183
|
+
rotate?: number;
|
|
184
|
+
scale?: number;
|
|
185
|
+
};
|
|
186
|
+
trigger?: TriggerConfig;
|
|
187
|
+
once?: boolean;
|
|
188
|
+
onComplete?: () => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
122
191
|
/**
|
|
123
192
|
* SolidJS hook — returns a ref setter to attach to any container element.
|
|
124
193
|
*
|
|
@@ -144,5 +213,106 @@ declare function createScrollDraw(options?: ScrollDrawOptions): {
|
|
|
144
213
|
ref: (node: HTMLElement) => void;
|
|
145
214
|
getInstance: () => ScrollDrawInstance | undefined;
|
|
146
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* SolidJS hook — animate any CSS property on any element driven by scroll.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* import { useScrollAnimate } from 'svg-scroll-draw/solid';
|
|
221
|
+
*
|
|
222
|
+
* function Card() {
|
|
223
|
+
* const ref = useScrollAnimate({
|
|
224
|
+
* props: { opacity: [0, 1], transform: ['translateY(40px)', 'translateY(0)'] },
|
|
225
|
+
* easing: 'ease-out',
|
|
226
|
+
* once: true,
|
|
227
|
+
* });
|
|
228
|
+
* return <div ref={ref}>...</div>;
|
|
229
|
+
* }
|
|
230
|
+
*/
|
|
231
|
+
declare function useScrollAnimate(options: ScrollAnimateOptions): (node: HTMLElement) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Returns both the ref setter and a getter for the live instance.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* const { ref, getInstance } = createScrollAnimate({
|
|
237
|
+
* props: { opacity: [0, 1] }, easing: 'ease-out', once: true,
|
|
238
|
+
* });
|
|
239
|
+
* <div ref={ref}>...</div>
|
|
240
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
241
|
+
*/
|
|
242
|
+
declare function createScrollAnimate(options: ScrollAnimateOptions): {
|
|
243
|
+
ref: (node: HTMLElement) => void;
|
|
244
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* SolidJS hook — animate a number from `from` to `to` as the element scrolls in.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* import { useScrollCounter } from 'svg-scroll-draw/solid';
|
|
251
|
+
*
|
|
252
|
+
* function Stats() {
|
|
253
|
+
* const ref = useScrollCounter({ to: 1_250_000, format: n => '$' + Math.round(n).toLocaleString(), once: true });
|
|
254
|
+
* return <span ref={ref} />;
|
|
255
|
+
* }
|
|
256
|
+
*/
|
|
257
|
+
declare function useScrollCounter(options: ScrollCounterOptions): (node: HTMLElement) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Returns both the ref setter and a getter for the live counter instance.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* const { ref, getInstance } = createScrollCounter({ to: 1000, once: true });
|
|
263
|
+
* <span ref={ref} />
|
|
264
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
265
|
+
*/
|
|
266
|
+
declare function createScrollCounter(options: ScrollCounterOptions): {
|
|
267
|
+
ref: (node: HTMLElement) => void;
|
|
268
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* SolidJS hook — tie a <video> element's currentTime to scroll position.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* import { useScrollVideo } from 'svg-scroll-draw/solid';
|
|
275
|
+
*
|
|
276
|
+
* function HeroSection() {
|
|
277
|
+
* const ref = useScrollVideo({ trigger: { start: 'top top', end: 'bottom top' } });
|
|
278
|
+
* return <video ref={ref} src="/hero.mp4" muted playsinline preload="auto" />;
|
|
279
|
+
* }
|
|
280
|
+
*/
|
|
281
|
+
declare function useScrollVideo(options?: ScrollVideoOptions): (node: HTMLVideoElement) => void;
|
|
282
|
+
/**
|
|
283
|
+
* Returns both the ref setter and a getter for the live video instance.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* const { ref, getInstance } = createScrollVideo({ once: false });
|
|
287
|
+
* <video ref={ref} src="/hero.mp4" muted playsinline preload="auto" />
|
|
288
|
+
*/
|
|
289
|
+
declare function createScrollVideo(options?: ScrollVideoOptions): {
|
|
290
|
+
ref: (node: HTMLVideoElement) => void;
|
|
291
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* SolidJS hook — split text and stagger-animate each piece on scroll.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* import { useScrollText } from 'svg-scroll-draw/solid';
|
|
298
|
+
*
|
|
299
|
+
* function Headline() {
|
|
300
|
+
* const ref = useScrollText({ split: 'words', stagger: 0.05, once: true });
|
|
301
|
+
* return <h2 ref={ref}>Animate on scroll.</h2>;
|
|
302
|
+
* }
|
|
303
|
+
*/
|
|
304
|
+
declare function useScrollText(options?: ScrollTextOptions): (node: HTMLElement) => void;
|
|
305
|
+
/**
|
|
306
|
+
* Returns both the ref setter and a getter for the live text instance.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* const { ref, getInstance } = createScrollText({ split: 'chars', stagger: 0.03 });
|
|
310
|
+
* <p ref={ref}>Hello world.</p>
|
|
311
|
+
* <button onClick={() => getInstance()?.replay()}>Replay</button>
|
|
312
|
+
*/
|
|
313
|
+
declare function createScrollText(options?: ScrollTextOptions): {
|
|
314
|
+
ref: (node: HTMLElement) => void;
|
|
315
|
+
getInstance: () => ScrollDrawInstance | undefined;
|
|
316
|
+
};
|
|
147
317
|
|
|
148
|
-
export { type ScrollDrawOptions, createScrollDraw, useScrollDraw };
|
|
318
|
+
export { type ScrollAnimateOptions, type ScrollCounterOptions, type ScrollDrawOptions, type ScrollTextOptions, type ScrollVideoOptions, createScrollAnimate, createScrollCounter, createScrollDraw, createScrollText, createScrollVideo, useScrollAnimate, useScrollCounter, useScrollDraw, useScrollText, useScrollVideo };
|