parallax-controller
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,2 +0,2 @@ | ||
import { ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxStartEndOffsets } from '../types'; | ||
import { Rect } from './Rect'; | ||
@@ -3,0 +3,0 @@ import { View } from './View'; |
import { Bounds } from './Bounds'; | ||
import { Rect } from './Rect'; | ||
import { CreateElementOptions, ParallaxElementProperties, ParallaxStartEndOffsets, ValidScrollAxis } from '../index'; | ||
import { CreateElementOptions, ParallaxElementProperties, ParallaxStartEndOffsets, ValidScrollAxis } from '../types'; | ||
import { View } from './View'; | ||
@@ -5,0 +5,0 @@ import { Scroll } from './Scroll'; |
import { View } from './View'; | ||
import { Scroll } from './Scroll'; | ||
import { Element } from './Element'; | ||
import { CreateElementOptions, ParallaxControllerOptions, ParallaxElementProperties, ValidScrollAxis, ViewElement } from '../index'; | ||
import { CreateElementOptions, ParallaxControllerOptions, ParallaxElementProperties, ValidScrollAxis, ViewElement } from '../types'; | ||
/** | ||
@@ -6,0 +6,0 @@ * ------------------------------------------------------- |
import { Element } from '../classes/Element'; | ||
import { ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxStartEndOffsets } from '../types'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Takes a parallax element and set the styles based on the |
@@ -1,2 +0,2 @@ | ||
import { ParallaxElementProperties, ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxElementProperties, ParallaxStartEndOffsets } from '../types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Takes a parallax element and parses the offset props to get the value |
@@ -1,2 +0,2 @@ | ||
import { OffsetShape, ParallaxStartEndOffsets } from '../index'; | ||
import { OffsetShape, ParallaxStartEndOffsets } from '../types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Gets the parallax X and Y offsets to be applied to an element |
@@ -16,37 +16,3 @@ import { Bounds } from './classes/Bounds'; | ||
import { testForPassiveScroll } from './utils/testForPassiveScroll'; | ||
export * from './types'; | ||
export { Bounds, Element, ParallaxController, Rect, Scroll, View, setParallaxStyles, resetStyles, getOffsets, getParallaxOffsets, isElementInView, percentMoved, createId, parseValueAndUnit, scaleBetween, testForPassiveScroll, }; | ||
export declare type ParallaxStartEndOffsets = { | ||
xUnit: ValidUnits; | ||
yUnit: ValidUnits; | ||
translateX: OffsetShape[]; | ||
translateY: OffsetShape[]; | ||
}; | ||
export declare enum Units { | ||
'px' = "px", | ||
'%' = "%" | ||
} | ||
export declare enum ScrollAxis { | ||
'vertical' = "vertical", | ||
'horizontal' = "horizontal" | ||
} | ||
export declare type ValidScrollAxis = keyof typeof ScrollAxis; | ||
export declare type ValidUnits = keyof typeof Units; | ||
export declare type OffsetShape = { | ||
value: number; | ||
unit: ValidUnits; | ||
}; | ||
export declare type ViewElement = HTMLElement | Window; | ||
export declare type ParallaxControllerOptions = { | ||
scrollAxis?: ValidScrollAxis; | ||
scrollContainer?: HTMLElement; | ||
}; | ||
export declare type ParallaxElementProperties = { | ||
disabled?: boolean; | ||
translateX: string[] | number[]; | ||
translateY: string[] | number[]; | ||
}; | ||
export declare type CreateElementOptions = { | ||
elInner?: HTMLElement; | ||
elOuter?: HTMLElement; | ||
props: ParallaxElementProperties; | ||
}; |
@@ -85,4 +85,2 @@ 'use strict'; | ||
var VERTICAL = exports.ScrollAxis.vertical; | ||
var Rect = function Rect(el, view, scroll) { | ||
@@ -111,2 +109,12 @@ var rect = el.getBoundingClientRect(); // rect is based on viewport -- must adjust for relative scroll container | ||
(function (Units) { | ||
Units["px"] = "px"; | ||
Units["%"] = "%"; | ||
})(exports.Units || (exports.Units = {})); | ||
(function (ScrollAxis) { | ||
ScrollAxis["vertical"] = "vertical"; | ||
ScrollAxis["horizontal"] = "horizontal"; | ||
})(exports.ScrollAxis || (exports.ScrollAxis = {})); | ||
/** | ||
@@ -277,3 +285,3 @@ * Determines the unit of a string and parses the value | ||
this.percent = 0; | ||
this.updatePosition = options.scrollAxis === VERTICAL ? this._updatePositionVertical : this._updatePositionHorizontal; | ||
this.updatePosition = options.scrollAxis === exports.ScrollAxis.vertical ? this._updatePositionVertical : this._updatePositionHorizontal; | ||
} | ||
@@ -389,3 +397,3 @@ | ||
var _ref$scrollAxis = _ref.scrollAxis, | ||
scrollAxis = _ref$scrollAxis === void 0 ? VERTICAL : _ref$scrollAxis, | ||
scrollAxis = _ref$scrollAxis === void 0 ? exports.ScrollAxis.vertical : _ref$scrollAxis, | ||
scrollContainer = _ref.scrollContainer; | ||
@@ -677,12 +685,2 @@ this.scrollAxis = scrollAxis; // All parallax elements to be updated | ||
(function (Units) { | ||
Units["px"] = "px"; | ||
Units["%"] = "%"; | ||
})(exports.Units || (exports.Units = {})); | ||
(function (ScrollAxis) { | ||
ScrollAxis["vertical"] = "vertical"; | ||
ScrollAxis["horizontal"] = "horizontal"; | ||
})(exports.ScrollAxis || (exports.ScrollAxis = {})); | ||
exports.Bounds = Bounds; | ||
@@ -689,0 +687,0 @@ exports.Element = Element; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t,e,i){var s=e.translateY,n=s[0],r=s[1],o=e.translateX,l=o[0],h=o[1],a=n.value,u=r.value;if("%"===r.unit&&"%"===n.unit){var c=t.height/100;a=n.value*c,u=r.value*c}var d=l.value,p=h.value;if("%"===h.unit&&"%"===l.unit){var f=t.width/100;d=l.value*f,p=h.value*f}var v=Math.abs(a)+Math.abs(u);this.totalDistY=i.height+t.height+v;var w=i.height+t.height+(u>a?-1*v:v),m=Math.abs(d)+Math.abs(p);this.totalDistX=i.width+t.width+m;var g=t.originTotalDistY/w,_=t.originTotalDistX/(i.width+t.width+(p>d?-1*m:m));this.top=t.top,this.bottom=t.bottom,a<0&&(this.top=this.top+a*g),u>0&&(this.bottom=this.bottom+u*g),this.left=t.left,this.right=t.right,d<0&&(this.left=this.left+d*_),p>0&&(this.right=this.right+p*_)};function e(){return(e=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)}var i=exports.ScrollAxis.vertical,s=function(t,i,s){var n=t.getBoundingClientRect();if(i.scrollContainer){var r=i.scrollContainer.getBoundingClientRect();n=e({},n,{top:n.top-r.top,right:n.right-r.left,bottom:n.bottom-r.top,left:n.left-r.left})}this.height=t.offsetHeight,this.width=t.offsetWidth,this.left=n.left+s.x,this.right=n.right+s.x,this.top=n.top+s.y,this.bottom=n.bottom+s.y,this.originTotalDistY=i.height+this.height,this.originTotalDistX=i.width+this.width};function n(t,e){if(void 0===e&&(e={value:0,unit:"px"}),"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),e.value=parseFloat(t),e.unit=t.match(/[\d.\-\+]*\s*(.*)/)[1]||"%",!["px","%"].find((function(t){return t===e.unit})))throw new Error("Invalid unit provided. Must provide a unit of px in or %");return e}function r(t){var e=[n(t.translateY[0]),n(t.translateY[1])],i=[n(t.translateX[0]),n(t.translateX[1])];if(i[0].unit!==i[1].unit||e[0].unit!==e[1].unit)throw new Error("Must provide matching units for the min and max offset values of each axis.");return{xUnit:i[0].unit||"%",yUnit:e[0].unit||"%",translateY:e,translateX:i}}function o(t,e,i,s){var n=t-s,r=e-s;return n>=0&&n<=i||r>=0&&r<=i||n<=0&&r>=i}function l(t,e,i,s){return(-1*(t-s)+i)/e*100}function h(t,e,i,s,n){return(i-e)*(t-s)/(n-s)+e}function a(t,e){var i=t.translateY,s=t.translateX,n=t.yUnit,r=t.xUnit;return{x:{value:h(e,s[0].value,s[1].value,0,100),unit:r},y:{value:h(e,i[0].value,i[1].value,0,100),unit:n}}}function u(t,e,i){var s=a(e,i),n=s.x,r=s.y;t.style.transform="translate3d("+n.value+n.unit+", "+r.value+r.unit+", 0)"}function c(t){var e=t.elInner;e&&(e.style.transform="")}var d=0;function p(){return++d}var f=function(){function n(t){this.elInner=t.elInner,this.elOuter=t.elOuter,this.props=t.props,this.scrollAxis=t.scrollAxis,this.id=p(),this.offsets=r(this.props),this.isInView=null,this.percent=0,this.updatePosition=t.scrollAxis===i?this._updatePositionVertical:this._updatePositionHorizontal}var h=n.prototype;return h.updateProps=function(t){return this.props=e({},this.props,t),this.offsets=r(t),this},h.setCachedAttributes=function(e,i){return this.elOuter?(this.rect=new s(this.elOuter,e,i),this.bounds=new t(this.rect,this.offsets,e),this):this},h._updatePositionHorizontal=function(t,e){return this.bounds&&this.rect&&this.elInner?(this.isInView=o(this.bounds.left,this.bounds.right,t.width,e.x),this.isInView?(this.percent=l(this.rect.left,this.rect.originTotalDistX,t.width,e.x),u(this.elInner,this.offsets,this.percent),this):this):this},h._updatePositionVertical=function(t,e){return this.bounds&&this.rect&&this.elInner?(this.isInView=o(this.bounds.top,this.bounds.bottom,t.height,e.y),this.isInView?(this.percent=l(this.rect.top,this.rect.originTotalDistY,t.height,e.y),u(this.elInner,this.offsets,this.percent),this):this):this},n}(),v=function(){function t(t){var e=t.width,i=t.height;this.scrollContainer=t.scrollContainer,this.width=e,this.height=i}return t.prototype.setSize=function(t,e){return this.width=t,this.height=e,this},t}(),w=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.setScroll=function(t,e){return this.x=t,this.y=e,this},t}();function m(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(t){}return t}var g,_,x=function(){function t(t){var e=t.scrollAxis,s=t.scrollContainer;this.scrollAxis=void 0===e?i:e,this.elements=[],this._hasScrollContainer=!!s,this.viewEl=null!=s?s:window;var n=this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,r=this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset;this.scroll=new w(n,r),this.view=new v({width:0,height:0,scrollContainer:this._hasScrollContainer?s:void 0}),this._ticking=!1,this._supportsPassive=m(),this._bindAllMethods(),this._addListeners(this.viewEl),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 s=t.prototype;return s._bindAllMethods=function(){var t=this;["_addListeners","_removeListeners","_handleScroll","_handleResize","_updateAllElements","_updateElementPosition","_setViewSize","getElements","createElement","removeElementById","updateElementPropsById","resetElementStyles","update","updateScrollContainer","destroy"].forEach((function(e){t[e]=t[e].bind(t)}))},s._addListeners=function(t){t.addEventListener("scroll",this._handleScroll,!!this._supportsPassive&&{passive:!0}),window.addEventListener("resize",this._handleResize,!1)},s._removeListeners=function(t){t.removeEventListener("scroll",this._handleScroll,!1),window.removeEventListener("resize",this._handleResize,!1)},s._handleScroll=function(){var t=this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,e=this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset;this.scroll.setScroll(t,e),!this._ticking&&this.elements.length>0&&(this._ticking=!0,window.requestAnimationFrame(this._updateAllElements))},s._handleResize=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},s._updateAllElements=function(t){var e=this,i=(void 0===t?{}:t).updateCache;this.elements&&this.elements.forEach((function(t){e._updateElementPosition(t),i&&t.setCachedAttributes(e.view,e.scroll)})),this._ticking=!1},s._updateElementPosition=function(t){t.props.disabled||t.updatePosition(this.view,this.scroll)},s._setViewSize=function(){if(this._hasScrollContainer)return this.view.setSize(this.viewEl.offsetWidth,this.viewEl.offsetHeight);var t=document.documentElement,e=window.innerWidth||t.clientWidth,i=window.innerHeight||t.clientHeight;return this.view.setSize(e,i)},s.getElements=function(){return this.elements},s.createElement=function(t){var i=new f(e({},t,{scrollAxis:this.scrollAxis}));return i.setCachedAttributes(this.view,this.scroll),this.elements=this.elements?[].concat(this.elements,[i]):[i],this._updateElementPosition(i),i},s.removeElementById=function(t){this.elements&&(this.elements=this.elements.filter((function(e){return e.id!==t})))},s.updateElementPropsById=function(t,e){this.elements&&(this.elements=this.elements.map((function(i){return i.id===t?i.updateProps(e):i}))),this.update()},s.resetElementStyles=function(t){c(t)},s.update=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},s.updateScrollContainer=function(t){this._removeListeners(this.viewEl),this.viewEl=t,this._hasScrollContainer=!!t,this.view=new v({width:0,height:0,scrollContainer:t}),this._setViewSize(),this._addListeners(this.viewEl),this._updateAllElements({updateCache:!0})},s.destroy=function(){this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return c(t)})),this.elements=void 0},t}();(g=exports.Units||(exports.Units={})).px="px",g["%"]="%",(_=exports.ScrollAxis||(exports.ScrollAxis={})).vertical="vertical",_.horizontal="horizontal",exports.Bounds=t,exports.Element=f,exports.ParallaxController=x,exports.Rect=s,exports.Scroll=w,exports.View=v,exports.createId=p,exports.getOffsets=r,exports.getParallaxOffsets=a,exports.isElementInView=o,exports.parseValueAndUnit=n,exports.percentMoved=l,exports.resetStyles=c,exports.scaleBetween=h,exports.setParallaxStyles=u,exports.testForPassiveScroll=m; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t,e,i){var s=e.translateY,n=s[0],r=s[1],o=e.translateX,l=o[0],h=o[1],a=n.value,u=r.value;if("%"===r.unit&&"%"===n.unit){var c=t.height/100;a=n.value*c,u=r.value*c}var d=l.value,p=h.value;if("%"===h.unit&&"%"===l.unit){var f=t.width/100;d=l.value*f,p=h.value*f}var v=Math.abs(a)+Math.abs(u);this.totalDistY=i.height+t.height+v;var w=i.height+t.height+(u>a?-1*v:v),m=Math.abs(d)+Math.abs(p);this.totalDistX=i.width+t.width+m;var g=t.originTotalDistY/w,x=t.originTotalDistX/(i.width+t.width+(p>d?-1*m:m));this.top=t.top,this.bottom=t.bottom,a<0&&(this.top=this.top+a*g),u>0&&(this.bottom=this.bottom+u*g),this.left=t.left,this.right=t.right,d<0&&(this.left=this.left+d*x),p>0&&(this.right=this.right+p*x)};function e(){return(e=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)}var i,s,n=function(t,i,s){var n=t.getBoundingClientRect();if(i.scrollContainer){var r=i.scrollContainer.getBoundingClientRect();n=e({},n,{top:n.top-r.top,right:n.right-r.left,bottom:n.bottom-r.top,left:n.left-r.left})}this.height=t.offsetHeight,this.width=t.offsetWidth,this.left=n.left+s.x,this.right=n.right+s.x,this.top=n.top+s.y,this.bottom=n.bottom+s.y,this.originTotalDistY=i.height+this.height,this.originTotalDistX=i.width+this.width};function r(t,e){if(void 0===e&&(e={value:0,unit:"px"}),"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),e.value=parseFloat(t),e.unit=t.match(/[\d.\-\+]*\s*(.*)/)[1]||"%",!["px","%"].find((function(t){return t===e.unit})))throw new Error("Invalid unit provided. Must provide a unit of px in or %");return e}function o(t){var e=[r(t.translateY[0]),r(t.translateY[1])],i=[r(t.translateX[0]),r(t.translateX[1])];if(i[0].unit!==i[1].unit||e[0].unit!==e[1].unit)throw new Error("Must provide matching units for the min and max offset values of each axis.");return{xUnit:i[0].unit||"%",yUnit:e[0].unit||"%",translateY:e,translateX:i}}function l(t,e,i,s){var n=t-s,r=e-s;return n>=0&&n<=i||r>=0&&r<=i||n<=0&&r>=i}function h(t,e,i,s){return(-1*(t-s)+i)/e*100}function a(t,e,i,s,n){return(i-e)*(t-s)/(n-s)+e}function u(t,e){var i=t.translateY,s=t.translateX,n=t.yUnit,r=t.xUnit;return{x:{value:a(e,s[0].value,s[1].value,0,100),unit:r},y:{value:a(e,i[0].value,i[1].value,0,100),unit:n}}}function c(t,e,i){var s=u(e,i),n=s.x,r=s.y;t.style.transform="translate3d("+n.value+n.unit+", "+r.value+r.unit+", 0)"}function d(t){var e=t.elInner;e&&(e.style.transform="")}(i=exports.Units||(exports.Units={})).px="px",i["%"]="%",(s=exports.ScrollAxis||(exports.ScrollAxis={})).vertical="vertical",s.horizontal="horizontal";var p=0;function f(){return++p}var v=function(){function i(t){this.elInner=t.elInner,this.elOuter=t.elOuter,this.props=t.props,this.scrollAxis=t.scrollAxis,this.id=f(),this.offsets=o(this.props),this.isInView=null,this.percent=0,this.updatePosition=t.scrollAxis===exports.ScrollAxis.vertical?this._updatePositionVertical:this._updatePositionHorizontal}var s=i.prototype;return s.updateProps=function(t){return this.props=e({},this.props,t),this.offsets=o(t),this},s.setCachedAttributes=function(e,i){return this.elOuter?(this.rect=new n(this.elOuter,e,i),this.bounds=new t(this.rect,this.offsets,e),this):this},s._updatePositionHorizontal=function(t,e){return this.bounds&&this.rect&&this.elInner?(this.isInView=l(this.bounds.left,this.bounds.right,t.width,e.x),this.isInView?(this.percent=h(this.rect.left,this.rect.originTotalDistX,t.width,e.x),c(this.elInner,this.offsets,this.percent),this):this):this},s._updatePositionVertical=function(t,e){return this.bounds&&this.rect&&this.elInner?(this.isInView=l(this.bounds.top,this.bounds.bottom,t.height,e.y),this.isInView?(this.percent=h(this.rect.top,this.rect.originTotalDistY,t.height,e.y),c(this.elInner,this.offsets,this.percent),this):this):this},i}(),w=function(){function t(t){var e=t.width,i=t.height;this.scrollContainer=t.scrollContainer,this.width=e,this.height=i}return t.prototype.setSize=function(t,e){return this.width=t,this.height=e,this},t}(),m=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.setScroll=function(t,e){return this.x=t,this.y=e,this},t}();function g(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(t){}return t}var x=function(){function t(t){var e=t.scrollAxis,i=void 0===e?exports.ScrollAxis.vertical:e,s=t.scrollContainer;this.scrollAxis=i,this.elements=[],this._hasScrollContainer=!!s,this.viewEl=null!=s?s:window;var n=this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,r=this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset;this.scroll=new m(n,r),this.view=new w({width:0,height:0,scrollContainer:this._hasScrollContainer?s:void 0}),this._ticking=!1,this._supportsPassive=g(),this._bindAllMethods(),this._addListeners(this.viewEl),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 i=t.prototype;return i._bindAllMethods=function(){var t=this;["_addListeners","_removeListeners","_handleScroll","_handleResize","_updateAllElements","_updateElementPosition","_setViewSize","getElements","createElement","removeElementById","updateElementPropsById","resetElementStyles","update","updateScrollContainer","destroy"].forEach((function(e){t[e]=t[e].bind(t)}))},i._addListeners=function(t){t.addEventListener("scroll",this._handleScroll,!!this._supportsPassive&&{passive:!0}),window.addEventListener("resize",this._handleResize,!1)},i._removeListeners=function(t){t.removeEventListener("scroll",this._handleScroll,!1),window.removeEventListener("resize",this._handleResize,!1)},i._handleScroll=function(){var t=this._hasScrollContainer?this.viewEl.scrollLeft:window.pageXOffset,e=this._hasScrollContainer?this.viewEl.scrollTop:window.pageYOffset;this.scroll.setScroll(t,e),!this._ticking&&this.elements.length>0&&(this._ticking=!0,window.requestAnimationFrame(this._updateAllElements))},i._handleResize=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},i._updateAllElements=function(t){var e=this,i=(void 0===t?{}:t).updateCache;this.elements&&this.elements.forEach((function(t){e._updateElementPosition(t),i&&t.setCachedAttributes(e.view,e.scroll)})),this._ticking=!1},i._updateElementPosition=function(t){t.props.disabled||t.updatePosition(this.view,this.scroll)},i._setViewSize=function(){if(this._hasScrollContainer)return this.view.setSize(this.viewEl.offsetWidth,this.viewEl.offsetHeight);var t=document.documentElement,e=window.innerWidth||t.clientWidth,i=window.innerHeight||t.clientHeight;return this.view.setSize(e,i)},i.getElements=function(){return this.elements},i.createElement=function(t){var i=new v(e({},t,{scrollAxis:this.scrollAxis}));return i.setCachedAttributes(this.view,this.scroll),this.elements=this.elements?[].concat(this.elements,[i]):[i],this._updateElementPosition(i),i},i.removeElementById=function(t){this.elements&&(this.elements=this.elements.filter((function(e){return e.id!==t})))},i.updateElementPropsById=function(t,e){this.elements&&(this.elements=this.elements.map((function(i){return i.id===t?i.updateProps(e):i}))),this.update()},i.resetElementStyles=function(t){d(t)},i.update=function(){this._setViewSize(),this._updateAllElements({updateCache:!0})},i.updateScrollContainer=function(t){this._removeListeners(this.viewEl),this.viewEl=t,this._hasScrollContainer=!!t,this.view=new w({width:0,height:0,scrollContainer:t}),this._setViewSize(),this._addListeners(this.viewEl),this._updateAllElements({updateCache:!0})},i.destroy=function(){this._removeListeners(this.viewEl),this.elements&&this.elements.forEach((function(t){return d(t)})),this.elements=void 0},t}();exports.Bounds=t,exports.Element=v,exports.ParallaxController=x,exports.Rect=n,exports.Scroll=m,exports.View=w,exports.createId=f,exports.getOffsets=o,exports.getParallaxOffsets=u,exports.isElementInView=l,exports.parseValueAndUnit=r,exports.percentMoved=h,exports.resetStyles=d,exports.scaleBetween=a,exports.setParallaxStyles=c,exports.testForPassiveScroll=g; | ||
//# sourceMappingURL=parallax-controller.cjs.production.min.js.map |
@@ -81,4 +81,2 @@ var Bounds = function Bounds(rect, offsets, view) { | ||
var VERTICAL = ScrollAxis.vertical; | ||
var Rect = function Rect(el, view, scroll) { | ||
@@ -107,2 +105,16 @@ var rect = el.getBoundingClientRect(); // rect is based on viewport -- must adjust for relative scroll container | ||
var Units; | ||
(function (Units) { | ||
Units["px"] = "px"; | ||
Units["%"] = "%"; | ||
})(Units || (Units = {})); | ||
var ScrollAxis; | ||
(function (ScrollAxis) { | ||
ScrollAxis["vertical"] = "vertical"; | ||
ScrollAxis["horizontal"] = "horizontal"; | ||
})(ScrollAxis || (ScrollAxis = {})); | ||
/** | ||
@@ -273,3 +285,3 @@ * Determines the unit of a string and parses the value | ||
this.percent = 0; | ||
this.updatePosition = options.scrollAxis === VERTICAL ? this._updatePositionVertical : this._updatePositionHorizontal; | ||
this.updatePosition = options.scrollAxis === ScrollAxis.vertical ? this._updatePositionVertical : this._updatePositionHorizontal; | ||
} | ||
@@ -385,3 +397,3 @@ | ||
var _ref$scrollAxis = _ref.scrollAxis, | ||
scrollAxis = _ref$scrollAxis === void 0 ? VERTICAL : _ref$scrollAxis, | ||
scrollAxis = _ref$scrollAxis === void 0 ? ScrollAxis.vertical : _ref$scrollAxis, | ||
scrollContainer = _ref.scrollContainer; | ||
@@ -673,17 +685,3 @@ this.scrollAxis = scrollAxis; // All parallax elements to be updated | ||
var Units; | ||
(function (Units) { | ||
Units["px"] = "px"; | ||
Units["%"] = "%"; | ||
})(Units || (Units = {})); | ||
var ScrollAxis; | ||
(function (ScrollAxis) { | ||
ScrollAxis["vertical"] = "vertical"; | ||
ScrollAxis["horizontal"] = "horizontal"; | ||
})(ScrollAxis || (ScrollAxis = {})); | ||
export { Bounds, Element, ParallaxController, Rect, Scroll, ScrollAxis, Units, View, createId, getOffsets, getParallaxOffsets, isElementInView, parseValueAndUnit, percentMoved, resetStyles, scaleBetween, setParallaxStyles, testForPassiveScroll }; | ||
//# sourceMappingURL=parallax-controller.esm.js.map |
@@ -1,2 +0,2 @@ | ||
import { OffsetShape } from '../index'; | ||
import { OffsetShape } from '../types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Determines the unit of a string and parses the value |
{ | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,2 @@ | ||
import { ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxStartEndOffsets } from '../types'; | ||
import { Rect } from './Rect'; | ||
@@ -3,0 +3,0 @@ import { View } from './View'; |
@@ -5,3 +5,3 @@ import { Element } from './Element'; | ||
import { createElementMock } from '../testUtils/createElementMock'; | ||
import { ScrollAxis } from '../index'; | ||
import { ScrollAxis } from '../types'; | ||
@@ -8,0 +8,0 @@ const DEFAULT_OPTIONS = { |
@@ -1,2 +0,1 @@ | ||
import { VERTICAL } from '../constants'; | ||
import { Bounds } from './Bounds'; | ||
@@ -8,4 +7,5 @@ import { Rect } from './Rect'; | ||
ParallaxStartEndOffsets, | ||
ScrollAxis, | ||
ValidScrollAxis, | ||
} from '../index'; | ||
} from '../types'; | ||
import { getOffsets } from '../helpers/getOffsets'; | ||
@@ -47,3 +47,3 @@ import { isElementInView } from '../helpers/isElementInView'; | ||
this.updatePosition = | ||
options.scrollAxis === VERTICAL | ||
options.scrollAxis === ScrollAxis.vertical | ||
? this._updatePositionVertical | ||
@@ -50,0 +50,0 @@ : this._updatePositionHorizontal; |
@@ -5,3 +5,3 @@ import { ParallaxController } from './ParallaxController'; | ||
import { Bounds } from './Bounds'; | ||
import { VERTICAL } from '../constants'; | ||
import { ScrollAxis } from '..'; | ||
@@ -28,3 +28,5 @@ const addEventListener = window.addEventListener; | ||
it('to return an instance on init', () => { | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
expect(controller).toBeInstanceOf(ParallaxController); | ||
@@ -36,3 +38,5 @@ controller.destroy(); | ||
window.addEventListener = jest.fn(); | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
// @ts-ignore | ||
@@ -54,3 +58,5 @@ expect(window.addEventListener.mock.calls[0]).toEqual( | ||
it('to create an element and return it', () => { | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
const element = controller.createElement(OPTIONS); | ||
@@ -96,3 +102,5 @@ expect(element).toBeInstanceOf(Element); | ||
it('to add created elements into the controller', () => { | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
const element = controller.createElement(OPTIONS); | ||
@@ -106,3 +114,5 @@ const elements = controller.getElements(); | ||
it('to remove elements from the controller', () => { | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
const element = controller.createElement(OPTIONS); | ||
@@ -118,3 +128,5 @@ expect(controller.getElements()[0]).toEqual(element); | ||
window.removeEventListener = jest.fn(); | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
@@ -140,3 +152,5 @@ const incorrectOffsets = { | ||
window.removeEventListener = jest.fn(); | ||
const controller = ParallaxController.init({ scrollAxis: VERTICAL }); | ||
const controller = ParallaxController.init({ | ||
scrollAxis: ScrollAxis.vertical, | ||
}); | ||
// @ts-ignore | ||
@@ -143,0 +157,0 @@ expect(window.removeEventListener.mock.calls[0]).toEqual( |
@@ -5,3 +5,2 @@ import { resetStyles } from '../helpers/elementStyles'; | ||
import { Element } from './Element'; | ||
import { VERTICAL } from '../constants'; | ||
import { testForPassiveScroll } from '../utils/testForPassiveScroll'; | ||
@@ -12,5 +11,6 @@ import { | ||
ParallaxElementProperties, | ||
ScrollAxis, | ||
ValidScrollAxis, | ||
ViewElement, | ||
} from '../index'; | ||
} from '../types'; | ||
@@ -57,3 +57,3 @@ /** | ||
constructor({ | ||
scrollAxis = VERTICAL, | ||
scrollAxis = ScrollAxis.vertical, | ||
scrollContainer, | ||
@@ -60,0 +60,0 @@ }: ParallaxControllerOptions) { |
import { Element } from '../classes/Element'; | ||
import { ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxStartEndOffsets } from '../types'; | ||
import { getParallaxOffsets } from './getParallaxOffsets'; | ||
@@ -4,0 +4,0 @@ |
@@ -5,3 +5,3 @@ import { | ||
ParallaxStartEndOffsets, | ||
} from '../index'; | ||
} from '../types'; | ||
import { parseValueAndUnit } from '../utils/parseValueAndUnit'; | ||
@@ -8,0 +8,0 @@ |
import { getParallaxOffsets } from './getParallaxOffsets'; | ||
import { ParallaxStartEndOffsets } from '../index'; | ||
import { ParallaxStartEndOffsets } from '../types'; | ||
import { parseValueAndUnit } from '../utils/parseValueAndUnit'; | ||
@@ -4,0 +4,0 @@ import { scaleBetween } from '../utils/scaleBetween'; |
@@ -1,2 +0,2 @@ | ||
import { OffsetShape, ParallaxStartEndOffsets } from '../index'; | ||
import { OffsetShape, ParallaxStartEndOffsets } from '../types'; | ||
import { scaleBetween } from '../utils/scaleBetween'; | ||
@@ -3,0 +3,0 @@ |
@@ -7,2 +7,3 @@ import { Bounds } from './classes/Bounds'; | ||
import { View } from './classes/View'; | ||
import { setParallaxStyles, resetStyles } from './helpers/elementStyles'; | ||
@@ -13,2 +14,3 @@ import { getOffsets } from './helpers/getOffsets'; | ||
import { percentMoved } from './helpers/percentMoved'; | ||
import { createId } from './utils/createId'; | ||
@@ -19,2 +21,4 @@ import { parseValueAndUnit } from './utils/parseValueAndUnit'; | ||
export * from './types'; | ||
export { | ||
@@ -38,45 +42,1 @@ Bounds, | ||
}; | ||
export type ParallaxStartEndOffsets = { | ||
xUnit: ValidUnits; | ||
yUnit: ValidUnits; | ||
translateX: OffsetShape[]; | ||
translateY: OffsetShape[]; | ||
}; | ||
export enum Units { | ||
'px' = 'px', | ||
'%' = '%', | ||
} | ||
export enum ScrollAxis { | ||
'vertical' = 'vertical', | ||
'horizontal' = 'horizontal', | ||
} | ||
export type ValidScrollAxis = keyof typeof ScrollAxis; | ||
export type ValidUnits = keyof typeof Units; | ||
export type OffsetShape = { | ||
value: number; | ||
unit: ValidUnits; | ||
}; | ||
export type ViewElement = HTMLElement | Window; | ||
export type ParallaxControllerOptions = { | ||
scrollAxis?: ValidScrollAxis; | ||
scrollContainer?: HTMLElement; | ||
}; | ||
export type ParallaxElementProperties = { | ||
disabled?: boolean; | ||
translateX: string[] | number[]; | ||
translateY: string[] | number[]; | ||
}; | ||
export type CreateElementOptions = { | ||
elInner?: HTMLElement; | ||
elOuter?: HTMLElement; | ||
props: ParallaxElementProperties; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { OffsetShape } from '../index'; | ||
import { OffsetShape } from '../types'; | ||
@@ -3,0 +3,0 @@ /** |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3225
222813