@stacksjs/browser 0.65.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/README.md +58 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +90 -0
- package/dist/utils/base.d.ts +2 -0
- package/dist/utils/debounce.d.ts +1 -0
- package/dist/utils/function.d.ts +18 -0
- package/dist/utils/guards.d.ts +28 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/math.d.ts +3 -0
- package/dist/utils/promise.d.ts +58 -0
- package/dist/utils/regex.d.ts +3 -0
- package/dist/utils/retry.d.ts +2 -0
- package/dist/utils/sleep.d.ts +37 -0
- package/dist/utils/throttle.d.ts +20 -0
- package/dist/utils/vendors.d.ts +4 -0
- package/package.json +44 -0
- package/src/index.ts +1 -0
- package/src/utils/base.ts +12 -0
- package/src/utils/debounce.ts +1 -0
- package/src/utils/function.ts +32 -0
- package/src/utils/guards.ts +39 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/math.ts +30 -0
- package/src/utils/promise.ts +134 -0
- package/src/utils/regex.ts +42 -0
- package/src/utils/retry.ts +43 -0
- package/src/utils/sleep.ts +125 -0
- package/src/utils/throttle.ts +47 -0
- package/src/utils/vendors.ts +258 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export type NonNegativeInteger<T extends number> = number extends T
|
|
2
|
+
? never
|
|
3
|
+
: `${T}` extends `-${string}` | `${string}.${string}`
|
|
4
|
+
? never
|
|
5
|
+
: T
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pauses execution for a specified number of milliseconds.
|
|
9
|
+
* @param ms The number of milliseconds to pause execution.
|
|
10
|
+
* @returns A promise that resolves after the specified delay.
|
|
11
|
+
*/
|
|
12
|
+
export function sleep(ms: number): Promise<void> {
|
|
13
|
+
if (ms < 0 || !Number.isInteger(ms)) {
|
|
14
|
+
throw new Error('sleep() requires a non-negative integer')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pauses execution for a specified number of milliseconds.
|
|
22
|
+
* @param ms The number of milliseconds to pause execution.
|
|
23
|
+
* @returns A promise that resolves after the specified delay.
|
|
24
|
+
*/
|
|
25
|
+
export function wait(ms: number): Promise<void> {
|
|
26
|
+
if (ms < 0 || !Number.isInteger(ms)) {
|
|
27
|
+
throw new Error('wait() requires a non-negative integer')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pauses execution for a specified number of milliseconds.
|
|
35
|
+
* @param ms The number of milliseconds to pause execution.
|
|
36
|
+
* @returns A promise that resolves after the specified delay.
|
|
37
|
+
*/
|
|
38
|
+
export function delay(ms: number): Promise<void> {
|
|
39
|
+
if (ms < 0 || !Number.isInteger(ms)) {
|
|
40
|
+
throw new Error('delay() requires a non-negative integer')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type WaitOptions = number | {
|
|
47
|
+
interval?: number
|
|
48
|
+
timeout?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Pauses execution until a specified condition is met.
|
|
53
|
+
* @param condition The condition to wait for.
|
|
54
|
+
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
55
|
+
* @returns A promise that resolves when the condition is met.
|
|
56
|
+
*/
|
|
57
|
+
export function waitUntil(condition: () => boolean, options: WaitOptions = {}): Promise<void> {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
const { interval, timeout } = normalizeOptions(options)
|
|
60
|
+
|
|
61
|
+
// Immediately resolve if the condition is initially true
|
|
62
|
+
if (condition()) {
|
|
63
|
+
resolve()
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const check = () => {
|
|
68
|
+
if (condition()) {
|
|
69
|
+
resolve()
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
setTimeout(check, interval)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (timeout) {
|
|
77
|
+
setTimeout(resolve, timeout)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
check()
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeOptions(options: WaitOptions): { interval: number, timeout: number } {
|
|
85
|
+
if (typeof options === 'number') {
|
|
86
|
+
return { interval: 100, timeout: options }
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
interval: options.interval ?? 100,
|
|
90
|
+
timeout: options.timeout ?? 0,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Pauses execution while a specified condition is met.
|
|
96
|
+
* @param condition The condition to wait while.
|
|
97
|
+
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
98
|
+
* @returns A promise that resolves when the condition is no longer met.
|
|
99
|
+
*/
|
|
100
|
+
export function waitWhile(condition: () => boolean, options: WaitOptions = {}): Promise<void> {
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
const { interval = 100, timeout = 0 } = options
|
|
103
|
+
|
|
104
|
+
// Immediately resolve if the condition is initially false
|
|
105
|
+
if (!condition()) {
|
|
106
|
+
resolve()
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const check = () => {
|
|
111
|
+
if (!condition()) {
|
|
112
|
+
resolve()
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
setTimeout(check, interval)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (timeout) {
|
|
120
|
+
setTimeout(resolve, timeout)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
check()
|
|
124
|
+
})
|
|
125
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttle a function.
|
|
3
|
+
*
|
|
4
|
+
* @param {Function} fn - The function to throttle.
|
|
5
|
+
* @param {number} [wait] - The time to wait between function calls.
|
|
6
|
+
* @returns {Function} - A new function that throttles the calls to the original function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // logs window dimensions at most every 250ms
|
|
11
|
+
* window.addEventListener(
|
|
12
|
+
* "resize",
|
|
13
|
+
* throttle(function (evt) {
|
|
14
|
+
* console.log(window.innerWidth)
|
|
15
|
+
* console.log(window.innerHeight)
|
|
16
|
+
* }, 250)
|
|
17
|
+
* )
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
// eslint-disable-next-line ts/no-unsafe-function-type
|
|
21
|
+
export function throttle(fn: Function, wait = 300) {
|
|
22
|
+
let inThrottle: boolean
|
|
23
|
+
let lastFn: ReturnType<typeof setTimeout>
|
|
24
|
+
let lastTime: number
|
|
25
|
+
|
|
26
|
+
return function (this: unknown, ...args: any[]): void {
|
|
27
|
+
if (!inThrottle) {
|
|
28
|
+
fn.apply(this, args)
|
|
29
|
+
|
|
30
|
+
lastTime = Date.now()
|
|
31
|
+
inThrottle = true
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
clearTimeout(lastFn)
|
|
35
|
+
|
|
36
|
+
lastFn = setTimeout(
|
|
37
|
+
() => {
|
|
38
|
+
if (Date.now() - lastTime >= wait) {
|
|
39
|
+
fn.apply(this, args) // Use 'this' directly
|
|
40
|
+
lastTime = Date.now()
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
Math.max(wait - (Date.now() - lastTime), 0),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
export {
|
|
2
|
+
asyncComputed,
|
|
3
|
+
autoResetRef,
|
|
4
|
+
breakpointsAntDesign,
|
|
5
|
+
breakpointsBootstrapV5,
|
|
6
|
+
breakpointsMasterCss,
|
|
7
|
+
breakpointsQuasar,
|
|
8
|
+
breakpointsSematic,
|
|
9
|
+
breakpointsTailwind,
|
|
10
|
+
breakpointsVuetify,
|
|
11
|
+
cloneFnJSON,
|
|
12
|
+
computedAsync,
|
|
13
|
+
computedEager,
|
|
14
|
+
computedInject,
|
|
15
|
+
computedWithControl,
|
|
16
|
+
controlledComputed,
|
|
17
|
+
controlledRef,
|
|
18
|
+
createEventHook,
|
|
19
|
+
createFetch,
|
|
20
|
+
createGlobalState,
|
|
21
|
+
createInjectionState,
|
|
22
|
+
createReactiveFn,
|
|
23
|
+
createReusableTemplate,
|
|
24
|
+
createSharedComposable,
|
|
25
|
+
createTemplatePromise,
|
|
26
|
+
createUnrefFn,
|
|
27
|
+
customStorageEventName,
|
|
28
|
+
debouncedRef,
|
|
29
|
+
debouncedWatch,
|
|
30
|
+
defaultDocument,
|
|
31
|
+
defaultLocation,
|
|
32
|
+
defaultNavigator,
|
|
33
|
+
defaultWindow,
|
|
34
|
+
eagerComputed,
|
|
35
|
+
executeTransition,
|
|
36
|
+
extendRef,
|
|
37
|
+
formatTimeAgo,
|
|
38
|
+
getSSRHandler,
|
|
39
|
+
ignorableWatch,
|
|
40
|
+
injectLocal,
|
|
41
|
+
isDefined,
|
|
42
|
+
makeDestructurable,
|
|
43
|
+
mapGamepadToXbox360Controller,
|
|
44
|
+
onClickOutside,
|
|
45
|
+
onKeyDown,
|
|
46
|
+
onKeyPressed,
|
|
47
|
+
onKeyStroke,
|
|
48
|
+
onKeyUp,
|
|
49
|
+
onLongPress,
|
|
50
|
+
onStartTyping,
|
|
51
|
+
pausableWatch,
|
|
52
|
+
provideLocal,
|
|
53
|
+
reactify,
|
|
54
|
+
reactifyObject,
|
|
55
|
+
reactiveComputed,
|
|
56
|
+
reactiveOmit,
|
|
57
|
+
reactivePick,
|
|
58
|
+
refAutoReset,
|
|
59
|
+
refDebounced,
|
|
60
|
+
refDefault,
|
|
61
|
+
refThrottled,
|
|
62
|
+
refWithControl,
|
|
63
|
+
resolveRef,
|
|
64
|
+
resolveUnref,
|
|
65
|
+
setSSRHandler,
|
|
66
|
+
syncRef,
|
|
67
|
+
syncRefs,
|
|
68
|
+
templateRef,
|
|
69
|
+
throttledRef,
|
|
70
|
+
throttledWatch,
|
|
71
|
+
toReactive,
|
|
72
|
+
tryOnBeforeMount,
|
|
73
|
+
tryOnBeforeUnmount,
|
|
74
|
+
tryOnMounted,
|
|
75
|
+
tryOnScopeDispose,
|
|
76
|
+
tryOnUnmounted,
|
|
77
|
+
unrefElement,
|
|
78
|
+
until,
|
|
79
|
+
useActiveElement,
|
|
80
|
+
useAnimate,
|
|
81
|
+
useArrayDifference,
|
|
82
|
+
useArrayEvery,
|
|
83
|
+
useArrayFilter,
|
|
84
|
+
useArrayFind,
|
|
85
|
+
useArrayFindIndex,
|
|
86
|
+
useArrayIncludes,
|
|
87
|
+
useArrayMap,
|
|
88
|
+
useArrayReduce,
|
|
89
|
+
useArraySome,
|
|
90
|
+
useArrayUnique,
|
|
91
|
+
useAsyncQueue,
|
|
92
|
+
useAsyncState,
|
|
93
|
+
useBase64,
|
|
94
|
+
useBattery,
|
|
95
|
+
useBluetooth,
|
|
96
|
+
useBreakpoints,
|
|
97
|
+
useBroadcastChannel,
|
|
98
|
+
useBrowserLocation,
|
|
99
|
+
useCached,
|
|
100
|
+
useClipboard,
|
|
101
|
+
useClipboardItems,
|
|
102
|
+
useCloned,
|
|
103
|
+
useColorMode,
|
|
104
|
+
useConfirmDialog,
|
|
105
|
+
useCounter,
|
|
106
|
+
useCssVar,
|
|
107
|
+
useCurrentElement,
|
|
108
|
+
useCycleList,
|
|
109
|
+
useDark,
|
|
110
|
+
useDateFormat,
|
|
111
|
+
useDebounce,
|
|
112
|
+
useDebouncedRefHistory,
|
|
113
|
+
useDebounceFn,
|
|
114
|
+
useDeviceMotion,
|
|
115
|
+
useDeviceOrientation,
|
|
116
|
+
useDevicePixelRatio,
|
|
117
|
+
useDevicesList,
|
|
118
|
+
useDisplayMedia,
|
|
119
|
+
useDocumentVisibility,
|
|
120
|
+
useDraggable,
|
|
121
|
+
useDropZone,
|
|
122
|
+
useElementBounding,
|
|
123
|
+
useElementByPoint,
|
|
124
|
+
useElementHover,
|
|
125
|
+
useElementSize,
|
|
126
|
+
useElementVisibility,
|
|
127
|
+
useEventBus,
|
|
128
|
+
useEventListener,
|
|
129
|
+
useEventSource,
|
|
130
|
+
useEyeDropper,
|
|
131
|
+
useFavicon,
|
|
132
|
+
useFetch,
|
|
133
|
+
useFileDialog,
|
|
134
|
+
useFileSystemAccess,
|
|
135
|
+
useFocus,
|
|
136
|
+
useFocusWithin,
|
|
137
|
+
useFps,
|
|
138
|
+
useFullscreen,
|
|
139
|
+
useGamepad,
|
|
140
|
+
useGeolocation,
|
|
141
|
+
useIdle,
|
|
142
|
+
useImage,
|
|
143
|
+
useInfiniteScroll,
|
|
144
|
+
useIntersectionObserver,
|
|
145
|
+
useInterval,
|
|
146
|
+
useIntervalFn,
|
|
147
|
+
useKeyModifier,
|
|
148
|
+
useLastChanged,
|
|
149
|
+
useLocalStorage,
|
|
150
|
+
useMagicKeys,
|
|
151
|
+
useManualRefHistory,
|
|
152
|
+
useMediaControls,
|
|
153
|
+
useMediaQuery,
|
|
154
|
+
useMemoize,
|
|
155
|
+
useMemory,
|
|
156
|
+
useMounted,
|
|
157
|
+
useMouse,
|
|
158
|
+
useMouseInElement,
|
|
159
|
+
useMousePressed,
|
|
160
|
+
useMutationObserver,
|
|
161
|
+
useNavigatorLanguage,
|
|
162
|
+
useNetwork,
|
|
163
|
+
useNow,
|
|
164
|
+
useObjectUrl,
|
|
165
|
+
useOffsetPagination,
|
|
166
|
+
useOnline,
|
|
167
|
+
usePageLeave,
|
|
168
|
+
useParallax,
|
|
169
|
+
useParentElement,
|
|
170
|
+
usePerformanceObserver,
|
|
171
|
+
usePermission,
|
|
172
|
+
usePointer,
|
|
173
|
+
usePointerLock,
|
|
174
|
+
usePointerSwipe,
|
|
175
|
+
usePreferredColorScheme,
|
|
176
|
+
usePreferredContrast,
|
|
177
|
+
usePreferredDark,
|
|
178
|
+
usePreferredLanguages,
|
|
179
|
+
usePreferredReducedMotion,
|
|
180
|
+
usePrevious,
|
|
181
|
+
useRafFn,
|
|
182
|
+
useRefHistory,
|
|
183
|
+
useResizeObserver,
|
|
184
|
+
useScreenOrientation,
|
|
185
|
+
useScreenSafeArea,
|
|
186
|
+
useScriptTag,
|
|
187
|
+
useScroll,
|
|
188
|
+
useScrollLock,
|
|
189
|
+
useSessionStorage,
|
|
190
|
+
useShare,
|
|
191
|
+
useSorted,
|
|
192
|
+
useSpeechRecognition,
|
|
193
|
+
useSpeechSynthesis,
|
|
194
|
+
useStepper,
|
|
195
|
+
useStorage,
|
|
196
|
+
useStorageAsync,
|
|
197
|
+
useStyleTag,
|
|
198
|
+
useSupported,
|
|
199
|
+
useSwipe,
|
|
200
|
+
useTemplateRefsList,
|
|
201
|
+
useTextareaAutosize,
|
|
202
|
+
useTextDirection,
|
|
203
|
+
useTextSelection,
|
|
204
|
+
useThrottle,
|
|
205
|
+
useThrottledRefHistory,
|
|
206
|
+
useThrottleFn,
|
|
207
|
+
useTimeAgo,
|
|
208
|
+
useTimeout,
|
|
209
|
+
useTimeoutFn,
|
|
210
|
+
useTimeoutPoll,
|
|
211
|
+
useTimestamp,
|
|
212
|
+
useTitle,
|
|
213
|
+
useToggle,
|
|
214
|
+
useToNumber,
|
|
215
|
+
useToString,
|
|
216
|
+
useTransition,
|
|
217
|
+
useUrlSearchParams,
|
|
218
|
+
useUserMedia,
|
|
219
|
+
useVibrate,
|
|
220
|
+
useVirtualList,
|
|
221
|
+
useVModel,
|
|
222
|
+
useVModels,
|
|
223
|
+
useWakeLock,
|
|
224
|
+
useWebNotification,
|
|
225
|
+
useWebSocket,
|
|
226
|
+
useWebWorker,
|
|
227
|
+
useWebWorkerFn,
|
|
228
|
+
useWindowFocus,
|
|
229
|
+
useWindowScroll,
|
|
230
|
+
useWindowSize,
|
|
231
|
+
watchArray,
|
|
232
|
+
watchAtMost,
|
|
233
|
+
watchDebounced,
|
|
234
|
+
watchDeep,
|
|
235
|
+
watchIgnorable,
|
|
236
|
+
watchImmediate,
|
|
237
|
+
watchOnce,
|
|
238
|
+
watchPausable,
|
|
239
|
+
watchThrottled,
|
|
240
|
+
watchTriggerable,
|
|
241
|
+
watchWithFilter,
|
|
242
|
+
whenever,
|
|
243
|
+
} from '@vueuse/core'
|
|
244
|
+
|
|
245
|
+
export type {
|
|
246
|
+
// Head,
|
|
247
|
+
HeadObject,
|
|
248
|
+
HeadObjectPlain,
|
|
249
|
+
} from '@vueuse/head'
|
|
250
|
+
|
|
251
|
+
export {
|
|
252
|
+
createHead,
|
|
253
|
+
Head,
|
|
254
|
+
HeadVuePlugin,
|
|
255
|
+
renderHeadToString,
|
|
256
|
+
} from '@vueuse/head'
|
|
257
|
+
|
|
258
|
+
export { default as readableSize } from 'pretty-bytes'
|