pdfjs-viewer-element 2.5.1 → 2.5.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,47 +1,47 @@
|
|
|
1
|
-
const
|
|
2
|
-
let i = e.querySelector(
|
|
1
|
+
const p = (m, e) => new Promise((t) => {
|
|
2
|
+
let i = e.querySelector(m);
|
|
3
3
|
if (i) {
|
|
4
4
|
t(i);
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
new MutationObserver((s,
|
|
8
|
-
Array.from(e.querySelectorAll(
|
|
9
|
-
t(
|
|
7
|
+
new MutationObserver((s, n) => {
|
|
8
|
+
Array.from(e.querySelectorAll(m)).forEach((r) => {
|
|
9
|
+
t(r), n.disconnect();
|
|
10
10
|
});
|
|
11
11
|
}).observe(e, {
|
|
12
12
|
childList: !0,
|
|
13
13
|
subtree: !0
|
|
14
14
|
});
|
|
15
|
-
}),
|
|
15
|
+
}), y = {
|
|
16
16
|
trailing: !0
|
|
17
17
|
};
|
|
18
|
-
function
|
|
19
|
-
if (t = { ...
|
|
18
|
+
function v(m, e = 25, t = {}) {
|
|
19
|
+
if (t = { ...y, ...t }, !Number.isFinite(e))
|
|
20
20
|
throw new TypeError("Expected `wait` to be a finite number");
|
|
21
|
-
let
|
|
22
|
-
const
|
|
23
|
-
if (r = null, t.trailing &&
|
|
24
|
-
const u =
|
|
25
|
-
return
|
|
21
|
+
let i, s, n = [], r, a;
|
|
22
|
+
const c = (o, h) => (r = b(m, o, h), r.finally(() => {
|
|
23
|
+
if (r = null, t.trailing && a && !s) {
|
|
24
|
+
const u = c(o, a);
|
|
25
|
+
return a = null, u;
|
|
26
26
|
}
|
|
27
27
|
}), r);
|
|
28
|
-
return function(...
|
|
29
|
-
return r ? (t.trailing && (
|
|
30
|
-
const u = !
|
|
31
|
-
clearTimeout(
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, e), u ? (
|
|
28
|
+
return function(...o) {
|
|
29
|
+
return r ? (t.trailing && (a = o), r) : new Promise((h) => {
|
|
30
|
+
const u = !s && t.leading;
|
|
31
|
+
clearTimeout(s), s = setTimeout(() => {
|
|
32
|
+
s = null;
|
|
33
|
+
const d = t.leading ? i : c(this, o);
|
|
34
|
+
for (const g of n)
|
|
35
|
+
g(d);
|
|
36
|
+
n = [];
|
|
37
|
+
}, e), u ? (i = c(this, o), h(i)) : n.push(h);
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
async function
|
|
42
|
-
return await
|
|
41
|
+
async function b(m, e, t) {
|
|
42
|
+
return await m.apply(e, t);
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const l = {
|
|
45
45
|
viewerPath: "/pdfjs",
|
|
46
46
|
viewerEntry: "/web/viewer.html",
|
|
47
47
|
src: "",
|
|
@@ -51,53 +51,72 @@ const a = {
|
|
|
51
51
|
zoom: "auto",
|
|
52
52
|
pagemode: "none",
|
|
53
53
|
locale: "",
|
|
54
|
-
textLayer: ""
|
|
54
|
+
textLayer: "",
|
|
55
|
+
viewerCssTheme: "AUTOMATIC",
|
|
56
|
+
viewerExtraStyles: ""
|
|
57
|
+
}, w = {
|
|
58
|
+
AUTOMATIC: 0,
|
|
59
|
+
// Default value.
|
|
60
|
+
LIGHT: 1,
|
|
61
|
+
DARK: 2
|
|
55
62
|
};
|
|
56
|
-
class
|
|
63
|
+
class f extends HTMLElement {
|
|
57
64
|
constructor() {
|
|
58
|
-
super(), this.onIframeReady =
|
|
59
|
-
await
|
|
60
|
-
}, 0, { leading: !0 }), this.
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
super(), this.onIframeReady = v(async (i) => {
|
|
66
|
+
await p("iframe", this.shadowRoot), i();
|
|
67
|
+
}, 0, { leading: !0 }), this.setViewerExtraStyles = (i) => {
|
|
68
|
+
var n, r, a, c, o;
|
|
69
|
+
if (!i) {
|
|
70
|
+
(r = (n = this.iframe.contentDocument) == null ? void 0 : n.head.querySelector("style[extra]")) == null || r.remove();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (((c = (a = this.iframe.contentDocument) == null ? void 0 : a.head.querySelector("style[extra]")) == null ? void 0 : c.innerHTML) === i)
|
|
74
|
+
return;
|
|
75
|
+
const s = document.createElement("style");
|
|
76
|
+
s.innerHTML = i, s.setAttribute("extra", ""), (o = this.iframe.contentDocument) == null || o.head.appendChild(s);
|
|
77
|
+
}, this.initialize = () => new Promise(async (i) => {
|
|
78
|
+
var s;
|
|
79
|
+
await p("iframe", this.shadowRoot), (s = this.iframe) == null || s.addEventListener("load", async () => {
|
|
80
|
+
var n, r, a;
|
|
81
|
+
await ((r = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplication) == null ? void 0 : r.initializedPromise), i((a = this.iframe.contentWindow) == null ? void 0 : a.PDFViewerApplication);
|
|
65
82
|
}, { once: !0 });
|
|
66
83
|
});
|
|
67
84
|
const e = this.attachShadow({ mode: "open" }), t = document.createElement("template");
|
|
68
85
|
t.innerHTML = `
|
|
69
|
-
<iframe frameborder="0" width="100%"></iframe>
|
|
70
86
|
<style>:host{width:100%;display:block;overflow:hidden}:host iframe{height:100%}</style>
|
|
87
|
+
<iframe frameborder="0" width="100%" loading="lazy"></iframe>
|
|
71
88
|
`, e.appendChild(t.content.cloneNode(!0));
|
|
72
89
|
}
|
|
73
90
|
static get observedAttributes() {
|
|
74
|
-
return ["src", "viewer-path", "locale", "page", "search", "phrase", "zoom", "pagemode", "text-layer"];
|
|
91
|
+
return ["src", "viewer-path", "locale", "page", "search", "phrase", "zoom", "pagemode", "text-layer", "viewer-css-theme", "viewer-extra-styles"];
|
|
75
92
|
}
|
|
76
93
|
connectedCallback() {
|
|
77
|
-
this.iframe = this.shadowRoot.querySelector("iframe"),
|
|
94
|
+
this.iframe = this.shadowRoot.querySelector("iframe"), document.addEventListener("webviewerloaded", () => {
|
|
95
|
+
var e, t, i, s, n, r, a, c, o, h;
|
|
96
|
+
this.dispatchEvent(new Event("loaded")), this.setViewerExtraStyles(this.getAttribute("viewer-extra-styles")), this.getAttribute("src") !== l.src && ((t = (e = this.iframe.contentWindow) == null ? void 0 : e.PDFViewerApplicationOptions) == null || t.set("defaultUrl", "")), (s = (i = this.iframe.contentWindow) == null ? void 0 : i.PDFViewerApplicationOptions) == null || s.set("viewerCssTheme", this.getCssThemeOption()), (r = (n = this.iframe.contentWindow) == null ? void 0 : n.PDFViewerApplicationOptions) == null || r.set("disablePreferences", !0), (c = (a = this.iframe.contentWindow) == null ? void 0 : a.PDFViewerApplicationOptions) == null || c.set("pdfBugEnabled", !0), (h = (o = this.iframe.contentWindow) == null ? void 0 : o.PDFViewerApplicationOptions) == null || h.set("eventBusDispatchToDOM", !0);
|
|
97
|
+
});
|
|
78
98
|
}
|
|
79
99
|
attributeChangedCallback() {
|
|
80
100
|
this.onIframeReady(() => this.mountViewer(this.getIframeSrc()));
|
|
81
101
|
}
|
|
82
102
|
getIframeSrc() {
|
|
83
|
-
const e = this.getFullPath(this.getAttribute("src") ||
|
|
103
|
+
const e = this.getFullPath(this.getAttribute("src") || l.src), t = 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, r = this.getAttribute("zoom") || l.zoom, a = this.getAttribute("pagemode") || l.pagemode, c = this.getAttribute("locale") || l.locale, o = this.getAttribute("text-layer") || l.textLayer, h = this.getAttribute("viewer-css-theme") || l.viewerCssTheme, u = !!(this.getAttribute("viewer-extra-styles") || l.viewerExtraStyles), d = `${t}${l.viewerEntry}?file=${encodeURIComponent(e)}#page=${i}&zoom=${r}&pagemode=${a}&search=${s}&phrase=${n}&textLayer=${o}${c ? "&locale=" + c : ""}&viewerCssTheme=${h}&viewerExtraStyles=${u}`;
|
|
84
104
|
return d !== this.iframe.getAttribute("src") ? d : "";
|
|
85
105
|
}
|
|
86
106
|
mountViewer(e) {
|
|
87
107
|
!e || !this.iframe || (this.shadowRoot.replaceChild(this.iframe.cloneNode(), this.iframe), this.iframe = this.shadowRoot.querySelector("iframe"), this.iframe.src = e);
|
|
88
108
|
}
|
|
89
|
-
setEventListeners() {
|
|
90
|
-
document.addEventListener("webviewerloaded", () => {
|
|
91
|
-
var e, t, o, i, s, r, n, l;
|
|
92
|
-
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);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
109
|
getFullPath(e) {
|
|
96
110
|
return e.startsWith("/") ? `${window.location.origin}${e}` : e;
|
|
97
111
|
}
|
|
112
|
+
getCssThemeOption() {
|
|
113
|
+
const e = this.getAttribute("viewer-css-theme");
|
|
114
|
+
return Object.keys(w).includes(e) ? w[e] : w[l.viewerCssTheme];
|
|
115
|
+
}
|
|
98
116
|
}
|
|
99
|
-
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement =
|
|
117
|
+
window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = f, window.customElements.define("pdfjs-viewer-element", f));
|
|
100
118
|
export {
|
|
101
|
-
|
|
102
|
-
w as
|
|
119
|
+
f as PdfjsViewerElement,
|
|
120
|
+
w as ViewerCssTheme,
|
|
121
|
+
f as default
|
|
103
122
|
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
export declare const ViewerCssTheme: {
|
|
2
|
+
readonly AUTOMATIC: 0;
|
|
3
|
+
readonly LIGHT: 1;
|
|
4
|
+
readonly DARK: 2;
|
|
5
|
+
};
|
|
1
6
|
export declare class PdfjsViewerElement extends HTMLElement {
|
|
2
7
|
constructor();
|
|
3
|
-
|
|
8
|
+
iframe: PdfjsViewerElementIframe;
|
|
4
9
|
static get observedAttributes(): string[];
|
|
5
10
|
connectedCallback(): void;
|
|
6
11
|
attributeChangedCallback(): void;
|
|
7
12
|
private onIframeReady;
|
|
8
13
|
private getIframeSrc;
|
|
9
14
|
private mountViewer;
|
|
10
|
-
private setEventListeners;
|
|
11
15
|
private getFullPath;
|
|
12
|
-
|
|
16
|
+
private getCssThemeOption;
|
|
17
|
+
private setViewerExtraStyles;
|
|
18
|
+
initialize: () => Promise<PdfjsViewerElementIframeWindow['PDFViewerApplication']>;
|
|
13
19
|
}
|
|
14
20
|
declare global {
|
|
15
21
|
interface Window {
|
|
@@ -27,7 +33,8 @@ export interface PdfjsViewerElementIframeWindow extends Window {
|
|
|
27
33
|
eventBus: Record<string, any>;
|
|
28
34
|
};
|
|
29
35
|
PDFViewerApplicationOptions: {
|
|
30
|
-
set: (name: string, value: string | boolean) => void;
|
|
36
|
+
set: (name: string, value: string | boolean | number) => void;
|
|
37
|
+
getAll: () => Record<string, any>;
|
|
31
38
|
};
|
|
32
39
|
}
|
|
33
40
|
export interface PdfjsViewerElementIframe extends HTMLIFrameElement {
|