@embedpdf/engines 1.0.11 → 1.0.13

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