-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
<script lang="ts"> | ||
import { Image } from "@unpic/svelte"; | ||
import { blurhashToCssGradientString } from "@unpic/placeholder"; | ||
export let blurhash: string | undefined = undefined; | ||
export let alt: string; | ||
export let src: string; | ||
export let width: string | null | undefined = undefined; | ||
export let height: string | null | undefined = undefined; | ||
export let blurhash: string | null | undefined = undefined; | ||
export let priority: boolean = false; | ||
let background: string | undefined = undefined; | ||
let props: any = $$restProps; | ||
$: { | ||
if (blurhash) { | ||
background = blurhashToCssGradientString(blurhash); | ||
} | ||
if (priority) { | ||
props.loading ||= "eager"; | ||
props.fetchpriority ||= "high"; | ||
} else { | ||
props.loading ||= "lazy"; | ||
props.decoding ||= "async"; | ||
} | ||
if (props.alt === "") { | ||
props.role ||= "presentation"; | ||
} | ||
let style = ''; | ||
if (width) { | ||
style += `width: ${width};`; | ||
} | ||
if (height) { | ||
style += `height: ${height};`; | ||
} | ||
if (blurhash) { | ||
let bg = blurhashToCssGradientString(blurhash); | ||
style += `background-image: ${bg};`; | ||
} | ||
props.style += style; | ||
} | ||
</script> | ||
|
||
<Image {background} width={500} height={281} {...$$restProps} /> | ||
<img {src} {alt} {width} {height} {...props} on:error={null} /> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ export default defineConfig({ | |
"jsonwebtoken", | ||
"@prisma/client", | ||
"marked", | ||
"@unpic/placeholder" | ||
], | ||
}, | ||
}); |