dash-parallax-scroll
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
import e,{useRef as t,useCallback as r,useEffect as n,useMemo as o,createContext as c,useContext as a,useState as u}from"react";import{useLenis as i}from"lenis/react";var l,s,f={exports:{}},b={},m={};"production"===process.env.NODE_ENV?f.exports=function(){if(l)return b;l=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(t,r,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==r.key&&(o=""+r.key),"key"in r)for(var c in n={},r)"key"!==c&&(n[c]=r[c]);else n=r;return r=n.ref,{$$typeof:e,type:t,key:o,ref:void 0!==r?r:null,props:n}}return b.Fragment=t,b.jsx=r,b.jsxs=r,b}():f.exports=(s||(s=1,"production"!==process.env.NODE_ENV&&function(){function t(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===M?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case y:return"Fragment";case v:return"Profiler";case p:return"StrictMode";case S:return"Suspense";case k:return"SuspenseList";case O:return"Activity"}if("object"==typeof e)switch(e.tag,e.$$typeof){case b:return"Portal";case h:return(e.displayName||"Context")+".Provider";case d:return(e.t.displayName||"Context")+".Consumer";case g:var r=e.render;return(e=e.displayName)||(e=""!==(e=r.displayName||r.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case j:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case w:r=e.o,e=e.u;try{return t(e(r))}catch(e){}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch(e){t=!0}if(t){var n=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),r(e)}}function o(e){if(e===y)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===w)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function c(){return Error("react-stack-top-frame")}function a(){var e=t(this.type);return F[e]||(F[e]=!0),void 0!==(e=this.props.ref)?e:null}function u(e,r,o,c,u,s,b,m){var y,p=r.children;if(void 0!==p)if(c){if(_(p)){for(c=0;c<p.length;c++)i(p[c]);Object.freeze&&Object.freeze(p)}}else i(p);if($.call(r,"key")){p=t(e);var v=Object.keys(r).filter(function(e){return"key"!==e});c=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",E[p+c]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",E[p+c]=!0)}if(p=null,void 0!==o&&(n(o),p=""+o),function(e){if($.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),p=""+r.key),"key"in r)for(var d in o={},r)"key"!==d&&(o[d]=r[d]);else o=r;return p&&function(e){function t(){l||(l=!0)}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(o,"function"==typeof e&&(e.displayName||e.name)),function(e,t,r,n,o,c,u,i){return r=c.ref,Object.defineProperty(e={$$typeof:f,type:e,key:t,props:c,i:o},"ref",null!==(void 0!==r?r:null)?{enumerable:!1,get:a}:{enumerable:!1,value:null}),e.l={},Object.defineProperty(e.l,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"m",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"p",{configurable:!1,enumerable:!1,writable:!0,value:u}),Object.defineProperty(e,"v",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,p,s,0,null===(y=x.A)?null:y.getOwner(),o,b,m)}function i(e){"object"==typeof e&&null!==e&&e.$$typeof===f&&e.l&&(e.l.validated=1)}var l,s=e,f=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),p=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),h=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),M=Symbol.for("react.client.reference"),x=s.h,$=Object.prototype.hasOwnProperty,_=Array.isArray,A=console.createTask?console.createTask:function(){return null},F={},P=(s={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(s,c)(),C=A(o(c)),E={};m.Fragment=y,m.jsx=function(e,t,r,n,c){var a=1e4>x.recentlyCreatedOwnerStacks++;return u(e,t,r,!1,0,c,a?Error("react-stack-top-frame"):P,a?A(o(e)):C)},m.jsxs=function(e,t,r,n,c){var a=1e4>x.recentlyCreatedOwnerStacks++;return u(e,t,r,!0,0,c,a?Error("react-stack-top-frame"):P,a?A(o(e)):C)}}()),m);var y=f.exports;const p=(e,t,r)=>e+(t-e)*r,v=e=>{const t=window.innerHeight+e.height,r=e.top+e.height;return Math.max(0,Math.min(1,r/t))},d=(e,t,r)=>(.5-v(e))*t+r,h=(e,t)=>{const r=v(e);return t[0]+(t[1]-t[0])*r},g=(e,t)=>{const r=window.innerHeight,n=e.top+e.height/2,o=Math.max(0,Math.min(1,1-Math.abs(n-r/2)/(r/2)));return t[0]+(t[1]-t[0])*o},S=(e,t,r,n,o)=>{if(Math.abs(t-n)>.1||Math.abs(r-o)>.01){const n=[];return 0!==t&&n.push(`translate3d(0,${t.toFixed(1)}%,0)`),1!==r&&n.push(`scale(${r.toFixed(3)})`),e.style.transform=n.join(" "),e.style.willChange=n.length?"transform":"auto",!0}return!1},k=(e,t,r,n)=>Math.abs(t-r)>.01&&((e.querySelector(n)||e).style.filter=`brightness(${t.toFixed(2)})`,!0),j=c(null),w={strength:-20,offset:0,throttle:16,enabled:!0,scrub:.1,scale:[1,1],brightness:{range:[.3,1],selector:"img, video, picture"}};let O=0;function M({children:e}){const c=i(),a=t(new Map),u=t(null),l=t(0),s=r((e,t={})=>{const r="parallax-"+ ++O,n={...w,...t};void 0===t.brightness?n.brightness=w.brightness:t.brightness&&!t.brightness.selector&&(n.brightness.selector="img, video, picture");const o={id:r,element:e,options:n,target:0,current:0,targetScale:1,currentScale:1,targetBrightness:1,currentBrightness:1};return a.current.set(r,o),r},[]),f=r(e=>{a.current.delete(e)},[]),b=r(e=>{const t=a.current.get(e);return t?{position:t.current,scale:t.currentScale,brightness:t.currentBrightness}:{position:0,scale:1,brightness:1}},[]),m=r(()=>{for(const e of a.current.values())if(e.options.enabled)try{const t=e.element.getBoundingClientRect();e.target=d(t,e.options.strength,e.options.offset),e.targetScale=h(t,e.options.scale),e.options.brightness&&(e.targetBrightness=g(t,e.options.brightness.range))}catch(e){}},[]),p=r(()=>{let e=!1;for(const t of a.current.values())if(t.options.enabled)try{const r=t.options.scrub,n=t.current,o=t.currentScale,c=t.currentBrightness;t.current+=(t.target-t.current)*r,t.currentScale+=(t.targetScale-t.currentScale)*r,t.currentBrightness+=(t.targetBrightness-t.currentBrightness)*r;const a=S(t.element,t.current,t.currentScale,n,o),u=!!t.options.brightness&&k(t.element,t.currentBrightness,c,t.options.brightness.selector||"img, video, picture");(a||u)&&(e=!0)}catch(e){}e&&a.current.size>0?u.current=requestAnimationFrame(p):u.current=null},[]),v=r(()=>{if(0===a.current.size)return;const e=performance.now(),t=Math.min(...Array.from(a.current.values()).map(e=>e.options.throttle));e-l.current<t||(l.current=e,m(),u.current||(u.current=requestAnimationFrame(p)))},[m,p]);n(()=>{if(c)return c.on("scroll",v),v(),()=>{c.off("scroll",v),u.current&&(cancelAnimationFrame(u.current),u.current=null)}},[c,v]);const M=o(()=>({register:s,unregister:f,getValue:b}),[s,f,b]);return y.jsx(j.Provider,{value:M,children:e})}const x=()=>{const e=a(j);if(!e)throw Error("useParallaxContext must be used within a ParallaxProvider");return e};function $(e={}){const o=x(),c=t(null),a=t(null),i=t(null),[l,s]=u({position:0,scale:1,brightness:1}),f=r(()=>{if(a.current&&o)try{const e=o.getValue(a.current);s(t=>t.position!==e.position||t.scale!==e.scale||t.brightness!==e.brightness?e:t)}catch(e){}},[o]);return n(()=>{const t=c.current;if(t&&o)try{return a.current=o.register(t,e),i.current=setInterval(f,16),()=>{a.current&&o&&o.unregister(a.current),i.current&&clearInterval(i.current)}}catch(e){}},[o,e,f]),[c,l]}function _(e,r={}){const o=x(),c=t([]);n(()=>{if(!o||!e.current)return;const t={strength:r.parallaxStrength||-20,enabled:!1!==r.enabled,throttle:r.throttle||16,scrub:r.scrub||.1,scale:r.scaleEnabled?[r.scaleFrom||1,r.scaleTo||1.2]:[1,1],brightness:r.applyBrightness?{range:[.3,1],selector:"img, video, picture"}:void 0};return c.current.forEach(e=>{o.unregister(e)}),c.current=[],e.current.forEach((e,r)=>{if(e)try{const r=o.register(e,t);c.current.push(r)}catch(e){}}),()=>{c.current.forEach(e=>{o.unregister(e)}),c.current=[]}},[o,e,r])}export{M as ParallaxProvider,g as calculateBrightness,d as calculateParallax,h as calculateScale,p as lerp,$ as useParallax,x as useParallaxContext,_ as useParallaxScroll}; | ||
import e,{useRef as t,useCallback as r,useEffect as n,createContext as o,useContext as c,useState as a}from"react";import{useLenis as u}from"lenis/react";var i,l,s={exports:{}},f={},b={};"production"===process.env.NODE_ENV?s.exports=function(){if(i)return f;i=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(t,r,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==r.key&&(o=""+r.key),"key"in r)for(var c in n={},r)"key"!==c&&(n[c]=r[c]);else n=r;return r=n.ref,{$$typeof:e,type:t,key:o,ref:void 0!==r?r:null,props:n}}return f.Fragment=t,f.jsx=r,f.jsxs=r,f}():s.exports=(l||(l=1,"production"!==process.env.NODE_ENV&&function(){function t(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===M?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case y:return"Fragment";case v:return"Profiler";case p:return"StrictMode";case S:return"Suspense";case k:return"SuspenseList";case O:return"Activity"}if("object"==typeof e)switch(e.tag,e.$$typeof){case m:return"Portal";case g:return(e.displayName||"Context")+".Provider";case d:return(e.t.displayName||"Context")+".Consumer";case h:var r=e.render;return(e=e.displayName)||(e=""!==(e=r.displayName||r.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case j:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case w:r=e.o,e=e.u;try{return t(e(r))}catch(e){}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch(e){t=!0}if(t){var n=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),r(e)}}function o(e){if(e===y)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===w)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function c(){return Error("react-stack-top-frame")}function a(){var e=t(this.type);return F[e]||(F[e]=!0),void 0!==(e=this.props.ref)?e:null}function u(e,r,o,c,u,s,b,m){var y,p=r.children;if(void 0!==p)if(c){if(_(p)){for(c=0;c<p.length;c++)i(p[c]);Object.freeze&&Object.freeze(p)}}else i(p);if($.call(r,"key")){p=t(e);var v=Object.keys(r).filter(function(e){return"key"!==e});c=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",E[p+c]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",E[p+c]=!0)}if(p=null,void 0!==o&&(n(o),p=""+o),function(e){if($.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),p=""+r.key),"key"in r)for(var d in o={},r)"key"!==d&&(o[d]=r[d]);else o=r;return p&&function(e){function t(){l||(l=!0)}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(o,"function"==typeof e&&(e.displayName||e.name)),function(e,t,r,n,o,c,u,i){return r=c.ref,Object.defineProperty(e={$$typeof:f,type:e,key:t,props:c,i:o},"ref",null!==(void 0!==r?r:null)?{enumerable:!1,get:a}:{enumerable:!1,value:null}),e.l={},Object.defineProperty(e.l,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"m",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"p",{configurable:!1,enumerable:!1,writable:!0,value:u}),Object.defineProperty(e,"v",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,p,s,0,null===(y=x.A)?null:y.getOwner(),o,b,m)}function i(e){"object"==typeof e&&null!==e&&e.$$typeof===f&&e.l&&(e.l.validated=1)}var l,s=e,f=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),p=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),g=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),M=Symbol.for("react.client.reference"),x=s.h,$=Object.prototype.hasOwnProperty,_=Array.isArray,A=console.createTask?console.createTask:function(){return null},F={},P=(s={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(s,c)(),C=A(o(c)),E={};b.Fragment=y,b.jsx=function(e,t,r,n,c){var a=1e4>x.recentlyCreatedOwnerStacks++;return u(e,t,r,!1,0,c,a?Error("react-stack-top-frame"):P,a?A(o(e)):C)},b.jsxs=function(e,t,r,n,c){var a=1e4>x.recentlyCreatedOwnerStacks++;return u(e,t,r,!0,0,c,a?Error("react-stack-top-frame"):P,a?A(o(e)):C)}}()),b);var m=s.exports;const y=(e,t,r)=>e+(t-e)*r,p=e=>{const t=window.innerHeight+e.height,r=e.top+e.height;return Math.max(0,Math.min(1,r/t))},v=(e,t,r)=>(.5-p(e))*t+r,d=(e,t)=>{const r=p(e);return t[0]+(t[1]-t[0])*r},g=(e,t)=>{const r=window.innerHeight,n=e.top+e.height/2,o=Math.max(0,Math.min(1,1-Math.abs(n-r/2)/(r/2)));return t[0]+(t[1]-t[0])*o},h=(e,t,r,n,o)=>{if(Math.abs(t-n)>.1||Math.abs(r-o)>.01){const n=[];0!==t&&n.push(`translate3d(0,${t.toFixed(1)}%,0)`),1!==r&&n.push(`scale(${r.toFixed(3)})`),e.style.transform=n.join(" ")}return!1},S=(e,t,r,n)=>(Math.abs(t-r)>.01&&((e.querySelector(n)||e).style.filter=`brightness(${t.toFixed(2)})`),!1),k=o(null),j={strength:-20,offset:0,throttle:16,enabled:!0,scrub:.1,scale:[1,1],brightness:{range:[.3,1],selector:"img, video, picture"}};let w=0;function O({children:e}){const o=u(),c=t(new Map),a=t(null),i=t(0),l=r((e,t={})=>{const r="parallax-"+ ++w,n={id:r,element:e,options:{...j,...t},target:0,current:0,targetScale:1,currentScale:1,targetBrightness:1,currentBrightness:1};return c.current.set(r,n),r},[]),s=r(e=>{c.current.delete(e)},[]),f=r(e=>{const t=c.current.get(e);return t?{position:t.current,scale:t.currentScale,brightness:t.currentBrightness}:{position:0,scale:1,brightness:1}},[]),b=r(()=>{for(const e of c.current.values()){if(!e.options.enabled)continue;const t=e.element.getBoundingClientRect();e.target=v(t,e.options.strength,e.options.offset),e.targetScale=d(t,e.options.scale),e.options.brightness&&(e.targetBrightness=g(t,e.options.brightness.range))}},[]),y=r(()=>{let e=!1;for(const t of c.current.values()){if(!t.options.enabled)continue;const r=t.options.scrub,n=t.current,o=t.currentScale,c=t.currentBrightness;t.current+=(t.target-t.current)*r,t.currentScale+=(t.targetScale-t.currentScale)*r,t.currentBrightness+=(t.targetBrightness-t.currentBrightness)*r,h(t.element,t.current,t.currentScale,n,o),t.options.brightness&&S(t.element,t.currentBrightness,c,t.options.brightness.selector)&&(e=!0)}a.current=e?requestAnimationFrame(y):null},[]),p=r(()=>{const e=performance.now(),t=Math.min(...Array.from(c.current.values()).map(e=>e.options.throttle));e-i.current<t||(i.current=e,b(),a.current||(a.current=requestAnimationFrame(y)))},[b,y]);return n(()=>{if(o)return o.on("scroll",p),p(),()=>{o.off("scroll",p),a.current&&cancelAnimationFrame(a.current)}},[o,p]),m.jsx(k.Provider,{value:{register:l,unregister:s,getValue:f},children:e})}const M=()=>{const e=c(k);if(!e)throw Error("useParallaxContext must be used within a ParallaxProvider");return e};function x(e={}){const o=M(),c=t(null),u=t(null),[i,l]=a({position:0,scale:1,brightness:1}),s=r(()=>{if(u.current){const e=o.getValue(u.current);l(e)}},[o]);return n(()=>{const t=c.current;if(!t)return;u.current=o.register(t,e);const r=setInterval(s,16);return()=>{u.current&&o.unregister(u.current),clearInterval(r)}},[o,e,s]),[c,i]}function $(e,r={}){const o=M(),c=t([]);n(()=>{if(!o||!e.current)return;const t={strength:r.parallaxStrength||-20,enabled:!1!==r.enabled,throttle:r.throttle||16,scrub:r.scrub||.1,scale:r.scaleEnabled?[r.scaleFrom||1,r.scaleTo||1.2]:[1,1],brightness:r.applyBrightness?{range:[.3,1],selector:"img, video, picture"}:void 0};return c.current.forEach(e=>{o.unregister(e)}),c.current=[],e.current.forEach((e,r)=>{if(e){const r=o.register(e,t);c.current.push(r)}}),()=>{c.current.forEach(e=>{o.unregister(e)}),c.current=[]}},[o,e,r])}export{O as ParallaxProvider,g as calculateBrightness,v as calculateParallax,d as calculateScale,y as lerp,x as useParallax,M as useParallaxContext,$ as useParallaxScroll}; |
{ | ||
"name": "dash-parallax-scroll", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A high-performance React parallax library with brightness control and smooth animations", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs", |
Sorry, the diff of this file is not supported yet
21007
-4.64%132
-2.94%