@vaadin-component-factory/vcf-pdf-viewer 4.0.1 → 4.1.0
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 +8 -0
- package/package.json +8 -2
- package/pdfjs/dist/event_utils.js +207 -0
- package/pdfjs/dist/genericl10n.js +2420 -0
- package/pdfjs/dist/message_handler.js +670 -462
- package/pdfjs/dist/node_stream.js +2 -396
- package/pdfjs/dist/node_stream2.js +1759 -0
- package/pdfjs/dist/pdf.js +20127 -10174
- package/pdfjs/dist/pdf.worker.js +24 -0
- package/pdfjs/dist/pdf_link_service.js +419 -480
- package/pdfjs/dist/pdf_rendering_queue.js +154 -134
- package/pdfjs/dist/pdf_thumbnail_viewer.js +575 -640
- package/pdfjs/dist/pdf_viewer.js +4506 -2821
- package/pdfjs/dist/ui_utils.js +663 -815
- package/pdfjs/dist/util.js +831 -918
- package/pdfjs/dist/worker.js +60324 -51758
- package/src/vcf-pdf-viewer.js +153 -16
- package/pdfjs/dist/display_utils.js +0 -743
- package/pdfjs/dist/fetch_stream.js +0 -252
- package/pdfjs/dist/l10n_utils.js +0 -131
- package/pdfjs/dist/network.js +0 -454
- package/pdfjs/dist/network_utils.js +0 -293
package/README.md
CHANGED
|
@@ -19,6 +19,14 @@ This component is part of Vaadin Component Factory.
|
|
|
19
19
|
|
|
20
20
|
1. Run `npm start` to open the demo.
|
|
21
21
|
|
|
22
|
+
## Development & publishing
|
|
23
|
+
|
|
24
|
+
DO NOT run `npm run build` before publishing a new release.
|
|
25
|
+
|
|
26
|
+
The `pdfjs/dist` files committed in this repository are manually edited to ensure correct module resolution. Running the build script will overwrite these files, generating incompatible file paths that will cause the component to fail when trying to resolve dependencies.
|
|
27
|
+
|
|
28
|
+
Only run `npm run build` if you are intentionally modifying the `pdfjs` dependency and are prepared to manually fix the resulting path references.
|
|
29
|
+
|
|
22
30
|
## Contributing
|
|
23
31
|
|
|
24
32
|
To contribute to the component, please read [the guideline](https://github.com/vaadin/vaadin-core/blob/master/CONTRIBUTING.md) first.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin-component-factory/vcf-pdf-viewer",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Lit element providing pdf viewer",
|
|
5
5
|
"author": "Vaadin Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
"pdfjs/dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@fluent/bundle": "^0.18.0",
|
|
28
|
+
"@fluent/dom": "^0.9.0",
|
|
27
29
|
"@vaadin/button": "^25.0.0",
|
|
28
30
|
"@vaadin/component-base": "^25.0.0",
|
|
29
31
|
"@vaadin/icon": "^25.0.0",
|
|
@@ -49,9 +51,12 @@
|
|
|
49
51
|
"@custom-elements-manifest/analyzer": "^0.11.0",
|
|
50
52
|
"@eslint/compat": "^2.0.0",
|
|
51
53
|
"@open-wc/testing": "^4.0.0",
|
|
54
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
52
55
|
"@rollup/plugin-babel": "6.1.0",
|
|
53
56
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
54
57
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
58
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
59
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
55
60
|
"@vaadin/vaadin-lumo-styles": "^25.0.0",
|
|
56
61
|
"@web/dev-server": "^0.4.6",
|
|
57
62
|
"@web/test-runner": "^0.20.2",
|
|
@@ -66,6 +71,7 @@
|
|
|
66
71
|
"rollup": "^4.53.2",
|
|
67
72
|
"rollup-plugin-copy": "^3.5.0",
|
|
68
73
|
"rollup-plugin-filesize": "^10.0.0",
|
|
74
|
+
"tslib": "^2.6.2",
|
|
69
75
|
"webpack": "^5.103.0",
|
|
70
76
|
"webpack-cli": "^6.0.1",
|
|
71
77
|
"webpack-dev-server": "^5.2.2"
|
|
@@ -80,4 +86,4 @@
|
|
|
80
86
|
"build": "rimraf dist && rollup -c pdfjs/rollup.config.js"
|
|
81
87
|
},
|
|
82
88
|
"customElements": "custom-elements.json"
|
|
83
|
-
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/* Copyright 2012 Mozilla Foundation
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const WaitOnType = {
|
|
17
|
+
EVENT: "event",
|
|
18
|
+
TIMEOUT: "timeout"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} WaitOnEventOrTimeoutParameters
|
|
23
|
+
* @property {Object} target - The event target, can for example be:
|
|
24
|
+
* `window`, `document`, a DOM element, or an {EventBus} instance.
|
|
25
|
+
* @property {string} name - The name of the event.
|
|
26
|
+
* @property {number} delay - The delay, in milliseconds, after which the
|
|
27
|
+
* timeout occurs (if the event wasn't already dispatched).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Allows waiting for an event or a timeout, whichever occurs first.
|
|
32
|
+
* Can be used to ensure that an action always occurs, even when an event
|
|
33
|
+
* arrives late or not at all.
|
|
34
|
+
*
|
|
35
|
+
* @param {WaitOnEventOrTimeoutParameters}
|
|
36
|
+
* @returns {Promise} A promise that is resolved with a {WaitOnType} value.
|
|
37
|
+
*/
|
|
38
|
+
async function waitOnEventOrTimeout({
|
|
39
|
+
target,
|
|
40
|
+
name,
|
|
41
|
+
delay = 0
|
|
42
|
+
}) {
|
|
43
|
+
if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
|
|
44
|
+
throw new Error("waitOnEventOrTimeout - invalid parameters.");
|
|
45
|
+
}
|
|
46
|
+
const {
|
|
47
|
+
promise,
|
|
48
|
+
resolve
|
|
49
|
+
} = Promise.withResolvers();
|
|
50
|
+
const ac = new AbortController();
|
|
51
|
+
function handler(type) {
|
|
52
|
+
ac.abort(); // Remove event listener.
|
|
53
|
+
clearTimeout(timeout);
|
|
54
|
+
resolve(type);
|
|
55
|
+
}
|
|
56
|
+
const evtMethod = target instanceof EventBus ? "_on" : "addEventListener";
|
|
57
|
+
target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), {
|
|
58
|
+
signal: ac.signal
|
|
59
|
+
});
|
|
60
|
+
const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay);
|
|
61
|
+
return promise;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Simple event bus for an application. Listeners are attached using the `on`
|
|
66
|
+
* and `off` methods. To raise an event, the `dispatch` method shall be used.
|
|
67
|
+
*/
|
|
68
|
+
class EventBus {
|
|
69
|
+
#listeners = Object.create(null);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} eventName
|
|
73
|
+
* @param {function} listener
|
|
74
|
+
* @param {Object} [options]
|
|
75
|
+
*/
|
|
76
|
+
on(eventName, listener, options = null) {
|
|
77
|
+
this._on(eventName, listener, {
|
|
78
|
+
external: true,
|
|
79
|
+
once: options === null || options === void 0 ? void 0 : options.once,
|
|
80
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {string} eventName
|
|
86
|
+
* @param {function} listener
|
|
87
|
+
* @param {Object} [options]
|
|
88
|
+
*/
|
|
89
|
+
off(eventName, listener, options = null) {
|
|
90
|
+
this._off(eventName, listener);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} eventName
|
|
95
|
+
* @param {Object} data
|
|
96
|
+
*/
|
|
97
|
+
dispatch(eventName, data) {
|
|
98
|
+
const eventListeners = this.#listeners[eventName];
|
|
99
|
+
if (!eventListeners || eventListeners.length === 0) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let externalListeners;
|
|
103
|
+
// Making copy of the listeners array in case if it will be modified
|
|
104
|
+
// during dispatch.
|
|
105
|
+
for (const {
|
|
106
|
+
listener,
|
|
107
|
+
external,
|
|
108
|
+
once
|
|
109
|
+
} of eventListeners.slice(0)) {
|
|
110
|
+
if (once) {
|
|
111
|
+
this._off(eventName, listener);
|
|
112
|
+
}
|
|
113
|
+
if (external) {
|
|
114
|
+
(externalListeners || (externalListeners = [])).push(listener);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
listener(data);
|
|
118
|
+
}
|
|
119
|
+
// Dispatch any "external" listeners *after* the internal ones, to give the
|
|
120
|
+
// viewer components time to handle events and update their state first.
|
|
121
|
+
if (externalListeners) {
|
|
122
|
+
for (const listener of externalListeners) {
|
|
123
|
+
listener(data);
|
|
124
|
+
}
|
|
125
|
+
externalListeners = null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @ignore
|
|
131
|
+
*/
|
|
132
|
+
_on(eventName, listener, options = null) {
|
|
133
|
+
var _this$listeners;
|
|
134
|
+
let rmAbort = null;
|
|
135
|
+
if ((options === null || options === void 0 ? void 0 : options.signal) instanceof AbortSignal) {
|
|
136
|
+
const {
|
|
137
|
+
signal
|
|
138
|
+
} = options;
|
|
139
|
+
if (signal.aborted) {
|
|
140
|
+
console.error("Cannot use an `aborted` signal.");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const onAbort = () => this._off(eventName, listener);
|
|
144
|
+
rmAbort = () => signal.removeEventListener("abort", onAbort);
|
|
145
|
+
signal.addEventListener("abort", onAbort);
|
|
146
|
+
}
|
|
147
|
+
const eventListeners = (_this$listeners = this.#listeners)[eventName] || (_this$listeners[eventName] = []);
|
|
148
|
+
eventListeners.push({
|
|
149
|
+
listener,
|
|
150
|
+
external: (options === null || options === void 0 ? void 0 : options.external) === true,
|
|
151
|
+
once: (options === null || options === void 0 ? void 0 : options.once) === true,
|
|
152
|
+
rmAbort
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @ignore
|
|
158
|
+
*/
|
|
159
|
+
_off(eventName, listener, options = null) {
|
|
160
|
+
const eventListeners = this.#listeners[eventName];
|
|
161
|
+
if (!eventListeners) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
for (let i = 0, ii = eventListeners.length; i < ii; i++) {
|
|
165
|
+
const evt = eventListeners[i];
|
|
166
|
+
if (evt.listener === listener) {
|
|
167
|
+
var _evt$rmAbort;
|
|
168
|
+
(_evt$rmAbort = evt.rmAbort) === null || _evt$rmAbort === void 0 ? void 0 : _evt$rmAbort.call(evt); // Ensure that the `AbortSignal` listener is removed.
|
|
169
|
+
eventListeners.splice(i, 1);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* NOTE: Only used to support various PDF viewer tests in `mozilla-central`.
|
|
178
|
+
*/
|
|
179
|
+
class AutomationEventBus extends EventBus {
|
|
180
|
+
dispatch(eventName, data) {
|
|
181
|
+
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("MOZCENTRAL")) {
|
|
182
|
+
throw new Error("Not implemented: AutomationEventBus.dispatch");
|
|
183
|
+
}
|
|
184
|
+
super.dispatch(eventName, data);
|
|
185
|
+
const detail = Object.create(null);
|
|
186
|
+
if (data) {
|
|
187
|
+
for (const key in data) {
|
|
188
|
+
const value = data[key];
|
|
189
|
+
if (key === "source") {
|
|
190
|
+
if (value === window || value === document) {
|
|
191
|
+
return; // No need to re-dispatch (already) global events.
|
|
192
|
+
}
|
|
193
|
+
continue; // Ignore the `source` property.
|
|
194
|
+
}
|
|
195
|
+
detail[key] = value;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const event = new CustomEvent(eventName, {
|
|
199
|
+
bubbles: true,
|
|
200
|
+
cancelable: true,
|
|
201
|
+
detail
|
|
202
|
+
});
|
|
203
|
+
document.dispatchEvent(event);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { AutomationEventBus, EventBus, WaitOnType, waitOnEventOrTimeout };
|