-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
166 additions
and
44 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
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
import { Image } from "@unpic/astro"; | ||
import { Opulento } from "uvcanvas"; | ||
import { getImagePlaceholder } from "~/utils/get-image-placeholder"; | ||
import CoverImgContainer from "./cover-img-container.astro"; | ||
import ImgFrame from "./img-frame.astro"; | ||
interface Props { | ||
src: string; | ||
class?: string; | ||
} | ||
const { src, class: className } = Astro.props; | ||
const placeholder = await getImagePlaceholder(src); | ||
--- | ||
|
||
<CoverImgContainer class={className}> | ||
<Fragment slot="image"> | ||
<ImgFrame class="aspect-[4/3] relative"> | ||
<slot id="canva-container" /> | ||
<a | ||
id="image-link" | ||
href={src} | ||
target="_blank" | ||
rel="noreferrer" | ||
class="w-full h-full absolute inset-0" | ||
> | ||
<Image | ||
src={src} | ||
width={672} | ||
height={504} | ||
placeholder="blurhash" | ||
background={placeholder} | ||
priority | ||
fetchpriority="high" | ||
class="aspect-[4/3] w-full h-full" | ||
/> | ||
</a> | ||
</ImgFrame> | ||
</Fragment> | ||
<Fragment slot="description"> | ||
<slot name="description" /> | ||
</Fragment> | ||
</CoverImgContainer> | ||
|
||
<script> | ||
const observer = new MutationObserver((mutations) => { | ||
mutations.forEach((mutation) => { | ||
const { target } = mutation; | ||
|
||
if ("querySelector" in target) { | ||
const canvas = (target as HTMLElement).querySelector("canvas"); | ||
if (canvas) { | ||
const imgLinkEl = document.getElementById("image-link"); | ||
if (imgLinkEl) { | ||
imgLinkEl.style.opacity = "0"; | ||
} | ||
observer.disconnect(); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
const containerEl = document.getElementById("canva-container"); | ||
if (containerEl) { | ||
observer.observe(containerEl, { childList: true, subtree: true }); | ||
} | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
import { cn } from "~/utils/cn"; | ||
import ImgFrame from "./img-frame.astro"; | ||
interface Props { | ||
description?: string; | ||
class?: string; | ||
} | ||
const { class: className } = Astro.props; | ||
--- | ||
|
||
<div class={cn(className, "flex flex-col items-center")}> | ||
<div class="select-none w-full mb-3"> | ||
<slot name="image" /> | ||
</div> | ||
<p class="small text-muted"> | ||
<slot name="description" /> | ||
</p> | ||
</div> |
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,36 +1,38 @@ | ||
--- | ||
import { Image } from "@unpic/astro"; | ||
import { cn } from "~/utils/cn"; | ||
import { getImagePlaceholder } from "~/utils/get-image-placeholder"; | ||
import CoverImgContainer from "./cover-img-container.astro"; | ||
import ImgFrame from "./img-frame.astro"; | ||
interface Props { | ||
src: string; | ||
alt: string; | ||
description?: string; | ||
class?: string; | ||
width: number; | ||
height: number; | ||
} | ||
const { class: className, src, description, ...otherProps } = Astro.props; | ||
const { class: className, src, ...otherProps } = Astro.props; | ||
const placeholder = await getImagePlaceholder(src); | ||
--- | ||
|
||
<div class={cn(className, "flex flex-col items-center")}> | ||
<div class="select-none w-full mb-3"> | ||
<a href={src} target="_blank" rel="noreferrer"> | ||
<Image | ||
{...otherProps} | ||
src={src} | ||
class="md:border-8 border-[6px] aspect-[4/3] w-full h-full" | ||
placeholder="blurhash" | ||
background={placeholder} | ||
priority | ||
fetchpriority="high" | ||
/> | ||
</a> | ||
</div> | ||
<slot name="description"> | ||
<span class="small text-muted">{description}</span> | ||
</slot> | ||
</div> | ||
<CoverImgContainer class={className}> | ||
<Fragment slot="image"> | ||
<ImgFrame> | ||
<a href={src} target="_blank" rel="noreferrer" class="w-full h-full"> | ||
<Image | ||
{...otherProps} | ||
src={src} | ||
placeholder="blurhash" | ||
background={placeholder} | ||
priority | ||
fetchpriority="high" | ||
class="aspect-[4/3] w-full h-full" | ||
/> | ||
</a> | ||
</ImgFrame> | ||
</Fragment> | ||
<Fragment slot="description"> | ||
<slot name="description" /> | ||
</Fragment> | ||
</CoverImgContainer> |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
import { cn } from "~/utils/cn"; | ||
interface Props { | ||
class?: string; | ||
} | ||
const { class: className } = Astro.props; | ||
--- | ||
|
||
<div class={cn(className, "md:border-8 border-[6px]")}> | ||
<slot /> | ||
</div> |
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