pl-fe: support static url in StillImage

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2025-10-27 05:25:33 +01:00
parent da860225ad
commit 56af5a26dd
2 changed files with 17 additions and 11 deletions

View File

@ -12,6 +12,8 @@ interface IStillImage {
innerClassName?: string; innerClassName?: string;
/** URL to the image */ /** URL to the image */
src: string; src: string;
/** URL to the static image */
staticSrc?: string;
/** Extra CSS styles on the outer <div> element. */ /** Extra CSS styles on the outer <div> element. */
style?: React.CSSProperties; style?: React.CSSProperties;
/** Whether to display the image contained vs filled in its container. */ /** Whether to display the image contained vs filled in its container. */
@ -30,19 +32,17 @@ interface IStillImage {
/** Renders images on a canvas, only playing GIFs if autoPlayGif is enabled. */ /** Renders images on a canvas, only playing GIFs if autoPlayGif is enabled. */
const StillImage: React.FC<IStillImage> = ({ const StillImage: React.FC<IStillImage> = ({
alt, className, innerClassName, src, style, letterboxed = false, showExt = false, onError, onLoad, isGif, noGroup, alt, className, innerClassName, src, staticSrc, style, letterboxed = false, showExt = false, onError, onLoad, isGif, noGroup,
}) => { }) => {
const { autoPlayGif } = useSettings(); const { autoPlayGif } = useSettings();
const canvas = useRef<HTMLCanvasElement>(null); const canvas = useRef<HTMLCanvasElement>(null);
const img = useRef<HTMLImageElement>(null); const img = useRef<HTMLImageElement>(null);
const hoverToPlay = ( const hoverToPlay = src && !autoPlayGif && ((isGif) || src.endsWith('.gif') || src.startsWith('blob:') || (src && staticSrc && src !== staticSrc));
src && !autoPlayGif && ((isGif) || src.endsWith('.gif') || src.startsWith('blob:'))
);
const handleImageLoad: React.ReactEventHandler<HTMLImageElement> = (e) => { const handleImageLoad: React.ReactEventHandler<HTMLImageElement> = (e) => {
if (hoverToPlay && canvas.current && img.current) { if (hoverToPlay && !staticSrc && canvas.current && img.current) {
canvas.current.width = img.current.naturalWidth; canvas.current.width = img.current.naturalWidth;
canvas.current.height = img.current.naturalHeight; canvas.current.height = img.current.naturalHeight;
const context = canvas.current.getContext('2d'); const context = canvas.current.getContext('2d');
@ -80,14 +80,18 @@ const StillImage: React.FC<IStillImage> = ({
})} })}
/> />
{hoverToPlay && ( {hoverToPlay && (staticSrc ? (
<img
src={staticSrc}
alt={alt}
className={clsx(baseClassName, 'absolute top-0 group-hover:invisible')}
/>
) : (
<canvas <canvas
ref={canvas} ref={canvas}
className={clsx(baseClassName, { className={clsx(baseClassName, 'absolute top-0 group-hover:invisible')}
'absolute group-hover:invisible top-0': hoverToPlay,
})}
/> />
)} ))}
{(hoverToPlay && showExt) && ( {(hoverToPlay && showExt) && (
<div className='pointer-events-none absolute bottom-2 left-2 opacity-90 group-hover:hidden'> <div className='pointer-events-none absolute bottom-2 left-2 opacity-90 group-hover:hidden'>

View File

@ -9,12 +9,13 @@ interface IEmoji extends Pick<React.ImgHTMLAttributes<HTMLImageElement>, 'alt' |
/** Unicode emoji character. */ /** Unicode emoji character. */
emoji?: string; emoji?: string;
noGroup?: boolean; noGroup?: boolean;
staticSrc?: string;
} }
/** A single emoji image. */ /** A single emoji image. */
const Emoji: React.FC<IEmoji> = (props): JSX.Element | null => { const Emoji: React.FC<IEmoji> = (props): JSX.Element | null => {
const { disableUserProvidedMedia, systemEmojiFont } = useSettings(); const { disableUserProvidedMedia, systemEmojiFont } = useSettings();
const { emoji, alt, src, noGroup, ...rest } = props; const { emoji, alt, src, staticSrc, noGroup, ...rest } = props;
let filename; let filename;
@ -35,6 +36,7 @@ const Emoji: React.FC<IEmoji> = (props): JSX.Element | null => {
<StillImage <StillImage
alt={alt || emoji} alt={alt || emoji}
src={src} src={src}
staticSrc={staticSrc}
isGif isGif
noGroup={noGroup} noGroup={noGroup}
letterboxed letterboxed