import type { Theme } from "../theme/types"; import { mergeGuiProps } from "./mergeGuiProps"; type GuiPropRecord = Record; export type Sx = Partial | ((theme: Theme) => Partial) | undefined; function isSxResolver(sx: Sx): sx is (theme: Theme) => Partial { return typeIs(sx, "function"); } export function resolveSx(sx: Sx, theme: Theme): Partial { if (!sx) { return {}; } if (isSxResolver(sx)) { return sx(theme); } return sx; } export function mergeSx(...sxList: Array>): Sx { return (theme) => { let merged: Partial = {}; for (const sx of sxList) { const resolved = resolveSx(sx, theme); merged = mergeGuiProps(merged, resolved); } return merged; }; }