@asnewyla/image 0.2.0 → 0.2.1
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/index.js +36 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/dist/test-utils.d.mts +3 -0
- package/dist/test-utils.d.ts +3 -0
- package/dist/test-utils.js +35 -0
- package/dist/test-utils.js.map +1 -0
- package/dist/test-utils.mjs +11 -0
- package/dist/test-utils.mjs.map +1 -0
- package/package.json +20 -5
package/dist/index.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
'use
|
|
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);
|
|
2
20
|
|
|
3
|
-
|
|
4
|
-
var
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
Image: () => Image
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
5
27
|
|
|
6
28
|
// src/components/Image.tsx
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
7
31
|
function ImageInner({
|
|
8
32
|
alt,
|
|
9
33
|
aspectRatio,
|
|
@@ -16,8 +40,8 @@ function ImageInner({
|
|
|
16
40
|
onError,
|
|
17
41
|
...restProps
|
|
18
42
|
}, ref) {
|
|
19
|
-
const [hasErrored, setHasErrored] =
|
|
20
|
-
|
|
43
|
+
const [hasErrored, setHasErrored] = (0, import_react.useState)(false);
|
|
44
|
+
(0, import_react.useEffect)(() => {
|
|
21
45
|
setHasErrored(false);
|
|
22
46
|
}, [src]);
|
|
23
47
|
const resolvedSrc = hasErrored && fallback ? fallback : src;
|
|
@@ -25,7 +49,7 @@ function ImageInner({
|
|
|
25
49
|
setHasErrored(true);
|
|
26
50
|
onError?.(e);
|
|
27
51
|
};
|
|
28
|
-
return /* @__PURE__ */
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
29
53
|
"img",
|
|
30
54
|
{
|
|
31
55
|
ref,
|
|
@@ -33,15 +57,16 @@ function ImageInner({
|
|
|
33
57
|
alt,
|
|
34
58
|
"data-fit": fit,
|
|
35
59
|
"data-radius": radius || void 0,
|
|
36
|
-
className:
|
|
60
|
+
className: className ? `xd-image ${className}` : "xd-image",
|
|
37
61
|
style: aspectRatio !== void 0 ? { aspectRatio, ...style } : style,
|
|
38
62
|
onError: handleError,
|
|
39
63
|
...restProps
|
|
40
64
|
}
|
|
41
65
|
);
|
|
42
66
|
}
|
|
43
|
-
var Image =
|
|
44
|
-
|
|
45
|
-
exports
|
|
46
|
-
|
|
67
|
+
var Image = (0, import_react.forwardRef)(ImageInner);
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
Image
|
|
71
|
+
});
|
|
47
72
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Image.tsx"],"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/Image.tsx"],"sourcesContent":["export { Image } from './components';\nexport type { ImageProps, ImageFit, ImageRadius } from './components';\n","import {\n type ForwardedRef,\n type ImgHTMLAttributes,\n forwardRef,\n useEffect,\n useState,\n} from 'react';\nimport './Image.css';\n\nexport type ImageFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';\nexport type ImageRadius = 'sm' | 'md' | 'lg' | 'full';\n\nexport type ImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, 'alt'> & {\n alt: string;\n aspectRatio?: string;\n fit?: ImageFit;\n radius?: ImageRadius;\n fallback?: string;\n};\n\nfunction ImageInner(\n {\n alt,\n aspectRatio,\n fit = 'cover',\n radius,\n fallback,\n src,\n className,\n style,\n onError,\n ...restProps\n }: ImageProps,\n ref: ForwardedRef<HTMLImageElement>,\n) {\n const [hasErrored, setHasErrored] = useState(false);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: src triggers the reset intentionally, it isn't read in the body\n useEffect(() => {\n setHasErrored(false);\n }, [src]);\n\n const resolvedSrc = hasErrored && fallback ? fallback : src;\n\n const handleError: React.ReactEventHandler<HTMLImageElement> = (e) => {\n setHasErrored(true);\n onError?.(e);\n };\n\n return (\n <img\n ref={ref}\n src={resolvedSrc}\n alt={alt}\n data-fit={fit}\n data-radius={radius || undefined}\n className={className ? `xd-image ${className}` : 'xd-image'}\n style={aspectRatio !== undefined ? { aspectRatio, ...style } : style}\n onError={handleError}\n {...restProps}\n />\n );\n}\n\nexport const Image = forwardRef(ImageInner);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAMO;AA4CH;AA9BJ,SAAS,WACP;AAAA,EACE;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAGlD,8BAAU,MAAM;AACd,kBAAc,KAAK;AAAA,EACrB,GAAG,CAAC,GAAG,CAAC;AAER,QAAM,cAAc,cAAc,WAAW,WAAW;AAExD,QAAM,cAAyD,CAAC,MAAM;AACpE,kBAAc,IAAI;AAClB,cAAU,CAAC;AAAA,EACb;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,KAAK;AAAA,MACL;AAAA,MACA,YAAU;AAAA,MACV,eAAa,UAAU;AAAA,MACvB,WAAW,YAAY,YAAY,SAAS,KAAK;AAAA,MACjD,OAAO,gBAAgB,SAAY,EAAE,aAAa,GAAG,MAAM,IAAI;AAAA,MAC/D,SAAS;AAAA,MACR,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,IAAM,YAAQ,yBAAW,UAAU;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
'use client';
|
|
3
2
|
|
|
4
3
|
// src/components/Image.tsx
|
|
4
|
+
import {
|
|
5
|
+
forwardRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
10
|
function ImageInner({
|
|
6
11
|
alt,
|
|
7
12
|
aspectRatio,
|
|
@@ -31,7 +36,7 @@ function ImageInner({
|
|
|
31
36
|
alt,
|
|
32
37
|
"data-fit": fit,
|
|
33
38
|
"data-radius": radius || void 0,
|
|
34
|
-
className:
|
|
39
|
+
className: className ? `xd-image ${className}` : "xd-image",
|
|
35
40
|
style: aspectRatio !== void 0 ? { aspectRatio, ...style } : style,
|
|
36
41
|
onError: handleError,
|
|
37
42
|
...restProps
|
|
@@ -39,7 +44,7 @@ function ImageInner({
|
|
|
39
44
|
);
|
|
40
45
|
}
|
|
41
46
|
var Image = forwardRef(ImageInner);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
export {
|
|
48
|
+
Image
|
|
49
|
+
};
|
|
45
50
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Image.tsx"],"
|
|
1
|
+
{"version":3,"sources":["../src/components/Image.tsx"],"sourcesContent":["import {\n type ForwardedRef,\n type ImgHTMLAttributes,\n forwardRef,\n useEffect,\n useState,\n} from 'react';\nimport './Image.css';\n\nexport type ImageFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';\nexport type ImageRadius = 'sm' | 'md' | 'lg' | 'full';\n\nexport type ImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, 'alt'> & {\n alt: string;\n aspectRatio?: string;\n fit?: ImageFit;\n radius?: ImageRadius;\n fallback?: string;\n};\n\nfunction ImageInner(\n {\n alt,\n aspectRatio,\n fit = 'cover',\n radius,\n fallback,\n src,\n className,\n style,\n onError,\n ...restProps\n }: ImageProps,\n ref: ForwardedRef<HTMLImageElement>,\n) {\n const [hasErrored, setHasErrored] = useState(false);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: src triggers the reset intentionally, it isn't read in the body\n useEffect(() => {\n setHasErrored(false);\n }, [src]);\n\n const resolvedSrc = hasErrored && fallback ? fallback : src;\n\n const handleError: React.ReactEventHandler<HTMLImageElement> = (e) => {\n setHasErrored(true);\n onError?.(e);\n };\n\n return (\n <img\n ref={ref}\n src={resolvedSrc}\n alt={alt}\n data-fit={fit}\n data-radius={radius || undefined}\n className={className ? `xd-image ${className}` : 'xd-image'}\n style={aspectRatio !== undefined ? { aspectRatio, ...style } : style}\n onError={handleError}\n {...restProps}\n />\n );\n}\n\nexport const Image = forwardRef(ImageInner);\n"],"mappings":";;;AAAA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4CH;AA9BJ,SAAS,WACP;AAAA,EACE;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAGlD,YAAU,MAAM;AACd,kBAAc,KAAK;AAAA,EACrB,GAAG,CAAC,GAAG,CAAC;AAER,QAAM,cAAc,cAAc,WAAW,WAAW;AAExD,QAAM,cAAyD,CAAC,MAAM;AACpE,kBAAc,IAAI;AAClB,cAAU,CAAC;AAAA,EACb;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,KAAK;AAAA,MACL;AAAA,MACA,YAAU;AAAA,MACV,eAAa,UAAU;AAAA,MACvB,WAAW,YAAY,YAAY,SAAS,KAAK;AAAA,MACjD,OAAO,gBAAgB,SAAY,EAAE,aAAa,GAAG,MAAM,IAAI;AAAA,MAC/D,SAAS;AAAA,MACR,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,IAAM,QAAQ,WAAW,UAAU;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
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/test-utils.ts
|
|
22
|
+
var test_utils_exports = {};
|
|
23
|
+
__export(test_utils_exports, {
|
|
24
|
+
getImage: () => getImage
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(test_utils_exports);
|
|
27
|
+
var import_react = require("@testing-library/react");
|
|
28
|
+
function getImage(alt) {
|
|
29
|
+
return import_react.screen.getByAltText(alt);
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
getImage
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/test-utils.ts"],"sourcesContent":["import { screen } from '@testing-library/react';\n\nexport function getImage(alt: string | RegExp): HTMLElement {\n return screen.getByAltText(alt);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;AAEhB,SAAS,SAAS,KAAmC;AAC1D,SAAO,oBAAO,aAAa,GAAG;AAChC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/test-utils.ts"],"sourcesContent":["import { screen } from '@testing-library/react';\n\nexport function getImage(alt: string | RegExp): HTMLElement {\n return screen.getByAltText(alt);\n}\n"],"mappings":";;;AAAA,SAAS,cAAc;AAEhB,SAAS,SAAS,KAAmC;AAC1D,SAAO,OAAO,aAAa,GAAG;AAChC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asnewyla/image",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Image display with org styling, aspect ratio, and load-error fallback",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,11 +16,16 @@
|
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
19
20
|
"import": "./dist/index.mjs",
|
|
20
|
-
"require": "./dist/index.js"
|
|
21
|
-
"types": "./dist/index.d.ts"
|
|
21
|
+
"require": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
-
"./styles.css": "./dist/index.css"
|
|
23
|
+
"./styles.css": "./dist/index.css",
|
|
24
|
+
"./test-utils": {
|
|
25
|
+
"types": "./dist/test-utils.d.ts",
|
|
26
|
+
"import": "./dist/test-utils.mjs",
|
|
27
|
+
"require": "./dist/test-utils.js"
|
|
28
|
+
}
|
|
24
29
|
},
|
|
25
30
|
"files": [
|
|
26
31
|
"dist"
|
|
@@ -35,7 +40,17 @@
|
|
|
35
40
|
],
|
|
36
41
|
"peerDependencies": {
|
|
37
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
38
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
|
43
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
44
|
+
"@testing-library/react": "^16.0.0",
|
|
45
|
+
"@testing-library/user-event": "^14.5.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"@testing-library/react": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@testing-library/user-event": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
39
54
|
},
|
|
40
55
|
"devDependencies": {
|
|
41
56
|
"@testing-library/jest-dom": "^6.4.0",
|