@opencode/ui 2.2.5 → 2.2.6
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/dist/actions/button/button.d.ts +2 -2
- package/dist/actions/icon-button/icon-button.d.ts +1 -1
- package/dist/components/animated-number-machine.d.ts +95 -0
- package/dist/components/file-icon-machine.d.ts +40 -0
- package/dist/components/file-icon.d.ts +0 -2
- package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
- package/dist/components/image-flight-machine.d.ts +135 -0
- package/dist/components/image-zoom-machine.d.ts +95 -0
- package/dist/components/image-zoom.d.ts +6 -3
- package/dist/components/list.d.ts +2 -6
- package/dist/components/menu-scroll.d.ts +9 -3
- package/dist/components/popover-machine.d.ts +96 -0
- package/dist/components/popover.d.ts +2 -2
- package/dist/components/resize-handle-machine.d.ts +71 -0
- package/dist/components/resize-handle.d.ts +2 -0
- package/dist/components/scroll-view-machine.d.ts +68 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/spinner.d.ts +11 -3
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -0
- package/dist/components/typewriter-machine.d.ts +62 -0
- package/dist/context/dialog-machine.d.ts +125 -0
- package/dist/context/dialog.d.ts +17 -16
- package/dist/data-display/line-comment/machine.d.ts +157 -0
- package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
- package/dist/data-display/project-avatar/animation.d.ts +1 -1
- package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
- package/dist/feedback/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/checkbox/checkbox.d.ts +6 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/select/select.d.ts +4 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/hooks/auto-scroll-machine.d.ts +89 -0
- package/dist/hooks/create-auto-scroll.d.ts +1 -1
- package/dist/hooks/list-machine.d.ts +150 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/dist/i18n/en.d.ts +5 -0
- package/dist/icons/catalog.d.ts +8 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/menu/menu.d.ts +5 -3
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
- package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
- package/dist/overlays/tooltip/machine.d.ts +146 -0
- package/dist/theme/context.d.ts +38 -14
- package/dist/theme/machine.d.ts +174 -0
- package/dist/typography/text-shimmer/machine.d.ts +48 -0
- package/package.json +19 -3
- package/src/actions/button/button.tsx +11 -6
- package/src/actions/icon-button/icon-button.tsx +17 -4
- package/src/components/animated-number-machine.ts +214 -0
- package/src/components/animated-number.tsx +134 -83
- package/src/components/file-icon-machine.ts +78 -0
- package/src/components/file-icon.tsx +96 -579
- package/src/components/file-icons/choose-icon-name.ts +574 -0
- package/src/components/image-flight-machine.ts +247 -0
- package/src/components/image-preview.css +5 -2
- package/src/components/image-preview.tsx +390 -252
- package/src/components/image-zoom-machine.ts +191 -0
- package/src/components/image-zoom.ts +22 -14
- package/src/components/list.tsx +46 -137
- package/src/components/menu-scroll.css +19 -8
- package/src/components/menu-scroll.tsx +111 -34
- package/src/components/popover-machine.ts +198 -0
- package/src/components/popover.tsx +157 -89
- package/src/components/resize-handle-machine.ts +174 -0
- package/src/components/resize-handle.tsx +116 -67
- package/src/components/scroll-view-machine.ts +244 -0
- package/src/components/scroll-view.tsx +163 -116
- package/src/components/spinner.css +18 -5
- package/src/components/spinner.tsx +28 -14
- package/src/components/text-field-machine.ts +102 -0
- package/src/components/text-field.tsx +78 -24
- package/src/components/text-reveal-machine.ts +184 -0
- package/src/components/text-reveal.tsx +96 -93
- package/src/components/typewriter-machine.ts +134 -0
- package/src/components/typewriter.tsx +50 -39
- package/src/context/dialog-machine.ts +280 -0
- package/src/context/dialog.tsx +168 -177
- package/src/data-display/line-comment/line-comment.tsx +157 -178
- package/src/data-display/line-comment/machine.ts +391 -0
- package/src/data-display/project-avatar/animation-machine.ts +182 -0
- package/src/data-display/project-avatar/animation.ts +67 -38
- package/src/feedback/activity-ring/activity-ring.tsx +1 -1
- package/src/feedback/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +55 -59
- package/src/forms/checkbox/checkbox-compact.css +169 -0
- package/src/forms/checkbox/checkbox.tsx +93 -31
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +4 -4
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.css +59 -17
- package/src/forms/select/select.tsx +67 -31
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +70 -62
- package/src/hooks/auto-scroll-machine.ts +261 -0
- package/src/hooks/create-auto-scroll.tsx +110 -205
- package/src/hooks/list-machine.ts +359 -0
- package/src/hooks/use-filtered-list.tsx +101 -112
- package/src/i18n/en.ts +6 -1
- package/src/icons/catalog.ts +8 -0
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +130 -22
- package/src/navigation/segmented-control/machine.ts +72 -0
- package/src/navigation/segmented-control/segmented-control.tsx +46 -46
- package/src/overlays/dialog/dialog.tsx +7 -1
- package/src/overlays/mcp-sign-in/machine.ts +343 -0
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
- package/src/overlays/tooltip/machine.ts +303 -0
- package/src/overlays/tooltip/tooltip.tsx +157 -92
- package/src/styles/theme.css +10 -2
- package/src/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/typography/text-shimmer/machine.ts +90 -0
- package/src/typography/text-shimmer/text-shimmer.css +71 -39
- package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Dialog as Kobalte, useDialogContext } from "@kobalte/core/dialog"
|
|
2
2
|
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
3
3
|
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
|
-
import { createEffect, createMemo, createSignal, on, onCleanup, Show } from "solid-js"
|
|
4
|
+
import { createEffect, createMemo, createSignal, on, onCleanup, Show, untrack } from "solid-js"
|
|
5
|
+
import { createStore } from "solid-js/store"
|
|
5
6
|
import { useDialogLayer } from "../context/dialog"
|
|
6
7
|
import { useI18n } from "../context/i18n"
|
|
7
8
|
import { Button } from "@opencode/ui/button"
|
|
@@ -19,6 +20,20 @@ import {
|
|
|
19
20
|
type FlightFrame,
|
|
20
21
|
} from "./image-flight"
|
|
21
22
|
import {
|
|
23
|
+
DECODE_TIMEOUT_MS,
|
|
24
|
+
INITIAL_PREVIEW_FLIGHT_STATE,
|
|
25
|
+
selectAwaitingReveal,
|
|
26
|
+
selectDecodeCurrent,
|
|
27
|
+
selectFlightFading,
|
|
28
|
+
selectFlightInteractive,
|
|
29
|
+
selectFlightStage,
|
|
30
|
+
selectVideoAtRest,
|
|
31
|
+
transitionPreviewFlight,
|
|
32
|
+
type PreviewFlightEffect,
|
|
33
|
+
type PreviewFlightEvent,
|
|
34
|
+
} from "./image-flight-machine"
|
|
35
|
+
import {
|
|
36
|
+
clampAxis,
|
|
22
37
|
clampView,
|
|
23
38
|
detailScale,
|
|
24
39
|
FIT_VIEW,
|
|
@@ -29,6 +44,15 @@ import {
|
|
|
29
44
|
zoomAt,
|
|
30
45
|
type ZoomView,
|
|
31
46
|
} from "./image-zoom"
|
|
47
|
+
import {
|
|
48
|
+
INITIAL_PREVIEW_ZOOM_STATE,
|
|
49
|
+
selectDragging,
|
|
50
|
+
selectPanPointer,
|
|
51
|
+
transitionPreviewZoom,
|
|
52
|
+
type PanTarget,
|
|
53
|
+
type PreviewZoomEffect,
|
|
54
|
+
type PreviewZoomEvent,
|
|
55
|
+
} from "./image-zoom-machine"
|
|
32
56
|
|
|
33
57
|
export interface ImagePreviewProps {
|
|
34
58
|
src: string
|
|
@@ -52,13 +76,19 @@ const fade = { duration: 0.15, bounce: 0 }
|
|
|
52
76
|
|
|
53
77
|
// How long the dialog stays mounted after a close starts, in milliseconds: the flight lands and hands the image back
|
|
54
78
|
// to the page well within this.
|
|
55
|
-
const
|
|
79
|
+
const EXIT_DURATION_MS = Math.max(FLIGHT_SPRING.duration, fade.duration) * 3200
|
|
56
80
|
|
|
57
81
|
const CENTER = { x: 0, y: 0 }
|
|
58
82
|
|
|
83
|
+
const SETTLED: PreviewFlightEvent = Object.freeze({ type: "motion.settled" })
|
|
84
|
+
|
|
85
|
+
// Previews closing at once, such as one still flying home under the next, share the body's closing mark.
|
|
86
|
+
let closingPreviews = 0
|
|
87
|
+
|
|
59
88
|
export function ImagePreview(props: ImagePreviewProps) {
|
|
60
89
|
const i18n = useI18n()
|
|
61
90
|
const dialog = useDialogContext()
|
|
91
|
+
const layer = useDialogLayer()
|
|
62
92
|
let root!: HTMLDivElement
|
|
63
93
|
let scrim!: HTMLDivElement
|
|
64
94
|
let content!: HTMLDivElement
|
|
@@ -71,13 +101,18 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
71
101
|
let surface!: HTMLDivElement
|
|
72
102
|
let edge!: HTMLDivElement
|
|
73
103
|
let close: HTMLButtonElement | undefined
|
|
104
|
+
|
|
74
105
|
// Nothing shows until the image has loaded and the preview knows where it lands; while flying, a stand-in image and
|
|
75
106
|
// its shadow travel above the dialog in place of the real one.
|
|
76
|
-
const [
|
|
107
|
+
const [flight, setFlight] = createSignal(INITIAL_PREVIEW_FLIGHT_STATE)
|
|
108
|
+
const [zoom, setZoom] = createSignal(INITIAL_PREVIEW_ZOOM_STATE)
|
|
109
|
+
// What the view shows the controls and the stylesheet, written only when it changes rather than on every frame.
|
|
110
|
+
const [shown, setShown] = createStore({ zoomed: false, ownsEscape: false, level: 100 })
|
|
77
111
|
|
|
78
|
-
// The flight under way: where the stand-in is laid out (the flight only transforms and clips it)
|
|
79
|
-
|
|
80
|
-
let
|
|
112
|
+
// The flight under way: where the stand-in is laid out (the flight only transforms and clips it) and the springs.
|
|
113
|
+
let course: { at: Box; flight: ReturnType<typeof createFlight> } | undefined
|
|
114
|
+
let flightJob: (() => void) | undefined
|
|
115
|
+
let decodeTimer: ReturnType<typeof setTimeout> | undefined
|
|
81
116
|
|
|
82
117
|
const dim = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
83
118
|
// Once a close lands, the stand-in fades out over the image the page shows again, so whatever the page draws over
|
|
@@ -86,162 +121,230 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
86
121
|
|
|
87
122
|
// How far the flight has lifted off the page, as last painted: the origin's outline fades out as it rises.
|
|
88
123
|
let lift = 0
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
124
|
+
|
|
125
|
+
// The view: each spring's value is what shows, and its target is where an eased zoom is heading, so repeated steps
|
|
126
|
+
// build on the destination rather than the frame in flight. Scale and offsets ride springs of one shape, so the point
|
|
127
|
+
// under the pointer stays put; a new target mid-glide keeps the velocity it has.
|
|
128
|
+
const scaleSpring = Spring.fromDuration(1, FLIGHT_SPRING)
|
|
129
|
+
const xSpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
130
|
+
const ySpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
131
|
+
let glideJob: (() => void) | undefined
|
|
132
|
+
// Where the pan under way last saw its pointer.
|
|
133
|
+
const cursor = { x: 0, y: 0 }
|
|
134
|
+
|
|
135
|
+
// Measured when the preview lays out rather than on every move or frame. A video zooms inside its own frame, so its
|
|
136
|
+
// controls stay where they are; an image zooms out across the window.
|
|
137
|
+
const natural = { width: 0, height: 0 }
|
|
138
|
+
const bounds = { width: 0, height: 0, viewportWidth: 0, viewportHeight: 0, maxScale: 1 }
|
|
139
|
+
let fitRatio = 1
|
|
140
|
+
|
|
141
|
+
// Reused on every pointer move of a pan.
|
|
142
|
+
const followEvent = { type: "follow" as const, zoomed: false }
|
|
143
|
+
const movedEvent = { type: "pointer.moved" as const, pointerId: 0 }
|
|
104
144
|
|
|
105
145
|
const percent = createMemo(() => new Intl.NumberFormat(i18n.locale(), { style: "percent", maximumFractionDigits: 0 }))
|
|
106
146
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: { width: image.width, height: image.height }
|
|
111
|
-
|
|
112
|
-
// A video zooms inside its own frame, so its controls stay where they are; an image zooms out across the window.
|
|
113
|
-
const bounds = () => ({
|
|
114
|
-
width: image.offsetWidth,
|
|
115
|
-
height: image.offsetHeight,
|
|
116
|
-
viewportWidth: props.video ? image.offsetWidth : viewport.clientWidth,
|
|
117
|
-
viewportHeight: props.video ? image.offsetHeight : viewport.clientHeight,
|
|
118
|
-
maxScale: maxScale(fitRatio()),
|
|
119
|
-
})
|
|
147
|
+
const dispatchFlight = (event: PreviewFlightEvent) => {
|
|
148
|
+
const prev = untrack(flight)
|
|
149
|
+
const next = transitionPreviewFlight(prev, event)
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
151
|
+
if (next.state !== prev) setFlight(next.state)
|
|
152
|
+
next.effects.forEach(runFlight)
|
|
153
|
+
}
|
|
123
154
|
|
|
124
|
-
const
|
|
125
|
-
|
|
155
|
+
const runFlight = (effect: PreviewFlightEffect) => {
|
|
156
|
+
if (effect.type === "decode.start") return decode(effect.attempt)
|
|
126
157
|
|
|
127
|
-
if (
|
|
128
|
-
props.video.style.setProperty("object-view-box", viewBox(next, size, natural()))
|
|
158
|
+
if (effect.type === "decode.cancel") return clearTimeout(decodeTimer)
|
|
129
159
|
|
|
130
|
-
|
|
131
|
-
}
|
|
160
|
+
if (effect.type === "video.borrow") return borrow()
|
|
132
161
|
|
|
133
|
-
|
|
134
|
-
}
|
|
162
|
+
if (effect.type === "video.return") return giveBack()
|
|
135
163
|
|
|
136
|
-
|
|
137
|
-
gliding?.()
|
|
138
|
-
gliding = undefined
|
|
139
|
-
}
|
|
164
|
+
if (effect.type === "origin.hide") return home()?.setAttribute("data-image-preview-origin", "")
|
|
140
165
|
|
|
141
|
-
|
|
142
|
-
const follow = (next: ZoomView) => {
|
|
143
|
-
settle()
|
|
144
|
-
setGoal(next)
|
|
145
|
-
show(next)
|
|
146
|
-
}
|
|
166
|
+
if (effect.type === "origin.show") return home()?.removeAttribute("data-image-preview-origin")
|
|
147
167
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
168
|
+
if (effect.type === "open.flight") {
|
|
169
|
+
dimTo(1, FLIGHT_SPRING)
|
|
170
|
+
const next = createFlight(effect.from)
|
|
171
|
+
next.to(restFrame(), KICK.open, FLIGHT_SPRING)
|
|
172
|
+
course = { at: place(fitted()), flight: next }
|
|
173
|
+
paint()
|
|
152
174
|
|
|
153
|
-
|
|
175
|
+
return run()
|
|
176
|
+
}
|
|
154
177
|
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
gliding ??= frameLoop.add((dt) => {
|
|
158
|
-
const [scale, x, y] = glide.map((spring) => spring.step(dt))
|
|
159
|
-
show({ scale, x, y })
|
|
178
|
+
if (effect.type === "open.fade") {
|
|
179
|
+
dimTo(1, fade)
|
|
160
180
|
|
|
161
|
-
if (
|
|
162
|
-
|
|
181
|
+
if (props.video) place(fitted())
|
|
182
|
+
paint()
|
|
163
183
|
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
}
|
|
184
|
+
return run()
|
|
185
|
+
}
|
|
167
186
|
|
|
168
|
-
|
|
187
|
+
if (effect.type === "close.flight") {
|
|
188
|
+
dimTo(0, FLIGHT_SPRING)
|
|
169
189
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
190
|
+
if (!effect.turn) course = { at: place(fitted()), flight: createFlight(restFrame()) }
|
|
191
|
+
course?.flight.to(effect.to, KICK.close, FLIGHT_SPRING)
|
|
192
|
+
paint()
|
|
173
193
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
layer?.setExitDuration(exit())
|
|
177
|
-
}
|
|
194
|
+
return run()
|
|
195
|
+
}
|
|
178
196
|
|
|
179
|
-
|
|
197
|
+
if (effect.type === "close.veil") {
|
|
198
|
+
veil.omega = (2 * Math.PI) / (FLIGHT_SPRING.duration * 0.75)
|
|
199
|
+
veil.set(0)
|
|
180
200
|
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
return
|
|
202
|
+
}
|
|
183
203
|
|
|
184
|
-
if (
|
|
185
|
-
|
|
204
|
+
if (effect.type === "close.fade") {
|
|
205
|
+
course = undefined
|
|
206
|
+
dimTo(0, fade)
|
|
186
207
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
dimTo(1, from ? FLIGHT_SPRING : fade)
|
|
208
|
+
return run()
|
|
209
|
+
}
|
|
190
210
|
|
|
191
|
-
if (
|
|
192
|
-
plain = true
|
|
211
|
+
if (effect.type === "zoom.fit") return ease(FIT_VIEW)
|
|
193
212
|
|
|
194
|
-
|
|
195
|
-
paint()
|
|
196
|
-
setStage("rest")
|
|
213
|
+
if (effect.type === "zoom.settle") return follow(scaleSpring.value, xSpring.value, ySpring.value)
|
|
197
214
|
|
|
198
|
-
|
|
215
|
+
// See image-preview.css: the body takes clicks again while the closing flight holds the dialog mounted.
|
|
216
|
+
if (effect.type === "body.closing.acquire") {
|
|
217
|
+
closingPreviews++
|
|
218
|
+
document.body.setAttribute("data-image-preview-closing", "")
|
|
219
|
+
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (effect.type === "body.closing.release") {
|
|
224
|
+
closingPreviews--
|
|
225
|
+
|
|
226
|
+
if (!closingPreviews) document.body.removeAttribute("data-image-preview-closing")
|
|
227
|
+
|
|
228
|
+
return
|
|
199
229
|
}
|
|
200
230
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
flight.to(rest, KICK.open, FLIGHT_SPRING)
|
|
204
|
-
course = { at: place(fitted()), flight, landed: () => setStage("rest") }
|
|
205
|
-
hideOrigin()
|
|
206
|
-
paint()
|
|
207
|
-
setStage("flying")
|
|
208
|
-
run()
|
|
231
|
+
flightJob?.()
|
|
232
|
+
flightJob = undefined
|
|
209
233
|
}
|
|
210
234
|
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
235
|
+
const dispatchZoom = (event: PreviewZoomEvent) => {
|
|
236
|
+
const prev = untrack(zoom)
|
|
237
|
+
const next = transitionPreviewZoom(prev, event)
|
|
238
|
+
|
|
239
|
+
if (next.state !== prev) setZoom(next.state)
|
|
240
|
+
next.effects.forEach(runZoom)
|
|
241
|
+
}
|
|
215
242
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
dimTo(0, to ? FLIGHT_SPRING : fade)
|
|
243
|
+
const runZoom = (effect: PreviewZoomEffect) => {
|
|
244
|
+
if (effect.type === "pointer.capture") return panElement(effect.target).setPointerCapture(effect.pointerId)
|
|
219
245
|
|
|
220
|
-
if (
|
|
221
|
-
|
|
246
|
+
if (effect.type === "pointer.release") {
|
|
247
|
+
const element = panElement(effect.target)
|
|
222
248
|
|
|
223
|
-
|
|
249
|
+
if (element.hasPointerCapture(effect.pointerId)) element.releasePointerCapture(effect.pointerId)
|
|
250
|
+
|
|
251
|
+
return
|
|
224
252
|
}
|
|
225
253
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
254
|
+
if (effect.type === "glide.loop.start") {
|
|
255
|
+
glideJob = frameLoop.add((dt) => {
|
|
256
|
+
scaleSpring.step(dt)
|
|
257
|
+
xSpring.step(dt)
|
|
258
|
+
ySpring.step(dt)
|
|
259
|
+
paintZoom()
|
|
260
|
+
|
|
261
|
+
if (!scaleSpring.resting || !xSpring.resting || !ySpring.resting) return true
|
|
262
|
+
dispatchZoom({ type: "glide.settled", zoomed: scaleSpring.value > 1 })
|
|
263
|
+
|
|
264
|
+
return false
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
return
|
|
230
268
|
}
|
|
231
269
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
270
|
+
if (effect.type === "glide.loop.stop") {
|
|
271
|
+
glideJob?.()
|
|
272
|
+
glideJob = undefined
|
|
235
273
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (effect.type === "video.suppress-click") return suppressVideoClick()
|
|
278
|
+
|
|
279
|
+
dialog.close()
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Writes the view to the DOM. A frame allocates nothing but the style string, and touches Solid state only when
|
|
283
|
+
// the zoom level's rounded percent or whether the image is zoomed changes.
|
|
284
|
+
const paintZoom = () => {
|
|
285
|
+
const scale = scaleSpring.value
|
|
286
|
+
|
|
287
|
+
if (props.video) {
|
|
288
|
+
props.video.style.setProperty("object-view-box", viewBox(scale, xSpring.value, ySpring.value, bounds, natural))
|
|
239
289
|
}
|
|
240
290
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
291
|
+
if (!props.video) image.style.transform = `translate(${xSpring.value}px, ${ySpring.value}px) scale(${scale})`
|
|
292
|
+
const level = Math.round(scale * fitRatio * 100)
|
|
293
|
+
|
|
294
|
+
if (shown.zoomed !== scale > 1) setShown("zoomed", scale > 1)
|
|
295
|
+
|
|
296
|
+
if (shown.level !== level) setShown("level", level)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const view = (): ZoomView => ({ scale: scaleSpring.value, x: xSpring.value, y: ySpring.value })
|
|
300
|
+
const goal = (): ZoomView => ({ scale: scaleSpring.target, x: xSpring.target, y: ySpring.target })
|
|
301
|
+
|
|
302
|
+
const own = (scale: number) => {
|
|
303
|
+
if (shown.ownsEscape !== scale > 1) setShown("ownsEscape", scale > 1)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Pinch, wheel and drag follow the hand directly and take over from an eased zoom mid-flight.
|
|
307
|
+
const follow = (scale: number, x: number, y: number) => {
|
|
308
|
+
followEvent.zoomed = scale > 1
|
|
309
|
+
dispatchZoom(followEvent)
|
|
310
|
+
scaleSpring.snap(scale)
|
|
311
|
+
xSpring.snap(x)
|
|
312
|
+
ySpring.snap(y)
|
|
313
|
+
own(scale)
|
|
314
|
+
paintZoom()
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const ease = (target: ZoomView) => {
|
|
318
|
+
if (prefersReducedMotion()) return follow(target.scale, target.x, target.y)
|
|
319
|
+
scaleSpring.set(target.scale)
|
|
320
|
+
xSpring.set(target.x)
|
|
321
|
+
ySpring.set(target.y)
|
|
322
|
+
own(target.scale)
|
|
323
|
+
dispatchZoom({ type: "glide.start" })
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const step = (factor: number) => {
|
|
327
|
+
const target = goal()
|
|
328
|
+
ease(zoomAt(target, target.scale * factor, CENTER, bounds))
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Kobalte keeps the content mounted while an exit animation runs; the dialog stack waits for the flight too.
|
|
332
|
+
layer?.setExitDuration(EXIT_DURATION_MS)
|
|
333
|
+
|
|
334
|
+
const decode = (attempt: number) => {
|
|
335
|
+
clearTimeout(decodeTimer)
|
|
336
|
+
decodeTimer = setTimeout(() => decoded(attempt), DECODE_TIMEOUT_MS)
|
|
337
|
+
|
|
338
|
+
if (!(image instanceof HTMLImageElement)) return
|
|
339
|
+
void Promise.all([image.decode(), standIn?.decode()])
|
|
340
|
+
.catch(() => undefined)
|
|
341
|
+
.then(() => decoded(attempt))
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Measuring where the origin shows is not free, so a decode the preview no longer waits for skips it.
|
|
345
|
+
const decoded = (attempt: number) => {
|
|
346
|
+
if (!selectDecodeCurrent(untrack(flight), attempt)) return
|
|
347
|
+
dispatchFlight({ type: "decode.ready", attempt, origin: originFrame() })
|
|
245
348
|
}
|
|
246
349
|
|
|
247
350
|
const dimTo = (target: number, spring: DurationOptions) => {
|
|
@@ -252,7 +355,7 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
252
355
|
|
|
253
356
|
// One job on the shared frame loop steps the flight and the backdrop together and writes them straight to the DOM.
|
|
254
357
|
const run = () => {
|
|
255
|
-
|
|
358
|
+
flightJob ??= frameLoop.add((dt) => {
|
|
256
359
|
const flying = course?.flight.step(dt)
|
|
257
360
|
dim.step(dt)
|
|
258
361
|
veil.step(dt)
|
|
@@ -260,16 +363,13 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
260
363
|
|
|
261
364
|
// The real image takes over only once the panel holding it is fully opaque, so its brightness doesn't step.
|
|
262
365
|
if (course && !flying && dim.resting) {
|
|
263
|
-
const landed = course.landed
|
|
264
366
|
course = undefined
|
|
265
|
-
|
|
367
|
+
dispatchFlight(SETTLED)
|
|
266
368
|
}
|
|
267
369
|
|
|
268
370
|
if (course || !dim.resting || !veil.resting) return true
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
// A video that faded out rather than flying home goes back once it has.
|
|
272
|
-
if (!dialog.isOpen()) giveBack()
|
|
371
|
+
flightJob = undefined
|
|
372
|
+
dispatchFlight(SETTLED)
|
|
273
373
|
|
|
274
374
|
return false
|
|
275
375
|
})
|
|
@@ -280,6 +380,8 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
280
380
|
|
|
281
381
|
const paint = () => {
|
|
282
382
|
const flying = flyer()
|
|
383
|
+
// Without a flight (reduced motion, or nothing on the page to fly to) the preview only fades with the backdrop.
|
|
384
|
+
const plain = selectFlightFading(untrack(flight))
|
|
283
385
|
scrim.style.opacity = String(dim.value)
|
|
284
386
|
surface.style.opacity = course ? "1" : "0"
|
|
285
387
|
|
|
@@ -310,19 +412,20 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
310
412
|
const place = (box: Box) => {
|
|
311
413
|
const flying = flyer()
|
|
312
414
|
|
|
313
|
-
if (flying)
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
height: `${box.height}px`,
|
|
319
|
-
})
|
|
415
|
+
if (!flying) return box
|
|
416
|
+
flying.style.left = `${box.x}px`
|
|
417
|
+
flying.style.top = `${box.y}px`
|
|
418
|
+
flying.style.width = `${box.width}px`
|
|
419
|
+
flying.style.height = `${box.height}px`
|
|
320
420
|
|
|
321
421
|
return box
|
|
322
422
|
}
|
|
323
423
|
|
|
324
424
|
// Moves the video into the preview, leaving a box of its size in its place to fly back to.
|
|
325
|
-
const borrow = (
|
|
425
|
+
const borrow = () => {
|
|
426
|
+
const video = props.video
|
|
427
|
+
|
|
428
|
+
if (!video) return
|
|
326
429
|
const rect = video.getBoundingClientRect()
|
|
327
430
|
holder = document.createElement("div")
|
|
328
431
|
Object.assign(holder.style, {
|
|
@@ -352,19 +455,23 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
352
455
|
|
|
353
456
|
// The image as shown now, zoomed and panned and cropped to the viewport. There is no panel: the image is the surface.
|
|
354
457
|
const restFrame = (): FlightFrame => {
|
|
355
|
-
const
|
|
356
|
-
const clip = intersect(
|
|
357
|
-
const cropped = clip.width <
|
|
358
|
-
|
|
458
|
+
const shownBox = image.getBoundingClientRect()
|
|
459
|
+
const clip = intersect(shownBox, viewport.getBoundingClientRect())
|
|
460
|
+
const cropped = clip.width < shownBox.width - 0.5 || clip.height < shownBox.height - 0.5
|
|
461
|
+
|
|
462
|
+
const radius = cropped
|
|
463
|
+
? 0
|
|
464
|
+
: parseFloat(getComputedStyle(image).borderTopLeftRadius) * (props.video ? 1 : scaleSpring.value)
|
|
359
465
|
|
|
360
|
-
return { image:
|
|
466
|
+
return { image: shownBox, clip, radius, surface: clip, surfaceRadius: radius, lift: 1 }
|
|
361
467
|
}
|
|
362
468
|
|
|
363
|
-
// The origin's frame, cropped to the part the page shows, or nothing when it is gone
|
|
469
|
+
// The origin's frame, cropped to the part the page shows, or nothing when it is gone, out of sight, or motion is
|
|
470
|
+
// reduced.
|
|
364
471
|
const originFrame = () => {
|
|
365
472
|
const origin = home()
|
|
366
473
|
|
|
367
|
-
if (!origin?.isConnected || !natural
|
|
474
|
+
if (prefersReducedMotion() || !origin?.isConnected || !natural.width) return
|
|
368
475
|
const rect = origin.getBoundingClientRect()
|
|
369
476
|
|
|
370
477
|
if (!rect.width || !rect.height) return
|
|
@@ -379,46 +486,52 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
379
486
|
? "none"
|
|
380
487
|
: ([style.boxShadow, getComputedStyle(origin, "::after").boxShadow].find((shadow) => shadow !== "none") ?? "none")
|
|
381
488
|
|
|
382
|
-
return elementFrame(rect, natural
|
|
489
|
+
return elementFrame(rect, natural, style.objectFit, parseFloat(style.borderTopLeftRadius) || 0, visible)
|
|
383
490
|
}
|
|
384
491
|
|
|
385
492
|
// The image's fitted layout box, wherever zoom has moved it. A video zooms inside its box, which stays put.
|
|
386
493
|
const fitted = (): Box => {
|
|
387
|
-
const
|
|
388
|
-
const
|
|
494
|
+
const shownBox = image.getBoundingClientRect()
|
|
495
|
+
const x = props.video ? 0 : xSpring.value
|
|
496
|
+
const y = props.video ? 0 : ySpring.value
|
|
389
497
|
|
|
390
498
|
return {
|
|
391
|
-
x:
|
|
392
|
-
y:
|
|
499
|
+
x: shownBox.x + shownBox.width / 2 - x - image.offsetWidth / 2,
|
|
500
|
+
y: shownBox.y + shownBox.height / 2 - y - image.offsetHeight / 2,
|
|
393
501
|
width: image.offsetWidth,
|
|
394
502
|
height: image.offsetHeight,
|
|
395
503
|
}
|
|
396
504
|
}
|
|
397
505
|
|
|
398
|
-
const scale = () => (props.video ? 1 : view().scale)
|
|
399
506
|
const home = () => holder ?? props.origin ?? props.video
|
|
400
|
-
const
|
|
401
|
-
|
|
507
|
+
const panElement = (target: PanTarget) => (target === "video" && props.video ? props.video : viewport)
|
|
508
|
+
|
|
509
|
+
const suppressVideoClick = () => {
|
|
510
|
+
const video = props.video
|
|
511
|
+
|
|
512
|
+
if (!video) return
|
|
513
|
+
|
|
514
|
+
const swallow = (event: MouseEvent) => {
|
|
515
|
+
event.preventDefault()
|
|
516
|
+
event.stopImmediatePropagation()
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// The click follows its pointerup in the same task; one that never comes must not swallow a later one.
|
|
520
|
+
video.addEventListener("click", swallow, { capture: true, once: true })
|
|
521
|
+
setTimeout(() => video.removeEventListener("click", swallow, { capture: true }))
|
|
522
|
+
}
|
|
402
523
|
|
|
403
524
|
onCleanup(() => {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
showOrigin()
|
|
407
|
-
giveBack()
|
|
408
|
-
document.body.removeAttribute("data-image-preview-closing")
|
|
525
|
+
dispatchFlight({ type: "disposed" })
|
|
526
|
+
dispatchZoom({ type: "disposed" })
|
|
409
527
|
})
|
|
410
528
|
|
|
411
|
-
|
|
412
|
-
on(
|
|
413
|
-
() => dialog.isOpen(),
|
|
414
|
-
(open) => {
|
|
415
|
-
// See image-preview.css: the body takes clicks again while the closing flight holds the dialog mounted.
|
|
416
|
-
document.body.toggleAttribute("data-image-preview-closing", !open)
|
|
529
|
+
const closing = () => (layer ? layer.closing() : !dialog.isOpen())
|
|
417
530
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
{
|
|
421
|
-
),
|
|
531
|
+
createEffect(
|
|
532
|
+
on(closing, (value) => {
|
|
533
|
+
if (value) dispatchFlight({ type: "close.started", origin: originFrame() })
|
|
534
|
+
}),
|
|
422
535
|
)
|
|
423
536
|
|
|
424
537
|
// From the center of the box zoom is measured in: the window's for an image, the frame's for a video.
|
|
@@ -429,17 +542,25 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
429
542
|
}
|
|
430
543
|
|
|
431
544
|
const measure = () => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
545
|
+
natural.width = image instanceof HTMLImageElement ? image.naturalWidth : image.width
|
|
546
|
+
natural.height = image instanceof HTMLImageElement ? image.naturalHeight : image.height
|
|
547
|
+
|
|
548
|
+
if (!natural.width || !image.offsetWidth) return
|
|
549
|
+
bounds.width = image.offsetWidth
|
|
550
|
+
bounds.height = image.offsetHeight
|
|
551
|
+
bounds.viewportWidth = props.video ? image.offsetWidth : viewport.clientWidth
|
|
552
|
+
bounds.viewportHeight = props.video ? image.offsetHeight : viewport.clientHeight
|
|
553
|
+
fitRatio = bounds.width / natural.width
|
|
554
|
+
bounds.maxScale = maxScale(fitRatio)
|
|
555
|
+
const next = clampView(view(), bounds)
|
|
556
|
+
follow(next.scale, next.x, next.y)
|
|
436
557
|
|
|
437
558
|
if (!props.video) return
|
|
438
559
|
|
|
439
560
|
// A video is ready as soon as the preview has laid out its box.
|
|
440
|
-
if (
|
|
561
|
+
if (selectAwaitingReveal(untrack(flight))) return dispatchFlight({ type: "video.ready", origin: originFrame() })
|
|
441
562
|
|
|
442
|
-
if (
|
|
563
|
+
if (selectVideoAtRest(untrack(flight))) place(fitted())
|
|
443
564
|
}
|
|
444
565
|
|
|
445
566
|
createResizeObserver(() => [viewport, image], measure)
|
|
@@ -447,59 +568,75 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
447
568
|
createEffect(
|
|
448
569
|
on(
|
|
449
570
|
() => props.src,
|
|
450
|
-
() =>
|
|
571
|
+
() => {
|
|
572
|
+
dispatchFlight({ type: "src.changed" })
|
|
573
|
+
follow(FIT_VIEW.scale, FIT_VIEW.x, FIT_VIEW.y)
|
|
574
|
+
},
|
|
451
575
|
{ defer: true },
|
|
452
576
|
),
|
|
453
577
|
)
|
|
454
578
|
|
|
579
|
+
const interactive = () => selectFlightInteractive(untrack(flight))
|
|
580
|
+
|
|
455
581
|
const detail = (event: MouseEvent) => {
|
|
456
|
-
if (
|
|
457
|
-
|
|
582
|
+
if (!interactive()) return
|
|
583
|
+
|
|
584
|
+
if (scaleSpring.target > 1) return ease(FIT_VIEW)
|
|
585
|
+
ease(zoomAt(goal(), detailScale(fitRatio), point(event), bounds))
|
|
458
586
|
}
|
|
459
587
|
|
|
460
|
-
const
|
|
461
|
-
if (
|
|
588
|
+
const press = (event: PointerEvent, target: PanTarget | "content", onBackdrop: boolean) => {
|
|
589
|
+
if (!interactive()) return
|
|
590
|
+
dispatchZoom({
|
|
591
|
+
type: "pointer.down",
|
|
592
|
+
pointerId: event.pointerId,
|
|
593
|
+
button: event.button,
|
|
594
|
+
target,
|
|
595
|
+
onBackdrop,
|
|
596
|
+
zoomed: scaleSpring.value > 1,
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
462
600
|
event.preventDefault()
|
|
463
|
-
|
|
464
|
-
|
|
601
|
+
cursor.x = event.clientX
|
|
602
|
+
cursor.y = event.clientY
|
|
465
603
|
}
|
|
466
604
|
|
|
605
|
+
// The hot path of a pan: no layout reads, and no Solid writes once the pan has moved.
|
|
467
606
|
const pan = (event: PointerEvent) => {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
607
|
+
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
608
|
+
|
|
609
|
+
// The button came up without a pointerup reaching the preview, so this is a hover, not a drag.
|
|
610
|
+
if ((event.buttons & 1) === 0) return dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
611
|
+
const dx = event.clientX - cursor.x
|
|
612
|
+
const dy = event.clientY - cursor.y
|
|
613
|
+
|
|
614
|
+
if (dx === 0 && dy === 0) return
|
|
615
|
+
cursor.x = event.clientX
|
|
616
|
+
cursor.y = event.clientY
|
|
617
|
+
movedEvent.pointerId = event.pointerId
|
|
618
|
+
dispatchZoom(movedEvent)
|
|
619
|
+
const scale = scaleSpring.value
|
|
620
|
+
follow(
|
|
621
|
+
scale,
|
|
622
|
+
clampAxis(xSpring.value + dx, bounds.width * scale, bounds.viewportWidth),
|
|
623
|
+
clampAxis(ySpring.value + dy, bounds.height * scale, bounds.viewportHeight),
|
|
624
|
+
)
|
|
475
625
|
}
|
|
476
626
|
|
|
477
|
-
const release = (event: PointerEvent) => {
|
|
478
|
-
|
|
479
|
-
}
|
|
627
|
+
const release = (event: PointerEvent) => dispatchZoom({ type: "pointer.up", pointerId: event.pointerId })
|
|
628
|
+
const cancel = (event: PointerEvent) => dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
480
629
|
|
|
481
630
|
if (props.video) {
|
|
482
631
|
const video = props.video
|
|
483
632
|
makeEventListener(video, "pointerdown", (event: PointerEvent) => {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (holder && event.clientY < video.getBoundingClientRect().bottom - CONTROLS) grab(event, video)
|
|
633
|
+
if (event.clientY < video.getBoundingClientRect().bottom - CONTROLS) press(event, "video", false)
|
|
487
634
|
})
|
|
488
635
|
makeEventListener(video, "pointermove", pan)
|
|
489
636
|
makeEventListener(video, "pointerup", release)
|
|
490
|
-
makeEventListener(video, "pointercancel",
|
|
491
|
-
makeEventListener(video, "
|
|
492
|
-
makeEventListener(
|
|
493
|
-
video,
|
|
494
|
-
"click",
|
|
495
|
-
(event: MouseEvent) => {
|
|
496
|
-
if (!panned) return
|
|
497
|
-
panned = false
|
|
498
|
-
event.preventDefault()
|
|
499
|
-
event.stopImmediatePropagation()
|
|
500
|
-
},
|
|
501
|
-
{ capture: true },
|
|
502
|
-
)
|
|
637
|
+
makeEventListener(video, "pointercancel", cancel)
|
|
638
|
+
makeEventListener(video, "lostpointercapture", cancel)
|
|
639
|
+
makeEventListener(video, "dblclick", detail)
|
|
503
640
|
}
|
|
504
641
|
|
|
505
642
|
// The preview owns zoom gestures while it is open: the page behind must neither scroll nor zoom the whole window.
|
|
@@ -507,35 +644,23 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
507
644
|
window,
|
|
508
645
|
"wheel",
|
|
509
646
|
(event: WheelEvent) => {
|
|
510
|
-
|
|
511
|
-
|
|
647
|
+
if (!interactive()) return
|
|
648
|
+
const inside = event.target instanceof Node && (viewport.contains(event.target) || event.target === props.video)
|
|
512
649
|
|
|
513
|
-
const
|
|
650
|
+
const pinch = event.ctrlKey || event.metaKey
|
|
514
651
|
|
|
515
|
-
if (!inside && !
|
|
652
|
+
if (!inside && !pinch) return
|
|
516
653
|
event.preventDefault()
|
|
517
654
|
event.stopPropagation()
|
|
518
655
|
|
|
519
656
|
if (!inside) return
|
|
520
657
|
const current = view()
|
|
521
658
|
|
|
522
|
-
|
|
523
|
-
|
|
659
|
+
const next = pinch
|
|
660
|
+
? zoomAt(current, current.scale * wheelZoomFactor(pixels(event, event.deltaY)), point(event), bounds)
|
|
661
|
+
: panBy(current, wheelPan(event), bounds)
|
|
524
662
|
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const horizontal = event.shiftKey && event.deltaX === 0
|
|
529
|
-
follow(
|
|
530
|
-
panBy(
|
|
531
|
-
current,
|
|
532
|
-
{
|
|
533
|
-
x: -pixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
534
|
-
y: horizontal ? 0 : -pixels(event, event.deltaY),
|
|
535
|
-
},
|
|
536
|
-
bounds(),
|
|
537
|
-
),
|
|
538
|
-
)
|
|
663
|
+
follow(next.scale, next.x, next.y)
|
|
539
664
|
},
|
|
540
665
|
{ passive: false, capture: true },
|
|
541
666
|
)
|
|
@@ -545,9 +670,10 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
545
670
|
window,
|
|
546
671
|
"keydown",
|
|
547
672
|
(event: KeyboardEvent) => {
|
|
673
|
+
if (!interactive()) return
|
|
548
674
|
const bare = !event.metaKey && !event.ctrlKey && !event.altKey
|
|
549
675
|
|
|
550
|
-
if (bare && event.key === " " && props.video
|
|
676
|
+
if (bare && event.key === " " && props.video) {
|
|
551
677
|
event.preventDefault()
|
|
552
678
|
event.stopPropagation()
|
|
553
679
|
|
|
@@ -572,10 +698,10 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
572
698
|
<div
|
|
573
699
|
ref={root}
|
|
574
700
|
data-component="image-preview"
|
|
575
|
-
data-stage={
|
|
701
|
+
data-stage={selectFlightStage(flight())}
|
|
576
702
|
// Zoomed in, the first Escape zooms back out; the dialog stack leaves it to the preview.
|
|
577
|
-
data-owns-escape={
|
|
578
|
-
style={{ "--image-preview-exit": `${
|
|
703
|
+
data-owns-escape={shown.ownsEscape ? "" : undefined}
|
|
704
|
+
style={{ "--image-preview-exit": `${EXIT_DURATION_MS}ms` }}
|
|
579
705
|
>
|
|
580
706
|
<div ref={scrim} data-slot="image-preview-scrim" />
|
|
581
707
|
<Kobalte.Content
|
|
@@ -587,7 +713,7 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
587
713
|
close?.focus()
|
|
588
714
|
}}
|
|
589
715
|
onEscapeKeyDown={(event) => {
|
|
590
|
-
if (
|
|
716
|
+
if (scaleSpring.target <= 1) return
|
|
591
717
|
event.preventDefault()
|
|
592
718
|
ease(FIT_VIEW)
|
|
593
719
|
}}
|
|
@@ -596,24 +722,28 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
596
722
|
if (props.video && event.target === props.video) event.preventDefault()
|
|
597
723
|
}}
|
|
598
724
|
onPointerDown={(event: PointerEvent) => {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
// The preview fills the window, so a click on the backdrop around the image lands here rather than outside.
|
|
603
|
-
if (!backdrop || (event.target !== content && event.target !== viewport)) return
|
|
604
|
-
dialog.close()
|
|
725
|
+
const target = event.target
|
|
726
|
+
const body = target instanceof Node && viewport.contains(target)
|
|
727
|
+
press(event, body ? "viewport" : "content", target === content || target === viewport)
|
|
605
728
|
}}
|
|
729
|
+
// The preview fills the window, so a click on the backdrop around the image lands here rather than outside.
|
|
730
|
+
onClick={(event: MouseEvent) =>
|
|
731
|
+
dispatchZoom({
|
|
732
|
+
type: "backdrop.click",
|
|
733
|
+
onBackdrop: event.target === content || event.target === viewport,
|
|
734
|
+
})
|
|
735
|
+
}
|
|
606
736
|
>
|
|
607
737
|
<div
|
|
608
738
|
ref={viewport}
|
|
609
739
|
data-slot="image-preview-body"
|
|
610
|
-
data-zoomed={
|
|
611
|
-
data-dragging={
|
|
740
|
+
data-zoomed={shown.zoomed ? "" : undefined}
|
|
741
|
+
data-dragging={selectDragging(zoom()) ? "" : undefined}
|
|
612
742
|
onDblClick={detail}
|
|
613
|
-
onPointerDown={(event) => grab(event, viewport)}
|
|
614
743
|
onPointerMove={pan}
|
|
615
744
|
onPointerUp={release}
|
|
616
|
-
onPointerCancel={
|
|
745
|
+
onPointerCancel={cancel}
|
|
746
|
+
onLostPointerCapture={cancel}
|
|
617
747
|
>
|
|
618
748
|
<Show
|
|
619
749
|
when={props.video}
|
|
@@ -626,9 +756,9 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
626
756
|
draggable={false}
|
|
627
757
|
onLoad={() => {
|
|
628
758
|
measure()
|
|
629
|
-
|
|
759
|
+
dispatchFlight({ type: "image.loaded" })
|
|
630
760
|
}}
|
|
631
|
-
onError={() =>
|
|
761
|
+
onError={() => dispatchFlight({ type: "image.failed" })}
|
|
632
762
|
/>
|
|
633
763
|
}
|
|
634
764
|
>
|
|
@@ -658,7 +788,7 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
658
788
|
title={i18n.t("ui.imagePreview.zoomToFit")}
|
|
659
789
|
onClick={() => ease(FIT_VIEW)}
|
|
660
790
|
>
|
|
661
|
-
{percent().format(
|
|
791
|
+
{percent().format(shown.level / 100)}
|
|
662
792
|
</Button>
|
|
663
793
|
<IconButton
|
|
664
794
|
data-slot="image-preview-zoom-in"
|
|
@@ -758,13 +888,11 @@ function dispose(video: HTMLVideoElement) {
|
|
|
758
888
|
}
|
|
759
889
|
|
|
760
890
|
function layout(element: HTMLElement, frame: Box, radius: number) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
borderRadius: `${radius}px`,
|
|
767
|
-
})
|
|
891
|
+
element.style.left = `${frame.x}px`
|
|
892
|
+
element.style.top = `${frame.y}px`
|
|
893
|
+
element.style.width = `${frame.width}px`
|
|
894
|
+
element.style.height = `${frame.height}px`
|
|
895
|
+
element.style.borderRadius = `${radius}px`
|
|
768
896
|
}
|
|
769
897
|
|
|
770
898
|
function shortcut(key: string) {
|
|
@@ -775,6 +903,16 @@ function shortcut(key: string) {
|
|
|
775
903
|
if (key === "0") return "fit"
|
|
776
904
|
}
|
|
777
905
|
|
|
906
|
+
// A plain wheel pans; Shift turns a vertical wheel sideways.
|
|
907
|
+
function wheelPan(event: WheelEvent) {
|
|
908
|
+
const horizontal = event.shiftKey && event.deltaX === 0
|
|
909
|
+
|
|
910
|
+
return {
|
|
911
|
+
x: -pixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
912
|
+
y: horizontal ? 0 : -pixels(event, event.deltaY),
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
778
916
|
function pixels(event: WheelEvent, delta: number) {
|
|
779
917
|
if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) return delta * 16
|
|
780
918
|
|