@prose-reader/core 1.141.0 → 1.143.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.
@@ -8,7 +8,6 @@ export type ContextState = {
8
8
  isUsingSpreadMode?: boolean;
9
9
  isFullyPrePaginated?: boolean;
10
10
  forceSinglePageMode?: boolean;
11
- areAllItemsPrePaginated?: boolean;
12
11
  calculatedInnerMargin: number;
13
12
  marginTop: number;
14
13
  marginBottom: number;
@@ -8,7 +8,7 @@ export declare class ImageRenderer extends DocumentRenderer {
8
8
  minPageSpread: number;
9
9
  blankPagePosition: `before` | `after` | `none`;
10
10
  spreadPosition: `none` | `left` | `right`;
11
- }): import('rxjs').Observable<{
11
+ }): import('rxjs').Observable<undefined> | import('rxjs').Observable<{
12
12
  width: number;
13
13
  height: number;
14
14
  }>;
package/dist/index.js CHANGED
@@ -250,12 +250,14 @@ const getFrameViewportInfo = (frame) => {
250
250
  return { hasViewport: false };
251
251
  };
252
252
  const waitForFrameLoad = (stream) => stream.pipe(
253
- switchMap$1(
254
- (frame) => fromEvent(frame, `load`).pipe(
253
+ switchMap$1((frame) => {
254
+ var _a;
255
+ if (((_a = frame.contentDocument) == null ? void 0 : _a.readyState) === "complete") return of(frame);
256
+ return fromEvent(frame, `load`).pipe(
255
257
  take(1),
256
258
  map$1(() => frame)
257
- )
258
- )
259
+ );
260
+ })
259
261
  );
260
262
  const waitForFrameReady = (stream) => stream.pipe(
261
263
  switchMap$1(
@@ -1936,7 +1938,6 @@ const isUsingSpreadMode = ({
1936
1938
  return isLandscape && ((manifest == null ? void 0 : manifest.renditionSpread) === void 0 || (manifest == null ? void 0 : manifest.renditionSpread) === `auto` || (manifest == null ? void 0 : manifest.renditionSpread) === `landscape` || (manifest == null ? void 0 : manifest.renditionSpread) === `both`);
1937
1939
  };
1938
1940
  const isFullyPrePaginated = (manifest) => (manifest == null ? void 0 : manifest.renditionLayout) === "pre-paginated" || (manifest == null ? void 0 : manifest.spineItems.every((item) => item.renditionLayout === "pre-paginated"));
1939
- const areAllItemsPrePaginated = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
1940
1941
  class BridgeEvent {
1941
1942
  constructor() {
1942
1943
  this.navigationSubject = new ReplaySubject(1);
@@ -2021,7 +2022,6 @@ class Context {
2021
2022
  height: newState.visibleAreaRect.height - marginTop - marginBottom
2022
2023
  },
2023
2024
  ...newState.manifest && {
2024
- areAllItemsPrePaginated: areAllItemsPrePaginated(manifest),
2025
2025
  isFullyPrePaginated: isFullyPrePaginated(manifest)
2026
2026
  },
2027
2027
  isUsingSpreadMode: isUsingSpreadMode({
@@ -4076,28 +4076,21 @@ class UserNavigator extends DestroyableClass {
4076
4076
  this.navigation$ = this.navigationSubject.asObservable();
4077
4077
  const userScroll$ = element$.pipe(
4078
4078
  switchMap$1(
4079
- (element) => settings.values$.pipe(
4080
- map$1(({ computedPageTurnMode }) => computedPageTurnMode),
4081
- distinctUntilChanged$1(),
4082
- filter$1(
4083
- (computedPageTurnMode) => computedPageTurnMode === "scrollable"
4084
- ),
4085
- switchMap$1(() => {
4086
- return fromEvent(element, `scroll`).pipe(
4079
+ (element) => settings.watch(["computedPageTurnMode"]).pipe(
4080
+ switchMap$1(
4081
+ ({ computedPageTurnMode }) => computedPageTurnMode === "controlled" ? NEVER : fromEvent(element, `scroll`).pipe(
4087
4082
  withLatestFrom(scrollHappeningFromBrowser$),
4088
- filter$1(([, shouldAvoidScrollEvent]) => !shouldAvoidScrollEvent),
4083
+ filter$1(
4084
+ ([, shouldAvoidScrollEvent]) => !shouldAvoidScrollEvent
4085
+ ),
4089
4086
  map$1(([event]) => event)
4090
- );
4091
- })
4087
+ )
4088
+ )
4092
4089
  )
4093
4090
  ),
4094
4091
  share()
4095
4092
  );
4096
- const navigateOnScroll$ = settings.values$.pipe(
4097
- map$1(({ computedPageTurnMode }) => computedPageTurnMode),
4098
- distinctUntilChanged$1(),
4099
- filter$1((computedPageTurnMode) => computedPageTurnMode === "scrollable"),
4100
- switchMap$1(() => userScroll$),
4093
+ const navigateOnScroll$ = userScroll$.pipe(
4101
4094
  exhaustMap((event) => {
4102
4095
  const unlock = this.locker.lock();
4103
4096
  return merge(userScroll$, of(event)).pipe(
@@ -4264,20 +4257,8 @@ const restoreNavigationForScrollingPageTurnMode = ({
4264
4257
  });
4265
4258
  }
4266
4259
  if (!isPositionWithinSpineItem) {
4267
- if (navigation.directionFromLastNavigation === "backward") {
4268
- const positionInItem = {
4269
- y: height - positionYfromBottomPreviousNavigation,
4270
- x: navigation.position.x
4271
- };
4272
- return spineLocator.getSpinePositionFromSpineItemPosition({
4273
- spineItemPosition: spineLocator.getSafeSpineItemPositionFromUnsafeSpineItemPosition(
4274
- positionInItem,
4275
- foundSpineItem
4276
- ),
4277
- spineItem: foundSpineItem
4278
- });
4279
- }
4280
- if (navigation.directionFromLastNavigation === "forward" || navigation.directionFromLastNavigation === "anchor") {
4260
+ const positionIsBeforeItem = navigation.position.y < top;
4261
+ if (!positionIsBeforeItem) {
4281
4262
  const positionInItem = {
4282
4263
  y: height - positionYfromBottomPreviousNavigation,
4283
4264
  x: navigation.position.x
@@ -4973,11 +4954,17 @@ const createNavigator = ({
4973
4954
  spine
4974
4955
  );
4975
4956
  const isSpineScrolling$ = merge(
4976
- spine.elementResize$,
4957
+ spine.element$.pipe(switchMap((element) => observeResize(element))),
4977
4958
  spine.element$.pipe(switchMap((element) => fromEvent(element, "scroll"))),
4978
4959
  spine.spineItemsObserver.itemResize$
4979
4960
  ).pipe(
4980
- switchMap(() => merge(of(true), timer(5).pipe(map(() => false)))),
4961
+ switchMap(
4962
+ () => timer(10).pipe(
4963
+ map(() => false),
4964
+ startWith(true)
4965
+ )
4966
+ ),
4967
+ distinctUntilChanged(),
4981
4968
  startWith(false)
4982
4969
  );
4983
4970
  const scrollHappeningFromBrowser$ = combineLatest([
@@ -5135,20 +5122,13 @@ class ReaderSettingsManager extends SettingsManager3 {
5135
5122
  const computedSettings = {
5136
5123
  computedPageTurnDirection: settings.pageTurnDirection,
5137
5124
  computedPageTurnAnimation: settings.pageTurnAnimation,
5138
- computedPageTurnMode: `controlled`,
5125
+ computedPageTurnMode: settings.pageTurnMode,
5139
5126
  computedPageTurnAnimationDuration: 0
5140
5127
  };
5141
5128
  if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
5142
5129
  computedSettings.computedPageTurnMode = `scrollable`;
5143
- computedSettings.computedPageTurnDirection = `vertical`;
5144
- } else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
5145
- Report.warn(
5146
- `pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`
5147
- );
5148
- computedSettings.computedPageTurnAnimation = `none`;
5149
- computedSettings.computedPageTurnMode = `controlled`;
5150
- } else if (settings.pageTurnMode === `scrollable`) {
5151
- computedSettings.computedPageTurnMode = `scrollable`;
5130
+ }
5131
+ if (computedSettings.computedPageTurnMode === "scrollable") {
5152
5132
  computedSettings.computedPageTurnDirection = `vertical`;
5153
5133
  }
5154
5134
  if (hasVerticalWriting && computedSettings.computedPageTurnAnimation === `slide`) {
@@ -6670,10 +6650,6 @@ class Spine extends DestroyableClass {
6670
6650
  this.settings = settings;
6671
6651
  this.hookManager = hookManager;
6672
6652
  this.elementSubject = new BehaviorSubject(noopElement());
6673
- this.elementResize$ = this.elementSubject.pipe(
6674
- switchMap((element) => observeResize(element)),
6675
- share$1()
6676
- );
6677
6653
  this.element$ = this.elementSubject.asObservable();
6678
6654
  this.spineLayout = new SpineLayout(spineItemsManager, context, settings);
6679
6655
  this.locator = createSpineLocator({
@@ -6867,7 +6843,7 @@ const createReader = (inputSettings) => {
6867
6843
  }) => {
6868
6844
  return {
6869
6845
  ...stateSubject$.value,
6870
- supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : !context.state.areAllItemsPrePaginated ? [`controlled`] : [`controlled`, `scrollable`],
6846
+ supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : [`controlled`, `scrollable`],
6871
6847
  supportedPageTurnAnimation: renditionFlow === `scrolled-continuous` || computedPageTurnMode === `scrollable` ? [`none`] : hasVerticalWriting ? [`fade`, `none`] : [`fade`, `none`, `slide`],
6872
6848
  supportedPageTurnDirection: computedPageTurnMode === `scrollable` ? [`vertical`] : renditionLayout === `reflowable` ? [`horizontal`] : [`horizontal`, `vertical`]
6873
6849
  };
@@ -7218,23 +7194,20 @@ class ImageRenderer extends DocumentRenderer {
7218
7194
  onLayout({
7219
7195
  spreadPosition
7220
7196
  }) {
7221
- var _a, _b;
7222
7197
  const element = this.getImageElement();
7223
- const continuousScrollableReflowableItem = ((_a = this.context.manifest) == null ? void 0 : _a.renditionLayout) === "reflowable" && ((_b = this.context.manifest) == null ? void 0 : _b.renditionFlow) === "scrolled-continuous";
7224
7198
  const { height: pageHeight, width: pageWidth } = this.context.getPageSize();
7225
7199
  let height = pageHeight;
7226
7200
  const width = pageWidth;
7227
- if (element) {
7228
- const naturalWidth = element.naturalWidth;
7229
- const naturalHeight = element.naturalHeight;
7230
- const ratio = naturalWidth / naturalHeight;
7231
- if (continuousScrollableReflowableItem) {
7232
- height = pageWidth / ratio;
7233
- }
7234
- element.style.height = `${height}px`;
7235
- element.style.width = `${width}px`;
7236
- element.style.objectPosition = spreadPosition === "left" ? `right` : spreadPosition === `right` ? `left` : `center`;
7237
- }
7201
+ if (!element) return of(void 0);
7202
+ const naturalWidth = element.naturalWidth || 1;
7203
+ const naturalHeight = element.naturalHeight || 1;
7204
+ const ratio = naturalWidth / naturalHeight;
7205
+ if (this.settings.values.computedPageTurnDirection === "vertical" && this.settings.values.computedPageTurnMode === "scrollable" && !this.context.state.isUsingSpreadMode) {
7206
+ height = Math.ceil(pageWidth / ratio);
7207
+ }
7208
+ element.style.height = `${height}px`;
7209
+ element.style.width = `${width}px`;
7210
+ element.style.objectPosition = spreadPosition === "left" ? `right` : spreadPosition === `right` ? `left` : `center`;
7238
7211
  return of({
7239
7212
  width,
7240
7213
  height
@@ -7512,6 +7485,7 @@ const loadingEnhancer = (next) => (options) => {
7512
7485
  const reader = next(options);
7513
7486
  const createEntries$ = (items) => of(
7514
7487
  items.reduce((acc, { item, element }) => {
7488
+ element.style.zIndex = `0`;
7515
7489
  const alreadyExistingElement = element.querySelector(
7516
7490
  `.${CONTAINER_HTML_PREFIX}`
7517
7491
  );
@@ -8740,16 +8714,14 @@ const selectionEnhancer = (next) => (options) => {
8740
8714
  });
8741
8715
  return merge(...instances);
8742
8716
  }),
8717
+ startWith$1(void 0),
8743
8718
  distinctUntilChanged$1(),
8744
8719
  tap$1((value) => {
8745
8720
  lasSelection = value;
8746
8721
  }),
8747
8722
  shareReplay$1({ refCount: true, bufferSize: 1 })
8748
8723
  );
8749
- const selection$ = trackedSelection$.pipe(
8750
- filter$1((selection) => (selection == null ? void 0 : selection.type) === "change" || !selection),
8751
- share()
8752
- );
8724
+ const selection$ = trackedSelection$;
8753
8725
  const selectionStart$ = trackedSelection$.pipe(
8754
8726
  map$1((selection) => !!selection),
8755
8727
  distinctUntilChanged$1(),
@@ -8771,9 +8743,9 @@ const selectionEnhancer = (next) => (options) => {
8771
8743
  withLatestFrom(selection$),
8772
8744
  map$1(([, selection]) => selection),
8773
8745
  startWith$1(void 0),
8774
- shareReplay$1(1)
8746
+ shareReplay$1({ refCount: true, bufferSize: 1 })
8775
8747
  );
8776
- selection$.pipe(takeUntil(reader.$.destroy$)).subscribe();
8748
+ merge(selection$, lastSelectionOnPointerdown$).pipe(takeUntil(reader.$.destroy$)).subscribe();
8777
8749
  return {
8778
8750
  ...reader,
8779
8751
  selection: {