-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathimage.ts
More file actions
123 lines (104 loc) · 3.56 KB
/
image.ts
File metadata and controls
123 lines (104 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import type { RuntimeConfig } from '@nuxt/schema'
import type { H3Event } from 'h3'
import type { ConfiguredImageProviders, ImageProviders, ProviderDefaults } from './module'
export interface ImageModifiers {
width: number | string
height: number | string
fit: string
format: string
quality: string | number
background: string
blur: number | string
}
export interface ResolvedImageModifiers extends ImageModifiers {
width: number
height: number
}
type DefaultProvider = ProviderDefaults extends Record<'provider', unknown> ? ProviderDefaults['provider'] : never
export interface ImageOptions<Provider extends keyof ConfiguredImageProviders = DefaultProvider> {
provider?: Provider
preset?: string
densities?: string
modifiers?: Partial<Omit<ImageModifiers, 'format' | 'quality' | 'background' | 'fit'>>
& ('modifiers' extends keyof ConfiguredImageProviders[Provider] ? ConfiguredImageProviders[Provider]['modifiers'] : Record<string, unknown>)
sizes?: string | Record<string, any>
}
export interface ImageSizesOptions extends ImageOptions {
sizes: Record<string, string | number> | string
}
export type ProviderGetImage<T = Record<string, unknown>> = (src: string, options: Omit<ImageOptions, 'modifiers'> & { modifiers: Partial<ResolvedImageModifiers> } & T, ctx: ImageCTX) => ResolvedImage
interface ImageModifierOptions {
modifiers?: Record<string, unknown>
}
export interface ImageProvider<T> extends ImageModifierOptions {
defaults?: T
getImage: ProviderGetImage<T>
validateDomains?: boolean
supportsAlias?: boolean
}
export interface CreateImageOptions {
providers: Record<keyof ConfiguredImageProviders, {
defaults: unknown
setup: () => ImageProvider<Record<string, unknown>>
}>
nuxt: {
baseURL: string
}
event?: H3Event
presets: { [name: string]: ImageOptions }
provider: (string & {}) | keyof ImageProviders
screens: Record<string, number>
alias: Record<string, string>
domains: string[]
densities: number[]
format: string[]
quality?: number
runtimeConfig: RuntimeConfig
}
export interface ImageInfo {
width: number
height: number
placeholder?: string
}
export interface ResolvedImage {
url: string
format?: string
getMeta?: () => Promise<ImageInfo>
}
export interface ImageSizes {
srcset: string
sizes: string | undefined
src?: string
}
export interface Img {
(source: string, modifiers?: ImageOptions['modifiers'], options?: ImageOptions): ResolvedImage['url']
options: CreateImageOptions
getImage: (source: string, options?: ImageOptions) => ResolvedImage
getSizes: (source: string, options?: ImageOptions, sizes?: string[]) => ImageSizes
getMeta: (source: string, options?: ImageOptions) => Promise<ImageInfo>
}
export type $Img = Img & {
[preset: string]: $Img
}
export interface ImageCTX {
options: CreateImageOptions
$img?: $Img
}
export type OperationMapper<From, To> = Record<string | Extract<From, string | number>, To> | ((key?: From) => To | From | undefined)
export type OperationGeneratorConfig<Key extends string, Value, FinalKey, FinalValue> = {
keyMap?: Partial<Record<Key, FinalKey>>
valueMap?: Partial<Record<Key, Partial<Record<Extract<Value, string>, FinalValue>> | ((key: Value) => Value | FinalValue)>>
} & ({
formatter?: (key: FinalKey, value: FinalValue) => string
joinWith?: undefined
} | {
formatter: (key: FinalKey, value: FinalValue) => string
joinWith: string
})
export interface ImageSizesVariant {
size?: string
screenMaxWidth: number
_cWidth: number
_cHeight?: number | undefined
}
export type DataAttributes = Record<`data-${string}`, string>