| 1 |
import { watch } from 'vue' |
| 2 |
import { useSettingsStore } from '@/stores/useSettingsStore' |
| 3 |
|
| 4 |
/** |
| 5 |
* Composable for managing WCAG-compliant color switching |
| 6 |
* Dynamically updates CSS classes based on WCAG backend compliance setting |
| 7 |
*/ |
| 8 |
export const useWcagColors = () => { |
| 9 |
const settingsStore = useSettingsStore() |
| 10 |
|
| 11 |
/** |
| 12 |
* Update CSS classes on document root based on WCAG compliance setting |
| 13 |
*/ |
| 14 |
const updateWcagClass = (useWcagColors: boolean) => { |
| 15 |
const root = document.documentElement |
| 16 |
|
| 17 |
if (useWcagColors) { |
| 18 |
// Add WCAG class to root element |
| 19 |
root.classList.add('wcag-compliant') |
| 20 |
} else { |
| 21 |
// Remove WCAG class from root element |
| 22 |
root.classList.remove('wcag-compliant') |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Initialize WCAG color system |
| 28 |
*/ |
| 29 |
const initializeWcagColors = () => { |
| 30 |
// Apply initial class based on current setting |
| 31 |
updateWcagClass(settingsStore.wcagBackendCompliance) |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Watch for changes in WCAG compliance setting |
| 36 |
*/ |
| 37 |
const startWatching = () => { |
| 38 |
return watch( |
| 39 |
() => settingsStore.wcagBackendCompliance, |
| 40 |
(newValue) => { |
| 41 |
updateWcagClass(newValue) |
| 42 |
}, |
| 43 |
{ immediate: true }, |
| 44 |
) |
| 45 |
} |
| 46 |
|
| 47 |
return { |
| 48 |
updateWcagClass, |
| 49 |
initializeWcagColors, |
| 50 |
startWatching, |
| 51 |
} |
| 52 |
} |
| 53 |
|