@embedpdf/models 1.0.10 → 1.0.12

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.
@@ -0,0 +1,21 @@
1
+ import { PdfAlphaColor } from './pdf';
2
+ export interface WebAlphaColor {
3
+ color: string;
4
+ opacity: number;
5
+ }
6
+ /**
7
+ * Convert a {@link PdfAlphaColor} to a CSS-style colour definition.
8
+ *
9
+ * @param c - the colour coming from PDFium (0-255 per channel)
10
+ * @returns
11
+ * hex – #RRGGBB (no alpha channel)
12
+ * opacity – 0-1 float suitable for CSS `opacity`/`rgba()`
13
+ */
14
+ export declare function pdfAlphaColorToWebAlphaColor(c: PdfAlphaColor): WebAlphaColor;
15
+ /**
16
+ * Convert a CSS hex colour + opacity back into {@link PdfAlphaColor}
17
+ *
18
+ * @param hex - #RGB, #RRGGBB, or #rrggbb
19
+ * @param opacity - 0-1 float (values outside clamp automatically)
20
+ */
21
+ export declare function webAlphaColorToPdfAlphaColor({ color, opacity }: WebAlphaColor): PdfAlphaColor;
package/dist/date.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
3
+ *
4
+ * Returns `undefined` if the input is malformed.
5
+ *
6
+ * @public
7
+ */
8
+ export declare function pdfDateToDate(pdf?: string): Date | undefined;
9
+ /**
10
+ * Convert a date to a PDF date string
11
+ * @param date - date to convert
12
+ * @returns PDF date string
13
+ *
14
+ * @public
15
+ */
16
+ export declare function dateToPdfDate(date?: Date): string;
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Clockwise direction
3
+ * @public
4
+ */
5
+ export declare enum Rotation {
6
+ Degree0 = 0,
7
+ Degree90 = 1,
8
+ Degree180 = 2,
9
+ Degree270 = 3
10
+ }
11
+ /** Clamp a Position to device-pixel integers (floor) */
12
+ export declare function toIntPos(p: Position): Position;
13
+ /** Clamp a Size so it never truncates right / bottom (ceil) */
14
+ export declare function toIntSize(s: Size): Size;
15
+ /** Apply both rules to a Rect */
16
+ export declare function toIntRect(r: Rect): Rect;
17
+ /**
18
+ * Calculate degree that match the rotation type
19
+ * @param rotation - type of rotation
20
+ * @returns rotated degree
21
+ *
22
+ * @public
23
+ */
24
+ export declare function calculateDegree(rotation: Rotation): 0 | 90 | 180 | 270;
25
+ /**
26
+ * Calculate angle that match the rotation type
27
+ * @param rotation - type of rotation
28
+ * @returns rotated angle
29
+ *
30
+ * @public
31
+ */
32
+ export declare function calculateAngle(rotation: Rotation): number;
33
+ /**
34
+ * Represent the size of object
35
+ *
36
+ * @public
37
+ */
38
+ export interface Size {
39
+ /**
40
+ * width of the object
41
+ */
42
+ width: number;
43
+ /**
44
+ * height of the object
45
+ */
46
+ height: number;
47
+ }
48
+ /**
49
+ * Represents a rectangle defined by its left, top, right, and bottom edges
50
+ *
51
+ * @public
52
+ */
53
+ export interface Box {
54
+ /**
55
+ * The x-coordinate of the left edge
56
+ */
57
+ left: number;
58
+ /**
59
+ * The y-coordinate of the top edge
60
+ */
61
+ top: number;
62
+ /**
63
+ * The x-coordinate of the right edge
64
+ */
65
+ right: number;
66
+ /**
67
+ * The y-coordinate of the bottom edge
68
+ */
69
+ bottom: number;
70
+ }
71
+ /**
72
+ * Swap the width and height of the size object
73
+ * @param size - the original size
74
+ * @returns swapped size
75
+ *
76
+ * @public
77
+ */
78
+ export declare function swap(size: Size): Size;
79
+ /**
80
+ * Transform size with specified rotation angle and scale factor
81
+ * @param size - orignal size of rect
82
+ * @param rotation - rotation angle
83
+ * @param scaleFactor - - scale factor
84
+ * @returns size that has been transformed
85
+ *
86
+ * @public
87
+ */
88
+ export declare function transformSize(size: Size, rotation: Rotation, scaleFactor: number): Size;
89
+ /**
90
+ * position of point
91
+ *
92
+ * @public
93
+ */
94
+ export interface Position {
95
+ /**
96
+ * x coordinate
97
+ */
98
+ x: number;
99
+ /**
100
+ * y coordinate
101
+ */
102
+ y: number;
103
+ }
104
+ /**
105
+ * Quadrilateral
106
+ *
107
+ * @public
108
+ */
109
+ export interface Quad {
110
+ p1: Position;
111
+ p2: Position;
112
+ p3: Position;
113
+ p4: Position;
114
+ }
115
+ /**
116
+ * Convert quadrilateral to rectangle
117
+ * @param q - quadrilateral
118
+ * @returns rectangle
119
+ *
120
+ * @public
121
+ */
122
+ export declare function quadToRect(q: Quad): Rect;
123
+ /**
124
+ * Convert rectangle to quadrilateral
125
+ * @param r - rectangle
126
+ * @returns quadrilateral
127
+ *
128
+ * @public
129
+ */
130
+ export declare function rectToQuad(r: Rect): Quad;
131
+ /**
132
+ * Rotate the container and calculate the new position for a point
133
+ * in specified position
134
+ * @param containerSize - size of the container
135
+ * @param position - position of the point
136
+ * @param rotation - rotated angle
137
+ * @returns new position of the point
138
+ *
139
+ * @public
140
+ */
141
+ export declare function rotatePosition(containerSize: Size, position: Position, rotation: Rotation): Position;
142
+ /**
143
+ * Calculate the position of point by scaling the container
144
+ * @param position - position of the point
145
+ * @param scaleFactor - factor of scaling
146
+ * @returns new position of point
147
+ *
148
+ * @public
149
+ */
150
+ export declare function scalePosition(position: Position, scaleFactor: number): Position;
151
+ /**
152
+ * Calculate the position of the point by applying the specified transformation
153
+ * @param containerSize - size of container
154
+ * @param position - position of the point
155
+ * @param rotation - rotated angle
156
+ * @param scaleFactor - factor of scaling
157
+ * @returns new position of point
158
+ *
159
+ * @public
160
+ */
161
+ export declare function transformPosition(containerSize: Size, position: Position, rotation: Rotation, scaleFactor: number): Position;
162
+ /**
163
+ * Restore the position in a transformed cotainer
164
+ * @param containerSize - size of the container
165
+ * @param position - position of the point
166
+ * @param rotation - rotated angle
167
+ * @param scaleFactor - factor of scaling
168
+ * @returns the original position of the point
169
+ *
170
+ * @public
171
+ */
172
+ export declare function restorePosition(containerSize: Size, position: Position, rotation: Rotation, scaleFactor: number): Position;
173
+ /**
174
+ * representation of rectangle
175
+ *
176
+ * @public
177
+ */
178
+ export interface Rect {
179
+ /**
180
+ * origin of the rectangle
181
+ */
182
+ origin: Position;
183
+ /**
184
+ * size of the rectangle
185
+ */
186
+ size: Size;
187
+ }
188
+ /**
189
+ * Calculate the rect after rotated the container
190
+ * @param containerSize - size of container
191
+ * @param rect - target rect
192
+ * @param rotation - rotation angle
193
+ * @returns rotated rect
194
+ *
195
+ * @public
196
+ */
197
+ export declare function rotateRect(containerSize: Size, rect: Rect, rotation: Rotation): Rect;
198
+ /**
199
+ * Scale the rectangle
200
+ * @param rect - rectangle
201
+ * @param scaleFactor - factor of scaling
202
+ * @returns new rectangle
203
+ *
204
+ * @public
205
+ */
206
+ export declare function scaleRect(rect: Rect, scaleFactor: number): Rect;
207
+ /**
208
+ * Calculate new rectangle after transforming the container
209
+ * @param containerSize - size of the container
210
+ * @param rect - the target rectangle
211
+ * @param rotation - rotated angle
212
+ * @param scaleFactor - factor of scaling
213
+ * @returns new rectangle after transformation
214
+ *
215
+ * @public
216
+ */
217
+ export declare function transformRect(containerSize: Size, rect: Rect, rotation: Rotation, scaleFactor: number): Rect;
218
+ /**
219
+ * Calculate new rectangle before transforming the container
220
+ * @param containerSize - size of the container
221
+ * @param rect - the target rectangle
222
+ * @param rotation - rotated angle
223
+ * @param scaleFactor - factor of scaling
224
+ * @returns original rectangle before transformation
225
+ *
226
+ * @public
227
+ */
228
+ export declare function restoreRect(containerSize: Size, rect: Rect, rotation: Rotation, scaleFactor: number): Rect;
229
+ /**
230
+ * Calculate the original offset in a transformed container
231
+ * @param offset - position of the point
232
+ * @param rotation - rotated angle
233
+ * @param scaleFactor - factor of scaling
234
+ * @returns original position of the point
235
+ *
236
+ * @public
237
+ */
238
+ export declare function restoreOffset(offset: Position, rotation: Rotation, scaleFactor: number): Position;
239
+ /**
240
+ * Return the smallest rectangle that encloses *all* `rects`.
241
+ * If the array is empty, returns `null`.
242
+ *
243
+ * @param rects - array of rectangles
244
+ * @returns smallest rectangle that encloses all the rectangles
245
+ *
246
+ * @public
247
+ */
248
+ export declare function boundingRect(rects: Rect[]): Rect | null;
249
+ export interface Matrix {
250
+ a: number;
251
+ b: number;
252
+ c: number;
253
+ d: number;
254
+ e: number;
255
+ f: number;
256
+ }
257
+ /**
258
+ * Build a CTM that maps *PDF-space* inside the annotation
259
+ * → *device-space* inside the bitmap, honouring
260
+ * zoom (scaleFactor × dpr) **and** page-rotation.
261
+ */
262
+ /** build the CTM for any page-rotation */
263
+ export declare const makeMatrix: (rectangle: Rect, rotation: Rotation, scaleFactor: number) => Matrix;
@@ -0,0 +1 @@
1
+ export {};