@hkdigital/lib-core 0.5.23 → 0.5.25

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.
@@ -116,8 +116,7 @@ export function generateResponseConfigs(options) {
116
116
  ...configPairs,
117
117
  w: String(w),
118
118
  format: 'png',
119
- ensureAlpha: '1',
120
- png: JSON.stringify({ palette: false })
119
+ ensureAlpha: 'true'
121
120
  };
122
121
  });
123
122
  // console.log('Returning favicon configs:', faviconConfigs);
@@ -131,8 +130,7 @@ export function generateResponseConfigs(options) {
131
130
  ...configPairs,
132
131
  w: String(w),
133
132
  format: 'png',
134
- ensureAlpha: '1',
135
- png: JSON.stringify({ palette: false })
133
+ ensureAlpha: 'true'
136
134
  };
137
135
  });
138
136
  // console.log('Returning apple-touch-icon configs:', appleTouchConfigs);
@@ -68,10 +68,36 @@ export async function generateViteConfig(options = {}) {
68
68
  generateResponseConfigs
69
69
  } = await import('./imagetools.js');
70
70
 
71
+ // Custom transform to ensure alpha channel based on directive
72
+ const ensureAlphaTransform = (config) => {
73
+ // Only apply if ensureAlpha directive is present
74
+ if (!config.ensureAlpha) return undefined;
75
+
76
+ return async (image) => {
77
+ // Force RGBA output by making one pixel slightly transparent
78
+ // This prevents Sharp from optimizing back to RGB palette
79
+ const metadata = await image.metadata();
80
+
81
+ return image
82
+ .ensureAlpha()
83
+ .composite([{
84
+ input: Buffer.from([0, 0, 0, 254]), // RGBA: black with 254 alpha (nearly opaque)
85
+ raw: { width: 1, height: 1, channels: 4 },
86
+ top: 0,
87
+ left: 0,
88
+ blend: 'over'
89
+ }]);
90
+ };
91
+ };
92
+
71
93
  plugins.push(
72
94
  imagetools({
73
95
  defaultDirectives: generateDefaultDirectives(imagetoolsOptions),
74
- resolveConfigs: generateResponseConfigs(imagetoolsOptions)
96
+ resolveConfigs: generateResponseConfigs(imagetoolsOptions),
97
+ extendTransforms: (builtins) => [
98
+ ...builtins,
99
+ ensureAlphaTransform
100
+ ]
75
101
  })
76
102
  );
77
103
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.23",
3
+ "version": "0.5.25",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"