Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parallax-controller

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parallax-controller - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

4

dist/parallax-controller.cjs.development.js

@@ -1051,2 +1051,4 @@ 'use strict';

_proto._handleScroll = function _handleScroll() {
var _this$elements;
var _this$_getScrollPosit2 = this._getScrollPosition(),

@@ -1059,3 +1061,3 @@ nx = _this$_getScrollPosit2[0],

if (!this._ticking && this.elements.length > 0) {
if (!this._ticking && ((_this$elements = this.elements) == null ? void 0 : _this$elements.length) > 0) {
this._ticking = true; // @ts-ignore

@@ -1062,0 +1064,0 @@

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,i,s,n,r,l=(t=require("bezier-easing"))&&"object"==typeof t&&"default"in t?t.default:t,a=function(t){this.startX=t.startX,this.startY=t.startY,this.endX=t.endX,this.endY=t.endY,this.totalX=this.endX-this.startX,this.totalY=this.endY-this.startY,this.startMultiplierX=t.startMultiplierX||1,this.endMultiplierX=t.endMultiplierX||1,this.startMultiplierY=t.startMultiplierY||1,this.endMultiplierY=t.endMultiplierY||1};function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}(e=exports.ValidCSSEffects||(exports.ValidCSSEffects={})).speed="speed",e.translateX="translateX",e.translateY="translateY",e.rotate="rotate",e.rotateX="rotateX",e.rotateY="rotateY",e.rotateZ="rotateZ",e.scale="scale",e.scaleX="scaleX",e.scaleY="scaleY",e.scaleZ="scaleZ",e.opacity="opacity",(i=exports.Units||(exports.Units={})).px="px",i["%"]="%",i.vh="vh",i.vw="vw",(s=exports.RotationUnits||(exports.RotationUnits={})).deg="deg",s.turn="turn",s.rad="rad",(exports.ScaleUnits||(exports.ScaleUnits={}))[""]="",(n=exports.ScrollAxis||(exports.ScrollAxis={})).vertical="vertical",n.horizontal="horizontal",(r=exports.EasingPreset||(exports.EasingPreset={})).ease="ease",r.easeIn="easeIn",r.easeOut="easeOut",r.easeInOut="easeInOut",r.easeInQuad="easeInQuad",r.easeInCubic="easeInCubic",r.easeInQuart="easeInQuart",r.easeInQuint="easeInQuint",r.easeInSine="easeInSine",r.easeInExpo="easeInExpo",r.easeInCirc="easeInCirc",r.easeOutQuad="easeOutQuad",r.easeOutCubic="easeOutCubic",r.easeOutQuart="easeOutQuart",r.easeOutQuint="easeOutQuint",r.easeOutSine="easeOutSine",r.easeOutExpo="easeOutExpo",r.easeOutCirc="easeOutCirc",r.easeInOutQuad="easeInOutQuad",r.easeInOutCubic="easeInOutCubic",r.easeInOutQuart="easeInOutQuart",r.easeInOutQuint="easeInOutQuint",r.easeInOutSine="easeInOutSine",r.easeInOutExpo="easeInOutExpo",r.easeInOutCirc="easeInOutCirc",r.easeInBack="easeInBack",r.easeOutBack="easeOutBack",r.easeInOutBack="easeInOutBack";var h=0;function u(){return++h}var d=function(){function t(t){var e=t.el.getBoundingClientRect();if(t.view.scrollContainer){var i=t.view.scrollContainer.getBoundingClientRect();e=o({},e,{top:e.top-i.top,right:e.right-i.left,bottom:e.bottom-i.top,left:e.left-i.left})}this.height=t.el.offsetHeight,this.width=t.el.offsetWidth,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,t.rootMargin&&this._setRectWithRootMargin(t.rootMargin)}return t.prototype._setRectWithRootMargin=function(t){var e=t.top+t.bottom,i=t.left+t.right;this.top-=t.top,this.right+=t.right,this.bottom+=t.bottom,this.left-=t.left,this.height+=e,this.width+=i},t}(),c=[exports.ScaleUnits[""],exports.Units.px,exports.Units["%"],exports.Units.vh,exports.Units.vw,exports.RotationUnits.deg,exports.RotationUnits.turn,exports.RotationUnits.rad];function p(t,e){void 0===e&&(e=exports.Units["%"]);var i={value:0,unit:e};if(void 0===t)return i;if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid value provided. Must provide a value as a string or number");if(t=String(t),i.value=parseFloat(t),i.unit=t.match(/[\d.\-+]*\s*(.*)/)[1]||e,!c.includes(i.unit))throw new Error("Invalid unit provided.");return i}var f={ease:[.25,.1,.25,1],easeIn:[.42,0,1,1],easeOut:[0,0,.58,1],easeInOut:[.42,0,.58,1],easeInQuad:[.55,.085,.68,.53],easeInCubic:[.55,.055,.675,.19],easeInQuart:[.895,.03,.685,.22],easeInQuint:[.755,.05,.855,.06],easeInSine:[.47,0,.745,.715],easeInExpo:[.95,.05,.795,.035],easeInCirc:[.6,.04,.98,.335],easeOutQuad:[.25,.46,.45,.94],easeOutCubic:[.215,.61,.355,1],easeOutQuart:[.165,.84,.44,1],easeOutQuint:[.23,1,.32,1],easeOutSine:[.39,.575,.565,1],easeOutExpo:[.19,1,.22,1],easeOutCirc:[.075,.82,.165,1],easeInOutQuad:[.455,.03,.515,.955],easeInOutCubic:[.645,.045,.355,1],easeInOutQuart:[.77,0,.175,1],easeInOutQuint:[.86,0,.07,1],easeInOutSine:[.445,.05,.55,.95],easeInOutExpo:[1,0,0,1],easeInOutCirc:[.785,.135,.15,.86],easeInBack:[.6,-.28,.735,.045],easeOutBack:[.175,.885,.32,1.275],easeInOutBack:[.68,-.55,.265,1.55]};function v(t){if(Array.isArray(t))return l(t[0],t[1],t[2],t[3]);if("string"==typeof t&&void 0!==f[t]){var e=f[t];return l(e[0],e[1],e[2],e[3])}}var g=Object.values(exports.ValidCSSEffects),w={speed:"px",translateX:"%",translateY:"%",rotate:"deg",rotateX:"deg",rotateY:"deg",rotateZ:"deg",scale:"",scaleX:"",scaleY:"",scaleZ:"",opacity:""};function m(t,e){var i={};return g.forEach((function(s){var n=w[s];if("number"==typeof(null==t?void 0:t[s])){var r=null==t?void 0:t[s],l=-10*(r||0)+"px",a=p(10*(r||0)+"px"),o=p(l),h={start:a.value,end:o.value,unit:a.unit};e===exports.ScrollAxis.vertical&&(i.translateY=h),e===exports.ScrollAxis.horizontal&&(i.translateX=h)}if(Array.isArray(null==t?void 0:t[s])){var u=null==t?void 0:t[s];if(void 0!==u[0]&&void 0!==u[1]){var d=p(null==u?void 0:u[0],n),c=p(null==u?void 0:u[1],n),f=v(null==u?void 0:u[2]);if(i[s]={start:d.value,end:c.value,unit:d.unit,easing:f},d.unit!==c.unit)throw new Error("Must provide matching units for the min and max offset values of each axis.")}}})),i}function x(t,e,i,s){var n=(i-t)/e;return s&&(n=s(n)),n}function E(t,e,i){return i>=t&&i<=e}function _(t,e,i,s,n){return(i-e)*(t-s)/(n-s)+e}function C(t,e){return{value:_("function"==typeof t.easing?t.easing(e):e,(null==t?void 0:t.start)||0,(null==t?void 0:t.end)||0,0,1),unit:null==t?void 0:t.unit}}var S=Object.values(exports.ValidCSSEffects).filter((function(t){return"opacity"!==t}));function b(t,e,i){if(i){var s=function(t,e){return S.reduce((function(i,s){var n=t[s]&&C(t[s],e);return void 0===n||void 0===n.value||void 0===n.unit?i:i+(s+"(")+n.value+n.unit+")"}),"")}(t,e),n=function(t,e){var i=t.opacity&&C(t.opacity,e);return void 0===i||void 0===i.value||void 0===i.unit?"":""+i.value}(t,e);i.style.transform=s,i.style.opacity=n}}function y(t){var e=t.el;e&&(e.style.transform="",e.style.opacity="")}function I(t,e,i){var s=e>t,n=(Math.abs(t)+Math.abs(e))*(s?-1:1);return Math.max(i/(i+n),1)}function O(t,e){var i=t.start,s=t.end,n=t.unit;if("%"===n){var r=e/100;i*=r,s*=r}return"vw"===n&&(i=window.innerWidth*(i/100),s=window.innerWidth*(s/100)),"vh"===n&&(i=window.innerHeight*(i/100),s=window.innerHeight*(s/100)),{start:i,end:s}}var P={start:0,end:0,unit:""},A=function(t,e,i){return Math.min(Math.max(t,e),i)},X=function(){function t(t){var e,i;this.el=t.el,this.props=t.props,this.scrollAxis=t.scrollAxis,this.disabledParallaxController=t.disabledParallaxController||!1,this.id=u(),this.effects=m(this.props,this.scrollAxis),this.isInView=null,this.progress=0,this._setElementEasing(t.props.easing),e=t.el,i=Object.keys(this.effects).includes("opacity"),e.style.willChange="transform"+(i?",opacity":"")}var e=t.prototype;return e.updateProps=function(t){return this.props=o({},this.props,t),this.effects=m(t,this.scrollAxis),this._setElementEasing(t.easing),this},e.setCachedAttributes=function(t,e){y(this),this.rect=new d({el:this.props.targetElement||this.el,rootMargin:this.props.rootMargin,view:t});var i,s,n,r=(s=this.effects,n=this.scrollAxis,!((i=this.props).rootMargin||i.targetElement||i.shouldDisableScalingTranslations||!(s.translateX&&n===exports.ScrollAxis.horizontal||s.translateY&&n===exports.ScrollAxis.vertical)));return"number"==typeof this.props.startScroll&&"number"==typeof this.props.endScroll?(this.limits=new a({startX:this.props.startScroll,startY:this.props.startScroll,endX:this.props.endScroll,endY:this.props.endScroll}),this._setElementStyles(),this):(r?(this.limits=function(t,e,i,s,n,r){var l=i.translateY||P,o=O(i.translateX||P,t.width),h=o.start,u=o.end,d=O(l,t.height),c=d.start,p=d.end,f=t.top-e.height,v=t.left-e.width,g=t.bottom,w=t.right,m=1,x=1;n===exports.ScrollAxis.vertical&&(x=m=I(c,p,e.height+t.height));var E=1,_=1;if(n===exports.ScrollAxis.horizontal&&(_=E=I(h,u,e.width+t.width)),c<0&&(f+=c*m),p>0&&(g+=p*x),h<0&&(v+=h*E),u>0&&(w+=u*_),v+=s.x,w+=s.x,f+=s.y,g+=s.y,r){var C=s.y+t.top<e.height,S=s.x+t.left<e.width,b=s.y+t.bottom>e.scrollHeight-e.height,y=s.x+t.right>e.scrollWidth-e.height;C&&b&&(m=1,x=1,f=0,g=e.scrollHeight-e.height),S&&y&&(E=1,_=1,v=0,w=e.scrollWidth-e.width),!C&&b&&(m=I(c,p,(g=e.scrollHeight-e.height)-(f=t.top-e.height+s.y)),x=1,c<0&&(f+=c*m)),!S&&y&&(E=I(h,u,(w=e.scrollWidth-e.width)-(v=t.left-e.width+s.x)),_=1,h<0&&(v+=h*E)),C&&!b&&(m=1,x=I(c,p,(g=t.bottom+s.y)-(f=0)),p>0&&(g+=p*x)),S&&!y&&(E=1,_=I(h,u,(w=t.right+s.x)-(v=0)),u>0&&(w+=u*_))}return new a({startX:v,startY:f,endX:w,endY:g,startMultiplierX:E,endMultiplierX:_,startMultiplierY:m,endMultiplierY:x})}(this.rect,t,this.effects,e,this.scrollAxis,this.props.shouldAlwaysCompleteAnimation),this.scaledEffects=function(t,e){var i=o({},t);return i.translateX&&(i.translateX=o({},t.translateX,{start:i.translateX.start*e.startMultiplierX,end:i.translateX.end*e.endMultiplierX})),i.translateY&&(i.translateY=o({},t.translateY,{start:i.translateY.start*e.startMultiplierY,end:i.translateY.end*e.endMultiplierY})),i}(this.effects,this.limits)):this.limits=function(t,e,i,s){var n=t.top-e.height,r=t.left-e.width,l=t.bottom,o=t.right;return r+=i.x,o+=i.x,n+=i.y,l+=i.y,s&&(i.y+t.top<e.height&&(n=0),i.x+t.left<e.width&&(r=0),l>e.scrollHeight-e.height&&(l=e.scrollHeight-e.height),o>e.scrollWidth-e.width&&(o=e.scrollWidth-e.width)),new a({startX:r,startY:n,endX:o,endY:l})}(this.rect,t,e,this.props.shouldAlwaysCompleteAnimation),this._setElementStyles(),this)},e._updateElementIsInView=function(t){var e=null===this.isInView;t!==this.isInView&&(t?this.props.onEnter&&this.props.onEnter(this):e||(this._setFinalProgress(),this._setElementStyles(),this.props.onExit&&this.props.onExit(this))),this.isInView=t},e._setFinalProgress=function(){var t=A(Math.round(this.progress),0,1);this._updateElementProgress(t)},e._setElementStyles=function(){this.props.disabled||this.disabledParallaxController||b(this.scaledEffects||this.effects,this.progress,this.el)},e._updateElementProgress=function(t){this.progress=t,this.props.onProgressChange&&this.props.onProgressChange(this.progress),this.props.onChange&&this.props.onChange(this)},e._setElementEasing=function(t){this.easing=v(t)},e.updateElementOptions=function(t){this.scrollAxis=t.scrollAxis,this.disabledParallaxController=t.disabledParallaxController||!1},e.updatePosition=function(t){if(!this.limits)return this;var e=this.scrollAxis===exports.ScrollAxis.vertical,i=null===this.isInView,s=e?this.limits.startY:this.limits.startX,n=e?this.limits.totalY:this.limits.totalX,r=e?t.y:t.x,l=E(s,e?this.limits.endY:this.limits.endX,r);if(this._updateElementIsInView(l),l){var a=x(s,n,r,this.easing);this._updateElementProgress(a),this._setElementStyles()}else i&&(this.progress=A(Math.round(x(s,n,r,this.easing)),0,1),this._setElementStyles());return this},t}(),Y=function(){function t(t){this.scrollContainer=t.scrollContainer,this.width=t.width,this.height=t.height,this.scrollHeight=t.scrollHeight,this.scrollWidth=t.scrollWidth}var e=t.prototype;return e.hasChanged=function(t){return t.width!==this.width||t.height!==this.height||t.scrollWidth!==this.scrollWidth||t.scrollHeight!==this.scrollHeight},e.setSize=function(t){return this.width=t.width,this.height=t.height,this.scrollHeight=t.scrollHeight,this.scrollWidth=t.scrollWidth,this},t}(),M=function(){function t(t,e){this.x=t,this.y=e,this.dx=0,this.dy=0}return t.prototype.setScroll=function(t,e){return this.dx=t-this.x,this.dy=e-this.y,this.x=t,this.y=e,this},t}();function V(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){return t=!0,!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(t){}return t}var z=function(){function t(t){var e=t.scrollAxis,i=void 0===e?exports.ScrollAxis.vertical:e,s=t.scrollContainer,n=t.disabled;this.disabled=void 0!==n&&n,this.scrollAxis=i,this.elements=[],this._hasScrollContainer=!!s,this.viewEl=null!=s?s:window;var r=this._getScrollPosition();this.scroll=new M(r[0],r[1]),this.view=new Y({width:0,height:0,scrollWidth:0,scrollHeight:0,scrollContainer:this._hasScrollContainer?s:void 0}),this._ticking=!1,this._supportsPassive=V(),this._bindAllMethods(),this.disabled||(this._addListeners(this.viewEl),this._addResizeObserver(),this._setViewSize())}t.init=function(e){if("undefined"==typeof window)throw new Error("Looks like ParallaxController.init() was called on the server. This method must be called on the client.");return new t(e)};var e=t.prototype;return e._bindAllMethods=function(){var t=this;["_addListeners","_removeListeners","_getScrollPosition","_handleScroll","_handleUpdateCache","_updateAllElements","_updateElementPosition","_setViewSize","_addResizeObserver","_checkIfViewHasChanged","_getViewParams","getElements","createElement","removeElementById","resetElementStyles","updateElementPropsById","update","updateScrollContainer","destroy"].forEach((function(e){t[e]=t[e].bind(t)}))},e._addListeners=function(t){t.addEventListener("scroll",this._handleScroll,!!this._supportsPassive&&{passive:!0}),window.addEventListener("resize",this._handleUpdateCache,!1),window.addEventListener("blur",this._handleUpdateCache,!1),window.addEventListener("focus",this._handleUpdateCache,!1),window.addEventListener("load",this._handleUpdateCache,!1)},e._removeListeners=function(t){var e;t.removeEventListener("scroll",this._handleScroll,!1),window.removeEventListener("resize",this._handleUpdateCache,!1),window.removeEventListener("blur",this._handleUpdateCache,!1),window.removeEventListener("focus",this._handleUpdateCache,!1),window.removeEventListener("load",this._handleUpdateCache,!1),null==(e=this._resizeObserver)||e.disconnect()},e._addResizeObserver=function(){var t=this;try{var e=this._hasScrollContainer?this.viewEl:document.documentElement;this._resizeObserver=new ResizeObserver((function(){return t.update()})),this._resizeObserver.observe(e)}catch(t){console.warn("Failed to create the resize observer in the ParallaxContoller")}},e._getScrollPosition=function(){return[this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset]},e._handleScroll=function(){var t=this._getScrollPosition();this.scroll.setScroll(t[0],t[1]),!this._ticking&&this.elements.length>0&&(this._ticking=!0,window.requestAnimationFrame(this._updateAllElements))},e._handleUpdateCache=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},e._updateAllElements=function(t){var e=this,i=(void 0===t?{}:t).updateCache;this.elements&&this.elements.forEach((function(t){i&&t.setCachedAttributes(e.view,e.scroll),e._updateElementPosition(t)})),this._ticking=!1},e._updateElementPosition=function(t){t.props.disabled||this.disabled||t.updatePosition(this.scroll)},e._getViewParams=function(){if(this._hasScrollContainer)return this.view.setSize({width:this.viewEl.offsetWidth,height:this.viewEl.offsetHeight,scrollHeight:this.viewEl.scrollHeight,scrollWidth:this.viewEl.scrollWidth});var t=document.documentElement;return{width:window.innerWidth||t.clientWidth,height:window.innerHeight||t.clientHeight,scrollHeight:t.scrollHeight,scrollWidth:t.scrollWidth}},e._setViewSize=function(){return this.view.setSize(this._getViewParams())},e._checkIfViewHasChanged=function(){return this.view.hasChanged(this._getViewParams())},e.getElements=function(){return this.elements},e.createElement=function(t){var e=new X(o({},t,{scrollAxis:this.scrollAxis,disabledParallaxController:this.disabled}));return e.setCachedAttributes(this.view,this.scroll),this.elements=this.elements?[].concat(this.elements,[e]):[e],this._updateElementPosition(e),this._checkIfViewHasChanged()&&this.update(),e},e.removeElementById=function(t){this.elements&&(this.elements=this.elements.filter((function(e){return e.id!==t})))},e.updateElementPropsById=function(t,e){this.elements&&(this.elements=this.elements.map((function(i){return i.id===t?i.updateProps(e):i}))),this.update()},e.resetElementStyles=function(t){y(t)},e.update=function(){var t=this._getScrollPosition();this.scroll.setScroll(t[0],t[1]),this._setViewSize(),this._updateAllElements({updateCache:!0})},e.updateScrollContainer=function(t){this._removeListeners(this.viewEl),this.viewEl=t,this._hasScrollContainer=!!t,this.view=new Y({width:0,height:0,scrollWidth:0,scrollHeight:0,scrollContainer:t}),this._setViewSize(),this._addListeners(this.viewEl),this._updateAllElements({updateCache:!0})},e.disableParallaxController=function(){this.disabled=!0,this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return y(t)}))},e.enableParallaxController=function(){var t=this;this.disabled=!1,this.elements&&this.elements.forEach((function(e){return e.updateElementOptions({disabledParallaxController:!1,scrollAxis:t.scrollAxis})})),this._addListeners(this.viewEl),this._addResizeObserver(),this._setViewSize()},e.disableAllElements=function(){console.warn("deprecated: use disableParallaxController() instead"),this.elements&&(this.elements=this.elements.map((function(t){return t.updateProps({disabled:!0})}))),this.update()},e.enableAllElements=function(){console.warn("deprecated: use enableParallaxController() instead"),this.elements&&(this.elements=this.elements.map((function(t){return t.updateProps({disabled:!1})}))),this.update()},e.destroy=function(){this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return y(t)})),this.elements=void 0},t}();exports.Element=X,exports.Limits=a,exports.ParallaxController=z,exports.Rect=d,exports.Scroll=M,exports.View=Y,exports.createId=u,exports.getProgressAmount=x,exports.isElementInView=E,exports.parseElementTransitionEffects=m,exports.parseValueAndUnit=p,exports.resetStyles=y,exports.scaleBetween=_,exports.scaleEffectByProgress=C,exports.setElementStyles=b,exports.testForPassiveScroll=V;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,i,s,n,r,l=(t=require("bezier-easing"))&&"object"==typeof t&&"default"in t?t.default:t,a=function(t){this.startX=t.startX,this.startY=t.startY,this.endX=t.endX,this.endY=t.endY,this.totalX=this.endX-this.startX,this.totalY=this.endY-this.startY,this.startMultiplierX=t.startMultiplierX||1,this.endMultiplierX=t.endMultiplierX||1,this.startMultiplierY=t.startMultiplierY||1,this.endMultiplierY=t.endMultiplierY||1};function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t}).apply(this,arguments)}(e=exports.ValidCSSEffects||(exports.ValidCSSEffects={})).speed="speed",e.translateX="translateX",e.translateY="translateY",e.rotate="rotate",e.rotateX="rotateX",e.rotateY="rotateY",e.rotateZ="rotateZ",e.scale="scale",e.scaleX="scaleX",e.scaleY="scaleY",e.scaleZ="scaleZ",e.opacity="opacity",(i=exports.Units||(exports.Units={})).px="px",i["%"]="%",i.vh="vh",i.vw="vw",(s=exports.RotationUnits||(exports.RotationUnits={})).deg="deg",s.turn="turn",s.rad="rad",(exports.ScaleUnits||(exports.ScaleUnits={}))[""]="",(n=exports.ScrollAxis||(exports.ScrollAxis={})).vertical="vertical",n.horizontal="horizontal",(r=exports.EasingPreset||(exports.EasingPreset={})).ease="ease",r.easeIn="easeIn",r.easeOut="easeOut",r.easeInOut="easeInOut",r.easeInQuad="easeInQuad",r.easeInCubic="easeInCubic",r.easeInQuart="easeInQuart",r.easeInQuint="easeInQuint",r.easeInSine="easeInSine",r.easeInExpo="easeInExpo",r.easeInCirc="easeInCirc",r.easeOutQuad="easeOutQuad",r.easeOutCubic="easeOutCubic",r.easeOutQuart="easeOutQuart",r.easeOutQuint="easeOutQuint",r.easeOutSine="easeOutSine",r.easeOutExpo="easeOutExpo",r.easeOutCirc="easeOutCirc",r.easeInOutQuad="easeInOutQuad",r.easeInOutCubic="easeInOutCubic",r.easeInOutQuart="easeInOutQuart",r.easeInOutQuint="easeInOutQuint",r.easeInOutSine="easeInOutSine",r.easeInOutExpo="easeInOutExpo",r.easeInOutCirc="easeInOutCirc",r.easeInBack="easeInBack",r.easeOutBack="easeOutBack",r.easeInOutBack="easeInOutBack";var h=0;function u(){return++h}var d=function(){function t(t){var e=t.el.getBoundingClientRect();if(t.view.scrollContainer){var i=t.view.scrollContainer.getBoundingClientRect();e=o({},e,{top:e.top-i.top,right:e.right-i.left,bottom:e.bottom-i.top,left:e.left-i.left})}this.height=t.el.offsetHeight,this.width=t.el.offsetWidth,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,t.rootMargin&&this._setRectWithRootMargin(t.rootMargin)}return t.prototype._setRectWithRootMargin=function(t){var e=t.top+t.bottom,i=t.left+t.right;this.top-=t.top,this.right+=t.right,this.bottom+=t.bottom,this.left-=t.left,this.height+=e,this.width+=i},t}(),c=[exports.ScaleUnits[""],exports.Units.px,exports.Units["%"],exports.Units.vh,exports.Units.vw,exports.RotationUnits.deg,exports.RotationUnits.turn,exports.RotationUnits.rad];function p(t,e){void 0===e&&(e=exports.Units["%"]);var i={value:0,unit:e};if(void 0===t)return i;if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid value provided. Must provide a value as a string or number");if(t=String(t),i.value=parseFloat(t),i.unit=t.match(/[\d.\-+]*\s*(.*)/)[1]||e,!c.includes(i.unit))throw new Error("Invalid unit provided.");return i}var f={ease:[.25,.1,.25,1],easeIn:[.42,0,1,1],easeOut:[0,0,.58,1],easeInOut:[.42,0,.58,1],easeInQuad:[.55,.085,.68,.53],easeInCubic:[.55,.055,.675,.19],easeInQuart:[.895,.03,.685,.22],easeInQuint:[.755,.05,.855,.06],easeInSine:[.47,0,.745,.715],easeInExpo:[.95,.05,.795,.035],easeInCirc:[.6,.04,.98,.335],easeOutQuad:[.25,.46,.45,.94],easeOutCubic:[.215,.61,.355,1],easeOutQuart:[.165,.84,.44,1],easeOutQuint:[.23,1,.32,1],easeOutSine:[.39,.575,.565,1],easeOutExpo:[.19,1,.22,1],easeOutCirc:[.075,.82,.165,1],easeInOutQuad:[.455,.03,.515,.955],easeInOutCubic:[.645,.045,.355,1],easeInOutQuart:[.77,0,.175,1],easeInOutQuint:[.86,0,.07,1],easeInOutSine:[.445,.05,.55,.95],easeInOutExpo:[1,0,0,1],easeInOutCirc:[.785,.135,.15,.86],easeInBack:[.6,-.28,.735,.045],easeOutBack:[.175,.885,.32,1.275],easeInOutBack:[.68,-.55,.265,1.55]};function v(t){if(Array.isArray(t))return l(t[0],t[1],t[2],t[3]);if("string"==typeof t&&void 0!==f[t]){var e=f[t];return l(e[0],e[1],e[2],e[3])}}var g=Object.values(exports.ValidCSSEffects),w={speed:"px",translateX:"%",translateY:"%",rotate:"deg",rotateX:"deg",rotateY:"deg",rotateZ:"deg",scale:"",scaleX:"",scaleY:"",scaleZ:"",opacity:""};function m(t,e){var i={};return g.forEach((function(s){var n=w[s];if("number"==typeof(null==t?void 0:t[s])){var r=null==t?void 0:t[s],l=-10*(r||0)+"px",a=p(10*(r||0)+"px"),o=p(l),h={start:a.value,end:o.value,unit:a.unit};e===exports.ScrollAxis.vertical&&(i.translateY=h),e===exports.ScrollAxis.horizontal&&(i.translateX=h)}if(Array.isArray(null==t?void 0:t[s])){var u=null==t?void 0:t[s];if(void 0!==u[0]&&void 0!==u[1]){var d=p(null==u?void 0:u[0],n),c=p(null==u?void 0:u[1],n),f=v(null==u?void 0:u[2]);if(i[s]={start:d.value,end:c.value,unit:d.unit,easing:f},d.unit!==c.unit)throw new Error("Must provide matching units for the min and max offset values of each axis.")}}})),i}function x(t,e,i,s){var n=(i-t)/e;return s&&(n=s(n)),n}function E(t,e,i){return i>=t&&i<=e}function _(t,e,i,s,n){return(i-e)*(t-s)/(n-s)+e}function C(t,e){return{value:_("function"==typeof t.easing?t.easing(e):e,(null==t?void 0:t.start)||0,(null==t?void 0:t.end)||0,0,1),unit:null==t?void 0:t.unit}}var S=Object.values(exports.ValidCSSEffects).filter((function(t){return"opacity"!==t}));function b(t,e,i){if(i){var s=function(t,e){return S.reduce((function(i,s){var n=t[s]&&C(t[s],e);return void 0===n||void 0===n.value||void 0===n.unit?i:i+(s+"(")+n.value+n.unit+")"}),"")}(t,e),n=function(t,e){var i=t.opacity&&C(t.opacity,e);return void 0===i||void 0===i.value||void 0===i.unit?"":""+i.value}(t,e);i.style.transform=s,i.style.opacity=n}}function y(t){var e=t.el;e&&(e.style.transform="",e.style.opacity="")}function I(t,e,i){var s=e>t,n=(Math.abs(t)+Math.abs(e))*(s?-1:1);return Math.max(i/(i+n),1)}function O(t,e){var i=t.start,s=t.end,n=t.unit;if("%"===n){var r=e/100;i*=r,s*=r}return"vw"===n&&(i=window.innerWidth*(i/100),s=window.innerWidth*(s/100)),"vh"===n&&(i=window.innerHeight*(i/100),s=window.innerHeight*(s/100)),{start:i,end:s}}var P={start:0,end:0,unit:""},A=function(t,e,i){return Math.min(Math.max(t,e),i)},X=function(){function t(t){var e,i;this.el=t.el,this.props=t.props,this.scrollAxis=t.scrollAxis,this.disabledParallaxController=t.disabledParallaxController||!1,this.id=u(),this.effects=m(this.props,this.scrollAxis),this.isInView=null,this.progress=0,this._setElementEasing(t.props.easing),e=t.el,i=Object.keys(this.effects).includes("opacity"),e.style.willChange="transform"+(i?",opacity":"")}var e=t.prototype;return e.updateProps=function(t){return this.props=o({},this.props,t),this.effects=m(t,this.scrollAxis),this._setElementEasing(t.easing),this},e.setCachedAttributes=function(t,e){y(this),this.rect=new d({el:this.props.targetElement||this.el,rootMargin:this.props.rootMargin,view:t});var i,s,n,r=(s=this.effects,n=this.scrollAxis,!((i=this.props).rootMargin||i.targetElement||i.shouldDisableScalingTranslations||!(s.translateX&&n===exports.ScrollAxis.horizontal||s.translateY&&n===exports.ScrollAxis.vertical)));return"number"==typeof this.props.startScroll&&"number"==typeof this.props.endScroll?(this.limits=new a({startX:this.props.startScroll,startY:this.props.startScroll,endX:this.props.endScroll,endY:this.props.endScroll}),this._setElementStyles(),this):(r?(this.limits=function(t,e,i,s,n,r){var l=i.translateY||P,o=O(i.translateX||P,t.width),h=o.start,u=o.end,d=O(l,t.height),c=d.start,p=d.end,f=t.top-e.height,v=t.left-e.width,g=t.bottom,w=t.right,m=1,x=1;n===exports.ScrollAxis.vertical&&(x=m=I(c,p,e.height+t.height));var E=1,_=1;if(n===exports.ScrollAxis.horizontal&&(_=E=I(h,u,e.width+t.width)),c<0&&(f+=c*m),p>0&&(g+=p*x),h<0&&(v+=h*E),u>0&&(w+=u*_),v+=s.x,w+=s.x,f+=s.y,g+=s.y,r){var C=s.y+t.top<e.height,S=s.x+t.left<e.width,b=s.y+t.bottom>e.scrollHeight-e.height,y=s.x+t.right>e.scrollWidth-e.height;C&&b&&(m=1,x=1,f=0,g=e.scrollHeight-e.height),S&&y&&(E=1,_=1,v=0,w=e.scrollWidth-e.width),!C&&b&&(m=I(c,p,(g=e.scrollHeight-e.height)-(f=t.top-e.height+s.y)),x=1,c<0&&(f+=c*m)),!S&&y&&(E=I(h,u,(w=e.scrollWidth-e.width)-(v=t.left-e.width+s.x)),_=1,h<0&&(v+=h*E)),C&&!b&&(m=1,x=I(c,p,(g=t.bottom+s.y)-(f=0)),p>0&&(g+=p*x)),S&&!y&&(E=1,_=I(h,u,(w=t.right+s.x)-(v=0)),u>0&&(w+=u*_))}return new a({startX:v,startY:f,endX:w,endY:g,startMultiplierX:E,endMultiplierX:_,startMultiplierY:m,endMultiplierY:x})}(this.rect,t,this.effects,e,this.scrollAxis,this.props.shouldAlwaysCompleteAnimation),this.scaledEffects=function(t,e){var i=o({},t);return i.translateX&&(i.translateX=o({},t.translateX,{start:i.translateX.start*e.startMultiplierX,end:i.translateX.end*e.endMultiplierX})),i.translateY&&(i.translateY=o({},t.translateY,{start:i.translateY.start*e.startMultiplierY,end:i.translateY.end*e.endMultiplierY})),i}(this.effects,this.limits)):this.limits=function(t,e,i,s){var n=t.top-e.height,r=t.left-e.width,l=t.bottom,o=t.right;return r+=i.x,o+=i.x,n+=i.y,l+=i.y,s&&(i.y+t.top<e.height&&(n=0),i.x+t.left<e.width&&(r=0),l>e.scrollHeight-e.height&&(l=e.scrollHeight-e.height),o>e.scrollWidth-e.width&&(o=e.scrollWidth-e.width)),new a({startX:r,startY:n,endX:o,endY:l})}(this.rect,t,e,this.props.shouldAlwaysCompleteAnimation),this._setElementStyles(),this)},e._updateElementIsInView=function(t){var e=null===this.isInView;t!==this.isInView&&(t?this.props.onEnter&&this.props.onEnter(this):e||(this._setFinalProgress(),this._setElementStyles(),this.props.onExit&&this.props.onExit(this))),this.isInView=t},e._setFinalProgress=function(){var t=A(Math.round(this.progress),0,1);this._updateElementProgress(t)},e._setElementStyles=function(){this.props.disabled||this.disabledParallaxController||b(this.scaledEffects||this.effects,this.progress,this.el)},e._updateElementProgress=function(t){this.progress=t,this.props.onProgressChange&&this.props.onProgressChange(this.progress),this.props.onChange&&this.props.onChange(this)},e._setElementEasing=function(t){this.easing=v(t)},e.updateElementOptions=function(t){this.scrollAxis=t.scrollAxis,this.disabledParallaxController=t.disabledParallaxController||!1},e.updatePosition=function(t){if(!this.limits)return this;var e=this.scrollAxis===exports.ScrollAxis.vertical,i=null===this.isInView,s=e?this.limits.startY:this.limits.startX,n=e?this.limits.totalY:this.limits.totalX,r=e?t.y:t.x,l=E(s,e?this.limits.endY:this.limits.endX,r);if(this._updateElementIsInView(l),l){var a=x(s,n,r,this.easing);this._updateElementProgress(a),this._setElementStyles()}else i&&(this.progress=A(Math.round(x(s,n,r,this.easing)),0,1),this._setElementStyles());return this},t}(),Y=function(){function t(t){this.scrollContainer=t.scrollContainer,this.width=t.width,this.height=t.height,this.scrollHeight=t.scrollHeight,this.scrollWidth=t.scrollWidth}var e=t.prototype;return e.hasChanged=function(t){return t.width!==this.width||t.height!==this.height||t.scrollWidth!==this.scrollWidth||t.scrollHeight!==this.scrollHeight},e.setSize=function(t){return this.width=t.width,this.height=t.height,this.scrollHeight=t.scrollHeight,this.scrollWidth=t.scrollWidth,this},t}(),M=function(){function t(t,e){this.x=t,this.y=e,this.dx=0,this.dy=0}return t.prototype.setScroll=function(t,e){return this.dx=t-this.x,this.dy=e-this.y,this.x=t,this.y=e,this},t}();function V(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){return t=!0,!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(t){}return t}var z=function(){function t(t){var e=t.scrollAxis,i=void 0===e?exports.ScrollAxis.vertical:e,s=t.scrollContainer,n=t.disabled;this.disabled=void 0!==n&&n,this.scrollAxis=i,this.elements=[],this._hasScrollContainer=!!s,this.viewEl=null!=s?s:window;var r=this._getScrollPosition();this.scroll=new M(r[0],r[1]),this.view=new Y({width:0,height:0,scrollWidth:0,scrollHeight:0,scrollContainer:this._hasScrollContainer?s:void 0}),this._ticking=!1,this._supportsPassive=V(),this._bindAllMethods(),this.disabled||(this._addListeners(this.viewEl),this._addResizeObserver(),this._setViewSize())}t.init=function(e){if("undefined"==typeof window)throw new Error("Looks like ParallaxController.init() was called on the server. This method must be called on the client.");return new t(e)};var e=t.prototype;return e._bindAllMethods=function(){var t=this;["_addListeners","_removeListeners","_getScrollPosition","_handleScroll","_handleUpdateCache","_updateAllElements","_updateElementPosition","_setViewSize","_addResizeObserver","_checkIfViewHasChanged","_getViewParams","getElements","createElement","removeElementById","resetElementStyles","updateElementPropsById","update","updateScrollContainer","destroy"].forEach((function(e){t[e]=t[e].bind(t)}))},e._addListeners=function(t){t.addEventListener("scroll",this._handleScroll,!!this._supportsPassive&&{passive:!0}),window.addEventListener("resize",this._handleUpdateCache,!1),window.addEventListener("blur",this._handleUpdateCache,!1),window.addEventListener("focus",this._handleUpdateCache,!1),window.addEventListener("load",this._handleUpdateCache,!1)},e._removeListeners=function(t){var e;t.removeEventListener("scroll",this._handleScroll,!1),window.removeEventListener("resize",this._handleUpdateCache,!1),window.removeEventListener("blur",this._handleUpdateCache,!1),window.removeEventListener("focus",this._handleUpdateCache,!1),window.removeEventListener("load",this._handleUpdateCache,!1),null==(e=this._resizeObserver)||e.disconnect()},e._addResizeObserver=function(){var t=this;try{var e=this._hasScrollContainer?this.viewEl:document.documentElement;this._resizeObserver=new ResizeObserver((function(){return t.update()})),this._resizeObserver.observe(e)}catch(t){console.warn("Failed to create the resize observer in the ParallaxContoller")}},e._getScrollPosition=function(){return[this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset]},e._handleScroll=function(){var t,e=this._getScrollPosition();this.scroll.setScroll(e[0],e[1]),!this._ticking&&(null==(t=this.elements)?void 0:t.length)>0&&(this._ticking=!0,window.requestAnimationFrame(this._updateAllElements))},e._handleUpdateCache=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},e._updateAllElements=function(t){var e=this,i=(void 0===t?{}:t).updateCache;this.elements&&this.elements.forEach((function(t){i&&t.setCachedAttributes(e.view,e.scroll),e._updateElementPosition(t)})),this._ticking=!1},e._updateElementPosition=function(t){t.props.disabled||this.disabled||t.updatePosition(this.scroll)},e._getViewParams=function(){if(this._hasScrollContainer)return this.view.setSize({width:this.viewEl.offsetWidth,height:this.viewEl.offsetHeight,scrollHeight:this.viewEl.scrollHeight,scrollWidth:this.viewEl.scrollWidth});var t=document.documentElement;return{width:window.innerWidth||t.clientWidth,height:window.innerHeight||t.clientHeight,scrollHeight:t.scrollHeight,scrollWidth:t.scrollWidth}},e._setViewSize=function(){return this.view.setSize(this._getViewParams())},e._checkIfViewHasChanged=function(){return this.view.hasChanged(this._getViewParams())},e.getElements=function(){return this.elements},e.createElement=function(t){var e=new X(o({},t,{scrollAxis:this.scrollAxis,disabledParallaxController:this.disabled}));return e.setCachedAttributes(this.view,this.scroll),this.elements=this.elements?[].concat(this.elements,[e]):[e],this._updateElementPosition(e),this._checkIfViewHasChanged()&&this.update(),e},e.removeElementById=function(t){this.elements&&(this.elements=this.elements.filter((function(e){return e.id!==t})))},e.updateElementPropsById=function(t,e){this.elements&&(this.elements=this.elements.map((function(i){return i.id===t?i.updateProps(e):i}))),this.update()},e.resetElementStyles=function(t){y(t)},e.update=function(){var t=this._getScrollPosition();this.scroll.setScroll(t[0],t[1]),this._setViewSize(),this._updateAllElements({updateCache:!0})},e.updateScrollContainer=function(t){this._removeListeners(this.viewEl),this.viewEl=t,this._hasScrollContainer=!!t,this.view=new Y({width:0,height:0,scrollWidth:0,scrollHeight:0,scrollContainer:t}),this._setViewSize(),this._addListeners(this.viewEl),this._updateAllElements({updateCache:!0})},e.disableParallaxController=function(){this.disabled=!0,this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return y(t)}))},e.enableParallaxController=function(){var t=this;this.disabled=!1,this.elements&&this.elements.forEach((function(e){return e.updateElementOptions({disabledParallaxController:!1,scrollAxis:t.scrollAxis})})),this._addListeners(this.viewEl),this._addResizeObserver(),this._setViewSize()},e.disableAllElements=function(){console.warn("deprecated: use disableParallaxController() instead"),this.elements&&(this.elements=this.elements.map((function(t){return t.updateProps({disabled:!0})}))),this.update()},e.enableAllElements=function(){console.warn("deprecated: use enableParallaxController() instead"),this.elements&&(this.elements=this.elements.map((function(t){return t.updateProps({disabled:!1})}))),this.update()},e.destroy=function(){this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return y(t)})),this.elements=void 0},t}();exports.Element=X,exports.Limits=a,exports.ParallaxController=z,exports.Rect=d,exports.Scroll=M,exports.View=Y,exports.createId=u,exports.getProgressAmount=x,exports.isElementInView=E,exports.parseElementTransitionEffects=m,exports.parseValueAndUnit=p,exports.resetStyles=y,exports.scaleBetween=_,exports.scaleEffectByProgress=C,exports.setElementStyles=b,exports.testForPassiveScroll=V;
//# sourceMappingURL=parallax-controller.cjs.production.min.js.map

@@ -1057,2 +1057,4 @@ import bezier from 'bezier-easing';

_proto._handleScroll = function _handleScroll() {
var _this$elements;
var _this$_getScrollPosit2 = this._getScrollPosition(),

@@ -1065,3 +1067,3 @@ nx = _this$_getScrollPosit2[0],

if (!this._ticking && this.elements.length > 0) {
if (!this._ticking && ((_this$elements = this.elements) == null ? void 0 : _this$elements.length) > 0) {
this._ticking = true; // @ts-ignore

@@ -1068,0 +1070,0 @@

{
"version": "1.7.0",
"version": "1.7.1",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -181,3 +181,3 @@ import { resetStyles } from '../helpers/elementStyles';

// completed and there are parallax elements to update
if (!this._ticking && this.elements.length > 0) {
if (!this._ticking && this.elements?.length > 0) {
this._ticking = true;

@@ -184,0 +184,0 @@ // @ts-ignore

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc