@ubean/image 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,417 @@
1
+ import { hash } from "ohash";
2
+ import { hasProtocol, joinURL } from "ufo";
3
+ //#region src/core.ts
4
+ const formatMap = {
5
+ webp: "image/webp",
6
+ avif: "image/avif",
7
+ jpeg: "image/jpeg",
8
+ jpg: "image/jpeg",
9
+ png: "image/png",
10
+ gif: "image/gif",
11
+ svg: "image/svg+xml"
12
+ };
13
+ function detectFormat(src) {
14
+ const ext = src.split("?")[0].split(".").pop()?.toLowerCase();
15
+ if (ext && ext in formatMap) return ext;
16
+ }
17
+ function isRemoteUrl(src) {
18
+ if (src.startsWith("//")) return true;
19
+ return hasProtocol(src, { acceptRelative: false });
20
+ }
21
+ function isDataUrl(src) {
22
+ return src.startsWith("data:");
23
+ }
24
+ function resolveAlias(src, alias) {
25
+ for (const [prefix, target] of Object.entries(alias)) if (src.startsWith(prefix)) return joinURL(target, src.slice(prefix.length));
26
+ return src;
27
+ }
28
+ function validateDomain(src, domains) {
29
+ if (!domains.length) return true;
30
+ if (!isRemoteUrl(src)) return true;
31
+ try {
32
+ const url = new URL(src);
33
+ return domains.some((domain) => url.hostname === domain || url.hostname.endsWith(`.${domain}`));
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+ function createIPXUrl(baseURL, src, modifiers = {}, defaultModifiers = {}) {
39
+ const mods = {
40
+ ...defaultModifiers,
41
+ ...modifiers
42
+ };
43
+ const segments = [];
44
+ if (mods.width) segments.push(`w_${mods.width}`);
45
+ if (mods.height) segments.push(`h_${mods.height}`);
46
+ if (mods.fit) segments.push(`f_${mods.fit}`);
47
+ if (mods.position) segments.push(`p_${encodeURIComponent(mods.position)}`);
48
+ if (mods.format) segments.push(`fm_${mods.format}`);
49
+ if (mods.quality) segments.push(`q_${mods.quality}`);
50
+ if (mods.blur) segments.push(`blur_${mods.blur}`);
51
+ if (mods.sharpen) segments.push(`sharpen_${mods.sharpen}`);
52
+ if (mods.rotate) segments.push(`rot_${mods.rotate}`);
53
+ if (mods.background) segments.push(`bg_${encodeURIComponent(mods.background)}`);
54
+ if (mods.grayscale) segments.push("grayscale");
55
+ if (mods.negate) segments.push("negate");
56
+ if (mods.trim) segments.push("trim");
57
+ if (mods.enlarge) segments.push("enlarge");
58
+ if (mods.flip === "h") segments.push("fh");
59
+ if (mods.flip === "v") segments.push("fv");
60
+ if (mods.flip === "hv") segments.push("fh", "fv");
61
+ if (mods.brightness !== void 0) segments.push(`br_${mods.brightness}`);
62
+ if (mods.contrast !== void 0) segments.push(`con_${mods.contrast}`);
63
+ if (mods.saturation !== void 0) segments.push(`sat_${mods.saturation}`);
64
+ return joinURL(baseURL, segments.length > 0 ? segments.join(",") : "_", src);
65
+ }
66
+ function createStaticUrl(baseURL, src, modifiers = {}, defaultModifiers = {}, dir = "") {
67
+ const mods = {
68
+ ...defaultModifiers,
69
+ ...modifiers
70
+ };
71
+ const ext = detectFormat(src) || "webp";
72
+ const format = mods.format || ext;
73
+ const suffixParts = [];
74
+ if (mods.width) suffixParts.push(`w${mods.width}`);
75
+ if (mods.height) suffixParts.push(`h${mods.height}`);
76
+ if (mods.quality) suffixParts.push(`q${mods.quality}`);
77
+ if (mods.blur) suffixParts.push(`blur${mods.blur}`);
78
+ const suffix = suffixParts.length > 0 ? `_${suffixParts.join("_")}` : "";
79
+ return joinURL(baseURL, dir, `${src.replace(/\.[^.]+$/, "")}${suffix}.${format}`);
80
+ }
81
+ const ipxProvider = {
82
+ name: "ipx",
83
+ getImage(src, mods, ctx) {
84
+ return { url: createIPXUrl(ctx?.options.ipx.baseURL || "/_ipx", src, mods, ctx?.options.ipx.modifiers || {}) };
85
+ }
86
+ };
87
+ const staticProvider = {
88
+ name: "static",
89
+ getImage(src, mods, ctx) {
90
+ const baseURL = ctx?.options.static.baseURL || "/_image";
91
+ const dir = ctx?.options.static.dir || "";
92
+ return { url: createStaticUrl(baseURL, src, mods, ctx?.options.static.modifiers || {}, dir) };
93
+ }
94
+ };
95
+ const cloudinaryProvider = {
96
+ name: "cloudinary",
97
+ getImage(src, mods = {}, ctx) {
98
+ const baseURL = ctx?.options.cloudinary?.baseURL || "";
99
+ const transforms = [];
100
+ if (mods.width || mods.height) {
101
+ transforms.push(`c_${mods.fit || "fill"}`);
102
+ if (mods.width) transforms.push(`w_${mods.width}`);
103
+ if (mods.height) transforms.push(`h_${mods.height}`);
104
+ if (mods.position) transforms.push(`g_${mods.position.replace(" ", "_")}`);
105
+ }
106
+ if (mods.quality) transforms.push(`q_${mods.quality}`);
107
+ if (mods.format) transforms.push(`f_${mods.format}`);
108
+ if (mods.rotate) transforms.push(`a_${mods.rotate}`);
109
+ if (mods.blur) transforms.push(`e_blur:${Math.round(mods.blur * 20)}`);
110
+ if (mods.grayscale) transforms.push("e_grayscale");
111
+ if (mods.negate) transforms.push("e_negate");
112
+ return { url: joinURL(baseURL, "image/upload", transforms.length > 0 ? `${transforms.join(",")}/` : "", src) };
113
+ }
114
+ };
115
+ const imgixProvider = {
116
+ name: "imgix",
117
+ getImage(src, mods = {}, ctx) {
118
+ const baseURL = ctx?.options.imgix?.baseURL || "";
119
+ const params = new URLSearchParams();
120
+ if (mods.width) params.set("w", String(mods.width));
121
+ if (mods.height) params.set("h", String(mods.height));
122
+ if (mods.fit) params.set("fit", mods.fit === "cover" ? "crop" : mods.fit);
123
+ if (mods.position) params.set("crop", {
124
+ center: "center",
125
+ top: "top",
126
+ bottom: "bottom",
127
+ left: "left",
128
+ right: "right",
129
+ "left top": "top,left",
130
+ "right top": "top,right",
131
+ "left bottom": "bottom,left",
132
+ "right bottom": "bottom,right"
133
+ }[mods.position] || "center");
134
+ if (mods.format) params.set("fm", mods.format);
135
+ if (mods.quality) params.set("q", String(mods.quality));
136
+ if (mods.blur) params.set("blur", String(Math.round(mods.blur * 20)));
137
+ if (mods.rotate) params.set("rot", String(mods.rotate));
138
+ if (mods.grayscale) params.set("sat", "-100");
139
+ const query = params.toString();
140
+ return { url: joinURL(baseURL, src) + (query ? `?${query}` : "") };
141
+ }
142
+ };
143
+ const builtinProviders = {
144
+ ipx: ipxProvider,
145
+ static: staticProvider,
146
+ cloudinary: cloudinaryProvider,
147
+ imgix: imgixProvider,
148
+ none: {
149
+ name: "none",
150
+ getImage(src) {
151
+ return { url: src };
152
+ }
153
+ }
154
+ };
155
+ const defaultScreens = {
156
+ xs: 320,
157
+ sm: 640,
158
+ md: 768,
159
+ lg: 1024,
160
+ xl: 1280,
161
+ xxl: 1536
162
+ };
163
+ function createImageContext(userOptions = {}) {
164
+ const options = {
165
+ provider: userOptions.provider || "ipx",
166
+ providers: {
167
+ ...builtinProviders,
168
+ ...userOptions.providers
169
+ },
170
+ presets: userOptions.presets || {},
171
+ screens: {
172
+ ...defaultScreens,
173
+ ...userOptions.screens
174
+ },
175
+ densities: userOptions.densities || [1, 2],
176
+ format: userOptions.format || [
177
+ "webp",
178
+ "avif",
179
+ "jpeg"
180
+ ],
181
+ quality: userOptions.quality || 80,
182
+ placeholder: userOptions.quality ?? 10,
183
+ responsiveSizes: userOptions.responsiveSizes || [
184
+ 320,
185
+ 640,
186
+ 768,
187
+ 1024,
188
+ 1280
189
+ ],
190
+ domains: userOptions.domains || [],
191
+ alias: userOptions.alias || {},
192
+ dir: userOptions.dir || "",
193
+ ipx: {
194
+ baseURL: "/_ipx",
195
+ modifiers: {},
196
+ ...userOptions.ipx
197
+ },
198
+ static: {
199
+ baseURL: "/_image",
200
+ modifiers: {},
201
+ dir: "",
202
+ ...userOptions.static
203
+ },
204
+ cloudinary: {
205
+ baseURL: "",
206
+ modifiers: {},
207
+ ...userOptions.cloudinary
208
+ },
209
+ imgix: {
210
+ baseURL: "",
211
+ modifiers: {},
212
+ ...userOptions.imgix
213
+ },
214
+ twicpics: {
215
+ baseURL: "",
216
+ modifiers: {}
217
+ },
218
+ fastly: {
219
+ baseURL: "",
220
+ modifiers: {}
221
+ },
222
+ vercel: {
223
+ baseURL: "/_vercel/image",
224
+ modifiers: {}
225
+ },
226
+ netlify: {
227
+ baseURL: "/.netlify/images",
228
+ modifiers: {}
229
+ },
230
+ imagekit: {
231
+ baseURL: "",
232
+ modifiers: {}
233
+ },
234
+ uploadcare: {
235
+ baseURL: "",
236
+ modifiers: {}
237
+ },
238
+ preload: true,
239
+ intersectOptions: { rootMargin: "200px" }
240
+ };
241
+ const providers = {};
242
+ for (const [name, provider] of Object.entries(options.providers)) providers[name] = {
243
+ name,
244
+ getImage: provider.getImage || builtinProviders[name]?.getImage || ((src) => ({ url: src })),
245
+ validateDomains: provider.validateDomains ?? builtinProviders[name]?.validateDomains,
246
+ supportsAlias: provider.supportsAlias ?? builtinProviders[name]?.supportsAlias
247
+ };
248
+ return {
249
+ options,
250
+ providers,
251
+ presets: options.presets
252
+ };
253
+ }
254
+ function getProvider(name, ctx) {
255
+ return ctx.providers[name] || ctx.providers[ctx.options.provider] || builtinProviders.none;
256
+ }
257
+ function resolvePreset(preset, ctx) {
258
+ if (!preset) return {};
259
+ return ctx.presets[preset] || {};
260
+ }
261
+ function resolveImage$1(source, overrides = {}, ctx) {
262
+ const input = typeof source === "string" ? {
263
+ src: source,
264
+ ...overrides
265
+ } : {
266
+ ...source,
267
+ ...overrides
268
+ };
269
+ if (input.preset) {
270
+ const preset = resolvePreset(input.preset, ctx);
271
+ Object.assign(input, preset, input);
272
+ }
273
+ let { src } = input;
274
+ const provider = getProvider(input.provider || ctx.options.provider, ctx);
275
+ src = resolveAlias(src, ctx.options.alias);
276
+ if (isDataUrl(src)) return { url: src };
277
+ if (isRemoteUrl(src)) {
278
+ if (!validateDomain(src, ctx.options.domains)) console.warn(`[ubean-image] Domain not allowed: ${new URL(src).hostname}`);
279
+ }
280
+ const modifiers = {
281
+ quality: input.quality ?? ctx.options.quality,
282
+ width: input.width,
283
+ height: input.height,
284
+ fit: input.fit,
285
+ position: input.position,
286
+ format: input.format,
287
+ background: input.background,
288
+ blur: input.blur,
289
+ sharpen: input.sharpen,
290
+ rotate: input.rotate,
291
+ flip: input.flip,
292
+ trim: input.trim,
293
+ enlarge: input.enlarge,
294
+ grayscale: input.grayscale,
295
+ negate: input.negate,
296
+ brightness: input.brightness,
297
+ contrast: input.contrast,
298
+ saturation: input.saturation
299
+ };
300
+ return {
301
+ ...provider.getImage(src, modifiers, ctx),
302
+ width: modifiers.width,
303
+ height: modifiers.height,
304
+ format: modifiers.format
305
+ };
306
+ }
307
+ function createSrcSet(src, sizes, modifiers, ctx, formats = []) {
308
+ const items = [];
309
+ const targetFormats = formats.length > 0 ? formats : [modifiers.format || detectFormat(src) || "jpeg"];
310
+ for (const format of targetFormats) for (const width of sizes) {
311
+ if (modifiers.width && width > modifiers.width) continue;
312
+ const resolved = resolveImage$1(src, {
313
+ ...modifiers,
314
+ width,
315
+ format
316
+ }, ctx);
317
+ items.push({
318
+ url: resolved.url,
319
+ width,
320
+ format
321
+ });
322
+ }
323
+ return items;
324
+ }
325
+ function createDensitySrcSet(src, densities, modifiers, ctx, formats = []) {
326
+ const items = [];
327
+ const targetFormats = formats.length > 0 ? formats : [modifiers.format || detectFormat(src) || "jpeg"];
328
+ const baseWidth = modifiers.width || 0;
329
+ for (const format of targetFormats) for (const density of densities) {
330
+ const width = baseWidth ? Math.round(baseWidth * density) : void 0;
331
+ const resolved = resolveImage$1(src, {
332
+ ...modifiers,
333
+ width,
334
+ format
335
+ }, ctx);
336
+ items.push({
337
+ url: resolved.url,
338
+ density,
339
+ format
340
+ });
341
+ }
342
+ return items;
343
+ }
344
+ function srcSetToString(items) {
345
+ return items.map((item) => {
346
+ if (item.width) return `${item.url} ${item.width}w`;
347
+ if (item.density) return `${item.url} ${item.density}x`;
348
+ return item.url;
349
+ }).join(", ");
350
+ }
351
+ function getPlaceholder(src, modifiers, ctx, size = 10) {
352
+ return resolveImage$1(src, {
353
+ ...modifiers,
354
+ width: size,
355
+ quality: 30,
356
+ format: "webp",
357
+ blur: 3
358
+ }, ctx).url;
359
+ }
360
+ function buildImgAttributes(src, options, ctx) {
361
+ const attrs = {
362
+ src: resolveImage$1(src, options, ctx).url,
363
+ alt: options.alt || "",
364
+ loading: options.loading || "lazy",
365
+ decoding: "async"
366
+ };
367
+ if (options.title) attrs.title = options.title;
368
+ if (options.crossorigin) attrs.crossorigin = options.crossorigin;
369
+ if (options.referrerpolicy) attrs.referrerpolicy = options.referrerpolicy;
370
+ if (options.sizes) attrs.sizes = options.sizes;
371
+ if (options.width) attrs.width = options.width;
372
+ if (options.height) attrs.height = options.height;
373
+ return attrs;
374
+ }
375
+ function createImageHash(url, modifiers) {
376
+ return hash({
377
+ url,
378
+ modifiers
379
+ }).slice(0, 10);
380
+ }
381
+ //#endregion
382
+ //#region src/runtime.ts
383
+ let imageCTX = null;
384
+ function configureImageRuntime(options = {}) {
385
+ imageCTX = createImageContext(options);
386
+ return imageCTX;
387
+ }
388
+ function getImageContext() {
389
+ if (!imageCTX) imageCTX = createImageContext();
390
+ return imageCTX;
391
+ }
392
+ function resolveImage(source, overrides = {}) {
393
+ return resolveImage$1(source, overrides, getImageContext());
394
+ }
395
+ function defineImagePreset(name, options) {
396
+ const ctx = getImageContext();
397
+ ctx.presets[name] = options;
398
+ }
399
+ function useImage() {
400
+ const ctx = getImageContext();
401
+ return {
402
+ resolveImage: (src, options) => resolveImage$1(src, options, ctx),
403
+ getImage: (src, mods) => resolveImage$1(src, mods || {}, ctx),
404
+ srcset: (src, sizes, mods, formats) => createSrcSet(src, sizes, mods || {}, ctx, formats),
405
+ densitySrcset: (src, densities, mods, formats) => createDensitySrcSet(src, densities, mods || {}, ctx, formats),
406
+ srcsetToString: srcSetToString,
407
+ getPlaceholder: (src, mods, size) => getPlaceholder(src, mods || {}, ctx, size),
408
+ getImgAttributes: (src, options) => buildImgAttributes(src, options, ctx),
409
+ detectFormat,
410
+ isRemote: isRemoteUrl,
411
+ isDataUrl,
412
+ validateDomain: (src) => validateDomain(src, ctx.options.domains),
413
+ resolveAlias: (src) => resolveAlias(src, ctx.options.alias)
414
+ };
415
+ }
416
+ //#endregion
417
+ export { resolveAlias as C, staticProvider as D, srcSetToString as E, validateDomain as O, isRemoteUrl as S, resolvePreset as T, getPlaceholder as _, useImage as a, ipxProvider as b, cloudinaryProvider as c, createImageContext as d, createImageHash as f, detectFormat as g, defaultScreens as h, resolveImage as i, createDensitySrcSet as l, createStaticUrl as m, defineImagePreset as n, buildImgAttributes as o, createSrcSet as p, getImageContext as r, builtinProviders as s, configureImageRuntime as t, createIPXUrl as u, getProvider as v, resolveImage$1 as w, isDataUrl as x, imgixProvider as y };
@@ -0,0 +1,47 @@
1
+ import { a as ImageModifiers, c as ImageProvider, d as ResolvedImage, i as ImageFormat, n as ImageCTX, o as ImageOptions, t as CreateImageOptions, u as ImageSrcsetItem } from "./types-DosomQo8.js";
2
+ //#region src/core.d.ts
3
+ declare function detectFormat(src: string): ImageFormat | undefined;
4
+ declare function isRemoteUrl(src: string): boolean;
5
+ declare function isDataUrl(src: string): boolean;
6
+ declare function resolveAlias(src: string, alias: Record<string, string>): string;
7
+ declare function validateDomain(src: string, domains: string[]): boolean;
8
+ declare function createIPXUrl(baseURL: string, src: string, modifiers?: ImageModifiers, defaultModifiers?: ImageModifiers): string;
9
+ declare function createStaticUrl(baseURL: string, src: string, modifiers?: ImageModifiers, defaultModifiers?: ImageModifiers, dir?: string): string;
10
+ declare const ipxProvider: ImageProvider;
11
+ declare const staticProvider: ImageProvider;
12
+ declare const cloudinaryProvider: ImageProvider;
13
+ declare const imgixProvider: ImageProvider;
14
+ declare const builtinProviders: Record<string, ImageProvider>;
15
+ declare const defaultScreens: Record<string, number>;
16
+ declare function createImageContext(userOptions?: CreateImageOptions): ImageCTX;
17
+ declare function getProvider(name: string, ctx: ImageCTX): ImageProvider;
18
+ declare function resolvePreset(preset: string | undefined, ctx: ImageCTX): Partial<ImageOptions>;
19
+ declare function resolveImage$1(source: string | ImageOptions, overrides: Partial<ImageOptions> | undefined, ctx: ImageCTX): ResolvedImage;
20
+ declare function createSrcSet(src: string, sizes: number[], modifiers: ImageModifiers, ctx: ImageCTX, formats?: ImageFormat[]): ImageSrcsetItem[];
21
+ declare function createDensitySrcSet(src: string, densities: number[], modifiers: ImageModifiers, ctx: ImageCTX, formats?: ImageFormat[]): ImageSrcsetItem[];
22
+ declare function srcSetToString(items: ImageSrcsetItem[]): string;
23
+ declare function getPlaceholder(src: string, modifiers: ImageModifiers, ctx: ImageCTX, size?: number): string | null;
24
+ declare function buildImgAttributes(src: string, options: ImageOptions, ctx: ImageCTX): Record<string, any>;
25
+ declare function createImageHash(url: string, modifiers?: ImageModifiers): string;
26
+ //#endregion
27
+ //#region src/runtime.d.ts
28
+ declare function configureImageRuntime(options?: CreateImageOptions): ImageCTX;
29
+ declare function getImageContext(): ImageCTX;
30
+ declare function resolveImage(source: string | ImageOptions, overrides?: Partial<ImageOptions>): ResolvedImage;
31
+ declare function defineImagePreset(name: string, options: Partial<ImageOptions>): void;
32
+ declare function useImage(): {
33
+ resolveImage: (src: string | ImageOptions, options?: Partial<ImageOptions>) => ResolvedImage;
34
+ getImage: (src: string, mods?: ImageModifiers) => ResolvedImage;
35
+ srcset: (src: string, sizes: number[], mods?: ImageModifiers, formats?: any[]) => ImageSrcsetItem[];
36
+ densitySrcset: (src: string, densities: number[], mods?: ImageModifiers, formats?: any[]) => ImageSrcsetItem[];
37
+ srcsetToString: typeof srcSetToString;
38
+ getPlaceholder: (src: string, mods?: ImageModifiers, size?: number) => string | null;
39
+ getImgAttributes: (src: string, options: ImageOptions) => Record<string, any>;
40
+ detectFormat: typeof detectFormat;
41
+ isRemote: typeof isRemoteUrl;
42
+ isDataUrl: typeof isDataUrl;
43
+ validateDomain: (src: string) => boolean;
44
+ resolveAlias: (src: string) => string;
45
+ };
46
+ //#endregion
47
+ export { resolveAlias as C, staticProvider as D, srcSetToString as E, validateDomain as O, isRemoteUrl as S, resolvePreset as T, getPlaceholder as _, useImage as a, ipxProvider as b, cloudinaryProvider as c, createImageContext as d, createImageHash as f, detectFormat as g, defaultScreens as h, resolveImage as i, createDensitySrcSet as l, createStaticUrl as m, defineImagePreset as n, buildImgAttributes as o, createSrcSet as p, getImageContext as r, builtinProviders as s, configureImageRuntime as t, createIPXUrl as u, getProvider as v, resolveImage$1 as w, isDataUrl as x, imgixProvider as y };
@@ -0,0 +1,3 @@
1
+ import { a as ImageModifiers, d as ResolvedImage, n as ImageCTX, o as ImageOptions, t as CreateImageOptions, u as ImageSrcsetItem } from "./types-DosomQo8.js";
2
+ import { C as resolveAlias, E as srcSetToString, O as validateDomain, S as isRemoteUrl, T as resolvePreset, _ as getPlaceholder, a as useImage, d as createImageContext, g as detectFormat, i as resolveImage$1, l as createDensitySrcSet, n as defineImagePreset, o as buildImgAttributes, p as createSrcSet, r as getImageContext, t as configureImageRuntime, v as getProvider, w as resolveImage, x as isDataUrl } from "./runtime-B5AxhRTR.js";
3
+ export { type CreateImageOptions, type ImageCTX, type ImageModifiers, type ImageOptions, type ImageSrcsetItem, type ResolvedImage, resolveImage as baseResolveImage, buildImgAttributes, configureImageRuntime, createDensitySrcSet, createImageContext, createSrcSet, defineImagePreset, detectFormat, getImageContext, getPlaceholder, getProvider, isDataUrl, isRemoteUrl, resolveAlias, resolveImage$1 as resolveImage, resolvePreset, srcSetToString, useImage, validateDomain };
@@ -0,0 +1,2 @@
1
+ import { C as resolveAlias, E as srcSetToString, O as validateDomain, S as isRemoteUrl, T as resolvePreset, _ as getPlaceholder, a as useImage, d as createImageContext, g as detectFormat, i as resolveImage$1, l as createDensitySrcSet, n as defineImagePreset, o as buildImgAttributes, p as createSrcSet, r as getImageContext, t as configureImageRuntime, v as getProvider, w as resolveImage, x as isDataUrl } from "./runtime-3aSOG0e9.js";
2
+ export { resolveImage as baseResolveImage, buildImgAttributes, configureImageRuntime, createDensitySrcSet, createImageContext, createSrcSet, defineImagePreset, detectFormat, getImageContext, getPlaceholder, getProvider, isDataUrl, isRemoteUrl, resolveAlias, resolveImage$1 as resolveImage, resolvePreset, srcSetToString, useImage, validateDomain };
@@ -0,0 +1,155 @@
1
+ //#region src/types.d.ts
2
+ type ImageFormat = 'webp' | 'avif' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg';
3
+ type ImageFit = 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
4
+ type ImagePosition = 'top' | 'right top' | 'right' | 'right bottom' | 'bottom' | 'left bottom' | 'left' | 'left top' | 'center';
5
+ interface ImageModifiers {
6
+ width?: number;
7
+ height?: number;
8
+ size?: string;
9
+ fit?: ImageFit;
10
+ position?: ImagePosition;
11
+ format?: ImageFormat;
12
+ quality?: number;
13
+ background?: string;
14
+ blur?: number;
15
+ sharpen?: number;
16
+ rotate?: number;
17
+ flip?: 'h' | 'v' | 'hv';
18
+ trim?: boolean | number;
19
+ enlarge?: boolean;
20
+ grayscale?: boolean;
21
+ negate?: boolean;
22
+ brightness?: number;
23
+ contrast?: number;
24
+ saturation?: number;
25
+ }
26
+ interface ImageOptions extends ImageModifiers {
27
+ src: string;
28
+ alt?: string;
29
+ title?: string;
30
+ loading?: 'lazy' | 'eager';
31
+ crossorigin?: 'anonymous' | 'use-credentials' | '';
32
+ referrerpolicy?: string;
33
+ placeholder?: string;
34
+ sizes?: string;
35
+ srcset?: string;
36
+ preset?: string;
37
+ provider?: string;
38
+ densities?: string;
39
+ }
40
+ interface ImageSize {
41
+ width?: number;
42
+ height?: number;
43
+ media?: string;
44
+ breakpoint?: number;
45
+ format?: ImageFormat;
46
+ }
47
+ interface ProviderGetImage {
48
+ (src: string, options?: ImageModifiers, ctx?: ImageCTX): ResolvedImage;
49
+ }
50
+ interface ResolvedImage {
51
+ url: string;
52
+ format?: ImageFormat;
53
+ width?: number;
54
+ height?: number;
55
+ sizes?: string;
56
+ srcset?: ImageSrcsetItem[];
57
+ }
58
+ interface ImageSrcsetItem {
59
+ url: string;
60
+ width?: number;
61
+ density?: number;
62
+ format?: ImageFormat;
63
+ }
64
+ interface ImageProvider {
65
+ name: string;
66
+ getImage: ProviderGetImage;
67
+ validateDomains?: boolean;
68
+ supportsAlias?: boolean;
69
+ }
70
+ interface ImageCTX {
71
+ options: Required<ImageModuleOptions>;
72
+ providers: Record<string, ImageProvider>;
73
+ presets: Record<string, Partial<ImageOptions>>;
74
+ }
75
+ interface ImageModuleOptions {
76
+ provider: string;
77
+ providers: Record<string, Partial<ImageProvider> & {
78
+ options?: any;
79
+ }>;
80
+ presets: Record<string, Partial<ImageOptions>>;
81
+ screens: Record<string, number>;
82
+ densities: number[];
83
+ format: ImageFormat[];
84
+ quality: number;
85
+ placeholder: number | false;
86
+ responsiveSizes: number[];
87
+ domains: string[];
88
+ alias: Record<string, string>;
89
+ dir: string;
90
+ ipx: {
91
+ baseURL: string;
92
+ modifiers?: Partial<ImageModifiers>;
93
+ };
94
+ static: {
95
+ baseURL: string;
96
+ modifiers?: Partial<ImageModifiers>;
97
+ dir?: string;
98
+ };
99
+ cloudinary?: {
100
+ baseURL: string;
101
+ modifiers?: Partial<ImageModifiers>;
102
+ };
103
+ imgix?: {
104
+ baseURL: string;
105
+ modifiers?: Partial<ImageModifiers>;
106
+ };
107
+ twicpics?: {
108
+ baseURL: string;
109
+ modifiers?: Partial<ImageModifiers>;
110
+ };
111
+ fastly?: {
112
+ baseURL: string;
113
+ modifiers?: Partial<ImageModifiers>;
114
+ };
115
+ vercel?: {
116
+ baseURL: string;
117
+ modifiers?: Partial<ImageModifiers>;
118
+ };
119
+ netlify?: {
120
+ baseURL: string;
121
+ modifiers?: Partial<ImageModifiers>;
122
+ };
123
+ imagekit?: {
124
+ baseURL: string;
125
+ modifiers?: Partial<ImageModifiers>;
126
+ };
127
+ uploadcare?: {
128
+ baseURL: string;
129
+ modifiers?: Partial<ImageModifiers>;
130
+ };
131
+ preload: boolean;
132
+ intersectOptions: IntersectionObserverInit;
133
+ }
134
+ interface CreateImageOptions {
135
+ providers?: Record<string, ImageProvider | Partial<ImageProvider>>;
136
+ presets?: Record<string, Partial<ImageOptions>>;
137
+ screens?: Record<string, number>;
138
+ densities?: number[];
139
+ format?: ImageFormat[];
140
+ quality?: number;
141
+ placeholder?: number | false;
142
+ responsiveSizes?: number[];
143
+ domains?: string[];
144
+ alias?: Record<string, string>;
145
+ provider?: string;
146
+ dir?: string;
147
+ ipx?: Partial<ImageModuleOptions['ipx']>;
148
+ static?: Partial<ImageModuleOptions['static']>;
149
+ cloudinary?: Partial<ImageModuleOptions['cloudinary']>;
150
+ imgix?: Partial<ImageModuleOptions['imgix']>;
151
+ preload?: boolean;
152
+ intersectOptions?: IntersectionObserverInit;
153
+ }
154
+ //#endregion
155
+ export { ImageModifiers as a, ImageProvider as c, ResolvedImage as d, ImageFormat as i, ImageSize as l, ImageCTX as n, ImageOptions as o, ImageFit as r, ImagePosition as s, CreateImageOptions as t, ImageSrcsetItem as u };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { t as CreateImageOptions } from "./types-DosomQo8.js";
2
+ import { Plugin } from "vite";
3
+ //#region src/vite.d.ts
4
+ interface UbeanImageOptions extends CreateImageOptions {
5
+ injectScript?: boolean;
6
+ staticDir?: string;
7
+ ipxMiddleware?: boolean;
8
+ devtools?: boolean;
9
+ }
10
+ declare function ubeanImagePlugin(userOptions?: UbeanImageOptions): Plugin;
11
+ //#endregion
12
+ export { UbeanImageOptions, ubeanImagePlugin as default, ubeanImagePlugin };