pdfjs-viewer-element 3.1.0 → 3.1.1
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/README.md +51 -67
- package/dist/pdf-DRXGYF_W.js +1 -0
- package/dist/pdfjs-viewer-element.js +1 -1
- package/dist/viewer-00vA-OlL.js +1 -0
- package/dist/viewer-DVUWiHIQ.js +1 -0
- package/dist/viewer-gf2SDly8.js +1 -0
- package/package.json +2 -2
- package/types/pdfjs-viewer-element.d.ts +2 -2
- package/dist/pdf.min-x5NwD-YK.js +0 -1
- package/dist/viewer-Cg70hpj3.js +0 -1
- package/dist/viewer-min-DkHkP1Ha.js +0 -1
- package/dist/viewer.min-Dyq1R7lM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const e_src="",e_iframeTitle="PDF viewer window",e_page="",e_search="",e_phrase="",e_zoom="",e_pagemode="none",e_locale="",e_viewerCssTheme="AUTOMATIC",e_workerSrc="https://cdn.jsdelivr.net/npm/pdfjs-dist@5.
|
|
1
|
+
const e_src="",e_iframeTitle="PDF viewer window",e_page="",e_search="",e_phrase="",e_zoom="",e_pagemode="none",e_locale="",e_viewerCssTheme="AUTOMATIC",e_workerSrc="https://cdn.jsdelivr.net/npm/pdfjs-dist@5.5.207/build/pdf.worker.min.mjs",t={AUTOMATIC:0,LIGHT:1,DARK:2};class i extends HTMLElement{constructor(){super(),this.initPromise=Promise.resolve({}),this.viewerStyles=new Set,this.applyIframeHash=async()=>new Promise(e=>{if(!this.iframe?.contentWindow)return e();this.iframe.contentWindow?.addEventListener("hashchange",()=>{e()},{once:!0}),this.iframe.contentWindow.location.hash=this.getIframeLocationHash()}),this.injectLocaleData=async()=>{const e=this.iframe.contentDocument,t=this.getAttribute("locale");if(!t)return void this.cleanupLocaleResource();const i=await import("./locale-DENudnjU.js");if(!Object.keys(JSON.parse(i.default)).includes(t))return void this.cleanupLocaleResource();const s={[String(t)]:`https://raw.githubusercontent.com/mozilla-l10n/firefox-l10n/main/${t}/toolkit/toolkit/pdfviewer/viewer.ftl`},r=e.createElement("link");r.rel="resource",r.type="application/l10n",this.cleanupLocaleResource(),this.localeResourceUrl=URL.createObjectURL(new Blob([JSON.stringify(s)],{type:"application/json"})),r.href=this.localeResourceUrl,this.iframe.contentDocument?.head.appendChild(r),this.localeResourceLink=r},this.onViewerAppCreated=()=>new Promise(e=>{const t=this.iframe.contentWindow;if(t.PDFViewerApplication)return e(t.PDFViewerApplication);let i;Object.defineProperty(t,"PDFViewerApplication",{get:()=>i,set(s){i=s,e(s),delete t.PDFViewerApplication,t.PDFViewerApplication=s},configurable:!0})}),this.applyViewerOptions=()=>{const t=this.iframe.contentWindow?.PDFViewerApplicationOptions;t?.set("workerSrc",this.getAttribute("worker-src")||e_workerSrc),t?.set("defaultUrl",this.getFullPath(this.getAttribute("src")||e_src)),t?.set("disablePreferences",!0),t?.set("eventBusDispatchToDOM",!0),t?.set("localeProperties",{lang:this.getAttribute("locale")||e_locale}),t?.set("viewerCssTheme",this.getCssThemeOption())},this.getIframeLocationHash=()=>{const t={page:this.getAttribute("page")||e_page,zoom:this.getAttribute("zoom")||e_zoom,pagemode:this.getAttribute("pagemode")||e_pagemode,search:this.getAttribute("search")||e_search,phrase:this.getAttribute("phrase")||e_phrase,locale:this.getAttribute("locale")||e_locale};return"#"+Object.entries(t).map(([e,t])=>`${e}=${t}`).join("&")},this.buildViewerEntry=async()=>new Promise(async e=>{const[t,i]=await Promise.all([import("./viewer-gf2SDly8.js"),import("./viewer-00vA-OlL.js")]),s=t.default.replace("</head>",`\n <style>${i.default}</style>\n ${Array.from(this.viewerStyles).map(e=>`<style>${e}</style>`).join("\n")}\n </head>`);this.iframe.addEventListener("load",()=>e(),{once:!0}),this.iframe.srcdoc=s}),this.setupViewerApp=async()=>{const e=await this.onViewerAppCreated();return this.applyViewerOptions(),await(e?.initializedPromise),this.applyQueuedRuntimeStyles(),{viewerApp:e}},this.buildViewerApp=async()=>{await this.applyIframeHash();const[e,t]=await Promise.all([import("./pdf-DRXGYF_W.js"),import("./viewer-DVUWiHIQ.js")]);return await this.injectLocaleData(),this.injectScript(e.default),this.injectScript(t.default),await this.setupViewerApp()},this.attachShadow({mode:"open"}).innerHTML='\n <style>:host{width:100%;display:block;overflow:hidden}:host iframe{height:100%}</style>\n <iframe frameborder="0" width="100%" loading="lazy"></iframe>\n '}static get observedAttributes(){return["src","locale","viewer-css-theme","worker-src","page","search","phrase","zoom","pagemode","iframe-title"]}getFullPath(e){return e.startsWith("/")?`${window.location.origin}${e}`:e}getCssThemeOption(){const i=this.getAttribute("viewer-css-theme");return Object.keys(t).includes(i)?t[i]:t[e_viewerCssTheme]}applyViewerTheme(){const e=this.getCssThemeOption(),i=this.iframe.contentWindow?.PDFViewerApplicationOptions;i?.set("viewerCssTheme",e);const s=this.iframe.contentDocument;if(!s?.documentElement)return;const r=e===t.LIGHT?"light":e===t.DARK?"dark":"";r?s.documentElement.style.setProperty("color-scheme",r):s.documentElement.style.removeProperty("color-scheme")}appendRuntimeStyle(e){const t=this.iframe?.contentDocument;if(!t?.head||!e)return;if(Array.from(t.querySelectorAll("style")).some(t=>t.textContent===e))return;const i=t.createElement("style");i.setAttribute("data-pdfjs-viewer-runtime-style","true"),i.textContent=e,t.head.appendChild(i)}applyQueuedRuntimeStyles(){this.viewerStyles.forEach(e=>{this.appendRuntimeStyle(e)})}injectScript(e,t="module"){const i=this.iframe.contentDocument;if(!i)return;if(!i.head){const e=i.createElement("head");i.documentElement?.prepend(e)}const s=document.createElement("script");s.type=t,s.textContent=e,i.head?.appendChild(s)}cleanupLocaleResource(){this.localeResourceLink&&(this.localeResourceLink.remove(),this.localeResourceLink=void 0),this.localeResourceUrl&&(URL.revokeObjectURL(this.localeResourceUrl),this.localeResourceUrl=void 0)}async connectedCallback(){this.iframe=this.shadowRoot?.querySelector("iframe"),this.iframe.setAttribute("title",this.getAttribute("iframe-title")||e_iframeTitle),this.initPromise=(async()=>(await this.buildViewerEntry(),await this.buildViewerApp()))()}disconnectedCallback(){for(this.cleanupLocaleResource(),this.iframe.src="about:blank";this.firstChild;)this.removeChild(this.firstChild)}async attributeChangedCallback(t,i,s){if(i!==s&&this.iframe)switch(t){case"src":{const t=this.iframe.contentWindow?.PDFViewerApplication;if(t){await t.initializedPromise;const i=this.getFullPath(s||e_src);i&&t.open({url:i})}return}case"locale":return this.cleanupLocaleResource(),this.initPromise=(async()=>(await this.buildViewerEntry(),await this.buildViewerApp()))(),void await this.initPromise;case"viewer-css-theme":return void this.applyViewerTheme();case"worker-src":{const t=this.iframe.contentWindow?.PDFViewerApplicationOptions;return void t?.set("workerSrc",s||e_workerSrc)}default:await this.applyIframeHash()}}async injectViewerStyles(e){e&&(this.viewerStyles.add(e),this.appendRuntimeStyle(e))}}window.customElements.get("pdfjs-viewer-element")||window.customElements.define("pdfjs-viewer-element",i);export{i as PdfjsViewerElement,t as ViewerCssTheme,i as default};
|