@paperpic/react 0.0.0-stage → 0.2.0

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/index.js ADDED
@@ -0,0 +1,85 @@
1
+ "use client";
2
+ import { PaperPic as PaperPic$1 } from "@paperpic/core";
3
+ import { useImperativeHandle, useLayoutEffect, useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/PaperPic.tsx
6
+ /**
7
+ * A document image viewer and editor. It fills its parent element, which needs a height. Import the stylesheet once,
8
+ * from `@paperpic/react/style.css`.
9
+ *
10
+ * @example
11
+ * import { PaperPic } from '@paperpic/react'
12
+ * import '@paperpic/react/style.css'
13
+ *
14
+ * <div style={{ height: 480 }}>
15
+ * <PaperPic src="/receipt.jpg" alt="A receipt" onApply={({ blob }) => upload(blob)} />
16
+ * </div>
17
+ */
18
+ function PaperPic({ ref, className, style, onApply, onChange, onDownload, onError, onLoad, alt, aspectRatio, download, editable, filename, icons, labels, maxOutputSize, output, softness, src, toolbar, tools, wheelZoom }) {
19
+ const hostRef = useRef(null);
20
+ const instanceRef = useRef(null);
21
+ const handlersRef = useRef({});
22
+ useLayoutEffect(() => {
23
+ handlersRef.current = {
24
+ onApply,
25
+ onChange,
26
+ onDownload,
27
+ onError,
28
+ onLoad
29
+ };
30
+ });
31
+ useLayoutEffect(() => {
32
+ const pic = new PaperPic$1(hostRef.current);
33
+ pic.on("apply", (payload) => handlersRef.current.onApply?.(payload));
34
+ pic.on("change", (payload) => handlersRef.current.onChange?.(payload));
35
+ pic.on("download", (payload) => handlersRef.current.onDownload?.(payload));
36
+ pic.on("error", (payload) => handlersRef.current.onError?.(payload));
37
+ pic.on("load", (payload) => handlersRef.current.onLoad?.(payload));
38
+ instanceRef.current = pic;
39
+ return () => {
40
+ pic.destroy();
41
+ instanceRef.current = null;
42
+ };
43
+ }, []);
44
+ useLayoutEffect(() => {
45
+ const options = {
46
+ alt,
47
+ aspectRatio,
48
+ download,
49
+ editable,
50
+ filename,
51
+ icons,
52
+ labels,
53
+ maxOutputSize,
54
+ output,
55
+ softness,
56
+ src,
57
+ toolbar,
58
+ tools,
59
+ wheelZoom
60
+ };
61
+ instanceRef.current?.setOptions(options);
62
+ }, [
63
+ alt,
64
+ aspectRatio,
65
+ download,
66
+ editable,
67
+ filename,
68
+ icons,
69
+ labels,
70
+ maxOutputSize,
71
+ output,
72
+ softness,
73
+ src,
74
+ toolbar,
75
+ tools,
76
+ wheelZoom
77
+ ]);
78
+ useImperativeHandle(ref, () => instanceRef.current, []);
79
+ return /* @__PURE__ */ jsx("div", {
80
+ ref: hostRef,
81
+ className: className ? `paperpic-host ${className}` : "paperpic-host",
82
+ style
83
+ });
84
+ }
85
+ export { PaperPic };