svg-scroll-draw 0.2.0 → 0.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/README.md +178 -0
- package/dist/cdn/svg-scroll-draw.global.js +8 -1
- package/dist/index.cjs +8 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.mjs +8 -1
- package/dist/react/index.cjs +8 -1
- package/dist/react/index.d.mts +9 -1
- package/dist/react/index.d.ts +9 -1
- package/dist/react/index.mjs +8 -1
- package/dist/svelte/index.cjs +8 -0
- package/dist/svelte/index.d.mts +72 -0
- package/dist/svelte/index.d.ts +72 -0
- package/dist/svelte/index.mjs +8 -0
- package/dist/vue/index.cjs +8 -1
- package/dist/vue/index.d.mts +29 -1
- package/dist/vue/index.d.ts +29 -1
- package/dist/vue/index.mjs +8 -1
- package/package.json +54 -5
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# svg-scroll-draw
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/svg-scroll-draw)
|
|
4
|
+
[](https://www.npmjs.com/package/svg-scroll-draw)
|
|
5
|
+
[](https://bundlephobia.com/package/svg-scroll-draw)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://github.com/DhruvilChauahan0210/ink-scroll/stargazers)
|
|
8
|
+
|
|
9
|
+
> Scroll-driven SVG path animation. Zero dependencies. Under 3KB gzipped.
|
|
10
|
+
|
|
11
|
+
**[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)
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm i svg-scroll-draw
|
|
21
|
+
# or
|
|
22
|
+
pnpm add svg-scroll-draw
|
|
23
|
+
# or
|
|
24
|
+
yarn add svg-scroll-draw
|
|
25
|
+
# or
|
|
26
|
+
bun add svg-scroll-draw
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Why this exists
|
|
32
|
+
|
|
33
|
+
The `stroke-dashoffset` trick for drawing SVG lines on scroll is well-known — but every existing tool that implements it is broken in a different way:
|
|
34
|
+
|
|
35
|
+
| Tool | Problem |
|
|
36
|
+
|---|---|
|
|
37
|
+
| **GSAP DrawSVG** | 40KB+, requires a paid Club GreenSock license for commercial use |
|
|
38
|
+
| **Framer Motion** | 35KB+, React-only, heavy runtime for a single animation effect |
|
|
39
|
+
| **scroll-svg** | ~2KB but abandoned — forces you to target individual path IDs manually, crashes in Next.js |
|
|
40
|
+
|
|
41
|
+
`svg-scroll-draw` fixes all three pain points in one package.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
### Vanilla JS
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { scrollDraw } from 'svg-scroll-draw';
|
|
51
|
+
|
|
52
|
+
const instance = scrollDraw('#my-svg-container', {
|
|
53
|
+
easing: 'ease-out',
|
|
54
|
+
speed: 1.2,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Clean up on SPA navigation / unmount
|
|
58
|
+
instance.destroy();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**[Try it on StackBlitz →](https://stackblitz.com/edit/svg-scroll-draw-vanilla)**
|
|
62
|
+
|
|
63
|
+
### React / Next.js
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { ScrollDraw } from 'svg-scroll-draw/react';
|
|
67
|
+
|
|
68
|
+
export default function Hero() {
|
|
69
|
+
return (
|
|
70
|
+
<ScrollDraw speed={1.2} fade easing="ease-out">
|
|
71
|
+
<svg width="500" height="500" viewBox="0 0 500 500">
|
|
72
|
+
<path d="M10 80 C 40 10, 60 10, 95 80" stroke="black" fill="none" />
|
|
73
|
+
</svg>
|
|
74
|
+
</ScrollDraw>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> **Next.js App Router:** add `'use client'` to any component that uses `ScrollDraw`.
|
|
80
|
+
|
|
81
|
+
**[Try it on StackBlitz →](https://stackblitz.com/edit/svg-scroll-draw-react)**
|
|
82
|
+
|
|
83
|
+
### Vue 3
|
|
84
|
+
|
|
85
|
+
```vue
|
|
86
|
+
<script setup>
|
|
87
|
+
import { ScrollDraw } from 'svg-scroll-draw/vue';
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<template>
|
|
91
|
+
<ScrollDraw easing="ease-out" :speed="1.2">
|
|
92
|
+
<svg>...</svg>
|
|
93
|
+
</ScrollDraw>
|
|
94
|
+
</template>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or use the composable directly:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { useScrollDraw } from 'svg-scroll-draw/vue';
|
|
101
|
+
|
|
102
|
+
const containerRef = useScrollDraw({ easing: 'ease-out', speed: 1.2 });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**[Try it on StackBlitz →](https://stackblitz.com/edit/svg-scroll-draw-vue)**
|
|
106
|
+
|
|
107
|
+
### CDN / Web Component
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<script src="https://unpkg.com/svg-scroll-draw/dist/cdn/svg-scroll-draw.global.js"></script>
|
|
111
|
+
|
|
112
|
+
<!-- Web Component (auto-registered) -->
|
|
113
|
+
<scroll-draw easing="ease-out" speed="1.2">
|
|
114
|
+
<svg>...</svg>
|
|
115
|
+
</scroll-draw>
|
|
116
|
+
|
|
117
|
+
<!-- Or vanilla JS API -->
|
|
118
|
+
<script>
|
|
119
|
+
SvgScrollDraw.scrollDraw('#my-container', { easing: 'ease-out' });
|
|
120
|
+
</script>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Options
|
|
126
|
+
|
|
127
|
+
| Option | Type | Default | Description |
|
|
128
|
+
|---|---|---|---|
|
|
129
|
+
| `selector` | `string` | `"path, polyline, line, polygon, rect, circle"` | CSS selector for child elements to animate |
|
|
130
|
+
| `speed` | `number` | `1` | Scale factor — values above 1 complete faster relative to scroll distance |
|
|
131
|
+
| `fade` | `boolean` | `false` | Simultaneously animate `opacity 0 → 1` while drawing |
|
|
132
|
+
| `easing` | `string \| fn` | `"linear"` | `linear`, `ease-in`, `ease-out`, `ease-in-out`, or a custom `(t: number) => number` |
|
|
133
|
+
| `stagger` | `number` | `0` | Normalized offset between each path starting. `0.15` = each path begins 15% of the scroll range after the previous |
|
|
134
|
+
| `direction` | `"forward" \| "reverse"` | `"forward"` | `reverse` starts fully drawn and erases as you scroll |
|
|
135
|
+
| `trigger.start` | `string` | `"top bottom"` | When animation begins. Accepts anchor strings (`"top bottom"`) or viewport percentages (`"20%"`) |
|
|
136
|
+
| `trigger.end` | `string` | `"bottom top"` | When animation ends |
|
|
137
|
+
| `onProgress` | `(alpha: number) => void` | — | Called every animation frame with current draw progress (0–1) |
|
|
138
|
+
| `onComplete` | `() => void` | — | Fires once when all paths reach 100% draw progress |
|
|
139
|
+
|
|
140
|
+
### Trigger anchors
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
scrollDraw('#logo', {
|
|
144
|
+
trigger: {
|
|
145
|
+
start: 'top bottom', // when top of element hits bottom of viewport
|
|
146
|
+
end: 'bottom top', // when bottom of element hits top of viewport
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Or use viewport percentages
|
|
151
|
+
scrollDraw('#logo', {
|
|
152
|
+
trigger: { start: '20%', end: '80%' }
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Available named anchors: `top`, `center`, `bottom`.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Bundle sizes
|
|
161
|
+
|
|
162
|
+
| Format | Size |
|
|
163
|
+
|---|---|
|
|
164
|
+
| ESM (`.mjs`) | ~3.2 KB |
|
|
165
|
+
| CJS (`.cjs`) | ~3.2 KB |
|
|
166
|
+
| IIFE / CDN (`.global.js`) | ~4.2 KB (includes Web Component) |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Browser support
|
|
171
|
+
|
|
172
|
+
Chrome 80+, Safari 14+, Firefox 75+, Edge 80+
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
"use strict";var SvgScrollDraw=(()=>{var
|
|
1
|
+
"use strict";var SvgScrollDraw=(()=>{var I=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var se=(e,t)=>{for(var r in t)I(e,r,{get:t[r],enumerable:!0})},ie=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ne(t))!oe.call(e,i)&&i!==r&&I(e,i,{get:()=>t[i],enumerable:!(o=re(t,i))||o.enumerable});return e};var ae=e=>ie(I({},"__esModule",{value:!0}),e);var fe={};se(fe,{scrollDraw:()=>pe});var M={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 L(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return{element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return{element:o,viewport:i}}function X(e,t,r,o){switch(o){case"top":return e+r;case"center":return e+r+t/2;case"bottom":return e+r+t;default:return e+r}}function B(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case"top":return 0;case"center":return t/2;case"bottom":return t;default:return t}}function F(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ce(e,t,r){return Math.min(r,Math.max(t,e))}function P(e,t,r,o){return r===t?0:ce((e-t)/(r-t)*o,0,1)}function _(e,t,r,o,i){let c=X(e.top,e.height,t,o.element)-B(o.viewport,r),a=X(e.top,e.height,t,i.element)-B(i.viewport,r);return{tStart:c,tEnd:a}}function H(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t)}function le(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?H("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&H("Element has a fill \u2014 it may obscure the stroke animation.",e)}function ue(e,t,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 i(){let a=r==="x"?window.scrollX:window.scrollY,u=e-a,b=t-a,l=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${l?`left:${u}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${u}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${l?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:!0}),i(),o}function S(e,t={}){if(typeof window>"u")return{destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:c=!1,easing:a="linear",trigger:u={},stagger:b=0,direction:l="forward",once:C=!1,debug:W=!1,axis:d="y",onProgress:j,onStart:J,onComplete:G}=t,K=typeof a=="function"?a:M[a]??M.linear,Q=L(u.start??"top bottom"),U=L(u.end??"bottom top"),h=Array.from(e.querySelectorAll(o)),f=[],m=0,g=0,w=!1,D=!1,y=0,A=!1,v=-1,$=null;function k(){return d==="x"?window.scrollX:window.scrollY}function Y(){return d==="x"?window.innerWidth:window.innerHeight}function Z(n){return d==="x"?n.left:n.top}function ee(n){return d==="x"?n.width:n.height}function V(){let n=e.getBoundingClientRect(),s=_({top:Z(n),height:ee(n)},k(),Y(),Q,U);m=s.tStart,g=s.tEnd,W&&process.env.NODE_ENV!=="production"&&($?.remove(),$=ue(m,g,d))}function te(){h.forEach((n,s)=>{n.style.strokeDasharray=`${f[s]}`,n.style.strokeDashoffset=l==="reverse"?"0":`${f[s]}`,c?n.style.opacity=l==="reverse"?"1":"0":n.style.opacity=""})}if(h.forEach(n=>{le(n);let s=F(n);f.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=l==="reverse"?`${s}`:"0",c&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=l==="reverse"?"0":`${s}`,c&&(n.style.opacity=l==="reverse"?"1":"0"))}),r)return G?.(),{destroy:()=>{},replay:()=>{}};V();function N(){if(!A)return;let n=g-m,s=!0;h.forEach((O,x)=>{let q=x*b*n,p=K(P(k(),m+q,g+q,i));C&&(v=Math.max(v,p),p=v),O.style.strokeDashoffset=l==="reverse"?`${f[x]*p}`:`${f[x]*(1-p)}`,c&&(O.style.opacity=l==="reverse"?`${1-p}`:`${p}`),x===0&&j?.(p),p<1&&(s=!1)}),D||P(k(),m,g,i)>0&&(D=!0,J?.()),s&&!w?(w=!0,G?.()):!s&&!C&&(w=!1),y=requestAnimationFrame(N)}let R=new IntersectionObserver(n=>{n.forEach(s=>{A=s.isIntersecting,A?y=requestAnimationFrame(N):cancelAnimationFrame(y)})});R.observe(e);let T;function E(){clearTimeout(T),T=setTimeout(()=>{h.forEach((n,s)=>{f[s]=F(n),n.style.strokeDasharray=`${f[s]}`}),V()},150)}return window.addEventListener("resize",E),window.addEventListener("orientationchange",E),{destroy(){cancelAnimationFrame(y),R.disconnect(),window.removeEventListener("resize",E),window.removeEventListener("orientationchange",E),clearTimeout(T),$?.remove()},replay(){v=-1,D=!1,w=!1,te()}}}function pe(e,t){let r={destroy:()=>{},replay:()=>{}};if(typeof window>"u")return r;let o=typeof e=="string"?document.querySelector(e):e;return o?S(o,t):(console.warn("[svg-scroll-draw] Container not found:",e),r)}var z=class extends HTMLElement{constructor(){super(...arguments);this.instance=null}connectedCallback(){let r={},o=this.getAttribute("speed"),i=this.getAttribute("easing"),c=this.getAttribute("stagger"),a=this.getAttribute("direction"),u=this.getAttribute("selector");o&&(r.speed=parseFloat(o)),i&&(r.easing=i),c&&(r.stagger=parseFloat(c)),a&&(r.direction=a),u&&(r.selector=u),this.hasAttribute("fade")&&(r.fade=this.getAttribute("fade")!=="false"),this.instance=S(this,r)}disconnectedCallback(){this.instance?.destroy(),this.instance=null}};typeof customElements<"u"&&!customElements.get("scroll-draw")&&customElements.define("scroll-draw",z);return ae(fe);})();
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var I={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 M(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function R(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function C(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function L(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function O(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function q(e,t,r,o,i){let u=R(e.top,e.height,t,o.element)-C(o.viewport,r),c=R(e.top,e.height,t,i.element)-C(i.viewport,r);return {tStart:u,tEnd:c}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let c=r==="x"?window.scrollX:window.scrollY,m=e-c,b=t-c,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function B(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:u=false,easing:c="linear",trigger:m={},stagger:b=0,direction:a="forward",once:P=false,debug:_=false,axis:f="y",onProgress:W,onStart:j,onComplete:z}=t,H=typeof c=="function"?c:I[c]??I.linear,J=M(m.start??"top bottom"),K=M(m.end??"bottom top"),w=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,h=false,S=false,y=0,D=false,v=-1,$=null;function A(){return f==="x"?window.scrollX:window.scrollY}function Q(){return f==="x"?window.innerWidth:window.innerHeight}function U(n){return f==="x"?n.left:n.top}function Y(n){return f==="x"?n.width:n.height}function F(){let n=e.getBoundingClientRect(),s=q({top:U(n),height:Y(n)},A(),Q(),J,K);d=s.tStart,g=s.tEnd,_&&process.env.NODE_ENV!=="production"&&($?.remove(),$=re(d,g,f));}function Z(){w.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,u?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(w.forEach(n=>{te(n);let s=L(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return z?.(),{destroy:()=>{},replay:()=>{}};F();function G(){if(!D)return;let n=g-d,s=true;w.forEach((k,E)=>{let N=E*b*n,l=H(O(A(),d+N,g+N,i));P&&(v=Math.max(v,l),l=v),k.style.strokeDashoffset=a==="reverse"?`${p[E]*l}`:`${p[E]*(1-l)}`,u&&(k.style.opacity=a==="reverse"?`${1-l}`:`${l}`),E===0&&W?.(l),l<1&&(s=false);}),S||O(A(),d,g,i)>0&&(S=true,j?.()),s&&!h?(h=true,z?.()):!s&&!P&&(h=false),y=requestAnimationFrame(G);}let V=new IntersectionObserver(n=>{n.forEach(s=>{D=s.isIntersecting,D?y=requestAnimationFrame(G):cancelAnimationFrame(y);});});V.observe(e);let T;function x(){clearTimeout(T),T=setTimeout(()=>{w.forEach((n,s)=>{p[s]=L(n),n.style.strokeDasharray=`${p[s]}`;}),F();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(y),V.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(T),$?.remove();},replay(){v=-1,S=false,h=false,Z();}}}function ae(e,t){let r={destroy:()=>{},replay:()=>{}};if(typeof window>"u")return r;let o=typeof e=="string"?document.querySelector(e):e;return o?B(o,t):(console.warn("[svg-scroll-draw] Container not found:",e),r)}exports.scrollDraw=ae;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
1
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
2
2
|
interface TriggerConfig {
|
|
3
3
|
start?: string;
|
|
4
4
|
end?: string;
|
|
@@ -13,12 +13,22 @@ interface ScrollDrawOptions {
|
|
|
13
13
|
stagger?: number;
|
|
14
14
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
15
15
|
direction?: 'forward' | 'reverse';
|
|
16
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
17
|
+
once?: boolean;
|
|
18
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
21
|
+
axis?: 'x' | 'y';
|
|
16
22
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
17
23
|
onProgress?: (alpha: number) => void;
|
|
24
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
25
|
+
onStart?: () => void;
|
|
18
26
|
onComplete?: () => void;
|
|
19
27
|
}
|
|
20
28
|
interface ScrollDrawInstance {
|
|
21
29
|
destroy: () => void;
|
|
30
|
+
/** Reset and replay the animation from the beginning. */
|
|
31
|
+
replay: () => void;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
declare function scrollDraw(target: string | Element, options?: ScrollDrawOptions): ScrollDrawInstance;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
1
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
2
2
|
interface TriggerConfig {
|
|
3
3
|
start?: string;
|
|
4
4
|
end?: string;
|
|
@@ -13,12 +13,22 @@ interface ScrollDrawOptions {
|
|
|
13
13
|
stagger?: number;
|
|
14
14
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
15
15
|
direction?: 'forward' | 'reverse';
|
|
16
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
17
|
+
once?: boolean;
|
|
18
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
21
|
+
axis?: 'x' | 'y';
|
|
16
22
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
17
23
|
onProgress?: (alpha: number) => void;
|
|
24
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
25
|
+
onStart?: () => void;
|
|
18
26
|
onComplete?: () => void;
|
|
19
27
|
}
|
|
20
28
|
interface ScrollDrawInstance {
|
|
21
29
|
destroy: () => void;
|
|
30
|
+
/** Reset and replay the animation from the beginning. */
|
|
31
|
+
replay: () => void;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
declare function scrollDraw(target: string | Element, options?: ScrollDrawOptions): ScrollDrawInstance;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I={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 M(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function R(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function C(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function L(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function O(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function q(e,t,r,o,i){let u=R(e.top,e.height,t,o.element)-C(o.viewport,r),c=R(e.top,e.height,t,i.element)-C(i.viewport,r);return {tStart:u,tEnd:c}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let c=r==="x"?window.scrollX:window.scrollY,m=e-c,b=t-c,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function B(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:u=false,easing:c="linear",trigger:m={},stagger:b=0,direction:a="forward",once:P=false,debug:_=false,axis:f="y",onProgress:W,onStart:j,onComplete:z}=t,H=typeof c=="function"?c:I[c]??I.linear,J=M(m.start??"top bottom"),K=M(m.end??"bottom top"),w=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,h=false,S=false,y=0,D=false,v=-1,$=null;function A(){return f==="x"?window.scrollX:window.scrollY}function Q(){return f==="x"?window.innerWidth:window.innerHeight}function U(n){return f==="x"?n.left:n.top}function Y(n){return f==="x"?n.width:n.height}function F(){let n=e.getBoundingClientRect(),s=q({top:U(n),height:Y(n)},A(),Q(),J,K);d=s.tStart,g=s.tEnd,_&&process.env.NODE_ENV!=="production"&&($?.remove(),$=re(d,g,f));}function Z(){w.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,u?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(w.forEach(n=>{te(n);let s=L(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return z?.(),{destroy:()=>{},replay:()=>{}};F();function G(){if(!D)return;let n=g-d,s=true;w.forEach((k,E)=>{let N=E*b*n,l=H(O(A(),d+N,g+N,i));P&&(v=Math.max(v,l),l=v),k.style.strokeDashoffset=a==="reverse"?`${p[E]*l}`:`${p[E]*(1-l)}`,u&&(k.style.opacity=a==="reverse"?`${1-l}`:`${l}`),E===0&&W?.(l),l<1&&(s=false);}),S||O(A(),d,g,i)>0&&(S=true,j?.()),s&&!h?(h=true,z?.()):!s&&!P&&(h=false),y=requestAnimationFrame(G);}let V=new IntersectionObserver(n=>{n.forEach(s=>{D=s.isIntersecting,D?y=requestAnimationFrame(G):cancelAnimationFrame(y);});});V.observe(e);let T;function x(){clearTimeout(T),T=setTimeout(()=>{w.forEach((n,s)=>{p[s]=L(n),n.style.strokeDasharray=`${p[s]}`;}),F();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(y),V.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(T),$?.remove();},replay(){v=-1,S=false,h=false,Z();}}}function ae(e,t){let r={destroy:()=>{},replay:()=>{}};if(typeof window>"u")return r;let o=typeof e=="string"?document.querySelector(e):e;return o?B(o,t):(console.warn("[svg-scroll-draw] Container not found:",e),r)}export{ae as scrollDraw};
|
package/dist/react/index.cjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var M={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 L(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function V(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function C(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function P(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function R(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function q(e,t,r,o,i){let c=V(e.top,e.height,t,o.element)-C(o.viewport,r),l=V(e.top,e.height,t,i.element)-C(i.viewport,r);return {tStart:c,tEnd:l}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let l=r==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function B(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:c=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:O=false,debug:_=false,axis:f="y",onProgress:H,onStart:W,onComplete:N}=t,J=typeof l=="function"?l:M[l]??M.linear,K=L(m.start??"top bottom"),Q=L(m.end??"bottom top"),h=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,w=false,S=false,y=0,D=false,v=-1,$=null;function A(){return f==="x"?window.scrollX:window.scrollY}function U(){return f==="x"?window.innerWidth:window.innerHeight}function Y(n){return f==="x"?n.left:n.top}function Z(n){return f==="x"?n.width:n.height}function z(){let n=e.getBoundingClientRect(),s=q({top:Y(n),height:Z(n)},A(),U(),K,Q);d=s.tStart,g=s.tEnd,_&&process.env.NODE_ENV!=="production"&&($?.remove(),$=re(d,g,f));}function j(){h.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,c?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(h.forEach(n=>{te(n);let s=P(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",c&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,c&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return N?.(),{destroy:()=>{},replay:()=>{}};z();function F(){if(!D)return;let n=g-d,s=true;h.forEach((k,x)=>{let G=x*b*n,u=J(R(A(),d+G,g+G,i));O&&(v=Math.max(v,u),u=v),k.style.strokeDashoffset=a==="reverse"?`${p[x]*u}`:`${p[x]*(1-u)}`,c&&(k.style.opacity=a==="reverse"?`${1-u}`:`${u}`),x===0&&H?.(u),u<1&&(s=false);}),S||R(A(),d,g,i)>0&&(S=true,W?.()),s&&!w?(w=true,N?.()):!s&&!O&&(w=false),y=requestAnimationFrame(F);}let I=new IntersectionObserver(n=>{n.forEach(s=>{D=s.isIntersecting,D?y=requestAnimationFrame(F):cancelAnimationFrame(y);});});I.observe(e);let T;function E(){clearTimeout(T),T=setTimeout(()=>{h.forEach((n,s)=>{p[s]=P(n),n.style.strokeDasharray=`${p[s]}`;}),z();},150);}return window.addEventListener("resize",E),window.addEventListener("orientationchange",E),{destroy(){cancelAnimationFrame(y),I.disconnect(),window.removeEventListener("resize",E),window.removeEventListener("orientationchange",E),clearTimeout(T),$?.remove();},replay(){v=-1,S=false,w=false,j();}}}function me({children:e,className:t,style:r,...o}){let i=react.useRef(null);return react.useEffect(()=>{if(!i.current)return;let c=B(i.current,o);return ()=>c.destroy()},[]),jsxRuntime.jsx("div",{ref:i,className:t,style:r,children:e})}exports.ScrollDraw=me;
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -16,8 +16,16 @@ interface ScrollDrawOptions {
|
|
|
16
16
|
stagger?: number;
|
|
17
17
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
18
18
|
direction?: 'forward' | 'reverse';
|
|
19
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
20
|
+
once?: boolean;
|
|
21
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
24
|
+
axis?: 'x' | 'y';
|
|
19
25
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
20
26
|
onProgress?: (alpha: number) => void;
|
|
27
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
28
|
+
onStart?: () => void;
|
|
21
29
|
onComplete?: () => void;
|
|
22
30
|
}
|
|
23
31
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
4
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
5
5
|
interface TriggerConfig {
|
|
6
6
|
start?: string;
|
|
7
7
|
end?: string;
|
|
@@ -16,8 +16,16 @@ interface ScrollDrawOptions {
|
|
|
16
16
|
stagger?: number;
|
|
17
17
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
18
18
|
direction?: 'forward' | 'reverse';
|
|
19
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
20
|
+
once?: boolean;
|
|
21
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
24
|
+
axis?: 'x' | 'y';
|
|
19
25
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
20
26
|
onProgress?: (alpha: number) => void;
|
|
27
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
28
|
+
onStart?: () => void;
|
|
21
29
|
onComplete?: () => void;
|
|
22
30
|
}
|
|
23
31
|
|
package/dist/react/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import {useRef,useEffect}from'react';import {jsx}from'react/jsx-runtime';var
|
|
1
|
+
import {useRef,useEffect}from'react';import {jsx}from'react/jsx-runtime';var M={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 L(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function V(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function C(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function P(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function R(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function q(e,t,r,o,i){let c=V(e.top,e.height,t,o.element)-C(o.viewport,r),l=V(e.top,e.height,t,i.element)-C(i.viewport,r);return {tStart:c,tEnd:l}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let l=r==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function B(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:c=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:O=false,debug:_=false,axis:f="y",onProgress:H,onStart:W,onComplete:N}=t,J=typeof l=="function"?l:M[l]??M.linear,K=L(m.start??"top bottom"),Q=L(m.end??"bottom top"),h=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,w=false,S=false,y=0,D=false,v=-1,$=null;function A(){return f==="x"?window.scrollX:window.scrollY}function U(){return f==="x"?window.innerWidth:window.innerHeight}function Y(n){return f==="x"?n.left:n.top}function Z(n){return f==="x"?n.width:n.height}function z(){let n=e.getBoundingClientRect(),s=q({top:Y(n),height:Z(n)},A(),U(),K,Q);d=s.tStart,g=s.tEnd,_&&process.env.NODE_ENV!=="production"&&($?.remove(),$=re(d,g,f));}function j(){h.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,c?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(h.forEach(n=>{te(n);let s=P(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",c&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,c&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return N?.(),{destroy:()=>{},replay:()=>{}};z();function F(){if(!D)return;let n=g-d,s=true;h.forEach((k,x)=>{let G=x*b*n,u=J(R(A(),d+G,g+G,i));O&&(v=Math.max(v,u),u=v),k.style.strokeDashoffset=a==="reverse"?`${p[x]*u}`:`${p[x]*(1-u)}`,c&&(k.style.opacity=a==="reverse"?`${1-u}`:`${u}`),x===0&&H?.(u),u<1&&(s=false);}),S||R(A(),d,g,i)>0&&(S=true,W?.()),s&&!w?(w=true,N?.()):!s&&!O&&(w=false),y=requestAnimationFrame(F);}let I=new IntersectionObserver(n=>{n.forEach(s=>{D=s.isIntersecting,D?y=requestAnimationFrame(F):cancelAnimationFrame(y);});});I.observe(e);let T;function E(){clearTimeout(T),T=setTimeout(()=>{h.forEach((n,s)=>{p[s]=P(n),n.style.strokeDasharray=`${p[s]}`;}),z();},150);}return window.addEventListener("resize",E),window.addEventListener("orientationchange",E),{destroy(){cancelAnimationFrame(y),I.disconnect(),window.removeEventListener("resize",E),window.removeEventListener("orientationchange",E),clearTimeout(T),$?.remove();},replay(){v=-1,S=false,w=false,j();}}}function me({children:e,className:t,style:r,...o}){let i=useRef(null);return useEffect(()=>{if(!i.current)return;let c=B(i.current,o);return ()=>c.destroy()},[]),jsx("div",{ref:i,className:t,style:r,children:e})}export{me as ScrollDraw};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';var L={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 O(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function C(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function q(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function I(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function P(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function X(e,t,r,o,i){let u=C(e.top,e.height,t,o.element)-q(o.viewport,r),l=C(e.top,e.height,t,i.element)-q(i.viewport,r);return {tStart:u,tEnd:l}}function B(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?B("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&B("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let l=r==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function D(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:u=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:z=false,debug:H=false,axis:f="y",onProgress:_,onStart:W,onComplete:F}=t,j=typeof l=="function"?l:L[l]??L.linear,J=O(m.start??"top bottom"),K=O(m.end??"bottom top"),w=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,h=false,S=false,y=0,$=false,v=-1,A=null;function T(){return f==="x"?window.scrollX:window.scrollY}function Q(){return f==="x"?window.innerWidth:window.innerHeight}function U(n){return f==="x"?n.left:n.top}function Y(n){return f==="x"?n.width:n.height}function G(){let n=e.getBoundingClientRect(),s=X({top:U(n),height:Y(n)},T(),Q(),J,K);d=s.tStart,g=s.tEnd,H&&process.env.NODE_ENV!=="production"&&(A?.remove(),A=re(d,g,f));}function Z(){w.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,u?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(w.forEach(n=>{te(n);let s=I(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return F?.(),{destroy:()=>{},replay:()=>{}};G();function V(){if(!$)return;let n=g-d,s=true;w.forEach((M,E)=>{let R=E*b*n,c=j(P(T(),d+R,g+R,i));z&&(v=Math.max(v,c),c=v),M.style.strokeDashoffset=a==="reverse"?`${p[E]*c}`:`${p[E]*(1-c)}`,u&&(M.style.opacity=a==="reverse"?`${1-c}`:`${c}`),E===0&&_?.(c),c<1&&(s=false);}),S||P(T(),d,g,i)>0&&(S=true,W?.()),s&&!h?(h=true,F?.()):!s&&!z&&(h=false),y=requestAnimationFrame(V);}let N=new IntersectionObserver(n=>{n.forEach(s=>{$=s.isIntersecting,$?y=requestAnimationFrame(V):cancelAnimationFrame(y);});});N.observe(e);let k;function x(){clearTimeout(k),k=setTimeout(()=>{w.forEach((n,s)=>{p[s]=I(n),n.style.strokeDasharray=`${p[s]}`;}),G();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(y),N.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(k),A?.remove();},replay(){v=-1,S=false,h=false,Z();}}}function ae(e,t={}){let r=D(e,t);return {update(o){r.destroy(),r=D(e,o);},destroy(){r.destroy();}}}function le(e={}){let t=null;function r(o){return t=D(o,e),{destroy(){t?.destroy(),t=null;}}}return {action:r,getInstance:()=>t}}exports.createScrollDraw=le;exports.scrollDraw=ae;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
2
|
+
interface TriggerConfig {
|
|
3
|
+
start?: string;
|
|
4
|
+
end?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ScrollDrawOptions {
|
|
7
|
+
selector?: string;
|
|
8
|
+
speed?: number;
|
|
9
|
+
fade?: boolean;
|
|
10
|
+
easing?: EasingName | ((t: number) => number);
|
|
11
|
+
trigger?: TriggerConfig;
|
|
12
|
+
/** Normalized scroll-progress offset between each path starting (0–1). e.g. 0.15 → each path begins 15% of the scroll range after the previous. */
|
|
13
|
+
stagger?: number;
|
|
14
|
+
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
15
|
+
direction?: 'forward' | 'reverse';
|
|
16
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
17
|
+
once?: boolean;
|
|
18
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
21
|
+
axis?: 'x' | 'y';
|
|
22
|
+
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
23
|
+
onProgress?: (alpha: number) => void;
|
|
24
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
25
|
+
onStart?: () => void;
|
|
26
|
+
onComplete?: () => void;
|
|
27
|
+
}
|
|
28
|
+
interface ScrollDrawInstance {
|
|
29
|
+
destroy: () => void;
|
|
30
|
+
/** Reset and replay the animation from the beginning. */
|
|
31
|
+
replay: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Svelte action — apply to any container element wrapping an SVG.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* <script>
|
|
39
|
+
* import { scrollDraw } from 'svg-scroll-draw/svelte';
|
|
40
|
+
* </script>
|
|
41
|
+
*
|
|
42
|
+
* <div use:scrollDraw={{ easing: 'ease-out', speed: 1.2, fade: true }}>
|
|
43
|
+
* <svg>...</svg>
|
|
44
|
+
* </div>
|
|
45
|
+
*/
|
|
46
|
+
declare function scrollDraw(node: HTMLElement, options?: ScrollDrawOptions): {
|
|
47
|
+
update(newOptions: ScrollDrawOptions): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Composable helper — returns an action and the live instance so you can
|
|
52
|
+
* call `instance.replay()` from your Svelte component logic.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* <script>
|
|
56
|
+
* import { createScrollDraw } from 'svg-scroll-draw/svelte';
|
|
57
|
+
* const { action, getInstance } = createScrollDraw({ easing: 'spring' });
|
|
58
|
+
* </script>
|
|
59
|
+
*
|
|
60
|
+
* <div use:action>
|
|
61
|
+
* <svg>...</svg>
|
|
62
|
+
* </div>
|
|
63
|
+
* <button on:click={() => getInstance()?.replay()}>Replay</button>
|
|
64
|
+
*/
|
|
65
|
+
declare function createScrollDraw(options?: ScrollDrawOptions): {
|
|
66
|
+
action: (node: HTMLElement) => {
|
|
67
|
+
destroy(): void;
|
|
68
|
+
};
|
|
69
|
+
getInstance: () => ScrollDrawInstance | null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { type ScrollDrawOptions, createScrollDraw, scrollDraw };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
2
|
+
interface TriggerConfig {
|
|
3
|
+
start?: string;
|
|
4
|
+
end?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ScrollDrawOptions {
|
|
7
|
+
selector?: string;
|
|
8
|
+
speed?: number;
|
|
9
|
+
fade?: boolean;
|
|
10
|
+
easing?: EasingName | ((t: number) => number);
|
|
11
|
+
trigger?: TriggerConfig;
|
|
12
|
+
/** Normalized scroll-progress offset between each path starting (0–1). e.g. 0.15 → each path begins 15% of the scroll range after the previous. */
|
|
13
|
+
stagger?: number;
|
|
14
|
+
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
15
|
+
direction?: 'forward' | 'reverse';
|
|
16
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
17
|
+
once?: boolean;
|
|
18
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
21
|
+
axis?: 'x' | 'y';
|
|
22
|
+
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
23
|
+
onProgress?: (alpha: number) => void;
|
|
24
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
25
|
+
onStart?: () => void;
|
|
26
|
+
onComplete?: () => void;
|
|
27
|
+
}
|
|
28
|
+
interface ScrollDrawInstance {
|
|
29
|
+
destroy: () => void;
|
|
30
|
+
/** Reset and replay the animation from the beginning. */
|
|
31
|
+
replay: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Svelte action — apply to any container element wrapping an SVG.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* <script>
|
|
39
|
+
* import { scrollDraw } from 'svg-scroll-draw/svelte';
|
|
40
|
+
* </script>
|
|
41
|
+
*
|
|
42
|
+
* <div use:scrollDraw={{ easing: 'ease-out', speed: 1.2, fade: true }}>
|
|
43
|
+
* <svg>...</svg>
|
|
44
|
+
* </div>
|
|
45
|
+
*/
|
|
46
|
+
declare function scrollDraw(node: HTMLElement, options?: ScrollDrawOptions): {
|
|
47
|
+
update(newOptions: ScrollDrawOptions): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Composable helper — returns an action and the live instance so you can
|
|
52
|
+
* call `instance.replay()` from your Svelte component logic.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* <script>
|
|
56
|
+
* import { createScrollDraw } from 'svg-scroll-draw/svelte';
|
|
57
|
+
* const { action, getInstance } = createScrollDraw({ easing: 'spring' });
|
|
58
|
+
* </script>
|
|
59
|
+
*
|
|
60
|
+
* <div use:action>
|
|
61
|
+
* <svg>...</svg>
|
|
62
|
+
* </div>
|
|
63
|
+
* <button on:click={() => getInstance()?.replay()}>Replay</button>
|
|
64
|
+
*/
|
|
65
|
+
declare function createScrollDraw(options?: ScrollDrawOptions): {
|
|
66
|
+
action: (node: HTMLElement) => {
|
|
67
|
+
destroy(): void;
|
|
68
|
+
};
|
|
69
|
+
getInstance: () => ScrollDrawInstance | null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { type ScrollDrawOptions, createScrollDraw, scrollDraw };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var L={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 O(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let r=t.split(/\s+/).filter(Boolean),[o="top",i="bottom"]=r;return {element:o,viewport:i}}function C(e,t,r,o){switch(o){case "top":return e+r;case "center":return e+r+t/2;case "bottom":return e+r+t;default:return e+r}}function q(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function I(e){let t=e.tagName.toLowerCase();if(t==="rect"){let r=parseFloat(e.getAttribute("width")??"0"),o=parseFloat(e.getAttribute("height")??"0");return 2*(r+o)}if(t==="circle"){let r=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*r}return e.getTotalLength()}function ee(e,t,r){return Math.min(r,Math.max(t,e))}function P(e,t,r,o){return r===t?0:ee((e-t)/(r-t)*o,0,1)}function X(e,t,r,o,i){let u=C(e.top,e.height,t,o.element)-q(o.viewport,r),l=C(e.top,e.height,t,i.element)-q(i.viewport,r);return {tStart:u,tEnd:l}}function B(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function te(e){let t=e.getAttribute("stroke"),r=e.getAttribute("fill");!t||t==="none"?B("Element has no stroke \u2014 path will not be visible.",e):r&&r!=="none"&&r!=="transparent"&&B("Element has a fill \u2014 it may obscure the stroke animation.",e);}function re(e,t,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 i(){let l=r==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=r==="x";o.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(o),window.addEventListener("scroll",i,{passive:true}),i(),o}function D(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let r=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:o="path, polyline, line, polygon, rect, circle",speed:i=1,fade:u=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:z=false,debug:H=false,axis:f="y",onProgress:_,onStart:W,onComplete:F}=t,j=typeof l=="function"?l:L[l]??L.linear,J=O(m.start??"top bottom"),K=O(m.end??"bottom top"),w=Array.from(e.querySelectorAll(o)),p=[],d=0,g=0,h=false,S=false,y=0,$=false,v=-1,A=null;function T(){return f==="x"?window.scrollX:window.scrollY}function Q(){return f==="x"?window.innerWidth:window.innerHeight}function U(n){return f==="x"?n.left:n.top}function Y(n){return f==="x"?n.width:n.height}function G(){let n=e.getBoundingClientRect(),s=X({top:U(n),height:Y(n)},T(),Q(),J,K);d=s.tStart,g=s.tEnd,H&&process.env.NODE_ENV!=="production"&&(A?.remove(),A=re(d,g,f));}function Z(){w.forEach((n,s)=>{n.style.strokeDasharray=`${p[s]}`,n.style.strokeDashoffset=a==="reverse"?"0":`${p[s]}`,u?n.style.opacity=a==="reverse"?"1":"0":n.style.opacity="";});}if(w.forEach(n=>{te(n);let s=I(n);p.push(s),r?(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?`${s}`:"0",u&&(n.style.opacity="1")):(n.style.strokeDasharray=`${s}`,n.style.strokeDashoffset=a==="reverse"?"0":`${s}`,u&&(n.style.opacity=a==="reverse"?"1":"0"));}),r)return F?.(),{destroy:()=>{},replay:()=>{}};G();function V(){if(!$)return;let n=g-d,s=true;w.forEach((M,E)=>{let R=E*b*n,c=j(P(T(),d+R,g+R,i));z&&(v=Math.max(v,c),c=v),M.style.strokeDashoffset=a==="reverse"?`${p[E]*c}`:`${p[E]*(1-c)}`,u&&(M.style.opacity=a==="reverse"?`${1-c}`:`${c}`),E===0&&_?.(c),c<1&&(s=false);}),S||P(T(),d,g,i)>0&&(S=true,W?.()),s&&!h?(h=true,F?.()):!s&&!z&&(h=false),y=requestAnimationFrame(V);}let N=new IntersectionObserver(n=>{n.forEach(s=>{$=s.isIntersecting,$?y=requestAnimationFrame(V):cancelAnimationFrame(y);});});N.observe(e);let k;function x(){clearTimeout(k),k=setTimeout(()=>{w.forEach((n,s)=>{p[s]=I(n),n.style.strokeDasharray=`${p[s]}`;}),G();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(y),N.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(k),A?.remove();},replay(){v=-1,S=false,h=false,Z();}}}function ae(e,t={}){let r=D(e,t);return {update(o){r.destroy(),r=D(e,o);},destroy(){r.destroy();}}}function le(e={}){let t=null;function r(o){return t=D(o,e),{destroy(){t?.destroy(),t=null;}}}return {action:r,getInstance:()=>t}}export{le as createScrollDraw,ae as scrollDraw};
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
'use strict';var vue=require('vue');var
|
|
1
|
+
'use strict';var vue=require('vue');var M={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 k(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let n=t.split(/\s+/).filter(Boolean),[r="top",s="bottom"]=n;return {element:r,viewport:s}}function V(e,t,n,r){switch(r){case "top":return e+n;case "center":return e+n+t/2;case "bottom":return e+n+t;default:return e+n}}function B(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function P(e){let t=e.tagName.toLowerCase();if(t==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),r=parseFloat(e.getAttribute("height")??"0");return 2*(n+r)}if(t==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function re(e,t,n){return Math.min(n,Math.max(t,e))}function L(e,t,n,r){return n===t?0:re((e-t)/(n-t)*r,0,1)}function q(e,t,n,r,s){let u=V(e.top,e.height,t,r.element)-B(r.viewport,n),l=V(e.top,e.height,t,s.element)-B(s.viewport,n);return {tStart:u,tEnd:l}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function oe(e){let t=e.getAttribute("stroke"),n=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function ie(e,t,n){let r=document.createElement("div");r.setAttribute("data-svg-scroll-draw-debug",""),r.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 s(){let l=n==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=n==="x";r.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(r),window.addEventListener("scroll",s,{passive:true}),s(),r}function F(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:r="path, polyline, line, polygon, rect, circle",speed:s=1,fade:u=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:C=false,debug:U=false,axis:d="y",onProgress:W,onStart:J,onComplete:z}=t,K=typeof l=="function"?l:M[l]??M.linear,Q=k(m.start??"top bottom"),Y=k(m.end??"bottom top"),w=Array.from(e.querySelectorAll(r)),f=[],p=0,g=0,y=false,E=false,h=0,D=false,v=-1,$=null;function A(){return d==="x"?window.scrollX:window.scrollY}function Z(){return d==="x"?window.innerWidth:window.innerHeight}function ee(o){return d==="x"?o.left:o.top}function te(o){return d==="x"?o.width:o.height}function I(){let o=e.getBoundingClientRect(),i=q({top:ee(o),height:te(o)},A(),Z(),Q,Y);p=i.tStart,g=i.tEnd,U&&process.env.NODE_ENV!=="production"&&($?.remove(),$=ie(p,g,d));}function ne(){w.forEach((o,i)=>{o.style.strokeDasharray=`${f[i]}`,o.style.strokeDashoffset=a==="reverse"?"0":`${f[i]}`,u?o.style.opacity=a==="reverse"?"1":"0":o.style.opacity="";});}if(w.forEach(o=>{oe(o);let i=P(o);f.push(i),n?(o.style.strokeDasharray=`${i}`,o.style.strokeDashoffset=a==="reverse"?`${i}`:"0",u&&(o.style.opacity="1")):(o.style.strokeDasharray=`${i}`,o.style.strokeDashoffset=a==="reverse"?"0":`${i}`,u&&(o.style.opacity=a==="reverse"?"1":"0"));}),n)return z?.(),{destroy:()=>{},replay:()=>{}};I();function N(){if(!D)return;let o=g-p,i=true;w.forEach((T,S)=>{let G=S*b*o,c=K(L(A(),p+G,g+G,s));C&&(v=Math.max(v,c),c=v),T.style.strokeDashoffset=a==="reverse"?`${f[S]*c}`:`${f[S]*(1-c)}`,u&&(T.style.opacity=a==="reverse"?`${1-c}`:`${c}`),S===0&&W?.(c),c<1&&(i=false);}),E||L(A(),p,g,s)>0&&(E=true,J?.()),i&&!y?(y=true,z?.()):!i&&!C&&(y=false),h=requestAnimationFrame(N);}let R=new IntersectionObserver(o=>{o.forEach(i=>{D=i.isIntersecting,D?h=requestAnimationFrame(N):cancelAnimationFrame(h);});});R.observe(e);let O;function x(){clearTimeout(O),O=setTimeout(()=>{w.forEach((o,i)=>{f[i]=P(o),o.style.strokeDasharray=`${f[i]}`;}),I();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(h),R.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(O),$?.remove();},replay(){v=-1,E=false,y=false,ne();}}}function de(e={}){let t=vue.ref(null);return vue.onMounted(()=>{if(!t.value)return;let n=F(t.value,e);vue.onUnmounted(()=>n.destroy());}),t}var pe=vue.defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:t}){let n=vue.ref(null);return vue.onMounted(()=>{if(!n.value)return;let r={};e.selector!=null&&(r.selector=e.selector),e.speed!=null&&(r.speed=e.speed),e.fade!=null&&(r.fade=e.fade),e.stagger!=null&&(r.stagger=e.stagger),e.easing!=null&&(r.easing=e.easing),e.direction!=null&&(r.direction=e.direction),e.trigger!=null&&(r.trigger=e.trigger),e.once!=null&&(r.once=e.once),e.debug!=null&&(r.debug=e.debug),e.onProgress!=null&&(r.onProgress=e.onProgress),e.onStart!=null&&(r.onStart=e.onStart),e.onComplete!=null&&(r.onComplete=e.onComplete);let s=F(n.value,r);vue.onUnmounted(()=>s.destroy());}),()=>vue.h("div",{ref:n},t.default?.())}});exports.ScrollDraw=pe;exports.useScrollDraw=de;
|
package/dist/vue/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
|
|
3
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
3
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
4
|
interface TriggerConfig {
|
|
5
5
|
start?: string;
|
|
6
6
|
end?: string;
|
|
@@ -15,8 +15,16 @@ interface ScrollDrawOptions {
|
|
|
15
15
|
stagger?: number;
|
|
16
16
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
17
17
|
direction?: 'forward' | 'reverse';
|
|
18
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
19
|
+
once?: boolean;
|
|
20
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
23
|
+
axis?: 'x' | 'y';
|
|
18
24
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
19
25
|
onProgress?: (alpha: number) => void;
|
|
26
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
27
|
+
onStart?: () => void;
|
|
20
28
|
onComplete?: () => void;
|
|
21
29
|
}
|
|
22
30
|
|
|
@@ -48,9 +56,18 @@ declare const ScrollDraw: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
48
56
|
onProgress: {
|
|
49
57
|
type: FunctionConstructor;
|
|
50
58
|
};
|
|
59
|
+
onStart: {
|
|
60
|
+
type: FunctionConstructor;
|
|
61
|
+
};
|
|
51
62
|
onComplete: {
|
|
52
63
|
type: FunctionConstructor;
|
|
53
64
|
};
|
|
65
|
+
once: {
|
|
66
|
+
type: BooleanConstructor;
|
|
67
|
+
};
|
|
68
|
+
debug: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
};
|
|
54
71
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
55
72
|
[key: string]: any;
|
|
56
73
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -78,11 +95,22 @@ declare const ScrollDraw: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
78
95
|
onProgress: {
|
|
79
96
|
type: FunctionConstructor;
|
|
80
97
|
};
|
|
98
|
+
onStart: {
|
|
99
|
+
type: FunctionConstructor;
|
|
100
|
+
};
|
|
81
101
|
onComplete: {
|
|
82
102
|
type: FunctionConstructor;
|
|
83
103
|
};
|
|
104
|
+
once: {
|
|
105
|
+
type: BooleanConstructor;
|
|
106
|
+
};
|
|
107
|
+
debug: {
|
|
108
|
+
type: BooleanConstructor;
|
|
109
|
+
};
|
|
84
110
|
}>> & Readonly<{}>, {
|
|
85
111
|
fade: boolean;
|
|
112
|
+
once: boolean;
|
|
113
|
+
debug: boolean;
|
|
86
114
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
87
115
|
|
|
88
116
|
export { ScrollDraw, type ScrollDrawOptions, useScrollDraw };
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
|
|
3
|
-
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
3
|
+
type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
|
|
4
4
|
interface TriggerConfig {
|
|
5
5
|
start?: string;
|
|
6
6
|
end?: string;
|
|
@@ -15,8 +15,16 @@ interface ScrollDrawOptions {
|
|
|
15
15
|
stagger?: number;
|
|
16
16
|
/** 'forward' draws the path in (default). 'reverse' erases — path starts fully drawn and disappears as you scroll. */
|
|
17
17
|
direction?: 'forward' | 'reverse';
|
|
18
|
+
/** Draw once and stay drawn — animation does not reverse when scrolling back up. */
|
|
19
|
+
once?: boolean;
|
|
20
|
+
/** Show trigger zone overlay for debugging. Dev-only — stripped in production. */
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
/** Scroll axis to track. 'y' (default) for vertical scroll, 'x' for horizontal scroll containers. */
|
|
23
|
+
axis?: 'x' | 'y';
|
|
18
24
|
/** Called every animation frame with the current draw progress (0–1) of the first path. */
|
|
19
25
|
onProgress?: (alpha: number) => void;
|
|
26
|
+
/** Fires once on the first frame the animation begins drawing. */
|
|
27
|
+
onStart?: () => void;
|
|
20
28
|
onComplete?: () => void;
|
|
21
29
|
}
|
|
22
30
|
|
|
@@ -48,9 +56,18 @@ declare const ScrollDraw: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
48
56
|
onProgress: {
|
|
49
57
|
type: FunctionConstructor;
|
|
50
58
|
};
|
|
59
|
+
onStart: {
|
|
60
|
+
type: FunctionConstructor;
|
|
61
|
+
};
|
|
51
62
|
onComplete: {
|
|
52
63
|
type: FunctionConstructor;
|
|
53
64
|
};
|
|
65
|
+
once: {
|
|
66
|
+
type: BooleanConstructor;
|
|
67
|
+
};
|
|
68
|
+
debug: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
};
|
|
54
71
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
55
72
|
[key: string]: any;
|
|
56
73
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -78,11 +95,22 @@ declare const ScrollDraw: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
78
95
|
onProgress: {
|
|
79
96
|
type: FunctionConstructor;
|
|
80
97
|
};
|
|
98
|
+
onStart: {
|
|
99
|
+
type: FunctionConstructor;
|
|
100
|
+
};
|
|
81
101
|
onComplete: {
|
|
82
102
|
type: FunctionConstructor;
|
|
83
103
|
};
|
|
104
|
+
once: {
|
|
105
|
+
type: BooleanConstructor;
|
|
106
|
+
};
|
|
107
|
+
debug: {
|
|
108
|
+
type: BooleanConstructor;
|
|
109
|
+
};
|
|
84
110
|
}>> & Readonly<{}>, {
|
|
85
111
|
fade: boolean;
|
|
112
|
+
once: boolean;
|
|
113
|
+
debug: boolean;
|
|
86
114
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
87
115
|
|
|
88
116
|
export { ScrollDraw, type ScrollDrawOptions, useScrollDraw };
|
package/dist/vue/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import {defineComponent,ref,onMounted,onUnmounted,h}from'vue';var
|
|
1
|
+
import {defineComponent,ref,onMounted,onUnmounted,h}from'vue';var M={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 k(e="top bottom"){let t=e.trim();if(/^\d+(\.\d+)?%$/.test(t))return {element:"top",viewport:t};let n=t.split(/\s+/).filter(Boolean),[r="top",s="bottom"]=n;return {element:r,viewport:s}}function V(e,t,n,r){switch(r){case "top":return e+n;case "center":return e+n+t/2;case "bottom":return e+n+t;default:return e+n}}function B(e,t){if(/^\d+(\.\d+)?%$/.test(e))return t*(parseFloat(e)/100);switch(e){case "top":return 0;case "center":return t/2;case "bottom":return t;default:return t}}function P(e){let t=e.tagName.toLowerCase();if(t==="rect"){let n=parseFloat(e.getAttribute("width")??"0"),r=parseFloat(e.getAttribute("height")??"0");return 2*(n+r)}if(t==="circle"){let n=parseFloat(e.getAttribute("r")??"0");return 2*Math.PI*n}return e.getTotalLength()}function re(e,t,n){return Math.min(n,Math.max(t,e))}function L(e,t,n,r){return n===t?0:re((e-t)/(n-t)*r,0,1)}function q(e,t,n,r,s){let u=V(e.top,e.height,t,r.element)-B(r.viewport,n),l=V(e.top,e.height,t,s.element)-B(s.viewport,n);return {tStart:u,tEnd:l}}function X(e,t){process.env.NODE_ENV!=="production"&&console.warn(`[svg-scroll-draw] ${e}`,t);}function oe(e){let t=e.getAttribute("stroke"),n=e.getAttribute("fill");!t||t==="none"?X("Element has no stroke \u2014 path will not be visible.",e):n&&n!=="none"&&n!=="transparent"&&X("Element has a fill \u2014 it may obscure the stroke animation.",e);}function ie(e,t,n){let r=document.createElement("div");r.setAttribute("data-svg-scroll-draw-debug",""),r.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 s(){let l=n==="x"?window.scrollX:window.scrollY,m=e-l,b=t-l,a=n==="x";r.innerHTML=`
|
|
2
|
+
<div style="position:absolute;
|
|
3
|
+
${a?`left:${m}px;top:0;bottom:0;border-left:2px dashed #22c55e;`:`top:${m}px;left:0;right:0;border-top:2px dashed #22c55e;`}
|
|
4
|
+
padding:2px 6px;color:#22c55e;background:rgba(0,0,0,0.6);">\u25B6 start</div>
|
|
5
|
+
<div style="position:absolute;
|
|
6
|
+
${a?`left:${b}px;top:0;bottom:0;border-left:2px dashed #ef4444;`:`top:${b}px;left:0;right:0;border-top:2px dashed #ef4444;`}
|
|
7
|
+
padding:2px 6px;color:#ef4444;background:rgba(0,0,0,0.6);">\u25A0 end</div>
|
|
8
|
+
`;}return document.body.appendChild(r),window.addEventListener("scroll",s,{passive:true}),s(),r}function F(e,t={}){if(typeof window>"u")return {destroy:()=>{},replay:()=>{}};let n=window.matchMedia("(prefers-reduced-motion: reduce)").matches,{selector:r="path, polyline, line, polygon, rect, circle",speed:s=1,fade:u=false,easing:l="linear",trigger:m={},stagger:b=0,direction:a="forward",once:C=false,debug:U=false,axis:d="y",onProgress:W,onStart:J,onComplete:z}=t,K=typeof l=="function"?l:M[l]??M.linear,Q=k(m.start??"top bottom"),Y=k(m.end??"bottom top"),w=Array.from(e.querySelectorAll(r)),f=[],p=0,g=0,y=false,E=false,h=0,D=false,v=-1,$=null;function A(){return d==="x"?window.scrollX:window.scrollY}function Z(){return d==="x"?window.innerWidth:window.innerHeight}function ee(o){return d==="x"?o.left:o.top}function te(o){return d==="x"?o.width:o.height}function I(){let o=e.getBoundingClientRect(),i=q({top:ee(o),height:te(o)},A(),Z(),Q,Y);p=i.tStart,g=i.tEnd,U&&process.env.NODE_ENV!=="production"&&($?.remove(),$=ie(p,g,d));}function ne(){w.forEach((o,i)=>{o.style.strokeDasharray=`${f[i]}`,o.style.strokeDashoffset=a==="reverse"?"0":`${f[i]}`,u?o.style.opacity=a==="reverse"?"1":"0":o.style.opacity="";});}if(w.forEach(o=>{oe(o);let i=P(o);f.push(i),n?(o.style.strokeDasharray=`${i}`,o.style.strokeDashoffset=a==="reverse"?`${i}`:"0",u&&(o.style.opacity="1")):(o.style.strokeDasharray=`${i}`,o.style.strokeDashoffset=a==="reverse"?"0":`${i}`,u&&(o.style.opacity=a==="reverse"?"1":"0"));}),n)return z?.(),{destroy:()=>{},replay:()=>{}};I();function N(){if(!D)return;let o=g-p,i=true;w.forEach((T,S)=>{let G=S*b*o,c=K(L(A(),p+G,g+G,s));C&&(v=Math.max(v,c),c=v),T.style.strokeDashoffset=a==="reverse"?`${f[S]*c}`:`${f[S]*(1-c)}`,u&&(T.style.opacity=a==="reverse"?`${1-c}`:`${c}`),S===0&&W?.(c),c<1&&(i=false);}),E||L(A(),p,g,s)>0&&(E=true,J?.()),i&&!y?(y=true,z?.()):!i&&!C&&(y=false),h=requestAnimationFrame(N);}let R=new IntersectionObserver(o=>{o.forEach(i=>{D=i.isIntersecting,D?h=requestAnimationFrame(N):cancelAnimationFrame(h);});});R.observe(e);let O;function x(){clearTimeout(O),O=setTimeout(()=>{w.forEach((o,i)=>{f[i]=P(o),o.style.strokeDasharray=`${f[i]}`;}),I();},150);}return window.addEventListener("resize",x),window.addEventListener("orientationchange",x),{destroy(){cancelAnimationFrame(h),R.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("orientationchange",x),clearTimeout(O),$?.remove();},replay(){v=-1,E=false,y=false,ne();}}}function de(e={}){let t=ref(null);return onMounted(()=>{if(!t.value)return;let n=F(t.value,e);onUnmounted(()=>n.destroy());}),t}var pe=defineComponent({name:"ScrollDraw",props:{selector:{type:String},speed:{type:Number},fade:{type:Boolean},stagger:{type:Number},easing:{type:[String,Function]},direction:{type:String},trigger:{type:Object},onProgress:{type:Function},onStart:{type:Function},onComplete:{type:Function},once:{type:Boolean},debug:{type:Boolean}},setup(e,{slots:t}){let n=ref(null);return onMounted(()=>{if(!n.value)return;let r={};e.selector!=null&&(r.selector=e.selector),e.speed!=null&&(r.speed=e.speed),e.fade!=null&&(r.fade=e.fade),e.stagger!=null&&(r.stagger=e.stagger),e.easing!=null&&(r.easing=e.easing),e.direction!=null&&(r.direction=e.direction),e.trigger!=null&&(r.trigger=e.trigger),e.once!=null&&(r.once=e.once),e.debug!=null&&(r.debug=e.debug),e.onProgress!=null&&(r.onProgress=e.onProgress),e.onStart!=null&&(r.onStart=e.onStart),e.onComplete!=null&&(r.onComplete=e.onComplete);let s=F(n.value,r);onUnmounted(()=>s.destroy());}),()=>h("div",{ref:n},t.default?.())}});export{pe as ScrollDraw,de as useScrollDraw};
|
package/package.json
CHANGED
|
@@ -1,12 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svg-scroll-draw",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Scroll-driven SVG path drawing animation library",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Scroll-driven SVG path drawing animation library — zero dependencies, under 3KB gzipped, works with React, Vue, and vanilla JS",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"svg",
|
|
7
|
+
"scroll",
|
|
8
|
+
"animation",
|
|
9
|
+
"path",
|
|
10
|
+
"draw",
|
|
11
|
+
"stroke-dashoffset",
|
|
12
|
+
"scroll-driven",
|
|
13
|
+
"intersection-observer",
|
|
14
|
+
"react",
|
|
15
|
+
"vue",
|
|
16
|
+
"nextjs",
|
|
17
|
+
"web-animation",
|
|
18
|
+
"svg-animation",
|
|
19
|
+
"scroll-animation",
|
|
20
|
+
"path-drawing",
|
|
21
|
+
"vanilla-js",
|
|
22
|
+
"web-component",
|
|
23
|
+
"zero-dependencies",
|
|
24
|
+
"lightweight",
|
|
25
|
+
"svelte",
|
|
26
|
+
"svelte-action",
|
|
27
|
+
"horizontal-scroll"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://ink-scroll.vercel.app",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/DhruvilChauahan0210/ink-scroll.git",
|
|
33
|
+
"directory": "packages/svg-scroll-draw"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/DhruvilChauahan0210/ink-scroll/issues"
|
|
37
|
+
},
|
|
38
|
+
"funding": {
|
|
39
|
+
"type": "github",
|
|
40
|
+
"url": "https://github.com/sponsors/DhruvilChauahan0210"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
5
43
|
"main": "./dist/index.cjs",
|
|
6
44
|
"module": "./dist/index.mjs",
|
|
7
45
|
"types": "./dist/index.d.ts",
|
|
8
46
|
"files": [
|
|
9
|
-
"dist"
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
10
50
|
],
|
|
11
51
|
"exports": {
|
|
12
52
|
".": {
|
|
@@ -23,6 +63,11 @@
|
|
|
23
63
|
"types": "./dist/vue/index.d.ts",
|
|
24
64
|
"import": "./dist/vue/index.mjs",
|
|
25
65
|
"require": "./dist/vue/index.cjs"
|
|
66
|
+
},
|
|
67
|
+
"./svelte": {
|
|
68
|
+
"types": "./dist/svelte/index.d.ts",
|
|
69
|
+
"import": "./dist/svelte/index.mjs",
|
|
70
|
+
"require": "./dist/svelte/index.cjs"
|
|
26
71
|
}
|
|
27
72
|
},
|
|
28
73
|
"scripts": {
|
|
@@ -47,7 +92,11 @@
|
|
|
47
92
|
"vue": ">=3"
|
|
48
93
|
},
|
|
49
94
|
"peerDependenciesMeta": {
|
|
50
|
-
"react": {
|
|
51
|
-
|
|
95
|
+
"react": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"vue": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
52
101
|
}
|
|
53
102
|
}
|