svg-scroll-draw 1.0.0 → 1.2.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.
Files changed (45) hide show
  1. package/README.md +27 -6
  2. package/dist/angular/index.cjs +3 -3
  3. package/dist/angular/index.d.mts +15 -1
  4. package/dist/angular/index.d.ts +15 -1
  5. package/dist/angular/index.mjs +3 -3
  6. package/dist/astro/index.cjs +3 -3
  7. package/dist/astro/index.d.mts +15 -1
  8. package/dist/astro/index.d.ts +15 -1
  9. package/dist/astro/index.mjs +3 -3
  10. package/dist/cdn/svg-scroll-draw.global.js +3 -3
  11. package/dist/group/index.cjs +3 -3
  12. package/dist/group/index.d.mts +15 -1
  13. package/dist/group/index.d.ts +15 -1
  14. package/dist/group/index.mjs +3 -3
  15. package/dist/index.cjs +3 -3
  16. package/dist/index.d.mts +45 -2
  17. package/dist/index.d.ts +45 -2
  18. package/dist/index.mjs +3 -3
  19. package/dist/nuxt/index.cjs +3 -3
  20. package/dist/nuxt/index.d.mts +15 -1
  21. package/dist/nuxt/index.d.ts +15 -1
  22. package/dist/nuxt/index.mjs +3 -3
  23. package/dist/react/index.cjs +3 -3
  24. package/dist/react/index.d.mts +15 -1
  25. package/dist/react/index.d.ts +15 -1
  26. package/dist/react/index.mjs +3 -3
  27. package/dist/solid/index.cjs +3 -3
  28. package/dist/solid/index.d.mts +15 -1
  29. package/dist/solid/index.d.ts +15 -1
  30. package/dist/solid/index.mjs +3 -3
  31. package/dist/svelte/index.cjs +3 -3
  32. package/dist/svelte/index.d.mts +15 -1
  33. package/dist/svelte/index.d.ts +15 -1
  34. package/dist/svelte/index.mjs +3 -3
  35. package/dist/timeline/index.cjs +1 -1
  36. package/dist/timeline/index.d.mts +1 -1
  37. package/dist/timeline/index.d.ts +1 -1
  38. package/dist/timeline/index.mjs +1 -1
  39. package/dist/vue/index.cjs +3 -3
  40. package/dist/vue/index.d.mts +15 -1
  41. package/dist/vue/index.d.ts +15 -1
  42. package/dist/vue/index.mjs +3 -3
  43. package/dist/web-component/index.cjs +3 -3
  44. package/dist/web-component/index.mjs +3 -3
  45. package/package.json +7 -3
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![license](https://img.shields.io/npm/l/svg-scroll-draw)](./LICENSE)
8
8
  [![GitHub stars](https://img.shields.io/github/stars/DhruvilChauahan0210/ink-scroll?style=flat)](https://github.com/DhruvilChauahan0210/ink-scroll/stargazers)
9
9
 
10
- > Scroll-driven SVG path animation. Zero dependencies. ~3 KB gzipped.
10
+ > Scroll-driven SVG path animation. Zero dependencies. ~4.4 KB gzipped — vs 35–40 KB for Framer Motion / GSAP DrawSVG.
11
11
 
12
12
  **[Live Demo](https://ink-scroll.vercel.app)** · [npm](https://www.npmjs.com/package/svg-scroll-draw) · [Report a bug](https://github.com/DhruvilChauahan0210/ink-scroll/issues)
13
13
 
@@ -137,6 +137,24 @@ const containerRef = useScrollDraw({ easing: 'ease-out', speed: 1.2 });
137
137
  | `trigger.end` | `string` | `"bottom top"` | When animation ends |
138
138
  | `onProgress` | `(alpha: number) => void` | — | Called every animation frame with current draw progress (0–1) |
139
139
  | `onComplete` | `() => void` | — | Fires once when all paths reach 100% draw progress |
140
+ | `native` | `boolean` | `true` | Run the draw as a native CSS scroll-driven animation when the browser supports it and the config is simple. Falls back to the JS engine automatically. Set `false` to always use the JS engine |
141
+
142
+ ### Native CSS rendering
143
+
144
+ For the common case — a default trigger, a named easing, optional `fade`, forward or
145
+ reverse — `svg-scroll-draw` hands the animation to the browser's native
146
+ [`animation-timeline: view()`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline).
147
+ The draw then runs on the compositor with **zero per-frame JavaScript and no scroll or
148
+ resize listeners**.
149
+
150
+ It falls back to the JS engine automatically when the browser lacks support, or when the
151
+ config uses something CSS can't express declaratively — callbacks (`onProgress` /
152
+ `onComplete` / `waypoints`), `stagger`, `morphTo`, `velocityScale`, `autoReverse`,
153
+ `once`, `repeat`, a custom trigger, a custom scroll container, `speed ≠ 1`, a
154
+ custom-function or `spring` easing, or animated color/width/fill. The full instance API
155
+ (`pause`, `resume`, `seek`, `replay`, `getProgress`, `destroy`) works on both paths.
156
+
157
+ Pass `native: false` to force the JS engine regardless.
140
158
 
141
159
  ### Trigger anchors
142
160
 
@@ -160,11 +178,14 @@ Available named anchors: `top`, `center`, `bottom`.
160
178
 
161
179
  ## Bundle sizes
162
180
 
163
- | Format | Size |
164
- |---|---|
165
- | ESM (`.mjs`) | ~3.2 KB |
166
- | CJS (`.cjs`) | ~3.2 KB |
167
- | IIFE / CDN (`.global.js`) | ~4.2 KB (includes Web Component) |
181
+ | Format | Minified | Gzipped |
182
+ |---|---|---|
183
+ | ESM (`.mjs`) | 11.9 KB | ~4.4 KB |
184
+ | CJS (`.cjs`) | 11.9 KB | ~4.4 KB |
185
+ | React (`/react`) | 13.4 KB | ~4.8 KB |
186
+ | IIFE / CDN (`.global.js`) | 12.9 KB | ~4.8 KB (includes Web Component) |
187
+
188
+ Still 8–9× smaller than Framer Motion (~35 KB) or GSAP DrawSVG (~40 KB), and on supporting browsers the simple case runs as a native CSS scroll animation with zero per-frame JavaScript.
168
189
 
169
190
  ---
170
191
 
@@ -1,3 +1,3 @@
1
- 'use strict';var me={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 de(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 Te(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 Ae(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 ye(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 We(e,r,s){return Math.min(s,Math.max(r,e))}function z(e,r,s,o){return s===r?0:We((e-r)/(s-r)*o,0,1)}function Se(e,r,s,o,a){let f=Te(e.top,e.height,r,o.element)-Ae(o.viewport,s),p=Te(e.top,e.height,r,a.element)-Ae(a.viewport,s);return {tStart:f,tEnd:p}}function ke(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 ge(e,r,s){let o=ke(e),a=ke(r);return !o||!a?e:`rgb(${Math.round(o[0]+(a[0]-o[0])*s)},${Math.round(o[1]+(a[1]-o[1])*s)},${Math.round(o[2]+(a[2]-o[2])*s)})`}function Me(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Ve(e){let r=e.getAttribute("stroke"),s=e.getAttribute("fill");!r||r==="none"?Me("Element has no stroke \u2014 path will not be visible.",e):s&&s!=="none"&&s!=="transparent"&&Me("Element has a fill \u2014 it may obscure the stroke animation.",e);}function ze(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 a(){let f=s==="x"?window.scrollX:window.scrollY,p=e-f,D=r-f,B=s==="x";o.innerHTML=`
2
- <div style="position:absolute;${B?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${B?`left:${D}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${D}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 Le(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let p=parseFloat(f),D=o[a++]??p;return String(+(p+(D-p)*s).toFixed(4))})}function De(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:f=false,easing:p="linear",trigger:D={},stagger:B=0,direction:I="forward",once:X=false,debug:Pe=false,axis:x="y",scrollContainer:ne,autoReverse:se=false,delay:he=0,strokeColor:C,strokeWidth:N,fillOpacity:H,waypoints:oe,velocityScale:ie=false,threshold:Oe=0,rootMargin:Fe="0px",repeat:_=0,repeatDelay:be=0,morphTo:P,clip:le,onProgress:we,onStart:ve,onComplete:j}=r,R=le===true?"left":typeof le=="string"?le:false,ae=typeof p=="function"?p:me[p]??me.linear,Ce=de(D.start??"top bottom"),Ne=de(D.end??"bottom top"),d=typeof ne=="string"?document.querySelector(ne):ne??null,T=Array.isArray(C)?C[0]:null,y=Array.isArray(C)?C[1]:typeof C=="string"?C:null,g=Array.isArray(N)?N[0]:null,h=Array.isArray(N)?N[1]:typeof N=="number"?N:null,b=Array.isArray(H)?H[0]:null,w=Array.isArray(H)?H[1]:typeof H=="number"?H:null;function W(t){let n=t*100;switch(R){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 G=R?[]:Array.from(e.querySelectorAll(o)),E=[],A=[],k=0,S=0,$=false,O=false,M=0,J=false,v=-1,K=-1,F=false,Q=0,q=0,U,ue=null,Y=new Set,Z=-1,xe=performance.now();function ce(){return d?x==="x"?d.scrollLeft:d.scrollTop:x==="x"?window.scrollX:window.scrollY}function He(){return d?x==="x"?d.clientWidth:d.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function Ee(){let t=e.getBoundingClientRect(),n,l,m;if(d){let V=d.getBoundingClientRect();n=x==="x"?t.left-V.left+d.scrollLeft:t.top-V.top+d.scrollTop,l=x==="x"?t.width:t.height,m=ce();}else n=x==="x"?t.left:t.top,l=x==="x"?t.width:t.height,m=ce();let re=Se({top:n,height:l},m,He(),Ce,Ne);k=re.tStart,S=re.tEnd,Pe&&process.env.NODE_ENV!=="production"&&(ue?.remove(),ue=ze(k,S,x));}function Re(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),R){let l=n==="reverse"?1-t:t;e.style.clipPath=W(l);return}G.forEach((l,m)=>{l.style.strokeDashoffset=n==="reverse"?`${E[m]*t}`:`${E[m]*(1-t)}`,f&&(l.style.opacity=n==="reverse"?`${1-t}`:`${t}`),T&&y?l.style.stroke=ge(T,y,t):y&&(l.style.stroke=y),g!==null&&h!==null?l.style.strokeWidth=`${g+(h-g)*t}`:h!==null&&(l.style.strokeWidth=`${h}`),b!==null&&w!==null?l.style.fillOpacity=`${b+(w-b)*t}`:w!==null&&(l.style.fillOpacity=`${w}`),P&&l.tagName.toLowerCase()==="path"&&A[m]&&l.setAttribute("d",Le(A[m],P,t));});}function $e(){if(e.style.setProperty("--scroll-draw-progress","0"),R){e.style.clipPath=W(0);return}G.forEach((t,n)=>{t.style.strokeDasharray=`${E[n]}`,t.style.strokeDashoffset=I==="reverse"?"0":`${E[n]}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",T&&(t.style.stroke=T),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`),P&&t.tagName.toLowerCase()==="path"&&A[n]&&t.setAttribute("d",A[n]);});}if(G.forEach(t=>{Ve(t);let n=ye(t);E.push(n),t.tagName.toLowerCase()==="path"?A.push(t.getAttribute("d")??""):A.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=I==="reverse"?`${n}`:"0",f&&(t.style.opacity="1"),y&&(t.style.stroke=y),h!==null&&(t.style.strokeWidth=`${h}`),w!==null&&(t.style.fillOpacity=`${w}`),P&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",P)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=I==="reverse"?"0":`${n}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",T&&(t.style.stroke=T),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`));}),R){if(s)return e.style.clipPath=W(1),j?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=W(0);}else if(s)return j?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};Ee();function ee(){if(!J||F)return;let t=performance.now(),n=ce(),l=a;if(ie!==false){let i=t-xe,c=i>0?Math.abs(n-(Z<0?n:Z))/i:0;l=a*Math.max(.2,1+c*(typeof ie=="number"?ie:1)*.04);}Z=n,xe=t;let m=se?K===-1||n>=K?"forward":"reverse":I;K=n;let re=S-k,V=true;if(R){let i=ae(z(n,k,S,l));X&&!se&&(v=Math.max(v,i),i=v),Q=i,e.style.setProperty("--scroll-draw-progress",String(i));let c=m==="reverse"?1-i:i;e.style.clipPath=W(c),we?.(i),!O&&z(n,k,S,l)>0&&(O=true,ve?.()),i>=1&&!$?($=true,j?.(),q<(_==="infinite"?1/0:_??0)&&(q++,U=setTimeout(()=>{v=-1,O=false,$=false,e.style.clipPath=W(0);},be))):i<1&&!X&&($=false),M=requestAnimationFrame(ee);return}if(G.forEach((i,c)=>{let L=c*B*re,u=ae(z(n,k+L,S+L,l));X&&!se&&(v=Math.max(v,u),u=v),Q=u,i.style.strokeDashoffset=m==="reverse"?`${E[c]*u}`:`${E[c]*(1-u)}`,f&&(i.style.opacity=m==="reverse"?`${1-u}`:`${u}`),T&&y?i.style.stroke=ge(T,y,u):y&&(i.style.stroke=y),g!==null&&h!==null?i.style.strokeWidth=`${g+(h-g)*u}`:h!==null&&(i.style.strokeWidth=`${h}`),b!==null&&w!==null?i.style.fillOpacity=`${b+(w-b)*u}`:w!==null&&(i.style.fillOpacity=`${w}`),P&&i.tagName.toLowerCase()==="path"&&A[c]&&i.setAttribute("d",Le(A[c],P,u)),c===0&&(we?.(u),e.style.setProperty("--scroll-draw-progress",String(u))),u<1&&(V=false);}),oe){let i=ae(z(n,k,S,l));for(let c in oe){let L=parseFloat(c);i>=L&&!Y.has(L)&&(Y.add(L),oe[c]?.());}}!O&&z(n,k,S,l)>0&&(O=true,ve?.()),V&&!$?($=true,j?.(),q<(_==="infinite"?1/0:_??0)&&(q++,U=setTimeout(()=>{v=-1,O=false,$=false,Y.clear(),$e();},be))):!V&&!X&&($=false),M=requestAnimationFrame(ee);}let fe=new IntersectionObserver(t=>{t.forEach(n=>{J=n.isIntersecting,J&&!F?M=requestAnimationFrame(ee):cancelAnimationFrame(M);});},{root:d??null,threshold:Oe,rootMargin:Fe}),pe;function te(){clearTimeout(pe),pe=setTimeout(()=>{G.forEach((t,n)=>{E[n]=ye(t),t.style.strokeDasharray=`${E[n]}`;}),Ee();},150);}return window.addEventListener("resize",te),window.addEventListener("orientationchange",te),he>0?setTimeout(()=>fe.observe(e),he):fe.observe(e),{destroy(){cancelAnimationFrame(M),clearTimeout(U),fe.disconnect(),window.removeEventListener("resize",te),window.removeEventListener("orientationchange",te),clearTimeout(pe),ue?.remove();},replay(){v=-1,K=-1,Z=-1,O=false,$=false,q=0,F=false,Y.clear(),clearTimeout(U),$e();},pause(){F=true,cancelAnimationFrame(M);},resume(){F&&(F=false,J&&(M=requestAnimationFrame(ee)));},seek(t){let n=Math.min(1,Math.max(0,t));Q=n,v=n,F=true,cancelAnimationFrame(M),Re(n,I);},getProgress(){return Q}}}var Ie=class{constructor(){this.instance=null;}init(r,s={}){return this.destroy(),this.instance=De(r,s),this}replay(){return this.instance?.replay(),this}destroy(){return this.instance?.destroy(),this.instance=null,this}};exports.ScrollDrawRef=Ie;
1
+ 'use strict';function Ue({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(o),u=0,p=[];for(let a=0;a<n;a++){let d=Math.pow(c,a);p.push(d),u+=d;}let h=[0],I=0;for(let a=0;a<n;a++)I+=p[a]/u,h.push(I);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let d=0;d<n;d++)if(a<=h[d+1]){let U=(a-h[d])/(h[d+1]-h[d]);if(d===0)return U*(2-U);let b=1-Math.pow(o,d);return b+(1-b)*(2*U-1)*(2*U-1)}return 1}}function je({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),o=Math.max(.1,r),c=n<=1?o/4:o/(2*Math.PI)*Math.asin(1/n);return u=>u<=0?0:u>=1?1:n*Math.pow(2,-10*u)*Math.sin((u-c)*(2*Math.PI)/o)+1}var we={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:Ue(),elastic:je()};function $e(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 Ce(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 Oe(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 xe(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 Je(e,r,n){return Math.min(n,Math.max(r,e))}function X(e,r,n,o){return n===r?0:Je((e-r)/(n-r)*o,0,1)}function Ee(e,r,n,o,c){let u=Ce(e.top,e.height,r,o.element)-Oe(o.viewport,n),p=Ce(e.top,e.height,r,c.element)-Oe(c.viewport,n);return {tStart:u,tEnd:p}}function Fe(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 Se(e,r,n){let o=Fe(e),c=Fe(r);return !o||!c?e:`rgb(${Math.round(o[0]+(c[0]-o[0])*n)},${Math.round(o[1]+(c[1]-o[1])*n)},${Math.round(o[2]+(c[2]-o[2])*n)})`}function Ne(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Re={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},Ke=0;function Qe(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function Ye(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Ne("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Ne("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ze(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 c(){let u=n==="x"?window.scrollX:window.scrollY,p=e-u,h=r-u,I=n==="x";o.innerHTML=`
2
+ <div style="position:absolute;${I?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${I?`left:${h}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${h}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 We(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let p=parseFloat(u),h=o[c++]??p;return String(+(p+(h-p)*n).toFixed(4))})}function He(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:c=1,fade:u=false,easing:p="linear",trigger:h={},stagger:I=0,direction:a="forward",once:d=false,debug:U=false,axis:b="y",scrollContainer:me,autoReverse:ee=false,delay:pe=0,strokeColor:H,strokeWidth:V,fillOpacity:G,waypoints:te,velocityScale:re=false,threshold:Ge=0,rootMargin:ze="0px",repeat:J=0,repeatDelay:Me=0,morphTo:C,clip:de,native:qe=true,onProgress:ye,onStart:he,onComplete:K}=r,z=de===true?"left":typeof de=="string"?de:false,ne=typeof p=="function"?p:we[p]??we.linear,ke=$e(h.start??"top bottom"),Ae=$e(h.end??"bottom top"),$=typeof me=="string"?document.querySelector(me):me??null,O=Array.isArray(H)?H[0]:null,S=Array.isArray(H)?H[1]:typeof H=="string"?H:null,M=Array.isArray(V)?V[0]:null,k=Array.isArray(V)?V[1]:typeof V=="number"?V:null,A=Array.isArray(G)?G[0]:null,T=Array.isArray(G)?G[1]:typeof G=="number"?G:null;function j(t){let s=t*100;switch(z){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=z?[]:Array.from(e.querySelectorAll(o)),v=[],F=[],N=0,R=0,D=false,q=false,W=0,se=false,P=-1,oe=-1,B=false,ie=0,Q=0,ae,ge=null,le=new Set,ue=-1,Te=performance.now();function Y(){return $?b==="x"?$.scrollLeft:$.scrollTop:b==="x"?window.scrollX:window.scrollY}function Pe(){return $?b==="x"?$.clientWidth:$.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),s,l,g;if($){let E=$.getBoundingClientRect();s=b==="x"?t.left-E.left+$.scrollLeft:t.top-E.top+$.scrollTop,l=b==="x"?t.width:t.height,g=Y();}else s=b==="x"?t.left:t.top,l=b==="x"?t.width:t.height,g=Y();let _=Ee({top:s,height:l},g,Pe(),ke,Ae);N=_.tStart,R=_.tEnd,U&&process.env.NODE_ENV!=="production"&&(ge?.remove(),ge=Ze(N,R,b));}function Be(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),z){let l=s==="reverse"?1-t:t;e.style.clipPath=j(l);return}x.forEach((l,g)=>{l.style.strokeDashoffset=s==="reverse"?`${v[g]*t}`:`${v[g]*(1-t)}`,u&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),O&&S?l.style.stroke=Se(O,S,t):S&&(l.style.stroke=S),M!==null&&k!==null?l.style.strokeWidth=`${M+(k-M)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),A!==null&&T!==null?l.style.fillOpacity=`${A+(T-A)*t}`:T!==null&&(l.style.fillOpacity=`${T}`),C&&l.tagName.toLowerCase()==="path"&&F[g]&&l.setAttribute("d",We(F[g],C,t));});}function De(){if(e.style.setProperty("--scroll-draw-progress","0"),z){e.style.clipPath=j(0);return}x.forEach((t,s)=>{t.style.strokeDasharray=`${v[s]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${v[s]}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`),C&&t.tagName.toLowerCase()==="path"&&F[s]&&t.setAttribute("d",F[s]);});}if(x.forEach(t=>{Ye(t);let s=xe(t);v.push(s),t.tagName.toLowerCase()==="path"?F.push(t.getAttribute("d")??""):F.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(t.style.opacity="1"),S&&(t.style.stroke=S),k!==null&&(t.style.strokeWidth=`${k}`),T!==null&&(t.style.fillOpacity=`${T}`),C&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",C)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`));}),z){if(n)return e.style.clipPath=j(1),K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=j(0);}else if(n)return K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function _e(){return !(qe===false||!Qe()||!x.length||typeof p!="string"||!(p in Re)||z||b!=="y"||$||c!==1||I!==0||d||ee||re!==false||C||te||J||pe>0||ye||he||K||H!=null||V!=null||G!=null||(h.start??"top bottom").trim()!=="top bottom"||(h.end??"bottom top").trim()!=="bottom top")}function Xe(){let t=`svg-scroll-draw-${++Ke}`,s=a==="reverse"?"0":"var(--ssd-len)",l=a==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${s};`,_=`stroke-dashoffset:${l};`;u&&(g+=`opacity:${a==="reverse"?1:0};`,_+=`opacity:${a==="reverse"?0:1};`);let E=document.createElement("style");E.setAttribute("data-svg-scroll-draw",""),E.textContent=`@keyframes ${t}{from{${g}}to{${_}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Re[p]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(E);function i(m,L){m.style.setProperty("--ssd-len",String(v[L])),m.style.strokeDasharray=`${v[L]}`,m.style.strokeDashoffset="",m.style.opacity="",m.style.animationPlayState="",m.classList.add(t);}x.forEach(i);let f=false,w=-1;function y(){if(w>=0)return w;let m=e.getBoundingClientRect(),{tStart:L,tEnd:Z}=Ee({top:m.top,height:m.height},Y(),Pe(),ke,Ae);return ne(X(Y(),L,Z,c))}return {destroy(){x.forEach(m=>{m.classList.remove(t),m.style.removeProperty("--ssd-len"),m.style.animationPlayState="";}),E.remove();},replay(){f=false,w=-1,x.forEach(i);},pause(){f=true,x.forEach(m=>{m.style.animationPlayState="paused";});},resume(){f&&(f=false,x.forEach(m=>{m.style.animationPlayState="running";}));},seek(m){let L=Math.min(1,Math.max(0,m));w=L,f=true,x.forEach((Z,Ie)=>{Z.classList.remove(t),Z.style.strokeDashoffset=a==="reverse"?`${v[Ie]*L}`:`${v[Ie]*(1-L)}`,u&&(Z.style.opacity=a==="reverse"?`${1-L}`:`${L}`);});},getProgress(){return y()}}}if(_e())return Xe();Le();function ce(){if(!se||B)return;let t=performance.now(),s=Y(),l=c;if(re!==false){let i=t-Te,f=i>0?Math.abs(s-(ue<0?s:ue))/i:0;l=c*Math.max(.2,1+f*(typeof re=="number"?re:1)*.04);}ue=s,Te=t;let g=ee?oe===-1||s>=oe?"forward":"reverse":a;oe=s;let _=R-N,E=true;if(z){let i=ne(X(s,N,R,l));d&&!ee&&(P=Math.max(P,i),i=P),ie=i,e.style.setProperty("--scroll-draw-progress",String(i));let f=g==="reverse"?1-i:i;e.style.clipPath=j(f),ye?.(i),!q&&X(s,N,R,l)>0&&(q=true,he?.()),i>=1&&!D?(D=true,K?.(),Q<(J==="infinite"?1/0:J??0)&&(Q++,ae=setTimeout(()=>{P=-1,q=false,D=false,e.style.clipPath=j(0);},Me))):i<1&&!d&&(D=false),W=requestAnimationFrame(ce);return}if(x.forEach((i,f)=>{let w=f*I*_,y=ne(X(s,N+w,R+w,l));d&&!ee&&(P=Math.max(P,y),y=P),ie=y,i.style.strokeDashoffset=g==="reverse"?`${v[f]*y}`:`${v[f]*(1-y)}`,u&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),O&&S?i.style.stroke=Se(O,S,y):S&&(i.style.stroke=S),M!==null&&k!==null?i.style.strokeWidth=`${M+(k-M)*y}`:k!==null&&(i.style.strokeWidth=`${k}`),A!==null&&T!==null?i.style.fillOpacity=`${A+(T-A)*y}`:T!==null&&(i.style.fillOpacity=`${T}`),C&&i.tagName.toLowerCase()==="path"&&F[f]&&i.setAttribute("d",We(F[f],C,y)),f===0&&(ye?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(E=false);}),te){let i=ne(X(s,N,R,l));for(let f in te){let w=parseFloat(f);i>=w&&!le.has(w)&&(le.add(w),te[f]?.());}}!q&&X(s,N,R,l)>0&&(q=true,he?.()),E&&!D?(D=true,K?.(),Q<(J==="infinite"?1/0:J??0)&&(Q++,ae=setTimeout(()=>{P=-1,q=false,D=false,le.clear(),De();},Me))):!E&&!d&&(D=false),W=requestAnimationFrame(ce);}let be=new IntersectionObserver(t=>{t.forEach(s=>{se=s.isIntersecting,se&&!B?W=requestAnimationFrame(ce):cancelAnimationFrame(W);});},{root:$??null,threshold:Ge,rootMargin:ze}),ve;function fe(){clearTimeout(ve),ve=setTimeout(()=>{x.forEach((t,s)=>{v[s]=xe(t),t.style.strokeDasharray=`${v[s]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),pe>0?setTimeout(()=>be.observe(e),pe):be.observe(e),{destroy(){cancelAnimationFrame(W),clearTimeout(ae),be.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(ve),ge?.remove();},replay(){P=-1,oe=-1,ue=-1,q=false,D=false,Q=0,B=false,le.clear(),clearTimeout(ae),De();},pause(){B=true,cancelAnimationFrame(W);},resume(){B&&(B=false,se&&(W=requestAnimationFrame(ce)));},seek(t){let s=Math.min(1,Math.max(0,t));ie=s,P=s,B=true,cancelAnimationFrame(W),Be(s,a);},getProgress(){return ie}}}var Ve=class{constructor(){this.instance=null;}init(r,n={}){return this.destroy(),this.instance=He(r,n),this}replay(){return this.instance?.replay(),this}destroy(){return this.instance?.destroy(),this.instance=null,this}};exports.ScrollDrawRef=Ve;
@@ -1,4 +1,4 @@
1
- type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
1
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
2
2
  interface TriggerConfig {
3
3
  start?: string;
4
4
  end?: string;
@@ -60,6 +60,20 @@ interface ScrollDrawOptions {
60
60
  onProgress?: (alpha: number) => void;
61
61
  onStart?: () => void;
62
62
  onComplete?: () => void;
63
+ /**
64
+ * Use the browser's native CSS scroll-driven animation
65
+ * (`animation-timeline: view()`) when the configuration is simple enough and
66
+ * the browser supports it. This runs the draw entirely on the compositor —
67
+ * zero per-frame JavaScript, zero scroll/resize listeners.
68
+ *
69
+ * Falls back to the JS engine automatically when unsupported or when the
70
+ * config uses a feature native CSS can't express (callbacks, stagger, morph,
71
+ * velocity scaling, custom triggers, `once`, custom easing functions, etc.).
72
+ *
73
+ * - `undefined` / `true` (default): use native when eligible.
74
+ * - `false`: always use the JS engine.
75
+ */
76
+ native?: boolean;
63
77
  }
64
78
  interface ScrollDrawInstance {
65
79
  destroy: () => void;
@@ -1,4 +1,4 @@
1
- type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
1
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
2
2
  interface TriggerConfig {
3
3
  start?: string;
4
4
  end?: string;
@@ -60,6 +60,20 @@ interface ScrollDrawOptions {
60
60
  onProgress?: (alpha: number) => void;
61
61
  onStart?: () => void;
62
62
  onComplete?: () => void;
63
+ /**
64
+ * Use the browser's native CSS scroll-driven animation
65
+ * (`animation-timeline: view()`) when the configuration is simple enough and
66
+ * the browser supports it. This runs the draw entirely on the compositor —
67
+ * zero per-frame JavaScript, zero scroll/resize listeners.
68
+ *
69
+ * Falls back to the JS engine automatically when unsupported or when the
70
+ * config uses a feature native CSS can't express (callbacks, stagger, morph,
71
+ * velocity scaling, custom triggers, `once`, custom easing functions, etc.).
72
+ *
73
+ * - `undefined` / `true` (default): use native when eligible.
74
+ * - `false`: always use the JS engine.
75
+ */
76
+ native?: boolean;
63
77
  }
64
78
  interface ScrollDrawInstance {
65
79
  destroy: () => void;
@@ -1,3 +1,3 @@
1
- var me={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 de(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 Te(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 Ae(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 ye(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 We(e,r,s){return Math.min(s,Math.max(r,e))}function z(e,r,s,o){return s===r?0:We((e-r)/(s-r)*o,0,1)}function Se(e,r,s,o,a){let f=Te(e.top,e.height,r,o.element)-Ae(o.viewport,s),p=Te(e.top,e.height,r,a.element)-Ae(a.viewport,s);return {tStart:f,tEnd:p}}function ke(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 ge(e,r,s){let o=ke(e),a=ke(r);return !o||!a?e:`rgb(${Math.round(o[0]+(a[0]-o[0])*s)},${Math.round(o[1]+(a[1]-o[1])*s)},${Math.round(o[2]+(a[2]-o[2])*s)})`}function Me(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function Ve(e){let r=e.getAttribute("stroke"),s=e.getAttribute("fill");!r||r==="none"?Me("Element has no stroke \u2014 path will not be visible.",e):s&&s!=="none"&&s!=="transparent"&&Me("Element has a fill \u2014 it may obscure the stroke animation.",e);}function ze(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 a(){let f=s==="x"?window.scrollX:window.scrollY,p=e-f,D=r-f,B=s==="x";o.innerHTML=`
2
- <div style="position:absolute;${B?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${B?`left:${D}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${D}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 Le(e,r,s){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let p=parseFloat(f),D=o[a++]??p;return String(+(p+(D-p)*s).toFixed(4))})}function De(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:f=false,easing:p="linear",trigger:D={},stagger:B=0,direction:I="forward",once:X=false,debug:Pe=false,axis:x="y",scrollContainer:ne,autoReverse:se=false,delay:he=0,strokeColor:C,strokeWidth:N,fillOpacity:H,waypoints:oe,velocityScale:ie=false,threshold:Oe=0,rootMargin:Fe="0px",repeat:_=0,repeatDelay:be=0,morphTo:P,clip:le,onProgress:we,onStart:ve,onComplete:j}=r,R=le===true?"left":typeof le=="string"?le:false,ae=typeof p=="function"?p:me[p]??me.linear,Ce=de(D.start??"top bottom"),Ne=de(D.end??"bottom top"),d=typeof ne=="string"?document.querySelector(ne):ne??null,T=Array.isArray(C)?C[0]:null,y=Array.isArray(C)?C[1]:typeof C=="string"?C:null,g=Array.isArray(N)?N[0]:null,h=Array.isArray(N)?N[1]:typeof N=="number"?N:null,b=Array.isArray(H)?H[0]:null,w=Array.isArray(H)?H[1]:typeof H=="number"?H:null;function W(t){let n=t*100;switch(R){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 G=R?[]:Array.from(e.querySelectorAll(o)),E=[],A=[],k=0,S=0,$=false,O=false,M=0,J=false,v=-1,K=-1,F=false,Q=0,q=0,U,ue=null,Y=new Set,Z=-1,xe=performance.now();function ce(){return d?x==="x"?d.scrollLeft:d.scrollTop:x==="x"?window.scrollX:window.scrollY}function He(){return d?x==="x"?d.clientWidth:d.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function Ee(){let t=e.getBoundingClientRect(),n,l,m;if(d){let V=d.getBoundingClientRect();n=x==="x"?t.left-V.left+d.scrollLeft:t.top-V.top+d.scrollTop,l=x==="x"?t.width:t.height,m=ce();}else n=x==="x"?t.left:t.top,l=x==="x"?t.width:t.height,m=ce();let re=Se({top:n,height:l},m,He(),Ce,Ne);k=re.tStart,S=re.tEnd,Pe&&process.env.NODE_ENV!=="production"&&(ue?.remove(),ue=ze(k,S,x));}function Re(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),R){let l=n==="reverse"?1-t:t;e.style.clipPath=W(l);return}G.forEach((l,m)=>{l.style.strokeDashoffset=n==="reverse"?`${E[m]*t}`:`${E[m]*(1-t)}`,f&&(l.style.opacity=n==="reverse"?`${1-t}`:`${t}`),T&&y?l.style.stroke=ge(T,y,t):y&&(l.style.stroke=y),g!==null&&h!==null?l.style.strokeWidth=`${g+(h-g)*t}`:h!==null&&(l.style.strokeWidth=`${h}`),b!==null&&w!==null?l.style.fillOpacity=`${b+(w-b)*t}`:w!==null&&(l.style.fillOpacity=`${w}`),P&&l.tagName.toLowerCase()==="path"&&A[m]&&l.setAttribute("d",Le(A[m],P,t));});}function $e(){if(e.style.setProperty("--scroll-draw-progress","0"),R){e.style.clipPath=W(0);return}G.forEach((t,n)=>{t.style.strokeDasharray=`${E[n]}`,t.style.strokeDashoffset=I==="reverse"?"0":`${E[n]}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",T&&(t.style.stroke=T),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`),P&&t.tagName.toLowerCase()==="path"&&A[n]&&t.setAttribute("d",A[n]);});}if(G.forEach(t=>{Ve(t);let n=ye(t);E.push(n),t.tagName.toLowerCase()==="path"?A.push(t.getAttribute("d")??""):A.push(""),s?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=I==="reverse"?`${n}`:"0",f&&(t.style.opacity="1"),y&&(t.style.stroke=y),h!==null&&(t.style.strokeWidth=`${h}`),w!==null&&(t.style.fillOpacity=`${w}`),P&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",P)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=I==="reverse"?"0":`${n}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",T&&(t.style.stroke=T),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`));}),R){if(s)return e.style.clipPath=W(1),j?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=W(0);}else if(s)return j?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};Ee();function ee(){if(!J||F)return;let t=performance.now(),n=ce(),l=a;if(ie!==false){let i=t-xe,c=i>0?Math.abs(n-(Z<0?n:Z))/i:0;l=a*Math.max(.2,1+c*(typeof ie=="number"?ie:1)*.04);}Z=n,xe=t;let m=se?K===-1||n>=K?"forward":"reverse":I;K=n;let re=S-k,V=true;if(R){let i=ae(z(n,k,S,l));X&&!se&&(v=Math.max(v,i),i=v),Q=i,e.style.setProperty("--scroll-draw-progress",String(i));let c=m==="reverse"?1-i:i;e.style.clipPath=W(c),we?.(i),!O&&z(n,k,S,l)>0&&(O=true,ve?.()),i>=1&&!$?($=true,j?.(),q<(_==="infinite"?1/0:_??0)&&(q++,U=setTimeout(()=>{v=-1,O=false,$=false,e.style.clipPath=W(0);},be))):i<1&&!X&&($=false),M=requestAnimationFrame(ee);return}if(G.forEach((i,c)=>{let L=c*B*re,u=ae(z(n,k+L,S+L,l));X&&!se&&(v=Math.max(v,u),u=v),Q=u,i.style.strokeDashoffset=m==="reverse"?`${E[c]*u}`:`${E[c]*(1-u)}`,f&&(i.style.opacity=m==="reverse"?`${1-u}`:`${u}`),T&&y?i.style.stroke=ge(T,y,u):y&&(i.style.stroke=y),g!==null&&h!==null?i.style.strokeWidth=`${g+(h-g)*u}`:h!==null&&(i.style.strokeWidth=`${h}`),b!==null&&w!==null?i.style.fillOpacity=`${b+(w-b)*u}`:w!==null&&(i.style.fillOpacity=`${w}`),P&&i.tagName.toLowerCase()==="path"&&A[c]&&i.setAttribute("d",Le(A[c],P,u)),c===0&&(we?.(u),e.style.setProperty("--scroll-draw-progress",String(u))),u<1&&(V=false);}),oe){let i=ae(z(n,k,S,l));for(let c in oe){let L=parseFloat(c);i>=L&&!Y.has(L)&&(Y.add(L),oe[c]?.());}}!O&&z(n,k,S,l)>0&&(O=true,ve?.()),V&&!$?($=true,j?.(),q<(_==="infinite"?1/0:_??0)&&(q++,U=setTimeout(()=>{v=-1,O=false,$=false,Y.clear(),$e();},be))):!V&&!X&&($=false),M=requestAnimationFrame(ee);}let fe=new IntersectionObserver(t=>{t.forEach(n=>{J=n.isIntersecting,J&&!F?M=requestAnimationFrame(ee):cancelAnimationFrame(M);});},{root:d??null,threshold:Oe,rootMargin:Fe}),pe;function te(){clearTimeout(pe),pe=setTimeout(()=>{G.forEach((t,n)=>{E[n]=ye(t),t.style.strokeDasharray=`${E[n]}`;}),Ee();},150);}return window.addEventListener("resize",te),window.addEventListener("orientationchange",te),he>0?setTimeout(()=>fe.observe(e),he):fe.observe(e),{destroy(){cancelAnimationFrame(M),clearTimeout(U),fe.disconnect(),window.removeEventListener("resize",te),window.removeEventListener("orientationchange",te),clearTimeout(pe),ue?.remove();},replay(){v=-1,K=-1,Z=-1,O=false,$=false,q=0,F=false,Y.clear(),clearTimeout(U),$e();},pause(){F=true,cancelAnimationFrame(M);},resume(){F&&(F=false,J&&(M=requestAnimationFrame(ee)));},seek(t){let n=Math.min(1,Math.max(0,t));Q=n,v=n,F=true,cancelAnimationFrame(M),Re(n,I);},getProgress(){return Q}}}var Ie=class{constructor(){this.instance=null;}init(r,s={}){return this.destroy(),this.instance=De(r,s),this}replay(){return this.instance?.replay(),this}destroy(){return this.instance?.destroy(),this.instance=null,this}};export{Ie as ScrollDrawRef};
1
+ function Ue({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(o),u=0,p=[];for(let a=0;a<n;a++){let d=Math.pow(c,a);p.push(d),u+=d;}let h=[0],I=0;for(let a=0;a<n;a++)I+=p[a]/u,h.push(I);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let d=0;d<n;d++)if(a<=h[d+1]){let U=(a-h[d])/(h[d+1]-h[d]);if(d===0)return U*(2-U);let b=1-Math.pow(o,d);return b+(1-b)*(2*U-1)*(2*U-1)}return 1}}function je({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),o=Math.max(.1,r),c=n<=1?o/4:o/(2*Math.PI)*Math.asin(1/n);return u=>u<=0?0:u>=1?1:n*Math.pow(2,-10*u)*Math.sin((u-c)*(2*Math.PI)/o)+1}var we={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:Ue(),elastic:je()};function $e(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 Ce(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 Oe(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 xe(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 Je(e,r,n){return Math.min(n,Math.max(r,e))}function X(e,r,n,o){return n===r?0:Je((e-r)/(n-r)*o,0,1)}function Ee(e,r,n,o,c){let u=Ce(e.top,e.height,r,o.element)-Oe(o.viewport,n),p=Ce(e.top,e.height,r,c.element)-Oe(c.viewport,n);return {tStart:u,tEnd:p}}function Fe(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 Se(e,r,n){let o=Fe(e),c=Fe(r);return !o||!c?e:`rgb(${Math.round(o[0]+(c[0]-o[0])*n)},${Math.round(o[1]+(c[1]-o[1])*n)},${Math.round(o[2]+(c[2]-o[2])*n)})`}function Ne(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Re={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},Ke=0;function Qe(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function Ye(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Ne("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Ne("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ze(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 c(){let u=n==="x"?window.scrollX:window.scrollY,p=e-u,h=r-u,I=n==="x";o.innerHTML=`
2
+ <div style="position:absolute;${I?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${I?`left:${h}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${h}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 We(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let p=parseFloat(u),h=o[c++]??p;return String(+(p+(h-p)*n).toFixed(4))})}function He(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:c=1,fade:u=false,easing:p="linear",trigger:h={},stagger:I=0,direction:a="forward",once:d=false,debug:U=false,axis:b="y",scrollContainer:me,autoReverse:ee=false,delay:pe=0,strokeColor:H,strokeWidth:V,fillOpacity:G,waypoints:te,velocityScale:re=false,threshold:Ge=0,rootMargin:ze="0px",repeat:J=0,repeatDelay:Me=0,morphTo:C,clip:de,native:qe=true,onProgress:ye,onStart:he,onComplete:K}=r,z=de===true?"left":typeof de=="string"?de:false,ne=typeof p=="function"?p:we[p]??we.linear,ke=$e(h.start??"top bottom"),Ae=$e(h.end??"bottom top"),$=typeof me=="string"?document.querySelector(me):me??null,O=Array.isArray(H)?H[0]:null,S=Array.isArray(H)?H[1]:typeof H=="string"?H:null,M=Array.isArray(V)?V[0]:null,k=Array.isArray(V)?V[1]:typeof V=="number"?V:null,A=Array.isArray(G)?G[0]:null,T=Array.isArray(G)?G[1]:typeof G=="number"?G:null;function j(t){let s=t*100;switch(z){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=z?[]:Array.from(e.querySelectorAll(o)),v=[],F=[],N=0,R=0,D=false,q=false,W=0,se=false,P=-1,oe=-1,B=false,ie=0,Q=0,ae,ge=null,le=new Set,ue=-1,Te=performance.now();function Y(){return $?b==="x"?$.scrollLeft:$.scrollTop:b==="x"?window.scrollX:window.scrollY}function Pe(){return $?b==="x"?$.clientWidth:$.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),s,l,g;if($){let E=$.getBoundingClientRect();s=b==="x"?t.left-E.left+$.scrollLeft:t.top-E.top+$.scrollTop,l=b==="x"?t.width:t.height,g=Y();}else s=b==="x"?t.left:t.top,l=b==="x"?t.width:t.height,g=Y();let _=Ee({top:s,height:l},g,Pe(),ke,Ae);N=_.tStart,R=_.tEnd,U&&process.env.NODE_ENV!=="production"&&(ge?.remove(),ge=Ze(N,R,b));}function Be(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),z){let l=s==="reverse"?1-t:t;e.style.clipPath=j(l);return}x.forEach((l,g)=>{l.style.strokeDashoffset=s==="reverse"?`${v[g]*t}`:`${v[g]*(1-t)}`,u&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),O&&S?l.style.stroke=Se(O,S,t):S&&(l.style.stroke=S),M!==null&&k!==null?l.style.strokeWidth=`${M+(k-M)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),A!==null&&T!==null?l.style.fillOpacity=`${A+(T-A)*t}`:T!==null&&(l.style.fillOpacity=`${T}`),C&&l.tagName.toLowerCase()==="path"&&F[g]&&l.setAttribute("d",We(F[g],C,t));});}function De(){if(e.style.setProperty("--scroll-draw-progress","0"),z){e.style.clipPath=j(0);return}x.forEach((t,s)=>{t.style.strokeDasharray=`${v[s]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${v[s]}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`),C&&t.tagName.toLowerCase()==="path"&&F[s]&&t.setAttribute("d",F[s]);});}if(x.forEach(t=>{Ye(t);let s=xe(t);v.push(s),t.tagName.toLowerCase()==="path"?F.push(t.getAttribute("d")??""):F.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(t.style.opacity="1"),S&&(t.style.stroke=S),k!==null&&(t.style.strokeWidth=`${k}`),T!==null&&(t.style.fillOpacity=`${T}`),C&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",C)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`));}),z){if(n)return e.style.clipPath=j(1),K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=j(0);}else if(n)return K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function _e(){return !(qe===false||!Qe()||!x.length||typeof p!="string"||!(p in Re)||z||b!=="y"||$||c!==1||I!==0||d||ee||re!==false||C||te||J||pe>0||ye||he||K||H!=null||V!=null||G!=null||(h.start??"top bottom").trim()!=="top bottom"||(h.end??"bottom top").trim()!=="bottom top")}function Xe(){let t=`svg-scroll-draw-${++Ke}`,s=a==="reverse"?"0":"var(--ssd-len)",l=a==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${s};`,_=`stroke-dashoffset:${l};`;u&&(g+=`opacity:${a==="reverse"?1:0};`,_+=`opacity:${a==="reverse"?0:1};`);let E=document.createElement("style");E.setAttribute("data-svg-scroll-draw",""),E.textContent=`@keyframes ${t}{from{${g}}to{${_}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Re[p]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(E);function i(m,L){m.style.setProperty("--ssd-len",String(v[L])),m.style.strokeDasharray=`${v[L]}`,m.style.strokeDashoffset="",m.style.opacity="",m.style.animationPlayState="",m.classList.add(t);}x.forEach(i);let f=false,w=-1;function y(){if(w>=0)return w;let m=e.getBoundingClientRect(),{tStart:L,tEnd:Z}=Ee({top:m.top,height:m.height},Y(),Pe(),ke,Ae);return ne(X(Y(),L,Z,c))}return {destroy(){x.forEach(m=>{m.classList.remove(t),m.style.removeProperty("--ssd-len"),m.style.animationPlayState="";}),E.remove();},replay(){f=false,w=-1,x.forEach(i);},pause(){f=true,x.forEach(m=>{m.style.animationPlayState="paused";});},resume(){f&&(f=false,x.forEach(m=>{m.style.animationPlayState="running";}));},seek(m){let L=Math.min(1,Math.max(0,m));w=L,f=true,x.forEach((Z,Ie)=>{Z.classList.remove(t),Z.style.strokeDashoffset=a==="reverse"?`${v[Ie]*L}`:`${v[Ie]*(1-L)}`,u&&(Z.style.opacity=a==="reverse"?`${1-L}`:`${L}`);});},getProgress(){return y()}}}if(_e())return Xe();Le();function ce(){if(!se||B)return;let t=performance.now(),s=Y(),l=c;if(re!==false){let i=t-Te,f=i>0?Math.abs(s-(ue<0?s:ue))/i:0;l=c*Math.max(.2,1+f*(typeof re=="number"?re:1)*.04);}ue=s,Te=t;let g=ee?oe===-1||s>=oe?"forward":"reverse":a;oe=s;let _=R-N,E=true;if(z){let i=ne(X(s,N,R,l));d&&!ee&&(P=Math.max(P,i),i=P),ie=i,e.style.setProperty("--scroll-draw-progress",String(i));let f=g==="reverse"?1-i:i;e.style.clipPath=j(f),ye?.(i),!q&&X(s,N,R,l)>0&&(q=true,he?.()),i>=1&&!D?(D=true,K?.(),Q<(J==="infinite"?1/0:J??0)&&(Q++,ae=setTimeout(()=>{P=-1,q=false,D=false,e.style.clipPath=j(0);},Me))):i<1&&!d&&(D=false),W=requestAnimationFrame(ce);return}if(x.forEach((i,f)=>{let w=f*I*_,y=ne(X(s,N+w,R+w,l));d&&!ee&&(P=Math.max(P,y),y=P),ie=y,i.style.strokeDashoffset=g==="reverse"?`${v[f]*y}`:`${v[f]*(1-y)}`,u&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),O&&S?i.style.stroke=Se(O,S,y):S&&(i.style.stroke=S),M!==null&&k!==null?i.style.strokeWidth=`${M+(k-M)*y}`:k!==null&&(i.style.strokeWidth=`${k}`),A!==null&&T!==null?i.style.fillOpacity=`${A+(T-A)*y}`:T!==null&&(i.style.fillOpacity=`${T}`),C&&i.tagName.toLowerCase()==="path"&&F[f]&&i.setAttribute("d",We(F[f],C,y)),f===0&&(ye?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(E=false);}),te){let i=ne(X(s,N,R,l));for(let f in te){let w=parseFloat(f);i>=w&&!le.has(w)&&(le.add(w),te[f]?.());}}!q&&X(s,N,R,l)>0&&(q=true,he?.()),E&&!D?(D=true,K?.(),Q<(J==="infinite"?1/0:J??0)&&(Q++,ae=setTimeout(()=>{P=-1,q=false,D=false,le.clear(),De();},Me))):!E&&!d&&(D=false),W=requestAnimationFrame(ce);}let be=new IntersectionObserver(t=>{t.forEach(s=>{se=s.isIntersecting,se&&!B?W=requestAnimationFrame(ce):cancelAnimationFrame(W);});},{root:$??null,threshold:Ge,rootMargin:ze}),ve;function fe(){clearTimeout(ve),ve=setTimeout(()=>{x.forEach((t,s)=>{v[s]=xe(t),t.style.strokeDasharray=`${v[s]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),pe>0?setTimeout(()=>be.observe(e),pe):be.observe(e),{destroy(){cancelAnimationFrame(W),clearTimeout(ae),be.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(ve),ge?.remove();},replay(){P=-1,oe=-1,ue=-1,q=false,D=false,Q=0,B=false,le.clear(),clearTimeout(ae),De();},pause(){B=true,cancelAnimationFrame(W);},resume(){B&&(B=false,se&&(W=requestAnimationFrame(ce)));},seek(t){let s=Math.min(1,Math.max(0,t));ie=s,P=s,B=true,cancelAnimationFrame(W),Be(s,a);},getProgress(){return ie}}}var Ve=class{constructor(){this.instance=null;}init(r,n={}){return this.destroy(),this.instance=He(r,n),this}replay(){return this.instance?.replay(),this}destroy(){return this.instance?.destroy(),this.instance=null,this}};export{Ve as ScrollDrawRef};
@@ -1,3 +1,3 @@
1
- 'use strict';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)};function ye(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 Ae(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 Te(e,r){if(/^\d+(\.\d+)?%$/.test(e))return r*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return r/2;case "bottom":return r;default:return r}}function ge(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),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 Re(e,r,n){return Math.min(n,Math.max(r,e))}function z(e,r,n,o){return n===r?0:Re((e-r)/(n-r)*o,0,1)}function ke(e,r,n,o,a){let f=Ae(e.top,e.height,r,o.element)-Te(o.viewport,n),p=Ae(e.top,e.height,r,a.element)-Te(a.viewport,n);return {tStart:f,tEnd:p}}function De(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 he(e,r,n){let o=De(e),a=De(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 Me(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function We(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Me("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Me("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ve(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 f=n==="x"?window.scrollX:window.scrollY,p=e-f,L=r-f,B=n==="x";o.innerHTML=`
2
- <div style="position:absolute;${B?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${B?`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",a,{passive:true}),a(),o}function Le(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let p=parseFloat(f),L=o[a++]??p;return String(+(p+(L-p)*n).toFixed(4))})}function ne(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:f=false,easing:p="linear",trigger:L={},stagger:B=0,direction:I="forward",once:X=false,debug:Ie=false,axis:x="y",scrollContainer:se,autoReverse:oe=false,delay:be=0,strokeColor:F,strokeWidth:N,fillOpacity:H,waypoints:ie,velocityScale:le=false,threshold:Oe=0,rootMargin:Pe="0px",repeat:_=0,repeatDelay:we=0,morphTo:O,clip:ae,onProgress:ve,onStart:xe,onComplete:J}=r,R=ae===true?"left":typeof ae=="string"?ae:false,ce=typeof p=="function"?p:de[p]??de.linear,Ce=ye(L.start??"top bottom"),Fe=ye(L.end??"bottom top"),d=typeof se=="string"?document.querySelector(se):se??null,S=Array.isArray(F)?F[0]:null,y=Array.isArray(F)?F[1]:typeof F=="string"?F:null,g=Array.isArray(N)?N[0]:null,h=Array.isArray(N)?N[1]:typeof N=="number"?N:null,b=Array.isArray(H)?H[0]:null,w=Array.isArray(H)?H[1]:typeof H=="number"?H:null;function W(t){let s=t*100;switch(R){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 q=R?[]:Array.from(e.querySelectorAll(o)),E=[],A=[],T=0,D=0,$=false,P=false,k=0,j=false,v=-1,K=-1,C=false,Q=0,G=0,U,ue=null,Y=new Set,Z=-1,Ee=performance.now();function fe(){return d?x==="x"?d.scrollLeft:d.scrollTop:x==="x"?window.scrollX:window.scrollY}function Ne(){return d?x==="x"?d.clientWidth:d.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function $e(){let t=e.getBoundingClientRect(),s,l,m;if(d){let V=d.getBoundingClientRect();s=x==="x"?t.left-V.left+d.scrollLeft:t.top-V.top+d.scrollTop,l=x==="x"?t.width:t.height,m=fe();}else s=x==="x"?t.left:t.top,l=x==="x"?t.width:t.height,m=fe();let re=ke({top:s,height:l},m,Ne(),Ce,Fe);T=re.tStart,D=re.tEnd,Ie&&process.env.NODE_ENV!=="production"&&(ue?.remove(),ue=Ve(T,D,x));}function He(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),R){let l=s==="reverse"?1-t:t;e.style.clipPath=W(l);return}q.forEach((l,m)=>{l.style.strokeDashoffset=s==="reverse"?`${E[m]*t}`:`${E[m]*(1-t)}`,f&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),S&&y?l.style.stroke=he(S,y,t):y&&(l.style.stroke=y),g!==null&&h!==null?l.style.strokeWidth=`${g+(h-g)*t}`:h!==null&&(l.style.strokeWidth=`${h}`),b!==null&&w!==null?l.style.fillOpacity=`${b+(w-b)*t}`:w!==null&&(l.style.fillOpacity=`${w}`),O&&l.tagName.toLowerCase()==="path"&&A[m]&&l.setAttribute("d",Le(A[m],O,t));});}function Se(){if(e.style.setProperty("--scroll-draw-progress","0"),R){e.style.clipPath=W(0);return}q.forEach((t,s)=>{t.style.strokeDasharray=`${E[s]}`,t.style.strokeDashoffset=I==="reverse"?"0":`${E[s]}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",S&&(t.style.stroke=S),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`),O&&t.tagName.toLowerCase()==="path"&&A[s]&&t.setAttribute("d",A[s]);});}if(q.forEach(t=>{We(t);let s=ge(t);E.push(s),t.tagName.toLowerCase()==="path"?A.push(t.getAttribute("d")??""):A.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=I==="reverse"?`${s}`:"0",f&&(t.style.opacity="1"),y&&(t.style.stroke=y),h!==null&&(t.style.strokeWidth=`${h}`),w!==null&&(t.style.fillOpacity=`${w}`),O&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",O)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=I==="reverse"?"0":`${s}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",S&&(t.style.stroke=S),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`));}),R){if(n)return e.style.clipPath=W(1),J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=W(0);}else if(n)return J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};$e();function ee(){if(!j||C)return;let t=performance.now(),s=fe(),l=a;if(le!==false){let i=t-Ee,u=i>0?Math.abs(s-(Z<0?s:Z))/i:0;l=a*Math.max(.2,1+u*(typeof le=="number"?le:1)*.04);}Z=s,Ee=t;let m=oe?K===-1||s>=K?"forward":"reverse":I;K=s;let re=D-T,V=true;if(R){let i=ce(z(s,T,D,l));X&&!oe&&(v=Math.max(v,i),i=v),Q=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=m==="reverse"?1-i:i;e.style.clipPath=W(u),ve?.(i),!P&&z(s,T,D,l)>0&&(P=true,xe?.()),i>=1&&!$?($=true,J?.(),G<(_==="infinite"?1/0:_??0)&&(G++,U=setTimeout(()=>{v=-1,P=false,$=false,e.style.clipPath=W(0);},we))):i<1&&!X&&($=false),k=requestAnimationFrame(ee);return}if(q.forEach((i,u)=>{let M=u*B*re,c=ce(z(s,T+M,D+M,l));X&&!oe&&(v=Math.max(v,c),c=v),Q=c,i.style.strokeDashoffset=m==="reverse"?`${E[u]*c}`:`${E[u]*(1-c)}`,f&&(i.style.opacity=m==="reverse"?`${1-c}`:`${c}`),S&&y?i.style.stroke=he(S,y,c):y&&(i.style.stroke=y),g!==null&&h!==null?i.style.strokeWidth=`${g+(h-g)*c}`:h!==null&&(i.style.strokeWidth=`${h}`),b!==null&&w!==null?i.style.fillOpacity=`${b+(w-b)*c}`:w!==null&&(i.style.fillOpacity=`${w}`),O&&i.tagName.toLowerCase()==="path"&&A[u]&&i.setAttribute("d",Le(A[u],O,c)),u===0&&(ve?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(V=false);}),ie){let i=ce(z(s,T,D,l));for(let u in ie){let M=parseFloat(u);i>=M&&!Y.has(M)&&(Y.add(M),ie[u]?.());}}!P&&z(s,T,D,l)>0&&(P=true,xe?.()),V&&!$?($=true,J?.(),G<(_==="infinite"?1/0:_??0)&&(G++,U=setTimeout(()=>{v=-1,P=false,$=false,Y.clear(),Se();},we))):!V&&!X&&($=false),k=requestAnimationFrame(ee);}let pe=new IntersectionObserver(t=>{t.forEach(s=>{j=s.isIntersecting,j&&!C?k=requestAnimationFrame(ee):cancelAnimationFrame(k);});},{root:d??null,threshold:Oe,rootMargin:Pe}),me;function te(){clearTimeout(me),me=setTimeout(()=>{q.forEach((t,s)=>{E[s]=ge(t),t.style.strokeDasharray=`${E[s]}`;}),$e();},150);}return window.addEventListener("resize",te),window.addEventListener("orientationchange",te),be>0?setTimeout(()=>pe.observe(e),be):pe.observe(e),{destroy(){cancelAnimationFrame(k),clearTimeout(U),pe.disconnect(),window.removeEventListener("resize",te),window.removeEventListener("orientationchange",te),clearTimeout(me),ue?.remove();},replay(){v=-1,K=-1,Z=-1,P=false,$=false,G=0,C=false,Y.clear(),clearTimeout(U),Se();},pause(){C=true,cancelAnimationFrame(k);},resume(){C&&(C=false,j&&(k=requestAnimationFrame(ee)));},seek(t){let s=Math.min(1,Math.max(0,t));Q=s,v=s,C=true,cancelAnimationFrame(k),He(s,I);},getProgress(){return Q}}}function ze(e,r){let n={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};if(typeof window>"u")return n;let o=typeof e=="string"?document.querySelector(e):e;return o?ne(o,r):(console.warn("[svg-scroll-draw] Container not found:",e),n)}function Qe(e=document){return Array.from(e.querySelectorAll("[data-scroll-draw]")).map(r=>{let n={};try{let o=r.dataset.scrollDrawOptions??r.dataset.scrollDrawoptions??"";o&&(n=JSON.parse(o));}catch{}return ne(r,n)})}exports.initScrollDraw=Qe;exports.scrollDraw=ze;
1
+ 'use strict';function Re({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),s=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(s),u=0,m=[];for(let a=0;a<n;a++){let d=Math.pow(c,a);m.push(d),u+=d;}let h=[0],I=0;for(let a=0;a<n;a++)I+=m[a]/u,h.push(I);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let d=0;d<n;d++)if(a<=h[d+1]){let J=(a-h[d])/(h[d+1]-h[d]);if(d===0)return J*(2-J);let b=1-Math.pow(s,d);return b+(1-b)*(2*J-1)*(2*J-1)}return 1}}function We({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),s=Math.max(.1,r),c=n<=1?s/4:s/(2*Math.PI)*Math.asin(1/n);return u=>u<=0?0:u>=1?1:n*Math.pow(2,-10*u)*Math.sin((u-c)*(2*Math.PI)/s)+1}var xe={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:Re(),elastic:We()};function Ee(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",s="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:s}}function Ce(e,r,n,s){switch(s){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function Fe(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"),s=parseFloat(e.getAttribute("height")??"0");return 2*(n+s)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function Ue(e,r,n){return Math.min(n,Math.max(r,e))}function X(e,r,n,s){return n===r?0:Ue((e-r)/(n-r)*s,0,1)}function $e(e,r,n,s,c){let u=Ce(e.top,e.height,r,s.element)-Fe(s.viewport,n),m=Ce(e.top,e.height,r,c.element)-Fe(c.viewport,n);return {tStart:u,tEnd:m}}function Ne(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 s=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return s?[parseInt(s[1]),parseInt(s[2]),parseInt(s[3])]:null}function Me(e,r,n){let s=Ne(e),c=Ne(r);return !s||!c?e:`rgb(${Math.round(s[0]+(c[0]-s[0])*n)},${Math.round(s[1]+(c[1]-s[1])*n)},${Math.round(s[2]+(c[2]-s[2])*n)})`}function He(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ve={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},je=0;function Ke(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function Qe(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?He("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&He("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ye(e,r,n){let s=document.createElement("div");s.setAttribute("data-svg-scroll-draw-debug",""),s.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 u=n==="x"?window.scrollX:window.scrollY,m=e-u,h=r-u,I=n==="x";s.innerHTML=`
2
+ <div style="position:absolute;${I?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}padding:2px 6px;color:#22c55e;background:rgba(0,0,0,.6)">\u25B6 start</div>
3
+ <div style="position:absolute;${I?`left:${h}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${h}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(s),window.addEventListener("scroll",c,{passive:true}),c(),s}function qe(e,r,n){let s=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let m=parseFloat(u),h=s[c++]??m;return String(+(m+(h-m)*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:s="path, polyline, line, polygon, rect, circle",speed:c=1,fade:u=false,easing:m="linear",trigger:h={},stagger:I=0,direction:a="forward",once:d=false,debug:J=false,axis:b="y",scrollContainer:me,autoReverse:ee=false,delay:de=0,strokeColor:H,strokeWidth:V,fillOpacity:q,waypoints:te,velocityScale:re=false,threshold:Ge=0,rootMargin:ze="0px",repeat:j=0,repeatDelay:ke=0,morphTo:O,clip:ye,native:Be=true,onProgress:he,onStart:ge,onComplete:K}=r,G=ye===true?"left":typeof ye=="string"?ye:false,ne=typeof m=="function"?m:xe[m]??xe.linear,Ae=Ee(h.start??"top bottom"),De=Ee(h.end??"bottom top"),x=typeof me=="string"?document.querySelector(me):me??null,C=Array.isArray(H)?H[0]:null,$=Array.isArray(H)?H[1]:typeof H=="string"?H:null,M=Array.isArray(V)?V[0]:null,k=Array.isArray(V)?V[1]:typeof V=="number"?V:null,A=Array.isArray(q)?q[0]:null,D=Array.isArray(q)?q[1]:typeof q=="number"?q:null;function U(t){let o=t*100;switch(G){case "right":return `inset(0 0 0 ${100-o}%)`;case "top":return `inset(0 0 ${100-o}% 0)`;case "bottom":return `inset(${100-o}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-o}% 0 0)`}}let E=G?[]:Array.from(e.querySelectorAll(s)),w=[],F=[],N=0,R=0,L=false,z=false,W=0,se=false,T=-1,oe=-1,B=false,ie=0,Q=0,ae,be=null,le=new Set,ue=-1,Te=performance.now();function Y(){return x?b==="x"?x.scrollLeft:x.scrollTop:b==="x"?window.scrollX:window.scrollY}function Pe(){return x?b==="x"?x.clientWidth:x.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),o,l,g;if(x){let S=x.getBoundingClientRect();o=b==="x"?t.left-S.left+x.scrollLeft:t.top-S.top+x.scrollTop,l=b==="x"?t.width:t.height,g=Y();}else o=b==="x"?t.left:t.top,l=b==="x"?t.width:t.height,g=Y();let _=$e({top:o,height:l},g,Pe(),Ae,De);N=_.tStart,R=_.tEnd,J&&process.env.NODE_ENV!=="production"&&(be?.remove(),be=Ye(N,R,b));}function _e(t,o){if(e.style.setProperty("--scroll-draw-progress",String(t)),G){let l=o==="reverse"?1-t:t;e.style.clipPath=U(l);return}E.forEach((l,g)=>{l.style.strokeDashoffset=o==="reverse"?`${w[g]*t}`:`${w[g]*(1-t)}`,u&&(l.style.opacity=o==="reverse"?`${1-t}`:`${t}`),C&&$?l.style.stroke=Me(C,$,t):$&&(l.style.stroke=$),M!==null&&k!==null?l.style.strokeWidth=`${M+(k-M)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),A!==null&&D!==null?l.style.fillOpacity=`${A+(D-A)*t}`:D!==null&&(l.style.fillOpacity=`${D}`),O&&l.tagName.toLowerCase()==="path"&&F[g]&&l.setAttribute("d",qe(F[g],O,t));});}function Ie(){if(e.style.setProperty("--scroll-draw-progress","0"),G){e.style.clipPath=U(0);return}E.forEach((t,o)=>{t.style.strokeDasharray=`${w[o]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${w[o]}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`),O&&t.tagName.toLowerCase()==="path"&&F[o]&&t.setAttribute("d",F[o]);});}if(E.forEach(t=>{Qe(t);let o=Se(t);w.push(o),t.tagName.toLowerCase()==="path"?F.push(t.getAttribute("d")??""):F.push(""),n?(t.style.strokeDasharray=`${o}`,t.style.strokeDashoffset=a==="reverse"?`${o}`:"0",u&&(t.style.opacity="1"),$&&(t.style.stroke=$),k!==null&&(t.style.strokeWidth=`${k}`),D!==null&&(t.style.fillOpacity=`${D}`),O&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",O)):(t.style.strokeDasharray=`${o}`,t.style.strokeDashoffset=a==="reverse"?"0":`${o}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`));}),G){if(n)return e.style.clipPath=U(1),K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=U(0);}else if(n)return K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Xe(){return !(Be===false||!Ke()||!E.length||typeof m!="string"||!(m in Ve)||G||b!=="y"||x||c!==1||I!==0||d||ee||re!==false||O||te||j||de>0||he||ge||K||H!=null||V!=null||q!=null||(h.start??"top bottom").trim()!=="top bottom"||(h.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++je}`,o=a==="reverse"?"0":"var(--ssd-len)",l=a==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${o};`,_=`stroke-dashoffset:${l};`;u&&(g+=`opacity:${a==="reverse"?1:0};`,_+=`opacity:${a==="reverse"?0:1};`);let S=document.createElement("style");S.setAttribute("data-svg-scroll-draw",""),S.textContent=`@keyframes ${t}{from{${g}}to{${_}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ve[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(S);function i(p,P){p.style.setProperty("--ssd-len",String(w[P])),p.style.strokeDasharray=`${w[P]}`,p.style.strokeDashoffset="",p.style.opacity="",p.style.animationPlayState="",p.classList.add(t);}E.forEach(i);let f=false,v=-1;function y(){if(v>=0)return v;let p=e.getBoundingClientRect(),{tStart:P,tEnd:Z}=$e({top:p.top,height:p.height},Y(),Pe(),Ae,De);return ne(X(Y(),P,Z,c))}return {destroy(){E.forEach(p=>{p.classList.remove(t),p.style.removeProperty("--ssd-len"),p.style.animationPlayState="";}),S.remove();},replay(){f=false,v=-1,E.forEach(i);},pause(){f=true,E.forEach(p=>{p.style.animationPlayState="paused";});},resume(){f&&(f=false,E.forEach(p=>{p.style.animationPlayState="running";}));},seek(p){let P=Math.min(1,Math.max(0,p));v=P,f=true,E.forEach((Z,Oe)=>{Z.classList.remove(t),Z.style.strokeDashoffset=a==="reverse"?`${w[Oe]*P}`:`${w[Oe]*(1-P)}`,u&&(Z.style.opacity=a==="reverse"?`${1-P}`:`${P}`);});},getProgress(){return y()}}}if(Xe())return Je();Le();function ce(){if(!se||B)return;let t=performance.now(),o=Y(),l=c;if(re!==false){let i=t-Te,f=i>0?Math.abs(o-(ue<0?o:ue))/i:0;l=c*Math.max(.2,1+f*(typeof re=="number"?re:1)*.04);}ue=o,Te=t;let g=ee?oe===-1||o>=oe?"forward":"reverse":a;oe=o;let _=R-N,S=true;if(G){let i=ne(X(o,N,R,l));d&&!ee&&(T=Math.max(T,i),i=T),ie=i,e.style.setProperty("--scroll-draw-progress",String(i));let f=g==="reverse"?1-i:i;e.style.clipPath=U(f),he?.(i),!z&&X(o,N,R,l)>0&&(z=true,ge?.()),i>=1&&!L?(L=true,K?.(),Q<(j==="infinite"?1/0:j??0)&&(Q++,ae=setTimeout(()=>{T=-1,z=false,L=false,e.style.clipPath=U(0);},ke))):i<1&&!d&&(L=false),W=requestAnimationFrame(ce);return}if(E.forEach((i,f)=>{let v=f*I*_,y=ne(X(o,N+v,R+v,l));d&&!ee&&(T=Math.max(T,y),y=T),ie=y,i.style.strokeDashoffset=g==="reverse"?`${w[f]*y}`:`${w[f]*(1-y)}`,u&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),C&&$?i.style.stroke=Me(C,$,y):$&&(i.style.stroke=$),M!==null&&k!==null?i.style.strokeWidth=`${M+(k-M)*y}`:k!==null&&(i.style.strokeWidth=`${k}`),A!==null&&D!==null?i.style.fillOpacity=`${A+(D-A)*y}`:D!==null&&(i.style.fillOpacity=`${D}`),O&&i.tagName.toLowerCase()==="path"&&F[f]&&i.setAttribute("d",qe(F[f],O,y)),f===0&&(he?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(S=false);}),te){let i=ne(X(o,N,R,l));for(let f in te){let v=parseFloat(f);i>=v&&!le.has(v)&&(le.add(v),te[f]?.());}}!z&&X(o,N,R,l)>0&&(z=true,ge?.()),S&&!L?(L=true,K?.(),Q<(j==="infinite"?1/0:j??0)&&(Q++,ae=setTimeout(()=>{T=-1,z=false,L=false,le.clear(),Ie();},ke))):!S&&!d&&(L=false),W=requestAnimationFrame(ce);}let we=new IntersectionObserver(t=>{t.forEach(o=>{se=o.isIntersecting,se&&!B?W=requestAnimationFrame(ce):cancelAnimationFrame(W);});},{root:x??null,threshold:Ge,rootMargin:ze}),ve;function fe(){clearTimeout(ve),ve=setTimeout(()=>{E.forEach((t,o)=>{w[o]=Se(t),t.style.strokeDasharray=`${w[o]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),de>0?setTimeout(()=>we.observe(e),de):we.observe(e),{destroy(){cancelAnimationFrame(W),clearTimeout(ae),we.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(ve),be?.remove();},replay(){T=-1,oe=-1,ue=-1,z=false,L=false,Q=0,B=false,le.clear(),clearTimeout(ae),Ie();},pause(){B=true,cancelAnimationFrame(W);},resume(){B&&(B=false,se&&(W=requestAnimationFrame(ce)));},seek(t){let o=Math.min(1,Math.max(0,t));ie=o,T=o,B=true,cancelAnimationFrame(W),_e(o,a);},getProgress(){return ie}}}function Ze(e,r){let n={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};if(typeof window>"u")return n;let s=typeof e=="string"?document.querySelector(e):e;return s?pe(s,r):(console.warn("[svg-scroll-draw] Container not found:",e),n)}function lt(e=document){return Array.from(e.querySelectorAll("[data-scroll-draw]")).map(r=>{let n={};try{let s=r.dataset.scrollDrawOptions??r.dataset.scrollDrawoptions??"";s&&(n=JSON.parse(s));}catch{}return pe(r,n)})}exports.initScrollDraw=lt;exports.scrollDraw=Ze;
@@ -1,4 +1,4 @@
1
- type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
1
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
2
2
  interface TriggerConfig {
3
3
  start?: string;
4
4
  end?: string;
@@ -60,6 +60,20 @@ interface ScrollDrawOptions {
60
60
  onProgress?: (alpha: number) => void;
61
61
  onStart?: () => void;
62
62
  onComplete?: () => void;
63
+ /**
64
+ * Use the browser's native CSS scroll-driven animation
65
+ * (`animation-timeline: view()`) when the configuration is simple enough and
66
+ * the browser supports it. This runs the draw entirely on the compositor —
67
+ * zero per-frame JavaScript, zero scroll/resize listeners.
68
+ *
69
+ * Falls back to the JS engine automatically when unsupported or when the
70
+ * config uses a feature native CSS can't express (callbacks, stagger, morph,
71
+ * velocity scaling, custom triggers, `once`, custom easing functions, etc.).
72
+ *
73
+ * - `undefined` / `true` (default): use native when eligible.
74
+ * - `false`: always use the JS engine.
75
+ */
76
+ native?: boolean;
63
77
  }
64
78
  interface ScrollDrawInstance {
65
79
  destroy: () => void;
@@ -1,4 +1,4 @@
1
- type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
1
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'bounce' | 'elastic';
2
2
  interface TriggerConfig {
3
3
  start?: string;
4
4
  end?: string;
@@ -60,6 +60,20 @@ interface ScrollDrawOptions {
60
60
  onProgress?: (alpha: number) => void;
61
61
  onStart?: () => void;
62
62
  onComplete?: () => void;
63
+ /**
64
+ * Use the browser's native CSS scroll-driven animation
65
+ * (`animation-timeline: view()`) when the configuration is simple enough and
66
+ * the browser supports it. This runs the draw entirely on the compositor —
67
+ * zero per-frame JavaScript, zero scroll/resize listeners.
68
+ *
69
+ * Falls back to the JS engine automatically when unsupported or when the
70
+ * config uses a feature native CSS can't express (callbacks, stagger, morph,
71
+ * velocity scaling, custom triggers, `once`, custom easing functions, etc.).
72
+ *
73
+ * - `undefined` / `true` (default): use native when eligible.
74
+ * - `false`: always use the JS engine.
75
+ */
76
+ native?: boolean;
63
77
  }
64
78
  interface ScrollDrawInstance {
65
79
  destroy: () => void;
@@ -1,3 +1,3 @@
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)};function ye(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 Ae(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 Te(e,r){if(/^\d+(\.\d+)?%$/.test(e))return r*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return r/2;case "bottom":return r;default:return r}}function ge(e){let r=e.tagName.toLowerCase();if(r==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),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 Re(e,r,n){return Math.min(n,Math.max(r,e))}function z(e,r,n,o){return n===r?0:Re((e-r)/(n-r)*o,0,1)}function ke(e,r,n,o,a){let f=Ae(e.top,e.height,r,o.element)-Te(o.viewport,n),p=Ae(e.top,e.height,r,a.element)-Te(a.viewport,n);return {tStart:f,tEnd:p}}function De(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 he(e,r,n){let o=De(e),a=De(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 Me(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}function We(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?Me("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&Me("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ve(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 f=n==="x"?window.scrollX:window.scrollY,p=e-f,L=r-f,B=n==="x";o.innerHTML=`
2
- <div style="position:absolute;${B?`left:${p}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${p}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;${B?`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",a,{passive:true}),a(),o}function Le(e,r,n){let o=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),a=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,f=>{let p=parseFloat(f),L=o[a++]??p;return String(+(p+(L-p)*n).toFixed(4))})}function ne(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:f=false,easing:p="linear",trigger:L={},stagger:B=0,direction:I="forward",once:X=false,debug:Ie=false,axis:x="y",scrollContainer:se,autoReverse:oe=false,delay:be=0,strokeColor:F,strokeWidth:N,fillOpacity:H,waypoints:ie,velocityScale:le=false,threshold:Oe=0,rootMargin:Pe="0px",repeat:_=0,repeatDelay:we=0,morphTo:O,clip:ae,onProgress:ve,onStart:xe,onComplete:J}=r,R=ae===true?"left":typeof ae=="string"?ae:false,ce=typeof p=="function"?p:de[p]??de.linear,Ce=ye(L.start??"top bottom"),Fe=ye(L.end??"bottom top"),d=typeof se=="string"?document.querySelector(se):se??null,S=Array.isArray(F)?F[0]:null,y=Array.isArray(F)?F[1]:typeof F=="string"?F:null,g=Array.isArray(N)?N[0]:null,h=Array.isArray(N)?N[1]:typeof N=="number"?N:null,b=Array.isArray(H)?H[0]:null,w=Array.isArray(H)?H[1]:typeof H=="number"?H:null;function W(t){let s=t*100;switch(R){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 q=R?[]:Array.from(e.querySelectorAll(o)),E=[],A=[],T=0,D=0,$=false,P=false,k=0,j=false,v=-1,K=-1,C=false,Q=0,G=0,U,ue=null,Y=new Set,Z=-1,Ee=performance.now();function fe(){return d?x==="x"?d.scrollLeft:d.scrollTop:x==="x"?window.scrollX:window.scrollY}function Ne(){return d?x==="x"?d.clientWidth:d.clientHeight:x==="x"?window.innerWidth:window.innerHeight}function $e(){let t=e.getBoundingClientRect(),s,l,m;if(d){let V=d.getBoundingClientRect();s=x==="x"?t.left-V.left+d.scrollLeft:t.top-V.top+d.scrollTop,l=x==="x"?t.width:t.height,m=fe();}else s=x==="x"?t.left:t.top,l=x==="x"?t.width:t.height,m=fe();let re=ke({top:s,height:l},m,Ne(),Ce,Fe);T=re.tStart,D=re.tEnd,Ie&&process.env.NODE_ENV!=="production"&&(ue?.remove(),ue=Ve(T,D,x));}function He(t,s){if(e.style.setProperty("--scroll-draw-progress",String(t)),R){let l=s==="reverse"?1-t:t;e.style.clipPath=W(l);return}q.forEach((l,m)=>{l.style.strokeDashoffset=s==="reverse"?`${E[m]*t}`:`${E[m]*(1-t)}`,f&&(l.style.opacity=s==="reverse"?`${1-t}`:`${t}`),S&&y?l.style.stroke=he(S,y,t):y&&(l.style.stroke=y),g!==null&&h!==null?l.style.strokeWidth=`${g+(h-g)*t}`:h!==null&&(l.style.strokeWidth=`${h}`),b!==null&&w!==null?l.style.fillOpacity=`${b+(w-b)*t}`:w!==null&&(l.style.fillOpacity=`${w}`),O&&l.tagName.toLowerCase()==="path"&&A[m]&&l.setAttribute("d",Le(A[m],O,t));});}function Se(){if(e.style.setProperty("--scroll-draw-progress","0"),R){e.style.clipPath=W(0);return}q.forEach((t,s)=>{t.style.strokeDasharray=`${E[s]}`,t.style.strokeDashoffset=I==="reverse"?"0":`${E[s]}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",S&&(t.style.stroke=S),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`),O&&t.tagName.toLowerCase()==="path"&&A[s]&&t.setAttribute("d",A[s]);});}if(q.forEach(t=>{We(t);let s=ge(t);E.push(s),t.tagName.toLowerCase()==="path"?A.push(t.getAttribute("d")??""):A.push(""),n?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=I==="reverse"?`${s}`:"0",f&&(t.style.opacity="1"),y&&(t.style.stroke=y),h!==null&&(t.style.strokeWidth=`${h}`),w!==null&&(t.style.fillOpacity=`${w}`),O&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",O)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=I==="reverse"?"0":`${s}`,f?t.style.opacity=I==="reverse"?"1":"0":t.style.opacity="",S&&(t.style.stroke=S),g!==null&&(t.style.strokeWidth=`${g}`),b!==null&&(t.style.fillOpacity=`${b}`));}),R){if(n)return e.style.clipPath=W(1),J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=W(0);}else if(n)return J?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};$e();function ee(){if(!j||C)return;let t=performance.now(),s=fe(),l=a;if(le!==false){let i=t-Ee,u=i>0?Math.abs(s-(Z<0?s:Z))/i:0;l=a*Math.max(.2,1+u*(typeof le=="number"?le:1)*.04);}Z=s,Ee=t;let m=oe?K===-1||s>=K?"forward":"reverse":I;K=s;let re=D-T,V=true;if(R){let i=ce(z(s,T,D,l));X&&!oe&&(v=Math.max(v,i),i=v),Q=i,e.style.setProperty("--scroll-draw-progress",String(i));let u=m==="reverse"?1-i:i;e.style.clipPath=W(u),ve?.(i),!P&&z(s,T,D,l)>0&&(P=true,xe?.()),i>=1&&!$?($=true,J?.(),G<(_==="infinite"?1/0:_??0)&&(G++,U=setTimeout(()=>{v=-1,P=false,$=false,e.style.clipPath=W(0);},we))):i<1&&!X&&($=false),k=requestAnimationFrame(ee);return}if(q.forEach((i,u)=>{let M=u*B*re,c=ce(z(s,T+M,D+M,l));X&&!oe&&(v=Math.max(v,c),c=v),Q=c,i.style.strokeDashoffset=m==="reverse"?`${E[u]*c}`:`${E[u]*(1-c)}`,f&&(i.style.opacity=m==="reverse"?`${1-c}`:`${c}`),S&&y?i.style.stroke=he(S,y,c):y&&(i.style.stroke=y),g!==null&&h!==null?i.style.strokeWidth=`${g+(h-g)*c}`:h!==null&&(i.style.strokeWidth=`${h}`),b!==null&&w!==null?i.style.fillOpacity=`${b+(w-b)*c}`:w!==null&&(i.style.fillOpacity=`${w}`),O&&i.tagName.toLowerCase()==="path"&&A[u]&&i.setAttribute("d",Le(A[u],O,c)),u===0&&(ve?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(V=false);}),ie){let i=ce(z(s,T,D,l));for(let u in ie){let M=parseFloat(u);i>=M&&!Y.has(M)&&(Y.add(M),ie[u]?.());}}!P&&z(s,T,D,l)>0&&(P=true,xe?.()),V&&!$?($=true,J?.(),G<(_==="infinite"?1/0:_??0)&&(G++,U=setTimeout(()=>{v=-1,P=false,$=false,Y.clear(),Se();},we))):!V&&!X&&($=false),k=requestAnimationFrame(ee);}let pe=new IntersectionObserver(t=>{t.forEach(s=>{j=s.isIntersecting,j&&!C?k=requestAnimationFrame(ee):cancelAnimationFrame(k);});},{root:d??null,threshold:Oe,rootMargin:Pe}),me;function te(){clearTimeout(me),me=setTimeout(()=>{q.forEach((t,s)=>{E[s]=ge(t),t.style.strokeDasharray=`${E[s]}`;}),$e();},150);}return window.addEventListener("resize",te),window.addEventListener("orientationchange",te),be>0?setTimeout(()=>pe.observe(e),be):pe.observe(e),{destroy(){cancelAnimationFrame(k),clearTimeout(U),pe.disconnect(),window.removeEventListener("resize",te),window.removeEventListener("orientationchange",te),clearTimeout(me),ue?.remove();},replay(){v=-1,K=-1,Z=-1,P=false,$=false,G=0,C=false,Y.clear(),clearTimeout(U),Se();},pause(){C=true,cancelAnimationFrame(k);},resume(){C&&(C=false,j&&(k=requestAnimationFrame(ee)));},seek(t){let s=Math.min(1,Math.max(0,t));Q=s,v=s,C=true,cancelAnimationFrame(k),He(s,I);},getProgress(){return Q}}}function ze(e,r){let n={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};if(typeof window>"u")return n;let o=typeof e=="string"?document.querySelector(e):e;return o?ne(o,r):(console.warn("[svg-scroll-draw] Container not found:",e),n)}function Qe(e=document){return Array.from(e.querySelectorAll("[data-scroll-draw]")).map(r=>{let n={};try{let o=r.dataset.scrollDrawOptions??r.dataset.scrollDrawoptions??"";o&&(n=JSON.parse(o));}catch{}return ne(r,n)})}export{Qe as initScrollDraw,ze as scrollDraw};
1
+ function Re({bounces:e=3,decay:r=.5}={}){let n=Math.max(1,Math.round(e)),s=Math.max(.01,Math.min(.99,r)),c=Math.sqrt(s),u=0,m=[];for(let a=0;a<n;a++){let d=Math.pow(c,a);m.push(d),u+=d;}let h=[0],I=0;for(let a=0;a<n;a++)I+=m[a]/u,h.push(I);return a=>{if(a<=0)return 0;if(a>=1)return 1;for(let d=0;d<n;d++)if(a<=h[d+1]){let J=(a-h[d])/(h[d+1]-h[d]);if(d===0)return J*(2-J);let b=1-Math.pow(s,d);return b+(1-b)*(2*J-1)*(2*J-1)}return 1}}function We({amplitude:e=1,period:r=.4}={}){let n=Math.max(1,e),s=Math.max(.1,r),c=n<=1?s/4:s/(2*Math.PI)*Math.asin(1/n);return u=>u<=0?0:u>=1?1:n*Math.pow(2,-10*u)*Math.sin((u-c)*(2*Math.PI)/s)+1}var xe={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:Re(),elastic:We()};function Ee(e="top bottom"){let r=e.trim();if(/^\d+(\.\d+)?%$/.test(r))return {element:"top",viewport:r};let[n="top",s="bottom"]=r.split(/\s+/).filter(Boolean);return {element:n,viewport:s}}function Ce(e,r,n,s){switch(s){case "top":return e+n;case "center":return e+n+r/2;case "bottom":return e+n+r;default:return e+n}}function Fe(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"),s=parseFloat(e.getAttribute("height")??"0");return 2*(n+s)}if(r==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function Ue(e,r,n){return Math.min(n,Math.max(r,e))}function X(e,r,n,s){return n===r?0:Ue((e-r)/(n-r)*s,0,1)}function $e(e,r,n,s,c){let u=Ce(e.top,e.height,r,s.element)-Fe(s.viewport,n),m=Ce(e.top,e.height,r,c.element)-Fe(c.viewport,n);return {tStart:u,tEnd:m}}function Ne(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 s=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return s?[parseInt(s[1]),parseInt(s[2]),parseInt(s[3])]:null}function Me(e,r,n){let s=Ne(e),c=Ne(r);return !s||!c?e:`rgb(${Math.round(s[0]+(c[0]-s[0])*n)},${Math.round(s[1]+(c[1]-s[1])*n)},${Math.round(s[2]+(c[2]-s[2])*n)})`}function He(e,r){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,r);}var Ve={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},je=0;function Ke(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function Qe(e){let r=e.getAttribute("stroke"),n=e.getAttribute("fill");!r||r==="none"?He("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&He("Element has a fill \u2014 it may obscure the stroke animation.",e);}function Ye(e,r,n){let s=document.createElement("div");s.setAttribute("data-svg-scroll-draw-debug",""),s.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 u=n==="x"?window.scrollX:window.scrollY,m=e-u,h=r-u,I=n==="x";s.innerHTML=`
2
+ <div style="position:absolute;${I?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}padding:2px 6px;color:#22c55e;background:rgba(0,0,0,.6)">\u25B6 start</div>
3
+ <div style="position:absolute;${I?`left:${h}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${h}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(s),window.addEventListener("scroll",c,{passive:true}),c(),s}function qe(e,r,n){let s=(r.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,u=>{let m=parseFloat(u),h=s[c++]??m;return String(+(m+(h-m)*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:s="path, polyline, line, polygon, rect, circle",speed:c=1,fade:u=false,easing:m="linear",trigger:h={},stagger:I=0,direction:a="forward",once:d=false,debug:J=false,axis:b="y",scrollContainer:me,autoReverse:ee=false,delay:de=0,strokeColor:H,strokeWidth:V,fillOpacity:q,waypoints:te,velocityScale:re=false,threshold:Ge=0,rootMargin:ze="0px",repeat:j=0,repeatDelay:ke=0,morphTo:O,clip:ye,native:Be=true,onProgress:he,onStart:ge,onComplete:K}=r,G=ye===true?"left":typeof ye=="string"?ye:false,ne=typeof m=="function"?m:xe[m]??xe.linear,Ae=Ee(h.start??"top bottom"),De=Ee(h.end??"bottom top"),x=typeof me=="string"?document.querySelector(me):me??null,C=Array.isArray(H)?H[0]:null,$=Array.isArray(H)?H[1]:typeof H=="string"?H:null,M=Array.isArray(V)?V[0]:null,k=Array.isArray(V)?V[1]:typeof V=="number"?V:null,A=Array.isArray(q)?q[0]:null,D=Array.isArray(q)?q[1]:typeof q=="number"?q:null;function U(t){let o=t*100;switch(G){case "right":return `inset(0 0 0 ${100-o}%)`;case "top":return `inset(0 0 ${100-o}% 0)`;case "bottom":return `inset(${100-o}% 0 0 0)`;case "center":return `circle(${t*150}% at 50% 50%)`;default:return `inset(0 ${100-o}% 0 0)`}}let E=G?[]:Array.from(e.querySelectorAll(s)),w=[],F=[],N=0,R=0,L=false,z=false,W=0,se=false,T=-1,oe=-1,B=false,ie=0,Q=0,ae,be=null,le=new Set,ue=-1,Te=performance.now();function Y(){return x?b==="x"?x.scrollLeft:x.scrollTop:b==="x"?window.scrollX:window.scrollY}function Pe(){return x?b==="x"?x.clientWidth:x.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function Le(){let t=e.getBoundingClientRect(),o,l,g;if(x){let S=x.getBoundingClientRect();o=b==="x"?t.left-S.left+x.scrollLeft:t.top-S.top+x.scrollTop,l=b==="x"?t.width:t.height,g=Y();}else o=b==="x"?t.left:t.top,l=b==="x"?t.width:t.height,g=Y();let _=$e({top:o,height:l},g,Pe(),Ae,De);N=_.tStart,R=_.tEnd,J&&process.env.NODE_ENV!=="production"&&(be?.remove(),be=Ye(N,R,b));}function _e(t,o){if(e.style.setProperty("--scroll-draw-progress",String(t)),G){let l=o==="reverse"?1-t:t;e.style.clipPath=U(l);return}E.forEach((l,g)=>{l.style.strokeDashoffset=o==="reverse"?`${w[g]*t}`:`${w[g]*(1-t)}`,u&&(l.style.opacity=o==="reverse"?`${1-t}`:`${t}`),C&&$?l.style.stroke=Me(C,$,t):$&&(l.style.stroke=$),M!==null&&k!==null?l.style.strokeWidth=`${M+(k-M)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),A!==null&&D!==null?l.style.fillOpacity=`${A+(D-A)*t}`:D!==null&&(l.style.fillOpacity=`${D}`),O&&l.tagName.toLowerCase()==="path"&&F[g]&&l.setAttribute("d",qe(F[g],O,t));});}function Ie(){if(e.style.setProperty("--scroll-draw-progress","0"),G){e.style.clipPath=U(0);return}E.forEach((t,o)=>{t.style.strokeDasharray=`${w[o]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${w[o]}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`),O&&t.tagName.toLowerCase()==="path"&&F[o]&&t.setAttribute("d",F[o]);});}if(E.forEach(t=>{Qe(t);let o=Se(t);w.push(o),t.tagName.toLowerCase()==="path"?F.push(t.getAttribute("d")??""):F.push(""),n?(t.style.strokeDasharray=`${o}`,t.style.strokeDashoffset=a==="reverse"?`${o}`:"0",u&&(t.style.opacity="1"),$&&(t.style.stroke=$),k!==null&&(t.style.strokeWidth=`${k}`),D!==null&&(t.style.fillOpacity=`${D}`),O&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",O)):(t.style.strokeDasharray=`${o}`,t.style.strokeDashoffset=a==="reverse"?"0":`${o}`,u?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",C&&(t.style.stroke=C),M!==null&&(t.style.strokeWidth=`${M}`),A!==null&&(t.style.fillOpacity=`${A}`));}),G){if(n)return e.style.clipPath=U(1),K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=U(0);}else if(n)return K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Xe(){return !(Be===false||!Ke()||!E.length||typeof m!="string"||!(m in Ve)||G||b!=="y"||x||c!==1||I!==0||d||ee||re!==false||O||te||j||de>0||he||ge||K||H!=null||V!=null||q!=null||(h.start??"top bottom").trim()!=="top bottom"||(h.end??"bottom top").trim()!=="bottom top")}function Je(){let t=`svg-scroll-draw-${++je}`,o=a==="reverse"?"0":"var(--ssd-len)",l=a==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${o};`,_=`stroke-dashoffset:${l};`;u&&(g+=`opacity:${a==="reverse"?1:0};`,_+=`opacity:${a==="reverse"?0:1};`);let S=document.createElement("style");S.setAttribute("data-svg-scroll-draw",""),S.textContent=`@keyframes ${t}{from{${g}}to{${_}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ve[m]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(S);function i(p,P){p.style.setProperty("--ssd-len",String(w[P])),p.style.strokeDasharray=`${w[P]}`,p.style.strokeDashoffset="",p.style.opacity="",p.style.animationPlayState="",p.classList.add(t);}E.forEach(i);let f=false,v=-1;function y(){if(v>=0)return v;let p=e.getBoundingClientRect(),{tStart:P,tEnd:Z}=$e({top:p.top,height:p.height},Y(),Pe(),Ae,De);return ne(X(Y(),P,Z,c))}return {destroy(){E.forEach(p=>{p.classList.remove(t),p.style.removeProperty("--ssd-len"),p.style.animationPlayState="";}),S.remove();},replay(){f=false,v=-1,E.forEach(i);},pause(){f=true,E.forEach(p=>{p.style.animationPlayState="paused";});},resume(){f&&(f=false,E.forEach(p=>{p.style.animationPlayState="running";}));},seek(p){let P=Math.min(1,Math.max(0,p));v=P,f=true,E.forEach((Z,Oe)=>{Z.classList.remove(t),Z.style.strokeDashoffset=a==="reverse"?`${w[Oe]*P}`:`${w[Oe]*(1-P)}`,u&&(Z.style.opacity=a==="reverse"?`${1-P}`:`${P}`);});},getProgress(){return y()}}}if(Xe())return Je();Le();function ce(){if(!se||B)return;let t=performance.now(),o=Y(),l=c;if(re!==false){let i=t-Te,f=i>0?Math.abs(o-(ue<0?o:ue))/i:0;l=c*Math.max(.2,1+f*(typeof re=="number"?re:1)*.04);}ue=o,Te=t;let g=ee?oe===-1||o>=oe?"forward":"reverse":a;oe=o;let _=R-N,S=true;if(G){let i=ne(X(o,N,R,l));d&&!ee&&(T=Math.max(T,i),i=T),ie=i,e.style.setProperty("--scroll-draw-progress",String(i));let f=g==="reverse"?1-i:i;e.style.clipPath=U(f),he?.(i),!z&&X(o,N,R,l)>0&&(z=true,ge?.()),i>=1&&!L?(L=true,K?.(),Q<(j==="infinite"?1/0:j??0)&&(Q++,ae=setTimeout(()=>{T=-1,z=false,L=false,e.style.clipPath=U(0);},ke))):i<1&&!d&&(L=false),W=requestAnimationFrame(ce);return}if(E.forEach((i,f)=>{let v=f*I*_,y=ne(X(o,N+v,R+v,l));d&&!ee&&(T=Math.max(T,y),y=T),ie=y,i.style.strokeDashoffset=g==="reverse"?`${w[f]*y}`:`${w[f]*(1-y)}`,u&&(i.style.opacity=g==="reverse"?`${1-y}`:`${y}`),C&&$?i.style.stroke=Me(C,$,y):$&&(i.style.stroke=$),M!==null&&k!==null?i.style.strokeWidth=`${M+(k-M)*y}`:k!==null&&(i.style.strokeWidth=`${k}`),A!==null&&D!==null?i.style.fillOpacity=`${A+(D-A)*y}`:D!==null&&(i.style.fillOpacity=`${D}`),O&&i.tagName.toLowerCase()==="path"&&F[f]&&i.setAttribute("d",qe(F[f],O,y)),f===0&&(he?.(y),e.style.setProperty("--scroll-draw-progress",String(y))),y<1&&(S=false);}),te){let i=ne(X(o,N,R,l));for(let f in te){let v=parseFloat(f);i>=v&&!le.has(v)&&(le.add(v),te[f]?.());}}!z&&X(o,N,R,l)>0&&(z=true,ge?.()),S&&!L?(L=true,K?.(),Q<(j==="infinite"?1/0:j??0)&&(Q++,ae=setTimeout(()=>{T=-1,z=false,L=false,le.clear(),Ie();},ke))):!S&&!d&&(L=false),W=requestAnimationFrame(ce);}let we=new IntersectionObserver(t=>{t.forEach(o=>{se=o.isIntersecting,se&&!B?W=requestAnimationFrame(ce):cancelAnimationFrame(W);});},{root:x??null,threshold:Ge,rootMargin:ze}),ve;function fe(){clearTimeout(ve),ve=setTimeout(()=>{E.forEach((t,o)=>{w[o]=Se(t),t.style.strokeDasharray=`${w[o]}`;}),Le();},150);}return window.addEventListener("resize",fe),window.addEventListener("orientationchange",fe),de>0?setTimeout(()=>we.observe(e),de):we.observe(e),{destroy(){cancelAnimationFrame(W),clearTimeout(ae),we.disconnect(),window.removeEventListener("resize",fe),window.removeEventListener("orientationchange",fe),clearTimeout(ve),be?.remove();},replay(){T=-1,oe=-1,ue=-1,z=false,L=false,Q=0,B=false,le.clear(),clearTimeout(ae),Ie();},pause(){B=true,cancelAnimationFrame(W);},resume(){B&&(B=false,se&&(W=requestAnimationFrame(ce)));},seek(t){let o=Math.min(1,Math.max(0,t));ie=o,T=o,B=true,cancelAnimationFrame(W),_e(o,a);},getProgress(){return ie}}}function Ze(e,r){let n={destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};if(typeof window>"u")return n;let s=typeof e=="string"?document.querySelector(e):e;return s?pe(s,r):(console.warn("[svg-scroll-draw] Container not found:",e),n)}function lt(e=document){return Array.from(e.querySelectorAll("[data-scroll-draw]")).map(r=>{let n={};try{let s=r.dataset.scrollDrawOptions??r.dataset.scrollDrawoptions??"";s&&(n=JSON.parse(s));}catch{}return pe(r,n)})}export{lt as initScrollDraw,Ze as scrollDraw};