| 676 | // Convert a Context.dev `css` block ("background-color: #x; padding: 8px;") |
| 677 | // into a React style object so we can apply it without a raw <style> injection. |
| 678 | function cssTextToObject(css?: string): React.CSSProperties { |
| 679 | if (!css) return {}; |
| 680 | const out: Record<string, string> = {}; |
| 681 | for (const decl of css.split(";")) { |
| 682 | const idx = decl.indexOf(":"); |
| 683 | if (idx === -1) continue; |
| 684 | const prop = decl.slice(0, idx).trim(); |
| 685 | const val = decl.slice(idx + 1).trim(); |
| 686 | if (!prop || !val) continue; |
| 687 | const camel = prop.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()); |
| 688 | out[camel] = val; |
| 689 | } |
| 690 | return out as React.CSSProperties; |
| 691 | } |