@a16n/web-sim 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +13 -2
  2. package/bin/cli.ts +255 -0
  3. package/bin/web-sim.js +39 -0
  4. package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
  5. package/overrides/@react-native-firebase/app/overrides.ts +34 -0
  6. package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
  7. package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
  8. package/overrides/expo-application/ExpoApplication.ts +81 -0
  9. package/overrides/expo-application/overrides.ts +16 -0
  10. package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
  11. package/overrides/expo-background-task/overrides.ts +9 -0
  12. package/overrides/expo-constants/ExponentConstants.ts +66 -0
  13. package/overrides/expo-constants/overrides.ts +9 -0
  14. package/overrides/expo-device/ExpoDevice.ts +104 -0
  15. package/overrides/expo-device/overrides.ts +9 -0
  16. package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
  17. package/overrides/expo-glass-effect/GlassView.tsx +95 -0
  18. package/overrides/expo-glass-effect/availability.ts +14 -0
  19. package/overrides/expo-glass-effect/overrides.ts +14 -0
  20. package/overrides/expo-haptics/Haptics.ts +67 -0
  21. package/overrides/expo-haptics/overrides.ts +5 -0
  22. package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
  23. package/overrides/expo-mail-composer/overrides.ts +9 -0
  24. package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
  25. package/overrides/expo-mesh-gradient/overrides.ts +9 -0
  26. package/overrides/expo-modules-core/overrides.ts +12 -0
  27. package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
  28. package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
  29. package/overrides/expo-navigation-bar/overrides.ts +12 -0
  30. package/overrides/expo-router/NativeStackView.tsx +74 -0
  31. package/overrides/expo-router/NativeTabsView.tsx +263 -0
  32. package/overrides/expo-router/SafeAreaProvider.ts +6 -0
  33. package/overrides/expo-router/overrides.ts +23 -0
  34. package/overrides/expo-router/statusBarRequests.ts +51 -0
  35. package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
  36. package/overrides/expo-screen-orientation/overrides.ts +21 -0
  37. package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
  38. package/overrides/expo-sharing/overrides.ts +9 -0
  39. package/overrides/expo-sms/ExpoSMS.ts +24 -0
  40. package/overrides/expo-sms/overrides.ts +9 -0
  41. package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
  42. package/overrides/expo-splash-screen/overrides.ts +5 -0
  43. package/overrides/expo-status-bar/StatusBar.tsx +44 -0
  44. package/overrides/expo-status-bar/overrides.ts +5 -0
  45. package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
  46. package/overrides/expo-store-review/overrides.ts +9 -0
  47. package/overrides/expo-symbols/SymbolView.tsx +192 -0
  48. package/overrides/expo-symbols/overrides.ts +9 -0
  49. package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
  50. package/overrides/expo-system-ui/overrides.ts +9 -0
  51. package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
  52. package/overrides/expo-task-manager/overrides.ts +9 -0
  53. package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
  54. package/overrides/expo-tracking-transparency/overrides.ts +11 -0
  55. package/overrides/expo-video/ExpoVideo.ts +16 -0
  56. package/overrides/expo-video/overrides.ts +9 -0
  57. package/overrides/lottie-react-native/LottieView.tsx +87 -0
  58. package/overrides/lottie-react-native/overrides.ts +9 -0
  59. package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
  60. package/overrides/react-native-pager-view/overrides.ts +9 -0
  61. package/overrides/react-native-reanimated/overrides.ts +28 -0
  62. package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
  63. package/overrides/react-native-safe-area-context/overrides.ts +12 -0
  64. package/overrides/react-native-share/NativeRNShare.ts +22 -0
  65. package/overrides/react-native-share/overrides.ts +12 -0
  66. package/overrides/react-native-share/platform.ts +14 -0
  67. package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
  68. package/overrides/react-native-turbo-image/overrides.ts +9 -0
  69. package/overrides/react-native-web/RefreshControl.tsx +57 -0
  70. package/overrides/react-native-web/overrides.ts +153 -0
  71. package/overrides/react-native-web/useElementLayout.ts +140 -0
  72. package/package.json +78 -4
  73. package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
  74. package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
  75. package/plugins/battery/plugin.ts +8 -0
  76. package/plugins/battery/shell.tsx +56 -0
  77. package/plugins/battery/state.ts +11 -0
  78. package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
  79. package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
  80. package/plugins/biometrics/plugin.ts +8 -0
  81. package/plugins/biometrics/shell.tsx +88 -0
  82. package/plugins/biometrics/state.ts +41 -0
  83. package/plugins/brightness/app.ts +5 -0
  84. package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
  85. package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
  86. package/plugins/brightness/plugin.ts +9 -0
  87. package/plugins/brightness/shell.tsx +55 -0
  88. package/plugins/brightness/state.ts +19 -0
  89. package/plugins/calendar/calendar.ts +299 -0
  90. package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
  91. package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
  92. package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
  93. package/plugins/calendar/plugin.ts +8 -0
  94. package/plugins/calendar/shell.tsx +123 -0
  95. package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
  96. package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
  97. package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
  98. package/plugins/camera/plugin.ts +9 -0
  99. package/plugins/camera/shell.tsx +107 -0
  100. package/plugins/camera/state.ts +61 -0
  101. package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
  102. package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
  103. package/plugins/clipboard/plugin.ts +8 -0
  104. package/plugins/clipboard/shell.tsx +122 -0
  105. package/plugins/clipboard/state.ts +93 -0
  106. package/plugins/clock/app.ts +25 -0
  107. package/plugins/clock/plugin.ts +8 -0
  108. package/plugins/clock/shell.tsx +225 -0
  109. package/plugins/clock/state.ts +12 -0
  110. package/plugins/contacts/contacts.ts +125 -0
  111. package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
  112. package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
  113. package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
  114. package/plugins/contacts/plugin.ts +8 -0
  115. package/plugins/contacts/shell.tsx +109 -0
  116. package/plugins/home-indicator/app.ts +5 -0
  117. package/plugins/home-indicator/plugin.ts +9 -0
  118. package/plugins/home-indicator/requests.ts +48 -0
  119. package/plugins/home-indicator/shell.tsx +68 -0
  120. package/plugins/home-indicator/state.ts +31 -0
  121. package/plugins/keep-awake/app.ts +5 -0
  122. package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
  123. package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
  124. package/plugins/keep-awake/plugin.ts +9 -0
  125. package/plugins/keep-awake/shell.tsx +80 -0
  126. package/plugins/keep-awake/state.ts +12 -0
  127. package/plugins/keyboard/Keyboard.tsx +354 -0
  128. package/plugins/keyboard/app.ts +90 -0
  129. package/plugins/keyboard/controller.ts +384 -0
  130. package/plugins/keyboard/fields.ts +244 -0
  131. package/plugins/keyboard/icons.tsx +283 -0
  132. package/plugins/keyboard/keyboard.css +362 -0
  133. package/plugins/keyboard/layouts/android.ts +175 -0
  134. package/plugins/keyboard/layouts/index.ts +10 -0
  135. package/plugins/keyboard/layouts/ios.ts +219 -0
  136. package/plugins/keyboard/layouts/types.ts +80 -0
  137. package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
  138. package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
  139. package/plugins/keyboard/plugin.ts +13 -0
  140. package/plugins/keyboard/shell.tsx +133 -0
  141. package/plugins/keyboard/state.ts +92 -0
  142. package/plugins/keyboard/suggestions.ts +63 -0
  143. package/plugins/keyboard/taps.ts +77 -0
  144. package/plugins/keyboard/typing.ts +112 -0
  145. package/plugins/locale/app.ts +232 -0
  146. package/plugins/locale/locale.ts +143 -0
  147. package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
  148. package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
  149. package/plugins/locale/plugin.ts +9 -0
  150. package/plugins/locale/shell.tsx +147 -0
  151. package/plugins/locale/state.ts +36 -0
  152. package/plugins/location/geo.ts +56 -0
  153. package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
  154. package/plugins/location/overrides/expo-location/overrides.ts +11 -0
  155. package/plugins/location/places.ts +38 -0
  156. package/plugins/location/plugin.ts +8 -0
  157. package/plugins/location/shell.tsx +188 -0
  158. package/plugins/location/state.ts +51 -0
  159. package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
  160. package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
  161. package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
  162. package/plugins/motion/plugin.ts +8 -0
  163. package/plugins/motion/sensors.ts +116 -0
  164. package/plugins/motion/shell.tsx +136 -0
  165. package/plugins/motion/state.ts +46 -0
  166. package/plugins/network/app.ts +400 -0
  167. package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
  168. package/plugins/network/overrides/expo-network/overrides.ts +9 -0
  169. package/plugins/network/plugin.ts +8 -0
  170. package/plugins/network/shell.tsx +67 -0
  171. package/plugins/network/state.ts +29 -0
  172. package/plugins/notifications/center.ts +255 -0
  173. package/plugins/notifications/content.ts +36 -0
  174. package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
  175. package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
  176. package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
  177. package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
  178. package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
  179. package/plugins/notifications/plugin.ts +8 -0
  180. package/plugins/notifications/shell.tsx +192 -0
  181. package/plugins/notifications/state.ts +56 -0
  182. package/plugins/notifications/tokens.ts +47 -0
  183. package/plugins/notifications/trigger.ts +107 -0
  184. package/plugins/permissions/plugin.ts +6 -0
  185. package/plugins/permissions/shell.tsx +50 -0
  186. package/plugins/permissions/state.ts +38 -0
  187. package/plugins/photos/appLibrary.ts +114 -0
  188. package/plugins/photos/library.ts +322 -0
  189. package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
  190. package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
  191. package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
  192. package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
  193. package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
  194. package/plugins/photos/plugin.ts +8 -0
  195. package/plugins/photos/samples.ts +367 -0
  196. package/plugins/photos/shell.tsx +164 -0
  197. package/plugins/photos/state.ts +88 -0
  198. package/plugins/storage/files.ts +351 -0
  199. package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
  200. package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
  201. package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
  202. package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
  203. package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
  204. package/plugins/storage/plugin.ts +8 -0
  205. package/plugins/storage/reset.ts +136 -0
  206. package/plugins/storage/secure.ts +71 -0
  207. package/plugins/storage/shell.tsx +365 -0
  208. package/plugins/storage/state.ts +13 -0
  209. package/src/client/app/appDocument.ts +113 -0
  210. package/src/client/app/appFocus.ts +97 -0
  211. package/src/client/app/console.ts +118 -0
  212. package/src/client/app/fonts.ts +59 -0
  213. package/src/client/app/main.tsx +99 -0
  214. package/src/client/app/routeContext.ts +45 -0
  215. package/src/client/app/touch.ts +640 -0
  216. package/src/client/entry.ts +20 -0
  217. package/src/client/modules.d.ts +8 -0
  218. package/src/client/react-native/app.ts +57 -0
  219. package/src/client/react-native/deep.ts +13 -0
  220. package/src/client/react-native/keyboard.tsx +192 -0
  221. package/src/client/react-native/library.ts +256 -0
  222. package/src/client/shell/Cookies.tsx +95 -0
  223. package/src/client/shell/LogDrawer.tsx +415 -0
  224. package/src/client/shell/PhotoPicker.tsx +174 -0
  225. package/src/client/shell/PluginOverlays.tsx +42 -0
  226. package/src/client/shell/PluginPanels.tsx +82 -0
  227. package/src/client/shell/ResetApp.tsx +87 -0
  228. package/src/client/shell/Resizer.tsx +99 -0
  229. package/src/client/shell/Shell.tsx +531 -0
  230. package/src/client/shell/SystemBars.tsx +376 -0
  231. package/src/client/shell/SystemCamera.tsx +181 -0
  232. package/src/client/shell/SystemOverlay.tsx +422 -0
  233. package/src/client/shell/SystemSheets.tsx +462 -0
  234. package/src/client/shell/backdrop.ts +229 -0
  235. package/src/client/shell/control.ts +91 -0
  236. package/src/client/shell/events.ts +226 -0
  237. package/src/client/shell/geometry.ts +68 -0
  238. package/src/client/shell/host.ts +492 -0
  239. package/src/client/shell/icons.tsx +34 -0
  240. package/src/client/shell/logFeed.ts +102 -0
  241. package/src/client/shell/main.tsx +22 -0
  242. package/src/client/shell/permissionCopy.ts +169 -0
  243. package/src/client/shell/plugins.ts +266 -0
  244. package/src/client/shell/popout.ts +185 -0
  245. package/src/client/shell/popover.ts +27 -0
  246. package/src/client/shell/shell.css +878 -0
  247. package/src/client/shell/statusTime.ts +31 -0
  248. package/src/client/shell/tooltips.ts +104 -0
  249. package/src/client/virtual.d.ts +21 -0
  250. package/src/devices/catalog.ts +223 -0
  251. package/src/devices/types.ts +83 -0
  252. package/src/node/appInfo.ts +186 -0
  253. package/src/node/appSource.ts +138 -0
  254. package/src/node/config.ts +180 -0
  255. package/src/node/control.ts +144 -0
  256. package/src/node/doctor.ts +199 -0
  257. package/src/node/events/cli.ts +206 -0
  258. package/src/node/events/shared.ts +238 -0
  259. package/src/node/events/store.ts +266 -0
  260. package/src/node/index.ts +5 -0
  261. package/src/node/overrides/define.ts +56 -0
  262. package/src/node/overrides/packages.ts +136 -0
  263. package/src/node/overrides/platformPatch.ts +56 -0
  264. package/src/node/overrides/plugin.ts +166 -0
  265. package/src/node/overrides/registry.ts +258 -0
  266. package/src/node/paths.ts +18 -0
  267. package/src/node/platform.ts +171 -0
  268. package/src/node/plugins.ts +98 -0
  269. package/src/node/proxy.ts +421 -0
  270. package/src/node/server.ts +253 -0
  271. package/src/plugin/index.ts +33 -0
  272. package/src/plugin/types.ts +127 -0
  273. package/src/plugin/ui.tsx +562 -0
  274. package/src/runtime/clock.ts +112 -0
  275. package/src/runtime/draw.ts +196 -0
  276. package/src/runtime/index.ts +513 -0
  277. package/src/runtime/media.ts +379 -0
  278. package/src/runtime/records.ts +76 -0
  279. package/src/runtime/timezone.ts +81 -0
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Canvas drawing helpers for the simulator's made-up pictures: the camera's scenes and the sample photos. Everything
3
+ * is drawn from a seed, so the same picture comes out every time.
4
+ */
5
+
6
+ export function rng(seed: number): () => number {
7
+ let state = seed * 2654435761
8
+ return () => {
9
+ state = (state + 0x6d2b79f5) | 0
10
+ let x = Math.imul(state ^ (state >>> 15), 1 | state)
11
+ x = (x + Math.imul(x ^ (x >>> 7), 61 | x)) ^ x
12
+ return ((x ^ (x >>> 14)) >>> 0) / 4294967296
13
+ }
14
+ }
15
+
16
+ export function linear(ctx: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number, colors: string[]) {
17
+ const gradient = ctx.createLinearGradient(x0, y0, x1, y1)
18
+ colors.forEach((color, index) => gradient.addColorStop(index / (colors.length - 1), color))
19
+ ctx.fillStyle = gradient
20
+ }
21
+
22
+ export function radial(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, colors: string[]) {
23
+ const gradient = ctx.createRadialGradient(x, y, 0, x, y, r)
24
+ colors.forEach((color, index) => gradient.addColorStop(index / (colors.length - 1), color))
25
+ ctx.fillStyle = gradient
26
+ }
27
+
28
+ export function circle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, color: string) {
29
+ ctx.fillStyle = color
30
+ ctx.beginPath()
31
+ ctx.arc(x, y, r, 0, Math.PI * 2)
32
+ ctx.fill()
33
+ }
34
+
35
+ export function glow(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, color: string) {
36
+ const gradient = ctx.createRadialGradient(x, y, r * 0.6, x, y, r * 5)
37
+ gradient.addColorStop(0, `${color}aa`)
38
+ gradient.addColorStop(1, `${color}00`)
39
+ ctx.fillStyle = gradient
40
+ ctx.fillRect(x - r * 5, y - r * 5, r * 10, r * 10)
41
+ circle(ctx, x, y, r, color)
42
+ }
43
+
44
+ export function cloud(ctx: CanvasRenderingContext2D, x: number, y: number, size: number) {
45
+ const puffs = [
46
+ [0, 0, 1, 0.32],
47
+ [0.35, -0.18, 0.5, 0.32],
48
+ [-0.3, -0.1, 0.45, 0.28],
49
+ ]
50
+ ctx.beginPath()
51
+ for (const [dx, dy, rx, ry] of puffs) {
52
+ ctx.moveTo(x + dx * size + rx * size, y + dy * size)
53
+ ctx.ellipse(x + dx * size, y + dy * size, rx * size, ry * size, 0, 0, Math.PI * 2)
54
+ }
55
+ ctx.fill()
56
+ }
57
+
58
+ export function hills(ctx: CanvasRenderingContext2D, w: number, base: number, height: number, color: string, phase: number) {
59
+ ctx.fillStyle = color
60
+ ctx.beginPath()
61
+ ctx.moveTo(0, base)
62
+ for (let x = 0; x <= w; x += w / 24) {
63
+ ctx.lineTo(x, base - height * (0.5 + 0.5 * Math.sin(x / w * 5 + phase)) * (0.6 + 0.4 * Math.sin(x / w * 13 + phase * 2)))
64
+ }
65
+ ctx.lineTo(w, base + height)
66
+ ctx.lineTo(0, base + height)
67
+ ctx.fill()
68
+ }
69
+
70
+ export function ridge(ctx: CanvasRenderingContext2D, w: number, top: number, bottom: number, roughness: number, color: string, random: () => number) {
71
+ ctx.fillStyle = color
72
+ ctx.beginPath()
73
+ ctx.moveTo(0, bottom)
74
+ let y = top + roughness * random()
75
+ ctx.lineTo(0, y)
76
+ const steps = 14
77
+ for (let i = 1; i <= steps; i++) {
78
+ y = Math.min(bottom, Math.max(top - roughness, y + (random() - 0.5) * roughness * 1.6))
79
+ ctx.lineTo((w * i) / steps, y)
80
+ }
81
+ ctx.lineTo(w, bottom)
82
+ ctx.fill()
83
+ }
84
+
85
+ export function pine(ctx: CanvasRenderingContext2D, x: number, base: number, height: number, color: string) {
86
+ ctx.fillStyle = color
87
+ for (let tier = 0; tier < 3; tier++) {
88
+ const top = base - height * (0.45 + tier * 0.27)
89
+ const width = height * (0.32 - tier * 0.07)
90
+ ctx.beginPath()
91
+ ctx.moveTo(x, top - height * 0.2)
92
+ ctx.lineTo(x + width, base - height * tier * 0.27)
93
+ ctx.lineTo(x - width, base - height * tier * 0.27)
94
+ ctx.fill()
95
+ }
96
+ ctx.fillRect(x - height * 0.025, base - height * 0.05, height * 0.05, height * 0.1)
97
+ }
98
+
99
+ export function tree(ctx: CanvasRenderingContext2D, x: number, base: number, height: number, sway: number) {
100
+ ctx.save()
101
+ ctx.translate(x, base)
102
+ ctx.rotate(sway)
103
+ ctx.fillStyle = '#5b4030'
104
+ ctx.fillRect(-height * 0.04, -height * 0.55, height * 0.08, height * 0.55)
105
+ const leaves = ['#3f6e33', '#4f8240', '#5f9a4c']
106
+ leaves.forEach((color, index) => {
107
+ ctx.fillStyle = color
108
+ ctx.beginPath()
109
+ ctx.ellipse(-height * 0.12 + index * height * 0.12, -height * (0.7 + (index % 2) * 0.12), height * 0.24, height * 0.22, 0, 0, Math.PI * 2)
110
+ ctx.fill()
111
+ })
112
+ ctx.restore()
113
+ }
114
+
115
+ export function wave(ctx: CanvasRenderingContext2D, w: number, top: number, bottom: number, amplitude: number, random: () => number) {
116
+ ctx.beginPath()
117
+ ctx.moveTo(0, bottom)
118
+ ctx.lineTo(0, top)
119
+ const phase = random() * Math.PI * 2
120
+ for (let x = 0; x <= w; x += w / 20) {
121
+ ctx.lineTo(x, top + Math.sin(x / w * 6 + phase) * amplitude)
122
+ }
123
+ ctx.lineTo(w, bottom)
124
+ ctx.fill()
125
+ }
126
+
127
+ export function wood(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
128
+ linear(ctx, 0, 0, w, h, ['#a87b56', '#8f6443', '#7a5337'])
129
+ ctx.fillRect(0, 0, w, h)
130
+ const plank = h / 5
131
+ for (let i = 0; i < 5; i++) {
132
+ ctx.fillStyle = `rgba(60, 35, 20, ${0.1 + random() * 0.15})`
133
+ ctx.fillRect(0, i * plank, w, plank)
134
+ ctx.fillStyle = 'rgba(40, 22, 12, 0.5)'
135
+ ctx.fillRect(0, i * plank, w, Math.max(1, h * 0.003))
136
+ ctx.strokeStyle = 'rgba(50, 30, 15, 0.18)'
137
+ ctx.lineWidth = 1
138
+ for (let g = 0; g < 6; g++) {
139
+ const y = i * plank + plank * random()
140
+ ctx.beginPath()
141
+ ctx.moveTo(0, y)
142
+ ctx.bezierCurveTo(w * 0.3, y + plank * 0.1, w * 0.6, y - plank * 0.1, w, y)
143
+ ctx.stroke()
144
+ }
145
+ }
146
+ }
147
+
148
+ export function shadowed(ctx: CanvasRenderingContext2D, draw: () => void) {
149
+ ctx.save()
150
+ ctx.shadowColor = 'rgba(0, 0, 0, 0.35)'
151
+ ctx.shadowBlur = Math.min(ctx.canvas.width, ctx.canvas.height) * 0.04
152
+ ctx.shadowOffsetY = Math.min(ctx.canvas.width, ctx.canvas.height) * 0.015
153
+ draw()
154
+ ctx.restore()
155
+ }
156
+
157
+ export function vignette(ctx: CanvasRenderingContext2D, w: number, h: number, strength: number) {
158
+ const gradient = ctx.createRadialGradient(w / 2, h / 2, Math.min(w, h) * 0.35, w / 2, h / 2, Math.max(w, h) * 0.75)
159
+ gradient.addColorStop(0, 'rgba(0, 0, 0, 0)')
160
+ gradient.addColorStop(1, `rgba(0, 0, 0, ${strength})`)
161
+ ctx.fillStyle = gradient
162
+ ctx.fillRect(0, 0, w, h)
163
+ }
164
+
165
+ /** Sensor noise: a small random tile, laid over the whole frame. */
166
+ export function grain(ctx: CanvasRenderingContext2D, w: number, h: number, seed: number, strength: number) {
167
+ const size = 96
168
+ const tile = document.createElement('canvas')
169
+ tile.width = size
170
+ tile.height = size
171
+ const tileCtx = tile.getContext('2d')!
172
+ const image = tileCtx.createImageData(size, size)
173
+ const random = rng(seed + 1)
174
+ for (let i = 0; i < image.data.length; i += 4) {
175
+ const value = random() * 255
176
+ image.data[i] = value
177
+ image.data[i + 1] = value
178
+ image.data[i + 2] = value
179
+ image.data[i + 3] = 255 * strength
180
+ }
181
+ tileCtx.putImageData(image, 0, 0)
182
+ ctx.save()
183
+ ctx.fillStyle = ctx.createPattern(tile, 'repeat')!
184
+ ctx.globalCompositeOperation = 'overlay'
185
+ ctx.fillRect(0, 0, w, h)
186
+ ctx.restore()
187
+ }
188
+
189
+ export function loadImage(uri: string): Promise<HTMLImageElement> {
190
+ return new Promise((resolve, reject) => {
191
+ const image = new Image()
192
+ image.onload = () => resolve(image)
193
+ image.onerror = () => reject(new Error(`Could not load the image at ${uri.slice(0, 60)}`))
194
+ image.src = uri
195
+ })
196
+ }