mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 03:46:25 -08:00
implement 'smart' pixelation in chat
Signed-off-by: Shea <[email protected]>
This commit is contained in:
6 files changed
+16
-9
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Change image rendering to allow enabling anti-aliasing in the image viewer
|
||||
@@ -359,11 +359,11 @@ function RenderMessageContentInternal({
|
||||
if (isGif && !autoplayGifs && p.src) {
|
||||
return (
|
||||
<ClientSideHoverFreeze src={p.src}>
|
||||
<Image {...p} loading="lazy" />
|
||||
<Image info={info} {...p} loading="lazy" />
|
||||
</ClientSideHoverFreeze>
|
||||
);
|
||||
}
|
||||
return <Image {...p} loading="lazy" />;
|
||||
return <Image info={info} {...p} loading="lazy" />;
|
||||
}}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
/>
|
||||
|
||||
@@ -28,8 +28,6 @@ export const ImageViewer = as<'div', ImageViewerProps>(
|
||||
const [isPixelated, setIsPixelated] = useState(
|
||||
isPixelatedRendering(pixelatedImageRendering, info)
|
||||
);
|
||||
// oxlint-disable-next-line no-console
|
||||
console.log(info);
|
||||
|
||||
const {
|
||||
transforms,
|
||||
@@ -98,7 +96,7 @@ export const ImageViewer = as<'div', ImageViewerProps>(
|
||||
radii="Pill"
|
||||
onClick={() => setIsPixelated(!isPixelated)}
|
||||
aria-label="Toggle Pixelation"
|
||||
title={`Turn ${isPixelated ? 'Antialiasing' : 'Pixelation'} on`}
|
||||
title={`Turn ${isPixelated ? 'Anti-aliasing' : 'Pixelation'} on`}
|
||||
>
|
||||
<CheckerboardIcon size={20} weight={isPixelated ? 'duotone' : 'fill'} />
|
||||
</IconButton>
|
||||
|
||||
@@ -4,16 +4,19 @@ import classNames from 'classnames';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { isPixelatedRendering, settingsAtom } from '$state/settings';
|
||||
import * as css from './media.css';
|
||||
import type { IImageInfo } from '$types/matrix/common';
|
||||
|
||||
export const Image = forwardRef<HTMLImageElement, ImgHTMLAttributes<HTMLImageElement>>(
|
||||
({ className, alt, ...props }, ref) => {
|
||||
type ImageProps = ImgHTMLAttributes<HTMLImageElement> & { info?: IImageInfo };
|
||||
|
||||
export const Image = forwardRef<HTMLImageElement, ImageProps>(
|
||||
({ className, alt, info, ...props }, ref) => {
|
||||
const [pixelatedImageRendering] = useSetting(settingsAtom, 'pixelatedImageRendering');
|
||||
|
||||
return (
|
||||
<img
|
||||
className={classNames(
|
||||
css.Image,
|
||||
isPixelatedRendering(pixelatedImageRendering) && css.ImagePixelated,
|
||||
isPixelatedRendering(pixelatedImageRendering, info) && css.ImagePixelated,
|
||||
className
|
||||
)}
|
||||
alt={alt}
|
||||
|
||||
@@ -305,6 +305,7 @@ export const UrlPreviewCard = as<
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
renderImage={(p) => (
|
||||
<Image
|
||||
info={ogImageInfo}
|
||||
{...p}
|
||||
style={{
|
||||
display: 'block',
|
||||
|
||||
@@ -63,7 +63,7 @@ export function isPixelatedRendering(
|
||||
mode: PixelatedImageRenderingMode,
|
||||
info?: IImageInfo
|
||||
): boolean {
|
||||
if (mode === 'smart') return !info || !info.w || !info.h || info.w < 192 || info.h < 192;
|
||||
if (mode === 'smart') return !!info && !!info.w && !!info.h && (info.w < 192 || info.h < 192);
|
||||
return mode === 'always';
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user