@develemit/web-hooks 0.2.0 → 0.3.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/CHANGELOG.md +12 -0
- package/README.md +145 -0
- package/dist/chunk-4PVVTQ5V.js +74 -0
- package/dist/{chunk-OZ4PU4E3.js → chunk-5XRVPZHD.js} +14 -4
- package/dist/{chunk-3UGRXQIA.js → chunk-DQBKU7HI.js} +10 -3
- package/dist/chunk-EXEJI4FK.js +43 -0
- package/dist/{chunk-3CACI4OQ.js → chunk-FE3BQD2I.js} +1 -25
- package/dist/chunk-HTVNN2NM.js +29 -0
- package/dist/chunk-JG3GPTMY.js +101 -0
- package/dist/chunk-TNEJ34T5.js +86 -0
- package/dist/chunk-UJ366T3Y.js +146 -0
- package/dist/{chunk-UZADAINO.js → chunk-WVM2LTWQ.js} +2 -21
- package/dist/chunk-WXL22EWK.js +21 -0
- package/dist/chunk-YFMMSLMB.js +41 -0
- package/dist/chunk-Z3X27PCA.js +108 -0
- package/dist/clipboard.cjs +13 -0
- package/dist/clipboard.d.cts +10 -1
- package/dist/clipboard.d.ts +10 -1
- package/dist/clipboard.js +6 -2
- package/dist/drawer-swipe.cjs +16 -4
- package/dist/drawer-swipe.d.cts +7 -3
- package/dist/drawer-swipe.d.ts +7 -3
- package/dist/drawer-swipe.js +5 -1
- package/dist/index.cjs +609 -19
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +77 -7
- package/dist/keyboard-inset.cjs +113 -0
- package/dist/keyboard-inset.d.cts +25 -0
- package/dist/keyboard-inset.d.ts +25 -0
- package/dist/keyboard-inset.js +11 -0
- package/dist/media-query.js +5 -3
- package/dist/online-status.cjs +46 -0
- package/dist/online-status.d.cts +3 -0
- package/dist/online-status.d.ts +3 -0
- package/dist/online-status.js +7 -0
- package/dist/outside-press.cjs +10 -3
- package/dist/outside-press.d.cts +4 -2
- package/dist/outside-press.d.ts +4 -2
- package/dist/outside-press.js +1 -1
- package/dist/push.cjs +201 -0
- package/dist/push.d.cts +37 -0
- package/dist/push.d.ts +37 -0
- package/dist/push.js +14 -0
- package/dist/pwa.cjs +198 -0
- package/dist/pwa.d.cts +35 -0
- package/dist/pwa.d.ts +35 -0
- package/dist/pwa.js +22 -0
- package/dist/service-worker.cjs +128 -0
- package/dist/service-worker.d.cts +23 -0
- package/dist/service-worker.d.ts +23 -0
- package/dist/service-worker.js +11 -0
- package/dist/share.cjs +139 -0
- package/dist/share.d.cts +23 -0
- package/dist/share.d.ts +23 -0
- package/dist/share.js +16 -0
- package/package.json +31 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
isIos,
|
|
4
|
+
isStandalone
|
|
5
|
+
} from "./chunk-YFMMSLMB.js";
|
|
6
|
+
|
|
7
|
+
// src/push/use-push-subscription.ts
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
|
+
|
|
10
|
+
// src/push/support.ts
|
|
11
|
+
function getPushSupport(env = readPushEnv()) {
|
|
12
|
+
if (env.isIos && !env.isStandalone) return "ios-needs-install";
|
|
13
|
+
if (!env.hasPushManager || !env.hasServiceWorker || !env.hasNotification) return "unsupported";
|
|
14
|
+
return "supported";
|
|
15
|
+
}
|
|
16
|
+
function readPushEnv() {
|
|
17
|
+
const browser = typeof window !== "undefined" && typeof navigator !== "undefined";
|
|
18
|
+
return {
|
|
19
|
+
hasPushManager: browser && "PushManager" in window,
|
|
20
|
+
hasServiceWorker: browser && "serviceWorker" in navigator,
|
|
21
|
+
hasNotification: browser && "Notification" in window,
|
|
22
|
+
isIos: browser && isIos(),
|
|
23
|
+
isStandalone: browser && isStandalone()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function readPermission() {
|
|
27
|
+
if (typeof window === "undefined" || !("Notification" in window)) return "unsupported";
|
|
28
|
+
return Notification.permission;
|
|
29
|
+
}
|
|
30
|
+
function shouldResubscribe({ permission, hasSubscription, resubscribeOnLoad }) {
|
|
31
|
+
return resubscribeOnLoad && permission === "granted" && !hasSubscription;
|
|
32
|
+
}
|
|
33
|
+
function isGone(error) {
|
|
34
|
+
return typeof error === "object" && error !== null && error.status === 410;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/push/vapid.ts
|
|
38
|
+
function urlBase64ToUint8Array(key) {
|
|
39
|
+
const padding = "=".repeat((4 - key.length % 4) % 4);
|
|
40
|
+
const base64 = (key + padding).replace(/-/g, "+").replace(/_/g, "/");
|
|
41
|
+
const raw = atob(base64);
|
|
42
|
+
const out = new Uint8Array(raw.length);
|
|
43
|
+
for (let i = 0; i < raw.length; i++) out[i] = raw.charCodeAt(i);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/push/register.ts
|
|
48
|
+
function subscribeFresh(reg, vapidPublicKey) {
|
|
49
|
+
return reg.pushManager.subscribe({
|
|
50
|
+
userVisibleOnly: true,
|
|
51
|
+
// lib.dom wants ArrayBufferView<ArrayBuffer>; a Uint8Array satisfies the runtime contract.
|
|
52
|
+
applicationServerKey: urlBase64ToUint8Array(vapidPublicKey)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function ensureSubscribed(reg, { vapidPublicKey, onSubscribe }, existing) {
|
|
56
|
+
let sub = existing ?? await reg.pushManager.getSubscription() ?? await subscribeFresh(reg, vapidPublicKey);
|
|
57
|
+
try {
|
|
58
|
+
await onSubscribe(sub.toJSON());
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!isGone(error)) throw error;
|
|
61
|
+
await sub.unsubscribe();
|
|
62
|
+
sub = await subscribeFresh(reg, vapidPublicKey);
|
|
63
|
+
await onSubscribe(sub.toJSON());
|
|
64
|
+
}
|
|
65
|
+
return sub;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/push/use-push-subscription.ts
|
|
69
|
+
var messageOf = (error, fallback) => error instanceof Error ? error.message : fallback;
|
|
70
|
+
function usePushSubscription(options) {
|
|
71
|
+
const { resubscribeOnLoad = true } = options;
|
|
72
|
+
const [support, setSupport] = useState("unsupported");
|
|
73
|
+
const [permission, setPermission] = useState("unsupported");
|
|
74
|
+
const [subscribed, setSubscribed] = useState(false);
|
|
75
|
+
const [busy, setBusy] = useState(false);
|
|
76
|
+
const [error, setError] = useState(null);
|
|
77
|
+
const latest = useRef(options);
|
|
78
|
+
latest.current = options;
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const current = getPushSupport();
|
|
81
|
+
setSupport(current);
|
|
82
|
+
setPermission(readPermission());
|
|
83
|
+
if (current !== "supported") return;
|
|
84
|
+
let cancelled = false;
|
|
85
|
+
(async () => {
|
|
86
|
+
try {
|
|
87
|
+
const reg = await navigator.serviceWorker.ready;
|
|
88
|
+
const existing = await reg.pushManager.getSubscription();
|
|
89
|
+
if (cancelled) return;
|
|
90
|
+
const permissionNow = readPermission();
|
|
91
|
+
setPermission(permissionNow);
|
|
92
|
+
if (existing) return setSubscribed(true);
|
|
93
|
+
if (!shouldResubscribe({ permission: permissionNow, hasSubscription: false, resubscribeOnLoad })) return;
|
|
94
|
+
await ensureSubscribed(reg, latest.current);
|
|
95
|
+
if (!cancelled) setSubscribed(true);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
})();
|
|
99
|
+
return () => {
|
|
100
|
+
cancelled = true;
|
|
101
|
+
};
|
|
102
|
+
}, [resubscribeOnLoad]);
|
|
103
|
+
const subscribe = useCallback(async () => {
|
|
104
|
+
if (getPushSupport() !== "supported") return;
|
|
105
|
+
setError(null);
|
|
106
|
+
setBusy(true);
|
|
107
|
+
try {
|
|
108
|
+
const result = await Notification.requestPermission();
|
|
109
|
+
setPermission(result);
|
|
110
|
+
if (result !== "granted") return;
|
|
111
|
+
const reg = await navigator.serviceWorker.ready;
|
|
112
|
+
await ensureSubscribed(reg, latest.current);
|
|
113
|
+
setSubscribed(true);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
setError(messageOf(e, "subscribe failed"));
|
|
116
|
+
} finally {
|
|
117
|
+
setBusy(false);
|
|
118
|
+
}
|
|
119
|
+
}, []);
|
|
120
|
+
const unsubscribe = useCallback(async () => {
|
|
121
|
+
if (getPushSupport() !== "supported") return;
|
|
122
|
+
setError(null);
|
|
123
|
+
setBusy(true);
|
|
124
|
+
try {
|
|
125
|
+
const reg = await navigator.serviceWorker.ready;
|
|
126
|
+
const sub = await reg.pushManager.getSubscription();
|
|
127
|
+
if (sub) {
|
|
128
|
+
await latest.current.onUnsubscribe(sub.endpoint);
|
|
129
|
+
await sub.unsubscribe();
|
|
130
|
+
}
|
|
131
|
+
setSubscribed(false);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
setError(messageOf(e, "unsubscribe failed"));
|
|
134
|
+
} finally {
|
|
135
|
+
setBusy(false);
|
|
136
|
+
}
|
|
137
|
+
}, []);
|
|
138
|
+
return { support, permission, subscribed, busy, error, subscribe, unsubscribe };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
getPushSupport,
|
|
143
|
+
shouldResubscribe,
|
|
144
|
+
urlBase64ToUint8Array,
|
|
145
|
+
usePushSubscription
|
|
146
|
+
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/media-query/use-media-query.ts
|
|
4
|
-
import { useCallback, useSyncExternalStore } from "react";
|
|
5
|
-
|
|
6
3
|
// src/media-query/media-query.ts
|
|
7
4
|
var REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
8
5
|
var COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
@@ -37,25 +34,9 @@ function subscribe(query, onChange) {
|
|
|
37
34
|
return () => list.removeListener(onChange);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
// src/media-query/use-media-query.ts
|
|
41
|
-
function useMediaQuery(query, options = {}) {
|
|
42
|
-
const serverDefault = options.serverDefault ?? false;
|
|
43
|
-
const subscribeToQuery = useCallback((onChange) => subscribe(query, onChange), [query]);
|
|
44
|
-
const getSnapshot = useCallback(() => getMatches(query) ?? serverDefault, [query, serverDefault]);
|
|
45
|
-
const getServerSnapshot = useCallback(() => serverDefault, [serverDefault]);
|
|
46
|
-
return useSyncExternalStore(subscribeToQuery, getSnapshot, getServerSnapshot);
|
|
47
|
-
}
|
|
48
|
-
function useReducedMotion(options) {
|
|
49
|
-
return useMediaQuery(REDUCED_MOTION_QUERY, options);
|
|
50
|
-
}
|
|
51
|
-
function useCoarsePointer(options) {
|
|
52
|
-
return useMediaQuery(COARSE_POINTER_QUERY, options);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
37
|
export {
|
|
56
38
|
REDUCED_MOTION_QUERY,
|
|
57
39
|
COARSE_POINTER_QUERY,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
useCoarsePointer
|
|
40
|
+
getMatches,
|
|
41
|
+
subscribe
|
|
61
42
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/online-status/use-online-status.ts
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
function subscribe(callback) {
|
|
6
|
+
window.addEventListener("online", callback);
|
|
7
|
+
window.addEventListener("offline", callback);
|
|
8
|
+
return () => {
|
|
9
|
+
window.removeEventListener("online", callback);
|
|
10
|
+
window.removeEventListener("offline", callback);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
var getSnapshot = () => navigator.onLine;
|
|
14
|
+
var getServerSnapshot = () => true;
|
|
15
|
+
function useOnlineStatus() {
|
|
16
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
useOnlineStatus
|
|
21
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/pwa/detect.ts
|
|
4
|
+
var IOS_UA = /iPhone|iPad|iPod/;
|
|
5
|
+
var IOS_OTHER_BROWSER = /CriOS|FxiOS|EdgiOS|OPiOS/;
|
|
6
|
+
var IN_APP_WEBVIEW = /FBAN|FBAV|Instagram/;
|
|
7
|
+
var STANDALONE_QUERY = "(display-mode: standalone)";
|
|
8
|
+
function detectPlatform(env) {
|
|
9
|
+
const isIos2 = IOS_UA.test(env.userAgent) || env.platform === "MacIntel" && env.maxTouchPoints > 1;
|
|
10
|
+
const isIosSafari2 = isIos2 && !IOS_OTHER_BROWSER.test(env.userAgent) && !IN_APP_WEBVIEW.test(env.userAgent);
|
|
11
|
+
return { isIos: isIos2, isIosSafari: isIosSafari2, isStandalone: env.standaloneMedia || env.navigatorStandalone };
|
|
12
|
+
}
|
|
13
|
+
function readStandaloneMedia() {
|
|
14
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
15
|
+
return window.matchMedia(STANDALONE_QUERY).matches;
|
|
16
|
+
}
|
|
17
|
+
function readNavigatorStandalone() {
|
|
18
|
+
if (typeof navigator === "undefined") return false;
|
|
19
|
+
return navigator.standalone === true;
|
|
20
|
+
}
|
|
21
|
+
function readPlatform() {
|
|
22
|
+
if (typeof navigator === "undefined") return { isIos: false, isIosSafari: false, isStandalone: false };
|
|
23
|
+
return detectPlatform({
|
|
24
|
+
userAgent: navigator.userAgent ?? "",
|
|
25
|
+
platform: navigator.platform ?? "",
|
|
26
|
+
maxTouchPoints: navigator.maxTouchPoints ?? 0,
|
|
27
|
+
standaloneMedia: readStandaloneMedia(),
|
|
28
|
+
navigatorStandalone: readNavigatorStandalone()
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
var isStandalone = () => readPlatform().isStandalone;
|
|
32
|
+
var isIos = () => readPlatform().isIos;
|
|
33
|
+
var isIosSafari = () => readPlatform().isIosSafari;
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
STANDALONE_QUERY,
|
|
37
|
+
detectPlatform,
|
|
38
|
+
isStandalone,
|
|
39
|
+
isIos,
|
|
40
|
+
isIosSafari
|
|
41
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
STANDALONE_QUERY,
|
|
4
|
+
isIosSafari,
|
|
5
|
+
isStandalone
|
|
6
|
+
} from "./chunk-YFMMSLMB.js";
|
|
7
|
+
import {
|
|
8
|
+
subscribe
|
|
9
|
+
} from "./chunk-WVM2LTWQ.js";
|
|
10
|
+
|
|
11
|
+
// src/pwa/use-is-standalone.ts
|
|
12
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
13
|
+
function useIsStandalone() {
|
|
14
|
+
const subscribeToMode = useCallback((onChange) => subscribe(STANDALONE_QUERY, onChange), []);
|
|
15
|
+
return useSyncExternalStore(subscribeToMode, isStandalone, () => false);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/pwa/use-install-prompt.ts
|
|
19
|
+
import { useEffect, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
20
|
+
|
|
21
|
+
// src/pwa/install-store.ts
|
|
22
|
+
var state = { event: null, installed: false };
|
|
23
|
+
var subscribers = /* @__PURE__ */ new Set();
|
|
24
|
+
var permanent = false;
|
|
25
|
+
var holders = 0;
|
|
26
|
+
var attached = false;
|
|
27
|
+
function set(next) {
|
|
28
|
+
state = next;
|
|
29
|
+
subscribers.forEach((fn) => fn());
|
|
30
|
+
}
|
|
31
|
+
function onBeforeInstallPrompt(e) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
set({ ...state, event: e });
|
|
34
|
+
}
|
|
35
|
+
function onAppInstalled() {
|
|
36
|
+
set({ event: null, installed: true });
|
|
37
|
+
}
|
|
38
|
+
function sync() {
|
|
39
|
+
const wanted = permanent || holders > 0;
|
|
40
|
+
if (wanted === attached || typeof window === "undefined") return;
|
|
41
|
+
attached = wanted;
|
|
42
|
+
const toggle = wanted ? window.addEventListener : window.removeEventListener;
|
|
43
|
+
toggle.call(window, "beforeinstallprompt", onBeforeInstallPrompt);
|
|
44
|
+
toggle.call(window, "appinstalled", onAppInstalled);
|
|
45
|
+
}
|
|
46
|
+
function startInstallPromptCapture() {
|
|
47
|
+
permanent = true;
|
|
48
|
+
sync();
|
|
49
|
+
}
|
|
50
|
+
function acquireCapture() {
|
|
51
|
+
holders += 1;
|
|
52
|
+
sync();
|
|
53
|
+
let released = false;
|
|
54
|
+
return () => {
|
|
55
|
+
if (released) return;
|
|
56
|
+
released = true;
|
|
57
|
+
holders -= 1;
|
|
58
|
+
sync();
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getInstallState() {
|
|
62
|
+
return state;
|
|
63
|
+
}
|
|
64
|
+
function subscribeInstallState(onChange) {
|
|
65
|
+
subscribers.add(onChange);
|
|
66
|
+
return () => {
|
|
67
|
+
subscribers.delete(onChange);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function promptInstall() {
|
|
71
|
+
const event = state.event;
|
|
72
|
+
if (!event) return "unavailable";
|
|
73
|
+
set({ ...state, event: null });
|
|
74
|
+
try {
|
|
75
|
+
await event.prompt();
|
|
76
|
+
const { outcome } = await event.userChoice;
|
|
77
|
+
return outcome;
|
|
78
|
+
} catch {
|
|
79
|
+
return "dismissed";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/pwa/use-install-prompt.ts
|
|
84
|
+
var serverState = { event: null, installed: false };
|
|
85
|
+
function useInstallPrompt() {
|
|
86
|
+
const state2 = useSyncExternalStore2(subscribeInstallState, getInstallState, () => serverState);
|
|
87
|
+
const standalone = useIsStandalone();
|
|
88
|
+
const iosSafari = useSyncExternalStore2(
|
|
89
|
+
() => () => {
|
|
90
|
+
},
|
|
91
|
+
isIosSafari,
|
|
92
|
+
() => false
|
|
93
|
+
);
|
|
94
|
+
useEffect(() => acquireCapture(), []);
|
|
95
|
+
const installed = state2.installed || standalone;
|
|
96
|
+
return {
|
|
97
|
+
canPrompt: state2.event !== null && !installed,
|
|
98
|
+
prompt: promptInstall,
|
|
99
|
+
installed,
|
|
100
|
+
needsIosInstructions: iosSafari && !installed
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export {
|
|
105
|
+
useIsStandalone,
|
|
106
|
+
startInstallPromptCapture,
|
|
107
|
+
useInstallPrompt
|
|
108
|
+
};
|
package/dist/clipboard.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var clipboard_exports = {};
|
|
23
23
|
__export(clipboard_exports, {
|
|
24
24
|
copyText: () => copyText,
|
|
25
|
+
readText: () => readText,
|
|
25
26
|
useCopyFeedback: () => useCopyFeedback
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(clipboard_exports);
|
|
@@ -87,8 +88,20 @@ function useCopyFeedback({ resetMs = 1500 } = {}) {
|
|
|
87
88
|
);
|
|
88
89
|
return { copy, status };
|
|
89
90
|
}
|
|
91
|
+
|
|
92
|
+
// src/clipboard/read-text.ts
|
|
93
|
+
async function readText() {
|
|
94
|
+
const hasClipboardApi = typeof navigator !== "undefined" && !!navigator.clipboard?.readText && typeof window !== "undefined" && window.isSecureContext;
|
|
95
|
+
if (!hasClipboardApi) return { ok: false, reason: "unavailable" };
|
|
96
|
+
try {
|
|
97
|
+
return { ok: true, text: await navigator.clipboard.readText() };
|
|
98
|
+
} catch {
|
|
99
|
+
return { ok: false, reason: "denied" };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
90
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
103
|
0 && (module.exports = {
|
|
92
104
|
copyText,
|
|
105
|
+
readText,
|
|
93
106
|
useCopyFeedback
|
|
94
107
|
});
|
package/dist/clipboard.d.cts
CHANGED
|
@@ -14,4 +14,13 @@ declare function useCopyFeedback({ resetMs }?: {
|
|
|
14
14
|
status: CopyStatus;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type ReadResult = {
|
|
18
|
+
ok: true;
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
reason: 'unavailable' | 'denied';
|
|
23
|
+
};
|
|
24
|
+
declare function readText(): Promise<ReadResult>;
|
|
25
|
+
|
|
26
|
+
export { type CopyResult, type CopyStatus, type ReadResult, copyText, readText, useCopyFeedback };
|
package/dist/clipboard.d.ts
CHANGED
|
@@ -14,4 +14,13 @@ declare function useCopyFeedback({ resetMs }?: {
|
|
|
14
14
|
status: CopyStatus;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type ReadResult = {
|
|
18
|
+
ok: true;
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
reason: 'unavailable' | 'denied';
|
|
23
|
+
};
|
|
24
|
+
declare function readText(): Promise<ReadResult>;
|
|
25
|
+
|
|
26
|
+
export { type CopyResult, type CopyStatus, type ReadResult, copyText, readText, useCopyFeedback };
|
package/dist/clipboard.js
CHANGED
package/dist/drawer-swipe.cjs
CHANGED
|
@@ -23,10 +23,12 @@ var drawer_swipe_exports = {};
|
|
|
23
23
|
__export(drawer_swipe_exports, {
|
|
24
24
|
BACK_ZONE_PX: () => BACK_ZONE_PX,
|
|
25
25
|
CLOSE_DISTANCE_PX: () => CLOSE_DISTANCE_PX,
|
|
26
|
+
DEFAULT_IGNORE_SELECTOR: () => DEFAULT_IGNORE_SELECTOR,
|
|
26
27
|
FORWARD_ZONE_PX: () => FORWARD_ZONE_PX,
|
|
27
28
|
MAX_SWIPE_DURATION_MS: () => MAX_SWIPE_DURATION_MS,
|
|
28
29
|
OPEN_DISTANCE_PX: () => OPEN_DISTANCE_PX,
|
|
29
30
|
VERTICAL_CANCEL_PX: () => VERTICAL_CANCEL_PX,
|
|
31
|
+
isInIgnoredRegion: () => isInIgnoredRegion,
|
|
30
32
|
isInOpenZone: () => isInOpenZone,
|
|
31
33
|
isInsideHorizontalScroller: () => isInsideHorizontalScroller,
|
|
32
34
|
resolveSwipeIntent: () => resolveSwipeIntent,
|
|
@@ -45,7 +47,8 @@ var HORIZONTAL_DOMINANCE = 1.5;
|
|
|
45
47
|
function isInOpenZone(x, viewportWidth) {
|
|
46
48
|
return x > BACK_ZONE_PX && x < viewportWidth - FORWARD_ZONE_PX;
|
|
47
49
|
}
|
|
48
|
-
function resolveSwipeIntent(start, end, drawerOpen, viewportWidth) {
|
|
50
|
+
function resolveSwipeIntent(start, end, drawerOpen, viewportWidth, startedInIgnoredRegion = false) {
|
|
51
|
+
if (startedInIgnoredRegion) return null;
|
|
49
52
|
const dx = end.x - start.x;
|
|
50
53
|
const dy = end.y - start.y;
|
|
51
54
|
if (end.time - start.time > MAX_SWIPE_DURATION_MS) return null;
|
|
@@ -67,6 +70,11 @@ function isInsideHorizontalScroller(target) {
|
|
|
67
70
|
}
|
|
68
71
|
return false;
|
|
69
72
|
}
|
|
73
|
+
var DEFAULT_IGNORE_SELECTOR = "[data-no-swipe]";
|
|
74
|
+
function isInIgnoredRegion(target, selector) {
|
|
75
|
+
if (!selector || !(target instanceof Element)) return false;
|
|
76
|
+
return target.closest(selector) !== null;
|
|
77
|
+
}
|
|
70
78
|
|
|
71
79
|
// src/drawer-swipe/use-drawer-swipe.ts
|
|
72
80
|
var import_react = require("react");
|
|
@@ -78,17 +86,19 @@ function useDrawerSwipe({
|
|
|
78
86
|
onOpen,
|
|
79
87
|
onClose,
|
|
80
88
|
enabled = true,
|
|
81
|
-
maxViewportWidth = 768
|
|
89
|
+
maxViewportWidth = 768,
|
|
90
|
+
ignoreSelector = DEFAULT_IGNORE_SELECTOR
|
|
82
91
|
}) {
|
|
83
92
|
const start = (0, import_react.useRef)(null);
|
|
84
|
-
const handlers = (0, import_react.useRef)({ drawerOpen, onOpen, onClose, maxViewportWidth });
|
|
85
|
-
handlers.current = { drawerOpen, onOpen, onClose, maxViewportWidth };
|
|
93
|
+
const handlers = (0, import_react.useRef)({ drawerOpen, onOpen, onClose, maxViewportWidth, ignoreSelector });
|
|
94
|
+
handlers.current = { drawerOpen, onOpen, onClose, maxViewportWidth, ignoreSelector };
|
|
86
95
|
(0, import_react.useEffect)(() => {
|
|
87
96
|
if (!enabled) return;
|
|
88
97
|
function handleStart(event) {
|
|
89
98
|
start.current = null;
|
|
90
99
|
if (event.touches.length !== 1) return;
|
|
91
100
|
if (isWideViewport(handlers.current.maxViewportWidth)) return;
|
|
101
|
+
if (isInIgnoredRegion(event.target, handlers.current.ignoreSelector)) return;
|
|
92
102
|
if (!handlers.current.drawerOpen && isInsideHorizontalScroller(event.target)) {
|
|
93
103
|
return;
|
|
94
104
|
}
|
|
@@ -138,10 +148,12 @@ function useDrawerSwipe({
|
|
|
138
148
|
0 && (module.exports = {
|
|
139
149
|
BACK_ZONE_PX,
|
|
140
150
|
CLOSE_DISTANCE_PX,
|
|
151
|
+
DEFAULT_IGNORE_SELECTOR,
|
|
141
152
|
FORWARD_ZONE_PX,
|
|
142
153
|
MAX_SWIPE_DURATION_MS,
|
|
143
154
|
OPEN_DISTANCE_PX,
|
|
144
155
|
VERTICAL_CANCEL_PX,
|
|
156
|
+
isInIgnoredRegion,
|
|
145
157
|
isInOpenZone,
|
|
146
158
|
isInsideHorizontalScroller,
|
|
147
159
|
resolveSwipeIntent,
|
package/dist/drawer-swipe.d.cts
CHANGED
|
@@ -11,8 +11,10 @@ declare const VERTICAL_CANCEL_PX = 40;
|
|
|
11
11
|
declare const MAX_SWIPE_DURATION_MS = 450;
|
|
12
12
|
type SwipeIntent = 'open' | 'close' | null;
|
|
13
13
|
declare function isInOpenZone(x: number, viewportWidth: number): boolean;
|
|
14
|
-
declare function resolveSwipeIntent(start: SwipePoint, end: SwipePoint, drawerOpen: boolean, viewportWidth: number): SwipeIntent;
|
|
14
|
+
declare function resolveSwipeIntent(start: SwipePoint, end: SwipePoint, drawerOpen: boolean, viewportWidth: number, startedInIgnoredRegion?: boolean): SwipeIntent;
|
|
15
15
|
declare function isInsideHorizontalScroller(target: EventTarget | null): boolean;
|
|
16
|
+
declare const DEFAULT_IGNORE_SELECTOR = "[data-no-swipe]";
|
|
17
|
+
declare function isInIgnoredRegion(target: EventTarget | null, selector: string | null): boolean;
|
|
16
18
|
|
|
17
19
|
type UseDrawerSwipeOptions = {
|
|
18
20
|
drawerOpen: boolean;
|
|
@@ -20,7 +22,9 @@ type UseDrawerSwipeOptions = {
|
|
|
20
22
|
onClose: () => void;
|
|
21
23
|
enabled?: boolean;
|
|
22
24
|
maxViewportWidth?: number;
|
|
25
|
+
/** Touches starting inside a match are ignored. Pass null to disable. */
|
|
26
|
+
ignoreSelector?: string | null;
|
|
23
27
|
};
|
|
24
|
-
declare function useDrawerSwipe({ drawerOpen, onOpen, onClose, enabled, maxViewportWidth, }: UseDrawerSwipeOptions): void;
|
|
28
|
+
declare function useDrawerSwipe({ drawerOpen, onOpen, onClose, enabled, maxViewportWidth, ignoreSelector, }: UseDrawerSwipeOptions): void;
|
|
25
29
|
|
|
26
|
-
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, type SwipeIntent, type SwipePoint, type UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe };
|
|
30
|
+
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, DEFAULT_IGNORE_SELECTOR, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, type SwipeIntent, type SwipePoint, type UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInIgnoredRegion, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe };
|
package/dist/drawer-swipe.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ declare const VERTICAL_CANCEL_PX = 40;
|
|
|
11
11
|
declare const MAX_SWIPE_DURATION_MS = 450;
|
|
12
12
|
type SwipeIntent = 'open' | 'close' | null;
|
|
13
13
|
declare function isInOpenZone(x: number, viewportWidth: number): boolean;
|
|
14
|
-
declare function resolveSwipeIntent(start: SwipePoint, end: SwipePoint, drawerOpen: boolean, viewportWidth: number): SwipeIntent;
|
|
14
|
+
declare function resolveSwipeIntent(start: SwipePoint, end: SwipePoint, drawerOpen: boolean, viewportWidth: number, startedInIgnoredRegion?: boolean): SwipeIntent;
|
|
15
15
|
declare function isInsideHorizontalScroller(target: EventTarget | null): boolean;
|
|
16
|
+
declare const DEFAULT_IGNORE_SELECTOR = "[data-no-swipe]";
|
|
17
|
+
declare function isInIgnoredRegion(target: EventTarget | null, selector: string | null): boolean;
|
|
16
18
|
|
|
17
19
|
type UseDrawerSwipeOptions = {
|
|
18
20
|
drawerOpen: boolean;
|
|
@@ -20,7 +22,9 @@ type UseDrawerSwipeOptions = {
|
|
|
20
22
|
onClose: () => void;
|
|
21
23
|
enabled?: boolean;
|
|
22
24
|
maxViewportWidth?: number;
|
|
25
|
+
/** Touches starting inside a match are ignored. Pass null to disable. */
|
|
26
|
+
ignoreSelector?: string | null;
|
|
23
27
|
};
|
|
24
|
-
declare function useDrawerSwipe({ drawerOpen, onOpen, onClose, enabled, maxViewportWidth, }: UseDrawerSwipeOptions): void;
|
|
28
|
+
declare function useDrawerSwipe({ drawerOpen, onOpen, onClose, enabled, maxViewportWidth, ignoreSelector, }: UseDrawerSwipeOptions): void;
|
|
25
29
|
|
|
26
|
-
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, type SwipeIntent, type SwipePoint, type UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe };
|
|
30
|
+
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, DEFAULT_IGNORE_SELECTOR, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, type SwipeIntent, type SwipePoint, type UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInIgnoredRegion, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe };
|
package/dist/drawer-swipe.js
CHANGED
|
@@ -2,22 +2,26 @@
|
|
|
2
2
|
import {
|
|
3
3
|
BACK_ZONE_PX,
|
|
4
4
|
CLOSE_DISTANCE_PX,
|
|
5
|
+
DEFAULT_IGNORE_SELECTOR,
|
|
5
6
|
FORWARD_ZONE_PX,
|
|
6
7
|
MAX_SWIPE_DURATION_MS,
|
|
7
8
|
OPEN_DISTANCE_PX,
|
|
8
9
|
VERTICAL_CANCEL_PX,
|
|
10
|
+
isInIgnoredRegion,
|
|
9
11
|
isInOpenZone,
|
|
10
12
|
isInsideHorizontalScroller,
|
|
11
13
|
resolveSwipeIntent,
|
|
12
14
|
useDrawerSwipe
|
|
13
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5XRVPZHD.js";
|
|
14
16
|
export {
|
|
15
17
|
BACK_ZONE_PX,
|
|
16
18
|
CLOSE_DISTANCE_PX,
|
|
19
|
+
DEFAULT_IGNORE_SELECTOR,
|
|
17
20
|
FORWARD_ZONE_PX,
|
|
18
21
|
MAX_SWIPE_DURATION_MS,
|
|
19
22
|
OPEN_DISTANCE_PX,
|
|
20
23
|
VERTICAL_CANCEL_PX,
|
|
24
|
+
isInIgnoredRegion,
|
|
21
25
|
isInOpenZone,
|
|
22
26
|
isInsideHorizontalScroller,
|
|
23
27
|
resolveSwipeIntent,
|