@prose-reader/core 1.203.0 → 1.204.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/createReaderWithEnhancer.d.ts +2 -2
- package/dist/enhancers/navigation/navigators/manualNavigator.d.ts +2 -1
- package/dist/enhancers/pagination/ResourcesLocator.d.ts +34 -0
- package/dist/enhancers/pagination/enhancer.d.ts +2 -12
- package/dist/enhancers/pagination/types.d.ts +11 -0
- package/dist/index.js +95 -72
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +95 -72
- package/dist/index.umd.cjs.map +1 -1
- package/dist/spineItem/SpineItem.d.ts +1 -0
- package/package.json +3 -3
- package/dist/enhancers/pagination/locate.d.ts +0 -28
|
@@ -128,9 +128,9 @@ export declare const createReaderWithEnhancers: (options: Partial<import('./sett
|
|
|
128
128
|
}, "state" | "state$"> & {
|
|
129
129
|
state$: import('rxjs').Observable<import('./pagination/Pagination').PaginationInfo & import('./enhancers/pagination/types').ExtraPaginationInfo>;
|
|
130
130
|
state: import('./pagination/Pagination').PaginationInfo & import('./enhancers/pagination/types').ExtraPaginationInfo;
|
|
131
|
-
} & {
|
|
132
|
-
locate: <T extends import('./enhancers/pagination/locate').LocatableResource>(resources: T[]) => import('rxjs').Observable<(import('./enhancers/pagination/locate').ConsolidatedResource & T)[]>;
|
|
133
131
|
};
|
|
132
|
+
locateResources: import('./enhancers/pagination/ResourcesLocator').ResourcesLocator["locateMultiple"];
|
|
133
|
+
locateResource: import('./enhancers/pagination/ResourcesLocator').ResourcesLocator["locate"];
|
|
134
134
|
} & {
|
|
135
135
|
theme: {
|
|
136
136
|
set: (theme: import('.').Theme) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UserNavigationEntry } from '../../../navigation/types';
|
|
2
2
|
import { Reader } from '../../../reader';
|
|
3
3
|
import { SpinePosition } from '../../../spine/types';
|
|
4
|
+
import { SpineItemReference } from '../../../spineItem/SpineItem';
|
|
4
5
|
export declare class ManualNavigator {
|
|
5
6
|
protected reader: Reader;
|
|
6
7
|
movingLastDelta: {
|
|
@@ -20,7 +21,7 @@ export declare class ManualNavigator {
|
|
|
20
21
|
animate: boolean;
|
|
21
22
|
}): void;
|
|
22
23
|
goToSpineItem({ indexOrId, ...rest }: {
|
|
23
|
-
indexOrId:
|
|
24
|
+
indexOrId: SpineItemReference;
|
|
24
25
|
} & Pick<UserNavigationEntry, "animation">): void;
|
|
25
26
|
goToNextSpineItem(): void;
|
|
26
27
|
goToPreviousSpineItem(): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { Reader } from '../../reader';
|
|
3
|
+
import { SpineItem } from '../../spineItem/SpineItem';
|
|
4
|
+
type CfiLocatableResource = {
|
|
5
|
+
cfi: string;
|
|
6
|
+
endCfi?: string;
|
|
7
|
+
};
|
|
8
|
+
export type LocatableResource = SpineItem | CfiLocatableResource;
|
|
9
|
+
export type ConsolidatedResource = CfiLocatableResource & {
|
|
10
|
+
itemIndex?: number;
|
|
11
|
+
itemPageIndex?: number;
|
|
12
|
+
absolutePageIndex?: number;
|
|
13
|
+
startNode?: Node;
|
|
14
|
+
startOffset?: number;
|
|
15
|
+
range?: Range;
|
|
16
|
+
};
|
|
17
|
+
export declare const consolidate: (resource: ConsolidatedResource, reader: Reader) => Observable<ConsolidatedResource>;
|
|
18
|
+
export declare class ResourcesLocator {
|
|
19
|
+
private reader;
|
|
20
|
+
constructor(reader: Reader);
|
|
21
|
+
locate: <T extends LocatableResource>(resource: T, options?: {
|
|
22
|
+
mode?: "shallow" | "load";
|
|
23
|
+
}) => Observable<{
|
|
24
|
+
resource: T;
|
|
25
|
+
meta: ConsolidatedResource;
|
|
26
|
+
}>;
|
|
27
|
+
locateMultiple: <T extends LocatableResource>(resources: T[], options?: {
|
|
28
|
+
mode?: "shallow" | "load";
|
|
29
|
+
}) => Observable<{
|
|
30
|
+
resource: T;
|
|
31
|
+
meta: ConsolidatedResource;
|
|
32
|
+
}[]>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { PaginationInfo } from '../../pagination/Pagination';
|
|
3
1
|
import { LayoutEnhancerOutput } from '../layout/layoutEnhancer';
|
|
4
2
|
import { EnhancerOutput, RootEnhancer } from '../types/enhancer';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export declare const paginationEnhancer: <InheritOptions, InheritOutput extends EnhancerOutput<RootEnhancer> & LayoutEnhancerOutput, PaginationOutput extends Omit<InheritOutput["pagination"], "state$" | "state"> & {
|
|
8
|
-
state$: Observable<PaginationInfo & ExtraPaginationInfo>;
|
|
9
|
-
state: PaginationInfo & ExtraPaginationInfo;
|
|
10
|
-
}>(next: (options: InheritOptions) => InheritOutput) => (options: InheritOptions) => Omit<InheritOutput, "pagination"> & {
|
|
11
|
-
pagination: PaginationOutput & {
|
|
12
|
-
locate: <T extends LocatableResource>(resources: T[]) => Observable<(ConsolidatedResource & T)[]>;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
3
|
+
import { PaginationEnhancerAPI } from './types';
|
|
4
|
+
export declare const paginationEnhancer: <InheritOptions, InheritOutput extends EnhancerOutput<RootEnhancer> & LayoutEnhancerOutput, PaginationOutput extends PaginationEnhancerAPI<InheritOutput>>(next: (options: InheritOptions) => InheritOutput) => (options: InheritOptions) => PaginationOutput;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
1
2
|
import { PaginationInfo } from '../../pagination/Pagination';
|
|
3
|
+
import { EnhancerOutput, RootEnhancer } from '../types/enhancer';
|
|
4
|
+
import { ResourcesLocator } from './ResourcesLocator';
|
|
2
5
|
import { ChapterInfo } from './chapters';
|
|
3
6
|
export type ExtraPaginationInfo = {
|
|
4
7
|
beginChapterInfo: ChapterInfo | undefined;
|
|
@@ -12,3 +15,11 @@ export type ExtraPaginationInfo = {
|
|
|
12
15
|
isUsingSpread: boolean;
|
|
13
16
|
};
|
|
14
17
|
export type EnhancerPaginationInto = PaginationInfo & ExtraPaginationInfo;
|
|
18
|
+
export type PaginationEnhancerAPI<InheritOutput extends EnhancerOutput<RootEnhancer>> = Omit<InheritOutput, "pagination"> & {
|
|
19
|
+
pagination: Omit<InheritOutput["pagination"], "state$" | "state"> & {
|
|
20
|
+
state$: Observable<PaginationInfo & ExtraPaginationInfo>;
|
|
21
|
+
state: PaginationInfo & ExtraPaginationInfo;
|
|
22
|
+
};
|
|
23
|
+
locateResources: ResourcesLocator["locateMultiple"];
|
|
24
|
+
locateResource: ResourcesLocator["locate"];
|
|
25
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1087,7 +1087,7 @@ const _DocumentRenderer = class _DocumentRenderer extends DestroyableClass {
|
|
|
1087
1087
|
);
|
|
1088
1088
|
}
|
|
1089
1089
|
layout(params) {
|
|
1090
|
-
return defer(() => this.onLayout(params))
|
|
1090
|
+
return defer(() => this.onLayout(params));
|
|
1091
1091
|
}
|
|
1092
1092
|
destroy() {
|
|
1093
1093
|
this.unload();
|
|
@@ -3062,7 +3062,7 @@ class ManualNavigator {
|
|
|
3062
3062
|
return;
|
|
3063
3063
|
}
|
|
3064
3064
|
this.reader.navigation.navigate({
|
|
3065
|
-
spineItem:
|
|
3065
|
+
spineItem: spineItem.index,
|
|
3066
3066
|
...rest
|
|
3067
3067
|
});
|
|
3068
3068
|
}
|
|
@@ -3336,91 +3336,118 @@ const navigationEnhancer = (next) => (options) => {
|
|
|
3336
3336
|
}
|
|
3337
3337
|
};
|
|
3338
3338
|
};
|
|
3339
|
-
const
|
|
3340
|
-
const
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
if (
|
|
3346
|
-
|
|
3347
|
-
|
|
3339
|
+
const getItemAnchor = (item) => `|[prose~anchor~${encodeURIComponent(item.index)}]`;
|
|
3340
|
+
const getRootCfi = (spineItem) => {
|
|
3341
|
+
const itemAnchor = getItemAnchor(spineItem.item);
|
|
3342
|
+
return `epubcfi(/0${itemAnchor})`;
|
|
3343
|
+
};
|
|
3344
|
+
const toCfiLocatableResource = (reader, resource) => {
|
|
3345
|
+
if ("cfi" in resource) {
|
|
3346
|
+
return resource;
|
|
3347
|
+
}
|
|
3348
|
+
const item = reader.spineItemsManager.get(resource);
|
|
3349
|
+
if (!item) {
|
|
3350
|
+
throw new Error(`Spine item not found`);
|
|
3348
3351
|
}
|
|
3352
|
+
return {
|
|
3353
|
+
cfi: getRootCfi(item)
|
|
3354
|
+
};
|
|
3355
|
+
};
|
|
3356
|
+
const consolidate = (resource, reader) => {
|
|
3357
|
+
let itemPageIndex = resource == null ? void 0 : resource.itemPageIndex;
|
|
3358
|
+
const { itemIndex } = reader.cfi.parseCfi(resource.cfi);
|
|
3359
|
+
const spineItem = reader.spineItemsManager.get(itemIndex);
|
|
3360
|
+
if (!spineItem) return of({ ...resource, itemIndex });
|
|
3349
3361
|
return idle().pipe(
|
|
3350
3362
|
withLatestFrom(spineItem.isReady$),
|
|
3351
3363
|
map(([, isSpineItemReady]) => {
|
|
3352
|
-
var
|
|
3364
|
+
var _a;
|
|
3353
3365
|
let range = void 0;
|
|
3354
|
-
const { node: startNode, offset: startOffset } = reader.cfi.resolveCfi({ cfi:
|
|
3355
|
-
|
|
3366
|
+
const { node: startNode, offset: startOffset } = reader.cfi.resolveCfi({ cfi: resource.cfi }) ?? {};
|
|
3367
|
+
const reflowableItemWithFoundNode = spineItem.renditionLayout !== `pre-paginated` && startNode;
|
|
3368
|
+
if (reflowableItemWithFoundNode) {
|
|
3356
3369
|
itemPageIndex = reader.spine.locator.spineItemLocator.getSpineItemPageIndexFromNode(
|
|
3357
3370
|
startNode,
|
|
3358
3371
|
startOffset ?? 0,
|
|
3359
3372
|
spineItem
|
|
3360
3373
|
) ?? itemPageIndex;
|
|
3361
3374
|
}
|
|
3362
|
-
if (startNode &&
|
|
3363
|
-
const { node: endNode, offset: endOffset } = reader.cfi.resolveCfi({ cfi:
|
|
3375
|
+
if (startNode && resource.endCfi) {
|
|
3376
|
+
const { node: endNode, offset: endOffset } = reader.cfi.resolveCfi({ cfi: resource.cfi }) ?? {};
|
|
3364
3377
|
if (endNode && isSpineItemReady) {
|
|
3365
|
-
range = (
|
|
3378
|
+
range = (_a = startNode == null ? void 0 : startNode.ownerDocument) == null ? void 0 : _a.createRange();
|
|
3366
3379
|
range == null ? void 0 : range.setStart(startNode, startOffset ?? 0);
|
|
3367
3380
|
range == null ? void 0 : range.setEnd(endNode, endOffset ?? 0);
|
|
3368
3381
|
}
|
|
3369
3382
|
}
|
|
3370
|
-
let absolutePageIndex =
|
|
3371
|
-
if (itemPageIndex
|
|
3372
|
-
|
|
3373
|
-
pageIndex: itemPageIndex,
|
|
3374
|
-
spineItemOrId: spineItem
|
|
3375
|
-
}) ?? ((_c = item.meta) == null ? void 0 : _c.absolutePageIndex);
|
|
3383
|
+
let absolutePageIndex = resource == null ? void 0 : resource.absolutePageIndex;
|
|
3384
|
+
if (itemPageIndex === void 0) {
|
|
3385
|
+
itemPageIndex = 0;
|
|
3376
3386
|
}
|
|
3387
|
+
absolutePageIndex = reader.spine.locator.getAbsolutePageIndexFromPageIndex({
|
|
3388
|
+
pageIndex: itemPageIndex,
|
|
3389
|
+
spineItemOrId: spineItem
|
|
3390
|
+
}) ?? (resource == null ? void 0 : resource.absolutePageIndex);
|
|
3377
3391
|
return {
|
|
3378
|
-
...
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
absolutePageIndex,
|
|
3386
|
-
itemPageIndex
|
|
3387
|
-
}
|
|
3392
|
+
...resource,
|
|
3393
|
+
range,
|
|
3394
|
+
itemIndex,
|
|
3395
|
+
startNode,
|
|
3396
|
+
startOffset,
|
|
3397
|
+
absolutePageIndex,
|
|
3398
|
+
itemPageIndex
|
|
3388
3399
|
};
|
|
3389
3400
|
})
|
|
3390
3401
|
);
|
|
3391
3402
|
};
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
)
|
|
3403
|
+
class ResourcesLocator {
|
|
3404
|
+
constructor(reader) {
|
|
3405
|
+
this.reader = reader;
|
|
3406
|
+
this.locate = (resource, options = {}) => {
|
|
3407
|
+
const cfiConsolidatedResource = {
|
|
3408
|
+
resource,
|
|
3409
|
+
meta: toCfiLocatableResource(this.reader, resource)
|
|
3410
|
+
};
|
|
3411
|
+
return deferIdle(() => {
|
|
3412
|
+
var _a;
|
|
3413
|
+
const consolidate$ = this.reader.spine.spineLayout.layout$.pipe(
|
|
3414
|
+
debounceTime$1(10),
|
|
3415
|
+
startWith$1(cfiConsolidatedResource),
|
|
3416
|
+
switchScan((acc) => {
|
|
3417
|
+
return consolidate(acc.meta, this.reader).pipe(
|
|
3418
|
+
map((consolidatedResource) => ({
|
|
3419
|
+
...acc,
|
|
3420
|
+
meta: consolidatedResource
|
|
3421
|
+
}))
|
|
3422
|
+
);
|
|
3423
|
+
}, cfiConsolidatedResource)
|
|
3405
3424
|
);
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
})
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3425
|
+
const itemIndex = (_a = this.reader.cfi.parseCfi(
|
|
3426
|
+
cfiConsolidatedResource.meta.cfi
|
|
3427
|
+
)) == null ? void 0 : _a.itemIndex;
|
|
3428
|
+
const item = this.reader.spineItemsManager.get(itemIndex);
|
|
3429
|
+
const isReflowable = (item == null ? void 0 : item.renditionLayout) === `reflowable`;
|
|
3430
|
+
const release = options.mode === "shallow" || !isReflowable || !item ? () => {
|
|
3431
|
+
} : this.reader.spine.spineItemsLoader.forceOpen([item.index]);
|
|
3432
|
+
return consolidate$.pipe(
|
|
3433
|
+
finalize(() => {
|
|
3434
|
+
setTimeout(() => {
|
|
3435
|
+
release();
|
|
3436
|
+
}, 1e3);
|
|
3437
|
+
})
|
|
3438
|
+
);
|
|
3439
|
+
});
|
|
3440
|
+
};
|
|
3441
|
+
this.locateMultiple = (resources, options = {}) => {
|
|
3442
|
+
return deferIdle(
|
|
3443
|
+
() => combineLatest(
|
|
3444
|
+
resources.map((resource) => this.locate(resource, options))
|
|
3445
|
+
)
|
|
3446
|
+
);
|
|
3447
|
+
};
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
const NAMESPACE$4 = `paginationEnhancer`;
|
|
3424
3451
|
const buildChaptersInfo = (href, tocItem, manifest) => {
|
|
3425
3452
|
const spineItemIndex = manifest.spineItems.findIndex(
|
|
3426
3453
|
(item) => item.href === href
|
|
@@ -3696,14 +3723,15 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
3696
3723
|
const reader = next(options);
|
|
3697
3724
|
const { paginationInfo$, getPaginationInfo } = trackPaginationInfo(reader);
|
|
3698
3725
|
paginationInfo$.pipe(takeUntil(reader.$.destroy$)).subscribe();
|
|
3699
|
-
const
|
|
3726
|
+
const resourcesLocator = new ResourcesLocator(reader);
|
|
3700
3727
|
return {
|
|
3701
3728
|
...reader,
|
|
3729
|
+
locateResources: resourcesLocator.locateMultiple,
|
|
3730
|
+
locateResource: resourcesLocator.locate,
|
|
3702
3731
|
pagination: {
|
|
3703
3732
|
...reader.pagination,
|
|
3704
3733
|
getState: () => getPaginationInfo(),
|
|
3705
|
-
state$: paginationInfo
|
|
3706
|
-
locate
|
|
3734
|
+
state$: paginationInfo$
|
|
3707
3735
|
}
|
|
3708
3736
|
};
|
|
3709
3737
|
};
|
|
@@ -4413,7 +4441,6 @@ const zoomEnhancer = (next) => (options) => {
|
|
|
4413
4441
|
}
|
|
4414
4442
|
};
|
|
4415
4443
|
};
|
|
4416
|
-
const getItemAnchor = (item) => `|[prose~anchor~${encodeURIComponent(item.index)}]`;
|
|
4417
4444
|
const ELEMENT_NODE = Node.ELEMENT_NODE;
|
|
4418
4445
|
const TEXT_NODE = Node.TEXT_NODE;
|
|
4419
4446
|
const CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE;
|
|
@@ -5306,10 +5333,6 @@ const generateCfi = (node, offset, item) => {
|
|
|
5306
5333
|
`${getItemAnchor(item)}|${offsetAnchor}`
|
|
5307
5334
|
);
|
|
5308
5335
|
};
|
|
5309
|
-
const getRootCfi = (spineItem) => {
|
|
5310
|
-
const itemAnchor = getItemAnchor(spineItem.item);
|
|
5311
|
-
return `epubcfi(/0${itemAnchor})`;
|
|
5312
|
-
};
|
|
5313
5336
|
const generateCfiForSpineItemPage = Report.measurePerformance(
|
|
5314
5337
|
`getCfi`,
|
|
5315
5338
|
10,
|