@koi-br/ocr-web-sdk 1.0.40 → 1.0.42
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-BkDBuqYg.mjs → index-CjNYfaz9.mjs} +8028 -7999
- package/dist/{index-CljhWsvW.js → index-Cr3cYaQd.js} +81 -81
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +2 -2
- package/dist/{tiff.min-CaQgo9oU.js → tiff.min-BnzmCYEC.js} +1 -1
- package/dist/{tiff.min-Cf15IJWV.mjs → tiff.min-CvG4sq3E.mjs} +1 -1
- package/package.json +1 -1
- package/preview/ImagePreview.vue +78 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index-
|
|
1
|
+
import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index-CjNYfaz9.mjs";
|
|
2
2
|
function _mergeNamespaces(U, W) {
|
|
3
3
|
for (var Z = 0; Z < W.length; Z++) {
|
|
4
4
|
const s0 = W[Z];
|
package/package.json
CHANGED
package/preview/ImagePreview.vue
CHANGED
|
@@ -120,13 +120,6 @@
|
|
|
120
120
|
<div v-if="isCalculatingAutoFit && autoFitWidth" class="auto-fit-loading">
|
|
121
121
|
<div class="loading-spinner"></div>
|
|
122
122
|
<div class="loading-text">加载中...</div>
|
|
123
|
-
<!-- 调试信息(开发环境显示) -->
|
|
124
|
-
<div style="font-size: 12px; color: #999; margin-top: 8px; text-align: center;">
|
|
125
|
-
isImageReady: {{ isImageReady }},
|
|
126
|
-
isCalculatingAutoFit: {{ isCalculatingAutoFit }},
|
|
127
|
-
autoFitWidth: {{ autoFitWidth }},
|
|
128
|
-
scale: {{ scale }}
|
|
129
|
-
</div>
|
|
130
123
|
</div>
|
|
131
124
|
|
|
132
125
|
<div
|
|
@@ -444,7 +437,10 @@ const isScrollPaging = ref(false); // 标记是否正在进行滚动翻页
|
|
|
444
437
|
|
|
445
438
|
// ResizeObserver 相关
|
|
446
439
|
let resizeObserver: ResizeObserver | null = null;
|
|
447
|
-
let resizeTimer: any = null; //
|
|
440
|
+
let resizeTimer: any = null; // handleContainerResize 内部的定时器
|
|
441
|
+
let resizeDebounceTimer: any = null; // ResizeObserver 的防抖定时器
|
|
442
|
+
let isResizing = false; // 标记是否正在处理 resize
|
|
443
|
+
let lastContainerWidth = 0; // 记录上次容器宽度,用于判断是否真的变化了
|
|
448
444
|
|
|
449
445
|
// 图片和容器引用
|
|
450
446
|
const containerRef = ref<HTMLElement>();
|
|
@@ -1047,6 +1043,10 @@ const onImageLoad = (event: Event, pageNum: number) => {
|
|
|
1047
1043
|
if (autoScale > 0) {
|
|
1048
1044
|
scale.value = autoScale;
|
|
1049
1045
|
initialAutoFitScale.value = autoScale; // 记录初始自适应缩放比例
|
|
1046
|
+
// 记录当前容器宽度,用于后续 resize 检查
|
|
1047
|
+
if (containerRef.value) {
|
|
1048
|
+
lastContainerWidth = containerRef.value.getBoundingClientRect().width;
|
|
1049
|
+
}
|
|
1050
1050
|
console.log('[ImagePreview] onImageLoad: 缩放比例已设置:', autoScale);
|
|
1051
1051
|
} else {
|
|
1052
1052
|
console.warn('[ImagePreview] onImageLoad: 计算出的缩放比例无效:', autoScale);
|
|
@@ -2384,6 +2384,33 @@ const handleContainerResize = () => {
|
|
|
2384
2384
|
return;
|
|
2385
2385
|
}
|
|
2386
2386
|
|
|
2387
|
+
// 如果正在计算中或正在处理 resize,跳过(避免重复计算)
|
|
2388
|
+
if (isCalculatingAutoFit.value || isResizing) {
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
// 检查容器尺寸是否真的变化了(避免无意义的重复计算)
|
|
2393
|
+
if (containerRef.value) {
|
|
2394
|
+
const currentWidth = containerRef.value.getBoundingClientRect().width;
|
|
2395
|
+
// 如果宽度变化小于 5px,认为是渲染抖动,不处理
|
|
2396
|
+
if (Math.abs(currentWidth - lastContainerWidth) < 5) {
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
lastContainerWidth = currentWidth;
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
console.log('[ImagePreview] handleContainerResize 被调用:', {
|
|
2403
|
+
autoFitWidth: props.autoFitWidth,
|
|
2404
|
+
isUserZooming: isUserZooming.value,
|
|
2405
|
+
isImageReady: isImageReady.value,
|
|
2406
|
+
isCalculatingAutoFit: isCalculatingAutoFit.value,
|
|
2407
|
+
hasFirstPageSize: !!imageSizes.get(1),
|
|
2408
|
+
containerWidth: containerRef.value?.getBoundingClientRect()?.width,
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
// 标记正在处理 resize
|
|
2412
|
+
isResizing = true;
|
|
2413
|
+
|
|
2387
2414
|
// 清除之前的定时器
|
|
2388
2415
|
if (resizeTimer) {
|
|
2389
2416
|
clearTimeout(resizeTimer);
|
|
@@ -2391,31 +2418,46 @@ const handleContainerResize = () => {
|
|
|
2391
2418
|
}
|
|
2392
2419
|
|
|
2393
2420
|
// 隐藏图片,显示 loading
|
|
2421
|
+
console.log('[ImagePreview] handleContainerResize: 开始重新计算');
|
|
2394
2422
|
isImageReady.value = false;
|
|
2395
2423
|
isCalculatingAutoFit.value = true;
|
|
2396
2424
|
|
|
2397
2425
|
// 立即计算并应用新的缩放比例,避免过渡期间露出底色
|
|
2398
2426
|
// 使用 requestAnimationFrame 确保在浏览器重绘前更新
|
|
2399
2427
|
requestAnimationFrame(() => {
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2428
|
+
try {
|
|
2429
|
+
console.log('[ImagePreview] handleContainerResize: 开始计算自适应宽度...');
|
|
2430
|
+
const newScale = calculateAutoFitScale();
|
|
2431
|
+
console.log('[ImagePreview] handleContainerResize: 计算结果:', newScale);
|
|
2432
|
+
|
|
2433
|
+
if (newScale > 0) {
|
|
2434
|
+
// 即使变化很小也立即更新,确保过渡期间图片始终填满容器
|
|
2435
|
+
scale.value = newScale;
|
|
2436
|
+
initialAutoFitScale.value = newScale;
|
|
2437
|
+
}
|
|
2438
|
+
} catch (error) {
|
|
2439
|
+
console.error('[ImagePreview] handleContainerResize: 计算失败:', error);
|
|
2405
2440
|
}
|
|
2406
2441
|
|
|
2407
2442
|
// 在过渡动画完成后再次检查,确保最终状态正确(处理过渡动画期间的连续变化)
|
|
2408
2443
|
resizeTimer = setTimeout(() => {
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
scale.value
|
|
2412
|
-
|
|
2444
|
+
try {
|
|
2445
|
+
const finalScale = calculateAutoFitScale();
|
|
2446
|
+
if (finalScale > 0 && Math.abs(finalScale - scale.value) > 0.01) {
|
|
2447
|
+
scale.value = finalScale;
|
|
2448
|
+
initialAutoFitScale.value = finalScale;
|
|
2449
|
+
}
|
|
2450
|
+
} catch (error) {
|
|
2451
|
+
console.error('[ImagePreview] handleContainerResize: 最终计算失败:', error);
|
|
2452
|
+
} finally {
|
|
2453
|
+
// 计算完成后,显示图片并隐藏 loading
|
|
2454
|
+
console.log('[ImagePreview] handleContainerResize: 更新状态完成');
|
|
2455
|
+
isCalculatingAutoFit.value = false;
|
|
2456
|
+
isResizing = false; // 重置标记
|
|
2457
|
+
requestAnimationFrame(() => {
|
|
2458
|
+
isImageReady.value = true;
|
|
2459
|
+
});
|
|
2413
2460
|
}
|
|
2414
|
-
// 计算完成后,显示图片并隐藏 loading
|
|
2415
|
-
isCalculatingAutoFit.value = false;
|
|
2416
|
-
requestAnimationFrame(() => {
|
|
2417
|
-
isImageReady.value = true;
|
|
2418
|
-
});
|
|
2419
2461
|
}, 350); // 350ms 延迟,略大于过渡动画时间(300ms),确保过渡完成后稳定
|
|
2420
2462
|
});
|
|
2421
2463
|
};
|
|
@@ -2473,11 +2515,17 @@ onMounted(() => {
|
|
|
2473
2515
|
nextTick(() => {
|
|
2474
2516
|
if (containerRef.value && typeof ResizeObserver !== 'undefined') {
|
|
2475
2517
|
resizeObserver = new ResizeObserver((entries) => {
|
|
2476
|
-
//
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
handleContainerResize();
|
|
2518
|
+
// 使用防抖,避免频繁触发
|
|
2519
|
+
if (resizeDebounceTimer) {
|
|
2520
|
+
clearTimeout(resizeDebounceTimer);
|
|
2480
2521
|
}
|
|
2522
|
+
resizeDebounceTimer = setTimeout(() => {
|
|
2523
|
+
// 使用 entries 参数立即获取新尺寸,避免延迟
|
|
2524
|
+
for (const entry of entries) {
|
|
2525
|
+
// 立即响应尺寸变化,避免过渡期间露出底色
|
|
2526
|
+
handleContainerResize();
|
|
2527
|
+
}
|
|
2528
|
+
}, 100); // 100ms 防抖,避免频繁触发
|
|
2481
2529
|
});
|
|
2482
2530
|
resizeObserver.observe(containerRef.value);
|
|
2483
2531
|
} else {
|
|
@@ -2503,6 +2551,10 @@ onBeforeUnmount(() => {
|
|
|
2503
2551
|
clearTimeout(resizeTimer);
|
|
2504
2552
|
resizeTimer = null;
|
|
2505
2553
|
}
|
|
2554
|
+
if (resizeDebounceTimer) {
|
|
2555
|
+
clearTimeout(resizeDebounceTimer);
|
|
2556
|
+
resizeDebounceTimer = null;
|
|
2557
|
+
}
|
|
2506
2558
|
if (resizeObserver) {
|
|
2507
2559
|
resizeObserver.disconnect();
|
|
2508
2560
|
resizeObserver = null;
|