Socket
Socket
Sign inDemoInstall

pdfjs-viewer-element

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfjs-viewer-element - npm Package Compare versions

Comparing version 2.3.3 to 2.4.0

84

dist/pdfjs-viewer-element.js

@@ -1,10 +0,10 @@

const w = (l, e) => new Promise((t, n) => {
let r = e.querySelector(l);
if (r) {
t(r);
const m = (h, e) => new Promise((t, o) => {
let i = e.querySelector(h);
if (i) {
t(i);
return;
}
new MutationObserver((h, s) => {
Array.from(e.querySelectorAll(l)).forEach((o) => {
t(o), s.disconnect();
new MutationObserver((s, r) => {
Array.from(e.querySelectorAll(h)).forEach((n) => {
t(n), r.disconnect();
});

@@ -18,29 +18,29 @@ }).observe(e, {

};
function b(l, e = 25, t = {}) {
function b(h, e = 25, t = {}) {
if (t = { ...g, ...t }, !Number.isFinite(e))
throw new TypeError("Expected `wait` to be a finite number");
let n, r, h = [], s, o;
const d = (a, c) => (s = y(l, a, c), s.finally(() => {
if (s = null, t.trailing && o && !r) {
const u = d(a, o);
return o = null, u;
let o, i, s = [], r, n;
const l = (c, d) => (r = y(h, c, d), r.finally(() => {
if (r = null, t.trailing && n && !i) {
const u = l(c, n);
return n = null, u;
}
}), s);
return function(...a) {
return s ? (t.trailing && (o = a), s) : new Promise((c) => {
const u = !r && t.leading;
clearTimeout(r), r = setTimeout(() => {
r = null;
const f = t.leading ? n : d(this, a);
for (const p of h)
}), r);
return function(...c) {
return r ? (t.trailing && (n = c), r) : new Promise((d) => {
const u = !i && t.leading;
clearTimeout(i), i = setTimeout(() => {
i = null;
const f = t.leading ? o : l(this, c);
for (const p of s)
p(f);
h = [];
}, e), u ? (n = d(this, a), c(n)) : h.push(c);
s = [];
}, e), u ? (o = l(this, c), d(o)) : s.push(d);
});
};
}
async function y(l, e, t) {
return await l.apply(e, t);
async function y(h, e, t) {
return await h.apply(e, t);
}
const i = {
const a = {
viewerPath: "/pdfjs",

@@ -57,7 +57,13 @@ viewerEntry: "/web/viewer.html",

};
class m extends HTMLElement {
class w extends HTMLElement {
constructor() {
super(), this.debouncedRenderIframe = b(async () => {
await w("iframe", this.shadowRoot), this.renderViewer(this.getIframeSrc());
}, 0, { leading: !0 });
super(), this.onIframeReady = b(async (o) => {
await m("iframe", this.shadowRoot), o();
}, 0, { leading: !0 }), this.initialize = () => new Promise(async (o) => {
var i;
await m("iframe", this.shadowRoot), (i = this.iframe) == null || i.addEventListener("load", async () => {
var s, r, n;
await ((r = (s = this.iframe.contentWindow) == null ? void 0 : s.PDFViewerApplication) == null ? void 0 : r.initializedPromise), o((n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplication);
}, { once: !0 });
});
const e = this.attachShadow({ mode: "open" }), t = document.createElement("template");

@@ -76,9 +82,9 @@ t.innerHTML = `

attributeChangedCallback() {
this.debouncedRenderIframe();
this.onIframeReady(() => this.mountViewer(this.getIframeSrc()));
}
getIframeSrc() {
const e = this.getFullPath(this.getAttribute("src") || i.src), t = this.getFullPath(this.getAttribute("viewer-path") || i.viewerPath), n = this.getAttribute("page") || i.page, r = this.getAttribute("search") || i.search, h = this.getAttribute("phrase") || i.phrase, s = this.getAttribute("zoom") || i.zoom, o = this.getAttribute("pagemode") || i.pagemode, d = this.getAttribute("locale") || i.locale, a = this.getAttribute("text-layer") || i.textLayer, c = `${t}${i.viewerEntry}?file=${encodeURIComponent(e)}#page=${n}&zoom=${s}&pagemode=${o}&search=${r}&phrase=${h}&textLayer=${a}${d ? "&locale=" + d : ""}`;
return c !== this.iframe.getAttribute("src") ? c : "";
const e = this.getFullPath(this.getAttribute("src") || a.src), t = this.getFullPath(this.getAttribute("viewer-path") || a.viewerPath), o = this.getAttribute("page") || a.page, i = this.getAttribute("search") || a.search, s = this.getAttribute("phrase") || a.phrase, r = this.getAttribute("zoom") || a.zoom, n = this.getAttribute("pagemode") || a.pagemode, l = this.getAttribute("locale") || a.locale, c = this.getAttribute("text-layer") || a.textLayer, d = `${t}${a.viewerEntry}?file=${encodeURIComponent(e)}#page=${o}&zoom=${r}&pagemode=${n}&search=${i}&phrase=${s}&textLayer=${c}${l ? "&locale=" + l : ""}`;
return d !== this.iframe.getAttribute("src") ? d : "";
}
renderViewer(e) {
mountViewer(e) {
!e || !this.iframe || (this.shadowRoot.replaceChild(this.iframe.cloneNode(), this.iframe), this.iframe = this.shadowRoot.querySelector("iframe"), this.iframe.src = e);

@@ -88,4 +94,4 @@ }

document.addEventListener("webviewerloaded", () => {
var e, t, n, r;
this.getAttribute("src") !== i.src && ((e = this.iframe.contentWindow.PDFViewerApplicationOptions) == null || e.set("defaultUrl", "")), (t = this.iframe.contentWindow.PDFViewerApplicationOptions) == null || t.set("disablePreferences", !0), (n = this.iframe.contentWindow.PDFViewerApplicationOptions) == null || n.set("pdfBugEnabled", !0), (r = this.iframe.contentWindow.PDFViewerApplicationOptions) == null || r.set("eventBusDispatchToDOM", !0);
var e, t, o, i, s, r, n, l;
this.getAttribute("src") !== a.src && ((t = (e = this.iframe.contentWindow) == null ? void 0 : e.PDFViewerApplicationOptions) == null || t.set("defaultUrl", "")), (i = (o = this.iframe.contentWindow) == null ? void 0 : o.PDFViewerApplicationOptions) == null || i.set("disablePreferences", !0), (r = (s = this.iframe.contentWindow) == null ? void 0 : s.PDFViewerApplicationOptions) == null || r.set("pdfBugEnabled", !0), (l = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplicationOptions) == null || l.set("eventBusDispatchToDOM", !0);
});

@@ -97,6 +103,6 @@ }

}
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = m, window.customElements.define("pdfjs-viewer-element", m));
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = w, window.customElements.define("pdfjs-viewer-element", w));
export {
m as PdfjsViewerElement,
m as default
w as PdfjsViewerElement,
w as default
};
{
"name": "pdfjs-viewer-element",
"version": "2.3.3",
"version": "2.4.0",
"license": "MIT",

@@ -46,4 +46,4 @@ "author": {

"vitest": "^0.34.3",
"webdriverio": "^8.16.4"
"webdriverio": "^8.16.7"
}
}

@@ -7,2 +7,4 @@ # pdfjs-viewer-element

You have full access to PDF.js viewer application using `initialize` method.
## Status

@@ -71,3 +73,17 @@

## PDF.js Viewer Application
`initialize` - using this method you can access PDFViewerApplication and use methods and events of PDF.js default viewer
```javascript
document.addEventListener('DOMContentLoaded', async () => {
const viewer = document.querySelector('pdfjs-viewer-element')
// Wait for the viewer initialization, receive PDFViewerApplication
const viewerApp = await viewer.initialize()
// Open PDF file data using Uint8Array instead of URL
viewerApp.open(pdfData)
})
```
## License
[MIT](http://opensource.org/licenses/MIT).
[MIT](http://opensource.org/licenses/MIT)

@@ -7,14 +7,24 @@ export declare class PdfjsViewerElement extends HTMLElement {

attributeChangedCallback(): void;
private debouncedRenderIframe;
private onIframeReady;
private getIframeSrc;
private renderViewer;
private mountViewer;
private setEventListeners;
private getFullPath;
initialize: () => Promise<unknown>;
}
declare global {
interface Window {
'PdfjsViewerElement': typeof PdfjsViewerElement;
PdfjsViewerElement: typeof PdfjsViewerElement;
}
}
export interface IPdfjsViewerElement extends HTMLElement {
initialize: () => Promise<PdfjsViewerElementIframeWindow['PDFViewerApplication']>;
}
export interface PdfjsViewerElementIframeWindow extends Window {
PDFViewerApplication: {
initializedPromise: Promise<void>;
initialized: boolean;
open: (data: Uint8Array) => void;
eventBus: Record<string, any>;
};
PDFViewerApplicationOptions: {

@@ -27,2 +37,7 @@ set: (name: string, value: string | boolean) => void;

}
export interface PdfjsViewerLoadedEvent extends Event {
detail: {
source: PdfjsViewerElementIframeWindow;
};
}
export default PdfjsViewerElement;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc