@rootnative/web 0.0.0-alpha.3 → 0.0.0-alpha.5

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 (241) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/apis/AccessibilityInfo/index.d.ts +30 -0
  3. package/dist/apis/AccessibilityInfo/index.js +84 -0
  4. package/dist/apis/AccessibilityInfo/index.js.map +1 -0
  5. package/dist/apis/Alert/index.d.ts +22 -0
  6. package/dist/apis/Alert/index.js +141 -0
  7. package/dist/apis/Alert/index.js.map +1 -0
  8. package/dist/apis/AppState/index.d.ts +21 -0
  9. package/dist/apis/AppState/index.js +86 -0
  10. package/dist/apis/AppState/index.js.map +1 -0
  11. package/dist/apis/Appearance/index.d.ts +14 -0
  12. package/dist/apis/Appearance/index.js +39 -0
  13. package/dist/apis/Appearance/index.js.map +1 -0
  14. package/dist/apis/BackHandler/index.d.ts +10 -0
  15. package/dist/apis/BackHandler/index.js +16 -0
  16. package/dist/apis/BackHandler/index.js.map +1 -0
  17. package/dist/apis/Clipboard/index.d.ts +9 -0
  18. package/dist/apis/Clipboard/index.js +45 -0
  19. package/dist/apis/Clipboard/index.js.map +1 -0
  20. package/dist/apis/Dimensions/index.d.ts +19 -0
  21. package/dist/apis/Dimensions/index.js +66 -0
  22. package/dist/apis/Dimensions/index.js.map +1 -0
  23. package/dist/apis/I18nManager/index.d.ts +14 -0
  24. package/dist/apis/I18nManager/index.js +33 -0
  25. package/dist/apis/I18nManager/index.js.map +1 -0
  26. package/dist/apis/Keyboard/index.d.ts +36 -0
  27. package/dist/apis/Keyboard/index.js +149 -0
  28. package/dist/apis/Keyboard/index.js.map +1 -0
  29. package/dist/apis/Linking/index.d.ts +29 -0
  30. package/dist/apis/Linking/index.js +86 -0
  31. package/dist/apis/Linking/index.js.map +1 -0
  32. package/dist/apis/PanResponder/index.d.ts +50 -0
  33. package/dist/apis/PanResponder/index.js +239 -0
  34. package/dist/apis/PanResponder/index.js.map +1 -0
  35. package/dist/apis/PixelRatio/index.d.ts +8 -0
  36. package/dist/apis/PixelRatio/index.js +15 -0
  37. package/dist/apis/PixelRatio/index.js.map +1 -0
  38. package/dist/apis/Platform/index.d.ts +4 -0
  39. package/dist/apis/Platform/index.js +28 -0
  40. package/dist/apis/Platform/index.js.map +1 -0
  41. package/dist/apis/Platform/types.d.ts +19 -0
  42. package/dist/apis/Share/index.d.ts +30 -0
  43. package/dist/apis/Share/index.js +34 -0
  44. package/dist/apis/Share/index.js.map +1 -0
  45. package/dist/apis/StyleSheet/index.d.ts +23 -0
  46. package/dist/apis/StyleSheet/index.js +29 -0
  47. package/dist/apis/StyleSheet/index.js.map +1 -0
  48. package/dist/apis/StyleSheet/types.d.ts +328 -0
  49. package/dist/apis/Vibration/index.d.ts +9 -0
  50. package/dist/apis/Vibration/index.js +40 -0
  51. package/dist/apis/Vibration/index.js.map +1 -0
  52. package/dist/apis/processColor/index.d.ts +3 -0
  53. package/dist/apis/processColor/index.js +12 -0
  54. package/dist/apis/processColor/index.js.map +1 -0
  55. package/dist/apis/useColorScheme/index.d.ts +3 -0
  56. package/dist/apis/useColorScheme/index.js +13 -0
  57. package/dist/apis/useColorScheme/index.js.map +1 -0
  58. package/dist/apis/useWindowDimensions/index.d.ts +3 -0
  59. package/dist/apis/useWindowDimensions/index.js +19 -0
  60. package/dist/apis/useWindowDimensions/index.js.map +1 -0
  61. package/dist/bundler/index.js +30 -0
  62. package/dist/bundler/index.js.map +1 -0
  63. package/dist/bundler/inlinePlatformOS.js +121 -0
  64. package/dist/bundler/inlinePlatformOS.js.map +1 -0
  65. package/dist/bundler/worklets.js +61 -0
  66. package/dist/bundler/worklets.js.map +1 -0
  67. package/dist/compat/TurboModuleRegistry/index.d.ts +16 -0
  68. package/dist/compat/TurboModuleRegistry/index.js +14 -0
  69. package/dist/compat/TurboModuleRegistry/index.js.map +1 -0
  70. package/dist/compat/createElement/index.d.ts +9 -0
  71. package/dist/compat/createElement/index.js +40 -0
  72. package/dist/compat/createElement/index.js.map +1 -0
  73. package/dist/compat/findNodeHandle/index.d.ts +7 -0
  74. package/dist/compat/findNodeHandle/index.js +19 -0
  75. package/dist/compat/findNodeHandle/index.js.map +1 -0
  76. package/dist/components/ActivityIndicator/index.d.ts +5 -0
  77. package/dist/components/ActivityIndicator/index.js +74 -0
  78. package/dist/components/ActivityIndicator/index.js.map +1 -0
  79. package/dist/components/ActivityIndicator/types.d.ts +8 -0
  80. package/dist/components/Button/index.d.ts +5 -0
  81. package/dist/components/Button/index.js +48 -0
  82. package/dist/components/Button/index.js.map +1 -0
  83. package/dist/components/Button/types.d.ts +31 -0
  84. package/dist/components/FlatList/index.d.ts +5 -0
  85. package/dist/components/FlatList/index.js +433 -0
  86. package/dist/components/FlatList/index.js.map +1 -0
  87. package/dist/components/FlatList/types.d.ts +138 -0
  88. package/dist/components/FlatList/viewability.js +86 -0
  89. package/dist/components/FlatList/viewability.js.map +1 -0
  90. package/dist/components/Image/index.d.ts +7 -0
  91. package/dist/components/Image/index.js +301 -0
  92. package/dist/components/Image/index.js.map +1 -0
  93. package/dist/components/Image/source.js +97 -0
  94. package/dist/components/Image/source.js.map +1 -0
  95. package/dist/components/Image/types.d.ts +96 -0
  96. package/dist/components/KeyboardAvoidingView/index.d.ts +10 -0
  97. package/dist/components/KeyboardAvoidingView/index.js +118 -0
  98. package/dist/components/KeyboardAvoidingView/index.js.map +1 -0
  99. package/dist/components/KeyboardAvoidingView/types.d.ts +14 -0
  100. package/dist/components/Modal/index.d.ts +9 -0
  101. package/dist/components/Modal/index.js +271 -0
  102. package/dist/components/Modal/index.js.map +1 -0
  103. package/dist/components/Modal/types.d.ts +29 -0
  104. package/dist/components/Pressable/index.d.ts +5 -0
  105. package/dist/components/Pressable/index.js +106 -0
  106. package/dist/components/Pressable/index.js.map +1 -0
  107. package/dist/components/Pressable/types.d.ts +44 -0
  108. package/dist/components/RefreshControl/index.d.ts +5 -0
  109. package/dist/components/RefreshControl/index.js +176 -0
  110. package/dist/components/RefreshControl/index.js.map +1 -0
  111. package/dist/components/RefreshControl/pull.js +16 -0
  112. package/dist/components/RefreshControl/pull.js.map +1 -0
  113. package/dist/components/RefreshControl/types.d.ts +14 -0
  114. package/dist/components/ScrollView/index.d.ts +5 -0
  115. package/dist/components/ScrollView/index.js +318 -0
  116. package/dist/components/ScrollView/index.js.map +1 -0
  117. package/dist/components/ScrollView/snap.js +38 -0
  118. package/dist/components/ScrollView/snap.js.map +1 -0
  119. package/dist/components/ScrollView/types.d.ts +115 -0
  120. package/dist/components/StatusBar/index.d.ts +26 -0
  121. package/dist/components/StatusBar/index.js +113 -0
  122. package/dist/components/StatusBar/index.js.map +1 -0
  123. package/dist/components/Switch/index.d.ts +5 -0
  124. package/dist/components/Switch/index.js +89 -0
  125. package/dist/components/Switch/index.js.map +1 -0
  126. package/dist/components/Switch/types.d.ts +25 -0
  127. package/dist/components/Text/TextAncestorContext.d.ts +3 -0
  128. package/dist/components/Text/TextAncestorContext.js +6 -0
  129. package/dist/components/Text/TextAncestorContext.js.map +1 -0
  130. package/dist/components/Text/index.d.ts +6 -0
  131. package/dist/components/Text/index.js +133 -0
  132. package/dist/components/Text/index.js.map +1 -0
  133. package/dist/components/Text/types.d.ts +38 -0
  134. package/dist/components/TextInput/autocomplete.js +102 -0
  135. package/dist/components/TextInput/autocomplete.js.map +1 -0
  136. package/dist/components/TextInput/index.d.ts +8 -0
  137. package/dist/components/TextInput/index.js +290 -0
  138. package/dist/components/TextInput/index.js.map +1 -0
  139. package/dist/components/TextInput/types.d.ts +130 -0
  140. package/dist/components/TouchableHighlight/index.d.ts +5 -0
  141. package/dist/components/TouchableHighlight/index.js +109 -0
  142. package/dist/components/TouchableHighlight/index.js.map +1 -0
  143. package/dist/components/TouchableHighlight/types.d.ts +15 -0
  144. package/dist/components/TouchableNativeFeedback/index.d.ts +11 -0
  145. package/dist/components/TouchableNativeFeedback/index.js +29 -0
  146. package/dist/components/TouchableNativeFeedback/index.js.map +1 -0
  147. package/dist/components/TouchableNativeFeedback/types.d.ts +19 -0
  148. package/dist/components/TouchableOpacity/index.d.ts +5 -0
  149. package/dist/components/TouchableOpacity/index.js +122 -0
  150. package/dist/components/TouchableOpacity/index.js.map +1 -0
  151. package/dist/components/TouchableOpacity/types.d.ts +11 -0
  152. package/dist/components/TouchableWithoutFeedback/index.d.ts +5 -0
  153. package/dist/components/TouchableWithoutFeedback/index.js +70 -0
  154. package/dist/components/TouchableWithoutFeedback/index.js.map +1 -0
  155. package/dist/components/TouchableWithoutFeedback/types.d.ts +40 -0
  156. package/dist/components/View/index.d.ts +5 -0
  157. package/dist/components/View/index.js +50 -0
  158. package/dist/components/View/index.js.map +1 -0
  159. package/dist/components/View/types.d.ts +98 -0
  160. package/dist/dom/Head.d.ts +21 -0
  161. package/dist/dom/Head.js +53 -0
  162. package/dist/dom/Head.js.map +1 -0
  163. package/dist/dom/index.d.ts +2 -22
  164. package/dist/dom/index.js +1 -53
  165. package/dist/events/press/Pressability.d.ts +2 -0
  166. package/dist/events/press/Pressability.js +366 -0
  167. package/dist/events/press/Pressability.js.map +1 -0
  168. package/dist/events/press/cursorStyle.js +5 -0
  169. package/dist/events/press/cursorStyle.js.map +1 -0
  170. package/dist/events/press/index.d.ts +4 -0
  171. package/dist/events/press/mergeHandlers.js +30 -0
  172. package/dist/events/press/mergeHandlers.js.map +1 -0
  173. package/dist/events/press/types.d.ts +48 -0
  174. package/dist/events/press/usePressability.d.ts +4 -0
  175. package/dist/events/press/usePressability.js +18 -0
  176. package/dist/events/press/usePressability.js.map +1 -0
  177. package/dist/events/responderEvent.js +50 -0
  178. package/dist/events/responderEvent.js.map +1 -0
  179. package/dist/events/types.d.ts +33 -0
  180. package/dist/index.d.ts +66 -1597
  181. package/dist/index.js +42 -4864
  182. package/dist/reactNativeVersion.d.ts +7 -0
  183. package/dist/reactNativeVersion.js +10 -0
  184. package/dist/reactNativeVersion.js.map +1 -0
  185. package/dist/render/domProps.js +66 -0
  186. package/dist/render/domProps.js.map +1 -0
  187. package/dist/render/hitSlop.js +21 -0
  188. package/dist/render/hitSlop.js.map +1 -0
  189. package/dist/render/hostMethods.js +44 -0
  190. package/dist/render/hostMethods.js.map +1 -0
  191. package/dist/render/resolveTag.js +64 -0
  192. package/dist/render/resolveTag.js.map +1 -0
  193. package/dist/render/useElementLayout.js +25 -0
  194. package/dist/render/useElementLayout.js.map +1 -0
  195. package/dist/server/index.d.ts +2 -27
  196. package/dist/server/index.js +2 -2
  197. package/dist/{StyleRegistryContext-ROsMlY4O.js → style/StyleRegistryContext.js} +3 -3
  198. package/dist/style/StyleRegistryContext.js.map +1 -0
  199. package/dist/style/color.js +16 -0
  200. package/dist/style/color.js.map +1 -0
  201. package/dist/style/compile.js +102 -0
  202. package/dist/style/compile.js.map +1 -0
  203. package/dist/style/direction.js +33 -0
  204. package/dist/style/direction.js.map +1 -0
  205. package/dist/style/index.d.ts +1 -1
  206. package/dist/style/index.js +5 -2
  207. package/dist/style/index.js.map +1 -1
  208. package/dist/style/registry.d.ts +28 -0
  209. package/dist/{registry-Aa_Od5m0.js → style/registry.js} +6 -3
  210. package/dist/style/registry.js.map +1 -0
  211. package/dist/style/resolveStyle.js +181 -0
  212. package/dist/style/resolveStyle.js.map +1 -0
  213. package/dist/style/shadow.js +87 -0
  214. package/dist/style/shadow.js.map +1 -0
  215. package/dist/style/splitLayoutProps.js +52 -0
  216. package/dist/style/splitLayoutProps.js.map +1 -0
  217. package/dist/style/transform.js +35 -0
  218. package/dist/style/transform.js.map +1 -0
  219. package/dist/style/types.d.ts +4 -0
  220. package/dist/style/units.js +21 -0
  221. package/dist/style/units.js.map +1 -0
  222. package/dist/style/webStyle.js +9 -0
  223. package/dist/style/webStyle.js.map +1 -0
  224. package/dist/{env-DK5Mt9yX.js → utils/env.js} +2 -2
  225. package/dist/utils/env.js.map +1 -0
  226. package/dist/utils/scrollLock.js +28 -0
  227. package/dist/utils/scrollLock.js.map +1 -0
  228. package/dist/utils/warn.js +11 -0
  229. package/dist/utils/warn.js.map +1 -0
  230. package/dist/vite/index.js +4 -202
  231. package/dist/vite/index.js.map +1 -1
  232. package/llms.txt +20 -0
  233. package/package.json +4 -3
  234. package/dist/StyleRegistryContext-ROsMlY4O.js.map +0 -1
  235. package/dist/compile-CVUjQrR9.js +0 -400
  236. package/dist/compile-CVUjQrR9.js.map +0 -1
  237. package/dist/dom/index.js.map +0 -1
  238. package/dist/env-DK5Mt9yX.js.map +0 -1
  239. package/dist/index.js.map +0 -1
  240. package/dist/registry-Aa_Od5m0.js.map +0 -1
  241. package/dist/types-BxTWbdj9.d.ts +0 -5
package/dist/index.js CHANGED
@@ -1,4865 +1,43 @@
1
- import { i as matchesMedia, n as isProductionEnv, r as isTestEnv, t as hasDOM } from "./env-DK5Mt9yX.js";
2
- import { a as getStyleRegistry } from "./registry-Aa_Od5m0.js";
3
- import { a as pointerEventsStyle, d as setLeftAndRightSwap, f as toCSSColor, i as joinClassNames, n as compileStyle, o as resolveStyle, r as flattenStyle, s as systemFontStack, t as compileReset, u as getLeftAndRightSwap } from "./compile-CVUjQrR9.js";
4
- import { n as useStyleRegistry } from "./StyleRegistryContext-ROsMlY4O.js";
5
- import normalizeColor from "@react-native/normalize-colors";
6
- import { Children, Fragment, cloneElement, createContext, createElement, isValidElement, memo, useCallback, useContext, useEffect, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
- import { jsx, jsxs } from "react/jsx-runtime";
8
- import { createPortal } from "react-dom";
9
- // src/apis/AccessibilityInfo/index.ts
10
- const mediaQueryOf = {
11
- reduceMotionChanged: "(prefers-reduced-motion: reduce)",
12
- reduceTransparencyChanged: "(prefers-reduced-transparency: reduce)",
13
- invertColorsChanged: "(inverted-colors: inverted)",
14
- darkerSystemColorsChanged: "(prefers-contrast: more)",
15
- highTextContrastChanged: "(prefers-contrast: more)"
16
- };
17
- const resolve = (value) => Promise.resolve(value);
18
- let liveRegion = null;
19
- const getLiveRegion = () => {
20
- if (!hasDOM()) return null;
21
- if (liveRegion !== null && liveRegion.isConnected) return liveRegion;
22
- const element = document.createElement("div");
23
- element.setAttribute("aria-live", "polite");
24
- element.setAttribute("aria-atomic", "true");
25
- element.setAttribute("data-rn-announcer", "");
26
- Object.assign(element.style, {
27
- position: "absolute",
28
- width: "1px",
29
- height: "1px",
30
- margin: "-1px",
31
- padding: "0",
32
- overflow: "hidden",
33
- clip: "rect(0 0 0 0)",
34
- whiteSpace: "nowrap",
35
- border: "0"
36
- });
37
- document.body.appendChild(element);
38
- liveRegion = element;
39
- return element;
40
- };
41
- const announcementListeners = /* @__PURE__ */ new Set();
42
- const announce = (announcement, queue) => {
43
- const region = getLiveRegion();
44
- if (region === null) return;
45
- region.setAttribute("aria-live", queue ? "polite" : "assertive");
46
- region.textContent = "";
47
- requestAnimationFrame(() => {
48
- region.textContent = announcement;
49
- for (const listener of announcementListeners) listener({
50
- announcement,
51
- success: true
52
- });
53
- });
54
- };
55
- const AccessibilityInfo = {
56
- isScreenReaderEnabled: () => resolve(false),
57
- isAccessibilityServiceEnabled: () => resolve(false),
58
- isBoldTextEnabled: () => resolve(false),
59
- isGrayscaleEnabled: () => resolve(false),
60
- isInvertColorsEnabled: () => resolve(matchesMedia("(inverted-colors: inverted)")),
61
- isReduceMotionEnabled: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
62
- isReduceTransparencyEnabled: () => resolve(matchesMedia("(prefers-reduced-transparency: reduce)")),
63
- isHighTextContrastEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
64
- isDarkerSystemColorsEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
65
- prefersCrossFadeTransitions: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
66
- getRecommendedTimeoutMillis: (originalTimeout) => resolve(originalTimeout),
67
- addEventListener: (eventName, handler) => {
68
- if (eventName === "announcementFinished") {
69
- const listener = handler;
70
- announcementListeners.add(listener);
71
- return { remove: () => announcementListeners.delete(listener) };
72
- }
73
- const query = mediaQueryOf[eventName];
74
- if (query === void 0 || !hasDOM() || typeof window.matchMedia !== "function") return { remove: () => {} };
75
- const list = window.matchMedia(query);
76
- const listener = () => handler(list.matches);
77
- list.addEventListener("change", listener);
78
- return { remove: () => list.removeEventListener("change", listener) };
79
- },
80
- announceForAccessibility: (announcement) => announce(announcement, true),
81
- announceForAccessibilityWithOptions: (announcement, options) => announce(announcement, options.queue !== false),
82
- setAccessibilityFocus: (target) => {
83
- if (target instanceof HTMLElement) target.focus();
84
- },
85
- sendAccessibilityEvent: (target, eventType) => {
86
- if (eventType === "focus" && target instanceof HTMLElement) target.focus();
87
- }
88
- };
89
- // src/utils/scrollLock.ts
90
- let locks = 0;
91
- let pageOverflow = "";
92
- let pageX = 0;
93
- let pageY = 0;
94
- const keepPlace = () => {
95
- const viewport = window.visualViewport;
96
- if (viewport !== null && viewport.scale === 1 && viewport.offsetTop > 0) window.scrollTo(pageX, pageY);
97
- };
98
- const lockScroll = () => {
99
- const root = document.documentElement;
100
- if (locks++ === 0) {
101
- pageOverflow = root.style.overflow;
102
- pageX = window.scrollX;
103
- pageY = window.scrollY;
104
- root.style.overflow = "hidden";
105
- window.visualViewport?.addEventListener("scroll", keepPlace);
106
- }
107
- };
108
- const unlockScroll = () => {
109
- if (--locks === 0) {
110
- document.documentElement.style.overflow = pageOverflow;
111
- window.visualViewport?.removeEventListener("scroll", keepPlace);
112
- }
113
- };
114
- // src/utils/warn.ts
115
- const warned = /* @__PURE__ */ new Set();
116
- const warnOnce = (key, message) => {
117
- if (isProductionEnv() || warned.has(key)) return;
118
- warned.add(key);
119
- console.warn(`[@rootnative/web] ${message}`);
120
- };
121
- // src/apis/Appearance/index.ts
122
- const DARK_QUERY = "(prefers-color-scheme: dark)";
123
- let override = null;
124
- let last$1 = null;
125
- let mediaList = null;
126
- const listeners$1 = /* @__PURE__ */ new Set();
127
- const system = () => matchesMedia(DARK_QUERY) ? "dark" : "light";
128
- const current$3 = () => override ?? system();
129
- const notify$1 = () => {
130
- const next = current$3();
131
- if (next === last$1) return;
132
- last$1 = next;
133
- for (const listener of listeners$1) listener({ colorScheme: next });
134
- };
135
- const listen$2 = () => {
136
- if (mediaList !== null || !hasDOM() || typeof window.matchMedia !== "function") return;
137
- mediaList = window.matchMedia(DARK_QUERY);
138
- mediaList.addEventListener("change", notify$1);
139
- };
140
- const Appearance = {
141
- getColorScheme() {
142
- return current$3();
143
- },
144
- setColorScheme(scheme) {
145
- override = scheme === "light" || scheme === "dark" ? scheme : null;
146
- if (hasDOM()) document.documentElement.style.colorScheme = override ?? "";
147
- notify$1();
148
- },
149
- addChangeListener(listener) {
150
- if (listeners$1.size === 0) last$1 = current$3();
151
- listeners$1.add(listener);
152
- listen$2();
153
- return { remove: () => listeners$1.delete(listener) };
154
- }
155
- };
156
- // src/apis/Alert/index.ts
157
- const ALERT = "rn-alert";
158
- const RULES$3 = [
159
- `.${ALERT}{position:fixed;inset:auto;top:50%;left:50%;z-index:2147483647;box-sizing:border-box;min-width:min(280px,calc(100% - 48px));max-width:min(560px,calc(100% - 48px));max-height:calc(100% - 48px);margin:0;padding:24px 24px 8px;overflow:auto;border:0;border-radius:2px;background:#fff;color:rgba(0,0,0,.87);font-family:${systemFontStack};box-shadow:0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14),0 9px 46px 8px rgba(0,0,0,.12);transform:translate(-50%,-50%)}`,
160
- `.${ALERT}:not([open]){display:none}`,
161
- `.${ALERT}:focus{outline:none}`,
162
- `.${ALERT}-title{margin:0;font-size:20px;font-weight:500;line-height:1.3;overflow-wrap:break-word}`,
163
- `.${ALERT}-message{margin:0;font-size:16px;line-height:1.5;color:rgba(0,0,0,.6);white-space:pre-wrap;overflow-wrap:break-word}`,
164
- `.${ALERT}-title+.${ALERT}-message{margin-top:16px}`,
165
- `.${ALERT}-buttons{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px;margin:24px -16px 0}`,
166
- `.${ALERT}-buttons[data-neutral]>:first-child{margin-inline-end:auto}`,
167
- `.${ALERT}-button{min-width:64px;min-height:36px;padding:0 8px;border:0;border-radius:2px;background:transparent;color:#009688;font:inherit;font-size:14px;font-weight:500;cursor:pointer}`,
168
- `.${ALERT}-button:hover{background:rgba(0,150,136,.08)}`,
169
- `.${ALERT}-button[data-style=destructive]{color:#d32f2f}`,
170
- `.${ALERT}[data-scheme=dark]{background:#424242;color:#fff}`,
171
- `.${ALERT}[data-scheme=dark] .${ALERT}-message{color:rgba(255,255,255,.7)}`,
172
- `.${ALERT}[data-scheme=dark] .${ALERT}-button{color:#80cbc4}`,
173
- `.${ALERT}[data-scheme=dark] .${ALERT}-button[data-style=destructive]{color:#ef9a9a}`,
174
- `@supports selector(:focus-visible){.${ALERT}-button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}}`,
175
- `@supports selector(::backdrop){.${ALERT}::backdrop{background:rgba(0,0,0,.6)}}`
176
- ];
177
- const openAlerts = /* @__PURE__ */ new Set();
178
- let nextId = 0;
179
- const lastIndexOf = (list, test) => {
180
- for (let index = list.length - 1; index >= 0; index--) {
181
- const button = list[index];
182
- if (button !== void 0 && test(button)) return index;
183
- }
184
- return -1;
185
- };
186
- const isOutside = (event, element) => {
187
- const box = element.getBoundingClientRect();
188
- return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
189
- };
190
- const show = (title, message, buttons, options) => {
191
- if (!hasDOM()) return;
192
- getStyleRegistry().staticClass(ALERT, RULES$3);
193
- const id = `${ALERT}-${++nextId}`;
194
- const dialog = document.createElement("dialog");
195
- dialog.className = ALERT;
196
- dialog.setAttribute("role", "alertdialog");
197
- const style = options?.userInterfaceStyle;
198
- dialog.dataset["scheme"] = style === "light" || style === "dark" ? style : Appearance.getColorScheme() ?? "light";
199
- if (title) {
200
- const heading = document.createElement("div");
201
- heading.className = `${ALERT}-title`;
202
- heading.id = `${id}-title`;
203
- heading.textContent = title;
204
- dialog.append(heading);
205
- dialog.setAttribute("aria-labelledby", heading.id);
206
- }
207
- if (message) {
208
- const body = document.createElement("div");
209
- body.className = `${ALERT}-message`;
210
- body.id = `${id}-message`;
211
- body.textContent = message;
212
- dialog.append(body);
213
- dialog.setAttribute("aria-describedby", body.id);
214
- }
215
- const list = buttons === void 0 || buttons.length === 0 ? [{ text: "OK" }] : buttons;
216
- const modal = typeof dialog.showModal === "function";
217
- const focused = document.activeElement;
218
- let closed = false;
219
- const close = () => {
220
- if (closed) return;
221
- closed = true;
222
- openAlerts.delete(entry);
223
- if (modal) dialog.close();
224
- else if (focused instanceof HTMLElement && focused.isConnected) focused.focus();
225
- dialog.remove();
226
- unlockScroll();
227
- };
228
- const entry = { close };
229
- const press = (button) => {
230
- close();
231
- button.onPress?.();
232
- };
233
- const dismiss = () => {
234
- close();
235
- options?.onDismiss?.();
236
- };
237
- const cancel = () => {
238
- const cancelButton = list[lastIndexOf(list, (button) => button.style === "cancel")];
239
- if (cancelButton !== void 0) press(cancelButton);
240
- else if (options?.cancelable === true) dismiss();
241
- };
242
- const row = document.createElement("div");
243
- row.className = `${ALERT}-buttons`;
244
- if (list.length >= 3) row.dataset["neutral"] = "";
245
- const elements = list.map((button, index) => {
246
- const element = document.createElement("button");
247
- element.type = "button";
248
- element.className = `${ALERT}-button`;
249
- element.textContent = button.text || (index === list.length - 1 ? "OK" : "");
250
- if (button.style === "destructive") element.dataset["style"] = "destructive";
251
- element.addEventListener("click", () => press(button));
252
- row.append(element);
253
- return element;
254
- });
255
- dialog.append(row);
256
- dialog.addEventListener("cancel", (event) => {
257
- event.preventDefault();
258
- cancel();
259
- });
260
- dialog.addEventListener("close", () => {
261
- if (!closed) dialog.showModal();
262
- });
263
- dialog.addEventListener("click", (event) => {
264
- if (event.target === dialog && isOutside(event, dialog) && options?.cancelable === true) dismiss();
265
- });
266
- if (!modal) dialog.addEventListener("keydown", (event) => {
267
- if (event.key === "Escape") cancel();
268
- });
269
- document.body.append(dialog);
270
- if (modal) dialog.showModal();
271
- else dialog.setAttribute("open", "");
272
- lockScroll();
273
- openAlerts.add(entry);
274
- const preferred = list.findIndex((button) => button.isPreferred === true);
275
- const target = preferred >= 0 ? preferred : lastIndexOf(list, (button) => button.style === "cancel");
276
- elements[target >= 0 ? target : 0]?.focus();
277
- };
278
- /**
279
- * React Native's `Alert` on a `<dialog role="alertdialog">` with the look of Android's
280
- * AlertDialog. It isn't part of the React tree, so it works from any handler.
281
- */
282
- const Alert = {
283
- alert: (title, message, buttons, options) => show(title, message, buttons, options),
284
- prompt: () => {
285
- warnOnce("alert-prompt", "Alert.prompt does nothing on the web yet, as on Android.");
286
- }
287
- };
288
- // src/apis/AppState/index.ts
289
- const handlers$2 = {
290
- change: /* @__PURE__ */ new Set(),
291
- memoryWarning: /* @__PURE__ */ new Set(),
292
- blur: /* @__PURE__ */ new Set(),
293
- focus: /* @__PURE__ */ new Set()
294
- };
295
- let pageHidden = false;
296
- let last = null;
297
- let visible = true;
298
- let caughtUp = false;
299
- let lastFocusEvent = null;
300
- let listening$2 = false;
301
- const read$2 = () => {
302
- if (!hasDOM()) return "active";
303
- return pageHidden || document.visibilityState !== "visible" ? "background" : "active";
304
- };
305
- const emit$1 = (next) => {
306
- if (next === last) return;
307
- last = next;
308
- for (const handler of handlers$2.change) handler(next);
309
- };
310
- const notify = () => emit$1(read$2());
311
- const onVisibilityChange = () => {
312
- const next = document.visibilityState === "visible";
313
- if (next !== visible) {
314
- caughtUp = false;
315
- visible = next;
316
- notify();
317
- return;
318
- }
319
- if (caughtUp) {
320
- caughtUp = false;
321
- return;
322
- }
323
- caughtUp = true;
324
- emit$1(next || pageHidden ? "background" : "active");
325
- notify();
326
- };
327
- const onPageHide = () => {
328
- pageHidden = true;
329
- notify();
330
- };
331
- const onPageShow = () => {
332
- pageHidden = false;
333
- notify();
334
- };
335
- const onWindowFocus = (event) => {
336
- if (event.target !== window || event.type === lastFocusEvent) return;
337
- lastFocusEvent = event.type;
338
- for (const handler of handlers$2[event.type === "focus" ? "focus" : "blur"]) handler();
339
- };
340
- const listen$1 = () => {
341
- if (listening$2 || !hasDOM()) return;
342
- listening$2 = true;
343
- last = read$2();
344
- visible = document.visibilityState === "visible";
345
- document.addEventListener("visibilitychange", onVisibilityChange);
346
- window.addEventListener("pagehide", onPageHide);
347
- window.addEventListener("pageshow", onPageShow);
348
- window.addEventListener("focus", onWindowFocus);
349
- window.addEventListener("blur", onWindowFocus);
350
- };
351
- /**
352
- * The app is `active` while its page is visible, and in the `background` while the page is
353
- * hidden or unloads. A focus change of the window fires `blur` and `focus`, as on Android, and
354
- * the state stays `active`.
355
- */
356
- const AppState = {
357
- get currentState() {
358
- return read$2();
359
- },
360
- isAvailable: true,
361
- addEventListener(type, handler) {
362
- const set = handlers$2[type];
363
- if (set === void 0) throw new Error(`Trying to subscribe to unknown event: ${String(type)}`);
364
- const entry = handler;
365
- set.add(entry);
366
- listen$1();
367
- return { remove: () => set.delete(entry) };
368
- }
369
- };
370
- // src/apis/BackHandler/index.ts
371
- const handlers$1 = /* @__PURE__ */ new Set();
372
- const BackHandler = {
373
- addEventListener: (eventName, handler) => {
374
- if (eventName !== "hardwareBackPress") throw new Error(`BackHandler: unknown event "${String(eventName)}"`);
375
- handlers$1.add(handler);
376
- return { remove: () => handlers$1.delete(handler) };
377
- },
378
- removeEventListener: (_eventName, handler) => {
379
- handlers$1.delete(handler);
380
- },
381
- exitApp: () => {}
382
- };
383
- // src/apis/Clipboard/index.ts
384
- const clipboardAPI = () => hasDOM() ? navigator.clipboard : void 0;
385
- const warnDeprecated = () => warnOnce("clipboard-deprecated", "Clipboard is deprecated in React Native, which will remove it in a future release.");
386
- const warnRefused = (reason) => warnOnce("clipboard-write", `Clipboard.setString: the browser refused the copy. ${reason}`);
387
- const copyWithTextarea = (content) => {
388
- const focused = document.activeElement;
389
- const textarea = document.createElement("textarea");
390
- textarea.value = content;
391
- textarea.setAttribute("readonly", "");
392
- textarea.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none";
393
- document.body.append(textarea);
394
- textarea.select();
395
- textarea.setSelectionRange(0, content.length);
396
- const copied = document.execCommand("copy");
397
- textarea.remove();
398
- if (focused instanceof HTMLElement) focused.focus({ preventScroll: true });
399
- if (!copied) warnRefused("Call setString from a press handler.");
400
- };
401
- /**
402
- * Reads and writes text on the clipboard with the async Clipboard API. Deprecated in React
403
- * Native, so the first call logs a warning.
404
- */
405
- const Clipboard = {
406
- getString() {
407
- warnDeprecated();
408
- const api = clipboardAPI();
409
- 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."));
410
- return api.readText();
411
- },
412
- setString(content) {
413
- warnDeprecated();
414
- if (!hasDOM()) return;
415
- const api = clipboardAPI();
416
- if (api === void 0 || typeof api.writeText !== "function") {
417
- copyWithTextarea(content);
418
- return;
419
- }
420
- api.writeText(content).catch((error) => warnRefused(String(error)));
421
- }
422
- };
423
- // src/apis/Dimensions/index.ts
424
- const serverSize = Object.freeze({
425
- width: 0,
426
- height: 0,
427
- scale: 1,
428
- fontScale: 1
429
- });
430
- const read$1 = () => {
431
- if (!hasDOM()) return {
432
- window: serverSize,
433
- screen: serverSize
434
- };
435
- const scale = window.devicePixelRatio || 1;
436
- const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
437
- const fontScale = Number.isFinite(rootFontSize) && rootFontSize > 0 ? rootFontSize / 16 : 1;
438
- return {
439
- window: {
440
- width: window.innerWidth,
441
- height: window.innerHeight,
442
- scale,
443
- fontScale
444
- },
445
- screen: {
446
- width: window.screen.width,
447
- height: window.screen.height,
448
- scale,
449
- fontScale
450
- }
451
- };
452
- };
453
- const sameSize = (a, b) => a.width === b.width && a.height === b.height && a.scale === b.scale && a.fontScale === b.fontScale;
454
- let current$2 = null;
455
- const handlers = /* @__PURE__ */ new Set();
456
- let listening$1 = false;
457
- const refresh = () => {
458
- const next = read$1();
459
- if (current$2 === null || !sameSize(current$2.window, next.window) || !sameSize(current$2.screen, next.screen)) current$2 = next;
460
- return current$2;
461
- };
462
- const update$1 = () => {
463
- const previous = current$2;
464
- const value = refresh();
465
- if (value === previous) return;
466
- for (const handler of handlers) handler(value);
467
- };
468
- const listen = () => {
469
- if (listening$1 || !hasDOM()) return;
470
- listening$1 = true;
471
- window.addEventListener("resize", update$1);
472
- };
473
- const Dimensions = {
474
- get(dimension) {
475
- return (current$2 === null || !listening$1 ? refresh() : current$2)[dimension];
476
- },
477
- addEventListener(type, handler) {
478
- if (type !== "change") throw new Error(`Dimensions: unknown event "${String(type)}"`);
479
- refresh();
480
- handlers.add(handler);
481
- listen();
482
- return { remove: () => handlers.delete(handler) };
483
- }
484
- };
485
- // src/apis/I18nManager/index.ts
486
- let allowed = true;
487
- let forced = false;
488
- const documentIsRTL = () => hasDOM() && getComputedStyle(document.documentElement).direction === "rtl";
489
- const isRTL = () => forced || allowed && documentIsRTL();
490
- const I18nManager = {
491
- get isRTL() {
492
- return isRTL();
493
- },
494
- get doLeftAndRightSwapInRTL() {
495
- return getLeftAndRightSwap();
496
- },
497
- getConstants: () => ({
498
- isRTL: isRTL(),
499
- doLeftAndRightSwapInRTL: getLeftAndRightSwap(),
500
- localeIdentifier: hasDOM() ? navigator.language : void 0
501
- }),
502
- allowRTL: (allow) => {
503
- allowed = allow;
504
- },
505
- forceRTL: (force) => {
506
- forced = force;
507
- if (hasDOM()) document.documentElement.dir = force ? "rtl" : "";
508
- },
509
- swapLeftAndRightInRTL: (swap) => {
510
- setLeftAndRightSwap(swap);
511
- }
512
- };
513
- // src/apis/Keyboard/index.ts
514
- /**
515
- * Internal. Where the keyboard module reads the two browser objects. A test replaces them,
516
- * because a headless browser shows no keyboard.
517
- */
518
- const keyboardSources = {
519
- visualViewport: () => window.visualViewport,
520
- virtualKeyboard: () => navigator.virtualKeyboard
521
- };
522
- const listeners = /* @__PURE__ */ new Map();
523
- let observed = null;
524
- let current$1 = null;
525
- let frame = null;
526
- const noTextInputTypes = /* @__PURE__ */ new Set([
527
- "button",
528
- "checkbox",
529
- "color",
530
- "file",
531
- "hidden",
532
- "image",
533
- "radio",
534
- "range",
535
- "reset",
536
- "submit"
537
- ]);
538
- const isEditable = (element) => {
539
- if (element instanceof HTMLTextAreaElement) return !element.readOnly && !element.disabled;
540
- if (element instanceof HTMLInputElement) return !element.readOnly && !element.disabled && !noTextInputTypes.has(element.type);
541
- return element instanceof HTMLElement && element.isContentEditable;
542
- };
543
- const read = () => {
544
- if (!hasDOM()) return null;
545
- const root = document.documentElement;
546
- const virtualKeyboard = keyboardSources.virtualKeyboard();
547
- if (virtualKeyboard?.overlaysContent === true) {
548
- const { x, y, width, height } = virtualKeyboard.boundingRect;
549
- return height > 0 ? {
550
- screenX: x,
551
- screenY: y,
552
- width,
553
- height
554
- } : null;
555
- }
556
- const viewport = keyboardSources.visualViewport();
557
- if (viewport === null || !isEditable(document.activeElement)) return null;
558
- const height = Math.round(root.clientHeight - viewport.height * viewport.scale);
559
- if (height <= 0) return null;
560
- return {
561
- screenX: 0,
562
- screenY: Math.min(root.clientHeight - height + Math.round(viewport.offsetTop), root.clientHeight),
563
- width: root.clientWidth,
564
- height
565
- };
566
- };
567
- const hiddenMetrics = () => ({
568
- screenX: 0,
569
- screenY: hasDOM() ? document.documentElement.clientHeight : 0,
570
- width: hasDOM() ? document.documentElement.clientWidth : 0,
571
- height: 0
572
- });
573
- const toEvent = (endCoordinates) => ({
574
- duration: 0,
575
- easing: "keyboard",
576
- endCoordinates
577
- });
578
- 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;
579
- const emit = (name, event) => {
580
- const set = listeners.get(name);
581
- if (set === void 0) return;
582
- for (const listener of set) listener(event);
583
- };
584
- const update = () => {
585
- frame = null;
586
- const next = read();
587
- if (sameMetrics(next, current$1)) return;
588
- current$1 = next;
589
- if (next === null) emit("keyboardDidHide", toEvent(hiddenMetrics()));
590
- else emit("keyboardDidShow", toEvent(next));
591
- };
592
- const schedule = () => {
593
- if (frame === null) frame = requestAnimationFrame(update);
594
- };
595
- const startObserving = () => {
596
- if (observed !== null || !hasDOM()) return;
597
- observed = {
598
- viewport: keyboardSources.visualViewport(),
599
- virtualKeyboard: keyboardSources.virtualKeyboard()
600
- };
601
- current$1 = read();
602
- observed.viewport?.addEventListener("resize", schedule);
603
- observed.viewport?.addEventListener("scroll", schedule);
604
- observed.virtualKeyboard?.addEventListener("geometrychange", schedule);
605
- window.addEventListener("resize", schedule);
606
- };
607
- const stopObserving = () => {
608
- if (observed === null) return;
609
- for (const set of listeners.values()) if (set.size > 0) return;
610
- observed.viewport?.removeEventListener("resize", schedule);
611
- observed.viewport?.removeEventListener("scroll", schedule);
612
- observed.virtualKeyboard?.removeEventListener("geometrychange", schedule);
613
- window.removeEventListener("resize", schedule);
614
- observed = null;
615
- if (frame !== null) cancelAnimationFrame(frame);
616
- frame = null;
617
- current$1 = null;
618
- };
619
- const state = () => observed === null ? read() : current$1;
620
- /**
621
- * The keyboard of a phone or a tablet, as on Android: `keyboardDidShow` fires when the keyboard
622
- * shows and when its height changes, and `keyboardDidHide` fires when it hides. The `Will` and
623
- * `ChangeFrame` events never fire.
624
- */
625
- const Keyboard = {
626
- addListener(eventType, listener) {
627
- let set = listeners.get(eventType);
628
- if (set === void 0) {
629
- set = /* @__PURE__ */ new Set();
630
- listeners.set(eventType, set);
631
- }
632
- const entry = (event) => listener(event);
633
- set.add(entry);
634
- startObserving();
635
- return { remove: () => {
636
- set.delete(entry);
637
- stopObserving();
638
- } };
639
- },
640
- removeAllListeners(eventType) {
641
- if (eventType === void 0 || eventType === null) listeners.clear();
642
- else listeners.delete(eventType);
643
- stopObserving();
644
- },
645
- dismiss() {
646
- if (!hasDOM()) return;
647
- const active = document.activeElement;
648
- if (isEditable(active)) active.blur();
649
- },
650
- isVisible() {
651
- return state() !== null;
652
- },
653
- metrics() {
654
- return state() ?? void 0;
655
- },
656
- scheduleLayoutAnimation() {}
657
- };
658
- // src/apis/Linking/index.ts
659
- const registrations = /* @__PURE__ */ new Map();
660
- const addListener = (eventType, listener, context) => {
661
- let set = registrations.get(eventType);
662
- if (set === void 0) {
663
- set = /* @__PURE__ */ new Set();
664
- registrations.set(eventType, set);
665
- }
666
- const registration = {
667
- listener,
668
- context
669
- };
670
- const owner = set;
671
- owner.add(registration);
672
- return { remove: () => owner.delete(registration) };
673
- };
674
- const validate = (url) => {
675
- if (typeof url !== "string") throw new Error(`Invalid URL: should be a string. Was: ${String(url)}`);
676
- if (url === "") throw new Error("Invalid URL: cannot be empty");
677
- };
678
- const REFUSED_PROTOCOLS = /* @__PURE__ */ new Set(["javascript:", "data:"]);
679
- const destination = (url) => {
680
- if (!hasDOM()) return /* @__PURE__ */ new Error("Linking: there is no browser to open a URL in.");
681
- let parsed;
682
- try {
683
- parsed = new URL(url, window.location.href);
684
- } catch {
685
- return /* @__PURE__ */ new Error(`Linking: "${url}" isn't a valid URL.`);
686
- }
687
- if (REFUSED_PROTOCOLS.has(parsed.protocol)) return /* @__PURE__ */ new Error(`Linking: refused to open a ${parsed.protocol} URL.`);
688
- const web = parsed.protocol === "http:" || parsed.protocol === "https:";
689
- return {
690
- href: parsed.href,
691
- newTab: web && parsed.origin !== window.location.origin
692
- };
693
- };
694
- const loadedURL = () => {
695
- if (!hasDOM()) return null;
696
- const [entry] = performance.getEntriesByType("navigation");
697
- return entry?.name || window.location.href;
698
- };
699
- /** For tests: `location.assign` can't be replaced, so the tests replace this. */
700
- const browserNavigation = { assign: (href) => window.location.assign(href) };
701
- /**
702
- * Opens URLs and reports the URL that the page loaded with. A URL of this site opens in this tab,
703
- * a URL of another site in a new tab, and `mailto:`, `tel:`, and other schemes go to the system.
704
- * The browser never fires `url`: back, forward, and links belong to the router.
705
- */
706
- const Linking = {
707
- addEventListener: (eventType, listener) => addListener(eventType, listener),
708
- addListener,
709
- emit(eventType, ...args) {
710
- const set = registrations.get(eventType);
711
- if (set === void 0) return;
712
- for (const { listener, context } of Array.from(set)) Reflect.apply(listener, context, args);
713
- },
714
- removeAllListeners(eventType) {
715
- if (eventType === void 0 || eventType === null) registrations.clear();
716
- else registrations.delete(eventType);
717
- },
718
- listenerCount: (eventType) => registrations.get(eventType)?.size ?? 0,
719
- openURL(url) {
720
- validate(url);
721
- const target = destination(url);
722
- if (target instanceof Error) return Promise.reject(target);
723
- if (!target.newTab) {
724
- browserNavigation.assign(target.href);
725
- return Promise.resolve();
726
- }
727
- const opened = window.open(target.href, "_blank");
728
- 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.`));
729
- opened.opener = null;
730
- return Promise.resolve();
731
- },
732
- canOpenURL(url) {
733
- validate(url);
734
- return Promise.resolve(!(destination(url) instanceof Error));
735
- },
736
- openSettings: () => Promise.reject(/* @__PURE__ */ new Error("Linking.openSettings: the web has no settings page for an app.")),
737
- getInitialURL: () => Promise.resolve(loadedURL()),
738
- sendIntent: () => Promise.reject(/* @__PURE__ */ new Error("Unsupported"))
739
- };
740
- // src/events/responderEvent.ts
741
- const hasPoint = (event) => event.clientX !== void 0 && !(event.type === "click" && event.detail === 0);
742
- const activeTypes = /* @__PURE__ */ new Set([
743
- "pointerdown",
744
- "pointermove",
745
- "keydown"
746
- ]);
747
- const define$1 = (target, fields) => {
748
- for (const key in fields) {
749
- if (key in target) continue;
750
- Object.defineProperty(target, key, {
751
- value: fields[key],
752
- configurable: true
753
- });
754
- }
755
- };
756
- const toGestureResponderEvent = (event, element) => {
757
- const native = event.nativeEvent;
758
- if (!("locationX" in native)) {
759
- const rect = element.getBoundingClientRect();
760
- const point = hasPoint(native);
761
- const clientX = point ? native.clientX ?? 0 : rect.left + rect.width / 2;
762
- const clientY = point ? native.clientY ?? 0 : rect.top + rect.height / 2;
763
- const touch = {
764
- changedTouches: [],
765
- force: native.pressure,
766
- identifier: native.pointerId ?? 0,
767
- locationX: clientX - rect.left,
768
- locationY: clientY - rect.top,
769
- pageX: clientX + window.scrollX,
770
- pageY: clientY + window.scrollY,
771
- target: native.target,
772
- timestamp: event.timeStamp,
773
- touches: []
774
- };
775
- define$1(native, {
776
- ...touch,
777
- changedTouches: [touch],
778
- touches: activeTypes.has(native.type) ? [touch] : []
779
- });
780
- }
781
- return event;
782
- };
783
- const toMouseEvent = (event) => {
784
- define$1(event.nativeEvent, { timestamp: event.timeStamp });
785
- return event;
786
- };
787
- // src/events/press/Pressability.ts
788
- const transitions = {
789
- NOT_RESPONDER: { RESPONDER_GRANT: "RESPONDER_INACTIVE_PRESS_IN" },
790
- RESPONDER_INACTIVE_PRESS_IN: {
791
- DELAY: "RESPONDER_ACTIVE_PRESS_IN",
792
- RESPONDER_RELEASE: "NOT_RESPONDER",
793
- RESPONDER_TERMINATED: "NOT_RESPONDER",
794
- ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
795
- LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
796
- },
797
- RESPONDER_INACTIVE_PRESS_OUT: {
798
- DELAY: "RESPONDER_ACTIVE_PRESS_OUT",
799
- RESPONDER_RELEASE: "NOT_RESPONDER",
800
- RESPONDER_TERMINATED: "NOT_RESPONDER",
801
- ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
802
- LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
803
- },
804
- RESPONDER_ACTIVE_PRESS_IN: {
805
- RESPONDER_RELEASE: "NOT_RESPONDER",
806
- RESPONDER_TERMINATED: "NOT_RESPONDER",
807
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
808
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT",
809
- LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
810
- },
811
- RESPONDER_ACTIVE_PRESS_OUT: {
812
- RESPONDER_RELEASE: "NOT_RESPONDER",
813
- RESPONDER_TERMINATED: "NOT_RESPONDER",
814
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
815
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT"
816
- },
817
- RESPONDER_ACTIVE_LONG_PRESS_IN: {
818
- RESPONDER_RELEASE: "NOT_RESPONDER",
819
- RESPONDER_TERMINATED: "NOT_RESPONDER",
820
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
821
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT",
822
- LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
823
- },
824
- RESPONDER_ACTIVE_LONG_PRESS_OUT: {
825
- RESPONDER_RELEASE: "NOT_RESPONDER",
826
- RESPONDER_TERMINATED: "NOT_RESPONDER",
827
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
828
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT"
829
- }
830
- };
831
- const isActive = (state) => state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
832
- const isActivation = (state) => state === "RESPONDER_ACTIVE_PRESS_OUT" || state === "RESPONDER_ACTIVE_PRESS_IN";
833
- const isPressIn = (state) => state === "RESPONDER_INACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
834
- const isTerminal = (signal) => signal === "RESPONDER_TERMINATED" || signal === "RESPONDER_RELEASE";
835
- const DEFAULT_LONG_PRESS_DELAY_MS = 500;
836
- const DEFAULT_MIN_PRESS_DURATION = 130;
837
- const DEFAULT_PRESS_RECT_OFFSETS = {
838
- bottom: 30,
839
- left: 20,
840
- right: 20,
841
- top: 20
842
- };
843
- let longPressDeactivationDistance = 10;
844
- const normalizeDelay = (delay, min = 0, fallback = 0) => Math.max(min, delay ?? fallback);
845
- const normalizeRect = (rect) => typeof rect === "number" ? {
846
- bottom: rect,
847
- left: rect,
848
- right: rect,
849
- top: rect
850
- } : rect;
851
- const claimed = /* @__PURE__ */ new WeakSet();
852
- const claimPress = (event) => {
853
- claimed.add(event);
854
- };
855
- const pressing = /* @__PURE__ */ new Map();
856
- const terminatePress = (event) => {
857
- pressing.get(event.pointerId)?.terminate(event, true);
858
- };
859
- const isPressClaimed = (event) => claimed.has(event);
860
- const isActivationKey = (key) => key === "Enter" || key === " ";
861
- const hasNativeActivation = (element) => {
862
- switch (element.tagName) {
863
- case "BUTTON":
864
- case "INPUT":
865
- case "SELECT":
866
- case "SUMMARY":
867
- case "TEXTAREA": return true;
868
- case "A":
869
- case "AREA": return element.hasAttribute("href");
870
- default: return element.isContentEditable;
871
- }
872
- };
873
- const nativeControl = "a[href],area[href],audio[controls],button,input,select,summary,textarea,video[controls],[contenteditable]:not([contenteditable=\"false\"])";
874
- const startsInNativeControl = (event) => {
875
- const { currentTarget, target } = event;
876
- if (!(target instanceof Element)) return false;
877
- const control = target.closest(nativeControl);
878
- return control !== null && control !== currentTarget && currentTarget.contains(control);
879
- };
880
- const TAP_CLICK_WINDOW_MS = 1e3;
881
- const stopRetargetedClick = (element, releasedAt) => {
882
- function end() {
883
- window.removeEventListener("click", onClick, true);
884
- window.removeEventListener("pointerdown", end, true);
885
- }
886
- function onClick(event) {
887
- if (event.detail === 0) return;
888
- end();
889
- if (event.timeStamp - releasedAt > TAP_CLICK_WINDOW_MS) return;
890
- if (event.target instanceof Node && element.contains(event.target)) return;
891
- event.preventDefault();
892
- event.stopImmediatePropagation();
893
- }
894
- window.addEventListener("click", onClick, true);
895
- window.addEventListener("pointerdown", end, true);
896
- };
897
- const clear = (timer) => {
898
- if (timer !== null) clearTimeout(timer);
899
- return null;
900
- };
901
- var Pressability = class {
902
- constructor(config) {
903
- this.state = "NOT_RESPONDER";
904
- this.element = null;
905
- this.region = null;
906
- this.pointerId = null;
907
- this.key = null;
908
- this.activatePosition = null;
909
- this.activateTime = null;
910
- this.hovered = false;
911
- this.pointerClickPending = false;
912
- this.cancelClick = false;
913
- this.hoverInTimer = null;
914
- this.hoverOutTimer = null;
915
- this.longPressTimer = null;
916
- this.pressDelayTimer = null;
917
- this.pressOutTimer = null;
918
- this.config = config;
919
- this.handlers = this.createEventHandlers();
920
- }
921
- configure(config) {
922
- this.config = config;
923
- }
924
- reset() {
925
- this.hoverInTimer = clear(this.hoverInTimer);
926
- this.hoverOutTimer = clear(this.hoverOutTimer);
927
- this.longPressTimer = clear(this.longPressTimer);
928
- this.pressDelayTimer = clear(this.pressDelayTimer);
929
- this.pressOutTimer = clear(this.pressOutTimer);
930
- if (this.pointerId !== null) pressing.delete(this.pointerId);
931
- this.config = Object.freeze({});
932
- }
933
- getEventHandlers() {
934
- return this.handlers;
935
- }
936
- terminate(event, clickFollows) {
937
- const element = this.element;
938
- if (event.pointerId !== this.pointerId || element === null) return;
939
- this.pointerId = null;
940
- pressing.delete(event.pointerId);
941
- this.pointerClickPending = clickFollows;
942
- this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
943
- }
944
- static setLongPressDeactivationDistance(distance) {
945
- longPressDeactivationDistance = distance;
946
- }
947
- createEventHandlers() {
948
- return {
949
- onPointerDown: (event) => {
950
- const native = event.nativeEvent;
951
- if (event.button !== 0 || claimed.has(native) || this.config.disabled === true) return;
952
- if (startsInNativeControl(event)) return;
953
- claimed.add(native);
954
- if (this.pointerId !== null || this.key !== null) return;
955
- const element = event.currentTarget;
956
- this.pointerId = event.pointerId;
957
- pressing.set(event.pointerId, this);
958
- this.pointerClickPending = true;
959
- try {
960
- element.setPointerCapture(event.pointerId);
961
- } catch {}
962
- this.grant(element, toGestureResponderEvent(event, element));
963
- },
964
- onPointerMove: (event) => {
965
- const element = this.element;
966
- if (event.pointerId !== this.pointerId || element === null) return;
967
- const pressEvent = toGestureResponderEvent(event, element);
968
- this.config.onPressMove?.(pressEvent);
969
- const region = this.region;
970
- if (region === null) return;
971
- const { pageX, pageY } = pressEvent.nativeEvent;
972
- const start = this.activatePosition;
973
- if (start !== null && Math.hypot(start.pageX - pageX, start.pageY - pageY) > longPressDeactivationDistance) this.longPressTimer = clear(this.longPressTimer);
974
- if (this.isWithinRegion(pageX, pageY, region)) this.receiveSignal("ENTER_PRESS_RECT", pressEvent);
975
- else {
976
- this.longPressTimer = clear(this.longPressTimer);
977
- this.receiveSignal("LEAVE_PRESS_RECT", pressEvent);
978
- }
979
- },
980
- onPointerUp: (event) => {
981
- const element = this.element;
982
- if (event.pointerId !== this.pointerId || element === null) return;
983
- this.pointerId = null;
984
- pressing.delete(event.pointerId);
985
- this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
986
- if (event.pointerType !== "mouse") stopRetargetedClick(element, event.timeStamp);
987
- },
988
- onPointerCancel: (event) => {
989
- this.terminate(event, false);
990
- },
991
- onClick: (event) => {
992
- const native = event.nativeEvent;
993
- if (claimed.has(native) || startsInNativeControl(event)) return;
994
- if (this.pointerClickPending && event.detail > 0) {
995
- this.pointerClickPending = false;
996
- claimed.add(native);
997
- if (this.cancelClick) event.preventDefault();
998
- return;
999
- }
1000
- if (this.config.disabled === true) return;
1001
- claimed.add(native);
1002
- this.config.onPress?.(toGestureResponderEvent(event, event.currentTarget));
1003
- },
1004
- onKeyDown: (event) => {
1005
- if (!isActivationKey(event.key) || event.repeat || event.nativeEvent.isComposing) return;
1006
- const element = event.currentTarget;
1007
- if (event.target !== element || this.config.disabled === true) return;
1008
- if (hasNativeActivation(element)) return;
1009
- if (event.key === " ") event.preventDefault();
1010
- if (this.pointerId !== null || this.key !== null) return;
1011
- this.key = event.key;
1012
- this.grant(element, toGestureResponderEvent(event, element));
1013
- },
1014
- onKeyUp: (event) => {
1015
- const element = this.element;
1016
- if (event.key !== this.key || element === null) return;
1017
- this.key = null;
1018
- this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
1019
- },
1020
- onFocus: (event) => {
1021
- this.config.onFocus?.(event);
1022
- },
1023
- onBlur: (event) => {
1024
- const element = this.element;
1025
- if (this.key !== null && element !== null && event.target === event.currentTarget) {
1026
- this.key = null;
1027
- this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
1028
- }
1029
- this.config.onBlur?.(event);
1030
- },
1031
- onPointerEnter: (event) => {
1032
- if (event.pointerType === "touch") return;
1033
- this.hovered = true;
1034
- this.hoverOutTimer = clear(this.hoverOutTimer);
1035
- this.hover(event, this.config.onHoverIn, this.config.delayHoverIn, "in");
1036
- },
1037
- onPointerLeave: (event) => {
1038
- if (!this.hovered) return;
1039
- this.hovered = false;
1040
- this.hoverInTimer = clear(this.hoverInTimer);
1041
- this.hover(event, this.config.onHoverOut, this.config.delayHoverOut, "out");
1042
- },
1043
- onContextMenu: (event) => {
1044
- if (this.pointerId !== null && this.config.onLongPress != null) event.preventDefault();
1045
- }
1046
- };
1047
- }
1048
- hover(event, callback, delay, direction) {
1049
- if (callback == null) return;
1050
- const hoverEvent = toMouseEvent(event);
1051
- const wait = normalizeDelay(delay);
1052
- if (wait === 0) {
1053
- callback(hoverEvent);
1054
- return;
1055
- }
1056
- const timer = setTimeout(() => callback(hoverEvent), wait);
1057
- if (direction === "in") this.hoverInTimer = timer;
1058
- else this.hoverOutTimer = timer;
1059
- }
1060
- grant(element, event) {
1061
- this.pressOutTimer = clear(this.pressOutTimer);
1062
- this.element = element;
1063
- this.cancelClick = false;
1064
- this.state = "NOT_RESPONDER";
1065
- this.receiveSignal("RESPONDER_GRANT", event);
1066
- const delayPressIn = normalizeDelay(this.config.delayPressIn);
1067
- if (delayPressIn > 0) this.pressDelayTimer = setTimeout(() => this.receiveSignal("DELAY", event), delayPressIn);
1068
- else this.receiveSignal("DELAY", event);
1069
- const delayLongPress = normalizeDelay(this.config.delayLongPress, 10, DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn);
1070
- this.longPressTimer = setTimeout(() => {
1071
- if (this.state === "RESPONDER_ACTIVE_PRESS_IN" || this.state === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.receiveSignal("LONG_PRESS_DETECTED", event);
1072
- }, delayLongPress + delayPressIn);
1073
- }
1074
- receiveSignal(signal, event) {
1075
- const prevState = this.state;
1076
- const nextState = transitions[prevState][signal];
1077
- if (nextState === void 0 || nextState === prevState) return;
1078
- this.performTransitionSideEffects(prevState, nextState, signal, event);
1079
- this.state = nextState;
1080
- }
1081
- performTransitionSideEffects(prevState, nextState, signal, event) {
1082
- if (isTerminal(signal)) {
1083
- this.activatePosition = null;
1084
- this.longPressTimer = clear(this.longPressTimer);
1085
- }
1086
- const isInitialTransition = prevState === "NOT_RESPONDER" && nextState === "RESPONDER_INACTIVE_PRESS_IN";
1087
- const isActivationTransition = !isActivation(prevState) && isActivation(nextState);
1088
- if (isInitialTransition || isActivationTransition) this.measureRegion();
1089
- if (isPressIn(prevState) && signal === "LONG_PRESS_DETECTED") this.config.onLongPress?.(event);
1090
- const isPrevActive = isActive(prevState);
1091
- const isNextActive = isActive(nextState);
1092
- if (!isPrevActive && isNextActive) this.activate(event);
1093
- else if (isPrevActive && !isNextActive) this.deactivate(event);
1094
- if (isPressIn(prevState) && signal === "RESPONDER_RELEASE") {
1095
- if (!isNextActive && !isPrevActive) {
1096
- this.activate(event);
1097
- this.deactivate(event);
1098
- }
1099
- const { onLongPress, onPress } = this.config;
1100
- if (onLongPress != null && prevState === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.cancelClick = true;
1101
- else if (onPress != null) {
1102
- onPress(event);
1103
- if (event.isDefaultPrevented()) this.cancelClick = true;
1104
- }
1105
- }
1106
- this.pressDelayTimer = clear(this.pressDelayTimer);
1107
- }
1108
- activate(event) {
1109
- const { pageX, pageY } = event.nativeEvent;
1110
- this.activatePosition = {
1111
- pageX,
1112
- pageY
1113
- };
1114
- this.activateTime = Date.now();
1115
- this.config.onPressIn?.(event);
1116
- }
1117
- deactivate(event) {
1118
- const { onPressOut } = this.config;
1119
- if (onPressOut != null) {
1120
- const minPressDuration = normalizeDelay(this.config.minPressDuration, 0, DEFAULT_MIN_PRESS_DURATION);
1121
- const pressDuration = Date.now() - (this.activateTime ?? 0);
1122
- const delayPressOut = Math.max(minPressDuration - pressDuration, normalizeDelay(this.config.delayPressOut));
1123
- if (delayPressOut > 0) this.pressOutTimer = setTimeout(() => onPressOut(event), delayPressOut);
1124
- else onPressOut(event);
1125
- }
1126
- this.activateTime = null;
1127
- }
1128
- measureRegion() {
1129
- if (this.element === null) return;
1130
- const rect = this.element.getBoundingClientRect();
1131
- if (rect.width === 0 && rect.height === 0 && rect.top === 0 && rect.left === 0) return;
1132
- this.region = {
1133
- bottom: rect.bottom + window.scrollY,
1134
- left: rect.left + window.scrollX,
1135
- right: rect.right + window.scrollX,
1136
- top: rect.top + window.scrollY
1137
- };
1138
- }
1139
- isWithinRegion(pageX, pageY, region) {
1140
- const hitSlop = normalizeRect(this.config.hitSlop);
1141
- const offset = normalizeRect(this.config.pressRectOffset);
1142
- const bottom = region.bottom + (hitSlop?.bottom ?? 0) + (offset?.bottom ?? DEFAULT_PRESS_RECT_OFFSETS.bottom);
1143
- const left = region.left - (hitSlop?.left ?? 0) - (offset?.left ?? DEFAULT_PRESS_RECT_OFFSETS.left);
1144
- const right = region.right + (hitSlop?.right ?? 0) + (offset?.right ?? DEFAULT_PRESS_RECT_OFFSETS.right);
1145
- const top = region.top - (hitSlop?.top ?? 0) - (offset?.top ?? DEFAULT_PRESS_RECT_OFFSETS.top);
1146
- return pageX > left && pageX < right && pageY > top && pageY < bottom;
1147
- }
1148
- };
1149
- // src/apis/PanResponder/index.ts
1150
- let current = null;
1151
- let grantEvent = null;
1152
- let nextStateID = 1;
1153
- let listening = false;
1154
- const blockNativeScroll = (event) => {
1155
- if (current !== null && current.blocksNative && event.cancelable) event.preventDefault();
1156
- };
1157
- const listenForTouchMove = () => {
1158
- if (listening || typeof document === "undefined") return;
1159
- listening = true;
1160
- document.addEventListener("touchmove", blockNativeScroll, { passive: false });
1161
- };
1162
- const newGestureState = () => ({
1163
- stateID: nextStateID++,
1164
- moveX: 0,
1165
- moveY: 0,
1166
- x0: 0,
1167
- y0: 0,
1168
- dx: 0,
1169
- dy: 0,
1170
- vx: 0,
1171
- vy: 0,
1172
- numberActiveTouches: 0,
1173
- _accountsForMovesUpTo: 0
1174
- });
1175
- const centroid = (pointers) => {
1176
- let x = 0;
1177
- let y = 0;
1178
- for (const pointer of pointers.values()) {
1179
- x += pointer.clientX + window.scrollX;
1180
- y += pointer.clientY + window.scrollY;
1181
- }
1182
- const count = pointers.size || 1;
1183
- return {
1184
- x: x / count,
1185
- y: y / count
1186
- };
1187
- };
1188
- const define = (target, fields) => {
1189
- for (const key in fields) Object.defineProperty(target, key, {
1190
- value: fields[key],
1191
- configurable: true,
1192
- writable: true
1193
- });
1194
- };
1195
- const touchOf = (pointer, rect, timestamp) => ({
1196
- changedTouches: [],
1197
- identifier: pointer.id,
1198
- locationX: pointer.clientX - rect.left,
1199
- locationY: pointer.clientY - rect.top,
1200
- pageX: pointer.clientX + window.scrollX,
1201
- pageY: pointer.clientY + window.scrollY,
1202
- target: pointer.target,
1203
- timestamp,
1204
- touches: []
1205
- });
1206
- const toResponderEvent = (event, responder, changed) => {
1207
- const rect = (responder.element ?? event.currentTarget).getBoundingClientRect();
1208
- const touches = [...responder.pointers.values()].map((p) => touchOf(p, rect, event.timeStamp));
1209
- const touch = touchOf(changed, rect, event.timeStamp);
1210
- define(event.nativeEvent, {
1211
- ...touch,
1212
- force: event.pressure,
1213
- touches,
1214
- changedTouches: [touch]
1215
- });
1216
- return event;
1217
- };
1218
- const pointerOf = (event) => ({
1219
- id: event.pointerId,
1220
- clientX: event.clientX,
1221
- clientY: event.clientY,
1222
- target: event.target
1223
- });
1224
- const updateMove = (responder, time) => {
1225
- const state = responder.gestureState;
1226
- const next = centroid(responder.pointers);
1227
- const last = responder.last;
1228
- if (last !== null) {
1229
- const dt = time - last.time;
1230
- state.dx += next.x - last.x;
1231
- state.dy += next.y - last.y;
1232
- state.vx = dt > 0 ? (next.x - last.x) / dt : 0;
1233
- state.vy = dt > 0 ? (next.y - last.y) / dt : 0;
1234
- }
1235
- state.moveX = next.x;
1236
- state.moveY = next.y;
1237
- state._accountsForMovesUpTo = time;
1238
- responder.last = {
1239
- x: next.x,
1240
- y: next.y,
1241
- time
1242
- };
1243
- };
1244
- const rebase = (responder, time) => {
1245
- const next = centroid(responder.pointers);
1246
- responder.last = {
1247
- x: next.x,
1248
- y: next.y,
1249
- time
1250
- };
1251
- responder.gestureState.numberActiveTouches = responder.pointers.size;
1252
- };
1253
- const grant = (responder, event, responderEvent) => {
1254
- const state = responder.gestureState;
1255
- const point = centroid(responder.pointers);
1256
- state.x0 = point.x;
1257
- state.y0 = point.y;
1258
- state.dx = 0;
1259
- state.dy = 0;
1260
- state.vx = 0;
1261
- state.vy = 0;
1262
- responder.last = {
1263
- x: point.x,
1264
- y: point.y,
1265
- time: event.timeStamp
1266
- };
1267
- responder.element = event.currentTarget;
1268
- current = responder;
1269
- grantEvent = event.nativeEvent;
1270
- claimPress(event.nativeEvent);
1271
- terminatePress(event);
1272
- for (const pointer of responder.pointers.values()) try {
1273
- responder.element.setPointerCapture(pointer.id);
1274
- } catch {}
1275
- responder.config.onPanResponderGrant?.(responderEvent, state);
1276
- responder.blocksNative = responder.config.onShouldBlockNativeResponder?.(responderEvent, state) !== false;
1277
- responder.config.onPanResponderStart?.(responderEvent, state);
1278
- };
1279
- const releaseCapture = (responder) => {
1280
- const element = responder.element;
1281
- if (element === null) return;
1282
- for (const pointer of responder.pointers.values()) try {
1283
- if (element.hasPointerCapture(pointer.id)) element.releasePointerCapture(pointer.id);
1284
- } catch {}
1285
- };
1286
- const finish = (responder) => {
1287
- releaseCapture(responder);
1288
- if (current === responder) current = null;
1289
- responder.element = null;
1290
- responder.last = null;
1291
- };
1292
- const negotiate = (responder, event, responderEvent, predicate) => {
1293
- if (current === responder) return;
1294
- if (current !== null && grantEvent === event.nativeEvent) return;
1295
- if (predicate === void 0 || !predicate(responderEvent, responder.gestureState)) return;
1296
- if (current !== null) {
1297
- const holder = current;
1298
- if (holder.config.onPanResponderTerminationRequest?.(responderEvent, holder.gestureState) === false) {
1299
- responder.config.onPanResponderReject?.(responderEvent, responder.gestureState);
1300
- return;
1301
- }
1302
- holder.config.onPanResponderTerminate?.(responderEvent, holder.gestureState);
1303
- finish(holder);
1304
- }
1305
- grant(responder, event, responderEvent);
1306
- };
1307
- const createHandlers = (responder) => {
1308
- const down = (event, capture) => {
1309
- const pointer = pointerOf(event);
1310
- const first = responder.pointers.size === 0;
1311
- if (capture) {
1312
- if (first) responder.gestureState = newGestureState();
1313
- responder.pointers.set(pointer.id, pointer);
1314
- rebase(responder, event.timeStamp);
1315
- }
1316
- const responderEvent = toResponderEvent(event, responder, pointer);
1317
- const { config } = responder;
1318
- if (current === responder) {
1319
- if (capture) config.onPanResponderStart?.(responderEvent, responder.gestureState);
1320
- return;
1321
- }
1322
- if (!capture && isPressClaimed(event.nativeEvent)) return;
1323
- negotiate(responder, event, responderEvent, capture ? config.onStartShouldSetPanResponderCapture : config.onStartShouldSetPanResponder);
1324
- };
1325
- const move = (event, capture) => {
1326
- const pointer = responder.pointers.get(event.pointerId);
1327
- if (pointer === void 0) return;
1328
- if (capture) {
1329
- pointer.clientX = event.clientX;
1330
- pointer.clientY = event.clientY;
1331
- updateMove(responder, event.timeStamp);
1332
- }
1333
- const responderEvent = toResponderEvent(event, responder, pointer);
1334
- const { config } = responder;
1335
- if (current === responder) {
1336
- if (capture) config.onPanResponderMove?.(responderEvent, responder.gestureState);
1337
- return;
1338
- }
1339
- negotiate(responder, event, responderEvent, capture ? config.onMoveShouldSetPanResponderCapture : config.onMoveShouldSetPanResponder);
1340
- };
1341
- const end = (event, cancel) => {
1342
- const pointer = responder.pointers.get(event.pointerId);
1343
- if (pointer === void 0) return;
1344
- const responderEvent = toResponderEvent(event, responder, pointer);
1345
- responder.pointers.delete(event.pointerId);
1346
- const { config, gestureState } = responder;
1347
- const responding = current === responder;
1348
- if (responding && cancel) {
1349
- config.onPanResponderTerminate?.(responderEvent, gestureState);
1350
- responder.pointers.clear();
1351
- finish(responder);
1352
- return;
1353
- }
1354
- if (responding) config.onPanResponderEnd?.(responderEvent, gestureState);
1355
- if (responder.pointers.size === 0) {
1356
- if (responding) config.onPanResponderRelease?.(responderEvent, gestureState);
1357
- finish(responder);
1358
- } else rebase(responder, event.timeStamp);
1359
- };
1360
- return {
1361
- onPointerDownCapture: (event) => down(event, true),
1362
- onPointerDown: (event) => down(event, false),
1363
- onPointerMoveCapture: (event) => move(event, true),
1364
- onPointerMove: (event) => move(event, false),
1365
- onPointerUp: (event) => end(event, false),
1366
- onPointerCancel: (event) => end(event, true)
1367
- };
1368
- };
1369
- const PanResponder = { create(config) {
1370
- const responder = {
1371
- config,
1372
- gestureState: newGestureState(),
1373
- pointers: /* @__PURE__ */ new Map(),
1374
- element: null,
1375
- last: null,
1376
- blocksNative: true
1377
- };
1378
- listenForTouchMove();
1379
- return {
1380
- panHandlers: createHandlers(responder),
1381
- getInteractionHandle: () => null
1382
- };
1383
- } };
1384
- // src/apis/PixelRatio/index.ts
1385
- const PixelRatio = {
1386
- get: () => Dimensions.get("window").scale,
1387
- getFontScale: () => Dimensions.get("window").fontScale,
1388
- getPixelSizeForLayoutSize: (layoutSize) => Math.round(layoutSize * PixelRatio.get()),
1389
- roundToNearestPixel: (layoutSize) => {
1390
- const ratio = PixelRatio.get();
1391
- return Math.round(layoutSize * ratio) / ratio;
1392
- },
1393
- startDetecting: () => {}
1394
- };
1395
- // src/reactNativeVersion.ts
1396
- const reactNativeVersion = {
1397
- major: 0,
1398
- minor: 88,
1399
- patch: 1,
1400
- prerelease: void 0
1401
- };
1402
- // src/apis/Platform/index.ts
1403
- const Platform = {
1404
- OS: "web",
1405
- get Version() {
1406
- return hasDOM() ? navigator.userAgent : "";
1407
- },
1408
- get constants() {
1409
- return { reactNativeVersion };
1410
- },
1411
- get isTV() {
1412
- return false;
1413
- },
1414
- get isTesting() {
1415
- return isTestEnv();
1416
- },
1417
- get isDisableAnimations() {
1418
- return matchesMedia("(prefers-reduced-motion: reduce)");
1419
- },
1420
- select(spec) {
1421
- if ("web" in spec) return spec.web;
1422
- if ("default" in spec) return spec.default;
1423
- }
1424
- };
1425
- // src/apis/processColor/index.ts
1426
- const processColor = (color) => {
1427
- if (color === void 0 || color === null) return color;
1428
- if (typeof color !== "string" && typeof color !== "number") return null;
1429
- const rgba = normalizeColor(color);
1430
- if (rgba === null || rgba === void 0) return null;
1431
- return (rgba << 24 | rgba >>> 8) >>> 0;
1432
- };
1433
- // src/apis/Share/index.ts
1434
- const isAbort = (error) => error instanceof DOMException && error.name === "AbortError";
1435
- /**
1436
- * Opens the browser's share sheet with `navigator.share`. It shares the title, the message,
1437
- * and the URL. A closed sheet resolves `dismissedAction`, as on iOS.
1438
- */
1439
- const Share = {
1440
- share(content, options = {}) {
1441
- if (typeof content !== "object" || content === null) throw new Error("Content to share must be a valid object");
1442
- if (typeof content.url !== "string" && typeof content.message !== "string") throw new Error("At least one of URL or message is required");
1443
- if (typeof options !== "object" || options === null) throw new Error("Options must be a valid object");
1444
- if (!hasDOM() || typeof navigator.share !== "function") return Promise.reject(/* @__PURE__ */ new Error("Unsupported platform"));
1445
- const data = {};
1446
- if (typeof content.title === "string") data.title = content.title;
1447
- if (typeof content.message === "string") data.text = content.message;
1448
- if (typeof content.url === "string") data.url = content.url;
1449
- return navigator.share(data).then(() => ({
1450
- action: "sharedAction",
1451
- activityType: null
1452
- }), (error) => {
1453
- if (isAbort(error)) return {
1454
- action: "dismissedAction",
1455
- activityType: null
1456
- };
1457
- throw error;
1458
- });
1459
- },
1460
- sharedAction: "sharedAction",
1461
- dismissedAction: "dismissedAction"
1462
- };
1463
- // src/apis/StyleSheet/index.ts
1464
- const absoluteFillObject = {
1465
- position: "absolute",
1466
- left: 0,
1467
- right: 0,
1468
- top: 0,
1469
- bottom: 0
1470
- };
1471
- const create = (styles) => {
1472
- for (const key in styles) Object.freeze(styles[key]);
1473
- return Object.freeze(styles);
1474
- };
1475
- const flatten = (style) => flattenStyle(style);
1476
- const compose = (style1, style2) => {
1477
- if (style1 && style2) return [style1, style2];
1478
- return style1 || style2;
1479
- };
1480
- const StyleSheet = Object.freeze({
1481
- absoluteFill: Object.freeze(absoluteFillObject),
1482
- absoluteFillObject,
1483
- hairlineWidth: 1,
1484
- create,
1485
- flatten,
1486
- compose
1487
- });
1488
- // src/apis/useColorScheme/index.ts
1489
- const subscribe$1 = (onChange) => {
1490
- const subscription = Appearance.addChangeListener(onChange);
1491
- return () => subscription.remove();
1492
- };
1493
- const getSnapshot$1 = () => Appearance.getColorScheme();
1494
- const getServerSnapshot$1 = () => "light";
1495
- const useColorScheme = () => useSyncExternalStore(subscribe$1, getSnapshot$1, getServerSnapshot$1);
1496
- // src/apis/useWindowDimensions/index.ts
1497
- const serverSnapshot = Object.freeze({
1498
- width: 0,
1499
- height: 0,
1500
- scale: 1,
1501
- fontScale: 1
1502
- });
1503
- const subscribe = (onChange) => {
1504
- const subscription = Dimensions.addEventListener("change", onChange);
1505
- return () => subscription.remove();
1506
- };
1507
- const getSnapshot = () => Dimensions.get("window");
1508
- const getServerSnapshot = () => serverSnapshot;
1509
- const useWindowDimensions = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
1510
- // src/apis/Vibration/index.ts
1511
- const DEFAULT_LENGTH = 400;
1512
- let repeatTimer;
1513
- const canVibrate = () => hasDOM() && typeof navigator.vibrate === "function";
1514
- const stopRepeat = () => {
1515
- if (repeatTimer === void 0) return;
1516
- clearTimeout(repeatTimer);
1517
- repeatTimer = void 0;
1518
- };
1519
- /**
1520
- * Vibrates the device with `navigator.vibrate`, with Android's rules: the durations apply, and
1521
- * an array starts with a wait.
1522
- */
1523
- const Vibration = {
1524
- vibrate(pattern = DEFAULT_LENGTH, repeat = false) {
1525
- let steps;
1526
- if (typeof pattern === "number") steps = [pattern];
1527
- else if (Array.isArray(pattern)) steps = [0, ...pattern];
1528
- else throw new Error("Vibration pattern should be a number or array");
1529
- stopRepeat();
1530
- if (!canVibrate()) return;
1531
- navigator.vibrate(steps);
1532
- if (!repeat || typeof pattern === "number") return;
1533
- const total = steps.reduce((sum, step) => sum + step, 0);
1534
- if (total <= 0) return;
1535
- const again = () => {
1536
- navigator.vibrate(steps);
1537
- repeatTimer = setTimeout(again, total);
1538
- };
1539
- repeatTimer = setTimeout(again, total);
1540
- },
1541
- cancel() {
1542
- stopRepeat();
1543
- if (canVibrate()) navigator.vibrate(0);
1544
- }
1545
- };
1546
- // src/style/webStyle.ts
1547
- /**
1548
- * A frozen style for the internals of a component that uses CSS React Native doesn't have, such
1549
- * as `overflowX` or `position: 'sticky'`. The compiler passes unknown names through to CSS.
1550
- */
1551
- const webStyle = (style) => Object.freeze(style);
1552
- // src/render/domProps.ts
1553
- const liveRegionToAriaLive = {
1554
- none: "off",
1555
- polite: "polite",
1556
- assertive: "assertive"
1557
- };
1558
- const nativeHandler = /^on(Press|Layout|TextLayout|Accessibility|Magic|Responder|Refresh|.*ShouldSet)/;
1559
- const isNativeHandler = (name) => nativeHandler.test(name);
1560
- const passThrough = /* @__PURE__ */ new Set([
1561
- "lang",
1562
- "dir",
1563
- "target",
1564
- "rel",
1565
- "download"
1566
- ]);
1567
- const toDOMProps = (props) => {
1568
- const out = {};
1569
- for (const name in props) {
1570
- const value = props[name];
1571
- if (value === void 0) continue;
1572
- if (name.startsWith("aria-") || name.startsWith("data-") || passThrough.has(name)) out[name] = value;
1573
- else if (name.startsWith("on") && name.length > 2 && !nativeHandler.test(name)) out[name] = value;
1574
- }
1575
- const { accessibilityLabel, accessibilityLabelledBy, accessibilityHint, accessibilityState, accessibilityValue, accessibilityLiveRegion, accessibilityElementsHidden, accessibilityViewIsModal, importantForAccessibility, id, nativeID, testID, tabIndex, focusable, href } = props;
1576
- if (accessibilityLabel !== void 0) out["aria-label"] ??= accessibilityLabel;
1577
- if (accessibilityLabelledBy !== void 0) out["aria-labelledby"] ??= Array.isArray(accessibilityLabelledBy) ? accessibilityLabelledBy.join(" ") : accessibilityLabelledBy;
1578
- if (accessibilityHint !== void 0) out["aria-description"] ??= accessibilityHint;
1579
- if (accessibilityLiveRegion !== void 0) out["aria-live"] ??= liveRegionToAriaLive[accessibilityLiveRegion];
1580
- if (accessibilityViewIsModal !== void 0) out["aria-modal"] ??= accessibilityViewIsModal;
1581
- if (accessibilityElementsHidden === true || importantForAccessibility === "no-hide-descendants") out["aria-hidden"] ??= true;
1582
- if (accessibilityState !== void 0) {
1583
- const { busy, checked, disabled, expanded, selected } = accessibilityState;
1584
- if (busy !== void 0) out["aria-busy"] ??= busy;
1585
- if (checked !== void 0) out["aria-checked"] ??= checked;
1586
- if (disabled !== void 0) out["aria-disabled"] ??= disabled;
1587
- if (expanded !== void 0) out["aria-expanded"] ??= expanded;
1588
- if (selected !== void 0) out["aria-selected"] ??= selected;
1589
- }
1590
- if (accessibilityValue !== void 0) {
1591
- const { max, min, now, text } = accessibilityValue;
1592
- if (max !== void 0) out["aria-valuemax"] ??= max;
1593
- if (min !== void 0) out["aria-valuemin"] ??= min;
1594
- if (now !== void 0) out["aria-valuenow"] ??= now;
1595
- if (text !== void 0) out["aria-valuetext"] ??= text;
1596
- }
1597
- const domId = id ?? nativeID;
1598
- if (domId !== void 0) out["id"] = domId;
1599
- if (testID !== void 0) out["data-testid"] = testID;
1600
- if (href !== void 0) out["href"] = href;
1601
- if (tabIndex !== void 0) out["tabIndex"] = tabIndex;
1602
- else if (focusable === true) out["tabIndex"] = 0;
1603
- else if (focusable === false) out["tabIndex"] = -1;
1604
- return out;
1605
- };
1606
- // src/render/hostMethods.ts
1607
- const applyNativeProps = (element, nativeProps) => {
1608
- const inline = element.style;
1609
- for (const [name, value] of Object.entries(nativeProps)) {
1610
- if (name !== "style") {
1611
- warnOnce(`set-native-props-${name}`, `setNativeProps: only \`style\` works on the web. \`${name}\` has no effect.`);
1612
- continue;
1613
- }
1614
- const flat = flattenStyle(value);
1615
- if (flat !== void 0) Object.assign(inline, resolveStyle(flat));
1616
- }
1617
- };
1618
- const hostMethods = (element) => ({
1619
- measure: (callback) => {
1620
- const { left, top, width, height } = element.getBoundingClientRect();
1621
- const parent = element.parentElement?.getBoundingClientRect();
1622
- callback(left - (parent?.left ?? 0), top - (parent?.top ?? 0), width, height, left, top);
1623
- },
1624
- measureInWindow: (callback) => {
1625
- const { left, top, width, height } = element.getBoundingClientRect();
1626
- callback(left, top, width, height);
1627
- },
1628
- measureLayout: (relativeToNativeNode, onSuccess, onFail) => {
1629
- if (!(relativeToNativeNode instanceof Element) || !element.isConnected || !relativeToNativeNode.contains(element)) {
1630
- onFail?.();
1631
- return;
1632
- }
1633
- const { left, top, width, height } = element.getBoundingClientRect();
1634
- const ancestor = relativeToNativeNode.getBoundingClientRect();
1635
- onSuccess(left - ancestor.left, top - ancestor.top, width, height);
1636
- },
1637
- setNativeProps: (nativeProps) => applyNativeProps(element, nativeProps)
1638
- });
1639
- const withHostMethods = (element) => {
1640
- const instance = element;
1641
- if (instance.measureInWindow === void 0) Object.assign(instance, hostMethods(element));
1642
- return instance;
1643
- };
1644
- // src/render/resolveTag.ts
1645
- const legacyRoleToRole = {
1646
- header: "heading",
1647
- image: "img",
1648
- imagebutton: "button",
1649
- summary: "region",
1650
- text: "none",
1651
- adjustable: "slider",
1652
- search: "searchbox",
1653
- keyboardkey: "none"
1654
- };
1655
- const roleToTag = {
1656
- article: "article",
1657
- banner: "header",
1658
- button: "button",
1659
- complementary: "aside",
1660
- contentinfo: "footer",
1661
- figure: "figure",
1662
- form: "form",
1663
- list: "ul",
1664
- listitem: "li",
1665
- main: "main",
1666
- navigation: "nav",
1667
- separator: "hr"
1668
- };
1669
- const headingLevel = (level) => level !== void 0 && Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2;
1670
- const voidTags = /* @__PURE__ */ new Set(["hr"]);
1671
- const resolveTag = (props, defaultTag, hasChildren = false) => {
1672
- const role = props.role ?? mapLegacyRole(props.accessibilityRole);
1673
- const resolved = tagForRole(role, props, defaultTag);
1674
- return hasChildren && voidTags.has(resolved.tag) ? {
1675
- tag: defaultTag,
1676
- role
1677
- } : resolved;
1678
- };
1679
- const tagForRole = (role, props, defaultTag) => {
1680
- if (role === "heading") return {
1681
- tag: `h${headingLevel(props["aria-level"])}`,
1682
- role: void 0
1683
- };
1684
- if (role === "link") return props.href === void 0 ? {
1685
- tag: defaultTag,
1686
- role: "link"
1687
- } : {
1688
- tag: "a",
1689
- role: void 0
1690
- };
1691
- if (role === void 0) return {
1692
- tag: props.href === void 0 ? defaultTag : "a",
1693
- role: void 0
1694
- };
1695
- const tag = roleToTag[role];
1696
- return tag === void 0 ? {
1697
- tag: defaultTag,
1698
- role
1699
- } : {
1700
- tag,
1701
- role: void 0
1702
- };
1703
- };
1704
- const mapLegacyRole = (legacy) => legacy === void 0 ? void 0 : legacyRoleToRole[legacy] ?? legacy;
1705
- // src/render/useElementLayout.ts
1706
- const measure = (element) => ({ nativeEvent: { layout: {
1707
- x: element.offsetLeft,
1708
- y: element.offsetTop,
1709
- width: element.offsetWidth,
1710
- height: element.offsetHeight
1711
- } } });
1712
- const useElementLayout = (ref, onLayout) => {
1713
- const latest = useRef(onLayout);
1714
- useEffect(() => {
1715
- latest.current = onLayout;
1716
- }, [onLayout]);
1717
- const enabled = onLayout !== void 0;
1718
- useEffect(() => {
1719
- const element = ref.current;
1720
- if (element === null || !enabled) return;
1721
- const observer = new ResizeObserver(() => latest.current?.(measure(element)));
1722
- observer.observe(element);
1723
- return () => observer.disconnect();
1724
- }, [ref, enabled]);
1725
- };
1726
- // src/components/View/index.tsx
1727
- const resetStyle$2 = Object.freeze({
1728
- alignItems: "stretch",
1729
- backgroundColor: "transparent",
1730
- border: "0 solid black",
1731
- boxSizing: "border-box",
1732
- display: "flex",
1733
- flexBasis: "auto",
1734
- flexDirection: "column",
1735
- flexShrink: 0,
1736
- listStyle: "none",
1737
- margin: 0,
1738
- minHeight: 0,
1739
- minWidth: 0,
1740
- padding: 0,
1741
- position: "relative",
1742
- textDecoration: "none",
1743
- zIndex: 0
1744
- });
1745
- function View(props) {
1746
- return useViewElement(props);
1747
- }
1748
- function useViewElement(props, extraClassName) {
1749
- const { children, onLayout, pointerEvents, ref, style, ...rest } = props;
1750
- const element = useRef(null);
1751
- useImperativeHandle(ref, () => withHostMethods(element.current), []);
1752
- useElementLayout(element, onLayout);
1753
- const registry = useStyleRegistry();
1754
- const { tag, role } = resolveTag(rest, "div", children != null);
1755
- let className = joinClassNames(compileReset("rn-view", resetStyle$2, registry), compileStyle(pointerEvents === void 0 ? style : [style, pointerEventsStyle[pointerEvents]], registry));
1756
- if (extraClassName !== void 0) className = `${className} ${extraClassName}`;
1757
- const domProps = toDOMProps(rest);
1758
- if (role !== void 0) domProps["role"] = role;
1759
- if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
1760
- if (tag === "button") domProps["type"] = "button";
1761
- domProps["className"] = className;
1762
- domProps["ref"] = element;
1763
- return createElement(tag, domProps, children);
1764
- }
1765
- // src/components/ActivityIndicator/index.tsx
1766
- const GRAY = "#999999";
1767
- const SPIN_CLASS = "rn-activity-indicator";
1768
- const SPIN_RULES = ["@keyframes rn-activity-indicator-spin{to{transform:rotate(360deg)}}", `.${SPIN_CLASS}{animation:rn-activity-indicator-spin .75s linear infinite}`];
1769
- const hiddenStyle$1 = webStyle({ visibility: "hidden" });
1770
- const pausedStyle = { animationPlayState: "paused" };
1771
- function ActivityIndicator(props) {
1772
- const { animating = true, color = GRAY, hidesWhenStopped = true, onLayout, ref, size = "small", style, ...rest } = props;
1773
- const spinClass = useStyleRegistry().staticClass(SPIN_CLASS, SPIN_RULES);
1774
- const stroke = toCSSColor(color) ?? GRAY;
1775
- const sizeStyle = size === "small" ? styles$4.sizeSmall : size === "large" ? styles$4.sizeLarge : {
1776
- width: size,
1777
- height: size
1778
- };
1779
- return /* @__PURE__ */ jsx(View, {
1780
- onLayout,
1781
- style: [styles$4.container, style],
1782
- children: /* @__PURE__ */ jsx(View, {
1783
- role: "progressbar",
1784
- ...rest,
1785
- ref,
1786
- style: [sizeStyle, !animating && hidesWhenStopped && hiddenStyle$1],
1787
- children: /* @__PURE__ */ jsxs("svg", {
1788
- "aria-hidden": true,
1789
- className: spinClass,
1790
- height: "100%",
1791
- style: animating ? void 0 : pausedStyle,
1792
- viewBox: "0 0 32 32",
1793
- width: "100%",
1794
- children: [/* @__PURE__ */ jsx("circle", {
1795
- cx: "16",
1796
- cy: "16",
1797
- fill: "none",
1798
- opacity: "0.2",
1799
- r: "14",
1800
- stroke,
1801
- strokeWidth: "4"
1802
- }), /* @__PURE__ */ jsx("circle", {
1803
- cx: "16",
1804
- cy: "16",
1805
- fill: "none",
1806
- r: "14",
1807
- stroke,
1808
- strokeDasharray: "80",
1809
- strokeDashoffset: "60",
1810
- strokeWidth: "4"
1811
- })]
1812
- })
1813
- })
1814
- });
1815
- }
1816
- const styles$4 = StyleSheet.create({
1817
- container: {
1818
- alignItems: "center",
1819
- justifyContent: "center"
1820
- },
1821
- sizeSmall: {
1822
- width: 20,
1823
- height: 20
1824
- },
1825
- sizeLarge: {
1826
- width: 36,
1827
- height: 36
1828
- }
1829
- });
1830
- // src/events/press/usePressability.ts
1831
- function usePressability(config) {
1832
- const [pressability, setPressability] = useState(() => config == null ? null : new Pressability(config));
1833
- if (pressability === null && config != null) setPressability(new Pressability(config));
1834
- useInsertionEffect(() => {
1835
- if (config != null && pressability !== null) pressability.configure(config);
1836
- }, [config, pressability]);
1837
- useInsertionEffect(() => {
1838
- if (pressability === null) return void 0;
1839
- return () => pressability.reset();
1840
- }, [pressability]);
1841
- return pressability === null ? null : pressability.getEventHandlers();
1842
- }
1843
- // src/events/press/mergeHandlers.ts
1844
- const sharedHandlers = [
1845
- "onClick",
1846
- "onContextMenu",
1847
- "onKeyDown",
1848
- "onKeyUp",
1849
- "onPointerCancel",
1850
- "onPointerDown",
1851
- "onPointerEnter",
1852
- "onPointerLeave",
1853
- "onPointerMove",
1854
- "onPointerUp"
1855
- ];
1856
- const mergeHandlers = (app, own) => {
1857
- const merged = { ...own };
1858
- for (const key of sharedHandlers) {
1859
- const value = app[key];
1860
- if (typeof value !== "function") continue;
1861
- const appHandler = value;
1862
- const ownHandler = own[key];
1863
- merged[key] = (event) => {
1864
- appHandler(event);
1865
- ownHandler(event);
1866
- };
1867
- }
1868
- return merged;
1869
- };
1870
- // src/components/Text/TextAncestorContext.ts
1871
- const TextAncestorContext = createContext(false);
1872
- // src/components/Text/index.tsx
1873
- const resetStyle$1 = Object.freeze({
1874
- backgroundColor: "transparent",
1875
- border: "0 solid black",
1876
- boxSizing: "border-box",
1877
- color: "black",
1878
- display: "inline",
1879
- fontFamily: "System",
1880
- fontSize: 14,
1881
- listStyle: "none",
1882
- margin: 0,
1883
- padding: 0,
1884
- position: "relative",
1885
- textAlign: "start",
1886
- textDecoration: "none",
1887
- whiteSpace: "pre-wrap",
1888
- wordWrap: "break-word"
1889
- });
1890
- const nestedResetStyle = Object.freeze({
1891
- color: "inherit",
1892
- font: "inherit",
1893
- textAlign: "inherit",
1894
- textDecoration: "inherit",
1895
- whiteSpace: "inherit"
1896
- });
1897
- const singleLineStyle = Object.freeze({
1898
- overflow: "hidden",
1899
- textOverflow: "ellipsis",
1900
- whiteSpace: "nowrap"
1901
- });
1902
- const multiLineStyle = (lines) => ({
1903
- display: "-webkit-box",
1904
- WebkitBoxOrient: "vertical",
1905
- WebkitLineClamp: lines,
1906
- overflow: "hidden"
1907
- });
1908
- const selectionClass$1 = (registry, color) => {
1909
- const css = toCSSColor(color);
1910
- if (css === void 0) return void 0;
1911
- const name = `rn-sel-${css.replace(/[^a-z0-9]/g, "")}`;
1912
- return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
1913
- };
1914
- function Text(props) {
1915
- const { children, disabled, ellipsizeMode, numberOfLines, onBlur, onFocus, onLayout, onLongPress, onPress, onPressIn, onPressOut, pointerEvents, pressRetentionOffset, ref, selectable, selectionColor, style, suppressHighlighting: _suppressHighlighting, ...rest } = props;
1916
- const nested = useContext(TextAncestorContext);
1917
- const element = useRef(null);
1918
- useImperativeHandle(ref, () => withHostMethods(element.current), []);
1919
- useElementLayout(element, onLayout);
1920
- const registry = useStyleRegistry();
1921
- const pressable = (onPress != null || onLongPress != null) && disabled !== true;
1922
- const handlers = usePressability(useMemo(() => pressable ? {
1923
- pressRectOffset: pressRetentionOffset,
1924
- onBlur,
1925
- onFocus,
1926
- onLongPress,
1927
- onPress,
1928
- onPressIn,
1929
- onPressOut
1930
- } : null, [
1931
- pressable,
1932
- pressRetentionOffset,
1933
- onBlur,
1934
- onFocus,
1935
- onLongPress,
1936
- onPress,
1937
- onPressIn,
1938
- onPressOut
1939
- ]));
1940
- const roleProps = pressable && rest.role === void 0 && rest.accessibilityRole === void 0 ? {
1941
- ...rest,
1942
- role: "link"
1943
- } : rest;
1944
- const { tag, role } = resolveTag(roleProps, "span", children != null);
1945
- const lineStyle = numberOfLines === void 0 || numberOfLines < 1 ? void 0 : numberOfLines === 1 ? singleLineStyle : multiLineStyle(numberOfLines);
1946
- const clipStyle = ellipsizeMode === "clip" ? { textOverflow: "clip" } : void 0;
1947
- const selectStyle = selectable === false ? { userSelect: "none" } : void 0;
1948
- const pointerStyle = pointerEvents === void 0 ? void 0 : pointerEventsStyle[pointerEvents];
1949
- let className = joinClassNames(nested ? compileReset("rn-text-nested", nestedResetStyle, registry) : compileReset("rn-text", resetStyle$1, registry), compileStyle([
1950
- style,
1951
- lineStyle,
1952
- clipStyle,
1953
- selectStyle,
1954
- pointerStyle
1955
- ], registry));
1956
- if (selectionColor !== void 0) {
1957
- const extra = selectionClass$1(registry, selectionColor);
1958
- if (extra !== void 0) className = `${className} ${extra}`;
1959
- }
1960
- const domProps = toDOMProps(rest);
1961
- if (role !== void 0) domProps["role"] = role;
1962
- if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
1963
- if (tag === "button") domProps["type"] = "button";
1964
- if (disabled === true) domProps["aria-disabled"] = true;
1965
- if (pressable && handlers !== null) {
1966
- Object.assign(domProps, mergeHandlers(rest, handlers));
1967
- if (domProps["tabIndex"] === void 0 && tag !== "a" && tag !== "button") domProps["tabIndex"] = 0;
1968
- } else {
1969
- if (onFocus !== void 0) domProps["onFocus"] = onFocus;
1970
- if (onBlur !== void 0) domProps["onBlur"] = onBlur;
1971
- }
1972
- domProps["className"] = className;
1973
- domProps["ref"] = element;
1974
- const content = nested ? children : createElement(TextAncestorContext.Provider, { value: true }, children);
1975
- return createElement(tag, domProps, content);
1976
- }
1977
- // src/render/hitSlop.ts
1978
- const hitSlopClass = (registry, hitSlop) => {
1979
- if (hitSlop === void 0) return void 0;
1980
- const { top = 0, right = 0, bottom = 0, left = 0 } = typeof hitSlop === "number" ? {
1981
- top: hitSlop,
1982
- right: hitSlop,
1983
- bottom: hitSlop,
1984
- left: hitSlop
1985
- } : hitSlop;
1986
- if (top === 0 && right === 0 && bottom === 0 && left === 0) return void 0;
1987
- const name = `rn-hs-${[
1988
- top,
1989
- right,
1990
- bottom,
1991
- left
1992
- ].map((n) => String(n).replace(/[^0-9]/g, "_")).join("-")}`;
1993
- return registry.staticClass(name, [`.${name}::before{content:"";position:absolute;top:${-top}px;right:${-right}px;bottom:${-bottom}px;left:${-left}px;z-index:-1}`]);
1994
- };
1995
- // src/components/TouchableOpacity/index.tsx
1996
- const EASE_IN_OUT_QUAD = "cubic-bezier(0.455, 0.03, 0.515, 0.955)";
1997
- const DEFAULT_ACTIVE_OPACITY$1 = .2;
1998
- const notCancelableStyle$2 = Object.freeze({ touchAction: "none" });
1999
- const isTrue$1 = (value) => value === void 0 ? void 0 : value === true || value === "true";
2000
- const restingOpacity = (style) => {
2001
- const opacity = flattenStyle(style)?.opacity;
2002
- return typeof opacity === "number" ? opacity : 1;
2003
- };
2004
- function TouchableOpacity(props) {
2005
- const { activeOpacity, children, delayLongPress, delayPressIn, delayPressOut, disabled, focusable, hasTVPreferredFocus: _hasTVPreferredFocus, hitSlop, nextFocusDown: _nextFocusDown, nextFocusForward: _nextFocusForward, nextFocusLeft: _nextFocusLeft, nextFocusRight: _nextFocusRight, nextFocusUp: _nextFocusUp, onBlur, onFocus, onLongPress, onPress, onPressIn, onPressOut, pressRetentionOffset, ref, rejectResponderTermination, style, touchSoundDisabled, ...rest } = props;
2006
- const element = useRef(null);
2007
- const animation = useRef(null);
2008
- const resting = restingOpacity(style);
2009
- const resolvedDisabled = disabled ?? isTrue$1(props["aria-disabled"]) ?? props.accessibilityState?.disabled;
2010
- const fadeTo = useCallback((opacity, duration, settle) => {
2011
- const node = element.current;
2012
- if (node === null || typeof node.animate !== "function") return;
2013
- const from = getComputedStyle(node).opacity;
2014
- animation.current?.cancel();
2015
- const next = node.animate([{ opacity: from }, { opacity: String(opacity) }], {
2016
- duration,
2017
- easing: EASE_IN_OUT_QUAD,
2018
- fill: "forwards"
2019
- });
2020
- animation.current = next;
2021
- if (settle) next.onfinish = () => {
2022
- if (animation.current !== next) return;
2023
- next.cancel();
2024
- animation.current = null;
2025
- };
2026
- }, []);
2027
- const handlers = usePressability(useMemo(() => ({
2028
- cancelable: rejectResponderTermination !== true,
2029
- disabled: resolvedDisabled,
2030
- hitSlop,
2031
- delayLongPress,
2032
- delayPressIn,
2033
- delayPressOut,
2034
- minPressDuration: 0,
2035
- pressRectOffset: pressRetentionOffset,
2036
- android_disableSound: touchSoundDisabled,
2037
- onBlur,
2038
- onFocus,
2039
- onLongPress,
2040
- onPress,
2041
- onPressIn: (event) => {
2042
- const starts = event.type === "pointerdown" || event.type === "keydown";
2043
- fadeTo(activeOpacity ?? DEFAULT_ACTIVE_OPACITY$1, starts ? 0 : 150, false);
2044
- onPressIn?.(event);
2045
- },
2046
- onPressOut: (event) => {
2047
- fadeTo(resting, 250, true);
2048
- onPressOut?.(event);
2049
- }
2050
- }), [
2051
- activeOpacity,
2052
- delayLongPress,
2053
- delayPressIn,
2054
- delayPressOut,
2055
- fadeTo,
2056
- hitSlop,
2057
- onBlur,
2058
- onFocus,
2059
- onLongPress,
2060
- onPress,
2061
- onPressIn,
2062
- onPressOut,
2063
- pressRetentionOffset,
2064
- rejectResponderTermination,
2065
- resolvedDisabled,
2066
- resting,
2067
- touchSoundDisabled
2068
- ]));
2069
- const registry = useStyleRegistry();
2070
- const previous = useRef({
2071
- disabled,
2072
- resting
2073
- });
2074
- useEffect(() => {
2075
- if (previous.current.disabled === disabled && previous.current.resting === resting) return;
2076
- previous.current = {
2077
- disabled,
2078
- resting
2079
- };
2080
- fadeTo(resting, 250, true);
2081
- }, [
2082
- disabled,
2083
- fadeTo,
2084
- resting
2085
- ]);
2086
- useEffect(() => () => {
2087
- animation.current?.cancel();
2088
- }, []);
2089
- const view = useViewElement({
2090
- ...rest,
2091
- ...mergeHandlers(rest, handlers),
2092
- ref: element,
2093
- focusable: focusable !== false && onPress !== void 0 && disabled !== true,
2094
- style: [style, rejectResponderTermination === true && notCancelableStyle$2],
2095
- children,
2096
- ...resolvedDisabled === true && { "aria-disabled": true }
2097
- }, hitSlopClass(registry, hitSlop));
2098
- useImperativeHandle(ref, () => element.current, []);
2099
- return view;
2100
- }
2101
- // src/components/Button/index.tsx
2102
- function Button(props) {
2103
- const { accessibilityActions: _accessibilityActions, accessibilityLanguage, accessibilityState, "aria-disabled": ariaDisabled, color, importantForAccessibility, onAccessibilityAction: _onAccessibilityAction, title, ...rest } = props;
2104
- if (typeof title !== "string") throw new Error("The title prop of a Button must be a string");
2105
- const disabled = props.disabled ?? ariaDisabled ?? accessibilityState?.disabled;
2106
- const state = disabled === accessibilityState?.disabled ? accessibilityState : {
2107
- ...accessibilityState,
2108
- disabled
2109
- };
2110
- return /* @__PURE__ */ jsx(TouchableOpacity, {
2111
- ...rest,
2112
- ...accessibilityLanguage !== void 0 && { lang: accessibilityLanguage },
2113
- role: "button",
2114
- accessibilityState: state,
2115
- disabled,
2116
- importantForAccessibility: importantForAccessibility === "no" ? "no-hide-descendants" : importantForAccessibility,
2117
- style: [
2118
- styles$3.button,
2119
- color != null && color !== "" && { backgroundColor: color },
2120
- disabled === true && styles$3.buttonDisabled
2121
- ],
2122
- children: /* @__PURE__ */ jsx(Text, {
2123
- style: [styles$3.text, disabled === true && styles$3.textDisabled],
2124
- children: title
2125
- })
2126
- });
2127
- }
2128
- const styles$3 = StyleSheet.create({
2129
- button: {
2130
- backgroundColor: "#2196F3",
2131
- borderRadius: 2
2132
- },
2133
- text: {
2134
- color: "white",
2135
- fontWeight: "500",
2136
- margin: 8,
2137
- textAlign: "center"
2138
- },
2139
- buttonDisabled: { backgroundColor: "#dfdfdf" },
2140
- textDisabled: { color: "#a1a1a1" }
2141
- });
2142
- const DRAG_RATE = .5;
2143
- /**
2144
- * The distance of the indicator for a finger distance. It follows the finger at half the speed,
2145
- * and slows down past the target, so it never goes past twice the target.
2146
- */
2147
- const pullOffset = (distance) => {
2148
- const travel = Math.max(0, distance) * DRAG_RATE;
2149
- if (travel <= 64) return travel;
2150
- const extra = travel - 64;
2151
- return 64 + 64 * extra / (extra + 64);
2152
- };
2153
- /** A release after this finger distance refreshes. */
2154
- const releasesRefresh = (distance) => distance * DRAG_RATE > 64;
2155
- // src/components/RefreshControl/index.tsx
2156
- const ARC = "#000000";
2157
- const DISC = "#FFFFFF";
2158
- const ARC_LENGTH = 2 * Math.PI * 8.75;
2159
- const INDICATOR_CLASS = "rn-refresh";
2160
- const RULES$2 = [
2161
- "@keyframes rn-refresh-spin{to{transform:rotate(360deg)}}",
2162
- `.${INDICATOR_CLASS}{position:absolute;top:0;left:50%;z-index:1;display:flex;width:40px;height:40px;margin-left:-20px;border-radius:50%;box-shadow:0 1px 4px rgba(0,0,0,.3);pointer-events:none;opacity:0;transform:translateY(calc(var(--rn-refresh-top) - 100%));transition:transform .2s ease-out,opacity .2s}`,
2163
- `.${INDICATOR_CLASS}[data-size=large]{width:56px;height:56px;margin-left:-28px}`,
2164
- `.${INDICATOR_CLASS}[data-refreshing]{opacity:1;transform:translateY(calc(var(--rn-refresh-top) + 64px - 100%))}`,
2165
- `.${INDICATOR_CLASS}>svg{width:100%;height:100%}`,
2166
- `.${INDICATOR_CLASS}[data-refreshing]>svg{animation:rn-refresh-spin .75s linear infinite}`,
2167
- `.${INDICATOR_CLASS} circle{stroke-dasharray:0 ${ARC_LENGTH}}`,
2168
- `.${INDICATOR_CLASS}[data-refreshing] circle{stroke-dasharray:${ARC_LENGTH * .75} ${ARC_LENGTH}}`,
2169
- `@media (prefers-reduced-motion:reduce){.${INDICATOR_CLASS}{transition:none}}`
2170
- ];
2171
- const frameOf = (element) => {
2172
- let toScreen = new DOMMatrix();
2173
- for (let node = element; node !== null; node = node.parentElement) {
2174
- const { transform } = getComputedStyle(node);
2175
- if (transform !== "none") toScreen = new DOMMatrix(transform).multiply(toScreen);
2176
- }
2177
- return toScreen.inverse();
2178
- };
2179
- function RefreshControl(props) {
2180
- const { children, colors, enabled = true, onRefresh, progressBackgroundColor, progressViewOffset = 0, refreshing, size = "default", style, tintColor, title, titleColor: _titleColor, ...rest } = props;
2181
- const indicatorClass = useStyleRegistry().staticClass(INDICATOR_CLASS, RULES$2);
2182
- const indicator = useRef(null);
2183
- const latest = useRef({
2184
- enabled,
2185
- refreshing,
2186
- onRefresh
2187
- });
2188
- useLayoutEffect(() => {
2189
- latest.current = {
2190
- enabled,
2191
- refreshing,
2192
- onRefresh
2193
- };
2194
- });
2195
- useEffect(() => {
2196
- const element = indicator.current;
2197
- const area = element?.parentElement;
2198
- if (!element || !area) return;
2199
- const svg = element.firstElementChild;
2200
- const arc = svg.firstElementChild;
2201
- let gesture = null;
2202
- let releaseTimer;
2203
- const scrollTop = () => {
2204
- const scroller = area.firstElementChild;
2205
- return scroller instanceof HTMLElement && scroller !== element ? scroller.scrollTop : 0;
2206
- };
2207
- const draw = (distance) => {
2208
- const offset = pullOffset(distance);
2209
- const progress = Math.min(1, offset / 64);
2210
- element.style.transition = "none";
2211
- element.style.opacity = String(Math.min(1, offset / element.offsetHeight));
2212
- element.style.transform = `translateY(calc(var(--rn-refresh-top) + ${offset}px - 100%))`;
2213
- svg.style.transform = `rotate(${progress * 270}deg)`;
2214
- arc.style.strokeDasharray = `${progress * .8 * ARC_LENGTH} ${ARC_LENGTH}`;
2215
- };
2216
- const clear = () => {
2217
- element.style.transition = "";
2218
- element.style.opacity = "";
2219
- element.style.transform = "";
2220
- svg.style.transform = "";
2221
- arc.style.strokeDasharray = "";
2222
- };
2223
- const touchOf = (event) => Array.from(event.changedTouches).find((touch) => touch.identifier === gesture?.id);
2224
- const onStart = (event) => {
2225
- const touch = event.touches[0];
2226
- const { enabled: on, refreshing: busy } = latest.current;
2227
- gesture = event.touches.length === 1 && touch !== void 0 && on && !busy && scrollTop() <= 0 ? {
2228
- id: touch.identifier,
2229
- x: touch.clientX,
2230
- y: touch.clientY,
2231
- pulling: false,
2232
- distance: 0,
2233
- toLocal: frameOf(area)
2234
- } : null;
2235
- };
2236
- const onMove = (event) => {
2237
- const touch = touchOf(event);
2238
- if (gesture === null || touch === void 0) return;
2239
- const { a, b, c, d } = gesture.toLocal;
2240
- const screenX = touch.clientX - gesture.x;
2241
- const screenY = touch.clientY - gesture.y;
2242
- const dx = a * screenX + c * screenY;
2243
- const dy = b * screenX + d * screenY;
2244
- if (!gesture.pulling) {
2245
- if (dx === 0 && dy === 0) return;
2246
- if (dy <= 0 || Math.abs(dx) > dy || scrollTop() > 0 || !event.cancelable) {
2247
- gesture = null;
2248
- return;
2249
- }
2250
- gesture.pulling = true;
2251
- }
2252
- event.preventDefault();
2253
- gesture.distance = Math.max(0, dy);
2254
- draw(gesture.distance);
2255
- };
2256
- const onEnd = (event) => {
2257
- if (gesture === null || touchOf(event) === void 0) return;
2258
- const { pulling, distance } = gesture;
2259
- gesture = null;
2260
- if (!pulling) return;
2261
- const refresh = event.type === "touchend" && releasesRefresh(distance);
2262
- if (refresh) element.setAttribute("data-refreshing", "");
2263
- clear();
2264
- if (!refresh) return;
2265
- latest.current.onRefresh?.();
2266
- releaseTimer = setTimeout(() => {
2267
- if (!latest.current.refreshing) element.removeAttribute("data-refreshing");
2268
- }, 0);
2269
- };
2270
- area.addEventListener("touchstart", onStart, { passive: true });
2271
- area.addEventListener("touchmove", onMove, { passive: false });
2272
- area.addEventListener("touchend", onEnd);
2273
- area.addEventListener("touchcancel", onEnd);
2274
- return () => {
2275
- area.removeEventListener("touchstart", onStart);
2276
- area.removeEventListener("touchmove", onMove);
2277
- area.removeEventListener("touchend", onEnd);
2278
- area.removeEventListener("touchcancel", onEnd);
2279
- clearTimeout(releaseTimer);
2280
- clear();
2281
- };
2282
- }, []);
2283
- const indicatorStyle = {
2284
- "--rn-refresh-top": `${progressViewOffset}px`,
2285
- backgroundColor: toCSSColor(progressBackgroundColor) ?? DISC
2286
- };
2287
- const arcColor = toCSSColor(colors?.[0]) ?? toCSSColor(tintColor) ?? ARC;
2288
- return /* @__PURE__ */ jsxs(View, {
2289
- ...rest,
2290
- "aria-busy": refreshing,
2291
- style: [styles$2.area, style],
2292
- children: [children, /* @__PURE__ */ jsx("div", {
2293
- ref: indicator,
2294
- "aria-hidden": !refreshing,
2295
- "aria-label": title,
2296
- className: indicatorClass,
2297
- "data-refreshing": refreshing ? "" : void 0,
2298
- "data-size": size === "large" ? "large" : void 0,
2299
- role: "progressbar",
2300
- style: indicatorStyle,
2301
- children: /* @__PURE__ */ jsx("svg", {
2302
- "aria-hidden": true,
2303
- viewBox: "0 0 40 40",
2304
- children: /* @__PURE__ */ jsx("circle", {
2305
- cx: "20",
2306
- cy: "20",
2307
- fill: "none",
2308
- r: "8.75",
2309
- stroke: arcColor,
2310
- strokeLinecap: "round",
2311
- strokeWidth: "2.5"
2312
- })
2313
- })
2314
- })]
2315
- });
2316
- }
2317
- const styles$2 = StyleSheet.create({ area: {
2318
- position: "relative",
2319
- overflow: "hidden"
2320
- } });
2321
- // src/style/splitLayoutProps.ts
2322
- const OUTER = /* @__PURE__ */ new Set([
2323
- "margin",
2324
- "marginHorizontal",
2325
- "marginVertical",
2326
- "marginBottom",
2327
- "marginTop",
2328
- "marginLeft",
2329
- "marginRight",
2330
- "flex",
2331
- "flexGrow",
2332
- "flexShrink",
2333
- "flexBasis",
2334
- "alignSelf",
2335
- "height",
2336
- "minHeight",
2337
- "maxHeight",
2338
- "width",
2339
- "minWidth",
2340
- "maxWidth",
2341
- "position",
2342
- "left",
2343
- "right",
2344
- "bottom",
2345
- "top",
2346
- "transform",
2347
- "transformOrigin",
2348
- "rowGap",
2349
- "columnGap",
2350
- "gap"
2351
- ]);
2352
- /**
2353
- * Splits a flat style in two, as React Native's `splitLayoutProps` does: `outer` places the box,
2354
- * `inner` is the rest. A wrapper takes `outer` and the wrapped box takes `inner`.
2355
- */
2356
- const splitLayoutProps = (style) => {
2357
- const outer = {};
2358
- const inner = {};
2359
- if (style == null) return {
2360
- outer,
2361
- inner
2362
- };
2363
- for (const [prop, value] of Object.entries(style)) if (OUTER.has(prop)) outer[prop] = value;
2364
- else inner[prop] = value;
2365
- return {
2366
- outer,
2367
- inner
2368
- };
2369
- };
2370
- // src/components/ScrollView/snap.ts
2371
- const nearest = (offset, candidates) => {
2372
- let best;
2373
- let distance = Infinity;
2374
- for (const candidate of candidates) {
2375
- const d = Math.abs(candidate - offset);
2376
- if (d < distance) {
2377
- distance = d;
2378
- best = candidate;
2379
- }
2380
- }
2381
- return best;
2382
- };
2383
- const snapTarget = (offset, viewport, contentSize, config) => {
2384
- const max = Math.max(0, contentSize - viewport);
2385
- let target;
2386
- if (config.offsets !== void 0) {
2387
- if (config.offsets.length === 0) return void 0;
2388
- const first = Math.min(...config.offsets);
2389
- const last = Math.max(...config.offsets);
2390
- if (!config.snapToStart && offset < first) return void 0;
2391
- if (!config.snapToEnd && offset > last) return void 0;
2392
- const candidates = [...config.offsets];
2393
- if (config.snapToStart) candidates.push(0);
2394
- if (config.snapToEnd) candidates.push(max);
2395
- target = nearest(offset, candidates);
2396
- } else if (config.interval !== void 0 && config.interval > 0) {
2397
- const { interval, alignment } = config;
2398
- const shift = alignment === "center" ? (viewport - interval) / 2 : alignment === "end" ? viewport - interval : 0;
2399
- target = Math.round((offset + shift) / interval) * interval - shift;
2400
- }
2401
- if (target === void 0) return void 0;
2402
- target = Math.min(max, Math.max(0, target));
2403
- return Math.abs(target - offset) < .5 ? void 0 : target;
2404
- };
2405
- // src/components/ScrollView/index.tsx
2406
- const scrollerStyle = webStyle({
2407
- flexGrow: 1,
2408
- flexShrink: 1,
2409
- overflowX: "hidden",
2410
- overflowY: "auto",
2411
- WebkitOverflowScrolling: "touch"
2412
- });
2413
- const horizontalScrollerStyle = webStyle({
2414
- flexDirection: "row",
2415
- overflowX: "auto",
2416
- overflowY: "hidden"
2417
- });
2418
- const disabledScrollerStyle = webStyle({
2419
- overflowX: "hidden",
2420
- overflowY: "hidden"
2421
- });
2422
- const refreshAreaStyle = Object.freeze({
2423
- flexGrow: 1,
2424
- flexShrink: 1
2425
- });
2426
- const horizontalContentStyle = Object.freeze({ flexDirection: "row" });
2427
- const centerContentStyle = Object.freeze({
2428
- flexGrow: 1,
2429
- justifyContent: "center"
2430
- });
2431
- const stickyStyle = webStyle({
2432
- position: "sticky",
2433
- top: 0,
2434
- zIndex: 10
2435
- });
2436
- const invertedStickyStyle = webStyle({
2437
- position: "sticky",
2438
- bottom: 0,
2439
- zIndex: 10
2440
- });
2441
- const hiddenScrollbarClass = (registry) => registry.staticClass("rn-scrollbar-none", [".rn-scrollbar-none{scrollbar-width:none;-ms-overflow-style:none}", ".rn-scrollbar-none::-webkit-scrollbar{display:none}"]);
2442
- const supportsScrollEnd = hasDOM() && "onscrollend" in window;
2443
- const SCROLL_END_DELAY = 150;
2444
- const behaviorFor = (animated) => animated !== false && !Platform.isDisableAnimations ? "smooth" : "auto";
2445
- const describe = (element) => ({
2446
- contentInset: {
2447
- top: 0,
2448
- left: 0,
2449
- bottom: 0,
2450
- right: 0
2451
- },
2452
- contentOffset: {
2453
- x: element.scrollLeft,
2454
- y: element.scrollTop
2455
- },
2456
- contentSize: {
2457
- width: element.scrollWidth,
2458
- height: element.scrollHeight
2459
- },
2460
- layoutMeasurement: {
2461
- width: element.clientWidth,
2462
- height: element.clientHeight
2463
- },
2464
- zoomScale: 1
2465
- });
2466
- const isReactNativeScrollTo = (value) => typeof value === "object" && value !== null && ("x" in value || "y" in value || "animated" in value);
2467
- const domScrollTo = (element, options) => {
2468
- const init = { behavior: behaviorFor(options.animated) };
2469
- if (options.x !== void 0) init.left = options.x;
2470
- if (options.y !== void 0) init.top = options.y;
2471
- element.scrollTo(init);
2472
- };
2473
- function ScrollView(props) {
2474
- const { centerContent, children, contentContainerStyle, contentOffset, horizontal = false, invertStickyHeaders, keyboardDismissMode, onContentSizeChange, onMomentumScrollBegin, onMomentumScrollEnd, onPointerDown, onScroll, onScrollBeginDrag, onScrollEndDrag, pagingEnabled, ref, refreshControl, scrollEnabled = true, showsHorizontalScrollIndicator = true, showsVerticalScrollIndicator = true, snapToAlignment = "start", snapToEnd = true, snapToInterval, snapToOffsets, snapToStart = true, stickyHeaderHiddenOnScroll, stickyHeaderIndices, style, alwaysBounceHorizontal: _alwaysBounceHorizontal, alwaysBounceVertical: _alwaysBounceVertical, automaticallyAdjustContentInsets: _automaticallyAdjustContentInsets, automaticallyAdjustKeyboardInsets: _automaticallyAdjustKeyboardInsets, automaticallyAdjustsScrollIndicatorInsets: _automaticallyAdjustsScrollIndicatorInsets, bounces: _bounces, bouncesZoom: _bouncesZoom, canCancelContentTouches: _canCancelContentTouches, contentInset: _contentInset, contentInsetAdjustmentBehavior: _contentInsetAdjustmentBehavior, decelerationRate: _decelerationRate, directionalLockEnabled: _directionalLockEnabled, disableIntervalMomentum: _disableIntervalMomentum, disableScrollViewPanResponder: _disableScrollViewPanResponder, endFillColor: _endFillColor, fadingEdgeLength: _fadingEdgeLength, indicatorStyle: _indicatorStyle, keyboardShouldPersistTaps: _keyboardShouldPersistTaps, maintainVisibleContentPosition: _maintainVisibleContentPosition, maximumZoomScale: _maximumZoomScale, minimumZoomScale: _minimumZoomScale, nestedScrollEnabled: _nestedScrollEnabled, onScrollToTop: _onScrollToTop, overScrollMode: _overScrollMode, persistentScrollbar: _persistentScrollbar, pinchGestureEnabled: _pinchGestureEnabled, removeClippedSubviews: _removeClippedSubviews, scrollEventThrottle: _scrollEventThrottle, scrollIndicatorInsets: _scrollIndicatorInsets, scrollPerfTag: _scrollPerfTag, scrollToOverflowEnabled: _scrollToOverflowEnabled, scrollsToTop: _scrollsToTop, snapToIntervalMomentum: _snapToIntervalMomentum, zoomScale: _zoomScale, ...rest } = props;
2475
- const registry = useStyleRegistry();
2476
- const scroller = useRef(null);
2477
- const content = useRef(null);
2478
- const handlers = useRef({});
2479
- useEffect(() => {
2480
- handlers.current = {
2481
- onScroll,
2482
- onScrollBeginDrag,
2483
- onScrollEndDrag,
2484
- onMomentumScrollBegin,
2485
- onMomentumScrollEnd
2486
- };
2487
- });
2488
- const snap = useRef({
2489
- horizontal,
2490
- pagingEnabled: pagingEnabled === true,
2491
- snapToInterval,
2492
- snapToOffsets,
2493
- snapToAlignment,
2494
- snapToStart,
2495
- snapToEnd,
2496
- keyboardDismissMode,
2497
- stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
2498
- });
2499
- useEffect(() => {
2500
- snap.current = {
2501
- horizontal,
2502
- pagingEnabled: pagingEnabled === true,
2503
- snapToInterval,
2504
- snapToOffsets,
2505
- snapToAlignment,
2506
- snapToStart,
2507
- snapToEnd,
2508
- keyboardDismissMode,
2509
- stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
2510
- };
2511
- });
2512
- const sequence = useRef({
2513
- phase: "idle",
2514
- pointerDown: false,
2515
- lastEvent: null,
2516
- lastOffset: 0,
2517
- timer: void 0,
2518
- snapping: false
2519
- });
2520
- const stickyHeaders = useRef([]);
2521
- const refreshEvent = useCallback(() => {
2522
- const state = sequence.current;
2523
- const element = scroller.current;
2524
- if (state.lastEvent === null || element === null) return null;
2525
- Object.assign(state.lastEvent.nativeEvent, describe(element));
2526
- return state.lastEvent;
2527
- }, []);
2528
- const settle = useCallback(() => {
2529
- const state = sequence.current;
2530
- const element = scroller.current;
2531
- if (element === null) return;
2532
- if (state.pointerDown && state.phase === "drag") return;
2533
- if (state.phase === "momentum") {
2534
- const event = refreshEvent();
2535
- if (event !== null) handlers.current.onMomentumScrollEnd?.(event);
2536
- }
2537
- state.phase = "idle";
2538
- if (state.snapping) {
2539
- state.snapping = false;
2540
- return;
2541
- }
2542
- const config = snap.current;
2543
- const axis = config.horizontal;
2544
- const viewport = axis ? element.clientWidth : element.clientHeight;
2545
- const target = snapTarget(axis ? element.scrollLeft : element.scrollTop, viewport, axis ? element.scrollWidth : element.scrollHeight, {
2546
- offsets: config.snapToOffsets,
2547
- interval: config.pagingEnabled ? viewport : config.snapToInterval,
2548
- alignment: config.snapToAlignment,
2549
- snapToStart: config.snapToStart,
2550
- snapToEnd: config.snapToEnd
2551
- });
2552
- if (target === void 0) return;
2553
- state.snapping = true;
2554
- domScrollTo(element, axis ? { x: target } : { y: target });
2555
- }, [refreshEvent]);
2556
- const handleScroll = (event) => {
2557
- const element = event.currentTarget;
2558
- if (event.target !== element) return;
2559
- const state = sequence.current;
2560
- const scrollEvent = event;
2561
- Object.assign(scrollEvent.nativeEvent, describe(element));
2562
- state.lastEvent = scrollEvent;
2563
- const config = snap.current;
2564
- const offset = config.horizontal ? element.scrollLeft : element.scrollTop;
2565
- const delta = offset - state.lastOffset;
2566
- state.lastOffset = offset;
2567
- if (state.phase === "idle") {
2568
- if (state.pointerDown) {
2569
- state.phase = "drag";
2570
- handlers.current.onScrollBeginDrag?.(scrollEvent);
2571
- if (config.keyboardDismissMode === "on-drag") {
2572
- const active = document.activeElement;
2573
- if (active instanceof HTMLElement && active !== document.body) active.blur();
2574
- }
2575
- } else {
2576
- state.phase = "momentum";
2577
- handlers.current.onMomentumScrollBegin?.(scrollEvent);
2578
- }
2579
- } else if (state.phase === "released") {
2580
- state.phase = "momentum";
2581
- handlers.current.onMomentumScrollBegin?.(scrollEvent);
2582
- }
2583
- if (config.stickyHeaderHiddenOnScroll && !config.horizontal && delta !== 0) {
2584
- const hidden = delta > 0;
2585
- for (const header of stickyHeaders.current) {
2586
- header.style.transition = "transform 150ms";
2587
- header.style.transform = hidden ? "translateY(-100%)" : "";
2588
- }
2589
- }
2590
- handlers.current.onScroll?.(scrollEvent);
2591
- if (!supportsScrollEnd) {
2592
- if (state.timer !== void 0) clearTimeout(state.timer);
2593
- state.timer = setTimeout(settle, SCROLL_END_DELAY);
2594
- }
2595
- };
2596
- const handleScrollEnd = (event) => {
2597
- if (event.target !== event.currentTarget) return;
2598
- settle();
2599
- };
2600
- const handlePointerDown = (event) => {
2601
- onPointerDown?.(event);
2602
- const state = sequence.current;
2603
- if (state.pointerDown) return;
2604
- state.pointerDown = true;
2605
- const release = () => {
2606
- window.removeEventListener("pointerup", release);
2607
- window.removeEventListener("pointercancel", release);
2608
- state.pointerDown = false;
2609
- if (state.phase === "drag") {
2610
- state.phase = "released";
2611
- const scrollEvent = refreshEvent();
2612
- if (scrollEvent !== null) handlers.current.onScrollEndDrag?.(scrollEvent);
2613
- }
2614
- };
2615
- window.addEventListener("pointerup", release);
2616
- window.addEventListener("pointercancel", release);
2617
- };
2618
- useEffect(() => {
2619
- const state = sequence.current;
2620
- return () => {
2621
- if (state.timer !== void 0) clearTimeout(state.timer);
2622
- };
2623
- }, []);
2624
- const onContentLayout = onContentSizeChange === void 0 ? void 0 : (event) => onContentSizeChange(event.nativeEvent.layout.width, event.nativeEvent.layout.height);
2625
- const stickySet = stickyHeaderIndices !== void 0 && stickyHeaderIndices.length > 0 && !horizontal ? new Set(stickyHeaderIndices) : void 0;
2626
- const setStickyHeader = useCallback((node) => {
2627
- const list = stickyHeaders.current;
2628
- if (node === null) return;
2629
- if (!list.includes(node)) list.push(node);
2630
- return () => {
2631
- const index = list.indexOf(node);
2632
- if (index !== -1) list.splice(index, 1);
2633
- };
2634
- }, []);
2635
- let items = children;
2636
- if (stickySet !== void 0) items = Children.toArray(children).map((child, index) => stickySet.has(index) ? /* @__PURE__ */ jsx(View, {
2637
- ref: setStickyHeader,
2638
- style: invertStickyHeaders === true ? invertedStickyStyle : stickyStyle,
2639
- children: child
2640
- }, isValidElement(child) && child.key !== null ? child.key : `sticky-${index}`) : child);
2641
- const contentElement = /* @__PURE__ */ jsx(View, {
2642
- ref: content,
2643
- onLayout: onContentLayout,
2644
- style: [
2645
- horizontal && horizontalContentStyle,
2646
- centerContent === true && centerContentStyle,
2647
- contentContainerStyle
2648
- ],
2649
- children: items
2650
- });
2651
- const hideScrollbar = horizontal ? !showsHorizontalScrollIndicator : !showsVerticalScrollIndicator;
2652
- const split = refreshControl === void 0 ? void 0 : splitLayoutProps(StyleSheet.flatten(style));
2653
- const scrollerElement = useViewElement({
2654
- ...rest,
2655
- ref: scroller,
2656
- style: [
2657
- scrollerStyle,
2658
- horizontal && horizontalScrollerStyle,
2659
- !scrollEnabled && disabledScrollerStyle,
2660
- split === void 0 ? style : split.inner
2661
- ],
2662
- onScroll: handleScroll,
2663
- onScrollEnd: handleScrollEnd,
2664
- onPointerDown: handlePointerDown,
2665
- children: contentElement
2666
- }, hideScrollbar ? hiddenScrollbarClass(registry) : void 0);
2667
- const offsetX = contentOffset?.x;
2668
- const offsetY = contentOffset?.y;
2669
- useLayoutEffect(() => {
2670
- const element = scroller.current;
2671
- if (element === null || offsetX === void 0 && offsetY === void 0) return;
2672
- if (offsetX !== void 0) element.scrollLeft = offsetX;
2673
- if (offsetY !== void 0) element.scrollTop = offsetY;
2674
- sequence.current.lastOffset = horizontal ? element.scrollLeft : element.scrollTop;
2675
- }, [
2676
- offsetX,
2677
- offsetY,
2678
- horizontal
2679
- ]);
2680
- useImperativeHandle(ref, () => {
2681
- const element = scroller.current;
2682
- const nativeScrollTo = element.scrollTo.bind(element);
2683
- const instance = element;
2684
- return Object.assign(instance, {
2685
- scrollTo: ((first, second) => {
2686
- if (isReactNativeScrollTo(first)) domScrollTo(element, first);
2687
- else if (typeof first === "number" && typeof second === "number") nativeScrollTo(first, second);
2688
- else nativeScrollTo(first);
2689
- }),
2690
- scrollToEnd: (options) => {
2691
- const animated = options?.animated;
2692
- domScrollTo(element, horizontal ? {
2693
- x: element.scrollWidth,
2694
- animated
2695
- } : {
2696
- y: element.scrollHeight,
2697
- animated
2698
- });
2699
- },
2700
- flashScrollIndicators: () => {},
2701
- getScrollResponder: () => instance,
2702
- getScrollableNode: () => element,
2703
- getInnerViewNode: () => content.current,
2704
- getInnerViewRef: () => content.current,
2705
- getNativeScrollRef: () => element
2706
- });
2707
- }, [horizontal]);
2708
- return refreshControl === void 0 || split === void 0 ? scrollerElement : cloneElement(refreshControl, { style: [refreshAreaStyle, split.outer] }, scrollerElement);
2709
- }
2710
- // src/components/FlatList/viewability.ts
2711
- const pixelsVisible = (top, bottom, viewport) => Math.max(0, Math.min(bottom, viewport) - Math.max(top, 0));
2712
- const isEntirelyVisible = (top, bottom, viewport) => top >= 0 && bottom <= viewport && bottom > top;
2713
- const isViewable = (viewAreaMode, threshold, top, bottom, viewport, length) => {
2714
- if (isEntirelyVisible(top, bottom, viewport)) return true;
2715
- const pixels = pixelsVisible(top, bottom, viewport);
2716
- return 100 * (viewAreaMode ? pixels / viewport : pixels / length) >= threshold;
2717
- };
2718
- const computeViewableIndices = (itemCount, metricsAt, scrollOffset, viewport, config) => {
2719
- const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = config;
2720
- const viewAreaMode = viewAreaCoveragePercentThreshold != null;
2721
- const threshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
2722
- if (threshold == null || viewAreaMode === (itemVisiblePercentThreshold != null)) throw new Error("Must set exactly one of itemVisiblePercentThreshold or viewAreaCoveragePercentThreshold");
2723
- const viewable = [];
2724
- let firstVisible = -1;
2725
- for (let index = 0; index < itemCount; index++) {
2726
- const metrics = metricsAt(index);
2727
- if (metrics === void 0) continue;
2728
- const top = Math.floor(metrics.offset - scrollOffset);
2729
- const bottom = Math.floor(top + metrics.length);
2730
- if (top < viewport && bottom > 0) {
2731
- firstVisible = index;
2732
- if (isViewable(viewAreaMode, threshold, top, bottom, viewport, metrics.length)) viewable.push(index);
2733
- } else if (firstVisible >= 0) break;
2734
- }
2735
- return viewable;
2736
- };
2737
- const sameIndices = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
2738
- var ViewabilityTracker = class {
2739
- constructor(config = { viewAreaCoveragePercentThreshold: 0 }) {
2740
- this.interacted = false;
2741
- this.timers = /* @__PURE__ */ new Set();
2742
- this.viewableIndices = [];
2743
- this.viewableItems = /* @__PURE__ */ new Map();
2744
- this.config = config;
2745
- }
2746
- dispose() {
2747
- for (const timer of this.timers) clearTimeout(timer);
2748
- this.timers.clear();
2749
- }
2750
- recordInteraction() {
2751
- this.interacted = true;
2752
- }
2753
- resetViewableIndices() {
2754
- this.viewableIndices = [];
2755
- }
2756
- onUpdate(itemCount, metricsAt, scrollOffset, viewport, createViewToken, onViewableItemsChanged) {
2757
- if (this.config.waitForInteraction === true && !this.interacted || itemCount === 0) return;
2758
- if (metricsAt(0) === void 0) return;
2759
- const next = computeViewableIndices(itemCount, metricsAt, scrollOffset, viewport, this.config);
2760
- if (sameIndices(this.viewableIndices, next)) return;
2761
- this.viewableIndices = next;
2762
- const { minimumViewTime } = this.config;
2763
- if (minimumViewTime !== void 0 && minimumViewTime > 0) {
2764
- const timer = setTimeout(() => {
2765
- this.timers.delete(timer);
2766
- if (this.viewableIndices !== next) return;
2767
- this.report(next, createViewToken, onViewableItemsChanged);
2768
- }, minimumViewTime);
2769
- this.timers.add(timer);
2770
- } else this.report(next, createViewToken, onViewableItemsChanged);
2771
- }
2772
- report(indices, createViewToken, onViewableItemsChanged) {
2773
- const previous = this.viewableItems;
2774
- const next = /* @__PURE__ */ new Map();
2775
- for (const index of indices) {
2776
- const token = createViewToken(index, true);
2777
- next.set(token.key, token);
2778
- }
2779
- const changed = [];
2780
- for (const [key, token] of next) if (!previous.has(key)) changed.push(token);
2781
- for (const [key, token] of previous) if (!next.has(key)) changed.push({
2782
- ...token,
2783
- isViewable: false
2784
- });
2785
- if (changed.length === 0) return;
2786
- this.viewableItems = next;
2787
- onViewableItemsChanged({
2788
- viewableItems: Array.from(next.values()),
2789
- changed
2790
- });
2791
- }
2792
- };
2793
- // src/components/FlatList/index.tsx
2794
- const rowStyle = Object.freeze({ flexDirection: "row" });
2795
- const rowReverseStyle = Object.freeze({ flexDirection: "row-reverse" });
2796
- const columnReverseStyle = Object.freeze({ flexDirection: "column-reverse" });
2797
- const verticallyInvertedStyle = Object.freeze({ transform: [{ scaleY: -1 }] });
2798
- const horizontallyInvertedStyle = Object.freeze({ transform: [{ scaleX: -1 }] });
2799
- const ON_EDGE_REACHED_EPSILON = .001;
2800
- const DEFAULT_EDGE_THRESHOLD_PX = 2;
2801
- const defaultKeyExtractor = (item, index) => {
2802
- if (typeof item === "object" && item !== null) {
2803
- const record = item;
2804
- if (record.key != null) return String(record.key);
2805
- if (record.id != null) return String(record.id);
2806
- }
2807
- return String(index);
2808
- };
2809
- const isArrayLike = (data) => data != null && typeof data.length === "number";
2810
- const renderListComponent = (component) => {
2811
- if (component == null) return null;
2812
- if (isValidElement(component)) return component;
2813
- return /* @__PURE__ */ jsx(component, {});
2814
- };
2815
- function CustomScroller({ render, ref, ...props }) {
2816
- return cloneElement(render(props), { ref }, props.children);
2817
- }
2818
- function Cell(props) {
2819
- const { cellKey, prevCellKey, index, item, style, renderCell, ItemSeparatorComponent, CellRendererComponent, separatorUpdaters, onElement } = props;
2820
- const [separatorProps, setSeparatorProps] = useState({
2821
- highlighted: false,
2822
- leadingItem: item
2823
- });
2824
- const shown = separatorProps.leadingItem === item ? separatorProps : {
2825
- ...separatorProps,
2826
- leadingItem: item
2827
- };
2828
- useEffect(() => {
2829
- separatorUpdaters.set(cellKey, (next) => {
2830
- setSeparatorProps((current) => ({
2831
- ...current,
2832
- ...next
2833
- }));
2834
- });
2835
- return () => {
2836
- separatorUpdaters.delete(cellKey);
2837
- };
2838
- }, [cellKey, separatorUpdaters]);
2839
- const separators = useMemo(() => {
2840
- const update = (keys, next) => {
2841
- for (const key of keys) if (key !== void 0) separatorUpdaters.get(key)?.(next);
2842
- };
2843
- return {
2844
- highlight: () => update([cellKey, prevCellKey], { highlighted: true }),
2845
- unhighlight: () => update([cellKey, prevCellKey], { highlighted: false }),
2846
- updateProps: (select, next) => update([select === "leading" ? prevCellKey : cellKey], next)
2847
- };
2848
- }, [
2849
- cellKey,
2850
- prevCellKey,
2851
- separatorUpdaters
2852
- ]);
2853
- const setElement = useCallback((node) => {
2854
- if (node === null) return;
2855
- onElement(index, node);
2856
- return () => onElement(index, null);
2857
- }, [index, onElement]);
2858
- let separator = null;
2859
- if (ItemSeparatorComponent != null) {
2860
- if (isValidElement(ItemSeparatorComponent)) separator = ItemSeparatorComponent;
2861
- else separator = /* @__PURE__ */ jsx(ItemSeparatorComponent, { ...shown });
2862
- }
2863
- const element = renderCell(item, index, separators);
2864
- if (CellRendererComponent != null) return /* @__PURE__ */ jsx(View, {
2865
- ref: setElement,
2866
- children: /* @__PURE__ */ jsxs(CellRendererComponent, {
2867
- cellKey,
2868
- index,
2869
- item,
2870
- style,
2871
- children: [element, separator]
2872
- })
2873
- });
2874
- return /* @__PURE__ */ jsxs(View, {
2875
- ref: setElement,
2876
- style,
2877
- children: [element, separator]
2878
- });
2879
- }
2880
- const createTrackers = (props) => {
2881
- if (props.viewabilityConfigCallbackPairs !== void 0) return props.viewabilityConfigCallbackPairs.map((pair) => ({
2882
- tracker: new ViewabilityTracker(pair.viewabilityConfig),
2883
- callback: () => pair.onViewableItemsChanged
2884
- }));
2885
- if (props.onViewableItemsChanged != null) return [{
2886
- tracker: new ViewabilityTracker(props.viewabilityConfig),
2887
- callback: (latest) => latest.onViewableItemsChanged
2888
- }];
2889
- return [];
2890
- };
2891
- function FlatList(props) {
2892
- const { data, renderItem, ListItemComponent, keyExtractor = defaultKeyExtractor, getItemLayout: _getItemLayout, numColumns = 1, columnWrapperStyle, inverted, initialScrollIndex: _initialScrollIndex, ItemSeparatorComponent, ListEmptyComponent, ListHeaderComponent, ListHeaderComponentStyle, ListFooterComponent, ListFooterComponentStyle, CellRendererComponent, renderScrollComponent, horizontal = false, style, ref, onScroll: _onScroll, onContentSizeChange: _onContentSizeChange, onLayout: _onLayout, onEndReached: _onEndReached, onEndReachedThreshold: _onEndReachedThreshold, onStartReached: _onStartReached, onStartReachedThreshold: _onStartReachedThreshold, onViewableItemsChanged: _onViewableItemsChanged, viewabilityConfig: _viewabilityConfig, viewabilityConfigCallbackPairs: _viewabilityConfigCallbackPairs, onScrollToIndexFailed: _onScrollToIndexFailed, onRefresh, refreshing, progressViewOffset, extraData: _extraData, debug: _debug, disableVirtualization: _disableVirtualization, initialNumToRender: _initialNumToRender, maxToRenderPerBatch: _maxToRenderPerBatch, strictMode: _strictMode, updateCellsBatchingPeriod: _updateCellsBatchingPeriod, windowSize: _windowSize, legacyImplementation: _legacyImplementation, ...scrollViewProps } = props;
2893
- if (numColumns > 1 && horizontal) throw new Error("numColumns does not support horizontal.");
2894
- const latest = useRef(props);
2895
- useEffect(() => {
2896
- latest.current = props;
2897
- });
2898
- const scroller = useRef(null);
2899
- const [cells] = useState(() => /* @__PURE__ */ new Map());
2900
- const [separatorUpdaters] = useState(() => /* @__PURE__ */ new Map());
2901
- const [trackers] = useState(() => createTrackers(props));
2902
- const edge = useRef({
2903
- sentEndForContentLength: 0,
2904
- sentStartForContentLength: 0
2905
- });
2906
- useEffect(() => {
2907
- return () => {
2908
- for (const entry of trackers) entry.tracker.dispose();
2909
- };
2910
- }, [trackers]);
2911
- const onElement = useCallback((index, node) => {
2912
- if (node === null) cells.delete(index);
2913
- else cells.set(index, node);
2914
- }, [cells]);
2915
- const items = isArrayLike(data) ? data : [];
2916
- const rowCount = numColumns > 1 ? Math.ceil(items.length / numColumns) : items.length;
2917
- const rowAt = (index) => {
2918
- if (numColumns === 1) return items[index];
2919
- const row = [];
2920
- for (let column = 0; column < numColumns; column++) {
2921
- const itemIndex = index * numColumns + column;
2922
- if (itemIndex < items.length) row.push(items[itemIndex]);
2923
- }
2924
- return row;
2925
- };
2926
- const rowKey = (row, index) => {
2927
- if (numColumns === 1) return keyExtractor(row, index);
2928
- return row.map((item, column) => keyExtractor(item, index * numColumns + column)).join(":");
2929
- };
2930
- const metricsAt = useCallback((index) => {
2931
- const element = cells.get(index);
2932
- const { horizontal: isHorizontal = false, getItemLayout, data: currentData } = latest.current;
2933
- if (element !== void 0) return isHorizontal ? {
2934
- offset: element.offsetLeft,
2935
- length: element.offsetWidth
2936
- } : {
2937
- offset: element.offsetTop,
2938
- length: element.offsetHeight
2939
- };
2940
- const layout = getItemLayout?.(currentData, index);
2941
- return layout === void 0 ? void 0 : {
2942
- offset: layout.offset,
2943
- length: layout.length
2944
- };
2945
- }, [cells]);
2946
- const maybeCallOnEdgeReached = useCallback(() => {
2947
- const element = scroller.current;
2948
- if (element === null) return;
2949
- const { horizontal: isHorizontal = false, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold } = latest.current;
2950
- const visibleLength = isHorizontal ? element.clientWidth : element.clientHeight;
2951
- const contentLength = isHorizontal ? element.scrollWidth : element.scrollHeight;
2952
- if (visibleLength === 0 || contentLength === 0) return;
2953
- const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
2954
- let distanceFromStart = offset;
2955
- let distanceFromEnd = contentLength - visibleLength - offset;
2956
- if (distanceFromStart < ON_EDGE_REACHED_EPSILON) distanceFromStart = 0;
2957
- if (distanceFromEnd < ON_EDGE_REACHED_EPSILON) distanceFromEnd = 0;
2958
- const startThreshold = onStartReachedThreshold != null ? onStartReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
2959
- const endThreshold = onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
2960
- const withinStart = distanceFromStart <= startThreshold;
2961
- const withinEnd = distanceFromEnd <= endThreshold;
2962
- const state = edge.current;
2963
- if (onEndReached != null && withinEnd && contentLength !== state.sentEndForContentLength) {
2964
- state.sentEndForContentLength = contentLength;
2965
- onEndReached({ distanceFromEnd });
2966
- }
2967
- if (onStartReached != null && withinStart && contentLength !== state.sentStartForContentLength) {
2968
- state.sentStartForContentLength = contentLength;
2969
- onStartReached({ distanceFromStart });
2970
- }
2971
- if (!withinStart) state.sentStartForContentLength = 0;
2972
- if (!withinEnd) state.sentEndForContentLength = 0;
2973
- }, []);
2974
- const updateViewability = useCallback(() => {
2975
- const element = scroller.current;
2976
- if (element === null || trackers.length === 0) return;
2977
- const current = latest.current;
2978
- const isHorizontal = current.horizontal === true;
2979
- const columns = current.numColumns ?? 1;
2980
- const extract = current.keyExtractor ?? defaultKeyExtractor;
2981
- const currentItems = isArrayLike(current.data) ? current.data : [];
2982
- const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
2983
- const createToken = (index, isViewable) => {
2984
- if (columns === 1) {
2985
- const item = currentItems[index];
2986
- return {
2987
- item,
2988
- key: extract(item, index),
2989
- index,
2990
- isViewable
2991
- };
2992
- }
2993
- const row = [];
2994
- for (let column = 0; column < columns; column++) {
2995
- const itemIndex = index * columns + column;
2996
- if (itemIndex < currentItems.length) row.push(currentItems[itemIndex]);
2997
- }
2998
- return {
2999
- item: row,
3000
- key: row.map((item, column) => extract(item, index * columns + column)).join(":"),
3001
- index,
3002
- isViewable
3003
- };
3004
- };
3005
- const expand = (tokens) => {
3006
- if (columns === 1) return tokens;
3007
- const out = [];
3008
- for (const token of tokens) token.item.forEach((item, column) => {
3009
- const index = (token.index ?? 0) * columns + column;
3010
- out.push({
3011
- ...token,
3012
- item,
3013
- key: extract(item, index),
3014
- index
3015
- });
3016
- });
3017
- return out;
3018
- };
3019
- const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
3020
- const viewport = isHorizontal ? element.clientWidth : element.clientHeight;
3021
- for (const entry of trackers) {
3022
- const handler = entry.callback(current);
3023
- if (handler == null) continue;
3024
- entry.tracker.onUpdate(count, metricsAt, offset, viewport, createToken, (info) => {
3025
- handler({
3026
- viewableItems: expand(info.viewableItems),
3027
- changed: expand(info.changed)
3028
- });
3029
- });
3030
- }
3031
- }, [metricsAt, trackers]);
3032
- const handleScroll = useCallback((event) => {
3033
- latest.current.onScroll?.(event);
3034
- maybeCallOnEdgeReached();
3035
- updateViewability();
3036
- }, [maybeCallOnEdgeReached, updateViewability]);
3037
- const handleContentSizeChange = useCallback((width, height) => {
3038
- latest.current.onContentSizeChange?.(width, height);
3039
- maybeCallOnEdgeReached();
3040
- updateViewability();
3041
- }, [maybeCallOnEdgeReached, updateViewability]);
3042
- const handleLayout = useCallback((event) => {
3043
- latest.current.onLayout?.(event);
3044
- maybeCallOnEdgeReached();
3045
- updateViewability();
3046
- }, [maybeCallOnEdgeReached, updateViewability]);
3047
- useEffect(() => {
3048
- updateViewability();
3049
- });
3050
- const scrollToOffset = useCallback((offset, animated) => {
3051
- const element = scroller.current;
3052
- if (element === null) return;
3053
- element.scrollTo(latest.current.horizontal === true ? {
3054
- x: offset,
3055
- animated
3056
- } : {
3057
- y: offset,
3058
- animated
3059
- });
3060
- }, []);
3061
- const scrollToIndex = useCallback((params) => {
3062
- const current = latest.current;
3063
- const columns = current.numColumns ?? 1;
3064
- const currentItems = isArrayLike(current.data) ? current.data : [];
3065
- const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
3066
- const { animated, index, viewOffset, viewPosition } = params;
3067
- if (index < 0) throw new Error(`scrollToIndex out of range: requested index ${index} but minimum is 0`);
3068
- if (count < 1) throw new Error(`scrollToIndex out of range: item length ${count} but minimum is 1`);
3069
- if (index >= count) throw new Error(`scrollToIndex out of range: requested index ${index} is out of 0 to ${count - 1}`);
3070
- const frame = metricsAt(Math.floor(index));
3071
- const element = scroller.current;
3072
- if (frame === void 0 || element === null) {
3073
- const { onScrollToIndexFailed } = current;
3074
- if (onScrollToIndexFailed === void 0) throw new Error("scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed, otherwise there is no way to know the location of offscreen indices or handle failures.");
3075
- onScrollToIndexFailed({
3076
- index,
3077
- highestMeasuredFrameIndex: -1,
3078
- averageItemLength: 0
3079
- });
3080
- return;
3081
- }
3082
- const visibleLength = current.horizontal === true ? element.clientWidth : element.clientHeight;
3083
- const offset = Math.max(0, frame.offset - (viewPosition ?? 0) * (visibleLength - frame.length)) - (viewOffset ?? 0);
3084
- scrollToOffset(offset, animated);
3085
- }, [metricsAt, scrollToOffset]);
3086
- useImperativeHandle(ref, () => ({
3087
- scrollToOffset: (params) => scrollToOffset(params.offset, params.animated),
3088
- scrollToEnd: (params) => scroller.current?.scrollToEnd({ animated: params?.animated }),
3089
- scrollToIndex,
3090
- scrollToItem: ({ item, ...rest }) => {
3091
- const current = latest.current;
3092
- const columns = current.numColumns ?? 1;
3093
- const currentItems = isArrayLike(current.data) ? current.data : [];
3094
- for (let index = 0; index < currentItems.length; index++) if (currentItems[index] === item) {
3095
- scrollToIndex({
3096
- ...rest,
3097
- index: Math.floor(index / columns)
3098
- });
3099
- return;
3100
- }
3101
- },
3102
- recordInteraction: () => {
3103
- for (const entry of trackers) entry.tracker.recordInteraction();
3104
- updateViewability();
3105
- },
3106
- flashScrollIndicators: () => {},
3107
- getScrollResponder: () => scroller.current,
3108
- getNativeScrollRef: () => scroller.current,
3109
- getScrollableNode: () => scroller.current,
3110
- setNativeProps: () => {}
3111
- }), [
3112
- scrollToIndex,
3113
- scrollToOffset,
3114
- trackers,
3115
- updateViewability
3116
- ]);
3117
- useLayoutEffect(() => {
3118
- const index = latest.current.initialScrollIndex;
3119
- const element = scroller.current;
3120
- if (index == null || element === null) return;
3121
- const frame = metricsAt(index);
3122
- if (frame === void 0) return;
3123
- if (latest.current.horizontal === true) element.scrollLeft = frame.offset;
3124
- else element.scrollTop = frame.offset;
3125
- }, [metricsAt]);
3126
- const inversionStyle = inverted ? horizontal ? horizontallyInvertedStyle : verticallyInvertedStyle : void 0;
3127
- const cellStyle = inversionStyle ? horizontal ? [rowReverseStyle, inversionStyle] : [columnReverseStyle, inversionStyle] : horizontal ? rowStyle : void 0;
3128
- const renderOne = (info) => {
3129
- if (ListItemComponent !== void 0) return /* @__PURE__ */ jsx(ListItemComponent, { ...info });
3130
- if (renderItem != null) return renderItem(info);
3131
- throw new Error("FlatList: Either ListItemComponent or renderItem props are required but none were found.");
3132
- };
3133
- const renderCell = (row, index, separators) => {
3134
- if (numColumns === 1) return renderOne({
3135
- item: row,
3136
- index,
3137
- separators
3138
- });
3139
- return /* @__PURE__ */ jsx(View, {
3140
- style: [rowStyle, columnWrapperStyle],
3141
- children: row.map((item, column) => {
3142
- const element = renderOne({
3143
- item,
3144
- index: index * numColumns + column,
3145
- separators
3146
- });
3147
- return element == null ? null : /* @__PURE__ */ jsx(Fragment, { children: element }, column);
3148
- })
3149
- });
3150
- };
3151
- const children = [];
3152
- if (ListHeaderComponent != null) children.push(/* @__PURE__ */ jsx(View, {
3153
- style: [inversionStyle, ListHeaderComponentStyle],
3154
- children: renderListComponent(ListHeaderComponent)
3155
- }, "$header"));
3156
- if (rowCount === 0) {
3157
- if (ListEmptyComponent != null) children.push(/* @__PURE__ */ jsx(View, {
3158
- style: inversionStyle,
3159
- children: renderListComponent(ListEmptyComponent)
3160
- }, "$empty"));
3161
- } else {
3162
- let prevCellKey;
3163
- for (let index = 0; index < rowCount; index++) {
3164
- const row = rowAt(index);
3165
- const cellKey = rowKey(row, index);
3166
- children.push(/* @__PURE__ */ jsx(Cell, {
3167
- cellKey,
3168
- prevCellKey,
3169
- index,
3170
- item: row,
3171
- style: cellStyle,
3172
- renderCell,
3173
- ItemSeparatorComponent: index < rowCount - 1 ? ItemSeparatorComponent : void 0,
3174
- CellRendererComponent,
3175
- separatorUpdaters,
3176
- onElement
3177
- }, cellKey));
3178
- prevCellKey = cellKey;
3179
- }
3180
- }
3181
- if (ListFooterComponent != null) children.push(/* @__PURE__ */ jsx(View, {
3182
- style: [inversionStyle, ListFooterComponentStyle],
3183
- children: renderListComponent(ListFooterComponent)
3184
- }, "$footer"));
3185
- const scrollProps = {
3186
- ...scrollViewProps,
3187
- horizontal,
3188
- style: [inversionStyle, style],
3189
- onScroll: handleScroll,
3190
- onContentSizeChange: handleContentSizeChange,
3191
- onLayout: handleLayout,
3192
- children
3193
- };
3194
- if (renderScrollComponent !== void 0) return /* @__PURE__ */ jsx(CustomScroller, {
3195
- ...scrollProps,
3196
- onRefresh,
3197
- refreshing,
3198
- progressViewOffset,
3199
- ref: scroller,
3200
- render: renderScrollComponent
3201
- });
3202
- let refreshControl = scrollProps.refreshControl;
3203
- if (onRefresh != null) {
3204
- if (typeof refreshing !== "boolean") throw new Error("`refreshing` prop must be set as a boolean in order to use `onRefresh`, but got `" + JSON.stringify(refreshing ?? "undefined") + "`");
3205
- refreshControl ??= /* @__PURE__ */ jsx(RefreshControl, {
3206
- refreshing,
3207
- onRefresh,
3208
- progressViewOffset
3209
- });
3210
- }
3211
- return /* @__PURE__ */ jsx(ScrollView, {
3212
- ...scrollProps,
3213
- refreshControl,
3214
- ref: scroller
3215
- });
3216
- }
3217
- // src/components/Image/source.ts
3218
- const none = Object.freeze({
3219
- src: void 0,
3220
- srcSet: void 0,
3221
- sizes: void 0,
3222
- width: void 0,
3223
- height: void 0,
3224
- request: void 0
3225
- });
3226
- const ASSET_ID_WARNING = "Image: a numeric source is a Metro asset id, which has no meaning here. Import the image file and pass its URL.";
3227
- const hasURI = (source) => typeof source.uri === "string" && source.uri.length > 0;
3228
- const requestOf = (source) => {
3229
- if (source.headers === void 0 && source.method === void 0 && source.body === void 0) return;
3230
- return {
3231
- method: source.method ?? "GET",
3232
- headers: source.headers,
3233
- body: source.body
3234
- };
3235
- };
3236
- const single = (source) => ({
3237
- src: source.uri,
3238
- srcSet: void 0,
3239
- sizes: void 0,
3240
- width: source.width,
3241
- height: source.height,
3242
- request: requestOf(source)
3243
- });
3244
- const firstCandidate = (srcSet) => srcSet.split(",")[0]?.trim().split(/\s+/)[0];
3245
- const list = (sources, layoutWidth) => {
3246
- const first = sources[0];
3247
- if (sources.length === 1) return single(first);
3248
- if (sources.every((s) => typeof s.width === "number")) return {
3249
- src: first.uri,
3250
- srcSet: sources.map((s) => `${s.uri} ${s.width}w`).join(", "),
3251
- sizes: layoutWidth === void 0 ? "100vw" : `${layoutWidth}px`,
3252
- width: void 0,
3253
- height: void 0,
3254
- request: void 0
3255
- };
3256
- if (sources.every((s) => typeof s.scale === "number")) {
3257
- const base = sources.find((s) => s.scale === 1) ?? first;
3258
- return {
3259
- src: base.uri,
3260
- srcSet: sources.map((s) => `${s.uri} ${s.scale}x`).join(", "),
3261
- sizes: void 0,
3262
- width: base.width,
3263
- height: base.height,
3264
- request: void 0
3265
- };
3266
- }
3267
- return single(first);
3268
- };
3269
- const resolveSource = (source, src, srcSet, layoutWidth) => {
3270
- if (src !== void 0 || srcSet !== void 0) return {
3271
- ...none,
3272
- src: src ?? (srcSet === void 0 ? void 0 : firstCandidate(srcSet)),
3273
- srcSet,
3274
- sizes: srcSet !== void 0 && /\d+w/.test(srcSet) ? "100vw" : void 0
3275
- };
3276
- if (source === void 0 || source === null) return none;
3277
- if (typeof source === "string") return {
3278
- ...none,
3279
- src: source
3280
- };
3281
- if (typeof source === "number") {
3282
- warnOnce("image-asset-id", ASSET_ID_WARNING);
3283
- return none;
3284
- }
3285
- if (Array.isArray(source)) {
3286
- const sources = source.filter(hasURI);
3287
- return sources.length === 0 ? none : list(sources, layoutWidth);
3288
- }
3289
- return hasURI(source) ? single(source) : none;
3290
- };
3291
- const resolveAssetSource = (source) => {
3292
- if (typeof source === "string") return {
3293
- uri: source,
3294
- scale: 1
3295
- };
3296
- if (typeof source === "number") {
3297
- warnOnce("image-asset-id", ASSET_ID_WARNING);
3298
- return null;
3299
- }
3300
- const first = Array.isArray(source) ? source[0] : source;
3301
- if (first === void 0 || first === null || !hasURI(first)) return null;
3302
- const { uri, width, height, scale } = first;
3303
- return {
3304
- uri,
3305
- width,
3306
- height,
3307
- scale: scale ?? 1
3308
- };
3309
- };
3310
- // src/components/Image/index.tsx
3311
- const boxStyle = Object.freeze({
3312
- backgroundColor: "transparent",
3313
- border: "0 solid black",
3314
- boxSizing: "border-box",
3315
- display: "flex",
3316
- flexBasis: "auto",
3317
- flexDirection: "column",
3318
- flexShrink: 0,
3319
- margin: 0,
3320
- minHeight: 0,
3321
- minWidth: 0,
3322
- overflow: "hidden",
3323
- padding: 0,
3324
- position: "relative",
3325
- zIndex: 0
3326
- });
3327
- const fillStyle = Object.freeze({
3328
- position: "absolute",
3329
- left: 0,
3330
- top: 0,
3331
- width: "100%",
3332
- height: "100%",
3333
- display: "block",
3334
- border: 0,
3335
- margin: 0,
3336
- padding: 0
3337
- });
3338
- const hiddenStyle = Object.freeze({ visibility: "hidden" });
3339
- const objectFitOf = {
3340
- cover: "cover",
3341
- contain: "contain",
3342
- stretch: "fill",
3343
- center: "none",
3344
- repeat: "none"
3345
- };
3346
- const resizeModeOfObjectFit = {
3347
- cover: "cover",
3348
- contain: "contain",
3349
- fill: "stretch",
3350
- "scale-down": "contain",
3351
- none: "center"
3352
- };
3353
- const maskSizeOf = {
3354
- cover: "cover",
3355
- contain: "contain",
3356
- stretch: "100% 100%",
3357
- center: "auto",
3358
- repeat: "auto"
3359
- };
3360
- const cssURL = (url) => `url("${url.replace(/["\\]/g, "\\$&")}")`;
3361
- const loadError = (uri) => `Failed to load image: ${uri ?? ""}`;
3362
- const sizeOf = (img) => ({
3363
- width: img.naturalWidth,
3364
- height: img.naturalHeight
3365
- });
3366
- const placeholderURI = (source) => {
3367
- if (typeof source === "string") return source;
3368
- if (typeof source === "object" && source !== null) return source.uri;
3369
- };
3370
- const useRequestURL = (uri, request) => {
3371
- const [state, setState] = useState({
3372
- uri: void 0,
3373
- url: void 0,
3374
- error: void 0
3375
- });
3376
- const requestKey = request === void 0 ? void 0 : JSON.stringify(request);
3377
- useEffect(() => {
3378
- if (uri === void 0 || requestKey === void 0) return;
3379
- const { method, headers, body } = JSON.parse(requestKey);
3380
- const controller = new AbortController();
3381
- let objectURL;
3382
- const init = {
3383
- method,
3384
- signal: controller.signal
3385
- };
3386
- if (headers !== void 0) init.headers = headers;
3387
- if (body !== void 0) init.body = body;
3388
- fetch(uri, init).then((response) => {
3389
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
3390
- return response.blob();
3391
- }).then((blob) => {
3392
- objectURL = URL.createObjectURL(blob);
3393
- setState({
3394
- uri,
3395
- url: objectURL,
3396
- error: void 0
3397
- });
3398
- }).catch((error) => {
3399
- if (controller.signal.aborted) return;
3400
- const message = error instanceof Error ? error.message : String(error);
3401
- setState({
3402
- uri,
3403
- url: void 0,
3404
- error: `${loadError(uri)} (${message})`
3405
- });
3406
- });
3407
- return () => {
3408
- controller.abort();
3409
- if (objectURL !== void 0) URL.revokeObjectURL(objectURL);
3410
- };
3411
- }, [uri, requestKey]);
3412
- return state.uri === uri ? state : {
3413
- url: void 0,
3414
- error: void 0
3415
- };
3416
- };
3417
- function ImageComponent(props) {
3418
- const { alt, blurRadius, crossOrigin, decoding, defaultSource, fetchPriority, height, loading, onError, onLayout, onLoad, onLoadEnd, onLoadStart, ref, referrerPolicy, resizeMode: resizeModeProp, source, src, srcSet, style, tintColor: tintColorProp, width, fadeDuration: _fadeDuration, loadingIndicatorSource: _loadingIndicatorSource, onProgress: _onProgress, progressiveRenderingEnabled: _progressiveRenderingEnabled, resizeMethod: _resizeMethod, ...rest } = props;
3419
- const element = useRef(null);
3420
- const img = useRef(null);
3421
- useImperativeHandle(ref, () => withHostMethods(element.current), []);
3422
- useElementLayout(element, onLayout);
3423
- const registry = useStyleRegistry();
3424
- const { resizeMode: styleResizeMode, objectFit, tintColor: styleTintColor, overlayColor: _overlayColor, ...userBoxStyle } = flattenStyle(style) ?? {};
3425
- const resizeMode = (typeof objectFit === "string" ? resizeModeOfObjectFit[objectFit] : void 0) ?? resizeModeProp ?? styleResizeMode ?? "cover";
3426
- const tintColor = tintColorProp ?? styleTintColor;
3427
- const painted = resizeMode === "repeat" || tintColor !== void 0;
3428
- const styleWidth = userBoxStyle["width"] ?? width;
3429
- const resolved = resolveSource(source, src, srcSet, typeof styleWidth === "number" ? styleWidth : void 0);
3430
- const requested = useRequestURL(resolved.src, resolved.request);
3431
- const currentSrc = resolved.request === void 0 ? resolved.src : requested.url;
3432
- const handlers = useRef({
3433
- onLoad,
3434
- onLoadStart,
3435
- onLoadEnd,
3436
- onError
3437
- });
3438
- useEffect(() => {
3439
- handlers.current = {
3440
- onLoad,
3441
- onLoadStart,
3442
- onLoadEnd,
3443
- onError
3444
- };
3445
- });
3446
- const [loadedSrc, setLoadedSrc] = useState(void 0);
3447
- const firedFor = useRef(void 0);
3448
- useEffect(() => {
3449
- if (resolved.src === void 0) return;
3450
- firedFor.current = void 0;
3451
- handlers.current.onLoadStart?.();
3452
- }, [resolved.src]);
3453
- const fireLoad = useCallback((target) => {
3454
- const uri = target.currentSrc || target.src;
3455
- if (firedFor.current === uri) return;
3456
- firedFor.current = uri;
3457
- setLoadedSrc(target.src);
3458
- const { width: naturalWidth, height: naturalHeight } = sizeOf(target);
3459
- handlers.current.onLoad?.({ nativeEvent: { source: {
3460
- uri,
3461
- width: naturalWidth,
3462
- height: naturalHeight
3463
- } } });
3464
- handlers.current.onLoadEnd?.();
3465
- }, []);
3466
- const fireError = useCallback((target) => {
3467
- const uri = target.currentSrc || target.src;
3468
- if (firedFor.current === uri) return;
3469
- firedFor.current = uri;
3470
- handlers.current.onError?.({ nativeEvent: { error: loadError(uri) } });
3471
- handlers.current.onLoadEnd?.();
3472
- }, []);
3473
- const handleLoad = useCallback((event) => fireLoad(event.currentTarget), [fireLoad]);
3474
- const handleError = useCallback((event) => fireError(event.currentTarget), [fireError]);
3475
- useEffect(() => {
3476
- const target = img.current;
3477
- if (target === null || currentSrc === void 0 || !target.complete) return;
3478
- if (target.naturalWidth > 0) fireLoad(target);
3479
- else fireError(target);
3480
- });
3481
- const requestError = requested.error;
3482
- useEffect(() => {
3483
- if (requestError === void 0) return;
3484
- if (firedFor.current === resolved.src) return;
3485
- firedFor.current = resolved.src;
3486
- handlers.current.onError?.({ nativeEvent: { error: requestError } });
3487
- handlers.current.onLoadEnd?.();
3488
- }, [requestError, resolved.src]);
3489
- const { tag, role } = resolveTag(rest, "div", true);
3490
- const sizeStyle = {
3491
- width: userBoxStyle["width"] ?? width ?? resolved.width,
3492
- height: userBoxStyle["height"] ?? height ?? resolved.height
3493
- };
3494
- const boxClassName = joinClassNames(compileReset("rn-image", boxStyle, registry), compileStyle([sizeStyle, userBoxStyle], registry));
3495
- const label = alt ?? rest.accessibilityLabel ?? rest["aria-label"];
3496
- const domProps = toDOMProps(rest);
3497
- domProps["className"] = boxClassName;
3498
- domProps["ref"] = element;
3499
- if (role !== void 0) domProps["role"] = role;
3500
- else if (painted && label !== void 0 && label !== "") {
3501
- domProps["role"] = "img";
3502
- domProps["aria-label"] = label;
3503
- }
3504
- const imgStyle = {
3505
- objectFit: objectFitOf[resizeMode],
3506
- filter: blurRadius !== void 0 && blurRadius > 0 ? `blur(${blurRadius}px)` : void 0
3507
- };
3508
- const placeholder = placeholderURI(defaultSource);
3509
- const showPlaceholder = placeholder !== void 0 && (currentSrc === void 0 || loadedSrc !== currentSrc);
3510
- let paintStyle;
3511
- if (painted && currentSrc !== void 0) {
3512
- const url = cssURL(currentSrc);
3513
- const repeat = resizeMode === "repeat" ? "repeat" : "no-repeat";
3514
- paintStyle = tintColor === void 0 ? {
3515
- backgroundImage: url,
3516
- backgroundRepeat: repeat,
3517
- backgroundPosition: "center",
3518
- backgroundSize: "auto"
3519
- } : {
3520
- backgroundColor: tintColor,
3521
- WebkitMaskImage: url,
3522
- maskImage: url,
3523
- WebkitMaskRepeat: repeat,
3524
- maskRepeat: repeat,
3525
- WebkitMaskPosition: "center",
3526
- maskPosition: "center",
3527
- WebkitMaskSize: maskSizeOf[resizeMode],
3528
- maskSize: maskSizeOf[resizeMode]
3529
- };
3530
- }
3531
- const children = [/* @__PURE__ */ jsx("img", {
3532
- ref: img,
3533
- src: currentSrc,
3534
- srcSet: resolved.srcSet,
3535
- sizes: resolved.sizes,
3536
- alt: painted ? "" : label ?? "",
3537
- "aria-hidden": painted ? true : void 0,
3538
- draggable: false,
3539
- crossOrigin,
3540
- referrerPolicy,
3541
- loading,
3542
- fetchPriority,
3543
- decoding,
3544
- onLoad: handleLoad,
3545
- onError: handleError,
3546
- className: compileStyle([
3547
- fillStyle,
3548
- imgStyle,
3549
- painted && hiddenStyle
3550
- ], registry)
3551
- }, "img")];
3552
- if (showPlaceholder) children.unshift(/* @__PURE__ */ jsx("img", {
3553
- src: placeholder,
3554
- alt: "",
3555
- "aria-hidden": true,
3556
- draggable: false,
3557
- className: compileStyle([fillStyle, imgStyle], registry)
3558
- }, "placeholder"));
3559
- if (paintStyle !== void 0) children.push(/* @__PURE__ */ jsx("div", {
3560
- "aria-hidden": true,
3561
- className: compileStyle([fillStyle, paintStyle], registry)
3562
- }, "paint"));
3563
- return createElement(tag, domProps, ...children);
3564
- }
3565
- const loadSize = (uri) => new Promise((resolve, reject) => {
3566
- if (!hasDOM()) {
3567
- reject(/* @__PURE__ */ new Error("Image.getSize needs a DOM"));
3568
- return;
3569
- }
3570
- const probe = document.createElement("img");
3571
- probe.addEventListener("load", () => resolve(sizeOf(probe)), { once: true });
3572
- probe.addEventListener("error", () => reject(new Error(loadError(uri))), { once: true });
3573
- probe.src = uri;
3574
- });
3575
- const fetchObjectURL = async (uri, headers) => {
3576
- const response = await fetch(uri, { headers });
3577
- if (!response.ok) throw new Error(`${loadError(uri)} (HTTP ${response.status})`);
3578
- return URL.createObjectURL(await response.blob());
3579
- };
3580
- const withCallbacks = (promise, success, failure) => {
3581
- if (success === void 0) return promise;
3582
- promise.then((size) => success(size.width, size.height), (error) => failure?.(error));
3583
- };
3584
- function getSize(uri, success, failure) {
3585
- return withCallbacks(loadSize(uri), success, failure);
3586
- }
3587
- function getSizeWithHeaders(uri, headers, success, failure) {
3588
- const promise = fetchObjectURL(uri, headers).then((url) => loadSize(url).finally(() => URL.revokeObjectURL(url)));
3589
- return withCallbacks(promise, success, failure);
3590
- }
3591
- const Image = Object.assign(ImageComponent, {
3592
- getSize,
3593
- getSizeWithHeaders,
3594
- prefetch: (url) => loadSize(url).then(() => true),
3595
- queryCache: () => Promise.resolve({}),
3596
- resolveAssetSource
3597
- });
3598
- // src/components/KeyboardAvoidingView/index.tsx
3599
- /**
3600
- * A view that moves out of the way of the keyboard, with the math of React Native 0.88. As on
3601
- * native, the frame of the view comes from `onLayout`, so its `y` is relative to its parent.
3602
- * `keyboardVerticalOffset` adds the distance to the top of the window.
3603
- */
3604
- function KeyboardAvoidingView(props) {
3605
- const { behavior, children, contentContainerStyle, enabled = true, keyboardVerticalOffset = 0, style, onLayout, ...rest } = props;
3606
- const [bottom, setBottom] = useState(0);
3607
- const [initialFrameHeight, setInitialFrameHeight] = useState(0);
3608
- const frame = useRef(null);
3609
- const keyboard = useRef(null);
3610
- const latestBottom = useRef(0);
3611
- const shownBottom = useRef(0);
3612
- const initialHeight = useRef(0);
3613
- const latest = useRef({
3614
- behavior,
3615
- enabled,
3616
- keyboardVerticalOffset,
3617
- onLayout
3618
- });
3619
- useEffect(() => {
3620
- latest.current = {
3621
- behavior,
3622
- enabled,
3623
- keyboardVerticalOffset,
3624
- onLayout
3625
- };
3626
- });
3627
- const [handlers] = useState(() => {
3628
- const relativeKeyboardHeight = (keyboardFrame) => {
3629
- const layout = frame.current;
3630
- if (layout === null) return 0;
3631
- const keyboardY = keyboardFrame.screenY - latest.current.keyboardVerticalOffset;
3632
- if (latest.current.behavior === "height") return Math.max(shownBottom.current + layout.y + layout.height - keyboardY, 0);
3633
- return Math.max(layout.y + layout.height - keyboardY, 0);
3634
- };
3635
- const update = () => {
3636
- const event = keyboard.current;
3637
- const next = event === null ? 0 : relativeKeyboardHeight(event.endCoordinates);
3638
- if (event !== null && latestBottom.current === next) return;
3639
- latestBottom.current = next;
3640
- if (latest.current.enabled) {
3641
- shownBottom.current = next;
3642
- setBottom(next);
3643
- }
3644
- };
3645
- const handleLayout = (event) => {
3646
- const old = frame.current;
3647
- frame.current = event.nativeEvent.layout;
3648
- if (initialHeight.current === 0) {
3649
- initialHeight.current = frame.current.height;
3650
- setInitialFrameHeight(frame.current.height);
3651
- }
3652
- if (old === null || old.height !== frame.current.height) update();
3653
- latest.current.onLayout?.(event);
3654
- };
3655
- return {
3656
- update,
3657
- handleLayout
3658
- };
3659
- });
3660
- useEffect(() => {
3661
- const { update } = handlers;
3662
- if (!Keyboard.isVisible()) {
3663
- keyboard.current = null;
3664
- update();
3665
- }
3666
- const subscriptions = [Keyboard.addListener("keyboardDidHide", () => {
3667
- keyboard.current = null;
3668
- update();
3669
- }), Keyboard.addListener("keyboardDidShow", (event) => {
3670
- keyboard.current = event;
3671
- update();
3672
- })];
3673
- return () => {
3674
- for (const subscription of subscriptions) subscription.remove();
3675
- };
3676
- }, [handlers]);
3677
- useEffect(() => {
3678
- if (enabled && shownBottom.current !== latestBottom.current) {
3679
- shownBottom.current = latestBottom.current;
3680
- setBottom(latestBottom.current);
3681
- }
3682
- }, [enabled]);
3683
- const bottomHeight = enabled ? bottom : 0;
3684
- const outerStyle = useMemo(() => {
3685
- if (behavior === "padding") return [style, { paddingBottom: bottomHeight }];
3686
- if (behavior === "height" && bottom > 0) return [style, {
3687
- height: initialFrameHeight - bottomHeight,
3688
- flex: 0
3689
- }];
3690
- return style;
3691
- }, [
3692
- behavior,
3693
- bottom,
3694
- bottomHeight,
3695
- initialFrameHeight,
3696
- style
3697
- ]);
3698
- const innerStyle = useMemo(() => [contentContainerStyle, { bottom: bottomHeight }], [contentContainerStyle, bottomHeight]);
3699
- return /* @__PURE__ */ jsx(View, {
3700
- ...rest,
3701
- style: outerStyle,
3702
- onLayout: handlers.handleLayout,
3703
- children: behavior === "position" ? /* @__PURE__ */ jsx(View, {
3704
- style: innerStyle,
3705
- children
3706
- }) : children
3707
- });
3708
- }
3709
- // src/components/Modal/index.tsx
3710
- const MODAL_CLASS = "rn-modal";
3711
- const RULES$1 = [
3712
- `.${MODAL_CLASS}{position:fixed;inset:0;z-index:2147483647;box-sizing:border-box;width:100%;height:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;background:transparent;color:inherit;overflow:hidden}`,
3713
- `.${MODAL_CLASS}[open]{display:flex;flex-direction:column}`,
3714
- `.${MODAL_CLASS}:not([open]){display:none}`,
3715
- `.${MODAL_CLASS}:focus{outline:none}`,
3716
- `.${MODAL_CLASS}[data-closing]{pointer-events:none}`,
3717
- `@supports selector(::backdrop){.${MODAL_CLASS}::backdrop{background:transparent}}`
3718
- ];
3719
- const DURATION_MS = 200;
3720
- const motions = {
3721
- slide: {
3722
- property: "transform",
3723
- hidden: "translateY(100%)",
3724
- shown: "translateY(0)",
3725
- easing: "cubic-bezier(0.37, 0, 0.63, 1)"
3726
- },
3727
- fade: {
3728
- property: "opacity",
3729
- hidden: "0",
3730
- shown: "1",
3731
- easing: "cubic-bezier(0.333, 0, 0.667, 0.333)"
3732
- }
3733
- };
3734
- const motionOf = (type) => type === "slide" || type === "fade" ? Platform.isDisableAnimations ? null : motions[type] : null;
3735
- const animate = (element, motion, to, running) => {
3736
- const from = running === null ? motion[to === "shown" ? "hidden" : "shown"] : getComputedStyle(element)[motion.property];
3737
- running?.cancel();
3738
- return element.animate([{ [motion.property]: from }, { [motion.property]: motion[to] }], {
3739
- duration: DURATION_MS,
3740
- easing: motion.easing,
3741
- fill: to === "hidden" ? "forwards" : "none"
3742
- });
3743
- };
3744
- const HostContext = createContext(null);
3745
- const createHost = () => {
3746
- const children = /* @__PURE__ */ new Set();
3747
- let shown = false;
3748
- return {
3749
- add: (child) => {
3750
- children.add(child);
3751
- if (shown) child.show();
3752
- return () => {
3753
- children.delete(child);
3754
- };
3755
- },
3756
- showChildren: () => {
3757
- shown = true;
3758
- for (const child of children) child.show();
3759
- },
3760
- hideChildren: () => {
3761
- shown = false;
3762
- const list = Array.from(children);
3763
- for (let index = list.length - 1; index >= 0; index--) list[index]?.hide();
3764
- }
3765
- };
3766
- };
3767
- const subscribeNothing = () => () => {};
3768
- const useIsClient = () => useSyncExternalStore(subscribeNothing, () => true, () => false);
3769
- /**
3770
- * React Native's `Modal` on a `<dialog>` in the top layer. `showModal()` makes the rest of the
3771
- * page inert, keeps the focus inside, and turns Escape into `onRequestClose`.
3772
- */
3773
- function Modal(props) {
3774
- const { visible = true, onDismiss, animationType } = props;
3775
- const shown = useIsClient() && visible;
3776
- const [exiting, setExiting] = useState(false);
3777
- const [lastShown, setLastShown] = useState(shown);
3778
- if (lastShown !== shown) {
3779
- setLastShown(shown);
3780
- setExiting(!shown && animationType != null && animationType !== "none");
3781
- }
3782
- const mounted = shown || exiting;
3783
- const onExited = useCallback(() => setExiting(false), []);
3784
- const dismiss = useRef(onDismiss);
3785
- const wasMounted = useRef(false);
3786
- useEffect(() => {
3787
- dismiss.current = onDismiss;
3788
- });
3789
- useEffect(() => {
3790
- if (wasMounted.current && !mounted) dismiss.current?.();
3791
- wasMounted.current = mounted;
3792
- }, [mounted]);
3793
- return mounted ? createPortal(/* @__PURE__ */ jsx(ModalDialog, {
3794
- ...props,
3795
- closing: !shown,
3796
- onExited
3797
- }), document.body) : null;
3798
- }
3799
- function ModalDialog(props) {
3800
- const { children, style, transparent, backdropColor, onRequestClose, onShow, ref, modalRef, animationType, closing, onExited, visible: _visible, onDismiss: _onDismiss, allowSwipeDismissal: _allowSwipeDismissal, hardwareAccelerated: _hardwareAccelerated, navigationBarTranslucent: _navigationBarTranslucent, onOrientationChange: _onOrientationChange, presentationStyle: _presentationStyle, statusBarTranslucent: _statusBarTranslucent, supportedOrientations: _supportedOrientations, ...rest } = props;
3801
- const className = useStyleRegistry().staticClass(MODAL_CLASS, RULES$1);
3802
- const dialog = useRef(null);
3803
- const open = useRef(false);
3804
- const announced = useRef(false);
3805
- const parent = useContext(HostContext);
3806
- const [host] = useState(createHost);
3807
- const animation = useRef(null);
3808
- const latest = useRef({
3809
- onRequestClose,
3810
- onShow,
3811
- onExited,
3812
- animationType
3813
- });
3814
- useLayoutEffect(() => {
3815
- latest.current = {
3816
- onRequestClose,
3817
- onShow,
3818
- onExited,
3819
- animationType
3820
- };
3821
- });
3822
- useImperativeHandle(ref, () => dialog.current, []);
3823
- useImperativeHandle(modalRef, () => dialog.current, []);
3824
- useLayoutEffect(() => {
3825
- const element = dialog.current;
3826
- if (element === null) return;
3827
- const modal = typeof element.showModal === "function";
3828
- let focused = null;
3829
- const layer = {
3830
- show: () => {
3831
- if (open.current) return;
3832
- open.current = true;
3833
- if (modal) element.showModal();
3834
- else {
3835
- focused = document.activeElement;
3836
- element.setAttribute("open", "");
3837
- element.tabIndex = -1;
3838
- element.focus();
3839
- }
3840
- lockScroll();
3841
- host.showChildren();
3842
- const announce = () => {
3843
- if (announced.current) return;
3844
- announced.current = true;
3845
- latest.current.onShow?.({ nativeEvent: null });
3846
- };
3847
- const motion = motionOf(latest.current.animationType);
3848
- if (motion === null || typeof element.animate !== "function") {
3849
- announce();
3850
- return;
3851
- }
3852
- const next = animate(element, motion, "shown", null);
3853
- animation.current = next;
3854
- next.onfinish = () => {
3855
- if (animation.current !== next) return;
3856
- animation.current = null;
3857
- announce();
3858
- };
3859
- },
3860
- hide: () => {
3861
- if (!open.current) return;
3862
- open.current = false;
3863
- animation.current?.cancel();
3864
- animation.current = null;
3865
- host.hideChildren();
3866
- if (modal) element.close();
3867
- else {
3868
- element.removeAttribute("open");
3869
- if (focused instanceof HTMLElement && focused.isConnected) focused.focus();
3870
- }
3871
- unlockScroll();
3872
- }
3873
- };
3874
- let remove;
3875
- if (parent === null) layer.show();
3876
- else remove = parent.add(layer);
3877
- return () => {
3878
- remove?.();
3879
- layer.hide();
3880
- };
3881
- }, [host, parent]);
3882
- const wasClosing = useRef(false);
3883
- useLayoutEffect(() => {
3884
- const element = dialog.current;
3885
- if (element === null || closing === wasClosing.current) return;
3886
- wasClosing.current = closing;
3887
- const motion = motionOf(latest.current.animationType);
3888
- const canAnimate = motion !== null && typeof element.animate === "function";
3889
- if (closing) {
3890
- host.hideChildren();
3891
- if (!canAnimate) {
3892
- latest.current.onExited();
3893
- return;
3894
- }
3895
- const next = animate(element, motion, "hidden", animation.current);
3896
- animation.current = next;
3897
- next.onfinish = () => {
3898
- if (animation.current === next) latest.current.onExited();
3899
- };
3900
- return;
3901
- }
3902
- host.showChildren();
3903
- if (!canAnimate || animation.current === null) return;
3904
- const next = animate(element, motion, "shown", animation.current);
3905
- animation.current = next;
3906
- next.onfinish = () => {
3907
- if (animation.current === next) animation.current = null;
3908
- };
3909
- }, [closing, host]);
3910
- const requestClose = () => {
3911
- latest.current.onRequestClose?.({ nativeEvent: null });
3912
- };
3913
- const handleCancel = (event) => {
3914
- if (event.target !== event.currentTarget) return;
3915
- event.preventDefault();
3916
- if (!closing) requestClose();
3917
- };
3918
- const handleClose = (event) => {
3919
- const element = event.currentTarget;
3920
- if (event.target === element && open.current && !element.open) element.showModal();
3921
- };
3922
- const domProps = toDOMProps(rest);
3923
- const appPointerDown = domProps["onPointerDown"];
3924
- const appClick = domProps["onClick"];
3925
- const appKeyDown = domProps["onKeyDown"];
3926
- const containerStyle = transparent ? styles$1.transparent : backdropColor != null ? { backgroundColor: backdropColor } : void 0;
3927
- return /* @__PURE__ */ jsx("dialog", {
3928
- ...domProps,
3929
- ref: dialog,
3930
- className,
3931
- "data-closing": closing ? "" : void 0,
3932
- onCancel: handleCancel,
3933
- onClose: handleClose,
3934
- onPointerDown: (event) => {
3935
- appPointerDown?.(event);
3936
- claimPress(event.nativeEvent);
3937
- },
3938
- onClick: (event) => {
3939
- appClick?.(event);
3940
- claimPress(event.nativeEvent);
3941
- },
3942
- onKeyDown: (event) => {
3943
- appKeyDown?.(event);
3944
- const element = event.currentTarget;
3945
- if (event.key === "Escape" && typeof element.showModal !== "function" && event.target.closest("dialog") === element) requestClose();
3946
- },
3947
- children: /* @__PURE__ */ jsx(HostContext.Provider, {
3948
- value: host,
3949
- children: /* @__PURE__ */ jsx(View, {
3950
- style: [
3951
- styles$1.container,
3952
- style,
3953
- containerStyle
3954
- ],
3955
- children
3956
- })
3957
- })
3958
- });
3959
- }
3960
- const styles$1 = StyleSheet.create({
3961
- container: {
3962
- flex: 1,
3963
- backgroundColor: "white"
3964
- },
3965
- transparent: { backgroundColor: "transparent" }
3966
- });
3967
- // src/components/Pressable/index.tsx
3968
- const notCancelableStyle$1 = Object.freeze({ touchAction: "none" });
3969
- const isFocusVisible = (element) => {
3970
- try {
3971
- return element.matches(":focus-visible");
3972
- } catch {
3973
- return true;
3974
- }
3975
- };
3976
- const Pressable = memo(function Pressable(props) {
3977
- const { android_disableSound, android_ripple: _androidRipple, blockNativeResponder, cancelable, children, delayHoverIn, delayHoverOut, delayLongPress, disabled, focusable, hitSlop, onBlur, onFocus, onHoverIn, onHoverOut, onLongPress, onPress, onPressIn, onPressMove, onPressOut, pressRetentionOffset, style, testOnly_pressed, unstable_pressDelay, ...rest } = props;
3978
- const [pressed, setPressed] = useState(false);
3979
- const [hovered, setHovered] = useState(false);
3980
- const [focused, setFocused] = useState(false);
3981
- const tracksState = typeof children === "function" || typeof style === "function";
3982
- const handlers = usePressability(useMemo(() => ({
3983
- cancelable,
3984
- disabled,
3985
- hitSlop,
3986
- pressRectOffset: pressRetentionOffset,
3987
- android_disableSound,
3988
- delayHoverIn,
3989
- delayHoverOut,
3990
- delayLongPress,
3991
- delayPressIn: unstable_pressDelay,
3992
- blockNativeResponder,
3993
- onLongPress,
3994
- onPress,
3995
- onPressMove,
3996
- onPressIn: (event) => {
3997
- if (tracksState) setPressed(true);
3998
- onPressIn?.(event);
3999
- },
4000
- onPressOut: (event) => {
4001
- if (tracksState) setPressed(false);
4002
- onPressOut?.(event);
4003
- },
4004
- onHoverIn: (event) => {
4005
- if (tracksState) setHovered(true);
4006
- onHoverIn?.(event);
4007
- },
4008
- onHoverOut: (event) => {
4009
- if (tracksState) setHovered(false);
4010
- onHoverOut?.(event);
4011
- },
4012
- onFocus: (event) => {
4013
- if (tracksState && event.target === event.currentTarget) setFocused(isFocusVisible(event.currentTarget));
4014
- onFocus?.(event);
4015
- },
4016
- onBlur: (event) => {
4017
- if (tracksState && event.target === event.currentTarget) setFocused(false);
4018
- onBlur?.(event);
4019
- }
4020
- }), [
4021
- android_disableSound,
4022
- blockNativeResponder,
4023
- cancelable,
4024
- delayHoverIn,
4025
- delayHoverOut,
4026
- delayLongPress,
4027
- disabled,
4028
- hitSlop,
4029
- onBlur,
4030
- onFocus,
4031
- onHoverIn,
4032
- onHoverOut,
4033
- onLongPress,
4034
- onPress,
4035
- onPressIn,
4036
- onPressMove,
4037
- onPressOut,
4038
- pressRetentionOffset,
4039
- tracksState,
4040
- unstable_pressDelay
4041
- ]));
4042
- const registry = useStyleRegistry();
4043
- const state = {
4044
- pressed: pressed || testOnly_pressed === true,
4045
- hovered,
4046
- focused
4047
- };
4048
- const viewProps = {
4049
- ...rest,
4050
- ...mergeHandlers(rest, handlers),
4051
- focusable: disabled !== true && focusable !== false,
4052
- style: [typeof style === "function" ? style(state) : style, cancelable === false && notCancelableStyle$1],
4053
- children: typeof children === "function" ? children(state) : children
4054
- };
4055
- if (disabled === true) viewProps["aria-disabled"] = true;
4056
- return useViewElement(viewProps, hitSlopClass(registry, hitSlop));
4057
- });
4058
- // src/components/StatusBar/index.tsx
4059
- const stack = [];
4060
- const base = {};
4061
- const merged = () => {
4062
- const out = { ...base };
4063
- for (const entry of stack) for (const key in entry) {
4064
- const value = entry[key];
4065
- if (value !== void 0) out[key] = value;
4066
- }
4067
- return out;
4068
- };
4069
- const themeColorMeta = () => {
4070
- if (!hasDOM()) return null;
4071
- let meta = document.head.querySelector("meta[name=\"theme-color\"]:not([media])");
4072
- if (meta === null) {
4073
- meta = document.createElement("meta");
4074
- meta.name = "theme-color";
4075
- document.head.appendChild(meta);
4076
- }
4077
- return meta;
4078
- };
4079
- let originalThemeColor;
4080
- const apply = () => {
4081
- const meta = themeColorMeta();
4082
- if (meta === null) return;
4083
- if (originalThemeColor === void 0) originalThemeColor = meta.getAttribute("content");
4084
- const color = toCSSColor(merged().backgroundColor);
4085
- if (color !== void 0) meta.setAttribute("content", color);
4086
- else if (originalThemeColor === null) meta.removeAttribute("content");
4087
- else meta.setAttribute("content", originalThemeColor);
4088
- };
4089
- const pushStackEntry = (props) => {
4090
- const entry = { ...props };
4091
- stack.push(entry);
4092
- apply();
4093
- return entry;
4094
- };
4095
- const popStackEntry = (entry) => {
4096
- const index = stack.indexOf(entry);
4097
- if (index !== -1) stack.splice(index, 1);
4098
- apply();
4099
- };
4100
- const replaceStackEntry = (entry, props) => {
4101
- const index = stack.indexOf(entry);
4102
- const next = { ...props };
4103
- if (index === -1) stack.push(next);
4104
- else stack[index] = next;
4105
- apply();
4106
- return next;
4107
- };
4108
- function StatusBarComponent(props) {
4109
- const entry = useRef(null);
4110
- const { animated, backgroundColor, barStyle, hidden, networkActivityIndicatorVisible, showHideTransition, translucent } = props;
4111
- useEffect(() => {
4112
- const next = {
4113
- animated,
4114
- backgroundColor,
4115
- barStyle,
4116
- hidden,
4117
- networkActivityIndicatorVisible,
4118
- showHideTransition,
4119
- translucent
4120
- };
4121
- entry.current = entry.current === null ? pushStackEntry(next) : replaceStackEntry(entry.current, next);
4122
- }, [
4123
- animated,
4124
- backgroundColor,
4125
- barStyle,
4126
- hidden,
4127
- networkActivityIndicatorVisible,
4128
- showHideTransition,
4129
- translucent
4130
- ]);
4131
- useEffect(() => {
4132
- return () => {
4133
- if (entry.current !== null) popStackEntry(entry.current);
4134
- entry.current = null;
4135
- };
4136
- }, []);
4137
- return null;
4138
- }
4139
- const StatusBar = Object.assign(StatusBarComponent, {
4140
- currentHeight: null,
4141
- setBarStyle: (style, _animated) => {
4142
- base.barStyle = style;
4143
- apply();
4144
- },
4145
- setBackgroundColor: (color, _animated) => {
4146
- base.backgroundColor = color;
4147
- apply();
4148
- },
4149
- setHidden: (hidden, _animation) => {
4150
- base.hidden = hidden;
4151
- apply();
4152
- },
4153
- setTranslucent: (translucent) => {
4154
- base.translucent = translucent;
4155
- apply();
4156
- },
4157
- setNetworkActivityIndicatorVisible: (visible) => {
4158
- base.networkActivityIndicatorVisible = visible;
4159
- apply();
4160
- },
4161
- pushStackEntry,
4162
- popStackEntry,
4163
- replaceStackEntry
4164
- });
4165
- // src/components/Switch/index.tsx
4166
- const TRACK_OFF = "#939393";
4167
- const TRACK_ON = "#A3D3CF";
4168
- const THUMB_OFF = "#FAFAFA";
4169
- const THUMB_ON = "#009688";
4170
- const INPUT_CLASS = "rn-switch-input";
4171
- const RULES = [
4172
- `.${INPUT_CLASS}{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:pointer;z-index:1}`,
4173
- `.${INPUT_CLASS}:disabled{cursor:default}`,
4174
- ".rn-switch-track{height:70%;border-radius:9999px;transition:background-color .15s}",
4175
- ".rn-switch-row{position:absolute;inset:0;display:flex;border-radius:9999px}",
4176
- ".rn-switch-spacer{flex-grow:0;transition:flex-grow .15s}",
4177
- ".rn-switch-thumb{height:100%;aspect-ratio:1;border-radius:50%;box-shadow:0 1px 3px rgba(0,0,0,.5);transition:background-color .15s}",
4178
- `.${INPUT_CLASS}:checked~.rn-switch-row>.rn-switch-spacer{flex-grow:1}`,
4179
- `.${INPUT_CLASS}:focus-visible~.rn-switch-row{outline:auto;outline-offset:2px}`,
4180
- "@media (prefers-reduced-motion:reduce){.rn-switch-track,.rn-switch-spacer,.rn-switch-thumb{transition:none}}"
4181
- ];
4182
- function Switch(props) {
4183
- const { accessibilityRole, accessibilityState, disabled, ios_backgroundColor: _iosBackgroundColor, onChange, onLayout, onTintColor: _onTintColor, onValueChange, pointerEvents, ref, role, style, thumbColor, thumbTintColor: _thumbTintColor, tintColor: _tintColor, trackColor, value, ...rest } = props;
4184
- const inputClass = useStyleRegistry().staticClass(INPUT_CLASS, RULES);
4185
- const on = value === true;
4186
- const resolvedDisabled = disabled ?? accessibilityState?.disabled;
4187
- const state = resolvedDisabled === accessibilityState?.disabled ? accessibilityState : {
4188
- ...accessibilityState,
4189
- disabled: resolvedDisabled
4190
- };
4191
- const handleChange = (event) => {
4192
- const next = event.target.checked;
4193
- Object.assign(event.nativeEvent, { value: next });
4194
- onChange?.(event);
4195
- onValueChange?.(next);
4196
- };
4197
- const inputProps = toDOMProps({
4198
- ...rest,
4199
- accessibilityState: state
4200
- });
4201
- inputProps["role"] = role ?? accessibilityRole ?? "switch";
4202
- const track = toCSSColor(on ? trackColor?.true : trackColor?.false) ?? (on ? TRACK_ON : TRACK_OFF);
4203
- const thumb = toCSSColor(thumbColor) ?? (on ? THUMB_ON : THUMB_OFF);
4204
- return /* @__PURE__ */ jsxs(View, {
4205
- onLayout,
4206
- pointerEvents,
4207
- style: [
4208
- styles.root,
4209
- style,
4210
- resolvedDisabled === true && styles.disabled
4211
- ],
4212
- children: [
4213
- /* @__PURE__ */ jsx("input", {
4214
- ...inputProps,
4215
- checked: on,
4216
- className: inputClass,
4217
- disabled: resolvedDisabled === true,
4218
- onChange: handleChange,
4219
- ref,
4220
- type: "checkbox"
4221
- }),
4222
- /* @__PURE__ */ jsx("div", {
4223
- className: "rn-switch-track",
4224
- style: { backgroundColor: track }
4225
- }),
4226
- /* @__PURE__ */ jsxs("div", {
4227
- className: "rn-switch-row",
4228
- children: [/* @__PURE__ */ jsx("div", { className: "rn-switch-spacer" }), /* @__PURE__ */ jsx("div", {
4229
- className: "rn-switch-thumb",
4230
- style: { backgroundColor: thumb }
4231
- })]
4232
- })
4233
- ]
4234
- });
4235
- }
4236
- const styles = StyleSheet.create({
4237
- root: {
4238
- alignSelf: "flex-start",
4239
- width: 40,
4240
- height: 20,
4241
- justifyContent: "center"
4242
- },
4243
- disabled: { opacity: .5 }
4244
- });
4245
- // src/components/TextInput/autocomplete.ts
4246
- const reactNativeToHTML = {
4247
- "address-line1": "address-line1",
4248
- "address-line2": "address-line2",
4249
- "birthdate-day": "bday-day",
4250
- "birthdate-full": "bday",
4251
- "birthdate-month": "bday-month",
4252
- "birthdate-year": "bday-year",
4253
- "cc-middle-name": "cc-additional-name",
4254
- gender: "sex",
4255
- "name-family": "family-name",
4256
- "name-given": "given-name",
4257
- "name-middle": "additional-name",
4258
- "name-middle-initial": "additional-name",
4259
- "name-prefix": "honorific-prefix",
4260
- "name-suffix": "honorific-suffix",
4261
- "postal-address": "street-address",
4262
- "postal-address-country": "country",
4263
- "postal-address-extended": "address-line2",
4264
- "postal-address-extended-postal-code": "postal-code",
4265
- "postal-address-locality": "address-level2",
4266
- "postal-address-region": "address-level1",
4267
- "sms-otp": "one-time-code",
4268
- "tel-device": "tel",
4269
- "username-new": "username"
4270
- };
4271
- const textContentTypeToHTML = {
4272
- none: "off",
4273
- URL: "url",
4274
- addressCity: "address-level2",
4275
- addressCityAndState: "address-level1",
4276
- addressState: "address-level1",
4277
- birthdate: "bday",
4278
- birthdateDay: "bday-day",
4279
- birthdateMonth: "bday-month",
4280
- birthdateYear: "bday-year",
4281
- countryName: "country-name",
4282
- creditCardExpiration: "cc-exp",
4283
- creditCardExpirationMonth: "cc-exp-month",
4284
- creditCardExpirationYear: "cc-exp-year",
4285
- creditCardFamilyName: "cc-family-name",
4286
- creditCardGivenName: "cc-given-name",
4287
- creditCardMiddleName: "cc-additional-name",
4288
- creditCardName: "cc-name",
4289
- creditCardNumber: "cc-number",
4290
- creditCardSecurityCode: "cc-csc",
4291
- creditCardType: "cc-type",
4292
- emailAddress: "email",
4293
- familyName: "family-name",
4294
- fullStreetAddress: "street-address",
4295
- givenName: "given-name",
4296
- jobTitle: "organization-title",
4297
- location: "street-address",
4298
- middleName: "additional-name",
4299
- name: "name",
4300
- namePrefix: "honorific-prefix",
4301
- nameSuffix: "honorific-suffix",
4302
- newPassword: "new-password",
4303
- nickname: "nickname",
4304
- oneTimeCode: "one-time-code",
4305
- organizationName: "organization",
4306
- password: "current-password",
4307
- postalCode: "postal-code",
4308
- streetAddressLine1: "address-line1",
4309
- streetAddressLine2: "address-line2",
4310
- sublocality: "address-level3",
4311
- telephoneNumber: "tel",
4312
- username: "username"
4313
- };
4314
- const toHTMLAutoComplete = (autoComplete, textContentType) => {
4315
- if (autoComplete !== void 0) return reactNativeToHTML[autoComplete] ?? autoComplete;
4316
- if (textContentType !== void 0) return textContentTypeToHTML[textContentType];
4317
- };
4318
- const keyboardTypeToInputMode = {
4319
- "decimal-pad": "decimal",
4320
- "email-address": "email",
4321
- "number-pad": "numeric",
4322
- numeric: "numeric",
4323
- "numbers-and-punctuation": "decimal",
4324
- "phone-pad": "tel",
4325
- url: "url",
4326
- "web-search": "search"
4327
- };
4328
- const toInputMode = (inputMode, keyboardType, showSoftInputOnFocus) => {
4329
- if (showSoftInputOnFocus === false) return "none";
4330
- if (inputMode !== void 0) return inputMode;
4331
- if (keyboardType !== void 0) return keyboardTypeToInputMode[keyboardType];
4332
- };
4333
- const returnKeyTypeToEnterKeyHint = {
4334
- done: "done",
4335
- go: "go",
4336
- next: "next",
4337
- search: "search",
4338
- send: "send"
4339
- };
4340
- const toEnterKeyHint = (enterKeyHint, returnKeyType) => {
4341
- if (enterKeyHint !== void 0) return enterKeyHint;
4342
- if (returnKeyType !== void 0) return returnKeyTypeToEnterKeyHint[returnKeyType];
4343
- };
4344
- // src/components/TextInput/index.tsx
4345
- const resetStyle = Object.freeze({
4346
- appearance: "none",
4347
- backgroundColor: "transparent",
4348
- border: "0 solid black",
4349
- borderRadius: 0,
4350
- boxSizing: "border-box",
4351
- color: "black",
4352
- display: "block",
4353
- fontFamily: "System",
4354
- fontSize: 14,
4355
- margin: 0,
4356
- minWidth: 0,
4357
- padding: 0,
4358
- position: "relative",
4359
- resize: "none",
4360
- textAlign: "start",
4361
- textDecoration: "none"
4362
- });
4363
- const textareaStyle = Object.freeze({
4364
- fieldSizing: "content",
4365
- overflow: "auto",
4366
- whiteSpace: "pre-wrap",
4367
- wordWrap: "break-word"
4368
- });
4369
- const supportsFieldSizing = hasDOM() && typeof CSS !== "undefined" && CSS.supports("field-sizing", "content");
4370
- const hash = (value) => {
4371
- let h = 5381;
4372
- for (let i = 0; i < value.length; i++) h = h * 33 ^ value.charCodeAt(i);
4373
- return (h >>> 0).toString(36);
4374
- };
4375
- const placeholderClass = (registry, color) => {
4376
- const css = toCSSColor(color);
4377
- if (css === void 0) return void 0;
4378
- const name = `rn-ph-${hash(css)}`;
4379
- return registry.staticClass(name, [`.${name}::placeholder{color:${css};opacity:1}`]);
4380
- };
4381
- const selectionClass = (registry, color) => {
4382
- const css = toCSSColor(color);
4383
- if (css === void 0) return void 0;
4384
- const name = `rn-sel-${hash(css)}`;
4385
- return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
4386
- };
4387
- const submitBehaviorOf = (submitBehavior, blurOnSubmit, multiline) => {
4388
- if (submitBehavior !== void 0) return submitBehavior;
4389
- if (multiline) return blurOnSubmit === true ? "blurAndSubmit" : "newline";
4390
- return blurOnSubmit === false ? "submit" : "blurAndSubmit";
4391
- };
4392
- const selectionOf = (field) => ({
4393
- start: field.selectionStart ?? 0,
4394
- end: field.selectionEnd ?? 0
4395
- });
4396
- const sameSelection = (a, b) => a !== null && a.start === b.start && a.end === b.end;
4397
- const isField = (node) => node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement;
4398
- function TextInputComponent(props) {
4399
- const { autoCapitalize, autoComplete, autoCorrect, autoFocus, blurOnSubmit: _blurOnSubmit, caretHidden, clearTextOnFocus: _clearTextOnFocus, contextMenuHidden: _contextMenuHidden, cursorColor, defaultValue, editable = true, enterKeyHint, inputMode, keyboardType, maxLength, multiline = false, numberOfLines, onBlur: _onBlur, onChange: _onChange, onChangeText: _onChangeText, onContentSizeChange, onContextMenu: _onContextMenu, onEndEditing: _onEndEditing, onFocus: _onFocus, onKeyDown: _onKeyDown, onKeyPress: _onKeyPress, onLayout, onScroll: _onScroll, onSelectionChange: _onSelectionChange, onSubmitEditing: _onSubmitEditing, placeholder, placeholderTextColor, readOnly, ref, returnKeyType, secureTextEntry, selectTextOnFocus: _selectTextOnFocus, selection, selectionColor, showSoftInputOnFocus, spellCheck, style, submitBehavior: _submitBehavior, textAlign, textContentType, value, allowFontScaling: _allowFontScaling, clearButtonMode: _clearButtonMode, dataDetectorTypes: _dataDetectorTypes, disableFullscreenUI: _disableFullscreenUI, enablesReturnKeyAutomatically: _enablesReturnKeyAutomatically, importantForAutofill: _importantForAutofill, inlineImageLeft: _inlineImageLeft, inlineImagePadding: _inlineImagePadding, keyboardAppearance: _keyboardAppearance, lineBreakStrategyIOS: _lineBreakStrategyIOS, maxFontSizeMultiplier: _maxFontSizeMultiplier, passwordRules: _passwordRules, rejectResponderTermination: _rejectResponderTermination, returnKeyLabel: _returnKeyLabel, scrollEnabled: _scrollEnabled, smartInsertDelete: _smartInsertDelete, textAlignVertical: _textAlignVertical, textBreakStrategy: _textBreakStrategy, underlineColorAndroid: _underlineColorAndroid, verticalAlign: _verticalAlign, ...rest } = props;
4400
- const registry = useStyleRegistry();
4401
- const field = useRef(null);
4402
- useElementLayout(field, onLayout);
4403
- const handlers = useRef(props);
4404
- useEffect(() => {
4405
- handlers.current = props;
4406
- });
4407
- const eventCount = useRef(0);
4408
- const lastSelection = useRef(null);
4409
- const lastContentSize = useRef(null);
4410
- const reportContentSize = useCallback((element) => {
4411
- const next = {
4412
- width: element.scrollWidth,
4413
- height: element.scrollHeight
4414
- };
4415
- const last = lastContentSize.current;
4416
- if (last !== null && last.width === next.width && last.height === next.height) return;
4417
- lastContentSize.current = next;
4418
- handlers.current.onContentSizeChange?.({ nativeEvent: { contentSize: next } });
4419
- }, []);
4420
- const grow = useCallback((element) => {
4421
- if (supportsFieldSizing || !(element instanceof HTMLTextAreaElement)) return;
4422
- if (handlers.current.style !== void 0) {
4423
- if (flattenStyle(handlers.current.style)?.["height"] !== void 0) return;
4424
- }
4425
- element.style.height = "auto";
4426
- element.style.height = `${element.scrollHeight}px`;
4427
- }, []);
4428
- const handleChange = useCallback((event) => {
4429
- const element = event.currentTarget;
4430
- const text = element.value;
4431
- eventCount.current += 1;
4432
- Object.assign(event.nativeEvent, {
4433
- text,
4434
- eventCount: eventCount.current
4435
- });
4436
- handlers.current.onChange?.(event);
4437
- handlers.current.onChangeText?.(text);
4438
- grow(element);
4439
- if (handlers.current.onContentSizeChange !== void 0) reportContentSize(element);
4440
- }, [grow, reportContentSize]);
4441
- const handleFocus = useCallback((event) => {
4442
- const element = event.currentTarget;
4443
- const current = handlers.current;
4444
- if (current.clearTextOnFocus === true && element.value !== "") {
4445
- element.value = "";
4446
- eventCount.current += 1;
4447
- current.onChangeText?.("");
4448
- }
4449
- if (current.selectTextOnFocus === true) element.select();
4450
- Object.assign(event.nativeEvent, {
4451
- text: element.value,
4452
- eventCount: eventCount.current
4453
- });
4454
- current.onFocus?.(event);
4455
- }, []);
4456
- const handleBlur = useCallback((event) => {
4457
- const element = event.currentTarget;
4458
- Object.assign(event.nativeEvent, {
4459
- text: element.value,
4460
- eventCount: eventCount.current
4461
- });
4462
- handlers.current.onBlur?.(event);
4463
- handlers.current.onEndEditing?.(event);
4464
- }, []);
4465
- const handleKeyDown = useCallback((event) => {
4466
- const current = handlers.current;
4467
- current.onKeyDown?.(event);
4468
- current.onKeyPress?.(event);
4469
- if (event.defaultPrevented || event.key !== "Enter" || event.shiftKey) return;
4470
- const isMultiline = current.multiline === true;
4471
- const behavior = submitBehaviorOf(current.submitBehavior, current.blurOnSubmit, isMultiline);
4472
- if (behavior === "newline") return;
4473
- if (isMultiline) event.preventDefault();
4474
- const element = event.currentTarget;
4475
- Object.assign(event.nativeEvent, { text: element.value });
4476
- current.onSubmitEditing?.(event);
4477
- if (behavior === "blurAndSubmit") element.blur();
4478
- }, []);
4479
- const handleSelect = useCallback((event) => {
4480
- const next = selectionOf(event.currentTarget);
4481
- if (sameSelection(lastSelection.current, next)) return;
4482
- lastSelection.current = next;
4483
- Object.assign(event.nativeEvent, { selection: next });
4484
- handlers.current.onSelectionChange?.(event);
4485
- }, []);
4486
- const handleScroll = useCallback((event) => {
4487
- const element = event.currentTarget;
4488
- Object.assign(event.nativeEvent, {
4489
- contentInset: {
4490
- top: 0,
4491
- left: 0,
4492
- bottom: 0,
4493
- right: 0
4494
- },
4495
- contentOffset: {
4496
- x: element.scrollLeft,
4497
- y: element.scrollTop
4498
- },
4499
- contentSize: {
4500
- width: element.scrollWidth,
4501
- height: element.scrollHeight
4502
- },
4503
- layoutMeasurement: {
4504
- width: element.clientWidth,
4505
- height: element.clientHeight
4506
- },
4507
- zoomScale: 1
4508
- });
4509
- handlers.current.onScroll?.(event);
4510
- }, []);
4511
- const handleContextMenu = useCallback((event) => {
4512
- handlers.current.onContextMenu?.(event);
4513
- if (handlers.current.contextMenuHidden === true) event.preventDefault();
4514
- }, []);
4515
- const selectionStart = selection?.start;
4516
- const selectionEnd = selection?.end ?? selection?.start;
4517
- useLayoutEffect(() => {
4518
- const element = field.current;
4519
- if (element === null || selectionStart === void 0 || selectionEnd === void 0) return;
4520
- if (element.selectionStart === selectionStart && element.selectionEnd === selectionEnd) return;
4521
- element.setSelectionRange(selectionStart, selectionEnd);
4522
- lastSelection.current = {
4523
- start: selectionStart,
4524
- end: selectionEnd
4525
- };
4526
- }, [
4527
- selectionStart,
4528
- selectionEnd,
4529
- value
4530
- ]);
4531
- useLayoutEffect(() => {
4532
- const element = field.current;
4533
- if (element === null) return;
4534
- grow(element);
4535
- }, [
4536
- grow,
4537
- value,
4538
- multiline
4539
- ]);
4540
- const wantsContentSize = onContentSizeChange !== void 0;
4541
- useEffect(() => {
4542
- const element = field.current;
4543
- if (element === null || !wantsContentSize) return;
4544
- reportContentSize(element);
4545
- const observer = new ResizeObserver(() => reportContentSize(element));
4546
- observer.observe(element);
4547
- return () => observer.disconnect();
4548
- }, [wantsContentSize, reportContentSize]);
4549
- useImperativeHandle(ref, () => {
4550
- const element = field.current;
4551
- return Object.assign(withHostMethods(element), {
4552
- clear: () => {
4553
- element.value = "";
4554
- grow(element);
4555
- handlers.current.onChangeText?.("");
4556
- },
4557
- isFocused: () => document.activeElement === element,
4558
- getNativeRef: () => element,
4559
- setNativeProps: ({ text, ...others }) => {
4560
- if (text !== void 0) element.value = text;
4561
- applyNativeProps(element, others);
4562
- grow(element);
4563
- }
4564
- });
4565
- }, [grow]);
4566
- const flat = flattenStyle(style);
4567
- const colorStyle = {};
4568
- const caret = cursorColor ?? selectionColor;
4569
- if (caretHidden === true) colorStyle["caretColor"] = "transparent";
4570
- else if (caret !== void 0) colorStyle["caretColor"] = caret;
4571
- if (textAlign !== void 0) colorStyle["textAlign"] = textAlign;
4572
- let className = joinClassNames(compileReset("rn-text-input", resetStyle, registry), multiline === true && compileReset("rn-text-input-multiline", textareaStyle, registry), compileStyle([flat, colorStyle], registry));
4573
- const placeholderName = placeholderClass(registry, placeholderTextColor);
4574
- if (placeholderName !== void 0) className = `${className} ${placeholderName}`;
4575
- const selectionName = selectionClass(registry, selectionColor);
4576
- if (selectionName !== void 0) className = `${className} ${selectionName}`;
4577
- const domProps = toDOMProps(rest);
4578
- domProps["className"] = className;
4579
- domProps["value"] = value;
4580
- domProps["defaultValue"] = defaultValue;
4581
- domProps["placeholder"] = placeholder;
4582
- domProps["readOnly"] = readOnly === true || !editable ? true : void 0;
4583
- domProps["maxLength"] = maxLength;
4584
- domProps["autoFocus"] = autoFocus;
4585
- domProps["autoCapitalize"] = autoCapitalize;
4586
- domProps["autoCorrect"] = autoCorrect === void 0 ? void 0 : autoCorrect ? "on" : "off";
4587
- domProps["spellCheck"] = spellCheck;
4588
- domProps["autoComplete"] = toHTMLAutoComplete(autoComplete, textContentType);
4589
- domProps["inputMode"] = toInputMode(inputMode, keyboardType, showSoftInputOnFocus);
4590
- domProps["enterKeyHint"] = toEnterKeyHint(enterKeyHint, returnKeyType);
4591
- domProps["dir"] ??= "auto";
4592
- domProps["onChange"] = handleChange;
4593
- domProps["onFocus"] = handleFocus;
4594
- domProps["onBlur"] = handleBlur;
4595
- domProps["onKeyDown"] = handleKeyDown;
4596
- domProps["onSelect"] = handleSelect;
4597
- domProps["onContextMenu"] = handleContextMenu;
4598
- if (multiline) {
4599
- domProps["rows"] = numberOfLines ?? 1;
4600
- domProps["onScroll"] = handleScroll;
4601
- return /* @__PURE__ */ jsx("textarea", {
4602
- ...domProps,
4603
- ref: field
4604
- });
4605
- }
4606
- domProps["type"] = secureTextEntry === true ? "password" : "text";
4607
- return /* @__PURE__ */ jsx("input", {
4608
- ...domProps,
4609
- ref: field
4610
- });
4611
- }
4612
- const TextInput = Object.assign(TextInputComponent, { State: {
4613
- currentlyFocusedInput: () => {
4614
- if (!hasDOM()) return null;
4615
- const active = document.activeElement;
4616
- return isField(active) ? active : null;
4617
- },
4618
- focusTextInput: (input) => input?.focus(),
4619
- blurTextInput: (input) => input?.blur()
4620
- } });
4621
- // src/components/TouchableHighlight/index.tsx
4622
- const DEFAULT_ACTIVE_OPACITY = .85;
4623
- const DEFAULT_UNDERLAY_COLOR = "black";
4624
- const notCancelableStyle = Object.freeze({ touchAction: "none" });
4625
- function TouchableHighlight(props) {
4626
- const { activeOpacity, children, delayLongPress, delayPressIn, delayPressOut, disabled, focusable, hasTVPreferredFocus: _hasTVPreferredFocus, hitSlop, nextFocusDown: _nextFocusDown, nextFocusForward: _nextFocusForward, nextFocusLeft: _nextFocusLeft, nextFocusRight: _nextFocusRight, nextFocusUp: _nextFocusUp, onBlur, onFocus, onHideUnderlay, onLongPress, onPress, onPressIn, onPressOut, onShowUnderlay, pressRetentionOffset, rejectResponderTermination, style, testOnly_pressed, touchSoundDisabled, underlayColor, ...rest } = props;
4627
- const [underlay, setUnderlay] = useState(false);
4628
- const hideTimer = useRef(null);
4629
- const resolvedDisabled = disabled ?? props.accessibilityState?.disabled;
4630
- const hasPressHandler = onPress != null || onPressIn != null || onPressOut != null || onLongPress != null;
4631
- const handlers = usePressability(useMemo(() => {
4632
- const clearHideTimer = () => {
4633
- if (hideTimer.current !== null) clearTimeout(hideTimer.current);
4634
- hideTimer.current = null;
4635
- };
4636
- const show = () => {
4637
- if (!hasPressHandler) return;
4638
- setUnderlay(true);
4639
- onShowUnderlay?.();
4640
- };
4641
- const hide = () => {
4642
- clearHideTimer();
4643
- if (testOnly_pressed === true || !hasPressHandler) return;
4644
- setUnderlay(false);
4645
- onHideUnderlay?.();
4646
- };
4647
- return {
4648
- cancelable: rejectResponderTermination !== true,
4649
- disabled: resolvedDisabled,
4650
- hitSlop,
4651
- delayLongPress,
4652
- delayPressIn,
4653
- delayPressOut,
4654
- minPressDuration: 0,
4655
- pressRectOffset: pressRetentionOffset,
4656
- android_disableSound: touchSoundDisabled,
4657
- onBlur,
4658
- onFocus,
4659
- onLongPress,
4660
- onPress: (event) => {
4661
- clearHideTimer();
4662
- show();
4663
- hideTimer.current = setTimeout(hide, delayPressOut ?? 0);
4664
- onPress?.(event);
4665
- },
4666
- onPressIn: (event) => {
4667
- clearHideTimer();
4668
- show();
4669
- onPressIn?.(event);
4670
- },
4671
- onPressOut: (event) => {
4672
- if (hideTimer.current === null) hide();
4673
- onPressOut?.(event);
4674
- }
4675
- };
4676
- }, [
4677
- delayLongPress,
4678
- delayPressIn,
4679
- delayPressOut,
4680
- hasPressHandler,
4681
- hitSlop,
4682
- onBlur,
4683
- onFocus,
4684
- onHideUnderlay,
4685
- onLongPress,
4686
- onPress,
4687
- onPressIn,
4688
- onPressOut,
4689
- onShowUnderlay,
4690
- pressRetentionOffset,
4691
- rejectResponderTermination,
4692
- resolvedDisabled,
4693
- testOnly_pressed,
4694
- touchSoundDisabled
4695
- ]));
4696
- const registry = useStyleRegistry();
4697
- useEffect(() => () => {
4698
- if (hideTimer.current !== null) clearTimeout(hideTimer.current);
4699
- }, []);
4700
- const pressed = underlay || testOnly_pressed === true;
4701
- const child = Children.only(children);
4702
- if (child.type === Fragment) warnOnce("TouchableHighlight-fragment", "TouchableHighlight does not support a Fragment as its child. Wrap the children in one View.");
4703
- const content = child.type === Fragment ? child : cloneElement(child, { style: [child.props.style, pressed && { opacity: activeOpacity ?? DEFAULT_ACTIVE_OPACITY }] });
4704
- return useViewElement({
4705
- ...rest,
4706
- ...mergeHandlers(rest, handlers),
4707
- focusable: focusable !== false && onPress !== void 0 && disabled !== true,
4708
- style: [
4709
- style,
4710
- pressed && { backgroundColor: underlayColor ?? DEFAULT_UNDERLAY_COLOR },
4711
- rejectResponderTermination === true && notCancelableStyle
4712
- ],
4713
- children: content,
4714
- ...resolvedDisabled === true && { "aria-disabled": true }
4715
- }, hitSlopClass(registry, hitSlop));
4716
- }
4717
- // src/components/TouchableWithoutFeedback/index.tsx
4718
- const isTrue = (value) => value === void 0 ? void 0 : value === true || value === "true";
4719
- function TouchableWithoutFeedback(props) {
4720
- const { children, delayLongPress, delayPressIn, delayPressOut, disabled, focusable, hitSlop, onBlur, onFocus, onLongPress, onPress, onPressIn, onPressOut, pressRetentionOffset, rejectResponderTermination, style: _style, touchSoundDisabled, ...rest } = props;
4721
- const resolvedDisabled = disabled ?? isTrue(props["aria-disabled"]) ?? props.accessibilityState?.disabled;
4722
- const handlers = usePressability(useMemo(() => ({
4723
- cancelable: rejectResponderTermination !== true,
4724
- disabled: resolvedDisabled,
4725
- hitSlop,
4726
- delayLongPress,
4727
- delayPressIn,
4728
- delayPressOut,
4729
- minPressDuration: 0,
4730
- pressRectOffset: pressRetentionOffset,
4731
- android_disableSound: touchSoundDisabled,
4732
- onBlur,
4733
- onFocus,
4734
- onLongPress,
4735
- onPress,
4736
- onPressIn,
4737
- onPressOut
4738
- }), [
4739
- delayLongPress,
4740
- delayPressIn,
4741
- delayPressOut,
4742
- hitSlop,
4743
- onBlur,
4744
- onFocus,
4745
- onLongPress,
4746
- onPress,
4747
- onPressIn,
4748
- onPressOut,
4749
- pressRetentionOffset,
4750
- rejectResponderTermination,
4751
- resolvedDisabled,
4752
- touchSoundDisabled
4753
- ]));
4754
- const element = Children.only(children);
4755
- const passed = {};
4756
- for (const [name, value] of Object.entries(rest)) if (value !== void 0) passed[name] = value;
4757
- if (hitSlop !== void 0) passed["hitSlop"] = hitSlop;
4758
- if (disabled != null) passed["accessibilityState"] = {
4759
- ...rest.accessibilityState,
4760
- disabled
4761
- };
4762
- const merged = mergeHandlers(element.props, handlers);
4763
- const childFocus = onFocus === void 0 ? element.props.onFocus : void 0;
4764
- const childBlur = onBlur === void 0 ? element.props.onBlur : void 0;
4765
- return cloneElement(element, {
4766
- ...passed,
4767
- ...merged,
4768
- onFocus: childFocus === void 0 ? merged.onFocus : (event) => {
4769
- merged.onFocus(event);
4770
- childFocus(event);
4771
- },
4772
- onBlur: childBlur === void 0 ? merged.onBlur : (event) => {
4773
- merged.onBlur(event);
4774
- childBlur(event);
4775
- },
4776
- accessible: rest.accessible !== false,
4777
- focusable: focusable !== false && onPress !== void 0 && disabled !== true
4778
- });
4779
- }
4780
- // src/components/TouchableNativeFeedback/index.tsx
4781
- const TouchableNativeFeedback = Object.assign(function TouchableNativeFeedback(props) {
4782
- const { background: _background, hasTVPreferredFocus: _hasTVPreferredFocus, nextFocusDown: _nextFocusDown, nextFocusForward: _nextFocusForward, nextFocusLeft: _nextFocusLeft, nextFocusRight: _nextFocusRight, nextFocusUp: _nextFocusUp, useForeground: _useForeground, ...rest } = props;
4783
- return createElement(TouchableWithoutFeedback, rest);
4784
- }, {
4785
- SelectableBackground: (rippleRadius) => ({
4786
- type: "ThemeAttrAndroid",
4787
- attribute: "selectableItemBackground",
4788
- rippleRadius
4789
- }),
4790
- SelectableBackgroundBorderless: (rippleRadius) => ({
4791
- type: "ThemeAttrAndroid",
4792
- attribute: "selectableItemBackgroundBorderless",
4793
- rippleRadius
4794
- }),
4795
- Ripple: (color, borderless, rippleRadius) => ({
4796
- type: "RippleAndroid",
4797
- color: processColor(color),
4798
- borderless,
4799
- rippleRadius
4800
- }),
4801
- canUseNativeForeground: () => false
4802
- });
4803
- // src/compat/createElement/index.tsx
4804
- const mappedProps = /* @__PURE__ */ new Set([
4805
- "focusable",
4806
- "importantForAccessibility",
4807
- "nativeID",
4808
- "testID"
4809
- ]);
4810
- const isNativeOnly = (name) => mappedProps.has(name) || name.startsWith("accessibility") || isNativeHandler(name);
4811
- function Host({ type, props }) {
4812
- const registry = useStyleRegistry();
4813
- const { className, style, ...rest } = props;
4814
- const domProps = {};
4815
- for (const name in rest) if (!isNativeOnly(name)) domProps[name] = rest[name];
4816
- Object.assign(domProps, toDOMProps(rest));
4817
- const compiled = compileStyle(style, registry);
4818
- const classes = typeof className === "string" && className !== "" ? [className] : [];
4819
- if (compiled !== "") classes.push(compiled);
4820
- if (classes.length > 0) domProps["className"] = classes.join(" ");
4821
- return createElement(type, domProps);
4822
- }
4823
- /**
4824
- * Compat export. Renders `type` with React Native props: `style` compiles to class names, and
4825
- * the accessibility props become ARIA attributes. Every other prop goes to the element as it
4826
- * is. Libraries such as `react-native-svg` import it from `react-native` on the web.
4827
- */
4828
- const unstable_createElement = (type, props) => {
4829
- const hostProps = props ?? {};
4830
- return createElement(Host, {
4831
- key: hostProps["key"],
4832
- type,
4833
- props: hostProps
4834
- });
4835
- };
4836
- // src/compat/findNodeHandle/index.ts
4837
- const isElement = (value) => value.nodeType === 1;
4838
- /**
4839
- * Compat export. On native it returns the tag of a view. On the web it returns the DOM element
4840
- * of a ref, of an element, or of a scroll component. A number comes back as it is. A class
4841
- * component instance gives `null`, because React has no `findDOMNode`.
4842
- */
4843
- const findNodeHandle = (componentOrHandle) => {
4844
- if (typeof componentOrHandle === "number") return componentOrHandle;
4845
- if (typeof componentOrHandle !== "object" || componentOrHandle === null) return null;
4846
- if (isElement(componentOrHandle)) return componentOrHandle;
4847
- const { getScrollableNode } = componentOrHandle;
4848
- if (typeof getScrollableNode === "function") return findNodeHandle(getScrollableNode.call(componentOrHandle));
4849
- if ("current" in componentOrHandle) return findNodeHandle(componentOrHandle.current);
4850
- return null;
4851
- };
4852
- // src/compat/TurboModuleRegistry/index.ts
4853
- /**
4854
- * Compat export. A browser has no native modules, so `get` always returns `null`. A library
4855
- * that reads its native module at import time then takes its JavaScript path.
4856
- */
4857
- const TurboModuleRegistry = {
4858
- get: () => null,
4859
- getEnforcing: (name) => {
4860
- throw new Error(`TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. A browser has no native modules.`);
4861
- }
4862
- };
1
+ import { AccessibilityInfo } from "./apis/AccessibilityInfo/index.js";
2
+ import { Alert } from "./apis/Alert/index.js";
3
+ import { Appearance } from "./apis/Appearance/index.js";
4
+ import { AppState } from "./apis/AppState/index.js";
5
+ import { BackHandler } from "./apis/BackHandler/index.js";
6
+ import { Clipboard } from "./apis/Clipboard/index.js";
7
+ import { Dimensions } from "./apis/Dimensions/index.js";
8
+ import { I18nManager } from "./apis/I18nManager/index.js";
9
+ import { Keyboard } from "./apis/Keyboard/index.js";
10
+ import { Linking } from "./apis/Linking/index.js";
11
+ import { PanResponder } from "./apis/PanResponder/index.js";
12
+ import { PixelRatio } from "./apis/PixelRatio/index.js";
13
+ import { Platform } from "./apis/Platform/index.js";
14
+ import { processColor } from "./apis/processColor/index.js";
15
+ import { Share } from "./apis/Share/index.js";
16
+ import { StyleSheet } from "./apis/StyleSheet/index.js";
17
+ import { useColorScheme } from "./apis/useColorScheme/index.js";
18
+ import { useWindowDimensions } from "./apis/useWindowDimensions/index.js";
19
+ import { Vibration } from "./apis/Vibration/index.js";
20
+ import { ActivityIndicator } from "./components/ActivityIndicator/index.js";
21
+ import { Button } from "./components/Button/index.js";
22
+ import { FlatList } from "./components/FlatList/index.js";
23
+ import { TextAncestorContext } from "./components/Text/TextAncestorContext.js";
24
+ import { Image } from "./components/Image/index.js";
25
+ import { KeyboardAvoidingView } from "./components/KeyboardAvoidingView/index.js";
26
+ import { Modal } from "./components/Modal/index.js";
27
+ import { Pressable } from "./components/Pressable/index.js";
28
+ import { RefreshControl } from "./components/RefreshControl/index.js";
29
+ import { ScrollView } from "./components/ScrollView/index.js";
30
+ import { StatusBar } from "./components/StatusBar/index.js";
31
+ import { Switch } from "./components/Switch/index.js";
32
+ import { Text } from "./components/Text/index.js";
33
+ import { TextInput } from "./components/TextInput/index.js";
34
+ import { TouchableHighlight } from "./components/TouchableHighlight/index.js";
35
+ import { TouchableNativeFeedback } from "./components/TouchableNativeFeedback/index.js";
36
+ import { TouchableOpacity } from "./components/TouchableOpacity/index.js";
37
+ import { TouchableWithoutFeedback } from "./components/TouchableWithoutFeedback/index.js";
38
+ import { View } from "./components/View/index.js";
39
+ import { unstable_createElement } from "./compat/createElement/index.js";
40
+ import { findNodeHandle } from "./compat/findNodeHandle/index.js";
41
+ import { TurboModuleRegistry } from "./compat/TurboModuleRegistry/index.js";
42
+ import { usePressability } from "./events/press/usePressability.js";
4863
43
  export { AccessibilityInfo, ActivityIndicator, Alert, AppState, Appearance, BackHandler, Button, Clipboard, Dimensions, FlatList, I18nManager, Image, Keyboard, KeyboardAvoidingView, Linking, Modal, PanResponder, PixelRatio, Platform, Pressable, RefreshControl, ScrollView, Share, StatusBar, StyleSheet, Switch, Text, TextAncestorContext, TextInput, TouchableHighlight, TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, TurboModuleRegistry, Vibration, View, findNodeHandle, processColor, unstable_createElement, useColorScheme, usePressability, useWindowDimensions };
4864
-
4865
- //# sourceMappingURL=index.js.map