@prose-reader/core 1.65.0 → 1.67.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
- 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, BehaviorSubject, filter as filter$1, debounceTime, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
2
- import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, distinctUntilChanged, takeUntil as takeUntil$1, skip, withLatestFrom as withLatestFrom$1, share, exhaustMap, mergeMap, catchError, debounce, debounceTime as debounceTime$1, delay } from "rxjs/operators";
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, BehaviorSubject, filter as filter$1, debounceTime as debounceTime$1, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
2
+ import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, distinctUntilChanged, takeUntil as takeUntil$1, debounceTime, skip, withLatestFrom as withLatestFrom$1, share, exhaustMap, mergeMap, catchError, debounce, delay } from "rxjs/operators";
3
3
  import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
4
4
  const chromeEnhancer = (next) => (options) => {
5
5
  const reader = next(options);
@@ -467,20 +467,25 @@ const layoutEnhancer = (next) => (options) => {
467
467
  }
468
468
  );
469
469
  fixReflowable(reader);
470
- let observer;
471
- if (options.layoutAutoResize === `container`) {
472
- reader.context.state$.pipe(
473
- map((state) => state.containerElement),
474
- filter(isDefined),
475
- distinctUntilChanged(),
476
- takeUntil$1(reader.$.destroy$)
477
- ).subscribe((container) => {
478
- observer = new ResizeObserver(() => {
479
- reader == null ? void 0 : reader.layout();
480
- });
481
- observer.observe(container);
470
+ const observeContainerResize = (container) => new Observable((observer) => {
471
+ const resizeObserver = new ResizeObserver(() => {
472
+ observer.next();
482
473
  });
483
- }
474
+ resizeObserver.observe(container);
475
+ return () => {
476
+ resizeObserver.disconnect();
477
+ };
478
+ });
479
+ const layoutOnContainerResize$ = settingsManager.settings$.pipe(
480
+ filter(({ layoutAutoResize: layoutAutoResize2 }) => layoutAutoResize2 === "container"),
481
+ switchMap$1(() => reader.context.containerElement$),
482
+ filter(isDefined),
483
+ switchMap$1((container) => observeContainerResize(container)),
484
+ debounceTime(100),
485
+ tap(() => {
486
+ reader == null ? void 0 : reader.layout();
487
+ })
488
+ );
484
489
  const movingSafePan$ = createMovingSafePan$(reader);
485
490
  movingSafePan$.subscribe();
486
491
  settingsManager.settings$.pipe(
@@ -492,12 +497,12 @@ const layoutEnhancer = (next) => (options) => {
492
497
  }),
493
498
  takeUntil$1(reader.$.destroy$)
494
499
  ).subscribe();
500
+ merge(layoutOnContainerResize$).pipe(takeUntil$1(reader.$.destroy$)).subscribe();
495
501
  return {
496
502
  ...reader,
497
503
  destroy: () => {
498
504
  settingsManager.destroy();
499
505
  reader.destroy();
500
- observer == null ? void 0 : observer.disconnect();
501
506
  },
502
507
  settings: settingsManager
503
508
  };
@@ -883,7 +888,7 @@ const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemManager.get
883
888
  }, 0);
884
889
  const trackTotalPages = (reader) => {
885
890
  const totalPages$ = reader.spine.$.layout$.pipe(
886
- debounceTime(10, animationFrameScheduler),
891
+ debounceTime$1(10, animationFrameScheduler),
887
892
  withLatestFrom(reader.pagination.paginationInfo$),
888
893
  map$1(() => {
889
894
  const numberOfPagesPerItems = getNumberOfPagesForAllSpineItems(reader);
@@ -2463,6 +2468,174 @@ const buildDocumentStyle = ({
2463
2468
  }
2464
2469
  `;
2465
2470
  };
2471
+ const buildStyleForViewportFrame = () => {
2472
+ return `
2473
+ ${getStyleForViewportDocument()}
2474
+ html {
2475
+ width: 100%;
2476
+ height: 100%;
2477
+ }
2478
+ body {
2479
+ width: 100%;
2480
+ height: 100%;
2481
+ margin: 0;
2482
+ }
2483
+ ${/*
2484
+ * @see https://hammerjs.github.io/touch-action/
2485
+ */
2486
+ ``}
2487
+ html, body {
2488
+ touch-action: none;
2489
+ }
2490
+ `;
2491
+ };
2492
+ const buildStyleForReflowableImageOnly = ({
2493
+ isScrollable,
2494
+ enableTouch
2495
+ }) => {
2496
+ return `
2497
+ ${/*
2498
+ * @see https://hammerjs.github.io/touch-action/
2499
+ */
2500
+ ``}
2501
+ html, body {
2502
+ width: 100%;
2503
+ margin: 0;
2504
+ padding: 0;
2505
+ ${enableTouch ? `
2506
+ touch-action: none
2507
+ ` : ``}
2508
+ }
2509
+ ${isScrollable ? `
2510
+ img {
2511
+ height: auto !important;
2512
+ margin: 0;
2513
+ padding: 0;
2514
+ box-sizing: border-box;
2515
+ ${// we make sure img spread on entire screen
2516
+ ``}
2517
+ width: 100%;
2518
+ ${/**
2519
+ * line break issue
2520
+ * @see https://stackoverflow.com/questions/37869020/image-not-taking-up-the-full-height-of-container
2521
+ */
2522
+ ``}
2523
+ display: block;
2524
+ }
2525
+ ` : ``}
2526
+ `;
2527
+ };
2528
+ const buildStyleWithMultiColumn = ({
2529
+ width,
2530
+ columnHeight,
2531
+ columnWidth
2532
+ }) => {
2533
+ return `
2534
+ parsererror {
2535
+ display: none !important;
2536
+ }
2537
+ ${/*
2538
+ might be html * but it does mess up things like figure if so.
2539
+ check accessible_epub_3
2540
+ */
2541
+ ``}
2542
+ html, body {
2543
+ margin: 0;
2544
+ padding: 0 !important;
2545
+ -max-width: ${columnWidth}px !important;
2546
+ }
2547
+ ${/*
2548
+ body {
2549
+ height: ${columnHeight}px !important;
2550
+ width: ${columnWidth}px !important;
2551
+ -margin-left: ${horizontalMargin}px !important;
2552
+ -margin-right: ${horizontalMargin}px !important;
2553
+ -margin: ${verticalMargin}px ${horizontalMargin}px !important;
2554
+ -padding-top: ${horizontalMargin}px !important;
2555
+ -padding-bottom: ${horizontalMargin}px !important;
2556
+ }
2557
+ */
2558
+ ``}
2559
+ body {
2560
+ padding: 0 !important;
2561
+ width: ${width}px !important;
2562
+ height: ${columnHeight}px !important;
2563
+ overflow-y: hidden;
2564
+ column-gap: 0px !important;
2565
+ column-width: ${columnWidth}px !important;
2566
+ column-fill: auto !important;
2567
+ word-wrap: break-word;
2568
+ box-sizing: border-box;
2569
+ }
2570
+ body {
2571
+ margin: 0;
2572
+ }
2573
+ body:focus-visible {
2574
+ ${/*
2575
+ we make sure that there are no outline when we focus something inside the iframe
2576
+ */
2577
+ ``}
2578
+ outline: none;
2579
+ }
2580
+ ${/*
2581
+ * @see https://hammerjs.github.io/touch-action/
2582
+ */
2583
+ ``}
2584
+ html, body {
2585
+ touch-action: none;
2586
+ }
2587
+ ${/*
2588
+ this messes up hard, be careful with this
2589
+ */
2590
+ ``}
2591
+ * {
2592
+ -max-width: ${columnWidth}px !important;
2593
+ }
2594
+ ${/*
2595
+ this is necessary to have a proper calculation when determining size
2596
+ of iframe content. If an img is using something like width:100% it would expand to
2597
+ the size of the original image and potentially gives back a wrong size (much larger)
2598
+ @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Columns/Handling_Overflow_in_Multicol
2599
+ */
2600
+ ``}
2601
+ img, video, audio, object, svg {
2602
+ max-width: 100%;
2603
+ max-width: ${columnWidth}px !important;
2604
+ max-height: ${columnHeight}px !important;
2605
+ -pointer-events: none;
2606
+ -webkit-column-break-inside: avoid;
2607
+ page-break-inside: avoid;
2608
+ break-inside: avoid;
2609
+ }
2610
+ figure {
2611
+ d-max-width: ${columnWidth}px !important;
2612
+ }
2613
+ img {
2614
+ object-fit: contain;
2615
+ break-inside: avoid;
2616
+ box-sizing: border-box;
2617
+ d-max-width: ${columnWidth}px !important;
2618
+ }
2619
+ ${/*
2620
+ img, video, audio, object, svg {
2621
+ max-height: ${columnHeight}px !important;
2622
+ box-sizing: border-box;
2623
+ object-fit: contain;
2624
+ -webkit-column-break-inside: avoid;
2625
+ page-break-inside: avoid;
2626
+ break-inside: avoid;
2627
+ }
2628
+ */
2629
+ ``}
2630
+ table {
2631
+ max-width: ${columnWidth}px !important;
2632
+ table-layout: fixed;
2633
+ }
2634
+ td {
2635
+ max-width: ${columnWidth}px;
2636
+ }
2637
+ `;
2638
+ };
2466
2639
  const createReflowableSpineItem = ({
2467
2640
  item,
2468
2641
  context,
@@ -2592,174 +2765,6 @@ const createReflowableSpineItem = ({
2592
2765
  layout
2593
2766
  };
2594
2767
  };
2595
- const buildStyleForViewportFrame = () => {
2596
- return `
2597
- ${getStyleForViewportDocument()}
2598
- html {
2599
- width: 100%;
2600
- height: 100%;
2601
- }
2602
- body {
2603
- width: 100%;
2604
- height: 100%;
2605
- margin: 0;
2606
- }
2607
- ${/*
2608
- * @see https://hammerjs.github.io/touch-action/
2609
- */
2610
- ``}
2611
- html, body {
2612
- touch-action: none;
2613
- }
2614
- `;
2615
- };
2616
- const buildStyleForReflowableImageOnly = ({
2617
- isScrollable,
2618
- enableTouch
2619
- }) => {
2620
- return `
2621
- ${/*
2622
- * @see https://hammerjs.github.io/touch-action/
2623
- */
2624
- ``}
2625
- html, body {
2626
- width: 100%;
2627
- margin: 0;
2628
- padding: 0;
2629
- ${enableTouch ? `
2630
- touch-action: none
2631
- ` : ``}
2632
- }
2633
- ${isScrollable ? `
2634
- img {
2635
- height: auto !important;
2636
- margin: 0;
2637
- padding: 0;
2638
- box-sizing: border-box;
2639
- ${// we make sure img spread on entire screen
2640
- ``}
2641
- width: 100%;
2642
- ${/**
2643
- * line break issue
2644
- * @see https://stackoverflow.com/questions/37869020/image-not-taking-up-the-full-height-of-container
2645
- */
2646
- ``}
2647
- display: block;
2648
- }
2649
- ` : ``}
2650
- `;
2651
- };
2652
- const buildStyleWithMultiColumn = ({
2653
- width,
2654
- columnHeight,
2655
- columnWidth
2656
- }) => {
2657
- return `
2658
- parsererror {
2659
- display: none !important;
2660
- }
2661
- ${/*
2662
- might be html * but it does mess up things like figure if so.
2663
- check accessible_epub_3
2664
- */
2665
- ``}
2666
- html, body {
2667
- margin: 0;
2668
- padding: 0 !important;
2669
- -max-width: ${columnWidth}px !important;
2670
- }
2671
- ${/*
2672
- body {
2673
- height: ${columnHeight}px !important;
2674
- width: ${columnWidth}px !important;
2675
- -margin-left: ${horizontalMargin}px !important;
2676
- -margin-right: ${horizontalMargin}px !important;
2677
- -margin: ${verticalMargin}px ${horizontalMargin}px !important;
2678
- -padding-top: ${horizontalMargin}px !important;
2679
- -padding-bottom: ${horizontalMargin}px !important;
2680
- }
2681
- */
2682
- ``}
2683
- body {
2684
- padding: 0 !important;
2685
- width: ${width}px !important;
2686
- height: ${columnHeight}px !important;
2687
- overflow-y: hidden;
2688
- column-gap: 0px !important;
2689
- column-width: ${columnWidth}px !important;
2690
- column-fill: auto !important;
2691
- word-wrap: break-word;
2692
- box-sizing: border-box;
2693
- }
2694
- body {
2695
- margin: 0;
2696
- }
2697
- body:focus-visible {
2698
- ${/*
2699
- we make sure that there are no outline when we focus something inside the iframe
2700
- */
2701
- ``}
2702
- outline: none;
2703
- }
2704
- ${/*
2705
- * @see https://hammerjs.github.io/touch-action/
2706
- */
2707
- ``}
2708
- html, body {
2709
- touch-action: none;
2710
- }
2711
- ${/*
2712
- this messes up hard, be careful with this
2713
- */
2714
- ``}
2715
- * {
2716
- -max-width: ${columnWidth}px !important;
2717
- }
2718
- ${/*
2719
- this is necessary to have a proper calculation when determining size
2720
- of iframe content. If an img is using something like width:100% it would expand to
2721
- the size of the original image and potentially gives back a wrong size (much larger)
2722
- @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Columns/Handling_Overflow_in_Multicol
2723
- */
2724
- ``}
2725
- img, video, audio, object, svg {
2726
- max-width: 100%;
2727
- max-width: ${columnWidth}px !important;
2728
- max-height: ${columnHeight}px !important;
2729
- -pointer-events: none;
2730
- -webkit-column-break-inside: avoid;
2731
- page-break-inside: avoid;
2732
- break-inside: avoid;
2733
- }
2734
- figure {
2735
- d-max-width: ${columnWidth}px !important;
2736
- }
2737
- img {
2738
- object-fit: contain;
2739
- break-inside: avoid;
2740
- box-sizing: border-box;
2741
- d-max-width: ${columnWidth}px !important;
2742
- }
2743
- ${/*
2744
- img, video, audio, object, svg {
2745
- max-height: ${columnHeight}px !important;
2746
- box-sizing: border-box;
2747
- object-fit: contain;
2748
- -webkit-column-break-inside: avoid;
2749
- page-break-inside: avoid;
2750
- break-inside: avoid;
2751
- }
2752
- */
2753
- ``}
2754
- table {
2755
- max-width: ${columnWidth}px !important;
2756
- table-layout: fixed;
2757
- }
2758
- td {
2759
- max-width: ${columnWidth}px;
2760
- }
2761
- `;
2762
- };
2763
2768
  const createSpineItem = ({
2764
2769
  item,
2765
2770
  context,
@@ -5033,7 +5038,7 @@ const createScrollViewportNavigator = ({
5033
5038
  });
5034
5039
  };
5035
5040
  const navigationOnScroll$ = userScroll$.pipe(
5036
- debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
5041
+ debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
5037
5042
  withLatestFrom$1(currentNavigationSubject$),
5038
5043
  switchMap$1(() => {
5039
5044
  var _a, _b;
@@ -5052,7 +5057,7 @@ const createScrollViewportNavigator = ({
5052
5057
  share()
5053
5058
  );
5054
5059
  const userScrollEnd$ = userScroll$.pipe(
5055
- debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
5060
+ debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
5056
5061
  share(),
5057
5062
  takeUntil$1(context.destroy$)
5058
5063
  );