astro-hotspot 0.2.0 → 0.3.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/CHANGELOG.md +8 -0
- package/dist/service.js +15 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.3.0 - 2026-09-13
|
|
6
|
+
|
|
7
|
+
- Added support for Astro 7.3 — the new `logger` argument of the image-service hooks is passed through to the base Sharp service
|
|
8
|
+
|
|
9
|
+
## 0.2.1 - 2026-07-31
|
|
10
|
+
|
|
11
|
+
- Fixed `hotspot` being forwarded to the rendered `<img>`, where it showed up as `hotspot="70% 34%"` (or `hotspot="[object Object]"` for the coordinate form)
|
|
12
|
+
|
|
5
13
|
## 0.2.0 - 2026-07-31
|
|
6
14
|
|
|
7
15
|
- Added Astro 7 support — `astro` peer range is now `>=5.0.0 <8.0.0`
|
package/dist/service.js
CHANGED
|
@@ -23,16 +23,16 @@ export const parseHotspot = (value) => {
|
|
|
23
23
|
}
|
|
24
24
|
return undefined;
|
|
25
25
|
};
|
|
26
|
-
const getURL = (options, imageConfig) => {
|
|
27
|
-
const url = baseSharpService.getURL(options, imageConfig);
|
|
26
|
+
const getURL = (options, imageConfig, logger) => {
|
|
27
|
+
const url = baseSharpService.getURL(options, imageConfig, logger);
|
|
28
28
|
const hotspot = parseHotspot(options.hotspot);
|
|
29
29
|
if (!hotspot || typeof url !== "string")
|
|
30
30
|
return url;
|
|
31
31
|
const sep = url.includes("?") ? "&" : "?";
|
|
32
32
|
return `${url}${sep}hotspot=${hotspot.x},${hotspot.y}`;
|
|
33
33
|
};
|
|
34
|
-
const parseURL = (url, imageConfig) => {
|
|
35
|
-
const transform = baseSharpService.parseURL(url, imageConfig);
|
|
34
|
+
const parseURL = (url, imageConfig, logger) => {
|
|
35
|
+
const transform = baseSharpService.parseURL(url, imageConfig, logger);
|
|
36
36
|
if (!transform || transform instanceof Promise)
|
|
37
37
|
return transform;
|
|
38
38
|
const raw = url.searchParams.get("hotspot");
|
|
@@ -44,10 +44,16 @@ const parseURL = (url, imageConfig) => {
|
|
|
44
44
|
}
|
|
45
45
|
return transform;
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
// The base service forwards every prop it doesn't recognise onto the element,
|
|
48
|
+
// so `hotspot` has to be removed before delegating or it renders as an attribute.
|
|
49
|
+
const getHTMLAttributes = (options, imageConfig, logger) => {
|
|
50
|
+
const { hotspot: _hotspot, ...rest } = options;
|
|
51
|
+
return baseSharpService.getHTMLAttributes?.(rest, imageConfig, logger) ?? {};
|
|
52
|
+
};
|
|
53
|
+
const transform = async (inputBuffer, transformOptions, config, logger) => {
|
|
48
54
|
const hotspot = parseHotspot(transformOptions.hotspot);
|
|
49
55
|
if (!hotspot || !transformOptions.width || !transformOptions.height) {
|
|
50
|
-
return baseSharpService.transform(inputBuffer, transformOptions, config);
|
|
56
|
+
return baseSharpService.transform(inputBuffer, transformOptions, config, logger);
|
|
51
57
|
}
|
|
52
58
|
const { default: sharp } = await import("sharp");
|
|
53
59
|
const img = sharp(inputBuffer, { failOn: "none", pages: -1 }).rotate();
|
|
@@ -55,7 +61,7 @@ const transform = async (inputBuffer, transformOptions, config) => {
|
|
|
55
61
|
const srcW = meta.width;
|
|
56
62
|
const srcH = meta.height;
|
|
57
63
|
if (!srcW || !srcH) {
|
|
58
|
-
return baseSharpService.transform(inputBuffer, transformOptions, config);
|
|
64
|
+
return baseSharpService.transform(inputBuffer, transformOptions, config, logger);
|
|
59
65
|
}
|
|
60
66
|
const targetW = Math.round(Number(transformOptions.width));
|
|
61
67
|
const targetH = Math.round(Number(transformOptions.height));
|
|
@@ -82,7 +88,7 @@ const transform = async (inputBuffer, transformOptions, config) => {
|
|
|
82
88
|
.toBuffer();
|
|
83
89
|
// Cropped buffer is already at target AR — delegate the final resize
|
|
84
90
|
// + format encode to the base service so we don't reimplement it.
|
|
85
|
-
return baseSharpService.transform(cropped, transformOptions, config);
|
|
91
|
+
return baseSharpService.transform(cropped, transformOptions, config, logger);
|
|
86
92
|
};
|
|
87
93
|
/**
|
|
88
94
|
* LocalImageService that wraps the default Sharp service and adds
|
|
@@ -104,6 +110,7 @@ const hotspotImageService = {
|
|
|
104
110
|
],
|
|
105
111
|
getURL,
|
|
106
112
|
parseURL,
|
|
113
|
+
getHTMLAttributes,
|
|
107
114
|
transform,
|
|
108
115
|
};
|
|
109
116
|
export default hotspotImageService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-hotspot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Astro image service: hotspot cropping (x/y or '70% 34%') via Sharp's extract+resize",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"sharp": ">=0.33.0 <0.36.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"astro": "7.
|
|
50
|
+
"astro": "7.3.2",
|
|
51
51
|
"prettier": "3.9.6",
|
|
52
|
-
"sharp": "0.35.
|
|
52
|
+
"sharp": "0.35.4",
|
|
53
53
|
"typescript": "6.0.3",
|
|
54
|
-
"vitest": "
|
|
54
|
+
"vitest": "5.0.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsc",
|