Skip to content

Commit 8d8333c

Browse files
committed
main 🧊 add browser api block
1 parent 74ae3a3 commit 8d8333c

File tree

79 files changed

+231
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+231
-63
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook for getting information about battery status
55
* @category Browser
66
*
7+
* @browserapi navigator.getBattery https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery
8+
*
79
* @returns {UseBatteryStateReturn} Object containing battery information & Battery API support
810
*
911
* @example

‎packages/core/src/bundle/hooks/useBluetooth/useBluetooth.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook for getting information about bluetooth
55
* @category Browser
66
*
7+
* @browserapi navigator.bluetooth https://developer.mozilla.org/en-US/docs/Web/API/Navigator/bluetooth
8+
*
79
* @param {boolean} [options.acceptAllDevices=false] The options to request all Bluetooth devices
810
* @param {Array<BluetoothLEScanFilter>} [options.filters] Array of filters to apply when scanning Bluetooth devices
911
* @param {Array<BluetoothServiceUUID>} [options.optionalServices] Array of optional services that the application can use

‎packages/core/src/bundle/hooks/useBoolean/useBoolean.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
/**
33
* @name useBoolean
4-
* @description - Hook provides a boolean state and a function to toggle the boolean value
4+
* @description - Hook provides opportunity to manage boolean state
55
* @category Utilities
66
*
77
* @param {boolean} [initialValue=false] The initial boolean value

‎packages/core/src/bundle/hooks/useBrowserLanguage/useBrowserLanguage.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const subscribe = (callback) => {
1010
* @description - Hook that returns the current browser language
1111
* @category Browser
1212
*
13+
* @browserapi navigator.language https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
14+
*
1315
* @returns {string} The current browser language
1416
*
1517
* @example

‎packages/core/src/bundle/hooks/useClipboard/useClipboard.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const legacyCopyToClipboard = (value) => {
1616
* @description - Hook that manages a copy to clipboard
1717
* @category Browser
1818
*
19+
* @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard
20+
*
1921
* @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled
2022
* @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state
2123
*

‎packages/core/src/bundle/hooks/useCounter/useCounter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
/**
33
* @name useCounter
4-
* @description - Hook that manages a counter with increment, decrement, reset, and set functionalities
4+
* @description - Hook that manages a counter
55
* @category Utilities
66
*
77
* @overload

‎packages/core/src/bundle/hooks/useCssVar/useCssVar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getElement } from '@/utils/helpers';
33
import { useRefState } from '../useRefState/useRefState';
44
/**
55
* @name useCssVar
6-
* @description - Hook that returns the value of a CSS variable
6+
* @description - Hook that returns the value of a css variable
77
* @category Utilities
88
*
99
* @overload

‎packages/core/src/bundle/hooks/useDebounceCallback/useDebounceCallback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { debounce } from '@/utils/helpers';
33
import { useEvent } from '../useEvent/useEvent';
44
/**
55
* @name useDebounceCallback
6-
* @description - Hook that creates a debounced callback and returns a stable reference of it
6+
* @description - Hook that creates a debounced callback
77
* @category Utilities
88
*
99
* @template Params The type of the params

‎packages/core/src/bundle/hooks/useDebounceValue/useDebounceValue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
22
import { useDebounceCallback } from '../useDebounceCallback/useDebounceCallback';
33
/**
44
* @name useDebounceValue
5-
* @description - Hook that creates a debounced value and returns a stable reference of it
5+
* @description - Hook that creates a debounced value
66
* @category Utilities
77
*
88
* @template Value The type of the value

‎packages/core/src/bundle/hooks/useDeviceMotion/useDeviceMotion.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { throttle } from '@/utils/helpers';
55
* @description - Hook that work with device motion
66
* @category Utilities
77
*
8+
* @browserapi DeviceMotionEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceMotionEvent
9+
*
810
* @param {number} [delay=1000] The delay in milliseconds
911
* @param {(event: DeviceMotionEvent) => void} [callback] The callback function to be invoked
1012
* @param {boolean} [enabled=true] Whether to enable the hook

‎packages/core/src/bundle/hooks/useDeviceOrientation/useDeviceOrientation.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that provides the current device orientation
55
* @category Sensors
66
*
7+
* @browserapi DeviceOrientationEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceOrientationEvent
8+
*
79
* @returns {UseDeviceOrientationReturn} The current device orientation
810
*
911
* @example

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useEffect, useState } from 'react';
22
/**
33
* @name useDevicePixelRatio
4-
* @description - Hook that returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device
4+
* @description - Hook that returns the device's pixel ratio
55
* @category Utilities
66
*
7+
* @browserapi window.devicePixelRatio https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
8+
*
79
* @returns {UseDevicePixelRatioReturn} The ratio and supported flag
810
*
911
* @example

‎packages/core/src/bundle/hooks/useDidUpdate/useDidUpdate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useRef } from 'react';
22
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
33
/**
44
* @name useDidUpdate
5-
* @description – Hook that behaves like useEffect, but skips the effect on the initial render
5+
* @description – Hook that triggers the effect callback on updates
66
* @category Lifecycle
77
*
88
* @param {EffectCallback} effect The effect callback

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { getElement, isTarget } from '@/utils/helpers';
33
import { useRefState } from '../useRefState/useRefState';
44
/**
55
* @name useDisplayMedia
6-
* @description - Hook that provides screen sharing functionality using the Display Media API
6+
* @description - Hook that provides screen sharing functionality
77
* @category Browser
88
*
9+
* @browserapi mediaDevices.getDisplayMedia https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia
10+
*
911
* @overload
1012
* @template Target The target video element
1113
* @param {Target} target The target video element to display the media stream

‎packages/core/src/bundle/hooks/useEyeDropper/useEyeDropper.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useState } from 'react';
44
* @description - Hook that gives you access to the eye dropper
55
* @category Browser
66
*
7+
* @browserapi EyeDropper https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper
8+
*
79
* @param {string} [initialValue=undefined] The initial value for the eye dropper
810
* @returns {UseEyeDropperReturn} An object containing the supported status, the value and the open method
911
*

‎packages/core/src/bundle/hooks/useFps/useFps.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that measures frames per second
55
* @category Sensors
66
*
7+
* @browserapi requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
8+
*
79
* @returns {number} A number which determines frames per second
810
*
911
* @example

‎packages/core/src/bundle/hooks/useGamepad/useGamepad.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useRaf } from '../useRaf/useRaf';
55
* @description - Hook for getting information about gamepad
66
* @category Browser
77
*
8+
* @browserapi navigator.getGamepads https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getGamepads
9+
*
810
* @returns {UseGamepadStateReturn} An object containing the gamepad information
911
*
1012
* @example
@@ -62,4 +64,39 @@ export const useGamepad = () => {
6264
gamepads: Object.values(gamepads)
6365
};
6466
};
65-
export { mapGamepadToXbox360Controller } from './helpers';
67+
export const mapGamepadToXbox360Controller = (gamepad) => ({
68+
buttons: {
69+
a: gamepad.buttons[0],
70+
b: gamepad.buttons[1],
71+
x: gamepad.buttons[2],
72+
y: gamepad.buttons[3]
73+
},
74+
bumper: {
75+
left: gamepad.buttons[4],
76+
right: gamepad.buttons[5]
77+
},
78+
triggers: {
79+
left: gamepad.buttons[6],
80+
right: gamepad.buttons[7]
81+
},
82+
stick: {
83+
left: {
84+
horizontal: gamepad.axes[0],
85+
vertical: gamepad.axes[1],
86+
button: gamepad.buttons[10]
87+
},
88+
right: {
89+
horizontal: gamepad.axes[2],
90+
vertical: gamepad.axes[3],
91+
button: gamepad.buttons[11]
92+
}
93+
},
94+
dpad: {
95+
up: gamepad.buttons[12],
96+
down: gamepad.buttons[13],
97+
left: gamepad.buttons[14],
98+
right: gamepad.buttons[15]
99+
},
100+
back: gamepad.buttons[8],
101+
start: gamepad.buttons[9]
102+
});

‎packages/core/src/bundle/hooks/useGeolocation/useGeolocation.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that returns the current geolocation
55
* @category Browser
66
*
7+
* @browserapi navigator.geolocation https://developer.mozilla.org/en-US/docs/Web/API/Navigator/geolocation
8+
*
79
* @param {boolean} [params.enableHighAccuracy] Enable high accuracy
810
* @param {number} [params.maximumAge] Maximum age
911
* @param {number} [params.timeout] Timeout

‎packages/core/src/bundle/hooks/useLocalStorage/useLocalStorage.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useStorage } from '../useStorage/useStorage';
44
* @description - Hook that manages local storage value
55
* @category Browser
66
*
7+
* @browserapi window.localStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
8+
*
79
* @template Value The type of the value
810
* @param {string} key The key of the storage
911
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage

‎packages/core/src/bundle/hooks/useMediaQuery/useMediaQuery.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const getServerSnapshot = () => false;
55
* @description - Hook that manages a media query
66
* @category Browser
77
*
8+
* @browserapi window.matchMedia https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
9+
*
810
* @param {string} query The media query string
911
* @returns {boolean} A boolean indicating if the media query matches
1012
*

‎packages/core/src/bundle/hooks/useMemory/useMemory.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useInterval } from '../useInterval/useInterval';
55
* @description - Hook that gives you current memory usage
66
* @category Browser
77
*
8+
* @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory
9+
*
810
* @returns {UseMemoryReturn} An object containing the current memory usage
911
*
1012
* @example

‎packages/core/src/bundle/hooks/useNetwork/useNetwork.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const getConnection = () => navigator?.connection || navigator?.mozConnec
55
* @description - Hook to track network status
66
* @category Sensors
77
*
8+
* @browserapi navigator.connection https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection
9+
*
810
* @returns {UseNetworkReturn} An object containing the network status
911
*
1012
* @example

‎packages/core/src/bundle/hooks/useOnline/useOnline.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const subscribe = (callback) => {
1414
* @description - Hook that manages if the user is online
1515
* @category Sensors
1616
*
17+
* @browserapi navigator.onLine https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine
18+
*
1719
* @returns {boolean} A boolean indicating if the user is online
1820
*
1921
* @example

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that returns the current screen orientation
55
* @category Browser
66
*
7+
* @browserapi window.screen.orientation https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
8+
*
79
* @returns {UseOrientationReturn} An object containing the current screen orientation
810
*
911
* @example

‎packages/core/src/bundle/hooks/useOtpCredential/useOtpCredential.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useRef, useState } from 'react';
44
* @description - Hook that creates an otp credential
55
* @category Browser
66
*
7+
* @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials
8+
*
79
* @overload
810
* @param {UseOtpCredentialCallback} callback The callback function to be invoked
911
* @returns {UseOtpCredentialReturn}

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useRef, useState } from 'react';
44
* @description - Hook that allows you to observe performance entries
55
* @category Sensors
66
*
7+
* @browserapi PerformanceObserver https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver
8+
*
79
* @param {UsePerformanceObserverOptions} options The options for the performance observer
810
* @param {PerformanceObserverCallback} callback The function to handle performance entries
911
* @returns {object} An object containing the observer's support status and methods to start and stop the observer

‎packages/core/src/bundle/hooks/usePermission/usePermission.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useEvent } from '../useEvent/useEvent';
55
* @description - Hook that gives you the state of permission
66
* @category Browser
77
*
8+
* @browserapi navigator.permissions https://developer.mozilla.org/en-US/docs/Web/API/Navigator/permissions
9+
*
810
* @param {UsePermissionName} permissionDescriptorName - The permission name
911
* @param {boolean} [options.enabled=true] - Whether the permission is enabled
1012
* @returns {UsePermissionReturn} An object containing the state and the supported status
@@ -13,8 +15,8 @@ import { useEvent } from '../useEvent/useEvent';
1315
* const { state, supported, query } = usePermission('microphone');
1416
*/
1517
export const usePermission = (permissionDescriptorName, options) => {
16-
const [state, setState] = useState('prompt');
1718
const supported = typeof navigator !== 'undefined' && 'permissions' in navigator;
19+
const [state, setState] = useState('prompt');
1820
const enabled = options?.enabled ?? true;
1921
const permissionDescriptor = { name: permissionDescriptorName };
2022
const query = useEvent(async () => {

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that provides reactive pointer lock
55
* @category Sensors
66
*
7+
* @browserapi pointerLockElement https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerLockElement
8+
*
79
* @returns {UsePointerLockReturn} An object containing the pointer lock element and functions to interact with the pointer lock
810
*
911
* @example

‎packages/core/src/bundle/hooks/usePreferredLanguages/usePreferredLanguages.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const subscribe = (callback) => {
1212
* @description Hook that returns a browser preferred languages from navigator
1313
* @category Browser
1414
*
15+
* @browserapi navigator.languages https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages
16+
*
1517
* @returns {readonly string[]} An array of strings representing the user's preferred languages
1618
*
1719
* @example

‎packages/core/src/bundle/hooks/useRaf/useRaf.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useRef, useState } from 'react';
44
* @description - Hook that defines the logic for raf callback
55
* @category Utilities
66
*
7+
* @browserapi requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
8+
*
79
* @param {UseRafCallback} callback The callback to execute
810
* @param {number} [options.delay] The delay between each frame in milliseconds
911
* @param {boolean} [options.enabled=true] Whether the callback should be enabled

‎packages/core/src/bundle/hooks/useResizeObserver/useResizeObserver.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useRefState } from '../useRefState/useRefState';
66
* @description - Hook that gives you resize observer state
77
* @category Browser
88
*
9+
* @browserapi ResizeObserver https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
10+
*
911
* @overload
1012
* @template Target The target element
1113
* @param {boolean} [options.enabled=true] The IntersectionObserver options

‎packages/core/src/bundle/hooks/useScreenOrientation/useScreenOrientation.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that provides the current screen orientation
55
* @category Sensors
66
*
7+
* @browserapi screen.orientation https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
8+
*
79
* @returns {useScreenOrientationReturn} The current screen orientation
810
*
911
* @example

‎packages/core/src/bundle/hooks/useSessionStorage/useSessionStorage.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useStorage } from '../useStorage/useStorage';
44
* @description - Hook that manages session storage value
55
* @category Browser
66
*
7+
* @browserapi sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
8+
*
79
* @template Value The type of the value
810
* @param {string} key The key of the storage
911
* @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage

‎packages/core/src/bundle/hooks/useTextSelection/useTextSelection.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const getRangesSelection = (selection) => {
99
* @description - Hook that manages the text selection
1010
* @category Sensors
1111
*
12+
* @browserapi document.getSelection https://developer.mozilla.org/en-US/docs/Web/API/Document/getSelection
13+
*
1214
* @returns {UseTextSelectionReturn} An object containing the current text selection
1315
*
1416
* @example

‎packages/core/src/bundle/hooks/useThrottleCallback/useThrottleCallback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { throttle } from '@/utils/helpers';
33
import { useEvent } from '../useEvent/useEvent';
44
/**
55
* @name useThrottleCallback
6-
* @description - Hook that creates a throttled callback and returns a stable reference of it
6+
* @description - Hook that creates a throttled callback
77
* @category Utilities
88
*
99
* @template Params The type of the params

‎packages/core/src/bundle/hooks/useThrottleValue/useThrottleValue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
22
import { useThrottleCallback } from '../useThrottleCallback/useThrottleCallback';
33
/**
44
* @name useThrottleValue
5-
* @description - Hook that creates a throttled value and returns a stable reference of it
5+
* @description - Hook that creates a throttled value
66
* @category Utilities
77
*
88
* @template Value The type of the value

‎packages/core/src/bundle/hooks/useVibrate/useVibrate.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useEffect, useRef, useState } from 'react';
44
* @description - Hook that provides vibrate api
55
* @category Browser
66
*
7+
* @browserapi navigator.vibrate https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate
8+
*
79
* @overload
810
* @param {UseVibratePattern} options.pattern The pattern for vibration
911
* @param {number} [options.interval=0] Time in milliseconds between vibrations

0 commit comments

Comments
 (0)