@graphcommerce/image 3.0.0 → 3.1.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 CHANGED
@@ -1,5 +1,70 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1284](https://github.com/ho-nl/m2-pwa/pull/1284)
8
+ [`5ffcb56bf`](https://github.com/ho-nl/m2-pwa/commit/5ffcb56bfcbe49ebeaf24f9341e819a145ab9a14)
9
+ Thanks [@paales](https://github.com/paales)! - SvgIcon is now more extenable and flexible:
10
+
11
+ - It will automatically calculate the stroke-width of the SVG based on the rendered size, allowing
12
+ for a more flexible use for icons.
13
+
14
+ - Make SvgIcon themable in your own Theme.
15
+
16
+ - Create overrides for components that will be used throughout the app.
17
+
18
+ ### Patch Changes
19
+
20
+ - [`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96)
21
+ Thanks [@paales](https://github.com/paales)! - made packages public
22
+
23
+ * [#1278](https://github.com/ho-nl/m2-pwa/pull/1278)
24
+ [`81ea406d5`](https://github.com/ho-nl/m2-pwa/commit/81ea406d54d6b5c662c030a7fea444abc4117a20)
25
+ Thanks [@ErwinOtten](https://github.com/ErwinOtten)! - Upgraded dependencies to the latest version
26
+
27
+ * Updated dependencies
28
+ [[`973ff8645`](https://github.com/ho-nl/m2-pwa/commit/973ff86452a70ade9f4db13fdda6e963d7220e96)]:
29
+ - @graphcommerce/framer-utils@3.0.3
30
+
31
+ ## 3.0.2
32
+
33
+ ### Patch Changes
34
+
35
+ - [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
36
+ [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2)
37
+ Thanks [@paales](https://github.com/paales)! - We've moved lots of internal packages from
38
+ `dependencies` to `peerDependencies`. The result of this is that there will be significantly less
39
+ duplicate packages in the node_modules folders.
40
+
41
+ * [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
42
+ [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)
43
+ Thanks [@paales](https://github.com/paales)! - Upgraded to
44
+ [NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for compatibility, but we'll be
45
+ implementing
46
+ [On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta)
47
+ soon.
48
+
49
+ This will greatly reduce the requirement to rebuid stuff and we'll add a management UI on the
50
+ frontend to be able to revalidate pages manually.
51
+
52
+ * Updated dependencies
53
+ [[`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2),
54
+ [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)]:
55
+ - @graphcommerce/framer-utils@3.0.2
56
+
57
+ ## 3.0.1
58
+
59
+ ### Patch Changes
60
+
61
+ - [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)
62
+ Thanks [@paales](https://github.com/paales)! - Added homepage and repository package.json files,
63
+ so that the packages link to back to the website and repository
64
+ - Updated dependencies
65
+ [[`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)]:
66
+ - @graphcommerce/framer-utils@3.0.1
67
+
3
68
  ## 3.0.0
4
69
 
5
70
  ### Major Changes
@@ -3,15 +3,20 @@
3
3
  /* eslint-disable @next/next/no-img-element */
4
4
  /* eslint-disable jsx-a11y/alt-text */
5
5
  import { useForkRef, styled, SxProps, Theme } from '@mui/material'
6
- import { LoaderValue, VALID_LOADERS } from 'next/dist/server/image-config'
6
+ import {
7
+ ImageConfigComplete,
8
+ LoaderValue,
9
+ VALID_LOADERS,
10
+ imageConfigDefault,
11
+ } from 'next/dist/server/image-config'
12
+ import { ImageConfigContext } from 'next/dist/shared/lib/image-config-context'
7
13
  import Head from 'next/head'
8
14
  import type { ImageLoaderProps, ImageLoader } from 'next/image'
9
- import React, { useEffect, useRef } from 'react'
15
+ import React, { useContext, useEffect, useMemo, useRef } from 'react'
10
16
  import {
11
17
  akamaiLoader,
12
18
  cloudinaryLoader,
13
19
  configDeviceSizes,
14
- configImageSizes,
15
20
  configLoader,
16
21
  configPath,
17
22
  DefaultImageLoaderProps,
@@ -54,7 +59,7 @@ interface StaticRequire {
54
59
  default: StaticImageData
55
60
  }
56
61
 
57
- type StaticImport = StaticRequire | StaticImageData
62
+ export type StaticImport = StaticRequire | StaticImageData
58
63
 
59
64
  export function isStaticRequire(src: StaticRequire | StaticImageData): src is StaticRequire {
60
65
  return (src as StaticRequire).default !== undefined
@@ -72,12 +77,13 @@ export function srcToString(src: StaticImport | string) {
72
77
  return isStaticImport(src) ? (isStaticRequire(src) ? src.default : src).src : src
73
78
  }
74
79
 
75
- // sort smallest to largest
76
- const allSizes = [...configDeviceSizes, ...configImageSizes]
77
- configDeviceSizes.sort((a, b) => a - b)
78
- allSizes.sort((a, b) => a - b)
80
+ // // sort smallest to largest
81
+ // const allSizes = [...configDeviceSizes, ...configImageSizes]
82
+ // configDeviceSizes.sort((a, b) => a - b)
83
+ // allSizes.sort((a, b) => a - b)
79
84
 
80
85
  function getWidths(
86
+ config: ImageLoaderProps['config'],
81
87
  width: number | undefined,
82
88
  layout: LayoutValue,
83
89
  sizes = '',
@@ -94,12 +100,12 @@ function getWidths(
94
100
  const smallestRatio = Math.min(...percentSizes) * 0.01
95
101
 
96
102
  return {
97
- widths: allSizes.filter((s) => s >= configDeviceSizes[0] * smallestRatio),
103
+ widths: config.allSizes.filter((s) => s >= configDeviceSizes[0] * smallestRatio),
98
104
  kind: 'w',
99
105
  }
100
106
  }
101
107
 
102
- return { widths: allSizes, kind: 'w' }
108
+ return { widths: config.allSizes, kind: 'w' }
103
109
  }
104
110
  if (typeof width !== 'number' || layout === 'fill') {
105
111
  return { widths: configDeviceSizes, kind: 'w' }
@@ -116,7 +122,7 @@ function getWidths(
116
122
  // > something like a magnifying glass.
117
123
  // https://blog.twitter.com/engineering/en_us/topics/infrastructure/2019/capping-image-fidelity-on-ultra-high-resolution-devices.html
118
124
  [width, width * 2 /* , width * 3*/].map(
119
- (w) => allSizes.find((p) => p >= w) || allSizes[allSizes.length - 1],
125
+ (w) => config.allSizes.find((p) => p >= w) || config.allSizes[config.allSizes.length - 1],
120
126
  ),
121
127
  ),
122
128
  ]
@@ -131,23 +137,17 @@ type GenImgAttrsData = {
131
137
  quality?: number
132
138
  sizes: string
133
139
  scale: number
140
+ config: ImageLoaderProps['config']
134
141
  }
135
142
 
136
- function generateSrcSet({
137
- src,
138
- layout,
139
- width,
140
- quality = 52,
141
- sizes,
142
- loader,
143
- scale,
144
- }: GenImgAttrsData): string {
145
- const { widths, kind } = getWidths(width, layout, sizes)
143
+ function generateSrcSet(props: GenImgAttrsData): string {
144
+ const { src, layout, width, quality = 52, sizes, loader, scale, config } = props
145
+ const { widths, kind } = getWidths(config, width, layout, sizes)
146
146
 
147
147
  return widths
148
148
  .map(
149
149
  (w, i) =>
150
- `${loader({ src, quality, width: w })} ${
150
+ `${loader({ src, quality, width: w, config })} ${
151
151
  kind === 'w' ? Math.round(w * scale) : i + 1
152
152
  }${kind}`,
153
153
  )
@@ -237,6 +237,9 @@ export type ImageProps = IntrisincImage & {
237
237
  const Img = styled('img')({})
238
238
  const Picture = styled('picture')({})
239
239
 
240
+ // eslint-disable-next-line no-underscore-dangle
241
+ const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete
242
+
240
243
  const Image = React.forwardRef<HTMLImageElement, ImageProps>(
241
244
  (
242
245
  {
@@ -261,6 +264,14 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
261
264
  const ref = useRef<HTMLImageElement>(null)
262
265
  const combinedRef = useForkRef(ref, forwardedRef)
263
266
 
267
+ const configContext = useContext(ImageConfigContext)
268
+ const config: ImageLoaderProps['config'] = useMemo(() => {
269
+ const c = configEnv || configContext || imageConfigDefault
270
+ const allSizes = [...c.deviceSizes, ...c.imageSizes].sort((a, b) => a - b)
271
+ const deviceSizes = c.deviceSizes.sort((a, b) => a - b)
272
+ return { ...c, allSizes, deviceSizes }
273
+ }, [configContext])
274
+
264
275
  const sizesOrig =
265
276
  layout === 'fixed' && width && !sizesIncomming
266
277
  ? (`${width}px` as SizesString)
@@ -433,9 +444,36 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
433
444
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
434
445
  if (src?.startsWith('data:') || src?.startsWith('blob:')) unoptimized = true
435
446
 
436
- const srcSet3x = generateSrcSet({ src, layout, loader, quality, sizes, width, scale: 1.5 })
437
- const srcSet2x = generateSrcSet({ src, layout, loader, quality, sizes, width, scale: 1 })
438
- const srcSet1x = generateSrcSet({ src, layout, loader, quality, sizes, width, scale: 0.5 })
447
+ const srcSet3x = generateSrcSet({
448
+ config,
449
+ src,
450
+ layout,
451
+ loader,
452
+ quality,
453
+ sizes,
454
+ width,
455
+ scale: 1.5,
456
+ })
457
+ const srcSet2x = generateSrcSet({
458
+ config,
459
+ src,
460
+ layout,
461
+ loader,
462
+ quality,
463
+ sizes,
464
+ width,
465
+ scale: 1,
466
+ })
467
+ const srcSet1x = generateSrcSet({
468
+ config,
469
+ src,
470
+ layout,
471
+ loader,
472
+ quality,
473
+ sizes,
474
+ width,
475
+ scale: 0.5,
476
+ })
439
477
 
440
478
  if (layout !== 'fixed' && !style) style = {}
441
479
  if (layout === 'responsive') style = { ...style, width: '100%', height: 'auto' }
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@graphcommerce/image",
3
- "version": "3.0.0",
3
+ "homepage": "https://www.graphcommerce.org/",
4
+ "repository": "github:graphcommerce-org/graphcommerce",
5
+ "version": "3.1.0",
4
6
  "sideEffects": false,
5
7
  "scripts": {
6
8
  "dev": "tsc -W"
@@ -13,18 +15,18 @@
13
15
  }
14
16
  },
15
17
  "dependencies": {
16
- "@graphcommerce/framer-utils": "^3.0.0"
18
+ "@graphcommerce/framer-utils": "^3.0.3"
17
19
  },
18
20
  "devDependencies": {
19
- "@graphcommerce/eslint-config-pwa": "^4.0.0",
20
- "@graphcommerce/prettier-config-pwa": "^4.0.0",
21
- "@graphcommerce/typescript-config-pwa": "^4.0.0",
22
- "@playwright/test": "^1.18.1"
21
+ "@graphcommerce/eslint-config-pwa": "^4.0.3",
22
+ "@graphcommerce/prettier-config-pwa": "^4.0.2",
23
+ "@graphcommerce/typescript-config-pwa": "^4.0.2",
24
+ "@playwright/test": "^1.19.1"
23
25
  },
24
26
  "peerDependencies": {
25
- "next": "^12.0.10",
27
+ "next": "^12.1.0",
26
28
  "react": "^17.0.2",
27
29
  "react-dom": "^17.0.2",
28
- "type-fest": "^2.11.2"
30
+ "type-fest": "^2.12.0"
29
31
  }
30
32
  }