Skip to content

Commit

Permalink
blur gifs while processing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Feb 8, 2025
1 parent ae018e2 commit af78297
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/features/accesskit/disable_gifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const canvasClass = 'xkit-paused-gif-placeholder';
const labelClass = 'xkit-paused-gif-label';
const containerClass = 'xkit-paused-gif-container';
const pausedBackgroundImageVar = '--xkit-paused-gif-background-image';
const loadingBlurClass = 'xkit-paused-gif-loading-blur';

let enabledTimestamp;

export const styleElement = buildStyle(`
.${labelClass} {
Expand Down Expand Up @@ -50,6 +53,20 @@ export const styleElement = buildStyle(`
[style*="${pausedBackgroundImageVar}"]:not(:hover) {
background-image: var(${pausedBackgroundImageVar}) !important;
}
.${loadingBlurClass}:not(:hover)::before {
content: "";
backdrop-filter: blur(50px);
position: absolute;
inset: 0;
}
.${loadingBlurClass}:not(:hover) {
isolation: isolate;
}
.${loadingBlurClass}:not(:hover) > * {
z-index: 1;
}
`);

const addLabel = (element, inside = false) => {
Expand Down Expand Up @@ -131,11 +148,13 @@ const processBackgroundGifs = function (gifBackgroundElements) {
const sourceUrl = sourceValue.match(sourceUrlRegex)?.[0];

if (sourceUrl) {
Date.now() - enabledTimestamp >= 100 && gifBackgroundElement.classList.add(loadingBlurClass);
gifBackgroundElement.style.setProperty(
pausedBackgroundImageVar,
sourceValue.replaceAll(sourceUrlRegex, await createPausedUrl(sourceUrl))
);
addLabel(gifBackgroundElement, true);
gifBackgroundElement.classList.remove(loadingBlurClass);
}
});
};
Expand All @@ -157,6 +176,8 @@ const processRows = function (rowsElements) {
};

export const main = async function () {
enabledTimestamp = Date.now();

const gifImage = `
:is(figure, ${keyToCss('tagImage', 'takeoverBanner', 'videoHubsFeatured')}) img:is([srcset*=".gif"], [src*=".gif"]):not(${keyToCss('poster')})
`;
Expand Down

0 comments on commit af78297

Please sign in to comment.