@component-hook/pdf-canvas 1.2.2-alpha.4 → 1.3.0-alpha.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
@@ -62,24 +62,19 @@ async function uploadFile(event: Event) {
62
62
  </script>
63
63
 
64
64
  <template>
65
- <div class="w-fit flex flex-col items-center gap-3">
65
+ <div>
66
66
  <pdf-canvas
67
67
  v-if="currentPdf"
68
68
  :file="currentPdf"
69
69
  />
70
70
 
71
- <p
72
- v-else
73
- class="font-mono text-sm"
74
- >
75
- Please select a PDF file or image.
76
- </p>
71
+ <p v-else>Please select a PDF file or image.</p>
77
72
 
78
73
  <button class="relative">
79
74
  <input
80
75
  type="file"
81
76
  accept="application/pdf, .jpg, .png"
82
- class="opacity-0 top-0 left-0 absolute w-[94px] h-[36px] cursor-pointer"
77
+ class="absolute top-0 left-0 h-[36px] w-[94px] cursor-pointer opacity-0"
83
78
  @change="uploadFile"
84
79
  />
85
80
  select file
@@ -127,6 +122,33 @@ export function DrawPdf() {
127
122
  }
128
123
  ```
129
124
 
125
+ ## ⚠️ Required Vite Configuration
126
+
127
+ If you're using Vite in development mode, you must exclude this package from Vite's dependency optimization, because it internally uses a Web Worker which doesn't work well when Vite pre-bundles dependencies.
128
+
129
+ ```js
130
+ // vite.config.js or vite.config.ts
131
+ import { defineConfig } from 'vite';
132
+
133
+ export default defineConfig({
134
+ // …other Vite config
135
+ optimizeDeps: {
136
+ exclude: ['@component-hook/pdf-canvas'],
137
+ },
138
+ });
139
+ ```
140
+
141
+ ### Why Is This Necessary?
142
+
143
+ - Vite's dev server does pre-bundling of dependencies (using esbuild) to improve performance.
144
+ - However, modules using Web Workers (like this component) may break or fail to initialize correctly during this pre-bundling stage.
145
+
146
+ ### Web Worker & Vite Known Issue
147
+
148
+ - This is a known issue: the Vite team is aware of difficulties when optimizing dependencies that use Web Workers.
149
+ - For more background, see this GitHub issue: [Vite/Rolldown-Vite #362](https://github.com/vitejs/rolldown-vite/issues/362)
150
+ - Once Vite improves its Web Worker optimization, it may become safe to remove this exclusion — but for now, it's required to ensure correct behavior in dev mode.
151
+
130
152
  ## License
131
153
 
132
154
  This project is licensed under the MIT License.
@@ -93,15 +93,21 @@ export declare function loadFile(file: File, password?: string, id?: string): Pr
93
93
  name: string;
94
94
  updateDate: number;
95
95
  PDFBase64: string;
96
+ }> | Promise<{
97
+ pages: number;
98
+ PDFId: string;
99
+ name: string;
100
+ updateDate: number;
101
+ data: ArrayBuffer;
96
102
  } | undefined>;
97
103
 
98
104
  export declare interface PDF {
99
105
  PDFId: string;
100
106
  name: string;
101
107
  updateDate: number;
102
- PDFBase64: string;
108
+ data: ArrayBuffer | string;
103
109
  pages: number;
104
- canvas?: string[];
110
+ canvas?: ArrayBuffer[];
105
111
  trashDate?: number;
106
112
  isUpdate?: boolean;
107
113
  }
@@ -132,7 +138,7 @@ export declare type SelectedEvent = Partial<TEvent> & {
132
138
 
133
139
  export declare interface SpecifyPageArgs {
134
140
  page: number;
135
- PDFBase64: string;
141
+ data: ArrayBuffer;
136
142
  scale: number;
137
143
  password?: string;
138
144
  }
@@ -156,6 +162,12 @@ export declare function useFabric(params?: FabricHookParams & {
156
162
  name: string;
157
163
  updateDate: number;
158
164
  PDFBase64: string;
165
+ }> | Promise<{
166
+ pages: number;
167
+ PDFId: string;
168
+ name: string;
169
+ updateDate: number;
170
+ data: ArrayBuffer;
159
171
  } | undefined>;
160
172
  specifyPage: (specifyPageParams: SpecifyPageArgs) => Promise<number>;
161
173
  renderImage: ({ url, scale }: RenderImageArgs) => Promise<void>;