@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,531 @@
|
|
|
1
|
+
import { ArrowUUpLeftIcon, DeviceMobileIcon, MoonIcon, PictureInPictureIcon, ShieldSlashIcon, SidebarSimpleIcon, SunIcon } from '@phosphor-icons/react'
|
|
2
|
+
import { OrientationLockIcon, RotateDeviceIcon } from './icons.tsx'
|
|
3
|
+
import { createPortal, flushSync } from 'react-dom'
|
|
4
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
5
|
+
import { projectName } from 'virtual:web-sim/sim-config'
|
|
6
|
+
import type { Device, Platform } from '../../devices/types.ts'
|
|
7
|
+
import { pressBack } from '../../runtime/index.ts'
|
|
8
|
+
import { frameLayout, screenSize } from './geometry.ts'
|
|
9
|
+
import type { HostStore } from './host.ts'
|
|
10
|
+
import { POPOUT_PADDING, usePopout } from './popout.ts'
|
|
11
|
+
import { PluginOverlays } from './PluginOverlays.tsx'
|
|
12
|
+
import { PluginPanels } from './PluginPanels.tsx'
|
|
13
|
+
import { ResizeHandles, SizeFields } from './Resizer.tsx'
|
|
14
|
+
import { useStatusTime } from './statusTime.ts'
|
|
15
|
+
import { useBackdropTone } from './backdrop.ts'
|
|
16
|
+
import { SystemBars } from './SystemBars.tsx'
|
|
17
|
+
import { SystemOverlay } from './SystemOverlay.tsx'
|
|
18
|
+
import { LogButton, LogDrawer } from './LogDrawer.tsx'
|
|
19
|
+
import { CookiesButton } from './Cookies.tsx'
|
|
20
|
+
import { ResetButton } from './ResetApp.tsx'
|
|
21
|
+
|
|
22
|
+
const PATH_KEY = 'web-sim:app-path'
|
|
23
|
+
const STAGE_PADDING = 48
|
|
24
|
+
const PANELS_KEY = 'web-sim:panels-open'
|
|
25
|
+
const PANELS_WIDTH = 300
|
|
26
|
+
const LOG_OPEN_KEY = 'web-sim:log-open'
|
|
27
|
+
const LOG_HEIGHT_KEY = 'web-sim:log-height'
|
|
28
|
+
const TOOLBAR_HEIGHT = 52
|
|
29
|
+
/** Where the status bar's content is read, as fractions of the bar: under the time, and under the icons. */
|
|
30
|
+
const STATUS_BAR_POINTS = [
|
|
31
|
+
[0.12, 0.5],
|
|
32
|
+
[0.18, 0.5],
|
|
33
|
+
[0.24, 0.5],
|
|
34
|
+
[0.76, 0.5],
|
|
35
|
+
[0.82, 0.5],
|
|
36
|
+
[0.88, 0.5],
|
|
37
|
+
] as const
|
|
38
|
+
|
|
39
|
+
export function Shell({ host }: { host: HostStore }) {
|
|
40
|
+
const state = useSyncExternalStore(host.subscribe, host.getState)
|
|
41
|
+
const statusBar = useSyncExternalStore(host.subscribe, host.getStatusBar)
|
|
42
|
+
const ui = useSyncExternalStore(host.subscribe, host.getUi)
|
|
43
|
+
const pluginVersion = useSyncExternalStore(host.plugins.subscribeAll, () => host.plugins.version)
|
|
44
|
+
const statusItems = useMemo(() => host.plugins.statusBarItems(state), [host, state, pluginVersion])
|
|
45
|
+
const statusTime = useStatusTime(host.plugins)
|
|
46
|
+
const screenEffect = useMemo(() => host.plugins.screenEffect(state), [host, state, pluginVersion])
|
|
47
|
+
const { device, orientation, appearance, appAppearance } = state
|
|
48
|
+
const readyPlatform = usePlatformReady(device.platform)
|
|
49
|
+
const [generation, setGeneration] = useState(0)
|
|
50
|
+
const hasPanels = host.plugins.plugins.some((plugin) => plugin.Panel !== undefined)
|
|
51
|
+
const [panelsOpen, setPanelsOpen] = useState(() => readFlag(PANELS_KEY, true))
|
|
52
|
+
const showPanels = hasPanels && panelsOpen
|
|
53
|
+
const [logOpen, setLogOpen] = useState(() => readFlag(LOG_OPEN_KEY, false))
|
|
54
|
+
const [logHeight, setLogHeight] = useState(() => readNumber(LOG_HEIGHT_KEY, 260))
|
|
55
|
+
const toggleLog = () => {
|
|
56
|
+
setLogOpen(!logOpen)
|
|
57
|
+
writeFlag(LOG_OPEN_KEY, !logOpen)
|
|
58
|
+
}
|
|
59
|
+
const resizeLog = (height: number) => {
|
|
60
|
+
const clamped = Math.round(Math.min(window.innerHeight * 0.7, Math.max(120, height)))
|
|
61
|
+
setLogHeight(clamped)
|
|
62
|
+
try {
|
|
63
|
+
localStorage.setItem(LOG_HEIGHT_KEY, String(clamped))
|
|
64
|
+
} catch {
|
|
65
|
+
// Storage blocked.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const frameRef = useRef<HTMLIFrameElement>(null)
|
|
69
|
+
|
|
70
|
+
const rememberPath = useCallback(() => {
|
|
71
|
+
try {
|
|
72
|
+
const location = frameRef.current?.contentWindow?.location
|
|
73
|
+
if (location !== undefined && location.pathname !== 'blank') {
|
|
74
|
+
sessionStorage.setItem(PATH_KEY, location.pathname + location.search)
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
// The frame is mid-navigation.
|
|
78
|
+
}
|
|
79
|
+
}, [])
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
window.addEventListener('beforeunload', rememberPath)
|
|
83
|
+
return () => window.removeEventListener('beforeunload', rememberPath)
|
|
84
|
+
}, [rememberPath])
|
|
85
|
+
|
|
86
|
+
const changeDevice = (id: string) => {
|
|
87
|
+
rememberPath()
|
|
88
|
+
host.setDevice(id)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const reload = () => {
|
|
92
|
+
rememberPath()
|
|
93
|
+
setGeneration((value) => value + 1)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// A relaunch takes the app's frame away while its work runs (a reset clearing the app's data), so nothing the app
|
|
97
|
+
// does on its way out lands after the clear, and its databases are closed for deleting.
|
|
98
|
+
const [stopped, setStopped] = useState(false)
|
|
99
|
+
useEffect(
|
|
100
|
+
() =>
|
|
101
|
+
host.onRelaunch(async (work) => {
|
|
102
|
+
rememberPath()
|
|
103
|
+
flushSync(() => setStopped(true))
|
|
104
|
+
try {
|
|
105
|
+
await work()
|
|
106
|
+
} finally {
|
|
107
|
+
setGeneration((value) => value + 1)
|
|
108
|
+
setStopped(false)
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
[host, rememberPath],
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const run = readyPlatform === device.platform && !stopped ? `${device.id}:${generation}` : null
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (run !== null) {
|
|
117
|
+
host.startRun()
|
|
118
|
+
}
|
|
119
|
+
}, [host, run])
|
|
120
|
+
|
|
121
|
+
const back = () => {
|
|
122
|
+
const appWindow = frameRef.current?.contentWindow
|
|
123
|
+
if (appWindow) {
|
|
124
|
+
pressBack(appWindow)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const layout = frameLayout(device, orientation)
|
|
129
|
+
const screen = screenSize(device, orientation)
|
|
130
|
+
const { popout, open: popOut, close: bringBack } = usePopout({ host, size: layout.frame, beforeMove: rememberPath })
|
|
131
|
+
const fitScale = useFitScale(
|
|
132
|
+
layout.frame,
|
|
133
|
+
popout !== null
|
|
134
|
+
? { view: popout.window, sidebar: 0, toolbar: 0, padding: POPOUT_PADDING }
|
|
135
|
+
: { view: window, sidebar: showPanels ? PANELS_WIDTH : 0, toolbar: TOOLBAR_HEIGHT + (logOpen ? logHeight : 0), padding: STAGE_PADDING },
|
|
136
|
+
)
|
|
137
|
+
// While a resize drag lasts the scale holds still, so the edge being dragged stays under the pointer.
|
|
138
|
+
const [heldScale, setHeldScale] = useState<number | null>(null)
|
|
139
|
+
const scale = heldScale ?? fitScale
|
|
140
|
+
/** Resizes from a size in the current orientation. */
|
|
141
|
+
const resize = (size: { width: number; height: number }) =>
|
|
142
|
+
host.setScreenSize(orientation === 'portrait' ? size : { width: size.height, height: size.width })
|
|
143
|
+
/** The content colour that follows the app's appearance: light content in dark mode. */
|
|
144
|
+
const schemeContent = appAppearance === 'dark' ? 'light' : 'dark'
|
|
145
|
+
const statusStyle = statusBar.screenStyle ?? statusBar.style
|
|
146
|
+
// iOS's default style (since iOS 17) picks light or dark from the content under the bar, which is read here.
|
|
147
|
+
const statusAdaptive = statusStyle === 'default' && device.platform === 'ios'
|
|
148
|
+
const statusBarRef = useRef<HTMLDivElement>(null)
|
|
149
|
+
const statusTone = useBackdropTone(
|
|
150
|
+
statusBarRef,
|
|
151
|
+
statusAdaptive && !statusBar.hidden && orientation === 'portrait',
|
|
152
|
+
appAppearance === 'dark' ? '#000000' : '#ffffff',
|
|
153
|
+
STATUS_BAR_POINTS,
|
|
154
|
+
)
|
|
155
|
+
const content = statusStyle === 'light' || statusStyle === 'dark' ? statusStyle : statusAdaptive ? (statusTone ?? schemeContent) : schemeContent
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (statusAdaptive && statusTone !== null) {
|
|
158
|
+
host.events.log({
|
|
159
|
+
kind: 'ui.statusBar.color',
|
|
160
|
+
actor: 'system',
|
|
161
|
+
level: 'debug',
|
|
162
|
+
summary: `Status bar: ${statusTone === 'dark' ? 'dark, over light content' : 'light, over dark content'}`,
|
|
163
|
+
data: { content: statusTone },
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
}, [host, statusAdaptive, statusTone])
|
|
167
|
+
const homeIndicatorRef = useRef<HTMLDivElement>(null)
|
|
168
|
+
const homeIndicatorHidden = statusItems.homeIndicator?.hidden ?? false
|
|
169
|
+
const homeIndicatorContent = useBackdropTone(
|
|
170
|
+
homeIndicatorRef,
|
|
171
|
+
// Read while faded out too, so it comes back in the right colour.
|
|
172
|
+
device.navigation === 'home-indicator' && !ui.navigationBar.hidden,
|
|
173
|
+
appAppearance === 'dark' ? '#000000' : '#ffffff',
|
|
174
|
+
)
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (homeIndicatorContent !== null) {
|
|
177
|
+
host.events.log({
|
|
178
|
+
kind: 'ui.homeIndicator.color',
|
|
179
|
+
actor: 'system',
|
|
180
|
+
level: 'debug',
|
|
181
|
+
summary: `Home indicator: ${homeIndicatorContent === 'dark' ? 'dark, over light content' : 'light, over dark content'}`,
|
|
182
|
+
data: { content: homeIndicatorContent },
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
}, [host, homeIndicatorContent])
|
|
186
|
+
|
|
187
|
+
// The device is drawn at `scale` with CSS zoom, not a transform. Zoom reaches into the app's frame as its
|
|
188
|
+
// devicePixelRatio, so the app lays out and snaps its edges to real screen pixels, as Yoga rounds to the phone's
|
|
189
|
+
// pixel grid. A scale transform lays the app out at the browser's own ratio and scales the drawing: an edge lands
|
|
190
|
+
// between two screen pixels and is blended, and what scrolls behind a bar shows through as a hairline at its edge.
|
|
191
|
+
// The slot is the scaled size. It renders in the stage, or in the phone's own window while it is popped out.
|
|
192
|
+
const deviceSlot = (
|
|
193
|
+
<div className="ws-device-slot" style={{ width: layout.frame.width * scale, height: layout.frame.height * scale }}>
|
|
194
|
+
{device.resizable !== undefined && (
|
|
195
|
+
<ResizeHandles
|
|
196
|
+
size={screen}
|
|
197
|
+
scale={scale}
|
|
198
|
+
slot={{ width: layout.frame.width * scale, height: layout.frame.height * scale }}
|
|
199
|
+
onResize={resize}
|
|
200
|
+
onDragChange={(dragging) => setHeldScale(dragging ? scale : null)}
|
|
201
|
+
/>
|
|
202
|
+
)}
|
|
203
|
+
<div
|
|
204
|
+
className="ws-device"
|
|
205
|
+
style={{
|
|
206
|
+
width: layout.frame.width,
|
|
207
|
+
height: layout.frame.height,
|
|
208
|
+
borderRadius: layout.frame.radius,
|
|
209
|
+
background: device.frame.color,
|
|
210
|
+
zoom: scale,
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
{layout.buttons.map((button, index) => (
|
|
214
|
+
<span
|
|
215
|
+
key={index}
|
|
216
|
+
className={`ws-button ws-button-${button.side}`}
|
|
217
|
+
style={{
|
|
218
|
+
[button.side === 'left' || button.side === 'right' ? 'top' : 'left']: button.offset,
|
|
219
|
+
[button.side === 'left' || button.side === 'right' ? 'height' : 'width']: button.length,
|
|
220
|
+
background: device.frame.color,
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
))}
|
|
224
|
+
{layout.homeButton !== null && (
|
|
225
|
+
<span
|
|
226
|
+
className="ws-home-button"
|
|
227
|
+
aria-label="Home"
|
|
228
|
+
style={{
|
|
229
|
+
left: layout.homeButton.x - layout.homeButton.size / 2,
|
|
230
|
+
top: layout.homeButton.y - layout.homeButton.size / 2,
|
|
231
|
+
width: layout.homeButton.size,
|
|
232
|
+
height: layout.homeButton.size,
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
)}
|
|
236
|
+
<div
|
|
237
|
+
className="ws-screen"
|
|
238
|
+
style={{
|
|
239
|
+
left: layout.screen.x,
|
|
240
|
+
top: layout.screen.y,
|
|
241
|
+
width: screen.width,
|
|
242
|
+
height: screen.height,
|
|
243
|
+
borderRadius: layout.screen.radius,
|
|
244
|
+
background: appAppearance === 'dark' ? '#000' : '#fff',
|
|
245
|
+
// Plugins dim or blank the screen (the brightness, auto-lock).
|
|
246
|
+
filter: screenEffect.filter,
|
|
247
|
+
}}
|
|
248
|
+
onPointerDownCapture={host.plugins.hearsPresses ? host.plugins.press : undefined}
|
|
249
|
+
>
|
|
250
|
+
{readyPlatform === device.platform && !stopped && (
|
|
251
|
+
<iframe
|
|
252
|
+
key={`${device.id}:${generation}`}
|
|
253
|
+
ref={frameRef}
|
|
254
|
+
title="App"
|
|
255
|
+
className="ws-app-frame"
|
|
256
|
+
// Absolute, because a popped-out phone's window has no address of its own to resolve against.
|
|
257
|
+
src={new URL(initialPath(), location.href).href}
|
|
258
|
+
allow="clipboard-read; clipboard-write; autoplay; fullscreen"
|
|
259
|
+
// The frame's preferred colour scheme follows its element's `color-scheme`, so `useColorScheme` and
|
|
260
|
+
// `prefers-color-scheme` media queries in the app see the app's appearance and update live.
|
|
261
|
+
style={{ width: screen.width, height: screen.height, colorScheme: appAppearance }}
|
|
262
|
+
// Presses in the app don't bubble out of its frame, so plugins hear them from inside it.
|
|
263
|
+
onLoad={(event) => {
|
|
264
|
+
if (host.plugins.hearsPresses) {
|
|
265
|
+
event.currentTarget.contentWindow?.addEventListener('pointerdown', host.plugins.press, true)
|
|
266
|
+
}
|
|
267
|
+
}}
|
|
268
|
+
/>
|
|
269
|
+
)}
|
|
270
|
+
<PluginOverlays store={host.plugins} sim={state} />
|
|
271
|
+
<SystemBars
|
|
272
|
+
device={device}
|
|
273
|
+
orientation={orientation}
|
|
274
|
+
screen={screen}
|
|
275
|
+
content={content}
|
|
276
|
+
statusBarRef={statusBarRef}
|
|
277
|
+
statusAdaptive={statusAdaptive}
|
|
278
|
+
navigationContent={ui.navigationBar.style === 'light' || ui.navigationBar.style === 'dark' ? ui.navigationBar.style : statusAdaptive ? schemeContent : content}
|
|
279
|
+
navigationHidden={ui.navigationBar.hidden}
|
|
280
|
+
homeIndicator={{ hidden: homeIndicatorHidden, content: homeIndicatorContent, ref: homeIndicatorRef }}
|
|
281
|
+
statusBarHidden={statusBar.hidden}
|
|
282
|
+
items={statusItems}
|
|
283
|
+
time={statusTime}
|
|
284
|
+
onBack={back}
|
|
285
|
+
/>
|
|
286
|
+
<SystemOverlay
|
|
287
|
+
host={host}
|
|
288
|
+
ui={ui}
|
|
289
|
+
device={device}
|
|
290
|
+
appearance={appAppearance}
|
|
291
|
+
topInset={device.insets[orientation].top}
|
|
292
|
+
/>
|
|
293
|
+
{screenEffect.blockInput && <div className="ws-screen-block" />}
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<div className="ws-shell">
|
|
301
|
+
<header className="ws-toolbar">
|
|
302
|
+
<div className="ws-toolbar-title">
|
|
303
|
+
<DeviceMobileIcon size={15} />
|
|
304
|
+
<span>{projectName}</span>
|
|
305
|
+
</div>
|
|
306
|
+
<div className="ws-toolbar-controls">
|
|
307
|
+
<DevicePicker devices={host.devices} value={device.id} onChange={changeDevice} />
|
|
308
|
+
<span className="ws-divider" />
|
|
309
|
+
<IconButton
|
|
310
|
+
label={
|
|
311
|
+
ui.orientationLock !== null
|
|
312
|
+
? `Locked to ${ui.orientationLock} by the app`
|
|
313
|
+
: orientation === 'portrait'
|
|
314
|
+
? 'Rotate to landscape'
|
|
315
|
+
: 'Rotate to portrait'
|
|
316
|
+
}
|
|
317
|
+
disabled={ui.orientationLock !== null}
|
|
318
|
+
onClick={() => host.setOrientation(orientation === 'portrait' ? 'landscape' : 'portrait')}
|
|
319
|
+
>
|
|
320
|
+
{ui.orientationLock !== null ? (
|
|
321
|
+
<OrientationLockIcon />
|
|
322
|
+
) : (
|
|
323
|
+
<RotateDeviceIcon direction={orientation === 'portrait' ? 'left' : 'right'} />
|
|
324
|
+
)}
|
|
325
|
+
</IconButton>
|
|
326
|
+
<IconButton
|
|
327
|
+
label={appearance === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
|
|
328
|
+
onClick={() => host.setAppearance(appearance === 'dark' ? 'light' : 'dark')}
|
|
329
|
+
>
|
|
330
|
+
{appearance === 'dark' ? <MoonIcon size={16} /> : <SunIcon size={16} />}
|
|
331
|
+
</IconButton>
|
|
332
|
+
{device.platform === 'android' && (
|
|
333
|
+
<IconButton label="Back" onClick={back}>
|
|
334
|
+
<ArrowUUpLeftIcon size={16} />
|
|
335
|
+
</IconButton>
|
|
336
|
+
)}
|
|
337
|
+
<IconButton label="Reset permissions" onClick={() => host.resetPermissions()}>
|
|
338
|
+
<ShieldSlashIcon size={16} />
|
|
339
|
+
</IconButton>
|
|
340
|
+
<IconButton label="Reload app" onClick={reload}>
|
|
341
|
+
<ReloadIcon />
|
|
342
|
+
</IconButton>
|
|
343
|
+
<IconButton
|
|
344
|
+
label={popout !== null ? 'Bring the phone back' : 'Pop out the phone'}
|
|
345
|
+
pressed={popout !== null}
|
|
346
|
+
onClick={() => (popout !== null ? bringBack() : void popOut())}
|
|
347
|
+
>
|
|
348
|
+
<PictureInPictureIcon size={16} />
|
|
349
|
+
</IconButton>
|
|
350
|
+
{hasPanels && (
|
|
351
|
+
<IconButton
|
|
352
|
+
label={panelsOpen ? 'Hide panels' : 'Show panels'}
|
|
353
|
+
pressed={panelsOpen}
|
|
354
|
+
onClick={() => {
|
|
355
|
+
setPanelsOpen(!panelsOpen)
|
|
356
|
+
writeFlag(PANELS_KEY, !panelsOpen)
|
|
357
|
+
}}
|
|
358
|
+
>
|
|
359
|
+
<SidebarSimpleIcon size={16} mirrored />
|
|
360
|
+
</IconButton>
|
|
361
|
+
)}
|
|
362
|
+
</div>
|
|
363
|
+
<div className="ws-toolbar-end">
|
|
364
|
+
<div className="ws-toolbar-meta">
|
|
365
|
+
{device.resizable !== undefined ? (
|
|
366
|
+
<SizeFields size={screen} onResize={resize} />
|
|
367
|
+
) : (
|
|
368
|
+
<>
|
|
369
|
+
{device.screen.width} × {device.screen.height}
|
|
370
|
+
</>
|
|
371
|
+
)}{' '}
|
|
372
|
+
@{device.pixelRatio}x
|
|
373
|
+
</div>
|
|
374
|
+
{/* The developer's tools, apart from the phone's own controls: what the app's requests left, and the log. */}
|
|
375
|
+
<div className="ws-toolbar-group" role="group" aria-label="Developer tools">
|
|
376
|
+
<ResetButton host={host} />
|
|
377
|
+
<CookiesButton host={host} />
|
|
378
|
+
<LogButton tab={host.events.tab} open={logOpen} onToggle={toggleLog} />
|
|
379
|
+
</div>
|
|
380
|
+
</div>
|
|
381
|
+
</header>
|
|
382
|
+
<div className="ws-body">
|
|
383
|
+
<div className="ws-stage-column">
|
|
384
|
+
<main className="ws-stage">
|
|
385
|
+
{popout === null ? (
|
|
386
|
+
deviceSlot
|
|
387
|
+
) : (
|
|
388
|
+
<div className="ws-popped-out">
|
|
389
|
+
<PictureInPictureIcon size={28} />
|
|
390
|
+
<p>The phone is in its own window.</p>
|
|
391
|
+
<button type="button" className="ws-text-button" onClick={bringBack}>
|
|
392
|
+
Bring it back
|
|
393
|
+
</button>
|
|
394
|
+
</div>
|
|
395
|
+
)}
|
|
396
|
+
</main>
|
|
397
|
+
{logOpen && <LogDrawer tab={host.events.tab} height={logHeight} onResize={resizeLog} onClose={toggleLog} />}
|
|
398
|
+
</div>
|
|
399
|
+
{showPanels && <PluginPanels store={host.plugins} sim={state} />}
|
|
400
|
+
{popout !== null && createPortal(deviceSlot, popout.container)}
|
|
401
|
+
</div>
|
|
402
|
+
</div>
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function readFlag(key: string, fallback: boolean): boolean {
|
|
407
|
+
try {
|
|
408
|
+
const value = localStorage.getItem(key)
|
|
409
|
+
return value === null ? fallback : value === 'true'
|
|
410
|
+
} catch {
|
|
411
|
+
return fallback
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function readNumber(key: string, fallback: number): number {
|
|
416
|
+
try {
|
|
417
|
+
const value = Number(localStorage.getItem(key))
|
|
418
|
+
return Number.isFinite(value) && value > 0 ? value : fallback
|
|
419
|
+
} catch {
|
|
420
|
+
return fallback
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function writeFlag(key: string, value: boolean): void {
|
|
425
|
+
try {
|
|
426
|
+
localStorage.setItem(key, String(value))
|
|
427
|
+
} catch {
|
|
428
|
+
// Storage blocked.
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function initialPath(): string {
|
|
433
|
+
try {
|
|
434
|
+
return sessionStorage.getItem(PATH_KEY) ?? '/'
|
|
435
|
+
} catch {
|
|
436
|
+
return '/'
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The dev server resolves app files for one platform at a time. The app loads once the server has switched to the
|
|
442
|
+
* device's platform.
|
|
443
|
+
*/
|
|
444
|
+
function usePlatformReady(platform: Platform): Platform | null {
|
|
445
|
+
const [ready, setReady] = useState<Platform | null>(null)
|
|
446
|
+
useEffect(() => {
|
|
447
|
+
const hot = import.meta.hot
|
|
448
|
+
if (hot === undefined) {
|
|
449
|
+
setReady(platform)
|
|
450
|
+
return
|
|
451
|
+
}
|
|
452
|
+
const onReady = (data: { platform: Platform }) => {
|
|
453
|
+
if (data.platform === platform) {
|
|
454
|
+
setReady(platform)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
hot.on('web-sim:platform-ready', onReady)
|
|
458
|
+
hot.send('web-sim:platform', { platform })
|
|
459
|
+
return () => hot.off('web-sim:platform-ready', onReady)
|
|
460
|
+
}, [platform])
|
|
461
|
+
return ready
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Scales the device down to fit the stage (the tab's, or its own window's when popped out), never up. */
|
|
465
|
+
function useFitScale(
|
|
466
|
+
frame: { width: number; height: number },
|
|
467
|
+
{ view, sidebar, toolbar, padding }: { view: Window; sidebar: number; toolbar: number; padding: number },
|
|
468
|
+
): number {
|
|
469
|
+
const [viewport, setViewport] = useState({ width: view.innerWidth, height: view.innerHeight })
|
|
470
|
+
useLayoutEffect(() => {
|
|
471
|
+
const onResize = () => setViewport({ width: view.innerWidth, height: view.innerHeight })
|
|
472
|
+
onResize()
|
|
473
|
+
view.addEventListener('resize', onResize)
|
|
474
|
+
return () => view.removeEventListener('resize', onResize)
|
|
475
|
+
}, [view])
|
|
476
|
+
return Math.max(
|
|
477
|
+
0.1,
|
|
478
|
+
Math.min(1, (viewport.width - sidebar - padding * 2) / frame.width, (viewport.height - toolbar - padding * 2) / frame.height),
|
|
479
|
+
)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function DevicePicker({ devices, value, onChange }: { devices: Device[]; value: string; onChange: (id: string) => void }) {
|
|
483
|
+
const groups: [string, Device[]][] = [
|
|
484
|
+
['iOS', devices.filter((device) => device.platform === 'ios')],
|
|
485
|
+
['Android', devices.filter((device) => device.platform === 'android')],
|
|
486
|
+
]
|
|
487
|
+
return (
|
|
488
|
+
<select className="ws-select" value={value} onChange={(event) => onChange(event.target.value)} aria-label="Device">
|
|
489
|
+
{groups
|
|
490
|
+
.filter(([, members]) => members.length > 0)
|
|
491
|
+
.map(([label, members]) => (
|
|
492
|
+
<optgroup key={label} label={label}>
|
|
493
|
+
{members.map((device) => (
|
|
494
|
+
<option key={device.id} value={device.id}>
|
|
495
|
+
{device.label}
|
|
496
|
+
</option>
|
|
497
|
+
))}
|
|
498
|
+
</optgroup>
|
|
499
|
+
))}
|
|
500
|
+
</select>
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function IconButton({
|
|
505
|
+
label,
|
|
506
|
+
onClick,
|
|
507
|
+
disabled = false,
|
|
508
|
+
pressed,
|
|
509
|
+
children,
|
|
510
|
+
}: {
|
|
511
|
+
label: string
|
|
512
|
+
onClick: () => void
|
|
513
|
+
disabled?: boolean
|
|
514
|
+
pressed?: boolean
|
|
515
|
+
children: React.ReactNode
|
|
516
|
+
}) {
|
|
517
|
+
return (
|
|
518
|
+
<button type="button" className="ws-icon-button" onClick={onClick} data-tooltip={label} aria-label={label} aria-pressed={pressed} disabled={disabled}>
|
|
519
|
+
{children}
|
|
520
|
+
</button>
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function ReloadIcon() {
|
|
525
|
+
return (
|
|
526
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
|
|
527
|
+
<path d="M21 12a9 9 0 1 1-2.64-6.36L21 8" />
|
|
528
|
+
<path d="M21 3v5h-5" />
|
|
529
|
+
</svg>
|
|
530
|
+
)
|
|
531
|
+
}
|