{"version":3,"file":"index.mjs","names":["newElement: Element | undefined","options: CreateElementOptions","absoluteStyle: CSSProperties","containerStyle: CSSProperties"],"sources":["../src/utils/removeUndefinedObjectKeys.ts","../src/helpers/getIsolatedParallaxProps.ts","../src/components/Parallax/hooks.ts","../src/context/ParallaxContext.ts","../src/hooks/useParallaxController.ts","../src/hooks/useParallax.ts","../src/components/Parallax/Parallax.tsx","../src/components/ParallaxBanner/helpers/getExpandedStyle.ts","../src/components/ParallaxBanner/helpers/getImageStyle.ts","../src/components/ParallaxBanner/components/ParallaxBannerLayer.tsx","../src/components/ParallaxBanner/ParallaxBanner.tsx","../src/components/ParallaxProvider/helpers.ts","../src/components/ParallaxProvider/ParallaxProvider.tsx"],"sourcesContent":["export function removeUndefinedObjectKeys(obj: { [key: string]: any }) {\n  Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);\n  return obj;\n}\n","import { ParallaxElementConfig } from 'parallax-controller';\nimport { removeUndefinedObjectKeys } from '../utils/removeUndefinedObjectKeys';\n\nexport function getIsolatedParallaxProps(\n  props: any\n): {\n  parallaxProps: ParallaxElementConfig;\n  rest: Record<string, any>;\n} {\n  const {\n    disabled,\n    easing,\n    endScroll,\n    onChange,\n    onEnter,\n    onExit,\n    onProgressChange,\n    opacity,\n    rootMargin,\n    rotate,\n    rotateX,\n    rotateY,\n    rotateZ,\n    scale,\n    scaleX,\n    scaleY,\n    scaleZ,\n    shouldAlwaysCompleteAnimation,\n    shouldDisableScalingTranslations,\n    speed,\n    startScroll,\n    targetElement,\n    translateX,\n    translateY,\n    ...rest\n  } = props;\n\n  const parallaxProps = removeUndefinedObjectKeys({\n    disabled,\n    easing,\n    endScroll,\n    onChange,\n    onEnter,\n    onExit,\n    onProgressChange,\n    opacity,\n    rootMargin,\n    rotate,\n    rotateX,\n    rotateY,\n    rotateZ,\n    scale,\n    scaleX,\n    scaleY,\n    scaleZ,\n    shouldAlwaysCompleteAnimation,\n    shouldDisableScalingTranslations,\n    speed,\n    startScroll,\n    targetElement,\n    translateX,\n    translateY,\n  });\n\n  return {\n    parallaxProps,\n    rest,\n  };\n}\n","import { ParallaxController } from 'parallax-controller';\nimport { useEffect } from 'react';\n\nexport function useVerifyController(controller: ParallaxController | unknown) {\n  useEffect(() => {\n    const isServer = typeof window === 'undefined';\n    // Make sure the provided controller is an instance of the Parallax Controller\n    const isInstance = controller instanceof ParallaxController;\n    // Throw if neither context or global is available\n    if (!isServer && !controller && !isInstance) {\n      throw new Error(\n        \"Must wrap your application's <Parallax /> components in a <ParallaxProvider />.\"\n      );\n    }\n  }, [controller]);\n}\n","import React from 'react';\nimport { ParallaxController } from 'parallax-controller';\n\nexport const ParallaxContext =\n  React.createContext<ParallaxController | null>(null);\n","import { useContext } from 'react';\nimport { ParallaxController } from 'parallax-controller';\nimport { ParallaxContext } from '../context/ParallaxContext';\n\nexport function useParallaxController(): ParallaxController | null {\n  const parallaxController = useContext(ParallaxContext);\n  const isServer = typeof window === 'undefined';\n  if (isServer) {\n    return null;\n  }\n\n  if (!parallaxController) {\n    throw new Error(\n      'Could not find `react-scroll-parallax` context value. Please ensure the component is wrapped in a <ParallaxProvider>'\n    );\n  }\n\n  return parallaxController;\n}\n","import { CreateElementOptions, Element } from 'parallax-controller';\nimport { useEffect, useRef, useState } from 'react';\nimport { useVerifyController } from '../components/Parallax/hooks';\nimport { ParallaxProps } from '../components/Parallax/types';\nimport { getIsolatedParallaxProps } from '../helpers/getIsolatedParallaxProps';\nimport { useParallaxController } from './useParallaxController';\n\nexport function useParallax<T extends HTMLElement>(props: ParallaxProps) {\n  const controller = useParallaxController();\n  const ref = useRef<T>(null);\n  const { parallaxProps } = getIsolatedParallaxProps(props);\n\n  useVerifyController(controller);\n\n  const [element, setElement] = useState<Element>();\n\n  // create element\n  useEffect(() => {\n    let newElement: Element | undefined;\n    if (ref.current instanceof HTMLElement) {\n      const options: CreateElementOptions = {\n        el: ref.current,\n        props: parallaxProps,\n      };\n      newElement = controller?.createElement(options);\n      setElement(newElement);\n    } else {\n      throw new Error(\n        'You must assign the ref returned by the useParallax() hook to an HTML Element.'\n      );\n    }\n\n    return () => {\n      if (newElement) {\n        controller?.removeElementById(newElement.id);\n      }\n    };\n  }, []);\n\n  // update element\n  useEffect(() => {\n    if (element) {\n      if (props.disabled) {\n        controller?.resetElementStyles(element);\n        controller?.updateElementPropsById(element.id, parallaxProps);\n      } else {\n        controller?.updateElementPropsById(element.id, parallaxProps);\n      }\n    }\n  }, [\n    props.disabled,\n    props.easing,\n    props.endScroll,\n    props.onChange,\n    props.onEnter,\n    props.onExit,\n    props.onProgressChange,\n    props.opacity,\n    props.rootMargin,\n    props.rotate,\n    props.rotateX,\n    props.rotateY,\n    props.rotateZ,\n    props.scale,\n    props.scaleX,\n    props.scaleY,\n    props.scaleZ,\n    props.shouldAlwaysCompleteAnimation,\n    props.shouldDisableScalingTranslations,\n    props.speed,\n    props.startScroll,\n    props.targetElement,\n    props.translateX,\n    props.translateY,\n  ]);\n\n  return { ref, controller, element };\n}\n","import React, { PropsWithChildren } from 'react';\nimport { getIsolatedParallaxProps } from '../../helpers/getIsolatedParallaxProps';\nimport { useParallax } from '../../hooks/useParallax';\nimport { ParallaxProps } from './types';\n\nexport function Parallax(props: PropsWithChildren<ParallaxProps>) {\n  const { parallaxProps, rest } = getIsolatedParallaxProps(props);\n  const { ref } = useParallax<HTMLDivElement>(parallaxProps);\n  return (\n    <div ref={ref} {...rest}>\n      {props.children}\n    </div>\n  );\n}\n","import { parseValueAndUnit } from 'parallax-controller';\nimport { BannerLayer } from '../types';\n\nconst FALLBACK_RECT = {\n  height: 0,\n};\n\ntype ExpandedStyle = {\n  top?: string;\n  bottom?: string;\n};\n\nexport function getExpandedStyle(layer: BannerLayer): ExpandedStyle {\n  if (Array.isArray(layer.translateY)) {\n    const translateYStart = parseValueAndUnit(layer.translateY[0]);\n    const translateYEnd = parseValueAndUnit(layer.translateY[1]);\n\n    if (translateYStart.unit === 'px' && translateYEnd.unit === 'px') {\n      return {\n        top: `${Math.abs(translateYEnd.value) * -1}px`,\n        bottom: `${Math.abs(translateYStart.value) * -1}px`,\n      };\n    }\n\n    if (translateYStart.unit === '%' && translateYEnd.unit === '%') {\n      const clientRect =\n        layer.targetElement?.getBoundingClientRect() ?? FALLBACK_RECT;\n      const top = Math.abs(clientRect.height * 0.01 * translateYEnd.value) * -1;\n      const bottom =\n        Math.abs(clientRect.height * 0.01 * translateYStart.value) * -1;\n      return {\n        top: `${top}px`,\n        bottom: `${bottom}px`,\n      };\n    }\n  }\n\n  if (layer.speed) {\n    const speed = layer.speed || 0;\n    const absSpeed = Math.abs(speed) * 10 * -1;\n\n    return {\n      top: `${absSpeed}px`,\n      bottom: `${absSpeed}px`,\n    };\n  }\n\n  return {};\n}\n","import { BannerLayer } from '../types';\n\nexport function getImageStyle(layer: BannerLayer) {\n  return layer.image\n    ? {\n        backgroundImage: `url(${layer.image})`,\n        backgroundPosition: 'center',\n        backgroundSize: 'cover',\n      }\n    : {};\n}\n","import React, { CSSProperties } from 'react';\nimport { useParallax } from '../../../hooks/useParallax';\nimport { getIsolatedParallaxProps } from '../../../helpers/getIsolatedParallaxProps';\nimport { getExpandedStyle } from '../helpers/getExpandedStyle';\nimport { getImageStyle } from '../helpers/getImageStyle';\nimport { BannerLayer } from '../types';\n\nconst absoluteStyle: CSSProperties = {\n  position: 'absolute',\n  top: 0,\n  left: 0,\n  right: 0,\n  bottom: 0,\n};\n\nexport const ParallaxBannerLayer = (\n  props: BannerLayer & { testId?: string }\n) => {\n  const { parallaxProps, rest } = getIsolatedParallaxProps(props);\n  const {\n    children,\n    disabled,\n    style,\n    expanded = true,\n    image,\n    testId,\n    ...divProps\n  } = rest;\n\n  const imageStyle = getImageStyle(props);\n  const expandedStyle = expanded ? getExpandedStyle(props) : {};\n  const parallax = useParallax<HTMLDivElement>({\n    targetElement: props.targetElement,\n    shouldDisableScalingTranslations: true,\n    ...parallaxProps,\n  });\n\n  return (\n    <div\n      data-testid={testId}\n      ref={parallax.ref}\n      style={{\n        ...imageStyle,\n        ...absoluteStyle,\n        ...expandedStyle,\n        ...style,\n      }}\n      {...divProps}\n    >\n      {rest.children}\n    </div>\n  );\n};\n","import React, {\n  PropsWithChildren,\n  CSSProperties,\n  useEffect,\n  useRef,\n  useState,\n  ReactElement,\n} from 'react';\nimport { ParallaxBannerLayer } from './components/ParallaxBannerLayer';\nimport { ParallaxBannerProps } from './types';\n\nconst containerStyle: CSSProperties = {\n  position: 'relative',\n  overflow: 'hidden',\n  width: '100%',\n};\n\nexport const ParallaxBanner = (\n  props: PropsWithChildren<ParallaxBannerProps>\n) => {\n  const [targetElement, setTargetElement] =\n    useState<HTMLDivElement | null>(null);\n  const containerRef = useRef<HTMLDivElement>(null);\n  useEffect(() => {\n    setTargetElement(containerRef.current);\n  }, []);\n  const {\n    disabled: disableAllLayers,\n    style: rootStyle,\n    layers = [],\n    ...rootRest\n  } = props;\n\n  function renderLayers() {\n    if (targetElement) {\n      const shouldUseLayers = layers && layers.length > 0;\n      if (shouldUseLayers) {\n        return layers.map((layer, i) => (\n          <ParallaxBannerLayer\n            {...layer}\n            targetElement={targetElement}\n            key={`layer-${i}`}\n            testId={`layer-${i}`}\n          />\n        ));\n      }\n    }\n    return null;\n  }\n\n  function renderChildren() {\n    if (targetElement) {\n      return React.Children.map(props.children, (child) => {\n        const item = child as ReactElement<\n          PropsWithChildren<{ targetElement: any }>\n        >;\n        // adds the targetElement prop to any ParallaxBannerLayer components\n        if (item?.type === ParallaxBannerLayer) {\n          const clone = React.cloneElement(item, {\n            targetElement,\n          });\n          return clone;\n        }\n        return child;\n      });\n    }\n    return null;\n  }\n  return (\n    <div\n      ref={containerRef}\n      style={{ ...containerStyle, ...rootStyle }}\n      {...rootRest}\n    >\n      {/* Using the `layers` prop to define children */}\n      {renderLayers()}\n      {/* Using children to compose layers */}\n      {renderChildren()}\n    </div>\n  );\n};\n","import {\n  ParallaxController,\n  ParallaxControllerOptions,\n} from 'parallax-controller';\n\nexport const createController = (options: ParallaxControllerOptions) => {\n  // Don't initialize on the server\n  const isServer = typeof window === 'undefined';\n\n  if (!isServer) {\n    // Must not be the server so kick it off...\n    return ParallaxController.init(options);\n  }\n  return null;\n};\n","import React, { PropsWithChildren, useEffect, useRef } from 'react';\n\nimport { ParallaxContext } from '../../context/ParallaxContext';\nimport { ParallaxController, ScrollAxis } from 'parallax-controller';\nimport { ParallaxProviderProps } from './types';\nimport { createController } from './helpers';\n\nexport function ParallaxProvider(\n  props: PropsWithChildren<ParallaxProviderProps>\n) {\n  const controller = useRef<null | ParallaxController>(null);\n\n  if (!controller.current) {\n    controller.current = createController({\n      scrollAxis: props.scrollAxis || ScrollAxis.vertical,\n      scrollContainer: props.scrollContainer,\n      disabled: props.isDisabled,\n    });\n  }\n\n  // update scroll container\n  useEffect(() => {\n    if (props.scrollContainer && controller.current) {\n      controller.current.updateScrollContainer(props.scrollContainer);\n    }\n  }, [props.scrollContainer]);\n\n  // disable/enable parallax\n  useEffect(() => {\n    if (props.isDisabled && controller.current) {\n      controller.current.disableParallaxController();\n    }\n    if (!props.isDisabled && controller.current) {\n      controller.current.enableParallaxController();\n    }\n  }, [props.isDisabled]);\n\n  // remove the controller when unmounting\n  useEffect(() => {\n    return () => {\n      controller?.current?.destroy();\n    };\n  }, []);\n\n  return (\n    <ParallaxContext.Provider value={controller.current}>\n      {props.children}\n    </ParallaxContext.Provider>\n  );\n}\n"],"mappings":";;;;AAAA,SAAgB,0BAA0B,KAA6B;AACrE,QAAO,KAAK,IAAI,CAAC,SAAS,QAAQ,IAAI,SAAS,UAAa,OAAO,IAAI,KAAK;AAC5E,QAAO;;;;;ACCT,SAAgB,yBACd,OAIA;CACA,MAAM,EACJ,UACA,QACA,WACA,UACA,SACA,QACA,kBACA,SACA,YACA,QACA,SACA,SACA,SACA,OACA,QACA,QACA,QACA,+BACA,kCACA,OACA,aACA,eACA,YACA,WACA,GAAG,SACD;AA6BJ,QAAO;EACL,eA5BoB,0BAA0B;GAC9C;GACA;GACA;GACA;GAC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