@ibiz-template-plugin/ibiz-file-previewer 0.0.10 → 0.0.12
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.es.js +95 -21
- package/dist/index.legacy.js +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1170,13 +1170,27 @@ const fileNameToFileType = (fileName) => {
|
|
|
1170
1170
|
return fileType;
|
|
1171
1171
|
};
|
|
1172
1172
|
const throttle = (func, wait) => {
|
|
1173
|
-
let
|
|
1173
|
+
let timeoutId = null;
|
|
1174
|
+
let lastCallTime = 0;
|
|
1174
1175
|
return (...args) => {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1176
|
+
const now = Date.now();
|
|
1177
|
+
const remaining = wait - (now - lastCallTime);
|
|
1178
|
+
if (remaining <= 0) {
|
|
1179
|
+
lastCallTime = now;
|
|
1180
|
+
if (timeoutId) {
|
|
1181
|
+
clearTimeout(timeoutId);
|
|
1182
|
+
timeoutId = null;
|
|
1183
|
+
}
|
|
1184
|
+
func.apply(void 0, args);
|
|
1185
|
+
} else {
|
|
1186
|
+
if (timeoutId) {
|
|
1187
|
+
clearTimeout(timeoutId);
|
|
1188
|
+
}
|
|
1189
|
+
timeoutId = setTimeout(() => {
|
|
1190
|
+
lastCallTime = Date.now();
|
|
1191
|
+
timeoutId = null;
|
|
1192
|
+
func.apply(void 0, args);
|
|
1193
|
+
}, remaining);
|
|
1180
1194
|
}
|
|
1181
1195
|
};
|
|
1182
1196
|
};
|
|
@@ -18402,15 +18416,17 @@ const ThumbnailPanel = (props) => {
|
|
|
18402
18416
|
const ImagePage = (props) => {
|
|
18403
18417
|
const isLoading = useSignal(true);
|
|
18404
18418
|
const imgRef = A(null);
|
|
18405
|
-
const
|
|
18419
|
+
const [parentDimensions, setParentDimensions] = d$2({
|
|
18406
18420
|
width: 0,
|
|
18407
18421
|
height: 0
|
|
18408
18422
|
});
|
|
18423
|
+
const prevDimensions = A({ width: 0, height: 0 });
|
|
18409
18424
|
const imgStyle = useComputed(() => {
|
|
18410
18425
|
let result = {};
|
|
18426
|
+
const { width, height } = parentDimensions;
|
|
18411
18427
|
if (isLoading.value) {
|
|
18412
18428
|
result = {
|
|
18413
|
-
height: "".concat(
|
|
18429
|
+
height: "".concat(height * props.state.value.scale, "px"),
|
|
18414
18430
|
flexShrink: 0
|
|
18415
18431
|
};
|
|
18416
18432
|
} else {
|
|
@@ -18420,11 +18436,11 @@ const ImagePage = (props) => {
|
|
|
18420
18436
|
};
|
|
18421
18437
|
if (props.state.value.mode === ImageMode.WIDTH) {
|
|
18422
18438
|
Object.assign(result, {
|
|
18423
|
-
width: "".concat((
|
|
18439
|
+
width: "".concat((width - 24 - 6) * props.state.value.scale, "px")
|
|
18424
18440
|
});
|
|
18425
18441
|
} else if (props.state.value.mode === ImageMode.PAGE) {
|
|
18426
18442
|
Object.assign(result, {
|
|
18427
|
-
height: "".concat(
|
|
18443
|
+
height: "".concat(height * props.state.value.scale, "px")
|
|
18428
18444
|
});
|
|
18429
18445
|
} else {
|
|
18430
18446
|
Object.assign(result, {
|
|
@@ -18445,14 +18461,20 @@ const ImagePage = (props) => {
|
|
|
18445
18461
|
var _a, _b;
|
|
18446
18462
|
const rect = (_b = (_a = imgRef.current) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.getBoundingClientRect();
|
|
18447
18463
|
if (!rect) return;
|
|
18448
|
-
|
|
18449
|
-
|
|
18450
|
-
|
|
18451
|
-
|
|
18464
|
+
const newWidth = Math.round(rect.width);
|
|
18465
|
+
const newHeight = Math.round(rect.height);
|
|
18466
|
+
if (prevDimensions.current.width !== newWidth || prevDimensions.current.height !== newHeight) {
|
|
18467
|
+
prevDimensions.current = { width: newWidth, height: newHeight };
|
|
18468
|
+
setParentDimensions({ width: newWidth, height: newHeight });
|
|
18469
|
+
}
|
|
18452
18470
|
};
|
|
18453
18471
|
y$1(() => {
|
|
18454
18472
|
updateParentStyle();
|
|
18455
|
-
const observer = new ResizeObserver(
|
|
18473
|
+
const observer = new ResizeObserver(() => {
|
|
18474
|
+
requestAnimationFrame(() => {
|
|
18475
|
+
updateParentStyle();
|
|
18476
|
+
});
|
|
18477
|
+
});
|
|
18456
18478
|
if (imgRef.current) {
|
|
18457
18479
|
if (imgRef.current.parentElement) {
|
|
18458
18480
|
observer.observe(imgRef.current.parentElement);
|
|
@@ -18501,7 +18523,12 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18501
18523
|
const containerRect = contentRef.current.getBoundingClientRect();
|
|
18502
18524
|
let closestPage = state.value.currentPage;
|
|
18503
18525
|
let minDistance = Infinity;
|
|
18504
|
-
|
|
18526
|
+
const checkRangeStart = Math.max(0, closestPage - 200);
|
|
18527
|
+
const checkRangeEnd = Math.min(
|
|
18528
|
+
state.value.items.length - 1,
|
|
18529
|
+
closestPage + 200
|
|
18530
|
+
);
|
|
18531
|
+
for (let index = checkRangeStart; index <= checkRangeEnd; index++) {
|
|
18505
18532
|
const pageElement = contentRef.current.querySelector(
|
|
18506
18533
|
'[data-page-index="'.concat(index, '"]')
|
|
18507
18534
|
);
|
|
@@ -18513,7 +18540,7 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18513
18540
|
closestPage = index;
|
|
18514
18541
|
}
|
|
18515
18542
|
}
|
|
18516
|
-
}
|
|
18543
|
+
}
|
|
18517
18544
|
return closestPage;
|
|
18518
18545
|
}
|
|
18519
18546
|
};
|
|
@@ -18524,7 +18551,7 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18524
18551
|
controller.updateState({ currentPage: closestPage });
|
|
18525
18552
|
}
|
|
18526
18553
|
}
|
|
18527
|
-
},
|
|
18554
|
+
}, 200);
|
|
18528
18555
|
const handleImageResize = () => {
|
|
18529
18556
|
if (contentRef.current) {
|
|
18530
18557
|
setTimeout(() => {
|
|
@@ -18554,16 +18581,57 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18554
18581
|
}
|
|
18555
18582
|
});
|
|
18556
18583
|
};
|
|
18584
|
+
let updateIsScrollingTimer;
|
|
18557
18585
|
const updateIsScrolling = () => {
|
|
18558
18586
|
isScrolling.value = true;
|
|
18559
|
-
|
|
18587
|
+
if (updateIsScrollingTimer) {
|
|
18588
|
+
clearTimeout(updateIsScrollingTimer);
|
|
18589
|
+
}
|
|
18590
|
+
updateIsScrollingTimer = setTimeout(() => {
|
|
18560
18591
|
isScrolling.value = false;
|
|
18561
18592
|
}, 1e3);
|
|
18562
18593
|
};
|
|
18594
|
+
const MAX_ATTEMPTS = 30;
|
|
18595
|
+
const STABLE_THRESHOLD = 2;
|
|
18596
|
+
let requestAnimationFrameId;
|
|
18597
|
+
const scrollToPageWhenStable = (pageIndex) => {
|
|
18598
|
+
let lastTop = null;
|
|
18599
|
+
let stableCount = 0;
|
|
18600
|
+
let attempt = 0;
|
|
18601
|
+
const tryScroll = () => {
|
|
18602
|
+
const container = contentRef.current;
|
|
18603
|
+
if (!container) return;
|
|
18604
|
+
const pageElement = container.querySelector(
|
|
18605
|
+
'[data-page-index="'.concat(pageIndex, '"]')
|
|
18606
|
+
);
|
|
18607
|
+
if (!pageElement) return;
|
|
18608
|
+
const rect = pageElement.getBoundingClientRect();
|
|
18609
|
+
if (rect.height > 0) {
|
|
18610
|
+
if (lastTop !== null && Math.abs(rect.top - lastTop) < 1) {
|
|
18611
|
+
stableCount++;
|
|
18612
|
+
} else {
|
|
18613
|
+
stableCount = 0;
|
|
18614
|
+
}
|
|
18615
|
+
lastTop = rect.top;
|
|
18616
|
+
if (stableCount >= STABLE_THRESHOLD) {
|
|
18617
|
+
scrollToPage(pageIndex);
|
|
18618
|
+
updateIsScrolling();
|
|
18619
|
+
return;
|
|
18620
|
+
}
|
|
18621
|
+
}
|
|
18622
|
+
attempt++;
|
|
18623
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
18624
|
+
requestAnimationFrameId = requestAnimationFrame(tryScroll);
|
|
18625
|
+
} else {
|
|
18626
|
+
scrollToPage(pageIndex);
|
|
18627
|
+
updateIsScrolling();
|
|
18628
|
+
}
|
|
18629
|
+
};
|
|
18630
|
+
requestAnimationFrameId = requestAnimationFrame(tryScroll);
|
|
18631
|
+
};
|
|
18563
18632
|
const handlePageClick = (pageIndex) => {
|
|
18564
18633
|
controller.updateState({ currentPage: pageIndex });
|
|
18565
|
-
|
|
18566
|
-
updateIsScrolling();
|
|
18634
|
+
scrollToPageWhenStable(pageIndex);
|
|
18567
18635
|
};
|
|
18568
18636
|
const handleInput = (e2) => {
|
|
18569
18637
|
const target = e2.target;
|
|
@@ -18602,6 +18670,12 @@ const FilePreviewImageGroup = (props) => {
|
|
|
18602
18670
|
return () => {
|
|
18603
18671
|
var _a;
|
|
18604
18672
|
(_a = contentRef.current) == null ? void 0 : _a.removeEventListener("scroll", handleScroll);
|
|
18673
|
+
if (updateIsScrollingTimer) {
|
|
18674
|
+
clearTimeout(updateIsScrollingTimer);
|
|
18675
|
+
}
|
|
18676
|
+
if (requestAnimationFrameId) {
|
|
18677
|
+
cancelAnimationFrame(requestAnimationFrameId);
|
|
18678
|
+
}
|
|
18605
18679
|
};
|
|
18606
18680
|
}, []);
|
|
18607
18681
|
return /* @__PURE__ */ u("div", { className: "file-preview-image-group", children: [
|