@foxycape/core 1.2.1 → 1.2.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/mediaTypes/html/renderer/HtmlRenderer.cjs +1 -1
- package/dist/mediaTypes/html/renderer/HtmlRenderer.d.ts +2 -2
- package/dist/mediaTypes/html/renderer/HtmlRenderer.mjs +2 -10
- package/dist/mediaTypes/html/renderer/document/HtmlDocument.cjs +1 -1
- package/dist/mediaTypes/html/renderer/document/HtmlDocument.mjs +13 -13
- package/package.json +1 -3
- package/dist/kernal/plugins/keyboard/KeyboardPageTurning.cjs +0 -1
- package/dist/kernal/plugins/keyboard/KeyboardPageTurning.d.ts +0 -39
- package/dist/kernal/plugins/keyboard/KeyboardPageTurning.mjs +0 -136
- package/dist/mediaTypes/html/renderer/style/LanguageHighlighter.cjs +0 -1
- package/dist/mediaTypes/html/renderer/style/LanguageHighlighter.d.ts +0 -18
- package/dist/mediaTypes/html/renderer/style/LanguageHighlighter.mjs +0 -52
- package/dist/node_modules/highlight.js/styles/github-dark.cjs +0 -118
- package/dist/node_modules/highlight.js/styles/github-dark.mjs +0 -4
- package/dist/node_modules/highlight.js/styles/github.cjs +0 -118
- package/dist/node_modules/highlight.js/styles/github.mjs +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../kernal/EventNames.cjs"),t=require("../../../kernal/common/uuid.cjs"),n=require("../../../kernal/Options.cjs"),r=require("../../../kernal/Theme.cjs"),i=require("../../../kernal/web/scheduler.cjs"),a=require("../../../kernal/html/events.cjs"),o=require("../HtmlOptions.cjs"),s=require("./navigator/HtmlCoreNavigator.cjs"),c=require("./layout/resolveLayoutRoute.cjs"),l=require("./navigator/HtmlPagingNavigator.cjs"),u=require("./navigator/HtmlNavPointNavigator.cjs"),d=require("./navigator/HtmlNavPointProvider.cjs"),f=require("./progress/HtmlProgressTracker.cjs"),p=require("./location/scrollActivity.cjs"),m=require("./documents/HtmlDocumentsProvider.cjs"),h=require("./layout/HtmlRendererLayout.cjs"),g=require("./style/HtmlStyleProvider.cjs"),_=require("./style/HtmlThemeApplier.cjs"),v=require("./documents/HtmlDocumentsResizeObserver.cjs"),y=require("./html/HtmlContentProcessor.cjs"),b=require("./image/HtmlImageLoader.cjs"),x=require("./image/HtmlImageObserver.cjs");var S=class extends m.HtmlDocumentsProvider{constructor(e,r,a,c){super(e,r,a,c),this.isInitRenderer=!1,this.injectProcessHandlers=()=>{this.addDocumentPreprocess(this.preprocessHandler)},this.preprocessHandler=async e=>{await this.contentProcessor.preprocess(e),await this.styleProvider.injectStyles(e);let t=await this.resolveCurrentTheme();t&&await this.themeApplier.applyToDocument(e,t),await this.rendererLayout.applyDocStyles(e),await this.imageLoader.preprocessImages(e);let n=await this.getHighlighter();n&&await n.highlight(e)},this.onPageChange=async()=>{this.progressTracker.notifyProgressChange()},this.onDocumentSizeChange=async()=>{this.owner.context.userChangedProgress||p.isProgrammaticScroll()||p.isUserScrollSettling()||await this.delayRestoreReadingPosition()},this.onOptionsChange=async e=>{let t=this.getRendererContainer();if(!(!t||!t.ownerDocument.defaultView)&&(n.isOptionKey(e)||o.isHtmlOptionKey(e))){let t=o.isHtmlOptionKey(e);if(t){if(!this.owner.context.currentLocation?.precise){let e=await this.progressTracker.getProgress(!0);e&&(this.owner.context.currentLocation=e.location)}this.owner.context.setUserChangedProgress(!1)}if(this.rendererViewport.applyCssVariables(),await i.yieldToMain(),t){for(let e of this.getLoadedDocuments())await this.rendererLayout.applyDocStyles(e);this.owner.context.userChangedProgress||await this.reload()}}},this.progressTracker=new f.HtmlProgressTracker(e,this,c),this.rendererLayout=new h.HtmlRendererLayout(e,this,this.rendererViewport,this.progressTracker,c),this.navPointProvider=new d.HtmlNavPointProvider(this,c),this.navigator=new s.HtmlCoreNavigator(this,c),this.navPointNavigator=new u.HtmlNavPointNavigator(e.locale,e.notifier,this,this.navigator,this.navPointProvider),this.pagingNavigator=new l.HtmlPagingNavigator(this,this.navigator,c),this.styleProvider=new g.HtmlStyleProvider(this),this.currentInstanceId=t.getRandomId(!0),this.themeApplier=new _.HtmlThemeApplier(this),this.documentsResizeObserver=new v.HtmlDocumentsResizeObserver(this,this.rendererViewport,this.progressTracker,this.rendererLayout),this.contentProcessor=new y.HtmlContentProcessor(r),this.imageLoader=this.createImageLoader(),this.imageObserver=new x.HtmlImageObserver(this,c),this.bindEvents(),this.bindScrollWatch(),this.injectProcessHandlers()}get id(){return this.currentInstanceId}createImageLoader(){return new b.HtmlImageLoader(this,this.rendererViewport,this.htmlOptions)}async resolveCurrentTheme(){return(await this.owner.services.get(`themeProvider`))?.getCurrentTheme()??new r.Theme}async getHighlighter(){
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../kernal/EventNames.cjs"),t=require("../../../kernal/common/uuid.cjs"),n=require("../../../kernal/Options.cjs"),r=require("../../../kernal/Theme.cjs"),i=require("../../../kernal/web/scheduler.cjs"),a=require("../../../kernal/html/events.cjs"),o=require("../HtmlOptions.cjs"),s=require("./navigator/HtmlCoreNavigator.cjs"),c=require("./layout/resolveLayoutRoute.cjs"),l=require("./navigator/HtmlPagingNavigator.cjs"),u=require("./navigator/HtmlNavPointNavigator.cjs"),d=require("./navigator/HtmlNavPointProvider.cjs"),f=require("./progress/HtmlProgressTracker.cjs"),p=require("./location/scrollActivity.cjs"),m=require("./documents/HtmlDocumentsProvider.cjs"),h=require("./layout/HtmlRendererLayout.cjs"),g=require("./style/HtmlStyleProvider.cjs"),_=require("./style/HtmlThemeApplier.cjs"),v=require("./documents/HtmlDocumentsResizeObserver.cjs"),y=require("./html/HtmlContentProcessor.cjs"),b=require("./image/HtmlImageLoader.cjs"),x=require("./image/HtmlImageObserver.cjs");var S=class extends m.HtmlDocumentsProvider{constructor(e,r,a,c){super(e,r,a,c),this.isInitRenderer=!1,this.injectProcessHandlers=()=>{this.addDocumentPreprocess(this.preprocessHandler)},this.preprocessHandler=async e=>{await this.contentProcessor.preprocess(e),await this.styleProvider.injectStyles(e);let t=await this.resolveCurrentTheme();t&&await this.themeApplier.applyToDocument(e,t),await this.rendererLayout.applyDocStyles(e),await this.imageLoader.preprocessImages(e);let n=await this.getHighlighter();n&&await n.highlight(e)},this.onPageChange=async()=>{this.progressTracker.notifyProgressChange()},this.onDocumentSizeChange=async()=>{this.owner.context.userChangedProgress||p.isProgrammaticScroll()||p.isUserScrollSettling()||await this.delayRestoreReadingPosition()},this.onOptionsChange=async e=>{let t=this.getRendererContainer();if(!(!t||!t.ownerDocument.defaultView)&&(n.isOptionKey(e)||o.isHtmlOptionKey(e))){let t=o.isHtmlOptionKey(e);if(t){if(!this.owner.context.currentLocation?.precise){let e=await this.progressTracker.getProgress(!0);e&&(this.owner.context.currentLocation=e.location)}this.owner.context.setUserChangedProgress(!1)}if(this.rendererViewport.applyCssVariables(),await i.yieldToMain(),t){for(let e of this.getLoadedDocuments())await this.rendererLayout.applyDocStyles(e);this.owner.context.userChangedProgress||await this.reload()}}},this.progressTracker=new f.HtmlProgressTracker(e,this,c),this.rendererLayout=new h.HtmlRendererLayout(e,this,this.rendererViewport,this.progressTracker,c),this.navPointProvider=new d.HtmlNavPointProvider(this,c),this.navigator=new s.HtmlCoreNavigator(this,c),this.navPointNavigator=new u.HtmlNavPointNavigator(e.locale,e.notifier,this,this.navigator,this.navPointProvider),this.pagingNavigator=new l.HtmlPagingNavigator(this,this.navigator,c),this.styleProvider=new g.HtmlStyleProvider(this),this.currentInstanceId=t.getRandomId(!0),this.themeApplier=new _.HtmlThemeApplier(this),this.documentsResizeObserver=new v.HtmlDocumentsResizeObserver(this,this.rendererViewport,this.progressTracker,this.rendererLayout),this.contentProcessor=new y.HtmlContentProcessor(r),this.imageLoader=this.createImageLoader(),this.imageObserver=new x.HtmlImageObserver(this,c),this.bindEvents(),this.bindScrollWatch(),this.injectProcessHandlers()}get id(){return this.currentInstanceId}createImageLoader(){return new b.HtmlImageLoader(this,this.rendererViewport,this.htmlOptions)}async resolveCurrentTheme(){return(await this.owner.services.get(`themeProvider`))?.getCurrentTheme()??new r.Theme}async getHighlighter(){}bindEvents(){this.owner.events.on(e.EventNames.OptionsChange,this.onOptionsChange),this.owner.events.on(e.EventNames.PageChange,this.onPageChange),this.owner.events.on(e.EventNames.DocumentSizeChange,this.onDocumentSizeChange)}unbindEvents(){this.owner.events.off(e.EventNames.OptionsChange,this.onOptionsChange),this.owner.events.off(e.EventNames.PageChange,this.onPageChange),this.owner.events.off(e.EventNames.DocumentSizeChange,this.onDocumentSizeChange)}bindScrollWatch(){let t=this.owner.getHostViewport();this.scrollWatchTarget=t.mode==`window`?t.scrollWatchTarget:this.getScrollElement(),this.scrollWatchTarget&&(this.scrollWatchState=a.watchScroll(this.scrollWatchTarget,this.owner.options.calcScrollDirection,async(t,n)=>{this.owner.events.emit(e.EventNames.ReaderDebounceScroll,t,n),this.progressTracker.notifyProgressChange()},t=>{p.isProgrammaticScroll()||!t.isTrusted||(this.owner.onProgressChangeGuard&&this.owner.context?.progress?.current&&(this.owner.onProgressChangeGuard(this.owner.context.progress.current)||t.preventDefault()),p.markUserScroll(),p.releaseAbsoluteLocate(),this.owner.events.emit(e.EventNames.ReaderOriginalScroll,t))}))}async load(e,t){e||=this.owner.context.progress?.location,this.isInitRenderer||(this.isInitRenderer=!0,this.documentsResizeObserver.register(),this.imageObserver.register()),await super.load(e,t)}getFileParser(){return this.fileParser}get writingMode(){return this.htmlOptions.writingMode??`horizontal-tb`}get direction(){return c.resolveHtmlTextDirection(this.htmlOptions)}get layout(){return this.rendererLayout}async applyTheme(e){await this.themeApplier.applyTheme(e);let t=await this.getHighlighter();t&&await t.applyTheme(e)}async dispose(){this.unbindEvents();let e=this.scrollWatchTarget??this.getScrollElement();e&&this.scrollWatchState?._eventHandler&&(e.removeEventListener(`scroll`,this.scrollWatchState._eventHandler,!0),this.scrollWatchState=void 0,this.scrollWatchTarget=void 0),await this.progressTracker.dispose(),await this.imageObserver.dispose(),await this.imageLoader.dispose(),await super.dispose(),await this.styleProvider?.dispose(),await this.navPointProvider?.dispose(),await this.pagingNavigator?.dispose(),await this.documentsResizeObserver.dispose(),await this.contentProcessor.dispose()}};exports.HtmlRenderer=S;
|
|
@@ -6,6 +6,7 @@ import { HtmlOptions } from '../HtmlOptions';
|
|
|
6
6
|
import { IHtmlProgressTracker } from './progress/IHtmlIProgressTracker';
|
|
7
7
|
import { IHtmlRendererLayout } from './layout/IHtmlRendererLayout';
|
|
8
8
|
import { IHtmlDocument } from './IHtmlDocument';
|
|
9
|
+
import { ILanguageHighlighter } from './style/ILanguageHighlighter';
|
|
9
10
|
import { IHtmlImageLoader } from './image/IHtmlImageLoader';
|
|
10
11
|
|
|
11
12
|
export declare class HtmlRenderer extends HtmlDocumentsProvider implements IHtmlRenderer {
|
|
@@ -31,8 +32,7 @@ export declare class HtmlRenderer extends HtmlDocumentsProvider implements IHtml
|
|
|
31
32
|
private injectProcessHandlers;
|
|
32
33
|
private resolveCurrentTheme;
|
|
33
34
|
protected preprocessHandler: (doc: IHtmlDocument) => Promise<void>;
|
|
34
|
-
|
|
35
|
-
private getHighlighter;
|
|
35
|
+
protected getHighlighter(): Promise<ILanguageHighlighter | undefined>;
|
|
36
36
|
protected bindEvents(): void;
|
|
37
37
|
protected unbindEvents(): void;
|
|
38
38
|
private bindScrollWatch;
|
|
@@ -62,15 +62,7 @@ var T = class extends _ {
|
|
|
62
62
|
async resolveCurrentTheme() {
|
|
63
63
|
return (await this.owner.services.get("themeProvider"))?.getCurrentTheme() ?? new r();
|
|
64
64
|
}
|
|
65
|
-
async getHighlighter() {
|
|
66
|
-
if (this.htmlOptions.enableFormatCodeBlock) {
|
|
67
|
-
if (!this.languageHighlighter) {
|
|
68
|
-
let { LanguageHighlighter: e } = await import("./style/LanguageHighlighter.mjs");
|
|
69
|
-
this.languageHighlighter = new e(this);
|
|
70
|
-
}
|
|
71
|
-
return this.languageHighlighter;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
65
|
+
async getHighlighter() {}
|
|
74
66
|
bindEvents() {
|
|
75
67
|
this.owner.events.on(e.OptionsChange, this.onOptionsChange), this.owner.events.on(e.PageChange, this.onPageChange), this.owner.events.on(e.DocumentSizeChange, this.onDocumentSizeChange);
|
|
76
68
|
}
|
|
@@ -108,7 +100,7 @@ var T = class extends _ {
|
|
|
108
100
|
async dispose() {
|
|
109
101
|
this.unbindEvents();
|
|
110
102
|
let e = this.scrollWatchTarget ?? this.getScrollElement();
|
|
111
|
-
e && this.scrollWatchState?._eventHandler && (e.removeEventListener("scroll", this.scrollWatchState._eventHandler, !0), this.scrollWatchState = void 0, this.scrollWatchTarget = void 0), await this.progressTracker.dispose(), await this.imageObserver.dispose(), await this.imageLoader.dispose(), await super.dispose(), await this.styleProvider?.dispose(), await this.
|
|
103
|
+
e && this.scrollWatchState?._eventHandler && (e.removeEventListener("scroll", this.scrollWatchState._eventHandler, !0), this.scrollWatchState = void 0, this.scrollWatchTarget = void 0), await this.progressTracker.dispose(), await this.imageObserver.dispose(), await this.imageLoader.dispose(), await super.dispose(), await this.styleProvider?.dispose(), await this.navPointProvider?.dispose(), await this.pagingNavigator?.dispose(), await this.documentsResizeObserver.dispose(), await this.contentProcessor.dispose();
|
|
112
104
|
}
|
|
113
105
|
};
|
|
114
106
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../../kernal/EventNames.cjs"),t=require("../../../../kernal/common/uuid.cjs"),n=require("../../../../kernal/web/BrowserCapabilities.cjs"),r=require("../../../../kernal/Constants.cjs"),i=require("../../../../kernal/html/finder.cjs"),a=require("../../../../kernal/html/dom.cjs"),o=require("../../../../kernal/web/scheduler.cjs"),s=require("../../../../kernal/html/geometry.cjs"),c=require("../../HtmlSettings.cjs"),l=require("../../../base/renderer/BaseDocument.cjs"),u=require("../visibilityCandidates.cjs"),d=require("../layout/resolveLayoutRoute.cjs"),f=require("../../fileParser/IHtmlFileParser.cjs"),p=require("../../../base/renderer/eventKeys.cjs"),m=require("../html/template.cjs"),h=require("./HtmlPageCalculator.cjs"),g=require("./HtmlSymbolCalclator.cjs"),_=require("./HtmlDocumentResizeObserver.cjs"),v=require("../location/HtmlLayoutStatePreserver.cjs"),y=require("../location/remapStoredPageNumber.cjs");var b=class extends l.BaseDocument{constructor(t,n,r,i,a,s){super(t,r,i,a),this.options=s,this.eventKeyMap=p.getEventKeyMap(),this.visibilityCandidates=null,this.callbacks=[],this.retainLoadingLayer=!1,this.pendingPageLayoutState=null,this.pageStripConcealed=!1,this.waitForRevealPaint=async()=>{await o.yieldToMain(),await new Promise(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>e())})}),await new Promise(e=>{window.setTimeout(e,120)}),await this.waitForVisibleImagesReady()},this.waitForVisibleImagesReady=async()=>{let e=this.getContentContainer(),t=e?.ownerDocument?.defaultView;if(!e||!t)return;let n=[...e.querySelectorAll(`img`),...e.getElementsByTagName(`image`)];if(n.length==0)return;let r=t.innerHeight||e.clientHeight,i=n.filter(e=>{let t=e.getBoundingClientRect();return t.bottom>-200&&t.top<r+200});i.length!=0&&await Promise.race([Promise.all(i.map(e=>this.waitForImageReady(e))),new Promise(e=>{window.setTimeout(e,800)})])},this.waitForImageReady=e=>this.isImageReady(e)?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,e.removeEventListener(`load`,r),e.removeEventListener(`error`,r),i.disconnect(),t())},i=new MutationObserver(()=>{this.isImageReady(e)&&r()});i.observe(e,{attributes:!0,attributeFilter:[`src`,`href`,`data-load-state`]}),e.addEventListener(`load`,r),e.addEventListener(`error`,r),window.setTimeout(r,800)}),this.isImageReady=e=>{let t=e.getAttribute(`data-load-state`);if(t==`loaded`||t==`fail`)return!0;let n=e.ownerDocument.defaultView?.window.HTMLImageElement;if(!n||!(e instanceof n))return!1;let r=e.currentSrc||e.src;return!r||r.startsWith(`data:image/svg+xml`)?!1:e.complete&&e.naturalWidth>0},this.bringLoadingLayerToFront=()=>{let e=this.wrapperContainer.querySelector(`div[data-type='loading-layer']`);e&&this.wrapperContainer.appendChild(e)},this.fadeOutCover=async(e=200)=>{let t=this.wrapperContainer.querySelector(`div[data-type='loading-layer']`);if(!t)return;let n=Math.max(0,e);t.style.pointerEvents=`none`,t.style.transition=`opacity ${n}ms ease`,t.style.opacity=`0`,await new Promise(e=>{let r=!1,i=()=>{r||(r=!0,t.removeEventListener(`transitionend`,i),e())};t.addEventListener(`transitionend`,i),window.setTimeout(i,n+50)})},this.releaseLoadingLayer=async()=>{this.loadingLayer?.removeLoadingLayer(),await this.loadingLayer?.dispose(),this.loadingLayer=void 0},this.buildLoadingContent=async()=>{let e=await this.getFormattedVirtualDocument(),t=this.owner.getRenderer()?.documentPreprocesses??[];for(let e of t)try{await e(this)}catch(t){this.logger.error(`preprocess`,`function`,e?.name,t)}let n=e.documentElement.outerHTML.replace(/<([^<]*)\?xml([^>]*)\?.*?>/i,``);return n.match(/<!DOCTYPE[^>]*>/i)||(n=`<!DOCTYPE html>`+n),n},this.processAfterLoaded=async()=>{let t=this.getContentContainer();if(!t){this.revealPendingPageStrip();return}t.setAttribute(`data-url`,this.url);let n=this.pendingPageLayoutState??this.captureLayoutState();this.pendingPageLayoutState=null;let r=d.getLayoutGeometry(this.options).iframeGrow==`width`;r||this.wrapperContainer.classList.remove(c.HtmlSettings.FileContentContainerHeightClassName);try{let e=this.owner.getRenderer()?.documentPostprocesses??[];for(let t of e)try{await t(this),await o.yieldToMain()}catch(e){this.logger.error(`postprocess`,`function`,t?.name,e)}await this.layoutStatePreserver.waitUntilPageTransformStable(),this.resetLayoutSizes(),r&&this.wrapperContainer.classList.remove(c.HtmlSettings.FileContentContainerHeightClassName),await this.layoutStatePreserver.restore(n)}finally{this.revealPendingPageStrip()}this.retainLoadingLayer||await this.releaseLoadingLayer(),this.loadStatus=`success`,this.visibilityCandidates=null,this.bindDocumentEvents(),this.owner.events.emit(e.EventNames.DocumentLoad,this),this.resizeObserver.observeIframeSize(async()=>{let e=d.getLayoutGeometry(this.options),t=y.shouldKeepPageEndOnContentGrow(this.owner.context.currentLocation,this.url),n=e.restoresScrollAfterResize||t,r=n?this.captureLayoutState():null;if(this.resetLayoutSizes(),e.flipMode==`page`&&this.pageCalculator.calcNumberOfPages(!0),n&&r&&(await this.restoreLayoutState(r),t)){let e=this.internalGetNumberOfPages(),t=this.owner.context.currentLocation;t?.url==this.url&&(t.current=e,t.total=e)}}),this.loadCompleted(!0)},this.loadCompleted=e=>{for(let t=0;t<this.callbacks.length;t++)try{e?this.callbacks[t].resolve():this.callbacks[t].reject()}catch{}this.callbacks=[]},this.capture=!0,this.eventListener=e=>{let t=this.eventKeyMap.get(e.type);t&&this.owner.events.emit(t,e,this)},this.pageCalculator=new h.HtmlPageCalculator(this,n,s),this.symbolCalclator=new g.HtmlSymbolCalclator(this,f.asHtmlFileParser(r).symbolMeasure),this.layoutStatePreserver=new v.HtmlLayoutStatePreserver(this,n,s),this.logger=this.owner.loggerFactory.getLogger(this.constructor.name),this.resizeObserver=new _.HtmlDocumentResizeObserver(this,this.owner.events)}get inIframe(){return!0}async load(){await new Promise(async(i,s)=>{if(this.loadStatus==`success`){i();return}if(this.callbacks.push({resolve:i,reject:s}),this.loadStatus!=`loading`){this.loadStatus=`loading`,this.loadingLayer=await this.owner.services.get(`loadLayer`),this.loadingLayer?.setDoc(this),a.emptyElement(this.wrapperContainer),this.loadingLayer.removeLoadingLayer(),this.loadingLayer.loadLoadingLayer(),await o.yieldToMain();try{if(this.inIframe){if(!this.iframe){let i=r.readerPrefixName+t.getUuid(!0);this.iframe=m.createIframe(this.wrapperContainer.ownerDocument,i,this.options.forceScroll,d.getLayoutGeometry(this.options)),this.options.forceScroll?this.iframe.removeAttribute(`scrolling`):this.iframe.setAttribute(`scrolling`,`no`);let a=await this.buildLoadingContent();await o.yieldToMain(),this.wrapperContainer.appendChild(this.iframe),this.bringLoadingLayerToFront(),await o.yieldToMain(),this.iframe.addEventListener(`load`,async()=>{await this.processAfterLoaded()},!1),this.iframe.addEventListener(`error`,t=>{this.revealPendingPageStrip(),this.retainLoadingLayer=!1,this.loadingLayer?.removeLoadingLayer(),this.loadStatus=`fail`,this.iframe=void 0,this.loadingLayer?.setReloadButton(),this.logger.error(t),this.owner.events.emit(e.EventNames.DocumentLoadFailed,this,t),this.loadCompleted(!0)},!1);let s=this.iframe.contentDocument,c=this.captureLayoutState(),l=d.getLayoutGeometry(this.options).flipMode==`page`&&n.BrowserCapabilities.isSafari();l&&(this.pendingPageLayoutState=c,this.concealPageStrip()),this.options.preferSrcdoc&&`srcdoc`in this.iframe||!(`write`in s)?this.iframe.srcdoc=a:(s.open(),s.write(a),s.close()),l||await this.restoreLayoutState(c),await o.yieldToMain()}}else{let e=await this.buildLoadingContent();a.setElementHtml(this.wrapperContainer,e),await this.processAfterLoaded(),await o.yieldToMain()}}catch(t){this.revealPendingPageStrip(),this.logger.error(t),this.retainLoadingLayer=!1,this.owner?.context?(this.loadingLayer?.removeLoadingLayer(),this.loadStatus=`fail`,this.iframe=void 0,this.loadingLayer?.setReloadButton(),this.owner.events.emit(e.EventNames.DocumentLoadFailed,this,t?.toString()),this.loadCompleted(!0)):(await this.releaseLoadingLayer(),this.loadCompleted(!0))}}})}prepareCoveredLoad(){this.retainLoadingLayer=!0}async revealCoveredLoad(){this.retainLoadingLayer=!1;try{await this.waitForRevealPaint(),await this.fadeOutCover()}finally{await this.releaseLoadingLayer()}}resetLayoutSizes(){this.resetIframeMinSize()}captureLayoutState(){return this.layoutStatePreserver.capture()}async restoreLayoutState(e){await this.layoutStatePreserver.restore(e)}concealPageStrip(){this.pageStripConcealed=!0,this.layoutStatePreserver.concealPageStrip()}revealPendingPageStrip(){this.pendingPageLayoutState=null,this.pageStripConcealed&&(this.pageStripConcealed=!1,this.layoutStatePreserver.revealPageStrip())}resetIframeMinSize(){let e=this.getContentRootElement();if(!e||!this.iframe)return;let t=d.getLayoutGeometry(this.options),n=i.getDocumentBody(e.ownerDocument);this.iframe.style.removeProperty(`transform`),this.iframe.style.removeProperty(`will-change`);let r=this.owner.getRenderer()?.getRendererContainer(),a=parseFloat(r?.getAttribute(`data-column-width`)??``)||Math.round(this.iframe.getBoundingClientRect().width),o=parseFloat(r?.getAttribute(`data-page-height`)??``)||Math.round(this.iframe.getBoundingClientRect().height),s=parseFloat(r?.getAttribute(`data-column-gap`)??``);t.sizeIframe({iframe:this.iframe,contentRoot:e,body:n,forceScroll:!!this.options.forceScroll,columnWidth:Number.isFinite(a)?Math.round(a):0,pageHeight:Number.isFinite(o)?Math.round(o):0,columnGap:Number.isFinite(s)&&s>0?s:0,parentContentHeight:this.getParentContentHeight(this.iframe.parentElement)}),t.useColumnLayout&&this.pageCalculator.calcNumberOfPages(!0)}getParentContentHeight(e){if(!e)return 0;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=parseFloat(t?.paddingTop??`0`)||0,r=parseFloat(t?.paddingBottom??`0`)||0;return Math.max(0,Math.round(e.clientHeight-n-r))}async getContent(){return this.docContent?this.docContent:(this.docContent=await(await this.fileParser.getTextDocument(this.url)).getPlaintext(),this.docContent.length>this.options.singleDocMaxSize?m.getTooBigHtmlTemplate(this.docContent.length):this.docContent)}async getFormattedVirtualDocument(){if(this.formattedVirtualDocument)return this.formattedVirtualDocument;let e=await this.fileParser.getTextDocument(this.url);return this.formattedVirtualDocument=await e.getFormattedDocument(),this.formattedVirtualDocument}async getText(e){return await(await this.fileParser.getTextDocument(this.url)).getPlaintext(e)}internalGetNumberOfPages(){let e=1;return this.getFlipMode()==`page`&&(e=this.pageCalculator.calcNumberOfPages()),e}async getNumberOfPages(){return await this.load(),this.internalGetNumberOfPages()}async getPageNumber(e){return this.pageCalculator.getPageNumber(e)}getContentRootElement(){return this.inIframe?this.iframe?.contentDocument?.documentElement:this.wrapperContainer}getContentContainer(){return this.inIframe?i.getDocumentBody(this.iframe?.contentDocument):this.wrapperContainer}async getVirtualContentContainer(e){if(e){let e=await this.fileParser.getTextDocument(this.url);return i.getDocumentBody(await e.getFormattedDocument())}let t=await this.getFormattedVirtualDocument();return i.getDocumentBody(t)}getVisibleElements(e){if(this.loadStatus!=`success`)return[];let t=this.getContentContainer(),n=t?.ownerDocument?.defaultView;if(!t||!n)return[];this.visibilityCandidates||=u.collectContentUnitElements(t,{htmlBlockTags:this.options.htmlBlockTags});let r=this.owner.getRenderer()?.getRendererContainer().getBoundingClientRect().top,i=s.resolveVisibleViewportInContentWindow(n,{topInset:r});return i?s.getOrderedElementsIntersectingRect(this.visibilityCandidates,i,{writingMode:d.getLayoutGeometry(this.options).writingMode,fullVisible:e}):[]}async dispose(){let t=this.captureLayoutState();this.owner.events.emit(e.EventNames.DocumentDisposing,this),this.unbindDocumentEvents(),this.resizeObserver.unobserveIframeSize(),this.callbacks?.splice(0),this.visibilityCandidates=null,this.retainLoadingLayer=!1,await this.releaseLoadingLayer();let n=this.getWrapperContainer();n.classList.add(c.HtmlSettings.FileContentContainerHeightClassName),this.iframe&&n.contains(this.iframe)&&n.removeChild(this.iframe),a.emptyElement(this.wrapperContainer),this.iframe=void 0,this.formattedVirtualDocument=null,await this.symbolCalclator.dispose(),await this.restoreLayoutState(t),await super.dispose()}bindDocumentEvents(){let e=this.inIframe?this.getContentContainer().ownerDocument:this.getContentRootElement();for(let t of this.eventKeyMap.keys())e.addEventListener(t,this.eventListener,this.capture)}unbindDocumentEvents(){let e=this.inIframe?this.getContentContainer()?.ownerDocument:this.getContentRootElement();if(e)for(let t of this.eventKeyMap.keys())e?.removeEventListener(t,this.eventListener,this.capture)}getFlipMode(){return this.options.forceScroll?`scroll`:this.options.flipMode}};exports.HtmlDocument=b;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../../kernal/EventNames.cjs"),t=require("../../../../kernal/common/uuid.cjs"),n=require("../../../../kernal/web/BrowserCapabilities.cjs"),r=require("../../../../kernal/Constants.cjs"),i=require("../../../../kernal/html/finder.cjs"),a=require("../../../../kernal/html/dom.cjs"),o=require("../../../../kernal/web/scheduler.cjs"),s=require("../../../../kernal/html/geometry.cjs"),c=require("../../HtmlSettings.cjs"),l=require("../../../base/renderer/BaseDocument.cjs"),u=require("../../../base/renderer/eventKeys.cjs"),d=require("../visibilityCandidates.cjs"),f=require("../layout/resolveLayoutRoute.cjs"),p=require("../../fileParser/IHtmlFileParser.cjs"),m=require("../html/template.cjs"),h=require("./HtmlPageCalculator.cjs"),g=require("./HtmlSymbolCalclator.cjs"),_=require("./HtmlDocumentResizeObserver.cjs"),v=require("../location/HtmlLayoutStatePreserver.cjs"),y=require("../location/remapStoredPageNumber.cjs");var b=class extends l.BaseDocument{constructor(t,n,r,i,a,s){super(t,r,i,a),this.options=s,this.eventKeyMap=u.getEventKeyMap(),this.visibilityCandidates=null,this.callbacks=[],this.retainLoadingLayer=!1,this.pendingPageLayoutState=null,this.pageStripConcealed=!1,this.waitForRevealPaint=async()=>{await o.yieldToMain(),await new Promise(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>e())})}),await new Promise(e=>{window.setTimeout(e,120)}),await this.waitForVisibleImagesReady()},this.waitForVisibleImagesReady=async()=>{let e=this.getContentContainer(),t=e?.ownerDocument?.defaultView;if(!e||!t)return;let n=[...e.querySelectorAll(`img`),...e.getElementsByTagName(`image`)];if(n.length==0)return;let r=t.innerHeight||e.clientHeight,i=n.filter(e=>{let t=e.getBoundingClientRect();return t.bottom>-200&&t.top<r+200});i.length!=0&&await Promise.race([Promise.all(i.map(e=>this.waitForImageReady(e))),new Promise(e=>{window.setTimeout(e,800)})])},this.waitForImageReady=e=>this.isImageReady(e)?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,e.removeEventListener(`load`,r),e.removeEventListener(`error`,r),i.disconnect(),t())},i=new MutationObserver(()=>{this.isImageReady(e)&&r()});i.observe(e,{attributes:!0,attributeFilter:[`src`,`href`,`data-load-state`]}),e.addEventListener(`load`,r),e.addEventListener(`error`,r),window.setTimeout(r,800)}),this.isImageReady=e=>{let t=e.getAttribute(`data-load-state`);if(t==`loaded`||t==`fail`)return!0;let n=e.ownerDocument.defaultView?.window.HTMLImageElement;if(!n||!(e instanceof n))return!1;let r=e.currentSrc||e.src;return!r||r.startsWith(`data:image/svg+xml`)?!1:e.complete&&e.naturalWidth>0},this.bringLoadingLayerToFront=()=>{let e=this.wrapperContainer.querySelector(`div[data-type='loading-layer']`);e&&this.wrapperContainer.appendChild(e)},this.fadeOutCover=async(e=200)=>{let t=this.wrapperContainer.querySelector(`div[data-type='loading-layer']`);if(!t)return;let n=Math.max(0,e);t.style.pointerEvents=`none`,t.style.transition=`opacity ${n}ms ease`,t.style.opacity=`0`,await new Promise(e=>{let r=!1,i=()=>{r||(r=!0,t.removeEventListener(`transitionend`,i),e())};t.addEventListener(`transitionend`,i),window.setTimeout(i,n+50)})},this.releaseLoadingLayer=async()=>{this.loadingLayer?.removeLoadingLayer(),await this.loadingLayer?.dispose(),this.loadingLayer=void 0},this.buildLoadingContent=async()=>{let e=await this.getFormattedVirtualDocument(),t=this.owner.getRenderer()?.documentPreprocesses??[];for(let e of t)try{await e(this)}catch(t){this.logger.error(`preprocess`,`function`,e?.name,t)}let n=e.documentElement.outerHTML.replace(/<([^<]*)\?xml([^>]*)\?.*?>/i,``);return n.match(/<!DOCTYPE[^>]*>/i)||(n=`<!DOCTYPE html>`+n),n},this.processAfterLoaded=async()=>{let t=this.getContentContainer();if(!t){this.revealPendingPageStrip();return}t.setAttribute(`data-url`,this.url);let n=this.pendingPageLayoutState??this.captureLayoutState();this.pendingPageLayoutState=null;let r=f.getLayoutGeometry(this.options).iframeGrow==`width`;r||this.wrapperContainer.classList.remove(c.HtmlSettings.FileContentContainerHeightClassName);try{let e=this.owner.getRenderer()?.documentPostprocesses??[];for(let t of e)try{await t(this),await o.yieldToMain()}catch(e){this.logger.error(`postprocess`,`function`,t?.name,e)}await this.layoutStatePreserver.waitUntilPageTransformStable(),this.resetLayoutSizes(),r&&this.wrapperContainer.classList.remove(c.HtmlSettings.FileContentContainerHeightClassName),await this.layoutStatePreserver.restore(n)}finally{this.revealPendingPageStrip()}this.retainLoadingLayer||await this.releaseLoadingLayer(),this.loadStatus=`success`,this.visibilityCandidates=null,this.bindDocumentEvents(),this.owner.events.emit(e.EventNames.DocumentLoad,this),this.resizeObserver.observeIframeSize(async()=>{let e=f.getLayoutGeometry(this.options),t=y.shouldKeepPageEndOnContentGrow(this.owner.context.currentLocation,this.url),n=e.restoresScrollAfterResize||t,r=n?this.captureLayoutState():null;if(this.resetLayoutSizes(),e.flipMode==`page`&&this.pageCalculator.calcNumberOfPages(!0),n&&r&&(await this.restoreLayoutState(r),t)){let e=this.internalGetNumberOfPages(),t=this.owner.context.currentLocation;t?.url==this.url&&(t.current=e,t.total=e)}}),this.loadCompleted(!0)},this.loadCompleted=e=>{for(let t=0;t<this.callbacks.length;t++)try{e?this.callbacks[t].resolve():this.callbacks[t].reject()}catch{}this.callbacks=[]},this.capture=!0,this.eventListener=e=>{let t=this.eventKeyMap.get(e.type);t&&this.owner.events.emit(t,e,this)},this.pageCalculator=new h.HtmlPageCalculator(this,n,s),this.symbolCalclator=new g.HtmlSymbolCalclator(this,p.asHtmlFileParser(r).symbolMeasure),this.layoutStatePreserver=new v.HtmlLayoutStatePreserver(this,n,s),this.logger=this.owner.loggerFactory.getLogger(this.constructor.name),this.resizeObserver=new _.HtmlDocumentResizeObserver(this,this.owner.events)}get inIframe(){return!0}async load(){await new Promise(async(i,s)=>{if(this.loadStatus==`success`){i();return}if(this.callbacks.push({resolve:i,reject:s}),this.loadStatus!=`loading`){this.loadStatus=`loading`,this.loadingLayer=await this.owner.services.get(`loadLayer`),this.loadingLayer?.setDoc(this),a.emptyElement(this.wrapperContainer),this.loadingLayer.removeLoadingLayer(),this.loadingLayer.loadLoadingLayer(),await o.yieldToMain();try{if(this.inIframe){if(!this.iframe){let i=r.readerPrefixName+t.getUuid(!0);this.iframe=m.createIframe(this.wrapperContainer.ownerDocument,i,this.options.forceScroll,f.getLayoutGeometry(this.options)),this.options.forceScroll?this.iframe.removeAttribute(`scrolling`):this.iframe.setAttribute(`scrolling`,`no`);let a=await this.buildLoadingContent();await o.yieldToMain(),this.wrapperContainer.appendChild(this.iframe),this.bringLoadingLayerToFront(),await o.yieldToMain(),this.iframe.addEventListener(`load`,async()=>{await this.processAfterLoaded()},!1),this.iframe.addEventListener(`error`,t=>{this.revealPendingPageStrip(),this.retainLoadingLayer=!1,this.loadingLayer?.removeLoadingLayer(),this.loadStatus=`fail`,this.iframe=void 0,this.loadingLayer?.setReloadButton(),this.logger.error(t),this.owner.events.emit(e.EventNames.DocumentLoadFailed,this,t),this.loadCompleted(!0)},!1);let s=this.iframe.contentDocument,c=this.captureLayoutState(),l=f.getLayoutGeometry(this.options).flipMode==`page`&&n.BrowserCapabilities.isSafari();l&&(this.pendingPageLayoutState=c,this.concealPageStrip()),this.options.preferSrcdoc&&`srcdoc`in this.iframe||!(`write`in s)?this.iframe.srcdoc=a:(s.open(),s.write(a),s.close()),l||await this.restoreLayoutState(c),await o.yieldToMain()}}else{let e=await this.buildLoadingContent();a.setElementHtml(this.wrapperContainer,e),await this.processAfterLoaded(),await o.yieldToMain()}}catch(t){this.revealPendingPageStrip(),this.logger.error(t),this.retainLoadingLayer=!1,this.owner?.context?(this.loadingLayer?.removeLoadingLayer(),this.loadStatus=`fail`,this.iframe=void 0,this.loadingLayer?.setReloadButton(),this.owner.events.emit(e.EventNames.DocumentLoadFailed,this,t?.toString()),this.loadCompleted(!0)):(await this.releaseLoadingLayer(),this.loadCompleted(!0))}}})}prepareCoveredLoad(){this.retainLoadingLayer=!0}async revealCoveredLoad(){this.retainLoadingLayer=!1;try{await this.waitForRevealPaint(),await this.fadeOutCover()}finally{await this.releaseLoadingLayer()}}resetLayoutSizes(){this.resetIframeMinSize()}captureLayoutState(){return this.layoutStatePreserver.capture()}async restoreLayoutState(e){await this.layoutStatePreserver.restore(e)}concealPageStrip(){this.pageStripConcealed=!0,this.layoutStatePreserver.concealPageStrip()}revealPendingPageStrip(){this.pendingPageLayoutState=null,this.pageStripConcealed&&(this.pageStripConcealed=!1,this.layoutStatePreserver.revealPageStrip())}resetIframeMinSize(){let e=this.getContentRootElement();if(!e||!this.iframe)return;let t=f.getLayoutGeometry(this.options),n=i.getDocumentBody(e.ownerDocument);this.iframe.style.removeProperty(`transform`),this.iframe.style.removeProperty(`will-change`);let r=this.owner.getRenderer()?.getRendererContainer(),a=parseFloat(r?.getAttribute(`data-column-width`)??``)||Math.round(this.iframe.getBoundingClientRect().width),o=parseFloat(r?.getAttribute(`data-page-height`)??``)||Math.round(this.iframe.getBoundingClientRect().height),s=parseFloat(r?.getAttribute(`data-column-gap`)??``);t.sizeIframe({iframe:this.iframe,contentRoot:e,body:n,forceScroll:!!this.options.forceScroll,columnWidth:Number.isFinite(a)?Math.round(a):0,pageHeight:Number.isFinite(o)?Math.round(o):0,columnGap:Number.isFinite(s)&&s>0?s:0,parentContentHeight:this.getParentContentHeight(this.iframe.parentElement)}),t.useColumnLayout&&this.pageCalculator.calcNumberOfPages(!0)}getParentContentHeight(e){if(!e)return 0;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=parseFloat(t?.paddingTop??`0`)||0,r=parseFloat(t?.paddingBottom??`0`)||0;return Math.max(0,Math.round(e.clientHeight-n-r))}async getContent(){return this.docContent?this.docContent:(this.docContent=await(await this.fileParser.getTextDocument(this.url)).getPlaintext(),this.docContent.length>this.options.singleDocMaxSize?m.getTooBigHtmlTemplate(this.docContent.length):this.docContent)}async getFormattedVirtualDocument(){if(this.formattedVirtualDocument)return this.formattedVirtualDocument;let e=await this.fileParser.getTextDocument(this.url);return this.formattedVirtualDocument=await e.getFormattedDocument(),this.formattedVirtualDocument}async getText(e){return await(await this.fileParser.getTextDocument(this.url)).getPlaintext(e)}internalGetNumberOfPages(){let e=1;return this.getFlipMode()==`page`&&(e=this.pageCalculator.calcNumberOfPages()),e}async getNumberOfPages(){return await this.load(),this.internalGetNumberOfPages()}async getPageNumber(e){return this.pageCalculator.getPageNumber(e)}getContentRootElement(){return this.inIframe?this.iframe?.contentDocument?.documentElement:this.wrapperContainer}getContentContainer(){return this.inIframe?i.getDocumentBody(this.iframe?.contentDocument):this.wrapperContainer}async getVirtualContentContainer(e){if(e){let e=await this.fileParser.getTextDocument(this.url);return i.getDocumentBody(await e.getFormattedDocument())}let t=await this.getFormattedVirtualDocument();return i.getDocumentBody(t)}getVisibleElements(e){if(this.loadStatus!=`success`)return[];let t=this.getContentContainer(),n=t?.ownerDocument?.defaultView;if(!t||!n)return[];this.visibilityCandidates||=d.collectContentUnitElements(t,{htmlBlockTags:this.options.htmlBlockTags});let r=this.owner.getRenderer()?.getRendererContainer().getBoundingClientRect().top,i=s.resolveVisibleViewportInContentWindow(n,{topInset:r});return i?s.getOrderedElementsIntersectingRect(this.visibilityCandidates,i,{writingMode:f.getLayoutGeometry(this.options).writingMode,fullVisible:e}):[]}async dispose(){let t=this.captureLayoutState();this.owner.events.emit(e.EventNames.DocumentDisposing,this),this.unbindDocumentEvents(),this.resizeObserver.unobserveIframeSize(),this.callbacks?.splice(0),this.visibilityCandidates=null,this.retainLoadingLayer=!1,await this.releaseLoadingLayer();let n=this.getWrapperContainer();n.classList.add(c.HtmlSettings.FileContentContainerHeightClassName),this.iframe&&n.contains(this.iframe)&&n.removeChild(this.iframe),a.emptyElement(this.wrapperContainer),this.iframe=void 0,this.formattedVirtualDocument=null,await this.symbolCalclator.dispose(),await this.restoreLayoutState(t),await super.dispose()}bindDocumentEvents(){let e=this.inIframe?this.getContentContainer().ownerDocument:this.getContentRootElement();for(let t of this.eventKeyMap.keys())e.addEventListener(t,this.eventListener,this.capture)}unbindDocumentEvents(){let e=this.inIframe?this.getContentContainer()?.ownerDocument:this.getContentRootElement();if(e)for(let t of this.eventKeyMap.keys())e?.removeEventListener(t,this.eventListener,this.capture)}getFlipMode(){return this.options.forceScroll?`scroll`:this.options.flipMode}};exports.HtmlDocument=b;
|
|
@@ -8,10 +8,10 @@ import { yieldToMain as s } from "../../../../kernal/web/scheduler.mjs";
|
|
|
8
8
|
import { getOrderedElementsIntersectingRect as c, resolveVisibleViewportInContentWindow as l } from "../../../../kernal/html/geometry.mjs";
|
|
9
9
|
import { HtmlSettings as u } from "../../HtmlSettings.mjs";
|
|
10
10
|
import { BaseDocument as d } from "../../../base/renderer/BaseDocument.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import { getEventKeyMap as f } from "../../../base/renderer/eventKeys.mjs";
|
|
12
|
+
import { collectContentUnitElements as p } from "../visibilityCandidates.mjs";
|
|
13
|
+
import { getLayoutGeometry as m } from "../layout/resolveLayoutRoute.mjs";
|
|
14
|
+
import { asHtmlFileParser as h } from "../../fileParser/IHtmlFileParser.mjs";
|
|
15
15
|
import { createIframe as g, getTooBigHtmlTemplate as _ } from "../html/template.mjs";
|
|
16
16
|
import { HtmlPageCalculator as v } from "./HtmlPageCalculator.mjs";
|
|
17
17
|
import { HtmlSymbolCalclator as y } from "./HtmlSymbolCalclator.mjs";
|
|
@@ -21,7 +21,7 @@ import { shouldKeepPageEndOnContentGrow as S } from "../location/remapStoredPage
|
|
|
21
21
|
//#region mediaTypes/html/renderer/document/HtmlDocument.ts
|
|
22
22
|
var C = class extends d {
|
|
23
23
|
constructor(t, n, r, i, a, o) {
|
|
24
|
-
super(t, r, i, a), this.options = o, this.eventKeyMap =
|
|
24
|
+
super(t, r, i, a), this.options = o, this.eventKeyMap = f(), this.visibilityCandidates = null, this.callbacks = [], this.retainLoadingLayer = !1, this.pendingPageLayoutState = null, this.pageStripConcealed = !1, this.waitForRevealPaint = async () => {
|
|
25
25
|
await s(), await new Promise((e) => {
|
|
26
26
|
requestAnimationFrame(() => {
|
|
27
27
|
requestAnimationFrame(() => e());
|
|
@@ -95,7 +95,7 @@ var C = class extends d {
|
|
|
95
95
|
t.setAttribute("data-url", this.url);
|
|
96
96
|
let n = this.pendingPageLayoutState ?? this.captureLayoutState();
|
|
97
97
|
this.pendingPageLayoutState = null;
|
|
98
|
-
let r =
|
|
98
|
+
let r = m(this.options).iframeGrow == "width";
|
|
99
99
|
r || this.wrapperContainer.classList.remove(u.FileContentContainerHeightClassName);
|
|
100
100
|
try {
|
|
101
101
|
let e = this.owner.getRenderer()?.documentPostprocesses ?? [];
|
|
@@ -109,7 +109,7 @@ var C = class extends d {
|
|
|
109
109
|
this.revealPendingPageStrip();
|
|
110
110
|
}
|
|
111
111
|
this.retainLoadingLayer || await this.releaseLoadingLayer(), this.loadStatus = "success", this.visibilityCandidates = null, this.bindDocumentEvents(), this.owner.events.emit(e.DocumentLoad, this), this.resizeObserver.observeIframeSize(async () => {
|
|
112
|
-
let e =
|
|
112
|
+
let e = m(this.options), t = S(this.owner.context.currentLocation, this.url), n = e.restoresScrollAfterResize || t, r = n ? this.captureLayoutState() : null;
|
|
113
113
|
if (this.resetLayoutSizes(), e.flipMode == "page" && this.pageCalculator.calcNumberOfPages(!0), n && r && (await this.restoreLayoutState(r), t)) {
|
|
114
114
|
let e = this.internalGetNumberOfPages(), t = this.owner.context.currentLocation;
|
|
115
115
|
t?.url == this.url && (t.current = e, t.total = e);
|
|
@@ -123,7 +123,7 @@ var C = class extends d {
|
|
|
123
123
|
}, this.capture = !0, this.eventListener = (e) => {
|
|
124
124
|
let t = this.eventKeyMap.get(e.type);
|
|
125
125
|
t && this.owner.events.emit(t, e, this);
|
|
126
|
-
}, this.pageCalculator = new v(this, n, o), this.symbolCalclator = new y(this,
|
|
126
|
+
}, this.pageCalculator = new v(this, n, o), this.symbolCalclator = new y(this, h(r).symbolMeasure), this.layoutStatePreserver = new x(this, n, o), this.logger = this.owner.loggerFactory.getLogger(this.constructor.name), this.resizeObserver = new b(this, this.owner.events);
|
|
127
127
|
}
|
|
128
128
|
get inIframe() {
|
|
129
129
|
return !0;
|
|
@@ -143,14 +143,14 @@ var C = class extends d {
|
|
|
143
143
|
if (this.inIframe) {
|
|
144
144
|
if (!this.iframe) {
|
|
145
145
|
let i = r + t(!0);
|
|
146
|
-
this.iframe = g(this.wrapperContainer.ownerDocument, i, this.options.forceScroll,
|
|
146
|
+
this.iframe = g(this.wrapperContainer.ownerDocument, i, this.options.forceScroll, m(this.options)), this.options.forceScroll ? this.iframe.removeAttribute("scrolling") : this.iframe.setAttribute("scrolling", "no");
|
|
147
147
|
let a = await this.buildLoadingContent();
|
|
148
148
|
await s(), this.wrapperContainer.appendChild(this.iframe), this.bringLoadingLayerToFront(), await s(), this.iframe.addEventListener("load", async () => {
|
|
149
149
|
await this.processAfterLoaded();
|
|
150
150
|
}, !1), this.iframe.addEventListener("error", (t) => {
|
|
151
151
|
this.revealPendingPageStrip(), this.retainLoadingLayer = !1, this.loadingLayer?.removeLoadingLayer(), this.loadStatus = "fail", this.iframe = void 0, this.loadingLayer?.setReloadButton(), this.logger.error(t), this.owner.events.emit(e.DocumentLoadFailed, this, t), this.loadCompleted(!0);
|
|
152
152
|
}, !1);
|
|
153
|
-
let o = this.iframe.contentDocument, c = this.captureLayoutState(), l =
|
|
153
|
+
let o = this.iframe.contentDocument, c = this.captureLayoutState(), l = m(this.options).flipMode == "page" && n.isSafari();
|
|
154
154
|
l && (this.pendingPageLayoutState = c, this.concealPageStrip()), this.options.preferSrcdoc && "srcdoc" in this.iframe || !("write" in o) ? this.iframe.srcdoc = a : (o.open(), o.write(a), o.close()), l || await this.restoreLayoutState(c), await s();
|
|
155
155
|
}
|
|
156
156
|
} else {
|
|
@@ -192,7 +192,7 @@ var C = class extends d {
|
|
|
192
192
|
resetIframeMinSize() {
|
|
193
193
|
let e = this.getContentRootElement();
|
|
194
194
|
if (!e || !this.iframe) return;
|
|
195
|
-
let t =
|
|
195
|
+
let t = m(this.options), n = i(e.ownerDocument);
|
|
196
196
|
this.iframe.style.removeProperty("transform"), this.iframe.style.removeProperty("will-change");
|
|
197
197
|
let r = this.owner.getRenderer()?.getRendererContainer(), a = parseFloat(r?.getAttribute("data-column-width") ?? "") || Math.round(this.iframe.getBoundingClientRect().width), o = parseFloat(r?.getAttribute("data-page-height") ?? "") || Math.round(this.iframe.getBoundingClientRect().height), s = parseFloat(r?.getAttribute("data-column-gap") ?? "");
|
|
198
198
|
t.sizeIframe({
|
|
@@ -250,10 +250,10 @@ var C = class extends d {
|
|
|
250
250
|
if (this.loadStatus != "success") return [];
|
|
251
251
|
let t = this.getContentContainer(), n = t?.ownerDocument?.defaultView;
|
|
252
252
|
if (!t || !n) return [];
|
|
253
|
-
this.visibilityCandidates ||=
|
|
253
|
+
this.visibilityCandidates ||= p(t, { htmlBlockTags: this.options.htmlBlockTags });
|
|
254
254
|
let r = this.owner.getRenderer()?.getRendererContainer().getBoundingClientRect().top, i = l(n, { topInset: r });
|
|
255
255
|
return i ? c(this.visibilityCandidates, i, {
|
|
256
|
-
writingMode:
|
|
256
|
+
writingMode: m(this.options).writingMode,
|
|
257
257
|
fullVisible: e
|
|
258
258
|
}) : [];
|
|
259
259
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxycape/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Browser-side multi-format reader kernel with pluggable parsers, renderers, services, and plugins.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -78,8 +78,6 @@
|
|
|
78
78
|
],
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"events": "^3.3.0",
|
|
81
|
-
"highlight.js": "^11.12.0",
|
|
82
|
-
"hotkeys-js": "^4.0.4",
|
|
83
81
|
"js-base64": "^3.9.2",
|
|
84
82
|
"js-logger": "^1.6.1",
|
|
85
83
|
"perfect-debounce": "^2.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../EventNames.cjs"),n=require("../PluginCore.cjs");let r=require("hotkeys-js");r=e.__toESM(r,1);let i=require("perfect-debounce");var a=`left,up,pageup`,o=`right,down,pagedown`,s=class extends n.PluginCore{constructor(e,t){super(e,t),this.bindedFlipPageElements=[],this.bindedDocuments=[],this.heldKeys={},this.currentPauseFlipPageOnPressKey=!1,this.documentKeydownHandlers=new Map,this.documentKeyupHandlers=new Map,this.onDocumentLoad=async e=>{await this.bindDocument(e)},this.onPressPreviousKey=(e,t)=>{if(this.pluginOptions.flipMode==`page`){if(this.heldKeys[e.keyCode]>1)return;this.currentPauseFlipPageOnPressKey||(e.preventDefault(),e.stopImmediatePropagation(),this.reader.context.setUserChangedProgress(!0,`keyboard`),this.delayGotoPreviousPage(this.reader.getRenderer()))}else this.reader.context.setUserChangedProgress(!0,`keyboard`)},this.onPressNextKey=(e,t)=>{if(this.pluginOptions.flipMode==`page`){if(this.heldKeys[e.keyCode]>1)return;this.currentPauseFlipPageOnPressKey||(e.preventDefault(),e.stopImmediatePropagation(),this.reader.context.setUserChangedProgress(!0,`keyboard`),this.delayGotoNextPage(this.reader.getRenderer()))}else this.reader.context.setUserChangedProgress(!0,`keyboard`)},this.delayGotoPreviousPage=(0,i.debounce)(async e=>{if(e?.pagingNavigator){await e.pagingNavigator.gotoPreviousPage({trigger:`user`,triggerType:`keyboard`});return}await e?.gotoPreviousPage?.({trigger:`user`,triggerType:`keyboard`})},64),this.delayGotoNextPage=(0,i.debounce)(async e=>{if(e?.pagingNavigator){await e.pagingNavigator.gotoNextPage({trigger:`user`,triggerType:`keyboard`});return}await e?.gotoNextPage?.({trigger:`user`,triggerType:`keyboard`})},64),this.pluginOptions={flipMode:t?.flipMode??`page`,flipPagePreviousKeys:t?.flipPagePreviousKeys??a,flipPageNextKeys:t?.flipPageNextKeys??o}}get name(){return`keyboard-page-turning`}get title(){return`Keyboard Page Turning`}get description(){return`Keyboard page flip navigation`}get version(){return`1.0.0`}get supportedVersion(){return`>=1.0.0`}get supportedExtensions(){return[`.xml`,`.xhtml`,`.html`,`.epub`,`.mobi`,`.azw3`,`.fb2`,`.txt`,`.md`]}get supportedLanguages(){return[`*`]}get isUIPlugin(){return!1}getContainer(){}set pauseFlipPageOnPressKey(e){this.currentPauseFlipPageOnPressKey=e}get pauseFlipPageOnPressKey(){return this.currentPauseFlipPageOnPressKey}async load(){let e=this.reader.getReaderContainer();e&&(await this.bindFlipPageKeys(e.ownerDocument.documentElement),e.ownerDocument!==document&&await this.bindFlipPageKeys(document.documentElement));let n=this.reader.getRenderer()?.getLoadedDocuments?.()??this.reader.getRenderer()?.getDocuments?.()??[];for(let e of n)await this.bindDocument(e);this.reader.events.on(t.EventNames.DocumentLoad,this.onDocumentLoad)}async dispose(){this.reader.events.off(t.EventNames.DocumentLoad,this.onDocumentLoad);let e=this.pluginOptions.flipPagePreviousKeys,n=this.pluginOptions.flipPageNextKeys;this.bindedFlipPageElements.length>0&&(e&&r.default.unbind(e,`all`,this.onPressPreviousKey),n&&r.default.unbind(n,`all`,this.onPressNextKey));for(let e of this.bindedDocuments){let t=this.documentKeydownHandlers.get(e),n=this.documentKeyupHandlers.get(e);t&&e.removeEventListener(`keydown`,t,!0),n&&e.removeEventListener(`keyup`,n,!0)}this.documentKeydownHandlers.clear(),this.documentKeyupHandlers.clear(),this.bindedFlipPageElements=[],this.bindedDocuments=[],this.heldKeys={},this.currentPauseFlipPageOnPressKey=!1}async bindDocument(e){let t=e.getContentContainer()?.ownerDocument?.documentElement;t&&await this.bindFlipPageKeys(t)}async bindFlipPageKeys(e){if(this.bindedFlipPageElements.includes(e))return;let t=this.pluginOptions.flipPagePreviousKeys,n=this.pluginOptions.flipPageNextKeys;t&&(0,r.default)(t,{element:e,scope:`all`},this.onPressPreviousKey),n&&(0,r.default)(n,{element:e,scope:`all`},this.onPressNextKey);let i=e.ownerDocument;if(!this.bindedDocuments.includes(i)){this.bindedDocuments.push(i);let e=e=>{this.heldKeys[e.keyCode]=(this.heldKeys[e.keyCode]??0)+1},t=e=>{this.heldKeys[e.keyCode]=0};this.documentKeydownHandlers.set(i,e),this.documentKeyupHandlers.set(i,t),i.addEventListener(`keydown`,e,!0),i.addEventListener(`keyup`,t,!0)}this.bindedFlipPageElements.push(e)}};exports.KeyboardPageTurning=s;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { PluginCore } from '../PluginCore';
|
|
2
|
-
import { Reader } from '../../Reader';
|
|
3
|
-
import { FlipMode } from '../../types';
|
|
4
|
-
|
|
5
|
-
export type KeyboardPageTurningOptions = {
|
|
6
|
-
flipPagePreviousKeys?: string;
|
|
7
|
-
flipPageNextKeys?: string;
|
|
8
|
-
flipMode?: FlipMode;
|
|
9
|
-
};
|
|
10
|
-
export declare class KeyboardPageTurning extends PluginCore {
|
|
11
|
-
private readonly pluginOptions;
|
|
12
|
-
private bindedFlipPageElements;
|
|
13
|
-
private bindedDocuments;
|
|
14
|
-
private heldKeys;
|
|
15
|
-
private currentPauseFlipPageOnPressKey;
|
|
16
|
-
private readonly documentKeydownHandlers;
|
|
17
|
-
private readonly documentKeyupHandlers;
|
|
18
|
-
constructor(reader: Reader, options?: KeyboardPageTurningOptions);
|
|
19
|
-
get name(): string;
|
|
20
|
-
get title(): string;
|
|
21
|
-
get description(): string;
|
|
22
|
-
get version(): string;
|
|
23
|
-
get supportedVersion(): string;
|
|
24
|
-
get supportedExtensions(): string[];
|
|
25
|
-
get supportedLanguages(): string[];
|
|
26
|
-
get isUIPlugin(): boolean;
|
|
27
|
-
getContainer(): HTMLElement | undefined;
|
|
28
|
-
set pauseFlipPageOnPressKey(value: boolean);
|
|
29
|
-
get pauseFlipPageOnPressKey(): boolean;
|
|
30
|
-
load(): Promise<void>;
|
|
31
|
-
dispose(): Promise<void>;
|
|
32
|
-
private onDocumentLoad;
|
|
33
|
-
private bindDocument;
|
|
34
|
-
private bindFlipPageKeys;
|
|
35
|
-
private onPressPreviousKey;
|
|
36
|
-
private onPressNextKey;
|
|
37
|
-
private delayGotoPreviousPage;
|
|
38
|
-
private delayGotoNextPage;
|
|
39
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { EventNames as e } from "../../EventNames.mjs";
|
|
2
|
-
import { PluginCore as t } from "../PluginCore.mjs";
|
|
3
|
-
import { asyncDebounce as n } from "../../web/debounce.mjs";
|
|
4
|
-
import r from "hotkeys-js";
|
|
5
|
-
//#region kernal/plugins/keyboard/KeyboardPageTurning.ts
|
|
6
|
-
var i = "left,up,pageup", a = "right,down,pagedown", o = class extends t {
|
|
7
|
-
constructor(e, t) {
|
|
8
|
-
super(e, t), this.bindedFlipPageElements = [], this.bindedDocuments = [], this.heldKeys = {}, this.currentPauseFlipPageOnPressKey = !1, this.documentKeydownHandlers = /* @__PURE__ */ new Map(), this.documentKeyupHandlers = /* @__PURE__ */ new Map(), this.onDocumentLoad = async (e) => {
|
|
9
|
-
await this.bindDocument(e);
|
|
10
|
-
}, this.onPressPreviousKey = (e, t) => {
|
|
11
|
-
if (this.pluginOptions.flipMode == "page") {
|
|
12
|
-
if (this.heldKeys[e.keyCode] > 1) return;
|
|
13
|
-
this.currentPauseFlipPageOnPressKey || (e.preventDefault(), e.stopImmediatePropagation(), this.reader.context.setUserChangedProgress(!0, "keyboard"), this.delayGotoPreviousPage(this.reader.getRenderer()));
|
|
14
|
-
} else this.reader.context.setUserChangedProgress(!0, "keyboard");
|
|
15
|
-
}, this.onPressNextKey = (e, t) => {
|
|
16
|
-
if (this.pluginOptions.flipMode == "page") {
|
|
17
|
-
if (this.heldKeys[e.keyCode] > 1) return;
|
|
18
|
-
this.currentPauseFlipPageOnPressKey || (e.preventDefault(), e.stopImmediatePropagation(), this.reader.context.setUserChangedProgress(!0, "keyboard"), this.delayGotoNextPage(this.reader.getRenderer()));
|
|
19
|
-
} else this.reader.context.setUserChangedProgress(!0, "keyboard");
|
|
20
|
-
}, this.delayGotoPreviousPage = n(async (e) => {
|
|
21
|
-
if (e?.pagingNavigator) {
|
|
22
|
-
await e.pagingNavigator.gotoPreviousPage({
|
|
23
|
-
trigger: "user",
|
|
24
|
-
triggerType: "keyboard"
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
await e?.gotoPreviousPage?.({
|
|
29
|
-
trigger: "user",
|
|
30
|
-
triggerType: "keyboard"
|
|
31
|
-
});
|
|
32
|
-
}, 64), this.delayGotoNextPage = n(async (e) => {
|
|
33
|
-
if (e?.pagingNavigator) {
|
|
34
|
-
await e.pagingNavigator.gotoNextPage({
|
|
35
|
-
trigger: "user",
|
|
36
|
-
triggerType: "keyboard"
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
await e?.gotoNextPage?.({
|
|
41
|
-
trigger: "user",
|
|
42
|
-
triggerType: "keyboard"
|
|
43
|
-
});
|
|
44
|
-
}, 64), this.pluginOptions = {
|
|
45
|
-
flipMode: t?.flipMode ?? "page",
|
|
46
|
-
flipPagePreviousKeys: t?.flipPagePreviousKeys ?? i,
|
|
47
|
-
flipPageNextKeys: t?.flipPageNextKeys ?? a
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
get name() {
|
|
51
|
-
return "keyboard-page-turning";
|
|
52
|
-
}
|
|
53
|
-
get title() {
|
|
54
|
-
return "Keyboard Page Turning";
|
|
55
|
-
}
|
|
56
|
-
get description() {
|
|
57
|
-
return "Keyboard page flip navigation";
|
|
58
|
-
}
|
|
59
|
-
get version() {
|
|
60
|
-
return "1.0.0";
|
|
61
|
-
}
|
|
62
|
-
get supportedVersion() {
|
|
63
|
-
return ">=1.0.0";
|
|
64
|
-
}
|
|
65
|
-
get supportedExtensions() {
|
|
66
|
-
return [
|
|
67
|
-
".xml",
|
|
68
|
-
".xhtml",
|
|
69
|
-
".html",
|
|
70
|
-
".epub",
|
|
71
|
-
".mobi",
|
|
72
|
-
".azw3",
|
|
73
|
-
".fb2",
|
|
74
|
-
".txt",
|
|
75
|
-
".md"
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
get supportedLanguages() {
|
|
79
|
-
return ["*"];
|
|
80
|
-
}
|
|
81
|
-
get isUIPlugin() {
|
|
82
|
-
return !1;
|
|
83
|
-
}
|
|
84
|
-
getContainer() {}
|
|
85
|
-
set pauseFlipPageOnPressKey(e) {
|
|
86
|
-
this.currentPauseFlipPageOnPressKey = e;
|
|
87
|
-
}
|
|
88
|
-
get pauseFlipPageOnPressKey() {
|
|
89
|
-
return this.currentPauseFlipPageOnPressKey;
|
|
90
|
-
}
|
|
91
|
-
async load() {
|
|
92
|
-
let t = this.reader.getReaderContainer();
|
|
93
|
-
t && (await this.bindFlipPageKeys(t.ownerDocument.documentElement), t.ownerDocument !== document && await this.bindFlipPageKeys(document.documentElement));
|
|
94
|
-
let n = this.reader.getRenderer()?.getLoadedDocuments?.() ?? this.reader.getRenderer()?.getDocuments?.() ?? [];
|
|
95
|
-
for (let e of n) await this.bindDocument(e);
|
|
96
|
-
this.reader.events.on(e.DocumentLoad, this.onDocumentLoad);
|
|
97
|
-
}
|
|
98
|
-
async dispose() {
|
|
99
|
-
this.reader.events.off(e.DocumentLoad, this.onDocumentLoad);
|
|
100
|
-
let t = this.pluginOptions.flipPagePreviousKeys, n = this.pluginOptions.flipPageNextKeys;
|
|
101
|
-
this.bindedFlipPageElements.length > 0 && (t && r.unbind(t, "all", this.onPressPreviousKey), n && r.unbind(n, "all", this.onPressNextKey));
|
|
102
|
-
for (let e of this.bindedDocuments) {
|
|
103
|
-
let t = this.documentKeydownHandlers.get(e), n = this.documentKeyupHandlers.get(e);
|
|
104
|
-
t && e.removeEventListener("keydown", t, !0), n && e.removeEventListener("keyup", n, !0);
|
|
105
|
-
}
|
|
106
|
-
this.documentKeydownHandlers.clear(), this.documentKeyupHandlers.clear(), this.bindedFlipPageElements = [], this.bindedDocuments = [], this.heldKeys = {}, this.currentPauseFlipPageOnPressKey = !1;
|
|
107
|
-
}
|
|
108
|
-
async bindDocument(e) {
|
|
109
|
-
let t = e.getContentContainer()?.ownerDocument?.documentElement;
|
|
110
|
-
t && await this.bindFlipPageKeys(t);
|
|
111
|
-
}
|
|
112
|
-
async bindFlipPageKeys(e) {
|
|
113
|
-
if (this.bindedFlipPageElements.includes(e)) return;
|
|
114
|
-
let t = this.pluginOptions.flipPagePreviousKeys, n = this.pluginOptions.flipPageNextKeys;
|
|
115
|
-
t && r(t, {
|
|
116
|
-
element: e,
|
|
117
|
-
scope: "all"
|
|
118
|
-
}, this.onPressPreviousKey), n && r(n, {
|
|
119
|
-
element: e,
|
|
120
|
-
scope: "all"
|
|
121
|
-
}, this.onPressNextKey);
|
|
122
|
-
let i = e.ownerDocument;
|
|
123
|
-
if (!this.bindedDocuments.includes(i)) {
|
|
124
|
-
this.bindedDocuments.push(i);
|
|
125
|
-
let e = (e) => {
|
|
126
|
-
this.heldKeys[e.keyCode] = (this.heldKeys[e.keyCode] ?? 0) + 1;
|
|
127
|
-
}, t = (e) => {
|
|
128
|
-
this.heldKeys[e.keyCode] = 0;
|
|
129
|
-
};
|
|
130
|
-
this.documentKeydownHandlers.set(i, e), this.documentKeyupHandlers.set(i, t), i.addEventListener("keydown", e, !0), i.addEventListener("keyup", t, !0);
|
|
131
|
-
}
|
|
132
|
-
this.bindedFlipPageElements.push(e);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
//#endregion
|
|
136
|
-
export { o as KeyboardPageTurning };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../../kernal/html/finder.cjs"),t=require("../../../../kernal/html/injector.cjs"),n=require("../../../../kernal/Theme.cjs"),r=require("../../../../kernal/html/image.cjs"),i=require("./ContentLayoutCssVariableNames.cjs");var a=`no-text-intent`,o=class{constructor(r){this.documentsProvider=r,this.languagesHighlightCssId=`languages-highlight-css`,this.highlightedDocuments=new Map,this.injectCss=async(n,r)=>{if(!e.getDocumentBody(r))return;let i=await this.getHighlightCss(n);t.injectCssContent(r,i,!0,this.languagesHighlightCssId)},this.getHighlightJs=async()=>{if(this.loadedHljs)return this.loadedHljs;let{default:e}=await import(`highlight.js`);return this.loadedHljs=e,this.loadedHljs},this.getHighlightCss=async e=>{if(e.colorMode===`dark`){let{default:e}=await Promise.resolve().then(()=>require("../../../../node_modules/highlight.js/styles/github-dark.cjs"));return e.toString()}let{default:t}=await Promise.resolve().then(()=>require("../../../../node_modules/highlight.js/styles/github.cjs"));return t.toString()},this.resolveCurrentTheme=async()=>(await this.documentsProvider.owner.services.get(`themeProvider`))?.getCurrentTheme()??new n.Theme}async dispose(){this.highlightedDocuments.clear(),this.loadedHljs=void 0}async applyTheme(e){let n=this.documentsProvider.getLoadedDocuments();for(let r of n){let n=r.getContentContainer()?.ownerDocument;n&&(e.colorMode===`dark`||this.highlightedDocuments.get(r)?await this.injectCss(e,n):t.removeElement(n,this.languagesHighlightCssId))}}async highlight(e){let t=(await e.getVirtualContentContainer())?.ownerDocument;if(!t)return;let n=t.getElementsByTagName(`pre`);for(let e=0;e<n.length;e++){let t=n[e];t.classList.add(a),t.style.setProperty(`max-height`,`var(${i.ContentLayoutCssVariableNames.ColumnMaxHeight})`,`important`),t.firstElementChild&&t.firstElementChild.classList.add(a)}let o=r.getRequireHighlightCodeElements(t),s=o.length>0;if(this.highlightedDocuments.set(e,s),!s)return;let c=await this.getHighlightJs(),l=await this.resolveCurrentTheme();await this.injectCss(l,t);for(let e of o)c.highlightElement(e)}};exports.LanguageHighlighter=o;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { IDocument, IDocumentsProvider, Theme } from '../../../../kernal';
|
|
2
|
-
import { IHtmlDocument } from '../IHtmlDocument';
|
|
3
|
-
import { ILanguageHighlighter } from './ILanguageHighlighter';
|
|
4
|
-
|
|
5
|
-
export declare class LanguageHighlighter implements ILanguageHighlighter {
|
|
6
|
-
private readonly documentsProvider;
|
|
7
|
-
private readonly languagesHighlightCssId;
|
|
8
|
-
private readonly highlightedDocuments;
|
|
9
|
-
private loadedHljs?;
|
|
10
|
-
constructor(documentsProvider: IDocumentsProvider<IHtmlDocument>);
|
|
11
|
-
dispose(): Promise<void>;
|
|
12
|
-
applyTheme(theme: Theme): Promise<void>;
|
|
13
|
-
highlight(doc: IDocument): Promise<void>;
|
|
14
|
-
private injectCss;
|
|
15
|
-
private getHighlightJs;
|
|
16
|
-
private getHighlightCss;
|
|
17
|
-
private resolveCurrentTheme;
|
|
18
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { getDocumentBody as e } from "../../../../kernal/html/finder.mjs";
|
|
2
|
-
import { injectCssContent as t, removeElement as n } from "../../../../kernal/html/injector.mjs";
|
|
3
|
-
import { Theme as r } from "../../../../kernal/Theme.mjs";
|
|
4
|
-
import { getRequireHighlightCodeElements as i } from "../../../../kernal/html/image.mjs";
|
|
5
|
-
import { ContentLayoutCssVariableNames as a } from "./ContentLayoutCssVariableNames.mjs";
|
|
6
|
-
//#region mediaTypes/html/renderer/style/LanguageHighlighter.ts
|
|
7
|
-
var o = "no-text-intent", s = class {
|
|
8
|
-
constructor(n) {
|
|
9
|
-
this.documentsProvider = n, this.languagesHighlightCssId = "languages-highlight-css", this.highlightedDocuments = /* @__PURE__ */ new Map(), this.injectCss = async (n, r) => {
|
|
10
|
-
if (!e(r)) return;
|
|
11
|
-
let i = await this.getHighlightCss(n);
|
|
12
|
-
t(r, i, !0, this.languagesHighlightCssId);
|
|
13
|
-
}, this.getHighlightJs = async () => {
|
|
14
|
-
if (this.loadedHljs) return this.loadedHljs;
|
|
15
|
-
let { default: e } = await import("highlight.js");
|
|
16
|
-
return this.loadedHljs = e, this.loadedHljs;
|
|
17
|
-
}, this.getHighlightCss = async (e) => {
|
|
18
|
-
if (e.colorMode === "dark") {
|
|
19
|
-
let { default: e } = await import("../../../../node_modules/highlight.js/styles/github-dark.mjs");
|
|
20
|
-
return e.toString();
|
|
21
|
-
}
|
|
22
|
-
let { default: t } = await import("../../../../node_modules/highlight.js/styles/github.mjs");
|
|
23
|
-
return t.toString();
|
|
24
|
-
}, this.resolveCurrentTheme = async () => (await this.documentsProvider.owner.services.get("themeProvider"))?.getCurrentTheme() ?? new r();
|
|
25
|
-
}
|
|
26
|
-
async dispose() {
|
|
27
|
-
this.highlightedDocuments.clear(), this.loadedHljs = void 0;
|
|
28
|
-
}
|
|
29
|
-
async applyTheme(e) {
|
|
30
|
-
let t = this.documentsProvider.getLoadedDocuments();
|
|
31
|
-
for (let r of t) {
|
|
32
|
-
let t = r.getContentContainer()?.ownerDocument;
|
|
33
|
-
t && (e.colorMode === "dark" || this.highlightedDocuments.get(r) ? await this.injectCss(e, t) : n(t, this.languagesHighlightCssId));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async highlight(e) {
|
|
37
|
-
let t = (await e.getVirtualContentContainer())?.ownerDocument;
|
|
38
|
-
if (!t) return;
|
|
39
|
-
let n = t.getElementsByTagName("pre");
|
|
40
|
-
for (let e = 0; e < n.length; e++) {
|
|
41
|
-
let t = n[e];
|
|
42
|
-
t.classList.add(o), t.style.setProperty("max-height", `var(${a.ColumnMaxHeight})`, "important"), t.firstElementChild && t.firstElementChild.classList.add(o);
|
|
43
|
-
}
|
|
44
|
-
let r = i(t), s = r.length > 0;
|
|
45
|
-
if (this.highlightedDocuments.set(e, s), !s) return;
|
|
46
|
-
let c = await this.getHighlightJs(), l = await this.resolveCurrentTheme();
|
|
47
|
-
await this.injectCss(l, t);
|
|
48
|
-
for (let e of r) c.highlightElement(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
//#endregion
|
|
52
|
-
export { s as LanguageHighlighter };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var e=`pre code.hljs {
|
|
2
|
-
display: block;
|
|
3
|
-
overflow-x: auto;
|
|
4
|
-
padding: 1em
|
|
5
|
-
}
|
|
6
|
-
code.hljs {
|
|
7
|
-
padding: 3px 5px
|
|
8
|
-
}
|
|
9
|
-
/*!
|
|
10
|
-
Theme: GitHub Dark
|
|
11
|
-
Description: Dark theme as seen on github.com
|
|
12
|
-
Author: github.com
|
|
13
|
-
Maintainer: @Hirse
|
|
14
|
-
Updated: 2021-05-15
|
|
15
|
-
|
|
16
|
-
Outdated base version: https://github.com/primer/github-syntax-dark
|
|
17
|
-
Current colors taken from GitHub's CSS
|
|
18
|
-
*/
|
|
19
|
-
.hljs {
|
|
20
|
-
color: #c9d1d9;
|
|
21
|
-
background: #0d1117
|
|
22
|
-
}
|
|
23
|
-
.hljs-doctag,
|
|
24
|
-
.hljs-keyword,
|
|
25
|
-
.hljs-meta .hljs-keyword,
|
|
26
|
-
.hljs-template-tag,
|
|
27
|
-
.hljs-template-variable,
|
|
28
|
-
.hljs-type,
|
|
29
|
-
.hljs-variable.language_ {
|
|
30
|
-
/* prettylights-syntax-keyword */
|
|
31
|
-
color: #ff7b72
|
|
32
|
-
}
|
|
33
|
-
.hljs-title,
|
|
34
|
-
.hljs-title.class_,
|
|
35
|
-
.hljs-title.class_.inherited__,
|
|
36
|
-
.hljs-title.function_ {
|
|
37
|
-
/* prettylights-syntax-entity */
|
|
38
|
-
color: #d2a8ff
|
|
39
|
-
}
|
|
40
|
-
.hljs-attr,
|
|
41
|
-
.hljs-attribute,
|
|
42
|
-
.hljs-literal,
|
|
43
|
-
.hljs-meta,
|
|
44
|
-
.hljs-number,
|
|
45
|
-
.hljs-operator,
|
|
46
|
-
.hljs-variable,
|
|
47
|
-
.hljs-selector-attr,
|
|
48
|
-
.hljs-selector-class,
|
|
49
|
-
.hljs-selector-id {
|
|
50
|
-
/* prettylights-syntax-constant */
|
|
51
|
-
color: #79c0ff
|
|
52
|
-
}
|
|
53
|
-
.hljs-regexp,
|
|
54
|
-
.hljs-string,
|
|
55
|
-
.hljs-meta .hljs-string {
|
|
56
|
-
/* prettylights-syntax-string */
|
|
57
|
-
color: #a5d6ff
|
|
58
|
-
}
|
|
59
|
-
.hljs-built_in,
|
|
60
|
-
.hljs-symbol {
|
|
61
|
-
/* prettylights-syntax-variable */
|
|
62
|
-
color: #ffa657
|
|
63
|
-
}
|
|
64
|
-
.hljs-comment,
|
|
65
|
-
.hljs-code,
|
|
66
|
-
.hljs-formula {
|
|
67
|
-
/* prettylights-syntax-comment */
|
|
68
|
-
color: #8b949e
|
|
69
|
-
}
|
|
70
|
-
.hljs-name,
|
|
71
|
-
.hljs-quote,
|
|
72
|
-
.hljs-selector-tag,
|
|
73
|
-
.hljs-selector-pseudo {
|
|
74
|
-
/* prettylights-syntax-entity-tag */
|
|
75
|
-
color: #7ee787
|
|
76
|
-
}
|
|
77
|
-
.hljs-subst {
|
|
78
|
-
/* prettylights-syntax-storage-modifier-import */
|
|
79
|
-
color: #c9d1d9
|
|
80
|
-
}
|
|
81
|
-
.hljs-section {
|
|
82
|
-
/* prettylights-syntax-markup-heading */
|
|
83
|
-
color: #1f6feb;
|
|
84
|
-
font-weight: bold
|
|
85
|
-
}
|
|
86
|
-
.hljs-bullet {
|
|
87
|
-
/* prettylights-syntax-markup-list */
|
|
88
|
-
color: #f2cc60
|
|
89
|
-
}
|
|
90
|
-
.hljs-emphasis {
|
|
91
|
-
/* prettylights-syntax-markup-italic */
|
|
92
|
-
color: #c9d1d9;
|
|
93
|
-
font-style: italic
|
|
94
|
-
}
|
|
95
|
-
.hljs-strong {
|
|
96
|
-
/* prettylights-syntax-markup-bold */
|
|
97
|
-
color: #c9d1d9;
|
|
98
|
-
font-weight: bold
|
|
99
|
-
}
|
|
100
|
-
.hljs-addition {
|
|
101
|
-
/* prettylights-syntax-markup-inserted */
|
|
102
|
-
color: #aff5b4;
|
|
103
|
-
background-color: #033a16
|
|
104
|
-
}
|
|
105
|
-
.hljs-deletion {
|
|
106
|
-
/* prettylights-syntax-markup-deleted */
|
|
107
|
-
color: #ffdcd7;
|
|
108
|
-
background-color: #67060c
|
|
109
|
-
}
|
|
110
|
-
.hljs-char.escape_,
|
|
111
|
-
.hljs-link,
|
|
112
|
-
.hljs-params,
|
|
113
|
-
.hljs-property,
|
|
114
|
-
.hljs-punctuation,
|
|
115
|
-
.hljs-tag {
|
|
116
|
-
/* purposely ignored */
|
|
117
|
-
|
|
118
|
-
}`;exports.default=e;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
//#region node_modules/highlight.js/styles/github-dark.css?raw
|
|
2
|
-
var e = "pre code.hljs {\n display: block;\n overflow-x: auto;\n padding: 1em\n}\ncode.hljs {\n padding: 3px 5px\n}\n/*!\n Theme: GitHub Dark\n Description: Dark theme as seen on github.com\n Author: github.com\n Maintainer: @Hirse\n Updated: 2021-05-15\n\n Outdated base version: https://github.com/primer/github-syntax-dark\n Current colors taken from GitHub's CSS\n*/\n.hljs {\n color: #c9d1d9;\n background: #0d1117\n}\n.hljs-doctag,\n.hljs-keyword,\n.hljs-meta .hljs-keyword,\n.hljs-template-tag,\n.hljs-template-variable,\n.hljs-type,\n.hljs-variable.language_ {\n /* prettylights-syntax-keyword */\n color: #ff7b72\n}\n.hljs-title,\n.hljs-title.class_,\n.hljs-title.class_.inherited__,\n.hljs-title.function_ {\n /* prettylights-syntax-entity */\n color: #d2a8ff\n}\n.hljs-attr,\n.hljs-attribute,\n.hljs-literal,\n.hljs-meta,\n.hljs-number,\n.hljs-operator,\n.hljs-variable,\n.hljs-selector-attr,\n.hljs-selector-class,\n.hljs-selector-id {\n /* prettylights-syntax-constant */\n color: #79c0ff\n}\n.hljs-regexp,\n.hljs-string,\n.hljs-meta .hljs-string {\n /* prettylights-syntax-string */\n color: #a5d6ff\n}\n.hljs-built_in,\n.hljs-symbol {\n /* prettylights-syntax-variable */\n color: #ffa657\n}\n.hljs-comment,\n.hljs-code,\n.hljs-formula {\n /* prettylights-syntax-comment */\n color: #8b949e\n}\n.hljs-name,\n.hljs-quote,\n.hljs-selector-tag,\n.hljs-selector-pseudo {\n /* prettylights-syntax-entity-tag */\n color: #7ee787\n}\n.hljs-subst {\n /* prettylights-syntax-storage-modifier-import */\n color: #c9d1d9\n}\n.hljs-section {\n /* prettylights-syntax-markup-heading */\n color: #1f6feb;\n font-weight: bold\n}\n.hljs-bullet {\n /* prettylights-syntax-markup-list */\n color: #f2cc60\n}\n.hljs-emphasis {\n /* prettylights-syntax-markup-italic */\n color: #c9d1d9;\n font-style: italic\n}\n.hljs-strong {\n /* prettylights-syntax-markup-bold */\n color: #c9d1d9;\n font-weight: bold\n}\n.hljs-addition {\n /* prettylights-syntax-markup-inserted */\n color: #aff5b4;\n background-color: #033a16\n}\n.hljs-deletion {\n /* prettylights-syntax-markup-deleted */\n color: #ffdcd7;\n background-color: #67060c\n}\n.hljs-char.escape_,\n.hljs-link,\n.hljs-params,\n.hljs-property,\n.hljs-punctuation,\n.hljs-tag {\n /* purposely ignored */\n \n}";
|
|
3
|
-
//#endregion
|
|
4
|
-
export { e as default };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var e=`pre code.hljs {
|
|
2
|
-
display: block;
|
|
3
|
-
overflow-x: auto;
|
|
4
|
-
padding: 1em
|
|
5
|
-
}
|
|
6
|
-
code.hljs {
|
|
7
|
-
padding: 3px 5px
|
|
8
|
-
}
|
|
9
|
-
/*!
|
|
10
|
-
Theme: GitHub
|
|
11
|
-
Description: Light theme as seen on github.com
|
|
12
|
-
Author: github.com
|
|
13
|
-
Maintainer: @Hirse
|
|
14
|
-
Updated: 2021-05-15
|
|
15
|
-
|
|
16
|
-
Outdated base version: https://github.com/primer/github-syntax-light
|
|
17
|
-
Current colors taken from GitHub's CSS
|
|
18
|
-
*/
|
|
19
|
-
.hljs {
|
|
20
|
-
color: #24292e;
|
|
21
|
-
background: #ffffff
|
|
22
|
-
}
|
|
23
|
-
.hljs-doctag,
|
|
24
|
-
.hljs-keyword,
|
|
25
|
-
.hljs-meta .hljs-keyword,
|
|
26
|
-
.hljs-template-tag,
|
|
27
|
-
.hljs-template-variable,
|
|
28
|
-
.hljs-type,
|
|
29
|
-
.hljs-variable.language_ {
|
|
30
|
-
/* prettylights-syntax-keyword */
|
|
31
|
-
color: #d73a49
|
|
32
|
-
}
|
|
33
|
-
.hljs-title,
|
|
34
|
-
.hljs-title.class_,
|
|
35
|
-
.hljs-title.class_.inherited__,
|
|
36
|
-
.hljs-title.function_ {
|
|
37
|
-
/* prettylights-syntax-entity */
|
|
38
|
-
color: #6f42c1
|
|
39
|
-
}
|
|
40
|
-
.hljs-attr,
|
|
41
|
-
.hljs-attribute,
|
|
42
|
-
.hljs-literal,
|
|
43
|
-
.hljs-meta,
|
|
44
|
-
.hljs-number,
|
|
45
|
-
.hljs-operator,
|
|
46
|
-
.hljs-variable,
|
|
47
|
-
.hljs-selector-attr,
|
|
48
|
-
.hljs-selector-class,
|
|
49
|
-
.hljs-selector-id {
|
|
50
|
-
/* prettylights-syntax-constant */
|
|
51
|
-
color: #005cc5
|
|
52
|
-
}
|
|
53
|
-
.hljs-regexp,
|
|
54
|
-
.hljs-string,
|
|
55
|
-
.hljs-meta .hljs-string {
|
|
56
|
-
/* prettylights-syntax-string */
|
|
57
|
-
color: #032f62
|
|
58
|
-
}
|
|
59
|
-
.hljs-built_in,
|
|
60
|
-
.hljs-symbol {
|
|
61
|
-
/* prettylights-syntax-variable */
|
|
62
|
-
color: #e36209
|
|
63
|
-
}
|
|
64
|
-
.hljs-comment,
|
|
65
|
-
.hljs-code,
|
|
66
|
-
.hljs-formula {
|
|
67
|
-
/* prettylights-syntax-comment */
|
|
68
|
-
color: #6a737d
|
|
69
|
-
}
|
|
70
|
-
.hljs-name,
|
|
71
|
-
.hljs-quote,
|
|
72
|
-
.hljs-selector-tag,
|
|
73
|
-
.hljs-selector-pseudo {
|
|
74
|
-
/* prettylights-syntax-entity-tag */
|
|
75
|
-
color: #22863a
|
|
76
|
-
}
|
|
77
|
-
.hljs-subst {
|
|
78
|
-
/* prettylights-syntax-storage-modifier-import */
|
|
79
|
-
color: #24292e
|
|
80
|
-
}
|
|
81
|
-
.hljs-section {
|
|
82
|
-
/* prettylights-syntax-markup-heading */
|
|
83
|
-
color: #005cc5;
|
|
84
|
-
font-weight: bold
|
|
85
|
-
}
|
|
86
|
-
.hljs-bullet {
|
|
87
|
-
/* prettylights-syntax-markup-list */
|
|
88
|
-
color: #735c0f
|
|
89
|
-
}
|
|
90
|
-
.hljs-emphasis {
|
|
91
|
-
/* prettylights-syntax-markup-italic */
|
|
92
|
-
color: #24292e;
|
|
93
|
-
font-style: italic
|
|
94
|
-
}
|
|
95
|
-
.hljs-strong {
|
|
96
|
-
/* prettylights-syntax-markup-bold */
|
|
97
|
-
color: #24292e;
|
|
98
|
-
font-weight: bold
|
|
99
|
-
}
|
|
100
|
-
.hljs-addition {
|
|
101
|
-
/* prettylights-syntax-markup-inserted */
|
|
102
|
-
color: #22863a;
|
|
103
|
-
background-color: #f0fff4
|
|
104
|
-
}
|
|
105
|
-
.hljs-deletion {
|
|
106
|
-
/* prettylights-syntax-markup-deleted */
|
|
107
|
-
color: #b31d28;
|
|
108
|
-
background-color: #ffeef0
|
|
109
|
-
}
|
|
110
|
-
.hljs-char.escape_,
|
|
111
|
-
.hljs-link,
|
|
112
|
-
.hljs-params,
|
|
113
|
-
.hljs-property,
|
|
114
|
-
.hljs-punctuation,
|
|
115
|
-
.hljs-tag {
|
|
116
|
-
/* purposely ignored */
|
|
117
|
-
|
|
118
|
-
}`;exports.default=e;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
//#region node_modules/highlight.js/styles/github.css?raw
|
|
2
|
-
var e = "pre code.hljs {\n display: block;\n overflow-x: auto;\n padding: 1em\n}\ncode.hljs {\n padding: 3px 5px\n}\n/*!\n Theme: GitHub\n Description: Light theme as seen on github.com\n Author: github.com\n Maintainer: @Hirse\n Updated: 2021-05-15\n\n Outdated base version: https://github.com/primer/github-syntax-light\n Current colors taken from GitHub's CSS\n*/\n.hljs {\n color: #24292e;\n background: #ffffff\n}\n.hljs-doctag,\n.hljs-keyword,\n.hljs-meta .hljs-keyword,\n.hljs-template-tag,\n.hljs-template-variable,\n.hljs-type,\n.hljs-variable.language_ {\n /* prettylights-syntax-keyword */\n color: #d73a49\n}\n.hljs-title,\n.hljs-title.class_,\n.hljs-title.class_.inherited__,\n.hljs-title.function_ {\n /* prettylights-syntax-entity */\n color: #6f42c1\n}\n.hljs-attr,\n.hljs-attribute,\n.hljs-literal,\n.hljs-meta,\n.hljs-number,\n.hljs-operator,\n.hljs-variable,\n.hljs-selector-attr,\n.hljs-selector-class,\n.hljs-selector-id {\n /* prettylights-syntax-constant */\n color: #005cc5\n}\n.hljs-regexp,\n.hljs-string,\n.hljs-meta .hljs-string {\n /* prettylights-syntax-string */\n color: #032f62\n}\n.hljs-built_in,\n.hljs-symbol {\n /* prettylights-syntax-variable */\n color: #e36209\n}\n.hljs-comment,\n.hljs-code,\n.hljs-formula {\n /* prettylights-syntax-comment */\n color: #6a737d\n}\n.hljs-name,\n.hljs-quote,\n.hljs-selector-tag,\n.hljs-selector-pseudo {\n /* prettylights-syntax-entity-tag */\n color: #22863a\n}\n.hljs-subst {\n /* prettylights-syntax-storage-modifier-import */\n color: #24292e\n}\n.hljs-section {\n /* prettylights-syntax-markup-heading */\n color: #005cc5;\n font-weight: bold\n}\n.hljs-bullet {\n /* prettylights-syntax-markup-list */\n color: #735c0f\n}\n.hljs-emphasis {\n /* prettylights-syntax-markup-italic */\n color: #24292e;\n font-style: italic\n}\n.hljs-strong {\n /* prettylights-syntax-markup-bold */\n color: #24292e;\n font-weight: bold\n}\n.hljs-addition {\n /* prettylights-syntax-markup-inserted */\n color: #22863a;\n background-color: #f0fff4\n}\n.hljs-deletion {\n /* prettylights-syntax-markup-deleted */\n color: #b31d28;\n background-color: #ffeef0\n}\n.hljs-char.escape_,\n.hljs-link,\n.hljs-params,\n.hljs-property,\n.hljs-punctuation,\n.hljs-tag {\n /* purposely ignored */\n \n}";
|
|
3
|
-
//#endregion
|
|
4
|
-
export { e as default };
|