@cedgetec-utils/astro-components 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedgetec-utils/astro-components",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "keywords": [
5
5
  "astro-component"
6
6
  ],
@@ -27,19 +27,32 @@ const ogTitle = slug === "" ? props.siteName : `${props.title}`;
27
27
  // Common favicon / PWA icon sizes.
28
28
  const faviconSizes = [16, 32, 48, 96, 192, 512];
29
29
 
30
- const buildIcons = (src: string | ImageMetadata) =>
31
- Promise.all(
32
- faviconSizes.map(async (size) => ({
33
- size,
34
- image: await getImage({
30
+ type Icon = { type: string; sizes: string; href: string };
31
+
32
+ const isSvg = (src: string | ImageMetadata) =>
33
+ typeof src === "string" ? src.endsWith(".svg") : src.format === "svg";
34
+
35
+ const buildIcons = async (src: string | ImageMetadata): Promise<Icon[]> => {
36
+ // An SVG favicon scales to any size, so pass it through unchanged rather
37
+ // than rasterizing it to PNG at every size.
38
+ if (isSvg(src)) {
39
+ const image = await getImage({ src, format: "svg" });
40
+ return [{ type: "image/svg+xml", sizes: "any", href: image.src }];
41
+ }
42
+
43
+ return Promise.all(
44
+ faviconSizes.map(async (size) => {
45
+ const image = await getImage({
35
46
  src,
36
47
  width: size,
37
48
  height: size,
38
49
  fit: "contain",
39
50
  format: "png",
40
- }),
41
- })),
51
+ });
52
+ return { type: "image/png", sizes: `${size}x${size}`, href: image.src };
53
+ }),
42
54
  );
55
+ };
43
56
 
44
57
  const iconsLight = await buildIcons(props.icons.light);
45
58
  const iconsDark = await buildIcons(props.icons.dark);
@@ -59,24 +72,19 @@ const openGraphImage = props.image
59
72
 
60
73
  {/* Default fallback icons (used when prefers-color-scheme is unsupported) */}
61
74
  {
62
- iconsDark.map(({ size, image }) => (
63
- <link
64
- rel="icon"
65
- type="image/png"
66
- sizes={`${size}x${size}`}
67
- href={image.src}
68
- />
75
+ iconsDark.map(({ type, sizes, href }) => (
76
+ <link rel="icon" type={type} sizes={sizes} href={href} />
69
77
  ))
70
78
  }
71
79
 
72
80
  {/* Light-colored icons for dark UI */}
73
81
  {
74
- iconsLight.map(({ size, image }) => (
82
+ iconsLight.map(({ type, sizes, href }) => (
75
83
  <link
76
84
  rel="icon"
77
- type="image/png"
78
- sizes={`${size}x${size}`}
79
- href={image.src}
85
+ type={type}
86
+ sizes={sizes}
87
+ href={href}
80
88
  media="(prefers-color-scheme:dark)"
81
89
  />
82
90
  ))
@@ -84,12 +92,12 @@ const openGraphImage = props.image
84
92
 
85
93
  {/* Dark-colored icons for light UI */}
86
94
  {
87
- iconsDark.map(({ size, image }) => (
95
+ iconsDark.map(({ type, sizes, href }) => (
88
96
  <link
89
97
  rel="icon"
90
- type="image/png"
91
- sizes={`${size}x${size}`}
92
- href={image.src}
98
+ type={type}
99
+ sizes={sizes}
100
+ href={href}
93
101
  media="(prefers-color-scheme:light)"
94
102
  />
95
103
  ))