Raw
1 import type { BannerNode, GradientStop } from "./types.js"
2
3 /** Element factory for the plain object tree satori consumes. */
4 export function h(
5 type: string,
6 props: Record<string, unknown> = {},
7 ...children: (BannerNode | string | false | null | undefined)[]
8 ): BannerNode {
9 // Conditional children are written inline as `condition && node`, so the
10 // falsy ones are dropped here rather than at every call site.
11 const kept = children.filter(Boolean) as (BannerNode | string)[]
12
13 return {
14 type,
15 props: {
16 ...props,
17 children: (kept.length > 1
18 ? kept
19 : kept[0]) as BannerNode["props"]["children"],
20 },
21 key: null,
22 }
23 }
24
25 export function linearGradient(
26 stops: GradientStop[],
27 angle = "180deg"
28 ): string {
29 const parts = stops.map(([offset, color]) => `${color} ${offset * 100}%`)
30
31 return `linear-gradient(${angle}, ${parts.join(", ")})`
32 }