@lonik/oh-image 2.0.1 → 2.0.2
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.
- package/dist/react.d.ts +40 -26
- package/dist/react.js +73 -28
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImgHTMLAttributes } from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime2 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/react/types.d.ts
|
|
5
5
|
interface ImageLoaderOptions {
|
|
@@ -31,7 +31,7 @@ interface ImageProps extends Partial<Pick<ImgHTMLAttributes<HTMLImageElement>, "
|
|
|
31
31
|
}
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/react/image.d.ts
|
|
34
|
-
declare function Image(props: ImageProps):
|
|
34
|
+
declare function Image(props: ImageProps): react_jsx_runtime2.JSX.Element;
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/react/use-img-loaded.d.ts
|
|
37
37
|
/**
|
|
@@ -62,58 +62,72 @@ declare function Image(props: ImageProps): react_jsx_runtime0.JSX.Element;
|
|
|
62
62
|
*/
|
|
63
63
|
declare function useImgLoaded(src: string | undefined): [(img: HTMLImageElement | null) => void, boolean];
|
|
64
64
|
//#endregion
|
|
65
|
-
//#region src/react/
|
|
66
|
-
interface
|
|
65
|
+
//#region src/react/image-context.d.ts
|
|
66
|
+
interface ImageContextValue extends Pick<ImageProps, "loading"> {
|
|
67
|
+
breakpoints: number[];
|
|
68
|
+
loader: ImageLoader | null;
|
|
69
|
+
}
|
|
70
|
+
declare function useImageContext(): ImageContextValue;
|
|
71
|
+
declare function ImageProvider({
|
|
72
|
+
children,
|
|
73
|
+
...props
|
|
74
|
+
}: {
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
} & Partial<ImageContextValue>): react_jsx_runtime2.JSX.Element;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/react/loaders/imgproxy-loader.d.ts
|
|
79
|
+
interface ImgproxyLoaderOptions {
|
|
67
80
|
path: string;
|
|
68
81
|
placeholder: boolean;
|
|
69
82
|
format: string;
|
|
70
83
|
params?: Record<string, string>;
|
|
71
84
|
placeholderParams?: Record<string, string>;
|
|
72
85
|
breakpoints?: number[];
|
|
86
|
+
paramsSeparator?: string;
|
|
73
87
|
}
|
|
74
|
-
declare function
|
|
75
|
-
declare function
|
|
88
|
+
declare function useImgproxyContext(): ImgproxyLoaderOptions;
|
|
89
|
+
declare function ImgproxyLoaderProvider({
|
|
76
90
|
children,
|
|
77
91
|
...props
|
|
78
92
|
}: {
|
|
79
93
|
children: React.ReactNode;
|
|
80
|
-
} & Partial<
|
|
94
|
+
} & Partial<ImgproxyLoaderOptions>): react_jsx_runtime2.JSX.Element;
|
|
95
|
+
declare function useImgproxyLoader(options?: Partial<ImgproxyLoaderOptions>): ImageLoader;
|
|
81
96
|
//#endregion
|
|
82
97
|
//#region src/react/loaders/cloudflare-loader.d.ts
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/react/loaders/imgproxy-context.d.ts
|
|
86
|
-
interface ImgproxyLoaderOptions {
|
|
98
|
+
interface CloudflareLoaderOptions {
|
|
87
99
|
path: string;
|
|
88
100
|
placeholder: boolean;
|
|
89
101
|
format: string;
|
|
90
102
|
params?: Record<string, string>;
|
|
91
103
|
placeholderParams?: Record<string, string>;
|
|
92
104
|
breakpoints?: number[];
|
|
93
|
-
paramsSeparator?: string;
|
|
94
105
|
}
|
|
95
|
-
declare function
|
|
96
|
-
declare function
|
|
106
|
+
declare function useCloudflareContext(): CloudflareLoaderOptions;
|
|
107
|
+
declare function CloudflareLoaderProvider({
|
|
97
108
|
children,
|
|
98
109
|
...props
|
|
99
110
|
}: {
|
|
100
111
|
children: React.ReactNode;
|
|
101
|
-
} & Partial<
|
|
102
|
-
|
|
103
|
-
//#region src/react/loaders/imgproxy-loader.d.ts
|
|
104
|
-
declare function useImgproxyLoader(options?: Partial<ImgproxyLoaderOptions>): ImageLoader;
|
|
112
|
+
} & Partial<CloudflareLoaderOptions>): react_jsx_runtime2.JSX.Element;
|
|
113
|
+
declare function useCloudflareLoader(options?: Partial<CloudflareLoaderOptions>): ImageLoader;
|
|
105
114
|
//#endregion
|
|
106
|
-
//#region src/react/
|
|
107
|
-
interface
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
//#region src/react/loaders/cloudinary-loader.d.ts
|
|
116
|
+
interface CloudinaryLoaderOptions {
|
|
117
|
+
path: string;
|
|
118
|
+
placeholder: boolean;
|
|
119
|
+
format: string;
|
|
120
|
+
params?: Record<string, string>;
|
|
121
|
+
placeholderParams?: Record<string, string>;
|
|
122
|
+
breakpoints?: number[];
|
|
110
123
|
}
|
|
111
|
-
declare function
|
|
112
|
-
declare function
|
|
124
|
+
declare function useCloudinaryContext(): CloudinaryLoaderOptions;
|
|
125
|
+
declare function CloudinaryLoaderProvider({
|
|
113
126
|
children,
|
|
114
127
|
...props
|
|
115
128
|
}: {
|
|
116
129
|
children: React.ReactNode;
|
|
117
|
-
} & Partial<
|
|
130
|
+
} & Partial<CloudinaryLoaderOptions>): react_jsx_runtime2.JSX.Element;
|
|
131
|
+
declare function useCloudinaryLoader(options?: Partial<CloudinaryLoaderOptions>): ImageLoader;
|
|
118
132
|
//#endregion
|
|
119
|
-
export { type CloudflareLoaderOptions, CloudflareLoaderProvider, Image, type ImageLoader, type ImageLoaderOptions, type ImageProps, ImageProvider, type ImageSrcType, type ImgproxyLoaderOptions, ImgproxyLoaderProvider, useCloudflareContext, useCloudflareLoader, useImageContext, useImgLoaded, useImgproxyContext, useImgproxyLoader };
|
|
133
|
+
export { type CloudflareLoaderOptions, CloudflareLoaderProvider, type CloudinaryLoaderOptions, CloudinaryLoaderProvider, Image, type ImageLoader, type ImageLoaderOptions, type ImageProps, ImageProvider, type ImageSrcType, type ImgproxyLoaderOptions, ImgproxyLoaderProvider, useCloudflareContext, useCloudflareLoader, useCloudinaryContext, useCloudinaryLoader, useImageContext, useImgLoaded, useImgproxyContext, useImgproxyLoader };
|
package/dist/react.js
CHANGED
|
@@ -310,7 +310,55 @@ function assertPath(path) {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
//#endregion
|
|
313
|
-
//#region src/react/loaders/
|
|
313
|
+
//#region src/react/loaders/imgproxy-loader.tsx
|
|
314
|
+
const ImgproxyContext = createContext({
|
|
315
|
+
path: "",
|
|
316
|
+
placeholder: true,
|
|
317
|
+
format: "webp",
|
|
318
|
+
placeholderParams: { quality: "1" }
|
|
319
|
+
});
|
|
320
|
+
function useImgproxyContext() {
|
|
321
|
+
return useContext(ImgproxyContext);
|
|
322
|
+
}
|
|
323
|
+
function ImgproxyLoaderProvider({ children, ...props }) {
|
|
324
|
+
const ctx = useImgproxyContext();
|
|
325
|
+
return /* @__PURE__ */ jsx(ImgproxyContext.Provider, {
|
|
326
|
+
value: {
|
|
327
|
+
...ctx,
|
|
328
|
+
...props
|
|
329
|
+
},
|
|
330
|
+
children
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function useImgproxyLoader(options) {
|
|
334
|
+
const resolvedOptions = {
|
|
335
|
+
...useImgproxyContext(),
|
|
336
|
+
...options
|
|
337
|
+
};
|
|
338
|
+
assertPath(resolvedOptions.path);
|
|
339
|
+
return (imageOptions) => {
|
|
340
|
+
const parts = [];
|
|
341
|
+
const format = resolvedOptions.format;
|
|
342
|
+
const paramsSeparator = resolvedOptions.paramsSeparator ?? "/";
|
|
343
|
+
if (format) parts.push(`format:${format}`);
|
|
344
|
+
if (imageOptions.width) parts.push(`width:${imageOptions.width}`);
|
|
345
|
+
if (imageOptions.height) parts.push(`height:${imageOptions.height}`);
|
|
346
|
+
if (imageOptions.isPlaceholder) {
|
|
347
|
+
if (resolvedOptions.placeholderParams) {
|
|
348
|
+
const placeholderParams = normalizeLoaderParams(resolvedOptions.placeholderParams, ":");
|
|
349
|
+
parts.push(...placeholderParams);
|
|
350
|
+
}
|
|
351
|
+
} else if (resolvedOptions.params) {
|
|
352
|
+
const params = normalizeLoaderParams(resolvedOptions.params, ":");
|
|
353
|
+
parts.push(...params);
|
|
354
|
+
}
|
|
355
|
+
const processingOptions = parts.join(paramsSeparator);
|
|
356
|
+
return `${resolvedOptions.path}/${processingOptions}/plain/${imageOptions.src}`;
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/react/loaders/cloudflare-loader.tsx
|
|
314
362
|
const CloudflareContext = createContext({
|
|
315
363
|
path: "",
|
|
316
364
|
placeholder: true,
|
|
@@ -330,9 +378,6 @@ function CloudflareLoaderProvider({ children, ...props }) {
|
|
|
330
378
|
children
|
|
331
379
|
});
|
|
332
380
|
}
|
|
333
|
-
|
|
334
|
-
//#endregion
|
|
335
|
-
//#region src/react/loaders/cloudflare-loader.ts
|
|
336
381
|
function useCloudflareLoader(options) {
|
|
337
382
|
const resolvedOptions = {
|
|
338
383
|
...useCloudflareContext(),
|
|
@@ -361,19 +406,22 @@ function useCloudflareLoader(options) {
|
|
|
361
406
|
}
|
|
362
407
|
|
|
363
408
|
//#endregion
|
|
364
|
-
//#region src/react/loaders/
|
|
365
|
-
const
|
|
409
|
+
//#region src/react/loaders/cloudinary-loader.tsx
|
|
410
|
+
const CloudinaryContext = createContext({
|
|
366
411
|
path: "",
|
|
367
412
|
placeholder: true,
|
|
368
|
-
format: "
|
|
369
|
-
placeholderParams: {
|
|
413
|
+
format: "auto",
|
|
414
|
+
placeholderParams: {
|
|
415
|
+
e_blur: ":1000",
|
|
416
|
+
q: "_1"
|
|
417
|
+
}
|
|
370
418
|
});
|
|
371
|
-
function
|
|
372
|
-
return useContext(
|
|
419
|
+
function useCloudinaryContext() {
|
|
420
|
+
return useContext(CloudinaryContext);
|
|
373
421
|
}
|
|
374
|
-
function
|
|
375
|
-
const ctx =
|
|
376
|
-
return /* @__PURE__ */ jsx(
|
|
422
|
+
function CloudinaryLoaderProvider({ children, ...props }) {
|
|
423
|
+
const ctx = useCloudinaryContext();
|
|
424
|
+
return /* @__PURE__ */ jsx(CloudinaryContext.Provider, {
|
|
377
425
|
value: {
|
|
378
426
|
...ctx,
|
|
379
427
|
...props
|
|
@@ -381,35 +429,32 @@ function ImgproxyLoaderProvider({ children, ...props }) {
|
|
|
381
429
|
children
|
|
382
430
|
});
|
|
383
431
|
}
|
|
384
|
-
|
|
385
|
-
//#endregion
|
|
386
|
-
//#region src/react/loaders/imgproxy-loader.ts
|
|
387
|
-
function useImgproxyLoader(options) {
|
|
432
|
+
function useCloudinaryLoader(options) {
|
|
388
433
|
const resolvedOptions = {
|
|
389
|
-
...
|
|
434
|
+
...useCloudinaryContext(),
|
|
390
435
|
...options
|
|
391
436
|
};
|
|
392
437
|
assertPath(resolvedOptions.path);
|
|
393
438
|
return (imageOptions) => {
|
|
394
439
|
const parts = [];
|
|
395
|
-
const format = resolvedOptions.format
|
|
396
|
-
|
|
397
|
-
if (
|
|
398
|
-
if (imageOptions.
|
|
399
|
-
if (imageOptions.height) parts.push(`height:${imageOptions.height}`);
|
|
440
|
+
const format = `f_${resolvedOptions.format}`;
|
|
441
|
+
parts.push(`${format}`);
|
|
442
|
+
if (imageOptions.width) parts.push(`w_${imageOptions.width}`);
|
|
443
|
+
if (imageOptions.height) parts.push(`h_${imageOptions.height}`);
|
|
400
444
|
if (imageOptions.isPlaceholder) {
|
|
401
445
|
if (resolvedOptions.placeholderParams) {
|
|
402
|
-
const placeholderParams = normalizeLoaderParams(resolvedOptions.placeholderParams, "
|
|
446
|
+
const placeholderParams = normalizeLoaderParams(resolvedOptions.placeholderParams, "");
|
|
403
447
|
parts.push(...placeholderParams);
|
|
404
448
|
}
|
|
405
449
|
} else if (resolvedOptions.params) {
|
|
406
|
-
const params = normalizeLoaderParams(resolvedOptions.params, "
|
|
450
|
+
const params = normalizeLoaderParams(resolvedOptions.params, "");
|
|
407
451
|
parts.push(...params);
|
|
408
452
|
}
|
|
409
|
-
|
|
410
|
-
|
|
453
|
+
let src = imageOptions.src;
|
|
454
|
+
if (src.startsWith("/")) src = src.slice(1);
|
|
455
|
+
return `${resolvedOptions.path.endsWith("/") ? resolvedOptions.path.slice(0, -1) : resolvedOptions.path}/image/upload/${parts.join(",")}/${src}`;
|
|
411
456
|
};
|
|
412
457
|
}
|
|
413
458
|
|
|
414
459
|
//#endregion
|
|
415
|
-
export { CloudflareLoaderProvider, Image, ImageProvider, ImgproxyLoaderProvider, useCloudflareContext, useCloudflareLoader, useImageContext, useImgLoaded, useImgproxyContext, useImgproxyLoader };
|
|
460
|
+
export { CloudflareLoaderProvider, CloudinaryLoaderProvider, Image, ImageProvider, ImgproxyLoaderProvider, useCloudflareContext, useCloudflareLoader, useCloudinaryContext, useCloudinaryLoader, useImageContext, useImgLoaded, useImgproxyContext, useImgproxyLoader };
|
package/package.json
CHANGED