@component-hook/pdf-canvas 1.1.0-alpha.8 → 1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @component-hook/pdf-canvas
2
2
 
3
- Rendering PDF documents onto a canvas with vue3 and react component ([DEMO](https://tzuyi0817.github.io/component-hook/#/component/vue-pdf-canvas))
3
+ Rendering PDF documents onto a canvas with `vue3` and `react` component.
4
4
  Implementation depository: [PDF-signature](https://github.com/tzuyi0817/PDF-signature)
5
5
 
6
6
  <p>
@@ -18,28 +18,34 @@ Implementation depository: [PDF-signature](https://github.com/tzuyi0817/PDF-sign
18
18
  - Open encrypted PDF files
19
19
  - Drag and drop the images and text onto the canvas
20
20
  - Manually add the images and text onto the canvas
21
- - Supports typescript
21
+ - Full `TypeScript` support
22
+
23
+ ## Documentation
24
+
25
+ For detailed documentation and usage examples, please visit: [Official Docs](https://tzuyi0817.github.io/component-hook/#/component/vue-pdf-canvas).
22
26
 
23
27
  ## Installation
24
28
 
25
29
  ```bash
30
+ # Using npm
26
31
  $ npm install @component-hook/pdf-canvas
27
32
 
28
- # or use yarn
33
+ # Using yarn
29
34
  $ yarn add @component-hook/pdf-canvas
30
35
 
31
- # or use pnpm
36
+ # Using pnpm
32
37
  $ pnpm install @component-hook/pdf-canvas
33
38
  ```
34
39
 
35
- ## Usage with Vue
40
+ ## Base Usage
41
+
42
+ ### Vue3
36
43
 
37
44
  ```vue
38
45
  <script setup lang="ts">
46
+ import PdfCanvas, { loadFile, type PDF } from '@component-hook/pdf-canvas/vue';
39
47
  import { ref } from 'vue';
40
- import PdfCanvas, { useFabric, type PDF } from '@component-hook/pdf-canvas/vue';
41
48
 
42
- const { loadFile } = useFabric();
43
49
  const currentPdf = ref<PDF>();
44
50
 
45
51
  async function uploadFile(event: Event) {
@@ -82,14 +88,13 @@ async function uploadFile(event: Event) {
82
88
  </template>
83
89
  ```
84
90
 
85
- ## Usage with React
91
+ ### React
86
92
 
87
93
  ```tsx
94
+ import PdfCanvas, { loadFile, type PDF } from '@component-hook/pdf-canvas/react';
88
95
  import { useState, type ChangeEvent } from 'react';
89
- import PdfCanvas, { useFabric, type PDF } from '@component-hook/pdf-canvas/react';
90
96
 
91
97
  export function DrawPdf() {
92
- const { loadFile } = useFabric();
93
98
  const [currentPdf, setCurrentPdf] = useState<PDF>();
94
99
 
95
100
  const uploadFile = async (event: ChangeEvent<HTMLInputElement>) => {
@@ -122,34 +127,6 @@ export function DrawPdf() {
122
127
  }
123
128
  ```
124
129
 
125
- ## Attributes
126
-
127
- | Name | Required | Type | Description | Default |
128
- | ---------------- | -------- | --------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
129
- | file | true | `PDF` | The data is generated by loadFile of useFabric hook | — |
130
- | page | false | `number` | The page number you want to display | 1 |
131
- | canvasId | false | `string` | Canvas dom prefix id selector - `${canvasId}-${page - 1}` | PDF-canvas |
132
- | fileZoom | false | `number` | Zoom in and out of the displayed canvas | 1 |
133
- | fileScale | false | `number` | The actual size of the canvas will affect the display clarity | 1 |
134
- | canvasClass | false | `string` | Canvas dom class selector | — |
135
- | isDrop | false | `boolean` | Control whether to drag and drop images and text onto the canvas | false |
136
- | password | false | `string` | Open password for encrypted PDF files | — |
137
- | dropTextOptions | false | `object` | [fabric.js FabricText options](https://github.com/fabricjs/fabric.js) | [text options](https://github.com/tzuyi0817/component-hook/blob/master/packages/pdf-canvas/src/shared/configs/index.ts) |
138
- | dropImageOptions | false | `object` | [fabric.js FabricImage options](https://github.com/fabricjs/fabric.js) | [image options](https://github.com/tzuyi0817/component-hook/blob/master/packages/pdf-canvas/src/shared/configs/index.ts) |
139
- | closeSvgOptions | false | `object` | Setup close svg options | [close options](https://github.com/tzuyi0817/component-hook/blob/master/packages/pdf-canvas/src/shared/configs/index.ts) |
140
-
141
- ## Exposes
142
-
143
- | Event | Description | Type |
144
- | :----------- | :-------------------------------------- | :--------------------------------------------------------------- |
145
- | addImage | Manually add the images onto the canvas | `Function (src: string, options?: TOptions<ImageProps>) => void` |
146
- | addText | Manually add the text onto the canvas | `Function (text: string, options?: TOptions<TextProps>) => void` |
147
- | clearActive | Manually deactivate status | `Function () => void` |
148
- | deleteCanvas | Delete the current canvas | `Function () => void` |
149
- | canvasRef | The current canvas dom ref | `object Ref<HTMLCanvasElement>` |
150
-
151
- ## UseFabric
152
-
153
- | Event | Description | Type |
154
- | :------- | :--------------------- | :------------------------------------------------------- |
155
- | loadFile | Load PDF file or image | `Function (file: File, password?: string): Promise<PDF>` |
130
+ ## License
131
+
132
+ This project is licensed under the MIT License.
@@ -26,9 +26,19 @@ declare interface CacheProperties {
26
26
  }
27
27
 
28
28
  export declare interface CloseSvgOptions {
29
- stroke: string;
30
- hoverStroke: string;
31
- src: string;
29
+ stroke?: string;
30
+ hoverStroke?: string;
31
+ src?: string;
32
+ }
33
+
34
+ declare interface ComponentEmits {
35
+ onLoaded?: () => void;
36
+ onReload?: () => void;
37
+ onPointerDown?: (event: FabricPointerEvent) => void;
38
+ onPointerMove?: (event: FabricPointerEvent) => void;
39
+ onPointerUp?: (event: FabricPointerEvent) => void;
40
+ onSelectionCreated?: (event: FabricSelectionCreatedEvent) => void;
41
+ onSelectionCleared?: (event: FabricSelectionClearedEvent) => void;
32
42
  }
33
43
 
34
44
  export declare interface ComponentProps {
@@ -63,10 +73,28 @@ export declare interface FabricHookParams {
63
73
  pointerDown?: (event: FabricPointerEvent) => void;
64
74
  pointerMove?: (event: FabricPointerEvent) => void;
65
75
  pointerUp?: (event: FabricPointerEvent) => void;
76
+ selectionCreated?: (event: FabricSelectionCreatedEvent) => void;
77
+ selectionCleared?: (event: FabricSelectionClearedEvent) => void;
66
78
  }
67
79
 
68
80
  export declare type FabricPointerEvent = TPointerEventInfo<TPointerEvent>;
69
81
 
82
+ export declare type FabricSelectionClearedEvent = Partial<TEvent<TPointerEvent>> & {
83
+ deselected: FabricObject[];
84
+ };
85
+
86
+ export declare type FabricSelectionCreatedEvent = Partial<TEvent<TPointerEvent>> & {
87
+ selected: FabricObject[];
88
+ };
89
+
90
+ export declare function loadFile(file: File, password?: string, id?: string): Promise<{
91
+ pages: number;
92
+ PDFId: string;
93
+ name: string;
94
+ updateDate: number;
95
+ PDFBase64: string;
96
+ } | undefined>;
97
+
70
98
  export declare interface PDF {
71
99
  PDFId: string;
72
100
  name: string;
@@ -78,14 +106,17 @@ export declare interface PDF {
78
106
  isUpdate?: boolean;
79
107
  }
80
108
 
81
- declare const PdfCanvas: ForwardRefExoticComponent<ComponentProps & RefAttributes<PdfCanvasHandle>>;
109
+ declare const PdfCanvas: ForwardRefExoticComponent<ComponentProps & ComponentEmits & RefAttributes<PdfCanvasHandle>>;
82
110
  export default PdfCanvas;
83
111
 
84
112
  export declare interface PdfCanvasHandle {
113
+ reload: () => Promise<void>;
85
114
  addImage: (src: string, options?: TOptions<ImageProps>) => void;
86
115
  addText: (text: string, options?: TOptions<TextProps>) => void;
87
116
  clearActive: () => void;
88
117
  deleteCanvas: () => void;
118
+ copyActiveFabric: () => Promise<void>;
119
+ deleteActiveFabric: () => void;
89
120
  canvasRef: React.RefObject<HTMLCanvasElement>;
90
121
  }
91
122
 
@@ -114,7 +145,9 @@ export declare interface TCornerPoint {
114
145
  br: Point;
115
146
  }
116
147
 
117
- export declare function useFabric(id?: string): {
148
+ export declare function useFabric(params?: FabricHookParams & {
149
+ selectionOptions?: TOptions<FabricObjectProps>;
150
+ }): {
118
151
  createCanvas: () => Canvas | undefined;
119
152
  loadFile: (file: File, password?: string) => Promise<{
120
153
  pages: number;
@@ -123,14 +156,16 @@ export declare function useFabric(id?: string): {
123
156
  updateDate: number;
124
157
  PDFBase64: string;
125
158
  } | undefined>;
126
- specifyPage: ({ page, PDFBase64, scale, password }: SpecifyPageArgs) => Promise<void>;
159
+ specifyPage: (specifyPageParams: SpecifyPageArgs) => Promise<number>;
127
160
  renderImage: ({ url, scale }: RenderImageArgs) => Promise<void>;
128
- addFabric: (src: string, options?: TOptions<ImageProps>) => Promise<void>;
129
- addTextFabric: (text: string, options?: TOptions<TextProps>) => void;
161
+ addFabric: (src: string, options?: TOptions<ImageProps>, offset?: DropOffset) => Promise<void>;
162
+ addTextFabric: (text: string, options?: TOptions<TextProps>, offset?: DropOffset) => void;
130
163
  clearActive: () => void;
131
164
  deleteCanvas: () => void;
132
165
  scaleFabric: (scale: number, isCreate?: boolean) => void;
133
166
  setCloseSvgOptions: (options?: CloseSvgOptions) => void;
167
+ copyActiveFabric: () => Promise<void>;
168
+ deleteActiveFabric: () => void;
134
169
  };
135
170
 
136
171
  export { }