@lonik/oh-image 1.0.1 → 1.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.
@@ -0,0 +1,58 @@
1
+ import { FormatEnum } from "sharp";
2
+ import * as vite0 from "vite";
3
+ import * as rollup0 from "rollup";
4
+
5
+ //#region src/plugin/types.d.ts
6
+ /**
7
+ * Configuration options for the oh-image Vite plugin.
8
+ * Extends ImageOptions with all properties required, plus plugin-specific settings.
9
+ */
10
+ interface PluginConfig extends Required<ImageOptions> {
11
+ /** Directory name where processed images will be output during build */
12
+ distDir: string;
13
+ }
14
+ /**
15
+ * Options for image processing and transformation.
16
+ * Can be passed via query parameters or plugin configuration.
17
+ */
18
+ interface ImageOptions {
19
+ /** Target width for the processed image in pixels */
20
+ width?: number | null;
21
+ /** Target height for the processed image in pixels */
22
+ height?: number | null;
23
+ /** Output format for the main image (e.g., 'webp', 'avif', 'png') */
24
+ format?: keyof FormatEnum | null;
25
+ /** Blur amount (true for default blur, or a number for sigma value) */
26
+ blur?: number | boolean;
27
+ /** Whether to generate a placeholder image for lazy loading */
28
+ placeholder?: boolean;
29
+ /** Width of the placeholder image in pixels */
30
+ placeholderW?: number;
31
+ /** Height of the placeholder image in pixels */
32
+ placeholderH?: number;
33
+ /** Output format for the placeholder image */
34
+ placeholderF?: keyof FormatEnum;
35
+ /** Blur setting for the placeholder (true for default, or sigma value) */
36
+ placeholderB: boolean | number;
37
+ /** Breakpoints array - widths in pixels for responsive srcSet generation */
38
+ bps?: number[];
39
+ /** Output format for srcSet images */
40
+ srcSetsF: keyof FormatEnum;
41
+ }
42
+ //#endregion
43
+ //#region src/plugin/plugin.d.ts
44
+ declare function ohImage(options?: Partial<PluginConfig>): {
45
+ name: string;
46
+ configResolved(this: vite0.MinimalPluginContextWithoutEnvironment, viteConfig: vite0.ResolvedConfig): void;
47
+ enforce: "pre";
48
+ configureServer(this: vite0.MinimalPluginContextWithoutEnvironment, server: vite0.ViteDevServer): void;
49
+ load: {
50
+ filter: {
51
+ id: RegExp;
52
+ };
53
+ handler(this: rollup0.PluginContext, id: string): Promise<string | null>;
54
+ };
55
+ writeBundle(this: rollup0.PluginContext): Promise<void>;
56
+ };
57
+ //#endregion
58
+ export { ohImage };
@@ -0,0 +1,55 @@
1
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import { CSSProperties } from "react";
3
+
4
+ //#region src/react/types.d.ts
5
+ /**
6
+ * Image source type - can be either a simple URL string or a full ImageSrc object
7
+ */
8
+ type ImageSrcType = string | ImageSrc;
9
+ /**
10
+ * Optimized image source with multiple responsive variants
11
+ */
12
+ interface ImageSrc {
13
+ /** Original image width in pixels */
14
+ width: number;
15
+ /** Original image height in pixels */
16
+ height: number;
17
+ /** Optional low-quality placeholder image URL for blur-up effect */
18
+ placeholderUrl?: string;
19
+ /** Array of responsive image variants for different screen sizes */
20
+ srcSets: ImageSrcSet[];
21
+ /** Primary image source URL */
22
+ src: string;
23
+ }
24
+ /**
25
+ * Single responsive image variant in a srcset
26
+ */
27
+ interface ImageSrcSet {
28
+ /** Width descriptor (e.g., "1920w") */
29
+ width: string;
30
+ /** Image URL for this variant */
31
+ src: string;
32
+ }
33
+ /**
34
+ * Props for the optimized Image component
35
+ * Extends standard HTML image attributes with optimization features
36
+ */
37
+ interface ImageProps extends Partial<Pick<HTMLImageElement, "alt" | "fetchPriority" | "decoding" | "loading" | "height" | "width" | "srcset" | "className" | "sizes">> {
38
+ /** Load the image immediately, bypassing lazy loading */
39
+ asap?: boolean;
40
+ /** Image source - either a URL string or ImageSrc object with responsive variants */
41
+ src: ImageSrcType;
42
+ /** Override placeholder URL (takes precedence over ImageSrc.placeholderUrl) */
43
+ placeholderUrl?: string | undefined;
44
+ /** Enable blur-up placeholder effect during image loading */
45
+ placeholder?: boolean;
46
+ /** Inline CSS styles */
47
+ style?: CSSProperties;
48
+ /** Make image fill its container (position: absolute) */
49
+ fill?: boolean;
50
+ }
51
+ //#endregion
52
+ //#region src/react/image.d.ts
53
+ declare function Image(props: ImageProps): react_jsx_runtime0.JSX.Element;
54
+ //#endregion
55
+ export { Image, type ImageProps, type ImageSrc, type ImageSrcSet };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lonik/oh-image",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "A React component library for optimized image handling.",
6
6
  "author": "Luka Onikadze <lukonik@gmail.com>",
7
7
  "license": "MIT",