@graphcommerce/image 11.0.0-canary.68 → 11.0.0-canary.69
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 +6 -0
- package/Config.graphqls +21 -0
- package/README.md +24 -8
- package/components/Image.tsx +7 -4
- package/config/config.ts +18 -15
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.69
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2732](https://github.com/graphcommerce-org/graphcommerce/pull/2732) [`cba75a0`](https://github.com/graphcommerce-org/graphcommerce/commit/cba75a006d4efface5d1149e9cc6ebe3a9b5b9f8) - Added `imageQuality` to `graphcommerce.config.ts`. Choose the kind (`content` or `product`) with `quality` on `<Image>` or `imageUrl()`. `quality='content'` is for content images, such as CMS images, and is the default when no quality is given, with quality 75 in place of the previous 52. `quality='product'` is for product images from the Magento catalog, with quality 52. ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
8
|
+
|
|
3
9
|
## 11.0.0-canary.68
|
|
4
10
|
|
|
5
11
|
## 11.0.0-canary.67
|
package/Config.graphqls
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The quality of each kind of image. Choose the kind with `quality` on `<Image>` or `imageUrl()`, for example `quality='product'`.
|
|
3
|
+
"""
|
|
4
|
+
input ImageQualityConfig {
|
|
5
|
+
"""
|
|
6
|
+
The quality of a content image, such as a banner or another CMS image. `quality='content'` is the default for `<Image>` without the quality prop.
|
|
7
|
+
"""
|
|
8
|
+
content: Int! = 75 @public
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
The quality of a product image from the Magento catalog.
|
|
12
|
+
"""
|
|
13
|
+
product: Int! = 52 @public
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
extend input GraphCommerceConfig {
|
|
17
|
+
"""
|
|
18
|
+
Sets the quality of the images of `<Image>` and `imageUrl()`.
|
|
19
|
+
"""
|
|
20
|
+
imageQuality: ImageQualityConfig! = {}
|
|
21
|
+
}
|
package/README.md
CHANGED
|
@@ -11,14 +11,30 @@ images further than what `next/image` has to offer.
|
|
|
11
11
|
|
|
12
12
|
- Optimize images further than what next/image does.
|
|
13
13
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
## Quality
|
|
15
|
+
|
|
16
|
+
1. Set `quality='product'` on images from the Magento catalog. An `<Image>`
|
|
17
|
+
without `quality` uses `content`.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
<Image
|
|
21
|
+
src={product.small_image.url}
|
|
22
|
+
width={300}
|
|
23
|
+
height={300}
|
|
24
|
+
quality='product'
|
|
25
|
+
/>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
2. Change the qualities in `graphcommerce.config.ts`. The defaults are
|
|
29
|
+
`content: 75` and `product: 52`.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
imageQuality: { content: 80 },
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`withGraphCommerce` adds the values of `imageQuality` to `images.qualities`. Add
|
|
36
|
+
a number that you pass as `quality={90}` to `images.qualities` in
|
|
37
|
+
`next.config.ts`.
|
|
22
38
|
|
|
23
39
|
## Serving the right images for low dpi screens (1x)
|
|
24
40
|
|
package/components/Image.tsx
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
/* eslint-disable @next/next/no-img-element */
|
|
9
9
|
|
|
10
10
|
/* eslint-disable jsx-a11y/alt-text */
|
|
11
|
+
import { imageQuality } from '@graphcommerce/next-config/config'
|
|
11
12
|
import { sxx } from '@graphcommerce/next-ui'
|
|
12
13
|
import type { SxProps, Theme } from '@mui/material'
|
|
13
14
|
import { styled, useForkRef } from '@mui/material'
|
|
@@ -146,7 +147,7 @@ type GenImgAttrsData = {
|
|
|
146
147
|
layout: LayoutValue
|
|
147
148
|
loader?: ImageLoaderWithConfig
|
|
148
149
|
width?: number
|
|
149
|
-
quality?:
|
|
150
|
+
quality?: ImageProps['quality']
|
|
150
151
|
sizes: string
|
|
151
152
|
scale: number
|
|
152
153
|
config?: ImageConfig
|
|
@@ -162,7 +163,7 @@ export function generateSrcSet(props: GenImgAttrsData): string {
|
|
|
162
163
|
src,
|
|
163
164
|
layout,
|
|
164
165
|
width,
|
|
165
|
-
quality =
|
|
166
|
+
quality = 'content',
|
|
166
167
|
sizes,
|
|
167
168
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
168
169
|
loader = defaultImageLoader,
|
|
@@ -170,11 +171,12 @@ export function generateSrcSet(props: GenImgAttrsData): string {
|
|
|
170
171
|
config = defaultConfig,
|
|
171
172
|
} = props
|
|
172
173
|
const { widths, kind } = getWidths(config, width, layout, sizes)
|
|
174
|
+
const q = typeof quality === 'number' ? quality : imageQuality[quality]
|
|
173
175
|
|
|
174
176
|
return `${widths
|
|
175
177
|
.map(
|
|
176
178
|
(w, i) =>
|
|
177
|
-
`${loader({ config, src, quality, width: w })} ${
|
|
179
|
+
`${loader({ config, src, quality: q, width: w })} ${
|
|
178
180
|
kind === 'w' ? Math.round(w * scale) : i + 1
|
|
179
181
|
}${kind}`,
|
|
180
182
|
)
|
|
@@ -237,7 +239,8 @@ export type ImageProps = IntrisincImage & {
|
|
|
237
239
|
src: StaticImport | string
|
|
238
240
|
blurDataURL?: string
|
|
239
241
|
loader?: ImageLoader
|
|
240
|
-
|
|
242
|
+
/** A number, or a key of `imageQuality` in `graphcommerce.config.ts`. */
|
|
243
|
+
quality?: number | keyof typeof imageQuality
|
|
241
244
|
unoptimized?: boolean
|
|
242
245
|
dontReportWronglySizedImages?: boolean
|
|
243
246
|
width?: number
|
package/config/config.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { imageQuality } from '@graphcommerce/next-config/config'
|
|
1
2
|
import { normalizePathTrailingSlash } from 'next/dist/client/normalize-trailing-slash'
|
|
2
3
|
import type { ImageConfigComplete } from 'next/dist/shared/lib/image-config'
|
|
3
4
|
import { imageConfigDefault } from 'next/dist/shared/lib/image-config'
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
5
6
|
import type { ImageLoaderProps } from 'next/image'
|
|
7
|
+
import type { ImageProps } from '../components/Image'
|
|
6
8
|
|
|
7
9
|
export type DefaultImageLoaderProps = ImageLoaderProps & { root: string }
|
|
8
10
|
|
|
@@ -139,24 +141,25 @@ const urlLoaders = {
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/**
|
|
142
|
-
* Build an optimized image URL outside of a React tree, for the places that
|
|
143
|
-
*
|
|
144
|
-
* `background-image`, an `og:image`.
|
|
144
|
+
* Build an optimized image URL outside of a React tree, for the places that need a bare URL string
|
|
145
|
+
* rather than an `<Image>` — `<video poster>`, a CSS `background-image`, an `og:image`.
|
|
145
146
|
*
|
|
146
|
-
* Routes through the configured loader exactly like `<Image>` does, so the
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* bandwidth.
|
|
147
|
+
* Routes through the configured loader exactly like `<Image>` does, so the bytes are served and
|
|
148
|
+
* cached by your own deployment rather than fetched from the origin host by every visitor. That
|
|
149
|
+
* matters when the origin meters bandwidth.
|
|
150
150
|
*
|
|
151
|
-
* `width` is snapped up to the nearest configured size: the optimizer rejects
|
|
152
|
-
*
|
|
153
|
-
*
|
|
151
|
+
* `width` is snapped up to the nearest configured size: the optimizer rejects any width outside
|
|
152
|
+
* `imageSizes`/`deviceSizes` with a 400. Format is negotiated by the optimizer on the request's
|
|
153
|
+
* `Accept` header and can't be pinned here.
|
|
154
154
|
*
|
|
155
|
-
* Returns `src` untouched under a `custom` loader, which exists only as a
|
|
156
|
-
*
|
|
155
|
+
* Returns `src` untouched under a `custom` loader, which exists only as a per-`<Image>` prop and so
|
|
156
|
+
* can't be resolved from here.
|
|
157
157
|
*/
|
|
158
|
-
export function imageUrl(
|
|
159
|
-
|
|
158
|
+
export function imageUrl(
|
|
159
|
+
src: string,
|
|
160
|
+
options: { width: number; quality?: ImageProps['quality'] },
|
|
161
|
+
): string {
|
|
162
|
+
const { width, quality = 'content' } = options
|
|
160
163
|
if (configLoader === 'custom') return src
|
|
161
164
|
|
|
162
165
|
const config =
|
|
@@ -168,6 +171,6 @@ export function imageUrl(src: string, options: { width: number; quality?: number
|
|
|
168
171
|
config: { ...config, allSizes },
|
|
169
172
|
src,
|
|
170
173
|
width: snapped,
|
|
171
|
-
quality,
|
|
174
|
+
quality: typeof quality === 'number' ? quality : imageQuality[quality],
|
|
172
175
|
})
|
|
173
176
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/image",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.69",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsc -W"
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.
|
|
22
|
-
"@graphcommerce/framer-utils": "^11.0.0-canary.
|
|
23
|
-
"@graphcommerce/
|
|
24
|
-
"@graphcommerce/
|
|
21
|
+
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.69",
|
|
22
|
+
"@graphcommerce/framer-utils": "^11.0.0-canary.69",
|
|
23
|
+
"@graphcommerce/next-config": "^11.0.0-canary.69",
|
|
24
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.69",
|
|
25
|
+
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.69",
|
|
25
26
|
"@mui/material": "^7.0.0",
|
|
26
27
|
"next": "*",
|
|
27
28
|
"react": "^19.2.0",
|