@embedpdf/models 1.0.11 → 1.0.13

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,299 @@
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
+ * Check if two rectangles are equal
190
+ * @param a - first rectangle
191
+ * @param b - second rectangle
192
+ * @returns true if the rectangles are equal, false otherwise
193
+ *
194
+ * @public
195
+ */
196
+ export declare function rectEquals(a: Rect, b: Rect): boolean;
197
+ /**
198
+ * Calculate the rect from the given points
199
+ * @param pts - points
200
+ * @returns rect
201
+ *
202
+ * @public
203
+ */
204
+ export declare function rectFromPoints(positions: Position[]): Rect;
205
+ /**
206
+ * Transform the point by the given angle and translation
207
+ * @param pos - point
208
+ * @param angleRad - angle in radians
209
+ * @param translate - translation
210
+ * @returns transformed point
211
+ *
212
+ * @public
213
+ */
214
+ export declare function rotateAndTranslatePoint(pos: Position, angleRad: number, translate: Position): Position;
215
+ /**
216
+ * Expand the rect by the given padding
217
+ * @param rect - rectangle
218
+ * @param padding - padding
219
+ * @returns expanded rect
220
+ *
221
+ * @public
222
+ */
223
+ export declare function expandRect(rect: Rect, padding: number): Rect;
224
+ /**
225
+ * Calculate the rect after rotated the container
226
+ * @param containerSize - size of container
227
+ * @param rect - target rect
228
+ * @param rotation - rotation angle
229
+ * @returns rotated rect
230
+ *
231
+ * @public
232
+ */
233
+ export declare function rotateRect(containerSize: Size, rect: Rect, rotation: Rotation): Rect;
234
+ /**
235
+ * Scale the rectangle
236
+ * @param rect - rectangle
237
+ * @param scaleFactor - factor of scaling
238
+ * @returns new rectangle
239
+ *
240
+ * @public
241
+ */
242
+ export declare function scaleRect(rect: Rect, scaleFactor: number): Rect;
243
+ /**
244
+ * Calculate new rectangle after transforming the container
245
+ * @param containerSize - size of the container
246
+ * @param rect - the target rectangle
247
+ * @param rotation - rotated angle
248
+ * @param scaleFactor - factor of scaling
249
+ * @returns new rectangle after transformation
250
+ *
251
+ * @public
252
+ */
253
+ export declare function transformRect(containerSize: Size, rect: Rect, rotation: Rotation, scaleFactor: number): Rect;
254
+ /**
255
+ * Calculate new rectangle before transforming the container
256
+ * @param containerSize - size of the container
257
+ * @param rect - the target rectangle
258
+ * @param rotation - rotated angle
259
+ * @param scaleFactor - factor of scaling
260
+ * @returns original rectangle before transformation
261
+ *
262
+ * @public
263
+ */
264
+ export declare function restoreRect(containerSize: Size, rect: Rect, rotation: Rotation, scaleFactor: number): Rect;
265
+ /**
266
+ * Calculate the original offset in a transformed container
267
+ * @param offset - position of the point
268
+ * @param rotation - rotated angle
269
+ * @param scaleFactor - factor of scaling
270
+ * @returns original position of the point
271
+ *
272
+ * @public
273
+ */
274
+ export declare function restoreOffset(offset: Position, rotation: Rotation, scaleFactor: number): Position;
275
+ /**
276
+ * Return the smallest rectangle that encloses *all* `rects`.
277
+ * If the array is empty, returns `null`.
278
+ *
279
+ * @param rects - array of rectangles
280
+ * @returns smallest rectangle that encloses all the rectangles
281
+ *
282
+ * @public
283
+ */
284
+ export declare function boundingRect(rects: Rect[]): Rect | null;
285
+ export interface Matrix {
286
+ a: number;
287
+ b: number;
288
+ c: number;
289
+ d: number;
290
+ e: number;
291
+ f: number;
292
+ }
293
+ /**
294
+ * Build a CTM that maps *PDF-space* inside the annotation
295
+ * → *device-space* inside the bitmap, honouring
296
+ * zoom (scaleFactor × dpr) **and** page-rotation.
297
+ */
298
+ /** build the CTM for any page-rotation */
299
+ export declare const makeMatrix: (rectangle: Rect, rotation: Rotation, scaleFactor: number) => Matrix;
@@ -0,0 +1 @@
1
+ export {};