@prose-reader/core 1.87.0 → 1.88.0

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.
@@ -0,0 +1,6 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Reader } from '../../reader';
3
+ export declare const throttleLock: ({ reader, duration }: {
4
+ reader: Reader;
5
+ duration: number;
6
+ }) => <T>(stream: Observable<T>) => Observable<T>;
@@ -1,3 +1,4 @@
1
+ import { Observable } from 'rxjs';
1
2
  import { Reader } from '../../reader';
2
3
  import { ManualNavigator } from './navigators/manualNavigator';
3
4
  import { PanNavigator } from './navigators/panNavigator';
@@ -8,6 +9,10 @@ export type NavigationEnhancerOutput = {
8
9
  }) => void;
9
10
  navigation: {
10
11
  state$: ReturnType<typeof observeState>;
12
+ throttleLock: <T>(params: {
13
+ duration: number;
14
+ trigger: Observable<T>;
15
+ }) => Observable<T>;
11
16
  moveTo: PanNavigator["moveTo"];
12
17
  turnTop: ManualNavigator["turnTop"];
13
18
  turnBottom: ManualNavigator["turnBottom"];
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { takeUntil, Subject, combineLatest, map as map$1, switchMap, merge, EMPTY, fromEvent, withLatestFrom, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, startWith as startWith$1, debounceTime as debounceTime$1, BehaviorSubject, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, ReplaySubject, filter as filter$1, share, mergeMap, delay, identity, timer, skip as skip$1, exhaustMap, first as first$1, finalize, take as take$1, from, catchError, forkJoin } from "rxjs";
1
+ import { takeUntil, Subject, combineLatest, map as map$1, switchMap, merge, EMPTY, fromEvent, withLatestFrom, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, tap as tap$1, throttleTime, finalize, startWith as startWith$1, debounceTime as debounceTime$1, BehaviorSubject, combineLatestWith, shareReplay as shareReplay$1, ReplaySubject, filter as filter$1, share, mergeMap, delay, identity, timer, skip as skip$1, exhaustMap, first as first$1, take as take$1, from, catchError, forkJoin } from "rxjs";
2
2
  import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, take, distinctUntilChanged, takeUntil as takeUntil$1, first, filter, debounceTime, skip, withLatestFrom as withLatestFrom$1, exhaustMap as exhaustMap$1, ignoreElements, endWith, defaultIfEmpty, share as share$1, mergeMap as mergeMap$1, catchError as catchError$1 } from "rxjs/operators";
3
3
  import { shallowMergeIfDefined, isShallowEqual, parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
4
4
  import { isShallowEqual as isShallowEqual2 } from "@prose-reader/shared";
@@ -1048,6 +1048,26 @@ const observeState = (reader) => {
1048
1048
  distinctUntilChanged$1(isShallowEqual)
1049
1049
  );
1050
1050
  };
1051
+ const throttleLock = ({ reader, duration }) => (stream) => {
1052
+ let unlockFn = void 0;
1053
+ const unlock = () => {
1054
+ unlockFn == null ? void 0 : unlockFn();
1055
+ unlockFn = void 0;
1056
+ };
1057
+ return stream.pipe(
1058
+ tap$1(() => {
1059
+ if (!unlockFn) {
1060
+ unlockFn = reader == null ? void 0 : reader.navigation.lock();
1061
+ }
1062
+ }),
1063
+ throttleTime(duration, animationFrameScheduler, {
1064
+ trailing: true,
1065
+ leading: true
1066
+ }),
1067
+ tap$1(unlock),
1068
+ finalize(unlock)
1069
+ );
1070
+ };
1051
1071
  const navigationEnhancer = (next) => (options) => {
1052
1072
  const reader = next(options);
1053
1073
  const state$ = observeState(reader);
@@ -1066,6 +1086,7 @@ const navigationEnhancer = (next) => (options) => {
1066
1086
  navigation: {
1067
1087
  ...reader.navigation,
1068
1088
  state$,
1089
+ throttleLock: ({ duration, trigger }) => trigger.pipe(throttleLock({ duration, reader })),
1069
1090
  moveTo: panNavigator.moveTo.bind(panNavigator),
1070
1091
  turnBottom: manualNavigator.turnBottom.bind(manualNavigator),
1071
1092
  turnTop: manualNavigator.turnTop.bind(manualNavigator),