zynx-pdf 0.1.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/README.md +10 -0
- package/dist/components/AnnotationLayer.d.ts +28 -0
- package/dist/components/PdfCanvas.d.ts +13 -0
- package/dist/components/PdfEditor.d.ts +3 -0
- package/dist/components/PropertiesPanel.d.ts +9 -0
- package/dist/components/Toolbar.d.ts +26 -0
- package/dist/hooks/usePdfDocument.d.ts +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/types/annotations.d.ts +85 -0
- package/dist/utils/colors.d.ts +1 -0
- package/dist/utils/coords.d.ts +8 -0
- package/dist/utils/file.d.ts +4 -0
- package/dist/utils/pdfExport.d.ts +2 -0
- package/dist/zynx-pdf.css +2 -0
- package/dist/zynx-pdf.js +1200 -0
- package/dist/zynx-pdf.umd.cjs +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AnnotationPatch, PdfAnnotation, PdfTextItem, PdfTool } from '../types/annotations';
|
|
2
|
+
type PendingImage = {
|
|
3
|
+
type: 'image' | 'signature';
|
|
4
|
+
dataUrl: string;
|
|
5
|
+
} | null;
|
|
6
|
+
type AnnotationLayerProps = {
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
scale: number;
|
|
9
|
+
pageSize: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
annotations: PdfAnnotation[];
|
|
14
|
+
textItems: PdfTextItem[];
|
|
15
|
+
selectedId: string | null;
|
|
16
|
+
tool: PdfTool;
|
|
17
|
+
defaultText: string;
|
|
18
|
+
pendingImage: PendingImage;
|
|
19
|
+
onPendingImageConsumed: () => void;
|
|
20
|
+
onAddAnnotation: (annotation: PdfAnnotation) => void;
|
|
21
|
+
onUpdateAnnotation: (id: string, patch: AnnotationPatch, recordHistory?: boolean) => void;
|
|
22
|
+
onStartHistoryTransaction: () => void;
|
|
23
|
+
onCommitHistoryTransaction: () => void;
|
|
24
|
+
onCancelHistoryTransaction: () => void;
|
|
25
|
+
onSelect: (id: string | null) => void;
|
|
26
|
+
};
|
|
27
|
+
export declare function AnnotationLayer(props: AnnotationLayerProps): import("react").JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PdfTextItem } from '../types/annotations';
|
|
2
|
+
type PdfCanvasProps = {
|
|
3
|
+
pdfDocument: any;
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
scale: number;
|
|
6
|
+
onPageSizeChange: (size: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}) => void;
|
|
10
|
+
onTextItemsChange?: (items: PdfTextItem[]) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function PdfCanvas({ pdfDocument, pageIndex, scale, onPageSizeChange, onTextItemsChange }: PdfCanvasProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnnotationPatch, PdfAnnotation } from '../types/annotations';
|
|
2
|
+
type PropertiesPanelProps = {
|
|
3
|
+
annotation: PdfAnnotation | null;
|
|
4
|
+
onUpdate: (id: string, patch: AnnotationPatch, recordHistory?: boolean) => void;
|
|
5
|
+
onDelete: () => void;
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function PropertiesPanel({ annotation, onUpdate, onDelete, onClose }: PropertiesPanelProps): import("react").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PdfTool } from '../types/annotations';
|
|
2
|
+
type ToolbarProps = {
|
|
3
|
+
tool: PdfTool;
|
|
4
|
+
scale: number;
|
|
5
|
+
pageIndex: number;
|
|
6
|
+
pageCount: number;
|
|
7
|
+
defaultText: string;
|
|
8
|
+
canExport: boolean;
|
|
9
|
+
canUndo: boolean;
|
|
10
|
+
canRedo: boolean;
|
|
11
|
+
enableUpload: boolean;
|
|
12
|
+
onToolChange: (tool: PdfTool) => void;
|
|
13
|
+
onScaleChange: (scale: number) => void;
|
|
14
|
+
onPageChange: (pageIndex: number) => void;
|
|
15
|
+
onDefaultTextChange: (text: string) => void;
|
|
16
|
+
onUploadPdf: (file: File) => void;
|
|
17
|
+
onUploadImage: (file: File, type: 'image' | 'signature') => void;
|
|
18
|
+
onDeleteSelected: () => void;
|
|
19
|
+
onUndo: () => void;
|
|
20
|
+
onRedo: () => void;
|
|
21
|
+
onExport: () => void;
|
|
22
|
+
selectedId?: string | null;
|
|
23
|
+
};
|
|
24
|
+
declare function fileToDataUrl(file: File): Promise<string>;
|
|
25
|
+
export declare function Toolbar(props: ToolbarProps): import("react").JSX.Element;
|
|
26
|
+
export { fileToDataUrl };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function usePdfDocument(initialFile?: string | ArrayBuffer | Uint8Array | File | null): {
|
|
2
|
+
loadPdf: (source: string | ArrayBuffer | Uint8Array | File) => Promise<void>;
|
|
3
|
+
pdfDocument: any | null;
|
|
4
|
+
originalBytes: Uint8Array | null;
|
|
5
|
+
pageCount: number;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PdfEditor } from './components/PdfEditor';
|
|
2
|
+
export { Toolbar } from './components/Toolbar';
|
|
3
|
+
export { AnnotationLayer } from './components/AnnotationLayer';
|
|
4
|
+
export { PdfCanvas } from './components/PdfCanvas';
|
|
5
|
+
export type { PdfAnnotation, PdfEditorProps, PdfEditorTheme, PdfPoint, PdfTool, TextAnnotation, TextReplaceAnnotation, PdfTextItem, HighlightAnnotation, ImageAnnotation, DrawAnnotation } from './types/annotations';
|
|
6
|
+
export { exportPdfWithAnnotations } from './utils/pdfExport';
|
|
7
|
+
export { downloadBytes } from './utils/file';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export type PdfTool = 'select' | 'replaceText' | 'text' | 'highlight' | 'draw' | 'image' | 'signature';
|
|
2
|
+
export type PdfPoint = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export type PdfTextItem = {
|
|
7
|
+
id: string;
|
|
8
|
+
pageIndex: number;
|
|
9
|
+
str: string;
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
fontSize: number;
|
|
15
|
+
};
|
|
16
|
+
export type BaseAnnotation = {
|
|
17
|
+
id: string;
|
|
18
|
+
pageIndex: number;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export type TextAnnotation = BaseAnnotation & {
|
|
25
|
+
type: 'text';
|
|
26
|
+
text: string;
|
|
27
|
+
fontSize: number;
|
|
28
|
+
color: string;
|
|
29
|
+
};
|
|
30
|
+
export type TextReplaceAnnotation = BaseAnnotation & {
|
|
31
|
+
type: 'text-replace';
|
|
32
|
+
originalText: string;
|
|
33
|
+
text: string;
|
|
34
|
+
fontSize: number;
|
|
35
|
+
color: string;
|
|
36
|
+
backgroundColor: string;
|
|
37
|
+
};
|
|
38
|
+
export type HighlightAnnotation = BaseAnnotation & {
|
|
39
|
+
type: 'highlight';
|
|
40
|
+
color: string;
|
|
41
|
+
opacity: number;
|
|
42
|
+
};
|
|
43
|
+
export type ImageAnnotation = BaseAnnotation & {
|
|
44
|
+
type: 'image' | 'signature';
|
|
45
|
+
dataUrl: string;
|
|
46
|
+
};
|
|
47
|
+
export type DrawAnnotation = BaseAnnotation & {
|
|
48
|
+
type: 'draw';
|
|
49
|
+
points: PdfPoint[];
|
|
50
|
+
color: string;
|
|
51
|
+
strokeWidth: number;
|
|
52
|
+
};
|
|
53
|
+
export type PdfAnnotation = TextAnnotation | TextReplaceAnnotation | HighlightAnnotation | ImageAnnotation | DrawAnnotation;
|
|
54
|
+
export type AnnotationPatch = Partial<{
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
text: string;
|
|
60
|
+
originalText: string;
|
|
61
|
+
fontSize: number;
|
|
62
|
+
color: string;
|
|
63
|
+
backgroundColor: string;
|
|
64
|
+
opacity: number;
|
|
65
|
+
dataUrl: string;
|
|
66
|
+
points: PdfPoint[];
|
|
67
|
+
strokeWidth: number;
|
|
68
|
+
}>;
|
|
69
|
+
export type PdfEditorTheme = {
|
|
70
|
+
primary?: string;
|
|
71
|
+
background?: string;
|
|
72
|
+
surface?: string;
|
|
73
|
+
border?: string;
|
|
74
|
+
text?: string;
|
|
75
|
+
};
|
|
76
|
+
export type PdfEditorProps = {
|
|
77
|
+
file?: string | ArrayBuffer | Uint8Array | File | null;
|
|
78
|
+
height?: string | number;
|
|
79
|
+
defaultScale?: number;
|
|
80
|
+
enableUpload?: boolean;
|
|
81
|
+
showDevJson?: boolean;
|
|
82
|
+
theme?: PdfEditorTheme;
|
|
83
|
+
onSave?: (pdfBytes: Uint8Array, annotations: PdfAnnotation[]) => void;
|
|
84
|
+
onAnnotationsChange?: (annotations: PdfAnnotation[]) => void;
|
|
85
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hexToRgb01(hex: string): import("pdf-lib").RGB;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PointerEvent as ReactPointerEvent } from 'react';
|
|
2
|
+
export declare function screenToPdfCoordinate(value: number, scale: number): number;
|
|
3
|
+
export declare function pdfToScreenCoordinate(value: number, scale: number): number;
|
|
4
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
5
|
+
export declare function getPointerPositionInElement(event: ReactPointerEvent<HTMLElement>, element: HTMLElement): {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function inputFileToArrayBuffer(file: File): Promise<ArrayBuffer>;
|
|
2
|
+
export declare function uint8ArrayFromSource(source: ArrayBuffer | Uint8Array): Uint8Array;
|
|
3
|
+
export declare function downloadBytes(bytes: Uint8Array, filename: string): void;
|
|
4
|
+
export declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
:root{font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.mpe-root{--mpe-primary:#6d5dfc;--mpe-primary-dark:#28245f;--mpe-primary-soft:#f1efff;--mpe-background:#f6f3ff;--mpe-surface:#fff;--mpe-border:#e4def8;--mpe-text:#16142f;--mpe-muted:#746f91;--mpe-shadow:0 24px 70px #32238c2e;background:radial-gradient(circle at top left, #8168ff29, transparent 28%), linear-gradient(135deg, #fbf9ff 0%, var(--mpe-background) 42%, #eeeaff 100%);color:var(--mpe-text);box-shadow:var(--mpe-shadow);border:1px solid #6d5dfc24;border-radius:24px;flex-direction:column;display:flex;overflow:hidden}.mpe-root *{box-sizing:border-box}.mpe-toolbar{-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);z-index:20;background:#ffffffdb;border-bottom:1px solid #6d5dfc21;align-items:center;gap:14px;min-height:78px;padding:12px 14px;display:flex;position:relative}.mpe-toolbar__brand{align-items:center;gap:11px;min-width:210px;padding-right:4px;display:flex}.mpe-toolbar__logo{color:#fff;letter-spacing:.02em;background:linear-gradient(135deg,#7c5cff,#382d8e);border-radius:14px;place-items:center;width:42px;height:42px;font-size:12px;font-weight:900;display:grid;box-shadow:0 14px 30px #5c4acf3d}.mpe-toolbar__brand strong,.mpe-toolbar__brand small{display:block}.mpe-toolbar__brand strong{letter-spacing:-.01em;font-size:14px}.mpe-toolbar__brand small{max-width:280px;color:var(--mpe-muted);margin-top:2px;font-size:11px;line-height:1.35}.mpe-toolbar__section{align-items:center;gap:7px;min-width:0;display:flex}.mpe-toolbar__section--view{background:#f6f3ffb8;border:1px solid #6d5dfc24;border-radius:18px;padding:8px}.mpe-toolbar__section--edit{scrollbar-width:thin;flex:1;justify-content:center;overflow-x:auto}.mpe-toolbar__section--actions{margin-left:auto}.mpe-button,.mpe-tool-button,.mpe-icon-button{color:var(--mpe-text);cursor:pointer;-webkit-user-select:none;user-select:none;white-space:nowrap;background:#fff;border:1px solid #6d5dfc29;border-radius:13px;justify-content:center;align-items:center;gap:7px;min-height:38px;padding:9px 11px;font-size:12px;font-weight:800;transition:transform .14s,border-color .14s,background .14s,box-shadow .14s;display:inline-flex}.mpe-button:hover:not(:disabled),.mpe-tool-button:hover:not(:disabled),.mpe-icon-button:hover:not(:disabled){border-color:#6d5dfc73;transform:translateY(-1px);box-shadow:0 10px 24px #4d39b41f}.mpe-button:disabled,.mpe-tool-button:disabled,.mpe-icon-button:disabled{opacity:.45;cursor:not-allowed;box-shadow:none;transform:none}.mpe-button--primary,.mpe-tool-button--active{color:#fff;background:linear-gradient(135deg,#7c5cff,#5140d7);border-color:#0000;box-shadow:0 14px 26px #5c4acf38}.mpe-button--save{padding-inline:14px}.mpe-button--danger{color:#b91c1c;background:#fff7f7;border-color:#dc262629}.mpe-icon-button{width:38px;padding:0}.mpe-icon-button--ghost{width:32px;min-height:32px;box-shadow:none;background:0 0;border-radius:10px}.mpe-page-chip{text-align:center;min-width:66px;color:var(--mpe-primary-dark);background:#fff;border:1px solid #6d5dfc24;border-radius:999px;padding:8px 10px;font-size:12px;font-weight:900}.mpe-editor-shell{flex:1;grid-template-rows:auto minmax(0,1fr);min-height:0;display:grid;position:relative}.mpe-editor-hint{min-height:40px;color:var(--mpe-muted);text-align:center;background:#ffffff80;border-bottom:1px solid #6d5dfc1a;justify-content:center;align-items:center;gap:12px;padding:8px 14px;font-size:12px;display:flex}.mpe-editor-hint strong{color:var(--mpe-primary-dark)}.mpe-stage{background:linear-gradient(90deg,#7a68ff0e 1px,#0000 1px) 0 0/32px 32px,linear-gradient(#7a68ff0e 1px,#0000 1px) 0 0/32px 32px,radial-gradient(circle at 50% 0,#fffffff2,#f4f0ffd9 42%,#e8e2ffe6);justify-content:center;align-items:flex-start;min-height:0;padding:34px;display:flex;overflow:auto}.mpe-page-shell{background:#fff;border-radius:10px;flex:none;position:relative;overflow:hidden;box-shadow:0 28px 80px #1c175240}.mpe-page-canvas{background:#fff;display:block}.mpe-render-badge,.mpe-render-error{z-index:6;border-radius:999px;max-width:calc(100% - 24px);padding:8px 10px;font-size:12px;font-weight:800;position:absolute;top:12px;left:12px}.mpe-render-badge{color:#fff;background:#1f194edb}.mpe-render-error{color:#b91c1c;background:#fff1f2;border:1px solid #fecaca}.mpe-annotation-layer{touch-action:none;z-index:3;position:absolute;inset:0;overflow:hidden}.mpe-annotation-layer--text,.mpe-annotation-layer--highlight,.mpe-annotation-layer--image,.mpe-annotation-layer--signature,.mpe-annotation-layer--replaceText{cursor:crosshair}.mpe-annotation-layer--draw{cursor:cell}.mpe-annotation-layer--select{cursor:default}.mpe-text-target{z-index:2;color:#0000;cursor:text;background:#6d5dfc0f;border:1px dashed #6d5dfc6b;border-radius:3px;margin:0;padding:0;position:absolute}.mpe-text-target span{opacity:0;pointer-events:none}.mpe-text-target:hover{background:#6d5dfc2e;border-color:#6d5dfcc7;box-shadow:0 0 0 2px #6d5dfc21}.mpe-annotation{box-sizing:border-box;cursor:move;-webkit-user-select:none;user-select:none;z-index:4;border-radius:4px;position:absolute}.mpe-annotation--selected{box-shadow:0 0 0 4px #6d5dfc26}.mpe-annotation--editing{cursor:text}.mpe-annotation-text,.mpe-annotation-replacement{width:100%;height:100%}.mpe-annotation-text{white-space:pre-wrap;pointer-events:none;justify-content:flex-start;align-items:flex-start;font-weight:650;line-height:1.15;display:flex;overflow:hidden}.mpe-annotation-replacement{border-radius:2px;padding:1px 2px;overflow:hidden}.mpe-annotation-highlight{pointer-events:none;border-radius:4px;width:100%;height:100%}.mpe-annotation-image{object-fit:contain;pointer-events:none;width:100%;height:100%}.mpe-annotation-ink{pointer-events:none;position:absolute;inset:0;overflow:visible}.mpe-annotation-textarea{resize:none;width:100%;height:100%;font:inherit;white-space:pre-wrap;pointer-events:auto;border:0;border-radius:3px;outline:0;margin:0;padding:2px;font-weight:650;line-height:1.15;display:block;overflow:auto}.mpe-resize-handle{background:var(--mpe-primary);cursor:nwse-resize;border:2px solid #fff;border-radius:999px;width:13px;height:13px;position:absolute;bottom:-7px;right:-7px;box-shadow:0 5px 14px #1e185047}.mpe-floating-inspector{z-index:30;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);background:#fffffff5;border:1px solid #6d5dfc29;border-radius:20px;width:min(320px,100% - 36px);padding:14px;position:absolute;top:58px;right:18px;box-shadow:0 22px 60px #23196e2e}.mpe-inspector-head{justify-content:space-between;align-items:center;gap:10px;margin-bottom:12px;display:flex}.mpe-inspector-head span,.mpe-inspector-head strong{display:block}.mpe-inspector-head span{color:var(--mpe-muted);text-transform:uppercase;letter-spacing:.08em;font-size:11px;font-weight:800}.mpe-inspector-head strong{margin-top:2px;font-size:14px}.mpe-inspector-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;display:grid}.mpe-inspector-grid--position{margin-top:10px}.mpe-inspector-field{color:var(--mpe-muted);gap:6px;margin-bottom:10px;font-size:11px;font-weight:900;display:grid}.mpe-inspector-field--full{grid-column:1/-1}.mpe-inspector-field input,.mpe-inspector-field textarea{border:1px solid var(--mpe-border);width:100%;font:inherit;color:var(--mpe-text);background:#fff;border-radius:12px;outline:none;padding:9px 10px;font-size:13px}.mpe-inspector-field input:focus,.mpe-inspector-field textarea:focus{border-color:#6d5dfcb3;box-shadow:0 0 0 3px #6d5dfc1f}.mpe-inspector-field textarea{resize:vertical}.mpe-original-text-note{background:var(--mpe-primary-soft);color:var(--mpe-muted);border-radius:12px;margin:-2px 0 10px;padding:8px 10px;font-size:11px;line-height:1.35}.mpe-original-text-note span{color:var(--mpe-primary-dark);font-weight:800}.mpe-inspector-preview{object-fit:contain;border:1px solid var(--mpe-border);background:#faf9ff;border-radius:14px;width:100%;max-height:160px;margin-bottom:10px}.mpe-inspector-delete{width:100%;margin-top:10px}.mpe-dev-drawer{z-index:25;background:#fffffff0;border:1px solid #6d5dfc29;border-radius:16px;width:min(420px,100% - 36px);max-height:300px;padding:10px 12px;position:absolute;bottom:18px;left:18px;overflow:auto;box-shadow:0 18px 40px #23196e24}.mpe-dev-drawer summary{cursor:pointer;color:var(--mpe-primary-dark);font-weight:900}.mpe-dev-drawer pre{white-space:pre-wrap;word-break:break-word;font-size:11px}.mpe-empty-state,.mpe-error{text-align:center;background:#fffffff0;border:1px solid #6d5dfc24;border-radius:28px;width:min(620px,100%);margin:70px auto;padding:34px;box-shadow:0 24px 60px #23196e24}.mpe-empty-icon{color:#fff;background:linear-gradient(135deg,#7c5cff,#382d8e);border-radius:22px;place-items:center;width:66px;height:66px;margin:0 auto 16px;font-weight:900;display:grid;box-shadow:0 14px 30px #5c4acf38}.mpe-empty-state h2{letter-spacing:-.03em;margin:0 0 8px;font-size:clamp(24px,4vw,34px)}.mpe-empty-state p{max-width:480px;color:var(--mpe-muted);margin:0 auto 18px;line-height:1.58}.mpe-error{color:#b91c1c;background:#fff1f2;border-color:#fecaca}@media (width<=1280px){.mpe-toolbar{flex-wrap:wrap}.mpe-toolbar__brand{min-width:100%}.mpe-toolbar__section--edit{order:3;justify-content:flex-start;width:100%}}@media (width<=780px){.mpe-root{border-radius:18px}.mpe-toolbar{gap:10px}.mpe-toolbar__section--view,.mpe-toolbar__section--actions{width:100%;overflow-x:auto}.mpe-toolbar__section--actions{justify-content:flex-start}.mpe-stage{justify-content:flex-start;padding:16px}.mpe-editor-hint{text-align:left;flex-direction:column;align-items:flex-start}.mpe-floating-inspector{width:auto;top:52px;left:12px;right:12px}}
|
|
2
|
+
/*$vite$:1*/
|