svg-scroll-draw 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular/index.cjs +3 -3
- package/dist/angular/index.d.mts +19 -0
- package/dist/angular/index.d.ts +19 -0
- package/dist/angular/index.mjs +3 -3
- package/dist/astro/index.cjs +3 -3
- package/dist/astro/index.d.mts +19 -0
- package/dist/astro/index.d.ts +19 -0
- package/dist/astro/index.mjs +3 -3
- package/dist/cdn/svg-scroll-draw.global.js +3 -3
- package/dist/group/index.cjs +3 -3
- package/dist/group/index.d.mts +19 -0
- package/dist/group/index.d.ts +19 -0
- package/dist/group/index.mjs +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.mjs +3 -3
- package/dist/nuxt/index.cjs +3 -3
- package/dist/nuxt/index.d.mts +19 -0
- package/dist/nuxt/index.d.ts +19 -0
- package/dist/nuxt/index.mjs +3 -3
- package/dist/react/index.cjs +3 -3
- package/dist/react/index.d.mts +19 -0
- package/dist/react/index.d.ts +19 -0
- package/dist/react/index.mjs +3 -3
- package/dist/solid/index.cjs +3 -3
- package/dist/solid/index.d.mts +19 -0
- package/dist/solid/index.d.ts +19 -0
- package/dist/solid/index.mjs +3 -3
- package/dist/svelte/index.cjs +3 -3
- package/dist/svelte/index.d.mts +19 -0
- package/dist/svelte/index.d.ts +19 -0
- package/dist/svelte/index.mjs +3 -3
- package/dist/vue/index.cjs +3 -3
- package/dist/vue/index.d.mts +19 -0
- package/dist/vue/index.d.ts +19 -0
- package/dist/vue/index.mjs +3 -3
- package/dist/web-component/index.cjs +3 -3
- package/dist/web-component/index.mjs +3 -3
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function
|
|
2
|
-
<div style="position:absolute;${
|
|
3
|
-
<div style="position:absolute;${C?`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",c,{passive:true}),c(),o}function He(e,n,r){let o=(n.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),c=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,l=>{let f=parseFloat(l),d=o[c++]??f;return String(+(f+(d-f)*r).toFixed(4))})}function Ve(e,n={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:c=1,fade:l=false,easing:f="linear",trigger:d={},stagger:C=0,direction:a="forward",once:y=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:I,clip:de,native:qe=true,onProgress:ye,onStart:he,onComplete:K}=n,z=de===true?"left":typeof de=="string"?de:false,ne=typeof f=="function"?f:ve[f]??ve.linear,ke=Ee(d.start??"top bottom"),Te=Ee(d.end??"bottom top"),E=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,A=Array.isArray(V)?V[0]:null,M=Array.isArray(V)?V[1]:typeof V=="number"?V:null,k=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 $=z?[]:Array.from(e.querySelectorAll(o)),w=[],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,Pe=performance.now();function Y(){return E?b==="x"?E.scrollLeft:E.scrollTop:b==="x"?window.scrollX:window.scrollY}function Le(){return E?b==="x"?E.clientWidth:E.clientHeight:b==="x"?window.innerWidth:window.innerHeight}function De(){let t=e.getBoundingClientRect(),s,u,g;if(E){let x=E.getBoundingClientRect();s=b==="x"?t.left-x.left+E.scrollLeft:t.top-x.top+E.scrollTop,u=b==="x"?t.width:t.height,g=Y();}else s=b==="x"?t.left:t.top,u=b==="x"?t.width:t.height,g=Y();let _=xe({top:s,height:u},g,Le(),ke,Te);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 u=s==="reverse"?1-t:t;e.style.clipPath=j(u);return}$.forEach((u,g)=>{u.style.strokeDashoffset=s==="reverse"?`${w[g]*t}`:`${w[g]*(1-t)}`,l&&(u.style.opacity=s==="reverse"?`${1-t}`:`${t}`),O&&S?u.style.stroke=Se(O,S,t):S&&(u.style.stroke=S),A!==null&&M!==null?u.style.strokeWidth=`${A+(M-A)*t}`:M!==null&&(u.style.strokeWidth=`${M}`),k!==null&&T!==null?u.style.fillOpacity=`${k+(T-k)*t}`:T!==null&&(u.style.fillOpacity=`${T}`),I&&u.tagName.toLowerCase()==="path"&&F[g]&&u.setAttribute("d",He(F[g],I,t));});}function Ce(){if(e.style.setProperty("--scroll-draw-progress","0"),z){e.style.clipPath=j(0);return}$.forEach((t,s)=>{t.style.strokeDasharray=`${w[s]}`,t.style.strokeDashoffset=a==="reverse"?"0":`${w[s]}`,l?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),A!==null&&(t.style.strokeWidth=`${A}`),k!==null&&(t.style.fillOpacity=`${k}`),I&&t.tagName.toLowerCase()==="path"&&F[s]&&t.setAttribute("d",F[s]);});}if($.forEach(t=>{Ye(t);let s=$e(t);w.push(s),t.tagName.toLowerCase()==="path"?F.push(t.getAttribute("d")??""):F.push(""),r?(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?`${s}`:"0",l&&(t.style.opacity="1"),S&&(t.style.stroke=S),M!==null&&(t.style.strokeWidth=`${M}`),T!==null&&(t.style.fillOpacity=`${T}`),I&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",I)):(t.style.strokeDasharray=`${s}`,t.style.strokeDashoffset=a==="reverse"?"0":`${s}`,l?t.style.opacity=a==="reverse"?"1":"0":t.style.opacity="",O&&(t.style.stroke=O),A!==null&&(t.style.strokeWidth=`${A}`),k!==null&&(t.style.fillOpacity=`${k}`));}),z){if(r)return e.style.clipPath=j(1),K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=j(0);}else if(r)return K?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function _e(){return !(qe===false||!Qe()||!$.length||typeof f!="string"||!(f in We)||z||b!=="y"||E||c!==1||C!==0||y||ee||re!==false||I||te||J||pe>0||ye||he||K||H!=null||V!=null||G!=null||(d.start??"top bottom").trim()!=="top bottom"||(d.end??"bottom top").trim()!=="bottom top")}function Xe(){let t=`svg-scroll-draw-${++Ke}`,s=a==="reverse"?"0":"var(--ssd-len)",u=a==="reverse"?"var(--ssd-len)":"0",g=`stroke-dashoffset:${s};`,_=`stroke-dashoffset:${u};`;l&&(g+=`opacity:${a==="reverse"?1:0};`,_+=`opacity:${a==="reverse"?0:1};`);let x=document.createElement("style");x.setAttribute("data-svg-scroll-draw",""),x.textContent=`@keyframes ${t}{from{${g}}to{${_}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${We[f]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(x);function i(p,L){p.style.setProperty("--ssd-len",String(w[L])),p.style.strokeDasharray=`${w[L]}`,p.style.strokeDashoffset="",p.style.opacity="",p.style.animationPlayState="",p.classList.add(t);}$.forEach(i);let m=false,v=-1;function h(){if(v>=0)return v;let p=e.getBoundingClientRect(),{tStart:L,tEnd:Z}=xe({top:p.top,height:p.height},Y(),Le(),ke,Te);return ne(X(Y(),L,Z,c))}return {destroy(){$.forEach(p=>{p.classList.remove(t),p.style.removeProperty("--ssd-len"),p.style.animationPlayState="";}),x.remove();},replay(){m=false,v=-1,$.forEach(i);},pause(){m=true,$.forEach(p=>{p.style.animationPlayState="paused";});},resume(){m&&(m=false,$.forEach(p=>{p.style.animationPlayState="running";}));},seek(p){let L=Math.min(1,Math.max(0,p));v=L,m=true,$.forEach((Z,Ie)=>{Z.classList.remove(t),Z.style.strokeDashoffset=a==="reverse"?`${w[Ie]*L}`:`${w[Ie]*(1-L)}`,l&&(Z.style.opacity=a==="reverse"?`${1-L}`:`${L}`);});},getProgress(){return h()}}}if(_e())return Xe();De();function ce(){if(!se||B)return;let t=performance.now(),s=Y(),u=c;if(re!==false){let i=t-Pe,m=i>0?Math.abs(s-(ue<0?s:ue))/i:0;u=c*Math.max(.2,1+m*(typeof re=="number"?re:1)*.04);}ue=s,Pe=t;let g=ee?oe===-1||s>=oe?"forward":"reverse":a;oe=s;let _=R-N,x=true;if(z){let i=ne(X(s,N,R,u));y&&!ee&&(P=Math.max(P,i),i=P),ie=i,e.style.setProperty("--scroll-draw-progress",String(i));let m=g==="reverse"?1-i:i;e.style.clipPath=j(m),ye?.(i),!q&&X(s,N,R,u)>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&&!y&&(D=false),W=requestAnimationFrame(ce);return}if($.forEach((i,m)=>{let v=m*C*_,h=ne(X(s,N+v,R+v,u));y&&!ee&&(P=Math.max(P,h),h=P),ie=h,i.style.strokeDashoffset=g==="reverse"?`${w[m]*h}`:`${w[m]*(1-h)}`,l&&(i.style.opacity=g==="reverse"?`${1-h}`:`${h}`),O&&S?i.style.stroke=Se(O,S,h):S&&(i.style.stroke=S),A!==null&&M!==null?i.style.strokeWidth=`${A+(M-A)*h}`:M!==null&&(i.style.strokeWidth=`${M}`),k!==null&&T!==null?i.style.fillOpacity=`${k+(T-k)*h}`:T!==null&&(i.style.fillOpacity=`${T}`),I&&i.tagName.toLowerCase()==="path"&&F[m]&&i.setAttribute("d",He(F[m],I,h)),m===0&&(ye?.(h),e.style.setProperty("--scroll-draw-progress",String(h))),h<1&&(x=false);}),te){let i=ne(X(s,N,R,u));for(let m in te){let v=parseFloat(m);i>=v&&!le.has(v)&&(le.add(v),te[m]?.());}}!q&&X(s,N,R,u)>0&&(q=true,he?.()),x&&!D?(D=true,K?.(),Q<(J==="infinite"?1/0:J??0)&&(Q++,ae=setTimeout(()=>{P=-1,q=false,D=false,le.clear(),Ce();},Me))):!x&&!y&&(D=false),W=requestAnimationFrame(ce);}let be=new IntersectionObserver(t=>{t.forEach(s=>{se=s.isIntersecting,se&&!B?W=requestAnimationFrame(ce):cancelAnimationFrame(W);});},{root:E??null,threshold:Ge,rootMargin:ze}),we;function fe(){clearTimeout(we),we=setTimeout(()=>{$.forEach((t,s)=>{w[s]=$e(t),t.style.strokeDasharray=`${w[s]}`;}),De();},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(we),ge?.remove();},replay(){P=-1,oe=-1,ue=-1,q=false,D=false,Q=0,B=false,le.clear(),clearTimeout(ae),Ce();},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 Ae=class extends HTMLElement{constructor(){super(...arguments);this.instance=null;}connectedCallback(){let r={},o=this.getAttribute("speed"),c=this.getAttribute("easing"),l=this.getAttribute("stagger"),f=this.getAttribute("direction"),d=this.getAttribute("selector");o&&(r.speed=parseFloat(o)),c&&(r.easing=c),l&&(r.stagger=parseFloat(l)),f&&(r.direction=f),d&&(r.selector=d),this.hasAttribute("fade")&&(r.fade=this.getAttribute("fade")!=="false"),this.instance=Ve(this,r);}disconnectedCallback(){this.instance?.destroy(),this.instance=null;}};typeof customElements<"u"&&!customElements.get("scroll-draw")&&customElements.define("scroll-draw",Ae);
|
|
1
|
+
function Ye({bounces:e=3,decay:s=.5}={}){let r=Math.max(1,Math.round(e)),o=Math.max(.01,Math.min(.99,s)),p=Math.sqrt(o),m=0,y=[];for(let u=0;u<r;u++){let g=Math.pow(p,u);y.push(g),m+=g;}let w=[0],R=0;for(let u=0;u<r;u++)R+=y[u]/m,w.push(R);return u=>{if(u<=0)return 0;if(u>=1)return 1;for(let g=0;g<r;g++)if(u<=w[g+1]){let se=(u-w[g])/(w[g+1]-w[g]);if(g===0)return se*(2-se);let P=1-Math.pow(o,g);return P+(1-P)*(2*se-1)*(2*se-1)}return 1}}function Ze({amplitude:e=1,period:s=.4}={}){let r=Math.max(1,e),o=Math.max(.1,s),p=r<=1?o/4:o/(2*Math.PI)*Math.asin(1/r);return m=>m<=0?0:m>=1?1:r*Math.pow(2,-10*m)*Math.sin((m-p)*(2*Math.PI)/o)+1}var Te={linear:e=>e,"ease-in":e=>e*e,"ease-out":e=>e*(2-e),"ease-in-out":e=>e<.5?2*e*e:-1+(4-2*e)*e,spring:e=>1-Math.cos(e*Math.PI*2.5)*Math.pow(1-e,2.2),bounce:Ye(),elastic:Ze()};function Se(e="top bottom"){let s=e.trim();if(/^\d+(\.\d+)?%$/.test(s))return {element:"top",viewport:s};let[r="top",o="bottom"]=s.split(/\s+/).filter(Boolean);return {element:r,viewport:o}}function We(e,s,r,o){switch(o){case "top":return e+r;case "center":return e+r+s/2;case "bottom":return e+r+s;default:return e+r}}function ze(e,s){if(/^\d+(\.\d+)?%$/.test(e))return s*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return s/2;case "bottom":return s;default:return s}}function we(e){let s=e.tagName.toLowerCase();if(s==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(s==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function et(e,s,r){return Math.min(r,Math.max(s,e))}function ne(e,s,r,o){return r===s?0:et((e-s)/(r-s)*o,0,1)}function Le(e,s,r,o,p){let m=We(e.top,e.height,s,o.element)-ze(o.viewport,r),y=We(e.top,e.height,s,p.element)-ze(p.viewport,r);return {tStart:m,tEnd:y}}function qe(e){let s=/^#([a-f\d])([a-f\d])([a-f\d])$/i.exec(e);if(s)return [parseInt(s[1]+s[1],16),parseInt(s[2]+s[2],16),parseInt(s[3]+s[3],16)];let r=/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(r)return [parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16)];let o=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(e);return o?[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]:null}function ve(e,s,r){let o=qe(e),p=qe(s);return !o||!p?e:`rgb(${Math.round(o[0]+(p[0]-o[0])*r)},${Math.round(o[1]+(p[1]-o[1])*r)},${Math.round(o[2]+(p[2]-o[2])*r)})`}function Ve(e,s){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,s);}var Ge={linear:"linear","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out"},tt=0;function rt(){return typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("animation-timeline: view()")}function nt(e){let s=e.getAttribute("stroke"),r=e.getAttribute("fill");!s||s==="none"?Ve("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&Ve("Element has a fill \u2014 it may obscure the stroke animation.",e);}function st(e,s,r){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 p(){let m=r==="x"?window.scrollX:window.scrollY,y=e-m,w=s-m,R=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;${R?`left:${y}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${y}px;left:0;right:0;border-top:2px dashed #22c55e;`}padding:2px 6px;color:#22c55e;background:rgba(0,0,0,.6)">\u25B6 start</div>
|
|
3
|
+
<div style="position:absolute;${R?`left:${w}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${w}px;left:0;right:0;border-top:2px dashed #ef4444;`}padding:2px 6px;color:#ef4444;background:rgba(0,0,0,.6)">\u25A0 end</div>`;}return document.body.appendChild(o),window.addEventListener("scroll",p,{passive:true}),p(),o}function Pe(e,s,r){let o=(s.match(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g)??[]).map(Number),p=0;return e.replace(/[-+]?(?:\d*\.)?\d+(?:[eE][-+]?\d+)?/g,m=>{let y=parseFloat(m),w=o[p++]??y;return String(+(y+(w-y)*r).toFixed(4))})}function Be(e,s={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>0};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:p=1,fade:m=false,easing:y="linear",trigger:w={},stagger:R=0,direction:u="forward",once:g=false,debug:se=false,axis:P="y",scrollContainer:Ee,autoReverse:ce=false,delay:ae=0,strokeColor:j,strokeWidth:J,fillOpacity:K,waypoints:Q,velocityScale:fe=false,threshold:Ie=0,rootMargin:Fe="0px",repeat:Y=0,repeatDelay:$e=0,morphTo:N,clip:xe,autoplay:_e=false,duration:Xe=1e3,native:Ue=true,onProgress:le,onStart:me,onComplete:oe}=s,G=xe===true?"left":typeof xe=="string"?xe:false,Z=typeof y=="function"?y:Te[y]??Te.linear,Ce=Se(w.start??"top bottom"),Oe=Se(w.end??"bottom top"),D=typeof Ee=="string"?document.querySelector(Ee):Ee??null,H=Array.isArray(j)?j[0]:null,M=Array.isArray(j)?j[1]:typeof j=="string"?j:null,I=Array.isArray(J)?J[0]:null,k=Array.isArray(J)?J[1]:typeof J=="number"?J:null,F=Array.isArray(K)?K[0]:null,T=Array.isArray(K)?K[1]:typeof K=="number"?K:null;function ee(t){let n=t*100;switch(G){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 x=G?[]:Array.from(e.querySelectorAll(o)),E=[],W=[],B=0,_=0,A=false,O=false,$=0,pe=false,z=-1,de=-1,S=false,te=0,V=0,X,Ae=null,U=new Set,ye=-1,Re=performance.now();function ue(){return D?P==="x"?D.scrollLeft:D.scrollTop:P==="x"?window.scrollX:window.scrollY}function Ne(){return D?P==="x"?D.clientWidth:D.clientHeight:P==="x"?window.innerWidth:window.innerHeight}function He(){let t=e.getBoundingClientRect(),n,l,b;if(D){let L=D.getBoundingClientRect();n=P==="x"?t.left-L.left+D.scrollLeft:t.top-L.top+D.scrollTop,l=P==="x"?t.width:t.height,b=ue();}else n=P==="x"?t.left:t.top,l=P==="x"?t.width:t.height,b=ue();let C=Le({top:n,height:l},b,Ne(),Ce,Oe);B=C.tStart,_=C.tEnd,se&&process.env.NODE_ENV!=="production"&&(Ae?.remove(),Ae=st(B,_,P));}function je(t,n){if(e.style.setProperty("--scroll-draw-progress",String(t)),G){let l=n==="reverse"?1-t:t;e.style.clipPath=ee(l);return}x.forEach((l,b)=>{l.style.strokeDashoffset=n==="reverse"?`${E[b]*t}`:`${E[b]*(1-t)}`,m&&(l.style.opacity=n==="reverse"?`${1-t}`:`${t}`),H&&M?l.style.stroke=ve(H,M,t):M&&(l.style.stroke=M),I!==null&&k!==null?l.style.strokeWidth=`${I+(k-I)*t}`:k!==null&&(l.style.strokeWidth=`${k}`),F!==null&&T!==null?l.style.fillOpacity=`${F+(T-F)*t}`:T!==null&&(l.style.fillOpacity=`${T}`),N&&l.tagName.toLowerCase()==="path"&&W[b]&&l.setAttribute("d",Pe(W[b],N,t));});}function he(){if(e.style.setProperty("--scroll-draw-progress","0"),G){e.style.clipPath=ee(0);return}x.forEach((t,n)=>{t.style.strokeDasharray=`${E[n]}`,t.style.strokeDashoffset=u==="reverse"?"0":`${E[n]}`,m?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),I!==null&&(t.style.strokeWidth=`${I}`),F!==null&&(t.style.fillOpacity=`${F}`),N&&t.tagName.toLowerCase()==="path"&&W[n]&&t.setAttribute("d",W[n]);});}if(x.forEach(t=>{nt(t);let n=we(t);E.push(n),t.tagName.toLowerCase()==="path"?W.push(t.getAttribute("d")??""):W.push(""),r?(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=u==="reverse"?`${n}`:"0",m&&(t.style.opacity="1"),M&&(t.style.stroke=M),k!==null&&(t.style.strokeWidth=`${k}`),T!==null&&(t.style.fillOpacity=`${T}`),N&&t.tagName.toLowerCase()==="path"&&t.setAttribute("d",N)):(t.style.strokeDasharray=`${n}`,t.style.strokeDashoffset=u==="reverse"?"0":`${n}`,m?t.style.opacity=u==="reverse"?"1":"0":t.style.opacity="",H&&(t.style.stroke=H),I!==null&&(t.style.strokeWidth=`${I}`),F!==null&&(t.style.fillOpacity=`${F}`));}),G){if(r)return e.style.clipPath=ee(1),oe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};e.style.clipPath=ee(0);}else if(r)return oe?.(),{destroy:()=>{},replay:()=>{},pause:()=>{},resume:()=>{},seek:()=>{},getProgress:()=>1};function Je(){return !(Ue===false||!rt()||!x.length||typeof y!="string"||!(y in Ge)||G||P!=="y"||D||p!==1||R!==0||g||ce||fe!==false||N||Q||Y||ae>0||le||me||oe||j!=null||J!=null||K!=null||(w.start??"top bottom").trim()!=="top bottom"||(w.end??"bottom top").trim()!=="bottom top")}function Ke(){let t=`svg-scroll-draw-${++tt}`,n=u==="reverse"?"0":"var(--ssd-len)",l=u==="reverse"?"var(--ssd-len)":"0",b=`stroke-dashoffset:${n};`,C=`stroke-dashoffset:${l};`;m&&(b+=`opacity:${u==="reverse"?1:0};`,C+=`opacity:${u==="reverse"?0:1};`);let L=document.createElement("style");L.setAttribute("data-svg-scroll-draw",""),L.textContent=`@keyframes ${t}{from{${b}}to{${C}}}.${t}{animation-name:${t};animation-duration:auto;animation-timing-function:${Ge[y]};animation-fill-mode:both;animation-timeline:view();animation-range:cover 0% cover 100%;}`,document.head.appendChild(L);function a(i,f){i.style.setProperty("--ssd-len",String(E[f])),i.style.strokeDasharray=`${E[f]}`,i.style.strokeDashoffset="",i.style.opacity="",i.style.animationPlayState="",i.classList.add(t);}x.forEach(a);let d=false,v=-1;function c(){if(v>=0)return v;let i=e.getBoundingClientRect(),{tStart:f,tEnd:h}=Le({top:i.top,height:i.height},ue(),Ne(),Ce,Oe);return Z(ne(ue(),f,h,p))}return {destroy(){x.forEach(i=>{i.classList.remove(t),i.style.removeProperty("--ssd-len"),i.style.animationPlayState="";}),L.remove();},replay(){d=false,v=-1,x.forEach(a);},pause(){d=true,x.forEach(i=>{i.style.animationPlayState="paused";});},resume(){d&&(d=false,x.forEach(i=>{i.style.animationPlayState="running";}));},seek(i){let f=Math.min(1,Math.max(0,i));v=f,d=true,x.forEach((h,re)=>{h.classList.remove(t),h.style.strokeDashoffset=u==="reverse"?`${E[re]*f}`:`${E[re]*(1-f)}`,m&&(h.style.opacity=u==="reverse"?`${1-f}`:`${f}`);});},getProgress(){return c()}}}if(Je())return Ke();function Qe(){let t=Math.max(1,Xe),n=0,l=0;function b(c){let i=true;if(G){let f=Math.min(1,Math.max(0,c/t)),h=Z(f);te=h,e.style.setProperty("--scroll-draw-progress",String(h)),e.style.clipPath=ee(u==="reverse"?1-h:h),le?.(h),f<1&&(i=false);}else x.forEach((f,h)=>{let re=h*R*t,ie=Math.min(1,Math.max(0,(c-re)/t)),q=Z(ie);f.style.strokeDashoffset=u==="reverse"?`${E[h]*q}`:`${E[h]*(1-q)}`,m&&(f.style.opacity=u==="reverse"?`${1-q}`:`${q}`),H&&M?f.style.stroke=ve(H,M,q):M&&(f.style.stroke=M),I!==null&&k!==null?f.style.strokeWidth=`${I+(k-I)*q}`:k!==null&&(f.style.strokeWidth=`${k}`),F!==null&&T!==null?f.style.fillOpacity=`${F+(T-F)*q}`:T!==null&&(f.style.fillOpacity=`${T}`),N&&f.tagName.toLowerCase()==="path"&&W[h]&&f.setAttribute("d",Pe(W[h],N,q)),h===0&&(le?.(q),e.style.setProperty("--scroll-draw-progress",String(q))),ie<1&&(i=false);});if(Q){let f=Math.min(1,Math.max(0,c/t)),h=Z(f);for(let re in Q){let ie=parseFloat(re);h>=ie&&!U.has(ie)&&(U.add(ie),Q[re]?.());}}return i}function C(c){if(S)return;let i=c-n;O||(O=true,me?.());let f=b(i);if(f&&!A){A=true,b(t*(1+Math.max(0,x.length-1)*R)),oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{n=performance.now(),O=false,A=false,U.clear(),he(),$=requestAnimationFrame(C);},$e));return}f||($=requestAnimationFrame(C));}function L(){cancelAnimationFrame($),clearTimeout(X),n=performance.now(),l=0,S=false,O=false,A=false,V=0,U.clear(),he(),$=requestAnimationFrame(C);}let a=new IntersectionObserver(c=>{c.forEach(i=>{i.isIntersecting&&!(g&&A)?L():!i.isIntersecting&&!g&&!A&&(cancelAnimationFrame($),clearTimeout(X),n=null);});},{root:D??null,threshold:Ie,rootMargin:Fe}),d;function v(){clearTimeout(d),d=setTimeout(()=>{x.forEach((c,i)=>{E[i]=we(c),c.style.strokeDasharray=`${E[i]}`;});},150);}return window.addEventListener("resize",v),window.addEventListener("orientationchange",v),ae>0?setTimeout(()=>a.observe(e),ae):a.observe(e),{destroy(){cancelAnimationFrame($),clearTimeout(X),a.disconnect(),window.removeEventListener("resize",v),window.removeEventListener("orientationchange",v),clearTimeout(d);},replay(){V=0,L();},pause(){S||(S=true,l=performance.now()-n,cancelAnimationFrame($));},resume(){S&&(S=false,n=performance.now()-l,$=requestAnimationFrame(C));},seek(c){let i=Math.min(1,Math.max(0,c));te=i,S=true,l=i*t,n=performance.now()-l,cancelAnimationFrame($),b(l);},getProgress(){return te}}}if(_e)return Qe();He();function ge(){if(!pe||S)return;let t=performance.now(),n=ue(),l=p;if(fe!==false){let a=t-Re,d=a>0?Math.abs(n-(ye<0?n:ye))/a:0;l=p*Math.max(.2,1+d*(typeof fe=="number"?fe:1)*.04);}ye=n,Re=t;let b=ce?de===-1||n>=de?"forward":"reverse":u;de=n;let C=_-B,L=true;if(G){let a=Z(ne(n,B,_,l));g&&!ce&&(z=Math.max(z,a),a=z),te=a,e.style.setProperty("--scroll-draw-progress",String(a));let d=b==="reverse"?1-a:a;e.style.clipPath=ee(d),le?.(a),!O&&ne(n,B,_,l)>0&&(O=true,me?.()),a>=1&&!A?(A=true,oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{z=-1,O=false,A=false,e.style.clipPath=ee(0);},$e))):a<1&&!g&&(A=false),$=requestAnimationFrame(ge);return}if(x.forEach((a,d)=>{let v=d*R*C,c=Z(ne(n,B+v,_+v,l));g&&!ce&&(z=Math.max(z,c),c=z),te=c,a.style.strokeDashoffset=b==="reverse"?`${E[d]*c}`:`${E[d]*(1-c)}`,m&&(a.style.opacity=b==="reverse"?`${1-c}`:`${c}`),H&&M?a.style.stroke=ve(H,M,c):M&&(a.style.stroke=M),I!==null&&k!==null?a.style.strokeWidth=`${I+(k-I)*c}`:k!==null&&(a.style.strokeWidth=`${k}`),F!==null&&T!==null?a.style.fillOpacity=`${F+(T-F)*c}`:T!==null&&(a.style.fillOpacity=`${T}`),N&&a.tagName.toLowerCase()==="path"&&W[d]&&a.setAttribute("d",Pe(W[d],N,c)),d===0&&(le?.(c),e.style.setProperty("--scroll-draw-progress",String(c))),c<1&&(L=false);}),Q){let a=Z(ne(n,B,_,l));for(let d in Q){let v=parseFloat(d);a>=v&&!U.has(v)&&(U.add(v),Q[d]?.());}}!O&&ne(n,B,_,l)>0&&(O=true,me?.()),L&&!A?(A=true,oe?.(),V<(Y==="infinite"?1/0:Y??0)&&(V++,X=setTimeout(()=>{z=-1,O=false,A=false,U.clear(),he();},$e))):!L&&!g&&(A=false),$=requestAnimationFrame(ge);}let Me=new IntersectionObserver(t=>{t.forEach(n=>{pe=n.isIntersecting,pe&&!S?$=requestAnimationFrame(ge):cancelAnimationFrame($);});},{root:D??null,threshold:Ie,rootMargin:Fe}),ke;function be(){clearTimeout(ke),ke=setTimeout(()=>{x.forEach((t,n)=>{E[n]=we(t),t.style.strokeDasharray=`${E[n]}`;}),He();},150);}return window.addEventListener("resize",be),window.addEventListener("orientationchange",be),ae>0?setTimeout(()=>Me.observe(e),ae):Me.observe(e),{destroy(){cancelAnimationFrame($),clearTimeout(X),Me.disconnect(),window.removeEventListener("resize",be),window.removeEventListener("orientationchange",be),clearTimeout(ke),Ae?.remove();},replay(){z=-1,de=-1,ye=-1,O=false,A=false,V=0,S=false,U.clear(),clearTimeout(X),he();},pause(){S=true,cancelAnimationFrame($);},resume(){S&&(S=false,pe&&($=requestAnimationFrame(ge)));},seek(t){let n=Math.min(1,Math.max(0,t));te=n,z=n,S=true,cancelAnimationFrame($),je(n,u);},getProgress(){return te}}}var De=class extends HTMLElement{constructor(){super(...arguments);this.instance=null;}connectedCallback(){let r={},o=this.getAttribute("speed"),p=this.getAttribute("easing"),m=this.getAttribute("stagger"),y=this.getAttribute("direction"),w=this.getAttribute("selector");o&&(r.speed=parseFloat(o)),p&&(r.easing=p),m&&(r.stagger=parseFloat(m)),y&&(r.direction=y),w&&(r.selector=w),this.hasAttribute("fade")&&(r.fade=this.getAttribute("fade")!=="false"),this.instance=Be(this,r);}disconnectedCallback(){this.instance?.destroy(),this.instance=null;}};typeof customElements<"u"&&!customElements.get("scroll-draw")&&customElements.define("scroll-draw",De);
|
package/package.json
CHANGED