pdfjs-viewer-element 3.2.1 → 3.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.
@@ -1 +1 @@
1
- var e={src:"",iframeTitle:"PDF viewer window",page:"",search:"",phrase:"",zoom:"",pagemode:"none",locale:"",viewerCssTheme:"AUTOMATIC",workerSrc:new URL("./pdf.worker.min.mjs",""+import.meta.url).href,debuggerSrc:"./debugger.mjs",cMapUrl:"../web/cmaps/",iccUrl:"../web/iccs/",imageResourcesPath:"./images/",sandboxBundleSrc:"../build/pdf.sandbox.mjs",standardFontDataUrl:"../web/standard_fonts/",wasmUrl:"../web/wasm/",localeSrcTemplate:"https://cdn.jsdelivr.net/gh/mozilla-l10n/firefox-l10n@main/{locale}/toolkit/toolkit/pdfviewer/viewer.ftl"},t={AUTOMATIC:0,LIGHT:1,DARK:2},i=class extends HTMLElement{constructor(){super(),this.initPromise=Promise.resolve({}),this.viewerStyles=new Set,this.optionsToSet={},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 t=this.iframe.contentDocument,i=this.getAttribute("locale");if(!i)return void this.cleanupLocaleResource();const r=await import("./locale-ZlyOoh6p.js");if(!Object.keys(JSON.parse(r.default)).includes(i))return void this.cleanupLocaleResource();const s=this.formatTemplate(this.getAttribute("locale-src-template")||e.localeSrcTemplate,{locale:i}),a={[String(i)]:s},n=t.createElement("link");n.rel="resource",n.type="application/l10n",this.cleanupLocaleResource(),this.localeResourceUrl=URL.createObjectURL(new Blob([JSON.stringify(a)],{type:"application/json"})),n.href=this.localeResourceUrl,this.iframe.contentDocument?.head.appendChild(n),this.localeResourceLink=n},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(r){i=r,e(r),delete t.PDFViewerApplication,t.PDFViewerApplication=r},configurable:!0})}),this.applyViewerOptions=()=>{const t=this.iframe.contentWindow?.PDFViewerApplicationOptions;t?.set("workerSrc",this.getAttribute("worker-src")||e.workerSrc),t?.set("debuggerSrc",this.getAttribute("debugger-src")||e.debuggerSrc),t?.set("cMapUrl",this.getAttribute("c-map-url")||e.cMapUrl),t?.set("iccUrl",this.getAttribute("icc-url")||e.iccUrl),t?.set("imageResourcesPath",this.getAttribute("image-resources-path")||e.imageResourcesPath),t?.set("sandboxBundleSrc",this.getAttribute("sandbox-bundle-src")||e.sandboxBundleSrc),t?.set("standardFontDataUrl",this.getAttribute("standard-font-data-url")||e.standardFontDataUrl),t?.set("wasmUrl",this.getAttribute("wasm-url")||e.wasmUrl),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());for(const[e,i]of Object.entries(this.optionsToSet))t?.set(e,i);this.optionsToSet={}},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,r]=await Promise.all([import("./viewer-asGZOfPa.js"),import("./viewer-BDue30WQ.js"),import("./paper-and-ink-DgTYBeKf.js")]),s=t.default.replace("</head>",`\n <style>${i.default}</style>\n <style>${r.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-Db_S0hNt.js"),import("./viewer-D69caMA4.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","debugger-src","c-map-url","icc-url","image-resources-path","sandbox-bundle-src","standard-font-data-url","wasm-url","page","search","phrase","zoom","pagemode","iframe-title"]}formatTemplate(e,t){return e.replace(/\{(\w+)\}/g,(e,i)=>{if(!(i in t))throw new Error(`Missing param: ${i}`);return String(t[i])})}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();(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("viewerCssTheme",e);const i=this.iframe.contentDocument;if(!i?.documentElement)return;const r=e===t.LIGHT?"light":e===t.DARK?"dark":"";r?i.documentElement.style.setProperty("color-scheme",r):i.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 r=document.createElement("script");r.type=t,r.textContent=e,i.head?.appendChild(r)}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,r){if(i===r)return;if(!this.iframe)return;const s={"worker-src":{key:"workerSrc",fallback:e.workerSrc},"debugger-src":{key:"debuggerSrc",fallback:e.debuggerSrc},"c-map-url":{key:"cMapUrl",fallback:e.cMapUrl},"icc-url":{key:"iccUrl",fallback:e.iccUrl},"image-resources-path":{key:"imageResourcesPath",fallback:e.imageResourcesPath},"sandbox-bundle-src":{key:"sandboxBundleSrc",fallback:e.sandboxBundleSrc},"standard-font-data-url":{key:"standardFontDataUrl",fallback:e.standardFontDataUrl},"wasm-url":{key:"wasmUrl",fallback:e.wasmUrl}};if(t in s){const e=this.iframe.contentWindow?.PDFViewerApplicationOptions,{key:i,fallback:a}=s[t];return void e?.set(i,r||a)}switch(t){case"src":{const t=this.iframe.contentWindow?.PDFViewerApplication;if(t){await t.initializedPromise;const i=this.getFullPath(r||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();default:await this.applyIframeHash()}}async injectViewerStyles(e){e&&(this.viewerStyles.add(e),this.appendRuntimeStyle(e))}async setViewerOptions(e={}){return this.optionsToSet=e,await this.initPromise,{viewerOptions:this.iframe.contentWindow?.PDFViewerApplicationOptions}}};window.customElements.get("pdfjs-viewer-element")||window.customElements.define("pdfjs-viewer-element",i);export{i as PdfjsViewerElement,i as default,t as ViewerCssTheme};
1
+ const e={src:"",iframeTitle:"PDF viewer window",page:"",search:"",phrase:"",zoom:"",pagemode:"none",locale:"",viewerCssTheme:"AUTOMATIC",workerSrc:new URL("./pdf.worker.min.mjs",import.meta.url).href,debuggerSrc:"./debugger.mjs",cMapUrl:"../web/cmaps/",iccUrl:"../web/iccs/",imageResourcesPath:"./images/",sandboxBundleSrc:"../build/pdf.sandbox.mjs",standardFontDataUrl:"../web/standard_fonts/",wasmUrl:"../web/wasm/",localeSrcTemplate:"https://cdn.jsdelivr.net/gh/mozilla-l10n/firefox-l10n@main/{locale}/toolkit/toolkit/pdfviewer/viewer.ftl"},t={AUTOMATIC:0,LIGHT:1,DARK:2};class i extends HTMLElement{constructor(){super(),this.initPromise=Promise.resolve({}),this.viewerStyles=new Set,this.optionsToSet={},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 t=this.iframe.contentDocument,i=this.getAttribute("locale");if(!i)return void this.cleanupLocaleResource();const r=await import("./locale-DENudnjU.js");if(!Object.keys(JSON.parse(r.default)).includes(i))return void this.cleanupLocaleResource();const s=this.formatTemplate(this.getAttribute("locale-src-template")||e.localeSrcTemplate,{locale:i}),a={[String(i)]:s},n=t.createElement("link");n.rel="resource",n.type="application/l10n",this.cleanupLocaleResource(),this.localeResourceUrl=URL.createObjectURL(new Blob([JSON.stringify(a)],{type:"application/json"})),n.href=this.localeResourceUrl,this.iframe.contentDocument?.head.appendChild(n),this.localeResourceLink=n},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(r){i=r,e(r),delete t.PDFViewerApplication,t.PDFViewerApplication=r},configurable:!0})}),this.applyViewerOptions=()=>{const t=this.iframe.contentWindow?.PDFViewerApplicationOptions;t?.set("workerSrc",this.getAttribute("worker-src")||e.workerSrc),t?.set("debuggerSrc",this.getAttribute("debugger-src")||e.debuggerSrc),t?.set("cMapUrl",this.getAttribute("c-map-url")||e.cMapUrl),t?.set("iccUrl",this.getAttribute("icc-url")||e.iccUrl),t?.set("imageResourcesPath",this.getAttribute("image-resources-path")||e.imageResourcesPath),t?.set("sandboxBundleSrc",this.getAttribute("sandbox-bundle-src")||e.sandboxBundleSrc),t?.set("standardFontDataUrl",this.getAttribute("standard-font-data-url")||e.standardFontDataUrl),t?.set("wasmUrl",this.getAttribute("wasm-url")||e.wasmUrl),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());for(const[e,i]of Object.entries(this.optionsToSet))t?.set(e,i);this.optionsToSet={}},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,r]=await Promise.all([import("./viewer-gf2SDly8.js"),import("./viewer-00vA-OlL.js"),import("./paper-and-ink-w6df3wtN.js")]),s=t.default.replace("</head>",`\n <style>${i.default}</style>\n <style>${r.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","debugger-src","c-map-url","icc-url","image-resources-path","sandbox-bundle-src","standard-font-data-url","wasm-url","page","search","phrase","zoom","pagemode","iframe-title"]}formatTemplate(e,t){return e.replace(/\{(\w+)\}/g,(e,i)=>{if(!(i in t))throw new Error(`Missing param: ${i}`);return String(t[i])})}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 r=this.iframe.contentDocument;if(!r?.documentElement)return;const s=e===t.LIGHT?"light":e===t.DARK?"dark":"";s?r.documentElement.style.setProperty("color-scheme",s):r.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 r=document.createElement("script");r.type=t,r.textContent=e,i.head?.appendChild(r)}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,r){if(i===r)return;if(!this.iframe)return;const s={"worker-src":{key:"workerSrc",fallback:e.workerSrc},"debugger-src":{key:"debuggerSrc",fallback:e.debuggerSrc},"c-map-url":{key:"cMapUrl",fallback:e.cMapUrl},"icc-url":{key:"iccUrl",fallback:e.iccUrl},"image-resources-path":{key:"imageResourcesPath",fallback:e.imageResourcesPath},"sandbox-bundle-src":{key:"sandboxBundleSrc",fallback:e.sandboxBundleSrc},"standard-font-data-url":{key:"standardFontDataUrl",fallback:e.standardFontDataUrl},"wasm-url":{key:"wasmUrl",fallback:e.wasmUrl}};if(t in s){const e=this.iframe.contentWindow?.PDFViewerApplicationOptions,{key:i,fallback:a}=s[t];return void e?.set(i,r||a)}switch(t){case"src":{const t=this.iframe.contentWindow?.PDFViewerApplication;if(t){await t.initializedPromise;const i=this.getFullPath(r||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();default:await this.applyIframeHash()}}async injectViewerStyles(e){e&&(this.viewerStyles.add(e),this.appendRuntimeStyle(e))}async setViewerOptions(e={}){return this.optionsToSet=e,await this.initPromise,{viewerOptions:this.iframe.contentWindow?.PDFViewerApplicationOptions}}}window.customElements.get("pdfjs-viewer-element")||window.customElements.define("pdfjs-viewer-element",i);export{i as PdfjsViewerElement,t as ViewerCssTheme,i as default};