@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.
- package/README.md +13 -2
- package/bin/cli.ts +255 -0
- package/bin/web-sim.js +39 -0
- package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
- package/overrides/@react-native-firebase/app/overrides.ts +34 -0
- package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
- package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
- package/overrides/expo-application/ExpoApplication.ts +81 -0
- package/overrides/expo-application/overrides.ts +16 -0
- package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
- package/overrides/expo-background-task/overrides.ts +9 -0
- package/overrides/expo-constants/ExponentConstants.ts +66 -0
- package/overrides/expo-constants/overrides.ts +9 -0
- package/overrides/expo-device/ExpoDevice.ts +104 -0
- package/overrides/expo-device/overrides.ts +9 -0
- package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
- package/overrides/expo-glass-effect/GlassView.tsx +95 -0
- package/overrides/expo-glass-effect/availability.ts +14 -0
- package/overrides/expo-glass-effect/overrides.ts +14 -0
- package/overrides/expo-haptics/Haptics.ts +67 -0
- package/overrides/expo-haptics/overrides.ts +5 -0
- package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
- package/overrides/expo-mail-composer/overrides.ts +9 -0
- package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
- package/overrides/expo-mesh-gradient/overrides.ts +9 -0
- package/overrides/expo-modules-core/overrides.ts +12 -0
- package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
- package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
- package/overrides/expo-navigation-bar/overrides.ts +12 -0
- package/overrides/expo-router/NativeStackView.tsx +74 -0
- package/overrides/expo-router/NativeTabsView.tsx +263 -0
- package/overrides/expo-router/SafeAreaProvider.ts +6 -0
- package/overrides/expo-router/overrides.ts +23 -0
- package/overrides/expo-router/statusBarRequests.ts +51 -0
- package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
- package/overrides/expo-screen-orientation/overrides.ts +21 -0
- package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
- package/overrides/expo-sharing/overrides.ts +9 -0
- package/overrides/expo-sms/ExpoSMS.ts +24 -0
- package/overrides/expo-sms/overrides.ts +9 -0
- package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
- package/overrides/expo-splash-screen/overrides.ts +5 -0
- package/overrides/expo-status-bar/StatusBar.tsx +44 -0
- package/overrides/expo-status-bar/overrides.ts +5 -0
- package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
- package/overrides/expo-store-review/overrides.ts +9 -0
- package/overrides/expo-symbols/SymbolView.tsx +192 -0
- package/overrides/expo-symbols/overrides.ts +9 -0
- package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
- package/overrides/expo-system-ui/overrides.ts +9 -0
- package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
- package/overrides/expo-task-manager/overrides.ts +9 -0
- package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
- package/overrides/expo-tracking-transparency/overrides.ts +11 -0
- package/overrides/expo-video/ExpoVideo.ts +16 -0
- package/overrides/expo-video/overrides.ts +9 -0
- package/overrides/lottie-react-native/LottieView.tsx +87 -0
- package/overrides/lottie-react-native/overrides.ts +9 -0
- package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
- package/overrides/react-native-pager-view/overrides.ts +9 -0
- package/overrides/react-native-reanimated/overrides.ts +28 -0
- package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
- package/overrides/react-native-safe-area-context/overrides.ts +12 -0
- package/overrides/react-native-share/NativeRNShare.ts +22 -0
- package/overrides/react-native-share/overrides.ts +12 -0
- package/overrides/react-native-share/platform.ts +14 -0
- package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
- package/overrides/react-native-turbo-image/overrides.ts +9 -0
- package/overrides/react-native-web/RefreshControl.tsx +57 -0
- package/overrides/react-native-web/overrides.ts +157 -0
- package/overrides/react-native-web/useElementLayout.ts +152 -0
- package/package.json +80 -4
- package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
- package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
- package/plugins/battery/plugin.ts +8 -0
- package/plugins/battery/shell.tsx +56 -0
- package/plugins/battery/state.ts +11 -0
- package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
- package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
- package/plugins/biometrics/plugin.ts +8 -0
- package/plugins/biometrics/shell.tsx +88 -0
- package/plugins/biometrics/state.ts +41 -0
- package/plugins/brightness/app.ts +5 -0
- package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
- package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
- package/plugins/brightness/plugin.ts +9 -0
- package/plugins/brightness/shell.tsx +55 -0
- package/plugins/brightness/state.ts +19 -0
- package/plugins/calendar/calendar.ts +299 -0
- package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
- package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
- package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
- package/plugins/calendar/plugin.ts +8 -0
- package/plugins/calendar/shell.tsx +123 -0
- package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
- package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
- package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
- package/plugins/camera/plugin.ts +9 -0
- package/plugins/camera/shell.tsx +107 -0
- package/plugins/camera/state.ts +61 -0
- package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
- package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
- package/plugins/clipboard/plugin.ts +8 -0
- package/plugins/clipboard/shell.tsx +122 -0
- package/plugins/clipboard/state.ts +93 -0
- package/plugins/clock/app.ts +25 -0
- package/plugins/clock/plugin.ts +8 -0
- package/plugins/clock/shell.tsx +225 -0
- package/plugins/clock/state.ts +12 -0
- package/plugins/contacts/contacts.ts +125 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
- package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
- package/plugins/contacts/plugin.ts +8 -0
- package/plugins/contacts/shell.tsx +109 -0
- package/plugins/home-indicator/app.ts +5 -0
- package/plugins/home-indicator/plugin.ts +9 -0
- package/plugins/home-indicator/requests.ts +48 -0
- package/plugins/home-indicator/shell.tsx +68 -0
- package/plugins/home-indicator/state.ts +31 -0
- package/plugins/keep-awake/app.ts +5 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
- package/plugins/keep-awake/plugin.ts +9 -0
- package/plugins/keep-awake/shell.tsx +80 -0
- package/plugins/keep-awake/state.ts +12 -0
- package/plugins/keyboard/Keyboard.tsx +354 -0
- package/plugins/keyboard/app.ts +90 -0
- package/plugins/keyboard/controller.ts +384 -0
- package/plugins/keyboard/fields.ts +244 -0
- package/plugins/keyboard/icons.tsx +283 -0
- package/plugins/keyboard/keyboard.css +362 -0
- package/plugins/keyboard/layouts/android.ts +175 -0
- package/plugins/keyboard/layouts/index.ts +10 -0
- package/plugins/keyboard/layouts/ios.ts +219 -0
- package/plugins/keyboard/layouts/types.ts +80 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
- package/plugins/keyboard/plugin.ts +13 -0
- package/plugins/keyboard/shell.tsx +133 -0
- package/plugins/keyboard/state.ts +92 -0
- package/plugins/keyboard/suggestions.ts +63 -0
- package/plugins/keyboard/taps.ts +77 -0
- package/plugins/keyboard/typing.ts +112 -0
- package/plugins/locale/app.ts +232 -0
- package/plugins/locale/locale.ts +143 -0
- package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
- package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
- package/plugins/locale/plugin.ts +9 -0
- package/plugins/locale/shell.tsx +147 -0
- package/plugins/locale/state.ts +36 -0
- package/plugins/location/geo.ts +56 -0
- package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
- package/plugins/location/overrides/expo-location/overrides.ts +11 -0
- package/plugins/location/places.ts +38 -0
- package/plugins/location/plugin.ts +8 -0
- package/plugins/location/shell.tsx +188 -0
- package/plugins/location/state.ts +51 -0
- package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
- package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
- package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
- package/plugins/motion/plugin.ts +8 -0
- package/plugins/motion/sensors.ts +116 -0
- package/plugins/motion/shell.tsx +136 -0
- package/plugins/motion/state.ts +46 -0
- package/plugins/network/app.ts +400 -0
- package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
- package/plugins/network/overrides/expo-network/overrides.ts +9 -0
- package/plugins/network/plugin.ts +8 -0
- package/plugins/network/shell.tsx +67 -0
- package/plugins/network/state.ts +29 -0
- package/plugins/notifications/center.ts +255 -0
- package/plugins/notifications/content.ts +36 -0
- package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
- package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
- package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
- package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
- package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
- package/plugins/notifications/plugin.ts +8 -0
- package/plugins/notifications/shell.tsx +192 -0
- package/plugins/notifications/state.ts +56 -0
- package/plugins/notifications/tokens.ts +47 -0
- package/plugins/notifications/trigger.ts +107 -0
- package/plugins/permissions/plugin.ts +6 -0
- package/plugins/permissions/shell.tsx +50 -0
- package/plugins/permissions/state.ts +38 -0
- package/plugins/photos/appLibrary.ts +114 -0
- package/plugins/photos/library.ts +322 -0
- package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
- package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
- package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
- package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
- package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
- package/plugins/photos/plugin.ts +8 -0
- package/plugins/photos/samples.ts +367 -0
- package/plugins/photos/shell.tsx +164 -0
- package/plugins/photos/state.ts +88 -0
- package/plugins/storage/files.ts +351 -0
- package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
- package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
- package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
- package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
- package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
- package/plugins/storage/plugin.ts +8 -0
- package/plugins/storage/reset.ts +136 -0
- package/plugins/storage/secure.ts +71 -0
- package/plugins/storage/shell.tsx +365 -0
- package/plugins/storage/state.ts +13 -0
- package/src/client/app/appDocument.ts +129 -0
- package/src/client/app/appFocus.ts +97 -0
- package/src/client/app/console.ts +118 -0
- package/src/client/app/fonts.ts +76 -0
- package/src/client/app/main.tsx +99 -0
- package/src/client/app/routeContext.ts +45 -0
- package/src/client/app/touch.ts +640 -0
- package/src/client/entry.ts +20 -0
- package/src/client/modules.d.ts +8 -0
- package/src/client/react-native/app.ts +57 -0
- package/src/client/react-native/deep.ts +13 -0
- package/src/client/react-native/keyboard.tsx +192 -0
- package/src/client/react-native/library.ts +256 -0
- package/src/client/shell/Cookies.tsx +95 -0
- package/src/client/shell/LogDrawer.tsx +415 -0
- package/src/client/shell/PhotoPicker.tsx +174 -0
- package/src/client/shell/PluginOverlays.tsx +42 -0
- package/src/client/shell/PluginPanels.tsx +82 -0
- package/src/client/shell/ResetApp.tsx +87 -0
- package/src/client/shell/Resizer.tsx +99 -0
- package/src/client/shell/Shell.tsx +531 -0
- package/src/client/shell/SystemBars.tsx +376 -0
- package/src/client/shell/SystemCamera.tsx +181 -0
- package/src/client/shell/SystemOverlay.tsx +422 -0
- package/src/client/shell/SystemSheets.tsx +462 -0
- package/src/client/shell/backdrop.ts +229 -0
- package/src/client/shell/control.ts +91 -0
- package/src/client/shell/events.ts +226 -0
- package/src/client/shell/geometry.ts +68 -0
- package/src/client/shell/host.ts +492 -0
- package/src/client/shell/icons.tsx +34 -0
- package/src/client/shell/logFeed.ts +102 -0
- package/src/client/shell/main.tsx +22 -0
- package/src/client/shell/permissionCopy.ts +169 -0
- package/src/client/shell/plugins.ts +266 -0
- package/src/client/shell/popout.ts +185 -0
- package/src/client/shell/popover.ts +27 -0
- package/src/client/shell/shell.css +878 -0
- package/src/client/shell/statusTime.ts +31 -0
- package/src/client/shell/tooltips.ts +104 -0
- package/src/client/virtual.d.ts +23 -0
- package/src/devices/catalog.ts +223 -0
- package/src/devices/types.ts +83 -0
- package/src/node/appInfo.ts +188 -0
- package/src/node/appSource.ts +140 -0
- package/src/node/config.ts +180 -0
- package/src/node/control.ts +144 -0
- package/src/node/doctor.ts +199 -0
- package/src/node/events/cli.ts +206 -0
- package/src/node/events/shared.ts +238 -0
- package/src/node/events/store.ts +266 -0
- package/src/node/fonts.ts +377 -0
- package/src/node/index.ts +5 -0
- package/src/node/overrides/define.ts +56 -0
- package/src/node/overrides/packages.ts +136 -0
- package/src/node/overrides/platformPatch.ts +56 -0
- package/src/node/overrides/plugin.ts +169 -0
- package/src/node/overrides/registry.ts +258 -0
- package/src/node/paths.ts +18 -0
- package/src/node/platform.ts +171 -0
- package/src/node/plugins.ts +98 -0
- package/src/node/proxy.ts +421 -0
- package/src/node/server.ts +254 -0
- package/src/node/worklets.ts +86 -0
- package/src/plugin/index.ts +33 -0
- package/src/plugin/types.ts +127 -0
- package/src/plugin/ui.tsx +562 -0
- package/src/runtime/clock.ts +112 -0
- package/src/runtime/draw.ts +196 -0
- package/src/runtime/index.ts +519 -0
- package/src/runtime/media.ts +379 -0
- package/src/runtime/records.ts +76 -0
- package/src/runtime/timezone.ts +81 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect, useReducer } from 'react'
|
|
2
|
+
import { clockState, phoneTimeZone, phoneUses24HourClock, realDelayUntil, phoneNow, statusBarTime } from '../../runtime/index.ts'
|
|
3
|
+
import type { PluginStore } from './plugins.ts'
|
|
4
|
+
|
|
5
|
+
const MINUTE = 60_000
|
|
6
|
+
/** The status bar redraws at most this often, however fast the clock runs. */
|
|
7
|
+
const FASTEST = 16
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The status bar's time: the phone's clock (the clock plugin), in its time zone and 12- or 24-hour clock (the locale
|
|
11
|
+
* plugin). It redraws when the phone's minute changes, which comes sooner the faster the clock runs, and at once when
|
|
12
|
+
* either plugin's state changes.
|
|
13
|
+
*/
|
|
14
|
+
export function useStatusTime(store: PluginStore): string {
|
|
15
|
+
const [count, redraw] = useReducer((value: number) => value + 1, 0)
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const removals = [store.subscribe('clock', redraw), store.subscribe('locale', redraw)]
|
|
18
|
+
return () => removals.forEach((remove) => remove())
|
|
19
|
+
}, [store])
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const now = phoneNow()
|
|
22
|
+
const delay = realDelayUntil(now - (((now % MINUTE) + MINUTE) % MINUTE) + MINUTE, clockState())
|
|
23
|
+
if (delay === null) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
// Capped at a minute, so a computer that slept catches up.
|
|
27
|
+
const timer = setTimeout(redraw, Math.min(Math.max(delay, FASTEST), MINUTE))
|
|
28
|
+
return () => clearTimeout(timer)
|
|
29
|
+
}, [count])
|
|
30
|
+
return statusBarTime(phoneNow(), phoneTimeZone(), phoneUses24HourClock())
|
|
31
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltips for the shell's icon buttons (ported from ios-keyboard). Any element with `data-tooltip` shows it on hover or keyboard focus, below
|
|
3
|
+
* the element, or to its right with `data-tooltip-side="right"`. The tooltip lives on the page's body, so a panel's
|
|
4
|
+
* edge cannot clip it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SHOW_DELAY_MS = 350
|
|
8
|
+
/** After a tooltip hides, another one shows straight away for this long, so moving along a row reads quickly. */
|
|
9
|
+
const WARM_MS = 600
|
|
10
|
+
const GAP = 8
|
|
11
|
+
const EDGE = 8
|
|
12
|
+
|
|
13
|
+
export function installTooltips(document: Document): () => void {
|
|
14
|
+
const tip = document.createElement('div')
|
|
15
|
+
tip.className = 'ws-tooltip'
|
|
16
|
+
tip.setAttribute('role', 'tooltip')
|
|
17
|
+
tip.hidden = true
|
|
18
|
+
document.body.append(tip)
|
|
19
|
+
|
|
20
|
+
let current: HTMLElement | null = null
|
|
21
|
+
let showTimer = 0
|
|
22
|
+
let warmUntil = 0
|
|
23
|
+
|
|
24
|
+
const place = (element: HTMLElement) => {
|
|
25
|
+
const view = document.defaultView!
|
|
26
|
+
const rect = element.getBoundingClientRect()
|
|
27
|
+
const box = tip.getBoundingClientRect()
|
|
28
|
+
let left: number
|
|
29
|
+
let top: number
|
|
30
|
+
if (element.dataset.tooltipSide === 'right') {
|
|
31
|
+
left = rect.right + GAP
|
|
32
|
+
top = rect.top + rect.height / 2 - box.height / 2
|
|
33
|
+
} else {
|
|
34
|
+
left = rect.left + rect.width / 2 - box.width / 2
|
|
35
|
+
top = rect.bottom + GAP
|
|
36
|
+
if (top + box.height > view.innerHeight - EDGE) {
|
|
37
|
+
top = rect.top - GAP - box.height
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
tip.style.left = `${Math.max(EDGE, Math.min(left, view.innerWidth - box.width - EDGE))}px`
|
|
41
|
+
tip.style.top = `${Math.max(EDGE, top)}px`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const show = (element: HTMLElement) => {
|
|
45
|
+
tip.textContent = element.dataset.tooltip ?? ''
|
|
46
|
+
tip.hidden = false
|
|
47
|
+
place(element)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hide = () => {
|
|
51
|
+
window.clearTimeout(showTimer)
|
|
52
|
+
if (!tip.hidden) {
|
|
53
|
+
warmUntil = performance.now() + WARM_MS
|
|
54
|
+
}
|
|
55
|
+
tip.hidden = true
|
|
56
|
+
current = null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const enter = (target: EventTarget | null) => {
|
|
60
|
+
const element = target instanceof Element ? target.closest<HTMLElement>('[data-tooltip]') : null
|
|
61
|
+
if (element === current) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
hide()
|
|
65
|
+
if (element === null || element.dataset.tooltip === '') {
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
current = element
|
|
69
|
+
if (performance.now() < warmUntil) {
|
|
70
|
+
show(element)
|
|
71
|
+
} else {
|
|
72
|
+
showTimer = window.setTimeout(() => show(element), SHOW_DELAY_MS)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const onOver = (event: PointerEvent) => enter(event.target)
|
|
77
|
+
const onFocus = (event: FocusEvent) => {
|
|
78
|
+
if (event.target instanceof HTMLElement && event.target.matches(':focus-visible')) {
|
|
79
|
+
enter(event.target)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const onLeave = (event: PointerEvent) => {
|
|
83
|
+
if (current !== null && !(event.relatedTarget instanceof Node && current.contains(event.relatedTarget))) {
|
|
84
|
+
hide()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
document.addEventListener('pointerover', onOver)
|
|
89
|
+
document.addEventListener('pointerout', onLeave)
|
|
90
|
+
document.addEventListener('pointerdown', hide, true)
|
|
91
|
+
document.addEventListener('focusin', onFocus)
|
|
92
|
+
document.addEventListener('focusout', hide)
|
|
93
|
+
window.addEventListener('scroll', hide, true)
|
|
94
|
+
return () => {
|
|
95
|
+
hide()
|
|
96
|
+
tip.remove()
|
|
97
|
+
document.removeEventListener('pointerover', onOver)
|
|
98
|
+
document.removeEventListener('pointerout', onLeave)
|
|
99
|
+
document.removeEventListener('pointerdown', hide, true)
|
|
100
|
+
document.removeEventListener('focusin', onFocus)
|
|
101
|
+
document.removeEventListener('focusout', hide)
|
|
102
|
+
window.removeEventListener('scroll', hide, true)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module 'virtual:web-sim/app-config' {
|
|
4
|
+
export const mode: 'router' | 'entry'
|
|
5
|
+
/** Root-relative, with a trailing slash: `/src/app/`. */
|
|
6
|
+
export const routesDir: string | null
|
|
7
|
+
export const routes: Record<string, unknown> | null
|
|
8
|
+
export const loadEntry: (() => Promise<{ default?: unknown }>) | null
|
|
9
|
+
/** expo-router, imported only by an app that uses it: an app without it has nothing to resolve. */
|
|
10
|
+
export const loadRouter: (() => Promise<typeof import('expo-router')>) | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'virtual:web-sim/sim-config' {
|
|
14
|
+
import type { Device } from '../devices/types.ts'
|
|
15
|
+
import type { AppInfo } from '../runtime/index.ts'
|
|
16
|
+
import type { ShellPlugin } from '../plugin/types.ts'
|
|
17
|
+
export const projectName: string
|
|
18
|
+
export const appInfo: AppInfo
|
|
19
|
+
export const devices: Device[]
|
|
20
|
+
export const defaultDevice: string
|
|
21
|
+
/** The shell modules of the plugins active for this app. */
|
|
22
|
+
export const plugins: ShellPlugin[]
|
|
23
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import type { Device } from './types.ts'
|
|
2
|
+
|
|
3
|
+
const GB = 1024 ** 3
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The built-in devices. Sizes come from each device's screen resolution divided by its pixel ratio; insets are what
|
|
7
|
+
* the OS reports to apps. Projects add their own through `devices` in `web-sim.config.ts`.
|
|
8
|
+
*/
|
|
9
|
+
export const DEVICES: Device[] = [
|
|
10
|
+
{
|
|
11
|
+
id: 'iphone-17-pro',
|
|
12
|
+
label: 'iPhone 17 Pro',
|
|
13
|
+
platform: 'ios',
|
|
14
|
+
osVersion: '26.0',
|
|
15
|
+
screen: { width: 402, height: 874 },
|
|
16
|
+
pixelRatio: 3,
|
|
17
|
+
cornerRadius: 62,
|
|
18
|
+
cutout: { kind: 'island', width: 125, height: 37, top: 11 },
|
|
19
|
+
insets: {
|
|
20
|
+
portrait: { top: 62, right: 0, bottom: 34, left: 0 },
|
|
21
|
+
landscape: { top: 0, right: 62, bottom: 21, left: 62 },
|
|
22
|
+
},
|
|
23
|
+
statusBarHeight: 62,
|
|
24
|
+
navigation: 'home-indicator',
|
|
25
|
+
hardware: {
|
|
26
|
+
brand: 'Apple',
|
|
27
|
+
manufacturer: 'Apple',
|
|
28
|
+
modelId: 'iPhone18,1',
|
|
29
|
+
osBuildId: '23A341',
|
|
30
|
+
yearClass: 2025,
|
|
31
|
+
totalMemory: 12 * GB,
|
|
32
|
+
totalStorage: 256 * GB,
|
|
33
|
+
cpuArchitectures: ['arm64e'],
|
|
34
|
+
},
|
|
35
|
+
frame: { bezel: 14, color: '#2b2b2e' },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'iphone-17-pro-max',
|
|
39
|
+
label: 'iPhone 17 Pro Max',
|
|
40
|
+
platform: 'ios',
|
|
41
|
+
osVersion: '26.0',
|
|
42
|
+
screen: { width: 440, height: 956 },
|
|
43
|
+
pixelRatio: 3,
|
|
44
|
+
cornerRadius: 62,
|
|
45
|
+
cutout: { kind: 'island', width: 125, height: 37, top: 11 },
|
|
46
|
+
insets: {
|
|
47
|
+
portrait: { top: 62, right: 0, bottom: 34, left: 0 },
|
|
48
|
+
landscape: { top: 0, right: 62, bottom: 21, left: 62 },
|
|
49
|
+
},
|
|
50
|
+
statusBarHeight: 62,
|
|
51
|
+
navigation: 'home-indicator',
|
|
52
|
+
hardware: {
|
|
53
|
+
brand: 'Apple',
|
|
54
|
+
manufacturer: 'Apple',
|
|
55
|
+
modelId: 'iPhone18,2',
|
|
56
|
+
osBuildId: '23A341',
|
|
57
|
+
yearClass: 2025,
|
|
58
|
+
totalMemory: 12 * GB,
|
|
59
|
+
totalStorage: 256 * GB,
|
|
60
|
+
cpuArchitectures: ['arm64e'],
|
|
61
|
+
},
|
|
62
|
+
frame: { bezel: 14, color: '#c9c2b8' },
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'iphone-se',
|
|
66
|
+
label: 'iPhone SE',
|
|
67
|
+
platform: 'ios',
|
|
68
|
+
osVersion: '26.0',
|
|
69
|
+
screen: { width: 375, height: 667 },
|
|
70
|
+
pixelRatio: 2,
|
|
71
|
+
cornerRadius: 0,
|
|
72
|
+
cutout: { kind: 'none' },
|
|
73
|
+
insets: {
|
|
74
|
+
portrait: { top: 20, right: 0, bottom: 0, left: 0 },
|
|
75
|
+
landscape: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
76
|
+
},
|
|
77
|
+
statusBarHeight: 20,
|
|
78
|
+
navigation: 'home-button',
|
|
79
|
+
hardware: {
|
|
80
|
+
brand: 'Apple',
|
|
81
|
+
manufacturer: 'Apple',
|
|
82
|
+
modelName: 'iPhone SE (3rd generation)',
|
|
83
|
+
modelId: 'iPhone14,6',
|
|
84
|
+
osBuildId: '23A341',
|
|
85
|
+
yearClass: 2022,
|
|
86
|
+
totalMemory: 4 * GB,
|
|
87
|
+
totalStorage: 64 * GB,
|
|
88
|
+
cpuArchitectures: ['arm64e'],
|
|
89
|
+
},
|
|
90
|
+
frame: { bezel: 16, color: '#1d1d1f', chin: 100 },
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'pixel-9',
|
|
94
|
+
label: 'Pixel 9',
|
|
95
|
+
platform: 'android',
|
|
96
|
+
osVersion: '35',
|
|
97
|
+
screen: { width: 412, height: 923 },
|
|
98
|
+
pixelRatio: 2.625,
|
|
99
|
+
cornerRadius: 46,
|
|
100
|
+
cutout: { kind: 'punch-hole', diameter: 26, top: 14 },
|
|
101
|
+
insets: {
|
|
102
|
+
portrait: { top: 52, right: 0, bottom: 24, left: 0 },
|
|
103
|
+
landscape: { top: 0, right: 0, bottom: 24, left: 52 },
|
|
104
|
+
},
|
|
105
|
+
statusBarHeight: 52,
|
|
106
|
+
navigation: 'gesture',
|
|
107
|
+
hardware: {
|
|
108
|
+
brand: 'google',
|
|
109
|
+
manufacturer: 'Google',
|
|
110
|
+
modelName: 'Pixel 9',
|
|
111
|
+
designName: 'tokay',
|
|
112
|
+
productName: 'tokay',
|
|
113
|
+
osRelease: '15',
|
|
114
|
+
osBuildId: 'AP4A.250205.002',
|
|
115
|
+
osBuildFingerprint: 'google/tokay/tokay:15/AP4A.250205.002/12650793:user/release-keys',
|
|
116
|
+
yearClass: 2024,
|
|
117
|
+
totalMemory: 12 * GB,
|
|
118
|
+
totalStorage: 128 * GB,
|
|
119
|
+
cpuArchitectures: ['arm64-v8a'],
|
|
120
|
+
},
|
|
121
|
+
frame: { bezel: 12, color: '#3a3d40' },
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'pixel-9-buttons',
|
|
125
|
+
label: 'Pixel 9 (3-button)',
|
|
126
|
+
platform: 'android',
|
|
127
|
+
osVersion: '35',
|
|
128
|
+
screen: { width: 412, height: 923 },
|
|
129
|
+
pixelRatio: 2.625,
|
|
130
|
+
cornerRadius: 46,
|
|
131
|
+
cutout: { kind: 'punch-hole', diameter: 26, top: 14 },
|
|
132
|
+
insets: {
|
|
133
|
+
portrait: { top: 52, right: 0, bottom: 48, left: 0 },
|
|
134
|
+
landscape: { top: 0, right: 48, bottom: 0, left: 52 },
|
|
135
|
+
},
|
|
136
|
+
statusBarHeight: 52,
|
|
137
|
+
navigation: 'three-button',
|
|
138
|
+
hardware: {
|
|
139
|
+
brand: 'google',
|
|
140
|
+
manufacturer: 'Google',
|
|
141
|
+
modelName: 'Pixel 9',
|
|
142
|
+
designName: 'tokay',
|
|
143
|
+
productName: 'tokay',
|
|
144
|
+
osRelease: '15',
|
|
145
|
+
osBuildId: 'AP4A.250205.002',
|
|
146
|
+
osBuildFingerprint: 'google/tokay/tokay:15/AP4A.250205.002/12650793:user/release-keys',
|
|
147
|
+
yearClass: 2024,
|
|
148
|
+
totalMemory: 12 * GB,
|
|
149
|
+
totalStorage: 128 * GB,
|
|
150
|
+
cpuArchitectures: ['arm64-v8a'],
|
|
151
|
+
},
|
|
152
|
+
frame: { bezel: 12, color: '#3a3d40' },
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
id: 'galaxy-s25',
|
|
156
|
+
label: 'Galaxy S25',
|
|
157
|
+
platform: 'android',
|
|
158
|
+
osVersion: '35',
|
|
159
|
+
screen: { width: 360, height: 780 },
|
|
160
|
+
pixelRatio: 3,
|
|
161
|
+
cornerRadius: 40,
|
|
162
|
+
cutout: { kind: 'punch-hole', diameter: 22, top: 12 },
|
|
163
|
+
insets: {
|
|
164
|
+
portrait: { top: 44, right: 0, bottom: 24, left: 0 },
|
|
165
|
+
landscape: { top: 0, right: 0, bottom: 24, left: 44 },
|
|
166
|
+
},
|
|
167
|
+
statusBarHeight: 44,
|
|
168
|
+
navigation: 'gesture',
|
|
169
|
+
hardware: {
|
|
170
|
+
brand: 'samsung',
|
|
171
|
+
manufacturer: 'samsung',
|
|
172
|
+
modelName: 'SM-S931B',
|
|
173
|
+
designName: 'pa1q',
|
|
174
|
+
productName: 'pa1qxxx',
|
|
175
|
+
osRelease: '15',
|
|
176
|
+
osBuildId: 'AP3A.240905.015.A2',
|
|
177
|
+
osBuildFingerprint: 'samsung/pa1qxxx/pa1q:15/AP3A.240905.015.A2/S931BXXU1AYA1:user/release-keys',
|
|
178
|
+
yearClass: 2025,
|
|
179
|
+
totalMemory: 12 * GB,
|
|
180
|
+
totalStorage: 128 * GB,
|
|
181
|
+
cpuArchitectures: ['arm64-v8a', 'armeabi-v7a', 'armeabi'],
|
|
182
|
+
},
|
|
183
|
+
frame: { bezel: 10, color: '#22252a' },
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: 'iphone-resizable',
|
|
187
|
+
label: 'iPhone (resizable)',
|
|
188
|
+
platform: 'ios',
|
|
189
|
+
osVersion: '26.0',
|
|
190
|
+
screen: { width: 393, height: 852 },
|
|
191
|
+
pixelRatio: 3,
|
|
192
|
+
cornerRadius: 55,
|
|
193
|
+
cutout: { kind: 'island', width: 125, height: 37, top: 11 },
|
|
194
|
+
insets: {
|
|
195
|
+
portrait: { top: 59, right: 0, bottom: 34, left: 0 },
|
|
196
|
+
landscape: { top: 0, right: 59, bottom: 21, left: 59 },
|
|
197
|
+
},
|
|
198
|
+
statusBarHeight: 59,
|
|
199
|
+
navigation: 'home-indicator',
|
|
200
|
+
resizable: { min: { width: 280, height: 400 }, max: { width: 1032, height: 1376 } },
|
|
201
|
+
frame: { bezel: 8, color: '#2b2b2e' },
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: 'android-resizable',
|
|
205
|
+
label: 'Android (resizable)',
|
|
206
|
+
platform: 'android',
|
|
207
|
+
osVersion: '35',
|
|
208
|
+
screen: { width: 412, height: 915 },
|
|
209
|
+
pixelRatio: 2.625,
|
|
210
|
+
cornerRadius: 40,
|
|
211
|
+
cutout: { kind: 'punch-hole', diameter: 22, top: 15 },
|
|
212
|
+
insets: {
|
|
213
|
+
portrait: { top: 52, right: 0, bottom: 24, left: 0 },
|
|
214
|
+
landscape: { top: 0, right: 0, bottom: 24, left: 52 },
|
|
215
|
+
},
|
|
216
|
+
statusBarHeight: 52,
|
|
217
|
+
navigation: 'gesture',
|
|
218
|
+
resizable: { min: { width: 280, height: 400 }, max: { width: 1032, height: 1376 } },
|
|
219
|
+
frame: { bezel: 8, color: '#22252a' },
|
|
220
|
+
},
|
|
221
|
+
]
|
|
222
|
+
|
|
223
|
+
export const DEFAULT_DEVICE_ID = 'iphone-17-pro'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export type Platform = 'ios' | 'android'
|
|
2
|
+
|
|
3
|
+
export type Orientation = 'portrait' | 'landscape'
|
|
4
|
+
|
|
5
|
+
export type Appearance = 'light' | 'dark'
|
|
6
|
+
|
|
7
|
+
export type Insets = { top: number; right: number; bottom: number; left: number }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What cuts into the top of the screen in portrait. Sizes are in points (iOS) or dp (Android).
|
|
11
|
+
*/
|
|
12
|
+
export type Cutout =
|
|
13
|
+
| { kind: 'island'; width: number; height: number; top: number }
|
|
14
|
+
| { kind: 'notch'; width: number; height: number }
|
|
15
|
+
| { kind: 'punch-hole'; diameter: number; top: number }
|
|
16
|
+
| { kind: 'none' }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What the device reports about itself, as `expo-device` and `expo-constants` give it on that phone. Optional: a
|
|
20
|
+
* device without it reports its label as the model, and generic values for the rest.
|
|
21
|
+
*/
|
|
22
|
+
export type DeviceHardware = {
|
|
23
|
+
/** `Build.BRAND` on Android ('google'), 'Apple' on iOS. */
|
|
24
|
+
brand: string
|
|
25
|
+
manufacturer: string
|
|
26
|
+
/** The marketing name: 'iPhone 17 Pro', or Android's `Build.MODEL`. Defaults to the label. */
|
|
27
|
+
modelName?: string
|
|
28
|
+
/** iOS's machine identifier ('iPhone18,1'). */
|
|
29
|
+
modelId?: string
|
|
30
|
+
/** Android's `Build.DEVICE`, the board's code name ('tokay'). */
|
|
31
|
+
designName?: string
|
|
32
|
+
/** Android's `Build.PRODUCT`. */
|
|
33
|
+
productName?: string
|
|
34
|
+
/** The OS's user-facing version when `osVersion` is an API level: '15' for Android API 35. */
|
|
35
|
+
osRelease?: string
|
|
36
|
+
/** The OS build: '23A341' on iOS, `Build.DISPLAY` on Android. */
|
|
37
|
+
osBuildId: string
|
|
38
|
+
/** Android's `Build.FINGERPRINT`. */
|
|
39
|
+
osBuildFingerprint?: string
|
|
40
|
+
/** The year the device's hardware is typical of. */
|
|
41
|
+
yearClass: number
|
|
42
|
+
/** RAM, in bytes. */
|
|
43
|
+
totalMemory: number
|
|
44
|
+
/** Storage, in bytes. */
|
|
45
|
+
totalStorage: number
|
|
46
|
+
cpuArchitectures: string[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type Device = {
|
|
50
|
+
id: string
|
|
51
|
+
label: string
|
|
52
|
+
platform: Platform
|
|
53
|
+
/** The OS version the device reports, as `Platform.Version` gives it: '27.0' on iOS, the API level on Android. */
|
|
54
|
+
osVersion: string
|
|
55
|
+
/** The screen in portrait, in points (iOS) or dp (Android). 1 CSS pixel is 1 point. */
|
|
56
|
+
screen: { width: number; height: number }
|
|
57
|
+
pixelRatio: number
|
|
58
|
+
/** The screen's corner radius, in points. */
|
|
59
|
+
cornerRadius: number
|
|
60
|
+
cutout: Cutout
|
|
61
|
+
/** The safe-area insets the OS reports, per orientation. Landscape is rotated with the cutout on the left. */
|
|
62
|
+
insets: Record<Orientation, Insets>
|
|
63
|
+
/** The status bar's height in portrait. In landscape iOS hides it on devices with a cutout. */
|
|
64
|
+
statusBarHeight: number
|
|
65
|
+
/** How the OS is navigated: the iOS home indicator or home button, or Android's gesture bar or three buttons. */
|
|
66
|
+
navigation: 'home-indicator' | 'home-button' | 'gesture' | 'three-button'
|
|
67
|
+
/** What the device reports about its hardware and OS build. */
|
|
68
|
+
hardware?: DeviceHardware
|
|
69
|
+
/**
|
|
70
|
+
* A generic device whose screen can be resized, as Chrome's responsive mode: by dragging its edges or typing a
|
|
71
|
+
* size. `screen` is its starting size; the bounds are in portrait points.
|
|
72
|
+
*/
|
|
73
|
+
resizable?: { min: { width: number; height: number }; max: { width: number; height: number } }
|
|
74
|
+
/** How the drawn frame looks. */
|
|
75
|
+
frame: {
|
|
76
|
+
/** The bezel's width around the screen, in points. */
|
|
77
|
+
bezel: number
|
|
78
|
+
/** The body colour. */
|
|
79
|
+
color: string
|
|
80
|
+
/** Extra chin and forehead, for devices with a home button. */
|
|
81
|
+
chin?: number
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { readBundledFonts } from './fonts.ts'
|
|
5
|
+
import type { AppInfo, FirebaseOptions, UserInterfaceStyle } from '../runtime/index.ts'
|
|
6
|
+
|
|
7
|
+
/** Config plugin options that set iOS usage descriptions, by plugin. */
|
|
8
|
+
const PLUGIN_USAGE_KEYS: Record<string, Record<string, string>> = {
|
|
9
|
+
'expo-camera': { cameraPermission: 'NSCameraUsageDescription', microphonePermission: 'NSMicrophoneUsageDescription' },
|
|
10
|
+
'expo-image-picker': { photosPermission: 'NSPhotoLibraryUsageDescription', cameraPermission: 'NSCameraUsageDescription', microphonePermission: 'NSMicrophoneUsageDescription' },
|
|
11
|
+
'expo-media-library': { photosPermission: 'NSPhotoLibraryUsageDescription', savePhotosPermission: 'NSPhotoLibraryAddUsageDescription' },
|
|
12
|
+
'expo-location': {
|
|
13
|
+
locationWhenInUsePermission: 'NSLocationWhenInUseUsageDescription',
|
|
14
|
+
locationAlwaysAndWhenInUsePermission: 'NSLocationAlwaysAndWhenInUseUsageDescription',
|
|
15
|
+
},
|
|
16
|
+
'expo-contacts': { contactsPermission: 'NSContactsUsageDescription' },
|
|
17
|
+
'expo-calendar': { calendarPermission: 'NSCalendarsUsageDescription', remindersPermission: 'NSRemindersUsageDescription' },
|
|
18
|
+
'expo-local-authentication': { faceIDPermission: 'NSFaceIDUsageDescription' },
|
|
19
|
+
'expo-tracking-transparency': { userTrackingPermission: 'NSUserTrackingUsageDescription' },
|
|
20
|
+
'expo-sensors': { motionPermission: 'NSMotionUsageDescription' },
|
|
21
|
+
'expo-audio': { microphonePermission: 'NSMicrophoneUsageDescription' },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Plugin = string | [string, Record<string, unknown>]
|
|
25
|
+
|
|
26
|
+
const DYNAMIC_CONFIG_FILES = ['app.config.ts', 'app.config.js', 'app.config.mjs', 'app.config.cjs']
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The app's Expo config, as Expo's CLI resolves it: a dynamic `app.config.ts` / `.js` through the project's own
|
|
30
|
+
* `expo/config`, with `app.json` passed to it. Without one, `app.json` as it is.
|
|
31
|
+
*/
|
|
32
|
+
function readExpoConfig(root: string): Record<string, any> {
|
|
33
|
+
if (DYNAMIC_CONFIG_FILES.some((name) => existsSync(path.join(root, name)))) {
|
|
34
|
+
try {
|
|
35
|
+
const require = createRequire(path.join(root, 'package.json'))
|
|
36
|
+
const { getConfig } = require('expo/config') as {
|
|
37
|
+
getConfig: (root: string, options: Record<string, unknown>) => { exp: Record<string, any> }
|
|
38
|
+
}
|
|
39
|
+
return getConfig(root, { skipSDKVersionRequirement: true, isPublicConfig: true }).exp
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.warn(`web-sim: could not read the app's dynamic config, so app.json is used: ${(error as Error).message}`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const file = path.join(root, 'app.json')
|
|
45
|
+
const json = existsSync(file) ? (JSON.parse(readFileSync(file, 'utf8')) as { expo?: Record<string, unknown> }) : {}
|
|
46
|
+
return (json.expo ?? json) as Record<string, any>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* What the simulator draws from the app's Expo config: the app's name in system prompts, its splash screen, and the
|
|
51
|
+
* usage descriptions iOS quotes in permission prompts.
|
|
52
|
+
*/
|
|
53
|
+
export function readAppInfo(root: string, fallbackName: string): AppInfo {
|
|
54
|
+
const expo = readExpoConfig(root)
|
|
55
|
+
const plugins: Plugin[] = Array.isArray(expo.plugins) ? expo.plugins : []
|
|
56
|
+
const pluginOptions = (name: string) => {
|
|
57
|
+
const entry = plugins.find((plugin) => (Array.isArray(plugin) ? plugin[0] : plugin) === name)
|
|
58
|
+
return Array.isArray(entry) ? entry[1] : null
|
|
59
|
+
}
|
|
60
|
+
const asset = (value: unknown) => (typeof value === 'string' ? `/${path.posix.normalize(value.replace(/^\.\//, ''))}` : undefined)
|
|
61
|
+
|
|
62
|
+
const splashPlugin = pluginOptions('expo-splash-screen') as Record<string, any> | null
|
|
63
|
+
const splashConfig = splashPlugin ?? (expo.splash as Record<string, any> | undefined) ?? null
|
|
64
|
+
const splash =
|
|
65
|
+
splashConfig === null
|
|
66
|
+
? null
|
|
67
|
+
: {
|
|
68
|
+
backgroundColor: splashConfig.backgroundColor ?? '#ffffff',
|
|
69
|
+
darkBackgroundColor: splashConfig.dark?.backgroundColor,
|
|
70
|
+
image: asset(splashConfig.image),
|
|
71
|
+
imageWidth: splashConfig.imageWidth ?? 200,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const usageDescriptions: Record<string, string> = { ...(expo.ios?.infoPlist ?? {}) }
|
|
75
|
+
for (const [plugin, keys] of Object.entries(PLUGIN_USAGE_KEYS)) {
|
|
76
|
+
const options = pluginOptions(plugin)
|
|
77
|
+
for (const [option, key] of Object.entries(keys)) {
|
|
78
|
+
if (typeof options?.[option] === 'string') {
|
|
79
|
+
usageDescriptions[key] = options[option] as string
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
name: typeof expo.name === 'string' ? expo.name : fallbackName,
|
|
85
|
+
slug: typeof expo.slug === 'string' ? expo.slug : fallbackName,
|
|
86
|
+
version: typeof expo.version === 'string' ? expo.version : '1.0.0',
|
|
87
|
+
icon: asset(expo.icon),
|
|
88
|
+
bundleId: expo.ios?.bundleIdentifier ?? expo.android?.package ?? `com.example.${String(expo.slug ?? fallbackName).replace(/[^a-z0-9]/gi, '')}`,
|
|
89
|
+
splash,
|
|
90
|
+
usageDescriptions: Object.fromEntries(Object.entries(usageDescriptions).filter(([key, value]) => key.endsWith('UsageDescription') && typeof value === 'string')),
|
|
91
|
+
config: expo,
|
|
92
|
+
googleServices: readGoogleServices(root, expo),
|
|
93
|
+
dependencies: readDependencies(root),
|
|
94
|
+
userInterfaceStyle: readUserInterfaceStyle(root, expo),
|
|
95
|
+
fonts: readBundledFonts(root, expo),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const STYLES = new Set(['light', 'dark', 'automatic'])
|
|
100
|
+
const style = (value: unknown): UserInterfaceStyle | undefined => (STYLES.has(value as string) ? (value as UserInterfaceStyle) : undefined)
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The appearance the app pins, as a native build of it would. On iOS, Expo's prebuild always writes
|
|
104
|
+
* `UIUserInterfaceStyle` from `ios.userInterfaceStyle`, then `userInterfaceStyle`, else `light`: an Expo app with
|
|
105
|
+
* neither stays light in dark mode, keyboard and alerts too. On Android only `expo-system-ui` applies it, and without
|
|
106
|
+
* a value the app follows the device. An app without `expo` follows the device.
|
|
107
|
+
*/
|
|
108
|
+
function readUserInterfaceStyle(root: string, expo: Record<string, any>): AppInfo['userInterfaceStyle'] {
|
|
109
|
+
const dependencies = readDependencies(root)
|
|
110
|
+
const isExpo = dependencies.includes('expo')
|
|
111
|
+
const shared = style(expo.userInterfaceStyle)
|
|
112
|
+
const systemUi = dependencies.includes('expo-system-ui')
|
|
113
|
+
return {
|
|
114
|
+
ios: isExpo ? (style(expo.ios?.userInterfaceStyle) ?? shared ?? 'light') : 'automatic',
|
|
115
|
+
android: systemUi ? (style(expo.android?.userInterfaceStyle) ?? shared ?? 'automatic') : 'automatic',
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function readGoogleServices(root: string, expo: Record<string, any>): AppInfo['googleServices'] {
|
|
120
|
+
const read = (file: unknown) => {
|
|
121
|
+
const full = typeof file === 'string' ? path.resolve(root, file) : null
|
|
122
|
+
return full !== null && existsSync(full) ? readFileSync(full, 'utf8') : null
|
|
123
|
+
}
|
|
124
|
+
const plist = read(expo.ios?.googleServicesFile)
|
|
125
|
+
const json = read(expo.android?.googleServicesFile)
|
|
126
|
+
try {
|
|
127
|
+
return {
|
|
128
|
+
ios: plist === null ? undefined : firebaseOptionsFromPlist(plist),
|
|
129
|
+
android: json === null ? undefined : firebaseOptionsFromJson(JSON.parse(json), expo.android?.package),
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn(`web-sim: could not read the app's Firebase config: ${(error as Error).message}`)
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const PLIST_KEYS: Record<string, keyof FirebaseOptions> = {
|
|
138
|
+
API_KEY: 'apiKey',
|
|
139
|
+
GOOGLE_APP_ID: 'appId',
|
|
140
|
+
PROJECT_ID: 'projectId',
|
|
141
|
+
GCM_SENDER_ID: 'messagingSenderId',
|
|
142
|
+
STORAGE_BUCKET: 'storageBucket',
|
|
143
|
+
DATABASE_URL: 'databaseURL',
|
|
144
|
+
CLIENT_ID: 'clientId',
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `GoogleService-Info.plist` holds only string values, so its key/string pairs are all there is to read. */
|
|
148
|
+
function firebaseOptionsFromPlist(plist: string): FirebaseOptions {
|
|
149
|
+
const options: FirebaseOptions = {}
|
|
150
|
+
for (const [, key, value] of plist.matchAll(/<key>([^<]+)<\/key>\s*<string>([^<]*)<\/string>/g)) {
|
|
151
|
+
const option = PLIST_KEYS[key]
|
|
152
|
+
if (option !== undefined) {
|
|
153
|
+
options[option] = value
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return options
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type GoogleServicesJson = {
|
|
160
|
+
project_info?: { project_id?: string; project_number?: string; storage_bucket?: string; firebase_url?: string }
|
|
161
|
+
client?: {
|
|
162
|
+
client_info?: { mobilesdk_app_id?: string; android_client_info?: { package_name?: string } }
|
|
163
|
+
api_key?: { current_key?: string }[]
|
|
164
|
+
oauth_client?: { client_id?: string; client_type?: number }[]
|
|
165
|
+
}[]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function firebaseOptionsFromJson(json: GoogleServicesJson, packageName: unknown): FirebaseOptions {
|
|
169
|
+
const client = json.client?.find((entry) => entry.client_info?.android_client_info?.package_name === packageName) ?? json.client?.[0]
|
|
170
|
+
return {
|
|
171
|
+
apiKey: client?.api_key?.[0]?.current_key,
|
|
172
|
+
appId: client?.client_info?.mobilesdk_app_id,
|
|
173
|
+
projectId: json.project_info?.project_id,
|
|
174
|
+
messagingSenderId: json.project_info?.project_number,
|
|
175
|
+
storageBucket: json.project_info?.storage_bucket,
|
|
176
|
+
databaseURL: json.project_info?.firebase_url,
|
|
177
|
+
clientId: client?.oauth_client?.find((entry) => entry.client_type === 3)?.client_id,
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function readDependencies(root: string): string[] {
|
|
182
|
+
const file = path.join(root, 'package.json')
|
|
183
|
+
if (!existsSync(file)) {
|
|
184
|
+
return []
|
|
185
|
+
}
|
|
186
|
+
const json = JSON.parse(readFileSync(file, 'utf8')) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
|
|
187
|
+
return Object.keys({ ...json.dependencies, ...json.devDependencies }).sort()
|
|
188
|
+
}
|