pdfjs-viewer-element 3.1.1 → 3.2.0
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
|
-
const
|
|
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.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())},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-CqrRiPsP.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))}}window.customElements.get("pdfjs-viewer-element")||window.customElements.define("pdfjs-viewer-element",i);export{i as PdfjsViewerElement,t as ViewerCssTheme,i as default};
|
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfjs-viewer-element",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Oleksandr Shevchuk",
|
|
7
7
|
"email": "alekswebnet@gmail.com"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
|
-
"
|
|
10
|
+
"javascript",
|
|
11
|
+
"web-component",
|
|
12
|
+
"typescript",
|
|
13
|
+
"pdf-viewer",
|
|
14
|
+
"pdf-document",
|
|
11
15
|
"pdfjs",
|
|
12
|
-
"pdf
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
16
|
+
"react-pdf",
|
|
17
|
+
"vue-pdf",
|
|
18
|
+
"pdfium",
|
|
19
|
+
"pdf-lib",
|
|
20
|
+
"adobe-acrobat",
|
|
21
|
+
"pdf-sdk",
|
|
22
|
+
"embed-pdf",
|
|
23
|
+
"pdfjs-viewer",
|
|
24
|
+
"embed-pdf-viewer"
|
|
17
25
|
],
|
|
18
26
|
"main": "./dist/pdfjs-viewer-element.js",
|
|
19
27
|
"module": "./dist/pdfjs-viewer-element.js",
|
|
@@ -41,6 +49,7 @@
|
|
|
41
49
|
"@vitest/browser": "^4.0.18",
|
|
42
50
|
"@vitest/browser-webdriverio": "^4.0.18",
|
|
43
51
|
"jsdom": "^28.1.0",
|
|
52
|
+
"terser": "^5.39.0",
|
|
44
53
|
"typescript": "^5.9.3",
|
|
45
54
|
"vite": "^7.3.1",
|
|
46
55
|
"vitest": "^4.0.18",
|
|
@@ -48,7 +57,7 @@
|
|
|
48
57
|
},
|
|
49
58
|
"scripts": {
|
|
50
59
|
"dev": "vite",
|
|
51
|
-
"build": "tsc && vite build",
|
|
60
|
+
"build": "tsc && vite build && node scripts/copy-worker.mjs",
|
|
52
61
|
"test": "vitest",
|
|
53
62
|
"coverage": "vitest run --coverage"
|
|
54
63
|
}
|
|
@@ -11,6 +11,7 @@ export declare class PdfjsViewerElement extends HTMLElement {
|
|
|
11
11
|
private localeResourceLink?;
|
|
12
12
|
private viewerStyles;
|
|
13
13
|
static get observedAttributes(): string[];
|
|
14
|
+
private formatTemplate;
|
|
14
15
|
private getFullPath;
|
|
15
16
|
private getCssThemeOption;
|
|
16
17
|
private applyIframeHash;
|