@xiping/react-components 0.0.63 → 0.0.64

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 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),i=require("@nextui-org/modal"),d=require("react-icons/io5"),x=require("../pinch-content/PinchContent.js"),g=require("react"),w=u=>{const{isOpen:h,onClose:n,imgSrc:r,canDownload:m=!1}=u,l=Array.isArray(r)?r:[r],[t,b]=g.useState(0),f=async()=>{const o=l[t];try{const p=await(await fetch(o)).blob(),c=window.URL.createObjectURL(p),a=document.createElement("a");a.href=c,a.download=o.split("/").pop()||"image",document.body.appendChild(a),a.click(),window.URL.revokeObjectURL(c),document.body.removeChild(a)}catch(s){console.error("Error downloading image:",s)}};return e.jsx(i.Modal,{isOpen:h,size:"full",onClose:n,className:"bg-black bg-opacity-70",hideCloseButton:!0,portalContainer:document.body,children:e.jsx(i.ModalContent,{className:"overflow-hidden",children:e.jsxs("div",{className:"w-screen h-screen relative flex flex-col",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-4 z-10",children:[m&&e.jsx(d.IoDownloadOutline,{size:24,className:"text-white cursor-pointer",onClick:f}),e.jsx(d.IoCloseSharp,{size:24,className:"text-white cursor-pointer",onClick:n})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(x.default,{canRotate:!1,children:e.jsx("img",{draggable:"false",src:l[t],alt:"",className:"w-screen h-full object-contain pointer-events-none"})})}),l.length>1&&e.jsx("div",{className:"h-24 bg-black bg-opacity-50 shrink-0",children:e.jsx("div",{className:"w-full h-full overflow-x-auto flex gap-2 p-2",children:l.map((o,s)=>e.jsx("div",{className:`h-full aspect-square flex-shrink-0 cursor-pointer border-2 ${s===t?"border-white":"border-transparent"}`,onClick:()=>b(s),children:e.jsx("img",{src:o,alt:"",className:"w-full h-full object-contain",draggable:"false"})},o))})})]})})})};exports.default=w;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),d=require("@nextui-org/modal"),N=require("@nextui-org/spinner"),u=require("react-icons/io5"),y=require("../pinch-content/PinchContent.js"),h=require("react"),k=m=>{const{isOpen:f,onClose:g,imgSrc:n,canDownload:b=!1}=m,l=Array.isArray(n)?n:[n],[a,x]=h.useState(0),[p,r]=h.useState(!0),c=()=>{r(!0),g()},j=async()=>{const s=l[a];try{const C=await(await fetch(s)).blob(),i=window.URL.createObjectURL(C),t=document.createElement("a");t.href=i,t.download=s.split("/").pop()||"image",document.body.appendChild(t),t.click(),window.URL.revokeObjectURL(i),document.body.removeChild(t)}catch(o){console.error("Error downloading image:",o)}},w=()=>{r(!1)},v=()=>{r(!1)};return e.jsx(d.Modal,{isOpen:f,size:"full",onClose:c,className:"bg-black bg-opacity-70",hideCloseButton:!0,portalContainer:document.body,children:e.jsx(d.ModalContent,{className:"overflow-hidden",children:e.jsxs("div",{className:"w-screen h-screen relative flex flex-col",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-4 z-10",children:[b&&e.jsx(u.IoDownloadOutline,{size:24,className:"text-white cursor-pointer",onClick:j}),e.jsx(u.IoCloseSharp,{size:24,className:"text-white cursor-pointer",onClick:c})]}),e.jsxs("div",{className:"flex-1 min-h-0 relative flex items-center justify-center",children:[e.jsx(y.default,{canRotate:!1,className:"w-full h-full",children:e.jsx("img",{draggable:"false",src:l[a],alt:"",className:"w-screen h-full object-contain pointer-events-none",onLoad:w,onError:v})}),p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black bg-opacity-50",children:e.jsx(N.Spinner,{color:"white",size:"lg"})})]}),l.length>1&&e.jsx("div",{className:"h-24 bg-black bg-opacity-50 shrink-0 z-10",children:e.jsx("div",{className:"w-full h-full overflow-x-auto flex gap-2 p-2",children:l.map((s,o)=>e.jsx("div",{className:`h-full aspect-square flex-shrink-0 cursor-pointer border-2 transition-all ${o===a?"border-white":"border-transparent"}`,onClick:()=>x(o),children:e.jsx("img",{src:s,alt:"",className:"w-full h-full object-contain",draggable:"false"})},s))})})]})})})};exports.default=k;
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  export interface PinchContentProps {
3
+ className?: string;
3
4
  children?: ReactNode;
4
5
  canDrag?: boolean;
5
6
  canPinch?: boolean;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react/jsx-runtime"),v=require("@react-spring/web"),d=require("@use-gesture/react"),w=require("react"),h=require("ahooks"),A=d.createUseGesture([d.dragAction,d.pinchAction]),c=a=>a.preventDefault(),B=a=>{const{children:x,canPinch:y=!0,canDrag:p=!0,canRotate:b=!0,scaleBounds:E={min:.3,max:8}}=a,t=w.useRef(null);h.useMount(()=>{var r,e,n;(r=t.current)==null||r.addEventListener("gesturestart",c),(e=t.current)==null||e.addEventListener("gesturechange",c),(n=t.current)==null||n.addEventListener("gestureend",c)}),h.useUnmount(()=>{var r,e,n;(r=t.current)==null||r.removeEventListener("gesturestart",c),(e=t.current)==null||e.removeEventListener("gesturechange",c),(n=t.current)==null||n.removeEventListener("gestureend",c)});const[u,g]=v.useSpring(()=>({x:0,y:0,scale:1,rotateZ:0}));return A({onDrag:({pinching:r,cancel:e,offset:[n,o],...i})=>{if(console.log(i),!p||r)return e();g.start({x:n,y:o})},onPinch:({origin:[r,e],first:n,movement:[o],offset:[i,L],memo:s,cancel:q})=>{if(!y)return q();if(n){const{width:P,height:m,x:D,y:M}=t.current.getBoundingClientRect(),S=r-(D+P/2),Z=e-(M+m/2);s=[u.x.get(),u.y.get(),S,Z]}const R=s[0]-(o-1)*s[2],j=s[1]-(o-1)*s[3],l={scale:i,rotateZ:0,x:R,y:j};return b&&(l.rotateZ=L),g.start(l),s}},{target:t,drag:{from:()=>[u.x.get(),u.y.get()]},pinch:{scaleBounds:E,rubberband:!0}}),f.jsx("div",{className:"flex fill center",children:f.jsx(v.animated.div,{className:"select-none",ref:t,style:u,children:x})})};exports.default=B;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("react/jsx-runtime"),f=require("@react-spring/web"),g=require("@use-gesture/react"),A=require("react"),v=require("ahooks"),B=require("clsx"),C=g.createUseGesture([g.dragAction,g.pinchAction]),u=a=>a.preventDefault(),G=a=>{const{className:h,children:x,canPinch:y=!0,canDrag:p=!0,canRotate:b=!0,scaleBounds:q={min:.3,max:10}}=a,t=A.useRef(null);v.useMount(()=>{var r,e,n;(r=t.current)==null||r.addEventListener("gesturestart",u),(e=t.current)==null||e.addEventListener("gesturechange",u),(n=t.current)==null||n.addEventListener("gestureend",u)}),v.useUnmount(()=>{var r,e,n;(r=t.current)==null||r.removeEventListener("gesturestart",u),(e=t.current)==null||e.removeEventListener("gesturechange",u),(n=t.current)==null||n.removeEventListener("gestureend",u)});const[c,d]=f.useSpring(()=>({x:0,y:0,scale:1,rotateZ:0}));return C({onDrag:({pinching:r,cancel:e,offset:[n,o],...i})=>{if(console.log(i),!p||r)return e();d.start({x:n,y:o})},onPinch:({origin:[r,e],first:n,movement:[o],offset:[i,E],memo:s,cancel:L})=>{if(!y)return L();if(n){const{width:j,height:m,x:D,y:M}=t.current.getBoundingClientRect(),S=r-(D+j/2),Z=e-(M+m/2);s=[c.x.get(),c.y.get(),S,Z]}const P=s[0]-(o-1)*s[2],R=s[1]-(o-1)*s[3],l={scale:i,rotateZ:0,x:P,y:R};return b&&(l.rotateZ=E),d.start(l),s}},{target:t,drag:{from:()=>[c.x.get(),c.y.get()]},pinch:{scaleBounds:q,rubberband:!0}}),w.jsx(f.animated.div,{className:B("select-none",h),ref:t,style:c,children:x})};exports.default=G;
@@ -1,60 +1,72 @@
1
- import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
- import { Modal as b, ModalContent as g } from "@nextui-org/modal";
3
- import { IoDownloadOutline as w, IoCloseSharp as x } from "react-icons/io5";
4
- import v from "../pinch-content/PinchContent.js";
5
- import C from "react";
6
- const I = (d) => {
7
- const { isOpen: m, onClose: s, imgSrc: t, canDownload: h = !1 } = d, l = Array.isArray(t) ? t : [t], [n, p] = C.useState(0), f = async () => {
8
- const o = l[n];
1
+ import { jsx as e, jsxs as c } from "react/jsx-runtime";
2
+ import { Modal as N, ModalContent as y } from "@nextui-org/modal";
3
+ import { Spinner as k } from "@nextui-org/spinner";
4
+ import { IoDownloadOutline as j, IoCloseSharp as I } from "react-icons/io5";
5
+ import L from "../pinch-content/PinchContent.js";
6
+ import { useState as m } from "react";
7
+ const D = (h) => {
8
+ const { isOpen: f, onClose: u, imgSrc: t, canDownload: p = !1 } = h, r = Array.isArray(t) ? t : [t], [n, g] = m(0), [b, s] = m(!0), i = () => {
9
+ s(!0), u();
10
+ }, w = async () => {
11
+ const o = r[n];
9
12
  try {
10
- const u = await (await fetch(o)).blob(), c = window.URL.createObjectURL(u), r = document.createElement("a");
11
- r.href = c, r.download = o.split("/").pop() || "image", document.body.appendChild(r), r.click(), window.URL.revokeObjectURL(c), document.body.removeChild(r);
13
+ const C = await (await fetch(o)).blob(), d = window.URL.createObjectURL(C), l = document.createElement("a");
14
+ l.href = d, l.download = o.split("/").pop() || "image", document.body.appendChild(l), l.click(), window.URL.revokeObjectURL(d), document.body.removeChild(l);
12
15
  } catch (a) {
13
16
  console.error("Error downloading image:", a);
14
17
  }
18
+ }, x = () => {
19
+ s(!1);
20
+ }, v = () => {
21
+ s(!1);
15
22
  };
16
23
  return /* @__PURE__ */ e(
17
- b,
24
+ N,
18
25
  {
19
- isOpen: m,
26
+ isOpen: f,
20
27
  size: "full",
21
- onClose: s,
28
+ onClose: i,
22
29
  className: "bg-black bg-opacity-70",
23
30
  hideCloseButton: !0,
24
31
  portalContainer: document.body,
25
- children: /* @__PURE__ */ e(g, { className: "overflow-hidden", children: /* @__PURE__ */ i("div", { className: "w-screen h-screen relative flex flex-col", children: [
26
- /* @__PURE__ */ i("div", { className: "absolute top-2 right-2 flex gap-4 z-10", children: [
27
- h && /* @__PURE__ */ e(
28
- w,
32
+ children: /* @__PURE__ */ e(y, { className: "overflow-hidden", children: /* @__PURE__ */ c("div", { className: "w-screen h-screen relative flex flex-col", children: [
33
+ /* @__PURE__ */ c("div", { className: "absolute top-2 right-2 flex gap-4 z-10", children: [
34
+ p && /* @__PURE__ */ e(
35
+ j,
29
36
  {
30
37
  size: 24,
31
38
  className: "text-white cursor-pointer",
32
- onClick: f
39
+ onClick: w
33
40
  }
34
41
  ),
35
42
  /* @__PURE__ */ e(
36
- x,
43
+ I,
37
44
  {
38
45
  size: 24,
39
46
  className: "text-white cursor-pointer",
40
- onClick: s
47
+ onClick: i
41
48
  }
42
49
  )
43
50
  ] }),
44
- /* @__PURE__ */ e("div", { className: "flex-1 min-h-0", children: /* @__PURE__ */ e(v, { canRotate: !1, children: /* @__PURE__ */ e(
45
- "img",
46
- {
47
- draggable: "false",
48
- src: l[n],
49
- alt: "",
50
- className: "w-screen h-full object-contain pointer-events-none"
51
- }
52
- ) }) }),
53
- l.length > 1 && /* @__PURE__ */ e("div", { className: "h-24 bg-black bg-opacity-50 shrink-0", children: /* @__PURE__ */ e("div", { className: "w-full h-full overflow-x-auto flex gap-2 p-2", children: l.map((o, a) => /* @__PURE__ */ e(
51
+ /* @__PURE__ */ c("div", { className: "flex-1 min-h-0 relative flex items-center justify-center", children: [
52
+ /* @__PURE__ */ e(L, { canRotate: !1, className: "w-full h-full", children: /* @__PURE__ */ e(
53
+ "img",
54
+ {
55
+ draggable: "false",
56
+ src: r[n],
57
+ alt: "",
58
+ className: "w-screen h-full object-contain pointer-events-none",
59
+ onLoad: x,
60
+ onError: v
61
+ }
62
+ ) }),
63
+ b && /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center bg-black bg-opacity-50", children: /* @__PURE__ */ e(k, { color: "white", size: "lg" }) })
64
+ ] }),
65
+ r.length > 1 && /* @__PURE__ */ e("div", { className: "h-24 bg-black bg-opacity-50 shrink-0 z-10", children: /* @__PURE__ */ e("div", { className: "w-full h-full overflow-x-auto flex gap-2 p-2", children: r.map((o, a) => /* @__PURE__ */ e(
54
66
  "div",
55
67
  {
56
- className: `h-full aspect-square flex-shrink-0 cursor-pointer border-2 ${a === n ? "border-white" : "border-transparent"}`,
57
- onClick: () => p(a),
68
+ className: `h-full aspect-square flex-shrink-0 cursor-pointer border-2 transition-all ${a === n ? "border-white" : "border-transparent"}`,
69
+ onClick: () => g(a),
58
70
  children: /* @__PURE__ */ e(
59
71
  "img",
60
72
  {
@@ -72,5 +84,5 @@ const I = (d) => {
72
84
  );
73
85
  };
74
86
  export {
75
- I as default
87
+ D as default
76
88
  };
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  export interface PinchContentProps {
3
+ className?: string;
3
4
  children?: ReactNode;
4
5
  canDrag?: boolean;
5
6
  canPinch?: boolean;
@@ -1,61 +1,72 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import { useSpring as B, animated as C } from "@react-spring/web";
3
- import { createUseGesture as G, dragAction as N, pinchAction as U } from "@use-gesture/react";
4
- import { useRef as j } from "react";
5
- import { useMount as w, useUnmount as M } from "ahooks";
6
- const S = G([N, U]), o = (i) => i.preventDefault(), I = (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 j } from "@use-gesture/react";
4
+ import { useRef as w } from "react";
5
+ import { useMount as M, useUnmount as S } from "ahooks";
6
+ import k from "clsx";
7
+ const q = N([U, j]), o = (u) => u.preventDefault(), O = (u) => {
7
8
  const {
9
+ className: f,
8
10
  children: l,
9
- canPinch: h = !0,
10
- canDrag: v = !0,
11
- canRotate: p = !0,
12
- scaleBounds: m = { min: 0.3, max: 8 }
13
- } = i, t = j(null);
14
- w(() => {
11
+ canPinch: m = !0,
12
+ canDrag: p = !0,
13
+ canRotate: h = !0,
14
+ scaleBounds: v = { min: 0.3, max: 10 }
15
+ } = u, t = w(null);
16
+ M(() => {
15
17
  var r, e, n;
16
18
  (r = t.current) == null || r.addEventListener("gesturestart", o), (e = t.current) == null || e.addEventListener("gesturechange", o), (n = t.current) == null || n.addEventListener("gestureend", o);
17
- }), M(() => {
19
+ }), S(() => {
18
20
  var r, e, n;
19
21
  (r = t.current) == null || r.removeEventListener("gesturestart", o), (e = t.current) == null || e.removeEventListener("gesturechange", o), (n = t.current) == null || n.removeEventListener("gestureend", o);
20
22
  });
21
- const [c, g] = B(() => ({
23
+ const [c, g] = C(() => ({
22
24
  x: 0,
23
25
  y: 0,
24
26
  scale: 1,
25
27
  rotateZ: 0
26
28
  }));
27
- return S(
29
+ return q(
28
30
  {
29
31
  // onHover: ({ active, event }) => console.log('hover', event, active),
30
32
  // onMove: ({ event }) => console.log('move', event),
31
- onDrag: ({ pinching: r, cancel: e, offset: [n, a], ...u }) => {
32
- if (console.log(u), !v || r) return e();
33
+ onDrag: ({ pinching: r, cancel: e, offset: [n, a], ...i }) => {
34
+ if (console.log(i), !p || r) return e();
33
35
  g.start({ x: n, y: a });
34
36
  },
35
37
  onPinch: ({
36
38
  origin: [r, e],
37
39
  first: n,
38
40
  movement: [a],
39
- offset: [u, x],
41
+ offset: [i, x],
40
42
  memo: s,
41
43
  cancel: y
42
44
  }) => {
43
- if (!h) return y();
45
+ if (!m) return y();
44
46
  if (n) {
45
47
  const { width: b, height: D, x: P, y: R } = t.current.getBoundingClientRect(), Z = r - (P + b / 2), A = e - (R + D / 2);
46
48
  s = [c.x.get(), c.y.get(), Z, A];
47
49
  }
48
- const E = s[0] - (a - 1) * s[2], L = s[1] - (a - 1) * s[3], d = { scale: u, rotateZ: 0, x: E, y: L };
49
- return p && (d.rotateZ = x), g.start(d), s;
50
+ const E = s[0] - (a - 1) * s[2], L = s[1] - (a - 1) * s[3], d = { scale: i, rotateZ: 0, x: E, y: L };
51
+ return h && (d.rotateZ = x), g.start(d), s;
50
52
  }
51
53
  },
52
54
  {
53
55
  target: t,
54
56
  drag: { from: () => [c.x.get(), c.y.get()] },
55
- pinch: { scaleBounds: m, rubberband: !0 }
57
+ pinch: { scaleBounds: v, rubberband: !0 }
56
58
  }
57
- ), /* @__PURE__ */ f("div", { className: "flex fill center", children: /* @__PURE__ */ f(C.div, { className: "select-none", ref: t, style: c, children: l }) });
59
+ ), // <div className="flex items-center justify-center h-full w-full">
60
+ /* @__PURE__ */ B(
61
+ G.div,
62
+ {
63
+ className: k("select-none", f),
64
+ ref: t,
65
+ style: c,
66
+ children: l
67
+ }
68
+ );
58
69
  };
59
70
  export {
60
- I as default
71
+ O as default
61
72
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xiping/react-components",
3
3
  "private": false,
4
- "version": "0.0.63",
4
+ "version": "0.0.64",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/es/index.js",
@@ -36,6 +36,7 @@
36
36
  "@nextui-org/button": "^2.2.9",
37
37
  "@nextui-org/modal": "^2.2.7",
38
38
  "@nextui-org/react": "^2.6.11",
39
+ "@nextui-org/spinner": "^2.2.6",
39
40
  "@nextui-org/system": "^2.4.6",
40
41
  "@nextui-org/theme": "^2.4.5",
41
42
  "@react-spring/web": "^9.7.5",
@@ -95,5 +96,5 @@
95
96
  "engines": {
96
97
  "node": ">=18"
97
98
  },
98
- "gitHead": "d624dbba9ebc4cfafeddf2af148d5564a0e660bb"
99
+ "gitHead": "9c8a13d9074b79d663541dadce6e4ab6a4462443"
99
100
  }