@reause/integrations 0.1.2

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.iife.js +1621 -0
  4. package/dist/index.iife.min.js +1 -0
  5. package/dist/index.js +13 -0
  6. package/dist/useAsyncValidator.d.ts +83 -0
  7. package/dist/useAsyncValidator.iife.js +192 -0
  8. package/dist/useAsyncValidator.iife.min.js +1 -0
  9. package/dist/useAsyncValidator.js +168 -0
  10. package/dist/useAxios.d.ts +125 -0
  11. package/dist/useAxios.iife.js +288 -0
  12. package/dist/useAxios.iife.min.js +1 -0
  13. package/dist/useAxios.js +265 -0
  14. package/dist/useChangeCase.d.ts +57 -0
  15. package/dist/useChangeCase.iife.js +91 -0
  16. package/dist/useChangeCase.iife.min.js +1 -0
  17. package/dist/useChangeCase.js +68 -0
  18. package/dist/useCookies.d.ts +117 -0
  19. package/dist/useCookies.iife.js +142 -0
  20. package/dist/useCookies.iife.min.js +1 -0
  21. package/dist/useCookies.js +117 -0
  22. package/dist/useDrauu.d.ts +152 -0
  23. package/dist/useDrauu.iife.js +221 -0
  24. package/dist/useDrauu.iife.min.js +1 -0
  25. package/dist/useDrauu.js +221 -0
  26. package/dist/useFocusTrap.d.ts +116 -0
  27. package/dist/useFocusTrap.iife.js +125 -0
  28. package/dist/useFocusTrap.iife.min.js +1 -0
  29. package/dist/useFocusTrap.js +125 -0
  30. package/dist/useFuse.d.ts +86 -0
  31. package/dist/useFuse.iife.js +95 -0
  32. package/dist/useFuse.iife.min.js +1 -0
  33. package/dist/useFuse.js +72 -0
  34. package/dist/useIDBKeyval.d.ts +139 -0
  35. package/dist/useIDBKeyval.iife.js +175 -0
  36. package/dist/useIDBKeyval.iife.min.js +1 -0
  37. package/dist/useIDBKeyval.js +174 -0
  38. package/dist/useJwt.d.ts +52 -0
  39. package/dist/useJwt.iife.js +54 -0
  40. package/dist/useJwt.iife.min.js +1 -0
  41. package/dist/useJwt.js +53 -0
  42. package/dist/useNProgress.d.ts +115 -0
  43. package/dist/useNProgress.iife.js +148 -0
  44. package/dist/useNProgress.iife.min.js +1 -0
  45. package/dist/useNProgress.js +125 -0
  46. package/dist/useQRCode.d.ts +38 -0
  47. package/dist/useQRCode.iife.js +78 -0
  48. package/dist/useQRCode.iife.min.js +1 -0
  49. package/dist/useQRCode.js +55 -0
  50. package/dist/useSortable.d.ts +143 -0
  51. package/dist/useSortable.iife.js +199 -0
  52. package/dist/useSortable.iife.min.js +1 -0
  53. package/dist/useSortable.js +173 -0
  54. package/package.json +92 -0
@@ -0,0 +1,115 @@
1
+ import { Dispatch, SetStateAction } from "react";
2
+ import { NProgress, NProgressOptions } from "nprogress";
3
+ //#region useNProgress/index.d.ts
4
+ /**
5
+ * Options forwarded to `nprogress.configure` — mirrors upstream's
6
+ * `UseNProgressOptions` (`Partial<NProgressOptions>`).
7
+ */
8
+ export type UseNProgressOptions = Partial<NProgressOptions>;
9
+ export interface UseNProgressReturn {
10
+ /**
11
+ * Current progress percentage (`0..1`), `null` after `remove()`, `1` after
12
+ * `done()` — the plain-state replacement for upstream's `progress` ref.
13
+ * Write through `setProgress`.
14
+ */
15
+ readonly progress: number | null | undefined;
16
+ /**
17
+ * Setter for `progress` — the React mapping of upstream's writable `progress`
18
+ * ref. Takes a plain value or a functional updater (like a React `useState`
19
+ * setter, `prev => next`). A `number` result is pushed to `nprogress` once,
20
+ * through the progress effect (upstream: writing `progress.value`); a `null`
21
+ * / `undefined` result only clears the state — the bar element is removed
22
+ * through `remove()`.
23
+ */
24
+ readonly setProgress: Dispatch<SetStateAction<number | null | undefined>>;
25
+ /**
26
+ * Whether the bar is currently showing — the React replacement for
27
+ * upstream's writable `isLoading` computed: `true` while `progress` is a
28
+ * number below 1. Write through `setIsLoading`.
29
+ */
30
+ readonly isLoading: boolean;
31
+ /**
32
+ * Setter half of upstream's writable `isLoading` computed — takes a plain
33
+ * value or a functional updater (like a React `useState` setter,
34
+ * `prev => next`): `setIsLoading(true)` starts the bar, `setIsLoading(false)`
35
+ * completes it.
36
+ */
37
+ readonly setIsLoading: Dispatch<SetStateAction<boolean>>;
38
+ /**
39
+ * Show the bar — upstream's `start`.
40
+ */
41
+ readonly start: () => NProgress;
42
+ /**
43
+ * Complete the bar (the placebo `done` animation) — upstream's `done`.
44
+ *
45
+ * @param force - show the bar even when it is hidden
46
+ */
47
+ readonly done: (force?: boolean) => NProgress;
48
+ /**
49
+ * Reset `progress` to `null` and remove the bar from the DOM — upstream's
50
+ * `remove`.
51
+ */
52
+ readonly remove: () => void;
53
+ }
54
+ /**
55
+ * React port of VueUse's `useNProgress`.
56
+ *
57
+ * Map from @vueuse/integrations `useNProgress`
58
+ * (`source/vueuse/packages/integrations/useNProgress/index.ts`), a reactive
59
+ * wrapper around the [`nprogress`](https://github.com/rstacruz/nprogress)
60
+ * progress bar. `currentProgress` is the hook's **read-only value source** and
61
+ * takes a plain `number | null | undefined` (upstream: `MaybeRefOrGetter`).
62
+ *
63
+ * Adjustment for React:
64
+ * - the writable `WritableComputedRef<boolean>` `isLoading` and the
65
+ * `Ref<number | null | undefined>` `progress` become plain state: `isLoading`
66
+ * is derived (`typeof progress === 'number' && progress < 1`) and written
67
+ * through `setIsLoading`, `progress` is a plain number written through
68
+ * `setProgress`; the object return mirrors upstream's object of refs with
69
+ * every writable value paired with its setter —
70
+ * `{ progress, setProgress, isLoading, setIsLoading, start, done, remove }`;
71
+ * - the setters are React `Dispatch<SetStateAction<...>>`: each accepts a plain
72
+ * value or a functional updater (`prev => next`), like a `useState` setter;
73
+ * - upstream monkey-patches the module-singleton `nprogress.set` so that its
74
+ * internal `set` calls (`start` → `set(0)`, `done` → `set(1)`) write back
75
+ * into `progress.value`, which is what makes `isLoading` flip. This port
76
+ * never touches the global `nprogress.set`: `setProgress(n)` only sets the
77
+ * state and the progress effect pushes the number into the bar once per
78
+ * render, while `start` / `done` / `setIsLoading` mirror the same write-back
79
+ * by hand (upstream's `start` only calls `set(0)` when the bar was idle, and
80
+ * `done` only calls `set(1)` when it actually progresses) — so `isLoading`
81
+ * flips exactly as upstream, without global pollution and safely with
82
+ * concurrent hook instances;
83
+ * - `options` are applied once on mount (`nprogress.configure`), like
84
+ * upstream's setup-time `if (options) nprogress.configure(options)`; later
85
+ * `options` changes are not re-applied, matching the upstream setup
86
+ * semantics;
87
+ * - a provided `currentProgress` is mirrored into the internal state (upstream's
88
+ * `toRef`): a changed plain number re-syncs between renders, and a write
89
+ * through `setProgress` / `start` / `done` is only superseded by a genuine
90
+ * external change. Writes are **not** propagated back to the caller
91
+ * (upstream's `toRef` writes through to a ref input); the source is
92
+ * read-only here;
93
+ * - unmount runs `nprogress.remove()`, mirroring upstream's
94
+ * `tryOnScopeDispose(nprogress.remove)`. `nprogress` is a module singleton,
95
+ * so unmounting one hook instance removes the shared bar — the same
96
+ * semantics as upstream.
97
+ *
98
+ * SSR-safe: `nprogress.set` is only called when `isClient` (upstream's
99
+ * `watchEffect` guard).
100
+ *
101
+ * @param currentProgress - initial progress percentage (`0..1`); a changed
102
+ * plain value re-syncs on the next render
103
+ * @param options - `nprogress.configure` options, applied once on mount
104
+ *
105
+ * @__NO_SIDE_EFFECTS__
106
+ * @example
107
+ * const { progress, setProgress, isLoading, setIsLoading, done, remove } = useNProgress()
108
+ * setIsLoading(true) // starts the bar, isLoading === true
109
+ * setProgress(0.5) // progress === 0.5, the bar renders at 50%
110
+ * setProgress(prev => (prev ?? 0) + 0.1) // functional updater, like a useState setter
111
+ * done() // progress === 1, isLoading === false
112
+ * remove() // progress === null, the #nprogress element is gone
113
+ */
114
+ export declare function useNProgress(currentProgress?: number | null | undefined, options?: UseNProgressOptions): UseNProgressReturn;
115
+ //#endregion
@@ -0,0 +1,148 @@
1
+ (function(exports, _reause_shared, nprogress, react) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region \0rolldown/runtime.js
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ nprogress = __toESM(nprogress, 1);
26
+ //#region useNProgress/index.tsx
27
+ /**
28
+ * React port of VueUse's `useNProgress`.
29
+ *
30
+ * Map from @vueuse/integrations `useNProgress`
31
+ * (`source/vueuse/packages/integrations/useNProgress/index.ts`), a reactive
32
+ * wrapper around the [`nprogress`](https://github.com/rstacruz/nprogress)
33
+ * progress bar. `currentProgress` is the hook's **read-only value source** and
34
+ * takes a plain `number | null | undefined` (upstream: `MaybeRefOrGetter`).
35
+ *
36
+ * Adjustment for React:
37
+ * - the writable `WritableComputedRef<boolean>` `isLoading` and the
38
+ * `Ref<number | null | undefined>` `progress` become plain state: `isLoading`
39
+ * is derived (`typeof progress === 'number' && progress < 1`) and written
40
+ * through `setIsLoading`, `progress` is a plain number written through
41
+ * `setProgress`; the object return mirrors upstream's object of refs with
42
+ * every writable value paired with its setter —
43
+ * `{ progress, setProgress, isLoading, setIsLoading, start, done, remove }`;
44
+ * - the setters are React `Dispatch<SetStateAction<...>>`: each accepts a plain
45
+ * value or a functional updater (`prev => next`), like a `useState` setter;
46
+ * - upstream monkey-patches the module-singleton `nprogress.set` so that its
47
+ * internal `set` calls (`start` → `set(0)`, `done` → `set(1)`) write back
48
+ * into `progress.value`, which is what makes `isLoading` flip. This port
49
+ * never touches the global `nprogress.set`: `setProgress(n)` only sets the
50
+ * state and the progress effect pushes the number into the bar once per
51
+ * render, while `start` / `done` / `setIsLoading` mirror the same write-back
52
+ * by hand (upstream's `start` only calls `set(0)` when the bar was idle, and
53
+ * `done` only calls `set(1)` when it actually progresses) — so `isLoading`
54
+ * flips exactly as upstream, without global pollution and safely with
55
+ * concurrent hook instances;
56
+ * - `options` are applied once on mount (`nprogress.configure`), like
57
+ * upstream's setup-time `if (options) nprogress.configure(options)`; later
58
+ * `options` changes are not re-applied, matching the upstream setup
59
+ * semantics;
60
+ * - a provided `currentProgress` is mirrored into the internal state (upstream's
61
+ * `toRef`): a changed plain number re-syncs between renders, and a write
62
+ * through `setProgress` / `start` / `done` is only superseded by a genuine
63
+ * external change. Writes are **not** propagated back to the caller
64
+ * (upstream's `toRef` writes through to a ref input); the source is
65
+ * read-only here;
66
+ * - unmount runs `nprogress.remove()`, mirroring upstream's
67
+ * `tryOnScopeDispose(nprogress.remove)`. `nprogress` is a module singleton,
68
+ * so unmounting one hook instance removes the shared bar — the same
69
+ * semantics as upstream.
70
+ *
71
+ * SSR-safe: `nprogress.set` is only called when `isClient` (upstream's
72
+ * `watchEffect` guard).
73
+ *
74
+ * @param currentProgress - initial progress percentage (`0..1`); a changed
75
+ * plain value re-syncs on the next render
76
+ * @param options - `nprogress.configure` options, applied once on mount
77
+ *
78
+ * @__NO_SIDE_EFFECTS__
79
+ * @example
80
+ * const { progress, setProgress, isLoading, setIsLoading, done, remove } = useNProgress()
81
+ * setIsLoading(true) // starts the bar, isLoading === true
82
+ * setProgress(0.5) // progress === 0.5, the bar renders at 50%
83
+ * setProgress(prev => (prev ?? 0) + 0.1) // functional updater, like a useState setter
84
+ * done() // progress === 1, isLoading === false
85
+ * remove() // progress === null, the #nprogress element is gone
86
+ */
87
+ function useNProgress(currentProgress = null, options) {
88
+ const [progress, setProgressState] = (0, react.useState)(currentProgress);
89
+ const progressRef = (0, react.useRef)(currentProgress);
90
+ const updateProgress = (0, react.useCallback)((next) => {
91
+ progressRef.current = next;
92
+ setProgressState(next);
93
+ }, []);
94
+ const lastExternalRef = (0, react.useRef)(currentProgress);
95
+ (0, react.useEffect)(() => {
96
+ if (!Object.is(currentProgress, lastExternalRef.current)) {
97
+ lastExternalRef.current = currentProgress;
98
+ updateProgress(currentProgress);
99
+ }
100
+ });
101
+ const optionsRef = (0, react.useRef)(options);
102
+ optionsRef.current = options;
103
+ (0, react.useEffect)(() => {
104
+ if (optionsRef.current) nprogress.default.configure(optionsRef.current);
105
+ }, []);
106
+ (0, react.useEffect)(() => {
107
+ if (typeof progress === "number" && _reause_shared.isClient) nprogress.default.set(progress);
108
+ }, [progress]);
109
+ (0, react.useEffect)(() => () => {
110
+ nprogress.default.remove();
111
+ }, []);
112
+ const setProgress = (0, react.useCallback)((updater) => {
113
+ const next = typeof updater === "function" ? updater(progressRef.current) : updater;
114
+ updateProgress(next);
115
+ }, [updateProgress]);
116
+ const start = (0, react.useCallback)(() => {
117
+ const wasStarted = nprogress.default.isStarted();
118
+ const result = nprogress.default.start();
119
+ if (!wasStarted) updateProgress(0);
120
+ return result;
121
+ }, [updateProgress]);
122
+ const done = (0, react.useCallback)((force) => {
123
+ const status = nprogress.default.status;
124
+ const result = nprogress.default.done(force);
125
+ if (force || status) updateProgress(1);
126
+ return result;
127
+ }, [updateProgress]);
128
+ const setIsLoading = (0, react.useCallback)((updater) => {
129
+ if (typeof updater === "function" ? updater(typeof progressRef.current === "number" && progressRef.current < 1) : updater) start();
130
+ else done();
131
+ }, [start, done]);
132
+ const remove = (0, react.useCallback)(() => {
133
+ updateProgress(null);
134
+ nprogress.default.remove();
135
+ }, [updateProgress]);
136
+ return {
137
+ progress,
138
+ setProgress,
139
+ isLoading: typeof progress === "number" && progress < 1,
140
+ setIsLoading,
141
+ start,
142
+ done,
143
+ remove
144
+ };
145
+ }
146
+ //#endregion
147
+ exports.useNProgress = useNProgress;
148
+ })(this.reause = this.reause || {}, reause, nprogress, React);
@@ -0,0 +1 @@
1
+ (function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule||!l.call(e,`default`)?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);function d(e=null,i){let[a,o]=(0,r.useState)(e),s=(0,r.useRef)(e),c=(0,r.useCallback)(e=>{s.current=e,o(e)},[]),l=(0,r.useRef)(e);(0,r.useEffect)(()=>{Object.is(e,l.current)||(l.current=e,c(e))});let u=(0,r.useRef)(i);u.current=i,(0,r.useEffect)(()=>{u.current&&n.default.configure(u.current)},[]),(0,r.useEffect)(()=>{typeof a==`number`&&t.isClient&&n.default.set(a)},[a]),(0,r.useEffect)(()=>()=>{n.default.remove()},[]);let d=(0,r.useCallback)(e=>{let t=typeof e==`function`?e(s.current):e;c(t)},[c]),f=(0,r.useCallback)(()=>{let e=n.default.isStarted(),t=n.default.start();return e||c(0),t},[c]),p=(0,r.useCallback)(e=>{let t=n.default.status,r=n.default.done(e);return(e||t)&&c(1),r},[c]),m=(0,r.useCallback)(e=>{(typeof e==`function`?e(typeof s.current==`number`&&s.current<1):e)?f():p()},[f,p]),h=(0,r.useCallback)(()=>{c(null),n.default.remove()},[c]);return{progress:a,setProgress:d,isLoading:typeof a==`number`&&a<1,setIsLoading:m,start:f,done:p,remove:h}}e.useNProgress=d})(this.reause=this.reause||{},reause,nprogress,React);
@@ -0,0 +1,125 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { isClient } from "@reause/shared";
3
+ import nprogress from "nprogress";
4
+ //#region useNProgress/index.tsx
5
+ /**
6
+ * React port of VueUse's `useNProgress`.
7
+ *
8
+ * Map from @vueuse/integrations `useNProgress`
9
+ * (`source/vueuse/packages/integrations/useNProgress/index.ts`), a reactive
10
+ * wrapper around the [`nprogress`](https://github.com/rstacruz/nprogress)
11
+ * progress bar. `currentProgress` is the hook's **read-only value source** and
12
+ * takes a plain `number | null | undefined` (upstream: `MaybeRefOrGetter`).
13
+ *
14
+ * Adjustment for React:
15
+ * - the writable `WritableComputedRef<boolean>` `isLoading` and the
16
+ * `Ref<number | null | undefined>` `progress` become plain state: `isLoading`
17
+ * is derived (`typeof progress === 'number' && progress < 1`) and written
18
+ * through `setIsLoading`, `progress` is a plain number written through
19
+ * `setProgress`; the object return mirrors upstream's object of refs with
20
+ * every writable value paired with its setter —
21
+ * `{ progress, setProgress, isLoading, setIsLoading, start, done, remove }`;
22
+ * - the setters are React `Dispatch<SetStateAction<...>>`: each accepts a plain
23
+ * value or a functional updater (`prev => next`), like a `useState` setter;
24
+ * - upstream monkey-patches the module-singleton `nprogress.set` so that its
25
+ * internal `set` calls (`start` → `set(0)`, `done` → `set(1)`) write back
26
+ * into `progress.value`, which is what makes `isLoading` flip. This port
27
+ * never touches the global `nprogress.set`: `setProgress(n)` only sets the
28
+ * state and the progress effect pushes the number into the bar once per
29
+ * render, while `start` / `done` / `setIsLoading` mirror the same write-back
30
+ * by hand (upstream's `start` only calls `set(0)` when the bar was idle, and
31
+ * `done` only calls `set(1)` when it actually progresses) — so `isLoading`
32
+ * flips exactly as upstream, without global pollution and safely with
33
+ * concurrent hook instances;
34
+ * - `options` are applied once on mount (`nprogress.configure`), like
35
+ * upstream's setup-time `if (options) nprogress.configure(options)`; later
36
+ * `options` changes are not re-applied, matching the upstream setup
37
+ * semantics;
38
+ * - a provided `currentProgress` is mirrored into the internal state (upstream's
39
+ * `toRef`): a changed plain number re-syncs between renders, and a write
40
+ * through `setProgress` / `start` / `done` is only superseded by a genuine
41
+ * external change. Writes are **not** propagated back to the caller
42
+ * (upstream's `toRef` writes through to a ref input); the source is
43
+ * read-only here;
44
+ * - unmount runs `nprogress.remove()`, mirroring upstream's
45
+ * `tryOnScopeDispose(nprogress.remove)`. `nprogress` is a module singleton,
46
+ * so unmounting one hook instance removes the shared bar — the same
47
+ * semantics as upstream.
48
+ *
49
+ * SSR-safe: `nprogress.set` is only called when `isClient` (upstream's
50
+ * `watchEffect` guard).
51
+ *
52
+ * @param currentProgress - initial progress percentage (`0..1`); a changed
53
+ * plain value re-syncs on the next render
54
+ * @param options - `nprogress.configure` options, applied once on mount
55
+ *
56
+ * @__NO_SIDE_EFFECTS__
57
+ * @example
58
+ * const { progress, setProgress, isLoading, setIsLoading, done, remove } = useNProgress()
59
+ * setIsLoading(true) // starts the bar, isLoading === true
60
+ * setProgress(0.5) // progress === 0.5, the bar renders at 50%
61
+ * setProgress(prev => (prev ?? 0) + 0.1) // functional updater, like a useState setter
62
+ * done() // progress === 1, isLoading === false
63
+ * remove() // progress === null, the #nprogress element is gone
64
+ */
65
+ function useNProgress(currentProgress = null, options) {
66
+ const [progress, setProgressState] = useState(currentProgress);
67
+ const progressRef = useRef(currentProgress);
68
+ const updateProgress = useCallback((next) => {
69
+ progressRef.current = next;
70
+ setProgressState(next);
71
+ }, []);
72
+ const lastExternalRef = useRef(currentProgress);
73
+ useEffect(() => {
74
+ if (!Object.is(currentProgress, lastExternalRef.current)) {
75
+ lastExternalRef.current = currentProgress;
76
+ updateProgress(currentProgress);
77
+ }
78
+ });
79
+ const optionsRef = useRef(options);
80
+ optionsRef.current = options;
81
+ useEffect(() => {
82
+ if (optionsRef.current) nprogress.configure(optionsRef.current);
83
+ }, []);
84
+ useEffect(() => {
85
+ if (typeof progress === "number" && isClient) nprogress.set(progress);
86
+ }, [progress]);
87
+ useEffect(() => () => {
88
+ nprogress.remove();
89
+ }, []);
90
+ const setProgress = useCallback((updater) => {
91
+ const next = typeof updater === "function" ? updater(progressRef.current) : updater;
92
+ updateProgress(next);
93
+ }, [updateProgress]);
94
+ const start = useCallback(() => {
95
+ const wasStarted = nprogress.isStarted();
96
+ const result = nprogress.start();
97
+ if (!wasStarted) updateProgress(0);
98
+ return result;
99
+ }, [updateProgress]);
100
+ const done = useCallback((force) => {
101
+ const status = nprogress.status;
102
+ const result = nprogress.done(force);
103
+ if (force || status) updateProgress(1);
104
+ return result;
105
+ }, [updateProgress]);
106
+ const setIsLoading = useCallback((updater) => {
107
+ if (typeof updater === "function" ? updater(typeof progressRef.current === "number" && progressRef.current < 1) : updater) start();
108
+ else done();
109
+ }, [start, done]);
110
+ const remove = useCallback(() => {
111
+ updateProgress(null);
112
+ nprogress.remove();
113
+ }, [updateProgress]);
114
+ return {
115
+ progress,
116
+ setProgress,
117
+ isLoading: typeof progress === "number" && progress < 1,
118
+ setIsLoading,
119
+ start,
120
+ done,
121
+ remove
122
+ };
123
+ }
124
+ //#endregion
125
+ export { useNProgress };
@@ -0,0 +1,38 @@
1
+ import * as QRCode from "qrcode";
2
+ //#region useQRCode/index.d.ts
3
+ /**
4
+ * React port of VueUse's `useQRCode`.
5
+ *
6
+ * Map from @vueuse/integrations `useQRCode`
7
+ * (`source/vueuse/packages/integrations/useQRCode/`), a reactive wrapper
8
+ * around the `qrcode` package: it encodes `text` into a PNG data URL.
9
+ *
10
+ * Adjustment for React:
11
+ * - upstream returns a `shallowRef<string>` holding the data URL; in React the
12
+ * asynchronous result is state, so the hook returns the plain `string` data
13
+ * URL directly (no `.value`, no tuple) — `''` until the first encode
14
+ * resolves. Exactly like upstream, an empty `text` never encodes, so the
15
+ * previous data URL is kept (it is not cleared);
16
+ * - `text` is the hook's **read-only value source** and takes a plain string
17
+ * (upstream: `MaybeRefOrGetter<string>`); a changed `text` prop re-encodes
18
+ * on the next render;
19
+ * - the encode is `await`-free but guarded by a `cancelled` flag: when `text`
20
+ * (or `options`) changes or the component unmounts while an encode is still
21
+ * pending, the stale promise is ignored, so the last write always wins;
22
+ * - **pass a memoized `options` object** (`useMemo`/module constant). React has
23
+ * no dependency-tracking equivalent of Vue's `watch` source, so `options` is
24
+ * compared by identity: a fresh literal on every render re-runs the effect
25
+ * and re-encodes the QR code. Options are deliberately not serialized — they
26
+ * may contain non-JSON values (`toSJISFunc`, `color` functions…), which
27
+ * serialization would break.
28
+ *
29
+ * @__NO_SIDE_EFFECTS__
30
+ * @see https://vueuse.org/useQRCode
31
+ * @param text - the text to encode (plain string)
32
+ * @param options - `qrcode` `toDataURL` options, memoized by the caller
33
+ * @example
34
+ * const qrcode = useQRCode('https://vueuse.org')
35
+ * qrcode // '' at first, then 'data:image/png;base64,…'
36
+ */
37
+ export declare function useQRCode(text: string, options?: QRCode.QRCodeToDataURLOptions): string;
38
+ //#endregion
@@ -0,0 +1,78 @@
1
+ (function(exports, _reause_shared, qrcode, react) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region \0rolldown/runtime.js
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ qrcode = __toESM(qrcode, 1);
26
+ //#region useQRCode/index.tsx
27
+ /**
28
+ * React port of VueUse's `useQRCode`.
29
+ *
30
+ * Map from @vueuse/integrations `useQRCode`
31
+ * (`source/vueuse/packages/integrations/useQRCode/`), a reactive wrapper
32
+ * around the `qrcode` package: it encodes `text` into a PNG data URL.
33
+ *
34
+ * Adjustment for React:
35
+ * - upstream returns a `shallowRef<string>` holding the data URL; in React the
36
+ * asynchronous result is state, so the hook returns the plain `string` data
37
+ * URL directly (no `.value`, no tuple) — `''` until the first encode
38
+ * resolves. Exactly like upstream, an empty `text` never encodes, so the
39
+ * previous data URL is kept (it is not cleared);
40
+ * - `text` is the hook's **read-only value source** and takes a plain string
41
+ * (upstream: `MaybeRefOrGetter<string>`); a changed `text` prop re-encodes
42
+ * on the next render;
43
+ * - the encode is `await`-free but guarded by a `cancelled` flag: when `text`
44
+ * (or `options`) changes or the component unmounts while an encode is still
45
+ * pending, the stale promise is ignored, so the last write always wins;
46
+ * - **pass a memoized `options` object** (`useMemo`/module constant). React has
47
+ * no dependency-tracking equivalent of Vue's `watch` source, so `options` is
48
+ * compared by identity: a fresh literal on every render re-runs the effect
49
+ * and re-encodes the QR code. Options are deliberately not serialized — they
50
+ * may contain non-JSON values (`toSJISFunc`, `color` functions…), which
51
+ * serialization would break.
52
+ *
53
+ * @__NO_SIDE_EFFECTS__
54
+ * @see https://vueuse.org/useQRCode
55
+ * @param text - the text to encode (plain string)
56
+ * @param options - `qrcode` `toDataURL` options, memoized by the caller
57
+ * @example
58
+ * const qrcode = useQRCode('https://vueuse.org')
59
+ * qrcode // '' at first, then 'data:image/png;base64,…'
60
+ */
61
+ function useQRCode(text, options) {
62
+ const value = text;
63
+ const [result, setResult] = (0, react.useState)("");
64
+ (0, react.useEffect)(() => {
65
+ if (!value || !_reause_shared.isClient) return;
66
+ let cancelled = false;
67
+ qrcode.toDataURL(value, options).then((url) => {
68
+ if (!cancelled) setResult(url);
69
+ });
70
+ return () => {
71
+ cancelled = true;
72
+ };
73
+ }, [value, options]);
74
+ return result;
75
+ }
76
+ //#endregion
77
+ exports.useQRCode = useQRCode;
78
+ })(this.reause = this.reause || {}, reause, QRCode, React);
@@ -0,0 +1 @@
1
+ (function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule||!l.call(e,`default`)?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);function d(e,i){let a=e,[o,s]=(0,r.useState)(``);return(0,r.useEffect)(()=>{if(!a||!t.isClient)return;let e=!1;return n.toDataURL(a,i).then(t=>{e||s(t)}),()=>{e=!0}},[a,i]),o}e.useQRCode=d})(this.reause=this.reause||{},reause,QRCode,React);
@@ -0,0 +1,55 @@
1
+ import { useEffect, useState } from "react";
2
+ import { isClient } from "@reause/shared";
3
+ import * as QRCode from "qrcode";
4
+ //#region useQRCode/index.tsx
5
+ /**
6
+ * React port of VueUse's `useQRCode`.
7
+ *
8
+ * Map from @vueuse/integrations `useQRCode`
9
+ * (`source/vueuse/packages/integrations/useQRCode/`), a reactive wrapper
10
+ * around the `qrcode` package: it encodes `text` into a PNG data URL.
11
+ *
12
+ * Adjustment for React:
13
+ * - upstream returns a `shallowRef<string>` holding the data URL; in React the
14
+ * asynchronous result is state, so the hook returns the plain `string` data
15
+ * URL directly (no `.value`, no tuple) — `''` until the first encode
16
+ * resolves. Exactly like upstream, an empty `text` never encodes, so the
17
+ * previous data URL is kept (it is not cleared);
18
+ * - `text` is the hook's **read-only value source** and takes a plain string
19
+ * (upstream: `MaybeRefOrGetter<string>`); a changed `text` prop re-encodes
20
+ * on the next render;
21
+ * - the encode is `await`-free but guarded by a `cancelled` flag: when `text`
22
+ * (or `options`) changes or the component unmounts while an encode is still
23
+ * pending, the stale promise is ignored, so the last write always wins;
24
+ * - **pass a memoized `options` object** (`useMemo`/module constant). React has
25
+ * no dependency-tracking equivalent of Vue's `watch` source, so `options` is
26
+ * compared by identity: a fresh literal on every render re-runs the effect
27
+ * and re-encodes the QR code. Options are deliberately not serialized — they
28
+ * may contain non-JSON values (`toSJISFunc`, `color` functions…), which
29
+ * serialization would break.
30
+ *
31
+ * @__NO_SIDE_EFFECTS__
32
+ * @see https://vueuse.org/useQRCode
33
+ * @param text - the text to encode (plain string)
34
+ * @param options - `qrcode` `toDataURL` options, memoized by the caller
35
+ * @example
36
+ * const qrcode = useQRCode('https://vueuse.org')
37
+ * qrcode // '' at first, then 'data:image/png;base64,…'
38
+ */
39
+ function useQRCode(text, options) {
40
+ const value = text;
41
+ const [result, setResult] = useState("");
42
+ useEffect(() => {
43
+ if (!value || !isClient) return;
44
+ let cancelled = false;
45
+ QRCode.toDataURL(value, options).then((url) => {
46
+ if (!cancelled) setResult(url);
47
+ });
48
+ return () => {
49
+ cancelled = true;
50
+ };
51
+ }, [value, options]);
52
+ return result;
53
+ }
54
+ //#endregion
55
+ export { useQRCode };