add: opt-in BlurHash placeholder - #8
Merged
Merged
Conversation
- Set placeholder: { type: "blurhash" } in the plugin to use a BlurHash instead of the inline image preview.
- blurhash is an optional peer dependency, loaded with a dynamic import and checked when the build starts.
- The generated module imports decode only when the option is on. The component never imports blurhash.
- The server paints the average color. The browser decodes the hash into a small canvas.
- Remote images can return { hash, color } from transformURL.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
commit: |
- Pass the configured sizes to getImageSource, so the source uses the largest real width from main. - Keep the publicDir default from main next to the placeholder resolution. - Turn the BlurHash sample upright with autoOrient, matching the variants and the inline preview. - Keep the tests from both sides, and add a test for a rotated photo hash. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Drop the componentX and componentY options. The whole config is placeholder: { type: "blurhash" }.
- Split a budget of about 12 components by aspect ratio, so the long side gets more and detail stays even.
- A 4:3 image still gets 4 by 3, the usual default.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a BlurHash preview as an alternative to the inline image preview. It is
off by default, and
blurhashis an optional peer dependency that apps installonly when they turn it on.
Changes
placeholder: { type: "blurhash" }in the plugin to use a BlurHashinstead of the 20px inline image. The inline image stays the default.
image from its aspect ratio, about 12 in total. The long side gets more, so
portraits and landscapes keep even detail. A 4:3 image gets the usual 4 by 3.
blurhashis listed as an optional peer dependency. The plugin loads it with adynamic import.
blurhashwhen the build starts. If it is missing, thedev server or build stops with install steps instead of failing on the first
image.
ships the hash with the average color.
decodefromblurhashonly when the option ison. The component never imports the package, so apps without it are
unaffected.
browser decodes the hash into a 32px wide canvas at the image's aspect ratio
and paints it over that color.
preview.
{ hash, color }fromtransformURL. The pluginadds the decoder for them.
How it was tested
pnpm testruns 152 tests across both projects and they pass.banner and strip shapes, and counts stay within 1 to 9.
reports the average color. A portrait gets 3 by 5 components and a 10:1
banner gets 9 by 1.
never import
blurhash.blurhashand checks that the build fails atstartup with the install message.
average color, the image is reduced to fit inside 32px, and a rotated photo is
hashed upright.
decoder is never called.
painted before the image loads, and removed once it loads.
pnpm buildsucceeds.dist/vite.jskeepsimport("blurhash")external, anddist/index.jsxdoes not reference the package.tsc --noEmitreports one pre-existing error insrc/vite/fs.ts, unrelated tothis change.
Notes for review
mainwas merged in after #7 landed. The BlurHash sample calls.autoOrient(),like the variants and the inline preview.
🤖 Generated with Claude Code