File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
packages/npm/@amazeelabs/image/src Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
type ImageProps ,
16
16
type ImageSettings as ImageSettingsType ,
17
17
inferTargetDimensions ,
18
+ validateFocus ,
18
19
} from './lib.js' ;
19
20
20
21
function base64 ( content : string ) {
@@ -95,7 +96,7 @@ export const Image = forwardRef(function Image(
95
96
ref . current . style . backgroundPosition = calculateFocusPosition (
96
97
ref . current . naturalWidth ,
97
98
ref . current . naturalHeight ,
98
- focalPoint || [
99
+ validateFocus ( focalPoint ) || [
99
100
ref . current . naturalWidth / 2 ,
100
101
ref . current . naturalHeight / 2 ,
101
102
] ,
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ export type ImageProps = Omit<
30
30
* one is the x-coordinate, the second one is the y-coordinate. Both are
31
31
* relative to the top-left corner of the *original* image.
32
32
*/
33
- focalPoint ?: [ number , number ] ;
33
+ focalPoint ?: Array < number > ;
34
34
/**
35
35
* A single property to switch between important and lazy-loaded images.
36
36
* It controls the `loading` and `decoding` attributes.
@@ -113,6 +113,15 @@ export function inferTargetDimensions(
113
113
114
114
export type Focus = [ number , number ] ;
115
115
116
+ export function validateFocus (
117
+ focus : Array < number > | undefined ,
118
+ ) : Focus | undefined {
119
+ if ( ! focus || focus . length === 2 ) {
120
+ return focus as Focus ;
121
+ }
122
+ console . warn ( 'Invalid focus point:' , focus ) ;
123
+ }
124
+
116
125
export function calculateFocusExtraction (
117
126
source : readonly [ number , number ] ,
118
127
target : readonly [ number , number ] ,
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
ImageProps ,
19
19
ImageSettings as ImageSettingsType ,
20
20
inferTargetDimensions ,
21
+ validateFocus ,
21
22
} from './lib.js' ;
22
23
23
24
async function prepareFile ( src : string ) {
@@ -170,7 +171,12 @@ export async function Image({
170
171
decoding = { priority ? 'async' : 'auto' }
171
172
// eslint-disable-next-line react/no-unknown-property
172
173
fetchPriority = { priority ? 'high' : 'auto' }
173
- src = { await transformSrc ( filename , source , target , focalPoint ) }
174
+ src = { await transformSrc (
175
+ filename ,
176
+ source ,
177
+ target ,
178
+ validateFocus ( focalPoint ) ,
179
+ ) }
174
180
srcSet = { await transformSrcSet (
175
181
filename ,
176
182
source ,
@@ -180,7 +186,7 @@ export async function Image({
180
186
target . width * 2 ,
181
187
...getSettings ( ) . resolutions . filter ( ( w ) => w < target . width ) ,
182
188
] ,
183
- focalPoint ,
189
+ validateFocus ( focalPoint ) ,
184
190
) }
185
191
sizes = { props . sizes || `(min-width: ${ width } px) ${ width } px, 100vw` }
186
192
data-src = { props . src }
You can’t perform that action at this time.
0 commit comments