-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply LQIP styles with dynamically generated CSS, to support FastBoot
Instead of applying styles with JS *after* rehydration, which is too late.
- Loading branch information
1 parent
8f930a6
commit f007eb3
Showing
16 changed files
with
192 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ | |
.eri-responsive { | ||
content-visibility: auto; | ||
} | ||
|
||
.eri-lqip-inline { | ||
background-size: cover; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const CachingWriter = require('broccoli-caching-writer'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const baseN = require('base-n'); | ||
|
||
const b64 = baseN.create(); | ||
|
||
class CssWriter extends CachingWriter { | ||
constructor(inputNodes, getMeta, cssExtensions, options) { | ||
options = options || {}; | ||
options.cacheInclude = [/.*/]; | ||
super(inputNodes, options); | ||
|
||
this.getMeta = getMeta; | ||
this.cssExtensions = cssExtensions; | ||
} | ||
|
||
async build() { | ||
const destinationPath = path.join( | ||
this.outputPath, | ||
'ember-responsive-image-dynamic.css' | ||
); | ||
|
||
await fs.writeFile(destinationPath, this.generateCss()); | ||
} | ||
|
||
generateCss() { | ||
const meta = this.getMeta(); | ||
let cssEntries = []; | ||
|
||
let classCounter = 0; | ||
const generateClassName = () => `eri-dyn-${b64.encode(classCounter++)}`; | ||
|
||
for (const [image, imageMeta] of Object.entries(meta)) { | ||
for (const { callback, target } of this.cssExtensions) { | ||
const css = callback.call(target, image, imageMeta, { | ||
generateClassName, | ||
}); | ||
if (css) { | ||
cssEntries.push(css); | ||
} | ||
} | ||
} | ||
|
||
return cssEntries.join(`\n`); | ||
} | ||
} | ||
|
||
module.exports = CssWriter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// taken from https://github.com/google/eleventy-high-performance-blog/blob/5ed39db7fd3f21ae82ac1a8e833bf283355bd3d0/_11ty/blurry-placeholder.js#L51 | ||
|
||
export default function blurrySvg( | ||
src: string, | ||
width: number, | ||
height: number | ||
): string { | ||
module.exports = function blurrySvg(src, width, height) { | ||
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}"> | ||
<filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation=".5"></feGaussianBlur><feComponentTransfer><feFuncA type="discrete" tableValues="1 1"></feFuncA></feComponentTransfer></filter> | ||
<image filter="url(#b)" preserveAspectRatio="none" height="100%" width="100%" xlink:href="${src}"></image> | ||
</svg>`; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = function dataUri(data, type, base64 = false) { | ||
return `data:${type};base64,${ | ||
base64 ? data : Buffer.from(data).toString('base64') | ||
}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
<ResponsiveImage @src="assets/images/tests/test.png"/> | ||
<ResponsiveImage @src="assets/images/tests/test.png" data-test-simple-image/> | ||
|
||
<ResponsiveImage @src="assets/images/tests/lqip/color.jpg" data-test-lqip-image="color"/> | ||
<ResponsiveImage @src="assets/images/tests/lqip/inline.jpg" data-test-lqip-image="inline"/> | ||
<ResponsiveImage @src="assets/images/tests/lqip/blurhash.jpg" data-test-lqip-image="blurhash"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.