@a16n/web-sim 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/README.md +13 -2
  2. package/bin/cli.ts +255 -0
  3. package/bin/web-sim.js +39 -0
  4. package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
  5. package/overrides/@react-native-firebase/app/overrides.ts +34 -0
  6. package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
  7. package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
  8. package/overrides/expo-application/ExpoApplication.ts +81 -0
  9. package/overrides/expo-application/overrides.ts +16 -0
  10. package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
  11. package/overrides/expo-background-task/overrides.ts +9 -0
  12. package/overrides/expo-constants/ExponentConstants.ts +66 -0
  13. package/overrides/expo-constants/overrides.ts +9 -0
  14. package/overrides/expo-device/ExpoDevice.ts +104 -0
  15. package/overrides/expo-device/overrides.ts +9 -0
  16. package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
  17. package/overrides/expo-glass-effect/GlassView.tsx +95 -0
  18. package/overrides/expo-glass-effect/availability.ts +14 -0
  19. package/overrides/expo-glass-effect/overrides.ts +14 -0
  20. package/overrides/expo-haptics/Haptics.ts +67 -0
  21. package/overrides/expo-haptics/overrides.ts +5 -0
  22. package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
  23. package/overrides/expo-mail-composer/overrides.ts +9 -0
  24. package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
  25. package/overrides/expo-mesh-gradient/overrides.ts +9 -0
  26. package/overrides/expo-modules-core/overrides.ts +12 -0
  27. package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
  28. package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
  29. package/overrides/expo-navigation-bar/overrides.ts +12 -0
  30. package/overrides/expo-router/NativeStackView.tsx +74 -0
  31. package/overrides/expo-router/NativeTabsView.tsx +263 -0
  32. package/overrides/expo-router/SafeAreaProvider.ts +6 -0
  33. package/overrides/expo-router/overrides.ts +23 -0
  34. package/overrides/expo-router/statusBarRequests.ts +51 -0
  35. package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
  36. package/overrides/expo-screen-orientation/overrides.ts +21 -0
  37. package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
  38. package/overrides/expo-sharing/overrides.ts +9 -0
  39. package/overrides/expo-sms/ExpoSMS.ts +24 -0
  40. package/overrides/expo-sms/overrides.ts +9 -0
  41. package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
  42. package/overrides/expo-splash-screen/overrides.ts +5 -0
  43. package/overrides/expo-status-bar/StatusBar.tsx +44 -0
  44. package/overrides/expo-status-bar/overrides.ts +5 -0
  45. package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
  46. package/overrides/expo-store-review/overrides.ts +9 -0
  47. package/overrides/expo-symbols/SymbolView.tsx +192 -0
  48. package/overrides/expo-symbols/overrides.ts +9 -0
  49. package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
  50. package/overrides/expo-system-ui/overrides.ts +9 -0
  51. package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
  52. package/overrides/expo-task-manager/overrides.ts +9 -0
  53. package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
  54. package/overrides/expo-tracking-transparency/overrides.ts +11 -0
  55. package/overrides/expo-video/ExpoVideo.ts +16 -0
  56. package/overrides/expo-video/overrides.ts +9 -0
  57. package/overrides/lottie-react-native/LottieView.tsx +87 -0
  58. package/overrides/lottie-react-native/overrides.ts +9 -0
  59. package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
  60. package/overrides/react-native-pager-view/overrides.ts +9 -0
  61. package/overrides/react-native-reanimated/overrides.ts +28 -0
  62. package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
  63. package/overrides/react-native-safe-area-context/overrides.ts +12 -0
  64. package/overrides/react-native-share/NativeRNShare.ts +22 -0
  65. package/overrides/react-native-share/overrides.ts +12 -0
  66. package/overrides/react-native-share/platform.ts +14 -0
  67. package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
  68. package/overrides/react-native-turbo-image/overrides.ts +9 -0
  69. package/overrides/react-native-web/RefreshControl.tsx +57 -0
  70. package/overrides/react-native-web/overrides.ts +157 -0
  71. package/overrides/react-native-web/useElementLayout.ts +152 -0
  72. package/package.json +80 -4
  73. package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
  74. package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
  75. package/plugins/battery/plugin.ts +8 -0
  76. package/plugins/battery/shell.tsx +56 -0
  77. package/plugins/battery/state.ts +11 -0
  78. package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
  79. package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
  80. package/plugins/biometrics/plugin.ts +8 -0
  81. package/plugins/biometrics/shell.tsx +88 -0
  82. package/plugins/biometrics/state.ts +41 -0
  83. package/plugins/brightness/app.ts +5 -0
  84. package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
  85. package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
  86. package/plugins/brightness/plugin.ts +9 -0
  87. package/plugins/brightness/shell.tsx +55 -0
  88. package/plugins/brightness/state.ts +19 -0
  89. package/plugins/calendar/calendar.ts +299 -0
  90. package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
  91. package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
  92. package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
  93. package/plugins/calendar/plugin.ts +8 -0
  94. package/plugins/calendar/shell.tsx +123 -0
  95. package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
  96. package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
  97. package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
  98. package/plugins/camera/plugin.ts +9 -0
  99. package/plugins/camera/shell.tsx +107 -0
  100. package/plugins/camera/state.ts +61 -0
  101. package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
  102. package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
  103. package/plugins/clipboard/plugin.ts +8 -0
  104. package/plugins/clipboard/shell.tsx +122 -0
  105. package/plugins/clipboard/state.ts +93 -0
  106. package/plugins/clock/app.ts +25 -0
  107. package/plugins/clock/plugin.ts +8 -0
  108. package/plugins/clock/shell.tsx +225 -0
  109. package/plugins/clock/state.ts +12 -0
  110. package/plugins/contacts/contacts.ts +125 -0
  111. package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
  112. package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
  113. package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
  114. package/plugins/contacts/plugin.ts +8 -0
  115. package/plugins/contacts/shell.tsx +109 -0
  116. package/plugins/home-indicator/app.ts +5 -0
  117. package/plugins/home-indicator/plugin.ts +9 -0
  118. package/plugins/home-indicator/requests.ts +48 -0
  119. package/plugins/home-indicator/shell.tsx +68 -0
  120. package/plugins/home-indicator/state.ts +31 -0
  121. package/plugins/keep-awake/app.ts +5 -0
  122. package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
  123. package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
  124. package/plugins/keep-awake/plugin.ts +9 -0
  125. package/plugins/keep-awake/shell.tsx +80 -0
  126. package/plugins/keep-awake/state.ts +12 -0
  127. package/plugins/keyboard/Keyboard.tsx +354 -0
  128. package/plugins/keyboard/app.ts +90 -0
  129. package/plugins/keyboard/controller.ts +384 -0
  130. package/plugins/keyboard/fields.ts +244 -0
  131. package/plugins/keyboard/icons.tsx +283 -0
  132. package/plugins/keyboard/keyboard.css +362 -0
  133. package/plugins/keyboard/layouts/android.ts +175 -0
  134. package/plugins/keyboard/layouts/index.ts +10 -0
  135. package/plugins/keyboard/layouts/ios.ts +219 -0
  136. package/plugins/keyboard/layouts/types.ts +80 -0
  137. package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
  138. package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
  139. package/plugins/keyboard/plugin.ts +13 -0
  140. package/plugins/keyboard/shell.tsx +133 -0
  141. package/plugins/keyboard/state.ts +92 -0
  142. package/plugins/keyboard/suggestions.ts +63 -0
  143. package/plugins/keyboard/taps.ts +77 -0
  144. package/plugins/keyboard/typing.ts +112 -0
  145. package/plugins/locale/app.ts +232 -0
  146. package/plugins/locale/locale.ts +143 -0
  147. package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
  148. package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
  149. package/plugins/locale/plugin.ts +9 -0
  150. package/plugins/locale/shell.tsx +147 -0
  151. package/plugins/locale/state.ts +36 -0
  152. package/plugins/location/geo.ts +56 -0
  153. package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
  154. package/plugins/location/overrides/expo-location/overrides.ts +11 -0
  155. package/plugins/location/places.ts +38 -0
  156. package/plugins/location/plugin.ts +8 -0
  157. package/plugins/location/shell.tsx +188 -0
  158. package/plugins/location/state.ts +51 -0
  159. package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
  160. package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
  161. package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
  162. package/plugins/motion/plugin.ts +8 -0
  163. package/plugins/motion/sensors.ts +116 -0
  164. package/plugins/motion/shell.tsx +136 -0
  165. package/plugins/motion/state.ts +46 -0
  166. package/plugins/network/app.ts +400 -0
  167. package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
  168. package/plugins/network/overrides/expo-network/overrides.ts +9 -0
  169. package/plugins/network/plugin.ts +8 -0
  170. package/plugins/network/shell.tsx +67 -0
  171. package/plugins/network/state.ts +29 -0
  172. package/plugins/notifications/center.ts +255 -0
  173. package/plugins/notifications/content.ts +36 -0
  174. package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
  175. package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
  176. package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
  177. package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
  178. package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
  179. package/plugins/notifications/plugin.ts +8 -0
  180. package/plugins/notifications/shell.tsx +192 -0
  181. package/plugins/notifications/state.ts +56 -0
  182. package/plugins/notifications/tokens.ts +47 -0
  183. package/plugins/notifications/trigger.ts +107 -0
  184. package/plugins/permissions/plugin.ts +6 -0
  185. package/plugins/permissions/shell.tsx +50 -0
  186. package/plugins/permissions/state.ts +38 -0
  187. package/plugins/photos/appLibrary.ts +114 -0
  188. package/plugins/photos/library.ts +322 -0
  189. package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
  190. package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
  191. package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
  192. package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
  193. package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
  194. package/plugins/photos/plugin.ts +8 -0
  195. package/plugins/photos/samples.ts +367 -0
  196. package/plugins/photos/shell.tsx +164 -0
  197. package/plugins/photos/state.ts +88 -0
  198. package/plugins/storage/files.ts +351 -0
  199. package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
  200. package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
  201. package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
  202. package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
  203. package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
  204. package/plugins/storage/plugin.ts +8 -0
  205. package/plugins/storage/reset.ts +136 -0
  206. package/plugins/storage/secure.ts +71 -0
  207. package/plugins/storage/shell.tsx +365 -0
  208. package/plugins/storage/state.ts +13 -0
  209. package/src/client/app/appDocument.ts +129 -0
  210. package/src/client/app/appFocus.ts +97 -0
  211. package/src/client/app/console.ts +118 -0
  212. package/src/client/app/fonts.ts +76 -0
  213. package/src/client/app/main.tsx +99 -0
  214. package/src/client/app/routeContext.ts +45 -0
  215. package/src/client/app/touch.ts +640 -0
  216. package/src/client/entry.ts +20 -0
  217. package/src/client/modules.d.ts +8 -0
  218. package/src/client/react-native/app.ts +57 -0
  219. package/src/client/react-native/deep.ts +13 -0
  220. package/src/client/react-native/keyboard.tsx +192 -0
  221. package/src/client/react-native/library.ts +256 -0
  222. package/src/client/shell/Cookies.tsx +95 -0
  223. package/src/client/shell/LogDrawer.tsx +415 -0
  224. package/src/client/shell/PhotoPicker.tsx +174 -0
  225. package/src/client/shell/PluginOverlays.tsx +42 -0
  226. package/src/client/shell/PluginPanels.tsx +82 -0
  227. package/src/client/shell/ResetApp.tsx +87 -0
  228. package/src/client/shell/Resizer.tsx +99 -0
  229. package/src/client/shell/Shell.tsx +531 -0
  230. package/src/client/shell/SystemBars.tsx +376 -0
  231. package/src/client/shell/SystemCamera.tsx +181 -0
  232. package/src/client/shell/SystemOverlay.tsx +422 -0
  233. package/src/client/shell/SystemSheets.tsx +462 -0
  234. package/src/client/shell/backdrop.ts +229 -0
  235. package/src/client/shell/control.ts +91 -0
  236. package/src/client/shell/events.ts +226 -0
  237. package/src/client/shell/geometry.ts +68 -0
  238. package/src/client/shell/host.ts +492 -0
  239. package/src/client/shell/icons.tsx +34 -0
  240. package/src/client/shell/logFeed.ts +102 -0
  241. package/src/client/shell/main.tsx +22 -0
  242. package/src/client/shell/permissionCopy.ts +169 -0
  243. package/src/client/shell/plugins.ts +266 -0
  244. package/src/client/shell/popout.ts +185 -0
  245. package/src/client/shell/popover.ts +27 -0
  246. package/src/client/shell/shell.css +878 -0
  247. package/src/client/shell/statusTime.ts +31 -0
  248. package/src/client/shell/tooltips.ts +104 -0
  249. package/src/client/virtual.d.ts +23 -0
  250. package/src/devices/catalog.ts +223 -0
  251. package/src/devices/types.ts +83 -0
  252. package/src/node/appInfo.ts +188 -0
  253. package/src/node/appSource.ts +140 -0
  254. package/src/node/config.ts +180 -0
  255. package/src/node/control.ts +144 -0
  256. package/src/node/doctor.ts +199 -0
  257. package/src/node/events/cli.ts +206 -0
  258. package/src/node/events/shared.ts +238 -0
  259. package/src/node/events/store.ts +266 -0
  260. package/src/node/fonts.ts +377 -0
  261. package/src/node/index.ts +5 -0
  262. package/src/node/overrides/define.ts +56 -0
  263. package/src/node/overrides/packages.ts +136 -0
  264. package/src/node/overrides/platformPatch.ts +56 -0
  265. package/src/node/overrides/plugin.ts +169 -0
  266. package/src/node/overrides/registry.ts +258 -0
  267. package/src/node/paths.ts +18 -0
  268. package/src/node/platform.ts +171 -0
  269. package/src/node/plugins.ts +98 -0
  270. package/src/node/proxy.ts +421 -0
  271. package/src/node/server.ts +254 -0
  272. package/src/node/worklets.ts +86 -0
  273. package/src/plugin/index.ts +33 -0
  274. package/src/plugin/types.ts +127 -0
  275. package/src/plugin/ui.tsx +562 -0
  276. package/src/runtime/clock.ts +112 -0
  277. package/src/runtime/draw.ts +196 -0
  278. package/src/runtime/index.ts +519 -0
  279. package/src/runtime/media.ts +379 -0
  280. package/src/runtime/records.ts +76 -0
  281. package/src/runtime/timezone.ts +81 -0
@@ -0,0 +1,143 @@
1
+ import type { LocaleState } from './state.ts'
2
+
3
+ /**
4
+ * `getLocales()` and `getCalendars()` as a phone with the locale panel's settings answers, every field filled in.
5
+ * The region is the phone's one region, shared by all of its languages. Shared by the override and the panel.
6
+ */
7
+
8
+ const EURO = 'AD AT BE CY DE EE ES FI FR GR HR IE IT LT LU LV MC ME MT NL PT SI SK SM VA XK'.split(' ')
9
+
10
+ const CURRENCIES: Record<string, string> = {
11
+ ...Object.fromEntries(EURO.map((region) => [region, 'EUR'])),
12
+ AE: 'AED', AR: 'ARS', AU: 'AUD', BD: 'BDT', BG: 'BGN', BR: 'BRL', CA: 'CAD', CH: 'CHF', CL: 'CLP', CN: 'CNY',
13
+ CO: 'COP', CZ: 'CZK', DK: 'DKK', EG: 'EGP', GB: 'GBP', HK: 'HKD', HU: 'HUF', ID: 'IDR', IL: 'ILS', IN: 'INR',
14
+ IS: 'ISK', JP: 'JPY', KE: 'KES', KR: 'KRW', LI: 'CHF', MA: 'MAD', MX: 'MXN', MY: 'MYR', NG: 'NGN', NO: 'NOK',
15
+ NZ: 'NZD', PE: 'PEN', PH: 'PHP', PK: 'PKR', PL: 'PLN', QA: 'QAR', RO: 'RON', RS: 'RSD', RU: 'RUB', SA: 'SAR',
16
+ SE: 'SEK', SG: 'SGD', TH: 'THB', TR: 'TRY', TW: 'TWD', UA: 'UAH', US: 'USD', VN: 'VND', ZA: 'ZAR',
17
+ PR: 'USD', EC: 'USD', SV: 'USD', PA: 'USD', LR: 'LRD', MM: 'MMK', BY: 'BYN', KZ: 'KZT', GE: 'GEL', AM: 'AMD',
18
+ AZ: 'AZN', JO: 'JOD', KW: 'KWD', BH: 'BHD', OM: 'OMR', LK: 'LKR', NP: 'NPR', GH: 'GHS', TZ: 'TZS', UG: 'UGX',
19
+ ET: 'ETB', DZ: 'DZD', TN: 'TND', UY: 'UYU', PY: 'PYG', BO: 'BOB', VE: 'VES', CR: 'CRC', GT: 'GTQ', DO: 'DOP',
20
+ JM: 'JMD', TT: 'TTD', IR: 'IRR', IQ: 'IQD', LB: 'LBP', KH: 'KHR', LA: 'LAK', MN: 'MNT', FJ: 'FJD',
21
+ }
22
+
23
+ const FAHRENHEIT = 'AG BS BZ FM KN KY LR MH MS PW TC US VG'.split(' ')
24
+
25
+ const RTL = 'ar arc ckb dv fa ha he khw ks ps sd ur yi'.split(' ')
26
+
27
+ /** The regions the panel offers: those with a known currency. */
28
+ export const REGIONS = Object.keys(CURRENCIES).sort()
29
+
30
+ export function intlLocale(tag: string): Intl.Locale | null {
31
+ try {
32
+ return new Intl.Locale(tag)
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ function currencySymbol(tag: string, currency: string | null): string | null {
39
+ if (currency === null) {
40
+ return null
41
+ }
42
+ try {
43
+ const parts = new Intl.NumberFormat(tag, { style: 'currency', currency }).formatToParts(1)
44
+ return parts.find((part) => part.type === 'currency')?.value ?? currency
45
+ } catch {
46
+ return currency
47
+ }
48
+ }
49
+
50
+ function separators(tag: string): { decimal: string | null; group: string | null } {
51
+ try {
52
+ const parts = new Intl.NumberFormat(tag, { useGrouping: 'always' } as Intl.NumberFormatOptions).formatToParts(1234567.5)
53
+ return {
54
+ decimal: parts.find((part) => part.type === 'decimal')?.value ?? null,
55
+ group: parts.find((part) => part.type === 'group')?.value ?? null,
56
+ }
57
+ } catch {
58
+ return { decimal: '.', group: ',' }
59
+ }
60
+ }
61
+
62
+ type LocaleInfo = Intl.Locale & { getTextInfo?: () => { direction: string }; textInfo?: { direction: string } }
63
+ type WeekLocale = Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } }
64
+
65
+ /** The tag the phone formats with: its first language, in its region when the language names none. */
66
+ export function formattingTag(state: LocaleState): string {
67
+ const tag = state.languages[0] ?? 'en'
68
+ const locale = intlLocale(tag)
69
+ return locale?.region ? tag : `${tag}-${state.region}`
70
+ }
71
+
72
+ export function regionMeasurementSystem(region: string): 'metric' | 'us' | 'uk' {
73
+ return region === 'US' || region === 'LR' || region === 'MM' ? 'us' : region === 'GB' ? 'uk' : 'metric'
74
+ }
75
+
76
+ export function regionTemperatureUnit(region: string): 'celsius' | 'fahrenheit' {
77
+ return FAHRENHEIT.includes(region) ? 'fahrenheit' : 'celsius'
78
+ }
79
+
80
+ /** Whether the region's convention is a 24-hour clock. */
81
+ export function regionUses24hourClock(state: LocaleState): boolean {
82
+ const language = intlLocale(state.languages[0] ?? 'en')?.language ?? 'en'
83
+ const hourCycle = new Intl.DateTimeFormat(`${language}-${state.region}`, { hour: 'numeric', timeZone: 'UTC' }).resolvedOptions().hourCycle
84
+ return hourCycle === 'h23' || hourCycle === 'h24'
85
+ }
86
+
87
+ export function uses24hourClock(state: LocaleState): boolean {
88
+ return state.clock === 'auto' ? regionUses24hourClock(state) : state.clock === '24'
89
+ }
90
+
91
+ /** The region's first day of the week, 1 for Sunday. */
92
+ export function regionFirstWeekday(state: LocaleState): number {
93
+ const language = intlLocale(state.languages[0] ?? 'en')?.language ?? 'en'
94
+ const locale = intlLocale(`${language}-${state.region}`) as WeekLocale | null
95
+ // Intl counts Monday as 1 and Sunday as 7.
96
+ const firstDay = locale?.getWeekInfo?.().firstDay ?? locale?.weekInfo?.firstDay ?? 7
97
+ return (firstDay % 7) + 1
98
+ }
99
+
100
+ export function getLocales(state: LocaleState) {
101
+ const region = state.region
102
+ const currency = CURRENCIES[region] ?? null
103
+ const measurementSystem = state.measurementSystem === 'auto' ? regionMeasurementSystem(region) : state.measurementSystem
104
+ const temperatureUnit = state.temperatureUnit === 'auto' ? regionTemperatureUnit(region) : state.temperatureUnit
105
+ const tags = state.languages.length > 0 ? state.languages : ['en']
106
+ return tags.map((tag) => {
107
+ const locale = intlLocale(tag) as LocaleInfo | null
108
+ const languageCode = locale?.language ?? tag.split('-')[0]
109
+ const languageRegion = locale?.region ?? region
110
+ const languageTag = locale?.region ? tag : `${tag}-${region}`
111
+ const languageCurrency = CURRENCIES[languageRegion] ?? null
112
+ const direction = locale?.getTextInfo?.().direction ?? locale?.textInfo?.direction ?? (RTL.includes(languageCode) ? 'rtl' : 'ltr')
113
+ // Numbers are written the region's way in the language.
114
+ const { decimal, group } = separators(`${languageCode}-${region}`)
115
+ return {
116
+ languageTag,
117
+ languageCode,
118
+ languageScriptCode: locale?.script ?? null,
119
+ regionCode: region,
120
+ languageRegionCode: languageRegion,
121
+ currencyCode: currency,
122
+ currencySymbol: currencySymbol(languageTag, currency),
123
+ languageCurrencyCode: languageCurrency,
124
+ languageCurrencySymbol: currencySymbol(languageTag, languageCurrency),
125
+ decimalSeparator: decimal,
126
+ digitGroupingSeparator: group,
127
+ textDirection: direction === 'rtl' ? 'rtl' : 'ltr',
128
+ measurementSystem,
129
+ temperatureUnit,
130
+ }
131
+ })
132
+ }
133
+
134
+ export function getCalendars(state: LocaleState) {
135
+ return [
136
+ {
137
+ calendar: 'gregory',
138
+ timeZone: state.timeZone,
139
+ uses24hourClock: uses24hourClock(state),
140
+ firstWeekday: state.firstWeekday > 0 ? state.firstWeekday : regionFirstWeekday(state),
141
+ },
142
+ ]
143
+ }
@@ -0,0 +1,41 @@
1
+ import { plugin } from 'web-sim/runtime'
2
+ import { getCalendars, getLocales } from '../../locale.ts'
3
+ import { INITIAL_LOCALE, type LocaleState } from '../../state.ts'
4
+
5
+ /**
6
+ * `getLocales()` and `getCalendars()` from the locale panel. A change in the panel reaches `useLocales` and
7
+ * `useCalendars` through the listeners.
8
+ */
9
+ const locale = () => plugin<LocaleState>('locale', INITIAL_LOCALE)
10
+
11
+ type Subscription = { remove: () => void }
12
+
13
+ const LOCALE_KEYS = ['languages', 'region', 'measurementSystem', 'temperatureUnit'] as const
14
+ const CALENDAR_KEYS = ['languages', 'region', 'timeZone', 'clock', 'firstWeekday'] as const
15
+
16
+ function listen(keys: readonly (keyof LocaleState)[], listener: () => void): Subscription {
17
+ const remove = locale().watch((next, previous) => {
18
+ if (keys.some((key) => JSON.stringify(next[key]) !== JSON.stringify(previous[key]))) {
19
+ listener()
20
+ }
21
+ })
22
+ return { remove }
23
+ }
24
+
25
+ export function addLocaleListener(listener: () => void): Subscription {
26
+ return listen(LOCALE_KEYS, listener)
27
+ }
28
+
29
+ export function addCalendarListener(listener: () => void): Subscription {
30
+ return listen(CALENDAR_KEYS, listener)
31
+ }
32
+
33
+ /** @deprecated use `subscription.remove()` instead. */
34
+ export function removeSubscription(subscription: Subscription): void {
35
+ subscription.remove()
36
+ }
37
+
38
+ export default {
39
+ getLocales: () => getLocales(locale().get()),
40
+ getCalendars: () => getCalendars(locale().get()),
41
+ }
@@ -0,0 +1,9 @@
1
+ import { defineOverrides } from '../../../../src/node/overrides/define.ts'
2
+
3
+ export default defineOverrides('expo-localization', [
4
+ {
5
+ versions: '>=58 <59',
6
+ note: 'locales and calendars from the locale panel, every field filled in; its changes reach useLocales and useCalendars',
7
+ files: { 'build/ExpoLocalization.js': './ExpoLocalization.ts' },
8
+ },
9
+ ])
@@ -0,0 +1,9 @@
1
+ import { definePlugin } from '../../src/node/plugins.ts'
2
+
3
+ // Without `packages`: the time zone and the language reach every app's dates and Intl, with expo-localization or not.
4
+ export default definePlugin({
5
+ name: 'locale',
6
+ overrides: './overrides',
7
+ shell: './shell.tsx',
8
+ app: './app.ts',
9
+ })
@@ -0,0 +1,147 @@
1
+ import { ArrowDownIcon, ArrowUpIcon, GlobeIcon, XIcon } from '@phosphor-icons/react'
2
+ import { defineShellPlugin, Field, IconButton, List, ListItem, Segmented, Select } from 'web-sim/shell'
3
+ import {
4
+ formattingTag,
5
+ regionFirstWeekday,
6
+ regionMeasurementSystem,
7
+ regionTemperatureUnit,
8
+ regionUses24hourClock,
9
+ REGIONS,
10
+ } from './locale.ts'
11
+ import { COMMON_LANGUAGES, INITIAL_LOCALE, type LocaleState } from './state.ts'
12
+
13
+ const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
14
+ const MEASUREMENT = { metric: 'Metric', us: 'US', uk: 'UK' } as const
15
+ const TEMPERATURE = { celsius: '°C', fahrenheit: '°F' } as const
16
+
17
+ function displayName(type: 'language' | 'region', code: string): string {
18
+ try {
19
+ return new Intl.DisplayNames(['en'], { type }).of(code) ?? code
20
+ } catch {
21
+ return code
22
+ }
23
+ }
24
+
25
+ function timeZones(current: string): string[] {
26
+ const zones = (Intl as { supportedValuesOf?: (key: string) => string[] }).supportedValuesOf?.('timeZone') ?? []
27
+ return zones.includes(current) ? zones : [current, ...zones]
28
+ }
29
+
30
+ function phoneTime(state: LocaleState): string {
31
+ try {
32
+ return new Date().toLocaleString(formattingTag(state), {
33
+ timeZone: state.timeZone,
34
+ dateStyle: 'medium',
35
+ timeStyle: 'short',
36
+ ...(state.clock === 'auto' ? {} : { hourCycle: state.clock === '24' ? 'h23' : 'h12' }),
37
+ })
38
+ } catch {
39
+ return '—'
40
+ }
41
+ }
42
+
43
+ function move<T>(list: T[], from: number, to: number): T[] {
44
+ const next = [...list]
45
+ const [item] = next.splice(from, 1)
46
+ next.splice(to, 0, item)
47
+ return next
48
+ }
49
+
50
+ export default defineShellPlugin<LocaleState>({
51
+ id: 'locale',
52
+ title: 'Language & Region',
53
+ icon: GlobeIcon,
54
+ initialState: INITIAL_LOCALE,
55
+ Panel: ({ state, set }) => {
56
+ const { languages } = state
57
+ const addable = COMMON_LANGUAGES.filter((tag) => !languages.includes(tag))
58
+ const regions = REGIONS.includes(state.region) ? REGIONS : [state.region, ...REGIONS]
59
+ return (
60
+ <>
61
+ <Field label="Languages">
62
+ <List>
63
+ {languages.map((tag, index) => (
64
+ <ListItem
65
+ key={tag}
66
+ title={displayName('language', tag)}
67
+ detail={tag}
68
+ actions={
69
+ <>
70
+ <IconButton icon={ArrowUpIcon} title={`Move ${tag} up`} disabled={index === 0} onClick={() => set({ languages: move(languages, index, index - 1) })} />
71
+ <IconButton
72
+ icon={ArrowDownIcon}
73
+ title={`Move ${tag} down`}
74
+ disabled={index === languages.length - 1}
75
+ onClick={() => set({ languages: move(languages, index, index + 1) })}
76
+ />
77
+ <IconButton icon={XIcon} title={`Remove ${tag}`} disabled={languages.length === 1} onClick={() => set({ languages: languages.filter((other) => other !== tag) })} />
78
+ </>
79
+ }
80
+ />
81
+ ))}
82
+ </List>
83
+ <Select
84
+ label="Add language"
85
+ value=""
86
+ options={[{ value: '', label: 'Add language…' }, ...addable.map((tag) => ({ value: tag, label: `${displayName('language', tag)} (${tag})` }))]}
87
+ onChange={(tag) => tag !== '' && set({ languages: [...languages, tag] })}
88
+ />
89
+ </Field>
90
+ <Field label="Region">
91
+ <Select label="Region" value={state.region} options={regions.map((code) => ({ value: code, label: `${displayName('region', code)} (${code})` }))} onChange={(region) => set({ region })} />
92
+ </Field>
93
+ <Field label="Time zone" value={phoneTime(state)}>
94
+ <Select label="Time zone" value={state.timeZone} options={timeZones(state.timeZone).map((zone) => ({ value: zone, label: zone.replace(/_/g, ' ') }))} onChange={(timeZone) => set({ timeZone })} />
95
+ </Field>
96
+ <Field label="Clock">
97
+ <Segmented
98
+ label="Clock"
99
+ value={state.clock}
100
+ options={[
101
+ { value: 'auto', label: `Region · ${regionUses24hourClock(state) ? '24h' : '12h'}` },
102
+ { value: '12', label: '12-hour' },
103
+ { value: '24', label: '24-hour' },
104
+ ]}
105
+ onChange={(clock) => set({ clock })}
106
+ />
107
+ </Field>
108
+ <Field label="Measurement system">
109
+ <Select
110
+ label="Measurement system"
111
+ value={state.measurementSystem}
112
+ options={[
113
+ { value: 'auto', label: `Region · ${MEASUREMENT[regionMeasurementSystem(state.region)]}` },
114
+ { value: 'metric', label: 'Metric' },
115
+ { value: 'us', label: 'US' },
116
+ { value: 'uk', label: 'UK' },
117
+ ]}
118
+ onChange={(measurementSystem) => set({ measurementSystem })}
119
+ />
120
+ </Field>
121
+ <Field label="Temperature">
122
+ <Segmented
123
+ label="Temperature"
124
+ value={state.temperatureUnit}
125
+ options={[
126
+ { value: 'auto', label: `Region · ${TEMPERATURE[regionTemperatureUnit(state.region)]}` },
127
+ { value: 'celsius', label: '°C' },
128
+ { value: 'fahrenheit', label: '°F' },
129
+ ]}
130
+ onChange={(temperatureUnit) => set({ temperatureUnit })}
131
+ />
132
+ </Field>
133
+ <Field label="First day of week">
134
+ <Select
135
+ label="First day of week"
136
+ value={String(state.firstWeekday)}
137
+ options={[
138
+ { value: '0', label: `Region · ${WEEKDAYS[regionFirstWeekday(state) - 1]}` },
139
+ ...WEEKDAYS.map((day, index) => ({ value: String(index + 1), label: day })),
140
+ ]}
141
+ onChange={(day) => set({ firstWeekday: Number(day) })}
142
+ />
143
+ </Field>
144
+ </>
145
+ )
146
+ },
147
+ })
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The phone's language and region settings, set in the panel. `expo-localization` reports them, and the app's
3
+ * window formats dates and numbers with them.
4
+ */
5
+ export type LocaleState = {
6
+ /** Preferred languages, most preferred first: BCP 47 tags such as `en-US` or `fr`. */
7
+ languages: string[]
8
+ /** ISO 3166 region code. */
9
+ region: string
10
+ /** IANA time zone. */
11
+ timeZone: string
12
+ /** 'auto' follows the region. */
13
+ clock: 'auto' | '12' | '24'
14
+ measurementSystem: 'auto' | 'metric' | 'us' | 'uk'
15
+ temperatureUnit: 'auto' | 'celsius' | 'fahrenheit'
16
+ /** 1 is Sunday, as expo-localization counts; 0 follows the region. */
17
+ firstWeekday: number
18
+ }
19
+
20
+ export const INITIAL_LOCALE: LocaleState = {
21
+ languages: ['en-US'],
22
+ region: 'US',
23
+ timeZone: 'America/Los_Angeles',
24
+ clock: 'auto',
25
+ measurementSystem: 'auto',
26
+ temperatureUnit: 'auto',
27
+ firstWeekday: 0,
28
+ }
29
+
30
+ /** The languages the panel offers. */
31
+ export const COMMON_LANGUAGES = [
32
+ 'en-US', 'en-GB', 'en-AU', 'en-CA', 'en-IN', 'en-NZ', 'fr-FR', 'fr-CA', 'de-DE', 'de-CH', 'es-ES', 'es-MX', 'es-US',
33
+ 'it-IT', 'pt-BR', 'pt-PT', 'nl-NL', 'sv-SE', 'da-DK', 'nb-NO', 'fi-FI', 'pl-PL', 'cs-CZ', 'hu-HU', 'ro-RO', 'el-GR',
34
+ 'ru-RU', 'uk-UA', 'tr-TR', 'ar-SA', 'he-IL', 'hi-IN', 'th-TH', 'vi-VN', 'id-ID', 'ms-MY', 'ja-JP', 'ko-KR', 'zh-CN',
35
+ 'zh-TW', 'zh-HK',
36
+ ]
@@ -0,0 +1,56 @@
1
+ /** Distances and bearings on the Earth, for routes, watches' distance filters and reverse geocoding. */
2
+ export type Coordinates = { latitude: number; longitude: number }
3
+
4
+ const RAD = Math.PI / 180
5
+ const EARTH_RADIUS = 6_371_000
6
+
7
+ /** Metres between two points, along the surface. */
8
+ export function distance(a: Coordinates, b: Coordinates): number {
9
+ const dLat = (b.latitude - a.latitude) * RAD
10
+ const dLon = (b.longitude - a.longitude) * RAD
11
+ const h = Math.sin(dLat / 2) ** 2 + Math.cos(a.latitude * RAD) * Math.cos(b.latitude * RAD) * Math.sin(dLon / 2) ** 2
12
+ return 2 * EARTH_RADIUS * Math.asin(Math.sqrt(h))
13
+ }
14
+
15
+ /** The compass bearing from `a` to `b`, in degrees from true north. */
16
+ export function bearing(a: Coordinates, b: Coordinates): number {
17
+ const [lat1, lat2, dLon] = [a.latitude * RAD, b.latitude * RAD, (b.longitude - a.longitude) * RAD]
18
+ const y = Math.sin(dLon) * Math.cos(lat2)
19
+ const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon)
20
+ return (Math.atan2(y, x) / RAD + 360) % 360
21
+ }
22
+
23
+ /** The point `east` and `north` metres from `origin`. */
24
+ export function offset(origin: Coordinates, east: number, north: number): Coordinates {
25
+ return {
26
+ latitude: origin.latitude + north / EARTH_RADIUS / RAD,
27
+ longitude: origin.longitude + east / (EARTH_RADIUS * Math.cos(origin.latitude * RAD)) / RAD,
28
+ }
29
+ }
30
+
31
+ export function pathLength(points: Coordinates[]): number {
32
+ let total = 0
33
+ for (let i = 1; i < points.length; i += 1) {
34
+ total += distance(points[i - 1], points[i])
35
+ }
36
+ return total
37
+ }
38
+
39
+ /** The point `travelled` metres along a path, and the bearing of the leg it is on. */
40
+ export function along(points: Coordinates[], travelled: number): Coordinates & { heading: number } {
41
+ let left = travelled
42
+ for (let i = 1; i < points.length; i += 1) {
43
+ const [from, to] = [points[i - 1], points[i]]
44
+ const leg = distance(from, to)
45
+ if (left <= leg || i === points.length - 1) {
46
+ const t = leg === 0 ? 1 : Math.min(1, left / leg)
47
+ return {
48
+ latitude: from.latitude + (to.latitude - from.latitude) * t,
49
+ longitude: from.longitude + (to.longitude - from.longitude) * t,
50
+ heading: bearing(from, to),
51
+ }
52
+ }
53
+ left -= leg
54
+ }
55
+ return { ...points[0], heading: 0 }
56
+ }