import { Match, Show, Switch, createEffect, createSignal, on, onCleanup, } from "solid-js"; import { Portal } from "solid-js/web"; import { Motion, Presence } from "solid-motionone"; import Panzoom, { PanzoomObject } from "@panzoom/panzoom"; import { css } from "styled-system/css"; import { styled } from "styled-system/jsx"; import { Column, Dialog, DialogProps, IconButton, Text } from "@revolt/ui"; import { Symbol } from "@revolt/ui/components/utils/Symbol"; import { Modals } from "../types"; export function ImageViewerModal( props: DialogProps & Modals & { type: "image_viewer" }, ) { const [ref, setRef] = createSignal(); let panzoom: PanzoomObject; createEffect( on( () => ref(), (ref) => { if (ref) { ref.addEventListener("mousedown", (e) => { // prevent panzoom from panning when // context menu is triggered (or other // non-dragging buttons are used!) if (e.button !== 0) { e.preventDefault(); } }); const zoom = Panzoom(ref, { minScale: 0.1, maxScale: 5, }); panzoom = zoom; function onMouseWheel(event: WheelEvent) { zoom.zoom(zoom.getScale() - event.deltaY / 1000); } document.addEventListener("mousewheel", onMouseWheel as never); onCleanup(() => { document.removeEventListener("mousewheel", onMouseWheel as never); zoom.destroy(); }); } }, ), ); return ( }> e.stopPropagation()}> {props.file!.filename} {props.file!.humanReadableSize} e.stopPropagation()}> panzoom?.zoomOut()}> zoom_out panzoom?.zoomIn()}> zoom_in download open_in_new close e.stopPropagation()} /> e.stopPropagation()} />
); } const Image = styled("img", { base: { minHeight: 0, alignSelf: "center", objectFit: "contain", background: "rgba(0, 0, 0, 0.6)", }, }); const Video = styled("video", { base: { minHeight: 0, alignSelf: "center", objectFit: "contain", background: "rgba(0, 0, 0, 0.6)", }, }); const Relative = styled("div", { base: { position: "relative", }, }); const Bar = styled("div", { base: { width: "100%", position: "absolute", height: "120px", flexShrink: 0, display: "flex", alignItems: "center", justifyContent: "space-between", }, }); const Card = styled("div", { base: { zIndex: 999, display: "flex", gap: "var(--gap-md)", padding: "var(--gap-md)", borderRadius: "var(--borderRadius-lg)", background: "var(--md-sys-color-surface)", color: "var(--md-sys-color-on-surface)", }, });