@koi-br/ocr-web-sdk 1.0.55 → 1.0.57
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-7NzuKZi7.mjs → index--nfCgExV.mjs} +6537 -6519
- package/dist/{index-DzCRrBSn.js → index-ispNX2cb.js} +74 -74
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +2 -2
- package/dist/style.css +1 -1
- package/dist/{tiff.min-BMh2flpF.js → tiff.min-B-7nQrRk.js} +1 -1
- package/dist/{tiff.min-CpubOvNg.mjs → tiff.min-CBNriamS.mjs} +1 -1
- package/package.json +1 -1
- package/preview/ImagePreview.vue +102 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index
|
|
1
|
+
import { g as getAugmentedNamespace, a as getDefaultExportFromCjs } from "./index--nfCgExV.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
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
<div
|
|
106
106
|
ref="containerRef"
|
|
107
107
|
class="image-container"
|
|
108
|
+
:class="{ 'hide-horizontal-scroll': shouldHideHorizontalScroll }"
|
|
108
109
|
@mousedown="startPan"
|
|
109
110
|
@mousemove="pan"
|
|
110
111
|
@mouseup="handleMouseUp"
|
|
@@ -489,6 +490,14 @@ const initialAutoFitScale = ref<number | null>(null); // 记录初始自适应
|
|
|
489
490
|
const isCalculatingAutoFit = ref(false); // 标记是否正在计算自适应宽度(显示 loading)
|
|
490
491
|
const isImageReady = ref(false); // 标记图片是否已准备好显示(自适应宽度计算完成)
|
|
491
492
|
|
|
493
|
+
// 自适应宽度“贴合宽度”时隐藏横向滚动条(避免 transform 带来的 1px 溢出触发横向滚动条)
|
|
494
|
+
// 仅在 scale <= initialAutoFitScale 的阶段生效,不影响用户放大后的横向滚动/拖拽查看逻辑
|
|
495
|
+
const shouldHideHorizontalScroll = computed(() => {
|
|
496
|
+
if (!props.autoFitWidth) return false;
|
|
497
|
+
if (initialAutoFitScale.value === null) return false;
|
|
498
|
+
return scale.value <= initialAutoFitScale.value + 0.001;
|
|
499
|
+
});
|
|
500
|
+
|
|
492
501
|
// 监听图片URL变化,当有新图片时立即隐藏(等待自适应宽度计算)
|
|
493
502
|
watch(
|
|
494
503
|
() => imageUrls.value,
|
|
@@ -650,7 +659,19 @@ const getPageBlocksData = (pageNo: number) => {
|
|
|
650
659
|
|
|
651
660
|
// 计算指定页面缩放后的尺寸(考虑旋转)
|
|
652
661
|
const getPageScaledSize = (pageNo: number) => {
|
|
653
|
-
|
|
662
|
+
// 某些情况下(尤其是多页最后一页)图片尺寸可能还没写入 imageSizes,
|
|
663
|
+
// 此时如果返回 0,会导致 page 容器走 "auto" 高度(未缩放高度),从而出现底部留白。
|
|
664
|
+
// 在自适应宽度模式下,兜底使用第一页尺寸作为基准,保证容器高度按 scale 计算。
|
|
665
|
+
let pageSize = imageSizes.get(pageNo);
|
|
666
|
+
if (
|
|
667
|
+
(!pageSize || pageSize.width === 0 || pageSize.height === 0) &&
|
|
668
|
+
props.autoFitWidth
|
|
669
|
+
) {
|
|
670
|
+
const firstPageSize = imageSizes.get(1);
|
|
671
|
+
if (firstPageSize && firstPageSize.width > 0 && firstPageSize.height > 0) {
|
|
672
|
+
pageSize = firstPageSize;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
654
675
|
if (!pageSize || pageSize.width === 0 || pageSize.height === 0) {
|
|
655
676
|
return { width: 0, height: 0 };
|
|
656
677
|
}
|
|
@@ -693,7 +714,10 @@ const zoom = (delta, isWheel = false) => {
|
|
|
693
714
|
isUserZooming.value = true;
|
|
694
715
|
|
|
695
716
|
const step = isWheel ? props.wheelStep : props.clickStep; // 滚轮缩放使用更小的步长
|
|
717
|
+
const oldScale = scale.value;
|
|
696
718
|
const newScale = scale.value + delta * step;
|
|
719
|
+
|
|
720
|
+
// 更新缩放比例
|
|
697
721
|
if (newScale <= props.minScale) {
|
|
698
722
|
scale.value = props.minScale;
|
|
699
723
|
} else if (newScale >= props.maxScale) {
|
|
@@ -701,6 +725,73 @@ const zoom = (delta, isWheel = false) => {
|
|
|
701
725
|
} else {
|
|
702
726
|
scale.value = newScale;
|
|
703
727
|
}
|
|
728
|
+
|
|
729
|
+
// 缩放后调整位置,确保图片不会超出容器
|
|
730
|
+
// 使用 nextTick 确保 DOM 已更新
|
|
731
|
+
nextTick(() => {
|
|
732
|
+
adjustPositionAfterZoom(oldScale, scale.value);
|
|
733
|
+
});
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* 缩放后调整位置
|
|
738
|
+
* 根据缩放前后的比例,智能调整图片位置,确保:
|
|
739
|
+
* 1. 图片不会超出容器顶部和左侧
|
|
740
|
+
* 2. 在自适应宽度范围内时,保持居中显示
|
|
741
|
+
* 3. 超过自适应宽度时,保持左侧对齐,向右向下扩展/向左向上收缩
|
|
742
|
+
*/
|
|
743
|
+
const adjustPositionAfterZoom = (oldScale: number, newScale: number) => {
|
|
744
|
+
if (!containerRef.value) return;
|
|
745
|
+
|
|
746
|
+
const container = containerRef.value;
|
|
747
|
+
const containerRect = container.getBoundingClientRect();
|
|
748
|
+
const containerWidth = containerRect.width;
|
|
749
|
+
|
|
750
|
+
// 获取当前页的图片尺寸
|
|
751
|
+
const currentPageSize = imageSizes.get(currentPage.value);
|
|
752
|
+
if (!currentPageSize || currentPageSize.width === 0) return;
|
|
753
|
+
|
|
754
|
+
// 计算缩放后的图片宽度(考虑旋转)
|
|
755
|
+
const normalizedRotation = ((rotation.value % 360) + 360) % 360;
|
|
756
|
+
const isRotated = normalizedRotation === 90 || normalizedRotation === 270;
|
|
757
|
+
const imageBaseWidth = isRotated ? currentPageSize.height : currentPageSize.width;
|
|
758
|
+
const newScaledWidth = imageBaseWidth * newScale;
|
|
759
|
+
const oldScaledWidth = imageBaseWidth * oldScale;
|
|
760
|
+
|
|
761
|
+
// 判断是否超过自适应宽度
|
|
762
|
+
const isOverAutoFitWidth = props.autoFitWidth && initialAutoFitScale.value !== null
|
|
763
|
+
? newScale > initialAutoFitScale.value
|
|
764
|
+
: newScaledWidth > containerWidth;
|
|
765
|
+
|
|
766
|
+
if (isOverAutoFitWidth) {
|
|
767
|
+
// 超过自适应宽度:强制左侧对齐,向右扩展/向左收缩
|
|
768
|
+
// 直接计算并设置左侧对齐的位置,确保不会有左侧空白
|
|
769
|
+
|
|
770
|
+
// 由于图片在容器中默认居中(align-items: center)
|
|
771
|
+
// 图片左侧位置 = (容器宽度 - 图片宽度) / 2 + position.x
|
|
772
|
+
// 要使左侧对齐容器左侧(左侧位置 = 0):
|
|
773
|
+
// 0 = (containerWidth - newScaledWidth) / 2 + position.x
|
|
774
|
+
// position.x = -(containerWidth - newScaledWidth) / 2
|
|
775
|
+
|
|
776
|
+
position.value = {
|
|
777
|
+
x: -(containerWidth - newScaledWidth) / 2,
|
|
778
|
+
y: Math.max(0, position.value.y), // 确保顶部不超出
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
// 确保容器滚动位置正确,使图片左上角可见
|
|
782
|
+
requestAnimationFrame(() => {
|
|
783
|
+
if (containerRef.value) {
|
|
784
|
+
containerRef.value.scrollLeft = 0;
|
|
785
|
+
if (position.value.y === 0) {
|
|
786
|
+
containerRef.value.scrollTop = 0;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
} else {
|
|
791
|
+
// 在自适应宽度范围内:保持居中显示,不调整位置
|
|
792
|
+
// position 保持为 { x: 0, y: 0 },图片会自动居中
|
|
793
|
+
// 这里不需要做任何调整,让原有的居中逻辑生效即可
|
|
794
|
+
}
|
|
704
795
|
};
|
|
705
796
|
|
|
706
797
|
const handleWheel = (e: WheelEvent) => {
|
|
@@ -1054,10 +1145,9 @@ const calculateAutoFitScale = () => {
|
|
|
1054
1145
|
return 1;
|
|
1055
1146
|
}
|
|
1056
1147
|
|
|
1057
|
-
|
|
1058
|
-
//
|
|
1059
|
-
|
|
1060
|
-
const containerWidth = containerRect.width - 4;
|
|
1148
|
+
// 使用容器可用内容宽度(clientWidth 不包含滚动条),避免因为纵向滚动条/小数像素导致横向滚动条
|
|
1149
|
+
// 再额外预留 1px,防止浏览器渲染/缩放的舍入误差触发横向滚动条
|
|
1150
|
+
const containerWidth = containerRef.value.clientWidth - 1;
|
|
1061
1151
|
|
|
1062
1152
|
if (containerWidth <= 0) {
|
|
1063
1153
|
console.log(
|
|
@@ -1081,7 +1171,7 @@ const calculateAutoFitScale = () => {
|
|
|
1081
1171
|
return 1;
|
|
1082
1172
|
}
|
|
1083
1173
|
|
|
1084
|
-
//
|
|
1174
|
+
// 计算缩放比例,使图片宽度适应容器宽度(带 1px 安全余量)
|
|
1085
1175
|
const calculatedScale = containerWidth / imageWidth;
|
|
1086
1176
|
const finalScale = Math.max(
|
|
1087
1177
|
props.minScale,
|
|
@@ -2972,6 +3062,12 @@ defineExpose({
|
|
|
2972
3062
|
overflow: auto;
|
|
2973
3063
|
}
|
|
2974
3064
|
|
|
3065
|
+
// 自适应宽度贴合阶段:隐藏横向滚动条(保留纵向滚动)
|
|
3066
|
+
.image-container.hide-horizontal-scroll {
|
|
3067
|
+
overflow-x: hidden;
|
|
3068
|
+
overflow-y: auto;
|
|
3069
|
+
}
|
|
3070
|
+
|
|
2975
3071
|
// 自适应宽度计算 Loading
|
|
2976
3072
|
.auto-fit-loading {
|
|
2977
3073
|
position: absolute;
|