-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
types.ts
178 lines (156 loc) · 4.97 KB
/
types.ts
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import type { html } from 'satori-html'
import type { H3Error, H3Event } from 'h3'
import type { ResvgRenderOptions } from '@resvg/resvg-js'
import type { SatoriOptions } from 'satori'
import type { AllowedComponentProps, Component, ComponentCustomProps, VNodeProps } from '@vue/runtime-core'
import type { SharpOptions } from 'sharp'
import type { NitroApp } from 'nitropack'
import type { UnwasmPluginOptions as WasmOptions } from 'unwasm/plugin'
import type { OgImageComponents } from '#nuxt-og-image/components'
export interface OgImageRenderEventContext {
e: H3Event
extension: 'png' | 'jpeg' | 'jpg' | 'svg' | 'html' | 'json'
key: string
basePath: string
renderer: Renderer
options: OgImageOptions
isDebugJsonPayload: boolean
_nitro: NitroApp
}
export type IconifyEmojiIconSets = 'twemoji' | 'noto' | 'fluent-emoji' | 'fluent-emoji-flat' | 'fluent-emoji-high-contrast' | 'noto-v1' | 'emojione' | 'emojione-monotone' | 'emojione-v1' | 'streamline-emojis' | 'openmoji'
export interface OgImageRuntimeConfig {
version: string
satoriOptions: SatoriOptions
resvgOptions: ResvgRenderOptions
sharpOptions: SharpOptions
defaults: OgImageOptions
debug: boolean
baseCacheKey: string
fonts: FontConfig[]
hasNuxtIcon: boolean
colorPreference: 'light' | 'dark'
isNuxtContentDocumentDriven: boolean
}
export interface OgImageComponent {
path?: string
pascalName: string
kebabName: string
hash: string
category: 'app' | 'community' | 'pro'
credits?: string
}
export interface ScreenshotOptions {
colorScheme?: 'dark' | 'light'
selector?: string
mask?: string
/**
* The width of the screenshot.
*
* @default 1200
*/
width: number
/**
* The height of the screenshot.
*
* @default 630
*/
height: number
/**
* How long to wait before taking the screenshot. Useful for waiting for animations.
*/
delay?: number
}
export type OgImagePrebuilt = { url: string } & Pick<OgImageOptions, 'width' | 'height' | 'alt' | '_query'>
export type DefineOgImageInput = OgImageOptions | OgImagePrebuilt | false
export interface OgImageOptions<T extends keyof OgImageComponents = 'NuxtSeo'> {
/**
* The width of the screenshot.
*
* @default 1200
*/
width?: number
/**
* The height of the screenshot.
*
* @default 630
*/
height?: number
/**
* The alt text for the image.
*/
alt?: string
/**
* Use a prebuilt image instead of generating one.
*
* Should be an absolute URL.
*/
url?: string
/**
* The name of the component to render.
*/
component?: T | string
/**
* Props to pass to the component.
*/
props?: OgImageComponents[T] | Record<string, any>
renderer?: 'chromium' | 'satori'
extension?: 'png' | 'jpeg' | 'jpg'
emojis?: IconifyEmojiIconSets
/**
* Provide a static HTML template to render the OG Image instead of a component.
*/
html?: string
// vendor config
resvg?: ResvgRenderOptions
satori?: SatoriOptions
screenshot?: Partial<ScreenshotOptions>
sharp?: SharpOptions
fonts?: InputFontConfig[]
// cache
cacheMaxAgeSeconds?: number
/**
* @internal
*/
_query?: Record<string, any>
}
export interface FontConfig {
name: string
style?: string
weight?: string | number
path?: string
key?: string
absolutePath?: boolean
}
export interface ResolvedFontConfig extends FontConfig { cacheKey: string, data?: BufferSource }
export type InputFontConfig = (`${string}:${number}` | string | FontConfig)
export interface RuntimeCompatibilitySchema {
chromium: 'chrome-launcher' | 'on-demand' | 'playwright' | false
['css-inline']: 'node' | 'wasm' | 'wasm-fs' | false
resvg: 'node' | 'wasm' | 'wasm-fs' | false
satori: 'node' | 'wasm' | 'wasm-fs' | false
sharp: 'node' | false
wasm?: WasmOptions
}
export type CompatibilityFlags = Partial<Omit<RuntimeCompatibilitySchema, 'wasm'>>
export interface CompatibilityFlagEnvOverrides {
dev?: CompatibilityFlags
runtime?: CompatibilityFlags
prerender?: CompatibilityFlags
}
export type RendererOptions = Omit<OgImageOptions, 'extension'> & { extension: Omit<OgImageOptions['extension'], 'html'> }
export interface Renderer {
name: 'chromium' | 'satori'
supportedFormats: Partial<RendererOptions['extension']>[]
createImage: (e: OgImageRenderEventContext) => Promise<H3Error | BufferSource | void>
debug: (e: OgImageRenderEventContext) => Promise<Record<string, any>>
}
export type ExtractComponentProps<T extends Component> = T extends new (...args: any) => any
? Omit<InstanceType<T>['$props'], keyof ComponentCustomProps | keyof VNodeProps | keyof AllowedComponentProps>
: never
export type OgImagePageScreenshotOptions = Omit<OgImageOptions, 'html' | 'renderer' | 'component' | 'satori' | 'resvg' | 'sharp'>
export type VNode = ReturnType<typeof html>
export interface SatoriTransformer {
filter: (node: VNode) => boolean
transform: (node: VNode, e: OgImageRenderEventContext) => Promise<void>
}
export interface SocialPreviewMetaData { twitter?: Record<string, string>, og?: Record<string, string> }