@embedpdf/plugin-scroll 1.0.0 → 1.0.1

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.cjs CHANGED
@@ -428,9 +428,13 @@ var HorizontalScrollStrategy = class extends BaseScrollStrategy {
428
428
  // src/lib/actions.ts
429
429
  var UPDATE_SCROLL_STATE = "UPDATE_SCROLL_STATE";
430
430
  var SET_DESIRED_SCROLL_POSITION = "SET_DESIRED_SCROLL_POSITION";
431
+ var UPDATE_TOTAL_PAGES = "UPDATE_TOTAL_PAGES";
431
432
  function updateScrollState(payload) {
432
433
  return { type: UPDATE_SCROLL_STATE, payload };
433
434
  }
435
+ function updateTotalPages(payload) {
436
+ return { type: UPDATE_TOTAL_PAGES, payload };
437
+ }
434
438
 
435
439
  // src/lib/selectors.ts
436
440
  var getScrollerLayout = (state, scale) => {
@@ -471,7 +475,7 @@ var ScrollPlugin = class extends import_core.BasePlugin {
471
475
  this.scroll$ = (0, import_core.createBehaviorEmitter)();
472
476
  this.state$ = (0, import_core.createBehaviorEmitter)();
473
477
  this.scrollerLayout$ = (0, import_core.createBehaviorEmitter)();
474
- this.pageChange$ = (0, import_core.createEmitter)();
478
+ this.pageChange$ = (0, import_core.createBehaviorEmitter)();
475
479
  this.viewport = this.registry.getPlugin("viewport").provides();
476
480
  this.strategyConfig = {
477
481
  pageGap: this.config?.pageGap ?? 10,
@@ -486,10 +490,12 @@ var ScrollPlugin = class extends import_core.BasePlugin {
486
490
  mode: "throttle",
487
491
  wait: 250
488
492
  });
489
- this.coreStore.onAction(
490
- import_core.SET_DOCUMENT,
491
- (_action, state) => this.refreshAll((0, import_core.getPagesWithRotatedSize)(state.core), this.viewport.getMetrics())
492
- );
493
+ this.coreStore.onAction(import_core.SET_DOCUMENT, (_action, state) => {
494
+ const totalPages = state.core.pages.length;
495
+ this.dispatch(updateTotalPages(totalPages));
496
+ this.pageChange$.emit({ pageNumber: this.currentPage, totalPages });
497
+ this.refreshAll((0, import_core.getPagesWithRotatedSize)(state.core), this.viewport.getMetrics());
498
+ });
493
499
  this.coreStore.onAction(
494
500
  import_core.SET_ROTATION,
495
501
  (_action, state) => this.refreshAll((0, import_core.getPagesWithRotatedSize)(state.core), this.viewport.getMetrics())
@@ -520,7 +526,7 @@ var ScrollPlugin = class extends import_core.BasePlugin {
520
526
  this.scroll$.emit(emit.metrics);
521
527
  if (emit.metrics.currentPage !== this.currentPage) {
522
528
  this.currentPage = emit.metrics.currentPage;
523
- this.pageChange$.emit(this.currentPage);
529
+ this.pageChange$.emit({ pageNumber: this.currentPage, totalPages: this.state.totalPages });
524
530
  }
525
531
  }
526
532
  this.scrollerLayout$.emit(this.getScrollerLayoutFromState());
@@ -581,6 +587,8 @@ var ScrollPlugin = class extends import_core.BasePlugin {
581
587
  onScroll: this.scroll$.on,
582
588
  onPageChange: this.pageChange$.on,
583
589
  onScrollerData: this.scrollerLayout$.on,
590
+ getCurrentPage: () => this.currentPage,
591
+ getTotalPages: () => this.state.totalPages,
584
592
  scrollToPage: (options) => {
585
593
  const { pageNumber, behavior = "smooth", pageCoordinates, center = false } = options;
586
594
  const virtualItems = this.getVirtualItemsFromState();
@@ -699,6 +707,7 @@ var defaultScrollMetrics = {
699
707
  };
700
708
  var initialState = (coreState, config) => ({
701
709
  virtualItems: [],
710
+ totalPages: coreState.pages.length,
702
711
  totalContentSize: { width: 0, height: 0 },
703
712
  desiredScrollPosition: { x: 0, y: 0 },
704
713
  strategy: config.strategy ?? "vertical" /* Vertical */,
@@ -708,6 +717,8 @@ var initialState = (coreState, config) => ({
708
717
  });
709
718
  var scrollReducer = (state, action) => {
710
719
  switch (action.type) {
720
+ case UPDATE_TOTAL_PAGES:
721
+ return { ...state, totalPages: action.payload };
711
722
  case import_core2.SET_SCALE:
712
723
  return { ...state, scale: action.payload };
713
724
  case UPDATE_SCROLL_STATE: