|
1
|
import type { GradientStop } from "./types.js" |
|
2
|
|
|
3
|
/** |
|
4
|
* The Medusa logomark, taken from `@medusajs/icons` |
|
5
|
* (packages/design-system/icons/src/components/medusa.tsx). |
|
6
|
* |
|
7
|
* The banner fills it with the same top-to-bottom sheen as the version text, so |
|
8
|
* the fill is a gradient reference rather than a flat colour. |
|
9
|
*/ |
|
10
|
export const LOGO_PATH = |
|
11
|
"M12.184 2.941 9.127 1.183a3.22 3.22 0 0 0-3.226 0L2.83 2.94a3.25 3.25 0 0 0-1.606 2.786V9.26c0 1.153.62 2.209 1.606 2.786l3.057 1.772c1 .577 2.226.577 3.226 0l3.057-1.772a3.2 3.2 0 0 0 1.606-2.786V5.727c.028-1.14-.592-2.209-1.592-2.786m-4.677 7.697A3.14 3.14 0 0 1 4.365 7.5a3.14 3.14 0 0 1 3.142-3.138c1.733 0 3.155 1.407 3.155 3.138a3.145 3.145 0 0 1-3.155 3.138" |
|
12
|
|
|
13
|
/** |
|
14
|
* Tight bounding box of `LOGO_PATH` inside its authored 15x15 viewBox. |
|
15
|
* |
|
16
|
* Cropping the viewBox to the ink means the width and height handed to satori |
|
17
|
* are the *visible* dimensions, with no invisible padding to compensate for. |
|
18
|
*/ |
|
19
|
export const LOGO_INK = { x: 1.215, y: 0.75, width: 12.57, height: 13.5 } |
|
20
|
|
|
21
|
export const LOGO_ASPECT = LOGO_INK.width / LOGO_INK.height |
|
22
|
|
|
23
|
export type Logo = { |
|
24
|
width: number |
|
25
|
height: number |
|
26
|
src: string |
|
27
|
} |
|
28
|
|
|
29
|
/** |
|
30
|
* Builds a standalone SVG of the logomark as a data URI — which is how satori |
|
31
|
* takes SVG. |
|
32
|
* |
|
33
|
* Pass a `gradient` for a vertical sheen, or a `color` for a flat fill; a |
|
34
|
* gradient wins when both are given. |
|
35
|
*/ |
|
36
|
export function logoDataUri({ |
|
37
|
height, |
|
38
|
gradient, |
|
39
|
color = "#FFFFFF", |
|
40
|
}: { |
|
41
|
height: number |
|
42
|
gradient?: GradientStop[] |
|
43
|
color?: string |
|
44
|
}): Logo { |
|
45
|
const width = height * LOGO_ASPECT |
|
46
|
const { x, y, width: w, height: h } = LOGO_INK |
|
47
|
|
|
48
|
const stops = (gradient ?? []) |
|
49
|
.map( |
|
50
|
([offset, stopColor]) => |
|
51
|
`<stop offset="${offset}" stop-color="${stopColor}"/>` |
|
52
|
) |
|
53
|
.join("") |
|
54
|
|
|
55
|
const defs = gradient |
|
56
|
? `<defs><linearGradient id="m" x1="0" y1="${y}" x2="0" y2="${y + h}" ` + |
|
57
|
`gradientUnits="userSpaceOnUse">${stops}</linearGradient></defs>` |
|
58
|
: "" |
|
59
|
|
|
60
|
const svg = |
|
61
|
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" ` + |
|
62
|
`height="${height}" viewBox="${x} ${y} ${w} ${h}">` + |
|
63
|
defs + |
|
64
|
`<path fill="${gradient ? "url(#m)" : color}" d="${LOGO_PATH}"/>` + |
|
65
|
`</svg>` |
|
66
|
|
|
67
|
return { |
|
68
|
width, |
|
69
|
height, |
|
70
|
src: `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`, |
|
71
|
} |
|
72
|
} |