New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hirasso/thumbhash-custom-element

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hirasso/thumbhash-custom-element

A custom element that renders a thumbhash placeholder for your lazy-loaded images 🎨

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-12.5%
Maintainers
0
Weekly downloads
 
Created
Source

<thumb-hash>

A custom element that automatically renders a thumbhash placeholder for your lazy-loaded images

Test status License

Demo

thumbhash-custom-element.netlify.app

Installation

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>

Usage

Markup

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>

Styling

figure,
figure img {
  position: relative;
}
thumb-hash {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

Strategies

The default strategy of <thumb-hash> is to render a canvas with the blurry representation of the thumbhash. Other options are image and average:

Strategy: 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>

Strategy: 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

Package last updated on 12 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc