@rootnative/web 0.0.0-alpha.3 → 0.0.0-alpha.4
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 +21 -1
- package/dist/apis/AccessibilityInfo/index.d.ts +30 -0
- package/dist/apis/AccessibilityInfo/index.js +84 -0
- package/dist/apis/AccessibilityInfo/index.js.map +1 -0
- package/dist/apis/Alert/index.d.ts +22 -0
- package/dist/apis/Alert/index.js +141 -0
- package/dist/apis/Alert/index.js.map +1 -0
- package/dist/apis/AppState/index.d.ts +21 -0
- package/dist/apis/AppState/index.js +86 -0
- package/dist/apis/AppState/index.js.map +1 -0
- package/dist/apis/Appearance/index.d.ts +14 -0
- package/dist/apis/Appearance/index.js +39 -0
- package/dist/apis/Appearance/index.js.map +1 -0
- package/dist/apis/BackHandler/index.d.ts +10 -0
- package/dist/apis/BackHandler/index.js +16 -0
- package/dist/apis/BackHandler/index.js.map +1 -0
- package/dist/apis/Clipboard/index.d.ts +9 -0
- package/dist/apis/Clipboard/index.js +45 -0
- package/dist/apis/Clipboard/index.js.map +1 -0
- package/dist/apis/Dimensions/index.d.ts +19 -0
- package/dist/apis/Dimensions/index.js +66 -0
- package/dist/apis/Dimensions/index.js.map +1 -0
- package/dist/apis/I18nManager/index.d.ts +14 -0
- package/dist/apis/I18nManager/index.js +33 -0
- package/dist/apis/I18nManager/index.js.map +1 -0
- package/dist/apis/Keyboard/index.d.ts +36 -0
- package/dist/apis/Keyboard/index.js +149 -0
- package/dist/apis/Keyboard/index.js.map +1 -0
- package/dist/apis/Linking/index.d.ts +29 -0
- package/dist/apis/Linking/index.js +86 -0
- package/dist/apis/Linking/index.js.map +1 -0
- package/dist/apis/PanResponder/index.d.ts +50 -0
- package/dist/apis/PanResponder/index.js +239 -0
- package/dist/apis/PanResponder/index.js.map +1 -0
- package/dist/apis/PixelRatio/index.d.ts +8 -0
- package/dist/apis/PixelRatio/index.js +15 -0
- package/dist/apis/PixelRatio/index.js.map +1 -0
- package/dist/apis/Platform/index.d.ts +4 -0
- package/dist/apis/Platform/index.js +28 -0
- package/dist/apis/Platform/index.js.map +1 -0
- package/dist/apis/Platform/types.d.ts +19 -0
- package/dist/apis/Share/index.d.ts +30 -0
- package/dist/apis/Share/index.js +34 -0
- package/dist/apis/Share/index.js.map +1 -0
- package/dist/apis/StyleSheet/index.d.ts +23 -0
- package/dist/apis/StyleSheet/index.js +29 -0
- package/dist/apis/StyleSheet/index.js.map +1 -0
- package/dist/apis/StyleSheet/types.d.ts +328 -0
- package/dist/apis/Vibration/index.d.ts +9 -0
- package/dist/apis/Vibration/index.js +40 -0
- package/dist/apis/Vibration/index.js.map +1 -0
- package/dist/apis/processColor/index.d.ts +3 -0
- package/dist/apis/processColor/index.js +12 -0
- package/dist/apis/processColor/index.js.map +1 -0
- package/dist/apis/useColorScheme/index.d.ts +3 -0
- package/dist/apis/useColorScheme/index.js +13 -0
- package/dist/apis/useColorScheme/index.js.map +1 -0
- package/dist/apis/useWindowDimensions/index.d.ts +3 -0
- package/dist/apis/useWindowDimensions/index.js +19 -0
- package/dist/apis/useWindowDimensions/index.js.map +1 -0
- package/dist/bundler/index.js +30 -0
- package/dist/bundler/index.js.map +1 -0
- package/dist/bundler/inlinePlatformOS.js +121 -0
- package/dist/bundler/inlinePlatformOS.js.map +1 -0
- package/dist/bundler/worklets.js +61 -0
- package/dist/bundler/worklets.js.map +1 -0
- package/dist/compat/TurboModuleRegistry/index.d.ts +16 -0
- package/dist/compat/TurboModuleRegistry/index.js +14 -0
- package/dist/compat/TurboModuleRegistry/index.js.map +1 -0
- package/dist/compat/createElement/index.d.ts +9 -0
- package/dist/compat/createElement/index.js +40 -0
- package/dist/compat/createElement/index.js.map +1 -0
- package/dist/compat/findNodeHandle/index.d.ts +7 -0
- package/dist/compat/findNodeHandle/index.js +19 -0
- package/dist/compat/findNodeHandle/index.js.map +1 -0
- package/dist/components/ActivityIndicator/index.d.ts +5 -0
- package/dist/components/ActivityIndicator/index.js +74 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/types.d.ts +8 -0
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Button/index.js +48 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Button/types.d.ts +31 -0
- package/dist/components/FlatList/index.d.ts +5 -0
- package/dist/components/FlatList/index.js +433 -0
- package/dist/components/FlatList/index.js.map +1 -0
- package/dist/components/FlatList/types.d.ts +138 -0
- package/dist/components/FlatList/viewability.js +86 -0
- package/dist/components/FlatList/viewability.js.map +1 -0
- package/dist/components/Image/index.d.ts +7 -0
- package/dist/components/Image/index.js +301 -0
- package/dist/components/Image/index.js.map +1 -0
- package/dist/components/Image/source.js +97 -0
- package/dist/components/Image/source.js.map +1 -0
- package/dist/components/Image/types.d.ts +96 -0
- package/dist/components/KeyboardAvoidingView/index.d.ts +10 -0
- package/dist/components/KeyboardAvoidingView/index.js +118 -0
- package/dist/components/KeyboardAvoidingView/index.js.map +1 -0
- package/dist/components/KeyboardAvoidingView/types.d.ts +14 -0
- package/dist/components/Modal/index.d.ts +9 -0
- package/dist/components/Modal/index.js +271 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/types.d.ts +29 -0
- package/dist/components/Pressable/index.d.ts +5 -0
- package/dist/components/Pressable/index.js +106 -0
- package/dist/components/Pressable/index.js.map +1 -0
- package/dist/components/Pressable/types.d.ts +44 -0
- package/dist/components/RefreshControl/index.d.ts +5 -0
- package/dist/components/RefreshControl/index.js +176 -0
- package/dist/components/RefreshControl/index.js.map +1 -0
- package/dist/components/RefreshControl/pull.js +16 -0
- package/dist/components/RefreshControl/pull.js.map +1 -0
- package/dist/components/RefreshControl/types.d.ts +14 -0
- package/dist/components/ScrollView/index.d.ts +5 -0
- package/dist/components/ScrollView/index.js +318 -0
- package/dist/components/ScrollView/index.js.map +1 -0
- package/dist/components/ScrollView/snap.js +38 -0
- package/dist/components/ScrollView/snap.js.map +1 -0
- package/dist/components/ScrollView/types.d.ts +115 -0
- package/dist/components/StatusBar/index.d.ts +26 -0
- package/dist/components/StatusBar/index.js +113 -0
- package/dist/components/StatusBar/index.js.map +1 -0
- package/dist/components/Switch/index.d.ts +5 -0
- package/dist/components/Switch/index.js +89 -0
- package/dist/components/Switch/index.js.map +1 -0
- package/dist/components/Switch/types.d.ts +25 -0
- package/dist/components/Text/TextAncestorContext.d.ts +3 -0
- package/dist/components/Text/TextAncestorContext.js +6 -0
- package/dist/components/Text/TextAncestorContext.js.map +1 -0
- package/dist/components/Text/index.d.ts +6 -0
- package/dist/components/Text/index.js +133 -0
- package/dist/components/Text/index.js.map +1 -0
- package/dist/components/Text/types.d.ts +38 -0
- package/dist/components/TextInput/autocomplete.js +102 -0
- package/dist/components/TextInput/autocomplete.js.map +1 -0
- package/dist/components/TextInput/index.d.ts +8 -0
- package/dist/components/TextInput/index.js +290 -0
- package/dist/components/TextInput/index.js.map +1 -0
- package/dist/components/TextInput/types.d.ts +130 -0
- package/dist/components/TouchableHighlight/index.d.ts +5 -0
- package/dist/components/TouchableHighlight/index.js +109 -0
- package/dist/components/TouchableHighlight/index.js.map +1 -0
- package/dist/components/TouchableHighlight/types.d.ts +15 -0
- package/dist/components/TouchableNativeFeedback/index.d.ts +11 -0
- package/dist/components/TouchableNativeFeedback/index.js +29 -0
- package/dist/components/TouchableNativeFeedback/index.js.map +1 -0
- package/dist/components/TouchableNativeFeedback/types.d.ts +19 -0
- package/dist/components/TouchableOpacity/index.d.ts +5 -0
- package/dist/components/TouchableOpacity/index.js +122 -0
- package/dist/components/TouchableOpacity/index.js.map +1 -0
- package/dist/components/TouchableOpacity/types.d.ts +11 -0
- package/dist/components/TouchableWithoutFeedback/index.d.ts +5 -0
- package/dist/components/TouchableWithoutFeedback/index.js +70 -0
- package/dist/components/TouchableWithoutFeedback/index.js.map +1 -0
- package/dist/components/TouchableWithoutFeedback/types.d.ts +40 -0
- package/dist/components/View/index.d.ts +5 -0
- package/dist/components/View/index.js +50 -0
- package/dist/components/View/index.js.map +1 -0
- package/dist/components/View/types.d.ts +98 -0
- package/dist/dom/Head.d.ts +21 -0
- package/dist/dom/Head.js +53 -0
- package/dist/dom/Head.js.map +1 -0
- package/dist/dom/index.d.ts +2 -22
- package/dist/dom/index.js +1 -53
- package/dist/events/press/Pressability.d.ts +2 -0
- package/dist/events/press/Pressability.js +366 -0
- package/dist/events/press/Pressability.js.map +1 -0
- package/dist/events/press/cursorStyle.js +5 -0
- package/dist/events/press/cursorStyle.js.map +1 -0
- package/dist/events/press/index.d.ts +4 -0
- package/dist/events/press/mergeHandlers.js +30 -0
- package/dist/events/press/mergeHandlers.js.map +1 -0
- package/dist/events/press/types.d.ts +48 -0
- package/dist/events/press/usePressability.d.ts +4 -0
- package/dist/events/press/usePressability.js +18 -0
- package/dist/events/press/usePressability.js.map +1 -0
- package/dist/events/responderEvent.js +50 -0
- package/dist/events/responderEvent.js.map +1 -0
- package/dist/events/types.d.ts +33 -0
- package/dist/index.d.ts +66 -1597
- package/dist/index.js +42 -4864
- package/dist/reactNativeVersion.d.ts +7 -0
- package/dist/reactNativeVersion.js +10 -0
- package/dist/reactNativeVersion.js.map +1 -0
- package/dist/render/domProps.js +66 -0
- package/dist/render/domProps.js.map +1 -0
- package/dist/render/hitSlop.js +21 -0
- package/dist/render/hitSlop.js.map +1 -0
- package/dist/render/hostMethods.js +44 -0
- package/dist/render/hostMethods.js.map +1 -0
- package/dist/render/resolveTag.js +64 -0
- package/dist/render/resolveTag.js.map +1 -0
- package/dist/render/useElementLayout.js +25 -0
- package/dist/render/useElementLayout.js.map +1 -0
- package/dist/server/index.d.ts +2 -27
- package/dist/server/index.js +2 -2
- package/dist/{StyleRegistryContext-ROsMlY4O.js → style/StyleRegistryContext.js} +3 -3
- package/dist/style/StyleRegistryContext.js.map +1 -0
- package/dist/style/color.js +16 -0
- package/dist/style/color.js.map +1 -0
- package/dist/style/compile.js +72 -0
- package/dist/style/compile.js.map +1 -0
- package/dist/style/direction.js +33 -0
- package/dist/style/direction.js.map +1 -0
- package/dist/style/index.d.ts +1 -1
- package/dist/style/index.js +5 -2
- package/dist/style/index.js.map +1 -1
- package/dist/style/registry.d.ts +27 -0
- package/dist/{registry-Aa_Od5m0.js → style/registry.js} +3 -3
- package/dist/style/registry.js.map +1 -0
- package/dist/style/resolveStyle.js +181 -0
- package/dist/style/resolveStyle.js.map +1 -0
- package/dist/style/shadow.js +87 -0
- package/dist/style/shadow.js.map +1 -0
- package/dist/style/splitLayoutProps.js +52 -0
- package/dist/style/splitLayoutProps.js.map +1 -0
- package/dist/style/transform.js +35 -0
- package/dist/style/transform.js.map +1 -0
- package/dist/style/types.d.ts +4 -0
- package/dist/style/units.js +21 -0
- package/dist/style/units.js.map +1 -0
- package/dist/style/webStyle.js +9 -0
- package/dist/style/webStyle.js.map +1 -0
- package/dist/{env-DK5Mt9yX.js → utils/env.js} +2 -2
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/scrollLock.js +28 -0
- package/dist/utils/scrollLock.js.map +1 -0
- package/dist/utils/warn.js +11 -0
- package/dist/utils/warn.js.map +1 -0
- package/dist/vite/index.js +4 -202
- package/dist/vite/index.js.map +1 -1
- package/llms.txt +20 -0
- package/package.json +4 -3
- package/dist/StyleRegistryContext-ROsMlY4O.js.map +0 -1
- package/dist/compile-CVUjQrR9.js +0 -400
- package/dist/compile-CVUjQrR9.js.map +0 -1
- package/dist/dom/index.js.map +0 -1
- package/dist/env-DK5Mt9yX.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/registry-Aa_Od5m0.js.map +0 -1
- package/dist/types-BxTWbdj9.d.ts +0 -5
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { hasDOM } from "../../utils/env.js";
|
|
2
|
+
import { warnOnce } from "../../utils/warn.js";
|
|
3
|
+
// src/apis/Clipboard/index.ts
|
|
4
|
+
const clipboardAPI = () => hasDOM() ? navigator.clipboard : void 0;
|
|
5
|
+
const warnDeprecated = () => warnOnce("clipboard-deprecated", "Clipboard is deprecated in React Native, which will remove it in a future release.");
|
|
6
|
+
const warnRefused = (reason) => warnOnce("clipboard-write", `Clipboard.setString: the browser refused the copy. ${reason}`);
|
|
7
|
+
const copyWithTextarea = (content) => {
|
|
8
|
+
const focused = document.activeElement;
|
|
9
|
+
const textarea = document.createElement("textarea");
|
|
10
|
+
textarea.value = content;
|
|
11
|
+
textarea.setAttribute("readonly", "");
|
|
12
|
+
textarea.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none";
|
|
13
|
+
document.body.append(textarea);
|
|
14
|
+
textarea.select();
|
|
15
|
+
textarea.setSelectionRange(0, content.length);
|
|
16
|
+
const copied = document.execCommand("copy");
|
|
17
|
+
textarea.remove();
|
|
18
|
+
if (focused instanceof HTMLElement) focused.focus({ preventScroll: true });
|
|
19
|
+
if (!copied) warnRefused("Call setString from a press handler.");
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Reads and writes text on the clipboard with the async Clipboard API. Deprecated in React
|
|
23
|
+
* Native, so the first call logs a warning.
|
|
24
|
+
*/
|
|
25
|
+
const Clipboard = {
|
|
26
|
+
getString() {
|
|
27
|
+
warnDeprecated();
|
|
28
|
+
const api = clipboardAPI();
|
|
29
|
+
if (api === void 0 || typeof api.readText !== "function") return Promise.reject(/* @__PURE__ */ new Error("Clipboard.getString: this page can't read the clipboard. Reading needs https or localhost, and a browser with navigator.clipboard.readText."));
|
|
30
|
+
return api.readText();
|
|
31
|
+
},
|
|
32
|
+
setString(content) {
|
|
33
|
+
warnDeprecated();
|
|
34
|
+
if (!hasDOM()) return;
|
|
35
|
+
const api = clipboardAPI();
|
|
36
|
+
if (api === void 0 || typeof api.writeText !== "function") {
|
|
37
|
+
copyWithTextarea(content);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
api.writeText(content).catch((error) => warnRefused(String(error)));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export { Clipboard };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/apis/Clipboard/index.ts"],"sourcesContent":["import { hasDOM } from '../../utils/env'\nimport { warnOnce } from '../../utils/warn'\n\ntype BrowserClipboard = Navigator['clipboard']\n\n// A page on plain `http` (not localhost) has no `navigator.clipboard`.\nconst clipboardAPI = (): BrowserClipboard | undefined =>\n hasDOM() ? (navigator.clipboard as BrowserClipboard | undefined) : undefined\n\nconst warnDeprecated = (): void =>\n warnOnce(\n 'clipboard-deprecated',\n 'Clipboard is deprecated in React Native, which will remove it in a future release.',\n )\n\nconst warnRefused = (reason: string): void =>\n warnOnce('clipboard-write', `Clipboard.setString: the browser refused the copy. ${reason}`)\n\n// The copy of a page with no Clipboard API, for example a phone on the dev server over the LAN.\nconst copyWithTextarea = (content: string): void => {\n const focused = document.activeElement\n const textarea = document.createElement('textarea')\n textarea.value = content\n // `readonly` keeps a phone keyboard closed.\n textarea.setAttribute('readonly', '')\n textarea.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none'\n document.body.append(textarea)\n textarea.select()\n textarea.setSelectionRange(0, content.length)\n const copied = document.execCommand('copy')\n textarea.remove()\n if (focused instanceof HTMLElement) focused.focus({ preventScroll: true })\n if (!copied) warnRefused('Call setString from a press handler.')\n}\n\n/**\n * Reads and writes text on the clipboard with the async Clipboard API. Deprecated in React\n * Native, so the first call logs a warning.\n */\nexport const Clipboard: {\n getString: () => Promise<string>\n setString: (content: string) => void\n} = {\n getString() {\n warnDeprecated()\n const api = clipboardAPI()\n if (api === undefined || typeof api.readText !== 'function') {\n return Promise.reject(\n new Error(\n \"Clipboard.getString: this page can't read the clipboard. Reading needs https or localhost, and a browser with navigator.clipboard.readText.\",\n ),\n )\n }\n return api.readText()\n },\n\n setString(content) {\n warnDeprecated()\n if (!hasDOM()) return\n const api = clipboardAPI()\n if (api === undefined || typeof api.writeText !== 'function') {\n copyWithTextarea(content)\n return\n }\n api.writeText(content).catch((error: unknown) => warnRefused(String(error)))\n },\n}\n"],"mappings":";;;AAMA,MAAM,qBACJ,OAAO,IAAK,UAAU,YAA6C,KAAA;AAErE,MAAM,uBACJ,SACE,wBACA,oFACF;AAEF,MAAM,eAAe,WACnB,SAAS,mBAAmB,sDAAsD,QAAQ;AAG5F,MAAM,oBAAoB,YAA0B;CAClD,MAAM,UAAU,SAAS;CACzB,MAAM,WAAW,SAAS,cAAc,UAAU;CAClD,SAAS,QAAQ;CAEjB,SAAS,aAAa,YAAY,EAAE;CACpC,SAAS,MAAM,UAAU;CACzB,SAAS,KAAK,OAAO,QAAQ;CAC7B,SAAS,OAAO;CAChB,SAAS,kBAAkB,GAAG,QAAQ,MAAM;CAC5C,MAAM,SAAS,SAAS,YAAY,MAAM;CAC1C,SAAS,OAAO;CAChB,IAAI,mBAAmB,aAAa,QAAQ,MAAM,EAAE,eAAe,KAAK,CAAC;CACzE,IAAI,CAAC,QAAQ,YAAY,sCAAsC;AACjE;;;;;AAMA,MAAa,YAGT;CACF,YAAY;EACV,eAAe;EACf,MAAM,MAAM,aAAa;EACzB,IAAI,QAAQ,KAAA,KAAa,OAAO,IAAI,aAAa,YAC/C,OAAO,QAAQ,uBACb,IAAI,MACF,6IACF,CACF;EAEF,OAAO,IAAI,SAAS;CACtB;CAEA,UAAU,SAAS;EACjB,eAAe;EACf,IAAI,CAAC,OAAO,GAAG;EACf,MAAM,MAAM,aAAa;EACzB,IAAI,QAAQ,KAAA,KAAa,OAAO,IAAI,cAAc,YAAY;GAC5D,iBAAiB,OAAO;GACxB;EACF;EACA,IAAI,UAAU,OAAO,CAAC,CAAC,OAAO,UAAmB,YAAY,OAAO,KAAK,CAAC,CAAC;CAC7E;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ScaledSize = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
fontScale: number;
|
|
6
|
+
};
|
|
7
|
+
export type DimensionsValue = {
|
|
8
|
+
window: ScaledSize;
|
|
9
|
+
screen: ScaledSize;
|
|
10
|
+
};
|
|
11
|
+
export type DimensionsChangeHandler = (value: DimensionsValue) => void;
|
|
12
|
+
export type EmitterSubscription = {
|
|
13
|
+
remove: () => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const Dimensions: {
|
|
16
|
+
get: (dimension: "window" | "screen") => ScaledSize;
|
|
17
|
+
addEventListener: (type: "change", handler: DimensionsChangeHandler) => EmitterSubscription;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { hasDOM } from "../../utils/env.js";
|
|
2
|
+
// src/apis/Dimensions/index.ts
|
|
3
|
+
const serverSize = Object.freeze({
|
|
4
|
+
width: 0,
|
|
5
|
+
height: 0,
|
|
6
|
+
scale: 1,
|
|
7
|
+
fontScale: 1
|
|
8
|
+
});
|
|
9
|
+
const read = () => {
|
|
10
|
+
if (!hasDOM()) return {
|
|
11
|
+
window: serverSize,
|
|
12
|
+
screen: serverSize
|
|
13
|
+
};
|
|
14
|
+
const scale = window.devicePixelRatio || 1;
|
|
15
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
16
|
+
const fontScale = Number.isFinite(rootFontSize) && rootFontSize > 0 ? rootFontSize / 16 : 1;
|
|
17
|
+
return {
|
|
18
|
+
window: {
|
|
19
|
+
width: window.innerWidth,
|
|
20
|
+
height: window.innerHeight,
|
|
21
|
+
scale,
|
|
22
|
+
fontScale
|
|
23
|
+
},
|
|
24
|
+
screen: {
|
|
25
|
+
width: window.screen.width,
|
|
26
|
+
height: window.screen.height,
|
|
27
|
+
scale,
|
|
28
|
+
fontScale
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const sameSize = (a, b) => a.width === b.width && a.height === b.height && a.scale === b.scale && a.fontScale === b.fontScale;
|
|
33
|
+
let current = null;
|
|
34
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
35
|
+
let listening = false;
|
|
36
|
+
const refresh = () => {
|
|
37
|
+
const next = read();
|
|
38
|
+
if (current === null || !sameSize(current.window, next.window) || !sameSize(current.screen, next.screen)) current = next;
|
|
39
|
+
return current;
|
|
40
|
+
};
|
|
41
|
+
const update = () => {
|
|
42
|
+
const previous = current;
|
|
43
|
+
const value = refresh();
|
|
44
|
+
if (value === previous) return;
|
|
45
|
+
for (const handler of handlers) handler(value);
|
|
46
|
+
};
|
|
47
|
+
const listen = () => {
|
|
48
|
+
if (listening || !hasDOM()) return;
|
|
49
|
+
listening = true;
|
|
50
|
+
window.addEventListener("resize", update);
|
|
51
|
+
};
|
|
52
|
+
const Dimensions = {
|
|
53
|
+
get(dimension) {
|
|
54
|
+
return (current === null || !listening ? refresh() : current)[dimension];
|
|
55
|
+
},
|
|
56
|
+
addEventListener(type, handler) {
|
|
57
|
+
if (type !== "change") throw new Error(`Dimensions: unknown event "${String(type)}"`);
|
|
58
|
+
refresh();
|
|
59
|
+
handlers.add(handler);
|
|
60
|
+
listen();
|
|
61
|
+
return { remove: () => handlers.delete(handler) };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export { Dimensions };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/apis/Dimensions/index.ts"],"sourcesContent":["import { hasDOM } from '../../utils/env'\n\nexport type ScaledSize = {\n width: number\n height: number\n scale: number\n fontScale: number\n}\n\nexport type DimensionsValue = { window: ScaledSize; screen: ScaledSize }\n\nexport type DimensionsChangeHandler = (value: DimensionsValue) => void\n\nexport type EmitterSubscription = { remove: () => void }\n\nconst serverSize: ScaledSize = Object.freeze({ width: 0, height: 0, scale: 1, fontScale: 1 })\n\nconst read = (): DimensionsValue => {\n if (!hasDOM()) return { window: serverSize, screen: serverSize }\n\n const scale = window.devicePixelRatio || 1\n const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize)\n const fontScale = Number.isFinite(rootFontSize) && rootFontSize > 0 ? rootFontSize / 16 : 1\n\n return {\n window: { width: window.innerWidth, height: window.innerHeight, scale, fontScale },\n screen: { width: window.screen.width, height: window.screen.height, scale, fontScale },\n }\n}\n\nconst sameSize = (a: ScaledSize, b: ScaledSize): boolean =>\n a.width === b.width && a.height === b.height && a.scale === b.scale && a.fontScale === b.fontScale\n\nlet current: DimensionsValue | null = null\nconst handlers = new Set<DimensionsChangeHandler>()\nlet listening = false\n\n// Keeps the cached object while nothing changed, so a useSyncExternalStore\n// snapshot stays the same object between reads.\nconst refresh = (): DimensionsValue => {\n const next = read()\n if (\n current === null ||\n !sameSize(current.window, next.window) ||\n !sameSize(current.screen, next.screen)\n ) {\n current = next\n }\n return current\n}\n\nconst update = (): void => {\n const previous = current\n const value = refresh()\n if (value === previous) return\n for (const handler of handlers) handler(value)\n}\n\nconst listen = (): void => {\n if (listening || !hasDOM()) return\n listening = true\n window.addEventListener('resize', update)\n}\n\nexport const Dimensions: {\n get: (dimension: 'window' | 'screen') => ScaledSize\n addEventListener: (type: 'change', handler: DimensionsChangeHandler) => EmitterSubscription\n} = {\n get(dimension) {\n // Only the resize listener keeps the cache fresh. Before it starts, read again.\n const value = current === null || !listening ? refresh() : current\n return value[dimension]\n },\n\n addEventListener(type, handler) {\n if (type !== 'change') throw new Error(`Dimensions: unknown event \"${String(type)}\"`)\n refresh()\n handlers.add(handler)\n listen()\n return { remove: () => handlers.delete(handler) }\n },\n}\n\n// For tests.\nexport const resetDimensions = (): void => {\n current = null\n handlers.clear()\n if (listening) window.removeEventListener('resize', update)\n listening = false\n}\n"],"mappings":";;AAeA,MAAM,aAAyB,OAAO,OAAO;CAAE,OAAO;CAAG,QAAQ;CAAG,OAAO;CAAG,WAAW;AAAE,CAAC;AAE5F,MAAM,aAA8B;CAClC,IAAI,CAAC,OAAO,GAAG,OAAO;EAAE,QAAQ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EACP,OAAO,EAAE,cAAc,SAAS,OAAO,OAAO,EAAE;CAClD;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type I18nManagerConstants = {
|
|
2
|
+
isRTL: boolean;
|
|
3
|
+
doLeftAndRightSwapInRTL: boolean;
|
|
4
|
+
localeIdentifier: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare const I18nManager: {
|
|
7
|
+
readonly isRTL: boolean;
|
|
8
|
+
readonly doLeftAndRightSwapInRTL: boolean;
|
|
9
|
+
getConstants: () => I18nManagerConstants;
|
|
10
|
+
allowRTL: (allow: boolean) => void;
|
|
11
|
+
forceRTL: (force: boolean) => void;
|
|
12
|
+
swapLeftAndRightInRTL: (swap: boolean) => void;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getLeftAndRightSwap, setLeftAndRightSwap } from "../../style/direction.js";
|
|
2
|
+
import { hasDOM } from "../../utils/env.js";
|
|
3
|
+
// src/apis/I18nManager/index.ts
|
|
4
|
+
let allowed = true;
|
|
5
|
+
let forced = false;
|
|
6
|
+
const documentIsRTL = () => hasDOM() && getComputedStyle(document.documentElement).direction === "rtl";
|
|
7
|
+
const isRTL = () => forced || allowed && documentIsRTL();
|
|
8
|
+
const I18nManager = {
|
|
9
|
+
get isRTL() {
|
|
10
|
+
return isRTL();
|
|
11
|
+
},
|
|
12
|
+
get doLeftAndRightSwapInRTL() {
|
|
13
|
+
return getLeftAndRightSwap();
|
|
14
|
+
},
|
|
15
|
+
getConstants: () => ({
|
|
16
|
+
isRTL: isRTL(),
|
|
17
|
+
doLeftAndRightSwapInRTL: getLeftAndRightSwap(),
|
|
18
|
+
localeIdentifier: hasDOM() ? navigator.language : void 0
|
|
19
|
+
}),
|
|
20
|
+
allowRTL: (allow) => {
|
|
21
|
+
allowed = allow;
|
|
22
|
+
},
|
|
23
|
+
forceRTL: (force) => {
|
|
24
|
+
forced = force;
|
|
25
|
+
if (hasDOM()) document.documentElement.dir = force ? "rtl" : "";
|
|
26
|
+
},
|
|
27
|
+
swapLeftAndRightInRTL: (swap) => {
|
|
28
|
+
setLeftAndRightSwap(swap);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export { I18nManager };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/apis/I18nManager/index.ts"],"sourcesContent":["import { getLeftAndRightSwap, setLeftAndRightSwap } from '../../style/direction'\nimport { hasDOM } from '../../utils/env'\n\nexport type I18nManagerConstants = {\n isRTL: boolean\n doLeftAndRightSwapInRTL: boolean\n localeIdentifier: string | undefined\n}\n\nlet allowed = true\nlet forced = false\n\n// The document direction, which the page sets with `dir` or with CSS.\nconst documentIsRTL = (): boolean =>\n hasDOM() && getComputedStyle(document.documentElement).direction === 'rtl'\n\nconst isRTL = (): boolean => forced || (allowed && documentIsRTL())\n\nexport const I18nManager: {\n readonly isRTL: boolean\n readonly doLeftAndRightSwapInRTL: boolean\n getConstants: () => I18nManagerConstants\n allowRTL: (allow: boolean) => void\n forceRTL: (force: boolean) => void\n swapLeftAndRightInRTL: (swap: boolean) => void\n} = {\n get isRTL() {\n return isRTL()\n },\n\n get doLeftAndRightSwapInRTL() {\n return getLeftAndRightSwap()\n },\n\n getConstants: () => ({\n isRTL: isRTL(),\n doLeftAndRightSwapInRTL: getLeftAndRightSwap(),\n localeIdentifier: hasDOM() ? navigator.language : undefined,\n }),\n\n allowRTL: (allow) => {\n allowed = allow\n },\n\n // On native this takes effect after a restart. Here it sets the document\n // direction at once, so logical styles and text follow.\n forceRTL: (force) => {\n forced = force\n if (hasDOM()) document.documentElement.dir = force ? 'rtl' : ''\n },\n\n // Call it before the first render. A style that a component compiled before keeps its\n // classes until the component renders again.\n swapLeftAndRightInRTL: (swap) => {\n setLeftAndRightSwap(swap)\n },\n}\n\n// For tests.\nexport const resetI18nManager = (): void => {\n allowed = true\n forced = false\n setLeftAndRightSwap(true)\n if (hasDOM()) document.documentElement.dir = ''\n}\n"],"mappings":";;;AASA,IAAI,UAAU;AACd,IAAI,SAAS;AAGb,MAAM,sBACJ,OAAO,KAAK,iBAAiB,SAAS,eAAe,CAAC,CAAC,cAAc;AAEvE,MAAM,cAAuB,UAAW,WAAW,cAAc;AAEjE,MAAa,cAOT;CACF,IAAI,QAAQ;EACV,OAAO,MAAM;CACf;CAEA,IAAI,0BAA0B;EAC5B,OAAO,oBAAoB;CAC7B;CAEA,qBAAqB;EACnB,OAAO,MAAM;EACb,yBAAyB,oBAAoB;EAC7C,kBAAkB,OAAO,IAAI,UAAU,WAAW,KAAA;CACpD;CAEA,WAAW,UAAU;EACnB,UAAU;CACZ;CAIA,WAAW,UAAU;EACnB,SAAS;EACT,IAAI,OAAO,GAAG,SAAS,gBAAgB,MAAM,QAAQ,QAAQ;CAC/D;CAIA,wBAAwB,SAAS;EAC/B,oBAAoB,IAAI;CAC1B;AACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventSubscription } from "../../events/types.js";
|
|
2
|
+
export type KeyboardEventName = "keyboardWillShow" | "keyboardDidShow" | "keyboardWillHide" | "keyboardDidHide" | "keyboardWillChangeFrame" | "keyboardDidChangeFrame";
|
|
3
|
+
export type KeyboardEventEasing = "easeIn" | "easeInEaseOut" | "easeOut" | "linear" | "keyboard";
|
|
4
|
+
export type KeyboardMetrics = Readonly<{
|
|
5
|
+
screenX: number;
|
|
6
|
+
screenY: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}>;
|
|
10
|
+
export type AndroidKeyboardEvent = Readonly<{
|
|
11
|
+
duration: 0;
|
|
12
|
+
easing: "keyboard";
|
|
13
|
+
endCoordinates: KeyboardMetrics;
|
|
14
|
+
}>;
|
|
15
|
+
export type IOSKeyboardEvent = Readonly<{
|
|
16
|
+
duration: number;
|
|
17
|
+
easing: KeyboardEventEasing;
|
|
18
|
+
endCoordinates: KeyboardMetrics;
|
|
19
|
+
startCoordinates: KeyboardMetrics;
|
|
20
|
+
isEventFromThisApp: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
export type KeyboardEvent = AndroidKeyboardEvent | IOSKeyboardEvent;
|
|
23
|
+
/**
|
|
24
|
+
* The keyboard of a phone or a tablet, as on Android: `keyboardDidShow` fires when the keyboard
|
|
25
|
+
* shows and when its height changes, and `keyboardDidHide` fires when it hides. The `Will` and
|
|
26
|
+
* `ChangeFrame` events never fire.
|
|
27
|
+
*/
|
|
28
|
+
export declare const Keyboard: {
|
|
29
|
+
addListener: <K extends KeyboardEventName>(eventType: K, listener: (event: KeyboardEvent) => unknown, context?: unknown) => EventSubscription;
|
|
30
|
+
removeAllListeners: (eventType?: KeyboardEventName | null) => void;
|
|
31
|
+
dismiss: () => void;
|
|
32
|
+
isVisible: () => boolean;
|
|
33
|
+
metrics: () => KeyboardMetrics | null | undefined;
|
|
34
|
+
scheduleLayoutAnimation: (event: KeyboardEvent) => void;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { hasDOM } from "../../utils/env.js";
|
|
2
|
+
// src/apis/Keyboard/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Internal. Where the keyboard module reads the two browser objects. A test replaces them,
|
|
5
|
+
* because a headless browser shows no keyboard.
|
|
6
|
+
*/
|
|
7
|
+
const keyboardSources = {
|
|
8
|
+
visualViewport: () => window.visualViewport,
|
|
9
|
+
virtualKeyboard: () => navigator.virtualKeyboard
|
|
10
|
+
};
|
|
11
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
12
|
+
let observed = null;
|
|
13
|
+
let current = null;
|
|
14
|
+
let frame = null;
|
|
15
|
+
const noTextInputTypes = /* @__PURE__ */ new Set([
|
|
16
|
+
"button",
|
|
17
|
+
"checkbox",
|
|
18
|
+
"color",
|
|
19
|
+
"file",
|
|
20
|
+
"hidden",
|
|
21
|
+
"image",
|
|
22
|
+
"radio",
|
|
23
|
+
"range",
|
|
24
|
+
"reset",
|
|
25
|
+
"submit"
|
|
26
|
+
]);
|
|
27
|
+
const isEditable = (element) => {
|
|
28
|
+
if (element instanceof HTMLTextAreaElement) return !element.readOnly && !element.disabled;
|
|
29
|
+
if (element instanceof HTMLInputElement) return !element.readOnly && !element.disabled && !noTextInputTypes.has(element.type);
|
|
30
|
+
return element instanceof HTMLElement && element.isContentEditable;
|
|
31
|
+
};
|
|
32
|
+
const read = () => {
|
|
33
|
+
if (!hasDOM()) return null;
|
|
34
|
+
const root = document.documentElement;
|
|
35
|
+
const virtualKeyboard = keyboardSources.virtualKeyboard();
|
|
36
|
+
if (virtualKeyboard?.overlaysContent === true) {
|
|
37
|
+
const { x, y, width, height } = virtualKeyboard.boundingRect;
|
|
38
|
+
return height > 0 ? {
|
|
39
|
+
screenX: x,
|
|
40
|
+
screenY: y,
|
|
41
|
+
width,
|
|
42
|
+
height
|
|
43
|
+
} : null;
|
|
44
|
+
}
|
|
45
|
+
const viewport = keyboardSources.visualViewport();
|
|
46
|
+
if (viewport === null || !isEditable(document.activeElement)) return null;
|
|
47
|
+
const height = Math.round(root.clientHeight - viewport.height * viewport.scale);
|
|
48
|
+
if (height <= 0) return null;
|
|
49
|
+
return {
|
|
50
|
+
screenX: 0,
|
|
51
|
+
screenY: Math.min(root.clientHeight - height + Math.round(viewport.offsetTop), root.clientHeight),
|
|
52
|
+
width: root.clientWidth,
|
|
53
|
+
height
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const hiddenMetrics = () => ({
|
|
57
|
+
screenX: 0,
|
|
58
|
+
screenY: hasDOM() ? document.documentElement.clientHeight : 0,
|
|
59
|
+
width: hasDOM() ? document.documentElement.clientWidth : 0,
|
|
60
|
+
height: 0
|
|
61
|
+
});
|
|
62
|
+
const toEvent = (endCoordinates) => ({
|
|
63
|
+
duration: 0,
|
|
64
|
+
easing: "keyboard",
|
|
65
|
+
endCoordinates
|
|
66
|
+
});
|
|
67
|
+
const sameMetrics = (a, b) => a === b || a !== null && b !== null && a.screenX === b.screenX && a.screenY === b.screenY && a.width === b.width && a.height === b.height;
|
|
68
|
+
const emit = (name, event) => {
|
|
69
|
+
const set = listeners.get(name);
|
|
70
|
+
if (set === void 0) return;
|
|
71
|
+
for (const listener of set) listener(event);
|
|
72
|
+
};
|
|
73
|
+
const update = () => {
|
|
74
|
+
frame = null;
|
|
75
|
+
const next = read();
|
|
76
|
+
if (sameMetrics(next, current)) return;
|
|
77
|
+
current = next;
|
|
78
|
+
if (next === null) emit("keyboardDidHide", toEvent(hiddenMetrics()));
|
|
79
|
+
else emit("keyboardDidShow", toEvent(next));
|
|
80
|
+
};
|
|
81
|
+
const schedule = () => {
|
|
82
|
+
if (frame === null) frame = requestAnimationFrame(update);
|
|
83
|
+
};
|
|
84
|
+
const startObserving = () => {
|
|
85
|
+
if (observed !== null || !hasDOM()) return;
|
|
86
|
+
observed = {
|
|
87
|
+
viewport: keyboardSources.visualViewport(),
|
|
88
|
+
virtualKeyboard: keyboardSources.virtualKeyboard()
|
|
89
|
+
};
|
|
90
|
+
current = read();
|
|
91
|
+
observed.viewport?.addEventListener("resize", schedule);
|
|
92
|
+
observed.viewport?.addEventListener("scroll", schedule);
|
|
93
|
+
observed.virtualKeyboard?.addEventListener("geometrychange", schedule);
|
|
94
|
+
window.addEventListener("resize", schedule);
|
|
95
|
+
};
|
|
96
|
+
const stopObserving = () => {
|
|
97
|
+
if (observed === null) return;
|
|
98
|
+
for (const set of listeners.values()) if (set.size > 0) return;
|
|
99
|
+
observed.viewport?.removeEventListener("resize", schedule);
|
|
100
|
+
observed.viewport?.removeEventListener("scroll", schedule);
|
|
101
|
+
observed.virtualKeyboard?.removeEventListener("geometrychange", schedule);
|
|
102
|
+
window.removeEventListener("resize", schedule);
|
|
103
|
+
observed = null;
|
|
104
|
+
if (frame !== null) cancelAnimationFrame(frame);
|
|
105
|
+
frame = null;
|
|
106
|
+
current = null;
|
|
107
|
+
};
|
|
108
|
+
const state = () => observed === null ? read() : current;
|
|
109
|
+
/**
|
|
110
|
+
* The keyboard of a phone or a tablet, as on Android: `keyboardDidShow` fires when the keyboard
|
|
111
|
+
* shows and when its height changes, and `keyboardDidHide` fires when it hides. The `Will` and
|
|
112
|
+
* `ChangeFrame` events never fire.
|
|
113
|
+
*/
|
|
114
|
+
const Keyboard = {
|
|
115
|
+
addListener(eventType, listener) {
|
|
116
|
+
let set = listeners.get(eventType);
|
|
117
|
+
if (set === void 0) {
|
|
118
|
+
set = /* @__PURE__ */ new Set();
|
|
119
|
+
listeners.set(eventType, set);
|
|
120
|
+
}
|
|
121
|
+
const entry = (event) => listener(event);
|
|
122
|
+
set.add(entry);
|
|
123
|
+
startObserving();
|
|
124
|
+
return { remove: () => {
|
|
125
|
+
set.delete(entry);
|
|
126
|
+
stopObserving();
|
|
127
|
+
} };
|
|
128
|
+
},
|
|
129
|
+
removeAllListeners(eventType) {
|
|
130
|
+
if (eventType === void 0 || eventType === null) listeners.clear();
|
|
131
|
+
else listeners.delete(eventType);
|
|
132
|
+
stopObserving();
|
|
133
|
+
},
|
|
134
|
+
dismiss() {
|
|
135
|
+
if (!hasDOM()) return;
|
|
136
|
+
const active = document.activeElement;
|
|
137
|
+
if (isEditable(active)) active.blur();
|
|
138
|
+
},
|
|
139
|
+
isVisible() {
|
|
140
|
+
return state() !== null;
|
|
141
|
+
},
|
|
142
|
+
metrics() {
|
|
143
|
+
return state() ?? void 0;
|
|
144
|
+
},
|
|
145
|
+
scheduleLayoutAnimation() {}
|
|
146
|
+
};
|
|
147
|
+
export { Keyboard, keyboardSources };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/apis/Keyboard/index.ts"],"sourcesContent":["import type { EventSubscription } from '../../events/types'\nimport { hasDOM } from '../../utils/env'\n\nexport type KeyboardEventName =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide'\n | 'keyboardWillChangeFrame'\n | 'keyboardDidChangeFrame'\n\nexport type KeyboardEventEasing = 'easeIn' | 'easeInEaseOut' | 'easeOut' | 'linear' | 'keyboard'\n\nexport type KeyboardMetrics = Readonly<{\n screenX: number\n screenY: number\n width: number\n height: number\n}>\n\nexport type AndroidKeyboardEvent = Readonly<{\n duration: 0\n easing: 'keyboard'\n endCoordinates: KeyboardMetrics\n}>\n\nexport type IOSKeyboardEvent = Readonly<{\n duration: number\n easing: KeyboardEventEasing\n endCoordinates: KeyboardMetrics\n startCoordinates: KeyboardMetrics\n isEventFromThisApp: boolean\n}>\n\nexport type KeyboardEvent = AndroidKeyboardEvent | IOSKeyboardEvent\n\ntype Listener = (event: KeyboardEvent) => unknown\n\ntype VirtualKeyboard = EventTarget & { overlaysContent: boolean; boundingRect: DOMRectReadOnly }\n\n/**\n * Internal. Where the keyboard module reads the two browser objects. A test replaces them,\n * because a headless browser shows no keyboard.\n */\nexport const keyboardSources: {\n visualViewport: () => VisualViewport | null\n virtualKeyboard: () => VirtualKeyboard | undefined\n} = {\n visualViewport: () => window.visualViewport,\n virtualKeyboard: () => (navigator as { virtualKeyboard?: VirtualKeyboard }).virtualKeyboard,\n}\n\nconst listeners = new Map<string, Set<Listener>>()\n// The objects that have our listeners, so the same ones lose them again.\nlet observed: {\n viewport: VisualViewport | null\n virtualKeyboard: VirtualKeyboard | undefined\n} | null = null\nlet current: KeyboardMetrics | null = null\nlet frame: number | null = null\n\n// The input types that take no text, so the browser shows no keyboard for them.\nconst noTextInputTypes = new Set([\n 'button',\n 'checkbox',\n 'color',\n 'file',\n 'hidden',\n 'image',\n 'radio',\n 'range',\n 'reset',\n 'submit',\n])\n\nconst isEditable = (element: Element | null): element is HTMLElement => {\n if (element instanceof HTMLTextAreaElement) return !element.readOnly && !element.disabled\n if (element instanceof HTMLInputElement) {\n return !element.readOnly && !element.disabled && !noTextInputTypes.has(element.type)\n }\n return element instanceof HTMLElement && element.isContentEditable\n}\n\n// The keyboard as the browser shows it now, or null.\nconst read = (): KeyboardMetrics | null => {\n if (!hasDOM()) return null\n const root = document.documentElement\n\n // An app that sets `overlaysContent` gets a keyboard over the page, and its exact rectangle.\n const virtualKeyboard = keyboardSources.virtualKeyboard()\n if (virtualKeyboard?.overlaysContent === true) {\n const { x, y, width, height } = virtualKeyboard.boundingRect\n return height > 0 ? { screenX: x, screenY: y, width, height } : null\n }\n\n // Else the keyboard covers the page, and the visual viewport shrinks by its height. A pinch\n // zoom shrinks the visual viewport too, so its height counts at a scale of 1. Without a focused\n // text field, a smaller viewport has another cause.\n const viewport = keyboardSources.visualViewport()\n if (viewport === null || !isEditable(document.activeElement)) return null\n const height = Math.round(root.clientHeight - viewport.height * viewport.scale)\n if (height <= 0) return null\n // A browser can also move the visual viewport down the page to show the focused field. The\n // keyboard then starts lower on the page, and covers less of it, or nothing.\n const screenY = Math.min(\n root.clientHeight - height + Math.round(viewport.offsetTop),\n root.clientHeight,\n )\n return { screenX: 0, screenY, width: root.clientWidth, height }\n}\n\nconst hiddenMetrics = (): KeyboardMetrics => ({\n screenX: 0,\n screenY: hasDOM() ? document.documentElement.clientHeight : 0,\n width: hasDOM() ? document.documentElement.clientWidth : 0,\n height: 0,\n})\n\n// As on Android: a duration of 0 and the `keyboard` easing.\nconst toEvent = (endCoordinates: KeyboardMetrics): AndroidKeyboardEvent => ({\n duration: 0,\n easing: 'keyboard',\n endCoordinates,\n})\n\nconst sameMetrics = (a: KeyboardMetrics | null, b: KeyboardMetrics | null): boolean =>\n a === b ||\n (a !== null &&\n b !== null &&\n a.screenX === b.screenX &&\n a.screenY === b.screenY &&\n a.width === b.width &&\n a.height === b.height)\n\nconst emit = (name: KeyboardEventName, event: KeyboardEvent): void => {\n const set = listeners.get(name)\n if (set === undefined) return\n for (const listener of set) listener(event)\n}\n\n// As on Android: a new height while the keyboard shows fires `keyboardDidShow` again.\nconst update = (): void => {\n frame = null\n const next = read()\n if (sameMetrics(next, current)) return\n current = next\n if (next === null) emit('keyboardDidHide', toEvent(hiddenMetrics()))\n else emit('keyboardDidShow', toEvent(next))\n}\n\n// The viewport can resize on each frame while the keyboard moves. One read per frame is enough.\nconst schedule = (): void => {\n if (frame === null) frame = requestAnimationFrame(update)\n}\n\nconst startObserving = (): void => {\n if (observed !== null || !hasDOM()) return\n observed = {\n viewport: keyboardSources.visualViewport(),\n virtualKeyboard: keyboardSources.virtualKeyboard(),\n }\n current = read()\n observed.viewport?.addEventListener('resize', schedule)\n observed.viewport?.addEventListener('scroll', schedule)\n observed.virtualKeyboard?.addEventListener('geometrychange', schedule)\n window.addEventListener('resize', schedule)\n}\n\nconst stopObserving = (): void => {\n if (observed === null) return\n for (const set of listeners.values()) if (set.size > 0) return\n observed.viewport?.removeEventListener('resize', schedule)\n observed.viewport?.removeEventListener('scroll', schedule)\n observed.virtualKeyboard?.removeEventListener('geometrychange', schedule)\n window.removeEventListener('resize', schedule)\n observed = null\n if (frame !== null) cancelAnimationFrame(frame)\n frame = null\n current = null\n}\n\nconst state = (): KeyboardMetrics | null => (observed === null ? read() : current)\n\n/**\n * The keyboard of a phone or a tablet, as on Android: `keyboardDidShow` fires when the keyboard\n * shows and when its height changes, and `keyboardDidHide` fires when it hides. The `Will` and\n * `ChangeFrame` events never fire.\n */\nexport const Keyboard: {\n addListener: <K extends KeyboardEventName>(\n eventType: K,\n listener: (event: KeyboardEvent) => unknown,\n context?: unknown,\n ) => EventSubscription\n removeAllListeners: (eventType?: KeyboardEventName | null) => void\n dismiss: () => void\n isVisible: () => boolean\n metrics: () => KeyboardMetrics | null | undefined\n scheduleLayoutAnimation: (event: KeyboardEvent) => void\n} = {\n addListener(eventType, listener) {\n let set = listeners.get(eventType)\n if (set === undefined) {\n set = new Set()\n listeners.set(eventType, set)\n }\n const entry: Listener = (event) => listener(event)\n set.add(entry)\n startObserving()\n return {\n remove: () => {\n set.delete(entry)\n stopObserving()\n },\n }\n },\n\n removeAllListeners(eventType) {\n if (eventType === undefined || eventType === null) listeners.clear()\n else listeners.delete(eventType)\n stopObserving()\n },\n\n dismiss() {\n if (!hasDOM()) return\n const active = document.activeElement\n if (isEditable(active)) active.blur()\n },\n\n isVisible() {\n return state() !== null\n },\n\n metrics() {\n return state() ?? undefined\n },\n\n // Native animates the next layout with the keyboard. The web has no layout animation, and its\n // keyboard events have no duration.\n scheduleLayoutAnimation() {},\n}\n"],"mappings":";;;;;;AA4CA,MAAa,kBAGT;CACF,sBAAsB,OAAO;CAC7B,uBAAwB,UAAoD;AAC9E;AAEA,MAAM,4BAAY,IAAI,IAA2B;AAEjD,IAAI,WAGO;AACX,IAAI,UAAkC;AACtC,IAAI,QAAuB;AAG3B,MAAM,mCAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,cAAc,YAAoD;CACtE,IAAI,mBAAmB,qBAAqB,OAAO,CAAC,QAAQ,YAAY,CAAC,QAAQ;CACjF,IAAI,mBAAmB,kBACrB,OAAO,CAAC,QAAQ,YAAY,CAAC,QAAQ,YAAY,CAAC,iBAAiB,IAAI,QAAQ,IAAI;CAErF,OAAO,mBAAmB,eAAe,QAAQ;AACnD;AAGA,MAAM,aAAqC;CACzC,IAAI,CAAC,OAAO,GAAG,OAAO;CACtB,MAAM,OAAO,SAAS;CAGtB,MAAM,kBAAkB,gBAAgB,gBAAgB;CACxD,IAAI,iBAAiB,oBAAoB,MAAM;EAC7C,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,gBAAgB;EAChD,OAAO,SAAS,IAAI;GAAE,SAAS;GAAG,SAAS;GAAG;GAAO;EAAO,IAAI;CAClE;CAKA,MAAM,WAAW,gBAAgB,eAAe;CAChD,IAAI,aAAa,QAAQ,CAAC,WAAW,SAAS,aAAa,GAAG,OAAO;CACrE,MAAM,SAAS,KAAK,MAAM,KAAK,eAAe,S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ingEventDefinitions = {
|
|
3
|
+
url: [{
|
|
4
|
+
url: string;
|
|
5
|
+
}];
|
|
6
|
+
};
|
|
7
|
+
type LinkingEvent = keyof LinkingEventDefinitions;
|
|
8
|
+
/**
|
|
9
|
+
* Opens URLs and reports the URL that the page loaded with. A URL of this site opens in this tab,
|
|
10
|
+
* a URL of another site in a new tab, and `mailto:`, `tel:`, and other schemes go to the system.
|
|
11
|
+
* The browser never fires `url`: back, forward, and links belong to the router.
|
|
12
|
+
*/
|
|
13
|
+
export declare const Linking: {
|
|
14
|
+
addEventListener: <K extends LinkingEvent>(eventType: K, listener: (...args: LinkingEventDefinitions[K]) => unknown) => EventSubscription;
|
|
15
|
+
addListener: <K extends LinkingEvent>(eventType: K, listener: (...args: LinkingEventDefinitions[K]) => unknown, context?: unknown) => EventSubscription;
|
|
16
|
+
emit: <K extends LinkingEvent>(eventType: K, ...args: LinkingEventDefinitions[K]) => void;
|
|
17
|
+
removeAllListeners: <K extends LinkingEvent>(eventType?: K | null) => void;
|
|
18
|
+
listenerCount: <K extends LinkingEvent>(eventType: K) => number;
|
|
19
|
+
openURL: (url: string) => Promise<void>;
|
|
20
|
+
canOpenURL: (url: string) => Promise<boolean>;
|
|
21
|
+
openSettings: () => Promise<void>;
|
|
22
|
+
getInitialURL: () => Promise<string | null>;
|
|
23
|
+
sendIntent: (action: string, extras?: Array<{
|
|
24
|
+
key: string;
|
|
25
|
+
value: string | number | boolean;
|
|
26
|
+
}>) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { hasDOM } from "../../utils/env.js";
|
|
2
|
+
// src/apis/Linking/index.ts
|
|
3
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
4
|
+
const addListener = (eventType, listener, context) => {
|
|
5
|
+
let set = registrations.get(eventType);
|
|
6
|
+
if (set === void 0) {
|
|
7
|
+
set = /* @__PURE__ */ new Set();
|
|
8
|
+
registrations.set(eventType, set);
|
|
9
|
+
}
|
|
10
|
+
const registration = {
|
|
11
|
+
listener,
|
|
12
|
+
context
|
|
13
|
+
};
|
|
14
|
+
const owner = set;
|
|
15
|
+
owner.add(registration);
|
|
16
|
+
return { remove: () => owner.delete(registration) };
|
|
17
|
+
};
|
|
18
|
+
const validate = (url) => {
|
|
19
|
+
if (typeof url !== "string") throw new Error(`Invalid URL: should be a string. Was: ${String(url)}`);
|
|
20
|
+
if (url === "") throw new Error("Invalid URL: cannot be empty");
|
|
21
|
+
};
|
|
22
|
+
const REFUSED_PROTOCOLS = /* @__PURE__ */ new Set(["javascript:", "data:"]);
|
|
23
|
+
const destination = (url) => {
|
|
24
|
+
if (!hasDOM()) return /* @__PURE__ */ new Error("Linking: there is no browser to open a URL in.");
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = new URL(url, window.location.href);
|
|
28
|
+
} catch {
|
|
29
|
+
return /* @__PURE__ */ new Error(`Linking: "${url}" isn't a valid URL.`);
|
|
30
|
+
}
|
|
31
|
+
if (REFUSED_PROTOCOLS.has(parsed.protocol)) return /* @__PURE__ */ new Error(`Linking: refused to open a ${parsed.protocol} URL.`);
|
|
32
|
+
const web = parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
33
|
+
return {
|
|
34
|
+
href: parsed.href,
|
|
35
|
+
newTab: web && parsed.origin !== window.location.origin
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const loadedURL = () => {
|
|
39
|
+
if (!hasDOM()) return null;
|
|
40
|
+
const [entry] = performance.getEntriesByType("navigation");
|
|
41
|
+
return entry?.name || window.location.href;
|
|
42
|
+
};
|
|
43
|
+
/** For tests: `location.assign` can't be replaced, so the tests replace this. */
|
|
44
|
+
const browserNavigation = { assign: (href) => window.location.assign(href) };
|
|
45
|
+
/**
|
|
46
|
+
* Opens URLs and reports the URL that the page loaded with. A URL of this site opens in this tab,
|
|
47
|
+
* a URL of another site in a new tab, and `mailto:`, `tel:`, and other schemes go to the system.
|
|
48
|
+
* The browser never fires `url`: back, forward, and links belong to the router.
|
|
49
|
+
*/
|
|
50
|
+
const Linking = {
|
|
51
|
+
addEventListener: (eventType, listener) => addListener(eventType, listener),
|
|
52
|
+
addListener,
|
|
53
|
+
emit(eventType, ...args) {
|
|
54
|
+
const set = registrations.get(eventType);
|
|
55
|
+
if (set === void 0) return;
|
|
56
|
+
for (const { listener, context } of Array.from(set)) Reflect.apply(listener, context, args);
|
|
57
|
+
},
|
|
58
|
+
removeAllListeners(eventType) {
|
|
59
|
+
if (eventType === void 0 || eventType === null) registrations.clear();
|
|
60
|
+
else registrations.delete(eventType);
|
|
61
|
+
},
|
|
62
|
+
listenerCount: (eventType) => registrations.get(eventType)?.size ?? 0,
|
|
63
|
+
openURL(url) {
|
|
64
|
+
validate(url);
|
|
65
|
+
const target = destination(url);
|
|
66
|
+
if (target instanceof Error) return Promise.reject(target);
|
|
67
|
+
if (!target.newTab) {
|
|
68
|
+
browserNavigation.assign(target.href);
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
}
|
|
71
|
+
const opened = window.open(target.href, "_blank");
|
|
72
|
+
if (opened === null) return Promise.reject(/* @__PURE__ */ new Error(`Linking: the browser blocked the new tab for ${target.href}. Call openURL from a press handler.`));
|
|
73
|
+
opened.opener = null;
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
},
|
|
76
|
+
canOpenURL(url) {
|
|
77
|
+
validate(url);
|
|
78
|
+
return Promise.resolve(!(destination(url) instanceof Error));
|
|
79
|
+
},
|
|
80
|
+
openSettings: () => Promise.reject(/* @__PURE__ */ new Error("Linking.openSettings: the web has no settings page for an app.")),
|
|
81
|
+
getInitialURL: () => Promise.resolve(loadedURL()),
|
|
82
|
+
sendIntent: () => Promise.reject(/* @__PURE__ */ new Error("Unsupported"))
|
|
83
|
+
};
|
|
84
|
+
export { Linking, browserNavigation };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/apis/Linking/index.ts"],"sourcesContent":["import type { EventSubscription } from '../../events/types'\nimport { hasDOM } from '../../utils/env'\n\ntype LinkingEventDefinitions = {\n url: [{ url: string }]\n}\n\ntype LinkingEvent = keyof LinkingEventDefinitions\n\ntype Registration = { listener: (...args: never[]) => unknown; context: unknown }\n\nconst registrations = new Map<string, Set<Registration>>()\n\nconst addListener = <K extends LinkingEvent>(\n eventType: K,\n listener: (...args: LinkingEventDefinitions[K]) => unknown,\n context?: unknown,\n): EventSubscription => {\n let set = registrations.get(eventType)\n if (set === undefined) {\n set = new Set()\n registrations.set(eventType, set)\n }\n const registration: Registration = { listener, context }\n const owner = set\n owner.add(registration)\n return { remove: () => owner.delete(registration) }\n}\n\nconst validate = (url: unknown): void => {\n if (typeof url !== 'string') {\n throw new Error(`Invalid URL: should be a string. Was: ${String(url)}`)\n }\n if (url === '') throw new Error('Invalid URL: cannot be empty')\n}\n\n// Browsers block a page that opens a data: URL, and a javascript: URL runs code in this page.\nconst REFUSED_PROTOCOLS = new Set(['javascript:', 'data:'])\n\ntype Destination = { href: string; newTab: boolean }\n\nconst destination = (url: string): Destination | Error => {\n if (!hasDOM()) return new Error('Linking: there is no browser to open a URL in.')\n let parsed: URL\n try {\n parsed = new URL(url, window.location.href)\n } catch {\n return new Error(`Linking: \"${url}\" isn't a valid URL.`)\n }\n if (REFUSED_PROTOCOLS.has(parsed.protocol)) {\n return new Error(`Linking: refused to open a ${parsed.protocol} URL.`)\n }\n const web = parsed.protocol === 'http:' || parsed.protocol === 'https:'\n return { href: parsed.href, newTab: web && parsed.origin !== window.location.origin }\n}\n\n// The URL of the document load. Unlike `location.href`, it stays the same after `pushState`.\nconst loadedURL = (): string | null => {\n if (!hasDOM()) return null\n const [entry] = performance.getEntriesByType('navigation')\n return entry?.name || window.location.href\n}\n\n/** For tests: `location.assign` can't be replaced, so the tests replace this. */\nexport const browserNavigation: { assign: (href: string) => void } = {\n assign: (href) => window.location.assign(href),\n}\n\n/**\n * Opens URLs and reports the URL that the page loaded with. A URL of this site opens in this tab,\n * a URL of another site in a new tab, and `mailto:`, `tel:`, and other schemes go to the system.\n * The browser never fires `url`: back, forward, and links belong to the router.\n */\nexport const Linking: {\n addEventListener: <K extends LinkingEvent>(\n eventType: K,\n listener: (...args: LinkingEventDefinitions[K]) => unknown,\n ) => EventSubscription\n addListener: <K extends LinkingEvent>(\n eventType: K,\n listener: (...args: LinkingEventDefinitions[K]) => unknown,\n context?: unknown,\n ) => EventSubscription\n emit: <K extends LinkingEvent>(eventType: K, ...args: LinkingEventDefinitions[K]) => void\n removeAllListeners: <K extends LinkingEvent>(eventType?: K | null) => void\n listenerCount: <K extends LinkingEvent>(eventType: K) => number\n openURL: (url: string) => Promise<void>\n canOpenURL: (url: string) => Promise<boolean>\n openSettings: () => Promise<void>\n getInitialURL: () => Promise<string | null>\n sendIntent: (\n action: string,\n extras?: Array<{ key: string; value: string | number | boolean }>,\n ) => Promise<void>\n} = {\n addEventListener: (eventType, listener) => addListener(eventType, listener),\n\n addListener,\n\n emit(eventType, ...args) {\n const set = registrations.get(eventType)\n if (set === undefined) return\n // A listener that removes itself or adds another doesn't change this emit, as on native.\n for (const { listener, context } of Array.from(set)) {\n Reflect.apply(listener, context, args)\n }\n },\n\n removeAllListeners(eventType) {\n if (eventType === undefined || eventType === null) registrations.clear()\n else registrations.delete(eventType)\n },\n\n listenerCount: (eventType) => registrations.get(eventType)?.size ?? 0,\n\n openURL(url) {\n validate(url)\n const target = destination(url)\n if (target instanceof Error) return Promise.reject(target)\n if (!target.newTab) {\n browserNavigation.assign(target.href)\n return Promise.resolve()\n }\n const opened = window.open(target.href, '_blank')\n if (opened === null) {\n return Promise.reject(\n new Error(\n `Linking: the browser blocked the new tab for ${target.href}. Call openURL from a press handler.`,\n ),\n )\n }\n // The new page must not reach this one through window.opener.\n opened.opener = null\n return Promise.resolve()\n },\n\n canOpenURL(url) {\n validate(url)\n return Promise.resolve(!(destination(url) instanceof Error))\n },\n\n openSettings: () =>\n Promise.reject(new Error('Linking.openSettings: the web has no settings page for an app.')),\n\n getInitialURL: () => Promise.resolve(loadedURL()),\n\n // The rejection of iOS.\n sendIntent: () => Promise.reject(new Error('Unsupported')),\n}\n"],"mappings":";;AAWA,MAAM,gCAAgB,IAAI,IAA+B;AAEzD,MAAM,eACJ,WACA,UACA,YACsB;CACtB,IAAI,MAAM,cAAc,IAAI,SAAS;CACrC,IAAI,QAAQ,KAAA,GAAW;EACrB,sBAAM,IAAI,IAAI;EACd,cAAc,IAAI,WAAW,GAAG;CAClC;CACA,MAAM,eAA6B;EAAE;EAAU;CAAQ;CACvD,MAAM,QAAQ;CACd,MAAM,IAAI,YAAY;CACtB,OAAO,EAAE,cAAc,MAAM,OAAO,YAAY,EAAE;AACpD;AAEA,MAAM,YAAY,QAAuB;CACvC,IAAI,OAAO,QAAQ,UACjB,MAAM,IAAI,MAAM,yCAAyC,OAAO,GAAG,GAAG;CAExE,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,8BAA8B;AAChE;AAGA,MAAM,oCAAoB,IAAI,IAAI,CAAC,eAAe,OAAO,CAAC;AAI1D,MAAM,eAAe,QAAqC;CACxD,IAAI,CAAC,OAAO,GAAG,uBAAO,IAAI,MAAM,gDAAgD;CAChF,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,KAAK,OAAO,SAAS,IAAI;CAC5C,QAAQ;EACN,uBAAO,IAAI,MAAM,aAAa,IAAI,qBAAqB;CACzD;CACA,IAAI,kBAAkB,IAAI,OAAO,QAAQ,GACvC,uBAAO,IAAI,MAAM,8BAA8B,OAAO,SAAS,MAAM;CAEvE,MAAM,MAAM,OAAO,aAAa,WAAW,OAAO,aAAa;CAC/D,OAAO;EAAE,MAAM,OAAO;EAAM,QAAQ,OAAO,OAAO,WAAW,OAAO,SAAS;CAAO;AACtF;AAGA,MAAM,kBAAiC;CACrC,IAAI,CAA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Q,uBAAO,IAAI,MAAM,aAAa,CAAC;AAC3D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GestureResponderEvent } from "../../events/types.js";
|
|
2
|
+
import { PointerEvent } from "react";
|
|
3
|
+
export type PanResponderGestureState = {
|
|
4
|
+
stateID: number;
|
|
5
|
+
moveX: number;
|
|
6
|
+
moveY: number;
|
|
7
|
+
x0: number;
|
|
8
|
+
y0: number;
|
|
9
|
+
dx: number;
|
|
10
|
+
dy: number;
|
|
11
|
+
vx: number;
|
|
12
|
+
vy: number;
|
|
13
|
+
numberActiveTouches: number;
|
|
14
|
+
_accountsForMovesUpTo: number;
|
|
15
|
+
};
|
|
16
|
+
type Callback = (event: GestureResponderEvent, gestureState: PanResponderGestureState) => void;
|
|
17
|
+
type Predicate = (event: GestureResponderEvent, gestureState: PanResponderGestureState) => boolean;
|
|
18
|
+
export type PanResponderCallbacks = {
|
|
19
|
+
onStartShouldSetPanResponder?: Predicate | undefined;
|
|
20
|
+
onStartShouldSetPanResponderCapture?: Predicate | undefined;
|
|
21
|
+
onMoveShouldSetPanResponder?: Predicate | undefined;
|
|
22
|
+
onMoveShouldSetPanResponderCapture?: Predicate | undefined;
|
|
23
|
+
onPanResponderGrant?: Callback | undefined;
|
|
24
|
+
onPanResponderStart?: Callback | undefined;
|
|
25
|
+
onPanResponderMove?: Callback | undefined;
|
|
26
|
+
onPanResponderEnd?: Callback | undefined;
|
|
27
|
+
onPanResponderRelease?: Callback | undefined;
|
|
28
|
+
onPanResponderReject?: Callback | undefined;
|
|
29
|
+
onPanResponderTerminate?: Callback | undefined;
|
|
30
|
+
onPanResponderTerminationRequest?: Predicate | undefined;
|
|
31
|
+
onShouldBlockNativeResponder?: Predicate | undefined;
|
|
32
|
+
};
|
|
33
|
+
type Handler = (event: PointerEvent<HTMLElement>) => void;
|
|
34
|
+
export type GestureResponderHandlers = {
|
|
35
|
+
onPointerDownCapture: Handler;
|
|
36
|
+
onPointerDown: Handler;
|
|
37
|
+
onPointerMoveCapture: Handler;
|
|
38
|
+
onPointerMove: Handler;
|
|
39
|
+
onPointerUp: Handler;
|
|
40
|
+
onPointerCancel: Handler;
|
|
41
|
+
};
|
|
42
|
+
export type PanResponderInstance = {
|
|
43
|
+
panHandlers: GestureResponderHandlers;
|
|
44
|
+
getInteractionHandle: () => number | null;
|
|
45
|
+
};
|
|
46
|
+
export declare const PanResponder: {
|
|
47
|
+
create: (config: PanResponderCallbacks) => PanResponderInstance;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|