@ibiz-template-plugin/ibiz-file-previewer 0.0.12 → 0.0.14

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 CHANGED
@@ -151,7 +151,7 @@ function O(n2, u2, t2, i2, o2, r2, e2, f2, c2, s2) {
151
151
  else u2.__e = t2.__e, u2.__k = t2.__k, n3.then || z$1(u2);
152
152
  l$3.__e(n3, u2, t2);
153
153
  }
154
- else null == r2 && u2.__v == t2.__v ? (u2.__k = t2.__k, u2.__e = t2.__e) : f2 = u2.__e = q$2(t2.__e, u2, t2, i2, o2, r2, e2, c2, s2);
154
+ else null == r2 && u2.__v == t2.__v ? (u2.__k = t2.__k, u2.__e = t2.__e) : f2 = u2.__e = q$1(t2.__e, u2, t2, i2, o2, r2, e2, c2, s2);
155
155
  return (a2 = l$3.diffed) && a2(u2), 128 & u2.__u ? void 0 : f2;
156
156
  }
157
157
  function z$1(n2) {
@@ -172,7 +172,7 @@ function N$1(n2, u2, t2) {
172
172
  function V$1(n2) {
173
173
  return "object" != typeof n2 || null == n2 || n2.__b && n2.__b > 0 ? n2 : d$3(n2) ? n2.map(V$1) : w$2({}, n2);
174
174
  }
175
- function q$2(u2, t2, i2, o2, r2, e2, f2, c2, s2) {
175
+ function q$1(u2, t2, i2, o2, r2, e2, f2, c2, s2) {
176
176
  var a2, h2, v2, y2, w2, _2, m2, b2 = i2.props || p$3, k2 = t2.props, x2 = t2.type;
177
177
  if ("svg" == x2 ? r2 = "http://www.w3.org/2000/svg" : "math" == x2 ? r2 = "http://www.w3.org/1998/Math/MathML" : r2 || (r2 = "http://www.w3.org/1999/xhtml"), null != e2) {
178
178
  for (a2 = 0; a2 < e2.length; a2++) if ((w2 = e2[a2]) && "setAttribute" in w2 == !!x2 && (x2 ? w2.localName == x2 : 3 == w2.nodeType)) {
@@ -303,11 +303,6 @@ function T$1(n2, r2) {
303
303
  var u2 = p$2(t$1++, 7);
304
304
  return C(u2.__H, r2) && (u2.__ = n2(), u2.__H = r2, u2.__h = n2), u2.__;
305
305
  }
306
- function q$1(n2, t2) {
307
- return o$1 = 8, T$1(function() {
308
- return n2;
309
- }, t2);
310
- }
311
306
  function j$1() {
312
307
  for (var n2; n2 = f$2.shift(); ) if (n2.__P && n2.__H) try {
313
308
  n2.__H.__h.forEach(z), n2.__H.__h.forEach(B$1), n2.__H.__h = [];
@@ -18309,27 +18304,35 @@ const ThumbnailPanel = (props) => {
18309
18304
  const [loadStates, setLoadStates] = d$2({});
18310
18305
  const ITEM_HEIGHT = 188;
18311
18306
  const BUFFER_COUNT = 1;
18312
- const [cachedImages, setCachedImages] = d$2(/* @__PURE__ */ new Set());
18307
+ const phantomHeight = props.pages.length * ITEM_HEIGHT;
18313
18308
  const [visibleRange, setVisibleRange] = d$2({ start: 0, end: 0 });
18314
- const calculateVisibleRange = q$1(() => {
18309
+ const [itemContainerOffsetY, setItemContainerOffsetY] = d$2(8);
18310
+ const calculateVisibleRange = (mode = "UI") => {
18315
18311
  if (!contentRef.current) return { start: 0, end: 0 };
18316
18312
  const container = contentRef.current;
18317
18313
  const scrollTop = container.scrollTop;
18318
18314
  const containerHeight = container.clientHeight;
18319
- const start = Math.max(
18320
- 0,
18321
- Math.floor(scrollTop / ITEM_HEIGHT) - BUFFER_COUNT
18322
- );
18315
+ let start = 0;
18316
+ if (mode === "UI") {
18317
+ start = Math.max(0, Math.floor(scrollTop / ITEM_HEIGHT) - BUFFER_COUNT);
18318
+ } else {
18319
+ start = Math.max(0, props.currentPage - BUFFER_COUNT);
18320
+ }
18323
18321
  const visibleCount = Math.ceil(containerHeight / ITEM_HEIGHT);
18324
18322
  const end = Math.min(
18325
18323
  props.pages.length,
18326
18324
  start + visibleCount + BUFFER_COUNT
18327
18325
  );
18328
18326
  return { start, end };
18329
- }, [props.pages.length]);
18330
- const updateVisibleRange = q$1(() => {
18331
- setVisibleRange(calculateVisibleRange());
18332
- }, [calculateVisibleRange]);
18327
+ };
18328
+ const updateVisibleRange = (mode) => {
18329
+ const range = calculateVisibleRange(mode);
18330
+ setItemContainerOffsetY(range.start * ITEM_HEIGHT + 8);
18331
+ setVisibleRange(range);
18332
+ };
18333
+ const throttleUpdateRange = throttle(() => {
18334
+ updateVisibleRange();
18335
+ }, 500);
18333
18336
  const handleClick = (index, _event) => {
18334
18337
  props.onPageClick(index);
18335
18338
  };
@@ -18346,84 +18349,110 @@ const ThumbnailPanel = (props) => {
18346
18349
  }
18347
18350
  }
18348
18351
  };
18349
- const handleImageLoad = (index) => {
18352
+ const handleImageLoad = (page) => {
18350
18353
  setLoadStates((prevState) => ({
18351
18354
  ...prevState,
18352
- [index]: true
18355
+ [page.image_url]: true
18353
18356
  }));
18354
- setCachedImages((prev) => new Set(prev).add(index));
18355
18357
  };
18356
- const handleImageError = (index, error2) => {
18358
+ const handleImageError = (page, error2) => {
18357
18359
  setLoadStates((prevState) => ({
18358
18360
  ...prevState,
18359
- [index]: true
18361
+ [page.image_url]: true
18360
18362
  }));
18361
- console.error("图片加载失败:", error2);
18363
+ console.error("路径为".concat(page.image_url, "的图片加载失败,"), error2);
18362
18364
  };
18363
- const getLoadState = (pageIndex) => {
18364
- return loadStates[pageIndex] || false;
18365
+ const getLoadState = (imageUrl) => {
18366
+ return loadStates[imageUrl] || false;
18365
18367
  };
18366
18368
  y$1(() => {
18367
18369
  const container = contentRef.current;
18368
18370
  if (container) {
18369
18371
  updateVisibleRange();
18370
- container.addEventListener("scroll", updateVisibleRange);
18372
+ container.addEventListener("scroll", throttleUpdateRange);
18371
18373
  return () => {
18372
- container.removeEventListener("scroll", updateVisibleRange);
18374
+ container.removeEventListener("scroll", throttleUpdateRange);
18373
18375
  };
18374
18376
  }
18375
- }, [updateVisibleRange]);
18377
+ });
18376
18378
  y$1(() => {
18377
- scrollToCurrentThumbnail();
18379
+ var _a;
18380
+ const activeThumbnail = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
18381
+ ".thumbnail-item.active"
18382
+ );
18383
+ if (activeThumbnail) {
18384
+ scrollToCurrentThumbnail();
18385
+ } else {
18386
+ updateVisibleRange("DATA");
18387
+ setTimeout(() => {
18388
+ scrollToCurrentThumbnail();
18389
+ }, 0);
18390
+ }
18378
18391
  }, [props.currentPage]);
18379
18392
  return /* @__PURE__ */ u("div", { className: "thumbnail-panel", children: [
18380
18393
  /* @__PURE__ */ u("div", { className: "thumbnail-panel-header", children: /* @__PURE__ */ u("h3", { children: "缩略图" }) }),
18381
- /* @__PURE__ */ u("div", { className: "thumbnail-panel-content", ref: contentRef, children: props.pages && props.pages.length > 0 && props.pages.map((page, index) => {
18382
- const isLoaded = getLoadState(index);
18383
- const isCached = cachedImages.has(index);
18384
- const isVisible = visibleRange.start <= index && index <= visibleRange.end;
18385
- return /* @__PURE__ */ u(
18394
+ /* @__PURE__ */ u("div", { className: "thumbnail-panel-content", ref: contentRef, children: [
18395
+ /* @__PURE__ */ u(
18386
18396
  "div",
18387
18397
  {
18388
- className: "thumbnail-item ".concat(page.index === props.currentPage ? "active" : ""),
18389
- onClick: (event) => {
18390
- handleClick(index);
18398
+ class: "thumbnail-panel-phantom",
18399
+ style: { height: "".concat(phantomHeight, "px") }
18400
+ }
18401
+ ),
18402
+ /* @__PURE__ */ u(
18403
+ "div",
18404
+ {
18405
+ className: "thumbnail-item-container",
18406
+ style: {
18407
+ transform: "translate3d(0,".concat(itemContainerOffsetY, "px,0)")
18391
18408
  },
18392
- children: [
18393
- !isLoaded && /* @__PURE__ */ u(Loading, {}),
18394
- (isVisible || isCached) && /* @__PURE__ */ u(
18395
- "img",
18409
+ children: props.pages && props.pages.length > 0 && props.pages.map((page, index) => {
18410
+ const isVisible = visibleRange.start <= index && index <= visibleRange.end;
18411
+ if (!isVisible) {
18412
+ return null;
18413
+ }
18414
+ const isLoaded = getLoadState(page.image_url);
18415
+ return /* @__PURE__ */ u(
18416
+ "div",
18396
18417
  {
18397
- src: "".concat(imgBasePath).concat(page.image_url),
18398
- alt: page.description,
18399
- className: "thumbnail-image",
18400
- onLoad: () => {
18401
- handleImageLoad(index);
18418
+ className: "thumbnail-item ".concat(page.index === props.currentPage ? "active" : ""),
18419
+ onClick: (event) => {
18420
+ handleClick(index);
18402
18421
  },
18403
- onError: (error2) => {
18404
- handleImageError(index, error2);
18405
- }
18406
- }
18407
- ),
18408
- /* @__PURE__ */ u("div", { className: "thumbnail-page-number", children: index + 1 })
18409
- ]
18410
- },
18411
- index
18412
- );
18413
- }) })
18422
+ children: [
18423
+ !isLoaded && /* @__PURE__ */ u(Loading, {}),
18424
+ /* @__PURE__ */ u(
18425
+ "img",
18426
+ {
18427
+ src: "".concat(imgBasePath).concat(page.image_url),
18428
+ alt: page.description,
18429
+ className: "thumbnail-image",
18430
+ onLoad: () => {
18431
+ handleImageLoad(page);
18432
+ },
18433
+ onError: (error2) => {
18434
+ handleImageError(page, error2);
18435
+ }
18436
+ }
18437
+ ),
18438
+ /* @__PURE__ */ u("div", { className: "thumbnail-page-number", children: index + 1 })
18439
+ ]
18440
+ },
18441
+ page.image_url
18442
+ );
18443
+ })
18444
+ }
18445
+ )
18446
+ ] })
18414
18447
  ] });
18415
18448
  };
18416
18449
  const ImagePage = (props) => {
18417
18450
  const isLoading = useSignal(true);
18418
18451
  const imgRef = A(null);
18419
- const [parentDimensions, setParentDimensions] = d$2({
18420
- width: 0,
18421
- height: 0
18422
- });
18423
- const prevDimensions = A({ width: 0, height: 0 });
18452
+ const elementHeight = useSignal(0);
18424
18453
  const imgStyle = useComputed(() => {
18425
18454
  let result = {};
18426
- const { width, height } = parentDimensions;
18455
+ const { width, height } = props.parentDimensions;
18427
18456
  if (isLoading.value) {
18428
18457
  result = {
18429
18458
  height: "".concat(height * props.state.value.scale, "px"),
@@ -18457,33 +18486,25 @@ const ImagePage = (props) => {
18457
18486
  console.error("图片加载失败:", error2);
18458
18487
  isLoading.value = false;
18459
18488
  };
18460
- const updateParentStyle = () => {
18461
- var _a, _b;
18462
- const rect = (_b = (_a = imgRef.current) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.getBoundingClientRect();
18463
- if (!rect) return;
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
- }
18489
+ const handleHeightChange = (newHeight) => {
18490
+ var _a;
18491
+ elementHeight.value = newHeight;
18492
+ (_a = props.onHeightChange) == null ? void 0 : _a.call(props, props.index, newHeight);
18470
18493
  };
18471
18494
  y$1(() => {
18472
- updateParentStyle();
18473
- const observer = new ResizeObserver(() => {
18474
- requestAnimationFrame(() => {
18475
- updateParentStyle();
18476
- });
18477
- });
18478
- if (imgRef.current) {
18479
- if (imgRef.current.parentElement) {
18480
- observer.observe(imgRef.current.parentElement);
18495
+ if (!imgRef.current) return;
18496
+ const resizeObserver = new ResizeObserver((entries) => {
18497
+ for (const entry of entries) {
18498
+ const contentRect = entry.contentRect;
18499
+ const newHeight = contentRect.height;
18500
+ handleHeightChange(newHeight);
18481
18501
  }
18482
- }
18502
+ });
18503
+ resizeObserver.observe(imgRef.current);
18483
18504
  return () => {
18484
- observer.disconnect();
18505
+ resizeObserver.disconnect();
18485
18506
  };
18486
- }, []);
18507
+ }, [props.index]);
18487
18508
  return /* @__PURE__ */ u(
18488
18509
  "div",
18489
18510
  {
@@ -18492,7 +18513,7 @@ const ImagePage = (props) => {
18492
18513
  style: imgStyle.value,
18493
18514
  "data-page-index": props.index,
18494
18515
  children: [
18495
- props.isShowImage ? /* @__PURE__ */ u(
18516
+ /* @__PURE__ */ u(
18496
18517
  "img",
18497
18518
  {
18498
18519
  className: "image-content",
@@ -18506,7 +18527,7 @@ const ImagePage = (props) => {
18506
18527
  },
18507
18528
  loading: "lazy"
18508
18529
  }
18509
- ) : /* @__PURE__ */ u(Loading, {}),
18530
+ ),
18510
18531
  isLoading.value && /* @__PURE__ */ u(Loading, {})
18511
18532
  ]
18512
18533
  }
@@ -18517,41 +18538,128 @@ const FilePreviewImageGroup = (props) => {
18517
18538
  const state = controller.state;
18518
18539
  const contentRef = A(null);
18519
18540
  const isScrolling = useSignal(false);
18520
- const [loadedPages, setLoadedPages] = d$2(/* @__PURE__ */ new Set());
18521
- const computeClosestPage = () => {
18522
- if (contentRef.current) {
18523
- const containerRect = contentRef.current.getBoundingClientRect();
18524
- let closestPage = state.value.currentPage;
18525
- let minDistance = Infinity;
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++) {
18532
- const pageElement = contentRef.current.querySelector(
18533
- '[data-page-index="'.concat(index, '"]')
18534
- );
18535
- if (pageElement) {
18536
- const rect = pageElement.getBoundingClientRect();
18537
- const distance = Math.abs(rect.top - containerRect.top);
18538
- if (distance < minDistance) {
18539
- minDistance = distance;
18540
- closestPage = index;
18541
- }
18541
+ const [parentDimensions, setParentDimensions] = d$2({
18542
+ width: 0,
18543
+ height: 0
18544
+ });
18545
+ const prevDimensions = A({ width: 0, height: 0 });
18546
+ const itemPositions = useSignal([]);
18547
+ const estimateHeight = useSignal(0);
18548
+ const phantomHeight = useSignal(0);
18549
+ const startOffset = useSignal(0);
18550
+ const visibleInfo = useSignal({
18551
+ startIndex: 0,
18552
+ // 起始索引
18553
+ count: 1,
18554
+ // 显示数量
18555
+ buffer: 1
18556
+ // 缓冲区域子项个数
18557
+ });
18558
+ const visibleData = useComputed(() => {
18559
+ const start = Math.max(0, visibleInfo.value.startIndex);
18560
+ const end = Math.min(
18561
+ state.value.items.length - 1,
18562
+ visibleInfo.value.startIndex + visibleInfo.value.count + visibleInfo.value.buffer
18563
+ );
18564
+ return state.value.items.slice(start, end + 1);
18565
+ });
18566
+ const preloadImages = () => {
18567
+ const preloadPages = state.value.items.slice(0, 2);
18568
+ preloadPages.forEach((page) => {
18569
+ if (page) {
18570
+ const img = new Image();
18571
+ img.src = "".concat(imgBasePath).concat(page.image_url);
18572
+ }
18573
+ });
18574
+ };
18575
+ const initPhantomHeight = () => {
18576
+ var _a;
18577
+ const rect = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect();
18578
+ if (!rect) return;
18579
+ const newHeight = Math.round(rect.height);
18580
+ estimateHeight.value = newHeight;
18581
+ phantomHeight.value = newHeight * state.value.items.length;
18582
+ };
18583
+ const initItemPositions = () => {
18584
+ itemPositions.value = state.value.items.map((_item, index) => {
18585
+ return {
18586
+ index,
18587
+ top: index * estimateHeight.value,
18588
+ bottom: (index + 1) * estimateHeight.value,
18589
+ height: estimateHeight.value
18590
+ };
18591
+ });
18592
+ };
18593
+ const updateParentStyle = () => {
18594
+ var _a;
18595
+ const rect = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect();
18596
+ if (!rect) return;
18597
+ const newWidth = Math.round(rect.width);
18598
+ const newHeight = Math.round(rect.height);
18599
+ if (prevDimensions.current.width !== newWidth || prevDimensions.current.height !== newHeight) {
18600
+ prevDimensions.current = { width: newWidth, height: newHeight };
18601
+ setParentDimensions({ width: newWidth, height: newHeight });
18602
+ }
18603
+ };
18604
+ const getStartIndex = (scrollTop) => {
18605
+ let start = 0;
18606
+ let end = state.value.items.length - 1;
18607
+ let tempIndex = null;
18608
+ while (start <= end) {
18609
+ const midIndex = parseInt(String((end + start) / 2));
18610
+ const midBottom = itemPositions.value[midIndex].bottom;
18611
+ if (midBottom === scrollTop) {
18612
+ tempIndex = midIndex + 1;
18613
+ return tempIndex;
18614
+ }
18615
+ if (midBottom < scrollTop) {
18616
+ start = midIndex + 1;
18617
+ } else if (midBottom > scrollTop) {
18618
+ if (tempIndex === null || tempIndex > midIndex) {
18619
+ tempIndex = midIndex;
18542
18620
  }
18621
+ end -= 1;
18543
18622
  }
18544
- return closestPage;
18545
18623
  }
18624
+ return tempIndex;
18625
+ };
18626
+ const getOffsetY = () => {
18627
+ const realStart = visibleInfo.value.startIndex;
18628
+ if (realStart) {
18629
+ return itemPositions.value[realStart].top;
18630
+ }
18631
+ return 0;
18632
+ };
18633
+ const updateVisualSize = (id, curHeight) => {
18634
+ if (curHeight === 0) return;
18635
+ const oldHeight = itemPositions.value[id].height;
18636
+ const dValue = curHeight - oldHeight;
18637
+ if (dValue) {
18638
+ itemPositions.value[id].height = curHeight;
18639
+ itemPositions.value[id].bottom = itemPositions.value[id].bottom + dValue;
18640
+ for (let index = id + 1; index < itemPositions.value.length; index++) {
18641
+ itemPositions.value[index].top = itemPositions.value[index].top + dValue;
18642
+ itemPositions.value[index].bottom = itemPositions.value[index].bottom + dValue;
18643
+ }
18644
+ }
18645
+ };
18646
+ const computeClosestPage = () => {
18647
+ if (!contentRef.current) return;
18648
+ const scrollTop = contentRef.current.scrollTop;
18649
+ const closestPage = getStartIndex(scrollTop);
18650
+ return closestPage;
18546
18651
  };
18547
18652
  const handleScroll = throttle(() => {
18548
18653
  if (contentRef.current) {
18549
18654
  const closestPage = computeClosestPage();
18550
- if (!isScrolling.value && closestPage !== state.value.currentPage) {
18655
+ if (closestPage === void 0) return;
18656
+ visibleInfo.value.startIndex = closestPage;
18657
+ startOffset.value = getOffsetY();
18658
+ if (closestPage !== state.value.currentPage) {
18551
18659
  controller.updateState({ currentPage: closestPage });
18552
18660
  }
18553
18661
  }
18554
- }, 200);
18662
+ }, 500);
18555
18663
  const handleImageResize = () => {
18556
18664
  if (contentRef.current) {
18557
18665
  setTimeout(() => {
@@ -18563,75 +18671,19 @@ const FilePreviewImageGroup = (props) => {
18563
18671
  }
18564
18672
  };
18565
18673
  const scrollToPage = (pageIndex) => {
18566
- if (contentRef.current) {
18567
- const pageElement = contentRef.current.querySelector(
18568
- '[data-page-index="'.concat(pageIndex, '"]')
18569
- );
18570
- if (pageElement) {
18571
- pageElement.scrollIntoView({ behavior: "smooth", block: "start" });
18572
- }
18573
- }
18574
- };
18575
- const preloadImages = () => {
18576
- const visiblePages = state.value.items.slice(0, 2);
18577
- visiblePages.forEach((page) => {
18578
- if (page) {
18579
- const img = new Image();
18580
- img.src = "".concat(imgBasePath).concat(page.image_url);
18581
- }
18582
- });
18583
- };
18584
- let updateIsScrollingTimer;
18585
- const updateIsScrolling = () => {
18586
18674
  isScrolling.value = true;
18587
- if (updateIsScrollingTimer) {
18588
- clearTimeout(updateIsScrollingTimer);
18675
+ visibleInfo.value.startIndex = pageIndex;
18676
+ startOffset.value = getOffsetY();
18677
+ if (contentRef.current) {
18678
+ contentRef.current.scrollTop = startOffset.value;
18589
18679
  }
18590
- updateIsScrollingTimer = setTimeout(() => {
18680
+ setTimeout(() => {
18591
18681
  isScrolling.value = false;
18592
- }, 1e3);
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);
18682
+ }, 0);
18631
18683
  };
18632
18684
  const handlePageClick = (pageIndex) => {
18633
18685
  controller.updateState({ currentPage: pageIndex });
18634
- scrollToPageWhenStable(pageIndex);
18686
+ scrollToPage(pageIndex);
18635
18687
  };
18636
18688
  const handleInput = (e2) => {
18637
18689
  const target = e2.target;
@@ -18662,20 +18714,23 @@ const FilePreviewImageGroup = (props) => {
18662
18714
  scrollToPage(state.value.currentPage);
18663
18715
  };
18664
18716
  y$1(() => {
18665
- if (contentRef.current) {
18666
- contentRef.current.addEventListener("scroll", handleScroll);
18667
- }
18668
18717
  preloadImages();
18669
18718
  props.onInitialization();
18670
- return () => {
18671
- var _a;
18672
- (_a = contentRef.current) == null ? void 0 : _a.removeEventListener("scroll", handleScroll);
18673
- if (updateIsScrollingTimer) {
18674
- clearTimeout(updateIsScrollingTimer);
18675
- }
18676
- if (requestAnimationFrameId) {
18677
- cancelAnimationFrame(requestAnimationFrameId);
18719
+ initPhantomHeight();
18720
+ initItemPositions();
18721
+ updateParentStyle();
18722
+ const observer = new ResizeObserver(() => {
18723
+ requestAnimationFrame(() => {
18724
+ updateParentStyle();
18725
+ });
18726
+ });
18727
+ if (contentRef.current) {
18728
+ if (contentRef) {
18729
+ observer.observe(contentRef.current);
18678
18730
  }
18731
+ }
18732
+ return () => {
18733
+ observer.disconnect();
18679
18734
  };
18680
18735
  }, []);
18681
18736
  return /* @__PURE__ */ u("div", { className: "file-preview-image-group", children: [
@@ -18701,36 +18756,43 @@ const FilePreviewImageGroup = (props) => {
18701
18756
  ref: contentRef,
18702
18757
  className: "image-group-main-container",
18703
18758
  onScroll: () => {
18704
- handleScroll();
18759
+ if (!isScrolling.value) {
18760
+ handleScroll();
18761
+ }
18705
18762
  },
18706
- children: state.value.items && state.value.items.length > 0 && state.value.items.map((page, index) => {
18707
- const bufferRange = 1;
18708
- const startRange = Math.max(
18709
- 0,
18710
- state.value.currentPage - bufferRange
18711
- );
18712
- const endRange = Math.min(
18713
- state.value.items.length - 1,
18714
- state.value.currentPage + bufferRange
18715
- );
18716
- const shouldRender = index >= startRange && index <= endRange;
18717
- const shouldKeepLoaded = loadedPages.has(index);
18718
- if (shouldRender) {
18719
- if (!loadedPages.has(index)) {
18720
- setLoadedPages((prev) => new Set(prev).add(index));
18763
+ children: [
18764
+ /* @__PURE__ */ u(
18765
+ "div",
18766
+ {
18767
+ class: "image-group-main-phantom",
18768
+ style: { height: "".concat(phantomHeight.value, "px") }
18721
18769
  }
18722
- }
18723
- return /* @__PURE__ */ u(
18724
- ImagePage,
18770
+ ),
18771
+ /* @__PURE__ */ u(
18772
+ "div",
18725
18773
  {
18726
- page,
18727
- index,
18728
- state,
18729
- isShowImage: shouldRender || shouldKeepLoaded
18730
- },
18731
- index
18732
- );
18733
- })
18774
+ className: "image-group-item-container",
18775
+ style: {
18776
+ transform: "translate3d(0,".concat(startOffset.value, "px,0)")
18777
+ },
18778
+ children: visibleData.value && visibleData.value.length > 0 && visibleData.value.map((page) => {
18779
+ return /* @__PURE__ */ u(
18780
+ ImagePage,
18781
+ {
18782
+ page,
18783
+ index: page.index,
18784
+ state,
18785
+ parentDimensions,
18786
+ onHeightChange: (index, height) => {
18787
+ updateVisualSize(index, height);
18788
+ }
18789
+ },
18790
+ page.image_url
18791
+ );
18792
+ })
18793
+ }
18794
+ )
18795
+ ]
18734
18796
  }
18735
18797
  ),
18736
18798
  /* @__PURE__ */ u(Teleport, { to: "#custom-controls", children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [