1 import { h, linearGradient } from "../../element.js"
2 import { logoDataUri } from "../../logo.js"
3 import { scaler } from "../../spec.js"
4 import type { BannerNode, DeepPartial } from "../../types.js"
5 import { CLOUD_CHANGELOG_SPEC, type CloudChangelogSpec } from "./spec.js"
6
7 export type CloudChangelogInput = {
8 type: "cloud-changelog"
9 /** Date shown after the wordmark, rendered as given — e.g. `Aug 17`. */
10 date: string
11 spec?: DeepPartial<CloudChangelogSpec>
12 }
13
14 /** Builds the Cloud changelog banner's element tree. */
15 export function buildCloudChangelog(
16 { date }: CloudChangelogInput,
17 spec: CloudChangelogSpec
18 ): BannerNode {
19 const px = scaler(spec, CLOUD_CHANGELOG_SPEC)
20 const { pill, content } = spec
21
22 const logo = logoDataUri({
23 height: px(content.logoHeight),
24 color: content.logoColor,
25 })
26
27 // Two inset shadows and a cast one, in the order the design layers them: the
28 // lit top edge, the ring around the whole pill, then the shadow it throws.
29 //
30 // The spread is clamped at zero because satori draws it as a stroke around
31 // the shadow's shape, and a negative one comes out as a negative
32 // `stroke-width` — which resvg does not reject but panics on.
33 const spread = Math.max(pill.shadowSpread, 0)
34 const shadow = [
35 `inset 0 ${px(pill.hairline)}px 0 ${pill.highlightColor}`,
36 `inset 0 0 0 ${px(pill.hairline)}px ${pill.ringColor}`,
37 `0 ${px(pill.shadowOffsetY)}px ${px(pill.shadowBlur)}px ` +
38 `${px(spread)}px ${pill.shadowColor}`,
39 ].join(", ")
40
41 return h(
42 "div",
43 {
44 style: {
45 width: spec.width,
46 height: spec.height,
47 display: "flex",
48 alignItems: "center",
49 justifyContent: "center",
50 backgroundColor: spec.background,
51 fontFamily: "Inter",
52 },
53 },
54 h(
55 "div",
56 {
57 style: {
58 display: "flex",
59 alignItems: "center",
60 height: px(pill.height),
61 paddingLeft: px(pill.paddingLeft),
62 paddingRight: px(pill.paddingRight),
63 borderRadius: 9999,
64 backgroundImage: linearGradient(pill.fillGradient),
65 boxShadow: shadow,
66 },
67 },
68 h("img", {
69 src: logo.src,
70 width: logo.width,
71 height: logo.height,
72 style: { marginRight: px(content.gap) },
73 }),
74 h(
75 "div",
76 {
77 style: {
78 display: "flex",
79 // Hug the glyphs, so the wordmark centres on the logomark rather
80 // than on the ascender and descender space around it.
81 lineHeight: 1,
82 fontSize: px(content.fontSize),
83 fontWeight: content.fontWeight,
84 letterSpacing: px(content.letterSpacing),
85 color: content.color,
86 },
87 },
88 content.wordmark
89 ),
90 h("div", {
91 style: {
92 display: "flex",
93 width: px(content.dividerWidth),
94 height: px(content.dividerHeight),
95 marginLeft: px(content.dividerMargin),
96 marginRight: px(content.dividerMargin),
97 backgroundColor: content.dividerColor,
98 },
99 }),
100 h(
101 "div",
102 {
103 style: {
104 display: "flex",
105 lineHeight: 1,
106 fontFamily: content.dateFontFamily,
107 fontSize: px(content.dateFontSize),
108 fontWeight: content.dateFontWeight,
109 letterSpacing: px(content.dateLetterSpacing),
110 color: content.dateColor,
111 },
112 },
113 date
114 )
115 )
116 )
117 }