@muhammara/native-core 7.0.0-alpha.1 → 7.0.0-beta.2
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 +4 -0
- package/index.js +45 -0
- package/lib/Recipe.js +163 -56
- package/lib/recipe/annotation.js +53 -4
- package/lib/recipe/appendPage.js +38 -16
- package/lib/recipe/graphics-state.js +20 -0
- package/lib/recipe/image.js +4 -0
- package/lib/recipe/info.js +71 -73
- package/lib/recipe/insertPage.js +20 -17
- package/lib/recipe/page.js +808 -11
- package/lib/recipe/parameters.js +2 -0
- package/lib/recipe/replaceText.js +66 -0
- package/lib/recipe/shapes.js +22 -1
- package/lib/recipe/split.js +2 -6
- package/lib/recipe/text.helper.js +1 -1
- package/lib/recipe/text.js +106 -8
- package/lib/recipe/utils.js +31 -27
- package/lib/recipe/vector-polygon.js +11 -0
- package/lib/recipe/vector.helper.js +15 -3
- package/lib/recipe/vector.js +108 -10
- package/lib/recipe-info.js +10 -0
- package/muhammara.d.ts +543 -89
- package/package.json +1 -1
package/muhammara.d.ts
CHANGED
|
@@ -327,12 +327,23 @@ declare namespace muhammara {
|
|
|
327
327
|
export type PDFObjectType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
|
|
328
328
|
export function getTypeLabel(type: PDFObjectType): string;
|
|
329
329
|
|
|
330
|
+
export const ePDFPageContentItemText = 0;
|
|
331
|
+
export const ePDFPageContentItemPath = 1;
|
|
332
|
+
export const ePDFPageContentItemXObject = 2;
|
|
333
|
+
export const ePDFPageContentItemShading = 3;
|
|
334
|
+
export type PDFPageContentItemType =
|
|
335
|
+
| typeof ePDFPageContentItemText
|
|
336
|
+
| typeof ePDFPageContentItemPath
|
|
337
|
+
| typeof ePDFPageContentItemXObject
|
|
338
|
+
| typeof ePDFPageContentItemShading;
|
|
339
|
+
|
|
330
340
|
export const ePDFPageBoxMediaBox = 0;
|
|
331
341
|
export const ePDFPageBoxCropBox = 1;
|
|
332
342
|
export const ePDFPageBoxBleedBox = 2;
|
|
333
343
|
export const ePDFPageBoxTrimBox = 3;
|
|
334
344
|
export const ePDFPageBoxArtBox = 4;
|
|
335
345
|
export type PDFPageBoxType = 0 | 1 | 2 | 3 | 4;
|
|
346
|
+
export type PageBox = "media" | "crop" | "bleed" | "trim" | "art";
|
|
336
347
|
|
|
337
348
|
export const eRangeTypeAll = 0;
|
|
338
349
|
export const eRangeTypeSpecific = 1;
|
|
@@ -396,10 +407,32 @@ declare namespace muhammara {
|
|
|
396
407
|
/** The page resource name selected by the most recent Tf operation. */
|
|
397
408
|
fontResource: string;
|
|
398
409
|
fontSize: number;
|
|
399
|
-
/** The active
|
|
410
|
+
/** The text-to-page matrix after applying the active graphics CTM: [a, b, c, d, e, f]. */
|
|
400
411
|
textMatrix: [number, number, number, number, number, number];
|
|
401
412
|
}
|
|
402
413
|
|
|
414
|
+
/** A content-stream operation that produces a page mark. */
|
|
415
|
+
export interface PDFPageContentItem {
|
|
416
|
+
type: PDFPageContentItemType;
|
|
417
|
+
operation: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Per-call extraction budget. Every field is clamped to a built-in ceiling,
|
|
422
|
+
* so a caller may tighten a limit but never raise it above the default.
|
|
423
|
+
* Omitted fields keep the ceiling.
|
|
424
|
+
*/
|
|
425
|
+
export interface PDFExtractionLimits {
|
|
426
|
+
/** Extracted elements or items. Default and ceiling: 100000. */
|
|
427
|
+
maxElements?: number;
|
|
428
|
+
/** Pending operands per operator. Default and ceiling: 1024. */
|
|
429
|
+
maxOperands?: number;
|
|
430
|
+
/** Total extracted text. Default and ceiling: 16777216 (16 MiB). */
|
|
431
|
+
maxTextBytes?: number;
|
|
432
|
+
/** Content-stream objects parsed. Default and ceiling: 1000000. */
|
|
433
|
+
maxParsedObjects?: number;
|
|
434
|
+
}
|
|
435
|
+
|
|
403
436
|
export interface RectangleDimension {
|
|
404
437
|
width: Width;
|
|
405
438
|
height: Height;
|
|
@@ -444,15 +477,33 @@ declare namespace muhammara {
|
|
|
444
477
|
): undefined | PDFObject;
|
|
445
478
|
parseNewObject(objectId: number): PDFObject;
|
|
446
479
|
getPageObjectID(objectId: number): number;
|
|
447
|
-
parsePageDictionary(
|
|
448
|
-
parsePage(
|
|
480
|
+
parsePageDictionary(pageIndex: number): PDFDictionary;
|
|
481
|
+
parsePage(pageIndex: number): PDFPageInput;
|
|
449
482
|
/**
|
|
450
483
|
* Returns text-showing operations in PDF content-stream drawing order.
|
|
451
|
-
* Does not decode font character maps or calculate glyph bounds.
|
|
452
|
-
*
|
|
453
|
-
*
|
|
484
|
+
* Does not decode font character maps or calculate glyph bounds.
|
|
485
|
+
*
|
|
486
|
+
* Throws when the page exceeds the extraction budget. `limits` may only
|
|
487
|
+
* tighten the defaults: higher values are clamped to the built-in ceilings
|
|
488
|
+
* of 1,000,000 content objects, 100,000 text operations, 1024 operands, and
|
|
489
|
+
* 16 MiB of text.
|
|
454
490
|
*/
|
|
455
|
-
extractPageText(
|
|
491
|
+
extractPageText(
|
|
492
|
+
pageIndex: number,
|
|
493
|
+
limits?: PDFExtractionLimits,
|
|
494
|
+
): PDFTextElement[];
|
|
495
|
+
/**
|
|
496
|
+
* Returns every direct content-stream operation that produces a page mark.
|
|
497
|
+
* White-on-white content is included; non-painting operations are excluded.
|
|
498
|
+
*
|
|
499
|
+
* Shares `extractPageText`'s budget and clamping. `limits.maxTextBytes` is
|
|
500
|
+
* accepted for signature parity but has no effect here, because items carry
|
|
501
|
+
* an operator name rather than extracted text.
|
|
502
|
+
*/
|
|
503
|
+
extractPageContentItems(
|
|
504
|
+
pageIndex: number,
|
|
505
|
+
limits?: PDFExtractionLimits,
|
|
506
|
+
): PDFPageContentItem[];
|
|
456
507
|
getObjectsCount(): number;
|
|
457
508
|
isEncrypted(): boolean;
|
|
458
509
|
getXrefSize(): number;
|
|
@@ -746,7 +797,19 @@ declare namespace muhammara {
|
|
|
746
797
|
|
|
747
798
|
export type inInterPagesCallback = () => {};
|
|
748
799
|
|
|
800
|
+
/** Stateful methods require an active writer and throw Error("PDF writer has ended") after cleanup. */
|
|
749
801
|
export interface PDFWriter {
|
|
802
|
+
/**
|
|
803
|
+
* Replace direct references to an object in a page dictionary.
|
|
804
|
+
* Available only when modifying an existing PDF.
|
|
805
|
+
*/
|
|
806
|
+
replaceObject(
|
|
807
|
+
pageIndex: number,
|
|
808
|
+
sourceObjectId: number,
|
|
809
|
+
replacementObjectId: number,
|
|
810
|
+
options?: ObjectReplacementOptions,
|
|
811
|
+
): this;
|
|
812
|
+
/** Finalize once; repeated calls return this writer. A failed finalization also ends the writer. */
|
|
750
813
|
end(): PDFWriter;
|
|
751
814
|
createPage(x: PosX, y: PosY, width: Width, height: Height): PDFPage;
|
|
752
815
|
createPage(): PDFPage;
|
|
@@ -774,11 +837,12 @@ declare namespace muhammara {
|
|
|
774
837
|
): UsedFont;
|
|
775
838
|
attachURLLinktoCurrentPage(
|
|
776
839
|
url: string,
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
840
|
+
left: PosX,
|
|
841
|
+
bottom: PosY,
|
|
842
|
+
right: PosX,
|
|
843
|
+
top: PosY,
|
|
781
844
|
): this;
|
|
845
|
+
/** Save continuation state and retire this writer, including when saving fails. */
|
|
782
846
|
shutdown(outputFilePath: FilePath): this;
|
|
783
847
|
createFormXObjectFromTIFF(
|
|
784
848
|
filePath: FilePath | PDFRStreamForFile,
|
|
@@ -822,7 +886,7 @@ declare namespace muhammara {
|
|
|
822
886
|
): FormXObjectId[];
|
|
823
887
|
createPDFCopyingContextForModifiedFile(): DocumentCopyingContext;
|
|
824
888
|
createPDFTextString(): PDFTextString;
|
|
825
|
-
createPDFDate(): PDFDate;
|
|
889
|
+
createPDFDate(value?: string | Date): PDFDate;
|
|
826
890
|
getImageDimensions(
|
|
827
891
|
inFontFilePath: FilePath | ReadStream,
|
|
828
892
|
): RectangleDimension;
|
|
@@ -845,7 +909,75 @@ declare namespace muhammara {
|
|
|
845
909
|
): void;
|
|
846
910
|
}
|
|
847
911
|
|
|
912
|
+
export interface ObjectReplacementOptions {
|
|
913
|
+
scope?: "global";
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
export interface RecipePageInfo {
|
|
917
|
+
width: number;
|
|
918
|
+
height: number;
|
|
919
|
+
rotate: number;
|
|
920
|
+
pageNumber: number;
|
|
921
|
+
}
|
|
922
|
+
|
|
848
923
|
namespace Recipe {
|
|
924
|
+
type Color = string | readonly number[];
|
|
925
|
+
type BorderRadius =
|
|
926
|
+
| number
|
|
927
|
+
| readonly [number]
|
|
928
|
+
| readonly [number, number]
|
|
929
|
+
| readonly [number, number, number]
|
|
930
|
+
| readonly [number, number, number, number];
|
|
931
|
+
type DeviceColorspace = "rgb" | "gray" | "cmyk";
|
|
932
|
+
type Colorspace = DeviceColorspace | "separation";
|
|
933
|
+
/**
|
|
934
|
+
* Matches known runtime values case-insensitively without enumerating
|
|
935
|
+
* every per-character capitalization combination — that recursive
|
|
936
|
+
* approach costs 2^N literal types for an N-character word (4096 for
|
|
937
|
+
* "circumcenter" alone). The runtime lowercases the whole value before
|
|
938
|
+
* comparing, so any casing works at runtime; the type instead accepts
|
|
939
|
+
* the three forms callers actually write (lower case, UPPER CASE, and
|
|
940
|
+
* Capitalized).
|
|
941
|
+
*/
|
|
942
|
+
type CaseInsensitive<Value extends string> =
|
|
943
|
+
Lowercase<Value> | Uppercase<Value> | Capitalize<Lowercase<Value>>;
|
|
944
|
+
type TriangleTrait = CaseInsensitive<"sss" | "sas" | "asa" | "vtx">;
|
|
945
|
+
type TriangleMeasurementTrait = CaseInsensitive<"sss" | "sas" | "asa">;
|
|
946
|
+
type TriangleVertexTrait = CaseInsensitive<"vtx">;
|
|
947
|
+
type TrianglePosition = CaseInsensitive<
|
|
948
|
+
"a" | "b" | "c" | "centroid" | "circumcenter" | "incenter"
|
|
949
|
+
>;
|
|
950
|
+
type PermissionName =
|
|
951
|
+
| "print"
|
|
952
|
+
| "modify"
|
|
953
|
+
| "copy"
|
|
954
|
+
| "edit"
|
|
955
|
+
| "fillform"
|
|
956
|
+
| "extract"
|
|
957
|
+
| "assemble"
|
|
958
|
+
| "printbest";
|
|
959
|
+
/** Known permission names with string compatibility for composed lists. */
|
|
960
|
+
type PermissionList = PermissionName | (string & {});
|
|
961
|
+
/**
|
|
962
|
+
* Passes a colorspace argument through when it is valid, and otherwise
|
|
963
|
+
* resolves to the accepted set so the compiler names the valid values
|
|
964
|
+
* instead of reporting the bare `never` the optional parameter would
|
|
965
|
+
* collapse to. A plain `string` stays accepted for runtime-computed values.
|
|
966
|
+
*/
|
|
967
|
+
type ValidColorspace<Value extends string | undefined> = [Value] extends [
|
|
968
|
+
undefined,
|
|
969
|
+
]
|
|
970
|
+
? Value
|
|
971
|
+
: string extends Exclude<Value, undefined>
|
|
972
|
+
? Value
|
|
973
|
+
: Exclude<Value, undefined> extends Colorspace | ""
|
|
974
|
+
? Value
|
|
975
|
+
: Colorspace | "";
|
|
976
|
+
type ExtensionCallback<
|
|
977
|
+
Arguments extends unknown[] = never[],
|
|
978
|
+
Result = unknown,
|
|
979
|
+
> = (this: Recipe, ...args: Arguments) => Result;
|
|
980
|
+
|
|
849
981
|
type CommentOptionsFlag =
|
|
850
982
|
| "invisible"
|
|
851
983
|
| "hidden"
|
|
@@ -908,12 +1040,18 @@ declare namespace muhammara {
|
|
|
908
1040
|
| "Paragraph"
|
|
909
1041
|
| "Insert";
|
|
910
1042
|
|
|
1043
|
+
type RecipeCoordinate = number | "center";
|
|
1044
|
+
|
|
1045
|
+
type RecipeFontStyle =
|
|
1046
|
+
"regular" | "bold" | "italic" | "bold-italic" | "r" | "b" | "i" | "bi";
|
|
1047
|
+
|
|
911
1048
|
interface RecipeOptions {
|
|
912
1049
|
version?: number;
|
|
913
1050
|
author?: string;
|
|
914
1051
|
title?: string;
|
|
915
1052
|
subject?: string;
|
|
916
1053
|
keywords?: string[];
|
|
1054
|
+
colorspace?: Colorspace;
|
|
917
1055
|
}
|
|
918
1056
|
|
|
919
1057
|
interface RecipeMargins {
|
|
@@ -929,6 +1067,8 @@ declare namespace muhammara {
|
|
|
929
1067
|
open?: boolean;
|
|
930
1068
|
richText?: boolean;
|
|
931
1069
|
flag?: CommentOptionsFlag;
|
|
1070
|
+
/** Replies linked to this comment annotation. */
|
|
1071
|
+
replies?: readonly AnnotReply[];
|
|
932
1072
|
}
|
|
933
1073
|
|
|
934
1074
|
interface AnnotOptions {
|
|
@@ -939,9 +1079,11 @@ declare namespace muhammara {
|
|
|
939
1079
|
icon?: AnnotOptionsIcon;
|
|
940
1080
|
width?: number;
|
|
941
1081
|
height?: number;
|
|
1082
|
+
/** Annotation opacity from 0 (transparent) to 1 (opaque). Defaults to 1. */
|
|
1083
|
+
opacity?: number;
|
|
942
1084
|
date?: string;
|
|
943
1085
|
subject?: string;
|
|
944
|
-
replies?:
|
|
1086
|
+
replies?: readonly AnnotReply[];
|
|
945
1087
|
}
|
|
946
1088
|
|
|
947
1089
|
interface AnnotReply {
|
|
@@ -950,10 +1092,19 @@ declare namespace muhammara {
|
|
|
950
1092
|
title?: string;
|
|
951
1093
|
richText?: boolean;
|
|
952
1094
|
flag?: AnnotOptionsFlag;
|
|
1095
|
+
opacity?: number;
|
|
953
1096
|
date?: string;
|
|
954
1097
|
subject?: string;
|
|
955
1098
|
}
|
|
956
1099
|
|
|
1100
|
+
interface TextMarkupOptions extends Pick<
|
|
1101
|
+
AnnotOptions,
|
|
1102
|
+
"opacity" | "replies"
|
|
1103
|
+
> {
|
|
1104
|
+
text?: string;
|
|
1105
|
+
color?: Color;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
957
1108
|
interface EncryptOptions {
|
|
958
1109
|
password?: string;
|
|
959
1110
|
ownerPassword?: string;
|
|
@@ -962,15 +1113,23 @@ declare namespace muhammara {
|
|
|
962
1113
|
}
|
|
963
1114
|
|
|
964
1115
|
interface ImageOptions {
|
|
1116
|
+
/** Make the rendered image open this URL. */
|
|
1117
|
+
link?: string;
|
|
965
1118
|
width?: number;
|
|
966
1119
|
height?: number;
|
|
967
1120
|
scale?: number;
|
|
968
1121
|
keepAspectRatio?: boolean;
|
|
969
1122
|
opacity?: number;
|
|
970
1123
|
align?: string;
|
|
1124
|
+
rotation?: number;
|
|
1125
|
+
rotationOrigin?: [number, number];
|
|
1126
|
+
skewX?: number;
|
|
1127
|
+
skewY?: number;
|
|
971
1128
|
}
|
|
972
1129
|
|
|
973
1130
|
interface InfoOptions {
|
|
1131
|
+
/** Additional Info dictionary entries; arrays are joined with a comma and space. */
|
|
1132
|
+
[key: string]: string | string[] | undefined;
|
|
974
1133
|
version?: string;
|
|
975
1134
|
author?: string;
|
|
976
1135
|
title?: string;
|
|
@@ -986,12 +1145,46 @@ declare namespace muhammara {
|
|
|
986
1145
|
fitHeight?: boolean;
|
|
987
1146
|
}
|
|
988
1147
|
|
|
1148
|
+
interface MetadataPage {
|
|
1149
|
+
pageNumber: number;
|
|
1150
|
+
mediaBox: number[];
|
|
1151
|
+
layout: "portrait" | "landscape";
|
|
1152
|
+
rotate: number;
|
|
1153
|
+
width: number;
|
|
1154
|
+
height: number;
|
|
1155
|
+
size?: number[];
|
|
1156
|
+
offsetX?: number;
|
|
1157
|
+
offsetY?: number;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
interface ReadMetadataPage extends MetadataPage {
|
|
1161
|
+
size: number[];
|
|
1162
|
+
offsetX: number;
|
|
1163
|
+
offsetY: number;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
interface Metadata {
|
|
1167
|
+
/** Number of pages in a parsed source PDF. */
|
|
1168
|
+
pages?: number;
|
|
1169
|
+
/** Number of pages created in a new PDF. */
|
|
1170
|
+
pageCount?: number;
|
|
1171
|
+
[page: number]: MetadataPage | undefined;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
interface ReadMetadata extends Metadata {
|
|
1175
|
+
pages: number;
|
|
1176
|
+
pageCount?: never;
|
|
1177
|
+
[page: number]: ReadMetadataPage | undefined;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
989
1180
|
interface TextBoxStyle {
|
|
990
1181
|
lineWidth?: number;
|
|
991
|
-
stroke?:
|
|
992
|
-
dash?: number[];
|
|
993
|
-
fill?:
|
|
1182
|
+
stroke?: Color;
|
|
1183
|
+
dash?: readonly number[];
|
|
1184
|
+
fill?: Color;
|
|
1185
|
+
colorspace?: Colorspace;
|
|
994
1186
|
opacity?: number;
|
|
1187
|
+
borderRadius?: boolean | BorderRadius;
|
|
995
1188
|
}
|
|
996
1189
|
|
|
997
1190
|
interface TextBoxClipResult {
|
|
@@ -1010,34 +1203,54 @@ declare namespace muhammara {
|
|
|
1010
1203
|
width?: number;
|
|
1011
1204
|
height?: number;
|
|
1012
1205
|
minHeight?: number;
|
|
1013
|
-
padding?: number | number[];
|
|
1206
|
+
padding?: number | readonly number[];
|
|
1014
1207
|
lineHeight?: number;
|
|
1208
|
+
wrap?: boolean | "auto" | "clip" | "trim" | "ellipsis";
|
|
1015
1209
|
textAlign?: string;
|
|
1016
1210
|
clipIfExceedsBox?: boolean;
|
|
1017
1211
|
onClip?: (recipe: Recipe, result: TextBoxClipResult) => void;
|
|
1018
1212
|
style?: TextBoxStyle;
|
|
1019
1213
|
}
|
|
1020
1214
|
|
|
1215
|
+
interface TextOverflowInstructions {
|
|
1216
|
+
layout?: number | string;
|
|
1217
|
+
column?: number | readonly [number, number];
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
type TextOverflowCallback = (
|
|
1221
|
+
this: Recipe,
|
|
1222
|
+
recipe: Recipe,
|
|
1223
|
+
) => boolean | TextOverflowInstructions;
|
|
1224
|
+
|
|
1021
1225
|
interface TextOptions {
|
|
1226
|
+
/** Make the rendered text open this URL. */
|
|
1227
|
+
link?: string;
|
|
1022
1228
|
charSpace?: number;
|
|
1023
|
-
color?:
|
|
1229
|
+
color?: Color;
|
|
1230
|
+
colorspace?: Colorspace;
|
|
1024
1231
|
flow?: boolean;
|
|
1025
|
-
overflow?:
|
|
1232
|
+
overflow?: TextOverflowCallback;
|
|
1026
1233
|
layout?: number | string;
|
|
1027
1234
|
opacity?: number;
|
|
1028
1235
|
rotation?: number;
|
|
1029
|
-
rotationOrigin?: [number, number];
|
|
1236
|
+
rotationOrigin?: readonly [number, number];
|
|
1030
1237
|
font?: string;
|
|
1238
|
+
/** Font size in points for text() and textDimensions(); defaults to 14 when both fontSize and size are omitted. */
|
|
1239
|
+
fontSize?: number;
|
|
1240
|
+
/** Font size in points for text() and textDimensions(); defaults to 14. */
|
|
1031
1241
|
size?: number;
|
|
1242
|
+
bold?: boolean;
|
|
1243
|
+
italic?: boolean;
|
|
1032
1244
|
align?: string;
|
|
1033
|
-
highlight?: boolean;
|
|
1034
|
-
underline?: boolean;
|
|
1035
|
-
strikeOut?: boolean;
|
|
1245
|
+
highlight?: boolean | TextMarkupOptions;
|
|
1246
|
+
underline?: boolean | TextMarkupOptions;
|
|
1247
|
+
strikeOut?: boolean | TextMarkupOptions;
|
|
1248
|
+
squiggly?: boolean | TextMarkupOptions;
|
|
1036
1249
|
html?: boolean;
|
|
1037
1250
|
hilite?:
|
|
1038
1251
|
| boolean
|
|
1039
1252
|
| {
|
|
1040
|
-
color?:
|
|
1253
|
+
color?: Color;
|
|
1041
1254
|
opacity?: number;
|
|
1042
1255
|
};
|
|
1043
1256
|
textBox?: TextBox;
|
|
@@ -1050,49 +1263,230 @@ declare namespace muhammara {
|
|
|
1050
1263
|
subject?: string;
|
|
1051
1264
|
}
|
|
1052
1265
|
|
|
1053
|
-
interface
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
lineWidth?: number;
|
|
1058
|
-
opacity?: number;
|
|
1059
|
-
dash?: number[];
|
|
1266
|
+
interface LayoutOptions {
|
|
1267
|
+
columns?: number;
|
|
1268
|
+
gap?: number;
|
|
1269
|
+
reset?: boolean;
|
|
1060
1270
|
}
|
|
1061
1271
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1272
|
+
type TableField<RecordType extends object> = RecordType extends unknown
|
|
1273
|
+
? RecordType extends readonly unknown[]
|
|
1274
|
+
? number extends RecordType["length"]
|
|
1275
|
+
? `${number}`
|
|
1276
|
+
: Extract<keyof RecordType, `${number}`>
|
|
1277
|
+
: | Extract<keyof RecordType, string>
|
|
1278
|
+
| `${Extract<keyof RecordType, number>}`
|
|
1279
|
+
: never;
|
|
1280
|
+
type TableColumnField<RecordType extends object> = Exclude<
|
|
1281
|
+
TableField<RecordType>,
|
|
1282
|
+
""
|
|
1283
|
+
>;
|
|
1284
|
+
type TableFieldValue<
|
|
1285
|
+
RecordType extends object,
|
|
1286
|
+
Field extends TableField<RecordType>,
|
|
1287
|
+
> = RecordType extends unknown
|
|
1288
|
+
? Field extends keyof RecordType
|
|
1289
|
+
? RecordType[Field]
|
|
1290
|
+
: Field extends `${infer NumericField extends number}`
|
|
1291
|
+
? NumericField extends keyof RecordType
|
|
1292
|
+
? RecordType[NumericField]
|
|
1293
|
+
: undefined
|
|
1294
|
+
: undefined
|
|
1295
|
+
: never;
|
|
1296
|
+
|
|
1297
|
+
interface TableColumnDefinition<
|
|
1298
|
+
RecordType extends object = Record<string, unknown>,
|
|
1299
|
+
Field extends TableColumnField<RecordType> = TableColumnField<RecordType>,
|
|
1300
|
+
> extends Omit<TextOptions, "textBox"> {
|
|
1301
|
+
name: Field;
|
|
1302
|
+
text?: string;
|
|
1303
|
+
width?: number;
|
|
1304
|
+
cell?: TextBox;
|
|
1305
|
+
header?: boolean | TextOptions;
|
|
1306
|
+
hcell?: TextBox;
|
|
1307
|
+
renderer?: (
|
|
1308
|
+
this: void,
|
|
1309
|
+
text: undefined extends TableFieldValue<RecordType, Field>
|
|
1310
|
+
? Exclude<TableFieldValue<RecordType, Field>, undefined> | ""
|
|
1311
|
+
: TableFieldValue<RecordType, Field>,
|
|
1312
|
+
record: RecordType,
|
|
1313
|
+
field: Field,
|
|
1314
|
+
row: number,
|
|
1315
|
+
) => TextOptions | false | null | "" | 0 | void;
|
|
1067
1316
|
}
|
|
1068
1317
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1318
|
+
/**
|
|
1319
|
+
* A distributive map over every field of `RecordType`, so a column's
|
|
1320
|
+
* `renderer` receives the exact value type for its own `name` rather than
|
|
1321
|
+
* the union of all columns' value types. This costs one
|
|
1322
|
+
* `TableColumnDefinition` instantiation per field of `RecordType`; a
|
|
1323
|
+
* plain `TableColumnDefinition<RecordType>` would be cheaper but would
|
|
1324
|
+
* widen every renderer's `text` parameter to the union of all fields.
|
|
1325
|
+
*/
|
|
1326
|
+
type TableColumnOptions<
|
|
1327
|
+
RecordType extends object = Record<string, unknown>,
|
|
1328
|
+
> = {
|
|
1329
|
+
[Field in TableColumnField<RecordType>]: TableColumnDefinition<
|
|
1330
|
+
RecordType,
|
|
1331
|
+
Field
|
|
1332
|
+
>;
|
|
1333
|
+
}[TableColumnField<RecordType>];
|
|
1334
|
+
|
|
1335
|
+
interface TableOptions<
|
|
1336
|
+
RecordType extends object = Record<string, unknown>,
|
|
1337
|
+
> extends Omit<TextOptions, "overflow"> {
|
|
1338
|
+
height?: number;
|
|
1339
|
+
order?:
|
|
1340
|
+
| string
|
|
1341
|
+
| TableField<RecordType>[]
|
|
1342
|
+
| readonly [TableField<RecordType>, ...TableField<RecordType>[]];
|
|
1343
|
+
columns?: readonly TableColumnOptions<RecordType>[];
|
|
1344
|
+
header?:
|
|
1345
|
+
boolean | (TextOptions & { alignToData?: boolean; cell?: TextBox });
|
|
1346
|
+
border?: boolean | PolygonOptions;
|
|
1347
|
+
row?: TextOptions & { nth?: "even" | "odd"; cell?: TextBox };
|
|
1348
|
+
overflow?: (
|
|
1349
|
+
this: Recipe,
|
|
1350
|
+
recipe: Recipe,
|
|
1351
|
+
row: number,
|
|
1352
|
+
) => boolean | { position?: readonly [number, number] };
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
interface HtmlTextObject {
|
|
1356
|
+
value: string | null;
|
|
1357
|
+
tag: string | undefined;
|
|
1358
|
+
font: string | undefined;
|
|
1359
|
+
isBold: boolean;
|
|
1360
|
+
isItalic: boolean;
|
|
1361
|
+
underline: boolean;
|
|
1362
|
+
strikeOut: boolean;
|
|
1363
|
+
attributes: Array<{ name: string; value: string | null }>;
|
|
1364
|
+
styles: Record<string, string | number | number[]>;
|
|
1365
|
+
needsLineBreaker: boolean;
|
|
1366
|
+
size: number | undefined;
|
|
1367
|
+
sizeRatio: number;
|
|
1368
|
+
sizeRatios: number[];
|
|
1369
|
+
link: string | null;
|
|
1370
|
+
childs: HtmlTextObject[];
|
|
1076
1371
|
}
|
|
1077
1372
|
|
|
1078
|
-
interface
|
|
1079
|
-
color?:
|
|
1080
|
-
stroke?:
|
|
1081
|
-
|
|
1373
|
+
interface DrawingOptions {
|
|
1374
|
+
color?: Color;
|
|
1375
|
+
stroke?: Color;
|
|
1376
|
+
colorspace?: Colorspace;
|
|
1082
1377
|
lineWidth?: number;
|
|
1378
|
+
width?: number;
|
|
1083
1379
|
opacity?: number;
|
|
1084
|
-
dash?: number[];
|
|
1380
|
+
dash?: readonly number[];
|
|
1381
|
+
dashPhase?: number;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
interface PathOptions extends DrawingOptions {
|
|
1385
|
+
lineCap?: "butt" | "round" | "square";
|
|
1386
|
+
lineJoin?: "miter" | "round" | "bevel";
|
|
1387
|
+
miterLimit?: number;
|
|
1085
1388
|
}
|
|
1086
1389
|
|
|
1087
|
-
interface
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1390
|
+
interface SkewOptions {
|
|
1391
|
+
skewX?: number;
|
|
1392
|
+
skewY?: number;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
interface TransformOptions extends SkewOptions {
|
|
1396
|
+
rotation?: number;
|
|
1397
|
+
rotationOrigin?: readonly [number, number];
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
interface TransformedPathOptions extends PathOptions, TransformOptions {}
|
|
1401
|
+
|
|
1402
|
+
type LineToOptions = PathOptions;
|
|
1403
|
+
|
|
1404
|
+
type LineOptions = PathOptions;
|
|
1405
|
+
|
|
1406
|
+
interface LinkFillOptions {
|
|
1407
|
+
link?: string;
|
|
1408
|
+
fill?: Color;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
interface PolygonOptions extends TransformedPathOptions, LinkFillOptions {}
|
|
1412
|
+
|
|
1413
|
+
interface ShapeOptions extends PolygonOptions {
|
|
1414
|
+
debug?: boolean | number;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
interface NGonOptions extends ShapeOptions {
|
|
1418
|
+
rotationVertice?: number;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
interface ArrowOptions extends ShapeOptions {
|
|
1422
|
+
head?:
|
|
1423
|
+
| number
|
|
1424
|
+
| readonly [number]
|
|
1425
|
+
| readonly [number, number]
|
|
1426
|
+
| readonly [number, number, number];
|
|
1427
|
+
shaft?: number | readonly [number] | readonly [number, number];
|
|
1428
|
+
double?: boolean;
|
|
1429
|
+
type?: 0 | 1 | 2 | "triangle" | "dart" | "kite";
|
|
1430
|
+
at?: "head" | "tail";
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
interface TriangleBaseOptions extends ShapeOptions {
|
|
1434
|
+
position?: TrianglePosition;
|
|
1435
|
+
flipX?: boolean;
|
|
1436
|
+
flipY?: boolean;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
type TriangleMeasurementOptions = TriangleBaseOptions &
|
|
1440
|
+
(
|
|
1441
|
+
| { traitID: TriangleMeasurementTrait; traitsID?: TriangleTrait }
|
|
1442
|
+
| {
|
|
1443
|
+
traitID?: undefined;
|
|
1444
|
+
traitsID?: TriangleMeasurementTrait;
|
|
1445
|
+
}
|
|
1446
|
+
);
|
|
1447
|
+
type TriangleVertexIdentifier =
|
|
1448
|
+
| { traitID: TriangleVertexTrait; traitsID?: TriangleTrait }
|
|
1449
|
+
| { traitID?: undefined; traitsID: TriangleVertexTrait };
|
|
1450
|
+
type TriangleVertexOptions = TriangleBaseOptions & TriangleVertexIdentifier;
|
|
1451
|
+
type TriangleUnpositionedVertexOptions = Omit<
|
|
1452
|
+
TriangleBaseOptions,
|
|
1453
|
+
"position" | "flipX" | "flipY"
|
|
1454
|
+
> & {
|
|
1455
|
+
position?: undefined;
|
|
1456
|
+
flipX?: false;
|
|
1457
|
+
flipY?: false;
|
|
1458
|
+
} & TriangleVertexIdentifier;
|
|
1459
|
+
type TriangleOptions = TriangleMeasurementOptions | TriangleVertexOptions;
|
|
1460
|
+
type TriangleMeasurements = readonly [number, number, number];
|
|
1461
|
+
type TriangleVertices = readonly [
|
|
1462
|
+
readonly [number, number],
|
|
1463
|
+
readonly [number, number],
|
|
1464
|
+
readonly [number, number],
|
|
1465
|
+
];
|
|
1466
|
+
type MutableTriangleVertices = [
|
|
1467
|
+
[number, number],
|
|
1468
|
+
[number, number],
|
|
1469
|
+
[number, number],
|
|
1470
|
+
];
|
|
1471
|
+
|
|
1472
|
+
interface CircleOptions
|
|
1473
|
+
extends DrawingOptions, SkewOptions, LinkFillOptions {}
|
|
1474
|
+
|
|
1475
|
+
interface EllipseOptions extends CircleOptions, TransformOptions {}
|
|
1476
|
+
|
|
1477
|
+
interface RectangleOptions
|
|
1478
|
+
extends DrawingOptions, TransformOptions, LinkFillOptions {
|
|
1479
|
+
borderRadius?: BorderRadius;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
interface LineStyleOptions {
|
|
1483
|
+
width?: number;
|
|
1091
1484
|
lineWidth?: number;
|
|
1092
|
-
|
|
1485
|
+
cap?: number;
|
|
1486
|
+
join?: number;
|
|
1487
|
+
miterLimit?: number;
|
|
1093
1488
|
dash?: number[];
|
|
1094
|
-
|
|
1095
|
-
rotationOrigin?: number[];
|
|
1489
|
+
dashPhase?: number;
|
|
1096
1490
|
}
|
|
1097
1491
|
|
|
1098
1492
|
type EndPDFCallback1 = () => any;
|
|
@@ -1108,9 +1502,16 @@ declare namespace muhammara {
|
|
|
1108
1502
|
);
|
|
1109
1503
|
|
|
1110
1504
|
readonly position: { x: number; y: number };
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1505
|
+
/** Current document metadata, keyed by one-based page number. */
|
|
1506
|
+
readonly metadata: Recipe.Metadata;
|
|
1507
|
+
read(inSrc?: string | Buffer): Recipe.ReadMetadata;
|
|
1508
|
+
register<Arguments extends unknown[], Result>(
|
|
1509
|
+
key: string,
|
|
1510
|
+
callback: Recipe.ExtensionCallback<Arguments, Result>,
|
|
1511
|
+
): Recipe;
|
|
1512
|
+
register<Arguments extends unknown[], Result>(
|
|
1513
|
+
callback: Recipe.ExtensionCallback<Arguments, Result>,
|
|
1514
|
+
): Recipe;
|
|
1114
1515
|
|
|
1115
1516
|
constructor(
|
|
1116
1517
|
buffer: Buffer,
|
|
@@ -1125,6 +1526,14 @@ declare namespace muhammara {
|
|
|
1125
1526
|
options?: Recipe.CommentOptions,
|
|
1126
1527
|
): Recipe;
|
|
1127
1528
|
|
|
1529
|
+
link(
|
|
1530
|
+
url: string,
|
|
1531
|
+
x: number,
|
|
1532
|
+
y: number,
|
|
1533
|
+
width: number,
|
|
1534
|
+
height: number,
|
|
1535
|
+
): Recipe;
|
|
1536
|
+
|
|
1128
1537
|
annot(
|
|
1129
1538
|
x: number,
|
|
1130
1539
|
y: number,
|
|
@@ -1139,12 +1548,16 @@ declare namespace muhammara {
|
|
|
1139
1548
|
|
|
1140
1549
|
encrypt(options?: Recipe.EncryptOptions): Recipe;
|
|
1141
1550
|
|
|
1142
|
-
registerFont(
|
|
1551
|
+
registerFont(
|
|
1552
|
+
fontName: string,
|
|
1553
|
+
fontSrcPath: string,
|
|
1554
|
+
type?: Recipe.RecipeFontStyle,
|
|
1555
|
+
): Recipe;
|
|
1143
1556
|
|
|
1144
1557
|
image(
|
|
1145
1558
|
imgSrc: string,
|
|
1146
|
-
x:
|
|
1147
|
-
y:
|
|
1559
|
+
x: Recipe.RecipeCoordinate,
|
|
1560
|
+
y: Recipe.RecipeCoordinate,
|
|
1148
1561
|
options?: Recipe.ImageOptions,
|
|
1149
1562
|
): Recipe;
|
|
1150
1563
|
|
|
@@ -1158,6 +1571,7 @@ declare namespace muhammara {
|
|
|
1158
1571
|
srcPageNumber: number,
|
|
1159
1572
|
): Recipe;
|
|
1160
1573
|
|
|
1574
|
+
overlay(pdfSrc: string, options?: Recipe.OverlayOptions): Recipe;
|
|
1161
1575
|
overlay(
|
|
1162
1576
|
pdfSrc: string,
|
|
1163
1577
|
x: number,
|
|
@@ -1175,16 +1589,23 @@ declare namespace muhammara {
|
|
|
1175
1589
|
rotation?: number,
|
|
1176
1590
|
margins?: Recipe.RecipeMargins,
|
|
1177
1591
|
): Recipe;
|
|
1592
|
+
rotate(rotation: number): Recipe;
|
|
1178
1593
|
endPage(): Recipe;
|
|
1594
|
+
setPageBox(
|
|
1595
|
+
box: PDFPageBoxType,
|
|
1596
|
+
left: number,
|
|
1597
|
+
bottom: number,
|
|
1598
|
+
right: number,
|
|
1599
|
+
top: number,
|
|
1600
|
+
): Recipe;
|
|
1179
1601
|
|
|
1180
1602
|
editPage(pageNumber: number): Recipe;
|
|
1603
|
+
deletePage(pageNumbers: number | number[]): Recipe;
|
|
1181
1604
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
pageNumber: number;
|
|
1187
|
-
};
|
|
1605
|
+
replaceText(text: string, replacement: string, pageNumber: number): Recipe;
|
|
1606
|
+
|
|
1607
|
+
pageInfo(pageNumber: number): RecipePageInfo;
|
|
1608
|
+
getCurrentPageInfo(): RecipePageInfo | null;
|
|
1188
1609
|
|
|
1189
1610
|
margins(): Required<Recipe.RecipeMargins>;
|
|
1190
1611
|
margins(margins: Recipe.RecipeMargins): Recipe;
|
|
@@ -1195,14 +1616,16 @@ declare namespace muhammara {
|
|
|
1195
1616
|
bottom?: number,
|
|
1196
1617
|
): Recipe;
|
|
1197
1618
|
getPageInfo(): InfoDictionary;
|
|
1198
|
-
pauseContext():
|
|
1199
|
-
resumeContext():
|
|
1619
|
+
pauseContext(): Recipe;
|
|
1620
|
+
resumeContext(): Recipe;
|
|
1621
|
+
rotateContent(degrees: number, x?: number, y?: number): Recipe;
|
|
1200
1622
|
split(outputDir?: string, prefix?: string): Recipe;
|
|
1201
1623
|
|
|
1624
|
+
text(text: string, options?: Recipe.TextOptions): Recipe;
|
|
1202
1625
|
text(
|
|
1203
1626
|
text: string,
|
|
1204
|
-
x:
|
|
1205
|
-
y:
|
|
1627
|
+
x: Recipe.RecipeCoordinate,
|
|
1628
|
+
y: Recipe.RecipeCoordinate,
|
|
1206
1629
|
options?: Recipe.TextOptions,
|
|
1207
1630
|
): Recipe;
|
|
1208
1631
|
textDimensions(text: string, options?: Recipe.TextOptions): TextDimension;
|
|
@@ -1215,9 +1638,14 @@ declare namespace muhammara {
|
|
|
1215
1638
|
y?: number,
|
|
1216
1639
|
width?: number,
|
|
1217
1640
|
height?: number,
|
|
1218
|
-
options?:
|
|
1641
|
+
options?: Recipe.LayoutOptions,
|
|
1642
|
+
): Recipe;
|
|
1643
|
+
table<RecordType extends object>(
|
|
1644
|
+
x: number,
|
|
1645
|
+
y: number,
|
|
1646
|
+
contents: readonly RecordType[],
|
|
1647
|
+
options?: Recipe.TableOptions<RecordType>,
|
|
1219
1648
|
): Recipe;
|
|
1220
|
-
table(x: number, y: number, contents: object[], options?: object): Recipe;
|
|
1221
1649
|
|
|
1222
1650
|
moveTo(x: number, y: number): Recipe;
|
|
1223
1651
|
|
|
@@ -1247,7 +1675,7 @@ declare namespace muhammara {
|
|
|
1247
1675
|
cy: number,
|
|
1248
1676
|
rx: number,
|
|
1249
1677
|
ry: number,
|
|
1250
|
-
options?: Recipe.
|
|
1678
|
+
options?: Recipe.EllipseOptions,
|
|
1251
1679
|
): Recipe;
|
|
1252
1680
|
arc(
|
|
1253
1681
|
x: number,
|
|
@@ -1255,41 +1683,67 @@ declare namespace muhammara {
|
|
|
1255
1683
|
radius: number,
|
|
1256
1684
|
startAngle?: number,
|
|
1257
1685
|
endAngle?: number,
|
|
1258
|
-
options?: Recipe.
|
|
1686
|
+
options?: Recipe.EllipseOptions,
|
|
1259
1687
|
): Recipe;
|
|
1688
|
+
pie(
|
|
1689
|
+
x: number,
|
|
1690
|
+
y: number,
|
|
1691
|
+
radius: number,
|
|
1692
|
+
startAngle?: number,
|
|
1693
|
+
endAngle?: number,
|
|
1694
|
+
options?: Recipe.EllipseOptions,
|
|
1695
|
+
): Recipe;
|
|
1696
|
+
lineStyle(options?: Recipe.LineStyleOptions): Recipe;
|
|
1260
1697
|
lineWidth(width: number): Recipe;
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1698
|
+
/** Set fill and stroke opacity from 0 (transparent) to 1 (opaque). */
|
|
1699
|
+
opacity(opacity: number): Recipe;
|
|
1700
|
+
fill(color?: Recipe.Color): Recipe;
|
|
1701
|
+
stroke(color?: Recipe.Color): Recipe;
|
|
1702
|
+
fillAndStroke(fill?: Recipe.Color, stroke?: Recipe.Color): Recipe;
|
|
1265
1703
|
n_gon(
|
|
1266
1704
|
cx: number,
|
|
1267
1705
|
cy: number,
|
|
1268
1706
|
radius: number,
|
|
1269
|
-
sides?: number | Recipe.
|
|
1270
|
-
options?: Recipe.
|
|
1707
|
+
sides?: number | Recipe.NGonOptions,
|
|
1708
|
+
options?: Recipe.NGonOptions,
|
|
1271
1709
|
): Recipe;
|
|
1272
1710
|
star(
|
|
1273
1711
|
cx: number,
|
|
1274
1712
|
cy: number,
|
|
1275
1713
|
radius: number,
|
|
1276
|
-
points?: number | Recipe.
|
|
1277
|
-
options?: Recipe.
|
|
1714
|
+
points?: number | Recipe.ShapeOptions,
|
|
1715
|
+
options?: Recipe.ShapeOptions,
|
|
1278
1716
|
): Recipe;
|
|
1279
1717
|
triangle(
|
|
1280
1718
|
x: number,
|
|
1281
1719
|
y: number,
|
|
1282
|
-
traits:
|
|
1283
|
-
options?: Recipe.
|
|
1720
|
+
traits: Recipe.TriangleMeasurements,
|
|
1721
|
+
options?: Recipe.TriangleMeasurementOptions,
|
|
1722
|
+
): Recipe;
|
|
1723
|
+
triangle(
|
|
1724
|
+
x: number,
|
|
1725
|
+
y: number,
|
|
1726
|
+
traits: Recipe.TriangleVertices,
|
|
1727
|
+
options: Recipe.TriangleUnpositionedVertexOptions,
|
|
1728
|
+
): Recipe;
|
|
1729
|
+
triangle(
|
|
1730
|
+
x: number,
|
|
1731
|
+
y: number,
|
|
1732
|
+
traits: Recipe.MutableTriangleVertices,
|
|
1733
|
+
options: Recipe.TriangleVertexOptions,
|
|
1734
|
+
): Recipe;
|
|
1735
|
+
arrow(x: number, y: number, options?: Recipe.ArrowOptions): Recipe;
|
|
1736
|
+
chroma<ColorspaceValue extends string | undefined = undefined>(
|
|
1737
|
+
name: string,
|
|
1738
|
+
value: Recipe.Color,
|
|
1739
|
+
colorspace?: Recipe.ValidColorspace<ColorspaceValue>,
|
|
1284
1740
|
): Recipe;
|
|
1285
|
-
|
|
1286
|
-
chroma(name: string, value: string | number[], colorspace?: string): Recipe;
|
|
1287
|
-
permission(flags?: string): number;
|
|
1741
|
+
permission(flags?: Recipe.PermissionList): number;
|
|
1288
1742
|
structure(output: string): Recipe;
|
|
1289
1743
|
htmlToTextObjects(
|
|
1290
1744
|
htmlCodes: string,
|
|
1291
1745
|
options?: Recipe.TextOptions,
|
|
1292
|
-
):
|
|
1746
|
+
): Recipe.HtmlTextObject[];
|
|
1293
1747
|
|
|
1294
1748
|
endPDF(): void;
|
|
1295
1749
|
endPDF<T>(callback: (output?: Buffer | string) => T): T;
|