@cedgetec-utils/astro-components 1.8.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.8.0",
3
+ "version": "1.11.0",
4
4
  "keywords": [
5
5
  "astro-component"
6
6
  ],
@@ -13,19 +13,15 @@
13
13
  ".": "./src/components/index.ts",
14
14
  "./libs": "./src/libs/index.ts"
15
15
  },
16
- "scripts": {
17
- "lint": "oxlint",
18
- "format": "oxfmt"
19
- },
20
16
  "dependencies": {
21
- "astro": "^6.0.2"
17
+ "astro": "^6.4.7"
22
18
  },
23
19
  "devDependencies": {
24
- "oxfmt": "^0.38.0",
25
- "oxlint": "^1.53.0",
26
- "typescript": "^5.9.3"
20
+ "oxfmt": "^0.55.0",
21
+ "oxlint": "^1.70.0",
22
+ "typescript": "^6.0.3"
27
23
  },
28
24
  "peerDependencies": {
29
- "astro": "^6.0.2"
25
+ "astro": "^6.4.7"
30
26
  }
31
27
  }
@@ -24,19 +24,38 @@ const title =
24
24
 
25
25
  const ogTitle = slug === "" ? props.siteName : `${props.title}`;
26
26
 
27
- const iconLight = await getImage({
28
- src: props.icons.light,
29
- width: 48,
30
- height: 48,
31
- fit: "contain",
32
- });
33
-
34
- const iconDark = await getImage({
35
- src: props.icons.dark,
36
- width: 48,
37
- height: 48,
38
- fit: "contain",
39
- });
27
+ // Common favicon / PWA icon sizes.
28
+ const faviconSizes = [16, 32, 48, 96, 192, 512];
29
+
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({
46
+ src,
47
+ width: size,
48
+ height: size,
49
+ fit: "contain",
50
+ format: "png",
51
+ });
52
+ return { type: "image/png", sizes: `${size}x${size}`, href: image.src };
53
+ }),
54
+ );
55
+ };
56
+
57
+ const iconsLight = await buildIcons(props.icons.light);
58
+ const iconsDark = await buildIcons(props.icons.dark);
40
59
 
41
60
  const openGraphImage = props.image
42
61
  ? await getImage({
@@ -51,9 +70,38 @@ const openGraphImage = props.image
51
70
  <meta charset="UTF-8" />
52
71
  <title>{title}</title>
53
72
 
54
- <link rel="icon" href={iconDark.src} />
55
- <link rel="icon" href={iconLight.src} media="(prefers-color-scheme:dark)" />
56
- <link rel="icon" href={iconDark.src} media="(prefers-color-scheme:light)" />
73
+ {/* Default fallback icons (used when prefers-color-scheme is unsupported) */}
74
+ {
75
+ iconsDark.map(({ type, sizes, href }) => (
76
+ <link rel="icon" type={type} sizes={sizes} href={href} />
77
+ ))
78
+ }
79
+
80
+ {/* Light-colored icons for dark UI */}
81
+ {
82
+ iconsLight.map(({ type, sizes, href }) => (
83
+ <link
84
+ rel="icon"
85
+ type={type}
86
+ sizes={sizes}
87
+ href={href}
88
+ media="(prefers-color-scheme:dark)"
89
+ />
90
+ ))
91
+ }
92
+
93
+ {/* Dark-colored icons for light UI */}
94
+ {
95
+ iconsDark.map(({ type, sizes, href }) => (
96
+ <link
97
+ rel="icon"
98
+ type={type}
99
+ sizes={sizes}
100
+ href={href}
101
+ media="(prefers-color-scheme:light)"
102
+ />
103
+ ))
104
+ }
57
105
 
58
106
  <meta name="generator" content={Astro.generator} />
59
107
  <meta name="view-transition" content="same-origin" />
@@ -75,4 +123,4 @@ const openGraphImage = props.image
75
123
  {props.type && <meta property="og:type" content={props.type} />}
76
124
  {openGraphImage && <meta property="og:image" content={openGraphImage.src} />}
77
125
  <slot />
78
- </head>
126
+ </head>