pdfjs-viewer-element 4.0.0 → 4.0.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=new URL("./pdf.worker.min.mjs",""+import.meta.url).href,t=new URL("./pdf.mjs",""+import.meta.url).href,i=new URL("./viewer.mjs",""+import.meta.url).href,r=new URL("./viewer.css",""+import.meta.url).href,s=new URL("./paper-and-ink.css",""+import.meta.url).href,a={src:"",iframeTitle:"PDF viewer window",page:"",search:"",phrase:"",zoom:"",pagemode:"none",locale:"",viewerCssTheme:"AUTOMATIC",workerSrc:e,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"},n={AUTOMATIC:0,LIGHT:1,DARK:2},o=class extends HTMLElement{constructor(){super(),this.initPromise=Promise.resolve({}),this.viewerStyles=new Set,this.optionsToSet={},this.applyIframeHash=async()=>{const e=this.iframe?.contentWindow;if(!e)return;const t=this.getIframeLocationHash();e.location.hash!==t&&await new Promise(i=>{let r=!1;const s=()=>{r||(r=!0,e.removeEventListener("hashchange",s),i())};e.addEventListener("hashchange",s),e.location.hash=t,queueMicrotask(()=>{e.location.hash===t&&s()})})},this.applyLocaleAtRuntime=async()=>{const e=this.iframe.contentWindow?.PDFViewerApplication,t=this.iframe.contentDocument;if(!e||!t)return!1;await e.initializedPromise;const i=e.externalServices?.createL10n;if("function"!=typeof i)return!1;const r=await i();if(!r)return!1;await(e.l10n?.destroy?.()),e.l10n=r;const s=e.appConfig?.appContainer||t.documentElement;return!!s&&("function"==typeof r.getDirection&&t.documentElement?.setAttribute("dir",r.getDirection()),"function"==typeof r.translate&&await r.translate(s),!0)},this.injectLocaleData=async()=>{const e=this.iframe.contentDocument,t=this.getAttribute("locale");if(!t)return void this.cleanupLocaleResource();const i=await(import("./locale-kKW4I85A.js"));if(!Object.keys(JSON.parse(i.default)).includes(t))return void this.cleanupLocaleResource();const r=this.formatTemplate(this.getAttribute("locale-src-template")||a.localeSrcTemplate,{locale:t}),s={[String(t)]:r},n=e.createElement("link");n.rel="resource",n.type="application/l10n",this.cleanupLocaleResource(),this.localeResourceUrl=URL.createObjectURL(new Blob([JSON.stringify(s)],{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 e=this.iframe.contentWindow?.PDFViewerApplicationOptions;e?.set("workerSrc",this.getAttribute("worker-src")||a.workerSrc),e?.set("debuggerSrc",this.getAttribute("debugger-src")||a.debuggerSrc),e?.set("cMapUrl",this.getAttribute("c-map-url")||a.cMapUrl),e?.set("iccUrl",this.getAttribute("icc-url")||a.iccUrl),e?.set("imageResourcesPath",this.getAttribute("image-resources-path")||a.imageResourcesPath),e?.set("sandboxBundleSrc",this.getAttribute("sandbox-bundle-src")||a.sandboxBundleSrc),e?.set("standardFontDataUrl",this.getAttribute("standard-font-data-url")||a.standardFontDataUrl),e?.set("wasmUrl",this.getAttribute("wasm-url")||a.wasmUrl),e?.set("defaultUrl",this.getFullPath(this.getAttribute("src")||a.src)),e?.set("disablePreferences",!0),e?.set("eventBusDispatchToDOM",!0),e?.set("localeProperties",{lang:this.getAttribute("locale")||a.locale}),e?.set("viewerCssTheme",this.getCssThemeOption());for(const[t,i]of Object.entries(this.optionsToSet))e?.set(t,i);this.optionsToSet={}},this.getIframeLocationHash=()=>{const e={page:this.getAttribute("page")||a.page,zoom:this.getAttribute("zoom")||a.zoom,pagemode:this.getAttribute("pagemode")||a.pagemode,search:this.getAttribute("search")||a.search,phrase:this.getAttribute("phrase")||a.phrase,locale:this.getAttribute("locale")||a.locale};return"#"+Object.entries(e).map(([e,t])=>`${e}=${t}`).join("&")},this.buildViewerEntry=async()=>new Promise(async e=>{const t=await(import("./_virtual_pdfjs-viewer-html-Db40JDMA.js")),i=window.location.origin,a=["default-src 'none'",`script-src 'self' 'wasm-unsafe-eval' ${i}`,`script-src-elem ${i}`,`worker-src ${i} blob:`,`style-src ${i} 'unsafe-inline'`,`img-src ${i} blob: data:`,"media-src blob:",`font-src ${i} data:`,"connect-src * blob: data:","base-uri 'none'","form-action 'none'"].join("; "),n=t.default.replace(/<meta\s+http-equiv="Content-Security-Policy"[^>]*>/i,`<meta http-equiv="Content-Security-Policy" content="${a};" />`).replace("</head>",`\n <link rel="stylesheet" href="${r}">\n <link rel="stylesheet" href="${s}">\n ${Array.from(this.viewerStyles).map(e=>`<style>${e}</style>`).join("\n")}\n </head>`);this.iframe.addEventListener("load",()=>e(),{once:!0}),this.iframe.srcdoc=n}),this.setupViewerApp=async()=>{const e=await this.onViewerAppCreated();return this.applyViewerOptions(),await(e?.initializedPromise),this.applyViewerTheme(),this.applyQueuedRuntimeStyles(),{viewerApp:e}},this.buildViewerApp=async()=>{await this.applyIframeHash();const e=this.setupViewerApp();return await this.injectLocaleData(),await this.injectScript(t),await this.injectScript(i),await e},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){if(!e)return e;try{return new URL(e,window.location.href).href}catch{return e}}getCssThemeOption(){const e=this.getAttribute("viewer-css-theme");return Object.keys(n).includes(e)?n[e]:n[a.viewerCssTheme]}applyViewerTheme(){const e=this.getCssThemeOption();(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("viewerCssTheme",e);const t=this.iframe.contentDocument;if(!t?.documentElement)return;const i=e===n.LIGHT?"light":e===n.DARK?"dark":"";i?t.documentElement.style.setProperty("color-scheme",i):t.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 Promise.resolve();if(!i.head){const e=i.createElement("head");i.documentElement?.prepend(e)}return new Promise((r,s)=>{let a="";const n=e=>{a=` (CSP ${e.effectiveDirective||e.violatedDirective||"unknown-directive"} blocked ${e.blockedURI||"unknown-uri"})`},o=()=>{i.removeEventListener("securitypolicyviolation",n)};i.addEventListener("securitypolicyviolation",n);const c=i.createElement("script");c.type=t,c.src=e,c.addEventListener("load",()=>{o(),r()},{once:!0}),c.addEventListener("error",()=>{o(),s(new Error(`Unable to load script: ${e}${a}`))},{once:!0}),i.head?.appendChild(c)})}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")||a.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(e,t,i){if(t===i)return;if(!this.iframe)return;const r={"debugger-src":{key:"debuggerSrc",fallback:a.debuggerSrc},"c-map-url":{key:"cMapUrl",fallback:a.cMapUrl},"icc-url":{key:"iccUrl",fallback:a.iccUrl},"image-resources-path":{key:"imageResourcesPath",fallback:a.imageResourcesPath},"sandbox-bundle-src":{key:"sandboxBundleSrc",fallback:a.sandboxBundleSrc},"standard-font-data-url":{key:"standardFontDataUrl",fallback:a.standardFontDataUrl},"wasm-url":{key:"wasmUrl",fallback:a.wasmUrl}};if("worker-src"!==e){if(e in r){const t=this.iframe.contentWindow?.PDFViewerApplicationOptions,{key:s,fallback:a}=r[e];return void t?.set(s,i||a)}switch(e){case"src":{const e=this.iframe.contentWindow?.PDFViewerApplication;if(e){await e.initializedPromise;const t=this.getFullPath(i||a.src);t&&e.open({url:t})}return}case"locale":return(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("localeProperties",{lang:i||a.locale}),this.cleanupLocaleResource(),await this.injectLocaleData(),await this.applyLocaleAtRuntime()||(this.initPromise=(async()=>(await this.buildViewerEntry(),await this.buildViewerApp()))(),await this.initPromise),void await this.applyIframeHash();case"iframe-title":return void this.iframe.setAttribute("title",i||a.iframeTitle);case"viewer-css-theme":return void this.applyViewerTheme();default:await this.applyIframeHash()}}else(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("workerSrc",i||a.workerSrc)}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",o);export{o as PdfjsViewerElement,o as default,n as ViewerCssTheme};
|
|
1
|
+
var e=new URL("./pdf.worker.min.mjs",""+import.meta.url).href,t=new URL("./pdf.mjs",""+import.meta.url).href,i=new URL("./viewer.mjs",""+import.meta.url).href,r=new URL("./viewer.css",""+import.meta.url).href,s=new URL("./paper-and-ink.css",""+import.meta.url).href,a={src:"",iframeTitle:"PDF viewer window",page:"",search:"",phrase:"",zoom:"",pagemode:"none",locale:"",viewerCssTheme:"AUTOMATIC",workerSrc:e,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"},n={AUTOMATIC:0,LIGHT:1,DARK:2},o=class extends HTMLElement{constructor(){super(),this.initPromise=Promise.resolve({}),this.viewerStyles=new Set,this.optionsToSet={},this.applyIframeHash=async()=>{const e=this.iframe?.contentWindow;if(!e)return;const t=this.getIframeLocationHash();e.location.hash!==t&&await new Promise(i=>{let r=!1;const s=()=>{r||(r=!0,e.removeEventListener("hashchange",s),i())};e.addEventListener("hashchange",s),e.location.hash=t,queueMicrotask(()=>{e.location.hash===t&&s()})})},this.applyLocaleAtRuntime=async()=>{const e=this.iframe.contentWindow?.PDFViewerApplication,t=this.iframe.contentDocument;if(!e||!t)return!1;await e.initializedPromise;const i=e.externalServices?.createL10n;if("function"!=typeof i)return!1;const r=await i();if(!r)return!1;await(e.l10n?.destroy?.()),e.l10n=r;const s=e.appConfig?.appContainer||t.documentElement;return!!s&&("function"==typeof r.getDirection&&t.documentElement?.setAttribute("dir",r.getDirection()),"function"==typeof r.translate&&await r.translate(s),!0)},this.injectLocaleData=async()=>{const e=this.iframe.contentDocument,t=this.getAttribute("locale");if(!t)return void this.cleanupLocaleResource();const i=await(import("./locale-kKW4I85A.js"));if(!Object.keys(JSON.parse(i.default)).includes(t))return void this.cleanupLocaleResource();const r=this.formatTemplate(this.getAttribute("locale-src-template")||a.localeSrcTemplate,{locale:t}),s={[String(t)]:r},n=e.createElement("link");n.rel="resource",n.type="application/l10n",this.cleanupLocaleResource(),this.localeResourceUrl=URL.createObjectURL(new Blob([JSON.stringify(s)],{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 e=this.iframe.contentWindow?.PDFViewerApplicationOptions;e?.set("workerSrc",this.getAttribute("worker-src")||a.workerSrc),e?.set("debuggerSrc",this.getAttribute("debugger-src")||a.debuggerSrc),e?.set("cMapUrl",this.getAttribute("c-map-url")||a.cMapUrl),e?.set("iccUrl",this.getAttribute("icc-url")||a.iccUrl),e?.set("imageResourcesPath",this.getAttribute("image-resources-path")||a.imageResourcesPath),e?.set("sandboxBundleSrc",this.getAttribute("sandbox-bundle-src")||a.sandboxBundleSrc),e?.set("standardFontDataUrl",this.getAttribute("standard-font-data-url")||a.standardFontDataUrl),e?.set("wasmUrl",this.getAttribute("wasm-url")||a.wasmUrl),e?.set("defaultUrl",this.getFullPath(this.getAttribute("src")||a.src)),e?.set("disablePreferences",!0),e?.set("eventBusDispatchToDOM",!0),e?.set("localeProperties",{lang:this.getAttribute("locale")||a.locale}),e?.set("viewerCssTheme",this.getCssThemeOption());for(const[t,i]of Object.entries(this.optionsToSet))e?.set(t,i);this.optionsToSet={}},this.getIframeLocationHash=()=>{const e={page:this.getAttribute("page")||a.page,zoom:this.getAttribute("zoom")||a.zoom,pagemode:this.getAttribute("pagemode")||a.pagemode,search:this.getAttribute("search")||a.search,phrase:this.getAttribute("phrase")||a.phrase,locale:this.getAttribute("locale")||a.locale};return"#"+Object.entries(e).map(([e,t])=>`${e}=${t}`).join("&")},this.buildViewerEntry=async()=>new Promise(async e=>{const n=await(import("./_virtual_pdfjs-viewer-html-Db40JDMA.js")),o=e=>{try{const t=new URL(e,window.location.href);if("http:"===t.protocol||"https:"===t.protocol)return t.origin}catch{}return""},c=e=>Array.from(new Set(e.filter(Boolean))).join(" "),l=o(this.getAttribute("worker-src")||a.workerSrc),h=c(["'self'",window.location.origin,o(t),o(i),l]),p=c(["'self'",window.location.origin,o(r),o(s)]),u=["default-src 'none'",`script-src ${h} 'wasm-unsafe-eval'`,`script-src-elem ${h}`,`worker-src ${c(["'self'","blob:",window.location.origin,l])}`,`style-src ${p} 'unsafe-inline'`,`img-src ${p} blob: data:`,"media-src blob:",`font-src ${p} data:`,"connect-src * blob: data:","base-uri 'none'","form-action 'none'"].join("; "),d=n.default.replace(/<meta\s+http-equiv="Content-Security-Policy"[^>]*>/i,`<meta http-equiv="Content-Security-Policy" content="${u};" />`).replace("</head>",`\n <link rel="stylesheet" href="${r}">\n <link rel="stylesheet" href="${s}">\n ${Array.from(this.viewerStyles).map(e=>`<style>${e}</style>`).join("\n")}\n </head>`);this.iframe.addEventListener("load",()=>e(),{once:!0}),this.iframe.srcdoc=d}),this.setupViewerApp=async()=>{const e=await this.onViewerAppCreated();return this.applyViewerOptions(),await(e?.initializedPromise),this.applyViewerTheme(),this.applyQueuedRuntimeStyles(),{viewerApp:e}},this.buildViewerApp=async()=>{await this.applyIframeHash();const e=this.setupViewerApp();return await this.injectLocaleData(),await this.injectScript(t),await this.injectScript(i),await e},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){if(!e)return e;try{return new URL(e,window.location.href).href}catch{return e}}getCssThemeOption(){const e=this.getAttribute("viewer-css-theme");return Object.keys(n).includes(e)?n[e]:n[a.viewerCssTheme]}applyViewerTheme(){const e=this.getCssThemeOption();(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("viewerCssTheme",e);const t=this.iframe.contentDocument;if(!t?.documentElement)return;const i=e===n.LIGHT?"light":e===n.DARK?"dark":"";i?t.documentElement.style.setProperty("color-scheme",i):t.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 Promise.resolve();if(!i.head){const e=i.createElement("head");i.documentElement?.prepend(e)}return new Promise((r,s)=>{let a="";const n=e=>{a=` (CSP ${e.effectiveDirective||e.violatedDirective||"unknown-directive"} blocked ${e.blockedURI||"unknown-uri"})`},o=()=>{i.removeEventListener("securitypolicyviolation",n)};i.addEventListener("securitypolicyviolation",n);const c=i.createElement("script");c.type=t,c.src=e,c.addEventListener("load",()=>{o(),r()},{once:!0}),c.addEventListener("error",()=>{o(),s(new Error(`Unable to load script: ${e}${a}`))},{once:!0}),i.head?.appendChild(c)})}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")||a.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(e,t,i){if(t===i)return;if(!this.iframe)return;const r={"debugger-src":{key:"debuggerSrc",fallback:a.debuggerSrc},"c-map-url":{key:"cMapUrl",fallback:a.cMapUrl},"icc-url":{key:"iccUrl",fallback:a.iccUrl},"image-resources-path":{key:"imageResourcesPath",fallback:a.imageResourcesPath},"sandbox-bundle-src":{key:"sandboxBundleSrc",fallback:a.sandboxBundleSrc},"standard-font-data-url":{key:"standardFontDataUrl",fallback:a.standardFontDataUrl},"wasm-url":{key:"wasmUrl",fallback:a.wasmUrl}};if("worker-src"!==e){if(e in r){const t=this.iframe.contentWindow?.PDFViewerApplicationOptions,{key:s,fallback:a}=r[e];return void t?.set(s,i||a)}switch(e){case"src":{const e=this.iframe.contentWindow?.PDFViewerApplication;if(e){await e.initializedPromise;const t=this.getFullPath(i||a.src);t&&e.open({url:t})}return}case"locale":return(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("localeProperties",{lang:i||a.locale}),this.cleanupLocaleResource(),await this.injectLocaleData(),await this.applyLocaleAtRuntime()||(this.initPromise=(async()=>(await this.buildViewerEntry(),await this.buildViewerApp()))(),await this.initPromise),void await this.applyIframeHash();case"iframe-title":return void this.iframe.setAttribute("title",i||a.iframeTitle);case"viewer-css-theme":return void this.applyViewerTheme();default:await this.applyIframeHash()}}else(this.iframe.contentWindow?.PDFViewerApplicationOptions)?.set("workerSrc",i||a.workerSrc)}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",o);export{o as PdfjsViewerElement,o as default,n as ViewerCssTheme};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfjs-viewer-element",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Oleksandr Shevchuk",
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"types": "types/pdfjs-viewer-element.d.ts",
|
|
29
29
|
"type": "module",
|
|
30
30
|
"exports": {
|
|
31
|
-
".":
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./types/pdfjs-viewer-element.d.ts",
|
|
33
|
+
"default": "./dist/pdfjs-viewer-element.js"
|
|
34
|
+
},
|
|
32
35
|
"./dist/*": "./dist/*"
|
|
33
36
|
},
|
|
34
37
|
"repository": {
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
2
|
+
import type { EventBus } from 'pdfjs-dist/types/web/event_utils';
|
|
1
3
|
export declare const ViewerCssTheme: {
|
|
2
4
|
readonly AUTOMATIC: 0;
|
|
3
5
|
readonly LIGHT: 1;
|
|
4
6
|
readonly DARK: 2;
|
|
5
7
|
};
|
|
8
|
+
export type PdfViewerApplicationOpenParameters = (DocumentInitParameters & {
|
|
9
|
+
originalUrl?: string;
|
|
10
|
+
}) | Uint8Array;
|
|
11
|
+
export type PdfViewerApplicationOptionValue = string | boolean | number | Record<string, unknown>;
|
|
12
|
+
export interface PdfViewerApplication {
|
|
13
|
+
initializedPromise: Promise<void>;
|
|
14
|
+
initialized: boolean;
|
|
15
|
+
eventBus: EventBus;
|
|
16
|
+
open: (params: PdfViewerApplicationOpenParameters) => void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface PdfViewerApplicationOptions {
|
|
19
|
+
set: (name: string, value: PdfViewerApplicationOptionValue) => void;
|
|
20
|
+
getAll: () => Record<string, unknown>;
|
|
21
|
+
}
|
|
6
22
|
export declare class PdfjsViewerElement extends HTMLElement {
|
|
7
23
|
constructor();
|
|
8
24
|
iframe: PdfjsViewerElementIframe;
|
|
@@ -33,34 +49,18 @@ export declare class PdfjsViewerElement extends HTMLElement {
|
|
|
33
49
|
disconnectedCallback(): void;
|
|
34
50
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): Promise<void>;
|
|
35
51
|
injectViewerStyles(styles: string): Promise<void>;
|
|
36
|
-
setViewerOptions(options?: Record<string,
|
|
37
|
-
viewerOptions:
|
|
38
|
-
set: (name: string, value: string | boolean | number | Record<string, any>) => void;
|
|
39
|
-
getAll: () => Record<string, any>;
|
|
40
|
-
};
|
|
52
|
+
setViewerOptions(options?: Record<string, PdfViewerApplicationOptionValue>): Promise<{
|
|
53
|
+
viewerOptions: PdfViewerApplicationOptions;
|
|
41
54
|
}>;
|
|
42
55
|
}
|
|
43
56
|
export interface IframeWindow extends Window {
|
|
44
|
-
PDFViewerApplication?:
|
|
45
|
-
|
|
46
|
-
initialized: boolean;
|
|
47
|
-
eventBus: Record<string, any>;
|
|
48
|
-
open: (params: {
|
|
49
|
-
url: string;
|
|
50
|
-
originalUrl?: string;
|
|
51
|
-
} | {
|
|
52
|
-
data: Uint8Array;
|
|
53
|
-
} | Uint8Array) => void;
|
|
54
|
-
};
|
|
55
|
-
PDFViewerApplicationOptions: {
|
|
56
|
-
set: (name: string, value: string | boolean | number | Record<string, any>) => void;
|
|
57
|
-
getAll: () => Record<string, any>;
|
|
58
|
-
};
|
|
57
|
+
PDFViewerApplication?: PdfViewerApplication;
|
|
58
|
+
PDFViewerApplicationOptions: PdfViewerApplicationOptions;
|
|
59
59
|
}
|
|
60
60
|
export interface PdfjsViewerElementIframe extends HTMLIFrameElement {
|
|
61
61
|
contentWindow: IframeWindow;
|
|
62
62
|
}
|
|
63
63
|
export interface InitializationData {
|
|
64
|
-
viewerApp?:
|
|
64
|
+
viewerApp?: PdfViewerApplication;
|
|
65
65
|
}
|
|
66
66
|
export default PdfjsViewerElement;
|