pdfjs-viewer-element 2.6.3 → 2.6.5

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.
package/README.md CHANGED
@@ -10,20 +10,17 @@ Supported in all [major browsers](https://caniuse.com/custom-elementsv1), and wo
10
10
  See [demo pages](https://github.com/alekswebnet/pdfjs-viewer-element/tree/master/demo) for various usecases.
11
11
  See [live examples](https://alekswebnet.github.io/pdfjs-viewer-element/#demo) of usage with frameworks.
12
12
 
13
- ⚠️ `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.
13
+ ## How it works
14
14
 
15
- The prebuilt comes with each PDF.js release. Supported releases:
15
+ **⚠️ This is an important part !!!**
16
16
 
17
- [v4.0.379](https://github.com/mozilla/pdf.js/releases/tag/v4.0.379)
17
+ **You should download and place the PDF.js prebuilt files in the project.**
18
18
 
19
- [v4.0.269](https://github.com/mozilla/pdf.js/releases/tag/v4.0.269)
19
+ `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.
20
20
 
21
- [v4.0.189](https://github.com/mozilla/pdf.js/releases/tag/v4.0.189)
21
+ The prebuilt comes with each PDF.js release. Supported all v4 and v3 [releases](https://github.com/mozilla/pdf.js/releases).
22
22
 
23
-
24
- To use the package you should download and **place the prebuilt** files in the project.
25
-
26
- Then specify the path to the directory with the `viewer-path` property (`/pdfjs` by default).
23
+ Then specify the path to the directory with the `viewer-path` property (`/pdfjs` by default) and PDF file URL with `src` property (should refer to the [same origin](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#can-i-load-a-pdf-from-another-server-cross-domain-request)).
27
24
 
28
25
  ## Status
29
26
 
@@ -67,7 +64,7 @@ Using browser:
67
64
  ## Usage
68
65
 
69
66
  ```html
70
- <pdfjs-viewer-element src="/file.pdf" viewer-path="/pdfjs-4.0.379-dist"></pdfjs-viewer-element>
67
+ <pdfjs-viewer-element src="/file.pdf" viewer-path="/pdfjs-4.5.136-dist"></pdfjs-viewer-element>
71
68
  ```
72
69
 
73
70
  ## Attributes
@@ -107,7 +104,7 @@ Use `viewer-css-theme` attribute to set light or dark theme manually:
107
104
  ```html
108
105
  <pdfjs-viewer-element
109
106
  src="/file.pdf"
110
- viewer-path="/pdfjs-4.0.379-dist"
107
+ viewer-path="/pdfjs-4.5.136-dist"
111
108
  viewer-css-theme="DARK">
112
109
  </pdfjs-viewer-element>
113
110
  ```
@@ -119,7 +116,7 @@ You can add your own CSS rules to the viewer application using `viewer-extra-sty
119
116
  ```html
120
117
  <pdfjs-viewer-element
121
118
  src="/file.pdf"
122
- viewer-path="/pdfjs-4.0.379-dist"
119
+ viewer-path="/pdfjs-4.5.136-dist"
123
120
  viewer-extra-styles="#toolbarViewerMiddle { display: none; }"
124
121
  viewer-extra-styles-urls="['/demo/viewer-custom-theme.css']">
125
122
  </pdfjs-viewer-element>
@@ -152,7 +149,7 @@ Build your own theme with viewer's custom variables and `viewer-extra-styles-url
152
149
  `initialize` - using this method you can access PDFViewerApplication and use methods and events of PDF.js default viewer
153
150
 
154
151
  ```html
155
- <pdfjs-viewer-element viewer-path="/pdfjs-4.0.379-dist"></pdfjs-viewer-element>
152
+ <pdfjs-viewer-element viewer-path="/pdfjs-4.5.136-dist"></pdfjs-viewer-element>
156
153
  ```
157
154
 
158
155
  ```javascript
@@ -163,5 +160,31 @@ const viewerApp = await viewer.initialize()
163
160
  viewerApp.open({ data: pdfData })
164
161
  ```
165
162
 
163
+ ## Server configuration
164
+
165
+ Since v4 PDF.js requires `.mjs` files support, make sure your server has it.
166
+
167
+ In case of `nginx` this may causes to errors, see https://github.com/mozilla/pdf.js/issues/17296
168
+
169
+ Add `.mjs` files support for `nginx` example:
170
+
171
+ ```bash
172
+ server {
173
+ # ...
174
+
175
+ location / {
176
+ root /usr/share/nginx/html;
177
+ index index.html;
178
+
179
+ location ~* \.mjs$ {
180
+ types {
181
+ text/javascript mjs;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+
166
189
  ## License
167
190
  [MIT](http://opensource.org/licenses/MIT)
@@ -30,9 +30,9 @@ function v(m, e = 25, s = {}) {
30
30
  const u = !n && s.leading;
31
31
  clearTimeout(n), n = setTimeout(() => {
32
32
  n = null;
33
- const w = s.leading ? r : o(this, l);
33
+ const d = s.leading ? r : o(this, l);
34
34
  for (const y of t)
35
- y(w);
35
+ y(d);
36
36
  t = [];
37
37
  }, e), u ? (r = o(this, l), h(r)) : t.push(h);
38
38
  });
@@ -56,7 +56,7 @@ const c = {
56
56
  viewerExtraStyles: "",
57
57
  viewerExtraStylesUrls: "",
58
58
  nameddest: ""
59
- }, d = {
59
+ }, w = {
60
60
  AUTOMATIC: 0,
61
61
  // Default value.
62
62
  LIGHT: 1,
@@ -118,8 +118,8 @@ class p extends HTMLElement {
118
118
  this.onIframeReady(() => this.mountViewer(this.getIframeSrc()));
119
119
  }
120
120
  getIframeSrc() {
121
- const e = this.getFullPath(this.getAttribute("src") || c.src), s = this.getFullPath(this.getAttribute("viewer-path") || c.viewerPath), r = this.getAttribute("page") || c.page, n = this.getAttribute("search") || c.search, t = this.getAttribute("phrase") || c.phrase, i = this.getAttribute("zoom") || c.zoom, a = this.getAttribute("pagemode") || c.pagemode, o = 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), w = this.getAttribute("nameddest") || c.nameddest;
122
- return `${s}${c.viewerEntry}?file=${encodeURIComponent(e)}#page=${r}&zoom=${i}&pagemode=${a}&search=${n}&phrase=${t}&textLayer=${l}${o ? "&locale=" + o : ""}&viewerCssTheme=${h}&viewerExtraStyles=${u}&nameddest=${w}`;
121
+ const e = this.getFullPath(this.getAttribute("src") || c.src), s = this.getFullPath(this.getAttribute("viewer-path") || c.viewerPath), r = this.getAttribute("page") || c.page, n = this.getAttribute("search") || c.search, t = this.getAttribute("phrase") || c.phrase, i = this.getAttribute("zoom") || c.zoom, a = this.getAttribute("pagemode") || c.pagemode, o = 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), d = this.getAttribute("nameddest") || c.nameddest;
122
+ return `${s}${c.viewerEntry}?file=${encodeURIComponent(e)}#page=${r}&zoom=${i}&pagemode=${a}&search=${n}&phrase=${t}&textLayer=${l}${o ? "&locale=" + o : ""}&viewerCssTheme=${h}&viewerExtraStyles=${u}${d ? "&nameddest=" + d : ""}`;
123
123
  }
124
124
  mountViewer(e) {
125
125
  !e || !this.iframe || (this.shadowRoot.replaceChild(this.iframe.cloneNode(), this.iframe), this.iframe = this.shadowRoot.querySelector("iframe"), this.iframe.src = e);
@@ -129,11 +129,11 @@ class p extends HTMLElement {
129
129
  }
130
130
  getCssThemeOption() {
131
131
  const e = this.getAttribute("viewer-css-theme");
132
- return Object.keys(d).includes(e) ? d[e] : d[c.viewerCssTheme];
132
+ return Object.keys(w).includes(e) ? w[e] : w[c.viewerCssTheme];
133
133
  }
134
134
  setCssTheme(e) {
135
135
  var s, r, n;
136
- if (e === d.DARK) {
136
+ if (e === w.DARK) {
137
137
  const t = (s = this.iframe.contentDocument) == null ? void 0 : s.styleSheets[0], i = (t == null ? void 0 : t.cssRules) || [], a = Object.keys(i).filter((o) => {
138
138
  var l;
139
139
  return ((l = i[Number(o)]) == null ? void 0 : l.conditionText) === "(prefers-color-scheme: dark)";
@@ -148,7 +148,7 @@ class p extends HTMLElement {
148
148
  window.customElements.get("pdfjs-viewer-element") || (window.PdfjsViewerElement = p, window.customElements.define("pdfjs-viewer-element", p));
149
149
  export {
150
150
  p as PdfjsViewerElement,
151
- d as ViewerCssTheme,
151
+ w as ViewerCssTheme,
152
152
  p as default,
153
153
  A as hardRefreshAttributes
154
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfjs-viewer-element",
3
- "version": "2.6.3",
3
+ "version": "2.6.5",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Oleksandr Shevchuk",
@@ -30,14 +30,15 @@
30
30
  "types"
31
31
  ],
32
32
  "devDependencies": {
33
- "@types/node": "^18.7.1",
34
- "@vitest/browser": "^1.2.1",
33
+ "@awlsn/pdfjs-full": "^4.2.392",
34
+ "@types/node": "^18.19.31",
35
+ "@vitest/browser": "^1.5.0",
35
36
  "jsdom": "^22.1.0",
36
37
  "perfect-debounce": "^1.0.0",
37
- "typescript": "^4.6.4",
38
- "vite": "^5.0.12",
39
- "vitest": "^1.2.1",
40
- "webdriverio": "^8.28.8"
38
+ "typescript": "^4.9.5",
39
+ "vite": "^5.2.9",
40
+ "vitest": "^1.5.0",
41
+ "webdriverio": "^8.36.1"
41
42
  },
42
43
  "scripts": {
43
44
  "dev": "vite",