@vaadin-component-factory/vcf-pdf-viewer 4.0.2 → 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.
@@ -1,306 +0,0 @@
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
-
5
- /* Copyright 2012 Mozilla Foundation
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
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 };
@@ -1,140 +0,0 @@
1
- /* Copyright 2021 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
- /**
17
- * A subset of the l10n strings in the `l10n/en-US/viewer.properties` file.
18
- */
19
- const DEFAULT_L10N_STRINGS = {
20
- of_pages: "of {{pagesCount}}",
21
- page_of_pages: "({{pageNumber}} of {{pagesCount}})",
22
- document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
23
- document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
24
- document_properties_date_string: "{{date}}, {{time}}",
25
- document_properties_page_size_unit_inches: "in",
26
- document_properties_page_size_unit_millimeters: "mm",
27
- document_properties_page_size_orientation_portrait: "portrait",
28
- document_properties_page_size_orientation_landscape: "landscape",
29
- document_properties_page_size_name_a3: "A3",
30
- document_properties_page_size_name_a4: "A4",
31
- document_properties_page_size_name_letter: "Letter",
32
- document_properties_page_size_name_legal: "Legal",
33
- document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
34
- document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
35
- document_properties_linearized_yes: "Yes",
36
- document_properties_linearized_no: "No",
37
- print_progress_percent: "{{progress}}%",
38
- "toggle_sidebar.title": "Toggle Sidebar",
39
- "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
40
- additional_layers: "Additional Layers",
41
- page_landmark: "Page {{page}}",
42
- thumb_page_title: "Page {{page}}",
43
- thumb_page_canvas: "Thumbnail of Page {{page}}",
44
- find_reached_top: "Reached top of document, continued from bottom",
45
- find_reached_bottom: "Reached end of document, continued from top",
46
- "find_match_count[one]": "{{current}} of {{total}} match",
47
- "find_match_count[other]": "{{current}} of {{total}} matches",
48
- "find_match_count_limit[one]": "More than {{limit}} match",
49
- "find_match_count_limit[other]": "More than {{limit}} matches",
50
- find_not_found: "Phrase not found",
51
- error_version_info: "PDF.js v{{version}} (build: {{build}})",
52
- error_message: "Message: {{message}}",
53
- error_stack: "Stack: {{stack}}",
54
- error_file: "File: {{file}}",
55
- error_line: "Line: {{line}}",
56
- rendering_error: "An error occurred while rendering the page.",
57
- page_scale_width: "Page Width",
58
- page_scale_fit: "Page Fit",
59
- page_scale_auto: "Automatic Zoom",
60
- page_scale_actual: "Actual Size",
61
- page_scale_percent: "{{scale}}%",
62
- loading: "Loading…",
63
- loading_error: "An error occurred while loading the PDF.",
64
- invalid_file_error: "Invalid or corrupted PDF file.",
65
- missing_file_error: "Missing PDF file.",
66
- unexpected_response_error: "Unexpected server response.",
67
- printing_not_supported: "Warning: Printing is not fully supported by this browser.",
68
- printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
69
- web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
70
- };
71
-
72
- function getL10nFallback(key, args) {
73
- switch (key) {
74
- case "find_match_count":
75
- key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
76
- break;
77
-
78
- case "find_match_count_limit":
79
- key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
80
- break;
81
- }
82
-
83
- return DEFAULT_L10N_STRINGS[key] || "";
84
- }
85
-
86
- const PARTIAL_LANG_CODES = {
87
- en: "en-US",
88
- es: "es-ES",
89
- fy: "fy-NL",
90
- ga: "ga-IE",
91
- gu: "gu-IN",
92
- hi: "hi-IN",
93
- hy: "hy-AM",
94
- nb: "nb-NO",
95
- ne: "ne-NP",
96
- nn: "nn-NO",
97
- pa: "pa-IN",
98
- pt: "pt-PT",
99
- sv: "sv-SE",
100
- zh: "zh-CN"
101
- }; // Try to support "incompletely" specified language codes (see issue 13689).
102
-
103
- function fixupLangCode(langCode) {
104
- return PARTIAL_LANG_CODES[langCode === null || langCode === void 0 ? void 0 : langCode.toLowerCase()] || langCode;
105
- } // Replaces {{arguments}} with their values.
106
-
107
-
108
- function formatL10nValue(text, args) {
109
- if (!args) {
110
- return text;
111
- }
112
-
113
- return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
114
- return name in args ? args[name] : "{{" + name + "}}";
115
- });
116
- }
117
- /**
118
- * No-op implementation of the localization service.
119
- * @implements {IL10n}
120
- */
121
-
122
-
123
- const NullL10n = {
124
- async getLanguage() {
125
- return "en-us";
126
- },
127
-
128
- async getDirection() {
129
- return "ltr";
130
- },
131
-
132
- async get(key, args = null, fallback = getL10nFallback(key, args)) {
133
- return formatL10nValue(fallback, args);
134
- },
135
-
136
- async translate(element) {}
137
-
138
- };
139
-
140
- export { NullL10n, fixupLangCode, getL10nFallback };