|
1
|
import { h, linearGradient } from "../../element.js" |
|
2
|
import { logoDataUri } from "../../logo.js" |
|
3
|
import { scaler } from "../../spec.js" |
|
4
|
import type { BannerNode, DeepPartial, StyleObject } from "../../types.js" |
|
5
|
import { RELEASE_SPEC, type ReleaseSpec } from "./spec.js" |
|
6
|
|
|
7
|
export type ReleaseInput = { |
|
8
|
type: "release" |
|
9
|
/** Version label rendered inside the pill, e.g. `v2.19.0`. */ |
|
10
|
version: string |
|
11
|
spec?: DeepPartial<ReleaseSpec> |
|
12
|
} |
|
13
|
|
|
14
|
/** Builds the release banner's element tree. */ |
|
15
|
export function buildRelease( |
|
16
|
{ version }: ReleaseInput, |
|
17
|
spec: ReleaseSpec |
|
18
|
): BannerNode { |
|
19
|
const px = scaler(spec, RELEASE_SPEC) |
|
20
|
|
|
21
|
const logo = logoDataUri({ |
|
22
|
height: px(spec.content.logoHeight), |
|
23
|
gradient: spec.content.logoGradient, |
|
24
|
}) |
|
25
|
|
|
26
|
const versionStyle: StyleObject = { |
|
27
|
display: "flex", |
|
28
|
marginTop: px(spec.content.textOffsetY), |
|
29
|
fontSize: px(spec.content.fontSize), |
|
30
|
// Hug the glyphs so the sheen maps onto the digits rather than onto the |
|
31
|
// ascender and descender space around them. |
|
32
|
lineHeight: 1, |
|
33
|
fontWeight: spec.content.fontWeight, |
|
34
|
letterSpacing: px(spec.content.letterSpacing), |
|
35
|
// Gradient text: paint the gradient, clip it to the glyphs, hide the fill. |
|
36
|
backgroundImage: linearGradient(spec.content.textGradient), |
|
37
|
backgroundClip: "text", |
|
38
|
color: "transparent", |
|
39
|
} |
|
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
|
}, |
|
52
|
}, |
|
53
|
// The outer element's gradient background *is* the rim: padding of |
|
54
|
// `borderWidth` exposes it as a hairline around the inner surface, which is |
|
55
|
// how you get a gradient border in satori, which has no border-image. |
|
56
|
h( |
|
57
|
"div", |
|
58
|
{ |
|
59
|
style: { |
|
60
|
display: "flex", |
|
61
|
marginTop: px(spec.pill.offsetY), |
|
62
|
padding: px(spec.pill.borderWidth), |
|
63
|
borderRadius: 9999, |
|
64
|
backgroundImage: linearGradient(spec.pill.borderGradient), |
|
65
|
}, |
|
66
|
}, |
|
67
|
h( |
|
68
|
"div", |
|
69
|
{ |
|
70
|
style: { |
|
71
|
display: "flex", |
|
72
|
alignItems: "center", |
|
73
|
// `pill.height` covers the rim, which the padding above contributes. |
|
74
|
height: px(spec.pill.height - spec.pill.borderWidth * 2), |
|
75
|
paddingLeft: px(spec.pill.paddingLeft), |
|
76
|
paddingRight: px(spec.pill.paddingRight), |
|
77
|
borderRadius: 9999, |
|
78
|
backgroundImage: linearGradient(spec.pill.fillGradient), |
|
79
|
}, |
|
80
|
}, |
|
81
|
h("img", { |
|
82
|
src: logo.src, |
|
83
|
width: logo.width, |
|
84
|
height: logo.height, |
|
85
|
style: { marginRight: px(spec.content.gap) }, |
|
86
|
}), |
|
87
|
h("div", { style: versionStyle }, version) |
|
88
|
) |
|
89
|
) |
|
90
|
) |
|
91
|
} |