Skip to content

Commit

Permalink
feat: strongly typed options for format options
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Jan 12, 2022
1 parent 9aa98a1 commit 7db1e03
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import type { Sharp, FormatEnum } from 'sharp'
import type {
Sharp,
OutputOptions,
AvifOptions,
GifOptions,
HeifOptions,
JpegOptions,
PngOptions,
TiffOptions,
WebpOptions,
} from 'sharp'
import { createImageApi } from './api'

export type ImageApi = ReturnType<typeof createImageApi>

export type Image = Sharp
export type ImageFormat = keyof FormatEnum
export type ImageFormats = { [k in ImageFormat]?: any }
export interface ImageFormatOptions {
avif: AvifOptions
gif: GifOptions
heif: HeifOptions
jpeg: JpegOptions
jpg: JpegOptions
png: PngOptions
tiff: TiffOptions
tif: TiffOptions
webp: WebpOptions
}
export type ImageFormats = Partial<ImageFormatOptions>
export type ImageFormat = keyof ImageFormatOptions

export type ImageAttrs = Partial<HTMLImageElement> & { class?: string }
export type ImageResult = ImageAttrs[] & { src?: string }

export type ImageGeneratorArgs = Record<string, any>
export type ImageGenerator = (image: Sharp, args: ImageGeneratorArgs) => Sharp
export type ImageGenerator = (image: Image, args: ImageGeneratorArgs) => Image | Promise<Image>
export interface ImageSpec {
/**
* A condition descriptor that specifies when the image should be used.
Expand Down

0 comments on commit 7db1e03

Please sign in to comment.