Skip to content

Commit 5852bc7

Browse files
committed
main 🧊 update demos for throttle value, add strong support cond
1 parent 9a42fc8 commit 5852bc7

29 files changed

Lines changed: 210 additions & 142 deletions

File tree

packages/core/src/bundle/hooks/useBattery/useBattery.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import { useEffect, useState } from 'react';
1414
*/
1515
export const useBattery = () => {
1616
const supported =
17-
typeof navigator !== 'undefined' &&
18-
'getBattery' in navigator &&
19-
typeof navigator.getBattery === 'function';
17+
typeof navigator !== 'undefined' && 'getBattery' in navigator && !!navigator.getBattery;
2018
const [value, setValue] = useState({
2119
loading: supported,
2220
level: 0,

packages/core/src/bundle/hooks/useDevicePixelRatio/useDevicePixelRatio.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { useEffect, useRef, useState } from 'react';
1616
export const useDevicePixelRatio = (callback) => {
1717
const supported =
1818
typeof window !== 'undefined' &&
19-
typeof window.matchMedia === 'function' &&
19+
'matchMedia' in window &&
20+
!!window.matchMedia &&
21+
'devicePixelRatio' in window &&
2022
typeof window.devicePixelRatio === 'number';
2123
const [value, setValue] = useState(supported ? window.devicePixelRatio : 1);
2224
const internalCallbackRef = useRef(callback);

packages/core/src/bundle/hooks/useDisplayMedia/useDisplayMedia.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const useDisplayMedia = (...params) => {
3434
typeof navigator !== 'undefined' &&
3535
'mediaDevices' in navigator &&
3636
!!navigator.mediaDevices &&
37-
'getDisplayMedia' in navigator.mediaDevices;
37+
'getDisplayMedia' in navigator.mediaDevices &&
38+
!!navigator.mediaDevices.getDisplayMedia;
3839
const target = isTarget(params[0]) ? params[0] : undefined;
3940
const options = params[1] ? params[1] : params[0];
4041
const immediately = options?.immediately ?? false;

packages/core/src/bundle/hooks/useFileSystemAccess/useFileSystemAccess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const useFileSystemAccess = (options = {}) => {
2222
typeof window !== 'undefined' &&
2323
'showOpenFilePicker' in window &&
2424
'showSaveFilePicker' in window &&
25-
typeof window.showOpenFilePicker === 'function' &&
26-
typeof window.showSaveFilePicker === 'function';
25+
!!window.showOpenFilePicker &&
26+
!!window.showSaveFilePicker;
2727
const dataType = options.dataType ?? 'Text';
2828
const handleRef = useRef(undefined);
2929
const [data, setData] = useState();

packages/core/src/bundle/hooks/useOrientation/useOrientation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { useEffect, useRef, useState } from 'react';
1515
*/
1616
export const useOrientation = (callback) => {
1717
const supported =
18-
typeof window !== 'undefined' && 'screen' in window && 'orientation' in window.screen;
18+
typeof window !== 'undefined' &&
19+
'screen' in window &&
20+
'orientation' in window.screen &&
21+
!!window.screen.orientation;
1922
const orientation = supported ? window.screen.orientation : {};
2023
const [value, setValue] = useState({
2124
angle: orientation.angle ?? 0,

packages/core/src/bundle/hooks/useParallax/useParallax.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export const useParallax = (...params) => {
7979
'DeviceOrientationEvent' in window &&
8080
!!window.DeviceOrientationEvent &&
8181
'screen' in window &&
82-
'orientation' in window.screen;
82+
'orientation' in window.screen &&
83+
!!window.screen.orientation;
8384
const orientation = supported ? window.screen.orientation : undefined;
8485
const internalRef = useRefState();
8586
const internalOptionsRef = useRef(options);

packages/core/src/bundle/hooks/usePerformanceObserver/usePerformanceObserver.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { useEffect, useRef, useState } from 'react';
1515
* const { supported, entries, start, stop } = usePerformanceObserver();
1616
*/
1717
export const usePerformanceObserver = (options, callback) => {
18-
const supported = typeof window !== 'undefined' && !!window.PerformanceObserver;
18+
const supported =
19+
typeof window !== 'undefined' &&
20+
'PerformanceObserver' in window &&
21+
!!window.PerformanceObserver;
1922
const [entries, setEntries] = useState([]);
2023
const observerRef = useRef(undefined);
2124
const internalCallback = useRef(callback);

packages/core/src/bundle/hooks/usePictureInPicture/usePictureInPicture.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const usePictureInPicture = (...params) => {
3030
const supported =
3131
typeof document !== 'undefined' &&
3232
'pictureInPictureEnabled' in document &&
33-
!!document.pictureInPictureEnabled;
33+
!!document.pictureInPictureEnabled &&
34+
'exitPictureInPicture' in document &&
35+
!!document.exitPictureInPicture;
3436
const target = isTarget(params[0]) ? params[0] : undefined;
3537
const options = (target ? params[1] : params[0]) ?? {};
3638
const [opened, setOpened] = useState(false);

packages/core/src/bundle/hooks/usePointerLock/usePointerLock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const usePointerLock = () => {
1616
const supported =
1717
typeof document !== 'undefined' &&
1818
'pointerLockElement' in document &&
19-
typeof document.exitPointerLock === 'function';
19+
'exitPointerLock' in document &&
20+
!!document.exitPointerLock;
2021
const [element, setElement] = useState();
2122
useEffect(() => {
2223
if (!supported) return;

packages/core/src/bundle/hooks/useVirtualKeyboard/useVirtualKeyboard.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import { useEffect, useState } from 'react';
1717
*/
1818
export const useVirtualKeyboard = (initialValue = false) => {
1919
const supported =
20-
(typeof window !== 'undefined' && 'visualViewport' in window) ||
21-
(typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);
20+
(typeof window !== 'undefined' && 'visualViewport' in window && !!window.visualViewport) ||
21+
(typeof navigator !== 'undefined' &&
22+
'virtualKeyboard' in navigator &&
23+
!!navigator.virtualKeyboard);
2224
const [opened, setOpened] = useState(initialValue);
2325
const hide = () => {
2426
if (!navigator.virtualKeyboard) return;

0 commit comments

Comments
 (0)