@xiping/react-components 0.0.62 → 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,7 +1,8 @@
1
1
  interface ImageViewerProps {
2
2
  isOpen: boolean;
3
- imgSrc: string;
3
+ imgSrc: string | string[];
4
4
  onClose: () => void;
5
+ canDownload?: boolean;
5
6
  }
6
7
  declare const ImageViewer: (props: ImageViewerProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export default ImageViewer;
@@ -1,39 +1,88 @@
1
- import { jsx as e, jsxs as a } from "react/jsx-runtime";
2
- import { Modal as r, ModalContent as n } from "@nextui-org/modal";
3
- import { IoCloseSharp as i } from "react-icons/io5";
4
- import c from "../pinch-content/PinchContent.js";
5
- const f = (l) => {
6
- const { isOpen: o, onClose: s, imgSrc: t } = l;
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];
12
+ try {
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);
15
+ } catch (a) {
16
+ console.error("Error downloading image:", a);
17
+ }
18
+ }, x = () => {
19
+ s(!1);
20
+ }, v = () => {
21
+ s(!1);
22
+ };
7
23
  return /* @__PURE__ */ e(
8
- r,
24
+ N,
9
25
  {
10
- isOpen: o,
26
+ isOpen: f,
11
27
  size: "full",
12
- onClose: s,
13
- className: "pppp bg-black bg-opacity-70",
28
+ onClose: i,
29
+ className: "bg-black bg-opacity-70",
14
30
  hideCloseButton: !0,
15
- children: /* @__PURE__ */ e(n, { className: "overflow-hidden", children: /* @__PURE__ */ a("div", { className: "w-screen h-screen relative", children: [
16
- /* @__PURE__ */ e(
17
- i,
18
- {
19
- size: 24,
20
- className: "absolute top-2 right-2 text-white z-10",
21
- onClick: s
22
- }
23
- ),
24
- /* @__PURE__ */ e("div", { className: "w-full h-full", children: /* @__PURE__ */ e(c, { canRotate: !1, children: /* @__PURE__ */ e(
25
- "img",
31
+ portalContainer: document.body,
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,
36
+ {
37
+ size: 24,
38
+ className: "text-white cursor-pointer",
39
+ onClick: w
40
+ }
41
+ ),
42
+ /* @__PURE__ */ e(
43
+ I,
44
+ {
45
+ size: 24,
46
+ className: "text-white cursor-pointer",
47
+ onClick: i
48
+ }
49
+ )
50
+ ] }),
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(
66
+ "div",
26
67
  {
27
- draggable: "false",
28
- src: t,
29
- alt: "",
30
- className: "w-screen h-screen object-contain pointer-events-none"
31
- }
32
- ) }) })
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),
70
+ children: /* @__PURE__ */ e(
71
+ "img",
72
+ {
73
+ src: o,
74
+ alt: "",
75
+ className: "w-full h-full object-contain",
76
+ draggable: "false"
77
+ }
78
+ )
79
+ },
80
+ o
81
+ )) }) })
33
82
  ] }) })
34
83
  }
35
84
  );
36
85
  };
37
86
  export {
38
- f as default
87
+ D as default
39
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
  };