@koi-br/ocr-web-sdk 1.0.33 → 1.0.35
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-xK8ReDUk.js → index-CKWQDPoP.js} +80 -80
- package/dist/{index-BW-AkzYU.mjs → index-Dx9CNRoV.mjs} +7297 -7276
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +2 -2
- package/dist/{tiff.min-C53DgzT0.mjs → tiff.min-B8vWRefT.mjs} +1 -1
- package/dist/{tiff.min-CEQg_SyY.js → tiff.min-D5eSYpnb.js} +1 -1
- package/package.json +1 -1
- package/preview/ImagePreview.vue +75 -0
package/package.json
CHANGED
package/preview/ImagePreview.vue
CHANGED
|
@@ -396,6 +396,10 @@ const isUserZooming = ref(false); // 标记用户是否主动缩放
|
|
|
396
396
|
let scrollPagingTimer: any = null;
|
|
397
397
|
const isScrollPaging = ref(false); // 标记是否正在进行滚动翻页
|
|
398
398
|
|
|
399
|
+
// ResizeObserver 相关
|
|
400
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
401
|
+
let resizeTimer: any = null; // 防抖定时器
|
|
402
|
+
|
|
399
403
|
// 图片和容器引用
|
|
400
404
|
const containerRef = ref<HTMLElement>();
|
|
401
405
|
const imageRefs = new Map<number, HTMLImageElement>();
|
|
@@ -2203,6 +2207,48 @@ watch(
|
|
|
2203
2207
|
{ deep: true }
|
|
2204
2208
|
);
|
|
2205
2209
|
|
|
2210
|
+
/**
|
|
2211
|
+
* 处理容器尺寸变化,重新计算自适应缩放比例
|
|
2212
|
+
*/
|
|
2213
|
+
const handleContainerResize = () => {
|
|
2214
|
+
// 如果禁用了自适应宽度,或者用户主动缩放过,不自动调整
|
|
2215
|
+
if (!props.autoFitWidth || isUserZooming.value) {
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// 如果第一页图片还没有加载完成,不处理
|
|
2220
|
+
const firstPageSize = imageSizes.get(1);
|
|
2221
|
+
if (!firstPageSize || firstPageSize.width === 0) {
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
// 清除之前的定时器
|
|
2226
|
+
if (resizeTimer) {
|
|
2227
|
+
clearTimeout(resizeTimer);
|
|
2228
|
+
resizeTimer = null;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// 立即计算并应用新的缩放比例,避免过渡期间露出底色
|
|
2232
|
+
// 使用 requestAnimationFrame 确保在浏览器重绘前更新
|
|
2233
|
+
requestAnimationFrame(() => {
|
|
2234
|
+
const newScale = calculateAutoFitScale();
|
|
2235
|
+
if (newScale > 0) {
|
|
2236
|
+
// 即使变化很小也立即更新,确保过渡期间图片始终填满容器
|
|
2237
|
+
scale.value = newScale;
|
|
2238
|
+
initialAutoFitScale.value = newScale;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
// 在过渡动画完成后再次检查,确保最终状态正确(处理过渡动画期间的连续变化)
|
|
2242
|
+
resizeTimer = setTimeout(() => {
|
|
2243
|
+
const finalScale = calculateAutoFitScale();
|
|
2244
|
+
if (finalScale > 0 && Math.abs(finalScale - scale.value) > 0.01) {
|
|
2245
|
+
scale.value = finalScale;
|
|
2246
|
+
initialAutoFitScale.value = finalScale;
|
|
2247
|
+
}
|
|
2248
|
+
}, 350); // 350ms 延迟,略大于过渡动画时间(300ms),确保过渡完成后稳定
|
|
2249
|
+
});
|
|
2250
|
+
};
|
|
2251
|
+
|
|
2206
2252
|
/**
|
|
2207
2253
|
* 组件挂载时的初始化
|
|
2208
2254
|
*/
|
|
@@ -2225,6 +2271,23 @@ onMounted(() => {
|
|
|
2225
2271
|
});
|
|
2226
2272
|
}
|
|
2227
2273
|
}
|
|
2274
|
+
|
|
2275
|
+
// 监听容器尺寸变化(用于响应外部收起/展开操作)
|
|
2276
|
+
nextTick(() => {
|
|
2277
|
+
if (containerRef.value && typeof ResizeObserver !== 'undefined') {
|
|
2278
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
2279
|
+
// 使用 entries 参数立即获取新尺寸,避免延迟
|
|
2280
|
+
for (const entry of entries) {
|
|
2281
|
+
// 立即响应尺寸变化,避免过渡期间露出底色
|
|
2282
|
+
handleContainerResize();
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
resizeObserver.observe(containerRef.value);
|
|
2286
|
+
} else {
|
|
2287
|
+
// 降级方案:监听窗口大小变化
|
|
2288
|
+
window.addEventListener('resize', handleContainerResize);
|
|
2289
|
+
}
|
|
2290
|
+
});
|
|
2228
2291
|
});
|
|
2229
2292
|
|
|
2230
2293
|
/**
|
|
@@ -2239,6 +2302,16 @@ onBeforeUnmount(() => {
|
|
|
2239
2302
|
clearTimeout(scrollPagingTimer);
|
|
2240
2303
|
scrollPagingTimer = null;
|
|
2241
2304
|
}
|
|
2305
|
+
if (resizeTimer) {
|
|
2306
|
+
clearTimeout(resizeTimer);
|
|
2307
|
+
resizeTimer = null;
|
|
2308
|
+
}
|
|
2309
|
+
if (resizeObserver) {
|
|
2310
|
+
resizeObserver.disconnect();
|
|
2311
|
+
resizeObserver = null;
|
|
2312
|
+
}
|
|
2313
|
+
// 移除窗口 resize 监听器(降级方案)
|
|
2314
|
+
window.removeEventListener('resize', handleContainerResize);
|
|
2242
2315
|
});
|
|
2243
2316
|
|
|
2244
2317
|
defineExpose({
|
|
@@ -2317,6 +2390,8 @@ defineExpose({
|
|
|
2317
2390
|
margin: 0;
|
|
2318
2391
|
padding: 0;
|
|
2319
2392
|
line-height: 0;
|
|
2393
|
+
// 添加平滑过渡,避免切换时露出底色
|
|
2394
|
+
transition: transform 0.3s ease;
|
|
2320
2395
|
|
|
2321
2396
|
img {
|
|
2322
2397
|
display: block; // 移除图片底部默认间隙
|