UNPKG

lightswind

Version:

A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.

82 lines 3.86 kB
"use strict"; "use client"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TypingText = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const framer_motion_1 = require("framer-motion"); const react_1 = __importStar(require("react")); const utils_1 = require("@/components/lib/utils"); const TypingText = ({ children, as: Component = "div", className = "", delay = 0, duration = 2, fontSize = "text-4xl", fontWeight = "font-bold", color = "text-white", letterSpacing = "tracking-wide", align = "left", loop = false, }) => { const [textContent, setTextContent] = (0, react_1.useState)(""); (0, react_1.useEffect)(() => { const extractText = (node) => { if (typeof node === "string" || typeof node === "number") { return node.toString(); } if (Array.isArray(node)) { return node.map(extractText).join(""); } if (react_1.default.isValidElement(node) && typeof node.props.children !== "undefined") { return extractText(node.props.children); } return ""; }; setTextContent(extractText(children)); }, [children]); const characters = textContent.split("").map((char) => char === " " ? "\u00A0" : char); const characterVariants = { hidden: { opacity: 0, scale: 0.95 }, visible: (i) => ({ opacity: 1, scale: 1, transition: { delay: delay + i * (duration / characters.length), duration: 0.3, ease: "easeInOut", }, }), }; return react_1.default.createElement(Component, { className: (0, utils_1.cn)("inline-flex", className, fontSize, fontWeight, color, letterSpacing, align === "center" ? "justify-center text-center" : align === "right" ? "justify-end text-right" : "justify-start text-left"), }, (0, jsx_runtime_1.jsx)(framer_motion_1.motion.span, { className: "inline-block", initial: "hidden", animate: "visible", "aria-label": textContent, role: "text", children: characters.map((char, index) => ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.span, { className: "inline-block", variants: characterVariants, custom: index, initial: "hidden", animate: "visible", children: char }, `${char}-${index}`))) })); }; exports.TypingText = TypingText; //# sourceMappingURL=typing-text.js.map