Skip to content

Commit

Permalink
More docs and bump to 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Aug 14, 2024
1 parent de3c140 commit 85d8caf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docusaurus-plugin-native-ideal-image",
"version": "0.0.6",
"version": "0.0.7",
"description": "Pre-process images to multiple formats and low quality image placeholders",
"keywords": ["docusaurus"],
"author": "Tony",
Expand Down
19 changes: 12 additions & 7 deletions src/theme/NativeIdealImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ export type NativeIdealImageProps = Omit<ComponentProps<'img'>, 'ref'> & {
/** The output of `import('ideal-img!./some-image.jpeg')` */
readonly img: { default: string | NativeIdealImageData } | string | NativeIdealImageData
/**
* Swap (fade in) the actual image after it's fully loaded,
* requires JavaScript to work, so this might cause the image to load a bit slower
* Swap (fade in) the actual image after it's fully loaded
*
* Note: this requires JavaScript to work,
* so will not work if the script is loaded after the image,
* and also if the image is half loaded when the script kicks in,
* the partially loaded image will get covered by the low quality placeholder
* */
swapOnLoad?: boolean
}
Expand Down Expand Up @@ -51,15 +55,16 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
const imageEl = useRef<HTMLImageElement>(null)

useEffect(() => {
if (loaded) {
return
}
if (imageEl.current?.complete) {
setLoaded(true)
return
}
if (!loaded) {
// Prevent fade in if we have the image cache available (likely being a back/forward navigation)
const id = setTimeout(() => setPlaceHolderOnTop(true), 50)
return () => clearTimeout(id)
}
// Prevent fade in if we have the image cache available (likely being a back/forward navigation)
const id = setTimeout(() => setPlaceHolderOnTop(true), 50)
return () => clearTimeout(id)
}, [loaded])

return (
Expand Down

0 comments on commit 85d8caf

Please sign in to comment.