import type { FlexElementContent } from '../core/types'; import type { CSSProperties } from 'vue'; // Constants export const spacingVarMap: Record = { 'none': 'var(--lumina-space-none, 0)', 'xs': 'var(--lumina-space-xs)', 'sm': 'var(--lumina-space-sm)', 'md': 'var(--lumina-space-md)', 'lg': 'var(--lumina-space-lg)', 'xl': 'var(--lumina-space-xl)', '2xl': 'var(--lumina-space-2xl)', '3xl': 'var(--lumina-space-3xl)', '4xl': 'var(--lumina-space-4xl)', }; export const sizeMap: Record = { 'auto': 'auto', 'quarter': '25%', 'third': '33.333%', 'half': '50%', 'two-thirds': '66.666%', 'three-quarters': '75%', 'full': '100%', }; export const valignMap: Record = { 'top': 'flex-start', 'Top': 'flex-start', 'center': 'center', 'Center': 'center', 'bottom': 'flex-end', 'Bottom': 'flex-end', }; export const halignMap: Record = { 'left': 'flex-start', 'Left': 'flex-start', 'center': 'center', 'Center': 'center', 'right': 'flex-end', 'Right': 'flex-end', }; // Helpers export const getSizeClass = (size?: string): string => { if (!size || size === 'auto') return 'flex-1'; return ''; }; export const getFlexItemStyle = (element: { size?: string }, directionVertical: boolean): CSSProperties => { const size = element.size || 'auto'; if (size === 'auto') return { flex: '1 1 auto' }; return { flex: `0 0 ${sizeMap[size]}`, maxWidth: !directionVertical ? sizeMap[size] : undefined, maxHeight: directionVertical ? sizeMap[size] : undefined, }; }; export const getFlexContainerStyle = (element: FlexElementContent): CSSProperties => { const valign = element.valign || 'center'; const halign = element.halign || 'left'; const gap = element.gap || 'md'; const padding = element.padding || 'lg'; const direction = element.direction || 'vertical'; return { display: 'flex', flexDirection: direction === 'horizontal' ? 'row' : 'column', justifyContent: direction === 'horizontal' ? halignMap[halign] as CSSProperties['justifyContent'] : valignMap[valign] as CSSProperties['justifyContent'], alignItems: direction === 'horizontal' ? valignMap[valign] as CSSProperties['alignItems'] : halignMap[halign] as CSSProperties['alignItems'], gap: spacingVarMap[gap], padding: spacingVarMap[padding], ...(element.style || {}), }; }; // Deprecated: kept for backward compat if needed, but we will update consumers export const getElementStyle = getFlexItemStyle; export const getContentStyle = (element: FlexElementContent & { size?: string }): CSSProperties => { // Legacy combined style return { ...getFlexItemStyle(element, false), // Default assumption ...getFlexContainerStyle(element) }; }; export const getTopLevelStyle = (): CSSProperties => ({ display: 'flex', alignItems: 'center', padding: spacingVarMap['lg'], }); /** * Alignment for the main flex slide container (all elements as a group). * When direction is horizontal: justify-content = halign, align-items = valign. * When direction is vertical: justify-content = valign, align-items = halign. */ export const getFlexSlideMainStyle = ( direction: 'horizontal' | 'vertical' | undefined, halign: string | undefined, valign: string | undefined ): CSSProperties => { const jc = direction === 'vertical' ? valignMap[valign || 'top'] : halignMap[halign || 'left']; const ai = direction === 'vertical' ? halignMap[halign || 'left'] : valignMap[valign || 'top']; return { justifyContent: jc as CSSProperties['justifyContent'], alignItems: ai as CSSProperties['alignItems'], }; }; export const getRoundedClass = (rounded?: string, fill?: boolean) => { if (fill !== false && !rounded) return 'w-full h-full'; const map: Record = { 'none': 'w-full h-full rounded-none', 'sm': 'w-full h-full rounded-sm', 'md': 'w-full h-full rounded-md', 'lg': 'w-full h-full rounded-lg', 'xl': 'w-full h-full rounded-xl', 'full': 'w-full h-full rounded-full', }; return map[rounded || 'lg'] || 'w-full h-full rounded-lg'; };