@vaadin-component-factory/vcf-pdf-viewer 4.0.2 → 4.2.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/LICENSE +190 -190
- package/README.md +35 -35
- package/custom-elements.json +664 -0
- package/package.json +118 -83
- package/pdfjs/dist/event_utils.js +207 -0
- package/pdfjs/dist/genericl10n.js +2420 -0
- package/pdfjs/dist/message_handler.js +704 -569
- package/pdfjs/dist/node_stream.js +2 -494
- package/pdfjs/dist/node_stream2.js +1759 -0
- package/pdfjs/dist/pdf.js +20927 -12778
- package/pdfjs/dist/pdf.worker.js +24 -0
- package/pdfjs/dist/pdf_link_service.js +483 -638
- package/pdfjs/dist/pdf_rendering_queue.js +199 -199
- package/pdfjs/dist/pdf_thumbnail_viewer.js +636 -819
- package/pdfjs/dist/pdf_viewer.js +4743 -3598
- package/pdfjs/dist/ui_utils.js +762 -1033
- package/pdfjs/dist/util.js +855 -1066
- package/pdfjs/dist/worker.js +61967 -62813
- package/src/vcf-pdf-viewer.d.ts +247 -0
- package/src/vcf-pdf-viewer.js +1214 -1072
- package/theme/base/vcf-pdf-viewer-styles.js +144 -144
- package/theme/base/vcf-pdf-viewer-toolbar-icons-styles.js +39 -39
- package/theme/base/vcf-pdf-viewer.d.ts +6 -0
- package/theme/base/vcf-pdf-viewer.js +2 -2
- package/vcf-pdf-viewer.d.ts +6 -0
- package/vcf-pdf-viewer.js +2 -2
- package/pdfjs/dist/display_utils.js +0 -848
- package/pdfjs/dist/fetch_stream.js +0 -306
- package/pdfjs/dist/l10n_utils.js +0 -140
- package/pdfjs/dist/network.js +0 -565
- package/pdfjs/dist/network_utils.js +0 -340
|
@@ -1,569 +1,704 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/* Copyright
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
} else
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
1
|
+
import { F as FeatureTest, p as ImageKind, e as assert, u as unreachable, v as UnknownErrorException, x as UnexpectedResponseException, z as PasswordException, M as MissingPDFException, a as AbortException } from './util.js';
|
|
2
|
+
|
|
3
|
+
/* Copyright 2014 Opera Software ASA
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
|
|
19
|
+
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const SEED = 0xc3d2e1f0;
|
|
23
|
+
// Workaround for missing math precision in JS.
|
|
24
|
+
const MASK_HIGH = 0xffff0000;
|
|
25
|
+
const MASK_LOW = 0xffff;
|
|
26
|
+
class MurmurHash3_64 {
|
|
27
|
+
constructor(seed) {
|
|
28
|
+
this.h1 = seed ? seed & 0xffffffff : SEED;
|
|
29
|
+
this.h2 = seed ? seed & 0xffffffff : SEED;
|
|
30
|
+
}
|
|
31
|
+
update(input) {
|
|
32
|
+
let data, length;
|
|
33
|
+
if (typeof input === "string") {
|
|
34
|
+
data = new Uint8Array(input.length * 2);
|
|
35
|
+
length = 0;
|
|
36
|
+
for (let i = 0, ii = input.length; i < ii; i++) {
|
|
37
|
+
const code = input.charCodeAt(i);
|
|
38
|
+
if (code <= 0xff) {
|
|
39
|
+
data[length++] = code;
|
|
40
|
+
} else {
|
|
41
|
+
data[length++] = code >>> 8;
|
|
42
|
+
data[length++] = code & 0xff;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
46
|
+
data = input.slice();
|
|
47
|
+
length = data.byteLength;
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error("Invalid data format, must be a string or TypedArray.");
|
|
50
|
+
}
|
|
51
|
+
const blockCounts = length >> 2;
|
|
52
|
+
const tailLength = length - blockCounts * 4;
|
|
53
|
+
// We don't care about endianness here.
|
|
54
|
+
const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
|
|
55
|
+
let k1 = 0,
|
|
56
|
+
k2 = 0;
|
|
57
|
+
let h1 = this.h1,
|
|
58
|
+
h2 = this.h2;
|
|
59
|
+
const C1 = 0xcc9e2d51,
|
|
60
|
+
C2 = 0x1b873593;
|
|
61
|
+
const C1_LOW = C1 & MASK_LOW,
|
|
62
|
+
C2_LOW = C2 & MASK_LOW;
|
|
63
|
+
for (let i = 0; i < blockCounts; i++) {
|
|
64
|
+
if (i & 1) {
|
|
65
|
+
k1 = dataUint32[i];
|
|
66
|
+
k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
|
67
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
68
|
+
k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
|
69
|
+
h1 ^= k1;
|
|
70
|
+
h1 = h1 << 13 | h1 >>> 19;
|
|
71
|
+
h1 = h1 * 5 + 0xe6546b64;
|
|
72
|
+
} else {
|
|
73
|
+
k2 = dataUint32[i];
|
|
74
|
+
k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
|
|
75
|
+
k2 = k2 << 15 | k2 >>> 17;
|
|
76
|
+
k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
|
|
77
|
+
h2 ^= k2;
|
|
78
|
+
h2 = h2 << 13 | h2 >>> 19;
|
|
79
|
+
h2 = h2 * 5 + 0xe6546b64;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
k1 = 0;
|
|
83
|
+
switch (tailLength) {
|
|
84
|
+
case 3:
|
|
85
|
+
k1 ^= data[blockCounts * 4 + 2] << 16;
|
|
86
|
+
/* falls through */
|
|
87
|
+
case 2:
|
|
88
|
+
k1 ^= data[blockCounts * 4 + 1] << 8;
|
|
89
|
+
/* falls through */
|
|
90
|
+
case 1:
|
|
91
|
+
k1 ^= data[blockCounts * 4];
|
|
92
|
+
/* falls through */
|
|
93
|
+
|
|
94
|
+
k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
|
95
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
96
|
+
k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
|
97
|
+
if (blockCounts & 1) {
|
|
98
|
+
h1 ^= k1;
|
|
99
|
+
} else {
|
|
100
|
+
h2 ^= k1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.h1 = h1;
|
|
104
|
+
this.h2 = h2;
|
|
105
|
+
}
|
|
106
|
+
hexdigest() {
|
|
107
|
+
let h1 = this.h1,
|
|
108
|
+
h2 = this.h2;
|
|
109
|
+
h1 ^= h2 >>> 1;
|
|
110
|
+
h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
|
|
111
|
+
h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
|
|
112
|
+
h1 ^= h2 >>> 1;
|
|
113
|
+
h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
|
|
114
|
+
h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
|
|
115
|
+
h1 ^= h2 >>> 1;
|
|
116
|
+
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Copyright 2022 Mozilla Foundation
|
|
121
|
+
*
|
|
122
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
123
|
+
* you may not use this file except in compliance with the License.
|
|
124
|
+
* You may obtain a copy of the License at
|
|
125
|
+
*
|
|
126
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
127
|
+
*
|
|
128
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
129
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
130
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
131
|
+
* See the License for the specific language governing permissions and
|
|
132
|
+
* limitations under the License.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
function convertToRGBA(params) {
|
|
136
|
+
switch (params.kind) {
|
|
137
|
+
case ImageKind.GRAYSCALE_1BPP:
|
|
138
|
+
return convertBlackAndWhiteToRGBA(params);
|
|
139
|
+
case ImageKind.RGB_24BPP:
|
|
140
|
+
return convertRGBToRGBA(params);
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
function convertBlackAndWhiteToRGBA({
|
|
145
|
+
src,
|
|
146
|
+
srcPos = 0,
|
|
147
|
+
dest,
|
|
148
|
+
width,
|
|
149
|
+
height,
|
|
150
|
+
nonBlackColor = 0xffffffff,
|
|
151
|
+
inverseDecode = false
|
|
152
|
+
}) {
|
|
153
|
+
const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
|
|
154
|
+
const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
|
|
155
|
+
const widthInSource = width >> 3;
|
|
156
|
+
const widthRemainder = width & 7;
|
|
157
|
+
const srcLength = src.length;
|
|
158
|
+
dest = new Uint32Array(dest.buffer);
|
|
159
|
+
let destPos = 0;
|
|
160
|
+
for (let i = 0; i < height; i++) {
|
|
161
|
+
for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
|
|
162
|
+
const elem = srcPos < srcLength ? src[srcPos] : 255;
|
|
163
|
+
dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
|
|
164
|
+
dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
|
|
165
|
+
dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
|
|
166
|
+
dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
|
|
167
|
+
dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
|
|
168
|
+
dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
|
|
169
|
+
dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
|
|
170
|
+
dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
|
|
171
|
+
}
|
|
172
|
+
if (widthRemainder === 0) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const elem = srcPos < srcLength ? src[srcPos++] : 255;
|
|
176
|
+
for (let j = 0; j < widthRemainder; j++) {
|
|
177
|
+
dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
srcPos,
|
|
182
|
+
destPos
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function convertRGBToRGBA({
|
|
186
|
+
src,
|
|
187
|
+
srcPos = 0,
|
|
188
|
+
dest,
|
|
189
|
+
destPos = 0,
|
|
190
|
+
width,
|
|
191
|
+
height
|
|
192
|
+
}) {
|
|
193
|
+
let i = 0;
|
|
194
|
+
const len32 = src.length >> 2;
|
|
195
|
+
const src32 = new Uint32Array(src.buffer, srcPos, len32);
|
|
196
|
+
if (FeatureTest.isLittleEndian) {
|
|
197
|
+
// It's a way faster to do the shuffle manually instead of working
|
|
198
|
+
// component by component with some Uint8 arrays.
|
|
199
|
+
for (; i < len32 - 2; i += 3, destPos += 4) {
|
|
200
|
+
const s1 = src32[i]; // R2B1G1R1
|
|
201
|
+
const s2 = src32[i + 1]; // G3R3B2G2
|
|
202
|
+
const s3 = src32[i + 2]; // B4G4R4B3
|
|
203
|
+
|
|
204
|
+
dest[destPos] = s1 | 0xff000000;
|
|
205
|
+
dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
|
|
206
|
+
dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
|
|
207
|
+
dest[destPos + 3] = s3 >>> 8 | 0xff000000;
|
|
208
|
+
}
|
|
209
|
+
for (let j = i * 4, jj = src.length; j < jj; j += 3) {
|
|
210
|
+
dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
for (; i < len32 - 2; i += 3, destPos += 4) {
|
|
214
|
+
const s1 = src32[i]; // R1G1B1R2
|
|
215
|
+
const s2 = src32[i + 1]; // G2B2R3G3
|
|
216
|
+
const s3 = src32[i + 2]; // B3R4G4B4
|
|
217
|
+
|
|
218
|
+
dest[destPos] = s1 | 0xff;
|
|
219
|
+
dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
|
|
220
|
+
dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
|
|
221
|
+
dest[destPos + 3] = s3 << 8 | 0xff;
|
|
222
|
+
}
|
|
223
|
+
for (let j = i * 4, jj = src.length; j < jj; j += 3) {
|
|
224
|
+
dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
srcPos,
|
|
229
|
+
destPos
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function grayToRGBA(src, dest) {
|
|
233
|
+
if (FeatureTest.isLittleEndian) {
|
|
234
|
+
for (let i = 0, ii = src.length; i < ii; i++) {
|
|
235
|
+
dest[i] = src[i] * 0x10101 | 0xff000000;
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
for (let i = 0, ii = src.length; i < ii; i++) {
|
|
239
|
+
dest[i] = src[i] * 0x1010100 | 0x000000ff;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Copyright 2018 Mozilla Foundation
|
|
245
|
+
*
|
|
246
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
247
|
+
* you may not use this file except in compliance with the License.
|
|
248
|
+
* You may obtain a copy of the License at
|
|
249
|
+
*
|
|
250
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
251
|
+
*
|
|
252
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
253
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
254
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
255
|
+
* See the License for the specific language governing permissions and
|
|
256
|
+
* limitations under the License.
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
const CallbackKind = {
|
|
260
|
+
DATA: 1,
|
|
261
|
+
ERROR: 2
|
|
262
|
+
};
|
|
263
|
+
const StreamKind = {
|
|
264
|
+
CANCEL: 1,
|
|
265
|
+
CANCEL_COMPLETE: 2,
|
|
266
|
+
CLOSE: 3,
|
|
267
|
+
ENQUEUE: 4,
|
|
268
|
+
ERROR: 5,
|
|
269
|
+
PULL: 6,
|
|
270
|
+
PULL_COMPLETE: 7,
|
|
271
|
+
START_COMPLETE: 8
|
|
272
|
+
};
|
|
273
|
+
function wrapReason(reason) {
|
|
274
|
+
if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
|
|
275
|
+
unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
|
|
276
|
+
}
|
|
277
|
+
switch (reason.name) {
|
|
278
|
+
case "AbortException":
|
|
279
|
+
return new AbortException(reason.message);
|
|
280
|
+
case "MissingPDFException":
|
|
281
|
+
return new MissingPDFException(reason.message);
|
|
282
|
+
case "PasswordException":
|
|
283
|
+
return new PasswordException(reason.message, reason.code);
|
|
284
|
+
case "UnexpectedResponseException":
|
|
285
|
+
return new UnexpectedResponseException(reason.message, reason.status);
|
|
286
|
+
case "UnknownErrorException":
|
|
287
|
+
return new UnknownErrorException(reason.message, reason.details);
|
|
288
|
+
default:
|
|
289
|
+
return new UnknownErrorException(reason.message, reason.toString());
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
class MessageHandler {
|
|
293
|
+
constructor(sourceName, targetName, comObj) {
|
|
294
|
+
this.sourceName = sourceName;
|
|
295
|
+
this.targetName = targetName;
|
|
296
|
+
this.comObj = comObj;
|
|
297
|
+
this.callbackId = 1;
|
|
298
|
+
this.streamId = 1;
|
|
299
|
+
this.streamSinks = Object.create(null);
|
|
300
|
+
this.streamControllers = Object.create(null);
|
|
301
|
+
this.callbackCapabilities = Object.create(null);
|
|
302
|
+
this.actionHandler = Object.create(null);
|
|
303
|
+
this._onComObjOnMessage = event => {
|
|
304
|
+
const data = event.data;
|
|
305
|
+
if (data.targetName !== this.sourceName) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (data.stream) {
|
|
309
|
+
this.#processStreamMessage(data);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (data.callback) {
|
|
313
|
+
const callbackId = data.callbackId;
|
|
314
|
+
const capability = this.callbackCapabilities[callbackId];
|
|
315
|
+
if (!capability) {
|
|
316
|
+
throw new Error(`Cannot resolve callback ${callbackId}`);
|
|
317
|
+
}
|
|
318
|
+
delete this.callbackCapabilities[callbackId];
|
|
319
|
+
if (data.callback === CallbackKind.DATA) {
|
|
320
|
+
capability.resolve(data.data);
|
|
321
|
+
} else if (data.callback === CallbackKind.ERROR) {
|
|
322
|
+
capability.reject(wrapReason(data.reason));
|
|
323
|
+
} else {
|
|
324
|
+
throw new Error("Unexpected callback case");
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const action = this.actionHandler[data.action];
|
|
329
|
+
if (!action) {
|
|
330
|
+
throw new Error(`Unknown action from worker: ${data.action}`);
|
|
331
|
+
}
|
|
332
|
+
if (data.callbackId) {
|
|
333
|
+
const cbSourceName = this.sourceName;
|
|
334
|
+
const cbTargetName = data.sourceName;
|
|
335
|
+
new Promise(function (resolve) {
|
|
336
|
+
resolve(action(data.data));
|
|
337
|
+
}).then(function (result) {
|
|
338
|
+
comObj.postMessage({
|
|
339
|
+
sourceName: cbSourceName,
|
|
340
|
+
targetName: cbTargetName,
|
|
341
|
+
callback: CallbackKind.DATA,
|
|
342
|
+
callbackId: data.callbackId,
|
|
343
|
+
data: result
|
|
344
|
+
});
|
|
345
|
+
}, function (reason) {
|
|
346
|
+
comObj.postMessage({
|
|
347
|
+
sourceName: cbSourceName,
|
|
348
|
+
targetName: cbTargetName,
|
|
349
|
+
callback: CallbackKind.ERROR,
|
|
350
|
+
callbackId: data.callbackId,
|
|
351
|
+
reason: wrapReason(reason)
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (data.streamId) {
|
|
357
|
+
this.#createStreamSink(data);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
action(data.data);
|
|
361
|
+
};
|
|
362
|
+
comObj.addEventListener("message", this._onComObjOnMessage);
|
|
363
|
+
}
|
|
364
|
+
on(actionName, handler) {
|
|
365
|
+
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
|
366
|
+
assert(typeof handler === "function", 'MessageHandler.on: Expected "handler" to be a function.');
|
|
367
|
+
}
|
|
368
|
+
const ah = this.actionHandler;
|
|
369
|
+
if (ah[actionName]) {
|
|
370
|
+
throw new Error(`There is already an actionName called "${actionName}"`);
|
|
371
|
+
}
|
|
372
|
+
ah[actionName] = handler;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
377
|
+
* @param {string} actionName - Action to call.
|
|
378
|
+
* @param {JSON} data - JSON data to send.
|
|
379
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
380
|
+
*/
|
|
381
|
+
send(actionName, data, transfers) {
|
|
382
|
+
this.comObj.postMessage({
|
|
383
|
+
sourceName: this.sourceName,
|
|
384
|
+
targetName: this.targetName,
|
|
385
|
+
action: actionName,
|
|
386
|
+
data
|
|
387
|
+
}, transfers);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
392
|
+
* Expects that the other side will callback with the response.
|
|
393
|
+
* @param {string} actionName - Action to call.
|
|
394
|
+
* @param {JSON} data - JSON data to send.
|
|
395
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
396
|
+
* @returns {Promise} Promise to be resolved with response data.
|
|
397
|
+
*/
|
|
398
|
+
sendWithPromise(actionName, data, transfers) {
|
|
399
|
+
const callbackId = this.callbackId++;
|
|
400
|
+
const capability = Promise.withResolvers();
|
|
401
|
+
this.callbackCapabilities[callbackId] = capability;
|
|
402
|
+
try {
|
|
403
|
+
this.comObj.postMessage({
|
|
404
|
+
sourceName: this.sourceName,
|
|
405
|
+
targetName: this.targetName,
|
|
406
|
+
action: actionName,
|
|
407
|
+
callbackId,
|
|
408
|
+
data
|
|
409
|
+
}, transfers);
|
|
410
|
+
} catch (ex) {
|
|
411
|
+
capability.reject(ex);
|
|
412
|
+
}
|
|
413
|
+
return capability.promise;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
418
|
+
* Expect that the other side will callback to signal 'start_complete'.
|
|
419
|
+
* @param {string} actionName - Action to call.
|
|
420
|
+
* @param {JSON} data - JSON data to send.
|
|
421
|
+
* @param {Object} queueingStrategy - Strategy to signal backpressure based on
|
|
422
|
+
* internal queue.
|
|
423
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
424
|
+
* @returns {ReadableStream} ReadableStream to read data in chunks.
|
|
425
|
+
*/
|
|
426
|
+
sendWithStream(actionName, data, queueingStrategy, transfers) {
|
|
427
|
+
const streamId = this.streamId++,
|
|
428
|
+
sourceName = this.sourceName,
|
|
429
|
+
targetName = this.targetName,
|
|
430
|
+
comObj = this.comObj;
|
|
431
|
+
return new ReadableStream({
|
|
432
|
+
start: controller => {
|
|
433
|
+
const startCapability = Promise.withResolvers();
|
|
434
|
+
this.streamControllers[streamId] = {
|
|
435
|
+
controller,
|
|
436
|
+
startCall: startCapability,
|
|
437
|
+
pullCall: null,
|
|
438
|
+
cancelCall: null,
|
|
439
|
+
isClosed: false
|
|
440
|
+
};
|
|
441
|
+
comObj.postMessage({
|
|
442
|
+
sourceName,
|
|
443
|
+
targetName,
|
|
444
|
+
action: actionName,
|
|
445
|
+
streamId,
|
|
446
|
+
data,
|
|
447
|
+
desiredSize: controller.desiredSize
|
|
448
|
+
}, transfers);
|
|
449
|
+
// Return Promise for Async process, to signal success/failure.
|
|
450
|
+
return startCapability.promise;
|
|
451
|
+
},
|
|
452
|
+
pull: controller => {
|
|
453
|
+
const pullCapability = Promise.withResolvers();
|
|
454
|
+
this.streamControllers[streamId].pullCall = pullCapability;
|
|
455
|
+
comObj.postMessage({
|
|
456
|
+
sourceName,
|
|
457
|
+
targetName,
|
|
458
|
+
stream: StreamKind.PULL,
|
|
459
|
+
streamId,
|
|
460
|
+
desiredSize: controller.desiredSize
|
|
461
|
+
});
|
|
462
|
+
// Returning Promise will not call "pull"
|
|
463
|
+
// again until current pull is resolved.
|
|
464
|
+
return pullCapability.promise;
|
|
465
|
+
},
|
|
466
|
+
cancel: reason => {
|
|
467
|
+
assert(reason instanceof Error, "cancel must have a valid reason");
|
|
468
|
+
const cancelCapability = Promise.withResolvers();
|
|
469
|
+
this.streamControllers[streamId].cancelCall = cancelCapability;
|
|
470
|
+
this.streamControllers[streamId].isClosed = true;
|
|
471
|
+
comObj.postMessage({
|
|
472
|
+
sourceName,
|
|
473
|
+
targetName,
|
|
474
|
+
stream: StreamKind.CANCEL,
|
|
475
|
+
streamId,
|
|
476
|
+
reason: wrapReason(reason)
|
|
477
|
+
});
|
|
478
|
+
// Return Promise to signal success or failure.
|
|
479
|
+
return cancelCapability.promise;
|
|
480
|
+
}
|
|
481
|
+
}, queueingStrategy);
|
|
482
|
+
}
|
|
483
|
+
#createStreamSink(data) {
|
|
484
|
+
const streamId = data.streamId,
|
|
485
|
+
sourceName = this.sourceName,
|
|
486
|
+
targetName = data.sourceName,
|
|
487
|
+
comObj = this.comObj;
|
|
488
|
+
const self = this,
|
|
489
|
+
action = this.actionHandler[data.action];
|
|
490
|
+
const streamSink = {
|
|
491
|
+
enqueue(chunk, size = 1, transfers) {
|
|
492
|
+
if (this.isCancelled) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const lastDesiredSize = this.desiredSize;
|
|
496
|
+
this.desiredSize -= size;
|
|
497
|
+
// Enqueue decreases the desiredSize property of sink,
|
|
498
|
+
// so when it changes from positive to negative,
|
|
499
|
+
// set ready as unresolved promise.
|
|
500
|
+
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
|
501
|
+
this.sinkCapability = Promise.withResolvers();
|
|
502
|
+
this.ready = this.sinkCapability.promise;
|
|
503
|
+
}
|
|
504
|
+
comObj.postMessage({
|
|
505
|
+
sourceName,
|
|
506
|
+
targetName,
|
|
507
|
+
stream: StreamKind.ENQUEUE,
|
|
508
|
+
streamId,
|
|
509
|
+
chunk
|
|
510
|
+
}, transfers);
|
|
511
|
+
},
|
|
512
|
+
close() {
|
|
513
|
+
if (this.isCancelled) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
this.isCancelled = true;
|
|
517
|
+
comObj.postMessage({
|
|
518
|
+
sourceName,
|
|
519
|
+
targetName,
|
|
520
|
+
stream: StreamKind.CLOSE,
|
|
521
|
+
streamId
|
|
522
|
+
});
|
|
523
|
+
delete self.streamSinks[streamId];
|
|
524
|
+
},
|
|
525
|
+
error(reason) {
|
|
526
|
+
assert(reason instanceof Error, "error must have a valid reason");
|
|
527
|
+
if (this.isCancelled) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
this.isCancelled = true;
|
|
531
|
+
comObj.postMessage({
|
|
532
|
+
sourceName,
|
|
533
|
+
targetName,
|
|
534
|
+
stream: StreamKind.ERROR,
|
|
535
|
+
streamId,
|
|
536
|
+
reason: wrapReason(reason)
|
|
537
|
+
});
|
|
538
|
+
},
|
|
539
|
+
sinkCapability: Promise.withResolvers(),
|
|
540
|
+
onPull: null,
|
|
541
|
+
onCancel: null,
|
|
542
|
+
isCancelled: false,
|
|
543
|
+
desiredSize: data.desiredSize,
|
|
544
|
+
ready: null
|
|
545
|
+
};
|
|
546
|
+
streamSink.sinkCapability.resolve();
|
|
547
|
+
streamSink.ready = streamSink.sinkCapability.promise;
|
|
548
|
+
this.streamSinks[streamId] = streamSink;
|
|
549
|
+
new Promise(function (resolve) {
|
|
550
|
+
resolve(action(data.data, streamSink));
|
|
551
|
+
}).then(function () {
|
|
552
|
+
comObj.postMessage({
|
|
553
|
+
sourceName,
|
|
554
|
+
targetName,
|
|
555
|
+
stream: StreamKind.START_COMPLETE,
|
|
556
|
+
streamId,
|
|
557
|
+
success: true
|
|
558
|
+
});
|
|
559
|
+
}, function (reason) {
|
|
560
|
+
comObj.postMessage({
|
|
561
|
+
sourceName,
|
|
562
|
+
targetName,
|
|
563
|
+
stream: StreamKind.START_COMPLETE,
|
|
564
|
+
streamId,
|
|
565
|
+
reason: wrapReason(reason)
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
#processStreamMessage(data) {
|
|
570
|
+
const streamId = data.streamId,
|
|
571
|
+
sourceName = this.sourceName,
|
|
572
|
+
targetName = data.sourceName,
|
|
573
|
+
comObj = this.comObj;
|
|
574
|
+
const streamController = this.streamControllers[streamId],
|
|
575
|
+
streamSink = this.streamSinks[streamId];
|
|
576
|
+
switch (data.stream) {
|
|
577
|
+
case StreamKind.START_COMPLETE:
|
|
578
|
+
if (data.success) {
|
|
579
|
+
streamController.startCall.resolve();
|
|
580
|
+
} else {
|
|
581
|
+
streamController.startCall.reject(wrapReason(data.reason));
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
case StreamKind.PULL_COMPLETE:
|
|
585
|
+
if (data.success) {
|
|
586
|
+
streamController.pullCall.resolve();
|
|
587
|
+
} else {
|
|
588
|
+
streamController.pullCall.reject(wrapReason(data.reason));
|
|
589
|
+
}
|
|
590
|
+
break;
|
|
591
|
+
case StreamKind.PULL:
|
|
592
|
+
// Ignore any pull after close is called.
|
|
593
|
+
if (!streamSink) {
|
|
594
|
+
comObj.postMessage({
|
|
595
|
+
sourceName,
|
|
596
|
+
targetName,
|
|
597
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
598
|
+
streamId,
|
|
599
|
+
success: true
|
|
600
|
+
});
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
// Pull increases the desiredSize property of sink, so when it changes
|
|
604
|
+
// from negative to positive, set ready property as resolved promise.
|
|
605
|
+
if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
|
|
606
|
+
streamSink.sinkCapability.resolve();
|
|
607
|
+
}
|
|
608
|
+
// Reset desiredSize property of sink on every pull.
|
|
609
|
+
streamSink.desiredSize = data.desiredSize;
|
|
610
|
+
new Promise(function (resolve) {
|
|
611
|
+
var _streamSink$onPull;
|
|
612
|
+
resolve((_streamSink$onPull = streamSink.onPull) === null || _streamSink$onPull === void 0 ? void 0 : _streamSink$onPull.call(streamSink));
|
|
613
|
+
}).then(function () {
|
|
614
|
+
comObj.postMessage({
|
|
615
|
+
sourceName,
|
|
616
|
+
targetName,
|
|
617
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
618
|
+
streamId,
|
|
619
|
+
success: true
|
|
620
|
+
});
|
|
621
|
+
}, function (reason) {
|
|
622
|
+
comObj.postMessage({
|
|
623
|
+
sourceName,
|
|
624
|
+
targetName,
|
|
625
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
626
|
+
streamId,
|
|
627
|
+
reason: wrapReason(reason)
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
break;
|
|
631
|
+
case StreamKind.ENQUEUE:
|
|
632
|
+
assert(streamController, "enqueue should have stream controller");
|
|
633
|
+
if (streamController.isClosed) {
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
streamController.controller.enqueue(data.chunk);
|
|
637
|
+
break;
|
|
638
|
+
case StreamKind.CLOSE:
|
|
639
|
+
assert(streamController, "close should have stream controller");
|
|
640
|
+
if (streamController.isClosed) {
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
streamController.isClosed = true;
|
|
644
|
+
streamController.controller.close();
|
|
645
|
+
this.#deleteStreamController(streamController, streamId);
|
|
646
|
+
break;
|
|
647
|
+
case StreamKind.ERROR:
|
|
648
|
+
assert(streamController, "error should have stream controller");
|
|
649
|
+
streamController.controller.error(wrapReason(data.reason));
|
|
650
|
+
this.#deleteStreamController(streamController, streamId);
|
|
651
|
+
break;
|
|
652
|
+
case StreamKind.CANCEL_COMPLETE:
|
|
653
|
+
if (data.success) {
|
|
654
|
+
streamController.cancelCall.resolve();
|
|
655
|
+
} else {
|
|
656
|
+
streamController.cancelCall.reject(wrapReason(data.reason));
|
|
657
|
+
}
|
|
658
|
+
this.#deleteStreamController(streamController, streamId);
|
|
659
|
+
break;
|
|
660
|
+
case StreamKind.CANCEL:
|
|
661
|
+
if (!streamSink) {
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
new Promise(function (resolve) {
|
|
665
|
+
var _streamSink$onCancel;
|
|
666
|
+
resolve((_streamSink$onCancel = streamSink.onCancel) === null || _streamSink$onCancel === void 0 ? void 0 : _streamSink$onCancel.call(streamSink, wrapReason(data.reason)));
|
|
667
|
+
}).then(function () {
|
|
668
|
+
comObj.postMessage({
|
|
669
|
+
sourceName,
|
|
670
|
+
targetName,
|
|
671
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
|
672
|
+
streamId,
|
|
673
|
+
success: true
|
|
674
|
+
});
|
|
675
|
+
}, function (reason) {
|
|
676
|
+
comObj.postMessage({
|
|
677
|
+
sourceName,
|
|
678
|
+
targetName,
|
|
679
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
|
680
|
+
streamId,
|
|
681
|
+
reason: wrapReason(reason)
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
streamSink.sinkCapability.reject(wrapReason(data.reason));
|
|
685
|
+
streamSink.isCancelled = true;
|
|
686
|
+
delete this.streamSinks[streamId];
|
|
687
|
+
break;
|
|
688
|
+
default:
|
|
689
|
+
throw new Error("Unexpected stream case");
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
async #deleteStreamController(streamController, streamId) {
|
|
693
|
+
var _streamController$sta, _streamController$pul, _streamController$can;
|
|
694
|
+
// Delete the `streamController` only when the start, pull, and cancel
|
|
695
|
+
// capabilities have settled, to prevent `TypeError`s.
|
|
696
|
+
await Promise.allSettled([(_streamController$sta = streamController.startCall) === null || _streamController$sta === void 0 ? void 0 : _streamController$sta.promise, (_streamController$pul = streamController.pullCall) === null || _streamController$pul === void 0 ? void 0 : _streamController$pul.promise, (_streamController$can = streamController.cancelCall) === null || _streamController$can === void 0 ? void 0 : _streamController$can.promise]);
|
|
697
|
+
delete this.streamControllers[streamId];
|
|
698
|
+
}
|
|
699
|
+
destroy() {
|
|
700
|
+
this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export { MurmurHash3_64 as M, MessageHandler as a, convertToRGBA as b, convertBlackAndWhiteToRGBA as c, grayToRGBA as g };
|