@chialab/pdfjs-lib 1.0.0-alpha.16 → 1.0.0-alpha.18
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/dist/browser/index.js
CHANGED
|
@@ -25868,7 +25868,9 @@ PDFPageProxy.prototype.getAnnotations = async function(params) {
|
|
|
25868
25868
|
|
|
25869
25869
|
// src/lib/WasmFactory.ts
|
|
25870
25870
|
var WasmFactory = class {
|
|
25871
|
-
async fetch({
|
|
25871
|
+
async fetch({
|
|
25872
|
+
filename
|
|
25873
|
+
}) {
|
|
25872
25874
|
switch (filename) {
|
|
25873
25875
|
case "openjpeg.wasm":
|
|
25874
25876
|
return import("./openjpeg-K2XBCFFN.js").then(
|
|
@@ -25894,7 +25896,9 @@ var StandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
|
|
25894
25896
|
* Fetch the corresponding standard font data.
|
|
25895
25897
|
* We need to use specific dynamic imports for each font file for the bundler to include them.
|
|
25896
25898
|
*/
|
|
25897
|
-
async fetch({
|
|
25899
|
+
async fetch({
|
|
25900
|
+
filename
|
|
25901
|
+
}) {
|
|
25898
25902
|
switch (filename) {
|
|
25899
25903
|
case "FoxitDingbats.pfb":
|
|
25900
25904
|
return import("./FoxitDingbats-SB6TO3S5.js").then((module) => module.default);
|
|
@@ -26195,14 +26199,16 @@ async function createTextLayer(page, {
|
|
|
26195
26199
|
};
|
|
26196
26200
|
const getCanvasContext = async (inputLang = null) => {
|
|
26197
26201
|
const lang = inputLang || "";
|
|
26198
|
-
let
|
|
26199
|
-
if (!
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26202
|
+
let canvasAndContext = canvasCache.get(lang);
|
|
26203
|
+
if (!canvasAndContext) {
|
|
26204
|
+
canvasAndContext = await canvasFactory.create(
|
|
26205
|
+
100,
|
|
26206
|
+
100
|
|
26207
|
+
);
|
|
26208
|
+
canvasAndContext.canvas.lang = lang;
|
|
26209
|
+
canvasCache.set(lang, canvasAndContext);
|
|
26210
|
+
}
|
|
26211
|
+
return canvasAndContext.context;
|
|
26206
26212
|
};
|
|
26207
26213
|
const getAscent = (fontFamily) => {
|
|
26208
26214
|
const cachedAscent = ascentCache.get(fontFamily);
|
|
@@ -26386,54 +26392,55 @@ async function createTextLayer(page, {
|
|
|
26386
26392
|
if (!id) {
|
|
26387
26393
|
return;
|
|
26388
26394
|
}
|
|
26389
|
-
|
|
26390
|
-
|
|
26391
|
-
|
|
26392
|
-
|
|
26393
|
-
|
|
26394
|
-
if (!imgData?.bitmap && !imgData?.data) {
|
|
26395
|
-
return;
|
|
26396
|
-
}
|
|
26397
|
-
const { context } = await canvasFactory.create(
|
|
26398
|
-
imgData.width,
|
|
26399
|
-
imgData.height
|
|
26400
|
-
);
|
|
26401
|
-
if (imgData.bitmap) {
|
|
26402
|
-
context.drawImage(imgData.bitmap, 0, 0);
|
|
26403
|
-
} else if (imgData.data) {
|
|
26404
|
-
if (imgData.kind === ImageKind.RGB_24BPP) {
|
|
26405
|
-
const rgbaArray = new Uint8ClampedArray(
|
|
26406
|
-
imgData.width * imgData.height * 4
|
|
26407
|
-
);
|
|
26408
|
-
for (let i = 0, j = 0; i < imgData.data.length; i += 3, j += 4) {
|
|
26409
|
-
rgbaArray[j] = imgData.data[i];
|
|
26410
|
-
rgbaArray[j + 1] = imgData.data[i + 1];
|
|
26411
|
-
rgbaArray[j + 2] = imgData.data[i + 2];
|
|
26412
|
-
rgbaArray[j + 3] = 255;
|
|
26395
|
+
await Promise.all(
|
|
26396
|
+
getMarkedObjects(id).map(async (imageId) => {
|
|
26397
|
+
const imgData = getObject(imageId);
|
|
26398
|
+
if (!imgData?.bitmap && !imgData?.data) {
|
|
26399
|
+
return;
|
|
26413
26400
|
}
|
|
26414
|
-
const
|
|
26415
|
-
rgbaArray,
|
|
26401
|
+
const canvasAndContext = await canvasFactory.create(
|
|
26416
26402
|
imgData.width,
|
|
26417
26403
|
imgData.height
|
|
26418
26404
|
);
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
imgData.
|
|
26423
|
-
|
|
26424
|
-
|
|
26405
|
+
if (imgData.bitmap) {
|
|
26406
|
+
canvasAndContext.context.drawImage(imgData.bitmap, 0, 0);
|
|
26407
|
+
} else if (imgData.data) {
|
|
26408
|
+
if (imgData.kind === ImageKind.RGB_24BPP) {
|
|
26409
|
+
const rgbaArray = new Uint8ClampedArray(
|
|
26410
|
+
imgData.width * imgData.height * 4
|
|
26411
|
+
);
|
|
26412
|
+
for (let i = 0, j = 0; i < imgData.data.length; i += 3, j += 4) {
|
|
26413
|
+
rgbaArray[j] = imgData.data[i];
|
|
26414
|
+
rgbaArray[j + 1] = imgData.data[i + 1];
|
|
26415
|
+
rgbaArray[j + 2] = imgData.data[i + 2];
|
|
26416
|
+
rgbaArray[j + 3] = 255;
|
|
26417
|
+
}
|
|
26418
|
+
const imageData = new ImageData(
|
|
26419
|
+
rgbaArray,
|
|
26420
|
+
imgData.width,
|
|
26421
|
+
imgData.height
|
|
26422
|
+
);
|
|
26423
|
+
canvasAndContext.context.putImageData(imageData, 0, 0);
|
|
26424
|
+
} else {
|
|
26425
|
+
const imageData = new ImageData(
|
|
26426
|
+
imgData.data,
|
|
26427
|
+
imgData.width,
|
|
26428
|
+
imgData.height
|
|
26429
|
+
);
|
|
26430
|
+
canvasAndContext.context.putImageData(imageData, 0, 0);
|
|
26431
|
+
}
|
|
26432
|
+
}
|
|
26433
|
+
const imgSrc = await toDataUrl(
|
|
26434
|
+
await canvasToData(canvasAndContext.canvas)
|
|
26425
26435
|
);
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
|
|
26436
|
+
canvasFactory.destroy(canvasAndContext);
|
|
26437
|
+
const img = {
|
|
26438
|
+
role: "img",
|
|
26439
|
+
src: imgSrc
|
|
26440
|
+
};
|
|
26441
|
+
parent.children.push(img);
|
|
26442
|
+
})
|
|
26431
26443
|
);
|
|
26432
|
-
const img = {
|
|
26433
|
-
role: "img",
|
|
26434
|
-
src: imgSrc
|
|
26435
|
-
};
|
|
26436
|
-
parent.children.push(img);
|
|
26437
26444
|
}
|
|
26438
26445
|
})
|
|
26439
26446
|
);
|
|
@@ -26464,12 +26471,16 @@ async function createTextLayer(page, {
|
|
|
26464
26471
|
parent.children.push(span.node);
|
|
26465
26472
|
}
|
|
26466
26473
|
};
|
|
26467
|
-
const
|
|
26474
|
+
const getMarkedObjects = (markedContentId) => {
|
|
26475
|
+
const results = [];
|
|
26468
26476
|
let currentMarkedContent = null;
|
|
26469
26477
|
for (let i = 0; i < operatorList.fnArray.length; i++) {
|
|
26470
26478
|
const fnId = operatorList.fnArray[i];
|
|
26471
26479
|
const args = operatorList.argsArray[i];
|
|
26472
26480
|
if (fnId === OPS.endMarkedContent) {
|
|
26481
|
+
if (currentMarkedContent === markedContentId) {
|
|
26482
|
+
return results;
|
|
26483
|
+
}
|
|
26473
26484
|
currentMarkedContent = null;
|
|
26474
26485
|
continue;
|
|
26475
26486
|
}
|
|
@@ -26481,10 +26492,10 @@ async function createTextLayer(page, {
|
|
|
26481
26492
|
continue;
|
|
26482
26493
|
}
|
|
26483
26494
|
if (fnId === OPS.paintImageXObject) {
|
|
26484
|
-
|
|
26495
|
+
results.push(args[0]);
|
|
26485
26496
|
}
|
|
26486
26497
|
}
|
|
26487
|
-
return
|
|
26498
|
+
return results;
|
|
26488
26499
|
};
|
|
26489
26500
|
await loadDefaultFonts();
|
|
26490
26501
|
const reader = textContentSource.getReader();
|
|
@@ -26501,6 +26512,9 @@ async function createTextLayer(page, {
|
|
|
26501
26512
|
root?.children.map((child) => renderStructTreeNode(child, rootContainer)) ?? []
|
|
26502
26513
|
);
|
|
26503
26514
|
ascentCache.clear();
|
|
26515
|
+
for (const canvasAndContext of canvasCache.values()) {
|
|
26516
|
+
canvasFactory.destroy(canvasAndContext);
|
|
26517
|
+
}
|
|
26504
26518
|
canvasCache.clear();
|
|
26505
26519
|
return rootContainer;
|
|
26506
26520
|
}
|
|
@@ -123,7 +123,7 @@ export interface FileAttachmentAnnotationData extends TextAnnotationData {
|
|
|
123
123
|
subtype: 'FileAttachment';
|
|
124
124
|
file: {
|
|
125
125
|
filename: string;
|
|
126
|
-
content?: Uint8Array | null;
|
|
126
|
+
content?: Uint8Array<ArrayBuffer> | null;
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
export interface SoundAnnotationData extends TextAnnotationData {
|
|
@@ -8,7 +8,7 @@ export declare class StandardFontDataFactory extends BaseStandardFontDataFactory
|
|
|
8
8
|
* Fetch the corresponding standard font data.
|
|
9
9
|
* We need to use specific dynamic imports for each font file for the bundler to include them.
|
|
10
10
|
*/
|
|
11
|
-
fetch({ filename }: {
|
|
11
|
+
fetch({ filename, }: {
|
|
12
12
|
filename: string;
|
|
13
|
-
}): Promise<Uint8Array
|
|
13
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
14
14
|
}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import type { Canvas } from '@napi-rs/canvas';
|
|
2
|
+
export type CanvasAndContext = {
|
|
3
|
+
canvas: HTMLCanvasElement;
|
|
4
|
+
context: CanvasRenderingContext2D;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Convert a canvas to a buffer.
|
|
4
8
|
* @param canvas The canvas to convert.
|
|
5
9
|
* @returns A promise that resolves to the buffer.
|
|
6
10
|
*/
|
|
7
|
-
export declare function canvasToData(canvas: HTMLCanvasElement | Canvas): Promise<Uint8Array
|
|
11
|
+
export declare function canvasToData(canvas: HTMLCanvasElement | Canvas): Promise<Uint8Array<ArrayBuffer>>;
|
|
8
12
|
/**
|
|
9
13
|
* Convert a buffer to a data url.
|
|
10
14
|
* @param data The buffer to convert.
|
|
11
15
|
* @param type The type of the data url. Defaults to 'image/png'.
|
|
12
16
|
* @returns A promise that resolves to the data url.
|
|
13
17
|
*/
|
|
14
|
-
export declare function toDataUrl(data: Uint8Array
|
|
18
|
+
export declare function toDataUrl(data: Uint8Array<ArrayBuffer>, type?: string): Promise<string>;
|
|
15
19
|
/**
|
|
16
20
|
* Ensure the object can be serialized and unserialized as JSON.
|
|
17
21
|
* Internally it converts typed arrays to plain arrays.
|
package/dist/node/index.js
CHANGED
|
@@ -26475,7 +26475,9 @@ PDFPageProxy.prototype.getAnnotations = async function(params) {
|
|
|
26475
26475
|
|
|
26476
26476
|
// src/lib/WasmFactory.ts
|
|
26477
26477
|
var WasmFactory = class {
|
|
26478
|
-
async fetch({
|
|
26478
|
+
async fetch({
|
|
26479
|
+
filename
|
|
26480
|
+
}) {
|
|
26479
26481
|
switch (filename) {
|
|
26480
26482
|
case "openjpeg.wasm":
|
|
26481
26483
|
return import("./openjpeg-B2WN24QZ.js").then(
|
|
@@ -26501,7 +26503,9 @@ var StandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
|
|
26501
26503
|
* Fetch the corresponding standard font data.
|
|
26502
26504
|
* We need to use specific dynamic imports for each font file for the bundler to include them.
|
|
26503
26505
|
*/
|
|
26504
|
-
async fetch({
|
|
26506
|
+
async fetch({
|
|
26507
|
+
filename
|
|
26508
|
+
}) {
|
|
26505
26509
|
switch (filename) {
|
|
26506
26510
|
case "FoxitDingbats.pfb":
|
|
26507
26511
|
return import("./FoxitDingbats-65AZ2Z2V.js").then((module) => module.default);
|
|
@@ -26802,14 +26806,16 @@ async function createTextLayer(page, {
|
|
|
26802
26806
|
};
|
|
26803
26807
|
const getCanvasContext = async (inputLang = null) => {
|
|
26804
26808
|
const lang = inputLang || "";
|
|
26805
|
-
let
|
|
26806
|
-
if (!
|
|
26807
|
-
|
|
26808
|
-
|
|
26809
|
-
|
|
26810
|
-
|
|
26811
|
-
|
|
26812
|
-
|
|
26809
|
+
let canvasAndContext = canvasCache.get(lang);
|
|
26810
|
+
if (!canvasAndContext) {
|
|
26811
|
+
canvasAndContext = await canvasFactory.create(
|
|
26812
|
+
100,
|
|
26813
|
+
100
|
|
26814
|
+
);
|
|
26815
|
+
canvasAndContext.canvas.lang = lang;
|
|
26816
|
+
canvasCache.set(lang, canvasAndContext);
|
|
26817
|
+
}
|
|
26818
|
+
return canvasAndContext.context;
|
|
26813
26819
|
};
|
|
26814
26820
|
const getAscent = (fontFamily) => {
|
|
26815
26821
|
const cachedAscent = ascentCache.get(fontFamily);
|
|
@@ -26993,54 +26999,55 @@ async function createTextLayer(page, {
|
|
|
26993
26999
|
if (!id) {
|
|
26994
27000
|
return;
|
|
26995
27001
|
}
|
|
26996
|
-
|
|
26997
|
-
|
|
26998
|
-
|
|
26999
|
-
|
|
27000
|
-
|
|
27001
|
-
if (!imgData?.bitmap && !imgData?.data) {
|
|
27002
|
-
return;
|
|
27003
|
-
}
|
|
27004
|
-
const { context } = await canvasFactory.create(
|
|
27005
|
-
imgData.width,
|
|
27006
|
-
imgData.height
|
|
27007
|
-
);
|
|
27008
|
-
if (imgData.bitmap) {
|
|
27009
|
-
context.drawImage(imgData.bitmap, 0, 0);
|
|
27010
|
-
} else if (imgData.data) {
|
|
27011
|
-
if (imgData.kind === ImageKind.RGB_24BPP) {
|
|
27012
|
-
const rgbaArray = new Uint8ClampedArray(
|
|
27013
|
-
imgData.width * imgData.height * 4
|
|
27014
|
-
);
|
|
27015
|
-
for (let i = 0, j = 0; i < imgData.data.length; i += 3, j += 4) {
|
|
27016
|
-
rgbaArray[j] = imgData.data[i];
|
|
27017
|
-
rgbaArray[j + 1] = imgData.data[i + 1];
|
|
27018
|
-
rgbaArray[j + 2] = imgData.data[i + 2];
|
|
27019
|
-
rgbaArray[j + 3] = 255;
|
|
27002
|
+
await Promise.all(
|
|
27003
|
+
getMarkedObjects(id).map(async (imageId) => {
|
|
27004
|
+
const imgData = getObject(imageId);
|
|
27005
|
+
if (!imgData?.bitmap && !imgData?.data) {
|
|
27006
|
+
return;
|
|
27020
27007
|
}
|
|
27021
|
-
const
|
|
27022
|
-
rgbaArray,
|
|
27008
|
+
const canvasAndContext = await canvasFactory.create(
|
|
27023
27009
|
imgData.width,
|
|
27024
27010
|
imgData.height
|
|
27025
27011
|
);
|
|
27026
|
-
|
|
27027
|
-
|
|
27028
|
-
|
|
27029
|
-
imgData.
|
|
27030
|
-
|
|
27031
|
-
|
|
27012
|
+
if (imgData.bitmap) {
|
|
27013
|
+
canvasAndContext.context.drawImage(imgData.bitmap, 0, 0);
|
|
27014
|
+
} else if (imgData.data) {
|
|
27015
|
+
if (imgData.kind === ImageKind.RGB_24BPP) {
|
|
27016
|
+
const rgbaArray = new Uint8ClampedArray(
|
|
27017
|
+
imgData.width * imgData.height * 4
|
|
27018
|
+
);
|
|
27019
|
+
for (let i = 0, j = 0; i < imgData.data.length; i += 3, j += 4) {
|
|
27020
|
+
rgbaArray[j] = imgData.data[i];
|
|
27021
|
+
rgbaArray[j + 1] = imgData.data[i + 1];
|
|
27022
|
+
rgbaArray[j + 2] = imgData.data[i + 2];
|
|
27023
|
+
rgbaArray[j + 3] = 255;
|
|
27024
|
+
}
|
|
27025
|
+
const imageData = new ImageData(
|
|
27026
|
+
rgbaArray,
|
|
27027
|
+
imgData.width,
|
|
27028
|
+
imgData.height
|
|
27029
|
+
);
|
|
27030
|
+
canvasAndContext.context.putImageData(imageData, 0, 0);
|
|
27031
|
+
} else {
|
|
27032
|
+
const imageData = new ImageData(
|
|
27033
|
+
imgData.data,
|
|
27034
|
+
imgData.width,
|
|
27035
|
+
imgData.height
|
|
27036
|
+
);
|
|
27037
|
+
canvasAndContext.context.putImageData(imageData, 0, 0);
|
|
27038
|
+
}
|
|
27039
|
+
}
|
|
27040
|
+
const imgSrc = await toDataUrl(
|
|
27041
|
+
await canvasToData(canvasAndContext.canvas)
|
|
27032
27042
|
);
|
|
27033
|
-
|
|
27034
|
-
|
|
27035
|
-
|
|
27036
|
-
|
|
27037
|
-
|
|
27043
|
+
canvasFactory.destroy(canvasAndContext);
|
|
27044
|
+
const img = {
|
|
27045
|
+
role: "img",
|
|
27046
|
+
src: imgSrc
|
|
27047
|
+
};
|
|
27048
|
+
parent.children.push(img);
|
|
27049
|
+
})
|
|
27038
27050
|
);
|
|
27039
|
-
const img = {
|
|
27040
|
-
role: "img",
|
|
27041
|
-
src: imgSrc
|
|
27042
|
-
};
|
|
27043
|
-
parent.children.push(img);
|
|
27044
27051
|
}
|
|
27045
27052
|
})
|
|
27046
27053
|
);
|
|
@@ -27071,12 +27078,16 @@ async function createTextLayer(page, {
|
|
|
27071
27078
|
parent.children.push(span.node);
|
|
27072
27079
|
}
|
|
27073
27080
|
};
|
|
27074
|
-
const
|
|
27081
|
+
const getMarkedObjects = (markedContentId) => {
|
|
27082
|
+
const results = [];
|
|
27075
27083
|
let currentMarkedContent = null;
|
|
27076
27084
|
for (let i = 0; i < operatorList.fnArray.length; i++) {
|
|
27077
27085
|
const fnId = operatorList.fnArray[i];
|
|
27078
27086
|
const args = operatorList.argsArray[i];
|
|
27079
27087
|
if (fnId === OPS.endMarkedContent) {
|
|
27088
|
+
if (currentMarkedContent === markedContentId) {
|
|
27089
|
+
return results;
|
|
27090
|
+
}
|
|
27080
27091
|
currentMarkedContent = null;
|
|
27081
27092
|
continue;
|
|
27082
27093
|
}
|
|
@@ -27088,10 +27099,10 @@ async function createTextLayer(page, {
|
|
|
27088
27099
|
continue;
|
|
27089
27100
|
}
|
|
27090
27101
|
if (fnId === OPS.paintImageXObject) {
|
|
27091
|
-
|
|
27102
|
+
results.push(args[0]);
|
|
27092
27103
|
}
|
|
27093
27104
|
}
|
|
27094
|
-
return
|
|
27105
|
+
return results;
|
|
27095
27106
|
};
|
|
27096
27107
|
await loadDefaultFonts();
|
|
27097
27108
|
const reader = textContentSource.getReader();
|
|
@@ -27108,6 +27119,9 @@ async function createTextLayer(page, {
|
|
|
27108
27119
|
root?.children.map((child) => renderStructTreeNode(child, rootContainer)) ?? []
|
|
27109
27120
|
);
|
|
27110
27121
|
ascentCache.clear();
|
|
27122
|
+
for (const canvasAndContext of canvasCache.values()) {
|
|
27123
|
+
canvasFactory.destroy(canvasAndContext);
|
|
27124
|
+
}
|
|
27111
27125
|
canvasCache.clear();
|
|
27112
27126
|
return rootContainer;
|
|
27113
27127
|
}
|
package/package.json
CHANGED