@chialab/pdfjs-lib 1.0.0-alpha.2 → 1.0.0-alpha.20
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/NodeCanvasFactory-ONRE5YYL.js +58 -0
- package/dist/browser/chunk-5IWODJWD.js +801 -0
- package/dist/browser/chunk-ELOUEWKT.js +1142 -0
- package/dist/browser/chunk-NJUB3B5A.js +1207 -0
- package/dist/browser/index.js +2641 -3053
- package/dist/browser/openjpeg-K2XBCFFN.js +9 -0
- package/dist/browser/qcms_bg-Q7BRLLZG.js +9 -0
- package/dist/browser/worker.js +7307 -6457
- package/dist/index.d.ts +3 -0
- package/dist/lib/AnnotationData.d.ts +8 -8
- package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
- 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/Path2D.d.ts +1 -1
- package/dist/lib/StandardFontDataFactory.d.ts +2 -2
- package/dist/lib/Svg.d.ts +143 -0
- package/dist/lib/SvgCanvasContext.d.ts +31 -22
- package/dist/lib/TextLayer.d.ts +12 -5
- package/dist/lib/WasmFactory.d.ts +5 -0
- package/dist/lib/utils.d.ts +29 -3
- package/dist/node/NodeCanvasFactory-YRBSQ5MH.js +8 -0
- package/dist/node/chunk-3XZOTLLE.js +1439 -0
- package/dist/node/chunk-XMKSLA4K.js +1207 -0
- package/dist/node/chunk-ZKUTXCS2.js +801 -0
- package/dist/node/index.js +2659 -3102
- package/dist/node/openjpeg-B2WN24QZ.js +9 -0
- package/dist/node/qcms_bg-T4RSHPOQ.js +9 -0
- package/dist/node/worker.js +7307 -6457
- package/dist/pdf.js/src/display/annotation_layer.d.ts +1 -2
- package/dist/pdf.js/src/display/annotation_storage.d.ts +1 -8
- package/dist/pdf.js/src/display/api.d.ts +38 -72
- package/dist/pdf.js/src/display/api_utils.d.ts +13 -0
- package/dist/pdf.js/src/display/canvas.d.ts +21 -29
- package/dist/pdf.js/src/display/display_utils.d.ts +12 -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 +5 -5
- package/dist/pdf.js/src/display/editor/color_picker.d.ts +1 -1
- package/dist/pdf.js/src/display/editor/draw.d.ts +7 -7
- package/dist/pdf.js/src/display/editor/drawers/freedraw.d.ts +3 -3
- package/dist/pdf.js/src/display/editor/drawers/signaturedraw.d.ts +13 -13
- package/dist/pdf.js/src/display/editor/editor.d.ts +30 -6
- package/dist/pdf.js/src/display/editor/freetext.d.ts +4 -7
- package/dist/pdf.js/src/display/editor/highlight.d.ts +6 -3
- package/dist/pdf.js/src/display/editor/ink.d.ts +1 -0
- package/dist/pdf.js/src/display/editor/signature.d.ts +3 -0
- package/dist/pdf.js/src/display/editor/stamp.d.ts +4 -3
- package/dist/pdf.js/src/display/editor/toolbar.d.ts +4 -2
- package/dist/pdf.js/src/display/editor/tools.d.ts +7 -9
- 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 +4 -2
- 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 +4 -1
- package/dist/pdf.js/src/shared/scripting_utils.d.ts +2 -0
- package/dist/pdf.js/src/shared/util.d.ts +123 -100
- package/dist/pdf.js/web/text_accessibility.d.ts +1 -1
- package/package.json +7 -4
- package/dist/browser/chunk-DYHYQ33L.js +0 -1775
- package/dist/node/chunk-KTTVPO2G.js +0 -1775
- package/dist/pdf.js/src/display/cmap_reader_factory.d.ts +0 -25
- package/dist/pdf.js/src/display/node_utils.d.ts +0 -32
- package/dist/pdf.js/src/display/wasm_factory.d.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,12 @@ 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, } 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
13
|
export * from './lib/TextLayer';
|
|
11
14
|
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",
|
|
@@ -106,7 +107,7 @@ export interface StrikeOutAnnotationData extends TextAnnotationData {
|
|
|
106
107
|
}
|
|
107
108
|
export interface StampAnnotationData extends TextAnnotationData {
|
|
108
109
|
subtype: 'Stamp';
|
|
109
|
-
graphics:
|
|
110
|
+
graphics: SvgRoot;
|
|
110
111
|
}
|
|
111
112
|
export interface CaretAnnotationData extends TextAnnotationData {
|
|
112
113
|
subtype: 'Caret';
|
|
@@ -122,7 +123,7 @@ export interface FileAttachmentAnnotationData extends TextAnnotationData {
|
|
|
122
123
|
subtype: 'FileAttachment';
|
|
123
124
|
file: {
|
|
124
125
|
filename: string;
|
|
125
|
-
content?: Uint8Array | null;
|
|
126
|
+
content?: Uint8Array<ArrayBuffer> | null;
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
129
|
export interface SoundAnnotationData extends TextAnnotationData {
|
|
@@ -201,4 +202,3 @@ export declare function isTrapNetAnnotation(annotation: AnnotationData): annotat
|
|
|
201
202
|
export declare function isWatermarkAnnotation(annotation: AnnotationData): annotation is WatermarkAnnotationData;
|
|
202
203
|
export declare function isThreeDAnnotation(annotation: AnnotationData): annotation is ThreeDAnnotationData;
|
|
203
204
|
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
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/lib/Path2D.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type PathCommand = MoveToCommand | LineToCommand | ArcCommand | BezierCur
|
|
|
51
51
|
export declare function parseCommands(svgPath: string): PathCommand[];
|
|
52
52
|
export declare function commandToSvgPath(command: PathCommand): string;
|
|
53
53
|
export declare function transformPath(commands: PathCommand[], transform: DOMMatrix): PathCommand[];
|
|
54
|
-
export declare function
|
|
54
|
+
export declare function getBBox(commands: PathCommand[]): {
|
|
55
55
|
x: number;
|
|
56
56
|
y: number;
|
|
57
57
|
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,143 @@
|
|
|
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
|
+
}> {
|
|
39
|
+
tag: 'path';
|
|
40
|
+
}
|
|
41
|
+
export interface SvgImage extends SvgNode<{
|
|
42
|
+
href: string;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
}> {
|
|
46
|
+
tag: 'image';
|
|
47
|
+
}
|
|
48
|
+
export interface SvgMarkedContent extends SvgNode<{
|
|
49
|
+
href: string;
|
|
50
|
+
type: string;
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}> {
|
|
56
|
+
tag: 'use';
|
|
57
|
+
}
|
|
58
|
+
export interface SvgRoot extends SvgElement<{
|
|
59
|
+
id?: string;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
}> {
|
|
63
|
+
tag: 'svg';
|
|
64
|
+
}
|
|
65
|
+
export declare function isSvgElement(node: SvgNode): node is SvgElement;
|
|
66
|
+
export declare function isSvgPath(node: SvgNode): node is SvgPath;
|
|
67
|
+
export declare function isSvgImage(node: SvgNode): node is SvgImage;
|
|
68
|
+
export declare function isSvgMarkedContent(node: SvgNode): node is SvgMarkedContent;
|
|
69
|
+
export declare function isSvgRoot(node: SvgNode): node is SvgRoot;
|
|
70
|
+
export declare enum PrefixType {
|
|
71
|
+
Root = "svg",
|
|
72
|
+
Clip = "clip",
|
|
73
|
+
Pattern = "pattern",
|
|
74
|
+
MarkedContent = "marked_content"
|
|
75
|
+
}
|
|
76
|
+
export declare function id(type: PrefixType, id?: string | null, scope?: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Traverse the SVG tree to find a node matching the given criteria.
|
|
79
|
+
* @param root The root element to start the search from.
|
|
80
|
+
* @param matcher A function that returns true for the desired node.
|
|
81
|
+
* @returns The first matching node, or null if none is found.
|
|
82
|
+
*/
|
|
83
|
+
export declare function findSvgNode(root: SvgElement, matcher: (node: SvgNode) => boolean): SvgNode | null;
|
|
84
|
+
/**
|
|
85
|
+
* Parse a transform string into a transformation matrix.
|
|
86
|
+
* @param input The transform string.
|
|
87
|
+
* @returns A transformation matrix.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseTransform(input: string): DOMMatrix;
|
|
90
|
+
export declare function matrixToTransform(matrix: DOMMatrix): string;
|
|
91
|
+
/**
|
|
92
|
+
* Parse a font string into its components.
|
|
93
|
+
* @param fontString The font string.
|
|
94
|
+
* @returns An object containing the font components.
|
|
95
|
+
*/
|
|
96
|
+
export declare function parseFontStyle(fontString: string): {
|
|
97
|
+
fontStyle: string;
|
|
98
|
+
fontVariant: string;
|
|
99
|
+
fontWeight: string;
|
|
100
|
+
fontSize: string;
|
|
101
|
+
lineHeight: string;
|
|
102
|
+
fontFamilies: string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Convert textAlign to text-anchor.
|
|
106
|
+
* @param textAlign The textAlign value.
|
|
107
|
+
* @returns The corresponding text-anchor value.
|
|
108
|
+
*/
|
|
109
|
+
export declare function getTextAnchor(textAlign: string): 'start' | 'end' | 'middle';
|
|
110
|
+
/**
|
|
111
|
+
* Convert textBaseline to dominant-baseline.
|
|
112
|
+
* @param textBaseline The textBaseline value.
|
|
113
|
+
* @returns The corresponding dominant-baseline value.
|
|
114
|
+
*/
|
|
115
|
+
export declare function getDominantBaseline(textBaseline: string): 'alphabetic' | 'hanging' | 'text-before-edge' | 'text-after-edge' | 'central';
|
|
116
|
+
/**
|
|
117
|
+
* Normalize a vector.
|
|
118
|
+
* @param vector The input vector.
|
|
119
|
+
* @returns The normalized vector.
|
|
120
|
+
*/
|
|
121
|
+
export declare function normalizeVector(vector: [number, number]): [number, number];
|
|
122
|
+
/**
|
|
123
|
+
* Get the angle of a vector in radians.
|
|
124
|
+
* @param vector The input vector.
|
|
125
|
+
* @returns The angle in radians.
|
|
126
|
+
*/
|
|
127
|
+
export declare function getAngle(vector: [number, number]): number;
|
|
128
|
+
/**
|
|
129
|
+
* Get the bounding box of a SVG node.
|
|
130
|
+
* @param node The SVG node.
|
|
131
|
+
* @param defs The SVG definitions (for resolving references).
|
|
132
|
+
* @param inheritedMatrix The inherited transformation matrix.
|
|
133
|
+
* @returns The bounding box of the SVG node.
|
|
134
|
+
*/
|
|
135
|
+
export declare function getBBox(node: SvgNode, defs?: SvgNode[], inheritedMatrix?: DOMMatrix): BoundingBox | null;
|
|
136
|
+
/**
|
|
137
|
+
* Make a HTML string from a Svg node.
|
|
138
|
+
* @param node The node to render.
|
|
139
|
+
* @param attrs The attributes to add to the node.
|
|
140
|
+
* @returns A HTML string representation of the node.
|
|
141
|
+
*/
|
|
142
|
+
export declare function renderSvgNode(node: SvgNode | string): string;
|
|
143
|
+
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,16 @@ 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;
|
|
72
73
|
private _transformMatrix;
|
|
73
74
|
private _currentPosition;
|
|
75
|
+
private _parents;
|
|
74
76
|
get canvas(): HTMLCanvasElement;
|
|
75
77
|
get fillStyle(): string;
|
|
76
78
|
set fillStyle(value: string);
|
|
@@ -103,6 +105,7 @@ export declare class SvgCanvasContext {
|
|
|
103
105
|
resize(width: number, height: number): void;
|
|
104
106
|
save(): void;
|
|
105
107
|
restore(): void;
|
|
108
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
106
109
|
beginPath(): void;
|
|
107
110
|
closePath(): void;
|
|
108
111
|
moveTo(x: number, y: number): void;
|
|
@@ -113,7 +116,7 @@ export declare class SvgCanvasContext {
|
|
|
113
116
|
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
114
117
|
rect(x: number, y: number, width: number, height: number): void;
|
|
115
118
|
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: boolean): void;
|
|
116
|
-
stroke(): void;
|
|
119
|
+
stroke(path?: Path2D): void;
|
|
117
120
|
transform(...values: number[]): void;
|
|
118
121
|
translate(x: number, y: number): void;
|
|
119
122
|
scale(x: number, y: number): void;
|
|
@@ -124,14 +127,19 @@ export declare class SvgCanvasContext {
|
|
|
124
127
|
setLineDash(dashArray: number[]): void;
|
|
125
128
|
drawImage(image: CanvasImageSource, ...args: number[]): void;
|
|
126
129
|
createPattern(image: CanvasImageSource, repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | null): SvgPattern;
|
|
127
|
-
createLinearGradient(x1: number, x2: number, y1: number, y2: number):
|
|
130
|
+
createLinearGradient(x1: number, x2: number, y1: number, y2: number): SvgLinearGradient;
|
|
131
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): SvgRadialGradient;
|
|
128
132
|
clip(path: Path2D, fillRule: CanvasFillRule): void;
|
|
129
133
|
measureText(text: string): TextMetrics;
|
|
130
134
|
resetTransform(): void;
|
|
131
135
|
getTransform(): DOMMatrix;
|
|
132
136
|
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
133
|
-
|
|
137
|
+
beginMarkedContent(type: string, props?: number | {
|
|
138
|
+
id: number;
|
|
139
|
+
} | null): void;
|
|
140
|
+
endMarkedContent(): void;
|
|
134
141
|
protected _ensureTransformationGroup(): SvgElement;
|
|
142
|
+
protected _addNode(node: SvgNode, parent?: SvgElement): void;
|
|
135
143
|
protected _applyStyleState(styleState: CanvasStyle): void;
|
|
136
144
|
protected _getStyleState(): CanvasStyle;
|
|
137
145
|
protected _getTransformScale(): {
|
|
@@ -145,7 +153,7 @@ export declare class SvgCanvasContext {
|
|
|
145
153
|
};
|
|
146
154
|
protected _applyTransformation(node: SvgNode, matrix?: DOMMatrix): void;
|
|
147
155
|
protected _createPatternNode(pattern: SvgPattern, transform?: DOMMatrix): SvgElement;
|
|
148
|
-
protected _createGradientNode(gradient:
|
|
156
|
+
protected _createGradientNode(gradient: SvgLinearGradient | SvgRadialGradient): SvgElement;
|
|
149
157
|
protected _applyStyle(currentElement: SvgNode, type: 'fill' | 'stroke'): void;
|
|
150
158
|
protected _addPathCommand(command: string): void;
|
|
151
159
|
protected _applyText(text: string, x: number, y: number, action: 'fill'): void;
|
|
@@ -153,4 +161,5 @@ export declare class SvgCanvasContext {
|
|
|
153
161
|
}
|
|
154
162
|
export declare function createSvgContext(width: number, height: number): Promise<CanvasRenderingContext2D>;
|
|
155
163
|
export declare function toSvgNode(ctx: CanvasRenderingContext2D): Promise<SvgRoot>;
|
|
164
|
+
export declare function toSvgString(ctx: CanvasRenderingContext2D): Promise<string>;
|
|
156
165
|
export {};
|
package/dist/lib/TextLayer.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PDFPageProxy } from '../pdf.js/src/display/api';
|
|
|
2
2
|
import type { BaseCanvasFactory } from '../pdf.js/src/display/canvas_factory';
|
|
3
3
|
import type { PageViewport } from '../pdf.js/src/display/display_utils';
|
|
4
4
|
import { type AnnotationData } from './AnnotationData';
|
|
5
|
+
import { type SvgRoot } from './Svg';
|
|
5
6
|
export interface TextLayerNode {
|
|
6
7
|
id?: string;
|
|
7
8
|
role: string;
|
|
@@ -30,16 +31,22 @@ export interface TextLayerText extends TextLayerNode {
|
|
|
30
31
|
scale: number;
|
|
31
32
|
angle: number;
|
|
32
33
|
}
|
|
33
|
-
export interface
|
|
34
|
-
role: '
|
|
35
|
-
|
|
34
|
+
export interface TextLayerFigure extends TextLayerNode {
|
|
35
|
+
role: 'figure';
|
|
36
|
+
href: string;
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
alt?: string;
|
|
36
42
|
}
|
|
37
43
|
export declare function isTextNode(node: TextLayerNode): node is TextLayerText;
|
|
38
44
|
export declare function isAnchorNode(node: TextLayerNode): node is TextLayerAnchor;
|
|
39
|
-
export declare function
|
|
40
|
-
export declare function createTextLayer(page: PDFPageProxy, { canvasFactory, viewport, outputScale, annotations, }: {
|
|
45
|
+
export declare function isFigureNode(node: TextLayerNode): node is TextLayerFigure;
|
|
46
|
+
export declare function createTextLayer(page: PDFPageProxy, { canvasFactory, viewport, outputScale, annotations, graphics, }: {
|
|
41
47
|
canvasFactory: BaseCanvasFactory;
|
|
42
48
|
viewport?: PageViewport;
|
|
43
49
|
outputScale?: number;
|
|
44
50
|
annotations?: AnnotationData[];
|
|
51
|
+
graphics?: SvgRoot;
|
|
45
52
|
}): Promise<TextLayerRoot>;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
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
|
+
* Ensure the object can be serialized and unserialized as JSON.
|
|
21
|
+
* Internally it converts typed arrays to plain arrays.
|
|
22
|
+
* @param object The object to serialize.
|
|
23
|
+
* @returns The serialized object.
|
|
24
|
+
*/
|
|
25
|
+
export declare function makeSerializable<T>(object: T): T;
|
|
26
|
+
/**
|
|
27
|
+
* Convert hash color to RGB array.
|
|
28
|
+
* @param color The color in hex format (e.g., '#ff0000' or '#f00').
|
|
29
|
+
* @returns An array of RGB values [r, g, b].
|
|
30
|
+
*/
|
|
31
|
+
export declare function colorToRgb(color: string): [number, number, number];
|
|
32
|
+
export declare function rgbToHex(rgb: [number, number, number]): string;
|
|
33
|
+
export declare function rgbToHex(r: number, g: number, b: number): string;
|
|
34
|
+
export declare function parseRgbaColor(color: string): {
|
|
35
|
+
r: number;
|
|
36
|
+
g: number;
|
|
37
|
+
b: number;
|
|
38
|
+
a: number;
|
|
39
|
+
};
|