@embedpdf/engines 1.0.10 → 1.0.12

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.
Files changed (104) hide show
  1. package/dist/engine-B7CS6Qyp.cjs +2 -0
  2. package/dist/engine-B7CS6Qyp.cjs.map +1 -0
  3. package/dist/engine-M0_XZhss.js +5043 -0
  4. package/dist/engine-M0_XZhss.js.map +1 -0
  5. package/dist/index.cjs +1 -5846
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +1 -1613
  8. package/dist/index.js +339 -5824
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/converters/index.cjs +2 -0
  11. package/dist/lib/converters/index.cjs.map +1 -0
  12. package/dist/{converters.d.ts → lib/converters/index.d.ts} +7 -10
  13. package/dist/lib/converters/index.js +80 -0
  14. package/dist/{converters.cjs.map → lib/converters/index.js.map} +1 -1
  15. package/dist/lib/index.d.ts +7 -0
  16. package/dist/lib/mock/index.d.ts +25 -0
  17. package/dist/lib/pdfium/cache.d.ts +62 -0
  18. package/dist/{pdfium-direct-engine.d.ts → lib/pdfium/engine.d.ts} +73 -8
  19. package/dist/lib/pdfium/helper.d.ts +21 -0
  20. package/dist/lib/pdfium/index.cjs +2 -0
  21. package/dist/lib/pdfium/index.cjs.map +1 -0
  22. package/dist/lib/pdfium/index.d.ts +3 -0
  23. package/dist/lib/pdfium/index.js +13 -0
  24. package/dist/lib/pdfium/index.js.map +1 -0
  25. package/dist/lib/pdfium/runner.d.ts +16 -0
  26. package/dist/lib/pdfium/web/direct-engine.cjs +2 -0
  27. package/dist/lib/pdfium/web/direct-engine.cjs.map +1 -0
  28. package/dist/lib/pdfium/web/direct-engine.d.ts +3 -0
  29. package/dist/lib/pdfium/web/direct-engine.js +12 -0
  30. package/dist/lib/pdfium/web/direct-engine.js.map +1 -0
  31. package/dist/lib/pdfium/web/worker-engine.cjs +2 -0
  32. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -0
  33. package/dist/lib/pdfium/web/worker-engine.d.ts +7 -0
  34. package/dist/lib/pdfium/web/worker-engine.js +15 -0
  35. package/dist/lib/pdfium/web/worker-engine.js.map +1 -0
  36. package/dist/lib/pdfium/worker.d.ts +1 -0
  37. package/dist/lib/pdfium-engine.d.ts +1 -0
  38. package/dist/lib/webworker/engine.cjs +2 -0
  39. package/dist/lib/webworker/engine.cjs.map +1 -0
  40. package/dist/{worker.d.ts → lib/webworker/engine.d.ts} +4 -34
  41. package/dist/lib/webworker/engine.js +887 -0
  42. package/dist/lib/webworker/engine.js.map +1 -0
  43. package/dist/lib/webworker/index.d.ts +2 -0
  44. package/dist/lib/webworker/runner.d.ts +128 -0
  45. package/dist/lib/webworker-engine.d.ts +1 -0
  46. package/dist/preact/adapter.d.ts +1 -0
  47. package/dist/preact/index.cjs +2 -0
  48. package/dist/preact/index.cjs.map +1 -0
  49. package/dist/preact/index.d.ts +1 -0
  50. package/dist/preact/index.js +37 -0
  51. package/dist/preact/index.js.map +1 -0
  52. package/dist/react/adapter.d.ts +1 -0
  53. package/dist/react/index.cjs +2 -0
  54. package/dist/react/index.cjs.map +1 -0
  55. package/dist/react/index.d.ts +1 -0
  56. package/dist/react/index.js +37 -0
  57. package/dist/react/index.js.map +1 -0
  58. package/dist/runner-BcS-WEof.cjs +2 -0
  59. package/dist/runner-BcS-WEof.cjs.map +1 -0
  60. package/dist/runner-DUp_7Uu_.js +269 -0
  61. package/dist/runner-DUp_7Uu_.js.map +1 -0
  62. package/dist/shared-preact/hooks/index.d.ts +1 -0
  63. package/dist/{preact.d.ts → shared-preact/hooks/use-pdfium-engine.d.ts} +3 -5
  64. package/dist/shared-preact/index.d.ts +1 -0
  65. package/dist/shared-react/hooks/index.d.ts +1 -0
  66. package/dist/{react.d.ts → shared-react/hooks/use-pdfium-engine.d.ts} +3 -5
  67. package/dist/shared-react/index.d.ts +1 -0
  68. package/dist/vue/hooks/index.d.ts +1 -0
  69. package/dist/vue/hooks/use-pdfium-engine.d.ts +18 -0
  70. package/dist/vue/index.cjs +2 -0
  71. package/dist/vue/index.cjs.map +1 -0
  72. package/dist/vue/index.d.ts +1 -0
  73. package/dist/vue/index.js +39 -0
  74. package/dist/vue/index.js.map +1 -0
  75. package/package.json +41 -41
  76. package/dist/converters.cjs +0 -139
  77. package/dist/converters.js +0 -133
  78. package/dist/converters.js.map +0 -1
  79. package/dist/pdfium-direct-engine.cjs +0 -4400
  80. package/dist/pdfium-direct-engine.cjs.map +0 -1
  81. package/dist/pdfium-direct-engine.js +0 -4398
  82. package/dist/pdfium-direct-engine.js.map +0 -1
  83. package/dist/pdfium-worker-engine.cjs +0 -851
  84. package/dist/pdfium-worker-engine.cjs.map +0 -1
  85. package/dist/pdfium-worker-engine.d.ts +0 -314
  86. package/dist/pdfium-worker-engine.js +0 -849
  87. package/dist/pdfium-worker-engine.js.map +0 -1
  88. package/dist/pdfium.cjs +0 -4667
  89. package/dist/pdfium.cjs.map +0 -1
  90. package/dist/pdfium.d.ts +0 -1311
  91. package/dist/pdfium.js +0 -4661
  92. package/dist/pdfium.js.map +0 -1
  93. package/dist/preact.cjs +0 -41
  94. package/dist/preact.cjs.map +0 -1
  95. package/dist/preact.js +0 -39
  96. package/dist/preact.js.map +0 -1
  97. package/dist/react.cjs +0 -41
  98. package/dist/react.cjs.map +0 -1
  99. package/dist/react.js +0 -39
  100. package/dist/react.js.map +0 -1
  101. package/dist/worker.cjs +0 -839
  102. package/dist/worker.cjs.map +0 -1
  103. package/dist/worker.js +0 -836
  104. package/dist/worker.js.map +0 -1
package/dist/worker.js DELETED
@@ -1,836 +0,0 @@
1
- import { Task, NoopLogger, PdfErrorCode } from '@embedpdf/models';
2
-
3
- const LOG_SOURCE = 'WebWorkerEngine';
4
- const LOG_CATEGORY = 'Engine';
5
- /**
6
- * Task that executed by webworker
7
- */
8
- class WorkerTask extends Task {
9
- /**
10
- * Create a task that bind to web worker with specified message id
11
- * @param worker - web worker instance
12
- * @param messageId - id of message
13
- *
14
- * @public
15
- */
16
- constructor(worker, messageId) {
17
- super();
18
- this.worker = worker;
19
- this.messageId = messageId;
20
- }
21
- /**
22
- * {@inheritDoc @embedpdf/models!Task.abort}
23
- *
24
- * @override
25
- */
26
- abort(e) {
27
- super.abort(e);
28
- this.worker.postMessage({
29
- type: 'AbortRequest',
30
- data: {
31
- messageId: this.messageId,
32
- },
33
- });
34
- }
35
- }
36
- /**
37
- * PDF engine that runs within webworker
38
- */
39
- class WebWorkerEngine {
40
- /**
41
- * Create an instance of WebWorkerEngine, it will create a worker with
42
- * specified url.
43
- * @param worker - webworker instance, this worker needs to contains the running instance of {@link EngineRunner}
44
- * @param logger - logger instance
45
- *
46
- * @public
47
- */
48
- constructor(worker, logger = new NoopLogger()) {
49
- this.worker = worker;
50
- this.logger = logger;
51
- /**
52
- * All the tasks that is executing
53
- */
54
- this.tasks = new Map();
55
- /**
56
- * Handle event from web worker. There are 2 kinds of event
57
- * 1. ReadyResponse: web worker is ready
58
- * 2. ExecuteResponse: result of execution
59
- * @param evt - message event from web worker
60
- * @returns
61
- *
62
- * @private
63
- */
64
- this.handle = (evt) => {
65
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'webworker engine start handling message: ', evt.data);
66
- try {
67
- const response = evt.data;
68
- const task = this.tasks.get(response.id);
69
- if (!task) {
70
- return;
71
- }
72
- switch (response.type) {
73
- case 'ReadyResponse':
74
- this.readyTask.resolve(true);
75
- break;
76
- case 'ExecuteResponse':
77
- {
78
- switch (response.data.type) {
79
- case 'result':
80
- task.resolve(response.data.value);
81
- break;
82
- case 'error':
83
- task.reject(response.data.value.reason);
84
- break;
85
- }
86
- this.tasks.delete(response.id);
87
- }
88
- break;
89
- }
90
- }
91
- catch (e) {
92
- this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'webworker met error when handling message: ', e);
93
- }
94
- };
95
- this.worker.addEventListener('message', this.handle);
96
- this.readyTask = new WorkerTask(this.worker, WebWorkerEngine.readyTaskId);
97
- this.tasks.set(WebWorkerEngine.readyTaskId, this.readyTask);
98
- }
99
- /**
100
- * Generate a unique message id
101
- * @returns message id
102
- *
103
- * @private
104
- */
105
- generateRequestId(id) {
106
- return `${id}.${Date.now()}.${Math.random()}`;
107
- }
108
- /**
109
- * {@inheritDoc @embedpdf/models!PdfEngine.initialize}
110
- *
111
- * @public
112
- */
113
- initialize() {
114
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'initialize');
115
- const requestId = this.generateRequestId('General');
116
- const task = new WorkerTask(this.worker, requestId);
117
- const request = {
118
- id: requestId,
119
- type: 'ExecuteRequest',
120
- data: {
121
- name: 'initialize',
122
- args: [],
123
- },
124
- };
125
- this.proxy(task, request);
126
- return task;
127
- }
128
- /**
129
- * {@inheritDoc @embedpdf/models!PdfEngine.destroy}
130
- *
131
- * @public
132
- */
133
- destroy() {
134
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'destroy');
135
- const requestId = this.generateRequestId('General');
136
- const task = new WorkerTask(this.worker, requestId);
137
- const finish = () => {
138
- this.worker.removeEventListener('message', this.handle);
139
- this.worker.terminate();
140
- };
141
- task.wait(finish, finish);
142
- const request = {
143
- id: requestId,
144
- type: 'ExecuteRequest',
145
- data: {
146
- name: 'destroy',
147
- args: [],
148
- },
149
- };
150
- this.proxy(task, request);
151
- return task;
152
- }
153
- /**
154
- * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentUrl}
155
- *
156
- * @public
157
- */
158
- openDocumentUrl(file, options) {
159
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentUrl', file.url, options);
160
- const requestId = this.generateRequestId(file.id);
161
- const task = new WorkerTask(this.worker, requestId);
162
- const request = {
163
- id: requestId,
164
- type: 'ExecuteRequest',
165
- data: {
166
- name: 'openDocumentUrl',
167
- args: [file, options],
168
- },
169
- };
170
- this.proxy(task, request);
171
- return task;
172
- }
173
- /**
174
- * {@inheritDoc @embedpdf/models!PdfEngine.openDocument}
175
- *
176
- * @public
177
- */
178
- openDocumentFromBuffer(file, password) {
179
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentFromBuffer', file, password);
180
- const requestId = this.generateRequestId(file.id);
181
- const task = new WorkerTask(this.worker, requestId);
182
- const request = {
183
- id: requestId,
184
- type: 'ExecuteRequest',
185
- data: {
186
- name: 'openDocumentFromBuffer',
187
- args: [file, password],
188
- },
189
- };
190
- this.proxy(task, request);
191
- return task;
192
- }
193
- /**
194
- * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentFromLoader}
195
- *
196
- * @public
197
- */
198
- openDocumentFromLoader(file, password) {
199
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentFromLoader', file, password);
200
- const requestId = this.generateRequestId(file.id);
201
- const task = new WorkerTask(this.worker, requestId);
202
- const request = {
203
- id: requestId,
204
- type: 'ExecuteRequest',
205
- data: {
206
- name: 'openDocumentFromLoader',
207
- args: [file, password],
208
- },
209
- };
210
- this.proxy(task, request);
211
- return task;
212
- }
213
- /**
214
- * {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
215
- *
216
- * @public
217
- */
218
- getMetadata(doc) {
219
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getMetadata', doc);
220
- const requestId = this.generateRequestId(doc.id);
221
- const task = new WorkerTask(this.worker, requestId);
222
- const request = {
223
- id: requestId,
224
- type: 'ExecuteRequest',
225
- data: {
226
- name: 'getMetadata',
227
- args: [doc],
228
- },
229
- };
230
- this.proxy(task, request);
231
- return task;
232
- }
233
- updateAnnotationColor(doc, page, annotation, color, which = 0) {
234
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'setAnnotationColor', doc, page, annotation, color);
235
- const requestId = this.generateRequestId(doc.id);
236
- const task = new WorkerTask(this.worker, requestId);
237
- const request = {
238
- id: requestId,
239
- type: 'ExecuteRequest',
240
- data: {
241
- name: 'updateAnnotationColor',
242
- args: [doc, page, annotation, color, which],
243
- },
244
- };
245
- this.proxy(task, request);
246
- return task;
247
- }
248
- /**
249
- * {@inheritDoc @embedpdf/models!PdfEngine.getDocPermissions}
250
- *
251
- * @public
252
- */
253
- getDocPermissions(doc) {
254
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getDocPermissions', doc);
255
- const requestId = this.generateRequestId(doc.id);
256
- const task = new WorkerTask(this.worker, requestId);
257
- const request = {
258
- id: requestId,
259
- type: 'ExecuteRequest',
260
- data: {
261
- name: 'getDocPermissions',
262
- args: [doc],
263
- },
264
- };
265
- this.proxy(task, request);
266
- return task;
267
- }
268
- /**
269
- * {@inheritDoc @embedpdf/models!PdfEngine.getDocUserPermissions}
270
- *
271
- * @public
272
- */
273
- getDocUserPermissions(doc) {
274
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getDocUserPermissions', doc);
275
- const requestId = this.generateRequestId(doc.id);
276
- const task = new WorkerTask(this.worker, requestId);
277
- const request = {
278
- id: requestId,
279
- type: 'ExecuteRequest',
280
- data: {
281
- name: 'getDocUserPermissions',
282
- args: [doc],
283
- },
284
- };
285
- this.proxy(task, request);
286
- return task;
287
- }
288
- /**
289
- * {@inheritDoc @embedpdf/models!PdfEngine.getBookmarks}
290
- *
291
- * @public
292
- */
293
- getBookmarks(doc) {
294
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getBookmarks', doc);
295
- const requestId = this.generateRequestId(doc.id);
296
- const task = new WorkerTask(this.worker, requestId);
297
- const request = {
298
- id: requestId,
299
- type: 'ExecuteRequest',
300
- data: {
301
- name: 'getBookmarks',
302
- args: [doc],
303
- },
304
- };
305
- this.proxy(task, request);
306
- return task;
307
- }
308
- /**
309
- * {@inheritDoc @embedpdf/models!PdfEngine.getSignatures}
310
- *
311
- * @public
312
- */
313
- getSignatures(doc) {
314
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getSignatures', doc);
315
- const requestId = this.generateRequestId(doc.id);
316
- const task = new WorkerTask(this.worker, requestId);
317
- const request = {
318
- id: requestId,
319
- type: 'ExecuteRequest',
320
- data: {
321
- name: 'getSignatures',
322
- args: [doc],
323
- },
324
- };
325
- this.proxy(task, request);
326
- return task;
327
- }
328
- /**
329
- * {@inheritDoc @embedpdf/models!PdfEngine.renderPage}
330
- *
331
- * @public
332
- */
333
- renderPage(doc, page, scaleFactor, rotation, dpr, options, imageType = 'image/webp') {
334
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPage', doc, page, scaleFactor, rotation, dpr, options);
335
- const requestId = this.generateRequestId(doc.id);
336
- const task = new WorkerTask(this.worker, requestId);
337
- const request = {
338
- id: requestId,
339
- type: 'ExecuteRequest',
340
- data: {
341
- name: 'renderPage',
342
- args: [doc, page, scaleFactor, rotation, dpr, options, imageType],
343
- },
344
- };
345
- this.proxy(task, request);
346
- return task;
347
- }
348
- /**
349
- * {@inheritDoc @embedpdf/models!PdfEngine.renderPageRect}
350
- *
351
- * @public
352
- */
353
- renderPageRect(doc, page, scaleFactor, rotation, dpr, rect, options, imageType = 'image/webp') {
354
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPageRect', doc, page, scaleFactor, rotation, dpr, rect, options);
355
- const requestId = this.generateRequestId(doc.id);
356
- const task = new WorkerTask(this.worker, requestId);
357
- const request = {
358
- id: requestId,
359
- type: 'ExecuteRequest',
360
- data: {
361
- name: 'renderPageRect',
362
- args: [doc, page, scaleFactor, rotation, dpr, rect, options, imageType],
363
- },
364
- };
365
- this.proxy(task, request);
366
- return task;
367
- }
368
- /**
369
- * {@inheritDoc @embedpdf/models!PdfEngine.renderAnnotation}
370
- *
371
- * @public
372
- */
373
- renderAnnotation(doc, page, annotation, scaleFactor, rotation, dpr, mode, imageType) {
374
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderAnnotation', doc, page, annotation, scaleFactor, rotation, dpr, mode, imageType);
375
- const requestId = this.generateRequestId(doc.id);
376
- const task = new WorkerTask(this.worker, requestId);
377
- const request = {
378
- id: requestId,
379
- type: 'ExecuteRequest',
380
- data: {
381
- name: 'renderAnnotation',
382
- args: [doc, page, annotation, scaleFactor, rotation, dpr, mode, imageType],
383
- },
384
- };
385
- this.proxy(task, request);
386
- return task;
387
- }
388
- /**
389
- * {@inheritDoc @embedpdf/models!PdfEngine.getAllAnnotations}
390
- *
391
- * @public
392
- */
393
- getAllAnnotations(doc) {
394
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getAllAnnotations', doc);
395
- const requestId = this.generateRequestId(doc.id);
396
- const task = new WorkerTask(this.worker, requestId);
397
- const request = {
398
- id: requestId,
399
- type: 'ExecuteRequest',
400
- data: {
401
- name: 'getAllAnnotations',
402
- args: [doc],
403
- },
404
- };
405
- this.proxy(task, request);
406
- return task;
407
- }
408
- /**
409
- * {@inheritDoc @embedpdf/models!PdfEngine.getPageAnnotations}
410
- *
411
- * @public
412
- */
413
- getPageAnnotations(doc, page) {
414
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageAnnotations', doc, page);
415
- const requestId = this.generateRequestId(doc.id);
416
- const task = new WorkerTask(this.worker, requestId);
417
- const request = {
418
- id: requestId,
419
- type: 'ExecuteRequest',
420
- data: {
421
- name: 'getPageAnnotations',
422
- args: [doc, page],
423
- },
424
- };
425
- this.proxy(task, request);
426
- return task;
427
- }
428
- /**
429
- * {@inheritDoc @embedpdf/models!PdfEngine.createPageAnnotation}
430
- *
431
- * @public
432
- */
433
- createPageAnnotation(doc, page, annotation) {
434
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'createPageAnnotations', doc, page, annotation);
435
- const requestId = this.generateRequestId(doc.id);
436
- const task = new WorkerTask(this.worker, requestId);
437
- const request = {
438
- id: requestId,
439
- type: 'ExecuteRequest',
440
- data: {
441
- name: 'createPageAnnotation',
442
- args: [doc, page, annotation],
443
- },
444
- };
445
- this.proxy(task, request);
446
- return task;
447
- }
448
- updatePageAnnotation(doc, page, annotation) {
449
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'updatePageAnnotation', doc, page, annotation);
450
- const requestId = this.generateRequestId(doc.id);
451
- const task = new WorkerTask(this.worker, requestId);
452
- const request = {
453
- id: requestId,
454
- type: 'ExecuteRequest',
455
- data: {
456
- name: 'updatePageAnnotation',
457
- args: [doc, page, annotation],
458
- },
459
- };
460
- this.proxy(task, request);
461
- return task;
462
- }
463
- /**
464
- * {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
465
- *
466
- * @public
467
- */
468
- removePageAnnotation(doc, page, annotation) {
469
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'removePageAnnotations', doc, page, annotation);
470
- const requestId = this.generateRequestId(doc.id);
471
- const task = new WorkerTask(this.worker, requestId);
472
- const request = {
473
- id: requestId,
474
- type: 'ExecuteRequest',
475
- data: {
476
- name: 'removePageAnnotation',
477
- args: [doc, page, annotation],
478
- },
479
- };
480
- this.proxy(task, request);
481
- return task;
482
- }
483
- /**
484
- * {@inheritDoc @embedpdf/models!PdfEngine.getPageTextRects}
485
- *
486
- * @public
487
- */
488
- getPageTextRects(doc, page, scaleFactor, rotation) {
489
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageTextRects', doc, page, scaleFactor, rotation);
490
- const requestId = this.generateRequestId(doc.id);
491
- const task = new WorkerTask(this.worker, requestId);
492
- const request = {
493
- id: requestId,
494
- type: 'ExecuteRequest',
495
- data: {
496
- name: 'getPageTextRects',
497
- args: [doc, page, scaleFactor, rotation],
498
- },
499
- };
500
- this.proxy(task, request);
501
- return task;
502
- }
503
- /**
504
- * {@inheritDoc @embedpdf/models!PdfEngine.renderThumbnail}
505
- *
506
- * @public
507
- */
508
- renderThumbnail(doc, page, scaleFactor, rotation, dpr) {
509
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderThumbnail', doc, page, scaleFactor, rotation, dpr);
510
- const requestId = this.generateRequestId(doc.id);
511
- const task = new WorkerTask(this.worker, requestId);
512
- const request = {
513
- id: requestId,
514
- type: 'ExecuteRequest',
515
- data: {
516
- name: 'renderThumbnail',
517
- args: [doc, page, scaleFactor, rotation, dpr],
518
- },
519
- };
520
- this.proxy(task, request);
521
- return task;
522
- }
523
- /**
524
- * {@inheritDoc @embedpdf/models!PdfEngine.searchAllPages}
525
- *
526
- * @public
527
- */
528
- searchAllPages(doc, keyword, flags = []) {
529
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'searchAllPages 123', doc, keyword, flags);
530
- const requestId = this.generateRequestId(doc.id);
531
- const task = new WorkerTask(this.worker, requestId);
532
- const request = {
533
- id: requestId,
534
- type: 'ExecuteRequest',
535
- data: {
536
- name: 'searchAllPages',
537
- args: [doc, keyword, flags],
538
- },
539
- };
540
- this.proxy(task, request);
541
- return task;
542
- }
543
- /**
544
- * {@inheritDoc @embedpdf/models!PdfEngine.saveAsCopy}
545
- *
546
- * @public
547
- */
548
- saveAsCopy(doc) {
549
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'saveAsCopy', doc);
550
- const requestId = this.generateRequestId(doc.id);
551
- const task = new WorkerTask(this.worker, requestId);
552
- const request = {
553
- id: requestId,
554
- type: 'ExecuteRequest',
555
- data: {
556
- name: 'saveAsCopy',
557
- args: [doc],
558
- },
559
- };
560
- this.proxy(task, request);
561
- return task;
562
- }
563
- /**
564
- * {@inheritDoc @embedpdf/models!PdfEngine.getAttachments}
565
- *
566
- * @public
567
- */
568
- getAttachments(doc) {
569
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getAttachments', doc);
570
- const requestId = this.generateRequestId(doc.id);
571
- const task = new WorkerTask(this.worker, requestId);
572
- const request = {
573
- id: requestId,
574
- type: 'ExecuteRequest',
575
- data: {
576
- name: 'getAttachments',
577
- args: [doc],
578
- },
579
- };
580
- this.proxy(task, request);
581
- return task;
582
- }
583
- /**
584
- * {@inheritDoc @embedpdf/models!PdfEngine.readAttachmentContent}
585
- *
586
- * @public
587
- */
588
- readAttachmentContent(doc, attachment) {
589
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'readAttachmentContent', doc, attachment);
590
- const requestId = this.generateRequestId(doc.id);
591
- const task = new WorkerTask(this.worker, requestId);
592
- const request = {
593
- id: requestId,
594
- type: 'ExecuteRequest',
595
- data: {
596
- name: 'readAttachmentContent',
597
- args: [doc, attachment],
598
- },
599
- };
600
- this.proxy(task, request);
601
- return task;
602
- }
603
- /**
604
- * {@inheritDoc @embedpdf/models!PdfEngine.setFormFieldValue}
605
- *
606
- * @public
607
- */
608
- setFormFieldValue(doc, page, annotation, value) {
609
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'setFormFieldValue', doc, annotation, value);
610
- const requestId = this.generateRequestId(doc.id);
611
- const task = new WorkerTask(this.worker, requestId);
612
- const request = {
613
- id: requestId,
614
- type: 'ExecuteRequest',
615
- data: {
616
- name: 'setFormFieldValue',
617
- args: [doc, page, annotation, value],
618
- },
619
- };
620
- this.proxy(task, request);
621
- return task;
622
- }
623
- /**
624
- * {@inheritDoc @embedpdf/models!PdfEngine.flattenPage}
625
- *
626
- * @public
627
- */
628
- flattenPage(doc, page, flag) {
629
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'flattenPage', doc, page, flag);
630
- const requestId = this.generateRequestId(doc.id);
631
- const task = new WorkerTask(this.worker, requestId);
632
- const request = {
633
- id: requestId,
634
- type: 'ExecuteRequest',
635
- data: {
636
- name: 'flattenPage',
637
- args: [doc, page, flag],
638
- },
639
- };
640
- this.proxy(task, request);
641
- return task;
642
- }
643
- /**
644
- * {@inheritDoc @embedpdf/models!PdfEngine.extractPages}
645
- *
646
- * @public
647
- */
648
- extractPages(doc, pageIndexes) {
649
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'extractPages', doc);
650
- const requestId = this.generateRequestId(doc.id);
651
- const task = new WorkerTask(this.worker, requestId);
652
- const request = {
653
- id: requestId,
654
- type: 'ExecuteRequest',
655
- data: {
656
- name: 'extractPages',
657
- args: [doc, pageIndexes],
658
- },
659
- };
660
- this.proxy(task, request);
661
- return task;
662
- }
663
- /**
664
- * {@inheritDoc @embedpdf/models!PdfEngine.extractText}
665
- *
666
- * @public
667
- */
668
- extractText(doc, pageIndexes) {
669
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'extractText', doc);
670
- const requestId = this.generateRequestId(doc.id);
671
- const task = new WorkerTask(this.worker, requestId);
672
- const request = {
673
- id: requestId,
674
- type: 'ExecuteRequest',
675
- data: {
676
- name: 'extractText',
677
- args: [doc, pageIndexes],
678
- },
679
- };
680
- this.proxy(task, request);
681
- return task;
682
- }
683
- /**
684
- * {@inheritDoc @embedpdf/models!PdfEngine.getTextSlices}
685
- *
686
- * @public
687
- */
688
- getTextSlices(doc, slices) {
689
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getTextSlices', doc, slices);
690
- const requestId = this.generateRequestId(doc.id);
691
- const task = new WorkerTask(this.worker, requestId);
692
- const request = {
693
- id: requestId,
694
- type: 'ExecuteRequest',
695
- data: {
696
- name: 'getTextSlices',
697
- args: [doc, slices],
698
- },
699
- };
700
- this.proxy(task, request);
701
- return task;
702
- }
703
- /**
704
- * {@inheritDoc @embedpdf/models!PdfEngine.getPageGlyphs}
705
- *
706
- * @public
707
- */
708
- getPageGlyphs(doc, page) {
709
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageGlyphs', doc, page);
710
- const requestId = this.generateRequestId(doc.id);
711
- const task = new WorkerTask(this.worker, requestId);
712
- const request = {
713
- id: requestId,
714
- type: 'ExecuteRequest',
715
- data: {
716
- name: 'getPageGlyphs',
717
- args: [doc, page],
718
- },
719
- };
720
- this.proxy(task, request);
721
- return task;
722
- }
723
- /**
724
- * {@inheritDoc @embedpdf/models!PdfEngine.getPageGeometry}
725
- *
726
- * @public
727
- */
728
- getPageGeometry(doc, page) {
729
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageGeometry', doc, page);
730
- const requestId = this.generateRequestId(doc.id);
731
- const task = new WorkerTask(this.worker, requestId);
732
- const request = {
733
- id: requestId,
734
- type: 'ExecuteRequest',
735
- data: {
736
- name: 'getPageGeometry',
737
- args: [doc, page],
738
- },
739
- };
740
- this.proxy(task, request);
741
- return task;
742
- }
743
- /**
744
- * {@inheritDoc @embedpdf/models!PdfEngine.merge}
745
- *
746
- * @public
747
- */
748
- merge(files) {
749
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'merge', files);
750
- const fileIds = files.map((file) => file.id).join('.');
751
- const requestId = this.generateRequestId(fileIds);
752
- const task = new WorkerTask(this.worker, requestId);
753
- const request = {
754
- id: requestId,
755
- type: 'ExecuteRequest',
756
- data: {
757
- name: 'merge',
758
- args: [files],
759
- },
760
- };
761
- this.proxy(task, request);
762
- return task;
763
- }
764
- /**
765
- * {@inheritDoc @embedpdf/models!PdfEngine.mergePages}
766
- *
767
- * @public
768
- */
769
- mergePages(mergeConfigs) {
770
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'mergePages', mergeConfigs);
771
- const requestId = this.generateRequestId(mergeConfigs.map((config) => config.docId).join('.'));
772
- const task = new WorkerTask(this.worker, requestId);
773
- const request = {
774
- id: requestId,
775
- type: 'ExecuteRequest',
776
- data: {
777
- name: 'mergePages',
778
- args: [mergeConfigs],
779
- },
780
- };
781
- this.proxy(task, request);
782
- return task;
783
- }
784
- /**
785
- * {@inheritDoc @embedpdf/models!PdfEngine.closeDocument}
786
- *
787
- * @public
788
- */
789
- closeDocument(doc) {
790
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'closeDocument', doc);
791
- const requestId = this.generateRequestId(doc.id);
792
- const task = new WorkerTask(this.worker, requestId);
793
- const request = {
794
- id: requestId,
795
- type: 'ExecuteRequest',
796
- data: {
797
- name: 'closeDocument',
798
- args: [doc],
799
- },
800
- };
801
- this.proxy(task, request);
802
- return task;
803
- }
804
- /**
805
- * Send the request to webworker inside and register the task
806
- * @param task - task that waiting for the response
807
- * @param request - request that needs send to web worker
808
- * @param transferables - transferables that need to transfer to webworker
809
- * @returns
810
- *
811
- * @internal
812
- */
813
- proxy(task, request, transferables = []) {
814
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'send request to worker', task, request, transferables);
815
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, 'Begin', request.id);
816
- this.readyTask.wait(() => {
817
- this.worker.postMessage(request, transferables);
818
- task.wait(() => {
819
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, 'End', request.id);
820
- }, () => {
821
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, 'End', request.id);
822
- });
823
- this.tasks.set(request.id, task);
824
- }, () => {
825
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, 'End', request.id);
826
- task.reject({
827
- code: PdfErrorCode.Initialization,
828
- message: 'worker initialization failed',
829
- });
830
- });
831
- }
832
- }
833
- WebWorkerEngine.readyTaskId = '0';
834
-
835
- export { WebWorkerEngine, WorkerTask };
836
- //# sourceMappingURL=worker.js.map