| 1 |
import { |
| 2 |
BG_SOURCE_ATTR, |
| 3 |
DESIGN_ROOT_ATTR, |
| 4 |
} from '@auto-launch/functions/tokens'; |
| 5 |
|
| 6 |
// A design may carry a variable this build predates; anything else is not ours. |
| 7 |
const DESIGN_VAR = /^--ext-(ui|tpl)-[a-z0-9-]+$/; |
| 8 |
|
| 9 |
let logo; |
| 10 |
|
| 11 |
// The design is read once before the first paint, so the parts read it from here. |
| 12 |
export const chooseLogo = (source) => { |
| 13 |
logo = source; |
| 14 |
}; |
| 15 |
|
| 16 |
export const activeLogo = () => logo; |
| 17 |
|
| 18 |
export const designRoot = () => document.querySelector(`[${DESIGN_ROOT_ATTR}]`); |
| 19 |
|
| 20 |
export const applyBgSource = (node, source) => { |
| 21 |
if (source) node.setAttribute(BG_SOURCE_ATTR, source); |
| 22 |
else node.removeAttribute(BG_SOURCE_ATTR); |
| 23 |
}; |
| 24 |
|
| 25 |
// Never on :root, or everything outside the flow is repainted with it. |
| 26 |
export const applyDesign = (node, design) => { |
| 27 |
if (!node || !design) return; |
| 28 |
for (const [name, value] of Object.entries(design.vars ?? {})) { |
| 29 |
if (DESIGN_VAR.test(name)) node.style.setProperty(name, value); |
| 30 |
} |
| 31 |
node.setAttribute(DESIGN_ROOT_ATTR, ''); |
| 32 |
applyBgSource(node, design.shader); |
| 33 |
}; |
| 34 |
|