@embedpdf/models 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +83 -2
- package/dist/index.js.map +1 -1
- package/dist/pdf.d.ts +168 -18
- package/dist/task.d.ts +21 -1
- package/dist/uuid.d.ts +22 -0
- package/package.json +1 -1
package/dist/pdf.d.ts
CHANGED
|
@@ -550,7 +550,7 @@ export declare enum PdfAnnotationState {
|
|
|
550
550
|
/**
|
|
551
551
|
* Annotation is complete
|
|
552
552
|
*/
|
|
553
|
-
|
|
553
|
+
Completed = "Completed",
|
|
554
554
|
/**
|
|
555
555
|
* Annotation is cancelled
|
|
556
556
|
*/
|
|
@@ -573,13 +573,130 @@ export declare enum PdfAnnotationStateModel {
|
|
|
573
573
|
/**
|
|
574
574
|
* Annotation is reviewed
|
|
575
575
|
*/
|
|
576
|
-
|
|
576
|
+
Review = "Review"
|
|
577
577
|
}
|
|
578
578
|
/**
|
|
579
|
-
*
|
|
579
|
+
* Icon of pdf annotation
|
|
580
580
|
*
|
|
581
581
|
* @public
|
|
582
582
|
*/
|
|
583
|
+
export declare enum PdfAnnotationIcon {
|
|
584
|
+
/**
|
|
585
|
+
* Unknown icon
|
|
586
|
+
*/
|
|
587
|
+
Unknown = -1,
|
|
588
|
+
/**
|
|
589
|
+
* Comment icon
|
|
590
|
+
*/
|
|
591
|
+
Comment = 0,
|
|
592
|
+
/**
|
|
593
|
+
* Key icon
|
|
594
|
+
*/
|
|
595
|
+
Key = 1,
|
|
596
|
+
/**
|
|
597
|
+
* Note icon
|
|
598
|
+
*/
|
|
599
|
+
Note = 2,
|
|
600
|
+
/**
|
|
601
|
+
* Help icon
|
|
602
|
+
*/
|
|
603
|
+
Help = 3,
|
|
604
|
+
/**
|
|
605
|
+
* New paragraph icon
|
|
606
|
+
*/
|
|
607
|
+
NewParagraph = 4,
|
|
608
|
+
/**
|
|
609
|
+
* Paragraph icon
|
|
610
|
+
*/
|
|
611
|
+
Paragraph = 5,
|
|
612
|
+
/**
|
|
613
|
+
* Insert icon
|
|
614
|
+
*/
|
|
615
|
+
Insert = 6,
|
|
616
|
+
/**
|
|
617
|
+
* Graph icon
|
|
618
|
+
*/
|
|
619
|
+
Graph = 7,
|
|
620
|
+
/**
|
|
621
|
+
* Push pin icon
|
|
622
|
+
*/
|
|
623
|
+
PushPin = 8,
|
|
624
|
+
/**
|
|
625
|
+
* Paperclip icon
|
|
626
|
+
*/
|
|
627
|
+
Paperclip = 9,
|
|
628
|
+
/**
|
|
629
|
+
* Tag icon
|
|
630
|
+
*/
|
|
631
|
+
Tag = 10,
|
|
632
|
+
/**
|
|
633
|
+
* Speaker icon
|
|
634
|
+
*/
|
|
635
|
+
Speaker = 11,
|
|
636
|
+
/**
|
|
637
|
+
* Mic icon
|
|
638
|
+
*/
|
|
639
|
+
Mic = 12,
|
|
640
|
+
/**
|
|
641
|
+
* Approved icon
|
|
642
|
+
*/
|
|
643
|
+
Approved = 13,
|
|
644
|
+
/**
|
|
645
|
+
* Experimental icon
|
|
646
|
+
*/
|
|
647
|
+
Experimental = 14,
|
|
648
|
+
/**
|
|
649
|
+
* Not approved icon
|
|
650
|
+
*/
|
|
651
|
+
NotApproved = 15,
|
|
652
|
+
/**
|
|
653
|
+
* As is icon
|
|
654
|
+
*/
|
|
655
|
+
AsIs = 16,
|
|
656
|
+
/**
|
|
657
|
+
* Expired icon
|
|
658
|
+
*/
|
|
659
|
+
Expired = 17,
|
|
660
|
+
/**
|
|
661
|
+
* Not for public release icon
|
|
662
|
+
*/
|
|
663
|
+
NotForPublicRelease = 18,
|
|
664
|
+
/**
|
|
665
|
+
* Confidential icon
|
|
666
|
+
*/
|
|
667
|
+
Confidential = 19,
|
|
668
|
+
/**
|
|
669
|
+
* Final icon
|
|
670
|
+
*/
|
|
671
|
+
Final = 20,
|
|
672
|
+
/**
|
|
673
|
+
* Sold icon
|
|
674
|
+
*/
|
|
675
|
+
Sold = 21,
|
|
676
|
+
/**
|
|
677
|
+
* Departmental icon
|
|
678
|
+
*/
|
|
679
|
+
Departmental = 22,
|
|
680
|
+
/**
|
|
681
|
+
* For comment icon
|
|
682
|
+
*/
|
|
683
|
+
ForComment = 23,
|
|
684
|
+
/**
|
|
685
|
+
* Top secret icon
|
|
686
|
+
*/
|
|
687
|
+
TopSecret = 24,
|
|
688
|
+
/**
|
|
689
|
+
* Draft icon
|
|
690
|
+
*/
|
|
691
|
+
Draft = 25,
|
|
692
|
+
/**
|
|
693
|
+
* For public release icon
|
|
694
|
+
*/
|
|
695
|
+
ForPublicRelease = 26
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Line ending of annotation
|
|
699
|
+
*/
|
|
583
700
|
export declare enum PdfAnnotationLineEnding {
|
|
584
701
|
/**
|
|
585
702
|
* No line ending
|
|
@@ -640,6 +757,10 @@ export interface PdfAnnotationObjectBase {
|
|
|
640
757
|
* Modified date of the annotation
|
|
641
758
|
*/
|
|
642
759
|
modified?: Date;
|
|
760
|
+
/**
|
|
761
|
+
* Created date of the annotation
|
|
762
|
+
*/
|
|
763
|
+
created?: Date;
|
|
643
764
|
/**
|
|
644
765
|
* blend mode of annotation
|
|
645
766
|
*/
|
|
@@ -660,14 +781,22 @@ export interface PdfAnnotationObjectBase {
|
|
|
660
781
|
* The index of page that this annotation belong to
|
|
661
782
|
*/
|
|
662
783
|
pageIndex: number;
|
|
784
|
+
/**
|
|
785
|
+
* contents of the annotation
|
|
786
|
+
*/
|
|
787
|
+
contents?: string;
|
|
663
788
|
/**
|
|
664
789
|
* id of the annotation
|
|
665
790
|
*/
|
|
666
|
-
id:
|
|
791
|
+
id: string;
|
|
667
792
|
/**
|
|
668
793
|
* Rectangle of the annotation
|
|
669
794
|
*/
|
|
670
795
|
rect: Rect;
|
|
796
|
+
/**
|
|
797
|
+
* Custom data of the annotation
|
|
798
|
+
*/
|
|
799
|
+
custom?: any;
|
|
671
800
|
}
|
|
672
801
|
/**
|
|
673
802
|
* Popup annotation
|
|
@@ -688,7 +817,7 @@ export interface PdfPopupAnnoObject extends PdfAnnotationObjectBase {
|
|
|
688
817
|
/**
|
|
689
818
|
* In reply to id
|
|
690
819
|
*/
|
|
691
|
-
inReplyToId?:
|
|
820
|
+
inReplyToId?: string;
|
|
692
821
|
}
|
|
693
822
|
/**
|
|
694
823
|
* Pdf Link annotation
|
|
@@ -698,10 +827,6 @@ export interface PdfPopupAnnoObject extends PdfAnnotationObjectBase {
|
|
|
698
827
|
export interface PdfLinkAnnoObject extends PdfAnnotationObjectBase {
|
|
699
828
|
/** {@inheritDoc PdfAnnotationObjectBase.type} */
|
|
700
829
|
type: PdfAnnotationSubtype.LINK;
|
|
701
|
-
/**
|
|
702
|
-
* Text of the link
|
|
703
|
-
*/
|
|
704
|
-
text: string;
|
|
705
830
|
/**
|
|
706
831
|
* target of the link
|
|
707
832
|
*/
|
|
@@ -730,7 +855,7 @@ export interface PdfTextAnnoObject extends PdfAnnotationObjectBase {
|
|
|
730
855
|
/**
|
|
731
856
|
* In reply to id
|
|
732
857
|
*/
|
|
733
|
-
inReplyToId?:
|
|
858
|
+
inReplyToId?: string;
|
|
734
859
|
/**
|
|
735
860
|
* State of the text annotation
|
|
736
861
|
*/
|
|
@@ -739,6 +864,10 @@ export interface PdfTextAnnoObject extends PdfAnnotationObjectBase {
|
|
|
739
864
|
* State model of the text annotation
|
|
740
865
|
*/
|
|
741
866
|
stateModel?: PdfAnnotationStateModel;
|
|
867
|
+
/**
|
|
868
|
+
* Icon of the text annotation
|
|
869
|
+
*/
|
|
870
|
+
icon?: PdfAnnotationIcon;
|
|
742
871
|
}
|
|
743
872
|
/**
|
|
744
873
|
* Type of form field
|
|
@@ -1859,6 +1988,19 @@ export interface PdfFileLoader extends PdfFileWithoutContent {
|
|
|
1859
1988
|
*/
|
|
1860
1989
|
callback: (offset: number, length: number) => Uint8Array;
|
|
1861
1990
|
}
|
|
1991
|
+
export interface PdfPageWithAnnotations {
|
|
1992
|
+
page: number;
|
|
1993
|
+
annotations: PdfAnnotationObject[];
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Progress of search all pages
|
|
1997
|
+
*
|
|
1998
|
+
* @public
|
|
1999
|
+
*/
|
|
2000
|
+
export type PdfPageSearchProgress = {
|
|
2001
|
+
page: number;
|
|
2002
|
+
results: SearchResult[];
|
|
2003
|
+
};
|
|
1862
2004
|
/**
|
|
1863
2005
|
* Pdf File
|
|
1864
2006
|
*
|
|
@@ -1906,38 +2048,39 @@ export declare enum PdfErrorCode {
|
|
|
1906
2048
|
CantFocusAnnot = 25,
|
|
1907
2049
|
CantSelectText = 26,
|
|
1908
2050
|
CantSelectOption = 27,
|
|
1909
|
-
CantCheckField = 28
|
|
2051
|
+
CantCheckField = 28,
|
|
2052
|
+
CantSetAnnotString = 29
|
|
1910
2053
|
}
|
|
1911
2054
|
export interface PdfErrorReason {
|
|
1912
2055
|
code: PdfErrorCode;
|
|
1913
2056
|
message: string;
|
|
1914
2057
|
}
|
|
1915
2058
|
export type PdfEngineError = TaskError<PdfErrorReason>;
|
|
1916
|
-
export type PdfTask<R> = Task<R, PdfErrorReason>;
|
|
2059
|
+
export type PdfTask<R, P = unknown> = Task<R, PdfErrorReason, P>;
|
|
1917
2060
|
export declare class PdfTaskHelper {
|
|
1918
2061
|
/**
|
|
1919
2062
|
* Create a task
|
|
1920
2063
|
* @returns new task
|
|
1921
2064
|
*/
|
|
1922
|
-
static create<R>(): Task<R, PdfErrorReason>;
|
|
2065
|
+
static create<R, P = unknown>(): Task<R, PdfErrorReason, P>;
|
|
1923
2066
|
/**
|
|
1924
2067
|
* Create a task that has been resolved with value
|
|
1925
2068
|
* @param result - resolved value
|
|
1926
2069
|
* @returns resolved task
|
|
1927
2070
|
*/
|
|
1928
|
-
static resolve<R>(result: R): Task<R, PdfErrorReason>;
|
|
2071
|
+
static resolve<R, P = unknown>(result: R): Task<R, PdfErrorReason, P>;
|
|
1929
2072
|
/**
|
|
1930
2073
|
* Create a task that has been rejected with error
|
|
1931
2074
|
* @param reason - rejected error
|
|
1932
2075
|
* @returns rejected task
|
|
1933
2076
|
*/
|
|
1934
|
-
static reject<T = any>(reason: PdfErrorReason): Task<T, PdfErrorReason>;
|
|
2077
|
+
static reject<T = any, P = unknown>(reason: PdfErrorReason): Task<T, PdfErrorReason, P>;
|
|
1935
2078
|
/**
|
|
1936
2079
|
* Create a task that has been aborted with error
|
|
1937
2080
|
* @param reason - aborted error
|
|
1938
2081
|
* @returns aborted task
|
|
1939
2082
|
*/
|
|
1940
|
-
static abort<T = any>(reason: PdfErrorReason): Task<T, PdfErrorReason>;
|
|
2083
|
+
static abort<T = any, P = unknown>(reason: PdfErrorReason): Task<T, PdfErrorReason, P>;
|
|
1941
2084
|
}
|
|
1942
2085
|
/**
|
|
1943
2086
|
* Pdf engine
|
|
@@ -2109,13 +2252,13 @@ export interface PdfEngine<T = Blob> {
|
|
|
2109
2252
|
* @param flags - match flags for search
|
|
2110
2253
|
* @returns Task contains all search results throughout the document
|
|
2111
2254
|
*/
|
|
2112
|
-
searchAllPages: (doc: PdfDocumentObject, keyword: string, flags?: MatchFlag[]) => PdfTask<SearchAllPagesResult>;
|
|
2255
|
+
searchAllPages: (doc: PdfDocumentObject, keyword: string, flags?: MatchFlag[]) => PdfTask<SearchAllPagesResult, PdfPageSearchProgress>;
|
|
2113
2256
|
/**
|
|
2114
2257
|
* Get all annotations in this file
|
|
2115
2258
|
* @param doc - pdf document
|
|
2116
2259
|
* @returns task that contains the annotations or error
|
|
2117
2260
|
*/
|
|
2118
|
-
getAllAnnotations: (doc: PdfDocumentObject) => PdfTask<Record<number, PdfAnnotationObject[]
|
|
2261
|
+
getAllAnnotations: (doc: PdfDocumentObject) => PdfTask<Record<number, PdfAnnotationObject[]>, PdfPageWithAnnotations>;
|
|
2119
2262
|
/**
|
|
2120
2263
|
* Get all attachments in this file
|
|
2121
2264
|
* @param doc - pdf document
|
|
@@ -2158,6 +2301,13 @@ export interface PdfEngine<T = Blob> {
|
|
|
2158
2301
|
* @returns task contains the text
|
|
2159
2302
|
*/
|
|
2160
2303
|
extractText: (doc: PdfDocumentObject, pageIndexes: number[]) => PdfTask<string>;
|
|
2304
|
+
/**
|
|
2305
|
+
* Redact text by run slices
|
|
2306
|
+
* @param doc - pdf document
|
|
2307
|
+
* @param perPage - per page run slices
|
|
2308
|
+
* @returns task contains the result
|
|
2309
|
+
*/
|
|
2310
|
+
redactTextInRects: (doc: PdfDocumentObject, page: PdfPageObject, rects: Rect[], recurseForms: boolean, drawBlackBoxes: boolean) => PdfTask<boolean>;
|
|
2161
2311
|
/**
|
|
2162
2312
|
* Extract text on specified pdf pages
|
|
2163
2313
|
* @param doc - pdf document
|
package/dist/task.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export type ResolvedCallback<R> = (r: R) => void;
|
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
45
|
export type RejectedCallback<D> = (e: TaskError<D>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* callback that will be called when task is progressing
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export type ProgressCallback<P> = (p: P) => void;
|
|
46
52
|
/**
|
|
47
53
|
* Task state in different stage
|
|
48
54
|
*
|
|
@@ -86,7 +92,7 @@ export declare class TaskRejectedError<D> extends Error {
|
|
|
86
92
|
*
|
|
87
93
|
* @public
|
|
88
94
|
*/
|
|
89
|
-
export declare class Task<R, D> {
|
|
95
|
+
export declare class Task<R, D, P = unknown> {
|
|
90
96
|
state: TaskState<R, D>;
|
|
91
97
|
/**
|
|
92
98
|
* callbacks that will be executed when task is resolved
|
|
@@ -100,6 +106,10 @@ export declare class Task<R, D> {
|
|
|
100
106
|
* Promise that will be resolved when task is settled
|
|
101
107
|
*/
|
|
102
108
|
private _promise;
|
|
109
|
+
/**
|
|
110
|
+
* callbacks that will be executed when task is progressing
|
|
111
|
+
*/
|
|
112
|
+
private progressCbs;
|
|
103
113
|
/**
|
|
104
114
|
* Convert task to promise
|
|
105
115
|
* @returns promise that will be resolved when task is settled
|
|
@@ -133,6 +143,16 @@ export declare class Task<R, D> {
|
|
|
133
143
|
* @param error - TaskError from another task
|
|
134
144
|
*/
|
|
135
145
|
fail(error: TaskError<D>): void;
|
|
146
|
+
/**
|
|
147
|
+
* add a progress callback
|
|
148
|
+
* @param cb - progress callback
|
|
149
|
+
*/
|
|
150
|
+
onProgress(cb: ProgressCallback<P>): void;
|
|
151
|
+
/**
|
|
152
|
+
* call progress callback
|
|
153
|
+
* @param p - progress value
|
|
154
|
+
*/
|
|
155
|
+
progress(p: P): void;
|
|
136
156
|
/**
|
|
137
157
|
* Static method to wait for all tasks to resolve
|
|
138
158
|
* Returns a new task that resolves with an array of all results
|
package/dist/uuid.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether the supplied string is a **valid RFC‑4122 v4 UUID**.
|
|
3
|
+
* Works in every runtime (browser / Node / Deno) because it is just
|
|
4
|
+
* string validation – no crypto required.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isUuidV4(str: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Generate a **version‑4 UUID** (random).
|
|
9
|
+
*
|
|
10
|
+
* • Uses the native `crypto.randomUUID()` when available (all modern
|
|
11
|
+
* browsers, Deno, Node ≥ 16.9).
|
|
12
|
+
* • Falls back to a tiny, standards‑compliant implementation that uses
|
|
13
|
+
* `crypto.getRandomValues` / `crypto.randomBytes` for entropy.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { uuidV4 } from "@embedpdf/models";
|
|
18
|
+
* const id = uuidV4();
|
|
19
|
+
* // → "36b8f84d-df4e-4d49-b662-bcde71a8764f"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function uuidV4(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/models",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared type definitions, data models, and utility helpers (geometry, tasks, logging, PDF primitives) that underpin every package in the EmbedPDF ecosystem.",
|
|
6
6
|
"type": "module",
|