@chialab/pdfjs-lib 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +15 -7
- package/dist/browser/NodeUtilsStabs-MUAXKISB.js +19 -0
- package/dist/browser/chunk-3ZTAZS2X.js +25 -0
- package/dist/browser/{chunk-DYHYQ33L.js → chunk-AQCSGHG6.js} +1578 -83
- package/dist/browser/index.js +8181 -4159
- package/dist/browser/openjpeg-QOD5OH7M.js +9 -0
- package/dist/browser/qcms_bg-Q7BRLLZG.js +9 -0
- package/dist/browser/worker.js +8390 -7851
- package/dist/index.d.ts +10 -1
- package/dist/lib/AnnotationData.d.ts +12 -8
- package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
- package/dist/lib/Canvas.d.ts +2 -7
- package/dist/lib/CanvasGraphics.d.ts +1 -0
- package/dist/lib/NodeCanvasFactory.d.ts +9 -0
- package/dist/lib/NodeFilterFactory.d.ts +10 -0
- package/dist/lib/NodeUtils.d.ts +24 -0
- package/dist/lib/Path2D.d.ts +9 -49
- package/dist/lib/StandardFontDataFactory.d.ts +2 -2
- package/dist/lib/StructTreePage.d.ts +5 -0
- package/dist/lib/Svg.d.ts +144 -0
- package/dist/lib/SvgCanvasContext.d.ts +38 -24
- package/dist/lib/TextLayer.d.ts +56 -17
- package/dist/lib/WasmFactory.d.ts +5 -0
- package/dist/lib/utils.d.ts +26 -3
- package/dist/node/NodeUtils-WQF223ZR.js +20 -0
- package/dist/node/chunk-5N6O7ENF.js +2065 -0
- package/dist/node/chunk-QUZQQXZM.js +1225 -0
- package/dist/node/chunk-SW5MJNUM.js +2090 -0
- package/dist/node/index.js +7309 -4996
- package/dist/node/openjpeg-JTQTBXER.js +9 -0
- package/dist/node/qcms_bg-T4RSHPOQ.js +9 -0
- package/dist/node/worker.js +8399 -7858
- package/dist/pdf.js/external/openjpeg/openjpeg.d.ts +2 -0
- package/dist/pdf.js/external/qcms/qcms.d.ts +92 -0
- package/dist/pdf.js/external/qcms/qcms_utils.d.ts +14 -0
- package/dist/pdf.js/src/core/arithmetic_decoder.d.ts +21 -0
- package/dist/pdf.js/src/core/ascii_85_stream.d.ts +8 -0
- package/dist/pdf.js/src/core/ascii_hex_stream.d.ts +8 -0
- package/dist/pdf.js/src/core/base_stream.d.ts +32 -0
- package/dist/pdf.js/src/core/bidi.d.ts +4 -0
- package/dist/pdf.js/src/core/binary_cmap.d.ts +3 -0
- package/dist/pdf.js/src/core/ccitt.d.ts +72 -0
- package/dist/pdf.js/src/core/ccitt_stream.d.ts +9 -0
- package/dist/pdf.js/src/core/cff_font.d.ts +15 -0
- package/dist/pdf.js/src/core/cff_parser.d.ts +166 -0
- package/dist/pdf.js/src/core/charsets.d.ts +3 -0
- package/dist/pdf.js/src/core/cmap.d.ts +37 -0
- package/dist/pdf.js/src/core/colorspace.d.ts +177 -0
- package/dist/pdf.js/src/core/colorspace_utils.d.ts +21 -0
- package/dist/pdf.js/src/core/core_utils.d.ts +140 -0
- package/dist/pdf.js/src/core/decode_stream.d.ts +25 -0
- package/dist/pdf.js/src/core/encodings.d.ts +7 -0
- package/dist/pdf.js/src/core/flate_stream.d.ts +15 -0
- package/dist/pdf.js/src/core/font_renderer.d.ts +34 -0
- package/dist/pdf.js/src/core/fonts.d.ts +98 -0
- package/dist/pdf.js/src/core/fonts_utils.d.ts +32 -0
- package/dist/pdf.js/src/core/glyf.d.ts +44 -0
- package/dist/pdf.js/src/core/glyphlist.d.ts +2 -0
- package/dist/pdf.js/src/core/icc_colorspace.d.ts +22 -0
- package/dist/pdf.js/src/core/jbig2.d.ts +12 -0
- package/dist/pdf.js/src/core/jbig2_stream.d.ts +17 -0
- package/dist/pdf.js/src/core/jpeg_stream.d.ts +25 -0
- package/dist/pdf.js/src/core/jpg.d.ts +62 -0
- package/dist/pdf.js/src/core/jpx.d.ts +35 -0
- package/dist/pdf.js/src/core/jpx_stream.d.ts +17 -0
- package/dist/pdf.js/src/core/lzw_stream.d.ts +21 -0
- package/dist/pdf.js/src/core/metrics.d.ts +2 -0
- package/dist/pdf.js/src/core/name_number_tree.d.ts +21 -0
- package/dist/pdf.js/src/core/opentype_file_builder.d.ts +12 -0
- package/dist/pdf.js/src/core/parser.d.ts +81 -0
- package/dist/pdf.js/src/core/predictor_stream.d.ts +15 -0
- package/dist/pdf.js/src/core/primitives.d.ts +78 -0
- package/dist/pdf.js/src/core/run_length_stream.d.ts +7 -0
- package/dist/pdf.js/src/core/standard_fonts.d.ts +18 -0
- package/dist/pdf.js/src/core/stream.d.ts +21 -0
- package/dist/pdf.js/src/core/struct_tree.d.ts +92 -0
- package/dist/pdf.js/src/core/to_unicode_map.d.ts +21 -0
- package/dist/pdf.js/src/core/type1_font.d.ts +17 -0
- package/dist/pdf.js/src/core/type1_parser.d.ts +29 -0
- package/dist/pdf.js/src/core/unicode.d.ts +5 -0
- package/dist/pdf.js/src/display/annotation_layer.d.ts +35 -5
- package/dist/pdf.js/src/display/annotation_storage.d.ts +3 -8
- package/dist/pdf.js/src/display/api.d.ts +86 -77
- package/dist/pdf.js/src/display/api_utils.d.ts +13 -0
- package/dist/pdf.js/src/display/canvas.d.ts +88 -94
- package/dist/pdf.js/src/display/canvas_dependency_tracker.d.ts +160 -0
- package/dist/pdf.js/src/display/display_utils.d.ts +34 -1
- package/dist/pdf.js/src/display/draw_layer.d.ts +2 -2
- package/dist/pdf.js/src/display/editor/alt_text.d.ts +1 -1
- package/dist/pdf.js/src/display/editor/annotation_editor_layer.d.ts +10 -8
- package/dist/pdf.js/src/display/editor/color_picker.d.ts +20 -1
- package/dist/pdf.js/src/display/editor/comment.d.ts +47 -0
- package/dist/pdf.js/src/display/editor/draw.d.ts +8 -8
- package/dist/pdf.js/src/display/editor/drawers/freedraw.d.ts +4 -3
- package/dist/pdf.js/src/display/editor/drawers/highlight.d.ts +2 -1
- package/dist/pdf.js/src/display/editor/drawers/signaturedraw.d.ts +13 -13
- package/dist/pdf.js/src/display/editor/editor.d.ts +117 -16
- package/dist/pdf.js/src/display/editor/freetext.d.ts +11 -7
- package/dist/pdf.js/src/display/editor/highlight.d.ts +9 -3
- package/dist/pdf.js/src/display/editor/ink.d.ts +6 -0
- package/dist/pdf.js/src/display/editor/signature.d.ts +3 -5
- package/dist/pdf.js/src/display/editor/stamp.d.ts +4 -3
- package/dist/pdf.js/src/display/editor/toolbar.d.ts +8 -3
- package/dist/pdf.js/src/display/editor/tools.d.ts +36 -12
- package/dist/pdf.js/src/display/font_loader.d.ts +27 -1
- package/dist/pdf.js/src/display/metadata.d.ts +1 -2
- package/dist/pdf.js/src/display/optional_content_config.d.ts +1 -1
- package/dist/pdf.js/src/display/pattern_helper.d.ts +6 -4
- package/dist/pdf.js/src/display/pdf_objects.d.ts +40 -0
- package/dist/pdf.js/src/display/text_layer.d.ts +9 -9
- package/dist/pdf.js/src/display/touch_manager.d.ts +5 -1
- package/dist/pdf.js/src/display/worker_options.d.ts +2 -2
- package/dist/pdf.js/src/pdf.d.ts +9 -1
- package/dist/pdf.js/src/shared/obj-bin-transform.d.ts +64 -0
- package/dist/pdf.js/src/shared/scripting_utils.d.ts +2 -0
- package/dist/pdf.js/src/shared/util.d.ts +129 -102
- package/dist/pdf.js/web/comment_manager.d.ts +20 -0
- package/dist/pdf.js/web/interfaces.d.ts +7 -0
- package/dist/pdf.js/web/text_accessibility.d.ts +1 -1
- package/package.json +12 -3
- package/dist/node/chunk-KTTVPO2G.js +0 -1775
- package/dist/pdf.js/src/display/node_utils.d.ts +0 -32
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,18 @@ import './lib/PDFPageProxy';
|
|
|
3
3
|
export type { DocumentInitParameters } from './pdf.js/src/display/api';
|
|
4
4
|
export type { BaseCanvasFactory } from './pdf.js/src/display/canvas_factory';
|
|
5
5
|
export * from './lib/utils';
|
|
6
|
+
export { type SvgRoot, type SvgElement, type SvgImage, type SvgMarkedContent, type SvgPath, type SvgNode, isSvgElement, isSvgImage, isSvgMarkedContent, isSvgPath, isSvgRoot, renderSvgNode, } from './lib/Svg';
|
|
6
7
|
export * from './lib/Canvas';
|
|
8
|
+
export * from './lib/WasmFactory';
|
|
7
9
|
export * from './lib/StandardFontDataFactory';
|
|
8
10
|
export * from './lib/AnnotationData';
|
|
11
|
+
export * from './lib/CanvasGraphics';
|
|
9
12
|
export * from './lib/SvgCanvasContext';
|
|
10
|
-
export
|
|
13
|
+
export { type TextLayerRoot, type TextLayerNode, type TextLayerAnchor, type TextLayerFigure, type TextLayerElement, isTextNode, isAnchorNode, isFigureNode, isElementNode, measure, createTextLayer, renderTextLayer, } from './lib/TextLayer';
|
|
14
|
+
export declare const textLayerUtils: {
|
|
15
|
+
findNode: (root: import(".").TextLayerElement, callback: (node: import(".").TextLayerNode, parent: import(".").TextLayerElement) => boolean | null | undefined) => import(".").TextLayerNode | null;
|
|
16
|
+
findNodes: (node: import(".").TextLayerElement, callback: (node: import(".").TextLayerNode, parent: import(".").TextLayerElement) => boolean | null | undefined) => import(".").TextLayerNode[];
|
|
17
|
+
getNodeContents: (node: import(".").TextLayerNode) => string;
|
|
18
|
+
flattenNodes: (node: import(".").TextLayerNode) => import(".").TextLayerNode[];
|
|
19
|
+
};
|
|
11
20
|
export * from './pdf.js/src/pdf.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
|
|
1
|
+
import type { SvgRoot } from './Svg';
|
|
2
|
+
export type Rect = [number, number, number, number];
|
|
3
|
+
export type Color = [number, number, number];
|
|
4
|
+
export type Dir = 'ltr' | 'rtl';
|
|
5
|
+
export declare enum BorderStyle {
|
|
5
6
|
SOLID = 1,
|
|
6
7
|
DASHED = 2
|
|
7
8
|
}
|
|
8
|
-
declare enum LineEnding {
|
|
9
|
+
export declare enum LineEnding {
|
|
9
10
|
NONE = "None",
|
|
10
11
|
SQUARE = "Square",
|
|
11
12
|
CIRCLE = "Circle",
|
|
@@ -41,6 +42,10 @@ export interface AnnotationData {
|
|
|
41
42
|
str: string;
|
|
42
43
|
dir: Dir;
|
|
43
44
|
};
|
|
45
|
+
contentsObj?: {
|
|
46
|
+
str: string;
|
|
47
|
+
dir: Dir;
|
|
48
|
+
};
|
|
44
49
|
popupRef?: string | null;
|
|
45
50
|
[key: string]: unknown;
|
|
46
51
|
}
|
|
@@ -106,7 +111,7 @@ export interface StrikeOutAnnotationData extends TextAnnotationData {
|
|
|
106
111
|
}
|
|
107
112
|
export interface StampAnnotationData extends TextAnnotationData {
|
|
108
113
|
subtype: 'Stamp';
|
|
109
|
-
graphics:
|
|
114
|
+
graphics: SvgRoot;
|
|
110
115
|
}
|
|
111
116
|
export interface CaretAnnotationData extends TextAnnotationData {
|
|
112
117
|
subtype: 'Caret';
|
|
@@ -122,7 +127,7 @@ export interface FileAttachmentAnnotationData extends TextAnnotationData {
|
|
|
122
127
|
subtype: 'FileAttachment';
|
|
123
128
|
file: {
|
|
124
129
|
filename: string;
|
|
125
|
-
content?: Uint8Array | null;
|
|
130
|
+
content?: Uint8Array<ArrayBuffer> | null;
|
|
126
131
|
};
|
|
127
132
|
}
|
|
128
133
|
export interface SoundAnnotationData extends TextAnnotationData {
|
|
@@ -201,4 +206,3 @@ export declare function isTrapNetAnnotation(annotation: AnnotationData): annotat
|
|
|
201
206
|
export declare function isWatermarkAnnotation(annotation: AnnotationData): annotation is WatermarkAnnotationData;
|
|
202
207
|
export declare function isThreeDAnnotation(annotation: AnnotationData): annotation is ThreeDAnnotationData;
|
|
203
208
|
export declare function isRedactAnnotation(annotation: AnnotationData): annotation is RedactAnnotationData;
|
|
204
|
-
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PDFOperatorList } from '../pdf.js/src/display/api';
|
|
2
|
+
export declare class AnnotationOperatorsList {
|
|
3
|
+
readonly map: Map<string, {
|
|
4
|
+
fn: number;
|
|
5
|
+
args: unknown[];
|
|
6
|
+
}[]>;
|
|
7
|
+
/**
|
|
8
|
+
* The list of operators to be executed.
|
|
9
|
+
* @param operatorList The list of operators to be executed.
|
|
10
|
+
*/
|
|
11
|
+
constructor(operatorList: PDFOperatorList);
|
|
12
|
+
/**
|
|
13
|
+
* Get the list of operators for the given annotation id.
|
|
14
|
+
* @param id The id of the annotation.
|
|
15
|
+
* @return The list of operators for the given annotation id.
|
|
16
|
+
*/
|
|
17
|
+
get(id: string): {
|
|
18
|
+
fn: number;
|
|
19
|
+
args: unknown[];
|
|
20
|
+
}[];
|
|
21
|
+
}
|
package/dist/lib/Canvas.d.ts
CHANGED
|
@@ -6,12 +6,7 @@ declare const Path2DConstructor: {
|
|
|
6
6
|
* Create a canvas for both the browser and Node.js.
|
|
7
7
|
* @param width The width of the canvas.
|
|
8
8
|
* @param height The height of the canvas.
|
|
9
|
-
* @returns A
|
|
9
|
+
* @returns A canvas element.
|
|
10
10
|
*/
|
|
11
|
-
export declare function createCanvas(width: number, height: number):
|
|
12
|
-
/**
|
|
13
|
-
* Load the fonts.
|
|
14
|
-
* @returns A promise that resolves when the fonts are loaded.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loadDefaultFonts(): Promise<void>;
|
|
11
|
+
export declare function createCanvas(width: number, height: number): HTMLCanvasElement;
|
|
17
12
|
export { Path2DConstructor as Path2D };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Canvas } from 'skia-canvas';
|
|
2
|
+
import { BaseCanvasFactory } from '../pdf.js/src/display/canvas_factory.js';
|
|
3
|
+
export declare class NodeCanvasFactory extends BaseCanvasFactory {
|
|
4
|
+
_createCanvas(width: number, height: number): Canvas;
|
|
5
|
+
create(width: number, height: number): {
|
|
6
|
+
canvas: void;
|
|
7
|
+
context: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseFilterFactory } from '../pdf.js/src/display/filter_factory.js';
|
|
2
|
+
export type Filter = (ctx: CanvasRenderingContext2D) => void;
|
|
3
|
+
export declare const filtersRegistry: Map<string, Filter>;
|
|
4
|
+
export declare class NodeFilterFactory extends BaseFilterFactory {
|
|
5
|
+
addFilter(maps: number[][]): string;
|
|
6
|
+
addHCMFilter(fgColor: string, bgColor: string): string;
|
|
7
|
+
addAlphaFilter(map: number[]): string;
|
|
8
|
+
addLuminosityFilter(map?: number[]): string;
|
|
9
|
+
addHighlightHCMFilter(filterName: string, fgColor: string, bgColor: string, newFgColor: string, newBgColor: string): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseCMapReaderFactory } from '../pdf.js/src/display/cmap_reader_factory.js';
|
|
2
|
+
import { BaseStandardFontDataFactory } from '../pdf.js/src/display/standard_fontdata_factory.js';
|
|
3
|
+
import { BaseWasmFactory } from '../pdf.js/src/display/wasm_factory.js';
|
|
4
|
+
export declare function fetchData(url: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
5
|
+
export declare class NodeCMapReaderFactory extends BaseCMapReaderFactory {
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
_fetch(url: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
10
|
+
}
|
|
11
|
+
export declare class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
_fetch(url: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
16
|
+
}
|
|
17
|
+
export declare class NodeWasmFactory extends BaseWasmFactory {
|
|
18
|
+
/**
|
|
19
|
+
* @ignore
|
|
20
|
+
*/
|
|
21
|
+
_fetch(url: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
22
|
+
}
|
|
23
|
+
export * from './NodeCanvasFactory.js';
|
|
24
|
+
export * from './NodeFilterFactory.js';
|
package/dist/lib/Path2D.d.ts
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
1
|
import { Path2D } from './Canvas';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export declare enum CommandType {
|
|
3
|
+
MoveTo = 0,
|
|
4
|
+
LineTo = 1,
|
|
5
|
+
Arc = 2,
|
|
6
|
+
Bezier = 3,
|
|
7
|
+
Quad = 4,
|
|
8
|
+
Close = 5
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
-
type: 'lineTo';
|
|
11
|
-
args: {
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface ArcCommand {
|
|
17
|
-
type: 'arc';
|
|
18
|
-
args: {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
radius: number;
|
|
22
|
-
startAngle: number;
|
|
23
|
-
endAngle: number;
|
|
24
|
-
anticlockwise: boolean;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export interface BezierCurveToCommand {
|
|
28
|
-
type: 'bezierCurveTo';
|
|
29
|
-
args: {
|
|
30
|
-
cp1x: number;
|
|
31
|
-
cp1y: number;
|
|
32
|
-
cp2x: number;
|
|
33
|
-
cp2y: number;
|
|
34
|
-
x: number;
|
|
35
|
-
y: number;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export interface QuadraticCurveToCommand {
|
|
39
|
-
type: 'quadraticCurveTo';
|
|
40
|
-
args: {
|
|
41
|
-
qx1: number;
|
|
42
|
-
qy1: number;
|
|
43
|
-
qx: number;
|
|
44
|
-
qy: number;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export interface ClosePathCommand {
|
|
48
|
-
type: 'closePath';
|
|
49
|
-
}
|
|
50
|
-
export type PathCommand = MoveToCommand | LineToCommand | ArcCommand | BezierCurveToCommand | QuadraticCurveToCommand | ClosePathCommand;
|
|
10
|
+
export type PathCommand = [CommandType.MoveTo, number, number] | [CommandType.LineTo, number, number] | [CommandType.Arc, number, number, number, number, number, boolean] | [CommandType.Bezier, number, number, number, number, number, number] | [CommandType.Quad, number, number, number, number] | [CommandType.Close];
|
|
51
11
|
export declare function parseCommands(svgPath: string): PathCommand[];
|
|
52
12
|
export declare function commandToSvgPath(command: PathCommand): string;
|
|
53
13
|
export declare function transformPath(commands: PathCommand[], transform: DOMMatrix): PathCommand[];
|
|
54
|
-
export declare function
|
|
14
|
+
export declare function getBBox(commands: PathCommand[]): {
|
|
55
15
|
x: number;
|
|
56
16
|
y: number;
|
|
57
17
|
width: number;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
type BoundingBox = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
export interface SvgNode<Attrs = Record<string, unknown>> {
|
|
8
|
+
tag: string;
|
|
9
|
+
attrs: Attrs & {
|
|
10
|
+
transform?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface SvgElement<Attrs = Record<string, unknown>> extends SvgNode<Attrs> {
|
|
14
|
+
children: (SvgNode | string)[];
|
|
15
|
+
}
|
|
16
|
+
export interface SvgGraphic extends SvgNode<{
|
|
17
|
+
x?: number;
|
|
18
|
+
y?: number;
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
x1?: number;
|
|
22
|
+
y1?: number;
|
|
23
|
+
x2?: number;
|
|
24
|
+
y2?: number;
|
|
25
|
+
points?: string;
|
|
26
|
+
cx?: number;
|
|
27
|
+
cy?: number;
|
|
28
|
+
r?: number;
|
|
29
|
+
rx?: number;
|
|
30
|
+
ry?: number;
|
|
31
|
+
}> {
|
|
32
|
+
}
|
|
33
|
+
export interface SvgPath extends SvgNode<{
|
|
34
|
+
d: string;
|
|
35
|
+
fill?: string;
|
|
36
|
+
stroke?: string;
|
|
37
|
+
'stroke-width'?: string | number;
|
|
38
|
+
'is-glyph'?: boolean;
|
|
39
|
+
}> {
|
|
40
|
+
tag: 'path';
|
|
41
|
+
}
|
|
42
|
+
export interface SvgImage extends SvgNode<{
|
|
43
|
+
href: string;
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
}> {
|
|
47
|
+
tag: 'image';
|
|
48
|
+
}
|
|
49
|
+
export interface SvgMarkedContent extends SvgNode<{
|
|
50
|
+
href: string;
|
|
51
|
+
type: string;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
}> {
|
|
57
|
+
tag: 'use';
|
|
58
|
+
}
|
|
59
|
+
export interface SvgRoot extends SvgElement<{
|
|
60
|
+
id?: string;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}> {
|
|
64
|
+
tag: 'svg';
|
|
65
|
+
}
|
|
66
|
+
export declare function isSvgElement(node: SvgNode): node is SvgElement;
|
|
67
|
+
export declare function isSvgPath(node: SvgNode): node is SvgPath;
|
|
68
|
+
export declare function isSvgImage(node: SvgNode): node is SvgImage;
|
|
69
|
+
export declare function isSvgMarkedContent(node: SvgNode): node is SvgMarkedContent;
|
|
70
|
+
export declare function isSvgRoot(node: SvgNode): node is SvgRoot;
|
|
71
|
+
export declare enum PrefixType {
|
|
72
|
+
Root = "svg",
|
|
73
|
+
Clip = "clip",
|
|
74
|
+
Pattern = "pattern",
|
|
75
|
+
MarkedContent = "marked_content"
|
|
76
|
+
}
|
|
77
|
+
export declare function id(type: PrefixType, id?: string | null, scope?: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Traverse the SVG tree to find a node matching the given criteria.
|
|
80
|
+
* @param root The root element to start the search from.
|
|
81
|
+
* @param matcher A function that returns true for the desired node.
|
|
82
|
+
* @returns The first matching node, or null if none is found.
|
|
83
|
+
*/
|
|
84
|
+
export declare function findSvgNode(root: SvgElement, matcher: (node: SvgNode) => boolean): SvgNode | null;
|
|
85
|
+
/**
|
|
86
|
+
* Parse a transform string into a transformation matrix.
|
|
87
|
+
* @param input The transform string.
|
|
88
|
+
* @returns A transformation matrix.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseTransform(input: string): DOMMatrix;
|
|
91
|
+
export declare function matrixToTransform(matrix: DOMMatrix): string;
|
|
92
|
+
/**
|
|
93
|
+
* Parse a font string into its components.
|
|
94
|
+
* @param fontString The font string.
|
|
95
|
+
* @returns An object containing the font components.
|
|
96
|
+
*/
|
|
97
|
+
export declare function parseFontStyle(fontString: string): {
|
|
98
|
+
fontStyle: string;
|
|
99
|
+
fontVariant: string;
|
|
100
|
+
fontWeight: string;
|
|
101
|
+
fontSize: string;
|
|
102
|
+
lineHeight: string;
|
|
103
|
+
fontFamilies: string[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Convert textAlign to text-anchor.
|
|
107
|
+
* @param textAlign The textAlign value.
|
|
108
|
+
* @returns The corresponding text-anchor value.
|
|
109
|
+
*/
|
|
110
|
+
export declare function getTextAnchor(textAlign: string): 'start' | 'end' | 'middle';
|
|
111
|
+
/**
|
|
112
|
+
* Convert textBaseline to dominant-baseline.
|
|
113
|
+
* @param textBaseline The textBaseline value.
|
|
114
|
+
* @returns The corresponding dominant-baseline value.
|
|
115
|
+
*/
|
|
116
|
+
export declare function getDominantBaseline(textBaseline: string): 'alphabetic' | 'hanging' | 'text-before-edge' | 'text-after-edge' | 'central';
|
|
117
|
+
/**
|
|
118
|
+
* Normalize a vector.
|
|
119
|
+
* @param vector The input vector.
|
|
120
|
+
* @returns The normalized vector.
|
|
121
|
+
*/
|
|
122
|
+
export declare function normalizeVector(vector: [number, number]): [number, number];
|
|
123
|
+
/**
|
|
124
|
+
* Get the angle of a vector in radians.
|
|
125
|
+
* @param vector The input vector.
|
|
126
|
+
* @returns The angle in radians.
|
|
127
|
+
*/
|
|
128
|
+
export declare function getAngle(vector: [number, number]): number;
|
|
129
|
+
/**
|
|
130
|
+
* Get the bounding box of a SVG node.
|
|
131
|
+
* @param node The SVG node.
|
|
132
|
+
* @param defs The SVG definitions (for resolving references).
|
|
133
|
+
* @param inheritedMatrix The inherited transformation matrix.
|
|
134
|
+
* @returns The bounding box of the SVG node.
|
|
135
|
+
*/
|
|
136
|
+
export declare function getBBox(node: SvgNode, defs?: SvgNode[], inheritedMatrix?: DOMMatrix): BoundingBox | null;
|
|
137
|
+
/**
|
|
138
|
+
* Make a HTML string from a Svg node.
|
|
139
|
+
* @param node The node to render.
|
|
140
|
+
* @param attrs The attributes to add to the node.
|
|
141
|
+
* @returns A HTML string representation of the node.
|
|
142
|
+
*/
|
|
143
|
+
export declare function renderSvgNode(node: SvgNode | string): string;
|
|
144
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Path2D } from './Path2D';
|
|
2
|
+
import { type SvgElement, type SvgNode, type SvgRoot } from './Svg';
|
|
2
3
|
interface CanvasStyle {
|
|
3
|
-
strokeStyle: string |
|
|
4
|
-
fillStyle: string |
|
|
4
|
+
strokeStyle: string | SvgLinearGradient | SvgPattern;
|
|
5
|
+
fillStyle: string | SvgLinearGradient | SvgRadialGradient | SvgPattern;
|
|
5
6
|
fillRule: CanvasFillRule;
|
|
6
7
|
filter: string;
|
|
7
8
|
lineCap: CanvasLineCap;
|
|
@@ -28,7 +29,7 @@ declare class SvgPattern {
|
|
|
28
29
|
constructor(src: string, width: number, height: number);
|
|
29
30
|
setTransform(matrix: DOMMatrix): void;
|
|
30
31
|
}
|
|
31
|
-
declare class
|
|
32
|
+
declare class SvgLinearGradient {
|
|
32
33
|
readonly x1: number;
|
|
33
34
|
readonly y1: number;
|
|
34
35
|
readonly x2: number;
|
|
@@ -40,22 +41,20 @@ declare class SvgGradient {
|
|
|
40
41
|
constructor(x1: number, y1: number, x2: number, y2: number);
|
|
41
42
|
addColorStop(offset: number, color: string): void;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
declare class SvgRadialGradient {
|
|
45
|
+
readonly x0: number;
|
|
46
|
+
readonly y0: number;
|
|
47
|
+
readonly r0: number;
|
|
48
|
+
readonly x1: number;
|
|
49
|
+
readonly y1: number;
|
|
50
|
+
readonly r1: number;
|
|
51
|
+
readonly stops: {
|
|
52
|
+
offset: number;
|
|
53
|
+
color: string;
|
|
54
|
+
}[];
|
|
55
|
+
constructor(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number);
|
|
56
|
+
addColorStop(offset: number, color: string): void;
|
|
56
57
|
}
|
|
57
|
-
export declare function isSvgElement(node: SvgNode): node is SvgElement;
|
|
58
|
-
export declare function isSvgText(node: SvgNode): node is SvgText;
|
|
59
58
|
export declare class SvgCanvasContext {
|
|
60
59
|
private _width;
|
|
61
60
|
private _height;
|
|
@@ -64,13 +63,17 @@ export declare class SvgCanvasContext {
|
|
|
64
63
|
private _currentStyle;
|
|
65
64
|
private _styleStack;
|
|
66
65
|
private _groupStack;
|
|
66
|
+
private _markedStack;
|
|
67
67
|
private _transformMatrixStack;
|
|
68
68
|
private _root;
|
|
69
69
|
private _defs;
|
|
70
70
|
private _currentGroup;
|
|
71
71
|
private _currentElement;
|
|
72
|
+
private _currentMarked;
|
|
73
|
+
private _textActive;
|
|
72
74
|
private _transformMatrix;
|
|
73
75
|
private _currentPosition;
|
|
76
|
+
private _parents;
|
|
74
77
|
get canvas(): HTMLCanvasElement;
|
|
75
78
|
get fillStyle(): string;
|
|
76
79
|
set fillStyle(value: string);
|
|
@@ -103,6 +106,7 @@ export declare class SvgCanvasContext {
|
|
|
103
106
|
resize(width: number, height: number): void;
|
|
104
107
|
save(): void;
|
|
105
108
|
restore(): void;
|
|
109
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
106
110
|
beginPath(): void;
|
|
107
111
|
closePath(): void;
|
|
108
112
|
moveTo(x: number, y: number): void;
|
|
@@ -113,7 +117,7 @@ export declare class SvgCanvasContext {
|
|
|
113
117
|
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
114
118
|
rect(x: number, y: number, width: number, height: number): void;
|
|
115
119
|
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: boolean): void;
|
|
116
|
-
stroke(): void;
|
|
120
|
+
stroke(path?: Path2D): void;
|
|
117
121
|
transform(...values: number[]): void;
|
|
118
122
|
translate(x: number, y: number): void;
|
|
119
123
|
scale(x: number, y: number): void;
|
|
@@ -124,14 +128,21 @@ export declare class SvgCanvasContext {
|
|
|
124
128
|
setLineDash(dashArray: number[]): void;
|
|
125
129
|
drawImage(image: CanvasImageSource, ...args: number[]): void;
|
|
126
130
|
createPattern(image: CanvasImageSource, repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | null): SvgPattern;
|
|
127
|
-
createLinearGradient(x1: number, x2: number, y1: number, y2: number):
|
|
131
|
+
createLinearGradient(x1: number, x2: number, y1: number, y2: number): SvgLinearGradient;
|
|
132
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): SvgRadialGradient;
|
|
128
133
|
clip(path: Path2D, fillRule: CanvasFillRule): void;
|
|
129
134
|
measureText(text: string): TextMetrics;
|
|
130
135
|
resetTransform(): void;
|
|
131
136
|
getTransform(): DOMMatrix;
|
|
132
137
|
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
133
|
-
|
|
138
|
+
beginText(): void;
|
|
139
|
+
endText(): void;
|
|
140
|
+
beginMarkedContent(type: string, props?: number | {
|
|
141
|
+
id: number;
|
|
142
|
+
} | null): void;
|
|
143
|
+
endMarkedContent(): void;
|
|
134
144
|
protected _ensureTransformationGroup(): SvgElement;
|
|
145
|
+
protected _addNode(node: SvgNode, parent?: SvgElement): void;
|
|
135
146
|
protected _applyStyleState(styleState: CanvasStyle): void;
|
|
136
147
|
protected _getStyleState(): CanvasStyle;
|
|
137
148
|
protected _getTransformScale(): {
|
|
@@ -145,12 +156,15 @@ export declare class SvgCanvasContext {
|
|
|
145
156
|
};
|
|
146
157
|
protected _applyTransformation(node: SvgNode, matrix?: DOMMatrix): void;
|
|
147
158
|
protected _createPatternNode(pattern: SvgPattern, transform?: DOMMatrix): SvgElement;
|
|
148
|
-
protected _createGradientNode(gradient:
|
|
159
|
+
protected _createGradientNode(gradient: SvgLinearGradient | SvgRadialGradient): SvgElement;
|
|
149
160
|
protected _applyStyle(currentElement: SvgNode, type: 'fill' | 'stroke'): void;
|
|
150
161
|
protected _addPathCommand(command: string): void;
|
|
151
162
|
protected _applyText(text: string, x: number, y: number, action: 'fill'): void;
|
|
152
163
|
protected _clearCanvas(): void;
|
|
164
|
+
destroy(): void;
|
|
153
165
|
}
|
|
154
|
-
export declare function createSvgContext(width: number, height: number):
|
|
155
|
-
export declare function toSvgNode(ctx: CanvasRenderingContext2D):
|
|
166
|
+
export declare function createSvgContext(width: number, height: number): CanvasRenderingContext2D;
|
|
167
|
+
export declare function toSvgNode(ctx: CanvasRenderingContext2D): SvgRoot;
|
|
168
|
+
export declare function toSvgString(ctx: CanvasRenderingContext2D): string;
|
|
169
|
+
export declare function destroySvgContext(ctx: CanvasRenderingContext2D): void;
|
|
156
170
|
export {};
|
package/dist/lib/TextLayer.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { PageViewport } from '../pdf.js/src/display/display_utils';
|
|
1
|
+
import type { Font } from '../pdf.js/src/core/fonts';
|
|
2
|
+
import type { PDFPageProxy, StructTreeContent } from '../pdf.js/src/display/api';
|
|
4
3
|
import { type AnnotationData } from './AnnotationData';
|
|
4
|
+
import type { StructTreeNodeWithAttrs } from './StructTreePage';
|
|
5
|
+
import { type SvgRoot } from './Svg';
|
|
5
6
|
export interface TextLayerNode {
|
|
6
7
|
id?: string;
|
|
7
8
|
role: string;
|
|
9
|
+
attrs?: {
|
|
10
|
+
dir?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
export interface TextLayerElement extends TextLayerNode {
|
|
10
|
-
children:
|
|
15
|
+
children: TextLayerNode[];
|
|
11
16
|
}
|
|
12
17
|
export interface TextLayerRoot extends TextLayerElement {
|
|
13
18
|
width: number;
|
|
@@ -17,29 +22,63 @@ export interface TextLayerAnchor extends TextLayerElement {
|
|
|
17
22
|
role: 'a';
|
|
18
23
|
href: string;
|
|
19
24
|
}
|
|
25
|
+
export interface TextLayerChunk {
|
|
26
|
+
text: string;
|
|
27
|
+
width: number;
|
|
28
|
+
margin: number;
|
|
29
|
+
}
|
|
20
30
|
export interface TextLayerText extends TextLayerNode {
|
|
21
31
|
role: 'text';
|
|
22
|
-
text:
|
|
23
|
-
hyphen?: boolean;
|
|
32
|
+
text: TextLayerChunk[];
|
|
24
33
|
top: number;
|
|
25
34
|
left: number;
|
|
26
35
|
fontSize: number;
|
|
36
|
+
fontWeight: number;
|
|
37
|
+
fontStyle: string;
|
|
27
38
|
fontFamily: string;
|
|
28
39
|
fontFallback: string;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
angle: number;
|
|
40
|
+
scale?: number;
|
|
41
|
+
angle?: number;
|
|
32
42
|
}
|
|
33
|
-
export interface
|
|
34
|
-
role: '
|
|
35
|
-
|
|
43
|
+
export interface TextLayerFigure extends TextLayerNode {
|
|
44
|
+
role: 'figure';
|
|
45
|
+
href: string;
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
alt?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface Glyph {
|
|
53
|
+
unicode: string;
|
|
54
|
+
isSpace: boolean;
|
|
36
55
|
}
|
|
56
|
+
export type TextItem = {
|
|
57
|
+
glyphs: [Glyph, number, number][];
|
|
58
|
+
font: Font;
|
|
59
|
+
fontSize: number;
|
|
60
|
+
top: number;
|
|
61
|
+
left: number;
|
|
62
|
+
angle: number;
|
|
63
|
+
scaleX: number;
|
|
64
|
+
};
|
|
37
65
|
export declare function isTextNode(node: TextLayerNode): node is TextLayerText;
|
|
38
66
|
export declare function isAnchorNode(node: TextLayerNode): node is TextLayerAnchor;
|
|
39
|
-
export declare function
|
|
40
|
-
export declare function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
67
|
+
export declare function isFigureNode(node: TextLayerNode): node is TextLayerFigure;
|
|
68
|
+
export declare function isElementNode(node: TextLayerNode): node is TextLayerElement;
|
|
69
|
+
export declare const normalizeMarkedContentId: (idRef: unknown) => string | null;
|
|
70
|
+
export declare const getNodeContents: (node: TextLayerNode) => string;
|
|
71
|
+
export declare const findNode: (root: TextLayerElement, callback: (node: TextLayerNode, parent: TextLayerElement) => boolean | null | undefined) => TextLayerNode | null;
|
|
72
|
+
export declare const findNodes: (node: TextLayerElement, callback: (node: TextLayerNode, parent: TextLayerElement) => boolean | null | undefined) => TextLayerNode[];
|
|
73
|
+
export declare const flattenNodes: (node: TextLayerNode) => TextLayerNode[];
|
|
74
|
+
export declare const renderTextLayer: (root: TextLayerRoot, options?: {
|
|
75
|
+
classes?: boolean;
|
|
76
|
+
styles?: boolean;
|
|
77
|
+
font?: string;
|
|
78
|
+
}) => string;
|
|
79
|
+
export declare const decorateStructTree: (node: StructTreeNodeWithAttrs | StructTreeContent, rootContainer: TextLayerRoot, graphics?: SvgRoot, annotations?: AnnotationData[], parents?: TextLayerElement[]) => void;
|
|
80
|
+
export declare const measure: (text: string, font: string, fontSize: number, lang?: string) => TextMetrics;
|
|
81
|
+
export declare function createTextLayer(page: PDFPageProxy, { graphics, annotations: _annotations, }?: {
|
|
82
|
+
graphics?: SvgRoot;
|
|
44
83
|
annotations?: AnnotationData[];
|
|
45
84
|
}): Promise<TextLayerRoot>;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import type { Canvas } from '
|
|
1
|
+
import type { Canvas } from 'skia-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.
|
|
15
|
+
* @param type The type of the data url. Defaults to 'image/png'.
|
|
11
16
|
* @returns A promise that resolves to the data url.
|
|
12
17
|
*/
|
|
13
|
-
export declare function toDataUrl(data: Uint8Array): Promise<string>;
|
|
18
|
+
export declare function toDataUrl(data: Uint8Array<ArrayBuffer>, type?: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Convert hash color to RGB array.
|
|
21
|
+
* @param color The color in hex format (e.g., '#ff0000' or '#f00').
|
|
22
|
+
* @returns An array of RGB values [r, g, b].
|
|
23
|
+
*/
|
|
24
|
+
export declare function colorToRgb(color: string): [number, number, number];
|
|
25
|
+
export declare function rgbToHex(rgb: [number, number, number]): string;
|
|
26
|
+
export declare function rgbToHex(r: number, g: number, b: number): string;
|
|
27
|
+
export declare function parseRgbaColor(color: string): {
|
|
28
|
+
r: number;
|
|
29
|
+
g: number;
|
|
30
|
+
b: number;
|
|
31
|
+
a: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function randomUUID(): string;
|
|
34
|
+
export declare const OPS_DICT: {
|
|
35
|
+
[k: string]: string;
|
|
36
|
+
};
|