@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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/docs/examples/custom-toolbar.md +211 -0
- package/dist/docs/examples/fixed-proportions.md +120 -0
- package/dist/docs/examples/read-only.md +115 -0
- package/dist/docs/examples/upload.md +130 -0
- package/dist/docs/guide/accessibility.md +55 -0
- package/dist/docs/guide/editing.md +140 -0
- package/dist/docs/guide/getting-started.md +144 -0
- package/dist/docs/guide/introduction.md +36 -0
- package/dist/docs/guide/labels.md +120 -0
- package/dist/docs/guide/performance.md +39 -0
- package/dist/docs/guide/saving.md +186 -0
- package/dist/docs/guide/styling.md +266 -0
- package/dist/docs/guide/tools/adjust.md +41 -0
- package/dist/docs/guide/tools/clean-up.md +41 -0
- package/dist/docs/guide/tools/crop.md +39 -0
- package/dist/docs/guide/tools/rotate-and-flip.md +35 -0
- package/dist/docs/guide/tools/straighten.md +78 -0
- package/dist/docs/guide/viewer.md +81 -0
- package/dist/docs/reference/css-tokens.md +113 -0
- package/dist/docs/reference/events.md +68 -0
- package/dist/docs/reference/labels.md +70 -0
- package/dist/docs/reference/methods.md +228 -0
- package/dist/docs/reference/options.md +160 -0
- package/dist/docs/reference/react.md +84 -0
- package/dist/docs/reference/state.md +30 -0
- package/dist/docs/reference/types.md +301 -0
- package/dist/docs/reference/vue.md +78 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +85 -0
- package/dist/style.css +702 -0
- package/package.json +62 -3
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 };
|