UNPKG

juq-llm-kit

Version:

Customizable UI components for React Native (Expo) chat applications

121 lines (120 loc) 4.83 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 }); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const framer_motion_1 = require("framer-motion"); const react_native_2 = require("react-native"); const moti_1 = require("moti"); const defaultPhrases = [ "loading...", "fetching data...", "calculating...", ]; const LoadingTextAnimation = ({ phrases = defaultPhrases, animationDuration = 3000, // 3 seconds for full animation cycle textStyle, containerStyle, fontFamily = "SpaceMono", theme = "dark" }) => { const [index, setIndex] = (0, react_1.useState)(0); // Get colors based on theme const textColor = theme === 'light' ? '#6b7280' : '#9CA3AF'; const bgColor = theme === 'light' ? '#f9fafb' : '#111827'; (0, react_1.useEffect)(() => { const interval = setInterval(() => { setIndex((prevIndex) => (prevIndex + 1) % phrases.length); }, animationDuration); return () => clearInterval(interval); }, [phrases, animationDuration]); if (react_native_1.Platform.OS !== 'web') { // Render native version return (<react_native_2.View style={[styles.container, containerStyle]}> <moti_1.MotiView key={index} from={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ type: 'timing', duration: 300 }}> <react_native_2.Animated.Text style={[ styles.text, { color: textColor, fontFamily: fontFamily, }, textStyle ]}> {phrases[index]} </react_native_2.Animated.Text> </moti_1.MotiView> </react_native_2.View>); } // Web version using Framer Motion return (<div style={Object.assign({ alignSelf: 'flex-start', paddingLeft: '24px' }, containerStyle)}> <framer_motion_1.AnimatePresence mode="wait"> <framer_motion_1.motion.div key={index} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.3 }} style={Object.assign({ fontSize: '18px', fontWeight: 400, color: textColor, whiteSpace: 'nowrap', overflow: 'hidden', fontFamily: fontFamily, lineHeight: '24px' }, textStyle)}> <div style={{ backgroundImage: `linear-gradient(to right, ${textColor} 0%, ${textColor} 40%, ${bgColor} 50%, ${textColor} 60%, ${textColor} 100%)`, WebkitBackgroundClip: 'text', backgroundClip: 'text', color: 'transparent', backgroundSize: '200% 100%', animation: `slide ${animationDuration / 1000}s linear infinite`, }}> {phrases[index]} </div> </framer_motion_1.motion.div> </framer_motion_1.AnimatePresence> <style>{` @keyframes slide { 0%, 100% { background-position: 100% 50%; } 93.33% { background-position: 0% 50%; } 93.34%, 99.99% { background-position: 100% 50%; } } `}</style> </div>); }; const styles = react_native_2.StyleSheet.create({ container: { alignSelf: 'flex-start', paddingLeft: 24, height: 24, }, text: { fontSize: 18, fontWeight: '400', textAlign: 'left', lineHeight: 24, }, }); exports.default = LoadingTextAnimation;