@siberiacancode/reactuse 0.0.114 → 0.0.116
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/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +2 -0
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -0
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +29 -0
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -0
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +30 -17
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +90 -85
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
- package/dist/esm/index.mjs +253 -251
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +2 -0
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +37 -0
- package/dist/types/hooks/useLongPress/useLongPress.d.ts +27 -25
- package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,94 +1,99 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useDeviceOrientation as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
deviceOrientationRollAdjust:
|
|
10
|
-
deviceOrientationTiltAdjust:
|
|
11
|
-
mouseRollAdjust:
|
|
12
|
-
mouseTiltAdjust:
|
|
13
|
-
} =
|
|
1
|
+
import { useState as x, useEffect as B } from "react";
|
|
2
|
+
import { useDeviceOrientation as C } from "../useDeviceOrientation/useDeviceOrientation.mjs";
|
|
3
|
+
import { useRefState as D } from "../useRefState/useRefState.mjs";
|
|
4
|
+
import { useScreenOrientation as P } from "../useScreenOrientation/useScreenOrientation.mjs";
|
|
5
|
+
import { isTarget as X } from "../../utils/helpers/isTarget.mjs";
|
|
6
|
+
import { getElement as Y } from "../../utils/helpers/getElement.mjs";
|
|
7
|
+
const G = (...a) => {
|
|
8
|
+
const n = X(a[0]) ? a[0] : void 0, p = a[1] ? a[1] : a[0], i = D(), s = P(), e = C(), {
|
|
9
|
+
deviceOrientationRollAdjust: g = (o) => o,
|
|
10
|
+
deviceOrientationTiltAdjust: f = (o) => o,
|
|
11
|
+
mouseRollAdjust: b = (o) => o,
|
|
12
|
+
mouseTiltAdjust: y = (o) => o
|
|
13
|
+
} = p ?? {}, [u, O] = x({
|
|
14
14
|
roll: 0,
|
|
15
15
|
tilt: 0,
|
|
16
16
|
source: "mouse"
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
17
|
+
});
|
|
18
|
+
return B(() => {
|
|
19
|
+
if (!n && !i.state) return;
|
|
20
|
+
const o = n ? Y(n) : i.current;
|
|
21
|
+
if (!o) return;
|
|
22
|
+
console.log("element", o);
|
|
23
|
+
const m = (v) => {
|
|
24
|
+
const { left: h, top: k } = o.getBoundingClientRect(), w = h + window.scrollX, R = k + window.scrollY, c = () => e.supported && (e.value.alpha || e.value.gamma) ? "deviceOrientation" : "mouse", T = () => {
|
|
25
|
+
if (c() === "deviceOrientation") {
|
|
26
|
+
let t;
|
|
27
|
+
switch (s.value.orientationType) {
|
|
28
|
+
case "landscape-primary":
|
|
29
|
+
t = e.value.gamma / 90;
|
|
30
|
+
break;
|
|
31
|
+
case "landscape-secondary":
|
|
32
|
+
t = -e.value.gamma / 90;
|
|
33
|
+
break;
|
|
34
|
+
case "portrait-primary":
|
|
35
|
+
t = -e.value.beta / 90;
|
|
36
|
+
break;
|
|
37
|
+
case "portrait-secondary":
|
|
38
|
+
t = e.value.beta / 90;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
t = -e.value.beta / 90;
|
|
42
|
+
}
|
|
43
|
+
return g(t);
|
|
44
|
+
} else {
|
|
45
|
+
const t = v.pageY - R, r = o.getBoundingClientRect().height, l = -(t - r / 2) / r;
|
|
46
|
+
return b(l);
|
|
47
|
+
}
|
|
48
|
+
}, j = () => {
|
|
49
|
+
if (c() === "deviceOrientation") {
|
|
50
|
+
let t;
|
|
51
|
+
switch (s.value.orientationType) {
|
|
52
|
+
case "landscape-primary":
|
|
53
|
+
t = e.value.beta / 90;
|
|
54
|
+
break;
|
|
55
|
+
case "landscape-secondary":
|
|
56
|
+
t = -e.value.beta / 90;
|
|
57
|
+
break;
|
|
58
|
+
case "portrait-primary":
|
|
59
|
+
t = e.value.gamma / 90;
|
|
60
|
+
break;
|
|
61
|
+
case "portrait-secondary":
|
|
62
|
+
t = -e.value.gamma / 90;
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
t = e.value.gamma / 90;
|
|
66
|
+
}
|
|
67
|
+
return f(t);
|
|
68
|
+
} else {
|
|
69
|
+
const t = v.pageX - w, r = o.getBoundingClientRect().width, l = (t - r / 2) / r;
|
|
70
|
+
return y(l);
|
|
71
|
+
}
|
|
72
|
+
}, A = c(), E = T(), S = j();
|
|
73
|
+
O({
|
|
74
|
+
roll: E,
|
|
75
|
+
source: A,
|
|
76
|
+
tilt: S
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return document.addEventListener("mousemove", m), () => {
|
|
80
|
+
document.removeEventListener("mousemove", m);
|
|
81
|
+
};
|
|
76
82
|
}, [
|
|
77
|
-
|
|
78
|
-
i.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
value: m
|
|
83
|
+
n,
|
|
84
|
+
i.state,
|
|
85
|
+
s.value.angle,
|
|
86
|
+
s.value.orientationType,
|
|
87
|
+
e.value.gamma,
|
|
88
|
+
e.value.beta,
|
|
89
|
+
e.value.alpha,
|
|
90
|
+
e.value.absolute
|
|
91
|
+
]), n ? { value: u } : {
|
|
92
|
+
ref: i,
|
|
93
|
+
value: u
|
|
89
94
|
};
|
|
90
95
|
};
|
|
91
96
|
export {
|
|
92
|
-
|
|
97
|
+
G as useParallax
|
|
93
98
|
};
|
|
94
99
|
//# sourceMappingURL=useParallax.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParallax.mjs","sources":["../../../../src/hooks/useParallax/useParallax.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useDeviceOrientation } from '../useDeviceOrientation/useDeviceOrientation';\nimport {
|
|
1
|
+
{"version":3,"file":"useParallax.mjs","sources":["../../../../src/hooks/useParallax/useParallax.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useDeviceOrientation } from '../useDeviceOrientation/useDeviceOrientation';\nimport { useRefState } from '../useRefState/useRefState';\nimport { useScreenOrientation } from '../useScreenOrientation/useScreenOrientation';\n\n/** The use parallax value type */\nexport interface UseParallaxValue {\n /** Roll value. Scaled to `-0.5 ~ 0.5` */\n roll: number;\n /** Sensor source, can be `mouse` or `deviceOrientation` */\n source: 'deviceOrientation' | 'mouse';\n /** Tilt value. Scaled to `-0.5 ~ 0.5` */\n tilt: number;\n}\n\n/** The use parallax options type */\nexport interface UseParallaxOptions {\n /** Device orientation roll adjust function */\n deviceOrientationRollAdjust?: (value: number) => number;\n /** Device orientation tilt adjust function */\n deviceOrientationTiltAdjust?: (value: number) => number;\n /** Mouse roll adjust function */\n mouseRollAdjust?: (value: number) => number;\n /** Mouse tilt adjust function */\n mouseTiltAdjust?: (value: number) => number;\n}\n\ninterface UseParallaxReturn {\n value: UseParallaxValue;\n}\n\nexport interface UseParallax {\n (target: HookTarget, options?: UseParallaxOptions): UseParallaxReturn;\n\n <Target extends Element>(\n options?: UseParallaxOptions,\n target?: never\n ): UseParallaxReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useParallax\n * @description - Hook to help create parallax effect\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn} An object of parallax values\n *\n * @example\n * const { value } = useParallax(ref);\n *\n * @overload\n * @template Target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn & { ref: StateRef<Target> }} An object of parallax values\n *\n * @example\n * const { ref, value } = useParallax();\n */\nexport const useParallax = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseParallaxOptions | undefined;\n\n const internalRef = useRefState<Element>();\n\n const screenOrientation = useScreenOrientation();\n const deviceOrientation = useDeviceOrientation();\n\n const {\n deviceOrientationRollAdjust = (value) => value,\n deviceOrientationTiltAdjust = (value) => value,\n mouseRollAdjust = (value) => value,\n mouseTiltAdjust = (value) => value\n } = (options ?? {}) as UseParallaxOptions;\n\n const [value, setValue] = useState({\n roll: 0,\n tilt: 0,\n source: 'mouse'\n });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n console.log('element', element);\n const onMouseMove = (event: MouseEvent) => {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n\n const getSource = () => {\n const isDeviceOrientation =\n deviceOrientation.supported &&\n (deviceOrientation.value.alpha || deviceOrientation.value.gamma);\n\n if (isDeviceOrientation) return 'deviceOrientation';\n return 'mouse';\n };\n\n const getRoll = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-primary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-secondary':\n value = deviceOrientation.value.beta! / 90;\n break;\n default:\n value = -deviceOrientation.value.beta! / 90;\n }\n return deviceOrientationRollAdjust(value);\n } else {\n const y = event.pageY - elementPositionY;\n const height = element.getBoundingClientRect().height;\n const value = -(y - height / 2) / height;\n return mouseRollAdjust(value);\n }\n };\n\n const getTilt = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.beta! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n default:\n value = deviceOrientation.value.gamma! / 90;\n }\n return deviceOrientationTiltAdjust(value);\n } else {\n const x = event.pageX - elementPositionX;\n const width = element.getBoundingClientRect().width;\n const value = (x - width / 2) / width;\n return mouseTiltAdjust(value);\n }\n };\n\n const source = getSource();\n const roll = getRoll();\n const tilt = getTilt();\n\n setValue({\n roll,\n source,\n tilt\n });\n };\n\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [\n target,\n internalRef.state,\n screenOrientation.value.angle,\n screenOrientation.value.orientationType,\n deviceOrientation.value.gamma,\n deviceOrientation.value.beta,\n deviceOrientation.value.alpha,\n deviceOrientation.value.absolute\n ]);\n\n if (target) return { value };\n\n return {\n ref: internalRef,\n value\n };\n}) as UseParallax;\n"],"names":["useParallax","params","target","isTarget","options","internalRef","useRefState","screenOrientation","useScreenOrientation","deviceOrientation","useDeviceOrientation","deviceOrientationRollAdjust","value","deviceOrientationTiltAdjust","mouseRollAdjust","mouseTiltAdjust","setValue","useState","useEffect","element","getElement","onMouseMove","event","left","top","elementPositionX","elementPositionY","getSource","getRoll","y","height","getTilt","x","width","source","roll","tilt"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowFocus.mjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useWindowFocus.mjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useWindowFocus.html}\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":";AAcO,MAAMA,IAAiB,MAAM;AAClC,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK;AAE5C,SAAAC,EAAU,MAAM;AACR,UAAAC,IAAU,MAAMH,EAAW,EAAI,GAC/BI,IAAS,MAAMJ,EAAW,EAAK;AAE9B,kBAAA,iBAAiB,SAASG,CAAO,GACjC,OAAA,iBAAiB,QAAQC,CAAM,GAE/B,MAAM;AACJ,aAAA,oBAAoB,SAASD,CAAO,GACpC,OAAA,oBAAoB,QAAQC,CAAM;AAAA,IAC3C;AAAA,EAAA,CACD,GAEML;AACT;"}
|