@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,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
|
+
}
|