@reactuses/core 2.2.7 → 2.2.9

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/index.cjs CHANGED
@@ -48,6 +48,7 @@ var index$4 = createUpdateEffect(React.useLayoutEffect);
48
48
 
49
49
  var _a;
50
50
  const isFunction$1 = (val) => typeof val === "function";
51
+ const isString = (val) => typeof val === "string";
51
52
  const isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
52
53
  const isBrowser = typeof window !== "undefined";
53
54
  const isNavigator = typeof navigator !== "undefined";
@@ -3877,11 +3878,11 @@ function useOnline() {
3877
3878
  return online;
3878
3879
  }
3879
3880
 
3880
- const defaultState = {
3881
+ const defaultState$1 = {
3881
3882
  angle: 0,
3882
3883
  type: "landscape-primary"
3883
3884
  };
3884
- function useOrientation(initialState = defaultState) {
3885
+ function useOrientation(initialState = defaultState$1) {
3885
3886
  const [state, setState] = React.useState(initialState);
3886
3887
  React.useEffect(() => {
3887
3888
  const screen = window.screen;
@@ -4049,19 +4050,19 @@ function useDropZone(target, onDrop) {
4049
4050
  return over;
4050
4051
  }
4051
4052
 
4052
- var __defProp$1 = Object.defineProperty;
4053
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
4054
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
4055
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
4056
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4057
- var __spreadValues$1 = (a, b) => {
4053
+ var __defProp$2 = Object.defineProperty;
4054
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
4055
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
4056
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
4057
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4058
+ var __spreadValues$2 = (a, b) => {
4058
4059
  for (var prop in b || (b = {}))
4059
- if (__hasOwnProp$1.call(b, prop))
4060
- __defNormalProp$1(a, prop, b[prop]);
4061
- if (__getOwnPropSymbols$1)
4062
- for (var prop of __getOwnPropSymbols$1(b)) {
4063
- if (__propIsEnum$1.call(b, prop))
4064
- __defNormalProp$1(a, prop, b[prop]);
4060
+ if (__hasOwnProp$3.call(b, prop))
4061
+ __defNormalProp$2(a, prop, b[prop]);
4062
+ if (__getOwnPropSymbols$3)
4063
+ for (var prop of __getOwnPropSymbols$3(b)) {
4064
+ if (__propIsEnum$3.call(b, prop))
4065
+ __defNormalProp$2(a, prop, b[prop]);
4065
4066
  }
4066
4067
  return a;
4067
4068
  };
@@ -4089,7 +4090,7 @@ function useFileDialog(options = {}) {
4089
4090
  if (!inputRef.current) {
4090
4091
  return;
4091
4092
  }
4092
- const _options = __spreadValues$1(__spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options), localOptions);
4093
+ const _options = __spreadValues$2(__spreadValues$2(__spreadValues$2({}, DEFAULT_OPTIONS), options), localOptions);
4093
4094
  inputRef.current.multiple = _options.multiple;
4094
4095
  inputRef.current.accept = _options.accept;
4095
4096
  inputRef.current.capture = _options.capture;
@@ -4176,21 +4177,21 @@ function useScroll(target, options = {}) {
4176
4177
  return [x, y, isScrolling, arrivedState, directions];
4177
4178
  }
4178
4179
 
4179
- var __defProp = Object.defineProperty;
4180
+ var __defProp$1 = Object.defineProperty;
4180
4181
  var __defProps = Object.defineProperties;
4181
4182
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4182
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4183
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4184
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4185
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4186
- var __spreadValues = (a, b) => {
4183
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
4184
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
4185
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
4186
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4187
+ var __spreadValues$1 = (a, b) => {
4187
4188
  for (var prop in b || (b = {}))
4188
- if (__hasOwnProp.call(b, prop))
4189
- __defNormalProp(a, prop, b[prop]);
4190
- if (__getOwnPropSymbols)
4191
- for (var prop of __getOwnPropSymbols(b)) {
4192
- if (__propIsEnum.call(b, prop))
4193
- __defNormalProp(a, prop, b[prop]);
4189
+ if (__hasOwnProp$2.call(b, prop))
4190
+ __defNormalProp$1(a, prop, b[prop]);
4191
+ if (__getOwnPropSymbols$2)
4192
+ for (var prop of __getOwnPropSymbols$2(b)) {
4193
+ if (__propIsEnum$2.call(b, prop))
4194
+ __defNormalProp$1(a, prop, b[prop]);
4194
4195
  }
4195
4196
  return a;
4196
4197
  };
@@ -4219,8 +4220,8 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
4219
4220
  var _a, _b;
4220
4221
  const savedLoadMore = useLatest(onLoadMore);
4221
4222
  const direction = (_a = options.direction) != null ? _a : "bottom";
4222
- const state = useScroll(target, __spreadProps(__spreadValues({}, options), {
4223
- offset: __spreadValues({
4223
+ const state = useScroll(target, __spreadProps(__spreadValues$1({}, options), {
4224
+ offset: __spreadValues$1({
4224
4225
  [direction]: (_b = options.distance) != null ? _b : 0
4225
4226
  }, options.offset)
4226
4227
  }));
@@ -5284,12 +5285,289 @@ function useEyeDropper() {
5284
5285
  return [isSupported, open];
5285
5286
  }
5286
5287
 
5288
+ /*! js-cookie v3.0.5 | MIT */
5289
+ /* eslint-disable no-var */
5290
+ function assign (target) {
5291
+ for (var i = 1; i < arguments.length; i++) {
5292
+ var source = arguments[i];
5293
+ for (var key in source) {
5294
+ target[key] = source[key];
5295
+ }
5296
+ }
5297
+ return target
5298
+ }
5299
+ /* eslint-enable no-var */
5300
+
5301
+ /* eslint-disable no-var */
5302
+ var defaultConverter = {
5303
+ read: function (value) {
5304
+ if (value[0] === '"') {
5305
+ value = value.slice(1, -1);
5306
+ }
5307
+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
5308
+ },
5309
+ write: function (value) {
5310
+ return encodeURIComponent(value).replace(
5311
+ /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
5312
+ decodeURIComponent
5313
+ )
5314
+ }
5315
+ };
5316
+ /* eslint-enable no-var */
5317
+
5318
+ /* eslint-disable no-var */
5319
+
5320
+ function init (converter, defaultAttributes) {
5321
+ function set (name, value, attributes) {
5322
+ if (typeof document === 'undefined') {
5323
+ return
5324
+ }
5325
+
5326
+ attributes = assign({}, defaultAttributes, attributes);
5327
+
5328
+ if (typeof attributes.expires === 'number') {
5329
+ attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
5330
+ }
5331
+ if (attributes.expires) {
5332
+ attributes.expires = attributes.expires.toUTCString();
5333
+ }
5334
+
5335
+ name = encodeURIComponent(name)
5336
+ .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
5337
+ .replace(/[()]/g, escape);
5338
+
5339
+ var stringifiedAttributes = '';
5340
+ for (var attributeName in attributes) {
5341
+ if (!attributes[attributeName]) {
5342
+ continue
5343
+ }
5344
+
5345
+ stringifiedAttributes += '; ' + attributeName;
5346
+
5347
+ if (attributes[attributeName] === true) {
5348
+ continue
5349
+ }
5350
+
5351
+ // Considers RFC 6265 section 5.2:
5352
+ // ...
5353
+ // 3. If the remaining unparsed-attributes contains a %x3B (";")
5354
+ // character:
5355
+ // Consume the characters of the unparsed-attributes up to,
5356
+ // not including, the first %x3B (";") character.
5357
+ // ...
5358
+ stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
5359
+ }
5360
+
5361
+ return (document.cookie =
5362
+ name + '=' + converter.write(value, name) + stringifiedAttributes)
5363
+ }
5364
+
5365
+ function get (name) {
5366
+ if (typeof document === 'undefined' || (arguments.length && !name)) {
5367
+ return
5368
+ }
5369
+
5370
+ // To prevent the for loop in the first place assign an empty array
5371
+ // in case there are no cookies at all.
5372
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
5373
+ var jar = {};
5374
+ for (var i = 0; i < cookies.length; i++) {
5375
+ var parts = cookies[i].split('=');
5376
+ var value = parts.slice(1).join('=');
5377
+
5378
+ try {
5379
+ var found = decodeURIComponent(parts[0]);
5380
+ jar[found] = converter.read(value, found);
5381
+
5382
+ if (name === found) {
5383
+ break
5384
+ }
5385
+ } catch (e) {}
5386
+ }
5387
+
5388
+ return name ? jar[name] : jar
5389
+ }
5390
+
5391
+ return Object.create(
5392
+ {
5393
+ set,
5394
+ get,
5395
+ remove: function (name, attributes) {
5396
+ set(
5397
+ name,
5398
+ '',
5399
+ assign({}, attributes, {
5400
+ expires: -1
5401
+ })
5402
+ );
5403
+ },
5404
+ withAttributes: function (attributes) {
5405
+ return init(this.converter, assign({}, this.attributes, attributes))
5406
+ },
5407
+ withConverter: function (converter) {
5408
+ return init(assign({}, this.converter, converter), this.attributes)
5409
+ }
5410
+ },
5411
+ {
5412
+ attributes: { value: Object.freeze(defaultAttributes) },
5413
+ converter: { value: Object.freeze(converter) }
5414
+ }
5415
+ )
5416
+ }
5417
+
5418
+ var api = init(defaultConverter, { path: '/' });
5419
+
5420
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
5421
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
5422
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
5423
+ var __objRest = (source, exclude) => {
5424
+ var target = {};
5425
+ for (var prop in source)
5426
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
5427
+ target[prop] = source[prop];
5428
+ if (source != null && __getOwnPropSymbols$1)
5429
+ for (var prop of __getOwnPropSymbols$1(source)) {
5430
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
5431
+ target[prop] = source[prop];
5432
+ }
5433
+ return target;
5434
+ };
5435
+ function useCookie(key, options = {
5436
+ defaultValue: ""
5437
+ }) {
5438
+ const _a = options, { defaultValue, csrData } = _a, cookieOptions = __objRest(_a, ["defaultValue", "csrData"]);
5439
+ const [cookieValue, setCookieValue] = React.useState(defaultValue);
5440
+ useDeepCompareEffect(() => {
5441
+ const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : isFunction$1(defaultValue) ? defaultValue() : defaultValue;
5442
+ const getStoredValue = () => {
5443
+ const raw = api.get(key);
5444
+ if (raw !== void 0 && raw !== null) {
5445
+ return raw;
5446
+ } else {
5447
+ if (data === void 0) {
5448
+ api.remove(key);
5449
+ } else {
5450
+ api.set(key, data, cookieOptions);
5451
+ }
5452
+ return data;
5453
+ }
5454
+ };
5455
+ setCookieValue(getStoredValue());
5456
+ }, [csrData, defaultValue, key, cookieOptions]);
5457
+ const updateCookie = React.useCallback(
5458
+ (newValue) => {
5459
+ const value = isFunction$1(newValue) ? newValue(cookieValue) : newValue;
5460
+ if (value === void 0) {
5461
+ api.remove(key);
5462
+ } else {
5463
+ api.set(key, value, cookieOptions);
5464
+ }
5465
+ setCookieValue(value);
5466
+ },
5467
+ [key, cookieValue]
5468
+ );
5469
+ const refreshCookie = React.useCallback(() => {
5470
+ const cookieValue2 = api.get(key);
5471
+ if (isString(cookieValue2)) {
5472
+ setCookieValue(cookieValue2);
5473
+ }
5474
+ }, [key]);
5475
+ return Object.freeze([cookieValue, updateCookie, refreshCookie]);
5476
+ }
5477
+
5478
+ function useDoubleClick({
5479
+ target,
5480
+ latency = 300,
5481
+ onSingleClick = () => {
5482
+ },
5483
+ onDoubleClick = () => {
5484
+ }
5485
+ }) {
5486
+ const element = useLatestElement(target);
5487
+ const handle = React.useCallback(
5488
+ (onSingleClick2, onDoubleClick2) => {
5489
+ let count = 0;
5490
+ return (e) => {
5491
+ if (e.type === "touchend") {
5492
+ e.stopPropagation();
5493
+ e.preventDefault();
5494
+ }
5495
+ count += 1;
5496
+ setTimeout(() => {
5497
+ if (count === 1) {
5498
+ onSingleClick2(e);
5499
+ } else if (count === 2) {
5500
+ onDoubleClick2(e);
5501
+ }
5502
+ count = 0;
5503
+ }, latency);
5504
+ };
5505
+ },
5506
+ [latency]
5507
+ );
5508
+ const handleClick = handle(onSingleClick, onDoubleClick);
5509
+ const handleTouchEnd = handle(onSingleClick, onDoubleClick);
5510
+ useEventListener("click", handleClick, element);
5511
+ useEventListener("touchend", handleTouchEnd, element, { passive: false });
5512
+ }
5513
+
5514
+ var __defProp = Object.defineProperty;
5515
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5516
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5517
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5518
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5519
+ var __spreadValues = (a, b) => {
5520
+ for (var prop in b || (b = {}))
5521
+ if (__hasOwnProp.call(b, prop))
5522
+ __defNormalProp(a, prop, b[prop]);
5523
+ if (__getOwnPropSymbols)
5524
+ for (var prop of __getOwnPropSymbols(b)) {
5525
+ if (__propIsEnum.call(b, prop))
5526
+ __defNormalProp(a, prop, b[prop]);
5527
+ }
5528
+ return a;
5529
+ };
5530
+ function useSetState(initialState) {
5531
+ const [state, _setState] = React.useState(initialState);
5532
+ const setState = React.useCallback(
5533
+ (statePartial) => _setState((current) => __spreadValues(__spreadValues({}, current), typeof statePartial === "function" ? statePartial(current) : statePartial)),
5534
+ []
5535
+ );
5536
+ return [state, setState];
5537
+ }
5538
+
5539
+ const defaultState = {
5540
+ x: 0,
5541
+ y: 0,
5542
+ width: 0,
5543
+ height: 0,
5544
+ top: 0,
5545
+ left: 0,
5546
+ bottom: 0,
5547
+ right: 0
5548
+ };
5549
+ function useMeasure(target, options = {}) {
5550
+ const [rect, setRect] = React.useState(defaultState);
5551
+ const stop = useResizeObserver(
5552
+ target,
5553
+ (entries) => {
5554
+ if (entries[0]) {
5555
+ const { x, y, width, height, top, left, bottom, right } = entries[0].contentRect;
5556
+ setRect({ x, y, width, height, top, left, bottom, right });
5557
+ }
5558
+ },
5559
+ options
5560
+ );
5561
+ return [rect, stop];
5562
+ }
5563
+
5287
5564
  exports.getHMSTime = getHMSTime;
5288
5565
  exports.useActiveElement = useActiveElement;
5289
5566
  exports.useAsyncEffect = useAsyncEffect;
5290
5567
  exports.useClickOutside = useClickOutSide;
5291
5568
  exports.useClipboard = useClipBorad;
5292
5569
  exports.useControlled = useControlled;
5570
+ exports.useCookie = useCookie;
5293
5571
  exports.useCountDown = useCountDown;
5294
5572
  exports.useCounter = useCounter;
5295
5573
  exports.useCustomCompareEffect = useCustomCompareEffect;
@@ -5299,6 +5577,7 @@ exports.useDebounce = useDebounce;
5299
5577
  exports.useDebounceFn = useDebounceFn;
5300
5578
  exports.useDeepCompareEffect = useDeepCompareEffect;
5301
5579
  exports.useDocumentVisibility = useDocumentVisibility;
5580
+ exports.useDoubleClick = useDoubleClick;
5302
5581
  exports.useDraggable = useDraggable;
5303
5582
  exports.useDropZone = useDropZone;
5304
5583
  exports.useElementBounding = useElementBounding;
@@ -5324,6 +5603,7 @@ exports.useKeyModifier = useKeyModifier;
5324
5603
  exports.useLatest = useLatest;
5325
5604
  exports.useLocalStorage = useLocalStorage;
5326
5605
  exports.useLongPress = useLongPress;
5606
+ exports.useMeasure = useMeasure;
5327
5607
  exports.useMediaDevices = index$3;
5328
5608
  exports.useMediaQuery = useMediaQuery;
5329
5609
  exports.useMount = useMount;
@@ -5352,6 +5632,7 @@ exports.useScroll = useScroll;
5352
5632
  exports.useScrollIntoView = useScrollIntoView;
5353
5633
  exports.useScrollLock = useScrollLock;
5354
5634
  exports.useSessionStorage = useSessionStorage;
5635
+ exports.useSetState = useSetState;
5355
5636
  exports.useSticky = useSticky;
5356
5637
  exports.useSupported = useSupported;
5357
5638
  exports.useTextDirection = useTextDirection;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import react__default, { MutableRefObject, useEffect, useLayoutEffect, Dispatch, SetStateAction, DependencyList, EffectCallback, RefObject, CSSProperties } from 'react';
3
3
  import * as lodash from 'lodash';
4
+ import Cookies from 'js-cookie';
4
5
 
5
6
  declare function usePrevious<T>(state: T): T | undefined;
6
7
 
@@ -45,9 +46,9 @@ declare function useSessionStorage(key: string, defaults: boolean, options?: Use
45
46
  declare function useSessionStorage<T>(key: string, defaults: T, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
46
47
  declare function useSessionStorage<T = unknown>(key: string, defaults: null, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
47
48
 
48
- declare type Fn = (this: any, ...args: any[]) => any;
49
- declare type Stoppable = [boolean, Fn, Fn];
50
- declare type PointerType = "mouse" | "touch" | "pen";
49
+ type Fn = (this: any, ...args: any[]) => any;
50
+ type Stoppable = [boolean, Fn, Fn];
51
+ type PointerType = "mouse" | "touch" | "pen";
51
52
  interface Position {
52
53
  x: number;
53
54
  y: number;
@@ -166,11 +167,11 @@ declare function useTimeout(ms?: number, options?: UseTimeoutFnOptions): Stoppab
166
167
 
167
168
  declare function useMountedState(): () => boolean;
168
169
 
169
- declare type TargetValue<T> = T | undefined | null;
170
- declare type TargetType = HTMLElement | Element | Window | Document | EventTarget;
171
- declare type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
170
+ type TargetValue<T> = T | undefined | null;
171
+ type TargetType = HTMLElement | Element | Window | Document | EventTarget;
172
+ type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
172
173
 
173
- declare type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
174
+ type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
174
175
  declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
175
176
  declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
176
177
  declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
@@ -180,7 +181,7 @@ declare function useEventListener(eventName: string, handler: (...p: any) => voi
180
181
 
181
182
  declare function useCounter(initialValue?: number | (() => number), max?: number | null, min?: number | null): readonly [number, (newState: number | ((prev: number) => number) | (() => number)) => void, (delta?: number) => void, (delta?: number) => void, () => void];
182
183
 
183
- declare type RafLoopReturns = readonly [() => void, () => void, () => boolean];
184
+ type RafLoopReturns = readonly [() => void, () => void, () => boolean];
184
185
  declare function useRafFn(callback: FrameRequestCallback, initiallyActive?: boolean): RafLoopReturns;
185
186
 
186
187
  interface IListener<T, U = void> {
@@ -218,7 +219,7 @@ declare function useFavicon(href: string, baseUrl?: string, rel?: string): void;
218
219
 
219
220
  declare function useMutationObserver(callback: MutationCallback, target: BasicTarget, options?: MutationObserverInit): () => void;
220
221
 
221
- declare type DepsEqualFnType<TDeps extends DependencyList> = (prevDeps: TDeps, nextDeps: TDeps) => boolean;
222
+ type DepsEqualFnType<TDeps extends DependencyList> = (prevDeps: TDeps, nextDeps: TDeps) => boolean;
222
223
  declare function useCustomCompareEffect<TDeps extends DependencyList>(effect: EffectCallback, deps: TDeps, depsEqual: DepsEqualFnType<TDeps>): void;
223
224
 
224
225
  declare function useDeepCompareEffect(effect: EffectCallback, deps: DependencyList): void;
@@ -260,12 +261,12 @@ interface UseScriptTagOptions {
260
261
  */
261
262
  attrs?: Record<string, string>;
262
263
  }
263
- declare type Status = "idle" | "loading" | "ready" | "error";
264
+ type Status = "idle" | "loading" | "ready" | "error";
264
265
  declare function useScriptTag(src: string, onLoaded?: (el: HTMLScriptElement) => void, options?: UseScriptTagOptions): readonly [HTMLScriptElement | null, Status, (waitForScriptLoad?: boolean) => Promise<HTMLScriptElement | boolean>, () => void];
265
266
 
266
- declare type IState = PermissionState | "";
267
- declare type DescriptorNamePolyfill = "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "notifications" | "payment-handler" | "persistent-storage" | "push" | "speaker";
268
- declare type GeneralPermissionDescriptor = PermissionDescriptor | {
267
+ type IState = PermissionState | "";
268
+ type DescriptorNamePolyfill = "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "notifications" | "payment-handler" | "persistent-storage" | "push" | "speaker";
269
+ type GeneralPermissionDescriptor = PermissionDescriptor | {
269
270
  name: DescriptorNamePolyfill;
270
271
  };
271
272
  declare function usePermission(permissionDesc: GeneralPermissionDescriptor | GeneralPermissionDescriptor["name"]): IState;
@@ -296,7 +297,7 @@ declare function useMediaDevices(): {
296
297
  };
297
298
  declare const _default$3: typeof useMediaDevices;
298
299
 
299
- declare type UseTextDirectionValue = "ltr" | "rtl" | "auto";
300
+ type UseTextDirectionValue = "ltr" | "rtl" | "auto";
300
301
  interface UseTextDirectionOptions {
301
302
  /**
302
303
  * CSS Selector for the target element applying to
@@ -539,7 +540,7 @@ interface UseInfiniteScrollOptions extends UseScrollOptions {
539
540
  }
540
541
  declare function useInfiniteScroll(target: BasicTarget<HTMLElement | SVGElement>, onLoadMore: (state: ReturnType<typeof useScroll>) => void | Promise<void>, options?: UseInfiniteScrollOptions): void;
541
542
 
542
- declare type KeyModifier = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Symbol" | "SymbolLock";
543
+ type KeyModifier = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Symbol" | "SymbolLock";
543
544
  interface UseModifierOptions {
544
545
  /**
545
546
  * Event names that will prompt update to modifier states
@@ -556,8 +557,8 @@ interface UseModifierOptions {
556
557
  }
557
558
  declare function useKeyModifier(modifier: KeyModifier, options?: UseModifierOptions): boolean;
558
559
 
559
- declare type IHookStateInitialSetter<S> = () => S;
560
- declare type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
560
+ type IHookStateInitialSetter<S> = () => S;
561
+ type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
561
562
 
562
563
  interface MousePressedOptions {
563
564
  /**
@@ -579,7 +580,7 @@ interface MousePressedOptions {
579
580
  */
580
581
  initialValue?: IHookStateInitAction<boolean>;
581
582
  }
582
- declare type MouseSourceType = "mouse" | "touch" | null;
583
+ type MouseSourceType = "mouse" | "touch" | null;
583
584
  declare function useMousePressed(target?: BasicTarget, options?: MousePressedOptions): readonly [boolean, MouseSourceType];
584
585
 
585
586
  declare function useScrollLock(target: BasicTarget<HTMLElement>, initialState?: boolean): readonly [boolean, (flag: boolean) => void];
@@ -626,10 +627,10 @@ interface UseVirtualListReturn<T> {
626
627
  }
627
628
  declare function useVirtualList<T = any>(list: T[] | undefined, options: UseVirtualListOptions): UseVirtualListReturn<T>;
628
629
 
629
- declare type ColorScheme = "dark" | "light" | "no-preference";
630
+ type ColorScheme = "dark" | "light" | "no-preference";
630
631
  declare function usePreferredColorScheme(defaultState?: ColorScheme): ColorScheme;
631
632
 
632
- declare type Contrast = "more" | "less" | "custom" | "no-preference";
633
+ type Contrast = "more" | "less" | "custom" | "no-preference";
633
634
  declare function usePreferredContrast(defaultState?: Contrast): Contrast;
634
635
 
635
636
  declare function useActiveElement<T extends Element>(): T | null;
@@ -751,7 +752,7 @@ declare function useClipBorad(): readonly [
751
752
  (txt: string) => Promise<void>
752
753
  ];
753
754
 
754
- declare type EventType = MouseEvent | TouchEvent;
755
+ type EventType = MouseEvent | TouchEvent;
755
756
  declare function useClickOutSide(target: BasicTarget, handler: (evt: EventType) => void): void;
756
757
 
757
758
  declare function useCycleList<T>(list: T[], i?: number): readonly [T, (i?: number) => void, (i?: number) => void];
@@ -814,7 +815,7 @@ declare const useSticky: ({ targetElement, scrollElement, axis, nav, }: UseStick
814
815
  declare function useAsyncEffect<T extends void>(effect: () => Promise<T> | T, cleanup?: typeof effect, deps?: DependencyList): void;
815
816
 
816
817
  declare const getHMSTime: (timeDiff: number) => [string, string, string];
817
- declare const useCountDown: (time: number, format?: (number: any) => [string, string, string], callback?: () => void) => readonly [string, string, string];
818
+ declare const useCountDown: (time: number, format?: (num: number) => [string, string, string], callback?: () => void) => readonly [string, string, string];
818
819
 
819
820
  declare function useSupported(callback: () => unknown, sync?: boolean): boolean;
820
821
 
@@ -827,6 +828,28 @@ interface EyeDropperOpenReturnType {
827
828
  sRGBHex: string;
828
829
  }
829
830
  declare function useEyeDropper(): readonly [boolean, (options?: EyeDropperOpenOptions) => Promise<EyeDropperOpenReturnType>];
830
- declare type UseEyeDropperReturn = ReturnType<typeof useEyeDropper>;
831
+ type UseEyeDropperReturn = ReturnType<typeof useEyeDropper>;
831
832
 
832
- export { ColorScheme, Contrast, CursorState, EyeDropperOpenReturnType, GeneralPermissionDescriptor, IDisposable, IEvent, IEventOnce, IListener, INetworkInformation, IState, IUseNetworkState, KeyModifier, MousePressedOptions, MouseSourceType, OrientationState, RafLoopReturns, ScrollIntoViewAnimation, ScrollIntoViewParams, State, Status, Target, UseDarkOptions, UseDraggableOptions, UseElementBoundingOptions, UseEventEmitterReturn, UseEyeDropperReturn, UseFileDialogOptions, UseFpsOptions, UseFullScreenOptions, UseInfiniteScrollOptions, UseLongPressOptions, UseModifierOptions, UseScriptTagOptions, UseScrollOptions, UseStickyParams, UseTextDirectionOptions, UseTextDirectionValue, UseTimeoutFnOptions, UseVirtualListItem, UseVirtualListOptions, UseVirtualListReturn, WindowSize, getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, _default$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, _default$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, _default$1 as useOnceEffect, _default as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$5 as useUpdateEffect, _default$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
833
+ type CookieState = string | undefined;
834
+ interface CookieOptions extends Cookies.CookieAttributes {
835
+ defaultValue?: string | (() => string);
836
+ /**
837
+ * set to storage when nodata in effect, fallback to defaultValue
838
+ */
839
+ csrData?: CookieState | (() => CookieState);
840
+ }
841
+ declare function useCookie(key: string, options?: CookieOptions): readonly [CookieState, (newValue: CookieState | ((prevState: CookieState) => CookieState)) => void, () => void];
842
+
843
+ declare function useDoubleClick({ target, latency, onSingleClick, onDoubleClick, }: {
844
+ target: BasicTarget;
845
+ latency?: number;
846
+ onSingleClick?: (e?: MouseEvent | TouchEvent) => void;
847
+ onDoubleClick?: (e?: MouseEvent | TouchEvent) => void;
848
+ }): void;
849
+
850
+ declare function useSetState<T extends Record<string, any>>(initialState: T): readonly [T, (statePartial: Partial<T> | ((currentState: T) => Partial<T>)) => void];
851
+
852
+ type UseMeasureRect = Omit<DOMRectReadOnly, "toJSON">;
853
+ declare function useMeasure(target: BasicTarget, options?: ResizeObserverOptions): readonly [UseMeasureRect, () => void];
854
+
855
+ export { ColorScheme, Contrast, CookieOptions, CookieState, CursorState, EyeDropperOpenReturnType, GeneralPermissionDescriptor, IDisposable, IEvent, IEventOnce, IListener, INetworkInformation, IState, IUseNetworkState, KeyModifier, MousePressedOptions, MouseSourceType, OrientationState, RafLoopReturns, ScrollIntoViewAnimation, ScrollIntoViewParams, State, Status, Target, UseDarkOptions, UseDraggableOptions, UseElementBoundingOptions, UseEventEmitterReturn, UseEyeDropperReturn, UseFileDialogOptions, UseFpsOptions, UseFullScreenOptions, UseInfiniteScrollOptions, UseLongPressOptions, UseMeasureRect, UseModifierOptions, UseScriptTagOptions, UseScrollOptions, UseStickyParams, UseTextDirectionOptions, UseTextDirectionValue, UseTimeoutFnOptions, UseVirtualListItem, UseVirtualListOptions, UseVirtualListReturn, WindowSize, getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCookie, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, _default$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMeasure, _default$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, _default$1 as useOnceEffect, _default as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$5 as useUpdateEffect, _default$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
package/dist/index.mjs CHANGED
@@ -40,6 +40,7 @@ var index$4 = createUpdateEffect(useLayoutEffect);
40
40
 
41
41
  var _a;
42
42
  const isFunction$1 = (val) => typeof val === "function";
43
+ const isString = (val) => typeof val === "string";
43
44
  const isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
44
45
  const isBrowser = typeof window !== "undefined";
45
46
  const isNavigator = typeof navigator !== "undefined";
@@ -3869,11 +3870,11 @@ function useOnline() {
3869
3870
  return online;
3870
3871
  }
3871
3872
 
3872
- const defaultState = {
3873
+ const defaultState$1 = {
3873
3874
  angle: 0,
3874
3875
  type: "landscape-primary"
3875
3876
  };
3876
- function useOrientation(initialState = defaultState) {
3877
+ function useOrientation(initialState = defaultState$1) {
3877
3878
  const [state, setState] = useState(initialState);
3878
3879
  useEffect(() => {
3879
3880
  const screen = window.screen;
@@ -4041,19 +4042,19 @@ function useDropZone(target, onDrop) {
4041
4042
  return over;
4042
4043
  }
4043
4044
 
4044
- var __defProp$1 = Object.defineProperty;
4045
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
4046
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
4047
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
4048
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4049
- var __spreadValues$1 = (a, b) => {
4045
+ var __defProp$2 = Object.defineProperty;
4046
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
4047
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
4048
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
4049
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4050
+ var __spreadValues$2 = (a, b) => {
4050
4051
  for (var prop in b || (b = {}))
4051
- if (__hasOwnProp$1.call(b, prop))
4052
- __defNormalProp$1(a, prop, b[prop]);
4053
- if (__getOwnPropSymbols$1)
4054
- for (var prop of __getOwnPropSymbols$1(b)) {
4055
- if (__propIsEnum$1.call(b, prop))
4056
- __defNormalProp$1(a, prop, b[prop]);
4052
+ if (__hasOwnProp$3.call(b, prop))
4053
+ __defNormalProp$2(a, prop, b[prop]);
4054
+ if (__getOwnPropSymbols$3)
4055
+ for (var prop of __getOwnPropSymbols$3(b)) {
4056
+ if (__propIsEnum$3.call(b, prop))
4057
+ __defNormalProp$2(a, prop, b[prop]);
4057
4058
  }
4058
4059
  return a;
4059
4060
  };
@@ -4081,7 +4082,7 @@ function useFileDialog(options = {}) {
4081
4082
  if (!inputRef.current) {
4082
4083
  return;
4083
4084
  }
4084
- const _options = __spreadValues$1(__spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options), localOptions);
4085
+ const _options = __spreadValues$2(__spreadValues$2(__spreadValues$2({}, DEFAULT_OPTIONS), options), localOptions);
4085
4086
  inputRef.current.multiple = _options.multiple;
4086
4087
  inputRef.current.accept = _options.accept;
4087
4088
  inputRef.current.capture = _options.capture;
@@ -4168,21 +4169,21 @@ function useScroll(target, options = {}) {
4168
4169
  return [x, y, isScrolling, arrivedState, directions];
4169
4170
  }
4170
4171
 
4171
- var __defProp = Object.defineProperty;
4172
+ var __defProp$1 = Object.defineProperty;
4172
4173
  var __defProps = Object.defineProperties;
4173
4174
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4174
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4175
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4176
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4177
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4178
- var __spreadValues = (a, b) => {
4175
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
4176
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
4177
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
4178
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4179
+ var __spreadValues$1 = (a, b) => {
4179
4180
  for (var prop in b || (b = {}))
4180
- if (__hasOwnProp.call(b, prop))
4181
- __defNormalProp(a, prop, b[prop]);
4182
- if (__getOwnPropSymbols)
4183
- for (var prop of __getOwnPropSymbols(b)) {
4184
- if (__propIsEnum.call(b, prop))
4185
- __defNormalProp(a, prop, b[prop]);
4181
+ if (__hasOwnProp$2.call(b, prop))
4182
+ __defNormalProp$1(a, prop, b[prop]);
4183
+ if (__getOwnPropSymbols$2)
4184
+ for (var prop of __getOwnPropSymbols$2(b)) {
4185
+ if (__propIsEnum$2.call(b, prop))
4186
+ __defNormalProp$1(a, prop, b[prop]);
4186
4187
  }
4187
4188
  return a;
4188
4189
  };
@@ -4211,8 +4212,8 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
4211
4212
  var _a, _b;
4212
4213
  const savedLoadMore = useLatest(onLoadMore);
4213
4214
  const direction = (_a = options.direction) != null ? _a : "bottom";
4214
- const state = useScroll(target, __spreadProps(__spreadValues({}, options), {
4215
- offset: __spreadValues({
4215
+ const state = useScroll(target, __spreadProps(__spreadValues$1({}, options), {
4216
+ offset: __spreadValues$1({
4216
4217
  [direction]: (_b = options.distance) != null ? _b : 0
4217
4218
  }, options.offset)
4218
4219
  }));
@@ -5276,4 +5277,280 @@ function useEyeDropper() {
5276
5277
  return [isSupported, open];
5277
5278
  }
5278
5279
 
5279
- export { getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, index$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, index$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, index$1 as useOnceEffect, index as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, index$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
5280
+ /*! js-cookie v3.0.5 | MIT */
5281
+ /* eslint-disable no-var */
5282
+ function assign (target) {
5283
+ for (var i = 1; i < arguments.length; i++) {
5284
+ var source = arguments[i];
5285
+ for (var key in source) {
5286
+ target[key] = source[key];
5287
+ }
5288
+ }
5289
+ return target
5290
+ }
5291
+ /* eslint-enable no-var */
5292
+
5293
+ /* eslint-disable no-var */
5294
+ var defaultConverter = {
5295
+ read: function (value) {
5296
+ if (value[0] === '"') {
5297
+ value = value.slice(1, -1);
5298
+ }
5299
+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
5300
+ },
5301
+ write: function (value) {
5302
+ return encodeURIComponent(value).replace(
5303
+ /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
5304
+ decodeURIComponent
5305
+ )
5306
+ }
5307
+ };
5308
+ /* eslint-enable no-var */
5309
+
5310
+ /* eslint-disable no-var */
5311
+
5312
+ function init (converter, defaultAttributes) {
5313
+ function set (name, value, attributes) {
5314
+ if (typeof document === 'undefined') {
5315
+ return
5316
+ }
5317
+
5318
+ attributes = assign({}, defaultAttributes, attributes);
5319
+
5320
+ if (typeof attributes.expires === 'number') {
5321
+ attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
5322
+ }
5323
+ if (attributes.expires) {
5324
+ attributes.expires = attributes.expires.toUTCString();
5325
+ }
5326
+
5327
+ name = encodeURIComponent(name)
5328
+ .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
5329
+ .replace(/[()]/g, escape);
5330
+
5331
+ var stringifiedAttributes = '';
5332
+ for (var attributeName in attributes) {
5333
+ if (!attributes[attributeName]) {
5334
+ continue
5335
+ }
5336
+
5337
+ stringifiedAttributes += '; ' + attributeName;
5338
+
5339
+ if (attributes[attributeName] === true) {
5340
+ continue
5341
+ }
5342
+
5343
+ // Considers RFC 6265 section 5.2:
5344
+ // ...
5345
+ // 3. If the remaining unparsed-attributes contains a %x3B (";")
5346
+ // character:
5347
+ // Consume the characters of the unparsed-attributes up to,
5348
+ // not including, the first %x3B (";") character.
5349
+ // ...
5350
+ stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
5351
+ }
5352
+
5353
+ return (document.cookie =
5354
+ name + '=' + converter.write(value, name) + stringifiedAttributes)
5355
+ }
5356
+
5357
+ function get (name) {
5358
+ if (typeof document === 'undefined' || (arguments.length && !name)) {
5359
+ return
5360
+ }
5361
+
5362
+ // To prevent the for loop in the first place assign an empty array
5363
+ // in case there are no cookies at all.
5364
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
5365
+ var jar = {};
5366
+ for (var i = 0; i < cookies.length; i++) {
5367
+ var parts = cookies[i].split('=');
5368
+ var value = parts.slice(1).join('=');
5369
+
5370
+ try {
5371
+ var found = decodeURIComponent(parts[0]);
5372
+ jar[found] = converter.read(value, found);
5373
+
5374
+ if (name === found) {
5375
+ break
5376
+ }
5377
+ } catch (e) {}
5378
+ }
5379
+
5380
+ return name ? jar[name] : jar
5381
+ }
5382
+
5383
+ return Object.create(
5384
+ {
5385
+ set,
5386
+ get,
5387
+ remove: function (name, attributes) {
5388
+ set(
5389
+ name,
5390
+ '',
5391
+ assign({}, attributes, {
5392
+ expires: -1
5393
+ })
5394
+ );
5395
+ },
5396
+ withAttributes: function (attributes) {
5397
+ return init(this.converter, assign({}, this.attributes, attributes))
5398
+ },
5399
+ withConverter: function (converter) {
5400
+ return init(assign({}, this.converter, converter), this.attributes)
5401
+ }
5402
+ },
5403
+ {
5404
+ attributes: { value: Object.freeze(defaultAttributes) },
5405
+ converter: { value: Object.freeze(converter) }
5406
+ }
5407
+ )
5408
+ }
5409
+
5410
+ var api = init(defaultConverter, { path: '/' });
5411
+
5412
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
5413
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
5414
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
5415
+ var __objRest = (source, exclude) => {
5416
+ var target = {};
5417
+ for (var prop in source)
5418
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
5419
+ target[prop] = source[prop];
5420
+ if (source != null && __getOwnPropSymbols$1)
5421
+ for (var prop of __getOwnPropSymbols$1(source)) {
5422
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
5423
+ target[prop] = source[prop];
5424
+ }
5425
+ return target;
5426
+ };
5427
+ function useCookie(key, options = {
5428
+ defaultValue: ""
5429
+ }) {
5430
+ const _a = options, { defaultValue, csrData } = _a, cookieOptions = __objRest(_a, ["defaultValue", "csrData"]);
5431
+ const [cookieValue, setCookieValue] = useState(defaultValue);
5432
+ useDeepCompareEffect(() => {
5433
+ const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : isFunction$1(defaultValue) ? defaultValue() : defaultValue;
5434
+ const getStoredValue = () => {
5435
+ const raw = api.get(key);
5436
+ if (raw !== void 0 && raw !== null) {
5437
+ return raw;
5438
+ } else {
5439
+ if (data === void 0) {
5440
+ api.remove(key);
5441
+ } else {
5442
+ api.set(key, data, cookieOptions);
5443
+ }
5444
+ return data;
5445
+ }
5446
+ };
5447
+ setCookieValue(getStoredValue());
5448
+ }, [csrData, defaultValue, key, cookieOptions]);
5449
+ const updateCookie = useCallback(
5450
+ (newValue) => {
5451
+ const value = isFunction$1(newValue) ? newValue(cookieValue) : newValue;
5452
+ if (value === void 0) {
5453
+ api.remove(key);
5454
+ } else {
5455
+ api.set(key, value, cookieOptions);
5456
+ }
5457
+ setCookieValue(value);
5458
+ },
5459
+ [key, cookieValue]
5460
+ );
5461
+ const refreshCookie = useCallback(() => {
5462
+ const cookieValue2 = api.get(key);
5463
+ if (isString(cookieValue2)) {
5464
+ setCookieValue(cookieValue2);
5465
+ }
5466
+ }, [key]);
5467
+ return Object.freeze([cookieValue, updateCookie, refreshCookie]);
5468
+ }
5469
+
5470
+ function useDoubleClick({
5471
+ target,
5472
+ latency = 300,
5473
+ onSingleClick = () => {
5474
+ },
5475
+ onDoubleClick = () => {
5476
+ }
5477
+ }) {
5478
+ const element = useLatestElement(target);
5479
+ const handle = useCallback(
5480
+ (onSingleClick2, onDoubleClick2) => {
5481
+ let count = 0;
5482
+ return (e) => {
5483
+ if (e.type === "touchend") {
5484
+ e.stopPropagation();
5485
+ e.preventDefault();
5486
+ }
5487
+ count += 1;
5488
+ setTimeout(() => {
5489
+ if (count === 1) {
5490
+ onSingleClick2(e);
5491
+ } else if (count === 2) {
5492
+ onDoubleClick2(e);
5493
+ }
5494
+ count = 0;
5495
+ }, latency);
5496
+ };
5497
+ },
5498
+ [latency]
5499
+ );
5500
+ const handleClick = handle(onSingleClick, onDoubleClick);
5501
+ const handleTouchEnd = handle(onSingleClick, onDoubleClick);
5502
+ useEventListener("click", handleClick, element);
5503
+ useEventListener("touchend", handleTouchEnd, element, { passive: false });
5504
+ }
5505
+
5506
+ var __defProp = Object.defineProperty;
5507
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5508
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5509
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5510
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5511
+ var __spreadValues = (a, b) => {
5512
+ for (var prop in b || (b = {}))
5513
+ if (__hasOwnProp.call(b, prop))
5514
+ __defNormalProp(a, prop, b[prop]);
5515
+ if (__getOwnPropSymbols)
5516
+ for (var prop of __getOwnPropSymbols(b)) {
5517
+ if (__propIsEnum.call(b, prop))
5518
+ __defNormalProp(a, prop, b[prop]);
5519
+ }
5520
+ return a;
5521
+ };
5522
+ function useSetState(initialState) {
5523
+ const [state, _setState] = useState(initialState);
5524
+ const setState = useCallback(
5525
+ (statePartial) => _setState((current) => __spreadValues(__spreadValues({}, current), typeof statePartial === "function" ? statePartial(current) : statePartial)),
5526
+ []
5527
+ );
5528
+ return [state, setState];
5529
+ }
5530
+
5531
+ const defaultState = {
5532
+ x: 0,
5533
+ y: 0,
5534
+ width: 0,
5535
+ height: 0,
5536
+ top: 0,
5537
+ left: 0,
5538
+ bottom: 0,
5539
+ right: 0
5540
+ };
5541
+ function useMeasure(target, options = {}) {
5542
+ const [rect, setRect] = useState(defaultState);
5543
+ const stop = useResizeObserver(
5544
+ target,
5545
+ (entries) => {
5546
+ if (entries[0]) {
5547
+ const { x, y, width, height, top, left, bottom, right } = entries[0].contentRect;
5548
+ setRect({ x, y, width, height, top, left, bottom, right });
5549
+ }
5550
+ },
5551
+ options
5552
+ );
5553
+ return [rect, stop];
5554
+ }
5555
+
5556
+ export { getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCookie, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDoubleClick, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useEyeDropper, useFavicon, useFileDialog, useFirstMountState, useFocus, index$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMeasure, index$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, index$1 as useOnceEffect, index as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSetState, useSticky, useSupported, useTextDirection, useTextSelection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, index$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {
@@ -52,44 +52,28 @@
52
52
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
53
53
  },
54
54
  "dependencies": {
55
+ "js-cookie": "^3.0.5",
55
56
  "lodash-es": "^4.17.21",
56
57
  "screenfull": "^5.0.0"
57
58
  },
58
59
  "devDependencies": {
59
- "@types/lodash-es": "^4.17.7",
60
- "lodash": "^4.17.21",
61
- "@babel/cli": "^7.19.3",
62
- "@babel/core": "^7.20.2",
63
- "@babel/preset-env": "^7.20.2",
64
- "@babel/preset-react": "^7.18.6",
65
- "@babel/preset-typescript": "^7.18.6",
66
60
  "@jsdevtools/version-bump-prompt": "^6.1.0",
67
61
  "@rollup/plugin-commonjs": "^22.0.2",
68
62
  "@rollup/plugin-json": "^4.1.0",
69
63
  "@rollup/plugin-node-resolve": "^14.1.0",
70
64
  "@rollup/plugin-replace": "^4.0.0",
71
65
  "@testing-library/react": "^13.4.0",
72
- "@types/fs-extra": "^9.0.13",
73
66
  "@types/jest": "^27.5.2",
74
- "@types/lodash": "^4.14.184",
75
- "@types/node": "^18.11.9",
76
- "@types/react": "^18.0.25",
77
67
  "babel-jest": "^29.0.2",
78
68
  "consola": "^2.15.3",
79
- "cross-env": "^7.0.3",
80
69
  "esbuild": "^0.17.15",
81
70
  "esbuild-register": "^3.4.1",
82
- "esno": "^0.16.3",
83
- "fast-glob": "^3.2.12",
84
- "fs-extra": "^10.1.0",
85
71
  "jest": "^29.0.2",
86
72
  "jest-environment-jsdom": "^29.0.2",
73
+ "lodash": "^4.17.21",
87
74
  "react": "^18.2.0",
88
- "react-dom": "^18.2.0",
89
75
  "rollup": "^2.79.0",
90
76
  "rollup-plugin-dts": "^4.2.2",
91
- "rollup-plugin-esbuild": "^4.10.1",
92
- "ts-node": "^10.9.1",
93
- "typescript": "^4.8.2"
77
+ "rollup-plugin-esbuild": "^4.10.1"
94
78
  }
95
79
  }