xxf_react 0.3.7 → 0.3.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,17 @@
1
+ import { ImageProps } from "next/image";
2
+ import React from "react";
3
+ export interface XImageProps extends ImageProps {
4
+ /** 图片加载失败时显示的备用图片 URL */
5
+ fallback?: string;
6
+ }
7
+ /**
8
+ * 增强的 image 组件,支持加载失败时显示备用图片
9
+ * @param src - 图片地址
10
+ * @param fallback - 加载失败时显示的备用图片 URL
11
+ * @param onError - 加载失败回调
12
+ * @param className - 样式类名
13
+ * @param props - 其他 Next.js image 支持的属性
14
+ */
15
+ export declare function XImage({ src, fallback, onError, ...props }: XImageProps): React.JSX.Element;
16
+ export default XImage;
17
+ //# sourceMappingURL=XImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XImage.d.ts","sourceRoot":"","sources":["../../../src/layout/image/XImage.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC3C,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,EACI,GAAG,EACH,QAAQ,EACR,OAAO,EACP,GAAG,KAAK,EACX,EAAE,WAAW,qBAsBpC;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import Image from "next/image";
3
+ import React, { useState, useEffect } from "react";
4
+ /**
5
+ * 增强的 image 组件,支持加载失败时显示备用图片
6
+ * @param src - 图片地址
7
+ * @param fallback - 加载失败时显示的备用图片 URL
8
+ * @param onError - 加载失败回调
9
+ * @param className - 样式类名
10
+ * @param props - 其他 Next.js image 支持的属性
11
+ */
12
+ export function XImage({ src, fallback, onError, ...props }) {
13
+ const [imgSrc, setImgSrc] = useState(src);
14
+ // src 变化时重置 imgSrc
15
+ useEffect(() => {
16
+ setImgSrc(src);
17
+ }, [src]);
18
+ const handleError = (e) => {
19
+ if (fallback && imgSrc !== fallback) {
20
+ setImgSrc(fallback);
21
+ }
22
+ onError === null || onError === void 0 ? void 0 : onError(e);
23
+ };
24
+ return (React.createElement(Image, { ...props, src: imgSrc, onError: handleError }));
25
+ }
26
+ export default XImage;
@@ -3,4 +3,5 @@ export * from './resize/core/SizedLayoutContext';
3
3
  export * from './resize/core/ResizeObserverHook';
4
4
  export * from './resize/impl/SizedContainer';
5
5
  export * from './resize/impl/SizedLayout';
6
+ export * from './image/XImage';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kCAAkC,CAAA;AAChD,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kCAAkC,CAAA;AAChD,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,gBAAgB,CAAA"}
@@ -3,3 +3,4 @@ export * from './resize/core/SizedLayoutContext';
3
3
  export * from './resize/core/ResizeObserverHook';
4
4
  export * from './resize/impl/SizedContainer';
5
5
  export * from './resize/impl/SizedLayout';
6
+ export * from './image/XImage';
@@ -1,7 +1,4 @@
1
1
  export * from './ScrollToCenter';
2
2
  export * from './Reload';
3
- export * from '../layout/resize/core/ResizeObserverHook';
4
- export * from '../layout/resize/core/SizedLayoutContext';
5
- export * from '../layout/resize/impl/SizedLayout';
6
- export * from '../layout/resize/impl/SizedContainer';
3
+ export * from './url-placholder';
7
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,0CAA0C,CAAA;AACxD,cAAc,0CAA0C,CAAA;AACxD,cAAc,mCAAmC,CAAA;AACjD,cAAc,sCAAsC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA"}
@@ -1,7 +1,4 @@
1
1
  'use client';
2
2
  export * from './ScrollToCenter';
3
3
  export * from './Reload';
4
- export * from '../layout/resize/core/ResizeObserverHook';
5
- export * from '../layout/resize/core/SizedLayoutContext';
6
- export * from '../layout/resize/impl/SizedLayout';
7
- export * from '../layout/resize/impl/SizedContainer';
4
+ export * from './url-placholder';
@@ -0,0 +1,14 @@
1
+ export declare const placeholderHost = "https://placehold.co";
2
+ /**
3
+ * 占位图
4
+ * */
5
+ export interface PlaceholderProps {
6
+ text?: string;
7
+ backgroundColor?: string;
8
+ textColor?: string;
9
+ }
10
+ /**
11
+ * 生成占位图 URL
12
+ */
13
+ export declare function urlPlaceholder(width: number, height: number, props?: PlaceholderProps): string;
14
+ //# sourceMappingURL=url-placholder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-placholder.d.ts","sourceRoot":"","sources":["../../src/utils/url-placholder.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,yBAAyB,CAAA;AAErD;;KAEK;AACL,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,gBAAqB,GAC7B,MAAM,CAgBR"}
@@ -0,0 +1,17 @@
1
+ export const placeholderHost = "https://placehold.co";
2
+ /**
3
+ * 生成占位图 URL
4
+ */
5
+ export function urlPlaceholder(width, height, props = {}) {
6
+ const { text, backgroundColor, textColor } = props;
7
+ // 拼尺寸
8
+ const sizePart = `${width}x${height}`;
9
+ // 拼颜色参数(可选)
10
+ let colorPart = "";
11
+ if (backgroundColor && textColor) {
12
+ colorPart = `/${backgroundColor.replace("#", "")}/${textColor.replace("#", "")}`;
13
+ }
14
+ // 拼文字,如果没有 text 就显示默认尺寸
15
+ const textPart = `?text=${encodeURIComponent(text !== null && text !== void 0 ? text : `${width}x${height}`)}`;
16
+ return `https://placehold.co/${sizePart}${colorPart}${textPart}`;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxf_react",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -74,5 +74,8 @@
74
74
  "tailwind-variants": "^3.2.2",
75
75
  "tiny-lru": "^11.4.7",
76
76
  "use-debounce": "^10.0.6"
77
+ },
78
+ "devDependencies": {
79
+ "next": "^16.0.7"
77
80
  }
78
81
  }