@koi-br/ocr-web-sdk 1.0.47 → 1.0.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koi-br/ocr-web-sdk",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "一个支持多种Office文件格式预览的Vue3组件SDK,包括PDF、Word、Excel、图片、OFD、TIF等格式",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -360,11 +360,6 @@ const props = defineProps({
360
360
  type: Boolean,
361
361
  default: true, // 默认不显示,保持向后兼容(isDownload 的默认值)
362
362
  },
363
- // 是否启用文本块的 hover 效果(高亮和显示批注按钮)
364
- enableBlockHover: {
365
- type: Boolean,
366
- default: true,
367
- },
368
363
  });
369
364
 
370
365
  const emit = defineEmits<{
@@ -381,6 +376,7 @@ const emit = defineEmits<{
381
376
  "annotation-add": [annotation: AnnotationInfo]; // 添加批注事件
382
377
  "annotation-update": [annotation: AnnotationInfo]; // 更新批注事件
383
378
  "annotation-delete": [annotationId: string]; // 删除批注事件
379
+ "highlight-clear": []; // 高亮清除事件(用于清除连接线)
384
380
  }>();
385
381
 
386
382
  // 图片URL数组和当前页码
@@ -873,12 +869,18 @@ const switchToPage = (page: number) => {
873
869
  showAnnotationPopup.value = false;
874
870
  currentAnnotationBlock.value = null;
875
871
  annotationInput.value = "";
872
+ const hadHighlight = isHighlighted.value && activeBlockDiv.value !== null;
876
873
  activeBlockDiv.value = null;
877
874
  isHighlighted.value = false;
878
875
 
879
876
  // 更新页码
880
877
  currentPage.value = page;
881
878
 
879
+ // 如果之前有高亮,触发高亮清除事件
880
+ if (hadHighlight) {
881
+ emit("highlight-clear");
882
+ }
883
+
882
884
  // 触发页码变化事件
883
885
  emit("page-change", page, totalPages.value);
884
886
 
@@ -922,9 +924,15 @@ const reset = () => {
922
924
  showAnnotationPopup.value = false;
923
925
  currentAnnotationBlock.value = null;
924
926
  annotationInput.value = "";
927
+ const hadHighlight = isHighlighted.value && activeBlockDiv.value !== null;
925
928
  activeBlockDiv.value = null;
926
929
  isHighlighted.value = false;
927
930
 
931
+ // 如果之前有高亮,触发高亮清除事件
932
+ if (hadHighlight) {
933
+ emit("highlight-clear");
934
+ }
935
+
928
936
  // 清除已渲染页面集合
929
937
  renderedPages.value.clear();
930
938
  };
@@ -1282,11 +1290,6 @@ const renderTextLayer = (pageNum?: number) => {
1282
1290
 
1283
1291
  // Hover 和点击事件
1284
1292
  blockDiv.addEventListener("mouseenter", (e) => {
1285
- // 如果禁用了 hover 效果,不执行相关逻辑
1286
- if (!props.enableBlockHover) {
1287
- return;
1288
- }
1289
-
1290
1293
  // 取消之前的隐藏定时器
1291
1294
  if (hideTimer) {
1292
1295
  clearTimeout(hideTimer);
@@ -1332,10 +1335,6 @@ const renderTextLayer = (pageNum?: number) => {
1332
1335
  });
1333
1336
 
1334
1337
  blockDiv.addEventListener("mouseleave", () => {
1335
- // 如果禁用了 hover 效果,不执行隐藏逻辑
1336
- if (!props.enableBlockHover) {
1337
- return;
1338
- }
1339
1338
  // 延迟隐藏,给用户时间移动到批注按钮
1340
1339
  hideAnnotationButton();
1341
1340
  });
@@ -1950,7 +1949,8 @@ const saveAnnotation = () => {
1950
1949
 
1951
1950
  const annotation: AnnotationInfo = {
1952
1951
  id:
1953
- existingAnnotation?.id || "",
1952
+ existingAnnotation?.id ||
1953
+ `annotation_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1954
1954
  blockBbox: bbox,
1955
1955
  blockContent: content,
1956
1956
  blockPage: currentPage.value,
@@ -1965,7 +1965,7 @@ const saveAnnotation = () => {
1965
1965
  } else {
1966
1966
  // 添加新批注
1967
1967
  emit("annotation-add", annotation);
1968
- // Message.success("批注已添加");
1968
+ Message.success("批注已添加");
1969
1969
  }
1970
1970
 
1971
1971
  // 关闭输入框
@@ -2157,6 +2157,7 @@ const highlightPosition = (
2157
2157
  highlightStyle?: HighlightStyle
2158
2158
  ): boolean => {
2159
2159
  // 清除之前的高亮
2160
+ const hadHighlight = activeBlockDiv.value !== null && isHighlighted.value;
2160
2161
  if (activeBlockDiv.value) {
2161
2162
  activeBlockDiv.value.style.backgroundColor = "transparent";
2162
2163
  activeBlockDiv.value.style.boxShadow = "none";
@@ -2164,6 +2165,11 @@ const highlightPosition = (
2164
2165
  activeBlockDiv.value = null;
2165
2166
  }
2166
2167
  isHighlighted.value = false;
2168
+
2169
+ // 如果之前有高亮,触发高亮清除事件
2170
+ if (hadHighlight) {
2171
+ emit("highlight-clear");
2172
+ }
2167
2173
 
2168
2174
  // 如果页码不在有效范围内,返回 false
2169
2175
  if (pageNum < 1 || pageNum > totalPages.value) {
@@ -2270,6 +2276,8 @@ const highlightPosition = (
2270
2276
  elementRef.style.border = "none";
2271
2277
  activeBlockDiv.value = null;
2272
2278
  isHighlighted.value = false;
2279
+ // 触发高亮清除事件,用于清除连接线
2280
+ emit("highlight-clear");
2273
2281
  }
2274
2282
  }, 5000);
2275
2283
 
@@ -2584,6 +2592,34 @@ onBeforeUnmount(() => {
2584
2592
  window.removeEventListener('resize', handleContainerResize);
2585
2593
  });
2586
2594
 
2595
+ // 获取当前高亮位置信息(用于连接线功能)
2596
+ const getCurrentPosition = () => {
2597
+ if (!activeBlockDiv.value || !containerRef.value) {
2598
+ return null;
2599
+ }
2600
+
2601
+ const bboxStr = activeBlockDiv.value.dataset.bbox;
2602
+ if (!bboxStr) {
2603
+ return null;
2604
+ }
2605
+
2606
+ try {
2607
+ const bbox = JSON.parse(bboxStr) as [number, number, number, number];
2608
+ const pageStr = activeBlockDiv.value.dataset.page;
2609
+ const pageNum = pageStr ? parseInt(pageStr, 10) : currentPage.value;
2610
+
2611
+ return {
2612
+ pageNum,
2613
+ bbox,
2614
+ element: activeBlockDiv.value,
2615
+ container: containerRef.value,
2616
+ };
2617
+ } catch (error) {
2618
+ console.error("解析 bbox 失败:", error);
2619
+ return null;
2620
+ }
2621
+ };
2622
+
2587
2623
  defineExpose({
2588
2624
  reset,
2589
2625
  jumpToPosition, // 暴露定位方法给父组件
@@ -2591,6 +2627,7 @@ defineExpose({
2591
2627
  getCurrentPage: () => currentPage.value, // 获取当前页码
2592
2628
  getTotalPages: () => totalPages.value, // 获取总页数
2593
2629
  getContainer: () => containerRef.value, // 暴露容器引用,用于同步滚动
2630
+ getCurrentPosition, // 获取当前高亮位置信息(用于连接线功能)
2594
2631
  });
2595
2632
  </script>
2596
2633
 
package/preview/index.vue CHANGED
@@ -53,6 +53,7 @@
53
53
  @annotation-add="handleAnnotationAdd"
54
54
  @annotation-update="handleAnnotationUpdate"
55
55
  @annotation-delete="handleAnnotationDelete"
56
+ @highlight-clear="$emit('highlight-clear')"
56
57
  >
57
58
  <template #left-top>
58
59
  <slot name="left-top"></slot>
@@ -141,7 +142,7 @@ import DocxPreview from './docxPreview.vue';
141
142
  import XLSXPreview from './xlsxPreview.vue';
142
143
 
143
144
  // 定义 emits
144
- const emit = defineEmits(['load', 'annotation-add', 'annotation-update', 'annotation-delete']);
145
+ const emit = defineEmits(['load', 'annotation-add', 'annotation-update', 'annotation-delete', 'highlight-clear']);
145
146
 
146
147
  // 定义 props
147
148
  const props = defineProps({