28 lines
846 B
JavaScript
28 lines
846 B
JavaScript
'use strict';
|
|
|
|
// Applies a color scheme using Beer CSS's dynamic theming, which derives a full
|
|
// Material 3 palette from a single seed color. `ui()` is provided by beer.min.js.
|
|
window.Theme = (function () {
|
|
async function apply(scheme) {
|
|
if (!scheme || typeof window.ui !== 'function') return;
|
|
try {
|
|
await window.ui('theme', scheme.seed_color);
|
|
window.ui('mode', scheme.mode === 'dark' ? 'dark' : 'light');
|
|
} catch (e) {
|
|
console.warn('Theme apply failed', e);
|
|
}
|
|
}
|
|
|
|
// Resolve the scheme to show: the user's preferred one, else the default.
|
|
function resolve(schemes, preferredId) {
|
|
if (!schemes || !schemes.length) return null;
|
|
return (
|
|
schemes.find((s) => s.id === preferredId) ||
|
|
schemes.find((s) => s.is_default) ||
|
|
schemes[0]
|
|
);
|
|
}
|
|
|
|
return { apply, resolve };
|
|
})();
|