@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,367 @@
|
|
|
1
|
+
import { circle, cloud, glow, grain, linear, pine, radial, ridge, rng, shadowed, vignette, wave, wood } from '../../src/runtime/draw.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The library's sample photos, drawn on a canvas from a scene and a seed: no image files, no network.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type SceneKind = 'mountains' | 'beach' | 'city' | 'forest' | 'dunes' | 'aurora' | 'salad' | 'coffee' | 'bokeh' | 'lake'
|
|
8
|
+
|
|
9
|
+
export function drawSample(ctx: CanvasRenderingContext2D, scene: SceneKind, seed: number, w: number, h: number) {
|
|
10
|
+
const random = rng(seed)
|
|
11
|
+
switch (scene) {
|
|
12
|
+
case 'mountains':
|
|
13
|
+
return mountains(ctx, w, h, random, false)
|
|
14
|
+
case 'lake':
|
|
15
|
+
return mountains(ctx, w, h, random, true)
|
|
16
|
+
case 'beach':
|
|
17
|
+
return beach(ctx, w, h, random)
|
|
18
|
+
case 'city':
|
|
19
|
+
return city(ctx, w, h, random)
|
|
20
|
+
case 'forest':
|
|
21
|
+
return forest(ctx, w, h, random)
|
|
22
|
+
case 'dunes':
|
|
23
|
+
return dunes(ctx, w, h, random)
|
|
24
|
+
case 'aurora':
|
|
25
|
+
return aurora(ctx, w, h, random)
|
|
26
|
+
case 'salad':
|
|
27
|
+
return salad(ctx, w, h, random)
|
|
28
|
+
case 'coffee':
|
|
29
|
+
return coffee(ctx, w, h, random)
|
|
30
|
+
case 'bokeh':
|
|
31
|
+
return bokeh(ctx, w, h, random)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function finish(ctx: CanvasRenderingContext2D, w: number, h: number, seed: number) {
|
|
36
|
+
vignette(ctx, w, h, 0.3)
|
|
37
|
+
grain(ctx, w, h, seed, 0.035)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function mountains(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number, lake: boolean) {
|
|
41
|
+
const sunset = random() > 0.4
|
|
42
|
+
const horizon = h * (lake ? 0.55 : 0.68)
|
|
43
|
+
linear(ctx, 0, 0, 0, horizon, sunset ? ['#2c3e74', '#c4637a', '#f6b26b', '#fbe3a1'] : ['#3d7cc9', '#8cbbe8', '#dceaf5'])
|
|
44
|
+
ctx.fillRect(0, 0, w, horizon)
|
|
45
|
+
const sunX = w * (0.25 + random() * 0.5)
|
|
46
|
+
glow(ctx, sunX, horizon * (sunset ? 0.82 : 0.3), Math.min(w, h) * 0.06, sunset ? '#fff1c1' : '#ffffff')
|
|
47
|
+
const layers = sunset ? ['#8c5a7d', '#6a4170', '#45305a', '#2a1f3d'] : ['#9fb6cf', '#7590ad', '#4f6886', '#2f435c']
|
|
48
|
+
layers.forEach((color, index) => {
|
|
49
|
+
ridge(ctx, w, horizon - h * (0.28 - index * 0.06), horizon, h * (0.14 - index * 0.02), color, random)
|
|
50
|
+
})
|
|
51
|
+
if (lake) {
|
|
52
|
+
// The water mirrors what is above it, darker and rippled.
|
|
53
|
+
ctx.save()
|
|
54
|
+
ctx.globalAlpha = 0.75
|
|
55
|
+
ctx.translate(0, horizon * 2)
|
|
56
|
+
ctx.scale(1, -1)
|
|
57
|
+
ctx.drawImage(ctx.canvas, 0, 0, w, horizon, 0, 0, w, horizon)
|
|
58
|
+
ctx.restore()
|
|
59
|
+
ctx.fillStyle = 'rgba(20, 30, 60, 0.35)'
|
|
60
|
+
ctx.fillRect(0, horizon, w, h - horizon)
|
|
61
|
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.12)'
|
|
62
|
+
for (let i = 0; i < 40; i++) {
|
|
63
|
+
const y = horizon + (h - horizon) * random()
|
|
64
|
+
ctx.lineWidth = 1 + random() * 2
|
|
65
|
+
ctx.beginPath()
|
|
66
|
+
const x = w * random()
|
|
67
|
+
ctx.moveTo(x, y)
|
|
68
|
+
ctx.lineTo(x + w * (0.05 + random() * 0.15), y)
|
|
69
|
+
ctx.stroke()
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
linear(ctx, 0, horizon, 0, h, sunset ? ['#2a1f3d', '#1a1428'] : ['#3d5a3a', '#26391f'])
|
|
73
|
+
ctx.fillRect(0, horizon, w, h - horizon)
|
|
74
|
+
for (let i = 0; i < 14; i++) {
|
|
75
|
+
pine(ctx, w * random(), horizon + (h - horizon) * (0.3 + random() * 0.7), h * (0.08 + random() * 0.1), sunset ? '#120d1c' : '#1b2a16')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
finish(ctx, w, h, 3)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function beach(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
82
|
+
const horizon = h * (0.42 + random() * 0.08)
|
|
83
|
+
linear(ctx, 0, 0, 0, horizon, ['#4a90d9', '#9ccbef', '#f4e7cf'])
|
|
84
|
+
ctx.fillRect(0, 0, w, horizon)
|
|
85
|
+
glow(ctx, w * (0.2 + random() * 0.6), horizon * 0.35, Math.min(w, h) * 0.05, '#fffbe8')
|
|
86
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)'
|
|
87
|
+
for (let i = 0; i < 3; i++) {
|
|
88
|
+
cloud(ctx, w * random(), horizon * (0.15 + random() * 0.4), w * (0.08 + random() * 0.08))
|
|
89
|
+
}
|
|
90
|
+
linear(ctx, 0, horizon, 0, h * 0.75, ['#1f6fa8', '#2f9fc2', '#6fd0d6'])
|
|
91
|
+
ctx.fillRect(0, horizon, w, h)
|
|
92
|
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.25)'
|
|
93
|
+
for (let i = 0; i < 30; i++) {
|
|
94
|
+
const y = horizon + (h * 0.75 - horizon) * Math.pow(random(), 0.7)
|
|
95
|
+
ctx.lineWidth = 1 + (y - horizon) / h * 6
|
|
96
|
+
ctx.beginPath()
|
|
97
|
+
const x = w * random()
|
|
98
|
+
ctx.moveTo(x, y)
|
|
99
|
+
ctx.lineTo(x + w * (0.04 + random() * 0.12), y)
|
|
100
|
+
ctx.stroke()
|
|
101
|
+
}
|
|
102
|
+
// Sand with a wet edge and foam.
|
|
103
|
+
const shore = h * 0.7
|
|
104
|
+
ctx.fillStyle = '#e8d3a8'
|
|
105
|
+
wave(ctx, w, shore, h, h * 0.02, random)
|
|
106
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)'
|
|
107
|
+
wave(ctx, w, shore - h * 0.005, shore + h * 0.012, h * 0.02, random)
|
|
108
|
+
ctx.fillStyle = '#d9c08f'
|
|
109
|
+
wave(ctx, w, shore + h * 0.06, h, h * 0.01, random)
|
|
110
|
+
// A palm leaning in from the side.
|
|
111
|
+
const base = random() > 0.5 ? w * 0.9 : w * 0.1
|
|
112
|
+
const lean = base > w / 2 ? -1 : 1
|
|
113
|
+
ctx.strokeStyle = '#5a4030'
|
|
114
|
+
ctx.lineWidth = w * 0.025
|
|
115
|
+
ctx.beginPath()
|
|
116
|
+
ctx.moveTo(base, h)
|
|
117
|
+
ctx.quadraticCurveTo(base + lean * w * 0.02, h * 0.6, base + lean * w * 0.12, h * 0.35)
|
|
118
|
+
ctx.stroke()
|
|
119
|
+
ctx.fillStyle = '#2f5b2a'
|
|
120
|
+
for (let i = 0; i < 7; i++) {
|
|
121
|
+
const angle = (i / 7) * Math.PI * 2
|
|
122
|
+
ctx.beginPath()
|
|
123
|
+
ctx.ellipse(base + lean * w * 0.12 + Math.cos(angle) * w * 0.08, h * 0.35 + Math.sin(angle) * h * 0.03, w * 0.1, h * 0.015, angle, 0, Math.PI * 2)
|
|
124
|
+
ctx.fill()
|
|
125
|
+
}
|
|
126
|
+
finish(ctx, w, h, 7)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function city(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
130
|
+
linear(ctx, 0, 0, 0, h, ['#0b1026', '#1d2756', '#5b3f78', '#c26b6b'])
|
|
131
|
+
ctx.fillRect(0, 0, w, h)
|
|
132
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)'
|
|
133
|
+
for (let i = 0; i < 80; i++) {
|
|
134
|
+
ctx.fillRect(w * random(), h * 0.5 * random(), 1.5, 1.5)
|
|
135
|
+
}
|
|
136
|
+
glow(ctx, w * (0.15 + random() * 0.7), h * 0.15, Math.min(w, h) * 0.035, '#f4f1e0')
|
|
137
|
+
for (let row = 0; row < 2; row++) {
|
|
138
|
+
let x = -w * 0.05
|
|
139
|
+
while (x < w) {
|
|
140
|
+
const bw = w * (0.07 + random() * 0.09)
|
|
141
|
+
const bh = h * (row === 0 ? 0.25 + random() * 0.35 : 0.15 + random() * 0.25)
|
|
142
|
+
const top = h - bh
|
|
143
|
+
ctx.fillStyle = row === 0 ? '#1a1d33' : '#0d0f1d'
|
|
144
|
+
ctx.fillRect(x, top, bw, bh)
|
|
145
|
+
const cols = Math.max(2, Math.floor(bw / (w * 0.018)))
|
|
146
|
+
const rows = Math.floor(bh / (h * 0.022))
|
|
147
|
+
for (let c = 0; c < cols; c++) {
|
|
148
|
+
for (let r = 0; r < rows; r++) {
|
|
149
|
+
if (random() > (row === 0 ? 0.55 : 0.7)) {
|
|
150
|
+
ctx.fillStyle = random() > 0.2 ? 'rgba(255, 210, 120, 0.85)' : 'rgba(170, 220, 255, 0.8)'
|
|
151
|
+
ctx.fillRect(x + (c + 0.25) * (bw / cols), top + (r + 0.4) * (h * 0.022), (bw / cols) * 0.5, h * 0.011)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
x += bw + w * 0.01
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
finish(ctx, w, h, 13)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function forest(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
162
|
+
linear(ctx, 0, 0, 0, h, ['#cfe3d6', '#9fc4ae', '#4e7a5d'])
|
|
163
|
+
ctx.fillRect(0, 0, w, h)
|
|
164
|
+
// Light through the trees.
|
|
165
|
+
ctx.save()
|
|
166
|
+
ctx.globalAlpha = 0.18
|
|
167
|
+
ctx.fillStyle = '#fff8dc'
|
|
168
|
+
for (let i = 0; i < 5; i++) {
|
|
169
|
+
const x = w * random()
|
|
170
|
+
ctx.beginPath()
|
|
171
|
+
ctx.moveTo(x, 0)
|
|
172
|
+
ctx.lineTo(x + w * 0.08, 0)
|
|
173
|
+
ctx.lineTo(x + w * 0.35, h)
|
|
174
|
+
ctx.lineTo(x + w * 0.2, h)
|
|
175
|
+
ctx.fill()
|
|
176
|
+
}
|
|
177
|
+
ctx.restore()
|
|
178
|
+
const colors = ['#7fa58c', '#5c8a6c', '#3e6b4f', '#244a33', '#15301f']
|
|
179
|
+
colors.forEach((color, layer) => {
|
|
180
|
+
const count = 6 + layer * 3
|
|
181
|
+
for (let i = 0; i < count; i++) {
|
|
182
|
+
pine(ctx, w * (i / count + random() * 0.08), h * (0.6 + layer * 0.09), h * (0.16 + layer * 0.06 + random() * 0.08), color)
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
ctx.fillStyle = '#1d2e1c'
|
|
186
|
+
ctx.fillRect(0, h * 0.95, w, h * 0.05)
|
|
187
|
+
finish(ctx, w, h, 5)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function dunes(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
191
|
+
linear(ctx, 0, 0, 0, h * 0.5, ['#f09a5a', '#f7c88a', '#fbe5bf'])
|
|
192
|
+
ctx.fillRect(0, 0, w, h)
|
|
193
|
+
glow(ctx, w * (0.3 + random() * 0.4), h * 0.3, Math.min(w, h) * 0.07, '#fff3d6')
|
|
194
|
+
const shades = [
|
|
195
|
+
['#e3a467', '#c47d43'],
|
|
196
|
+
['#d48e52', '#a9632f'],
|
|
197
|
+
['#c27a3f', '#8f4f22'],
|
|
198
|
+
]
|
|
199
|
+
shades.forEach(([light, dark], index) => {
|
|
200
|
+
const top = h * (0.45 + index * 0.13)
|
|
201
|
+
const peak = w * (0.2 + random() * 0.6)
|
|
202
|
+
ctx.fillStyle = light
|
|
203
|
+
ctx.beginPath()
|
|
204
|
+
ctx.moveTo(0, top + h * 0.08)
|
|
205
|
+
ctx.quadraticCurveTo(peak * 0.6, top - h * 0.02, peak, top)
|
|
206
|
+
ctx.quadraticCurveTo(peak + (w - peak) * 0.5, top + h * 0.05, w, top + h * 0.09)
|
|
207
|
+
ctx.lineTo(w, h)
|
|
208
|
+
ctx.lineTo(0, h)
|
|
209
|
+
ctx.fill()
|
|
210
|
+
ctx.fillStyle = dark
|
|
211
|
+
ctx.beginPath()
|
|
212
|
+
ctx.moveTo(peak, top)
|
|
213
|
+
ctx.quadraticCurveTo(peak + w * 0.1, top + h * 0.15, peak - w * 0.05, h)
|
|
214
|
+
ctx.lineTo(w, h)
|
|
215
|
+
ctx.lineTo(w, top + h * 0.09)
|
|
216
|
+
ctx.quadraticCurveTo(peak + (w - peak) * 0.5, top + h * 0.05, peak, top)
|
|
217
|
+
ctx.fill()
|
|
218
|
+
})
|
|
219
|
+
finish(ctx, w, h, 6)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function aurora(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
223
|
+
linear(ctx, 0, 0, 0, h, ['#030814', '#0a1a33', '#12324a'])
|
|
224
|
+
ctx.fillRect(0, 0, w, h)
|
|
225
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.85)'
|
|
226
|
+
for (let i = 0; i < 160; i++) {
|
|
227
|
+
const size = random() * 1.8 + 0.4
|
|
228
|
+
ctx.fillRect(w * random(), h * 0.75 * random(), size, size)
|
|
229
|
+
}
|
|
230
|
+
ctx.save()
|
|
231
|
+
ctx.filter = `blur(${Math.round(Math.min(w, h) * 0.03)}px)`
|
|
232
|
+
ctx.globalCompositeOperation = 'lighter'
|
|
233
|
+
const bands = [
|
|
234
|
+
['rgba(60, 255, 160, 0.5)', 0.3],
|
|
235
|
+
['rgba(80, 200, 255, 0.35)', 0.42],
|
|
236
|
+
['rgba(190, 90, 255, 0.3)', 0.22],
|
|
237
|
+
] as const
|
|
238
|
+
for (const [color, y] of bands) {
|
|
239
|
+
ctx.strokeStyle = color
|
|
240
|
+
ctx.lineWidth = h * 0.08
|
|
241
|
+
ctx.beginPath()
|
|
242
|
+
ctx.moveTo(-w * 0.1, h * (y + random() * 0.1))
|
|
243
|
+
ctx.bezierCurveTo(w * 0.3, h * (y - 0.15 + random() * 0.1), w * 0.6, h * (y + 0.2 * random()), w * 1.1, h * (y - 0.1 + random() * 0.1))
|
|
244
|
+
ctx.stroke()
|
|
245
|
+
}
|
|
246
|
+
ctx.restore()
|
|
247
|
+
ridge(ctx, w, h * 0.72, h, h * 0.08, '#050a10', random)
|
|
248
|
+
finish(ctx, w, h, 2)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function salad(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
252
|
+
wood(ctx, w, h, random)
|
|
253
|
+
const cx = w * 0.5
|
|
254
|
+
const cy = h * 0.5
|
|
255
|
+
const r = Math.min(w, h) * 0.36
|
|
256
|
+
shadowed(ctx, () => circle(ctx, cx, cy, r, '#f4f1ec'))
|
|
257
|
+
circle(ctx, cx, cy, r * 0.82, '#e9e4dc')
|
|
258
|
+
const greens = ['#4f8a3c', '#6aa84f', '#86c06a', '#3b6e2c']
|
|
259
|
+
for (let i = 0; i < 70; i++) {
|
|
260
|
+
const angle = random() * Math.PI * 2
|
|
261
|
+
const distance = Math.sqrt(random()) * r * 0.72
|
|
262
|
+
ctx.fillStyle = greens[i % greens.length]
|
|
263
|
+
ctx.beginPath()
|
|
264
|
+
ctx.ellipse(cx + Math.cos(angle) * distance, cy + Math.sin(angle) * distance, r * 0.12, r * 0.06, random() * Math.PI, 0, Math.PI * 2)
|
|
265
|
+
ctx.fill()
|
|
266
|
+
}
|
|
267
|
+
for (let i = 0; i < 8; i++) {
|
|
268
|
+
const angle = random() * Math.PI * 2
|
|
269
|
+
const distance = Math.sqrt(random()) * r * 0.6
|
|
270
|
+
circle(ctx, cx + Math.cos(angle) * distance, cy + Math.sin(angle) * distance, r * 0.08, '#d9412b')
|
|
271
|
+
circle(ctx, cx + Math.cos(angle) * distance - r * 0.02, cy + Math.sin(angle) * distance - r * 0.02, r * 0.025, 'rgba(255,255,255,0.35)')
|
|
272
|
+
}
|
|
273
|
+
for (let i = 0; i < 10; i++) {
|
|
274
|
+
const angle = random() * Math.PI * 2
|
|
275
|
+
const distance = Math.sqrt(random()) * r * 0.6
|
|
276
|
+
ctx.fillStyle = '#f2e3a0'
|
|
277
|
+
ctx.fillRect(cx + Math.cos(angle) * distance, cy + Math.sin(angle) * distance, r * 0.08, r * 0.08)
|
|
278
|
+
}
|
|
279
|
+
// A fork beside the bowl.
|
|
280
|
+
ctx.fillStyle = '#c9ccd1'
|
|
281
|
+
const fx = cx + r * 1.2 > w * 0.95 ? cx - r * 1.2 : cx + r * 1.2
|
|
282
|
+
ctx.fillRect(fx - r * 0.02, cy - r * 0.3, r * 0.04, r * 0.9)
|
|
283
|
+
for (let i = -1.5; i <= 1.5; i++) {
|
|
284
|
+
ctx.fillRect(fx + i * r * 0.035 - r * 0.008, cy - r * 0.55, r * 0.016, r * 0.28)
|
|
285
|
+
}
|
|
286
|
+
finish(ctx, w, h, 9)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function coffee(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
290
|
+
wood(ctx, w, h, random)
|
|
291
|
+
const cx = w * (0.45 + random() * 0.1)
|
|
292
|
+
const cy = h * (0.45 + random() * 0.1)
|
|
293
|
+
const r = Math.min(w, h) * 0.3
|
|
294
|
+
shadowed(ctx, () => circle(ctx, cx, cy, r * 1.15, '#f6f4f0'))
|
|
295
|
+
circle(ctx, cx, cy, r * 0.95, '#ebe7e1')
|
|
296
|
+
circle(ctx, cx, cy, r * 0.8, '#ffffff')
|
|
297
|
+
circle(ctx, cx, cy, r * 0.7, '#6b3f22')
|
|
298
|
+
radial(ctx, cx, cy, r * 0.7, ['#c8925f', '#8a5530', '#5a3219'])
|
|
299
|
+
ctx.beginPath()
|
|
300
|
+
ctx.arc(cx, cy, r * 0.7, 0, Math.PI * 2)
|
|
301
|
+
ctx.fill()
|
|
302
|
+
// A latte-art heart.
|
|
303
|
+
ctx.fillStyle = '#f3e6d3'
|
|
304
|
+
ctx.beginPath()
|
|
305
|
+
ctx.arc(cx - r * 0.13, cy - r * 0.08, r * 0.17, 0, Math.PI * 2)
|
|
306
|
+
ctx.arc(cx + r * 0.13, cy - r * 0.08, r * 0.17, 0, Math.PI * 2)
|
|
307
|
+
ctx.fill()
|
|
308
|
+
ctx.beginPath()
|
|
309
|
+
ctx.moveTo(cx - r * 0.29, cy - r * 0.02)
|
|
310
|
+
ctx.lineTo(cx + r * 0.29, cy - r * 0.02)
|
|
311
|
+
ctx.lineTo(cx, cy + r * 0.32)
|
|
312
|
+
ctx.fill()
|
|
313
|
+
// The handle and a spoon.
|
|
314
|
+
ctx.fillStyle = '#ffffff'
|
|
315
|
+
ctx.fillRect(cx + r * 0.78, cy - r * 0.08, r * 0.3, r * 0.16)
|
|
316
|
+
ctx.fillStyle = '#c9ccd1'
|
|
317
|
+
ctx.beginPath()
|
|
318
|
+
ctx.ellipse(cx - r * 0.2, cy + r * 1.0, r * 0.1, r * 0.06, 0.2, 0, Math.PI * 2)
|
|
319
|
+
ctx.fill()
|
|
320
|
+
ctx.save()
|
|
321
|
+
ctx.translate(cx - r * 0.2, cy + r * 1.0)
|
|
322
|
+
ctx.rotate(0.2)
|
|
323
|
+
ctx.fillRect(r * 0.08, -r * 0.015, r * 0.6, r * 0.03)
|
|
324
|
+
ctx.restore()
|
|
325
|
+
finish(ctx, w, h, 4)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function bokeh(ctx: CanvasRenderingContext2D, w: number, h: number, random: () => number) {
|
|
329
|
+
linear(ctx, 0, 0, w, h, ['#1b1030', '#3a1d4f', '#14243f'])
|
|
330
|
+
ctx.fillRect(0, 0, w, h)
|
|
331
|
+
const hues = [30, 45, 320, 200, 280]
|
|
332
|
+
ctx.save()
|
|
333
|
+
ctx.globalCompositeOperation = 'lighter'
|
|
334
|
+
for (let i = 0; i < 45; i++) {
|
|
335
|
+
const r = Math.min(w, h) * (0.03 + random() * 0.08)
|
|
336
|
+
const hue = hues[Math.floor(random() * hues.length)]
|
|
337
|
+
const x = w * random()
|
|
338
|
+
const y = h * random() * 0.8
|
|
339
|
+
const gradient = ctx.createRadialGradient(x, y, 0, x, y, r)
|
|
340
|
+
gradient.addColorStop(0, `hsla(${hue}, 90%, 70%, 0.35)`)
|
|
341
|
+
gradient.addColorStop(0.8, `hsla(${hue}, 90%, 60%, 0.25)`)
|
|
342
|
+
gradient.addColorStop(1, `hsla(${hue}, 90%, 60%, 0)`)
|
|
343
|
+
ctx.fillStyle = gradient
|
|
344
|
+
ctx.beginPath()
|
|
345
|
+
ctx.arc(x, y, r, 0, Math.PI * 2)
|
|
346
|
+
ctx.fill()
|
|
347
|
+
}
|
|
348
|
+
ctx.restore()
|
|
349
|
+
// Flowers in focus at the bottom.
|
|
350
|
+
for (let i = 0; i < 5; i++) {
|
|
351
|
+
const x = w * (0.1 + i * 0.2 + random() * 0.05)
|
|
352
|
+
const y = h * (0.78 + random() * 0.12)
|
|
353
|
+
ctx.strokeStyle = '#2e5a2c'
|
|
354
|
+
ctx.lineWidth = Math.max(2, w * 0.008)
|
|
355
|
+
ctx.beginPath()
|
|
356
|
+
ctx.moveTo(x, y)
|
|
357
|
+
ctx.lineTo(x + w * 0.01, h)
|
|
358
|
+
ctx.stroke()
|
|
359
|
+
const r = Math.min(w, h) * 0.035
|
|
360
|
+
for (let p = 0; p < 6; p++) {
|
|
361
|
+
const angle = (p / 6) * Math.PI * 2
|
|
362
|
+
circle(ctx, x + Math.cos(angle) * r, y + Math.sin(angle) * r, r * 0.75, i % 2 ? '#f7c4d8' : '#fbe7a1')
|
|
363
|
+
}
|
|
364
|
+
circle(ctx, x, y, r * 0.55, '#e5a32b')
|
|
365
|
+
}
|
|
366
|
+
finish(ctx, w, h, 12)
|
|
367
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ImagesIcon, TrashIcon } from '@phosphor-icons/react'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
defineShellPlugin,
|
|
6
|
+
Field,
|
|
7
|
+
FileButton,
|
|
8
|
+
IconButton,
|
|
9
|
+
List,
|
|
10
|
+
ListItem,
|
|
11
|
+
Log,
|
|
12
|
+
readDataUrl,
|
|
13
|
+
Row,
|
|
14
|
+
TextField,
|
|
15
|
+
Thumbnails,
|
|
16
|
+
type PluginContext,
|
|
17
|
+
} from 'web-sim/shell'
|
|
18
|
+
import { addPhoto, createAlbum, deleteAlbums, deletePhotos, editAlbum, libraryPhotos, photoThumbnail, pruneImages, type PhotosHandle } from './library.ts'
|
|
19
|
+
import { INITIAL_PHOTOS, type PhotosState } from './state.ts'
|
|
20
|
+
|
|
21
|
+
type AddArgs = { uri: string; filename?: string; album?: number }
|
|
22
|
+
|
|
23
|
+
const handle = (context: PluginContext<PhotosState>): PhotosHandle => ({ get: context.state, set: context.set })
|
|
24
|
+
|
|
25
|
+
/** Thumbnails by photo number, made as photos appear. Samples are drawn; added photos' come from IndexedDB. */
|
|
26
|
+
function useThumbnails(state: PhotosState): Map<number, string> {
|
|
27
|
+
const [thumbnails, setThumbnails] = useState(() => new Map<number, string>())
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
let live = true
|
|
30
|
+
const missing = state.photos.filter((photo) => !thumbnails.has(photo.n))
|
|
31
|
+
if (missing.length === 0) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
void Promise.all(missing.map(async (photo) => [photo.n, await photoThumbnail(photo, 120)] as const)).then((made) => {
|
|
35
|
+
if (live) {
|
|
36
|
+
setThumbnails((current) => new Map([...current, ...made]))
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
return () => {
|
|
40
|
+
live = false
|
|
41
|
+
}
|
|
42
|
+
}, [state.photos, thumbnails])
|
|
43
|
+
return thumbnails
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default defineShellPlugin<PhotosState>({
|
|
47
|
+
id: 'photos',
|
|
48
|
+
title: 'Photos',
|
|
49
|
+
icon: ImagesIcon,
|
|
50
|
+
initialState: INITIAL_PHOTOS,
|
|
51
|
+
actions: {
|
|
52
|
+
/** Adds an image (a data URL) to the library, and to one of the user's albums by its number. */
|
|
53
|
+
add: async (context, args) => {
|
|
54
|
+
const { uri, filename, album } = args as AddArgs
|
|
55
|
+
return addPhoto(handle(context), uri, { by: 'panel', filename, album })
|
|
56
|
+
},
|
|
57
|
+
/** Removes photos by number. */
|
|
58
|
+
remove: (context, args) => {
|
|
59
|
+
const { n } = args as { n: number | number[] }
|
|
60
|
+
deletePhotos(handle(context), Array.isArray(n) ? n : [n])
|
|
61
|
+
},
|
|
62
|
+
/** Adds an album, empty or with photos by number. */
|
|
63
|
+
'add-album': (context, args) => {
|
|
64
|
+
const { title, photos = [] } = args as { title: string; photos?: number[] }
|
|
65
|
+
return createAlbum(handle(context), title, photos)
|
|
66
|
+
},
|
|
67
|
+
'remove-album': (context, args) => {
|
|
68
|
+
const { n } = args as { n: number }
|
|
69
|
+
deleteAlbums(handle(context), [n])
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
setup: (context) => {
|
|
73
|
+
// Images no photo has any longer, after a removal or a reset, are deleted from IndexedDB.
|
|
74
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
75
|
+
let photos: PhotosState['photos'] | null = null
|
|
76
|
+
const prune = () => {
|
|
77
|
+
if (context.state().photos === photos) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
photos = context.state().photos
|
|
81
|
+
clearTimeout(timer)
|
|
82
|
+
timer = setTimeout(() => void pruneImages(() => new Set(context.state().photos.map((photo) => photo.n))).catch(() => undefined), 1000)
|
|
83
|
+
}
|
|
84
|
+
const offState = context.subscribe(prune)
|
|
85
|
+
prune()
|
|
86
|
+
return () => {
|
|
87
|
+
clearTimeout(timer)
|
|
88
|
+
offState()
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
Panel: ({ state, set, run, sim }) => {
|
|
92
|
+
const [albumN, setAlbumN] = useState<number | null>(null)
|
|
93
|
+
const [title, setTitle] = useState('')
|
|
94
|
+
const thumbnails = useThumbnails(state)
|
|
95
|
+
const album = state.albums.find((candidate) => candidate.n === albumN)
|
|
96
|
+
const photos = libraryPhotos(state, sim.device.platform).filter((photo) => album === undefined || album.photos.includes(photo.n))
|
|
97
|
+
const add = async (files: File[]) => {
|
|
98
|
+
for (const file of files) {
|
|
99
|
+
await run('add', { uri: await readDataUrl(file), filename: file.name, album: album?.n })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const remove = (id: string) => {
|
|
103
|
+
const n = Number(id)
|
|
104
|
+
if (album !== undefined) {
|
|
105
|
+
editAlbum({ get: () => state, set }, album.n, { remove: [n] })
|
|
106
|
+
} else {
|
|
107
|
+
run('remove', { n })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<Field label={album?.title ?? 'Library'} value={photos.length === 1 ? '1 photo' : `${photos.length} photos`}>
|
|
113
|
+
<Thumbnails
|
|
114
|
+
items={photos.map((photo) => ({
|
|
115
|
+
id: String(photo.n),
|
|
116
|
+
src: thumbnails.get(photo.n) ?? null,
|
|
117
|
+
label: photo.filename,
|
|
118
|
+
badge: photo.source.kind === 'added' && photo.source.by === 'app' ? 'App' : undefined,
|
|
119
|
+
}))}
|
|
120
|
+
onRemove={remove}
|
|
121
|
+
removeLabel={album === undefined ? 'Remove' : `Remove from ${album.title}`}
|
|
122
|
+
/>
|
|
123
|
+
<Row>
|
|
124
|
+
<FileButton accept="image/*" multiple onFiles={add}>
|
|
125
|
+
Add photos
|
|
126
|
+
</FileButton>
|
|
127
|
+
</Row>
|
|
128
|
+
</Field>
|
|
129
|
+
<Field label="Albums">
|
|
130
|
+
<List>
|
|
131
|
+
<ListItem title="All photos" detail={state.photos.length} selected={album === undefined} onPress={() => setAlbumN(null)} />
|
|
132
|
+
{state.albums.map((candidate) => (
|
|
133
|
+
<ListItem
|
|
134
|
+
key={candidate.n}
|
|
135
|
+
title={candidate.title}
|
|
136
|
+
detail={candidate.photos.filter((n) => state.photos.some((photo) => photo.n === n)).length}
|
|
137
|
+
selected={candidate.n === albumN}
|
|
138
|
+
onPress={() => setAlbumN(candidate.n === albumN ? null : candidate.n)}
|
|
139
|
+
actions={<IconButton icon={TrashIcon} title={`Delete ${candidate.title}`} onClick={() => run('remove-album', { n: candidate.n })} />}
|
|
140
|
+
/>
|
|
141
|
+
))}
|
|
142
|
+
</List>
|
|
143
|
+
<Row>
|
|
144
|
+
<div style={{ flex: 1 }}>
|
|
145
|
+
<TextField label="New album" placeholder="Album name" value={title} onChange={setTitle} />
|
|
146
|
+
</div>
|
|
147
|
+
<Button
|
|
148
|
+
disabled={title.trim() === ''}
|
|
149
|
+
onClick={() => {
|
|
150
|
+
run('add-album', { title: title.trim() })
|
|
151
|
+
setTitle('')
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
Add album
|
|
155
|
+
</Button>
|
|
156
|
+
</Row>
|
|
157
|
+
</Field>
|
|
158
|
+
<Field label="App">
|
|
159
|
+
<Log entries={state.log} />
|
|
160
|
+
</Field>
|
|
161
|
+
</>
|
|
162
|
+
)
|
|
163
|
+
},
|
|
164
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { LogEntry } from '../../src/runtime/index.ts'
|
|
2
|
+
import type { SceneKind } from './samples.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A photo in the library. Its `n` is its number, from which each platform's asset id is made. The images of added
|
|
6
|
+
* photos are kept in IndexedDB under that number, out of the state.
|
|
7
|
+
*/
|
|
8
|
+
export type StoredPhoto = {
|
|
9
|
+
n: number
|
|
10
|
+
width: number
|
|
11
|
+
height: number
|
|
12
|
+
/** When it was taken, in milliseconds since the epoch; null for a sample, dated `ago` before the last whole hour. */
|
|
13
|
+
time: number | null
|
|
14
|
+
ago: number
|
|
15
|
+
favorite: boolean
|
|
16
|
+
location: { latitude: number; longitude: number } | null
|
|
17
|
+
/** A drawn sample, or an image added by the app or the panel. */
|
|
18
|
+
source: { kind: 'sample'; scene: SceneKind; seed: number } | { kind: 'added'; by: 'app' | 'panel'; filename: string }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** An album of the user's. The smart albums and Android's folders are made from the photos. */
|
|
22
|
+
export type StoredAlbum = { n: number; title: string; photos: number[] }
|
|
23
|
+
|
|
24
|
+
export type PhotosState = {
|
|
25
|
+
photos: StoredPhoto[]
|
|
26
|
+
albums: StoredAlbum[]
|
|
27
|
+
/** The next number for a photo or album. */
|
|
28
|
+
next: number
|
|
29
|
+
/** What the app saved, deleted and changed. */
|
|
30
|
+
log: LogEntry[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const PLACES = [
|
|
34
|
+
{ latitude: 37.8199, longitude: -122.4783 },
|
|
35
|
+
{ latitude: 36.2704, longitude: -121.8081 },
|
|
36
|
+
{ latitude: 37.7456, longitude: -119.5936 },
|
|
37
|
+
{ latitude: 37.7749, longitude: -122.4194 },
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
type SampleSpec = [scene: SceneKind, seed: number, portrait: boolean, daysAgo: number, favorite: boolean, place: number | null]
|
|
41
|
+
|
|
42
|
+
const SAMPLES: SampleSpec[] = [
|
|
43
|
+
['mountains', 11, false, 0, false, 2],
|
|
44
|
+
['coffee', 4, true, 0, false, null],
|
|
45
|
+
['beach', 7, true, 1, true, 1],
|
|
46
|
+
['city', 3, true, 2, false, 3],
|
|
47
|
+
['salad', 9, false, 3, false, null],
|
|
48
|
+
['forest', 5, true, 4, false, 2],
|
|
49
|
+
['aurora', 2, false, 6, true, null],
|
|
50
|
+
['lake', 8, false, 8, false, 2],
|
|
51
|
+
['dunes', 6, true, 11, false, null],
|
|
52
|
+
['bokeh', 12, true, 13, false, null],
|
|
53
|
+
['mountains', 21, true, 16, false, 2],
|
|
54
|
+
['beach', 17, false, 19, false, 0],
|
|
55
|
+
['coffee', 14, false, 23, false, null],
|
|
56
|
+
['city', 13, false, 27, true, 3],
|
|
57
|
+
['forest', 15, false, 31, false, null],
|
|
58
|
+
['salad', 19, true, 36, false, null],
|
|
59
|
+
['lake', 18, true, 42, false, null],
|
|
60
|
+
['aurora', 22, true, 50, false, null],
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
const samples: StoredPhoto[] = SAMPLES.map(([scene, seed, portrait, daysAgo, favorite, place], n) => ({
|
|
64
|
+
n,
|
|
65
|
+
width: portrait ? 1200 : 1600,
|
|
66
|
+
height: portrait ? 1600 : 1200,
|
|
67
|
+
time: null,
|
|
68
|
+
// A little earlier for each sample, so they sort the same way every time.
|
|
69
|
+
ago: daysAgo * 86_400_000 + n * 7 * 60_000,
|
|
70
|
+
favorite,
|
|
71
|
+
location: place === null ? null : PLACES[place],
|
|
72
|
+
source: { kind: 'sample', scene, seed },
|
|
73
|
+
}))
|
|
74
|
+
|
|
75
|
+
const FOOD = ['salad', 'coffee']
|
|
76
|
+
const TRAVEL = ['mountains', 'lake', 'beach', 'city', 'aurora', 'dunes']
|
|
77
|
+
const inScenes = (scenes: string[]) => samples.filter((photo) => photo.source.kind === 'sample' && scenes.includes(photo.source.scene)).map((photo) => photo.n)
|
|
78
|
+
|
|
79
|
+
export const INITIAL_PHOTOS: PhotosState = {
|
|
80
|
+
photos: samples,
|
|
81
|
+
// 1 and 2 are iOS's Recents and Favorites.
|
|
82
|
+
albums: [
|
|
83
|
+
{ n: 3, title: 'Food', photos: inScenes(FOOD) },
|
|
84
|
+
{ n: 4, title: 'Travel', photos: inScenes(TRAVEL) },
|
|
85
|
+
],
|
|
86
|
+
next: 100,
|
|
87
|
+
log: [],
|
|
88
|
+
}
|