@heroui/image 0.0.0-canary-20250109194025
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/chunk-BWCZTRRG.mjs +52 -0
- package/dist/chunk-DSOLHU5M.mjs +124 -0
- package/dist/image.d.ts +12 -0
- package/dist/image.js +191 -0
- package/dist/image.mjs +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +197 -0
- package/dist/index.mjs +11 -0
- package/dist/use-image.d.ts +142 -0
- package/dist/use-image.js +147 -0
- package/dist/use-image.mjs +7 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Next UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @heroui/image
|
|
2
|
+
|
|
3
|
+
The Image component is used to display images with support for fallback.
|
|
4
|
+
|
|
5
|
+
Please refer to the [documentation](https://heroui.com/docs/components/image) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @heroui/image
|
|
11
|
+
# or
|
|
12
|
+
npm i @heroui/image
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Contribution
|
|
16
|
+
|
|
17
|
+
Yes please! See the
|
|
18
|
+
[contributing guidelines](https://github.com/frontio-ai/heroui/blob/master/CONTRIBUTING.md)
|
|
19
|
+
for details.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
This project is licensed under the terms of the
|
|
24
|
+
[MIT license](https://github.com/frontio-ai/heroui/blob/master/LICENSE).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useImage
|
|
4
|
+
} from "./chunk-DSOLHU5M.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 = "HeorUI.Image";
|
|
48
|
+
var image_default = Image;
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
image_default
|
|
52
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
...(otherProps == null ? void 0 : otherProps.height) && { height: h },
|
|
81
|
+
...props2.style,
|
|
82
|
+
...otherProps.style
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const getWrapperProps = useCallback(() => {
|
|
87
|
+
const fallbackStyle = showFallback ? {
|
|
88
|
+
backgroundImage: `url(${fallbackSrc})`
|
|
89
|
+
} : {};
|
|
90
|
+
return {
|
|
91
|
+
className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
|
|
92
|
+
style: {
|
|
93
|
+
...fallbackStyle,
|
|
94
|
+
maxWidth: w
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
|
|
98
|
+
const getBlurredImgProps = useCallback(() => {
|
|
99
|
+
return {
|
|
100
|
+
src,
|
|
101
|
+
"aria-hidden": dataAttr(true),
|
|
102
|
+
className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
|
|
103
|
+
};
|
|
104
|
+
}, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
|
|
105
|
+
return {
|
|
106
|
+
Component,
|
|
107
|
+
domRef,
|
|
108
|
+
slots,
|
|
109
|
+
classNames,
|
|
110
|
+
isBlurred,
|
|
111
|
+
disableSkeleton,
|
|
112
|
+
fallbackSrc,
|
|
113
|
+
removeWrapper,
|
|
114
|
+
isZoomed,
|
|
115
|
+
isLoading,
|
|
116
|
+
getImgProps,
|
|
117
|
+
getWrapperProps,
|
|
118
|
+
getBlurredImgProps
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
useImage
|
|
124
|
+
};
|
package/dist/image.d.ts
ADDED
|
@@ -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 { 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
|
+
...(otherProps == null ? void 0 : otherProps.height) && { height: h },
|
|
108
|
+
...props2.style,
|
|
109
|
+
...otherProps.style
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const getWrapperProps = (0, import_react.useCallback)(() => {
|
|
114
|
+
const fallbackStyle = showFallback ? {
|
|
115
|
+
backgroundImage: `url(${fallbackSrc})`
|
|
116
|
+
} : {};
|
|
117
|
+
return {
|
|
118
|
+
className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
|
|
119
|
+
style: {
|
|
120
|
+
...fallbackStyle,
|
|
121
|
+
maxWidth: w
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
|
|
125
|
+
const getBlurredImgProps = (0, import_react.useCallback)(() => {
|
|
126
|
+
return {
|
|
127
|
+
src,
|
|
128
|
+
"aria-hidden": (0, import_shared_utils.dataAttr)(true),
|
|
129
|
+
className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
|
|
130
|
+
};
|
|
131
|
+
}, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
|
|
132
|
+
return {
|
|
133
|
+
Component,
|
|
134
|
+
domRef,
|
|
135
|
+
slots,
|
|
136
|
+
classNames,
|
|
137
|
+
isBlurred,
|
|
138
|
+
disableSkeleton,
|
|
139
|
+
fallbackSrc,
|
|
140
|
+
removeWrapper,
|
|
141
|
+
isZoomed,
|
|
142
|
+
isLoading,
|
|
143
|
+
getImgProps,
|
|
144
|
+
getWrapperProps,
|
|
145
|
+
getBlurredImgProps
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/image.tsx
|
|
150
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
151
|
+
var Image = (0, import_system2.forwardRef)((props, ref) => {
|
|
152
|
+
const {
|
|
153
|
+
Component,
|
|
154
|
+
domRef,
|
|
155
|
+
slots,
|
|
156
|
+
classNames,
|
|
157
|
+
isBlurred,
|
|
158
|
+
isZoomed,
|
|
159
|
+
fallbackSrc,
|
|
160
|
+
removeWrapper,
|
|
161
|
+
disableSkeleton,
|
|
162
|
+
getImgProps,
|
|
163
|
+
getWrapperProps,
|
|
164
|
+
getBlurredImgProps
|
|
165
|
+
} = useImage({
|
|
166
|
+
...props,
|
|
167
|
+
ref
|
|
168
|
+
});
|
|
169
|
+
const img = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: domRef, ...getImgProps() });
|
|
170
|
+
if (removeWrapper) {
|
|
171
|
+
return img;
|
|
172
|
+
}
|
|
173
|
+
const zoomed = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: slots.zoomedWrapper({ class: classNames == null ? void 0 : classNames.zoomedWrapper }), children: img });
|
|
174
|
+
if (isBlurred) {
|
|
175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
|
|
176
|
+
isZoomed ? zoomed : img,
|
|
177
|
+
(0, import_react3.cloneElement)(img, getBlurredImgProps())
|
|
178
|
+
] });
|
|
179
|
+
}
|
|
180
|
+
if (isZoomed || !disableSkeleton || fallbackSrc) {
|
|
181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
|
|
182
|
+
" ",
|
|
183
|
+
isZoomed ? zoomed : img
|
|
184
|
+
] });
|
|
185
|
+
}
|
|
186
|
+
return img;
|
|
187
|
+
});
|
|
188
|
+
Image.displayName = "HeorUI.Image";
|
|
189
|
+
var image_default = Image;
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {});
|
package/dist/image.mjs
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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 src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
Image: () => image_default,
|
|
25
|
+
useImage: () => useImage
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_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
|
+
...(otherProps == null ? void 0 : otherProps.height) && { height: h },
|
|
111
|
+
...props2.style,
|
|
112
|
+
...otherProps.style
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const getWrapperProps = (0, import_react.useCallback)(() => {
|
|
117
|
+
const fallbackStyle = showFallback ? {
|
|
118
|
+
backgroundImage: `url(${fallbackSrc})`
|
|
119
|
+
} : {};
|
|
120
|
+
return {
|
|
121
|
+
className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
|
|
122
|
+
style: {
|
|
123
|
+
...fallbackStyle,
|
|
124
|
+
maxWidth: w
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
|
|
128
|
+
const getBlurredImgProps = (0, import_react.useCallback)(() => {
|
|
129
|
+
return {
|
|
130
|
+
src,
|
|
131
|
+
"aria-hidden": (0, import_shared_utils.dataAttr)(true),
|
|
132
|
+
className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
|
|
133
|
+
};
|
|
134
|
+
}, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
|
|
135
|
+
return {
|
|
136
|
+
Component,
|
|
137
|
+
domRef,
|
|
138
|
+
slots,
|
|
139
|
+
classNames,
|
|
140
|
+
isBlurred,
|
|
141
|
+
disableSkeleton,
|
|
142
|
+
fallbackSrc,
|
|
143
|
+
removeWrapper,
|
|
144
|
+
isZoomed,
|
|
145
|
+
isLoading,
|
|
146
|
+
getImgProps,
|
|
147
|
+
getWrapperProps,
|
|
148
|
+
getBlurredImgProps
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/image.tsx
|
|
153
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
154
|
+
var Image = (0, import_system2.forwardRef)((props, ref) => {
|
|
155
|
+
const {
|
|
156
|
+
Component,
|
|
157
|
+
domRef,
|
|
158
|
+
slots,
|
|
159
|
+
classNames,
|
|
160
|
+
isBlurred,
|
|
161
|
+
isZoomed,
|
|
162
|
+
fallbackSrc,
|
|
163
|
+
removeWrapper,
|
|
164
|
+
disableSkeleton,
|
|
165
|
+
getImgProps,
|
|
166
|
+
getWrapperProps,
|
|
167
|
+
getBlurredImgProps
|
|
168
|
+
} = useImage({
|
|
169
|
+
...props,
|
|
170
|
+
ref
|
|
171
|
+
});
|
|
172
|
+
const img = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: domRef, ...getImgProps() });
|
|
173
|
+
if (removeWrapper) {
|
|
174
|
+
return img;
|
|
175
|
+
}
|
|
176
|
+
const zoomed = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: slots.zoomedWrapper({ class: classNames == null ? void 0 : classNames.zoomedWrapper }), children: img });
|
|
177
|
+
if (isBlurred) {
|
|
178
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
|
|
179
|
+
isZoomed ? zoomed : img,
|
|
180
|
+
(0, import_react3.cloneElement)(img, getBlurredImgProps())
|
|
181
|
+
] });
|
|
182
|
+
}
|
|
183
|
+
if (isZoomed || !disableSkeleton || fallbackSrc) {
|
|
184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...getWrapperProps(), children: [
|
|
185
|
+
" ",
|
|
186
|
+
isZoomed ? zoomed : img
|
|
187
|
+
] });
|
|
188
|
+
}
|
|
189
|
+
return img;
|
|
190
|
+
});
|
|
191
|
+
Image.displayName = "HeorUI.Image";
|
|
192
|
+
var image_default = Image;
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
Image,
|
|
196
|
+
useImage
|
|
197
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -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?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
73
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
74
|
+
isZoomed?: boolean | undefined;
|
|
75
|
+
showSkeleton?: boolean | undefined;
|
|
76
|
+
disableAnimation?: boolean | undefined;
|
|
77
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
78
|
+
zoomedWrapper: (slotProps?: ({
|
|
79
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
80
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
81
|
+
isZoomed?: boolean | undefined;
|
|
82
|
+
showSkeleton?: boolean | undefined;
|
|
83
|
+
disableAnimation?: boolean | undefined;
|
|
84
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
85
|
+
img: (slotProps?: ({
|
|
86
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
87
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
88
|
+
isZoomed?: boolean | undefined;
|
|
89
|
+
showSkeleton?: boolean | undefined;
|
|
90
|
+
disableAnimation?: boolean | undefined;
|
|
91
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
92
|
+
blurredImg: (slotProps?: ({
|
|
93
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
94
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
95
|
+
isZoomed?: boolean | undefined;
|
|
96
|
+
showSkeleton?: boolean | undefined;
|
|
97
|
+
disableAnimation?: boolean | undefined;
|
|
98
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
99
|
+
} & {
|
|
100
|
+
wrapper: (slotProps?: ({
|
|
101
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
102
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
103
|
+
isZoomed?: boolean | undefined;
|
|
104
|
+
showSkeleton?: boolean | undefined;
|
|
105
|
+
disableAnimation?: boolean | undefined;
|
|
106
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
107
|
+
zoomedWrapper: (slotProps?: ({
|
|
108
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
109
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
110
|
+
isZoomed?: boolean | undefined;
|
|
111
|
+
showSkeleton?: boolean | undefined;
|
|
112
|
+
disableAnimation?: boolean | undefined;
|
|
113
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
114
|
+
img: (slotProps?: ({
|
|
115
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
116
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
117
|
+
isZoomed?: boolean | undefined;
|
|
118
|
+
showSkeleton?: boolean | undefined;
|
|
119
|
+
disableAnimation?: boolean | undefined;
|
|
120
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
121
|
+
blurredImg: (slotProps?: ({
|
|
122
|
+
radius?: "none" | "sm" | "md" | "lg" | "full" | undefined;
|
|
123
|
+
shadow?: "none" | "sm" | "md" | "lg" | undefined;
|
|
124
|
+
isZoomed?: boolean | undefined;
|
|
125
|
+
showSkeleton?: boolean | undefined;
|
|
126
|
+
disableAnimation?: boolean | undefined;
|
|
127
|
+
} & tailwind_variants.ClassProp<ClassValue>) | undefined) => string;
|
|
128
|
+
} & {};
|
|
129
|
+
classNames: SlotsToClasses<"wrapper" | "zoomedWrapper" | "img" | "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<Record<string, unknown>, _heroui_system.DOMAttributes<_heroui_system.DOMElement>>;
|
|
137
|
+
getWrapperProps: PropGetter<Record<string, unknown>, _heroui_system.DOMAttributes<_heroui_system.DOMElement>>;
|
|
138
|
+
getBlurredImgProps: PropGetter<Record<string, unknown>, _heroui_system.DOMAttributes<_heroui_system.DOMElement>>;
|
|
139
|
+
};
|
|
140
|
+
type UseImageReturn = ReturnType<typeof useImage>;
|
|
141
|
+
|
|
142
|
+
export { UseImageProps, UseImageReturn, useImage };
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
...(otherProps == null ? void 0 : otherProps.height) && { height: h },
|
|
104
|
+
...props2.style,
|
|
105
|
+
...otherProps.style
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const getWrapperProps = (0, import_react.useCallback)(() => {
|
|
110
|
+
const fallbackStyle = showFallback ? {
|
|
111
|
+
backgroundImage: `url(${fallbackSrc})`
|
|
112
|
+
} : {};
|
|
113
|
+
return {
|
|
114
|
+
className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
|
|
115
|
+
style: {
|
|
116
|
+
...fallbackStyle,
|
|
117
|
+
maxWidth: w
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}, [slots, showFallback, fallbackSrc, classNames == null ? void 0 : classNames.wrapper, w]);
|
|
121
|
+
const getBlurredImgProps = (0, import_react.useCallback)(() => {
|
|
122
|
+
return {
|
|
123
|
+
src,
|
|
124
|
+
"aria-hidden": (0, import_shared_utils.dataAttr)(true),
|
|
125
|
+
className: slots.blurredImg({ class: classNames == null ? void 0 : classNames.blurredImg })
|
|
126
|
+
};
|
|
127
|
+
}, [slots, src, classNames == null ? void 0 : classNames.blurredImg]);
|
|
128
|
+
return {
|
|
129
|
+
Component,
|
|
130
|
+
domRef,
|
|
131
|
+
slots,
|
|
132
|
+
classNames,
|
|
133
|
+
isBlurred,
|
|
134
|
+
disableSkeleton,
|
|
135
|
+
fallbackSrc,
|
|
136
|
+
removeWrapper,
|
|
137
|
+
isZoomed,
|
|
138
|
+
isLoading,
|
|
139
|
+
getImgProps,
|
|
140
|
+
getWrapperProps,
|
|
141
|
+
getBlurredImgProps
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
useImage
|
|
147
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@heroui/image",
|
|
3
|
+
"version": "0.0.0-canary-20250109194025",
|
|
4
|
+
"description": "A simple image component",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"image"
|
|
7
|
+
],
|
|
8
|
+
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
9
|
+
"homepage": "https://heroui.com",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/frontio-ai/heroui.git",
|
|
22
|
+
"directory": "packages/components/image"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/frontio-ai/heroui/issues"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18 || >=19.0.0-rc.0",
|
|
29
|
+
"react-dom": ">=18 || >=19.0.0-rc.0",
|
|
30
|
+
"@heroui/theme": "0.0.0-canary-20250109194025",
|
|
31
|
+
"@heroui/system": "0.0.0-canary-20250109194025"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@heroui/react-utils": "0.0.0-canary-20250109194025",
|
|
35
|
+
"@heroui/shared-utils": "0.0.0-canary-20250109194025",
|
|
36
|
+
"@heroui/use-image": "0.0.0-canary-20250109194025"
|
|
37
|
+
},
|
|
38
|
+
"clean-package": "../../../clean-package.config.json",
|
|
39
|
+
"module": "dist/index.mjs",
|
|
40
|
+
"types": "dist/index.d.ts",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.mjs",
|
|
45
|
+
"require": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup src --dts",
|
|
51
|
+
"build:fast": "tsup src",
|
|
52
|
+
"dev": "pnpm build:fast --watch",
|
|
53
|
+
"clean": "rimraf dist .turbo",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
55
|
+
}
|
|
56
|
+
}
|