@prose-reader/core 1.68.0 → 1.69.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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
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, take as take$1, finalize, first as first$1, from, catchError, forkJoin } from "rxjs";
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, share as share$1, mergeMap as mergeMap$1, catchError as catchError$1 } from "rxjs/operators";
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 { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
4
4
  const chromeEnhancer = (next) => (options) => {
5
5
  const reader = next(options);
@@ -5536,73 +5536,88 @@ const createLoader = ({
5536
5536
  const loadSubject = new Subject();
5537
5537
  const unloadSubject = new Subject();
5538
5538
  const frameElementSubject = new BehaviorSubject(void 0);
5539
- const load$ = loadSubject.asObservable();
5540
- const unload$ = unloadSubject.asObservable();
5541
- const stateIdle$ = stateSubject.pipe(filter((state) => state === "idle"));
5542
- const stateIsReady$ = stateSubject.pipe(
5543
- map((state) => state === "ready"),
5544
- distinctUntilChanged()
5545
- );
5546
- const unloaded$ = unload$.pipe(
5539
+ const unloadFrame$ = unloadSubject.pipe(
5547
5540
  withLatestFrom$1(stateSubject),
5548
5541
  filter(([, state]) => state !== "unloading" && state !== "idle"),
5549
- exhaustMap$1(() => {
5550
- stateSubject.next("unloading");
5551
- return unloadFrame({
5552
- hookManager,
5553
- item,
5554
- frameElement: frameElementSubject.getValue(),
5555
- context
5556
- }).pipe(
5557
- tap(() => {
5558
- frameElementSubject.next(void 0);
5559
- stateSubject.next("idle");
5560
- })
5561
- );
5562
- }),
5563
- share$1()
5564
- );
5565
- const loaded$ = load$.pipe(
5566
5542
  exhaustMap$1(
5567
- () => stateIdle$.pipe(
5543
+ () => context.bridgeEvent.viewportFree$.pipe(
5568
5544
  first(),
5569
- tap(() => {
5570
- stateSubject.next("loading");
5571
- }),
5572
- waitForSwitch(context.bridgeEvent.viewportFree$),
5573
5545
  switchMap$1(
5574
- () => loadFrame({
5575
- element: parent,
5546
+ () => unloadFrame({
5576
5547
  hookManager,
5577
5548
  item,
5578
- onFrameElement: (element) => {
5579
- frameElementSubject.next(element);
5580
- },
5581
- settings,
5549
+ frameElement: frameElementSubject.getValue(),
5582
5550
  context
5583
5551
  })
5584
5552
  ),
5585
5553
  tap(() => {
5586
- stateSubject.next("loaded");
5554
+ frameElementSubject.next(void 0);
5587
5555
  }),
5588
- takeUntil$1(unload$)
5556
+ ignoreElements(),
5557
+ startWith("loading"),
5558
+ endWith("success"),
5559
+ defaultIfEmpty("idle")
5589
5560
  )
5590
5561
  ),
5562
+ startWith("idle"),
5563
+ distinctUntilChanged(),
5564
+ share$1()
5565
+ );
5566
+ const unloaded$ = unloadFrame$.pipe(filter((state) => state === "success"));
5567
+ const unloading$ = unloadFrame$.pipe(filter((state) => state === "loading"));
5568
+ const loadFrame$ = loadSubject.pipe(
5569
+ exhaustMap$1(() => {
5570
+ const preventFurtherLoad$ = NEVER;
5571
+ return merge(
5572
+ preventFurtherLoad$,
5573
+ context.bridgeEvent.viewportFree$.pipe(
5574
+ first(),
5575
+ switchMap$1(
5576
+ () => loadFrame({
5577
+ element: parent,
5578
+ hookManager,
5579
+ item,
5580
+ onFrameElement: (element) => {
5581
+ frameElementSubject.next(element);
5582
+ },
5583
+ settings,
5584
+ context
5585
+ })
5586
+ ),
5587
+ map((frame) => ({ state: "success", frame })),
5588
+ startWith({ state: "loading" }),
5589
+ defaultIfEmpty({ state: "idle" })
5590
+ )
5591
+ ).pipe(takeUntil$1(unloaded$));
5592
+ }),
5593
+ startWith({ state: "idle" }),
5591
5594
  share$1()
5592
5595
  );
5593
- const ready$ = loaded$.pipe(
5596
+ const loading$ = loadFrame$.pipe(filter(({ state }) => state === "loading"));
5597
+ const loaded$ = loadFrame$.pipe(
5598
+ filter((state) => state.state === "success"),
5599
+ map(({ frame }) => frame)
5600
+ );
5601
+ const frameIsReady$ = loaded$.pipe(
5594
5602
  switchMap$1(
5595
- (frame) => of(frame).pipe(
5596
- waitForFrameReady,
5597
- tap(() => {
5598
- stateSubject.next("ready");
5599
- }),
5600
- takeUntil$1(unload$)
5601
- )
5603
+ (frame) => of(frame).pipe(waitForFrameReady, takeUntil$1(unloadSubject))
5602
5604
  ),
5603
5605
  share$1()
5604
5606
  );
5605
- merge(unloaded$, loaded$, ready$).pipe(takeUntil$1(destroySubject$)).subscribe();
5607
+ const ready$ = frameIsReady$;
5608
+ const state$ = merge(
5609
+ unloaded$.pipe(map(() => "idle")),
5610
+ unloading$.pipe(map(() => "unloading")),
5611
+ loaded$.pipe(map(() => "loaded")),
5612
+ loading$.pipe(map(() => "loading")),
5613
+ ready$.pipe(map(() => "ready"))
5614
+ ).pipe(
5615
+ startWith("idle"),
5616
+ tap((state) => stateSubject.next(state)),
5617
+ shareReplay(1)
5618
+ );
5619
+ const isReady$ = state$.pipe(map((state) => state === "ready"));
5620
+ state$.pipe(takeUntil$1(destroySubject$)).subscribe();
5606
5621
  return {
5607
5622
  load: () => loadSubject.next(),
5608
5623
  unload: () => unloadSubject.next(),
@@ -5613,6 +5628,7 @@ const createLoader = ({
5613
5628
  frameElementSubject.complete();
5614
5629
  destroySubject$.next();
5615
5630
  destroySubject$.complete();
5631
+ stateSubject.complete();
5616
5632
  },
5617
5633
  get state() {
5618
5634
  return stateSubject.getValue();
@@ -5620,7 +5636,7 @@ const createLoader = ({
5620
5636
  get element() {
5621
5637
  return frameElementSubject.getValue();
5622
5638
  },
5623
- isReady$: stateIsReady$,
5639
+ isReady$,
5624
5640
  ready$,
5625
5641
  loaded$,
5626
5642
  unloaded$,