diff --git a/.changeset/y_always_underline_links.md b/.changeset/y_always_underline_links.md new file mode 100644 index 00000000..793daf3e --- /dev/null +++ b/.changeset/y_always_underline_links.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Added setting to always underline links. diff --git a/.changeset/y_autoplay.md b/.changeset/y_autoplay.md new file mode 100644 index 00000000..7d24ecbe --- /dev/null +++ b/.changeset/y_autoplay.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Added settings for disabling autoplay of gifs (& banners), stickers, and emojis. diff --git a/.changeset/y_reduced_motion_option.md b/.changeset/y_reduced_motion_option.md new file mode 100644 index 00000000..4cec37f5 --- /dev/null +++ b/.changeset/y_reduced_motion_option.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Added reduced motion setting. Let us know if any elements were missed! diff --git a/.changeset/y_saturation_slider.md b/.changeset/y_saturation_slider.md new file mode 100644 index 00000000..77fbb35b --- /dev/null +++ b/.changeset/y_saturation_slider.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Replaced the monochrome mode with a saturation slider for more control. diff --git a/src/app/components/ClientSideHoverFreeze.tsx b/src/app/components/ClientSideHoverFreeze.tsx new file mode 100644 index 00000000..5a516d13 --- /dev/null +++ b/src/app/components/ClientSideHoverFreeze.tsx @@ -0,0 +1,76 @@ +import { useEffect, useRef, useState } from 'react'; + +export function ClientSideHoverFreeze({ + children, + src, + className, +}: { + children: React.ReactNode; + src: string; + className?: string; +}) { + const [isHovered, setIsHovered] = useState(false); + const canvasRef = useRef(null); + const [isCanvasReady, setIsCanvasReady] = useState(false); + useEffect(() => { + let isMounted = true; + const img = new window.Image(); + img.crossOrigin = 'anonymous'; + img.src = src; + + img.onload = () => { + if (isMounted && canvasRef.current) { + canvasRef.current.width = img.naturalWidth || img.width; + canvasRef.current.height = img.naturalHeight || img.height; + const ctx = canvasRef.current.getContext('2d'); + ctx?.drawImage(img, 0, 0); + setIsCanvasReady(true); + } + }; + return () => { + isMounted = false; + }; + }, [src]); + + return ( +
setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + onFocus={() => setIsHovered(true)} + onBlur={() => setIsHovered(false)} + className={className} + style={{ + position: 'relative', + display: 'inline-flex', + cursor: 'pointer', + verticalAlign: 'middle', + overflow: 'hidden', + borderRadius: 'inherit', + }} + > +
+ {children} +
+ +
+ ); +} diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index 8ba8f6dc..6811b116 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -1,6 +1,8 @@ import { memo, useMemo, useCallback } from 'react'; import { MsgType } from '$types/matrix-sdk'; import { testMatrixTo } from '$plugins/matrix-to'; +import { useSetting } from '$state/hooks/settings'; +import { settingsAtom } from '$state/settings'; import { HTMLReactParserOptions } from 'html-react-parser'; import { Opts } from 'linkifyjs'; import { config } from 'folds'; @@ -30,6 +32,7 @@ import { Image, MediaControl, Video } from './media'; import { ImageViewer } from './image-viewer'; import { PdfViewer } from './Pdf-viewer'; import { TextViewer } from './text-viewer'; +import { ClientSideHoverFreeze } from './ClientSideHoverFreeze'; type RenderMessageContentProps = { displayName: string; @@ -70,6 +73,8 @@ function RenderMessageContentInternal({ }: RenderMessageContentProps) { const content = useMemo(() => getContent(), [getContent]); + const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); + const renderBody = useCallback( (props: any) => ( } + renderImage={(p) => { + if (isGif && !autoplayGifs && p.src) { + return ( + + + + ); + } + return ; + }} renderViewer={(p) => } /> )} diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index dfc62f24..0acdc361 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useMemo, useState } from 'react'; import { Avatar, Box, @@ -27,6 +27,7 @@ import { useBlobCache } from '$hooks/useBlobCache'; import { ImageViewer } from '$components/image-viewer'; import { AvatarPresence, PresenceBadge } from '$components/presence'; import { UserAvatar } from '$components/user-avatar'; +import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze'; import * as css from './styles.css'; type UserHeroProps = { @@ -34,8 +35,9 @@ type UserHeroProps = { avatarUrl?: string; bannerUrl?: string; presence?: UserPresence; + autoplayGifs?: boolean; }; -export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroProps) { +export function UserHero({ userId, avatarUrl, bannerUrl, presence, autoplayGifs }: UserHeroProps) { const [viewAvatar, setViewAvatar] = useState(); const [isFullStatus, setIsFullStatus] = useState(false); @@ -45,6 +47,25 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroPro const coverUrl = cachedBannerUrl || cachedAvatarUrl; const isFallbackCover = !cachedBannerUrl && !!cachedAvatarUrl; + const isAnimated = useMemo(() => { + if (!coverUrl) return false; + const url = coverUrl.toLowerCase(); + const isStatic = url.endsWith('.jpg') || url.endsWith('.jpeg') || url.endsWith('.png'); + + return !isStatic || url.includes('gif') || url.includes('webp'); + }, [coverUrl]); + + const bannerClasses = classNames(css.UserHeroCover, isFallbackCover && css.UserHeroCoverFallback); + + const renderCoverImage = () => ( + {`${userId} + ); + const status = presence?.status; const isExpandable = (status?.length ?? 0) > 70; @@ -57,12 +78,15 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroPro }} > {coverUrl && ( - {`${userId} + <> + {isAnimated && !autoplayGifs ? ( + + {renderCoverImage()} + + ) : ( + renderCoverImage() + )} + )} diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 3878bba5..8a108f21 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -259,6 +259,8 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps const ignoredUsers = useIgnoredUsers(); const ignored = ignoredUsers.includes(userId); + const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); + const room = useRoom(); const powerLevels = usePowerLevels(room); const creators = useRoomCreators(room); @@ -348,6 +350,7 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps avatarUrl={avatarUrl} bannerUrl={bannerHttpUrl ?? undefined} presence={presence && presence.lastActiveTs !== 0 ? presence : undefined} + autoplayGifs={autoplayGifs} /> diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 38063d24..d07c62a3 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -129,6 +129,7 @@ import { useRoomCreators } from '$hooks/useRoomCreators'; import { useRoomPermissions } from '$hooks/useRoomPermissions'; import { useGetMemberPowerTag } from '$hooks/useMemberPowerTag'; import { profilesCacheAtom } from '$state/userRoomProfile'; +import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze'; import * as css from './RoomTimeline.css'; import { EncryptedContent, Event, Message, Reactions } from './message'; @@ -571,10 +572,14 @@ export function RoomTimeline({ const showUrlPreview = room.hasEncryptionStateEvent() ? encUrlPreview : urlPreview; const [showHiddenEvents] = useSetting(settingsAtom, 'showHiddenEvents'); const [showDeveloperTools] = useSetting(settingsAtom, 'developerTools'); + const [reducedMotion] = useSetting(settingsAtom, 'reducedMotion'); const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock'); const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString'); + const [autoplayStickers] = useSetting(settingsAtom, 'autoplayStickers'); + const [autoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis'); + const ignoredUsersList = useIgnoredUsers(); const ignoredUsersSet = useMemo(() => new Set(ignoredUsersList), [ignoredUsersList]); const nicknames = useAtomValue(nicknamesAtom); @@ -657,8 +662,18 @@ export function RoomTimeline({ handleSpoilerClick: spoilerClickHandler, handleMentionClick: mentionClickHandler, nicknames, + autoplayEmojis, }), - [mx, room, linkifyOpts, spoilerClickHandler, mentionClickHandler, useAuthentication, nicknames] + [ + mx, + room, + linkifyOpts, + autoplayEmojis, + spoilerClickHandler, + mentionClickHandler, + useAuthentication, + nicknames, + ] ); const parseMemberEvent = useMemberEventParser(); @@ -814,7 +829,7 @@ export function RoomTimeline({ if (typeof absoluteIndex === 'number') { const scrolled = scrollToItem(absoluteIndex, { - behavior: 'smooth', + behavior: reducedMotion ? 'instant' : 'smooth', align: 'center', stopInView: true, }); @@ -828,7 +843,7 @@ export function RoomTimeline({ loadEventTimeline(evtId); } }, - [room, timeline, scrollToItem, loadEventTimeline] + [room, timeline, scrollToItem, loadEventTimeline, reducedMotion] ); useLiveTimelineRefresh( @@ -1067,7 +1082,7 @@ export function RoomTimeline({ if (scrollToBottomCount > 0) { const scrollEl = scrollRef.current; if (scrollEl) { - const behavior = scrollToBottomRef.current.smooth ? 'smooth' : 'instant'; + const behavior = scrollToBottomRef.current.smooth && !reducedMotion ? 'smooth' : 'instant'; scrollToBottom(scrollEl, behavior); // On Android WebView, layout may still settle after the initial scroll. // Fire a second instant scroll after a short delay to guarantee we @@ -1078,7 +1093,7 @@ export function RoomTimeline({ } } } - }, [scrollToBottomCount]); + }, [scrollToBottomCount, reducedMotion]); // Remove unreadInfo on mark as read useEffect(() => { @@ -1478,7 +1493,16 @@ export function RoomTimeline({ } + renderImage={(p) => { + if (!autoplayStickers && p.src) { + return ( + + + + ); + } + return ; + }} renderViewer={(p) => } /> )} @@ -1598,7 +1622,16 @@ export function RoomTimeline({ } + renderImage={(p) => { + if (!autoplayStickers && p.src) { + return ( + + + + ); + } + return ; + }} renderViewer={(p) => } /> )} diff --git a/src/app/features/settings/cosmetics/Themes.tsx b/src/app/features/settings/cosmetics/Themes.tsx index 714bbd57..baf73762 100644 --- a/src/app/features/settings/cosmetics/Themes.tsx +++ b/src/app/features/settings/cosmetics/Themes.tsx @@ -244,7 +244,12 @@ function SystemThemePreferences() { function ThemeSettings() { const [systemTheme, setSystemTheme] = useSetting(settingsAtom, 'useSystemTheme'); - const [monochromeMode, setMonochromeMode] = useSetting(settingsAtom, 'monochromeMode'); + const [saturation, setSaturation] = useSetting(settingsAtom, 'saturationLevel'); + const [underlineLinks, setUnderlineLinks] = useSetting(settingsAtom, 'underlineLinks'); + const [reducedMotion, setReducedMotion] = useSetting(settingsAtom, 'reducedMotion'); + const [autoplayGifs, setAutoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); + const [autoplayStickers, setAutoplayStickers] = useSetting(settingsAtom, 'autoplayStickers'); + const [autoplayEmojis, setAutoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis'); return ( @@ -274,8 +279,64 @@ function ThemeSettings() { } + title="Saturation" + description={`${saturation}%`} + after={ + setSaturation(parseInt(e.target.value, 10))} + style={{ + width: toRem(160), + cursor: 'pointer', + appearance: 'none', + height: toRem(6), + borderRadius: config.radii.Pill, + backgroundColor: 'var(--sable-surface-container-line)', + accentColor: 'var(--sable-primary-main)', + }} + /> + } + /> + + + } + /> + + + } + /> + + + } + /> + + + + } + /> + + + } /> diff --git a/src/app/pages/ThemeManager.tsx b/src/app/pages/ThemeManager.tsx index dea860f9..90a7e578 100644 --- a/src/app/pages/ThemeManager.tsx +++ b/src/app/pages/ThemeManager.tsx @@ -30,20 +30,35 @@ export function UnAuthRouteThemeManager() { export function AuthRouteThemeManager({ children }: { children: ReactNode }) { const activeTheme = useActiveTheme(); - const [monochromeMode] = useSetting(settingsAtom, 'monochromeMode'); + const [saturation] = useSetting(settingsAtom, 'saturationLevel'); + const [underlineLinks] = useSetting(settingsAtom, 'underlineLinks'); + const [reducedMotion] = useSetting(settingsAtom, 'reducedMotion'); useEffect(() => { document.body.className = ''; document.body.classList.add(configClass, varsClass); - document.body.classList.add(...activeTheme.classNames); - if (monochromeMode) { + if (underlineLinks) { + document.body.classList.add('force-underline-links'); + } else { + document.body.classList.remove('force-underline-links'); + } + + if (reducedMotion) { + document.body.classList.add('reduced-motion'); + } else { + document.body.classList.remove('reduced-motion'); + } + + if (saturation === 0) { document.body.style.filter = 'grayscale(1)'; + } else if (saturation && saturation < 100) { + document.body.style.filter = `saturate(${saturation}%)`; } else { document.body.style.filter = ''; } - }, [activeTheme, monochromeMode]); + }, [activeTheme, saturation, underlineLinks, reducedMotion]); return {children}; } diff --git a/src/app/plugins/react-custom-html-parser.tsx b/src/app/plugins/react-custom-html-parser.tsx index dc3bf484..12a86926 100644 --- a/src/app/plugins/react-custom-html-parser.tsx +++ b/src/app/plugins/react-custom-html-parser.tsx @@ -36,6 +36,7 @@ import { findAndReplace } from '$utils/findAndReplace'; import { onEnterOrSpace } from '$utils/keyboard'; import { copyToClipboard } from '$utils/dom'; import { useTimeoutToggle } from '$hooks/useTimeoutToggle'; +import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze'; import { parseMatrixToRoom, parseMatrixToRoomEvent, @@ -341,6 +342,7 @@ export const getReactCustomHtmlParser = ( handleMentionClick?: ReactEventHandler; useAuthentication?: boolean; nicknames?: Nicknames; + autoplayEmojis?: boolean; } ): HTMLReactParserOptions => { const opts: HTMLReactParserOptions = { @@ -547,25 +549,39 @@ export const getReactCustomHtmlParser = ( const siblingCount = domNode.parent?.children.length ?? 0; + // seperate style for bundled emojis // seperate style for bundled emojis if (siblingCount > 5) { return ( - - {props.alt || props.title ? `:${props.alt || props.title}:` : '?'} - - } - /> + {!params.autoplayEmojis ? ( + + + {props.alt || props.title || '?'} + + } + /> + + ) : ( + + {props.alt || props.title || '?'} + + } + /> + )} ); @@ -575,19 +591,29 @@ export const getReactCustomHtmlParser = ( return ( - - {props.alt || props.title ? `:${props.alt || props.title}:` : '?'} - - } - /> + {!params.autoplayEmojis ? ( + + + {props.alt || props.title || '?'} + + } + /> + + ) : ( + {props.alt || props.title || '?'} + } + /> + )} ); diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index d7067171..6de1ad16 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -22,7 +22,7 @@ export interface Settings { useSystemTheme: boolean; lightThemeId?: string; darkThemeId?: string; - monochromeMode?: boolean; + saturationLevel?: number; uniformIcons: boolean; isMarkdown: boolean; editorToolbar: boolean; @@ -80,6 +80,11 @@ export interface Settings { showPingCounts: boolean; hideReads: boolean; emojiSuggestThreshold: number; + underlineLinks: boolean; + reducedMotion: boolean; + autoplayGifs: boolean; + autoplayStickers: boolean; + autoplayEmojis: boolean; // furry stuff renderAnimals: boolean; @@ -90,7 +95,7 @@ const defaultSettings: Settings = { useSystemTheme: true, lightThemeId: undefined, darkThemeId: undefined, - monochromeMode: false, + saturationLevel: 100, uniformIcons: false, isMarkdown: true, editorToolbar: false, @@ -149,6 +154,11 @@ const defaultSettings: Settings = { showPingCounts: true, hideReads: false, emojiSuggestThreshold: 2, + underlineLinks: false, + reducedMotion: false, + autoplayGifs: true, + autoplayStickers: true, + autoplayEmojis: true, // furry stuff renderAnimals: true, @@ -157,9 +167,20 @@ const defaultSettings: Settings = { export const getSettings = () => { const settings = localStorage.getItem(STORAGE_KEY); if (settings === null) return defaultSettings; + + // migration for old keys + // monochrome -> saturation + const parsed = JSON.parse(settings); + if (parsed.monochromeMode === true && parsed.saturationLevel === undefined) { + parsed.saturationLevel = 0; + } else if (parsed.monochromeMode === false && parsed.saturationLevel === undefined) { + parsed.saturationLevel = 100; + } + delete parsed.monochromeMode; + return { ...defaultSettings, - ...(JSON.parse(settings) as Settings), + ...(parsed as Settings), }; }; diff --git a/src/index.css b/src/index.css index 5935979f..f2f2547b 100755 --- a/src/index.css +++ b/src/index.css @@ -174,3 +174,61 @@ pre { letter-spacing: -0.01em; font-variant-ligatures: contextual; } + +/* Accessibility Overrides :D */ + +.force-underline-links a { + text-decoration: underline !important; + text-decoration-thickness: 1px; + text-underline-offset: 2px; +} + +body.reduced-motion * { + animation-duration: 0.001ms !important; + transition-duration: 0.001ms !important; +} + +body.reduced-motion button:hover, +body.reduced-motion a:hover, +body.reduced-motion [role='button']:hover { + transform: none !important; + scale: 1 !important; +} + +body.reduced-motion div[class*='Sidebar_SidebarItem']:hover, +body.reduced-motion div[class*='Sidebar_SidebarItem']:hover button, +body.reduced-motion div[class*='Sidebar_SidebarItem']:hover img { + transform: none !important; + scale: 1 !important; + translate: none !important; + margin: 0 !important; + padding: 0 !important; +} + +body.reduced-motion div[class*='Sidebar_SidebarStack']:hover { + width: revert !important; + translate: none !important; + transform: none !important; +} + +body.reduced-motion div[class*='layout_MessageBase'] { + animation: none !important; + transition: none !important; + transform: none !important; +} + +body.reduced-motion div[class*='RoomTimeline_messageList'], +body.reduced-motion div[class*='RoomTimeline_messageList'] > * { + scroll-behavior: auto !important; +} + +body.reduced-motion span[class*='layout_AvatarBase']:hover, +body.reduced-motion span[class*='layout_AvatarBase']:hover *, +body.reduced-motion button[class*='styles_MessageAvatar']:hover, +body.reduced-motion button[class*='styles_MessageAvatar']:hover * { + transform: none !important; + scale: 1 !important; + translate: none !important; + animation: none !important; + margin: 0 !important; +}