@koi-br/ocr-web-sdk 1.0.33 → 1.0.34

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.
@@ -1,4 +1,4 @@
1
- import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index-BW-AkzYU.mjs";
1
+ import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index-DXnzd_-3.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koi-br/ocr-web-sdk",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "一个支持多种Office文件格式预览的Vue3组件SDK,包括PDF、Word、Excel、图片、OFD、TIF等格式",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -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,35 @@ 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
+ }
2229
+
2230
+ resizeTimer = setTimeout(() => {
2231
+ const newScale = calculateAutoFitScale();
2232
+ if (newScale > 0 && Math.abs(newScale - scale.value) > 0.01) {
2233
+ scale.value = newScale;
2234
+ initialAutoFitScale.value = newScale;
2235
+ }
2236
+ }, 150); // 150ms 防抖延迟
2237
+ };
2238
+
2206
2239
  /**
2207
2240
  * 组件挂载时的初始化
2208
2241
  */
@@ -2225,6 +2258,19 @@ onMounted(() => {
2225
2258
  });
2226
2259
  }
2227
2260
  }
2261
+
2262
+ // 监听容器尺寸变化(用于响应外部收起/展开操作)
2263
+ nextTick(() => {
2264
+ if (containerRef.value && typeof ResizeObserver !== 'undefined') {
2265
+ resizeObserver = new ResizeObserver(() => {
2266
+ handleContainerResize();
2267
+ });
2268
+ resizeObserver.observe(containerRef.value);
2269
+ } else {
2270
+ // 降级方案:监听窗口大小变化
2271
+ window.addEventListener('resize', handleContainerResize);
2272
+ }
2273
+ });
2228
2274
  });
2229
2275
 
2230
2276
  /**
@@ -2239,6 +2285,16 @@ onBeforeUnmount(() => {
2239
2285
  clearTimeout(scrollPagingTimer);
2240
2286
  scrollPagingTimer = null;
2241
2287
  }
2288
+ if (resizeTimer) {
2289
+ clearTimeout(resizeTimer);
2290
+ resizeTimer = null;
2291
+ }
2292
+ if (resizeObserver) {
2293
+ resizeObserver.disconnect();
2294
+ resizeObserver = null;
2295
+ }
2296
+ // 移除窗口 resize 监听器(降级方案)
2297
+ window.removeEventListener('resize', handleContainerResize);
2242
2298
  });
2243
2299
 
2244
2300
  defineExpose({