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