fix: ensure "disable blurhash" setting is honored (#1422)
* fix: ensure "disable blurhash" setting is honored fixes #1421 * remove play button for audio/video
This commit is contained in:
parent
dd625b80a0
commit
8c6a701d6f
7 changed files with 57 additions and 68 deletions
|
@ -155,7 +155,8 @@
|
||||||
"MessageChannel",
|
"MessageChannel",
|
||||||
"ImageData",
|
"ImageData",
|
||||||
"OffscreenCanvas",
|
"OffscreenCanvas",
|
||||||
"postMessage"
|
"postMessage",
|
||||||
|
"getComputedStyle"
|
||||||
],
|
],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
alt={label || ''}
|
alt={label || ''}
|
||||||
title={label || ''}
|
title={label || ''}
|
||||||
src={staticSrc}
|
src={staticSrc}
|
||||||
blurhash={blurhash}
|
{blurhash}
|
||||||
fallback={oneTransparentPixel}
|
fallback={oneTransparentPixel}
|
||||||
{width}
|
{width}
|
||||||
{height}
|
{height}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{#if (type === 'video' && !blurhash) || type === 'audio'}
|
{#if !blurhash && (type === 'video' || type === 'audio')}
|
||||||
<button id={elementId}
|
<button id={elementId}
|
||||||
type="button"
|
type="button"
|
||||||
class="play-video-button focus-after {$largeInlineMedia ? '' : 'fixed-size'} {type === 'audio' ? 'play-audio-button' : ''}"
|
class="play-video-button focus-after {$largeInlineMedia ? '' : 'fixed-size'} {type === 'audio' ? 'play-audio-button' : ''}"
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
title={description}
|
title={description}
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
fallback={oneTransparentPixel}
|
fallback={oneTransparentPixel}
|
||||||
blurhash={blurhash}
|
{blurhash}
|
||||||
width={inlineWidth}
|
width={inlineWidth}
|
||||||
height={inlineHeight}
|
height={inlineHeight}
|
||||||
background="var(--loading-bg)"
|
background="var(--loading-bg)"
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
title={description}
|
title={description}
|
||||||
on:mouseover="set({mouseover: event})"
|
on:mouseover="set({mouseover: event})"
|
||||||
style="width: {inlineWidth}px; height: {inlineHeight}px;">
|
style="width: {inlineWidth}px; height: {inlineHeight}px;">
|
||||||
{#if type === 'gifv' && $autoplayGifs && !blurhash}
|
{#if type === 'gifv' && $autoplayGifs}
|
||||||
<AutoplayVideo
|
<AutoplayVideo
|
||||||
ariaLabel="Animated GIF: {description}"
|
ariaLabel="Animated GIF: {description}"
|
||||||
poster={previewUrl}
|
poster={previewUrl}
|
||||||
|
@ -36,12 +36,12 @@
|
||||||
height={inlineHeight}
|
height={inlineHeight}
|
||||||
{focus}
|
{focus}
|
||||||
/>
|
/>
|
||||||
{:elseif type === 'gifv' && !blurhash}
|
{:elseif type === 'gifv'}
|
||||||
<NonAutoplayGifv
|
<NonAutoplayGifv
|
||||||
class={noNativeWidthHeight ? 'no-native-width-height' : ''}
|
class={noNativeWidthHeight ? 'no-native-width-height' : ''}
|
||||||
label="Animated GIF: {description}"
|
label="Animated GIF: {description}"
|
||||||
poster={previewUrl}
|
poster={previewUrl}
|
||||||
blurhash={blurhash}
|
{blurhash}
|
||||||
src={url}
|
src={url}
|
||||||
staticSrc={previewUrl}
|
staticSrc={previewUrl}
|
||||||
width={inlineWidth}
|
width={inlineWidth}
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
title={description}
|
title={description}
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
fallback={oneTransparentPixel}
|
fallback={oneTransparentPixel}
|
||||||
blurhash={blurhash}
|
{blurhash}
|
||||||
width={inlineWidth}
|
width={inlineWidth}
|
||||||
height={inlineHeight}
|
height={inlineHeight}
|
||||||
background="var(--loading-bg)"
|
background="var(--loading-bg)"
|
||||||
|
@ -94,6 +94,7 @@
|
||||||
import LazyImage from '../LazyImage.html'
|
import LazyImage from '../LazyImage.html'
|
||||||
import AutoplayVideo from '../AutoplayVideo.html'
|
import AutoplayVideo from '../AutoplayVideo.html'
|
||||||
import { registerClickDelegate } from '../../_utils/delegate'
|
import { registerClickDelegate } from '../../_utils/delegate'
|
||||||
|
import { convertCssPropertyToDataUrl } from '../../_utils/convertCssPropertyToDataUrl'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async oncreate () {
|
async oncreate () {
|
||||||
|
@ -129,8 +130,16 @@ export default {
|
||||||
elementId: ({ media, uuid }) => `media-${uuid}-${media.id}`,
|
elementId: ({ media, uuid }) => `media-${uuid}-${media.id}`,
|
||||||
description: ({ media }) => media.description || '',
|
description: ({ media }) => media.description || '',
|
||||||
previewUrl: ({ media }) => media.preview_url,
|
previewUrl: ({ media }) => media.preview_url,
|
||||||
decodedBlurhash: ({ media }) => media.decodedBlurhash || ONE_TRANSPARENT_PIXEL,
|
decodedBlurhash: ({ media }) => media.decodedBlurhash,
|
||||||
blurhash: ({ showBlurhash, decodedBlurhash }) => showBlurhash && decodedBlurhash,
|
blurhashToUse: ({ decodedBlurhash, $ignoreBlurhash }) => {
|
||||||
|
if (!$ignoreBlurhash && decodedBlurhash) {
|
||||||
|
return decodedBlurhash
|
||||||
|
}
|
||||||
|
// Convert the var(--loading-bg) variable into a data URL based on a single pixel of color
|
||||||
|
// TODO: this is hacky
|
||||||
|
return convertCssPropertyToDataUrl('--mask-bg')
|
||||||
|
},
|
||||||
|
blurhash: ({ blurhashToUse, showAsSensitive }) => showAsSensitive && blurhashToUse,
|
||||||
url: ({ media }) => media.url,
|
url: ({ media }) => media.url,
|
||||||
type: ({ media }) => media.type
|
type: ({ media }) => media.type
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class={computedClass}
|
<div class={computedClass}
|
||||||
style="grid-template-columns: repeat({nCols}, 1fr);" >
|
style="grid-template-columns: repeat({nCols}, 1fr);" >
|
||||||
{#each mediaAttachments as media, index}
|
{#each mediaAttachments as media, index}
|
||||||
<Media {media} {uuid} {mediaAttachments} {index} {showBlurhash} />
|
<Media {media} {uuid} {mediaAttachments} {index} {showAsSensitive} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<style>
|
<style>
|
||||||
|
@ -56,8 +56,8 @@
|
||||||
twoCols && 'two-cols',
|
twoCols && 'two-cols',
|
||||||
!$largeInlineMedia && 'grouped-images'
|
!$largeInlineMedia && 'grouped-images'
|
||||||
),
|
),
|
||||||
showBlurhash: ({ sensitive, sensitiveShown, mediaAttachments }) => {
|
showAsSensitive: ({ sensitive, sensitiveShown }) => {
|
||||||
return sensitive && mediaAttachments.every(attachment => !!attachment.blurhash) ? !sensitiveShown : false
|
return sensitive ? !sensitiveShown : false
|
||||||
},
|
},
|
||||||
nCols: ({ mediaAttachments, $largeInlineMedia }) => {
|
nCols: ({ mediaAttachments, $largeInlineMedia }) => {
|
||||||
return (!$largeInlineMedia && mediaAttachments.length > 1) ? 2 : 1
|
return (!$largeInlineMedia && mediaAttachments.length > 1) ? 2 : 1
|
||||||
|
|
|
@ -4,32 +4,30 @@
|
||||||
{#if sensitiveShown}
|
{#if sensitiveShown}
|
||||||
<button id={elementId}
|
<button id={elementId}
|
||||||
type="button"
|
type="button"
|
||||||
class={sensitiveMediaButtonClass}
|
class="status-sensitive-media-button"
|
||||||
aria-label="Hide sensitive media" >
|
aria-label="Hide sensitive media" >
|
||||||
<div class={svgWrapperClass}>
|
<div class="svg-wrapper">
|
||||||
<SvgIcon className={sensitiveMediaIconClass}
|
<SvgIcon className="status-sensitive-media-svg"
|
||||||
href="#fa-eye-slash" />
|
href="#fa-eye-slash" />
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
<button id={elementId}
|
<button id={elementId}
|
||||||
type="button"
|
type="button"
|
||||||
class={sensitiveMediaButtonClass}
|
class="status-sensitive-media-button"
|
||||||
aria-label="Show sensitive media" >
|
aria-label="Show sensitive media" >
|
||||||
|
|
||||||
<div class="{customWarningClass}">
|
<div class="status-sensitive-media-warning">
|
||||||
<div class="status-sensitive-media-warning-text">
|
<div class="status-sensitive-media-warning-text">
|
||||||
Sensitive content. Click to show.
|
Sensitive content. Click to show.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class={svgWrapperClass}>
|
<div class="svg-wrapper">
|
||||||
<SvgIcon className={sensitiveMediaIconClass} href="#fa-eye" />
|
<SvgIcon className="status-sensitive-media-svg" href="#fa-eye" />
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if sensitiveShown || canUseBlurhash}
|
<MediaAttachments {mediaAttachments} {sensitive} {sensitiveShown} {uuid} />
|
||||||
<MediaAttachments {mediaAttachments} {sensitive} {sensitiveShown} {uuid} />
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if enableShortcuts}
|
{#if enableShortcuts}
|
||||||
|
@ -79,14 +77,9 @@
|
||||||
|
|
||||||
.status-sensitive-media-shown .status-sensitive-media-button {
|
.status-sensitive-media-shown .status-sensitive-media-button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
z-index: 90;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-sensitive-media-shown .status-sensitive-media-button.status-sensitive-media-button-transparent {
|
|
||||||
top: 5px;
|
top: 5px;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
|
z-index: 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-sensitive-media-hidden .status-sensitive-media-button {
|
.status-sensitive-media-hidden .status-sensitive-media-button {
|
||||||
|
@ -116,18 +109,10 @@
|
||||||
color: var(--deemphasized-text-color);
|
color: var(--deemphasized-text-color);
|
||||||
z-index: 60;
|
z-index: 60;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
}
|
|
||||||
|
|
||||||
.status-sensitive-media-container .status-sensitive-media-warning-transparent {
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-sensitive-media-container .status-sensitive-media-warning-opaque {
|
.status-sensitive-media-container .status-sensitive-media-warning .status-sensitive-media-warning-text {
|
||||||
background: var(--mask-bg);
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-sensitive-media-container .status-sensitive-media-warning-transparent .status-sensitive-media-warning-text {
|
|
||||||
background: var(--mask-bg);
|
background: var(--mask-bg);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
@ -145,15 +130,10 @@
|
||||||
.status-sensitive-media-hidden .svg-wrapper {
|
.status-sensitive-media-hidden .svg-wrapper {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background: none;
|
background: none;
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-sensitive-media-hidden .svg-wrapper.svg-wrapper-transparent {
|
|
||||||
top: 5px;
|
top: 5px;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-sensitive-media-container.grouped-images .svg-wrapper {
|
.status-sensitive-media-container.grouped-images .svg-wrapper {
|
||||||
|
@ -172,11 +152,6 @@
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
}
|
}
|
||||||
:global(.status-sensitive-media-container.status-sensitive-media-hidden .status-sensitive-media-svg) {
|
:global(.status-sensitive-media-container.status-sensitive-media-hidden .status-sensitive-media-svg) {
|
||||||
fill: var(--deemphasized-text-color);
|
|
||||||
background: var(--mask-opaque-bg);
|
|
||||||
}
|
|
||||||
:global(.status-sensitive-media-container.status-sensitive-media-hidden
|
|
||||||
.status-sensitive-media-svg.status-sensitive-media-svg-transparent) {
|
|
||||||
fill: var(--blurhash-sensitive-text-color);
|
fill: var(--blurhash-sensitive-text-color);
|
||||||
background: var(--mask-bg);
|
background: var(--mask-bg);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +184,6 @@
|
||||||
$largeInlineMedia ? 'not-grouped-images' : 'grouped-images'
|
$largeInlineMedia ? 'not-grouped-images' : 'grouped-images'
|
||||||
),
|
),
|
||||||
mediaAttachments: ({ originalStatus }) => originalStatus.media_attachments,
|
mediaAttachments: ({ originalStatus }) => originalStatus.media_attachments,
|
||||||
canUseBlurhash: ({ $ignoreBlurhash, mediaAttachments }) => !$ignoreBlurhash && mediaAttachments && mediaAttachments.every(media => !!media.blurhash),
|
|
||||||
sensitiveShown: ({ $sensitivesShown, uuid }) => !!$sensitivesShown[uuid],
|
sensitiveShown: ({ $sensitivesShown, uuid }) => !!$sensitivesShown[uuid],
|
||||||
sensitive: ({ originalStatus, $markMediaAsSensitive, $neverMarkMediaAsSensitive }) => (
|
sensitive: ({ originalStatus, $markMediaAsSensitive, $neverMarkMediaAsSensitive }) => (
|
||||||
!$neverMarkMediaAsSensitive && ($markMediaAsSensitive || originalStatus.sensitive)
|
!$neverMarkMediaAsSensitive && ($markMediaAsSensitive || originalStatus.sensitive)
|
||||||
|
@ -221,22 +195,6 @@
|
||||||
}
|
}
|
||||||
return `padding-bottom: ${Math.ceil(mediaAttachments.length / 2) * 29}%;`
|
return `padding-bottom: ${Math.ceil(mediaAttachments.length / 2) * 29}%;`
|
||||||
},
|
},
|
||||||
sensitiveMediaButtonClass: ({ canUseBlurhash }) => classname(
|
|
||||||
'status-sensitive-media-button',
|
|
||||||
canUseBlurhash && 'status-sensitive-media-button-transparent'
|
|
||||||
),
|
|
||||||
svgWrapperClass: ({ canUseBlurhash }) => classname(
|
|
||||||
'svg-wrapper',
|
|
||||||
canUseBlurhash && 'svg-wrapper-transparent'
|
|
||||||
),
|
|
||||||
customWarningClass: ({ canUseBlurhash }) => classname(
|
|
||||||
'status-sensitive-media-warning',
|
|
||||||
canUseBlurhash ? 'status-sensitive-media-warning-transparent' : 'status-sensitive-media-warning-opaque'
|
|
||||||
),
|
|
||||||
sensitiveMediaIconClass: ({ canUseBlurhash }) => classname(
|
|
||||||
'status-sensitive-media-svg',
|
|
||||||
canUseBlurhash && 'status-sensitive-media-svg-transparent'
|
|
||||||
),
|
|
||||||
nCols: ({ mediaAttachments, $largeInlineMedia }) => {
|
nCols: ({ mediaAttachments, $largeInlineMedia }) => {
|
||||||
return (!$largeInlineMedia && mediaAttachments.length > 1) ? 2 : 1
|
return (!$largeInlineMedia && mediaAttachments.length > 1) ? 2 : 1
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,7 +35,6 @@ async function decodeUsingCanvas (imageData) {
|
||||||
initCanvas()
|
initCanvas()
|
||||||
canvasContext2D.putImageData(imageData, 0, 0)
|
canvasContext2D.putImageData(imageData, 0, 0)
|
||||||
const blob = await new Promise(resolve => canvas.toBlob(resolve))
|
const blob = await new Promise(resolve => canvas.toBlob(resolve))
|
||||||
console.log('blob.size', blob.size)
|
|
||||||
return URL.createObjectURL(blob)
|
return URL.createObjectURL(blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/routes/_utils/convertCssPropertyToDataUrl.js
Normal file
22
src/routes/_utils/convertCssPropertyToDataUrl.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const colorsToUrls = new Map()
|
||||||
|
let canvas
|
||||||
|
let context
|
||||||
|
|
||||||
|
export function convertCssPropertyToDataUrl (prop) {
|
||||||
|
const color = getComputedStyle(document.documentElement).getPropertyValue(prop)
|
||||||
|
let url = colorsToUrls.get(color)
|
||||||
|
if (!url) {
|
||||||
|
if (!canvas) {
|
||||||
|
canvas = document.createElement('canvas')
|
||||||
|
canvas.width = 1
|
||||||
|
canvas.height = 1
|
||||||
|
context = canvas.getContext('2d')
|
||||||
|
}
|
||||||
|
context.fillStyle = color
|
||||||
|
context.rect(0, 0, 1, 1)
|
||||||
|
context.fill()
|
||||||
|
url = canvas.toDataURL()
|
||||||
|
colorsToUrls.set(color, url)
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue