@a16n/web-sim 0.0.0-stage → 0.1.1

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 (281) hide show
  1. package/README.md +13 -2
  2. package/bin/cli.ts +255 -0
  3. package/bin/web-sim.js +39 -0
  4. package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
  5. package/overrides/@react-native-firebase/app/overrides.ts +34 -0
  6. package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
  7. package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
  8. package/overrides/expo-application/ExpoApplication.ts +81 -0
  9. package/overrides/expo-application/overrides.ts +16 -0
  10. package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
  11. package/overrides/expo-background-task/overrides.ts +9 -0
  12. package/overrides/expo-constants/ExponentConstants.ts +66 -0
  13. package/overrides/expo-constants/overrides.ts +9 -0
  14. package/overrides/expo-device/ExpoDevice.ts +104 -0
  15. package/overrides/expo-device/overrides.ts +9 -0
  16. package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
  17. package/overrides/expo-glass-effect/GlassView.tsx +95 -0
  18. package/overrides/expo-glass-effect/availability.ts +14 -0
  19. package/overrides/expo-glass-effect/overrides.ts +14 -0
  20. package/overrides/expo-haptics/Haptics.ts +67 -0
  21. package/overrides/expo-haptics/overrides.ts +5 -0
  22. package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
  23. package/overrides/expo-mail-composer/overrides.ts +9 -0
  24. package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
  25. package/overrides/expo-mesh-gradient/overrides.ts +9 -0
  26. package/overrides/expo-modules-core/overrides.ts +12 -0
  27. package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
  28. package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
  29. package/overrides/expo-navigation-bar/overrides.ts +12 -0
  30. package/overrides/expo-router/NativeStackView.tsx +74 -0
  31. package/overrides/expo-router/NativeTabsView.tsx +263 -0
  32. package/overrides/expo-router/SafeAreaProvider.ts +6 -0
  33. package/overrides/expo-router/overrides.ts +23 -0
  34. package/overrides/expo-router/statusBarRequests.ts +51 -0
  35. package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
  36. package/overrides/expo-screen-orientation/overrides.ts +21 -0
  37. package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
  38. package/overrides/expo-sharing/overrides.ts +9 -0
  39. package/overrides/expo-sms/ExpoSMS.ts +24 -0
  40. package/overrides/expo-sms/overrides.ts +9 -0
  41. package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
  42. package/overrides/expo-splash-screen/overrides.ts +5 -0
  43. package/overrides/expo-status-bar/StatusBar.tsx +44 -0
  44. package/overrides/expo-status-bar/overrides.ts +5 -0
  45. package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
  46. package/overrides/expo-store-review/overrides.ts +9 -0
  47. package/overrides/expo-symbols/SymbolView.tsx +192 -0
  48. package/overrides/expo-symbols/overrides.ts +9 -0
  49. package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
  50. package/overrides/expo-system-ui/overrides.ts +9 -0
  51. package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
  52. package/overrides/expo-task-manager/overrides.ts +9 -0
  53. package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
  54. package/overrides/expo-tracking-transparency/overrides.ts +11 -0
  55. package/overrides/expo-video/ExpoVideo.ts +16 -0
  56. package/overrides/expo-video/overrides.ts +9 -0
  57. package/overrides/lottie-react-native/LottieView.tsx +87 -0
  58. package/overrides/lottie-react-native/overrides.ts +9 -0
  59. package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
  60. package/overrides/react-native-pager-view/overrides.ts +9 -0
  61. package/overrides/react-native-reanimated/overrides.ts +28 -0
  62. package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
  63. package/overrides/react-native-safe-area-context/overrides.ts +12 -0
  64. package/overrides/react-native-share/NativeRNShare.ts +22 -0
  65. package/overrides/react-native-share/overrides.ts +12 -0
  66. package/overrides/react-native-share/platform.ts +14 -0
  67. package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
  68. package/overrides/react-native-turbo-image/overrides.ts +9 -0
  69. package/overrides/react-native-web/RefreshControl.tsx +57 -0
  70. package/overrides/react-native-web/overrides.ts +157 -0
  71. package/overrides/react-native-web/useElementLayout.ts +152 -0
  72. package/package.json +80 -4
  73. package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
  74. package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
  75. package/plugins/battery/plugin.ts +8 -0
  76. package/plugins/battery/shell.tsx +56 -0
  77. package/plugins/battery/state.ts +11 -0
  78. package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
  79. package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
  80. package/plugins/biometrics/plugin.ts +8 -0
  81. package/plugins/biometrics/shell.tsx +88 -0
  82. package/plugins/biometrics/state.ts +41 -0
  83. package/plugins/brightness/app.ts +5 -0
  84. package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
  85. package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
  86. package/plugins/brightness/plugin.ts +9 -0
  87. package/plugins/brightness/shell.tsx +55 -0
  88. package/plugins/brightness/state.ts +19 -0
  89. package/plugins/calendar/calendar.ts +299 -0
  90. package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
  91. package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
  92. package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
  93. package/plugins/calendar/plugin.ts +8 -0
  94. package/plugins/calendar/shell.tsx +123 -0
  95. package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
  96. package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
  97. package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
  98. package/plugins/camera/plugin.ts +9 -0
  99. package/plugins/camera/shell.tsx +107 -0
  100. package/plugins/camera/state.ts +61 -0
  101. package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
  102. package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
  103. package/plugins/clipboard/plugin.ts +8 -0
  104. package/plugins/clipboard/shell.tsx +122 -0
  105. package/plugins/clipboard/state.ts +93 -0
  106. package/plugins/clock/app.ts +25 -0
  107. package/plugins/clock/plugin.ts +8 -0
  108. package/plugins/clock/shell.tsx +225 -0
  109. package/plugins/clock/state.ts +12 -0
  110. package/plugins/contacts/contacts.ts +125 -0
  111. package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
  112. package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
  113. package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
  114. package/plugins/contacts/plugin.ts +8 -0
  115. package/plugins/contacts/shell.tsx +109 -0
  116. package/plugins/home-indicator/app.ts +5 -0
  117. package/plugins/home-indicator/plugin.ts +9 -0
  118. package/plugins/home-indicator/requests.ts +48 -0
  119. package/plugins/home-indicator/shell.tsx +68 -0
  120. package/plugins/home-indicator/state.ts +31 -0
  121. package/plugins/keep-awake/app.ts +5 -0
  122. package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
  123. package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
  124. package/plugins/keep-awake/plugin.ts +9 -0
  125. package/plugins/keep-awake/shell.tsx +80 -0
  126. package/plugins/keep-awake/state.ts +12 -0
  127. package/plugins/keyboard/Keyboard.tsx +354 -0
  128. package/plugins/keyboard/app.ts +90 -0
  129. package/plugins/keyboard/controller.ts +384 -0
  130. package/plugins/keyboard/fields.ts +244 -0
  131. package/plugins/keyboard/icons.tsx +283 -0
  132. package/plugins/keyboard/keyboard.css +362 -0
  133. package/plugins/keyboard/layouts/android.ts +175 -0
  134. package/plugins/keyboard/layouts/index.ts +10 -0
  135. package/plugins/keyboard/layouts/ios.ts +219 -0
  136. package/plugins/keyboard/layouts/types.ts +80 -0
  137. package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
  138. package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
  139. package/plugins/keyboard/plugin.ts +13 -0
  140. package/plugins/keyboard/shell.tsx +133 -0
  141. package/plugins/keyboard/state.ts +92 -0
  142. package/plugins/keyboard/suggestions.ts +63 -0
  143. package/plugins/keyboard/taps.ts +77 -0
  144. package/plugins/keyboard/typing.ts +112 -0
  145. package/plugins/locale/app.ts +232 -0
  146. package/plugins/locale/locale.ts +143 -0
  147. package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
  148. package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
  149. package/plugins/locale/plugin.ts +9 -0
  150. package/plugins/locale/shell.tsx +147 -0
  151. package/plugins/locale/state.ts +36 -0
  152. package/plugins/location/geo.ts +56 -0
  153. package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
  154. package/plugins/location/overrides/expo-location/overrides.ts +11 -0
  155. package/plugins/location/places.ts +38 -0
  156. package/plugins/location/plugin.ts +8 -0
  157. package/plugins/location/shell.tsx +188 -0
  158. package/plugins/location/state.ts +51 -0
  159. package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
  160. package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
  161. package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
  162. package/plugins/motion/plugin.ts +8 -0
  163. package/plugins/motion/sensors.ts +116 -0
  164. package/plugins/motion/shell.tsx +136 -0
  165. package/plugins/motion/state.ts +46 -0
  166. package/plugins/network/app.ts +400 -0
  167. package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
  168. package/plugins/network/overrides/expo-network/overrides.ts +9 -0
  169. package/plugins/network/plugin.ts +8 -0
  170. package/plugins/network/shell.tsx +67 -0
  171. package/plugins/network/state.ts +29 -0
  172. package/plugins/notifications/center.ts +255 -0
  173. package/plugins/notifications/content.ts +36 -0
  174. package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
  175. package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
  176. package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
  177. package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
  178. package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
  179. package/plugins/notifications/plugin.ts +8 -0
  180. package/plugins/notifications/shell.tsx +192 -0
  181. package/plugins/notifications/state.ts +56 -0
  182. package/plugins/notifications/tokens.ts +47 -0
  183. package/plugins/notifications/trigger.ts +107 -0
  184. package/plugins/permissions/plugin.ts +6 -0
  185. package/plugins/permissions/shell.tsx +50 -0
  186. package/plugins/permissions/state.ts +38 -0
  187. package/plugins/photos/appLibrary.ts +114 -0
  188. package/plugins/photos/library.ts +322 -0
  189. package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
  190. package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
  191. package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
  192. package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
  193. package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
  194. package/plugins/photos/plugin.ts +8 -0
  195. package/plugins/photos/samples.ts +367 -0
  196. package/plugins/photos/shell.tsx +164 -0
  197. package/plugins/photos/state.ts +88 -0
  198. package/plugins/storage/files.ts +351 -0
  199. package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
  200. package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
  201. package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
  202. package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
  203. package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
  204. package/plugins/storage/plugin.ts +8 -0
  205. package/plugins/storage/reset.ts +136 -0
  206. package/plugins/storage/secure.ts +71 -0
  207. package/plugins/storage/shell.tsx +365 -0
  208. package/plugins/storage/state.ts +13 -0
  209. package/src/client/app/appDocument.ts +129 -0
  210. package/src/client/app/appFocus.ts +97 -0
  211. package/src/client/app/console.ts +118 -0
  212. package/src/client/app/fonts.ts +76 -0
  213. package/src/client/app/main.tsx +99 -0
  214. package/src/client/app/routeContext.ts +45 -0
  215. package/src/client/app/touch.ts +640 -0
  216. package/src/client/entry.ts +20 -0
  217. package/src/client/modules.d.ts +8 -0
  218. package/src/client/react-native/app.ts +57 -0
  219. package/src/client/react-native/deep.ts +13 -0
  220. package/src/client/react-native/keyboard.tsx +192 -0
  221. package/src/client/react-native/library.ts +256 -0
  222. package/src/client/shell/Cookies.tsx +95 -0
  223. package/src/client/shell/LogDrawer.tsx +415 -0
  224. package/src/client/shell/PhotoPicker.tsx +174 -0
  225. package/src/client/shell/PluginOverlays.tsx +42 -0
  226. package/src/client/shell/PluginPanels.tsx +82 -0
  227. package/src/client/shell/ResetApp.tsx +87 -0
  228. package/src/client/shell/Resizer.tsx +99 -0
  229. package/src/client/shell/Shell.tsx +531 -0
  230. package/src/client/shell/SystemBars.tsx +376 -0
  231. package/src/client/shell/SystemCamera.tsx +181 -0
  232. package/src/client/shell/SystemOverlay.tsx +422 -0
  233. package/src/client/shell/SystemSheets.tsx +462 -0
  234. package/src/client/shell/backdrop.ts +229 -0
  235. package/src/client/shell/control.ts +91 -0
  236. package/src/client/shell/events.ts +226 -0
  237. package/src/client/shell/geometry.ts +68 -0
  238. package/src/client/shell/host.ts +492 -0
  239. package/src/client/shell/icons.tsx +34 -0
  240. package/src/client/shell/logFeed.ts +102 -0
  241. package/src/client/shell/main.tsx +22 -0
  242. package/src/client/shell/permissionCopy.ts +169 -0
  243. package/src/client/shell/plugins.ts +266 -0
  244. package/src/client/shell/popout.ts +185 -0
  245. package/src/client/shell/popover.ts +27 -0
  246. package/src/client/shell/shell.css +878 -0
  247. package/src/client/shell/statusTime.ts +31 -0
  248. package/src/client/shell/tooltips.ts +104 -0
  249. package/src/client/virtual.d.ts +23 -0
  250. package/src/devices/catalog.ts +223 -0
  251. package/src/devices/types.ts +83 -0
  252. package/src/node/appInfo.ts +188 -0
  253. package/src/node/appSource.ts +140 -0
  254. package/src/node/config.ts +180 -0
  255. package/src/node/control.ts +144 -0
  256. package/src/node/doctor.ts +199 -0
  257. package/src/node/events/cli.ts +206 -0
  258. package/src/node/events/shared.ts +238 -0
  259. package/src/node/events/store.ts +266 -0
  260. package/src/node/fonts.ts +377 -0
  261. package/src/node/index.ts +5 -0
  262. package/src/node/overrides/define.ts +56 -0
  263. package/src/node/overrides/packages.ts +136 -0
  264. package/src/node/overrides/platformPatch.ts +56 -0
  265. package/src/node/overrides/plugin.ts +169 -0
  266. package/src/node/overrides/registry.ts +258 -0
  267. package/src/node/paths.ts +18 -0
  268. package/src/node/platform.ts +171 -0
  269. package/src/node/plugins.ts +98 -0
  270. package/src/node/proxy.ts +421 -0
  271. package/src/node/server.ts +254 -0
  272. package/src/node/worklets.ts +86 -0
  273. package/src/plugin/index.ts +33 -0
  274. package/src/plugin/types.ts +127 -0
  275. package/src/plugin/ui.tsx +562 -0
  276. package/src/runtime/clock.ts +112 -0
  277. package/src/runtime/draw.ts +196 -0
  278. package/src/runtime/index.ts +519 -0
  279. package/src/runtime/media.ts +379 -0
  280. package/src/runtime/records.ts +76 -0
  281. package/src/runtime/timezone.ts +81 -0
@@ -0,0 +1,196 @@
1
+ import { NativeModule, registerWebModule } from 'expo'
2
+ import { getState } from 'web-sim/runtime'
3
+ // Compiled in the package's `build/legacy` folder, where this is the new API's module, also replaced by web-sim:
4
+ // both APIs see the same files.
5
+ // @ts-ignore
6
+ import ExpoFileSystem from '../ExpoFileSystem'
7
+
8
+ /** The new API's file store (`__webSim` in `ExpoFileSystem.ts`). */
9
+ const fs = () => (ExpoFileSystem as { __webSim: any }).__webSim
10
+
11
+ type Encoding = 'utf8' | 'base64'
12
+
13
+ function seconds(ms: number | undefined): number {
14
+ return (ms ?? 0) / 1000
15
+ }
16
+
17
+ /**
18
+ * The legacy API (`expo-file-system/legacy`) over the same files as `File` and `Directory`. Every call is async, so
19
+ * each waits for the stored files to load.
20
+ */
21
+ class ExponentFileSystemModule extends NativeModule<Record<string, (event: unknown) => void>> {
22
+ private tasks = new Map<string, { controller: AbortController; paused: boolean }>()
23
+
24
+ get documentDirectory(): string {
25
+ return fs().toUri(fs().roots().document, true)
26
+ }
27
+
28
+ get cacheDirectory(): string {
29
+ return fs().toUri(fs().roots().cache, true)
30
+ }
31
+
32
+ get bundleDirectory(): string {
33
+ return getState().device.platform === 'android' ? 'asset:///' : fs().toUri(fs().roots().bundle, true)
34
+ }
35
+
36
+ async getInfoAsync(uri: string, options: { md5?: boolean } = {}) {
37
+ await fs().ready()
38
+ const path = fs().toPath(uri)
39
+ if (!fs().exists(path)) {
40
+ return { exists: false, isDirectory: false, uri }
41
+ }
42
+ const directory = fs().isDirectory(path)
43
+ return {
44
+ exists: true,
45
+ uri,
46
+ isDirectory: directory,
47
+ size: fs().size(path),
48
+ modificationTime: seconds(fs().node(path)?.modified),
49
+ ...(options.md5 && !directory ? { md5: fs().md5(fs().readFile(path)) } : {}),
50
+ }
51
+ }
52
+
53
+ async readAsStringAsync(uri: string, options: { encoding?: Encoding; position?: number; length?: number } = {}) {
54
+ await fs().ready()
55
+ let bytes: Uint8Array = fs().readFile(fs().toPath(uri))
56
+ if (options.position !== undefined || options.length !== undefined) {
57
+ const start = options.position ?? 0
58
+ bytes = bytes.subarray(start, options.length === undefined ? undefined : start + options.length)
59
+ }
60
+ return options.encoding === 'base64' ? fs().toBase64(bytes) : new TextDecoder().decode(bytes)
61
+ }
62
+
63
+ async writeAsStringAsync(uri: string, contents: string, options: { encoding?: Encoding; append?: boolean } = {}) {
64
+ await fs().ready()
65
+ const bytes = options.encoding === 'base64' ? fs().fromBase64(contents) : new TextEncoder().encode(contents)
66
+ fs().writeFile(fs().toPath(uri), bytes, options.append)
67
+ }
68
+
69
+ async deleteAsync(uri: string, options: { idempotent?: boolean } = {}) {
70
+ await fs().ready()
71
+ const path = fs().toPath(uri)
72
+ if (!fs().exists(path)) {
73
+ if (options.idempotent) {
74
+ return
75
+ }
76
+ throw new Error(`File '${uri}' could not be deleted because it could not be found`)
77
+ }
78
+ fs().remove(path)
79
+ }
80
+
81
+ async moveAsync({ from, to }: { from: string; to: string }) {
82
+ await fs().ready()
83
+ fs().move(fs().toPath(from), fs().toPath(to), true)
84
+ }
85
+
86
+ async copyAsync({ from, to }: { from: string; to: string }) {
87
+ await fs().ready()
88
+ fs().copy(fs().toPath(from), fs().toPath(to), true)
89
+ }
90
+
91
+ async makeDirectoryAsync(uri: string, options: { intermediates?: boolean } = {}) {
92
+ await fs().ready()
93
+ const path = fs().toPath(uri)
94
+ if (fs().exists(path)) {
95
+ if (options.intermediates && fs().isDirectory(path)) {
96
+ return
97
+ }
98
+ throw new Error(`Directory '${uri}' could not be created or already exists`)
99
+ }
100
+ fs().makeDirectory(path, options.intermediates ?? false)
101
+ }
102
+
103
+ async readDirectoryAsync(uri: string) {
104
+ await fs().ready()
105
+ const path = fs().toPath(uri)
106
+ if (!fs().isDirectory(path)) {
107
+ throw new Error(`Directory '${uri}' could not be read`)
108
+ }
109
+ return fs().children(path).map((child: string) => child.slice(child.lastIndexOf('/') + 1))
110
+ }
111
+
112
+ async getFreeDiskStorageAsync() {
113
+ return (ExpoFileSystem as { availableDiskSpace: number }).availableDiskSpace
114
+ }
115
+
116
+ async getTotalDiskCapacityAsync() {
117
+ return (ExpoFileSystem as { totalDiskSpace: number }).totalDiskSpace
118
+ }
119
+
120
+ async downloadAsync(url: string, fileUri: string, options: { headers?: Record<string, string>; md5?: boolean } = {}) {
121
+ return this.downloadInto(url, fileUri, options, new AbortController())
122
+ }
123
+
124
+ async downloadResumableStartAsync(url: string, fileUri: string, uuid: string, options: { headers?: Record<string, string>; md5?: boolean } = {}) {
125
+ const task = { controller: new AbortController(), paused: false }
126
+ this.tasks.set(uuid, task)
127
+ try {
128
+ return await this.downloadInto(url, fileUri, options, task.controller, (written, total) =>
129
+ this.emit('expo-file-system.downloadProgress', { uuid, data: { totalBytesWritten: written, totalBytesExpectedToWrite: total } }),
130
+ )
131
+ } catch (error) {
132
+ if (task.paused) {
133
+ return undefined
134
+ }
135
+ throw error
136
+ } finally {
137
+ this.tasks.delete(uuid)
138
+ }
139
+ }
140
+
141
+ /** Pausing stops the transfer; resuming starts it again. */
142
+ async downloadResumablePauseAsync(uuid: string) {
143
+ const task = this.tasks.get(uuid)
144
+ if (task !== undefined) {
145
+ task.paused = true
146
+ task.controller.abort()
147
+ }
148
+ return { resumeData: 'web-sim' }
149
+ }
150
+
151
+ async networkTaskCancelAsync(uuid: string) {
152
+ this.tasks.get(uuid)?.controller.abort()
153
+ }
154
+
155
+ async uploadAsync(url: string, fileUri: string, options: Record<string, any> = {}) {
156
+ const { bytes: _bytes, ...result } = await fs().upload(url, fs().toPath(fileUri), options)
157
+ return { ...result, mimeType: result.headers['content-type'] ?? null }
158
+ }
159
+
160
+ async uploadTaskStartAsync(url: string, fileUri: string, uuid: string, options: Record<string, any> = {}) {
161
+ const task = { controller: new AbortController(), paused: false }
162
+ this.tasks.set(uuid, task)
163
+ try {
164
+ const { bytes, ...result } = await fs().upload(url, fs().toPath(fileUri), options, task.controller.signal)
165
+ this.emit('expo-file-system.uploadProgress', { uuid, data: { totalBytesSent: bytes, totalBytesExpectedToSend: bytes } })
166
+ return { ...result, mimeType: result.headers['content-type'] ?? null }
167
+ } finally {
168
+ this.tasks.delete(uuid)
169
+ }
170
+ }
171
+
172
+ async getContentUriAsync(uri: string) {
173
+ const File = (ExpoFileSystem as { FileSystemFile: new (uri: string) => { contentUri: string } }).FileSystemFile
174
+ return new File(uri).contentUri
175
+ }
176
+
177
+ private async downloadInto(
178
+ url: string,
179
+ fileUri: string,
180
+ options: { headers?: Record<string, string>; md5?: boolean },
181
+ controller: AbortController,
182
+ onProgress: (written: number, total: number) => void = () => undefined,
183
+ ) {
184
+ const { path, response } = await fs().download(url, fileUri, { headers: options.headers, idempotent: true, signal: controller.signal }, onProgress)
185
+ const headers = Object.fromEntries((response as Response).headers.entries())
186
+ return {
187
+ uri: fs().toUri(path, false),
188
+ status: (response as Response).status,
189
+ headers,
190
+ mimeType: headers['content-type'] ?? null,
191
+ ...(options.md5 ? { md5: fs().md5(fs().readFile(path)) } : {}),
192
+ }
193
+ }
194
+ }
195
+
196
+ export default registerWebModule(ExponentFileSystemModule, 'ExponentFileSystem')
@@ -0,0 +1,13 @@
1
+ import { defineOverrides } from '../../../../src/node/overrides/define.ts'
2
+
3
+ export default defineOverrides('expo-file-system', [
4
+ {
5
+ versions: '>=58 <59',
6
+ note: 'a working file system in memory and IndexedDB, for the File/Directory API and the legacy API, browsed in the storage panel',
7
+ files: {
8
+ // The web build has neither API: every call warns and returns nothing.
9
+ 'build/ExpoFileSystem.web.js': './ExpoFileSystem.ts',
10
+ 'build/legacy/ExponentFileSystem.web.js': './ExponentFileSystem.ts',
11
+ },
12
+ },
13
+ ])
@@ -0,0 +1,75 @@
1
+ import { platform, showDialog } from 'web-sim/runtime'
2
+ import { deleteItem, readItem, writeItem } from '../../secure.ts'
3
+
4
+ /**
5
+ * The keychain (iOS) or encrypted shared preferences (Android), over the storage plugin's secure store
6
+ * (`secure.ts`), which the storage panel shows and edits.
7
+ */
8
+
9
+ type Options = {
10
+ keychainService?: string
11
+ requireAuthentication?: boolean
12
+ authenticationPrompt?: string
13
+ }
14
+
15
+ function read(key: string, options: Options) {
16
+ return readItem(key, options.keychainService)
17
+ }
18
+
19
+ function write(value: string, key: string, options: Options): void {
20
+ writeItem(key, value, { service: options.keychainService, requireAuthentication: options.requireAuthentication })
21
+ }
22
+
23
+ /** The biometric prompt the OS shows for an item that requires authentication. Throws when it does not pass. */
24
+ async function authenticate(options: Options): Promise<void> {
25
+ const { button } = await showDialog({ kind: 'biometric', reason: options.authenticationPrompt })
26
+ if (button !== 0) {
27
+ throw new Error(button === 2 ? 'User canceled the operation.' : 'Authentication failed.')
28
+ }
29
+ }
30
+
31
+ const ExpoSecureStore = {
32
+ // iOS's keychain accessibility constants.
33
+ AFTER_FIRST_UNLOCK: 0,
34
+ AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: 1,
35
+ ALWAYS: 2,
36
+ WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: 3,
37
+ ALWAYS_THIS_DEVICE_ONLY: 4,
38
+ WHEN_UNLOCKED: 5,
39
+ WHEN_UNLOCKED_THIS_DEVICE_ONLY: 6,
40
+
41
+ async getValueWithKeyAsync(key: string, options: Options = {}): Promise<string | null> {
42
+ const item = read(key, options)
43
+ if (item?.requireAuthentication) {
44
+ await authenticate(options)
45
+ }
46
+ return item?.value ?? null
47
+ },
48
+
49
+ async setValueWithKeyAsync(value: string, key: string, options: Options = {}): Promise<void> {
50
+ // Android asks when an item that requires authentication is written; iOS only when it is read.
51
+ if (options.requireAuthentication && platform() === 'android') {
52
+ await authenticate(options)
53
+ }
54
+ write(value, key, options)
55
+ },
56
+
57
+ async deleteValueWithKeyAsync(key: string, options: Options = {}): Promise<void> {
58
+ deleteItem(key, options.keychainService)
59
+ },
60
+
61
+ /** The synchronous calls cannot wait for a prompt, so they read and write without one. */
62
+ getValueWithKeySync(key: string, options: Options = {}): string | null {
63
+ return read(key, options)?.value ?? null
64
+ },
65
+
66
+ setValueWithKeySync(value: string, key: string, options: Options = {}): void {
67
+ write(value, key, options)
68
+ },
69
+
70
+ canUseBiometricAuthentication(): boolean {
71
+ return true
72
+ },
73
+ }
74
+
75
+ export default ExpoSecureStore
@@ -0,0 +1,9 @@
1
+ import { defineOverrides } from '../../../../src/node/overrides/define.ts'
2
+
3
+ export default defineOverrides('expo-secure-store', [
4
+ {
5
+ versions: '>=58 <59',
6
+ note: 'a keychain per app, in localStorage, that the storage panel edits; items that require authentication ask for Face ID or a fingerprint',
7
+ files: { 'build/ExpoSecureStore.web.js': './ExpoSecureStore.ts' },
8
+ },
9
+ ])
@@ -0,0 +1,8 @@
1
+ import { definePlugin } from '../../src/node/plugins.ts'
2
+
3
+ export default definePlugin({
4
+ name: 'storage',
5
+ // No packages: every app has localStorage, and the toolbar's reset (`reset`) is this plugin's.
6
+ overrides: './overrides',
7
+ shell: './shell.tsx',
8
+ })
@@ -0,0 +1,136 @@
1
+ import { getHost, plugin } from 'web-sim/runtime'
2
+ import { clearFiles, descendants, isFile, roots, store } from './files.ts'
3
+ import { clearItems, listItems } from './secure.ts'
4
+ import { INITIAL_STORAGE, type StorageState } from './state.ts'
5
+
6
+ /**
7
+ * Resetting the app, as deleting and reinstalling it does, one store at a time.
8
+ *
9
+ * The app's frame shares the shell's origin, so what the app keeps in the browser (AsyncStorage and MMKV's web builds
10
+ * in localStorage, databases in IndexedDB) sits beside web-sim's own. web-sim's own names start with `web-sim`
11
+ * (`web-sim:state`, `web-sim:secure-store:…`, `web-sim-photos`); everything else is the app's.
12
+ */
13
+ export const STORES = ['secureStore', 'files', 'localStorage', 'databases', 'cookies', 'permissions'] as const
14
+ export type Store = (typeof STORES)[number]
15
+
16
+ const OWN = /^web-sim[:-]/
17
+
18
+ /** The app's own keys in a Storage (localStorage, sessionStorage), web-sim's left out. */
19
+ export function appKeys(storage: Storage): string[] {
20
+ const keys: string[] = []
21
+ for (let i = 0; i < storage.length; i++) {
22
+ const key = storage.key(i)
23
+ if (key !== null && !OWN.test(key)) {
24
+ keys.push(key)
25
+ }
26
+ }
27
+ return keys.sort()
28
+ }
29
+
30
+ /** Tells the panel the app's localStorage changed, for changes made from the shell (the app's fire `storage` events). */
31
+ export function localStorageChanged(): void {
32
+ const storage = plugin<StorageState>('storage', INITIAL_STORAGE)
33
+ storage.set({ localStorage: storage.get().localStorage + 1 })
34
+ }
35
+
36
+ async function appDatabases(): Promise<string[]> {
37
+ const databases = await indexedDB.databases()
38
+ return databases.map((database) => database.name ?? '').filter((name) => name !== '' && !OWN.test(name))
39
+ }
40
+
41
+ function deleteDatabase(name: string): Promise<void> {
42
+ return new Promise((resolve) => {
43
+ const request = indexedDB.deleteDatabase(name)
44
+ request.onsuccess = () => resolve()
45
+ request.onerror = () => resolve()
46
+ // Blocked: something still has it open. The app is stopped, so it won't be for long; it goes when they close.
47
+ setTimeout(resolve, 2000)
48
+ })
49
+ }
50
+
51
+ /** Which stores: all of them, or `{"only": [...]}`. `asyncStorage` is another name for `localStorage`. */
52
+ export function parseStores(args: unknown): Store[] {
53
+ const only = (args as { only?: unknown } | undefined)?.only
54
+ if (only === undefined) {
55
+ return [...STORES]
56
+ }
57
+ if (!Array.isArray(only)) {
58
+ throw new Error(`"only" must be a list of: ${STORES.join(', ')}`)
59
+ }
60
+ return only.map((name) => {
61
+ const store = name === 'asyncStorage' ? 'localStorage' : name
62
+ if (!STORES.includes(store as Store)) {
63
+ throw new Error(`No store '${String(name)}'. Stores: ${STORES.join(', ')}`)
64
+ }
65
+ return store as Store
66
+ })
67
+ }
68
+
69
+ export type ResetResult = {
70
+ secureStore?: number
71
+ files?: number
72
+ localStorage?: number
73
+ databases?: string[]
74
+ /** Null when the dev server keeps no cookie jar (`proxy: false`). */
75
+ cookies?: number | null
76
+ permissions?: true
77
+ }
78
+
79
+ /** Stops the app, clears the stores, and launches it again. Returns what each store held. */
80
+ export async function resetApp(stores: Store[]): Promise<ResetResult> {
81
+ const result: ResetResult = {}
82
+ const host = getHost()
83
+ const work = async () => {
84
+ if (stores.includes('secureStore')) {
85
+ result.secureStore = listItems().length
86
+ clearItems()
87
+ }
88
+ if (stores.includes('files')) {
89
+ await store().ready
90
+ const { document, cache } = roots()
91
+ result.files = [...descendants(document), ...descendants(cache)].filter(isFile).length
92
+ clearFiles()
93
+ }
94
+ if (stores.includes('localStorage')) {
95
+ const local = appKeys(localStorage)
96
+ local.forEach((key) => localStorage.removeItem(key))
97
+ appKeys(sessionStorage).forEach((key) => sessionStorage.removeItem(key))
98
+ result.localStorage = local.length
99
+ localStorageChanged()
100
+ }
101
+ if (stores.includes('databases')) {
102
+ const names = await appDatabases()
103
+ await Promise.all(names.map(deleteDatabase))
104
+ result.databases = names
105
+ }
106
+ if (stores.includes('cookies')) {
107
+ try {
108
+ const response = await fetch('/__web-sim/cookies', { method: 'DELETE' })
109
+ result.cookies = response.ok ? ((await response.json()) as { cleared: number }).cleared : null
110
+ } catch {
111
+ result.cookies = null
112
+ }
113
+ }
114
+ if (stores.includes('permissions')) {
115
+ host.resetPermissions?.()
116
+ result.permissions = true
117
+ }
118
+ }
119
+ await (host.relaunch?.(work) ?? work())
120
+ return result
121
+ }
122
+
123
+ const plural = (count: number, noun: string) => `${count} ${noun}${count === 1 ? '' : 's'}`
124
+
125
+ /** One line for the log: `Reset app: 2 secure items, 5 localStorage keys, permissions`. */
126
+ export function describeReset(result: ResetResult): string {
127
+ const parts = [
128
+ result.secureStore !== undefined && plural(result.secureStore, 'secure item'),
129
+ result.files !== undefined && plural(result.files, 'file'),
130
+ result.localStorage !== undefined && plural(result.localStorage, 'localStorage key'),
131
+ result.databases !== undefined && plural(result.databases.length, 'database'),
132
+ result.cookies !== undefined && (result.cookies === null ? 'no cookie jar' : plural(result.cookies, 'cookie')),
133
+ result.permissions && 'permissions',
134
+ ].filter((part): part is string => typeof part === 'string')
135
+ return `Reset app: ${parts.length > 0 ? parts.join(', ') : 'nothing'}`
136
+ }
@@ -0,0 +1,71 @@
1
+ import { app, plugin } from 'web-sim/runtime'
2
+ import { INITIAL_STORAGE, type StorageState } from './state.ts'
3
+
4
+ /**
5
+ * The keychain (iOS) or encrypted shared preferences (Android), kept in localStorage under
6
+ * `web-sim:secure-store:<app slug>:`, then the keychain service and a colon when one is given, then the key. Keys
7
+ * hold only letters, digits, `.`, `-` and `_`, as expo-secure-store requires, so the colon tells the service apart.
8
+ * Shared by the override and the storage panel.
9
+ */
10
+ export type SecureItem = { key: string; service: string | null; value: string; requireAuthentication: boolean }
11
+
12
+ function prefix(): string {
13
+ return `web-sim:secure-store:${app().slug}:`
14
+ }
15
+
16
+ function storageKey(key: string, service: string | null | undefined): string {
17
+ return `${prefix()}${service ? `${service}:` : ''}${key}`
18
+ }
19
+
20
+ function changed(): void {
21
+ const storage = plugin<StorageState>('storage', INITIAL_STORAGE)
22
+ storage.set({ secureStore: storage.get().secureStore + 1 })
23
+ }
24
+
25
+ export function readItem(key: string, service?: string | null): SecureItem | null {
26
+ const raw = localStorage.getItem(storageKey(key, service))
27
+ if (raw === null) {
28
+ return null
29
+ }
30
+ try {
31
+ const item = JSON.parse(raw) as { value: string; requireAuthentication?: boolean }
32
+ return { key, service: service ?? null, value: item.value, requireAuthentication: item.requireAuthentication === true }
33
+ } catch {
34
+ return { key, service: service ?? null, value: raw, requireAuthentication: false }
35
+ }
36
+ }
37
+
38
+ export function writeItem(key: string, value: string, options: { service?: string | null; requireAuthentication?: boolean } = {}): void {
39
+ localStorage.setItem(storageKey(key, options.service), JSON.stringify(options.requireAuthentication ? { value, requireAuthentication: true } : { value }))
40
+ changed()
41
+ }
42
+
43
+ export function deleteItem(key: string, service?: string | null): void {
44
+ localStorage.removeItem(storageKey(key, service))
45
+ changed()
46
+ }
47
+
48
+ /** Every item the app has stored, by service then key. */
49
+ export function listItems(): SecureItem[] {
50
+ const items: SecureItem[] = []
51
+ for (let i = 0; i < localStorage.length; i++) {
52
+ const name = localStorage.key(i)
53
+ if (name === null || !name.startsWith(prefix())) {
54
+ continue
55
+ }
56
+ const rest = name.slice(prefix().length)
57
+ const colon = rest.lastIndexOf(':')
58
+ const item = colon === -1 ? readItem(rest) : readItem(rest.slice(colon + 1), rest.slice(0, colon))
59
+ if (item !== null) {
60
+ items.push(item)
61
+ }
62
+ }
63
+ return items.sort((a, b) => (a.service ?? '').localeCompare(b.service ?? '') || a.key.localeCompare(b.key))
64
+ }
65
+
66
+ export function clearItems(): void {
67
+ for (const item of listItems()) {
68
+ localStorage.removeItem(storageKey(item.key, item.service))
69
+ }
70
+ changed()
71
+ }