pdfjs-viewer-element
Advanced tools
Comparing version 2.5.6 to 2.6.0
@@ -1,2 +0,2 @@ | ||
const f = (m, e) => new Promise((r) => { | ||
const w = (m, e) => new Promise((r) => { | ||
let i = e.querySelector(m); | ||
@@ -15,25 +15,25 @@ if (i) { | ||
}); | ||
}), y = { | ||
}), g = { | ||
trailing: !0 | ||
}; | ||
function b(m, e = 25, r = {}) { | ||
if (r = { ...y, ...r }, !Number.isFinite(e)) | ||
if (r = { ...g, ...r }, !Number.isFinite(e)) | ||
throw new TypeError("Expected `wait` to be a finite number"); | ||
let i, s, n = [], t, o; | ||
const a = (c, h) => (t = v(m, c, h), t.finally(() => { | ||
const a = (l, h) => (t = v(m, l, h), t.finally(() => { | ||
if (t = null, r.trailing && o && !s) { | ||
const u = a(c, o); | ||
const u = a(l, o); | ||
return o = null, u; | ||
} | ||
}), t); | ||
return function(...c) { | ||
return t ? (r.trailing && (o = c), t) : new Promise((h) => { | ||
return function(...l) { | ||
return t ? (r.trailing && (o = l), t) : new Promise((h) => { | ||
const u = !s && r.leading; | ||
clearTimeout(s), s = setTimeout(() => { | ||
s = null; | ||
const d = r.leading ? i : a(this, c); | ||
for (const g of n) | ||
g(d); | ||
const p = r.leading ? i : a(this, l); | ||
for (const y of n) | ||
y(p); | ||
n = []; | ||
}, e), u ? (i = a(this, c), h(i)) : n.push(h); | ||
}, e), u ? (i = a(this, l), h(i)) : n.push(h); | ||
}); | ||
@@ -45,3 +45,3 @@ }; | ||
} | ||
const l = { | ||
const c = { | ||
viewerPath: "/pdfjs", | ||
@@ -53,3 +53,3 @@ viewerEntry: "/web/viewer.html", | ||
phrase: "", | ||
zoom: "auto", | ||
zoom: "", | ||
pagemode: "none", | ||
@@ -60,3 +60,3 @@ locale: "", | ||
viewerExtraStyles: "" | ||
}, w = { | ||
}, d = { | ||
AUTOMATIC: 0, | ||
@@ -66,9 +66,9 @@ // Default value. | ||
DARK: 2 | ||
}; | ||
class p extends HTMLElement { | ||
}, A = ["src", "viewer-path", "locale", "viewer-css-theme", "viewer-extra-styles"]; | ||
class f extends HTMLElement { | ||
constructor() { | ||
super(), this.onIframeReady = b(async (i) => { | ||
await f("iframe", this.shadowRoot), i(); | ||
await w("iframe", this.shadowRoot), i(); | ||
}, 0, { leading: !0 }), this.setViewerExtraStyles = (i, s = "extra") => { | ||
var t, o, a, c, h; | ||
var t, o, a, l, h; | ||
if (!i) { | ||
@@ -78,3 +78,3 @@ (o = (t = this.iframe.contentDocument) == null ? void 0 : t.head.querySelector(`style[${s}]`)) == null || o.remove(); | ||
} | ||
if (((c = (a = this.iframe.contentDocument) == null ? void 0 : a.head.querySelector(`style[${s}]`)) == null ? void 0 : c.innerHTML) === i) | ||
if (((l = (a = this.iframe.contentDocument) == null ? void 0 : a.head.querySelector(`style[${s}]`)) == null ? void 0 : l.innerHTML) === i) | ||
return; | ||
@@ -85,3 +85,3 @@ const n = document.createElement("style"); | ||
var s; | ||
await f("iframe", this.shadowRoot), (s = this.iframe) == null || s.addEventListener("load", async () => { | ||
await w("iframe", this.shadowRoot), (s = this.iframe) == null || s.addEventListener("load", async () => { | ||
var n, t, o; | ||
@@ -101,13 +101,19 @@ await ((t = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplication) == null ? void 0 : t.initializedPromise), i((o = this.iframe.contentWindow) == null ? void 0 : o.PDFViewerApplication); | ||
connectedCallback() { | ||
this.iframe = this.shadowRoot.querySelector("iframe"), document.addEventListener("webviewerloaded", () => { | ||
this.iframe = this.shadowRoot.querySelector("iframe"), document.addEventListener("webviewerloaded", async () => { | ||
var e, r, i, s, n, t, o, a; | ||
this.setCssTheme(), this.setViewerExtraStyles(this.getAttribute("viewer-extra-styles")), this.getAttribute("src") !== l.src && ((r = (e = this.iframe.contentWindow) == null ? void 0 : e.PDFViewerApplicationOptions) == null || r.set("defaultUrl", "")), (s = (i = this.iframe.contentWindow) == null ? void 0 : i.PDFViewerApplicationOptions) == null || s.set("disablePreferences", !0), (t = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplicationOptions) == null || t.set("pdfBugEnabled", !0), (a = (o = this.iframe.contentWindow) == null ? void 0 : o.PDFViewerApplicationOptions) == null || a.set("eventBusDispatchToDOM", !0); | ||
this.setCssTheme(this.getCssThemeOption()), this.setViewerExtraStyles(this.getAttribute("viewer-extra-styles")), this.getAttribute("src") !== c.src && ((r = (e = this.iframe.contentWindow) == null ? void 0 : e.PDFViewerApplicationOptions) == null || r.set("defaultUrl", "")), (s = (i = this.iframe.contentWindow) == null ? void 0 : i.PDFViewerApplicationOptions) == null || s.set("disablePreferences", !0), (t = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplicationOptions) == null || t.set("pdfBugEnabled", !0), (a = (o = this.iframe.contentWindow) == null ? void 0 : o.PDFViewerApplicationOptions) == null || a.set("eventBusDispatchToDOM", !0); | ||
}); | ||
} | ||
attributeChangedCallback() { | ||
attributeChangedCallback(e) { | ||
if (!A.includes(e)) { | ||
this.onIframeReady(() => { | ||
this.iframe.src = this.getIframeSrc(); | ||
}); | ||
return; | ||
} | ||
this.onIframeReady(() => this.mountViewer(this.getIframeSrc())); | ||
} | ||
getIframeSrc() { | ||
const e = this.getFullPath(this.getAttribute("src") || l.src), r = this.getFullPath(this.getAttribute("viewer-path") || l.viewerPath), i = this.getAttribute("page") || l.page, s = this.getAttribute("search") || l.search, n = this.getAttribute("phrase") || l.phrase, t = this.getAttribute("zoom") || l.zoom, o = this.getAttribute("pagemode") || l.pagemode, a = this.getAttribute("locale") || l.locale, c = this.getAttribute("text-layer") || l.textLayer, h = this.getAttribute("viewer-css-theme") || l.viewerCssTheme, u = !!(this.getAttribute("viewer-extra-styles") || l.viewerExtraStyles), d = `${r}${l.viewerEntry}?file=${encodeURIComponent(e)}#page=${i}&zoom=${t}&pagemode=${o}&search=${s}&phrase=${n}&textLayer=${c}${a ? "&locale=" + a : ""}&viewerCssTheme=${h}&viewerExtraStyles=${u}`; | ||
return d !== this.iframe.getAttribute("src") ? d : ""; | ||
const e = this.getFullPath(this.getAttribute("src") || c.src), r = this.getFullPath(this.getAttribute("viewer-path") || c.viewerPath), i = this.getAttribute("page") || c.page, s = this.getAttribute("search") || c.search, n = this.getAttribute("phrase") || c.phrase, t = this.getAttribute("zoom") || c.zoom, o = this.getAttribute("pagemode") || c.pagemode, a = this.getAttribute("locale") || c.locale, l = this.getAttribute("text-layer") || c.textLayer, h = this.getAttribute("viewer-css-theme") || c.viewerCssTheme, u = !!(this.getAttribute("viewer-extra-styles") || c.viewerExtraStyles); | ||
return `${r}${c.viewerEntry}?file=${encodeURIComponent(e)}#page=${i}&zoom=${t}&pagemode=${o}&search=${s}&phrase=${n}&textLayer=${l}${a ? "&locale=" + a : ""}&viewerCssTheme=${h}&viewerExtraStyles=${u}`; | ||
} | ||
@@ -122,10 +128,10 @@ mountViewer(e) { | ||
const e = this.getAttribute("viewer-css-theme"); | ||
return Object.keys(w).includes(e) ? w[e] : w[l.viewerCssTheme]; | ||
return Object.keys(d).includes(e) ? d[e] : d[c.viewerCssTheme]; | ||
} | ||
setCssTheme() { | ||
setCssTheme(e) { | ||
var r, i, s; | ||
if (this.getCssThemeOption() === w.DARK) { | ||
if (e === d.DARK) { | ||
const n = (r = this.iframe.contentDocument) == null ? void 0 : r.styleSheets[0], t = (n == null ? void 0 : n.cssRules) || [], o = Object.keys(t).filter((a) => { | ||
var c; | ||
return ((c = t[Number(a)]) == null ? void 0 : c.conditionText) === "(prefers-color-scheme: dark)"; | ||
var l; | ||
return ((l = t[Number(a)]) == null ? void 0 : l.conditionText) === "(prefers-color-scheme: dark)"; | ||
}).map((a) => t[Number(a)].cssText.split(`@media (prefers-color-scheme: dark) { | ||
@@ -139,7 +145,8 @@ `)[1].split(` | ||
} | ||
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = p, window.customElements.define("pdfjs-viewer-element", p)); | ||
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = f, window.customElements.define("pdfjs-viewer-element", f)); | ||
export { | ||
p as PdfjsViewerElement, | ||
w as ViewerCssTheme, | ||
p as default | ||
f as PdfjsViewerElement, | ||
d as ViewerCssTheme, | ||
f as default, | ||
A as hardRefreshAttributes | ||
}; |
{ | ||
"name": "pdfjs-viewer-element", | ||
"version": "2.5.6", | ||
"version": "2.6.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -6,5 +6,8 @@ <p align="center"> | ||
Probably the simplest integration of PDF.js viewer. | ||
The package provide a custom element, based on [PDF.js default viewer](https://mozilla.github.io/pdf.js/web/viewer.html), supported in all [major browsers](https://caniuse.com/custom-elementsv1), and works with most [JS frameworks](https://custom-elements-everywhere.com/). | ||
The simplest integration of [PDF.js default viewer](https://mozilla.github.io/pdf.js/web/viewer.html) using the `iframe` element and web component. | ||
The package provides a custom element, based on PDF.js [viewer options](https://github.com/mozilla/pdf.js/wiki/Viewer-options) and [URL parameters](https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js#url-parameters) API. | ||
Supported in all [major browsers](https://caniuse.com/custom-elementsv1), and works with most [JS frameworks](https://custom-elements-everywhere.com/). | ||
See [examples](https://alekswebnet.github.io/pdfjs-viewer-element/#demo) of usage in Vue, React, Svelte, or simple HTML pages. | ||
⚠️ `pdfjs-viewer-element` requires PDF.js [prebuilt](http://mozilla.github.io/pdf.js/getting_started/), that includes the generic build of PDF.js and the viewer. | ||
@@ -21,8 +24,6 @@ | ||
To use the package you should download and **place the prebuilt** files to some directory of your project. | ||
To use the package you should download and **place the prebuilt** files in the project. | ||
Then specify the path to the directory with `viewer-path` property (`/pdfjs` by default). | ||
Then specify the path to the directory with the `viewer-path` property (`/pdfjs` by default). | ||
See [examples](https://alekswebnet.github.io/pdfjs-viewer-element/#demo) of usage in Vue, React, Svelte or simple HTML page. | ||
## Status | ||
@@ -91,5 +92,5 @@ | ||
`viewer-css-theme` - Apply automatic, light or dark theme `AUTOMATIC | LIGHT | DARK` | ||
`viewer-css-theme` - Apply automatic, light, or dark theme `AUTOMATIC | LIGHT | DARK` | ||
`viewer-extra-styles` - Add your CSS rules to viewer application | ||
`viewer-extra-styles` - Add your CSS rules to the viewer application | ||
@@ -144,2 +145,2 @@ Play with attributes on [Api docs page](https://alekswebnet.github.io/pdfjs-viewer-element/#api). | ||
## License | ||
[MIT](http://opensource.org/licenses/MIT) | ||
[MIT](http://opensource.org/licenses/MIT) |
@@ -6,2 +6,3 @@ export declare const ViewerCssTheme: { | ||
}; | ||
export declare const hardRefreshAttributes: string[]; | ||
export declare class PdfjsViewerElement extends HTMLElement { | ||
@@ -12,3 +13,3 @@ constructor(); | ||
connectedCallback(): void; | ||
attributeChangedCallback(): void; | ||
attributeChangedCallback(name: string): void; | ||
private onIframeReady; | ||
@@ -19,3 +20,3 @@ private getIframeSrc; | ||
private getCssThemeOption; | ||
setCssTheme(): void; | ||
private setCssTheme; | ||
private setViewerExtraStyles; | ||
@@ -22,0 +23,0 @@ initialize: () => Promise<PdfjsViewerElementIframeWindow['PDFViewerApplication']>; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
63182767
1119
286388
143
3
80
25