svg-scroll-draw 2.19.1 → 2.20.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 +1 -1
- package/dist/pin/index.cjs +1 -1
- package/dist/pin/index.d.mts +8 -2
- package/dist/pin/index.d.ts +8 -2
- package/dist/pin/index.mjs +1 -1
- package/dist/react/index.d.mts +4 -5
- package/dist/react/index.d.ts +4 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -640,7 +640,7 @@ devtools.highlight('#my-element'); // outline for 2 seconds
|
|
|
640
640
|
| `svg-scroll-draw/aos` (styles included) | 3.1 KB |
|
|
641
641
|
| `svg-scroll-draw/snap` | 1.9 KB |
|
|
642
642
|
| `svg-scroll-draw/devtools` | 1.8 KB (dev only) |
|
|
643
|
-
| `svg-scroll-draw/pin` | 1.
|
|
643
|
+
| `svg-scroll-draw/pin` | 1.6 KB |
|
|
644
644
|
<!-- size-table:end -->
|
|
645
645
|
|
|
646
646
|
Measured with `npm run size`: each entry plus the shared chunks it imports, minified, gzip level 9. Entries share their code through those chunks, so importing several costs less than the sum. For comparison, GSAP 3.15.0 core + ScrollTrigger is 45.3 KB gzipped, and 47.5 KB with DrawSVG. GSAP does far more than scroll animation; for the scroll effects this library covers, that is the size difference.
|
package/dist/pin/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function
|
|
1
|
+
'use strict';function z(t,s,a){return Math.min(a,Math.max(s,t))}var D=Symbol.for("svg-scroll-draw.registry");function O(){let t=globalThis;return t[D]||(t[D]=new Map)}function B(t,s){O().set(t,s);}function C(t){O().delete(t);}var F=typeof __SVG_SCROLL_DRAW_DEV__<"u"?__SVG_SCROLL_DRAW_DEV__:typeof process<"u"&&typeof process.env<"u"&&process.env.NODE_ENV!=="production";function S(t,...s){F&&console.warn(`[svg-scroll-draw] ${t}`,...s);}var V={destroy:()=>{},refresh:()=>{},getProgress:()=>0};function Q(t,s={}){if(typeof window>"u")return V;let a=typeof t=="string"?document.querySelector(t):t;if(!a)return S("scrollPin: element not found:",t),V;let e=a,{top:f=0,scrollContainer:g,onEnter:$,onLeave:H,onEnterBack:I,onLeaveBack:M,onProgress:k}=s,A=typeof g=="string"?document.querySelector(g):g??null,i={position:e.style.position,top:e.style.top,bottom:e.style.bottom,left:e.style.left,width:e.style.width,boxSizing:e.style.boxSizing},n=document.createElement("div");n.setAttribute("data-ssd-pin-wrapper",""),n.style.cssText="position:relative;",e.parentNode?.insertBefore(n,e),n.appendChild(e);let b=0,v=0,w=0,u="before",h=0,R=0,E=false,P=false;function N(){let o=s.pinDistance;if(o===void 0)return window.innerHeight;if(typeof o=="number")return o;let r=parseFloat(o),d=o.trim().slice(-2);if(r===r&&d==="px")return r;if(r===r&&d==="vh"){let l=document.createElement("div");l.style.cssText="position:fixed;height:100vh",document.body.appendChild(l);let q=l.offsetHeight||window.innerHeight;return l.remove(),r*q/100}return P||S("scrollPin: pinDistance is not a number, vh or px; using window.innerHeight:",o),P=true,window.innerHeight}function T(){b=n.offsetWidth,v=e.offsetHeight,w=N(),n.style.height=`${v+w}px`;}function x(o){if(u===o)return;let r=u;if(u=o,o==="before")e.style.position=i.position,e.style.top=i.top,e.style.bottom=i.bottom,e.style.left=i.left,e.style.width=i.width,e.style.boxSizing=i.boxSizing,r==="pinned"&&M?.();else if(o==="pinned"){let d=n.getBoundingClientRect();e.style.position="fixed",e.style.top=`${f}px`,e.style.bottom="",e.style.left=`${d.left}px`,e.style.width=`${b}px`,e.style.boxSizing="border-box",r==="before"?$?.():r==="after"&&I?.();}else e.style.position="absolute",e.style.top="",e.style.bottom="0",e.style.left="0",e.style.width="100%",e.style.boxSizing="border-box",r==="pinned"&&H?.();}function W(){E=false;let o=n.getBoundingClientRect(),r=o.top,d=o.bottom,l=z((f-r)/w,0,1);h=l,k?.(l),r>f?x("before"):d-v<=f?x("after"):x("pinned");}function m(){E||(E=true,R=requestAnimationFrame(()=>W()));}function _(){T(),u==="pinned"&&(e.style.left=`${n.getBoundingClientRect().left}px`,e.style.width=`${b}px`),m();}let L=A??window;L.addEventListener("scroll",m,{passive:true});let c;function y(){clearTimeout(c),c=setTimeout(_,150);}window.addEventListener("resize",y),window.addEventListener("orientationchange",y);let p=null;return typeof ResizeObserver<"u"&&(p=new ResizeObserver(()=>{clearTimeout(c),c=setTimeout(_,100);}),p.observe(n),p.observe(document.documentElement),p.observe(e)),T(),m(),B(n,{type:"pin",getProgress:()=>h,getTrigger:()=>({tStart:0,tEnd:1})}),{destroy(){cancelAnimationFrame(R),clearTimeout(c),L.removeEventListener("scroll",m),window.removeEventListener("resize",y),window.removeEventListener("orientationchange",y),p?.disconnect(),e.style.position=i.position,e.style.top=i.top,e.style.bottom=i.bottom,e.style.left=i.left,e.style.width=i.width,e.style.boxSizing=i.boxSizing,n.parentNode?.insertBefore(e,n),n.remove(),C(n);},refresh(){_();},getProgress(){return h}}}exports.scrollPin=Q;
|
package/dist/pin/index.d.mts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
interface ScrollPinOptions {
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* How much scroll the element stays pinned for once it reaches `top`.
|
|
4
|
+
* A number is pixels and stays that; `'600px'` is 600. `'150vh'` is CSS's
|
|
5
|
+
* 150vh: it follows rotation and window resizes, but not a phone's address
|
|
6
|
+
* bar sliding in and out. Default: `window.innerHeight`, read again on every
|
|
7
|
+
* resize, address bar included.
|
|
8
|
+
*/
|
|
9
|
+
pinDistance?: number | `${number}vh` | `${number}px`;
|
|
4
10
|
/** Viewport Y position (px) where the element pins. Default: 0 (top of viewport). */
|
|
5
11
|
top?: number;
|
|
6
12
|
/** Custom scroll container (CSS selector or Element). Default: window. */
|
package/dist/pin/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
interface ScrollPinOptions {
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* How much scroll the element stays pinned for once it reaches `top`.
|
|
4
|
+
* A number is pixels and stays that; `'600px'` is 600. `'150vh'` is CSS's
|
|
5
|
+
* 150vh: it follows rotation and window resizes, but not a phone's address
|
|
6
|
+
* bar sliding in and out. Default: `window.innerHeight`, read again on every
|
|
7
|
+
* resize, address bar included.
|
|
8
|
+
*/
|
|
9
|
+
pinDistance?: number | `${number}vh` | `${number}px`;
|
|
4
10
|
/** Viewport Y position (px) where the element pins. Default: 0 (top of viewport). */
|
|
5
11
|
top?: number;
|
|
6
12
|
/** Custom scroll container (CSS selector or Element). Default: window. */
|
package/dist/pin/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'../chunk-4DOJSIEQ.mjs';import {a,b as b$1}from'../chunk-BCV4RAIX.mjs';import {b}from'../chunk-LFSU6LR3.mjs';var C={destroy:()=>{},refresh:()=>{},getProgress:()=>0};function
|
|
1
|
+
import {a as a$1}from'../chunk-4DOJSIEQ.mjs';import {a,b as b$1}from'../chunk-BCV4RAIX.mjs';import {b}from'../chunk-LFSU6LR3.mjs';var C={destroy:()=>{},refresh:()=>{},getProgress:()=>0};function V(c,P={}){if(typeof window>"u")return C;let S=typeof c=="string"?document.querySelector(c):c;if(!S)return b("scrollPin: element not found:",c),C;let e=S,{top:p=0,scrollContainer:m,onEnter:O,onLeave:k,onEnterBack:D,onLeaveBack:I,onProgress:q}=P,A=typeof m=="string"?document.querySelector(m):m??null,i={position:e.style.position,top:e.style.top,bottom:e.style.bottom,left:e.style.left,width:e.style.width,boxSizing:e.style.boxSizing},t=document.createElement("div");t.setAttribute("data-ssd-pin-wrapper",""),t.style.cssText="position:relative;",e.parentNode?.insertBefore(t,e),t.appendChild(e);let y=0,g=0,b$2=0,f="before",v=0,z=0,h=false,T=false;function F(){let n=P.pinDistance;if(n===void 0)return window.innerHeight;if(typeof n=="number")return n;let o=parseFloat(n),s=n.trim().slice(-2);if(o===o&&s==="px")return o;if(o===o&&s==="vh"){let r=document.createElement("div");r.style.cssText="position:fixed;height:100vh",document.body.appendChild(r);let W=r.offsetHeight||window.innerHeight;return r.remove(),o*W/100}return T||b("scrollPin: pinDistance is not a number, vh or px; using window.innerHeight:",n),T=true,window.innerHeight}function L(){y=t.offsetWidth,g=e.offsetHeight,b$2=F(),t.style.height=`${g+b$2}px`;}function w(n){if(f===n)return;let o=f;if(f=n,n==="before")e.style.position=i.position,e.style.top=i.top,e.style.bottom=i.bottom,e.style.left=i.left,e.style.width=i.width,e.style.boxSizing=i.boxSizing,o==="pinned"&&I?.();else if(n==="pinned"){let s=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${p}px`,e.style.bottom="",e.style.left=`${s.left}px`,e.style.width=`${y}px`,e.style.boxSizing="border-box",o==="before"?O?.():o==="after"&&D?.();}else e.style.position="absolute",e.style.top="",e.style.bottom="0",e.style.left="0",e.style.width="100%",e.style.boxSizing="border-box",o==="pinned"&&k?.();}function N(){h=false;let n=t.getBoundingClientRect(),o=n.top,s=n.bottom,r=a$1((p-o)/b$2,0,1);v=r,q?.(r),o>p?w("before"):s-g<=p?w("after"):w("pinned");}function a$2(){h||(h=true,z=requestAnimationFrame(()=>N()));}function x(){L(),f==="pinned"&&(e.style.left=`${t.getBoundingClientRect().left}px`,e.style.width=`${y}px`),a$2();}let B=A??window;B.addEventListener("scroll",a$2,{passive:true});let l;function u(){clearTimeout(l),l=setTimeout(x,150);}window.addEventListener("resize",u),window.addEventListener("orientationchange",u);let d=null;return typeof ResizeObserver<"u"&&(d=new ResizeObserver(()=>{clearTimeout(l),l=setTimeout(x,100);}),d.observe(t),d.observe(document.documentElement),d.observe(e)),L(),a$2(),a(t,{type:"pin",getProgress:()=>v,getTrigger:()=>({tStart:0,tEnd:1})}),{destroy(){cancelAnimationFrame(z),clearTimeout(l),B.removeEventListener("scroll",a$2),window.removeEventListener("resize",u),window.removeEventListener("orientationchange",u),d?.disconnect(),e.style.position=i.position,e.style.top=i.top,e.style.bottom=i.bottom,e.style.left=i.left,e.style.width=i.width,e.style.boxSizing=i.boxSizing,t.parentNode?.insertBefore(e,t),t.remove(),b$1(t);},refresh(){x();},getProgress(){return v}}}export{V as scrollPin};
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import React, { RefObject } from 'react';
|
|
3
2
|
import { E as EasingName, T as TriggerConfig, a as ScrollDrawOptions } from '../types-MswK0erX.mjs';
|
|
4
3
|
import { S as ScrollAnimateOptions } from '../engine-P8u6OK4m.mjs';
|
|
@@ -40,18 +39,18 @@ type ScrollDrawProps = ScrollDrawOptions & ElementAttrs & {
|
|
|
40
39
|
className?: string;
|
|
41
40
|
style?: React.CSSProperties;
|
|
42
41
|
};
|
|
43
|
-
declare function ScrollDraw({ children, className, style, ...rest }: ScrollDrawProps):
|
|
42
|
+
declare function ScrollDraw({ children, className, style, ...rest }: ScrollDrawProps): React.JSX.Element;
|
|
44
43
|
type ScrollAnimateProps = ScrollAnimateOptions & ElementAttrs & {
|
|
45
44
|
children: React.ReactNode;
|
|
46
45
|
className?: string;
|
|
47
46
|
style?: React.CSSProperties;
|
|
48
47
|
};
|
|
49
|
-
declare function ScrollAnimate({ children, className, style, ...rest }: ScrollAnimateProps):
|
|
48
|
+
declare function ScrollAnimate({ children, className, style, ...rest }: ScrollAnimateProps): React.JSX.Element;
|
|
50
49
|
type ScrollCounterProps = ScrollCounterOptions & ElementAttrs & {
|
|
51
50
|
className?: string;
|
|
52
51
|
style?: React.CSSProperties;
|
|
53
52
|
};
|
|
54
|
-
declare function ScrollCounter({ className, style, ...rest }: ScrollCounterProps):
|
|
53
|
+
declare function ScrollCounter({ className, style, ...rest }: ScrollCounterProps): React.JSX.Element;
|
|
55
54
|
type ScrollVideoProps = ScrollVideoOptions & ElementAttrs & {
|
|
56
55
|
src: string;
|
|
57
56
|
className?: string;
|
|
@@ -59,7 +58,7 @@ type ScrollVideoProps = ScrollVideoOptions & ElementAttrs & {
|
|
|
59
58
|
muted?: boolean;
|
|
60
59
|
playsInline?: boolean;
|
|
61
60
|
};
|
|
62
|
-
declare function ScrollVideo({ src, className, style, muted, playsInline, ...rest }: ScrollVideoProps):
|
|
61
|
+
declare function ScrollVideo({ src, className, style, muted, playsInline, ...rest }: ScrollVideoProps): React.JSX.Element;
|
|
63
62
|
type ScrollTextProps = ScrollTextOptions & ElementAttrs & {
|
|
64
63
|
children: string;
|
|
65
64
|
as?: keyof React.JSX.IntrinsicElements;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import React, { RefObject } from 'react';
|
|
3
2
|
import { E as EasingName, T as TriggerConfig, a as ScrollDrawOptions } from '../types-MswK0erX.js';
|
|
4
3
|
import { S as ScrollAnimateOptions } from '../engine-DQyBzZDl.js';
|
|
@@ -40,18 +39,18 @@ type ScrollDrawProps = ScrollDrawOptions & ElementAttrs & {
|
|
|
40
39
|
className?: string;
|
|
41
40
|
style?: React.CSSProperties;
|
|
42
41
|
};
|
|
43
|
-
declare function ScrollDraw({ children, className, style, ...rest }: ScrollDrawProps):
|
|
42
|
+
declare function ScrollDraw({ children, className, style, ...rest }: ScrollDrawProps): React.JSX.Element;
|
|
44
43
|
type ScrollAnimateProps = ScrollAnimateOptions & ElementAttrs & {
|
|
45
44
|
children: React.ReactNode;
|
|
46
45
|
className?: string;
|
|
47
46
|
style?: React.CSSProperties;
|
|
48
47
|
};
|
|
49
|
-
declare function ScrollAnimate({ children, className, style, ...rest }: ScrollAnimateProps):
|
|
48
|
+
declare function ScrollAnimate({ children, className, style, ...rest }: ScrollAnimateProps): React.JSX.Element;
|
|
50
49
|
type ScrollCounterProps = ScrollCounterOptions & ElementAttrs & {
|
|
51
50
|
className?: string;
|
|
52
51
|
style?: React.CSSProperties;
|
|
53
52
|
};
|
|
54
|
-
declare function ScrollCounter({ className, style, ...rest }: ScrollCounterProps):
|
|
53
|
+
declare function ScrollCounter({ className, style, ...rest }: ScrollCounterProps): React.JSX.Element;
|
|
55
54
|
type ScrollVideoProps = ScrollVideoOptions & ElementAttrs & {
|
|
56
55
|
src: string;
|
|
57
56
|
className?: string;
|
|
@@ -59,7 +58,7 @@ type ScrollVideoProps = ScrollVideoOptions & ElementAttrs & {
|
|
|
59
58
|
muted?: boolean;
|
|
60
59
|
playsInline?: boolean;
|
|
61
60
|
};
|
|
62
|
-
declare function ScrollVideo({ src, className, style, muted, playsInline, ...rest }: ScrollVideoProps):
|
|
61
|
+
declare function ScrollVideo({ src, className, style, muted, playsInline, ...rest }: ScrollVideoProps): React.JSX.Element;
|
|
63
62
|
type ScrollTextProps = ScrollTextOptions & ElementAttrs & {
|
|
64
63
|
children: string;
|
|
65
64
|
as?: keyof React.JSX.IntrinsicElements;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svg-scroll-draw",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "Scroll-driven animation for the web — draw SVG paths, reveal elements, pin sections, scrub video. Zero dependencies, native CSS fast path, works with React, Vue, Svelte, Solid, Angular, Astro and vanilla JS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svg",
|
|
@@ -472,7 +472,7 @@
|
|
|
472
472
|
"@playwright/test": "^1.65.0",
|
|
473
473
|
"@types/react": "^18.0.0",
|
|
474
474
|
"@vitest/coverage-v8": "^2.0.0",
|
|
475
|
-
"esbuild": "^0.
|
|
475
|
+
"esbuild": "^0.28.2",
|
|
476
476
|
"jsdom": "^25.0.0",
|
|
477
477
|
"scrollreveal": "^4.0.9",
|
|
478
478
|
"solid-js": "^1.9.13",
|