@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.mjs
CHANGED
|
@@ -20524,13 +20524,36 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20524
20524
|
if(elapsed>=0 && elapsed<450 && Math.hypot(dx,dy)<=12)return 'tap';
|
|
20525
20525
|
return null;
|
|
20526
20526
|
}
|
|
20527
|
-
function location(raw,count,readingMode){
|
|
20527
|
+
function location(raw,count,readingMode,geometry){
|
|
20528
20528
|
var start=raw && raw.start;if(!start || !validCfi(start.cfi))return null;
|
|
20529
20529
|
var displayed=start.displayed||{},chapter=Math.max(1,(Number(start.index)||0)+1);
|
|
20530
20530
|
var visualPage=mode(readingMode)==='paged' && Number.isFinite(displayed.page)?displayed.page:null;
|
|
20531
20531
|
var total=mode(readingMode)==='paged' && Number.isFinite(displayed.total)?displayed.total:null;
|
|
20532
|
+
var atStart=Boolean(raw.atStart),atEnd=Boolean(raw.atEnd);
|
|
20533
|
+
// Chromium may round a column offset down by a fraction of a CSS pixel.
|
|
20534
|
+
// Keep epub.js authoritative outside a 1px boundary, and for RTL layouts.
|
|
20535
|
+
if(visualPage!==null && total>0 && geometry && geometry.direction==='ltr' && geometry.pageWidth>0 && Number.isFinite(geometry.offset)){
|
|
20536
|
+
var boundary=Math.round(geometry.offset/geometry.pageWidth);
|
|
20537
|
+
if(Math.abs(geometry.offset-boundary*geometry.pageWidth)<=1){
|
|
20538
|
+
visualPage=Math.min(total,Math.max(1,boundary+1));
|
|
20539
|
+
atStart=chapter===(geometry.firstIndex ?? 0)+1 && visualPage===1;
|
|
20540
|
+
atEnd=chapter===(geometry.lastIndex ?? count-1)+1 && visualPage===total;
|
|
20541
|
+
}
|
|
20542
|
+
}
|
|
20532
20543
|
var fraction=total?Math.max(0,(visualPage-1)/total):0;
|
|
20533
|
-
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:
|
|
20544
|
+
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};
|
|
20545
|
+
}
|
|
20546
|
+
function installResizeAnchor(manager,readCfi){
|
|
20547
|
+
var original=manager.resize,anchor=null;
|
|
20548
|
+
function resize(width,height,target){
|
|
20549
|
+
if(validCfi(target))anchor=target;
|
|
20550
|
+
if(!anchor){var current=readCfi();if(validCfi(current))anchor=current;}
|
|
20551
|
+
// epub.js accepts a logical target as its third argument. Keep it across
|
|
20552
|
+
// keyboard/dialog reflows instead of adopting each new viewport start.
|
|
20553
|
+
return original.call(this,width,height,anchor || target);
|
|
20554
|
+
}
|
|
20555
|
+
manager.resize=resize;
|
|
20556
|
+
return {cfi:function(){return anchor;},invalidate:function(){anchor=null;},destroy:function(){if(manager.resize===resize)manager.resize=original;anchor=null;}};
|
|
20534
20557
|
}
|
|
20535
20558
|
function install(contents,config){
|
|
20536
20559
|
var doc=contents.document,win=contents.window,start=null,blocked=false;
|
|
@@ -20538,13 +20561,15 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20538
20561
|
function selected(){return Boolean(String(win.getSelection()||'').trim()) || config.blocked();}
|
|
20539
20562
|
function interactive(target){return Boolean(target && target.closest && target.closest('a,button,input,textarea,select,[contenteditable="true"],[data-papyrus-overlay]'));}
|
|
20540
20563
|
function begin(e){start=point(e);blocked=e.touches.length!==1 || selected() || interactive(e.target);}
|
|
20541
|
-
function
|
|
20542
|
-
function
|
|
20564
|
+
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();}
|
|
20565
|
+
function move(e){if(e.touches.length!==1)blocked=true;invalidateScroll(point(e));}
|
|
20566
|
+
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);}
|
|
20543
20567
|
function cancel(){start=null;blocked=true;}
|
|
20544
|
-
|
|
20545
|
-
|
|
20568
|
+
function link(e){if(config.current() && e.target?.closest?.('a') && config.interact)config.interact();}
|
|
20569
|
+
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);
|
|
20570
|
+
return function(){doc.removeEventListener('touchstart',begin);doc.removeEventListener('touchmove',move);doc.removeEventListener('touchend',end);doc.removeEventListener('touchcancel',cancel);doc.removeEventListener('click',link);};
|
|
20546
20571
|
}
|
|
20547
|
-
root.PapyrusEpubReader={mode:mode,validCfi:validCfi,options:options,gesture:gesture,location:location,install:install};
|
|
20572
|
+
root.PapyrusEpubReader={mode:mode,validCfi:validCfi,options:options,gesture:gesture,location:location,installResizeAnchor:installResizeAnchor,install:install};
|
|
20548
20573
|
})(typeof window==='undefined'?globalThis:window);
|
|
20549
20574
|
|
|
20550
20575
|
/* @papyrus-epub-reader:end */
|
|
@@ -20679,6 +20704,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
20679
20704
|
let currentType = null;
|
|
20680
20705
|
let book = null;
|
|
20681
20706
|
let rendition = null;
|
|
20707
|
+
let epubResizeAnchor = null;
|
|
20682
20708
|
let documentSessionId = null;
|
|
20683
20709
|
let annotationDocumentId;
|
|
20684
20710
|
let annotationLabels = {};
|
|
@@ -21091,6 +21117,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21091
21117
|
};
|
|
21092
21118
|
|
|
21093
21119
|
const clearViewer = () => {
|
|
21120
|
+
if(epubResizeAnchor){epubResizeAnchor.destroy();epubResizeAnchor=null;}
|
|
21094
21121
|
epubAnnotationRenderers.forEach(renderer => renderer.destroy());
|
|
21095
21122
|
epubAnnotationRenderers.clear();
|
|
21096
21123
|
if (epubInteractionCleanup) {
|
|
@@ -21778,10 +21805,12 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21778
21805
|
blocked: () => Boolean(nativeMenuSelection && String(nativeMenuSelection.contents?.window?.getSelection() || '').trim()),
|
|
21779
21806
|
annotationHit: point => epubAnnotationRenderers.get(contents)?.hit(point.x,point.y),
|
|
21780
21807
|
current: () => session === documentSessionId && activeRendition === rendition,
|
|
21808
|
+
interact: () => epubResizeAnchor?.invalidate(),
|
|
21781
21809
|
tap: () => sendEvent('EPUB_CONTENT_TAP',{documentSessionId:session}),
|
|
21782
21810
|
turn: direction => {
|
|
21783
21811
|
epubNavigationQueue = epubNavigationQueue.catch(()=>{}).then(() => {
|
|
21784
21812
|
if(session !== documentSessionId || activeRendition !== rendition)return;
|
|
21813
|
+
epubResizeAnchor?.invalidate();
|
|
21785
21814
|
return direction<0?activeRendition.prev():activeRendition.next();
|
|
21786
21815
|
});
|
|
21787
21816
|
epubNavigationQueue.catch(error => sendEvent('EPUB_NAVIGATION_ERROR',{message:String(error)}));
|
|
@@ -21899,8 +21928,18 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21899
21928
|
if (index < 0 && start && start.href) index = getSpineIndexByHref(start.href);
|
|
21900
21929
|
if (index < 0 || index >= spineItems.length) return;
|
|
21901
21930
|
epubScrollDiagnostics && epubScrollDiagnostics.relocated(location);
|
|
21902
|
-
|
|
21931
|
+
let pageGeometry;
|
|
21932
|
+
const manager=rendition.manager,layout=manager?.layout;
|
|
21933
|
+
if(epubViewMode==='single' && layout?.divisor===1 && !manager?.settings?.fullsize && manager?.settings?.direction==='ltr'){
|
|
21934
|
+
const visible=manager.visible?.();
|
|
21935
|
+
const view=visible?.find(view=>view.index===index);
|
|
21936
|
+
if(view && manager.container){
|
|
21937
|
+
pageGeometry={direction:'ltr',firstIndex:book.spine.first()?.index,lastIndex:book.spine.last()?.index,pageWidth:layout.pageWidth,offset:manager.container.getBoundingClientRect().left-view.position().left};
|
|
21938
|
+
}
|
|
21939
|
+
}
|
|
21940
|
+
epubLocation=window.PapyrusEpubReader.location(location,spineItems.length,epubViewMode==='single'?'paged':'chapter-scroll',pageGeometry);
|
|
21903
21941
|
if(epubLocation){
|
|
21942
|
+
epubLocation.cfi=epubResizeAnchor?.cfi() || epubLocation.cfi;
|
|
21904
21943
|
if(book.locations?.length?.()>0)epubLocation.progress=book.locations.percentageFromCfi(epubLocation.cfi);
|
|
21905
21944
|
sendEvent('EPUB_LOCATION',{documentSessionId,location:epubLocation});
|
|
21906
21945
|
}
|
|
@@ -21920,6 +21959,8 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
21920
21959
|
);
|
|
21921
21960
|
if (!isCurrentLoad()) throw new Error('EPUB load superseded by a newer load');
|
|
21922
21961
|
sendEpubDiagnostic('epub.display.end', diagnosticPayload);
|
|
21962
|
+
const resizeRendition=rendition;
|
|
21963
|
+
epubResizeAnchor=window.PapyrusEpubReader.installResizeAnchor(resizeRendition.manager,()=>resizeRendition.location?.start?.cfi);
|
|
21923
21964
|
if (
|
|
21924
21965
|
rendition &&
|
|
21925
21966
|
rendition.manager &&
|
|
@@ -22053,6 +22094,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22053
22094
|
const request = ++epubNavigationRequest;
|
|
22054
22095
|
const navigation = epubNavigationQueue.catch(() => {}).then(async () => {
|
|
22055
22096
|
if (request !== epubNavigationRequest || session !== documentSessionId || activeRendition !== rendition) return;
|
|
22097
|
+
epubResizeAnchor?.invalidate();
|
|
22056
22098
|
await activeRendition.display(target);
|
|
22057
22099
|
if (request !== epubNavigationRequest || session !== documentSessionId || activeRendition !== rendition) return;
|
|
22058
22100
|
currentPage = pageIndex + 1;
|
|
@@ -22242,6 +22284,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22242
22284
|
epubNavigationRequest += 1;
|
|
22243
22285
|
const navigation = epubNavigationQueue.catch(() => {}).then(async () => {
|
|
22244
22286
|
if(navigationSession !== documentSessionId || activeRendition !== rendition)throw new Error('Stale EPUB navigation');
|
|
22287
|
+
epubResizeAnchor?.invalidate();
|
|
22245
22288
|
await activeRendition.display(annotation.anchor.href);
|
|
22246
22289
|
if(navigationSession !== documentSessionId || activeRendition !== rendition)throw new Error('Stale EPUB navigation');
|
|
22247
22290
|
const contents = activeRendition.getContents().find(c => spineItems[c.sectionIndex]?.href === annotation.anchor.href);
|
|
@@ -22283,6 +22326,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22283
22326
|
const active = rendition;
|
|
22284
22327
|
epubNavigationQueue = epubNavigationQueue.catch(() => {}).then(() => {
|
|
22285
22328
|
if (active !== rendition || payload.documentSessionId !== documentSessionId) return;
|
|
22329
|
+
epubResizeAnchor?.invalidate();
|
|
22286
22330
|
return payload.direction < 0 ? active.prev() : active.next();
|
|
22287
22331
|
});
|
|
22288
22332
|
await epubNavigationQueue;
|
|
@@ -22295,7 +22339,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22295
22339
|
{
|
|
22296
22340
|
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(async()=>{
|
|
22297
22341
|
if(payload.documentSessionId!==documentSessionId || next===epubViewMode)return;
|
|
22298
|
-
const target=epubLocation?.cfi;
|
|
22342
|
+
const target=epubResizeAnchor?.cfi() || epubLocation?.cfi;
|
|
22299
22343
|
epubViewMode=next;
|
|
22300
22344
|
await renderEpubRendition('layout',epubLoadGeneration,target);
|
|
22301
22345
|
});
|
|
@@ -22305,7 +22349,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22305
22349
|
}
|
|
22306
22350
|
if(kind === 'epub-go-to-location'){
|
|
22307
22351
|
if(currentType!=='epub' || payload.documentSessionId!==documentSessionId || !window.PapyrusEpubReader.validCfi(payload.cfi))throw new Error('Invalid EPUB location');
|
|
22308
|
-
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(()=>payload.documentSessionId
|
|
22352
|
+
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(()=>{if(payload.documentSessionId!==documentSessionId)return;epubResizeAnchor?.invalidate();return rendition.display(payload.cfi);});
|
|
22309
22353
|
await epubNavigationQueue;sendResponse(id,true,null);return;
|
|
22310
22354
|
}
|
|
22311
22355
|
|
|
@@ -22316,7 +22360,7 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
22316
22360
|
epubNavigationQueue=epubNavigationQueue.catch(()=>{}).then(async()=>{
|
|
22317
22361
|
if(session!==documentSessionId)return;
|
|
22318
22362
|
const active=rendition;
|
|
22319
|
-
const cfi=epubLocation?.cfi;
|
|
22363
|
+
const cfi=epubResizeAnchor?.cfi() || epubLocation?.cfi;
|
|
22320
22364
|
zoom=requestedZoom;applyEpubZoom();
|
|
22321
22365
|
// Let the content CSS update before redisplaying the logical anchor.
|
|
22322
22366
|
await new Promise(resolve=>(window.requestAnimationFrame || (callback=>setTimeout(callback,0)))(resolve));
|