(root: Element | null)
| 37 | * compositionLoader can compute the same defaults map for sub-comp instances. |
| 38 | */ |
| 39 | export function readDeclaredDefaults(root: Element | null): Record<string, unknown> { |
| 40 | if (!root) return {}; |
| 41 | const raw = root.getAttribute("data-composition-variables"); |
| 42 | if (!raw) return {}; |
| 43 | |
| 44 | let parsed: unknown; |
| 45 | try { |
| 46 | parsed = JSON.parse(raw); |
| 47 | } catch { |
| 48 | return {}; |
| 49 | } |
| 50 | if (!Array.isArray(parsed)) return {}; |
| 51 | |
| 52 | const out: Record<string, unknown> = {}; |
| 53 | for (const entry of parsed) { |
| 54 | if (!entry || typeof entry !== "object") continue; |
| 55 | const e = entry as Record<string, unknown>; |
| 56 | if (typeof e.id !== "string" || !("default" in e)) continue; |
| 57 | out[e.id] = e.default; |
| 58 | } |
| 59 | return out; |
| 60 | } |
| 61 | |
| 62 | function readOverrides(): Record<string, unknown> { |
| 63 | if (typeof window === "undefined") return {}; |
no test coverage detected