Socket
Socket
Sign inDemoInstall

react-scroll-parallax

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-scroll-parallax - npm Package Compare versions

Comparing version 3.0.0-beta.14 to 3.0.0-beta.15

dist/components/ParallaxBanner/components/ParallaxBannerLayer.d.ts

130

dist/react-scroll-parallax.cjs.development.js

@@ -220,23 +220,39 @@ 'use strict';

var _excluded$1 = ["disabled", "style", "layers"],
_excluded2 = ["children", "disabled", "style", "expanded", "image"];
var containerStyle = {
position: 'relative',
overflow: 'hidden',
width: '100%'
var FALLBACK_RECT = {
height: 0
};
var absoluteStyle = {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0
};
function getExpandedStyle(layer) {
if (Array.isArray(layer.translateY)) {
var translateYStart = parallaxController.parseValueAndUnit(layer.translateY[0]);
var translateYEnd = parallaxController.parseValueAndUnit(layer.translateY[1]);
function getExpandedStyle(expanded, layer) {
var speed = layer.speed || 0;
return expanded ? {
top: Math.abs(speed) * 10 * -1 + 'px',
bottom: Math.abs(speed) * 10 * -1 + 'px'
} : {};
if (translateYStart.unit === 'px' && translateYEnd.unit === 'px') {
return {
top: Math.abs(translateYEnd.value) * -1 + "px",
bottom: Math.abs(translateYStart.value) * -1 + "px"
};
}
if (translateYStart.unit === '%' && translateYEnd.unit === '%') {
var _layer$targetElement;
var clientRect = ((_layer$targetElement = layer.targetElement) == null ? void 0 : _layer$targetElement.getBoundingClientRect()) || FALLBACK_RECT;
var top = Math.abs(clientRect.height * 0.01 * translateYEnd.value) * -1;
var bottom = Math.abs(clientRect.height * 0.01 * translateYStart.value) * -1;
return {
top: top + "px",
bottom: bottom + "px"
};
}
}
if (layer.speed) {
var speed = layer.speed || 0;
return {
top: Math.abs(speed) * 10 * -1 + 'px',
bottom: Math.abs(speed) * 10 * -1 + 'px'
};
}
return {};
}

@@ -252,32 +268,64 @@

var _excluded$1 = ["children", "disabled", "style", "expanded", "image", "testId"];
var absoluteStyle = {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0
};
var ParallaxBannerLayer = function ParallaxBannerLayer(props) {
var _getIsolatedParallaxP = getIsolatedParallaxProps(props),
parallaxProps = _getIsolatedParallaxP.parallaxProps,
rest = _getIsolatedParallaxP.rest;
var style = rest.style,
_rest$expanded = rest.expanded,
expanded = _rest$expanded === void 0 ? true : _rest$expanded,
testId = rest.testId,
divProps = _objectWithoutPropertiesLoose(rest, _excluded$1);
var imageStyle = getImageStyle(props);
var expandedStyle = expanded ? getExpandedStyle(props) : {};
var parallax = useParallax(_extends({
targetElement: props.targetElement,
shouldDisableScalingTranslations: true
}, parallaxProps));
return React__default.createElement("div", Object.assign({
"data-testid": testId,
ref: parallax.ref,
style: _extends({}, imageStyle, absoluteStyle, expandedStyle, style)
}, divProps), rest.children);
};
var _excluded$2 = ["disabled", "style", "layers"];
var containerStyle = {
position: 'relative',
overflow: 'hidden',
width: '100%'
};
var ParallaxBanner = function ParallaxBanner(props) {
var _useState = React.useState(null),
targetElement = _useState[0],
setTargetElement = _useState[1];
var containerRef = React.useRef(null);
React.useEffect(function () {
setTargetElement(containerRef.current);
}, []);
var rootStyle = props.style,
_props$layers = props.layers,
layers = _props$layers === void 0 ? [] : _props$layers,
rootRest = _objectWithoutPropertiesLoose(props, _excluded$1);
rootRest = _objectWithoutPropertiesLoose(props, _excluded$2);
return React__default.createElement("div", Object.assign({
ref: containerRef,
style: _extends({}, containerStyle, rootStyle)
}, rootRest), layers.map(function (layer, i) {
var _getIsolatedParallaxP = getIsolatedParallaxProps(layer),
parallaxProps = _getIsolatedParallaxP.parallaxProps,
rest = _getIsolatedParallaxP.rest;
var style = rest.style,
_rest$expanded = rest.expanded,
expanded = _rest$expanded === void 0 ? true : _rest$expanded,
divProps = _objectWithoutPropertiesLoose(rest, _excluded2);
var key = "layer-" + i;
var imageStyle = getImageStyle(layer);
var expandedStyle = getExpandedStyle(expanded, layer);
var parallax = useParallax(_extends({
shouldDisableScalingTranslations: true
}, parallaxProps));
return React__default.createElement("div", Object.assign({
"data-testid": key,
key: key,
ref: parallax.ref,
style: _extends({}, imageStyle, absoluteStyle, expandedStyle, style)
}, divProps), rest.children);
return targetElement && React__default.createElement(ParallaxBannerLayer, Object.assign({}, layer, {
targetElement: targetElement,
key: "layer-" + i,
testId: "layer-" + i
}));
}), props.children);

@@ -284,0 +332,0 @@ };

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("parallax-controller"),r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}var s=["disabled","easing","endScroll","onChange","onEnter","onExit","onProgressChange","opacity","rootMargin","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","shouldAlwaysCompleteAnimation","shouldDisableScalingTranslations","speed","startScroll","targetElement","translateX","translateY"];function i(e){var t,r=e.disabled,n=e.easing,a=e.endScroll,o=e.onChange,i=e.onEnter,c=e.onExit,u=e.onProgressChange,d=e.opacity,p=e.rootMargin,f=e.rotate,h=e.rotateX,g=e.rotateY,x=e.rotateZ,y=e.scale,m=e.scaleX,v=e.scaleY,b=e.scaleZ,P=e.shouldAlwaysCompleteAnimation,E=e.shouldDisableScalingTranslations,C=e.speed,w=e.startScroll,S=e.targetElement,O=e.translateX,Y=e.translateY,j=l(e,s);return{parallaxProps:(t={disabled:r,easing:n,endScroll:a,onChange:o,onEnter:i,onExit:c,onProgressChange:u,opacity:d,rootMargin:p,rotate:f,rotateX:h,rotateY:g,rotateZ:x,scale:y,scaleX:m,scaleY:v,scaleZ:b,shouldAlwaysCompleteAnimation:P,shouldDisableScalingTranslations:E,speed:C,startScroll:w,targetElement:S,translateX:O,translateY:Y},Object.keys(t).forEach((function(e){return void 0===t[e]?delete t[e]:{}})),t),rest:j}}var c=n.createContext(null);function u(){var e=r.useContext(c);if("undefined"==typeof window)return null;if(!e)throw new Error("Could not find `react-scroll-parallax` context value. Please ensure the component is wrapped in a <ParallaxProvider>");return e}function d(e){var n=u(),a=r.useRef(null),o=i(e).parallaxProps;!function(e){r.useEffect((function(){if(!("undefined"==typeof window||e||e instanceof t.ParallaxController))throw new Error("Must wrap your application's <Parallax /> components in a <ParallaxProvider />.")}),[e])}(n);var l=r.useState(),s=l[0],c=l[1];return r.useEffect((function(){var e;if(!(a.current instanceof HTMLElement))throw new Error("You must assign the ref returned by the useParallax() hook to an HTML Element.");return e=null==n?void 0:n.createElement({el:a.current,props:o}),c(e),function(){e&&(null==n||n.removeElementById(e.id))}}),[]),r.useEffect((function(){s&&(e.disabled?null==n||n.resetElementStyles(s):null==n||n.updateElementPropsById(s.id,o))}),[e.disabled,e.easing,e.endScroll,e.onChange,e.onEnter,e.onExit,e.onProgressChange,e.opacity,e.rootMargin,e.rotate,e.rotateX,e.rotateY,e.rotateZ,e.scale,e.scaleX,e.scaleY,e.scaleZ,e.shouldAlwaysCompleteAnimation,e.shouldDisableScalingTranslations,e.speed,e.startScroll,e.targetElement,e.translateX,e.translateY]),{ref:a,controller:n,element:s}}var p=["disabled","style","layers"],f=["children","disabled","style","expanded","image"],h={position:"relative",overflow:"hidden",width:"100%"},g={position:"absolute",top:0,left:0,right:0,bottom:0},x=function(e){var r,a;function l(r){var n;return(n=e.call(this,r)||this).controller="undefined"==typeof window?null:t.ParallaxController.init({scrollAxis:r.scrollAxis,scrollContainer:r.scrollContainer}),n}a=e,(r=l).prototype=Object.create(a.prototype),r.prototype.constructor=r,o(r,a);var s=l.prototype;return s.componentDidUpdate=function(e){e.scrollContainer!==this.props.scrollContainer&&this.controller.updateScrollContainer(this.props.scrollContainer)},s.componentWillUnmount=function(){this.controller=this.controller.destroy()},s.render=function(){return n.createElement(c.Provider,{value:this.controller},this.props.children)},l}(r.Component);x.defaultProps={scrollAxis:t.ScrollAxis.vertical},Object.defineProperty(exports,"EasingPreset",{enumerable:!0,get:function(){return t.EasingPreset}}),exports.Parallax=function(e){var t=i(e),r=t.rest,a=d(t.parallaxProps);return n.createElement("div",Object.assign({ref:a.ref},r),e.children)},exports.ParallaxBanner=function(e){var t=e.style,r=e.layers,o=void 0===r?[]:r,s=l(e,p);return n.createElement("div",Object.assign({style:a({},h,t)},s),o.map((function(e,t){var r=i(e),o=r.parallaxProps,s=r.rest,c=s.style,u=s.expanded,p=void 0===u||u,h=l(s,f),x="layer-"+t,y=function(e){return e.image?{backgroundImage:"url("+e.image+")",backgroundPosition:"center",backgroundSize:"cover"}:{}}(e),m=function(e,t){var r=t.speed||0;return e?{top:10*Math.abs(r)*-1+"px",bottom:10*Math.abs(r)*-1+"px"}:{}}(p,e),v=d(a({shouldDisableScalingTranslations:!0},o));return n.createElement("div",Object.assign({"data-testid":x,key:x,ref:v.ref,style:a({},y,g,m,c)},h),s.children)})),e.children)},exports.ParallaxContext=c,exports.ParallaxProvider=x,exports.useParallax=d,exports.useParallaxController=u;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("parallax-controller"),r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}var s=["disabled","easing","endScroll","onChange","onEnter","onExit","onProgressChange","opacity","rootMargin","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","shouldAlwaysCompleteAnimation","shouldDisableScalingTranslations","speed","startScroll","targetElement","translateX","translateY"];function i(e){var t,r=e.disabled,n=e.easing,a=e.endScroll,o=e.onChange,i=e.onEnter,c=e.onExit,u=e.onProgressChange,d=e.opacity,p=e.rootMargin,f=e.rotate,h=e.rotateX,g=e.rotateY,x=e.rotateZ,v=e.scale,m=e.scaleX,y=e.scaleY,b=e.scaleZ,E=e.shouldAlwaysCompleteAnimation,P=e.shouldDisableScalingTranslations,C=e.speed,w=e.startScroll,S=e.targetElement,A=e.translateX,Y=e.translateY,O=l(e,s);return{parallaxProps:(t={disabled:r,easing:n,endScroll:a,onChange:o,onEnter:i,onExit:c,onProgressChange:u,opacity:d,rootMargin:p,rotate:f,rotateX:h,rotateY:g,rotateZ:x,scale:v,scaleX:m,scaleY:y,scaleZ:b,shouldAlwaysCompleteAnimation:E,shouldDisableScalingTranslations:P,speed:C,startScroll:w,targetElement:S,translateX:A,translateY:Y},Object.keys(t).forEach((function(e){return void 0===t[e]?delete t[e]:{}})),t),rest:O}}var c=n.createContext(null);function u(){var e=r.useContext(c);if("undefined"==typeof window)return null;if(!e)throw new Error("Could not find `react-scroll-parallax` context value. Please ensure the component is wrapped in a <ParallaxProvider>");return e}function d(e){var n=u(),a=r.useRef(null),o=i(e).parallaxProps;!function(e){r.useEffect((function(){if(!("undefined"==typeof window||e||e instanceof t.ParallaxController))throw new Error("Must wrap your application's <Parallax /> components in a <ParallaxProvider />.")}),[e])}(n);var l=r.useState(),s=l[0],c=l[1];return r.useEffect((function(){var e;if(!(a.current instanceof HTMLElement))throw new Error("You must assign the ref returned by the useParallax() hook to an HTML Element.");return e=null==n?void 0:n.createElement({el:a.current,props:o}),c(e),function(){e&&(null==n||n.removeElementById(e.id))}}),[]),r.useEffect((function(){s&&(e.disabled?null==n||n.resetElementStyles(s):null==n||n.updateElementPropsById(s.id,o))}),[e.disabled,e.easing,e.endScroll,e.onChange,e.onEnter,e.onExit,e.onProgressChange,e.opacity,e.rootMargin,e.rotate,e.rotateX,e.rotateY,e.rotateZ,e.scale,e.scaleX,e.scaleY,e.scaleZ,e.shouldAlwaysCompleteAnimation,e.shouldDisableScalingTranslations,e.speed,e.startScroll,e.targetElement,e.translateX,e.translateY]),{ref:a,controller:n,element:s}}var p={height:0},f=["children","disabled","style","expanded","image","testId"],h={position:"absolute",top:0,left:0,right:0,bottom:0},g=function(e){var r,o=i(e),s=o.parallaxProps,c=o.rest,u=c.style,g=c.expanded,x=void 0===g||g,v=c.testId,m=l(c,f),y=(r=e).image?{backgroundImage:"url("+r.image+")",backgroundPosition:"center",backgroundSize:"cover"}:{},b=x?function(e){if(Array.isArray(e.translateY)){var r=t.parseValueAndUnit(e.translateY[0]),n=t.parseValueAndUnit(e.translateY[1]);if("px"===r.unit&&"px"===n.unit)return{top:-1*Math.abs(n.value)+"px",bottom:-1*Math.abs(r.value)+"px"};if("%"===r.unit&&"%"===n.unit){var a,o=(null==(a=e.targetElement)?void 0:a.getBoundingClientRect())||p;return{top:-1*Math.abs(.01*o.height*n.value)+"px",bottom:-1*Math.abs(.01*o.height*r.value)+"px"}}}if(e.speed){var l=e.speed||0;return{top:10*Math.abs(l)*-1+"px",bottom:10*Math.abs(l)*-1+"px"}}return{}}(e):{},E=d(a({targetElement:e.targetElement,shouldDisableScalingTranslations:!0},s));return n.createElement("div",Object.assign({"data-testid":v,ref:E.ref,style:a({},y,h,b,u)},m),c.children)},x=["disabled","style","layers"],v={position:"relative",overflow:"hidden",width:"100%"},m=function(e){var r,a;function l(r){var n;return(n=e.call(this,r)||this).controller="undefined"==typeof window?null:t.ParallaxController.init({scrollAxis:r.scrollAxis,scrollContainer:r.scrollContainer}),n}a=e,(r=l).prototype=Object.create(a.prototype),r.prototype.constructor=r,o(r,a);var s=l.prototype;return s.componentDidUpdate=function(e){e.scrollContainer!==this.props.scrollContainer&&this.controller.updateScrollContainer(this.props.scrollContainer)},s.componentWillUnmount=function(){this.controller=this.controller.destroy()},s.render=function(){return n.createElement(c.Provider,{value:this.controller},this.props.children)},l}(r.Component);m.defaultProps={scrollAxis:t.ScrollAxis.vertical},Object.defineProperty(exports,"EasingPreset",{enumerable:!0,get:function(){return t.EasingPreset}}),exports.Parallax=function(e){var t=i(e),r=t.rest,a=d(t.parallaxProps);return n.createElement("div",Object.assign({ref:a.ref},r),e.children)},exports.ParallaxBanner=function(e){var t=r.useState(null),o=t[0],s=t[1],i=r.useRef(null);r.useEffect((function(){s(i.current)}),[]);var c=e.style,u=e.layers,d=void 0===u?[]:u,p=l(e,x);return n.createElement("div",Object.assign({ref:i,style:a({},v,c)},p),d.map((function(e,t){return o&&n.createElement(g,Object.assign({},e,{targetElement:o,key:"layer-"+t,testId:"layer-"+t}))})),e.children)},exports.ParallaxContext=c,exports.ParallaxProvider=m,exports.useParallax=d,exports.useParallaxController=u;
//# sourceMappingURL=react-scroll-parallax.cjs.production.min.js.map

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

import { ParallaxController, ScrollAxis } from 'parallax-controller';
import { ParallaxController, parseValueAndUnit, ScrollAxis } from 'parallax-controller';
export { EasingPreset } from 'parallax-controller';

@@ -214,23 +214,39 @@ import React, { useEffect, useContext, useRef, useState, Component } from 'react';

var _excluded$1 = ["disabled", "style", "layers"],
_excluded2 = ["children", "disabled", "style", "expanded", "image"];
var containerStyle = {
position: 'relative',
overflow: 'hidden',
width: '100%'
var FALLBACK_RECT = {
height: 0
};
var absoluteStyle = {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0
};
function getExpandedStyle(layer) {
if (Array.isArray(layer.translateY)) {
var translateYStart = parseValueAndUnit(layer.translateY[0]);
var translateYEnd = parseValueAndUnit(layer.translateY[1]);
function getExpandedStyle(expanded, layer) {
var speed = layer.speed || 0;
return expanded ? {
top: Math.abs(speed) * 10 * -1 + 'px',
bottom: Math.abs(speed) * 10 * -1 + 'px'
} : {};
if (translateYStart.unit === 'px' && translateYEnd.unit === 'px') {
return {
top: Math.abs(translateYEnd.value) * -1 + "px",
bottom: Math.abs(translateYStart.value) * -1 + "px"
};
}
if (translateYStart.unit === '%' && translateYEnd.unit === '%') {
var _layer$targetElement;
var clientRect = ((_layer$targetElement = layer.targetElement) == null ? void 0 : _layer$targetElement.getBoundingClientRect()) || FALLBACK_RECT;
var top = Math.abs(clientRect.height * 0.01 * translateYEnd.value) * -1;
var bottom = Math.abs(clientRect.height * 0.01 * translateYStart.value) * -1;
return {
top: top + "px",
bottom: bottom + "px"
};
}
}
if (layer.speed) {
var speed = layer.speed || 0;
return {
top: Math.abs(speed) * 10 * -1 + 'px',
bottom: Math.abs(speed) * 10 * -1 + 'px'
};
}
return {};
}

@@ -246,32 +262,64 @@

var _excluded$1 = ["children", "disabled", "style", "expanded", "image", "testId"];
var absoluteStyle = {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0
};
var ParallaxBannerLayer = function ParallaxBannerLayer(props) {
var _getIsolatedParallaxP = getIsolatedParallaxProps(props),
parallaxProps = _getIsolatedParallaxP.parallaxProps,
rest = _getIsolatedParallaxP.rest;
var style = rest.style,
_rest$expanded = rest.expanded,
expanded = _rest$expanded === void 0 ? true : _rest$expanded,
testId = rest.testId,
divProps = _objectWithoutPropertiesLoose(rest, _excluded$1);
var imageStyle = getImageStyle(props);
var expandedStyle = expanded ? getExpandedStyle(props) : {};
var parallax = useParallax(_extends({
targetElement: props.targetElement,
shouldDisableScalingTranslations: true
}, parallaxProps));
return React.createElement("div", Object.assign({
"data-testid": testId,
ref: parallax.ref,
style: _extends({}, imageStyle, absoluteStyle, expandedStyle, style)
}, divProps), rest.children);
};
var _excluded$2 = ["disabled", "style", "layers"];
var containerStyle = {
position: 'relative',
overflow: 'hidden',
width: '100%'
};
var ParallaxBanner = function ParallaxBanner(props) {
var _useState = useState(null),
targetElement = _useState[0],
setTargetElement = _useState[1];
var containerRef = useRef(null);
useEffect(function () {
setTargetElement(containerRef.current);
}, []);
var rootStyle = props.style,
_props$layers = props.layers,
layers = _props$layers === void 0 ? [] : _props$layers,
rootRest = _objectWithoutPropertiesLoose(props, _excluded$1);
rootRest = _objectWithoutPropertiesLoose(props, _excluded$2);
return React.createElement("div", Object.assign({
ref: containerRef,
style: _extends({}, containerStyle, rootStyle)
}, rootRest), layers.map(function (layer, i) {
var _getIsolatedParallaxP = getIsolatedParallaxProps(layer),
parallaxProps = _getIsolatedParallaxP.parallaxProps,
rest = _getIsolatedParallaxP.rest;
var style = rest.style,
_rest$expanded = rest.expanded,
expanded = _rest$expanded === void 0 ? true : _rest$expanded,
divProps = _objectWithoutPropertiesLoose(rest, _excluded2);
var key = "layer-" + i;
var imageStyle = getImageStyle(layer);
var expandedStyle = getExpandedStyle(expanded, layer);
var parallax = useParallax(_extends({
shouldDisableScalingTranslations: true
}, parallaxProps));
return React.createElement("div", Object.assign({
"data-testid": key,
key: key,
ref: parallax.ref,
style: _extends({}, imageStyle, absoluteStyle, expandedStyle, style)
}, divProps), rest.children);
return targetElement && React.createElement(ParallaxBannerLayer, Object.assign({}, layer, {
targetElement: targetElement,
key: "layer-" + i,
testId: "layer-" + i
}));
}), props.children);

@@ -278,0 +326,0 @@ };

{
"name": "react-scroll-parallax",
"version": "3.0.0-beta.14",
"version": "3.0.0-beta.15",
"description": "React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.",

@@ -5,0 +5,0 @@ "keywords": [

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

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