@papyrus-sdk/ui-react-native 0.2.35-beta.11.epub.1 → 0.2.35-beta.11.epub.2
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 +55 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/comicRuntime.test.ts +9 -9
- package/runtime/epubReader.js +32 -7
- package/runtime/epubReader.test.ts +52 -0
- package/runtime/index.html +55 -11
- package/runtime/runtime.js +55 -11
package/dist/index.js
CHANGED
|
@@ -20529,13 +20529,36 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20529
20529
|
if(elapsed>=0 && elapsed<450 && Math.hypot(dx,dy)<=12)return 'tap';
|
|
20530
20530
|
return null;
|
|
20531
20531
|
}
|
|
20532
|
-
function location(raw,count,readingMode){
|
|
20532
|
+
function location(raw,count,readingMode,geometry){
|
|
20533
20533
|
var start=raw && raw.start;if(!start || !validCfi(start.cfi))return null;
|
|
20534
20534
|
var displayed=start.displayed||{},chapter=Math.max(1,(Number(start.index)||0)+1);
|
|
20535
20535
|
var visualPage=mode(readingMode)==='paged' && Number.isFinite(displayed.page)?displayed.page:null;
|
|
20536
20536
|
var total=mode(readingMode)==='paged' && Number.isFinite(displayed.total)?displayed.total:null;
|
|
20537
|
+
var atStart=Boolean(raw.atStart),atEnd=Boolean(raw.atEnd);
|
|
20538
|
+
// Chromium may round a column offset down by a fraction of a CSS pixel.
|
|
20539
|
+
// Keep epub.js authoritative outside a 1px boundary, and for RTL layouts.
|
|
20540
|
+
if(visualPage!==null && total>0 && geometry && geometry.direction==='ltr' && geometry.pageWidth>0 && Number.isFinite(geometry.offset)){
|
|
20541
|
+
var boundary=Math.round(geometry.offset/geometry.pageWidth);
|
|
20542
|
+
if(Math.abs(geometry.offset-boundary*geometry.pageWidth)<=1){
|
|
20543
|
+
visualPage=Math.min(total,Math.max(1,boundary+1));
|
|
20544
|
+
atStart=chapter===(geometry.firstIndex ?? 0)+1 && visualPage===1;
|
|
20545
|
+
atEnd=chapter===(geometry.lastIndex ?? count-1)+1 && visualPage===total;
|
|
20546
|
+
}
|
|
20547
|
+
}
|
|
20537
20548
|
var fraction=total?Math.max(0,(visualPage-1)/total):0;
|
|
20538
|
-
return {version:1,cfi:start.cfi,href:start.href||'',chapter:chapter,chapterCount:count,visualPage:visualPage,visualPageCount:total,progress:Math.min(1,Math.max(0,(chapter-1+fraction)/Math.max(1,count))),mode:mode(readingMode),atStart:
|
|
20549
|
+
return {version:1,cfi:start.cfi,href:start.href||'',chapter:chapter,chapterCount:count,visualPage:visualPage,visualPageCount:total,progress:Math.min(1,Math.max(0,(chapter-1+fraction)/Math.max(1,count))),mode:mode(readingMode),atStart:atStart,atEnd:atEnd};
|
|
20550
|
+
}
|
|
20551
|
+
function installResizeAnchor(manager,readCfi){
|
|
20552
|
+
var original=manager.resize,anchor=null;
|
|
20553
|
+
function resize(width,height,target){
|
|
20554
|
+
if(validCfi(target))anchor=target;
|
|
20555
|
+
if(!anchor){var current=readCfi();if(validCfi(current))anchor=current;}
|
|
20556
|
+
// epub.js accepts a logical target as its third argument. Keep it across
|
|
20557
|
+
// keyboard/dialog reflows instead of adopting each new viewport start.
|
|
20558
|
+
return original.call(this,width,height,anchor || target);
|
|
20559
|
+
}
|
|
20560
|
+
manager.resize=resize;
|
|
20561
|
+
return {cfi:function(){return anchor;},invalidate:function(){anchor=null;},destroy:function(){if(manager.resize===resize)manager.resize=original;anchor=null;}};
|
|
20539
20562
|
}
|
|
20540
20563
|
function install(contents,config){
|
|
20541
20564
|
var doc=contents.document,win=contents.window,start=null,blocked=false;
|
|
@@ -20543,13 +20566,15 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20543
20566
|
function selected(){return Boolean(String(win.getSelection()||'').trim()) || config.blocked();}
|
|
20544
20567
|
function interactive(target){return Boolean(target && target.closest && target.closest('a,button,input,textarea,select,[contenteditable="true"],[data-papyrus-overlay]'));}
|
|
20545
20568
|
function begin(e){start=point(e);blocked=e.touches.length!==1 || selected() || interactive(e.target);}
|
|
20546
|
-
function
|
|
20547
|
-
function
|
|
20569
|
+
function invalidateScroll(finish){if(config.current() && start && finish && config.mode()==='chapter-scroll' && !blocked && !selected() && Math.abs(finish.y-start.y)>12 && Math.abs(finish.y-start.y)>Math.abs(finish.x-start.x) && config.interact)config.interact();}
|
|
20570
|
+
function move(e){if(e.touches.length!==1)blocked=true;invalidateScroll(point(e));}
|
|
20571
|
+
function end(e){var finish=point(e);invalidateScroll(finish);var action=gesture(start,finish,{mode:config.mode(),rtl:config.rtl(),selected:selected(),interactive:blocked||interactive(e.target)||Boolean(config.annotationHit && config.annotationHit(point(e))),multitouch:blocked});start=null;if(!config.current())return;if(action==='tap')config.tap();else if(action)config.turn(action==='next'?1:-1);}
|
|
20548
20572
|
function cancel(){start=null;blocked=true;}
|
|
20549
|
-
|
|
20550
|
-
|
|
20573
|
+
function link(e){if(config.current() && e.target?.closest?.('a') && config.interact)config.interact();}
|
|
20574
|
+
doc.addEventListener('touchstart',begin,{passive:true});doc.addEventListener('touchmove',move,{passive:true});doc.addEventListener('touchend',end,{passive:true});doc.addEventListener('touchcancel',cancel,{passive:true});doc.addEventListener('click',link);
|
|
20575
|
+
return function(){doc.removeEventListener('touchstart',begin);doc.removeEventListener('touchmove',move);doc.removeEventListener('touchend',end);doc.removeEventListener('touchcancel',cancel);doc.removeEventListener('click',link);};
|
|
20551
20576
|
}
|
|
20552
|
-
root.PapyrusEpubReader={mode:mode,validCfi:validCfi,options:options,gesture:gesture,location:location,install:install};
|
|
20577
|
+
root.PapyrusEpubReader={mode:mode,validCfi:validCfi,options:options,gesture:gesture,location:location,installResizeAnchor:installResizeAnchor,install:install};
|
|
20553
20578
|
})(typeof window==='undefined'?globalThis:window);
|
|
20554
20579
|
|
|
20555
20580
|
/* @papyrus-epub-reader:end */
|
|
@@ -20684,6 +20709,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20684
20709
|
let currentType = null;
|
|
20685
20710
|
let book = null;
|
|
20686
20711
|
let rendition = null;
|
|
20712
|
+
let epubResizeAnchor = null;
|
|
20687
20713
|
let documentSessionId = null;
|
|
20688
20714
|
let annotationDocumentId;
|
|
20689
20715
|
let annotationLabels = {};
|
|
@@ -21096,6 +21122,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21096
21122
|
};
|
|
21097
21123
|
|
|
21098
21124
|
const clearViewer = () => {
|
|
21125
|
+
if(epubResizeAnchor){epubResizeAnchor.destroy();epubResizeAnchor=null;}
|
|
21099
21126
|
epubAnnotationRenderers.forEach(renderer => renderer.destroy());
|
|
21100
21127
|
epubAnnotationRenderers.clear();
|
|
21101
21128
|
if (epubInteractionCleanup) {
|
|
@@ -21783,10 +21810,12 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21783
21810
|
blocked: () => Boolean(nativeMenuSelection && String(nativeMenuSelection.contents?.window?.getSelection() || '').trim()),
|
|
21784
21811
|
annotationHit: point => epubAnnotationRenderers.get(contents)?.hit(point.x,point.y),
|
|
21785
21812
|
current: () => session === documentSessionId && activeRendition === rendition,
|
|
21813
|
+
interact: () => epubResizeAnchor?.invalidate(),
|
|
21786
21814
|
tap: () => sendEvent('EPUB_CONTENT_TAP',{documentSessionId:session}),
|
|
21787
21815
|
turn: direction => {
|
|
21788
21816
|
epubNavigationQueue = epubNavigationQueue.catch(()=>{}).then(() => {
|
|
21789
21817
|
if(session !== documentSessionId || activeRendition !== rendition)return;
|
|
21818
|
+
epubResizeAnchor?.invalidate();
|
|
21790
21819
|
return direction<0?activeRendition.prev():activeRendition.next();
|
|
21791
21820
|
});
|
|
21792
21821
|
epubNavigationQueue.catch(error => sendEvent('EPUB_NAVIGATION_ERROR',{message:String(error)}));
|
|
@@ -21904,8 +21933,18 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21904
21933
|
if (index < 0 && start && start.href) index = getSpineIndexByHref(start.href);
|
|
21905
21934
|
if (index < 0 || index >= spineItems.length) return;
|
|
21906
21935
|
epubScrollDiagnostics && epubScrollDiagnostics.relocated(location);
|
|
21907
|
-
|
|
21936
|
+
let pageGeometry;
|
|
21937
|
+
const manager=rendition.manager,layout=manager?.layout;
|
|
21938
|
+
if(epubViewMode==='single' && layout?.divisor===1 && !manager?.settings?.fullsize && manager?.settings?.direction==='ltr'){
|
|
21939
|
+
const visible=manager.visible?.();
|
|
21940
|
+
const view=visible?.find(view=>view.index===index);
|
|
21941
|
+
if(view && manager.container){
|
|
21942
|
+
pageGeometry={direction:'ltr',firstIndex:book.spine.first()?.index,lastIndex:book.spine.last()?.index,pageWidth:layout.pageWidth,offset:manager.container.getBoundingClientRect().left-view.position().left};
|
|
21943
|
+
}
|
|
21944
|
+
}
|
|
21945
|
+
epubLocation=window.PapyrusEpubReader.location(location,spineItems.length,epubViewMode==='single'?'paged':'chapter-scroll',pageGeometry);
|
|
21908
21946
|
if(epubLocation){
|
|
21947
|
+
epubLocation.cfi=epubResizeAnchor?.cfi() || epubLocation.cfi;
|
|
21909
21948
|
if(book.locations?.length?.()>0)epubLocation.progress=book.locations.percentageFromCfi(epubLocation.cfi);
|
|
21910
21949
|
sendEvent('EPUB_LOCATION',{documentSessionId,location:epubLocation});
|
|
21911
21950
|
}
|
|
@@ -21925,6 +21964,8 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21925
21964
|
);
|
|
21926
21965
|
if (!isCurrentLoad()) throw new Error('EPUB load superseded by a newer load');
|
|
21927
21966
|
sendEpubDiagnostic('epub.display.end', diagnosticPayload);
|
|
21967
|
+
const resizeRendition=rendition;
|
|
21968
|
+
epubResizeAnchor=window.PapyrusEpubReader.installResizeAnchor(resizeRendition.manager,()=>resizeRendition.location?.start?.cfi);
|
|
21928
21969
|
if (
|
|
21929
21970
|
rendition &&
|
|
21930
21971
|
rendition.manager &&
|
|
@@ -22058,6 +22099,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22058
22099
|
const request = ++epubNavigationRequest;
|
|
22059
22100
|
const navigation = epubNavigationQueue.catch(() => {}).then(async () => {
|
|
22060
22101
|
if (request !== epubNavigationRequest || session !== documentSessionId || activeRendition !== rendition) return;
|
|
22102
|
+
epubResizeAnchor?.invalidate();
|
|
22061
22103
|
await activeRendition.display(target);
|
|
22062
22104
|
if (request !== epubNavigationRequest || session !== documentSessionId || activeRendition !== rendition) return;
|
|
22063
22105
|
currentPage = pageIndex + 1;
|
|
@@ -22247,6 +22289,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22247
22289
|
epubNavigationRequest += 1;
|
|
22248
22290
|
const navigation = epubNavigationQueue.catch(() => {}).then(async () => {
|
|
22249
22291
|
if(navigationSession !== documentSessionId || activeRendition !== rendition)throw new Error('Stale EPUB navigation');
|
|
22292
|
+
epubResizeAnchor?.invalidate();
|
|
22250
22293
|
await activeRendition.display(annotation.anchor.href);
|
|
22251
22294
|
if(navigationSession !== documentSessionId || activeRendition !== rendition)throw new Error('Stale EPUB navigation');
|
|
22252
22295
|
const contents = activeRendition.getContents().find(c => spineItems[c.sectionIndex]?.href === annotation.anchor.href);
|
|
@@ -22288,6 +22331,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22288
22331
|
const active = rendition;
|
|
22289
22332
|
epubNavigationQueue = epubNavigationQueue.catch(() => {}).then(() => {
|
|
22290
22333
|
if (active !== rendition || payload.documentSessionId !== documentSessionId) return;
|
|
22334
|
+
epubResizeAnchor?.invalidate();
|
|
22291
22335
|
return payload.direction < 0 ? active.prev() : active.next();
|
|
22292
22336
|
});
|
|
22293
22337
|
await epubNavigationQueue;
|
|
@@ -22300,7 +22344,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22300
22344
|
{
|
|
22301
22345
|
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(async()=>{
|
|
22302
22346
|
if(payload.documentSessionId!==documentSessionId || next===epubViewMode)return;
|
|
22303
|
-
const target=epubLocation?.cfi;
|
|
22347
|
+
const target=epubResizeAnchor?.cfi() || epubLocation?.cfi;
|
|
22304
22348
|
epubViewMode=next;
|
|
22305
22349
|
await renderEpubRendition('layout',epubLoadGeneration,target);
|
|
22306
22350
|
});
|
|
@@ -22310,7 +22354,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22310
22354
|
}
|
|
22311
22355
|
if(kind === 'epub-go-to-location'){
|
|
22312
22356
|
if(currentType!=='epub' || payload.documentSessionId!==documentSessionId || !window.PapyrusEpubReader.validCfi(payload.cfi))throw new Error('Invalid EPUB location');
|
|
22313
|
-
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(()=>payload.documentSessionId
|
|
22357
|
+
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(()=>{if(payload.documentSessionId!==documentSessionId)return;epubResizeAnchor?.invalidate();return rendition.display(payload.cfi);});
|
|
22314
22358
|
await epubNavigationQueue;sendResponse(id,true,null);return;
|
|
22315
22359
|
}
|
|
22316
22360
|
|
|
@@ -22321,7 +22365,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22321
22365
|
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(async()=>{
|
|
22322
22366
|
if(session!==documentSessionId)return;
|
|
22323
22367
|
const active=rendition;
|
|
22324
|
-
const cfi=epubLocation?.cfi;
|
|
22368
|
+
const cfi=epubResizeAnchor?.cfi() || epubLocation?.cfi;
|
|
22325
22369
|
zoom=requestedZoom;applyEpubZoom();
|
|
22326
22370
|
// Let the content CSS update before redisplaying the logical anchor.
|
|
22327
22371
|
await new Promise(resolve=>(window.requestAnimationFrame || (callback=>setTimeout(callback,0)))(resolve));
|