-
Notifications
You must be signed in to change notification settings - Fork 53
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
12 changed files
with
150 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
// @ts-expect-error - Astro imports don't work with TypeScript libs :( | ||
export { default as Image } from "./src/Image.astro"; | ||
// @ts-expect-error - Astro imports don't work with TypeScript libs :( | ||
export { default as Source } from "./src/Source.astro"; |
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,2 @@ | ||
export { default as Image } from "./base/Image.astro"; | ||
export { default as Source } from "./base/Source.astro"; |
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,62 @@ | ||
--- | ||
import { imageConfig } from "astro:assets"; | ||
import type { Operations, UnpicBaseImageProps } from "@unpic/core"; | ||
import { | ||
inferImageDimensions, | ||
transformBaseImageProps, | ||
} from "@unpic/core/base"; | ||
import type { ImageMetadata } from "astro"; | ||
import type { HTMLAttributes } from "astro/types"; | ||
import { getBackground } from "../background"; | ||
import type { UnpicConfig } from "../service"; | ||
type Props< | ||
TOperations extends Operations = Operations, | ||
TOptions = unknown, | ||
> = Omit< | ||
UnpicBaseImageProps<TOperations, TOptions, astroHTML.JSX.ImgHTMLAttributes>, | ||
"src" | ||
> & { | ||
placeholder?: "none" | "blurhash" | "dominantColor" | "lqip" | ({} & string); | ||
src: string | ImageMetadata; | ||
}; | ||
const { placeholder, ...props }: Props = Astro.props; | ||
type BaseImageProps = UnpicBaseImageProps< | ||
Operations, | ||
unknown, | ||
HTMLAttributes<"img"> | ||
>; | ||
let imgProps: BaseImageProps; | ||
if (typeof props.src === "object") { | ||
imgProps = { | ||
...props, | ||
src: props.src.src, | ||
...inferImageDimensions(props, props.src), | ||
} as BaseImageProps; | ||
} else { | ||
imgProps = { | ||
...props, | ||
} as BaseImageProps; | ||
} | ||
const config: UnpicConfig = imageConfig.service?.config; | ||
imgProps.layout ||= config?.layout; | ||
imgProps.background ||= placeholder ?? config?.placeholder; | ||
imgProps.background = await getBackground(imgProps); | ||
--- | ||
|
||
<img | ||
{...transformBaseImageProps< | ||
Operations, | ||
unknown, | ||
astroHTML.JSX.ImgHTMLAttributes, | ||
astroHTML.JSX.ImgHTMLAttributes["style"] | ||
>(imgProps)} | ||
/> |
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,36 @@ | ||
--- | ||
import { imageConfig } from "astro:assets"; | ||
import type { Operations, UnpicBaseSourceProps } from "@unpic/core"; | ||
import type { UnpicConfig } from "../service"; | ||
import { | ||
transformBaseSourceProps, | ||
inferImageDimensions, | ||
} from "@unpic/core/base"; | ||
type Props<TOperations extends Operations, TOptions> = Omit< | ||
UnpicBaseSourceProps<TOperations, TOptions>, | ||
"src" | ||
> & { | ||
src: string | ImageMetadata; | ||
}; | ||
const props = Astro.props as Props<Operations, unknown>; | ||
let sourceProps: UnpicBaseSourceProps<Operations, unknown>; | ||
if (typeof props.src === "object") { | ||
sourceProps = { | ||
...props, | ||
src: props.src.src, | ||
...inferImageDimensions(props, props.src), | ||
} as UnpicBaseSourceProps<Operations, unknown>; | ||
} else { | ||
sourceProps = props as UnpicBaseSourceProps<Operations, unknown>; | ||
} | ||
const config: UnpicConfig = imageConfig.service?.config; | ||
sourceProps.layout ||= config?.layout; | ||
--- | ||
|
||
<source {...transformBaseSourceProps(sourceProps)} /> |
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