()
| 20 | * const { title = "Untitled", theme = "light" } = getVariables<MyVars>(); |
| 21 | */ |
| 22 | export function getVariables< |
| 23 | T extends Record<string, unknown> = Record<string, unknown>, |
| 24 | >(): Partial<T> { |
| 25 | if (typeof document === "undefined") return {} as Partial<T>; |
| 26 | |
| 27 | const declaredDefaults = readDeclaredDefaults(document.documentElement); |
| 28 | const overrides = readOverrides(); |
| 29 | |
| 30 | return { ...declaredDefaults, ...overrides } as Partial<T>; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Extract `{id: default}` map from an element's `data-composition-variables` |
no test coverage detected