import * as React from 'react' import {objectIsEmpty} from '../../utils/helpers' // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore because we're using an alias that TS doesn't know about. // TODO: fix this import animation from 'TEMPLATE/animation/index.js' import {AnimationScripts} from '../../components/AnimationScripts' /** * @category Types */ export interface AnimationBag { /** * An array of animation scripts that initialise the animation in various environments. */ scripts: React.ReactNode /** * A class name applied to the Body component containing `is-static` if an animated template's props contains `cancelAnimation: true`. */ bodyClassName: string } const builderConfig: GSDevTools.Vars = {hideGlobalTimeline: true, loop: false, minimal: true, visibility: `auto`} /** * * @param allTemplateProps - the props object passed to the template * @returns {@link AnimationBag} to be passed to {@link Body}’s {@link BodyProps.animation} prop * * @category Hooks * * @example * ```jsx * import {useAnimation} from '@/hooks/useAnimation' * * const Template = (props) => { * const animationBag = useAnimation(props) * return ( *
* {* your template here *} * * ``` */ export const useAnimation = ({ libs: {gsap, GSDevTools, ...libs} = {}, content = {}, /** * Setting this to false will disable the animation and set `is-static` on the body class. Which can be used to hide or show elements, thereby creating how the static version of the otherwise animated template should look. This is done through the Hucssley classes `is-static__visibility:visible` and `visibility:hidden` which you can set on elements that should be hidden prior to animation, but shown in the static version of the template. */ cancelAnimation = false, templateUrl = `./template`, gsapVersion, }: TemplateProps) => { // allow passing this flag from builder content or as regular prop const isStatic = content.cancelAnimation || cancelAnimation // store the running animation so it can be `kill`ed if user // toggles animation off from builder (via cancelAnimation) const [activeAnimation, setActiveAnimation] = React.useState