UNPKG

@trap_stevo/legendarybuilderproreact-ui

Version:

The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton

234 lines 11.9 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import * as React from "react"; import { useState, useRef, useCallback, useMemo } from "react"; import { motion } from "framer-motion"; import { useTimeout } from "../HUDManagers/HUDUniversalHUDEventEffectsManager.js"; function HUDShowcaseDeck(_ref) { var _ref$secondToTopCardC = _ref.secondToTopCardContainerConfigurationSettings, secondToTopCardContainerConfigurationSettings = _ref$secondToTopCardC === void 0 ? {} : _ref$secondToTopCardC, _ref$cardContainerTra = _ref.cardContainerTransitionConfigurationSettings, cardContainerTransitionConfigurationSettings = _ref$cardContainerTra === void 0 ? {} : _ref$cardContainerTra, _ref$cardContainerAni = _ref.cardContainerAnimationConfigurationSettings, cardContainerAnimationConfigurationSettings = _ref$cardContainerAni === void 0 ? {} : _ref$cardContainerAni, _ref$showcaseDeckCont = _ref.showcaseDeckContainerConfigurationSettings, showcaseDeckContainerConfigurationSettings = _ref$showcaseDeckCont === void 0 ? {} : _ref$showcaseDeckCont, _ref$topCardContainer = _ref.topCardContainerConfigurationSettings, topCardContainerConfigurationSettings = _ref$topCardContainer === void 0 ? {} : _ref$topCardContainer, _ref$cardContainerCon = _ref.cardContainerConfigurationSettings, cardContainerConfigurationSettings = _ref$cardContainerCon === void 0 ? {} : _ref$cardContainerCon, _ref$showcaseDeckCont2 = _ref.showcaseDeckContainerConfigurations, showcaseDeckContainerConfigurations = _ref$showcaseDeckCont2 === void 0 ? {} : _ref$showcaseDeckCont2, _ref$cardContainerCon2 = _ref.cardContainerConfigurations, cardContainerConfigurations = _ref$cardContainerCon2 === void 0 ? {} : _ref$cardContainerCon2, _ref$onCardAnimationC = _ref.onCardAnimationCompleted, onCardAnimationCompleted = _ref$onCardAnimationC === void 0 ? null : _ref$onCardAnimationC, _ref$onCardClicked = _ref.onCardClicked, onCardClicked = _ref$onCardClicked === void 0 ? null : _ref$onCardClicked, _ref$shuffleMode = _ref.shuffleMode, shuffleMode = _ref$shuffleMode === void 0 ? "sequential" : _ref$shuffleMode, _ref$layerXPositionin = _ref.layerXPositioningIntensity, layerXPositioningIntensity = _ref$layerXPositionin === void 0 ? 0.85 : _ref$layerXPositionin, _ref$layerYPositionin = _ref.layerYPositioningIntensity, layerYPositioningIntensity = _ref$layerYPositionin === void 0 ? 0.269 : _ref$layerYPositionin, _ref$layerBlurringInt = _ref.layerBlurringIntensity, layerBlurringIntensity = _ref$layerBlurringInt === void 0 ? 1 : _ref$layerBlurringInt, _ref$layerScalingInte = _ref.layerScalingIntensity, layerScalingIntensity = _ref$layerScalingInte === void 0 ? 1 : _ref$layerScalingInte, _ref$layerOpacityInte = _ref.layerOpacityIntensity, layerOpacityIntensity = _ref$layerOpacityInte === void 0 ? 1 : _ref$layerOpacityInte, _ref$layerRotationalO = _ref.layerRotationalOffset, layerRotationalOffset = _ref$layerRotationalO === void 0 ? 10 : _ref$layerRotationalO, _ref$cardClickDebounc = _ref.cardClickDebounce, cardClickDebounce = _ref$cardClickDebounc === void 0 ? 1000 : _ref$cardClickDebounc, _ref$xTranslationFann = _ref.xTranslationFanningFactor, xTranslationFanningFactor = _ref$xTranslationFann === void 0 ? 1.169 : _ref$xTranslationFann, _ref$xPositioningOffs = _ref.xPositioningOffset, xPositioningOffset = _ref$xPositioningOffs === void 0 ? 50 : _ref$xPositioningOffs, _ref$yPositioningOffs = _ref.yPositioningOffset, yPositioningOffset = _ref$yPositioningOffs === void 0 ? 2 : _ref$yPositioningOffs, _ref$rotationOffset = _ref.rotationOffset, rotationOffset = _ref$rotationOffset === void 0 ? -10 : _ref$rotationOffset, _ref$deckRotation = _ref.deckRotation, deckRotation = _ref$deckRotation === void 0 ? -20 : _ref$deckRotation, _ref$layout = _ref.layout, layout = _ref$layout === void 0 ? "fan" : _ref$layout, _ref$cards = _ref.cards, cards = _ref$cards === void 0 ? [] : _ref$cards; var _useTimeout = useTimeout(), schedule = _useTimeout.schedule; var _useState = useState(function () { return cards.map(function (_, index) { return index; }); }), _useState2 = _slicedToArray(_useState, 2), cardOrder = _useState2[0], setCardOrder = _useState2[1]; var cardClicked = useRef(false); var cardStyles = useMemo(function () { return { base: { position: "absolute", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", transition: "backdrop-filter 0.3s ease-in-out", transformOrigin: "center", borderRadius: "18px", background: "transparent", height: "269px", width: "369px" }, topCard: { boxShadow: "0 20px 50px rgba(0, 0, 0, 0.569)", height: "277.69px" }, secondToTop: { boxShadow: "0 15px 40px rgba(0, 0, 0, 0.469)" }, "default": { boxShadow: "0 10px 25px rgba(0, 0, 0, 0.2169)" } }; }, []); var handleCardClick = useCallback(function (clickedStackIndex) { if (cardClicked.current) { return; } cardClicked.current = true; schedule(function () { cardClicked.current = false; }, cardClickDebounce); var clickedOriginalIndex = cardOrder[clickedStackIndex]; var nextTopIndex = cardOrder[(clickedStackIndex + 1) % cardOrder.length]; setCardOrder(function (prevOrder) { var newOrder = _toConsumableArray(prevOrder); if (shuffleMode === "sequential") { newOrder = [].concat(_toConsumableArray(newOrder.slice(1)), [newOrder[0]]); nextTopIndex = newOrder[0]; } else if (shuffleMode === "selection") { if (clickedStackIndex === 0) { newOrder = [].concat(_toConsumableArray(newOrder.slice(1)), [newOrder[0]]); } else { var clickedCard = newOrder.splice(clickedStackIndex, 1)[0]; newOrder = [clickedCard].concat(_toConsumableArray(newOrder)); } nextTopIndex = newOrder[0]; } else if (shuffleMode === "random") { newOrder = newOrder.sort(function () { return Math.random() - 0.5; }); nextTopIndex = newOrder[0]; } else { var _clickedCard = newOrder.splice(clickedStackIndex, 1); newOrder.push(_clickedCard[0]); nextTopIndex = newOrder[0]; } return newOrder; }); onCardClicked === null || onCardClicked === void 0 || onCardClicked(nextTopIndex, clickedOriginalIndex); }, [schedule, shuffleMode, onCardClicked, cardClickDebounce]); var cardTransforms = useMemo(function () { return cardOrder.map(function (_, stackIndex) { var totalCards = cardOrder.length; var depthFactor = totalCards - stackIndex - 1; var topCard = stackIndex === 0; var secondToTop = stackIndex === 1; var translateX = depthFactor * xPositioningOffset * layerXPositioningIntensity; var translateY = depthFactor * layerYPositioningIntensity; var rotation = depthFactor * rotationOffset; var opacity = topCard ? 1 : secondToTop ? 0.98 : 1 - depthFactor * (0.12 * layerOpacityIntensity); var scale = topCard ? 1.1069 : secondToTop ? 1.069 : 1 - depthFactor * (0.05 * layerScalingIntensity); var blurEffect = topCard ? "none" : secondToTop ? "".concat(depthFactor * 1.1 * layerBlurringIntensity, "px") : "".concat(depthFactor * 1.5 * layerBlurringIntensity, "px"); if (layout === "fan") { translateX = depthFactor * xTranslationFanningFactor * xPositioningOffset; rotation = depthFactor * layerRotationalOffset; translateY = depthFactor * yPositioningOffset; } else if (layout === "carousel") { translateX = Math.sin(depthFactor * 0.5) * 80; translateY = Math.cos(depthFactor * 0.5) * 30; rotation = depthFactor * 4; } else if (layout === "grid") { var row = Math.floor(stackIndex / 2); var col = stackIndex % 2; translateX = col * 180 - 90; translateY = row * 180 - 90; rotation = 0; opacity = 1; scale = 1; } return { translateX: translateX, translateY: translateY, rotation: rotation, scale: scale, opacity: opacity, blurEffect: blurEffect, topCard: topCard, secondToTop: secondToTop }; }); }, [cardOrder, layout, xPositioningOffset, layerXPositioningIntensity, layerYPositioningIntensity, rotationOffset]); return /*#__PURE__*/React.createElement(motion.div, _extends({ animate: { rotate: deckRotation }, transition: { type: "spring", stiffness: 80, damping: 12 }, style: _objectSpread({ position: "relative", display: "flex", flexWrap: layout === "grid" ? "wrap" : "nowrap", justifyContent: "center", alignItems: "center", height: layout === "grid" ? "450px" : "320px", width: layout === "grid" ? "600px" : "420px" }, showcaseDeckContainerConfigurationSettings) }, showcaseDeckContainerConfigurations), cardOrder.map(function (originalIndex, stackIndex) { var _cardTransforms$stack = cardTransforms[stackIndex], translateX = _cardTransforms$stack.translateX, translateY = _cardTransforms$stack.translateY, rotation = _cardTransforms$stack.rotation, scale = _cardTransforms$stack.scale, opacity = _cardTransforms$stack.opacity, blurEffect = _cardTransforms$stack.blurEffect, topCard = _cardTransforms$stack.topCard, secondToTop = _cardTransforms$stack.secondToTop; return /*#__PURE__*/React.createElement(motion.div, _extends({ key: originalIndex, animate: _objectSpread({ rotate: rotation, x: translateX, y: translateY, scale: scale, opacity: opacity }, cardContainerAnimationConfigurationSettings), transition: _objectSpread({ type: "spring", stiffness: 140, damping: 18 }, cardContainerTransitionConfigurationSettings), onAnimationComplete: function onAnimationComplete() { return onCardAnimationCompleted === null || onCardAnimationCompleted === void 0 ? void 0 : onCardAnimationCompleted(originalIndex); }, style: _objectSpread(_objectSpread(_objectSpread({}, cardStyles.base), topCard ? cardStyles.topCard : secondToTop ? cardStyles.secondToTop : cardStyles["default"]), {}, { backdropFilter: "blur(".concat(blurEffect, ")"), zIndex: cardOrder.length - stackIndex }, topCard ? topCardContainerConfigurationSettings : secondToTop ? secondToTopCardContainerConfigurationSettings : cardContainerConfigurationSettings), onClick: function onClick() { return handleCardClick(stackIndex); } }, cardContainerConfigurations), cards[originalIndex]); })); } ; export default HUDShowcaseDeck;