@lonik/oh-image 2.0.4 → 2.0.6

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ImgHTMLAttributes } from "react";
2
- import * as react_jsx_runtime3 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/react/types.d.ts
5
5
  interface ImageLoaderOptions {
@@ -13,8 +13,10 @@ type ImageSrcType = string | ImageSrc;
13
13
  interface ImageProps extends Partial<Pick<ImgHTMLAttributes<HTMLImageElement>, "fetchPriority" | "decoding" | "loading" | "srcSet" | "className" | "sizes" | "style">> {
14
14
  /** Alternative text for the image, required for accessibility. Use an empty string for decorative images. */
15
15
  alt: string;
16
- /** Configures the Image component to load the image immediately. */
16
+ /** @deprecated Use `priority` instead. */
17
17
  asap?: boolean;
18
+ /** Configures the Image component to load the image immediately. */
19
+ priority?: boolean;
18
20
  /** */
19
21
  src: ImageSrcType;
20
22
  /** The URL of the placeholder image to display while loading. */
@@ -31,7 +33,7 @@ interface ImageProps extends Partial<Pick<ImgHTMLAttributes<HTMLImageElement>, "
31
33
  }
32
34
  //#endregion
33
35
  //#region src/react/image.d.ts
34
- declare function Image(props: ImageProps): react_jsx_runtime3.JSX.Element;
36
+ declare function Image(props: ImageProps): react_jsx_runtime0.JSX.Element;
35
37
  //#endregion
36
38
  //#region src/react/use-img-loaded.d.ts
37
39
  /**
@@ -73,7 +75,7 @@ declare function ImageProvider({
73
75
  ...props
74
76
  }: {
75
77
  children: React.ReactNode;
76
- } & Partial<ImageContextValue>): react_jsx_runtime3.JSX.Element;
78
+ } & Partial<ImageContextValue>): react_jsx_runtime0.JSX.Element;
77
79
  //#endregion
78
80
  //#region src/react/loaders/imgproxy-loader.d.ts
79
81
  interface ImgproxyLoaderOptions {
@@ -91,7 +93,7 @@ declare function ImgproxyLoaderProvider({
91
93
  ...props
92
94
  }: {
93
95
  children: React.ReactNode;
94
- } & Partial<ImgproxyLoaderOptions>): react_jsx_runtime3.JSX.Element;
96
+ } & Partial<ImgproxyLoaderOptions>): react_jsx_runtime0.JSX.Element;
95
97
  declare function useImgproxyLoader(options?: Partial<ImgproxyLoaderOptions>): ImageLoader;
96
98
  //#endregion
97
99
  //#region src/react/loaders/cloudflare-loader.d.ts
@@ -109,7 +111,7 @@ declare function CloudflareLoaderProvider({
109
111
  ...props
110
112
  }: {
111
113
  children: React.ReactNode;
112
- } & Partial<CloudflareLoaderOptions>): react_jsx_runtime3.JSX.Element;
114
+ } & Partial<CloudflareLoaderOptions>): react_jsx_runtime0.JSX.Element;
113
115
  declare function useCloudflareLoader(options?: Partial<CloudflareLoaderOptions>): ImageLoader;
114
116
  //#endregion
115
117
  //#region src/react/loaders/cloudinary-loader.d.ts
@@ -127,7 +129,7 @@ declare function CloudinaryLoaderProvider({
127
129
  ...props
128
130
  }: {
129
131
  children: React.ReactNode;
130
- } & Partial<CloudinaryLoaderOptions>): react_jsx_runtime3.JSX.Element;
132
+ } & Partial<CloudinaryLoaderOptions>): react_jsx_runtime0.JSX.Element;
131
133
  declare function useCloudinaryLoader(options?: Partial<CloudinaryLoaderOptions>): ImageLoader;
132
134
  //#endregion
133
135
  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
@@ -102,10 +102,10 @@ function resolveOptions(prop, defaultOptions) {
102
102
  return resolved;
103
103
  }
104
104
  function resolveDecoding(prop) {
105
- return prop.asap ? "async" : prop.decoding;
105
+ return prop.priority || prop.asap ? "async" : prop.decoding;
106
106
  }
107
107
  function resolveFetchPriority(prop) {
108
- if (prop.asap) return "high";
108
+ if (prop.priority || prop.asap) return "high";
109
109
  return prop.fetchPriority ?? "auto";
110
110
  }
111
111
  function resolveSrcSet(prop) {
@@ -124,8 +124,9 @@ function resolveSrcSet(prop) {
124
124
  return entries.join(", ");
125
125
  }
126
126
  function resolveLoading(prop) {
127
- if (!prop.asap && prop.loading !== void 0) return prop.loading;
128
- return prop.asap ? "eager" : "lazy";
127
+ const priority = prop.priority || prop.asap;
128
+ if (!priority && prop.loading !== void 0) return prop.loading;
129
+ return priority ? "eager" : "lazy";
129
130
  }
130
131
  function resolveSizes(prop, resolvedSrcSet, resolvedLoading) {
131
132
  const loading = resolvedLoading ?? resolveLoading(prop);
@@ -169,6 +170,7 @@ function resolvePlaceholderURL(prop) {
169
170
  //#region src/react/prop-asserts.ts
170
171
  function assertProps(prop) {
171
172
  try {
173
+ if (prop.asap !== void 0) console.warn("The `asap` prop is deprecated and will be removed in a future version. Please use `priority` instead.");
172
174
  assertLoadingProp(prop);
173
175
  assertDecodingProp(prop);
174
176
  assertFetchPriorityProp(prop);
@@ -181,28 +183,26 @@ function assertProps(prop) {
181
183
  }
182
184
  }
183
185
  function assert(assertion, message) {
184
- if (import.meta.env.DEV) {
185
- if (assertion()) throw new Error(message || void 0);
186
- }
186
+ if (assertion()) throw new Error(message || void 0);
187
187
  }
188
188
  function assertLoadingProp(prop) {
189
- assert(() => prop.loading && prop.asap, import.meta.env.DEV && `Do not use \`loading\` on a asap image — asap images are always eagerly loaded.`);
189
+ assert(() => prop.loading && (prop.priority || prop.asap), `Do not use \`loading\` on a priority image — priority images are always eagerly loaded.`);
190
190
  }
191
191
  function assertDecodingProp(prop) {
192
- assert(() => prop.decoding && prop.asap, import.meta.env.DEV && `Do not use \`decoding\` on a asap image — asap images always use async decoding.`);
192
+ assert(() => prop.decoding && (prop.priority || prop.asap), `Do not use \`decoding\` on a priority image — priority images always use async decoding.`);
193
193
  }
194
194
  function assertFetchPriorityProp(prop) {
195
- assert(() => prop.fetchPriority && prop.asap, import.meta.env.DEV && `Do not use \`fetchPriority\` on a asap image — asap images always use high fetch priority.`);
195
+ assert(() => prop.fetchPriority && (prop.priority || prop.asap), `Do not use \`fetchPriority\` on a priority image — priority images always use high fetch priority.`);
196
196
  }
197
197
  function assertBreakpointsProp(prop) {
198
- assert(() => prop.breakpoints && typeof prop.src === "object", import.meta.env.DEV && `Do not use \`breakpoints\` when \`src\` is an imported image — the image's built-in srcSets are used instead.`);
199
- assert(() => prop.breakpoints && typeof prop.src === "string" && !prop.loader, import.meta.env.DEV && `Do not use \`breakpoints\` without a \`loader\` — breakpoints require a loader to generate srcSet entries.`);
198
+ assert(() => prop.breakpoints && typeof prop.src === "object", `Do not use \`breakpoints\` when \`src\` is an imported image — the image's built-in srcSets are used instead.`);
199
+ assert(() => prop.breakpoints && typeof prop.src === "string" && !prop.loader, `Do not use \`breakpoints\` without a \`loader\` — breakpoints require a loader to generate srcSet entries.`);
200
200
  }
201
201
  function assertFillProp(prop) {
202
- assert(() => prop.fill && (prop.width !== void 0 || prop.height !== void 0), import.meta.env.DEV && `Do not use \`width\` or \`height\` with \`fill\` — fill mode makes the image fill its container.`);
202
+ assert(() => prop.fill && (prop.width !== void 0 || prop.height !== void 0), `Do not use \`width\` or \`height\` with \`fill\` — fill mode makes the image fill its container.`);
203
203
  }
204
204
  function assertDimensionsProp(prop) {
205
- assert(() => typeof prop.src === "string" && !prop.fill && prop.width === void 0 && prop.height === void 0, import.meta.env.DEV && `Image is missing \`width\` and \`height\` props. Either provide dimensions, use \`fill\`, or use an imported image source.`);
205
+ assert(() => typeof prop.src === "string" && !prop.fill && prop.width === void 0 && prop.height === void 0, `Image is missing \`width\` and \`height\` props. Either provide dimensions, use \`fill\`, or use an imported image source.`);
206
206
  }
207
207
 
208
208
  //#endregion
@@ -340,7 +340,7 @@ function useImgproxyLoader(options) {
340
340
  const parts = [];
341
341
  const format = resolvedOptions.format;
342
342
  const paramsSeparator = resolvedOptions.paramsSeparator ?? "/";
343
- if (format) parts.push(`format:${format}`);
343
+ if (format) parts.push(`f:${format}`);
344
344
  if (imageOptions.width) parts.push(`width:${imageOptions.width}`);
345
345
  if (imageOptions.height) parts.push(`height:${imageOptions.height}`);
346
346
  if (imageOptions.isPlaceholder) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lonik/oh-image",
3
3
  "type": "module",
4
- "version": "2.0.4",
4
+ "version": "2.0.6",
5
5
  "description": "A React component library for optimized image handling.",
6
6
  "author": "Luka Onikadze <lukonik@gmail.com>",
7
7
  "license": "MIT",