@koi-br/ocr-web-sdk 1.0.18 → 1.0.20
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-pXgfT7RF.js → index-CBQ568pM.js} +68 -68
- package/dist/{index-Kl8JZvac.mjs → index-WSXL-n78.mjs} +3894 -3880
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +2 -2
- package/dist/{tiff.min-Cf9JfAI8.mjs → tiff.min-B-Qg8e2o.mjs} +1 -1
- package/dist/{tiff.min-Dw94LHXi.js → tiff.min-CgtwxxRj.js} +1 -1
- package/package.json +4 -3
- package/preview/PdfPreview.vue +1 -0
- package/preview/index.vue +3 -2
- package/preview/tifPreview.vue +35 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koi-br/ocr-web-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "一个支持多种Office文件格式预览的Vue3组件SDK,包括PDF、Word、Excel、图片、OFD、TIF等格式",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"private": false,
|
|
19
19
|
"author": "chunyu.ma",
|
|
20
20
|
"publishConfig": {
|
|
21
|
-
"access": "public"
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
@@ -59,4 +60,4 @@
|
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"vue": "^3.0.0"
|
|
61
62
|
}
|
|
62
|
-
}
|
|
63
|
+
}
|
package/preview/PdfPreview.vue
CHANGED
package/preview/index.vue
CHANGED
|
@@ -203,7 +203,7 @@ const onLoadCallback = ref(null);
|
|
|
203
203
|
const getFileType = (fileName = '') => {
|
|
204
204
|
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
205
205
|
if (ext === 'pdf') return 'pdf';
|
|
206
|
-
if (['tif'].includes(ext)) return 'tif';
|
|
206
|
+
if (['tif', 'tiff'].includes(ext)) return 'tif';
|
|
207
207
|
if (['ofd'].includes(ext)) return 'ofd';
|
|
208
208
|
if (['docx'].includes(ext)) return 'docx';
|
|
209
209
|
if (['xlsx'].includes(ext)) return 'xlsx';
|
|
@@ -229,7 +229,8 @@ const getMimeType = (fileName = '') => {
|
|
|
229
229
|
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
230
230
|
const mimeTypes = {
|
|
231
231
|
pdf: 'application/pdf',
|
|
232
|
-
tif: 'image/
|
|
232
|
+
tif: 'image/tiff',
|
|
233
|
+
tiff: 'image/tiff',
|
|
233
234
|
docx: 'application/docx',
|
|
234
235
|
jpg: 'image/jpeg',
|
|
235
236
|
jpeg: 'image/jpeg',
|
package/preview/tifPreview.vue
CHANGED
|
@@ -327,6 +327,40 @@ const loadTiff = async () => {
|
|
|
327
327
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
328
328
|
}
|
|
329
329
|
const arrayBuffer = await response.arrayBuffer();
|
|
330
|
+
// 验证文件大小
|
|
331
|
+
if (arrayBuffer.byteLength === 0) {
|
|
332
|
+
throw new Error('文件为空或无法读取');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 验证文件实际格式
|
|
336
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
337
|
+
const isValidTiff =
|
|
338
|
+
(uint8Array[0] === 0x49 && uint8Array[1] === 0x49) || // Little-endian TIFF
|
|
339
|
+
(uint8Array[0] === 0x4d && uint8Array[1] === 0x4d); // Big-endian TIFF
|
|
340
|
+
|
|
341
|
+
// 检测是否为 JPEG 格式 (0xFF 0xD8)
|
|
342
|
+
const isJpeg = uint8Array[0] === 0xff && uint8Array[1] === 0xd8;
|
|
343
|
+
// 检测是否为 PNG 格式 (0x89 0x50 0x4E 0x47)
|
|
344
|
+
const isPng =
|
|
345
|
+
uint8Array[0] === 0x89 &&
|
|
346
|
+
uint8Array[1] === 0x50 &&
|
|
347
|
+
uint8Array[2] === 0x4e &&
|
|
348
|
+
uint8Array[3] === 0x47;
|
|
349
|
+
|
|
350
|
+
// 如果不是 TIFF 格式,但是常见的图片格式,直接使用图片预览
|
|
351
|
+
if (!isValidTiff && (isJpeg || isPng)) {
|
|
352
|
+
const blob = new Blob([arrayBuffer], {
|
|
353
|
+
type: isJpeg ? 'image/jpeg' : 'image/png'
|
|
354
|
+
});
|
|
355
|
+
imgDataUrl.value = URL.createObjectURL(blob);
|
|
356
|
+
error.value = '';
|
|
357
|
+
emit('load', {
|
|
358
|
+
width: 0,
|
|
359
|
+
height: 0
|
|
360
|
+
});
|
|
361
|
+
isLoading.value = false;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
330
364
|
|
|
331
365
|
// 创建TIFF实例
|
|
332
366
|
// tiff.js 的 Tiff 是一个构造函数,需要使用 new 关键字
|
|
@@ -382,7 +416,7 @@ const loadTiff = async () => {
|
|
|
382
416
|
|
|
383
417
|
// 图片加载成功回调
|
|
384
418
|
const onImageLoad = () => {
|
|
385
|
-
|
|
419
|
+
// 图片加载成功
|
|
386
420
|
};
|
|
387
421
|
|
|
388
422
|
// 图片加载失败回调
|