@lonik/oh-image 1.0.1 → 1.0.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,6 @@
1
+ import type { ImageSrc } from "@lonik/oh-image/plugin";
2
+
3
+ declare module "*?oh" {
4
+ const imageSrc: ImageSrc;
5
+ export default imageSrc;
6
+ }
@@ -0,0 +1,84 @@
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
+ /**
43
+ * Represents a single entry in the srcSet array.
44
+ * Used for responsive image loading at different viewport widths.
45
+ */
46
+ interface ImageSrcSet {
47
+ /** Width descriptor (e.g., '640w', '1080w') */
48
+ width: string;
49
+ /** URL or path to the image at this breakpoint */
50
+ src: string;
51
+ }
52
+ /**
53
+ * The processed image source object returned by the plugin.
54
+ * Contains all URLs and metadata needed for responsive image rendering.
55
+ */
56
+ interface ImageSrc {
57
+ /** Original width of the source image in pixels */
58
+ width: number;
59
+ /** Original height of the source image in pixels */
60
+ height: number;
61
+ /** URL to the placeholder image (if placeholder was enabled) */
62
+ placeholderUrl?: string;
63
+ /** Array of responsive image sources at different breakpoints */
64
+ srcSets: ImageSrcSet[];
65
+ /** URL to the main processed image */
66
+ src: string;
67
+ }
68
+ //#endregion
69
+ //#region src/plugin/plugin.d.ts
70
+ declare function ohImage(options?: Partial<PluginConfig>): {
71
+ name: string;
72
+ configResolved(this: vite0.MinimalPluginContextWithoutEnvironment, viteConfig: vite0.ResolvedConfig): void;
73
+ enforce: "pre";
74
+ configureServer(this: vite0.MinimalPluginContextWithoutEnvironment, server: vite0.ViteDevServer): void;
75
+ load: {
76
+ filter: {
77
+ id: RegExp;
78
+ };
79
+ handler(this: rollup0.PluginContext, id: string): Promise<string | null>;
80
+ };
81
+ writeBundle(this: rollup0.PluginContext): Promise<void>;
82
+ };
83
+ //#endregion
84
+ export { type ImageOptions, type ImageSrc, type ImageSrcSet, type PluginConfig, 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.3",
5
5
  "description": "A React component library for optimized image handling.",
6
6
  "author": "Luka Onikadze <lukonik@gmail.com>",
7
7
  "license": "MIT",
@@ -22,6 +22,9 @@
22
22
  "./react": {
23
23
  "types": "./dist/react.d.ts",
24
24
  "default": "./dist/react.js"
25
+ },
26
+ "./client": {
27
+ "types": "./dist/client.d.ts"
25
28
  }
26
29
  },
27
30
  "files": [