Skip to content

feat: support ThumbHash as placeholder - #12

Open
subframe7536 wants to merge 1 commit into
solidjs:mainfrom
subframe7536:thumbhash-placeholder
Open

subframe7536 wants to merge 1 commit into
solidjs:mainfrom
subframe7536:thumbhash-placeholder

Conversation

@subframe7536

Copy link
Copy Markdown

Summary

Adds opt-in ThumbHash placeholders alongside the existing inline image and BlurHash previews.

imagePlugin({
  local: {
    sizes: [480, 800, 1200],
    placeholder: { type: "thumbhash" },
  },
});

thumbhash is an optional peer dependency and is only imported when this preview type is enabled.

Why

ThumbHash is a useful alternative to BlurHash because it:

  • has a compact binary representation;
  • supports transparency;
  • includes an approximate aspect ratio;
  • does not require component-count configuration.

This implementation keeps the hash as a Uint8Array, matching the upstream thumbhash API instead of introducing an internal base64 representation.

Implementation

  • Add { type: "thumbhash" } to the Vite plugin placeholder options.
  • Encode local images with rgbaToThumbHash from an EXIF-corrected, max-100px RGBA sample.
  • Preserve alpha in the server-side average placeholder color.
  • Decode in the browser with thumbHashToDataURL.
  • Keep SolidImage independent of thumbhash; generated modules inject the decoder only when needed.
  • Support ThumbHash placeholders from remote.transformURL.
  • Serialize cached/remote hash bytes as arrays and restore them to Uint8Array in generated modules.
  • Keep the existing BlurHash API unchanged; string hashes remain BlurHash, binary hashes are ThumbHash.
  • Add a ThumbHash example, docs, tests, and a minor changeset.

Testing

Validated with:

  • frozen pnpm install;
  • package build;
  • all example builds;
  • Node tests;
  • Playwright Chromium browser tests.

Coverage includes local and remote placeholders, EXIF orientation, the 100px encoding limit, alpha-aware colors, Uint8Array restoration, decoder injection, browser decoding, and preview cleanup after image load.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedthumbhash@​0.1.11001006879100

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant