@rootnative/web 0.0.0-alpha.2 → 0.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/CHANGELOG.md +66 -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/assets-registry/index.d.ts +18 -0
  62. package/dist/assets-registry/index.js +12 -0
  63. package/dist/assets-registry/index.js.map +1 -0
  64. package/dist/bundler/index.js +30 -0
  65. package/dist/bundler/index.js.map +1 -0
  66. package/dist/bundler/inlinePlatformOS.js +121 -0
  67. package/dist/bundler/inlinePlatformOS.js.map +1 -0
  68. package/dist/bundler/worklets.js +61 -0
  69. package/dist/bundler/worklets.js.map +1 -0
  70. package/dist/compat/TurboModuleRegistry/index.d.ts +16 -0
  71. package/dist/compat/TurboModuleRegistry/index.js +14 -0
  72. package/dist/compat/TurboModuleRegistry/index.js.map +1 -0
  73. package/dist/compat/createElement/index.d.ts +9 -0
  74. package/dist/compat/createElement/index.js +40 -0
  75. package/dist/compat/createElement/index.js.map +1 -0
  76. package/dist/compat/findNodeHandle/index.d.ts +7 -0
  77. package/dist/compat/findNodeHandle/index.js +19 -0
  78. package/dist/compat/findNodeHandle/index.js.map +1 -0
  79. package/dist/components/ActivityIndicator/index.d.ts +5 -0
  80. package/dist/components/ActivityIndicator/index.js +74 -0
  81. package/dist/components/ActivityIndicator/index.js.map +1 -0
  82. package/dist/components/ActivityIndicator/types.d.ts +8 -0
  83. package/dist/components/Button/index.d.ts +5 -0
  84. package/dist/components/Button/index.js +48 -0
  85. package/dist/components/Button/index.js.map +1 -0
  86. package/dist/components/Button/types.d.ts +31 -0
  87. package/dist/components/FlatList/index.d.ts +5 -0
  88. package/dist/components/FlatList/index.js +433 -0
  89. package/dist/components/FlatList/index.js.map +1 -0
  90. package/dist/components/FlatList/types.d.ts +138 -0
  91. package/dist/components/FlatList/viewability.js +86 -0
  92. package/dist/components/FlatList/viewability.js.map +1 -0
  93. package/dist/components/Image/index.d.ts +7 -0
  94. package/dist/components/Image/index.js +301 -0
  95. package/dist/components/Image/index.js.map +1 -0
  96. package/dist/components/Image/source.js +97 -0
  97. package/dist/components/Image/source.js.map +1 -0
  98. package/dist/components/Image/types.d.ts +96 -0
  99. package/dist/components/KeyboardAvoidingView/index.d.ts +10 -0
  100. package/dist/components/KeyboardAvoidingView/index.js +118 -0
  101. package/dist/components/KeyboardAvoidingView/index.js.map +1 -0
  102. package/dist/components/KeyboardAvoidingView/types.d.ts +14 -0
  103. package/dist/components/Modal/index.d.ts +9 -0
  104. package/dist/components/Modal/index.js +271 -0
  105. package/dist/components/Modal/index.js.map +1 -0
  106. package/dist/components/Modal/types.d.ts +29 -0
  107. package/dist/components/Pressable/index.d.ts +5 -0
  108. package/dist/components/Pressable/index.js +106 -0
  109. package/dist/components/Pressable/index.js.map +1 -0
  110. package/dist/components/Pressable/types.d.ts +44 -0
  111. package/dist/components/RefreshControl/index.d.ts +5 -0
  112. package/dist/components/RefreshControl/index.js +176 -0
  113. package/dist/components/RefreshControl/index.js.map +1 -0
  114. package/dist/components/RefreshControl/pull.js +16 -0
  115. package/dist/components/RefreshControl/pull.js.map +1 -0
  116. package/dist/components/RefreshControl/types.d.ts +14 -0
  117. package/dist/components/ScrollView/index.d.ts +5 -0
  118. package/dist/components/ScrollView/index.js +318 -0
  119. package/dist/components/ScrollView/index.js.map +1 -0
  120. package/dist/components/ScrollView/snap.js +38 -0
  121. package/dist/components/ScrollView/snap.js.map +1 -0
  122. package/dist/components/ScrollView/types.d.ts +115 -0
  123. package/dist/components/StatusBar/index.d.ts +26 -0
  124. package/dist/components/StatusBar/index.js +113 -0
  125. package/dist/components/StatusBar/index.js.map +1 -0
  126. package/dist/components/Switch/index.d.ts +5 -0
  127. package/dist/components/Switch/index.js +89 -0
  128. package/dist/components/Switch/index.js.map +1 -0
  129. package/dist/components/Switch/types.d.ts +25 -0
  130. package/dist/components/Text/TextAncestorContext.d.ts +3 -0
  131. package/dist/components/Text/TextAncestorContext.js +6 -0
  132. package/dist/components/Text/TextAncestorContext.js.map +1 -0
  133. package/dist/components/Text/index.d.ts +6 -0
  134. package/dist/components/Text/index.js +133 -0
  135. package/dist/components/Text/index.js.map +1 -0
  136. package/dist/components/Text/types.d.ts +38 -0
  137. package/dist/components/TextInput/autocomplete.js +102 -0
  138. package/dist/components/TextInput/autocomplete.js.map +1 -0
  139. package/dist/components/TextInput/index.d.ts +8 -0
  140. package/dist/components/TextInput/index.js +290 -0
  141. package/dist/components/TextInput/index.js.map +1 -0
  142. package/dist/components/TextInput/types.d.ts +130 -0
  143. package/dist/components/TouchableHighlight/index.d.ts +5 -0
  144. package/dist/components/TouchableHighlight/index.js +109 -0
  145. package/dist/components/TouchableHighlight/index.js.map +1 -0
  146. package/dist/components/TouchableHighlight/types.d.ts +15 -0
  147. package/dist/components/TouchableNativeFeedback/index.d.ts +11 -0
  148. package/dist/components/TouchableNativeFeedback/index.js +29 -0
  149. package/dist/components/TouchableNativeFeedback/index.js.map +1 -0
  150. package/dist/components/TouchableNativeFeedback/types.d.ts +19 -0
  151. package/dist/components/TouchableOpacity/index.d.ts +5 -0
  152. package/dist/components/TouchableOpacity/index.js +122 -0
  153. package/dist/components/TouchableOpacity/index.js.map +1 -0
  154. package/dist/components/TouchableOpacity/types.d.ts +11 -0
  155. package/dist/components/TouchableWithoutFeedback/index.d.ts +5 -0
  156. package/dist/components/TouchableWithoutFeedback/index.js +70 -0
  157. package/dist/components/TouchableWithoutFeedback/index.js.map +1 -0
  158. package/dist/components/TouchableWithoutFeedback/types.d.ts +40 -0
  159. package/dist/components/View/index.d.ts +5 -0
  160. package/dist/components/View/index.js +50 -0
  161. package/dist/components/View/index.js.map +1 -0
  162. package/dist/components/View/types.d.ts +98 -0
  163. package/dist/dom/Head.d.ts +21 -0
  164. package/dist/dom/Head.js +53 -0
  165. package/dist/dom/Head.js.map +1 -0
  166. package/dist/dom/index.d.ts +2 -22
  167. package/dist/dom/index.js +1 -53
  168. package/dist/events/press/Pressability.d.ts +2 -0
  169. package/dist/events/press/Pressability.js +366 -0
  170. package/dist/events/press/Pressability.js.map +1 -0
  171. package/dist/events/press/cursorStyle.js +5 -0
  172. package/dist/events/press/cursorStyle.js.map +1 -0
  173. package/dist/events/press/index.d.ts +4 -0
  174. package/dist/events/press/mergeHandlers.js +30 -0
  175. package/dist/events/press/mergeHandlers.js.map +1 -0
  176. package/dist/events/press/types.d.ts +48 -0
  177. package/dist/events/press/usePressability.d.ts +4 -0
  178. package/dist/events/press/usePressability.js +18 -0
  179. package/dist/events/press/usePressability.js.map +1 -0
  180. package/dist/events/responderEvent.js +50 -0
  181. package/dist/events/responderEvent.js.map +1 -0
  182. package/dist/events/types.d.ts +33 -0
  183. package/dist/index.d.ts +66 -1009
  184. package/dist/index.js +43 -3872
  185. package/dist/reactNativeVersion.d.ts +7 -0
  186. package/dist/reactNativeVersion.js +10 -0
  187. package/dist/reactNativeVersion.js.map +1 -0
  188. package/dist/render/domProps.js +66 -0
  189. package/dist/render/domProps.js.map +1 -0
  190. package/dist/render/hitSlop.js +21 -0
  191. package/dist/render/hitSlop.js.map +1 -0
  192. package/dist/render/hostMethods.js +44 -0
  193. package/dist/render/hostMethods.js.map +1 -0
  194. package/dist/render/resolveTag.js +64 -0
  195. package/dist/render/resolveTag.js.map +1 -0
  196. package/dist/render/useElementLayout.js +25 -0
  197. package/dist/render/useElementLayout.js.map +1 -0
  198. package/dist/server/index.d.ts +2 -23
  199. package/dist/server/index.js +8 -4
  200. package/dist/server/index.js.map +1 -1
  201. package/dist/style/StyleRegistryContext.js +8 -0
  202. package/dist/style/StyleRegistryContext.js.map +1 -0
  203. package/dist/style/color.js +16 -0
  204. package/dist/style/color.js.map +1 -0
  205. package/dist/style/compile.js +72 -0
  206. package/dist/style/compile.js.map +1 -0
  207. package/dist/style/direction.js +33 -0
  208. package/dist/style/direction.js.map +1 -0
  209. package/dist/style/index.d.ts +25 -0
  210. package/dist/style/index.js +38 -0
  211. package/dist/style/index.js.map +1 -0
  212. package/dist/style/registry.d.ts +27 -0
  213. package/dist/{StyleRegistryContext-CAD45r4n.js → style/registry.js} +32 -10
  214. package/dist/style/registry.js.map +1 -0
  215. package/dist/style/resolveStyle.js +181 -0
  216. package/dist/style/resolveStyle.js.map +1 -0
  217. package/dist/style/shadow.js +87 -0
  218. package/dist/style/shadow.js.map +1 -0
  219. package/dist/style/splitLayoutProps.js +52 -0
  220. package/dist/style/splitLayoutProps.js.map +1 -0
  221. package/dist/style/transform.js +35 -0
  222. package/dist/style/transform.js.map +1 -0
  223. package/dist/style/types.d.ts +4 -0
  224. package/dist/style/units.js +21 -0
  225. package/dist/style/units.js.map +1 -0
  226. package/dist/style/webStyle.js +9 -0
  227. package/dist/style/webStyle.js.map +1 -0
  228. package/dist/{env-DK5Mt9yX.js → utils/env.js} +2 -2
  229. package/dist/utils/env.js.map +1 -0
  230. package/dist/utils/scrollLock.js +28 -0
  231. package/dist/utils/scrollLock.js.map +1 -0
  232. package/dist/utils/warn.js +11 -0
  233. package/dist/utils/warn.js.map +1 -0
  234. package/dist/vite/index.d.ts +9 -1
  235. package/dist/vite/index.js +71 -174
  236. package/dist/vite/index.js.map +1 -1
  237. package/llms.txt +203 -22
  238. package/package.json +16 -3
  239. package/dist/StyleRegistryContext-CAD45r4n.js.map +0 -1
  240. package/dist/dom/index.js.map +0 -1
  241. package/dist/env-DK5Mt9yX.js.map +0 -1
  242. package/dist/index.js.map +0 -1
  243. package/dist/types-BxTWbdj9.d.ts +0 -5
package/dist/index.js CHANGED
@@ -1,3872 +1,43 @@
1
- import { i as matchesMedia, n as isProductionEnv, r as isTestEnv, t as hasDOM } from "./env-DK5Mt9yX.js";
2
- import { n as useStyleRegistry, o as getStyleRegistry } from "./StyleRegistryContext-CAD45r4n.js";
3
- import normalizeColor from "@react-native/normalize-colors";
4
- import { Children, Fragment, cloneElement, createContext, createElement, isValidElement, memo, useCallback, useContext, useEffect, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
- import { jsx, jsxs } from "react/jsx-runtime";
6
- // src/apis/AccessibilityInfo/index.ts
7
- const mediaQueryOf = {
8
- reduceMotionChanged: "(prefers-reduced-motion: reduce)",
9
- reduceTransparencyChanged: "(prefers-reduced-transparency: reduce)",
10
- invertColorsChanged: "(inverted-colors: inverted)",
11
- darkerSystemColorsChanged: "(prefers-contrast: more)",
12
- highTextContrastChanged: "(prefers-contrast: more)"
13
- };
14
- const resolve = (value) => Promise.resolve(value);
15
- let liveRegion = null;
16
- const getLiveRegion = () => {
17
- if (!hasDOM()) return null;
18
- if (liveRegion !== null && liveRegion.isConnected) return liveRegion;
19
- const element = document.createElement("div");
20
- element.setAttribute("aria-live", "polite");
21
- element.setAttribute("aria-atomic", "true");
22
- element.setAttribute("data-rn-announcer", "");
23
- Object.assign(element.style, {
24
- position: "absolute",
25
- width: "1px",
26
- height: "1px",
27
- margin: "-1px",
28
- padding: "0",
29
- overflow: "hidden",
30
- clip: "rect(0 0 0 0)",
31
- whiteSpace: "nowrap",
32
- border: "0"
33
- });
34
- document.body.appendChild(element);
35
- liveRegion = element;
36
- return element;
37
- };
38
- const announcementListeners = /* @__PURE__ */ new Set();
39
- const announce = (announcement, queue) => {
40
- const region = getLiveRegion();
41
- if (region === null) return;
42
- region.setAttribute("aria-live", queue ? "polite" : "assertive");
43
- region.textContent = "";
44
- requestAnimationFrame(() => {
45
- region.textContent = announcement;
46
- for (const listener of announcementListeners) listener({
47
- announcement,
48
- success: true
49
- });
50
- });
51
- };
52
- const AccessibilityInfo = {
53
- isScreenReaderEnabled: () => resolve(false),
54
- isAccessibilityServiceEnabled: () => resolve(false),
55
- isBoldTextEnabled: () => resolve(false),
56
- isGrayscaleEnabled: () => resolve(false),
57
- isInvertColorsEnabled: () => resolve(matchesMedia("(inverted-colors: inverted)")),
58
- isReduceMotionEnabled: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
59
- isReduceTransparencyEnabled: () => resolve(matchesMedia("(prefers-reduced-transparency: reduce)")),
60
- isHighTextContrastEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
61
- isDarkerSystemColorsEnabled: () => resolve(matchesMedia("(prefers-contrast: more)")),
62
- prefersCrossFadeTransitions: () => resolve(matchesMedia("(prefers-reduced-motion: reduce)")),
63
- getRecommendedTimeoutMillis: (originalTimeout) => resolve(originalTimeout),
64
- addEventListener: (eventName, handler) => {
65
- if (eventName === "announcementFinished") {
66
- const listener = handler;
67
- announcementListeners.add(listener);
68
- return { remove: () => announcementListeners.delete(listener) };
69
- }
70
- const query = mediaQueryOf[eventName];
71
- if (query === void 0 || !hasDOM() || typeof window.matchMedia !== "function") return { remove: () => {} };
72
- const list = window.matchMedia(query);
73
- const listener = () => handler(list.matches);
74
- list.addEventListener("change", listener);
75
- return { remove: () => list.removeEventListener("change", listener) };
76
- },
77
- announceForAccessibility: (announcement) => announce(announcement, true),
78
- announceForAccessibilityWithOptions: (announcement, options) => announce(announcement, options.queue !== false),
79
- setAccessibilityFocus: (target) => {
80
- if (target instanceof HTMLElement) target.focus();
81
- },
82
- sendAccessibilityEvent: (target, eventType) => {
83
- if (eventType === "focus" && target instanceof HTMLElement) target.focus();
84
- }
85
- };
86
- // src/apis/Appearance/index.ts
87
- const DARK_QUERY = "(prefers-color-scheme: dark)";
88
- let override = null;
89
- let last = null;
90
- let mediaList = null;
91
- const listeners = /* @__PURE__ */ new Set();
92
- const system = () => matchesMedia(DARK_QUERY) ? "dark" : "light";
93
- const current$2 = () => override ?? system();
94
- const notify = () => {
95
- const next = current$2();
96
- if (next === last) return;
97
- last = next;
98
- for (const listener of listeners) listener({ colorScheme: next });
99
- };
100
- const listen$1 = () => {
101
- if (mediaList !== null || !hasDOM() || typeof window.matchMedia !== "function") return;
102
- mediaList = window.matchMedia(DARK_QUERY);
103
- mediaList.addEventListener("change", notify);
104
- };
105
- const Appearance = {
106
- getColorScheme() {
107
- return current$2();
108
- },
109
- setColorScheme(scheme) {
110
- override = scheme === "light" || scheme === "dark" ? scheme : null;
111
- if (hasDOM()) document.documentElement.style.colorScheme = override ?? "";
112
- notify();
113
- },
114
- addChangeListener(listener) {
115
- if (listeners.size === 0) last = current$2();
116
- listeners.add(listener);
117
- listen$1();
118
- return { remove: () => listeners.delete(listener) };
119
- }
120
- };
121
- // src/apis/BackHandler/index.ts
122
- const handlers$1 = /* @__PURE__ */ new Set();
123
- const BackHandler = {
124
- addEventListener: (eventName, handler) => {
125
- if (eventName !== "hardwareBackPress") throw new Error(`BackHandler: unknown event "${String(eventName)}"`);
126
- handlers$1.add(handler);
127
- return { remove: () => handlers$1.delete(handler) };
128
- },
129
- removeEventListener: (_eventName, handler) => {
130
- handlers$1.delete(handler);
131
- },
132
- exitApp: () => {}
133
- };
134
- // src/apis/Dimensions/index.ts
135
- const serverSize = Object.freeze({
136
- width: 0,
137
- height: 0,
138
- scale: 1,
139
- fontScale: 1
140
- });
141
- const read = () => {
142
- if (!hasDOM()) return {
143
- window: serverSize,
144
- screen: serverSize
145
- };
146
- const scale = window.devicePixelRatio || 1;
147
- const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
148
- const fontScale = Number.isFinite(rootFontSize) && rootFontSize > 0 ? rootFontSize / 16 : 1;
149
- return {
150
- window: {
151
- width: window.innerWidth,
152
- height: window.innerHeight,
153
- scale,
154
- fontScale
155
- },
156
- screen: {
157
- width: window.screen.width,
158
- height: window.screen.height,
159
- scale,
160
- fontScale
161
- }
162
- };
163
- };
164
- const sameSize = (a, b) => a.width === b.width && a.height === b.height && a.scale === b.scale && a.fontScale === b.fontScale;
165
- let current$1 = null;
166
- const handlers = /* @__PURE__ */ new Set();
167
- let listening = false;
168
- const refresh = () => {
169
- const next = read();
170
- if (current$1 === null || !sameSize(current$1.window, next.window) || !sameSize(current$1.screen, next.screen)) current$1 = next;
171
- return current$1;
172
- };
173
- const update = () => {
174
- const previous = current$1;
175
- const value = refresh();
176
- if (value === previous) return;
177
- for (const handler of handlers) handler(value);
178
- };
179
- const listen = () => {
180
- if (listening || !hasDOM()) return;
181
- listening = true;
182
- window.addEventListener("resize", update);
183
- };
184
- const Dimensions = {
185
- get(dimension) {
186
- return (current$1 === null || !listening ? refresh() : current$1)[dimension];
187
- },
188
- addEventListener(type, handler) {
189
- if (type !== "change") throw new Error(`Dimensions: unknown event "${String(type)}"`);
190
- refresh();
191
- handlers.add(handler);
192
- listen();
193
- return { remove: () => handlers.delete(handler) };
194
- }
195
- };
196
- // src/apis/I18nManager/index.ts
197
- let allowed = true;
198
- let forced = false;
199
- let swapLeftAndRight = true;
200
- const documentIsRTL = () => hasDOM() && getComputedStyle(document.documentElement).direction === "rtl";
201
- const isRTL = () => forced || allowed && documentIsRTL();
202
- const I18nManager = {
203
- get isRTL() {
204
- return isRTL();
205
- },
206
- get doLeftAndRightSwapInRTL() {
207
- return swapLeftAndRight;
208
- },
209
- getConstants: () => ({
210
- isRTL: isRTL(),
211
- doLeftAndRightSwapInRTL: swapLeftAndRight,
212
- localeIdentifier: hasDOM() ? navigator.language : void 0
213
- }),
214
- allowRTL: (allow) => {
215
- allowed = allow;
216
- },
217
- forceRTL: (force) => {
218
- forced = force;
219
- if (hasDOM()) document.documentElement.dir = force ? "rtl" : "";
220
- },
221
- swapLeftAndRightInRTL: (swap) => {
222
- swapLeftAndRight = swap;
223
- }
224
- };
225
- // src/apis/PanResponder/index.ts
226
- let current = null;
227
- let grantEvent = null;
228
- let nextStateID = 1;
229
- const newGestureState = () => ({
230
- stateID: nextStateID++,
231
- moveX: 0,
232
- moveY: 0,
233
- x0: 0,
234
- y0: 0,
235
- dx: 0,
236
- dy: 0,
237
- vx: 0,
238
- vy: 0,
239
- numberActiveTouches: 0,
240
- _accountsForMovesUpTo: 0
241
- });
242
- const centroid = (pointers) => {
243
- let x = 0;
244
- let y = 0;
245
- for (const pointer of pointers.values()) {
246
- x += pointer.clientX + window.scrollX;
247
- y += pointer.clientY + window.scrollY;
248
- }
249
- const count = pointers.size || 1;
250
- return {
251
- x: x / count,
252
- y: y / count
253
- };
254
- };
255
- const define$1 = (target, fields) => {
256
- for (const key in fields) Object.defineProperty(target, key, {
257
- value: fields[key],
258
- configurable: true,
259
- writable: true
260
- });
261
- };
262
- const touchOf = (pointer, rect, timestamp) => ({
263
- changedTouches: [],
264
- identifier: pointer.id,
265
- locationX: pointer.clientX - rect.left,
266
- locationY: pointer.clientY - rect.top,
267
- pageX: pointer.clientX + window.scrollX,
268
- pageY: pointer.clientY + window.scrollY,
269
- target: pointer.target,
270
- timestamp,
271
- touches: []
272
- });
273
- const toResponderEvent = (event, responder, changed) => {
274
- const rect = (responder.element ?? event.currentTarget).getBoundingClientRect();
275
- const touches = [...responder.pointers.values()].map((p) => touchOf(p, rect, event.timeStamp));
276
- const touch = touchOf(changed, rect, event.timeStamp);
277
- define$1(event.nativeEvent, {
278
- ...touch,
279
- force: event.pressure,
280
- touches,
281
- changedTouches: [touch]
282
- });
283
- return event;
284
- };
285
- const pointerOf = (event) => ({
286
- id: event.pointerId,
287
- clientX: event.clientX,
288
- clientY: event.clientY,
289
- target: event.target
290
- });
291
- const updateMove = (responder, time) => {
292
- const state = responder.gestureState;
293
- const next = centroid(responder.pointers);
294
- const last = responder.last;
295
- if (last !== null) {
296
- const dt = time - last.time;
297
- state.dx += next.x - last.x;
298
- state.dy += next.y - last.y;
299
- state.vx = dt > 0 ? (next.x - last.x) / dt : 0;
300
- state.vy = dt > 0 ? (next.y - last.y) / dt : 0;
301
- }
302
- state.moveX = next.x;
303
- state.moveY = next.y;
304
- state._accountsForMovesUpTo = time;
305
- responder.last = {
306
- x: next.x,
307
- y: next.y,
308
- time
309
- };
310
- };
311
- const rebase = (responder, time) => {
312
- const next = centroid(responder.pointers);
313
- responder.last = {
314
- x: next.x,
315
- y: next.y,
316
- time
317
- };
318
- responder.gestureState.numberActiveTouches = responder.pointers.size;
319
- };
320
- const grant = (responder, event, responderEvent) => {
321
- const state = responder.gestureState;
322
- const point = centroid(responder.pointers);
323
- state.x0 = point.x;
324
- state.y0 = point.y;
325
- state.dx = 0;
326
- state.dy = 0;
327
- state.vx = 0;
328
- state.vy = 0;
329
- responder.last = {
330
- x: point.x,
331
- y: point.y,
332
- time: event.timeStamp
333
- };
334
- responder.element = event.currentTarget;
335
- current = responder;
336
- grantEvent = event.nativeEvent;
337
- for (const pointer of responder.pointers.values()) try {
338
- responder.element.setPointerCapture(pointer.id);
339
- } catch {}
340
- responder.config.onPanResponderGrant?.(responderEvent, state);
341
- responder.config.onPanResponderStart?.(responderEvent, state);
342
- };
343
- const releaseCapture = (responder) => {
344
- const element = responder.element;
345
- if (element === null) return;
346
- for (const pointer of responder.pointers.values()) try {
347
- if (element.hasPointerCapture(pointer.id)) element.releasePointerCapture(pointer.id);
348
- } catch {}
349
- };
350
- const finish = (responder) => {
351
- releaseCapture(responder);
352
- if (current === responder) current = null;
353
- responder.element = null;
354
- responder.last = null;
355
- };
356
- const negotiate = (responder, event, responderEvent, predicate) => {
357
- if (current === responder) return;
358
- if (current !== null && grantEvent === event.nativeEvent) return;
359
- if (predicate === void 0 || !predicate(responderEvent, responder.gestureState)) return;
360
- if (current !== null) {
361
- const holder = current;
362
- if (holder.config.onPanResponderTerminationRequest?.(responderEvent, holder.gestureState) === false) {
363
- responder.config.onPanResponderReject?.(responderEvent, responder.gestureState);
364
- return;
365
- }
366
- holder.config.onPanResponderTerminate?.(responderEvent, holder.gestureState);
367
- finish(holder);
368
- }
369
- grant(responder, event, responderEvent);
370
- };
371
- const createHandlers = (responder) => {
372
- const down = (event, capture) => {
373
- const pointer = pointerOf(event);
374
- const first = responder.pointers.size === 0;
375
- if (capture) {
376
- if (first) responder.gestureState = newGestureState();
377
- responder.pointers.set(pointer.id, pointer);
378
- rebase(responder, event.timeStamp);
379
- }
380
- const responderEvent = toResponderEvent(event, responder, pointer);
381
- const { config } = responder;
382
- if (current === responder) {
383
- if (capture) config.onPanResponderStart?.(responderEvent, responder.gestureState);
384
- return;
385
- }
386
- negotiate(responder, event, responderEvent, capture ? config.onStartShouldSetPanResponderCapture : config.onStartShouldSetPanResponder);
387
- };
388
- const move = (event, capture) => {
389
- const pointer = responder.pointers.get(event.pointerId);
390
- if (pointer === void 0) return;
391
- if (capture) {
392
- pointer.clientX = event.clientX;
393
- pointer.clientY = event.clientY;
394
- updateMove(responder, event.timeStamp);
395
- }
396
- const responderEvent = toResponderEvent(event, responder, pointer);
397
- const { config } = responder;
398
- if (current === responder) {
399
- if (capture) config.onPanResponderMove?.(responderEvent, responder.gestureState);
400
- return;
401
- }
402
- negotiate(responder, event, responderEvent, capture ? config.onMoveShouldSetPanResponderCapture : config.onMoveShouldSetPanResponder);
403
- };
404
- const end = (event, cancel) => {
405
- const pointer = responder.pointers.get(event.pointerId);
406
- if (pointer === void 0) return;
407
- const responderEvent = toResponderEvent(event, responder, pointer);
408
- responder.pointers.delete(event.pointerId);
409
- const { config, gestureState } = responder;
410
- const responding = current === responder;
411
- if (responding && cancel) {
412
- config.onPanResponderTerminate?.(responderEvent, gestureState);
413
- responder.pointers.clear();
414
- finish(responder);
415
- return;
416
- }
417
- if (responding) config.onPanResponderEnd?.(responderEvent, gestureState);
418
- if (responder.pointers.size === 0) {
419
- if (responding) config.onPanResponderRelease?.(responderEvent, gestureState);
420
- finish(responder);
421
- } else rebase(responder, event.timeStamp);
422
- };
423
- return {
424
- onPointerDownCapture: (event) => down(event, true),
425
- onPointerDown: (event) => down(event, false),
426
- onPointerMoveCapture: (event) => move(event, true),
427
- onPointerMove: (event) => move(event, false),
428
- onPointerUp: (event) => end(event, false),
429
- onPointerCancel: (event) => end(event, true)
430
- };
431
- };
432
- const PanResponder = { create(config) {
433
- const responder = {
434
- config,
435
- gestureState: newGestureState(),
436
- pointers: /* @__PURE__ */ new Map(),
437
- element: null,
438
- last: null
439
- };
440
- return {
441
- panHandlers: createHandlers(responder),
442
- getInteractionHandle: () => null
443
- };
444
- } };
445
- // src/apis/PixelRatio/index.ts
446
- const PixelRatio = {
447
- get: () => Dimensions.get("window").scale,
448
- getFontScale: () => Dimensions.get("window").fontScale,
449
- getPixelSizeForLayoutSize: (layoutSize) => Math.round(layoutSize * PixelRatio.get()),
450
- roundToNearestPixel: (layoutSize) => {
451
- const ratio = PixelRatio.get();
452
- return Math.round(layoutSize * ratio) / ratio;
453
- },
454
- startDetecting: () => {}
455
- };
456
- // src/reactNativeVersion.ts
457
- const reactNativeVersion = {
458
- major: 0,
459
- minor: 88,
460
- patch: 1,
461
- prerelease: void 0
462
- };
463
- // src/apis/Platform/index.ts
464
- const Platform = {
465
- OS: "web",
466
- get Version() {
467
- return hasDOM() ? navigator.userAgent : "";
468
- },
469
- get constants() {
470
- return { reactNativeVersion };
471
- },
472
- get isTV() {
473
- return false;
474
- },
475
- get isTesting() {
476
- return isTestEnv();
477
- },
478
- get isDisableAnimations() {
479
- return matchesMedia("(prefers-reduced-motion: reduce)");
480
- },
481
- select(spec) {
482
- if ("web" in spec) return spec.web;
483
- if ("default" in spec) return spec.default;
484
- }
485
- };
486
- // src/apis/processColor/index.ts
487
- const processColor = (color) => {
488
- if (color === void 0 || color === null) return color;
489
- if (typeof color !== "string" && typeof color !== "number") return null;
490
- const rgba = normalizeColor(color);
491
- if (rgba === null || rgba === void 0) return null;
492
- return (rgba << 24 | rgba >>> 8) >>> 0;
493
- };
494
- // src/style/color.ts
495
- const toCSSColor = (value) => {
496
- if (typeof value !== "string" && typeof value !== "number") return void 0;
497
- const packed = normalizeColor(value);
498
- if (packed === null || packed === void 0) return void 0;
499
- const r = packed >>> 24 & 255;
500
- const g = packed >>> 16 & 255;
501
- const b = packed >>> 8 & 255;
502
- const a = (packed & 255) / 255;
503
- return a === 1 ? `rgb(${r},${g},${b})` : `rgba(${r},${g},${b},${round(a)})`;
504
- };
505
- const round = (n) => Math.round(n * 1e3) / 1e3;
506
- // src/style/units.ts
507
- const toUnit = (value, unit) => {
508
- if (typeof value === "number") return value === 0 ? "0" : `${value}${unit}`;
509
- return String(value);
510
- };
511
- const unitlessProperties = /* @__PURE__ */ new Set([
512
- "aspectRatio",
513
- "flex",
514
- "flexGrow",
515
- "flexShrink",
516
- "fontWeight",
517
- "lineClamp",
518
- "WebkitLineClamp",
519
- "opacity",
520
- "zIndex",
521
- "scale",
522
- "shadowOpacity"
523
- ]);
524
- // src/style/shadow.ts
525
- const offsetOf = (value) => {
526
- const o = value ?? {};
527
- return {
528
- x: typeof o.width === "number" ? o.width : 0,
529
- y: typeof o.height === "number" ? o.height : 0
530
- };
531
- };
532
- const legacyBoxShadow = (style) => {
533
- const { x, y } = offsetOf(style["shadowOffset"]);
534
- const radius = typeof style["shadowRadius"] === "number" ? style["shadowRadius"] : 0;
535
- const opacity = typeof style["shadowOpacity"] === "number" ? style["shadowOpacity"] : 1;
536
- const color = toCSSColor(style["shadowColor"] ?? "black");
537
- if (color === void 0) return void 0;
538
- return `${x}px ${y}px ${radius}px ${withOpacity(color, opacity)}`;
539
- };
540
- const toCSSTextShadow = (style) => {
541
- const { x, y } = offsetOf(style["textShadowOffset"]);
542
- const radius = typeof style["textShadowRadius"] === "number" ? style["textShadowRadius"] : 0;
543
- const color = toCSSColor(style["textShadowColor"] ?? "black");
544
- if (color === void 0) return void 0;
545
- return `${x}px ${y}px ${radius}px ${color}`;
546
- };
547
- const toCSSBoxShadow = (value) => {
548
- if (typeof value === "string") return value;
549
- if (!Array.isArray(value)) return void 0;
550
- const shadows = value.map((s) => {
551
- const parts = [
552
- toUnit(s.offsetX, "px"),
553
- toUnit(s.offsetY, "px"),
554
- toUnit(s.blurRadius ?? 0, "px"),
555
- toUnit(s.spreadDistance ?? 0, "px"),
556
- toCSSColor(s.color ?? "black") ?? "black"
557
- ];
558
- if (s.inset === true) parts.push("inset");
559
- return parts.join(" ");
560
- });
561
- return shadows.length === 0 ? "none" : shadows.join(", ");
562
- };
563
- const lengthFilters = /* @__PURE__ */ new Set(["blur"]);
564
- const angleFilters = /* @__PURE__ */ new Set(["hueRotate"]);
565
- const toCSSFilter = (value) => {
566
- if (typeof value === "string") return value;
567
- if (!Array.isArray(value)) return void 0;
568
- const parts = [];
569
- for (const entry of value) for (const [name, raw] of Object.entries(entry)) {
570
- const css = toFilterFunction(name, raw);
571
- if (css !== void 0) parts.push(css);
572
- }
573
- return parts.length === 0 ? "none" : parts.join(" ");
574
- };
575
- const toFilterFunction = (name, raw) => {
576
- if (name === "dropShadow") {
577
- const shadow = typeof raw === "string" ? raw : dropShadow(raw);
578
- return shadow === void 0 ? void 0 : `drop-shadow(${shadow})`;
579
- }
580
- const cssName = name === "hueRotate" ? "hue-rotate" : name;
581
- if (typeof raw === "number") {
582
- if (lengthFilters.has(name)) return `${cssName}(${raw}px)`;
583
- if (angleFilters.has(name)) return `${cssName}(${raw}deg)`;
584
- return `${cssName}(${raw})`;
585
- }
586
- if (typeof raw === "string") return `${cssName}(${raw})`;
587
- };
588
- const dropShadow = (v) => {
589
- const color = toCSSColor(v["color"] ?? "black");
590
- if (color === void 0) return void 0;
591
- return [
592
- toUnit(v["offsetX"] ?? 0, "px"),
593
- toUnit(v["offsetY"] ?? 0, "px"),
594
- toUnit(v["standardDeviation"] ?? 0, "px"),
595
- color
596
- ].join(" ");
597
- };
598
- const withOpacity = (color, opacity) => {
599
- if (opacity >= 1) return color;
600
- const match = /^rgba?\((\d+),(\d+),(\d+)(?:,([\d.]+))?\)$/.exec(color);
601
- if (match === null) return color;
602
- const alpha = match[4] === void 0 ? 1 : Number(match[4]);
603
- const a = Math.round(alpha * opacity * 1e3) / 1e3;
604
- return `rgba(${match[1]},${match[2]},${match[3]},${a})`;
605
- };
606
- // src/style/transform.ts
607
- const lengthFunctions = /* @__PURE__ */ new Set([
608
- "translateX",
609
- "translateY",
610
- "translateZ",
611
- "perspective"
612
- ]);
613
- const toCSSTransform = (value) => {
614
- if (typeof value === "string") return value;
615
- if (!Array.isArray(value)) return void 0;
616
- const parts = [];
617
- for (const entry of value) {
618
- if (entry === null || typeof entry !== "object") continue;
619
- for (const [name, raw] of Object.entries(entry)) {
620
- const css = toTransformFunction(name, raw);
621
- if (css !== void 0) parts.push(css);
622
- }
623
- }
624
- return parts.length === 0 ? "none" : parts.join(" ");
625
- };
626
- const toTransformFunction = (name, raw) => {
627
- if (name === "matrix" && Array.isArray(raw)) return `${raw.length === 16 ? "matrix3d" : "matrix"}(${raw.join(",")})`;
628
- if (name === "translate" && Array.isArray(raw)) return `translate(${raw.map((v) => toUnit(v, "px")).join(",")})`;
629
- if (typeof raw === "number") return lengthFunctions.has(name) ? `${name}(${raw}px)` : `${name}(${raw})`;
630
- if (typeof raw === "string") return `${name}(${raw})`;
631
- };
632
- const toCSSTransformOrigin = (value) => {
633
- if (typeof value === "string") return value;
634
- if (!Array.isArray(value)) return void 0;
635
- return value.map((v) => toUnit(v, "px")).join(" ");
636
- };
637
- // src/style/resolveStyle.ts
638
- const colorProperties = /* @__PURE__ */ new Set([
639
- "backgroundColor",
640
- "borderBlockColor",
641
- "borderBlockEndColor",
642
- "borderBlockStartColor",
643
- "borderBottomColor",
644
- "borderColor",
645
- "borderEndColor",
646
- "borderLeftColor",
647
- "borderRightColor",
648
- "borderStartColor",
649
- "borderTopColor",
650
- "color",
651
- "outlineColor",
652
- "textDecorationColor"
653
- ]);
654
- const renamedProperties = {
655
- borderEndColor: "borderInlineEndColor",
656
- borderEndWidth: "borderInlineEndWidth",
657
- borderStartColor: "borderInlineStartColor",
658
- borderStartWidth: "borderInlineStartWidth",
659
- borderTopStartRadius: "borderStartStartRadius",
660
- borderTopEndRadius: "borderStartEndRadius",
661
- borderBottomStartRadius: "borderEndStartRadius",
662
- borderBottomEndRadius: "borderEndEndRadius",
663
- end: "insetInlineEnd",
664
- marginEnd: "marginInlineEnd",
665
- marginStart: "marginInlineStart",
666
- paddingEnd: "paddingInlineEnd",
667
- paddingStart: "paddingInlineStart",
668
- start: "insetInlineStart",
669
- writingDirection: "direction"
670
- };
671
- const expandedProperties = {
672
- marginHorizontal: ["marginLeft", "marginRight"],
673
- marginVertical: ["marginTop", "marginBottom"],
674
- paddingHorizontal: ["paddingLeft", "paddingRight"],
675
- paddingVertical: ["paddingTop", "paddingBottom"]
676
- };
677
- const ignoredProperties = /* @__PURE__ */ new Set([
678
- "borderCurve",
679
- "elevation",
680
- "includeFontPadding",
681
- "overlayColor",
682
- "shadowColor",
683
- "shadowOffset",
684
- "shadowOpacity",
685
- "shadowRadius",
686
- "textShadowColor",
687
- "textShadowOffset",
688
- "textShadowRadius",
689
- "tintColor"
690
- ]);
691
- const fontWeightNames = {
692
- ultralight: "200",
693
- thin: "100",
694
- light: "300",
695
- regular: "400",
696
- medium: "500",
697
- semibold: "600",
698
- condensedBold: "700",
699
- condensed: "400",
700
- heavy: "800",
701
- black: "900"
702
- };
703
- const resizeModeToObjectFit = {
704
- contain: "contain",
705
- cover: "cover",
706
- stretch: "fill",
707
- center: "none",
708
- repeat: "none"
709
- };
710
- const systemFontStack = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
711
- const textAlignVerticalToVerticalAlign = {
712
- top: "top",
713
- center: "middle",
714
- bottom: "bottom"
715
- };
716
- const resolveStyle = (style) => {
717
- const out = {};
718
- for (const [name, value] of Object.entries(style)) {
719
- if (value === void 0 || value === null || ignoredProperties.has(name)) continue;
720
- resolveProperty(name, value, out);
721
- }
722
- if (out["boxShadow"] === void 0 && hasLegacyShadow(style)) {
723
- const shadow = legacyBoxShadow(style);
724
- if (shadow !== void 0) out["boxShadow"] = shadow;
725
- }
726
- if (style["textShadowColor"] !== void 0 || style["textShadowOffset"] !== void 0) {
727
- const shadow = toCSSTextShadow(style);
728
- if (shadow !== void 0) out["textShadow"] = shadow;
729
- }
730
- return out;
731
- };
732
- const resolveProperty = (name, value, out) => {
733
- switch (name) {
734
- case "flex":
735
- if (typeof value === "number") out["flex"] = value > 0 ? `${value} 1 0%` : value === 0 ? "0 0 auto" : "0 1 auto";
736
- else out["flex"] = String(value);
737
- return;
738
- case "transform": {
739
- const transform = toCSSTransform(value);
740
- if (transform !== void 0) out["transform"] = transform;
741
- return;
742
- }
743
- case "transformOrigin": {
744
- const origin = toCSSTransformOrigin(value);
745
- if (origin !== void 0) out["transformOrigin"] = origin;
746
- return;
747
- }
748
- case "boxShadow": {
749
- const shadow = toCSSBoxShadow(value);
750
- if (shadow !== void 0) out["boxShadow"] = shadow;
751
- return;
752
- }
753
- case "filter": {
754
- const filter = toCSSFilter(value);
755
- if (filter !== void 0) out["filter"] = filter;
756
- return;
757
- }
758
- case "fontWeight":
759
- out["fontWeight"] = fontWeightNames[String(value)] ?? String(value);
760
- return;
761
- case "fontFamily":
762
- out["fontFamily"] = value === "System" ? systemFontStack : String(value);
763
- return;
764
- case "fontVariant":
765
- out["fontVariant"] = Array.isArray(value) ? value.join(" ") : String(value);
766
- return;
767
- case "fontVariationSettings":
768
- out["fontVariationSettings"] = Array.isArray(value) ? value.map((v) => `'${v.axis}' ${v.value}`).join(", ") : String(value);
769
- return;
770
- case "resizeMode": {
771
- const fit = resizeModeToObjectFit[String(value)];
772
- if (fit !== void 0 && out["objectFit"] === void 0) out["objectFit"] = fit;
773
- return;
774
- }
775
- case "objectFit":
776
- out["objectFit"] = String(value);
777
- return;
778
- case "textAlignVertical": {
779
- const align = textAlignVerticalToVerticalAlign[String(value)];
780
- if (align !== void 0 && out["verticalAlign"] === void 0) out["verticalAlign"] = align;
781
- return;
782
- }
783
- case "backgroundImage":
784
- if (typeof value === "string") out["backgroundImage"] = value;
785
- return;
786
- }
787
- if (colorProperties.has(name)) {
788
- const color = toCSSColor(value);
789
- if (color !== void 0) out[renamedProperties[name] ?? name] = color;
790
- return;
791
- }
792
- const targets = expandedProperties[name] ?? [renamedProperties[name] ?? name];
793
- const css = unitlessProperties.has(name) ? String(value) : toUnit(value, "px");
794
- for (const target of targets) out[target] = css;
795
- };
796
- const hasLegacyShadow = (style) => style["shadowColor"] !== void 0 || style["shadowOffset"] !== void 0 || style["shadowOpacity"] !== void 0 || style["shadowRadius"] !== void 0;
797
- // src/style/compile.ts
798
- const flattenStyle = (style) => {
799
- if (style === null || style === void 0 || style === false || style === "") return void 0;
800
- if (!Array.isArray(style)) return style;
801
- let result;
802
- for (const entry of style) {
803
- const flat = flattenStyle(entry);
804
- if (flat === void 0) continue;
805
- result = result === void 0 ? { ...flat } : Object.assign(result, flat);
806
- }
807
- return result;
808
- };
809
- const cache = /* @__PURE__ */ new WeakMap();
810
- const compileStyle = (style, registry = getStyleRegistry()) => {
811
- const flat = flattenStyle(style);
812
- if (flat === void 0) return "";
813
- const cacheable = Object.isFrozen(flat);
814
- let perRegistry = cache.get(registry);
815
- if (cacheable) {
816
- const cached = perRegistry?.get(flat);
817
- if (cached !== void 0) return cached;
818
- }
819
- const classes = registry.classesFor(resolveStyle(flat));
820
- if (cacheable) {
821
- if (perRegistry === void 0) {
822
- perRegistry = /* @__PURE__ */ new WeakMap();
823
- cache.set(registry, perRegistry);
824
- }
825
- perRegistry.set(flat, classes);
826
- }
827
- return classes;
828
- };
829
- // src/apis/StyleSheet/index.ts
830
- const absoluteFillObject = {
831
- position: "absolute",
832
- left: 0,
833
- right: 0,
834
- top: 0,
835
- bottom: 0
836
- };
837
- const create = (styles) => {
838
- for (const key in styles) Object.freeze(styles[key]);
839
- return Object.freeze(styles);
840
- };
841
- const flatten = (style) => flattenStyle(style);
842
- const compose = (style1, style2) => {
843
- if (style1 && style2) return [style1, style2];
844
- return style1 || style2;
845
- };
846
- const StyleSheet = Object.freeze({
847
- absoluteFill: Object.freeze(absoluteFillObject),
848
- absoluteFillObject,
849
- hairlineWidth: 1,
850
- create,
851
- flatten,
852
- compose
853
- });
854
- // src/apis/useColorScheme/index.ts
855
- const subscribe$1 = (onChange) => {
856
- const subscription = Appearance.addChangeListener(onChange);
857
- return () => subscription.remove();
858
- };
859
- const getSnapshot$1 = () => Appearance.getColorScheme();
860
- const getServerSnapshot$1 = () => "light";
861
- const useColorScheme = () => useSyncExternalStore(subscribe$1, getSnapshot$1, getServerSnapshot$1);
862
- // src/apis/useWindowDimensions/index.ts
863
- const serverSnapshot = Object.freeze({
864
- width: 0,
865
- height: 0,
866
- scale: 1,
867
- fontScale: 1
868
- });
869
- const subscribe = (onChange) => {
870
- const subscription = Dimensions.addEventListener("change", onChange);
871
- return () => subscription.remove();
872
- };
873
- const getSnapshot = () => Dimensions.get("window");
874
- const getServerSnapshot = () => serverSnapshot;
875
- const useWindowDimensions = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
876
- // src/render/domProps.ts
877
- const liveRegionToAriaLive = {
878
- none: "off",
879
- polite: "polite",
880
- assertive: "assertive"
881
- };
882
- const nativeHandler = /^on(Press|Layout|TextLayout|Accessibility|Magic|Responder|.*ShouldSet)/;
883
- const passThrough = /* @__PURE__ */ new Set([
884
- "lang",
885
- "dir",
886
- "target",
887
- "rel",
888
- "download"
889
- ]);
890
- const toDOMProps = (props) => {
891
- const out = {};
892
- for (const name in props) {
893
- const value = props[name];
894
- if (value === void 0) continue;
895
- if (name.startsWith("aria-") || name.startsWith("data-") || passThrough.has(name)) out[name] = value;
896
- else if (name.startsWith("on") && name.length > 2 && !nativeHandler.test(name)) out[name] = value;
897
- }
898
- const { accessibilityLabel, accessibilityLabelledBy, accessibilityHint, accessibilityState, accessibilityValue, accessibilityLiveRegion, accessibilityElementsHidden, accessibilityViewIsModal, importantForAccessibility, id, nativeID, testID, tabIndex, focusable, href } = props;
899
- if (accessibilityLabel !== void 0) out["aria-label"] ??= accessibilityLabel;
900
- if (accessibilityLabelledBy !== void 0) out["aria-labelledby"] ??= Array.isArray(accessibilityLabelledBy) ? accessibilityLabelledBy.join(" ") : accessibilityLabelledBy;
901
- if (accessibilityHint !== void 0) out["aria-description"] ??= accessibilityHint;
902
- if (accessibilityLiveRegion !== void 0) out["aria-live"] ??= liveRegionToAriaLive[accessibilityLiveRegion];
903
- if (accessibilityViewIsModal !== void 0) out["aria-modal"] ??= accessibilityViewIsModal;
904
- if (accessibilityElementsHidden === true || importantForAccessibility === "no-hide-descendants") out["aria-hidden"] ??= true;
905
- if (accessibilityState !== void 0) {
906
- const { busy, checked, disabled, expanded, selected } = accessibilityState;
907
- if (busy !== void 0) out["aria-busy"] ??= busy;
908
- if (checked !== void 0) out["aria-checked"] ??= checked;
909
- if (disabled !== void 0) out["aria-disabled"] ??= disabled;
910
- if (expanded !== void 0) out["aria-expanded"] ??= expanded;
911
- if (selected !== void 0) out["aria-selected"] ??= selected;
912
- }
913
- if (accessibilityValue !== void 0) {
914
- const { max, min, now, text } = accessibilityValue;
915
- if (max !== void 0) out["aria-valuemax"] ??= max;
916
- if (min !== void 0) out["aria-valuemin"] ??= min;
917
- if (now !== void 0) out["aria-valuenow"] ??= now;
918
- if (text !== void 0) out["aria-valuetext"] ??= text;
919
- }
920
- const domId = id ?? nativeID;
921
- if (domId !== void 0) out["id"] = domId;
922
- if (testID !== void 0) out["data-testid"] = testID;
923
- if (href !== void 0) out["href"] = href;
924
- if (tabIndex !== void 0) out["tabIndex"] = tabIndex;
925
- else if (focusable === true) out["tabIndex"] = 0;
926
- else if (focusable === false) out["tabIndex"] = -1;
927
- return out;
928
- };
929
- // src/render/resolveTag.ts
930
- const legacyRoleToRole = {
931
- header: "heading",
932
- image: "img",
933
- imagebutton: "button",
934
- summary: "region",
935
- text: "none",
936
- adjustable: "slider",
937
- search: "searchbox",
938
- keyboardkey: "none"
939
- };
940
- const roleToTag = {
941
- article: "article",
942
- banner: "header",
943
- button: "button",
944
- complementary: "aside",
945
- contentinfo: "footer",
946
- figure: "figure",
947
- form: "form",
948
- list: "ul",
949
- listitem: "li",
950
- main: "main",
951
- navigation: "nav",
952
- separator: "hr"
953
- };
954
- const headingLevel = (level) => level !== void 0 && Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2;
955
- const voidTags = /* @__PURE__ */ new Set(["hr"]);
956
- const resolveTag = (props, defaultTag, hasChildren = false) => {
957
- const role = props.role ?? mapLegacyRole(props.accessibilityRole);
958
- const resolved = tagForRole(role, props, defaultTag);
959
- return hasChildren && voidTags.has(resolved.tag) ? {
960
- tag: defaultTag,
961
- role
962
- } : resolved;
963
- };
964
- const tagForRole = (role, props, defaultTag) => {
965
- if (role === "heading") return {
966
- tag: `h${headingLevel(props["aria-level"])}`,
967
- role: void 0
968
- };
969
- if (role === "link") return props.href === void 0 ? {
970
- tag: defaultTag,
971
- role: "link"
972
- } : {
973
- tag: "a",
974
- role: void 0
975
- };
976
- if (role === void 0) return {
977
- tag: props.href === void 0 ? defaultTag : "a",
978
- role: void 0
979
- };
980
- const tag = roleToTag[role];
981
- return tag === void 0 ? {
982
- tag: defaultTag,
983
- role
984
- } : {
985
- tag,
986
- role: void 0
987
- };
988
- };
989
- const mapLegacyRole = (legacy) => legacy === void 0 ? void 0 : legacyRoleToRole[legacy] ?? legacy;
990
- // src/render/useElementLayout.ts
991
- const measure = (element) => ({ nativeEvent: { layout: {
992
- x: element.offsetLeft,
993
- y: element.offsetTop,
994
- width: element.offsetWidth,
995
- height: element.offsetHeight
996
- } } });
997
- const useElementLayout = (ref, onLayout) => {
998
- const latest = useRef(onLayout);
999
- useEffect(() => {
1000
- latest.current = onLayout;
1001
- }, [onLayout]);
1002
- const enabled = onLayout !== void 0;
1003
- useEffect(() => {
1004
- const element = ref.current;
1005
- if (element === null || !enabled) return;
1006
- const observer = new ResizeObserver(() => latest.current?.(measure(element)));
1007
- observer.observe(element);
1008
- return () => observer.disconnect();
1009
- }, [ref, enabled]);
1010
- };
1011
- // src/components/View/index.tsx
1012
- const resetStyle$2 = Object.freeze({
1013
- alignItems: "stretch",
1014
- backgroundColor: "transparent",
1015
- border: "0 solid black",
1016
- boxSizing: "border-box",
1017
- display: "flex",
1018
- flexBasis: "auto",
1019
- flexDirection: "column",
1020
- flexShrink: 0,
1021
- listStyle: "none",
1022
- margin: 0,
1023
- minHeight: 0,
1024
- minWidth: 0,
1025
- padding: 0,
1026
- position: "relative",
1027
- textDecoration: "none",
1028
- zIndex: 0
1029
- });
1030
- const pointerEventsClass = (registry, value) => registry.staticClass(`rn-pe-${value}`, value === "box-none" ? [".rn-pe-box-none{pointer-events:none}", ".rn-pe-box-none>*{pointer-events:auto}"] : [".rn-pe-box-only{pointer-events:auto}", ".rn-pe-box-only>*{pointer-events:none}"]);
1031
- function View(props) {
1032
- return useViewElement(props);
1033
- }
1034
- function useViewElement(props, extraClassName) {
1035
- const { children, onLayout, pointerEvents, ref, style, ...rest } = props;
1036
- const element = useRef(null);
1037
- useImperativeHandle(ref, () => element.current, []);
1038
- useElementLayout(element, onLayout);
1039
- const registry = useStyleRegistry();
1040
- const { tag, role } = resolveTag(rest, "div", children != null);
1041
- let className = compileStyle([
1042
- resetStyle$2,
1043
- style,
1044
- pointerEvents === "none" || pointerEvents === "auto" ? { pointerEvents } : void 0
1045
- ], registry);
1046
- if (pointerEvents === "box-none" || pointerEvents === "box-only") className = `${className} ${pointerEventsClass(registry, pointerEvents)}`;
1047
- if (extraClassName !== void 0) className = `${className} ${extraClassName}`;
1048
- const domProps = toDOMProps(rest);
1049
- if (role !== void 0) domProps["role"] = role;
1050
- if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
1051
- if (tag === "button") domProps["type"] = "button";
1052
- domProps["className"] = className;
1053
- domProps["ref"] = element;
1054
- return createElement(tag, domProps, children);
1055
- }
1056
- // src/components/ActivityIndicator/index.tsx
1057
- const GRAY = "#999999";
1058
- const SPIN_CLASS = "rn-activity-indicator";
1059
- const SPIN_RULES = ["@keyframes rn-activity-indicator-spin{to{transform:rotate(360deg)}}", `.${SPIN_CLASS}{animation:rn-activity-indicator-spin .75s linear infinite}`];
1060
- const pausedStyle = { animationPlayState: "paused" };
1061
- function ActivityIndicator(props) {
1062
- const { animating = true, color = GRAY, hidesWhenStopped = true, onLayout, ref, size = "small", style, ...rest } = props;
1063
- const spinClass = useStyleRegistry().staticClass(SPIN_CLASS, SPIN_RULES);
1064
- const stroke = toCSSColor(color) ?? GRAY;
1065
- const sizeStyle = size === "small" ? styles$2.sizeSmall : size === "large" ? styles$2.sizeLarge : {
1066
- width: size,
1067
- height: size
1068
- };
1069
- return /* @__PURE__ */ jsx(View, {
1070
- onLayout,
1071
- style: [styles$2.container, style],
1072
- children: /* @__PURE__ */ jsx(View, {
1073
- role: "progressbar",
1074
- ...rest,
1075
- ref,
1076
- style: [sizeStyle, !animating && hidesWhenStopped && styles$2.hidden],
1077
- children: /* @__PURE__ */ jsxs("svg", {
1078
- "aria-hidden": true,
1079
- className: spinClass,
1080
- height: "100%",
1081
- style: animating ? void 0 : pausedStyle,
1082
- viewBox: "0 0 32 32",
1083
- width: "100%",
1084
- children: [/* @__PURE__ */ jsx("circle", {
1085
- cx: "16",
1086
- cy: "16",
1087
- fill: "none",
1088
- opacity: "0.2",
1089
- r: "14",
1090
- stroke,
1091
- strokeWidth: "4"
1092
- }), /* @__PURE__ */ jsx("circle", {
1093
- cx: "16",
1094
- cy: "16",
1095
- fill: "none",
1096
- r: "14",
1097
- stroke,
1098
- strokeDasharray: "80",
1099
- strokeDashoffset: "60",
1100
- strokeWidth: "4"
1101
- })]
1102
- })
1103
- })
1104
- });
1105
- }
1106
- const styles$2 = StyleSheet.create({
1107
- container: {
1108
- alignItems: "center",
1109
- justifyContent: "center"
1110
- },
1111
- sizeSmall: {
1112
- width: 20,
1113
- height: 20
1114
- },
1115
- sizeLarge: {
1116
- width: 36,
1117
- height: 36
1118
- },
1119
- hidden: { visibility: "hidden" }
1120
- });
1121
- // src/events/responderEvent.ts
1122
- const hasPoint = (event) => event.clientX !== void 0 && !(event.type === "click" && event.detail === 0);
1123
- const activeTypes = /* @__PURE__ */ new Set([
1124
- "pointerdown",
1125
- "pointermove",
1126
- "keydown"
1127
- ]);
1128
- const define = (target, fields) => {
1129
- for (const key in fields) {
1130
- if (key in target) continue;
1131
- Object.defineProperty(target, key, {
1132
- value: fields[key],
1133
- configurable: true
1134
- });
1135
- }
1136
- };
1137
- const toGestureResponderEvent = (event, element) => {
1138
- const native = event.nativeEvent;
1139
- if (!("locationX" in native)) {
1140
- const rect = element.getBoundingClientRect();
1141
- const point = hasPoint(native);
1142
- const clientX = point ? native.clientX ?? 0 : rect.left + rect.width / 2;
1143
- const clientY = point ? native.clientY ?? 0 : rect.top + rect.height / 2;
1144
- const touch = {
1145
- changedTouches: [],
1146
- force: native.pressure,
1147
- identifier: native.pointerId ?? 0,
1148
- locationX: clientX - rect.left,
1149
- locationY: clientY - rect.top,
1150
- pageX: clientX + window.scrollX,
1151
- pageY: clientY + window.scrollY,
1152
- target: native.target,
1153
- timestamp: event.timeStamp,
1154
- touches: []
1155
- };
1156
- define(native, {
1157
- ...touch,
1158
- changedTouches: [touch],
1159
- touches: activeTypes.has(native.type) ? [touch] : []
1160
- });
1161
- }
1162
- return event;
1163
- };
1164
- const toMouseEvent = (event) => {
1165
- define(event.nativeEvent, { timestamp: event.timeStamp });
1166
- return event;
1167
- };
1168
- // src/events/press/Pressability.ts
1169
- const transitions = {
1170
- NOT_RESPONDER: { RESPONDER_GRANT: "RESPONDER_INACTIVE_PRESS_IN" },
1171
- RESPONDER_INACTIVE_PRESS_IN: {
1172
- DELAY: "RESPONDER_ACTIVE_PRESS_IN",
1173
- RESPONDER_RELEASE: "NOT_RESPONDER",
1174
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1175
- ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
1176
- LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
1177
- },
1178
- RESPONDER_INACTIVE_PRESS_OUT: {
1179
- DELAY: "RESPONDER_ACTIVE_PRESS_OUT",
1180
- RESPONDER_RELEASE: "NOT_RESPONDER",
1181
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1182
- ENTER_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_IN",
1183
- LEAVE_PRESS_RECT: "RESPONDER_INACTIVE_PRESS_OUT"
1184
- },
1185
- RESPONDER_ACTIVE_PRESS_IN: {
1186
- RESPONDER_RELEASE: "NOT_RESPONDER",
1187
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1188
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
1189
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT",
1190
- LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
1191
- },
1192
- RESPONDER_ACTIVE_PRESS_OUT: {
1193
- RESPONDER_RELEASE: "NOT_RESPONDER",
1194
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1195
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_IN",
1196
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_PRESS_OUT"
1197
- },
1198
- RESPONDER_ACTIVE_LONG_PRESS_IN: {
1199
- RESPONDER_RELEASE: "NOT_RESPONDER",
1200
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1201
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
1202
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT",
1203
- LONG_PRESS_DETECTED: "RESPONDER_ACTIVE_LONG_PRESS_IN"
1204
- },
1205
- RESPONDER_ACTIVE_LONG_PRESS_OUT: {
1206
- RESPONDER_RELEASE: "NOT_RESPONDER",
1207
- RESPONDER_TERMINATED: "NOT_RESPONDER",
1208
- ENTER_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_IN",
1209
- LEAVE_PRESS_RECT: "RESPONDER_ACTIVE_LONG_PRESS_OUT"
1210
- }
1211
- };
1212
- const isActive = (state) => state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
1213
- const isActivation = (state) => state === "RESPONDER_ACTIVE_PRESS_OUT" || state === "RESPONDER_ACTIVE_PRESS_IN";
1214
- const isPressIn = (state) => state === "RESPONDER_INACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_PRESS_IN" || state === "RESPONDER_ACTIVE_LONG_PRESS_IN";
1215
- const isTerminal = (signal) => signal === "RESPONDER_TERMINATED" || signal === "RESPONDER_RELEASE";
1216
- const DEFAULT_LONG_PRESS_DELAY_MS = 500;
1217
- const DEFAULT_MIN_PRESS_DURATION = 130;
1218
- const DEFAULT_PRESS_RECT_OFFSETS = {
1219
- bottom: 30,
1220
- left: 20,
1221
- right: 20,
1222
- top: 20
1223
- };
1224
- let longPressDeactivationDistance = 10;
1225
- const normalizeDelay = (delay, min = 0, fallback = 0) => Math.max(min, delay ?? fallback);
1226
- const normalizeRect = (rect) => typeof rect === "number" ? {
1227
- bottom: rect,
1228
- left: rect,
1229
- right: rect,
1230
- top: rect
1231
- } : rect;
1232
- const claimed = /* @__PURE__ */ new WeakSet();
1233
- const isActivationKey = (key) => key === "Enter" || key === " ";
1234
- const hasNativeActivation = (element) => {
1235
- switch (element.tagName) {
1236
- case "BUTTON":
1237
- case "INPUT":
1238
- case "SELECT":
1239
- case "SUMMARY":
1240
- case "TEXTAREA": return true;
1241
- case "A":
1242
- case "AREA": return element.hasAttribute("href");
1243
- default: return element.isContentEditable;
1244
- }
1245
- };
1246
- const nativeControl = "a[href],area[href],audio[controls],button,input,select,summary,textarea,video[controls],[contenteditable]:not([contenteditable=\"false\"])";
1247
- const startsInNativeControl = (event) => {
1248
- const { currentTarget, target } = event;
1249
- if (!(target instanceof Element)) return false;
1250
- const control = target.closest(nativeControl);
1251
- return control !== null && control !== currentTarget && currentTarget.contains(control);
1252
- };
1253
- const clear = (timer) => {
1254
- if (timer !== null) clearTimeout(timer);
1255
- return null;
1256
- };
1257
- var Pressability = class {
1258
- constructor(config) {
1259
- this.state = "NOT_RESPONDER";
1260
- this.element = null;
1261
- this.region = null;
1262
- this.pointerId = null;
1263
- this.key = null;
1264
- this.activatePosition = null;
1265
- this.activateTime = null;
1266
- this.hovered = false;
1267
- this.pointerClickPending = false;
1268
- this.cancelClick = false;
1269
- this.hoverInTimer = null;
1270
- this.hoverOutTimer = null;
1271
- this.longPressTimer = null;
1272
- this.pressDelayTimer = null;
1273
- this.pressOutTimer = null;
1274
- this.config = config;
1275
- this.handlers = this.createEventHandlers();
1276
- }
1277
- configure(config) {
1278
- this.config = config;
1279
- }
1280
- reset() {
1281
- this.hoverInTimer = clear(this.hoverInTimer);
1282
- this.hoverOutTimer = clear(this.hoverOutTimer);
1283
- this.longPressTimer = clear(this.longPressTimer);
1284
- this.pressDelayTimer = clear(this.pressDelayTimer);
1285
- this.pressOutTimer = clear(this.pressOutTimer);
1286
- this.config = Object.freeze({});
1287
- }
1288
- getEventHandlers() {
1289
- return this.handlers;
1290
- }
1291
- static setLongPressDeactivationDistance(distance) {
1292
- longPressDeactivationDistance = distance;
1293
- }
1294
- createEventHandlers() {
1295
- return {
1296
- onPointerDown: (event) => {
1297
- const native = event.nativeEvent;
1298
- if (event.button !== 0 || claimed.has(native) || this.config.disabled === true) return;
1299
- if (startsInNativeControl(event)) return;
1300
- claimed.add(native);
1301
- if (this.pointerId !== null || this.key !== null) return;
1302
- const element = event.currentTarget;
1303
- this.pointerId = event.pointerId;
1304
- this.pointerClickPending = true;
1305
- try {
1306
- element.setPointerCapture(event.pointerId);
1307
- } catch {}
1308
- this.grant(element, toGestureResponderEvent(event, element));
1309
- },
1310
- onPointerMove: (event) => {
1311
- const element = this.element;
1312
- if (event.pointerId !== this.pointerId || element === null) return;
1313
- const pressEvent = toGestureResponderEvent(event, element);
1314
- this.config.onPressMove?.(pressEvent);
1315
- const region = this.region;
1316
- if (region === null) return;
1317
- const { pageX, pageY } = pressEvent.nativeEvent;
1318
- const start = this.activatePosition;
1319
- if (start !== null && Math.hypot(start.pageX - pageX, start.pageY - pageY) > longPressDeactivationDistance) this.longPressTimer = clear(this.longPressTimer);
1320
- if (this.isWithinRegion(pageX, pageY, region)) this.receiveSignal("ENTER_PRESS_RECT", pressEvent);
1321
- else {
1322
- this.longPressTimer = clear(this.longPressTimer);
1323
- this.receiveSignal("LEAVE_PRESS_RECT", pressEvent);
1324
- }
1325
- },
1326
- onPointerUp: (event) => {
1327
- const element = this.element;
1328
- if (event.pointerId !== this.pointerId || element === null) return;
1329
- this.pointerId = null;
1330
- this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
1331
- },
1332
- onPointerCancel: (event) => {
1333
- const element = this.element;
1334
- if (event.pointerId !== this.pointerId || element === null) return;
1335
- this.pointerId = null;
1336
- this.pointerClickPending = false;
1337
- this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
1338
- },
1339
- onClick: (event) => {
1340
- const native = event.nativeEvent;
1341
- if (claimed.has(native) || startsInNativeControl(event)) return;
1342
- if (this.pointerClickPending && event.detail > 0) {
1343
- this.pointerClickPending = false;
1344
- claimed.add(native);
1345
- if (this.cancelClick) event.preventDefault();
1346
- return;
1347
- }
1348
- if (this.config.disabled === true) return;
1349
- claimed.add(native);
1350
- this.config.onPress?.(toGestureResponderEvent(event, event.currentTarget));
1351
- },
1352
- onKeyDown: (event) => {
1353
- if (!isActivationKey(event.key) || event.repeat || event.nativeEvent.isComposing) return;
1354
- const element = event.currentTarget;
1355
- if (event.target !== element || this.config.disabled === true) return;
1356
- if (hasNativeActivation(element)) return;
1357
- if (event.key === " ") event.preventDefault();
1358
- if (this.pointerId !== null || this.key !== null) return;
1359
- this.key = event.key;
1360
- this.grant(element, toGestureResponderEvent(event, element));
1361
- },
1362
- onKeyUp: (event) => {
1363
- const element = this.element;
1364
- if (event.key !== this.key || element === null) return;
1365
- this.key = null;
1366
- this.receiveSignal("RESPONDER_RELEASE", toGestureResponderEvent(event, element));
1367
- },
1368
- onFocus: (event) => {
1369
- this.config.onFocus?.(event);
1370
- },
1371
- onBlur: (event) => {
1372
- const element = this.element;
1373
- if (this.key !== null && element !== null && event.target === event.currentTarget) {
1374
- this.key = null;
1375
- this.receiveSignal("RESPONDER_TERMINATED", toGestureResponderEvent(event, element));
1376
- }
1377
- this.config.onBlur?.(event);
1378
- },
1379
- onPointerEnter: (event) => {
1380
- if (event.pointerType === "touch") return;
1381
- this.hovered = true;
1382
- this.hoverOutTimer = clear(this.hoverOutTimer);
1383
- this.hover(event, this.config.onHoverIn, this.config.delayHoverIn, "in");
1384
- },
1385
- onPointerLeave: (event) => {
1386
- if (!this.hovered) return;
1387
- this.hovered = false;
1388
- this.hoverInTimer = clear(this.hoverInTimer);
1389
- this.hover(event, this.config.onHoverOut, this.config.delayHoverOut, "out");
1390
- },
1391
- onContextMenu: (event) => {
1392
- if (this.pointerId !== null && this.config.onLongPress != null) event.preventDefault();
1393
- }
1394
- };
1395
- }
1396
- hover(event, callback, delay, direction) {
1397
- if (callback == null) return;
1398
- const hoverEvent = toMouseEvent(event);
1399
- const wait = normalizeDelay(delay);
1400
- if (wait === 0) {
1401
- callback(hoverEvent);
1402
- return;
1403
- }
1404
- const timer = setTimeout(() => callback(hoverEvent), wait);
1405
- if (direction === "in") this.hoverInTimer = timer;
1406
- else this.hoverOutTimer = timer;
1407
- }
1408
- grant(element, event) {
1409
- this.pressOutTimer = clear(this.pressOutTimer);
1410
- this.element = element;
1411
- this.cancelClick = false;
1412
- this.state = "NOT_RESPONDER";
1413
- this.receiveSignal("RESPONDER_GRANT", event);
1414
- const delayPressIn = normalizeDelay(this.config.delayPressIn);
1415
- if (delayPressIn > 0) this.pressDelayTimer = setTimeout(() => this.receiveSignal("DELAY", event), delayPressIn);
1416
- else this.receiveSignal("DELAY", event);
1417
- const delayLongPress = normalizeDelay(this.config.delayLongPress, 10, DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn);
1418
- this.longPressTimer = setTimeout(() => {
1419
- if (this.state === "RESPONDER_ACTIVE_PRESS_IN" || this.state === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.receiveSignal("LONG_PRESS_DETECTED", event);
1420
- }, delayLongPress + delayPressIn);
1421
- }
1422
- receiveSignal(signal, event) {
1423
- const prevState = this.state;
1424
- const nextState = transitions[prevState][signal];
1425
- if (nextState === void 0 || nextState === prevState) return;
1426
- this.performTransitionSideEffects(prevState, nextState, signal, event);
1427
- this.state = nextState;
1428
- }
1429
- performTransitionSideEffects(prevState, nextState, signal, event) {
1430
- if (isTerminal(signal)) {
1431
- this.activatePosition = null;
1432
- this.longPressTimer = clear(this.longPressTimer);
1433
- }
1434
- const isInitialTransition = prevState === "NOT_RESPONDER" && nextState === "RESPONDER_INACTIVE_PRESS_IN";
1435
- const isActivationTransition = !isActivation(prevState) && isActivation(nextState);
1436
- if (isInitialTransition || isActivationTransition) this.measureRegion();
1437
- if (isPressIn(prevState) && signal === "LONG_PRESS_DETECTED") this.config.onLongPress?.(event);
1438
- const isPrevActive = isActive(prevState);
1439
- const isNextActive = isActive(nextState);
1440
- if (!isPrevActive && isNextActive) this.activate(event);
1441
- else if (isPrevActive && !isNextActive) this.deactivate(event);
1442
- if (isPressIn(prevState) && signal === "RESPONDER_RELEASE") {
1443
- if (!isNextActive && !isPrevActive) {
1444
- this.activate(event);
1445
- this.deactivate(event);
1446
- }
1447
- const { onLongPress, onPress } = this.config;
1448
- if (onLongPress != null && prevState === "RESPONDER_ACTIVE_LONG_PRESS_IN") this.cancelClick = true;
1449
- else if (onPress != null) {
1450
- onPress(event);
1451
- if (event.isDefaultPrevented()) this.cancelClick = true;
1452
- }
1453
- }
1454
- this.pressDelayTimer = clear(this.pressDelayTimer);
1455
- }
1456
- activate(event) {
1457
- const { pageX, pageY } = event.nativeEvent;
1458
- this.activatePosition = {
1459
- pageX,
1460
- pageY
1461
- };
1462
- this.activateTime = Date.now();
1463
- this.config.onPressIn?.(event);
1464
- }
1465
- deactivate(event) {
1466
- const { onPressOut } = this.config;
1467
- if (onPressOut != null) {
1468
- const minPressDuration = normalizeDelay(this.config.minPressDuration, 0, DEFAULT_MIN_PRESS_DURATION);
1469
- const pressDuration = Date.now() - (this.activateTime ?? 0);
1470
- const delayPressOut = Math.max(minPressDuration - pressDuration, normalizeDelay(this.config.delayPressOut));
1471
- if (delayPressOut > 0) this.pressOutTimer = setTimeout(() => onPressOut(event), delayPressOut);
1472
- else onPressOut(event);
1473
- }
1474
- this.activateTime = null;
1475
- }
1476
- measureRegion() {
1477
- if (this.element === null) return;
1478
- const rect = this.element.getBoundingClientRect();
1479
- if (rect.width === 0 && rect.height === 0 && rect.top === 0 && rect.left === 0) return;
1480
- this.region = {
1481
- bottom: rect.bottom + window.scrollY,
1482
- left: rect.left + window.scrollX,
1483
- right: rect.right + window.scrollX,
1484
- top: rect.top + window.scrollY
1485
- };
1486
- }
1487
- isWithinRegion(pageX, pageY, region) {
1488
- const hitSlop = normalizeRect(this.config.hitSlop);
1489
- const offset = normalizeRect(this.config.pressRectOffset);
1490
- const bottom = region.bottom + (hitSlop?.bottom ?? 0) + (offset?.bottom ?? DEFAULT_PRESS_RECT_OFFSETS.bottom);
1491
- const left = region.left - (hitSlop?.left ?? 0) - (offset?.left ?? DEFAULT_PRESS_RECT_OFFSETS.left);
1492
- const right = region.right + (hitSlop?.right ?? 0) + (offset?.right ?? DEFAULT_PRESS_RECT_OFFSETS.right);
1493
- const top = region.top - (hitSlop?.top ?? 0) - (offset?.top ?? DEFAULT_PRESS_RECT_OFFSETS.top);
1494
- return pageX > left && pageX < right && pageY > top && pageY < bottom;
1495
- }
1496
- };
1497
- // src/events/press/usePressability.ts
1498
- function usePressability(config) {
1499
- const [pressability, setPressability] = useState(() => config == null ? null : new Pressability(config));
1500
- if (pressability === null && config != null) setPressability(new Pressability(config));
1501
- useInsertionEffect(() => {
1502
- if (config != null && pressability !== null) pressability.configure(config);
1503
- }, [config, pressability]);
1504
- useInsertionEffect(() => {
1505
- if (pressability === null) return void 0;
1506
- return () => pressability.reset();
1507
- }, [pressability]);
1508
- return pressability === null ? null : pressability.getEventHandlers();
1509
- }
1510
- // src/events/press/mergeHandlers.ts
1511
- const sharedHandlers = [
1512
- "onClick",
1513
- "onContextMenu",
1514
- "onKeyDown",
1515
- "onKeyUp",
1516
- "onPointerCancel",
1517
- "onPointerDown",
1518
- "onPointerEnter",
1519
- "onPointerLeave",
1520
- "onPointerMove",
1521
- "onPointerUp"
1522
- ];
1523
- const mergeHandlers = (app, own) => {
1524
- const merged = { ...own };
1525
- for (const key of sharedHandlers) {
1526
- const value = app[key];
1527
- if (typeof value !== "function") continue;
1528
- const appHandler = value;
1529
- const ownHandler = own[key];
1530
- merged[key] = (event) => {
1531
- appHandler(event);
1532
- ownHandler(event);
1533
- };
1534
- }
1535
- return merged;
1536
- };
1537
- // src/components/Text/TextAncestorContext.ts
1538
- const TextAncestorContext = createContext(false);
1539
- // src/components/Text/index.tsx
1540
- const resetStyle$1 = Object.freeze({
1541
- backgroundColor: "transparent",
1542
- border: "0 solid black",
1543
- boxSizing: "border-box",
1544
- color: "black",
1545
- display: "inline",
1546
- fontFamily: "System",
1547
- fontSize: 14,
1548
- listStyle: "none",
1549
- margin: 0,
1550
- padding: 0,
1551
- position: "relative",
1552
- textAlign: "start",
1553
- textDecoration: "none",
1554
- whiteSpace: "pre-wrap",
1555
- wordWrap: "break-word"
1556
- });
1557
- const nestedResetStyle = Object.freeze({
1558
- color: "inherit",
1559
- font: "inherit",
1560
- textAlign: "inherit",
1561
- textDecoration: "inherit",
1562
- whiteSpace: "inherit"
1563
- });
1564
- const singleLineStyle = Object.freeze({
1565
- overflow: "hidden",
1566
- textOverflow: "ellipsis",
1567
- whiteSpace: "nowrap"
1568
- });
1569
- const multiLineStyle = (lines) => ({
1570
- display: "-webkit-box",
1571
- WebkitBoxOrient: "vertical",
1572
- WebkitLineClamp: lines,
1573
- overflow: "hidden"
1574
- });
1575
- const selectionClass$1 = (registry, color) => {
1576
- const css = toCSSColor(color);
1577
- if (css === void 0) return void 0;
1578
- const name = `rn-sel-${css.replace(/[^a-z0-9]/g, "")}`;
1579
- return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
1580
- };
1581
- function Text(props) {
1582
- const { children, disabled, ellipsizeMode, numberOfLines, onBlur, onFocus, onLayout, onLongPress, onPress, onPressIn, onPressOut, pointerEvents, pressRetentionOffset, ref, selectable, selectionColor, style, suppressHighlighting: _suppressHighlighting, ...rest } = props;
1583
- const nested = useContext(TextAncestorContext);
1584
- const element = useRef(null);
1585
- useImperativeHandle(ref, () => element.current, []);
1586
- useElementLayout(element, onLayout);
1587
- const registry = useStyleRegistry();
1588
- const pressable = (onPress != null || onLongPress != null) && disabled !== true;
1589
- const handlers = usePressability(useMemo(() => pressable ? {
1590
- pressRectOffset: pressRetentionOffset,
1591
- onBlur,
1592
- onFocus,
1593
- onLongPress,
1594
- onPress,
1595
- onPressIn,
1596
- onPressOut
1597
- } : null, [
1598
- pressable,
1599
- pressRetentionOffset,
1600
- onBlur,
1601
- onFocus,
1602
- onLongPress,
1603
- onPress,
1604
- onPressIn,
1605
- onPressOut
1606
- ]));
1607
- const roleProps = pressable && rest.role === void 0 && rest.accessibilityRole === void 0 ? {
1608
- ...rest,
1609
- role: "link"
1610
- } : rest;
1611
- const { tag, role } = resolveTag(roleProps, "span", children != null);
1612
- const lineStyle = numberOfLines === void 0 || numberOfLines < 1 ? void 0 : numberOfLines === 1 ? singleLineStyle : multiLineStyle(numberOfLines);
1613
- let className = compileStyle([
1614
- nested ? nestedResetStyle : resetStyle$1,
1615
- style,
1616
- lineStyle,
1617
- ellipsizeMode === "clip" ? { textOverflow: "clip" } : void 0,
1618
- selectable === false ? { userSelect: "none" } : void 0,
1619
- pointerEvents === "none" || pointerEvents === "auto" ? { pointerEvents } : void 0
1620
- ], registry);
1621
- if (selectionColor !== void 0) {
1622
- const extra = selectionClass$1(registry, selectionColor);
1623
- if (extra !== void 0) className = `${className} ${extra}`;
1624
- }
1625
- const domProps = toDOMProps(rest);
1626
- if (role !== void 0) domProps["role"] = role;
1627
- if (tag.length === 2 && tag[0] === "h") delete domProps["aria-level"];
1628
- if (tag === "button") domProps["type"] = "button";
1629
- if (disabled === true) domProps["aria-disabled"] = true;
1630
- if (pressable && handlers !== null) {
1631
- Object.assign(domProps, mergeHandlers(rest, handlers));
1632
- if (domProps["tabIndex"] === void 0 && tag !== "a" && tag !== "button") domProps["tabIndex"] = 0;
1633
- } else {
1634
- if (onFocus !== void 0) domProps["onFocus"] = onFocus;
1635
- if (onBlur !== void 0) domProps["onBlur"] = onBlur;
1636
- }
1637
- domProps["className"] = className;
1638
- domProps["ref"] = element;
1639
- const content = nested ? children : createElement(TextAncestorContext.Provider, { value: true }, children);
1640
- return createElement(tag, domProps, content);
1641
- }
1642
- // src/render/hitSlop.ts
1643
- const hitSlopClass = (registry, hitSlop) => {
1644
- if (hitSlop === void 0) return void 0;
1645
- const { top = 0, right = 0, bottom = 0, left = 0 } = typeof hitSlop === "number" ? {
1646
- top: hitSlop,
1647
- right: hitSlop,
1648
- bottom: hitSlop,
1649
- left: hitSlop
1650
- } : hitSlop;
1651
- if (top === 0 && right === 0 && bottom === 0 && left === 0) return void 0;
1652
- const name = `rn-hs-${[
1653
- top,
1654
- right,
1655
- bottom,
1656
- left
1657
- ].map((n) => String(n).replace(/[^0-9]/g, "_")).join("-")}`;
1658
- return registry.staticClass(name, [`.${name}::before{content:"";position:absolute;top:${-top}px;right:${-right}px;bottom:${-bottom}px;left:${-left}px;z-index:-1}`]);
1659
- };
1660
- // src/components/TouchableOpacity/index.tsx
1661
- const EASE_IN_OUT_QUAD = "cubic-bezier(0.455, 0.03, 0.515, 0.955)";
1662
- const DEFAULT_ACTIVE_OPACITY$1 = .2;
1663
- const notCancelableStyle$2 = Object.freeze({ touchAction: "none" });
1664
- const isTrue$1 = (value) => value === void 0 ? void 0 : value === true || value === "true";
1665
- const restingOpacity = (style) => {
1666
- const opacity = flattenStyle(style)?.["opacity"];
1667
- return typeof opacity === "number" ? opacity : 1;
1668
- };
1669
- function TouchableOpacity(props) {
1670
- 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;
1671
- const element = useRef(null);
1672
- const animation = useRef(null);
1673
- const resting = restingOpacity(style);
1674
- const resolvedDisabled = disabled ?? isTrue$1(props["aria-disabled"]) ?? props.accessibilityState?.disabled;
1675
- const fadeTo = useCallback((opacity, duration, settle) => {
1676
- const node = element.current;
1677
- if (node === null || typeof node.animate !== "function") return;
1678
- const from = getComputedStyle(node).opacity;
1679
- animation.current?.cancel();
1680
- const next = node.animate([{ opacity: from }, { opacity: String(opacity) }], {
1681
- duration,
1682
- easing: EASE_IN_OUT_QUAD,
1683
- fill: "forwards"
1684
- });
1685
- animation.current = next;
1686
- if (settle) next.onfinish = () => {
1687
- if (animation.current !== next) return;
1688
- next.cancel();
1689
- animation.current = null;
1690
- };
1691
- }, []);
1692
- const handlers = usePressability(useMemo(() => ({
1693
- cancelable: rejectResponderTermination !== true,
1694
- disabled: resolvedDisabled,
1695
- hitSlop,
1696
- delayLongPress,
1697
- delayPressIn,
1698
- delayPressOut,
1699
- minPressDuration: 0,
1700
- pressRectOffset: pressRetentionOffset,
1701
- android_disableSound: touchSoundDisabled,
1702
- onBlur,
1703
- onFocus,
1704
- onLongPress,
1705
- onPress,
1706
- onPressIn: (event) => {
1707
- const starts = event.type === "pointerdown" || event.type === "keydown";
1708
- fadeTo(activeOpacity ?? DEFAULT_ACTIVE_OPACITY$1, starts ? 0 : 150, false);
1709
- onPressIn?.(event);
1710
- },
1711
- onPressOut: (event) => {
1712
- fadeTo(resting, 250, true);
1713
- onPressOut?.(event);
1714
- }
1715
- }), [
1716
- activeOpacity,
1717
- delayLongPress,
1718
- delayPressIn,
1719
- delayPressOut,
1720
- fadeTo,
1721
- hitSlop,
1722
- onBlur,
1723
- onFocus,
1724
- onLongPress,
1725
- onPress,
1726
- onPressIn,
1727
- onPressOut,
1728
- pressRetentionOffset,
1729
- rejectResponderTermination,
1730
- resolvedDisabled,
1731
- resting,
1732
- touchSoundDisabled
1733
- ]));
1734
- const registry = useStyleRegistry();
1735
- const previous = useRef({
1736
- disabled,
1737
- resting
1738
- });
1739
- useEffect(() => {
1740
- if (previous.current.disabled === disabled && previous.current.resting === resting) return;
1741
- previous.current = {
1742
- disabled,
1743
- resting
1744
- };
1745
- fadeTo(resting, 250, true);
1746
- }, [
1747
- disabled,
1748
- fadeTo,
1749
- resting
1750
- ]);
1751
- useEffect(() => () => {
1752
- animation.current?.cancel();
1753
- }, []);
1754
- const view = useViewElement({
1755
- ...rest,
1756
- ...mergeHandlers(rest, handlers),
1757
- ref: element,
1758
- focusable: focusable !== false && onPress !== void 0 && disabled !== true,
1759
- style: [style, rejectResponderTermination === true && notCancelableStyle$2],
1760
- children,
1761
- ...resolvedDisabled === true && { "aria-disabled": true }
1762
- }, hitSlopClass(registry, hitSlop));
1763
- useImperativeHandle(ref, () => element.current, []);
1764
- return view;
1765
- }
1766
- // src/components/Button/index.tsx
1767
- function Button(props) {
1768
- const { accessibilityActions: _accessibilityActions, accessibilityLanguage, accessibilityState, "aria-disabled": ariaDisabled, color, importantForAccessibility, onAccessibilityAction: _onAccessibilityAction, title, ...rest } = props;
1769
- if (typeof title !== "string") throw new Error("The title prop of a Button must be a string");
1770
- const disabled = props.disabled ?? ariaDisabled ?? accessibilityState?.disabled;
1771
- const state = disabled === accessibilityState?.disabled ? accessibilityState : {
1772
- ...accessibilityState,
1773
- disabled
1774
- };
1775
- return /* @__PURE__ */ jsx(TouchableOpacity, {
1776
- ...rest,
1777
- ...accessibilityLanguage !== void 0 && { lang: accessibilityLanguage },
1778
- role: "button",
1779
- accessibilityState: state,
1780
- disabled,
1781
- importantForAccessibility: importantForAccessibility === "no" ? "no-hide-descendants" : importantForAccessibility,
1782
- style: [
1783
- styles$1.button,
1784
- color != null && color !== "" && { backgroundColor: color },
1785
- disabled === true && styles$1.buttonDisabled
1786
- ],
1787
- children: /* @__PURE__ */ jsx(Text, {
1788
- style: [styles$1.text, disabled === true && styles$1.textDisabled],
1789
- children: title
1790
- })
1791
- });
1792
- }
1793
- const styles$1 = StyleSheet.create({
1794
- button: {
1795
- backgroundColor: "#2196F3",
1796
- borderRadius: 2
1797
- },
1798
- text: {
1799
- color: "white",
1800
- fontWeight: "500",
1801
- margin: 8,
1802
- textAlign: "center"
1803
- },
1804
- buttonDisabled: { backgroundColor: "#dfdfdf" },
1805
- textDisabled: { color: "#a1a1a1" }
1806
- });
1807
- // src/components/ScrollView/snap.ts
1808
- const nearest = (offset, candidates) => {
1809
- let best;
1810
- let distance = Infinity;
1811
- for (const candidate of candidates) {
1812
- const d = Math.abs(candidate - offset);
1813
- if (d < distance) {
1814
- distance = d;
1815
- best = candidate;
1816
- }
1817
- }
1818
- return best;
1819
- };
1820
- const snapTarget = (offset, viewport, contentSize, config) => {
1821
- const max = Math.max(0, contentSize - viewport);
1822
- let target;
1823
- if (config.offsets !== void 0) {
1824
- if (config.offsets.length === 0) return void 0;
1825
- const first = Math.min(...config.offsets);
1826
- const last = Math.max(...config.offsets);
1827
- if (!config.snapToStart && offset < first) return void 0;
1828
- if (!config.snapToEnd && offset > last) return void 0;
1829
- const candidates = [...config.offsets];
1830
- if (config.snapToStart) candidates.push(0);
1831
- if (config.snapToEnd) candidates.push(max);
1832
- target = nearest(offset, candidates);
1833
- } else if (config.interval !== void 0 && config.interval > 0) {
1834
- const { interval, alignment } = config;
1835
- const shift = alignment === "center" ? (viewport - interval) / 2 : alignment === "end" ? viewport - interval : 0;
1836
- target = Math.round((offset + shift) / interval) * interval - shift;
1837
- }
1838
- if (target === void 0) return void 0;
1839
- target = Math.min(max, Math.max(0, target));
1840
- return Math.abs(target - offset) < .5 ? void 0 : target;
1841
- };
1842
- // src/components/ScrollView/index.tsx
1843
- const scrollerStyle = Object.freeze({
1844
- flexGrow: 1,
1845
- flexShrink: 1,
1846
- overflowX: "hidden",
1847
- overflowY: "auto",
1848
- WebkitOverflowScrolling: "touch"
1849
- });
1850
- const horizontalScrollerStyle = Object.freeze({
1851
- flexDirection: "row",
1852
- overflowX: "auto",
1853
- overflowY: "hidden"
1854
- });
1855
- const disabledScrollerStyle = Object.freeze({
1856
- overflowX: "hidden",
1857
- overflowY: "hidden"
1858
- });
1859
- const horizontalContentStyle = Object.freeze({ flexDirection: "row" });
1860
- const centerContentStyle = Object.freeze({
1861
- flexGrow: 1,
1862
- justifyContent: "center"
1863
- });
1864
- const stickyStyle = Object.freeze({
1865
- position: "sticky",
1866
- top: 0,
1867
- zIndex: 10
1868
- });
1869
- const invertedStickyStyle = Object.freeze({
1870
- position: "sticky",
1871
- bottom: 0,
1872
- zIndex: 10
1873
- });
1874
- 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}"]);
1875
- const supportsScrollEnd = hasDOM() && "onscrollend" in window;
1876
- const SCROLL_END_DELAY = 150;
1877
- const behaviorFor = (animated) => animated !== false && !Platform.isDisableAnimations ? "smooth" : "auto";
1878
- const describe = (element) => ({
1879
- contentInset: {
1880
- top: 0,
1881
- left: 0,
1882
- bottom: 0,
1883
- right: 0
1884
- },
1885
- contentOffset: {
1886
- x: element.scrollLeft,
1887
- y: element.scrollTop
1888
- },
1889
- contentSize: {
1890
- width: element.scrollWidth,
1891
- height: element.scrollHeight
1892
- },
1893
- layoutMeasurement: {
1894
- width: element.clientWidth,
1895
- height: element.clientHeight
1896
- },
1897
- zoomScale: 1
1898
- });
1899
- const isReactNativeScrollTo = (value) => typeof value === "object" && value !== null && ("x" in value || "y" in value || "animated" in value);
1900
- const domScrollTo = (element, options) => {
1901
- const init = { behavior: behaviorFor(options.animated) };
1902
- if (options.x !== void 0) init.left = options.x;
1903
- if (options.y !== void 0) init.top = options.y;
1904
- element.scrollTo(init);
1905
- };
1906
- function ScrollView(props) {
1907
- 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;
1908
- const registry = useStyleRegistry();
1909
- const scroller = useRef(null);
1910
- const content = useRef(null);
1911
- const handlers = useRef({});
1912
- useEffect(() => {
1913
- handlers.current = {
1914
- onScroll,
1915
- onScrollBeginDrag,
1916
- onScrollEndDrag,
1917
- onMomentumScrollBegin,
1918
- onMomentumScrollEnd
1919
- };
1920
- });
1921
- const snap = useRef({
1922
- horizontal,
1923
- pagingEnabled: pagingEnabled === true,
1924
- snapToInterval,
1925
- snapToOffsets,
1926
- snapToAlignment,
1927
- snapToStart,
1928
- snapToEnd,
1929
- keyboardDismissMode,
1930
- stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
1931
- });
1932
- useEffect(() => {
1933
- snap.current = {
1934
- horizontal,
1935
- pagingEnabled: pagingEnabled === true,
1936
- snapToInterval,
1937
- snapToOffsets,
1938
- snapToAlignment,
1939
- snapToStart,
1940
- snapToEnd,
1941
- keyboardDismissMode,
1942
- stickyHeaderHiddenOnScroll: stickyHeaderHiddenOnScroll === true
1943
- };
1944
- });
1945
- const sequence = useRef({
1946
- phase: "idle",
1947
- pointerDown: false,
1948
- lastEvent: null,
1949
- lastOffset: 0,
1950
- timer: void 0,
1951
- snapping: false
1952
- });
1953
- const stickyHeaders = useRef([]);
1954
- const refreshEvent = useCallback(() => {
1955
- const state = sequence.current;
1956
- const element = scroller.current;
1957
- if (state.lastEvent === null || element === null) return null;
1958
- Object.assign(state.lastEvent.nativeEvent, describe(element));
1959
- return state.lastEvent;
1960
- }, []);
1961
- const settle = useCallback(() => {
1962
- const state = sequence.current;
1963
- const element = scroller.current;
1964
- if (element === null) return;
1965
- if (state.pointerDown && state.phase === "drag") return;
1966
- if (state.phase === "momentum") {
1967
- const event = refreshEvent();
1968
- if (event !== null) handlers.current.onMomentumScrollEnd?.(event);
1969
- }
1970
- state.phase = "idle";
1971
- if (state.snapping) {
1972
- state.snapping = false;
1973
- return;
1974
- }
1975
- const config = snap.current;
1976
- const axis = config.horizontal;
1977
- const viewport = axis ? element.clientWidth : element.clientHeight;
1978
- const target = snapTarget(axis ? element.scrollLeft : element.scrollTop, viewport, axis ? element.scrollWidth : element.scrollHeight, {
1979
- offsets: config.snapToOffsets,
1980
- interval: config.pagingEnabled ? viewport : config.snapToInterval,
1981
- alignment: config.snapToAlignment,
1982
- snapToStart: config.snapToStart,
1983
- snapToEnd: config.snapToEnd
1984
- });
1985
- if (target === void 0) return;
1986
- state.snapping = true;
1987
- domScrollTo(element, axis ? { x: target } : { y: target });
1988
- }, [refreshEvent]);
1989
- const handleScroll = (event) => {
1990
- const element = event.currentTarget;
1991
- if (event.target !== element) return;
1992
- const state = sequence.current;
1993
- const scrollEvent = event;
1994
- Object.assign(scrollEvent.nativeEvent, describe(element));
1995
- state.lastEvent = scrollEvent;
1996
- const config = snap.current;
1997
- const offset = config.horizontal ? element.scrollLeft : element.scrollTop;
1998
- const delta = offset - state.lastOffset;
1999
- state.lastOffset = offset;
2000
- if (state.phase === "idle") {
2001
- if (state.pointerDown) {
2002
- state.phase = "drag";
2003
- handlers.current.onScrollBeginDrag?.(scrollEvent);
2004
- if (config.keyboardDismissMode === "on-drag") {
2005
- const active = document.activeElement;
2006
- if (active instanceof HTMLElement && active !== document.body) active.blur();
2007
- }
2008
- } else {
2009
- state.phase = "momentum";
2010
- handlers.current.onMomentumScrollBegin?.(scrollEvent);
2011
- }
2012
- } else if (state.phase === "released") {
2013
- state.phase = "momentum";
2014
- handlers.current.onMomentumScrollBegin?.(scrollEvent);
2015
- }
2016
- if (config.stickyHeaderHiddenOnScroll && !config.horizontal && delta !== 0) {
2017
- const hidden = delta > 0;
2018
- for (const header of stickyHeaders.current) {
2019
- header.style.transition = "transform 150ms";
2020
- header.style.transform = hidden ? "translateY(-100%)" : "";
2021
- }
2022
- }
2023
- handlers.current.onScroll?.(scrollEvent);
2024
- if (!supportsScrollEnd) {
2025
- if (state.timer !== void 0) clearTimeout(state.timer);
2026
- state.timer = setTimeout(settle, SCROLL_END_DELAY);
2027
- }
2028
- };
2029
- const handleScrollEnd = (event) => {
2030
- if (event.target !== event.currentTarget) return;
2031
- settle();
2032
- };
2033
- const handlePointerDown = (event) => {
2034
- onPointerDown?.(event);
2035
- const state = sequence.current;
2036
- if (state.pointerDown) return;
2037
- state.pointerDown = true;
2038
- const release = () => {
2039
- window.removeEventListener("pointerup", release);
2040
- window.removeEventListener("pointercancel", release);
2041
- state.pointerDown = false;
2042
- if (state.phase === "drag") {
2043
- state.phase = "released";
2044
- const scrollEvent = refreshEvent();
2045
- if (scrollEvent !== null) handlers.current.onScrollEndDrag?.(scrollEvent);
2046
- }
2047
- };
2048
- window.addEventListener("pointerup", release);
2049
- window.addEventListener("pointercancel", release);
2050
- };
2051
- useEffect(() => {
2052
- const state = sequence.current;
2053
- return () => {
2054
- if (state.timer !== void 0) clearTimeout(state.timer);
2055
- };
2056
- }, []);
2057
- const onContentLayout = onContentSizeChange === void 0 ? void 0 : (event) => onContentSizeChange(event.nativeEvent.layout.width, event.nativeEvent.layout.height);
2058
- const stickySet = stickyHeaderIndices !== void 0 && stickyHeaderIndices.length > 0 && !horizontal ? new Set(stickyHeaderIndices) : void 0;
2059
- const setStickyHeader = useCallback((node) => {
2060
- const list = stickyHeaders.current;
2061
- if (node === null) return;
2062
- if (!list.includes(node)) list.push(node);
2063
- return () => {
2064
- const index = list.indexOf(node);
2065
- if (index !== -1) list.splice(index, 1);
2066
- };
2067
- }, []);
2068
- let items = children;
2069
- if (stickySet !== void 0) items = Children.toArray(children).map((child, index) => stickySet.has(index) ? /* @__PURE__ */ jsx(View, {
2070
- ref: setStickyHeader,
2071
- style: invertStickyHeaders === true ? invertedStickyStyle : stickyStyle,
2072
- children: child
2073
- }, isValidElement(child) && child.key !== null ? child.key : `sticky-${index}`) : child);
2074
- const contentElement = /* @__PURE__ */ jsx(View, {
2075
- ref: content,
2076
- onLayout: onContentLayout,
2077
- style: [
2078
- horizontal && horizontalContentStyle,
2079
- centerContent === true && centerContentStyle,
2080
- contentContainerStyle
2081
- ],
2082
- children: items
2083
- });
2084
- const hideScrollbar = horizontal ? !showsHorizontalScrollIndicator : !showsVerticalScrollIndicator;
2085
- const scrollerElement = useViewElement({
2086
- ...rest,
2087
- ref: scroller,
2088
- style: [
2089
- scrollerStyle,
2090
- horizontal && horizontalScrollerStyle,
2091
- !scrollEnabled && disabledScrollerStyle,
2092
- style
2093
- ],
2094
- onScroll: handleScroll,
2095
- onScrollEnd: handleScrollEnd,
2096
- onPointerDown: handlePointerDown,
2097
- children: contentElement
2098
- }, hideScrollbar ? hiddenScrollbarClass(registry) : void 0);
2099
- const offsetX = contentOffset?.x;
2100
- const offsetY = contentOffset?.y;
2101
- useLayoutEffect(() => {
2102
- const element = scroller.current;
2103
- if (element === null || offsetX === void 0 && offsetY === void 0) return;
2104
- if (offsetX !== void 0) element.scrollLeft = offsetX;
2105
- if (offsetY !== void 0) element.scrollTop = offsetY;
2106
- sequence.current.lastOffset = horizontal ? element.scrollLeft : element.scrollTop;
2107
- }, [
2108
- offsetX,
2109
- offsetY,
2110
- horizontal
2111
- ]);
2112
- useImperativeHandle(ref, () => {
2113
- const element = scroller.current;
2114
- const nativeScrollTo = element.scrollTo.bind(element);
2115
- const instance = element;
2116
- return Object.assign(instance, {
2117
- scrollTo: ((first, second) => {
2118
- if (isReactNativeScrollTo(first)) domScrollTo(element, first);
2119
- else if (typeof first === "number" && typeof second === "number") nativeScrollTo(first, second);
2120
- else nativeScrollTo(first);
2121
- }),
2122
- scrollToEnd: (options) => {
2123
- const animated = options?.animated;
2124
- domScrollTo(element, horizontal ? {
2125
- x: element.scrollWidth,
2126
- animated
2127
- } : {
2128
- y: element.scrollHeight,
2129
- animated
2130
- });
2131
- },
2132
- flashScrollIndicators: () => {},
2133
- getScrollResponder: () => instance,
2134
- getScrollableNode: () => element,
2135
- getInnerViewNode: () => content.current,
2136
- getInnerViewRef: () => content.current,
2137
- getNativeScrollRef: () => element
2138
- });
2139
- }, [horizontal]);
2140
- return refreshControl === void 0 ? scrollerElement : cloneElement(refreshControl, void 0, scrollerElement);
2141
- }
2142
- // src/components/FlatList/viewability.ts
2143
- const pixelsVisible = (top, bottom, viewport) => Math.max(0, Math.min(bottom, viewport) - Math.max(top, 0));
2144
- const isEntirelyVisible = (top, bottom, viewport) => top >= 0 && bottom <= viewport && bottom > top;
2145
- const isViewable = (viewAreaMode, threshold, top, bottom, viewport, length) => {
2146
- if (isEntirelyVisible(top, bottom, viewport)) return true;
2147
- const pixels = pixelsVisible(top, bottom, viewport);
2148
- return 100 * (viewAreaMode ? pixels / viewport : pixels / length) >= threshold;
2149
- };
2150
- const computeViewableIndices = (itemCount, metricsAt, scrollOffset, viewport, config) => {
2151
- const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = config;
2152
- const viewAreaMode = viewAreaCoveragePercentThreshold != null;
2153
- const threshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
2154
- if (threshold == null || viewAreaMode === (itemVisiblePercentThreshold != null)) throw new Error("Must set exactly one of itemVisiblePercentThreshold or viewAreaCoveragePercentThreshold");
2155
- const viewable = [];
2156
- let firstVisible = -1;
2157
- for (let index = 0; index < itemCount; index++) {
2158
- const metrics = metricsAt(index);
2159
- if (metrics === void 0) continue;
2160
- const top = Math.floor(metrics.offset - scrollOffset);
2161
- const bottom = Math.floor(top + metrics.length);
2162
- if (top < viewport && bottom > 0) {
2163
- firstVisible = index;
2164
- if (isViewable(viewAreaMode, threshold, top, bottom, viewport, metrics.length)) viewable.push(index);
2165
- } else if (firstVisible >= 0) break;
2166
- }
2167
- return viewable;
2168
- };
2169
- const sameIndices = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
2170
- var ViewabilityTracker = class {
2171
- constructor(config = { viewAreaCoveragePercentThreshold: 0 }) {
2172
- this.interacted = false;
2173
- this.timers = /* @__PURE__ */ new Set();
2174
- this.viewableIndices = [];
2175
- this.viewableItems = /* @__PURE__ */ new Map();
2176
- this.config = config;
2177
- }
2178
- dispose() {
2179
- for (const timer of this.timers) clearTimeout(timer);
2180
- this.timers.clear();
2181
- }
2182
- recordInteraction() {
2183
- this.interacted = true;
2184
- }
2185
- resetViewableIndices() {
2186
- this.viewableIndices = [];
2187
- }
2188
- onUpdate(itemCount, metricsAt, scrollOffset, viewport, createViewToken, onViewableItemsChanged) {
2189
- if (this.config.waitForInteraction === true && !this.interacted || itemCount === 0) return;
2190
- if (metricsAt(0) === void 0) return;
2191
- const next = computeViewableIndices(itemCount, metricsAt, scrollOffset, viewport, this.config);
2192
- if (sameIndices(this.viewableIndices, next)) return;
2193
- this.viewableIndices = next;
2194
- const { minimumViewTime } = this.config;
2195
- if (minimumViewTime !== void 0 && minimumViewTime > 0) {
2196
- const timer = setTimeout(() => {
2197
- this.timers.delete(timer);
2198
- if (this.viewableIndices !== next) return;
2199
- this.report(next, createViewToken, onViewableItemsChanged);
2200
- }, minimumViewTime);
2201
- this.timers.add(timer);
2202
- } else this.report(next, createViewToken, onViewableItemsChanged);
2203
- }
2204
- report(indices, createViewToken, onViewableItemsChanged) {
2205
- const previous = this.viewableItems;
2206
- const next = /* @__PURE__ */ new Map();
2207
- for (const index of indices) {
2208
- const token = createViewToken(index, true);
2209
- next.set(token.key, token);
2210
- }
2211
- const changed = [];
2212
- for (const [key, token] of next) if (!previous.has(key)) changed.push(token);
2213
- for (const [key, token] of previous) if (!next.has(key)) changed.push({
2214
- ...token,
2215
- isViewable: false
2216
- });
2217
- if (changed.length === 0) return;
2218
- this.viewableItems = next;
2219
- onViewableItemsChanged({
2220
- viewableItems: Array.from(next.values()),
2221
- changed
2222
- });
2223
- }
2224
- };
2225
- // src/components/FlatList/index.tsx
2226
- const rowStyle = Object.freeze({ flexDirection: "row" });
2227
- const rowReverseStyle = Object.freeze({ flexDirection: "row-reverse" });
2228
- const columnReverseStyle = Object.freeze({ flexDirection: "column-reverse" });
2229
- const verticallyInvertedStyle = Object.freeze({ transform: [{ scaleY: -1 }] });
2230
- const horizontallyInvertedStyle = Object.freeze({ transform: [{ scaleX: -1 }] });
2231
- const ON_EDGE_REACHED_EPSILON = .001;
2232
- const DEFAULT_EDGE_THRESHOLD_PX = 2;
2233
- const defaultKeyExtractor = (item, index) => {
2234
- if (typeof item === "object" && item !== null) {
2235
- const record = item;
2236
- if (record.key != null) return String(record.key);
2237
- if (record.id != null) return String(record.id);
2238
- }
2239
- return String(index);
2240
- };
2241
- const isArrayLike = (data) => data != null && typeof data.length === "number";
2242
- const renderListComponent = (component) => {
2243
- if (component == null) return null;
2244
- if (isValidElement(component)) return component;
2245
- return /* @__PURE__ */ jsx(component, {});
2246
- };
2247
- function CustomScroller({ render, ref, ...props }) {
2248
- return cloneElement(render(props), { ref }, props.children);
2249
- }
2250
- function Cell(props) {
2251
- const { cellKey, prevCellKey, index, item, style, renderCell, ItemSeparatorComponent, CellRendererComponent, separatorUpdaters, onElement } = props;
2252
- const [separatorProps, setSeparatorProps] = useState({
2253
- highlighted: false,
2254
- leadingItem: item
2255
- });
2256
- const shown = separatorProps.leadingItem === item ? separatorProps : {
2257
- ...separatorProps,
2258
- leadingItem: item
2259
- };
2260
- useEffect(() => {
2261
- separatorUpdaters.set(cellKey, (next) => {
2262
- setSeparatorProps((current) => ({
2263
- ...current,
2264
- ...next
2265
- }));
2266
- });
2267
- return () => {
2268
- separatorUpdaters.delete(cellKey);
2269
- };
2270
- }, [cellKey, separatorUpdaters]);
2271
- const separators = useMemo(() => {
2272
- const update = (keys, next) => {
2273
- for (const key of keys) if (key !== void 0) separatorUpdaters.get(key)?.(next);
2274
- };
2275
- return {
2276
- highlight: () => update([cellKey, prevCellKey], { highlighted: true }),
2277
- unhighlight: () => update([cellKey, prevCellKey], { highlighted: false }),
2278
- updateProps: (select, next) => update([select === "leading" ? prevCellKey : cellKey], next)
2279
- };
2280
- }, [
2281
- cellKey,
2282
- prevCellKey,
2283
- separatorUpdaters
2284
- ]);
2285
- const setElement = useCallback((node) => {
2286
- if (node === null) return;
2287
- onElement(index, node);
2288
- return () => onElement(index, null);
2289
- }, [index, onElement]);
2290
- let separator = null;
2291
- if (ItemSeparatorComponent != null) {
2292
- if (isValidElement(ItemSeparatorComponent)) separator = ItemSeparatorComponent;
2293
- else separator = /* @__PURE__ */ jsx(ItemSeparatorComponent, { ...shown });
2294
- }
2295
- const element = renderCell(item, index, separators);
2296
- if (CellRendererComponent != null) return /* @__PURE__ */ jsx(View, {
2297
- ref: setElement,
2298
- children: /* @__PURE__ */ jsxs(CellRendererComponent, {
2299
- cellKey,
2300
- index,
2301
- item,
2302
- style,
2303
- children: [element, separator]
2304
- })
2305
- });
2306
- return /* @__PURE__ */ jsxs(View, {
2307
- ref: setElement,
2308
- style,
2309
- children: [element, separator]
2310
- });
2311
- }
2312
- const createTrackers = (props) => {
2313
- if (props.viewabilityConfigCallbackPairs !== void 0) return props.viewabilityConfigCallbackPairs.map((pair) => ({
2314
- tracker: new ViewabilityTracker(pair.viewabilityConfig),
2315
- callback: () => pair.onViewableItemsChanged
2316
- }));
2317
- if (props.onViewableItemsChanged != null) return [{
2318
- tracker: new ViewabilityTracker(props.viewabilityConfig),
2319
- callback: (latest) => latest.onViewableItemsChanged
2320
- }];
2321
- return [];
2322
- };
2323
- function FlatList(props) {
2324
- 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, extraData: _extraData, onRefresh: _onRefresh, refreshing: _refreshing, debug: _debug, disableVirtualization: _disableVirtualization, initialNumToRender: _initialNumToRender, maxToRenderPerBatch: _maxToRenderPerBatch, progressViewOffset: _progressViewOffset, strictMode: _strictMode, updateCellsBatchingPeriod: _updateCellsBatchingPeriod, windowSize: _windowSize, legacyImplementation: _legacyImplementation, ...scrollViewProps } = props;
2325
- if (numColumns > 1 && horizontal) throw new Error("numColumns does not support horizontal.");
2326
- const latest = useRef(props);
2327
- useEffect(() => {
2328
- latest.current = props;
2329
- });
2330
- const scroller = useRef(null);
2331
- const [cells] = useState(() => /* @__PURE__ */ new Map());
2332
- const [separatorUpdaters] = useState(() => /* @__PURE__ */ new Map());
2333
- const [trackers] = useState(() => createTrackers(props));
2334
- const edge = useRef({
2335
- sentEndForContentLength: 0,
2336
- sentStartForContentLength: 0
2337
- });
2338
- useEffect(() => {
2339
- return () => {
2340
- for (const entry of trackers) entry.tracker.dispose();
2341
- };
2342
- }, [trackers]);
2343
- const onElement = useCallback((index, node) => {
2344
- if (node === null) cells.delete(index);
2345
- else cells.set(index, node);
2346
- }, [cells]);
2347
- const items = isArrayLike(data) ? data : [];
2348
- const rowCount = numColumns > 1 ? Math.ceil(items.length / numColumns) : items.length;
2349
- const rowAt = (index) => {
2350
- if (numColumns === 1) return items[index];
2351
- const row = [];
2352
- for (let column = 0; column < numColumns; column++) {
2353
- const itemIndex = index * numColumns + column;
2354
- if (itemIndex < items.length) row.push(items[itemIndex]);
2355
- }
2356
- return row;
2357
- };
2358
- const rowKey = (row, index) => {
2359
- if (numColumns === 1) return keyExtractor(row, index);
2360
- return row.map((item, column) => keyExtractor(item, index * numColumns + column)).join(":");
2361
- };
2362
- const metricsAt = useCallback((index) => {
2363
- const element = cells.get(index);
2364
- const { horizontal: isHorizontal = false, getItemLayout, data: currentData } = latest.current;
2365
- if (element !== void 0) return isHorizontal ? {
2366
- offset: element.offsetLeft,
2367
- length: element.offsetWidth
2368
- } : {
2369
- offset: element.offsetTop,
2370
- length: element.offsetHeight
2371
- };
2372
- const layout = getItemLayout?.(currentData, index);
2373
- return layout === void 0 ? void 0 : {
2374
- offset: layout.offset,
2375
- length: layout.length
2376
- };
2377
- }, [cells]);
2378
- const maybeCallOnEdgeReached = useCallback(() => {
2379
- const element = scroller.current;
2380
- if (element === null) return;
2381
- const { horizontal: isHorizontal = false, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold } = latest.current;
2382
- const visibleLength = isHorizontal ? element.clientWidth : element.clientHeight;
2383
- const contentLength = isHorizontal ? element.scrollWidth : element.scrollHeight;
2384
- if (visibleLength === 0 || contentLength === 0) return;
2385
- const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
2386
- let distanceFromStart = offset;
2387
- let distanceFromEnd = contentLength - visibleLength - offset;
2388
- if (distanceFromStart < ON_EDGE_REACHED_EPSILON) distanceFromStart = 0;
2389
- if (distanceFromEnd < ON_EDGE_REACHED_EPSILON) distanceFromEnd = 0;
2390
- const startThreshold = onStartReachedThreshold != null ? onStartReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
2391
- const endThreshold = onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : DEFAULT_EDGE_THRESHOLD_PX;
2392
- const withinStart = distanceFromStart <= startThreshold;
2393
- const withinEnd = distanceFromEnd <= endThreshold;
2394
- const state = edge.current;
2395
- if (onEndReached != null && withinEnd && contentLength !== state.sentEndForContentLength) {
2396
- state.sentEndForContentLength = contentLength;
2397
- onEndReached({ distanceFromEnd });
2398
- }
2399
- if (onStartReached != null && withinStart && contentLength !== state.sentStartForContentLength) {
2400
- state.sentStartForContentLength = contentLength;
2401
- onStartReached({ distanceFromStart });
2402
- }
2403
- if (!withinStart) state.sentStartForContentLength = 0;
2404
- if (!withinEnd) state.sentEndForContentLength = 0;
2405
- }, []);
2406
- const updateViewability = useCallback(() => {
2407
- const element = scroller.current;
2408
- if (element === null || trackers.length === 0) return;
2409
- const current = latest.current;
2410
- const isHorizontal = current.horizontal === true;
2411
- const columns = current.numColumns ?? 1;
2412
- const extract = current.keyExtractor ?? defaultKeyExtractor;
2413
- const currentItems = isArrayLike(current.data) ? current.data : [];
2414
- const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
2415
- const createToken = (index, isViewable) => {
2416
- if (columns === 1) {
2417
- const item = currentItems[index];
2418
- return {
2419
- item,
2420
- key: extract(item, index),
2421
- index,
2422
- isViewable
2423
- };
2424
- }
2425
- const row = [];
2426
- for (let column = 0; column < columns; column++) {
2427
- const itemIndex = index * columns + column;
2428
- if (itemIndex < currentItems.length) row.push(currentItems[itemIndex]);
2429
- }
2430
- return {
2431
- item: row,
2432
- key: row.map((item, column) => extract(item, index * columns + column)).join(":"),
2433
- index,
2434
- isViewable
2435
- };
2436
- };
2437
- const expand = (tokens) => {
2438
- if (columns === 1) return tokens;
2439
- const out = [];
2440
- for (const token of tokens) token.item.forEach((item, column) => {
2441
- const index = (token.index ?? 0) * columns + column;
2442
- out.push({
2443
- ...token,
2444
- item,
2445
- key: extract(item, index),
2446
- index
2447
- });
2448
- });
2449
- return out;
2450
- };
2451
- const offset = isHorizontal ? element.scrollLeft : element.scrollTop;
2452
- const viewport = isHorizontal ? element.clientWidth : element.clientHeight;
2453
- for (const entry of trackers) {
2454
- const handler = entry.callback(current);
2455
- if (handler == null) continue;
2456
- entry.tracker.onUpdate(count, metricsAt, offset, viewport, createToken, (info) => {
2457
- handler({
2458
- viewableItems: expand(info.viewableItems),
2459
- changed: expand(info.changed)
2460
- });
2461
- });
2462
- }
2463
- }, [metricsAt, trackers]);
2464
- const handleScroll = useCallback((event) => {
2465
- latest.current.onScroll?.(event);
2466
- maybeCallOnEdgeReached();
2467
- updateViewability();
2468
- }, [maybeCallOnEdgeReached, updateViewability]);
2469
- const handleContentSizeChange = useCallback((width, height) => {
2470
- latest.current.onContentSizeChange?.(width, height);
2471
- maybeCallOnEdgeReached();
2472
- updateViewability();
2473
- }, [maybeCallOnEdgeReached, updateViewability]);
2474
- const handleLayout = useCallback((event) => {
2475
- latest.current.onLayout?.(event);
2476
- maybeCallOnEdgeReached();
2477
- updateViewability();
2478
- }, [maybeCallOnEdgeReached, updateViewability]);
2479
- useEffect(() => {
2480
- updateViewability();
2481
- });
2482
- const scrollToOffset = useCallback((offset, animated) => {
2483
- const element = scroller.current;
2484
- if (element === null) return;
2485
- element.scrollTo(latest.current.horizontal === true ? {
2486
- x: offset,
2487
- animated
2488
- } : {
2489
- y: offset,
2490
- animated
2491
- });
2492
- }, []);
2493
- const scrollToIndex = useCallback((params) => {
2494
- const current = latest.current;
2495
- const columns = current.numColumns ?? 1;
2496
- const currentItems = isArrayLike(current.data) ? current.data : [];
2497
- const count = columns > 1 ? Math.ceil(currentItems.length / columns) : currentItems.length;
2498
- const { animated, index, viewOffset, viewPosition } = params;
2499
- if (index < 0) throw new Error(`scrollToIndex out of range: requested index ${index} but minimum is 0`);
2500
- if (count < 1) throw new Error(`scrollToIndex out of range: item length ${count} but minimum is 1`);
2501
- if (index >= count) throw new Error(`scrollToIndex out of range: requested index ${index} is out of 0 to ${count - 1}`);
2502
- const frame = metricsAt(Math.floor(index));
2503
- const element = scroller.current;
2504
- if (frame === void 0 || element === null) {
2505
- const { onScrollToIndexFailed } = current;
2506
- 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.");
2507
- onScrollToIndexFailed({
2508
- index,
2509
- highestMeasuredFrameIndex: -1,
2510
- averageItemLength: 0
2511
- });
2512
- return;
2513
- }
2514
- const visibleLength = current.horizontal === true ? element.clientWidth : element.clientHeight;
2515
- const offset = Math.max(0, frame.offset - (viewPosition ?? 0) * (visibleLength - frame.length)) - (viewOffset ?? 0);
2516
- scrollToOffset(offset, animated);
2517
- }, [metricsAt, scrollToOffset]);
2518
- useImperativeHandle(ref, () => ({
2519
- scrollToOffset: (params) => scrollToOffset(params.offset, params.animated),
2520
- scrollToEnd: (params) => scroller.current?.scrollToEnd({ animated: params?.animated }),
2521
- scrollToIndex,
2522
- scrollToItem: ({ item, ...rest }) => {
2523
- const current = latest.current;
2524
- const columns = current.numColumns ?? 1;
2525
- const currentItems = isArrayLike(current.data) ? current.data : [];
2526
- for (let index = 0; index < currentItems.length; index++) if (currentItems[index] === item) {
2527
- scrollToIndex({
2528
- ...rest,
2529
- index: Math.floor(index / columns)
2530
- });
2531
- return;
2532
- }
2533
- },
2534
- recordInteraction: () => {
2535
- for (const entry of trackers) entry.tracker.recordInteraction();
2536
- updateViewability();
2537
- },
2538
- flashScrollIndicators: () => {},
2539
- getScrollResponder: () => scroller.current,
2540
- getNativeScrollRef: () => scroller.current,
2541
- getScrollableNode: () => scroller.current,
2542
- setNativeProps: () => {}
2543
- }), [
2544
- scrollToIndex,
2545
- scrollToOffset,
2546
- trackers,
2547
- updateViewability
2548
- ]);
2549
- useLayoutEffect(() => {
2550
- const index = latest.current.initialScrollIndex;
2551
- const element = scroller.current;
2552
- if (index == null || element === null) return;
2553
- const frame = metricsAt(index);
2554
- if (frame === void 0) return;
2555
- if (latest.current.horizontal === true) element.scrollLeft = frame.offset;
2556
- else element.scrollTop = frame.offset;
2557
- }, [metricsAt]);
2558
- const inversionStyle = inverted ? horizontal ? horizontallyInvertedStyle : verticallyInvertedStyle : void 0;
2559
- const cellStyle = inversionStyle ? horizontal ? [rowReverseStyle, inversionStyle] : [columnReverseStyle, inversionStyle] : horizontal ? rowStyle : void 0;
2560
- const renderOne = (info) => {
2561
- if (ListItemComponent !== void 0) return /* @__PURE__ */ jsx(ListItemComponent, { ...info });
2562
- if (renderItem != null) return renderItem(info);
2563
- throw new Error("FlatList: Either ListItemComponent or renderItem props are required but none were found.");
2564
- };
2565
- const renderCell = (row, index, separators) => {
2566
- if (numColumns === 1) return renderOne({
2567
- item: row,
2568
- index,
2569
- separators
2570
- });
2571
- return /* @__PURE__ */ jsx(View, {
2572
- style: [rowStyle, columnWrapperStyle],
2573
- children: row.map((item, column) => {
2574
- const element = renderOne({
2575
- item,
2576
- index: index * numColumns + column,
2577
- separators
2578
- });
2579
- return element == null ? null : /* @__PURE__ */ jsx(Fragment, { children: element }, column);
2580
- })
2581
- });
2582
- };
2583
- const children = [];
2584
- if (ListHeaderComponent != null) children.push(/* @__PURE__ */ jsx(View, {
2585
- style: [inversionStyle, ListHeaderComponentStyle],
2586
- children: renderListComponent(ListHeaderComponent)
2587
- }, "$header"));
2588
- if (rowCount === 0) {
2589
- if (ListEmptyComponent != null) children.push(/* @__PURE__ */ jsx(View, {
2590
- style: inversionStyle,
2591
- children: renderListComponent(ListEmptyComponent)
2592
- }, "$empty"));
2593
- } else {
2594
- let prevCellKey;
2595
- for (let index = 0; index < rowCount; index++) {
2596
- const row = rowAt(index);
2597
- const cellKey = rowKey(row, index);
2598
- children.push(/* @__PURE__ */ jsx(Cell, {
2599
- cellKey,
2600
- prevCellKey,
2601
- index,
2602
- item: row,
2603
- style: cellStyle,
2604
- renderCell,
2605
- ItemSeparatorComponent: index < rowCount - 1 ? ItemSeparatorComponent : void 0,
2606
- CellRendererComponent,
2607
- separatorUpdaters,
2608
- onElement
2609
- }, cellKey));
2610
- prevCellKey = cellKey;
2611
- }
2612
- }
2613
- if (ListFooterComponent != null) children.push(/* @__PURE__ */ jsx(View, {
2614
- style: [inversionStyle, ListFooterComponentStyle],
2615
- children: renderListComponent(ListFooterComponent)
2616
- }, "$footer"));
2617
- const scrollProps = {
2618
- ...scrollViewProps,
2619
- horizontal,
2620
- style: [inversionStyle, style],
2621
- onScroll: handleScroll,
2622
- onContentSizeChange: handleContentSizeChange,
2623
- onLayout: handleLayout,
2624
- children
2625
- };
2626
- if (renderScrollComponent !== void 0) return /* @__PURE__ */ jsx(CustomScroller, {
2627
- ...scrollProps,
2628
- ref: scroller,
2629
- render: renderScrollComponent
2630
- });
2631
- return /* @__PURE__ */ jsx(ScrollView, {
2632
- ...scrollProps,
2633
- ref: scroller
2634
- });
2635
- }
2636
- // src/utils/warn.ts
2637
- const warned = /* @__PURE__ */ new Set();
2638
- const warnOnce = (key, message) => {
2639
- if (isProductionEnv() || warned.has(key)) return;
2640
- warned.add(key);
2641
- console.warn(`[@rootnative/web] ${message}`);
2642
- };
2643
- // src/components/Image/source.ts
2644
- const none = Object.freeze({
2645
- src: void 0,
2646
- srcSet: void 0,
2647
- sizes: void 0,
2648
- width: void 0,
2649
- height: void 0,
2650
- request: void 0
2651
- });
2652
- 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.";
2653
- const hasURI = (source) => typeof source.uri === "string" && source.uri.length > 0;
2654
- const requestOf = (source) => {
2655
- if (source.headers === void 0 && source.method === void 0 && source.body === void 0) return;
2656
- return {
2657
- method: source.method ?? "GET",
2658
- headers: source.headers,
2659
- body: source.body
2660
- };
2661
- };
2662
- const single = (source) => ({
2663
- src: source.uri,
2664
- srcSet: void 0,
2665
- sizes: void 0,
2666
- width: source.width,
2667
- height: source.height,
2668
- request: requestOf(source)
2669
- });
2670
- const firstCandidate = (srcSet) => srcSet.split(",")[0]?.trim().split(/\s+/)[0];
2671
- const list = (sources, layoutWidth) => {
2672
- const first = sources[0];
2673
- if (sources.length === 1) return single(first);
2674
- if (sources.every((s) => typeof s.width === "number")) return {
2675
- src: first.uri,
2676
- srcSet: sources.map((s) => `${s.uri} ${s.width}w`).join(", "),
2677
- sizes: layoutWidth === void 0 ? "100vw" : `${layoutWidth}px`,
2678
- width: void 0,
2679
- height: void 0,
2680
- request: void 0
2681
- };
2682
- if (sources.every((s) => typeof s.scale === "number")) {
2683
- const base = sources.find((s) => s.scale === 1) ?? first;
2684
- return {
2685
- src: base.uri,
2686
- srcSet: sources.map((s) => `${s.uri} ${s.scale}x`).join(", "),
2687
- sizes: void 0,
2688
- width: base.width,
2689
- height: base.height,
2690
- request: void 0
2691
- };
2692
- }
2693
- return single(first);
2694
- };
2695
- const resolveSource = (source, src, srcSet, layoutWidth) => {
2696
- if (src !== void 0 || srcSet !== void 0) return {
2697
- ...none,
2698
- src: src ?? (srcSet === void 0 ? void 0 : firstCandidate(srcSet)),
2699
- srcSet,
2700
- sizes: srcSet !== void 0 && /\d+w/.test(srcSet) ? "100vw" : void 0
2701
- };
2702
- if (source === void 0 || source === null) return none;
2703
- if (typeof source === "string") return {
2704
- ...none,
2705
- src: source
2706
- };
2707
- if (typeof source === "number") {
2708
- warnOnce("image-asset-id", ASSET_ID_WARNING);
2709
- return none;
2710
- }
2711
- if (Array.isArray(source)) {
2712
- const sources = source.filter(hasURI);
2713
- return sources.length === 0 ? none : list(sources, layoutWidth);
2714
- }
2715
- return hasURI(source) ? single(source) : none;
2716
- };
2717
- const resolveAssetSource = (source) => {
2718
- if (typeof source === "string") return {
2719
- uri: source,
2720
- scale: 1
2721
- };
2722
- if (typeof source === "number") {
2723
- warnOnce("image-asset-id", ASSET_ID_WARNING);
2724
- return null;
2725
- }
2726
- const first = Array.isArray(source) ? source[0] : source;
2727
- if (first === void 0 || first === null || !hasURI(first)) return null;
2728
- const { uri, width, height, scale } = first;
2729
- return {
2730
- uri,
2731
- width,
2732
- height,
2733
- scale: scale ?? 1
2734
- };
2735
- };
2736
- // src/components/Image/index.tsx
2737
- const boxStyle = Object.freeze({
2738
- backgroundColor: "transparent",
2739
- border: "0 solid black",
2740
- boxSizing: "border-box",
2741
- display: "flex",
2742
- flexBasis: "auto",
2743
- flexDirection: "column",
2744
- flexShrink: 0,
2745
- margin: 0,
2746
- minHeight: 0,
2747
- minWidth: 0,
2748
- overflow: "hidden",
2749
- padding: 0,
2750
- position: "relative",
2751
- zIndex: 0
2752
- });
2753
- const fillStyle = Object.freeze({
2754
- position: "absolute",
2755
- left: 0,
2756
- top: 0,
2757
- width: "100%",
2758
- height: "100%",
2759
- display: "block",
2760
- border: 0,
2761
- margin: 0,
2762
- padding: 0
2763
- });
2764
- const hiddenStyle = Object.freeze({ visibility: "hidden" });
2765
- const objectFitOf = {
2766
- cover: "cover",
2767
- contain: "contain",
2768
- stretch: "fill",
2769
- center: "none",
2770
- repeat: "none"
2771
- };
2772
- const resizeModeOfObjectFit = {
2773
- cover: "cover",
2774
- contain: "contain",
2775
- fill: "stretch",
2776
- "scale-down": "contain",
2777
- none: "center"
2778
- };
2779
- const maskSizeOf = {
2780
- cover: "cover",
2781
- contain: "contain",
2782
- stretch: "100% 100%",
2783
- center: "auto",
2784
- repeat: "auto"
2785
- };
2786
- const cssURL = (url) => `url("${url.replace(/["\\]/g, "\\$&")}")`;
2787
- const loadError = (uri) => `Failed to load image: ${uri ?? ""}`;
2788
- const sizeOf = (img) => ({
2789
- width: img.naturalWidth,
2790
- height: img.naturalHeight
2791
- });
2792
- const placeholderURI = (source) => {
2793
- if (typeof source === "string") return source;
2794
- if (typeof source === "object" && source !== null) return source.uri;
2795
- };
2796
- const useRequestURL = (uri, request) => {
2797
- const [state, setState] = useState({
2798
- uri: void 0,
2799
- url: void 0,
2800
- error: void 0
2801
- });
2802
- const requestKey = request === void 0 ? void 0 : JSON.stringify(request);
2803
- useEffect(() => {
2804
- if (uri === void 0 || requestKey === void 0) return;
2805
- const { method, headers, body } = JSON.parse(requestKey);
2806
- const controller = new AbortController();
2807
- let objectURL;
2808
- const init = {
2809
- method,
2810
- signal: controller.signal
2811
- };
2812
- if (headers !== void 0) init.headers = headers;
2813
- if (body !== void 0) init.body = body;
2814
- fetch(uri, init).then((response) => {
2815
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
2816
- return response.blob();
2817
- }).then((blob) => {
2818
- objectURL = URL.createObjectURL(blob);
2819
- setState({
2820
- uri,
2821
- url: objectURL,
2822
- error: void 0
2823
- });
2824
- }).catch((error) => {
2825
- if (controller.signal.aborted) return;
2826
- const message = error instanceof Error ? error.message : String(error);
2827
- setState({
2828
- uri,
2829
- url: void 0,
2830
- error: `${loadError(uri)} (${message})`
2831
- });
2832
- });
2833
- return () => {
2834
- controller.abort();
2835
- if (objectURL !== void 0) URL.revokeObjectURL(objectURL);
2836
- };
2837
- }, [uri, requestKey]);
2838
- return state.uri === uri ? state : {
2839
- url: void 0,
2840
- error: void 0
2841
- };
2842
- };
2843
- function ImageComponent(props) {
2844
- 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;
2845
- const element = useRef(null);
2846
- const img = useRef(null);
2847
- useImperativeHandle(ref, () => element.current, []);
2848
- useElementLayout(element, onLayout);
2849
- const registry = useStyleRegistry();
2850
- const { resizeMode: styleResizeMode, objectFit, tintColor: styleTintColor, overlayColor: _overlayColor, ...userBoxStyle } = flattenStyle(style) ?? {};
2851
- const resizeMode = (typeof objectFit === "string" ? resizeModeOfObjectFit[objectFit] : void 0) ?? resizeModeProp ?? styleResizeMode ?? "cover";
2852
- const tintColor = tintColorProp ?? styleTintColor;
2853
- const painted = resizeMode === "repeat" || tintColor !== void 0;
2854
- const styleWidth = userBoxStyle["width"] ?? width;
2855
- const resolved = resolveSource(source, src, srcSet, typeof styleWidth === "number" ? styleWidth : void 0);
2856
- const requested = useRequestURL(resolved.src, resolved.request);
2857
- const currentSrc = resolved.request === void 0 ? resolved.src : requested.url;
2858
- const handlers = useRef({
2859
- onLoad,
2860
- onLoadStart,
2861
- onLoadEnd,
2862
- onError
2863
- });
2864
- useEffect(() => {
2865
- handlers.current = {
2866
- onLoad,
2867
- onLoadStart,
2868
- onLoadEnd,
2869
- onError
2870
- };
2871
- });
2872
- const [loadedSrc, setLoadedSrc] = useState(void 0);
2873
- const firedFor = useRef(void 0);
2874
- useEffect(() => {
2875
- if (resolved.src === void 0) return;
2876
- firedFor.current = void 0;
2877
- handlers.current.onLoadStart?.();
2878
- }, [resolved.src]);
2879
- const fireLoad = useCallback((target) => {
2880
- const uri = target.currentSrc || target.src;
2881
- if (firedFor.current === uri) return;
2882
- firedFor.current = uri;
2883
- setLoadedSrc(target.src);
2884
- const { width: naturalWidth, height: naturalHeight } = sizeOf(target);
2885
- handlers.current.onLoad?.({ nativeEvent: { source: {
2886
- uri,
2887
- width: naturalWidth,
2888
- height: naturalHeight
2889
- } } });
2890
- handlers.current.onLoadEnd?.();
2891
- }, []);
2892
- const fireError = useCallback((target) => {
2893
- const uri = target.currentSrc || target.src;
2894
- if (firedFor.current === uri) return;
2895
- firedFor.current = uri;
2896
- handlers.current.onError?.({ nativeEvent: { error: loadError(uri) } });
2897
- handlers.current.onLoadEnd?.();
2898
- }, []);
2899
- const handleLoad = useCallback((event) => fireLoad(event.currentTarget), [fireLoad]);
2900
- const handleError = useCallback((event) => fireError(event.currentTarget), [fireError]);
2901
- useEffect(() => {
2902
- const target = img.current;
2903
- if (target === null || currentSrc === void 0 || !target.complete) return;
2904
- if (target.naturalWidth > 0) fireLoad(target);
2905
- else fireError(target);
2906
- });
2907
- const requestError = requested.error;
2908
- useEffect(() => {
2909
- if (requestError === void 0) return;
2910
- if (firedFor.current === resolved.src) return;
2911
- firedFor.current = resolved.src;
2912
- handlers.current.onError?.({ nativeEvent: { error: requestError } });
2913
- handlers.current.onLoadEnd?.();
2914
- }, [requestError, resolved.src]);
2915
- const { tag, role } = resolveTag(rest, "div", true);
2916
- const sizeStyle = {
2917
- width: userBoxStyle["width"] ?? width ?? resolved.width,
2918
- height: userBoxStyle["height"] ?? height ?? resolved.height
2919
- };
2920
- const boxClassName = compileStyle([
2921
- boxStyle,
2922
- sizeStyle,
2923
- userBoxStyle
2924
- ], registry);
2925
- const label = alt ?? rest.accessibilityLabel ?? rest["aria-label"];
2926
- const domProps = toDOMProps(rest);
2927
- domProps["className"] = boxClassName;
2928
- domProps["ref"] = element;
2929
- if (role !== void 0) domProps["role"] = role;
2930
- else if (painted && label !== void 0 && label !== "") {
2931
- domProps["role"] = "img";
2932
- domProps["aria-label"] = label;
2933
- }
2934
- const imgStyle = {
2935
- objectFit: objectFitOf[resizeMode],
2936
- filter: blurRadius !== void 0 && blurRadius > 0 ? `blur(${blurRadius}px)` : void 0
2937
- };
2938
- const placeholder = placeholderURI(defaultSource);
2939
- const showPlaceholder = placeholder !== void 0 && (currentSrc === void 0 || loadedSrc !== currentSrc);
2940
- let paintStyle;
2941
- if (painted && currentSrc !== void 0) {
2942
- const url = cssURL(currentSrc);
2943
- const repeat = resizeMode === "repeat" ? "repeat" : "no-repeat";
2944
- paintStyle = tintColor === void 0 ? {
2945
- backgroundImage: url,
2946
- backgroundRepeat: repeat,
2947
- backgroundPosition: "center",
2948
- backgroundSize: "auto"
2949
- } : {
2950
- backgroundColor: tintColor,
2951
- WebkitMaskImage: url,
2952
- maskImage: url,
2953
- WebkitMaskRepeat: repeat,
2954
- maskRepeat: repeat,
2955
- WebkitMaskPosition: "center",
2956
- maskPosition: "center",
2957
- WebkitMaskSize: maskSizeOf[resizeMode],
2958
- maskSize: maskSizeOf[resizeMode]
2959
- };
2960
- }
2961
- const children = [/* @__PURE__ */ jsx("img", {
2962
- ref: img,
2963
- src: currentSrc,
2964
- srcSet: resolved.srcSet,
2965
- sizes: resolved.sizes,
2966
- alt: painted ? "" : label ?? "",
2967
- "aria-hidden": painted ? true : void 0,
2968
- draggable: false,
2969
- crossOrigin,
2970
- referrerPolicy,
2971
- loading,
2972
- fetchPriority,
2973
- decoding,
2974
- onLoad: handleLoad,
2975
- onError: handleError,
2976
- className: compileStyle([
2977
- fillStyle,
2978
- imgStyle,
2979
- painted && hiddenStyle
2980
- ], registry)
2981
- }, "img")];
2982
- if (showPlaceholder) children.unshift(/* @__PURE__ */ jsx("img", {
2983
- src: placeholder,
2984
- alt: "",
2985
- "aria-hidden": true,
2986
- draggable: false,
2987
- className: compileStyle([fillStyle, imgStyle], registry)
2988
- }, "placeholder"));
2989
- if (paintStyle !== void 0) children.push(/* @__PURE__ */ jsx("div", {
2990
- "aria-hidden": true,
2991
- className: compileStyle([fillStyle, paintStyle], registry)
2992
- }, "paint"));
2993
- return createElement(tag, domProps, ...children);
2994
- }
2995
- const loadSize = (uri) => new Promise((resolve, reject) => {
2996
- if (!hasDOM()) {
2997
- reject(/* @__PURE__ */ new Error("Image.getSize needs a DOM"));
2998
- return;
2999
- }
3000
- const probe = document.createElement("img");
3001
- probe.addEventListener("load", () => resolve(sizeOf(probe)), { once: true });
3002
- probe.addEventListener("error", () => reject(new Error(loadError(uri))), { once: true });
3003
- probe.src = uri;
3004
- });
3005
- const fetchObjectURL = async (uri, headers) => {
3006
- const response = await fetch(uri, { headers });
3007
- if (!response.ok) throw new Error(`${loadError(uri)} (HTTP ${response.status})`);
3008
- return URL.createObjectURL(await response.blob());
3009
- };
3010
- const withCallbacks = (promise, success, failure) => {
3011
- if (success === void 0) return promise;
3012
- promise.then((size) => success(size.width, size.height), (error) => failure?.(error));
3013
- };
3014
- function getSize(uri, success, failure) {
3015
- return withCallbacks(loadSize(uri), success, failure);
3016
- }
3017
- function getSizeWithHeaders(uri, headers, success, failure) {
3018
- const promise = fetchObjectURL(uri, headers).then((url) => loadSize(url).finally(() => URL.revokeObjectURL(url)));
3019
- return withCallbacks(promise, success, failure);
3020
- }
3021
- const Image = Object.assign(ImageComponent, {
3022
- getSize,
3023
- getSizeWithHeaders,
3024
- prefetch: (url) => loadSize(url).then(() => true),
3025
- queryCache: () => Promise.resolve({}),
3026
- resolveAssetSource
3027
- });
3028
- // src/components/Pressable/index.tsx
3029
- const notCancelableStyle$1 = Object.freeze({ touchAction: "none" });
3030
- const isFocusVisible = (element) => {
3031
- try {
3032
- return element.matches(":focus-visible");
3033
- } catch {
3034
- return true;
3035
- }
3036
- };
3037
- const Pressable = memo(function Pressable(props) {
3038
- 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;
3039
- const [pressed, setPressed] = useState(false);
3040
- const [hovered, setHovered] = useState(false);
3041
- const [focused, setFocused] = useState(false);
3042
- const tracksState = typeof children === "function" || typeof style === "function";
3043
- const handlers = usePressability(useMemo(() => ({
3044
- cancelable,
3045
- disabled,
3046
- hitSlop,
3047
- pressRectOffset: pressRetentionOffset,
3048
- android_disableSound,
3049
- delayHoverIn,
3050
- delayHoverOut,
3051
- delayLongPress,
3052
- delayPressIn: unstable_pressDelay,
3053
- blockNativeResponder,
3054
- onLongPress,
3055
- onPress,
3056
- onPressMove,
3057
- onPressIn: (event) => {
3058
- if (tracksState) setPressed(true);
3059
- onPressIn?.(event);
3060
- },
3061
- onPressOut: (event) => {
3062
- if (tracksState) setPressed(false);
3063
- onPressOut?.(event);
3064
- },
3065
- onHoverIn: (event) => {
3066
- if (tracksState) setHovered(true);
3067
- onHoverIn?.(event);
3068
- },
3069
- onHoverOut: (event) => {
3070
- if (tracksState) setHovered(false);
3071
- onHoverOut?.(event);
3072
- },
3073
- onFocus: (event) => {
3074
- if (tracksState && event.target === event.currentTarget) setFocused(isFocusVisible(event.currentTarget));
3075
- onFocus?.(event);
3076
- },
3077
- onBlur: (event) => {
3078
- if (tracksState && event.target === event.currentTarget) setFocused(false);
3079
- onBlur?.(event);
3080
- }
3081
- }), [
3082
- android_disableSound,
3083
- blockNativeResponder,
3084
- cancelable,
3085
- delayHoverIn,
3086
- delayHoverOut,
3087
- delayLongPress,
3088
- disabled,
3089
- hitSlop,
3090
- onBlur,
3091
- onFocus,
3092
- onHoverIn,
3093
- onHoverOut,
3094
- onLongPress,
3095
- onPress,
3096
- onPressIn,
3097
- onPressMove,
3098
- onPressOut,
3099
- pressRetentionOffset,
3100
- tracksState,
3101
- unstable_pressDelay
3102
- ]));
3103
- const registry = useStyleRegistry();
3104
- const state = {
3105
- pressed: pressed || testOnly_pressed === true,
3106
- hovered,
3107
- focused
3108
- };
3109
- const viewProps = {
3110
- ...rest,
3111
- ...mergeHandlers(rest, handlers),
3112
- focusable: disabled !== true && focusable !== false,
3113
- style: [typeof style === "function" ? style(state) : style, cancelable === false && notCancelableStyle$1],
3114
- children: typeof children === "function" ? children(state) : children
3115
- };
3116
- if (disabled === true) viewProps["aria-disabled"] = true;
3117
- return useViewElement(viewProps, hitSlopClass(registry, hitSlop));
3118
- });
3119
- // src/components/StatusBar/index.tsx
3120
- const stack = [];
3121
- const base = {};
3122
- const merged = () => {
3123
- const out = { ...base };
3124
- for (const entry of stack) for (const key in entry) {
3125
- const value = entry[key];
3126
- if (value !== void 0) out[key] = value;
3127
- }
3128
- return out;
3129
- };
3130
- const themeColorMeta = () => {
3131
- if (!hasDOM()) return null;
3132
- let meta = document.head.querySelector("meta[name=\"theme-color\"]:not([media])");
3133
- if (meta === null) {
3134
- meta = document.createElement("meta");
3135
- meta.name = "theme-color";
3136
- document.head.appendChild(meta);
3137
- }
3138
- return meta;
3139
- };
3140
- let originalThemeColor;
3141
- const apply = () => {
3142
- const meta = themeColorMeta();
3143
- if (meta === null) return;
3144
- if (originalThemeColor === void 0) originalThemeColor = meta.getAttribute("content");
3145
- const color = toCSSColor(merged().backgroundColor);
3146
- if (color !== void 0) meta.setAttribute("content", color);
3147
- else if (originalThemeColor === null) meta.removeAttribute("content");
3148
- else meta.setAttribute("content", originalThemeColor);
3149
- };
3150
- const pushStackEntry = (props) => {
3151
- const entry = { ...props };
3152
- stack.push(entry);
3153
- apply();
3154
- return entry;
3155
- };
3156
- const popStackEntry = (entry) => {
3157
- const index = stack.indexOf(entry);
3158
- if (index !== -1) stack.splice(index, 1);
3159
- apply();
3160
- };
3161
- const replaceStackEntry = (entry, props) => {
3162
- const index = stack.indexOf(entry);
3163
- const next = { ...props };
3164
- if (index === -1) stack.push(next);
3165
- else stack[index] = next;
3166
- apply();
3167
- return next;
3168
- };
3169
- function StatusBarComponent(props) {
3170
- const entry = useRef(null);
3171
- const { animated, backgroundColor, barStyle, hidden, networkActivityIndicatorVisible, showHideTransition, translucent } = props;
3172
- useEffect(() => {
3173
- const next = {
3174
- animated,
3175
- backgroundColor,
3176
- barStyle,
3177
- hidden,
3178
- networkActivityIndicatorVisible,
3179
- showHideTransition,
3180
- translucent
3181
- };
3182
- entry.current = entry.current === null ? pushStackEntry(next) : replaceStackEntry(entry.current, next);
3183
- }, [
3184
- animated,
3185
- backgroundColor,
3186
- barStyle,
3187
- hidden,
3188
- networkActivityIndicatorVisible,
3189
- showHideTransition,
3190
- translucent
3191
- ]);
3192
- useEffect(() => {
3193
- return () => {
3194
- if (entry.current !== null) popStackEntry(entry.current);
3195
- entry.current = null;
3196
- };
3197
- }, []);
3198
- return null;
3199
- }
3200
- const StatusBar = Object.assign(StatusBarComponent, {
3201
- currentHeight: null,
3202
- setBarStyle: (style, _animated) => {
3203
- base.barStyle = style;
3204
- apply();
3205
- },
3206
- setBackgroundColor: (color, _animated) => {
3207
- base.backgroundColor = color;
3208
- apply();
3209
- },
3210
- setHidden: (hidden, _animation) => {
3211
- base.hidden = hidden;
3212
- apply();
3213
- },
3214
- setTranslucent: (translucent) => {
3215
- base.translucent = translucent;
3216
- apply();
3217
- },
3218
- setNetworkActivityIndicatorVisible: (visible) => {
3219
- base.networkActivityIndicatorVisible = visible;
3220
- apply();
3221
- },
3222
- pushStackEntry,
3223
- popStackEntry,
3224
- replaceStackEntry
3225
- });
3226
- // src/components/Switch/index.tsx
3227
- const TRACK_OFF = "#939393";
3228
- const TRACK_ON = "#A3D3CF";
3229
- const THUMB_OFF = "#FAFAFA";
3230
- const THUMB_ON = "#009688";
3231
- const INPUT_CLASS = "rn-switch-input";
3232
- const RULES = [
3233
- `.${INPUT_CLASS}{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:pointer;z-index:1}`,
3234
- `.${INPUT_CLASS}:disabled{cursor:default}`,
3235
- ".rn-switch-track{height:70%;border-radius:9999px;transition:background-color .15s}",
3236
- ".rn-switch-row{position:absolute;inset:0;display:flex;border-radius:9999px}",
3237
- ".rn-switch-spacer{flex-grow:0;transition:flex-grow .15s}",
3238
- ".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}",
3239
- `.${INPUT_CLASS}:checked~.rn-switch-row>.rn-switch-spacer{flex-grow:1}`,
3240
- `.${INPUT_CLASS}:focus-visible~.rn-switch-row{outline:auto;outline-offset:2px}`,
3241
- "@media (prefers-reduced-motion:reduce){.rn-switch-track,.rn-switch-spacer,.rn-switch-thumb{transition:none}}"
3242
- ];
3243
- function Switch(props) {
3244
- 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;
3245
- const inputClass = useStyleRegistry().staticClass(INPUT_CLASS, RULES);
3246
- const on = value === true;
3247
- const resolvedDisabled = disabled ?? accessibilityState?.disabled;
3248
- const state = resolvedDisabled === accessibilityState?.disabled ? accessibilityState : {
3249
- ...accessibilityState,
3250
- disabled: resolvedDisabled
3251
- };
3252
- const handleChange = (event) => {
3253
- const next = event.target.checked;
3254
- Object.assign(event.nativeEvent, { value: next });
3255
- onChange?.(event);
3256
- onValueChange?.(next);
3257
- };
3258
- const inputProps = toDOMProps({
3259
- ...rest,
3260
- accessibilityState: state
3261
- });
3262
- inputProps["role"] = role ?? accessibilityRole ?? "switch";
3263
- const track = toCSSColor(on ? trackColor?.true : trackColor?.false) ?? (on ? TRACK_ON : TRACK_OFF);
3264
- const thumb = toCSSColor(thumbColor) ?? (on ? THUMB_ON : THUMB_OFF);
3265
- return /* @__PURE__ */ jsxs(View, {
3266
- onLayout,
3267
- pointerEvents,
3268
- style: [
3269
- styles.root,
3270
- style,
3271
- resolvedDisabled === true && styles.disabled
3272
- ],
3273
- children: [
3274
- /* @__PURE__ */ jsx("input", {
3275
- ...inputProps,
3276
- checked: on,
3277
- className: inputClass,
3278
- disabled: resolvedDisabled === true,
3279
- onChange: handleChange,
3280
- ref,
3281
- type: "checkbox"
3282
- }),
3283
- /* @__PURE__ */ jsx("div", {
3284
- className: "rn-switch-track",
3285
- style: { backgroundColor: track }
3286
- }),
3287
- /* @__PURE__ */ jsxs("div", {
3288
- className: "rn-switch-row",
3289
- children: [/* @__PURE__ */ jsx("div", { className: "rn-switch-spacer" }), /* @__PURE__ */ jsx("div", {
3290
- className: "rn-switch-thumb",
3291
- style: { backgroundColor: thumb }
3292
- })]
3293
- })
3294
- ]
3295
- });
3296
- }
3297
- const styles = StyleSheet.create({
3298
- root: {
3299
- alignSelf: "flex-start",
3300
- width: 40,
3301
- height: 20,
3302
- justifyContent: "center"
3303
- },
3304
- disabled: { opacity: .5 }
3305
- });
3306
- // src/components/TextInput/autocomplete.ts
3307
- const reactNativeToHTML = {
3308
- "address-line1": "address-line1",
3309
- "address-line2": "address-line2",
3310
- "birthdate-day": "bday-day",
3311
- "birthdate-full": "bday",
3312
- "birthdate-month": "bday-month",
3313
- "birthdate-year": "bday-year",
3314
- "cc-middle-name": "cc-additional-name",
3315
- gender: "sex",
3316
- "name-family": "family-name",
3317
- "name-given": "given-name",
3318
- "name-middle": "additional-name",
3319
- "name-middle-initial": "additional-name",
3320
- "name-prefix": "honorific-prefix",
3321
- "name-suffix": "honorific-suffix",
3322
- "postal-address": "street-address",
3323
- "postal-address-country": "country",
3324
- "postal-address-extended": "address-line2",
3325
- "postal-address-extended-postal-code": "postal-code",
3326
- "postal-address-locality": "address-level2",
3327
- "postal-address-region": "address-level1",
3328
- "sms-otp": "one-time-code",
3329
- "tel-device": "tel",
3330
- "username-new": "username"
3331
- };
3332
- const textContentTypeToHTML = {
3333
- none: "off",
3334
- URL: "url",
3335
- addressCity: "address-level2",
3336
- addressCityAndState: "address-level1",
3337
- addressState: "address-level1",
3338
- birthdate: "bday",
3339
- birthdateDay: "bday-day",
3340
- birthdateMonth: "bday-month",
3341
- birthdateYear: "bday-year",
3342
- countryName: "country-name",
3343
- creditCardExpiration: "cc-exp",
3344
- creditCardExpirationMonth: "cc-exp-month",
3345
- creditCardExpirationYear: "cc-exp-year",
3346
- creditCardFamilyName: "cc-family-name",
3347
- creditCardGivenName: "cc-given-name",
3348
- creditCardMiddleName: "cc-additional-name",
3349
- creditCardName: "cc-name",
3350
- creditCardNumber: "cc-number",
3351
- creditCardSecurityCode: "cc-csc",
3352
- creditCardType: "cc-type",
3353
- emailAddress: "email",
3354
- familyName: "family-name",
3355
- fullStreetAddress: "street-address",
3356
- givenName: "given-name",
3357
- jobTitle: "organization-title",
3358
- location: "street-address",
3359
- middleName: "additional-name",
3360
- name: "name",
3361
- namePrefix: "honorific-prefix",
3362
- nameSuffix: "honorific-suffix",
3363
- newPassword: "new-password",
3364
- nickname: "nickname",
3365
- oneTimeCode: "one-time-code",
3366
- organizationName: "organization",
3367
- password: "current-password",
3368
- postalCode: "postal-code",
3369
- streetAddressLine1: "address-line1",
3370
- streetAddressLine2: "address-line2",
3371
- sublocality: "address-level3",
3372
- telephoneNumber: "tel",
3373
- username: "username"
3374
- };
3375
- const toHTMLAutoComplete = (autoComplete, textContentType) => {
3376
- if (autoComplete !== void 0) return reactNativeToHTML[autoComplete] ?? autoComplete;
3377
- if (textContentType !== void 0) return textContentTypeToHTML[textContentType];
3378
- };
3379
- const keyboardTypeToInputMode = {
3380
- "decimal-pad": "decimal",
3381
- "email-address": "email",
3382
- "number-pad": "numeric",
3383
- numeric: "numeric",
3384
- "numbers-and-punctuation": "decimal",
3385
- "phone-pad": "tel",
3386
- url: "url",
3387
- "web-search": "search"
3388
- };
3389
- const toInputMode = (inputMode, keyboardType, showSoftInputOnFocus) => {
3390
- if (showSoftInputOnFocus === false) return "none";
3391
- if (inputMode !== void 0) return inputMode;
3392
- if (keyboardType !== void 0) return keyboardTypeToInputMode[keyboardType];
3393
- };
3394
- const returnKeyTypeToEnterKeyHint = {
3395
- done: "done",
3396
- go: "go",
3397
- next: "next",
3398
- search: "search",
3399
- send: "send"
3400
- };
3401
- const toEnterKeyHint = (enterKeyHint, returnKeyType) => {
3402
- if (enterKeyHint !== void 0) return enterKeyHint;
3403
- if (returnKeyType !== void 0) return returnKeyTypeToEnterKeyHint[returnKeyType];
3404
- };
3405
- // src/components/TextInput/index.tsx
3406
- const resetStyle = Object.freeze({
3407
- appearance: "none",
3408
- backgroundColor: "transparent",
3409
- border: "0 solid black",
3410
- borderRadius: 0,
3411
- boxSizing: "border-box",
3412
- color: "black",
3413
- display: "block",
3414
- fontFamily: "System",
3415
- fontSize: 14,
3416
- margin: 0,
3417
- minWidth: 0,
3418
- padding: 0,
3419
- position: "relative",
3420
- resize: "none",
3421
- textAlign: "start",
3422
- textDecoration: "none"
3423
- });
3424
- const textareaStyle = Object.freeze({
3425
- fieldSizing: "content",
3426
- overflow: "auto",
3427
- whiteSpace: "pre-wrap",
3428
- wordWrap: "break-word"
3429
- });
3430
- const supportsFieldSizing = hasDOM() && typeof CSS !== "undefined" && CSS.supports("field-sizing", "content");
3431
- const hash = (value) => {
3432
- let h = 5381;
3433
- for (let i = 0; i < value.length; i++) h = h * 33 ^ value.charCodeAt(i);
3434
- return (h >>> 0).toString(36);
3435
- };
3436
- const placeholderClass = (registry, color) => {
3437
- const css = toCSSColor(color);
3438
- if (css === void 0) return void 0;
3439
- const name = `rn-ph-${hash(css)}`;
3440
- return registry.staticClass(name, [`.${name}::placeholder{color:${css};opacity:1}`]);
3441
- };
3442
- const selectionClass = (registry, color) => {
3443
- const css = toCSSColor(color);
3444
- if (css === void 0) return void 0;
3445
- const name = `rn-sel-${hash(css)}`;
3446
- return registry.staticClass(name, [`.${name}::selection{background-color:${css}}`]);
3447
- };
3448
- const submitBehaviorOf = (submitBehavior, blurOnSubmit, multiline) => {
3449
- if (submitBehavior !== void 0) return submitBehavior;
3450
- if (multiline) return blurOnSubmit === true ? "blurAndSubmit" : "newline";
3451
- return blurOnSubmit === false ? "submit" : "blurAndSubmit";
3452
- };
3453
- const selectionOf = (field) => ({
3454
- start: field.selectionStart ?? 0,
3455
- end: field.selectionEnd ?? 0
3456
- });
3457
- const sameSelection = (a, b) => a !== null && a.start === b.start && a.end === b.end;
3458
- const isField = (node) => node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement;
3459
- function TextInputComponent(props) {
3460
- 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;
3461
- const registry = useStyleRegistry();
3462
- const field = useRef(null);
3463
- useElementLayout(field, onLayout);
3464
- const handlers = useRef(props);
3465
- useEffect(() => {
3466
- handlers.current = props;
3467
- });
3468
- const eventCount = useRef(0);
3469
- const lastSelection = useRef(null);
3470
- const lastContentSize = useRef(null);
3471
- const reportContentSize = useCallback((element) => {
3472
- const next = {
3473
- width: element.scrollWidth,
3474
- height: element.scrollHeight
3475
- };
3476
- const last = lastContentSize.current;
3477
- if (last !== null && last.width === next.width && last.height === next.height) return;
3478
- lastContentSize.current = next;
3479
- handlers.current.onContentSizeChange?.({ nativeEvent: { contentSize: next } });
3480
- }, []);
3481
- const grow = useCallback((element) => {
3482
- if (supportsFieldSizing || !(element instanceof HTMLTextAreaElement)) return;
3483
- if (handlers.current.style !== void 0) {
3484
- if (flattenStyle(handlers.current.style)?.["height"] !== void 0) return;
3485
- }
3486
- element.style.height = "auto";
3487
- element.style.height = `${element.scrollHeight}px`;
3488
- }, []);
3489
- const handleChange = useCallback((event) => {
3490
- const element = event.currentTarget;
3491
- const text = element.value;
3492
- eventCount.current += 1;
3493
- Object.assign(event.nativeEvent, {
3494
- text,
3495
- eventCount: eventCount.current
3496
- });
3497
- handlers.current.onChange?.(event);
3498
- handlers.current.onChangeText?.(text);
3499
- grow(element);
3500
- if (handlers.current.onContentSizeChange !== void 0) reportContentSize(element);
3501
- }, [grow, reportContentSize]);
3502
- const handleFocus = useCallback((event) => {
3503
- const element = event.currentTarget;
3504
- const current = handlers.current;
3505
- if (current.clearTextOnFocus === true && element.value !== "") {
3506
- element.value = "";
3507
- eventCount.current += 1;
3508
- current.onChangeText?.("");
3509
- }
3510
- if (current.selectTextOnFocus === true) element.select();
3511
- Object.assign(event.nativeEvent, {
3512
- text: element.value,
3513
- eventCount: eventCount.current
3514
- });
3515
- current.onFocus?.(event);
3516
- }, []);
3517
- const handleBlur = useCallback((event) => {
3518
- const element = event.currentTarget;
3519
- Object.assign(event.nativeEvent, {
3520
- text: element.value,
3521
- eventCount: eventCount.current
3522
- });
3523
- handlers.current.onBlur?.(event);
3524
- handlers.current.onEndEditing?.(event);
3525
- }, []);
3526
- const handleKeyDown = useCallback((event) => {
3527
- const current = handlers.current;
3528
- current.onKeyDown?.(event);
3529
- current.onKeyPress?.(event);
3530
- if (event.defaultPrevented || event.key !== "Enter" || event.shiftKey) return;
3531
- const isMultiline = current.multiline === true;
3532
- const behavior = submitBehaviorOf(current.submitBehavior, current.blurOnSubmit, isMultiline);
3533
- if (behavior === "newline") return;
3534
- if (isMultiline) event.preventDefault();
3535
- const element = event.currentTarget;
3536
- Object.assign(event.nativeEvent, { text: element.value });
3537
- current.onSubmitEditing?.(event);
3538
- if (behavior === "blurAndSubmit") element.blur();
3539
- }, []);
3540
- const handleSelect = useCallback((event) => {
3541
- const next = selectionOf(event.currentTarget);
3542
- if (sameSelection(lastSelection.current, next)) return;
3543
- lastSelection.current = next;
3544
- Object.assign(event.nativeEvent, { selection: next });
3545
- handlers.current.onSelectionChange?.(event);
3546
- }, []);
3547
- const handleScroll = useCallback((event) => {
3548
- const element = event.currentTarget;
3549
- Object.assign(event.nativeEvent, {
3550
- contentInset: {
3551
- top: 0,
3552
- left: 0,
3553
- bottom: 0,
3554
- right: 0
3555
- },
3556
- contentOffset: {
3557
- x: element.scrollLeft,
3558
- y: element.scrollTop
3559
- },
3560
- contentSize: {
3561
- width: element.scrollWidth,
3562
- height: element.scrollHeight
3563
- },
3564
- layoutMeasurement: {
3565
- width: element.clientWidth,
3566
- height: element.clientHeight
3567
- },
3568
- zoomScale: 1
3569
- });
3570
- handlers.current.onScroll?.(event);
3571
- }, []);
3572
- const handleContextMenu = useCallback((event) => {
3573
- handlers.current.onContextMenu?.(event);
3574
- if (handlers.current.contextMenuHidden === true) event.preventDefault();
3575
- }, []);
3576
- const selectionStart = selection?.start;
3577
- const selectionEnd = selection?.end ?? selection?.start;
3578
- useLayoutEffect(() => {
3579
- const element = field.current;
3580
- if (element === null || selectionStart === void 0 || selectionEnd === void 0) return;
3581
- if (element.selectionStart === selectionStart && element.selectionEnd === selectionEnd) return;
3582
- element.setSelectionRange(selectionStart, selectionEnd);
3583
- lastSelection.current = {
3584
- start: selectionStart,
3585
- end: selectionEnd
3586
- };
3587
- }, [
3588
- selectionStart,
3589
- selectionEnd,
3590
- value
3591
- ]);
3592
- useLayoutEffect(() => {
3593
- const element = field.current;
3594
- if (element === null) return;
3595
- grow(element);
3596
- }, [
3597
- grow,
3598
- value,
3599
- multiline
3600
- ]);
3601
- const wantsContentSize = onContentSizeChange !== void 0;
3602
- useEffect(() => {
3603
- const element = field.current;
3604
- if (element === null || !wantsContentSize) return;
3605
- reportContentSize(element);
3606
- const observer = new ResizeObserver(() => reportContentSize(element));
3607
- observer.observe(element);
3608
- return () => observer.disconnect();
3609
- }, [wantsContentSize, reportContentSize]);
3610
- useImperativeHandle(ref, () => {
3611
- const element = field.current;
3612
- return Object.assign(element, {
3613
- clear: () => {
3614
- element.value = "";
3615
- grow(element);
3616
- handlers.current.onChangeText?.("");
3617
- },
3618
- isFocused: () => document.activeElement === element,
3619
- getNativeRef: () => element,
3620
- setNativeProps: (nativeProps) => {
3621
- if (nativeProps.text !== void 0) {
3622
- element.value = nativeProps.text;
3623
- grow(element);
3624
- }
3625
- }
3626
- });
3627
- }, [grow]);
3628
- const flat = flattenStyle(style);
3629
- const colorStyle = {};
3630
- const caret = cursorColor ?? selectionColor;
3631
- if (caretHidden === true) colorStyle["caretColor"] = "transparent";
3632
- else if (caret !== void 0) colorStyle["caretColor"] = caret;
3633
- if (textAlign !== void 0) colorStyle["textAlign"] = textAlign;
3634
- let className = compileStyle([
3635
- resetStyle,
3636
- multiline && textareaStyle,
3637
- flat,
3638
- colorStyle
3639
- ], registry);
3640
- const placeholderName = placeholderClass(registry, placeholderTextColor);
3641
- if (placeholderName !== void 0) className = `${className} ${placeholderName}`;
3642
- const selectionName = selectionClass(registry, selectionColor);
3643
- if (selectionName !== void 0) className = `${className} ${selectionName}`;
3644
- const domProps = toDOMProps(rest);
3645
- domProps["className"] = className;
3646
- domProps["value"] = value;
3647
- domProps["defaultValue"] = defaultValue;
3648
- domProps["placeholder"] = placeholder;
3649
- domProps["readOnly"] = readOnly === true || !editable ? true : void 0;
3650
- domProps["maxLength"] = maxLength;
3651
- domProps["autoFocus"] = autoFocus;
3652
- domProps["autoCapitalize"] = autoCapitalize;
3653
- domProps["autoCorrect"] = autoCorrect === void 0 ? void 0 : autoCorrect ? "on" : "off";
3654
- domProps["spellCheck"] = spellCheck;
3655
- domProps["autoComplete"] = toHTMLAutoComplete(autoComplete, textContentType);
3656
- domProps["inputMode"] = toInputMode(inputMode, keyboardType, showSoftInputOnFocus);
3657
- domProps["enterKeyHint"] = toEnterKeyHint(enterKeyHint, returnKeyType);
3658
- domProps["dir"] ??= "auto";
3659
- domProps["onChange"] = handleChange;
3660
- domProps["onFocus"] = handleFocus;
3661
- domProps["onBlur"] = handleBlur;
3662
- domProps["onKeyDown"] = handleKeyDown;
3663
- domProps["onSelect"] = handleSelect;
3664
- domProps["onContextMenu"] = handleContextMenu;
3665
- if (multiline) {
3666
- domProps["rows"] = numberOfLines ?? 1;
3667
- domProps["onScroll"] = handleScroll;
3668
- return /* @__PURE__ */ jsx("textarea", {
3669
- ...domProps,
3670
- ref: field
3671
- });
3672
- }
3673
- domProps["type"] = secureTextEntry === true ? "password" : "text";
3674
- return /* @__PURE__ */ jsx("input", {
3675
- ...domProps,
3676
- ref: field
3677
- });
3678
- }
3679
- const TextInput = Object.assign(TextInputComponent, { State: {
3680
- currentlyFocusedInput: () => {
3681
- if (!hasDOM()) return null;
3682
- const active = document.activeElement;
3683
- return isField(active) ? active : null;
3684
- },
3685
- focusTextInput: (input) => input?.focus(),
3686
- blurTextInput: (input) => input?.blur()
3687
- } });
3688
- // src/components/TouchableHighlight/index.tsx
3689
- const DEFAULT_ACTIVE_OPACITY = .85;
3690
- const DEFAULT_UNDERLAY_COLOR = "black";
3691
- const notCancelableStyle = Object.freeze({ touchAction: "none" });
3692
- function TouchableHighlight(props) {
3693
- 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;
3694
- const [underlay, setUnderlay] = useState(false);
3695
- const hideTimer = useRef(null);
3696
- const resolvedDisabled = disabled ?? props.accessibilityState?.disabled;
3697
- const hasPressHandler = onPress != null || onPressIn != null || onPressOut != null || onLongPress != null;
3698
- const handlers = usePressability(useMemo(() => {
3699
- const clearHideTimer = () => {
3700
- if (hideTimer.current !== null) clearTimeout(hideTimer.current);
3701
- hideTimer.current = null;
3702
- };
3703
- const show = () => {
3704
- if (!hasPressHandler) return;
3705
- setUnderlay(true);
3706
- onShowUnderlay?.();
3707
- };
3708
- const hide = () => {
3709
- clearHideTimer();
3710
- if (testOnly_pressed === true || !hasPressHandler) return;
3711
- setUnderlay(false);
3712
- onHideUnderlay?.();
3713
- };
3714
- return {
3715
- cancelable: rejectResponderTermination !== true,
3716
- disabled: resolvedDisabled,
3717
- hitSlop,
3718
- delayLongPress,
3719
- delayPressIn,
3720
- delayPressOut,
3721
- minPressDuration: 0,
3722
- pressRectOffset: pressRetentionOffset,
3723
- android_disableSound: touchSoundDisabled,
3724
- onBlur,
3725
- onFocus,
3726
- onLongPress,
3727
- onPress: (event) => {
3728
- clearHideTimer();
3729
- show();
3730
- hideTimer.current = setTimeout(hide, delayPressOut ?? 0);
3731
- onPress?.(event);
3732
- },
3733
- onPressIn: (event) => {
3734
- clearHideTimer();
3735
- show();
3736
- onPressIn?.(event);
3737
- },
3738
- onPressOut: (event) => {
3739
- if (hideTimer.current === null) hide();
3740
- onPressOut?.(event);
3741
- }
3742
- };
3743
- }, [
3744
- delayLongPress,
3745
- delayPressIn,
3746
- delayPressOut,
3747
- hasPressHandler,
3748
- hitSlop,
3749
- onBlur,
3750
- onFocus,
3751
- onHideUnderlay,
3752
- onLongPress,
3753
- onPress,
3754
- onPressIn,
3755
- onPressOut,
3756
- onShowUnderlay,
3757
- pressRetentionOffset,
3758
- rejectResponderTermination,
3759
- resolvedDisabled,
3760
- testOnly_pressed,
3761
- touchSoundDisabled
3762
- ]));
3763
- const registry = useStyleRegistry();
3764
- useEffect(() => () => {
3765
- if (hideTimer.current !== null) clearTimeout(hideTimer.current);
3766
- }, []);
3767
- const pressed = underlay || testOnly_pressed === true;
3768
- const child = Children.only(children);
3769
- if (child.type === Fragment) warnOnce("TouchableHighlight-fragment", "TouchableHighlight does not support a Fragment as its child. Wrap the children in one View.");
3770
- const content = child.type === Fragment ? child : cloneElement(child, { style: [child.props.style, pressed && { opacity: activeOpacity ?? DEFAULT_ACTIVE_OPACITY }] });
3771
- return useViewElement({
3772
- ...rest,
3773
- ...mergeHandlers(rest, handlers),
3774
- focusable: focusable !== false && onPress !== void 0 && disabled !== true,
3775
- style: [
3776
- style,
3777
- pressed && { backgroundColor: underlayColor ?? DEFAULT_UNDERLAY_COLOR },
3778
- rejectResponderTermination === true && notCancelableStyle
3779
- ],
3780
- children: content,
3781
- ...resolvedDisabled === true && { "aria-disabled": true }
3782
- }, hitSlopClass(registry, hitSlop));
3783
- }
3784
- // src/components/TouchableWithoutFeedback/index.tsx
3785
- const isTrue = (value) => value === void 0 ? void 0 : value === true || value === "true";
3786
- function TouchableWithoutFeedback(props) {
3787
- const { children, delayLongPress, delayPressIn, delayPressOut, disabled, focusable, hitSlop, onBlur, onFocus, onLongPress, onPress, onPressIn, onPressOut, pressRetentionOffset, rejectResponderTermination, style: _style, touchSoundDisabled, ...rest } = props;
3788
- const resolvedDisabled = disabled ?? isTrue(props["aria-disabled"]) ?? props.accessibilityState?.disabled;
3789
- const handlers = usePressability(useMemo(() => ({
3790
- cancelable: rejectResponderTermination !== true,
3791
- disabled: resolvedDisabled,
3792
- hitSlop,
3793
- delayLongPress,
3794
- delayPressIn,
3795
- delayPressOut,
3796
- minPressDuration: 0,
3797
- pressRectOffset: pressRetentionOffset,
3798
- android_disableSound: touchSoundDisabled,
3799
- onBlur,
3800
- onFocus,
3801
- onLongPress,
3802
- onPress,
3803
- onPressIn,
3804
- onPressOut
3805
- }), [
3806
- delayLongPress,
3807
- delayPressIn,
3808
- delayPressOut,
3809
- hitSlop,
3810
- onBlur,
3811
- onFocus,
3812
- onLongPress,
3813
- onPress,
3814
- onPressIn,
3815
- onPressOut,
3816
- pressRetentionOffset,
3817
- rejectResponderTermination,
3818
- resolvedDisabled,
3819
- touchSoundDisabled
3820
- ]));
3821
- const element = Children.only(children);
3822
- const passed = {};
3823
- for (const [name, value] of Object.entries(rest)) if (value !== void 0) passed[name] = value;
3824
- if (hitSlop !== void 0) passed["hitSlop"] = hitSlop;
3825
- if (disabled != null) passed["accessibilityState"] = {
3826
- ...rest.accessibilityState,
3827
- disabled
3828
- };
3829
- const merged = mergeHandlers(element.props, handlers);
3830
- const childFocus = onFocus === void 0 ? element.props.onFocus : void 0;
3831
- const childBlur = onBlur === void 0 ? element.props.onBlur : void 0;
3832
- return cloneElement(element, {
3833
- ...passed,
3834
- ...merged,
3835
- onFocus: childFocus === void 0 ? merged.onFocus : (event) => {
3836
- merged.onFocus(event);
3837
- childFocus(event);
3838
- },
3839
- onBlur: childBlur === void 0 ? merged.onBlur : (event) => {
3840
- merged.onBlur(event);
3841
- childBlur(event);
3842
- },
3843
- accessible: rest.accessible !== false,
3844
- focusable: focusable !== false && onPress !== void 0 && disabled !== true
3845
- });
3846
- }
3847
- // src/components/TouchableNativeFeedback/index.tsx
3848
- const TouchableNativeFeedback = Object.assign(function TouchableNativeFeedback(props) {
3849
- const { background: _background, hasTVPreferredFocus: _hasTVPreferredFocus, nextFocusDown: _nextFocusDown, nextFocusForward: _nextFocusForward, nextFocusLeft: _nextFocusLeft, nextFocusRight: _nextFocusRight, nextFocusUp: _nextFocusUp, useForeground: _useForeground, ...rest } = props;
3850
- return createElement(TouchableWithoutFeedback, rest);
3851
- }, {
3852
- SelectableBackground: (rippleRadius) => ({
3853
- type: "ThemeAttrAndroid",
3854
- attribute: "selectableItemBackground",
3855
- rippleRadius
3856
- }),
3857
- SelectableBackgroundBorderless: (rippleRadius) => ({
3858
- type: "ThemeAttrAndroid",
3859
- attribute: "selectableItemBackgroundBorderless",
3860
- rippleRadius
3861
- }),
3862
- Ripple: (color, borderless, rippleRadius) => ({
3863
- type: "RippleAndroid",
3864
- color: processColor(color),
3865
- borderless,
3866
- rippleRadius
3867
- }),
3868
- canUseNativeForeground: () => false
3869
- });
3870
- export { AccessibilityInfo, ActivityIndicator, Appearance, BackHandler, Button, Dimensions, FlatList, I18nManager, Image, PanResponder, PixelRatio, Platform, Pressable, ScrollView, StatusBar, StyleSheet, Switch, Text, TextAncestorContext, TextInput, TouchableHighlight, TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, View, processColor, useColorScheme, usePressability, useWindowDimensions };
3871
-
3872
- //# sourceMappingURL=index.js.map
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";
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 };