@a16n/web-sim 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) 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 +153 -0
  71. package/overrides/react-native-web/useElementLayout.ts +140 -0
  72. package/package.json +78 -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 +113 -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 +59 -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 +21 -0
  250. package/src/devices/catalog.ts +223 -0
  251. package/src/devices/types.ts +83 -0
  252. package/src/node/appInfo.ts +186 -0
  253. package/src/node/appSource.ts +138 -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/index.ts +5 -0
  261. package/src/node/overrides/define.ts +56 -0
  262. package/src/node/overrides/packages.ts +136 -0
  263. package/src/node/overrides/platformPatch.ts +56 -0
  264. package/src/node/overrides/plugin.ts +166 -0
  265. package/src/node/overrides/registry.ts +258 -0
  266. package/src/node/paths.ts +18 -0
  267. package/src/node/platform.ts +171 -0
  268. package/src/node/plugins.ts +98 -0
  269. package/src/node/proxy.ts +421 -0
  270. package/src/node/server.ts +253 -0
  271. package/src/plugin/index.ts +33 -0
  272. package/src/plugin/types.ts +127 -0
  273. package/src/plugin/ui.tsx +562 -0
  274. package/src/runtime/clock.ts +112 -0
  275. package/src/runtime/draw.ts +196 -0
  276. package/src/runtime/index.ts +513 -0
  277. package/src/runtime/media.ts +379 -0
  278. package/src/runtime/records.ts +76 -0
  279. package/src/runtime/timezone.ts +81 -0
@@ -0,0 +1,513 @@
1
+ import { useSyncExternalStore } from 'react'
2
+ import { DEFAULT_DEVICE_ID, DEVICES } from '../devices/catalog.ts'
3
+ import type { Appearance, Device, DeviceHardware, Insets, Orientation, Platform } from '../devices/types.ts'
4
+ import type { EventInput, Level } from '../node/events/shared.ts'
5
+ import type { CameraFacing, CameraFeed, CapturedPhoto } from './media.ts'
6
+
7
+ export type { Appearance, Cutout, Device, DeviceHardware, Insets, Orientation, Platform } from '../devices/types.ts'
8
+ export type { Actor, EventInput, Level, SimEvent } from '../node/events/shared.ts'
9
+ export * from './clock.ts'
10
+ export * from './media.ts'
11
+ export * from './records.ts'
12
+ export * from './timezone.ts'
13
+
14
+ /**
15
+ * The simulator's state, as the device would report it to the app.
16
+ */
17
+ export type SimState = {
18
+ device: Device
19
+ orientation: Orientation
20
+ /** The device's appearance setting, Light or Dark in Settings. System UI outside the app (Android's keyboard) follows it. */
21
+ appearance: Appearance
22
+ /**
23
+ * The appearance the app's views get: the device's, unless the app pins one, as `UIUserInterfaceStyle` (Expo's
24
+ * `userInterfaceStyle`) or `Appearance.setColorScheme` do. What the app draws, and what iOS draws in its windows (the
25
+ * keyboard, alerts), follows this.
26
+ */
27
+ appAppearance: Appearance
28
+ }
29
+
30
+ /** An app's `userInterfaceStyle`: a pinned appearance, or `automatic` to follow the device. */
31
+ export type UserInterfaceStyle = Appearance | 'automatic'
32
+
33
+ /**
34
+ * The colour of a system bar's content. `light` is light content, for dark backgrounds. `auto` follows the
35
+ * appearance (light content in dark mode), as expo-status-bar's and react-native-screens' `auto` resolve it.
36
+ * `default` is iOS's `UIStatusBarStyleDefault`: since iOS 17 the status bar picks light or dark from the content under
37
+ * it, so the shell reads that content; Android, and the navigation bar, treat it as `auto`.
38
+ */
39
+ export type StatusBarStyle = 'light' | 'dark' | 'auto' | 'default'
40
+
41
+ /**
42
+ * What the app asks of the status bar. `screenStyle` is the focused navigator screen's `statusBarStyle`: while one is
43
+ * set it wins over the `StatusBar` components' `style`, as a view controller's preference does on iOS.
44
+ */
45
+ export type StatusBarUpdate = { style?: StatusBarStyle; hidden?: boolean; screenStyle?: StatusBarStyle | null }
46
+
47
+ export type DialogButton = { text: string; style?: 'default' | 'cancel' | 'destructive' }
48
+
49
+ /** What a permission is for. The shell words its prompt from this, as each OS words its own. */
50
+ export type PermissionKind =
51
+ | 'camera'
52
+ | 'microphone'
53
+ | 'photos'
54
+ | 'location'
55
+ | 'location-background'
56
+ | 'contacts'
57
+ | 'calendar'
58
+ | 'reminders'
59
+ | 'notifications'
60
+ | 'tracking'
61
+ | 'motion'
62
+ | 'face-id'
63
+
64
+ export type PermissionStatus = 'undetermined' | 'granted' | 'denied'
65
+
66
+ /**
67
+ * A system dialog the shell draws over the app, in the platform's style.
68
+ *
69
+ * - `alert`: `Alert.alert`, with an optional text field (`Alert.prompt`).
70
+ * - `action-sheet`: iOS's action sheet, or Android's bottom sheet.
71
+ * - `permission`: the OS's permission prompt. Button 0 denies; 1 allows; for location, 2 allows once.
72
+ * - `biometric`: Face ID, Touch ID or Android's biometric prompt for `sensor` (by default, what the device has). The
73
+ * shell adds controls for what the sensor sees. Button 0 is a match, 1 a failed match, 2 a cancel.
74
+ * - `photo-picker`: the system photo picker over `photos` and `albums`. Button 1 picks `selected` (asset ids), 0 cancels.
75
+ * - `camera`: the system camera app, seeing `feeds`. Button 1 uses the `photo` taken, 0 cancels.
76
+ */
77
+ export type Dialog =
78
+ | {
79
+ kind: 'alert'
80
+ title: string
81
+ message?: string
82
+ buttons: DialogButton[]
83
+ input?: { secure?: boolean; defaultValue?: string; placeholder?: string }
84
+ }
85
+ | { kind: 'action-sheet'; title?: string; message?: string; buttons: DialogButton[] }
86
+ | { kind: 'permission'; permission: PermissionKind; message?: string }
87
+ | { kind: 'biometric'; reason?: string; cancelLabel?: string; sensor?: BiometricSensor }
88
+ | { kind: 'store-review' }
89
+ | { kind: 'share'; url: string; title?: string; mimeType?: string }
90
+ | {
91
+ kind: 'compose'
92
+ channel: 'sms' | 'mail'
93
+ recipients: string[]
94
+ ccRecipients?: string[]
95
+ bccRecipients?: string[]
96
+ subject?: string
97
+ body?: string
98
+ attachments?: string[]
99
+ }
100
+ | {
101
+ kind: 'photo-picker'
102
+ multiple: boolean
103
+ limit: number
104
+ ordered?: boolean
105
+ mediaTypes: ('images' | 'videos' | 'livePhotos')[]
106
+ photos: PickerPhoto[]
107
+ albums: { id: string; title: string; assetIds: string[] }[]
108
+ }
109
+ | { kind: 'camera'; facing: CameraFacing; feeds: Record<CameraFacing, CameraFeed> }
110
+
111
+ export type BiometricSensor = 'face' | 'touch' | 'fingerprint'
112
+
113
+ /** A photo the picker shows: its asset id, and a small image for the grid. */
114
+ export type PickerPhoto = { id: string; filename: string; thumbnail: string; favorite: boolean }
115
+
116
+ export type DialogResult = { button: number; text?: string; selected?: string[]; photo?: CapturedPhoto }
117
+
118
+ export type HapticKind =
119
+ | 'light'
120
+ | 'medium'
121
+ | 'heavy'
122
+ | 'soft'
123
+ | 'rigid'
124
+ | 'selection'
125
+ | 'success'
126
+ | 'warning'
127
+ | 'error'
128
+
129
+ /** Which of the app's haptic calls made a haptic: expo-haptics' impact, notification, selection or Android call. */
130
+ export type HapticCall = { method: 'impact' | 'notification' | 'selection' } | { method: 'android'; type: string }
131
+
132
+ export type SimNotification = { id: string; title?: string; subtitle?: string; body?: string; data?: unknown }
133
+
134
+ /** What the app's config (`app.json`) says, as far as the simulator draws it. */
135
+ export type FirebaseOptions = {
136
+ apiKey?: string
137
+ appId?: string
138
+ projectId?: string
139
+ messagingSenderId?: string
140
+ storageBucket?: string
141
+ databaseURL?: string
142
+ clientId?: string
143
+ }
144
+
145
+ export type AppInfo = {
146
+ name: string
147
+ slug: string
148
+ version: string
149
+ bundleId: string
150
+ /** The app icon's URL. */
151
+ icon?: string
152
+ splash: { backgroundColor: string; darkBackgroundColor?: string; image?: string; imageWidth: number } | null
153
+ /** iOS usage descriptions, by Info.plist key (`NSCameraUsageDescription`). */
154
+ usageDescriptions: Record<string, string>
155
+ /** The app's resolved Expo config (`app.config.ts` or `app.json`), as `expo-constants` gives it in `expoConfig`. */
156
+ config?: Record<string, any>
157
+ /**
158
+ * The Firebase options a native build reads from the app's `GoogleService-Info.plist` (iOS) and
159
+ * `google-services.json` (Android), when the Expo config names them.
160
+ */
161
+ googleServices?: { ios?: FirebaseOptions; android?: FirebaseOptions }
162
+ /** The packages the app depends on, from its `package.json`. */
163
+ dependencies?: string[]
164
+ /** The appearance the app pins by platform, from its Expo config's `userInterfaceStyle`. */
165
+ userInterfaceStyle?: { ios: UserInterfaceStyle; android: UserInterfaceStyle }
166
+ }
167
+
168
+ /**
169
+ * The shell's side of the simulator. It lives on the shell's window; the app reaches it through `window.parent`,
170
+ * which works because both share an origin. Overrides talk to it through this module and keep no state of their
171
+ * own, because a module an override imports can be loaded twice: once in the pre-bundle, once as source.
172
+ */
173
+ export interface SimHost {
174
+ getState(): SimState
175
+ subscribe(listener: () => void): () => void
176
+ /** What the app's status bar components ask for. The last call wins. */
177
+ setStatusBar(update: StatusBarUpdate): void
178
+ app: AppInfo
179
+ showDialog(dialog: Dialog): Promise<DialogResult>
180
+ haptic(kind: HapticKind, call?: HapticCall): void
181
+ getPermission(kind: PermissionKind): PermissionStatus
182
+ setPermission(kind: PermissionKind, status: PermissionStatus): void
183
+ /** Shows a notification banner. Resolves true when it is tapped, false when it goes away. */
184
+ notify(notification: SimNotification): Promise<boolean>
185
+ /** The splash screen: kept up until `hideSplash` once `preventAutoHideSplash` is called, else hidden on first render. */
186
+ preventAutoHideSplash(): void
187
+ hideSplash(options?: { fade?: boolean; duration?: number }): void
188
+ /** The app rendered for the first time. */
189
+ appRendered(): void
190
+ /** Rotates to and holds an orientation, as `expo-screen-orientation`'s locks do; null lets the user rotate. */
191
+ setOrientationLock(lock: Orientation | null): void
192
+ getOrientationLock(): Orientation | null
193
+ /** Android's navigation bar: the colour of its handle or buttons, and whether it shows. */
194
+ setNavigationBar(update: { style?: StatusBarStyle; hidden?: boolean }): void
195
+ /** Plugins' state and events, which their panels and their overrides share. */
196
+ plugins: PluginHost
197
+ getNavigationBar(): { style: StatusBarStyle; hidden: boolean }
198
+ /** Adds an event to the simulator's log. `maxString` (default 1 KB) is the longest string kept in `data`. */
199
+ log(input: EventInput & { maxString?: number }): void
200
+ /**
201
+ * Stops the app (its frame is removed, so its pages unload and its databases close), runs `work` while no app is
202
+ * running, then launches it fresh. The shell's own; absent from the fallback host.
203
+ */
204
+ relaunch?(work?: () => Promise<void>): Promise<void>
205
+ /** Every permission back to not asked, as the toolbar's button does. The shell's own. */
206
+ resetPermissions?(): void
207
+ /** `Appearance.setColorScheme`: pins the app's appearance until the next launch; null follows the config again. */
208
+ setAppColorScheme?(scheme: Appearance | null): void
209
+ }
210
+
211
+ /**
212
+ * The shell's plugin state, by plugin id. Values are plain JSON, so they read the same from the app's window.
213
+ */
214
+ export interface PluginHost {
215
+ /** The plugin's state, or undefined when no plugin with that id is loaded. */
216
+ get(id: string): Record<string, unknown> | undefined
217
+ set(id: string, patch: Record<string, unknown>): void
218
+ subscribe(id: string, listener: () => void): () => void
219
+ /** Sends an event on the plugin's channel. `from` says which side sent it, so each side hears only the other. */
220
+ emit(id: string, event: string, payload: unknown, from: 'app' | 'shell'): void
221
+ on(id: string, event: string, listener: (payload: unknown) => void, side: 'app' | 'shell'): () => void
222
+ /** How many listeners one side has for an event. */
223
+ listenerCount(id: string, event: string, side: 'app' | 'shell'): number
224
+ }
225
+
226
+ declare global {
227
+ interface Window {
228
+ __webSimHost?: SimHost
229
+ __webSimBackListeners?: Set<() => boolean>
230
+ /** On the window of a phone popped out of the shell's tab: the shell's own window. */
231
+ __webSimShell?: Window
232
+ }
233
+ }
234
+
235
+ let fallback: SimHost | null = null
236
+
237
+ /**
238
+ * A host for the app opened on its own, outside the shell: the default device, never changing.
239
+ */
240
+ function fallbackHost(): SimHost {
241
+ const state: SimState = {
242
+ device: DEVICES.find((device) => device.id === DEFAULT_DEVICE_ID)!,
243
+ orientation: 'portrait',
244
+ appearance: 'light',
245
+ appAppearance: 'light',
246
+ }
247
+ const permissions = new Map<PermissionKind, PermissionStatus>()
248
+ return {
249
+ getState: () => state,
250
+ subscribe: () => () => undefined,
251
+ setStatusBar: () => undefined,
252
+ app: { name: document.title, slug: 'app', version: '1.0.0', bundleId: 'com.example.app', splash: null, usageDescriptions: {} },
253
+ showDialog: (dialog) => {
254
+ if (dialog.kind === 'alert') {
255
+ window.alert([dialog.title, dialog.message].filter(Boolean).join('\n\n'))
256
+ }
257
+ return Promise.resolve({ button: dialog.kind === 'permission' ? 1 : 0 })
258
+ },
259
+ haptic: () => undefined,
260
+ getPermission: (kind) => permissions.get(kind) ?? 'undetermined',
261
+ setPermission: (kind, status) => permissions.set(kind, status),
262
+ notify: () => Promise.resolve(false),
263
+ preventAutoHideSplash: () => undefined,
264
+ hideSplash: () => undefined,
265
+ appRendered: () => undefined,
266
+ setOrientationLock: () => undefined,
267
+ getOrientationLock: () => null,
268
+ setNavigationBar: () => undefined,
269
+ plugins: {
270
+ get: () => undefined,
271
+ set: () => undefined,
272
+ subscribe: () => () => undefined,
273
+ emit: () => undefined,
274
+ on: () => () => undefined,
275
+ listenerCount: () => 0,
276
+ },
277
+ getNavigationBar: () => ({ style: 'auto', hidden: false }),
278
+ log: () => undefined,
279
+ }
280
+ }
281
+
282
+ /**
283
+ * The shell's window, which outlives the app's, so state kept on it lasts across reloads. Usually the app's parent;
284
+ * while the phone is popped out into its own window, that window points back to the shell's.
285
+ */
286
+ export function shellWindow(): Window {
287
+ try {
288
+ const parent = window.parent
289
+ if (parent !== window && parent.__webSimHost !== undefined) {
290
+ return parent.__webSimShell ?? parent
291
+ }
292
+ } catch {
293
+ // A parent on another origin.
294
+ }
295
+ return window
296
+ }
297
+
298
+ export function getHost(): SimHost {
299
+ if (window.__webSimHost !== undefined) {
300
+ return window.__webSimHost
301
+ }
302
+ try {
303
+ if (window.parent !== window && window.parent.__webSimHost !== undefined) {
304
+ return window.parent.__webSimHost
305
+ }
306
+ } catch {
307
+ // A parent on another origin.
308
+ }
309
+ fallback ??= fallbackHost()
310
+ return fallback
311
+ }
312
+
313
+ export function getState(): SimState {
314
+ return getHost().getState()
315
+ }
316
+
317
+ export function subscribe(listener: () => void): () => void {
318
+ return getHost().subscribe(listener)
319
+ }
320
+
321
+ export function useSimState(): SimState {
322
+ return useSyncExternalStore(subscribe, getState)
323
+ }
324
+
325
+ export function platform(): Platform {
326
+ return getState().device.platform
327
+ }
328
+
329
+ /** The screen's size in the current orientation. */
330
+ export function screenSize(state: SimState = getState()): { width: number; height: number } {
331
+ const { width, height } = state.device.screen
332
+ return state.orientation === 'portrait' ? { width, height } : { width: height, height: width }
333
+ }
334
+
335
+ export function insets(state: SimState = getState()): Insets {
336
+ return state.device.insets[state.orientation]
337
+ }
338
+
339
+ /**
340
+ * A value every copy of an override shares for the shell's session, such as the battery's level: kept on the host,
341
+ * made by `create` on first use, gone when the shell reloads.
342
+ */
343
+ export function sessionValue<T>(key: string, create: () => T): T {
344
+ const host = getHost() as SimHost & { __webSimSession?: Map<string, unknown> }
345
+ host.__webSimSession ??= new Map()
346
+ if (!host.__webSimSession.has(key)) {
347
+ host.__webSimSession.set(key, create())
348
+ }
349
+ return host.__webSimSession.get(key) as T
350
+ }
351
+
352
+ /**
353
+ * What the device reports about its hardware, with generic values for a device the catalogue does not describe.
354
+ */
355
+ export function hardware(device: Device = getState().device): DeviceHardware & { modelName: string } {
356
+ const ios = device.platform === 'ios'
357
+ return {
358
+ brand: ios ? 'Apple' : 'generic',
359
+ manufacturer: ios ? 'Apple' : 'unknown',
360
+ osBuildId: ios ? '23A341' : 'AP4A.250205.002',
361
+ yearClass: 2024,
362
+ totalMemory: 8 * 1024 ** 3,
363
+ totalStorage: 128 * 1024 ** 3,
364
+ cpuArchitectures: [ios ? 'arm64e' : 'arm64-v8a'],
365
+ ...device.hardware,
366
+ modelName: device.hardware?.modelName ?? device.label,
367
+ }
368
+ }
369
+
370
+ export function setStatusBar(update: StatusBarUpdate): void {
371
+ getHost().setStatusBar(update)
372
+ }
373
+
374
+ /**
375
+ * Android's back button. Listeners run newest first until one returns true, as `BackHandler` runs them.
376
+ */
377
+ export function addBackListener(listener: () => boolean): () => void {
378
+ const listeners = (window.__webSimBackListeners ??= new Set())
379
+ listeners.add(listener)
380
+ return () => listeners.delete(listener)
381
+ }
382
+
383
+ /**
384
+ * Presses back in the app's window: the listeners first, then the browser history, which expo-router and React
385
+ * Navigation keep in step with the screens on the web. Returns whether anything handled it.
386
+ */
387
+ export function pressBack(appWindow: Window = window): boolean {
388
+ const listeners = [...(appWindow.__webSimBackListeners ?? [])].reverse()
389
+ if (listeners.some((listener) => listener())) {
390
+ return true
391
+ }
392
+ if (appWindow.history.length > 1) {
393
+ appWindow.history.back()
394
+ return true
395
+ }
396
+ return false
397
+ }
398
+
399
+ export function app(): AppInfo {
400
+ return getHost().app
401
+ }
402
+
403
+ export function showDialog(dialog: Dialog): Promise<DialogResult> {
404
+ return getHost().showDialog(dialog)
405
+ }
406
+
407
+ export function haptic(kind: HapticKind, call?: HapticCall): void {
408
+ getHost().haptic(kind, call)
409
+ }
410
+
411
+ export function notify(notification: SimNotification): Promise<boolean> {
412
+ return getHost().notify(notification)
413
+ }
414
+
415
+ /**
416
+ * The shape Expo's permission APIs answer with. On iOS a denied permission cannot be asked for again; on Android it
417
+ * can, until the user picks "Don't allow" twice, which is simplified here to the same rule.
418
+ */
419
+ export type PermissionResponse = {
420
+ status: PermissionStatus
421
+ granted: boolean
422
+ canAskAgain: boolean
423
+ expires: 'never'
424
+ }
425
+
426
+ export function permissionResponse(status: PermissionStatus): PermissionResponse {
427
+ return { status, granted: status === 'granted', canAskAgain: status === 'undetermined', expires: 'never' }
428
+ }
429
+
430
+ export function getPermission(kind: PermissionKind): PermissionResponse {
431
+ return permissionResponse(getHost().getPermission(kind))
432
+ }
433
+
434
+ /**
435
+ * Asks for a permission as the OS does: the prompt shows only while it is undetermined, and the answer is kept
436
+ * until the simulator's permissions are reset. `message` is the iOS usage description, when the module has one.
437
+ */
438
+ export async function requestPermission(kind: PermissionKind, message?: string): Promise<PermissionResponse> {
439
+ const host = getHost()
440
+ const current = host.getPermission(kind)
441
+ if (current !== 'undetermined') {
442
+ return permissionResponse(current)
443
+ }
444
+ const { button } = await host.showDialog({ kind: 'permission', permission: kind, message })
445
+ const status: PermissionStatus = button === 0 ? 'denied' : 'granted'
446
+ host.setPermission(kind, status)
447
+ return permissionResponse(status)
448
+ }
449
+
450
+ /**
451
+ * An override's handle on its plugin: the state the plugin's panel shows and changes, and the events between them.
452
+ * The state is the plugin's `initialState` until the panel changes it; outside the shell, `fallback`.
453
+ *
454
+ * ```ts
455
+ * const battery = plugin('battery', { level: 1, charging: false })
456
+ * battery.get().level
457
+ * battery.subscribe(() => emitLevel(battery.get().level))
458
+ * ```
459
+ */
460
+ export function plugin<S extends Record<string, unknown>>(id: string, fallback: S) {
461
+ const host = () => getHost().plugins
462
+ const get = (): S => (host().get(id) as S | undefined) ?? fallback
463
+ const subscribe = (listener: () => void) => host().subscribe(id, listener)
464
+ return {
465
+ get,
466
+ set: (patch: Partial<S>) => host().set(id, patch),
467
+ subscribe,
468
+ /** Calls `listener` with each new state, and returns its removal. */
469
+ watch(listener: (state: S, previous: S) => void): () => void {
470
+ let previous = get()
471
+ return subscribe(() => {
472
+ const next = get()
473
+ if (next !== previous) {
474
+ const last = previous
475
+ previous = next
476
+ listener(next, last)
477
+ }
478
+ })
479
+ },
480
+ use: (): S => useSyncExternalStore(subscribe, get),
481
+ /** Sends an event to the plugin's shell side. */
482
+ emit: (event: string, payload?: unknown) => host().emit(id, event, payload, 'app'),
483
+ /** Listens to events the plugin's panel or the CLI sends. */
484
+ on: (event: string, listener: (payload: unknown) => void) => host().on(id, event, listener, 'app'),
485
+ /** Adds an event to the simulator's log under the plugin's id: `log('request', ...)` logs `network.request`. */
486
+ log: (kind: string, summary: string, data?: unknown, options?: LogOptions) => log(kind.startsWith(`${id}.`) ? kind : `${id}.${kind}`, summary, data, options),
487
+ }
488
+ }
489
+
490
+ export type LogOptions = { level?: Level; span?: string; cause?: string; maxString?: number }
491
+
492
+ /**
493
+ * Adds an event to the simulator's log, which `web-sim logs` and the shell show. `kind` is dotted and source-first
494
+ * (`notifications.scheduled`); `summary` is one readable line; `data` is any value, copied as JSON with long strings
495
+ * cut. Events logged here are the app's (`actor: app`).
496
+ *
497
+ * ```ts
498
+ * log('notifications.scheduled', 'Reminder in 30 s', { identifier, trigger }, { span: identifier })
499
+ * ```
500
+ */
501
+ export function log(kind: string, summary: string, data?: unknown, options?: LogOptions): void {
502
+ getHost().log?.({ kind, summary, data, actor: 'app', ...options })
503
+ }
504
+
505
+ /** A line in a log a plugin keeps in its state: what the app asked for, or wrote. */
506
+ export type LogEntry = { time: number; text: string }
507
+
508
+ /** Adds an entry to a log, keeping the newest `max`. A repeat of the last entry replaces it, with the new time. */
509
+ export function appendLog(entries: LogEntry[], text: string, max = 20): LogEntry[] {
510
+ const last = entries.at(-1)
511
+ const base = last !== undefined && last.text === text ? entries.slice(0, -1) : entries
512
+ return [...base, { time: Date.now(), text }].slice(-max)
513
+ }