| 1 | type PresentationColorFields = { |
| 2 | color?: unknown; |
| 3 | }; |
| 4 | |
| 5 | function getColorFields(element: unknown): PresentationColorFields | undefined { |
| 6 | return typeof element === "object" && element !== null |
| 7 | ? (element as PresentationColorFields) |
| 8 | : undefined; |
| 9 | } |
| 10 | |
| 11 | export function getPresentationAccentColor( |
| 12 | element: unknown, |
| 13 | parentElement: unknown, |
| 14 | fallback: string, |
| 15 | ) { |
| 16 | const colorFields = getColorFields(element); |
| 17 | const parentColorFields = getColorFields(parentElement); |
| 18 | |
| 19 | if (typeof colorFields?.color === "string") return colorFields.color; |
| 20 | if (typeof parentColorFields?.color === "string") { |
| 21 | return parentColorFields.color; |
| 22 | } |
| 23 | return fallback; |
| 24 | } |
| 25 |