@vaadin-component-factory/vcf-pdf-viewer 3.0.2 → 4.0.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.
@@ -1,7 +1,7 @@
1
- import { c as assert, l as createPromiseCapability, A as AbortException } from './util.js';
2
- import { a as validateResponseStatus, c as createResponseStatusError, v as validateRangeRequestCapabilities, e as extractFilenameFromHeader } from './network_utils.js';
3
- import './display_utils.js';
4
-
1
+ import { d as assert, c as createPromiseCapability, A as AbortException } from './util.js';
2
+ import { a as validateResponseStatus, c as createResponseStatusError, v as validateRangeRequestCapabilities, e as extractFilenameFromHeader } from './network_utils.js';
3
+ import './display_utils.js';
4
+
5
5
  /* Copyright 2012 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,292 +15,238 @@ import './display_utils.js';
15
15
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
- */
19
-
20
- if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
21
- throw new Error('Module "./fetch_stream.js" shall not be used with MOZCENTRAL builds.');
22
- }
23
-
24
- function createFetchOptions(headers, withCredentials, abortController) {
25
- return {
26
- method: "GET",
27
- headers,
28
- signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
29
- mode: "cors",
30
- credentials: withCredentials ? "include" : "same-origin",
31
- redirect: "follow"
32
- };
33
- }
34
-
35
- function createHeaders(httpHeaders) {
36
- const headers = new Headers();
37
-
38
- for (const property in httpHeaders) {
39
- const value = httpHeaders[property];
40
-
41
- if (typeof value === "undefined") {
42
- continue;
43
- }
44
-
45
- headers.append(property, value);
46
- }
47
-
48
- return headers;
49
- }
50
- /** @implements {IPDFStream} */
51
-
52
-
53
- class PDFFetchStream {
54
- constructor(source) {
55
- this.source = source;
56
- this.isHttp = /^https?:/i.test(source.url);
57
- this.httpHeaders = this.isHttp && source.httpHeaders || {};
58
- this._fullRequestReader = null;
59
- this._rangeRequestReaders = [];
60
- }
61
-
62
- get _progressiveDataLength() {
63
- var _this$_fullRequestRea, _this$_fullRequestRea2;
64
-
65
- return (_this$_fullRequestRea = (_this$_fullRequestRea2 = this._fullRequestReader) === null || _this$_fullRequestRea2 === void 0 ? void 0 : _this$_fullRequestRea2._loaded) !== null && _this$_fullRequestRea !== void 0 ? _this$_fullRequestRea : 0;
66
- }
67
-
68
- getFullReader() {
69
- assert(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
70
- this._fullRequestReader = new PDFFetchStreamReader(this);
71
- return this._fullRequestReader;
72
- }
73
-
74
- getRangeReader(begin, end) {
75
- if (end <= this._progressiveDataLength) {
76
- return null;
77
- }
78
-
79
- const reader = new PDFFetchStreamRangeReader(this, begin, end);
80
-
81
- this._rangeRequestReaders.push(reader);
82
-
83
- return reader;
84
- }
85
-
86
- cancelAllRequests(reason) {
87
- if (this._fullRequestReader) {
88
- this._fullRequestReader.cancel(reason);
89
- }
90
-
91
- for (const reader of this._rangeRequestReaders.slice(0)) {
92
- reader.cancel(reason);
93
- }
94
- }
95
-
96
- }
97
- /** @implements {IPDFStreamReader} */
98
-
99
-
100
- class PDFFetchStreamReader {
101
- constructor(stream) {
102
- this._stream = stream;
103
- this._reader = null;
104
- this._loaded = 0;
105
- this._filename = null;
106
- const source = stream.source;
107
- this._withCredentials = source.withCredentials || false;
108
- this._contentLength = source.length;
109
- this._headersCapability = createPromiseCapability();
110
- this._disableRange = source.disableRange || false;
111
- this._rangeChunkSize = source.rangeChunkSize;
112
-
113
- if (!this._rangeChunkSize && !this._disableRange) {
114
- this._disableRange = true;
115
- }
116
-
117
- if (typeof AbortController !== "undefined") {
118
- this._abortController = new AbortController();
119
- }
120
-
121
- this._isStreamingSupported = !source.disableStream;
122
- this._isRangeSupported = !source.disableRange;
123
- this._headers = createHeaders(this._stream.httpHeaders);
124
- const url = source.url;
125
- fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
126
- if (!validateResponseStatus(response.status)) {
127
- throw createResponseStatusError(response.status, url);
128
- }
129
-
130
- this._reader = response.body.getReader();
131
-
132
- this._headersCapability.resolve();
133
-
134
- const getResponseHeader = name => {
135
- return response.headers.get(name);
136
- };
137
-
138
- const {
139
- allowRangeRequests,
140
- suggestedLength
141
- } = validateRangeRequestCapabilities({
142
- getResponseHeader,
143
- isHttp: this._stream.isHttp,
144
- rangeChunkSize: this._rangeChunkSize,
145
- disableRange: this._disableRange
146
- });
147
- this._isRangeSupported = allowRangeRequests; // Setting right content length.
148
-
149
- this._contentLength = suggestedLength || this._contentLength;
150
- this._filename = extractFilenameFromHeader(getResponseHeader); // We need to stop reading when range is supported and streaming is
151
- // disabled.
152
-
153
- if (!this._isStreamingSupported && this._isRangeSupported) {
154
- this.cancel(new AbortException("Streaming is disabled."));
155
- }
156
- }).catch(this._headersCapability.reject);
157
- this.onProgress = null;
158
- }
159
-
160
- get headersReady() {
161
- return this._headersCapability.promise;
162
- }
163
-
164
- get filename() {
165
- return this._filename;
166
- }
167
-
168
- get contentLength() {
169
- return this._contentLength;
170
- }
171
-
172
- get isRangeSupported() {
173
- return this._isRangeSupported;
174
- }
175
-
176
- get isStreamingSupported() {
177
- return this._isStreamingSupported;
178
- }
179
-
180
- async read() {
181
- await this._headersCapability.promise;
182
- const {
183
- value,
184
- done
185
- } = await this._reader.read();
186
-
187
- if (done) {
188
- return {
189
- value,
190
- done
191
- };
192
- }
193
-
194
- this._loaded += value.byteLength;
195
-
196
- if (this.onProgress) {
197
- this.onProgress({
198
- loaded: this._loaded,
199
- total: this._contentLength
200
- });
201
- }
202
-
203
- const buffer = new Uint8Array(value).buffer;
204
- return {
205
- value: buffer,
206
- done: false
207
- };
208
- }
209
-
210
- cancel(reason) {
211
- if (this._reader) {
212
- this._reader.cancel(reason);
213
- }
214
-
215
- if (this._abortController) {
216
- this._abortController.abort();
217
- }
218
- }
219
-
220
- }
221
- /** @implements {IPDFStreamRangeReader} */
222
-
223
-
224
- class PDFFetchStreamRangeReader {
225
- constructor(stream, begin, end) {
226
- this._stream = stream;
227
- this._reader = null;
228
- this._loaded = 0;
229
- const source = stream.source;
230
- this._withCredentials = source.withCredentials || false;
231
- this._readCapability = createPromiseCapability();
232
- this._isStreamingSupported = !source.disableStream;
233
-
234
- if (typeof AbortController !== "undefined") {
235
- this._abortController = new AbortController();
236
- }
237
-
238
- this._headers = createHeaders(this._stream.httpHeaders);
239
-
240
- this._headers.append("Range", `bytes=${begin}-${end - 1}`);
241
-
242
- const url = source.url;
243
- fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
244
- if (!validateResponseStatus(response.status)) {
245
- throw createResponseStatusError(response.status, url);
246
- }
247
-
248
- this._readCapability.resolve();
249
-
250
- this._reader = response.body.getReader();
251
- }).catch(reason => {
252
- if ((reason === null || reason === void 0 ? void 0 : reason.name) === "AbortError") {
253
- return;
254
- }
255
-
256
- throw reason;
257
- });
258
- this.onProgress = null;
259
- }
260
-
261
- get isStreamingSupported() {
262
- return this._isStreamingSupported;
263
- }
264
-
265
- async read() {
266
- await this._readCapability.promise;
267
- const {
268
- value,
269
- done
270
- } = await this._reader.read();
271
-
272
- if (done) {
273
- return {
274
- value,
275
- done
276
- };
277
- }
278
-
279
- this._loaded += value.byteLength;
280
-
281
- if (this.onProgress) {
282
- this.onProgress({
283
- loaded: this._loaded
284
- });
285
- }
286
-
287
- const buffer = new Uint8Array(value).buffer;
288
- return {
289
- value: buffer,
290
- done: false
291
- };
292
- }
293
-
294
- cancel(reason) {
295
- if (this._reader) {
296
- this._reader.cancel(reason);
297
- }
298
-
299
- if (this._abortController) {
300
- this._abortController.abort();
301
- }
302
- }
303
-
304
- }
305
-
306
- export { PDFFetchStream };
18
+ */
19
+
20
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
21
+ throw new Error('Module "./fetch_stream.js" shall not be used with MOZCENTRAL builds.');
22
+ }
23
+ function createFetchOptions(headers, withCredentials, abortController) {
24
+ return {
25
+ method: "GET",
26
+ headers,
27
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
28
+ mode: "cors",
29
+ credentials: withCredentials ? "include" : "same-origin",
30
+ redirect: "follow"
31
+ };
32
+ }
33
+ function createHeaders(httpHeaders) {
34
+ const headers = new Headers();
35
+ for (const property in httpHeaders) {
36
+ const value = httpHeaders[property];
37
+ if (typeof value === "undefined") {
38
+ continue;
39
+ }
40
+ headers.append(property, value);
41
+ }
42
+ return headers;
43
+ }
44
+
45
+ /** @implements {IPDFStream} */
46
+ class PDFFetchStream {
47
+ constructor(source) {
48
+ this.source = source;
49
+ this.isHttp = /^https?:/i.test(source.url);
50
+ this.httpHeaders = this.isHttp && source.httpHeaders || {};
51
+ this._fullRequestReader = null;
52
+ this._rangeRequestReaders = [];
53
+ }
54
+ get _progressiveDataLength() {
55
+ var _this$_fullRequestRea, _this$_fullRequestRea2;
56
+ return (_this$_fullRequestRea = (_this$_fullRequestRea2 = this._fullRequestReader) === null || _this$_fullRequestRea2 === void 0 ? void 0 : _this$_fullRequestRea2._loaded) !== null && _this$_fullRequestRea !== void 0 ? _this$_fullRequestRea : 0;
57
+ }
58
+ getFullReader() {
59
+ assert(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
60
+ this._fullRequestReader = new PDFFetchStreamReader(this);
61
+ return this._fullRequestReader;
62
+ }
63
+ getRangeReader(begin, end) {
64
+ if (end <= this._progressiveDataLength) {
65
+ return null;
66
+ }
67
+ const reader = new PDFFetchStreamRangeReader(this, begin, end);
68
+ this._rangeRequestReaders.push(reader);
69
+ return reader;
70
+ }
71
+ cancelAllRequests(reason) {
72
+ if (this._fullRequestReader) {
73
+ this._fullRequestReader.cancel(reason);
74
+ }
75
+ for (const reader of this._rangeRequestReaders.slice(0)) {
76
+ reader.cancel(reason);
77
+ }
78
+ }
79
+ }
80
+
81
+ /** @implements {IPDFStreamReader} */
82
+ class PDFFetchStreamReader {
83
+ constructor(stream) {
84
+ this._stream = stream;
85
+ this._reader = null;
86
+ this._loaded = 0;
87
+ this._filename = null;
88
+ const source = stream.source;
89
+ this._withCredentials = source.withCredentials || false;
90
+ this._contentLength = source.length;
91
+ this._headersCapability = createPromiseCapability();
92
+ this._disableRange = source.disableRange || false;
93
+ this._rangeChunkSize = source.rangeChunkSize;
94
+ if (!this._rangeChunkSize && !this._disableRange) {
95
+ this._disableRange = true;
96
+ }
97
+ if (typeof AbortController !== "undefined") {
98
+ this._abortController = new AbortController();
99
+ }
100
+ this._isStreamingSupported = !source.disableStream;
101
+ this._isRangeSupported = !source.disableRange;
102
+ this._headers = createHeaders(this._stream.httpHeaders);
103
+ const url = source.url;
104
+ fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
105
+ if (!validateResponseStatus(response.status)) {
106
+ throw createResponseStatusError(response.status, url);
107
+ }
108
+ this._reader = response.body.getReader();
109
+ this._headersCapability.resolve();
110
+ const getResponseHeader = name => {
111
+ return response.headers.get(name);
112
+ };
113
+ const {
114
+ allowRangeRequests,
115
+ suggestedLength
116
+ } = validateRangeRequestCapabilities({
117
+ getResponseHeader,
118
+ isHttp: this._stream.isHttp,
119
+ rangeChunkSize: this._rangeChunkSize,
120
+ disableRange: this._disableRange
121
+ });
122
+ this._isRangeSupported = allowRangeRequests;
123
+ // Setting right content length.
124
+ this._contentLength = suggestedLength || this._contentLength;
125
+ this._filename = extractFilenameFromHeader(getResponseHeader);
126
+
127
+ // We need to stop reading when range is supported and streaming is
128
+ // disabled.
129
+ if (!this._isStreamingSupported && this._isRangeSupported) {
130
+ this.cancel(new AbortException("Streaming is disabled."));
131
+ }
132
+ }).catch(this._headersCapability.reject);
133
+ this.onProgress = null;
134
+ }
135
+ get headersReady() {
136
+ return this._headersCapability.promise;
137
+ }
138
+ get filename() {
139
+ return this._filename;
140
+ }
141
+ get contentLength() {
142
+ return this._contentLength;
143
+ }
144
+ get isRangeSupported() {
145
+ return this._isRangeSupported;
146
+ }
147
+ get isStreamingSupported() {
148
+ return this._isStreamingSupported;
149
+ }
150
+ async read() {
151
+ await this._headersCapability.promise;
152
+ const {
153
+ value,
154
+ done
155
+ } = await this._reader.read();
156
+ if (done) {
157
+ return {
158
+ value,
159
+ done
160
+ };
161
+ }
162
+ this._loaded += value.byteLength;
163
+ if (this.onProgress) {
164
+ this.onProgress({
165
+ loaded: this._loaded,
166
+ total: this._contentLength
167
+ });
168
+ }
169
+ const buffer = new Uint8Array(value).buffer;
170
+ return {
171
+ value: buffer,
172
+ done: false
173
+ };
174
+ }
175
+ cancel(reason) {
176
+ if (this._reader) {
177
+ this._reader.cancel(reason);
178
+ }
179
+ if (this._abortController) {
180
+ this._abortController.abort();
181
+ }
182
+ }
183
+ }
184
+
185
+ /** @implements {IPDFStreamRangeReader} */
186
+ class PDFFetchStreamRangeReader {
187
+ constructor(stream, begin, end) {
188
+ this._stream = stream;
189
+ this._reader = null;
190
+ this._loaded = 0;
191
+ const source = stream.source;
192
+ this._withCredentials = source.withCredentials || false;
193
+ this._readCapability = createPromiseCapability();
194
+ this._isStreamingSupported = !source.disableStream;
195
+ if (typeof AbortController !== "undefined") {
196
+ this._abortController = new AbortController();
197
+ }
198
+ this._headers = createHeaders(this._stream.httpHeaders);
199
+ this._headers.append("Range", `bytes=${begin}-${end - 1}`);
200
+ const url = source.url;
201
+ fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
202
+ if (!validateResponseStatus(response.status)) {
203
+ throw createResponseStatusError(response.status, url);
204
+ }
205
+ this._readCapability.resolve();
206
+ this._reader = response.body.getReader();
207
+ }).catch(reason => {
208
+ if ((reason === null || reason === void 0 ? void 0 : reason.name) === "AbortError") {
209
+ return;
210
+ }
211
+ throw reason;
212
+ });
213
+ this.onProgress = null;
214
+ }
215
+ get isStreamingSupported() {
216
+ return this._isStreamingSupported;
217
+ }
218
+ async read() {
219
+ await this._readCapability.promise;
220
+ const {
221
+ value,
222
+ done
223
+ } = await this._reader.read();
224
+ if (done) {
225
+ return {
226
+ value,
227
+ done
228
+ };
229
+ }
230
+ this._loaded += value.byteLength;
231
+ if (this.onProgress) {
232
+ this.onProgress({
233
+ loaded: this._loaded
234
+ });
235
+ }
236
+ const buffer = new Uint8Array(value).buffer;
237
+ return {
238
+ value: buffer,
239
+ done: false
240
+ };
241
+ }
242
+ cancel(reason) {
243
+ if (this._reader) {
244
+ this._reader.cancel(reason);
245
+ }
246
+ if (this._abortController) {
247
+ this._abortController.abort();
248
+ }
249
+ }
250
+ }
251
+
252
+ export { PDFFetchStream };