svg-scroll-draw 0.4.0 → 0.6.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 +21 -1
- package/dist/angular/index.d.ts +21 -1
- package/dist/angular/index.mjs +3 -3
- package/dist/astro/index.cjs +3 -0
- package/dist/astro/index.d.mts +79 -0
- package/dist/astro/index.d.ts +79 -0
- package/dist/astro/index.mjs +3 -0
- package/dist/cdn/svg-scroll-draw.global.js +3 -3
- package/dist/group/index.cjs +3 -0
- package/dist/group/index.d.mts +89 -0
- package/dist/group/index.d.ts +89 -0
- package/dist/group/index.mjs +3 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.mjs +3 -3
- package/dist/nuxt/index.cjs +3 -0
- package/dist/nuxt/index.d.mts +166 -0
- package/dist/nuxt/index.d.ts +166 -0
- package/dist/nuxt/index.mjs +3 -0
- package/dist/react/index.cjs +3 -3
- package/dist/react/index.d.mts +13 -1
- package/dist/react/index.d.ts +13 -1
- package/dist/react/index.mjs +3 -3
- package/dist/solid/index.cjs +3 -3
- package/dist/solid/index.d.mts +21 -1
- package/dist/solid/index.d.ts +21 -1
- package/dist/solid/index.mjs +3 -3
- package/dist/svelte/index.cjs +3 -3
- package/dist/svelte/index.d.mts +21 -1
- package/dist/svelte/index.d.ts +21 -1
- package/dist/svelte/index.mjs +3 -3
- package/dist/vue/index.cjs +3 -3
- package/dist/vue/index.d.mts +13 -1
- package/dist/vue/index.d.ts +13 -1
- package/dist/vue/index.mjs +3 -3
- package/package.json +23 -2
package/dist/svelte/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${
|
|
1
|
+
'use strict';var ne={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)};function oe(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 ye(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 he(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 se(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 Ce(e,r,n){return Math.min(n,Math.max(r,e))}function H(e,r,n,o){return n===r?0:Ce((e-r)/(n-r)*o,0,1)}function we(e,r,n,o,a){let c=ye(e.top,e.height,r,o.element)-he(o.viewport,n),u=ye(e.top,e.height,r,a.element)-he(a.viewport,n);return {tStart:c,tEnd:u}}function be(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 ie(e,r,n){let o=be(e),a=be(r);return !o||!a?e:`rgb(${Math.round(o[0]+(a[0]-o[0])*n)},${Math.round(o[1]+(a[1]-o[1])*n)},${Math.round(o[2]+(a[2]-o[2])*n)})`}function ve(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Fe(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 Ne(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 a(){let c=n==="x"?window.scrollX:window.scrollY,u=e-c,E=r-c,P=n==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${P?`left:${u}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${u}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;${P?`left:${E}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${E}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 xe(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,c=>{let u=parseFloat(c),E=o[a++]??u;return String(+(u+(E-u)*n).toFixed(4))})}function X(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:a=1,fade:c=false,easing:u="linear",trigger:E={},stagger:P=0,direction:k="forward",once:ae=false,debug:Ee=false,axis:b="y",scrollContainer:_,autoReverse:le=false,delay:ce=0,strokeColor:D,strokeWidth:I,waypoints:j,velocityScale:J=false,threshold:ke=0,rootMargin:$e="0px",repeat:ue=0,repeatDelay:Ae=0,morphTo:$,onProgress:Se,onStart:Te,onComplete:fe}=r,pe=typeof u=="function"?u:ne[u]??ne.linear,De=oe(E.start??"top bottom"),Ie=oe(E.end??"bottom top"),p=typeof _=="string"?document.querySelector(_):_??null,v=Array.isArray(D)?D[0]:null,g=Array.isArray(D)?D[1]:typeof D=="string"?D:null,y=Array.isArray(I)?I[0]:null,h=Array.isArray(I)?I[1]:typeof I=="number"?I:null,N=Array.from(e.querySelectorAll(o)),w=[],x=[],L=0,M=0,O=false,W=false,A=0,R=false,C=-1,V=-1,S=false,K=0,Q=0,U,Y=null,z=new Set,G=-1,me=performance.now();function Z(){return p?b==="x"?p.scrollLeft:p.scrollTop:b==="x"?window.scrollX:window.scrollY}function Le(){return p?b==="x"?p.clientWidth:p.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function de(){let t=e.getBoundingClientRect(),s,i,m;if(p){let F=p.getBoundingClientRect();s=b==="x"?t.left-F.left+p.scrollLeft:t.top-F.top+p.scrollTop,i=b==="x"?t.width:t.height,m=Z();}else s=b==="x"?t.left:t.top,i=b==="x"?t.width:t.height,m=Z();let B=we({top:s,height:i},m,Le(),De,Ie);L=B.tStart,M=B.tEnd,Ee&&process.env.NODE_ENV!=="production"&&(Y?.remove(),Y=Ne(L,M,b));}function Me(t,s){N.forEach((i,m)=>{i.style.strokeDashoffset=s==="reverse"?`${w[m]*t}`:`${w[m]*(1-t)}`,c&&(i.style.opacity=s==="reverse"?`${1-t}`:`${t}`),v&&g?i.style.stroke=ie(v,g,t):g&&(i.style.stroke=g),y!==null&&h!==null?i.style.strokeWidth=`${y+(h-y)*t}`:h!==null&&(i.style.strokeWidth=`${h}`),$&&i.tagName.toLowerCase()==="path"&&x[m]&&i.setAttribute("d",xe(x[m],$,t));});}function ge(){N.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=k==="reverse"?"0":`${w[s]}`,c?t.style.opacity=k==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`),$&&t.tagName.toLowerCase()==="path"&&x[s]&&t.setAttribute("d",x[s]);});}if(N.forEach(t=>{Fe(t);let s=se(t);w.push(s),t.tagName.toLowerCase()==="path"?x.push(t.getAttribute("d")??""):x.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=k==="reverse"?`${s}`:"0",c&&(t.style.opacity="1"),g&&(t.style.stroke=g),h!==null&&(t.style.strokeWidth=`${h}`),$&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",$)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=k==="reverse"?"0":`${s}`,c?t.style.opacity=k==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`));}),n)return fe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};de();function ee(){if(!R||S)return;let t=performance.now(),s=Z(),i=a;if(J!==false){let l=t-me,d=l>0?Math.abs(s-(G<0?s:G))/l:0;i=a*Math.max(.2,1+d*(typeof J=="number"?J:1)*.04);}G=s,me=t;let m=le?V===-1||s>=V?"forward":"reverse":k;V=s;let B=M-L,F=true;if(N.forEach((l,d)=>{let T=d*P*B,f=pe(H(s,L+T,M+T,i));ae&&!le&&(C=Math.max(C,f),f=C),K=f,l.style.strokeDashoffset=m==="reverse"?`${w[d]*f}`:`${w[d]*(1-f)}`,c&&(l.style.opacity=m==="reverse"?`${1-f}`:`${f}`),v&&g?l.style.stroke=ie(v,g,f):g&&(l.style.stroke=g),y!==null&&h!==null?l.style.strokeWidth=`${y+(h-y)*f}`:h!==null&&(l.style.strokeWidth=`${h}`),$&&l.tagName.toLowerCase()==="path"&&x[d]&&l.setAttribute("d",xe(x[d],$,f)),d===0&&Se?.(f),f<1&&(F=false);}),j){let l=pe(H(s,L,M,i));for(let d in j){let T=parseFloat(d);l>=T&&!z.has(T)&&(z.add(T),j[d]?.());}}!W&&H(s,L,M,i)>0&&(W=true,Te?.()),F&&!O?(O=true,fe?.(),Q<(ue==="infinite"?1/0:ue??0)&&(Q++,U=setTimeout(()=>{C=-1,W=false,O=false,z.clear(),ge();},Ae))):!F&&!ae&&(O=false),A=requestAnimationFrame(ee);}let te=new IntersectionObserver(t=>{t.forEach(s=>{R=s.isIntersecting,R&&!S?A=requestAnimationFrame(ee):cancelAnimationFrame(A);});},{root:p??null,threshold:ke,rootMargin:$e}),re;function q(){clearTimeout(re),re=setTimeout(()=>{N.forEach((t,s)=>{w[s]=se(t),t.style.strokeDasharray=`${w[s]}`;}),de();},150);}return window.addEventListener("resize",q),window.addEventListener("orientationchange",q),ce>0?setTimeout(()=>te.observe(e),ce):te.observe(e),{destroy(){cancelAnimationFrame(A),clearTimeout(U),te.disconnect(),window.removeEventListener("resize",q),window.removeEventListener("orientationchange",q),clearTimeout(re),Y?.remove();},replay(){C=-1,V=-1,G=-1,W=false,O=false,Q=0,S=false,z.clear(),clearTimeout(U),ge();},pause(){S=true,cancelAnimationFrame(A);},resume(){S&&(S=false,R&&(A=requestAnimationFrame(ee)));},seek(t){let s=Math.min(1,Math.max(0,t));K=s,C=s,S=true,cancelAnimationFrame(A),Me(s,k);},getProgress(){return K}}}function Ve(e,r={}){let n=X(e,r);return {update(o){n.destroy(),n=X(e,o);},destroy(){n.destroy();}}}function ze(e={}){let r=null;function n(o){return r=X(o,e),{destroy(){r?.destroy(),r=null;}}}return {action:n,getInstance:()=>r}}exports.createScrollDraw=ze;exports.scrollDraw=Ve;
|
package/dist/svelte/index.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ interface ScrollDrawOptions {
|
|
|
19
19
|
scrollContainer?: string | Element;
|
|
20
20
|
/** Automatically reverse the animation when the user scrolls back up. */
|
|
21
21
|
autoReverse?: boolean;
|
|
22
|
-
/** Delay in milliseconds before the engine starts observing
|
|
22
|
+
/** Delay in milliseconds before the engine starts observing. */
|
|
23
23
|
delay?: number;
|
|
24
24
|
/** Animate stroke color. Single string = static override. Tuple = interpolate from → to. */
|
|
25
25
|
strokeColor?: string | [string, string];
|
|
@@ -27,6 +27,18 @@ interface ScrollDrawOptions {
|
|
|
27
27
|
strokeWidth?: number | [number, number];
|
|
28
28
|
/** Fire callbacks at specific progress thresholds (0–1). Resets on replay(). */
|
|
29
29
|
waypoints?: Record<number, () => void>;
|
|
30
|
+
/** Scale animation speed by scroll velocity — faster scrolling = faster draw. Pass a number to control sensitivity (default 1). */
|
|
31
|
+
velocityScale?: boolean | number;
|
|
32
|
+
/** IntersectionObserver threshold (0–1). Default 0. */
|
|
33
|
+
threshold?: number;
|
|
34
|
+
/** IntersectionObserver rootMargin. Default "0px". */
|
|
35
|
+
rootMargin?: string;
|
|
36
|
+
/** Repeat the animation N times after completion. Use 'infinite' to loop forever. */
|
|
37
|
+
repeat?: number | 'infinite';
|
|
38
|
+
/** Milliseconds to wait between repeats. Default 0. */
|
|
39
|
+
repeatDelay?: number;
|
|
40
|
+
/** Target path `d` attribute to morph toward as the animation progresses. Paths must have compatible structures. */
|
|
41
|
+
morphTo?: string;
|
|
30
42
|
onProgress?: (alpha: number) => void;
|
|
31
43
|
onStart?: () => void;
|
|
32
44
|
onComplete?: () => void;
|
|
@@ -35,6 +47,14 @@ interface ScrollDrawInstance {
|
|
|
35
47
|
destroy: () => void;
|
|
36
48
|
/** Reset and replay the animation from the beginning. */
|
|
37
49
|
replay: () => void;
|
|
50
|
+
/** Pause the animation at the current progress. */
|
|
51
|
+
pause: () => void;
|
|
52
|
+
/** Resume a paused animation. */
|
|
53
|
+
resume: () => void;
|
|
54
|
+
/** Jump to a specific progress value (0–1) and pause. */
|
|
55
|
+
seek: (progress: number) => void;
|
|
56
|
+
/** Returns current draw progress (0–1). */
|
|
57
|
+
getProgress: () => number;
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
/**
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ interface ScrollDrawOptions {
|
|
|
19
19
|
scrollContainer?: string | Element;
|
|
20
20
|
/** Automatically reverse the animation when the user scrolls back up. */
|
|
21
21
|
autoReverse?: boolean;
|
|
22
|
-
/** Delay in milliseconds before the engine starts observing
|
|
22
|
+
/** Delay in milliseconds before the engine starts observing. */
|
|
23
23
|
delay?: number;
|
|
24
24
|
/** Animate stroke color. Single string = static override. Tuple = interpolate from → to. */
|
|
25
25
|
strokeColor?: string | [string, string];
|
|
@@ -27,6 +27,18 @@ interface ScrollDrawOptions {
|
|
|
27
27
|
strokeWidth?: number | [number, number];
|
|
28
28
|
/** Fire callbacks at specific progress thresholds (0–1). Resets on replay(). */
|
|
29
29
|
waypoints?: Record<number, () => void>;
|
|
30
|
+
/** Scale animation speed by scroll velocity — faster scrolling = faster draw. Pass a number to control sensitivity (default 1). */
|
|
31
|
+
velocityScale?: boolean | number;
|
|
32
|
+
/** IntersectionObserver threshold (0–1). Default 0. */
|
|
33
|
+
threshold?: number;
|
|
34
|
+
/** IntersectionObserver rootMargin. Default "0px". */
|
|
35
|
+
rootMargin?: string;
|
|
36
|
+
/** Repeat the animation N times after completion. Use 'infinite' to loop forever. */
|
|
37
|
+
repeat?: number | 'infinite';
|
|
38
|
+
/** Milliseconds to wait between repeats. Default 0. */
|
|
39
|
+
repeatDelay?: number;
|
|
40
|
+
/** Target path `d` attribute to morph toward as the animation progresses. Paths must have compatible structures. */
|
|
41
|
+
morphTo?: string;
|
|
30
42
|
onProgress?: (alpha: number) => void;
|
|
31
43
|
onStart?: () => void;
|
|
32
44
|
onComplete?: () => void;
|
|
@@ -35,6 +47,14 @@ interface ScrollDrawInstance {
|
|
|
35
47
|
destroy: () => void;
|
|
36
48
|
/** Reset and replay the animation from the beginning. */
|
|
37
49
|
replay: () => void;
|
|
50
|
+
/** Pause the animation at the current progress. */
|
|
51
|
+
pause: () => void;
|
|
52
|
+
/** Resume a paused animation. */
|
|
53
|
+
resume: () => void;
|
|
54
|
+
/** Jump to a specific progress value (0–1) and pause. */
|
|
55
|
+
seek: (progress: number) => void;
|
|
56
|
+
/** Returns current draw progress (0–1). */
|
|
57
|
+
getProgress: () => number;
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
/**
|
package/dist/svelte/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${
|
|
1
|
+
var ne={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)};function oe(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 ye(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 he(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 se(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 Ce(e,r,n){return Math.min(n,Math.max(r,e))}function H(e,r,n,o){return n===r?0:Ce((e-r)/(n-r)*o,0,1)}function we(e,r,n,o,a){let c=ye(e.top,e.height,r,o.element)-he(o.viewport,n),u=ye(e.top,e.height,r,a.element)-he(a.viewport,n);return {tStart:c,tEnd:u}}function be(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 ie(e,r,n){let o=be(e),a=be(r);return !o||!a?e:`rgb(${Math.round(o[0]+(a[0]-o[0])*n)},${Math.round(o[1]+(a[1]-o[1])*n)},${Math.round(o[2]+(a[2]-o[2])*n)})`}function ve(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Fe(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 Ne(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 a(){let c=n==="x"?window.scrollX:window.scrollY,u=e-c,E=r-c,P=n==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${P?`left:${u}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${u}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;${P?`left:${E}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${E}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 xe(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,c=>{let u=parseFloat(c),E=o[a++]??u;return String(+(u+(E-u)*n).toFixed(4))})}function X(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:a=1,fade:c=false,easing:u="linear",trigger:E={},stagger:P=0,direction:k="forward",once:ae=false,debug:Ee=false,axis:b="y",scrollContainer:_,autoReverse:le=false,delay:ce=0,strokeColor:D,strokeWidth:I,waypoints:j,velocityScale:J=false,threshold:ke=0,rootMargin:$e="0px",repeat:ue=0,repeatDelay:Ae=0,morphTo:$,onProgress:Se,onStart:Te,onComplete:fe}=r,pe=typeof u=="function"?u:ne[u]??ne.linear,De=oe(E.start??"top bottom"),Ie=oe(E.end??"bottom top"),p=typeof _=="string"?document.querySelector(_):_??null,v=Array.isArray(D)?D[0]:null,g=Array.isArray(D)?D[1]:typeof D=="string"?D:null,y=Array.isArray(I)?I[0]:null,h=Array.isArray(I)?I[1]:typeof I=="number"?I:null,N=Array.from(e.querySelectorAll(o)),w=[],x=[],L=0,M=0,O=false,W=false,A=0,R=false,C=-1,V=-1,S=false,K=0,Q=0,U,Y=null,z=new Set,G=-1,me=performance.now();function Z(){return p?b==="x"?p.scrollLeft:p.scrollTop:b==="x"?window.scrollX:window.scrollY}function Le(){return p?b==="x"?p.clientWidth:p.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function de(){let t=e.getBoundingClientRect(),s,i,m;if(p){let F=p.getBoundingClientRect();s=b==="x"?t.left-F.left+p.scrollLeft:t.top-F.top+p.scrollTop,i=b==="x"?t.width:t.height,m=Z();}else s=b==="x"?t.left:t.top,i=b==="x"?t.width:t.height,m=Z();let B=we({top:s,height:i},m,Le(),De,Ie);L=B.tStart,M=B.tEnd,Ee&&process.env.NODE_ENV!=="production"&&(Y?.remove(),Y=Ne(L,M,b));}function Me(t,s){N.forEach((i,m)=>{i.style.strokeDashoffset=s==="reverse"?`${w[m]*t}`:`${w[m]*(1-t)}`,c&&(i.style.opacity=s==="reverse"?`${1-t}`:`${t}`),v&&g?i.style.stroke=ie(v,g,t):g&&(i.style.stroke=g),y!==null&&h!==null?i.style.strokeWidth=`${y+(h-y)*t}`:h!==null&&(i.style.strokeWidth=`${h}`),$&&i.tagName.toLowerCase()==="path"&&x[m]&&i.setAttribute("d",xe(x[m],$,t));});}function ge(){N.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=k==="reverse"?"0":`${w[s]}`,c?t.style.opacity=k==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`),$&&t.tagName.toLowerCase()==="path"&&x[s]&&t.setAttribute("d",x[s]);});}if(N.forEach(t=>{Fe(t);let s=se(t);w.push(s),t.tagName.toLowerCase()==="path"?x.push(t.getAttribute("d")??""):x.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=k==="reverse"?`${s}`:"0",c&&(t.style.opacity="1"),g&&(t.style.stroke=g),h!==null&&(t.style.strokeWidth=`${h}`),$&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",$)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=k==="reverse"?"0":`${s}`,c?t.style.opacity=k==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`));}),n)return fe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};de();function ee(){if(!R||S)return;let t=performance.now(),s=Z(),i=a;if(J!==false){let l=t-me,d=l>0?Math.abs(s-(G<0?s:G))/l:0;i=a*Math.max(.2,1+d*(typeof J=="number"?J:1)*.04);}G=s,me=t;let m=le?V===-1||s>=V?"forward":"reverse":k;V=s;let B=M-L,F=true;if(N.forEach((l,d)=>{let T=d*P*B,f=pe(H(s,L+T,M+T,i));ae&&!le&&(C=Math.max(C,f),f=C),K=f,l.style.strokeDashoffset=m==="reverse"?`${w[d]*f}`:`${w[d]*(1-f)}`,c&&(l.style.opacity=m==="reverse"?`${1-f}`:`${f}`),v&&g?l.style.stroke=ie(v,g,f):g&&(l.style.stroke=g),y!==null&&h!==null?l.style.strokeWidth=`${y+(h-y)*f}`:h!==null&&(l.style.strokeWidth=`${h}`),$&&l.tagName.toLowerCase()==="path"&&x[d]&&l.setAttribute("d",xe(x[d],$,f)),d===0&&Se?.(f),f<1&&(F=false);}),j){let l=pe(H(s,L,M,i));for(let d in j){let T=parseFloat(d);l>=T&&!z.has(T)&&(z.add(T),j[d]?.());}}!W&&H(s,L,M,i)>0&&(W=true,Te?.()),F&&!O?(O=true,fe?.(),Q<(ue==="infinite"?1/0:ue??0)&&(Q++,U=setTimeout(()=>{C=-1,W=false,O=false,z.clear(),ge();},Ae))):!F&&!ae&&(O=false),A=requestAnimationFrame(ee);}let te=new IntersectionObserver(t=>{t.forEach(s=>{R=s.isIntersecting,R&&!S?A=requestAnimationFrame(ee):cancelAnimationFrame(A);});},{root:p??null,threshold:ke,rootMargin:$e}),re;function q(){clearTimeout(re),re=setTimeout(()=>{N.forEach((t,s)=>{w[s]=se(t),t.style.strokeDasharray=`${w[s]}`;}),de();},150);}return window.addEventListener("resize",q),window.addEventListener("orientationchange",q),ce>0?setTimeout(()=>te.observe(e),ce):te.observe(e),{destroy(){cancelAnimationFrame(A),clearTimeout(U),te.disconnect(),window.removeEventListener("resize",q),window.removeEventListener("orientationchange",q),clearTimeout(re),Y?.remove();},replay(){C=-1,V=-1,G=-1,W=false,O=false,Q=0,S=false,z.clear(),clearTimeout(U),ge();},pause(){S=true,cancelAnimationFrame(A);},resume(){S&&(S=false,R&&(A=requestAnimationFrame(ee)));},seek(t){let s=Math.min(1,Math.max(0,t));K=s,C=s,S=true,cancelAnimationFrame(A),Me(s,k);},getProgress(){return K}}}function Ve(e,r={}){let n=X(e,r);return {update(o){n.destroy(),n=X(e,o);},destroy(){n.destroy();}}}function ze(e={}){let r=null;function n(o){return r=X(o,e),{destroy(){r?.destroy(),r=null;}}}return {action:n,getInstance:()=>r}}export{ze as createScrollDraw,Ve as scrollDraw};
|
package/dist/vue/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;${
|
|
1
|
+
'use strict';var vue=require('vue');var re={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)};function ne(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[o="top",n="bottom"]=r.split(/\s+/).filter(Boolean);return {element:o,viewport:n}}function ye(e,r,o,n){switch(n){case "top":return e+o;case "center":return e+o+r/2;case "bottom":return e+o+r;default:return e+o}}function be(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 oe(e){let r=e.tagName.toLowerCase();if(r==="rect"){let o=parseFloat(e.getAttribute("width")??"0"),n=parseFloat(e.getAttribute("height")??"0");return 2*(o+n)}if(r==="circle"){let o=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*o}return e.getTotalLength()}function Ne(e,r,o){return Math.min(o,Math.max(r,e))}function H(e,r,o,n){return o===r?0:Ne((e-r)/(o-r)*n,0,1)}function we(e,r,o,n,i){let u=ye(e.top,e.height,r,n.element)-be(n.viewport,o),c=ye(e.top,e.height,r,i.element)-be(i.viewport,o);return {tStart:u,tEnd:c}}function he(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 o=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(o)return [parseInt(o[1],16),parseInt(o[2],16),parseInt(o[3],16)];let n=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return n?[parseInt(n[1]),parseInt(n[2]),parseInt(n[3])]:null}function se(e,r,o){let n=he(e),i=he(r);return !n||!i?e:`rgb(${Math.round(n[0]+(i[0]-n[0])*o)},${Math.round(n[1]+(i[1]-n[1])*o)},${Math.round(n[2]+(i[2]-n[2])*o)})`}function ve(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Pe(e){let r=e.getAttribute("stroke"),o=e.getAttribute("fill");!r||r==="none"?ve("Element has no stroke \u2014 path will not be visible.",e):o&&o!=="none"&&o!=="transparent"&&ve("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Re(e,r,o){let n=document.createElement("div");n.setAttribute("data-svg-scroll-draw-debug",""),n.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 i(){let u=o==="x"?window.scrollX:window.scrollY,c=e-u,S=r-u,P=o==="x";n.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${P?`left:${c}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${c}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;${P?`left:${S}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${S}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",i,{passive:true}),i(),n}function xe(e,r,o){let n=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),i=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let c=parseFloat(u),S=n[i++]??c;return String(+(c+(S-c)*o).toFixed(4))})}function ie(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:i=1,fade:u=false,easing:c="linear",trigger:S={},stagger:P=0,direction:E="forward",once:ae=false,debug:$e=false,axis:h="y",scrollContainer:X,autoReverse:le=false,delay:ue=0,strokeColor:T,strokeWidth:C,waypoints:_,velocityScale:j=false,threshold:Ae=0,rootMargin:De="0px",repeat:ce=0,repeatDelay:Te=0,morphTo:k,onProgress:Ce,onStart:Me,onComplete:fe}=r,me=typeof c=="function"?c:re[c]??re.linear,Fe=ne(S.start??"top bottom"),Le=ne(S.end??"bottom top"),m=typeof X=="string"?document.querySelector(X):X??null,v=Array.isArray(T)?T[0]:null,g=Array.isArray(T)?T[1]:typeof T=="string"?T:null,y=Array.isArray(C)?C[0]:null,b=Array.isArray(C)?C[1]:typeof C=="number"?C:null,O=Array.from(e.querySelectorAll(n)),w=[],x=[],M=0,F=0,N=false,R=false,$=0,W=false,L=-1,V=-1,A=false,U=0,J=0,K,Q=null,z=new Set,G=-1,de=performance.now();function Y(){return m?h==="x"?m.scrollLeft:m.scrollTop:h==="x"?window.scrollX:window.scrollY}function Ie(){return m?h==="x"?m.clientWidth:m.clientHeight:h==="x"?window.innerWidth:window.innerHeight}function pe(){let t=e.getBoundingClientRect(),s,a,d;if(m){let I=m.getBoundingClientRect();s=h==="x"?t.left-I.left+m.scrollLeft:t.top-I.top+m.scrollTop,a=h==="x"?t.width:t.height,d=Y();}else s=h==="x"?t.left:t.top,a=h==="x"?t.width:t.height,d=Y();let q=we({top:s,height:a},d,Ie(),Fe,Le);M=q.tStart,F=q.tEnd,$e&&process.env.NODE_ENV!=="production"&&(Q?.remove(),Q=Re(M,F,h));}function Oe(t,s){O.forEach((a,d)=>{a.style.strokeDashoffset=s==="reverse"?`${w[d]*t}`:`${w[d]*(1-t)}`,u&&(a.style.opacity=s==="reverse"?`${1-t}`:`${t}`),v&&g?a.style.stroke=se(v,g,t):g&&(a.style.stroke=g),y!==null&&b!==null?a.style.strokeWidth=`${y+(b-y)*t}`:b!==null&&(a.style.strokeWidth=`${b}`),k&&a.tagName.toLowerCase()==="path"&&x[d]&&a.setAttribute("d",xe(x[d],k,t));});}function ge(){O.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=E==="reverse"?"0":`${w[s]}`,u?t.style.opacity=E==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`),k&&t.tagName.toLowerCase()==="path"&&x[s]&&t.setAttribute("d",x[s]);});}if(O.forEach(t=>{Pe(t);let s=oe(t);w.push(s),t.tagName.toLowerCase()==="path"?x.push(t.getAttribute("d")??""):x.push(""),o?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=E==="reverse"?`${s}`:"0",u&&(t.style.opacity="1"),g&&(t.style.stroke=g),b!==null&&(t.style.strokeWidth=`${b}`),k&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",k)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=E==="reverse"?"0":`${s}`,u?t.style.opacity=E==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`));}),o)return fe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};pe();function Z(){if(!W||A)return;let t=performance.now(),s=Y(),a=i;if(j!==false){let l=t-de,p=l>0?Math.abs(s-(G<0?s:G))/l:0;a=i*Math.max(.2,1+p*(typeof j=="number"?j:1)*.04);}G=s,de=t;let d=le?V===-1||s>=V?"forward":"reverse":E;V=s;let q=F-M,I=true;if(O.forEach((l,p)=>{let D=p*P*q,f=me(H(s,M+D,F+D,a));ae&&!le&&(L=Math.max(L,f),f=L),U=f,l.style.strokeDashoffset=d==="reverse"?`${w[p]*f}`:`${w[p]*(1-f)}`,u&&(l.style.opacity=d==="reverse"?`${1-f}`:`${f}`),v&&g?l.style.stroke=se(v,g,f):g&&(l.style.stroke=g),y!==null&&b!==null?l.style.strokeWidth=`${y+(b-y)*f}`:b!==null&&(l.style.strokeWidth=`${b}`),k&&l.tagName.toLowerCase()==="path"&&x[p]&&l.setAttribute("d",xe(x[p],k,f)),p===0&&Ce?.(f),f<1&&(I=false);}),_){let l=me(H(s,M,F,a));for(let p in _){let D=parseFloat(p);l>=D&&!z.has(D)&&(z.add(D),_[p]?.());}}!R&&H(s,M,F,a)>0&&(R=true,Me?.()),I&&!N?(N=true,fe?.(),J<(ce==="infinite"?1/0:ce??0)&&(J++,K=setTimeout(()=>{L=-1,R=false,N=false,z.clear(),ge();},Te))):!I&&!ae&&(N=false),$=requestAnimationFrame(Z);}let ee=new IntersectionObserver(t=>{t.forEach(s=>{W=s.isIntersecting,W&&!A?$=requestAnimationFrame(Z):cancelAnimationFrame($);});},{root:m??null,threshold:Ae,rootMargin:De}),te;function B(){clearTimeout(te),te=setTimeout(()=>{O.forEach((t,s)=>{w[s]=oe(t),t.style.strokeDasharray=`${w[s]}`;}),pe();},150);}return window.addEventListener("resize",B),window.addEventListener("orientationchange",B),ue>0?setTimeout(()=>ee.observe(e),ue):ee.observe(e),{destroy(){cancelAnimationFrame($),clearTimeout(K),ee.disconnect(),window.removeEventListener("resize",B),window.removeEventListener("orientationchange",B),clearTimeout(te),Q?.remove();},replay(){L=-1,V=-1,G=-1,R=false,N=false,J=0,A=false,z.clear(),clearTimeout(K),ge();},pause(){A=true,cancelAnimationFrame($);},resume(){A&&(A=false,W&&($=requestAnimationFrame(Z)));},seek(t){let s=Math.min(1,Math.max(0,t));U=s,L=s,A=true,cancelAnimationFrame($),Oe(s,E);},getProgress(){return U}}}function Xe(e={}){let r=vue.ref(null);return vue.onMounted(()=>{if(!r.value)return;let o=ie(r.value,e);vue.onUnmounted(()=>o.destroy());}),r}var _e=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 i=ie(o.value,n);vue.onUnmounted(()=>i.destroy());}),()=>vue.h("div",{ref:o},r.default?.())}});exports.ScrollDraw=_e;exports.useScrollDraw=Xe;
|
package/dist/vue/index.d.mts
CHANGED
|
@@ -21,7 +21,7 @@ interface ScrollDrawOptions {
|
|
|
21
21
|
scrollContainer?: string | Element;
|
|
22
22
|
/** Automatically reverse the animation when the user scrolls back up. */
|
|
23
23
|
autoReverse?: boolean;
|
|
24
|
-
/** Delay in milliseconds before the engine starts observing
|
|
24
|
+
/** Delay in milliseconds before the engine starts observing. */
|
|
25
25
|
delay?: number;
|
|
26
26
|
/** Animate stroke color. Single string = static override. Tuple = interpolate from → to. */
|
|
27
27
|
strokeColor?: string | [string, string];
|
|
@@ -29,6 +29,18 @@ interface ScrollDrawOptions {
|
|
|
29
29
|
strokeWidth?: number | [number, number];
|
|
30
30
|
/** Fire callbacks at specific progress thresholds (0–1). Resets on replay(). */
|
|
31
31
|
waypoints?: Record<number, () => void>;
|
|
32
|
+
/** Scale animation speed by scroll velocity — faster scrolling = faster draw. Pass a number to control sensitivity (default 1). */
|
|
33
|
+
velocityScale?: boolean | number;
|
|
34
|
+
/** IntersectionObserver threshold (0–1). Default 0. */
|
|
35
|
+
threshold?: number;
|
|
36
|
+
/** IntersectionObserver rootMargin. Default "0px". */
|
|
37
|
+
rootMargin?: string;
|
|
38
|
+
/** Repeat the animation N times after completion. Use 'infinite' to loop forever. */
|
|
39
|
+
repeat?: number | 'infinite';
|
|
40
|
+
/** Milliseconds to wait between repeats. Default 0. */
|
|
41
|
+
repeatDelay?: number;
|
|
42
|
+
/** Target path `d` attribute to morph toward as the animation progresses. Paths must have compatible structures. */
|
|
43
|
+
morphTo?: string;
|
|
32
44
|
onProgress?: (alpha: number) => void;
|
|
33
45
|
onStart?: () => void;
|
|
34
46
|
onComplete?: () => void;
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface ScrollDrawOptions {
|
|
|
21
21
|
scrollContainer?: string | Element;
|
|
22
22
|
/** Automatically reverse the animation when the user scrolls back up. */
|
|
23
23
|
autoReverse?: boolean;
|
|
24
|
-
/** Delay in milliseconds before the engine starts observing
|
|
24
|
+
/** Delay in milliseconds before the engine starts observing. */
|
|
25
25
|
delay?: number;
|
|
26
26
|
/** Animate stroke color. Single string = static override. Tuple = interpolate from → to. */
|
|
27
27
|
strokeColor?: string | [string, string];
|
|
@@ -29,6 +29,18 @@ interface ScrollDrawOptions {
|
|
|
29
29
|
strokeWidth?: number | [number, number];
|
|
30
30
|
/** Fire callbacks at specific progress thresholds (0–1). Resets on replay(). */
|
|
31
31
|
waypoints?: Record<number, () => void>;
|
|
32
|
+
/** Scale animation speed by scroll velocity — faster scrolling = faster draw. Pass a number to control sensitivity (default 1). */
|
|
33
|
+
velocityScale?: boolean | number;
|
|
34
|
+
/** IntersectionObserver threshold (0–1). Default 0. */
|
|
35
|
+
threshold?: number;
|
|
36
|
+
/** IntersectionObserver rootMargin. Default "0px". */
|
|
37
|
+
rootMargin?: string;
|
|
38
|
+
/** Repeat the animation N times after completion. Use 'infinite' to loop forever. */
|
|
39
|
+
repeat?: number | 'infinite';
|
|
40
|
+
/** Milliseconds to wait between repeats. Default 0. */
|
|
41
|
+
repeatDelay?: number;
|
|
42
|
+
/** Target path `d` attribute to morph toward as the animation progresses. Paths must have compatible structures. */
|
|
43
|
+
morphTo?: string;
|
|
32
44
|
onProgress?: (alpha: number) => void;
|
|
33
45
|
onStart?: () => void;
|
|
34
46
|
onComplete?: () => void;
|
package/dist/vue/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;${
|
|
1
|
+
import {defineComponent,ref,onMounted,onUnmounted,h}from'vue';var re={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)};function ne(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[o="top",n="bottom"]=r.split(/\s+/).filter(Boolean);return {element:o,viewport:n}}function ye(e,r,o,n){switch(n){case "top":return e+o;case "center":return e+o+r/2;case "bottom":return e+o+r;default:return e+o}}function be(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 oe(e){let r=e.tagName.toLowerCase();if(r==="rect"){let o=parseFloat(e.getAttribute("width")??"0"),n=parseFloat(e.getAttribute("height")??"0");return 2*(o+n)}if(r==="circle"){let o=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*o}return e.getTotalLength()}function Ne(e,r,o){return Math.min(o,Math.max(r,e))}function H(e,r,o,n){return o===r?0:Ne((e-r)/(o-r)*n,0,1)}function we(e,r,o,n,i){let u=ye(e.top,e.height,r,n.element)-be(n.viewport,o),c=ye(e.top,e.height,r,i.element)-be(i.viewport,o);return {tStart:u,tEnd:c}}function he(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 o=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(o)return [parseInt(o[1],16),parseInt(o[2],16),parseInt(o[3],16)];let n=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return n?[parseInt(n[1]),parseInt(n[2]),parseInt(n[3])]:null}function se(e,r,o){let n=he(e),i=he(r);return !n||!i?e:`rgb(${Math.round(n[0]+(i[0]-n[0])*o)},${Math.round(n[1]+(i[1]-n[1])*o)},${Math.round(n[2]+(i[2]-n[2])*o)})`}function ve(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Pe(e){let r=e.getAttribute("stroke"),o=e.getAttribute("fill");!r||r==="none"?ve("Element has no stroke \u2014 path will not be visible.",e):o&&o!=="none"&&o!=="transparent"&&ve("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Re(e,r,o){let n=document.createElement("div");n.setAttribute("data-svg-scroll-draw-debug",""),n.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 i(){let u=o==="x"?window.scrollX:window.scrollY,c=e-u,S=r-u,P=o==="x";n.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${P?`left:${c}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${c}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;${P?`left:${S}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${S}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",i,{passive:true}),i(),n}function xe(e,r,o){let n=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),i=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let c=parseFloat(u),S=n[i++]??c;return String(+(c+(S-c)*o).toFixed(4))})}function ie(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:i=1,fade:u=false,easing:c="linear",trigger:S={},stagger:P=0,direction:E="forward",once:ae=false,debug:$e=false,axis:h="y",scrollContainer:X,autoReverse:le=false,delay:ue=0,strokeColor:T,strokeWidth:C,waypoints:_,velocityScale:j=false,threshold:Ae=0,rootMargin:De="0px",repeat:ce=0,repeatDelay:Te=0,morphTo:k,onProgress:Ce,onStart:Me,onComplete:fe}=r,me=typeof c=="function"?c:re[c]??re.linear,Fe=ne(S.start??"top bottom"),Le=ne(S.end??"bottom top"),m=typeof X=="string"?document.querySelector(X):X??null,v=Array.isArray(T)?T[0]:null,g=Array.isArray(T)?T[1]:typeof T=="string"?T:null,y=Array.isArray(C)?C[0]:null,b=Array.isArray(C)?C[1]:typeof C=="number"?C:null,O=Array.from(e.querySelectorAll(n)),w=[],x=[],M=0,F=0,N=false,R=false,$=0,W=false,L=-1,V=-1,A=false,U=0,J=0,K,Q=null,z=new Set,G=-1,de=performance.now();function Y(){return m?h==="x"?m.scrollLeft:m.scrollTop:h==="x"?window.scrollX:window.scrollY}function Ie(){return m?h==="x"?m.clientWidth:m.clientHeight:h==="x"?window.innerWidth:window.innerHeight}function pe(){let t=e.getBoundingClientRect(),s,a,d;if(m){let I=m.getBoundingClientRect();s=h==="x"?t.left-I.left+m.scrollLeft:t.top-I.top+m.scrollTop,a=h==="x"?t.width:t.height,d=Y();}else s=h==="x"?t.left:t.top,a=h==="x"?t.width:t.height,d=Y();let q=we({top:s,height:a},d,Ie(),Fe,Le);M=q.tStart,F=q.tEnd,$e&&process.env.NODE_ENV!=="production"&&(Q?.remove(),Q=Re(M,F,h));}function Oe(t,s){O.forEach((a,d)=>{a.style.strokeDashoffset=s==="reverse"?`${w[d]*t}`:`${w[d]*(1-t)}`,u&&(a.style.opacity=s==="reverse"?`${1-t}`:`${t}`),v&&g?a.style.stroke=se(v,g,t):g&&(a.style.stroke=g),y!==null&&b!==null?a.style.strokeWidth=`${y+(b-y)*t}`:b!==null&&(a.style.strokeWidth=`${b}`),k&&a.tagName.toLowerCase()==="path"&&x[d]&&a.setAttribute("d",xe(x[d],k,t));});}function ge(){O.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=E==="reverse"?"0":`${w[s]}`,u?t.style.opacity=E==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`),k&&t.tagName.toLowerCase()==="path"&&x[s]&&t.setAttribute("d",x[s]);});}if(O.forEach(t=>{Pe(t);let s=oe(t);w.push(s),t.tagName.toLowerCase()==="path"?x.push(t.getAttribute("d")??""):x.push(""),o?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=E==="reverse"?`${s}`:"0",u&&(t.style.opacity="1"),g&&(t.style.stroke=g),b!==null&&(t.style.strokeWidth=`${b}`),k&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",k)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=E==="reverse"?"0":`${s}`,u?t.style.opacity=E==="reverse"?"1":"0":t.style.opacity="",v&&(t.style.stroke=v),y!==null&&(t.style.strokeWidth=`${y}`));}),o)return fe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};pe();function Z(){if(!W||A)return;let t=performance.now(),s=Y(),a=i;if(j!==false){let l=t-de,p=l>0?Math.abs(s-(G<0?s:G))/l:0;a=i*Math.max(.2,1+p*(typeof j=="number"?j:1)*.04);}G=s,de=t;let d=le?V===-1||s>=V?"forward":"reverse":E;V=s;let q=F-M,I=true;if(O.forEach((l,p)=>{let D=p*P*q,f=me(H(s,M+D,F+D,a));ae&&!le&&(L=Math.max(L,f),f=L),U=f,l.style.strokeDashoffset=d==="reverse"?`${w[p]*f}`:`${w[p]*(1-f)}`,u&&(l.style.opacity=d==="reverse"?`${1-f}`:`${f}`),v&&g?l.style.stroke=se(v,g,f):g&&(l.style.stroke=g),y!==null&&b!==null?l.style.strokeWidth=`${y+(b-y)*f}`:b!==null&&(l.style.strokeWidth=`${b}`),k&&l.tagName.toLowerCase()==="path"&&x[p]&&l.setAttribute("d",xe(x[p],k,f)),p===0&&Ce?.(f),f<1&&(I=false);}),_){let l=me(H(s,M,F,a));for(let p in _){let D=parseFloat(p);l>=D&&!z.has(D)&&(z.add(D),_[p]?.());}}!R&&H(s,M,F,a)>0&&(R=true,Me?.()),I&&!N?(N=true,fe?.(),J<(ce==="infinite"?1/0:ce??0)&&(J++,K=setTimeout(()=>{L=-1,R=false,N=false,z.clear(),ge();},Te))):!I&&!ae&&(N=false),$=requestAnimationFrame(Z);}let ee=new IntersectionObserver(t=>{t.forEach(s=>{W=s.isIntersecting,W&&!A?$=requestAnimationFrame(Z):cancelAnimationFrame($);});},{root:m??null,threshold:Ae,rootMargin:De}),te;function B(){clearTimeout(te),te=setTimeout(()=>{O.forEach((t,s)=>{w[s]=oe(t),t.style.strokeDasharray=`${w[s]}`;}),pe();},150);}return window.addEventListener("resize",B),window.addEventListener("orientationchange",B),ue>0?setTimeout(()=>ee.observe(e),ue):ee.observe(e),{destroy(){cancelAnimationFrame($),clearTimeout(K),ee.disconnect(),window.removeEventListener("resize",B),window.removeEventListener("orientationchange",B),clearTimeout(te),Q?.remove();},replay(){L=-1,V=-1,G=-1,R=false,N=false,J=0,A=false,z.clear(),clearTimeout(K),ge();},pause(){A=true,cancelAnimationFrame($);},resume(){A&&(A=false,W&&($=requestAnimationFrame(Z)));},seek(t){let s=Math.min(1,Math.max(0,t));U=s,L=s,A=true,cancelAnimationFrame($),Oe(s,E);},getProgress(){return U}}}function Xe(e={}){let r=ref(null);return onMounted(()=>{if(!r.value)return;let o=ie(r.value,e);onUnmounted(()=>o.destroy());}),r}var _e=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 i=ie(o.value,n);onUnmounted(()=>i.destroy());}),()=>h("div",{ref:o},r.default?.())}});export{_e as ScrollDraw,Xe as useScrollDraw};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svg-scroll-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Scroll-driven SVG path drawing animation library — zero dependencies, under 3KB gzipped, works with React, Vue, and vanilla JS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svg",
|
|
@@ -29,7 +29,13 @@
|
|
|
29
29
|
"angular",
|
|
30
30
|
"horizontal-scroll",
|
|
31
31
|
"color-animation",
|
|
32
|
-
"waypoints"
|
|
32
|
+
"waypoints",
|
|
33
|
+
"astro",
|
|
34
|
+
"nuxt",
|
|
35
|
+
"path-morphing",
|
|
36
|
+
"svg-morph",
|
|
37
|
+
"sequence",
|
|
38
|
+
"group"
|
|
33
39
|
],
|
|
34
40
|
"homepage": "https://ink-scroll.vercel.app",
|
|
35
41
|
"repository": {
|
|
@@ -83,6 +89,21 @@
|
|
|
83
89
|
"types": "./dist/angular/index.d.ts",
|
|
84
90
|
"import": "./dist/angular/index.mjs",
|
|
85
91
|
"require": "./dist/angular/index.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./astro": {
|
|
94
|
+
"types": "./dist/astro/index.d.ts",
|
|
95
|
+
"import": "./dist/astro/index.mjs",
|
|
96
|
+
"require": "./dist/astro/index.cjs"
|
|
97
|
+
},
|
|
98
|
+
"./nuxt": {
|
|
99
|
+
"types": "./dist/nuxt/index.d.ts",
|
|
100
|
+
"import": "./dist/nuxt/index.mjs",
|
|
101
|
+
"require": "./dist/nuxt/index.cjs"
|
|
102
|
+
},
|
|
103
|
+
"./group": {
|
|
104
|
+
"types": "./dist/group/index.d.ts",
|
|
105
|
+
"import": "./dist/group/index.mjs",
|
|
106
|
+
"require": "./dist/group/index.cjs"
|
|
86
107
|
}
|
|
87
108
|
},
|
|
88
109
|
"scripts": {
|