From 8949b36873de93003f523feeac26895b84624259 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 22 Aug 2018 21:00:53 -0700 Subject: [PATCH] Use img.decode() (#473) * remove will-change:transform from container * WIP: use img.decode() * more work on img.decode --- routes/_components/Avatar.html | 70 ++++++++----------- routes/_components/LazyImage.html | 64 +++++++++-------- routes/_components/NonAutoplayImg.html | 65 ++++++++++------- .../settings/instances/[instanceName].html | 4 +- routes/_store/observers/observers.js | 2 + routes/_store/observers/resizeObservers.js | 14 ++++ routes/_utils/decodeImage.js | 14 ++++ routes/_utils/events.js | 20 ------ 8 files changed, 137 insertions(+), 116 deletions(-) create mode 100644 routes/_store/observers/resizeObservers.js create mode 100644 routes/_utils/decodeImage.js diff --git a/routes/_components/Avatar.html b/routes/_components/Avatar.html index f1380a9..7191f42 100644 --- a/routes/_components/Avatar.html +++ b/routes/_components/Avatar.html @@ -1,13 +1,15 @@ {#if error} - {:else} @@ -17,6 +19,8 @@ alt="" src={account.avatar} staticSrc={account.avatar_static} + {width} + {height} {isLink} on:imgLoad="set({loaded: true})" on:imgLoadError="set({error: true})" @@ -32,48 +36,17 @@ background: none; } - :global(.avatar.size-extra-small) { - width: 24px; - height: 24px; - } - - :global(.avatar.size-small) { - width: 48px; - height: 48px; - } - - :global(.avatar.size-medium) { - width: 64px; - height: 64px; - } - - :global(.avatar.size-big) { - width: 100px; - height: 100px; - } - - @media (max-width: 767px) { - :global(.avatar.size-big) { - width: 80px; - height: 80px; - } - } - svg.avatar { fill: var(--deemphasized-text-color); } \ No newline at end of file diff --git a/routes/_components/LazyImage.html b/routes/_components/LazyImage.html index 5304c3d..acf72f3 100644 --- a/routes/_components/LazyImage.html +++ b/routes/_components/LazyImage.html @@ -1,14 +1,13 @@ -
+
{#if displaySrc} {alt {/if}
@@ -16,40 +15,45 @@ .lazy-image { overflow: hidden; } - .lazy-image img { - transition: opacity 0.2s linear; - } \ No newline at end of file diff --git a/routes/_components/NonAutoplayImg.html b/routes/_components/NonAutoplayImg.html index 57ee503..2455e30 100644 --- a/routes/_components/NonAutoplayImg.html +++ b/routes/_components/NonAutoplayImg.html @@ -1,22 +1,13 @@ -{#if staticSrc === src} - {alt -{:else} - {alt -{/if} + \ No newline at end of file diff --git a/routes/_pages/settings/instances/[instanceName].html b/routes/_pages/settings/instances/[instanceName].html index ffa4a26..353cb16 100644 --- a/routes/_pages/settings/instances/[instanceName].html +++ b/routes/_pages/settings/instances/[instanceName].html @@ -4,7 +4,9 @@ {#if verifyCredentials}

Logged in as:

- +
+ +
{'@' + verifyCredentials.acct} diff --git a/routes/_store/observers/observers.js b/routes/_store/observers/observers.js index 7066a9d..3f0f515 100644 --- a/routes/_store/observers/observers.js +++ b/routes/_store/observers/observers.js @@ -5,6 +5,7 @@ import { onlineObservers } from './onlineObservers' import { navObservers } from './navObservers' import { autosuggestObservers } from './autosuggestObservers' import { pageVisibilityObservers } from './pageVisibilityObservers' +import { resizeObservers } from './resizeObservers' export function observers (store) { instanceObservers(store) @@ -14,4 +15,5 @@ export function observers (store) { navObservers(store) autosuggestObservers(store) pageVisibilityObservers(store) + resizeObservers(store) } diff --git a/routes/_store/observers/resizeObservers.js b/routes/_store/observers/resizeObservers.js new file mode 100644 index 0000000..f4ae748 --- /dev/null +++ b/routes/_store/observers/resizeObservers.js @@ -0,0 +1,14 @@ +import { registerResizeListener } from '../../_utils/resize' + +export function resizeObservers (store) { + if (!process.browser) { + return + } + + const recalculateIsMobileSize = () => { + store.set({isMobileSize: window.matchMedia('(max-width: 767px)').matches}) + } + + registerResizeListener(recalculateIsMobileSize) + recalculateIsMobileSize() +} diff --git a/routes/_utils/decodeImage.js b/routes/_utils/decodeImage.js new file mode 100644 index 0000000..b661777 --- /dev/null +++ b/routes/_utils/decodeImage.js @@ -0,0 +1,14 @@ +export function decodeImage (src) { + if (typeof Image.prototype.decode === 'function') { + let img = new Image() + img.src = src + return img.decode() + } + + return new Promise((resolve, reject) => { + let img = new Image() + img.src = src + img.onload = resolve + img.onerror = reject + }) +} diff --git a/routes/_utils/events.js b/routes/_utils/events.js index f853d1e..3188479 100644 --- a/routes/_utils/events.js +++ b/routes/_utils/events.js @@ -1,23 +1,3 @@ -export function imgLoadError (node, callback) { - node.addEventListener('error', callback) - - return { - destroy () { - node.removeEventListener('error', callback) - } - } -} - -export function imgLoad (node, callback) { - node.addEventListener('load', callback) - - return { - destroy () { - node.removeEventListener('load', callback) - } - } -} - export function mouseover (node, callback) { function onMouseEnter () { callback(true) // eslint-disable-line