@graphcommerce/framer-utils 3.0.4 → 3.1.1

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,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1369](https://github.com/graphcommerce-org/graphcommerce/pull/1369) [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9) Thanks [@paales](https://github.com/paales)! - Upgraded dependencies
8
+
9
+ ## 3.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#1360](https://github.com/graphcommerce-org/graphcommerce/pull/1360) [`829b8690b`](https://github.com/graphcommerce-org/graphcommerce/commit/829b8690bc5d0a46e596299e4120e9837a9f179c) Thanks [@paales](https://github.com/paales)! - Add a clientSizeCssVar that will change when the viewport changes size, as a better alternative for 100vh and in preparation for 100dvh
14
+
15
+ ## 3.0.5
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1322](https://github.com/graphcommerce-org/graphcommerce/pull/1322) [`bec88d0d7`](https://github.com/graphcommerce-org/graphcommerce/commit/bec88d0d70b679e15150917df89986ecee5b39a6) Thanks [@paales](https://github.com/paales)! - ScrollerButton is rendered while it shouldn’t because there is a rounding error in scroll and offset values
20
+
3
21
  ## 3.0.4
4
22
 
5
23
  ### Patch Changes
@@ -2,10 +2,40 @@ import { motionValue, MotionValue } from 'framer-motion'
2
2
  import { useEffect } from 'react'
3
3
  import { clientSize } from '../utils/clientSize'
4
4
  import { useConstant } from './useConstant'
5
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
5
6
 
6
7
  export type UseClientSizeReturn = { x: MotionValue<string>; y: MotionValue<string> }
7
8
  export type UseClientSizeOptions = { x?: string; y?: string }
8
9
 
10
+ export const clientSizeCssVar = {
11
+ y: `var(--client-size-y, 100vh)`,
12
+ x: `var(--client-size-x, 100vh)`,
13
+ }
14
+
15
+ let watching = false
16
+
17
+ export function useClientSizeCssVar() {
18
+ useIsomorphicLayoutEffect(() => {
19
+ if (watching === true) return () => {}
20
+
21
+ const recalc = () => {
22
+ if (typeof window !== 'undefined') {
23
+ const { x, y } = clientSize
24
+ document.body.style.setProperty('--client-size-x', `${x.get()}px`)
25
+ document.body.style.setProperty('--client-size-y', `${y.get()}px`)
26
+ }
27
+ }
28
+ recalc()
29
+ watching = true
30
+ const reset = clientSize.y.onChange(recalc)
31
+
32
+ return () => {
33
+ watching = false
34
+ reset()
35
+ }
36
+ }, [])
37
+ }
38
+
9
39
  /**
10
40
  * Get the clientSize x|y as a motionValue
11
41
  *
@@ -30,23 +30,22 @@ export function useElementScroll(
30
30
  const element = ref?.current
31
31
  if (!element) return () => {}
32
32
 
33
- const setProgress = (offset: number, maxOffset: number, value: MotionValue) => {
34
- value.set(!offset && !maxOffset ? noScroll : offset / maxOffset)
35
- }
36
-
37
33
  const updater = () => {
38
34
  sync.read(() => {
39
35
  const { scrollLeft, scrollTop, scrollWidth, scrollHeight, offsetWidth, offsetHeight } =
40
36
  element
41
37
 
38
+ const xMax = Math.max(0, scrollWidth - offsetWidth)
39
+ const yMax = Math.max(0, scrollHeight - offsetHeight)
40
+
42
41
  values.x.set(scrollLeft)
43
42
  values.y.set(scrollTop)
44
- values.xMax.set(scrollWidth - offsetWidth)
45
- values.yMax.set(scrollHeight - offsetHeight)
43
+ values.xMax.set(xMax)
44
+ values.yMax.set(yMax)
46
45
 
47
46
  // Set 0-1 progress
48
- setProgress(scrollLeft, scrollWidth - offsetWidth, values.xProgress)
49
- setProgress(scrollTop, scrollHeight - offsetHeight, values.yProgress)
47
+ values.xProgress.set(!scrollLeft && !xMax ? noScroll : scrollLeft / xMax)
48
+ values.yProgress.set(!scrollTop && !yMax ? noScroll : scrollTop / yMax)
50
49
  })
51
50
  }
52
51
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/framer-utils",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "3.0.4",
5
+ "version": "3.1.1",
6
6
  "sideEffects": false,
7
7
  "scripts": {
8
8
  "dev": "tsc -W"
@@ -15,10 +15,10 @@
15
15
  }
16
16
  },
17
17
  "devDependencies": {
18
- "@graphcommerce/eslint-config-pwa": "^4.0.5",
19
- "@graphcommerce/prettier-config-pwa": "^4.0.3",
18
+ "@graphcommerce/eslint-config-pwa": "^4.1.3",
19
+ "@graphcommerce/prettier-config-pwa": "^4.0.5",
20
20
  "@graphcommerce/typescript-config-pwa": "^4.0.2",
21
- "@playwright/test": "^1.19.2"
21
+ "@playwright/test": "^1.20.1"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "framer-motion": "^6.2.4",