Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@hirasso/thumbhash-custom-element
Advanced tools
A custom element that renders a thumbhash placeholder for your lazy-loaded images 🎨
A custom element that automatically renders a thumbhash placeholder for your lazy-loaded images
thumbhash-custom-element.netlify.app
This package is intended for frontend-only use only. It assumes you have already pre-generated your thumbhashes on the server or during an SSG build step. Many server-side libraries already provide convenience functions that will generate a thumbhash data URI for you. This is fine for pages with a few images, but will quickly increase the size of your html if you have more images. This is where thumbhash-custom-element
comes in. All data-heavy calculation will be executed on the frontend, keeping your html small.
Install from npm and import it into your bundle:
npm i @hirasso/thumbhash-custom-element
import { ThumbHashElement } from "thumbhash-custom-element";
ThumbHashElement.init();
Or include the minified production file from a CDN:
<script type="module">
import { ThumbHashElement } from "https://unpkg.com/@hirasso/thumbhash-custom-element@0?module";
ThumbHashElement.init();
</script>
Add <thumb-hash>
elements with your pre-generated thumbhash strings to your markup:
<figure>
+ <thumb-hash value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" />
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
Result:
<figure>
+ <thumb-hash value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" aria-hidden="true">
+ ⏷ #shadow-root (open)
+ <canvas width="32" height="32" style="width: 100%; height: 100%;"></canvas>
+ </thumb-hash>
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
figure,
figure img {
position: relative;
}
thumb-hash {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
The default strategy of <thumb-hash>
is to render a canvas
with the blurry representation of the thumbhash. Other options are img
and average
:
img
Add the attribute strategy="img"
to render an image with a data URI:
<figure>
+ <thumb-hash strategy="img" value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" />
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
Result:
<figure>
+ <thumb-hash strategy="img" value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" aria-hidden="true">
+ ⏷ #shadow-root (open)
+ <img alt="" src="data:image/png;base64,iVBORw0KGgo..." style="width: 100%; height: 100%;">
+ </thumb-hash>
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
average
Add the attribute strategy="average"
to render a div with the average color:
<figure>
+ <thumb-hash strategy="average" value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" />
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
Result:
<figure>
+ <thumb-hash strategy="average" value="YTkGJwaRhWUIt4lbgnhZl3ath2BUBGYA" aria-hidden="true">
+ ⏷ #shadow-root (open)
+ <div style="width: 100%; height: 100%; background: rgb(111, 51, 0);"></div>
+ </thumb-hash>
<img src="https://example.com/image.jpg" loading="lazy" width="32" height="32" alt="My large lazy-loaded image">
</figure>
FAQs
A custom element that renders a thumbhash placeholder for your lazy-loaded images 🎨
The npm package @hirasso/thumbhash-custom-element receives a total of 9 weekly downloads. As such, @hirasso/thumbhash-custom-element popularity was classified as not popular.
We found that @hirasso/thumbhash-custom-element demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.