svg-scroll-draw 1.1.0 → 1.3.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/dist/angular/index.cjs +3 -3
- package/dist/angular/index.d.mts +20 -1
- package/dist/angular/index.d.ts +20 -1
- package/dist/angular/index.mjs +3 -3
- package/dist/astro/index.cjs +3 -3
- package/dist/astro/index.d.mts +20 -1
- package/dist/astro/index.d.ts +20 -1
- package/dist/astro/index.mjs +3 -3
- package/dist/cdn/svg-scroll-draw.global.js +3 -3
- package/dist/group/index.cjs +3 -3
- package/dist/group/index.d.mts +20 -1
- package/dist/group/index.d.ts +20 -1
- package/dist/group/index.mjs +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.mts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.mjs +3 -3
- package/dist/nuxt/index.cjs +3 -3
- package/dist/nuxt/index.d.mts +20 -1
- package/dist/nuxt/index.d.ts +20 -1
- package/dist/nuxt/index.mjs +3 -3
- package/dist/react/index.cjs +3 -3
- package/dist/react/index.d.mts +20 -1
- package/dist/react/index.d.ts +20 -1
- package/dist/react/index.mjs +3 -3
- package/dist/solid/index.cjs +3 -3
- package/dist/solid/index.d.mts +20 -1
- package/dist/solid/index.d.ts +20 -1
- package/dist/solid/index.mjs +3 -3
- package/dist/svelte/index.cjs +3 -3
- package/dist/svelte/index.d.mts +20 -1
- package/dist/svelte/index.d.ts +20 -1
- package/dist/svelte/index.mjs +3 -3
- package/dist/timeline/index.cjs +1 -1
- package/dist/timeline/index.d.mts +1 -1
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.mjs +1 -1
- package/dist/vue/index.cjs +3 -3
- package/dist/vue/index.d.mts +20 -1
- package/dist/vue/index.d.ts +20 -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 +6 -2
package/dist/nuxt/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var vue=require('vue');var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${U?`left:${M}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${M}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(n),window.addEventListener("scroll",a,{passive:true}),a(),n}function Ve(e,r,o){let n=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,d=>{let m=parseFloat(d),M=n[a++]??m;return String(+(m+(M-m)*o).toFixed(4))})}function xe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let o=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:n="path, polyline, line, polygon, rect, circle",speed:a=1,fade:d=false,easing:m="linear",trigger:M={},stagger:U=0,direction:y="forward",once:X=false,debug:Be=false,axis:S="y",scrollContainer:ce,autoReverse:Z=false,delay:me=0,strokeColor:R,strokeWidth:H,fillOpacity:V,waypoints:ee,velocityScale:te=false,threshold:qe=0,rootMargin:_e="0px",repeat:j=0,repeatDelay:Ae=0,morphTo:L,clip:pe,native:Ue=true,onProgress:de,onStart:ye,onComplete:J}=r,W=pe===true?"left":typeof pe=="string"?pe:false,re=typeof m=="function"?m:we[m]??we.linear,Te=ve(M.start??"top bottom"),De=ve(M.end??"bottom top"),b=typeof ce=="string"?document.querySelector(ce):ce??null,C=Array.isArray(R)?R[0]:null,$=Array.isArray(R)?R[1]:typeof R=="string"?R:null,E=Array.isArray(H)?H[0]:null,x=Array.isArray(H)?H[1]:typeof H=="number"?H:null,k=Array.isArray(V)?V[0]:null,A=Array.isArray(V)?V[1]:typeof V=="number"?V:null;function _(t){let s=t*100;switch(W){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 w=W?[]:Array.from(e.querySelectorAll(n)),g=[],O=[],F=0,I=0,P=false,G=false,N=0,ne=false,T=-1,oe=-1,z=false,se=0,K=0,ie,ge=null,le=new Set,ae=-1,Me=performance.now();function Q(){return b?S==="x"?b.scrollLeft:b.scrollTop:S==="x"?window.scrollX:window.scrollY}function Pe(){return b?S==="x"?b.clientWidth:b.clientHeight:S==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),s,l,p;if(b){let v=b.getBoundingClientRect();s=S==="x"?t.left-v.left+b.scrollLeft:t.top-v.top+b.scrollTop,l=S==="x"?t.width:t.height,p=Q();}else s=S==="x"?t.left:t.top,l=S==="x"?t.width:t.height,p=Q();let B=$e({top:s,height:l},p,Pe(),Te,De);F=B.tStart,I=B.tEnd,Be&&process.env.NODE_ENV!=="production"&&(ge?.remove(),ge=et(F,I,S));}function Xe(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),W){let l=s==="reverse"?1-t:t;e.style.clipPath=_(l);return}w.forEach((l,p)=>{l.style.strokeDashoffset=s==="reverse"?`${g[p]*t}`:`${g[p]*(1-t)}`,d&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),C&&$?l.style.stroke=Ee(C,$,t):$&&(l.style.stroke=$),E!==null&&x!==null?l.style.strokeWidth=`${E+(x-E)*t}`:x!==null&&(l.style.strokeWidth=`${x}`),k!==null&&A!==null?l.style.fillOpacity=`${k+(A-k)*t}`:A!==null&&(l.style.fillOpacity=`${A}`),L&&l.tagName.toLowerCase()==="path"&&O[p]&&l.setAttribute("d",Ve(O[p],L,t));});}function Ce(){if(e.style.setProperty("--scroll-draw-progress","0"),W){e.style.clipPath=_(0);return}w.forEach((t,s)=>{t.style.strokeDasharray=`${g[s]}`,t.style.strokeDashoffset=y==="reverse"?"0":`${g[s]}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),E!==null&&(t.style.strokeWidth=`${E}`),k!==null&&(t.style.fillOpacity=`${k}`),L&&t.tagName.toLowerCase()==="path"&&O[s]&&t.setAttribute("d",O[s]);});}if(w.forEach(t=>{Ze(t);let s=Se(t);g.push(s),t.tagName.toLowerCase()==="path"?O.push(t.getAttribute("d")??""):O.push(""),o?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?`${s}`:"0",d&&(t.style.opacity="1"),$&&(t.style.stroke=$),x!==null&&(t.style.strokeWidth=`${x}`),A!==null&&(t.style.fillOpacity=`${A}`),L&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",L)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?"0":`${s}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),E!==null&&(t.style.strokeWidth=`${E}`),k!==null&&(t.style.fillOpacity=`${k}`));}),W){if(o)return e.style.clipPath=_(1),J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=_(0);}else if(o)return J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function je(){return !(Ue===false||!Ye()||!w.length||typeof m!="string"||!(m in He)||W||S!=="y"||b||a!==1||U!==0||X||Z||te!==false||L||ee||j||me>0||de||ye||J||R!=null||H!=null||V!=null||(M.start??"top bottom").trim()!=="top bottom"||(M.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++Qe}`,s=y==="reverse"?"0":"var(--ssd-len)",l=y==="reverse"?"var(--ssd-len)":"0",p=`stroke-dashoffset:${s};`,B=`stroke-dashoffset:${l};`;d&&(p+=`opacity:${y==="reverse"?1:0};`,B+=`opacity:${y==="reverse"?0:1};`);let v=document.createElement("style");v.setAttribute("data-svg-scroll-draw",""),v.textContent=`@keyframes ${t}{from{${p}}to{${B}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${He[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(v);function i(f,D){f.style.setProperty("--ssd-len",String(g[D])),f.style.strokeDasharray=`${g[D]}`,f.style.strokeDashoffset="",f.style.opacity="",f.style.animationPlayState="",f.classList.add(t);}w.forEach(i);let u=false,h=-1;function c(){if(h>=0)return h;let f=e.getBoundingClientRect(),{tStart:D,tEnd:Y}=$e({top:f.top,height:f.height},Q(),Pe(),Te,De);return re(q(Q(),D,Y,a))}return {destroy(){w.forEach(f=>{f.classList.remove(t),f.style.removeProperty("--ssd-len"),f.style.animationPlayState="";}),v.remove();},replay(){u=false,h=-1,w.forEach(i);},pause(){u=true,w.forEach(f=>{f.style.animationPlayState="paused";});},resume(){u&&(u=false,w.forEach(f=>{f.style.animationPlayState="running";}));},seek(f){let D=Math.min(1,Math.max(0,f));h=D,u=true,w.forEach((Y,Oe)=>{Y.classList.remove(t),Y.style.strokeDashoffset=y==="reverse"?`${g[Oe]*D}`:`${g[Oe]*(1-D)}`,d&&(Y.style.opacity=y==="reverse"?`${1-D}`:`${D}`);});},getProgress(){return c()}}}if(je())return Je();Le();function ue(){if(!ne||z)return;let t=performance.now(),s=Q(),l=a;if(te!==false){let i=t-Me,u=i>0?Math.abs(s-(ae<0?s:ae))/i:0;l=a*Math.max(.2,1+u*(typeof te=="number"?te:1)*.04);}ae=s,Me=t;let p=Z?oe===-1||s>=oe?"forward":"reverse":y;oe=s;let B=I-F,v=true;if(W){let i=re(q(s,F,I,l));X&&!Z&&(T=Math.max(T,i),i=T),se=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=p==="reverse"?1-i:i;e.style.clipPath=_(u),de?.(i),!G&&q(s,F,I,l)>0&&(G=true,ye?.()),i>=1&&!P?(P=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{T=-1,G=false,P=false,e.style.clipPath=_(0);},Ae))):i<1&&!X&&(P=false),N=requestAnimationFrame(ue);return}if(w.forEach((i,u)=>{let h=u*U*B,c=re(q(s,F+h,I+h,l));X&&!Z&&(T=Math.max(T,c),c=T),se=c,i.style.strokeDashoffset=p==="reverse"?`${g[u]*c}`:`${g[u]*(1-c)}`,d&&(i.style.opacity=p==="reverse"?`${1-c}`:`${c}`),C&&$?i.style.stroke=Ee(C,$,c):$&&(i.style.stroke=$),E!==null&&x!==null?i.style.strokeWidth=`${E+(x-E)*c}`:x!==null&&(i.style.strokeWidth=`${x}`),k!==null&&A!==null?i.style.fillOpacity=`${k+(A-k)*c}`:A!==null&&(i.style.fillOpacity=`${A}`),L&&i.tagName.toLowerCase()==="path"&&O[u]&&i.setAttribute("d",Ve(O[u],L,c)),u===0&&(de?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(v=false);}),ee){let i=re(q(s,F,I,l));for(let u in ee){let h=parseFloat(u);i>=h&&!le.has(h)&&(le.add(h),ee[u]?.());}}!G&&q(s,F,I,l)>0&&(G=true,ye?.()),v&&!P?(P=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{T=-1,G=false,P=false,le.clear(),Ce();},Ae))):!v&&!X&&(P=false),N=requestAnimationFrame(ue);}let he=new IntersectionObserver(t=>{t.forEach(s=>{ne=s.isIntersecting,ne&&!z?N=requestAnimationFrame(ue):cancelAnimationFrame(N);});},{root:b??null,threshold:qe,rootMargin:_e}),be;function fe(){clearTimeout(be),be=setTimeout(()=>{w.forEach((t,s)=>{g[s]=Se(t),t.style.strokeDasharray=`${g[s]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),me>0?setTimeout(()=>he.observe(e),me):he.observe(e),{destroy(){cancelAnimationFrame(N),clearTimeout(ie),he.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(be),ge?.remove();},replay(){T=-1,oe=-1,ae=-1,G=false,P=false,K=0,z=false,le.clear(),clearTimeout(ie),Ce();},pause(){z=true,cancelAnimationFrame(N);},resume(){z&&(z=false,ne&&(N=requestAnimationFrame(ue)));},seek(t){let s=Math.min(1,Math.max(0,t));se=s,T=s,z=true,cancelAnimationFrame(N),Xe(s,y);},getProgress(){return se}}}function nt(e={}){let r=vue.ref(null);return vue.onMounted(()=>{if(!r.value)return;let o=xe(r.value,e);vue.onUnmounted(()=>o.destroy());}),r}var ke=vue.defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:r}){let o=vue.ref(null);return vue.onMounted(()=>{if(!o.value)return;let n={};e.selector!=null&&(n.selector=e.selector),e.speed!=null&&(n.speed=e.speed),e.fade!=null&&(n.fade=e.fade),e.stagger!=null&&(n.stagger=e.stagger),e.easing!=null&&(n.easing=e.easing),e.direction!=null&&(n.direction=e.direction),e.trigger!=null&&(n.trigger=e.trigger),e.once!=null&&(n.once=e.once),e.debug!=null&&(n.debug=e.debug),e.onProgress!=null&&(n.onProgress=e.onProgress),e.onStart!=null&&(n.onStart=e.onStart),e.onComplete!=null&&(n.onComplete=e.onComplete);let a=xe(o.value,n);vue.onUnmounted(()=>a.destroy());}),()=>vue.h("div",{ref:o},r.default?.())}});function ct(){return {install(e){e.component("ScrollDraw",ke);}}}exports.ScrollDraw=ke;exports.createScrollDrawPlugin=ct;exports.useScrollDraw=nt;
|
|
1
|
+
'use strict';var vue=require('vue');function tt({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),m=Math.sqrt(o),p=0,b=[];for(let u=0;u<n;u++){let g=Math.pow(m,u);b.push(g),p+=g;}let x=[0],R=0;for(let u=0;u<n;u++)R+=b[u]/p,x.push(R);return u=>{if(u<=0)return 0;if(u>=1)return 1;for(let g=0;g<n;g++)if(u<=x[g+1]){let oe=(u-x[g])/(x[g+1]-x[g]);if(g===0)return oe*(2-oe);let P=1-Math.pow(o,g);return P+(1-P)*(2*oe-1)*(2*oe-1)}return 1}}function rt({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),o=Math.max(.1,r),m=n<=1?o/4:o/(2*Math.PI)*Math.asin(1/n);return p=>p<=0?0:p>=1?1:n*Math.pow(2,-10*p)*Math.sin((p-m)*(2*Math.PI)/o)+1}var Te={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:rt()};function ke(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",o="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:o}}function ze(e,r,n,o){switch(o){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function qe(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 we(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(n+o)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function nt(e,r,n){return Math.min(n,Math.max(r,e))}function ne(e,r,n,o){return n===r?0:nt((e-r)/(n-r)*o,0,1)}function De(e,r,n,o,m){let p=ze(e.top,e.height,r,o.element)-qe(o.viewport,n),b=ze(e.top,e.height,r,m.element)-qe(m.viewport,n);return {tStart:p,tEnd:b}}function Ve(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 o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function ve(e,r,n){let o=Ve(e),m=Ve(r);return !o||!m?e:`rgb(${Math.round(o[0]+(m[0]-o[0])*n)},${Math.round(o[1]+(m[1]-o[1])*n)},${Math.round(o[2]+(m[2]-o[2])*n)})`}function Be(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ge={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},ot=0;function st(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function it(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Be("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Be("Element has a fill \u2014 it may obscure the stroke animation.",e);}function at(e,r,n){let o=document.createElement("div");o.setAttribute("data-svg-scroll-draw-debug",""),o.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 m(){let p=n==="x"?window.scrollX:window.scrollY,b=e-p,x=r-p,R=n==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${R?`left:${b}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${b}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;${R?`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",m,{passive:true}),m(),o}function Pe(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),m=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,p=>{let b=parseFloat(p),x=o[m++]??b;return String(+(b+(x-b)*n).toFixed(4))})}function Le(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:m=1,fade:p=false,easing:b="linear",trigger:x={},stagger:R=0,direction:u="forward",once:g=false,debug:oe=false,axis:P="y",scrollContainer:Se,autoReverse:ce=false,delay:ae=0,strokeColor:j,strokeWidth:J,fillOpacity:K,waypoints:Q,velocityScale:fe=false,threshold:Oe=0,rootMargin:Ce="0px",repeat:Y=0,repeatDelay:xe=0,morphTo:N,clip:Ee,autoplay:je=false,duration:Je=1e3,native:Ke=true,onProgress:le,onStart:me,onComplete:se}=r,B=Ee===true?"left":typeof Ee=="string"?Ee:false,Z=typeof b=="function"?b:Te[b]??Te.linear,Ie=ke(x.start??"top bottom"),Re=ke(x.end??"bottom top"),L=typeof Se=="string"?document.querySelector(Se):Se??null,H=Array.isArray(j)?j[0]:null,M=Array.isArray(j)?j[1]:typeof j=="string"?j:null,F=Array.isArray(J)?J[0]:null,A=Array.isArray(J)?J[1]:typeof J=="number"?J:null,O=Array.isArray(K)?K[0]:null,T=Array.isArray(K)?K[1]:typeof K=="number"?K:null;function ee(t){let s=t*100;switch(B){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 E=B?[]:Array.from(e.querySelectorAll(o)),v=[],W=[],G=0,_=0,$=false,I=false,S=0,pe=false,z=-1,de=-1,k=false,te=0,V=0,U,$e=null,X=new Set,ye=-1,Ne=performance.now();function ue(){return L?P==="x"?L.scrollLeft:L.scrollTop:P==="x"?window.scrollX:window.scrollY}function He(){return L?P==="x"?L.clientWidth:L.clientHeight:P==="x"?window.innerWidth:window.innerHeight}function We(){let t=e.getBoundingClientRect(),s,l,h;if(L){let D=L.getBoundingClientRect();s=P==="x"?t.left-D.left+L.scrollLeft:t.top-D.top+L.scrollTop,l=P==="x"?t.width:t.height,h=ue();}else s=P==="x"?t.left:t.top,l=P==="x"?t.width:t.height,h=ue();let C=De({top:s,height:l},h,He(),Ie,Re);G=C.tStart,_=C.tEnd,oe&&process.env.NODE_ENV!=="production"&&($e?.remove(),$e=at(G,_,P));}function Qe(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),B){let l=s==="reverse"?1-t:t;e.style.clipPath=ee(l);return}E.forEach((l,h)=>{l.style.strokeDashoffset=s==="reverse"?`${v[h]*t}`:`${v[h]*(1-t)}`,p&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),H&&M?l.style.stroke=ve(H,M,t):M&&(l.style.stroke=M),F!==null&&A!==null?l.style.strokeWidth=`${F+(A-F)*t}`:A!==null&&(l.style.strokeWidth=`${A}`),O!==null&&T!==null?l.style.fillOpacity=`${O+(T-O)*t}`:T!==null&&(l.style.fillOpacity=`${T}`),N&&l.tagName.toLowerCase()==="path"&&W[h]&&l.setAttribute("d",Pe(W[h],N,t));});}function ge(){if(e.style.setProperty("--scroll-draw-progress","0"),B){e.style.clipPath=ee(0);return}E.forEach((t,s)=>{t.style.strokeDasharray=`${v[s]}`,t.style.strokeDashoffset=u==="reverse"?"0":`${v[s]}`,p?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),F!==null&&(t.style.strokeWidth=`${F}`),O!==null&&(t.style.fillOpacity=`${O}`),N&&t.tagName.toLowerCase()==="path"&&W[s]&&t.setAttribute("d",W[s]);});}if(E.forEach(t=>{it(t);let s=we(t);v.push(s),t.tagName.toLowerCase()==="path"?W.push(t.getAttribute("d")??""):W.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?`${s}`:"0",p&&(t.style.opacity="1"),M&&(t.style.stroke=M),A!==null&&(t.style.strokeWidth=`${A}`),T!==null&&(t.style.fillOpacity=`${T}`),N&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",N)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?"0":`${s}`,p?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),F!==null&&(t.style.strokeWidth=`${F}`),O!==null&&(t.style.fillOpacity=`${O}`));}),B){if(n)return e.style.clipPath=ee(1),se?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=ee(0);}else if(n)return se?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ye(){return !(Ke===false||!st()||!E.length||typeof b!="string"||!(b in Ge)||B||P!=="y"||L||m!==1||R!==0||g||ce||fe!==false||N||Q||Y||ae>0||le||me||se||j!=null||J!=null||K!=null||(x.start??"top bottom").trim()!=="top bottom"||(x.end??"bottom top").trim()!=="bottom top")}function Ze(){let t=`svg-scroll-draw-${++ot}`,s=u==="reverse"?"0":"var(--ssd-len)",l=u==="reverse"?"var(--ssd-len)":"0",h=`stroke-dashoffset:${s};`,C=`stroke-dashoffset:${l};`;p&&(h+=`opacity:${u==="reverse"?1:0};`,C+=`opacity:${u==="reverse"?0:1};`);let D=document.createElement("style");D.setAttribute("data-svg-scroll-draw",""),D.textContent=`@keyframes ${t}{from{${h}}to{${C}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ge[b]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(D);function a(i,f){i.style.setProperty("--ssd-len",String(v[f])),i.style.strokeDasharray=`${v[f]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}E.forEach(a);let d=false,w=-1;function c(){if(w>=0)return w;let i=e.getBoundingClientRect(),{tStart:f,tEnd:y}=De({top:i.top,height:i.height},ue(),He(),Ie,Re);return Z(ne(ue(),f,y,m))}return {destroy(){E.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),D.remove();},replay(){d=false,w=-1,E.forEach(a);},pause(){d=true,E.forEach(i=>{i.style.animationPlayState="paused";});},resume(){d&&(d=false,E.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let f=Math.min(1,Math.max(0,i));w=f,d=true,E.forEach((y,re)=>{y.classList.remove(t),y.style.strokeDashoffset=u==="reverse"?`${v[re]*f}`:`${v[re]*(1-f)}`,p&&(y.style.opacity=u==="reverse"?`${1-f}`:`${f}`);});},getProgress(){return c()}}}if(Ye())return Ze();function et(){let t=Math.max(1,Je),s=0,l=0;function h(c){let i=true;if(B){let f=Math.min(1,Math.max(0,c/t)),y=Z(f);te=y,e.style.setProperty("--scroll-draw-progress",String(y)),e.style.clipPath=ee(u==="reverse"?1-y:y),le?.(y),f<1&&(i=false);}else E.forEach((f,y)=>{let re=y*R*t,ie=Math.min(1,Math.max(0,(c-re)/t)),q=Z(ie);f.style.strokeDashoffset=u==="reverse"?`${v[y]*q}`:`${v[y]*(1-q)}`,p&&(f.style.opacity=u==="reverse"?`${1-q}`:`${q}`),H&&M?f.style.stroke=ve(H,M,q):M&&(f.style.stroke=M),F!==null&&A!==null?f.style.strokeWidth=`${F+(A-F)*q}`:A!==null&&(f.style.strokeWidth=`${A}`),O!==null&&T!==null?f.style.fillOpacity=`${O+(T-O)*q}`:T!==null&&(f.style.fillOpacity=`${T}`),N&&f.tagName.toLowerCase()==="path"&&W[y]&&f.setAttribute("d",Pe(W[y],N,q)),y===0&&(le?.(q),e.style.setProperty("--scroll-draw-progress",String(q))),ie<1&&(i=false);});if(Q){let f=Math.min(1,Math.max(0,c/t)),y=Z(f);for(let re in Q){let ie=parseFloat(re);y>=ie&&!X.has(ie)&&(X.add(ie),Q[re]?.());}}return i}function C(c){if(k)return;let i=c-s;I||(I=true,me?.());let f=h(i);if(f&&!$){$=true,h(t*(1+Math.max(0,E.length-1)*R)),se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{s=performance.now(),I=false,$=false,X.clear(),ge(),S=requestAnimationFrame(C);},xe));return}f||(S=requestAnimationFrame(C));}function D(){cancelAnimationFrame(S),clearTimeout(U),s=performance.now(),l=0,k=false,I=false,$=false,V=0,X.clear(),ge(),S=requestAnimationFrame(C);}let a=new IntersectionObserver(c=>{c.forEach(i=>{i.isIntersecting&&!(g&&$)?D():!i.isIntersecting&&!g&&!$&&(cancelAnimationFrame(S),clearTimeout(U),s=null);});},{root:L??null,threshold:Oe,rootMargin:Ce}),d;function w(){clearTimeout(d),d=setTimeout(()=>{E.forEach((c,i)=>{v[i]=we(c),c.style.strokeDasharray=`${v[i]}`;});},150);}return window.addEventListener("resize",w),window.addEventListener("orientationchange",w),ae>0?setTimeout(()=>a.observe(e),ae):a.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(U),a.disconnect(),window.removeEventListener("resize",w),window.removeEventListener("orientationchange",w),clearTimeout(d);},replay(){V=0,D();},pause(){k||(k=true,l=performance.now()-s,cancelAnimationFrame(S));},resume(){k&&(k=false,s=performance.now()-l,S=requestAnimationFrame(C));},seek(c){let i=Math.min(1,Math.max(0,c));te=i,k=true,l=i*t,s=performance.now()-l,cancelAnimationFrame(S),h(l);},getProgress(){return te}}}if(je)return et();We();function he(){if(!pe||k)return;let t=performance.now(),s=ue(),l=m;if(fe!==false){let a=t-Ne,d=a>0?Math.abs(s-(ye<0?s:ye))/a:0;l=m*Math.max(.2,1+d*(typeof fe=="number"?fe:1)*.04);}ye=s,Ne=t;let h=ce?de===-1||s>=de?"forward":"reverse":u;de=s;let C=_-G,D=true;if(B){let a=Z(ne(s,G,_,l));g&&!ce&&(z=Math.max(z,a),a=z),te=a,e.style.setProperty("--scroll-draw-progress",String(a));let d=h==="reverse"?1-a:a;e.style.clipPath=ee(d),le?.(a),!I&&ne(s,G,_,l)>0&&(I=true,me?.()),a>=1&&!$?($=true,se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{z=-1,I=false,$=false,e.style.clipPath=ee(0);},xe))):a<1&&!g&&($=false),S=requestAnimationFrame(he);return}if(E.forEach((a,d)=>{let w=d*R*C,c=Z(ne(s,G+w,_+w,l));g&&!ce&&(z=Math.max(z,c),c=z),te=c,a.style.strokeDashoffset=h==="reverse"?`${v[d]*c}`:`${v[d]*(1-c)}`,p&&(a.style.opacity=h==="reverse"?`${1-c}`:`${c}`),H&&M?a.style.stroke=ve(H,M,c):M&&(a.style.stroke=M),F!==null&&A!==null?a.style.strokeWidth=`${F+(A-F)*c}`:A!==null&&(a.style.strokeWidth=`${A}`),O!==null&&T!==null?a.style.fillOpacity=`${O+(T-O)*c}`:T!==null&&(a.style.fillOpacity=`${T}`),N&&a.tagName.toLowerCase()==="path"&&W[d]&&a.setAttribute("d",Pe(W[d],N,c)),d===0&&(le?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(D=false);}),Q){let a=Z(ne(s,G,_,l));for(let d in Q){let w=parseFloat(d);a>=w&&!X.has(w)&&(X.add(w),Q[d]?.());}}!I&&ne(s,G,_,l)>0&&(I=true,me?.()),D&&!$?($=true,se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{z=-1,I=false,$=false,X.clear(),ge();},xe))):!D&&!g&&($=false),S=requestAnimationFrame(he);}let Me=new IntersectionObserver(t=>{t.forEach(s=>{pe=s.isIntersecting,pe&&!k?S=requestAnimationFrame(he):cancelAnimationFrame(S);});},{root:L??null,threshold:Oe,rootMargin:Ce}),Ae;function be(){clearTimeout(Ae),Ae=setTimeout(()=>{E.forEach((t,s)=>{v[s]=we(t),t.style.strokeDasharray=`${v[s]}`;}),We();},150);}return window.addEventListener("resize",be),window.addEventListener("orientationchange",be),ae>0?setTimeout(()=>Me.observe(e),ae):Me.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(U),Me.disconnect(),window.removeEventListener("resize",be),window.removeEventListener("orientationchange",be),clearTimeout(Ae),$e?.remove();},replay(){z=-1,de=-1,ye=-1,I=false,$=false,V=0,k=false,X.clear(),clearTimeout(U),ge();},pause(){k=true,cancelAnimationFrame(S);},resume(){k&&(k=false,pe&&(S=requestAnimationFrame(he)));},seek(t){let s=Math.min(1,Math.max(0,t));te=s,z=s,k=true,cancelAnimationFrame(S),Qe(s,u);},getProgress(){return te}}}function ct(e={}){let r=vue.ref(null);return vue.onMounted(()=>{if(!r.value)return;let n=Le(r.value,e);vue.onUnmounted(()=>n.destroy());}),r}var Fe=vue.defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:r}){let n=vue.ref(null);return vue.onMounted(()=>{if(!n.value)return;let o={};e.selector!=null&&(o.selector=e.selector),e.speed!=null&&(o.speed=e.speed),e.fade!=null&&(o.fade=e.fade),e.stagger!=null&&(o.stagger=e.stagger),e.easing!=null&&(o.easing=e.easing),e.direction!=null&&(o.direction=e.direction),e.trigger!=null&&(o.trigger=e.trigger),e.once!=null&&(o.once=e.once),e.debug!=null&&(o.debug=e.debug),e.onProgress!=null&&(o.onProgress=e.onProgress),e.onStart!=null&&(o.onStart=e.onStart),e.onComplete!=null&&(o.onComplete=e.onComplete);let m=Le(n.value,o);vue.onUnmounted(()=>m.destroy());}),()=>vue.h("div",{ref:n},r.default?.())}});function bt(){return {install(e){e.component("ScrollDraw",Fe);}}}exports.ScrollDraw=Fe;exports.createScrollDrawPlugin=bt;exports.useScrollDraw=ct;
|
package/dist/nuxt/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -63,6 +63,25 @@ interface ScrollDrawOptions {
|
|
|
63
63
|
onProgress?: (alpha: number) => void;
|
|
64
64
|
onStart?: () => void;
|
|
65
65
|
onComplete?: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Trigger the animation when the element enters the viewport instead of
|
|
68
|
+
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
69
|
+
* replaying each time the element re-enters the viewport (use `once: true`
|
|
70
|
+
* to play only the first time).
|
|
71
|
+
*
|
|
72
|
+
* All visual options work in autoplay mode — `easing`, `stagger`, `fade`,
|
|
73
|
+
* `strokeColor`, `strokeWidth`, `fillOpacity`, `clip`, `morphTo`, `waypoints`,
|
|
74
|
+
* `repeat`, `repeatDelay`, `onStart`, `onComplete`, `onProgress`, etc.
|
|
75
|
+
*
|
|
76
|
+
* The full instance API (`pause`, `resume`, `seek`, `replay`, `getProgress`)
|
|
77
|
+
* also works — `seek(0.5)` pauses at 50% of the duration.
|
|
78
|
+
*/
|
|
79
|
+
autoplay?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Duration of the autoplay animation in milliseconds. Only used when
|
|
82
|
+
* `autoplay: true`. Default `1000`.
|
|
83
|
+
*/
|
|
84
|
+
duration?: number;
|
|
66
85
|
/**
|
|
67
86
|
* Use the browser's native CSS scroll-driven animation
|
|
68
87
|
* (`animation-timeline: view()`) when the configuration is simple enough and
|
package/dist/nuxt/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -63,6 +63,25 @@ interface ScrollDrawOptions {
|
|
|
63
63
|
onProgress?: (alpha: number) => void;
|
|
64
64
|
onStart?: () => void;
|
|
65
65
|
onComplete?: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Trigger the animation when the element enters the viewport instead of
|
|
68
|
+
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
69
|
+
* replaying each time the element re-enters the viewport (use `once: true`
|
|
70
|
+
* to play only the first time).
|
|
71
|
+
*
|
|
72
|
+
* All visual options work in autoplay mode — `easing`, `stagger`, `fade`,
|
|
73
|
+
* `strokeColor`, `strokeWidth`, `fillOpacity`, `clip`, `morphTo`, `waypoints`,
|
|
74
|
+
* `repeat`, `repeatDelay`, `onStart`, `onComplete`, `onProgress`, etc.
|
|
75
|
+
*
|
|
76
|
+
* The full instance API (`pause`, `resume`, `seek`, `replay`, `getProgress`)
|
|
77
|
+
* also works — `seek(0.5)` pauses at 50% of the duration.
|
|
78
|
+
*/
|
|
79
|
+
autoplay?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Duration of the autoplay animation in milliseconds. Only used when
|
|
82
|
+
* `autoplay: true`. Default `1000`.
|
|
83
|
+
*/
|
|
84
|
+
duration?: number;
|
|
66
85
|
/**
|
|
67
86
|
* Use the browser's native CSS scroll-driven animation
|
|
68
87
|
* (`animation-timeline: view()`) when the configuration is simple enough and
|
package/dist/nuxt/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {defineComponent,ref,onMounted,onUnmounted,h}from'vue';var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${U?`left:${M}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${M}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(n),window.addEventListener("scroll",a,{passive:true}),a(),n}function Ve(e,r,o){let n=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,d=>{let m=parseFloat(d),M=n[a++]??m;return String(+(m+(M-m)*o).toFixed(4))})}function xe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let o=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:n="path, polyline, line, polygon, rect, circle",speed:a=1,fade:d=false,easing:m="linear",trigger:M={},stagger:U=0,direction:y="forward",once:X=false,debug:Be=false,axis:S="y",scrollContainer:ce,autoReverse:Z=false,delay:me=0,strokeColor:R,strokeWidth:H,fillOpacity:V,waypoints:ee,velocityScale:te=false,threshold:qe=0,rootMargin:_e="0px",repeat:j=0,repeatDelay:Ae=0,morphTo:L,clip:pe,native:Ue=true,onProgress:de,onStart:ye,onComplete:J}=r,W=pe===true?"left":typeof pe=="string"?pe:false,re=typeof m=="function"?m:we[m]??we.linear,Te=ve(M.start??"top bottom"),De=ve(M.end??"bottom top"),b=typeof ce=="string"?document.querySelector(ce):ce??null,C=Array.isArray(R)?R[0]:null,$=Array.isArray(R)?R[1]:typeof R=="string"?R:null,E=Array.isArray(H)?H[0]:null,x=Array.isArray(H)?H[1]:typeof H=="number"?H:null,k=Array.isArray(V)?V[0]:null,A=Array.isArray(V)?V[1]:typeof V=="number"?V:null;function _(t){let s=t*100;switch(W){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 w=W?[]:Array.from(e.querySelectorAll(n)),g=[],O=[],F=0,I=0,P=false,G=false,N=0,ne=false,T=-1,oe=-1,z=false,se=0,K=0,ie,ge=null,le=new Set,ae=-1,Me=performance.now();function Q(){return b?S==="x"?b.scrollLeft:b.scrollTop:S==="x"?window.scrollX:window.scrollY}function Pe(){return b?S==="x"?b.clientWidth:b.clientHeight:S==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),s,l,p;if(b){let v=b.getBoundingClientRect();s=S==="x"?t.left-v.left+b.scrollLeft:t.top-v.top+b.scrollTop,l=S==="x"?t.width:t.height,p=Q();}else s=S==="x"?t.left:t.top,l=S==="x"?t.width:t.height,p=Q();let B=$e({top:s,height:l},p,Pe(),Te,De);F=B.tStart,I=B.tEnd,Be&&process.env.NODE_ENV!=="production"&&(ge?.remove(),ge=et(F,I,S));}function Xe(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),W){let l=s==="reverse"?1-t:t;e.style.clipPath=_(l);return}w.forEach((l,p)=>{l.style.strokeDashoffset=s==="reverse"?`${g[p]*t}`:`${g[p]*(1-t)}`,d&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),C&&$?l.style.stroke=Ee(C,$,t):$&&(l.style.stroke=$),E!==null&&x!==null?l.style.strokeWidth=`${E+(x-E)*t}`:x!==null&&(l.style.strokeWidth=`${x}`),k!==null&&A!==null?l.style.fillOpacity=`${k+(A-k)*t}`:A!==null&&(l.style.fillOpacity=`${A}`),L&&l.tagName.toLowerCase()==="path"&&O[p]&&l.setAttribute("d",Ve(O[p],L,t));});}function Ce(){if(e.style.setProperty("--scroll-draw-progress","0"),W){e.style.clipPath=_(0);return}w.forEach((t,s)=>{t.style.strokeDasharray=`${g[s]}`,t.style.strokeDashoffset=y==="reverse"?"0":`${g[s]}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),E!==null&&(t.style.strokeWidth=`${E}`),k!==null&&(t.style.fillOpacity=`${k}`),L&&t.tagName.toLowerCase()==="path"&&O[s]&&t.setAttribute("d",O[s]);});}if(w.forEach(t=>{Ze(t);let s=Se(t);g.push(s),t.tagName.toLowerCase()==="path"?O.push(t.getAttribute("d")??""):O.push(""),o?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?`${s}`:"0",d&&(t.style.opacity="1"),$&&(t.style.stroke=$),x!==null&&(t.style.strokeWidth=`${x}`),A!==null&&(t.style.fillOpacity=`${A}`),L&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",L)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?"0":`${s}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),E!==null&&(t.style.strokeWidth=`${E}`),k!==null&&(t.style.fillOpacity=`${k}`));}),W){if(o)return e.style.clipPath=_(1),J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=_(0);}else if(o)return J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function je(){return !(Ue===false||!Ye()||!w.length||typeof m!="string"||!(m in He)||W||S!=="y"||b||a!==1||U!==0||X||Z||te!==false||L||ee||j||me>0||de||ye||J||R!=null||H!=null||V!=null||(M.start??"top bottom").trim()!=="top bottom"||(M.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++Qe}`,s=y==="reverse"?"0":"var(--ssd-len)",l=y==="reverse"?"var(--ssd-len)":"0",p=`stroke-dashoffset:${s};`,B=`stroke-dashoffset:${l};`;d&&(p+=`opacity:${y==="reverse"?1:0};`,B+=`opacity:${y==="reverse"?0:1};`);let v=document.createElement("style");v.setAttribute("data-svg-scroll-draw",""),v.textContent=`@keyframes ${t}{from{${p}}to{${B}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${He[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(v);function i(f,D){f.style.setProperty("--ssd-len",String(g[D])),f.style.strokeDasharray=`${g[D]}`,f.style.strokeDashoffset="",f.style.opacity="",f.style.animationPlayState="",f.classList.add(t);}w.forEach(i);let u=false,h=-1;function c(){if(h>=0)return h;let f=e.getBoundingClientRect(),{tStart:D,tEnd:Y}=$e({top:f.top,height:f.height},Q(),Pe(),Te,De);return re(q(Q(),D,Y,a))}return {destroy(){w.forEach(f=>{f.classList.remove(t),f.style.removeProperty("--ssd-len"),f.style.animationPlayState="";}),v.remove();},replay(){u=false,h=-1,w.forEach(i);},pause(){u=true,w.forEach(f=>{f.style.animationPlayState="paused";});},resume(){u&&(u=false,w.forEach(f=>{f.style.animationPlayState="running";}));},seek(f){let D=Math.min(1,Math.max(0,f));h=D,u=true,w.forEach((Y,Oe)=>{Y.classList.remove(t),Y.style.strokeDashoffset=y==="reverse"?`${g[Oe]*D}`:`${g[Oe]*(1-D)}`,d&&(Y.style.opacity=y==="reverse"?`${1-D}`:`${D}`);});},getProgress(){return c()}}}if(je())return Je();Le();function ue(){if(!ne||z)return;let t=performance.now(),s=Q(),l=a;if(te!==false){let i=t-Me,u=i>0?Math.abs(s-(ae<0?s:ae))/i:0;l=a*Math.max(.2,1+u*(typeof te=="number"?te:1)*.04);}ae=s,Me=t;let p=Z?oe===-1||s>=oe?"forward":"reverse":y;oe=s;let B=I-F,v=true;if(W){let i=re(q(s,F,I,l));X&&!Z&&(T=Math.max(T,i),i=T),se=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=p==="reverse"?1-i:i;e.style.clipPath=_(u),de?.(i),!G&&q(s,F,I,l)>0&&(G=true,ye?.()),i>=1&&!P?(P=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{T=-1,G=false,P=false,e.style.clipPath=_(0);},Ae))):i<1&&!X&&(P=false),N=requestAnimationFrame(ue);return}if(w.forEach((i,u)=>{let h=u*U*B,c=re(q(s,F+h,I+h,l));X&&!Z&&(T=Math.max(T,c),c=T),se=c,i.style.strokeDashoffset=p==="reverse"?`${g[u]*c}`:`${g[u]*(1-c)}`,d&&(i.style.opacity=p==="reverse"?`${1-c}`:`${c}`),C&&$?i.style.stroke=Ee(C,$,c):$&&(i.style.stroke=$),E!==null&&x!==null?i.style.strokeWidth=`${E+(x-E)*c}`:x!==null&&(i.style.strokeWidth=`${x}`),k!==null&&A!==null?i.style.fillOpacity=`${k+(A-k)*c}`:A!==null&&(i.style.fillOpacity=`${A}`),L&&i.tagName.toLowerCase()==="path"&&O[u]&&i.setAttribute("d",Ve(O[u],L,c)),u===0&&(de?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(v=false);}),ee){let i=re(q(s,F,I,l));for(let u in ee){let h=parseFloat(u);i>=h&&!le.has(h)&&(le.add(h),ee[u]?.());}}!G&&q(s,F,I,l)>0&&(G=true,ye?.()),v&&!P?(P=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{T=-1,G=false,P=false,le.clear(),Ce();},Ae))):!v&&!X&&(P=false),N=requestAnimationFrame(ue);}let he=new IntersectionObserver(t=>{t.forEach(s=>{ne=s.isIntersecting,ne&&!z?N=requestAnimationFrame(ue):cancelAnimationFrame(N);});},{root:b??null,threshold:qe,rootMargin:_e}),be;function fe(){clearTimeout(be),be=setTimeout(()=>{w.forEach((t,s)=>{g[s]=Se(t),t.style.strokeDasharray=`${g[s]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),me>0?setTimeout(()=>he.observe(e),me):he.observe(e),{destroy(){cancelAnimationFrame(N),clearTimeout(ie),he.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(be),ge?.remove();},replay(){T=-1,oe=-1,ae=-1,G=false,P=false,K=0,z=false,le.clear(),clearTimeout(ie),Ce();},pause(){z=true,cancelAnimationFrame(N);},resume(){z&&(z=false,ne&&(N=requestAnimationFrame(ue)));},seek(t){let s=Math.min(1,Math.max(0,t));se=s,T=s,z=true,cancelAnimationFrame(N),Xe(s,y);},getProgress(){return se}}}function nt(e={}){let r=ref(null);return onMounted(()=>{if(!r.value)return;let o=xe(r.value,e);onUnmounted(()=>o.destroy());}),r}var ke=defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:r}){let o=ref(null);return onMounted(()=>{if(!o.value)return;let n={};e.selector!=null&&(n.selector=e.selector),e.speed!=null&&(n.speed=e.speed),e.fade!=null&&(n.fade=e.fade),e.stagger!=null&&(n.stagger=e.stagger),e.easing!=null&&(n.easing=e.easing),e.direction!=null&&(n.direction=e.direction),e.trigger!=null&&(n.trigger=e.trigger),e.once!=null&&(n.once=e.once),e.debug!=null&&(n.debug=e.debug),e.onProgress!=null&&(n.onProgress=e.onProgress),e.onStart!=null&&(n.onStart=e.onStart),e.onComplete!=null&&(n.onComplete=e.onComplete);let a=xe(o.value,n);onUnmounted(()=>a.destroy());}),()=>h("div",{ref:o},r.default?.())}});function ct(){return {install(e){e.component("ScrollDraw",ke);}}}export{ke as ScrollDraw,ct as createScrollDrawPlugin,nt as useScrollDraw};
|
|
1
|
+
import {defineComponent,ref,onMounted,onUnmounted,h}from'vue';function tt({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),m=Math.sqrt(o),p=0,b=[];for(let u=0;u<n;u++){let g=Math.pow(m,u);b.push(g),p+=g;}let x=[0],R=0;for(let u=0;u<n;u++)R+=b[u]/p,x.push(R);return u=>{if(u<=0)return 0;if(u>=1)return 1;for(let g=0;g<n;g++)if(u<=x[g+1]){let oe=(u-x[g])/(x[g+1]-x[g]);if(g===0)return oe*(2-oe);let P=1-Math.pow(o,g);return P+(1-P)*(2*oe-1)*(2*oe-1)}return 1}}function rt({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),o=Math.max(.1,r),m=n<=1?o/4:o/(2*Math.PI)*Math.asin(1/n);return p=>p<=0?0:p>=1?1:n*Math.pow(2,-10*p)*Math.sin((p-m)*(2*Math.PI)/o)+1}var Te={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:rt()};function ke(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",o="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:o}}function ze(e,r,n,o){switch(o){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function qe(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 we(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(n+o)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function nt(e,r,n){return Math.min(n,Math.max(r,e))}function ne(e,r,n,o){return n===r?0:nt((e-r)/(n-r)*o,0,1)}function De(e,r,n,o,m){let p=ze(e.top,e.height,r,o.element)-qe(o.viewport,n),b=ze(e.top,e.height,r,m.element)-qe(m.viewport,n);return {tStart:p,tEnd:b}}function Ve(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 o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function ve(e,r,n){let o=Ve(e),m=Ve(r);return !o||!m?e:`rgb(${Math.round(o[0]+(m[0]-o[0])*n)},${Math.round(o[1]+(m[1]-o[1])*n)},${Math.round(o[2]+(m[2]-o[2])*n)})`}function Be(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ge={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},ot=0;function st(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function it(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Be("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Be("Element has a fill \u2014 it may obscure the stroke animation.",e);}function at(e,r,n){let o=document.createElement("div");o.setAttribute("data-svg-scroll-draw-debug",""),o.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 m(){let p=n==="x"?window.scrollX:window.scrollY,b=e-p,x=r-p,R=n==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${R?`left:${b}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${b}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;${R?`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",m,{passive:true}),m(),o}function Pe(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),m=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,p=>{let b=parseFloat(p),x=o[m++]??b;return String(+(b+(x-b)*n).toFixed(4))})}function Le(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:m=1,fade:p=false,easing:b="linear",trigger:x={},stagger:R=0,direction:u="forward",once:g=false,debug:oe=false,axis:P="y",scrollContainer:Se,autoReverse:ce=false,delay:ae=0,strokeColor:j,strokeWidth:J,fillOpacity:K,waypoints:Q,velocityScale:fe=false,threshold:Oe=0,rootMargin:Ce="0px",repeat:Y=0,repeatDelay:xe=0,morphTo:N,clip:Ee,autoplay:je=false,duration:Je=1e3,native:Ke=true,onProgress:le,onStart:me,onComplete:se}=r,B=Ee===true?"left":typeof Ee=="string"?Ee:false,Z=typeof b=="function"?b:Te[b]??Te.linear,Ie=ke(x.start??"top bottom"),Re=ke(x.end??"bottom top"),L=typeof Se=="string"?document.querySelector(Se):Se??null,H=Array.isArray(j)?j[0]:null,M=Array.isArray(j)?j[1]:typeof j=="string"?j:null,F=Array.isArray(J)?J[0]:null,A=Array.isArray(J)?J[1]:typeof J=="number"?J:null,O=Array.isArray(K)?K[0]:null,T=Array.isArray(K)?K[1]:typeof K=="number"?K:null;function ee(t){let s=t*100;switch(B){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 E=B?[]:Array.from(e.querySelectorAll(o)),v=[],W=[],G=0,_=0,$=false,I=false,S=0,pe=false,z=-1,de=-1,k=false,te=0,V=0,U,$e=null,X=new Set,ye=-1,Ne=performance.now();function ue(){return L?P==="x"?L.scrollLeft:L.scrollTop:P==="x"?window.scrollX:window.scrollY}function He(){return L?P==="x"?L.clientWidth:L.clientHeight:P==="x"?window.innerWidth:window.innerHeight}function We(){let t=e.getBoundingClientRect(),s,l,h;if(L){let D=L.getBoundingClientRect();s=P==="x"?t.left-D.left+L.scrollLeft:t.top-D.top+L.scrollTop,l=P==="x"?t.width:t.height,h=ue();}else s=P==="x"?t.left:t.top,l=P==="x"?t.width:t.height,h=ue();let C=De({top:s,height:l},h,He(),Ie,Re);G=C.tStart,_=C.tEnd,oe&&process.env.NODE_ENV!=="production"&&($e?.remove(),$e=at(G,_,P));}function Qe(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),B){let l=s==="reverse"?1-t:t;e.style.clipPath=ee(l);return}E.forEach((l,h)=>{l.style.strokeDashoffset=s==="reverse"?`${v[h]*t}`:`${v[h]*(1-t)}`,p&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),H&&M?l.style.stroke=ve(H,M,t):M&&(l.style.stroke=M),F!==null&&A!==null?l.style.strokeWidth=`${F+(A-F)*t}`:A!==null&&(l.style.strokeWidth=`${A}`),O!==null&&T!==null?l.style.fillOpacity=`${O+(T-O)*t}`:T!==null&&(l.style.fillOpacity=`${T}`),N&&l.tagName.toLowerCase()==="path"&&W[h]&&l.setAttribute("d",Pe(W[h],N,t));});}function ge(){if(e.style.setProperty("--scroll-draw-progress","0"),B){e.style.clipPath=ee(0);return}E.forEach((t,s)=>{t.style.strokeDasharray=`${v[s]}`,t.style.strokeDashoffset=u==="reverse"?"0":`${v[s]}`,p?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),F!==null&&(t.style.strokeWidth=`${F}`),O!==null&&(t.style.fillOpacity=`${O}`),N&&t.tagName.toLowerCase()==="path"&&W[s]&&t.setAttribute("d",W[s]);});}if(E.forEach(t=>{it(t);let s=we(t);v.push(s),t.tagName.toLowerCase()==="path"?W.push(t.getAttribute("d")??""):W.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?`${s}`:"0",p&&(t.style.opacity="1"),M&&(t.style.stroke=M),A!==null&&(t.style.strokeWidth=`${A}`),T!==null&&(t.style.fillOpacity=`${T}`),N&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",N)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?"0":`${s}`,p?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),F!==null&&(t.style.strokeWidth=`${F}`),O!==null&&(t.style.fillOpacity=`${O}`));}),B){if(n)return e.style.clipPath=ee(1),se?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=ee(0);}else if(n)return se?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ye(){return !(Ke===false||!st()||!E.length||typeof b!="string"||!(b in Ge)||B||P!=="y"||L||m!==1||R!==0||g||ce||fe!==false||N||Q||Y||ae>0||le||me||se||j!=null||J!=null||K!=null||(x.start??"top bottom").trim()!=="top bottom"||(x.end??"bottom top").trim()!=="bottom top")}function Ze(){let t=`svg-scroll-draw-${++ot}`,s=u==="reverse"?"0":"var(--ssd-len)",l=u==="reverse"?"var(--ssd-len)":"0",h=`stroke-dashoffset:${s};`,C=`stroke-dashoffset:${l};`;p&&(h+=`opacity:${u==="reverse"?1:0};`,C+=`opacity:${u==="reverse"?0:1};`);let D=document.createElement("style");D.setAttribute("data-svg-scroll-draw",""),D.textContent=`@keyframes ${t}{from{${h}}to{${C}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ge[b]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(D);function a(i,f){i.style.setProperty("--ssd-len",String(v[f])),i.style.strokeDasharray=`${v[f]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}E.forEach(a);let d=false,w=-1;function c(){if(w>=0)return w;let i=e.getBoundingClientRect(),{tStart:f,tEnd:y}=De({top:i.top,height:i.height},ue(),He(),Ie,Re);return Z(ne(ue(),f,y,m))}return {destroy(){E.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),D.remove();},replay(){d=false,w=-1,E.forEach(a);},pause(){d=true,E.forEach(i=>{i.style.animationPlayState="paused";});},resume(){d&&(d=false,E.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let f=Math.min(1,Math.max(0,i));w=f,d=true,E.forEach((y,re)=>{y.classList.remove(t),y.style.strokeDashoffset=u==="reverse"?`${v[re]*f}`:`${v[re]*(1-f)}`,p&&(y.style.opacity=u==="reverse"?`${1-f}`:`${f}`);});},getProgress(){return c()}}}if(Ye())return Ze();function et(){let t=Math.max(1,Je),s=0,l=0;function h(c){let i=true;if(B){let f=Math.min(1,Math.max(0,c/t)),y=Z(f);te=y,e.style.setProperty("--scroll-draw-progress",String(y)),e.style.clipPath=ee(u==="reverse"?1-y:y),le?.(y),f<1&&(i=false);}else E.forEach((f,y)=>{let re=y*R*t,ie=Math.min(1,Math.max(0,(c-re)/t)),q=Z(ie);f.style.strokeDashoffset=u==="reverse"?`${v[y]*q}`:`${v[y]*(1-q)}`,p&&(f.style.opacity=u==="reverse"?`${1-q}`:`${q}`),H&&M?f.style.stroke=ve(H,M,q):M&&(f.style.stroke=M),F!==null&&A!==null?f.style.strokeWidth=`${F+(A-F)*q}`:A!==null&&(f.style.strokeWidth=`${A}`),O!==null&&T!==null?f.style.fillOpacity=`${O+(T-O)*q}`:T!==null&&(f.style.fillOpacity=`${T}`),N&&f.tagName.toLowerCase()==="path"&&W[y]&&f.setAttribute("d",Pe(W[y],N,q)),y===0&&(le?.(q),e.style.setProperty("--scroll-draw-progress",String(q))),ie<1&&(i=false);});if(Q){let f=Math.min(1,Math.max(0,c/t)),y=Z(f);for(let re in Q){let ie=parseFloat(re);y>=ie&&!X.has(ie)&&(X.add(ie),Q[re]?.());}}return i}function C(c){if(k)return;let i=c-s;I||(I=true,me?.());let f=h(i);if(f&&!$){$=true,h(t*(1+Math.max(0,E.length-1)*R)),se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{s=performance.now(),I=false,$=false,X.clear(),ge(),S=requestAnimationFrame(C);},xe));return}f||(S=requestAnimationFrame(C));}function D(){cancelAnimationFrame(S),clearTimeout(U),s=performance.now(),l=0,k=false,I=false,$=false,V=0,X.clear(),ge(),S=requestAnimationFrame(C);}let a=new IntersectionObserver(c=>{c.forEach(i=>{i.isIntersecting&&!(g&&$)?D():!i.isIntersecting&&!g&&!$&&(cancelAnimationFrame(S),clearTimeout(U),s=null);});},{root:L??null,threshold:Oe,rootMargin:Ce}),d;function w(){clearTimeout(d),d=setTimeout(()=>{E.forEach((c,i)=>{v[i]=we(c),c.style.strokeDasharray=`${v[i]}`;});},150);}return window.addEventListener("resize",w),window.addEventListener("orientationchange",w),ae>0?setTimeout(()=>a.observe(e),ae):a.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(U),a.disconnect(),window.removeEventListener("resize",w),window.removeEventListener("orientationchange",w),clearTimeout(d);},replay(){V=0,D();},pause(){k||(k=true,l=performance.now()-s,cancelAnimationFrame(S));},resume(){k&&(k=false,s=performance.now()-l,S=requestAnimationFrame(C));},seek(c){let i=Math.min(1,Math.max(0,c));te=i,k=true,l=i*t,s=performance.now()-l,cancelAnimationFrame(S),h(l);},getProgress(){return te}}}if(je)return et();We();function he(){if(!pe||k)return;let t=performance.now(),s=ue(),l=m;if(fe!==false){let a=t-Ne,d=a>0?Math.abs(s-(ye<0?s:ye))/a:0;l=m*Math.max(.2,1+d*(typeof fe=="number"?fe:1)*.04);}ye=s,Ne=t;let h=ce?de===-1||s>=de?"forward":"reverse":u;de=s;let C=_-G,D=true;if(B){let a=Z(ne(s,G,_,l));g&&!ce&&(z=Math.max(z,a),a=z),te=a,e.style.setProperty("--scroll-draw-progress",String(a));let d=h==="reverse"?1-a:a;e.style.clipPath=ee(d),le?.(a),!I&&ne(s,G,_,l)>0&&(I=true,me?.()),a>=1&&!$?($=true,se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{z=-1,I=false,$=false,e.style.clipPath=ee(0);},xe))):a<1&&!g&&($=false),S=requestAnimationFrame(he);return}if(E.forEach((a,d)=>{let w=d*R*C,c=Z(ne(s,G+w,_+w,l));g&&!ce&&(z=Math.max(z,c),c=z),te=c,a.style.strokeDashoffset=h==="reverse"?`${v[d]*c}`:`${v[d]*(1-c)}`,p&&(a.style.opacity=h==="reverse"?`${1-c}`:`${c}`),H&&M?a.style.stroke=ve(H,M,c):M&&(a.style.stroke=M),F!==null&&A!==null?a.style.strokeWidth=`${F+(A-F)*c}`:A!==null&&(a.style.strokeWidth=`${A}`),O!==null&&T!==null?a.style.fillOpacity=`${O+(T-O)*c}`:T!==null&&(a.style.fillOpacity=`${T}`),N&&a.tagName.toLowerCase()==="path"&&W[d]&&a.setAttribute("d",Pe(W[d],N,c)),d===0&&(le?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(D=false);}),Q){let a=Z(ne(s,G,_,l));for(let d in Q){let w=parseFloat(d);a>=w&&!X.has(w)&&(X.add(w),Q[d]?.());}}!I&&ne(s,G,_,l)>0&&(I=true,me?.()),D&&!$?($=true,se?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,U=setTimeout(()=>{z=-1,I=false,$=false,X.clear(),ge();},xe))):!D&&!g&&($=false),S=requestAnimationFrame(he);}let Me=new IntersectionObserver(t=>{t.forEach(s=>{pe=s.isIntersecting,pe&&!k?S=requestAnimationFrame(he):cancelAnimationFrame(S);});},{root:L??null,threshold:Oe,rootMargin:Ce}),Ae;function be(){clearTimeout(Ae),Ae=setTimeout(()=>{E.forEach((t,s)=>{v[s]=we(t),t.style.strokeDasharray=`${v[s]}`;}),We();},150);}return window.addEventListener("resize",be),window.addEventListener("orientationchange",be),ae>0?setTimeout(()=>Me.observe(e),ae):Me.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(U),Me.disconnect(),window.removeEventListener("resize",be),window.removeEventListener("orientationchange",be),clearTimeout(Ae),$e?.remove();},replay(){z=-1,de=-1,ye=-1,I=false,$=false,V=0,k=false,X.clear(),clearTimeout(U),ge();},pause(){k=true,cancelAnimationFrame(S);},resume(){k&&(k=false,pe&&(S=requestAnimationFrame(he)));},seek(t){let s=Math.min(1,Math.max(0,t));te=s,z=s,k=true,cancelAnimationFrame(S),Qe(s,u);},getProgress(){return te}}}function ct(e={}){let r=ref(null);return onMounted(()=>{if(!r.value)return;let n=Le(r.value,e);onUnmounted(()=>n.destroy());}),r}var Fe=defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:r}){let n=ref(null);return onMounted(()=>{if(!n.value)return;let o={};e.selector!=null&&(o.selector=e.selector),e.speed!=null&&(o.speed=e.speed),e.fade!=null&&(o.fade=e.fade),e.stagger!=null&&(o.stagger=e.stagger),e.easing!=null&&(o.easing=e.easing),e.direction!=null&&(o.direction=e.direction),e.trigger!=null&&(o.trigger=e.trigger),e.once!=null&&(o.once=e.once),e.debug!=null&&(o.debug=e.debug),e.onProgress!=null&&(o.onProgress=e.onProgress),e.onStart!=null&&(o.onStart=e.onStart),e.onComplete!=null&&(o.onComplete=e.onComplete);let m=Le(n.value,o);onUnmounted(()=>m.destroy());}),()=>h("div",{ref:n},r.default?.())}});function bt(){return {install(e){e.component("ScrollDraw",Fe);}}}export{Fe as ScrollDraw,bt as createScrollDrawPlugin,ct as useScrollDraw};
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${v?`left:${w}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${w}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",a,{passive:true}),a(),o}function Ve(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,c=>{let m=parseFloat(c),w=o[a++]??m;return String(+(m+(w-m)*s).toFixed(4))})}function Ge(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let s=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:a=1,fade:c=false,easing:m="linear",trigger:w={},stagger:v=0,direction:p="forward",once:V=false,debug:F=false,axis:E="y",scrollContainer:ae,autoReverse:j=false,delay:re=0,strokeColor:T,strokeWidth:x,fillOpacity:P,waypoints:ne,velocityScale:Y=false,threshold:pe=0,rootMargin:de="0px",repeat:N=0,repeatDelay:J=0,morphTo:d,clip:A,native:le=true,onProgress:K,onStart:G,onComplete:z}=r,Q=A===true?"left":typeof A=="string"?A:false,ye=typeof m=="function"?m:oe[m]??oe.linear,Le=ie(w.start??"top bottom"),Me=ie(w.end??"bottom top"),S=typeof ae=="string"?document.querySelector(ae):ae??null,q=Array.isArray(T)?T[0]:null,L=Array.isArray(T)?T[1]:typeof T=="string"?T:null,M=Array.isArray(x)?x[0]:null,D=Array.isArray(x)?x[1]:typeof x=="number"?x:null,C=Array.isArray(P)?P[0]:null,I=Array.isArray(P)?P[1]:typeof P=="number"?P:null;function se(t){let n=t*100;switch(Q){case "right":return `inset(0 0 0 ${100-n}%)`;case "top":return `inset(0 0 ${100-n}% 0)`;case "bottom":return `inset(${100-n}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-n}% 0 0)`}}let $=Q?[]:Array.from(e.querySelectorAll(o)),h=[],B=[],U=0,X=0,H=false,Z=false,_=0,ge=false,O=-1,he=-1,ee=false,be=0,ce=0,we,$e=null,ve=new Set,Ee=-1,De=performance.now();function ue(){return S?E==="x"?S.scrollLeft:S.scrollTop:E==="x"?window.scrollX:window.scrollY}function Ce(){return S?E==="x"?S.clientWidth:S.clientHeight:E==="x"?window.innerWidth:window.innerHeight}function Ie(){let t=e.getBoundingClientRect(),n,l,g;if(S){let k=S.getBoundingClientRect();n=E==="x"?t.left-k.left+S.scrollLeft:t.top-k.top+S.scrollTop,l=E==="x"?t.width:t.height,g=ue();}else n=E==="x"?t.left:t.top,l=E==="x"?t.width:t.height,g=ue();let te=me({top:n,height:l},g,Ce(),Le,Me);U=te.tStart,X=te.tEnd,F&&process.env.NODE_ENV!=="production"&&($e?.remove(),$e=Ke(U,X,E));}function Be(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),Q){let l=n==="reverse"?1-t:t;e.style.clipPath=se(l);return}$.forEach((l,g)=>{l.style.strokeDashoffset=n==="reverse"?`${h[g]*t}`:`${h[g]*(1-t)}`,c&&(l.style.opacity=n==="reverse"?`${1-t}`:`${t}`),q&&L?l.style.stroke=Pe(q,L,t):L&&(l.style.stroke=L),M!==null&&D!==null?l.style.strokeWidth=`${M+(D-M)*t}`:D!==null&&(l.style.strokeWidth=`${D}`),C!==null&&I!==null?l.style.fillOpacity=`${C+(I-C)*t}`:I!==null&&(l.style.fillOpacity=`${I}`),d&&l.tagName.toLowerCase()==="path"&&B[g]&&l.setAttribute("d",Ve(B[g],d,t));});}function Oe(){if(e.style.setProperty("--scroll-draw-progress","0"),Q){e.style.clipPath=se(0);return}$.forEach((t,n)=>{t.style.strokeDasharray=`${h[n]}`,t.style.strokeDashoffset=p==="reverse"?"0":`${h[n]}`,c?t.style.opacity=p==="reverse"?"1":"0":t.style.opacity="",q&&(t.style.stroke=q),M!==null&&(t.style.strokeWidth=`${M}`),C!==null&&(t.style.fillOpacity=`${C}`),d&&t.tagName.toLowerCase()==="path"&&B[n]&&t.setAttribute("d",B[n]);});}if($.forEach(t=>{Je(t);let n=ke(t);h.push(n),t.tagName.toLowerCase()==="path"?B.push(t.getAttribute("d")??""):B.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=p==="reverse"?`${n}`:"0",c&&(t.style.opacity="1"),L&&(t.style.stroke=L),D!==null&&(t.style.strokeWidth=`${D}`),I!==null&&(t.style.fillOpacity=`${I}`),d&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",d)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=p==="reverse"?"0":`${n}`,c?t.style.opacity=p==="reverse"?"1":"0":t.style.opacity="",q&&(t.style.stroke=q),M!==null&&(t.style.strokeWidth=`${M}`),C!==null&&(t.style.fillOpacity=`${C}`));}),Q){if(s)return e.style.clipPath=se(1),z?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=se(0);}else if(s)return z?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ue(){return !(le===false||!Ye()||!$.length||typeof m!="string"||!(m in We)||Q||E!=="y"||S||a!==1||v!==0||V||j||Y!==false||d||ne||N||re>0||K||G||z||T!=null||x!=null||P!=null||(w.start??"top bottom").trim()!=="top bottom"||(w.end??"bottom top").trim()!=="bottom top")}function Xe(){let t=`svg-scroll-draw-${++je}`,n=p==="reverse"?"0":"var(--ssd-len)",l=p==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${n};`,te=`stroke-dashoffset:${l};`;c&&(g+=`opacity:${p==="reverse"?1:0};`,te+=`opacity:${p==="reverse"?0:1};`);let k=document.createElement("style");k.setAttribute("data-svg-scroll-draw",""),k.textContent=`@keyframes ${t}{from{${g}}to{${te}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${We[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(k);function i(f,R){f.style.setProperty("--ssd-len",String(h[R])),f.style.strokeDasharray=`${h[R]}`,f.style.strokeDashoffset="",f.style.opacity="",f.style.animationPlayState="",f.classList.add(t);}$.forEach(i);let u=false,b=-1;function y(){if(b>=0)return b;let f=e.getBoundingClientRect(),{tStart:R,tEnd:fe}=me({top:f.top,height:f.height},ue(),Ce(),Le,Me);return ye(W(ue(),R,fe,a))}return {destroy(){$.forEach(f=>{f.classList.remove(t),f.style.removeProperty("--ssd-len"),f.style.animationPlayState="";}),k.remove();},replay(){u=false,b=-1,$.forEach(i);},pause(){u=true,$.forEach(f=>{f.style.animationPlayState="paused";});},resume(){u&&(u=false,$.forEach(f=>{f.style.animationPlayState="running";}));},seek(f){let R=Math.min(1,Math.max(0,f));b=R,u=true,$.forEach((fe,Re)=>{fe.classList.remove(t),fe.style.strokeDashoffset=p==="reverse"?`${h[Re]*R}`:`${h[Re]*(1-R)}`,c&&(fe.style.opacity=p==="reverse"?`${1-R}`:`${R}`);});},getProgress(){return y()}}}if(Ue())return Xe();Ie();function xe(){if(!ge||ee)return;let t=performance.now(),n=ue(),l=a;if(Y!==false){let i=t-De,u=i>0?Math.abs(n-(Ee<0?n:Ee))/i:0;l=a*Math.max(.2,1+u*(typeof Y=="number"?Y:1)*.04);}Ee=n,De=t;let g=j?he===-1||n>=he?"forward":"reverse":p;he=n;let te=X-U,k=true;if(Q){let i=ye(W(n,U,X,l));V&&!j&&(O=Math.max(O,i),i=O),be=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=g==="reverse"?1-i:i;e.style.clipPath=se(u),K?.(i),!Z&&W(n,U,X,l)>0&&(Z=true,G?.()),i>=1&&!H?(H=true,z?.(),ce<(N==="infinite"?1/0:N??0)&&(ce++,we=setTimeout(()=>{O=-1,Z=false,H=false,e.style.clipPath=se(0);},J))):i<1&&!V&&(H=false),_=requestAnimationFrame(xe);return}if($.forEach((i,u)=>{let b=u*v*te,y=ye(W(n,U+b,X+b,l));V&&!j&&(O=Math.max(O,y),y=O),be=y,i.style.strokeDashoffset=g==="reverse"?`${h[u]*y}`:`${h[u]*(1-y)}`,c&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),q&&L?i.style.stroke=Pe(q,L,y):L&&(i.style.stroke=L),M!==null&&D!==null?i.style.strokeWidth=`${M+(D-M)*y}`:D!==null&&(i.style.strokeWidth=`${D}`),C!==null&&I!==null?i.style.fillOpacity=`${C+(I-C)*y}`:I!==null&&(i.style.fillOpacity=`${I}`),d&&i.tagName.toLowerCase()==="path"&&B[u]&&i.setAttribute("d",Ve(B[u],d,y)),u===0&&(K?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(k=false);}),ne){let i=ye(W(n,U,X,l));for(let u in ne){let b=parseFloat(u);i>=b&&!ve.has(b)&&(ve.add(b),ne[u]?.());}}!Z&&W(n,U,X,l)>0&&(Z=true,G?.()),k&&!H?(H=true,z?.(),ce<(N==="infinite"?1/0:N??0)&&(ce++,we=setTimeout(()=>{O=-1,Z=false,H=false,ve.clear(),Oe();},J))):!k&&!V&&(H=false),_=requestAnimationFrame(xe);}let Te=new IntersectionObserver(t=>{t.forEach(n=>{ge=n.isIntersecting,ge&&!ee?_=requestAnimationFrame(xe):cancelAnimationFrame(_);});},{root:S??null,threshold:pe,rootMargin:de}),Ae;function Se(){clearTimeout(Ae),Ae=setTimeout(()=>{$.forEach((t,n)=>{h[n]=ke(t),t.style.strokeDasharray=`${h[n]}`;}),Ie();},150);}return window.addEventListener("resize",Se),window.addEventListener("orientationchange",Se),re>0?setTimeout(()=>Te.observe(e),re):Te.observe(e),{destroy(){cancelAnimationFrame(_),clearTimeout(we),Te.disconnect(),window.removeEventListener("resize",Se),window.removeEventListener("orientationchange",Se),clearTimeout(Ae),$e?.remove();},replay(){O=-1,he=-1,Ee=-1,Z=false,H=false,ce=0,ee=false,ve.clear(),clearTimeout(we),Oe();},pause(){ee=true,cancelAnimationFrame(_);},resume(){ee&&(ee=false,ge&&(_=requestAnimationFrame(xe)));},seek(t){let n=Math.min(1,Math.max(0,t));be=n,O=n,ee=true,cancelAnimationFrame(_),Be(n,p);},getProgress(){return be}}}function et(e,r={}){let[s,o]=react.useState(0),a=react.useRef(r);a.current=r;let c=react.useRef(-1);return react.useEffect(()=>{if(typeof window>"u")return;if(window.matchMedia("(prefers-reduced-motion: reduce)").matches){o(1);return}let m=typeof e=="string"?document.querySelector(e):e.current;if(!m)return;let w=m,{axis:v="y",scrollContainer:p,trigger:V={}}=a.current,F=typeof p=="string"?document.querySelector(p):p??null,E=ie(V.start??"top bottom"),ae=ie(V.end??"bottom top"),j=0,re=0,T=false,x=0;function P(){return F?v==="x"?F.scrollLeft:F.scrollTop:v==="x"?window.scrollX:window.scrollY}function ne(){return F?v==="x"?F.clientWidth:F.clientHeight:v==="x"?window.innerWidth:window.innerHeight}function Y(){let d=w.getBoundingClientRect(),A=P(),le=v==="x"?d.left:d.top,K=v==="x"?d.width:d.height,G=me({top:le,height:K},A,ne(),E,ae);j=G.tStart,re=G.tEnd;}function pe(){if(!T)return;let{speed:d=1,easing:A="linear",once:le=false}=a.current,K=typeof A=="function"?A:oe[A]??oe.linear,G=W(P(),j,re,d),z=K(G);le&&(c.current=Math.max(c.current,z),z=c.current),o(z),x=requestAnimationFrame(pe);}let de=new IntersectionObserver(d=>{d.forEach(A=>{T=A.isIntersecting,T?x=requestAnimationFrame(pe):cancelAnimationFrame(x);});},{root:F??null,threshold:0});Y(),de.observe(w);let N;function J(){clearTimeout(N),N=setTimeout(Y,150);}return window.addEventListener("resize",J),window.addEventListener("orientationchange",J),()=>{cancelAnimationFrame(x),clearTimeout(N),de.disconnect(),window.removeEventListener("resize",J),window.removeEventListener("orientationchange",J);}},[]),s}function pt({children:e,className:r,style:s,...o}){let a=react.useRef(null);return react.useEffect(()=>{if(!a.current)return;let c=Ge(a.current,o);return ()=>c.destroy()},[]),jsxRuntime.jsx("div",{ref:a,className:r,style:s,children:e})}exports.ScrollDraw=pt;exports.useScrollDrawProgress=et;
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function Qe({bounces:e=3,decay:r=.5}={}){let s=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(o),f=0,g=[];for(let a=0;a<s;a++){let y=Math.pow(c,a);g.push(y),f+=y;}let v=[0],x=0;for(let a=0;a<s;a++)x+=g[a]/f,v.push(x);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let y=0;y<s;y++)if(a<=v[y+1]){let k=(a-v[y])/(v[y+1]-v[y]);if(y===0)return k*(2-k);let T=1-Math.pow(o,y);return T+(1-T)*(2*k-1)*(2*k-1)}return 1}}function Ze({amplitude:e=1,period:r=.4}={}){let s=Math.max(1,e),o=Math.max(.1,r),c=s<=1?o/4:o/(2*Math.PI)*Math.asin(1/s);return f=>f<=0?0:f>=1?1:s*Math.pow(2,-10*f)*Math.sin((f-c)*(2*Math.PI)/o)+1}var de={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:Qe(),elastic:Ze()};function ye(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[s="top",o="bottom"]=r.split(/\s+/).filter(Boolean);return {element:s,viewport:o}}function qe(e,r,s,o){switch(o){case "top":return e+s;case "center":return e+s+r/2;case "bottom":return e+s+r;default:return e+s}}function Ve(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 Le(e){let r=e.tagName.toLowerCase();if(r==="rect"){let s=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(s+o)}if(r==="circle"){let s=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*s}return e.getTotalLength()}function et(e,r,s){return Math.min(s,Math.max(r,e))}function K(e,r,s,o){return s===r?0:et((e-r)/(s-r)*o,0,1)}function xe(e,r,s,o,c){let f=qe(e.top,e.height,r,o.element)-Ve(o.viewport,s),g=qe(e.top,e.height,r,c.element)-Ve(c.viewport,s);return {tStart:f,tEnd:g}}function Ge(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 s=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(s)return [parseInt(s[1],16),parseInt(s[2],16),parseInt(s[3],16)];let o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function De(e,r,s){let o=Ge(e),c=Ge(r);return !o||!c?e:`rgb(${Math.round(o[0]+(c[0]-o[0])*s)},${Math.round(o[1]+(c[1]-o[1])*s)},${Math.round(o[2]+(c[2]-o[2])*s)})`}function Be(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ue={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},tt=0;function rt(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function nt(e){let r=e.getAttribute("stroke"),s=e.getAttribute("fill");!r||r==="none"?Be("Element has no stroke \u2014 path will not be visible.",e):s&&s!=="none"&&s!=="transparent"&&Be("Element has a fill \u2014 it may obscure the stroke animation.",e);}function st(e,r,s){let o=document.createElement("div");o.setAttribute("data-svg-scroll-draw-debug",""),o.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 c(){let f=s==="x"?window.scrollX:window.scrollY,g=e-f,v=r-f,x=s==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${x?`left:${g}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${g}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;${x?`left:${v}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${v}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",c,{passive:true}),c(),o}function Re(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let g=parseFloat(f),v=o[c++]??g;return String(+(g+(v-g)*s).toFixed(4))})}function Xe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let s=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:c=1,fade:f=false,easing:g="linear",trigger:v={},stagger:x=0,direction:a="forward",once:y=false,debug:k=false,axis:T="y",scrollContainer:ge,autoReverse:oe=false,delay:Q=0,strokeColor:H,strokeWidth:N,fillOpacity:G,waypoints:j,velocityScale:ie=false,threshold:he=0,rootMargin:be="0px",repeat:W=0,repeatDelay:Z=0,morphTo:b,clip:q,autoplay:we=false,duration:ve=1e3,native:fe=true,onProgress:Y,onStart:$e,onComplete:me}=r,ee=q===true?"left":typeof q=="string"?q:false,ae=typeof g=="function"?g:de[g]??de.linear,Oe=ye(v.start??"top bottom"),Ne=ye(v.end??"bottom top"),I=typeof ge=="string"?document.querySelector(ge):ge??null,B=Array.isArray(H)?H[0]:null,P=Array.isArray(H)?H[1]:typeof H=="string"?H:null,R=Array.isArray(N)?N[0]:null,L=Array.isArray(N)?N[1]:typeof N=="number"?N:null,O=Array.isArray(G)?G[0]:null,D=Array.isArray(G)?G[1]:typeof G=="number"?G:null;function le(t){let n=t*100;switch(ee){case "right":return `inset(0 0 0 ${100-n}%)`;case "top":return `inset(0 0 ${100-n}% 0)`;case "bottom":return `inset(${100-n}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-n}% 0 0)`}}let M=ee?[]:Array.from(e.querySelectorAll(o)),$=[],U=[],te=0,re=0,A=false,V=false,S=0,Se=false,X=-1,Te=-1,C=false,ue=0,J=0,ne,Ce=null,se=new Set,Me=-1,ze=performance.now();function Ee(){return I?T==="x"?I.scrollLeft:I.scrollTop:T==="x"?window.scrollX:window.scrollY}function He(){return I?T==="x"?I.clientWidth:I.clientHeight:T==="x"?window.innerWidth:window.innerHeight}function We(){let t=e.getBoundingClientRect(),n,u,w;if(I){let F=I.getBoundingClientRect();n=T==="x"?t.left-F.left+I.scrollLeft:t.top-F.top+I.scrollTop,u=T==="x"?t.width:t.height,w=Ee();}else n=T==="x"?t.left:t.top,u=T==="x"?t.width:t.height,w=Ee();let z=xe({top:n,height:u},w,He(),Oe,Ne);te=z.tStart,re=z.tEnd,k&&process.env.NODE_ENV!=="production"&&(Ce?.remove(),Ce=st(te,re,T));}function je(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),ee){let u=n==="reverse"?1-t:t;e.style.clipPath=le(u);return}M.forEach((u,w)=>{u.style.strokeDashoffset=n==="reverse"?`${$[w]*t}`:`${$[w]*(1-t)}`,f&&(u.style.opacity=n==="reverse"?`${1-t}`:`${t}`),B&&P?u.style.stroke=De(B,P,t):P&&(u.style.stroke=P),R!==null&&L!==null?u.style.strokeWidth=`${R+(L-R)*t}`:L!==null&&(u.style.strokeWidth=`${L}`),O!==null&&D!==null?u.style.fillOpacity=`${O+(D-O)*t}`:D!==null&&(u.style.fillOpacity=`${D}`),b&&u.tagName.toLowerCase()==="path"&&U[w]&&u.setAttribute("d",Re(U[w],b,t));});}function Ae(){if(e.style.setProperty("--scroll-draw-progress","0"),ee){e.style.clipPath=le(0);return}M.forEach((t,n)=>{t.style.strokeDasharray=`${$[n]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${$[n]}`,f?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",B&&(t.style.stroke=B),R!==null&&(t.style.strokeWidth=`${R}`),O!==null&&(t.style.fillOpacity=`${O}`),b&&t.tagName.toLowerCase()==="path"&&U[n]&&t.setAttribute("d",U[n]);});}if(M.forEach(t=>{nt(t);let n=Le(t);$.push(n),t.tagName.toLowerCase()==="path"?U.push(t.getAttribute("d")??""):U.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=a==="reverse"?`${n}`:"0",f&&(t.style.opacity="1"),P&&(t.style.stroke=P),L!==null&&(t.style.strokeWidth=`${L}`),D!==null&&(t.style.fillOpacity=`${D}`),b&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",b)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=a==="reverse"?"0":`${n}`,f?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",B&&(t.style.stroke=B),R!==null&&(t.style.strokeWidth=`${R}`),O!==null&&(t.style.fillOpacity=`${O}`));}),ee){if(s)return e.style.clipPath=le(1),me?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=le(0);}else if(s)return me?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ye(){return !(fe===false||!rt()||!M.length||typeof g!="string"||!(g in Ue)||ee||T!=="y"||I||c!==1||x!==0||y||oe||ie!==false||b||j||W||Q>0||Y||$e||me||H!=null||N!=null||G!=null||(v.start??"top bottom").trim()!=="top bottom"||(v.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++tt}`,n=a==="reverse"?"0":"var(--ssd-len)",u=a==="reverse"?"var(--ssd-len)":"0",w=`stroke-dashoffset:${n};`,z=`stroke-dashoffset:${u};`;f&&(w+=`opacity:${a==="reverse"?1:0};`,z+=`opacity:${a==="reverse"?0:1};`);let F=document.createElement("style");F.setAttribute("data-svg-scroll-draw",""),F.textContent=`@keyframes ${t}{from{${w}}to{${z}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ue[g]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(F);function l(i,p){i.style.setProperty("--ssd-len",String($[p])),i.style.strokeDasharray=`${$[p]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}M.forEach(l);let d=false,E=-1;function m(){if(E>=0)return E;let i=e.getBoundingClientRect(),{tStart:p,tEnd:h}=xe({top:i.top,height:i.height},Ee(),He(),Oe,Ne);return ae(K(Ee(),p,h,c))}return {destroy(){M.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),F.remove();},replay(){d=false,E=-1,M.forEach(l);},pause(){d=true,M.forEach(i=>{i.style.animationPlayState="paused";});},resume(){d&&(d=false,M.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let p=Math.min(1,Math.max(0,i));E=p,d=true,M.forEach((h,ce)=>{h.classList.remove(t),h.style.strokeDashoffset=a==="reverse"?`${$[ce]*p}`:`${$[ce]*(1-p)}`,f&&(h.style.opacity=a==="reverse"?`${1-p}`:`${p}`);});},getProgress(){return m()}}}if(Ye())return Je();function Ke(){let t=Math.max(1,ve),n=0,u=0;function w(m){let i=true;if(ee){let p=Math.min(1,Math.max(0,m/t)),h=ae(p);ue=h,e.style.setProperty("--scroll-draw-progress",String(h)),e.style.clipPath=le(a==="reverse"?1-h:h),Y?.(h),p<1&&(i=false);}else M.forEach((p,h)=>{let ce=h*x*t,pe=Math.min(1,Math.max(0,(m-ce)/t)),_=ae(pe);p.style.strokeDashoffset=a==="reverse"?`${$[h]*_}`:`${$[h]*(1-_)}`,f&&(p.style.opacity=a==="reverse"?`${1-_}`:`${_}`),B&&P?p.style.stroke=De(B,P,_):P&&(p.style.stroke=P),R!==null&&L!==null?p.style.strokeWidth=`${R+(L-R)*_}`:L!==null&&(p.style.strokeWidth=`${L}`),O!==null&&D!==null?p.style.fillOpacity=`${O+(D-O)*_}`:D!==null&&(p.style.fillOpacity=`${D}`),b&&p.tagName.toLowerCase()==="path"&&U[h]&&p.setAttribute("d",Re(U[h],b,_)),h===0&&(Y?.(_),e.style.setProperty("--scroll-draw-progress",String(_))),pe<1&&(i=false);});if(j){let p=Math.min(1,Math.max(0,m/t)),h=ae(p);for(let ce in j){let pe=parseFloat(ce);h>=pe&&!se.has(pe)&&(se.add(pe),j[ce]?.());}}return i}function z(m){if(C)return;let i=m-n;V||(V=true,$e?.());let p=w(i);if(p&&!A){A=true,w(t*(1+Math.max(0,M.length-1)*x)),me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{n=performance.now(),V=false,A=false,se.clear(),Ae(),S=requestAnimationFrame(z);},Z));return}p||(S=requestAnimationFrame(z));}function F(){cancelAnimationFrame(S),clearTimeout(ne),n=performance.now(),u=0,C=false,V=false,A=false,J=0,se.clear(),Ae(),S=requestAnimationFrame(z);}let l=new IntersectionObserver(m=>{m.forEach(i=>{i.isIntersecting&&!(y&&A)?F():!i.isIntersecting&&!y&&!A&&(cancelAnimationFrame(S),clearTimeout(ne),n=null);});},{root:I??null,threshold:he,rootMargin:be}),d;function E(){clearTimeout(d),d=setTimeout(()=>{M.forEach((m,i)=>{$[i]=Le(m),m.style.strokeDasharray=`${$[i]}`;});},150);}return window.addEventListener("resize",E),window.addEventListener("orientationchange",E),Q>0?setTimeout(()=>l.observe(e),Q):l.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(ne),l.disconnect(),window.removeEventListener("resize",E),window.removeEventListener("orientationchange",E),clearTimeout(d);},replay(){J=0,F();},pause(){C||(C=true,u=performance.now()-n,cancelAnimationFrame(S));},resume(){C&&(C=false,n=performance.now()-u,S=requestAnimationFrame(z));},seek(m){let i=Math.min(1,Math.max(0,m));ue=i,C=true,u=i*t,n=performance.now()-u,cancelAnimationFrame(S),w(u);},getProgress(){return ue}}}if(we)return Ke();We();function ke(){if(!Se||C)return;let t=performance.now(),n=Ee(),u=c;if(ie!==false){let l=t-ze,d=l>0?Math.abs(n-(Me<0?n:Me))/l:0;u=c*Math.max(.2,1+d*(typeof ie=="number"?ie:1)*.04);}Me=n,ze=t;let w=oe?Te===-1||n>=Te?"forward":"reverse":a;Te=n;let z=re-te,F=true;if(ee){let l=ae(K(n,te,re,u));y&&!oe&&(X=Math.max(X,l),l=X),ue=l,e.style.setProperty("--scroll-draw-progress",String(l));let d=w==="reverse"?1-l:l;e.style.clipPath=le(d),Y?.(l),!V&&K(n,te,re,u)>0&&(V=true,$e?.()),l>=1&&!A?(A=true,me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{X=-1,V=false,A=false,e.style.clipPath=le(0);},Z))):l<1&&!y&&(A=false),S=requestAnimationFrame(ke);return}if(M.forEach((l,d)=>{let E=d*x*z,m=ae(K(n,te+E,re+E,u));y&&!oe&&(X=Math.max(X,m),m=X),ue=m,l.style.strokeDashoffset=w==="reverse"?`${$[d]*m}`:`${$[d]*(1-m)}`,f&&(l.style.opacity=w==="reverse"?`${1-m}`:`${m}`),B&&P?l.style.stroke=De(B,P,m):P&&(l.style.stroke=P),R!==null&&L!==null?l.style.strokeWidth=`${R+(L-R)*m}`:L!==null&&(l.style.strokeWidth=`${L}`),O!==null&&D!==null?l.style.fillOpacity=`${O+(D-O)*m}`:D!==null&&(l.style.fillOpacity=`${D}`),b&&l.tagName.toLowerCase()==="path"&&U[d]&&l.setAttribute("d",Re(U[d],b,m)),d===0&&(Y?.(m),e.style.setProperty("--scroll-draw-progress",String(m))),m<1&&(F=false);}),j){let l=ae(K(n,te,re,u));for(let d in j){let E=parseFloat(d);l>=E&&!se.has(E)&&(se.add(E),j[d]?.());}}!V&&K(n,te,re,u)>0&&(V=true,$e?.()),F&&!A?(A=true,me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{X=-1,V=false,A=false,se.clear(),Ae();},Z))):!F&&!y&&(A=false),S=requestAnimationFrame(ke);}let Fe=new IntersectionObserver(t=>{t.forEach(n=>{Se=n.isIntersecting,Se&&!C?S=requestAnimationFrame(ke):cancelAnimationFrame(S);});},{root:I??null,threshold:he,rootMargin:be}),Ie;function Pe(){clearTimeout(Ie),Ie=setTimeout(()=>{M.forEach((t,n)=>{$[n]=Le(t),t.style.strokeDasharray=`${$[n]}`;}),We();},150);}return window.addEventListener("resize",Pe),window.addEventListener("orientationchange",Pe),Q>0?setTimeout(()=>Fe.observe(e),Q):Fe.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(ne),Fe.disconnect(),window.removeEventListener("resize",Pe),window.removeEventListener("orientationchange",Pe),clearTimeout(Ie),Ce?.remove();},replay(){X=-1,Te=-1,Me=-1,V=false,A=false,J=0,C=false,se.clear(),clearTimeout(ne),Ae();},pause(){C=true,cancelAnimationFrame(S);},resume(){C&&(C=false,Se&&(S=requestAnimationFrame(ke)));},seek(t){let n=Math.min(1,Math.max(0,t));ue=n,X=n,C=true,cancelAnimationFrame(S),je(n,a);},getProgress(){return ue}}}function at(e,r={}){let[s,o]=react.useState(0),c=react.useRef(r);c.current=r;let f=react.useRef(-1);return react.useEffect(()=>{if(typeof window>"u")return;if(window.matchMedia("(prefers-reduced-motion: reduce)").matches){o(1);return}let g=typeof e=="string"?document.querySelector(e):e.current;if(!g)return;let v=g,{axis:x="y",scrollContainer:a,trigger:y={}}=c.current,k=typeof a=="string"?document.querySelector(a):a??null,T=ye(y.start??"top bottom"),ge=ye(y.end??"bottom top"),oe=0,Q=0,H=false,N=0;function G(){return k?x==="x"?k.scrollLeft:k.scrollTop:x==="x"?window.scrollX:window.scrollY}function j(){return k?x==="x"?k.clientWidth:k.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function ie(){let b=v.getBoundingClientRect(),q=G(),we=x==="x"?b.left:b.top,ve=x==="x"?b.width:b.height,fe=xe({top:we,height:ve},q,j(),T,ge);oe=fe.tStart,Q=fe.tEnd;}function he(){if(!H)return;let{speed:b=1,easing:q="linear",once:we=false}=c.current,ve=typeof q=="function"?q:de[q]??de.linear,fe=K(G(),oe,Q,b),Y=ve(fe);we&&(f.current=Math.max(f.current,Y),Y=f.current),o(Y),N=requestAnimationFrame(he);}let be=new IntersectionObserver(b=>{b.forEach(q=>{H=q.isIntersecting,H?N=requestAnimationFrame(he):cancelAnimationFrame(N);});},{root:k??null,threshold:0});ie(),be.observe(v);let W;function Z(){clearTimeout(W),W=setTimeout(ie,150);}return window.addEventListener("resize",Z),window.addEventListener("orientationchange",Z),()=>{cancelAnimationFrame(N),clearTimeout(W),be.disconnect(),window.removeEventListener("resize",Z),window.removeEventListener("orientationchange",Z);}},[]),s}function vt({children:e,className:r,style:s,...o}){let c=react.useRef(null);return react.useEffect(()=>{if(!c.current)return;let f=Xe(c.current,o);return ()=>f.destroy()},[]),jsxRuntime.jsx("div",{ref:c,className:r,style:s,children:e})}exports.ScrollDraw=vt;exports.useScrollDrawProgress=at;
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { RefObject } from 'react';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -63,6 +63,25 @@ interface ScrollDrawOptions {
|
|
|
63
63
|
onProgress?: (alpha: number) => void;
|
|
64
64
|
onStart?: () => void;
|
|
65
65
|
onComplete?: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Trigger the animation when the element enters the viewport instead of
|
|
68
|
+
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
69
|
+
* replaying each time the element re-enters the viewport (use `once: true`
|
|
70
|
+
* to play only the first time).
|
|
71
|
+
*
|
|
72
|
+
* All visual options work in autoplay mode — `easing`, `stagger`, `fade`,
|
|
73
|
+
* `strokeColor`, `strokeWidth`, `fillOpacity`, `clip`, `morphTo`, `waypoints`,
|
|
74
|
+
* `repeat`, `repeatDelay`, `onStart`, `onComplete`, `onProgress`, etc.
|
|
75
|
+
*
|
|
76
|
+
* The full instance API (`pause`, `resume`, `seek`, `replay`, `getProgress`)
|
|
77
|
+
* also works — `seek(0.5)` pauses at 50% of the duration.
|
|
78
|
+
*/
|
|
79
|
+
autoplay?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Duration of the autoplay animation in milliseconds. Only used when
|
|
82
|
+
* `autoplay: true`. Default `1000`.
|
|
83
|
+
*/
|
|
84
|
+
duration?: number;
|
|
66
85
|
/**
|
|
67
86
|
* Use the browser's native CSS scroll-driven animation
|
|
68
87
|
* (`animation-timeline: view()`) when the configuration is simple enough and
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { RefObject } from 'react';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -63,6 +63,25 @@ interface ScrollDrawOptions {
|
|
|
63
63
|
onProgress?: (alpha: number) => void;
|
|
64
64
|
onStart?: () => void;
|
|
65
65
|
onComplete?: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Trigger the animation when the element enters the viewport instead of
|
|
68
|
+
* tying it to scroll position. The draw runs over `duration` milliseconds,
|
|
69
|
+
* replaying each time the element re-enters the viewport (use `once: true`
|
|
70
|
+
* to play only the first time).
|
|
71
|
+
*
|
|
72
|
+
* All visual options work in autoplay mode — `easing`, `stagger`, `fade`,
|
|
73
|
+
* `strokeColor`, `strokeWidth`, `fillOpacity`, `clip`, `morphTo`, `waypoints`,
|
|
74
|
+
* `repeat`, `repeatDelay`, `onStart`, `onComplete`, `onProgress`, etc.
|
|
75
|
+
*
|
|
76
|
+
* The full instance API (`pause`, `resume`, `seek`, `replay`, `getProgress`)
|
|
77
|
+
* also works — `seek(0.5)` pauses at 50% of the duration.
|
|
78
|
+
*/
|
|
79
|
+
autoplay?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Duration of the autoplay animation in milliseconds. Only used when
|
|
82
|
+
* `autoplay: true`. Default `1000`.
|
|
83
|
+
*/
|
|
84
|
+
duration?: number;
|
|
66
85
|
/**
|
|
67
86
|
* Use the browser's native CSS scroll-driven animation
|
|
68
87
|
* (`animation-timeline: view()`) when the configuration is simple enough and
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {useState,useRef,useEffect}from'react';import {jsx}from'react/jsx-runtime';var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${v?`left:${w}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${w}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",a,{passive:true}),a(),o}function Ve(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,c=>{let m=parseFloat(c),w=o[a++]??m;return String(+(m+(w-m)*s).toFixed(4))})}function Ge(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let s=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:a=1,fade:c=false,easing:m="linear",trigger:w={},stagger:v=0,direction:p="forward",once:V=false,debug:F=false,axis:E="y",scrollContainer:ae,autoReverse:j=false,delay:re=0,strokeColor:T,strokeWidth:x,fillOpacity:P,waypoints:ne,velocityScale:Y=false,threshold:pe=0,rootMargin:de="0px",repeat:N=0,repeatDelay:J=0,morphTo:d,clip:A,native:le=true,onProgress:K,onStart:G,onComplete:z}=r,Q=A===true?"left":typeof A=="string"?A:false,ye=typeof m=="function"?m:oe[m]??oe.linear,Le=ie(w.start??"top bottom"),Me=ie(w.end??"bottom top"),S=typeof ae=="string"?document.querySelector(ae):ae??null,q=Array.isArray(T)?T[0]:null,L=Array.isArray(T)?T[1]:typeof T=="string"?T:null,M=Array.isArray(x)?x[0]:null,D=Array.isArray(x)?x[1]:typeof x=="number"?x:null,C=Array.isArray(P)?P[0]:null,I=Array.isArray(P)?P[1]:typeof P=="number"?P:null;function se(t){let n=t*100;switch(Q){case "right":return `inset(0 0 0 ${100-n}%)`;case "top":return `inset(0 0 ${100-n}% 0)`;case "bottom":return `inset(${100-n}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-n}% 0 0)`}}let $=Q?[]:Array.from(e.querySelectorAll(o)),h=[],B=[],U=0,X=0,H=false,Z=false,_=0,ge=false,O=-1,he=-1,ee=false,be=0,ce=0,we,$e=null,ve=new Set,Ee=-1,De=performance.now();function ue(){return S?E==="x"?S.scrollLeft:S.scrollTop:E==="x"?window.scrollX:window.scrollY}function Ce(){return S?E==="x"?S.clientWidth:S.clientHeight:E==="x"?window.innerWidth:window.innerHeight}function Ie(){let t=e.getBoundingClientRect(),n,l,g;if(S){let k=S.getBoundingClientRect();n=E==="x"?t.left-k.left+S.scrollLeft:t.top-k.top+S.scrollTop,l=E==="x"?t.width:t.height,g=ue();}else n=E==="x"?t.left:t.top,l=E==="x"?t.width:t.height,g=ue();let te=me({top:n,height:l},g,Ce(),Le,Me);U=te.tStart,X=te.tEnd,F&&process.env.NODE_ENV!=="production"&&($e?.remove(),$e=Ke(U,X,E));}function Be(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),Q){let l=n==="reverse"?1-t:t;e.style.clipPath=se(l);return}$.forEach((l,g)=>{l.style.strokeDashoffset=n==="reverse"?`${h[g]*t}`:`${h[g]*(1-t)}`,c&&(l.style.opacity=n==="reverse"?`${1-t}`:`${t}`),q&&L?l.style.stroke=Pe(q,L,t):L&&(l.style.stroke=L),M!==null&&D!==null?l.style.strokeWidth=`${M+(D-M)*t}`:D!==null&&(l.style.strokeWidth=`${D}`),C!==null&&I!==null?l.style.fillOpacity=`${C+(I-C)*t}`:I!==null&&(l.style.fillOpacity=`${I}`),d&&l.tagName.toLowerCase()==="path"&&B[g]&&l.setAttribute("d",Ve(B[g],d,t));});}function Oe(){if(e.style.setProperty("--scroll-draw-progress","0"),Q){e.style.clipPath=se(0);return}$.forEach((t,n)=>{t.style.strokeDasharray=`${h[n]}`,t.style.strokeDashoffset=p==="reverse"?"0":`${h[n]}`,c?t.style.opacity=p==="reverse"?"1":"0":t.style.opacity="",q&&(t.style.stroke=q),M!==null&&(t.style.strokeWidth=`${M}`),C!==null&&(t.style.fillOpacity=`${C}`),d&&t.tagName.toLowerCase()==="path"&&B[n]&&t.setAttribute("d",B[n]);});}if($.forEach(t=>{Je(t);let n=ke(t);h.push(n),t.tagName.toLowerCase()==="path"?B.push(t.getAttribute("d")??""):B.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=p==="reverse"?`${n}`:"0",c&&(t.style.opacity="1"),L&&(t.style.stroke=L),D!==null&&(t.style.strokeWidth=`${D}`),I!==null&&(t.style.fillOpacity=`${I}`),d&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",d)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=p==="reverse"?"0":`${n}`,c?t.style.opacity=p==="reverse"?"1":"0":t.style.opacity="",q&&(t.style.stroke=q),M!==null&&(t.style.strokeWidth=`${M}`),C!==null&&(t.style.fillOpacity=`${C}`));}),Q){if(s)return e.style.clipPath=se(1),z?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=se(0);}else if(s)return z?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ue(){return !(le===false||!Ye()||!$.length||typeof m!="string"||!(m in We)||Q||E!=="y"||S||a!==1||v!==0||V||j||Y!==false||d||ne||N||re>0||K||G||z||T!=null||x!=null||P!=null||(w.start??"top bottom").trim()!=="top bottom"||(w.end??"bottom top").trim()!=="bottom top")}function Xe(){let t=`svg-scroll-draw-${++je}`,n=p==="reverse"?"0":"var(--ssd-len)",l=p==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${n};`,te=`stroke-dashoffset:${l};`;c&&(g+=`opacity:${p==="reverse"?1:0};`,te+=`opacity:${p==="reverse"?0:1};`);let k=document.createElement("style");k.setAttribute("data-svg-scroll-draw",""),k.textContent=`@keyframes ${t}{from{${g}}to{${te}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${We[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(k);function i(f,R){f.style.setProperty("--ssd-len",String(h[R])),f.style.strokeDasharray=`${h[R]}`,f.style.strokeDashoffset="",f.style.opacity="",f.style.animationPlayState="",f.classList.add(t);}$.forEach(i);let u=false,b=-1;function y(){if(b>=0)return b;let f=e.getBoundingClientRect(),{tStart:R,tEnd:fe}=me({top:f.top,height:f.height},ue(),Ce(),Le,Me);return ye(W(ue(),R,fe,a))}return {destroy(){$.forEach(f=>{f.classList.remove(t),f.style.removeProperty("--ssd-len"),f.style.animationPlayState="";}),k.remove();},replay(){u=false,b=-1,$.forEach(i);},pause(){u=true,$.forEach(f=>{f.style.animationPlayState="paused";});},resume(){u&&(u=false,$.forEach(f=>{f.style.animationPlayState="running";}));},seek(f){let R=Math.min(1,Math.max(0,f));b=R,u=true,$.forEach((fe,Re)=>{fe.classList.remove(t),fe.style.strokeDashoffset=p==="reverse"?`${h[Re]*R}`:`${h[Re]*(1-R)}`,c&&(fe.style.opacity=p==="reverse"?`${1-R}`:`${R}`);});},getProgress(){return y()}}}if(Ue())return Xe();Ie();function xe(){if(!ge||ee)return;let t=performance.now(),n=ue(),l=a;if(Y!==false){let i=t-De,u=i>0?Math.abs(n-(Ee<0?n:Ee))/i:0;l=a*Math.max(.2,1+u*(typeof Y=="number"?Y:1)*.04);}Ee=n,De=t;let g=j?he===-1||n>=he?"forward":"reverse":p;he=n;let te=X-U,k=true;if(Q){let i=ye(W(n,U,X,l));V&&!j&&(O=Math.max(O,i),i=O),be=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=g==="reverse"?1-i:i;e.style.clipPath=se(u),K?.(i),!Z&&W(n,U,X,l)>0&&(Z=true,G?.()),i>=1&&!H?(H=true,z?.(),ce<(N==="infinite"?1/0:N??0)&&(ce++,we=setTimeout(()=>{O=-1,Z=false,H=false,e.style.clipPath=se(0);},J))):i<1&&!V&&(H=false),_=requestAnimationFrame(xe);return}if($.forEach((i,u)=>{let b=u*v*te,y=ye(W(n,U+b,X+b,l));V&&!j&&(O=Math.max(O,y),y=O),be=y,i.style.strokeDashoffset=g==="reverse"?`${h[u]*y}`:`${h[u]*(1-y)}`,c&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),q&&L?i.style.stroke=Pe(q,L,y):L&&(i.style.stroke=L),M!==null&&D!==null?i.style.strokeWidth=`${M+(D-M)*y}`:D!==null&&(i.style.strokeWidth=`${D}`),C!==null&&I!==null?i.style.fillOpacity=`${C+(I-C)*y}`:I!==null&&(i.style.fillOpacity=`${I}`),d&&i.tagName.toLowerCase()==="path"&&B[u]&&i.setAttribute("d",Ve(B[u],d,y)),u===0&&(K?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(k=false);}),ne){let i=ye(W(n,U,X,l));for(let u in ne){let b=parseFloat(u);i>=b&&!ve.has(b)&&(ve.add(b),ne[u]?.());}}!Z&&W(n,U,X,l)>0&&(Z=true,G?.()),k&&!H?(H=true,z?.(),ce<(N==="infinite"?1/0:N??0)&&(ce++,we=setTimeout(()=>{O=-1,Z=false,H=false,ve.clear(),Oe();},J))):!k&&!V&&(H=false),_=requestAnimationFrame(xe);}let Te=new IntersectionObserver(t=>{t.forEach(n=>{ge=n.isIntersecting,ge&&!ee?_=requestAnimationFrame(xe):cancelAnimationFrame(_);});},{root:S??null,threshold:pe,rootMargin:de}),Ae;function Se(){clearTimeout(Ae),Ae=setTimeout(()=>{$.forEach((t,n)=>{h[n]=ke(t),t.style.strokeDasharray=`${h[n]}`;}),Ie();},150);}return window.addEventListener("resize",Se),window.addEventListener("orientationchange",Se),re>0?setTimeout(()=>Te.observe(e),re):Te.observe(e),{destroy(){cancelAnimationFrame(_),clearTimeout(we),Te.disconnect(),window.removeEventListener("resize",Se),window.removeEventListener("orientationchange",Se),clearTimeout(Ae),$e?.remove();},replay(){O=-1,he=-1,Ee=-1,Z=false,H=false,ce=0,ee=false,ve.clear(),clearTimeout(we),Oe();},pause(){ee=true,cancelAnimationFrame(_);},resume(){ee&&(ee=false,ge&&(_=requestAnimationFrame(xe)));},seek(t){let n=Math.min(1,Math.max(0,t));be=n,O=n,ee=true,cancelAnimationFrame(_),Be(n,p);},getProgress(){return be}}}function et(e,r={}){let[s,o]=useState(0),a=useRef(r);a.current=r;let c=useRef(-1);return useEffect(()=>{if(typeof window>"u")return;if(window.matchMedia("(prefers-reduced-motion: reduce)").matches){o(1);return}let m=typeof e=="string"?document.querySelector(e):e.current;if(!m)return;let w=m,{axis:v="y",scrollContainer:p,trigger:V={}}=a.current,F=typeof p=="string"?document.querySelector(p):p??null,E=ie(V.start??"top bottom"),ae=ie(V.end??"bottom top"),j=0,re=0,T=false,x=0;function P(){return F?v==="x"?F.scrollLeft:F.scrollTop:v==="x"?window.scrollX:window.scrollY}function ne(){return F?v==="x"?F.clientWidth:F.clientHeight:v==="x"?window.innerWidth:window.innerHeight}function Y(){let d=w.getBoundingClientRect(),A=P(),le=v==="x"?d.left:d.top,K=v==="x"?d.width:d.height,G=me({top:le,height:K},A,ne(),E,ae);j=G.tStart,re=G.tEnd;}function pe(){if(!T)return;let{speed:d=1,easing:A="linear",once:le=false}=a.current,K=typeof A=="function"?A:oe[A]??oe.linear,G=W(P(),j,re,d),z=K(G);le&&(c.current=Math.max(c.current,z),z=c.current),o(z),x=requestAnimationFrame(pe);}let de=new IntersectionObserver(d=>{d.forEach(A=>{T=A.isIntersecting,T?x=requestAnimationFrame(pe):cancelAnimationFrame(x);});},{root:F??null,threshold:0});Y(),de.observe(w);let N;function J(){clearTimeout(N),N=setTimeout(Y,150);}return window.addEventListener("resize",J),window.addEventListener("orientationchange",J),()=>{cancelAnimationFrame(x),clearTimeout(N),de.disconnect(),window.removeEventListener("resize",J),window.removeEventListener("orientationchange",J);}},[]),s}function pt({children:e,className:r,style:s,...o}){let a=useRef(null);return useEffect(()=>{if(!a.current)return;let c=Ge(a.current,o);return ()=>c.destroy()},[]),jsx("div",{ref:a,className:r,style:s,children:e})}export{pt as ScrollDraw,et as useScrollDrawProgress};
|
|
1
|
+
import {useState,useRef,useEffect}from'react';import {jsx}from'react/jsx-runtime';function Qe({bounces:e=3,decay:r=.5}={}){let s=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(o),f=0,g=[];for(let a=0;a<s;a++){let y=Math.pow(c,a);g.push(y),f+=y;}let v=[0],x=0;for(let a=0;a<s;a++)x+=g[a]/f,v.push(x);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let y=0;y<s;y++)if(a<=v[y+1]){let k=(a-v[y])/(v[y+1]-v[y]);if(y===0)return k*(2-k);let T=1-Math.pow(o,y);return T+(1-T)*(2*k-1)*(2*k-1)}return 1}}function Ze({amplitude:e=1,period:r=.4}={}){let s=Math.max(1,e),o=Math.max(.1,r),c=s<=1?o/4:o/(2*Math.PI)*Math.asin(1/s);return f=>f<=0?0:f>=1?1:s*Math.pow(2,-10*f)*Math.sin((f-c)*(2*Math.PI)/o)+1}var de={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:Qe(),elastic:Ze()};function ye(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[s="top",o="bottom"]=r.split(/\s+/).filter(Boolean);return {element:s,viewport:o}}function qe(e,r,s,o){switch(o){case "top":return e+s;case "center":return e+s+r/2;case "bottom":return e+s+r;default:return e+s}}function Ve(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 Le(e){let r=e.tagName.toLowerCase();if(r==="rect"){let s=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(s+o)}if(r==="circle"){let s=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*s}return e.getTotalLength()}function et(e,r,s){return Math.min(s,Math.max(r,e))}function K(e,r,s,o){return s===r?0:et((e-r)/(s-r)*o,0,1)}function xe(e,r,s,o,c){let f=qe(e.top,e.height,r,o.element)-Ve(o.viewport,s),g=qe(e.top,e.height,r,c.element)-Ve(c.viewport,s);return {tStart:f,tEnd:g}}function Ge(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 s=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(s)return [parseInt(s[1],16),parseInt(s[2],16),parseInt(s[3],16)];let o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function De(e,r,s){let o=Ge(e),c=Ge(r);return !o||!c?e:`rgb(${Math.round(o[0]+(c[0]-o[0])*s)},${Math.round(o[1]+(c[1]-o[1])*s)},${Math.round(o[2]+(c[2]-o[2])*s)})`}function Be(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ue={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},tt=0;function rt(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function nt(e){let r=e.getAttribute("stroke"),s=e.getAttribute("fill");!r||r==="none"?Be("Element has no stroke \u2014 path will not be visible.",e):s&&s!=="none"&&s!=="transparent"&&Be("Element has a fill \u2014 it may obscure the stroke animation.",e);}function st(e,r,s){let o=document.createElement("div");o.setAttribute("data-svg-scroll-draw-debug",""),o.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 c(){let f=s==="x"?window.scrollX:window.scrollY,g=e-f,v=r-f,x=s==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${x?`left:${g}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${g}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;${x?`left:${v}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${v}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",c,{passive:true}),c(),o}function Re(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let g=parseFloat(f),v=o[c++]??g;return String(+(g+(v-g)*s).toFixed(4))})}function Xe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let s=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:c=1,fade:f=false,easing:g="linear",trigger:v={},stagger:x=0,direction:a="forward",once:y=false,debug:k=false,axis:T="y",scrollContainer:ge,autoReverse:oe=false,delay:Q=0,strokeColor:H,strokeWidth:N,fillOpacity:G,waypoints:j,velocityScale:ie=false,threshold:he=0,rootMargin:be="0px",repeat:W=0,repeatDelay:Z=0,morphTo:b,clip:q,autoplay:we=false,duration:ve=1e3,native:fe=true,onProgress:Y,onStart:$e,onComplete:me}=r,ee=q===true?"left":typeof q=="string"?q:false,ae=typeof g=="function"?g:de[g]??de.linear,Oe=ye(v.start??"top bottom"),Ne=ye(v.end??"bottom top"),I=typeof ge=="string"?document.querySelector(ge):ge??null,B=Array.isArray(H)?H[0]:null,P=Array.isArray(H)?H[1]:typeof H=="string"?H:null,R=Array.isArray(N)?N[0]:null,L=Array.isArray(N)?N[1]:typeof N=="number"?N:null,O=Array.isArray(G)?G[0]:null,D=Array.isArray(G)?G[1]:typeof G=="number"?G:null;function le(t){let n=t*100;switch(ee){case "right":return `inset(0 0 0 ${100-n}%)`;case "top":return `inset(0 0 ${100-n}% 0)`;case "bottom":return `inset(${100-n}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-n}% 0 0)`}}let M=ee?[]:Array.from(e.querySelectorAll(o)),$=[],U=[],te=0,re=0,A=false,V=false,S=0,Se=false,X=-1,Te=-1,C=false,ue=0,J=0,ne,Ce=null,se=new Set,Me=-1,ze=performance.now();function Ee(){return I?T==="x"?I.scrollLeft:I.scrollTop:T==="x"?window.scrollX:window.scrollY}function He(){return I?T==="x"?I.clientWidth:I.clientHeight:T==="x"?window.innerWidth:window.innerHeight}function We(){let t=e.getBoundingClientRect(),n,u,w;if(I){let F=I.getBoundingClientRect();n=T==="x"?t.left-F.left+I.scrollLeft:t.top-F.top+I.scrollTop,u=T==="x"?t.width:t.height,w=Ee();}else n=T==="x"?t.left:t.top,u=T==="x"?t.width:t.height,w=Ee();let z=xe({top:n,height:u},w,He(),Oe,Ne);te=z.tStart,re=z.tEnd,k&&process.env.NODE_ENV!=="production"&&(Ce?.remove(),Ce=st(te,re,T));}function je(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),ee){let u=n==="reverse"?1-t:t;e.style.clipPath=le(u);return}M.forEach((u,w)=>{u.style.strokeDashoffset=n==="reverse"?`${$[w]*t}`:`${$[w]*(1-t)}`,f&&(u.style.opacity=n==="reverse"?`${1-t}`:`${t}`),B&&P?u.style.stroke=De(B,P,t):P&&(u.style.stroke=P),R!==null&&L!==null?u.style.strokeWidth=`${R+(L-R)*t}`:L!==null&&(u.style.strokeWidth=`${L}`),O!==null&&D!==null?u.style.fillOpacity=`${O+(D-O)*t}`:D!==null&&(u.style.fillOpacity=`${D}`),b&&u.tagName.toLowerCase()==="path"&&U[w]&&u.setAttribute("d",Re(U[w],b,t));});}function Ae(){if(e.style.setProperty("--scroll-draw-progress","0"),ee){e.style.clipPath=le(0);return}M.forEach((t,n)=>{t.style.strokeDasharray=`${$[n]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${$[n]}`,f?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",B&&(t.style.stroke=B),R!==null&&(t.style.strokeWidth=`${R}`),O!==null&&(t.style.fillOpacity=`${O}`),b&&t.tagName.toLowerCase()==="path"&&U[n]&&t.setAttribute("d",U[n]);});}if(M.forEach(t=>{nt(t);let n=Le(t);$.push(n),t.tagName.toLowerCase()==="path"?U.push(t.getAttribute("d")??""):U.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=a==="reverse"?`${n}`:"0",f&&(t.style.opacity="1"),P&&(t.style.stroke=P),L!==null&&(t.style.strokeWidth=`${L}`),D!==null&&(t.style.fillOpacity=`${D}`),b&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",b)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=a==="reverse"?"0":`${n}`,f?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",B&&(t.style.stroke=B),R!==null&&(t.style.strokeWidth=`${R}`),O!==null&&(t.style.fillOpacity=`${O}`));}),ee){if(s)return e.style.clipPath=le(1),me?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=le(0);}else if(s)return me?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ye(){return !(fe===false||!rt()||!M.length||typeof g!="string"||!(g in Ue)||ee||T!=="y"||I||c!==1||x!==0||y||oe||ie!==false||b||j||W||Q>0||Y||$e||me||H!=null||N!=null||G!=null||(v.start??"top bottom").trim()!=="top bottom"||(v.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++tt}`,n=a==="reverse"?"0":"var(--ssd-len)",u=a==="reverse"?"var(--ssd-len)":"0",w=`stroke-dashoffset:${n};`,z=`stroke-dashoffset:${u};`;f&&(w+=`opacity:${a==="reverse"?1:0};`,z+=`opacity:${a==="reverse"?0:1};`);let F=document.createElement("style");F.setAttribute("data-svg-scroll-draw",""),F.textContent=`@keyframes ${t}{from{${w}}to{${z}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ue[g]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(F);function l(i,p){i.style.setProperty("--ssd-len",String($[p])),i.style.strokeDasharray=`${$[p]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}M.forEach(l);let d=false,E=-1;function m(){if(E>=0)return E;let i=e.getBoundingClientRect(),{tStart:p,tEnd:h}=xe({top:i.top,height:i.height},Ee(),He(),Oe,Ne);return ae(K(Ee(),p,h,c))}return {destroy(){M.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),F.remove();},replay(){d=false,E=-1,M.forEach(l);},pause(){d=true,M.forEach(i=>{i.style.animationPlayState="paused";});},resume(){d&&(d=false,M.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let p=Math.min(1,Math.max(0,i));E=p,d=true,M.forEach((h,ce)=>{h.classList.remove(t),h.style.strokeDashoffset=a==="reverse"?`${$[ce]*p}`:`${$[ce]*(1-p)}`,f&&(h.style.opacity=a==="reverse"?`${1-p}`:`${p}`);});},getProgress(){return m()}}}if(Ye())return Je();function Ke(){let t=Math.max(1,ve),n=0,u=0;function w(m){let i=true;if(ee){let p=Math.min(1,Math.max(0,m/t)),h=ae(p);ue=h,e.style.setProperty("--scroll-draw-progress",String(h)),e.style.clipPath=le(a==="reverse"?1-h:h),Y?.(h),p<1&&(i=false);}else M.forEach((p,h)=>{let ce=h*x*t,pe=Math.min(1,Math.max(0,(m-ce)/t)),_=ae(pe);p.style.strokeDashoffset=a==="reverse"?`${$[h]*_}`:`${$[h]*(1-_)}`,f&&(p.style.opacity=a==="reverse"?`${1-_}`:`${_}`),B&&P?p.style.stroke=De(B,P,_):P&&(p.style.stroke=P),R!==null&&L!==null?p.style.strokeWidth=`${R+(L-R)*_}`:L!==null&&(p.style.strokeWidth=`${L}`),O!==null&&D!==null?p.style.fillOpacity=`${O+(D-O)*_}`:D!==null&&(p.style.fillOpacity=`${D}`),b&&p.tagName.toLowerCase()==="path"&&U[h]&&p.setAttribute("d",Re(U[h],b,_)),h===0&&(Y?.(_),e.style.setProperty("--scroll-draw-progress",String(_))),pe<1&&(i=false);});if(j){let p=Math.min(1,Math.max(0,m/t)),h=ae(p);for(let ce in j){let pe=parseFloat(ce);h>=pe&&!se.has(pe)&&(se.add(pe),j[ce]?.());}}return i}function z(m){if(C)return;let i=m-n;V||(V=true,$e?.());let p=w(i);if(p&&!A){A=true,w(t*(1+Math.max(0,M.length-1)*x)),me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{n=performance.now(),V=false,A=false,se.clear(),Ae(),S=requestAnimationFrame(z);},Z));return}p||(S=requestAnimationFrame(z));}function F(){cancelAnimationFrame(S),clearTimeout(ne),n=performance.now(),u=0,C=false,V=false,A=false,J=0,se.clear(),Ae(),S=requestAnimationFrame(z);}let l=new IntersectionObserver(m=>{m.forEach(i=>{i.isIntersecting&&!(y&&A)?F():!i.isIntersecting&&!y&&!A&&(cancelAnimationFrame(S),clearTimeout(ne),n=null);});},{root:I??null,threshold:he,rootMargin:be}),d;function E(){clearTimeout(d),d=setTimeout(()=>{M.forEach((m,i)=>{$[i]=Le(m),m.style.strokeDasharray=`${$[i]}`;});},150);}return window.addEventListener("resize",E),window.addEventListener("orientationchange",E),Q>0?setTimeout(()=>l.observe(e),Q):l.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(ne),l.disconnect(),window.removeEventListener("resize",E),window.removeEventListener("orientationchange",E),clearTimeout(d);},replay(){J=0,F();},pause(){C||(C=true,u=performance.now()-n,cancelAnimationFrame(S));},resume(){C&&(C=false,n=performance.now()-u,S=requestAnimationFrame(z));},seek(m){let i=Math.min(1,Math.max(0,m));ue=i,C=true,u=i*t,n=performance.now()-u,cancelAnimationFrame(S),w(u);},getProgress(){return ue}}}if(we)return Ke();We();function ke(){if(!Se||C)return;let t=performance.now(),n=Ee(),u=c;if(ie!==false){let l=t-ze,d=l>0?Math.abs(n-(Me<0?n:Me))/l:0;u=c*Math.max(.2,1+d*(typeof ie=="number"?ie:1)*.04);}Me=n,ze=t;let w=oe?Te===-1||n>=Te?"forward":"reverse":a;Te=n;let z=re-te,F=true;if(ee){let l=ae(K(n,te,re,u));y&&!oe&&(X=Math.max(X,l),l=X),ue=l,e.style.setProperty("--scroll-draw-progress",String(l));let d=w==="reverse"?1-l:l;e.style.clipPath=le(d),Y?.(l),!V&&K(n,te,re,u)>0&&(V=true,$e?.()),l>=1&&!A?(A=true,me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{X=-1,V=false,A=false,e.style.clipPath=le(0);},Z))):l<1&&!y&&(A=false),S=requestAnimationFrame(ke);return}if(M.forEach((l,d)=>{let E=d*x*z,m=ae(K(n,te+E,re+E,u));y&&!oe&&(X=Math.max(X,m),m=X),ue=m,l.style.strokeDashoffset=w==="reverse"?`${$[d]*m}`:`${$[d]*(1-m)}`,f&&(l.style.opacity=w==="reverse"?`${1-m}`:`${m}`),B&&P?l.style.stroke=De(B,P,m):P&&(l.style.stroke=P),R!==null&&L!==null?l.style.strokeWidth=`${R+(L-R)*m}`:L!==null&&(l.style.strokeWidth=`${L}`),O!==null&&D!==null?l.style.fillOpacity=`${O+(D-O)*m}`:D!==null&&(l.style.fillOpacity=`${D}`),b&&l.tagName.toLowerCase()==="path"&&U[d]&&l.setAttribute("d",Re(U[d],b,m)),d===0&&(Y?.(m),e.style.setProperty("--scroll-draw-progress",String(m))),m<1&&(F=false);}),j){let l=ae(K(n,te,re,u));for(let d in j){let E=parseFloat(d);l>=E&&!se.has(E)&&(se.add(E),j[d]?.());}}!V&&K(n,te,re,u)>0&&(V=true,$e?.()),F&&!A?(A=true,me?.(),J<(W==="infinite"?1/0:W??0)&&(J++,ne=setTimeout(()=>{X=-1,V=false,A=false,se.clear(),Ae();},Z))):!F&&!y&&(A=false),S=requestAnimationFrame(ke);}let Fe=new IntersectionObserver(t=>{t.forEach(n=>{Se=n.isIntersecting,Se&&!C?S=requestAnimationFrame(ke):cancelAnimationFrame(S);});},{root:I??null,threshold:he,rootMargin:be}),Ie;function Pe(){clearTimeout(Ie),Ie=setTimeout(()=>{M.forEach((t,n)=>{$[n]=Le(t),t.style.strokeDasharray=`${$[n]}`;}),We();},150);}return window.addEventListener("resize",Pe),window.addEventListener("orientationchange",Pe),Q>0?setTimeout(()=>Fe.observe(e),Q):Fe.observe(e),{destroy(){cancelAnimationFrame(S),clearTimeout(ne),Fe.disconnect(),window.removeEventListener("resize",Pe),window.removeEventListener("orientationchange",Pe),clearTimeout(Ie),Ce?.remove();},replay(){X=-1,Te=-1,Me=-1,V=false,A=false,J=0,C=false,se.clear(),clearTimeout(ne),Ae();},pause(){C=true,cancelAnimationFrame(S);},resume(){C&&(C=false,Se&&(S=requestAnimationFrame(ke)));},seek(t){let n=Math.min(1,Math.max(0,t));ue=n,X=n,C=true,cancelAnimationFrame(S),je(n,a);},getProgress(){return ue}}}function at(e,r={}){let[s,o]=useState(0),c=useRef(r);c.current=r;let f=useRef(-1);return useEffect(()=>{if(typeof window>"u")return;if(window.matchMedia("(prefers-reduced-motion: reduce)").matches){o(1);return}let g=typeof e=="string"?document.querySelector(e):e.current;if(!g)return;let v=g,{axis:x="y",scrollContainer:a,trigger:y={}}=c.current,k=typeof a=="string"?document.querySelector(a):a??null,T=ye(y.start??"top bottom"),ge=ye(y.end??"bottom top"),oe=0,Q=0,H=false,N=0;function G(){return k?x==="x"?k.scrollLeft:k.scrollTop:x==="x"?window.scrollX:window.scrollY}function j(){return k?x==="x"?k.clientWidth:k.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function ie(){let b=v.getBoundingClientRect(),q=G(),we=x==="x"?b.left:b.top,ve=x==="x"?b.width:b.height,fe=xe({top:we,height:ve},q,j(),T,ge);oe=fe.tStart,Q=fe.tEnd;}function he(){if(!H)return;let{speed:b=1,easing:q="linear",once:we=false}=c.current,ve=typeof q=="function"?q:de[q]??de.linear,fe=K(G(),oe,Q,b),Y=ve(fe);we&&(f.current=Math.max(f.current,Y),Y=f.current),o(Y),N=requestAnimationFrame(he);}let be=new IntersectionObserver(b=>{b.forEach(q=>{H=q.isIntersecting,H?N=requestAnimationFrame(he):cancelAnimationFrame(N);});},{root:k??null,threshold:0});ie(),be.observe(v);let W;function Z(){clearTimeout(W),W=setTimeout(ie,150);}return window.addEventListener("resize",Z),window.addEventListener("orientationchange",Z),()=>{cancelAnimationFrame(N),clearTimeout(W),be.disconnect(),window.removeEventListener("resize",Z),window.removeEventListener("orientationchange",Z);}},[]),s}function vt({children:e,className:r,style:s,...o}){let c=useRef(null);return useEffect(()=>{if(!c.current)return;let f=Xe(c.current,o);return ()=>f.destroy()},[]),jsx("div",{ref:c,className:r,style:s,children:e})}export{vt as ScrollDraw,at as useScrollDrawProgress};
|
package/dist/solid/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var solidJs=require('solid-js');var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${X?`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(o),window.addEventListener("scroll",f,{passive:true}),f(),o}function Re(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),f=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,d=>{let p=parseFloat(d),L=o[f++]??p;return String(+(p+(L-p)*n).toFixed(4))})}function Se(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:f=1,fade:d=false,easing:p="linear",trigger:L={},stagger:X=0,direction:y="forward",once:U=false,debug:Ge=false,axis:E="y",scrollContainer:ce,autoReverse:Z=false,delay:pe=0,strokeColor:H,strokeWidth:R,fillOpacity:V,waypoints:ee,velocityScale:te=false,threshold:ze=0,rootMargin:qe="0px",repeat:j=0,repeatDelay:ke=0,morphTo:P,clip:me,native:Be=true,onProgress:de,onStart:ye,onComplete:J}=r,W=me===true?"left":typeof me=="string"?me:false,re=typeof p=="function"?p:ve[p]??ve.linear,Te=we(L.start??"top bottom"),Ae=we(L.end??"bottom top"),b=typeof ce=="string"?document.querySelector(ce):ce??null,I=Array.isArray(H)?H[0]:null,$=Array.isArray(H)?H[1]:typeof H=="string"?H:null,x=Array.isArray(R)?R[0]:null,S=Array.isArray(R)?R[1]:typeof R=="number"?R:null,k=Array.isArray(V)?V[0]:null,T=Array.isArray(V)?V[1]:typeof V=="number"?V:null;function _(t){let s=t*100;switch(W){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 v=W?[]:Array.from(e.querySelectorAll(o)),g=[],C=[],O=0,F=0,D=false,G=false,N=0,ne=false,A=-1,se=-1,z=false,oe=0,K=0,ie,ge=null,ae=new Set,le=-1,Me=performance.now();function Q(){return b?E==="x"?b.scrollLeft:b.scrollTop:E==="x"?window.scrollX:window.scrollY}function Le(){return b?E==="x"?b.clientWidth:b.clientHeight:E==="x"?window.innerWidth:window.innerHeight}function De(){let t=e.getBoundingClientRect(),s,a,m;if(b){let w=b.getBoundingClientRect();s=E==="x"?t.left-w.left+b.scrollLeft:t.top-w.top+b.scrollTop,a=E==="x"?t.width:t.height,m=Q();}else s=E==="x"?t.left:t.top,a=E==="x"?t.width:t.height,m=Q();let q=$e({top:s,height:a},m,Le(),Te,Ae);O=q.tStart,F=q.tEnd,Ge&&process.env.NODE_ENV!=="production"&&(ge?.remove(),ge=Ye(O,F,E));}function _e(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),W){let a=s==="reverse"?1-t:t;e.style.clipPath=_(a);return}v.forEach((a,m)=>{a.style.strokeDashoffset=s==="reverse"?`${g[m]*t}`:`${g[m]*(1-t)}`,d&&(a.style.opacity=s==="reverse"?`${1-t}`:`${t}`),I&&$?a.style.stroke=xe(I,$,t):$&&(a.style.stroke=$),x!==null&&S!==null?a.style.strokeWidth=`${x+(S-x)*t}`:S!==null&&(a.style.strokeWidth=`${S}`),k!==null&&T!==null?a.style.fillOpacity=`${k+(T-k)*t}`:T!==null&&(a.style.fillOpacity=`${T}`),P&&a.tagName.toLowerCase()==="path"&&C[m]&&a.setAttribute("d",Re(C[m],P,t));});}function Pe(){if(e.style.setProperty("--scroll-draw-progress","0"),W){e.style.clipPath=_(0);return}v.forEach((t,s)=>{t.style.strokeDasharray=`${g[s]}`,t.style.strokeDashoffset=y==="reverse"?"0":`${g[s]}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",I&&(t.style.stroke=I),x!==null&&(t.style.strokeWidth=`${x}`),k!==null&&(t.style.fillOpacity=`${k}`),P&&t.tagName.toLowerCase()==="path"&&C[s]&&t.setAttribute("d",C[s]);});}if(v.forEach(t=>{Qe(t);let s=Ee(t);g.push(s),t.tagName.toLowerCase()==="path"?C.push(t.getAttribute("d")??""):C.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?`${s}`:"0",d&&(t.style.opacity="1"),$&&(t.style.stroke=$),S!==null&&(t.style.strokeWidth=`${S}`),T!==null&&(t.style.fillOpacity=`${T}`),P&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",P)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=y==="reverse"?"0":`${s}`,d?t.style.opacity=y==="reverse"?"1":"0":t.style.opacity="",I&&(t.style.stroke=I),x!==null&&(t.style.strokeWidth=`${x}`),k!==null&&(t.style.fillOpacity=`${k}`));}),W){if(n)return e.style.clipPath=_(1),J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=_(0);}else if(n)return J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Xe(){return !(Be===false||!Ke()||!v.length||typeof p!="string"||!(p in He)||W||E!=="y"||b||f!==1||X!==0||U||Z||te!==false||P||ee||j||pe>0||de||ye||J||H!=null||R!=null||V!=null||(L.start??"top bottom").trim()!=="top bottom"||(L.end??"bottom top").trim()!=="bottom top")}function Ue(){let t=`svg-scroll-draw-${++Je}`,s=y==="reverse"?"0":"var(--ssd-len)",a=y==="reverse"?"var(--ssd-len)":"0",m=`stroke-dashoffset:${s};`,q=`stroke-dashoffset:${a};`;d&&(m+=`opacity:${y==="reverse"?1:0};`,q+=`opacity:${y==="reverse"?0:1};`);let w=document.createElement("style");w.setAttribute("data-svg-scroll-draw",""),w.textContent=`@keyframes ${t}{from{${m}}to{${q}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${He[p]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(w);function i(u,M){u.style.setProperty("--ssd-len",String(g[M])),u.style.strokeDasharray=`${g[M]}`,u.style.strokeDashoffset="",u.style.opacity="",u.style.animationPlayState="",u.classList.add(t);}v.forEach(i);let l=false,h=-1;function c(){if(h>=0)return h;let u=e.getBoundingClientRect(),{tStart:M,tEnd:Y}=$e({top:u.top,height:u.height},Q(),Le(),Te,Ae);return re(B(Q(),M,Y,f))}return {destroy(){v.forEach(u=>{u.classList.remove(t),u.style.removeProperty("--ssd-len"),u.style.animationPlayState="";}),w.remove();},replay(){l=false,h=-1,v.forEach(i);},pause(){l=true,v.forEach(u=>{u.style.animationPlayState="paused";});},resume(){l&&(l=false,v.forEach(u=>{u.style.animationPlayState="running";}));},seek(u){let M=Math.min(1,Math.max(0,u));h=M,l=true,v.forEach((Y,Ie)=>{Y.classList.remove(t),Y.style.strokeDashoffset=y==="reverse"?`${g[Ie]*M}`:`${g[Ie]*(1-M)}`,d&&(Y.style.opacity=y==="reverse"?`${1-M}`:`${M}`);});},getProgress(){return c()}}}if(Xe())return Ue();De();function ue(){if(!ne||z)return;let t=performance.now(),s=Q(),a=f;if(te!==false){let i=t-Me,l=i>0?Math.abs(s-(le<0?s:le))/i:0;a=f*Math.max(.2,1+l*(typeof te=="number"?te:1)*.04);}le=s,Me=t;let m=Z?se===-1||s>=se?"forward":"reverse":y;se=s;let q=F-O,w=true;if(W){let i=re(B(s,O,F,a));U&&!Z&&(A=Math.max(A,i),i=A),oe=i,e.style.setProperty("--scroll-draw-progress",String(i));let l=m==="reverse"?1-i:i;e.style.clipPath=_(l),de?.(i),!G&&B(s,O,F,a)>0&&(G=true,ye?.()),i>=1&&!D?(D=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{A=-1,G=false,D=false,e.style.clipPath=_(0);},ke))):i<1&&!U&&(D=false),N=requestAnimationFrame(ue);return}if(v.forEach((i,l)=>{let h=l*X*q,c=re(B(s,O+h,F+h,a));U&&!Z&&(A=Math.max(A,c),c=A),oe=c,i.style.strokeDashoffset=m==="reverse"?`${g[l]*c}`:`${g[l]*(1-c)}`,d&&(i.style.opacity=m==="reverse"?`${1-c}`:`${c}`),I&&$?i.style.stroke=xe(I,$,c):$&&(i.style.stroke=$),x!==null&&S!==null?i.style.strokeWidth=`${x+(S-x)*c}`:S!==null&&(i.style.strokeWidth=`${S}`),k!==null&&T!==null?i.style.fillOpacity=`${k+(T-k)*c}`:T!==null&&(i.style.fillOpacity=`${T}`),P&&i.tagName.toLowerCase()==="path"&&C[l]&&i.setAttribute("d",Re(C[l],P,c)),l===0&&(de?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(w=false);}),ee){let i=re(B(s,O,F,a));for(let l in ee){let h=parseFloat(l);i>=h&&!ae.has(h)&&(ae.add(h),ee[l]?.());}}!G&&B(s,O,F,a)>0&&(G=true,ye?.()),w&&!D?(D=true,J?.(),K<(j==="infinite"?1/0:j??0)&&(K++,ie=setTimeout(()=>{A=-1,G=false,D=false,ae.clear(),Pe();},ke))):!w&&!U&&(D=false),N=requestAnimationFrame(ue);}let he=new IntersectionObserver(t=>{t.forEach(s=>{ne=s.isIntersecting,ne&&!z?N=requestAnimationFrame(ue):cancelAnimationFrame(N);});},{root:b??null,threshold:ze,rootMargin:qe}),be;function fe(){clearTimeout(be),be=setTimeout(()=>{v.forEach((t,s)=>{g[s]=Ee(t),t.style.strokeDasharray=`${g[s]}`;}),De();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),pe>0?setTimeout(()=>he.observe(e),pe):he.observe(e),{destroy(){cancelAnimationFrame(N),clearTimeout(ie),he.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(be),ge?.remove();},replay(){A=-1,se=-1,le=-1,G=false,D=false,K=0,z=false,ae.clear(),clearTimeout(ie),Pe();},pause(){z=true,cancelAnimationFrame(N);},resume(){z&&(z=false,ne&&(N=requestAnimationFrame(ue)));},seek(t){let s=Math.min(1,Math.max(0,t));oe=s,A=s,z=true,cancelAnimationFrame(N),_e(s,y);},getProgress(){return oe}}}function st(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Se(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),o=>{r=o;}}function ot(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Se(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:o=>{r=o;},getInstance:()=>n}}exports.createScrollDraw=ot;exports.useScrollDraw=st;
|
|
1
|
+
'use strict';var solidJs=require('solid-js');function Ze({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),d=Math.sqrt(o),m=0,b=[];for(let u=0;u<n;u++){let h=Math.pow(d,u);b.push(h),m+=h;}let $=[0],R=0;for(let u=0;u<n;u++)R+=b[u]/m,$.push(R);return u=>{if(u<=0)return 0;if(u>=1)return 1;for(let h=0;h<n;h++)if(u<=$[h+1]){let se=(u-$[h])/($[h+1]-$[h]);if(h===0)return se*(2-se);let D=1-Math.pow(o,h);return D+(1-D)*(2*se-1)*(2*se-1)}return 1}}function et({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),o=Math.max(.1,r),d=n<=1?o/4:o/(2*Math.PI)*Math.asin(1/n);return m=>m<=0?0:m>=1?1:n*Math.pow(2,-10*m)*Math.sin((m-d)*(2*Math.PI)/o)+1}var Ae={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:Ze(),elastic:et()};function ke(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",o="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:o}}function We(e,r,n,o){switch(o){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function ze(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 we(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(n+o)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function tt(e,r,n){return Math.min(n,Math.max(r,e))}function ne(e,r,n,o){return n===r?0:tt((e-r)/(n-r)*o,0,1)}function Le(e,r,n,o,d){let m=We(e.top,e.height,r,o.element)-ze(o.viewport,n),b=We(e.top,e.height,r,d.element)-ze(d.viewport,n);return {tStart:m,tEnd:b}}function qe(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 o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function ve(e,r,n){let o=qe(e),d=qe(r);return !o||!d?e:`rgb(${Math.round(o[0]+(d[0]-o[0])*n)},${Math.round(o[1]+(d[1]-o[1])*n)},${Math.round(o[2]+(d[2]-o[2])*n)})`}function Ve(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ge={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},rt=0;function nt(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function st(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Ve("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Ve("Element has a fill \u2014 it may obscure the stroke animation.",e);}function ot(e,r,n){let o=document.createElement("div");o.setAttribute("data-svg-scroll-draw-debug",""),o.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 d(){let m=n==="x"?window.scrollX:window.scrollY,b=e-m,$=r-m,R=n==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${R?`left:${b}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${b}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;${R?`left:${$}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${$}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",d,{passive:true}),d(),o}function De(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),d=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,m=>{let b=parseFloat(m),$=o[d++]??b;return String(+(b+($-b)*n).toFixed(4))})}function Pe(e,r={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:d=1,fade:m=false,easing:b="linear",trigger:$={},stagger:R=0,direction:u="forward",once:h=false,debug:se=false,axis:D="y",scrollContainer:Ee,autoReverse:fe=false,delay:ae=0,strokeColor:j,strokeWidth:J,fillOpacity:K,waypoints:Q,velocityScale:ce=false,threshold:Ie=0,rootMargin:Fe="0px",repeat:Y=0,repeatDelay:$e=0,morphTo:H,clip:xe,autoplay:Xe=false,duration:Ue=1e3,native:je=true,onProgress:le,onStart:me,onComplete:oe}=r,G=xe===true?"left":typeof xe=="string"?xe:false,Z=typeof b=="function"?b:Ae[b]??Ae.linear,Ce=ke($.start??"top bottom"),Oe=ke($.end??"bottom top"),P=typeof Ee=="string"?document.querySelector(Ee):Ee??null,N=Array.isArray(j)?j[0]:null,S=Array.isArray(j)?j[1]:typeof j=="string"?j:null,I=Array.isArray(J)?J[0]:null,T=Array.isArray(J)?J[1]:typeof J=="number"?J:null,F=Array.isArray(K)?K[0]:null,A=Array.isArray(K)?K[1]:typeof K=="number"?K:null;function ee(t){let s=t*100;switch(G){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 x=G?[]:Array.from(e.querySelectorAll(o)),v=[],W=[],B=0,_=0,M=false,O=false,E=0,pe=false,z=-1,de=-1,k=false,te=0,V=0,X,Me=null,U=new Set,ye=-1,Re=performance.now();function ue(){return P?D==="x"?P.scrollLeft:P.scrollTop:D==="x"?window.scrollX:window.scrollY}function He(){return P?D==="x"?P.clientWidth:P.clientHeight:D==="x"?window.innerWidth:window.innerHeight}function Ne(){let t=e.getBoundingClientRect(),s,l,g;if(P){let L=P.getBoundingClientRect();s=D==="x"?t.left-L.left+P.scrollLeft:t.top-L.top+P.scrollTop,l=D==="x"?t.width:t.height,g=ue();}else s=D==="x"?t.left:t.top,l=D==="x"?t.width:t.height,g=ue();let C=Le({top:s,height:l},g,He(),Ce,Oe);B=C.tStart,_=C.tEnd,se&&process.env.NODE_ENV!=="production"&&(Me?.remove(),Me=ot(B,_,D));}function Je(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),G){let l=s==="reverse"?1-t:t;e.style.clipPath=ee(l);return}x.forEach((l,g)=>{l.style.strokeDashoffset=s==="reverse"?`${v[g]*t}`:`${v[g]*(1-t)}`,m&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),N&&S?l.style.stroke=ve(N,S,t):S&&(l.style.stroke=S),I!==null&&T!==null?l.style.strokeWidth=`${I+(T-I)*t}`:T!==null&&(l.style.strokeWidth=`${T}`),F!==null&&A!==null?l.style.fillOpacity=`${F+(A-F)*t}`:A!==null&&(l.style.fillOpacity=`${A}`),H&&l.tagName.toLowerCase()==="path"&&W[g]&&l.setAttribute("d",De(W[g],H,t));});}function he(){if(e.style.setProperty("--scroll-draw-progress","0"),G){e.style.clipPath=ee(0);return}x.forEach((t,s)=>{t.style.strokeDasharray=`${v[s]}`,t.style.strokeDashoffset=u==="reverse"?"0":`${v[s]}`,m?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",N&&(t.style.stroke=N),I!==null&&(t.style.strokeWidth=`${I}`),F!==null&&(t.style.fillOpacity=`${F}`),H&&t.tagName.toLowerCase()==="path"&&W[s]&&t.setAttribute("d",W[s]);});}if(x.forEach(t=>{st(t);let s=we(t);v.push(s),t.tagName.toLowerCase()==="path"?W.push(t.getAttribute("d")??""):W.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?`${s}`:"0",m&&(t.style.opacity="1"),S&&(t.style.stroke=S),T!==null&&(t.style.strokeWidth=`${T}`),A!==null&&(t.style.fillOpacity=`${A}`),H&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",H)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=u==="reverse"?"0":`${s}`,m?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",N&&(t.style.stroke=N),I!==null&&(t.style.strokeWidth=`${I}`),F!==null&&(t.style.fillOpacity=`${F}`));}),G){if(n)return e.style.clipPath=ee(1),oe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=ee(0);}else if(n)return oe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Ke(){return !(je===false||!nt()||!x.length||typeof b!="string"||!(b in Ge)||G||D!=="y"||P||d!==1||R!==0||h||fe||ce!==false||H||Q||Y||ae>0||le||me||oe||j!=null||J!=null||K!=null||($.start??"top bottom").trim()!=="top bottom"||($.end??"bottom top").trim()!=="bottom top")}function Qe(){let t=`svg-scroll-draw-${++rt}`,s=u==="reverse"?"0":"var(--ssd-len)",l=u==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${s};`,C=`stroke-dashoffset:${l};`;m&&(g+=`opacity:${u==="reverse"?1:0};`,C+=`opacity:${u==="reverse"?0:1};`);let L=document.createElement("style");L.setAttribute("data-svg-scroll-draw",""),L.textContent=`@keyframes ${t}{from{${g}}to{${C}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ge[b]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(L);function a(i,c){i.style.setProperty("--ssd-len",String(v[c])),i.style.strokeDasharray=`${v[c]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}x.forEach(a);let p=false,w=-1;function f(){if(w>=0)return w;let i=e.getBoundingClientRect(),{tStart:c,tEnd:y}=Le({top:i.top,height:i.height},ue(),He(),Ce,Oe);return Z(ne(ue(),c,y,d))}return {destroy(){x.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),L.remove();},replay(){p=false,w=-1,x.forEach(a);},pause(){p=true,x.forEach(i=>{i.style.animationPlayState="paused";});},resume(){p&&(p=false,x.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let c=Math.min(1,Math.max(0,i));w=c,p=true,x.forEach((y,re)=>{y.classList.remove(t),y.style.strokeDashoffset=u==="reverse"?`${v[re]*c}`:`${v[re]*(1-c)}`,m&&(y.style.opacity=u==="reverse"?`${1-c}`:`${c}`);});},getProgress(){return f()}}}if(Ke())return Qe();function Ye(){let t=Math.max(1,Ue),s=0,l=0;function g(f){let i=true;if(G){let c=Math.min(1,Math.max(0,f/t)),y=Z(c);te=y,e.style.setProperty("--scroll-draw-progress",String(y)),e.style.clipPath=ee(u==="reverse"?1-y:y),le?.(y),c<1&&(i=false);}else x.forEach((c,y)=>{let re=y*R*t,ie=Math.min(1,Math.max(0,(f-re)/t)),q=Z(ie);c.style.strokeDashoffset=u==="reverse"?`${v[y]*q}`:`${v[y]*(1-q)}`,m&&(c.style.opacity=u==="reverse"?`${1-q}`:`${q}`),N&&S?c.style.stroke=ve(N,S,q):S&&(c.style.stroke=S),I!==null&&T!==null?c.style.strokeWidth=`${I+(T-I)*q}`:T!==null&&(c.style.strokeWidth=`${T}`),F!==null&&A!==null?c.style.fillOpacity=`${F+(A-F)*q}`:A!==null&&(c.style.fillOpacity=`${A}`),H&&c.tagName.toLowerCase()==="path"&&W[y]&&c.setAttribute("d",De(W[y],H,q)),y===0&&(le?.(q),e.style.setProperty("--scroll-draw-progress",String(q))),ie<1&&(i=false);});if(Q){let c=Math.min(1,Math.max(0,f/t)),y=Z(c);for(let re in Q){let ie=parseFloat(re);y>=ie&&!U.has(ie)&&(U.add(ie),Q[re]?.());}}return i}function C(f){if(k)return;let i=f-s;O||(O=true,me?.());let c=g(i);if(c&&!M){M=true,g(t*(1+Math.max(0,x.length-1)*R)),oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{s=performance.now(),O=false,M=false,U.clear(),he(),E=requestAnimationFrame(C);},$e));return}c||(E=requestAnimationFrame(C));}function L(){cancelAnimationFrame(E),clearTimeout(X),s=performance.now(),l=0,k=false,O=false,M=false,V=0,U.clear(),he(),E=requestAnimationFrame(C);}let a=new IntersectionObserver(f=>{f.forEach(i=>{i.isIntersecting&&!(h&&M)?L():!i.isIntersecting&&!h&&!M&&(cancelAnimationFrame(E),clearTimeout(X),s=null);});},{root:P??null,threshold:Ie,rootMargin:Fe}),p;function w(){clearTimeout(p),p=setTimeout(()=>{x.forEach((f,i)=>{v[i]=we(f),f.style.strokeDasharray=`${v[i]}`;});},150);}return window.addEventListener("resize",w),window.addEventListener("orientationchange",w),ae>0?setTimeout(()=>a.observe(e),ae):a.observe(e),{destroy(){cancelAnimationFrame(E),clearTimeout(X),a.disconnect(),window.removeEventListener("resize",w),window.removeEventListener("orientationchange",w),clearTimeout(p);},replay(){V=0,L();},pause(){k||(k=true,l=performance.now()-s,cancelAnimationFrame(E));},resume(){k&&(k=false,s=performance.now()-l,E=requestAnimationFrame(C));},seek(f){let i=Math.min(1,Math.max(0,f));te=i,k=true,l=i*t,s=performance.now()-l,cancelAnimationFrame(E),g(l);},getProgress(){return te}}}if(Xe)return Ye();Ne();function ge(){if(!pe||k)return;let t=performance.now(),s=ue(),l=d;if(ce!==false){let a=t-Re,p=a>0?Math.abs(s-(ye<0?s:ye))/a:0;l=d*Math.max(.2,1+p*(typeof ce=="number"?ce:1)*.04);}ye=s,Re=t;let g=fe?de===-1||s>=de?"forward":"reverse":u;de=s;let C=_-B,L=true;if(G){let a=Z(ne(s,B,_,l));h&&!fe&&(z=Math.max(z,a),a=z),te=a,e.style.setProperty("--scroll-draw-progress",String(a));let p=g==="reverse"?1-a:a;e.style.clipPath=ee(p),le?.(a),!O&&ne(s,B,_,l)>0&&(O=true,me?.()),a>=1&&!M?(M=true,oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{z=-1,O=false,M=false,e.style.clipPath=ee(0);},$e))):a<1&&!h&&(M=false),E=requestAnimationFrame(ge);return}if(x.forEach((a,p)=>{let w=p*R*C,f=Z(ne(s,B+w,_+w,l));h&&!fe&&(z=Math.max(z,f),f=z),te=f,a.style.strokeDashoffset=g==="reverse"?`${v[p]*f}`:`${v[p]*(1-f)}`,m&&(a.style.opacity=g==="reverse"?`${1-f}`:`${f}`),N&&S?a.style.stroke=ve(N,S,f):S&&(a.style.stroke=S),I!==null&&T!==null?a.style.strokeWidth=`${I+(T-I)*f}`:T!==null&&(a.style.strokeWidth=`${T}`),F!==null&&A!==null?a.style.fillOpacity=`${F+(A-F)*f}`:A!==null&&(a.style.fillOpacity=`${A}`),H&&a.tagName.toLowerCase()==="path"&&W[p]&&a.setAttribute("d",De(W[p],H,f)),p===0&&(le?.(f),e.style.setProperty("--scroll-draw-progress",String(f))),f<1&&(L=false);}),Q){let a=Z(ne(s,B,_,l));for(let p in Q){let w=parseFloat(p);a>=w&&!U.has(w)&&(U.add(w),Q[p]?.());}}!O&&ne(s,B,_,l)>0&&(O=true,me?.()),L&&!M?(M=true,oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{z=-1,O=false,M=false,U.clear(),he();},$e))):!L&&!h&&(M=false),E=requestAnimationFrame(ge);}let Se=new IntersectionObserver(t=>{t.forEach(s=>{pe=s.isIntersecting,pe&&!k?E=requestAnimationFrame(ge):cancelAnimationFrame(E);});},{root:P??null,threshold:Ie,rootMargin:Fe}),Te;function be(){clearTimeout(Te),Te=setTimeout(()=>{x.forEach((t,s)=>{v[s]=we(t),t.style.strokeDasharray=`${v[s]}`;}),Ne();},150);}return window.addEventListener("resize",be),window.addEventListener("orientationchange",be),ae>0?setTimeout(()=>Se.observe(e),ae):Se.observe(e),{destroy(){cancelAnimationFrame(E),clearTimeout(X),Se.disconnect(),window.removeEventListener("resize",be),window.removeEventListener("orientationchange",be),clearTimeout(Te),Me?.remove();},replay(){z=-1,de=-1,ye=-1,O=false,M=false,V=0,k=false,U.clear(),clearTimeout(X),he();},pause(){k=true,cancelAnimationFrame(E);},resume(){k&&(k=false,pe&&(E=requestAnimationFrame(ge)));},seek(t){let s=Math.min(1,Math.max(0,t));te=s,z=s,k=true,cancelAnimationFrame(E),Je(s,u);},getProgress(){return te}}}function ct(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Pe(r,e));}),solidJs.onCleanup(()=>{n?.destroy();}),o=>{r=o;}}function mt(e={}){let r,n;return solidJs.onMount(()=>{r&&(n=Pe(r,e));}),solidJs.onCleanup(()=>{n?.destroy(),n=void 0;}),{ref:o=>{r=o;},getInstance:()=>n}}exports.createScrollDraw=mt;exports.useScrollDraw=ct;
|