@chialab/pdfjs-lib 1.0.0-alpha.20 → 1.0.0-alpha.22
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/NodeUtilsStabs-MUAXKISB.js +19 -0
- package/dist/browser/chunk-3ZTAZS2X.js +25 -0
- package/dist/browser/{chunk-NJUB3B5A.js → chunk-W3YEFTNG.js} +785 -3
- package/dist/browser/index.js +1147 -80
- package/dist/browser/worker.js +10 -12
- package/dist/lib/NodeUtils.d.ts +24 -0
- package/dist/lib/SvgCanvasContext.d.ts +2 -0
- package/dist/node/NodeUtils-EDBNTTIR.js +20 -0
- package/dist/node/{chunk-3XZOTLLE.js → chunk-K6VD27AD.js} +269 -68
- package/dist/node/index.js +28 -196
- package/dist/pdf.js/src/display/api.d.ts +1 -1
- package/dist/pdf.js/src/display/cmap_reader_factory.d.ts +25 -0
- package/dist/pdf.js/src/display/wasm_factory.d.ts +20 -0
- package/package.json +1 -1
- package/dist/browser/NodeCanvasFactory-ONRE5YYL.js +0 -58
- package/dist/browser/chunk-5IWODJWD.js +0 -801
- package/dist/browser/chunk-ELOUEWKT.js +0 -1142
- package/dist/node/NodeCanvasFactory-YRBSQ5MH.js +0 -8
package/dist/node/index.js
CHANGED
|
@@ -6,10 +6,17 @@ import {
|
|
|
6
6
|
wrapReason
|
|
7
7
|
} from "./chunk-ZKUTXCS2.js";
|
|
8
8
|
import {
|
|
9
|
+
BaseStandardFontDataFactory,
|
|
10
|
+
DOMCMapReaderFactory,
|
|
9
11
|
DOMCanvasFactory,
|
|
10
12
|
DOMFilterFactory,
|
|
13
|
+
DOMStandardFontDataFactory,
|
|
14
|
+
DOMWasmFactory,
|
|
15
|
+
NodeCMapReaderFactory,
|
|
11
16
|
NodeCanvasFactory,
|
|
12
17
|
NodeFilterFactory,
|
|
18
|
+
NodeStandardFontDataFactory,
|
|
19
|
+
NodeWasmFactory,
|
|
13
20
|
OutputScale,
|
|
14
21
|
PDFDateString,
|
|
15
22
|
PageViewport,
|
|
@@ -39,7 +46,7 @@ import {
|
|
|
39
46
|
setLayerDimensions,
|
|
40
47
|
stopEvent,
|
|
41
48
|
toDataUrl
|
|
42
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-K6VD27AD.js";
|
|
43
50
|
import {
|
|
44
51
|
AbortException,
|
|
45
52
|
AnnotationBorderStyleType,
|
|
@@ -5799,197 +5806,6 @@ var LoopbackPort = class {
|
|
|
5799
5806
|
_listeners = new WeakMap();
|
|
5800
5807
|
_deferred = new WeakMap();
|
|
5801
5808
|
|
|
5802
|
-
// src/lib/NodeUtils.ts
|
|
5803
|
-
import {
|
|
5804
|
-
DOMMatrix as NodeDOMMatrix,
|
|
5805
|
-
DOMPoint as NodeDOMPoint,
|
|
5806
|
-
ImageData as NodeImageData,
|
|
5807
|
-
Path2D as NodePath2D
|
|
5808
|
-
} from "skia-canvas";
|
|
5809
|
-
|
|
5810
|
-
// src/pdf.js/src/display/cmap_reader_factory.js
|
|
5811
|
-
var BaseCMapReaderFactory = class {
|
|
5812
|
-
constructor({ baseUrl = null, isCompressed = true }) {
|
|
5813
|
-
if (false) {
|
|
5814
|
-
unreachable("Cannot initialize BaseCMapReaderFactory.");
|
|
5815
|
-
}
|
|
5816
|
-
this.baseUrl = baseUrl;
|
|
5817
|
-
this.isCompressed = isCompressed;
|
|
5818
|
-
}
|
|
5819
|
-
async fetch({ name }) {
|
|
5820
|
-
if (!this.baseUrl) {
|
|
5821
|
-
throw new Error(
|
|
5822
|
-
"Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided."
|
|
5823
|
-
);
|
|
5824
|
-
}
|
|
5825
|
-
if (!name) {
|
|
5826
|
-
throw new Error("CMap name must be specified.");
|
|
5827
|
-
}
|
|
5828
|
-
const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
|
|
5829
|
-
return this._fetch(url).then((cMapData) => ({ cMapData, isCompressed: this.isCompressed })).catch((reason) => {
|
|
5830
|
-
throw new Error(
|
|
5831
|
-
`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`
|
|
5832
|
-
);
|
|
5833
|
-
});
|
|
5834
|
-
}
|
|
5835
|
-
/**
|
|
5836
|
-
* @ignore
|
|
5837
|
-
* @returns {Promise<Uint8Array>}
|
|
5838
|
-
*/
|
|
5839
|
-
async _fetch(url) {
|
|
5840
|
-
unreachable("Abstract method `_fetch` called.");
|
|
5841
|
-
}
|
|
5842
|
-
};
|
|
5843
|
-
var DOMCMapReaderFactory = class extends BaseCMapReaderFactory {
|
|
5844
|
-
/**
|
|
5845
|
-
* @ignore
|
|
5846
|
-
*/
|
|
5847
|
-
async _fetch(url) {
|
|
5848
|
-
const data = await fetchData(
|
|
5849
|
-
url,
|
|
5850
|
-
/* type = */
|
|
5851
|
-
this.isCompressed ? "arraybuffer" : "text"
|
|
5852
|
-
);
|
|
5853
|
-
return data instanceof ArrayBuffer ? new Uint8Array(data) : stringToBytes(data);
|
|
5854
|
-
}
|
|
5855
|
-
};
|
|
5856
|
-
|
|
5857
|
-
// src/pdf.js/src/display/standard_fontdata_factory.js
|
|
5858
|
-
var BaseStandardFontDataFactory = class {
|
|
5859
|
-
constructor({ baseUrl = null }) {
|
|
5860
|
-
if (false) {
|
|
5861
|
-
unreachable("Cannot initialize BaseStandardFontDataFactory.");
|
|
5862
|
-
}
|
|
5863
|
-
this.baseUrl = baseUrl;
|
|
5864
|
-
}
|
|
5865
|
-
async fetch({ filename }) {
|
|
5866
|
-
if (!this.baseUrl) {
|
|
5867
|
-
throw new Error(
|
|
5868
|
-
"Ensure that the `standardFontDataUrl` API parameter is provided."
|
|
5869
|
-
);
|
|
5870
|
-
}
|
|
5871
|
-
if (!filename) {
|
|
5872
|
-
throw new Error("Font filename must be specified.");
|
|
5873
|
-
}
|
|
5874
|
-
const url = `${this.baseUrl}${filename}`;
|
|
5875
|
-
return this._fetch(url).catch((reason) => {
|
|
5876
|
-
throw new Error(`Unable to load font data at: ${url}`);
|
|
5877
|
-
});
|
|
5878
|
-
}
|
|
5879
|
-
/**
|
|
5880
|
-
* @ignore
|
|
5881
|
-
* @returns {Promise<Uint8Array>}
|
|
5882
|
-
*/
|
|
5883
|
-
async _fetch(url) {
|
|
5884
|
-
unreachable("Abstract method `_fetch` called.");
|
|
5885
|
-
}
|
|
5886
|
-
};
|
|
5887
|
-
var DOMStandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
|
5888
|
-
/**
|
|
5889
|
-
* @ignore
|
|
5890
|
-
*/
|
|
5891
|
-
async _fetch(url) {
|
|
5892
|
-
const data = await fetchData(
|
|
5893
|
-
url,
|
|
5894
|
-
/* type = */
|
|
5895
|
-
"arraybuffer"
|
|
5896
|
-
);
|
|
5897
|
-
return new Uint8Array(data);
|
|
5898
|
-
}
|
|
5899
|
-
};
|
|
5900
|
-
|
|
5901
|
-
// src/pdf.js/src/display/wasm_factory.js
|
|
5902
|
-
var BaseWasmFactory = class {
|
|
5903
|
-
constructor({ baseUrl = null }) {
|
|
5904
|
-
if (false) {
|
|
5905
|
-
unreachable("Cannot initialize BaseWasmFactory.");
|
|
5906
|
-
}
|
|
5907
|
-
this.baseUrl = baseUrl;
|
|
5908
|
-
}
|
|
5909
|
-
async fetch({ filename }) {
|
|
5910
|
-
if (!this.baseUrl) {
|
|
5911
|
-
throw new Error("Ensure that the `wasmUrl` API parameter is provided.");
|
|
5912
|
-
}
|
|
5913
|
-
if (!filename) {
|
|
5914
|
-
throw new Error("Wasm filename must be specified.");
|
|
5915
|
-
}
|
|
5916
|
-
const url = `${this.baseUrl}${filename}`;
|
|
5917
|
-
return this._fetch(url).catch((reason) => {
|
|
5918
|
-
throw new Error(`Unable to load wasm data at: ${url}`);
|
|
5919
|
-
});
|
|
5920
|
-
}
|
|
5921
|
-
/**
|
|
5922
|
-
* @ignore
|
|
5923
|
-
* @returns {Promise<Uint8Array>}
|
|
5924
|
-
*/
|
|
5925
|
-
async _fetch(url) {
|
|
5926
|
-
unreachable("Abstract method `_fetch` called.");
|
|
5927
|
-
}
|
|
5928
|
-
};
|
|
5929
|
-
var DOMWasmFactory = class extends BaseWasmFactory {
|
|
5930
|
-
/**
|
|
5931
|
-
* @ignore
|
|
5932
|
-
*/
|
|
5933
|
-
async _fetch(url) {
|
|
5934
|
-
const data = await fetchData(
|
|
5935
|
-
url,
|
|
5936
|
-
/* type = */
|
|
5937
|
-
"arraybuffer"
|
|
5938
|
-
);
|
|
5939
|
-
return new Uint8Array(data);
|
|
5940
|
-
}
|
|
5941
|
-
};
|
|
5942
|
-
|
|
5943
|
-
// src/lib/NodeUtils.ts
|
|
5944
|
-
if (!globalThis.DOMMatrix) {
|
|
5945
|
-
globalThis.DOMMatrix = NodeDOMMatrix;
|
|
5946
|
-
}
|
|
5947
|
-
if (!globalThis.DOMPoint) {
|
|
5948
|
-
globalThis.DOMPoint = NodeDOMPoint;
|
|
5949
|
-
}
|
|
5950
|
-
if (!globalThis.ImageData) {
|
|
5951
|
-
globalThis.ImageData = NodeImageData;
|
|
5952
|
-
}
|
|
5953
|
-
if (!globalThis.Path2D) {
|
|
5954
|
-
globalThis.Path2D = NodePath2D;
|
|
5955
|
-
}
|
|
5956
|
-
if (!globalThis.navigator?.language) {
|
|
5957
|
-
globalThis.navigator = {
|
|
5958
|
-
language: "en-US",
|
|
5959
|
-
platform: "",
|
|
5960
|
-
userAgent: ""
|
|
5961
|
-
};
|
|
5962
|
-
}
|
|
5963
|
-
async function fetchData2(url) {
|
|
5964
|
-
const { readFile } = await import("node:fs/promises");
|
|
5965
|
-
const data = await readFile(url);
|
|
5966
|
-
return new Uint8Array(data);
|
|
5967
|
-
}
|
|
5968
|
-
var NodeCMapReaderFactory = class extends BaseCMapReaderFactory {
|
|
5969
|
-
/**
|
|
5970
|
-
* @ignore
|
|
5971
|
-
*/
|
|
5972
|
-
async _fetch(url) {
|
|
5973
|
-
return fetchData2(url);
|
|
5974
|
-
}
|
|
5975
|
-
};
|
|
5976
|
-
var NodeStandardFontDataFactory = class extends BaseStandardFontDataFactory {
|
|
5977
|
-
/**
|
|
5978
|
-
* @ignore
|
|
5979
|
-
*/
|
|
5980
|
-
async _fetch(url) {
|
|
5981
|
-
return fetchData2(url);
|
|
5982
|
-
}
|
|
5983
|
-
};
|
|
5984
|
-
var NodeWasmFactory = class extends BaseWasmFactory {
|
|
5985
|
-
/**
|
|
5986
|
-
* @ignore
|
|
5987
|
-
*/
|
|
5988
|
-
async _fetch(url) {
|
|
5989
|
-
return fetchData2(url);
|
|
5990
|
-
}
|
|
5991
|
-
};
|
|
5992
|
-
|
|
5993
5809
|
// src/pdf.js/src/display/pattern_helper.js
|
|
5994
5810
|
var PathType = {
|
|
5995
5811
|
FILL: "Fill",
|
|
@@ -24346,7 +24162,7 @@ var SvgCanvasContext = class {
|
|
|
24346
24162
|
constructor(width, height, canvas) {
|
|
24347
24163
|
__publicField(this, "_width");
|
|
24348
24164
|
__publicField(this, "_height");
|
|
24349
|
-
__publicField(this, "_canvas");
|
|
24165
|
+
__publicField(this, "_canvas", null);
|
|
24350
24166
|
__publicField(this, "_ctx", null);
|
|
24351
24167
|
__publicField(this, "_currentStyle", {
|
|
24352
24168
|
strokeStyle: "#000000",
|
|
@@ -24405,6 +24221,9 @@ var SvgCanvasContext = class {
|
|
|
24405
24221
|
this.resetTransform();
|
|
24406
24222
|
}
|
|
24407
24223
|
get canvas() {
|
|
24224
|
+
if (!this._canvas) {
|
|
24225
|
+
throw new Error("Canvas is destroyed");
|
|
24226
|
+
}
|
|
24408
24227
|
return this._canvas;
|
|
24409
24228
|
}
|
|
24410
24229
|
get fillStyle() {
|
|
@@ -24503,8 +24322,8 @@ var SvgCanvasContext = class {
|
|
|
24503
24322
|
resize(width, height) {
|
|
24504
24323
|
this._width = width;
|
|
24505
24324
|
this._height = height;
|
|
24506
|
-
this.
|
|
24507
|
-
this.
|
|
24325
|
+
this.canvas.width = width;
|
|
24326
|
+
this.canvas.height = height;
|
|
24508
24327
|
this._root.attrs.width = width;
|
|
24509
24328
|
this._root.attrs.height = height;
|
|
24510
24329
|
}
|
|
@@ -25230,6 +25049,13 @@ var SvgCanvasContext = class {
|
|
|
25230
25049
|
this._groupStack = [];
|
|
25231
25050
|
this._parents.clear();
|
|
25232
25051
|
}
|
|
25052
|
+
destroy() {
|
|
25053
|
+
this._clearCanvas();
|
|
25054
|
+
this.canvas.width = 0;
|
|
25055
|
+
this.canvas.height = 0;
|
|
25056
|
+
this._ctx = null;
|
|
25057
|
+
this._canvas = null;
|
|
25058
|
+
}
|
|
25233
25059
|
};
|
|
25234
25060
|
async function createSvgContext(width, height) {
|
|
25235
25061
|
const canvas = await createCanvas(width, height);
|
|
@@ -25248,10 +25074,15 @@ async function toSvgNode(ctx) {
|
|
|
25248
25074
|
async function toSvgString(ctx) {
|
|
25249
25075
|
return renderSvgNode(await toSvgNode(ctx));
|
|
25250
25076
|
}
|
|
25077
|
+
function destroySvgContext(ctx) {
|
|
25078
|
+
if (ctx instanceof SvgCanvasContext) {
|
|
25079
|
+
ctx.destroy();
|
|
25080
|
+
}
|
|
25081
|
+
}
|
|
25251
25082
|
|
|
25252
25083
|
// src/lib/PDFPageProxy.ts
|
|
25253
25084
|
async function loadNodeCanvasFactory() {
|
|
25254
|
-
const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./
|
|
25085
|
+
const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtils-EDBNTTIR.js");
|
|
25255
25086
|
return new NodeCanvasFactory2({});
|
|
25256
25087
|
}
|
|
25257
25088
|
var getAnnotations = PDFPageProxy.prototype.getAnnotations;
|
|
@@ -26099,6 +25930,7 @@ export {
|
|
|
26099
25930
|
createSvgContext,
|
|
26100
25931
|
createTextLayer,
|
|
26101
25932
|
createValidAbsoluteUrl,
|
|
25933
|
+
destroySvgContext,
|
|
26102
25934
|
fetchData,
|
|
26103
25935
|
getDocument,
|
|
26104
25936
|
getFilenameFromUrl,
|
|
@@ -21,7 +21,7 @@ export type DocumentInitParameters = {
|
|
|
21
21
|
* worker-thread. This will help reduce main-thread memory usage, however
|
|
22
22
|
* it will take ownership of the TypedArrays.
|
|
23
23
|
*/
|
|
24
|
-
data?: string | number[] |
|
|
24
|
+
data?: string | ArrayBuffer | number[] | TypedArray | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* - Basic authentication headers.
|
|
27
27
|
*/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class BaseCMapReaderFactory {
|
|
2
|
+
constructor({ baseUrl, isCompressed }: {
|
|
3
|
+
baseUrl?: null | undefined;
|
|
4
|
+
isCompressed?: boolean | undefined;
|
|
5
|
+
});
|
|
6
|
+
baseUrl: any;
|
|
7
|
+
isCompressed: boolean;
|
|
8
|
+
fetch({ name }: {
|
|
9
|
+
name: any;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
cMapData: Uint8Array<ArrayBufferLike>;
|
|
12
|
+
isCompressed: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* @ignore
|
|
16
|
+
* @returns {Promise<Uint8Array>}
|
|
17
|
+
*/
|
|
18
|
+
_fetch(url: any): Promise<Uint8Array>;
|
|
19
|
+
}
|
|
20
|
+
export class DOMCMapReaderFactory extends BaseCMapReaderFactory {
|
|
21
|
+
/**
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
_fetch(url: any): Promise<Uint8Array<any>>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class BaseWasmFactory {
|
|
2
|
+
constructor({ baseUrl }: {
|
|
3
|
+
baseUrl?: null | undefined;
|
|
4
|
+
});
|
|
5
|
+
baseUrl: any;
|
|
6
|
+
fetch({ filename }: {
|
|
7
|
+
filename: any;
|
|
8
|
+
}): Promise<Uint8Array<ArrayBufferLike>>;
|
|
9
|
+
/**
|
|
10
|
+
* @ignore
|
|
11
|
+
* @returns {Promise<Uint8Array>}
|
|
12
|
+
*/
|
|
13
|
+
_fetch(url: any): Promise<Uint8Array>;
|
|
14
|
+
}
|
|
15
|
+
export class DOMWasmFactory extends BaseWasmFactory {
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
|
+
_fetch(url: any): Promise<Uint8Array<any>>;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseCanvasFactory
|
|
3
|
-
} from "./chunk-ELOUEWKT.js";
|
|
4
|
-
import "./chunk-NJUB3B5A.js";
|
|
5
|
-
import "./chunk-O4UKW7AD.js";
|
|
6
|
-
|
|
7
|
-
// src/lib/NodeCanvasFactory.ts
|
|
8
|
-
import { Canvas } from "skia-canvas";
|
|
9
|
-
|
|
10
|
-
// src/lib/NodeFilterFactory.ts
|
|
11
|
-
var filtersRegistry = /* @__PURE__ */ new Map();
|
|
12
|
-
|
|
13
|
-
// src/lib/NodeCanvasFactory.ts
|
|
14
|
-
var NodeCanvasFactory = class extends BaseCanvasFactory {
|
|
15
|
-
_createCanvas(width, height) {
|
|
16
|
-
return new Canvas(width, height);
|
|
17
|
-
}
|
|
18
|
-
create(width, height) {
|
|
19
|
-
const factory = this;
|
|
20
|
-
const { canvas, context } = super.create(width, height);
|
|
21
|
-
const drawImage = context.drawImage;
|
|
22
|
-
let currentFilter = "none";
|
|
23
|
-
Object.defineProperty(context, "filter", {
|
|
24
|
-
get() {
|
|
25
|
-
if (currentFilter.startsWith("url(")) {
|
|
26
|
-
return "none";
|
|
27
|
-
}
|
|
28
|
-
return currentFilter;
|
|
29
|
-
},
|
|
30
|
-
set(value) {
|
|
31
|
-
currentFilter = value;
|
|
32
|
-
},
|
|
33
|
-
configurable: true
|
|
34
|
-
});
|
|
35
|
-
context.drawImage = function(src, ...args) {
|
|
36
|
-
const filter = filtersRegistry.get(currentFilter);
|
|
37
|
-
if (!filter) {
|
|
38
|
-
drawImage.call(this, src, ...args);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const { canvas: canvas2, context: context2 } = factory.create(src.width, src.height);
|
|
42
|
-
context2.drawImage(src, 0, 0, src.width, src.height);
|
|
43
|
-
filter(context2);
|
|
44
|
-
drawImage.call(this, canvas2, ...args);
|
|
45
|
-
factory.destroy({
|
|
46
|
-
canvas: canvas2,
|
|
47
|
-
context: context2
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
canvas,
|
|
52
|
-
context
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
export {
|
|
57
|
-
NodeCanvasFactory
|
|
58
|
-
};
|