import { createSignal, createMemo, createEffect, Show, onCleanup } from 'solid-js'; import { useSettings } from '@util/context'; export default function Preview() { const { state, setState, settings } = useSettings(); // Calculate progress bar height based on thickness setting const progressbarHeight = createMemo(() => { const thickness = settings.progressbar_weight; if (thickness === 'thin') return '3px'; if (thickness === 'normal') return '7px'; if (thickness === 'large') return '12px'; if (thickness === 'custom') { const customValue = settings.progressbar_weight_custom || '7px'; // Validate custom value const validPattern = /^-?\d+(\.\d+)?(px|rem|em|%|vh|vw|vmin|vmax|ch|ex)$/i; return validPattern.test(customValue.trim()) ? customValue : '7px'; } // Fallback for old numeric values return thickness + 'px'; }); // Track animation class for preview const [animationClass, setAnimationClass] = createSignal(''); let animationTimeout = null; let animationTimeout2 = null; // Get duration value const getDuration = () => { const duration = settings.content_animation_duration; if (duration === 'custom') { return parseFloat(settings.content_animation_duration_custom) || 0.3; } return parseFloat(duration) || 0.3; }; // Function to stop current animation and start new one (out -> in sequence) const triggerAnimation = (animationName) => { if (!settings.content_animation || !animationName) { setAnimationClass(''); return; } // Clear any existing timeouts if (animationTimeout) { clearTimeout(animationTimeout); animationTimeout = null; } if (animationTimeout2) { clearTimeout(animationTimeout2); animationTimeout2 = null; } // Reset animation class immediately to stop current animation setAnimationClass(''); const duration = getDuration(); const halfDuration = (duration / 2) * 1000; // Use requestAnimationFrame to ensure DOM update happens before adding new class requestAnimationFrame(() => { // Phase 1: Out animation setAnimationClass(`ajaxpress-animate-${animationName}-out`); // Phase 2: In animation after out completes animationTimeout = setTimeout(() => { setAnimationClass(`ajaxpress-animate-${animationName}-in`); // Reset after in animation completes animationTimeout2 = setTimeout(() => { setAnimationClass(''); animationTimeout = null; animationTimeout2 = null; }, halfDuration); }, halfDuration); }); }; // Watch for content animation state changes (triggered by preview button) createEffect(() => { const contentAnimation = state.content_animation; if (contentAnimation && settings.content_animation) { triggerAnimation(contentAnimation); } else { // Clear animation if state is reset if (animationTimeout) { clearTimeout(animationTimeout); animationTimeout = null; } setAnimationClass(''); } }); // Watch for animation name changes - stop current and start new animation createEffect(() => { const animationName = settings.content_animation_name; if (settings.content_animation && animationName) { // Stop current animation and start new one immediately triggerAnimation(animationName); } }); // Cleanup on unmount onCleanup(() => { if (animationTimeout) { clearTimeout(animationTimeout); } if (animationTimeout2) { clearTimeout(animationTimeout2); } }); // Computed class for the preview content const contentClass = createMemo(() => { // Only show animation when explicitly triggered via preview button return animationClass(); }); // Computed styles for reactivity const contentWrapperStyle = createMemo(() => ({ cursor: settings.animate_cursor ? settings.cursor_mode : '', '--ajaxpress-animation-duration': (getDuration() / 2) + 's' })); const progressbarStyle = createMemo(() => ({ height: progressbarHeight(), 'background-color': !settings.progressbar_animate ? settings.progressbar_color : undefined, '--progressbar-color': settings.progressbar_color, '--animation-speed': (settings.progressbar_animation_speed || 1.5) + 's', opacity: (settings.progressbar_opacity || 100) / 100 })); const loaderBackdropStyle = createMemo(() => ({ 'background-color': settings.loader_background, opacity: (settings.loader_background_opacity || 100) / 100 })); const loaderWrapperStyle = createMemo(() => ({ gap: settings.loader_gap + 'px' })); const loaderImageStyle = createMemo(() => ({ width: settings.loader_image_size + 'px', transform: 'rotate(' + settings.loader_image_rotation + 'deg)' })); const loaderTextStyle = createMemo(() => ({ color: settings.loader_color, 'font-family': settings.loader_font_family, 'font-weight': settings.loader_font_weight, 'font-size': settings.loader_font_size + 'px', 'letter-spacing': settings.loader_letter_spacing + 'px' })); // Custom CSS for preview const customCSS = createMemo(() => { return settings.custom_css || ''; }); return (
{/* Inject custom CSS */}

How it will look like.

setState('isMobile', !state.isMobile)} class="ap-hidden min-[1080px]:ap-flex ap-items-center ap-bg-gray-100 ap-rounded ap-ring-4 ap-h-7 ap-text-sm ap-ring-slate-100 ap-relative ap-cursor-pointer" >
{/* Dummy Website Preview */}
{/* Header */}
{/* Hero Section */}
{/* Content */}
{/* Footer */}
{/* progress bar */}
{/* loader */}
{/* wrapper */}
{/* icon */} {/* text */}
); }