@xiping/react-components 1.0.13 → 1.0.14

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.
@@ -1,15 +1,18 @@
1
- import { ReactNode } from 'react';
1
+ import { ReactNode, CSSProperties } from 'react';
2
2
  export interface PinchContentProps {
3
3
  className?: string;
4
4
  children?: ReactNode;
5
5
  canDrag?: boolean;
6
6
  canPinch?: boolean;
7
7
  canRotate?: boolean;
8
+ pinchWithoutMove?: boolean;
8
9
  scaleBounds?: {
9
10
  min: number;
10
11
  max: number;
11
12
  };
12
13
  wheelZoomFactor?: number;
14
+ rubberband?: boolean;
15
+ style?: CSSProperties;
13
16
  }
14
17
  declare const PinchContent: (props: PinchContentProps) => import("react/jsx-runtime").JSX.Element;
15
18
  export default PinchContent;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const D=require("react/jsx-runtime"),v=require("@react-spring/web"),i=require("@use-gesture/react"),B=require("react"),x=require("ahooks"),C=require("clsx"),G=i.createUseGesture([i.dragAction,i.pinchAction,i.wheelAction]),u=l=>l.preventDefault(),N=l=>{const{className:m,children:y,canPinch:h=!0,canDrag:p=!0,canRotate:b=!0,scaleBounds:d={min:.3,max:10},wheelZoomFactor:S=.001}=l,n=B.useRef(null);x.useMount(()=>{var t,e,r;(t=n.current)==null||t.addEventListener("gesturestart",u),(e=n.current)==null||e.addEventListener("gesturechange",u),(r=n.current)==null||r.addEventListener("gestureend",u)}),x.useUnmount(()=>{var t,e,r;(t=n.current)==null||t.removeEventListener("gesturestart",u),(e=n.current)==null||e.removeEventListener("gesturechange",u),(r=n.current)==null||r.removeEventListener("gestureend",u)});const[s,g]=v.useSpring(()=>({x:0,y:0,scale:1,rotateZ:0}));return G({onWheel:({event:t,delta:[,e]})=>{if(!h)return;const c=s.scale.get()*(1-e*S),o=Math.min(Math.max(c,d.min),d.max);g.start({scale:o})},onDrag:({pinching:t,cancel:e,offset:[r,c],...o})=>{if(!p||t)return e();g.start({x:r,y:c})},onPinch:({origin:[t,e],first:r,movement:[c],offset:[o,q],memo:a,cancel:w})=>{if(!h)return w();if(r){const{width:M,height:R,x:P,y:Z}=n.current.getBoundingClientRect(),j=t-(P+M/2),A=e-(Z+R/2);a=[s.x.get(),s.y.get(),j,A]}const E=a[0]-(c-1)*a[2],L=a[1]-(c-1)*a[3],f={scale:o,rotateZ:0,x:E,y:L};return b&&(f.rotateZ=q),g.start(f),a}},{target:n,drag:{from:()=>[s.x.get(),s.y.get()]},pinch:{scaleBounds:d,rubberband:!0},wheel:{enabled:!0}}),D.jsx(v.animated.div,{className:C("select-none",m),ref:n,style:s,children:y})};exports.default=N;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C=require("react/jsx-runtime"),f=require("@react-spring/web"),l=require("@use-gesture/react"),G=require("react"),v=require("ahooks"),N=require("clsx"),U=l.createUseGesture([l.dragAction,l.pinchAction,l.wheelAction]),u=o=>o.preventDefault(),W=o=>{const{className:x,children:y,pinchWithoutMove:m=!1,canPinch:h=!0,canDrag:b=!0,canRotate:p=!0,scaleBounds:g={min:.3,max:10},wheelZoomFactor:S=.001,rubberband:q=!0}=o,r=G.useRef(null);v.useMount(()=>{var t,e,n;(t=r.current)==null||t.addEventListener("gesturestart",u),(e=r.current)==null||e.addEventListener("gesturechange",u),(n=r.current)==null||n.addEventListener("gestureend",u)}),v.useUnmount(()=>{var t,e,n;(t=r.current)==null||t.removeEventListener("gesturestart",u),(e=r.current)==null||e.removeEventListener("gesturechange",u),(n=r.current)==null||n.removeEventListener("gestureend",u)});const[s,d]=f.useSpring(()=>({x:0,y:0,scale:1,rotateZ:0}));return U({onWheel:({event:t,delta:[,e]})=>{if(!h)return;const c=s.scale.get()*(1-e*S),i=Math.min(Math.max(c,g.min),g.max);d.start({scale:i})},onDrag:({pinching:t,cancel:e,offset:[n,c],...i})=>{if(!b||t)return e();d.start({x:n,y:c})},onPinch:({origin:[t,e],first:n,movement:[c],offset:[i,w],memo:a,cancel:E})=>{if(!h)return E();if(n){const{width:P,height:Z,x:j,y:A}=r.current.getBoundingClientRect(),D=t-(j+P/2),B=e-(A+Z/2);a=[s.x.get(),s.y.get(),D,B]}const L=a[0]-(c-1)*a[2],M=a[1]-(c-1)*a[3],R={scale:i,rotateZ:p?w:s.rotateZ.get(),...m?{x:s.x.get(),y:s.y.get()}:{x:L,y:M}};return d.start(R),a}},{target:r,drag:{from:()=>[s.x.get(),s.y.get()]},pinch:{scaleBounds:g,rubberband:q},wheel:{enabled:!0}}),C.jsx(f.animated.div,{className:N("select-none",x),ref:r,style:{...o.style,...s},children:y})};exports.default=W;
@@ -44,71 +44,58 @@ type ImageSettings = {
44
44
  * the attribute behaves differently than the empty string.
45
45
  */
46
46
  crossOrigin?: CrossOrigin;
47
+ /**
48
+ * 图片渲染质量
49
+ * @defaultValue 'high'
50
+ */
51
+ imageQuality?: 'low' | 'medium' | 'high';
47
52
  };
48
53
  export interface QRCodeProps {
49
54
  /**
50
- * The value to encode into the QR Code. An array of strings can be passed in
51
- * to represent multiple segments to further optimize the QR Code.
55
+ * 要编码到二维码中的值
52
56
  */
53
- value: string | string[];
57
+ value: string;
54
58
  /**
55
- * The size, in pixels, to render the QR Code.
59
+ * 二维码的渲染尺寸(像素)
56
60
  * @defaultValue 128
57
61
  */
58
62
  size?: number;
59
63
  /**
60
- * The Error Correction Level to use.
61
- * @see https://www.qrcode.com/en/about/error_correction.html
62
- * @defaultValue L
64
+ * 错误纠正级别
65
+ * @defaultValue M
63
66
  */
64
67
  level?: ErrorCorrectionLevel;
65
68
  /**
66
- * The background color used to render the QR Code.
67
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
69
+ * 二维码的背景颜色
68
70
  * @defaultValue #FFFFFF
69
71
  */
70
72
  bgColor?: string;
71
73
  /**
72
- * The foregtound color used to render the QR Code.
73
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
74
+ * 二维码的前景颜色
74
75
  * @defaultValue #000000
75
76
  */
76
77
  fgColor?: string;
77
78
  /**
78
- * Whether or not a margin of 4 modules should be rendered as a part of the
79
- * QR Code.
80
- * @deprecated Use `marginSize` instead.
81
- * @defaultValue false
82
- */
83
- includeMargin?: boolean;
84
- /**
85
- * The number of _modules_ to use for margin. The QR Code specification
86
- * requires `4`, however you can specify any number. Values will be turned to
87
- * integers with `Math.floor`. Overrides `includeMargin` when both are specified.
88
- * @defaultValue 0
79
+ * 二维码边距的模块数量
80
+ * @defaultValue 4
89
81
  */
90
82
  marginSize?: number;
91
83
  /**
92
- * The title to assign to the QR Code. Used for accessibility reasons.
84
+ * 二维码的标题(用于无障碍访问)
93
85
  */
94
86
  title?: string;
95
87
  /**
96
- * The minimum version used when encoding the QR Code. Valid values are 1-40
97
- * with higher values resulting in more complex QR Codes. The optimal
98
- * (lowest) version is determined for the `value` provided, using `minVersion`
99
- * as the lower bound.
88
+ * 编码二维码时使用的最小版本(1-40
100
89
  * @defaultValue 1
101
90
  */
102
91
  minVersion?: number;
103
92
  /**
104
- * If enabled, the Error Correction Level of the result may be higher than
105
- * the specified Error Correction Level option if it can be done without
106
- * increasing the version.
93
+ * 是否允许在可能的情况下提高错误纠正级别
107
94
  * @defaultValue true
108
95
  */
109
96
  boostLevel?: boolean;
110
97
  /**
111
- * The settings for the embedded image.
98
+ * 嵌入图片的设置
112
99
  */
113
100
  imageSettings?: ImageSettings;
114
101
  }
@@ -1,15 +1,18 @@
1
- import { ReactNode } from 'react';
1
+ import { ReactNode, CSSProperties } from 'react';
2
2
  export interface PinchContentProps {
3
3
  className?: string;
4
4
  children?: ReactNode;
5
5
  canDrag?: boolean;
6
6
  canPinch?: boolean;
7
7
  canRotate?: boolean;
8
+ pinchWithoutMove?: boolean;
8
9
  scaleBounds?: {
9
10
  min: number;
10
11
  max: number;
11
12
  };
12
13
  wheelZoomFactor?: number;
14
+ rubberband?: boolean;
15
+ style?: CSSProperties;
13
16
  }
14
17
  declare const PinchContent: (props: PinchContentProps) => import("react/jsx-runtime").JSX.Element;
15
18
  export default PinchContent;
@@ -1,80 +1,88 @@
1
- import { jsx as P } from "react/jsx-runtime";
2
- import { useSpring as R, animated as B } from "@react-spring/web";
3
- import { createUseGesture as C, dragAction as G, pinchAction as N, wheelAction as U } from "@use-gesture/react";
4
- import { useRef as j } from "react";
5
- import { useMount as F, useUnmount as W } from "ahooks";
6
- import k from "clsx";
7
- const q = C([G, N, U]), o = (i) => i.preventDefault(), Q = (i) => {
1
+ import { jsx as B } from "react/jsx-runtime";
2
+ import { useSpring as C, animated as G } from "@react-spring/web";
3
+ import { createUseGesture as N, dragAction as U, pinchAction as W, wheelAction as j } from "@use-gesture/react";
4
+ import { useRef as F } from "react";
5
+ import { useMount as k, useUnmount as q } from "ahooks";
6
+ import z from "clsx";
7
+ const H = N([U, W, j]), o = (u) => u.preventDefault(), V = (u) => {
8
8
  const {
9
- className: m,
9
+ className: f,
10
10
  children: h,
11
- canPinch: g = !0,
12
- canDrag: p = !0,
11
+ pinchWithoutMove: m = !1,
12
+ canPinch: d = !0,
13
+ canDrag: x = !0,
13
14
  canRotate: v = !0,
14
15
  scaleBounds: l = { min: 0.3, max: 10 },
15
- wheelZoomFactor: x = 1e-3
16
- } = i, n = j(null);
17
- F(() => {
16
+ wheelZoomFactor: p = 1e-3,
17
+ rubberband: y = !0
18
+ } = u, n = F(null);
19
+ k(() => {
18
20
  var t, e, r;
19
21
  (t = n.current) == null || t.addEventListener("gesturestart", o), (e = n.current) == null || e.addEventListener("gesturechange", o), (r = n.current) == null || r.addEventListener("gestureend", o);
20
- }), W(() => {
22
+ }), q(() => {
21
23
  var t, e, r;
22
24
  (t = n.current) == null || t.removeEventListener("gesturestart", o), (e = n.current) == null || e.removeEventListener("gesturechange", o), (r = n.current) == null || r.removeEventListener("gestureend", o);
23
25
  });
24
- const [s, d] = R(() => ({
26
+ const [s, g] = C(() => ({
25
27
  x: 0,
26
28
  y: 0,
27
29
  scale: 1,
28
30
  rotateZ: 0
29
31
  }));
30
- return q(
32
+ return H(
31
33
  {
32
34
  onWheel: ({ event: t, delta: [, e] }) => {
33
- if (!g) return;
34
- const a = s.scale.get() * (1 - e * x), u = Math.min(
35
+ if (!d) return;
36
+ const a = s.scale.get() * (1 - e * p), i = Math.min(
35
37
  Math.max(a, l.min),
36
38
  l.max
37
39
  );
38
- d.start({ scale: u });
40
+ g.start({ scale: i });
39
41
  },
40
- onDrag: ({ pinching: t, cancel: e, offset: [r, a], ...u }) => {
41
- if (!p || t) return e();
42
- d.start({ x: r, y: a });
42
+ onDrag: ({ pinching: t, cancel: e, offset: [r, a], ...i }) => {
43
+ if (!x || t) return e();
44
+ g.start({ x: r, y: a });
43
45
  },
44
46
  onPinch: ({
45
47
  origin: [t, e],
46
48
  first: r,
47
49
  movement: [a],
48
- offset: [u, y],
50
+ offset: [i, E],
49
51
  memo: c,
50
- cancel: E
52
+ cancel: L
51
53
  }) => {
52
- if (!g) return E();
54
+ if (!d) return L();
53
55
  if (r) {
54
- const { width: S, height: b, x: Z, y: A } = n.current.getBoundingClientRect(), D = t - (Z + S / 2), M = e - (A + b / 2);
55
- c = [s.x.get(), s.y.get(), D, M];
56
+ const { width: M, height: Z, x: A, y: D } = n.current.getBoundingClientRect(), P = t - (A + M / 2), R = e - (D + Z / 2);
57
+ c = [s.x.get(), s.y.get(), P, R];
56
58
  }
57
- const L = c[0] - (a - 1) * c[2], w = c[1] - (a - 1) * c[3], f = { scale: u, rotateZ: 0, x: L, y: w };
58
- return v && (f.rotateZ = y), d.start(f), c;
59
+ const w = c[0] - (a - 1) * c[2], S = c[1] - (a - 1) * c[3], b = {
60
+ scale: i,
61
+ rotateZ: v ? E : s.rotateZ.get(),
62
+ ...m ? { x: s.x.get(), y: s.y.get() } : { x: w, y: S }
63
+ };
64
+ return g.start(b), c;
59
65
  }
60
66
  },
61
67
  {
62
68
  target: n,
63
69
  drag: { from: () => [s.x.get(), s.y.get()] },
64
- pinch: { scaleBounds: l, rubberband: !0 },
70
+ pinch: { scaleBounds: l, rubberband: y },
65
71
  wheel: { enabled: !0 }
66
72
  }
67
- ), // <div className="flex items-center justify-center h-full w-full">
68
- /* @__PURE__ */ P(
69
- B.div,
73
+ ), /* @__PURE__ */ B(
74
+ G.div,
70
75
  {
71
- className: k("select-none", m),
76
+ className: z("select-none", f),
72
77
  ref: n,
73
- style: s,
78
+ style: {
79
+ ...u.style,
80
+ ...s
81
+ },
74
82
  children: h
75
83
  }
76
84
  );
77
85
  };
78
86
  export {
79
- Q as default
87
+ V as default
80
88
  };
@@ -44,71 +44,58 @@ type ImageSettings = {
44
44
  * the attribute behaves differently than the empty string.
45
45
  */
46
46
  crossOrigin?: CrossOrigin;
47
+ /**
48
+ * 图片渲染质量
49
+ * @defaultValue 'high'
50
+ */
51
+ imageQuality?: 'low' | 'medium' | 'high';
47
52
  };
48
53
  export interface QRCodeProps {
49
54
  /**
50
- * The value to encode into the QR Code. An array of strings can be passed in
51
- * to represent multiple segments to further optimize the QR Code.
55
+ * 要编码到二维码中的值
52
56
  */
53
- value: string | string[];
57
+ value: string;
54
58
  /**
55
- * The size, in pixels, to render the QR Code.
59
+ * 二维码的渲染尺寸(像素)
56
60
  * @defaultValue 128
57
61
  */
58
62
  size?: number;
59
63
  /**
60
- * The Error Correction Level to use.
61
- * @see https://www.qrcode.com/en/about/error_correction.html
62
- * @defaultValue L
64
+ * 错误纠正级别
65
+ * @defaultValue M
63
66
  */
64
67
  level?: ErrorCorrectionLevel;
65
68
  /**
66
- * The background color used to render the QR Code.
67
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
69
+ * 二维码的背景颜色
68
70
  * @defaultValue #FFFFFF
69
71
  */
70
72
  bgColor?: string;
71
73
  /**
72
- * The foregtound color used to render the QR Code.
73
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
74
+ * 二维码的前景颜色
74
75
  * @defaultValue #000000
75
76
  */
76
77
  fgColor?: string;
77
78
  /**
78
- * Whether or not a margin of 4 modules should be rendered as a part of the
79
- * QR Code.
80
- * @deprecated Use `marginSize` instead.
81
- * @defaultValue false
82
- */
83
- includeMargin?: boolean;
84
- /**
85
- * The number of _modules_ to use for margin. The QR Code specification
86
- * requires `4`, however you can specify any number. Values will be turned to
87
- * integers with `Math.floor`. Overrides `includeMargin` when both are specified.
88
- * @defaultValue 0
79
+ * 二维码边距的模块数量
80
+ * @defaultValue 4
89
81
  */
90
82
  marginSize?: number;
91
83
  /**
92
- * The title to assign to the QR Code. Used for accessibility reasons.
84
+ * 二维码的标题(用于无障碍访问)
93
85
  */
94
86
  title?: string;
95
87
  /**
96
- * The minimum version used when encoding the QR Code. Valid values are 1-40
97
- * with higher values resulting in more complex QR Codes. The optimal
98
- * (lowest) version is determined for the `value` provided, using `minVersion`
99
- * as the lower bound.
88
+ * 编码二维码时使用的最小版本(1-40
100
89
  * @defaultValue 1
101
90
  */
102
91
  minVersion?: number;
103
92
  /**
104
- * If enabled, the Error Correction Level of the result may be higher than
105
- * the specified Error Correction Level option if it can be done without
106
- * increasing the version.
93
+ * 是否允许在可能的情况下提高错误纠正级别
107
94
  * @defaultValue true
108
95
  */
109
96
  boostLevel?: boolean;
110
97
  /**
111
- * The settings for the embedded image.
98
+ * 嵌入图片的设置
112
99
  */
113
100
  imageSettings?: ImageSettings;
114
101
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xiping/react-components",
3
3
  "private": false,
4
- "version": "1.0.13",
4
+ "version": "1.0.14",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/es/index.js",
@@ -48,7 +48,8 @@
48
48
  "clsx": "^2.1.1",
49
49
  "dayjs": "^1.11.13",
50
50
  "lodash-es": "^4.17.21",
51
- "motion": "^12.17.0",
51
+ "motion": "^12.18.1",
52
+ "qrcode": "^1.5.4",
52
53
  "qrcode.react": "^4.2.0",
53
54
  "react": "^18.3.1",
54
55
  "react-dom": "^18.3.1",
@@ -64,10 +65,11 @@
64
65
  "@eslint/js": "^9.29.0",
65
66
  "@faker-js/faker": "^9.8.0",
66
67
  "@storybook/addon-docs": "^9.0.10",
67
- "@storybook/addon-onboarding": "^9.0.9",
68
- "@storybook/react-vite": "^9.0.9",
68
+ "@storybook/addon-onboarding": "^9.0.10",
69
+ "@storybook/react-vite": "^9.0.10",
69
70
  "@types/lodash-es": "^4.17.12",
70
- "@types/node": "^22.15.31",
71
+ "@types/node": "^22.15.32",
72
+ "@types/qrcode": "^1.5.5",
71
73
  "@types/react": "^18.3.23",
72
74
  "@types/react-dom": "^18.3.7",
73
75
  "@vitejs/plugin-react": "^4.5.2",
@@ -75,19 +77,19 @@
75
77
  "eslint": "^9.29.0",
76
78
  "eslint-plugin-react-hooks": "^5.2.0",
77
79
  "eslint-plugin-react-refresh": "^0.4.20",
78
- "eslint-plugin-storybook": "^9.0.10",
80
+ "eslint-plugin-storybook": "^9.0.11",
79
81
  "globals": "^16.2.0",
80
- "postcss": "^8.5.5",
82
+ "postcss": "^8.5.6",
81
83
  "rollup-preserve-directives": "^1.1.3",
82
84
  "sharp": "^0.34.2",
83
- "storybook": "^9.0.9",
85
+ "storybook": "^9.0.10",
84
86
  "svgo": "^3.3.2",
85
87
  "tailwind-merge": "^2.6.0",
86
88
  "tailwind-scrollbar": "^3.1.0",
87
89
  "tailwindcss": "^3.4.17",
88
90
  "tailwindcss-safe-area": "^0.6.0",
89
91
  "typescript": "^5.8.3",
90
- "typescript-eslint": "^8.34.0",
92
+ "typescript-eslint": "^8.34.1",
91
93
  "vite": "^6.3.5",
92
94
  "vite-plugin-dts": "^4.5.4",
93
95
  "vite-plugin-image-optimizer": "^1.1.8",
@@ -102,5 +104,5 @@
102
104
  "engines": {
103
105
  "node": ">=20"
104
106
  },
105
- "gitHead": "2241fd579443d54339afba75c192a73d68f9043e"
107
+ "gitHead": "762cae9539bf1baba146a43651393fc3140bd4ad"
106
108
  }