@heroui/image 2.2.7 → 2.2.9

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,52 @@
1
+ "use client";
2
+ import {
3
+ useImage
4
+ } from "./chunk-Q3TXVV4U.mjs";
5
+
6
+ // src/image.tsx
7
+ import { cloneElement } from "react";
8
+ import { forwardRef } from "@heroui/system";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ var Image = forwardRef((props, ref) => {
11
+ const {
12
+ Component,
13
+ domRef,
14
+ slots,
15
+ classNames,
16
+ isBlurred,
17
+ isZoomed,
18
+ fallbackSrc,
19
+ removeWrapper,
20
+ disableSkeleton,
21
+ getImgProps,
22
+ getWrapperProps,
23
+ getBlurredImgProps
24
+ } = useImage({
25
+ ...props,
26
+ ref
27
+ });
28
+ const img = /* @__PURE__ */ jsx(Component, { ref: domRef, ...getImgProps() });
29
+ if (removeWrapper) {
30
+ return img;
31
+ }
32
+ const zoomed = /* @__PURE__ */ jsx("div", { className: slots.zoomedWrapper({ class: classNames == null ? void 0 : classNames.zoomedWrapper }), children: img });
33
+ if (isBlurred) {
34
+ return /* @__PURE__ */ jsxs("div", { ...getWrapperProps(), children: [
35
+ isZoomed ? zoomed : img,
36
+ cloneElement(img, getBlurredImgProps())
37
+ ] });
38
+ }
39
+ if (isZoomed || !disableSkeleton || fallbackSrc) {
40
+ return /* @__PURE__ */ jsxs("div", { ...getWrapperProps(), children: [
41
+ " ",
42
+ isZoomed ? zoomed : img
43
+ ] });
44
+ }
45
+ return img;
46
+ });
47
+ Image.displayName = "HeroUI.Image";
48
+ var image_default = Image;
49
+
50
+ export {
51
+ image_default
52
+ };
@@ -0,0 +1,126 @@
1
+ "use client";
2
+
3
+ // src/use-image.ts
4
+ import { useCallback } from "react";
5
+ import { mapPropsVariants, useProviderContext } from "@heroui/system";
6
+ import { image } from "@heroui/theme";
7
+ import { useDOMRef } from "@heroui/react-utils";
8
+ import { clsx, dataAttr, objectToDeps } from "@heroui/shared-utils";
9
+ import { useImage as useImageBase } from "@heroui/use-image";
10
+ import { useMemo } from "react";
11
+ function useImage(originalProps) {
12
+ var _a, _b;
13
+ const globalContext = useProviderContext();
14
+ const [props, variantProps] = mapPropsVariants(originalProps, image.variantKeys);
15
+ const {
16
+ ref,
17
+ as,
18
+ src,
19
+ className,
20
+ classNames,
21
+ loading,
22
+ isBlurred,
23
+ fallbackSrc,
24
+ isLoading: isLoadingProp,
25
+ disableSkeleton = !!fallbackSrc,
26
+ removeWrapper = false,
27
+ onError,
28
+ onLoad,
29
+ srcSet,
30
+ sizes,
31
+ crossOrigin,
32
+ ...otherProps
33
+ } = props;
34
+ const imageStatus = useImageBase({
35
+ src,
36
+ loading,
37
+ onError,
38
+ onLoad,
39
+ ignoreFallback: false,
40
+ srcSet,
41
+ sizes,
42
+ crossOrigin
43
+ });
44
+ const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
45
+ const isImgLoaded = imageStatus === "loaded" && !isLoadingProp;
46
+ const isLoading = imageStatus === "loading" || isLoadingProp;
47
+ const isZoomed = originalProps.isZoomed;
48
+ const Component = as || "img";
49
+ const domRef = useDOMRef(ref);
50
+ const { w, h } = useMemo(() => {
51
+ return {
52
+ w: props.width ? typeof props.width === "number" ? `${props.width}px` : props.width : "fit-content",
53
+ h: props.height ? typeof props.height === "number" ? `${props.height}px` : props.height : "auto"
54
+ };
55
+ }, [props == null ? void 0 : props.width, props == null ? void 0 : props.height]);
56
+ const showFallback = (!src || !isImgLoaded) && !!fallbackSrc;
57
+ const showSkeleton = isLoading && !disableSkeleton;
58
+ const slots = useMemo(
59
+ () => image({
60
+ ...variantProps,
61
+ disableAnimation,
62
+ showSkeleton
63
+ }),
64
+ [objectToDeps(variantProps), disableAnimation, showSkeleton]
65
+ );
66
+ const baseStyles = clsx(className, classNames == null ? void 0 : classNames.img);
67
+ const getImgProps = (props2 = {}) => {
68
+ const imgStyles = clsx(baseStyles, props2 == null ? void 0 : props2.className);
69
+ return {
70
+ src,
71
+ ref: domRef,
72
+ "data-loaded": dataAttr(isImgLoaded),
73
+ className: slots.img({ class: imgStyles }),
74
+ loading,
75
+ srcSet,
76
+ sizes,
77
+ crossOrigin,
78
+ ...otherProps,
79
+ style: {
80
+ // img has `height: auto` by default
81
+ // passing the custom height here to override if it is specified
82
+ ...(otherProps == null ? void 0 : otherProps.height) && { height: h },
83
+ ...props2.style,
84
+ ...otherProps.style
85
+ }
86
+ };
87
+ };
88
+ const getWrapperProps = useCallback(() => {
89
+ const fallbackStyle = showFallback ? {
90
+ backgroundImage: `url(${fallbackSrc})`
91
+ } : {};
92
+ return {
93
+ className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
94
+ style: {
95
+ ...fallbackStyle,
96
+ maxWidth: w
97
+ }
98
+ };
99
+ }, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
100
+ const getBlurredImgProps = useCallback(() => {
101
+ return {
102
+ src,
103
+ "aria-hidden": dataAttr(true),
104
+ className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
105
+ };
106
+ }, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
107
+ return {
108
+ Component,
109
+ domRef,
110
+ slots,
111
+ classNames,
112
+ isBlurred,
113
+ disableSkeleton,
114
+ fallbackSrc,
115
+ removeWrapper,
116
+ isZoomed,
117
+ isLoading,
118
+ getImgProps,
119
+ getWrapperProps,
120
+ getBlurredImgProps
121
+ };
122
+ }
123
+
124
+ export {
125
+ useImage
126
+ };
@@ -0,0 +1,12 @@
1
+ import * as _heroui_system from '@heroui/system';
2
+ import { UseImageProps } from './use-image.mjs';
3
+ import 'tailwind-variants';
4
+ import 'react';
5
+ import '@heroui/theme';
6
+ import '@heroui/react-utils';
7
+
8
+ interface ImageProps extends Omit<UseImageProps, "showSkeleton"> {
9
+ }
10
+ declare const Image: _heroui_system.InternalForwardRefRenderFunction<"img", ImageProps, never>;
11
+
12
+ export { type ImageProps, Image as default };
@@ -0,0 +1,12 @@
1
+ import * as _heroui_system from '@heroui/system';
2
+ import { UseImageProps } from './use-image.js';
3
+ import 'tailwind-variants';
4
+ import 'react';
5
+ import '@heroui/theme';
6
+ import '@heroui/react-utils';
7
+
8
+ interface ImageProps extends Omit<UseImageProps, "showSkeleton"> {
9
+ }
10
+ declare const Image: _heroui_system.InternalForwardRefRenderFunction<"img", ImageProps, never>;
11
+
12
+ export { type ImageProps, Image as default };
package/dist/image.js ADDED
@@ -0,0 +1,191 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/image.tsx
22
+ var image_exports = {};
23
+ __export(image_exports, {
24
+ default: () => image_default
25
+ });
26
+ module.exports = __toCommonJS(image_exports);
27
+ var import_react3 = require("react");
28
+ var import_system2 = require("@heroui/system");
29
+
30
+ // src/use-image.ts
31
+ var import_react = require("react");
32
+ var import_system = require("@heroui/system");
33
+ var import_theme = require("@heroui/theme");
34
+ var import_react_utils = require("@heroui/react-utils");
35
+ var import_shared_utils = require("@heroui/shared-utils");
36
+ var import_use_image = require("@heroui/use-image");
37
+ var import_react2 = require("react");
38
+ function useImage(originalProps) {
39
+ var _a, _b;
40
+ const globalContext = (0, import_system.useProviderContext)();
41
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.image.variantKeys);
42
+ const {
43
+ ref,
44
+ as,
45
+ src,
46
+ className,
47
+ classNames,
48
+ loading,
49
+ isBlurred,
50
+ fallbackSrc,
51
+ isLoading: isLoadingProp,
52
+ disableSkeleton = !!fallbackSrc,
53
+ removeWrapper = false,
54
+ onError,
55
+ onLoad,
56
+ srcSet,
57
+ sizes,
58
+ crossOrigin,
59
+ ...otherProps
60
+ } = props;
61
+ const imageStatus = (0, import_use_image.useImage)({
62
+ src,
63
+ loading,
64
+ onError,
65
+ onLoad,
66
+ ignoreFallback: false,
67
+ srcSet,
68
+ sizes,
69
+ crossOrigin
70
+ });
71
+ const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
72
+ const isImgLoaded = imageStatus === "loaded" && !isLoadingProp;
73
+ const isLoading = imageStatus === "loading" || isLoadingProp;
74
+ const isZoomed = originalProps.isZoomed;
75
+ const Component = as || "img";
76
+ const domRef = (0, import_react_utils.useDOMRef)(ref);
77
+ const { w, h } = (0, import_react2.useMemo)(() => {
78
+ return {
79
+ w: props.width ? typeof props.width === "number" ? `${props.width}px` : props.width : "fit-content",
80
+ h: props.height ? typeof props.height === "number" ? `${props.height}px` : props.height : "auto"
81
+ };
82
+ }, [props == null ? void 0 : props.width, props == null ? void 0 : props.height]);
83
+ const showFallback = (!src || !isImgLoaded) && !!fallbackSrc;
84
+ const showSkeleton = isLoading && !disableSkeleton;
85
+ const slots = (0, import_react2.useMemo)(
86
+ () => (0, import_theme.image)({
87
+ ...variantProps,
88
+ disableAnimation,
89
+ showSkeleton
90
+ }),
91
+ [(0, import_shared_utils.objectToDeps)(variantProps), disableAnimation, showSkeleton]
92
+ );
93
+ const baseStyles = (0, import_shared_utils.clsx)(className, classNames == null ? void 0 : classNames.img);
94
+ const getImgProps = (props2 = {}) => {
95
+ const imgStyles = (0, import_shared_utils.clsx)(baseStyles, props2 == null ? void 0 : props2.className);
96
+ return {
97
+ src,
98
+ ref: domRef,
99
+ "data-loaded": (0, import_shared_utils.dataAttr)(isImgLoaded),
100
+ className: slots.img({ class: imgStyles }),
101
+ loading,
102
+ srcSet,
103
+ sizes,
104
+ crossOrigin,
105
+ ...otherProps,
106
+ style: {
107
+ // img has `height: auto` by default
108
+ // passing the custom height here to override if it is specified
109
+ ...(otherProps == null ? void 0 : otherProps.height) && { height: h },
110
+ ...props2.style,
111
+ ...otherProps.style
112
+ }
113
+ };
114
+ };
115
+ const getWrapperProps = (0, import_react.useCallback)(() => {
116
+ const fallbackStyle = showFallback ? {
117
+ backgroundImage: `url(${fallbackSrc})`
118
+ } : {};
119
+ return {
120
+ className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
121
+ style: {
122
+ ...fallbackStyle,
123
+ maxWidth: w
124
+ }
125
+ };
126
+ }, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
127
+ const getBlurredImgProps = (0, import_react.useCallback)(() => {
128
+ return {
129
+ src,
130
+ "aria-hidden": (0, import_shared_utils.dataAttr)(true),
131
+ className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
132
+ };
133
+ }, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
134
+ return {
135
+ Component,
136
+ domRef,
137
+ slots,
138
+ classNames,
139
+ isBlurred,
140
+ disableSkeleton,
141
+ fallbackSrc,
142
+ removeWrapper,
143
+ isZoomed,
144
+ isLoading,
145
+ getImgProps,
146
+ getWrapperProps,
147
+ getBlurredImgProps
148
+ };
149
+ }
150
+
151
+ // src/image.tsx
152
+ var import_jsx_runtime = require("react/jsx-runtime");
153
+ var Image = (0, import_system2.forwardRef)((props, ref) => {
154
+ const {
155
+ Component,
156
+ domRef,
157
+ slots,
158
+ classNames,
159
+ isBlurred,
160
+ isZoomed,
161
+ fallbackSrc,
162
+ removeWrapper,
163
+ disableSkeleton,
164
+ getImgProps,
165
+ getWrapperProps,
166
+ getBlurredImgProps
167
+ } = useImage({
168
+ ...props,
169
+ ref
170
+ });
171
+ const img = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: domRef, ...getImgProps() });
172
+ if (removeWrapper) {
173
+ return img;
174
+ }
175
+ const zoomed = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: slots.zoomedWrapper({ class: classNames == null ? void 0 : classNames.zoomedWrapper }), children: img });
176
+ if (isBlurred) {
177
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
178
+ isZoomed ? zoomed : img,
179
+ (0, import_react3.cloneElement)(img, getBlurredImgProps())
180
+ ] });
181
+ }
182
+ if (isZoomed || !disableSkeleton || fallbackSrc) {
183
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
184
+ " ",
185
+ isZoomed ? zoomed : img
186
+ ] });
187
+ }
188
+ return img;
189
+ });
190
+ Image.displayName = "HeroUI.Image";
191
+ var image_default = Image;
package/dist/image.mjs ADDED
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import {
3
+ image_default
4
+ } from "./chunk-3TCFMHK3.mjs";
5
+ import "./chunk-Q3TXVV4U.mjs";
6
+ export {
7
+ image_default as default
8
+ };
@@ -0,0 +1,7 @@
1
+ export { default as Image, ImageProps } from './image.mjs';
2
+ export { useImage } from './use-image.mjs';
3
+ import '@heroui/system';
4
+ import 'tailwind-variants';
5
+ import 'react';
6
+ import '@heroui/theme';
7
+ import '@heroui/react-utils';
@@ -0,0 +1,7 @@
1
+ export { default as Image, ImageProps } from './image.js';
2
+ export { useImage } from './use-image.js';
3
+ import '@heroui/system';
4
+ import 'tailwind-variants';
5
+ import 'react';
6
+ import '@heroui/theme';
7
+ import '@heroui/react-utils';
package/dist/index.js ADDED
@@ -0,0 +1,199 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Image: () => image_default,
25
+ useImage: () => useImage
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/image.tsx
30
+ var import_react3 = require("react");
31
+ var import_system2 = require("@heroui/system");
32
+
33
+ // src/use-image.ts
34
+ var import_react = require("react");
35
+ var import_system = require("@heroui/system");
36
+ var import_theme = require("@heroui/theme");
37
+ var import_react_utils = require("@heroui/react-utils");
38
+ var import_shared_utils = require("@heroui/shared-utils");
39
+ var import_use_image = require("@heroui/use-image");
40
+ var import_react2 = require("react");
41
+ function useImage(originalProps) {
42
+ var _a, _b;
43
+ const globalContext = (0, import_system.useProviderContext)();
44
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.image.variantKeys);
45
+ const {
46
+ ref,
47
+ as,
48
+ src,
49
+ className,
50
+ classNames,
51
+ loading,
52
+ isBlurred,
53
+ fallbackSrc,
54
+ isLoading: isLoadingProp,
55
+ disableSkeleton = !!fallbackSrc,
56
+ removeWrapper = false,
57
+ onError,
58
+ onLoad,
59
+ srcSet,
60
+ sizes,
61
+ crossOrigin,
62
+ ...otherProps
63
+ } = props;
64
+ const imageStatus = (0, import_use_image.useImage)({
65
+ src,
66
+ loading,
67
+ onError,
68
+ onLoad,
69
+ ignoreFallback: false,
70
+ srcSet,
71
+ sizes,
72
+ crossOrigin
73
+ });
74
+ const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
75
+ const isImgLoaded = imageStatus === "loaded" && !isLoadingProp;
76
+ const isLoading = imageStatus === "loading" || isLoadingProp;
77
+ const isZoomed = originalProps.isZoomed;
78
+ const Component = as || "img";
79
+ const domRef = (0, import_react_utils.useDOMRef)(ref);
80
+ const { w, h } = (0, import_react2.useMemo)(() => {
81
+ return {
82
+ w: props.width ? typeof props.width === "number" ? `${props.width}px` : props.width : "fit-content",
83
+ h: props.height ? typeof props.height === "number" ? `${props.height}px` : props.height : "auto"
84
+ };
85
+ }, [props == null ? void 0 : props.width, props == null ? void 0 : props.height]);
86
+ const showFallback = (!src || !isImgLoaded) && !!fallbackSrc;
87
+ const showSkeleton = isLoading && !disableSkeleton;
88
+ const slots = (0, import_react2.useMemo)(
89
+ () => (0, import_theme.image)({
90
+ ...variantProps,
91
+ disableAnimation,
92
+ showSkeleton
93
+ }),
94
+ [(0, import_shared_utils.objectToDeps)(variantProps), disableAnimation, showSkeleton]
95
+ );
96
+ const baseStyles = (0, import_shared_utils.clsx)(className, classNames == null ? void 0 : classNames.img);
97
+ const getImgProps = (props2 = {}) => {
98
+ const imgStyles = (0, import_shared_utils.clsx)(baseStyles, props2 == null ? void 0 : props2.className);
99
+ return {
100
+ src,
101
+ ref: domRef,
102
+ "data-loaded": (0, import_shared_utils.dataAttr)(isImgLoaded),
103
+ className: slots.img({ class: imgStyles }),
104
+ loading,
105
+ srcSet,
106
+ sizes,
107
+ crossOrigin,
108
+ ...otherProps,
109
+ style: {
110
+ // img has `height: auto` by default
111
+ // passing the custom height here to override if it is specified
112
+ ...(otherProps == null ? void 0 : otherProps.height) && { height: h },
113
+ ...props2.style,
114
+ ...otherProps.style
115
+ }
116
+ };
117
+ };
118
+ const getWrapperProps = (0, import_react.useCallback)(() => {
119
+ const fallbackStyle = showFallback ? {
120
+ backgroundImage: `url(${fallbackSrc})`
121
+ } : {};
122
+ return {
123
+ className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
124
+ style: {
125
+ ...fallbackStyle,
126
+ maxWidth: w
127
+ }
128
+ };
129
+ }, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
130
+ const getBlurredImgProps = (0, import_react.useCallback)(() => {
131
+ return {
132
+ src,
133
+ "aria-hidden": (0, import_shared_utils.dataAttr)(true),
134
+ className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
135
+ };
136
+ }, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
137
+ return {
138
+ Component,
139
+ domRef,
140
+ slots,
141
+ classNames,
142
+ isBlurred,
143
+ disableSkeleton,
144
+ fallbackSrc,
145
+ removeWrapper,
146
+ isZoomed,
147
+ isLoading,
148
+ getImgProps,
149
+ getWrapperProps,
150
+ getBlurredImgProps
151
+ };
152
+ }
153
+
154
+ // src/image.tsx
155
+ var import_jsx_runtime = require("react/jsx-runtime");
156
+ var Image = (0, import_system2.forwardRef)((props, ref) => {
157
+ const {
158
+ Component,
159
+ domRef,
160
+ slots,
161
+ classNames,
162
+ isBlurred,
163
+ isZoomed,
164
+ fallbackSrc,
165
+ removeWrapper,
166
+ disableSkeleton,
167
+ getImgProps,
168
+ getWrapperProps,
169
+ getBlurredImgProps
170
+ } = useImage({
171
+ ...props,
172
+ ref
173
+ });
174
+ const img = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: domRef, ...getImgProps() });
175
+ if (removeWrapper) {
176
+ return img;
177
+ }
178
+ const zoomed = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: slots.zoomedWrapper({ class: classNames == null ? void 0 : classNames.zoomedWrapper }), children: img });
179
+ if (isBlurred) {
180
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
181
+ isZoomed ? zoomed : img,
182
+ (0, import_react3.cloneElement)(img, getBlurredImgProps())
183
+ ] });
184
+ }
185
+ if (isZoomed || !disableSkeleton || fallbackSrc) {
186
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
187
+ " ",
188
+ isZoomed ? zoomed : img
189
+ ] });
190
+ }
191
+ return img;
192
+ });
193
+ Image.displayName = "HeroUI.Image";
194
+ var image_default = Image;
195
+ // Annotate the CommonJS export names for ESM import in node:
196
+ 0 && (module.exports = {
197
+ Image,
198
+ useImage
199
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import {
3
+ image_default
4
+ } from "./chunk-3TCFMHK3.mjs";
5
+ import {
6
+ useImage
7
+ } from "./chunk-Q3TXVV4U.mjs";
8
+ export {
9
+ image_default as Image,
10
+ useImage
11
+ };
@@ -0,0 +1,142 @@
1
+ import * as tailwind_variants from 'tailwind-variants';
2
+ import * as react from 'react';
3
+ import { ImgHTMLAttributes } from 'react';
4
+ import * as _heroui_system from '@heroui/system';
5
+ import { PropGetter, HTMLHeroUIProps } from '@heroui/system';
6
+ import { ImageVariantProps, SlotsToClasses, ImageSlots } from '@heroui/theme';
7
+ import { ReactRef } from '@heroui/react-utils';
8
+
9
+ type NativeImageProps = ImgHTMLAttributes<HTMLImageElement>;
10
+ interface Props extends HTMLHeroUIProps<"img"> {
11
+ /**
12
+ * Ref to the DOM node.
13
+ */
14
+ ref?: ReactRef<HTMLImageElement | null>;
15
+ /**
16
+ * Whether to add a blurred effect to the image.
17
+ * @default false
18
+ */
19
+ isBlurred?: boolean;
20
+ /**
21
+ * A fallback image.
22
+ */
23
+ fallbackSrc?: React.ReactNode;
24
+ /**
25
+ * Whether to disable the loading skeleton.
26
+ * @default false
27
+ */
28
+ disableSkeleton?: boolean;
29
+ /**
30
+ * A callback for when the image `src` has been loaded
31
+ */
32
+ onLoad?: NativeImageProps["onLoad"];
33
+ /**
34
+ * A loading strategy to use for the image.
35
+ */
36
+ loading?: NativeImageProps["loading"];
37
+ /**
38
+ * Whether to remove the wrapper element. This will cause the image to be rendered as a direct child of the parent element.
39
+ * If you set this prop as `true` neither the skeleton nor the zoom effect will work.
40
+ * @default false
41
+ */
42
+ removeWrapper?: boolean;
43
+ /**
44
+ * Controlled loading state.
45
+ */
46
+ isLoading?: boolean;
47
+ /**
48
+ * Function called when image failed to load
49
+ */
50
+ onError?: () => void;
51
+ /**
52
+ * Classname or List of classes to change the classNames of the element.
53
+ * if `className` is passed, it will be added to the base slot.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * <Image classNames={{
58
+ * base:"base-classes", // image classes
59
+ * wrapper: "wrapper-classes",
60
+ * blurredImg: "blurredImg-classes", // this is a cloned version of the img
61
+ * }} />
62
+ * ```
63
+ */
64
+ classNames?: SlotsToClasses<ImageSlots>;
65
+ }
66
+ type UseImageProps = Props & ImageVariantProps;
67
+ declare function useImage(originalProps: UseImageProps): {
68
+ Component: _heroui_system.As<any>;
69
+ domRef: react.RefObject<HTMLImageElement>;
70
+ slots: {
71
+ wrapper: (slotProps?: ({
72
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
73
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
74
+ isZoomed?: boolean | undefined;
75
+ showSkeleton?: boolean | undefined;
76
+ disableAnimation?: boolean | undefined;
77
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
78
+ zoomedWrapper: (slotProps?: ({
79
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
80
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
81
+ isZoomed?: boolean | undefined;
82
+ showSkeleton?: boolean | undefined;
83
+ disableAnimation?: boolean | undefined;
84
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
85
+ img: (slotProps?: ({
86
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
87
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
88
+ isZoomed?: boolean | undefined;
89
+ showSkeleton?: boolean | undefined;
90
+ disableAnimation?: boolean | undefined;
91
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
92
+ blurredImg: (slotProps?: ({
93
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
94
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
95
+ isZoomed?: boolean | undefined;
96
+ showSkeleton?: boolean | undefined;
97
+ disableAnimation?: boolean | undefined;
98
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
99
+ } & {
100
+ wrapper: (slotProps?: ({
101
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
102
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
103
+ isZoomed?: boolean | undefined;
104
+ showSkeleton?: boolean | undefined;
105
+ disableAnimation?: boolean | undefined;
106
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
107
+ zoomedWrapper: (slotProps?: ({
108
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
109
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
110
+ isZoomed?: boolean | undefined;
111
+ showSkeleton?: boolean | undefined;
112
+ disableAnimation?: boolean | undefined;
113
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
114
+ img: (slotProps?: ({
115
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
116
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
117
+ isZoomed?: boolean | undefined;
118
+ showSkeleton?: boolean | undefined;
119
+ disableAnimation?: boolean | undefined;
120
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
121
+ blurredImg: (slotProps?: ({
122
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
123
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
124
+ isZoomed?: boolean | undefined;
125
+ showSkeleton?: boolean | undefined;
126
+ disableAnimation?: boolean | undefined;
127
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
128
+ } & {};
129
+ classNames: SlotsToClasses<"img" | "wrapper" | "zoomedWrapper" | "blurredImg"> | undefined;
130
+ isBlurred: boolean | undefined;
131
+ disableSkeleton: boolean;
132
+ fallbackSrc: react.ReactNode;
133
+ removeWrapper: boolean;
134
+ isZoomed: boolean | undefined;
135
+ isLoading: boolean | undefined;
136
+ getImgProps: PropGetter;
137
+ getWrapperProps: PropGetter;
138
+ getBlurredImgProps: PropGetter;
139
+ };
140
+ type UseImageReturn = ReturnType<typeof useImage>;
141
+
142
+ export { type UseImageProps, type UseImageReturn, useImage };
@@ -0,0 +1,142 @@
1
+ import * as tailwind_variants from 'tailwind-variants';
2
+ import * as react from 'react';
3
+ import { ImgHTMLAttributes } from 'react';
4
+ import * as _heroui_system from '@heroui/system';
5
+ import { PropGetter, HTMLHeroUIProps } from '@heroui/system';
6
+ import { ImageVariantProps, SlotsToClasses, ImageSlots } from '@heroui/theme';
7
+ import { ReactRef } from '@heroui/react-utils';
8
+
9
+ type NativeImageProps = ImgHTMLAttributes<HTMLImageElement>;
10
+ interface Props extends HTMLHeroUIProps<"img"> {
11
+ /**
12
+ * Ref to the DOM node.
13
+ */
14
+ ref?: ReactRef<HTMLImageElement | null>;
15
+ /**
16
+ * Whether to add a blurred effect to the image.
17
+ * @default false
18
+ */
19
+ isBlurred?: boolean;
20
+ /**
21
+ * A fallback image.
22
+ */
23
+ fallbackSrc?: React.ReactNode;
24
+ /**
25
+ * Whether to disable the loading skeleton.
26
+ * @default false
27
+ */
28
+ disableSkeleton?: boolean;
29
+ /**
30
+ * A callback for when the image `src` has been loaded
31
+ */
32
+ onLoad?: NativeImageProps["onLoad"];
33
+ /**
34
+ * A loading strategy to use for the image.
35
+ */
36
+ loading?: NativeImageProps["loading"];
37
+ /**
38
+ * Whether to remove the wrapper element. This will cause the image to be rendered as a direct child of the parent element.
39
+ * If you set this prop as `true` neither the skeleton nor the zoom effect will work.
40
+ * @default false
41
+ */
42
+ removeWrapper?: boolean;
43
+ /**
44
+ * Controlled loading state.
45
+ */
46
+ isLoading?: boolean;
47
+ /**
48
+ * Function called when image failed to load
49
+ */
50
+ onError?: () => void;
51
+ /**
52
+ * Classname or List of classes to change the classNames of the element.
53
+ * if `className` is passed, it will be added to the base slot.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * <Image classNames={{
58
+ * base:"base-classes", // image classes
59
+ * wrapper: "wrapper-classes",
60
+ * blurredImg: "blurredImg-classes", // this is a cloned version of the img
61
+ * }} />
62
+ * ```
63
+ */
64
+ classNames?: SlotsToClasses<ImageSlots>;
65
+ }
66
+ type UseImageProps = Props & ImageVariantProps;
67
+ declare function useImage(originalProps: UseImageProps): {
68
+ Component: _heroui_system.As<any>;
69
+ domRef: react.RefObject<HTMLImageElement>;
70
+ slots: {
71
+ wrapper: (slotProps?: ({
72
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
73
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
74
+ isZoomed?: boolean | undefined;
75
+ showSkeleton?: boolean | undefined;
76
+ disableAnimation?: boolean | undefined;
77
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
78
+ zoomedWrapper: (slotProps?: ({
79
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
80
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
81
+ isZoomed?: boolean | undefined;
82
+ showSkeleton?: boolean | undefined;
83
+ disableAnimation?: boolean | undefined;
84
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
85
+ img: (slotProps?: ({
86
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
87
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
88
+ isZoomed?: boolean | undefined;
89
+ showSkeleton?: boolean | undefined;
90
+ disableAnimation?: boolean | undefined;
91
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
92
+ blurredImg: (slotProps?: ({
93
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
94
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
95
+ isZoomed?: boolean | undefined;
96
+ showSkeleton?: boolean | undefined;
97
+ disableAnimation?: boolean | undefined;
98
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
99
+ } & {
100
+ wrapper: (slotProps?: ({
101
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
102
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
103
+ isZoomed?: boolean | undefined;
104
+ showSkeleton?: boolean | undefined;
105
+ disableAnimation?: boolean | undefined;
106
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
107
+ zoomedWrapper: (slotProps?: ({
108
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
109
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
110
+ isZoomed?: boolean | undefined;
111
+ showSkeleton?: boolean | undefined;
112
+ disableAnimation?: boolean | undefined;
113
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
114
+ img: (slotProps?: ({
115
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
116
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
117
+ isZoomed?: boolean | undefined;
118
+ showSkeleton?: boolean | undefined;
119
+ disableAnimation?: boolean | undefined;
120
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
121
+ blurredImg: (slotProps?: ({
122
+ radius?: "lg" | "none" | "full" | "sm" | "md" | undefined;
123
+ shadow?: "lg" | "none" | "sm" | "md" | undefined;
124
+ isZoomed?: boolean | undefined;
125
+ showSkeleton?: boolean | undefined;
126
+ disableAnimation?: boolean | undefined;
127
+ } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
128
+ } & {};
129
+ classNames: SlotsToClasses<"img" | "wrapper" | "zoomedWrapper" | "blurredImg"> | undefined;
130
+ isBlurred: boolean | undefined;
131
+ disableSkeleton: boolean;
132
+ fallbackSrc: react.ReactNode;
133
+ removeWrapper: boolean;
134
+ isZoomed: boolean | undefined;
135
+ isLoading: boolean | undefined;
136
+ getImgProps: PropGetter;
137
+ getWrapperProps: PropGetter;
138
+ getBlurredImgProps: PropGetter;
139
+ };
140
+ type UseImageReturn = ReturnType<typeof useImage>;
141
+
142
+ export { type UseImageProps, type UseImageReturn, useImage };
@@ -0,0 +1,149 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-image.ts
22
+ var use_image_exports = {};
23
+ __export(use_image_exports, {
24
+ useImage: () => useImage
25
+ });
26
+ module.exports = __toCommonJS(use_image_exports);
27
+ var import_react = require("react");
28
+ var import_system = require("@heroui/system");
29
+ var import_theme = require("@heroui/theme");
30
+ var import_react_utils = require("@heroui/react-utils");
31
+ var import_shared_utils = require("@heroui/shared-utils");
32
+ var import_use_image = require("@heroui/use-image");
33
+ var import_react2 = require("react");
34
+ function useImage(originalProps) {
35
+ var _a, _b;
36
+ const globalContext = (0, import_system.useProviderContext)();
37
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.image.variantKeys);
38
+ const {
39
+ ref,
40
+ as,
41
+ src,
42
+ className,
43
+ classNames,
44
+ loading,
45
+ isBlurred,
46
+ fallbackSrc,
47
+ isLoading: isLoadingProp,
48
+ disableSkeleton = !!fallbackSrc,
49
+ removeWrapper = false,
50
+ onError,
51
+ onLoad,
52
+ srcSet,
53
+ sizes,
54
+ crossOrigin,
55
+ ...otherProps
56
+ } = props;
57
+ const imageStatus = (0, import_use_image.useImage)({
58
+ src,
59
+ loading,
60
+ onError,
61
+ onLoad,
62
+ ignoreFallback: false,
63
+ srcSet,
64
+ sizes,
65
+ crossOrigin
66
+ });
67
+ const disableAnimation = (_b = (_a = originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
68
+ const isImgLoaded = imageStatus === "loaded" && !isLoadingProp;
69
+ const isLoading = imageStatus === "loading" || isLoadingProp;
70
+ const isZoomed = originalProps.isZoomed;
71
+ const Component = as || "img";
72
+ const domRef = (0, import_react_utils.useDOMRef)(ref);
73
+ const { w, h } = (0, import_react2.useMemo)(() => {
74
+ return {
75
+ w: props.width ? typeof props.width === "number" ? `${props.width}px` : props.width : "fit-content",
76
+ h: props.height ? typeof props.height === "number" ? `${props.height}px` : props.height : "auto"
77
+ };
78
+ }, [props == null ? void 0 : props.width, props == null ? void 0 : props.height]);
79
+ const showFallback = (!src || !isImgLoaded) && !!fallbackSrc;
80
+ const showSkeleton = isLoading && !disableSkeleton;
81
+ const slots = (0, import_react2.useMemo)(
82
+ () => (0, import_theme.image)({
83
+ ...variantProps,
84
+ disableAnimation,
85
+ showSkeleton
86
+ }),
87
+ [(0, import_shared_utils.objectToDeps)(variantProps), disableAnimation, showSkeleton]
88
+ );
89
+ const baseStyles = (0, import_shared_utils.clsx)(className, classNames == null ? void 0 : classNames.img);
90
+ const getImgProps = (props2 = {}) => {
91
+ const imgStyles = (0, import_shared_utils.clsx)(baseStyles, props2 == null ? void 0 : props2.className);
92
+ return {
93
+ src,
94
+ ref: domRef,
95
+ "data-loaded": (0, import_shared_utils.dataAttr)(isImgLoaded),
96
+ className: slots.img({ class: imgStyles }),
97
+ loading,
98
+ srcSet,
99
+ sizes,
100
+ crossOrigin,
101
+ ...otherProps,
102
+ style: {
103
+ // img has `height: auto` by default
104
+ // passing the custom height here to override if it is specified
105
+ ...(otherProps == null ? void 0 : otherProps.height) && { height: h },
106
+ ...props2.style,
107
+ ...otherProps.style
108
+ }
109
+ };
110
+ };
111
+ const getWrapperProps = (0, import_react.useCallback)(() => {
112
+ const fallbackStyle = showFallback ? {
113
+ backgroundImage: `url(${fallbackSrc})`
114
+ } : {};
115
+ return {
116
+ className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
117
+ style: {
118
+ ...fallbackStyle,
119
+ maxWidth: w
120
+ }
121
+ };
122
+ }, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
123
+ const getBlurredImgProps = (0, import_react.useCallback)(() => {
124
+ return {
125
+ src,
126
+ "aria-hidden": (0, import_shared_utils.dataAttr)(true),
127
+ className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
128
+ };
129
+ }, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
130
+ return {
131
+ Component,
132
+ domRef,
133
+ slots,
134
+ classNames,
135
+ isBlurred,
136
+ disableSkeleton,
137
+ fallbackSrc,
138
+ removeWrapper,
139
+ isZoomed,
140
+ isLoading,
141
+ getImgProps,
142
+ getWrapperProps,
143
+ getBlurredImgProps
144
+ };
145
+ }
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ useImage
149
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ useImage
4
+ } from "./chunk-Q3TXVV4U.mjs";
5
+ export {
6
+ useImage
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroui/image",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "A simple image component",
5
5
  "keywords": [
6
6
  "image"
@@ -31,9 +31,9 @@
31
31
  "@heroui/system": ">=2.4.7"
32
32
  },
33
33
  "dependencies": {
34
- "@heroui/shared-utils": "2.1.4",
35
- "@heroui/react-utils": "2.1.5",
36
- "@heroui/use-image": "2.1.4"
34
+ "@heroui/shared-utils": "2.1.6",
35
+ "@heroui/react-utils": "2.1.7",
36
+ "@heroui/use-image": "2.1.6"
37
37
  },
38
38
  "clean-package": "../../../clean-package.config.json",
39
39
  "module": "dist/index.mjs",