@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.
- package/dist/cjs/components/image-viewer/ImageViewer.js +1 -1
- package/dist/cjs/components/pinch-content/PinchContent.d.ts +1 -0
- package/dist/cjs/components/pinch-content/PinchContent.js +1 -1
- package/dist/es/components/image-viewer/ImageViewer.js +45 -33
- package/dist/es/components/pinch-content/PinchContent.d.ts +1 -0
- package/dist/es/components/pinch-content/PinchContent.js +35 -24
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
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
|
|
2
|
-
import { Modal as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
11
|
-
|
|
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
|
-
|
|
24
|
+
N,
|
|
18
25
|
{
|
|
19
|
-
isOpen:
|
|
26
|
+
isOpen: f,
|
|
20
27
|
size: "full",
|
|
21
|
-
onClose:
|
|
28
|
+
onClose: i,
|
|
22
29
|
className: "bg-black bg-opacity-70",
|
|
23
30
|
hideCloseButton: !0,
|
|
24
31
|
portalContainer: document.body,
|
|
25
|
-
children: /* @__PURE__ */ e(
|
|
26
|
-
/* @__PURE__ */
|
|
27
|
-
|
|
28
|
-
|
|
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:
|
|
39
|
+
onClick: w
|
|
33
40
|
}
|
|
34
41
|
),
|
|
35
42
|
/* @__PURE__ */ e(
|
|
36
|
-
|
|
43
|
+
I,
|
|
37
44
|
{
|
|
38
45
|
size: 24,
|
|
39
46
|
className: "text-white cursor-pointer",
|
|
40
|
-
onClick:
|
|
47
|
+
onClick: i
|
|
41
48
|
}
|
|
42
49
|
)
|
|
43
50
|
] }),
|
|
44
|
-
/* @__PURE__ */
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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: () =>
|
|
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
|
-
|
|
87
|
+
D as default
|
|
76
88
|
};
|
|
@@ -1,61 +1,72 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useSpring as
|
|
3
|
-
import { createUseGesture as
|
|
4
|
-
import { useRef as
|
|
5
|
-
import { useMount as
|
|
6
|
-
|
|
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:
|
|
10
|
-
canDrag:
|
|
11
|
-
canRotate:
|
|
12
|
-
scaleBounds:
|
|
13
|
-
} =
|
|
14
|
-
|
|
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
|
-
}),
|
|
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] =
|
|
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
|
|
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], ...
|
|
32
|
-
if (console.log(
|
|
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: [
|
|
41
|
+
offset: [i, x],
|
|
40
42
|
memo: s,
|
|
41
43
|
cancel: y
|
|
42
44
|
}) => {
|
|
43
|
-
if (!
|
|
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:
|
|
49
|
-
return
|
|
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:
|
|
57
|
+
pinch: { scaleBounds: v, rubberband: !0 }
|
|
56
58
|
}
|
|
57
|
-
),
|
|
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
|
-
|
|
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.
|
|
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": "
|
|
99
|
+
"gitHead": "9c8a13d9074b79d663541dadce6e4ab6a4462443"
|
|
99
100
|
}
|