1import{app}from"../../app/app.js";import{config}from"../../app/config.js";import{setFaviconForDoc}from"../../lib/favicon.js";import{$}from"../../lib/util.js";import{Notice}from"../misc/notice.js";import{BasePage}from"../pages/base.js";import{HiddenPage}from"../pages/hidden.js";import{JqueryPage}from"../pages/jquery.js";import{RdocPage}from"../pages/rdoc.js";import{SqlitePage}from"../pages/sqlite.js";import{SupportTablesPage}from"../pages/support_tables.js";import{View}from"../view.js";const TYPE_PAGES={JqueryPage:JqueryPage,RdocPage:RdocPage,SqlitePage:SqlitePage,SupportTablesPage:SupportTablesPage};export class EntryPage extends View{static className="_page";static errorClass="_page-error";static events={click:"onClick"};static shortcuts={altC:"onAltC",altO:"onAltO"};static routes={before:"beforeRoute"};static LINKS={home:"Homepage",code:"Source code"};init(){this.cacheMap={},this.cacheStack=[]}deactivate(){super.deactivate()&&(this.hideTransientNotice(),this.empty(),this.entry=null)}loading(){this.empty(),this.trigger("loading")}render(t,e){null==t&&(t=""),null==e&&(e=!1),this.activated&&(this.empty(),this.subview=new(this.subViewClass())(this.el,this.entry),$.batchUpdate(this.el,()=>{this.subview.render(t,e),e||this.addCopyButtons()}),app.disabledDocs.findBy("slug",this.entry.doc.slug)&&(this.hiddenView=new HiddenPage(this.el,this.entry)),setFaviconForDoc(this.entry.doc),this.delay(this.polyfillMathML),this.trigger("loaded"))}addCopyButtons(){for(var t of(this.copyButton||(this.copyButton=document.createElement("button"),this.copyButton.innerHTML='<svg><use xlink:href="#icon-copy"/></svg>',this.copyButton.type="button",this.copyButton.className="_pre-clip",this.copyButton.title="Copy to clipboard",this.copyButton.setAttribute("aria-label","Copy to clipboard")),this.findAllByTag("pre")))t.appendChild(this.copyButton.cloneNode(!0))}polyfillMathML(){!1===window.supportsMathML&&!this.polyfilledMathML&&this.findByTag("math")&&(this.polyfilledMathML=!0,$.append(document.head,`<link rel="stylesheet" href="${config.mathml_stylesheet}">`))}prepareContent(t){if(!this.entry.isIndex()||!this.entry.doc.links)return t;return`<p class="_links">${Object.entries(this.entry.doc.links).map(([t,e])=>`<a href="${e}" class="_links-link">${EntryPage.LINKS[t]}</a>`).join("")}</p>${t}`}empty(){null!=this.subview&&this.subview.deactivate(),this.subview=null,null!=this.hiddenView&&this.hiddenView.deactivate(),this.hiddenView=null,this.resetClass(),super.empty()}subViewClass(){const t=this.entry.doc.type;return t&&TYPE_PAGES[`${$.classify(t)}Page`]||BasePage}getTitle(){return this.entry.doc.fullName+(this.entry.isIndex()?" documentation":` / ${this.entry.name}`)}beforeRoute(){this.cache(),this.abort()}onRoute(t){const e=t.entry.filePath()===this.entry?.filePath?.();this.entry=t.entry,e||this.restore()||this.load()}xhr;load(){this.loading(),this.xhr=this.entry.loadFile(t=>this.onSuccess(t),()=>this.onError())}abort(){this.xhr&&(this.xhr.abort(),this.xhr=this.entry=null)}onSuccess(t){this.activated&&(this.xhr=null,this.render(this.prepareContent(t)))}onError(){this.xhr=null,this.render(this.tmpl("pageLoadError")),this.resetClass(),this.addClass(this.statics().errorClass),null!=app.serviceWorker&&app.serviceWorker.update()}cache(){let t;if(!this.xhr&&this.entry&&!this.cacheMap[t=this.entry.filePath()])for(this.cacheMap[t]=this.el.innerHTML,this.cacheStack.push(t);this.cacheStack.length>config.history_cache_size;)delete this.cacheMap[this.cacheStack.shift()]}restore(){const t=this.entry.filePath();if(this.cacheMap[[t]])return this.render(this.cacheMap[t],!0),!0}onClick(t){const e=$.eventTarget(t);e.hasAttribute("data-retry")?($.stopEvent(t),this.load()):e.classList.contains("_pre-clip")&&($.stopEvent(t),navigator.clipboard.writeText(e.parentNode.textContent).then(()=>e.classList.add("_pre-clip-success"),()=>e.classList.add("_pre-clip-error")),setTimeout(()=>e.className="_pre-clip",2e3))}originalLink(){const t=this.findAll("._attribution ._attribution-link");return t[t.length-1]}onAltC(){const t=this.originalLink();t?navigator.clipboard?navigator.clipboard.writeText(t.href+location.hash).catch(()=>{this.activated&&t.isConnected&&this.showTransientNotice("copyFailed")}):this.showTransientNotice("copyFailed"):this.showTransientNotice("noOriginalLink")}onAltO(){const t=this.originalLink();t?this.delay(()=>$.popup(t.href+location.hash)):this.showTransientNotice("noOriginalLink")}showTransientNotice(t){this.hideTransientNotice(),this.transientNotice=new Notice(t),this.transientNotice.addClass("_notice-transient"),this.transientNoticeTimer=this.delay(this.hideTransientNotice,3e3)}hideTransientNotice(){this.transientNotice&&(clearTimeout(this.transientNoticeTimer),this.transientNotice.deactivate(),this.transientNotice=null,this.transientNoticeTimer=null)}}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.